C -> CPP
Some checks failed
Build Dusk / build-linux (push) Failing after 1m47s
Build Dusk / build-psp (push) Failing after 1m40s

This commit is contained in:
2025-12-22 11:41:49 +10:00
parent a495179e5f
commit 76b5c51ab6
162 changed files with 751 additions and 740 deletions

View File

@@ -7,6 +7,8 @@
cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
if(NOT DEFINED DUSK_TARGET_SYSTEM)
@@ -45,7 +47,7 @@ endif()
# Init Project
project(${DUSK_TARGET_NAME}
VERSION 1.0.0
LANGUAGES C
LANGUAGES C CXX
)
# Executable

View File

@@ -9,7 +9,7 @@ following packages, depending on your system;
Fedora;
```
sudo dnf install git make gcc python python-polib python3-pillow python3-dotenv python3-numpy python-qt5 python3-pyopengl
sudo dnf install git make gcc python python-polib python3-pillow python3-dotenv python3-numpy python-qt5 python3-pyopengl SDL2-devel libzip-devel bzip2-devel xz-devel lua-devel
```
Ubuntu;

View File

@@ -12,7 +12,7 @@ endif()
file(STRINGS "${ENV_FILE}" ENV_LINES)
set(HEADER_CONTENT "#pragma once\n#include \"dusk.h\"\n\n")
set(HEADER_CONTENT "#pragma once\n#include \"dusk.hpp\"\n\n")
foreach(line IN LISTS ENV_LINES)
# Skip comments and empty lines (allow whitespace before # or ;)

View File

@@ -36,11 +36,11 @@ target_include_directories(${DUSK_TARGET_NAME}
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
main.c
main.cpp
)
# Defs
add_defs(duskdefs.env duskdefs.h)
add_defs(duskdefs.env duskdefs.hpp)
# Subdirs
add_subdirectory(assert)

View File

@@ -6,5 +6,5 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
assert.c
assert.cpp
)

View File

