diff options
-rw-r--r-- | demos/checkerboard/checkerboard.c | 48 | ||||
-rw-r--r-- | demos/isomap/isomap.c | 35 | ||||
-rw-r--r-- | include/isogfx/backend.h | 13 | ||||
-rw-r--r-- | src/backend.c | 10 |
4 files changed, 52 insertions, 54 deletions
diff --git a/demos/checkerboard/checkerboard.c b/demos/checkerboard/checkerboard.c index dbc817c..9d1791e 100644 --- a/demos/checkerboard/checkerboard.c +++ b/demos/checkerboard/checkerboard.c | |||
@@ -76,11 +76,10 @@ static bool init(GfxAppState* state, int argc, const char** argv) { | |||
76 | isogfx_resize(iso, SCREEN_WIDTH, SCREEN_HEIGHT); | 76 | isogfx_resize(iso, SCREEN_WIDTH, SCREEN_HEIGHT); |
77 | 77 | ||
78 | if (!isogfx_make_world( | 78 | if (!isogfx_make_world( |
79 | iso, &(WorldDesc){ | 79 | iso, &(WorldDesc){.tile_width = TILE_WIDTH, |
80 | .tile_width = TILE_WIDTH, | 80 | .tile_height = TILE_HEIGHT, |
81 | .tile_height = TILE_HEIGHT, | 81 | .world_width = WORLD_WIDTH, |
82 | .world_width = WORLD_WIDTH, | 82 | .world_height = WORLD_HEIGHT})) { |
83 | .world_height = WORLD_HEIGHT})) { | ||
84 | return false; | 83 | return false; |
85 | } | 84 | } |
86 | 85 | ||
@@ -89,7 +88,7 @@ static bool init(GfxAppState* state, int argc, const char** argv) { | |||
89 | state->red = isogfx_make_tile(iso, &tile_set[Red]); | 88 | state->red = isogfx_make_tile(iso, &tile_set[Red]); |
90 | make_checkerboard(iso, black, white); | 89 | make_checkerboard(iso, black, white); |
91 | 90 | ||
92 | if (!(state->backend = IsoBackendInit(iso))) { | 91 | if (!(state->backend = iso_backend_init(iso))) { |
93 | return false; | 92 | return false; |
94 | } | 93 | } |
95 | 94 | ||
@@ -99,7 +98,7 @@ static bool init(GfxAppState* state, int argc, const char** argv) { | |||
99 | static void shutdown(GfxAppState* state) { | 98 | static void shutdown(GfxAppState* state) { |
100 | assert(state); | 99 | assert(state); |
101 | 100 | ||
102 | IsoBackendShutdown(&state->backend); | 101 | iso_backend_shutdown(&state->backend); |
103 | isogfx_del(&state->iso); | 102 | isogfx_del(&state->iso); |
104 | } | 103 | } |
105 | 104 | ||
@@ -116,7 +115,7 @@ static void update(GfxAppState* state, double t, double dt) { | |||
116 | gfx_app_get_mouse_position(&mouse_x, &mouse_y); | 115 | gfx_app_get_mouse_position(&mouse_x, &mouse_y); |
117 | 116 | ||
118 | // Map from window coordinates to virtual screen coordinates. | 117 | // Map from window coordinates to virtual screen coordinates. |
119 | IsoBackendGetMousePosition( | 118 | iso_backend_get_mouse_position( |
120 | state->backend, mouse_x, mouse_y, &mouse_x, &mouse_y); | 119 | state->backend, mouse_x, mouse_y, &mouse_x, &mouse_y); |
121 | 120 | ||
122 | isogfx_pick_tile(iso, mouse_x, mouse_y, &state->xpick, &state->ypick); | 121 | isogfx_pick_tile(iso, mouse_x, mouse_y, &state->xpick, &state->ypick); |
@@ -135,32 +134,31 @@ static void render(GfxAppState* state) { | |||
135 | isogfx_draw_tile(iso, state->xpick, state->ypick, state->red); | 134 | isogfx_draw_tile(iso, state->xpick, state->ypick, state->red); |
136 | } | 135 | } |
137 | 136 | ||
138 | IsoBackendRender(state->backend, iso); | 137 | iso_backend_render(state->backend, iso); |
139 | } | 138 | } |
140 | 139 | ||
141 | static void resize(GfxAppState* state, int width, int height) { | 140 | static void resize(GfxAppState* state, int width, int height) { |
142 | assert(state); | 141 | assert(state); |
143 | 142 | ||
144 | IsoBackendResizeWindow(state->backend, state->iso, width, height); | 143 | iso_backend_resize_window(state->backend, state->iso, width, height); |
145 | } | 144 | } |
146 | 145 | ||
147 | int main(int argc, const char** argv) { | 146 | int main(int argc, const char** argv) { |
148 | GfxAppState state = {0}; | 147 | GfxAppState state = {0}; |
149 | gfx_app_run( | 148 | gfx_app_run( |
150 | &(GfxAppDesc){ | 149 | &(GfxAppDesc){.argc = argc, |
151 | .argc = argc, | 150 | .argv = argv, |
152 | .argv = argv, | 151 | .width = WINDOW_WIDTH, |
153 | .width = WINDOW_WIDTH, | 152 | .height = WINDOW_HEIGHT, |
154 | .height = WINDOW_HEIGHT, | 153 | .max_fps = MAX_FPS, |
155 | .max_fps = MAX_FPS, | 154 | .update_delta_time = |
156 | .update_delta_time = MAX_FPS > 0 ? 1.0 / (double)MAX_FPS : 0.0, | 155 | MAX_FPS > 0 ? 1.0 / (double)MAX_FPS : 0.0, |
157 | .title = "Isometric Renderer", | 156 | .title = "Isometric Renderer", |
158 | .app_state = &state}, | 157 | .app_state = &state}, |
159 | &(GfxAppCallbacks){ | 158 | &(GfxAppCallbacks){.init = init, |
160 | .init = init, | 159 | .update = update, |
161 | .update = update, | 160 | .render = render, |
162 | .render = render, | 161 | .resize = resize, |
163 | .resize = resize, | 162 | .shutdown = shutdown}); |
164 | .shutdown = shutdown}); | ||
165 | return 0; | 163 | return 0; |
166 | } | 164 | } |
diff --git a/demos/isomap/isomap.c b/demos/isomap/isomap.c index a233659..5adf6f1 100644 --- a/demos/isomap/isomap.c +++ b/demos/isomap/isomap.c | |||
@@ -49,7 +49,7 @@ static bool init(GfxAppState* state, int argc, const char** argv) { | |||
49 | state->stag = isogfx_make_sprite(iso, state->stag_sheet); | 49 | state->stag = isogfx_make_sprite(iso, state->stag_sheet); |
50 | isogfx_set_sprite_position(iso, state->stag, 5, 4); | 50 | isogfx_set_sprite_position(iso, state->stag, 5, 4); |
51 | 51 | ||
52 | if (!(state->backend = IsoBackendInit(iso))) { | 52 | if (!(state->backend = iso_backend_init(iso))) { |
53 | return false; | 53 | return false; |
54 | } | 54 | } |
55 | 55 | ||
@@ -74,32 +74,31 @@ static void render(GfxAppState* state) { | |||
74 | 74 | ||
75 | IsoGfx* iso = state->iso; | 75 | IsoGfx* iso = state->iso; |
76 | isogfx_render(iso); | 76 | isogfx_render(iso); |
77 | IsoBackendRender(state->backend, iso); | 77 | iso_backend_render(state->backend, iso); |
78 | } | 78 | } |
79 | 79 | ||
80 | static void resize(GfxAppState* state, int width, int height) { | 80 | static void resize(GfxAppState* state, int width, int height) { |
81 | assert(state); | 81 | assert(state); |
82 | 82 | ||
83 | IsoBackendResizeWindow(state->backend, state->iso, width, height); | 83 | iso_backend_resize_window(state->backend, state->iso, width, height); |
84 | } | 84 | } |
85 | 85 | ||
86 | int main(int argc, const char** argv) { | 86 | int main(int argc, const char** argv) { |
87 | GfxAppState state = {0}; | 87 | GfxAppState state = {0}; |
88 | gfx_app_run( | 88 | gfx_app_run( |
89 | &(GfxAppDesc){ | 89 | &(GfxAppDesc){.argc = argc, |
90 | .argc = argc, | 90 | .argv = argv, |
91 | .argv = argv, | 91 | .width = WINDOW_WIDTH, |
92 | .width = WINDOW_WIDTH, | 92 | .height = WINDOW_HEIGHT, |
93 | .height = WINDOW_HEIGHT, | 93 | .max_fps = MAX_FPS, |
94 | .max_fps = MAX_FPS, | 94 | .update_delta_time = |
95 | .update_delta_time = MAX_FPS > 0 ? 1.0 / (double)MAX_FPS : 0.0, | 95 | MAX_FPS > 0 ? 1.0 / (double)MAX_FPS : 0.0, |
96 | .title = "Isometric Renderer", | 96 | .title = "Isometric Renderer", |
97 | .app_state = &state}, | 97 | .app_state = &state}, |
98 | &(GfxAppCallbacks){ | 98 | &(GfxAppCallbacks){.init = init, |
99 | .init = init, | 99 | .update = update, |
100 | .update = update, | 100 | .render = render, |
101 | .render = render, | 101 | .resize = resize, |
102 | .resize = resize, | 102 | .shutdown = shutdown}); |
103 | .shutdown = shutdown}); | ||
104 | return 0; | 103 | return 0; |
105 | } | 104 | } |
diff --git a/include/isogfx/backend.h b/include/isogfx/backend.h index 172991d..76ee13d 100644 --- a/include/isogfx/backend.h +++ b/include/isogfx/backend.h | |||
@@ -8,21 +8,22 @@ typedef struct IsoGfx IsoGfx; | |||
8 | typedef struct IsoBackend IsoBackend; | 8 | typedef struct IsoBackend IsoBackend; |
9 | 9 | ||
10 | /// Initialize the backend. | 10 | /// Initialize the backend. |
11 | IsoBackend* IsoBackendInit(const IsoGfx*); | 11 | IsoBackend* iso_backend_init(const IsoGfx*); |
12 | 12 | ||
13 | /// Shut down the backend. | 13 | /// Shut down the backend. |
14 | void IsoBackendShutdown(IsoBackend**); | 14 | void iso_backend_shutdown(IsoBackend**); |
15 | 15 | ||
16 | /// Notify the backend of a window resize event. | 16 | /// Notify the backend of a window resize event. |
17 | /// This allows the backend to determine how to position and scale the iso | 17 | /// This allows the backend to determine how to position and scale the iso |
18 | /// screen buffer on the graphics window. | 18 | /// screen buffer on the graphics window. |
19 | void IsoBackendResizeWindow(IsoBackend*, const IsoGfx*, int width, int height); | 19 | void iso_backend_resize_window( |
20 | IsoBackend*, const IsoGfx*, int width, int height); | ||
20 | 21 | ||
21 | /// Render the iso screen to the graphics window. | 22 | /// Render the iso screen to the graphics window. |
22 | void IsoBackendRender(const IsoBackend*, const IsoGfx*); | 23 | void iso_backend_render(const IsoBackend*, const IsoGfx*); |
23 | 24 | ||
24 | /// Map window coordinates to iso space coordinates. | 25 | /// Map window coordinates to iso space coordinates. |
25 | /// This takes into account any possible resizing done by the backend in | 26 | /// This takes into account any possible resizing done by the backend in |
26 | /// response to calls to IsoBackendResizeWindow(). | 27 | /// response to calls to iso_backend_resize_window(). |
27 | bool IsoBackendGetMousePosition( | 28 | bool iso_backend_get_mouse_position( |
28 | const IsoBackend*, double window_x, double window_y, double* x, double* y); | 29 | const IsoBackend*, double window_x, double window_y, double* x, double* y); |
diff --git a/src/backend.c b/src/backend.c index f610905..567146f 100644 --- a/src/backend.c +++ b/src/backend.c | |||
@@ -31,7 +31,7 @@ typedef struct IsoBackend { | |||
31 | // dimensions. | 31 | // dimensions. |
32 | } IsoBackend; | 32 | } IsoBackend; |
33 | 33 | ||
34 | IsoBackend* IsoBackendInit(const IsoGfx* iso) { | 34 | IsoBackend* iso_backend_init(const IsoGfx* iso) { |
35 | assert(iso); | 35 | assert(iso); |
36 | 36 | ||
37 | IsoBackend* backend = calloc(1, sizeof(IsoBackend)); | 37 | IsoBackend* backend = calloc(1, sizeof(IsoBackend)); |
@@ -95,7 +95,7 @@ cleanup: | |||
95 | return 0; | 95 | return 0; |
96 | } | 96 | } |
97 | 97 | ||
98 | void IsoBackendShutdown(IsoBackend** ppApp) { | 98 | void iso_backend_shutdown(IsoBackend** ppApp) { |
99 | assert(ppApp); | 99 | assert(ppApp); |
100 | 100 | ||
101 | IsoBackend* app = *ppApp; | 101 | IsoBackend* app = *ppApp; |
@@ -106,7 +106,7 @@ void IsoBackendShutdown(IsoBackend** ppApp) { | |||
106 | gfx_destroy(&app->gfx); | 106 | gfx_destroy(&app->gfx); |
107 | } | 107 | } |
108 | 108 | ||
109 | void IsoBackendResizeWindow( | 109 | void iso_backend_resize_window( |
110 | IsoBackend* app, const IsoGfx* iso, int width, int height) { | 110 | IsoBackend* app, const IsoGfx* iso, int width, int height) { |
111 | assert(app); | 111 | assert(app); |
112 | assert(iso); | 112 | assert(iso); |
@@ -135,7 +135,7 @@ void IsoBackendResizeWindow( | |||
135 | } | 135 | } |
136 | } | 136 | } |
137 | 137 | ||
138 | void IsoBackendRender(const IsoBackend* app, const IsoGfx* iso) { | 138 | void iso_backend_render(const IsoBackend* app, const IsoGfx* iso) { |
139 | assert(app); | 139 | assert(app); |
140 | assert(iso); | 140 | assert(iso); |
141 | 141 | ||
@@ -162,7 +162,7 @@ void IsoBackendRender(const IsoBackend* app, const IsoGfx* iso) { | |||
162 | gfx_end_frame(gfxcore); | 162 | gfx_end_frame(gfxcore); |
163 | } | 163 | } |
164 | 164 | ||
165 | bool IsoBackendGetMousePosition( | 165 | bool iso_backend_get_mouse_position( |
166 | const IsoBackend* app, double window_x, double window_y, double* x, | 166 | const IsoBackend* app, double window_x, double window_y, double* x, |
167 | double* y) { | 167 | double* y) { |
168 | assert(app); | 168 | assert(app); |