fixes i don't remember + fixed_t functions to ASM for practice
This commit is contained in:
parent
1d53ceebb3
commit
c217e69ce8
|
@ -1,9 +1,8 @@
|
|||
# Configure with [fxsdk build-fx] or [fxsdk build-cg], which provide the
|
||||
# toolchain file and module path of the fxSDK
|
||||
# With standard make, it compiles with SDL2 and SDL2_image
|
||||
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(RaycasterGame)
|
||||
project(RaycasterGame LANGUAGES C ASM)
|
||||
|
||||
#FX-CG50 build
|
||||
if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
|
||||
|
@ -47,6 +46,10 @@ set(ASSETS
|
|||
#assets-cg/skybox0.png
|
||||
)
|
||||
if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
|
||||
|
||||
set(ASMSOURCES
|
||||
src/fixed.S
|
||||
)
|
||||
#fxconv_declare_converters(assets-cg/map/converters.py)
|
||||
|
||||
#Les lignes suivantes proviennent de https://gitea.planet-casio.com/Slyvtt/Collab_RPG
|
||||
|
@ -62,13 +65,10 @@ if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
|
|||
#)
|
||||
|
||||
fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA)
|
||||
endif()
|
||||
|
||||
if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
|
||||
|
||||
set(CFLAGS -Wall -Wextra -Ofast -pipe -flto)
|
||||
|
||||
add_executable(RaycasterGame ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}})
|
||||
add_executable(RaycasterGame ${ASMSOURCES} ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}})
|
||||
|
||||
target_link_libraries(RaycasterGame LibProf::LibProf)
|
||||
|
||||
|
|
Binary file not shown.
13
build.sh
13
build.sh
|
@ -1,15 +1,18 @@
|
|||
#Script to do the build for you. Not meant to be more then an automation tool for devs.
|
||||
|
||||
if test $1 = "linux"; then
|
||||
if test $1 "linux"; then
|
||||
mkdir "./build"
|
||||
cd "./build"
|
||||
cmake ..
|
||||
make
|
||||
mv "./RaycasterGame" "../RaycasterGame.amd64";
|
||||
elif test $1 = "win"; then
|
||||
#todo
|
||||
echo "not done yet !";
|
||||
elif test $1 = "ems"; then
|
||||
elif test $1 "win"; then
|
||||
#todo
|
||||
echo "not done yet !";
|
||||
elif test $1 "ems"; then
|
||||
mkdir "./build"
|
||||
cd "./build"
|
||||
cmake ..
|
||||
emmake make
|
||||
emcc [-Ox] RaycaserGame.o -o RaycaserGame.js
|
||||
fi
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
#Fcalva, 10/02/2024
|
||||
|
||||
.global _fmul
|
||||
.type _fmul, @function
|
||||
|
||||
.global _fdec
|
||||
.type _fdec, @function
|
||||
|
||||
.global _fceil
|
||||
.type _fceil, @function
|
||||
|
||||
.global _fround
|
||||
.type _fround, @function
|
||||
|
||||
.global _feasein
|
||||
.type _feasein, @function
|
||||
|
||||
_fmul:
|
||||
dmuls.l r4, r5
|
||||
sts MACH, r1
|
||||
sts MACL , r0
|
||||
rts
|
||||
xtrct r1, r0
|
||||
|
||||
_fdec:
|
||||
mov #-1, r0
|
||||
extu.w r0, r0
|
||||
rts
|
||||
and r4, r0
|
||||
|
||||
_fceil:
|
||||
mov #-1, r0
|
||||
extu.w r0, r0
|
||||
add r4, r0
|
||||
mov #-16, r1
|
||||
rts
|
||||
shad r1, r0
|
||||
|
||||
_fround:
|
||||
mov.l .fround_constant, r0
|
||||
add r4, r0
|
||||
mov #-16, r1
|
||||
rts
|
||||
shad r1, r0
|
||||
|
||||
_feasein:
|
||||
mov r4, r5
|
||||
dmuls.l r4, r5
|
||||
sts MACH, r1
|
||||
sts MACL , r0
|
||||
rts
|
||||
xtrct r1, r0
|
||||
|
||||
.fround_constant:
|
||||
.long 0x8000
|
57
src/fixed.h
57
src/fixed.h
|
@ -13,6 +13,8 @@ typedef int32_t fixed_t;
|
|||
//GCC complained when in inline functions
|
||||
#define ffloor(f) ((f) >> 16)
|
||||
|
||||
#ifndef FXCG50
|
||||
|
||||
static inline fixed_t fmul(fixed_t left, fixed_t right)
|
||||
{
|
||||
/* Generally optimized by the compiler to use dmuls.l and xtrct */
|
||||
|
@ -20,6 +22,41 @@ static inline fixed_t fmul(fixed_t left, fixed_t right)
|
|||
return (int32_t)(p >> 16);
|
||||
}
|
||||
|
||||
static inline fixed_t fdec(fixed_t f)
|
||||
{
|
||||
return f & 0xffff;
|
||||
}
|
||||
|
||||
static inline int fceil(fixed_t f)
|
||||
{
|
||||
return (f + 0xffff) >> 16;
|
||||
}
|
||||
|
||||
static inline int fround(fixed_t f)
|
||||
{
|
||||
return (f + 0x8000) >> 16;
|
||||
}
|
||||
|
||||
static inline fixed_t feasein(fixed_t x)
|
||||
{
|
||||
return fmul(x, x);
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef FXCG50
|
||||
|
||||
extern inline fixed_t fmul(fixed_t left, fixed_t right);
|
||||
|
||||
extern inline fixed_t fdec(fixed_t f);
|
||||
|
||||
extern inline int fceil(fixed_t f);
|
||||
|
||||
extern inline int fround(fixed_t f);
|
||||
|
||||
inline fixed_t feasein(fixed_t x);
|
||||
|
||||
#endif
|
||||
|
||||
static inline fixed_t fdiv(fixed_t left, fixed_t right)
|
||||
{
|
||||
/* Pretty slow */
|
||||
|
@ -39,21 +76,6 @@ static inline fixed_t fixfloat(float constant)
|
|||
return (fixed_t)(constant * 65536);
|
||||
}
|
||||
|
||||
static inline fixed_t fdec(fixed_t f)
|
||||
{
|
||||
return f & 0xffff;
|
||||
}
|
||||
|
||||
static inline int fceil(fixed_t f)
|
||||
{
|
||||
return (f + 0xffff) >> 16;
|
||||
}
|
||||
|
||||
static inline int fround(fixed_t f)
|
||||
{
|
||||
return (f + 0x8000) >> 16;
|
||||
}
|
||||
|
||||
static inline float f2float(fixed_t f)
|
||||
{
|
||||
return (float)f / 65536;
|
||||
|
@ -69,11 +91,6 @@ static inline double f2int(fixed_t f)
|
|||
return (int)f / 65536;
|
||||
}
|
||||
|
||||
static inline fixed_t feasein(fixed_t x)
|
||||
{
|
||||
return fmul(x, x);
|
||||
}
|
||||
|
||||
static inline fixed_t fease(fixed_t x)
|
||||
{
|
||||
if(x <= fix(0.5)) {
|
||||
|
|
|
@ -83,7 +83,7 @@ void move(Game *game, uint32_t keys) {
|
|||
player->velocity.x = -fmul(player->dir.x, moveSpeed);
|
||||
player->velocity.y = -fmul(player->dir.y, moveSpeed);
|
||||
}
|
||||
if(keydown(KEY_F2)){
|
||||
/*if(keydown(KEY_F2)){
|
||||
if(player->pos.z - fmul(moveSpeed, 0x3FFF) > 0){
|
||||
player->pos.z -= fmul(moveSpeed, 0x3FFF);
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ void move(Game *game, uint32_t keys) {
|
|||
if(player->pos.z + player_height + fmul(moveSpeed, 0x3FFF) < fix(3)){
|
||||
player->pos.z += fmul(moveSpeed, 0x3FFF);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
//rotate to the right
|
||||
if(keys & 0b1<<3) {
|
||||
//both camera direction and camera plane must be rotated
|
||||
|
@ -163,7 +163,7 @@ void draw_f(image_t *vram){ //a refaire
|
|||
|
||||
}*/
|
||||
|
||||
inline void dstripe(image_t *stripe, image_t *vram, int x, int linePos, int lineHeight, int ymin, int ymax){
|
||||
void dstripe(image_t *stripe, image_t *vram, int x, int linePos, int lineHeight, int ymin, int ymax){
|
||||
int i;
|
||||
fixed_t cpixel;
|
||||
int cy;
|
||||
|
@ -219,7 +219,7 @@ void __attribute__((aligned(4))) draw_walls(Game *game, image_t *vram){
|
|||
//Assign dbuffer to xyram so that checks go vroom vroom
|
||||
int32_t __attribute__((aligned(4))) *dbuffer = (void *)0xe500e000 + 32;
|
||||
#else
|
||||
int32_t *dbuffer[viewport_h];
|
||||
int32_t dbuffer[viewport_h];
|
||||
#endif
|
||||
|
||||
struct image_linear_map temp;
|
||||
|
|
|
@ -157,11 +157,11 @@ image_t *image_sub(image_t *src, int x, int y, int w, int h, image_t *dest){
|
|||
return dest;
|
||||
}
|
||||
|
||||
void image_fill(image_t *img, int value) {
|
||||
void image_fill(image_t *img, SDL_Color color) {
|
||||
|
||||
|
||||
|
||||
SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
|
||||
//SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
|
||||
}
|
||||
|
||||
void image_scale(image_t const *src, int gamma_x, int gamma_y, struct image_linear_map *map){
|
||||
|
|
|
@ -82,8 +82,6 @@ image_t *image_sub(image_t *src, int x, int y, int w, int h, image_t *dest);
|
|||
|
||||
void image_free(image_t *img);
|
||||
|
||||
void image_fill(image_t *img, int value);
|
||||
|
||||
void image_scale(image_t const *src, int gamma_x, int gamma_y, struct image_linear_map *map);
|
||||
|
||||
void image_linear(image_t const *src, image_t *dst, struct image_linear_map *map);
|
||||
|
@ -140,5 +138,7 @@ image_t sdl_tex_load(char *filename);
|
|||
|
||||
void sdl_image_init();
|
||||
|
||||
void sdl_image_quit();
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -132,7 +132,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
// 3D raycast function based on Permadi's'
|
||||
// Returns -1 if it didn't hit anything within dist, else distance to hit
|
||||
|
||||
fixed_t raycast(ShooterMap *ShooterLevel, Vector3d pos, Vector3d rayDir, fixed_t dist){
|
||||
/*fixed_t raycast(ShooterMap *ShooterLevel, Vector3d pos, Vector3d rayDir, fixed_t dist){
|
||||
|
||||
Vector3d sideDist;
|
||||
Vector3d deltaDist;
|
||||
|
@ -185,4 +185,4 @@ fixed_t raycast(ShooterMap *ShooterLevel, Vector3d pos, Vector3d rayDir, fixed_t
|
|||
if (hit == 0) return -1;
|
||||
|
||||
return sideDistp[side] - deltaDistp[side];
|
||||
}
|
||||
}*/
|
||||
|
|
Loading…
Reference in New Issue