diff options
Diffstat (limited to 'demos')
-rw-r--r-- | demos/checkerboard/CMakeLists.txt | 2 | ||||
-rw-r--r-- | demos/checkerboard/checkerboard.c | 97 | ||||
-rw-r--r-- | demos/isomap/CMakeLists.txt | 2 | ||||
-rw-r--r-- | demos/isomap/isomap.c | 87 |
4 files changed, 100 insertions, 88 deletions
diff --git a/demos/checkerboard/CMakeLists.txt b/demos/checkerboard/CMakeLists.txt index d1691c6..b4e3a2a 100644 --- a/demos/checkerboard/CMakeLists.txt +++ b/demos/checkerboard/CMakeLists.txt | |||
@@ -1,4 +1,4 @@ | |||
1 | cmake_minimum_required(VERSION 3.0) | 1 | cmake_minimum_required(VERSION 3.5) |
2 | 2 | ||
3 | project(checkerboard) | 3 | project(checkerboard) |
4 | 4 | ||
diff --git a/demos/checkerboard/checkerboard.c b/demos/checkerboard/checkerboard.c index b408fc2..243f7a8 100644 --- a/demos/checkerboard/checkerboard.c +++ b/demos/checkerboard/checkerboard.c | |||
@@ -1,5 +1,5 @@ | |||
1 | #include <isogfx/backend.h> | 1 | #include <isogfx/backend.h> |
2 | #include <isogfx/isogfx.h> | 2 | #include <isogfx/gfx2d.h> |
3 | 3 | ||
4 | #include <gfx/app.h> | 4 | #include <gfx/app.h> |
5 | 5 | ||
@@ -47,105 +47,110 @@ typedef enum Colour { | |||
47 | } Colour; | 47 | } Colour; |
48 | 48 | ||
49 | typedef struct GfxAppState { | 49 | typedef struct GfxAppState { |
50 | IsoBackend* backend; | 50 | Gfx2dBackend* backend; |
51 | IsoGfx* iso; | 51 | Gfx2d* gfx; |
52 | Tile red; | 52 | Tile red; |
53 | int xpick; | 53 | int xpick; |
54 | int ypick; | 54 | int ypick; |
55 | } GfxAppState; | 55 | } GfxAppState; |
56 | 56 | ||
57 | static void make_checkerboard(IsoGfx* iso, Tile black, Tile white) { | 57 | static void make_checkerboard(Gfx2d* iso, Tile black, Tile white) { |
58 | assert(iso); | 58 | assert(iso); |
59 | for (int y = 0; y < isogfx_world_height(iso); ++y) { | 59 | for (int y = 0; y < gfx2d_world_height(iso); ++y) { |
60 | for (int x = 0; x < isogfx_world_width(iso); ++x) { | 60 | for (int x = 0; x < gfx2d_world_width(iso); ++x) { |
61 | const int odd_col = x & 1; | 61 | const int odd_col = x & 1; |
62 | const int odd_row = y & 1; | 62 | const int odd_row = y & 1; |
63 | const Tile value = (odd_row ^ odd_col) == 0 ? black : white; | 63 | const Tile value = (odd_row ^ odd_col) == 0 ? black : white; |
64 | isogfx_set_tile(iso, x, y, value); | 64 | gfx2d_set_tile(iso, x, y, value); |
65 | } | 65 | } |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | static bool init(GfxAppState* state, int argc, const char** argv) { | 69 | static bool init(GfxApp* app, GfxAppState* state, int argc, const char** argv) { |
70 | assert(app); | ||
70 | assert(state); | 71 | assert(state); |
71 | |||
72 | (void)argc; | 72 | (void)argc; |
73 | (void)argv; | 73 | (void)argv; |
74 | 74 | ||
75 | if (!((state->iso = | 75 | if (!((state->gfx = |
76 | isogfx_new(&(IsoGfxDesc){.memory = MEMORY, | 76 | gfx2d_new(&(Gfx2dDesc){.memory = MEMORY, |
77 | .memory_size = MEMORY_SIZE, | 77 | .memory_size = MEMORY_SIZE, |
78 | .screen_width = SCREEN_WIDTH, | 78 | .screen_width = SCREEN_WIDTH, |
79 | .screen_height = SCREEN_HEIGHT})))) { | 79 | .screen_height = SCREEN_HEIGHT})))) { |
80 | return false; | 80 | return false; |
81 | } | 81 | } |
82 | IsoGfx* iso = state->iso; | 82 | Gfx2d* iso = state->gfx; |
83 | 83 | ||
84 | isogfx_make_world( | 84 | gfx2d_make_map( |
85 | iso, &(WorldDesc){.tile_width = TILE_WIDTH, | 85 | iso, &(MapDesc){.tile_width = TILE_WIDTH, |
86 | .tile_height = TILE_HEIGHT, | 86 | .tile_height = TILE_HEIGHT, |
87 | .world_width = WORLD_WIDTH, | 87 | .world_width = WORLD_WIDTH, |
88 | .world_height = WORLD_HEIGHT, | 88 | .world_height = WORLD_HEIGHT, |
89 | .num_tiles = NUM_TILES}); | 89 | .num_tiles = NUM_TILES, |
90 | 90 | .orientation = MapIsometric}); | |
91 | const Tile black = isogfx_make_tile(iso, &tile_set[Black]); | 91 | |
92 | const Tile white = isogfx_make_tile(iso, &tile_set[White]); | 92 | const Tile black = gfx2d_make_tile(iso, &tile_set[Black]); |
93 | state->red = isogfx_make_tile(iso, &tile_set[Red]); | 93 | const Tile white = gfx2d_make_tile(iso, &tile_set[White]); |
94 | state->red = gfx2d_make_tile(iso, &tile_set[Red]); | ||
94 | make_checkerboard(iso, black, white); | 95 | make_checkerboard(iso, black, white); |
95 | 96 | ||
96 | if (!((state->backend = iso_backend_init(iso)))) { | 97 | if (!((state->backend = gfx2d_backend_init(iso)))) { |
97 | return false; | 98 | return false; |
98 | } | 99 | } |
99 | 100 | ||
100 | return true; | 101 | return true; |
101 | } | 102 | } |
102 | 103 | ||
103 | static void shutdown(GfxAppState* state) { | 104 | static void shutdown(GfxApp* app, GfxAppState* state) { |
105 | assert(app); | ||
104 | assert(state); | 106 | assert(state); |
105 | 107 | ||
106 | iso_backend_shutdown(&state->backend); | 108 | gfx2d_backend_shutdown(&state->backend); |
107 | isogfx_del(&state->iso); | 109 | gfx2d_del(&state->gfx); |
108 | } | 110 | } |
109 | 111 | ||
110 | static void update(GfxAppState* state, double t, double dt) { | 112 | static void update(GfxApp* app, GfxAppState* state, double t, double dt) { |
113 | assert(app); | ||
111 | assert(state); | 114 | assert(state); |
112 | (void)dt; | 115 | (void)dt; |
113 | 116 | ||
114 | IsoGfx* iso = state->iso; | 117 | Gfx2d* iso = state->gfx; |
115 | 118 | ||
116 | isogfx_update(iso, t); | 119 | gfx2d_update(iso, t); |
117 | 120 | ||
118 | // Get mouse position in window coordinates. | 121 | // Get mouse position in window coordinates. |
119 | double mouse_x, mouse_y; | 122 | double mouse_x, mouse_y; |
120 | gfx_app_get_mouse_position(&mouse_x, &mouse_y); | 123 | gfx_app_get_mouse_position(app, &mouse_x, &mouse_y); |
121 | 124 | ||
122 | // Map from window coordinates to virtual screen coordinates. | 125 | // Map from window coordinates to virtual screen coordinates. |
123 | iso_backend_get_mouse_position( | 126 | gfx2d_backend_get_mouse_position( |
124 | state->backend, mouse_x, mouse_y, &mouse_x, &mouse_y); | 127 | state->backend, mouse_x, mouse_y, &mouse_x, &mouse_y); |
125 | 128 | ||
126 | isogfx_pick_tile(iso, mouse_x, mouse_y, &state->xpick, &state->ypick); | 129 | gfx2d_pick_tile(iso, mouse_x, mouse_y, &state->xpick, &state->ypick); |
127 | 130 | ||
128 | printf("Picked tile: (%d, %d)\n", state->xpick, state->ypick); | 131 | printf("Picked tile: (%d, %d)\n", state->xpick, state->ypick); |
129 | } | 132 | } |
130 | 133 | ||
131 | static void render(GfxAppState* state) { | 134 | static void render(const GfxApp* app, GfxAppState* state) { |
135 | assert(app); | ||
132 | assert(state); | 136 | assert(state); |
133 | 137 | ||
134 | IsoGfx* iso = state->iso; | 138 | Gfx2d* iso = state->gfx; |
135 | 139 | ||
136 | isogfx_render(iso); | 140 | gfx2d_render(iso); |
137 | 141 | ||
138 | if ((state->xpick != -1) && (state->ypick != -1)) { | 142 | if ((state->xpick != -1) && (state->ypick != -1)) { |
139 | isogfx_draw_tile(iso, state->xpick, state->ypick, state->red); | 143 | gfx2d_draw_tile(iso, state->xpick, state->ypick, state->red); |
140 | } | 144 | } |
141 | 145 | ||
142 | iso_backend_render(state->backend, iso); | 146 | gfx2d_backend_render(state->backend, iso); |
143 | } | 147 | } |
144 | 148 | ||
145 | static void resize(GfxAppState* state, int width, int height) { | 149 | static void resize(GfxApp* app, GfxAppState* state, int width, int height) { |
150 | assert(app); | ||
146 | assert(state); | 151 | assert(state); |
147 | 152 | ||
148 | iso_backend_resize_window(state->backend, state->iso, width, height); | 153 | gfx2d_backend_resize_window(state->backend, state->gfx, width, height); |
149 | } | 154 | } |
150 | 155 | ||
151 | int main(int argc, const char** argv) { | 156 | int main(int argc, const char** argv) { |
diff --git a/demos/isomap/CMakeLists.txt b/demos/isomap/CMakeLists.txt index 2dbfd32..9467625 100644 --- a/demos/isomap/CMakeLists.txt +++ b/demos/isomap/CMakeLists.txt | |||
@@ -1,4 +1,4 @@ | |||
1 | cmake_minimum_required(VERSION 3.0) | 1 | cmake_minimum_required(VERSION 3.5) |
2 | 2 | ||
3 | project(isomap) | 3 | project(isomap) |
4 | 4 | ||
diff --git a/demos/isomap/isomap.c b/demos/isomap/isomap.c index a940535..471ef57 100644 --- a/demos/isomap/isomap.c +++ b/demos/isomap/isomap.c | |||
@@ -1,5 +1,5 @@ | |||
1 | #include <isogfx/backend.h> | 1 | #include <isogfx/backend.h> |
2 | #include <isogfx/isogfx.h> | 2 | #include <isogfx/gfx2d.h> |
3 | 3 | ||
4 | #include <gfx/app.h> | 4 | #include <gfx/app.h> |
5 | #include <math/vec2.h> | 5 | #include <math/vec2.h> |
@@ -16,73 +16,77 @@ static const int MAX_FPS = 60; | |||
16 | static const int SCREEN_WIDTH = 704; | 16 | static const int SCREEN_WIDTH = 704; |
17 | static const int SCREEN_HEIGHT = 480; | 17 | static const int SCREEN_HEIGHT = 480; |
18 | 18 | ||
19 | static const R CAMERA_SPEED = 400; | 19 | static const R CAMERA_SPEED = 800; |
20 | 20 | ||
21 | #define MEMORY_SIZE (2 * 1024 * 1024) | 21 | #define MEMORY_SIZE (8 * 1024 * 1024) |
22 | uint8_t MEMORY[MEMORY_SIZE]; | 22 | uint8_t MEMORY[MEMORY_SIZE]; |
23 | 23 | ||
24 | typedef struct GfxAppState { | 24 | typedef struct GfxAppState { |
25 | IsoBackend* backend; | 25 | Gfx2dBackend* backend; |
26 | IsoGfx* iso; | 26 | Gfx2d* gfx; |
27 | int xpick; | 27 | int xpick; |
28 | int ypick; | 28 | int ypick; |
29 | vec2 camera; | 29 | vec2 camera; |
30 | SpriteSheet stag_sheet; | 30 | SpriteSheet stag_sheet; |
31 | Sprite stag; | 31 | Sprite stag; |
32 | } GfxAppState; | 32 | } GfxAppState; |
33 | 33 | ||
34 | static bool init(GfxAppState* state, int argc, const char** argv) { | 34 | static bool init(GfxApp* app, GfxAppState* state, int argc, const char** argv) { |
35 | assert(app); | ||
35 | assert(state); | 36 | assert(state); |
36 | (void)argc; | 37 | (void)argc; |
37 | (void)argv; | 38 | (void)argv; |
38 | 39 | ||
39 | if (!((state->iso = | 40 | if (!((state->gfx = |
40 | isogfx_new(&(IsoGfxDesc){.memory = MEMORY, | 41 | gfx2d_new(&(Gfx2dDesc){.memory = MEMORY, |
41 | .memory_size = MEMORY_SIZE, | 42 | .memory_size = MEMORY_SIZE, |
42 | .screen_width = SCREEN_WIDTH, | 43 | .screen_width = SCREEN_WIDTH, |
43 | .screen_height = SCREEN_HEIGHT})))) { | 44 | .screen_height = SCREEN_HEIGHT})))) { |
44 | return false; | 45 | return false; |
45 | } | 46 | } |
46 | IsoGfx* iso = state->iso; | 47 | Gfx2d* iso = state->gfx; |
47 | 48 | ||
48 | if (!isogfx_load_world(iso, "/home/jeanne/Nextcloud/assets/maps/demo-1.tm")) { | 49 | if (!gfx2d_load_map( |
50 | iso, "/home/jeanne/Nextcloud/assets/tilemaps/scrabling1.tm")) { | ||
49 | return false; | 51 | return false; |
50 | } | 52 | } |
51 | 53 | ||
52 | if (!((state->stag_sheet = isogfx_load_sprite_sheet( | 54 | if (!((state->stag_sheet = gfx2d_load_sprite_sheet( |
53 | iso, | 55 | iso, |
54 | "/home/jeanne/Nextcloud/assets/tilesets/scrabling/critters/stag/" | 56 | "/home/jeanne/Nextcloud/assets/tilesets/scrabling/critters/stag/" |
55 | "stag.ss")))) { | 57 | "stag.ss")))) { |
56 | return false; | 58 | return false; |
57 | } | 59 | } |
58 | 60 | ||
59 | state->stag = isogfx_make_sprite(iso, state->stag_sheet); | 61 | state->stag = gfx2d_make_sprite(iso, state->stag_sheet); |
60 | isogfx_set_sprite_position(iso, state->stag, 5, 4); | 62 | gfx2d_set_sprite_position(iso, state->stag, 0, 0); |
61 | 63 | ||
62 | if (!((state->backend = iso_backend_init(iso)))) { | 64 | if (!((state->backend = gfx2d_backend_init(iso)))) { |
63 | return false; | 65 | return false; |
64 | } | 66 | } |
65 | 67 | ||
66 | return true; | 68 | return true; |
67 | } | 69 | } |
68 | 70 | ||
69 | static void shutdown(GfxAppState* state) { | 71 | static void shutdown(GfxApp* app, GfxAppState* state) { |
72 | assert(app); | ||
70 | assert(state); | 73 | assert(state); |
71 | // | ||
72 | } | 74 | } |
73 | 75 | ||
74 | static vec2 get_camera_movement(R dt) { | 76 | static vec2 get_camera_movement(GfxApp* app, R dt) { |
77 | assert(app); | ||
78 | |||
75 | vec2 offset = {0}; | 79 | vec2 offset = {0}; |
76 | if (gfx_app_is_key_pressed(KeyA)) { | 80 | if (gfx_app_is_key_pressed(app, KeyA)) { |
77 | offset.x -= 1; | 81 | offset.x -= 1; |
78 | } | 82 | } |
79 | if (gfx_app_is_key_pressed(KeyD)) { | 83 | if (gfx_app_is_key_pressed(app, KeyD)) { |
80 | offset.x += 1; | 84 | offset.x += 1; |
81 | } | 85 | } |
82 | if (gfx_app_is_key_pressed(KeyW)) { | 86 | if (gfx_app_is_key_pressed(app, KeyW)) { |
83 | offset.y -= 1; | 87 | offset.y -= 1; |
84 | } | 88 | } |
85 | if (gfx_app_is_key_pressed(KeyS)) { | 89 | if (gfx_app_is_key_pressed(app, KeyS)) { |
86 | offset.y += 1; | 90 | offset.y += 1; |
87 | } | 91 | } |
88 | if ((offset.x != 0) || (offset.y != 0)) { | 92 | if ((offset.x != 0) || (offset.y != 0)) { |
@@ -91,28 +95,31 @@ static vec2 get_camera_movement(R dt) { | |||
91 | return offset; | 95 | return offset; |
92 | } | 96 | } |
93 | 97 | ||
94 | static void update(GfxAppState* state, double t, double dt) { | 98 | static void update(GfxApp* app, GfxAppState* state, double t, double dt) { |
99 | assert(app); | ||
95 | assert(state); | 100 | assert(state); |
96 | 101 | ||
97 | state->camera = vec2_add(state->camera, get_camera_movement((R)dt)); | 102 | state->camera = vec2_add(state->camera, get_camera_movement(app, (R)dt)); |
98 | 103 | ||
99 | IsoGfx* iso = state->iso; | 104 | Gfx2d* iso = state->gfx; |
100 | isogfx_set_camera(iso, (int)state->camera.x, (int)state->camera.y); | 105 | gfx2d_set_camera(iso, (int)state->camera.x, (int)state->camera.y); |
101 | isogfx_update(iso, t); | 106 | gfx2d_update(iso, t); |
102 | } | 107 | } |
103 | 108 | ||
104 | static void render(GfxAppState* state) { | 109 | static void render(const GfxApp* app, GfxAppState* state) { |
110 | assert(app); | ||
105 | assert(state); | 111 | assert(state); |
106 | 112 | ||
107 | IsoGfx* iso = state->iso; | 113 | Gfx2d* iso = state->gfx; |
108 | isogfx_render(iso); | 114 | gfx2d_render(iso); |
109 | iso_backend_render(state->backend, iso); | 115 | gfx2d_backend_render(state->backend, iso); |
110 | } | 116 | } |
111 | 117 | ||
112 | static void resize(GfxAppState* state, int width, int height) { | 118 | static void resize(GfxApp* app, GfxAppState* state, int width, int height) { |
119 | assert(app); | ||
113 | assert(state); | 120 | assert(state); |
114 | 121 | ||
115 | iso_backend_resize_window(state->backend, state->iso, width, height); | 122 | gfx2d_backend_resize_window(state->backend, state->gfx, width, height); |
116 | } | 123 | } |
117 | 124 | ||
118 | int main(int argc, const char** argv) { | 125 | int main(int argc, const char** argv) { |