diff --git a/materialsystem/vulkan/rendercontext.cpp b/materialsystem/vulkan/rendercontext.cpp index c2997dd..19aaa45 100644 --- a/materialsystem/vulkan/rendercontext.cpp +++ b/materialsystem/vulkan/rendercontext.cpp @@ -1,6 +1,7 @@ #include "SDL3/SDL_vulkan.h" #include "materialsystem/materialsystem.h" #include "tier0/platform.h" +#include "tier1/utlstring.h" #include "tier1/utlvector.h" #define VK_NO_PROTOTYPES #include "vulkan/vulkan_core.h" @@ -63,6 +64,7 @@ IIndexBuffer *CVkRenderContext::CreateIndexBuffer( uint32_t nSize ) //----------------------------------------------------------------------------- IBuffer *CreateBuffer( uint32_t nSize, VkBufferUsageFlags2 eUsage ) { + } //----------------------------------------------------------------------------- @@ -208,8 +210,16 @@ void CVkRenderContext::Frame( float fDeltaTime ) void CVkRenderContext::CreateSwapchain() { + CUtlVector surfaceFormats; + gamewindow->CreateVulkanSurface(g_vkInstance); + VkSwapchainCreateInfoKHR stSwapchainCreateInfo = {}; + stSwapchainCreateInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + stSwapchainCreateInfo.surface = (VkSurfaceKHR)gamewindow->GetVulkanSurface(); + + vkCreateSwapchainKHR(g_vkDevice, &stSwapchainCreateInfo, NULL, &g_vkSwapchain); + } void CVkRenderContext::DestroySwapchain() diff --git a/public/tier1/utlvector.h b/public/tier1/utlvector.h index fc6fa45..c8641d9 100644 --- a/public/tier1/utlvector.h +++ b/public/tier1/utlvector.h @@ -127,7 +127,7 @@ void CUtlVector::AppendHead( const T &data ) } template -void CUtlVector::AppendHead( const T *pData, size_t n ) +void CUtlVector::AppendHead( const T *pData, size_t n ) { size_t nOldSize = m_nSize; m_data.Resize(m_nSize+n); @@ -144,13 +144,13 @@ void CUtlVector::AppendHead( const T *pData, size_t n ) } template -void CUtlVector::AppendTail( const T &data ) +void CUtlVector::AppendTail( const T &data ) { AppendTail(&data,1); } template -void CUtlVector::AppendTail( const T *pData, size_t n ) +void CUtlVector::AppendTail( const T *pData, size_t n ) { m_data.Resize(m_data.GetSize()+n); for ( size_t i = 0; i < n; i++ ) @@ -159,13 +159,13 @@ void CUtlVector::AppendTail( const T *pData, size_t n ) } template -void CUtlVector::AppendAt( size_t nIndex, const T &data ) +void CUtlVector::AppendAt( size_t nIndex, const T &data ) { AppendAt(nIndex, &data, 1); } template -void CUtlVector::AppendAt( size_t nIndex, const T *pData, size_t n ) +void CUtlVector::AppendAt( size_t nIndex, const T *pData, size_t n ) { size_t nOldSize = m_nSize; m_data.Resize(m_nSize+n); diff --git a/public/tier2/fileformats/ini.h b/public/tier2/fileformats/ini.h index fe16be0..22ea470 100644 --- a/public/tier2/fileformats/ini.h +++ b/public/tier2/fileformats/ini.h @@ -24,6 +24,7 @@ abstract_class IINIManager { public: virtual IINIFile *ReadString( const char *psz ) = 0; + virtual void ReleaseFile( IINIFile *pFile ) = 0; }; IINIManager *INIManager(); diff --git a/tests/ini/initest b/tests/ini/initest index 01d2d95..8726a99 100644 Binary files a/tests/ini/initest and b/tests/ini/initest differ diff --git a/tests/ini/main.cpp b/tests/ini/main.cpp index 14b74fa..5516b08 100644 --- a/tests/ini/main.cpp +++ b/tests/ini/main.cpp @@ -45,5 +45,5 @@ int main( int argc, char **argv ) if (!pTestValues) return 0; V_printf("%s\n",pTestValues->GetStringValue("abc3d")); - + return 0; }; diff --git a/tests/ini/test1.ini b/tests/ini/test1.ini index f86614a..cf31c5e 100644 --- a/tests/ini/test1.ini +++ b/tests/ini/test1.ini @@ -10,3 +10,4 @@ f = -890 g = .34 abc3d = "Hello world from the funny engine, you can use \" to add quotes" + diff --git a/tier2/fileformats/ini.cpp b/tier2/fileformats/ini.cpp index 03daf55..c5fb6bc 100644 --- a/tier2/fileformats/ini.cpp +++ b/tier2/fileformats/ini.cpp @@ -7,9 +7,9 @@ enum ESectionType { - SECTIONTYPE_String, - SECTIONTYPE_Boolean, - SECTIONTYPE_Float, + SECTIONTYPE_STRING, + SECTIONTYPE_BOOLEAN, + SECTIONTYPE_FLOAT, }; @@ -31,7 +31,7 @@ public: virtual const char *GetStringValue( const char *szKeyName ) override; virtual CUtlString GetUTLStringValue( const char *szKeyName ) override; - CUtlVector m_values; + CUtlVector m_values; CUtlString m_szSectionName; }; @@ -47,6 +47,11 @@ int CINISection::GetIntValue( const char *szKeyName ) const char *CINISection::GetStringValue( const char *szKeyName ) { + for (auto &value: m_values) + { + if (value->m_szKey == szKeyName) + return value->m_szData; + } return 0; } @@ -68,7 +73,7 @@ IINISection *CINIFile::GetSection( const char *szSectionName ) for ( auto §ion: m_sections ) { if ( section->m_szSectionName == szSectionName ) - return (IINISection*)§ion; + return (IINISection*)section; } return 0; } @@ -78,23 +83,24 @@ class CINIManager: public IINIManager { public: virtual IINIFile *ReadString( const char *psz ) override; + virtual void ReleaseFile( IINIFile *pFile ) override; bool IsWordSymbol( char c ); CUtlVector TokenizeString(); }; IINIFile *CINIManager::ReadString( const char *psz ) { - CINIFile *pFile = 0; - CINIFile file = {}; - bool bIsQuoted; - bool bIsSlash; + CINIFile *pFile = new CINIFile; + *pFile = {}; + bool bIsQuoted = false; + bool bIsSlash = false; bool bIsVarName; bool bIsVarValue; bool bIsSectionName; - CINISection currentSection; - SectionData_t currentSectionData; + CINISection *pCurrentSection = 0; + SectionData_t *pCurrentSectionData = 0; size_t i = 0; char c; @@ -183,14 +189,13 @@ IINIFile *CINIManager::ReadString( const char *psz ) } }; - currentSectionData.m_eSectionType = SECTIONTYPE_String; for ( int i = 0; i < tokens.GetSize(); i++ ) { if (tokens[i] == "]") { V_printf("Error: unexpected ]\n"); - return 0; + return pFile; } if (tokens[i] == "[") { @@ -198,32 +203,45 @@ IINIFile *CINIManager::ReadString( const char *psz ) if (i>=tokens.GetSize()) { V_printf("Error: Trailing section start\n"); - return 0; + return pFile; } - currentSection = {}; - currentSection.m_szSectionName = tokens[i]; - V_printf("[%s]\n",currentSection.m_szSectionName.GetString()); + pCurrentSection = (CINISection*)pFile->GetSection(tokens[i]); + if (!pCurrentSection) + { + pCurrentSection = new CINISection; + *pCurrentSection = {}; + pFile->m_sections.AppendTail(pCurrentSection); + } + pCurrentSection->m_szSectionName = tokens[i]; + i++; if (i>=tokens.GetSize()) { V_printf("Error: Trailing section name\n"); - return 0; + return pFile; } if (tokens[i] != "]") { V_printf("Error: expected ]\n"); - return 0; + return pFile; } continue; } + if (!pCurrentSection) + { + V_printf("Error: section wasn't specified\n"); + return pFile; + } if (tokens[i] == "=") { - V_printf("Error: expected key\n"); - return 0; + V_printf("Error: expected key\n"); + return pFile; } - currentSectionData = {}; - currentSectionData.m_szKey = tokens[i]; + + pCurrentSectionData = new SectionData_t; + pCurrentSectionData->m_eSectionType = SECTIONTYPE_STRING; + pCurrentSectionData->m_szKey = tokens[i]; @@ -231,12 +249,14 @@ IINIFile *CINIManager::ReadString( const char *psz ) if (i>=tokens.GetSize()) { V_printf("Error: trailing key\n"); - return 0; + delete pCurrentSectionData; + return pFile; } if (tokens[i] != "=") { V_printf("Error: expected =\n"); - return 0; + delete pCurrentSectionData; + return pFile; } i++; @@ -244,18 +264,21 @@ IINIFile *CINIManager::ReadString( const char *psz ) if (i>=tokens.GetSize()) { V_printf("Error: expected value\n"); - return 0; + delete pCurrentSectionData; + return pFile; } - currentSectionData.m_szData = tokens[i]; - currentSection.m_values.AppendTail(currentSectionData); + pCurrentSectionData->m_szData = tokens[i]; + pCurrentSection->m_values.AppendTail(pCurrentSectionData); } - - pFile = new CINIFile; - *pFile = file; - return (IINIFile*)pFile; } + +void CINIManager::ReleaseFile( IINIFile *pFile ) +{ + +} + bool CINIManager::IsWordSymbol( char c ) { if (V_isalnum(c))