introduces ios support? still needs metal

This commit is contained in:
2025-06-29 01:21:55 +03:00
parent af4f0c3cad
commit cdeaac7c0c
79 changed files with 2176 additions and 1349 deletions

9
Entitlemenets.plist Normal file
View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- Example: Enable push notifications -->
<key>aps-environment</key>
<string>development</string>
</dict>
</plist>

55
build.c
View File

@@ -1,55 +0,0 @@
#include "god/build.h"
#include "god/utils.h"
#define GAME_NAME "funnygame"
char* include_dirs[] = {
"public",
"external/cglm/include",
"external/Vulkan-Headers/include",
"external/VulkanMemoryAllocator/include",
"external/stb",
NULL,
};
#include "tier0/__build.c"
#include "tier1/__build.c"
#include "fgui/__build.c"
#include "rapier/__build.c"
#include "engine/__build.c"
#include "game/server/__build.c"
#include "game/client/__build.c"
#include "launcher/__build.c"
#include "funnyassets/__build.c"
int build(struct build_data b) {
trace = 1;
makedir("build/"GAME_NAME"/game/" GAME_NAME);
makedir("build/"GAME_NAME"/game/" GAME_NAME "/bin");
makedir("build/"GAME_NAME"/game/bin/");
tier0_build(b);
tier1_build(b);
fgui_build(b);
rapier_build(b);
engine_build(b);
launcher_build(b);
server_build(b);
client_build(b);
if (step("noassets"))
{
assets_build(b);
}
mv("build", "tools");
if (step("run")!=STEP_FAILED)
{
struct run_project rp = run_new("build/"GAME_NAME"/game/bin/"GAME_NAME);
run_run(&rp);
}
return 0;
};

View File

@@ -1,5 +1,6 @@
#include "target.h"
#include "tier1/utlstring.h"
#include "tier1/utlstring.h"
#include "helper.h"
CUtlVector<CUtlString> all_IncludeDirectories = {
"public",
@@ -7,17 +8,34 @@ CUtlVector<CUtlString> all_IncludeDirectories = {
"external/Vulkan-Headers/include",
"external/VulkanMemoryAllocator/include",
"external/stb",
"external/SDL/include",
};
auto szTarget = Target_t::DefaultTarget().GetTriplet();
auto szOutputDir = CUtlString("build/funnygame/%s/game",szTarget.GetString());
bool bStaticBuild = false;
extern "C" void Preinit()
{
if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_IOS)
bStaticBuild = true;
};
CUtlString tier0_lib;
CUtlString engine_lib;
CUtlString server_lib;
CUtlString client_lib;
#include "tier0/__build.cpp"
#include "tier1/__build.cpp"
#include "rapier/__build.cpp"
#include "engine/__build.cpp"
#include "launcher/__build.cpp"
#include "game/server/__build.cpp"
#include "game/client/__build.cpp"
#include "rapier/__build.cpp"
#include "engine/__build.cpp"
#include "funnyassets/__build.cpp"
#include "launcher/__build.cpp"

View File

@@ -1,75 +0,0 @@
#include "god/build.h"
#include "god/c.h"
#include "god/ld.h"
#include "god/utils.h"
char *engine_lib;
char *engine_implib;
void engine_build(struct build_data b)
{
char *szVideoFile = "engine/vk_videosdl.cpp";
char* files[] = {
"engine/console.cpp",
"engine/filesystem.cpp",
"engine/server.cpp",
"engine/engine.cpp",
/* rendering */
"engine/vk_video.cpp",
"engine/vk_mesh.cpp",
szVideoFile,
/* entities */
"engine/baseentity.cpp",
"engine/level.cpp",
"engine/brush.cpp",
/* server */
"engine/sv_worldspawn.cpp",
"engine/sv_light.cpp",
/* client */
"engine/cl_worldspawn.cpp",
"engine/cl_light.cpp",
NULL,
};
struct project p = {
.b = &b,
.files = files,
.name = "engine",
};
struct project o = C_compile(p, (struct C_settings){
.generation_flags = C_GENERATION_FLAGS_PIC,
.compile_flags = C_COMPILE_FLAGS_WALL,
.include_dirs = include_dirs,
});
add_item(&o.files, tier1_lib);
add_item(&o.files, rapierLib);
char *szVulkan = (char*)1;
char *szws2 = (char*)1;
if (b.kernel==BUILD_KERNEL_WINDOWS)
{
szVulkan="vulkan-1";
szws2="ws2_32";
}
if (b.kernel==BUILD_KERNEL_LINUX)
{
szVulkan="vulkan";
}
char* libs[] = {
"c",
"SDL3",
szVulkan,
NULL,
};
engine_lib = ld_link_project(o, (struct link_settings){
.type = LINK_TYPE_DYNAMIC,
.libs = libs,
});
mv("build/"GAME_NAME"/game/bin",engine_lib);
}

View File

@@ -29,8 +29,6 @@ CUtlVector<CUtlString> engine_CompiledFiles = {
/* rendering */
"engine/vk_videosdl.cpp",
"engine/vk_video.cpp",
"engine/vk_mesh.cpp",
"engine/vk_postprocessing.cpp",
/* io */
"engine/input.cpp",
@@ -40,11 +38,14 @@ CUtlVector<CUtlString> engine_CompiledFiles = {
CUtlVector<CUtlString> engine_Libraries = {
"c",
"SDL3",
"vulkan",
};
int engine_build()
{
if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_DARWIN)
engine_Libraries.AppendTail("MoltenVK");
if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_LINUX)
engine_Libraries.AppendTail("vulkan");
CCProject compileProject = {};
CLDProject ldProject = {};
@@ -53,19 +54,27 @@ int engine_build()
compileProject.includeDirectories = all_IncludeDirectories;
compileProject.bFPIC = true;
ldProject = compileProject.Compile();
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
ldProject.libraries = engine_Libraries;
ldProject.objects.AppendTail((CObject){tier1_lib});
ldProject.objects.AppendTail((CObject){rapier_lib});
if (bStaticBuild)
ldProject.linkType = ELINK_STATIC_LIBRARY;
else
{
ldProject.objects.AppendTail((CObject){tier1_lib});
ldProject.objects.AppendTail((CObject){rapier_lib});
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
}
CUtlString outputProject = ldProject.Link();
if (!bStaticBuild)
{
IFileSystem2::MakeDirectory(CUtlString("%s/bin",szOutputDir.GetString()));
IFileSystem2::CopyFile(CUtlString("%s/bin", szOutputDir.GetString()), outputProject);
} else {
engine_lib = outputProject;
}
const char *szGameName = ICommandLine::ParamValue("-game");
if (szGameName == NULL)
szGameName = "funnygame";
IFileSystem2::MakeDirectory(CUtlString("build/%s/game/bin",szGameName));
IFileSystem2::CopyFile(CUtlString("build/%s/game/bin",szGameName), outputProject);
return 0;

View File

@@ -30,7 +30,7 @@ void CBrushEntity::Spawn()
}
/* use them */
px_collider_params params = {};
params.friction = 0.6;
params.friction = 0.0;
m_collider = px_trimesh((Point<float>*)triangles.GetMemory(), triangles.GetSize(), (uint32_t(*)[3])indicies.GetMemory(), indicies.GetSize()/3 ,params);
px_fixedbody(px, m_collider);
};
@@ -65,10 +65,11 @@ void C_BrushEntity::Spawn()
float uv[2];
};
pAlbedo = ITextureManager::LoadTexture("textures/bricks.png");
CBrushEntity* pBrushEntity = (CBrushEntity*)pEntity;
uint32_t numVertices = 15*pBrushEntity->m_mesh.GetSize();
vertexBuffer = IRenderer::CreateVertexBuffer(numVertices*4);
Vertex_t *pTriangles = (Vertex_t*)vertexBuffer->Map();
uint32_t i = 0;
for (auto &triangle: pBrushEntity->m_mesh)
@@ -91,10 +92,6 @@ void C_BrushEntity::Spawn()
i+=3;
}
vertexBuffer->Unmap();
mesh = IMeshRenderer::CreateMesh();
mesh->SetVertexBuffer(vertexBuffer);
};
void C_BrushEntity::Destroy()
@@ -103,7 +100,6 @@ void C_BrushEntity::Destroy()
}
void C_BrushEntity::Think( float fDelta )
{
material.m.albedo = ITextureManager::GetTexture(pAlbedo);
mat4 matrix;
glm_mat4_zero(matrix);
for (int i = 0; i < 9; i++) {
@@ -113,8 +109,48 @@ void C_BrushEntity::Think( float fDelta )
matrix[3][0] = pEntity->m_position[0];
matrix[3][1] = pEntity->m_position[1];
matrix[3][2] = pEntity->m_position[2];
mesh->SetMatrix(matrix);
mesh->SetMaterial(&material);
mesh->Draw();
};
IGraphicsPipeline *g_BrushPipeline;
class CBrushRendering: public IRenderingPipelineStep
{
public:
virtual void Init() override;
virtual void Frame( float fDelta ) override;
virtual void Deinit() override;
private:
};
DECLARE_MESH_RENDERING_STAGE(CBrushRendering, brush_rasterizer);
CUtlVector<IVertexBuffer*> g_BrushVertices;
void CBrushRendering::Init()
{
V_printf("cool\n");
IRenderer::CreateGraphicsPipeline(
{
{"shaders/brush_vert.spv", SHADER_TYPE_VERTEX},
{"shaders/brush_frag.spv", SHADER_TYPE_FRAGMENT},
},
{}, 64,
{EImageFormat::IMAGE_FORMAT_R8G8B8A8}
);
};
void CBrushRendering::Frame( float fDelta )
{
V_printf("cooll\n");
IRenderer::ResetState();
IRenderer::SetDepthMode(DEPTH_MODE_LESS_EQUAL);
IRenderer::BindPipeline(g_BrushPipeline);
for (auto &vertices: g_BrushVertices)
{
IRenderer::Draw(vertices, 0);
}
};
void CBrushRendering::Deinit()
{
};

View File

@@ -1,4 +1,5 @@
#include "console.h"
#include "filesystem.h"
#include "tier1/utlstring.h"
#include "tier1/utlvector.h"
@@ -64,33 +65,43 @@ void IConsole::Execute2( CUtlVector<CUtlString> &args )
(cmd->GetCallback())(args.GetSize(), strbuffer);
}
void IConsole::Execute( void )
{
CUtlVector<CUtlVector<CUtlString>> commands = ParseCommandLine(g_commandBuffer);
g_commandBuffer = 0;
for (auto &command: commands)
{
IConsole::Execute2(command);
}
}
//-----------------------------------------------------------------------------
// Parses command buffer.
//-----------------------------------------------------------------------------
void IConsole::Execute( void )
{
CUtlVector<CUtlVector<CUtlString>> IConsole::ParseCommandLine( CUtlString psz )
{
CUtlVector<CUtlString> arguments;
CUtlVector<CUtlVector<CUtlString>> commands;
CUtlString szArgument;
bool bIsQuote = false;
for (auto &c: (CUtlVector<char>&)g_commandBuffer)
for ( auto &c: (CUtlVector<char>&)psz )
{
if (c == '\"')
if ( c == '\"' )
{
bIsQuote = !bIsQuote;
continue;
}
if (c == ';' || c == '\n' || c == '\0')
if ( c == ';' || c == '\n' )
{
if (bIsQuote)
{
if (c != '\0')
szArgument.AppendTail(c);
continue;
}
if (szArgument != 0)
arguments.AppendTail(szArgument);
IConsole::Execute2(arguments);
if ( arguments.GetSize() > 0 )
commands.AppendTail(arguments);
szArgument = 0;
arguments = {};
continue;
@@ -110,7 +121,11 @@ void IConsole::Execute( void )
}
szArgument.AppendTail(c);
};
g_commandBuffer = 0;
if (szArgument != 0)
arguments.AppendTail(szArgument);
if ( arguments.GetSize() > 0 )
commands.AppendTail(arguments);
return commands;
}
void IConsole::AddCommand( const char *psz )
@@ -232,3 +247,23 @@ ConCommandFn ConCommand::GetCallback( void )
{
return m_callback;
}
void IConsole_Exec( int argc, char **argv)
{
if (argc != 2)
return;
FileHandle_t f = IFileSystem::Open(argv[1], IFILE_READ);
if (!f)
return;
CUtlBuffer<char> b(IFileSystem::Size(f)+1);
IFileSystem::Read(f, b, b.GetSize());
b[IFileSystem::Size(f)] = 0;
IConsole::AddCommand(b);
IConsole::AddCommand(";");
IConsole::Execute();
}
ConCommand IConsole_ExecCmd("exec", IConsole_Exec);

View File

@@ -54,7 +54,7 @@ void IEngine_Signal(int sig)
break;
};
IEngine::Shutdown();
_exit(0);
Plat_Exit(0);
};
//-----------------------------------------------------------------------------
@@ -88,8 +88,14 @@ void IEngine::Init()
IVideo::Init();
IInput::Init();
IInput::SetMouseMode(MOUSE_MODE_GAME);
}
IServer::LoadGame("funnygame");
IConsole::AddCommand("exec default.cfg;");
IConsole::Execute();
};
//-----------------------------------------------------------------------------

View File

