diff --git a/.gitmodules b/.gitmodules index b8e4e86..abcc806 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "external/stb"] path = external/stb url = https://github.com/nothings/stb.git +[submodule "external/SDL"] + path = external/SDL + url = https://github.com/libsdl-org/SDL.git diff --git a/build.c b/build.c index 2605791..aafbd1a 100644 --- a/build.c +++ b/build.c @@ -18,15 +18,15 @@ char* include_dirs[] = { #include "fgui/__build.c" #include "rapier/__build.c" #include "engine/__build.c" -#include "game/__build.c" +#include "game/server/__build.c" +#include "game/client/__build.c" #include "launcher/__build.c" #include "funnyassets/__build.c" -int build(struct build_data b) { - if (!step("trace")) - trace = 1; +int build(struct build_data b) { + trace = 1; makedir("build/"GAME_NAME"/game/" GAME_NAME); makedir("build/"GAME_NAME"/game/" GAME_NAME "/bin"); makedir("build/"GAME_NAME"/game/bin/"); @@ -38,8 +38,12 @@ int build(struct build_data b) { launcher_build(b); server_build(b); + client_build(b); - assets_build(b); + if (step("noassets")) + { + assets_build(b); + } mv("build", "tools"); if (step("run")!=STEP_FAILED) diff --git a/engine/__build.c b/engine/__build.c index f0573d9..5dddadd 100644 --- a/engine/__build.c +++ b/engine/__build.c @@ -1,9 +1,13 @@ +#include "god/build.h" #include "god/c.h" #include "god/ld.h" #include "god/utils.h" +char *engine_lib; +char *engine_implib; void engine_build(struct build_data b) { + char *szVideoFile = "engine/vk_videosdl.cpp"; char* files[] = { "engine/console.cpp", "engine/filesystem.cpp", @@ -11,12 +15,12 @@ void engine_build(struct build_data b) "engine/engine.cpp", /* rendering */ - "engine/vk_videolinux.cpp", "engine/vk_video.cpp", "engine/vk_brush.cpp", + "engine/vk_mesh.cpp", + szVideoFile, - /* entities */ - + /* entities */ "engine/baseentity.cpp", "engine/level.cpp", "engine/brush.cpp", @@ -30,9 +34,6 @@ void engine_build(struct build_data b) "engine/cl_light.cpp", NULL, }; - char *rustFiles[] = { - "engine/rust/physics.rs" - }; struct project p = { @@ -40,7 +41,6 @@ void engine_build(struct build_data b) .files = files, .name = "engine", }; - struct project o = C_compile(p, (struct C_settings){ .generation_flags = C_GENERATION_FLAGS_PIC, .compile_flags = C_COMPILE_FLAGS_WALL, @@ -49,16 +49,28 @@ void engine_build(struct build_data b) add_item(&o.files, tier1_lib); add_item(&o.files, rapierLib); + char *szVulkan = (char*)1; + char *szws2 = (char*)1; + if (b.kernel==BUILD_KERNEL_WINDOWS) + { + szVulkan="vulkan-1"; + szws2="ws2_32"; + } + if (b.kernel==BUILD_KERNEL_LINUX) + { + szVulkan="vulkan"; + } + char* libs[] = { "c", - "vulkan", - "X11", + "SDL3", + szVulkan, NULL, }; - char* dll = ld_link_project(o, (struct link_settings){ + engine_lib = ld_link_project(o, (struct link_settings){ .type = LINK_TYPE_DYNAMIC, .libs = libs, }); - mv("build/"GAME_NAME"/game/bin",dll); + mv("build/"GAME_NAME"/game/bin",engine_lib); } diff --git a/engine/baseentity.cpp b/engine/baseentity.cpp index 4fe2a78..b2eb5e9 100644 --- a/engine/baseentity.cpp +++ b/engine/baseentity.cpp @@ -1,8 +1,15 @@ #include "baseentity.h" +#include "cglm/mat4.h" +#include "tier0/platform.h" CUtlSelfReferencingVector g_entities; CUtlVector g_RegisteredEntities; +CBaseEntity::CBaseEntity() +{ + glm_mat4_identity(m_matrix); +}; + CEntityRegistry::CEntityRegistry(const char *szName, const char *szClass, EntityRegistryFn pfn) : m_szName(szName), m_szClass(szClass), m_pfn(pfn), m_pClientfn(0) { diff --git a/engine/brush.cpp b/engine/brush.cpp index 778a43b..afd72bd 100644 --- a/engine/brush.cpp +++ b/engine/brush.cpp @@ -22,22 +22,20 @@ void CBrushEntity::Spawn() for (auto tri: m_mesh) { V_memcpy(&triangles[i],tri.location,36); - i+=1; + i+=3; } - V_printf("indicides %i\n",indicies.GetSize()); - V_printf("vertices %i\n",triangles.GetSize()); - px_collider_params params = {}; - params.friction = 0; + params.friction = 0.6; m_collider = px_trimesh((Point*)triangles.GetMemory(), triangles.GetSize(), (uint32_t(*)[3])indicies.GetMemory(), indicies.GetSize()/3 ,params); + //m_collider = px_box(4, 10, 1, params); px_matrix mat = {}; mat.m[0] = 1; - mat.m[4] = 1; - mat.m[9] = 1; + mat.m[5] = 1; + mat.m[10] = 1; mat.m[15] = 1; px_rigidbody_params param = {}; param.gravity_scale = 1; - m_body = px_staticbody(px, m_collider, mat); + px_fixedbody(px, m_collider); }; void CBrushEntity::Destroy() @@ -67,7 +65,7 @@ void C_BrushEntity::Spawn() pAlbedo = ITextureManager::LoadTexture("gfx/bricks.png"); CBrushEntity* pBrushEntity = (CBrushEntity*)pEntity; uint32_t numVertices = 15*pBrushEntity->m_mesh.GetSize(); - vertexBuffer = IBrushRenderer::CreateVertexBuffer(numVertices*4); + vertexBuffer = IRenderer::CreateVertexBuffer(numVertices*4); Vertex_t *pTriangles = (Vertex_t*)vertexBuffer->Map(); uint32_t i = 0; for (auto &triangle: pBrushEntity->m_mesh) @@ -103,7 +101,7 @@ void C_BrushEntity::Destroy() void C_BrushEntity::Think( float fDelta ) { material.m.albedo = ITextureManager::GetTexture(pAlbedo); - IBrushRenderer::SetMaterial(&material); + IRenderer::SetMaterial(&material); mesh->Draw(); }; diff --git a/engine/cl_light.cpp b/engine/cl_light.cpp index b6dfc2d..490a116 100644 --- a/engine/cl_light.cpp +++ b/engine/cl_light.cpp @@ -1,5 +1,5 @@ #include "baseentity.h" - +#include "rendering.h" class C_Light: public C_BaseEntity { @@ -7,7 +7,9 @@ public: virtual void Precache ( void ) override; virtual void Spawn( void ) override; virtual void Destroy( void ) override; - virtual void Think( float fDelta ) override; + virtual void Think( float fDelta ) override; + IVertexBuffer *vertexBuffer; + IMesh *mesh; }; void C_Light::Precache() @@ -17,6 +19,56 @@ void C_Light::Precache() void C_Light::Spawn() { + float cubeVertices[] = { + -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, + 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, + 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, + 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, + -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, + -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, + + -0.5f, -0.5f, -0.5f, 1.0f, 0.0f, + -0.5f, 0.5f, -0.5f, 1.0f, 1.0f, + 0.5f, 0.5f, -0.5f, 0.0f, 1.0f, + 0.5f, 0.5f, -0.5f, 0.0f, 1.0f, + 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, + -0.5f, -0.5f, -0.5f, 1.0f, 0.0f, + + -0.5f, 0.5f, 0.5f, 1.0f, 0.0f, + -0.5f, 0.5f, -0.5f, 1.0f, 1.0f, + -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, + -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, + -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, + -0.5f, 0.5f, 0.5f, 1.0f, 0.0f, + + 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, + 0.5f, -0.5f, -0.5f, 0.0f, 1.0f, + 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, + 0.5f, -0.5f, -0.5f, 0.0f, 1.0f, + 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, + 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, + + -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, + -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, + 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, + 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, + 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, + -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, + + -0.5f, -0.5f, -0.5f, 1.0f, 1.0f, + 0.5f, -0.5f, -0.5f, 0.0f, 1.0f, + 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, + 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, + -0.5f, -0.5f, 0.5f, 1.0f, 0.0f, + -0.5f, -0.5f, -0.5f, 1.0f, 1.0f, + }; + vertexBuffer = IRenderer::CreateVertexBuffer(sizeof(cubeVertices)); + void *pTriangles = vertexBuffer->Map(); + V_memcpy(pTriangles, cubeVertices, sizeof(cubeVertices)); + vertexBuffer->Unmap(); + + mesh = IMeshRenderer::CreateMesh(); + mesh->SetVertexBuffer(vertexBuffer); }; void C_Light::Destroy() @@ -25,7 +77,9 @@ void C_Light::Destroy() } void C_Light::Think( float fDelta ) { - + IRenderer::SetMaterial(0); + mesh->SetMatrix(pEntity->m_matrix); + mesh->Draw(); }; LINK_CLIENT_ENTITY(C_Light, CLight) diff --git a/engine/cl_worldspawn.cpp b/engine/cl_worldspawn.cpp index d3be7db..2daff5b 100644 --- a/engine/cl_worldspawn.cpp +++ b/engine/cl_worldspawn.cpp @@ -13,7 +13,7 @@ public: void C_WorldSpawn::Precache() { - + C_BrushEntity::Precache(); } void C_WorldSpawn::Spawn() diff --git a/engine/client.cpp b/engine/client.cpp new file mode 100644 index 0000000..f679c0d --- /dev/null +++ b/engine/client.cpp @@ -0,0 +1 @@ +#include "client.h" diff --git a/engine/engine.cpp b/engine/engine.cpp index 1181fa0..1e60137 100644 --- a/engine/engine.cpp +++ b/engine/engine.cpp @@ -8,13 +8,12 @@ #include "baseentity.h" #include "server.h" #include "physics.h" - -#ifdef __linux #include "signal.h" -#endif double fPrev = 0; double fCurrent = 0; + +funnyphysics *px; //----------------------------------------------------------------------------- // Purpose: Engine entry point //----------------------------------------------------------------------------- @@ -49,7 +48,6 @@ void IEngine_Signal(int sig) _exit(0); }; -funnyphysics *px; void IEngine::Init() { @@ -83,15 +81,6 @@ void IEngine::Shutdown() { }; -void IIEngine::PrecacheModel( const char *psz ) -{ - -} -void IIEngine::PrecacheSound( const char *psz ) -{ - -} - CBaseEntity *IIEngine::SpawnEntity( const char *szName ) { diff --git a/engine/filesystem.cpp b/engine/filesystem.cpp index fa7feed..d827eb0 100644 --- a/engine/filesystem.cpp +++ b/engine/filesystem.cpp @@ -88,7 +88,7 @@ bool IFileSystem::LoadPackFile( const char *szFilename ) unsigned long long nNumFiles = 0; PackDirectory_t *pDirs = NULL; - FILE* f = V_fopen(szFilename, "r"); + FILE* f = V_fopen(szFilename, "rb"); if (!f) Plat_FatalErrorFunc("Failed to open %s",szFilename); V_fread(&header,1,sizeof(header),f); diff --git a/engine/server.cpp b/engine/server.cpp index 563f285..289fa9e 100644 --- a/engine/server.cpp +++ b/engine/server.cpp @@ -5,19 +5,23 @@ #include "physics.h" void *g_serverdll; +ConVar g_tickrate("tickrate","64",FCVAR_PROTECTED); +float g_fAccumulator = 0; void IServer::LoadGame( const char *psz ) { +#ifdef __WIN32__ + g_serverdll = Plat_LoadLibrary(CUtlString("%s/bin/server.dll", psz)); +#endif +#ifdef __linux__ g_serverdll = Plat_LoadLibrary(CUtlString("%s/bin/libserver.so", psz)); +#endif void (*GameLoadfn)() = (void(*)())Plat_GetProc(g_serverdll, "IGame_Load"); if (!GameLoadfn) Plat_FatalErrorFunc("IGame_Load not found in libserver.so\n"); GameLoadfn(); }; -ConVar g_tickrate("tickrate","64",FCVAR_PROTECTED); -float g_fAccumulator = 0; - void IServer::Think( float fDelta ) { g_fAccumulator += fDelta; diff --git a/engine/sv_light.cpp b/engine/sv_light.cpp index 4ff1527..6eecd8b 100644 --- a/engine/sv_light.cpp +++ b/engine/sv_light.cpp @@ -23,15 +23,16 @@ void CLight::Precache() void CLight::Spawn() { px_collider_params params = {}; - params.friction = 0; - col = px_box(1, 1, 1, params); + params.friction = 0.7; + col = px_box(0.5,0.5,0.5, params); px_matrix mat = {}; mat.m[0] = 1; - mat.m[4] = 1; - mat.m[9] = 1; + mat.m[5] = 1; + mat.m[10] = 1; mat.m[15] = 1; - mat.m[3]=-10; mat.m[11]=10; + mat.m[7]=-4; + mat.m[3]=12; px_rigidbody_params param = {}; param.gravity_scale = 1; m_body=px_rigidbody(px, col, mat, param); @@ -43,8 +44,9 @@ void CLight::Destroy() } void CLight::Think( float fDelta ) { - px_vec3 pos = px_getposition(px, m_body); - V_printf("%p %f %f %f\n",col, pos.m[0], pos.m[1], pos.m[2]); + px_matrix pos = px_getmatrix(px, m_body); + V_memcpy(m_matrix, pos.m, 64); + V_printf("%p %f %f %f\n",col, pos.m[12], pos.m[13], pos.m[14]); }; DECLARE_ENTITY(light, CLight) diff --git a/engine/sv_worldspawn.cpp b/engine/sv_worldspawn.cpp index 8517429..b144328 100644 --- a/engine/sv_worldspawn.cpp +++ b/engine/sv_worldspawn.cpp @@ -17,6 +17,7 @@ void CWorldSpawn::Precache() void CWorldSpawn::Spawn() { + V_printf("Cool\n"); CBrushEntity::Spawn(); }; diff --git a/engine/vk_brush.cpp b/engine/vk_brush.cpp index 42c6f67..75f260f 100644 --- a/engine/vk_brush.cpp +++ b/engine/vk_brush.cpp @@ -4,48 +4,27 @@ #include "vk_helper.h" #include "vulkan/vulkan_core.h" -extern VkSampler g_invalidTextureSampler; + +vk_tripipeline_t g_brushPipeline = {}; + +VkDescriptorPool g_brushDescriptorPool; +VkDescriptorSet g_brushDescriptorSet; + +VkSampler g_brushSampler; + + abstract_class CBrush: public IBrush { public: - void SetPosition( vec3 position ) override; - void SetRotationEuler( vec3 angle ) override; - void SetRotationQuat( vec4 quaternion) override; - void SetMatrix( mat3 matrix ) override; - void SetScale( vec3 scale ) override; - void SetVertexBuffer( IVertexBuffer *pBuffer ) override; void SetIndexBuffer( IIndexBuffer *pBuffer ) override; void Draw() override; - IMaterial *m_pMaterial = NULL; + Material_t m_material; CVertexBuffer *m_pVertexBuffer = NULL; CIndexBuffer *m_pIndexBuffer = NULL; }; -void CBrush::SetPosition( vec3 position ) -{ - -} - -void CBrush::SetRotationEuler( vec3 angle ) -{ - -} - -void CBrush::SetRotationQuat( vec4 quaternion) -{ - -} - -void CBrush::SetMatrix( mat3 matrix ) -{ - -} - -void CBrush::SetScale( vec3 scale ) -{ - -} +CUtlVector g_drawnBrushes; void CBrush::SetVertexBuffer( IVertexBuffer *pBuffer ) @@ -58,34 +37,15 @@ void CBrush::SetIndexBuffer( IIndexBuffer *pBuffer ) m_pIndexBuffer = (CIndexBuffer*)pBuffer; } -CUtlVector g_drawnMeshes; -IMaterial *g_pDefaultMaterial; -IMaterial *g_pCurrentMaterial; - void CBrush::Draw() { - g_drawnMeshes.AppendTail(*this); + if (!g_pCurrentMaterial) + m_material = {}; + else + m_material = g_pCurrentMaterial->m; + g_drawnBrushes.AppendTail(*this); } -abstract_class CMaterial: public IMaterial -{ -}; - -extern CUtlVector g_textures; - -vk_tripipeline_t g_brushPipeline = {}; -vk_image2d_t meshdepth; -vk_image2d_t meshcolor; -extern bool g_bConfigNotify; - -VkDescriptorPool g_brushDescriptorPool; -VkDescriptorSet g_brushDescriptorSet; -vk_buffer_t g_brushProjection; -struct MeshProjection { - mat4 projection; -} *g_brushProject; - -VkSampler g_brushSampler; void IBrushRenderer::Init() { @@ -111,9 +71,6 @@ void IBrushRenderer::Init() shaders[1].Destroy(); shaders[0].Destroy(); - meshdepth.Create(1280, 720, VK_FORMAT_D32_SFLOAT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); - meshcolor.Create(1280, 720, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); - CUtlVector pools; for (auto &binding: bindings) { @@ -137,8 +94,6 @@ void IBrushRenderer::Init() allocInfo.pSetLayouts = &g_brushPipeline.m_descriptorSetLayout; vkAllocateDescriptorSets(g_vkDevice, &allocInfo, &g_brushDescriptorSet); - g_brushProjection.Create(64, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT); - g_brushProject = (MeshProjection*)g_brushProjection.Map(0, 64); VkPhysicalDeviceProperties properties{}; vkGetPhysicalDeviceProperties(g_vkPhysicalDevice, &properties); @@ -164,17 +119,6 @@ void IBrushRenderer::Init() void IBrushRenderer::Frame( float fDelta ) { - glm_mat4_identity(g_brushProject->projection); - glm_perspective(glm_rad(90),(float)g_nWindowWidth/g_nWindowHeight, 0.01, 100, g_brushProject->projection); - glm_rotate(g_brushProject->projection, glm_rad(90), (vec4){1,0,0,0}); - glm_scale(g_brushProject->projection, (vec4){1,-1,1,1}); - glm_rotate(g_brushProject->projection, glm_rad(-90), (vec4){0,0,1,0}); - if (g_bConfigNotify) - { - meshdepth.Destroy(); - meshdepth.Create(g_nWindowWidth, g_nWindowHeight, VK_FORMAT_D32_SFLOAT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); - } - CUtlVector writes(2); for (auto &write: writes) @@ -186,9 +130,9 @@ void IBrushRenderer::Frame( float fDelta ) } VkDescriptorBufferInfo bufferInfo = {}; - bufferInfo.buffer = g_brushProjection.m_buffer; + bufferInfo.buffer = g_cameraProperties.m_buffer; bufferInfo.offset = 0; - bufferInfo.range = g_brushProjection.m_nSize; + bufferInfo.range = g_cameraProperties.m_nSize; writes[0].dstBinding = 0; writes[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; writes[0].descriptorCount = 1; @@ -237,7 +181,7 @@ void IBrushRenderer::Frame( float fDelta ) }; VkRenderingAttachmentInfo depthAttachment = { .sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO, - .imageView = meshdepth.m_imageView, + .imageView = g_meshdepth.m_imageView, .imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL, .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR, .storeOp = VK_ATTACHMENT_STORE_OP_STORE, @@ -317,14 +261,10 @@ void IBrushRenderer::Frame( float fDelta ) vkCmdBindPipeline(g_vkCommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_brushPipeline.m_pipeline); vkCmdBindDescriptorSets(g_vkCommandBuffer,VK_PIPELINE_BIND_POINT_GRAPHICS, g_brushPipeline.m_layout, 0, 1, &g_brushDescriptorSet, 0, NULL); - for (auto &mesh: g_drawnMeshes) + for (auto &mesh: g_drawnBrushes) { VkDeviceSize offset = 0; - uint32_t textureID = 0; - if (g_pCurrentMaterial == 0) - textureID = 0; - else - textureID = ((CMaterial*)g_pCurrentMaterial)->m.albedo; + uint32_t textureID = mesh.m_material.albedo; vkCmdPushConstants(g_vkCommandBuffer, g_brushPipeline.m_layout, VK_SHADER_STAGE_ALL, 0, 4, &textureID); vkCmdBindVertexBuffers(g_vkCommandBuffer, 0, 1, &mesh.m_pVertexBuffer->m_buffer.m_buffer, &offset); if (mesh.m_pIndexBuffer) @@ -349,7 +289,7 @@ void IBrushRenderer::Frame( float fDelta ) .srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, .dstAccessMask = 0, .oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, - .newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, + .newLayout = VK_IMAGE_LAYOUT_GENERAL, .image = g_swapchainImage, .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1} }; @@ -358,23 +298,10 @@ void IBrushRenderer::Frame( float fDelta ) VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, NULL, 0, NULL, 1, &barrier); - g_drawnMeshes = CUtlVector(); + g_drawnBrushes = CUtlVector(); } -IVertexBuffer *IBrushRenderer::CreateVertexBuffer( uint32_t uSize ) -{ - CVertexBuffer *pBuffer = new CVertexBuffer(); - pBuffer->m_buffer.Create(uSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT); - return pBuffer; -} - -IIndexBuffer *IBrushRenderer::CreateIndexBuffer( uint32_t uSize ) -{ - CIndexBuffer *pBuffer = new CIndexBuffer(); - pBuffer->m_buffer.Create(uSize, VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT); - return pBuffer; -} IBrush *IBrushRenderer::CreateMesh() { @@ -387,21 +314,3 @@ void IBrushRenderer::Destroy( IBrush *pModel ) } -IMaterial *IBrushRenderer::LoadMaterial( const char *szMaterial ) -{ - FileHandle_t file = IFileSystem::Open(szMaterial, IFILE_READ); - CMaterial *pMaterial = new CMaterial; - if (!file) - { - return g_pDefaultMaterial; - } - - IFileSystem::Close(file); -} - -void IBrushRenderer::SetMaterial( IMaterial *pMaterial ) -{ - g_pCurrentMaterial = pMaterial; -} - - diff --git a/engine/vk_helper.h b/engine/vk_helper.h index 597a773..b20b5ee 100644 --- a/engine/vk_helper.h +++ b/engine/vk_helper.h @@ -5,11 +5,7 @@ #include "console.h" #include "tier1/commandline.h" -#include "X11/X.h" -#include "X11/Xlib.h" #include "vulkan/vulkan.h" -#include "vulkan/vulkan_core.h" -#include "vulkan/vulkan_xlib.h" #define VULKAN_RENDERING_IMPL #include "vk_video.h" @@ -21,31 +17,6 @@ #include "cglm/affine.h" #include "cglm/cglm.h" -extern Display* g_xdisplay; -extern int g_xscreen; -extern Window g_xroot; -extern Window g_xwin; - -extern VkInstance g_vkInstance; -extern VkPhysicalDevice g_vkPhysicalDevice; -extern VkDevice g_vkDevice; -extern uint32_t g_drawfamily; -extern VkQueue g_drawQueue; -extern uint32_t g_presentfamily; -extern VkQueue g_presentQueue; -extern VmaAllocator g_allocator; - -extern VkSurfaceKHR g_surface; -extern VkSwapchainKHR g_swapchain; - -extern VkCommandPool g_vkCommandPool; -extern VkCommandBuffer g_vkCommandBuffer; -extern VkImageView g_swapchainImageView; -extern VkImage g_swapchainImage; - -extern uint32_t g_nWindowWidth; -extern uint32_t g_nWindowHeight; - class CVertexBuffer: public IVertexBuffer { public: @@ -70,3 +41,42 @@ class CTexture: public ITexture public: vk_image2d_t image; }; + + + +extern VkInstance g_vkInstance; +extern VkPhysicalDevice g_vkPhysicalDevice; +extern VkDevice g_vkDevice; +extern uint32_t g_drawfamily; +extern VkQueue g_drawQueue; +extern uint32_t g_presentfamily; +extern VkQueue g_presentQueue; +extern VmaAllocator g_allocator; + +extern VkSurfaceKHR g_surface; +extern VkSwapchainKHR g_swapchain; + +extern VkCommandPool g_vkCommandPool; +extern VkCommandBuffer g_vkCommandBuffer; +extern VkImageView g_swapchainImageView; +extern VkImage g_swapchainImage; + +extern bool g_bConfigNotify; +extern uint32_t g_nWindowWidth; +extern uint32_t g_nWindowHeight; + +extern VkSampler g_invalidTextureSampler; +extern IMaterial *g_pDefaultMaterial; +extern IMaterial *g_pCurrentMaterial; + +extern CUtlVector g_textures; + +struct CameraProjection { + mat4 viewprojection; +}; + +extern vk_buffer_t g_cameraProperties; +extern CameraProjection *g_cameraDataMap; + +extern vk_image2d_t g_meshdepth; +extern vk_image2d_t g_meshcolor; diff --git a/engine/vk_mesh.cpp b/engine/vk_mesh.cpp new file mode 100644 index 0000000..dc23cd8 --- /dev/null +++ b/engine/vk_mesh.cpp @@ -0,0 +1,354 @@ +#include "cglm/mat4.h" +#include "filesystem.h" +#include "rendering.h" +#include "tier1/utlvector.h" +#include "vk_helper.h" +#include "vulkan/vulkan_core.h" + + +vk_tripipeline_t g_meshPipeline = {}; + +VkDescriptorPool g_meshDescriptorPool; +VkDescriptorSet g_meshDescriptorSet; + +VkSampler g_meshSampler; + + +abstract_class CMesh: public IMesh +{ +public: + CMesh(); + void SetPosition( vec3 position ) override; + void SetRotationEuler( vec3 angle ) override; + void SetRotationQuat( vec4 quaternion) override; + void SetMatrix( mat4 matrix ) override; + void SetScale( vec3 scale ) override; + + void SetVertexBuffer( IVertexBuffer *pBuffer ) override; + void SetIndexBuffer( IIndexBuffer *pBuffer ) override; + void Draw() override; + + Material_t m_material; + CVertexBuffer *m_pVertexBuffer = NULL; + CIndexBuffer *m_pIndexBuffer = NULL; + mat4 m_matrix; +}; + +CMesh::CMesh() +{ + glm_mat4_identity(m_matrix); +}; + +void CMesh::SetPosition( vec3 position ) +{ + m_matrix[0][3] = position[0]; + m_matrix[1][3] = position[1]; + m_matrix[2][3] = position[2]; +} + +void CMesh::SetRotationEuler( vec3 angle ) +{ + +} + +void CMesh::SetRotationQuat( vec4 quaternion) +{ + +} + +void CMesh::SetMatrix( mat4 matrix ) +{ + memcpy(m_matrix,matrix,64); +} + +void CMesh::SetScale( vec3 scale ) +{ + +} + +void CMesh::SetVertexBuffer( IVertexBuffer *pBuffer ) +{ + m_pVertexBuffer = (CVertexBuffer*)pBuffer; +} + +void CMesh::SetIndexBuffer( IIndexBuffer *pBuffer ) +{ + m_pIndexBuffer = (CIndexBuffer*)pBuffer; +} + +CUtlVector g_drawnMeshes; + +void CMesh::Draw() +{ + if (!g_pCurrentMaterial) + m_material = {}; + else + m_material = g_pCurrentMaterial->m; + g_drawnMeshes.AppendTail(*this); +} + +void IMeshRenderer::Init() +{ + CUtlVector shaders(2); + for (auto &shader: shaders) + { + shader.m_shaderModule = NULL; + } + shaders[0].Create("gfx/mesh_vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + shaders[1].Create("gfx/mesh_frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + CUtlVector bindings(2); + bindings[0] = {}; + bindings[0].binding = 0; + bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + bindings[0].descriptorCount = 1; + bindings[1] = {}; + bindings[1].binding = 1; + bindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; + bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + bindings[1].descriptorCount = 1024; + g_meshPipeline.Create(shaders, bindings, 76); + shaders[1].Destroy(); + shaders[0].Destroy(); + + CUtlVector pools; + for (auto &binding: bindings) + { + VkDescriptorPoolSize dps = {}; + dps.type = binding.descriptorType; + dps.descriptorCount = binding.descriptorCount; + pools.AppendTail(dps); + } + + VkDescriptorPoolCreateInfo poolInfo = {}; + poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + poolInfo.poolSizeCount = pools.GetSize(); + poolInfo.pPoolSizes = pools.GetData(); + poolInfo.maxSets = 1; + vkCreateDescriptorPool(g_vkDevice, &poolInfo, NULL, &g_meshDescriptorPool); + + VkDescriptorSetAllocateInfo allocInfo = {}; + allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + allocInfo.descriptorPool = g_meshDescriptorPool; + allocInfo.descriptorSetCount = 1; + allocInfo.pSetLayouts = &g_meshPipeline.m_descriptorSetLayout; + vkAllocateDescriptorSets(g_vkDevice, &allocInfo, &g_meshDescriptorSet); + + + VkPhysicalDeviceProperties properties{}; + vkGetPhysicalDeviceProperties(g_vkPhysicalDevice, &properties); + VkSamplerCreateInfo samplerInfo{}; + samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + samplerInfo.magFilter = VK_FILTER_LINEAR; + samplerInfo.minFilter = VK_FILTER_LINEAR; + samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; + samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; + samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; + samplerInfo.anisotropyEnable = VK_FALSE; + samplerInfo.maxAnisotropy = properties.limits.maxSamplerAnisotropy; + samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; + samplerInfo.unnormalizedCoordinates = VK_FALSE; + samplerInfo.compareEnable = VK_FALSE; + samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS; + samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; + samplerInfo.mipLodBias = 0.0f; + samplerInfo.minLod = 0.0f; + samplerInfo.maxLod = 0.0f; + vkCreateSampler(g_vkDevice, &samplerInfo, nullptr, &g_meshSampler); +} + +void IMeshRenderer::Frame( float fDelta ) +{ + CUtlVector writes(2); + for (auto &write: writes) + { + write = {}; + write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write.dstSet = g_meshDescriptorSet; + write.dstArrayElement = 0; + } + + VkDescriptorBufferInfo bufferInfo = {}; + bufferInfo.buffer = g_cameraProperties.m_buffer; + bufferInfo.offset = 0; + bufferInfo.range = g_cameraProperties.m_nSize; + writes[0].dstBinding = 0; + writes[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + writes[0].descriptorCount = 1; + writes[0].pBufferInfo = &bufferInfo; + + CUtlVector textures; + textures.Reserve(g_textures.GetSize()); + for (ITexture *t: g_textures) + { + CTexture *texture = (CTexture*)t; + VkDescriptorImageInfo image = {}; + image.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + image.imageView = texture->image.m_imageView; + image.sampler = g_meshSampler; + textures.AppendTail(image); + }; + textures[0].sampler = g_invalidTextureSampler; + writes[1].dstBinding = 1; + writes[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + writes[1].descriptorCount = textures.GetSize(); + writes[1].pImageInfo = textures.GetData(); + vkUpdateDescriptorSets(g_vkDevice, writes.GetSize(), writes.GetData(), 0, NULL); + + + VkImageMemoryBarrier barrier = { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, + .srcAccessMask = 0, + .dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + .oldLayout = VK_IMAGE_LAYOUT_GENERAL, + .newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + .image = g_swapchainImage, + .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1} + }; + vkCmdPipelineBarrier(g_vkCommandBuffer, + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, + 0, 0, NULL, 0, NULL, 1, &barrier); + + VkRenderingAttachmentInfo colorAttachment = { + .sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO, + .imageView = g_swapchainImageView, + .imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD, + .storeOp = VK_ATTACHMENT_STORE_OP_STORE, + }; + VkRenderingAttachmentInfo depthAttachment = { + .sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO, + .imageView = g_meshdepth.m_imageView, + .imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL, + .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD, + .storeOp = VK_ATTACHMENT_STORE_OP_STORE, + }; + + VkRenderingInfo renderInfo = { + .sType = VK_STRUCTURE_TYPE_RENDERING_INFO, + .renderArea = {{0, 0}, {g_nWindowWidth, g_nWindowHeight}}, + .layerCount = 1, + .colorAttachmentCount = 1, + .pColorAttachments = &colorAttachment, + .pDepthAttachment = &depthAttachment, + }; + vkCmdBeginRendering(g_vkCommandBuffer, &renderInfo); + + vkCmdSetRasterizerDiscardEnable(g_vkCommandBuffer, VK_FALSE); + vkCmdSetDepthBiasEnable(g_vkCommandBuffer, VK_FALSE); + _vkCmdSetPolygonModeEXT(g_vkCommandBuffer, VK_POLYGON_MODE_FILL); + vkCmdSetCullMode(g_vkCommandBuffer, VK_CULL_MODE_BACK_BIT); + vkCmdSetFrontFace(g_vkCommandBuffer, VK_FRONT_FACE_COUNTER_CLOCKWISE); + + vkCmdSetDepthTestEnable(g_vkCommandBuffer, VK_TRUE); + vkCmdSetDepthWriteEnable(g_vkCommandBuffer, VK_TRUE); + vkCmdSetDepthCompareOp(g_vkCommandBuffer, VK_COMPARE_OP_LESS); + vkCmdSetStencilTestEnable(g_vkCommandBuffer, VK_FALSE); + + _vkCmdSetRasterizationSamplesEXT(g_vkCommandBuffer, VK_SAMPLE_COUNT_1_BIT); + VkSampleMask sampleMask = 0xFFFFFFFF; + _vkCmdSetSampleMaskEXT(g_vkCommandBuffer, VK_SAMPLE_COUNT_1_BIT, &sampleMask); + _vkCmdSetAlphaToCoverageEnableEXT(g_vkCommandBuffer, VK_FALSE); + + VkViewport viewport = {0, 0, (float)g_nWindowWidth, (float)g_nWindowHeight, 0.0f, 1.0f}; + VkRect2D scissor = {{0, 0}, {g_nWindowWidth, g_nWindowHeight}}; + vkCmdSetViewportWithCount(g_vkCommandBuffer, 1, &viewport); + vkCmdSetScissorWithCount(g_vkCommandBuffer, 1, &scissor); + + vkCmdSetPrimitiveTopology(g_vkCommandBuffer, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST); + vkCmdSetPrimitiveRestartEnable(g_vkCommandBuffer, VK_FALSE); + + VkVertexInputBindingDescription2EXT binding = { + .sType = VK_STRUCTURE_TYPE_VERTEX_INPUT_BINDING_DESCRIPTION_2_EXT, + .binding = 0, + .stride = 20, + .inputRate = VK_VERTEX_INPUT_RATE_VERTEX, + .divisor = 1, + }; + VkVertexInputAttributeDescription2EXT attributes[2] = { + { + VK_STRUCTURE_TYPE_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION_2_EXT, + NULL, + 0, 0, + VK_FORMAT_R32G32B32_SFLOAT, + 0 + }, + { + VK_STRUCTURE_TYPE_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION_2_EXT, + NULL, + 1, 0, + VK_FORMAT_R32G32_SFLOAT, + 12 + } + }; + _vkCmdSetVertexInputEXT(g_vkCommandBuffer, 1, &binding, 2, attributes); + + VkBool32 blendEnable = VK_FALSE; + VkColorBlendEquationEXT blendEquation = { + VK_BLEND_FACTOR_SRC_ALPHA, VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, VK_BLEND_OP_ADD, + VK_BLEND_FACTOR_ONE, VK_BLEND_FACTOR_ZERO, VK_BLEND_OP_ADD + }; + VkColorComponentFlags writeMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + + _vkCmdSetColorBlendEnableEXT(g_vkCommandBuffer, 0, 1, &blendEnable); + _vkCmdSetColorBlendEquationEXT(g_vkCommandBuffer, 0, 1, &blendEquation); + _vkCmdSetColorWriteMaskEXT(g_vkCommandBuffer, 0, 1, &writeMask); + + vkCmdBindPipeline(g_vkCommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_meshPipeline.m_pipeline); + vkCmdBindDescriptorSets(g_vkCommandBuffer,VK_PIPELINE_BIND_POINT_GRAPHICS, g_meshPipeline.m_layout, 0, 1, &g_meshDescriptorSet, 0, NULL); + for (auto &mesh: g_drawnMeshes) + { + VkDeviceSize offset = 0; + uint32_t textureID = mesh.m_material.albedo; + vkCmdPushConstants(g_vkCommandBuffer, g_meshPipeline.m_layout, VK_SHADER_STAGE_ALL, 0, 64, mesh.m_matrix); + vkCmdPushConstants(g_vkCommandBuffer, g_meshPipeline.m_layout, VK_SHADER_STAGE_ALL, 64, 4, &textureID); + vkCmdBindVertexBuffers(g_vkCommandBuffer, 0, 1, &mesh.m_pVertexBuffer->m_buffer.m_buffer, &offset); + if (mesh.m_pIndexBuffer) + { + vkCmdBindIndexBuffer( + g_vkCommandBuffer, + mesh.m_pIndexBuffer->m_buffer.m_buffer, + 0, + VK_INDEX_TYPE_UINT32 + ); + vkCmdDrawIndexed(g_vkCommandBuffer, mesh.m_pIndexBuffer->m_buffer.m_nSize/4, 1, 0, 0, 0); + } + else + { + vkCmdDraw(g_vkCommandBuffer, mesh.m_pVertexBuffer->m_buffer.m_nSize/12,1,0,0); + } + } + vkCmdEndRendering(g_vkCommandBuffer); + + barrier = { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, + .srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + .dstAccessMask = 0, + .oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + .newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, + .image = g_swapchainImage, + .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1} + }; + + vkCmdPipelineBarrier(g_vkCommandBuffer, + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, + VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, + 0, 0, NULL, 0, NULL, 1, &barrier); + g_drawnMeshes = CUtlVector(); + +} + + +IMesh *IMeshRenderer::CreateMesh() +{ + CMesh *mesh = new CMesh; + return mesh; +} + +void IMeshRenderer::Destroy( IBrush *pModel ) +{ + +} + diff --git a/engine/vk_postprocessing.cpp b/engine/vk_postprocessing.cpp new file mode 100644 index 0000000..e69de29 diff --git a/engine/vk_shading.cpp b/engine/vk_shading.cpp new file mode 100644 index 0000000..e69de29 diff --git a/engine/vk_video.cpp b/engine/vk_video.cpp index 77ea595..695d401 100644 --- a/engine/vk_video.cpp +++ b/engine/vk_video.cpp @@ -11,6 +11,15 @@ VkSampler g_invalidTextureSampler; +vk_buffer_t g_cameraProperties; +CameraProjection *g_cameraDataMap; + +IMaterial *g_pDefaultMaterial; +IMaterial *g_pCurrentMaterial; + +vk_image2d_t g_meshdepth; +vk_image2d_t g_meshcolor; + void IVulkan::Init() { char invalidTexture[1024] = {}; @@ -43,13 +52,33 @@ void IVulkan::Init() samplerInfo.minLod = 0.0f; samplerInfo.maxLod = 0.0f; vkCreateSampler(g_vkDevice, &samplerInfo, nullptr, &g_invalidTextureSampler); - IBrushRenderer::Init(); + + g_cameraProperties.Create(sizeof(CameraProjection), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT); + g_cameraDataMap = (CameraProjection*)g_cameraProperties.Map(0, 64); + g_meshdepth.Create(1280, 720, VK_FORMAT_D32_SFLOAT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); + g_meshcolor.Create(1280, 720, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); + + IBrushRenderer::Init(); + IMeshRenderer::Init(); }; void IVulkan::Frame() { + glm_mat4_identity(g_cameraDataMap->viewprojection); + glm_perspective(glm_rad(90),(float)g_nWindowWidth/g_nWindowHeight, 0.01, 100, g_cameraDataMap->viewprojection); + glm_rotate(g_cameraDataMap->viewprojection, glm_rad(90), (vec4){1,0,0,0}); + glm_scale(g_cameraDataMap->viewprojection, (vec4){1,-1,1,1}); + glm_rotate(g_cameraDataMap->viewprojection, glm_rad(90), (vec4){0,0,1,0}); + + if (g_bConfigNotify) + { + g_meshdepth.Destroy(); + g_meshdepth.Create(g_nWindowWidth, g_nWindowHeight, VK_FORMAT_D32_SFLOAT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); + } + IBrushRenderer::Frame(0); + IMeshRenderer::Frame(0); }; void vk_shader_t::Create( const char *szPath, VkShaderStageFlagBits shaderStage ) @@ -472,3 +501,35 @@ ITexture *ITextureManager::LoadTexture( const char *szName ) pTexture->szName = szName; return pTexture; }; + +IMaterial *IRenderer::LoadMaterial( const char *szMaterial ) +{ + FileHandle_t file = IFileSystem::Open(szMaterial, IFILE_READ); + IMaterial *pMaterial = new IMaterial; + if (!file) + { + return g_pDefaultMaterial; + } + + IFileSystem::Close(file); +} + +void IRenderer::SetMaterial( IMaterial *pMaterial ) +{ + g_pCurrentMaterial = pMaterial; +} + +IVertexBuffer *IRenderer::CreateVertexBuffer( uint32_t uSize ) +{ + CVertexBuffer *pBuffer = new CVertexBuffer(); + pBuffer->m_buffer.Create(uSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT); + return pBuffer; +} + +IIndexBuffer *IRenderer::CreateIndexBuffer( uint32_t uSize ) +{ + CIndexBuffer *pBuffer = new CIndexBuffer(); + pBuffer->m_buffer.Create(uSize, VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT); + return pBuffer; +} + diff --git a/engine/vk_videolinux.cpp b/engine/vk_videolinux.cpp index c8674d6..d1d52ef 100644 --- a/engine/vk_videolinux.cpp +++ b/engine/vk_videolinux.cpp @@ -38,6 +38,7 @@ ConVar vulkan_gpu("vk_gpu", "0", FCVAR_ARCHIVE); VkCommandPool g_vkCommandPool; + /* more efficient */ CUtlVector g_commandBuffers; VkCommandBuffer g_vkCommandBuffer; @@ -49,11 +50,18 @@ VkImage g_swapchainImage; uint32_t g_nNumSwapchainImages = 0; +#define VK_DEVICE_FUNCTION(name) PFN_##name _##name +#include "vk_external_functions.cpp" +#undef VK_DEVICE_FUNCTION + +char g_bConfigNotify = 0; +uint32_t g_nWindowWidth = 1280; +uint32_t g_nWindowHeight = 720; + void IVideo_SwapchainInit() { /* swapchain */ - VkXlibSurfaceCreateInfoKHR surfaceCreateInfo = {}; surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR; surfaceCreateInfo.dpy = g_xdisplay; @@ -176,16 +184,13 @@ void IVideo_SwapchainDestroy() } }; -#define VK_DEVICE_FUNCTION(name) PFN_##name _##name -#include "vk_external_functions.cpp" -#undef VK_DEVICE_FUNCTION - void IVideo::Init() { g_xdisplay = XOpenDisplay(NULL); g_xscreen = DefaultScreen(g_xdisplay); g_xroot = RootWindow(g_xdisplay, g_xscreen); g_xwin = XCreateSimpleWindow(g_xdisplay, g_xroot, 0, 0, 1280, 720, 0, 0, 0); + XSelectInput(g_xdisplay, g_xwin, StructureNotifyMask); vulkan_gpu.SetValue(ICommandLine::ParamValue("-gpu")); @@ -338,7 +343,6 @@ void IVideo::Init() #undef VK_DEVICE_FUNCTION IVideo_SwapchainInit(); - XMapWindow(g_xdisplay, g_xwin); XFlush(g_xdisplay); @@ -346,10 +350,6 @@ void IVideo::Init() } -char g_bConfigNotify = 0; -uint32_t g_nWindowWidth = 1280; -uint32_t g_nWindowHeight = 720; - void IVideo_HandleX11() { XEvent event; diff --git a/engine/vk_videosdl.cpp b/engine/vk_videosdl.cpp new file mode 100644 index 0000000..7b89978 --- /dev/null +++ b/engine/vk_videosdl.cpp @@ -0,0 +1,424 @@ +#include "rendering.h" +#include "tier0/platform.h" +#include "tier1/utlvector.h" +#include "console.h" +#include "tier1/commandline.h" + +#include "vulkan/vulkan.h" +#include "SDL3/SDL.h" +#define SDL_MAIN_HANDLED +#include "SDL3/SDL_main.h" +#include "SDL3/SDL_vulkan.h" +#include "SDL3/SDL_events.h" + +#define VULKAN_RENDERING_IMPL +#include "vk_video.h" + +#define VMA_VULKAN_VERSION 1004000 +#define VMA_IMPLEMENTATION +#include "vk_mem_alloc.h" + +SDL_Window *g_window; + +VkInstance g_vkInstance = NULL; +VkPhysicalDevice g_vkPhysicalDevice = NULL; +VkDevice g_vkDevice = NULL; +uint32_t g_drawfamily = 0; +VkQueue g_drawQueue; +uint32_t g_presentfamily = 0; +VkQueue g_presentQueue; +VmaAllocator g_allocator = NULL; + +VkSurfaceKHR g_surface; +VkSwapchainKHR g_swapchain; + +ConVar vulkan_gpu("vk_gpu", "0", FCVAR_ARCHIVE); + + +VkCommandPool g_vkCommandPool; + +/* more efficient */ +CUtlVector g_commandBuffers; +VkCommandBuffer g_vkCommandBuffer; +CUtlVector g_frameData; +CUtlVector g_swapchainImages; +CUtlVector g_swapchainImageViews; +VkImageView g_swapchainImageView; +VkImage g_swapchainImage; + +uint32_t g_nNumSwapchainImages = 0; + +#define VK_DEVICE_FUNCTION(name) PFN_##name _##name +#include "vk_external_functions.cpp" +#undef VK_DEVICE_FUNCTION + +char g_bConfigNotify = 0; +uint32_t g_nWindowWidth = 1280; +uint32_t g_nWindowHeight = 720; + + +void IVideo_SwapchainInit() +{ + + /* swapchain */ + SDL_Vulkan_CreateSurface(g_window, g_vkInstance, NULL, &g_surface); + + VkSurfaceCapabilitiesKHR surfaceCapatibilities = {}; + + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(g_vkPhysicalDevice, g_surface, &surfaceCapatibilities); + + const VkFormat preferedSurfaceFormats[] = { + VK_FORMAT_R8G8B8A8_UNORM, + VK_FORMAT_B8G8R8A8_UNORM, + }; + + uint32_t numSurfaceFormats = 0; + vkGetPhysicalDeviceSurfaceFormatsKHR(g_vkPhysicalDevice, g_surface, &numSurfaceFormats, NULL); + CUtlVector surfaceFormats(numSurfaceFormats); + vkGetPhysicalDeviceSurfaceFormatsKHR(g_vkPhysicalDevice, g_surface, &numSurfaceFormats, surfaceFormats.GetData()); + + VkSurfaceFormatKHR selectedFormat = surfaceFormats[0]; + for (auto &format: surfaceFormats) + { + for (int i = 0; i < sizeof(preferedSurfaceFormats)/sizeof(VkFormat); i++) + { + selectedFormat = surfaceFormats[i]; + } + } + + uint32_t numSurfacePresentModes = 0; + vkGetPhysicalDeviceSurfacePresentModesKHR(g_vkPhysicalDevice, g_surface, &numSurfacePresentModes, NULL); + CUtlVector surfacePresentModes(numSurfacePresentModes); + vkGetPhysicalDeviceSurfacePresentModesKHR(g_vkPhysicalDevice, g_surface, &numSurfacePresentModes, surfacePresentModes.GetData()); + + VkSwapchainCreateInfoKHR swapchainCreateInfo = {}; + swapchainCreateInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + swapchainCreateInfo.surface = g_surface; + swapchainCreateInfo.imageFormat = selectedFormat.format; + swapchainCreateInfo.imageColorSpace = selectedFormat.colorSpace; + swapchainCreateInfo.presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR; + swapchainCreateInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + swapchainCreateInfo.preTransform = surfaceCapatibilities.currentTransform; + swapchainCreateInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + swapchainCreateInfo.imageArrayLayers = 1; + swapchainCreateInfo.imageExtent = surfaceCapatibilities.minImageExtent; + swapchainCreateInfo.minImageCount = surfaceCapatibilities.minImageCount; + vkCreateSwapchainKHR(g_vkDevice, &swapchainCreateInfo, NULL, &g_swapchain); + + vkGetSwapchainImagesKHR(g_vkDevice, g_swapchain, &g_nNumSwapchainImages, NULL); + g_swapchainImages = CUtlVector(g_nNumSwapchainImages); + g_swapchainImageViews = CUtlVector(g_nNumSwapchainImages); + g_commandBuffers = CUtlVector(g_nNumSwapchainImages); + g_frameData = CUtlVector(g_nNumSwapchainImages); + vkGetSwapchainImagesKHR(g_vkDevice, g_swapchain, &g_nNumSwapchainImages, g_swapchainImages.GetData()); + + for (int i = 0; i < g_nNumSwapchainImages; i++) + { + VkImageViewCreateInfo createInfo = {}; + createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + createInfo.image = g_swapchainImages[i]; + createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; + createInfo.format = selectedFormat.format; + createInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + createInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + createInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + createInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + createInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + createInfo.subresourceRange.baseMipLevel = 0; + createInfo.subresourceRange.levelCount = 1; + createInfo.subresourceRange.baseArrayLayer = 0; + createInfo.subresourceRange.layerCount = 1; + + vkCreateImageView(g_vkDevice, &createInfo, NULL, &g_swapchainImageViews[i]); + } + + + /* command buffers */ + VkCommandPoolCreateInfo commandPoolCreateInfo = {}; + commandPoolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + commandPoolCreateInfo.queueFamilyIndex = g_drawfamily; + commandPoolCreateInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + vkCreateCommandPool(g_vkDevice, &commandPoolCreateInfo, NULL, &g_vkCommandPool); + + VkCommandBufferAllocateInfo commandBufferAllocInfo = {}; + commandBufferAllocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + commandBufferAllocInfo.commandPool = g_vkCommandPool; + commandBufferAllocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + commandBufferAllocInfo.commandBufferCount = g_nNumSwapchainImages; + vkAllocateCommandBuffers(g_vkDevice, &commandBufferAllocInfo, g_commandBuffers.GetData()); + + /* sync */ + + VkFenceCreateInfo fenceCreateInfo = {}; + fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + fenceCreateInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; + + VkSemaphoreCreateInfo semaphoreCreateInfo = {}; + semaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + + for (int i = 0; i < g_nNumSwapchainImages; i++) + { + vkCreateFence(g_vkDevice,&fenceCreateInfo, NULL, &g_frameData[i].fence); + vkCreateSemaphore(g_vkDevice, &semaphoreCreateInfo, NULL, &g_frameData[i].draw); + vkCreateSemaphore(g_vkDevice, &semaphoreCreateInfo, NULL, &g_frameData[i].present); + } + +}; + +void IVideo_SwapchainDestroy() +{ + vkDestroySwapchainKHR(g_vkDevice, g_swapchain, NULL); + vkDestroySurfaceKHR(g_vkInstance, g_surface, NULL); + for (int i = 0; i < g_nNumSwapchainImages; i++) + { + vkDestroyImageView(g_vkDevice, g_swapchainImageViews[i], NULL); + vkDestroySemaphore(g_vkDevice, g_frameData[i].draw, NULL); + vkDestroySemaphore(g_vkDevice, g_frameData[i].present, NULL); + vkDestroyFence(g_vkDevice, g_frameData[i].fence, NULL); + } +}; + +void IVideo::Init() +{ + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS); + g_window = SDL_CreateWindow("rtt", 1280, 720, SDL_WINDOW_VULKAN); + + unsigned int nExtensionCount = 0; + const char* const* szExtensions = SDL_Vulkan_GetInstanceExtensions(&nExtensionCount); + + vulkan_gpu.SetValue(ICommandLine::ParamValue("-gpu")); + VkResult r = VK_SUCCESS; + uint32_t i = 0; + + /* Instance */ + VkApplicationInfo applicationInfo = {}; + applicationInfo.apiVersion = VK_API_VERSION_1_4; + + VkInstanceCreateInfo instanceCreateInfo = {}; + instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + instanceCreateInfo.pApplicationInfo = &applicationInfo; + + instanceCreateInfo.enabledExtensionCount = nExtensionCount; + instanceCreateInfo.ppEnabledExtensionNames = szExtensions; + r = vkCreateInstance(&instanceCreateInfo, NULL, &g_vkInstance); + if ( r != VK_SUCCESS ) + Plat_FatalErrorFunc("Failed to create VkInstance!"); + + + /* Physical Devices */ + uint32_t nNumPhysicalDevices = 0; + vkEnumeratePhysicalDevices(g_vkInstance, &nNumPhysicalDevices, NULL); + if ( nNumPhysicalDevices == 0 ) + Plat_FatalErrorFunc("No GPU drivers available!"); + CUtlVector PhysicalDevices(nNumPhysicalDevices); + + vkEnumeratePhysicalDevices(g_vkInstance, &nNumPhysicalDevices, PhysicalDevices.GetData()); + + /* enumerate them for the user */ + for (auto &device: PhysicalDevices) + { + VkPhysicalDeviceProperties Properties = {}; + vkGetPhysicalDeviceProperties(device, &Properties); + V_printf("GPU%i available: %s\n", i, Properties.deviceName); + i++; + } + + /* select one in vk_gpu */ + g_vkPhysicalDevice = PhysicalDevices[vulkan_gpu.GetInt()]; + VkPhysicalDeviceProperties Properties = {}; + vkGetPhysicalDeviceProperties(g_vkPhysicalDevice, &Properties); + V_printf("Using %s\n", Properties.deviceName); + + /* queue family */ + uint32_t nNumQueueFamilies = 0; + vkGetPhysicalDeviceQueueFamilyProperties(g_vkPhysicalDevice, &nNumQueueFamilies, NULL); + CUtlVector queueFamilyProperties(nNumQueueFamilies); + vkGetPhysicalDeviceQueueFamilyProperties(g_vkPhysicalDevice, &nNumQueueFamilies, queueFamilyProperties.GetData()); + + i = 0; + for (auto &family: queueFamilyProperties) + { + if (family.queueFlags & VK_QUEUE_GRAPHICS_BIT) + { + g_drawfamily = i; + g_presentfamily = i; + } + i++; + } + + /* create device */ + float queuePriority = 1.0f; + VkDeviceQueueCreateInfo queueCreateInfo = {}; + queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + queueCreateInfo.queueFamilyIndex = g_drawfamily; + queueCreateInfo.queueCount = 1; + queueCreateInfo.pQueuePriorities = &queuePriority; + + VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT pdvidsfe = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_INPUT_DYNAMIC_STATE_FEATURES_EXT, + .vertexInputDynamicState = VK_TRUE, + }; + + VkPhysicalDeviceExtendedDynamicState3FeaturesEXT pdeds3fe = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_3_FEATURES_EXT, + .pNext = &pdvidsfe, + .extendedDynamicState3DepthClampEnable = VK_TRUE, + .extendedDynamicState3PolygonMode = VK_TRUE, + .extendedDynamicState3RasterizationSamples = VK_TRUE, + .extendedDynamicState3SampleMask = VK_TRUE, + .extendedDynamicState3AlphaToCoverageEnable = VK_TRUE, + .extendedDynamicState3LogicOpEnable = VK_TRUE, + .extendedDynamicState3ColorBlendEnable = VK_TRUE, + .extendedDynamicState3ColorBlendEquation = VK_TRUE, + .extendedDynamicState3ColorWriteMask = VK_TRUE, + }; + + VkPhysicalDeviceExtendedDynamicState2FeaturesEXT pdeds2fe = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_2_FEATURES_EXT, + .pNext = &pdeds3fe, + .extendedDynamicState2LogicOp = VK_TRUE, + .extendedDynamicState2PatchControlPoints = VK_TRUE, + }; + + VkPhysicalDeviceVulkan13Features pdv13f = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES, + .pNext = &pdeds2fe, + .dynamicRendering = VK_TRUE, + }; + VkPhysicalDeviceVulkan12Features pdv12f = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, + .pNext = &pdv13f, + .runtimeDescriptorArray = VK_TRUE, + .bufferDeviceAddress = VK_TRUE, + }; + VkPhysicalDeviceVulkan11Features pdv11f = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES, + .pNext = &pdv12f, + }; + + const char *szEnabledGPUExtensions[] = { + VK_KHR_SWAPCHAIN_EXTENSION_NAME, + VK_EXT_VERTEX_INPUT_DYNAMIC_STATE_EXTENSION_NAME, + VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME, + }; + VkDeviceCreateInfo deviceCreateInfo = {}; + deviceCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + deviceCreateInfo.pQueueCreateInfos = &queueCreateInfo; + deviceCreateInfo.queueCreateInfoCount = 1; + deviceCreateInfo.enabledExtensionCount = sizeof(szEnabledGPUExtensions)/(sizeof(const char*)); + deviceCreateInfo.ppEnabledExtensionNames = szEnabledGPUExtensions; + deviceCreateInfo.pNext = &pdv11f; + + r = vkCreateDevice(g_vkPhysicalDevice, &deviceCreateInfo, NULL, &g_vkDevice); + if ( r != VK_SUCCESS ) + Plat_FatalErrorFunc("Failed to create VkDevice!"); + vkGetDeviceQueue(g_vkDevice, g_drawfamily, 0, &g_drawQueue); + vkGetDeviceQueue(g_vkDevice, g_presentfamily, 0, &g_presentQueue); + + VmaVulkanFunctions vulkanFunctions = {}; + vulkanFunctions.vkGetInstanceProcAddr = &vkGetInstanceProcAddr; + vulkanFunctions.vkGetDeviceProcAddr = &vkGetDeviceProcAddr; + + VmaAllocatorCreateInfo allocatorCreateInfo = {}; + allocatorCreateInfo.flags = VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT; + allocatorCreateInfo.vulkanApiVersion = VK_API_VERSION_1_4; + allocatorCreateInfo.physicalDevice = g_vkPhysicalDevice; + allocatorCreateInfo.device = g_vkDevice; + allocatorCreateInfo.instance = g_vkInstance; + vmaCreateAllocator(&allocatorCreateInfo, &g_allocator); + + #define VK_DEVICE_FUNCTION(name) _##name = (PFN_##name)vkGetDeviceProcAddr(g_vkDevice, #name) + #include "vk_external_functions.cpp" + #undef VK_DEVICE_FUNCTION + + IVideo_SwapchainInit(); + + IVulkan::Init(); + +} + +void IVideo_HandleEvents() +{ + SDL_Event event; + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_EVENT_WINDOW_RESIZED: + g_nWindowWidth = event.window.data1; + g_nWindowHeight = event.window.data2; + g_bConfigNotify = 2; + } + }; +}; + + +void IVideo::Frame( float fDelta ) +{ + static uint32_t s_frameID = 0; + IVideo_HandleEvents(); + + vk_framedata_t frame = g_frameData[s_frameID]; + vkDeviceWaitIdle(g_vkDevice); + + vkWaitForFences(g_vkDevice, 1, &frame.fence, VK_TRUE, UINT64_MAX); + + uint32_t imageIndex = 0; + VkResult r = vkAcquireNextImageKHR(g_vkDevice, g_swapchain, UINT64_MAX, frame.draw, VK_NULL_HANDLE, &imageIndex); + if (r == VK_ERROR_OUT_OF_DATE_KHR || r == VK_SUBOPTIMAL_KHR || g_bConfigNotify == 2) + { + g_bConfigNotify=1; + vkDeviceWaitIdle(g_vkDevice); + IVideo_SwapchainDestroy(); + IVideo_SwapchainInit(); + return; + } + vk_framedata_t frameindex = g_frameData[imageIndex]; + + vkResetFences(g_vkDevice, 1, &frame.fence); + + g_vkCommandBuffer = g_commandBuffers[s_frameID]; + g_swapchainImageView = g_swapchainImageViews[imageIndex]; + g_swapchainImage = g_swapchainImages[imageIndex]; + vkResetCommandBuffer(g_vkCommandBuffer, 0); + + VkCommandBufferBeginInfo beginInfo = {}; + beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + vkBeginCommandBuffer(g_vkCommandBuffer, &beginInfo); + IVulkan::Frame(); + vkEndCommandBuffer(g_vkCommandBuffer); + + VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT}; + VkSubmitInfo submitInfo = {}; + submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submitInfo.waitSemaphoreCount = 1; + submitInfo.pWaitSemaphores = &frame.draw; + submitInfo.pWaitDstStageMask = waitStages; + submitInfo.commandBufferCount = 1; + submitInfo.pCommandBuffers = &g_vkCommandBuffer; + submitInfo.signalSemaphoreCount = 1; + submitInfo.pSignalSemaphores = &frameindex.present; + + vkQueueSubmit(g_drawQueue, 1, &submitInfo, frame.fence); + + VkPresentInfoKHR presentInfo = {}; + presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + presentInfo.waitSemaphoreCount = 1; + presentInfo.pWaitSemaphores = &frameindex.present; + presentInfo.swapchainCount = 1; + presentInfo.pSwapchains = &g_swapchain; + presentInfo.pImageIndices = &imageIndex; + + + r = vkQueuePresentKHR(g_presentQueue, &presentInfo); + if (r == VK_ERROR_OUT_OF_DATE_KHR || r == VK_SUBOPTIMAL_KHR) + { + vkDeviceWaitIdle(g_vkDevice); + IVideo_SwapchainDestroy(); + IVideo_SwapchainInit(); + return; + } + + g_bConfigNotify = 0; + s_frameID=(s_frameID+1)%g_nNumSwapchainImages; +}; diff --git a/external/SDL b/external/SDL new file mode 160000 index 0000000..b512735 --- /dev/null +++ b/external/SDL @@ -0,0 +1 @@ +Subproject commit b51273512b8eaf6c42986335fefb4235a444e505 diff --git a/fpc/build.sh b/fpc/build.sh new file mode 100644 index 0000000..e69de29 diff --git a/fpc/main.cpp b/fpc/main.cpp new file mode 100644 index 0000000..e69de29 diff --git a/funnyassets/__build.c b/funnyassets/__build.c index b5ce5a1..3bdbdf8 100644 --- a/funnyassets/__build.c +++ b/funnyassets/__build.c @@ -1,3 +1,4 @@ +#include "god/build.h" #include "god/slang.h" #include "god/utils.h" #include "god/common.h" @@ -13,7 +14,7 @@ void build_shader(char *name, enum slang_stage stage) mv(string_clone("funnyassets/_rtt/gfx/%s.spv",name),file); }; -void makepak(char *name) +void makepak(struct build_data b, char *name) { struct run_project rp = run_new("python"); run_add_arg(&rp, "tools/makepak64.py"); @@ -28,9 +29,11 @@ void assets_build(struct build_data b) makedir("funnyassets/_rtt/gfx"); build_shader("brush_frag", SLANG_STAGE_FRAGMENT); build_shader("brush_vert", SLANG_STAGE_VERTEX); + build_shader("mesh_frag", SLANG_STAGE_FRAGMENT); + build_shader("mesh_vert", SLANG_STAGE_VERTEX); mv("funnyassets/_rtt/","funnyassets/maps"); mv("funnyassets/_rtt/","funnyassets/gfx"); mv("funnyassets/_rtt/","funnyassets/textures"); mv("funnyassets/_rtt/","funnyassets/materials"); - makepak("rtt"); + makepak(b, "rtt"); } diff --git a/funnyassets/_rtt/gfx/mesh_frag.spv b/funnyassets/_rtt/gfx/mesh_frag.spv new file mode 100644 index 0000000..060bbd1 Binary files /dev/null and b/funnyassets/_rtt/gfx/mesh_frag.spv differ diff --git a/funnyassets/_rtt/gfx/mesh_vert.spv b/funnyassets/_rtt/gfx/mesh_vert.spv new file mode 100644 index 0000000..73c788a Binary files /dev/null and b/funnyassets/_rtt/gfx/mesh_vert.spv differ diff --git a/funnyassets/_rtt/maps/test_map.fmap b/funnyassets/_rtt/maps/test_map.fmap index eaba661..5d27d77 100644 Binary files a/funnyassets/_rtt/maps/test_map.fmap and b/funnyassets/_rtt/maps/test_map.fmap differ diff --git a/funnyassets/gfx_shaders/mesh_frag.slang b/funnyassets/gfx_shaders/mesh_frag.slang new file mode 100644 index 0000000..da95e75 --- /dev/null +++ b/funnyassets/gfx_shaders/mesh_frag.slang @@ -0,0 +1,23 @@ +#include "mesh_shared.slang" + +uint32_t hash32(uint32_t x) { + x = ((x >> 16) ^ x) * 0x45d9f3b; + x = ((x >> 16) ^ x) * 0x45d9f3b; + x = (x >> 16) ^ x; + return x; +} + +[[vk::binding(1)]] +uniform Sampler2D textures[]; + + +float4 main( + VertexOutput input, + uint triid: SV_PrimitiveID, + uniform PushConstants constants, +) : SV_TARGET +{ + return float4(textures[constants.albedoID].Sample(input.uv).xyz, 1); + +} + diff --git a/funnyassets/gfx_shaders/mesh_shared.slang b/funnyassets/gfx_shaders/mesh_shared.slang new file mode 100644 index 0000000..c4d96ff --- /dev/null +++ b/funnyassets/gfx_shaders/mesh_shared.slang @@ -0,0 +1,15 @@ +#pragma once + +struct VertexOutput +{ + float4 position: SV_Position; + float2 uv: TEXCOORD0; +}; + +struct PushConstants +{ + float4x4 modelMatrix; + uint albedoID; + uint roughnessID; + uint metalnessID; +}; diff --git a/funnyassets/gfx_shaders/mesh_vert.slang b/funnyassets/gfx_shaders/mesh_vert.slang new file mode 100644 index 0000000..3204921 --- /dev/null +++ b/funnyassets/gfx_shaders/mesh_vert.slang @@ -0,0 +1,24 @@ +#include "mesh_shared.slang" + +struct VertexInput +{ + float3 position: POSITION; + float2 uv: TEXCOORD0; +}; + +[[vk::binding(0)]] +cbuffer CameraInfo +{ + float4x4 projection; +}; + +VertexOutput main( + VertexInput input, + uniform PushConstants constants, +) +{ + VertexOutput output; + output.position = mul(projection, mul(constants.modelMatrix, float4(input.position,1))); + output.uv = input.uv; + return output; +} diff --git a/funnyassets/maps/test_map.fmap b/funnyassets/maps/test_map.fmap index eaba661..5d27d77 100644 Binary files a/funnyassets/maps/test_map.fmap and b/funnyassets/maps/test_map.fmap differ diff --git a/funnyassets/raw_maps/dust.map b/funnyassets/raw_maps/dust.map index cfbb044..6a774fe 100644 --- a/funnyassets/raw_maps/dust.map +++ b/funnyassets/raw_maps/dust.map @@ -1,99 +1,99 @@ { "classname" "worldspawn" { -(-10.000000 -5.999999 -2.000000) (-10.000001 -9.999999 -2.000000) (-10.000001 -9.999999 -4.000000) (6.483328 1.451694) (6.483328 0.190320) (7.114015 0.190320) BRICK0 -(-10.000000 -5.999999 -2.000000) (-10.000001 -9.999999 -4.000000) (-10.000000 -5.999999 -4.000000) (6.483328 1.451694) (7.114015 0.190320) (7.114015 1.451694) BRICK0 -(-14.000000 -1.999999 -2.000000) (-16.000000 -1.999999 -2.000000) (-16.000000 -2.299999 -2.000000) (0.820848 2.713067) (0.190320 2.713067) (0.190320 2.618464) BRICK0 -(-14.000000 -1.999999 -2.000000) (-16.000000 -2.299999 -2.000000) (-14.000000 -2.299999 -2.000000) (0.820848 2.713067) (0.190320 2.618464) (0.820848 2.618464) BRICK0 -(-8.000000 -1.999999 -4.000000) (-8.000000 2.000001 -4.000000) (-12.000000 2.000001 -2.000000) (2.726604 2.713067) (2.726604 3.974441) (1.451375 3.974441) BRICK0 -(-8.000000 -1.999999 -4.000000) (-12.000000 2.000001 -2.000000) (-12.000000 -1.999999 -2.000000) (2.726604 2.713067) (1.451375 3.974441) (1.451375 2.713067) BRICK0 -(-8.000000 -1.999999 -4.000000) (-12.000000 -1.999999 -2.000000) (-8.000000 -1.999999 -2.000000) (6.798353 5.902491) (6.167666 7.163865) (6.167666 5.902491) BRICK0 -(-14.000000 -1.999999 -2.000000) (-14.000000 2.000001 -2.000000) (-16.000000 2.000001 -2.000000) (0.820848 2.713067) (0.820848 3.974441) (0.190320 3.974441) BRICK0 -(-14.000000 -1.999999 -2.000000) (-16.000000 2.000001 -2.000000) (-16.000000 -1.999999 -2.000000) (0.820848 2.713067) (0.190320 3.974441) (0.190320 2.713067) BRICK0 -(-14.000000 -2.299999 -2.000000) (-16.000000 -2.299999 -2.000000) (-16.000000 -5.699999 -2.000000) (0.820848 2.618464) (0.190320 2.618464) (0.190320 1.546297) BRICK0 -(-14.000000 -2.299999 -2.000000) (-16.000000 -5.699999 -2.000000) (-14.000000 -5.699999 -2.000000) (0.820848 2.618464) (0.190320 1.546297) (0.820848 1.546297) BRICK0 -(-4.000000 -2.000000 -4.000000) (-4.000000 2.000000 -4.000000) (-8.000000 2.000001 -4.000000) (3.987659 2.713067) (3.987659 3.974441) (2.726604 3.974441) BRICK0 -(-4.000000 -2.000000 -4.000000) (-8.000000 2.000001 -4.000000) (-8.000000 -1.999999 -4.000000) (3.987659 2.713067) (2.726604 3.974441) (2.726604 2.713067) BRICK0 -(-12.000000 -2.299999 -2.000000) (-12.000000 -5.699999 -2.000000) (-10.300000 -5.699999 -2.000000) (1.451375 2.618464) (1.451375 1.546297) (1.987324 1.546297) BRICK0 -(-12.000000 -2.299999 -2.000000) (-10.300000 -5.699999 -2.000000) (-10.300000 -2.299999 -2.000000) (1.451375 2.618464) (1.987324 1.546297) (1.987324 2.618464) BRICK0 -(-8.000000 -6.000000 -4.000000) (-10.000000 -5.999999 -4.000000) (-10.000001 -9.999999 -4.000000) (2.726604 1.451694) (2.096077 1.451694) (2.096077 0.190320) BRICK0 -(-8.000000 -6.000000 -4.000000) (-10.000001 -9.999999 -4.000000) (-8.000001 -9.999999 -4.000000) (2.726604 1.451694) (2.096077 0.190320) (2.726604 0.190320) BRICK0 -(-4.000000 -6.000000 -4.000000) (-8.000000 -6.000000 -4.000000) (-8.000001 -9.999999 -4.000000) (3.987659 1.451694) (2.726604 1.451694) (2.726604 0.190320) BRICK0 -(-4.000000 -6.000000 -4.000000) (-8.000001 -9.999999 -4.000000) (-4.000000 -10.000000 -4.000000) (3.987659 1.451694) (2.726604 0.190320) (3.987659 0.190320) BRICK0 -(-8.000000 -6.000000 -4.000000) (-8.000000 -6.000000 -2.000000) (-10.000000 -5.999999 -2.000000) (6.325656 2.620692) (6.325656 1.990005) (6.956343 1.990005) BRICK0 -(-8.000000 -6.000000 -4.000000) (-10.000000 -5.999999 -2.000000) (-10.000000 -5.999999 -4.000000) (6.325656 2.620692) (6.956343 1.990005) (6.956343 2.620692) BRICK0 -(-8.000000 -1.999999 -4.000000) (-8.000000 -1.999999 -2.000000) (-8.000000 -6.000000 -2.000000) (5.156658 7.258468) (4.525971 7.258468) (4.525971 5.997094) BRICK0 -(-8.000000 -1.999999 -4.000000) (-8.000000 -6.000000 -2.000000) (-8.000000 -6.000000 -4.000000) (5.156658 7.258468) (4.525971 5.997094) (5.156658 5.997094) BRICK0 -(-4.000000 -2.000000 -4.000000) (-8.000000 -1.999999 -4.000000) (-8.000000 -6.000000 -4.000000) (3.987659 2.713067) (2.726604 2.713067) (2.726604 1.451694) BRICK0 -(-4.000000 -2.000000 -4.000000) (-8.000000 -6.000000 -4.000000) (-4.000000 -6.000000 -4.000000) (3.987659 2.713067) (2.726604 1.451694) (3.987659 1.451694) BRICK0 -(-10.300000 -2.299999 -2.000000) (-10.300000 -5.699999 -2.000000) (-8.300000 -5.699999 -2.000000) (1.987324 2.618464) (1.987324 1.546297) (2.617851 1.546297) BRICK0 -(-10.300000 -2.299999 -2.000000) (-8.300000 -5.699999 -2.000000) (-8.300000 -2.299999 -2.000000) (1.987324 2.618464) (2.617851 1.546297) (2.617851 2.618464) BRICK0 -(-10.300000 -5.699999 -2.000000) (-12.000000 -5.699999 -2.000000) (-12.000001 -9.999999 -2.000000) (1.987324 1.546297) (1.451375 1.546297) (1.451375 0.190320) BRICK0 -(-10.300000 -5.699999 -2.000000) (-12.000001 -9.999999 -2.000000) (-10.300001 -9.999999 -2.000000) (1.987324 1.546297) (1.451375 0.190320) (1.987324 0.190320) BRICK0 -(-8.000000 2.000001 -4.000000) (-4.000000 2.000000 -4.000000) (-4.000000 4.000000 -4.000000) (2.726604 3.974441) (3.987659 3.974441) (3.987659 4.605128) BRICK0 -(-8.000000 2.000001 -4.000000) (-4.000000 4.000000 -4.000000) (-8.000000 4.000000 -4.000000) (2.726604 3.974441) (3.987659 4.605128) (2.726604 4.605128) BRICK0 -(-8.000000 2.000001 -4.000000) (-8.000000 4.000000 -4.000000) (-8.000000 4.000000 -2.000000) (1.451694 6.562484) (0.821007 6.562484) (0.821007 5.931798) BRICK0 -(-8.000000 2.000001 -4.000000) (-8.000000 4.000000 -2.000000) (-8.000000 2.000001 -2.000000) (1.451694 6.562484) (0.821007 5.931798) (1.451694 5.931798) BRICK0 -(-8.000000 4.000000 -4.000000) (-4.000000 4.000000 -4.000000) (-4.000000 4.000000 -2.000000) (7.809680 5.902491) (7.809680 7.163865) (7.178993 7.163865) BRICK0 -(-8.000000 4.000000 -4.000000) (-4.000000 4.000000 -2.000000) (-8.000000 4.000000 -2.000000) (7.809680 5.902491) (7.178993 7.163865) (7.178992 5.902491) BRICK0 -(-8.000000 2.000001 -4.000000) (-8.000000 2.000001 -2.000000) (-12.000000 2.000001 -2.000000) (5.945016 2.713067) (5.314330 2.713067) (5.314329 1.451694) BRICK0 -(-12.000000 -5.699999 -2.000000) (-14.000000 -5.699999 -2.000000) (-14.000001 -9.999999 -2.000000) (1.451375 1.546297) (0.820848 1.546297) (0.820848 0.190320) BRICK0 -(-12.000000 -5.699999 -2.000000) (-14.000001 -9.999999 -2.000000) (-12.000001 -9.999999 -2.000000) (1.451375 1.546297) (0.820848 0.190320) (1.451375 0.190320) BRICK0 -(-12.000000 -2.299999 -2.000000) (-14.000000 -2.299999 -2.000000) (-14.000000 -5.699999 -2.000000) (1.451375 2.618464) (0.820848 2.618464) (0.820848 1.546297) BRICK0 -(-12.000000 -2.299999 -2.000000) (-14.000000 -5.699999 -2.000000) (-12.000000 -5.699999 -2.000000) (1.451375 2.618464) (0.820848 1.546297) (1.451375 1.546297) BRICK0 -(-12.000000 -1.999999 -2.000000) (-12.000000 2.000001 -2.000000) (-14.000000 2.000001 -2.000000) (1.451375 2.713067) (1.451375 3.974441) (0.820848 3.974441) BRICK0 -(-12.000000 -1.999999 -2.000000) (-14.000000 2.000001 -2.000000) (-14.000000 -1.999999 -2.000000) (1.451375 2.713067) (0.820848 3.974441) (0.820848 2.713067) BRICK0 -(-12.000000 -1.999999 -2.000000) (-14.000000 -1.999999 -2.000000) (-14.000000 -2.299999 -2.000000) (1.451375 2.713067) (0.820848 2.713067) (0.820848 2.618464) BRICK0 -(-12.000000 -1.999999 -2.000000) (-14.000000 -2.299999 -2.000000) (-12.000000 -2.299999 -2.000000) (1.451375 2.713067) (0.820848 2.618464) (1.451375 2.618464) BRICK0 -(-8.000000 2.000001 -2.000000) (-8.000000 4.000000 -2.000000) (-8.000000 4.000000 1.000000) (1.451694 5.931798) (0.821007 5.931798) (0.821007 4.985767) BRICK0 -(-8.000000 2.000001 -2.000000) (-8.000000 4.000000 1.000000) (-8.000000 2.000001 1.000000) (1.451694 5.931798) (0.821007 4.985767) (1.451694 4.985767) BRICK0 -(-14.000000 2.000001 -2.000000) (-12.000000 2.000001 -2.000000) (-12.000000 2.000001 1.000000) (5.314329 0.821007) (5.314329 1.451694) (4.368299 1.451694) BRICK0 -(-14.000000 2.000001 -2.000000) (-12.000000 2.000001 1.000000) (-14.000000 2.000001 1.000000) (5.314329 0.821007) (4.368299 1.451694) (4.368299 0.821007) BRICK0 -(-12.000000 2.000001 -2.000000) (-8.000000 2.000001 -2.000000) (-8.000000 2.000001 1.000000) (5.314329 1.451694) (5.314330 2.713067) (4.368299 2.713067) BRICK0 -(-12.000000 2.000001 -2.000000) (-8.000000 2.000001 1.000000) (-12.000000 2.000001 1.000000) (5.314329 1.451694) (4.368299 2.713067) (4.368299 1.451694) BRICK0 -(-16.000000 -2.299999 -2.000000) (-16.000000 -1.999999 -2.000000) (-16.000000 -1.999999 1.000000) (6.956025 4.165875) (6.956025 4.260478) (6.009995 4.260478) BRICK0 -(-16.000000 -2.299999 -2.000000) (-16.000000 -1.999999 1.000000) (-16.000000 -2.299999 1.000000) (6.956025 4.165875) (6.009995 4.260478) (6.009995 4.165875) BRICK0 -(-16.000000 -1.999999 -2.000000) (-16.000000 2.000001 -2.000000) (-16.000000 2.000001 1.000000) (6.956025 4.260478) (6.956025 5.521852) (6.009995 5.521852) BRICK0 -(-16.000000 -1.999999 -2.000000) (-16.000000 2.000001 1.000000) (-16.000000 -1.999999 1.000000) (6.956025 4.260478) (6.009995 5.521852) (6.009995 4.260478) BRICK0 -(-16.000000 2.000001 -2.000000) (-14.000000 2.000001 -2.000000) (-14.000000 2.000001 1.000000) (5.314329 0.190320) (5.314329 0.821007) (4.368299 0.821007) BRICK0 -(-16.000000 2.000001 -2.000000) (-14.000000 2.000001 1.000000) (-16.000000 2.000001 1.000000) (5.314329 0.190320) (4.368299 0.821007) (4.368299 0.190320) BRICK0 -(-14.000001 -9.999999 -2.000000) (-14.000000 -5.699999 -2.000000) (-14.000000 -5.699999 1.000000) (2.778364 4.985768) (2.778364 6.341744) (1.832334 6.341744) BRICK0 -(-14.000001 -9.999999 -2.000000) (-14.000000 -5.699999 1.000000) (-14.000001 -9.999999 1.000000) (2.778364 4.985768) (1.832334 6.341744) (1.832334 4.985768) BRICK0 -(-16.000000 -5.699999 -2.000000) (-16.000000 -2.299999 -2.000000) (-16.000000 -2.299999 1.000000) (6.956025 3.093707) (6.956025 4.165875) (6.009995 4.165875) BRICK0 -(-16.000000 -5.699999 -2.000000) (-16.000000 -2.299999 1.000000) (-16.000000 -5.699999 1.000000) (6.956025 3.093707) (6.009995 4.165875) (6.009994 3.093707) BRICK0 -(-14.000000 -5.699999 -2.000000) (-16.000000 -5.699999 -2.000000) (-16.000000 -5.699999 1.000000) (2.463020 7.668415) (1.832333 7.668415) (1.832333 6.722384) BRICK0 -(-14.000000 -5.699999 -2.000000) (-16.000000 -5.699999 1.000000) (-14.000000 -5.699999 1.000000) (2.463020 7.668415) (1.832333 6.722384) (2.463020 6.722384) BRICK0 -(-8.000000 4.000000 1.000000) (-8.000000 4.000000 -2.000000) (-8.000000 6.000000 -2.000000) (0.821007 4.985767) (0.821007 5.931798) (0.190320 5.931798) BRICK0 -(-8.000000 4.000000 1.000000) (-8.000000 6.000000 -2.000000) (-8.000000 6.000000 1.000000) (0.821007 4.985767) (0.190320 5.931798) (0.190320 4.985767) BRICK0 -(-10.300000 -2.299999 -2.000000) (-8.300000 -2.299999 -2.000000) (-8.300000 -2.299999 -1.500000) (3.854987 5.521851) (3.854987 6.152538) (3.697315 6.152538) BRICK0 -(-10.300000 -2.299999 -2.000000) (-8.300000 -2.299999 -1.500000) (-10.300000 -2.299999 -1.500000) (3.854987 5.521851) (3.697315 6.152538) (3.697315 5.521851) BRICK0 -(-10.300000 -5.699999 -2.000000) (-10.300001 -9.999999 -2.000000) (-10.300001 -9.999999 -1.500000) (3.316675 4.985768) (3.316675 6.341744) (3.159004 6.341744) BRICK0 -(-10.300000 -5.699999 -2.000000) (-10.300001 -9.999999 -1.500000) (-10.300000 -5.699999 -1.500000) (3.316675 4.985768) (3.159004 6.341744) (3.159004 4.985768) BRICK0 -(-10.000000 -5.999999 -2.000000) (-8.000000 -6.000000 -2.000000) (-8.000000 -6.000000 -1.500000) (6.956343 1.990005) (6.325656 1.990005) (6.325656 1.832333) BRICK0 -(-10.000000 -5.999999 -2.000000) (-8.000000 -6.000000 -1.500000) (-10.000000 -5.999999 -1.500000) (6.956343 1.990005) (6.325656 1.832333) (6.956343 1.832333) BRICK0 -(-12.000000 -1.999999 -2.000000) (-12.000000 -2.299999 -2.000000) (-12.000000 -2.299999 -1.500000) (2.938263 6.880056) (2.843660 6.880056) (2.843660 6.722384) BRICK0 -(-12.000000 -1.999999 -2.000000) (-12.000000 -2.299999 -1.500000) (-12.000000 -1.999999 -1.500000) (2.938263 6.880056) (2.843660 6.722384) (2.938263 6.722384) BRICK0 -(-8.300000 -2.299999 -2.000000) (-8.300000 -5.699999 -2.000000) (-8.300000 -5.699999 -1.500000) (7.494336 3.093707) (7.494337 4.165875) (7.336665 4.165875) BRICK0 -(-8.300000 -2.299999 -2.000000) (-8.300000 -5.699999 -1.500000) (-8.300000 -2.299999 -1.500000) (7.494336 3.093707) (7.336665 4.165875) (7.336665 3.093707) BRICK0 -(-8.000000 -1.999999 -2.000000) (-12.000000 -1.999999 -2.000000) (-12.000000 -1.999999 -1.500000) (6.167666 5.902491) (6.167666 7.163865) (6.009995 7.163865) BRICK0 -(-8.000000 -1.999999 -2.000000) (-12.000000 -1.999999 -1.500000) (-8.000000 -1.999999 -1.500000) (6.167666 5.902491) (6.009995 7.163865) (6.009995 5.902491) BRICK0 -(-8.000000 -6.000000 -2.000000) (-8.000000 -1.999999 -2.000000) (-8.000000 -1.999999 -1.500000) (4.525971 5.997094) (4.525971 7.258468) (4.368299 7.258468) BRICK0 -(-8.000000 -6.000000 -2.000000) (-8.000000 -1.999999 -1.500000) (-8.000000 -6.000000 -1.500000) (4.525971 5.997094) (4.368299 7.258468) (4.368299 5.997094) BRICK0 -(-8.300000 -5.699999 -2.000000) (-10.300000 -5.699999 -2.000000) (-10.300000 -5.699999 -1.500000) (3.854987 6.533178) (3.854987 7.163865) (3.697315 7.163865) BRICK0 -(-8.300000 -5.699999 -2.000000) (-10.300000 -5.699999 -1.500000) (-8.300000 -5.699999 -1.500000) (3.854987 6.533178) (3.697315 7.163865) (3.697315 6.533178) BRICK0 -(-10.000001 -9.999999 -2.000000) (-10.000000 -5.999999 -2.000000) (-10.000000 -5.999999 -1.500000) (6.483328 0.190320) (6.483328 1.451694) (6.325656 1.451694) BRICK0 -(-10.000001 -9.999999 -2.000000) (-10.000000 -5.999999 -1.500000) (-10.000001 -9.999999 -1.500000) (6.483328 0.190320) (6.325656 1.451694) (6.325656 0.190320) BRICK0 -(-12.000000 -2.299999 -2.000000) (-10.300000 -2.299999 -2.000000) (-10.300000 -2.299999 -1.500000) (3.854987 4.985767) (3.854987 5.521851) (3.697315 5.521851) BRICK0 -(-12.000000 -2.299999 -2.000000) (-10.300000 -2.299999 -1.500000) (-12.000000 -2.299999 -1.500000) (3.854987 4.985767) (3.697315 5.521851) (3.697315 4.985767) BRICK0 -(-10.000000 -5.999999 -1.500000) (-10.300000 -5.699999 -1.500000) (-10.300001 -9.999999 -1.500000) (4.998827 4.355081) (4.904248 4.449684) (4.904248 3.093707) BRICK0 -(-10.000000 -5.999999 -1.500000) (-10.300001 -9.999999 -1.500000) (-10.000001 -9.999999 -1.500000) (4.998827 4.355081) (4.904248 3.093707) (4.998827 3.093707) BRICK0 -(-8.000000 -6.000000 -1.500000) (-8.300000 -5.699999 -1.500000) (-10.300000 -5.699999 -1.500000) (5.629354 4.355081) (5.534775 4.449684) (4.904248 4.449684) BRICK0 -(-8.000000 -6.000000 -1.500000) (-10.300000 -5.699999 -1.500000) (-10.000000 -5.999999 -1.500000) (5.629354 4.355081) (4.904248 4.449684) (4.998827 4.355081) BRICK0 -(-8.000000 -1.999999 -1.500000) (-8.300000 -2.299999 -1.500000) (-8.300000 -5.699999 -1.500000) (5.629354 5.616455) (5.534775 5.521852) (5.534775 4.449684) BRICK0 -(-8.000000 -1.999999 -1.500000) (-8.300000 -5.699999 -1.500000) (-8.000000 -6.000000 -1.500000) (5.629354 5.616455) (5.534775 4.449684) (5.629354 4.355081) BRICK0 -(-10.300000 -2.299999 -1.500000) (-8.300000 -2.299999 -1.500000) (-8.000000 -1.999999 -1.500000) (4.904248 5.521852) (5.534775 5.521852) (5.629354 5.616455) BRICK0 -(-8.000000 -1.999999 -1.500000) (-12.000000 -1.999999 -1.500000) (-12.000000 -2.299999 -1.500000) (5.629354 5.616455) (4.368299 5.616455) (4.368299 5.521852) BRICK0 -(-10.300000 -2.299999 -1.500000) (-8.000000 -1.999999 -1.500000) (-12.000000 -2.299999 -1.500000) (4.904248 5.521852) (5.629354 5.616455) (4.368299 5.521852) BRICK0 +(10.000000 2.000001 -2.000000) (9.999999 6.000001 -2.000000) (9.999999 6.000001 -4.000000) (6.483328 1.451694) (6.483328 0.190320) (7.114015 0.190320) BRICK0 +(10.000000 2.000001 -2.000000) (9.999999 6.000001 -4.000000) (10.000000 2.000001 -4.000000) (6.483328 1.451694) (7.114015 0.190320) (7.114015 1.451694) BRICK0 +(14.000000 -1.999999 -2.000000) (16.000000 -1.999999 -2.000000) (16.000000 -1.699999 -2.000000) (0.820848 2.713067) (0.190320 2.713067) (0.190320 2.618464) BRICK0 +(14.000000 -1.999999 -2.000000) (16.000000 -1.699999 -2.000000) (14.000000 -1.699999 -2.000000) (0.820848 2.713067) (0.190320 2.618464) (0.820848 2.618464) BRICK0 +(8.000000 -1.999999 -4.000000) (8.000000 -6.000000 -4.000000) (12.000000 -5.999999 -2.000000) (2.726604 2.713067) (2.726604 3.974441) (1.451375 3.974441) BRICK0 +(8.000000 -1.999999 -4.000000) (12.000000 -5.999999 -2.000000) (12.000000 -1.999999 -2.000000) (2.726604 2.713067) (1.451375 3.974441) (1.451375 2.713067) BRICK0 +(8.000000 -1.999999 -4.000000) (12.000000 -1.999999 -2.000000) (8.000000 -1.999999 -2.000000) (6.798353 5.902491) (6.167666 7.163865) (6.167666 5.902491) BRICK0 +(14.000000 -1.999999 -2.000000) (14.000000 -5.999999 -2.000000) (16.000000 -5.999999 -2.000000) (0.820848 2.713067) (0.820848 3.974441) (0.190320 3.974441) BRICK0 +(14.000000 -1.999999 -2.000000) (16.000000 -5.999999 -2.000000) (16.000000 -1.999999 -2.000000) (0.820848 2.713067) (0.190320 3.974441) (0.190320 2.713067) BRICK0 +(14.000000 -1.699999 -2.000000) (16.000000 -1.699999 -2.000000) (16.000000 1.700001 -2.000000) (0.820848 2.618464) (0.190320 2.618464) (0.190320 1.546297) BRICK0 +(14.000000 -1.699999 -2.000000) (16.000000 1.700001 -2.000000) (14.000000 1.700001 -2.000000) (0.820848 2.618464) (0.190320 1.546297) (0.820848 1.546297) BRICK0 +(4.000000 -2.000000 -4.000000) (4.000000 -6.000000 -4.000000) (8.000000 -6.000000 -4.000000) (3.987659 2.713067) (3.987659 3.974441) (2.726604 3.974441) BRICK0 +(4.000000 -2.000000 -4.000000) (8.000000 -6.000000 -4.000000) (8.000000 -1.999999 -4.000000) (3.987659 2.713067) (2.726604 3.974441) (2.726604 2.713067) BRICK0 +(12.000000 -1.699999 -2.000000) (12.000000 1.700001 -2.000000) (10.300000 1.700001 -2.000000) (1.451375 2.618464) (1.451375 1.546297) (1.987324 1.546297) BRICK0 +(12.000000 -1.699999 -2.000000) (10.300000 1.700001 -2.000000) (10.300000 -1.699999 -2.000000) (1.451375 2.618464) (1.987324 1.546297) (1.987324 2.618464) BRICK0 +(8.000000 2.000001 -4.000000) (10.000000 2.000001 -4.000000) (9.999999 6.000001 -4.000000) (2.726604 1.451694) (2.096077 1.451694) (2.096077 0.190320) BRICK0 +(8.000000 2.000001 -4.000000) (9.999999 6.000001 -4.000000) (8.000000 6.000000 -4.000000) (2.726604 1.451694) (2.096077 0.190320) (2.726604 0.190320) BRICK0 +(4.000000 2.000000 -4.000000) (8.000000 2.000001 -4.000000) (8.000000 6.000000 -4.000000) (3.987659 1.451694) (2.726604 1.451694) (2.726604 0.190320) BRICK0 +(4.000000 2.000000 -4.000000) (8.000000 6.000000 -4.000000) (3.999999 6.000000 -4.000000) (3.987659 1.451694) (2.726604 0.190320) (3.987659 0.190320) BRICK0 +(8.000000 2.000001 -4.000000) (8.000000 2.000001 -2.000000) (10.000000 2.000001 -2.000000) (6.325656 2.620692) (6.325656 1.990005) (6.956343 1.990005) BRICK0 +(8.000000 2.000001 -4.000000) (10.000000 2.000001 -2.000000) (10.000000 2.000001 -4.000000) (6.325656 2.620692) (6.956343 1.990005) (6.956343 2.620692) BRICK0 +(8.000000 -1.999999 -4.000000) (8.000000 -1.999999 -2.000000) (8.000000 2.000001 -2.000000) (5.156658 7.258468) (4.525971 7.258468) (4.525971 5.997094) BRICK0 +(8.000000 -1.999999 -4.000000) (8.000000 2.000001 -2.000000) (8.000000 2.000001 -4.000000) (5.156658 7.258468) (4.525971 5.997094) (5.156658 5.997094) BRICK0 +(4.000000 -2.000000 -4.000000) (8.000000 -1.999999 -4.000000) (8.000000 2.000001 -4.000000) (3.987659 2.713067) (2.726604 2.713067) (2.726604 1.451694) BRICK0 +(4.000000 -2.000000 -4.000000) (8.000000 2.000001 -4.000000) (4.000000 2.000000 -4.000000) (3.987659 2.713067) (2.726604 1.451694) (3.987659 1.451694) BRICK0 +(10.300000 -1.699999 -2.000000) (10.300000 1.700001 -2.000000) (8.300000 1.700001 -2.000000) (1.987324 2.618464) (1.987324 1.546297) (2.617851 1.546297) BRICK0 +(10.300000 -1.699999 -2.000000) (8.300000 1.700001 -2.000000) (8.300000 -1.699999 -2.000000) (1.987324 2.618464) (2.617851 1.546297) (2.617851 2.618464) BRICK0 +(10.300000 1.700001 -2.000000) (12.000000 1.700001 -2.000000) (11.999999 6.000001 -2.000000) (1.987324 1.546297) (1.451375 1.546297) (1.451375 0.190320) BRICK0 +(10.300000 1.700001 -2.000000) (11.999999 6.000001 -2.000000) (10.299999 6.000001 -2.000000) (1.987324 1.546297) (1.451375 0.190320) (1.987324 0.190320) BRICK0 +(8.000000 -6.000000 -4.000000) (4.000000 -6.000000 -4.000000) (4.000000 -8.000000 -4.000000) (2.726604 3.974441) (3.987659 3.974441) (3.987659 4.605128) BRICK0 +(8.000000 -6.000000 -4.000000) (4.000000 -8.000000 -4.000000) (8.000000 -8.000000 -4.000000) (2.726604 3.974441) (3.987659 4.605128) (2.726604 4.605128) BRICK0 +(8.000000 -6.000000 -4.000000) (8.000000 -8.000000 -4.000000) (8.000000 -8.000000 -2.000000) (1.451694 6.562484) (0.821007 6.562484) (0.821007 5.931798) BRICK0 +(8.000000 -6.000000 -4.000000) (8.000000 -8.000000 -2.000000) (8.000000 -6.000000 -2.000000) (1.451694 6.562484) (0.821007 5.931798) (1.451694 5.931798) BRICK0 +(8.000000 -8.000000 -4.000000) (4.000000 -8.000000 -4.000000) (4.000000 -8.000000 -2.000000) (7.809680 5.902491) (7.809680 7.163865) (7.178993 7.163865) BRICK0 +(8.000000 -8.000000 -4.000000) (4.000000 -8.000000 -2.000000) (8.000000 -8.000000 -2.000000) (7.809680 5.902491) (7.178993 7.163865) (7.178992 5.902491) BRICK0 +(8.000000 -6.000000 -4.000000) (8.000000 -6.000000 -2.000000) (12.000000 -5.999999 -2.000000) (5.945016 2.713067) (5.314330 2.713067) (5.314329 1.451694) BRICK0 +(12.000000 1.700001 -2.000000) (14.000000 1.700001 -2.000000) (13.999999 6.000001 -2.000000) (1.451375 1.546297) (0.820848 1.546297) (0.820848 0.190320) BRICK0 +(12.000000 1.700001 -2.000000) (13.999999 6.000001 -2.000000) (11.999999 6.000001 -2.000000) (1.451375 1.546297) (0.820848 0.190320) (1.451375 0.190320) BRICK0 +(12.000000 -1.699999 -2.000000) (14.000000 -1.699999 -2.000000) (14.000000 1.700001 -2.000000) (1.451375 2.618464) (0.820848 2.618464) (0.820848 1.546297) BRICK0 +(12.000000 -1.699999 -2.000000) (14.000000 1.700001 -2.000000) (12.000000 1.700001 -2.000000) (1.451375 2.618464) (0.820848 1.546297) (1.451375 1.546297) BRICK0 +(12.000000 -1.999999 -2.000000) (12.000000 -5.999999 -2.000000) (14.000000 -5.999999 -2.000000) (1.451375 2.713067) (1.451375 3.974441) (0.820848 3.974441) BRICK0 +(12.000000 -1.999999 -2.000000) (14.000000 -5.999999 -2.000000) (14.000000 -1.999999 -2.000000) (1.451375 2.713067) (0.820848 3.974441) (0.820848 2.713067) BRICK0 +(12.000000 -1.999999 -2.000000) (14.000000 -1.999999 -2.000000) (14.000000 -1.699999 -2.000000) (1.451375 2.713067) (0.820848 2.713067) (0.820848 2.618464) BRICK0 +(12.000000 -1.999999 -2.000000) (14.000000 -1.699999 -2.000000) (12.000000 -1.699999 -2.000000) (1.451375 2.713067) (0.820848 2.618464) (1.451375 2.618464) BRICK0 +(8.000000 -6.000000 -2.000000) (8.000000 -8.000000 -2.000000) (8.000000 -8.000000 1.000000) (1.451694 5.931798) (0.821007 5.931798) (0.821007 4.985767) BRICK0 +(8.000000 -6.000000 -2.000000) (8.000000 -8.000000 1.000000) (8.000000 -6.000000 1.000000) (1.451694 5.931798) (0.821007 4.985767) (1.451694 4.985767) BRICK0 +(14.000000 -5.999999 -2.000000) (12.000000 -5.999999 -2.000000) (12.000000 -5.999999 1.000000) (5.314329 0.821007) (5.314329 1.451694) (4.368299 1.451694) BRICK0 +(14.000000 -5.999999 -2.000000) (12.000000 -5.999999 1.000000) (14.000000 -5.999999 1.000000) (5.314329 0.821007) (4.368299 1.451694) (4.368299 0.821007) BRICK0 +(12.000000 -5.999999 -2.000000) (8.000000 -6.000000 -2.000000) (8.000000 -6.000000 1.000000) (5.314329 1.451694) (5.314330 2.713067) (4.368299 2.713067) BRICK0 +(12.000000 -5.999999 -2.000000) (8.000000 -6.000000 1.000000) (12.000000 -5.999999 1.000000) (5.314329 1.451694) (4.368299 2.713067) (4.368299 1.451694) BRICK0 +(16.000000 -1.699999 -2.000000) (16.000000 -1.999999 -2.000000) (16.000000 -1.999999 1.000000) (6.956025 4.165875) (6.956025 4.260478) (6.009995 4.260478) BRICK0 +(16.000000 -1.699999 -2.000000) (16.000000 -1.999999 1.000000) (16.000000 -1.699999 1.000000) (6.956025 4.165875) (6.009995 4.260478) (6.009995 4.165875) BRICK0 +(16.000000 -1.999999 -2.000000) (16.000000 -5.999999 -2.000000) (16.000000 -5.999999 1.000000) (6.956025 4.260478) (6.956025 5.521852) (6.009995 5.521852) BRICK0 +(16.000000 -1.999999 -2.000000) (16.000000 -5.999999 1.000000) (16.000000 -1.999999 1.000000) (6.956025 4.260478) (6.009995 5.521852) (6.009995 4.260478) BRICK0 +(16.000000 -5.999999 -2.000000) (14.000000 -5.999999 -2.000000) (14.000000 -5.999999 1.000000) (5.314329 0.190320) (5.314329 0.821007) (4.368299 0.821007) BRICK0 +(16.000000 -5.999999 -2.000000) (14.000000 -5.999999 1.000000) (16.000000 -5.999999 1.000000) (5.314329 0.190320) (4.368299 0.821007) (4.368299 0.190320) BRICK0 +(13.999999 6.000001 -2.000000) (14.000000 1.700001 -2.000000) (14.000000 1.700001 1.000000) (2.778364 4.985768) (2.778364 6.341744) (1.832334 6.341744) BRICK0 +(13.999999 6.000001 -2.000000) (14.000000 1.700001 1.000000) (13.999999 6.000001 1.000000) (2.778364 4.985768) (1.832334 6.341744) (1.832334 4.985768) BRICK0 +(16.000000 1.700001 -2.000000) (16.000000 -1.699999 -2.000000) (16.000000 -1.699999 1.000000) (6.956025 3.093707) (6.956025 4.165875) (6.009995 4.165875) BRICK0 +(16.000000 1.700001 -2.000000) (16.000000 -1.699999 1.000000) (16.000000 1.700001 1.000000) (6.956025 3.093707) (6.009995 4.165875) (6.009994 3.093707) BRICK0 +(14.000000 1.700001 -2.000000) (16.000000 1.700001 -2.000000) (16.000000 1.700001 1.000000) (2.463020 7.668415) (1.832333 7.668415) (1.832333 6.722384) BRICK0 +(14.000000 1.700001 -2.000000) (16.000000 1.700001 1.000000) (14.000000 1.700001 1.000000) (2.463020 7.668415) (1.832333 6.722384) (2.463020 6.722384) BRICK0 +(8.000000 -8.000000 1.000000) (8.000000 -8.000000 -2.000000) (8.000001 -9.999999 -2.000000) (0.821007 4.985767) (0.821007 5.931798) (0.190320 5.931798) BRICK0 +(8.000000 -8.000000 1.000000) (8.000001 -9.999999 -2.000000) (8.000001 -9.999999 1.000000) (0.821007 4.985767) (0.190320 5.931798) (0.190320 4.985767) BRICK0 +(10.300000 -1.699999 -2.000000) (8.300000 -1.699999 -2.000000) (8.300000 -1.699999 -1.500000) (3.854987 5.521851) (3.854987 6.152538) (3.697315 6.152538) BRICK0 +(10.300000 -1.699999 -2.000000) (8.300000 -1.699999 -1.500000) (10.300000 -1.699999 -1.500000) (3.854987 5.521851) (3.697315 6.152538) (3.697315 5.521851) BRICK0 +(10.300000 1.700001 -2.000000) (10.299999 6.000001 -2.000000) (10.299999 6.000001 -1.500000) (3.316675 4.985768) (3.316675 6.341744) (3.159004 6.341744) BRICK0 +(10.300000 1.700001 -2.000000) (10.299999 6.000001 -1.500000) (10.300000 1.700001 -1.500000) (3.316675 4.985768) (3.159004 6.341744) (3.159004 4.985768) BRICK0 +(10.000000 2.000001 -2.000000) (8.000000 2.000001 -2.000000) (8.000000 2.000001 -1.500000) (6.956343 1.990005) (6.325656 1.990005) (6.325656 1.832333) BRICK0 +(10.000000 2.000001 -2.000000) (8.000000 2.000001 -1.500000) (10.000000 2.000001 -1.500000) (6.956343 1.990005) (6.325656 1.832333) (6.956343 1.832333) BRICK0 +(12.000000 -1.999999 -2.000000) (12.000000 -1.699999 -2.000000) (12.000000 -1.699999 -1.500000) (2.938263 6.880056) (2.843660 6.880056) (2.843660 6.722384) BRICK0 +(12.000000 -1.999999 -2.000000) (12.000000 -1.699999 -1.500000) (12.000000 -1.999999 -1.500000) (2.938263 6.880056) (2.843660 6.722384) (2.938263 6.722384) BRICK0 +(8.300000 -1.699999 -2.000000) (8.300000 1.700001 -2.000000) (8.300000 1.700001 -1.500000) (7.494336 3.093707) (7.494337 4.165875) (7.336665 4.165875) BRICK0 +(8.300000 -1.699999 -2.000000) (8.300000 1.700001 -1.500000) (8.300000 -1.699999 -1.500000) (7.494336 3.093707) (7.336665 4.165875) (7.336665 3.093707) BRICK0 +(8.000000 -1.999999 -2.000000) (12.000000 -1.999999 -2.000000) (12.000000 -1.999999 -1.500000) (6.167666 5.902491) (6.167666 7.163865) (6.009995 7.163865) BRICK0 +(8.000000 -1.999999 -2.000000) (12.000000 -1.999999 -1.500000) (8.000000 -1.999999 -1.500000) (6.167666 5.902491) (6.009995 7.163865) (6.009995 5.902491) BRICK0 +(8.000000 2.000001 -2.000000) (8.000000 -1.999999 -2.000000) (8.000000 -1.999999 -1.500000) (4.525971 5.997094) (4.525971 7.258468) (4.368299 7.258468) BRICK0 +(8.000000 2.000001 -2.000000) (8.000000 -1.999999 -1.500000) (8.000000 2.000001 -1.500000) (4.525971 5.997094) (4.368299 7.258468) (4.368299 5.997094) BRICK0 +(8.300000 1.700001 -2.000000) (10.300000 1.700001 -2.000000) (10.300000 1.700001 -1.500000) (3.854987 6.533178) (3.854987 7.163865) (3.697315 7.163865) BRICK0 +(8.300000 1.700001 -2.000000) (10.300000 1.700001 -1.500000) (8.300000 1.700001 -1.500000) (3.854987 6.533178) (3.697315 7.163865) (3.697315 6.533178) BRICK0 +(9.999999 6.000001 -2.000000) (10.000000 2.000001 -2.000000) (10.000000 2.000001 -1.500000) (6.483328 0.190320) (6.483328 1.451694) (6.325656 1.451694) BRICK0 +(9.999999 6.000001 -2.000000) (10.000000 2.000001 -1.500000) (9.999999 6.000001 -1.500000) (6.483328 0.190320) (6.325656 1.451694) (6.325656 0.190320) BRICK0 +(12.000000 -1.699999 -2.000000) (10.300000 -1.699999 -2.000000) (10.300000 -1.699999 -1.500000) (3.854987 4.985767) (3.854987 5.521851) (3.697315 5.521851) BRICK0 +(12.000000 -1.699999 -2.000000) (10.300000 -1.699999 -1.500000) (12.000000 -1.699999 -1.500000) (3.854987 4.985767) (3.697315 5.521851) (3.697315 4.985767) BRICK0 +(10.000000 2.000001 -1.500000) (10.300000 1.700001 -1.500000) (10.299999 6.000001 -1.500000) (4.998827 4.355081) (4.904248 4.449684) (4.904248 3.093707) BRICK0 +(10.000000 2.000001 -1.500000) (10.299999 6.000001 -1.500000) (9.999999 6.000001 -1.500000) (4.998827 4.355081) (4.904248 3.093707) (4.998827 3.093707) BRICK0 +(8.000000 2.000001 -1.500000) (8.300000 1.700001 -1.500000) (10.300000 1.700001 -1.500000) (5.629354 4.355081) (5.534775 4.449684) (4.904248 4.449684) BRICK0 +(8.000000 2.000001 -1.500000) (10.300000 1.700001 -1.500000) (10.000000 2.000001 -1.500000) (5.629354 4.355081) (4.904248 4.449684) (4.998827 4.355081) BRICK0 +(8.000000 -1.999999 -1.500000) (8.300000 -1.699999 -1.500000) (8.300000 1.700001 -1.500000) (5.629354 5.616455) (5.534775 5.521852) (5.534775 4.449684) BRICK0 +(8.000000 -1.999999 -1.500000) (8.300000 1.700001 -1.500000) (8.000000 2.000001 -1.500000) (5.629354 5.616455) (5.534775 4.449684) (5.629354 4.355081) BRICK0 +(10.300000 -1.699999 -1.500000) (8.300000 -1.699999 -1.500000) (8.000000 -1.999999 -1.500000) (4.904248 5.521852) (5.534775 5.521852) (5.629354 5.616455) BRICK0 +(8.000000 -1.999999 -1.500000) (12.000000 -1.999999 -1.500000) (12.000000 -1.699999 -1.500000) (5.629354 5.616455) (4.368299 5.616455) (4.368299 5.521852) BRICK0 +(10.300000 -1.699999 -1.500000) (8.000000 -1.999999 -1.500000) (12.000000 -1.699999 -1.500000) (4.904248 5.521852) (5.629354 5.616455) (4.368299 5.521852) BRICK0 } } { diff --git a/game/client/__build.c b/game/client/__build.c new file mode 100644 index 0000000..fbab919 --- /dev/null +++ b/game/client/__build.c @@ -0,0 +1,35 @@ +#include "god/build.h" +#include "god/c.h" +#include "god/ld.h" + + +char* client_dll = 0; +void client_build(struct build_data b) +{ + char* files[] = { + "game/client/baseplayer.cpp", + NULL, + }; + + struct project p = { + .b = &b, + .files = files, + .name = "client", + }; + + struct project o = C_compile(p, (struct C_settings){ + .generation_flags = C_GENERATION_FLAGS_PIC, + .compile_flags = C_COMPILE_FLAGS_WALL, + .include_dirs = include_dirs, + }); + char* libs[] = { + "c", + NULL, + }; + + client_dll = ld_link_project(o, (struct link_settings){ + .type = LINK_TYPE_DYNAMIC, + .libs = libs, + }); + mv("build/"GAME_NAME"/game/"GAME_NAME"/bin/libclient.so",server_dll); +} diff --git a/game/client/baseplayer.cpp b/game/client/baseplayer.cpp new file mode 100644 index 0000000..4b8076a --- /dev/null +++ b/game/client/baseplayer.cpp @@ -0,0 +1,32 @@ +#include "baseentity.h" + +class C_BasePlayer: public C_BaseEntity +{ +public: + virtual void Precache ( void ) override; + virtual void Spawn( void ) override; + virtual void Destroy( void ) override; + virtual void Think( float fDelta ) override; +}; + + +void C_BasePlayer::Precache() +{ + +} + +void C_BasePlayer::Spawn() +{ + +}; + +void C_BasePlayer::Destroy() +{ + +} +void C_BasePlayer::Think( float fDelta ) +{ + +}; + +LINK_CLIENT_ENTITY(C_BasePlayer, CBasePlayer) diff --git a/game/__build.c b/game/server/__build.c similarity index 79% rename from game/__build.c rename to game/server/__build.c index 9415510..6d326e4 100644 --- a/game/__build.c +++ b/game/server/__build.c @@ -1,20 +1,16 @@ +#include "god/build.h" #include "god/c.h" #include "god/ld.h" - +#include "libgen.h" char* server_dll = 0; void server_build(struct build_data b) { char* files[] = { - "game/game.cpp", - "game/baseplayer.cpp", + "game/server/game.cpp", + "game/server/baseplayer.cpp", NULL, }; - struct C_Macro macros[] = { - (struct C_Macro){"TIER0_IMPLEMENTATION","1"}, - NULL, - }; - struct project p = { .b = &b, @@ -26,7 +22,6 @@ void server_build(struct build_data b) .generation_flags = C_GENERATION_FLAGS_PIC, .compile_flags = C_COMPILE_FLAGS_WALL, .include_dirs = include_dirs, - .macros = macros, }); char* libs[] = { "c", diff --git a/game/baseplayer.cpp b/game/server/baseplayer.cpp similarity index 100% rename from game/baseplayer.cpp rename to game/server/baseplayer.cpp diff --git a/game/game.cpp b/game/server/game.cpp similarity index 71% rename from game/game.cpp rename to game/server/game.cpp index ef0a776..51e72ec 100644 --- a/game/game.cpp +++ b/game/server/game.cpp @@ -2,9 +2,10 @@ #include "tier0/platform.h" #include "engine.h" #include "level.h" +#include "stdio.h" -PLATFORM_INTERFACE void IGame_Load() +DLL_EXPORT void IGame_Load() { ILevel::LoadLevel("maps/test_map"); return; diff --git a/launcher/launcher.cpp b/launcher/launcher.cpp index 3ecce0d..9ff8f50 100644 --- a/launcher/launcher.cpp +++ b/launcher/launcher.cpp @@ -10,8 +10,8 @@ static char szLauncherPath[MAX_PATH]; static char szEnginePath[MAX_PATH]; static char szTier0Path[MAX_PATH]; -void *pEngineLib; -void *pTier0Lib; +void *pEngineLib = NULL; +void *pTier0Lib = NULL; typedef void (*EngineMainFn)(int argc, char** argv); EngineMainFn pEngineMain; @@ -21,6 +21,8 @@ int main( int argc, char **argv ) { snprintf(szEnginePath, MAX_PATH, "%s/libengine.so", szLauncherPath); snprintf(szTier0Path, MAX_PATH, "%s/libtier0.so", szLauncherPath); + printf("%s\n",szEnginePath); + printf("%s\n",szTier0Path); pTier0Lib = dlopen(szTier0Path, RTLD_NOW | RTLD_GLOBAL); if ( !pTier0Lib ) { @@ -32,6 +34,8 @@ int main( int argc, char **argv ) { printf("Failed to open libengine.so\n"); printf("\t%s\n",dlerror()); } + printf("\t%p\n",pTier0Lib); + printf("\t%p\n",pEngineLib); pEngineMain = (EngineMainFn)dlsym(pEngineLib, "FunnyMain"); if ( !pEngineMain ) { printf("Symbol not found: FunnyMain\n"); @@ -43,4 +47,4 @@ int main( int argc, char **argv ) { pEngineMain(argc, argv); dlclose(pEngineLib); -}; \ No newline at end of file +}; diff --git a/public/baseentity.h b/public/baseentity.h index a0f5efd..db842ee 100644 --- a/public/baseentity.h +++ b/public/baseentity.h @@ -1,7 +1,9 @@ #ifndef ENTITY_H #define ENTITY_H +#include "engine.h" #include "tier1/utlvector.h" +#include "cglm/cglm.h" class CBaseEntity; class C_BaseEntity; @@ -19,20 +21,21 @@ struct Triangle_t class CBaseEntity { public: - C_BaseEntity *pClientEntity; - + CBaseEntity(); virtual void Precache() = 0; virtual void Spawn( void ) = 0; virtual void Destroy( void ) = 0; virtual void Think( float fDelta ) = 0; + + C_BaseEntity *pClientEntity; + mat4 m_matrix; }; -extern CUtlSelfReferencingVector g_entities; typedef CBaseEntity*(*EntityRegistryFn)( void ); typedef C_BaseEntity*(*ClientEntityRegistryFn)( void ); -class CEntityRegistry +interface CEntityRegistry { public: CEntityRegistry( const char *szName, const char *szClass, EntityRegistryFn pfn ); @@ -43,7 +46,6 @@ public: ClientEntityRegistryFn m_pClientfn; }; -extern CUtlVector g_RegisteredEntities; #define DECLARE_ENTITY(name, class) \ @@ -66,9 +68,10 @@ public: virtual void Destroy( void ) = 0; /* happens every frame instead of tick */ virtual void Think( float fDelta ) = 0; +private: }; -class C_EntityRegistry +interface C_EntityRegistry { public: C_EntityRegistry( const char *pName, ClientEntityRegistryFn pfn ); @@ -82,6 +85,8 @@ C_BaseEntity *__c_entity_alloc_##server() \ C_EntityRegistry __c_entity_##server##_registry(#server, __c_entity_alloc_##server); \ +extern CUtlSelfReferencingVector g_entities; +extern CUtlVector g_RegisteredEntities; #endif diff --git a/public/console.h b/public/console.h index ff7371e..5815ac9 100644 --- a/public/console.h +++ b/public/console.h @@ -1,7 +1,7 @@ #ifndef CONSOLE_H #define CONSOLE_H -#include "tier0/platform.h" +#include "engine.h" #include "tier1/utlstring.h" class ConVar; @@ -95,4 +95,4 @@ void Msg( const char* message ); void Warning( const char* message ); void Error( const char* message ); -#endif \ No newline at end of file +#endif diff --git a/public/engine.h b/public/engine.h index d9ed617..6149938 100644 --- a/public/engine.h +++ b/public/engine.h @@ -1,6 +1,7 @@ #ifndef ENGINE_H #define ENGINE_H +/* for windows as it sucks */ #include "tier0/platform.h" class CBaseEntity; @@ -17,11 +18,9 @@ public: interface IIEngine { public: - static void PrecacheModel( const char *psz ); - static void PrecacheSound( const char *psz ); - static CBaseEntity *SpawnEntity( const char *szName ); static void DestroyEntity( CBaseEntity *pEntity ); }; + #endif diff --git a/public/filesystem.h b/public/filesystem.h index 6f1d9b6..787c021 100644 --- a/public/filesystem.h +++ b/public/filesystem.h @@ -3,6 +3,7 @@ #include "tier0/platform.h" #include "tier1/utlbuffer.h" #include "tier1/utlstring.h" +#include "engine.h" enum EFileOptions { diff --git a/public/level.h b/public/level.h index 90b35f1..f631215 100644 --- a/public/level.h +++ b/public/level.h @@ -1,7 +1,7 @@ #ifndef LEVEL_H #define LEVEL_H -#include "tier0/platform.h" +#include "engine.h" interface ILevel { diff --git a/public/physics_gen.h b/public/physics_gen.h index 2aa56b5..7fbab84 100644 --- a/public/physics_gen.h +++ b/public/physics_gen.h @@ -60,6 +60,8 @@ struct px_cast_result px_box_cast(struct funnyphysics *px_world, struct px_vec3 vel, float time); +void px_fixedbody(struct funnyphysics *px_world, Collider *collider); + void px_frame(struct funnyphysics *px_world, float delta); struct px_matrix px_getmatrix(struct funnyphysics *px_world, RigidBodyHandle *body); diff --git a/public/rendering.h b/public/rendering.h index 77aadd2..a0903ce 100644 --- a/public/rendering.h +++ b/public/rendering.h @@ -29,20 +29,6 @@ public: virtual void Unmap() = 0; }; -abstract_class IBrush -{ -public: - virtual void SetPosition( vec3 position ) = 0; - virtual void SetRotationEuler( vec3 angle ) = 0; - virtual void SetRotationQuat( vec4 quaternion) = 0; - virtual void SetMatrix( mat3 matrix ) = 0; - virtual void SetScale( vec3 scale ) = 0; - - virtual void SetVertexBuffer( IVertexBuffer *pBuffer ) = 0; - virtual void SetIndexBuffer( IIndexBuffer *pBuffer ) = 0; - virtual void Draw() = 0; -}; - enum EMaterialType { IMATERIAL_ERROR = 0, @@ -82,20 +68,64 @@ public: Material_t m; }; +interface IRenderer +{ +public: + + static IVertexBuffer *CreateVertexBuffer( uint32_t uSize ); + static IIndexBuffer *CreateIndexBuffer( uint32_t uSize ); + + static IMaterial *LoadMaterial( const char *szName ); + static void SetMaterial( IMaterial *pMaterial ); +}; + + +//---------------------------------------------------------------------------- +// Brush handler for the rendering +//---------------------------------------------------------------------------- +abstract_class IBrush +{ +public: + virtual void SetVertexBuffer( IVertexBuffer *pBuffer ) = 0; + virtual void SetIndexBuffer( IIndexBuffer *pBuffer ) = 0; + virtual void Draw() = 0; +}; + interface IBrushRenderer { public: static void Init(); static void Frame( float fDelta ); - static IVertexBuffer *CreateVertexBuffer( uint32_t uSize ); - static IIndexBuffer *CreateIndexBuffer( uint32_t uSize ); - static IBrush *CreateMesh(); static void Destroy( IBrush *pModel ); +}; - static IMaterial *LoadMaterial( const char *szName ); - static void SetMaterial( IMaterial *pMaterial ); +//---------------------------------------------------------------------------- +// Mesh handler for the rendering +//---------------------------------------------------------------------------- +abstract_class IMesh +{ +public: + virtual void SetPosition( vec3 position ) = 0; + virtual void SetRotationEuler( vec3 angle ) = 0; + virtual void SetRotationQuat( vec4 quaternion) = 0; + virtual void SetMatrix( mat4 matrix ) = 0; + virtual void SetScale( vec3 scale ) = 0; + + virtual void SetVertexBuffer( IVertexBuffer *pBuffer ) = 0; + virtual void SetIndexBuffer( IIndexBuffer *pBuffer ) = 0; + virtual void Draw() = 0; +}; + +interface IMeshRenderer +{ +public: + static void Init(); + static void Frame( float fDelta ); + + static IMesh *CreateMesh(); + static void Destroy( IBrush *pModel ); }; abstract_class ITexture diff --git a/public/tier0/platform.h b/public/tier0/platform.h index 710fbd1..32cf75a 100644 --- a/public/tier0/platform.h +++ b/public/tier0/platform.h @@ -4,6 +4,16 @@ #include "stdint.h" #include "stddef.h" +#ifdef __WIN32__ +#define DLL_EXPORT extern "C" __declspec(dllexport) +#define DLL_IMPORT extern "C" __declspec(dllimport) + +#define DLL_CLASS_EXPORT __declspec(dllexport) +#define DLL_CLASS_IMPORT __declspec(dllimport) + +#define DLL_GLOBAL_EXPORT extern __declspec(dllexport) +#define DLL_GLOBAL_IMPORT extern __declspec(dllimport) +#else #define DLL_EXPORT extern "C" __attribute__ ((visibility("default"))) #define DLL_IMPORT extern "C" @@ -12,6 +22,7 @@ #define DLL_GLOBAL_EXPORT extern __attribute ((visibility("default"))) #define DLL_GLOBAL_IMPORT extern +#endif #ifdef TIER0_STATIC diff --git a/public/tier1/utlvector.h b/public/tier1/utlvector.h index ac3c944..0fb3021 100644 --- a/public/tier1/utlvector.h +++ b/public/tier1/utlvector.h @@ -320,4 +320,4 @@ void CUtlSelfReferencingVector::RemoveTail( void ) } -#endif \ No newline at end of file +#endif diff --git a/rapier/__build.c b/rapier/__build.c index f7089f9..531dbf7 100644 --- a/rapier/__build.c +++ b/rapier/__build.c @@ -1,3 +1,4 @@ +#include "god/build.h" #include "god/c.h" #include "god/ld.h" #include "god/utils.h" @@ -9,6 +10,12 @@ void rapier_build(struct build_data b) cargo_build.wd = "rapier"; run_add_arg(&cargo_build, "build"); run_add_arg(&cargo_build, "--release"); + if (b.kernel == BUILD_KERNEL_LINUX) + { + run_add_arg(&cargo_build, "--target"); + run_add_arg(&cargo_build, "x86_64-unknown-linux-gnu"); + rapierLib = "rapier/target/x86_64-unknown-linux-gnu/release/librapier_rtt.a"; + } run_run(&cargo_build); struct run_project cbindgen = run_new("cbindgen"); cbindgen.wd = "rapier"; @@ -17,7 +24,6 @@ void rapier_build(struct build_data b) run_add_arg(&cbindgen, "--crate"); run_add_arg(&cbindgen, "rapier_rtt"); run_add_arg(&cbindgen, "--output"); - run_add_arg(&cbindgen, "../public/physics_gen.h"); + run_add_arg(&cbindgen, "../public/physics_gen.h"); run_run(&cbindgen); - rapierLib = "rapier/target/release/librapier_rtt.a"; } diff --git a/rapier/px.rs b/rapier/px.rs index 390436e..2105215 100644 --- a/rapier/px.rs +++ b/rapier/px.rs @@ -49,9 +49,9 @@ pub unsafe extern "C" fn px_frame(px_world: *mut funnyphysics, delta:f32) { let gravity = vector![0.0, 0.0, -9.81]; let mut integration_parameters = IntegrationParameters::default(); integration_parameters.dt=delta; - integration_parameters.min_island_size=1; - integration_parameters.num_solver_iterations=NonZeroUsize::new(4).unwrap(); - integration_parameters.num_internal_stabilization_iterations=2; + integration_parameters.min_island_size=256; + integration_parameters.num_solver_iterations=NonZeroUsize::new(8).unwrap(); + integration_parameters.num_internal_stabilization_iterations=4; let physics_hooks = (); let event_handler = (); if let Some(px) = px_world.as_mut() { @@ -107,6 +107,13 @@ pub unsafe extern "C" fn px_staticbody(px_world: *mut funnyphysics, collider: *m Box::into_raw(Box::new(body)) } +#[unsafe(no_mangle)] +pub unsafe extern "C" fn px_fixedbody(px_world: *mut funnyphysics, collider: *mut Collider) { + let c = &mut *collider; + let px = px_world.as_mut().unwrap(); + px.collider_set.insert(c.clone()); +} + #[repr(C)] pub struct px_matrix { diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/tier0/__build.c b/tier0/__build.c index a52e972..64c8893 100644 --- a/tier0/__build.c +++ b/tier0/__build.c @@ -1,7 +1,8 @@ +#include "god/build.h" #include "god/c.h" #include "god/ld.h" -char* tier0_dll = 0; +char* tier0_lib = 0; void tier0_build(struct build_data b) { char* files[] = { @@ -33,9 +34,9 @@ void tier0_build(struct build_data b) NULL, }; - tier0_dll = ld_link_project(o, (struct link_settings){ + tier0_lib = ld_link_project(o, (struct link_settings){ .type = LINK_TYPE_DYNAMIC, .libs = libs, }); - mv("build/"GAME_NAME"/game/bin/libtier0.so",tier0_dll); -} \ No newline at end of file + mv("build/"GAME_NAME"/game/bin/libtier0.so",tier0_lib); +} diff --git a/tier0/platform.cpp b/tier0/platform.cpp index d9caf61..b83899f 100644 --- a/tier0/platform.cpp +++ b/tier0/platform.cpp @@ -3,11 +3,16 @@ #include "stdarg.h" #include "unistd.h" #include "sys/stat.h" -#include "execinfo.h" #include "dirent.h" -#include "dlfcn.h" #include "time.h" - +#ifdef __linux__ +#include "dlfcn.h" +#include "execinfo.h" +#endif +#ifdef __WIN32__ +#include "windows.h" +#include "dbghelp.h" +#endif PLATFORM_INTERFACE void Plat_FatalErrorFunc(const char* szFormat, ...) { va_list list; @@ -76,6 +81,7 @@ PLATFORM_INTERFACE char *Plat_GetExtension( const char *szPath ) PLATFORM_INTERFACE void Plat_Backtrace( void ) { +#ifdef __linux__ void *buffer[64]; int nptrs = backtrace(buffer, 64); char **symbols = backtrace_symbols(buffer, nptrs); @@ -90,22 +96,64 @@ PLATFORM_INTERFACE void Plat_Backtrace( void ) } free(symbols); +#endif +#ifdef __WIN32__ + void* buffer[64]; + USHORT nptrs = CaptureStackBackTrace(0, 64, buffer, NULL); + + HANDLE process = GetCurrentProcess(); + SymInitialize(process, NULL, TRUE); + + SYMBOL_INFO* symbol = (SYMBOL_INFO*)calloc(sizeof(SYMBOL_INFO) + 256, 1); + symbol->MaxNameLen = 255; + symbol->SizeOfStruct = sizeof(SYMBOL_INFO); + + if (!symbol) { + V_printf("Backtrace failed\n"); + return; + } + + for (USHORT i = 0; i < nptrs; i++) { + if (SymFromAddr(process, (DWORD64)(buffer[i]), 0, symbol)) { + V_printf(" [%d] %s - 0x%0llX\n", i, symbol->Name, symbol->Address); + } else { + V_printf(" [%d] ??? - 0x%0llX\n", i, (DWORD64)(buffer[i])); + } + } + + free(symbol); +#endif }; PLATFORM_INTERFACE void *Plat_LoadLibrary( const char *psz ) { +#ifdef __linux__ void *lib = dlopen(psz, RTLD_GLOBAL | RTLD_NOW); if (!lib) V_printf("Failed to open %s\n\t%s\n", psz, dlerror()); return lib; +#endif +#ifdef __WIN32__ + return LoadLibraryA(psz); +#endif } PLATFORM_INTERFACE void *Plat_GetProc( void *lib, const char *psz ) { +#ifdef __linux__ return dlsym(lib, psz); +#endif +#ifdef __WIN32__ + return (void*)GetProcAddress((HMODULE)lib, psz); +#endif } PLATFORM_INTERFACE void Plat_UnloadLibrary( void *lib ) { +#ifdef __linux__ dlclose(lib); +#endif +#ifdef __WIN32__ + FreeLibrary((HMODULE)lib); +#endif }; PLATFORM_INTERFACE double Plat_GetTime( void )