diff options
Diffstat (limited to '3de.c')
-rw-r--r-- | 3de.c | 91 |
1 files changed, 63 insertions, 28 deletions
@@ -1,5 +1,7 @@ #include "asset.h" #include "config.h" +#include "editor.h" +#include "gui.h" #include "map.h" #include "maths.h" #include "memory.h" @@ -9,6 +11,25 @@ #include "services.h" #include "tile.h" +static int map_data[] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + #include <stdio.h> void draw_spinny(Renderer* r, Colour c) { @@ -51,28 +72,17 @@ void draw_line(Renderer* r, int x, int y) { ren_line(r, make_red(), s, e); } -void draw_map(Renderer* r, Player* p) { - int data[512] = { - 16, 16, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, - 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, - 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - }; +void init_map(Map* m) { + int* t = (int*)&m[1], i; + m->w = 16; + m->h = 16; + for (i = 0; i < 0x100; i++) { + t[i] = map_data[i]; + } +} + +void draw_map(Renderer* r, const Player* p, const Map* m) { int pos[2]; - Map* m = (Map*)data; pos[0] = p->p[0]; pos[1] = p->p[2]; ren_map(r, m, pos, p->f, p->l); @@ -81,14 +91,19 @@ void draw_map(Renderer* r, Player* p) { int entrypoint(int argc, const char** argv, Arena* a) { App* app; Renderer r = { 0 }; + GUI g; + Editor e; Heap h; FPS f; char buf[32]; int* depth = 0; - Arena preload; + Arena preload, gui_arena, map_arena; + Map* map; + void* gui_mem; Colour blue = make_aliceblue(); Player p; Services s; + int editing = 0; (void)argc; (void)argv; init_maths(); @@ -102,6 +117,12 @@ int entrypoint(int argc, const char** argv, Arena* a) { arena_alloc(a, asset_preload_memory_size), asset_preload_memory_size ); + init_arena( + &map_arena, + arena_alloc(a, map_memory_size), + map_memory_size + ); + gui_mem = arena_alloc(a, gui_memory_size); app = new_app(&h, 640, 480, "3D Engine"); if (!app) return app->err; init_fps(&f, 20); @@ -115,20 +136,34 @@ int entrypoint(int argc, const char** argv, Arena* a) { s.r = &r; cfg_mouse(app, 0); init_player(&p); + map = arena_alloc(&map_arena, map_size(max_map_w, max_map_h)); + init_map(map); while (app->o) { fps_begin(&f); while (f.now >= f.next) { app_begin(app); - update_player(&p, &s); + init_arena(&gui_arena, gui_mem, gui_memory_size); + gui_begin(&g, app, &gui_arena); + if (app->key_states[key_f12] & key_state_just_pressed) { + editing = !editing; + cfg_mouse(app, editing); + } + if (!editing) + update_player(&p, &s); ren_begin(&r, app->fb, depth, app->w, app->h); - ren_clear(&r); + ren_clearc(&r, make_colour(0xc3c3c3, 0xff)); ren_cleard(&r, f1 * 300); /* draw_line(&r, app->mx, app->my);*/ - push_player_cam(&p); - draw_gun(&r); - draw_map(&r, &p); - pop_player_cam(); + if (editing) { + edit_map(&e, &g, map); + } else { + push_player_cam(&p); + draw_map(&r, &p, map); + draw_gun(&r); + pop_player_cam(); + } /*draw_tri(&r, app->mx, app->my);*/ + gui_end(&g, &r); sprintf(buf, "FPS: %d", app->fps); ren_texts(&r, blue, 3, 3, buf); sprintf(buf, "CAP: %d", f.fps); |