@@ -44,6 +44,10 @@ public:
static void AddFile( const char *psz );
};
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void IFileSystem::InitFilesystem()
{
fs_basedir = ICommandLine::ParamValue("-basedir");
@@ -59,6 +63,10 @@ void IFileSystem::InitFilesystem()
AddGameDirectory(fs_gamedir);
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CFileSystem::AddFile( const char *psz )
{
CUtlString extension = Plat_GetExtension(psz);
@@ -68,6 +76,9 @@ void CFileSystem::AddFile( const char *psz )
};
}
//-----------------------------------------------------------------------------
// Adds directory which can contain pack files
//-----------------------------------------------------------------------------
void IFileSystem::AddGameDirectory( const char *psz )
{
FileDirectory_t dir = {};
@@ -81,6 +92,10 @@ void IFileSystem::AddGameDirectory( const char *psz )
};
};
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
bool IFileSystem::LoadPackFile( const char *szFilename )
{
Pack_t pack = {};
@@ -109,10 +124,6 @@ bool IFileSystem::LoadPackFile( const char *szFilename )
pack.handle = f;
pack.files = CUtlVector<PackDirectory_t>(nNumFiles);
V_memcpy(pack.files.GetData(),pDirs, header.size);
for (auto &i: pack.files)
{
V_printf(" LOADED %s\n",i.name);
}
V_free(pDirs);
nNumFiles = header.size/sizeof(PackDirectory_t);
@@ -124,10 +135,19 @@ bool IFileSystem::LoadPackFile( const char *szFilename )
return true;
}
//-----------------------------------------------------------------------------
// Creates path
//-----------------------------------------------------------------------------
void IFileSystem::CreatePath( const char *szPath )
{
}
//-----------------------------------------------------------------------------
// Opens file
// If it is located in a pack then it can only be read
//-----------------------------------------------------------------------------
FileHandle_t IFileSystem::Open( const char *szFilename, EFileOptions options )
{
if (options == IFILE_READ)
@@ -172,6 +192,9 @@ FileHandle_t IFileSystem::Open( const char *szFilename, EFileOptions options )
return 0;
}
//-----------------------------------------------------------------------------
// Closes file
//-----------------------------------------------------------------------------
void IFileSystem::Close( FileHandle_t file )
{
/* close only fs files */
@@ -182,10 +205,18 @@ void IFileSystem::Close( FileHandle_t file )
delete file;
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
size_t IFileSystem::Size( FileHandle_t file )
{
return file->nSize;
}
//-----------------------------------------------------------------------------
// Reads nSize bytes of file
//-----------------------------------------------------------------------------
size_t IFileSystem::Read( FileHandle_t file, void *pOutput, size_t nSize)
{
if (file->file)
@@ -200,10 +231,18 @@ size_t IFileSystem::Read( FileHandle_t file, void *pOutput, size_t nSize)
return readsize;
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
size_t IFileSystem::ReadLine( FileHandle_t file, void *pOutput, size_t nSize)
{
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
size_t IFileSystem::Write( FileHandle_t file, void *pInput, size_t nSize)
{

View File

@@ -4,6 +4,9 @@
CGameMode *pCurrentMode = NULL;
//-----------------------------------------------------------------------------
// Round begin handler
//-----------------------------------------------------------------------------
void CGameMode::RoundBegin( void )
{
size_t i = 0;
@@ -24,22 +27,33 @@ void CGameMode::RoundBegin( void )
}
}
//-----------------------------------------------------------------------------
// Round end handler
//-----------------------------------------------------------------------------
void CGameMode::RoundEnd( void )
{
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void IGameModeManager::Init( void )
{
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void IGameModeManager::Frame( void )
{
}
//-----------------------------------------------------------------------------
// Sets gamemode
//-----------------------------------------------------------------------------
void IGameModeManager::StartGameMode(CGameMode *pGameMode)
{
if (pCurrentMode)
@@ -49,11 +63,17 @@ void IGameModeManager::StartGameMode(CGameMode *pGameMode)
pCurrentMode->RoundBegin();
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
CGameMode *IGameModeManager::GetCurrentMode( void )
{
return pCurrentMode;
}
//-----------------------------------------------------------------------------
// Restarts the gamemode
//-----------------------------------------------------------------------------
void IGameModeManager::RestartCurrentMode( void )
{
if (!pCurrentMode)

View File

@@ -1,52 +1,166 @@
#include "input.h"
#include "console.h"
#include "tier0/lib.h"
#include "tier1/commandline.h"
#include "math3d.h"
char g_PressedKeys[256];
float g_fXAxisEvent[256];
float g_fYAxisEvent[256];
char g_PressedKeys[KEY_NUM_KEYS];
float g_fAxisValues[AXIS_NUM_AXIS];
CUtlString g_bindings[256];
struct KeyName_t {
const char *szName;
EInputKey key;
};
KeyName_t keys[] = {
{"TAB",KEY_TAB},
{"ENTER",KEY_ENTER},
{"ESCAPE",KEY_ESCAPE},
{"SPACE",KEY_SPACE},
{"A",KEY_A},
{"B",KEY_B},
{"C",KEY_C},
{"D",KEY_D},
{"E",KEY_E},
{"F",KEY_F},
{"G",KEY_G},
{"H",KEY_H},
{"I",KEY_I},
{"J",KEY_J},
{"K",KEY_K},
{"L",KEY_L},
{"M",KEY_M},
{"N",KEY_N},
{"O",KEY_O},
{"P",KEY_P},
{"Q",KEY_Q},
{"R",KEY_R},
{"S",KEY_S},
{"T",KEY_T},
{"U",KEY_U},
{"V",KEY_V},
{"W",KEY_W},
{"X",KEY_X},
{"Y",KEY_Y},
{"Z",KEY_Z},
};
//-----------------------------------------------------------------------------
// Converts string (eg. tab, mouse0, w, 0) to keycode
//-----------------------------------------------------------------------------
EInputKey IInput_StringToKey( char *psz )
{
for (uint32_t i = 0; i<sizeof(keys)/sizeof(KeyName_t); i++)
{
if (!V_stricmp(keys[i].szName, psz))
return keys[i].key;
};
return KEY_NONE;
};
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void IInput::Init( void )
{
}
//-----------------------------------------------------------------------------
// Generates command call when pressed the key. eg +forward; -left;
// Just to be sure we put ; in the end of the command.
// When user releases the key command event is not generated. But if the first
// command contains + as first character ( in case of example +forward ), then
// it fires -forward
//-----------------------------------------------------------------------------
void IInput::KeyEvent( EInputKey key, EKeyEventType event )
{
V_printf("key\n");
if (event == KEY_EVENT_TYPE_DOWN) {
IConsole::AddCommand(g_bindings[key]);
IConsole::AddCommand(";");
}
if (event == KEY_EVENT_TYPE_UP)
{
auto binding = IConsole::ParseCommandLine(g_bindings[key]);
if (binding.GetSize()==0)
return;
if (binding[0].GetSize() == 0)
return;
if (binding[0][0].GetString()[0] == '+')
{
CUtlString command = binding[0][0];
command.GetString()[0] = '-';
IConsole::AddCommand(command);
IConsole::AddCommand(";");
}
}
}
void IInput::AxisEvent( unsigned char cAxis, float fX, float fY )
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void IInput::AxisEvent( EInputAxis axis, float fValue )
{
if (axis == AXIS_MOUSE_X || axis == AXIS_MOUSE_Y)
{
g_fAxisValues[axis] += fValue*3.09;
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void IInput::Frame( void )
{
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void IInput::Deinit( void )
{
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void IInput_Bind( int argc, char **argv )
{
if (argc == 1)
return;
if (argc == 2)
return;
EInputKey key = IInput_StringToKey(argv[1]);
if (key == KEY_NONE)
return;
for ( int i = 2; i<argc; i++ )
{
g_bindings[key] = 0;
g_bindings[key].AppendTail(argv[i]);
}
};
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void IInput_Unbind( int argc, char **argv )
{
};
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void IInput_UnbindAll( int argc, char **argv )
{
};
ConCommand BindCmd("bind", IInput_Bind, 0);
ConCommand UnbindCmd("unbind", IInput_Bind, 0);
ConCommand unbindAllcmd("unbindall", IInput_Bind, 0);
ConCommand UnbindCmd("unbind", IInput_Unbind, 0);
ConCommand UnbindAllcmd("unbindall", IInput_UnbindAll, 0);

View File

@@ -18,6 +18,9 @@ struct EntityHeader_t
uint32_t nProperties;
};
//-----------------------------------------------------------------------------
// Loads level from file, deserializes it and creates entities.
//-----------------------------------------------------------------------------
void ILevel::LoadLevel( const char *szLevelName )
{
FileHandle_t handle = IFileSystem::Open(CUtlString("%s.fmap",szLevelName), IFILE_READ);

0
engine/mesh.cpp Normal file
View File

View File

@@ -1,5 +1,30 @@
#include "physics.h"
#include "physics_gen.h"
#include "math3d.h"
PxCastResult_t IPxWorld::BoxCast( vec3 size, vec3 origin, vec3 destination, vec3 rotation )
{
vec3 velocity;
PxCastResult_t result = {};
px_cast_result r = {};
for ( int i = 0; i < 3; i++ )
velocity[i] = destination[i] - origin[i];
r = px_box_cast(px, size[0], size[1], size[2], PX_GLM_VEC3(origin), PX_GLM_VEC3(rotation), PX_GLM_VEC3(velocity), 1);
result.bHit = r.hit;
result.fTime = r.time;
for ( int i = 0; i < 3; i++ )
{
result.position[i] = origin[i] + velocity[i] * result.fTime;
result.normal[i] = r.normal1.m[i];
result.normal2[i] = r.normal2.m[i];
}
return result;
}
void CPxCollider::Spawn( float fFriction )
{
@@ -44,6 +69,11 @@ void CPxRigidKinematicPosition::Spawn( CPxCollider *pCollider, px_matrix matrix,
{
m_pRigidBody = px_kinematic_position_body(px, pCollider->m_pCollider, matrix, params);
};
void CPxRigidKinematicPosition::SetPosition( px_vec3 position )
{
px_setposition(px, m_pRigidBody, position);
};
px_vec3 CPxRigidKinematicPosition::GetPosition( void )
{
return px_getposition(px, m_pRigidBody);

View File

@@ -12,6 +12,10 @@ void *g_serverdll;
ConVar g_tickrate("tickrate","64",FCVAR_PROTECTED);
float g_fAccumulator = 0;
//-----------------------------------------------------------------------------
// Loads game and client libraries if linking dynamically, otherwise it runs
// IGame_Load compiled statically.
//-----------------------------------------------------------------------------
void IServer::LoadGame( const char *psz )
{
#ifdef __WIN32__
@@ -21,6 +25,10 @@ void IServer::LoadGame( const char *psz )
g_serverdll = Plat_LoadLibrary(CUtlString("%s/bin/libserver.so", psz));
Plat_LoadLibrary(CUtlString("%s/bin/libclient.so", psz));
#endif
#ifdef __APPLE__
g_serverdll = Plat_LoadLibrary(CUtlString("%s/bin/libserver.dysim", psz));
Plat_LoadLibrary(CUtlString("%s/bin/libclient.dysim", psz));
#endif
void (*GameLoadfn)() = (void(*)())Plat_GetProc(g_serverdll, "IGame_Load");
if (!GameLoadfn)
@@ -28,6 +36,9 @@ void IServer::LoadGame( const char *psz )
GameLoadfn();
};
//-----------------------------------------------------------------------------
// Updates server and client state.
//-----------------------------------------------------------------------------
void IServer::Think( float fDelta )
{
g_fAccumulator += fDelta;
@@ -37,8 +48,8 @@ void IServer::Think( float fDelta )
while(g_fAccumulator>=fTickrate)
{
IInput::Frame();
IConsole::AddCommand("+forward;");
IConsole::Execute();
g_fAccumulator-=fTickrate;
for (auto &entity: g_entities)
{
@@ -52,3 +63,8 @@ void IServer::Think( float fDelta )
entity->pClientEntity->Think(fDelta);
}
};
void IGame_Exit( int argc, char **argv ) {
Plat_Exit(0);
}
ConCommand ExitCmd("exit", IGame_Exit, 0);

View File

@@ -8,3 +8,9 @@ VK_DEVICE_FUNCTION(vkCmdSetColorBlendEnableEXT);
VK_DEVICE_FUNCTION(vkCmdSetColorBlendEquationEXT);
VK_DEVICE_FUNCTION(vkCmdSetColorWriteMaskEXT);
VK_DEVICE_FUNCTION(vkCmdSetLogicOpEXT);
VK_DEVICE_FUNCTION(vkCmdTraceRaysKHR);
VK_DEVICE_FUNCTION(vkCreateAccelerationStructureKHR);
VK_DEVICE_FUNCTION(vkDestroyAccelerationStructureKHR);
VK_DEVICE_FUNCTION(vkGetAccelerationStructureBuildSizesKHR);
VK_DEVICE_FUNCTION(vkCmdBuildAccelerationStructuresKHR);
VK_DEVICE_FUNCTION(vkCreateRayTracingPipelinesKHR);

View File

@@ -14,8 +14,7 @@
#include "vk_external_functions.cpp"
#undef VK_DEVICE_FUNCTION
class CVertexBuffer: public IVertexBuffer
class CVkBuffer: public IBuffer
{
public:
void *Map() override;
@@ -24,17 +23,14 @@ public:
void *m_pAllocated = NULL;
};
class CIndexBuffer: public IIndexBuffer
class CVkImage: public IImage
{
public:
void *Map() override;
void Unmap() override;
vk_buffer_t m_buffer;
void *m_pAllocated;
vk_image2d_t m_image;
};
class CTexture: public ITexture
class CVkTexture: public ITexture
{
public:
vk_image2d_t image;
@@ -65,8 +61,6 @@ extern uint32_t g_nWindowWidth;
extern uint32_t g_nWindowHeight;
extern VkSampler g_invalidTextureSampler;
extern IMaterial *g_pDefaultMaterial;
extern IMaterial *g_pCurrentMaterial;
extern CUtlVector<ITexture*> g_textures;
@@ -77,7 +71,7 @@ struct CameraProjection {
extern vk_buffer_t g_cameraProperties;
extern CameraProjection *g_cameraDataMap;
extern vk_image2d_t g_meshDepth;
extern vk_image2d_t g_meshDepthMSAA;
extern vk_image2d_t g_meshColor;
extern vk_image2d_t g_meshColorMSAA;
extern IImage *g_meshDepth;
extern IImage *g_meshDepthMSAA;
extern IImage *g_meshColor;
extern IImage *g_meshColorMSAA;

View File

@@ -1,423 +0,0 @@
#include "filesystem.h"
#include "rendering.h"
#include "tier1/utlvector.h"
#include "vk_helper.h"
#include "vulkan/vulkan_core.h"
#include "math3d.h"
vk_tripipeline_t g_meshPipeline = {};
VkDescriptorPool g_meshDescriptorPool;
VkDescriptorSet g_meshDescriptorSet;
VkSampler g_meshSampler;
abstract_class CMesh: public IMesh
{
public:
CMesh();
void SetPosition( vec3 position ) override;
void SetRotationEuler( vec3 angle ) override;
void SetRotationQuat( vec4 quaternion) override;
void SetMatrix( mat4 matrix ) override;
void SetScale( vec3 scale ) override;
void SetVertexBuffer( IVertexBuffer *pBuffer ) override;
void SetIndexBuffer( IIndexBuffer *pBuffer ) override;
void SetMaterial( IMaterial *pMaterial ) override;
void Draw() override;
Material_t m_material;
CVertexBuffer *m_pVertexBuffer = NULL;
CIndexBuffer *m_pIndexBuffer = NULL;
mat4 m_matrix;
};
CMesh::CMesh()
{
glm_mat4_identity(m_matrix);
};
void CMesh::SetPosition( vec3 position )
{
m_matrix[0][3] = position[0];
m_matrix[1][3] = position[1];
m_matrix[2][3] = position[2];
}
void CMesh::SetRotationEuler( vec3 angle )
{
}
void CMesh::SetRotationQuat( vec4 quaternion)
{
}
void CMesh::SetMatrix( mat4 matrix )
{
memcpy(m_matrix,matrix,64);
}
void CMesh::SetScale( vec3 scale )
{
}
void CMesh::SetVertexBuffer( IVertexBuffer *pBuffer )
{
m_pVertexBuffer = (CVertexBuffer*)pBuffer;
}
void CMesh::SetIndexBuffer( IIndexBuffer *pBuffer )
{
m_pIndexBuffer = (CIndexBuffer*)pBuffer;
}
void CMesh::SetMaterial( IMaterial *pMaterial )
{
if (pMaterial == 0)
return;
m_material = pMaterial->m;
}
CUtlVector<CMesh> g_drawnMeshes;
void CMesh::Draw()
{
g_drawnMeshes.AppendTail(*this);
}
void IMeshRenderer::Init()
{
CUtlVector<vk_shader_t> shaders(2);
for (auto &shader: shaders)
{
shader.m_shaderModule = NULL;
}
shaders[0].Create("gfx/mesh_vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
shaders[1].Create("gfx/mesh_frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
CUtlVector<VkDescriptorSetLayoutBinding> bindings(2);
bindings[0] = {};
bindings[0].binding = 0;
bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
bindings[0].descriptorCount = 1;
bindings[1] = {};
bindings[1].binding = 1;
bindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
bindings[1].descriptorCount = 1024;
CUtlVector<VkFormat> formats(1);
formats[0] = VK_FORMAT_R16G16B16A16_SFLOAT;
g_meshPipeline.Create(shaders, bindings, 76, formats);
shaders[1].Destroy();
shaders[0].Destroy();
CUtlVector<VkDescriptorPoolSize> pools;
for (auto &binding: bindings)
{
VkDescriptorPoolSize dps = {};
dps.type = binding.descriptorType;
dps.descriptorCount = binding.descriptorCount;
pools.AppendTail(dps);
}
VkDescriptorPoolCreateInfo poolInfo = {};
poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
poolInfo.poolSizeCount = pools.GetSize();
poolInfo.pPoolSizes = pools.GetData();
poolInfo.maxSets = 1;
vkCreateDescriptorPool(g_vkDevice, &poolInfo, NULL, &g_meshDescriptorPool);
VkDescriptorSetAllocateInfo allocInfo = {};
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
allocInfo.descriptorPool = g_meshDescriptorPool;
allocInfo.descriptorSetCount = 1;
allocInfo.pSetLayouts = &g_meshPipeline.m_descriptorSetLayout;
vkAllocateDescriptorSets(g_vkDevice, &allocInfo, &g_meshDescriptorSet);
VkPhysicalDeviceProperties properties{};
vkGetPhysicalDeviceProperties(g_vkPhysicalDevice, &properties);
VkSamplerCreateInfo samplerInfo{};
samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
samplerInfo.magFilter = VK_FILTER_LINEAR;
samplerInfo.minFilter = VK_FILTER_LINEAR;
samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
samplerInfo.anisotropyEnable = VK_FALSE;
samplerInfo.maxAnisotropy = properties.limits.maxSamplerAnisotropy;
samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
samplerInfo.unnormalizedCoordinates = VK_FALSE;
samplerInfo.compareEnable = VK_FALSE;
samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS;
samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
samplerInfo.mipLodBias = 0.0f;
samplerInfo.minLod = 0.0f;
samplerInfo.maxLod = 0.0f;
vkCreateSampler(g_vkDevice, &samplerInfo, nullptr, &g_meshSampler);
}
void IMeshRenderer_PrepassNoMSAA()
{
};
void IMeshRenderer_Prepass()
{
};
void IMeshRenderer_EdgeDetection()
{
};
void IMeshRenderer_Light()
{
};
void IMeshRenderer_Combine()
{
};
void IMeshRenderer::Frame( float fDelta )
{
CUtlVector<VkWriteDescriptorSet> writes(2);
for (auto &write: writes)
{
write = {};
write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
write.dstSet = g_meshDescriptorSet;
write.dstArrayElement = 0;
}
VkDescriptorBufferInfo bufferInfo = {};
bufferInfo.buffer = g_cameraProperties.m_buffer;
bufferInfo.offset = 0;
bufferInfo.range = g_cameraProperties.m_nSize;
writes[0].dstBinding = 0;
writes[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
writes[0].descriptorCount = 1;
writes[0].pBufferInfo = &bufferInfo;
CUtlVector<VkDescriptorImageInfo> textures;
textures.Reserve(g_textures.GetSize());
for (ITexture *t: g_textures)
{
CTexture *texture = (CTexture*)t;
VkDescriptorImageInfo image = {};
image.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
image.imageView = texture->image.m_imageView;
image.sampler = g_meshSampler;
textures.AppendTail(image);
};
textures[0].sampler = g_invalidTextureSampler;
writes[1].dstBinding = 1;
writes[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
writes[1].descriptorCount = textures.GetSize();
writes[1].pImageInfo = textures.GetData();
vkUpdateDescriptorSets(g_vkDevice, writes.GetSize(), writes.GetData(), 0, NULL);
VkImageMemoryBarrier barriers[4] = {
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = 0,
.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
.image = g_meshColor.m_image,
.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}
},
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = 0,
.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
.image = g_meshColorMSAA.m_image,
.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}
},
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = 0,
.dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.newLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL,
.image = g_meshDepth.m_image,
.subresourceRange = {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1}
},
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = 0,
.dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.newLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL,
.image = g_meshDepthMSAA.m_image,
.subresourceRange = {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1}
},
};
vkCmdPipelineBarrier(g_vkCommandBuffer,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
0, 0, NULL, 0, NULL, 4, barriers);
VkRenderingAttachmentInfo colorAttachment = {
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO,
.imageView = g_meshColorMSAA.m_imageView,
.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
.resolveMode = VK_RESOLVE_MODE_AVERAGE_BIT,
.resolveImageView = g_meshColor.m_imageView,
.resolveImageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
.clearValue = {.color = {0.0f, 0.0f, 0.0f, 1.0f}},
};
VkRenderingAttachmentInfo depthAttachment = {
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO,
.imageView = g_meshDepthMSAA.m_imageView,
.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL,
.resolveMode = VK_RESOLVE_MODE_MIN_BIT,
.resolveImageView = g_meshDepth.m_imageView,
.resolveImageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL,
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
.clearValue = {.depthStencil = {.depth = 1}},
};
VkRenderingInfo renderInfo = {
.sType = VK_STRUCTURE_TYPE_RENDERING_INFO,
.renderArea = {{0, 0}, {g_nWindowWidth, g_nWindowHeight}},
.layerCount = 1,
.colorAttachmentCount = 1,
.pColorAttachments = &colorAttachment,
.pDepthAttachment = &depthAttachment,
};
vkCmdBeginRendering(g_vkCommandBuffer, &renderInfo);
vkCmdSetRasterizerDiscardEnable(g_vkCommandBuffer, VK_FALSE);
vkCmdSetDepthBiasEnable(g_vkCommandBuffer, VK_FALSE);
_vkCmdSetPolygonModeEXT(g_vkCommandBuffer, VK_POLYGON_MODE_FILL);
vkCmdSetCullMode(g_vkCommandBuffer, VK_CULL_MODE_BACK_BIT);
vkCmdSetFrontFace(g_vkCommandBuffer, VK_FRONT_FACE_COUNTER_CLOCKWISE);
vkCmdSetDepthTestEnable(g_vkCommandBuffer, VK_TRUE);
vkCmdSetDepthWriteEnable(g_vkCommandBuffer, VK_TRUE);
vkCmdSetDepthCompareOp(g_vkCommandBuffer, VK_COMPARE_OP_LESS);
vkCmdSetStencilTestEnable(g_vkCommandBuffer, VK_FALSE);
_vkCmdSetRasterizationSamplesEXT(g_vkCommandBuffer, VK_SAMPLE_COUNT_4_BIT);
VkSampleMask sampleMask = 0xFFFFFFFF;
_vkCmdSetSampleMaskEXT(g_vkCommandBuffer, VK_SAMPLE_COUNT_4_BIT, &sampleMask);
_vkCmdSetAlphaToCoverageEnableEXT(g_vkCommandBuffer, VK_FALSE);
VkViewport viewport = {0, 0, (float)g_nWindowWidth, (float)g_nWindowHeight, 0.0f, 1.0f};
VkRect2D scissor = {{0, 0}, {g_nWindowWidth, g_nWindowHeight}};
vkCmdSetViewportWithCount(g_vkCommandBuffer, 1, &viewport);
vkCmdSetScissorWithCount(g_vkCommandBuffer, 1, &scissor);
vkCmdSetPrimitiveTopology(g_vkCommandBuffer, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST);
vkCmdSetPrimitiveRestartEnable(g_vkCommandBuffer, VK_FALSE);
VkVertexInputBindingDescription2EXT binding = {
.sType = VK_STRUCTURE_TYPE_VERTEX_INPUT_BINDING_DESCRIPTION_2_EXT,
.binding = 0,
.stride = 20,
.inputRate = VK_VERTEX_INPUT_RATE_VERTEX,
.divisor = 1,
};
VkVertexInputAttributeDescription2EXT attributes[2] = {
{
VK_STRUCTURE_TYPE_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION_2_EXT,
NULL,
0, 0,
VK_FORMAT_R32G32B32_SFLOAT,
0
},
{
VK_STRUCTURE_TYPE_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION_2_EXT,
NULL,
1, 0,
VK_FORMAT_R32G32_SFLOAT,
12
}
};
_vkCmdSetVertexInputEXT(g_vkCommandBuffer, 1, &binding, 2, attributes);
VkBool32 blendEnable = VK_FALSE;
VkColorBlendEquationEXT blendEquation = {
VK_BLEND_FACTOR_SRC_ALPHA, VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, VK_BLEND_OP_ADD,
VK_BLEND_FACTOR_ONE, VK_BLEND_FACTOR_ZERO, VK_BLEND_OP_ADD
};
VkColorComponentFlags writeMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |
VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
_vkCmdSetColorBlendEnableEXT(g_vkCommandBuffer, 0, 1, &blendEnable);
_vkCmdSetColorBlendEquationEXT(g_vkCommandBuffer, 0, 1, &blendEquation);
_vkCmdSetColorWriteMaskEXT(g_vkCommandBuffer, 0, 1, &writeMask);
vkCmdBindPipeline(g_vkCommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_meshPipeline.m_pipeline);
vkCmdBindDescriptorSets(g_vkCommandBuffer,VK_PIPELINE_BIND_POINT_GRAPHICS, g_meshPipeline.m_layout, 0, 1, &g_meshDescriptorSet, 0, NULL);
for (auto &mesh: g_drawnMeshes)
{
VkDeviceSize offset = 0;
uint32_t textureID = mesh.m_material.albedo;
vkCmdPushConstants(g_vkCommandBuffer, g_meshPipeline.m_layout, VK_SHADER_STAGE_ALL, 0, 64, &mesh.m_matrix);
vkCmdPushConstants(g_vkCommandBuffer, g_meshPipeline.m_layout, VK_SHADER_STAGE_ALL, 64, 4, &textureID);
vkCmdBindVertexBuffers(g_vkCommandBuffer, 0, 1, &mesh.m_pVertexBuffer->m_buffer.m_buffer, &offset);
if (mesh.m_pIndexBuffer)
{
vkCmdBindIndexBuffer(
g_vkCommandBuffer,
mesh.m_pIndexBuffer->m_buffer.m_buffer,
0,
VK_INDEX_TYPE_UINT32
);
vkCmdDrawIndexed(g_vkCommandBuffer, mesh.m_pIndexBuffer->m_buffer.m_nSize/4, 1, 0, 0, 0);
}
else
{
vkCmdDraw(g_vkCommandBuffer, mesh.m_pVertexBuffer->m_buffer.m_nSize/20,1,0,0);
}
}
vkCmdEndRendering(g_vkCommandBuffer);
VkImageMemoryBarrier barrier = {
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.dstAccessMask = 0,
.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
.image = g_meshColor.m_image,
.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}
};
vkCmdPipelineBarrier(g_vkCommandBuffer,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
0, 0, NULL, 0, NULL, 1, &barrier);
g_drawnMeshes = CUtlVector<CMesh>();
}
IMesh *IMeshRenderer::CreateMesh()
{
CMesh *mesh = new CMesh;
return mesh;
}
void IMeshRenderer::Destroy( IMesh *pModel )
{
}

View File

@@ -1,144 +0,0 @@
#include "rendering.h"
#include "vk_helper.h"
#include "vk_video.h"
#include "vulkan/vulkan_core.h"
vk_shader_t post_agxShader = {};
vk_comppipeline_t post_agxPipeline = {};
VkDescriptorPool post_descriptorPool;
VkDescriptorSet post_descriptorSet;
void IPostProcessRenderer::Init()
{
post_agxShader.Create("gfx/agx_comp.spv", VK_SHADER_STAGE_COMPUTE_BIT);
CUtlVector<VkDescriptorSetLayoutBinding> bindings = {
{
.binding = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
},
{
.binding = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
}
};
post_agxPipeline.Create(post_agxShader, bindings, 0);
CUtlVector<VkDescriptorPoolSize> pools;
for (auto &binding: bindings)
{
VkDescriptorPoolSize dps = {};
dps.type = binding.descriptorType;
dps.descriptorCount = binding.descriptorCount;
pools.AppendTail(dps);
}
VkDescriptorPoolCreateInfo poolInfo = {};
poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
poolInfo.poolSizeCount = pools.GetSize();
poolInfo.pPoolSizes = pools.GetData();
poolInfo.maxSets = 1;
vkCreateDescriptorPool(g_vkDevice, &poolInfo, NULL, &post_descriptorPool);
VkDescriptorSetAllocateInfo allocInfo = {};
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
allocInfo.descriptorPool = post_descriptorPool;
allocInfo.descriptorSetCount = 1;
allocInfo.pSetLayouts = &post_agxPipeline.m_descriptorSetLayout;
vkAllocateDescriptorSets(g_vkDevice, &allocInfo, &post_descriptorSet);
}
void IPostProcessRenderer::Frame(float fDelta)
{
CUtlVector<VkImageMemoryBarrier> barriers = {
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = 0,
.dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
.oldLayout = VK_IMAGE_LAYOUT_GENERAL,
.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
.image = g_meshColor.m_image,
.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}
},
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = 0,
.dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
.image = g_swapchainImage,
.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}
}
};
vkCmdPipelineBarrier(g_vkCommandBuffer,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
0, 0, NULL, 0, NULL, barriers.GetSize(), barriers.GetData());
CUtlVector<VkWriteDescriptorSet> writes(2);
for (auto &write: writes)
{
write = {};
write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
write.dstSet = post_descriptorSet;
write.dstArrayElement = 0;
}
VkDescriptorImageInfo dii1 = {
.imageView = g_meshColor.m_imageView,
.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
.sampler = NULL,
};
VkDescriptorImageInfo dii2 = {
.imageView = g_swapchainImageView,
.imageLayout = VK_IMAGE_LAYOUT_GENERAL,
.sampler = NULL,
};
writes[0].dstBinding = 0;
writes[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
writes[0].descriptorCount = 1;
writes[0].pImageInfo = &dii1;
writes[1].dstBinding = 1;
writes[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
writes[1].descriptorCount = 1;
writes[1].pImageInfo = &dii2;
vkUpdateDescriptorSets(g_vkDevice, writes.GetSize(), writes.GetData(), 0, NULL);
vkCmdBindPipeline(g_vkCommandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, post_agxPipeline.m_pipeline);
vkCmdBindDescriptorSets(g_vkCommandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, post_agxPipeline.m_layout, 0, 1, &post_descriptorSet, 0, 0);
vkCmdDispatch(g_vkCommandBuffer, (g_nWindowWidth+31)/32, (g_nWindowHeight+31)/32, 1);
barriers = {
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = 0,
.dstAccessMask = 0,
.oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
.image = g_meshColor.m_image,
.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}
},
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
.dstAccessMask = 0,
.oldLayout = VK_IMAGE_LAYOUT_GENERAL,
.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
.image = g_swapchainImage,
.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}
}
};
vkCmdPipelineBarrier(g_vkCommandBuffer,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
0, 0, NULL, 0, NULL, barriers.GetSize(), barriers.GetData());
}

View File

@@ -9,6 +9,19 @@
#include "vulkan/vulkan_core.h"
#define STB_IMAGE_IMPLEMENTATION
#if defined(__APPLE__) && defined(__MACH__)
#include "TargetConditionals.h"
#if TARGET_OS_IPHONE
// iOS
#define STBI_NO_THREAD_LOCALS
#else
// macOS
#endif
#else
// Other platforms
#define STBI_THREAD_LOCAL thread_local
#endif
#include "stb_image.h"
#define VULKAN_RENDERING_IMPLEMENTATION
@@ -21,13 +34,58 @@ CameraProjection *g_cameraDataMap;
mat4 g_cameraView;
IMaterial *g_pDefaultMaterial;
IMaterial *g_pCurrentMaterial;
IImage *g_meshDepth;
IImage *g_meshDepthMSAA;
IImage *g_meshColor;
IImage *g_meshColorMSAA;
class CVkGraphicsPipeline: public IGraphicsPipeline
{
public:
vk_tripipeline_t m_pipeline;
};
vk_image2d_t g_meshDepth;
vk_image2d_t g_meshDepthMSAA;
vk_image2d_t g_meshColor;
vk_image2d_t g_meshColorMSAA;
class CVkComputePipeline: public IComputePipeline
{
public:
vk_comppipeline_t m_pipeline;
};
class CVkRayTracingPipeline: public IRayTracingPipeline
{
public:
};
VkFormat IRenderer_FormatToVk( EImageFormat format )
{
switch (format)
{
case IMAGE_FORMAT_R8G8B8A8: return VK_FORMAT_R8G8B8A8_UNORM;
case IMAGE_FORMAT_R16G16B16A16: return VK_FORMAT_R16G16B16A16_UNORM;
case IMAGE_FORMAT_DEPTH: return VK_FORMAT_D32_SFLOAT;
default: return VK_FORMAT_R8G8B8A8_UNORM;
}
};
VkAttachmentLoadOp IRenderer_LoadOpVk( EAttachmentLoadMode mode )
{
switch (mode)
{
case ATTACHMENT_LOAD_MODE_DONT_CARE: return VK_ATTACHMENT_LOAD_OP_DONT_CARE;
case ATTACHMENT_LOAD_MODE_CLEAR: return VK_ATTACHMENT_LOAD_OP_CLEAR;
case ATTACHMENT_LOAD_MODE_LOAD: return VK_ATTACHMENT_LOAD_OP_LOAD;
default: return VK_ATTACHMENT_LOAD_OP_DONT_CARE;
}
}
VkAttachmentStoreOp IRenderer_StoreOpVk( EAttachmentStoreMode mode )
{
switch (mode)
{
case ATTACHMENT_STORE_MODE_DONT_CARE: return VK_ATTACHMENT_STORE_OP_DONT_CARE;
case ATTACHMENT_STORE_MODE_STORE: return VK_ATTACHMENT_STORE_OP_STORE;
default: return VK_ATTACHMENT_STORE_OP_DONT_CARE;
}
}
void IVulkan::Init()
{
@@ -65,15 +123,25 @@ void IVulkan::Init()
g_cameraProperties.Create(sizeof(CameraProjection), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
g_cameraDataMap = (CameraProjection*)g_cameraProperties.Map(0, 64);
g_meshDepth.Create(1280, 720, VK_FORMAT_D32_SFLOAT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_SAMPLE_COUNT_1_BIT);
g_meshDepthMSAA.Create(1280, 720, VK_FORMAT_D32_SFLOAT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_SAMPLE_COUNT_4_BIT);
g_meshColor.Create(1280, 720, VK_FORMAT_R16G16B16A16_SFLOAT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_SAMPLE_COUNT_1_BIT);
g_meshColorMSAA.Create(1280, 720, VK_FORMAT_R16G16B16A16_SFLOAT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_SAMPLE_COUNT_4_BIT);
g_meshDepth = IRenderer::CreateImage(IMAGE_FORMAT_DEPTH, IMAGE_USAGE_DEPTH_ATTACHMENT, 1280, 720, 1);
g_meshDepthMSAA = IRenderer::CreateImage(IMAGE_FORMAT_DEPTH, IMAGE_USAGE_DEPTH_ATTACHMENT, 1280, 720, 4);
g_meshColor = IRenderer::CreateImage(IMAGE_FORMAT_R8G8B8A8, IMAGE_USAGE_COLOR_ATTACHMENT, 1280, 720, 1);
g_meshColorMSAA = IRenderer::CreateImage(IMAGE_FORMAT_R8G8B8A8, IMAGE_USAGE_COLOR_ATTACHMENT, 1280, 720, 4);
glm_mat4_identity(g_cameraView);
IMeshRenderer::Init();
IPostProcessRenderer::Init();
};
void IVulkan::CreatePipelines()
{
for (auto &step: g_StepPrepass)
step.pPipeline->Init();
for (auto &step: g_StepMeshRendering)
step.pPipeline->Init();
for (auto &step: g_StepShading)
step.pPipeline->Init();
for (auto &step: g_StepPostProcessing)
step.pPipeline->Init();
for (auto &step: g_StepUI)
step.pPipeline->Init();
}
void IVulkan::Frame()
{
@@ -87,19 +155,42 @@ void IVulkan::Frame()
if (g_bConfigNotify)
{
g_meshDepth.Destroy();
g_meshDepthMSAA.Destroy();
g_meshColor.Destroy();
g_meshColorMSAA.Destroy();
g_meshDepth.Create(g_nWindowWidth, g_nWindowHeight, VK_FORMAT_D32_SFLOAT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_SAMPLE_COUNT_1_BIT);
g_meshDepthMSAA.Create(g_nWindowWidth, g_nWindowHeight, VK_FORMAT_D32_SFLOAT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_SAMPLE_COUNT_4_BIT);
g_meshColor.Create(g_nWindowWidth, g_nWindowHeight, VK_FORMAT_R16G16B16A16_SFLOAT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_SAMPLE_COUNT_1_BIT);
g_meshColorMSAA.Create(g_nWindowWidth, g_nWindowHeight, VK_FORMAT_R16G16B16A16_SFLOAT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_SAMPLE_COUNT_4_BIT);
IRenderer::DestroyImage(g_meshDepth);
IRenderer::DestroyImage(g_meshDepthMSAA);
IRenderer::DestroyImage(g_meshColor);
IRenderer::DestroyImage(g_meshColorMSAA);
g_meshDepth = IRenderer::CreateImage(IMAGE_FORMAT_DEPTH, IMAGE_USAGE_DEPTH_ATTACHMENT, g_nWindowWidth, g_nWindowHeight, 1);
g_meshDepthMSAA = IRenderer::CreateImage(IMAGE_FORMAT_DEPTH, IMAGE_USAGE_DEPTH_ATTACHMENT, g_nWindowWidth, g_nWindowHeight, 4);
g_meshColor = IRenderer::CreateImage(IMAGE_FORMAT_R8G8B8A8, IMAGE_USAGE_COLOR_ATTACHMENT, g_nWindowWidth, g_nWindowHeight, 1);
g_meshColorMSAA = IRenderer::CreateImage(IMAGE_FORMAT_R8G8B8A8, IMAGE_USAGE_COLOR_ATTACHMENT, g_nWindowWidth, g_nWindowHeight, 4);
}
IMeshRenderer::Frame(0);
IPostProcessRenderer::Frame(0);
for (auto &step: g_StepPrepass)
step.pPipeline->Frame(0);
IRenderer::Begin(g_nWindowWidth, g_nWindowHeight,
{
{
g_meshColor,
g_meshColorMSAA,
ATTACHMENT_LOAD_MODE_DONT_CARE,
ATTACHMENT_STORE_MODE_STORE,
}
},
{
g_meshDepth,
g_meshDepthMSAA,
ATTACHMENT_LOAD_MODE_DONT_CARE,
ATTACHMENT_STORE_MODE_STORE,
});
for (auto &step: g_StepMeshRendering)
step.pPipeline->Frame(0);
IRenderer::End();
for (auto &step: g_StepShading)
step.pPipeline->Frame(0);
for (auto &step: g_StepPostProcessing)
step.pPipeline->Frame(0);
for (auto &step: g_StepUI)
step.pPipeline->Frame(0);
};
void vk_shader_t::Create( const char *szPath, VkShaderStageFlagBits shaderStage )
@@ -384,27 +475,13 @@ void vk_image2d_t::Destroy()
void CopyTo(struct vk_image2d_t *image);
void CopyTo(struct vk_buffer_t *buffer);
void *CVertexBuffer::Map()
void *CVkBuffer::Map()
{
if (!m_pAllocated)
m_pAllocated = m_buffer.Map(0, m_buffer.m_nSize);
return m_pAllocated;
};
void CVertexBuffer::Unmap()
{
if (!m_pAllocated)
return;
m_buffer.Unmap();
m_pAllocated = 0;
};
void *CIndexBuffer::Map()
{
if (!m_pAllocated)
m_pAllocated = m_buffer.Map(0, m_buffer.m_nSize);
return m_pAllocated;
};
void CIndexBuffer::Unmap()
void CVkBuffer::Unmap()
{
if (!m_pAllocated)
return;
@@ -415,21 +492,9 @@ void CIndexBuffer::Unmap()
CUtlVector<ITexture*> g_textures;
CUtlVector<ITexture*> g_newtextures;
uint32_t ITextureManager::GetTexture(ITexture *pTexture)
{
uint32_t i = 0;
for (ITexture *texture: g_textures)
{
if (texture == pTexture)
return i;
i++;
};
return 0;
}
ITexture *ITextureManager::LoadTexture( void *pData, uint32_t X, uint32_t Y, uint32_t numChannels )
{
CTexture *pTexture = new CTexture;
CVkTexture *pTexture = new CVkTexture;
*pTexture = {};
VkDeviceSize imageSize = X*Y*4;
vk_buffer_t gpu_buffer = {};
@@ -562,28 +627,265 @@ ITexture *ITextureManager::LoadTexture( const char *szName )
return pTexture;
};
IMaterial *IRenderer::LoadMaterial( const char *szMaterial )
{
FileHandle_t file = IFileSystem::Open(szMaterial, IFILE_READ);
IMaterial *pMaterial = new IMaterial;
if (!file)
{
return g_pDefaultMaterial;
}
IFileSystem::Close(file);
IStorageBuffer *IRenderer::CreateStorageBuffer( uint32_t uSize )
{
CVkBuffer *pBuffer = new CVkBuffer();
pBuffer->m_buffer.Create(uSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
return pBuffer;
}
IUniformBuffer *IRenderer::CreateUniformBuffer( uint32_t uSize )
{
CVkBuffer *pBuffer = new CVkBuffer();
pBuffer->m_buffer.Create(uSize, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
return pBuffer;
}
IVertexBuffer *IRenderer::CreateVertexBuffer( uint32_t uSize )
{
CVertexBuffer *pBuffer = new CVertexBuffer();
CVkBuffer *pBuffer = new CVkBuffer();
pBuffer->m_buffer.Create(uSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
return pBuffer;
}
IIndexBuffer *IRenderer::CreateIndexBuffer( uint32_t uSize )
{
CIndexBuffer *pBuffer = new CIndexBuffer();
CVkBuffer *pBuffer = new CVkBuffer();
pBuffer->m_buffer.Create(uSize, VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
return pBuffer;
}
IImage *IRenderer::CreateImage( EImageFormat format, uint32_t usage, uint32_t nWidth, uint32_t nHeight, uint32_t nSamples )
{
VkFormat vkformat;
VkImageUsageFlags vkusage;
CVkImage *pImage = new CVkImage();
VkSampleCountFlagBits samples;
switch (format)
{
case IMAGE_FORMAT_R8G8B8A8: vkformat = VK_FORMAT_R8G8B8A8_UNORM; break;
case IMAGE_FORMAT_R16G16B16A16: vkformat = VK_FORMAT_R16G16B16A16_UNORM; break;
case IMAGE_FORMAT_DEPTH: vkformat = VK_FORMAT_D32_SFLOAT; break;
default: return 0;
};
if (usage&IMAGE_USAGE_COLOR_ATTACHMENT) vkusage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
if (usage&IMAGE_USAGE_DEPTH_ATTACHMENT) vkusage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
if (usage&IMAGE_USAGE_STORAGE) vkusage |= VK_IMAGE_USAGE_STORAGE_BIT;
switch (nSamples)
{
case 1: samples = VK_SAMPLE_COUNT_1_BIT; break;
case 4: samples = VK_SAMPLE_COUNT_4_BIT; break;
default: samples = VK_SAMPLE_COUNT_1_BIT; break;
}
pImage->m_image.Create(nWidth, nHeight, vkformat, vkusage, samples);
return pImage;
};
void IRenderer::DestroyBuffer( IBuffer *pBuffer )
{
CVkBuffer *pVkBuffer = (CVkBuffer*)pBuffer;
if (pVkBuffer)
pVkBuffer->m_buffer.Destroy();
}
void IRenderer::DestroyImage( IImage *pImage )
{
CVkImage *pVkImage = (CVkImage*)pImage;
if (pVkImage)
pVkImage->m_image.Destroy();
}
void IRenderer::SetConstants( uint32_t nSize, uint32_t nOffset, void *pData )
{
}
void IRenderer::Barrier( EBarrierStage stageIn, uint32_t stageOut, CUtlVector<BufferBarrier_t> buffers, CUtlVector<ImageBarrier_t> images )
{
}
void IRenderer::BindData( uint32_t binding, IBuffer *pBuffer, IImage* pImage)
{
}
void IRenderer::BindPipeline( IPipeline *pPipeline )
{
if (!pPipeline)
return;
if (pPipeline->type == PIPELINE_TYPE_RASTERIZATION)
{
CVkGraphicsPipeline *pVkPipeline = (CVkGraphicsPipeline*)pPipeline;
vkCmdBindPipeline(g_vkCommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pVkPipeline->m_pipeline.m_pipeline);
}
}
void IRenderer::Begin( uint32_t nWidth, uint32_t nHeight, CUtlVector<RenderingColorAttachment_t> attachments, RenderingDepthAttachment_t depth )
{
CUtlVector<VkRenderingAttachmentInfo> colorAttachments = {};
VkRenderingAttachmentInfo depthAttachment = {};
for (auto &attachment: attachments)
{
VkRenderingAttachmentInfo vkattachment = {};
vkattachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
CVkImage *pImage = (CVkImage*)attachment.pTemporary;
CVkImage *pTemporary = (CVkImage*)attachment.pTemporary;
if (attachment.pTemporary)
{
vkattachment.imageView = pTemporary->m_image.m_imageView;
vkattachment.resolveImageView = pImage->m_image.m_imageView;
vkattachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
vkattachment.resolveImageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
} else
{
vkattachment.imageView = pImage->m_image.m_imageView;
vkattachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
}
vkattachment.loadOp = IRenderer_LoadOpVk(attachment.loadMode);
vkattachment.storeOp = IRenderer_StoreOpVk(attachment.storeMode);
colorAttachments.AppendTail(vkattachment);
}
depthAttachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
CVkImage *pDepthImage = (CVkImage*)depth.pTemporary;
CVkImage *pDepthTemporary = (CVkImage*)depth.pTemporary;
if (depth.pTemporary)
{
depthAttachment.imageView = pDepthTemporary->m_image.m_imageView;
depthAttachment.resolveImageView = pDepthImage->m_image.m_imageView;
depthAttachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
depthAttachment.resolveImageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
} else
{
depthAttachment.imageView = pDepthImage->m_image.m_imageView;
depthAttachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
}
depthAttachment.loadOp = IRenderer_LoadOpVk(depth.loadMode);
depthAttachment.storeOp = IRenderer_StoreOpVk(depth.storeMode);
VkRenderingInfo renderInfo = {
.sType = VK_STRUCTURE_TYPE_RENDERING_INFO,
.renderArea = {{0, 0}, {nWidth, nHeight}},
.layerCount = 1,
.colorAttachmentCount = (uint32_t)colorAttachments.GetSize(),
.pColorAttachments = colorAttachments.GetData(),
.pDepthAttachment = &depthAttachment,
};
vkCmdBeginRendering(g_vkCommandBuffer, &renderInfo);
}
void IRenderer::ResetState()
{
}
void IRenderer::SetDepthMode( EDepthMode mode )
{
}
void IRenderer::Draw( IVertexBuffer *pVertex, IIndexBuffer *pIndex )
{
}
void IRenderer::End()
{
vkCmdEndRendering(g_vkCommandBuffer);
}
IGraphicsPipeline *IRenderer::CreateGraphicsPipeline(
CUtlVector<Shader_t> shaders,
CUtlVector<ShaderInput_t> inputs,
uint32_t nConstantsSize,
CUtlVector<EImageFormat> outputFormats
)
{
CVkGraphicsPipeline *pipeline = new CVkGraphicsPipeline;
pipeline->type = PIPELINE_TYPE_RASTERIZATION;
CUtlVector<vk_shader_t> vkshaders(shaders.GetSize());
CUtlVector<VkDescriptorSetLayoutBinding> vkbindings(inputs.GetSize());
CUtlVector<VkFormat> vkformats(outputFormats.GetSize());
for ( uint32_t i = 0; i < vkshaders.GetSize(); i++ )
{
VkShaderStageFlagBits flags;
if (shaders[i].type == SHADER_TYPE_VERTEX) flags = VK_SHADER_STAGE_VERTEX_BIT;
if (shaders[i].type == SHADER_TYPE_FRAGMENT) flags = VK_SHADER_STAGE_FRAGMENT_BIT;
vkshaders[i].Create(shaders[i].szPath, flags);
}
for ( uint32_t i = 0; i < vkbindings.GetSize(); i++ )
{
vkbindings[i].binding = inputs[i].binding;
vkbindings[i].descriptorCount = 1;
if (inputs[i].type == SHADER_INPUT_TYPE_IMAGE) vkbindings[i].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
if (inputs[i].type == SHADER_INPUT_TYPE_UNIFORM_BUFFER) vkbindings[i].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
if (inputs[i].type == SHADER_INPUT_TYPE_STORAGE_BUFFER) vkbindings[i].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
if (inputs[i].type == SHADER_INPUT_TYPE_TLAS) vkbindings[i].descriptorType = VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR;
if (inputs[i].type == SHADER_INPUT_TYPE_TEXTURES)
{
vkbindings[i].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
vkbindings[i].descriptorCount = 1024;
}
}
for ( uint32_t i = 0; i < vkformats.GetSize(); i++ )
{
vkformats[i] = IRenderer_FormatToVk(outputFormats[i]);
}
pipeline->m_pipeline.Create(vkshaders, vkbindings, nConstantsSize, vkformats);
return 0;
};
CUtlVector<RenderingStep_t> g_StepPrepass;
CUtlVector<RenderingStep_t> g_StepMeshRendering;
CUtlVector<RenderingStep_t> g_StepShading;
CUtlVector<RenderingStep_t> g_StepPostProcessing;
CUtlVector<RenderingStep_t> g_StepUI;
CRenderingStep::CRenderingStep()
{
}
CRenderingStep::CRenderingStep(const char *szStepName, CreateRenderStepFn pfn)
{
}
CPrepassRenderingStep::CPrepassRenderingStep(const char *szStepName, CreateRenderStepFn pfn)
{
g_StepPrepass.AppendTail({pfn(), szStepName});
}
CMeshRenderingStep::CMeshRenderingStep(const char *szStepName, CreateRenderStepFn pfn)
{
g_StepMeshRendering.AppendTail({pfn(), szStepName});
}
CShadingRenderingStep::CShadingRenderingStep(const char *szStepName, CreateRenderStepFn pfn)
{
g_StepShading.AppendTail({pfn(), szStepName});
}
CPostProcessingRenderingStep::CPostProcessingRenderingStep(const char *szStepName, CreateRenderStepFn pfn)
{
g_StepPostProcessing.AppendTail({pfn(), szStepName});
}
CUIRenderingStep::CUIRenderingStep(const char *szStepName, CreateRenderStepFn pfn)
{
g_StepUI.AppendTail({pfn(), szStepName});
}

View File

@@ -97,6 +97,7 @@ interface IVulkan
{
public:
static void Init();
static void CreatePipelines();
static void Frame();
static void Deinit();
};

View File

@@ -189,6 +189,8 @@ EInputKey ISDL_KeyName(SDL_Keycode key)
{
switch(key)
{
case SDLK_ESCAPE: return KEY_ESCAPE;
case SDLK_1: return KEY_1;
case SDLK_2: return KEY_2;
case SDLK_3: return KEY_3;
@@ -380,7 +382,19 @@ void IVideo::Init()
IVideo_SwapchainInit();
IVulkan::Init();
}
void IInput::SetMouseMode( EMouseMode mode )
{
switch (mode)
{
case MOUSE_MODE_GAME:
SDL_SetWindowRelativeMouseMode(g_window, true);
return;
default:
SDL_SetWindowRelativeMouseMode(g_window, false);
return;
}
}
void IVideo_HandleEvents()
@@ -389,6 +403,7 @@ void IVideo_HandleEvents()
while (SDL_PollEvent(&event))
{
SDL_KeyboardEvent *key = &event.key;
SDL_MouseMotionEvent *motion = &event.motion;
switch (event.type)
{
case SDL_EVENT_WINDOW_RESIZED:
@@ -398,16 +413,25 @@ void IVideo_HandleEvents()
break;
case SDL_EVENT_KEY_DOWN:
if (!key->repeat)
IInput::KeyEvent(ISDL_KeyName(key->key),KEY_EVENT_TYPE_UP);
IInput::KeyEvent(ISDL_KeyName(key->key),KEY_EVENT_TYPE_DOWN);
break;
case SDL_EVENT_KEY_UP:
key = &event.key;
SDL_Log("Key Up: %s", SDL_GetKeyName(key->key));
if (!key->repeat)
IInput::KeyEvent(ISDL_KeyName(key->key),KEY_EVENT_TYPE_UP);
break;
case SDL_EVENT_MOUSE_MOTION:
IInput::AxisEvent(AXIS_MOUSE_X, motion->yrel*0.022);
IInput::AxisEvent(AXIS_MOUSE_Y, -motion->xrel*0.022);
break;
}
};
};
void IVideo::CreatePipelines( )
{
IVulkan::CreatePipelines();
};
void IVideo::Frame( float fDelta )
{

View File

@@ -1,37 +0,0 @@
char* fgui_lib = 0;
void fgui_build(struct build_data b)
{
char* files[] = {
"fgui/fgui.cpp",
NULL,
};
struct C_Macro macros[] = {
(struct C_Macro){"TIER0_IMPLEMENTATION","1"},
NULL,
};
struct project p = {
.b = &b,
.files = files,
.name = "fgui",
};
struct project o = C_compile(p, (struct C_settings){
.generation_flags = C_GENERATION_FLAGS_PIC,
.compile_flags = C_COMPILE_FLAGS_WALL,
.include_dirs = include_dirs,
.macros = macros,
});
char* libs[] = {
"c",
NULL,
};
fgui_lib = ld_link_project(o, (struct link_settings){
.type = LINK_TYPE_STATIC,
.libs = libs,
});
}

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.fpc</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

Binary file not shown.

View File

@@ -0,0 +1,5 @@
---
triple: 'x86_64-apple-darwin'
binary-path: fpc
relocations: []
...

View File

@@ -25,22 +25,7 @@ CLDProject CCProject::Compile()
{
CUtlVector<CUtlString> args;
V_printf(" CC %s\n", file.GetString());
CUtlString szTarget = "";
if (m_target.cpu == TARGET_CPU_AMD64)
{
if (m_target.kernel == TARGET_KERNEL_WINDOWS)
{
szTarget = "x86_64-pc-windows-gnu";
}
if (m_target.kernel == TARGET_KERNEL_LINUX)
{
szTarget = "x86_64-unknown-linux-gnu";
}
if (m_target.kernel == TARGET_KERNEL_DARWIN)
{
szTarget = "x86_64-apple-darwin";
}
};
CUtlString szTarget = m_target.GetTriplet();
CUtlString szOutputFile = CUtlString("%s/%s/cc/%u_%s/%s/%s.o",FPC_TEMPORAL_DIRNAME, szTarget.GetString(), hash, m_szName.GetString(), IFileSystem2::BuildDirectory(), file.GetString());
CUtlString szOutputDir;
@@ -63,6 +48,13 @@ CLDProject CCProject::Compile()
args.AppendTail("-isysroot");
args.AppendTail("/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk");
}
if (m_target.kernel == TARGET_KERNEL_IOS)
{
args.AppendTail("-isysroot");
args.AppendTail("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk");
args.AppendTail("-miphoneos-version-min=18.0 ");
args.AppendTail("-fembed-bitcode");
}
if (bFPIC)
args.AppendTail("-fPIC");
if (bFPIE)

View File

@@ -6,6 +6,9 @@
#include "unistd.h"
#include "libgen.h"
#include "sys/stat.h"
#ifdef __APPLE__
#include <mach-o/dyld.h>
#endif
unsigned int g_hashState = 102851263;
unsigned int CProject::GenerateProjectHash( void )
@@ -23,7 +26,13 @@ unsigned int CProject::GenerateProjectHash( void )
};
static char path[1024];
#ifdef __linux__
static ssize_t pathSize = readlink("/proc/self/exe", path, sizeof(path) - 1);
#endif
#ifdef __APPLE__
static uint32_t pathSize = sizeof(path);
int pathResult = _NSGetExecutablePath(path, &pathSize);
#endif
char *szPathDir = dirname(path);
char *szBuildDir = 0;
char *IFileSystem2::OwnDirectory()

View File

@@ -22,7 +22,9 @@ CUtlString CLDProject::Link( void )
szFileName = CUtlString("lib%s.so", m_szName.GetString());
break;
}
CUtlString szOutputFile = CUtlString("%s/ld/%u_%s/%s",FPC_TEMPORAL_DIRNAME, hash, m_szName.GetString(), szFileName.GetString());
CUtlString szTarget = m_target.GetTriplet();
CUtlString szOutputFile = CUtlString("%s/%s/ld/%u_%s/%s",FPC_TEMPORAL_DIRNAME, szTarget.GetString(), hash, m_szName.GetString(), szFileName.GetString());
CUtlString szOutputDir = szOutputFile;
szOutputDir = dirname(szOutputDir);
IFileSystem2::MakeDirectory(szOutputDir);
@@ -65,7 +67,21 @@ CUtlString CLDProject::Link( void )
args = {
"-o",
szOutputFile,
"-target",
m_target.GetTriplet(),
};
if (m_target.kernel == TARGET_KERNEL_DARWIN)
{
args.AppendTail("-isysroot");
args.AppendTail("/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk");
}
if (m_target.kernel == TARGET_KERNEL_IOS)
{
args.AppendTail("-isysroot");
args.AppendTail("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk");
args.AppendTail("-miphoneos-version-min=18.0 ");
args.AppendTail("-fembed-bitcode");
}
if (m_target.kernel == TARGET_KERNEL_LINUX)
{
args.AppendTail("-rdynamic");

View File

@@ -2,6 +2,44 @@
#include "tier1/commandline.h"
#include "tier1/utlstring.h"
CUtlString Target_t::GetTriplet()
{
CUtlString triplet = "";
if ( cpu == TARGET_CPU_AMD64 )
triplet.AppendTail("x86_64");
if ( cpu == TARGET_CPU_AARCH64 )
triplet.AppendTail("aarch64");
triplet.AppendTail("-");
if ( kernel == TARGET_KERNEL_WINDOWS )
triplet.AppendTail("pc-windows-gnu");
if ( kernel == TARGET_KERNEL_LINUX )
triplet.AppendTail("unknown-linux-gnu");
if ( kernel == TARGET_KERNEL_DARWIN )
triplet.AppendTail("apple-darwin");
if ( kernel == TARGET_KERNEL_IOS )
triplet.AppendTail("apple-ios");
return triplet;
}
Target_t Target_t::HostTarget()
{
ETargetKernel kernel =
#if defined(__linux__)
TARGET_KERNEL_LINUX
#elif defined(__APPLE__)
TARGET_KERNEL_DARWIN
#endif
;
ETargetCPU cpu = TARGET_CPU_AMD64;
return {
.kernel = kernel,
.cpu = cpu,
.optimization = TARGET_DEBUG,
};
};
Target_t Target_t::DefaultTarget()
{
CUtlString szDevice = ICommandLine::ParamValue("-device");
@@ -16,6 +54,10 @@ Target_t Target_t::DefaultTarget()
#endif
;
ETargetCPU cpu = TARGET_CPU_AMD64;
if ( szArch == "x86_64" )
cpu = TARGET_CPU_AMD64;
else if ( szArch == "aarch64" )
cpu = TARGET_CPU_AARCH64;
if ( szOS == "windows" )
kernel = TARGET_KERNEL_WINDOWS;
@@ -23,6 +65,8 @@ Target_t Target_t::DefaultTarget()
kernel = TARGET_KERNEL_LINUX;
else if ( szOS == "macos" )
kernel = TARGET_KERNEL_DARWIN;
else if ( szOS == "ios" )
kernel = TARGET_KERNEL_IOS;
else if ( szOS != 0 )
V_printf("Unknown OS: %s\n", szOS.GetString());

View File

@@ -1,6 +1,7 @@
#include "public/c.h"
#include "public/helper.h"
#include "public/ld.h"
#include "public/target.h"
#include "tier0/platform.h"
#include "tier1/commandline.h"
#include "c.h"
@@ -20,10 +21,18 @@ int build()
compileScriptProject.files = {"build.cpp"};
compileScriptProject.includeDirectories = {CUtlString("%s/public",IFileSystem2::OwnDirectory()),CUtlString("%s/public", IFileSystem2::BuildDirectory()), CUtlString("%s/../public",IFileSystem2::OwnDirectory()),CUtlString("%s/../public", IFileSystem2::BuildDirectory())};
compileScriptProject.bFPIC = true;
compileScriptProject.m_target = Target_t::HostTarget();
CLDProject linkScriptProject = compileScriptProject.Compile();
linkScriptProject.linkType = ELINK_DYNAMIC_LIBRARY;
linkScriptProject.m_target = Target_t::HostTarget();
CUtlString script = linkScriptProject.Link();
void *scriptDLL = Plat_LoadLibrary(script);
auto PreinitFn = (void(*)())Plat_GetProc(scriptDLL, "Preinit");
V_printf("%p\n",PreinitFn);
if (PreinitFn)
PreinitFn();
for (auto &build: BuildStages())
{
build->m_pMainFn();
@@ -46,7 +55,7 @@ void IEngine_Signal(int sig)
default:
break;
};
_exit(0);
Plat_Exit(0);
};
int main(int c, char **v)

View File

@@ -1,17 +1,21 @@
#ifndef TARGET_T
#define TARGET_T
#include "tier1/utlstring.h"
enum ETargetKernel
{
TARGET_KERNEL_LINUX,
TARGET_KERNEL_WINDOWS,
TARGET_KERNEL_DARWIN,
TARGET_KERNEL_IOS,
};
enum ETargetCPU
{
TARGET_CPU_AMD64,
TARGET_CPU_I386,
TARGET_CPU_AARCH64,
};
enum ETargetOptimization
@@ -26,6 +30,8 @@ struct Target_t
ETargetKernel kernel;
ETargetCPU cpu;
ETargetOptimization optimization;
CUtlString GetTriplet();
static Target_t HostTarget();
static Target_t DefaultTarget();
};

View File

@@ -1,39 +0,0 @@
#include "god/build.h"
#include "god/slang.h"
#include "god/utils.h"
#include "god/common.h"
void build_shader(char *name, enum slang_stage stage)
{
struct slang_settings shadercc = {
.entry = string_clone("funnyassets/gfx_shaders/%s.slang", name),
.stage = stage,
.output_type = SLANG_OUTPUT_SPIRV,
};
char *file = slang_compile(shadercc);
mv(string_clone("funnyassets/_rtt/gfx/%s.spv",name),file);
};
void makepak(struct build_data b, char *name)
{
struct run_project rp = run_new("python");
run_add_arg(&rp, "tools/makepak64.py");
run_add_arg(&rp, string_clone("funnyassets/_%s",name));
run_add_arg(&rp, string_clone("build/"GAME_NAME"/game/"GAME_NAME"/%s.pak", name));
run_run(&rp);
};
void assets_build(struct build_data b)
{
remove("funnyassets/_rtt");
makedir("funnyassets/_rtt/gfx");
build_shader("brush_frag", SLANG_STAGE_FRAGMENT);
build_shader("brush_vert", SLANG_STAGE_VERTEX);
build_shader("mesh_frag", SLANG_STAGE_FRAGMENT);
build_shader("mesh_vert", SLANG_STAGE_VERTEX);
mv("funnyassets/_rtt/","funnyassets/maps");
mv("funnyassets/_rtt/","funnyassets/gfx");
mv("funnyassets/_rtt/","funnyassets/textures");
mv("funnyassets/_rtt/","funnyassets/materials");
makepak(b, "rtt");
}

View File

@@ -7,15 +7,12 @@
void build_shader( const char *szName )
{
const char *szGameName = ICommandLine::ParamValue("-game");
if (szGameName == NULL)
szGameName = "funnygame";
IFileSystem2::MakeDirectory(CUtlString("build/%s/assets/gfx",szGameName));
IFileSystem2::MakeDirectory(CUtlString("build/funnygame/assets/gfx"));
CUtlVector<CUtlString> slang_args = {
CUtlString("funnyassets/gfx_shaders/%s.slang", szName),
"-o",
CUtlString("build/%s/assets/gfx/%s.spv", szGameName, szName),
CUtlString("build/funnygame/assets/gfx/%s.spv", szName),
};
IRunner::Run("slangc", slang_args);
@@ -25,21 +22,19 @@ void build_shader( const char *szName )
int assets_build()
{
IFileSystem2::CopyDirectory("build", "tools");
const char *szGameName = ICommandLine::ParamValue("-game");
if (szGameName == NULL)
szGameName = "funnygame";
IFileSystem2::CopyDirectory(CUtlString("build/%s/assets",szGameName), "funnyassets/maps");
IFileSystem2::CopyDirectory(CUtlString("build/%s/assets",szGameName), "funnyassets/gfx");
IFileSystem2::CopyDirectory(CUtlString("build/%s/assets",szGameName), "funnyassets/textures");
IFileSystem2::CopyDirectory(CUtlString("build/%s/assets",szGameName), "funnyassets/materials");
IFileSystem2::CopyDirectory(CUtlString("build/funnygame/assets"), "funnyassets/maps");
IFileSystem2::CopyDirectory(CUtlString("build/funnygame/assets"), "funnyassets/gfx");
IFileSystem2::CopyDirectory(CUtlString("build/funnygame/assets"), "funnyassets/textures");
IFileSystem2::CopyDirectory(CUtlString("build/funnygame/assets"), "funnyassets/materials");
build_shader("mesh_frag");
build_shader("mesh_vert");
build_shader("agx_comp");
build_shader("mesh_edge_detection_comp");
CUtlVector<CUtlString> python_args = {
"build/tools/makepak64.py",
CUtlString("build/%s/assets", szGameName),
CUtlString("build/%s/game/%s/%s.pak", szGameName, szGameName, "rtt"),
CUtlString("build/funnygame/assets"),
CUtlString("%s/funnygame/%s.pak", szOutputDir.GetString(), "rtt"),
};
IRunner::Run("python", python_args);
return 0;

Binary file not shown.

View File

@@ -261849,5 +261849,5 @@
}
{
"classname" "info_player_start"
"origin" "10 -50 20"
"origin" "10 -50 3"
}

View File

@@ -1,35 +0,0 @@
#include "god/build.h"
#include "god/c.h"
#include "god/ld.h"
char* client_dll = 0;
void client_build(struct build_data b)
{
char* files[] = {
"game/client/baseplayer.cpp",
NULL,
};
struct project p = {
.b = &b,
.files = files,
.name = "client",
};
struct project o = C_compile(p, (struct C_settings){
.generation_flags = C_GENERATION_FLAGS_PIC,
.compile_flags = C_COMPILE_FLAGS_WALL,
.include_dirs = include_dirs,
});
char* libs[] = {
"c",
NULL,
};
client_dll = ld_link_project(o, (struct link_settings){
.type = LINK_TYPE_DYNAMIC,
.libs = libs,
});
mv("build/"GAME_NAME"/game/"GAME_NAME"/bin/libclient.so",server_dll);
}

View File

@@ -18,15 +18,20 @@ int client_build()
compileProject.includeDirectories = all_IncludeDirectories;
compileProject.bFPIC = true;
ldProject = compileProject.Compile();
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
if (bStaticBuild)
ldProject.linkType = ELINK_STATIC_LIBRARY;
else
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
CUtlString outputProject = ldProject.Link();
const char *szGameName = ICommandLine::ParamValue("-game");
if (szGameName == NULL)
szGameName = "funnygame";
IFileSystem2::MakeDirectory(CUtlString("build/%s/game/%s/bin",szGameName, szGameName));
IFileSystem2::CopyFile(CUtlString("build/%s/game/%s/bin",szGameName,szGameName), outputProject);
if (!bStaticBuild)
{
IFileSystem2::MakeDirectory(CUtlString("%s/funnygame/bin",szOutputDir.GetString()));
IFileSystem2::CopyFile(CUtlString("%s/funnygame/bin", szOutputDir.GetString()), outputProject);
} else {
client_lib = outputProject;
}
return 0;
};

View File

@@ -1,6 +1,9 @@
#include "baseplayer.h"
#include "cglm/affine-pre.h"
#include "cglm/mat4.h"
#include "engine.h"
#include "rendering.h"
#include "input.h"
class C_MOBAPlayer: public C_BaseEntity
{
@@ -27,6 +30,13 @@ void C_MOBAPlayer::Destroy()
}
void C_MOBAPlayer::Think( float fDelta )
{
float x = g_fAxisValues[AXIS_MOUSE_X];
float y = g_fAxisValues[AXIS_MOUSE_Y];
float fPitch = glm_rad(x);
float fYaw = glm_rad(y);
glm_mat4_identity(g_cameraView);
glm_rotate_z(g_cameraView, fYaw, g_cameraView);
glm_rotate_y(g_cameraView, fPitch, g_cameraView);
if (g_localClient.pBasePlayer == pEntity)
{
g_cameraView[3][0] = pEntity->m_position[0];

View File

@@ -1,36 +0,0 @@
#include "god/build.h"
#include "god/c.h"
#include "god/ld.h"
#include "libgen.h"
char* server_dll = 0;
void server_build(struct build_data b)
{
char* files[] = {
"game/server/game.cpp",
"game/server/baseplayer.cpp",
NULL,
};
struct project p = {
.b = &b,
.files = files,
.name = "server",
};
struct project o = C_compile(p, (struct C_settings){
.generation_flags = C_GENERATION_FLAGS_PIC,
.compile_flags = C_COMPILE_FLAGS_WALL,
.include_dirs = include_dirs,
});
char* libs[] = {
"c",
NULL,
};
server_dll = ld_link_project(o, (struct link_settings){
.type = LINK_TYPE_DYNAMIC,
.libs = libs,
});
mv("build/"GAME_NAME"/game/"GAME_NAME"/bin/libserver.so",server_dll);
}

View File

@@ -19,15 +19,20 @@ int server_build()
compileProject.includeDirectories = all_IncludeDirectories;
compileProject.bFPIC = true;
ldProject = compileProject.Compile();
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
if (bStaticBuild)
ldProject.linkType = ELINK_STATIC_LIBRARY;
else
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
CUtlString outputProject = ldProject.Link();
const char *szGameName = ICommandLine::ParamValue("-game");
if (szGameName == NULL)
szGameName = "funnygame";
IFileSystem2::MakeDirectory(CUtlString("build/%s/game/%s/bin",szGameName, szGameName));
IFileSystem2::CopyFile(CUtlString("build/%s/game/%s/bin",szGameName,szGameName), outputProject);
if (!bStaticBuild)
{
IFileSystem2::MakeDirectory(CUtlString("%s/funnygame/bin",szOutputDir.GetString()));
IFileSystem2::CopyFile(CUtlString("%s/funnygame/bin", szOutputDir.GetString()), outputProject);
} else {
server_lib = outputProject;
}
return 0;
};

View File

@@ -1,14 +1,20 @@
#include "baseentity.h"
#include "baseplayer.h"
#include "cglm/mat4.h"
#include "cglm/util.h"
#include "cglm/io.h"
#include "cglm/vec2.h"
#include "cglm/vec3.h"
#include "console.h"
#include "engine.h"
#include "input.h"
#include "math3d.h"
#include "physics.h"
#include "physics_gen.h"
#define STEP_SIZE 0.3f
#define PLAYER_WIDTH 0.5f
#define PLAYER_HEIGHT 1.8f
#define EPSILON 0.0005f
class CMOBAPlayer: public CBasePlayer
{
public:
@@ -18,9 +24,15 @@ public:
virtual void ReadParameter( const char *szName, const char *szValue ) override;
virtual void Think( float fDelta ) override;
void AirAccelerate();
void Accelerate( float fDelta, vec2 wishDir, float fWishSpeed, float fAcceleration );
void Move( float fDelta );
void Accelerate( void );
void AirAccelerate( void );
int ClipVelocity( vec3 in, vec3 normal, vec3 &out, float fOverbounce );
void FlyMove( void );
void GroundMove( void );
void AirMove( void );
void CategorizePosition( void );
void Friction( void );
void PlayerMove( void );
bool bIsForward = 0;
@@ -33,14 +45,25 @@ public:
bool bIsProning = 0;
bool bIsFiring = 0;
bool bIsFiring2 = 0;
float fStamina;
float m_fDelta = 0;
float fPitch = 0;
float fYaw = 0;
vec3 m_velocity;
enum {
PLAYER_GROUNDED,
PLAYER_FLYING,
} m_playerState;
vec3 m_velocity = {0,0,0};
vec3 m_prevVelocity = {0,0,0};
vec2 forward = {};
vec2 right = {};
CPxBoxMesh mesh;
CPxRigidBody rigidbody;
CPxRigidKinematicPosition rigidbody;
};
void CMOBAPlayer::Precache()
@@ -50,26 +73,7 @@ void CMOBAPlayer::Precache()
void CMOBAPlayer::Spawn()
{
mesh.m_fRadius[0] = 0.3;
mesh.m_fRadius[1] = 0.3;
mesh.m_fRadius[2] = 0.8;
mesh.Spawn();
px_matrix m = {};
m.m[0] = 1;
m.m[5] = 1;
m.m[10] = 1;
m.m[15] = 1;
m.m[12] = m_position[0];
m.m[13] = m_position[1];
m.m[14] = m_position[2];
rigidbody.Spawn(&mesh, m, {
.gravity_scale = 1,
.continous = true,
.lockrotx = 1,
.lockroty = 1,
.lockrotz = 1,
.dominance = 127,
});
};
@@ -83,68 +87,84 @@ void CMOBAPlayer::Destroy()
}
void CMOBAPlayer::AirAccelerate()
void CMOBAPlayer::AirAccelerate( void )
{
m_velocity[2] -= 9.8 * m_fDelta;
}
void CMOBAPlayer::Accelerate( void )
{
vec2 wishdir = {(float)bIsForward-bIsBack, (float)bIsLeft-bIsRight};
vec3 velocityDifference;
vec3 acceleration;
glm_vec2_rotate(wishdir, fYaw, wishdir);
glm_vec2_normalize(wishdir);
for ( int i = 0; i < 2; i++ )
m_velocity[i] += (wishdir[i]*6 - m_velocity[i]) * m_fDelta/0.25;
}
void CMOBAPlayer::Friction( void )
{
};
void CMOBAPlayer::FlyMove( void )
{
}
void CMOBAPlayer::Accelerate( float fDelta, vec2 wishDir, float fWishSpeed, float fAcceleration )
void CMOBAPlayer::GroundMove( void )
{
float fCurrentSpeed = glm_vec2_dot(wishDir, m_velocity);
float fAddSpeed = fWishSpeed - fCurrentSpeed;
if ( fAddSpeed < 0 )
return;
float fAccelSpeed = fAcceleration*fDelta*fWishSpeed;
if ( fAccelSpeed > fAddSpeed )
fAccelSpeed = fAddSpeed;
glm_vec2_scale(wishDir, fAccelSpeed, m_velocity);
m_velocity[2] = 0;
Accelerate();
}
void CMOBAPlayer::Move( float fDelta )
void CMOBAPlayer::CategorizePosition( void )
{
vec2 forward = {(float)bIsForward-(float)bIsBack,0};
vec2 right = {0,(float)bIsLeft-(float)bIsRight};
vec2 wishDir;
float fWishSpeed;
px_vec3 p;
px_cast_result r;
p.m[0] = m_position[0];
p.m[1] = m_position[1];
p.m[2] = m_position[2];
r = px_box_cast(px, PLAYER_WIDTH/2, PLAYER_WIDTH/2, PLAYER_HEIGHT/2, p, (px_vec3){}, (px_vec3){0,0,-0.01}, 1);
glm_vec2_rotate(forward, fYaw, forward);
glm_vec2_rotate(forward, fYaw, forward);
glm_vec2_add(forward, right, wishDir);
fWishSpeed = glm_vec2_distance(wishDir, (vec3){0,0,0});
if (fWishSpeed != 0)
if (r.hit)
{
glm_vec2_divs(wishDir, fWishSpeed, wishDir);
fWishSpeed = 10;
m_playerState = PLAYER_GROUNDED;
} else {
glm_vec2_zero(wishDir);
m_playerState = PLAYER_FLYING;
}
Accelerate(fDelta, wishDir, fWishSpeed, 5.5);
}
void CMOBAPlayer::PlayerMove( void )
{
CategorizePosition();
GroundMove();
vec3 velocity;
for ( int i = 0; i < 3; i++ )
velocity[i] = (m_prevVelocity[i] + m_velocity[i]) * 0.5;
for ( int i = 0; i < 3; i++ )
m_position[i] += velocity[i] * m_fDelta;
for ( int i = 0; i < 3; i++ )
m_prevVelocity[i] = m_velocity[i];
CategorizePosition();
}
void CMOBAPlayer::Think( float fDelta )
{
m_position[0] = rigidbody.GetPosition().m[0];
m_position[1] = rigidbody.GetPosition().m[1];
m_position[2] = rigidbody.GetPosition().m[2];
px_vec3 v = rigidbody.GetVelocity();
px_vec3 p = rigidbody.GetPosition();
float x = g_fAxisValues[AXIS_MOUSE_X];
float y = g_fAxisValues[AXIS_MOUSE_Y];
fPitch = glm_rad(x);
fYaw = glm_rad(y);
for (int i = 0; i < 3; i++)
m_velocity[i] = v.m[i];
m_fDelta = fDelta;
px_cast_result r = px_box_cast(px, 0.3,0.3,0.01, {p.m[0],p.m[1],p.m[2]-0.79f}, {0,0,0}, {0,0,-1}, 1);
if (r.hit)
{
Move(fDelta);
}
for (int i = 0; i < 3; i++)
v.m[i] = m_velocity[i];
rigidbody.SetVelocity(v);
PlayerMove();
};
void PlayerForward(int argc, char **argv) {if (g_localClient.pBasePlayer) ((CMOBAPlayer*)g_localClient.pBasePlayer)->bIsForward = true;};

View File

@@ -0,0 +1,336 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 77;
objects = {
/* Begin PBXFileReference section */
24CCF9852E1065A100A06964 /* funnygame.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = funnygame.app; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
24CCF99C2E1065A300A06964 /* Exceptions for "funnygame" folder in "funnygame" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
Info.plist,
);
target = 24CCF9842E1065A100A06964 /* funnygame */;
};
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
/* Begin PBXFileSystemSynchronizedRootGroup section */
24CCF9872E1065A100A06964 /* funnygame */ = {
isa = PBXFileSystemSynchronizedRootGroup;
exceptions = (
24CCF99C2E1065A300A06964 /* Exceptions for "funnygame" folder in "funnygame" target */,
);
path = funnygame;
sourceTree = "<group>";
};
/* End PBXFileSystemSynchronizedRootGroup section */
/* Begin PBXFrameworksBuildPhase section */
24CCF9822E1065A100A06964 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
24CCF97C2E1065A100A06964 = {
isa = PBXGroup;
children = (
24CCF9872E1065A100A06964 /* funnygame */,
24CCF9862E1065A100A06964 /* Products */,
);
sourceTree = "<group>";
};
24CCF9862E1065A100A06964 /* Products */ = {
isa = PBXGroup;
children = (
24CCF9852E1065A100A06964 /* funnygame.app */,
);
name = Products;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
24CCF9842E1065A100A06964 /* funnygame */ = {
isa = PBXNativeTarget;
buildConfigurationList = 24CCF99D2E1065A300A06964 /* Build configuration list for PBXNativeTarget "funnygame" */;
buildPhases = (
24CCF9812E1065A100A06964 /* Sources */,
24CCF9822E1065A100A06964 /* Frameworks */,
24CCF9832E1065A100A06964 /* Resources */,
);
buildRules = (
);
dependencies = (
);
fileSystemSynchronizedGroups = (
24CCF9872E1065A100A06964 /* funnygame */,
);
name = funnygame;
packageProductDependencies = (
);
productName = funnygame;
productReference = 24CCF9852E1065A100A06964 /* funnygame.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
24CCF97D2E1065A100A06964 /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastUpgradeCheck = 1620;
TargetAttributes = {
24CCF9842E1065A100A06964 = {
CreatedOnToolsVersion = 16.2;
};
};
};
buildConfigurationList = 24CCF9802E1065A100A06964 /* Build configuration list for PBXProject "funnygame" */;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 24CCF97C2E1065A100A06964;
minimizedProjectReferenceProxies = 1;
preferredProjectObjectVersion = 77;
productRefGroup = 24CCF9862E1065A100A06964 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
24CCF9842E1065A100A06964 /* funnygame */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
24CCF9832E1065A100A06964 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
24CCF9812E1065A100A06964 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
24CCF99E2E1065A300A06964 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = QU3M3RV4XD;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = funnygame/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = kotofyt.funnygame;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
24CCF99F2E1065A300A06964 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = QU3M3RV4XD;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = funnygame/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = kotofyt.funnygame;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
24CCF9A02E1065A300A06964 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.2;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
name = Debug;
};
24CCF9A12E1065A300A06964 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.2;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
24CCF9802E1065A100A06964 /* Build configuration list for PBXProject "funnygame" */ = {
isa = XCConfigurationList;
buildConfigurations = (
24CCF9A02E1065A300A06964 /* Debug */,
24CCF9A12E1065A300A06964 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
24CCF99D2E1065A300A06964 /* Build configuration list for PBXNativeTarget "funnygame" */ = {
isa = XCConfigurationList;
buildConfigurations = (
24CCF99E2E1065A300A06964 /* Debug */,
24CCF99F2E1065A300A06964 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 24CCF97D2E1065A100A06964 /* Project object */;
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>funnygame.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,35 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "tinted"
}
],
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,15 @@
//
// SceneDelegate.h
// funnygame
//
// Created by kotofyt on 28.06.2025.
//
#import <UIKit/UIKit.h>
@interface SceneDelegate : UIResponder <UIWindowSceneDelegate>
@property (strong, nonatomic) UIWindow * window;
@end

View File

@@ -0,0 +1,57 @@
//
// SceneDelegate.m
// funnygame
//
// Created by kotofyt on 28.06.2025.
//
#import "SceneDelegate.h"
@interface SceneDelegate ()
@end
@implementation SceneDelegate
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
}
- (void)sceneDidDisconnect:(UIScene *)scene {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
}
- (void)sceneDidBecomeActive:(UIScene *)scene {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
}
- (void)sceneWillResignActive:(UIScene *)scene {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}
- (void)sceneWillEnterForeground:(UIScene *)scene {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}
- (void)sceneDidEnterBackground:(UIScene *)scene {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
}
@end

View File

@@ -0,0 +1,14 @@
//
// ViewController.h
// funnygame
//
// Created by kotofyt on 28.06.2025.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end

View File

@@ -0,0 +1,18 @@
//
// main.m
// funnygame
//
// Created by kotofyt on 28.06.2025.
//
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
NSString * appDelegateClassName;
@autoreleasepool {
// Setup code that might create autoreleased objects goes here.
appDelegateClassName = NSStringFromClass([AppDelegate class]);
}
return UIApplicationMain(argc, argv, nil, appDelegateClassName);
}

View File

@@ -1,35 +0,0 @@
#include "god/c.h"
#include "god/ld.h"
#include "god/utils.h"
void launcher_build(struct build_data b)
{
char* files[] = {
"launcher/launcher.cpp",
NULL,
};
struct project p = {
.b = &b,
.files = files,
.name = "launcher",
};
struct project o = C_compile(p, (struct C_settings){
.generation_flags = C_GENERATION_FLAGS_PIC,
.compile_flags = C_COMPILE_FLAGS_WALL,
.include_dirs = include_dirs,
});
char* libs[] = {
"c",
NULL,
};
char* launcher_dll = ld_link_project(o, (struct link_settings){
.type = LINK_TYPE_EXECUTABLE,
.libs = libs,
});
mv("build/"GAME_NAME"/game/bin/"GAME_NAME,launcher_dll);
}

View File

@@ -19,12 +19,19 @@ int launcher_build()
ldProject = compileProject.Compile();
ldProject.linkType = ELINK_EXECUTABLE;
if (bStaticBuild)
{
ldProject.objects.AppendTail((CObject){tier0_lib});
ldProject.objects.AppendTail((CObject){tier1_lib});
ldProject.objects.AppendTail((CObject){rapier_lib});
ldProject.objects.AppendTail((CObject){engine_lib});
ldProject.objects.AppendTail((CObject){server_lib});
ldProject.objects.AppendTail((CObject){client_lib});
};
CUtlString outputProject = ldProject.Link();
const char *szGameName = ICommandLine::ParamValue("-game");
if (szGameName == NULL)
szGameName = "funnygame";
IFileSystem2::MakeDirectory(CUtlString("build/%s/game/bin",szGameName));
IFileSystem2::CopyFile(CUtlString("build/%s/game/bin/%s", szGameName, szGameName), outputProject);
IFileSystem2::MakeDirectory(CUtlString("%s/bin",szOutputDir.GetString()));
IFileSystem2::CopyFile(CUtlString("%s/bin/funnygame", szOutputDir.GetString()), outputProject);
return 0;
};

View File

@@ -3,6 +3,9 @@
#include "unistd.h"
#include "dlfcn.h"
#include "libgen.h"
#ifdef __APPLE__
#include <mach-o/dyld.h>
#endif
#define MAX_PATH 4096
@@ -16,26 +19,33 @@ typedef void (*EngineMainFn)(int argc, char** argv);
EngineMainFn pEngineMain;
int main( int argc, char **argv ) {
#ifdef __linux__
readlink("/proc/self/exe",szLauncherPath, MAX_PATH);
dirname(szLauncherPath);
snprintf(szEnginePath, MAX_PATH, "%s/libengine.so", szLauncherPath);
snprintf(szTier0Path, MAX_PATH, "%s/libtier0.so", szLauncherPath);
printf("%s\n",szEnginePath);
printf("%s\n",szTier0Path);
#endif
#ifdef __APPLE__
uint32_t pathSize = sizeof(szLauncherPath);
int pathResult = _NSGetExecutablePath(szLauncherPath, &pathSize);
printf("%s\n",szLauncherPath);
char *szLauncherPath2 = dirname(szLauncherPath);
printf("%s\n",szLauncherPath2);
snprintf(szEnginePath, MAX_PATH, "%s/libengine.dylib", szLauncherPath2);
snprintf(szTier0Path, MAX_PATH, "%s/libtier0.dylib", szLauncherPath2);
#endif
pTier0Lib = dlopen(szTier0Path, RTLD_NOW | RTLD_GLOBAL);
if ( !pTier0Lib ) {
printf("Failed to open libtier0.so\n");
printf("Failed to open libtier0\n");
printf("\t%s\n",dlerror());
}
pEngineLib = dlopen(szEnginePath, RTLD_NOW | RTLD_GLOBAL);
if ( !pEngineLib ) {
printf("Failed to open libengine.so\n");
printf("Failed to open libengine\n");
printf("\t%s\n",dlerror());
}
printf("\t%p\n",pTier0Lib);
printf("\t%p\n",pEngineLib);
pEngineMain = (EngineMainFn)dlsym(pEngineLib, "FunnyMain");
if ( !pEngineMain ) {
printf("Symbol not found: FunnyMain\n");

View File

@@ -61,8 +61,7 @@ CEntityRegistry __entity_##name##_registry(#name, #class, __entity_alloc_##name)
//-----------------------------------------------------------------------------
// Base client entity class.
// It recieves pure server data, which has to be interpolated by the client to
// get smoother image.
// It uses server data directly.
//-----------------------------------------------------------------------------
class C_BaseEntity
{

View File

@@ -5,6 +5,7 @@
#include "rendering.h"
#include "baseentity.h"
#include "physics.h"
#include "mesh.h"
//-----------------------------------------------------------------------------
// Basic triangle structure which is used in brush entities.
@@ -51,8 +52,6 @@ private:
IVertexBuffer *vertexBuffer;
IIndexBuffer *indexBuffer;
IMesh *mesh;
IMaterial material;
ITexture *pAlbedo;
};
#endif

View File

@@ -13,15 +13,20 @@ typedef void(*ConCommandFn)(int argc, char **argv);
interface IConsole
{
public:
// Variables
static void RegisterVar( ConVar *cvar );
static void UnRegisterVar( ConVar *cvar );
static ConVar *FindVar( const char *pName );
// Commands
static void RegisterCommand( ConCommand *cvar );
static void UnRegisterCommand( ConCommand *cvar );
static ConCommand *FindCommand( const char *pName );
// Command buffer
static void Execute( void );
static CUtlVector<CUtlVector<CUtlString>> ParseCommandLine( CUtlString psz );
static void AddCommand( const char *psz );
static void InsertCommand( const char *psz );
private:

View File

@@ -3,6 +3,11 @@
#include "tier0/platform.h"
//-----------------------------------------------------------------------------
// Keys include mouse buttons and gamepad buttons as well.
// KEY_NONE and AXIS_NONE are garbage, so don't rely on them
//-----------------------------------------------------------------------------
enum EKeyEventType
{
KEY_EVENT_TYPE_DOWN,
@@ -81,13 +86,24 @@ enum EInputKey
KEY_X,
KEY_Y,
KEY_Z,
KEY_MAX,
KEY_NUM_KEYS = KEY_MAX - 1,
};
enum EInputAxis
{
AXIS_NONE,
AXIS_MOUSE_X,
AXIS_MOUSE_Y,
AXIS_MOUSE_SCROLL,
AXIS_MAX,
AXIS_NUM_AXIS = AXIS_MAX - 1,
};
enum EMouseMode
{
MOUSE_MODE_GAME,
MOUSE_MODE_MENU,F
};
interface IInput
@@ -95,9 +111,12 @@ interface IInput
public:
static void Init( void );
static void KeyEvent( EInputKey key, EKeyEventType event );
static void AxisEvent( unsigned char axis, float fX, float fY );
static void AxisEvent( EInputAxis axis, float fValue );
static void SetMouseMode( EMouseMode mode );
static void Frame( void );
static void Deinit( void );
};
extern float g_fAxisValues[AXIS_NUM_AXIS];
#endif

View File

@@ -4,5 +4,10 @@
#include "tier0/minmax_off.h"
#include "cglm/cglm.h"
#include "cglm/affine.h"
#include "cglm/mat4.h"
#include "cglm/mat3.h"
#include "cglm/mat2.h"
#include "tier0/minmax.h"
#define PX_GLM_VEC3(v) (px_vec3){v[0], v[1], v[2]}
#endif

31
public/mesh.h Normal file
View File

@@ -0,0 +1,31 @@
#include "rendering.h"
//----------------------------------------------------------------------------
// Mesh handler for the rendering
//----------------------------------------------------------------------------
abstract_class IMesh
{
public:
virtual void SetVertexBuffer( IVertexBuffer *pBuffer ) = 0;
virtual void SetIndexBuffer( IIndexBuffer *pBuffer ) = 0;
virtual void SetPosition( vec3 position ) = 0;
virtual void SetRotationEuler( vec3 angle ) = 0;
virtual void SetRotationQuat( vec4 quaternion) = 0;
virtual void SetMatrix( mat4 matrix ) = 0;
virtual void SetScale( vec3 scale ) = 0;
virtual void Draw() = 0;
};
interface IMeshRendering: public IRenderingPipelineStep
{
public:
virtual IMesh *CreateMesh();
};
interface IModelManager
{
public:
virtual void LoadModel( const char *szPath );
};

View File

@@ -4,6 +4,7 @@
#include "tier0/lib.h"
#include "stdint.h"
#include "tier1/utlvector.h"
#include "math3d.h"
typedef void Collider;
@@ -23,10 +24,25 @@ typedef struct u128 {
extern funnyphysics *px;
struct PxCastResult_t
{
bool bHit;
float fTime;
vec3 position;
vec3 normal;
vec3 normal2;
};
interface IPxWorld
{
public:
static PxCastResult_t BoxCast( vec3 size, vec3 origin, vec3 destination, vec3 rotation = (vec3){0,0,0} );
};
class CPxCollider
{
public:
virtual void Spawn( float fFriction = 0.5 ) = 0;
virtual void Spawn( float fFriction = 0.0 ) = 0;
virtual void Destroy( void );
Collider *m_pCollider;
};
@@ -34,7 +50,7 @@ public:
class CPxBallMesh: public CPxCollider
{
public:
virtual void Spawn( float fFriction = 0.5 ) override;
virtual void Spawn( float fFriction = 0.0 ) override;
virtual void Destroy( void ) override;
float m_fRadius;
};
@@ -42,7 +58,7 @@ public:
class CPxBoxMesh: public CPxCollider
{
public:
virtual void Spawn( float fFriction = 0.5 ) override;
virtual void Spawn( float fFriction = 0.0 ) override;
virtual void Destroy( void ) override;
float m_fRadius[3];
};
@@ -50,7 +66,7 @@ public:
class CPxTriangleMesh: public CPxCollider
{
public:
virtual void Spawn( float fFriction = 0.5 ) override;
virtual void Spawn( float fFriction = 0.0 ) override;
virtual void Destroy( void ) override;
};
@@ -58,6 +74,8 @@ class CPxRigidKinematicPosition
{
public:
void Spawn( CPxCollider *pCollider, px_matrix matrix, px_rigidbody_params params );
void SetPosition( px_vec3 position );
void SetPositionTeleport( px_vec3 position );
px_vec3 GetPosition( void );
px_matrix GetMatrix ( void );
void Destroy( void );

View File

@@ -5,109 +5,234 @@
#include "tier0/platform.h"
#include "tier1/utlbuffer.h"
#include "baseentity.h"
#include "tier1/utlstring.h"
#include "tier1/utlvector.h"
extern mat4 g_cameraView;
enum EImageFormat
{
IMAGE_FORMAT_R8,
IMAGE_FORMAT_R8G8,
IMAGE_FORMAT_R8G8B8,
IMAGE_FORMAT_R8G8B8A8,
IMAGE_FORMAT_R16,
IMAGE_FORMAT_R16G16,
IMAGE_FORMAT_R16G16B16,
IMAGE_FORMAT_R16G16B16A16,
IMAGE_FORMAT_R32,
IMAGE_FORMAT_R32G32,
IMAGE_FORMAT_R32G32B32,
IMAGE_FORMAT_R32G32B32A32,
IMAGE_FORMAT_DEPTH,
IMAGE_FORMAT_RENDERING = IMAGE_FORMAT_R8G8B8A8,
};
enum EImageUsage
{
IMAGE_USAGE_COLOR_ATTACHMENT = 0x1,
IMAGE_USAGE_DEPTH_ATTACHMENT = 0x2,
IMAGE_USAGE_STORAGE = 0x4,
};
enum EVertexFormat
{
VERTEX_FORMAT_X16,
VERTEX_FORMAT_X16Y16,
VERTEX_FORMAT_X16Y16Z16,
VERTEX_FORMAT_X16Y16Z16W16,
VERTEX_FORMAT_X32,
VERTEX_FORMAT_X32Y32,
VERTEX_FORMAT_X32Y32Z32,
VERTEX_FORMAT_X32Y32Z32W32,
};
enum EMSAAMode
{
MSAA_MODE_DISABLED,
MSAA_MODE_MIN,
MSAA_MODE_MAX,
MSAA_MODE_AVERAGE,
};
enum EDepthMode
{
DEPTH_MODE_DISABLED,
DEPTH_MODE_EQUAL,
DEPTH_MODE_NOT_EQUAL,
DEPTH_MODE_LESS,
DEPTH_MODE_LESS_EQUAL,
DEPTH_MODE_GREATER,
DEPTH_MODE_GREATER_EQUAL,
};
enum EShaderInputType
{
SHADER_INPUT_TYPE_STORAGE_BUFFER,
SHADER_INPUT_TYPE_UNIFORM_BUFFER,
SHADER_INPUT_TYPE_IMAGE,
SHADER_INPUT_TYPE_TLAS,
// All available textures are binded
SHADER_INPUT_TYPE_TEXTURES,
};
enum EShaderType
{
SHADER_TYPE_VERTEX,
SHADER_TYPE_GEOMETRY,
SHADER_TYPE_FRAGMENT,
SHADER_TYPE_COMPUTE,
SHADER_TYPE_RAY_GEN,
SHADER_TYPE_CLOSEST_HIT,
SHADER_TYPE_MISS,
SHADER_TYPE_INTERSECTION,
SHADER_TYPE_ANY_HIT,
};
enum EBarrierMemoryPermissions
{
BARRIER_MEMORY_PERMISSIONS_VERTEX_BUFFER_READ = 0x1,
BARRIER_MEMORY_PERMISSIONS_INDEX_BUFFER_READ = 0x2,
BARRIER_MEMORY_PERMISSIONS_UNIFORM_BUFFER_READ = 0x4,
BARRIER_MEMORY_PERMISSIONS_SHADER_READ = 0x8,
BARRIER_MEMORY_PERMISSIONS_SHADER_WRITE = 0x10,
BARRIER_MEMORY_PERMISSIONS_COLOR_READ = 0x20,
BARRIER_MEMORY_PERMISSIONS_COLOR_WRITE = 0x40,
BARRIER_MEMORY_PERMISSIONS_DEPTH_READ = 0x80,
BARRIER_MEMORY_PERMISSIONS_DEPTH_WRITE = 0x100,
BARRIER_MEMORY_PERMISSIONS_COPY_READ = 0x200,
BARRIER_MEMORY_PERMISSIONS_COPY_WRITE = 0x400,
};
enum EBarrierStage
{
BARRIER_STAGE_TOP,
BARRIER_STAGE_VERTEX_INPUT,
BARRIER_STAGE_VERTEX_SHADER,
BARRIER_STAGE_GEOMETRY_SHADER,
BARRIER_STAGE_FRAGMENT_SHADER,
BARRIER_STAGE_COMPUTE_SHADER,
BARRIER_STAGE_RAY_TRACING_SHADER,
BARRIER_STAGE_BOTTOM,
};
enum EAttachmentLoadMode
{
ATTACHMENT_LOAD_MODE_DONT_CARE,
ATTACHMENT_LOAD_MODE_CLEAR,
ATTACHMENT_LOAD_MODE_LOAD,
};
enum EAttachmentStoreMode
{
ATTACHMENT_STORE_MODE_DONT_CARE,
ATTACHMENT_STORE_MODE_STORE,
};
enum EPipelineType
{
PIPELINE_TYPE_RASTERIZATION,
PIPELINE_TYPE_COMPUTE,
PIPELINE_TYPE_RAY_TRACING,
};
interface IVideo
{
public:
static void Init();
static void CreatePipelines( void );
static void Frame( float fDelta );
};
abstract_class IVertexBuffer
abstract_class IBuffer
{
public:
virtual void *Map() = 0;
virtual void Unmap() = 0;
};
abstract_class IIndexBuffer
typedef IBuffer IStorageBuffer;
typedef IBuffer IUniformBuffer;
typedef IBuffer IVertexBuffer;
typedef IBuffer IIndexBuffer;
abstract_class IImage
{
public:
virtual void *Map() = 0;
virtual void Unmap() = 0;
};
enum EMaterialType
{
IMATERIAL_ERROR = 0,
IMATERIAL_PBR = 1,
IMATERIAL_FULLBRIGHT = 2,
};
struct MaterialProperties_t
{
EMaterialType type;
vec3 albedoColor;
const char *szAlbedoTexture;
const char *szNormalsTexture;
const char *szRoughnessTexture;
const char *szMetalnessTexture;
vec2 uvScaling;
};
struct Material_t
{
uint32_t shader;
uint32_t albedo;
uint32_t normal;
uint32_t roughness;
uint32_t metalness;
vec3 albedoColor;
};
abstract_class IMaterial
{
public:
Material_t m;
};
interface IRenderer
{
public:
static IVertexBuffer *CreateVertexBuffer( uint32_t uSize );
static IIndexBuffer *CreateIndexBuffer( uint32_t uSize );
static IMaterial *LoadMaterial( const char *szName );
static void SetMaterial( IMaterial *pMaterial );
EImageFormat format;
};
//----------------------------------------------------------------------------
// Mesh handler for the rendering
// Bottom level acceleration structure for ray tracing.
//----------------------------------------------------------------------------
abstract_class IMesh
abstract_class IBLAS
{
public:
virtual void SetPosition( vec3 position ) = 0;
virtual void SetRotationEuler( vec3 angle ) = 0;
virtual void SetRotationQuat( vec4 quaternion) = 0;
virtual void SetMatrix( mat4 matrix ) = 0;
virtual void SetScale( vec3 scale ) = 0;
virtual void SetVertexBuffer( IVertexBuffer *pBuffer ) = 0;
virtual void SetIndexBuffer( IIndexBuffer *pBuffer ) = 0;
virtual void SetMaterial( IMaterial *pMaterial ) = 0;
virtual void Draw() = 0;
virtual void Build() = 0;
virtual void Update() = 0;
};
interface IMeshRenderer
//----------------------------------------------------------------------------
// Bottom level acceleration structure with triangle geometry.
//----------------------------------------------------------------------------
abstract_class IBLASMesh: public IBLAS
{
public:
static void Init();
static void Frame( float fDelta );
static IMesh *CreateMesh();
static void Destroy( IMesh *pModel );
virtual void SetMesh( IVertexBuffer *pVertex, IIndexBuffer *pIndex ) = 0;
};
//----------------------------------------------------------------------------
// Bottom level acceleration structure with AABB geometry.
//----------------------------------------------------------------------------
abstract_class IBLASAABB: public IBLAS
{
public:
virtual void SetBoundaries( vec4 size );
};
//----------------------------------------------------------------------------
// Top level acceleration structure for handling worlds
//----------------------------------------------------------------------------
abstract_class ITLAS
{
public:
virtual void AddInstance( IBLAS *pBLAS, mat4 matrix, uint32_t data ) = 0;
virtual void ResetInstances() = 0;
};
struct ShaderInput_t
{
EShaderInputType type;
uint32_t binding;
};
struct Shader_t
{
const char *szPath;
EShaderType type;
};
abstract_class IPipeline
{
public:
EPipelineType type;
};
typedef IPipeline IGraphicsPipeline;
typedef IPipeline IComputePipeline;
typedef IPipeline IRayTracingPipeline;
//----------------------------------------------------------------------------
// Texture handle
//----------------------------------------------------------------------------
abstract_class ITexture
{
public:
@@ -115,19 +240,195 @@ public:
uint32_t id;
};
//----------------------------------------------------------------------------
// Manages loaded textures
//----------------------------------------------------------------------------
interface ITextureManager
{
public:
static uint32_t GetTexture(ITexture *pTexture);
static uint32_t GetTextureID(ITexture *pTexture);
static ITexture *LoadTexture( void *pData, uint32_t X, uint32_t Y, uint32_t numChannels );
static ITexture *LoadTexture( const char *szName );
};
interface IPostProcessRenderer
struct BufferBarrier_t
{
public:
static void Init();
static void Frame( float fDelta );
EBarrierMemoryPermissions in;
EBarrierMemoryPermissions out;
IBuffer *pBuffer;
};
struct ImageBarrier_t
{
EBarrierMemoryPermissions in;
EBarrierMemoryPermissions out;
IBuffer *pBuffer;
};
struct VertexAttribute_t
{
uint32_t offset;
uint32_t binding;
EVertexFormat format;
};
struct RenderingColorAttachment_t
{
IImage *pOutput;
IImage *pTemporary;
EAttachmentLoadMode loadMode;
EAttachmentStoreMode storeMode;
EMSAAMode msaaMode;
vec4 clearColor;
};
struct RenderingDepthAttachment_t
{
IImage *pOutput;
IImage *pTemporary;
EAttachmentLoadMode loadMode;
EAttachmentStoreMode storeMode;
EMSAAMode msaaMode;
float clearValue;
};
//----------------------------------------------------------------------------
// Manages all buffers and pipelines.
// It is meant to be used in render pipelines
//----------------------------------------------------------------------------
interface IRenderer
{
public:
static IStorageBuffer *CreateStorageBuffer( uint32_t uSize );
static IUniformBuffer *CreateUniformBuffer( uint32_t uSize );
static IVertexBuffer *CreateVertexBuffer( uint32_t uSize );
static IIndexBuffer *CreateIndexBuffer( uint32_t uSize );
static IImage *CreateImage( EImageFormat format, uint32_t usage, uint32_t nWidth, uint32_t nHeight, uint32_t nSamples = 1 );
static void DestroyBuffer( IBuffer *pBuffer );
static void DestroyImage( IImage *pImage );
static void SetConstants( uint32_t nSize, uint32_t nOffset, void *pData );
static void Barrier( EBarrierStage stageIn, uint32_t stageOut, CUtlVector<BufferBarrier_t> buffers, CUtlVector<ImageBarrier_t> images );
static void BindData( uint32_t binding, IBuffer *pBuffer, IImage* pImage);
static void BindPipeline( IPipeline *pPipeline );
static void Begin( uint32_t nWidth, uint32_t nHeight, CUtlVector<RenderingColorAttachment_t> attachments, RenderingDepthAttachment_t depth );
static void ResetState();
static void SetDepthMode( EDepthMode mode );
static void Draw( IVertexBuffer *pVertex, IIndexBuffer *pIndex );
static void Dispatch( uint32_t x, uint32_t y, uint32_t z );
static void TraceRays( uint32_t x, uint32_t y, uint32_t z );
static void End();
static IGraphicsPipeline *CreateGraphicsPipeline(
CUtlVector<Shader_t> shaders,
CUtlVector<ShaderInput_t> inputs,
uint32_t nConstantsSize,
CUtlVector<EImageFormat> outputFormats
);
static IComputePipeline *CreateComputePipeline(
Shader_t szShader,
CUtlVector<ShaderInput_t> inputs,
uint32_t nConstantsSize
);
static IRayTracingPipeline *CreateRayTracingPipeline(
CUtlVector<Shader_t> shaders,
CUtlVector<ShaderInput_t> inputs,
uint32_t nConstantsSize
);
};
abstract_class IRenderingPipelineStep
{
public:
virtual void Init() = 0;
virtual void Frame( float fDelta ) = 0;
virtual void Deinit() = 0;
};
struct RenderingStep_t
{
IRenderingPipelineStep *pPipeline;
const char *szName;
};
extern CUtlVector<RenderingStep_t> g_StepPrepass;
extern CUtlVector<RenderingStep_t> g_StepMeshRendering;
extern CUtlVector<RenderingStep_t> g_StepShading;
extern CUtlVector<RenderingStep_t> g_StepPostProcessing;
extern CUtlVector<RenderingStep_t> g_StepUI;
typedef IRenderingPipelineStep*(*CreateRenderStepFn)();
class CRenderingStep
{
public:
CRenderingStep();
CRenderingStep(const char *szStepName, CreateRenderStepFn pfn);
};
class CPrepassRenderingStep: public CRenderingStep
{
public:
CPrepassRenderingStep(const char *szStepName, CreateRenderStepFn pfn);
};
class CMeshRenderingStep: public CRenderingStep
{
public:
CMeshRenderingStep(const char *szStepName, CreateRenderStepFn pfn);
};
class CShadingRenderingStep: public CRenderingStep
{
public:
CShadingRenderingStep(const char *szStepName, CreateRenderStepFn pfn);
};
class CPostProcessingRenderingStep: public CRenderingStep
{
public:
CPostProcessingRenderingStep(const char *szStepName, CreateRenderStepFn pfn);
};
class CUIRenderingStep: public CRenderingStep
{
public:
CUIRenderingStep(const char *szStepName, CreateRenderStepFn pfn);
};
#define DECLARE_MESH_PREPASS_STAGE(class, name) \
IRenderingPipelineStep *__rendering_stage_##name() \
{ \
return new class; \
}; \
CPrepassRenderingStep __renering_##name##_registry(#name, __rendering_stage_##name);
#define DECLARE_MESH_RENDERING_STAGE(class, name) \
IRenderingPipelineStep *__rendering_stage_##name() \
{ \
return new class; \
}; \
CMeshRenderingStep __renering_##name##_registry(#name, __rendering_stage_##name);
#define DECLARE_MESH_SHADING_STAGE(class, name) \
IRenderingPipelineStep *__rendering_stage_##name() \
{ \
return new class; \
}; \
CShadingRenderingStep __renering_##name##_registry(#name, __rendering_stage_##name);
#define DECLARE_POST_PROCESSING_STAGE(class, name) \
IRenderingPipelineStep *__rendering_stage_##name() \
{ \
return new class; \
}; \
CPostProcessingRenderingStep __renering_##name##_registry(#name, __rendering_stage_##name);
#define DECLARE_UI_RENDERING_STAGE(class, name) \
IRenderingPipelineStep *__rendering_stage_##name() \
{ \
return new class; \
}; \
CUIRenderingStep __renering_##name##_registry(#name, __rendering_stage_##name);
#endif

View File

@@ -44,6 +44,12 @@
#define V_strtok strtok
#define V_strxfrm strxfrm
#ifdef __WIN32__
#define V_stricmp stricmp
#else
#define V_stricmp strcasecmp
#endif
//-----------------------------------------------------------------------------
// stdio.h
//-----------------------------------------------------------------------------

View File

@@ -57,6 +57,6 @@ PLATFORM_INTERFACE void *Plat_GetProc( void *lib, const char *psz );
PLATFORM_INTERFACE void Plat_UnloadLibrary( void *psz );
PLATFORM_INTERFACE double Plat_GetTime( void );
PLATFORM_INTERFACE void Plat_Exit( int status );
#endif

View File

@@ -9,7 +9,7 @@ interface ICommandLine
public:
static void CreateCommandLine( int argc, char **argv );
static bool CheckParam( char *psz );
static bool CheckParam( const char *psz );
static char *ParamValue( const char* psz );
static void AddParam( char *psz );

View File

@@ -1,29 +0,0 @@
#include "god/build.h"
#include "god/c.h"
#include "god/ld.h"
#include "god/utils.h"
char *rapierLib = NULL;
void rapier_build(struct build_data b)
{
struct run_project cargo_build = run_new("cargo");
cargo_build.wd = "rapier";
run_add_arg(&cargo_build, "build");
run_add_arg(&cargo_build, "--release");
if (b.kernel == BUILD_KERNEL_LINUX)
{
run_add_arg(&cargo_build, "--target");
run_add_arg(&cargo_build, "x86_64-unknown-linux-gnu");
rapierLib = "rapier/target/x86_64-unknown-linux-gnu/release/librapier_rtt.a";
}
run_run(&cargo_build);
struct run_project cbindgen = run_new("cbindgen");
cbindgen.wd = "rapier";
run_add_arg(&cbindgen, "--config");
run_add_arg(&cbindgen, "cbindgen.toml");
run_add_arg(&cbindgen, "--crate");
run_add_arg(&cbindgen, "rapier_rtt");
run_add_arg(&cbindgen, "--output");
run_add_arg(&cbindgen, "../public/physics_gen.h");
run_run(&cbindgen);
}

View File

@@ -7,11 +7,13 @@
CUtlString rapier_lib;
int rapier_build()
{
rapier_lib = CUtlString("rapier/target/%s/release/librapier_rtt.a",szTarget.GetString());
V_printf("%s\n",rapier_lib.GetString());
CUtlVector<CUtlString> cargo_args = {
"build",
"--release",
"--target",
"x86_64-unknown-linux-gnu"
szTarget
};
IRunner::Run("cargo", "rapier", cargo_args);
@@ -24,7 +26,6 @@ int rapier_build()
"../public/physics_gen.h",
};
IRunner::Run("cbindgen", "rapier", cbindgen_args);
rapier_lib = "rapier/target/x86_64-unknown-linux-gnu/release/librapier_rtt.a";
return 0;
};

View File

@@ -161,6 +161,7 @@ pub unsafe extern "C" fn px_kinematic_position_body(px_world: *mut funnyphysics,
.dominance_group(params.dominance)
.linear_damping(0.0)
.angular_damping(0.0)
.ccd_enabled(params.continous == 1)
.build();
let body = px.rigid_body_set.insert(rigid_body);
px.collider_set.insert_with_parent(c.clone(),body,&mut px.rigid_body_set);
@@ -284,7 +285,12 @@ pub unsafe extern "C" fn px_box_cast(px_world: *mut funnyphysics, x:f32,y:f32,z:
&px.rigid_body_set, &px.collider_set, &shape_pos, &shape_vel, &c, options, filter
) {
res.time=hit.time_of_impact;
res.normal1.m[0] = hit.normal1.x;
res.normal1.m[1] = hit.normal1.y;
res.normal1.m[2] = hit.normal1.z;
res.hit = 1;
} else {
res.time = time;
}
res
res
}

View File

@@ -1,42 +0,0 @@
#include "god/build.h"
#include "god/c.h"
#include "god/ld.h"
char* tier0_lib = 0;
void tier0_build(struct build_data b)
{
char* files[] = {
"tier0/mem.cpp",
"tier0/platform.cpp",
"tier0/lib.cpp",
NULL,
};
struct C_Macro macros[] = {
(struct C_Macro){"TIER0_IMPLEMENTATION","1"},
NULL,
};
struct project p = {
.b = &b,
.files = files,
.name = "tier0",
};
struct project o = C_compile(p, (struct C_settings){
.generation_flags = C_GENERATION_FLAGS_PIC,
.compile_flags = C_COMPILE_FLAGS_WALL,
.include_dirs = include_dirs,
.macros = macros,
});
char* libs[] = {
"c",
NULL,
};
tier0_lib = ld_link_project(o, (struct link_settings){
.type = LINK_TYPE_DYNAMIC,
.libs = libs,
});
mv("build/"GAME_NAME"/game/bin/libtier0.so",tier0_lib);
}

View File

@@ -20,15 +20,20 @@ int tier0_build()
compileProject.includeDirectories = all_IncludeDirectories;
compileProject.bFPIC = true;
ldProject = compileProject.Compile();
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
if (bStaticBuild)
ldProject.linkType = ELINK_STATIC_LIBRARY;
else
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
CUtlString outputProject = ldProject.Link();
const char *szGameName = ICommandLine::ParamValue("-game");
if (szGameName == NULL)
szGameName = "funnygame";
IFileSystem2::MakeDirectory(CUtlString("build/%s/game/bin",szGameName));
IFileSystem2::CopyFile(CUtlString("build/%s/game/bin",szGameName), outputProject);
if (!bStaticBuild)
{
IFileSystem2::MakeDirectory(CUtlString("%s/bin",szOutputDir.GetString()));
IFileSystem2::CopyFile(CUtlString("%s/bin", szOutputDir.GetString()), outputProject);
} else {
tier0_lib = outputProject;
}
return 0;
};

View File

@@ -10,6 +10,9 @@
#include "dlfcn.h"
#include "execinfo.h"
#endif
#ifdef __APPLE__
#include "dlfcn.h"
#endif
#ifdef __WIN32__
#include "windows.h"
#include "dbghelp.h"
@@ -22,7 +25,7 @@ PLATFORM_INTERFACE void Plat_FatalErrorFunc(const char* szFormat, ...)
va_end(list);
fflush(stdout);
raise(SIGTRAP);
_exit(1);
Plat_Exit(1);
}
PLATFORM_INTERFACE void Plat_ListDirRecursive(const char* szPath, ListDirCallbackFn file, ListDirCallbackFn dir)
@@ -163,6 +166,12 @@ PLATFORM_INTERFACE void *Plat_LoadLibrary( const char *psz )
V_printf("Failed to open %s\n\t%s\n", psz, dlerror());
return lib;
#endif
#ifdef __APPLE__
void *lib = dlopen(psz, RTLD_GLOBAL | RTLD_NOW);
if (!lib)
V_printf("Failed to open %s\n\t%s\n", psz, dlerror());
return lib;
#endif
#ifdef __WIN32__
return LoadLibraryA(psz);
#endif
@@ -172,6 +181,9 @@ PLATFORM_INTERFACE void *Plat_GetProc( void *lib, const char *psz )
#ifdef __linux__
return dlsym(lib, psz);
#endif
#ifdef __APPLE__
return dlsym(lib, psz);
#endif
#ifdef __WIN32__
return (void*)GetProcAddress((HMODULE)lib, psz);
#endif
@@ -194,3 +206,13 @@ PLATFORM_INTERFACE double Plat_GetTime( void )
return (tp.tv_sec-s_starttime)+tp.tv_nsec/1e9;
}
PLATFORM_INTERFACE void Plat_Exit( int status )
{
#ifdef __linux__
_exit(status);
#endif
#ifdef __APPLE__
_exit(status);
#endif
};

View File

@@ -1,42 +0,0 @@
#include "god/c.h"
#include "god/ld.h"
char* tier1_lib = 0;
void tier1_build(struct build_data b)
{
char* files[] = {
"tier1/commandline.cpp",
"tier1/utlbuffer.cpp",
"tier1/utlmap.cpp",
"tier1/utlstring.cpp",
"tier1/utlvector.cpp",
NULL,
};
struct C_Macro macros[] = {
(struct C_Macro){"TIER0_IMPLEMENTATION","1"},
NULL,
};
struct project p = {
.b = &b,
.files = files,
.name = "tier1",
};
struct project o = C_compile(p, (struct C_settings){
.generation_flags = C_GENERATION_FLAGS_PIC,
.compile_flags = C_COMPILE_FLAGS_WALL,
.include_dirs = include_dirs,
.macros = macros,
});
char* libs[] = {
"c",
NULL,
};
tier1_lib = ld_link_project(o, (struct link_settings){
.type = LINK_TYPE_STATIC,
.libs = libs,
});
}

View File

@@ -8,7 +8,7 @@ void ICommandLine::CreateCommandLine( int argc, char **argv )
cl_params.AppendTail(argv,argc);
}
bool ICommandLine::CheckParam( char *psz )
bool ICommandLine::CheckParam( const char *psz )
{
for (auto szParam: cl_params) {
if (!V_strcmp(szParam, psz))