summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2024-08-10 12:27:32 +0200
committerMitya Selivanov <automainint@guattari.tech>2024-08-10 12:27:32 +0200
commit5470826fd6a3ed5ad8af947239ee2fc1d1058cac (patch)
tree52854f16430bf5ff7abdc7228687194fa24892fe /examples
parent73b1fd787554e7a3cdd778393d846e662022e7d7 (diff)
downloadreduced_system_layer-5470826fd6a3ed5ad8af947239ee2fc1d1058cac.zip
Update landscape
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/landscape.c135
1 files changed, 14 insertions, 121 deletions
diff --git a/examples/landscape.c b/examples/landscape.c
index 624183e..018242b 100755
--- a/examples/landscape.c
+++ b/examples/landscape.c
@@ -180,21 +180,7 @@ Platform platform = {0};
#define EPS 1e-8
enum {
- F_ENABLED = 1,
- F_HIDDEN = 2,
-
- TILE_NONE = 0,
- TILE_GROUND,
- TILE_ROCK,
- TILE_GRASS,
-
- ENTITY_NONE = 0,
- ENTITY_STONE,
- ENTITY_TREE,
- ENTITY_CABIN,
-
- MAX_NUM_TILES = 10 * 1024 * 1024,
- MAX_NUM_ENTITIES = 10 * 1024 * 1024,
+ MAX_NUM_TILES = 10 * 1024 * 1024,
};
typedef struct {
@@ -227,41 +213,20 @@ typedef struct {
} Screen_Area;
typedef struct {
- u32 flags;
- u16 id;
- u16 variation;
- f64 height;
- f64 water;
-} Tile;
-
-typedef struct {
- u32 flags;
- i32 version;
- u16 type;
- u16 variation;
- f64 size;
i64 time;
- Vec3 position;
-} Entity;
-
-typedef struct {
- i64 time;
- i32 map_num_x;
- i32 map_num_y;
- Tile map[MAX_NUM_TILES];
- i32 num_entities;
- i32 next_entity;
- Entity entities[MAX_NUM_ENTITIES];
- f64 screen_distance;
- f64 zoom;
- f64 tilt;
- Vec3 eye_position;
- Vec3 right;
- Vec3 up;
- Vec3 forward;
- Vec3 screen_x_axis;
- Vec3 screen_y_axis;
- Vec3 screen_z_axis;
+ i32 map_num_x;
+ i32 map_num_y;
+ f64 map[MAX_NUM_TILES];
+ f64 screen_distance;
+ f64 zoom;
+ f64 tilt;
+ Vec3 eye_position;
+ Vec3 right;
+ Vec3 up;
+ Vec3 forward;
+ Vec3 screen_x_axis;
+ Vec3 screen_y_axis;
+ Vec3 screen_z_axis;
} World;
#define CHECK(fail_return, condition) \
@@ -269,9 +234,6 @@ typedef struct {
if (!(condition)) \
return fail_return;
-#define Y(flags, mask) (((flags) & (mask)) == (mask))
-#define N(flags, mask) (((flags) & (mask)) != (mask))
-
World world = {0};
f64 dot(Vec3 a, Vec3 b) {
@@ -397,59 +359,6 @@ Vec3 screen_to_world(i32 x, i32 y) {
return add(world.eye_position, r);
}
-Handle e_create_in(i32 index, Entity data) {
- CHECK((Handle) {0}, index < MAX_NUM_ENTITIES);
- CHECK((Handle) {0}, N(world.entities[index].flags, F_ENABLED));
- Handle h = {
- .index = index,
- .version = world.entities[index].version + 1,
- };
- world.entities[index] = data;
- world.entities[index].version = h.version;
- world.entities[index].flags |= F_ENABLED;
- while (Y(world.entities[world.next_entity].flags, F_ENABLED)) {
- ++world.next_entity;
- CHECK(h, world.next_entity < MAX_NUM_ENTITIES);
- }
- if (world.num_entities <= index)
- world.num_entities = index + 1;
- return h;
-}
-
-Handle e_create(Entity data) {
- return e_create_in(world.next_entity, data);
-}
-
-void e_destroy(Handle id) {
- CHECK(, world.entities[id.index].version == id.version);
- CHECK(, Y(world.entities[id.index].flags, F_ENABLED));
- world.entities[id.index].flags = 0;
- if (world.next_entity > id.index)
- world.next_entity = id.index;
-}
-
-void e_render(i32 index) {
- Entity *e = world.entities + index;
- CHECK(, Y(e->flags, F_ENABLED));
- if (Y(e->flags, F_HIDDEN))
- return;
-
- Screen_Area a = world_to_screen(e->position, e->size);
-
- i32 nx = (i32) floor(a.x + .5);
- i32 ny = (i32) floor(a.y + .5);
- i32 ns = (i32) floor(a.size + .5);
-
- if (!a.visible)
- return;
-
- for (i64 j = -ns; j <= ns; ++j)
- if (ny + j >= 0 && ny + j < platform.frame_height)
- for (i64 i = -ns; i <= ns; ++i)
- if (nx + i >= 0 && nx + i < platform.frame_width)
- platform.pixels[(ny + j) * platform.frame_width + (nx + i)] = 0x00ff00;
-}
-
i64 time_milliseconds() {
struct timespec t;
timespec_get(&t, TIME_UTC);
@@ -521,19 +430,6 @@ i32 main(i32 argc, c8 **argv) {
world.eye_position.y += platform.cursor_dy * k;
}
- if (platform.key_pressed[BUTTON_LEFT]) {
- e_create((Entity) {
- .size = .1,
- .position = screen_to_world(platform.cursor_x, platform.cursor_y),
- });
- }
-
- if (platform.key_down[BUTTON_LEFT])
- world.entities[world.num_entities - 1].position.z += .01 * time_elapsed;
-
- for (i32 k = 0; k < world.num_entities; ++k)
- world.entities[k].time += time_elapsed;
-
world.time += time_elapsed;
}
@@ -541,9 +437,6 @@ i32 main(i32 argc, c8 **argv) {
for (i32 i = 0; i < platform.frame_width; ++i)
platform.pixels[j * platform.frame_width + i] = background;
- for (i32 k = 0; k < world.num_entities; ++k)
- e_render(k);
-
p_render_frame();
}