fx : port fx ""fonctionel""
|
@ -4,7 +4,7 @@
|
|||
cmake_minimum_required(VERSION 3.15)
|
||||
project(Copy3DEngine LANGUAGES C ASM)
|
||||
|
||||
include(GenerateG3A)
|
||||
include(GenerateG1A)
|
||||
include(Fxconv)
|
||||
find_package(Gint 2.9 REQUIRED)
|
||||
find_package(LibProf 2.1 REQUIRED)
|
||||
|
@ -22,20 +22,21 @@ set(SOURCES
|
|||
)
|
||||
|
||||
set(ASSETS
|
||||
assets-cg/textures/briques0.png
|
||||
assets-cg/textures/buisson1.png
|
||||
assets-fx/textures/briques0.png
|
||||
assets-fx/textures/buisson1.png
|
||||
)
|
||||
|
||||
fxconv_declare_assets(${ASSETS} WITH_METADATA)
|
||||
|
||||
add_executable(Copy3DEngine ${SOURCES} ${ASSETS})
|
||||
target_compile_options(Copy3DEngine PRIVATE -Wall -Wextra -Ofast)
|
||||
#the -I is an ugly hack because lephe won't let us use render-fx.h >:(
|
||||
target_compile_options(Copy3DEngine PRIVATE -flto -Wall -Wextra -Ofast -I "$ENV{HOME}/.local/share/giteapc/Lephenixnoir/gint/src/render-fx/")
|
||||
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)
|
||||
|
||||
if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
|
||||
generate_g3a(TARGET Copy3DEngine OUTPUT "${NAMEOFGAME}.g3a"
|
||||
NAME "${NAMEOFGAME}" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png)
|
||||
if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G)
|
||||
generate_g1a(TARGET Copy3DEngine OUTPUT ${NAMEOFGAME}".g1a"
|
||||
NAME ${NAMEOFGAME} ICON assets-fx/icon.png)
|
||||
endif()
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
zombard1.png:
|
||||
type: bopti-image
|
||||
name: zombard
|
||||
skybox0.png:
|
||||
type: bopti-image
|
||||
name: skybox_quarter
|
Before Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 31 KiB |
0
assets-fx/fxconv-metadata.txt
Normal file
BIN
assets-fx/icon.png
Normal file
After Width: | Height: | Size: 7.3 KiB |
BIN
assets-fx/textures/briques0.png
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
assets-fx/textures/buisson1.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
86
src/main.c
|
@ -1,15 +1,18 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <gint/display.h>
|
||||
#include <gint/keyboard.h>
|
||||
#include <gint/image.h>
|
||||
#include <gint/gray.h>
|
||||
#include <gint/dma.h>
|
||||
#include <gint/gdb.h>
|
||||
#include <libprof.h>
|
||||
|
||||
#include "fixed.h"
|
||||
|
||||
#include "gint/display-fx.h"
|
||||
#include "moteur.h"
|
||||
#include "map.h"
|
||||
|
||||
|
@ -23,18 +26,14 @@
|
|||
//
|
||||
//
|
||||
|
||||
#ifndef FXCG50
|
||||
#error Ce code est pour FXCG50/G90+E uniquement, enlevez ce message a vos riques et périls
|
||||
#endif
|
||||
|
||||
image_t *tex_index[TINDEX_S];
|
||||
bopti_image_t *tex_index[TINDEX_S];
|
||||
|
||||
extern char map_test[map_w][map_h];
|
||||
|
||||
//Vos images ici
|
||||
|
||||
extern image_t briques0;
|
||||
extern image_t buisson0;
|
||||
extern bopti_image_t briques0;
|
||||
extern bopti_image_t buisson0;
|
||||
|
||||
char exit_game = 0;
|
||||
char disp_frame_time = 0;
|
||||
|
@ -73,9 +72,29 @@ 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, "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();
|
||||
|
@ -89,21 +108,26 @@ int main(){
|
|||
|
||||
load_map();
|
||||
|
||||
extern image_t *tex_index[TINDEX_S];
|
||||
|
||||
tex_index[1] = &buisson0;
|
||||
tex_index[2] = &briques0;
|
||||
|
||||
//Vos textures générées procéduralement
|
||||
|
||||
tex_index[0] = image_alloc(64, 64, IMAGE_RGB565);
|
||||
tex_index[3] = image_alloc(64, 64, IMAGE_RGB565);
|
||||
|
||||
image_fill(tex_index[0], 0x4228);
|
||||
image_fill(tex_index[3], 0x9dbd);
|
||||
tex_index[0] = &briques0;//bopti_make(64,64,1);
|
||||
tex_index[3] = &briques0;//bopti_make(64, 64,0);
|
||||
|
||||
prof_init();
|
||||
|
||||
if(dgray(DGRAY_ON))
|
||||
goto c3d_abort;
|
||||
dupdate();
|
||||
|
||||
dimage(0,0,&briques0);
|
||||
dimage(63,0,&buisson0);
|
||||
|
||||
dupdate();
|
||||
getkey();
|
||||
|
||||
#if debug
|
||||
EngineTimers timers;
|
||||
#endif
|
||||
|
@ -112,10 +136,7 @@ int main(){
|
|||
prof_t frame = prof_make();
|
||||
prof_enter(frame);
|
||||
|
||||
//Big brain drect()
|
||||
dma_memset(gint_vram, 0x9dbd9dbd, viewport_w*viewport_h);
|
||||
dma_memset((void*)((uint32_t)gint_vram + viewport_w*viewport_h),
|
||||
0xc4c9c4c9, viewport_w*viewport_h);
|
||||
dclear(C_WHITE);
|
||||
|
||||
if(first_frame){
|
||||
main_menu();
|
||||
|
@ -129,17 +150,17 @@ int main(){
|
|||
#endif
|
||||
);
|
||||
|
||||
if (disp_frame_time == 1) dprint( 1, 10, C_BLACK, "Frame time : %d ms", frame_time);
|
||||
if (disp_frame_time == 1) dprint( 0, 0, C_BLACK, "%d ms", frame_time);
|
||||
|
||||
#if debug
|
||||
dprint( 1, 20, C_BLACK, "planeX : %d", planeX);
|
||||
dprint( 1, 30, C_BLACK, "planeY : %d", planeY);
|
||||
dprint( 1, 40, C_BLACK, "dirX : %d", dirX);
|
||||
dprint( 1, 50, C_BLACK, "dirY : %d", dirY);
|
||||
dprint( 1, 60, C_BLACK, "posX : %d", posX);
|
||||
dprint( 1, 70, C_BLACK, "posY : %d", posY);
|
||||
dprint( 1, 80, C_BLACK, "Raycast time : %d", prof_time(timers.raycast_time));
|
||||
dprint( 1, 90, C_BLACK, "Draw time : %d", prof_time(timers.draw_time));
|
||||
dprint( 1, 9, C_BLACK, "plX %d", planeX);
|
||||
dprint( 1, 18, C_BLACK, "plY %d", planeY);
|
||||
dprint( 1, 27, C_BLACK, "dX %d", dirX);
|
||||
dprint( 1, 36, C_BLACK, "dY %d", dirY);
|
||||
dprint( 1, 45, C_BLACK, "pX %d", posX);
|
||||
dprint( 1, 54, C_BLACK, "pY %d", posY);
|
||||
dprint( 1, 63, C_BLACK, "Rct %d", prof_time(timers.raycast_time));
|
||||
dprint( 1, 72, C_BLACK, "Dt %d", prof_time(timers.draw_time));
|
||||
timers.raycast_time = prof_make();
|
||||
timers.draw_time = prof_make();
|
||||
#endif
|
||||
|
@ -149,13 +170,16 @@ int main(){
|
|||
frame_time = (int)prof_time(frame)/1000;
|
||||
first_frame = 0;
|
||||
}
|
||||
c3d_abort:
|
||||
|
||||
dgray(DGRAY_OFF);
|
||||
|
||||
prof_quit();
|
||||
|
||||
//Libérez vos textures générées procéduralement
|
||||
|
||||
image_free(tex_index[0]);
|
||||
image_free(tex_index[3]);
|
||||
//bopti_free(tex_index[0]);
|
||||
//bopti_free(tex_index[3]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "map.h"
|
||||
#include "moteur.h"
|
||||
|
||||
char map_test[map_w][map_h] = {
|
||||
char __attribute__((section(".rodata"))) map_test[map_w][map_h] = {
|
||||
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
|
||||
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3},
|
||||
{1,0,1,0,1,0,0,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,1,0,0,0,0,0,1,1,1,1,1,0,1,0,0,1,0,1,1,1,0,1,0,1,1,0,1,0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,1,0,2,0,2,0,0,2,0,0,0,0,2,0,0,2,0,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3},
|
||||
|
|
71
src/moteur.c
|
@ -7,11 +7,14 @@
|
|||
|
||||
#include <gint/display.h>
|
||||
#include <gint/keyboard.h>
|
||||
#include "render-fx.h"
|
||||
#include <gint/gray.h>
|
||||
#include <libprof.h>
|
||||
|
||||
#include "fixed.h"
|
||||
|
||||
#include "gint/display-cg.h"
|
||||
#include "gint/display-fx.h"
|
||||
#include "moteur.h"
|
||||
#include "map.h"
|
||||
|
||||
|
@ -169,33 +172,34 @@ void load_map(){
|
|||
|
||||
#if asm_opti
|
||||
#else
|
||||
inline void __attribute__((always_inline)) draw_stripe(image_t *tex, int texSampleY,
|
||||
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);
|
||||
|
||||
struct rbox pxbox = {
|
||||
.x = x-texX,
|
||||
.visual_x = x,
|
||||
.width = 1,
|
||||
.left = texX,
|
||||
.columns = 1,
|
||||
.height = 1
|
||||
};
|
||||
|
||||
fixed_t screenPos = fix(linePos);
|
||||
uint32_t texDat = (uint32_t)tex->data + 2*texX;
|
||||
register int vramSize asm("r2") = 396;
|
||||
register int oneConst asm("r12");
|
||||
asm("mov #-1, r12\n"
|
||||
"extu.w r12, r12"
|
||||
: "=r" (oneConst)
|
||||
: "r" (oneConst)
|
||||
);
|
||||
register int maxConst asm("r13") = viewport_w*viewport_h;
|
||||
for(int texPos = texSampleY; texPos < 64; ++texPos){
|
||||
if(screenPos >= -texSize){
|
||||
int vrampos = ffloor(screenPos)*vramSize+x;
|
||||
for(int texPos = texSampleY; texPos < TSIZE; ++texPos){
|
||||
if(screenPos >= 0){
|
||||
fixed_t oldPos = screenPos;
|
||||
int16_t pix = *(int16_t*)texDat;
|
||||
pxbox.top = texPos;
|
||||
do{
|
||||
gint_vram[vrampos] = pix;
|
||||
vrampos += vramSize;
|
||||
oldPos += oneConst;
|
||||
if(vrampos >= maxConst)
|
||||
if(screenPos >= fix(viewport_h))
|
||||
return;
|
||||
}while(oldPos < screenPos+texSize);
|
||||
pxbox.y = ffloor(oldPos);
|
||||
bopti_render(tex,&pxbox,light,dark);
|
||||
oldPos += 0xFFFF;
|
||||
} while(oldPos < screenPos+texSize);
|
||||
}
|
||||
screenPos += texSize;
|
||||
texDat += tex->stride;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -211,7 +215,7 @@ void draw_walls(
|
|||
extern fixed_t dirY;
|
||||
extern fixed_t planeX;
|
||||
extern fixed_t planeY;
|
||||
extern image_t *tex_index[TINDEX_S];
|
||||
extern bopti_image_t *tex_index[TINDEX_S];
|
||||
extern char map_test[map_w][map_h];
|
||||
|
||||
fixed_t cameraX;
|
||||
|
@ -238,7 +242,7 @@ void draw_walls(
|
|||
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);
|
||||
|
||||
struct image_linear_map temp;
|
||||
//struct image_linear_map temp;
|
||||
|
||||
for(x = 0; x < viewport_w; x++) {
|
||||
#if debug
|
||||
|
@ -343,32 +347,35 @@ void draw_walls(
|
|||
wallX -= fix(floor(f2int(wallX)));
|
||||
|
||||
//x coordinate on the texture
|
||||
texX = fmul(wallX, 64);
|
||||
texX = texX % 64;
|
||||
texX = fmul(wallX, TSIZE);
|
||||
texX %= TSIZE;
|
||||
|
||||
if(side == 0 && rayDirX > 0) texX = 64 - texX - 1;
|
||||
if(side == 1 && rayDirY < 0) texX = 64 - texX - 1;
|
||||
|
||||
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) / 64; //taille proportionelle de la ligne a la tex
|
||||
if (texSize < 0x400) texSize = 0x400; //0x400 = 1/64 * 2^16
|
||||
if (texSize > 0x3D000) { //0x3D000 = 3.8125 * 2^16, 3.8125 = viewport_h/64
|
||||
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
|
||||
texSample = fceil(fdiv(fix(viewport_h), texSize));
|
||||
texSampleY = 32 - texSample/2;
|
||||
texSampleY = TSIZE/2 - texSample/2;
|
||||
}
|
||||
else {
|
||||
texSample = 64;
|
||||
texSample = TSIZE;
|
||||
texSampleY = 0;
|
||||
}
|
||||
|
||||
int linePos = viewport_h/2 - lineHeight/2;
|
||||
|
||||
image_t *tex = tex_index[map_test[mapX][mapY]];
|
||||
bopti_image_t *tex = tex_index[map_test[mapX][mapY]];
|
||||
|
||||
draw_stripe(tex, texSampleY, linePos, texSize, texX, x);
|
||||
//dline(x, linePos, x, linePos+lineHeight, color);
|
||||
|
||||
draw_stripe(tex_index[map_test[mapX][mapY]], texSampleY, linePos,
|
||||
texSize, texX, x);
|
||||
|
||||
#if debug
|
||||
prof_leave(timers->draw_time);
|
||||
|
|
19
src/moteur.h
|
@ -3,17 +3,20 @@
|
|||
#ifndef moteur_h
|
||||
#define moteur_h
|
||||
|
||||
#include "libprof.h"
|
||||
#include <gint/image.h>
|
||||
#include <libprof.h>
|
||||
#include <gint/display.h>
|
||||
#include "fixed.h"
|
||||
|
||||
//param. graphiques
|
||||
#define screen_w 396
|
||||
#define screen_h 224
|
||||
#define viewport_w 396
|
||||
#define viewport_h 224
|
||||
#define screen_w 128
|
||||
#define screen_h 64
|
||||
#define viewport_w 128
|
||||
#define viewport_h 64
|
||||
#define max_dist fix(32) //en tuiles << 16, actuellement 32
|
||||
|
||||
#define TINDEX_S 256
|
||||
#define TSIZE 32
|
||||
|
||||
#define TINDEX_S 16
|
||||
|
||||
#define debug 0 //pour afficher les infos de debug
|
||||
|
||||
|
@ -26,7 +29,7 @@ typedef struct {
|
|||
|
||||
} EngineTimers;
|
||||
|
||||
void draw_stripe(image_t *tex, int texSampleY, int linePos, fixed_t texSize, int texX, int x);
|
||||
void draw_stripe(bopti_image_t *tex, int texSampleY, int linePos, fixed_t texSize, int texX, int x);
|
||||
|
||||
void load_map();
|
||||
void end_screen();
|
||||
|
|