From 03c560c2b703bff95158d3bb3fedcefd644f4491 Mon Sep 17 00:00:00 2001 From: kotofyt Date: Sat, 28 Feb 2026 21:07:44 +0200 Subject: [PATCH] networking i guess --- .gitmodules | 3 + build.cpp | 3 + buildcfg.cpp | 3 + engine/build.cpp | 13 +- engine/cl_dll.cpp | 1 + engine/engine.cpp | 68 +++++--- engine/inetwork.cpp | 5 + engine/localnetwork.cpp | 218 ++++++++++++++++++++++++ engine/socketnetwork.cpp | 0 engine/steamnetwork.cpp | 82 +++++++++ engine/sv_dll.cpp | 2 +- external/SPIRV-Tools | 1 + funnyassets/models/cube.fmdl | 2 +- funnyassets/shaders/macros.hlsl | 6 + funnyassets/shaders/mesh_trace.shader | 29 ++++ funnyassets/shaders/ray_trace.hlsl | 10 +- game/client/assetmgr.cpp | 48 +++++- game/client/baseentity.cpp | 29 +++- game/client/baseentity.h | 9 +- game/client/basemodelentity.cpp | 34 ++++ game/client/basemodelentity.h | 27 +++ game/client/build.cpp | 1 + game/client/engine.h | 12 -- game/client/entitysystem.cpp | 25 +++ game/client/entitysystem.h | 4 + game/client/game.cpp | 81 ++++++++- game/client/mapmgr.cpp | 0 game/client/mapmgr.h | 0 game/client/milmoba/baseprojectile.cpp | 0 game/client/milmoba/baseprojectile.h | 0 game/client/milmoba/baseweapon.cpp | 0 game/client/milmoba/baseweapon.h | 0 game/client/milmoba/player.cpp | 16 +- game/client/milmoba/player.h | 20 ++- game/client/worldrender.cpp | 14 +- game/client/worldrender.h | 10 ++ game/server/baseentity.cpp | 24 ++- game/server/baseentity.h | 26 ++- game/server/basemodelentity.cpp | 1 + game/server/basemodelentity.h | 12 ++ game/server/build.cpp | 3 + game/server/entitysystem.cpp | 77 ++++++++- game/server/entitysystem.h | 1 + game/server/game.cpp | 41 ++++- game/server/milmoba/player.cpp | 26 +++ game/server/milmoba/player.h | 19 +++ game/server/pointentity.cpp | 1 + game/server/pointentity.h | 10 ++ game/shared/datamap.h | 8 +- game/shared/engine.h | 26 +++ game/shared/gameclass.h | 9 + game/shared/netmap.h | 118 +++++++++++++ game/shared/netprotocol.h | 76 +++++++++ materialsystem/vulkan/material.cpp | 4 + materialsystem/vulkan/rendercontext.cpp | 1 + materialsystem/vulkan/shader.cpp | 10 +- materialsystem/vulkan/utils.cpp | 4 + materialsystem/vulkan/vulkan_state.h | 4 +- public/cl_dll.h | 1 + public/enginebridge.h | 10 ++ public/inetworkclient.h | 10 ++ public/inetworkserver.h | 24 +++ public/materialsystem/imaterialsystem.h | 55 +++++- public/materialsystem/shaderinternals.h | 6 + public/networkbase.h | 30 ++++ public/sv_dll.h | 1 + public/trig.h | 11 ++ shadercompiler/slang/vulkan_spirv.cpp | 44 ++++- 68 files changed, 1348 insertions(+), 121 deletions(-) create mode 100644 engine/inetwork.cpp create mode 100644 engine/localnetwork.cpp create mode 100644 engine/socketnetwork.cpp create mode 100644 engine/steamnetwork.cpp create mode 160000 external/SPIRV-Tools create mode 100644 game/client/basemodelentity.cpp create mode 100644 game/client/basemodelentity.h delete mode 100644 game/client/engine.h create mode 100644 game/client/mapmgr.cpp create mode 100644 game/client/mapmgr.h create mode 100644 game/client/milmoba/baseprojectile.cpp create mode 100644 game/client/milmoba/baseprojectile.h create mode 100644 game/client/milmoba/baseweapon.cpp create mode 100644 game/client/milmoba/baseweapon.h create mode 100644 game/server/basemodelentity.cpp create mode 100644 game/server/basemodelentity.h create mode 100644 game/server/milmoba/player.cpp create mode 100644 game/server/milmoba/player.h create mode 100644 game/server/pointentity.cpp create mode 100644 game/server/pointentity.h create mode 100644 game/shared/engine.h create mode 100644 game/shared/gameclass.h create mode 100644 game/shared/netmap.h create mode 100644 game/shared/netprotocol.h create mode 100644 public/networkbase.h diff --git a/.gitmodules b/.gitmodules index d429b95..403cafd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -31,3 +31,6 @@ [submodule "external/funnystdlib"] path = external/funnystdlib url = https://github.com/KoT3isGood/funnystdlib.git +[submodule "external/SPIRV-Tools"] + path = external/SPIRV-Tools + url = https://github.com/KoT3isGood/SPIRV-Tools.git diff --git a/build.cpp b/build.cpp index c4eb884..3f58f77 100755 --- a/build.cpp +++ b/build.cpp @@ -30,6 +30,9 @@ DECLARE_BUILD_STAGE(install_game) filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(Server, "server")); filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(Client, "client")); } + if ( GET_PROJECT_VALUE(config, "steam") == "true" ) { + filesystem2->CopyFile(szOutputDir, EXTERNAL"steamworks/redistributable_bin/linux64/libsteam_api.so"); + } filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(launcher, "launcher")); filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/models"); filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/meshes"); diff --git a/buildcfg.cpp b/buildcfg.cpp index eca5a59..ed87c78 100644 --- a/buildcfg.cpp +++ b/buildcfg.cpp @@ -1,14 +1,17 @@ #include "helper.h" +#include "tier0/commandline.h" DECLARE_BUILD_STAGE(config) { if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_IOS) { ADD_OUTPUT_VALUE("static", "true"); + ADD_OUTPUT_VALUE("steam", "false"); } else { ADD_OUTPUT_VALUE("static", "false"); + ADD_OUTPUT_VALUE("steam", "true"); } ADD_OUTPUT_VALUE("static", "true"); return 0; diff --git a/engine/build.cpp b/engine/build.cpp index 489b92f..95be044 100644 --- a/engine/build.cpp +++ b/engine/build.cpp @@ -3,6 +3,7 @@ #include "ld.h" #include "tier1/utlstring.h" +#define EXTERNAL "../external/" #define FUNNYSTDLIB "../external/funnystdlib/" ADD_DEPENDENCY_BUILD_FILE(cfg, "../buildcfg.cpp"); ADD_DEPENDENCY_BUILD_FILE(MaterialSystem, "../materialsystem/build.cpp") @@ -19,6 +20,9 @@ DECLARE_BUILD_STAGE(engine) compileProject.files = { "engine.cpp", "cvar.cpp", + "localnetwork.cpp", + "socketnetwork.cpp", + "steamnetwork.cpp", "sv_dll.cpp", "cl_dll.cpp", @@ -29,7 +33,10 @@ DECLARE_BUILD_STAGE(engine) "../external/SDL/include", "../external/cglm/include", FUNNYSTDLIB"public", + EXTERNAL"steamworks/public", }; + if ( GET_PROJECT_VALUE(config, "steam") == "true" ) + compileProject.macros.AppendTail({"STEAM", "TRUE"}); compileProject.bFPIC = true; ldProject = ccompiler->Compile(&compileProject); @@ -39,6 +46,10 @@ DECLARE_BUILD_STAGE(engine) } else { + if ( GET_PROJECT_VALUE(config, "steam") == "true" ) { + ldProject.libraryDirectories.AppendTail(EXTERNAL"steamworks/redistributable_bin/linux64"); + ldProject.libraries.AppendTail("steam_api"); + } ldProject.linkType = ELINK_DYNAMIC_LIBRARY; ldProject.libraryObjects = { GET_PROJECT_LIBRARY(tier0, "tier0"), @@ -49,7 +60,7 @@ DECLARE_BUILD_STAGE(engine) if (ldProject.m_target.kernel & TARGET_KERNEL_WINDOWS_DEVICES) { - ldProject.libraryDirectories = {"../external/windows"}; + ldProject.libraryDirectories.AppendTail(EXTERNAL"windows"); ldProject.libraries.AppendTail("winpthread-1"); ldProject.libraries.AppendTail("winmm"); ldProject.libraries.AppendTail("ole32"); diff --git a/engine/cl_dll.cpp b/engine/cl_dll.cpp index bc7eeb0..99084ff 100644 --- a/engine/cl_dll.cpp +++ b/engine/cl_dll.cpp @@ -21,6 +21,7 @@ void CClientGameDLL::Init() pEngineBridge->ConnectInterface(RENDER_CONTEXT_INTERFACE_VERSION, m_pRenderContext); pEngineBridge->ConnectInterface("MainWindow", m_pGameWindow); pEngineBridge->ConnectInterface(FILESYSTEM_INTERFACE_VERSION, filesystem); + pEngineBridge->ConnectInterface("EngineConstants", m_pEngineConsts); pEngineBridge->Init(); m_pBridge = pEngineBridge; } diff --git a/engine/engine.cpp b/engine/engine.cpp index 453928c..09e00c6 100644 --- a/engine/engine.cpp +++ b/engine/engine.cpp @@ -7,6 +7,12 @@ #include "tier0/mem.h" #include "sv_dll.h" #include "cl_dll.h" +#include "inetworkserver.h" +#include "inetworkclient.h" + +#ifdef STEAM +#include "steam/steam_api.h" +#endif IRenderContext *g_pRenderContext; IFileSystem *filesystem; @@ -19,38 +25,52 @@ extern "C" void FunnyMain( int argc, char **argv ) { CommandLine()->CreateCommandLine(argc, argv); + EngineConsts_t stConstants = {}; +#ifdef STEAM + stConstants.m_bIsSteam = true; + if (!SteamAPI_Init()) + Plat_FatalErrorFunc("SteamAPI_Init failed lol\n"); + stConstants.LaunchServer = LaunchLocalBridge; + stConstants.ConnectSteamServer = ConnectBySteamID; +#endif + stConstants.m_bIsDedicated = CommandLine()->CheckParam("-dedicated"); + stConstants.LaunchLocalBridge = LaunchLocalBridge; + stConstants.ConnectLocalBridge = ConnectByLocalBridge; CreateInterfaceFn pFilesystemFactory = Sys_GetFactory("filesystem_std"); CreateInterfaceFn pMaterialSystemFactory = Sys_GetFactory("MaterialSystem"); CreateInterfaceFn pRenderSystemFactory = Sys_GetFactory("RenderSystemVulkan"); + IGameWindow *pWindow; filesystem = (IFileSystem*)pFilesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL); filesystem->Init(); - g_pWindowManager = (IGameWindowManager*)pRenderSystemFactory(GAME_WINDOW_MANAGER_INTERFACE_VERSION, NULL); - V_printf("%s\n", GAME_WINDOW_MANAGER_INTERFACE_VERSION); - g_pWindowManager->Init(); + if (!stConstants.m_bIsDedicated) + { + g_pWindowManager = (IGameWindowManager*)pRenderSystemFactory(GAME_WINDOW_MANAGER_INTERFACE_VERSION, NULL); + g_pWindowManager->Init(); - IGameWindow *pWindow = g_pWindowManager->CreateWindow(); - pWindow->Init(); - - - g_pRenderContext = (IRenderContext*)pRenderSystemFactory(RENDER_CONTEXT_INTERFACE_VERSION, NULL); - g_pRenderContext->SetMainWindowManager(g_pWindowManager); - g_pRenderContext->Init(); - - g_pRenderContext->RegisterGameWindow(pWindow); + pWindow = g_pWindowManager->CreateWindow(); + pWindow->Init(); + g_pRenderContext = (IRenderContext*)pRenderSystemFactory(RENDER_CONTEXT_INTERFACE_VERSION, NULL); + g_pRenderContext->SetMainWindowManager(g_pWindowManager); + g_pRenderContext->Init(); + g_pRenderContext->RegisterGameWindow(pWindow); + } g_pServerGame = new CServerGameDLL; - g_pServerGame->m_pGameWindow = pWindow; - g_pServerGame->m_pRenderContext = g_pRenderContext; + g_pServerGame->m_pEngineConsts = &stConstants; g_pServerGame->Init(); - - g_pClientGame = new CClientGameDLL; - g_pClientGame->m_pGameWindow = pWindow; - g_pClientGame->m_pRenderContext = g_pRenderContext; - g_pClientGame->Init(); + + if (!stConstants.m_bIsDedicated) + { + g_pClientGame = new CClientGameDLL; + g_pClientGame->m_pGameWindow = pWindow; + g_pClientGame->m_pRenderContext = g_pRenderContext; + g_pClientGame->m_pEngineConsts = &stConstants; + g_pClientGame->Init(); + } double fPrevious = Plat_GetTime(); @@ -58,11 +78,15 @@ extern "C" void FunnyMain( int argc, char **argv ) double fCurrent = Plat_GetTime(); double fDelta = fCurrent-fPrevious; fPrevious = fCurrent; - g_pWindowManager->Frame(fDelta); g_pServerGame->m_pBridge->Frame(fDelta); - g_pClientGame->m_pBridge->Frame(fDelta); - g_pRenderContext->Frame(fDelta); + if (!stConstants.m_bIsDedicated) + { + g_pWindowManager->Frame(fDelta); + g_pClientGame->m_pBridge->Frame(fDelta); + g_pRenderContext->Frame(fDelta); + } + }; }; diff --git a/engine/inetwork.cpp b/engine/inetwork.cpp new file mode 100644 index 0000000..cc6af49 --- /dev/null +++ b/engine/inetwork.cpp @@ -0,0 +1,5 @@ + +class CUnsecureNetworkManager +{ + +}; diff --git a/engine/localnetwork.cpp b/engine/localnetwork.cpp new file mode 100644 index 0000000..11ba4ed --- /dev/null +++ b/engine/localnetwork.cpp @@ -0,0 +1,218 @@ +#include "inetworkserver.h" +#include "tier1/utlmutex.h" +#include "tier1/utlvector.h" + +class CLocalNetworkServer; +static CLocalNetworkServer *s_pLocalServers[128]; + +class CLocalNetworkServer: public INetworkBase +{ +public: + CLocalNetworkServer( uint16_t uPort ); + virtual ~CLocalNetworkServer() override; + + virtual void NetThink() override; + + virtual uint32_t BHasUpdates() override; + virtual NetPacket_t RecievePacket() override; + virtual NetPacket_t PeekPacket() override; + + virtual void SendPacket( NetPacket_t stPacket ) override; + + virtual uint64_t GetSteamID() override; + virtual const char *GetIP() override; + virtual uint16_t GetPort() override; + + CUtlLock m_lock; + CUtlVector m_packets; + CUtlVector m_clientPackets; + CUtlVector m_freedPackets; + const uint16_t m_uPort; +}; + +CLocalNetworkServer::CLocalNetworkServer( uint16_t uPort ) : m_uPort(uPort) +{ + s_pLocalServers[uPort] = this; +} + +CLocalNetworkServer::~CLocalNetworkServer() +{ + s_pLocalServers[m_uPort] = NULL; + +} + + +void CLocalNetworkServer::NetThink() +{ + m_lock.Lock(); + for ( auto p: m_freedPackets) + { + V_free(p); + } + m_freedPackets = {}; + m_lock.Unlock(); +} + + +uint32_t CLocalNetworkServer::BHasUpdates() +{ + return m_clientPackets.GetSize(); +} + +NetPacket_t CLocalNetworkServer::RecievePacket() +{ + m_lock.Lock(); + if (!BHasUpdates()) + return {}; + NetPacket_t p = m_clientPackets[0]; + m_clientPackets.RemoveHead(1); + m_freedPackets.AppendTail(p.pData); + m_lock.Unlock(); + return p; +} + +NetPacket_t CLocalNetworkServer::PeekPacket() +{ + m_lock.Lock(); + if (!BHasUpdates()) + return {}; + NetPacket_t p = m_clientPackets[0]; + m_lock.Unlock(); + return p; +} + + +void CLocalNetworkServer::SendPacket( NetPacket_t stPacket ) +{ + NetPacket_t stSavedPacked; + stSavedPacked.uSize = stPacket.uSize; + stSavedPacked.pData = V_malloc(stPacket.uSize); + V_memcpy(stSavedPacked.pData, stPacket.pData, stPacket.uSize); + + m_lock.Lock(); + m_packets.AppendTail(stSavedPacked); + m_lock.Unlock(); +} + + +uint64_t CLocalNetworkServer::GetSteamID() +{ + return 0; +} + +const char *CLocalNetworkServer::GetIP() +{ + return NULL; +} + +uint16_t CLocalNetworkServer::GetPort() +{ + return m_uPort; +} + +class CLocalNetworkClient: public INetworkBase +{ +public: + CLocalNetworkClient( uint16_t uPort ); + virtual ~CLocalNetworkClient() override; + + virtual void NetThink() override; + + virtual uint32_t BHasUpdates() override; + virtual NetPacket_t RecievePacket() override; + virtual NetPacket_t PeekPacket() override; + + virtual void SendPacket( NetPacket_t stPacket ) override; + + virtual uint64_t GetSteamID() override; + virtual const char *GetIP() override; + virtual uint16_t GetPort() override; + + CLocalNetworkServer *m_pServer; +}; + +CLocalNetworkClient::CLocalNetworkClient( uint16_t uPort ) +{ + m_pServer = s_pLocalServers[uPort]; +} + +CLocalNetworkClient::~CLocalNetworkClient() +{ + +} + + +void CLocalNetworkClient::NetThink() +{ +} + + +uint32_t CLocalNetworkClient::BHasUpdates() +{ + return m_pServer->m_packets.GetSize(); +} + +NetPacket_t CLocalNetworkClient::RecievePacket() +{ + m_pServer->m_lock.Lock(); + if (!BHasUpdates()) + return {}; + NetPacket_t p = m_pServer->m_packets[0]; + m_pServer->m_packets.RemoveHead(1); + m_pServer->m_freedPackets.AppendTail(p.pData); + m_pServer->m_lock.Unlock(); + return p; +} + +NetPacket_t CLocalNetworkClient::PeekPacket() +{ + m_pServer->m_lock.Lock(); + if (!BHasUpdates()) + return {}; + NetPacket_t p = m_pServer->m_packets[0]; + m_pServer->m_lock.Unlock(); + return p; +} + + +void CLocalNetworkClient::SendPacket( NetPacket_t stPacket ) +{ + NetPacket_t stSavedPacked; + stSavedPacked.uSize = stPacket.uSize; + stSavedPacked.pData = V_malloc(stPacket.uSize); + V_memcpy(stSavedPacked.pData, stPacket.pData, stPacket.uSize); + + m_pServer->m_lock.Lock(); + m_pServer->m_clientPackets.AppendTail(stSavedPacked); + m_pServer->m_lock.Unlock(); +} + + +uint64_t CLocalNetworkClient::GetSteamID() +{ + return 0; +} + +const char *CLocalNetworkClient::GetIP() +{ + return NULL; +} + +uint16_t CLocalNetworkClient::GetPort() +{ + return m_pServer->m_uPort; +} + +INetworkBase *LaunchLocalBridge( uint16_t uPort ) +{ + INetworkBase *pBase = new CLocalNetworkServer(uPort); + return pBase; +} +INetworkBase *ConnectByLocalBridge( uint16_t uPort ) +{ + if (s_pLocalServers[uPort] == 0) + { + return NULL; + } + return new CLocalNetworkClient(uPort); +} diff --git a/engine/socketnetwork.cpp b/engine/socketnetwork.cpp new file mode 100644 index 0000000..e69de29 diff --git a/engine/steamnetwork.cpp b/engine/steamnetwork.cpp new file mode 100644 index 0000000..93df8f0 --- /dev/null +++ b/engine/steamnetwork.cpp @@ -0,0 +1,82 @@ +#include "inetworkserver.h" +#include "inetworkclient.h" +#include "steam/isteamnetworkingsockets.h" + +class CSteamNetworkServer: public INetworkBase +{ +public: + CSteamNetworkServer( uint16_t uPort ); + virtual ~CSteamNetworkServer() override; + + virtual void NetThink() override; + + virtual uint32_t BHasUpdates() override; + virtual NetPacket_t RecievePacket() override; + + virtual void SendPacket( NetPacket_t stPacket ) override; + + virtual uint64_t GetSteamID() override; + virtual const char *GetIP() override; + virtual uint16_t GetPort() override; + HSteamListenSocket m_hSocket; +}; + +CSteamNetworkServer::CSteamNetworkServer( uint16_t uPort ) +{ + m_hSocket = SteamNetworkingSockets()->CreateListenSocketP2P(uPort, 0, NULL); + +} + +CSteamNetworkServer::~CSteamNetworkServer() +{ + +} + + +void CSteamNetworkServer::NetThink() +{ +} + + +uint32_t CSteamNetworkServer::BHasUpdates() +{ + +} + +NetPacket_t CSteamNetworkServer::RecievePacket() +{ + +} + + +void CSteamNetworkServer::SendPacket( NetPacket_t stPacket ) +{ +} + + +uint64_t CSteamNetworkServer::GetSteamID() +{ + return 0; +} + +const char *CSteamNetworkServer::GetIP() +{ + return NULL; +} + +uint16_t CSteamNetworkServer::GetPort() +{ + return 0; +} + + +INetworkBase *LaunchServerAtSteamRelay( uint16_t uPort ) +{ + INetworkBase *pBase = new CSteamNetworkServer(uPort); + return pBase; +} + +INetworkBase *ConnectBySteamID( uint64_t uID, uint16_t uPort ) +{ + return NULL; +} diff --git a/engine/sv_dll.cpp b/engine/sv_dll.cpp index ebcf400..dce2767 100644 --- a/engine/sv_dll.cpp +++ b/engine/sv_dll.cpp @@ -16,7 +16,7 @@ void CServerGameDLL::Init() CreateInterfaceFn pfnServerFactory = Sys_GetFactory(pLib); IEngineBridge *pEngineBridge = (IEngineBridge*)pfnServerFactory(ENGINE_BRIDGE_INTERFACE_VERSION, NULL); - + pEngineBridge->ConnectInterface("EngineConstants", m_pEngineConsts); pEngineBridge->Init(); m_pBridge = pEngineBridge; } diff --git a/external/SPIRV-Tools b/external/SPIRV-Tools new file mode 160000 index 0000000..0436c4b --- /dev/null +++ b/external/SPIRV-Tools @@ -0,0 +1 @@ +Subproject commit 0436c4b0556fbfcff46610e888974965fd36be2a diff --git a/funnyassets/models/cube.fmdl b/funnyassets/models/cube.fmdl index 254b5fb..3f488c1 100644 --- a/funnyassets/models/cube.fmdl +++ b/funnyassets/models/cube.fmdl @@ -1,4 +1,4 @@ { "mesh": "game/core/meshes/cube.fmesh_c", - "material": "cube.fmat" + "material": "game/core/materials/cube.fmat" } diff --git a/funnyassets/shaders/macros.hlsl b/funnyassets/shaders/macros.hlsl index 4172254..4f4e33b 100644 --- a/funnyassets/shaders/macros.hlsl +++ b/funnyassets/shaders/macros.hlsl @@ -15,6 +15,12 @@ #define PS namespace PixelShader_DO_NOT_USE #endif +#ifdef RAY_SHADER +#define RAY using namespace RAYShader; namespace RAYShader +#else +#define RAY namespace RAYShader_DO_NOT_USE +#endif + #ifdef BRDF_SHADER #define BRDF using namespace BRDFShader; namespace BRDFShader #else diff --git a/funnyassets/shaders/mesh_trace.shader b/funnyassets/shaders/mesh_trace.shader index 0e1ae64..2550396 100644 --- a/funnyassets/shaders/mesh_trace.shader +++ b/funnyassets/shaders/mesh_trace.shader @@ -1 +1,30 @@ #include "macros.hlsl" +#include "ray_trace.hlsl" + +struct MeshPayload +{ + float3 m_vColor; +} + +RAY +{ + funnyAccelerationStructure g_asGlobal; + Texture2D g_tWorldSpaceCoords; + RWTexture2D g_tDirectImage; + RWTexture2D g_tIndirectImage; + + + void rayMain() + { + /* + uint2 pixel = DispatchRaysIndex().xy; + MeshPayload p; + RayDesc ray; + ray.Origin = g_tWorldSpaceCoords[pixel]; + ray.Direction = float3(1,0,0); + ray.TMin = 0.001; + ray.TMax = 10000; + funnyHitObject hit = funnyHitObject::TraceRay(g_asGlobal, RAY_FLAG_NONE, 0xFF, 0, 1, 0, ray, p); + */ + } +} diff --git a/funnyassets/shaders/ray_trace.hlsl b/funnyassets/shaders/ray_trace.hlsl index c79bd5f..c78a725 100644 --- a/funnyassets/shaders/ray_trace.hlsl +++ b/funnyassets/shaders/ray_trace.hlsl @@ -2,15 +2,9 @@ #define RAY_TRACE_H #ifdef SOFTWARE_RAY_TRACING -struct funnyAccelerationStructure -{ - -} +typedef Buffer funnyAccelerationStructure #else -struct funnyAccelerationStructure -{ - RaytracingAccelerationStructure accel; -} +typedef RaytracingAccelerationStructure funnyAccelerationStructure #endif struct funnyHitObject diff --git a/game/client/assetmgr.cpp b/game/client/assetmgr.cpp index a0aa05c..71894fc 100644 --- a/game/client/assetmgr.cpp +++ b/game/client/assetmgr.cpp @@ -25,6 +25,7 @@ public: FunnyModel_t *LoadModelFromParams( const char *szMesh, const char *szMaterial ); uint32_t LoadShader( const char *szName ); + FunnyShader_t *GetShaderByIndex( uint32_t uIndex ); void UnrefShader( uint32_t uIndex ); FunnyModel_t *m_models[MAX_MODEL_COUNT] = {}; @@ -46,6 +47,10 @@ FunnyMaterial_t *CAssetManager::GetMaterialByIndex( uint32_t uIndex ) { return m_materials[uIndex]; } +FunnyShader_t *CAssetManager::GetShaderByIndex( uint32_t uIndex ) +{ + return m_shaders[uIndex]; +} uint32_t CAssetManager::LoadModel( const char *szName ) @@ -116,7 +121,7 @@ uint32_t CAssetManager::LoadMaterial( const char *szName ) { uint32_t u = 0; uint32_t uFoundIndex = 1; - for ( auto &m: m_models) + for ( auto &m: m_materials) { if (m == NULL) { @@ -125,17 +130,51 @@ uint32_t CAssetManager::LoadMaterial( const char *szName ) } if (m->m_szName == szName) { - m_modelUsages[uFoundIndex]++; + m_materialsUsages[uFoundIndex]++; return u; } u++; } - for ( auto &m: m_models) + for ( auto &m: m_materials) { if (m == NULL) break; uFoundIndex++; } + IFileHandle *pHandle = filesystem->Open(szName, FILEMODE_READ); + CUtlString szProperties = filesystem->ReadString(pHandle); + IJSONValue *pRoot = JSONManager()->ReadString(szProperties); + IJSONObject *pMainObject; + switch (pRoot->GetType()) + { + case JSON_PARAMETER_OBJECT: + { + pMainObject = pRoot->GetObject(); + if (!pMainObject) + { + V_printf("Failed to load properties\n"); + return 0; + + } + IJSONValue *pShaderValue = pMainObject->GetValue("shader"); + CUtlString szShader = pShaderValue->GetStringValue(); + CBaseMaterial *pMaterial = CreateMaterial(szShader); + + uint32_t uShaderId = LoadShader(pMaterial->GetShaderPath()); + FunnyShader_t *pShader = GetShaderByIndex(uShaderId); + m_materials[uFoundIndex] = new FunnyMaterial_t; + m_materials[uFoundIndex]->m_pShaders = pShader->m_pShader; + m_materials[uFoundIndex]->m_pMaterial = g_pRenderContext->CreateMaterial(pShader->m_pShader); + m_materials[uFoundIndex]->m_pLayout = pMaterial; + m_materialsUsages[uFoundIndex]++; + + return uFoundIndex; + } + break; + default: + return 0; + } + return uFoundIndex; } void CAssetManager::UnrefMaterial( uint32_t uIndex ) @@ -163,6 +202,8 @@ FunnyModel_t *CAssetManager::LoadModelFromParams( const char *szMesh, const char pModel->m_szName = szMesh; pModel->m_pMesh = g_pWorldRenderer->CreateMesh(szMesh); pModel->m_pMesh->SetVertices(pVertexBuffer); + uint32_t uMaterial = LoadMaterial(szMaterial); + pModel->m_pFunnyMaterial = GetMaterialByIndex(uMaterial); return pModel; } @@ -200,6 +241,7 @@ uint32_t CAssetManager::LoadShader( const char *szName ) FunnyShader_t *pFunnyShader = new FunnyShader_t; pFunnyShader->m_szName = szName; pFunnyShader->m_pShader = pShader; + m_shaders[uFoundIndex] = pFunnyShader; return uFoundIndex; } diff --git a/game/client/baseentity.cpp b/game/client/baseentity.cpp index e33172c..885b525 100644 --- a/game/client/baseentity.cpp +++ b/game/client/baseentity.cpp @@ -7,6 +7,7 @@ #include "baseentity.h" #include "datamap.h" #include "tier0/lib.h" +#include "cglm/cglm.h" C_BaseEntity::~C_BaseEntity() { @@ -19,11 +20,20 @@ void C_BaseEntity::Precache() void C_BaseEntity::Spawn() { - + Precache(); + SetAbsOrigin({0, 0, 0}); + SetAbsAngles(0, 0, 0); + SetScale(1); } void C_BaseEntity::SetAbsAngles( float fPitch, float fYaw, float fRoll ) { + versor q; + glm_euler_yzx_quat((vec3){fPitch, fYaw, fRoll}, q); + m_vRotation.x = q[0]; + m_vRotation.y = q[1]; + m_vRotation.z = q[2]; + m_vRotation.w = q[3]; } void C_BaseEntity::SetAbsOrigin( Vector origin ) @@ -39,19 +49,24 @@ void C_BaseEntity::SetScale( float fScale ) } -QAngle C_BaseEntity::GetAbsAngles( void ) +QAngle C_BaseEntity::GetAbsQAngles( void ) { } +Quat C_BaseEntity::GetAbsAngles( void ) +{ + return m_vRotation; +} + Vector C_BaseEntity::GetAbsOrigin( void ) { - + return m_vPosition; } float C_BaseEntity::GetScale( void ) { - + return m_vScale.x; } void C_BaseEntity::SetThinkImpl( fnThink pfnThink ) @@ -111,3 +126,9 @@ BEGIN_DATADESC_NOBASE(C_BaseEntity) DEFINE_KEYFIELD(m_vRotation, FIELD_QUATERNION, "angles") DEFINE_KEYFIELD(m_vScale, FIELD_FLOAT3, "scales") END_DATADESC() + +IMPLEMENT_RECV_DT_NOBASE(C_BaseEntity) + NetPropFloat3(m_vPosition) +END_RECV_DT() + +IMPLEMENT_EMPTY_SEND_DT_NOBASE(C_BaseEntity) diff --git a/game/client/baseentity.h b/game/client/baseentity.h index 8e76737..8419808 100644 --- a/game/client/baseentity.h +++ b/game/client/baseentity.h @@ -10,6 +10,8 @@ #include "entitysystem.h" #include "datamap.h" #include "trig.h" +#include "netmap.h" +#include "tier1/utlstring.h" #define DECLARE_CLASS_NOBASE( className ) \ typedef className ThisClass; @@ -18,7 +20,7 @@ typedef className ThisClass; #define LINK_ENTITY_TO_CLASS( mapClassName, DLLClassName) \ - static CEntityFactory g_EntityFactory_##mapClassName( #mapClassName ); + static CEntityFactory g_EntityFactory_##mapClassName( #mapClassName ); \ class C_BaseEntity; @@ -50,6 +52,7 @@ class C_BaseEntity public: DECLARE_CLASS_NOBASE(C_BaseEntity); DECLARE_DATADESC_NOBASE() + DECLARE_CLIENTCLASS_NOBASE() typedescription_t *FindDataByName( const char *szName ); typedescription_t *FindDataByMapName( const char *szName ); @@ -62,7 +65,8 @@ public: virtual void SetAbsOrigin( Vector origin ); virtual void SetScale( float fScale ); - virtual QAngle GetAbsAngles( void ); + virtual QAngle GetAbsQAngles( void ); + virtual Quat GetAbsAngles( void ); virtual Vector GetAbsOrigin( void ); virtual float GetScale( void ); @@ -71,6 +75,7 @@ public: virtual void SetNextThink( float fThink ); fnThink m_pfnThink = NULL; + CUtlString m_szClassName; private: Vector m_vPosition; Quat m_vRotation; diff --git a/game/client/basemodelentity.cpp b/game/client/basemodelentity.cpp new file mode 100644 index 0000000..4f00ba2 --- /dev/null +++ b/game/client/basemodelentity.cpp @@ -0,0 +1,34 @@ +#include "basemodelentity.h" + +void C_BaseModelEntity::Precache() +{ + +} +void C_BaseModelEntity::Spawn() +{ + BaseClass::Spawn(); + SetThink(Think); +} + +void C_BaseModelEntity::Think( float fDelta ) +{ + m_pInstance->SetPosition(GetAbsOrigin()); + m_pInstance->SetRotation(GetAbsAngles()); + m_pInstance->SetScale({GetScale(),GetScale(),GetScale()}); +} + + +void C_BaseModelEntity::SetModel( const char *szName ) +{ + if (m_uModelIndex) + { + g_pAssetManager->UnrefModel(m_uModelIndex); + } + m_uModelIndex = g_pAssetManager->LoadModel(szName); + m_pModel = g_pAssetManager->GetModelByIndex(m_uModelIndex); + m_pInstance = g_pWorldRenderer->CreateInstance(m_pModel->m_pMesh); +} + +BEGIN_DATADESC(C_BaseModelEntity) + +END_DATADESC() diff --git a/game/client/basemodelentity.h b/game/client/basemodelentity.h new file mode 100644 index 0000000..17ebb8e --- /dev/null +++ b/game/client/basemodelentity.h @@ -0,0 +1,27 @@ + +#ifndef BASE_MODEL_ENTITY_H +#define BASE_MODEL_ENTITY_H + +#include "baseentity.h" +#include "worldrender.h" +#include "assetmgr.h" + +class C_BaseModelEntity: public C_BaseEntity +{ +public: + DECLARE_CLASS(C_BaseModelEntity, C_BaseEntity); + DECLARE_DATADESC(); + + virtual void Precache() override; + virtual void Spawn() override; + void Think( float fDelta ); + + void SetModel( const char *szName ); +private: + + uint32_t m_uModelIndex; + FunnyModel_t *m_pModel; + IMeshInstance *m_pInstance; +}; + +#endif diff --git a/game/client/build.cpp b/game/client/build.cpp index e053f10..edec58d 100644 --- a/game/client/build.cpp +++ b/game/client/build.cpp @@ -18,6 +18,7 @@ DECLARE_BUILD_STAGE(Client) "game.cpp", "baseentity.cpp", + "basemodelentity.cpp", "entitysystem.cpp", "worldrender.cpp", diff --git a/game/client/engine.h b/game/client/engine.h deleted file mode 100644 index 69ca2f7..0000000 --- a/game/client/engine.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef ENGINE_H -#define ENGINE_H - -#include "tier2/ifilesystem.h" -#include "materialsystem/imaterialsystem.h" -#include "materialsystem/igamewindow.h" - -extern IFileSystem *filesystem; -extern IRenderContext *g_pRenderContext; -extern IGameWindow *g_pMainWindow; - -#endif diff --git a/game/client/entitysystem.cpp b/game/client/entitysystem.cpp index 38cc063..fb9f840 100644 --- a/game/client/entitysystem.cpp +++ b/game/client/entitysystem.cpp @@ -81,10 +81,30 @@ C_BaseEntity *CEntitySystem::CreateByClassname( const char *szName ) } pEntity = pFactory->Create(); + pEntity->m_szClassName = szName; m_pEntities[iSelectedSlot] = pEntity; m_nEntityCount++; return pEntity; } +C_BaseEntity *CEntitySystem::CreateByClassnameWithIndex( const char *szName, uint32_t uIndex ) +{ + IEntityFactory *pFactory; + C_BaseEntity *pEntity; + + // Do not create such shit + if (uIndex >= MAX_EDICTS) + return NULL; + + pFactory = GetFactoryByClassname(szName); + if ( !pFactory ) + return NULL; + + pEntity = pFactory->Create(); + pEntity->m_szClassName = szName; + m_pEntities[uIndex] = pEntity; + m_nEntityCount++; + return pEntity; +} IEntityFactory *CEntitySystem::GetFactoryByClassname( const char *szName ) { @@ -118,3 +138,8 @@ void CEntitySystem::Think() (pEntity->*pEntity->m_pfnThink)(0); } } + +C_BaseEntity **CEntitySystem::GetEntities() +{ + return m_pEntities; +}; diff --git a/game/client/entitysystem.h b/game/client/entitysystem.h index a4c7cf0..c3e9c33 100644 --- a/game/client/entitysystem.h +++ b/game/client/entitysystem.h @@ -7,6 +7,8 @@ #ifndef ENTITIES_H #define ENTITIES_H +#include "stdint.h" + class IEntityFactory; class C_BaseEntity; @@ -19,10 +21,12 @@ public: virtual void RegisterEntityClass( IEntityFactory *pEntityFactory, const char *szClassName ); virtual C_BaseEntity *CreateByClassname( const char *szName ); + virtual C_BaseEntity *CreateByClassnameWithIndex( const char *szName, uint32_t uIndex ); virtual IEntityFactory *GetFactoryByClassname( const char *szName ); virtual void Think(); + virtual C_BaseEntity **GetEntities(); private: C_BaseEntity *m_pEntities[MAX_EDICTS]; int m_nEntityCount; diff --git a/game/client/game.cpp b/game/client/game.cpp index 03770b9..788a344 100644 --- a/game/client/game.cpp +++ b/game/client/game.cpp @@ -7,12 +7,16 @@ #include "game.h" #include "cglm/mat4.h" #include "cglm/cglm.h" +#include "inetworkclient.h" +#include "netprotocol.h" IFileSystem *filesystem; IRenderContext *g_pRenderContext; IGameWindow *g_pMainWindow; static CEngineVars s_vars; CEngineVars *g_pEngineVars = &s_vars; +EngineConsts_t *g_pEngineConstants; +INetworkBase *g_pServerBridge; class CFunnyGameBridge: public IEngineBridge { @@ -34,18 +38,90 @@ EXPOSE_INTERFACE_FN(EngineBridge, IEngineBridge, ENGINE_BRIDGE_INTERFACE_VERSION void CFunnyGameBridge::Init() { g_pWorldRenderer->Init(); - C_BaseEntity *pEntity = EntitySystem()->CreateByClassname("player"); - pEntity->Spawn(); + g_pServerBridge = g_pEngineConstants->ConnectLocalBridge(0); + + PlayerJoined_t join = { + MESSAGE_PLAYER_JOINED, + "LocalPlayer" + }; + g_pServerBridge->SendPacket({&join, sizeof(join)}); } void CFunnyGameBridge::Tick( float fDelta ) { } +void *ENT_GetNetMapData(C_BaseEntity *pEntity, netmap_t *pMap, uint32_t uIndex ) +{ + netmap_t *pCurrentMap = pMap; + uint32_t uCurrentIndex = uIndex; +searchIndex: + if (uCurrentIndex >= pCurrentMap->m_uFieldCount) + { + if (!pCurrentMap->m_uFieldCount) + return NULL; + uCurrentIndex -= pCurrentMap->m_uFieldCount; + pCurrentMap = pCurrentMap->m_pBase; + if (!pCurrentMap) + return NULL; + goto searchIndex; + } + + return (char*)pEntity+pCurrentMap->m_pFields[uCurrentIndex].m_uOffset; +} + void CFunnyGameBridge::Frame( float fDelta ) { g_pEngineVars->m_fTime += fDelta; g_pEngineVars->m_fDeltaTime = fDelta; + + g_pServerBridge->NetThink(); + while ( g_pServerBridge->BHasUpdates() ) + { + NetPacket_t packet = g_pServerBridge->PeekPacket(); + // discard it + if (packet.uSize < sizeof (EMessageType)) + continue; + PlayerPacket_t *pPacket = (PlayerPacket_t*)packet.pData; + C_BaseEntity *pEntity; + switch (pPacket->m_eType) + { + case MESSAGE_ENTITY_CLASS_SYNC: + pEntity = EntitySystem()->CreateByClassnameWithIndex( + (char*)pPacket->m_entityClass.m_szEntityName, pPacket->m_entityClass.m_uIndex + ); + pEntity->Spawn(); + g_pServerBridge->RecievePacket(); + break; + case MESSAGE_ENTITY_DATA_SYNC: + pEntity = EntitySystem()->GetEntities()[pPacket->m_entityData.m_uIndex]; + union { + void *pData; + char *pcCurrentData; + EntityDataSyncValue_t *pcSyncValue; + }; + pData = pPacket; + pcCurrentData += sizeof(EntityDataSync_t); + for ( uint32_t u = 0; u < pPacket->m_entityData.m_uCount; u++ ) + { + uint32_t uVariableSize = pcSyncValue->m_uVariableSize; + void *pValueData = (float*)ENT_GetNetMapData( + pEntity, + pEntity->GetRecvMap(), + pcSyncValue->m_uVariableIndex); + + pcCurrentData += sizeof(EntityDataSyncValue_t); + if (pValueData) + V_memcpy(pValueData, pcCurrentData, uVariableSize); + pcCurrentData += (uVariableSize+7) & ~7; + } + g_pServerBridge->RecievePacket(); + break; + default: + continue; + } + } + EntitySystem()->Think(); g_pWorldRenderer->Frame(fDelta); } @@ -61,5 +137,6 @@ void CFunnyGameBridge::ConnectInterface( const char *psz, void *pInterface ) CONNECT_INTERFACE(RENDER_CONTEXT_INTERFACE_VERSION, g_pRenderContext); CONNECT_INTERFACE(FILESYSTEM_INTERFACE_VERSION, filesystem); CONNECT_INTERFACE("MainWindow", g_pMainWindow); + CONNECT_INTERFACE("EngineConstants", g_pEngineConstants); } diff --git a/game/client/mapmgr.cpp b/game/client/mapmgr.cpp new file mode 100644 index 0000000..e69de29 diff --git a/game/client/mapmgr.h b/game/client/mapmgr.h new file mode 100644 index 0000000..e69de29 diff --git a/game/client/milmoba/baseprojectile.cpp b/game/client/milmoba/baseprojectile.cpp new file mode 100644 index 0000000..e69de29 diff --git a/game/client/milmoba/baseprojectile.h b/game/client/milmoba/baseprojectile.h new file mode 100644 index 0000000..e69de29 diff --git a/game/client/milmoba/baseweapon.cpp b/game/client/milmoba/baseweapon.cpp new file mode 100644 index 0000000..e69de29 diff --git a/game/client/milmoba/baseweapon.h b/game/client/milmoba/baseweapon.h new file mode 100644 index 0000000..e69de29 diff --git a/game/client/milmoba/player.cpp b/game/client/milmoba/player.cpp index 78f4d92..22806dc 100644 --- a/game/client/milmoba/player.cpp +++ b/game/client/milmoba/player.cpp @@ -4,21 +4,29 @@ void C_MOBAPlayer::Precache() { - uint32_t uIndex = g_pAssetManager->LoadModel("game/core/models/cube.fmdl"); - V_printf("%u\n", uIndex); - pModel = g_pAssetManager->GetModelByIndex(uIndex); + SetModel("game/core/models/cube.fmdl"); } void C_MOBAPlayer::Spawn() { - Precache(); + BaseClass::Spawn(); SetThink(Think); + g_pWorldRenderer->SetCameraPosition({0, 0, -20}); }; void C_MOBAPlayer::Think( float fDelta ) { + BaseClass::Think(fDelta); }; LINK_ENTITY_TO_CLASS(player, C_MOBAPlayer) +BEGIN_DATADESC(C_MOBAPlayer) +END_DATADESC() + +IMPLEMENT_RECV_DT(C_MOBAPlayer) + NetPropFloat(m_fTimer), +END_RECV_DT() +IMPLEMENT_EMPTY_SEND_DT(C_MOBAPlayer) + diff --git a/game/client/milmoba/player.h b/game/client/milmoba/player.h index 3f3a0cb..acffbd2 100644 --- a/game/client/milmoba/player.h +++ b/game/client/milmoba/player.h @@ -1,17 +1,21 @@ -#include "baseentity.h" -#include "worldrender.h" -#include "game.h" -#include "assetmgr.h" +#ifndef MILMOBA_PLAYER_H +#define MILMOBA_PLAYER_H +#include "basemodelentity.h" -class C_MOBAPlayer: public C_BaseEntity +class C_MOBAPlayer: public C_BaseModelEntity { public: - DECLARE_CLASS(C_MOBAPlayer, C_BaseEntity) + DECLARE_CLASS(C_MOBAPlayer, C_BaseModelEntity); + DECLARE_DATADESC(); + DECLARE_CLIENTCLASS() + virtual void Precache ( void ) override; virtual void Spawn( void ) override; - virtual void Think( float fDelta ); + void Think( float fDelta ); - FunnyModel_t *pModel; + float m_fTimer; }; + +#endif diff --git a/game/client/worldrender.cpp b/game/client/worldrender.cpp index f4b81d1..9937958 100644 --- a/game/client/worldrender.cpp +++ b/game/client/worldrender.cpp @@ -134,6 +134,8 @@ private: ViewBuffer_t *m_pViewBufferData; ITextureArray *m_pTextures; + IShader *m_pRasterShader; + IMaterial *m_pRasterMaterial; vec3 m_vPos; versor m_vRot; @@ -192,6 +194,10 @@ void CFunnyWorldRenderer::Init() IMAGE_FORMAT_D32_SFLOAT, MULTISAMPLE_TYPE_4_SAMPLES ); + m_pRasterShader = g_pRenderContext->CreateShader("game/core/shaders/mesh_raster.shader_c"); + ConfigureShader(m_pRasterShader); + m_pRasterShader->Build(); + m_pRasterMaterial = g_pRenderContext->CreateMaterial(m_pRasterShader); g_pMainWindow->SetOutputImage(m_pResolvedOutputImage); @@ -291,16 +297,16 @@ void CFunnyWorldRenderer::Frame( float fDelta ) } pDataBuffer->Unmap(); pDataBuffer->Unlock(); - mesh->m_pMaterial->VSSetConstantsBuffer(0, m_pViewBuffer); - mesh->m_pMaterial->VSSetConstantsBuffer(1, pDataBuffer); - mesh->m_pMaterial->PSSetTextureArray(1, m_pTextures); + m_pRasterMaterial->VSSetConstantsBuffer(0, m_pViewBuffer); + m_pRasterMaterial->VSSetConstantsBuffer(1, pDataBuffer); + m_pRasterMaterial->PSSetTextureArray(1, m_pTextures); g_pRenderContext->DestroyBuffer(pDataBuffer); } for ( auto mesh: m_pMeshes) { if (mesh->m_instances.GetSize()==0) continue; - m_pRasterCommandList->SetMaterial(mesh->m_pMaterial); + m_pRasterCommandList->SetMaterial(m_pRasterMaterial); m_pRasterCommandList->SetVertexBuffer(0, mesh->m_pVertexBuffer); m_pRasterCommandList->DrawPrimitives(mesh->m_pVertexBuffer->GetSize()/32, 0, mesh->m_instances.GetSize(), 0); } diff --git a/game/client/worldrender.h b/game/client/worldrender.h index e4d3dc7..8e759f2 100644 --- a/game/client/worldrender.h +++ b/game/client/worldrender.h @@ -16,6 +16,16 @@ public: virtual void SetMaterial( IMaterial *pMaterial ) = 0; }; +abstract_class IPointLight +{ +public: + virtual void SetColor( Vector vColor ) = 0; + virtual void SetRadius( Vector vColor ) = 0; + virtual void SetPosition( Vector vPosition ) = 0; + virtual void SetRotation( Quat vRotation ) = 0; + virtual void SetScale( Vector vScale ) = 0; +}; + abstract_class IMeshInstance { public: diff --git a/game/server/baseentity.cpp b/game/server/baseentity.cpp index 805b1f7..0c9994e 100644 --- a/game/server/baseentity.cpp +++ b/game/server/baseentity.cpp @@ -7,15 +7,20 @@ #include "baseentity.h" #include "datamap.h" #include "tier0/lib.h" +#include "tier0/mem.h" CBaseEntity::~CBaseEntity() { +} +void CBaseEntity::Precache() +{ + } void CBaseEntity::Spawn() { - + Precache(); } void CBaseEntity::SetAbsAngles( float fPitch, float fYaw, float fRoll ) @@ -35,22 +40,27 @@ void CBaseEntity::SetScale( float fScale ) } -QAngle CBaseEntity::GetAbsAngles( void ) +QAngle CBaseEntity::GetAbsQAngles( void ) { } +Quat CBaseEntity::GetAbsAngles( void ) +{ + return m_vRotation; +} Vector CBaseEntity::GetAbsOrigin( void ) { + return m_vPosition; } float CBaseEntity::GetScale( void ) { - + return m_vScale.x; } -void CBaseEntity::SetThink( fnThink pfnThink ) +void CBaseEntity::SetThinkImpl( fnThink pfnThink ) { m_pfnThink = pfnThink; } @@ -107,3 +117,9 @@ BEGIN_DATADESC_NOBASE(CBaseEntity) DEFINE_KEYFIELD(m_vRotation, FIELD_QUATERNION, "angles") DEFINE_KEYFIELD(m_vScale, FIELD_FLOAT3, "scales") END_DATADESC() + +IMPLEMENT_SEND_DT_NOBASE(CBaseEntity) + NetPropFloat3(m_vPosition) +END_SEND_DT() + +IMPLEMENT_EMPTY_RECV_DT_NOBASE(CBaseEntity) diff --git a/game/server/baseentity.h b/game/server/baseentity.h index 373551a..5077e8f 100644 --- a/game/server/baseentity.h +++ b/game/server/baseentity.h @@ -11,15 +11,12 @@ #include "datamap.h" #include "cglm/cglm.h" #include "trig.h" +#include "netmap.h" -#define DECLARE_CLASS_NOBASE( className ) \ - typedef className ThisClass; -#define DECLARE_CLASS( className, baseName ) \ - typedef baseName BaseClass; \ - typedef className ThisClass; #define LINK_ENTITY_TO_CLASS( mapClassName, DLLClassName) \ - static CEntityFactory g_EntityFactory_##mapClassName( #mapClassName ); + static CEntityFactory g_EntityFactory_##mapClassName( #mapClassName ); \ + class CBaseEntity; @@ -45,35 +42,46 @@ public: class CBaseEntity; -typedef void(*fnThink)( float fTime ); +typedef void(CBaseEntity::*fnThink)( float fTime ); class CBaseEntity { +public: + public: DECLARE_CLASS_NOBASE(CBaseEntity); DECLARE_DATADESC_NOBASE() + DECLARE_SERVERCLASS_NOBASE() typedescription_t *FindDataByName( const char *szName ); typedescription_t *FindDataByMapName( const char *szName ); + const char *GetClassName(); + virtual ~CBaseEntity(); + virtual void Precache(); virtual void Spawn(); virtual void SetAbsAngles( float fPitch, float fYaw, float fRoll ); virtual void SetAbsOrigin( Vector origin ); virtual void SetScale( float fScale ); - virtual QAngle GetAbsAngles( void ); + virtual QAngle GetAbsQAngles( void ); + virtual Quat GetAbsAngles( void ); virtual Vector GetAbsOrigin( void ); virtual float GetScale( void ); - virtual void SetThink( fnThink pfnThink ); +#define SetThink(fn) SetThinkImpl((fnThink)&ThisClass::fn) + virtual void SetThinkImpl( fnThink pfnThink ); virtual void SetNextThink( float fThink ); fnThink m_pfnThink = NULL; + const char *m_szClassName; private: Vector m_vPosition; Quat m_vRotation; Vector m_vScale; + + }; #endif diff --git a/game/server/basemodelentity.cpp b/game/server/basemodelentity.cpp new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/game/server/basemodelentity.cpp @@ -0,0 +1 @@ + diff --git a/game/server/basemodelentity.h b/game/server/basemodelentity.h new file mode 100644 index 0000000..0f7c633 --- /dev/null +++ b/game/server/basemodelentity.h @@ -0,0 +1,12 @@ +#ifndef BASE_MODEL_ENTITY_H +#define BASE_MODEL_ENTITY_H + +#include "baseentity.h" + +class CBaseModelEntity: public CBaseEntity +{ +public: + DECLARE_CLASS(CBaseModelEntity, CBaseEntity); +}; + +#endif diff --git a/game/server/build.cpp b/game/server/build.cpp index 070d2cf..fa6152e 100644 --- a/game/server/build.cpp +++ b/game/server/build.cpp @@ -18,6 +18,9 @@ DECLARE_BUILD_STAGE(Server) "game.cpp", "entitysystem.cpp", "baseentity.cpp", + "basemodelentity.cpp", + + "milmoba/player.cpp", }; compileProject.includeDirectories = { "../../public", diff --git a/game/server/entitysystem.cpp b/game/server/entitysystem.cpp index 47ce830..3859337 100644 --- a/game/server/entitysystem.cpp +++ b/game/server/entitysystem.cpp @@ -9,6 +9,8 @@ #include "stddef.h" #include "string.h" #include "stdlib.h" +#include "engine.h" +#include "netprotocol.h" CEntitySystem *EntitySystem() @@ -81,11 +83,18 @@ CBaseEntity *CEntitySystem::CreateByClassname( const char *szName ) } pEntity = pFactory->Create(); + pEntity->m_szClassName = szName; m_pEntities[iSelectedSlot] = pEntity; m_nEntityCount++; + + EntityClass_t stClassSync = { + MESSAGE_ENTITY_CLASS_SYNC, + iSelectedSlot, + }; + V_strncpy((char*)stClassSync.m_szEntityName, szName, 256); + g_pClientBridge->SendPacket({&stClassSync, sizeof(stClassSync)}); return pEntity; } - IEntityFactory *CEntitySystem::GetFactoryByClassname( const char *szName ) { EntityRegistry_t *pEntity; @@ -99,15 +108,27 @@ IEntityFactory *CEntitySystem::GetFactoryByClassname( const char *szName ) } return NULL; } - - void CEntitySystem::Think() { CBaseEntity *pEntity; int i; + uint32_t u; + uint32_t x; + uint32_t uSize; + netmap_t *pNetMap; + void *pData; + union { + void *pCurrentData; + char *pcCurrentData; + EntityDataSync_t *pSync; + EntityDataSyncValue_t *pValue; + }; + + for ( i = 0; i < MAX_EDICTS; i++ ) { + pEntity = m_pEntities[i]; if ( pEntity == NULL ) continue; @@ -115,6 +136,54 @@ void CEntitySystem::Think() if ( !pEntity->m_pfnThink ) continue; - pEntity->m_pfnThink(0); + (pEntity->*pEntity->m_pfnThink)(0); + + pNetMap = pEntity->GetSendMap(); + uSize = sizeof(EntityDataSyncValue_t); + x = 0; + while ( pNetMap ) + { + for ( u = 0; u < pNetMap->m_uFieldCount; u++ ) + { + x++; + uSize += (pNetMap->m_pFields[u].m_uSize+7) & ~7; + uSize += sizeof(EntityDataSyncValue_t); + } + pNetMap = pNetMap->m_pBase; + } + pData = V_malloc(uSize); + V_memset(pData, 0, uSize); + pCurrentData = pData; + pSync->m_eType = MESSAGE_ENTITY_DATA_SYNC; + pSync->m_uIndex = i; + pSync->m_uCount = x; + + pcCurrentData += sizeof(EntityDataSync_t); + pNetMap = pEntity->GetSendMap(); + x = 0; + while ( pNetMap ) + { + for ( u = 0; u < pNetMap->m_uFieldCount; u++ ) + { + pValue->m_uVariableSize = pNetMap->m_pFields[u].m_uSize; + pValue->m_uVariableIndex = x; + uint32_t uVariableSize; + pcCurrentData += sizeof(EntityDataSyncValue_t); + V_memcpy(pcCurrentData, + pNetMap->m_pFields[u].m_uOffset+(char*)pEntity, + pNetMap->m_pFields[u].m_uSize); + pcCurrentData += (pNetMap->m_pFields[u].m_uSize+7) & ~7; + x++; + } + pNetMap = pNetMap->m_pBase; + } + g_pClientBridge->SendPacket({pData, uSize}); + V_free(pData); + } } + +CBaseEntity **CEntitySystem::GetEntities() +{ + return m_pEntities; +} diff --git a/game/server/entitysystem.h b/game/server/entitysystem.h index 93af605..66e211f 100644 --- a/game/server/entitysystem.h +++ b/game/server/entitysystem.h @@ -23,6 +23,7 @@ public: virtual IEntityFactory *GetFactoryByClassname( const char *szName ); virtual void Think(); + virtual CBaseEntity **GetEntities(); private: CBaseEntity *m_pEntities[MAX_EDICTS]; int m_nEntityCount; diff --git a/game/server/game.cpp b/game/server/game.cpp index 2ea56bd..0690086 100644 --- a/game/server/game.cpp +++ b/game/server/game.cpp @@ -1,10 +1,18 @@ #include "tier2/ifilesystem.h" -#include "materialsystem/imaterialsystem.h" +#include "entitysystem.h" +#include "baseentity.h" #include "enginebridge.h" +#include "game.h" +#include "inetworkserver.h" +#include "netprotocol.h" IFileSystem *filesystem; IRenderContext *g_pRenderContext; IGameWindow *g_pMainWindow; +static CEngineVars s_vars; +CEngineVars *g_pEngineVars = &s_vars; +EngineConsts_t *g_pEngineConstants; +INetworkBase *g_pClientBridge; class CFunnyGameBridge: public IEngineBridge { @@ -13,6 +21,7 @@ class CFunnyGameBridge: public IEngineBridge virtual void Frame( float fDelta ) override; virtual void Shutdown() override; virtual void ConnectInterface( const char *psz, void *pInterface ) override; + }; IEngineBridge *EngineBridge() @@ -24,7 +33,8 @@ IEngineBridge *EngineBridge() EXPOSE_INTERFACE_FN(EngineBridge, IEngineBridge, ENGINE_BRIDGE_INTERFACE_VERSION) void CFunnyGameBridge::Init() -{ +{ + g_pClientBridge = g_pEngineConstants->LaunchLocalBridge(0); } void CFunnyGameBridge::Tick( float fDelta ) @@ -34,6 +44,32 @@ void CFunnyGameBridge::Tick( float fDelta ) void CFunnyGameBridge::Frame( float fDelta ) { + g_pEngineVars->m_fTime += fDelta; + g_pEngineVars->m_fDeltaTime = fDelta; + + g_pClientBridge->NetThink(); + while (g_pClientBridge->BHasUpdates()) + { + NetPacket_t packet = g_pClientBridge->PeekPacket(); + // discard it + if (packet.uSize < sizeof (EMessageType)) + continue; + PlayerPacket_t *pPacket = (PlayerPacket_t*)packet.pData; + CBaseEntity *pEntity; + switch (pPacket->m_eType) + { + case MESSAGE_PLAYER_JOINED: + g_pClientBridge->RecievePacket(); + V_printf("Hi %s\n",pPacket->m_playerJoined.m_szPlayerName); + pEntity = EntitySystem()->CreateByClassname("player"); + pEntity->Spawn(); + break; + default: + continue; + } + } + + EntitySystem()->Think(); } @@ -45,5 +81,6 @@ void CFunnyGameBridge::Shutdown() #define CONNECT_INTERFACE(szName, pGlobal) if (!V_strcmp(psz, szName)) { pGlobal = (typeof(pGlobal))pInterface; return; } void CFunnyGameBridge::ConnectInterface( const char *psz, void *pInterface ) { + CONNECT_INTERFACE("EngineConstants", g_pEngineConstants) } diff --git a/game/server/milmoba/player.cpp b/game/server/milmoba/player.cpp new file mode 100644 index 0000000..68ecf9a --- /dev/null +++ b/game/server/milmoba/player.cpp @@ -0,0 +1,26 @@ +#include "player.h" +#include "game.h" + + + +void CMOBAPlayer::Spawn() +{ + SetThink(Think); +}; + +void CMOBAPlayer::Think( float fDelta ) +{ + m_fTimer = g_pEngineVars->m_fTime; + SetAbsOrigin({m_fTimer,0,0}); +}; + +LINK_ENTITY_TO_CLASS(player, CMOBAPlayer) + +BEGIN_DATADESC(CMOBAPlayer) +END_DATADESC() + +IMPLEMENT_SEND_DT(CMOBAPlayer) + NetPropFloat(m_fTimer) +END_SEND_DT() + +IMPLEMENT_EMPTY_RECV_DT(CMOBAPlayer) diff --git a/game/server/milmoba/player.h b/game/server/milmoba/player.h new file mode 100644 index 0000000..72cece1 --- /dev/null +++ b/game/server/milmoba/player.h @@ -0,0 +1,19 @@ +#ifndef MILMOBA_PLAYER_H +#define MILMOBA_PLAYER_H +#include "basemodelentity.h" + + +class CMOBAPlayer: public CBaseModelEntity +{ +public: + DECLARE_CLASS(CMOBAPlayer, CBaseModelEntity); + DECLARE_DATADESC(); + DECLARE_SERVERCLASS() + + virtual void Spawn( void ) override; + void Think( float fDelta ); + + float m_fTimer; +}; + +#endif diff --git a/game/server/pointentity.cpp b/game/server/pointentity.cpp new file mode 100644 index 0000000..6bc3868 --- /dev/null +++ b/game/server/pointentity.cpp @@ -0,0 +1 @@ +#include "pointentity.h" diff --git a/game/server/pointentity.h b/game/server/pointentity.h new file mode 100644 index 0000000..97db1cd --- /dev/null +++ b/game/server/pointentity.h @@ -0,0 +1,10 @@ +#ifndef POINT_ENTITY_H +#define POINT_ENTITY_H + +#include "baseentity.h" +class CPointEntity: public CBaseEntity +{ +public: +}; + +#endif diff --git a/game/shared/datamap.h b/game/shared/datamap.h index 204d7a3..cfda34e 100644 --- a/game/shared/datamap.h +++ b/game/shared/datamap.h @@ -10,6 +10,7 @@ #ifndef DATAMAP_H #define DATAMAP_H #include "stddef.h" +#include "gameclass.h" enum fieldtype_t { FIELD_VOID = 0, @@ -57,12 +58,6 @@ struct datamap_t int m_iNumFields; }; -#define DECLARE_CLASS_NOBASE( className ) \ - typedef className ThisClass; -#define DECLARE_CLASS( className, baseName ) \ - typedef baseName BaseClass; \ - typedef className ThisClass; - #define DECLARE_DATADESC() \ datamap_t *GetBaseMap(); \ virtual datamap_t *GetDataMap() override; \ @@ -103,6 +98,7 @@ struct datamap_t #define _class_offsetof( class, var ) ((size_t)&(((class*)0)->var)) #define _FIELD( name, fieldtype, count, flags, mapname, tolerance) { #name, mapname, fieldtype, _class_offsetof(ThisClass, name), count, sizeof(((ThisClass*)0)->name), flags }, +#define DEFINE_FIELD( name, fieldtype ) _FIELD( name, fieldtype, 1, FTYPEDESC_KEY, 0, 0) #define DEFINE_KEYFIELD( name, fieldtype, mapname ) _FIELD( name, fieldtype, 1, FTYPEDESC_KEY, mapname, 0) #define FTYPEDESC_KEY 0x0004 diff --git a/game/shared/engine.h b/game/shared/engine.h new file mode 100644 index 0000000..043a11d --- /dev/null +++ b/game/shared/engine.h @@ -0,0 +1,26 @@ +#ifndef ENGINE_H +#define ENGINE_H + +#include "tier2/ifilesystem.h" +#include "materialsystem/imaterialsystem.h" +#include "materialsystem/igamewindow.h" +#include "networkbase.h" + +struct EngineConsts_t +{ + bool m_bIsDedicated; + bool m_bIsSteam; + INetworkBase *(LaunchLocalBridge)(uint16_t uPort); + INetworkBase *(LaunchServer)(uint16_t uPort); + INetworkBase *(ConnectLocalBridge)(uint16_t uPort); + INetworkBase *(ConnectSteamServer)(uint64_t uServer, uint16_t uPort); +}; + +extern IFileSystem *filesystem; +extern IRenderContext *g_pRenderContext; +extern IGameWindow *g_pMainWindow; +extern EngineConsts_t *g_pEngineConstants; +extern INetworkBase *g_pServerBridge; +extern INetworkBase *g_pClientBridge; + +#endif diff --git a/game/shared/gameclass.h b/game/shared/gameclass.h new file mode 100644 index 0000000..592bb56 --- /dev/null +++ b/game/shared/gameclass.h @@ -0,0 +1,9 @@ +#ifndef GAMECLASS_H +#define GAMECLASS_H + +#define DECLARE_CLASS_NOBASE( className ) \ + typedef className ThisClass; +#define DECLARE_CLASS( className, baseName ) \ + typedef baseName BaseClass; \ + typedef className ThisClass; +#endif diff --git a/game/shared/netmap.h b/game/shared/netmap.h new file mode 100644 index 0000000..70aeab9 --- /dev/null +++ b/game/shared/netmap.h @@ -0,0 +1,118 @@ +#ifndef NETMAP_H +#define NETMAP_H +#include "stddef.h" +#include "stdint.h" +#include "datamap.h" + +struct netfield_t +{ + const char *m_szName; + fieldtype_t m_eType; + size_t m_uOffset; + size_t m_uSize; +}; + +struct netmap_t +{ + struct netmap_t *m_pBase; + netfield_t *m_pFields; + uint32_t m_uFieldCount; +}; + +#define NetPropInt(name) { #name, FIELD_INT, _class_offsetof(ThisClass, name), sizeof(name)} +#define NetPropFloat(name) { #name, FIELD_FLOAT, _class_offsetof(ThisClass, name), sizeof(name)} +#define NetPropFloat3(name) \ + NetPropFloat(name.x), \ + NetPropFloat(name.y), \ + NetPropFloat(name.z) +#define NetPropQuaternion(name) \ + NetPropFloat(name.x), \ + NetPropFloat(name.y), \ + NetPropFloat(name.z), \ + NetPropFloat(name.w) \ + +#define __DECLARE_NETCLASS_NOBASE() \ + netmap_t *GetBaseSendMap(); \ + virtual netmap_t *GetSendMap(); \ + virtual netmap_t SendMapInit(); \ + netmap_t *GetBaseRecvMap(); \ + virtual netmap_t *GetRecvMap(); \ + virtual netmap_t RecvMapInit(); \ + +#define __DECLARE_NETCLASS() \ + netmap_t *GetBaseSendMap(); \ + virtual netmap_t *GetSendMap() override; \ + virtual netmap_t SendMapInit() override; \ + netmap_t *GetBaseRecvMap(); \ + virtual netmap_t *GetRecvMap() override; \ + virtual netmap_t RecvMapInit() override; \ + +#define DECLARE_SERVERCLASS_NOBASE() \ + __DECLARE_NETCLASS_NOBASE() \ + +#define DECLARE_CLIENTCLASS_NOBASE() \ + __DECLARE_NETCLASS_NOBASE() \ + +#define DECLARE_SERVERCLASS() \ + __DECLARE_NETCLASS() \ + +#define DECLARE_CLIENTCLASS() \ + __DECLARE_NETCLASS() \ + +#define IMPLEMENT_SEND_DT_INTERNAL(className) \ +netmap_t *className::GetSendMap() { static netmap_t s_DataMap = ThisClass::SendMapInit(); return &s_DataMap; } \ +netmap_t className::SendMapInit() { \ + netmap_t map; \ + map.m_pBase = ThisClass::GetBaseSendMap(); \ + static netfield_t dataDesc[] \ + {\ + +#define IMPLEMENT_SEND_DT_NOBASE(className) \ + netmap_t *className::GetBaseSendMap() { return NULL; } \ + IMPLEMENT_SEND_DT_INTERNAL(className) +#define IMPLEMENT_SEND_DT(className) \ + netmap_t *className::GetBaseSendMap() { return BaseClass::GetSendMap(); } \ + IMPLEMENT_SEND_DT_INTERNAL(className) + +#define IMPLEMENT_RECV_DT_INTERNAL(className) \ +netmap_t *className::GetRecvMap() { static netmap_t s_DataMap = ThisClass::RecvMapInit(); return &s_DataMap; } \ +netmap_t className::RecvMapInit() { \ + netmap_t map; \ + map.m_pBase = ThisClass::GetBaseRecvMap(); \ + static netfield_t dataDesc[] \ + {\ + +#define IMPLEMENT_RECV_DT_NOBASE(className) \ + netmap_t *className::GetBaseRecvMap() { return NULL; } \ + IMPLEMENT_RECV_DT_INTERNAL(className) +#define IMPLEMENT_RECV_DT(className) \ + netmap_t *className::GetBaseRecvMap() { return BaseClass::GetRecvMap(); } \ + IMPLEMENT_RECV_DT_INTERNAL(className) + +#define END_NET_DT_INTERNAL() \ + }; \ + map.m_uFieldCount = sizeof(dataDesc)/sizeof(netfield_t); \ + map.m_pFields = dataDesc; \ + return map; \ +} + +#define END_SEND_DT() \ + END_NET_DT_INTERNAL() +#define END_RECV_DT() \ + END_NET_DT_INTERNAL() + +#define IMPLEMENT_EMPTY_SEND_DT_NOBASE(className) \ + IMPLEMENT_SEND_DT_NOBASE(className) \ + END_RECV_DT() +#define IMPLEMENT_EMPTY_SEND_DT(className) \ + IMPLEMENT_SEND_DT(className) \ + END_RECV_DT() +#define IMPLEMENT_EMPTY_RECV_DT_NOBASE(className) \ + IMPLEMENT_RECV_DT_NOBASE(className) \ + END_RECV_DT() +#define IMPLEMENT_EMPTY_RECV_DT(className) \ + IMPLEMENT_RECV_DT(className) \ + END_RECV_DT() + + +#endif diff --git a/game/shared/netprotocol.h b/game/shared/netprotocol.h new file mode 100644 index 0000000..a6d6d03 --- /dev/null +++ b/game/shared/netprotocol.h @@ -0,0 +1,76 @@ +#ifndef NET_PROTOCOL_H +#define NET_PROTOCOL_H + + +#include "stdint.h" +#include + +class CNetworkUInt32 +{ +public: + CNetworkUInt32() : m_uValue(0) {} + CNetworkUInt32( uint32_t uValue ) : m_uValue(htonl(uValue)) {} + operator uint32_t() const { + return htonl(m_uValue); + } + uint32_t m_uValue; +}; + +enum EMessageType: uint32_t +{ + MESSAGE_PLAYER_JOINED, + MESSAGE_PLAYER_JOINED_CALLBACK, + MESSAGE_PLAYER_LEFT, + MESSAGE_ENTITY_CLASS_SYNC, + MESSAGE_ENTITY_DATA_SYNC, +}; + +struct PlayerJoined_t +{ + EMessageType m_eType; + int8_t m_szPlayerName[256]; +}; + +struct PlayerJoinedCallback_t +{ + EMessageType m_eType; + CNetworkUInt32 m_uPlayerIndex; +}; + +struct PlayerLeft_t +{ + EMessageType m_eType; + CNetworkUInt32 m_uPlayerIndex; +}; + +struct EntityClass_t +{ + EMessageType m_eType; + CNetworkUInt32 m_uIndex; + int8_t m_szEntityName[256]; +}; + +struct EntityDataSync_t +{ + EMessageType m_eType; + CNetworkUInt32 m_uIndex; + CNetworkUInt32 m_uCount; +}; + +struct EntityDataSyncValue_t +{ + CNetworkUInt32 m_uVariableIndex; + CNetworkUInt32 m_uVariableSize; +}; + +union PlayerPacket_t +{ + EMessageType m_eType; + PlayerJoined_t m_playerJoined; + PlayerJoinedCallback_t m_playerJoinedCallback; + PlayerLeft_t m_playerLeft; + EntityClass_t m_entityClass; + EntityDataSync_t m_entityData; +}; + +#endif diff --git a/materialsystem/vulkan/material.cpp b/materialsystem/vulkan/material.cpp index 896680f..5bdbc4e 100644 --- a/materialsystem/vulkan/material.cpp +++ b/materialsystem/vulkan/material.cpp @@ -2,6 +2,8 @@ CVkMaterial::CVkMaterial( IShader *pShader ) { m_pVkShader = (CVkShader*)pShader; + if ( m_pVkShader->m_setLayouts.GetSize() == 0 ) + return; VkDescriptorPoolSize pools[4] = { @@ -76,6 +78,8 @@ void CVkMaterial::PSSetTextureArray( uint32_t uSet, ITextureArray *pArray ) void CVkMaterial::SetShaderResource( uint32_t uRegister, uint32_t uSet, IRenderingObject *pObject) { + if ( m_pVkShader->m_setLayouts.GetSize() == 0 ) + return; union { IRenderingObject *pVkObject; CVkBuffer *pBuffer; diff --git a/materialsystem/vulkan/rendercontext.cpp b/materialsystem/vulkan/rendercontext.cpp index 260c4ba..f5a16dd 100644 --- a/materialsystem/vulkan/rendercontext.cpp +++ b/materialsystem/vulkan/rendercontext.cpp @@ -935,6 +935,7 @@ void CVkRenderContext::Frame( float fDeltaTime ) stPresentInfo.pImageIndices = uImageIndexes.GetData(); vkQueuePresentKHR(s_vkPresentQueue, &stPresentInfo); + vkDeviceWaitIdle(s_vkDevice); for ( auto &s: m_renderWindows ) { diff --git a/materialsystem/vulkan/shader.cpp b/materialsystem/vulkan/shader.cpp index e0b85ea..0282081 100644 --- a/materialsystem/vulkan/shader.cpp +++ b/materialsystem/vulkan/shader.cpp @@ -2,10 +2,7 @@ #include "tier1/utlvector.h" #include "vulkan_state.h" #include "shaderparser.h" -CVkShader::~CVkShader() -{ -} void CVkShader::AddLayout( int iIndex, int iStride ) { VkVertexInputBindingDescription layout = {}; @@ -208,12 +205,7 @@ void CVkShader::Build() vkCreateGraphicsPipelines(m_hDevice, NULL, 1, &createInfo, NULL, &m_hPipeline); } -uint32_t CVkShader::PSGetResourceByName( const char *szName ) -{ - -} - -uint32_t CVkShader::VSGetResourceByName( const char *szName ) +uint32_t CVkShader::GetResourceByName( const char *szName ) { } diff --git a/materialsystem/vulkan/utils.cpp b/materialsystem/vulkan/utils.cpp index 7fc2866..14c11d2 100644 --- a/materialsystem/vulkan/utils.cpp +++ b/materialsystem/vulkan/utils.cpp @@ -115,6 +115,10 @@ VkShaderStageFlagBits VulkanGetShaderStage( EShaderStage eStage ) { case SHADER_STAGE_VERTEX: return VK_SHADER_STAGE_VERTEX_BIT; case SHADER_STAGE_PIXEL: return VK_SHADER_STAGE_FRAGMENT_BIT; + case SHADER_STAGE_COMPUTE: return VK_SHADER_STAGE_COMPUTE_BIT; + case SHADER_STAGE_RAYGEN: return VK_SHADER_STAGE_RAYGEN_BIT_KHR; + case SHADER_STAGE_RAYGEN_SOFTWARE: + return VK_SHADER_STAGE_COMPUTE_BIT; default: break; } diff --git a/materialsystem/vulkan/vulkan_state.h b/materialsystem/vulkan/vulkan_state.h index 178018e..acb8e46 100644 --- a/materialsystem/vulkan/vulkan_state.h +++ b/materialsystem/vulkan/vulkan_state.h @@ -261,9 +261,7 @@ void CVk##name##PipelineLibrary::Build() \ class CVkShader : public IShader { public: - ~CVkShader(); - virtual uint32_t PSGetResourceByName( const char *szName ) override; - virtual uint32_t VSGetResourceByName( const char *szName ) override; + virtual uint32_t GetResourceByName( const char *szName ) override; virtual void AddLayout( int iIndex, int iStride ) override; virtual void AddAttribute( int iBufferIndex, int iLocation, EVertexFormat eFormat, int iOffset ) override; virtual void SetTopology( ETopologyMode eTopology ) override; diff --git a/public/cl_dll.h b/public/cl_dll.h index 955f784..589b6af 100644 --- a/public/cl_dll.h +++ b/public/cl_dll.h @@ -14,6 +14,7 @@ public: IGameWindow *m_pGameWindow; IRenderContext *m_pRenderContext; + EngineConsts_t *m_pEngineConsts; IEngineBridge *m_pBridge; diff --git a/public/enginebridge.h b/public/enginebridge.h index 5ab6e93..343e007 100644 --- a/public/enginebridge.h +++ b/public/enginebridge.h @@ -2,7 +2,17 @@ #define ENGINE_BRIDGE_H #include "gamesystem.h" +#include "networkbase.h" +struct EngineConsts_t +{ + bool m_bIsDedicated; + bool m_bIsSteam; + INetworkBase *(*LaunchLocalBridge)(uint16_t uPort); + INetworkBase *(*LaunchServer)(uint16_t uPort); + INetworkBase *(*ConnectLocalBridge)(uint16_t uPort); + INetworkBase *(*ConnectSteamServer)(uint64_t uServer, uint16_t uPort); +}; abstract_class IEngineBridge: public IGameSystem { public: diff --git a/public/inetworkclient.h b/public/inetworkclient.h index e69de29..d51223d 100644 --- a/public/inetworkclient.h +++ b/public/inetworkclient.h @@ -0,0 +1,10 @@ +#ifndef NETWORK_CLIENT_H +#define NETWORK_CLIENT_H + +#include "networkbase.h" + +INetworkBase *ConnectByLocalBridge( uint16_t uPort ); +INetworkBase *ConnectByIP( const char *szIP, uint16_t uPort ); +INetworkBase *ConnectBySteamID( uint64_t uID, uint16_t uPort ); + +#endif diff --git a/public/inetworkserver.h b/public/inetworkserver.h index e69de29..de11506 100644 --- a/public/inetworkserver.h +++ b/public/inetworkserver.h @@ -0,0 +1,24 @@ +#ifndef NETWORK_SERVER_H +#define NETWORK_SERVER_H + +#include "networkbase.h" + +//----------------------------------------------------------------------------- +// Launches local server +// Good to pass data between server and client +//----------------------------------------------------------------------------- +INetworkBase *LaunchLocalBridge( uint16_t uPort ); + +//----------------------------------------------------------------------------- +// Launches public server at port +// Public if you open ports :0 +//----------------------------------------------------------------------------- +INetworkBase *LaunchServerAtPort( uint16_t uPort ); + +//----------------------------------------------------------------------------- +// Launches public server at steam datagram relay +// We just trust this method +//----------------------------------------------------------------------------- +INetworkBase *LaunchServerAtSteamRelay( uint16_t uPort ); + +#endif diff --git a/public/materialsystem/imaterialsystem.h b/public/materialsystem/imaterialsystem.h index f56ce0a..17e2efa 100644 --- a/public/materialsystem/imaterialsystem.h +++ b/public/materialsystem/imaterialsystem.h @@ -109,6 +109,13 @@ enum EStoreMode STORE_MODE_DONT_CARE, }; +enum ECullingMode +{ + CULL_MODE_NONE, + CULL_MODE_FRONT, + CULL_MODE_BACK, +}; + enum ETopologyMode { TOPOLOGY_MODE_POINT_LIST, @@ -168,15 +175,41 @@ public: virtual void UnloadTexture( uint32_t uTextureID ) = 0; }; +abstract_class ITriangleAccelerationStructure: public IRenderingObject +{ +public: + virtual void SetVertices( IVertexBuffer *pBuffer, EVertexFormat eFormat, int iStride ) = 0; + virtual void SetIndicies( IVertexBuffer *pBuffer, EIndexFormat eFormat ) = 0; + virtual void SetTopology( ETopologyMode eTopology ) = 0; + virtual void Build() = 0; + virtual void Update( IVertexBuffer *pBuffer ) = 0; +}; + +abstract_class IAABBAccelerationStructure: public IRenderingObject +{ +public: + virtual void Build() = 0; +}; + +abstract_class IWorldAccelerationStructure: public IRenderingObject +{ +public: + virtual void Build() = 0; +}; + +abstract_class IBaseShader +{ +public: + virtual void Build() = 0; +}; + //----------------------------------------------------------------------------- // Shader object //----------------------------------------------------------------------------- -abstract_class IShader +abstract_class IShader: public IBaseShader { public: - virtual ~IShader() = default; - virtual uint32_t PSGetResourceByName( const char *szName ) = 0; - virtual uint32_t VSGetResourceByName( const char *szName ) = 0; + virtual uint32_t GetResourceByName( const char *szName ) = 0; virtual void AddLayout( int iIndex, int iStride ) = 0; virtual void AddAttribute( int iBufferIndex, int iLocation, EVertexFormat eFormat, int iOffset ) = 0; virtual void SetTopology( ETopologyMode eTopology ) = 0; @@ -184,7 +217,19 @@ public: virtual void SetDepthImage( EImageFormat eFormat ) = 0; virtual void SetMultisampling( EMultisampleType eFormat ) = 0; virtual void DisablePixelShader( bool bDisable) = 0; - virtual void Build() = 0; +}; + +abstract_class IComputeShader +{ +public: +}; + +abstract_class IRayTracingShader +{ +public: + virtual uint32_t GetMissShaderBinding( const char *szName ); + virtual uint32_t GetClosestHitShaderBinding( const char *szName ); + virtual uint32_t GetCallableShaderBinding( const char *szName ); }; //----------------------------------------------------------------------------- diff --git a/public/materialsystem/shaderinternals.h b/public/materialsystem/shaderinternals.h index ceb70c9..0ebf9f1 100644 --- a/public/materialsystem/shaderinternals.h +++ b/public/materialsystem/shaderinternals.h @@ -37,6 +37,12 @@ enum EShaderStage: uint32_t SHADER_STAGE_MISS, SHADER_STAGE_CALLABLE, + SHADER_STAGE_RAYGEN_SOFTWARE, + SHADER_STAGE_ANY_HIT_SOFTWARE, + SHADER_STAGE_CLOSEST_HIT_SOFTWARE, + SHADER_STAGE_MISS_SOFTWARE, + SHADER_STAGE_CALLABLE_SOFTWARE, + SHADER_STAGE_TASK, SHADER_STAGE_MESH, diff --git a/public/networkbase.h b/public/networkbase.h new file mode 100644 index 0000000..04299f1 --- /dev/null +++ b/public/networkbase.h @@ -0,0 +1,30 @@ + +#ifndef NETWORK_BASE_H +#define NETWORK_BASE_H +#include "tier1/interface.h" + +struct NetPacket_t +{ + void *pData; + uint32_t uSize; +}; + +abstract_class INetworkBase +{ +public: + virtual ~INetworkBase() = default; + + virtual void NetThink() = 0; + + virtual uint32_t BHasUpdates() = 0; + virtual NetPacket_t RecievePacket() = 0; + virtual NetPacket_t PeekPacket() = 0; + + virtual void SendPacket( NetPacket_t stPacket ) = 0; + + virtual uint64_t GetSteamID() = 0; + virtual const char *GetIP() = 0; + virtual uint16_t GetPort() = 0; +}; + +#endif diff --git a/public/sv_dll.h b/public/sv_dll.h index 4f9c358..d267962 100644 --- a/public/sv_dll.h +++ b/public/sv_dll.h @@ -14,6 +14,7 @@ public: IGameWindow *m_pGameWindow; IRenderContext *m_pRenderContext; + EngineConsts_t *m_pEngineConsts; IEngineBridge *m_pBridge; diff --git a/public/trig.h b/public/trig.h index 9aaf858..e9de4fc 100644 --- a/public/trig.h +++ b/public/trig.h @@ -6,6 +6,17 @@ struct Vector { float y; float z; }; +struct Color { + float r; + float g; + float b; +}; +struct ColorAlpha { + float r; + float g; + float b; + float a; +}; struct QAngle { float pitch; float yaw; diff --git a/shadercompiler/slang/vulkan_spirv.cpp b/shadercompiler/slang/vulkan_spirv.cpp index 97d7fed..e902d40 100644 --- a/shadercompiler/slang/vulkan_spirv.cpp +++ b/shadercompiler/slang/vulkan_spirv.cpp @@ -63,6 +63,12 @@ void CSlangVulkanSpirvShaderCompiler::CompileShaderStage( EShaderStage eStage, c case SHADER_STAGE_PIXEL: eSlangStage = SLANG_STAGE_PIXEL; break; + case SHADER_STAGE_RAYGEN: + eSlangStage = SLANG_STAGE_RAY_GENERATION; + break; + case SHADER_STAGE_RAYGEN_SOFTWARE: + eSlangStage = SLANG_STAGE_COMPUTE; + break; case SHADER_STAGE_CALLABLE: eSlangStage = SLANG_STAGE_CALLABLE; break; @@ -104,6 +110,20 @@ trygetkind: break; } break; + case slang::TypeReflection::Kind::Resource: + V_printf("%s: %i\n", pType->getName(), pType->getResourceShape()); + switch(pType->getResourceShape()) + { + case SLANG_TEXTURE_2D: + input.eDescriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; + break; + case SLANG_STRUCTURED_BUFFER: + input.eDescriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + break; + default: + break; + } + break; case slang::TypeReflection::Kind::Array: { size_t uCount = pType->getTotalArrayElementCount(); @@ -123,7 +143,7 @@ trygetkind: V_strncpy(input.szName, pVar->getName(), 32); input.uBinding = pVar->getBindingIndex(); input.uSet = pVar->getBindingSpace(); - V_printf("%i\n", input.uCount); + //V_printf("%i\n", input.uCount); inputs.AppendTail(input); } @@ -182,7 +202,7 @@ void CSlangVulkanSpirvShaderCompiler::CompileShader( const char *szInput, CCompi { SessionDesc stSessionDesc = {}; TargetDesc stTargetDesc = {}; - PreprocessorMacroDesc stStageMacroDesc = {}; + PreprocessorMacroDesc stStageMacroDesc[2] = {}; const char *szMainName; IModule *pModule = NULL; ISession *pSession = NULL; @@ -215,25 +235,35 @@ void CSlangVulkanSpirvShaderCompiler::CompileShader( const char *szInput, CCompi for ( i = 0; i