Compare commits

..

No commits in common. "886fdb19c04bcfc7119302d3fd14d0f0134f5a7d" and "61c4ca9135247604f9cb6fcd42209e8cca7f33f5" have entirely different histories.

5 changed files with 23 additions and 57 deletions

View file

@ -28,11 +28,11 @@ set(ASSETS
fxconv_declare_assets(${ASSETS} WITH_METADATA)
add_executable(Copy3DEngine ${SOURCES} ${ASSETS})
target_compile_options(Copy3DEngine PRIVATE -Wall -Wextra -Ofast)
target_compile_options(Copy3DEngine PRIVATE -Wall -Wextra -Ofast -fira-region=all -flto -fno-math-errno -funsafe-math-optimizations -fassociative-math -freciprocal-math)
target_compile_definitions(Copy3DEngine PRIVATE NAMEOFGAME="${NAMEOFGAME}" AUTHOR="${AUTHOR}")
target_link_libraries(Copy3DEngine Gint::Gint)
target_link_libraries(Copy3DEngine LibProf::LibProf)
target_link_options(Copy3DEngine PRIVATE -Wl,--print-memory-usage)
target_link_options(Copy3DEngine PRIVATE -Wl,--print-memory-usage,-flto)
if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
generate_g3a(TARGET Copy3DEngine OUTPUT "${NAMEOFGAME}.g3a"

View file

@ -9,10 +9,6 @@
typedef int32_t fixed_t;
/* Standard arithmetic. */
typedef struct {
int32_t x ,y;
} V2d;
static inline fixed_t fmul(fixed_t left, fixed_t right)
{
/* Generally optimized by the compiler to use dmuls.l and xtrct */
@ -89,17 +85,3 @@ static inline fixed_t fease(fixed_t x)
return fix(1) - 2 * fmul(x, x);
}
}
static inline fixed_t fV2d_dotp(V2d u, V2d v){
return fmul(u.x,v.x) + fmul(u.y,v.y);
}
static inline uint16_t mul_color(uint16_t color, fixed_t multpl){
int r = color & 31;
int g = (color>>5) & 63;
int b = (color>>11) & 31;
r *= multpl;
g *= multpl;
b *= multpl;
return (ffloor(b)<<11) | (ffloor(g)<<5) | r;
}

View file

@ -78,8 +78,8 @@ void keys_get(){
}
void main_menu(){
dtext_opt(198, 100, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Demo 3D", -1);
dtext_opt(198, 120, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "De Fcalva", -1);
//dtext_opt(198, 100, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, NAMEOFGAME, -1);
//dtext_opt(198, 120, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "De " AUTHOR, -1);
dtext_opt(198, 150, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Appuyez sur une touche", -1);
dupdate();
@ -119,9 +119,9 @@ int main(){
dma_memset((void*)((uint32_t)gint_vram + viewport_w*viewport_h),
0xc4c9c4c9, viewport_w*viewport_h);
draw_walls();
draw_walls(frame_buffer);
if(first_frame){
if(first_frame == 1){
main_menu();
}

View file

@ -11,7 +11,6 @@
#include "fixed.h"
#include "gint/display-cg.h"
#include "moteur.h"
#include "map.h"
@ -43,20 +42,20 @@ void move() {
int ytemp2;
if (keydown(KEY_UP)) {
xtemp1 = f2int(posX + fmul(dirX, moveSpeed) - 0xF);
xtemp1 = f2int(posX + fmul(dirX, moveSpeed));
ytemp1 = f2int(posY);
xtemp2 = f2int(posX);
ytemp2 = f2int(posY + fmul(dirY, moveSpeed) - 0xF);
ytemp2 = f2int(posY + fmul(dirY, moveSpeed));
if(map_test[xtemp1][ytemp1] == 0) posX += fmul(dirX, moveSpeed);
if(map_test[xtemp2][ytemp2] == 0) posY += fmul(dirY, moveSpeed);
}
//move backwards if no wall behind you
if (keydown(KEY_DOWN)) {
xtemp1 = f2int(posX - fmul(dirX, moveSpeed) + 0xF);
xtemp1 = f2int(posX - fmul(dirX, moveSpeed));
ytemp1 = f2int(posY);
xtemp2 = f2int(posX);
ytemp2 = f2int(posY - fmul(dirY, moveSpeed) + 0xF);
ytemp2 = f2int(posY - fmul(dirY, moveSpeed));
if(map_test[xtemp1][ytemp1] == 0) posX -= fmul(dirX, moveSpeed);
if(map_test[xtemp2][ytemp2] == 0) posY -= fmul(dirY, moveSpeed);
@ -167,21 +166,7 @@ void load_map(){
spawn_gen();
}
void draw_stripe(image_t *tex, int texSampleY, int texSample, int linePos, fixed_t texSize, int texX, int x){
fixed_t screenPos = fix(linePos);
uint32_t texDat = (uint32_t)tex->data + 2*texX;
for(int texPos = texSampleY; texPos < 64; texPos++){
if(screenPos < -texSize) goto noDraw;
for(fixed_t oldPos = screenPos; oldPos < screenPos+texSize; oldPos+=0xFFFF){
gint_vram[ffloor(oldPos)*396+x] = *(uint16_t*)texDat;
}
noDraw:
screenPos += texSize;
texDat += tex->stride;
}
}
void draw_walls(){
void draw_walls(image_t *frame_buffer){
extern fixed_t posX;
extern fixed_t posY;
extern fixed_t dirX;
@ -201,7 +186,6 @@ void draw_walls(){
fixed_t perpWallDist;
fixed_t texSize;
int x;
int i;
int mapX;
int mapY;
int stepX; //what direction to step in x or y-direction (either +1 or -1)
@ -241,13 +225,11 @@ void draw_walls(){
// stepping further below works. So the values can be computed as below.
// Division through zero is prevented, even though technically that's not
// needed in C++ with IEEE 754 floating point values.
rayDirX = rayDirX == 0 ? 1 : rayDirX;
rayDirY = rayDirY == 0 ? 1 : rayDirY;
// Fcalva : removed the 0 div prevention
deltaDistX = abs(fdiv(0xFFFF, rayDirX));
deltaDistY = abs(fdiv(0xFFFF, rayDirY));
//calculate step and initial sideDist
if (rayDirX < 0) {
stepX = -1;
@ -303,6 +285,7 @@ void draw_walls(){
else perpWallDist = (sideDistY - deltaDistY);
//texturing calculations
//int texNum = test_map[mapX][mapY] - 1; //a voir plus tard
//calculate value of wallX
fixed_t wallX; //where exactly the wall was hit
@ -325,17 +308,18 @@ void draw_walls(){
if (texSize < 0x400) texSize = 0x400; //0x400 = 1/64 * 2^16
if (texSize > 0x3D000) { //0x3D000 = 3.8125 * 2^16, 3.8125 = viewport_h/64
texSample = fceil(fdiv(fix(viewport_h), texSize));
texSampleY = 32 - texSample/2;
texSampleY = 32 - (int)texSample * 0.5;
}
else {
texSample = 64;
texSampleY = 0;
}
image_t texStripe;
int linePos = viewport_h/2 - lineHeight/2;
texStripe = *image_sub(tex_index[map_test[mapX][mapY]], texX, texSampleY, 1, texSample);
image_t *tex = tex_index[map_test[mapX][mapY]];
draw_stripe(tex, texSampleY, texSample, linePos, texSize, texX, x);
}
image_scale(&texStripe, 0xFFFF, texSize, &temp);
image_linear(&texStripe, image_at(frame_buffer, x, (int)(viewport_h * 0.5 - lineHeight * 0.5) + v_offset), &temp);
}
}

View file

@ -10,13 +10,13 @@
#define screen_h 224
#define viewport_w 396
#define viewport_h 224
#define max_dist fix(32) //en tuiles << 16, actuellement 32
#define max_dist 0x1FFFFF //en tuiles << 16, actuellement 32
#define TINDEX_S 256
void load_map();
void end_screen();
void draw_walls();
void draw_walls(image_t *frame_buffer);
void move();
#endif /* moteur */