lots of updates

This commit is contained in:
2026-02-19 00:39:20 +02:00
parent 898bf90504
commit 4dd2e13c48
53 changed files with 1495 additions and 250 deletions

View File

@@ -11,6 +11,9 @@ ADD_DEPENDENCY_BUILD_FILE(ms, "materialsystem/build.cpp");
ADD_DEPENDENCY_BUILD_FILE(fs, "external/funnystdlib/stdfilesystems/build.cpp");
ADD_DEPENDENCY_BUILD_FILE(tier0, "external/funnystdlib/tier0/build.cpp");
ADD_DEPENDENCY_BUILD_FILE(fsc, "shadercompiler/build.cpp");
ADD_DEPENDENCY_BUILD_FILE(server, "game/server/build.cpp");
ADD_DEPENDENCY_BUILD_FILE(client, "game/client/build.cpp");
#define EXTERNAL "external/"
DECLARE_BUILD_STAGE(install_game)
{
@@ -22,6 +25,14 @@ DECLARE_BUILD_STAGE(install_game)
filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(tier0, "tier0"));
filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(filesystem_std, "fs"));
filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(shadercompiler, "fs"));
filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(Server, "server"));
filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(Client, "client"));
filesystem2->CopyDirectory(CUtlString("%s/core",szOutputDir.GetString()), "build/funnygame/assets/shaders");
if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_WINDOWS)
{
filesystem2->CopyFile(szOutputDir, EXTERNAL "windows/libgcc_s_seh-1.dll");
filesystem2->CopyFile(szOutputDir, EXTERNAL "windows/libwinpthread-1.dll");
filesystem2->CopyFile(szOutputDir, EXTERNAL "windows/libstdc++-6.dll");
}
return 0;
}

View File

@@ -1 +1,30 @@
#include "cl_dll.h"
#include "tier1/interface.h"
#include "tier0/platform.h"
#include "icvar.h"
void CClientGameDLL::Init()
{
void *pLib;
#ifdef __linux
pLib = Plat_LoadLibrary("libclient.so");
#endif
if (!pLib)
Plat_FatalErrorFunc("Failed to load server library\n");
m_pLibrary = pLib;
CreateInterfaceFn pfnServerFactory = Sys_GetFactory(pLib);
IEngineBridge *pEngineBridge = (IEngineBridge*)pfnServerFactory(ENGINE_BRIDGE_INTERFACE_VERSION, NULL);
pEngineBridge->ConnectInterface(RENDER_CONTEXT_INTERFACE_VERSION, m_pRenderContext);
pEngineBridge->ConnectInterface("MainWindow", m_pGameWindow);
pEngineBridge->Init();
m_pBridge = pEngineBridge;
}
void CClientGameDLL::Shutdown()
{
}

View File

@@ -6,12 +6,15 @@
#include "tier0/commandline.h"
#include "tier0/mem.h"
#include "sv_dll.h"
#include "cglm/cglm.h"
#include "cl_dll.h"
IRenderContext *g_pRenderContext;
IFileSystem *filesystem;
IGameWindowManager *g_pWindowManager;
CServerGameDLL *g_pServerGame;
CClientGameDLL *g_pClientGame;
extern "C" void FunnyMain( int argc, char **argv )
{
CommandLine()->CreateCommandLine(argc, argv);
@@ -38,81 +41,24 @@ extern "C" void FunnyMain( int argc, char **argv )
g_pRenderContext->RegisterGameWindow(pWindow);
ServerGameDLL()->Init();
IShader *pShader = NULL;
IBuffer *pCameraInfoBuffer = NULL;
IMaterial *pMaterial = NULL;
g_pServerGame = new CServerGameDLL;
g_pServerGame->m_pGameWindow = pWindow;
g_pServerGame->m_pRenderContext = g_pRenderContext;
g_pServerGame->Init();
IImage *pOutputImage = NULL;
IVertexBuffer *pVertices = NULL;
float vertices[18] = {
-0.5, -0.5, 0.5,
0.5, -0.5, 0.5,
-0.5, 0.5, 0.5,
-0.5, 0.5, 0.5,
0.5, -0.5, 0.5,
0.5, 0.5, 0.5
};
mat4 mat;
glm_mat4_identity(mat);
pVertices = g_pRenderContext->CreateVertexBuffer(72);
void *pMapped = pVertices->Map();
V_memcpy(pMapped, vertices, 72);
pVertices->Unmap();
pCameraInfoBuffer = g_pRenderContext->CreateConstantBuffer(64);
pMapped = pCameraInfoBuffer->Map();
V_memcpy(pMapped, mat, 64);
pCameraInfoBuffer->Unmap();
pShader = g_pRenderContext->CreateShader("game/core/shaders/flat.shader_c");
pShader->AddLayout(0, 12);
pShader->AddAttribute(0, 0, VERTEX_FORMAT_XYZ32_SFLOAT, 0);
pShader->AddOutputImage(0, IMAGE_FORMAT_RGBA8_UNORM);
pShader->Build();
pMaterial = g_pRenderContext->CreateMaterial(pShader);
pMaterial->PSSetConstantsBuffer(0, pCameraInfoBuffer);
pOutputImage = g_pRenderContext->CreateRenderTarget(
100,
100,
IMAGE_FORMAT_RGBA8_UNORM,
MULTISAMPLE_TYPE_NONE);
g_pClientGame = new CClientGameDLL;
g_pClientGame->m_pGameWindow = pWindow;
g_pClientGame->m_pRenderContext = g_pRenderContext;
g_pClientGame->Init();
for (;;) {
g_pWindowManager->Frame(0);
if (pWindow->BRenderSizeUpdated())
{
g_pRenderContext->DestroyImage(pOutputImage);
pOutputImage = g_pRenderContext->CreateRenderTarget(
pWindow->GetRenderWidth(),
pWindow->GetRenderHeight(),
IMAGE_FORMAT_RGBA8_UNORM,
MULTISAMPLE_TYPE_NONE);
}
g_pServerGame->m_pBridge->Frame(0);
g_pClientGame->m_pBridge->Frame(0);
IRenderCommandList *pCommandList = g_pRenderContext->CreateCommandList();
pCommandList->StartRecording();
pCommandList->SetRenderResolution(pWindow->GetRenderWidth(), pWindow->GetRenderHeight());
pCommandList->SetRenderTarget(0, pOutputImage);
pCommandList->SetClearColor(0, 0, 0, 0, 0);
pCommandList->SetMaterial(pMaterial);
pCommandList->SetVertexBuffer(0, pVertices);
pCommandList->DrawPrimitives(6, 0, 1, 0);
pCommandList->EndRecording();
pWindow->SetOutputImage(pOutputImage);
g_pRenderContext->SubmitCommandList(pCommandList);
g_pRenderContext->Frame(0);
g_pRenderContext->DestroyCommandList(pCommandList);
};
};

View File

@@ -1,11 +1,24 @@
#include "sv_dll.h"
#include "tier1/interface.h"
#include "tier0/platform.h"
#include "icvar.h"
void CServerGameDLL::Init()
{
#if defined(__linux__)
void *pLib;
#ifdef __linux
pLib = Plat_LoadLibrary("libserver.so");
#endif
if (!pLib)
Plat_FatalErrorFunc("Failed to load server library\n");
m_pLibrary = pLib;
CreateInterfaceFn pfnServerFactory = Sys_GetFactory(pLib);
IEngineBridge *pEngineBridge = (IEngineBridge*)pfnServerFactory(ENGINE_BRIDGE_INTERFACE_VERSION, NULL);
pEngineBridge->Init();
m_pBridge = pEngineBridge;
}
void CServerGameDLL::Shutdown()
@@ -13,9 +26,3 @@ void CServerGameDLL::Shutdown()
}
CServerGameDLL *ServerGameDLL()
{
static CServerGameDLL s_serverdll;
return &s_serverdll;
}

BIN
external/windows/libstdc++-6.dll vendored Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,2 +0,0 @@
parent rtt_simple_pbr
albedo textures/bricks.png

View File

@@ -0,0 +1,4 @@
{
"shader": "mesh_raster.shader",
"albedo": "bricks.png"
}

Binary file not shown.

View File

@@ -0,0 +1,7 @@
[
{
"model": "cube.fmesh",
"material": "cube.fmat",
"physics": "cube.fmesh"
}
]

View File

@@ -0,0 +1,33 @@
float GetSpecularThreshold( float m_fMetalness )
{
return 0;
}
struct BRDF_Data
{
float3 m_vRayIn;
float3 m_vRayOut;
float3 m_vNormal;
float3 m_vAlbedo;
float m_fRoughness;
float m_fMetalness;
float FresnelDiffuseTerm( float fSine )
{
return (fSine * (1 - 0.5 * m_fRoughness) + 0.5 * m_fRoughness);
}
float3 BurleyDiffuse( )
{
float fSineNormalLight = saturate(dot(m_vNormal, m_vRayOut));
float fSineNormalView = saturate(dot(m_vNormal, m_vRayIn));
float fFresnelLight = FresnelDiffuseTerm(fSineNormalLight);
float fFresnelView = FresnelDiffuseTerm(fSineNormalView);
return fFresnelView * fFresnelLight;
}
float3 GetOutGoingDirection()
{
return 0;
}
}

View File

@@ -0,0 +1,12 @@
#include "../macros.hlsl"
COMMON
{
}
VS
{
}
PS
{
}

View File

