Renders on PSP again

This commit is contained in:
2025-09-12 00:25:17 -05:00
parent 964a9f64f2
commit 46a94ecacd
17 changed files with 105 additions and 31 deletions

View File

@@ -10,8 +10,8 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
if(NOT DEFINED DUSK_TARGET_SYSTEM) if(NOT DEFINED DUSK_TARGET_SYSTEM)
set(DUSK_TARGET_SYSTEM "linux") # set(DUSK_TARGET_SYSTEM "linux")
# set(DUSK_TARGET_SYSTEM "psp") set(DUSK_TARGET_SYSTEM "psp")
endif() endif()
# Prep cache # Prep cache

View File

@@ -7,4 +7,5 @@ add_asset(PALETTE first.palette.png)
add_asset(IMAGE font_minogram.png type=ALPHA) add_asset(IMAGE font_minogram.png type=ALPHA)
add_asset(IMAGE entities.png type=PALETTIZED) add_asset(IMAGE entities.png type=PALETTIZED)
add_asset(CONFIG init.dcf) add_asset(CONFIG init.dcf)
add_asset(CONFIG init_psp.dcf)
# add_asset(TILESET entities.tsx) # add_asset(TILESET entities.tsx)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -1,4 +1,5 @@
echo " = Dawn Init = "; echo " = Dawn Init = ";
bind ` toggleconsole; bind ` toggleconsole;
bind w up; bind w up;
bind s down; bind s down;

17
assets/init_psp.dcf Normal file
View File

@@ -0,0 +1,17 @@
echo " = Dawn PSP = ";
bind up up;
bind down down;
bind left left;
bind right right;
bind cross accept;
bind circle cancel;
bind select toggleconsole;
bind start toggleconsole;
bind lstick_negative_y up;
bind lstick_positive_y down;
bind lstick_negative_x left;
bind lstick_positive_x right;
fps 1;

View File

@@ -14,7 +14,7 @@
#define CONSOLE_VARIABLES_MAX 128 #define CONSOLE_VARIABLES_MAX 128
#define CONSOLE_LINE_MAX 256 #define CONSOLE_LINE_MAX 256
#define CONSOLE_HISTORY_MAX 32 #define CONSOLE_HISTORY_MAX 32
#define CONSOLE_EXEC_BUFFER_MAX 16 #define CONSOLE_EXEC_BUFFER_MAX 32
#define CONSOLE_ALIAS_MAX 32 #define CONSOLE_ALIAS_MAX 32
#define CONSOLE_VAR_NAME_MAX 32 #define CONSOLE_VAR_NAME_MAX 32

View File

