Compare commits

...

2 commits

Author SHA1 Message Date
attilavs2
12df54420b fx : Rendu réparé et début dscale_bopti 2024-09-26 20:47:04 +02:00
attilavs2
950a7b5631 fx : Première version propre 2024-09-26 19:09:33 +02:00
5 changed files with 81 additions and 60 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
# Build files
/build-fx
/build-fxg3a
/build-cg
/build-cg-push
/*.g1a

View file

@ -5,6 +5,7 @@ cmake_minimum_required(VERSION 3.15)
project(Copy3DEngine LANGUAGES C ASM)
include(GenerateG1A)
include(GenerateG3A)
include(Fxconv)
find_package(Gint 2.9 REQUIRED)
find_package(LibProf 2.1 REQUIRED)
@ -39,4 +40,7 @@ target_link_options(Copy3DEngine PRIVATE -Wl,--print-memory-usage)
if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G)
generate_g1a(TARGET Copy3DEngine OUTPUT ${NAMEOFGAME}".g1a"
NAME ${NAMEOFGAME} ICON assets-fx/icon.png)
else()
generate_g3a(TARGET Copy3DEngine OUTPUT ${NAMEOFGAME}".g3a"
NAME ${NAMEOFGAME} ICONS assets-fx/icon.png assets-fx/icon.png)
endif()

View file

@ -72,26 +72,6 @@ void keys_get(){
#endif
}
bopti_image_t *bopti_make(int width, int height, int8_t fill){
//Make it so fill == 0xFF or 0x00
if(fill)
fill = 0xFF;
bopti_image_t *image = malloc(sizeof(bopti_image_t)+(width*height)/8+1);
image->data = (void*)image+sizeof(bopti_image_t);
image->gray = 0;
image->profile = IMAGE_MONO;
image->width = width;
image->height = height;
memset(image->data, fill, (width*height)/8+1);
return image;
}
void bopti_free(bopti_image_t *image){
free(image);
}
void main_menu(){
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);
@ -118,26 +98,21 @@ int main(){
prof_init();
dtext(0,0,C_BLACK,"Activer le mode de gris ?");
dtext(0,10,C_BLACK,"Enable grayscale ?");
dtext(0,20,C_BLACK,"F1 : Oui/Yes");
dtext(0,30,C_BLACK,"F2 : Non/No");
if(dgray(DGRAY_ON))
goto c3d_abort;
dupdate();
dclear(C_WHITE);
dscale_bopti(&briques0, fix(2), fix(2), 0, 0);
/*dimage(0,0,tex_index[0]);
dimage(32,0,tex_index[1]);
dimage(64,0,tex_index[2]);
dimage(96,0,tex_index[3]);*/
dupdate();
key_event_t keyev = getkey();
if(keyev.key == KEY_F1){
if(dgray(DGRAY_ON))
goto c3d_abort;
dupdate();
dimage(0,0,tex_index[0]);
dimage(32,0,tex_index[1]);
dimage(64,0,tex_index[2]);
dimage(96,0,tex_index[3]);
dupdate();
getkey();
}
getkey();
#if debug
EngineTimers timers;

View file

