From a8dff07bf18a14701477e592b5c107093b8fc553 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 14 Mar 2025 15:06:27 -0500 Subject: [PATCH] now trying to build --- flake.nix | 58 +++++++++++++++++++++---------- modules/print/src/print.cpp | 15 ++++++++ modules/print/src/print.h | 16 +++++++++ modules/testMenu/src/testMenu.cpp | 1 + src/App.cpp | 20 +++++------ src/Module.h | 2 ++ src/pch.hpp | 3 ++ 7 files changed, 86 insertions(+), 29 deletions(-) create mode 100644 modules/print/src/print.cpp create mode 100644 modules/print/src/print.h diff --git a/flake.nix b/flake.nix index 42b3148..60f224b 100755 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "Build Project X-001"; + description = "Build Project Archimedes"; inputs = { nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; @@ -9,23 +9,21 @@ }; }; - outputs = { self, nixpkgs, imgui }@inputs: let + outputs = { self, nixpkgs, imgui }: let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; in { - packages.${system}.default = pkgs.stdenv.mkDerivation { + Archimedes = pkgs.stdenv.mkDerivation { - name = "Engine"; + name = "Archimedes"; src = ./src; - imgui = inputs.imgui; + #imgui = inputs.imgui; - buildInputs = with pkgs; [ - vulkan-headers - vulkan-loader - ]; + /*buildInputs = with pkgs; [ + ];*/ buildPhase = '' g++ *.cpp -o $name @@ -38,26 +36,48 @@ }; - shaders = pkgs.stdenv.mkDerivation { + TestMenu = pkgs.stdenv.mkDerivation { - name = "Engine"; + name = "TestMenu"; - src = ./modules/shaders; + src = ./.; - buildInputs = with pkgs; [ - shaderc - ]; + /*buildInputs = with pkgs; [ + ];*/ buildPhase = '' - glslc *.vert -o vert.spv - glslc *.frag -o frag.spv - ''; + g++ modules/testMenu/src/*.cpp -fpic -shared -I src -o $name + ''; installPhase = '' mkdir -p $out/bin - cp *.spv $out/bin + cp $name $out/bin ''; }; + + Print = pkgs.stdenv.mkDerivation { + + name = "Print"; + + src = ./.; + + /*buildInputs = with pkgs; [ + ];*/ + + buildPhase = '' + g++ modules/print/src/*.cpp -fpic -shared -I src -I include -o $name + ''; + + installPhase = '' + mkdir -p $out/bin + cp $name $out/bin + ''; + + }; + + + packages.${system}.default = self.Archimedes; + }; } diff --git a/modules/print/src/print.cpp b/modules/print/src/print.cpp new file mode 100644 index 0000000..0c5f6a1 --- /dev/null +++ b/modules/print/src/print.cpp @@ -0,0 +1,15 @@ +#include "print.h" + +Print::Print(void* h) { + handle = h; + name = "Print"; +} + +Print::~Print() { + std::cout << "Print Destroyed!\n"; +} + +void Print::run() { + std::cout << "Print lib loaded and run!\n"; + App::Get().unload(self); +} diff --git a/modules/print/src/print.h b/modules/print/src/print.h new file mode 100644 index 0000000..803a7d3 --- /dev/null +++ b/modules/print/src/print.h @@ -0,0 +1,16 @@ +#include "../../../include/Archimedes.h" + +class Print : public Module { + + public: + Print(void*); + ~Print(); + void run(); + +}; + +extern "C" { + Module* create(void* handle) { + return new Print(handle); + } +} diff --git a/modules/testMenu/src/testMenu.cpp b/modules/testMenu/src/testMenu.cpp index c925d55..8ece03e 100644 --- a/modules/testMenu/src/testMenu.cpp +++ b/modules/testMenu/src/testMenu.cpp @@ -2,6 +2,7 @@ TestMenu::TestMenu(void* h) { handle = h; + name = "TestMenu"; } TestMenu::~TestMenu() { diff --git a/src/App.cpp b/src/App.cpp index 961b6d3..de2528b 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -50,23 +50,23 @@ void App::load(std::string lib) { } Module::create_t* create = (Module::create_t*) dlsym(handle, "create"); + if(dlerror()) { std::cout << "error finding create function in file: " << lib << std::endl; } - - Module::destroy_t* destroy = (Module::destroy_t*) dlsym(handle, "destroy"); - if(dlerror()) { - std::cout << "error finding destroy function in file: " << lib << std::endl; - } Module* m = create(handle); for(auto it = modules.begin(); it != modules.end(); it++) { - if((*it)->getName() != "") { - + if((*it)->getName() != m->getName()) { + std::cout << "Module \"" << m->getName() << "\" is already loaded!\n"; + return; } } + + m->setSelf(modules.end()); + modules.push_back(m); } void App::unload(std::list::iterator it) { @@ -78,15 +78,15 @@ void App::unload(std::list::iterator it) { void App::handleArgs(const int& argc, char* argv[]) { - int i = 0; + int i = 1; - if(argc == 0) { + if(argc == 1) { printHelp(); end(); } while(i < argc) { - if(strcmp(argv[i], "-h") == 0) { + if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { printHelp(); end(); } else { diff --git a/src/Module.h b/src/Module.h index 7b4daa0..7d01bca 100644 --- a/src/Module.h +++ b/src/Module.h @@ -14,6 +14,8 @@ class Module { virtual void run() = 0; std::string getName() const { return name; } void* getHandle() { return handle; } + + void setSelf(std::list::iterator s) { self = s; } protected: std::string name; diff --git a/src/pch.hpp b/src/pch.hpp index 72b2b97..b60cc0f 100644 --- a/src/pch.hpp +++ b/src/pch.hpp @@ -5,6 +5,9 @@ #include #include +//#include +//#include + #include #endif