@@ -1,17 +1,4 @@
#define COMMON using namespace Common; namespace Common
#ifdef VS_SHADER
#define VS using namespace VertexShader; namespace VertexShader
#else
#define VS namespace VertexShader_DO_NOT_USE
#endif
#ifdef PS_SHADER
#define PS using namespace PixelShader; namespace PixelShader
#else
#define PS namespace PixelShader_DO_NOT_USE
#endif
#include "macros.hlsl"
COMMON
{

View File

@@ -1,2 +0,0 @@
[Inputs]

View File

@@ -1,3 +1,6 @@
#ifndef MACROS_H
#define MACROS_H
#define COMMON using namespace Common; namespace Common
#ifdef VS_SHADER
@@ -12,32 +15,4 @@
#define PS namespace PixelShader_DO_NOT_USE
#endif
COMMON
{
struct PS_INPUT
{
float4 m_vPosition : SV_Position;
}
}
VS
{
struct VS_INPUT
{
float3 m_vPosition: POSITION;
}
PS_INPUT vsMain( VS_INPUT i )
{
PS_INPUT o;
o.m_vPosition = { i.m_vPosition, 1 };
return o;
}
}
PS
{
float4 psMain( PS_INPUT i )
{
return float4(1);
}
}
#endif

View File

@@ -0,0 +1,54 @@
#include "macros.hlsl"
COMMON {
cbuffer CameraInfo
{
float4x4 g_matViewProjection;
};
struct PerModelData
{
float4x4 m_matTranslation;
}
StructuredBuffer<PerModelData> g_modelData;
struct PS_INPUT
{
float4 m_vScreenPosition: SV_POSITION;
float4 m_vWorldPosition: POSITION;
}
}
VS
{
struct VS_INPUT
{
float3 m_vPosition: POSITION;
}
PS_INPUT vsMain( VS_INPUT input )
{
PS_INPUT output = {};
output.m_vScreenPosition = float4(input.m_vPosition, 1);
output.m_vScreenPosition = mul(
output.m_vScreenPosition,
g_modelData[0].m_matTranslation
);
output.m_vScreenPosition = mul(
output.m_vScreenPosition,
g_matViewProjection
);
output.m_vWorldPosition = float4(input.m_vPosition, 1);
return output;
}
}
PS
{
#include "brdf.hlsl"
float4 psMain( PS_INPUT input )
{
float4 vWorldSpacePosition = input.m_vWorldPosition;
return float4(vWorldSpacePosition);
}
}

View File

@@ -1,38 +0,0 @@
#include "helper.h"
#include "c.h"
#include "ld.h"
#include "tier1/utlstring.h"
#include "tier1/commandline.h"
CUtlVector<CUtlString> client_CompiledFiles = {
};
DECLARE_BUILD_STAGE(client)
{
CProject_t compileProject = {};
LinkProject_t ldProject = {};
compileProject.m_szName = "client";
compileProject.files = client_CompiledFiles;
compileProject.includeDirectories = all_IncludeDirectories;
compileProject.bFPIC = true;
ldProject = ccompiler->Compile(&compileProject);
if (bStaticBuild)
ldProject.linkType = ELINK_STATIC_LIBRARY;
else
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
CUtlString outputProject = linker->Link(&ldProject);
/*
if (!bStaticBuild)
{
filesystem2->MakeDirectory(CUtlString("%s/funnygame/bin",szOutputDir.GetString()));
filesystem2->CopyFile(CUtlString("%s/funnygame/bin", szOutputDir.GetString()), outputProject);
} else {
client_lib = outputProject;
}
*/
return 0;
};

43
game/client/build.cpp Normal file
View File

@@ -0,0 +1,43 @@
#include "helper.h"
#include "c.h"
#include "ld.h"
#define EXTERNAL "../../external/"
#define FUNNYSTDLIB EXTERNAL"funnystdlib/"
ADD_DEPENDENCY_BUILD_FILE(tier0, FUNNYSTDLIB"tier0/build.cpp");
ADD_DEPENDENCY_BUILD_FILE(tier1, FUNNYSTDLIB"tier1/build.cpp");
ADD_DEPENDENCY_BUILD_FILE(tier2, FUNNYSTDLIB"tier2/build.cpp");
DECLARE_BUILD_STAGE(Client)
{
CProject_t compileProject = {};
LinkProject_t ldProject = {};
compileProject.m_szName = "client";
compileProject.files = {
"game.cpp",
"worldrender.cpp",
};
compileProject.includeDirectories = {
"../../public",
FUNNYSTDLIB"public",
EXTERNAL"cglm/include"
};
compileProject.bFPIC = true;
ldProject = ccompiler->Compile(&compileProject);
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
ldProject.libraryObjects = {
GET_PROJECT_LIBRARY(tier0, "tier0"),
};
ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier1, "tier1")});
ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier2, "tier2")});
if (ldProject.m_target.kernel & TARGET_KERNEL_WINDOWS_DEVICES)
{
ldProject.libraries.AppendTail("pthread");
};
CUtlString outputProject = linker->Link(&ldProject);
ADD_OUTPUT_OBJECT("client", outputProject);
return 0;
}

12
game/client/engine.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef ENGINE_H
#define ENGINE_H
#include "tier2/ifilesystem.h"
#include "materialsystem/imaterialsystem.h"
#include "materialsystem/igamewindow.h"
extern IFileSystem *filesystem;
extern IRenderContext *g_pRenderContext;
extern IGameWindow *g_pMainWindow;
#endif

94
game/client/game.cpp Normal file
View File

@@ -0,0 +1,94 @@
#include "tier2/ifilesystem.h"
#include "materialsystem/imaterialsystem.h"
#include "enginebridge.h"
#include "worldrender.h"
#include "cglm/mat4.h"
#include "cglm/cglm.h"
IFileSystem *filesystem;
IRenderContext *g_pRenderContext;
IGameWindow *g_pMainWindow;
class CFunnyGameBridge: public IEngineBridge
{
virtual void Init() override;
virtual void Tick( float fDelta ) override;
virtual void Frame( float fDelta ) override;
virtual void Shutdown() override;
virtual void ConnectInterface( const char *psz, void *pInterface ) override;
};
IEngineBridge *EngineBridge()
{
static CFunnyGameBridge s_bridge;
return &s_bridge;
}
EXPOSE_INTERFACE_FN(EngineBridge, IEngineBridge, ENGINE_BRIDGE_INTERFACE_VERSION)
void CFunnyGameBridge::Init()
{
IVertexBuffer *pBuffer;
IBuffer *pDataBuffer;
IShader *pShader;
IMaterial *pMaterial;
g_pWorldRenderer->Init();
pShader = g_pRenderContext->CreateShader("game/core/shaders/mesh_raster.shader_c");
float cubeVertices[][3] = {
{-1, -1, 1}, { 1, -1, 1}, { 1, 1, 1},
{-1, -1, 1}, { 1, 1, 1}, {-1, 1, 1},
{-1, -1, -1}, {-1, 1, -1}, { 1, 1, -1},
{-1, -1, -1}, { 1, 1, -1}, { 1, -1, -1},
{-1, -1, -1}, {-1, -1, 1}, {-1, 1, 1},
{-1, -1, -1}, {-1, 1, 1}, {-1, 1, -1},
{ 1, -1, -1}, { 1, 1, -1}, { 1, 1, 1},
{ 1, -1, -1}, { 1, 1, 1}, { 1, -1, 1},
{-1, 1, -1}, {-1, 1, 1}, { 1, 1, 1},
{-1, 1, -1}, { 1, 1, 1}, { 1, 1, -1},
{-1, -1, -1}, { 1, -1, -1}, { 1, -1, 1},
{-1, -1, -1}, { 1, -1, 1}, {-1, -1, 1}
};
pBuffer = g_pRenderContext->CreateVertexBuffer(sizeof(cubeVertices));
pBuffer->Lock();
void *pMapped = pBuffer->Map();
V_memcpy(pMapped, cubeVertices, sizeof(cubeVertices));
pBuffer->Unmap();
pBuffer->Unlock();
IMesh *pMesh = g_pWorldRenderer->CreateMesh("Triangle");
g_pWorldRenderer->SetCameraPosition((Vector){0,0,-20});
g_pWorldRenderer->SetCameraRotation((Quat){1,0,0,0});
pMesh->ConfigureShader(pShader);
pShader->Build();
pMaterial = g_pRenderContext->CreateMaterial(pShader);
pMesh->SetVertices(pBuffer);
pMesh->SetMaterial(pMaterial);
IMeshInstance *pMeshInstance = g_pWorldRenderer->CreateInstance(pMesh);
pMeshInstance->SetPosition({1,1,1});
}
void CFunnyGameBridge::Tick( float fDelta )
{
}
void CFunnyGameBridge::Frame( float fDelta )
{
g_pWorldRenderer->Frame(fDelta);
}
void CFunnyGameBridge::Shutdown()
{
}
#define CONNECT_INTERFACE(szName, pGlobal) if (!V_strcmp(psz, szName)) { pGlobal = (typeof(pGlobal))pInterface; return; }
void CFunnyGameBridge::ConnectInterface( const char *psz, void *pInterface )
{
CONNECT_INTERFACE(RENDER_CONTEXT_INTERFACE_VERSION, g_pRenderContext);
CONNECT_INTERFACE("MainWindow", g_pMainWindow);
}

269
game/client/worldrender.cpp Normal file
View File

