Avancées build PC-SDL

This commit is contained in:
attilavs2 2023-11-02 12:05:20 +01:00
parent ee0d2ab025
commit 0a88a5cbc4
13 changed files with 249 additions and 72 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
# Build files
/build
/build-fx
/build-cg
/build-cg-push

View File

@ -5,18 +5,20 @@ cmake_minimum_required(VERSION 3.15)
project(RaycasterGame)
#FX-CG50 build
include(GenerateG3A)
include(Fxconv)
if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
include(Fxconv)
include(GenerateG3A)
find_package(Gint 2.10 REQUIRED)
find_package(LibProf 2.4 REQUIRED)
else()
else() #SDL2 build
find_package(SDL2 REQUIRED CONFIG REQUIRED COMPONENTS SDL2)
find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main)
#find_file(SDL2_INCLUDE_DIR NAME SDL.h HINTS SDL2)
#find_library(SDL2_LIBRARY NAME SDL2)
endif()
@ -30,6 +32,7 @@ set(SOURCES
src/utils.c
src/inputs.c
src/ui.c
src/sdl_image.c
)
set(ASSETS
@ -41,7 +44,7 @@ set(ASSETS
assets-cg/sprites/zombard1.png
#assets-cg/skybox0.png
)
if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
fxconv_declare_converters(assets-cg/map/converters.py)
#Les lignes suivantes proviennent de https://gitea.planet-casio.com/Slyvtt/Collab_RPG
@ -57,10 +60,17 @@ add_custom_command(
)
fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA)
endif()
add_executable(RaycasterGame ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}})
target_compile_options(RaycasterGame PRIVATE -Wall -Wextra -O0)
if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
target_link_libraries(RaycasterGame LibProf::LibProf)
else()
target_link_libraries(RaycasterGame SDL2::SDL2)
endif()
target_compile_options(RaycasterGame PRIVATE -Wall -Wextra -O0)
target_link_options(RaycasterGame PRIVATE -Wl,--print-memory-usage)
if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
@ -70,5 +80,4 @@ else()
target_compile_definitions(RaycasterGame PRIVATE SDL2)
endif()

Binary file not shown.

View File

@ -2,7 +2,10 @@
#define config__h
#define debug //pour afficher les infos de debug
#ifdef FXCG50
//#define USB //Pour la capture USB
#endif
//A caser autrpart

View File

@ -16,23 +16,32 @@
//SDL2 is defined by CMake
#ifndef SDL2
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/image.h>
#include <libprof.h>
#endif
#ifdef SDL2
#include "sdl.h"
#ifdef FXCG50
#ifdef debug
#include <gint/kmalloc.h>
#endif
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/image.h>
#include <libprof.h>
#endif
#ifdef debug
#include <gint/kmalloc.h>
#ifdef SDL2
#include <SDL.h>
#include "sdl_image.h"
#endif
#ifdef USB
#include <gint/usb.h>
#include <gint/usb-ff-bulk.h>
#include <gint/usb.h>
#include <gint/usb-ff-bulk.h>
#endif
#endif //includes__h

View File

