Compare commits

...
11 Commits
Author SHA1 Message Date
syedm 8a3da07c6c Cleanup 2026-07-26 19:59:14 +01:00
syedm e188501d19 Setup python env 2026-07-26 19:59:10 +01:00
syedm e0994b42c0 Add some useful mgems 2026-07-26 19:49:39 +01:00
syedm d484db4e84 Format files (using clang-format) 2026-07-26 19:17:24 +01:00
syedm f82ab718f3 Make fread call error handle 2026-07-26 19:12:32 +01:00
syedm 2f70c44ad5 Fix incorrect comparision 2026-07-26 19:10:53 +01:00
syedm 2006ee55ab Remove clang specific warning 2026-07-26 19:08:56 +01:00
syedm 9f4c345c74 Fix nix flake and use gcc as compiler 2026-07-26 19:04:49 +01:00
syedm edad8ff5cd Refractor directory name 2026-07-26 18:33:26 +01:00
syedm 1935be52ac try fixing flake 2026-07-26 18:29:13 +01:00
syedm a9054b3be4 Cleanup 2026-07-14 13:07:13 +01:00
34 changed files with 256 additions and 89 deletions
+2
View File
@@ -12,3 +12,5 @@ include/bindings/ruby_compiled.h
p.vim
.cache/
result
+9
View File
@@ -2,3 +2,12 @@
path = libs/mruby
url = https://github.com/mruby/mruby.git
ignore = dirty
[submodule "libs/mgems/mruby-process"]
path = libs/mgems/mruby-process
url = https://github.com/katzer/mruby-process
[submodule "libs/mgems/mruby-env"]
path = libs/mgems/mruby-env
url = https://github.com/iij/mruby-env.git
[submodule "libs/mgems/mruby-marshal-c"]
path = libs/mgems/mruby-marshal-c
url = https://github.com/LanzaSchneider/mruby-marshal-c.git
+22 -26
View File
@@ -2,16 +2,16 @@ SRC_DIR := src
BIN_DIR := bin
OBJ_DIR := build
INCLUDE_DIR := include
SCRIPT_DIR := scripts
TARGET_DEBUG := $(BIN_DIR)/game-dbg
TARGET_RELEASE := $(BIN_DIR)/game
TARGET_DEBUG := $(BIN_DIR)/misth-dbg
TARGET_RELEASE := $(BIN_DIR)/misth
PCH_DEBUG := $(OBJ_DIR)/debug/pch.h.gch
PCH_RELEASE := $(OBJ_DIR)/release/pch.h.gch
CCACHE := ccache
CXX := $(CCACHE) $(shell which clang++)
CC := $(CCACHE) $(shell which clang)
CC ?= gcc
CXX ?= g++
# ---------------- SDL3 ----------------
@@ -19,32 +19,28 @@ SDL_CFLAGS := $(shell pkg-config --cflags sdl3 sdl3-ttf sdl3-image)
SDL_LIBS_DEBUG := $(shell pkg-config --libs sdl3 sdl3-ttf sdl3-image)
SDL_LIBS_RELEASE := $(shell pkg-config --libs sdl3 sdl3-ttf sdl3-image)
# ----------------- MRUBY --------------
MRUBY_CFLAGS := -I$(MRUBY_INCLUDE)
MRUBY_LIBS := $(MRUBY_LIB)
# ---------------- FLAGS ----------------
CFLAGS_DEBUG := \
-std=c++20 -Wall -Wextra \
-Og -g -fno-omit-frame-pointer \
-Wno-unused-command-line-argument \
-I./include -I./libs/mruby/build/host/include \
$(SDL_CFLAGS)
$(SDL_CFLAGS) $(MRUBY_CFLAGS)
CFLAGS_RELEASE := \
-std=c++20 -O3 -march=x86-64 -mtune=generic \
-flto=thin \
-std=c++20 -O3 -mtune=generic \
-fno-rtti -fomit-frame-pointer -DNDEBUG -s \
-Wno-unused-command-line-argument \
-I./include -I./libs/mruby/build/host/include \
$(SDL_CFLAGS)
$(SDL_CFLAGS) $(MRUBY_CFLAGS)
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
MGEM_DIR := ./libs/l_mgems
# ---------------- SOURCES ----------------
SRC := $(shell find $(SRC_DIR) -name "*.cc")
@@ -57,18 +53,18 @@ DEP_RELEASE := $(OBJ_RELEASE:.o=.d)
# ---------------- TARGETS ----------------
.PHONY: all debug release clean mgems
.PHONY: all debug release clean scripts
all: debug
all: release
debug: mgems $(TARGET_DEBUG)
debug: scripts $(TARGET_DEBUG)
release: mgems $(TARGET_RELEASE)
release: scripts $(TARGET_RELEASE)
# ---------------- MRB_MGEMS ----------------
mgems:
@$(MGEM_DIR)/compile.sh
scripts:
bash $(SCRIPT_DIR)/compile.sh
# ---------------- PCH ----------------
@@ -86,12 +82,12 @@ $(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) $(LIBS)
@$(CXX) $(CFLAGS_DEBUG) -o $@ $(OBJ_DEBUG) $(SDL_LIBS_DEBUG) $(MRUBY_LIBS)
@echo "Debug build complete: $@"
$(TARGET_RELEASE): $(PCH_RELEASE) $(OBJ_RELEASE)
@mkdir -p $(BIN_DIR)
@$(CXX) $(CFLAGS_RELEASE) -o $@ $(OBJ_RELEASE) $(SDL_LIBS_RELEASE) $(LIBS)
@$(CXX) $(CFLAGS_RELEASE) -o $@ $(OBJ_RELEASE) $(SDL_LIBS_RELEASE) $(MRUBY_LIBS)
@echo "Release build complete: $@"
# ---------------- COMPILE ----------------
@@ -115,5 +111,5 @@ $(OBJ_DIR)/release/%.o: $(SRC_DIR)/%.cc $(PCH_RELEASE)
clean:
@rm -rf $(OBJ_DIR) $(BIN_DIR)
@$(MGEM_DIR)/compile.sh clean
bash $(SCRIPT_DIR)/compile.sh clean
@echo "Cleaned build artifacts."
+107 -20
View File
@@ -1,43 +1,130 @@
{
description = "game";
description = "Project Misth";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
self.submodules = true;
};
outputs = { self, nixpkgs }:
outputs =
{ nixpkgs, ... }:
let
systems = [ "x86_64-linux" ];
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
forAllSystems = f:
nixpkgs.lib.genAttrs systems (system:
f (import nixpkgs {
inherit system;
}));
in {
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
packages = with pkgs; [
clang-tools
clang
ccache
mruby = pkgs.stdenv.mkDerivation {
pname = "mruby";
version = "0.0.1";
src = pkgs.lib.cleanSourceWith {
src = ./libs;
name = "mruby-src";
};
patches = [
./libs/changes.patch
];
nativeBuildInputs = with pkgs; [
ruby
gnumake
];
buildPhase = ''
cd mruby
rake
'';
installPhase = ''
mkdir -p $out
cp -r build/host/lib $out/lib
cp -r build/host/include $out/include
mkdir -p $out/bin
cp build/host/bin/mrbc $out/bin/mrbc
'';
};
misth = pkgs.stdenv.mkDerivation {
pname = "misth";
version = "0.1.0";
src = ./.;
nativeBuildInputs = with pkgs; [
pkg-config
gnumake
bear
xxd
bash
];
buildInputs = with pkgs; [
sdl3
sdl3-ttf
sdl3-image
mruby
];
buildPhase = ''
make \
MRBC=${mruby}/bin/mrbc \
MRUBY_INCLUDE=${mruby}/include \
MRUBY_LIB=${mruby}/lib/libmruby.a
'';
installPhase = ''
mkdir -p $out/bin
cp bin/misth $out/bin/misth
'';
};
pythonEnv = pkgs.python3.withPackages (
ps: with ps; [
pandas
matplotlib
]
);
in
{
packages.${system} = {
default = misth;
misth = misth;
mruby = mruby;
pythonEnv = pythonEnv;
};
devShells.${system}.default = pkgs.mkShell {
inputsFrom = [ misth ];
packages = with pkgs; [
clang-tools
pkg-config
ccache
gnumake
bear
ruby
xxd
bear
sdl3
sdl3-ttf
sdl3-image
pythonEnv
ruff
];
shellHook = ''
export CC=clang
export CXX=clang++
export LD=clang
export CC="ccache gcc"
export CXX="ccache g++"
export MRBC=${mruby}/bin/mrbc
export MRUBY_INCLUDE=${mruby}/include
export MRUBY_LIB=${mruby}/lib/libmruby.a
'';
};
});
};
}
+1 -1
View File
@@ -73,8 +73,8 @@ private:
};
struct ERect : Element {
Color color = {255, 255, 255};
Vec2<float> shape = {0, 0};
Color color = {255, 255, 255};
Vec2<float> size() override;
+5 -1
View File
@@ -3,8 +3,12 @@
#include "utils.h"
struct Entity;
struct Entity {};
struct Component;
struct System;
struct EntityPool {
Entity entities[];
};
#endif
+1 -2
View File
@@ -226,8 +226,7 @@ struct Pool {
bool is_valid(uint64_t index) const {
uint32_t id = (uint32_t)(index & 0xFFFFFFFFULL);
uint32_t gen = (uint32_t)(index >> 32);
return id >= 0
&& id < slots.size()
return id < slots.size()
&& slots[id].alive
&& slots[id].generation == gen;
}
+53
View File
@@ -0,0 +1,53 @@
--- ./mruby/build_config/default.rb
+++ ./mruby/build_config/default.rb
@@ -1,6 +1,18 @@
MRuby::Build.new do |conf|
# load specific toolchain settings
- conf.toolchain
+ conf.toolchain :gcc
+
+ conf.cc do |cc|
+ cc.command = ENV['CC']
+ end
+
+ conf.cxx do |cxx|
+ cxx.command = ENV['CXX']
+ end
+
+ conf.linker do |linker|
+ linker.command = ENV['CXX']
+ end
# Use mrbgems
# conf.gem 'examples/mrbgems/ruby_extension_example'
@@ -16,6 +28,10 @@
# include the GEM box
conf.gembox 'default'
+ conf.gem '../mgems/mruby-env'
+ conf.gem '../mgems/mruby-process'
+ conf.gem '../mgems/mruby-marshal-c'
+
# C compiler settings
# conf.cc do |cc|
# cc.command = ENV['CC'] || 'gcc'
@@ -79,5 +79,5 @@
# Turn on `enable_debug` for better debugging
# conf.enable_debug
- conf.enable_bintest
- conf.enable_test
+ # conf.enable_bintest
+ # conf.enable_test
end
--- ./mgems/mruby-process/mrbgem.rake
+++ ./mgems/mruby-process/mrbgem.rake
@@ -54,4 +54,9 @@
else
spec.objs.delete objfile("#{build_dir}/src/win32")
end
+
+ spec.objs.delete objfile("#{build_dir}/src/internal")
+ spec.objs.delete objfile("#{build_dir}/src/dln")
+ spec.objs.delete objfile("#{build_dir}/src/signal")
+ spec.objs.delete objfile("#{build_dir}/src/status")
end
+7 -1
View File
@@ -19,7 +19,7 @@ bg_image1_a = Animation.from(bg_image1)
App.language = :en
App.localize(:en, :btn_text, "Click %{name}!")
text = ElementText.new :btn_text, default_font, 0xFFFF00, {name: "Me"}, position: {x: 50, y: 50}, z: 1, click_mode: :block, alpha: 1
text = ElementText.new :btn_text, default_font, 0xFFFF00, {name: ENV.fetch("name", "me")}, position: {x: 50, y: 50}, z: 1, click_mode: :block, alpha: 1
rect = ElementRect.new 100, 25, 0xFF0000, position: {x: 50, y: 50}, z: 0, rotation: 60, scale: { x: 1, y: 1 }, alpha: 0.8, click_mode: :block
@@ -58,12 +58,18 @@ rect.click do
end
App.map_key :mouse_left, :action_name
App.map_key :q, :quit
start = Time.now
c_ = 0.0
c_c = 0
App.update do |delta_time|
if App.pressed?(:quit)
App.exit!
next
end
c_ += delta_time
c_c += 1
@@ -4,7 +4,7 @@ set -e
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
OUTPUT_TMP=$(mktemp)
OUTPUT="$SCRIPT_DIR/../../include/bindings/ruby_compiled.h"
OUTPUT="$SCRIPT_DIR/../include/bindings/ruby_compiled.h"
if test "$1" = "clean"; then
rm -f "$OUTPUT"
@@ -28,7 +28,7 @@ fi
echo "Compiling mgems..."
"$SCRIPT_DIR/../mruby/bin/mrbc" -o "$OUTPUT_TMP" "${FILES[@]}"
"${MRBC:-mrbc}" -o "$OUTPUT_TMP" "${FILES[@]}"
{
echo "#ifndef MGEMS_H"
+9 -1
View File
@@ -15,7 +15,15 @@ int main(int argc, char *argv[]) {
fseek(file, 0, SEEK_SET);
char *script_content = (char *)malloc(size + 1);
fread(script_content, 1, size, file);
size_t read = fread(script_content, 1, size, file);
if (read != size) {
fprintf(stderr, "Failed to read startup script: %s\n", startup_script);
free(script_content);
fclose(file);
return 1;
}
script_content[size] = '\0';
fclose(file);