better physics
This commit is contained in:
@@ -40,6 +40,7 @@ DECLARE_BUILD_STAGE(install_game)
|
|||||||
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/meshes");
|
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/meshes");
|
||||||
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/materials");
|
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/materials");
|
||||||
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/textures");
|
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/textures");
|
||||||
|
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/physics");
|
||||||
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "build/funnygame/assets/shaders");
|
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "build/funnygame/assets/shaders");
|
||||||
if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_WINDOWS)
|
if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_WINDOWS)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ void CClientGameDLL::Init()
|
|||||||
IEngineBridge *pEngineBridge = (IEngineBridge*)pfnServerFactory(ENGINE_BRIDGE_INTERFACE_VERSION, NULL);
|
IEngineBridge *pEngineBridge = (IEngineBridge*)pfnServerFactory(ENGINE_BRIDGE_INTERFACE_VERSION, NULL);
|
||||||
|
|
||||||
pEngineBridge->ConnectInterface(RENDER_CONTEXT_INTERFACE_VERSION, m_pRenderContext);
|
pEngineBridge->ConnectInterface(RENDER_CONTEXT_INTERFACE_VERSION, m_pRenderContext);
|
||||||
pEngineBridge->ConnectInterface("MainWindow", m_pGameWindow);
|
|
||||||
pEngineBridge->ConnectInterface(FILESYSTEM_INTERFACE_VERSION, filesystem);
|
pEngineBridge->ConnectInterface(FILESYSTEM_INTERFACE_VERSION, filesystem);
|
||||||
|
pEngineBridge->ConnectInterface("MainWindow", m_pGameWindow);
|
||||||
pEngineBridge->ConnectInterface("EngineConstants", m_pEngineConsts);
|
pEngineBridge->ConnectInterface("EngineConstants", m_pEngineConsts);
|
||||||
pEngineBridge->Init();
|
pEngineBridge->Init();
|
||||||
m_pBridge = pEngineBridge;
|
m_pBridge = pEngineBridge;
|
||||||
|
|||||||
24
engine/humandevice.cpp
Normal file
24
engine/humandevice.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include "humandevice.h"
|
||||||
|
#include "tier1/interface.h"
|
||||||
|
|
||||||
|
class CHumanDeviceManager: public IHumanDeviceManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void SetButtonPressed( EInputButton eButton ) override;
|
||||||
|
virtual void SetButtonUnpressed( EInputButton eButton ) override;
|
||||||
|
|
||||||
|
bool m_abIsButtonPressed[k_EInputButton_Count];
|
||||||
|
};
|
||||||
|
|
||||||
|
void CHumanDeviceManager::SetButtonPressed( EInputButton eButton )
|
||||||
|
{
|
||||||
|
m_abIsButtonPressed[eButton] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CHumanDeviceManager::SetButtonUnpressed( EInputButton eButton )
|
||||||
|
{
|
||||||
|
m_abIsButtonPressed[eButton] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
EXPOSE_INTERFACE_GLOBALVAR(CHumanDeviceManager, IHumanDeviceManager, HUMAN_DEVICE_MANAGER_INTERFACE_VERSION, g_pHumanDeviceManager)
|
||||||
110
engine/humandevice.h
Normal file
110
engine/humandevice.h
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
#ifndef KEYBINDINGS_H
|
||||||
|
#define KEYBINDINGS_H
|
||||||
|
|
||||||
|
#include "tier0/platform.h"
|
||||||
|
|
||||||
|
enum EInputButton
|
||||||
|
{
|
||||||
|
k_EInputButton_NONE = 0,
|
||||||
|
|
||||||
|
k_EInputButton_MOUSE_BUTTON_0,
|
||||||
|
k_EInputButton_MOUSE_BUTTON_1,
|
||||||
|
k_EInputButton_MOUSE_BUTTON_2,
|
||||||
|
k_EInputButton_MOUSE_BUTTON_3,
|
||||||
|
k_EInputButton_MOUSE_BUTTON_4,
|
||||||
|
|
||||||
|
k_EInputButton_ESCAPE,
|
||||||
|
k_EInputButton_TAB,
|
||||||
|
k_EInputButton_TILDE,
|
||||||
|
k_EInputButton_CAPSLOCK,
|
||||||
|
k_EInputButton_CONTROL,
|
||||||
|
k_EInputButton_SHIFT,
|
||||||
|
k_EInputButton_WIN,
|
||||||
|
k_EInputButton_ALT,
|
||||||
|
k_EInputButton_SPACE,
|
||||||
|
|
||||||
|
k_EInputButton_BACKSPACE,
|
||||||
|
k_EInputButton_LBRACKET,
|
||||||
|
k_EInputButton_RBRACKET,
|
||||||
|
k_EInputButton_BACKSLASH,
|
||||||
|
k_EInputButton_SEMICOLON,
|
||||||
|
k_EInputButton_APOSTROPHE,
|
||||||
|
k_EInputButton_SLASH,
|
||||||
|
k_EInputButton_ENTER,
|
||||||
|
|
||||||
|
k_EInputButton_F1,
|
||||||
|
k_EInputButton_F2,
|
||||||
|
k_EInputButton_F3,
|
||||||
|
k_EInputButton_F4,
|
||||||
|
k_EInputButton_F5,
|
||||||
|
k_EInputButton_F6,
|
||||||
|
k_EInputButton_F7,
|
||||||
|
k_EInputButton_F8,
|
||||||
|
k_EInputButton_F9,
|
||||||
|
k_EInputButton_F10,
|
||||||
|
k_EInputButton_F11,
|
||||||
|
k_EInputButton_F12,
|
||||||
|
|
||||||
|
k_EInputButton_1,
|
||||||
|
k_EInputButton_2,
|
||||||
|
k_EInputButton_3,
|
||||||
|
k_EInputButton_4,
|
||||||
|
k_EInputButton_5,
|
||||||
|
k_EInputButton_6,
|
||||||
|
k_EInputButton_7,
|
||||||
|
k_EInputButton_8,
|
||||||
|
k_EInputButton_9,
|
||||||
|
k_EInputButton_0,
|
||||||
|
|
||||||
|
k_EInputButton_A,
|
||||||
|
k_EInputButton_B,
|
||||||
|
k_EInputButton_C,
|
||||||
|
k_EInputButton_D,
|
||||||
|
k_EInputButton_E,
|
||||||
|
k_EInputButton_F,
|
||||||
|
k_EInputButton_G,
|
||||||
|
k_EInputButton_H,
|
||||||
|
k_EInputButton_I,
|
||||||
|
k_EInputButton_J,
|
||||||
|
k_EInputButton_K,
|
||||||
|
k_EInputButton_L,
|
||||||
|
k_EInputButton_M,
|
||||||
|
k_EInputButton_N,
|
||||||
|
k_EInputButton_O,
|
||||||
|
k_EInputButton_P,
|
||||||
|
k_EInputButton_Q,
|
||||||
|
k_EInputButton_R,
|
||||||
|
k_EInputButton_S,
|
||||||
|
k_EInputButton_T,
|
||||||
|
k_EInputButton_U,
|
||||||
|
k_EInputButton_V,
|
||||||
|
k_EInputButton_W,
|
||||||
|
k_EInputButton_X,
|
||||||
|
k_EInputButton_Y,
|
||||||
|
k_EInputButton_Z,
|
||||||
|
k_EInputButton_MAX,
|
||||||
|
k_EInputButton_Count = k_EInputButton_MAX - 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum EInputType
|
||||||
|
{
|
||||||
|
k_EInput_Game,
|
||||||
|
k_EInput_Menu,
|
||||||
|
k_EInput_InputBox,
|
||||||
|
};
|
||||||
|
|
||||||
|
abstract_class IHumanDeviceManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void SetDefaultInputType( EInputType eType ) = 0;
|
||||||
|
virtual void PushInputType( EInputType eType ) = 0;
|
||||||
|
virtual void PopInputType() = 0;
|
||||||
|
virtual void SetButtonPressed( EInputButton eButton ) = 0;
|
||||||
|
virtual void SetButtonUnpressed( EInputButton eButton ) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define HUMAN_DEVICE_MANAGER_INTERFACE_VERSION "HumanDeviceMgr001"
|
||||||
|
|
||||||
|
extern IHumanDeviceManager *g_pHumanDeviceManager;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
|
|
||||||
class CUnsecureNetworkManager
|
|
||||||
{
|
|
||||||
|
|
||||||
};
|
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "tier1/interface.h"
|
#include "tier1/interface.h"
|
||||||
#include "tier0/platform.h"
|
#include "tier0/platform.h"
|
||||||
#include "icvar.h"
|
#include "icvar.h"
|
||||||
|
#include "tier2/ifilesystem.h"
|
||||||
|
|
||||||
void CServerGameDLL::Init()
|
void CServerGameDLL::Init()
|
||||||
{
|
{
|
||||||
@@ -16,6 +17,7 @@ void CServerGameDLL::Init()
|
|||||||
|
|
||||||
CreateInterfaceFn pfnServerFactory = Sys_GetFactory(pLib);
|
CreateInterfaceFn pfnServerFactory = Sys_GetFactory(pLib);
|
||||||
IEngineBridge *pEngineBridge = (IEngineBridge*)pfnServerFactory(ENGINE_BRIDGE_INTERFACE_VERSION, NULL);
|
IEngineBridge *pEngineBridge = (IEngineBridge*)pfnServerFactory(ENGINE_BRIDGE_INTERFACE_VERSION, NULL);
|
||||||
|
pEngineBridge->ConnectInterface(FILESYSTEM_INTERFACE_VERSION, filesystem);
|
||||||
pEngineBridge->ConnectInterface("EngineConstants", m_pEngineConsts);
|
pEngineBridge->ConnectInterface("EngineConstants", m_pEngineConsts);
|
||||||
pEngineBridge->Init();
|
pEngineBridge->Init();
|
||||||
m_pBridge = pEngineBridge;
|
m_pBridge = pEngineBridge;
|
||||||
|
|||||||
2
external/GameNetworkingSockets
vendored
2
external/GameNetworkingSockets
vendored
Submodule external/GameNetworkingSockets updated: 725e273c74...517fff0cf6
2
external/SDL
vendored
2
external/SDL
vendored
Submodule external/SDL updated: 7c11a8cb9f...77f4a8e2b8
2
external/Vulkan-Headers
vendored
2
external/Vulkan-Headers
vendored
Submodule external/Vulkan-Headers updated: 2e0a6e699e...ad9ce1235e
2
external/Vulkan-Utility-Libraries
vendored
2
external/Vulkan-Utility-Libraries
vendored
Submodule external/Vulkan-Utility-Libraries updated: 4f4c0b6c61...738ec97a3f
2
external/VulkanMemoryAllocator
vendored
2
external/VulkanMemoryAllocator
vendored
Submodule external/VulkanMemoryAllocator updated: f0969e908b...e722e57c89
2
external/cglm
vendored
2
external/cglm
vendored
Submodule external/cglm updated: a886d6e170...83d5b2c973
2
external/slang
vendored
2
external/slang
vendored
Submodule external/slang updated: 5d775e2829...6128e511c7
2
external/stb
vendored
2
external/stb
vendored
Submodule external/stb updated: 802cd454f2...f1c79c0282
2
external/volk
vendored
2
external/volk
vendored
Submodule external/volk updated: d64d20b4ea...87f4f07894
2
external/xtool
vendored
2
external/xtool
vendored
Submodule external/xtool updated: 22655f3e70...f12a84e960
@@ -1,34 +0,0 @@
|
|||||||
#include <metal_stdlib>
|
|
||||||
using namespace metal;
|
|
||||||
|
|
||||||
struct VertexOut {
|
|
||||||
float4 position [[position]];
|
|
||||||
float2 texCoord;
|
|
||||||
};
|
|
||||||
|
|
||||||
vertex VertexOut vertex_main(uint vertexID [[vertex_id]]) {
|
|
||||||
float2 pos[] = {
|
|
||||||
{-1.0, -1.0},
|
|
||||||
{ 1.0, -1.0},
|
|
||||||
{-1.0, 1.0},
|
|
||||||
{ 1.0, 1.0},
|
|
||||||
};
|
|
||||||
|
|
||||||
float2 uv[] = {
|
|
||||||
{0.0, 1.0},
|
|
||||||
{1.0, 1.0},
|
|
||||||
{0.0, 0.0},
|
|
||||||
{1.0, 0.0},
|
|
||||||
};
|
|
||||||
|
|
||||||
VertexOut out;
|
|
||||||
out.position = float4(pos[vertexID], 0.0, 1.0);
|
|
||||||
out.texCoord = uv[vertexID];
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
fragment float4 fragment_main(VertexOut in [[stage_in]],
|
|
||||||
texture2d<float> tex [[texture(0)]]) {
|
|
||||||
constexpr sampler s(filter::linear);
|
|
||||||
return pow(tex.sample(s, in.texCoord), 0.45f);
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
[[vk::binding(0)]]
|
|
||||||
RWTexture2D<float4> g_imageIn;
|
|
||||||
[[vk::binding(1)]]
|
|
||||||
RWTexture2D<float4> g_imageOut;
|
|
||||||
|
|
||||||
#define AGX_LOOK 2
|
|
||||||
|
|
||||||
float3 agxDefaultContrastApprox(float3 x) {
|
|
||||||
float3 x2 = x * x;
|
|
||||||
float3 x4 = x2 * x2;
|
|
||||||
|
|
||||||
return + 15.5 * x4 * x2
|
|
||||||
- 40.14 * x4 * x
|
|
||||||
+ 31.96 * x4
|
|
||||||
- 6.868 * x2 * x
|
|
||||||
+ 0.4298 * x2
|
|
||||||
+ 0.1191 * x
|
|
||||||
- 0.00232;
|
|
||||||
}
|
|
||||||
|
|
||||||
float3 agx(float3 val) {
|
|
||||||
const float3x3 agx_mat = float3x3(
|
|
||||||
0.842479062253094, 0.0423282422610123, 0.0423756549057051,
|
|
||||||
0.0784335999999992, 0.878468636469772, 0.0784336,
|
|
||||||
0.0792237451477643, 0.0791661274605434, 0.879142973793104);
|
|
||||||
|
|
||||||
const float min_ev = -12.47393f;
|
|
||||||
const float max_ev = 4.026069f;
|
|
||||||
|
|
||||||
val = mul(agx_mat, val);
|
|
||||||
|
|
||||||
val = clamp(log2(val), min_ev, max_ev);
|
|
||||||
val = (val - min_ev) / (max_ev - min_ev);
|
|
||||||
|
|
||||||
val = agxDefaultContrastApprox(val);
|
|
||||||
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
float3 agxEotf(float3 val) {
|
|
||||||
const float3x3 agx_mat_inv = float3x3(
|
|
||||||
1.19687900512017, -0.0528968517574562, -0.0529716355144438,
|
|
||||||
-0.0980208811401368, 1.15190312990417, -0.0980434501171241,
|
|
||||||
-0.0990297440797205, -0.0989611768448433, 1.15107367264116);
|
|
||||||
|
|
||||||
val = mul(agx_mat_inv, val);
|
|
||||||
val = pow(val, float3(2.2));
|
|
||||||
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
float3 agxLook(float3 val) {
|
|
||||||
float3 offset = float3(0.0);
|
|
||||||
float3 slope = float3(1.0);
|
|
||||||
float3 power = float3(1.0);
|
|
||||||
float sat = 1.0;
|
|
||||||
|
|
||||||
#if AGX_LOOK == 1
|
|
||||||
slope = float3(1.0, 0.9, 0.5);
|
|
||||||
power = float3(0.8);
|
|
||||||
sat = 0.8;
|
|
||||||
#elif AGX_LOOK == 2
|
|
||||||
slope = float3(1.0);
|
|
||||||
power = float3(1.35, 1.35, 1.35);
|
|
||||||
sat = 1.4;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ASC CDL
|
|
||||||
val = pow(val * slope + offset, power);
|
|
||||||
|
|
||||||
const float3 lw = float3(0.2126, 0.7152, 0.0722);
|
|
||||||
float luma = dot(val, lw);
|
|
||||||
|
|
||||||
return luma + sat * (val - luma);
|
|
||||||
}
|
|
||||||
|
|
||||||
[shader("compute")]
|
|
||||||
[numthreads(32,32,1)]
|
|
||||||
void main(uint3 threadId: SV_DispatchThreadID)
|
|
||||||
{
|
|
||||||
uint2 coord = threadId.xy;
|
|
||||||
float3 color = g_imageIn.Load(coord).xyz;
|
|
||||||
color = pow(color,2.2);
|
|
||||||
color = agx(color);
|
|
||||||
color = agxLook(color);
|
|
||||||
color = agxEotf(color);
|
|
||||||
color = pow(color,0.45);
|
|
||||||
color = clamp(color, 0, 1);
|
|
||||||
g_imageOut[coord] = float4(color,1);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
#include "fgui_rect_shared.slang"
|
|
||||||
|
|
||||||
[shader("fragment")]
|
|
||||||
float4 _main(
|
|
||||||
VertexOutput input,
|
|
||||||
uint triid: SV_PrimitiveID,
|
|
||||||
) : SV_TARGET
|
|
||||||
{
|
|
||||||
return float4(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
struct VertexOutput
|
|
||||||
{
|
|
||||||
float4 position: SV_Position;
|
|
||||||
}
|
|
||||||
#include "shader_base.h"
|
|
||||||
|
|
||||||
DECLARE_CONSTANTS()
|
|
||||||
{
|
|
||||||
uint2 resolution;
|
|
||||||
uint2 size;
|
|
||||||
int2 position;
|
|
||||||
float4 color;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#include "fgui_rect_shared.slang"
|
|
||||||
|
|
||||||
struct VertexInput
|
|
||||||
{
|
|
||||||
float2 position: POSITION;
|
|
||||||
};
|
|
||||||
|
|
||||||
[shader("vertex")]
|
|
||||||
VertexOutput _main(
|
|
||||||
VertexInput input,
|
|
||||||
)
|
|
||||||
{
|
|
||||||
VertexOutput output;
|
|
||||||
output.position = float4((input.position*size+position)/resolution*2-1, 0, 1.0f);
|
|
||||||
FIX_VERTEX_POSITION(output.position);
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#include "fgui_text_shared.slang"
|
|
||||||
|
|
||||||
[shader("fragment")]
|
|
||||||
float4 _main(
|
|
||||||
VertexOutput input,
|
|
||||||
uint triid: SV_PrimitiveID,
|
|
||||||
) : SV_TARGET
|
|
||||||
{
|
|
||||||
float dist = SampleTexture(font, (input.uv+glyphPos)*glyphSize).x;
|
|
||||||
float smoothing = 0.4;
|
|
||||||
float alpha = clamp(smoothstep(0.5-smoothing, 0.5+smoothing, dist),0,1);
|
|
||||||
return float4(fontColor.xyz, alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
struct VertexOutput
|
|
||||||
{
|
|
||||||
float4 position: SV_Position;
|
|
||||||
float2 uv: TEXCOORD0;
|
|
||||||
}
|
|
||||||
#include "shader_base.h"
|
|
||||||
|
|
||||||
DECLARE_CONSTANTS()
|
|
||||||
{
|
|
||||||
int2 resolution;
|
|
||||||
uint2 size;
|
|
||||||
int2 position;
|
|
||||||
float4 fontColor;
|
|
||||||
float2 glyphPos;
|
|
||||||
float2 glyphSize;
|
|
||||||
uint font;
|
|
||||||
};
|
|
||||||
|
|
||||||
DECLARE_TEXTURES(29);
|
|
||||||
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#include "fgui_text_shared.slang"
|
|
||||||
|
|
||||||
struct VertexInput
|
|
||||||
{
|
|
||||||
float2 position: POSITION;
|
|
||||||
float2 uv: TEXCOORD0;
|
|
||||||
};
|
|
||||||
|
|
||||||
[shader("vertex")]
|
|
||||||
VertexOutput _main(
|
|
||||||
VertexInput input,
|
|
||||||
)
|
|
||||||
{
|
|
||||||
VertexOutput output;
|
|
||||||
output.position = float4((input.position*size+position)/resolution*2-1, 0, 1.0f);
|
|
||||||
output.uv = input.uv;
|
|
||||||
FIX_VERTEX_POSITION(output.position);
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
#include "shader_base.h"
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#include "mesh_shared.slang"
|
|
||||||
|
|
||||||
|
|
||||||
[shader("fragment")]
|
|
||||||
float4 _main(
|
|
||||||
VertexOutput input,
|
|
||||||
uint triid: SV_PrimitiveID,
|
|
||||||
) : SV_TARGET
|
|
||||||
{
|
|
||||||
return float4(SampleTexture(albedoID, input.uv).xyz,1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
|
|
||||||
#include "mesh_raytracer_shared.slang"
|
|
||||||
|
|
||||||
[shader("raygeneration")]
|
|
||||||
void _main()
|
|
||||||
{
|
|
||||||
uint2 launchIndex = DispatchRaysIndex().xy;
|
|
||||||
uint8_t edgemask = inputMask.Load(uint3(launchIndex, 0));
|
|
||||||
uint8_t edgemask1 = inputMask.Load(uint3(launchIndex, 1));
|
|
||||||
uint8_t edgemask2 = inputMask.Load(uint3(launchIndex, 2));
|
|
||||||
uint8_t edgemask3 = inputMask.Load(uint3(launchIndex, 3));
|
|
||||||
uint8_t nBits = (countbits(edgemask) + countbits(edgemask1) + countbits(edgemask2) + countbits(edgemask3));
|
|
||||||
if ( nBits != 16 && nBits != 0 )
|
|
||||||
outputTest[launchIndex] = float4(1,0,0,0);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
struct RayPayload
|
|
||||||
{
|
|
||||||
bool bHit;
|
|
||||||
float fDistance;
|
|
||||||
};
|
|
||||||
|
|
||||||
#include "shader_base.slang"
|
|
||||||
|
|
||||||
DECLARE_CBUFFER(0)
|
|
||||||
{
|
|
||||||
float4x4 projection;
|
|
||||||
}
|
|
||||||
|
|
||||||
DECLARE_DATA(1, Texture2DMS<float> inputDepth;);
|
|
||||||
DECLARE_DATA(2, Texture2DMS<uint8_t> inputMask;);
|
|
||||||
DECLARE_DATA(3, RWTexture2D<float4> outputTest;);
|
|
||||||
|
|
||||||
DECLARE_TEXTURES(29)
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
struct VertexOutput
|
|
||||||
{
|
|
||||||
float4 position: SV_Position;
|
|
||||||
float2 uv: TEXCOORD0;
|
|
||||||
};
|
|
||||||
|
|
||||||
#include "shader_base.h"
|
|
||||||
DECLARE_CONSTANTS()
|
|
||||||
{
|
|
||||||
float4x4 modelMatrix;
|
|
||||||
uint albedoID;
|
|
||||||
uint roughnessID;
|
|
||||||
uint metalnessID;
|
|
||||||
};
|
|
||||||
|
|
||||||
DECLARE_CBUFFER(0)
|
|
||||||
{
|
|
||||||
float4x4 projection;
|
|
||||||
};
|
|
||||||
|
|
||||||
DECLARE_TEXTURES(1)
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#include "mesh_shared.slang"
|
|
||||||
|
|
||||||
struct VertexInput
|
|
||||||
{
|
|
||||||
float3 position: POSITION;
|
|
||||||
float2 uv: TEXCOORD0;
|
|
||||||
};
|
|
||||||
|
|
||||||
[shader("vertex")]
|
|
||||||
VertexOutput _main(
|
|
||||||
VertexInput input,
|
|
||||||
)
|
|
||||||
{
|
|
||||||
VertexOutput output;
|
|
||||||
output.position = mul(projection, mul(modelMatrix, float4(input.position,1)));
|
|
||||||
FIX_VERTEX_POSITION(output.position);
|
|
||||||
output.uv = input.uv;
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
#ifndef SHADER_BASE_SLANG
|
|
||||||
#define SHADER_BASE_SLANG
|
|
||||||
|
|
||||||
/*
|
|
||||||
* I hope you are not looking at these war crimes.
|
|
||||||
* They are truly horrible crimes.
|
|
||||||
* Don't even try to understand what the fuck is happening here.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(__METAL__)
|
|
||||||
/* We hijack all the argument buffers, which allows to use a bit more textures at cost of buffers */
|
|
||||||
#define DECLARE_TEXTURES(b) \
|
|
||||||
struct TextureBinding {Texture2D textures[96];}; \
|
|
||||||
[[vk::binding(21)]] ParameterBlock<TextureBinding> g_textures0 : register(t21); \
|
|
||||||
ParameterBlock<TextureBinding> g_textures1 : register(t22); \
|
|
||||||
ParameterBlock<TextureBinding> g_textures2 : register(t23); \
|
|
||||||
ParameterBlock<TextureBinding> g_textures3 : register(t24); \
|
|
||||||
ParameterBlock<TextureBinding> g_textures4 : register(t25); \
|
|
||||||
ParameterBlock<TextureBinding> g_textures5 : register(t26); \
|
|
||||||
ParameterBlock<TextureBinding> g_textures6 : register(t27); \
|
|
||||||
ParameterBlock<TextureBinding> g_textures7 : register(t28); \
|
|
||||||
float4 SampleTexture(uint32_t binding, float2 uv) \
|
|
||||||
{ \
|
|
||||||
SamplerState sampler = mlGetSampler(); \
|
|
||||||
uint8_t textureArray = 0; \
|
|
||||||
uint8_t textureSamplerArray = (binding >> 16) & 0xFF; \
|
|
||||||
uint8_t textureSampler = (binding >> 8) & 0xFF; \
|
|
||||||
uint8_t textureIndex = 1; \
|
|
||||||
return g_textures0.textures[1].Sample(sampler, uv); \
|
|
||||||
};
|
|
||||||
|
|
||||||
void _mlGetSampler()
|
|
||||||
{
|
|
||||||
__intrinsic_asm R"(
|
|
||||||
constexpr sampler s(filter::linear, address::repeat);
|
|
||||||
return s;
|
|
||||||
)";
|
|
||||||
}
|
|
||||||
SamplerState mlGetSampler()
|
|
||||||
{
|
|
||||||
_mlGetSampler();
|
|
||||||
};
|
|
||||||
|
|
||||||
#define DECLARE_CBUFFER(n) \
|
|
||||||
[[vk::binding(n)]] cbuffer cbuffer_##b : register(b##n)
|
|
||||||
|
|
||||||
#define DECLARE_CONSTANTS() \
|
|
||||||
[[vk::push_constant]] \
|
|
||||||
cbuffer cbuffer_constants : register(b29)
|
|
||||||
|
|
||||||
#define FIX_VERTEX_POSITION(g) g = float4(g.x, -g.y, g.z, g.w);
|
|
||||||
|
|
||||||
#elif defined(__SPIRV__)
|
|
||||||
|
|
||||||
#define DECLARE_TEXTURES(n) \
|
|
||||||
[[vk::binding(n)]] \
|
|
||||||
Sampler2D g_textures[]; \
|
|
||||||
float4 SampleTexture(uint32_t binding, float2 uv) \
|
|
||||||
{ \
|
|
||||||
return g_textures[binding].Sample(uv); \
|
|
||||||
};
|
|
||||||
|
|
||||||
#define DECLARE_CBUFFER(b) \
|
|
||||||
[[vk::binding(b)]] \
|
|
||||||
cbuffer cbuffer_##b
|
|
||||||
|
|
||||||
|
|
||||||
#define DECLARE_DATA(b,r) \
|
|
||||||
[[vk::binding(b)]] \
|
|
||||||
r
|
|
||||||
|
|
||||||
#define DECLARE_CONSTANTS()
|
|
||||||
[[vk::push_constant]] \
|
|
||||||
cbuffer cbuffer_constants
|
|
||||||
|
|
||||||
#define FIX_VERTEX_POSITION(x)
|
|
||||||
|
|
||||||
#else
|
|
||||||
#define DECLARE_TEXTURES()
|
|
||||||
float4 SampleTexture(uint32_t binding, float2 uv);
|
|
||||||
#define DECLARE_CBUFFER() cbuffer cbuffer_constants
|
|
||||||
#define DECLARE_DATA() cbuffer cbuffer_constants
|
|
||||||
#define DECLARE_CONSTANTS() cbuffer cbuffer_constants
|
|
||||||
#define FIX_VERTEX_POSITION(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#ifndef SHADER_BASE_SLANG
|
|
||||||
#define SHADER_BASE_SLANG
|
|
||||||
|
|
||||||
/*
|
|
||||||
* I hope you are not looking at these war crimes.
|
|
||||||
* They are truly horrible crimes.
|
|
||||||
* Don't even try to understand what the fuck is happening here.
|
|
||||||
*/
|
|
||||||
#define DECLARE_TEXTURES(n) \
|
|
||||||
[[vk::binding(n)]] \
|
|
||||||
Sampler2D g_textures[]; \
|
|
||||||
float4 SampleTexture(uint32_t binding, float2 uv) { return g_textures[binding].Sample(uv); };
|
|
||||||
|
|
||||||
#define DECLARE_CBUFFER(b) [[vk::binding(b)]] cbuffer cbuffer_##b
|
|
||||||
|
|
||||||
|
|
||||||
#define DECLARE_DATA(b, r) [[vk::binding(b)]] r
|
|
||||||
|
|
||||||
#define DECLARE_CONSTANTS [[vk::push_constant]] cbuffer cbuffer_constants
|
|
||||||
|
|
||||||
#define FIX_VERTEX_POSITION(x)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"class": "mesh",
|
|
||||||
"model": "test_map.fmesh",
|
|
||||||
"material": "test_map.fmat",
|
|
||||||
"physics": "test_map.fmesh",
|
|
||||||
"position": [0, 0, 0],
|
|
||||||
"rotation": [1, 0, 0, 0]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"class": "point_light",
|
|
||||||
"position": [100, 0, 0]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
Binary file not shown.
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"mesh": "game/core/meshes/cube.fmesh_c",
|
"Mesh": "game/core/meshes/cube.fmesh_c",
|
||||||
"material": "game/core/materials/cube.fmat"
|
"Material": "game/core/materials/cube.fmat",
|
||||||
|
"Physics": "game/core/physics/cube.fpx"
|
||||||
}
|
}
|
||||||
|
|||||||
4
funnyassets/physics/cube.fpx
Normal file
4
funnyassets/physics/cube.fpx
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"Type": "Sphere",
|
||||||
|
"Radius": "1.0"
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"classname" "worldspawn"
|
|
||||||
{
|
|
||||||
( 0 0 0 ) ( 256 0 0 ) ( 256 256 0 ) ( 0 0 ) ( 1 0 ) ( 1 1 ) BRICK1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
"classname" "light"
|
|
||||||
"origin" "128 128 96"
|
|
||||||
"light" "400"
|
|
||||||
}
|
|
||||||
@@ -9,8 +9,7 @@
|
|||||||
#define MAX_TEXTURE_COUNT 4096
|
#define MAX_TEXTURE_COUNT 4096
|
||||||
#define MAX_SHADER_COUNT 1024
|
#define MAX_SHADER_COUNT 1024
|
||||||
|
|
||||||
#define MAX_PHYSICAL_MESH_COUNT 1024
|
#define MAX_PHYSICS_COUNT 1024
|
||||||
#define MAX_PHYSICAL_MATERIAL_COUNT 512
|
|
||||||
|
|
||||||
template<typename T, uint32_t nCount>
|
template<typename T, uint32_t nCount>
|
||||||
class CAssetArc
|
class CAssetArc
|
||||||
@@ -89,13 +88,9 @@ public:
|
|||||||
virtual FunnyMaterial_t *GetMaterialByIndex( HFunnyMaterial hMat ) override;
|
virtual FunnyMaterial_t *GetMaterialByIndex( HFunnyMaterial hMat ) override;
|
||||||
virtual void UnrefMaterial( HFunnyMaterial hMat ) override;
|
virtual void UnrefMaterial( HFunnyMaterial hMat ) override;
|
||||||
|
|
||||||
virtual HFunnyPhysicalMesh LoadPhysicalMesh( const char *szName ) override;
|
virtual HFunnyPhysics LoadPhysics( const char *szName ) override;
|
||||||
virtual FunnyPhysicalMesh_t *GetPhysicalMeshByIndex( HFunnyPhysicalMesh hPhysicalMesh ) override;
|
virtual FunnyPhysics_t *GetPhysicsByIndex( HFunnyPhysics hPhysics ) override;
|
||||||
virtual void UnrefPhysicalMesh( HFunnyPhysicalMesh hPhysicalMesh ) override;
|
virtual void UnrefPhysics( HFunnyPhysics hPhysics ) override;
|
||||||
|
|
||||||
virtual HFunnyPhysicalMaterial LoadPhysicalMaterial( const char *szName ) override;
|
|
||||||
virtual FunnyPhysicalMaterial_t *GetPhysicalMaterialByIndex( HFunnyPhysicalMaterial hPhysicalMaterial ) override;
|
|
||||||
virtual void UnrefPhysicalMaterial( HFunnyPhysicalMaterial hPhysicalMaterial ) override;
|
|
||||||
|
|
||||||
uint32_t LoadShader( const char *szName );
|
uint32_t LoadShader( const char *szName );
|
||||||
IShader **GetShaderByIndex( uint32_t hShader );
|
IShader **GetShaderByIndex( uint32_t hShader );
|
||||||
@@ -105,6 +100,7 @@ public:
|
|||||||
CAssetArc<FunnyMesh_t, MAX_MESH_COUNT> m_meshes = {};
|
CAssetArc<FunnyMesh_t, MAX_MESH_COUNT> m_meshes = {};
|
||||||
CAssetArc<FunnyMaterial_t, MAX_MATERIAL_COUNT> m_materials = {};
|
CAssetArc<FunnyMaterial_t, MAX_MATERIAL_COUNT> m_materials = {};
|
||||||
CAssetArc<IShader*, MAX_SHADER_COUNT> m_shaders = {};
|
CAssetArc<IShader*, MAX_SHADER_COUNT> m_shaders = {};
|
||||||
|
CAssetArc<FunnyPhysics_t, MAX_PHYSICS_COUNT> m_physics = {};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -163,12 +159,15 @@ uint32_t CAssetManager::LoadModel( const char *szName )
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
IJSONValue *pMesh = pMainObject->GetValue("mesh");
|
IJSONValue *pMesh = pMainObject->GetValue("Mesh");
|
||||||
IJSONValue *pMaterial = pMainObject->GetValue("material");
|
IJSONValue *pMaterial = pMainObject->GetValue("Material");
|
||||||
|
IJSONValue *pPhysics = pMainObject->GetValue("Physics");
|
||||||
if (pMesh)
|
if (pMesh)
|
||||||
pModel->m_hMesh = LoadMesh(pMesh->GetStringValue());
|
pModel->m_hMesh = LoadMesh(pMesh->GetStringValue());
|
||||||
if (pMaterial)
|
if (pMaterial)
|
||||||
pModel->m_hMaterial = LoadMaterial(pMaterial->GetStringValue());
|
pModel->m_hMaterial = LoadMaterial(pMaterial->GetStringValue());
|
||||||
|
if (pPhysics)
|
||||||
|
pModel->m_hPhysics = LoadPhysics(pPhysics->GetStringValue());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -290,6 +289,7 @@ uint32_t CAssetManager::LoadShader( const char *szName )
|
|||||||
if ( pShader == NULL )
|
if ( pShader == NULL )
|
||||||
{
|
{
|
||||||
V_printf("Failed to load %s\n", szName);
|
V_printf("Failed to load %s\n", szName);
|
||||||
|
m_shaders.UnrefObject(hShader);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*ppShader = pShader;
|
*ppShader = pShader;
|
||||||
@@ -298,40 +298,73 @@ uint32_t CAssetManager::LoadShader( const char *szName )
|
|||||||
|
|
||||||
void CAssetManager::UnrefShader( uint32_t uIndex )
|
void CAssetManager::UnrefShader( uint32_t uIndex )
|
||||||
{
|
{
|
||||||
|
m_shaders.UnrefObject(uIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
HFunnyPhysicalMesh CAssetManager::LoadPhysicalMesh( const char *szName )
|
|
||||||
|
HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
||||||
{
|
{
|
||||||
|
bool bHasBeenCreated = false;
|
||||||
|
HFunnyPhysics hPhysics = m_physics.GetOrCreateObject(szName, &bHasBeenCreated);
|
||||||
|
if (!bHasBeenCreated)
|
||||||
|
return hPhysics;
|
||||||
|
FunnyPhysics_t *pPhysics = m_physics.GetObjectPtr(hPhysics);
|
||||||
|
|
||||||
}
|
IFileHandle *pHandle = filesystem->Open(szName, FILEMODE_READ);
|
||||||
|
if (!pHandle)
|
||||||
|
return 0;
|
||||||
|
CUtlString szProperties = filesystem->ReadString(pHandle);
|
||||||
|
IJSONValue *pRoot = JSONManager()->ReadString(szProperties);
|
||||||
|
if (!pRoot)
|
||||||
|
return 0;
|
||||||
|
|
||||||
FunnyPhysicalMesh_t *CAssetManager::GetPhysicalMeshByIndex( HFunnyPhysicalMesh hPhysicalMesh )
|
IJSONObject *pMainObject;
|
||||||
|
switch (pRoot->GetType())
|
||||||
{
|
{
|
||||||
|
case JSON_PARAMETER_OBJECT:
|
||||||
}
|
|
||||||
|
|
||||||
void CAssetManager::UnrefPhysicalMesh( HFunnyPhysicalMesh hPhysicalMesh )
|
|
||||||
{
|
{
|
||||||
|
pMainObject = pRoot->GetObject();
|
||||||
}
|
if (!pMainObject)
|
||||||
|
|
||||||
|
|
||||||
HFunnyPhysicalMaterial CAssetManager::LoadPhysicalMaterial( const char *szName )
|
|
||||||
{
|
{
|
||||||
|
V_printf("Failed to load properties\n");
|
||||||
|
m_physics.UnrefObject(hPhysics);
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
IJSONValue *pTypeValue = pMainObject->GetValue("Type");
|
||||||
FunnyPhysicalMaterial_t *CAssetManager::GetPhysicalMaterialByIndex( HFunnyPhysicalMaterial hPhysicalMaterial )
|
if (!pTypeValue)
|
||||||
{
|
{
|
||||||
|
V_printf("\"Type\" must be specified\n");
|
||||||
|
m_physics.UnrefObject(hPhysics);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
CUtlString szType = pTypeValue->GetStringValue();
|
||||||
void CAssetManager::UnrefPhysicalMaterial( HFunnyPhysicalMaterial hPhysicalMaterial )
|
if (szType == "Sphere")
|
||||||
{
|
{
|
||||||
|
pPhysics->m_hShape = g_pPhysics->CreateBall({1.0});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return hPhysics;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hPhysics;
|
||||||
|
}
|
||||||
|
|
||||||
|
FunnyPhysics_t *CAssetManager::GetPhysicsByIndex( HFunnyPhysics hPhysics )
|
||||||
|
{
|
||||||
|
return m_physics.GetObjectPtr(hPhysics);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAssetManager::UnrefPhysics( HFunnyPhysics hPhysics )
|
||||||
|
{
|
||||||
|
m_physics.UnrefObject(hPhysics);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static CAssetManager s_assetmgr;
|
static CAssetManager s_assetmgr;
|
||||||
|
|||||||
@@ -10,8 +10,7 @@
|
|||||||
|
|
||||||
typedef uint32_t HFunnyMaterial;
|
typedef uint32_t HFunnyMaterial;
|
||||||
typedef uint32_t HFunnyMesh;
|
typedef uint32_t HFunnyMesh;
|
||||||
typedef uint32_t HFunnyPhysicalMesh;
|
typedef uint32_t HFunnyPhysics;
|
||||||
typedef uint32_t HFunnyPhysicalMaterial;
|
|
||||||
typedef uint32_t HFunnyModel;
|
typedef uint32_t HFunnyModel;
|
||||||
|
|
||||||
struct FunnyMaterial_t
|
struct FunnyMaterial_t
|
||||||
@@ -26,11 +25,7 @@ struct FunnyMesh_t
|
|||||||
IMesh *m_pMesh;
|
IMesh *m_pMesh;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FunnyPhysicalMaterial_t
|
struct FunnyPhysics_t
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
struct FunnyPhysicalMesh_t
|
|
||||||
{
|
{
|
||||||
HShape m_hShape;
|
HShape m_hShape;
|
||||||
};
|
};
|
||||||
@@ -39,8 +34,7 @@ struct FunnyModel_t
|
|||||||
{
|
{
|
||||||
HFunnyMesh m_hMesh;
|
HFunnyMesh m_hMesh;
|
||||||
HFunnyMaterial m_hMaterial;
|
HFunnyMaterial m_hMaterial;
|
||||||
HFunnyPhysicalMesh m_hPhysicalMesh;
|
HFunnyPhysics m_hPhysics;
|
||||||
HFunnyPhysicalMaterial m_hPhysicalMaterial;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -59,17 +53,11 @@ public:
|
|||||||
virtual FunnyMaterial_t *GetMaterialByIndex( HFunnyMaterial hMat ) = 0;
|
virtual FunnyMaterial_t *GetMaterialByIndex( HFunnyMaterial hMat ) = 0;
|
||||||
virtual void UnrefMaterial( HFunnyMaterial hMat ) = 0;
|
virtual void UnrefMaterial( HFunnyMaterial hMat ) = 0;
|
||||||
|
|
||||||
virtual HFunnyPhysicalMesh LoadPhysicalMesh( const char *szName ) = 0;
|
virtual HFunnyPhysics LoadPhysics( const char *szName ) = 0;
|
||||||
virtual FunnyPhysicalMesh_t *GetPhysicalMeshByIndex( HFunnyPhysicalMesh hPhysicalMesh ) = 0;
|
virtual FunnyPhysics_t *GetPhysicsByIndex( HFunnyPhysics hPhysics ) = 0;
|
||||||
virtual void UnrefPhysicalMesh( HFunnyPhysicalMesh hPhysicalMesh ) = 0;
|
virtual void UnrefPhysics( HFunnyPhysics hPhysics ) = 0;
|
||||||
|
|
||||||
virtual HFunnyPhysicalMaterial LoadPhysicalMaterial( const char *szName ) = 0;
|
|
||||||
virtual FunnyPhysicalMaterial_t *GetPhysicalMaterialByIndex( HFunnyPhysicalMaterial hPhysicalMaterial ) = 0;
|
|
||||||
virtual void UnrefPhysicalMaterial( HFunnyPhysicalMaterial hPhysicalMaterial ) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern IAssetManager *g_pAssetManager;
|
extern IAssetManager *g_pAssetManager;
|
||||||
|
|
||||||
#define ASSET_MANAGER_INTERFACE_VERSION "AssetMgr001"
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -22,11 +22,16 @@ void C_BaseEntity::Spawn()
|
|||||||
{
|
{
|
||||||
Precache();
|
Precache();
|
||||||
SetAbsOrigin({0, 0, 0});
|
SetAbsOrigin({0, 0, 0});
|
||||||
SetAbsAngles(0, 0, 0);
|
SetAbsQAngles(0, 0, 0);
|
||||||
SetScale(1);
|
SetScale(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void C_BaseEntity::SetAbsAngles( float fPitch, float fYaw, float fRoll )
|
void C_BaseEntity::SetAbsAngles( Quat vQuat )
|
||||||
|
{
|
||||||
|
m_vRotation = vQuat;
|
||||||
|
}
|
||||||
|
|
||||||
|
void C_BaseEntity::SetAbsQAngles( float fPitch, float fYaw, float fRoll )
|
||||||
{
|
{
|
||||||
versor q;
|
versor q;
|
||||||
glm_euler_yzx_quat((vec3){fPitch, fYaw, fRoll}, q);
|
glm_euler_yzx_quat((vec3){fPitch, fYaw, fRoll}, q);
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ public:
|
|||||||
virtual void Precache();
|
virtual void Precache();
|
||||||
virtual void Spawn();
|
virtual void Spawn();
|
||||||
|
|
||||||
virtual void SetAbsAngles( float fPitch, float fYaw, float fRoll );
|
virtual void SetAbsAngles( Quat vQuat );
|
||||||
|
virtual void SetAbsQAngles( float fPitch, float fYaw, float fRoll );
|
||||||
virtual void SetAbsOrigin( Vector origin );
|
virtual void SetAbsOrigin( Vector origin );
|
||||||
virtual void SetScale( float fScale );
|
virtual void SetScale( float fScale );
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ void C_BaseModelEntity::Think( float fDelta )
|
|||||||
|
|
||||||
void C_BaseModelEntity::SetModel( const char *szName )
|
void C_BaseModelEntity::SetModel( const char *szName )
|
||||||
{
|
{
|
||||||
if (m_uModelIndex)
|
if (m_hModelHandle)
|
||||||
{
|
{
|
||||||
g_pAssetManager->UnrefModel(m_uModelIndex);
|
g_pAssetManager->UnrefModel(m_hModelHandle);
|
||||||
}
|
}
|
||||||
m_uModelIndex = g_pAssetManager->LoadModel(szName);
|
m_hModelHandle = g_pAssetManager->LoadModel(szName);
|
||||||
m_pModel = g_pAssetManager->GetModelByIndex(m_uModelIndex);
|
m_pModel = g_pAssetManager->GetModelByIndex(m_hModelHandle);
|
||||||
|
|
||||||
FunnyMesh_t *pMesh = g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh);
|
FunnyMesh_t *pMesh = g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh);
|
||||||
m_pInstance = g_pWorldRenderer->CreateInstance(pMesh->m_pMesh);
|
m_pInstance = g_pWorldRenderer->CreateInstance(pMesh->m_pMesh);
|
||||||
@@ -35,7 +35,7 @@ C_BaseModelEntity::~C_BaseModelEntity()
|
|||||||
{
|
{
|
||||||
FunnyMesh_t *pMesh = g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh);
|
FunnyMesh_t *pMesh = g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh);
|
||||||
g_pWorldRenderer->DestroyMeshInstance(pMesh->m_pMesh, m_pInstance);
|
g_pWorldRenderer->DestroyMeshInstance(pMesh->m_pMesh, m_pInstance);
|
||||||
g_pAssetManager->UnrefModel(m_uModelIndex);
|
g_pAssetManager->UnrefModel(m_hModelHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN_DATADESC(C_BaseModelEntity)
|
BEGIN_DATADESC(C_BaseModelEntity)
|
||||||
|
|||||||
@@ -16,8 +16,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
IFileSystem *filesystem;
|
IFileSystem *filesystem;
|
||||||
|
|
||||||
IRenderContext *g_pRenderContext;
|
IRenderContext *g_pRenderContext;
|
||||||
IGameWindow *g_pMainWindow;
|
IGameWindow *g_pMainWindow;
|
||||||
|
|
||||||
static CEngineVars s_vars;
|
static CEngineVars s_vars;
|
||||||
CEngineVars *g_pEngineVars = &s_vars;
|
CEngineVars *g_pEngineVars = &s_vars;
|
||||||
EngineConsts_t *g_pEngineConstants;
|
EngineConsts_t *g_pEngineConstants;
|
||||||
@@ -25,6 +27,9 @@ EngineConsts_t *g_pEngineConstants;
|
|||||||
INetworkBase *g_pServerBridge;
|
INetworkBase *g_pServerBridge;
|
||||||
INetworkBase *g_pServerConnection;
|
INetworkBase *g_pServerConnection;
|
||||||
|
|
||||||
|
IPhysics *g_pPhysics;
|
||||||
|
IPhysicsWorld *g_pPhysicsWorld;
|
||||||
|
|
||||||
class CFunnyGameBridge: public IEngineBridge
|
class CFunnyGameBridge: public IEngineBridge
|
||||||
{
|
{
|
||||||
virtual void Init() override;
|
virtual void Init() override;
|
||||||
@@ -70,6 +75,10 @@ void CFunnyGameBridge::Init()
|
|||||||
};
|
};
|
||||||
g_pServerBridge->SendPacket({&join, sizeof(join)});
|
g_pServerBridge->SendPacket({&join, sizeof(join)});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CreateInterfaceFn fnPhysicsFactory = Sys_GetFactory("RapierPhysics");
|
||||||
|
g_pPhysics = (IPhysics*)fnPhysicsFactory(PHYSICS_INTERFACE_VERSION, NULL);
|
||||||
|
g_pPhysicsWorld = g_pPhysics->CreateWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFunnyGameBridge::Tick( float fDelta )
|
void CFunnyGameBridge::Tick( float fDelta )
|
||||||
|
|||||||
@@ -0,0 +1,257 @@
|
|||||||
|
#include "assetmgr.h"
|
||||||
|
#include "tier2/ifilesystem.h"
|
||||||
|
#include "tier2/fileformats/json.h"
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
|
#define MAX_MODEL_COUNT 2048
|
||||||
|
#define MAX_MESH_COUNT 2048
|
||||||
|
#define MAX_MATERIAL_COUNT 2048
|
||||||
|
#define MAX_TEXTURE_COUNT 4096
|
||||||
|
#define MAX_SHADER_COUNT 1024
|
||||||
|
|
||||||
|
#define MAX_PHYSICS_COUNT 1024
|
||||||
|
|
||||||
|
template<typename T, uint32_t nCount>
|
||||||
|
class CAssetArc
|
||||||
|
{
|
||||||
|
struct ObjectHandle_t
|
||||||
|
{
|
||||||
|
CUtlString m_szName;
|
||||||
|
uint32_t m_uUsageCount;
|
||||||
|
T *m_pObject;
|
||||||
|
};
|
||||||
|
ObjectHandle_t m_objects[nCount] = {};
|
||||||
|
public:
|
||||||
|
uint32_t GetOrCreateObject( const char *szName, bool *pbHasBeenCreated )
|
||||||
|
{
|
||||||
|
uint32_t uFoundIndex = 1;
|
||||||
|
for ( uint32_t u = 1; u < nCount; u++ )
|
||||||
|
{
|
||||||
|
if (m_objects[u].m_pObject == NULL)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (m_objects[u].m_szName == szName)
|
||||||
|
{
|
||||||
|
m_objects[u].m_uUsageCount++;
|
||||||
|
if (pbHasBeenCreated)
|
||||||
|
*pbHasBeenCreated = false;
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for ( auto &m: m_objects)
|
||||||
|
{
|
||||||
|
if (m.m_pObject == NULL)
|
||||||
|
break;
|
||||||
|
uFoundIndex++;
|
||||||
|
}
|
||||||
|
m_objects[uFoundIndex].m_szName = szName;
|
||||||
|
m_objects[uFoundIndex].m_uUsageCount++;
|
||||||
|
m_objects[uFoundIndex].m_pObject = (T*)V_malloc(sizeof(T));
|
||||||
|
if (pbHasBeenCreated)
|
||||||
|
*pbHasBeenCreated = true;
|
||||||
|
return uFoundIndex;
|
||||||
|
}
|
||||||
|
T *GetObjectPtr( uint32_t uIndex )
|
||||||
|
{
|
||||||
|
if (uIndex >= nCount)
|
||||||
|
return 0;
|
||||||
|
return m_objects[uIndex].m_pObject;
|
||||||
|
}
|
||||||
|
void UnrefObject( uint32_t uIndex )
|
||||||
|
{
|
||||||
|
if (uIndex >= nCount)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_objects[uIndex].m_uUsageCount--;
|
||||||
|
if (m_objects[uIndex].m_uUsageCount == 0)
|
||||||
|
{
|
||||||
|
V_free(m_objects[uIndex].m_pObject);
|
||||||
|
m_objects[uIndex].m_pObject = NULL;
|
||||||
|
m_objects[uIndex].m_szName = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class CAssetManager: public IAssetManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual HFunnyModel LoadModel( const char *szName ) override;
|
||||||
|
virtual FunnyModel_t *GetModelByIndex( HFunnyModel hModel ) override;
|
||||||
|
virtual void UnrefModel( HFunnyModel uIndex ) override;
|
||||||
|
|
||||||
|
virtual HFunnyMesh LoadMesh( const char *szName ) override;
|
||||||
|
virtual FunnyMesh_t *GetMeshByIndex( HFunnyMesh hMesh ) override;
|
||||||
|
virtual void UnrefMesh( HFunnyMesh hMesh ) override;
|
||||||
|
|
||||||
|
virtual HFunnyMaterial LoadMaterial( const char *szName ) override;
|
||||||
|
virtual FunnyMaterial_t *GetMaterialByIndex( HFunnyMaterial hMat ) override;
|
||||||
|
virtual void UnrefMaterial( HFunnyMaterial hMat ) override;
|
||||||
|
|
||||||
|
virtual HFunnyPhysics LoadPhysics( const char *szName ) override;
|
||||||
|
virtual FunnyPhysics_t *GetPhysicsByIndex( HFunnyPhysics hPhysics ) override;
|
||||||
|
virtual void UnrefPhysics( HFunnyPhysics hPhysics ) override;
|
||||||
|
|
||||||
|
CAssetArc<FunnyModel_t, MAX_MODEL_COUNT> m_models = {};
|
||||||
|
CAssetArc<FunnyPhysics_t, MAX_PHYSICS_COUNT> m_physics = {};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
FunnyModel_t *CAssetManager::GetModelByIndex( uint32_t uIndex )
|
||||||
|
{
|
||||||
|
return m_models.GetObjectPtr(uIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
FunnyMaterial_t *CAssetManager::GetMaterialByIndex( uint32_t uIndex )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
FunnyMesh_t *CAssetManager::GetMeshByIndex( uint32_t uIndex )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t CAssetManager::LoadModel( const char *szName )
|
||||||
|
{
|
||||||
|
bool bHasBeenCreated = false;
|
||||||
|
HFunnyModel hModel = m_models.GetOrCreateObject(szName, &bHasBeenCreated);
|
||||||
|
if (!bHasBeenCreated)
|
||||||
|
return hModel;
|
||||||
|
|
||||||
|
FunnyModel_t *pModel = m_models.GetObjectPtr(hModel);
|
||||||
|
|
||||||
|
IFileHandle *pHandle = filesystem->Open(szName, FILEMODE_READ);
|
||||||
|
if (!pHandle)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
CUtlString szProperties = filesystem->ReadString(pHandle);
|
||||||
|
IJSONValue *pRoot = JSONManager()->ReadString(szProperties);
|
||||||
|
filesystem->Close(pHandle);
|
||||||
|
|
||||||
|
if (!pRoot)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
IJSONObject *pMainObject;
|
||||||
|
CUtlString szMeshData;
|
||||||
|
IVertexBuffer *pVertices;
|
||||||
|
switch (pRoot->GetType())
|
||||||
|
{
|
||||||
|
case JSON_PARAMETER_OBJECT:
|
||||||
|
{
|
||||||
|
pMainObject = pRoot->GetObject();
|
||||||
|
if (!pMainObject)
|
||||||
|
{
|
||||||
|
V_printf("Failed to load properties\n");
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
IJSONValue *pPhysics = pMainObject->GetValue("Physics");
|
||||||
|
if (pPhysics)
|
||||||
|
pModel->m_hPhysics = LoadPhysics(pPhysics->GetStringValue());
|
||||||
|
|
||||||
|
return hModel;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAssetManager::UnrefModel( uint32_t uIndex )
|
||||||
|
{
|
||||||
|
m_models.UnrefObject(uIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t CAssetManager::LoadMaterial( const char *szName )
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAssetManager::UnrefMaterial( uint32_t uIndex )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
HFunnyMesh CAssetManager::LoadMesh( const char *szName )
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
void CAssetManager::UnrefMesh( uint32_t uIndex )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
||||||
|
{
|
||||||
|
bool bHasBeenCreated = false;
|
||||||
|
HFunnyPhysics hPhysics = m_physics.GetOrCreateObject(szName, &bHasBeenCreated);
|
||||||
|
if (!bHasBeenCreated)
|
||||||
|
return hPhysics;
|
||||||
|
FunnyPhysics_t *pPhysics = m_physics.GetObjectPtr(hPhysics);
|
||||||
|
|
||||||
|
IFileHandle *pHandle = filesystem->Open(szName, FILEMODE_READ);
|
||||||
|
if (!pHandle)
|
||||||
|
return 0;
|
||||||
|
CUtlString szProperties = filesystem->ReadString(pHandle);
|
||||||
|
IJSONValue *pRoot = JSONManager()->ReadString(szProperties);
|
||||||
|
if (!pRoot)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
IJSONObject *pMainObject;
|
||||||
|
switch (pRoot->GetType())
|
||||||
|
{
|
||||||
|
case JSON_PARAMETER_OBJECT:
|
||||||
|
{
|
||||||
|
pMainObject = pRoot->GetObject();
|
||||||
|
if (!pMainObject)
|
||||||
|
{
|
||||||
|
V_printf("Failed to load properties\n");
|
||||||
|
m_physics.UnrefObject(hPhysics);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
IJSONValue *pTypeValue = pMainObject->GetValue("Type");
|
||||||
|
if (!pTypeValue)
|
||||||
|
{
|
||||||
|
V_printf("\"Type\" must be specified\n");
|
||||||
|
m_physics.UnrefObject(hPhysics);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
CUtlString szType = pTypeValue->GetStringValue();
|
||||||
|
if (szType == "Sphere")
|
||||||
|
{
|
||||||
|
pPhysics->m_hShape = g_pPhysics->CreateBall({1.0});
|
||||||
|
}
|
||||||
|
|
||||||
|
return hPhysics;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hPhysics;
|
||||||
|
}
|
||||||
|
|
||||||
|
FunnyPhysics_t *CAssetManager::GetPhysicsByIndex( HFunnyPhysics hPhysics )
|
||||||
|
{
|
||||||
|
return m_physics.GetObjectPtr(hPhysics);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAssetManager::UnrefPhysics( HFunnyPhysics hPhysics )
|
||||||
|
{
|
||||||
|
m_physics.UnrefObject(hPhysics);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static CAssetManager s_assetmgr;
|
||||||
|
IAssetManager *g_pAssetManager = &s_assetmgr;
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
#ifndef ASSET_MANAGER_H
|
||||||
|
#define ASSET_MANAGER_H
|
||||||
|
|
||||||
|
#include "datamap.h"
|
||||||
|
#include "iphysics.h"
|
||||||
|
#include "tier1/utlstring.h"
|
||||||
|
|
||||||
|
typedef uint32_t HFunnyMaterial;
|
||||||
|
typedef uint32_t HFunnyMesh;
|
||||||
|
typedef uint32_t HFunnyPhysics;
|
||||||
|
typedef uint32_t HFunnyModel;
|
||||||
|
|
||||||
|
struct FunnyMaterial_t
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FunnyMesh_t
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FunnyPhysics_t
|
||||||
|
{
|
||||||
|
HShape m_hShape;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FunnyModel_t
|
||||||
|
{
|
||||||
|
HFunnyPhysics m_hPhysics;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class IAssetManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual HFunnyModel LoadModel( const char *szName ) = 0;
|
||||||
|
virtual FunnyModel_t *GetModelByIndex( HFunnyModel hModel ) = 0;
|
||||||
|
virtual void UnrefModel( HFunnyModel uIndex ) = 0;
|
||||||
|
|
||||||
|
virtual HFunnyMesh LoadMesh( const char *szName ) = 0;
|
||||||
|
virtual FunnyMesh_t *GetMeshByIndex( HFunnyMesh hMesh ) = 0;
|
||||||
|
virtual void UnrefMesh( HFunnyMesh hMesh ) = 0;
|
||||||
|
|
||||||
|
virtual HFunnyMaterial LoadMaterial( const char *szName ) = 0;
|
||||||
|
virtual FunnyMaterial_t *GetMaterialByIndex( HFunnyMaterial hMat ) = 0;
|
||||||
|
virtual void UnrefMaterial( HFunnyMaterial hMat ) = 0;
|
||||||
|
|
||||||
|
virtual HFunnyPhysics LoadPhysics( const char *szName ) = 0;
|
||||||
|
virtual FunnyPhysics_t *GetPhysicsByIndex( HFunnyPhysics hPhysics ) = 0;
|
||||||
|
virtual void UnrefPhysics( HFunnyPhysics hPhysics ) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern IAssetManager *g_pAssetManager;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -21,9 +21,17 @@ void CBaseEntity::Precache()
|
|||||||
void CBaseEntity::Spawn()
|
void CBaseEntity::Spawn()
|
||||||
{
|
{
|
||||||
Precache();
|
Precache();
|
||||||
|
SetAbsOrigin({0, 0, 0});
|
||||||
|
SetAbsQAngles(0, 0, 0);
|
||||||
|
SetScale(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBaseEntity::SetAbsAngles( float fPitch, float fYaw, float fRoll )
|
void CBaseEntity::SetAbsAngles( Quat vQuat )
|
||||||
|
{
|
||||||
|
m_vRotation = vQuat;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CBaseEntity::SetAbsQAngles( float fPitch, float fYaw, float fRoll )
|
||||||
{
|
{
|
||||||
versor q;
|
versor q;
|
||||||
glm_euler_yzx_quat((vec3){fPitch, fYaw, fRoll}, q);
|
glm_euler_yzx_quat((vec3){fPitch, fYaw, fRoll}, q);
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ public:
|
|||||||
virtual void Precache();
|
virtual void Precache();
|
||||||
virtual void Spawn();
|
virtual void Spawn();
|
||||||
|
|
||||||
virtual void SetAbsAngles( float fPitch, float fYaw, float fRoll );
|
virtual void SetAbsAngles( Quat vQuat );
|
||||||
|
virtual void SetAbsQAngles( float fPitch, float fYaw, float fRoll );
|
||||||
virtual void SetAbsOrigin( Vector origin );
|
virtual void SetAbsOrigin( Vector origin );
|
||||||
virtual void SetScale( float fScale );
|
virtual void SetScale( float fScale );
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
#include "basemodelentity.h"
|
#include "basemodelentity.h"
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
void CBaseModelEntity::Spawn()
|
void CBaseModelEntity::SetModel( const char *szName )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBaseModelEntity::Precache()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,18 +9,7 @@ class CBaseModelEntity: public CBaseEntity
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_CLASS(CBaseModelEntity, CBaseEntity);
|
DECLARE_CLASS(CBaseModelEntity, CBaseEntity);
|
||||||
virtual void Spawn() override;
|
virtual void SetModel( const char *szName );
|
||||||
virtual void Precache() override;
|
|
||||||
|
|
||||||
void SetModel( const char *szName );
|
|
||||||
private:
|
|
||||||
|
|
||||||
HFunnyModel m_hModelHandle;
|
|
||||||
FunnyModel_t *m_pModel;
|
|
||||||
|
|
||||||
HShape m_hShape;
|
|
||||||
HCollider m_hCollider;
|
|
||||||
IPhysicsBody *m_pBody;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,9 +17,12 @@ DECLARE_BUILD_STAGE(Server)
|
|||||||
compileProject.m_szName = "server";
|
compileProject.m_szName = "server";
|
||||||
compileProject.files = {
|
compileProject.files = {
|
||||||
"game.cpp",
|
"game.cpp",
|
||||||
|
"assetmgr.cpp",
|
||||||
|
|
||||||
"entitysystem.cpp",
|
"entitysystem.cpp",
|
||||||
"baseentity.cpp",
|
"baseentity.cpp",
|
||||||
"basemodelentity.cpp",
|
"basemodelentity.cpp",
|
||||||
|
"physicsprop.cpp",
|
||||||
|
|
||||||
"milmoba/player.cpp",
|
"milmoba/player.cpp",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -129,6 +129,11 @@ void CEntitySystem::Think()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
// Purpose: Sends packets to clients.
|
||||||
|
// Since we are running this on server we can't really accept any packet.
|
||||||
|
// We only allow packets from the entities sent by a client
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
void CEntitySystem::NetThink( INetworkBase *pBase )
|
void CEntitySystem::NetThink( INetworkBase *pBase )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,14 @@
|
|||||||
|
|
||||||
|
|
||||||
IFileSystem *filesystem;
|
IFileSystem *filesystem;
|
||||||
|
|
||||||
IRenderContext *g_pRenderContext;
|
IRenderContext *g_pRenderContext;
|
||||||
IGameWindow *g_pMainWindow;
|
IGameWindow *g_pMainWindow;
|
||||||
|
|
||||||
static CEngineVars s_vars;
|
static CEngineVars s_vars;
|
||||||
CEngineVars *g_pEngineVars = &s_vars;
|
CEngineVars *g_pEngineVars = &s_vars;
|
||||||
EngineConsts_t *g_pEngineConstants;
|
EngineConsts_t *g_pEngineConstants;
|
||||||
|
|
||||||
INetworkBase *g_pClientBridge;
|
INetworkBase *g_pClientBridge;
|
||||||
INetworkBase *g_pPublicConnection;
|
INetworkBase *g_pPublicConnection;
|
||||||
INetworkBase *g_pCurrentConnection;
|
INetworkBase *g_pCurrentConnection;
|
||||||
@@ -211,6 +214,7 @@ void CFunnyGameBridge::Shutdown()
|
|||||||
#define CONNECT_INTERFACE(szName, pGlobal) if (!V_strcmp(psz, szName)) { pGlobal = (typeof(pGlobal))pInterface; return; }
|
#define CONNECT_INTERFACE(szName, pGlobal) if (!V_strcmp(psz, szName)) { pGlobal = (typeof(pGlobal))pInterface; return; }
|
||||||
void CFunnyGameBridge::ConnectInterface( const char *psz, void *pInterface )
|
void CFunnyGameBridge::ConnectInterface( const char *psz, void *pInterface )
|
||||||
{
|
{
|
||||||
|
CONNECT_INTERFACE(FILESYSTEM_INTERFACE_VERSION, filesystem);
|
||||||
CONNECT_INTERFACE("EngineConstants", g_pEngineConstants)
|
CONNECT_INTERFACE("EngineConstants", g_pEngineConstants)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,15 +5,14 @@
|
|||||||
|
|
||||||
void CMOBAPlayer::Spawn()
|
void CMOBAPlayer::Spawn()
|
||||||
{
|
{
|
||||||
|
SetModel("game/core/models/cube.fmdl");
|
||||||
SetThink(Think);
|
SetThink(Think);
|
||||||
m_fTimer = 0;
|
m_fTimer = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void CMOBAPlayer::Think( float fDelta )
|
void CMOBAPlayer::Think( float fDelta )
|
||||||
{
|
{
|
||||||
m_fTimer += 1.0/60.0;
|
BaseClass::Think(fDelta);
|
||||||
SetAbsOrigin({m_fTimer, 0, 0});
|
|
||||||
SetAbsAngles(glm_rad(90), m_fTimer, 0);
|
|
||||||
SetScale(1);
|
SetScale(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef MILMOBA_PLAYER_H
|
#ifndef MILMOBA_PLAYER_H
|
||||||
#define MILMOBA_PLAYER_H
|
#define MILMOBA_PLAYER_H
|
||||||
#include "basemodelentity.h"
|
|
||||||
|
|
||||||
|
#include "basemodelentity.h"
|
||||||
|
|
||||||
class CMOBAPlayer: public CBaseModelEntity
|
class CMOBAPlayer: public CBaseModelEntity
|
||||||
{
|
{
|
||||||
@@ -12,8 +12,6 @@ public:
|
|||||||
|
|
||||||
virtual void Spawn( void ) override;
|
virtual void Spawn( void ) override;
|
||||||
void Think( float fDelta );
|
void Think( float fDelta );
|
||||||
|
|
||||||
float m_fTimer;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
#include "physicsprop.h"
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
|
|
||||||
|
void CPhysicsProp::Precache()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPhysicsProp::Spawn()
|
||||||
|
{
|
||||||
|
SetThink(Think);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPhysicsProp::Think( float fDelta )
|
||||||
|
{
|
||||||
|
SetAbsOrigin(m_pBody->GetPosition());
|
||||||
|
SetAbsAngles(m_pBody->GetRotation());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPhysicsProp::SetModel( const char *szName )
|
||||||
|
{
|
||||||
|
if (m_hModel)
|
||||||
|
{
|
||||||
|
g_pAssetManager->UnrefModel(m_hModel);
|
||||||
|
}
|
||||||
|
m_hModel = g_pAssetManager->LoadModel(szName);
|
||||||
|
m_pModel = g_pAssetManager->GetModelByIndex(m_hModel);
|
||||||
|
m_pPhysics = g_pAssetManager->GetPhysicsByIndex(m_pModel->m_hPhysics);
|
||||||
|
m_hCollider = g_pPhysics->CreateCollider(m_pPhysics->m_hShape);
|
||||||
|
m_pBody = g_pPhysicsWorld->CreateRigidBody(m_hCollider, k_EPhysics_Dynamic);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPhysicsProp::EnableMovement()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPhysicsProp::DisableMovement()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,19 @@ friend CBaseModelEntity;
|
|||||||
public:
|
public:
|
||||||
DECLARE_CLASS(CPhysicsProp, CBaseModelEntity);
|
DECLARE_CLASS(CPhysicsProp, CBaseModelEntity);
|
||||||
virtual void Spawn() override;
|
virtual void Spawn() override;
|
||||||
|
virtual void Precache() override;
|
||||||
|
|
||||||
|
virtual void SetModel( const char *szName ) override;
|
||||||
virtual void EnableMovement();
|
virtual void EnableMovement();
|
||||||
virtual void DisableMovement();
|
virtual void DisableMovement();
|
||||||
|
|
||||||
|
void Think( float fDelta );
|
||||||
|
private:
|
||||||
|
HFunnyModel m_hModel;
|
||||||
|
FunnyModel_t *m_pModel;
|
||||||
|
FunnyPhysics_t *m_pPhysics;
|
||||||
|
HCollider m_hCollider;
|
||||||
|
IPhysicsBody *m_pBody;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define GAME_H
|
#define GAME_H
|
||||||
#include "tier2/ifilesystem.h"
|
#include "tier2/ifilesystem.h"
|
||||||
#include "materialsystem/imaterialsystem.h"
|
#include "materialsystem/imaterialsystem.h"
|
||||||
|
#include "iphysics.h"
|
||||||
extern IRenderContext *g_pRenderContext;
|
extern IRenderContext *g_pRenderContext;
|
||||||
extern IFileSystem *filesystem;
|
extern IFileSystem *filesystem;
|
||||||
extern IGameWindowManager *g_pWindowManager;
|
extern IGameWindowManager *g_pWindowManager;
|
||||||
@@ -15,6 +16,9 @@ public:
|
|||||||
|
|
||||||
extern CEngineVars *g_pEngineVars;
|
extern CEngineVars *g_pEngineVars;
|
||||||
|
|
||||||
|
extern IPhysics *g_pPhysics;
|
||||||
|
extern IPhysicsWorld *g_pPhysicsWorld;
|
||||||
|
|
||||||
#define FUNNY_SECURE_PORT 27015
|
#define FUNNY_SECURE_PORT 27015
|
||||||
#define FUNNY_QUERY_PORT 27016
|
#define FUNNY_QUERY_PORT 27016
|
||||||
|
|
||||||
|
|||||||
@@ -114,9 +114,9 @@ DECLARE_VULKAN_COMMAND(SetViewport)
|
|||||||
{
|
{
|
||||||
VkViewport v = {
|
VkViewport v = {
|
||||||
fX,
|
fX,
|
||||||
fY,
|
fY+fHeight,
|
||||||
fWidth,
|
fWidth,
|
||||||
fHeight,
|
-fHeight,
|
||||||
fDepthMin,
|
fDepthMin,
|
||||||
fDepthMax
|
fDepthMax
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ abstract_class IPhysicsBody
|
|||||||
public:
|
public:
|
||||||
virtual void SetPosition( Vector vPosition ) = 0;
|
virtual void SetPosition( Vector vPosition ) = 0;
|
||||||
virtual void SetRotation( Quat vRotation ) = 0;
|
virtual void SetRotation( Quat vRotation ) = 0;
|
||||||
|
virtual Vector GetPosition() = 0;
|
||||||
|
virtual Quat GetRotation() = 0;
|
||||||
virtual void SetGravityScale( float fScale ) = 0;
|
virtual void SetGravityScale( float fScale ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,9 @@
|
|||||||
|
|
||||||
#include "physics.h"
|
#include "physics.h"
|
||||||
#define PHYSICS_OBJECT_DEFINED
|
#define PHYSICS_OBJECT_DEFINED
|
||||||
|
#define TRIG_H
|
||||||
#include "iphysics.h"
|
#include "iphysics.h"
|
||||||
|
#include "tier0/lib.h"
|
||||||
#include "tier1/interface.h"
|
#include "tier1/interface.h"
|
||||||
|
|
||||||
class CRapierPhysicsBody: public IPhysicsBody
|
class CRapierPhysicsBody: public IPhysicsBody
|
||||||
@@ -20,14 +22,28 @@ public:
|
|||||||
|
|
||||||
virtual void SetRotation( Quat vRotation ) override
|
virtual void SetRotation( Quat vRotation ) override
|
||||||
{
|
{
|
||||||
|
CRapierPhysicsBody_SetRotation(m_pBody, vRotation.x, vRotation.y, vRotation.z, vRotation.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void SetGravityScale( float fScale ) override
|
virtual void SetGravityScale( float fScale ) override
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
RapierPhysicsBody_t *m_pBody;
|
|
||||||
|
|
||||||
|
virtual Vector GetPosition() override
|
||||||
|
{
|
||||||
|
return CRapierPhysicsBody_GetPosition(m_pBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual Quat GetRotation() override
|
||||||
|
{
|
||||||
|
return CRapierPhysicsBody_GetRotation(m_pBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RapierPhysicsBody_t *m_pBody = NULL;
|
||||||
|
|
||||||
};
|
};
|
||||||
class CRapierPhysicsWorld: public IPhysicsWorld
|
class CRapierPhysicsWorld: public IPhysicsWorld
|
||||||
@@ -58,7 +74,7 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RapierWorld_t *m_pWorld;
|
RapierWorld_t *m_pWorld = NULL;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CRapierPhysics: public IPhysics
|
class CRapierPhysics: public IPhysics
|
||||||
@@ -109,7 +125,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
RapierPhysics_t *m_pRustHandle;
|
RapierPhysics_t *m_pRustHandle = NULL;
|
||||||
};
|
};
|
||||||
|
|
||||||
EXPOSE_INTERFACE(CRapierPhysics, IPhysics, PHYSICS_INTERFACE_VERSION)
|
EXPOSE_INTERFACE(CRapierPhysics, IPhysics, PHYSICS_INTERFACE_VERSION)
|
||||||
|
|||||||
@@ -20,6 +20,19 @@ typedef struct RapierShape_t RapierShape_t;
|
|||||||
|
|
||||||
typedef struct RapierWorld_t RapierWorld_t;
|
typedef struct RapierWorld_t RapierWorld_t;
|
||||||
|
|
||||||
|
typedef struct Vector {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float z;
|
||||||
|
} Vector;
|
||||||
|
|
||||||
|
typedef struct Quat {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float z;
|
||||||
|
float w;
|
||||||
|
} Quat;
|
||||||
|
|
||||||
typedef struct BallShape_t {
|
typedef struct BallShape_t {
|
||||||
float m_fRadius;
|
float m_fRadius;
|
||||||
} BallShape_t;
|
} BallShape_t;
|
||||||
@@ -34,11 +47,21 @@ typedef struct CuboidShape_t {
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
struct Vector CRapierPhysicsBody_GetPosition(struct RapierPhysicsBody_t *this_);
|
||||||
|
|
||||||
|
struct Quat CRapierPhysicsBody_GetRotation(struct RapierPhysicsBody_t *this_);
|
||||||
|
|
||||||
void CRapierPhysicsBody_SetPosition(struct RapierPhysicsBody_t *this_,
|
void CRapierPhysicsBody_SetPosition(struct RapierPhysicsBody_t *this_,
|
||||||
float fX,
|
float fX,
|
||||||
float fY,
|
float fY,
|
||||||
float fZ);
|
float fZ);
|
||||||
|
|
||||||
|
void CRapierPhysicsBody_SetRotation(struct RapierPhysicsBody_t *this_,
|
||||||
|
float fX,
|
||||||
|
float fY,
|
||||||
|
float fZ,
|
||||||
|
float fW);
|
||||||
|
|
||||||
struct RapierPhysicsBody_t *CRapierPhysicsWorld_CreateRigidBody(struct RapierWorld_t *this_,
|
struct RapierPhysicsBody_t *CRapierPhysicsWorld_CreateRigidBody(struct RapierWorld_t *this_,
|
||||||
struct RapierCollider_t *pCollider,
|
struct RapierCollider_t *pCollider,
|
||||||
enum EPhysicsBodyType eType);
|
enum EPhysicsBodyType eType);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ macro_rules! V_malloc {
|
|||||||
use std::{default, ptr::{self, null}, sync::Arc};
|
use std::{default, ptr::{self, null}, sync::Arc};
|
||||||
|
|
||||||
use parry3d::{glamx::vec3, shape::{Shape, ShapeType, SharedShape}};
|
use parry3d::{glamx::vec3, shape::{Shape, ShapeType, SharedShape}};
|
||||||
use rapier3d::{geometry::Ball};
|
use rapier3d::{geometry::Ball, na::{UnitQuaternion, Vector4}};
|
||||||
use rapier3d::prelude::*;
|
use rapier3d::prelude::*;
|
||||||
use libc::{malloc, free};
|
use libc::{malloc, free};
|
||||||
|
|
||||||
@@ -93,26 +93,67 @@ pub struct RapierPhysics_t
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn CRapierPhysicsBody_SetPosition( this: *mut RapierPhysicsBody_t, fX: f32, fY: f32, fZ: f32 )
|
pub unsafe extern "C" fn CRapierPhysicsBody_SetPosition( this: *mut RapierPhysicsBody_t, fX: f32, fY: f32, fZ: f32 )
|
||||||
{
|
{
|
||||||
let world: &mut RapierWorld_t = &mut *(*this).m_pWorld;
|
let world: &mut RapierWorld_t = &mut *(*this).m_pWorld;
|
||||||
world.m_rigidBodies[(*this).m_hRigidBodyHandle]
|
world.m_rigidBodies[(*this).m_hRigidBodyHandle]
|
||||||
.set_translation(vec3(fX, fY, fZ), true);
|
.set_translation(vec3(fX, fY, fZ), true);
|
||||||
print!("{} {} {}\n", fX, fY, fZ);
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn CRapierPhysicsBody_SetRotation( this: *mut RapierPhysicsBody_t, fX: f32, fY: f32, fZ: f32, fW: f32 )
|
||||||
|
{
|
||||||
|
let world: &mut RapierWorld_t = &mut *(*this).m_pWorld;
|
||||||
|
world.m_rigidBodies[(*this).m_hRigidBodyHandle]
|
||||||
|
.set_translation(vec3(fX, fY, fZ), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct Vector {
|
||||||
|
x: f32,
|
||||||
|
y: f32,
|
||||||
|
z: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn CRapierPhysicsBody_GetPosition( this: *mut RapierPhysicsBody_t ) -> Vector
|
||||||
|
{
|
||||||
|
let world: &mut RapierWorld_t = &mut *(*this).m_pWorld;
|
||||||
|
let position = world.m_rigidBodies[(*this).m_hRigidBodyHandle]
|
||||||
|
.translation().to_array();
|
||||||
|
return Vector { x: position[0], y: position[1], z: position[2]}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct Quat {
|
||||||
|
x: f32,
|
||||||
|
y: f32,
|
||||||
|
z: f32,
|
||||||
|
w: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn CRapierPhysicsBody_GetRotation( this: *mut RapierPhysicsBody_t ) -> Quat
|
||||||
|
{
|
||||||
|
let world: &mut RapierWorld_t = &mut *(*this).m_pWorld;
|
||||||
|
let rotationVector = world.m_rigidBodies[(*this).m_hRigidBodyHandle]
|
||||||
|
.rotation().to_array();
|
||||||
|
Quat{ x: rotationVector[0], y: rotationVector[1], z: rotationVector[2], w: rotationVector[3]}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn CRapierPhysicsWorld_Frame( this: *mut RapierWorld_t, fDelta: f32 )
|
pub unsafe extern "C" fn CRapierPhysicsWorld_Frame( this: *mut RapierWorld_t, fDelta: f32 )
|
||||||
{
|
{
|
||||||
let gravity = vec3(0.0, -9.81, 0.0);
|
let vGravity = vec3(0.0, -9.8, 0.0);
|
||||||
let mut integrationParameters = IntegrationParameters::default();
|
let mut integrationParameters = IntegrationParameters::default();
|
||||||
integrationParameters.dt = fDelta;
|
integrationParameters.dt = fDelta;
|
||||||
let mut physicsPipeline = PhysicsPipeline::new();
|
let mut physicsPipeline = PhysicsPipeline::new();
|
||||||
let physicsHooks = ();
|
let physicsHooks = ();
|
||||||
let eventHandler = ();
|
let eventHandler = ();
|
||||||
physicsPipeline.step(
|
physicsPipeline.step(
|
||||||
gravity,
|
vGravity,
|
||||||
&integrationParameters,
|
&integrationParameters,
|
||||||
&mut (*this).m_islandManager,
|
&mut (*this).m_islandManager,
|
||||||
&mut (*this).m_broadPhase,
|
&mut (*this).m_broadPhase,
|
||||||
@@ -125,10 +166,6 @@ pub unsafe extern "C" fn CRapierPhysicsWorld_Frame( this: *mut RapierWorld_t, fD
|
|||||||
&physicsHooks,
|
&physicsHooks,
|
||||||
&eventHandler,
|
&eventHandler,
|
||||||
);
|
);
|
||||||
for (h, b) in (*this).m_colliders.iter()
|
|
||||||
{
|
|
||||||
print!("{:?}\n",b.position())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
@@ -207,12 +244,8 @@ pub unsafe extern "C" fn CRapierPhysics_CreateCollider( this: *mut RapierPhysics
|
|||||||
{
|
{
|
||||||
let pRapierShape = (*pShape).m_pShape;
|
let pRapierShape = (*pShape).m_pShape;
|
||||||
let shape: &SharedShape = &(*pShape).m_sharedShape;
|
let shape: &SharedShape = &(*pShape).m_sharedShape;
|
||||||
let rapierCollider = ColliderBuilder::new(shape.clone()).build();
|
|
||||||
let collider = RapierCollider_t {
|
|
||||||
m_collider: rapierCollider,
|
|
||||||
};
|
|
||||||
let pCollider = V_malloc!(RapierCollider_t, 1);
|
let pCollider = V_malloc!(RapierCollider_t, 1);
|
||||||
*pCollider = collider;
|
std::ptr::write(&mut (*pCollider).m_collider, ColliderBuilder::new(shape.clone()).build());
|
||||||
pCollider
|
pCollider
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user