Rearrange & setup

This commit is contained in:
2026-05-03 23:00:41 +01:00
parent f953f72322
commit 9e85763f9e
12 changed files with 125 additions and 28 deletions
+3 -1
View File
@@ -1,4 +1,6 @@
**old**
build/*
bin/*
bin/*
.clangd
+1
View File
@@ -1,3 +1,4 @@
[submodule "libs/mruby"]
path = libs/mruby
url = https://github.com/mruby/mruby.git
ignore = dirty
+13 -3
View File
@@ -38,6 +38,10 @@ CFLAGS_RELEASE := \
PCH_CFLAGS_DEBUG := $(CFLAGS_DEBUG) -x c++-header
PCH_CFLAGS_RELEASE := $(CFLAGS_RELEASE) -x c++-header
# ---------------- LIBS ----------------
LIBS := ./libs/mruby/build/host/lib/libmruby.a
# ---------------- SOURCES ----------------
SRC := $(wildcard $(SRC_DIR)/*.cc) $(wildcard $(SRC_DIR)/**/*.cc)
@@ -50,7 +54,7 @@ DEP_RELEASE := $(OBJ_RELEASE:.o=.d)
# ---------------- TARGETS ----------------
.PHONY: all debug release clean
.PHONY: all debug release clean setup
all: debug
@@ -58,6 +62,12 @@ debug: $(TARGET_DEBUG)
release: $(TARGET_RELEASE)
# ---------------- CLANGD ----------------
setup: setup.rb
@echo "Setting up clangd configuration..."
ruby setup.rb
# ---------------- PCH ----------------
$(PCH_DEBUG): $(INCLUDE_DIR)/pch.h
@@ -72,11 +82,11 @@ $(PCH_RELEASE): $(INCLUDE_DIR)/pch.h
$(TARGET_DEBUG): $(PCH_DEBUG) $(OBJ_DEBUG)
mkdir -p $(BIN_DIR)
$(CXX) $(CFLAGS_DEBUG) -o $@ $(OBJ_DEBUG) $(SDL_LIBS_DEBUG)
$(CXX) $(CFLAGS_DEBUG) -o $@ $(OBJ_DEBUG) $(SDL_LIBS_DEBUG) $(LIBS)
$(TARGET_RELEASE): $(PCH_RELEASE) $(OBJ_RELEASE)
mkdir -p $(BIN_DIR)
$(CXX) $(CFLAGS_RELEASE) -o $@ $(OBJ_RELEASE) $(SDL_LIBS_RELEASE)
$(CXX) $(CFLAGS_RELEASE) -o $@ $(OBJ_RELEASE) $(SDL_LIBS_RELEASE) $(LIBS)
# ---------------- COMPILE ----------------
+25
View File
@@ -0,0 +1,25 @@
#include "binding/ruby.h"
#include "utils.h"
#include "window/window.h"
struct Element {
Vec2<float> position;
float rotation;
Vec2<float> scale;
float z;
Ruby::Block on_click;
Ruby::Block on_update;
Ruby::Block on_hover;
virtual void render(Window &window) {}
};
struct Scene {
std::vector<Element> elements;
};
struct App {
Window window;
App(Vec2<float> size, const char *title) : window(size, title) {}
};
+13
View File
@@ -0,0 +1,13 @@
#include "pch.h"
#include "utils.h"
namespace Ruby {
extern mrb_state *mrb;
struct Block {
mrb_value proc;
Block(mrb_value proc) : proc(proc) {
mrb_gc_protect(mrb, proc);
}
};
}; // namespace Ruby
+40
View File
@@ -1,15 +1,55 @@
#ifndef PCH_H
#define PCH_H
#include "mruby.h"
#include "mruby/array.h"
#include "mruby/compile.h"
#include "mruby/hash.h"
#include "mruby/irep.h"
#include "mruby/string.h"
#include <SDL3/SDL.h>
#include <SDL3/SDL_events.h>
#include <SDL3_image/SDL_image.h>
#include <SDL3_ttf/SDL_ttf.h>
#include <algorithm>
#include <atomic>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdarg>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fcntl.h>
#include <filesystem>
#include <fstream>
#include <functional>
#include <immintrin.h>
#include <limits.h>
#include <map>
#include <mutex>
#include <optional>
#include <queue>
#include <set>
#include <shared_mutex>
#include <signal.h>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <termios.h>
#include <thread>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#endif
+2 -2
View File
@@ -1,8 +1,8 @@
#ifndef WINDOW_H
#define WINDOW_H
#include "../pch.h"
#include "../utils.h"
#include "pch.h"
#include "utils.h"
using ImageID = uint32_t;
using FontID = uint32_t;
+2 -4
View File
@@ -1,4 +1,4 @@
window = Window.new 400, 400, title: "Button Test"
app = App.new 400, 400, title: "Button Test"
main_scene = Scene.new
@@ -18,6 +18,4 @@ end
main_scene << text
main_scene << rect
window.scenes[:main_scene] = main_scene
window.start :main_scene
app.start main_scene
+11 -14
View File
@@ -5,15 +5,15 @@ width, height = 720, 480
image = Image.new "assets/loading.png"
window = Window.new width, height, title: "My Game", loading_bg: image
app = App.new width, height, title: "My Game", loading_bg: image
window.map_key ?w, :forward
window.map_key ?s, :backward
window.map_key ?a, :left
window.map_key ?d, :right
app.map_key ?w, :forward
app.map_key ?s, :backward
app.map_key ?a, :left
app.map_key ?d, :right
window.map_key ?h, :heal
window.map_key ?t, :place
app.map_key ?h, :heal
app.map_key ?t, :place
menu_scene = Scene.new
@@ -21,14 +21,14 @@ default_font = Font.new "assets/DejaVuSans.ttf", 12, italic: true
start_button = ElementText.new "Start Game", font: default_font, position: {x: 100, y: 100}
game_scene = Scene.new
start_button.on_click do
window.start :game_scene
app.start game_scene
end
menu_scene << start_button
game_scene = Scene.new
world = ElementWorld.new
# world.cam # camera object to control the view of the world, has position, zoom, rotation
@@ -183,7 +183,4 @@ world.shader :fog do |shader|
z = 100 # shaders always appear above normal sprites but z is used to sort them relative to each other, so a shader with z 100 will appear above a shader with z 50, but both will appear above normal sprites
end
window.scenes[:menu_scene] = menu_scene
window.scenes[:game_scene] = game_scene
window.start :menu_scene # first scene to show when the game starts, stops the loading bg
app.start menu_scene # first scene to show when the game starts, stops the loading bg
+14
View File
@@ -0,0 +1,14 @@
dir = File.expand_path(__dir__)
clangd = <<CLANGD
CompileFlags:
Add: [
-I#{dir}/include,
-I#{dir}/libs/mruby/include,
-std=c++23
]
Remove: []
Compiler: clang++
CLANGD
File.write ".clangd", clangd
+1 -4
View File
@@ -1,4 +1,4 @@
#include "../include/window/window.h"
#include "window/window.h"
int main() {
printf("Starting engine...\n");
@@ -23,12 +23,9 @@ int main() {
printf("Entering main loop...\n");
int i = 0;
while (running) {
Event e;
while (w.poll(e)) {
printf("Event polled: %d\n", e.type);
switch (e.type) {
case Event::QUIT:
printf("Exiting\n");