Merge pull request 'dev' (#1) from dev into master

Reviewed-on: https://git.planet-casio.com///Fcalva/Copy3DEngine/pulls/1
This commit is contained in:
Fcalva 2024-08-09 19:21:14 +02:00
commit 886fdb19c0
5 changed files with 57 additions and 23 deletions

View file

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

View file

@ -9,6 +9,10 @@
typedef int32_t fixed_t; typedef int32_t fixed_t;
/* Standard arithmetic. */ /* Standard arithmetic. */
typedef struct {
int32_t x ,y;
} V2d;
static inline fixed_t fmul(fixed_t left, fixed_t right) static inline fixed_t fmul(fixed_t left, fixed_t right)
{ {
/* Generally optimized by the compiler to use dmuls.l and xtrct */ /* Generally optimized by the compiler to use dmuls.l and xtrct */
@ -85,3 +89,17 @@ static inline fixed_t fease(fixed_t x)
return fix(1) - 2 * fmul(x, 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(){ void main_menu(){
//dtext_opt(198, 100, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, NAMEOFGAME, -1); 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 " AUTHOR, -1); dtext_opt(198, 120, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "De Fcalva", -1);
dtext_opt(198, 150, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Appuyez sur une touche", -1); dtext_opt(198, 150, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Appuyez sur une touche", -1);
dupdate(); dupdate();
@ -119,9 +119,9 @@ int main(){
dma_memset((void*)((uint32_t)gint_vram + viewport_w*viewport_h), dma_memset((void*)((uint32_t)gint_vram + viewport_w*viewport_h),
0xc4c9c4c9, viewport_w*viewport_h); 0xc4c9c4c9, viewport_w*viewport_h);
draw_walls(frame_buffer); draw_walls();
if(first_frame == 1){ if(first_frame){
main_menu(); main_menu();
} }

View file

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

View file

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