@@ -18,8 +18,8 @@ display_t DISPLAY;
errorret_t displayInit(void) { errorret_t displayInit(void) {
#if DISPLAY_SDL2 #if DISPLAY_SDL2
uint32_t flags = SDL_INIT_VIDEO; uint32_t flags = SDL_INIT_VIDEO;
#if INPUT_SUPPORT_GAMEPAD #if INPUT_GAMEPAD == 1
flags |= SDL_INIT_GAMECONTROLLER; flags |= SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK;
#endif #endif
if(SDL_Init(flags) != 0) { if(SDL_Init(flags) != 0) {
errorThrow("SDL Failed to Initialize: %s", SDL_GetError()); errorThrow("SDL Failed to Initialize: %s", SDL_GetError());

View File

@@ -63,8 +63,8 @@ void sceneOverworldRenderMap(const map_t *map) {
// Draw base layer // Draw base layer
// Draw entities // Draw entities
entity_t *start = &map->entities[0]; const entity_t *start = &map->entities[0];
entity_t *end = &map->entities[map->entityCount]; const entity_t *end = &map->entities[map->entityCount];
while(start < end) { while(start < end) {
// Render entity here. // Render entity here.
sceneOverworldRenderEntity(start); sceneOverworldRenderEntity(start);

View File

@@ -54,7 +54,7 @@ void uiRender(void) {
cameraPushMatrix(&UI.camera); cameraPushMatrix(&UI.camera);
uiConsoleRender(); uiConsoleRender();
uiFPSRender(); // uiFPSRender();
spriteBatchFlush(); spriteBatchFlush();
cameraPopMatrix(); cameraPopMatrix();

View File

@@ -11,16 +11,17 @@
void uiConsoleRender(void) { void uiConsoleRender(void) {
if(!CONSOLE.visible) return; if(!CONSOLE.visible) return;
consolePrint("Test\n");
int32_t i = 0; int32_t i = CONSOLE_HISTORY_MAX - 1;
char_t *line; char_t *line;
do { do {
line = CONSOLE.line[i]; line = CONSOLE.line[i];
if(line[0] == '\0') { if(line[0] == '\0') {
i++; i--;
continue; continue;
} }
uiTextDraw(0, i * UI_TEXT_TILE_HEIGHT, line, COLOR_WHITE); uiTextDraw(0, i * UI_TEXT_TILE_HEIGHT, line, COLOR_WHITE);
i++; i--;
} while(i < CONSOLE_HISTORY_MAX); } while(i > 0);
} }

View File

@@ -12,16 +12,15 @@
#include "util/string.h" #include "util/string.h"
void uiFPSInit(void) { void uiFPSInit(void) {
consoleRegVar("fps", "1", NULL); consoleRegVar("fps", "0", NULL);
} }
void uiFPSRender(void) { void uiFPSRender(void) {
float_t fps = TIME.delta > 0.0f ? (1.0f / TIME.delta) : 0.0f;
if(stringCompare(consoleVarGet("fps")->value, "0") == 0) { if(stringCompare(consoleVarGet("fps")->value, "0") == 0) {
return; return;
} }
float_t fps = TIME.delta > 0.0f ? (1.0f / TIME.delta) : 0.0f;
char_t buffer[64]; char_t buffer[64];
snprintf( snprintf(
buffer, buffer,

View File

@@ -31,7 +31,12 @@ errorret_t engineInit(void) {
errorChain(displayInit()); errorChain(displayInit());
rpgInit(); rpgInit();
consoleExec("exec init.dcf"); // Init scripts
#if PSP
consoleExec("exec init_psp.dcf");
#else
consoleExec("exec init.dcf");
#endif
errorOk(); errorOk();
} }

View File

@@ -22,7 +22,7 @@ if(DUSK_TARGET_SYSTEM STREQUAL "linux")
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp") elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
target_compile_definitions(${DUSK_TARGET_NAME} target_compile_definitions(${DUSK_TARGET_NAME}
PRIVATE PRIVATE
INPUT_SDL=1 INPUT_SDL2=1
INPUT_GAMEPAD=1 INPUT_GAMEPAD=1
) )
endif() endif()

View File

@@ -22,16 +22,23 @@ void inputInit(void) {
INPUT.actions[i].currentValue = 0.0f; INPUT.actions[i].currentValue = 0.0f;
} }
stringCopy(&INPUT_BUTTON_DATA[0].command[0], "echo \"test\";", CONSOLE_LINE_MAX); INPUT.deadzone = 0.1f;
INPUT_BUTTON_DATA[0].actionType = INPUT_BUTTON_ACTION_TYPE_COMMAND;
INPUT_BUTTON_DATA[1].actionType = INPUT_BUTTON_ACTION_TYPE_ACTION;
INPUT_BUTTON_DATA[1].action = INPUT_ACTION_UP;
} }
void inputUpdate(void) { void inputUpdate(void) {
#if INPUT_SDL2 == 1 #if INPUT_SDL2 == 1
INPUT.keyboardState = SDL_GetKeyboardState(NULL); #if INPUT_GAMEPAD == 1
INPUT.controller = NULL;
for(int32_t i = 0; i < SDL_NumJoysticks(); i++) {
if(!SDL_IsGameController(i)) continue;
INPUT.controller = SDL_GameControllerOpen(i);
if(INPUT.controller) break;
}
#endif
#if INPUT_KEYBOARD == 1
INPUT.keyboardState = SDL_GetKeyboardState(NULL);
#endif
#endif #endif
// Reset all actions // Reset all actions

View File

@@ -12,7 +12,15 @@
typedef struct { typedef struct {
inputactiondata_t actions[INPUT_ACTION_COUNT]; inputactiondata_t actions[INPUT_ACTION_COUNT];
#if INPUT_GAMEPAD == 1
float_t deadzone;
#endif
#if INPUT_SDL2 == 1 #if INPUT_SDL2 == 1
#if INPUT_GAMEPAD == 1
SDL_GameController *controller;
#endif
#if INPUT_KEYBOARD == 1 #if INPUT_KEYBOARD == 1
const uint8_t *keyboardState; const uint8_t *keyboardState;
#endif #endif

View File

@@ -14,6 +14,23 @@ inputbuttondata_t INPUT_BUTTON_DATA[] = {
#if INPUT_SDL2 == 1 #if INPUT_SDL2 == 1
#if INPUT_GAMEPAD == 1 #if INPUT_GAMEPAD == 1
#if PSP #if PSP
{ .name = "triangle", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_Y } },
{ .name = "cross", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_A } },
{ .name = "circle", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_B } },
{ .name = "square", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_X } },
{ .name = "start", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_START } },
{ .name = "select", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_BACK } },
{ .name = "up", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_UP } },
{ .name = "down", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_DOWN } },
{ .name = "left", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_LEFT } },
{ .name = "right", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_RIGHT } },
{ .name = "l", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_LEFTSHOULDER } },
{ .name = "r", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER } },
{ .name = "lstick_positive_x", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTX, .positive = true } } },
{ .name = "lstick_negative_x", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTX, .positive = false } } },
{ .name = "lstick_positive_y", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = true } } },
{ .name = "lstick_negative_y", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = false } } },
#else #else
#endif #endif
#endif #endif
@@ -145,11 +162,12 @@ inputbuttondata_t INPUT_BUTTON_DATA[] = {
inputbutton_t inputButtonGetByName(const char_t *name) { inputbutton_t inputButtonGetByName(const char_t *name) {
assertNotNull(name, "name must not be NULL"); assertNotNull(name, "name must not be NULL");
uint32_t len = sizeof(INPUT_BUTTON_DATA) / sizeof(inputbuttondata_t); inputbuttondata_t *data = INPUT_BUTTON_DATA;
while(data->name != NULL) {
for(uint32_t i = 0; i < len; i++) { if(stringCompareInsensitive(data->name, name) == 0) {
if(stringCompareInsensitive(INPUT_BUTTON_DATA[i].name, name) != 0) continue; return data->button;
return INPUT_BUTTON_DATA[i].button; }
data++;
} }
return (inputbutton_t){ .type = INPUT_BUTTON_TYPE_NONE }; return (inputbutton_t){ .type = INPUT_BUTTON_TYPE_NONE };
@@ -170,12 +188,23 @@ float_t inputButtonGetValue(const inputbutton_t button) {
#if INPUT_GAMEPAD == 1 #if INPUT_GAMEPAD == 1
case INPUT_BUTTON_TYPE_GAMEPAD: { case INPUT_BUTTON_TYPE_GAMEPAD: {
#if INPUT_SDL2 == 1 #if INPUT_SDL2 == 1
if(SDL_GameControllerGetButton( if(SDL_GameControllerGetButton(INPUT.controller, button.gpButton)) {
SDL_GameControllerFromInstanceID(0), button.gpButton return 1.0f;
)) return 1.0f; }
#endif #endif
return 0.0f; return 0.0f;
} }
case INPUT_BUTTON_TYPE_GAMEPAD_AXIS: {
#if INPUT_SDL2 == 1
Sint16 axis = SDL_GameControllerGetAxis(INPUT.controller, button.gpAxis.axis);
if(!button.gpAxis.positive) axis = -axis;
float_t value = (float_t)axis / 32767.0f;
// Deadzone
if(value < INPUT.deadzone) return 0.0f;
return value;
#endif
}
#endif #endif
default: { default: {

View File

@@ -26,6 +26,7 @@
#if INPUT_GAMEPAD == 1 #if INPUT_GAMEPAD == 1
#if INPUT_SDL2 == 1 #if INPUT_SDL2 == 1
typedef SDL_GameControllerButton inputgamepadbutton_t; typedef SDL_GameControllerButton inputgamepadbutton_t;
typedef SDL_GameControllerAxis inputgamepadaxis_t;
#endif #endif
#endif #endif
@@ -37,6 +38,7 @@ typedef enum {
#endif #endif
#if INPUT_GAMEPAD == 1 #if INPUT_GAMEPAD == 1
INPUT_BUTTON_TYPE_GAMEPAD, INPUT_BUTTON_TYPE_GAMEPAD,
INPUT_BUTTON_TYPE_GAMEPAD_AXIS,
#endif #endif
INPUT_BUTTON_TYPE_COUNT INPUT_BUTTON_TYPE_COUNT
@@ -48,6 +50,10 @@ typedef struct {
union { union {
#if INPUT_GAMEPAD == 1 #if INPUT_GAMEPAD == 1
inputgamepadbutton_t gpButton; inputgamepadbutton_t gpButton;
struct {
inputgamepadaxis_t axis;
bool_t positive;
} gpAxis;
#endif #endif
#if INPUT_KEYBOARD == 1 #if INPUT_KEYBOARD == 1