ini parser completed
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include "SDL3/SDL_vulkan.h"
|
#include "SDL3/SDL_vulkan.h"
|
||||||
#include "materialsystem/materialsystem.h"
|
#include "materialsystem/materialsystem.h"
|
||||||
#include "tier0/platform.h"
|
#include "tier0/platform.h"
|
||||||
|
#include "tier1/utlstring.h"
|
||||||
#include "tier1/utlvector.h"
|
#include "tier1/utlvector.h"
|
||||||
#define VK_NO_PROTOTYPES
|
#define VK_NO_PROTOTYPES
|
||||||
#include "vulkan/vulkan_core.h"
|
#include "vulkan/vulkan_core.h"
|
||||||
@@ -63,6 +64,7 @@ IIndexBuffer *CVkRenderContext::CreateIndexBuffer( uint32_t nSize )
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
IBuffer *CreateBuffer( uint32_t nSize, VkBufferUsageFlags2 eUsage )
|
IBuffer *CreateBuffer( uint32_t nSize, VkBufferUsageFlags2 eUsage )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -208,8 +210,16 @@ void CVkRenderContext::Frame( float fDeltaTime )
|
|||||||
|
|
||||||
void CVkRenderContext::CreateSwapchain()
|
void CVkRenderContext::CreateSwapchain()
|
||||||
{
|
{
|
||||||
|
CUtlVector<VkSurfaceFormatKHR> surfaceFormats;
|
||||||
|
|
||||||
gamewindow->CreateVulkanSurface(g_vkInstance);
|
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()
|
void CVkRenderContext::DestroySwapchain()
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ void CUtlVector<T>::AppendHead( const T &data )
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void CUtlVector<T>::AppendHead( const T *pData, size_t n )
|
void CUtlVector<T>::AppendHead( const T *pData, size_t n )
|
||||||
{
|
{
|
||||||
size_t nOldSize = m_nSize;
|
size_t nOldSize = m_nSize;
|
||||||
m_data.Resize(m_nSize+n);
|
m_data.Resize(m_nSize+n);
|
||||||
@@ -144,13 +144,13 @@ void CUtlVector<T>::AppendHead( const T *pData, size_t n )
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void CUtlVector<T>::AppendTail( const T &data )
|
void CUtlVector<T>::AppendTail( const T &data )
|
||||||
{
|
{
|
||||||
AppendTail(&data,1);
|
AppendTail(&data,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void CUtlVector<T>::AppendTail( const T *pData, size_t n )
|
void CUtlVector<T>::AppendTail( const T *pData, size_t n )
|
||||||
{
|
{
|
||||||
m_data.Resize(m_data.GetSize()+n);
|
m_data.Resize(m_data.GetSize()+n);
|
||||||
for ( size_t i = 0; i < n; i++ )
|
for ( size_t i = 0; i < n; i++ )
|
||||||
@@ -159,13 +159,13 @@ void CUtlVector<T>::AppendTail( const T *pData, size_t n )
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void CUtlVector<T>::AppendAt( size_t nIndex, const T &data )
|
void CUtlVector<T>::AppendAt( size_t nIndex, const T &data )
|
||||||
{
|
{
|
||||||
AppendAt(nIndex, &data, 1);
|
AppendAt(nIndex, &data, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void CUtlVector<T>::AppendAt( size_t nIndex, const T *pData, size_t n )
|
void CUtlVector<T>::AppendAt( size_t nIndex, const T *pData, size_t n )
|
||||||
{
|
{
|
||||||
size_t nOldSize = m_nSize;
|
size_t nOldSize = m_nSize;
|
||||||
m_data.Resize(m_nSize+n);
|
m_data.Resize(m_nSize+n);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ abstract_class IINIManager
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual IINIFile *ReadString( const char *psz ) = 0;
|
virtual IINIFile *ReadString( const char *psz ) = 0;
|
||||||
|
virtual void ReleaseFile( IINIFile *pFile ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
IINIManager *INIManager();
|
IINIManager *INIManager();
|
||||||
|
|||||||
Binary file not shown.
@@ -45,5 +45,5 @@ int main( int argc, char **argv )
|
|||||||
if (!pTestValues)
|
if (!pTestValues)
|
||||||
return 0;
|
return 0;
|
||||||
V_printf("%s\n",pTestValues->GetStringValue("abc3d"));
|
V_printf("%s\n",pTestValues->GetStringValue("abc3d"));
|
||||||
|
return 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,3 +10,4 @@ f = -890
|
|||||||
g = .34
|
g = .34
|
||||||
abc3d = "Hello world from the funny engine, you can use \" to add quotes"
|
abc3d = "Hello world from the funny engine, you can use \" to add quotes"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
enum ESectionType
|
enum ESectionType
|
||||||
{
|
{
|
||||||
SECTIONTYPE_String,
|
SECTIONTYPE_STRING,
|
||||||
SECTIONTYPE_Boolean,
|
SECTIONTYPE_BOOLEAN,
|
||||||
SECTIONTYPE_Float,
|
SECTIONTYPE_FLOAT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ public:
|
|||||||
virtual const char *GetStringValue( const char *szKeyName ) override;
|
virtual const char *GetStringValue( const char *szKeyName ) override;
|
||||||
virtual CUtlString GetUTLStringValue( const char *szKeyName ) override;
|
virtual CUtlString GetUTLStringValue( const char *szKeyName ) override;
|
||||||
|
|
||||||
CUtlVector<SectionData_t> m_values;
|
CUtlVector<SectionData_t*> m_values;
|
||||||
CUtlString m_szSectionName;
|
CUtlString m_szSectionName;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,6 +47,11 @@ int CINISection::GetIntValue( const char *szKeyName )
|
|||||||
|
|
||||||
const char *CINISection::GetStringValue( 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +73,7 @@ IINISection *CINIFile::GetSection( const char *szSectionName )
|
|||||||
for ( auto §ion: m_sections )
|
for ( auto §ion: m_sections )
|
||||||
{
|
{
|
||||||
if ( section->m_szSectionName == szSectionName )
|
if ( section->m_szSectionName == szSectionName )
|
||||||
return (IINISection*)§ion;
|
return (IINISection*)section;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -78,23 +83,24 @@ class CINIManager: public IINIManager
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual IINIFile *ReadString( const char *psz ) override;
|
virtual IINIFile *ReadString( const char *psz ) override;
|
||||||
|
virtual void ReleaseFile( IINIFile *pFile ) override;
|
||||||
bool IsWordSymbol( char c );
|
bool IsWordSymbol( char c );
|
||||||
CUtlVector<CUtlString> TokenizeString();
|
CUtlVector<CUtlString> TokenizeString();
|
||||||
};
|
};
|
||||||
|
|
||||||
IINIFile *CINIManager::ReadString( const char *psz )
|
IINIFile *CINIManager::ReadString( const char *psz )
|
||||||
{
|
{
|
||||||
CINIFile *pFile = 0;
|
CINIFile *pFile = new CINIFile;
|
||||||
CINIFile file = {};
|
*pFile = {};
|
||||||
bool bIsQuoted;
|
bool bIsQuoted = false;
|
||||||
bool bIsSlash;
|
bool bIsSlash = false;
|
||||||
|
|
||||||
bool bIsVarName;
|
bool bIsVarName;
|
||||||
bool bIsVarValue;
|
bool bIsVarValue;
|
||||||
bool bIsSectionName;
|
bool bIsSectionName;
|
||||||
|
|
||||||
CINISection currentSection;
|
CINISection *pCurrentSection = 0;
|
||||||
SectionData_t currentSectionData;
|
SectionData_t *pCurrentSectionData = 0;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
char c;
|
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++ )
|
for ( int i = 0; i < tokens.GetSize(); i++ )
|
||||||
{
|
{
|
||||||
if (tokens[i] == "]")
|
if (tokens[i] == "]")
|
||||||
{
|
{
|
||||||
V_printf("Error: unexpected ]\n");
|
V_printf("Error: unexpected ]\n");
|
||||||
return 0;
|
return pFile;
|
||||||
}
|
}
|
||||||
if (tokens[i] == "[")
|
if (tokens[i] == "[")
|
||||||
{
|
{
|
||||||
@@ -198,32 +203,45 @@ IINIFile *CINIManager::ReadString( const char *psz )
|
|||||||
if (i>=tokens.GetSize())
|
if (i>=tokens.GetSize())
|
||||||
{
|
{
|
||||||
V_printf("Error: Trailing section start\n");
|
V_printf("Error: Trailing section start\n");
|
||||||
return 0;
|
return pFile;
|
||||||
}
|
}
|
||||||
currentSection = {};
|
|
||||||
currentSection.m_szSectionName = tokens[i];
|
pCurrentSection = (CINISection*)pFile->GetSection(tokens[i]);
|
||||||
V_printf("[%s]\n",currentSection.m_szSectionName.GetString());
|
if (!pCurrentSection)
|
||||||
|
{
|
||||||
|
pCurrentSection = new CINISection;
|
||||||
|
*pCurrentSection = {};
|
||||||
|
pFile->m_sections.AppendTail(pCurrentSection);
|
||||||
|
}
|
||||||
|
pCurrentSection->m_szSectionName = tokens[i];
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
if (i>=tokens.GetSize())
|
if (i>=tokens.GetSize())
|
||||||
{
|
{
|
||||||
V_printf("Error: Trailing section name\n");
|
V_printf("Error: Trailing section name\n");
|
||||||
return 0;
|
return pFile;
|
||||||
}
|
}
|
||||||
if (tokens[i] != "]")
|
if (tokens[i] != "]")
|
||||||
{
|
{
|
||||||
V_printf("Error: expected ]\n");
|
V_printf("Error: expected ]\n");
|
||||||
return 0;
|
return pFile;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!pCurrentSection)
|
||||||
|
{
|
||||||
|
V_printf("Error: section wasn't specified\n");
|
||||||
|
return pFile;
|
||||||
|
}
|
||||||
if (tokens[i] == "=")
|
if (tokens[i] == "=")
|
||||||
{
|
{
|
||||||
V_printf("Error: expected key\n");
|
V_printf("Error: expected key\n");
|
||||||
return 0;
|
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())
|
if (i>=tokens.GetSize())
|
||||||
{
|
{
|
||||||
V_printf("Error: trailing key\n");
|
V_printf("Error: trailing key\n");
|
||||||
return 0;
|
delete pCurrentSectionData;
|
||||||
|
return pFile;
|
||||||
}
|
}
|
||||||
if (tokens[i] != "=")
|
if (tokens[i] != "=")
|
||||||
{
|
{
|
||||||
V_printf("Error: expected =\n");
|
V_printf("Error: expected =\n");
|
||||||
return 0;
|
delete pCurrentSectionData;
|
||||||
|
return pFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
@@ -244,18 +264,21 @@ IINIFile *CINIManager::ReadString( const char *psz )
|
|||||||
if (i>=tokens.GetSize())
|
if (i>=tokens.GetSize())
|
||||||
{
|
{
|
||||||
V_printf("Error: expected value\n");
|
V_printf("Error: expected value\n");
|
||||||
return 0;
|
delete pCurrentSectionData;
|
||||||
|
return pFile;
|
||||||
}
|
}
|
||||||
currentSectionData.m_szData = tokens[i];
|
pCurrentSectionData->m_szData = tokens[i];
|
||||||
currentSection.m_values.AppendTail(currentSectionData);
|
|
||||||
|
|
||||||
|
pCurrentSection->m_values.AppendTail(pCurrentSectionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
pFile = new CINIFile;
|
|
||||||
*pFile = file;
|
|
||||||
|
|
||||||
return (IINIFile*)pFile;
|
return (IINIFile*)pFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CINIManager::ReleaseFile( IINIFile *pFile )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool CINIManager::IsWordSymbol( char c )
|
bool CINIManager::IsWordSymbol( char c )
|
||||||
{
|
{
|
||||||
if (V_isalnum(c))
|
if (V_isalnum(c))
|
||||||
|
|||||||
Reference in New Issue
Block a user