conversion to c by gemini 4 argon
This commit is contained in:
1 parent
b70e2d21d2
commit
f9356f9ba7
369 files changed
+18074
-107634
No files matched your search
+167
@@ -0,0 +1,167 @@
|
||||
#include <game.h>
|
||||
|
||||
#include <Controller/DebugCameraController.h>
|
||||
#include <Core/Common/serialization.h>
|
||||
#include <Core/HAL/Filesystem/Filesystem.h>
|
||||
#include <Core/HAL/Keyboard/Keyboard.h>
|
||||
#include <Core/JulietInit.h>
|
||||
#include <Core/Logging/LogManager.h>
|
||||
#include <Core/Memory/MemoryArena.h>
|
||||
#include <Data/World.h>
|
||||
#include <Entity/Entity.h>
|
||||
#include <Entity/entity_types.h>
|
||||
#include <Entity/EntityManager.h>
|
||||
#include <Graphics/Camera.h>
|
||||
#include <Graphics/MeshRenderer.h>
|
||||
#include <dcimgui.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if JULIET_DEBUG
|
||||
#include <Debug/DebugTopBar.h>
|
||||
#include <UnitTest/WorldUnitTest.h>
|
||||
#endif
|
||||
|
||||
global GameState* gGameState = NULL;
|
||||
|
||||
GameState* GetGameState(void)
|
||||
{
|
||||
return gGameState;
|
||||
}
|
||||
|
||||
JULIET_API void __cdecl GameShutdown(void)
|
||||
{
|
||||
printf("Shutting down game...\n");
|
||||
|
||||
if (gGameState != NULL && gGameState->World != NULL)
|
||||
{
|
||||
ShutdownWorld(gGameState->World);
|
||||
}
|
||||
|
||||
ShutdownEntityManager();
|
||||
}
|
||||
|
||||
JULIET_API void __cdecl GameUpdate(GameData* params, float deltaTime)
|
||||
{
|
||||
Assert(params != NULL);
|
||||
|
||||
gGameState = params->GameState;
|
||||
if (gGameState == NULL)
|
||||
{
|
||||
ArenaParams gameStateParams = { .ReserveSize = Megabytes(1), .Name = "Game Total Arena" };
|
||||
Arena* gameStateArena = ArenaAllocate(gameStateParams);
|
||||
GameState* gameState = ArenaPushStruct(gameStateArena, GameState);
|
||||
gGameState = params->GameState = gameState;
|
||||
gameState->TotalArena = gameStateArena;
|
||||
gameState->Mode = GameMode_Editor;
|
||||
|
||||
gameState->TotalTime = 0.0f;
|
||||
gameState->Score = 0;
|
||||
|
||||
printf("Game Arena Allocated: %p\n", (void*)gameState);
|
||||
|
||||
// Reserve cameras. Lets go with 4 for now
|
||||
ReserveCamera(4);
|
||||
|
||||
#if JULIET_DEBUG
|
||||
UnitTest_WorldUnitTest();
|
||||
#endif
|
||||
|
||||
// Bootstrap world
|
||||
ArenaParams worldParams = { .ReserveSize = Megabytes(1), .Name = "World Arena" };
|
||||
Arena* worldArena = ArenaAllocate(worldParams);
|
||||
World* world = ArenaPushStructTag(worldArena, World, "World");
|
||||
gameState->World = world;
|
||||
InitWorld(gameState->World, worldArena);
|
||||
|
||||
// Entity Use case
|
||||
InitEntityManager(gameState->World);
|
||||
EntityManager* manager = GetEntityManager();
|
||||
|
||||
Inert* mesh = MakeEntity(Inert, manager, 1.f, 2.f, 0.f);
|
||||
Assert(mesh != NULL);
|
||||
|
||||
MeshAssetID cubeAsset = GetCubePrimitiveMeshAssetID();
|
||||
Matrix identity = MatrixIdentity();
|
||||
MeshInstanceID meshInst = CreateMeshInstance(cubeAsset, 0, &identity);
|
||||
mesh->MeshInstance = meshInst;
|
||||
|
||||
Inert* mesh2 = MakeEntity(Inert, manager, 4.f, 0.f, 2.f);
|
||||
Assert(mesh2 != NULL);
|
||||
|
||||
MeshInstanceID meshInst2 = CreateMeshInstance(cubeAsset, 0, &identity);
|
||||
mesh2->MeshInstance = meshInst2;
|
||||
|
||||
// Summer at 2pm lighting
|
||||
Vector3 sunDirection = { -0.2f, -0.9f, -0.3f };
|
||||
Vector3 sunColor = { 1.0f, 0.95f, 0.85f };
|
||||
float ambientIntensity = 0.4f;
|
||||
SetGlobalLight(sunDirection, sunColor, ambientIntensity);
|
||||
}
|
||||
|
||||
#if JULIET_DEBUG
|
||||
DrawTopBar();
|
||||
#endif
|
||||
|
||||
GameMode previousFrameMode = gGameState->Mode;
|
||||
if (IsKeyPressed(ScanCode_F1))
|
||||
{
|
||||
if (previousFrameMode == GameMode_Play)
|
||||
{
|
||||
gGameState->Mode = GameMode_Debug;
|
||||
}
|
||||
else if (previousFrameMode == GameMode_Debug)
|
||||
{
|
||||
gGameState->Mode = GameMode_Play;
|
||||
}
|
||||
}
|
||||
|
||||
if (gGameState->Mode == GameMode_Editor)
|
||||
{
|
||||
if (IsKeyPressed(ScanCode_F5))
|
||||
{
|
||||
gGameState->Mode = GameMode_Play;
|
||||
}
|
||||
|
||||
#if JULIET_EDITOR
|
||||
RenderWorldEditorUI(gGameState->World);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (gGameState->Mode == GameMode_Play)
|
||||
{
|
||||
if (IsKeyPressed(ScanCode_Escape))
|
||||
{
|
||||
gGameState->Mode = GameMode_Editor;
|
||||
}
|
||||
|
||||
// update game
|
||||
}
|
||||
|
||||
EntityManager* manager = GetEntityManager();
|
||||
UpdateEntityManager(manager);
|
||||
|
||||
if (gGameState->Mode == GameMode_Debug)
|
||||
{
|
||||
if (previousFrameMode == GameMode_Play)
|
||||
{
|
||||
ActivateDebugController();
|
||||
}
|
||||
|
||||
if (IsKeyPressed(ScanCode_Escape))
|
||||
{
|
||||
gGameState->Mode = GameMode_Editor;
|
||||
}
|
||||
|
||||
UpdateDebugController(deltaTime);
|
||||
|
||||
#if JULIET_DEBUG
|
||||
ImGui_Begin("Debug", NULL, ImGuiWindowFlags_None);
|
||||
RenderImGuiDebugController(deltaTime);
|
||||
ImGui_End();
|
||||
#endif
|
||||
}
|
||||
if (gGameState->Mode != GameMode_Debug && previousFrameMode == GameMode_Debug)
|
||||
{
|
||||
DeactivateDebugController();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user