somehow got this to work at >1000 FPS

This commit is contained in:
Alexandre 2025-01-05 12:00:07 +01:00
parent 4049af7b4b
commit 2997f77c40
10 changed files with 12 additions and 18 deletions

View File

@ -1,5 +1,5 @@
CC = gcc
FLAGS = -Wall -Wextra -Wpedantic -g
FLAGS = -O2 -Wall -Wextra -Wpedantic -g
LFLAGS = -lSDL2 -lSDL2_image -lm -lncurses
all: bin/back

BIN
bin/back

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -386,6 +386,13 @@ SDL_Vertex construct_vertex(double px, double py, int r, int g, int b) {
return vtx ;
}
double px0; double py0; double pz0;
double px1; double py1; double pz1;
double px2; double py2; double pz2;
double fpx0; double fpy0; double fpz0;
double fpx1; double fpy1; double fpz1;
double mpx0; double mpy0; double mpz0;
double mpx1; double mpy1; double mpz1;
void renderTriangle(
SDL_Renderer* renderer,
double x0, double y0, double z0,
@ -393,9 +400,6 @@ void renderTriangle(
double x2, double y2, double z2,
int red, int green, int blue
) {
double px0; double py0; double pz0;
double px1; double py1; double pz1;
double px2; double py2; double pz2;
project_to_camera(x0, y0, z0, &px0, &py0, &pz0);
project_to_camera(x1, y1, z1, &px1, &py1, &pz1);
project_to_camera(x2, y2, z2, &px2, &py2, &pz2);
@ -407,10 +411,6 @@ void renderTriangle(
};
SDL_RenderGeometry(renderer, NULL, vtxs, 3, NULL, 0);
} else if((pz0 >= draw_constant) + (pz1 >= draw_constant) + (pz2 >= draw_constant) == 2) {
double fpx0; double fpy0; double fpz0;
double fpx1; double fpy1; double fpz1;
double mpx0; double mpy0; double mpz0;
double mpx1; double mpy1; double mpz1;
if(pz0 < draw_constant) {
// pz1 >= draw_constant and pz2 >+ draw_constant
fpx0 = px1 ; fpy0 = py1 ; fpz0 = pz1 ;
@ -445,7 +445,7 @@ void renderTriangle(
convex_pt(y2, y1, (pz2 - draw_constant)/(pz2 - pz1)),
convex_pt(z2, z1, (pz2 - draw_constant)/(pz2 - pz1)),
&mpx1, &mpy1, &mpz1) ;
} else if(pz2 < draw_constant) {
} else /*if(pz2 < draw_constant)*/ {
// pz1 >= draw_constant and pz0 >+ draw_constant
fpx0 = px0 ; fpy0 = py0 ; fpz0 = pz0 ;
fpx1 = px1 ; fpy1 = py1 ; fpz1 = pz1 ;
@ -525,9 +525,9 @@ void renderTriangleRotated(
int red, int green, int blue,
cube_0 cb
) {
double px0; double py0; double pz0;
/*double px0; double py0; double pz0;
double px1; double py1; double pz1;
double px2; double py2; double pz2;
double px2; double py2; double pz2;*/
rotate_cube(x0, y0, z0, &px0, &py0, &pz0, cb);
rotate_cube(x1, y1, z1, &px1, &py1, &pz1, cb);
rotate_cube(x2, y2, z2, &px2, &py2, &pz2, cb);
@ -630,15 +630,9 @@ void drawCurrentRoom(SDL_Renderer* renderer) {
insertionSort_cb(current_room->map, current_room->map_size);
insertionSort_tp(current_room->tps, current_room->tps_size);
for(int k = 0; k < current_room->map_size; k++) {
SDL_SetRenderDrawColor(renderer, current_room->map[k].red/2, current_room->map[k].green/2, current_room->map[k].blue/2, 255);
drawOutlineOfCube_0(renderer, current_room->map[k]);
drawFullCube(renderer, current_room->map[k]);
}
for(int k = 0; k < current_room->tps_size; k++) {
SDL_SetRenderDrawColor(renderer, current_room->tps[k].hitbox.red/2, current_room->tps[k].hitbox.green/2, current_room->tps[k].hitbox.blue/2, 255);
drawOutlineOfCube_0(renderer, current_room->tps[k].hitbox);
drawFullCube(renderer, current_room->tps[k].hitbox);
}
}

View File

@ -14,6 +14,6 @@ Teleporters :
[-5.0, 1.0, 9.0, 10.0, 2.0, 1.0, 0.0, 0.0, 0, 0, 255; 1, 0]
Weight :
10
30
$