"cwd": "${workspaceFolder}/run_tree"
},
"problemMatcher": "$onyx",
- "command": "onyx run -V -I ../src build",
+ "command": "./run.sh",
"group": {
"kind": "build",
"isDefault": true
--- /dev/null
+Relevant game-engine functionality
+----------------------------------
+
+## Immediate Mode Rendering
+Render simple shapes and images using the following functions.
+
+### Drawing
+- immediate_flush()
+ All draw operations are batched together.
+ Call this to flush the batch and render everything.
+ This should be called at least once per frame, in practice much more often.
+
+- immediate_clear(color: Color)
+ Clears the screen with `color`
+
+- immediate_rectangle(x, y, w, h: f32)
+ Render a rectangle at `(x, y)` with size `w` by `h`.
+ `(x, y)` is the top-left of the rectangle.
+
+- immediate_image(image: ^Texture, x, y, w, h: f32)
+ Render the `image` at `(x, y)` with size `w` by `h`.
+ `w` and `h` are given in destination pixels, not a scale factor of the image size.
+ Use image.width, image.height to get the size of the image.
+
+- immediate_triangle(x1, x2, x3: Vector2)
+ Render a triangle with verticies `x1`, `x2`, `x3`.
+
+### Stateful operations
+- immediate_set_color(color: Color)
+ Set the color to be used by other drawing primitivies.
+
+### Structures
+- Color :: struct { r, g, b, a: f32; }
+
+
--- /dev/null
+onyx run -V -I ../src build
use package glfw3
Entity_Vtable :: struct {
- draw : (entity: ^Entity) -> void;
- update : (entity: ^Entity, dt: f32) -> void;
+ update : (entity: ^Entity, dt: f32) -> void = null_proc;
+ draw : (entity: ^Entity) -> void = null_proc;
}
Entity :: struct {
use vtable: ^Entity_Vtable;
+
id: u32;
+ type: type_expr;
+
+ pos: Vector2;
+}
+
+IsEntity :: interface (e: $E) {
+ { e } -> ^Entity;
}
Entity_Manager :: struct {
return em;
}
-entity_manager_register :: (use this: ^Entity_Manager, entity: ^Entity) -> u32 {
- id := next_entity_id;
+entity_manager_register :: (use this: ^Entity_Manager, entity: ^$T) -> u32 where IsEntity(^T) {
+ entity.type = T;
+ entity.id = next_entity_id;
next_entity_id += 1;
- entity.id = id;
entities << entity;
- return id;
+ return entity.id;
}
entity_manager_update :: (use this: ^Entity_Manager, dt: f32) {
Player :: struct {
use entity: Entity;
-
- pos: Vector2;
}
player_make :: () -> ^Player {
}
player_update :: (use this: ^Player, dt: f32) {
- if is_key_down(GLFW_KEY_W) do pos.y -= 100 * dt;
- if is_key_down(GLFW_KEY_S) do pos.y += 100 * dt;
- if is_key_down(GLFW_KEY_A) do pos.x -= 100 * dt;
- if is_key_down(GLFW_KEY_D) do pos.x += 100 * dt;
+ if is_key_down(GLFW_KEY_W) do pos.y -= 200 * dt;
+ if is_key_down(GLFW_KEY_S) do pos.y += 200 * dt;
+ if is_key_down(GLFW_KEY_A) do pos.x -= 200 * dt;
+ if is_key_down(GLFW_KEY_D) do pos.x += 200 * dt;
}
player_draw :: (use this: ^Player) {
- immediate_set_color(.{0.4,0.4,1});
- immediate_rectangle(pos.x, pos.y, 50, 50);
+ immediate_set_color(.{1,1,1});
+ immediate_image(^player_texture, pos.x, pos.y, 64, 64);
}
#local player_vtable := Entity_Vtable.{ update=player_update, draw=player_draw };
+
+player_texture: Texture;
chars = char_data
};
+ font_registry[fd] = font;
+
return font;
}
window_width: u32
window_height: u32
-player_texture: Texture;
main_font: Font;
entity_manager: Entity_Manager;
update_view_matrix();
player_texture = texture_make(#cstr "./assets/images/player.png");
- main_font = font_make(.{"./assets/fonts/calibri.ttf", 32});
+ main_font = font_lookup(.{"./assets/fonts/calibri.ttf", 32});
entity_manager = entity_manager_make();
player := player_make();
immediate_set_color(.{0,0,1});
immediate_rectangle(0, 0, 100, 100);
- immediate_set_color(.{1,0,0});
- for i: 100 {
- immediate_image(^player_texture, ~~(100 + 64 * i), 50, 64, 64);
- }
-
entity_manager->draw();
mx, my := mouse_get_position();