@ -172,32 +172,67 @@ void load_map(){
#if asm_opti
#else
inline void __attribute__((always_inline)) draw_stripe(bopti_image_t *tex, int texSampleY,
int linePos, fixed_t texSize, int texX, int x){
uint32_t *light, *dark;
dgray_getvram(&light,&dark);
//Fonction fournie par le grand Lephe :D
inline int __attribute__((always_inline))
get_pixel(bopti_image_t const *img, int u, int v)
{
int layers = 2;
int columns = (img->width + 31) >> 5;
struct rbox pxbox = {
.x = (texX&31)-(x&31),
.visual_x = x,
.width = 1,
.left = texX,
.columns = 1,
.height = 1
};
uint32_t const *layer_ptr = (void *)img->data;
layer_ptr += (v * columns + (u >> 5)) * layers;
uint32_t mask = 0x80000000u >> (u & 31);
int light = (layer_ptr[0] & mask) != 0;
int dark = (layer_ptr[1] & mask) != 0;
return (dark << 1) + light;
}
uint32_t *light, *dark;
void dscale_bopti(bopti_image_t *tex, fixed_t scale_x, fixed_t scale_y, int x, int y){
fixed_t screen_x = x;
fixed_t screen_y = y;
for(fixed_t tex_y = 0; tex_y < fix(tex->height); tex_y+=scale_y){
yloop:
;//For clangd which doesn't like the label (?)
fixed_t oldy = screen_y;
screen_y += scale_y;
if(screen_y >= 64)
break;
for(; oldy < screen_x; oldy += 0xFFFF){
for(fixed_t tex_x = 0; tex_x < fix(tex->width); tex_x+=scale_x){
fixed_t oldx = screen_x;
screen_x += scale_x;
if(screen_x >= 128)
goto yloop;
int tpix = get_pixel(tex, tex_x, tex_y);
for(; oldx < screen_x; oldx += 0xFFFF){
dpixel(screen_x, screen_y, tpix);
}
screen_x = oldx;
}
}
screen_y = oldy;
}
}
inline void __attribute__((always_inline))
draw_stripe(bopti_image_t *tex, int texSampleY, int linePos, fixed_t texSize,
int texX, int x){
fixed_t screenPos = fix(linePos);
for(int texPos = texSampleY; texPos < TSIZE; ++texPos){
if(screenPos >= 0){
fixed_t oldPos = screenPos;
pxbox.top = texPos;
int tpix = get_pixel(tex, texX, texPos);
do{
if(screenPos >= fix(viewport_h))
return;
pxbox.y = ffloor(oldPos);
bopti_render_scsp(tex,&pxbox,light,dark);
dpixel(x, ffloor(oldPos), tpix);
oldPos += 0xFFFF;
} while(oldPos < screenPos+texSize);
} while(oldPos <= screenPos+texSize);
}
screenPos += texSize;
}
@ -239,6 +274,8 @@ void draw_walls(
int texSample;
int texSampleY;
dgray_getvram(&light,&dark);
int v_offset = 0; //(int)(sin(f2int(posX + posY)) * 5); //a raffiner un peu
fixed_t h_offset = 0; //fix(sin(f2int(posX - posY)) * 0.01);
@ -355,13 +392,13 @@ void draw_walls(
lineHeight = f2int(fdiv(fix(viewport_h), perpWallDist)); //Taille en px de la ligne
if (lineHeight < 1) lineHeight = 1;
if (lineHeight > viewport_h) lineHeight = viewport_h - 1;
//if (lineHeight > viewport_h) lineHeight = viewport_h - 1;
fixed_t texSize = fix(lineHeight) / TSIZE; //taille proportionelle de la ligne a la tex
if (texSize < fix(1.0/(float)TSIZE)) texSize = fix(1.0/(float)TSIZE); //0x400 = 1/64 * 2^16
if (texSize > fix((float)viewport_h/(float)TSIZE)) { //0x3D000 = 3.8125 * 2^16, 3.8125 = viewport_h/64
if (texSize < fix(1.0/(float)TSIZE)) texSize = fix(1.0/(float)TSIZE);
if (texSize > fix((float)viewport_h/(float)TSIZE)) {
texSample = fceil(fdiv(fix(viewport_h), texSize));
texSampleY = TSIZE/2 - texSample/2;
texSampleY = TSIZE/2 - texSample/2;
}
else {
texSample = TSIZE;

View file

@ -12,7 +12,7 @@
#define screen_h 64
#define viewport_w 128
#define viewport_h 64
#define max_dist fix(32) //en tuiles << 16, actuellement 32
#define max_dist fix(32)
#define TSIZE 32
@ -29,7 +29,11 @@ typedef struct {
} EngineTimers;
void draw_stripe(bopti_image_t *tex, int texSampleY, int linePos, fixed_t texSize, int texX, int x);
void dscale_bopti(bopti_image_t *tex, fixed_t scale_x, fixed_t scale_y,
int x, int y);
void draw_stripe(bopti_image_t *tex, int texSampleY, int linePos,
fixed_t texSize, int texX, int x);
void load_map();
void end_screen();