From e8167a90f51fa5d198f862a965d694ddb0c9b154 Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Mon, 27 Apr 2026 10:42:06 -0400 Subject: [PATCH] Split visualizer into example/ sub-project - Move renderer.h/cpp and ui_renderer.h/cpp to example/src/ - Move main.cpp to example/src/ - Move raylib and raygui submodules to example/ext/ - Keep tomlc17 submodule at root (library-only dependency) - Root Makefile builds liborbit.a static library + tests - example/Makefile builds orbit_sim, links liborbit.a - All build artifacts go to ./build/ via recursive BUILD_DIR - Remove example/tests/ (sim configs run from project root) --- .gitmodules | 10 ++-- Makefile | 78 +++++++++------------------- example/Makefile | 42 +++++++++++++++ example/ext/raygui | 1 + example/ext/raylib | 1 + {src => example/src}/main.cpp | 0 {src => example/src}/renderer.cpp | 0 {src => example/src}/renderer.h | 0 {src => example/src}/ui_renderer.cpp | 2 +- {src => example/src}/ui_renderer.h | 0 ext/raygui | 1 - ext/raylib | 1 - 12 files changed, 74 insertions(+), 62 deletions(-) create mode 100644 example/Makefile create mode 160000 example/ext/raygui create mode 160000 example/ext/raylib rename {src => example/src}/main.cpp (100%) rename {src => example/src}/renderer.cpp (100%) rename {src => example/src}/renderer.h (100%) rename {src => example/src}/ui_renderer.cpp (99%) rename {src => example/src}/ui_renderer.h (100%) delete mode 160000 ext/raygui delete mode 160000 ext/raylib diff --git a/.gitmodules b/.gitmodules index 28d8240..7b8e1fa 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,9 @@ -[submodule "ext/raylib"] - path = ext/raylib - url = https://github.com/raysan5/raylib.git [submodule "ext/tomlc17"] path = ext/tomlc17 url = https://github.com/cktan/tomlc17 -[submodule "ext/raygui"] - path = ext/raygui +[submodule "example/ext/raylib"] + path = example/ext/raylib + url = https://github.com/raysan5/raylib.git +[submodule "example/ext/raygui"] + path = example/ext/raygui url = https://github.com/raysan5/raygui.git diff --git a/Makefile b/Makefile index ba7cc6a..e0bc78f 100644 --- a/Makefile +++ b/Makefile @@ -1,87 +1,57 @@ -# Compiler and flags CXX = g++ CXXFLAGS = -Wall -Wextra -g -ggdb3 -std=c++14 \ -I./src \ - -isystem./ext/tomlc17/src \ - -isystem./ext/raylib/src \ - -isystem./ext/raygui/src \ - -isystem./ext/raygui/styles -LDFLAGS = -L./ext/raylib/src -lraylib -lm -lpthread -ldl -lrt -lX11 + -isystem./ext/tomlc17/src +LDFLAGS = -lm -# Directories SRC_DIR = src BUILD_DIR ?= build -RAYLIB_DIR = ext/raylib/src -TARGET = ${BUILD_DIR}/orbit_sim TEST_DIR = tests -TEST_TARGET = ${BUILD_DIR}/orbit_test -# Source files (exclude old mission planning files) CPP_SOURCES := $(wildcard $(SRC_DIR)/*.cpp) C_SOURCES = ext/tomlc17/src/tomlc17.c TEST_SOURCES := $(wildcard $(TEST_DIR)/*.cpp) -# Object files CPP_OBJECTS = $(CPP_SOURCES:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.o) C_OBJECTS = $(BUILD_DIR)/tomlc17.o TEST_OBJECTS := $(patsubst $(TEST_DIR)/%.cpp, $(BUILD_DIR)/%.o, $(TEST_SOURCES)) -# Default target (updates ctags if available) -all: raylib $(BUILD_DIR) $(TARGET) - @command -v ctags >/dev/null 2>&1 && ctags -R tests/ src/ || true +LIBRARY = $(BUILD_DIR)/liborbit.a -# Build raylib -raylib: - @if [ ! -f $(RAYLIB_DIR)/libraylib.a ]; then \ - echo "Building raylib..."; \ - cd $(RAYLIB_DIR) && $(MAKE) PLATFORM=PLATFORM_DESKTOP; \ - fi +all: lib test-build example -# Create build directory $(BUILD_DIR): mkdir -p $(BUILD_DIR) -# Link the executable -$(TARGET): $(C_OBJECTS) $(CPP_OBJECTS) raylib - $(CXX) $(C_OBJECTS) $(CPP_OBJECTS) -o $(TARGET) $(LDFLAGS) - -# Compile C++ source files $(CPP_OBJECTS): $(BUILD_DIR)/%.o : $(SRC_DIR)/%.cpp $(CXX) $(CXXFLAGS) -c $< -o $@ -# Compile C source files $(C_OBJECTS): $(BUILD_DIR)/%.o : $(C_SOURCES) $(CC) -Wall -Wextra -g -ggdb3 -std=c99 -I./src -I./ext/tomlc17/src -c $< -o $@ -# Clean build files -clean: - rm -rf $(BUILD_DIR) $(TARGET) $(TEST_TARGET) - -# Clean everything including raylib -clean-all: clean - cd $(RAYLIB_DIR) && $(MAKE) clean - -# Rebuild -rebuild: clean all +lib: $(BUILD_DIR) $(C_OBJECTS) $(CPP_OBJECTS) + ar rcs $(LIBRARY) $(C_OBJECTS) $(CPP_OBJECTS) + @echo "Built $(LIBRARY)" $(TEST_OBJECTS): $(BUILD_DIR)/%.o : $(TEST_DIR)/%.cpp $(CXX) $(CXXFLAGS) -c $< -o $@ -# Build automated test suite -test-build: $(BUILD_DIR) $(C_OBJECTS) $(CPP_OBJECTS) $(TEST_OBJECTS) - $(CXX) $(C_OBJECTS) $(TEST_OBJECTS) \ - build/test_utilities.o \ - build/physics.o \ - build/orbital_mechanics.o \ - build/simulation.o \ - build/config_loader.o \ - build/config_validator.o \ - build/maneuver.o \ - build/rendezvous.o \ - -o $(TEST_TARGET) -lCatch2Main -lCatch2 -lm - -# Run automated test suite +test-build: lib $(BUILD_DIR) $(TEST_OBJECTS) + $(CXX) $(TEST_OBJECTS) -o $(BUILD_DIR)/orbit_test -L$(BUILD_DIR) -lorbit -lCatch2Main -lCatch2 -lm + test: test-build - ./$(TEST_TARGET) + ./$(BUILD_DIR)/orbit_test + +example: lib + $(MAKE) -C example all BUILD_DIR=../$(BUILD_DIR) + +clean: + rm -rf $(BUILD_DIR) $(LIBRARY) + $(MAKE) -C example clean + +clean-all: clean + $(MAKE) -C example clean-all + +rebuild: clean all -.PHONY: all clean clean-all rebuild test test-build raylib ctags +.PHONY: all lib test-build test example clean clean-all rebuild diff --git a/example/Makefile b/example/Makefile new file mode 100644 index 0000000..778b34e --- /dev/null +++ b/example/Makefile @@ -0,0 +1,42 @@ +CXX = g++ +CXXFLAGS = -Wall -Wextra -g -ggdb3 -std=c++14 \ + -I./src \ + -I../src \ + -isystem./ext/raylib/src \ + -isystem./ext/raygui/src \ + -isystem./ext/raygui/styles +LDFLAGS = -L./ext/raylib/src -lraylib -lm -lpthread -ldl -lrt -lX11 + +SRC_DIR = src +BUILD_DIR ?= build +RAYLIB_DIR = ext/raylib/src + +CPP_SOURCES := $(wildcard $(SRC_DIR)/*.cpp) + +CPP_OBJECTS = $(CPP_SOURCES:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.o) + +TARGET = ${BUILD_DIR}/orbit_sim + +raylib: + @if [ ! -f $(RAYLIB_DIR)/libraylib.a ]; then \ + cd $(RAYLIB_DIR) && $(MAKE) PLATFORM=PLATFORM_DESKTOP; \ + fi + +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) + +$(TARGET): $(CPP_OBJECTS) raylib + $(CXX) $(CPP_OBJECTS) -o $(TARGET) -L$(BUILD_DIR) -lorbit $(LDFLAGS) + +$(CPP_OBJECTS): $(BUILD_DIR)/%.o : $(SRC_DIR)/%.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +clean: + rm -f $(TARGET) + @for f in $(CPP_SOURCES); do rm -f $(BUILD_DIR)/$$(basename $${f%.cpp}.o); done + +rebuild: clean all + +all: raylib $(BUILD_DIR) $(TARGET) + +.PHONY: all clean raylib rebuild diff --git a/example/ext/raygui b/example/ext/raygui new file mode 160000 index 0000000..3b28558 --- /dev/null +++ b/example/ext/raygui @@ -0,0 +1 @@ +Subproject commit 3b2855842ab578a034f827c38cf8f62c042fc983 diff --git a/example/ext/raylib b/example/ext/raylib new file mode 160000 index 0000000..72a341a --- /dev/null +++ b/example/ext/raylib @@ -0,0 +1 @@ +Subproject commit 72a341a37fbd9ccc1d8ec284ff20aeb5b991ad75 diff --git a/src/main.cpp b/example/src/main.cpp similarity index 100% rename from src/main.cpp rename to example/src/main.cpp diff --git a/src/renderer.cpp b/example/src/renderer.cpp similarity index 100% rename from src/renderer.cpp rename to example/src/renderer.cpp diff --git a/src/renderer.h b/example/src/renderer.h similarity index 100% rename from src/renderer.h rename to example/src/renderer.h diff --git a/src/ui_renderer.cpp b/example/src/ui_renderer.cpp similarity index 99% rename from src/ui_renderer.cpp rename to example/src/ui_renderer.cpp index cebaebc..4da619c 100644 --- a/src/ui_renderer.cpp +++ b/example/src/ui_renderer.cpp @@ -1045,7 +1045,7 @@ void render_maneuver_dialog(SimulationState* sim, RenderState* render_state, UIS return; } - const char* tabs[] = {"Create Maneuver", "Hohmann Transfer", "Edit Maneuver"}; + char* tabs[] = {(char*)"Create Maneuver", (char*)"Hohmann Transfer", (char*)"Edit Maneuver"}; int tab_count = 3; Rectangle tab_bounds = {x + 8, y + 30, width - 16, 25}; GuiTabBar(tab_bounds, tabs, tab_count, (int*)&ui_state->maneuver_dialog.active_tab); diff --git a/src/ui_renderer.h b/example/src/ui_renderer.h similarity index 100% rename from src/ui_renderer.h rename to example/src/ui_renderer.h diff --git a/ext/raygui b/ext/raygui deleted file mode 160000 index 9a1c183..0000000 --- a/ext/raygui +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9a1c183d8539e2470635b22f92bdaefaf5218aaa diff --git a/ext/raylib b/ext/raylib deleted file mode 160000 index ca89934..0000000 --- a/ext/raylib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ca89934ed5af9161f781a9b35b808b765dc40f3a