summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-09-29 16:37:48 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-09-29 16:37:48 -0400
commitced65fa208a4c47c8a7d70b87ed51c84703a1b3f (patch)
treece56915a31d1a2bc468148b73e8343bc40fd163f
parent20890a4617b58e7b7dfc5aea8801d866ff009bfd (diff)
pke-at: add init level
-rw-r--r--Makefile1
-rw-r--r--src/level-init.cpp39
-rw-r--r--src/level-init.hpp11
-rw-r--r--src/pke-at.cpp4
4 files changed, 53 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 604c290..a111866 100644
--- a/Makefile
+++ b/Makefile
@@ -46,6 +46,7 @@ bin/pke-at: obj/pke-at-settings.o
bin/pke-at: obj/pke-at-common.o
bin/pke-at: obj/pke-at.o
bin/pke-at: obj/level-main.o
+bin/pke-at: obj/level-init.o
$(CXX) -v -std=c++23 $(BUILD_MODE_FLAGS) $(INCS) -Wl,--whole-archive $^ $(LDFLAGS) -Wl,--no-whole-archive $(CXXFLAGS) -o $@
.PHONY: clean
diff --git a/src/level-init.cpp b/src/level-init.cpp
new file mode 100644
index 0000000..98493e2
--- /dev/null
+++ b/src/level-init.cpp
@@ -0,0 +1,39 @@
+
+#include "level-init.hpp"
+#include "level-main.hpp"
+
+#include <pke/pke.hpp>
+
+struct pke_level_init_master {
+ pke_level *level = nullptr;
+} init_mstr;
+
+pke_level *pke_at_level_init_create() {
+ init_mstr.level = pke_level_create("init", pk_uuid_zed, pk_uuid_zed);
+ init_mstr.level->pke_cb_spinup.func = pke_at_level_init_init;
+ init_mstr.level->pke_cb_tick.func = (void(*)())pke_at_level_init_tick;
+ init_mstr.level->pke_cb_teardown.func = pke_at_level_init_teardown;
+ return init_mstr.level;
+}
+
+void pke_at_level_init_init() { }
+
+void pke_at_level_init_tick(double delta) {
+ (void)delta;
+ /* 2025-09-29 JCB
+ * This is a little goofy, but the engine needs to process 1(one) entire
+ * tick before we actually want to start the application.
+ * Specifically, the issue I was running into was that the editor plugin
+ * activates its player inputs on its very first tick, which happens *after*
+ * both the first level's init function and the first level's first tick.
+ * This means that certain ui actions are being swallowed because they do not
+ * have the desired priority in the input handler.
+ * I am unconvinced that this qualifies as a bug; perhaps a quirk at worst.
+ * The fix is to just register things in the right order, which we are doing
+ * with this fake level that immediately passes off being the active level,
+ * allowing the needed 1(one) tick to pass.
+ */
+ pkeSettings.rt.nextLevel = pke_at_level_main_create();
+}
+
+void pke_at_level_init_teardown() { }
diff --git a/src/level-init.hpp b/src/level-init.hpp
new file mode 100644
index 0000000..12f05bc
--- /dev/null
+++ b/src/level-init.hpp
@@ -0,0 +1,11 @@
+#ifndef PKE_AT_LEVEL_INIT_HPP
+#define PKE_AT_LEVEL_INIT_HPP
+
+#include <pke/level-types.hpp>
+
+pke_level *pke_at_level_init_create();
+void pke_at_level_init_init();
+void pke_at_level_init_tick(double delta);
+void pke_at_level_init_teardown();
+
+#endif /* PKE_AT_LEVEL_INIT_HPP */
diff --git a/src/pke-at.cpp b/src/pke-at.cpp
index f4c7462..70625ba 100644
--- a/src/pke-at.cpp
+++ b/src/pke-at.cpp
@@ -2,7 +2,7 @@
#include <pke/pke.hpp>
#include "pke-at.hpp"
-#include "level-main.hpp"
+#include "level-init.hpp"
struct pke_at_master {
struct pke_at_master_states {
@@ -14,7 +14,7 @@ void pke_at_tick(double delta) {
}
void pke_at_init() {
- pkeSettings.rt.nextLevel = pke_at_level_main_create();
+ pkeSettings.rt.nextLevel = pke_at_level_init_create();
}
void pke_at_teardown() {