From c25ed1949d8b52dbfe779ea703718d05107ab902 Mon Sep 17 00:00:00 2001 From: Nathan Date: Sun, 15 Feb 2026 23:56:24 -0600 Subject: [PATCH] add SandboxEmbed --- .../SandboxEmbed/SandboxEmbed.cpp | 71 +++++++++++++++++++ src/example_apps/SandboxEmbed/SandboxEmbed.h | 29 ++++++++ src/example_apps/SandboxEmbed/default.nix | 54 ++++++++++++++ src/example_apps/TriangleEmbed/default.nix | 2 +- 4 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 src/example_apps/SandboxEmbed/SandboxEmbed.cpp create mode 100644 src/example_apps/SandboxEmbed/SandboxEmbed.h create mode 100644 src/example_apps/SandboxEmbed/default.nix diff --git a/src/example_apps/SandboxEmbed/SandboxEmbed.cpp b/src/example_apps/SandboxEmbed/SandboxEmbed.cpp new file mode 100644 index 0000000..d840e5d --- /dev/null +++ b/src/example_apps/SandboxEmbed/SandboxEmbed.cpp @@ -0,0 +1,71 @@ +#include "SandboxEmbed.h" + +bool SandboxEmbed::onEvent(const Archimedes::Event& event) { + + unsigned int type = getEventType(event); + + if(type == getEventType(Archimedes::DoLoadModuleEvent())) { + + Archimedes::DoLoadModuleEvent& e = (Archimedes::DoLoadModuleEvent&) event; + + startModule(e.module); + + return true; + + } else if(type == getEventType(Archimedes::DoUnloadModuleEvent())) { + + Archimedes::DoUnloadModuleEvent& e = (Archimedes::DoUnloadModuleEvent&) event; + + stopModule(e.module); + + return true; + + } else if(type == getEventType(Archimedes::LoadModuleEvent())) { + + return true; + } else if(type == getEventType(Archimedes::UnloadModuleEvent())) { + + return true; + } else if(type == getEventType(Archimedes::AnonymousEvent())) { + return true; + } + + return false; +} + +void SandboxEmbed::run() { + + for(std::string m : runOrder) { + modules[m]->onLoad(); + } + + + // Main loop + while (!done && !runOrder.empty()) { + + for(std::string m : runOrder) { + modules[m]->run(); + } + + handleEvents(); + + for(std::string m : toClose) { + unload(m); + } + toClose.clear(); + + for(auto m : toOpen) { + static Archimedes::Module* n; + if(std::holds_alternative(m)) { + n = load(std::get(m)); + } else { + n = load(std::get(m)); + } + if(n) { + n->onLoad(); + n = nullptr; + } + } + toOpen.clear(); + } +} diff --git a/src/example_apps/SandboxEmbed/SandboxEmbed.h b/src/example_apps/SandboxEmbed/SandboxEmbed.h new file mode 100644 index 0000000..d699e89 --- /dev/null +++ b/src/example_apps/SandboxEmbed/SandboxEmbed.h @@ -0,0 +1,29 @@ +#define ENTRYPOINT +#include "Archimedes.h" + +#include "modules/Archimedes-Modules/Sandbox/Sandbox.h" + +class SandboxEmbed : public Archimedes::App { + + private: + + void printHelp() override {}; + + bool onEvent(const Archimedes::Event&) override; + + public: + SandboxEmbed() { + Archimedes::Module* m = (Archimedes::Module*) new Sandbox(Get(), nullptr); + + load(m); + }; + ~SandboxEmbed() {}; + + void handleArgs(const int& argc, char* argv[]) override {}; + + void run() override; + +}; + +#define APP_TYPE SandboxEmbed +#include "endApp.h" diff --git a/src/example_apps/SandboxEmbed/default.nix b/src/example_apps/SandboxEmbed/default.nix new file mode 100644 index 0000000..0043942 --- /dev/null +++ b/src/example_apps/SandboxEmbed/default.nix @@ -0,0 +1,54 @@ +{ inputs, ... }: { + + + perSystem = { system, pkgs, self', ... }: { + packages.exampleApps_Sandbox = pkgs.stdenvNoCC.mkDerivation { + + name = "Archimedes"; + + src = inputs.src; + + imgui = inputs.imgui; + + nativeBuildInputs = with pkgs; [ + clang + ]; + + buildInputs = with pkgs; [ + glfw + glew + + glm + nlohmann_json + curl + ]; + + buildPhase = '' + clang++ \ + example_apps/SandboxEmbed/*.cpp \ + modules/Archimedes-Modules/Sandbox/*.cpp \ + modules/WindowModule/*.cpp \ + modules/ImguiModule/*.cpp \ + $imgui/backends/imgui_impl_glfw.cpp \ + $imgui/backends/imgui_impl_opengl3.cpp \ + $imgui/misc/cpp/*.cpp \ + $imgui/*.cpp \ + -DRENDERER_OPENGL=1 \ + -DWINDOW_GLFW=1 \ + -I include -I $imgui -I . \ + -lEGL -lGL -lglfw -lGLEW \ + $(curl-config --cflags) \ + $(curl-config --libs) \ + -Wall \ + -o $name + ''; + + installPhase = '' + mkdir -p $out/bin + cp $name $out/bin + ''; + + }; }; + + +} diff --git a/src/example_apps/TriangleEmbed/default.nix b/src/example_apps/TriangleEmbed/default.nix index 4a80a7e..072de6e 100644 --- a/src/example_apps/TriangleEmbed/default.nix +++ b/src/example_apps/TriangleEmbed/default.nix @@ -25,7 +25,7 @@ buildPhase = '' clang++ \ - src/example_apps/TriangleEmbed/*.cpp \ + example_apps/TriangleEmbed/*.cpp \ modules/Archimedes-Modules/TestTriangle/*.cpp \ modules/WindowModule/*.cpp \ -DRENDERER_OPENGL=1 \