networking i guess
This commit is contained in:
@@ -25,6 +25,7 @@ public:
|
||||
FunnyModel_t *LoadModelFromParams( const char *szMesh, const char *szMaterial );
|
||||
|
||||
uint32_t LoadShader( const char *szName );
|
||||
FunnyShader_t *GetShaderByIndex( uint32_t uIndex );
|
||||
void UnrefShader( uint32_t uIndex );
|
||||
|
||||
FunnyModel_t *m_models[MAX_MODEL_COUNT] = {};
|
||||
@@ -46,6 +47,10 @@ FunnyMaterial_t *CAssetManager::GetMaterialByIndex( uint32_t uIndex )
|
||||
{
|
||||
return m_materials[uIndex];
|
||||
}
|
||||
FunnyShader_t *CAssetManager::GetShaderByIndex( uint32_t uIndex )
|
||||
{
|
||||
return m_shaders[uIndex];
|
||||
}
|
||||
|
||||
|
||||
uint32_t CAssetManager::LoadModel( const char *szName )
|
||||
@@ -116,7 +121,7 @@ uint32_t CAssetManager::LoadMaterial( const char *szName )
|
||||
{
|
||||
uint32_t u = 0;
|
||||
uint32_t uFoundIndex = 1;
|
||||
for ( auto &m: m_models)
|
||||
for ( auto &m: m_materials)
|
||||
{
|
||||
if (m == NULL)
|
||||
{
|
||||
@@ -125,17 +130,51 @@ uint32_t CAssetManager::LoadMaterial( const char *szName )
|
||||
}
|
||||
if (m->m_szName == szName)
|
||||
{
|
||||
m_modelUsages[uFoundIndex]++;
|
||||
m_materialsUsages[uFoundIndex]++;
|
||||
return u;
|
||||
}
|
||||
u++;
|
||||
}
|
||||
for ( auto &m: m_models)
|
||||
for ( auto &m: m_materials)
|
||||
{
|
||||
if (m == NULL)
|
||||
break;
|
||||
uFoundIndex++;
|
||||
}
|
||||
IFileHandle *pHandle = filesystem->Open(szName, FILEMODE_READ);
|
||||
CUtlString szProperties = filesystem->ReadString(pHandle);
|
||||
IJSONValue *pRoot = JSONManager()->ReadString(szProperties);
|
||||
IJSONObject *pMainObject;
|
||||
switch (pRoot->GetType())
|
||||
{
|
||||
case JSON_PARAMETER_OBJECT:
|
||||
{
|
||||
pMainObject = pRoot->GetObject();
|
||||
if (!pMainObject)
|
||||
{
|
||||
V_printf("Failed to load properties\n");
|
||||
return 0;
|
||||
|
||||
}
|
||||
IJSONValue *pShaderValue = pMainObject->GetValue("shader");
|
||||
CUtlString szShader = pShaderValue->GetStringValue();
|
||||
CBaseMaterial *pMaterial = CreateMaterial(szShader);
|
||||
|
||||
uint32_t uShaderId = LoadShader(pMaterial->GetShaderPath());
|
||||
FunnyShader_t *pShader = GetShaderByIndex(uShaderId);
|
||||
m_materials[uFoundIndex] = new FunnyMaterial_t;
|
||||
m_materials[uFoundIndex]->m_pShaders = pShader->m_pShader;
|
||||
m_materials[uFoundIndex]->m_pMaterial = g_pRenderContext->CreateMaterial(pShader->m_pShader);
|
||||
m_materials[uFoundIndex]->m_pLayout = pMaterial;
|
||||
m_materialsUsages[uFoundIndex]++;
|
||||
|
||||
return uFoundIndex;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return uFoundIndex;
|
||||
}
|
||||
|
||||
void CAssetManager::UnrefMaterial( uint32_t uIndex )
|
||||
@@ -163,6 +202,8 @@ FunnyModel_t *CAssetManager::LoadModelFromParams( const char *szMesh, const char
|
||||
pModel->m_szName = szMesh;
|
||||
pModel->m_pMesh = g_pWorldRenderer->CreateMesh(szMesh);
|
||||
pModel->m_pMesh->SetVertices(pVertexBuffer);
|
||||
uint32_t uMaterial = LoadMaterial(szMaterial);
|
||||
pModel->m_pFunnyMaterial = GetMaterialByIndex(uMaterial);
|
||||
return pModel;
|
||||
}
|
||||
|
||||
@@ -200,6 +241,7 @@ uint32_t CAssetManager::LoadShader( const char *szName )
|
||||
FunnyShader_t *pFunnyShader = new FunnyShader_t;
|
||||
pFunnyShader->m_szName = szName;
|
||||
pFunnyShader->m_pShader = pShader;
|
||||
m_shaders[uFoundIndex] = pFunnyShader;
|
||||
return uFoundIndex;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user