diff --git a/include/app/app.h b/include/app/app.h index 660896c..5d9e436 100644 --- a/include/app/app.h +++ b/include/app/app.h @@ -27,8 +27,8 @@ struct Element { virtual Vec2 size(Window *window) = 0; void click() { - if (!mrb_nil_p(on_click.proc)) - on_click.call(); + printf("Running click handler\n"); + on_click.call(); } }; @@ -170,6 +170,7 @@ struct Scene { void update_scene(uint64_t delta_time) { if (!mrb_nil_p(update.proc)) { mrb_value dt_val = mrb_int_value(Ruby::mrb, delta_time); + printf("running: update, dt: %lu\n", delta_time); update.call(1, &dt_val); } } diff --git a/include/binding/ruby.h b/include/binding/ruby.h index 8f60343..fa364ca 100644 --- a/include/binding/ruby.h +++ b/include/binding/ruby.h @@ -60,11 +60,8 @@ struct Block { Block() : proc(mrb_nil_value()) {} void set_proc(mrb_value new_proc) { - if (!mrb_nil_p(proc)) - mrb_gc_unregister(mrb, proc); proc = new_proc; - if (!mrb_nil_p(proc)) - mrb_gc_protect(mrb, proc); + mrb_gc_protect(mrb, proc); } Block(const Block &) = delete; @@ -76,16 +73,10 @@ struct Block { mrb_value result = mrb_funcall_argv(mrb, proc, mrb_intern_cstr(mrb, "call"), argc, argv); return result; } - - ~Block() { - mrb_gc_unregister(mrb, proc); - } }; inline void run_string(const char *code, size_t length) { - int ai = mrb_gc_arena_save(mrb); mrb_load_nstring(mrb, code, length); - mrb_gc_arena_restore(mrb, ai); } }; // namespace Ruby diff --git a/samples/main.rb b/samples/main.rb index 246705d..1af63b5 100644 --- a/samples/main.rb +++ b/samples/main.rb @@ -61,6 +61,13 @@ world.spawn do |e| # Name is optional animation1 = {tiles: tiles[0..3], frame_rate: 10, loop: true} c.animations = {idle: animation1} c.current_animation = :idle + ## For tilemaps + # tiles is an array of of tiles in sheet, largest one's w and h will be used. or width: height: to override + c.tilemap = Tilemap.new tiles + c.default_tile = tiles.first # default tile to use for empty spaces in the tilemap + c.auto_tile = true # tiles must follow pattern + # c.tile[x: 0, y: 0] = tiles[0] # set tile at position x,y in tilemap to a specific tile from the sheet (if no auto_tile is used) + c.tile[x: 0, y: 0] = true # true/false otherwise end e.add_component :render do |c| c.z_index = 0 diff --git a/src/main.cc b/src/main.cc index 446b454..fcf5b60 100644 --- a/src/main.cc +++ b/src/main.cc @@ -34,5 +34,7 @@ int main(int argc, char *argv[]) { } } + mrb_close(Ruby::mrb); + return 0; } \ No newline at end of file diff --git a/writeup/analysis.md b/writeup/analysis.md index 1fe3dd3..5e9e881 100644 --- a/writeup/analysis.md +++ b/writeup/analysis.md @@ -263,6 +263,31 @@ The engine could compile the developers scripts into mruby bytecode when buildin - then a draft one of teh requirements with justification of each based on the previous sections +Requirements v1: + +- A game loop capable of handling any max fps given to it. +- A scene system + - A scene is a set of scene elements used to create it, + - For example, a scene for menu, for game over screen, and most importantly, for the main game scene. + - A scene element can be one of, + - A rectangle + - A text + - An image + - A game world + - A pixel scripted element, for stuff like minimaps (called Surface). + - A sdl command batch element, for something that batches a bunch of image/rect/text into one element. (Called Render) + - each element has coordinates on screen and z ordering. + - And they can handle clicks / keyboard events and have scripts attached to each or the scene itself. +- A game world is just the game world (everything is coordinates in the world map relative, and this object controls the camera), \ + and it can be defined as topdown or side (for z ordering rules). + - everything is an entity + - with specail entities for tiling spritesheets where a set of tiles can be defined and the engine will place the right kind of tile based on the scenario \ + (for example in a maze if i define a spritesheet with tiles for corner / edge peices and then tell the maze as a grid of cells with 1 for wall and 0 \ + for empty it will automatically place the correct tile from that list.) + - and support for maze generation and solving algorithms, which can be used with tiling entity to create maze maps but also just usable for anything. + +## + - then any limitations / problems that can arise with certain choices in that list and how i might tackle them or ignore them - then specifics of what ill need to actually make this, like the libaries, languages & hardware ill use with reasons of why, can have a big section on stuff like explaining why i chose sdl3 for rendering, or mruby (mostly because of mruby precompiling and how i can prepack the engine into a single binary)