diff --git a/haloo3d b/haloo3d index cca7ec4..11f20ce 160000 --- a/haloo3d +++ b/haloo3d @@ -1 +1 @@ -Subproject commit cca7ec456909732e051a00aef5319dd452955299 +Subproject commit 11f20ce5e2b3053ce777151928500be797f3893f diff --git a/maze.c b/maze.c index 485a29b..e2b6e24 100644 --- a/maze.c +++ b/maze.c @@ -15,11 +15,13 @@ // #define FASTTRIS #define DITHERSTART -1 #define DITHEREND 8 -#define TARGETFPS 60 +#define TARGETFPS 30 #define SECPERFRAME (1.0 / TARGETFPS) -#define WIDTH 640 -#define HEIGHT 480 +#define WIDTH 320 +#define HEIGHT 200 +#define SWIDTH WIDTH * 3 +#define SHEIGHT HEIGHT * 3 #define ASPECT ((float)WIDTH / HEIGHT) #define FOV 90.0 #define NEARCLIP 0.01 @@ -30,12 +32,18 @@ // Game options #define MAZESIZE 31 +#define HSCALE 2.0 int main() { // int argc, char **argv) { haloo3d_easystore storage; haloo3d_easystore_init(&storage); + haloo3d_fb screen; + haloo3d_fb_init(&screen, SWIDTH, SHEIGHT); + haloo3d_recti texrect = {.x1 = 0, .y1 = 0, .x2 = WIDTH, .y2 = HEIGHT}; + haloo3d_recti screenrect = {.x1 = 0, .y1 = 0, .x2 = SWIDTH, .y2 = SHEIGHT}; + haloo3d_easyrender render; haloo3d_easyrender_init(&render, WIDTH, HEIGHT); haloo3d_perspective(render.perspective, FOV, ASPECT, NEARCLIP, FARCLIP); @@ -45,6 +53,8 @@ int main() { // int argc, char **argv) { #endif eprintf("Initialized renderer\n"); + render.tprint.fb = &screen; + haloo3d_easytimer frametimer, sdltimer; haloo3d_easytimer_init(&frametimer, AVGWEIGHT); haloo3d_easytimer_init(&sdltimer, AVGWEIGHT); @@ -52,13 +62,29 @@ int main() { // int argc, char **argv) { // Load the junk + generate stuff haloo3d_obj *flooro = haloo3d_easystore_addobj(&storage, "floor"); haloo3d_obj *ceilo = haloo3d_easystore_addobj(&storage, "ceiling"); + haloo3d_obj *wallo = haloo3d_easystore_addobj(&storage, "walls"); haloo3d_fb *floort = haloo3d_easystore_addtex(&storage, "floor"); haloo3d_fb *ceilt = haloo3d_easystore_addtex(&storage, "ceiling"); + haloo3d_fb *wallt = haloo3d_easystore_addtex(&storage, "walls"); haloo3d_gen_plane(flooro, MAZESIZE); haloo3d_gen_plane(ceilo, MAZESIZE); + haloo3d_gen_grid(wallo, MAZESIZE); + uint16_t cols[4] = {0xFD93, 0xFB83, 0xFEEE, 0xFDDD}; - haloo3d_gen_checkerboard(floort, cols, 2, 32); - haloo3d_gen_checkerboard(ceilt, cols + 2, 2, 32); + haloo3d_fb_init_tex(floort, 64, 64); + haloo3d_apply_alternating(floort, cols, 1); + haloo3d_apply_noise(floort, NULL, 1.0 / 6); + // haloo3d_apply_alternating(floort, cols, 2); + haloo3d_fb_init_tex(ceilt, 16, 16); + haloo3d_apply_alternating(ceilt, cols + 2, 2); + + haloo3d_fb_init_tex(wallt, 64, 64); + uint16_t wallcols[] = {0xFA22}; + haloo3d_apply_alternating(wallt, wallcols, 1); + haloo3d_apply_noise(wallt, NULL, 1.0 / 8); + haloo3d_apply_brick(wallt, 16, 11, 0xFEEE); + // haloo3d_apply_brick(wallt, 14, 8, 0xFD94); + haloo3d_apply_noise(wallt, NULL, 1.0 / 8); eprintf("Initialized models and textures\n"); // Lighting. Note that for performance, the lighting is always calculated @@ -71,17 +97,23 @@ int main() { // int argc, char **argv) { haloo3d_obj_instance *floori = haloo3d_easyrender_addinstance(&render, flooro, floort); + haloo3d_obj_instance *walli = + haloo3d_easyrender_addinstance(&render, wallo, wallt); haloo3d_obj_instance *ceili = haloo3d_easyrender_addinstance(&render, ceilo, ceilt); floori->cullbackface = 0; ceili->cullbackface = 0; + walli->cullbackface = 0; + vec3(floori->scale.v, HSCALE, 1, HSCALE); + vec3(ceili->scale.v, HSCALE, 1, HSCALE); + vec3(walli->scale.v, HSCALE, 0, HSCALE); ceili->pos.y = 1; eprintf("Setup all object instances\n"); unigi_type_event event; unigi_type_resolution res; - res.width = WIDTH; - res.height = HEIGHT; + res.width = SWIDTH; + res.height = SHEIGHT; res.depth = 0; int totaldrawn = 0; @@ -98,12 +130,26 @@ int main() { // int argc, char **argv) { // Actual rendering // ----------------------------------- + // ceili->texture = &render.window; + while (1) { haloo3d_easytimer_start(&frametimer); - render.camera.yaw += 0.005; + render.camera.yaw += 0.008; haloo3d_easyrender_beginframe(&render); - memset(render.window.buffer, 0, - sizeof(uint16_t) * render.window.width * render.window.height); + haloo3d_fb_clear(&render.window, 0xF000); + // memset(render.window.buffer, 0, + // sizeof(uint16_t) * render.window.width * render.window.height); + + // for (int j = 0; j < 100; j++) { + // ceilt->buffer[rand() % (ceilt->width * ceilt->height)] = + // 0xF000 | (rand() & 0xFFF); + // } + + walli->scale.y = fabs(sin(3 * render.camera.yaw)); + // render.camera.up.x = sin(render.camera.yaw); + // render.camera.up.y = cos(render.camera.yaw); + // walli->up.x = sin(3 * render.camera.yaw); + // walli->up.y = cos(4 * render.camera.yaw); unigi_event_get(&event); if (event.type == unigi_enum_event_input_keyboard) { @@ -126,6 +172,8 @@ int main() { // int argc, char **argv) { } } + haloo3d_sprite(&screen, &render.window, texrect, screenrect); + haloo3d_print(&render.tprint, "Last frame: %05.2f (%05.2f)\nLast SDLFl: %05.2f " "(%05.2f)\nTris: %d / %d\nVerts: %d\n", @@ -133,7 +181,7 @@ int main() { // int argc, char **argv) { sdltimer.last * 1000, sdltimer.sum * 1000, totaldrawn, render.totalfaces, render.totalverts); - unigi_graphics_blit(0, (unigi_type_color *)render.window.buffer, + unigi_graphics_blit(0, (unigi_type_color *)screen.buffer, res.width * res.height); haloo3d_easytimer_start(&sdltimer);