trynna fix click handler being garbage collected
This commit is contained in:
+3
-2
@@ -27,8 +27,8 @@ struct Element {
|
|||||||
virtual Vec2<float> size(Window *window) = 0;
|
virtual Vec2<float> size(Window *window) = 0;
|
||||||
|
|
||||||
void click() {
|
void click() {
|
||||||
if (!mrb_nil_p(on_click.proc))
|
printf("Running click handler\n");
|
||||||
on_click.call();
|
on_click.call();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -170,6 +170,7 @@ struct Scene {
|
|||||||
void update_scene(uint64_t delta_time) {
|
void update_scene(uint64_t delta_time) {
|
||||||
if (!mrb_nil_p(update.proc)) {
|
if (!mrb_nil_p(update.proc)) {
|
||||||
mrb_value dt_val = mrb_int_value(Ruby::mrb, delta_time);
|
mrb_value dt_val = mrb_int_value(Ruby::mrb, delta_time);
|
||||||
|
printf("running: update, dt: %lu\n", delta_time);
|
||||||
update.call(1, &dt_val);
|
update.call(1, &dt_val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-10
@@ -60,11 +60,8 @@ struct Block {
|
|||||||
Block() : proc(mrb_nil_value()) {}
|
Block() : proc(mrb_nil_value()) {}
|
||||||
|
|
||||||
void set_proc(mrb_value new_proc) {
|
void set_proc(mrb_value new_proc) {
|
||||||
if (!mrb_nil_p(proc))
|
|
||||||
mrb_gc_unregister(mrb, proc);
|
|
||||||
proc = new_proc;
|
proc = new_proc;
|
||||||
if (!mrb_nil_p(proc))
|
mrb_gc_protect(mrb, proc);
|
||||||
mrb_gc_protect(mrb, proc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Block(const Block &) = delete;
|
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);
|
mrb_value result = mrb_funcall_argv(mrb, proc, mrb_intern_cstr(mrb, "call"), argc, argv);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Block() {
|
|
||||||
mrb_gc_unregister(mrb, proc);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void run_string(const char *code, size_t length) {
|
inline void run_string(const char *code, size_t length) {
|
||||||
int ai = mrb_gc_arena_save(mrb);
|
|
||||||
mrb_load_nstring(mrb, code, length);
|
mrb_load_nstring(mrb, code, length);
|
||||||
mrb_gc_arena_restore(mrb, ai);
|
|
||||||
}
|
}
|
||||||
}; // namespace Ruby
|
}; // namespace Ruby
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,13 @@ world.spawn do |e| # Name is optional
|
|||||||
animation1 = {tiles: tiles[0..3], frame_rate: 10, loop: true}
|
animation1 = {tiles: tiles[0..3], frame_rate: 10, loop: true}
|
||||||
c.animations = {idle: animation1}
|
c.animations = {idle: animation1}
|
||||||
c.current_animation = :idle
|
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
|
end
|
||||||
e.add_component :render do |c|
|
e.add_component :render do |c|
|
||||||
c.z_index = 0
|
c.z_index = 0
|
||||||
|
|||||||
@@ -34,5 +34,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mrb_close(Ruby::mrb);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -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
|
- 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 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)
|
- 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)
|
||||||
|
|||||||
Reference in New Issue
Block a user