@@ -5,8 +5,8 @@
* https://opensource.org/licenses/MIT
*/
#include "assert.h"
#include "debug/debug.h"
#include "assert.hpp"
#include "debug/debug.hpp"
#ifndef ASSERTIONS_FAKED
void assertTrueImpl(

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "dusk.h"
#include "dusk.hpp"
#ifndef ASSERTIONS_FAKED
/**
@@ -115,10 +115,10 @@
assertUnreachableImpl(__FILE__, __LINE__, message)
#define assertNotNull(pointer, message) \
assertNotNullImpl(__FILE__, __LINE__, pointer, message)
assertNotNullImpl(__FILE__, __LINE__, (const void*)pointer, message)
#define assertNull(pointer, message) \
assertNullImpl(__FILE__, __LINE__, pointer, message)
assertNullImpl(__FILE__, __LINE__, (const void*)pointer, message)
#define assertDeprecated(message) \
assertDeprecatedImpl(__FILE__, __LINE__, message)

View File

@@ -6,7 +6,7 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
asset.c
asset.cpp
)
# Subdirs

View File

@@ -5,13 +5,13 @@
* https://opensource.org/licenses/MIT
*/
#include "asset.h"
#include "util/memory.h"
#include "util/string.h"
#include "assert/assert.h"
#include "asset.hpp"
#include "util/memory.hpp"
#include "util/string.hpp"
#include "assert/assert.hpp"
#include "asset/assettype.h"
#include "engine/engine.h"
#include "debug/debug.h"
#include "engine/engine.hpp"
#include "debug/debug.hpp"
errorret_t assetInit(void) {
memoryZero(&ASSET, sizeof(asset_t));
@@ -220,7 +220,7 @@ errorret_t assetLoad(const char_t *filename, void *output) {
// We found the asset type, now load the asset data
switch(def->loadStrategy) {
case ASSET_LOAD_STRAT_ENTIRE:
case ASSET_LOAD_STRAT_ENTIRE: {
assertNotNull(def->entire, "Asset load function cannot be NULL.");
void *data = memoryAllocate(def->dataSize);
bytesRead = zip_fread(file, data, def->dataSize);
@@ -238,8 +238,9 @@ errorret_t assetLoad(const char_t *filename, void *output) {
memoryFree(data);
errorChain(ret);
break;
}
case ASSET_LOAD_STRAT_CUSTOM:
case ASSET_LOAD_STRAT_CUSTOM: {
assertNotNull(def->custom, "Asset load function cannot be NULL.");
assetcustom_t customData = {
.zipFile = file,
@@ -247,6 +248,7 @@ errorret_t assetLoad(const char_t *filename, void *output) {
};
errorChain(def->custom(customData));
break;
}
default:
assertUnreachable("Unknown asset load strategy.");

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "error/error.h"
#include "error/error.hpp"
#include "assettype.h"
#if ASSET_TYPE == wad

View File

@@ -6,12 +6,12 @@
*/
#pragma once
#include "type/assetpaletteimage.h"
#include "type/assetalphaimage.h"
#include "type/assetlanguage.h"
#include "type/assetmap.h"
#include "type/assetchunk.h"
#include "type/assetscript.h"
#include "type/assetpaletteimage.hpp"
#include "type/assetalphaimage.hpp"
#include "type/assetlanguage.hpp"
#include "type/assetmap.hpp"
#include "type/assetchunk.hpp"
#include "type/assetscript.hpp"
#include <zip.h>
typedef enum {
@@ -27,10 +27,9 @@ typedef enum {
ASSET_TYPE_COUNT,
} assettype_t;
typedef enum {
ASSET_LOAD_STRAT_ENTIRE,
ASSET_LOAD_STRAT_CUSTOM
} assetloadstrat_t;
typedef uint8_t assetloadstrat_t;
#define ASSET_LOAD_STRAT_ENTIRE 0
#define ASSET_LOAD_STRAT_CUSTOM 1
typedef struct assetcustom_s {
zip_file_t *zipFile;
@@ -39,8 +38,8 @@ typedef struct assetcustom_s {
typedef struct {
const char_t *header;
const size_t dataSize;
const assetloadstrat_t loadStrategy;
const size_t dataSize;
union {
errorret_t (*entire)(void *data, void *output);
errorret_t (*custom)(assetcustom_t custom);

View File

@@ -6,10 +6,10 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
assetalphaimage.c
assetpaletteimage.c
assetlanguage.c
assetmap.c
assetchunk.c
assetscript.c
assetalphaimage.cpp
assetpaletteimage.cpp
assetlanguage.cpp
assetmap.cpp
assetchunk.cpp
assetscript.cpp
)

View File

@@ -5,9 +5,9 @@
* https://opensource.org/licenses/MIT
*/
#include "assetalphaimage.h"
#include "assert/assert.h"
#include "display/texture.h"
#include "assetalphaimage.hpp"
#include "assert/assert.hpp"
#include "display/texture.hpp"
errorret_t assetAlphaImageLoad(void *data, void *output) {
assertNotNull(data, "Data pointer cannot be NULL.");

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "error/error.h"
#include "error/error.hpp"
#define ASSET_ALPHA_IMAGE_WIDTH_MAX 256
#define ASSET_ALPHA_IMAGE_HEIGHT_MAX 256

View File

@@ -5,9 +5,9 @@
* https://opensource.org/licenses/MIT
*/
#include "asset/asset.h"
#include "assert/assert.h"
#include "rpg/entity/entity.h"
#include "asset/asset.hpp"
#include "assert/assert.hpp"
#include "rpg/entity/entity.hpp"
#pragma pack(push, 1)
typedef struct {

View File

@@ -6,8 +6,8 @@
*/
#pragma once
#include "error/error.h"
#include "rpg/world/chunk.h"
#include "error/error.hpp"
#include "rpg/world/chunk.hpp"
typedef struct assetcustom_s assetcustom_t;

View File

@@ -5,9 +5,9 @@
* https://opensource.org/licenses/MIT
*/
#include "asset/asset.h"
#include "assert/assert.h"
#include "locale/localemanager.h"
#include "asset/asset.hpp"
#include "assert/assert.hpp"
#include "locale/localemanager.hpp"
errorret_t assetLanguageHandler(assetcustom_t custom) {
assertNotNull(custom.zipFile, "Custom asset zip file cannot be NULL");

View File

@@ -6,9 +6,9 @@
*/
#pragma once
#include "locale/language/keys.h"
#include "error/error.h"
#include "duskdefs.h"
#include "locale/language/keys.hpp"
#include "error/error.hpp"
#include "duskdefs.hpp"
#include <zip.h>
#define ASSET_LANG_CHUNK_CACHE 4 // Number of chunks to cache in memory

View File

@@ -5,9 +5,9 @@
* https://opensource.org/licenses/MIT
*/
#include "asset/asset.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "asset/asset.hpp"
#include "assert/assert.hpp"
#include "util/memory.hpp"
errorret_t assetMapLoad(void *data, void *output) {
assertNotNull(data, "Data cannot be NULL");

View File

@@ -6,9 +6,9 @@
*/
#pragma once
#include "error/error.h"
#include "rpg/world/map.h"
#include "display/mesh/mesh.h"
#include "error/error.hpp"
#include "rpg/world/map.hpp"
#include "display/mesh/mesh.hpp"
/**
* Loads a map asset from the given data pointer into the output map structure.

View File

@@ -5,9 +5,9 @@
* https://opensource.org/licenses/MIT
*/
#include "assetpaletteimage.h"
#include "assert/assert.h"
#include "display/texture.h"
#include "assetpaletteimage.hpp"
#include "assert/assert.hpp"
#include "display/texture.hpp"
errorret_t assetPaletteImageLoad(void *data, void *output) {
assertNotNull(data, "Data pointer cannot be NULL.");

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "error/error.h"
#include "error/error.hpp"
#define ASSET_PALETTE_IMAGE_WIDTH_MAX 128
#define ASSET_PALETTE_IMAGE_HEIGHT_MAX 128

View File

@@ -5,8 +5,8 @@
* https://opensource.org/licenses/MIT
*/
#include "asset/asset.h"
#include "assert/assert.h"
#include "asset/asset.hpp"
#include "assert/assert.hpp"
errorret_t assetScriptHandler(assetcustom_t custom) {
assertNotNull(custom.zipFile, "Custom asset zip file cannot be NULL");

View File

@@ -6,10 +6,10 @@
*/
#pragma once
#include "error/error.h"
#include "duskdefs.h"
#include "error/error.hpp"
#include "duskdefs.hpp"
#include <zip.h>
#include <lua.h>
#include "script/scriptcontext.hpp"
#define ASSET_SCRIPT_BUFFER_SIZE 1024

View File

@@ -6,7 +6,7 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
debug.c
debug.cpp
)
# Subdirs

View File

@@ -5,7 +5,7 @@
* https://opensource.org/licenses/MIT
*/
#include "debug.h"
#include "debug.hpp"
void debugPrint(const char_t *message, ...) {
va_list args;

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "dusk.h"
#include "dusk.hpp"
/**
* Prints a debug message to the debug console.

View File

@@ -6,12 +6,12 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
display.c
framebuffer.c
camera.c
screen.c
texture.c
spritebatch.c
display.cpp
framebuffer.cpp
camera.cpp
screen.cpp
texture.cpp
spritebatch.cpp
)
# Subdirectories

View File

@@ -5,11 +5,11 @@
* https://opensource.org/licenses/MIT
*/
#include "camera.h"
#include "display/display.h"
#include "assert/assert.h"
#include "display/framebuffer.h"
#include "display/screen.h"
#include "camera.hpp"
#include "display/display.hpp"
#include "assert/assert.hpp"
#include "display/framebuffer.hpp"
#include "display/screen.hpp"
void cameraInit(camera_t *camera) {
cameraInitPerspective(camera);
@@ -93,11 +93,12 @@ void cameraPushMatrix(camera_t *camera) {
}
switch(camera->viewType) {
case CAMERA_VIEW_TYPE_MATRIX:
case CAMERA_VIEW_TYPE_MATRIX: {
glm_mat4_copy(camera->view, view);
break;
}
case CAMERA_VIEW_TYPE_LOOKAT:
case CAMERA_VIEW_TYPE_LOOKAT: {
glm_lookat(
camera->lookat.position,
camera->lookat.target,
@@ -105,8 +106,9 @@ void cameraPushMatrix(camera_t *camera) {
view
);
break;
}
case CAMERA_VIEW_TYPE_LOOKAT_PIXEL_PERFECT:
case CAMERA_VIEW_TYPE_LOOKAT_PIXEL_PERFECT: {
assertTrue(
camera->projType == CAMERA_PROJECTION_TYPE_PERSPECTIVE ||
camera->projType == CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED,
@@ -133,8 +135,9 @@ void cameraPushMatrix(camera_t *camera) {
view
);
break;
}
case CAMERA_VIEW_TYPE_2D:
case CAMERA_VIEW_TYPE_2D: {
glm_mat4_identity(view);
glm_translate(view, (vec3){
-camera->_2d.position[0],
@@ -147,6 +150,7 @@ void cameraPushMatrix(camera_t *camera) {
1.0f
});
break;
}
default:
assertUnreachable("Invalid camera view type");

View File

@@ -6,8 +6,8 @@
*/
#pragma once
#include "dusk.h"
#include "display/color.h"
#include "dusk.hpp"
#include "display/color.hpp"
#define CAMERA_COUNT_MAX 4
@@ -17,12 +17,11 @@ typedef enum {
CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC
} cameraprojectiontype_t;
typedef enum {
CAMERA_VIEW_TYPE_MATRIX,
CAMERA_VIEW_TYPE_LOOKAT,
CAMERA_VIEW_TYPE_2D,
CAMERA_VIEW_TYPE_LOOKAT_PIXEL_PERFECT
} cameraviewtype_t;
typedef uint8_t cameraviewtype_t;
#define CAMERA_VIEW_TYPE_MATRIX 0x00
#define CAMERA_VIEW_TYPE_LOOKAT 0x01
#define CAMERA_VIEW_TYPE_2D 0x02
#define CAMERA_VIEW_TYPE_LOOKAT_PIXEL_PERFECT 0x03
typedef struct {
cameraprojectiontype_t projType;

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "dusk.h"
#include "dusk.hpp"
typedef float_t colorchannelf_t;
typedef uint8_t colorchannelb_t;

View File

@@ -5,15 +5,15 @@
* https://opensource.org/licenses/MIT
*/
#include "display/display.h"
#include "engine/engine.h"
#include "display/framebuffer.h"
#include "scene/scenemanager.h"
#include "display/spritebatch.h"
#include "display/mesh/quad.h"
#include "display/screen.h"
#include "ui/ui.h"
#include "debug/debug.h"
#include "display/display.hpp"
#include "engine/engine.hpp"
#include "display/framebuffer.hpp"
#include "scene/scenemanager.hpp"
#include "display/spritebatch.hpp"
#include "display/mesh/quad.hpp"
#include "display/screen.hpp"
#include "ui/ui.hpp"
#include "debug/debug.hpp"
display_t DISPLAY;

View File

@@ -6,10 +6,10 @@
*/
#pragma once
#include "displaydefs.h"
#include "error/error.h"
#include "display/camera.h"
#include "display/framebuffer.h"
#include "displaydefs.hpp"
#include "error/error.hpp"
#include "display/camera.hpp"
#include "display/framebuffer.hpp"
typedef struct {
#if DISPLAY_SDL2

View File

@@ -5,10 +5,10 @@
* https://opensource.org/licenses/MIT
*/
#include "framebuffer.h"
#include "display/display.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "framebuffer.hpp"
#include "display/display.hpp"
#include "assert/assert.hpp"
#include "util/memory.hpp"
framebuffer_t FRAMEBUFFER_BACKBUFFER = {0};
const framebuffer_t *FRAMEBUFFER_BOUND = &FRAMEBUFFER_BACKBUFFER;
@@ -31,9 +31,11 @@ void frameBufferInitBackbuffer() {
assertTrue(width > 0 && height > 0, "W/H must be greater than 0");
memoryZero(framebuffer, sizeof(framebuffer_t));
textureInit(&framebuffer->texture, width, height, GL_RGBA,(texturedata_t){
.rgba = { .colors = NULL }
});
textureInit(
&framebuffer->texture,
width, height, TEXTURE_FORMAT_RGBA,
(texturedata_t){ .rgba = { .colors = NULL } }
);
glGenFramebuffersEXT(1, &framebuffer->id);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer->id);

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "display/texture.h"
#include "display/texture.hpp"
#define FRAMEBUFFER_CLEAR_COLOR (1 << 0)
#define FRAMEBUFFER_CLEAR_DEPTH (1 << 1)

View File

@@ -6,6 +6,6 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
mesh.c
quad.c
mesh.cpp
quad.cpp
)

View File

@@ -5,9 +5,9 @@
* https://opensource.org/licenses/MIT
*/
#include "mesh.h"
#include "util/memory.h"
#include "assert/assert.h"
#include "mesh.hpp"
#include "util/memory.hpp"
#include "assert/assert.hpp"
void meshInit(
mesh_t *mesh,

View File

@@ -4,8 +4,8 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "display/display.h"
#include "display/color.h"
#include "display/display.hpp"
#include "display/color.hpp"
typedef enum {
#if DISPLAY_SDL2

View File

@@ -5,8 +5,8 @@
* https://opensource.org/licenses/MIT
*/
#include "quad.h"
#include "assert/assert.h"
#include "quad.hpp"
#include "assert/assert.hpp"
mesh_t QUAD_MESH_SIMPLE;
meshvertex_t QUAD_MESH_SIMPLE_VERTICES[QUAD_VERTEX_COUNT] = {

View File

@@ -6,8 +6,8 @@
*/
#pragma once
#include "mesh.h"
#include "display/color.h"
#include "mesh.hpp"
#include "display/color.hpp"
#define QUAD_VERTEX_COUNT 6
#define QUAD_PRIMITIVE_TYPE MESH_PRIMITIVE_TRIANGLES

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "display/color.h"
#include "display/color.hpp"
typedef struct {
const uint8_t colorCount;

View File

@@ -5,10 +5,10 @@
* https://opensource.org/licenses/MIT
*/
#include "screen.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "display/mesh/quad.h"
#include "screen.hpp"
#include "assert/assert.hpp"
#include "util/memory.hpp"
#include "display/mesh/quad.hpp"
screen_t SCREEN;

View File

@@ -6,10 +6,10 @@
*/
#pragma once
#include "dusk.h"
#include "display/framebuffer.h"
#include "display/camera.h"
#include "display/mesh/quad.h"
#include "dusk.hpp"
#include "display/framebuffer.hpp"
#include "display/camera.hpp"
#include "display/mesh/quad.hpp"
#if DISPLAY_SIZE_DYNAMIC == 1
#ifndef DISPLAY_SCREEN_HEIGHT_DEFAULT

View File

@@ -5,9 +5,9 @@
* https://opensource.org/licenses/MIT
*/
#include "spritebatch.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "spritebatch.hpp"
#include "assert/assert.hpp"
#include "util/memory.hpp"
spritebatch_t SPRITEBATCH;

View File

@@ -6,8 +6,8 @@
*/
#pragma once
#include "display/mesh/quad.h"
#include "display/texture.h"
#include "display/mesh/quad.hpp"
#include "display/texture.hpp"
#define SPRITEBATCH_SPRITES_MAX 1
#define SPRITEBATCH_VERTEX_COUNT (SPRITEBATCH_SPRITES_MAX * QUAD_VERTEX_COUNT)

View File

@@ -5,11 +5,11 @@
* https://opensource.org/licenses/MIT
*/
#include "texture.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "util/math.h"
#include "display/palette/palettelist.h"
#include "texture.hpp"
#include "assert/assert.hpp"
#include "util/memory.hpp"
#include "util/math.hpp"
#include "display/palette/palettelist.hpp"
const texture_t *TEXTURE_BOUND = NULL;
@@ -43,21 +43,23 @@ void textureInit(
glBindTexture(GL_TEXTURE_2D, texture->id);
switch(format) {
case TEXTURE_FORMAT_RGBA:
case TEXTURE_FORMAT_RGBA: {
glTexImage2D(
GL_TEXTURE_2D, 0, format, width, height, 0,
format, GL_UNSIGNED_BYTE, (void*)data.rgba.colors
);
break;
}
case TEXTURE_FORMAT_ALPHA:
case TEXTURE_FORMAT_ALPHA: {
glTexImage2D(
GL_TEXTURE_2D, 0, format, width, height, 0,
format, GL_UNSIGNED_BYTE, (void*)data.alpha.data
);
break;
}
case TEXTURE_FORMAT_PALETTE:
case TEXTURE_FORMAT_PALETTE: {
assertNotNull(data.palette.data, "Palette texture data cannot be NULL");
assertTrue(
data.palette.palette < PALETTE_LIST_COUNT,
@@ -130,8 +132,8 @@ void textureInit(
GL_UNSIGNED_BYTE, (const void*)pal->colors
);
}
break;
}
default:
assertUnreachable("Unknown texture format");

View File

@@ -6,8 +6,8 @@
*/
#pragma once
#include "display/color.h"
#include "display/displaydefs.h"
#include "display/color.hpp"
#include "display/displaydefs.hpp"
typedef enum {
#if DISPLAY_SDL2

View File

@@ -6,5 +6,5 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
tileset.c
tileset.cpp
)

View File

@@ -5,7 +5,7 @@
* https://opensource.org/licenses/MIT
*/
#include "tileset.h"
#include "tileset.hpp"
void tilesetTileGetUV(
const tileset_t *tileset,

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "dusk.h"
#include "dusk.hpp"
typedef struct tileset_s {
const uint16_t tileWidth;

View File

@@ -1,35 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <errno.h>
#include <ctype.h>
#include <stdarg.h>
#include <float.h>
#include <cglm/cglm.h>
#include <cglm/types.h>
#include <cglm/vec2.h>
#if PSP
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <psphprm.h>
#endif
typedef bool bool_t;
typedef int int_t;
typedef float float_t;
typedef char char_t;

38
src/dusk.hpp Normal file
View File

@@ -0,0 +1,38 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <errno.h>
#include <ctype.h>
#include <stdarg.h>
#include <float.h>
#include <cglm/cglm.h>
#include <cglm/types.h>
#include <cglm/vec2.h>
#if PSP
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <psphprm.h>
#endif
typedef bool bool_t;
typedef int int_t;
typedef float float_t;
typedef char char_t;
}

View File

@@ -6,5 +6,5 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
engine.c
engine.cpp
)

View File

@@ -5,20 +5,20 @@
* https://opensource.org/licenses/MIT
*/
#include "engine.h"
#include "util/memory.h"
#include "time/time.h"
#include "input/input.h"
#include "locale/localemanager.h"
#include "display/display.h"
#include "scene/scenemanager.h"
#include "asset/asset.h"
#include "ui/ui.h"
#include "rpg/rpg.h"
#include "script/scriptmanager.h"
#include "debug/debug.h"
#include "engine.hpp"
#include "util/memory.hpp"
#include "time/time.hpp"
#include "input/input.hpp"
#include "locale/localemanager.hpp"
#include "display/display.hpp"
#include "scene/scenemanager.hpp"
#include "asset/asset.hpp"
#include "ui/ui.hpp"
#include "rpg/rpg.hpp"
#include "script/scriptmanager.hpp"
#include "debug/debug.hpp"
#include "script/scriptcontext.h"
#include "script/scriptcontext.hpp"
engine_t ENGINE;

View File

@@ -6,8 +6,8 @@
*/
#pragma once
#include "display/display.h"// Important to be included first.
#include "error/error.h"
#include "display/display.hpp"// Important to be included first.
#include "error/error.hpp"
typedef struct {
bool_t running;

View File

@@ -6,5 +6,5 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
error.c
error.cpp
)

View File

@@ -5,11 +5,11 @@
* https://opensource.org/licenses/MIT
*/
#include "assert/assert.h"
#include "error.h"
#include "util/memory.h"
#include "util/string.h"
#include "debug/debug.h"
#include "assert/assert.hpp"
#include "error.hpp"
#include "util/memory.hpp"
#include "util/string.hpp"
#include "debug/debug.hpp"
errorstate_t ERROR_STATE = { 0 };

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "dusk.h"
#include "dusk.hpp"
typedef uint8_t errorcode_t;

View File

@@ -6,9 +6,9 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
input.c
inputbutton.c
inputaction.c
input.cpp
inputbutton.cpp
inputaction.cpp
)
if(DUSK_TARGET_SYSTEM STREQUAL "linux")

View File

@@ -5,12 +5,12 @@
* https://opensource.org/licenses/MIT
*/
#include "input.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "util/string.h"
#include "util/math.h"
#include "time/time.h"
#include "input.hpp"
#include "assert/assert.hpp"
#include "util/memory.hpp"
#include "util/string.hpp"
#include "util/math.hpp"
#include "time/time.hpp"
input_t INPUT;

View File

@@ -6,8 +6,8 @@
*/
#pragma once
#include "inputbutton.h"
#include "inputaction.h"
#include "inputbutton.hpp"
#include "inputaction.hpp"
typedef struct {
inputactiondata_t actions[INPUT_ACTION_COUNT];

View File

@@ -5,9 +5,9 @@
* https://opensource.org/licenses/MIT
*/
#include "inputaction.h"
#include "assert/assert.h"
#include "util/string.h"
#include "inputaction.hpp"
#include "assert/assert.hpp"
#include "util/string.hpp"
// inputaction_t inputActionGetByName(const char_t *name) {
// assertNotNull(name, "name must not be NULL");

View File

@@ -6,20 +6,19 @@
*/
#pragma once
#include "time/time.h"
#include "time/time.hpp"
typedef enum {
INPUT_ACTION_NULL,
INPUT_ACTION_UP,
INPUT_ACTION_DOWN,
INPUT_ACTION_LEFT,
INPUT_ACTION_RIGHT,
INPUT_ACTION_ACCEPT,
INPUT_ACTION_CANCEL,
INPUT_ACTION_RAGEQUIT,
typedef uint8_t inputaction_t;
INPUT_ACTION_COUNT
} inputaction_t;
#define INPUT_ACTION_NULL 0x00
#define INPUT_ACTION_UP 0x01
#define INPUT_ACTION_DOWN 0x02
#define INPUT_ACTION_LEFT 0x03
#define INPUT_ACTION_RIGHT 0x04
#define INPUT_ACTION_ACCEPT 0x05
#define INPUT_ACTION_CANCEL 0x06
#define INPUT_ACTION_RAGEQUIT 0x07
#define INPUT_ACTION_COUNT INPUT_ACTION_RAGEQUIT + 1
typedef struct {
inputaction_t action;

View File

@@ -1,233 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "inputbutton.h"
#include "input.h"
#include "assert/assert.h"
#include "util/string.h"
inputbuttondata_t INPUT_BUTTON_DATA[] = {
#if INPUT_SDL2 == 1
#if INPUT_GAMEPAD == 1
#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
#endif
#endif
#if INPUT_KEYBOARD == 1
{ .name = "a", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_A } },
{ .name = "b", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_B } },
{ .name = "c", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_C } },
{ .name = "d", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_D } },
{ .name = "e", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_E } },
{ .name = "f", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F } },
{ .name = "g", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_G } },
{ .name = "h", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_H } },
{ .name = "i", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_I } },
{ .name = "j", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_J } },
{ .name = "k", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_K } },
{ .name = "l", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_L } },
{ .name = "m", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_M } },
{ .name = "n", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_N } },
{ .name = "o", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_O } },
{ .name = "p", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_P } },
{ .name = "q", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_Q } },
{ .name = "r", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_R } },
{ .name = "s", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_S } },
{ .name = "t", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_T } },
{ .name = "u", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_U } },
{ .name = "v", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_V } },
{ .name = "w", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_W } },
{ .name = "x", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_X } },
{ .name = "y", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_Y } },
{ .name = "z", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_Z } },
{ .name = "0", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_0 } },
{ .name = "1", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_1 } },
{ .name = "2", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_2 } },
{ .name = "3", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_3 } },
{ .name = "4", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_4 } },
{ .name = "5", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_5 } },
{ .name = "6", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_6 } },
{ .name = "7", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_7 } },
{ .name = "8", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_8 } },
{ .name = "9", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_9 } },
{ .name = "space", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_SPACE } },
{ .name = "shift", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LSHIFT } },
{ .name = "lshift", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LSHIFT } },
{ .name = "rshift", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_RSHIFT } },
{ .name = "lctrl", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LCTRL } },
{ .name = "rctrl", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_RCTRL } },
{ .name = "ctrl", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LCTRL } },
{ .name = "lalt", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LALT } },
{ .name = "ralt", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_RALT } },
{ .name = "tab", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_TAB } },
{ .name = "enter", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_RETURN } },
{ .name = "backspace", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_BACKSPACE } },
{ .name = "escape", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_ESCAPE } },
{ .name = "esc", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_ESCAPE } },
{ .name = "up", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_UP } },
{ .name = "down", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_DOWN } },
{ .name = "left", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LEFT } },
{ .name = "right", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_RIGHT } },
{ .name = "pageup", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_PAGEUP } },
{ .name = "pagedown", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_PAGEDOWN } },
{ .name = "home", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_HOME } },
{ .name = "end", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_END } },
{ .name = "insert", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_INSERT } },
{ .name = "delete", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_DELETE } },
{ .name = "f1", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F1 } },
{ .name = "f2", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F2 } },
{ .name = "f3", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F3 } },
{ .name = "f4", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F4 } },
{ .name = "f5", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F5 } },
{ .name = "f6", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F6 } },
{ .name = "f7", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F7 } },
{ .name = "f8", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F8 } },
{ .name = "f9", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F9 } },
{ .name = "f10", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F10 } },
{ .name = "f11", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F11 } },
{ .name = "f12", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F12 } },
{ .name = "f13", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F13 } },
{ .name = "f14", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F14 } },
{ .name = "f15", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F15 } },
{ .name = "f16", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F16 } },
{ .name = "f17", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F17 } },
{ .name = "f18", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F18 } },
{ .name = "f19", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F19 } },
{ .name = "f20", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F20 } },
{ .name = "f21", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F21 } },
{ .name = "f22", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F22 } },
{ .name = "f23", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F23 } },
{ .name = "f24", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F24 } },
{ .name = "minus", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_MINUS } },
{ .name = "equals", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_EQUALS } },
{ .name = "leftbracket", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LEFTBRACKET } },
{ .name = "rightbracket", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_RIGHTBRACKET } },
{ .name = "backslash", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_BACKSLASH } },
{ .name = "semicolon", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_SEMICOLON } },
{ .name = "apostrophe", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_APOSTROPHE } },
{ .name = "grave", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_GRAVE } },
{ .name = "comma", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_COMMA } },
{ .name = "period", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_PERIOD } },
{ .name = "slash", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_SLASH } },
{ .name = "caps", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_CAPSLOCK } },
{ .name = "capslock", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_CAPSLOCK } },
{ .name = "numlock", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_NUMLOCKCLEAR } },
{ .name = "scrollock", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_SCROLLLOCK } },
{ .name = "-", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_MINUS } },
{ .name = "=", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_EQUALS } },
{ .name = "[", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LEFTBRACKET } },
{ .name = "]", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_RIGHTBRACKET } },
{ .name = "\\", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_BACKSLASH } },
{ .name = ";", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_SEMICOLON } },
{ .name = "'", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_APOSTROPHE } },
{ .name = "`", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_GRAVE } },
{ .name = ",", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_COMMA } },
{ .name = ".", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_PERIOD } },
{ .name = "/", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_SLASH } },
{ .name = "kp_0", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_0 } },
{ .name = "kp_1", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_1 } },
{ .name = "kp_2", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_2 } },
{ .name = "kp_3", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_3 } },
{ .name = "kp_4", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_4 } },
{ .name = "kp_5", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_5 } },
{ .name = "kp_6", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_6 } },
{ .name = "kp_7", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_7 } },
{ .name = "kp_8", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_8 } },
{ .name = "kp_9", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_9 } },
{ .name = "kp_period", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_PERIOD } },
{ .name = "kp_divide", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_DIVIDE } },
{ .name = "kp_multiply", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_MULTIPLY } },
{ .name = "kp_minus", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_MINUS } },
{ .name = "kp_plus", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_PLUS } },
{ .name = "kp_enter", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_ENTER } },
{ .name = "kp_equals", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_EQUALS } },
#endif
#endif
{ .name = NULL }
};
inputbutton_t inputButtonGetByName(const char_t *name) {
assertNotNull(name, "name must not be NULL");
inputbuttondata_t *data = INPUT_BUTTON_DATA;
while(data->name != NULL) {
if(stringCompareInsensitive(data->name, name) == 0) {
return data->button;
}
data++;
}
return (inputbutton_t){ .type = INPUT_BUTTON_TYPE_NONE };
}
float_t inputButtonGetValue(const inputbutton_t button) {
switch(button.type) {
#if INPUT_KEYBOARD == 1
case INPUT_BUTTON_TYPE_KEYBOARD: {
#if INPUT_SDL2 == 1
return INPUT.keyboardState[button.scancode] ? 1.0f : 0.0f;
#else
return 0.0f;
#endif
}
#endif
#if INPUT_GAMEPAD == 1
case INPUT_BUTTON_TYPE_GAMEPAD: {
#if INPUT_SDL2 == 1
if(SDL_GameControllerGetButton(INPUT.controller, button.gpButton)) {
return 1.0f;
}
#endif
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
default: {
assertUnreachable("Unknown input button type");
return 0.0f;
}
}
}

233
src/input/inputbutton.cpp Normal file
View File

@@ -0,0 +1,233 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "inputbutton.hpp"
#include "input.hpp"
#include "assert/assert.hpp"
#include "util/string.hpp"
inputbuttondata_t INPUT_BUTTON_DATA[] = {
#if INPUT_SDL2 == 1
#if INPUT_GAMEPAD == 1
#if PSP
{ .name = "triangle", .button = { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_Y } },
{ .name = "cross", .button = { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_A } },
{ .name = "circle", .button = { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_B } },
{ .name = "square", .button = { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_X } },
{ .name = "start", .button = { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_START } },
{ .name = "select", .button = { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_BACK } },
{ .name = "up", .button = { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_UP } },
{ .name = "down", .button = { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_DOWN } },
{ .name = "left", .button = { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_LEFT } },
{ .name = "right", .button = { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_RIGHT } },
{ .name = "l", .button = { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_LEFTSHOULDER } },
{ .name = "r", .button = { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER } },
{ .name = "lstick_positive_x", .button = { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTX, .positive = true } } },
{ .name = "lstick_negative_x", .button = { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTX, .positive = false } } },
{ .name = "lstick_positive_y", .button = { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = true } } },
{ .name = "lstick_negative_y", .button = { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = false } } },
#else
#endif
#endif
#if INPUT_KEYBOARD == 1
{ .name = "a", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_A } },
{ .name = "b", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_B } },
{ .name = "c", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_C } },
{ .name = "d", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_D } },
{ .name = "e", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_E } },
{ .name = "f", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F } },
{ .name = "g", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_G } },
{ .name = "h", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_H } },
{ .name = "i", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_I } },
{ .name = "j", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_J } },
{ .name = "k", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_K } },
{ .name = "l", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_L } },
{ .name = "m", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_M } },
{ .name = "n", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_N } },
{ .name = "o", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_O } },
{ .name = "p", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_P } },
{ .name = "q", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_Q } },
{ .name = "r", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_R } },
{ .name = "s", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_S } },
{ .name = "t", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_T } },
{ .name = "u", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_U } },
{ .name = "v", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_V } },
{ .name = "w", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_W } },
{ .name = "x", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_X } },
{ .name = "y", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_Y } },
{ .name = "z", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_Z } },
{ .name = "0", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_0 } },
{ .name = "1", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_1 } },
{ .name = "2", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_2 } },
{ .name = "3", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_3 } },
{ .name = "4", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_4 } },
{ .name = "5", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_5 } },
{ .name = "6", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_6 } },
{ .name = "7", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_7 } },
{ .name = "8", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_8 } },
{ .name = "9", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_9 } },
{ .name = "space", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_SPACE } },
{ .name = "shift", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LSHIFT } },
{ .name = "lshift", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LSHIFT } },
{ .name = "rshift", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_RSHIFT } },
{ .name = "lctrl", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LCTRL } },
{ .name = "rctrl", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_RCTRL } },
{ .name = "ctrl", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LCTRL } },
{ .name = "lalt", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LALT } },
{ .name = "ralt", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_RALT } },
{ .name = "tab", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_TAB } },
{ .name = "enter", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_RETURN } },
{ .name = "backspace", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_BACKSPACE } },
{ .name = "escape", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_ESCAPE } },
{ .name = "esc", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_ESCAPE } },
{ .name = "up", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_UP } },
{ .name = "down", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_DOWN } },
{ .name = "left", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LEFT } },
{ .name = "right", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_RIGHT } },
{ .name = "pageup", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_PAGEUP } },
{ .name = "pagedown", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_PAGEDOWN } },
{ .name = "home", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_HOME } },
{ .name = "end", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_END } },
{ .name = "insert", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_INSERT } },
{ .name = "delete", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_DELETE } },
{ .name = "f1", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F1 } },
{ .name = "f2", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F2 } },
{ .name = "f3", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F3 } },
{ .name = "f4", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F4 } },
{ .name = "f5", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F5 } },
{ .name = "f6", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F6 } },
{ .name = "f7", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F7 } },
{ .name = "f8", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F8 } },
{ .name = "f9", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F9 } },
{ .name = "f10", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F10 } },
{ .name = "f11", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F11 } },
{ .name = "f12", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F12 } },
{ .name = "f13", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F13 } },
{ .name = "f14", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F14 } },
{ .name = "f15", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F15 } },
{ .name = "f16", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F16 } },
{ .name = "f17", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F17 } },
{ .name = "f18", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F18 } },
{ .name = "f19", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F19 } },
{ .name = "f20", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F20 } },
{ .name = "f21", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F21 } },
{ .name = "f22", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F22 } },
{ .name = "f23", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F23 } },
{ .name = "f24", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F24 } },
{ .name = "minus", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_MINUS } },
{ .name = "equals", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_EQUALS } },
{ .name = "leftbracket", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LEFTBRACKET } },
{ .name = "rightbracket", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_RIGHTBRACKET } },
{ .name = "backslash", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_BACKSLASH } },
{ .name = "semicolon", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_SEMICOLON } },
{ .name = "apostrophe", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_APOSTROPHE } },
{ .name = "grave", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_GRAVE } },
{ .name = "comma", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_COMMA } },
{ .name = "period", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_PERIOD } },
{ .name = "slash", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_SLASH } },
{ .name = "caps", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_CAPSLOCK } },
{ .name = "capslock", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_CAPSLOCK } },
{ .name = "numlock", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_NUMLOCKCLEAR } },
{ .name = "scrollock", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_SCROLLLOCK } },
{ .name = "-", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_MINUS } },
{ .name = "=", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_EQUALS } },
{ .name = "[", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LEFTBRACKET } },
{ .name = "]", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_RIGHTBRACKET } },
{ .name = "\\", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_BACKSLASH } },
{ .name = ";", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_SEMICOLON } },
{ .name = "'", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_APOSTROPHE } },
{ .name = "`", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_GRAVE } },
{ .name = ",", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_COMMA } },
{ .name = ".", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_PERIOD } },
{ .name = "/", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_SLASH } },
{ .name = "kp_0", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_0 } },
{ .name = "kp_1", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_1 } },
{ .name = "kp_2", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_2 } },
{ .name = "kp_3", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_3 } },
{ .name = "kp_4", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_4 } },
{ .name = "kp_5", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_5 } },
{ .name = "kp_6", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_6 } },
{ .name = "kp_7", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_7 } },
{ .name = "kp_8", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_8 } },
{ .name = "kp_9", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_9 } },
{ .name = "kp_period", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_PERIOD } },
{ .name = "kp_divide", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_DIVIDE } },
{ .name = "kp_multiply", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_MULTIPLY } },
{ .name = "kp_minus", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_MINUS } },
{ .name = "kp_plus", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_PLUS } },
{ .name = "kp_enter", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_ENTER } },
{ .name = "kp_equals", .button = { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_EQUALS } },
#endif
#endif
{ .name = NULL }
};
inputbutton_t inputButtonGetByName(const char_t *name) {
assertNotNull(name, "name must not be NULL");
inputbuttondata_t *data = INPUT_BUTTON_DATA;
while(data->name != NULL) {
if(stringCompareInsensitive(data->name, name) == 0) {
return data->button;
}
data++;
}
return (inputbutton_t){ .type = INPUT_BUTTON_TYPE_NONE };
}
float_t inputButtonGetValue(const inputbutton_t button) {
switch(button.type) {
#if INPUT_KEYBOARD == 1
case INPUT_BUTTON_TYPE_KEYBOARD: {
#if INPUT_SDL2 == 1
return INPUT.keyboardState[button.scancode] ? 1.0f : 0.0f;
#else
return 0.0f;
#endif
}
#endif
#if INPUT_GAMEPAD == 1
case INPUT_BUTTON_TYPE_GAMEPAD: {
#if INPUT_SDL2 == 1
if(SDL_GameControllerGetButton(INPUT.controller, button.gpButton)) {
return 1.0f;
}
#endif
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
default: {
assertUnreachable("Unknown input button type");
return 0.0f;
}
}
}

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "inputaction.h"
#include "inputaction.hpp"
#if INPUT_SDL2 == 1
#include <SDL2/SDL.h>

View File

@@ -6,5 +6,5 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
localemanager.c
localemanager.cpp
)

