summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor/editor.cpp7
-rw-r--r--editor/editor.hpp1
-rw-r--r--editor/main.cpp11
-rw-r--r--src/game-settings.cpp1
-rw-r--r--src/game-settings.hpp9
-rw-r--r--src/game.cpp20
-rw-r--r--src/game.hpp4
-rw-r--r--src/window.cpp8
-rw-r--r--src/window.hpp2
9 files changed, 40 insertions, 23 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp
index 6f887ed..23a748f 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -650,25 +650,24 @@ void RecordImGuiSceneEditor() {
}
}
-void RecordImGuiEditor() {
+void PkeEditor_RecordImGui() {
if (pkeSettings.isShowingEditor) {
RecordImGuiEditorWrapper();
RecordImGuiEntityList();
RecordImGuiSceneEditor();
RecordImGuiUBO();
+ Game_RecordImGui();
}
}
void PkeEditor_Setup() {
shouldSetupEditor = false;
PkeInput_ActivateSet(debugControlsHandle);
- Event_RegisterCallback("RenderImGui", RecordImGuiEditor);
}
void PkeEditor_Disable() {
shouldDisableEditor = false;
PkeInput_DeactivateSet(debugControlsHandle);
- Event_UnregisterCallback("RenderImGui", RecordImGuiEditor);
}
void PkeEditor_Teardown() {
@@ -748,6 +747,4 @@ void PkeEditor_Init() {
ActiveCamera = &cameraDefault;
threadPoolHandle = PkeThreads_Init(1, 1);
-
- Event_RegisterCallback<TickEvent>("GAME_TICK", PkeEditor_Tick);
}
diff --git a/editor/editor.hpp b/editor/editor.hpp
index 3cfb2df..e790259 100644
--- a/editor/editor.hpp
+++ b/editor/editor.hpp
@@ -2,6 +2,7 @@
#define PKE_EDITOR_HPP
void PkeEditor_Tick(double delta);
+void PkeEditor_RecordImGui();
void PkeEditor_Init();
void PkeEditor_Setup();
void PkeEditor_Disable();
diff --git a/editor/main.cpp b/editor/main.cpp
index 7400583..54c7607 100644
--- a/editor/main.cpp
+++ b/editor/main.cpp
@@ -11,20 +11,19 @@ void signal_handler(int signal_num) {
pkeSettings.isGameRunning = false;
}
-PKEWindowProperties windowProps{};
-
int main() {
signal(SIGTERM, signal_handler);
fprintf(stdout, "PKE_EDITOR ENTERING\n");
// setup
{
pkeSettings.isShowingEditor = true;
- Event_RegisterCallback<EventHandler>("GAME_INIT", PkeEditor_Init);
-
- Event_RegisterCallback<EventHandler>("GAME_TEARDOWN", PkeEditor_Teardown);
+ pkeGameCallbacks.OnInit = PkeEditor_Init;
+ pkeGameCallbacks.OnTick = PkeEditor_Tick;
+ pkeGameCallbacks.OnTeardown = PkeEditor_Teardown;
+ pkeGameCallbacks.OnImGuiRender = PkeEditor_RecordImGui;
}
// run
- Game_Main(&windowProps);
+ Game_Main({});
fprintf(stdout, "PKE_EDITOR EXITING\n");
return 0;
}
diff --git a/src/game-settings.cpp b/src/game-settings.cpp
index 6f09432..54699dd 100644
--- a/src/game-settings.cpp
+++ b/src/game-settings.cpp
@@ -1,3 +1,4 @@
#include "game-settings.hpp"
GameSettings pkeSettings{};
+PKEGameCallbacks pkeGameCallbacks{};
diff --git a/src/game-settings.hpp b/src/game-settings.hpp
index 3456725..480ae8e 100644
--- a/src/game-settings.hpp
+++ b/src/game-settings.hpp
@@ -33,6 +33,15 @@ struct GameSettings {
} mem;
};
+struct PKEGameCallbacks {
+ void (*OnInit)() = nullptr;
+ void (*OnTick)(double delta) = nullptr;
+ void (*OnTeardown)() = nullptr;
+ void (*OnImGuiRender)() = nullptr;
+};
+
extern GameSettings pkeSettings;
+extern PKEGameCallbacks pkeGameCallbacks;
+
#endif /* PKE_GAME_SETTINGS_HPP */
diff --git a/src/game.cpp b/src/game.cpp
index 511003a..72228bf 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -439,7 +439,7 @@ const uint64_t consoleBufferCount = 30;
const uint64_t consoleLineLength = 128;
char consoleBuffer[consoleBufferCount][consoleLineLength];
long consoleBufferIndex = 0;
-void RecordImGuiConsole() {
+void Game_RecordImGui() {
static bool scrollToBottom = true;
if (!ImGui::Begin("Console", &pkeSettings.editorSettings.isShowingConsole)) {
ImGui::End();
@@ -484,13 +484,15 @@ void Game_Tick(double delta) {
PkeInput_Tick(delta);
// TODO invoke external ticks here
- Event_Dispatch<TickEvent, double>("GAME_TICK", delta);
+ if (pkeGameCallbacks.OnTick) {
+ pkeGameCallbacks.OnTick(delta);
+ }
EntityType_Tick_Late(delta);
ECS_Tick_Late(delta);
}
-void Game_Main(PKEWindowProperties *windowProps) {
+void Game_Main(PKEWindowProperties windowProps) {
fprintf(stdout, "Game_Main Entering\n");
try {
AM_Init();
@@ -500,7 +502,9 @@ void Game_Main(PKEWindowProperties *windowProps) {
CreateWindow(windowProps);
PkeInput_Init();
EntityType_Init();
- Event_Dispatch<EventHandler>("GAME_INIT");
+ if (pkeGameCallbacks.OnInit) {
+ pkeGameCallbacks.OnInit();
+ }
GameTimePoint lastTimePoint = pkeSettings.steadyClock.now();
double deltaTillNextRender = pkeSettings.deltaPerFrame;
@@ -589,7 +593,9 @@ void Game_Main(PKEWindowProperties *windowProps) {
#ifndef NDEBUG
Pke_DebugPrint();
#endif
- Event_Dispatch<EventHandler>("GAME_TEARDOWN");
+ if (pkeGameCallbacks.OnTeardown) {
+ pkeGameCallbacks.OnTeardown();
+ }
Game_Teardown();
Event_Teardown();
EntityType_Teardown();
@@ -609,7 +615,9 @@ void Game_Init() {
for (long i = 0; i < consoleBufferCount; ++i) {
memset(consoleBuffer[i], '\0', consoleLineLength);
}
- Event_RegisterCallback("RenderImGui", RecordImGuiConsole);
+ if (!pkeGameCallbacks.OnImGuiRender) {
+ pkeGameCallbacks.OnImGuiRender = Game_RecordImGui;
+ }
}
void Game_Teardown() { }
diff --git a/src/game.hpp b/src/game.hpp
index 3e21c26..5697efa 100644
--- a/src/game.hpp
+++ b/src/game.hpp
@@ -1,12 +1,14 @@
#ifndef PKE_GAME_HPP
#define PKE_GAME_HPP
+#include "game-settings.hpp"
#include "window-types.hpp"
-void Game_Main(PKEWindowProperties *windowProps);
+void Game_Main(PKEWindowProperties windowProps);
void Game_Init();
void Game_Tick(double delta);
void Game_Teardown();
+void Game_RecordImGui();
void Game_SaveSceneFile(const char *);
void Game_LoadSceneFile(const char *);
diff --git a/src/window.cpp b/src/window.cpp
index 2b75cdd..8d40221 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -2427,12 +2427,12 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
vkCmdDraw(commandBuffer, 3, 1, 0, 0);
// ImGui
- if (isImGuiRenderActive) {
+ if (isImGuiRenderActive && pkeGameCallbacks.OnImGuiRender) {
ImGui_ImplVulkan_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
- Event_Dispatch<EventHandler>("RenderImGui");
+ pkeGameCallbacks.OnImGuiRender();
ImGui::Render();
auto drawData = ImGui::GetDrawData();
@@ -2547,7 +2547,7 @@ void FramebufferResizeCallback(GLFWwindow *window, int width, int height) {
shouldRecreateSwapchain = true;
}
-void CreateWindow(PKEWindowProperties *wp) {
+void CreateWindow(PKEWindowProperties wp) {
if (vkInstance != nullptr) return;
MemBkt_Vulkan = Pke_BeginTransientBucket();
vulkanAllocs = Pke_New<DynArray<pke_vkAllocData>>(MemBkt_Vulkan);
@@ -2555,7 +2555,7 @@ void CreateWindow(PKEWindowProperties *wp) {
vulkanAllocs->Reserve(2048);
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
- window = glfwCreateWindow(wp->width, wp->height, "Pikul", nullptr, nullptr);
+ window = glfwCreateWindow(wp.width, wp.height, "Pikul", nullptr, nullptr);
InitVulkan();
glfwSetFramebufferSizeCallback(window, FramebufferResizeCallback);
CreateSwapchain();
diff --git a/src/window.hpp b/src/window.hpp
index 0194a18..73369d3 100644
--- a/src/window.hpp
+++ b/src/window.hpp
@@ -88,7 +88,7 @@ struct ImplementedPipelines {
};
extern ImplementedPipelines pkePipelines;
-void CreateWindow(PKEWindowProperties *wp);
+void CreateWindow(PKEWindowProperties wp);
void DestroyWindow();
VkShaderModule UploadShader(AssetHandle handle);
void Render();