@@ -0,0 +1,269 @@
#include "worldrender.h"
#include "tier1/utlstring.h"
#include "engine.h"
#include "cglm/cglm.h"
#include "cglm/quat.h"
#include "cglm/mat4.h"
struct ViewBuffer_t
{
mat4 m_matCameraProjection;
};
struct PerMeshData_t
{
mat4 m_matTranslation;
};
class CFunnyMeshInstance;
class CFunnyMesh: public IMesh
{
public:
virtual void ConfigureShader( IShader *pShader ) override;
virtual void SetVertices( IVertexBuffer *pBuffer ) override;
virtual void SetIndicies( IIndexBuffer *pBuffer, EIndexFormat eIndexFormat ) override;
virtual void SetMaterial( IMaterial *pMaterial ) override;
CUtlString m_szName;
CUtlVector<CFunnyMeshInstance*> m_instances;
IMaterial *m_pMaterial;
IVertexBuffer *m_pVertexBuffer;
};
void CFunnyMesh::ConfigureShader( IShader *pShader )
{
pShader->AddLayout(0, 12);
pShader->AddAttribute(0, 0, VERTEX_FORMAT_XYZ32_SFLOAT, 0);
// color
pShader->AddOutputImage(0, IMAGE_FORMAT_RGBA8_UNORM);
pShader->SetDepthImage(IMAGE_FORMAT_D32_SFLOAT);
}
void CFunnyMesh::SetVertices( IVertexBuffer *pBuffer )
{
m_pVertexBuffer = pBuffer;
}
void CFunnyMesh::SetIndicies( IIndexBuffer *pBuffer, EIndexFormat eIndexFormat )
{
}
void CFunnyMesh::SetMaterial( IMaterial *pMaterial )
{
m_pMaterial = pMaterial;
}
class CFunnyMeshInstance: public IMeshInstance
{
public:
virtual void SetPosition( Vector vPosition ) override;
virtual void SetRotation( Quat vRotation ) override;
virtual void SetScale( Vector vScale ) override;
virtual void Frame();
PerMeshData_t m_data = {};
Quat m_vRotation = {};
Vector m_vPosition = {};
Vector m_vScale = {};
};
void CFunnyMeshInstance::SetPosition( Vector vPosition )
{
m_vPosition = vPosition;
}
void CFunnyMeshInstance::SetRotation( Quat vRotation )
{
m_vRotation = vRotation;
}
void CFunnyMeshInstance::SetScale( Vector vScale )
{
m_vScale = vScale;
}
void CFunnyMeshInstance::Frame()
{
glm_mat4_identity(m_data.m_matTranslation);
}
class CFunnyWorldRenderer: public IWorldRenderer
{
public:
virtual void Init() override;
virtual void Tick( float fDelta ) override;
virtual void Frame( float fDelta ) override;
virtual void Shutdown() override;
virtual void SetCameraRotation( Quat vRotation ) override;
virtual void SetCameraPosition( Vector vPosition ) override;
virtual IMesh *CreateMesh( const char *szName ) override;
virtual IMeshInstance *CreateInstance( IMesh *pMesh ) override;
private:
CUtlVector<CFunnyMesh*> m_pMeshes;
IImage *m_pOutputImage = NULL;
IImage *m_pDepthImage = NULL;
IRenderCommandList *m_pRasterCommandList = NULL;
IBuffer *m_pViewBuffer;
ViewBuffer_t *m_pViewBufferData;
vec3 m_vPos;
versor m_vRot;
};
static CFunnyWorldRenderer s_renderer;
IWorldRenderer *g_pWorldRenderer = &s_renderer;
void CFunnyWorldRenderer::Init()
{
m_pOutputImage = g_pRenderContext->CreateRenderTarget(
100,
100,
IMAGE_FORMAT_RGBA8_UNORM,
MULTISAMPLE_TYPE_NONE
);
m_pDepthImage = g_pRenderContext->CreateRenderTarget(
100,
100,
IMAGE_FORMAT_D32_SFLOAT,
MULTISAMPLE_TYPE_NONE
);
g_pMainWindow->SetOutputImage(m_pOutputImage);
m_pRasterCommandList = g_pRenderContext->CreateCommandList();
m_pViewBuffer = g_pRenderContext->CreateConstantBuffer(sizeof(ViewBuffer_t));
}
void CFunnyWorldRenderer::Tick( float fDelta )
{
}
void CFunnyWorldRenderer::Frame( float fDelta )
{
uint32_t uWidth = g_pMainWindow->GetRenderWidth();
uint32_t uHeight = g_pMainWindow->GetRenderHeight();
mat4 matCamera;
glm_perspective(glm_rad(60), uWidth/(float)uHeight, 0.01, 100, matCamera);
glm_translate(matCamera, m_vPos);
/*
V_printf("%f %f %f %f\n", matCamera[0][0], matCamera[0][1], matCamera[0][2], matCamera[0][3]);
V_printf("%f %f %f %f\n", matCamera[1][0], matCamera[1][1], matCamera[1][2], matCamera[1][3]);
V_printf("%f %f %f %f\n", matCamera[2][0], matCamera[2][1], matCamera[2][2], matCamera[2][3]);
V_printf("%f %f %f %f\n", matCamera[3][0], matCamera[3][1], matCamera[3][2], matCamera[3][3]);
*/
m_pViewBufferData = (ViewBuffer_t*)m_pViewBuffer->Map();
m_pViewBuffer->Lock();
V_memcpy(m_pViewBufferData, matCamera, sizeof(matCamera));
m_pViewBuffer->Unlock();
m_pViewBuffer->Unmap();
if (g_pMainWindow->BRenderSizeUpdated())
{
g_pRenderContext->DestroyImage(m_pOutputImage);
m_pOutputImage = g_pRenderContext->CreateRenderTarget(
g_pMainWindow->GetRenderWidth(),
g_pMainWindow->GetRenderHeight(),
IMAGE_FORMAT_RGBA8_UNORM,
MULTISAMPLE_TYPE_NONE);
g_pRenderContext->DestroyImage(m_pOutputImage);
m_pDepthImage = g_pRenderContext->CreateRenderTarget(
g_pMainWindow->GetRenderWidth(),
g_pMainWindow->GetRenderHeight(),
IMAGE_FORMAT_D32_SFLOAT,
MULTISAMPLE_TYPE_NONE);
g_pMainWindow->SetOutputImage(m_pOutputImage);
}
m_pRasterCommandList->StartRecording();
m_pRasterCommandList->SetRenderResolution(uWidth, uHeight);
m_pRasterCommandList->SetRenderTarget(0, m_pOutputImage);
m_pRasterCommandList->SetDepthTarget(m_pDepthImage);
m_pRasterCommandList->SetViewport(0, 0, uWidth, uHeight, 0, 1);
m_pRasterCommandList->SetScissors(0, 0, uWidth, uHeight);
m_pRasterCommandList->SetClearColor(0, 0, 0, 0, 0);
m_pRasterCommandList->SetClearDepth(1);
for ( auto mesh: m_pMeshes)
{
if (mesh->m_instances.GetSize()==0)
continue;
CUtlVector<PerMeshData_t> data = {};
data.Reserve(mesh->m_instances.GetSize());
for ( auto instance: mesh->m_instances )
{
instance->Frame();
data.AppendTail(instance->m_data);
}
IBuffer *pDataBuffer = g_pRenderContext->CreateStorageBuffer(data.GetSize()*sizeof(PerMeshData_t));
pDataBuffer->Lock();
void *pData = pDataBuffer->Map();
for ( uint32_t i = 0; i < mesh->m_instances.GetSize(); i++ )
{
V_memcpy(&((PerMeshData_t*)pData)[i], &mesh->m_instances[i]->m_data, sizeof(PerMeshData_t));
}
pDataBuffer->Unmap();
pDataBuffer->Unlock();
mesh->m_pMaterial->VSSetConstantsBuffer(0, m_pViewBuffer);
mesh->m_pMaterial->VSSetConstantsBuffer(1, pDataBuffer);
g_pRenderContext->DestroyBuffer(pDataBuffer);
}
for ( auto mesh: m_pMeshes)
{
if (mesh->m_instances.GetSize()==0)
continue;
m_pRasterCommandList->SetMaterial(mesh->m_pMaterial);
m_pRasterCommandList->SetVertexBuffer(0, mesh->m_pVertexBuffer);
m_pRasterCommandList->DrawPrimitives(mesh->m_pVertexBuffer->GetSize()/12, 0, mesh->m_instances.GetSize(), 0);
}
m_pRasterCommandList->EndRecording();
g_pRenderContext->SubmitCommandList(m_pRasterCommandList);
}
void CFunnyWorldRenderer::Shutdown()
{
}
void CFunnyWorldRenderer::SetCameraRotation( Quat vRotation )
{
m_vRot[0] = vRotation.x;
m_vRot[1] = vRotation.y;
m_vRot[2] = vRotation.z;
m_vRot[3] = vRotation.w;
}
void CFunnyWorldRenderer::SetCameraPosition( Vector vPosition )
{
m_vPos[0] = vPosition.x;
m_vPos[1] = vPosition.y;
m_vPos[2] = vPosition.z;
}
IMesh *CFunnyWorldRenderer::CreateMesh( const char *szName )
{
CFunnyMesh *pMesh = new CFunnyMesh;
pMesh->m_szName = szName;
m_pMeshes.AppendTail(pMesh);
return pMesh;
}
IMeshInstance *CFunnyWorldRenderer::CreateInstance( IMesh *pMesh )
{
CFunnyMesh *pFunnyMesh = (CFunnyMesh*)pMesh;
CFunnyMeshInstance *pInstance = new CFunnyMeshInstance;
pFunnyMesh->m_instances.AppendTail(pInstance);
return pInstance;
}