View File

@@ -5,10 +5,10 @@
* https://opensource.org/licenses/MIT
*/
#include "localemanager.h"
#include "util/memory.h"
#include "asset/asset.h"
#include "assert/assert.h"
#include "localemanager.hpp"
#include "util/memory.hpp"
#include "asset/asset.hpp"
#include "assert/assert.hpp"
localemanager_t LOCALE;

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "asset/asset.h"
#include "asset/asset.hpp"
typedef enum {
DUSK_LOCALE_EN_US,

View File

@@ -5,10 +5,10 @@
* https://opensource.org/licenses/MIT
*/
#include "engine/engine.h"
#include "asset/asset.h"
#include "util/string.h"
#include "input/input.h"
#include "engine/engine.hpp"
#include "asset/asset.hpp"
#include "util/string.hpp"
#include "input/input.hpp"
int main(int argc, char **argv) {
// Main applet

View File

@@ -6,9 +6,9 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
rpg.c
rpgcamera.c
rpgtextbox.c
rpg.cpp
rpgcamera.cpp
rpgtextbox.cpp
)
# Subdirs

View File

@@ -6,8 +6,8 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
cutscenesystem.c
cutscenemode.c
cutscenesystem.cpp
cutscenemode.cpp
)
# Subdirs

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "rpg/cutscene/item/cutsceneitem.h"
#include "rpg/cutscene/item/cutsceneitem.hpp"
typedef struct cutscene_s {
const cutsceneitem_t *items;

View File

@@ -5,7 +5,7 @@
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/cutscenesystem.h"
#include "rpg/cutscene/cutscenesystem.hpp"
bool_t cutsceneModeIsInputAllowed() {
switch(CUTSCENE_SYSTEM.mode) {

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "dusk.h"
#include "dusk.hpp"
typedef enum {
CUTSCENE_MODE_NONE,

View File

@@ -5,8 +5,8 @@
* https://opensource.org/licenses/MIT
*/
#include "cutscenesystem.h"
#include "util/memory.h"
#include "cutscenesystem.hpp"
#include "util/memory.hpp"
cutscenesystem_t CUTSCENE_SYSTEM;

View File

@@ -6,8 +6,8 @@
*/
#pragma once
#include "cutscene.h"
#include "cutscenemode.h"
#include "cutscene.hpp"
#include "cutscenemode.hpp"
typedef struct {
const cutscene_t *scene;

View File

@@ -6,5 +6,5 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
cutsceneitem.c
cutsceneitem.cpp
)

View File

@@ -6,6 +6,6 @@
*/
#pragma once
#include "dusk.h"
#include "dusk.hpp"
typedef void (*cutscenecallback_t)(void);

View File

@@ -6,8 +6,6 @@
*/
#pragma once
#include "dusk.h"
#include "dusk.hpp"
typedef struct cutscene_s cutscene_t;
typedef cutscene_t* cutscenecutscene_t;

View File

@@ -5,9 +5,9 @@
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/cutscenesystem.h"
#include "input/input.h"
#include "time/time.h"
#include "rpg/cutscene/cutscenesystem.hpp"
#include "input/input.hpp"
#include "time/time.hpp"
void cutsceneItemStart(const cutsceneitem_t *item, cutsceneitemdata_t *data) {
switch(item->type) {

View File

@@ -6,10 +6,10 @@
*/
#pragma once
#include "cutscenewait.h"
#include "cutscenecallback.h"
#include "cutscenetext.h"
#include "cutscenecutscene.h"
#include "cutscenewait.hpp"
#include "cutscenecallback.hpp"
#include "cutscenetext.hpp"
#include "cutscenecutscene.hpp"
typedef enum {
CUTSCENE_ITEM_TYPE_NULL,
@@ -27,7 +27,7 @@ typedef struct cutsceneitem_s {
cutscenetext_t text;
cutscenecallback_t callback;
cutscenewait_t wait;
const cutscenecutscene_t cutscene;
const cutscene_t *cutscene;
};
} cutsceneitem_t;

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "rpg/rpgtextbox.h"
#include "rpg/rpgtextbox.hpp"
typedef struct {
char_t text[RPG_TEXTBOX_MAX_CHARS];

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "dusk.h"
#include "dusk.hpp"
typedef float_t cutscenewait_t;
typedef float_t cutscenewaitdata_t;

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "rpg/cutscene/cutscenesystem.h"
#include "rpg/cutscene/cutscenesystem.hpp"
static const cutsceneitem_t TEST_CUTSCENE_ONE_ITEMS[] = {
{ .type = CUTSCENE_ITEM_TYPE_TEXT, .text = { .text = "This is a test cutscene.", .position = RPG_TEXTBOX_POS_BOTTOM } },

View File

@@ -6,9 +6,9 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
entity.c
entityanim.c
npc.c
player.c
entitydir.c
entity.cpp
entityanim.cpp
npc.cpp
player.cpp
entitydir.cpp
)

View File

@@ -5,13 +5,13 @@
* https://opensource.org/licenses/MIT
*/
#include "entity.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "time/time.h"
#include "util/math.h"
#include "rpg/cutscene/cutscenemode.h"
#include "rpg/world/map.h"
#include "entity.hpp"
#include "assert/assert.hpp"
#include "util/memory.hpp"
#include "time/time.hpp"
#include "util/math.hpp"
#include "rpg/cutscene/cutscenemode.hpp"
#include "rpg/world/map.hpp"
entity_t ENTITIES[ENTITY_COUNT];

View File

@@ -6,17 +6,17 @@
*/
#pragma once
#include "entitydir.h"
#include "entityanim.h"
#include "entitytype.h"
#include "npc.h"
#include "entitydir.hpp"
#include "entityanim.hpp"
#include "entitytype.hpp"
#include "npc.hpp"
typedef struct map_s map_t;
typedef struct entity_s {
uint8_t id;
entitytype_t type;
entitytypedata_t;
entitytypedata_t data;
// Movement
entitydir_t direction;

View File

@@ -5,5 +5,5 @@
* https://opensource.org/licenses/MIT
*/
#include "entityanim.h"
#include "entityanim.hpp"

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "dusk.h"
#include "dusk.hpp"
#define ENTITY_ANIM_TURN_DURATION 0.06f
#define ENTITY_ANIM_WALK_DURATION 0.1f

View File

@@ -5,8 +5,8 @@
* https://opensource.org/licenses/MIT
*/
#include "entitydir.h"
#include "assert/assert.h"
#include "entitydir.hpp"
#include "assert/assert.hpp"
entitydir_t entityDirGetOpposite(const entitydir_t dir) {
switch(dir) {

View File

@@ -6,14 +6,13 @@
*/
#pragma once
#include "rpg/world/worldpos.h"
#include "rpg/world/worldpos.hpp"
typedef enum {
ENTITY_DIR_UP = ENTITY_DIR_NORTH,
ENTITY_DIR_DOWN = ENTITY_DIR_SOUTH,
ENTITY_DIR_LEFT = ENTITY_DIR_WEST,
ENTITY_DIR_RIGHT = ENTITY_DIR_EAST,
} entitydir_t;
typedef uint8_t entitydir_t;
#define ENTITY_DIR_UP ENTITY_DIR_NORTH
#define ENTITY_DIR_DOWN ENTITY_DIR_SOUTH
#define ENTITY_DIR_LEFT ENTITY_DIR_WEST
#define ENTITY_DIR_RIGHT ENTITY_DIR_EAST
/**
* Gets the opposite direction of a given direction.

View File

@@ -6,9 +6,9 @@
*/
#pragma once
#include "duskdefs.h"
#include "rpg/entity/player.h"
#include "npc.h"
#include "duskdefs.hpp"
#include "rpg/entity/player.hpp"
#include "npc.hpp"
typedef uint8_t entitytype_t;

View File

@@ -5,11 +5,11 @@
* https://opensource.org/licenses/MIT
*/
#include "entity.h"
#include "assert/assert.h"
#include "entity.hpp"
#include "assert/assert.hpp"
#include "rpg/cutscene/scene/testcutscene.h"
#include "rpg/rpgtextbox.h"
#include "rpg/cutscene/scene/testcutscene.hpp"
#include "rpg/rpgtextbox.hpp"
void npcInit(entity_t *entity) {
assertNotNull(entity, "Entity pointer cannot be NULL");

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "dusk.h"
#include "dusk.hpp"
typedef struct entity_s entity_t;

View File

@@ -5,11 +5,11 @@
* https://opensource.org/licenses/MIT
*/
#include "entity.h"
#include "assert/assert.h"
#include "rpg/rpgcamera.h"
#include "util/memory.h"
#include "time/time.h"
#include "entity.hpp"
#include "assert/assert.hpp"
#include "rpg/rpgcamera.hpp"
#include "util/memory.hpp"
#include "time/time.hpp"
void playerInit(entity_t *entity) {
assertNotNull(entity, "Entity pointer cannot be NULL");

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "input/input.h"
#include "input/input.hpp"
typedef struct entity_s entity_t;
@@ -24,8 +24,7 @@ static const playerinputdirmap_t PLAYER_INPUT_DIR_MAP[] = {
{ INPUT_ACTION_DOWN, ENTITY_DIR_SOUTH },
{ INPUT_ACTION_LEFT, ENTITY_DIR_WEST },
{ INPUT_ACTION_RIGHT, ENTITY_DIR_EAST },
{ 0xFF, 0xFF }
{ .action = 0xFF, .direction = 0xFF }
};
/**

View File

@@ -5,15 +5,15 @@
* https://opensource.org/licenses/MIT
*/
#include "rpg.h"
#include "entity/entity.h"
#include "rpg/world/map.h"
#include "rpg/cutscene/cutscenesystem.h"
#include "time/time.h"
#include "rpgcamera.h"
#include "rpgtextbox.h"
#include "util/memory.h"
#include "assert/assert.h"
#include "rpg.hpp"
#include "entity/entity.hpp"
#include "rpg/world/map.hpp"
#include "rpg/cutscene/cutscenesystem.hpp"
#include "time/time.hpp"
#include "rpgcamera.hpp"
#include "rpgtextbox.hpp"
#include "util/memory.hpp"
#include "assert/assert.hpp"
errorret_t rpgInit(void) {
memoryZero(ENTITIES, sizeof(ENTITIES));

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "error/error.h"
#include "error/error.hpp"
typedef struct {
int32_t nothing;

Some files were not shown because too many files have changed in this diff Show More