maze more
This commit is contained in:
parent
3255556ead
commit
1567cf0d15
2
haloo3d
2
haloo3d
@ -1 +1 @@
|
|||||||
Subproject commit 1a1a277e7bd1bf824faaafe01d88d8ab46cce85e
|
Subproject commit d19e5e7fbd3b1024c178f0c1c575ecb16625ffcb
|
98
maze.c
98
maze.c
@ -13,8 +13,8 @@
|
|||||||
// Performance options
|
// Performance options
|
||||||
#define DOLIGHTING
|
#define DOLIGHTING
|
||||||
// #define FASTTRIS
|
// #define FASTTRIS
|
||||||
#define DITHERSTART 100
|
#define DITHERSTART 1
|
||||||
#define DITHEREND 101
|
#define DITHEREND 8
|
||||||
#define TARGETFPS 60
|
#define TARGETFPS 60
|
||||||
#define SECPERFRAME 1.0 / TARGETFPS
|
#define SECPERFRAME 1.0 / TARGETFPS
|
||||||
|
|
||||||
@ -35,20 +35,7 @@
|
|||||||
// Game options
|
// Game options
|
||||||
#define MAZESIZE 31
|
#define MAZESIZE 31
|
||||||
|
|
||||||
#ifdef FASTTRIS
|
int main() { // int argc, char **argv) {
|
||||||
#define DBUFCLEARFUNC(fb) haloo3d_fb_cleardepth(fb, FARCLIP);
|
|
||||||
#define TRIFUNC haloo3d_texturedtriangle_fast
|
|
||||||
#else
|
|
||||||
#define DBUFCLEARFUNC(fb) haloo3d_fb_cleardepth(fb, 0);
|
|
||||||
#define TRIFUNC haloo3d_texturedtriangle
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
|
||||||
|
|
||||||
if (argc != 4) {
|
|
||||||
dieerr("You must pass in the following:\n- obj file .obj\n- texture file "
|
|
||||||
".ppm\n- camera file (xofs yofs zofs yawdeg pitchdeg)\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
haloo3d_easystore storage;
|
haloo3d_easystore storage;
|
||||||
haloo3d_easystore_init(&storage);
|
haloo3d_easystore_init(&storage);
|
||||||
@ -56,14 +43,14 @@ int main(int argc, char **argv) {
|
|||||||
haloo3d_easyrender render;
|
haloo3d_easyrender render;
|
||||||
haloo3d_easyrender_init(&render, WIDTH, HEIGHT);
|
haloo3d_easyrender_init(&render, WIDTH, HEIGHT);
|
||||||
haloo3d_perspective(render.perspective, FOV, ASPECT, NEARCLIP, FARCLIP);
|
haloo3d_perspective(render.perspective, FOV, ASPECT, NEARCLIP, FARCLIP);
|
||||||
|
render.camera.pos.y = 0.5;
|
||||||
// Setup render config with defaults. We won't necessarily use all features
|
#ifdef FASTTRIS
|
||||||
// present in this
|
render.trifunc = H3D_EASYRENDER_FASTFUNC;
|
||||||
haloo3d_trirender rendersettings;
|
#endif
|
||||||
haloo3d_trirender_init(&rendersettings);
|
eprintf("Initialized renderer\n");
|
||||||
|
|
||||||
haloo3d_easytimer frametimer;
|
haloo3d_easytimer frametimer;
|
||||||
haloo3d_easytimer_init(&frametimer);
|
haloo3d_easytimer_init(&frametimer, AVGWEIGHT);
|
||||||
|
|
||||||
// Load the junk + generate stuff
|
// Load the junk + generate stuff
|
||||||
haloo3d_obj *flooro = haloo3d_easystore_addobj(&storage, "floor");
|
haloo3d_obj *flooro = haloo3d_easystore_addobj(&storage, "floor");
|
||||||
@ -75,6 +62,7 @@ int main(int argc, char **argv) {
|
|||||||
uint16_t cols[4] = {0xFD93, 0xFB83, 0xFEEE, 0xFDDD};
|
uint16_t cols[4] = {0xFD93, 0xFB83, 0xFEEE, 0xFDDD};
|
||||||
haloo3d_gen_checkerboard(floort, cols, 2, 32);
|
haloo3d_gen_checkerboard(floort, cols, 2, 32);
|
||||||
haloo3d_gen_checkerboard(ceilt, cols + 2, 2, 32);
|
haloo3d_gen_checkerboard(ceilt, cols + 2, 2, 32);
|
||||||
|
eprintf("Initialized models and textures\n");
|
||||||
|
|
||||||
// Lighting. Note that for performance, the lighting is always calculated
|
// Lighting. Note that for performance, the lighting is always calculated
|
||||||
// against the base model, and is thus not realistic if the object rotates in
|
// against the base model, and is thus not realistic if the object rotates in
|
||||||
@ -84,19 +72,14 @@ int main(int argc, char **argv) {
|
|||||||
struct vec3 light;
|
struct vec3 light;
|
||||||
vec3(light.v, 0, -MCOS(LIGHTANG), MSIN(LIGHTANG));
|
vec3(light.v, 0, -MCOS(LIGHTANG), MSIN(LIGHTANG));
|
||||||
|
|
||||||
int totalfaces = 0;
|
|
||||||
int totalverts = 0;
|
|
||||||
haloo3d_obj_instance *floori =
|
haloo3d_obj_instance *floori =
|
||||||
haloo3d_easyrender_addinstance(&render, flooro, floort);
|
haloo3d_easyrender_addinstance(&render, flooro, floort);
|
||||||
haloo3d_obj_instance *ceili =
|
haloo3d_obj_instance *ceili =
|
||||||
haloo3d_easyrender_addinstance(&render, ceilo, ceilt);
|
haloo3d_easyrender_addinstance(&render, ceilo, ceilt);
|
||||||
|
floori->cullbackface = 0;
|
||||||
// totalfaces += objects[i].model->numfaces;
|
ceili->cullbackface = 0;
|
||||||
// totalverts += objects[i].model->numvertices;
|
ceili->pos.y = 1;
|
||||||
// #ifdef DOLIGHTING
|
eprintf("Setup all object instances\n");
|
||||||
// objects[0].lighting = &light;
|
|
||||||
// objects[2].lighting = &light;
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
unigi_type_event event;
|
unigi_type_event event;
|
||||||
unigi_type_resolution res;
|
unigi_type_resolution res;
|
||||||
@ -104,16 +87,15 @@ int main(int argc, char **argv) {
|
|||||||
res.height = HEIGHT;
|
res.height = HEIGHT;
|
||||||
res.depth = UNIGIBITDEPTH;
|
res.depth = UNIGIBITDEPTH;
|
||||||
|
|
||||||
// Storage stuff
|
|
||||||
haloo3d_facef face, baseface;
|
|
||||||
int totaldrawn = 0;
|
int totaldrawn = 0;
|
||||||
|
|
||||||
eprintf("Scene has %d tris, %d verts\n", totalfaces, totalverts);
|
eprintf("Scene has %d tris, %d verts\n", render.totalfaces,
|
||||||
|
render.totalverts);
|
||||||
|
|
||||||
// Init unigi system
|
// Init unigi system
|
||||||
sprintf(render.printbuf, "scene.exe - %s %s %s", argv[1], argv[2], argv[3]);
|
// sprintf(render.printbuf, "maze.exe - %s %s %s", argv[1], argv[2], argv[3]);
|
||||||
unigi_graphics_init();
|
unigi_graphics_init();
|
||||||
unigi_window_create(res, render.printbuf);
|
unigi_window_create(res, "maze.exe"); // render.printbuf);
|
||||||
|
|
||||||
// -----------------------------------
|
// -----------------------------------
|
||||||
// Actual rendering
|
// Actual rendering
|
||||||
@ -121,7 +103,10 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
haloo3d_easytimer_start(&frametimer);
|
haloo3d_easytimer_start(&frametimer);
|
||||||
|
render.camera.yaw += 0.005;
|
||||||
haloo3d_easyrender_beginframe(&render);
|
haloo3d_easyrender_beginframe(&render);
|
||||||
|
memset(render.window.buffer, 0,
|
||||||
|
sizeof(uint16_t) * render.window.width * render.window.height);
|
||||||
|
|
||||||
unigi_event_get(&event);
|
unigi_event_get(&event);
|
||||||
if (event.type == unigi_enum_event_input_keyboard) {
|
if (event.type == unigi_enum_event_input_keyboard) {
|
||||||
@ -130,55 +115,26 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
totaldrawn = 0;
|
totaldrawn = 0;
|
||||||
|
|
||||||
// camera.pos.x = cams[cami].xofs;
|
|
||||||
// camera.pos.y = cams[cami].yofs;
|
|
||||||
// camera.pos.z = cams[cami].zofs;
|
|
||||||
// camera.yaw = cams[cami].yaw;
|
|
||||||
// camera.pitch = cams[cami].pitch + MPI_2;
|
|
||||||
|
|
||||||
haloo3d_obj_instance *object = NULL;
|
haloo3d_obj_instance *object = NULL;
|
||||||
|
|
||||||
// Iterate over objects
|
// Iterate over objects
|
||||||
while ((object = haloo3d_easyrender_nextinstance(&render, object))) {
|
while ((object = haloo3d_easyrender_nextinstance(&render, object)) !=
|
||||||
|
NULL) {
|
||||||
// Setup final model matrix and the precalced vertices
|
// Setup final model matrix and the precalced vertices
|
||||||
haloo3d_easyrender_beginmodel(&render, object);
|
haloo3d_easyrender_beginmodel(&render, object);
|
||||||
rendersettings.texture = object->texture;
|
|
||||||
// Iterate over object faces
|
// Iterate over object faces
|
||||||
for (int fi = 0; fi < object->model->numfaces; fi++) {
|
for (int fi = 0; fi < object->model->numfaces; fi++) {
|
||||||
// Copy face values out of precalc array and clip them
|
totaldrawn += haloo3d_easyrender_renderface(
|
||||||
haloo3d_make_facef(object->model->faces[fi], render.precalcs,
|
&render, object, fi, DITHERSTART, DITHEREND, MINLIGHT);
|
||||||
object->model->vtexture, face);
|
|
||||||
int tris = haloo3d_facef_clip(face, render.outfaces);
|
|
||||||
if (tris > 0) {
|
|
||||||
haloo3d_easy_calcdither4x4(&rendersettings, face, DITHERSTART,
|
|
||||||
DITHEREND);
|
|
||||||
rendersettings.intensity = 1.0;
|
|
||||||
if (object->lighting) {
|
|
||||||
haloo3d_obj_facef(object->model, object->model->faces[fi],
|
|
||||||
baseface);
|
|
||||||
rendersettings.intensity =
|
|
||||||
haloo3d_calc_light(object->lighting->v, MINLIGHT, baseface);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int ti = 0; ti < tris; ti++) {
|
|
||||||
int backface = !haloo3d_facef_finalize(render.outfaces[ti]);
|
|
||||||
if (object->cullbackface && backface) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
totaldrawn++;
|
|
||||||
// We still have to convert the points into the view
|
|
||||||
haloo3d_facef_viewport_into(render.outfaces[ti], WIDTH, HEIGHT);
|
|
||||||
TRIFUNC(&render.window, &rendersettings, render.outfaces[ti]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
haloo3d_print(&render.tprint,
|
haloo3d_print(&render.tprint,
|
||||||
"Last frame: %05.2f (%05.2f)\nTris: %d / %d\nVerts: %d\n",
|
"Last frame: %05.2f (%05.2f)\nTris: %d / %d\nVerts: %d\n",
|
||||||
frametimer.last * 1000, frametimer.sum * 1000, totaldrawn,
|
frametimer.last * 1000, frametimer.sum * 1000, totaldrawn,
|
||||||
totalfaces, totalverts);
|
render.totalfaces, render.totalverts);
|
||||||
|
|
||||||
unigi_graphics_blit(0, (unigi_type_color *)&render.window,
|
unigi_graphics_blit(0, (unigi_type_color *)render.window.buffer,
|
||||||
res.width * res.height);
|
res.width * res.height);
|
||||||
unigi_graphics_flush();
|
unigi_graphics_flush();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user