40
game/client/worldrender.h Normal file
View File

@@ -0,0 +1,40 @@
#ifndef WORLD_RENDER_H
#define WORLD_RENDER_H
#include "tier0/platform.h"
#include "gamesystem.h"
#include "trig.h"
#include "materialsystem/imaterialsystem.h"
abstract_class IMesh
{
public:
virtual void ConfigureShader( IShader *pShader ) = 0;
virtual void SetVertices( IVertexBuffer *pBuffer ) = 0;
virtual void SetIndicies( IIndexBuffer *pBuffer, EIndexFormat eIndexFormat ) = 0;
virtual void SetMaterial( IMaterial *pMaterial ) = 0;
};
abstract_class IMeshInstance
{
public:
virtual void SetPosition( Vector vPosition ) = 0;
virtual void SetRotation( Quat vRotation ) = 0;
virtual void SetScale( Vector vScale ) = 0;
};
abstract_class IWorldRenderer: public IGameSystem
{
public:
virtual void SetCameraRotation( Quat vRotation ) = 0;
virtual void SetCameraPosition( Vector vPosition ) = 0;
virtual IMesh *CreateMesh( const char *szName ) = 0;
virtual IMeshInstance *CreateInstance( IMesh *pMesh ) = 0;
};
extern IWorldRenderer *g_pWorldRenderer;
#endif

View File

@@ -1,38 +0,0 @@
#include "helper.h"
#include "c.h"
#include "ld.h"
#include "tier1/utlstring.h"
#include "tier1/commandline.h"
CUtlVector<CUtlString> server_CompiledFiles = {
"game/server/game.cpp",
"game/server/milmoba/player.cpp",
};
DECLARE_BUILD_STAGE(server)
{
CProject_t compileProject = {};
LinkProject_t ldProject = {};
compileProject.m_szName = "server";
compileProject.files = server_CompiledFiles;
compileProject.includeDirectories = all_IncludeDirectories;
compileProject.bFPIC = true;
ldProject = ccompiler->Compile(&compileProject);
if (bStaticBuild)
ldProject.linkType = ELINK_STATIC_LIBRARY;
else
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
CUtlString outputProject = linker->Link(&ldProject);
if (!bStaticBuild)
{
filesystem2->MakeDirectory(CUtlString("%s/funnygame/bin",szOutputDir.GetString()));
filesystem2->CopyFile(CUtlString("%s/funnygame/bin", szOutputDir.GetString()), outputProject);
} else {
server_lib = outputProject;
}
return 0;
};

109
game/server/baseentity.cpp Normal file
View File

@@ -0,0 +1,109 @@
//================= Copyright kotofyt, All rights reserved ==================//
//
// Purpose:
//
//===========================================================================//
#include "baseentity.h"
#include "datamap.h"
#include "tier0/lib.h"
CBaseEntity::~CBaseEntity()
{
}
void CBaseEntity::Spawn()
{
}
void CBaseEntity::SetAbsAngles( float fPitch, float fYaw, float fRoll )
{
}
void CBaseEntity::SetAbsOrigin( Vector origin )
{
m_vPosition = origin;
}
void CBaseEntity::SetScale( float fScale )
{
m_vScale.x = fScale;
m_vScale.y = fScale;
m_vScale.z = fScale;
}
QAngle CBaseEntity::GetAbsAngles( void )
{
}
Vector CBaseEntity::GetAbsOrigin( void )
{
}
float CBaseEntity::GetScale( void )
{
}
void CBaseEntity::SetThink( fnThink pfnThink )
{
m_pfnThink = pfnThink;
}
void CBaseEntity::SetNextThink( float fThink )
{
}
typedescription_t *CBaseEntity::FindDataByName( const char *szName )
{
datamap_t *pDataMap;
int i;
pDataMap = GetDataMap();
lookforname:
for ( i = 0; i < pDataMap->m_iNumFields; i++ )
{
if (!V_strcmp(pDataMap->m_pData[i].m_szFieldName, szName))
return &pDataMap->m_pData[i];
}
pDataMap = pDataMap->m_pBase;
if (pDataMap)
goto lookforname;
return NULL;
};
typedescription_t *CBaseEntity::FindDataByMapName( const char *szName )
{
datamap_t *pDataMap;
int i;
pDataMap = GetDataMap();
lookforname:
for ( i = 0; i < pDataMap->m_iNumFields; i++ )
{
if (!V_strcmp(pDataMap->m_pData[i].m_szEditorName, szName))
return &pDataMap->m_pData[i];
}
pDataMap = pDataMap->m_pBase;
if (pDataMap)
goto lookforname;
return NULL;
};
BEGIN_DATADESC_NOBASE(CBaseEntity)
DEFINE_KEYFIELD(m_vPosition, FIELD_VECTOR, "origin")
DEFINE_KEYFIELD(m_vRotation, FIELD_QUATERNION, "angles")
DEFINE_KEYFIELD(m_vScale, FIELD_VECTOR, "scales")
END_DATADESC()

79
game/server/baseentity.h Normal file
View File

@@ -0,0 +1,79 @@
//================= Copyright kotofyt, All rights reserved ==================//
//
// Purpose:
//
//===========================================================================//
#ifndef BASEENTITY_H
#define BASEENTITY_H
#include "entitysystem.h"
#include "datamap.h"
#include "cglm/cglm.h"
#include "trig.h"
#define DECLARE_CLASS_NOBASE( className ) \
typedef className ThisClass;
#define DECLARE_CLASS( className, baseName ) \
typedef baseName BaseClass; \
typedef className ThisClass;
#define LINK_ENTITY_TO_CLASS( mapClassName, DLLClassName) \
static CEntityFactory<DLLClassName> g_EntityFactory_##mapClassName( #mapClassName );
class CBaseEntity;
class IEntityFactory
{
public:
virtual CBaseEntity *Create() = 0;
};
template<class T>
class CEntityFactory : public IEntityFactory
{
public:
CEntityFactory( const char *szClassName )
{
EntitySystem()->RegisterEntityClass(this, szClassName);
};
virtual CBaseEntity *Create() {
return new T;
}
};
class CBaseEntity;
typedef void(*fnThink)( CBaseEntity *pThis );
class CBaseEntity
{
public:
DECLARE_CLASS_NOBASE(CBaseEntity);
DECLARE_DATADESC_NOBASE()
typedescription_t *FindDataByName( const char *szName );
typedescription_t *FindDataByMapName( const char *szName );
virtual ~CBaseEntity();
virtual void Spawn();
virtual void SetAbsAngles( float fPitch, float fYaw, float fRoll );
virtual void SetAbsOrigin( Vector origin );
virtual void SetScale( float fScale );
virtual QAngle GetAbsAngles( void );
virtual Vector GetAbsOrigin( void );
virtual float GetScale( void );
virtual void SetThink( fnThink pfnThink );
virtual void SetNextThink( float fThink );
fnThink m_pfnThink = NULL;
private:
Vector m_vPosition;
Quat m_vRotation;
Vector m_vScale;
};
#endif

44
game/server/build.cpp Normal file
View File

@@ -0,0 +1,44 @@
#include "helper.h"
#include "c.h"
#include "ld.h"
#define EXTERNAL "../../external/"
#define FUNNYSTDLIB EXTERNAL"funnystdlib/"
ADD_DEPENDENCY_BUILD_FILE(tier0, FUNNYSTDLIB"tier0/build.cpp");
ADD_DEPENDENCY_BUILD_FILE(tier1, FUNNYSTDLIB"tier1/build.cpp");
ADD_DEPENDENCY_BUILD_FILE(tier2, FUNNYSTDLIB"tier2/build.cpp");
DECLARE_BUILD_STAGE(Server)
{
CProject_t compileProject = {};
LinkProject_t ldProject = {};
compileProject.m_szName = "server";
compileProject.files = {
"game.cpp",
"entitysystem.cpp",
"baseentity.cpp",
};
compileProject.includeDirectories = {
"../../public",
FUNNYSTDLIB"public",
EXTERNAL"cglm/include"
};
compileProject.bFPIC = true;
ldProject = ccompiler->Compile(&compileProject);
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
ldProject.libraryObjects = {
GET_PROJECT_LIBRARY(tier0, "tier0"),
};
ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier1, "tier1")});
ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier2, "tier2")});
if (ldProject.m_target.kernel & TARGET_KERNEL_WINDOWS_DEVICES)
{
ldProject.libraries.AppendTail("pthread");
};
CUtlString outputProject = linker->Link(&ldProject);
ADD_OUTPUT_OBJECT("server", outputProject);
return 0;
}

97
game/server/datamap.h Normal file
View File

