summaryrefslogtreecommitdiff
path: root/gfx-iso/demos/isomap/isomap.c
diff options
context:
space:
mode:
Diffstat (limited to 'gfx-iso/demos/isomap/isomap.c')
-rw-r--r--gfx-iso/demos/isomap/isomap.c88
1 files changed, 58 insertions, 30 deletions
diff --git a/gfx-iso/demos/isomap/isomap.c b/gfx-iso/demos/isomap/isomap.c
index 5ab926c..a233659 100644
--- a/gfx-iso/demos/isomap/isomap.c
+++ b/gfx-iso/demos/isomap/isomap.c
@@ -1,23 +1,41 @@
1#include <isogfx/app.h> 1#include <isogfx/backend.h>
2#include <isogfx/isogfx.h> 2#include <isogfx/isogfx.h>
3 3
4#include <gfx/app.h>
5
4#include <assert.h> 6#include <assert.h>
5#include <stdbool.h> 7#include <stdbool.h>
6 8
7typedef struct IsoGfxAppState { 9static const int WINDOW_WIDTH = 1408;
10static const int WINDOW_HEIGHT = 960;
11static const int MAX_FPS = 60;
12
13// Virtual screen dimensions.
14static const int SCREEN_WIDTH = 704;
15static const int SCREEN_HEIGHT = 480;
16
17typedef struct GfxAppState {
18 IsoBackend* backend;
19 IsoGfx* iso;
8 int xpick; 20 int xpick;
9 int ypick; 21 int ypick;
10 SpriteSheet stag_sheet; 22 SpriteSheet stag_sheet;
11 Sprite stag; 23 Sprite stag;
12} IsoGfxAppState; 24} GfxAppState;
13 25
14static bool init( 26static bool init(GfxAppState* state, int argc, const char** argv) {
15 IsoGfxAppState* state, IsoGfx* iso, int argc, const char** argv) {
16 assert(state); 27 assert(state);
17 assert(iso);
18 (void)argc; 28 (void)argc;
19 (void)argv; 29 (void)argv;
20 30
31 if (!(state->iso = isogfx_new(&(IsoGfxDesc){
32 .screen_width = SCREEN_WIDTH, .screen_height = SCREEN_HEIGHT}))) {
33 return false;
34 }
35 IsoGfx* iso = state->iso;
36
37 isogfx_resize(iso, SCREEN_WIDTH, SCREEN_HEIGHT);
38
21 if (!isogfx_load_world(iso, "/home/jeanne/assets/tilemaps/demo1.tm")) { 39 if (!isogfx_load_world(iso, "/home/jeanne/assets/tilemaps/demo1.tm")) {
22 return false; 40 return false;
23 } 41 }
@@ -31,47 +49,57 @@ static bool init(
31 state->stag = isogfx_make_sprite(iso, state->stag_sheet); 49 state->stag = isogfx_make_sprite(iso, state->stag_sheet);
32 isogfx_set_sprite_position(iso, state->stag, 5, 4); 50 isogfx_set_sprite_position(iso, state->stag, 5, 4);
33 51
52 if (!(state->backend = IsoBackendInit(iso))) {
53 return false;
54 }
55
34 return true; 56 return true;
35} 57}
36 58
37static void shutdown(IsoGfxAppState* state, IsoGfx* iso) { 59static void shutdown(GfxAppState* state) {
38 assert(state); 60 assert(state);
39 assert(iso); 61 //
40} 62}
41 63
42static void update(IsoGfxAppState* state, IsoGfx* iso, double t, double dt) { 64static void update(GfxAppState* state, double t, double dt) {
43 assert(state); 65 assert(state);
44 assert(iso);
45
46 (void)t;
47 (void)dt; 66 (void)dt;
48 67
49 double mouse_x, mouse_y; 68 IsoGfx* iso = state->iso;
50 gfx_app_get_mouse_position(&mouse_x, &mouse_y); 69 isogfx_update(iso, t);
70}
51 71
52 isogfx_pick_tile(iso, mouse_x, mouse_y, &state->xpick, &state->ypick); 72static void render(GfxAppState* state) {
73 assert(state);
53 74
54 // printf("Picked tile: (%d, %d)\n", state->xpick, state->ypick); 75 IsoGfx* iso = state->iso;
76 isogfx_render(iso);
77 IsoBackendRender(state->backend, iso);
55} 78}
56 79
57static void render(IsoGfxAppState* state, IsoGfx* iso) { 80static void resize(GfxAppState* state, int width, int height) {
58 assert(state); 81 assert(state);
59 assert(iso);
60 82
61 isogfx_render(iso); 83 IsoBackendResizeWindow(state->backend, state->iso, width, height);
62} 84}
63 85
64int main(int argc, const char** argv) { 86int main(int argc, const char** argv) {
65 IsoGfxAppState state = {0}; 87 GfxAppState state = {0};
66 iso_run( 88 gfx_app_run(
67 argc, argv, 89 &(GfxAppDesc){
68 &(IsoGfxApp){ 90 .argc = argc,
69 .pixel_scale = 2, 91 .argv = argv,
70 .state = &state, 92 .width = WINDOW_WIDTH,
71 .init = init, 93 .height = WINDOW_HEIGHT,
72 .shutdown = shutdown, 94 .max_fps = MAX_FPS,
73 .update = update, 95 .update_delta_time = MAX_FPS > 0 ? 1.0 / (double)MAX_FPS : 0.0,
74 .render = render, 96 .title = "Isometric Renderer",
75 }); 97 .app_state = &state},
98 &(GfxAppCallbacks){
99 .init = init,
100 .update = update,
101 .render = render,
102 .resize = resize,
103 .shutdown = shutdown});
76 return 0; 104 return 0;
77} 105}