case "$1" in
build) shift; onyx -V -I ../src build -o $dest $@ ;;
run) onyx-run $dest ;;
+ debug) onyx-run --debug $dest ;;
*) onyx run -V -I ../src build $@ ;;
esac
\ No newline at end of file
update :: (use this: ^CollisionMaskComponent, entity: ^Entity, dt: f32) {
if mask.data == null {
memory.alloc_slice(^mask, width * height);
- }
- for y: height {
- for x: width {
- mask[y * width + x] = false;
- area := Rect.{ ~~(x * grid_size), ~~(y * grid_size), ~~grid_size, ~~grid_size };
+ for y: height {
+ for x: width {
+ mask[y * width + x] = false;
+ area := Rect.{ ~~(x * grid_size), ~~(y * grid_size), ~~grid_size, ~~grid_size };
- for scene.entities {
- if it.flags & .Solid {
- if Rect.intersects(Entity.get_rect(it), area) {
- mask[y * width + x] = true;
- continue continue;
+ for scene.entities {
+ if it.flags & .Solid {
+ if Rect.intersects(Entity.get_rect(it), area) {
+ mask[y * width + x] = true;
+ continue continue;
+ }
}
}
}
}
get_path :: (use this: ^CollisionMaskComponent, start: Vector2, target: Vector2, buf: ^[..] Vector2) -> bool {
- Node :: struct {
- pos: Vector2i;
- g: f32 = 0;
- h: f32 = 0;
- }
-
- Visited_Node :: struct {
- prev: Vector2i;
- cost: f32;
- }
-
start_pos := Vector2i.{ ~~start.x / grid_size, ~~start.y / grid_size };
target_pos := Vector2i.{ ~~target.x / grid_size, ~~target.y / grid_size };
- stack: [..] Node;
- stack << .{ start_pos };
+ stack := array.make(.[ .{ pos=start_pos, g=0.0f, h=0.0f } ]);
- visited: Map(Vector2i, Visited_Node);
+ visited: Map(Vector2i, #type struct{ prev: Vector2i; cost: f32 });
found := false;
while stack.count != 0 {
}
}
- array.quicksort(stack, (n1: ^Node, n2: typeof n1) => {
+ array.quicksort(stack, (n1, n2) => {
f1 := n1.g + n1.h;
f2 := n2.g + n2.h;
if f1 < f2 do return 1;
item_info := item_store->get_item(dispenser_comp.item);
money_comp := scene->first_component(MoneyComponent);
- if !money_comp->withdraw(item_info.production_cost) do return;
+ if !(money_comp->withdraw(item_info.production_cost)) do return;
item := scene->create_from_schematic("Item_Entity");
if item == null {
if path.count == 0 {
array.clear(^path);
collision_mask := scene->first_component(CollisionMaskComponent);
- if !collision_mask->get_path(entity.pos, target_location, ^path) {
+ if !(collision_mask->get_path(entity.pos, target_location, ^path)) {
debug_log(.Warning, "No path for patron.");
return;
}
debug_log(.Debug, "Discovered component: '{}'", s_info.name);
comp_type := cast(type_expr) index;
- if !component_vtables->has(comp_type) {
+ if !(component_vtables->has(comp_type)) {
vtable := new(Component_Vtable, allocator=entity_allocator);
runtime.info.populate_struct_vtable(vtable, comp_type, safe=false);
component_vtables[comp_type] = vtable;
comp := cast(^Component) new(component_type, allocator=entity_allocator);
comp.type = component_type;
- if !component_vtables->has(comp.type) {
+ if !(component_vtables->has(comp.type)) {
vtable := new(Component_Vtable, allocator=entity_allocator);
type_info.populate_struct_vtable(vtable, component_type, safe=false);
component_vtables[comp.type] = vtable;
use core.intrinsics.onyx {__initialize}
comp: ^component_type;
- if !entity->has(component_type) {
- comp = cast(^component_type) this->create_component(component_type);
+ if !(entity->has(component_type)) {
+ comp = cast(^component_type) (this->create_component(component_type));
// The 'create_component' function does not initailize the component, as it is not
// a compile time known parameter and therefore cannot know how to initialize it.
scene_query_by_component :: (use this: ^Scene, area: Rect, comp_type: type_expr) -> [] ^Entity {
ents: [..] ^Entity;
for entities {
- if !it.components->has(comp_type) do continue;
+ if !(it.components->has(comp_type)) do continue;
if Rect.intersects(Entity.get_rect(it), area) {
ents << it;
game_init :: () {
Audio_Manager.init();
+ Audio_Manager.set_volume(0.1);
distortion_shader = shader_make("./assets/shaders/crt.glsl");
shader_link_window_matrix_block(distortion_shader);
game_draw :: () {
@REMOVE @DEBUG
- Spritesheet', _ := texture_lookup(#cstr "./assets/images/spritesheet.png");
+ // Spritesheet', _ := texture_lookup(#cstr "./assets/images/spritesheet.png");
canvas_use(^scene_canvas);
immediate_clear(.{0.15, 0.15, 0.2});
frame_count = 0;
}
- update(cast(f32) dt);
+ update(~~ dt);
draw();
}
}
alcCloseDevice(device);
}
+ set_volume :: (volume: f32) {
+ alListenerf(AL_GAIN, volume);
+ }
+
get_sound :: (path: str) -> Sound {
if loaded_sounds->has(path) {
return loaded_sounds[path];