@@ -0,0 +1,97 @@
//================= Copyright kotofyt, All rights reserved ==================//
//
// Purpose: Valve-styled entity data maps
//
// Note: This file is insipired by Valve's convention in Source SDK, but it
// was written for scratch with compatibility in mind.
//
//===========================================================================//
#ifndef DATAMAP_H
#define DATAMAP_H
#include "stddef.h"
enum fieldtype_t {
FIELD_VOID = 0,
FIELD_FLOAT,
FIELD_STRING,
FIELD_VECTOR2D,
FIELD_VECTOR,
FIELD_VECTOR4D,
FIELD_QUATERNION,
FIELD_QUATERNION_QANGLE,
FIELD_COLOR255,
FIELD_COLOR1,
FIELD_INTEGER,
FIELD_BOOLEAN,
FIELD_MATERIAL,
FIELD_TEXTURE,
FIELD_MODEL,
};
struct typedescription_t
{
const char *m_szFieldName;
const char *m_szEditorName;
fieldtype_t m_eFieldType;
size_t m_iFieldOffset;
unsigned int m_uFieldCount;
unsigned short m_uFieldSize;
unsigned int m_iFlags;
};
struct datamap_t
{
struct datamap_t *m_pBase;
typedescription_t *m_pData;
int m_iNumFields;
};
#define DECLARE_DATADESC() \
datamap_t *GetBaseMap(); \
virtual datamap_t *GetDataMap() override; \
virtual datamap_t DataMapInit() override;
#define DECLARE_DATADESC_NOBASE() \
datamap_t *GetBaseMap(); \
virtual datamap_t *GetDataMap(); \
virtual datamap_t DataMapInit();
#define BEGIN_DATADESC( className ) \
datamap_t *className::GetBaseMap() { return BaseClass::GetDataMap(); } \
BEGIN_DATADESC_INTERNAL(className)
#define BEGIN_DATADESC_NOBASE( className ) \
datamap_t *className::GetBaseMap() { return NULL; } \
BEGIN_DATADESC_INTERNAL(className)
#define BEGIN_DATADESC_INTERNAL( className ) \
datamap_t *className::GetDataMap() { static datamap_t s_DataMap = ThisClass::DataMapInit(); return &s_DataMap; } \
datamap_t className::DataMapInit() \
{ \
datamap_t map; \
map.m_pBase = ThisClass::GetBaseMap(); \
static typedescription_t dataDesc[] \
{\
#define END_DATADESC() \
};\
map.m_iNumFields = sizeof(dataDesc)/sizeof(typedescription_t); \
map.m_pData = dataDesc; \
return map; \
}
#define IMPLEMENT_NULL_DATADESC( className ) \
BEGIN_DATADESC(className) \
END_DATADESC()
#define _class_offsetof( class, var ) ((size_t)&(((class*)0)->var))
#define _FIELD( name, fieldtype, count, flags, mapname, tolerance) { #name, mapname, fieldtype, _class_offsetof(ThisClass, name), count, sizeof(((ThisClass*)0)->name), flags },
#define DEFINE_KEYFIELD( name, fieldtype, mapname ) _FIELD( name, fieldtype, 1, FTYPEDESC_KEY, mapname, 0)
#define FTYPEDESC_KEY 0x0004
#endif

View File

@@ -0,0 +1,120 @@
//================= Copyright kotofyt, All rights reserved ==================//
//
// Purpose:
//
//===========================================================================//
#include "entitysystem.h"
#include "baseentity.h"
#include "stddef.h"
#include "string.h"
#include "stdlib.h"
CEntitySystem *EntitySystem()
{
static CEntitySystem s_entitySystem;
return &s_entitySystem;
}
static struct EntityRegistry_t
{
IEntityFactory *m_pFactory;
const char *m_szClassName;
struct EntityRegistry_t *m_pNext;
} *s_pEntitiesRegistry = NULL;
CEntitySystem::CEntitySystem()
{
int i = 0;
for ( i = 0; i < MAX_EDICTS; i++ )
{
m_pEntities[i] = NULL;
}
m_nEntityCount = 0;
}
void CEntitySystem::RegisterEntityClass( IEntityFactory *pEntityFactory, const char *szClassName )
{
IEntityFactory *pFactory;
EntityRegistry_t *pRegistry;
pFactory = GetFactoryByClassname(szClassName);
if ( pFactory != NULL )
{
// Already registered
return;
}
pRegistry = new EntityRegistry_t;
pRegistry->m_pFactory = pEntityFactory;
pRegistry->m_pNext = s_pEntitiesRegistry;
pRegistry->m_szClassName = szClassName;
s_pEntitiesRegistry = pRegistry;
}
CBaseEntity *CEntitySystem::CreateByClassname( const char *szName )
{
IEntityFactory *pFactory;
CBaseEntity *pEntity;
int i;
int iSelectedSlot;
pFactory = GetFactoryByClassname(szName);
if ( !pFactory )
return NULL;
// We do not want to have more than MAX_EDICT entities
if ( m_nEntityCount >= MAX_EDICTS-1 )
return NULL;
// Search for space
// Could be more efficient but nobody cares
for ( i = 0; i < MAX_EDICTS; i++ )
{
if ( m_pEntities[i] == NULL )
{
iSelectedSlot = i;
break;
}
}
pEntity = pFactory->Create();
m_pEntities[iSelectedSlot] = pEntity;
m_nEntityCount++;
return pEntity;
}
IEntityFactory *CEntitySystem::GetFactoryByClassname( const char *szName )
{
EntityRegistry_t *pEntity;
for ( pEntity = s_pEntitiesRegistry; pEntity; pEntity = pEntity->m_pNext )
{
if (!strcmp(szName, pEntity->m_szClassName))
{
return pEntity->m_pFactory;
}
}
return NULL;
}
void CEntitySystem::Think()
{
CBaseEntity *pEntity;
int i;
for ( i = 0; i < MAX_EDICTS; i++ )
{
pEntity = m_pEntities[i];
if ( pEntity == NULL )
continue;
if ( !pEntity->m_pfnThink )
continue;
pEntity->m_pfnThink(pEntity);
}
}

View File

@@ -0,0 +1,33 @@
//================= Copyright kotofyt, All rights reserved ==================//
//
// Purpose:
//
//===========================================================================//
#ifndef ENTITIES_H
#define ENTITIES_H
class IEntityFactory;
class CBaseEntity;
#define MAX_EDICTS 8192
class CEntitySystem
{
public:
CEntitySystem();
virtual void RegisterEntityClass( IEntityFactory *pEntityFactory, const char *szClassName );
virtual CBaseEntity *CreateByClassname( const char *szName );
virtual IEntityFactory *GetFactoryByClassname( const char *szName );
virtual void Think();
private:
CBaseEntity *m_pEntities[MAX_EDICTS];
int m_nEntityCount;
};
CEntitySystem *EntitySystem();
#endif

View File

@@ -1 +1,49 @@
#include "tier2/ifilesystem.h"
#include "materialsystem/imaterialsystem.h"
#include "enginebridge.h"
IFileSystem *filesystem;
IRenderContext *g_pRenderContext;
IGameWindow *g_pMainWindow;
class CFunnyGameBridge: public IEngineBridge
{
virtual void Init() override;
virtual void Tick( float fDelta ) override;
virtual void Frame( float fDelta ) override;
virtual void Shutdown() override;
virtual void ConnectInterface( const char *psz, void *pInterface ) override;
};
IEngineBridge *EngineBridge()
{
static CFunnyGameBridge s_bridge;
return &s_bridge;
}
EXPOSE_INTERFACE_FN(EngineBridge, IEngineBridge, ENGINE_BRIDGE_INTERFACE_VERSION)
void CFunnyGameBridge::Init()
{
}
void CFunnyGameBridge::Tick( float fDelta )
{
}
void CFunnyGameBridge::Frame( float fDelta )
{
}
void CFunnyGameBridge::Shutdown()
{
}
#define CONNECT_INTERFACE(szName, pGlobal) if (!V_strcmp(psz, szName)) { pGlobal = (typeof(pGlobal))pInterface; return; }
void CFunnyGameBridge::ConnectInterface( const char *psz, void *pInterface )
{
}

1
game/server/scene.cpp Normal file
View File

@@ -0,0 +1 @@

4
game/server/scene.h Normal file
View File

@@ -0,0 +1,4 @@
#ifndef GAME_SCENE_H
#define GAME_SCENE_H
#endif

View File

@@ -3,7 +3,8 @@
#include "ld.h"
#include "tier1/utlstring.h"
#define FUNNYSTDLIB "../external/funnystdlib/"
#define EXTERNAL "../external/"
#define FUNNYSTDLIB EXTERNAL"funnystdlib/"
ADD_DEPENDENCY_BUILD_FILE(tier0, FUNNYSTDLIB"tier0/build.cpp");
ADD_DEPENDENCY_BUILD_FILE(tier1, FUNNYSTDLIB"tier1/build.cpp");
ADD_DEPENDENCY_BUILD_FILE(tier2, FUNNYSTDLIB"tier2/build.cpp");
@@ -26,7 +27,7 @@ CUtlVector<CUtlString> RenderContextVulkan_CompiledFiles = {
"vulkan/commands/transfer.cpp",
"vulkan/commands/base.cpp",
"vulkan/libraries/raster.cpp",
"../external/volk/volk.c",
EXTERNAL"volk/volk.c",
"gamewindow_sdl.cpp"
};
@@ -40,6 +41,7 @@ DECLARE_BUILD_STAGE(MaterialSystem)
compileProject.includeDirectories = {
"../public",
FUNNYSTDLIB"public",
EXTERNAL"SDL/include",
};
compileProject.bFPIC = true;
ldProject = ccompiler->Compile(&compileProject);
@@ -49,9 +51,9 @@ DECLARE_BUILD_STAGE(MaterialSystem)
};
ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier1, "tier1")});
if (ldProject.m_target.kernel & TARGET_KERNEL_WINDOWS_DEVICES)
if (ldProject.m_target.kernel == TARGET_KERNEL_WINDOWS)
{
ldProject.libraries.AppendTail("pthread");
ldProject.libraryDirectories.AppendTail(EXTERNAL"windows");
};
CUtlString outputProject = linker->Link(&ldProject);
@@ -72,10 +74,11 @@ DECLARE_BUILD_STAGE(RenderSystemVulkan)
compileProject.includeDirectories = {
"../public",
FUNNYSTDLIB"public",
"../external/Vulkan-Headers/include",
"../external/Vulkan-Utility-Libraries/include",
"../external/VulkanMemoryAllocator/include",
"../external/volk"
EXTERNAL"SDL/include",
EXTERNAL"Vulkan-Headers/include",
EXTERNAL"Vulkan-Utility-Libraries/include",
EXTERNAL"VulkanMemoryAllocator/include",
EXTERNAL"volk"
};
compileProject.bFPIC = true;
ldProject = ccompiler->Compile(&compileProject);
@@ -84,11 +87,21 @@ DECLARE_BUILD_STAGE(RenderSystemVulkan)
GET_PROJECT_LIBRARY(tier0, "tier0"),
};
ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier1, "tier1")});
if (ldProject.m_target.kernel & TARGET_KERNEL_WINDOWS_DEVICES)
{
ldProject.libraries.AppendTail("pthread");
};
ldProject.libraries.AppendTail("SDL3");
if (ldProject.m_target.kernel == TARGET_KERNEL_WINDOWS)
{
ldProject.libraryDirectories.AppendTail(EXTERNAL"windows");
ldProject.libraries.AppendTail("winpthread-1");
ldProject.libraries.AppendTail("winmm");
ldProject.libraries.AppendTail("ole32");
ldProject.libraries.AppendTail("gdi32");
ldProject.libraries.AppendTail("oleaut32");
ldProject.libraries.AppendTail("setupapi");
ldProject.libraries.AppendTail("imm32");
ldProject.libraries.AppendTail("version");
ldProject.libraries.AppendTail("shell32");
ldProject.libraries.AppendTail("uuid");
};
CUtlString outputProject = linker->Link(&ldProject);
ADD_OUTPUT_OBJECT("RenderSystemVulkan", outputProject);

