551 lines
19 KiB
C
551 lines
19 KiB
C
#include "haloo3d/haloo3d.h"
|
|
#include "haloo3d/haloo3dex_console.h"
|
|
#include "haloo3d/haloo3dex_easy.h"
|
|
#include "haloo3d/haloo3dex_gen.h"
|
|
// #include "haloo3d/haloo3dex_img.h"
|
|
#include "haloo3d/haloo3dex_obj.h"
|
|
#include "haloo3d/haloo3dex_print.h"
|
|
|
|
#include "unigi/unigi.headers/src/main.h"
|
|
#include "unigi/unigi.platform.sdl1/src/main.c"
|
|
|
|
#include "ecs2.h"
|
|
#include "ecs2_comps.h"
|
|
#include "keys.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
// INteresting flags for performance comparisons
|
|
#define FASTFILL
|
|
|
|
#define WIDTH 480
|
|
#define HEIGHT 300
|
|
#define ASPECT ((float)WIDTH / HEIGHT)
|
|
#define SCREENSCALE 2
|
|
#define SWIDTH (WIDTH * SCREENSCALE)
|
|
#define SHEIGHT (HEIGHT * SCREENSCALE)
|
|
#define NEARCLIP 0.01
|
|
#define FARCLIP 100.0
|
|
#define LIGHTANG -MPI / 4.0
|
|
#define AVGWEIGHT 0.85
|
|
|
|
// Game options
|
|
#define MAZESIZE 15
|
|
#define HSCALE 1.5
|
|
|
|
// Maze grows in the positive direction
|
|
#define MAZENORTH 1
|
|
#define MAZEEAST 2
|
|
#define MAZEVISIT 4
|
|
|
|
// When you rightshift these values, you "turn right".
|
|
// NOTE: north in this case is "towards the screen" because it moves in the
|
|
// positive direction. In this case, it's actually wound in the opposite
|
|
// direction of what you'd expect
|
|
#define DIRNORTH 8
|
|
#define DIRWEST 4
|
|
#define DIRSOUTH 2
|
|
#define DIREAST 1
|
|
|
|
#define TURNRIGHT(d) (d == 1 ? 8 : (d >> 1))
|
|
#define TURNLEFT(d) (d == 8 ? 1 : (d << 1))
|
|
#define STACKPUSH(s, t, v) s[t++] = v;
|
|
|
|
// Store all the values users can change at the beginning
|
|
float ditherstart = -1;
|
|
float ditherend = 8;
|
|
float fov = 90.0;
|
|
float minlight = 0.25;
|
|
int fps = 30;
|
|
uint16_t sky = 0xF000;
|
|
|
|
struct vec2i dirtovec(uint8_t dir) {
|
|
struct vec2i result;
|
|
switch (dir) {
|
|
case DIREAST:
|
|
vec2i(result.v, 1, 0);
|
|
break;
|
|
case DIRWEST:
|
|
vec2i(result.v, -1, 0);
|
|
break;
|
|
case DIRNORTH:
|
|
vec2i(result.v, 0, 1);
|
|
break;
|
|
case DIRSOUTH:
|
|
vec2i(result.v, 0, -1);
|
|
break;
|
|
default:
|
|
vec2i(result.v, 0, 0);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
int maze_visited(uint8_t *maze, int x, int y, int size) {
|
|
return (maze[x + y * size] & MAZEVISIT) > 0;
|
|
}
|
|
|
|
int maze_connected(uint8_t *maze, int x, int y, int size, uint8_t move) {
|
|
// eprintf("CHECKING DIR %d at (%d,%d), it is %d\n", move, x, y,
|
|
// maze[x + y * size]);
|
|
if (move == DIREAST) {
|
|
return (maze[x + y * size] & MAZEEAST) == 0;
|
|
} else if (move == DIRWEST) {
|
|
return (x > 0) && ((maze[x - 1 + y * size] & MAZEEAST) == 0);
|
|
} else if (move == DIRNORTH) {
|
|
return (maze[x + y * size] & MAZENORTH) == 0;
|
|
} else if (move == DIRSOUTH) {
|
|
return (y > 0) && ((maze[x + (y - 1) * size] & MAZENORTH) == 0);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// Generate a (square) maze. Utilize one bit of the maze (#2) to
|
|
// indicate whether it is visited
|
|
void maze_generate(uint8_t *maze, int size) {
|
|
const int mazesquare = (size) * (size);
|
|
for (int i = 0; i < mazesquare; i++) {
|
|
maze[i] = MAZENORTH | MAZEEAST;
|
|
}
|
|
int *mazestack;
|
|
mallocordie(mazestack, sizeof(int) * mazesquare);
|
|
for (int i = 0; i < size * size; i++) {
|
|
mazestack[i] = -1;
|
|
}
|
|
// Push current cell onto stack, mark as visited
|
|
int x = size / 2;
|
|
int y = size / 2;
|
|
int mazetop = 0;
|
|
STACKPUSH(mazestack, mazetop, x + y * size);
|
|
maze[x + y * size] |= MAZEVISIT;
|
|
uint8_t visitable[4];
|
|
int visittop = 0;
|
|
|
|
// Now let's make a maze!
|
|
while (mazetop) {
|
|
mazetop--;
|
|
visittop = 0;
|
|
x = mazestack[mazetop] % size;
|
|
y = mazestack[mazetop] / size;
|
|
if (x > 0 && !maze_visited(maze, x - 1, y, size)) {
|
|
visitable[visittop++] = DIRWEST;
|
|
}
|
|
if (x < size - 1 && !maze_visited(maze, x + 1, y, size)) {
|
|
visitable[visittop++] = DIREAST;
|
|
}
|
|
if (y > 0 && !maze_visited(maze, x, y - 1, size)) {
|
|
visitable[visittop++] = DIRSOUTH;
|
|
}
|
|
if (y < size - 1 && !maze_visited(maze, x, y + 1, size)) {
|
|
visitable[visittop++] = DIRNORTH;
|
|
}
|
|
// You can generate a random location!
|
|
if (visittop) {
|
|
// Readd ourselves, we're moving
|
|
STACKPUSH(mazestack, mazetop, x + y * size);
|
|
uint8_t dir = visitable[rand() % visittop];
|
|
struct vec2i movedir = dirtovec(dir);
|
|
int nx = x + movedir.x;
|
|
int ny = y + movedir.y;
|
|
// Trust that the visitable array is always valid
|
|
if (dir == DIREAST) { // Tear down east wall
|
|
maze[x + y * size] &= ~MAZEEAST;
|
|
} else if (dir == DIRWEST) { // Move left and tear down east wall
|
|
maze[(x - 1) + y * size] &= ~MAZEEAST;
|
|
} else if (dir == DIRNORTH) { // tear down north wall
|
|
maze[x + y * size] &= ~MAZENORTH;
|
|
} else if (dir == DIRSOUTH) { // move down and tear down north wall
|
|
maze[x + (y - 1) * size] &= ~MAZENORTH;
|
|
}
|
|
// Push onto stack and set visited
|
|
STACKPUSH(mazestack, mazetop, nx + ny * size);
|
|
maze[nx + ny * size] |= MAZEVISIT;
|
|
}
|
|
}
|
|
|
|
free(mazestack);
|
|
}
|
|
|
|
void maze_wall_generate(uint8_t *maze, int size, haloo3d_obj *obj) {
|
|
// Simple: for each cell, we check if north or east is a wall. If so,
|
|
// generate it. Also, generate walls for the south and west global wall
|
|
for (int y = 0; y < size; y++) {
|
|
for (int x = 0; x < size; x++) {
|
|
if (!maze_connected(maze, x, y, size, DIREAST)) {
|
|
haloo3d_gen_grid_quad(obj, x, y, dirtovec(DIREAST));
|
|
}
|
|
if (!maze_connected(maze, x, y, size, DIRNORTH)) {
|
|
haloo3d_gen_grid_quad(obj, x, y, dirtovec(DIRNORTH));
|
|
}
|
|
}
|
|
}
|
|
for (int i = 0; i < size; i++) {
|
|
haloo3d_gen_grid_quad(obj, i, 0, dirtovec(DIRSOUTH));
|
|
haloo3d_gen_grid_quad(obj, 0, i, dirtovec(DIRWEST));
|
|
}
|
|
}
|
|
|
|
// A general position within the maze, and a pointer to the maze itself.
|
|
// Can be used to traverse the maze
|
|
typedef struct {
|
|
uint8_t *maze;
|
|
struct vec2i pos; // tile position within maze
|
|
int size;
|
|
uint8_t dir; // facing dir (see DIREAST/DIRSOUTH/etc);
|
|
} ecs_maze;
|
|
|
|
// State for tracking ai moving through the maze.
|
|
typedef struct {
|
|
uint8_t state;
|
|
// uint8_t nextdir;
|
|
uint32_t timer;
|
|
} ecs_smartai;
|
|
|
|
// everything in the maze is controlled by the CPU. As such, movement
|
|
// is as simple as "go here by this time". No need to complicate the
|
|
// components?
|
|
static void sys_ecs_smartai(ecs_smartai *smartai, ecs_maze *maze,
|
|
ecs_moveto *mt, ecs_rotateto *rt) {
|
|
// haloo_ecs *ecs, hecs_eidt id, hecs_cidt said, hecs_cidt mzid, hecs_cidt
|
|
// mtid, hecs_cidt rtid) {
|
|
// ecs_smartai *smartai = HECS_ENTITYCOMPONENT(ecs_smartai *, id, said, ecs);
|
|
// ecs_maze *maze = HECS_ENTITYCOMPONENT(ecs_maze *, id, mzid, ecs);
|
|
// ecs_moveto *mt = HECS_ENTITYCOMPONENT(ecs_moveto *, id, mtid, ecs);
|
|
// ecs_rotateto *rt = HECS_ENTITYCOMPONENT(ecs_rotateto *, id, rtid, ecs);
|
|
int actiontime = fps / 2;
|
|
// Some states are triggered based on the timer
|
|
if (smartai->timer > 0) {
|
|
smartai->timer--;
|
|
}
|
|
// The rotation is delayed to make it feel a bit more like the original
|
|
// maze, which I think determined rotation and direction upon entering
|
|
// a tile. I instead calculate that in the middle of the tile. It doesn't
|
|
// really line up like it does on the windows screensaver but it's
|
|
// close enough for me.
|
|
if (smartai->timer == 0) {
|
|
if (smartai->state == 1) {
|
|
eprintf("TURNING RIGHT\n");
|
|
rt->dstrot.x = rt->dstrot.x + MPI_2;
|
|
rt->timer = actiontime;
|
|
maze->dir = TURNRIGHT(maze->dir);
|
|
smartai->state = 0;
|
|
} else if (smartai->state == 2) {
|
|
eprintf("TURNING LEFT\n");
|
|
rt->dstrot.x = rt->dstrot.x - MPI_2;
|
|
rt->timer = actiontime;
|
|
maze->dir = TURNLEFT(maze->dir);
|
|
smartai->state = 0;
|
|
}
|
|
}
|
|
// Only decide to do things if you're not moving anymore. Movement is the most
|
|
// important thing
|
|
if (mt->timer == 0) {
|
|
eprintf("SMARTAI: %d TIMER: %d DIR: %d POS: (%f, %f)\n", smartai->state,
|
|
smartai->timer, maze->dir, mt->pos.x, mt->pos.z);
|
|
// Player can only move forward if there's nothing in front of them
|
|
if (maze_connected(maze->maze, maze->pos.x, maze->pos.y, maze->size,
|
|
maze->dir)) {
|
|
struct vec2i movement = dirtovec(maze->dir);
|
|
maze->pos.x += movement.x;
|
|
maze->pos.y += movement.y;
|
|
mt->timer = actiontime;
|
|
mt->dst.x += HSCALE * movement.x;
|
|
mt->dst.z += HSCALE * movement.y;
|
|
smartai->state = 0;
|
|
}
|
|
if (smartai->timer <= 0) {
|
|
// Ok we might be moving, we might not be. Let's go ahead and calculate
|
|
// rotation based on the FUTURE direction we want to turn.
|
|
uint8_t rightdir = TURNRIGHT(maze->dir);
|
|
uint8_t leftdir = TURNLEFT(maze->dir);
|
|
if (maze_connected(maze->maze, maze->pos.x, maze->pos.y, maze->size,
|
|
rightdir)) {
|
|
// Always choose right over left
|
|
smartai->state = 1;
|
|
smartai->timer = 2 * actiontime / 5;
|
|
eprintf("WILL TURN RIGHT TO: %d\n", rightdir);
|
|
} else if (!maze_connected(maze->maze, maze->pos.x, maze->pos.y,
|
|
maze->size, maze->dir)) {
|
|
// We only move left if the player can't move forward or right
|
|
smartai->state = 2;
|
|
smartai->timer = 2 * actiontime / 5;
|
|
eprintf("WILL TURN LEFT (stuck) TO: %d\n", leftdir);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Setup ECS system for our game
|
|
ECS_START(mecs)
|
|
ECS_COMPONENT(ecs_moveto);
|
|
ECS_COMPONENT(ecs_rotateto);
|
|
ECS_COMPONENT(ecs_smartai);
|
|
ECS_COMPONENT(ecs_camera);
|
|
ECS_COMPONENT(ecs_maze);
|
|
ECS_END(mecs)
|
|
|
|
// And then a copy of the components here... that sucksssss
|
|
ECS_CID(ecs_moveto, 0);
|
|
ECS_CID(ecs_rotateto, 1);
|
|
ECS_CID(ecs_smartai, 2);
|
|
ECS_CID(ecs_camera, 3);
|
|
ECS_CID(ecs_maze, 4);
|
|
|
|
ECS_SYSTEM1(mecs, sys_ecs_moveto, ecs_moveto);
|
|
ECS_SYSTEM1(mecs, sys_ecs_rotateto, ecs_rotateto);
|
|
ECS_SYSTEM2(mecs, sys_ecs_moveto_camera, ecs_moveto, ecs_camera);
|
|
ECS_SYSTEM2(mecs, sys_ecs_rotateto_camera, ecs_rotateto, ecs_camera);
|
|
ECS_SYSTEM4(mecs, sys_ecs_smartai, ecs_smartai, ecs_maze, ecs_moveto,
|
|
ecs_rotateto);
|
|
|
|
// ECS_SYSTEM1(mecs, sys2_moveto, ecs_moveto, mt) {
|
|
// mt->pos.x = 1;
|
|
// }
|
|
|
|
int main() { // int argc, char **argv) {
|
|
|
|
haloo3d_easystore storage;
|
|
haloo3d_easystore_init(&storage);
|
|
|
|
haloo3d_debugconsole dc;
|
|
haloo3d_debugconsole_init(&dc);
|
|
|
|
haloo3d_fb screen;
|
|
haloo3d_fb_init(&screen, SWIDTH, SHEIGHT);
|
|
|
|
haloo3d_easyrender render;
|
|
haloo3d_easyrender_init(&render, WIDTH, HEIGHT);
|
|
render.camera.pos.y = 0.5;
|
|
eprintf("Initialized renderer\n");
|
|
|
|
haloo3d_debugconsole_set(&dc, "render/fps.i", &fps);
|
|
haloo3d_debugconsole_set(&dc, "render/fov.f", &fov);
|
|
haloo3d_debugconsole_set(&dc, "render/trifunc.i", &render.trifunc);
|
|
haloo3d_debugconsole_set(&dc, "render/ditherstart.f", &ditherstart);
|
|
haloo3d_debugconsole_set(&dc, "render/ditherend.f", &ditherend);
|
|
haloo3d_debugconsole_set(&dc, "render/sky.u16x", &sky);
|
|
haloo3d_debugconsole_set(&dc, "camera/pos_y.f", &render.camera.pos.y);
|
|
haloo3d_debugconsole_set(&dc, "camera/pitch.f", &render.camera.pitch);
|
|
|
|
render.tprint.fb = &screen;
|
|
|
|
haloo3d_easytimer frametimer, sdltimer, filltimer;
|
|
haloo3d_easytimer_init(&frametimer, AVGWEIGHT);
|
|
haloo3d_easytimer_init(&sdltimer, AVGWEIGHT);
|
|
haloo3d_easytimer_init(&filltimer, AVGWEIGHT);
|
|
|
|
// 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, 0);
|
|
|
|
// no generic maze generator, we just do it raw. Each cell has a byte which
|
|
// indicates if the wall to the NORTH (#0 bit) and the wall to the WEST (#1
|
|
// bit) are solid. Because of this, we need one additional row and column
|
|
uint8_t maze[MAZESIZE * MAZESIZE];
|
|
maze_generate(maze, MAZESIZE);
|
|
maze_wall_generate(maze, MAZESIZE, wallo);
|
|
|
|
uint16_t cols[4] = {0xFD93, 0xFB83, 0xFFFF}; //, 0xFDDD};
|
|
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, 64, 64);
|
|
haloo3d_apply_alternating(ceilt, cols + 2, 1);
|
|
haloo3d_apply_noise(ceilt, NULL, 1.0 / 4);
|
|
haloo3d_apply_brick(ceilt, 16, 8, 0xFAAA);
|
|
|
|
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, 18, 13, 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
|
|
// against the base model, and is thus not realistic if the object rotates in
|
|
// the world. This can be fixed easily, since each object gets its own
|
|
// lighting vector, which can easily be rotated in the opposite direction of
|
|
// the model
|
|
struct vec3 light;
|
|
vec3(light.v, 0, -MCOS(LIGHTANG), MSIN(LIGHTANG));
|
|
|
|
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, 1, HSCALE);
|
|
// vec3(walli->scale.v, HSCALE, 0, HSCALE);
|
|
floori->pos.x += MAZESIZE / 2.0 * HSCALE;
|
|
floori->pos.z += MAZESIZE / 2.0 * HSCALE;
|
|
ceili->pos.x += MAZESIZE / 2.0 * HSCALE;
|
|
ceili->pos.z += MAZESIZE / 2.0 * HSCALE;
|
|
walli->pos.x += MAZESIZE / 2.0 * HSCALE;
|
|
walli->pos.z += MAZESIZE / 2.0 * HSCALE;
|
|
ceili->pos.y = 1; //-1;
|
|
eprintf("Setup all object instances\n");
|
|
|
|
unigi_type_event event;
|
|
unigi_type_resolution res;
|
|
res.width = SWIDTH;
|
|
res.height = SHEIGHT;
|
|
res.depth = 0;
|
|
|
|
int totaldrawn = 0;
|
|
|
|
eprintf("Scene has %d tris, %d verts\n", render.totalfaces,
|
|
render.totalverts);
|
|
|
|
// Init unigi system
|
|
// sprintf(render.printbuf, "maze.exe - %s %s %s", argv[1], argv[2], argv[3]);
|
|
unigi_graphics_init();
|
|
unigi_window_create(res, "maze.exe"); // render.printbuf);
|
|
|
|
// render.camera.pos.y = 4; // 5;
|
|
// render.camera.pitch = MPI - 0.1; // 2.2;
|
|
// ceili->pos.y = -10;
|
|
|
|
haloo3d_debugconsole_set(&dc, "obj/ceil/pos_y.f", &ceili->pos.y);
|
|
|
|
// Set up the various systems
|
|
mecs ecs;
|
|
mecs_init(&ecs);
|
|
|
|
ecs_eid playerid = mecs_newentity(&ecs, 0);
|
|
if (playerid == -1) {
|
|
dieerr("WHY IS PLAYERID -1???\n");
|
|
}
|
|
eprintf("Player eid: %d\n", playerid);
|
|
|
|
// System is setup such that camera position matches maze index
|
|
render.camera.pos.x = 0.5 * HSCALE;
|
|
render.camera.pos.z = 0.5 * HSCALE;
|
|
struct vec2i playerstart = {.x = 0, .y = 0};
|
|
struct vec2 playerrotation = {.x = render.camera.yaw,
|
|
.y = render.camera.pitch};
|
|
ECS_SETCOMPONENT(&ecs, playerid, ecs_moveto){
|
|
.pos = render.camera.pos, .dst = render.camera.pos, .timer = 0};
|
|
ECS_SETCOMPONENT(&ecs, playerid, ecs_rotateto){
|
|
.rot = playerrotation, .dstrot = playerrotation, .timer = 0};
|
|
ECS_SETCOMPONENT(&ecs, playerid, ecs_maze){
|
|
.maze = maze, .pos = playerstart, .size = MAZESIZE, .dir = DIRSOUTH};
|
|
ECS_SETCOMPONENT(&ecs, playerid, ecs_camera) & render.camera;
|
|
ECS_SETCOMPONENT(&ecs, playerid, ecs_smartai){.state = 0, .timer = 0};
|
|
|
|
eprintf("Player component mask: %lx\n", ecs.entities[playerid]);
|
|
|
|
// -----------------------------------
|
|
// Actual rendering
|
|
// -----------------------------------
|
|
|
|
// ceili->texture = &render.window;
|
|
|
|
while (1) {
|
|
haloo3d_easytimer_start(&frametimer);
|
|
// render.camera.yaw += 0.008;
|
|
haloo3d_perspective(render.perspective, fov, ASPECT, NEARCLIP, FARCLIP);
|
|
haloo3d_easyrender_beginframe(&render);
|
|
haloo3d_fb_clear(&render.window, sky);
|
|
|
|
// 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) {
|
|
if (event.data.input_keyboard.down) {
|
|
switch (event.data.input_keyboard.button) {
|
|
case KEY_SPACE:
|
|
haloo3d_debugconsole_beginprompt(&dc);
|
|
break;
|
|
default:
|
|
exit(0);
|
|
}
|
|
}
|
|
}
|
|
|
|
// ---------------------------
|
|
// Game logic?
|
|
// ---------------------------
|
|
|
|
for (int i = 0; i < ECS_MAXENTITIES; i++) {
|
|
sys_ecs_smartai_run(&ecs, i);
|
|
sys_ecs_moveto_run(&ecs, i);
|
|
sys_ecs_rotateto_run(&ecs, i);
|
|
sys_ecs_moveto_camera_run(&ecs, i);
|
|
sys_ecs_rotateto_camera_run(&ecs, i);
|
|
}
|
|
|
|
totaldrawn = 0;
|
|
|
|
haloo3d_obj_instance *object = NULL;
|
|
|
|
// Iterate over objects
|
|
while ((object = haloo3d_easyrender_nextinstance(&render, object)) !=
|
|
NULL) {
|
|
// Setup final model matrix and the precalced vertices
|
|
haloo3d_easyrender_beginmodel(&render, object);
|
|
// Iterate over object faces
|
|
for (int fi = 0; fi < object->model->numfaces; fi++) {
|
|
totaldrawn += haloo3d_easyrender_renderface(
|
|
&render, object, fi, ditherstart, ditherend, minlight);
|
|
}
|
|
}
|
|
|
|
haloo3d_easytimer_start(&filltimer);
|
|
#ifdef FASTFILL
|
|
haloo3d_fb_fill(&screen, &render.window);
|
|
#else
|
|
haloo3d_recti texrect = {.x1 = 0, .y1 = 0, .x2 = WIDTH, .y2 = HEIGHT};
|
|
haloo3d_recti screenrect = {.x1 = 0, .y1 = 0, .x2 = SWIDTH, .y2 = SHEIGHT};
|
|
haloo3d_sprite(&screen, &render.window, texrect, screenrect);
|
|
#endif
|
|
haloo3d_easytimer_end(&filltimer);
|
|
|
|
haloo3d_print(&render.tprint,
|
|
"Last frame: %05.2f (%05.2f)\nLast fill: %05.2f "
|
|
"(%05.2f)\nLast SDLFl: %05.2f "
|
|
"(%05.2f)\nTris: %d / %d\nVerts: %d\n",
|
|
frametimer.last * 1000, frametimer.sum * 1000,
|
|
filltimer.last * 1000, filltimer.sum * 1000,
|
|
sdltimer.last * 1000, sdltimer.sum * 1000, totaldrawn,
|
|
render.totalfaces, render.totalverts);
|
|
|
|
haloo3d_easytimer_start(&sdltimer);
|
|
unigi_graphics_blit(0, (unigi_type_color *)screen.buffer,
|
|
res.width * res.height);
|
|
unigi_graphics_flush();
|
|
haloo3d_easytimer_end(&sdltimer);
|
|
|
|
haloo3d_easytimer_end(&frametimer);
|
|
|
|
float waittime = (1.0 / fps) - frametimer.last;
|
|
if (waittime > 0) {
|
|
unigi_time_sleep(waittime * unigi_time_clocks_per_s);
|
|
}
|
|
}
|
|
|
|
// Just to get the compiler to STOP COMPLAINING about unused
|
|
mecs_deleteentity(&ecs, playerid);
|
|
|
|
haloo3d_easystore_deleteallobj(&storage, haloo3d_obj_free);
|
|
haloo3d_easystore_deletealltex(&storage, haloo3d_fb_free);
|
|
}
|