2022-08-20 16:32:37 +02:00
|
|
|
#include "level.h"
|
|
|
|
#include "generator.h"
|
2022-08-20 16:31:49 +02:00
|
|
|
#include "render.h"
|
2022-08-20 11:51:24 +02:00
|
|
|
#include <gint/display.h>
|
|
|
|
#include <gint/keyboard.h>
|
|
|
|
#include <gint/timer.h>
|
|
|
|
#include <azur/gint/render.h>
|
|
|
|
#include <gint/drivers/r61524.h>
|
2022-08-20 16:31:49 +02:00
|
|
|
#include <fxlibc/printf.h>
|
|
|
|
|
2022-08-20 11:51:24 +02:00
|
|
|
int main(void)
|
|
|
|
{
|
2022-08-20 16:31:49 +02:00
|
|
|
__printf_enable_fp();
|
2022-08-20 15:18:14 +02:00
|
|
|
prof_init();
|
2022-08-20 11:51:24 +02:00
|
|
|
azrp_config_scale(1);
|
|
|
|
azrp_shader_clear_configure();
|
2022-08-20 16:31:49 +02:00
|
|
|
// azrp_shader_image_rgb16_configure();
|
|
|
|
// azrp_shader_image_p8_configure();
|
|
|
|
// azrp_shader_image_p4_configure();
|
2022-08-20 11:51:24 +02:00
|
|
|
azrp_shader_triangle_configure();
|
|
|
|
|
2022-08-20 16:31:49 +02:00
|
|
|
level_t level = level_create(1);
|
|
|
|
|
2022-08-20 17:55:41 +02:00
|
|
|
int volatile need_frame = 1;
|
2022-08-20 11:51:24 +02:00
|
|
|
int timer = timer_configure(TIMER_ANY, 33000, GINT_CALL_SET(&need_frame));
|
|
|
|
timer_start(timer);
|
2022-08-20 17:55:41 +02:00
|
|
|
|
|
|
|
num t = 0.0;
|
|
|
|
num player_z = 0.0;
|
|
|
|
num level_z = 0.0;
|
|
|
|
num player_speed = 5.0;
|
|
|
|
int sections_passed = 0;
|
2022-08-20 11:51:24 +02:00
|
|
|
|
2022-08-20 16:31:49 +02:00
|
|
|
bool game_run = true;
|
|
|
|
while(game_run) {
|
2022-08-20 17:55:41 +02:00
|
|
|
num dt = 1.0 / 30;
|
|
|
|
t += dt;
|
2022-08-20 11:51:24 +02:00
|
|
|
|
2022-08-20 16:31:49 +02:00
|
|
|
level_update(&level);
|
2022-08-20 11:51:24 +02:00
|
|
|
|
2022-08-20 17:55:41 +02:00
|
|
|
//---
|
|
|
|
// Rendering
|
|
|
|
//---
|
|
|
|
|
2022-08-20 15:18:14 +02:00
|
|
|
azrp_perf_clear();
|
2022-08-20 11:51:24 +02:00
|
|
|
azrp_clear(C_WHITE);
|
2022-08-20 16:31:49 +02:00
|
|
|
|
|
|
|
struct camera camera;
|
|
|
|
camera.pos = vec3(0, RENDER_CAMERA_DEPTH, 0);
|
|
|
|
vec2 screen_size(DWIDTH, DHEIGHT);
|
|
|
|
|
2022-08-20 17:55:41 +02:00
|
|
|
for(int depth = RENDER_SECTION_DISTANCE - 1; depth >= 0; depth--) {
|
|
|
|
num z = depth * RENDER_SECTION_LENGTH - level_z;
|
|
|
|
|
|
|
|
for(int i = 0; i < PLATFORM_COUNT; i++) {
|
|
|
|
int gray = ((i + depth + sections_passed) % PLATFORM_COUNT)
|
|
|
|
* 31 / PLATFORM_COUNT;
|
|
|
|
int color = C_RGB(gray, gray, gray);
|
|
|
|
|
|
|
|
struct prect p = render_platform_position(i, z);
|
|
|
|
/* Near plane clipping */
|
|
|
|
if(p.fl.z <= num(0.1) || p.fr.z <= num(0.1)) continue;
|
|
|
|
if(p.nl.z <= num(0.1)) p.nl.z = num(0.1);
|
|
|
|
if(p.nr.z <= num(0.1)) p.nr.z = num(0.1);
|
|
|
|
|
|
|
|
camera_project_prect(&camera, &p, screen_size);
|
|
|
|
render_triangle(&p.nl, &p.fr, &p.fl, color);
|
|
|
|
render_triangle(&p.fr, &p.nl, &p.nr, color);
|
|
|
|
}
|
2022-08-20 16:31:49 +02:00
|
|
|
}
|
2022-08-20 11:51:24 +02:00
|
|
|
azrp_update();
|
|
|
|
|
|
|
|
drect(0, DHEIGHT-20, DWIDTH-1, DHEIGHT-1, C_WHITE);
|
2022-08-20 17:55:41 +02:00
|
|
|
dprint(1, 210, C_BLACK, "render:%4d+%4dus level_z=%f",
|
2022-08-20 15:18:14 +02:00
|
|
|
prof_time(azrp_perf_render) - prof_time(azrp_perf_r61524),
|
2022-08-20 17:55:41 +02:00
|
|
|
prof_time(azrp_perf_r61524),
|
|
|
|
(float)level_z);
|
2022-08-20 11:51:24 +02:00
|
|
|
r61524_display(gint_vram, DHEIGHT-20, 20, R61524_DMA_WAIT);
|
|
|
|
|
2022-08-20 17:55:41 +02:00
|
|
|
//---
|
|
|
|
// Input
|
|
|
|
//---
|
2022-08-20 16:31:49 +02:00
|
|
|
|
|
|
|
key_event_t ev;
|
|
|
|
while((ev = pollevent()).type != KEYEV_NONE) {
|
|
|
|
if(ev.type == KEYEV_UP)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(ev.key == KEY_EXIT || ev.key == KEY_MENU)
|
|
|
|
game_run = false;
|
|
|
|
if(ev.key == KEY_F1)
|
|
|
|
level = level_create(1);
|
|
|
|
if(ev.key == KEY_F2)
|
|
|
|
level = level_create(2);
|
|
|
|
if(ev.key == KEY_F3)
|
|
|
|
level = level_create(3);
|
|
|
|
}
|
2022-08-20 17:55:41 +02:00
|
|
|
|
|
|
|
if(!game_run) break;
|
|
|
|
|
|
|
|
//---
|
|
|
|
// Simulation
|
|
|
|
//---
|
|
|
|
|
|
|
|
player_z += player_speed * dt;
|
|
|
|
level_z += player_speed * dt;
|
|
|
|
while(level_z > num(RENDER_SECTION_LENGTH)) {
|
|
|
|
level_advance(&level);
|
|
|
|
level_z -= RENDER_SECTION_LENGTH;
|
|
|
|
sections_passed++;
|
|
|
|
}
|
2022-08-20 11:51:24 +02:00
|
|
|
}
|
|
|
|
|
2022-08-20 17:55:41 +02:00
|
|
|
timer_stop(timer);
|
2022-08-20 16:31:49 +02:00
|
|
|
return 0;
|
2022-08-20 11:51:24 +02:00
|
|
|
}
|