View File

@@ -1,4 +1,3 @@
#include "SDL3/SDL_error.h"
#include "materialsystem/igamewindow.h"
#include "tier0/lib.h"
#include "tier0/platform.h"
@@ -49,7 +48,7 @@ void CSDLGameWindow::Init()
if (!m_pWindow)
Plat_FatalErrorFunc("SDL_CreateWindow: %s\n", SDL_GetError());
m_uRenderWidth = 1280;
m_uRenderWidth = 720;
m_uRenderHeight = 720;
}
void CSDLGameWindow::Shutdown()

View File

@@ -26,6 +26,7 @@ public:
virtual void Reset() override;
virtual void Submit( int iFrameIndex ) override;
virtual void Render() override;
void FreeWithCommands();
private:
void SortDependencies();
void TryBarrier( int iCurrent, int iCurrentBuffer );
@@ -40,9 +41,23 @@ private:
VkDevice m_hDevice;
IVkCommandBufferManager *m_pMgr;
VkCommandPool m_hPool;
VkCommandPool m_hPool = NULL;
};
void CVkCommandBuffer::FreeWithCommands()
{
if (m_hPool)
{
for ( auto &c: m_commands)
{
delete c;
};
vkFreeCommandBuffers(m_hDevice, m_hPool, m_hBuffers.GetSize(), m_hBuffers.GetData());
vkDestroyCommandPool(m_hDevice, m_hPool, NULL);
m_hPool = NULL;
}
}
void CVkCommandBuffer::SetVulkanHandlers( VkDevice hDevice, IVkCommandBufferManager *pManager )
{
m_hDevice = hDevice;
@@ -54,6 +69,8 @@ void CVkCommandBuffer::Reset()
VkCommandBufferAllocateInfo commandBufferAllocInfo = {};
VkCommandPoolCreateInfo stCreateInfo = {};
FreeWithCommands();
stCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
stCreateInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
vkCreateCommandPool(m_hDevice, &stCreateInfo, NULL, &m_hPool);
@@ -343,6 +360,7 @@ public:
virtual IVkCommandBuffer *CreateCommandBuffer() override;
virtual CVkCommand *CreateCommand( const char *szName ) override;
virtual CUtlVector<VkCommandBuffer> &GetVulkanCommands() override;
virtual void FreeCommandBufferWithCommands(IVkCommandBuffer* pCommandBuffer) override;
virtual void RenderingFinished() override;
private:
@@ -399,6 +417,12 @@ CUtlVector<VkCommandBuffer> &CVkCommandBufferManager::GetVulkanCommands()
{
return m_commands;
}
void CVkCommandBufferManager::FreeCommandBufferWithCommands(IVkCommandBuffer* pCommandBuffer)
{
CVkCommandBuffer *pVkBuffer = (CVkCommandBuffer*)pCommandBuffer;
pVkBuffer->FreeWithCommands();
delete pVkBuffer;
};
void CVkCommandBufferManager::RenderingFinished()
{

View File

@@ -27,9 +27,10 @@ END_VULKAN_COMMAND(ClearColor)
BEGIN_VULKAN_COMMAND(Begin)
CUtlVector<VulkanRenderOutput_t> images;
VulkanRenderOutput_t stDepthImage;
uint32_t nResolutionX;
uint32_t nResolutionY;
VulkanRenderOutput_t stDepthImage = {};
bool bDepthEnabled = {};
uint32_t nResolutionX = 0;
uint32_t nResolutionY = 0;
END_VULKAN_COMMAND(Begin)

View File

@@ -32,6 +32,7 @@ DECLARE_VULKAN_COMMAND(Begin)
{
VkRenderingInfo stRenderingInfo = {};
CUtlVector<VkRenderingAttachmentInfo> attachments = {};
VkRenderingAttachmentInfo depthAttachment = {};
for (auto i: images)
{
VkRenderingAttachmentInfo a = {};
@@ -46,6 +47,16 @@ DECLARE_VULKAN_COMMAND(Begin)
a.imageView = ((CVkImage*)VulkanGetObject(i.m_stImage, iCurrentFrame))->m_imageView;
attachments.AppendTail(a);
}
if (bDepthEnabled)
{
depthAttachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
depthAttachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
depthAttachment.clearValue.depthStencil.depth = stDepthImage.m_fClearDepth;
depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
depthAttachment.imageView = ((CVkImage*)VulkanGetObject(stDepthImage.m_stImage, iCurrentFrame))->m_imageView;
stRenderingInfo.pDepthAttachment = &depthAttachment;
}
stRenderingInfo.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
stRenderingInfo.layerCount = 1;

View File

@@ -3,16 +3,20 @@ CVkMaterial::CVkMaterial( IShader *pShader )
{
m_pVkShader = (CVkShader*)pShader;
VkDescriptorPoolSize pools[1] =
VkDescriptorPoolSize pools[2] =
{
{
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
128,
},
{
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
128,
}
};
VkDescriptorPoolCreateInfo stPool = {};
stPool.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
stPool.poolSizeCount = 1;
stPool.poolSizeCount = 2;
stPool.pPoolSizes = pools;
stPool.maxSets = 1;
stPool.flags = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT;
@@ -37,6 +41,7 @@ CVkMaterial::CVkMaterial( IShader *pShader )
switch (b.eDescriptorType)
{
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
write.pBufferInfo = new VkDescriptorBufferInfo;
break;
default:
@@ -88,6 +93,6 @@ void CVkMaterial::SetShaderResource( uint32_t uRegister, uint32_t uSet, IRenderi
((VkDescriptorBufferInfo*)m_writes[uRegister].pBufferInfo)->buffer = pBuffer->m_buffer;
((VkDescriptorBufferInfo*)m_writes[uRegister].pBufferInfo)->range = pBuffer->m_nSize;
}
Frame();
vkUpdateDescriptorSets(m_pVkShader->m_hDevice, 1, &m_writes[uRegister], 0, 0);
}

View File

@@ -1,14 +1,18 @@
#include "vulkan_state.h"
#include "commands.h"
CVkRenderCommandList::~CVkRenderCommandList()
{
ResetRendering();
}
void CVkRenderCommandList::ResetRendering()
{
/*
for ( auto m: m_materials )
{
delete m.m_pCommandBuffer;
m_pCommandBufferManager->FreeCommandBufferWithCommands(m.m_pCommandBuffer);
}
*/
m_materials = {};
}
@@ -33,7 +37,15 @@ void CVkRenderCommandList::SetClearColor( uint32_t uIndex, float r, float g, flo
void CVkRenderCommandList::SetDepthTarget( IImage *pDepth )
{
SwitchRenderingStage(RENDERING_STAGE_SETUP_RASTER);
if (pDepth)
{
m_bDepthEnabled = true;
m_depth.m_stImage.m_pSingle = pDepth;
}
else
{
m_bDepthEnabled = false;
}
}
void CVkRenderCommandList::SetClearDepth( float fVal)
@@ -76,11 +88,17 @@ void CVkRenderCommandList::SetMaterial( IMaterial *pMaterial )
pBeginCommand->images = m_pOutput;
pBeginCommand->nResolutionX = m_uWidth;
pBeginCommand->nResolutionY = m_uHeight;
pBeginCommand->stDepthImage = m_depth;
for ( auto &i: pBeginCommand->images)
{
pBeginCommand->AddDependency(i.m_stImage.m_pSingle, DEPENDENCY_MODE_DRAWCALL_OUTPUT_IMAGE);
}
if ( m_bDepthEnabled )
{
pBeginCommand->AddDependency(m_depth.m_stImage.m_pSingle, DEPENDENCY_MODE_DRAWCALL_OUTPUT_DEPTH_IMAGE);
pBeginCommand->bDepthEnabled = m_bDepthEnabled;
pBeginCommand->stDepthImage = m_depth;
}
m_pCurrentMaterialBuffer->AddCommand(pBeginCommand);
CVkSetShaderCommand *pSetShader = CREATE_COMMAND(SetShader);
@@ -207,5 +225,5 @@ IVkCommandBuffer *CVkRenderCommandList::FindOrCreateMaterialCommandBuffer( IMate
m_materials.AppendTail(mat);
if (pbWasCreated)
*pbWasCreated = true;
return m_materials.GetLast().m_pCommandBuffer;
return m_materials[m_materials.GetSize()-1].m_pCommandBuffer;
}

View File

@@ -62,7 +62,11 @@ CVkImage::CVkImage( uint32_t nWidth, uint32_t nHeight, uint32_t nDepth, EImageFo
m_eMultisampleType = eMultisampleType;
m_eImageType = eImageType;
m_eFormat = eFormat;
if (eFormat == IMAGE_FORMAT_D32_SFLOAT)
m_ePreferredLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
else
m_ePreferredLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
CreateImage(nWidth, nHeight, eFormat, eMultisampleType, eUsage);
CreateImageView();
}
@@ -211,7 +215,7 @@ CVkBuffer::CVkBuffer( uint32_t nSize, VkBufferUsageFlags2 eUsage, uint32_t nAlig
CVkBuffer::~CVkBuffer()
{
vmaDestroyBuffer(s_vkAllocator, m_buffer, m_allocation);
}
@@ -233,7 +237,9 @@ void *CVkBuffer::Map()
void *pData;
pData = NULL;
vmaMapMemory(s_vkAllocator, m_allocation, &pData);
VkResult r = vmaMapMemory(s_vkAllocator, m_allocation, &pData);
VULKAN_RESULT_PRINT(r, vmaMapMemory);
return pData;
}
@@ -295,6 +301,10 @@ private:
CUtlVector<VulkanWindow_t> m_renderWindows;
CUtlVector<CVkMaterial*> m_pMaterials;
CUtlVector<CVkRenderCommandList*> m_scheduledRemovalLists;
CUtlVector<CVkBuffer*> m_scheduledRemovalBuffers;
CUtlVector<CVkImage*> m_scheduledRemovalImages;
};
EXPOSE_INTERFACE(CVkRenderContext, IRenderContext, RENDER_CONTEXT_INTERFACE_VERSION);
@@ -366,7 +376,7 @@ IImage *CVkRenderContext::CreateStorageImage( uint32_t x, uint32_t y, EImageForm
void CVkRenderContext::DestroyBuffer( IBuffer *pBuffer )
{
delete (CVkBuffer*)pBuffer;
m_scheduledRemovalBuffers.AppendTail((CVkBuffer*)pBuffer);
}
void CVkRenderContext::DestroyImage( IImage *pImage )
@@ -412,7 +422,7 @@ IRenderCommandList *CVkRenderContext::CreateCommandList()
void CVkRenderContext::DestroyCommandList( IRenderCommandList *pCommandList )
{
m_scheduledRemovalLists.AppendTail((CVkRenderCommandList*)pCommandList);
}
void CVkRenderContext::SubmitCommandList(IRenderCommandList *pList)
@@ -711,6 +721,21 @@ void CVkRenderContext::Frame( float fDeltaTime )
s.m_uCurrentFrame = (s.m_uCurrentFrame + 1) % FRAMES_IN_FLIGHT;
}
m_pCommandBufferManager->RenderingFinished();
vkDeviceWaitIdle(s_vkDevice);
for (auto &a: m_scheduledRemovalBuffers)
{
delete a;
}
for (auto &a: m_scheduledRemovalLists)
{
delete a;
}
m_scheduledRemovalLists = {};
m_scheduledRemovalBuffers = {};
m_pCommandBufferManager->FreeCommandBufferWithCommands(s_pPresentCommandBuffer);
vkDeviceWaitIdle(s_vkDevice);
}
VulkanWindow_t CVkRenderContext::CreateSwapchain( IGameWindow *pWindow )

View File

@@ -37,6 +37,11 @@ void CVkShader::AddOutputImage( int iImageIndex, EImageFormat eFormat )
void CVkShader::SetDepthImage( EImageFormat eFormat )
{
m_eDepthFormat = CVkImage::GetImageFormat(eFormat);
}
void CVkShader::DisablePixelShader( bool bDisable )
{
}
@@ -71,12 +76,11 @@ void CVkShader::Build()
VulkanInputMetaData_t *pMetaData = (VulkanInputMetaData_t*)m_shader.GetLumpPtr(m_shader.m_objects[i].m_nMetadataLump);
for ( int u = 0; u < pMetaData->nDescriptorsCount; u++ )
{
VulkanDescriptor_t *pDescriptor = (VulkanDescriptor_t*)m_shader.GetLumpPtr(pMetaData->pDescriptorSets);
V_printf("%s\n" ,pDescriptor->szName);
VulkanDescriptor_t stDescriptor = ((VulkanDescriptor_t*)m_shader.GetLumpPtr(pMetaData->pDescriptorSets))[u];
bool bFound = false;
for ( auto &b: bindings )
{
if (b.binding != pDescriptor->uBinding)
if (b.binding != stDescriptor.uBinding)
continue;
bFound = true;
break;
@@ -84,12 +88,12 @@ void CVkShader::Build()
if (bFound)
break;
VkDescriptorSetLayoutBinding bind = {};
bind.binding = pDescriptor->uBinding;
bind.binding = stDescriptor.uBinding;
bind.descriptorCount = 1;
bind.descriptorType = pDescriptor->eDescriptorType;
bind.descriptorType = stDescriptor.eDescriptorType;
bind.stageFlags = VK_SHADER_STAGE_ALL;
bindings.AppendTail(bind);
m_bindings.AppendTail(*pDescriptor);
m_bindings.AppendTail(stDescriptor);
}
modules[i].sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
modules[i].pCode = (uint32_t*)m_shader.GetLumpPtr(m_shader.m_objects[i].m_nDataLump);
@@ -146,6 +150,13 @@ void CVkShader::Build()
render.pColorAttachmentFormats = m_eFormats.GetData();
depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
if (m_eDepthFormat == VK_FORMAT_D32_SFLOAT)
{
depthStencil.depthTestEnable = VK_TRUE;
depthStencil.depthWriteEnable = VK_TRUE;
depthStencil.depthCompareOp = VK_COMPARE_OP_LESS;
render.depthAttachmentFormat = m_eDepthFormat;
}
for ( auto e: m_eFormats )
{
@@ -159,10 +170,6 @@ void CVkShader::Build()
blend.attachmentCount = attachments.GetSize();
blend.pAttachments = attachments.GetData();
render.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO;
render.colorAttachmentCount = m_eFormats.GetSize();
render.pColorAttachmentFormats = m_eFormats.GetData();
createInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
createInfo.stageCount = stages.GetSize();
createInfo.pStages = stages.GetData();

View File

@@ -18,7 +18,9 @@ VkAccessFlags2 VulkanGetAccessFlags( EDependencyMode eMode )
{
switch (eMode)
{
case DEPENDENCY_MODE_JUST_CREATED: return VK_ACCESS_2_NONE;
case DEPENDENCY_MODE_DRAWCALL_OUTPUT_IMAGE: return VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT_KHR;
case DEPENDENCY_MODE_DRAWCALL_OUTPUT_DEPTH_IMAGE: return VK_ACCESS_2_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
case DEPENDENCY_MODE_COLOR_CLEAR_DESTINATION: return VK_ACCESS_2_TRANSFER_WRITE_BIT;
case DEPENDENCY_MODE_IMAGE_PRESENT: return VK_ACCESS_2_NONE;
case DEPENDENCY_MODE_BLIT_IMAGE_DESTINATION: return VK_ACCESS_2_TRANSFER_WRITE_BIT;
@@ -32,7 +34,9 @@ VkPipelineStageFlags2 VulkanGetStageFlags( EDependencyMode eMode )
{
switch (eMode)
{
case DEPENDENCY_MODE_JUST_CREATED: return VK_PIPELINE_STAGE_2_NONE;
case DEPENDENCY_MODE_DRAWCALL_OUTPUT_IMAGE: return VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
case DEPENDENCY_MODE_DRAWCALL_OUTPUT_DEPTH_IMAGE: return VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT;
case DEPENDENCY_MODE_COLOR_CLEAR_DESTINATION: return VK_PIPELINE_STAGE_2_TRANSFER_BIT;
case DEPENDENCY_MODE_IMAGE_PRESENT: return VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
case DEPENDENCY_MODE_BLIT_IMAGE_DESTINATION:
@@ -47,7 +51,9 @@ VkImageLayout VulkanGetImageLayout( EDependencyMode eMode )
{
switch (eMode)
{
case DEPENDENCY_MODE_JUST_CREATED: return VK_IMAGE_LAYOUT_UNDEFINED;
case DEPENDENCY_MODE_DRAWCALL_OUTPUT_IMAGE: return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
case DEPENDENCY_MODE_DRAWCALL_OUTPUT_DEPTH_IMAGE: return VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
case DEPENDENCY_MODE_COLOR_CLEAR_DESTINATION: return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
case DEPENDENCY_MODE_IMAGE_PRESENT: return VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
case DEPENDENCY_MODE_BLIT_IMAGE_DESTINATION: return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;

View File

@@ -42,6 +42,7 @@ enum EVulkanCommandParameterType
enum EDependencyMode
{
DEPENDENCY_MODE_JUST_CREATED,
DEPENDENCY_MODE_SHADER_IMAGE_READ,
DEPENDENCY_MODE_SHADER_BUFFER_READ,
@@ -52,6 +53,7 @@ enum EDependencyMode
DEPENDENCY_MODE_DRAWCALL_VERTEX_BUFFER,
DEPENDENCY_MODE_DRAWCALL_INDEX_BUFFER,
DEPENDENCY_MODE_DRAWCALL_OUTPUT_IMAGE,
DEPENDENCY_MODE_DRAWCALL_OUTPUT_DEPTH_IMAGE,
DEPENDENCY_MODE_DRAWCALL_INPUT_IMAGE,
DEPENDENCY_MODE_DRAWCALL_MIXED_IMAGE,
@@ -96,6 +98,7 @@ abstract_class CVkCommand
{
public:
virtual void Execute( VkCommandBuffer hCommandBuffer, int iCurrentFrame ) = 0;
virtual ~CVkCommand() = default;
//virtual const char *GetName();
CUtlVector<VulkanCommandDepenency_t> m_dependencies = {};
@@ -127,6 +130,7 @@ public:
virtual IVkCommandBuffer *CreateCommandBuffer() = 0;
virtual CVkCommand *CreateCommand( const char *szName ) = 0;
virtual CUtlVector<VkCommandBuffer> &GetVulkanCommands() = 0;
virtual void FreeCommandBufferWithCommands(IVkCommandBuffer* pCommandBuffer) = 0;
virtual void RenderingFinished() = 0;
};
#define VULKAN_COMMAND_BUFFER_MANAGER_INTERFACE_NAME "VulkanCommandBufferManager"
@@ -194,7 +198,7 @@ public:
VkImageLayout m_ePreferredLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkImageLayout m_eImageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
EDependencyMode m_eLastUsage;
EDependencyMode m_eLastUsage = DEPENDENCY_MODE_JUST_CREATED;
};
class CVkBuffer: public IBuffer
@@ -261,6 +265,7 @@ public:
virtual void SetTopology( ETopologyMode eTopology ) override;
virtual void AddOutputImage( int iImageIndex, EImageFormat eFormat ) override;
virtual void SetDepthImage( EImageFormat eFormat ) override;
virtual void DisablePixelShader( bool bDisable) override;
virtual void Build() override;
VkPipeline m_hPipeline = NULL;
@@ -274,6 +279,8 @@ private:
CUtlVector<VkVertexInputBindingDescription> m_layouts;
CUtlVector<VkVertexInputAttributeDescription> m_attributes;
CUtlVector<VkFormat> m_eFormats;
VkFormat m_eDepthFormat;
bool m_bIsFragmentEnabled;
};
@@ -347,6 +354,7 @@ struct VulkanRenderOutput_t {
class CVkRenderCommandList: public IRenderCommandList
{
public:
~CVkRenderCommandList();
virtual void ResetRendering() override;
virtual void SetRenderTarget( uint32_t uIndex, IImage *pImage ) override;
@@ -381,10 +389,11 @@ private:
VulkanRenderOutput_t *FindOrCreateRenderOutput( uint32_t uIndex );
IVkCommandBuffer *FindOrCreateMaterialCommandBuffer( IMaterial *pMaterial, bool *pbWasCreated = NULL );
VulkanRenderOutput_t m_depth;
bool m_bDepthEnabled = false;
VulkanRenderOutput_t m_depth = {};
CUtlVector<VulkanRenderOutput_t> m_pOutput = {};
CUtlSelfReferencingVector<VulkanMaterialCommandBuffer_t> m_materials = {};
CUtlVector<VulkanMaterialCommandBuffer_t> m_materials = {};
IVkCommandBuffer *m_pPostRaster;
IVkCommandBuffer *m_pCurrentMaterialBuffer = NULL;

View File

@@ -0,0 +1,24 @@
#ifndef CL_DLL_H
#define CL_DLL_H
#include "tier2/iappsystem.h"
#include "materialsystem/imaterialsystem.h"
#include "materialsystem/igamewindow.h"
#include "enginebridge.h"
class CClientGameDLL: public IAppSystem
{
public:
virtual void Init() override;
virtual void Shutdown() override;
IGameWindow *m_pGameWindow;
IRenderContext *m_pRenderContext;
IEngineBridge *m_pBridge;
private:
void *m_pLibrary;
};
#endif

14
public/enginebridge.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef ENGINE_BRIDGE_H
#define ENGINE_BRIDGE_H
#include "gamesystem.h"
abstract_class IEngineBridge: public IGameSystem
{
public:
virtual void ConnectInterface( const char *psz, void *pInterface ) = 0;
};
#define ENGINE_BRIDGE_INTERFACE_VERSION "EngineBridge001"
#endif

View File

View File

@@ -15,6 +15,9 @@ enum EImageFormat
IMAGE_FORMAT_BGRA8_UNORM,
IMAGE_FORMAT_RGBA8_UINT,
IMAGE_FORMAT_RGBA8_SINT,
IMAGE_FORMAT_RGBA16_UNORM,
IMAGE_FORMAT_RGBA16_UINT,
IMAGE_FORMAT_RGBA16_SINT,
IMAGE_FORMAT_RGBA16_SFLOAT,
IMAGE_FORMAT_RGBA32_SFLOAT,
@@ -31,6 +34,12 @@ enum EVertexFormat
VERTEX_FORMAT_XYZW32_SFLOAT,
};
enum EIndexFormat
{
INDEX_FORMAT_USHORT,
INDEX_FORMAT_UINT,
};
enum EImageType
{
IMAGE_TYPE_1D,
@@ -136,6 +145,7 @@ public:
virtual void SetTopology( ETopologyMode eTopology ) = 0;
virtual void AddOutputImage( int iImageIndex, EImageFormat eFormat ) = 0;
virtual void SetDepthImage( EImageFormat eFormat ) = 0;
virtual void DisablePixelShader( bool bDisable) = 0;
virtual void Build() = 0;
};

View File

@@ -2,8 +2,9 @@
#define SV_DLL_H
#include "tier2/iappsystem.h"
#define SERVER_DLL_INTERFACE_NAME "ServerGameDLL001"
#include "materialsystem/imaterialsystem.h"
#include "materialsystem/igamewindow.h"
#include "enginebridge.h"
class CServerGameDLL: public IAppSystem
{
@@ -11,12 +12,13 @@ public:
virtual void Init() override;
virtual void Shutdown() override;
void GameFrame();
IGameWindow *m_pGameWindow;
IRenderContext *m_pRenderContext;
IEngineBridge *m_pBridge;
private:
void *m_pLibrary;
};
CServerGameDLL *ServerGameDLL();
#endif

21
public/trig.h Normal file
View File

@@ -0,0 +1,21 @@
#ifndef TRIG_H
#define TRIG_H
struct Vector {
float x;
float y;
float z;
};
struct QAngle {
float pitch;
float yaw;
float roll;
};
struct Quat {
float x;
float y;
float z;
float w;
};
#endif

View File

@@ -81,6 +81,9 @@ void CSlangVulkanSpirvShaderCompiler::CompileShaderStage( EShaderStage eStage, c
case slang::TypeReflection::Kind::ConstantBuffer:
input.eDescriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
break;
case slang::TypeReflection::Kind::Resource:
input.eDescriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
break;
default:
break;
}

BIN
tools/Untitled.fmesh_c Normal file

Binary file not shown.

View File

@@ -0,0 +1,75 @@
import bpy
import os
import struct
from bpy_extras.io_utils import ExportHelper
from bpy.types import Operator
from bpy.props import StringProperty
bl_info = {
"name": "FunnyMesh export",
"author": "kotofyt",
"version": (1, 0),
"blender": (4, 3, 0),
"location": "File > Export > FunnyMesh (.fmesh_c)",
"description": "Export meshes as FunnyMeshes",
"category": "Import-Export",
}
class ExportFunnyMesh(Operator, ExportHelper):
"""Export to Funnymesh"""
bl_idname = "export_scene.fmesh_c"
bl_label = "Export Funnymesh"
filename_ext = ".fmesh_c"
filter_glob: StringProperty(
default="*.map",
options={'HIDDEN'},
)
def execute(self, context):
return export_my_format(self.filepath)
def export_my_format(filepath):
with open(filepath, 'wb') as f:
for obj in bpy.context.scene.objects:
if obj.type == 'MESH':
mesh = obj.to_mesh()
mesh.calc_loop_triangles()
uv_layer = mesh.uv_layers.active.data if mesh.uv_layers.active else None
for tri in mesh.loop_triangles:
for loop_index in tri.loops:
vert = mesh.vertices[mesh.loops[loop_index].vertex_index]
world_pos = obj.matrix_world @ vert.co
print(world_pos.x)
f.write(struct.pack('f', world_pos.x))
print(world_pos.y)
f.write(struct.pack('f', world_pos.y))
print(world_pos.z)
f.write(struct.pack('f', world_pos.z))
if uv_layer:
uv = uv_layer[loop_index].uv
print(uv.x)
f.write(struct.pack('f', uv.x))
print(uv.y)
f.write(struct.pack('f', uv.y))
else:
f.write(struct.pack('f', 0))
f.write(struct.pack('f', 0))
return {'FINISHED'}
def menu_func_export(self, context):
self.layout.operator(ExportFunnyMesh.bl_idname, text="FunnyMesh (.fmesh_c)")
def register():
bpy.utils.register_class(ExportFunnyMesh)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
def unregister():
bpy.utils.unregister_class(ExportFunnyMesh)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
if __name__ == "__main__":
register()