aboutsummaryrefslogtreecommitdiff
path: root/src/terrain
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-02-08 15:16:57 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-03-30 08:20:20 +0200
commit9f9c0226d03c060c3c5b12b7a8d37d2e8b372a74 (patch)
tree4fbc9523da206df65b9b68896f48bfd7c2243ac4 /src/terrain
parent6fe03359d8ec1b558f50a75fbf52c496a85939a0 (diff)
downloadjancity-9f9c0226d03c060c3c5b12b7a8d37d2e8b372a74.tar.gz
Refresh camera and terrain rendering on screen resize
Diffstat (limited to 'src/terrain')
-rw-r--r--src/terrain/inc/terrain.h3
-rw-r--r--src/terrain/src/terrain.c23
2 files changed, 21 insertions, 5 deletions
diff --git a/src/terrain/inc/terrain.h b/src/terrain/inc/terrain.h
index 9552555..d5f4e12 100644
--- a/src/terrain/inc/terrain.h
+++ b/src/terrain/inc/terrain.h
@@ -26,10 +26,11 @@ enum terrain_type
struct terrain_map
{
enum terrain_type m[MAP_TILES][MAP_TILES];
- int nx, ny;
+ int nx, ny, last_w, last_h;
};
void terrain_init(struct terrain_map *map);
+void terrain_update(struct terrain_map *map);
int terrain_render(const struct terrain_map *map, const struct camera *cam);
extern struct sprite grass_sprite;
diff --git a/src/terrain/src/terrain.c b/src/terrain/src/terrain.c
index 04df6e6..a528c10 100644
--- a/src/terrain/src/terrain.c
+++ b/src/terrain/src/terrain.c
@@ -7,6 +7,25 @@
struct sprite grass_sprite;
+void terrain_update(struct terrain_map *const map)
+{
+ if (map->last_w != screen_w)
+ {
+ const int extra = !!(screen_w % TERRAIN_SZ);
+
+ map->nx = screen_w / TERRAIN_SZ + extra;
+ map->last_w = screen_w;
+ }
+
+ if (map->last_h != screen_h)
+ {
+ const int extra = !!(screen_h % TERRAIN_SZ);
+
+ map->ny = screen_h / TERRAIN_SZ + extra;
+ map->last_h = screen_h;
+ }
+}
+
int terrain_render(const struct terrain_map *const map,
const struct camera *const cam)
{
@@ -59,9 +78,5 @@ int terrain_render(const struct terrain_map *const map,
void terrain_init(struct terrain_map *const map)
{
- const int extra = !!(screen_w % TERRAIN_SZ);
-
memset(map, 0, sizeof *map);
- map->nx = screen_w / TERRAIN_SZ + extra;
- map->ny = screen_h / TERRAIN_SZ + extra;
}