@ -4,6 +4,53 @@
#include "types.h"
#include "moteur.h"
#ifdef FXCG50
//The actual keys behind the RCKEY_ ones
uint8_t keymap = [0, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_ALPHA,
KEY_SHIFT, KEY_F6, KEY_F1, KEY_TAN];
void rc_pollevent() {
pollevent();
}
uint8_t rc_keydown(enum keys key) {
}
#endif
#ifdef SDL2
//The actual keys behind the RCKEY_ ones
// W = move fowards
// S = move backwards
// Q = turn left
// D = turn right
// Space = jump
// F = interact
// Esc = exit
// F1 = FPS counter
// G = Debug
uint8_t keymap = [0, SDL_SCANCODE_W, SDL_SCANCODE_S, SDL_SCANCODE_Q, SDL_SCANCODE_D,
SDL_SCANCODE_SPACE, SDL_SCANCODE_F, SDL_SCANCODE_ESCAPE,
SDL_SCANCODE_F1, SDL_SCANCODE_G];
SDL_Event sdl_events;
void rc_pollevent() {
SDL_PeepEvents(&sdl_events, int numevents,
SDL_eventaction action,
Uint32 minType, Uint32 maxType);
}
uint8_t rc_keydown(enum keys key){
}
#endif
void keys_get(ShooterMap *ShooterLevel, Player *player){
extern char screenshot;
extern char record;
@ -14,8 +61,7 @@ void keys_get(ShooterMap *ShooterLevel, Player *player){
move(ShooterLevel, player);
//pollevent();
if (keydown(KEY_F1) && frame_time_timer <= 0) {
if (rc_keydown(RCKEY_FPS) && frame_time_timer <= 0) {
if (disp_frame_time == 0) {
disp_frame_time = 1;
frame_time_timer = 10;
@ -26,10 +72,10 @@ void keys_get(ShooterMap *ShooterLevel, Player *player){
}
}
frame_time_timer--;
if (keydown(KEY_F6)) exit_game = 1;
if (rc_keydown(RCKEY_EXIT)) exit_game = 1;
#ifdef debug
if (keydown(KEY_TAN)) end_screen();
if (keydown(RCKEY_DEBUG)) end_screen();
#endif
#ifdef USB

View File

@ -4,14 +4,17 @@
enum keys {
ANY = -1,
NONE = 0,
UP = 1,
DOWN = 2,
LEFT = 3,
RIGHT = 4,
JUMP = 5,
ACTION = 6
RCKEY_ANY = -1,
RCKEY_NONE = 0,
RCKEY_UP = 1,
RCKEY_DOWN = 2,
RCKEY_LEFT = 3,
RCKEY_RIGHT = 4,
RCKEY_JUMP = 5,
RCKEY_ACTION = 6,
RCKEY_EXIT = 7,
RCKEY_FPS = 8,
RCKEY_DEBUG = 9
};

View File

@ -24,18 +24,16 @@
// Lephenixnoir pour Gint, Azur et l'aide
// Pour le moment le nouveau moteur de rendu 3lvl ne marche pas
// TODO :
// - Nouveau mouvement | |
// - 3 Level | |
// - Nouveau mouvement |~| (Cassé mais marchait)
// - 3 Level |~| (Textures sont cassées)
// - Sprites ! |~|
// -Refaire mieux |X|
// -Re-refaire mieux |X|
// -Optimiser | |
//
// - Refactoriser ce qui reste |~|
//
#ifdef FX9860G
#error Ce code est pour FXCG50/G90+E uniquement, enlevez ce message a vos riques et périls
#error "Ce code n'est pas pour FX, enlevez ce message a vos riques et périls"
#endif
extern ShooterMap ShooterLevel0;
@ -58,6 +56,11 @@ int raycast_time = 0;
int draw_time = 0;
int main(){
#ifdef SDL2
sdl_image_init();
#endif
dclear(C_WHITE);
dprint( 0, 0, C_BLACK, "Chargement...");
dupdate();
@ -124,6 +127,7 @@ int main(){
if (disp_frame_time == 1) dprint( 1, 1, C_BLACK, "Frame time : %d ms", frame_time);
#ifdef debug
dprint( 1, 10,C_BLACK, "Raycast time : %d ms", raycast_time);
dprint( 1, 20,C_BLACK, "Draw time : %d ms", draw_time);
dprint( 1, 30, C_BLACK, "planeX : %d", player1.plane.x);
@ -133,9 +137,10 @@ int main(){
dprint( 1, 70, C_BLACK, "posX : %d", player1.pos.x);
dprint( 1, 80, C_BLACK, "posY : %d", player1.pos.y);
dprint( 1, 90, C_BLACK, "posZ : %d", player1.pos.z);
#ifdef FXCG50
dprint( 1, 130, C_BLACK, "RAM usage : %d",
kmalloc_get_gint_stats(kmalloc_get_arena("_uram"))->used_memory);
#endif
#endif

View File

@ -251,7 +251,7 @@ void draw_walls(ShooterMap *ShooterLevel, Player *player, image_t *vram){
walls[0] = 0; walls[1] = 0; walls[2] = 0;
//perform DDA
while(true) {
while(1) {
//Check if the ray is out of range/bounds
if (sideDistX >= max_dist || sideDistY >= max_dist || mapX < 0 || mapY < 0 || mapX >= map_w || mapY >= map_h) {
hit = 0;
@ -293,20 +293,12 @@ void draw_walls(ShooterMap *ShooterLevel, Player *player, image_t *vram){
if(side == 0 && rayDirX > 0) texX = tsize - texX - 1;
if(side == 1 && rayDirY < 0) texX = tsize - texX - 1;
lineHeight = f2int(fdiv(fix(viewport_h), perpWallDist)); //Taille en px de la ligne
lineHeight = fround(fdiv(fix(viewport_h), perpWallDist)); //Taille en px de la ligne
if (lineHeight < 1) lineHeight = 1;
if (lineHeight > viewport_h-1) lineHeight = viewport_h-1;
fixed_t texSize = fix(lineHeight) / tsize; //taille proportionelle de la ligne a la tex
if (texSize < fix(1/tsize)) texSize = fix(1/tsize);
if (texSize > fix(viewport_h/tsize)) {
texSample = fceil(fdiv(fix(viewport_h), texSize));
texSampleY = tsize*0.5 - (int)texSample * 0.5 + 1;
}
else {
texSample = tsize;
texSampleY = 0;
}
for(i = 0; i <3; i++){
if(walls[i] < 1) continue;
@ -314,20 +306,32 @@ void draw_walls(ShooterMap *ShooterLevel, Player *player, image_t *vram){
// depending on the offset between the wall and the player
int linePos = viewport_h/2 - lineHeight/2 + fround((player->pos.z-fix(i))*lineHeight);
if(linePos > viewport_h - 1) continue;
if(linePos >= viewport_h) continue;
if(linePos+lineHeight < 1) continue;
if(linePos < 1) linePos = 1;
/*
uint8_t tex;
if(mapX < 0 || mapY < 0 || mapX >= map_w || mapY >= map_h) tex = 0;
else tex = 1; //ShooterLevel->wall[mapX][mapY][i];
uint8_t tex = 1; //ShooterLevel->wall[mapX][mapY][i];
if (linePos < 1) {
texSampleY = texSize*abs(linePos);
texSample = tsize - texSampleY;
linePos = 2;
}
if (linePos > viewport_h) {
texSampleY = texSize*abs(linePos);
texSample = tsize - texSampleY;
linePos = viewport_h;
}
else {
texSampleY = 0;
}
dclear(C_WHITE); dprint(1,1,C_BLACK,"coucou 327"); dupdate(); getkey();
tex_stripe = image_sub(tex_index[tex], texX, texSampleY, 1, texSample);
image_scale(tex_stripe, 0xFFFF, texSize, &temp);
image_linear(tex_stripe, image_at(vram, x, linePos), &temp);
*/
dline(x, linePos, x, linePos+lineHeight, 0xFAFA);
image_linear(tex_stripe, image_at(vram, x, linePos), &temp); //Plante ici
//dline(x, linePos, x, linePos+lineHeight, 0xFAFA);
prof_leave(img_drw);
prof_enter(rayscat);
}

View File

@ -1,8 +0,0 @@
#include "includes.h"
#define window_w screen_w*upscale
#define window_h screen_h*upscale
void sdl_init(){
}

View File

@ -1,6 +0,0 @@
#ifndef sdl__h
#define sdl__h
void sdl_init();
#endif

24
src/sdl_image.c Normal file
View File

@ -0,0 +1,24 @@
#include "includes.h"
#define window_w screen_w*upscale
#define window_h screen_h*upscale
SDL_info sdl_image_init(){
uint32_t init_flags = SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO;
SDL_Init(init_flags);
uint32_t window_flags = SDL_WINDOW_INPUT_GRABBED;
SDL_Window *window = SDL_CreateWindow("RaycasterGame", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
window_w, window_h, window_flags);
}
void sdl_image_quit(SDL_Window *window){
SDL_DestroyWindow(window);
SDL_Quit();
}

87
src/sdl_image.h Normal file
View File

@ -0,0 +1,87 @@
#ifndef sdl__h
#define sdl__h
//Gint defs
#define C_WHITE (SDL_Color){255, 255, 255, 255}
#define C_BLACK (SDL_Color){0, 0, 0, 255}
#define GPACKED(x) __attribute__((packed, aligned(x)))
// Taken from gint/image.h
/* image_t: gint's native bitmap image format
Images of this format can be created through this header's API but also by
using the fxSDK's built-in image converters with fxconv. */
typedef struct
{
/* Color format, one of the IMAGE_* values defined above */
uint8_t format;
/* Additional flags, a combination of IMAGE_FLAGS_* values */
uint8_t flags;
/* Number of colors in the palette; this includes alpha for transparent
images, as alpha is always the first entry.
RGB16: 0
P8: Ranges between 1 and 256
P4: 16 */
int16_t color_count;
/* Full width and height, in pixels */
uint16_t width;
uint16_t height;
/* Byte stride between lines */
int stride;
/* Pixel data in row-major order, left to right.
- RGB16: 2 bytes per entry, each row padded to 4 bytes for alignment.
Each 2-byte value is an RGB565 color.
- P8: 1 signed byte per entry. Each byte is a palette index shifted by
128 (to access the color, use palette[<value>+128]).
- P4: 4 bits per entry, each row padded to a full byte. Each entry is a
direct palette index between 0 and 15. */
void *data;
/* For P8 and P4, color palette. The number of entries allocated in the
array is equal to the color_count attribute. */
uint16_t *palette;
} GPACKED(4) image_t;
enum {
IMAGE_RGB565 = 0, /* Converted to RGBA8888 but with alpha = 255*/
IMAGE_RGB565A = 1, /* RGBA8888 but with alpha = 0 */
};
//SDL-ported gint functions and defs
typedef struct{
uint32_t start;
uint32_t current;
uint8_t rec;
} prof_t;
int prof_init(void){
return;
}
void prof_quit(void){
return;
}
#define prof_make() ((prof_t){ 0, 0 })
#define prof_enter(prof) { \
if(!(prof).rec++) (prof).elapsed += *prof_tcnt; \
}
#define prof_enter(prof) { if(1>prof.rec){ prof.start=SDL_GetTicks(); prof.rec=1;}}
//SDL specific defs
typedef struct{
SDL_Window *window;
SDL_Renderer *renderer;
} SDL_info;
void sdl_image_init();
#endif