summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-05-18 13:06:45 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-05-18 13:06:45 +0200
commitc548d74f4daac078c1338e5f8daf4afe980e08a9 (patch)
tree003ded17200ae0bf19f8a56cd7276cf7e590cebb /src
parentf646ddb88ec19307d42729b7babdb77966449327 (diff)
move stuff from stack to heap
Diffstat (limited to 'src')
-rw-r--r--src/bullets.c2
-rw-r--r--src/editor.c64
-rw-r--r--src/game.c14
-rw-r--r--src/map.c137
-rw-r--r--src/objects.c22
-rw-r--r--src/pathfinding.c2
-rw-r--r--src/players.c2
-rw-r--r--src/throwables.c2
-rw-r--r--src/zombies.c4
9 files changed, 132 insertions, 117 deletions
diff --git a/src/bullets.c b/src/bullets.c
index 4de760d..90d8ec7 100644
--- a/src/bullets.c
+++ b/src/bullets.c
@@ -96,7 +96,7 @@ object_type check_if_bullet_collided_with_object(bullet* b, platform_window* win
float dist_of_closest_intersect = __FLT_MAX__;
for (int i = 0; i < MAX_OBJECTS; i++) {
- object o = loaded_map.objects[i];
+ object o = loaded_map->objects[i];
if (!o.active) continue;
if (!o.collision) continue;
if (b->position.z <= o.position.z + o.size.z && b->position.z >= o.position.z) {
diff --git a/src/editor.c b/src/editor.c
index 9eee45c..9585ed1 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -32,15 +32,15 @@ static void update_tile_editor(platform_window* window) {
vec2 pos = screen_pos_to_world_pos(window, _global_mouse.x, _global_mouse.y);
if (pos.x < 0 || pos.y < 0) return;
- if (pos.x >= loaded_map.width || pos.y >= loaded_map.height) return;
+ if (pos.x >= loaded_map->width || pos.y >= loaded_map->height) return;
if (_global_mouse.x < editor_width) return;
switch (tile_edit_state)
{
case PLACING_TILE:
if (is_left_down()) {
- map_to_load.tiles[pos.y][pos.x] = tile_to_place;
- loaded_map.heightmap[pos.y][pos.x].type = tile_to_place;
+ map_to_load->tiles[pos.y][pos.x] = tile_to_place;
+ loaded_map->heightmap[pos.y][pos.x].type = tile_to_place;
//load_mapdata_into_world();
printf("%d %d\n", pos.x, pos.y);
}
@@ -48,14 +48,14 @@ static void update_tile_editor(platform_window* window) {
case RAISING_GROUND:
if (is_left_clicked()) {
- map_to_load.heightmap[pos.y][pos.x]++;
+ map_to_load->heightmap[pos.y][pos.x]++;
load_mapdata_into_world();
}
break;
case LOWERING_GROUND:
if (is_left_clicked()) {
- if (map_to_load.heightmap[pos.y][pos.x] > 0) map_to_load.heightmap[pos.y][pos.x]--;
+ if (map_to_load->heightmap[pos.y][pos.x] > 0) map_to_load->heightmap[pos.y][pos.x]--;
load_mapdata_into_world();
}
break;
@@ -68,15 +68,15 @@ static void update_tile_editor(platform_window* window) {
void update_lighting_panel(platform_window* window, vec2 cursor_pos) {
if (keyboard_is_key_pressed(KEY_ENTER)) {
for (int i = 0; i < MAX_LIGHT_EMITTERS; i++) {
- light_emitter emitter = loaded_map.light_emitters[i];
+ light_emitter emitter = loaded_map->light_emitters[i];
if (emitter.active) continue;
- map_to_load.light_emitters[i].position.x = cursor_pos.x;
- map_to_load.light_emitters[i].position.y = cursor_pos.y;
- map_to_load.light_emitters[i].position.z = 1;
- map_to_load.light_emitters[i].active = 1;
- map_to_load.light_emitters[i].brightness = 1.0f;
- map_to_load.light_emitters[i].range = 10.0f;
+ map_to_load->light_emitters[i].position.x = cursor_pos.x;
+ map_to_load->light_emitters[i].position.y = cursor_pos.y;
+ map_to_load->light_emitters[i].position.z = 1;
+ map_to_load->light_emitters[i].active = 1;
+ map_to_load->light_emitters[i].brightness = 1.0f;
+ map_to_load->light_emitters[i].range = 10.0f;
load_mapdata_into_world();
return;
@@ -131,14 +131,14 @@ void update_editor(platform_window* window)
if (keyboard_is_key_down(KEY_LEFT_CONTROL) && keyboard_is_key_pressed(KEY_S)) {
#if 0
map_data2* tmp = malloc(sizeof(map_data2));
- tmp->width = map_to_load.width;
- tmp->height = map_to_load.height;
- memcpy(tmp->heightmap, map_to_load.heightmap, sizeof(map_to_load.heightmap));
- memcpy(tmp->tiles, map_to_load.tiles, sizeof(map_to_load.tiles));
- memcpy(tmp->light_emitters, map_to_load.light_emitters, sizeof(map_to_load.light_emitters));
+ tmp->width = map_to_load->width;
+ tmp->height = map_to_load->height;
+ memcpy(tmp->heightmap, map_to_load->heightmap, sizeof(map_to_load->heightmap));
+ memcpy(tmp->tiles, map_to_load->tiles, sizeof(map_to_load->tiles));
+ memcpy(tmp->light_emitters, map_to_load->light_emitters, sizeof(map_to_load->light_emitters));
for (int i = 0; i < MAX_OBJECTS; i++) {
- object o = map_to_load.objects[i];
+ object o = map_to_load->objects[i];
tmp->objects[i].active = o.active;
tmp->objects[i].position = o.position;
tmp->objects[i].size = o.size;
@@ -182,9 +182,9 @@ void draw_placing_rectangle(platform_window* window) {
int mouse_tile_x = (((_global_mouse.x + _global_camera.x) - (info.px_incline * mouse_tile_y)) / info.tile_width);
if (mouse_tile_x < 0 || mouse_tile_y < 0) return;
- if (mouse_tile_x >= loaded_map.width || mouse_tile_y >= loaded_map.height) return;
+ if (mouse_tile_x >= loaded_map->width || mouse_tile_y >= loaded_map->height) return;
- tile t = loaded_map.heightmap[mouse_tile_y][mouse_tile_x];
+ tile t = loaded_map->heightmap[mouse_tile_y][mouse_tile_x];
box box = get_render_box_of_square(window, (vec3f){mouse_tile_x, mouse_tile_y, 0}, (vec3f){1,1,t.height});
render_fill_quad_with_outline(box.tl_d, box.tr_d, box.bl_d, box.br_d, rgba(255,0,0, 70));
@@ -261,7 +261,7 @@ void draw_lighting_panel(platform_window* window) {
int offsety = 0;
for (int i = 0; i < MAX_LIGHT_EMITTERS; i++) {
- light_emitter emitter = loaded_map.light_emitters[i];
+ light_emitter emitter = loaded_map->light_emitters[i];
if (!emitter.active) continue;
renderer->render_rectangle(_global_camera.x, _global_camera.y + offset_y + row_h + offsety, editor_width, row_h, rgba(255,0,0,40));
@@ -295,14 +295,14 @@ void draw_lighting_panel(platform_window* window) {
int newy = (_global_mouse.y - drag_start_y) - _global_camera.y;
vec2 newpos = screen_pos_to_world_pos(window, newx, newy);
- map_to_load.light_emitters[i].position.x = orig_x + newpos.x;
- map_to_load.light_emitters[i].position.y = orig_y + newpos.y;
+ map_to_load->light_emitters[i].position.x = orig_x + newpos.x;
+ map_to_load->light_emitters[i].position.y = orig_y + newpos.y;
if (_global_mouse.scroll_state == SCROLL_UP) {
- map_to_load.light_emitters[i].range++;
+ map_to_load->light_emitters[i].range++;
}
if (_global_mouse.scroll_state == SCROLL_DOWN) {
- map_to_load.light_emitters[i].range--;
+ map_to_load->light_emitters[i].range--;
}
load_mapdata_into_world();
}
@@ -387,9 +387,9 @@ void update_object_selection(platform_window* window, vec2 cursor_pos) {
array_push(&l, (void*)&obj);
- int index = (obj-map_to_load.objects);
- loaded_map.objects[index].position.x += diffx;
- loaded_map.objects[index].position.y += diffy;
+ int index = (obj-map_to_load->objects);
+ loaded_map->objects[index].position.x += diffx;
+ loaded_map->objects[index].position.y += diffy;
}
}
}
@@ -406,9 +406,9 @@ void update_object_selection(platform_window* window, vec2 cursor_pos) {
{
object* obj = get_object_at_tile_from_mapfile(x, y);
if (obj) {
- int index = (obj-map_to_load.objects);
- map_to_load.objects[index].position.x = loaded_map.objects[index].position.x;
- map_to_load.objects[index].position.y = loaded_map.objects[index].position.y;
+ int index = (obj-map_to_load->objects);
+ map_to_load->objects[index].position.x = loaded_map->objects[index].position.x;
+ map_to_load->objects[index].position.y = loaded_map->objects[index].position.y;
}
}
}
@@ -444,7 +444,7 @@ void update_object_editor(platform_window* window) {
if (_global_mouse.x < editor_width) return;
if (pos.x < 0 || pos.y < 0) return;
- if (pos.x >= loaded_map.width || pos.y >= loaded_map.height) return;
+ if (pos.x >= loaded_map->width || pos.y >= loaded_map->height) return;
switch (object_edit_state)
{
diff --git a/src/game.c b/src/game.c
index 181a041..a43aa16 100644
--- a/src/game.c
+++ b/src/game.c
@@ -133,6 +133,20 @@ void load_map() {
void fill_game_structs()
{
+ glass_doors = calloc(MAX_GLASS_DOORS, sizeof(glass_door));
+ spawner_tiles = calloc(MAX_SPAWNERS, sizeof(spawner));
+ zombies = calloc(SERVER_MAX_ZOMBIES, sizeof(zombie));
+
+ map_to_load = malloc(sizeof(map_data));
+ loaded_map = malloc(sizeof(extracted_map_data));
+
+ memset(glass_doors, 0, MAX_GLASS_DOORS*sizeof(glass_door));
+ memset(spawner_tiles, 0, MAX_SPAWNERS*sizeof(spawner));
+ memset(zombies, 0, SERVER_MAX_ZOMBIES*sizeof(zombie));
+
+ memset(map_to_load, 0, sizeof(map_data));
+ memset(loaded_map, 0, sizeof(extracted_map_data));
+
global_audio_source_position = (vec3f){-1,-1,-1};
object _localobject_dict[OBJECT_END] = {
diff --git a/src/map.c b/src/map.c
index d05f8a4..01c25e4 100644
--- a/src/map.c
+++ b/src/map.c
@@ -5,19 +5,19 @@ int player_zoom = 30;
static int get_height_of_tile_tl(int current_height, int x, int y) {
int highest_point = current_height;
if (y > 0) {
- int tile_above = map_to_load.heightmap[y-1][x];
+ int tile_above = map_to_load->heightmap[y-1][x];
if (tile_above > highest_point) {
highest_point = tile_above;
}
}
if (y > 0 && x > 0) {
- int tile_above = map_to_load.heightmap[y-1][x-1];
+ int tile_above = map_to_load->heightmap[y-1][x-1];
if (tile_above > highest_point) {
highest_point = tile_above;
}
}
if (x > 0) {
- int tile_above = map_to_load.heightmap[y][x-1];
+ int tile_above = map_to_load->heightmap[y][x-1];
if (tile_above > highest_point) {
highest_point = tile_above;
}
@@ -29,19 +29,19 @@ static int get_height_of_tile_tl(int current_height, int x, int y) {
static int get_height_of_tile_br(int current_height, int x, int y) {
int highest_point = current_height;
if (x < MAP_SIZE_X-1) {
- int tile_right = map_to_load.heightmap[y][x+1];
+ int tile_right = map_to_load->heightmap[y][x+1];
if (tile_right > highest_point) {
highest_point = tile_right;
}
}
if (y < MAP_SIZE_Y-1 && x < MAP_SIZE_X-1) {
- int tile_bottom_right = map_to_load.heightmap[y+1][x+1];
+ int tile_bottom_right = map_to_load->heightmap[y+1][x+1];
if (tile_bottom_right > highest_point) {
highest_point = tile_bottom_right;
}
}
if (y < MAP_SIZE_Y-1) {
- int tile_bottom = map_to_load.heightmap[y+1][x];
+ int tile_bottom = map_to_load->heightmap[y+1][x];
if (tile_bottom > highest_point) {
highest_point = tile_bottom;
}
@@ -52,19 +52,19 @@ static int get_height_of_tile_br(int current_height, int x, int y) {
static int get_height_of_tile_bl(int current_height, int x, int y) {
int highest_point = current_height;
if (y > 0 && x > 0) {
- int tile_left = map_to_load.heightmap[y][x-1];
+ int tile_left = map_to_load->heightmap[y][x-1];
if (tile_left > highest_point) {
highest_point = tile_left;
}
}
if (y < MAP_SIZE_Y-1 && x > 0) {
- int tile_bottom_left = map_to_load.heightmap[y+1][x-1];
+ int tile_bottom_left = map_to_load->heightmap[y+1][x-1];
if (tile_bottom_left > highest_point) {
highest_point = tile_bottom_left;
}
}
if (y < MAP_SIZE_Y-1) {
- int tile_bottom = map_to_load.heightmap[y+1][x];
+ int tile_bottom = map_to_load->heightmap[y+1][x];
if (tile_bottom > highest_point) {
highest_point = tile_bottom;
}
@@ -75,19 +75,19 @@ static int get_height_of_tile_bl(int current_height, int x, int y) {
static int get_height_of_tile_tr(int current_height, int x, int y) {
int highest_point = current_height;
if (y > 0) {
- int tile_above = map_to_load.heightmap[y-1][x];
+ int tile_above = map_to_load->heightmap[y-1][x];
if (tile_above > highest_point) {
highest_point = tile_above;
}
}
if (y > 0 && x < MAP_SIZE_X-1) {
- int tile_above_right = map_to_load.heightmap[y-1][x+1];
+ int tile_above_right = map_to_load->heightmap[y-1][x+1];
if (tile_above_right > highest_point) {
highest_point = tile_above_right;
}
}
if (x < MAP_SIZE_X-1) {
- int tile_right = map_to_load.heightmap[y][x+1];
+ int tile_right = map_to_load->heightmap[y][x+1];
if (tile_right > highest_point) {
highest_point = tile_right;
}
@@ -109,7 +109,7 @@ static bool ray_intersects_with_object(vec3f begin, vec3f end) {
vec2f bend = (vec2f){end.x, end.y};
for (int i = 0; i < MAX_OBJECTS; i++) {
- object o = loaded_map.objects[i];
+ object o = loaded_map->objects[i];
if (!o.active) continue;
if (begin.z <= o.position.z + o.size.z && begin.z >= o.position.z) {
box obj_box = get_box_of_square((vec3f){o.position.x, o.position.y, o.position.z}, o.size);
@@ -159,34 +159,34 @@ int sort_objects(const void * obj1, const void* obj2) {
}
void load_mapdata_into_world() {
- loaded_map.width = map_to_load.width;
- loaded_map.height = map_to_load.height;
+ loaded_map->width = map_to_load->width;
+ loaded_map->height = map_to_load->height;
// Load heightmap
for (int y = 0; y < MAP_SIZE_Y; y++) {
for (int x = MAP_SIZE_X-1; x >= 0; x--) {
- int h = map_to_load.heightmap[y][x];
+ int h = map_to_load->heightmap[y][x];
int highest_point_topleft = get_height_of_tile_tl(h, x, y);
int highest_point_topright = get_height_of_tile_tr(h, x, y);
int highest_point_bottomright = get_height_of_tile_br(h, x, y);
int highest_point_bottomleft = get_height_of_tile_bl(h, x, y);
- if (x >= 205) map_to_load.tiles[y][x] = TILE_NONE;
+ if (x >= 205) map_to_load->tiles[y][x] = TILE_NONE;
- loaded_map.heightmap[y][x] = (tile){.height = h, .type = map_to_load.tiles[y][x], highest_point_topleft, highest_point_topright, highest_point_bottomleft, highest_point_bottomright};
- loaded_map.lightmap[y][x] = (light_data){0.0f,0.0f,0.0f,0.0f};
+ loaded_map->heightmap[y][x] = (tile){.height = h, .type = map_to_load->tiles[y][x], highest_point_topleft, highest_point_topright, highest_point_bottomleft, highest_point_bottomright};
+ loaded_map->lightmap[y][x] = (light_data){0.0f,0.0f,0.0f,0.0f};
}
}
// Load emitters
for (int i = 0; i < MAX_LIGHT_EMITTERS; i++) {
- loaded_map.light_emitters[i] = map_to_load.light_emitters[i];
- loaded_map.light_emitters[i].position.z = 1;
+ loaded_map->light_emitters[i] = map_to_load->light_emitters[i];
+ loaded_map->light_emitters[i].position.z = 1;
}
// Load lightmap
for (int l = 0; l < MAX_LIGHT_EMITTERS; l++) {
- light_emitter emitter = loaded_map.light_emitters[l];
+ light_emitter emitter = loaded_map->light_emitters[l];
if (!emitter.active) continue;
int ystart = emitter.position.y - emitter.range-2;
@@ -200,12 +200,13 @@ void load_mapdata_into_world() {
if (xend >= MAP_SIZE_X) xend = MAP_SIZE_X-1;
for (int y = ystart; y <= yend; y++) {
+ if (y < 0) continue;
for (int x = xstart; x <= xend; x++) {
-
- float dist_tl = distance_between_3f(emitter.position, (vec3f){x, y, loaded_map.heightmap[y][x].topleft});
- float dist_tr = distance_between_3f(emitter.position, (vec3f){x, y, loaded_map.heightmap[y][x].topright});
- float dist_bl = distance_between_3f(emitter.position, (vec3f){x, y, loaded_map.heightmap[y][x].bottomleft});
- float dist_br = distance_between_3f(emitter.position, (vec3f){x, y, loaded_map.heightmap[y][x].bottomright});
+ if (x < 0) continue;
+ float dist_tl = distance_between_3f(emitter.position, (vec3f){x, y, loaded_map->heightmap[y][x].topleft});
+ float dist_tr = distance_between_3f(emitter.position, (vec3f){x, y, loaded_map->heightmap[y][x].topright});
+ float dist_bl = distance_between_3f(emitter.position, (vec3f){x, y, loaded_map->heightmap[y][x].bottomleft});
+ float dist_br = distance_between_3f(emitter.position, (vec3f){x, y, loaded_map->heightmap[y][x].bottomright});
if (dist_tl > emitter.range) {
continue;
@@ -220,58 +221,58 @@ void load_mapdata_into_world() {
if (p_bl < 0.0f) p_bl = 0.0f;
if (p_br < 0.0f) p_br = 0.0f;
- if (ray_intersects_with_ground((vec3f){x, y, loaded_map.heightmap[y][x].topleft}, emitter.position)) {
+ if (ray_intersects_with_ground((vec3f){x, y, loaded_map->heightmap[y][x].topleft}, emitter.position)) {
p_tl = 0.0f;
}
- if (ray_intersects_with_ground((vec3f){x, y, loaded_map.heightmap[y][x].topright}, emitter.position)) {
+ if (ray_intersects_with_ground((vec3f){x, y, loaded_map->heightmap[y][x].topright}, emitter.position)) {
p_tr = 0.0f;
}
- if (ray_intersects_with_ground((vec3f){x, y, loaded_map.heightmap[y][x].bottomleft}, emitter.position)) {
+ if (ray_intersects_with_ground((vec3f){x, y, loaded_map->heightmap[y][x].bottomleft}, emitter.position)) {
p_bl = 0.0f;
}
- if (ray_intersects_with_ground((vec3f){x, y, loaded_map.heightmap[y][x].bottomright}, emitter.position)) {
+ if (ray_intersects_with_ground((vec3f){x, y, loaded_map->heightmap[y][x].bottomright}, emitter.position)) {
p_br = 0.0f;
}
/*
- if (ray_intersects_with_object((vec3f){x, y, loaded_map.heightmap[y][x].topleft}, emitter.position)) {
+ if (ray_intersects_with_object((vec3f){x, y, loaded_map->heightmap[y][x].topleft}, emitter.position)) {
p_tl = 0.0f;
}
- if (ray_intersects_with_object((vec3f){x, y, loaded_map.heightmap[y][x].topright}, emitter.position)) {
+ if (ray_intersects_with_object((vec3f){x, y, loaded_map->heightmap[y][x].topright}, emitter.position)) {
p_tr = 0.0f;
}
- if (ray_intersects_with_object((vec3f){x, y, loaded_map.heightmap[y][x].bottomleft}, emitter.position)) {
+ if (ray_intersects_with_object((vec3f){x, y, loaded_map->heightmap[y][x].bottomleft}, emitter.position)) {
p_bl = 0.0f;
}
- if (ray_intersects_with_object((vec3f){x, y, loaded_map.heightmap[y][x].bottomright}, emitter.position)) {
+ if (ray_intersects_with_object((vec3f){x, y, loaded_map->heightmap[y][x].bottomright}, emitter.position)) {
p_br = 0.0f;
}
*/
- p_tl += loaded_map.lightmap[y][x].tl;
- p_tr += loaded_map.lightmap[y][x].tr;
- p_bl += loaded_map.lightmap[y][x].bl;
- p_br += loaded_map.lightmap[y][x].br;
+ p_tl += loaded_map->lightmap[y][x].tl;
+ p_tr += loaded_map->lightmap[y][x].tr;
+ p_bl += loaded_map->lightmap[y][x].bl;
+ p_br += loaded_map->lightmap[y][x].br;
if (p_tl > 1.0f) p_tl = 1.0f;
if (p_tr > 1.0f) p_tr = 1.0f;
if (p_bl > 1.0f) p_bl = 1.0f;
if (p_br > 1.0f) p_br = 1.0f;
- loaded_map.lightmap[y][x].tl = p_tl;
- loaded_map.lightmap[y][x].tr = p_tr;
- loaded_map.lightmap[y][x].bl = p_bl;
- loaded_map.lightmap[y][x].br = p_br;
+ loaded_map->lightmap[y][x].tl = p_tl;
+ loaded_map->lightmap[y][x].tr = p_tr;
+ loaded_map->lightmap[y][x].bl = p_bl;
+ loaded_map->lightmap[y][x].br = p_br;
}
}
}
// Load objects
- memcpy(loaded_map.objects, map_to_load.objects, sizeof(loaded_map.objects));
+ memcpy(loaded_map->objects, map_to_load->objects, sizeof(loaded_map->objects));
// Load special objects
for (int i = 0; i < MAX_OBJECTS; i++) {
- object o = loaded_map.objects[i];
+ object o = loaded_map->objects[i];
if (!o.active) continue;
- if (o.position.x >= 205) map_to_load.objects[i].active = 0;
+ if (o.position.x >= 205) map_to_load->objects[i].active = 0;
if (o.type == OBJECT_ZOMBIE_SPAWNER) {
create_spawner((vec2){.x = o.position.x, .y = o.position.y});
@@ -289,21 +290,21 @@ void load_mapdata_into_world() {
}
void create_empty_map() {
- map_to_load.width = MAP_SIZE_X;
- map_to_load.height = MAP_SIZE_Y;
+ map_to_load->width = MAP_SIZE_X;
+ map_to_load->height = MAP_SIZE_Y;
for (int y = 0; y < MAP_SIZE_Y; y++) {
for (int x = 0; x < MAP_SIZE_X; x++) {
- map_to_load.tiles[y][x] = TILE_FLOOR1;
+ map_to_load->tiles[y][x] = TILE_FLOOR1;
}
}
for (int x = 0; x < MAP_SIZE_X; x++) {
- map_to_load.objects[x] = (object){.active = true, .position = (vec3f){x, 0, 0}, .size = (vec3f){1,1,1}, .type = OBJECT_METAL_WALL};
+ map_to_load->objects[x] = (object){.active = true, .position = (vec3f){x, 0, 0}, .size = (vec3f){1,1,1}, .type = OBJECT_METAL_WALL};
}
- //map_to_load.light_emitters[0] = (light_emitter){.brightness = 1.0f, .position = (vec3f){0, 0, 10}, .range = 20.0f, .active = true};
- //map_to_load.light_emitters[1] = (light_emitter){.brightness = 1.0f, .position = (vec3f){0, 30, 10}, .range = 20.0f, .active = true};
+ //map_to_load->light_emitters[0] = (light_emitter){.brightness = 1.0f, .position = (vec3f){0, 0, 10}, .range = 20.0f, .active = true};
+ //map_to_load->light_emitters[1] = (light_emitter){.brightness = 1.0f, .position = (vec3f){0, 30, 10}, .range = 20.0f, .active = true};
load_mapdata_into_world();
}
@@ -312,20 +313,20 @@ void load_map_from_file() {
// load map from file..
file_content content = platform_read_file_content("data/maps/map1.dat", "rb");
- memcpy(&map_to_load, content.content, content.content_length);
+ memcpy(map_to_load, content.content, content.content_length);
- //map_to_load.width = MAP_SIZE_X;
- //map_to_load.height = MAP_SIZE_Y;
- //memcpy(map_to_load.heightmap, map, sizeof(map));
+ //map_to_load->width = MAP_SIZE_X;
+ //map_to_load->height = MAP_SIZE_Y;
+ //memcpy(map_to_load->heightmap, map, sizeof(map));
- loaded_map.width = map_to_load.width;
- loaded_map.height = map_to_load.height;
+ loaded_map->width = map_to_load->width;
+ loaded_map->height = map_to_load->height;
load_mapdata_into_world();
}
tile get_tile_under_coords(float x, float y) {
- return loaded_map.heightmap[(int)(y)][(int)(x)];
+ return loaded_map->heightmap[(int)(y)][(int)(x)];
}
float get_height_of_tile_under_coords(float tocheckx, float tochecky) {
@@ -497,7 +498,7 @@ void draw_grid(platform_window* window) {
if (x < tilemap_render_min_x) continue;
if (x > tilemap_render_max_x) continue;
- tile tile = loaded_map.heightmap[y][x];
+ tile tile = loaded_map->heightmap[y][x];
float xdiff_between_bottom_and_top = info.px_incline;
float render_x = (info.tile_width * x) + (xdiff_between_bottom_and_top * y);
@@ -550,10 +551,10 @@ void draw_grid(platform_window* window) {
bottomright.x, bottomright.y,
topright.x, topright.y);
- color c_tl = rgba(0,0,0, (u8)(min_brightness * (1.0f - loaded_map.lightmap[y][x].tl)));
- color c_tr = rgba(0,0,0, (u8)(min_brightness * (1.0f - loaded_map.lightmap[y][x].tr)));
- color c_bl = rgba(0,0,0, (u8)(min_brightness * (1.0f - loaded_map.lightmap[y][x].bl)));
- color c_br = rgba(0,0,0, (u8)(min_brightness * (1.0f - loaded_map.lightmap[y][x].br)));
+ color c_tl = rgba(0,0,0, (u8)(min_brightness * (1.0f - loaded_map->lightmap[y][x].tl)));
+ color c_tr = rgba(0,0,0, (u8)(min_brightness * (1.0f - loaded_map->lightmap[y][x].tr)));
+ color c_bl = rgba(0,0,0, (u8)(min_brightness * (1.0f - loaded_map->lightmap[y][x].bl)));
+ color c_br = rgba(0,0,0, (u8)(min_brightness * (1.0f - loaded_map->lightmap[y][x].br)));
renderer->render_quad_gradient(topleft.x, topleft.y,
bottomleft.x, bottomleft.y,
bottomright.x, bottomright.y,
@@ -571,10 +572,10 @@ void draw_grid(platform_window* window) {
}
*/
- loaded_map.heightmap[y][x].tl = topleft;
- loaded_map.heightmap[y][x].tr = topright;
- loaded_map.heightmap[y][x].bl = bottomleft;
- loaded_map.heightmap[y][x].br = bottomright;
+ loaded_map->heightmap[y][x].tl = topleft;
+ loaded_map->heightmap[y][x].tr = topright;
+ loaded_map->heightmap[y][x].bl = bottomleft;
+ loaded_map->heightmap[y][x].br = bottomright;
}
}
}
diff --git a/src/objects.c b/src/objects.c
index 72535f6..e7bb06c 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -47,25 +47,25 @@ void render_fill_quad_with_outline(vec2f tl, vec2f tr, vec2f bl, vec2f br, color
object* get_object_at_tile_from_mapfile(float x, float y) {
for (int i = 0; i < MAX_OBJECTS; i++) {
- object o = map_to_load.objects[i];
+ object o = map_to_load->objects[i];
if (!o.active) continue;
- if (x >= o.position.x && x < o.position.x + o.size.x && y >= o.position.y && y < o.position.y + o.size.y) return &map_to_load.objects[i];
+ if (x >= o.position.x && x < o.position.x + o.size.x && y >= o.position.y && y < o.position.y + o.size.y) return &map_to_load->objects[i];
}
return 0;
}
object* get_pobject_at_tile(float x, float y) {
for (int i = 0; i < MAX_OBJECTS; i++) {
- object o = loaded_map.objects[i];
+ object o = loaded_map->objects[i];
if (!o.active) continue;
- if (x >= o.position.x && x < o.position.x + o.size.x && y >= o.position.y && y < o.position.y + o.size.y) return &loaded_map.objects[i];
+ if (x >= o.position.x && x < o.position.x + o.size.x && y >= o.position.y && y < o.position.y + o.size.y) return &loaded_map->objects[i];
}
return 0;
}
object get_object_at_tile(float x, float y) {
for (int i = 0; i < MAX_OBJECTS; i++) {
- object o = loaded_map.objects[i];
+ object o = loaded_map->objects[i];
if (!o.active) continue;
if (x >= o.position.x && x < o.position.x + o.size.x && y >= o.position.y && y < o.position.y + o.size.y) return o;
}
@@ -80,13 +80,13 @@ void add_object(object obj) {
}
for (int i = 0; i < MAX_OBJECTS; i++) {
- object o = map_to_load.objects[i];
+ object o = map_to_load->objects[i];
if (o.active) continue;
- map_to_load.objects[i] = obj;
- map_to_load.objects[i].active = true;
+ map_to_load->objects[i] = obj;
+ map_to_load->objects[i].active = true;
// sort y-axis
- qsort(map_to_load.objects, MAX_OBJECTS, sizeof(object), sort_objects);
+ qsort(map_to_load->objects, MAX_OBJECTS, sizeof(object), sort_objects);
return;
}
@@ -243,8 +243,8 @@ void draw_objects(platform_window* window) {
float prev_y = 0;
for (int i = 0; i < MAX_OBJECTS; i++) {
- if (!loaded_map.objects[i].active) continue;
- object o = loaded_map.objects[i];
+ if (!loaded_map->objects[i].active) continue;
+ object o = loaded_map->objects[i];
if (o.type == OBJECT_GLASS_DOOR_H) continue;
if (o.type == OBJECT_GLASS_DOOR_V) continue;
diff --git a/src/pathfinding.c b/src/pathfinding.c
index a6b08d5..ddf5ae6 100644
--- a/src/pathfinding.c
+++ b/src/pathfinding.c
@@ -8,7 +8,7 @@ float distance_between(vec2f v1, vec2f v2)
bool can_walk_at(float x, float y)
{
for (int i = 0; i < MAX_OBJECTS; i++) {
- object o = loaded_map.objects[i];
+ object o = loaded_map->objects[i];
if (!o.active) continue;
if (!o.collision) continue;
if (o.type == OBJECT_ZOMBIE_SPAWNER) continue;
diff --git a/src/players.c b/src/players.c
index 9a3804a..4eb4033 100644
--- a/src/players.c
+++ b/src/players.c
@@ -228,7 +228,7 @@ bool check_if_player_collided_with_box(player p, box o) {
object check_if_player_collided_with_object(player p) {
for (int i = 0; i < MAX_OBJECTS; i++) {
- object o = loaded_map.objects[i];
+ object o = loaded_map->objects[i];
if (!o.active) continue;
if (!o.collision) continue;
diff --git a/src/throwables.c b/src/throwables.c
index 867a762..9e88d7e 100644
--- a/src/throwables.c
+++ b/src/throwables.c
@@ -71,7 +71,7 @@ bool check_if_throwable_collided_with_object(throwable* b, vec3f oldpos, vec3f n
bool result = false;
for (int i = 0; i < MAX_OBJECTS; i++) {
- object o = loaded_map.objects[i];
+ object o = loaded_map->objects[i];
if (!o.active) continue;
if (b->position.z <= o.position.z + o.size.z && b->position.z >= o.position.z) {
box obj_box = get_box_of_square((vec3f){o.position.x, o.position.y, o.position.z}, o.size);
diff --git a/src/zombies.c b/src/zombies.c
index a4fc94e..d553d4a 100644
--- a/src/zombies.c
+++ b/src/zombies.c
@@ -110,7 +110,7 @@ static vec2f get_random_target_for_zombie(zombie o) {
if (target.x <= 0 || target.y <= 0) goto try_again;
if (target.x >= MAP_SIZE_X-1 || target.y >= MAP_SIZE_Y-1) goto try_again;
- if (loaded_map.heightmap[(int)target.y][(int)target.x].type == TILE_NONE) goto try_again; // Outside of map.
+ if (loaded_map->heightmap[(int)target.y][(int)target.x].type == TILE_NONE) goto try_again; // Outside of map.
object obj = get_object_at_tile(target.x, target.y);
if (obj.active && obj.active) goto try_again;
@@ -243,7 +243,7 @@ void draw_spawners(platform_window* window) {
int render_x = (info.tile_width * spawner.position.x) + (info.px_incline * spawner.position.y);
int render_y = info.tile_height * spawner.position.y;
- tile tile = loaded_map.heightmap[spawner.position.y][spawner.position.x];
+ tile tile = loaded_map->heightmap[spawner.position.y][spawner.position.x];
sprite_frame frame = sprite_get_frame(img_spawner, &spawner.sprite);