From 76b5c51ab6fe817fc21ace2f3a7b8ec3a95a6910 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 22 Dec 2025 11:41:49 +1000 Subject: [PATCH] C -> CPP --- CMakeLists.txt | 4 +- README.md | 2 +- cmake/modules/envtoh.cmake | 2 +- src/CMakeLists.txt | 4 +- src/assert/CMakeLists.txt | 2 +- src/assert/{assert.c => assert.cpp} | 4 +- src/assert/{assert.h => assert.hpp} | 6 +- src/asset/CMakeLists.txt | 2 +- src/asset/{asset.c => asset.cpp} | 18 +- src/asset/{asset.h => asset.hpp} | 2 +- src/asset/assettype.h | 21 +- src/asset/type/CMakeLists.txt | 12 +- ...{assetalphaimage.c => assetalphaimage.cpp} | 6 +- ...{assetalphaimage.h => assetalphaimage.hpp} | 2 +- .../type/{assetchunk.c => assetchunk.cpp} | 6 +- .../type/{assetchunk.h => assetchunk.hpp} | 4 +- .../{assetlanguage.c => assetlanguage.cpp} | 6 +- .../{assetlanguage.h => assetlanguage.hpp} | 6 +- src/asset/type/{assetmap.c => assetmap.cpp} | 6 +- src/asset/type/{assetmap.h => assetmap.hpp} | 6 +- ...etpaletteimage.c => assetpaletteimage.cpp} | 6 +- ...etpaletteimage.h => assetpaletteimage.hpp} | 2 +- .../type/{assetscript.c => assetscript.cpp} | 4 +- .../type/{assetscript.h => assetscript.hpp} | 6 +- src/debug/CMakeLists.txt | 2 +- src/debug/{debug.c => debug.cpp} | 2 +- src/debug/{debug.h => debug.hpp} | 2 +- src/display/CMakeLists.txt | 12 +- src/display/{camera.c => camera.cpp} | 22 +- src/display/{camera.h => camera.hpp} | 15 +- src/display/{color.h => color.hpp} | 2 +- src/display/{display.c => display.cpp} | 18 +- src/display/{display.h => display.hpp} | 8 +- .../{displaydefs.h => displaydefs.hpp} | 0 .../{framebuffer.c => framebuffer.cpp} | 16 +- .../{framebuffer.h => framebuffer.hpp} | 2 +- src/display/mesh/CMakeLists.txt | 4 +- src/display/mesh/{mesh.c => mesh.cpp} | 6 +- src/display/mesh/{mesh.h => mesh.hpp} | 4 +- src/display/mesh/{quad.c => quad.cpp} | 4 +- src/display/mesh/{quad.h => quad.hpp} | 4 +- .../palette/{palette.h => palette.hpp} | 2 +- src/display/{screen.c => screen.cpp} | 8 +- src/display/{screen.h => screen.hpp} | 8 +- .../{spritebatch.c => spritebatch.cpp} | 6 +- .../{spritebatch.h => spritebatch.hpp} | 4 +- src/display/{texture.c => texture.cpp} | 20 +- src/display/{texture.h => texture.hpp} | 4 +- src/display/tileset/CMakeLists.txt | 2 +- .../tileset/{tileset.c => tileset.cpp} | 2 +- .../tileset/{tileset.h => tileset.hpp} | 2 +- src/dusk.h | 35 --- src/dusk.hpp | 38 +++ src/engine/CMakeLists.txt | 2 +- src/engine/{engine.c => engine.cpp} | 26 +- src/engine/{engine.h => engine.hpp} | 4 +- src/error/CMakeLists.txt | 2 +- src/error/{error.c => error.cpp} | 10 +- src/error/{error.h => error.hpp} | 2 +- src/input/CMakeLists.txt | 6 +- src/input/{input.c => input.cpp} | 12 +- src/input/{input.h => input.hpp} | 4 +- src/input/{inputaction.c => inputaction.cpp} | 6 +- src/input/{inputaction.h => inputaction.hpp} | 23 +- src/input/inputbutton.c | 233 ------------------ src/input/inputbutton.cpp | 233 ++++++++++++++++++ src/input/{inputbutton.h => inputbutton.hpp} | 2 +- src/locale/CMakeLists.txt | 2 +- .../{localemanager.c => localemanager.cpp} | 8 +- .../{localemanager.h => localemanager.hpp} | 2 +- src/{main.c => main.cpp} | 8 +- src/rpg/CMakeLists.txt | 6 +- src/rpg/cutscene/CMakeLists.txt | 4 +- src/rpg/cutscene/{cutscene.h => cutscene.hpp} | 2 +- .../{cutscenemode.c => cutscenemode.cpp} | 2 +- .../{cutscenemode.h => cutscenemode.hpp} | 2 +- .../{cutscenesystem.c => cutscenesystem.cpp} | 4 +- .../{cutscenesystem.h => cutscenesystem.hpp} | 4 +- src/rpg/cutscene/item/CMakeLists.txt | 2 +- ...utscenecallback.h => cutscenecallback.hpp} | 2 +- ...utscenecutscene.h => cutscenecutscene.hpp} | 6 +- .../item/{cutsceneitem.c => cutsceneitem.cpp} | 6 +- .../item/{cutsceneitem.h => cutsceneitem.hpp} | 10 +- .../item/{cutscenetext.h => cutscenetext.hpp} | 2 +- .../item/{cutscenewait.h => cutscenewait.hpp} | 2 +- .../{testcutscene.h => testcutscene.hpp} | 2 +- src/rpg/entity/CMakeLists.txt | 10 +- src/rpg/entity/{entity.c => entity.cpp} | 14 +- src/rpg/entity/{entity.h => entity.hpp} | 10 +- .../entity/{entityanim.c => entityanim.cpp} | 2 +- .../entity/{entityanim.h => entityanim.hpp} | 2 +- src/rpg/entity/{entitydir.c => entitydir.cpp} | 4 +- src/rpg/entity/{entitydir.h => entitydir.hpp} | 13 +- .../entity/{entitytype.h => entitytype.hpp} | 6 +- src/rpg/entity/{npc.c => npc.cpp} | 8 +- src/rpg/entity/{npc.h => npc.hpp} | 2 +- src/rpg/entity/{player.c => player.cpp} | 10 +- src/rpg/entity/{player.h => player.hpp} | 5 +- src/rpg/{rpg.c => rpg.cpp} | 18 +- src/rpg/{rpg.h => rpg.hpp} | 2 +- src/rpg/{rpgcamera.c => rpgcamera.cpp} | 10 +- src/rpg/{rpgcamera.h => rpgcamera.hpp} | 4 +- src/rpg/{rpgtextbox.c => rpgtextbox.cpp} | 8 +- src/rpg/{rpgtextbox.h => rpgtextbox.hpp} | 2 +- src/rpg/world/CMakeLists.txt | 8 +- src/rpg/world/{chunk.c => chunk.cpp} | 2 +- src/rpg/world/{chunk.h => chunk.hpp} | 6 +- src/rpg/world/{map.c => map.cpp} | 10 +- src/rpg/world/{map.h => map.hpp} | 2 +- src/rpg/world/{tile.c => tile.cpp} | 2 +- src/rpg/world/{tile.h => tile.hpp} | 2 +- src/rpg/world/{worldpos.c => worldpos.cpp} | 4 +- src/rpg/world/{worldpos.h => worldpos.hpp} | 4 +- src/scene/CMakeLists.txt | 2 +- src/scene/{scene.h => scene.hpp} | 6 +- src/scene/scene/CMakeLists.txt | 4 +- src/scene/scene/{scenemap.c => scenemap.cpp} | 22 +- src/scene/scene/{scenemap.h => scenemap.hpp} | 8 +- .../scene/{scenetest.c => scenetest.cpp} | 4 +- .../scene/{scenetest.h => scenetest.hpp} | 2 +- src/scene/{scenedata.h => scenedata.hpp} | 6 +- .../{scenemanager.c => scenemanager.cpp} | 10 +- .../{scenemanager.h => scenemanager.hpp} | 4 +- src/script/CMakeLists.txt | 4 +- ...criptfunccamera.h => scriptfunccamera.hpp} | 4 +- ...criptfuncentity.h => scriptfuncentity.hpp} | 6 +- ...criptfuncsystem.h => scriptfuncsystem.hpp} | 6 +- .../{scriptcontext.c => scriptcontext.cpp} | 16 +- .../{scriptcontext.h => scriptcontext.hpp} | 13 +- .../{scriptmanager.c => scriptmanager.cpp} | 10 +- .../{scriptmanager.h => scriptmanager.hpp} | 4 +- src/script/{scriptvalue.h => scriptvalue.hpp} | 2 +- src/thread/CMakeLists.txt | 4 +- src/thread/{thread.c => thread.cpp} | 6 +- src/thread/{thread.h => thread.hpp} | 2 +- src/thread/{threadmutex.c => threadmutex.cpp} | 2 +- src/thread/{threadmutex.h => threadmutex.hpp} | 2 +- src/time/CMakeLists.txt | 2 +- src/time/{time.c => time.cpp} | 6 +- src/time/{time.h => time.hpp} | 2 +- src/ui/CMakeLists.txt | 10 +- .../{uielementtype.h => uielementtype.hpp} | 0 src/ui/{ui.c => ui.cpp} | 14 +- src/ui/{ui.h => ui.hpp} | 8 +- src/ui/{uidebug.c => uidebug.cpp} | 14 +- src/ui/{uidebug.h => uidebug.hpp} | 4 +- src/ui/{uiframe.c => uiframe.cpp} | 6 +- src/ui/{uiframe.h => uiframe.hpp} | 4 +- src/ui/{uitext.c => uitext.cpp} | 8 +- src/ui/{uitext.h => uitext.hpp} | 6 +- src/ui/{uitextbox.c => uitextbox.cpp} | 14 +- src/ui/{uitextbox.h => uitextbox.hpp} | 2 +- src/util/CMakeLists.txt | 6 +- src/util/{math.c => math.cpp} | 2 +- src/util/{math.h => math.hpp} | 2 +- src/util/{memory.c => memory.cpp} | 4 +- src/util/{memory.h => memory.hpp} | 2 +- src/util/{string.c => string.cpp} | 6 +- src/util/{string.h => string.hpp} | 2 +- tools/assetstool/processlanguage.py | 4 +- tools/assetstool/processpalette.py | 6 +- tools/assetstool/processtileset.py | 4 +- 162 files changed, 751 insertions(+), 740 deletions(-) rename src/assert/{assert.c => assert.cpp} (96%) rename src/assert/{assert.h => assert.hpp} (96%) rename src/asset/{asset.c => asset.cpp} (96%) rename src/asset/{asset.h => asset.hpp} (98%) rename src/asset/type/{assetalphaimage.c => assetalphaimage.cpp} (86%) rename src/asset/type/{assetalphaimage.h => assetalphaimage.hpp} (96%) rename src/asset/type/{assetchunk.c => assetchunk.cpp} (98%) rename src/asset/type/{assetchunk.h => assetchunk.hpp} (87%) rename src/asset/type/{assetlanguage.c => assetlanguage.cpp} (96%) rename src/asset/type/{assetlanguage.h => assetlanguage.hpp} (95%) rename src/asset/type/{assetmap.c => assetmap.cpp} (80%) rename src/asset/type/{assetmap.h => assetmap.hpp} (82%) rename src/asset/type/{assetpaletteimage.c => assetpaletteimage.cpp} (88%) rename src/asset/type/{assetpaletteimage.h => assetpaletteimage.hpp} (96%) rename src/asset/type/{assetscript.c => assetscript.cpp} (95%) rename src/asset/type/{assetscript.h => assetscript.hpp} (93%) rename src/debug/{debug.c => debug.cpp} (95%) rename src/debug/{debug.h => debug.hpp} (94%) rename src/display/{camera.c => camera.cpp} (93%) rename src/display/{camera.h => camera.hpp} (86%) rename src/display/{color.h => color.hpp} (99%) rename src/display/{display.c => display.cpp} (92%) rename src/display/{display.h => display.hpp} (81%) rename src/display/{displaydefs.h => displaydefs.hpp} (100%) rename src/display/{framebuffer.c => framebuffer.cpp} (93%) rename src/display/{framebuffer.h => framebuffer.hpp} (98%) rename src/display/mesh/{mesh.c => mesh.cpp} (96%) rename src/display/mesh/{mesh.h => mesh.hpp} (96%) rename src/display/mesh/{quad.c => quad.cpp} (98%) rename src/display/mesh/{quad.h => quad.hpp} (97%) rename src/display/palette/{palette.h => palette.hpp} (89%) rename src/display/{screen.c => screen.cpp} (99%) rename src/display/{screen.h => screen.hpp} (94%) rename src/display/{spritebatch.c => spritebatch.cpp} (95%) rename src/display/{spritebatch.h => spritebatch.hpp} (97%) rename src/display/{texture.c => texture.cpp} (94%) rename src/display/{texture.h => texture.hpp} (95%) rename src/display/tileset/{tileset.c => tileset.cpp} (96%) rename src/display/tileset/{tileset.h => tileset.hpp} (96%) delete mode 100644 src/dusk.h create mode 100644 src/dusk.hpp rename src/engine/{engine.c => engine.cpp} (77%) rename src/engine/{engine.h => engine.hpp} (86%) rename src/error/{error.c => error.cpp} (96%) rename src/error/{error.h => error.hpp} (99%) rename src/input/{input.c => input.cpp} (97%) rename src/input/{input.h => input.hpp} (98%) rename src/input/{inputaction.c => inputaction.cpp} (84%) rename src/input/{inputaction.h => inputaction.hpp} (71%) delete mode 100644 src/input/inputbutton.c create mode 100644 src/input/inputbutton.cpp rename src/input/{inputbutton.h => inputbutton.hpp} (98%) rename src/locale/{localemanager.c => localemanager.cpp} (88%) rename src/locale/{localemanager.h => localemanager.hpp} (97%) rename src/{main.c => main.cpp} (85%) rename src/rpg/cutscene/{cutscene.h => cutscene.hpp} (84%) rename src/rpg/cutscene/{cutscenemode.c => cutscenemode.cpp} (89%) rename src/rpg/cutscene/{cutscenemode.h => cutscenemode.hpp} (96%) rename src/rpg/cutscene/{cutscenesystem.c => cutscenesystem.cpp} (96%) rename src/rpg/cutscene/{cutscenesystem.h => cutscenesystem.hpp} (94%) rename src/rpg/cutscene/item/{cutscenecallback.h => cutscenecallback.hpp} (90%) rename src/rpg/cutscene/item/{cutscenecutscene.h => cutscenecutscene.hpp} (61%) rename src/rpg/cutscene/item/{cutsceneitem.c => cutsceneitem.cpp} (92%) rename src/rpg/cutscene/item/{cutsceneitem.h => cutsceneitem.hpp} (87%) rename src/rpg/cutscene/item/{cutscenetext.h => cutscenetext.hpp} (89%) rename src/rpg/cutscene/item/{cutscenewait.h => cutscenewait.hpp} (91%) rename src/rpg/cutscene/scene/{testcutscene.h => testcutscene.hpp} (96%) rename src/rpg/entity/{entity.c => entity.cpp} (96%) rename src/rpg/entity/{entity.h => entity.hpp} (93%) rename src/rpg/entity/{entityanim.c => entityanim.cpp} (84%) rename src/rpg/entity/{entityanim.h => entityanim.hpp} (94%) rename src/rpg/entity/{entitydir.c => entitydir.cpp} (95%) rename src/rpg/entity/{entitydir.h => entitydir.hpp} (82%) rename src/rpg/entity/{entitytype.h => entitytype.hpp} (93%) rename src/rpg/entity/{npc.c => npc.cpp} (83%) rename src/rpg/entity/{npc.h => npc.hpp} (97%) rename src/rpg/entity/{player.c => player.cpp} (91%) rename src/rpg/entity/{player.h => player.hpp} (92%) rename src/rpg/{rpg.c => rpg.cpp} (83%) rename src/rpg/{rpg.h => rpg.hpp} (94%) rename src/rpg/{rpgcamera.c => rpgcamera.cpp} (88%) rename src/rpg/{rpgcamera.h => rpgcamera.hpp} (90%) rename src/rpg/{rpgtextbox.c => rpgtextbox.cpp} (84%) rename src/rpg/{rpgtextbox.h => rpgtextbox.hpp} (97%) rename src/rpg/world/{chunk.c => chunk.cpp} (95%) rename src/rpg/world/{chunk.h => chunk.hpp} (90%) rename src/rpg/world/{map.c => map.cpp} (97%) rename src/rpg/world/{map.h => map.hpp} (98%) rename src/rpg/world/{tile.c => tile.cpp} (97%) rename src/rpg/world/{tile.h => tile.hpp} (93%) rename src/rpg/world/{worldpos.c => worldpos.cpp} (98%) rename src/rpg/world/{worldpos.h => worldpos.hpp} (97%) rename src/scene/{scene.h => scene.hpp} (85%) rename src/scene/scene/{scenemap.c => scenemap.cpp} (94%) rename src/scene/scene/{scenemap.h => scenemap.hpp} (84%) rename src/scene/scene/{scenetest.c => scenetest.cpp} (86%) rename src/scene/scene/{scenetest.h => scenetest.hpp} (95%) rename src/scene/{scenedata.h => scenedata.hpp} (72%) rename src/scene/{scenemanager.c => scenemanager.cpp} (94%) rename src/scene/{scenemanager.h => scenemanager.hpp} (96%) rename src/script/func/{scriptfunccamera.h => scriptfunccamera.hpp} (80%) rename src/script/func/{scriptfuncentity.h => scriptfuncentity.hpp} (97%) rename src/script/func/{scriptfuncsystem.h => scriptfuncsystem.hpp} (90%) rename src/script/{scriptcontext.c => scriptcontext.cpp} (94%) rename src/script/{scriptcontext.h => scriptcontext.hpp} (93%) rename src/script/{scriptmanager.c => scriptmanager.cpp} (70%) rename src/script/{scriptmanager.h => scriptmanager.hpp} (90%) rename src/script/{scriptvalue.h => scriptvalue.hpp} (96%) rename src/thread/{thread.c => thread.cpp} (97%) rename src/thread/{thread.h => thread.hpp} (98%) rename src/thread/{threadmutex.c => threadmutex.cpp} (97%) rename src/thread/{threadmutex.h => threadmutex.hpp} (98%) rename src/time/{time.c => time.cpp} (93%) rename src/time/{time.h => time.hpp} (96%) rename src/ui/element/{uielementtype.h => uielementtype.hpp} (100%) rename src/ui/{ui.c => ui.cpp} (85%) rename src/ui/{ui.h => ui.hpp} (87%) rename src/ui/{uidebug.c => uidebug.cpp} (91%) rename src/ui/{uidebug.h => uidebug.hpp} (84%) rename src/ui/{uiframe.c => uiframe.cpp} (98%) rename src/ui/{uiframe.h => uiframe.hpp} (96%) rename src/ui/{uitext.c => uitext.cpp} (94%) rename src/ui/{uitext.h => uitext.hpp} (94%) rename src/ui/{uitextbox.c => uitextbox.cpp} (80%) rename src/ui/{uitextbox.h => uitextbox.hpp} (93%) rename src/util/{math.c => math.cpp} (95%) rename src/util/{math.h => math.hpp} (98%) rename src/util/{memory.c => memory.cpp} (98%) rename src/util/{memory.h => memory.hpp} (99%) rename src/util/{string.c => string.cpp} (98%) rename src/util/{string.h => string.hpp} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a471c4..ee4d463 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/README.md b/README.md index e3aceca..52bd9ed 100644 --- a/README.md +++ b/README.md @@ -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; diff --git a/cmake/modules/envtoh.cmake b/cmake/modules/envtoh.cmake index 62c506d..85cf69f 100644 --- a/cmake/modules/envtoh.cmake +++ b/cmake/modules/envtoh.cmake @@ -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 ;) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 47de100..85ec272 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/assert/CMakeLists.txt b/src/assert/CMakeLists.txt index ca33cd5..aa2e40b 100644 --- a/src/assert/CMakeLists.txt +++ b/src/assert/CMakeLists.txt @@ -6,5 +6,5 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - assert.c + assert.cpp ) \ No newline at end of file diff --git a/src/assert/assert.c b/src/assert/assert.cpp similarity index 96% rename from src/assert/assert.c rename to src/assert/assert.cpp index 0d8b02e..185b50a 100644 --- a/src/assert/assert.c +++ b/src/assert/assert.cpp @@ -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( diff --git a/src/assert/assert.h b/src/assert/assert.hpp similarity index 96% rename from src/assert/assert.h rename to src/assert/assert.hpp index 03e401e..88e3ee8 100644 --- a/src/assert/assert.h +++ b/src/assert/assert.hpp @@ -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) diff --git a/src/asset/CMakeLists.txt b/src/asset/CMakeLists.txt index 399ef34..0b2509c 100644 --- a/src/asset/CMakeLists.txt +++ b/src/asset/CMakeLists.txt @@ -6,7 +6,7 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - asset.c + asset.cpp ) # Subdirs diff --git a/src/asset/asset.c b/src/asset/asset.cpp similarity index 96% rename from src/asset/asset.c rename to src/asset/asset.cpp index 68f126a..08b152a 100644 --- a/src/asset/asset.c +++ b/src/asset/asset.cpp @@ -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."); diff --git a/src/asset/asset.h b/src/asset/asset.hpp similarity index 98% rename from src/asset/asset.h rename to src/asset/asset.hpp index c482053..ac9a0e3 100644 --- a/src/asset/asset.h +++ b/src/asset/asset.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "error/error.h" +#include "error/error.hpp" #include "assettype.h" #if ASSET_TYPE == wad diff --git a/src/asset/assettype.h b/src/asset/assettype.h index de12191..b1fd205 100644 --- a/src/asset/assettype.h +++ b/src/asset/assettype.h @@ -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 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); diff --git a/src/asset/type/CMakeLists.txt b/src/asset/type/CMakeLists.txt index 1acad3d..aea69c2 100644 --- a/src/asset/type/CMakeLists.txt +++ b/src/asset/type/CMakeLists.txt @@ -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 ) \ No newline at end of file diff --git a/src/asset/type/assetalphaimage.c b/src/asset/type/assetalphaimage.cpp similarity index 86% rename from src/asset/type/assetalphaimage.c rename to src/asset/type/assetalphaimage.cpp index 475a354..c3f129e 100644 --- a/src/asset/type/assetalphaimage.c +++ b/src/asset/type/assetalphaimage.cpp @@ -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."); diff --git a/src/asset/type/assetalphaimage.h b/src/asset/type/assetalphaimage.hpp similarity index 96% rename from src/asset/type/assetalphaimage.h rename to src/asset/type/assetalphaimage.hpp index c197c82..dbe47c1 100644 --- a/src/asset/type/assetalphaimage.h +++ b/src/asset/type/assetalphaimage.hpp @@ -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 diff --git a/src/asset/type/assetchunk.c b/src/asset/type/assetchunk.cpp similarity index 98% rename from src/asset/type/assetchunk.c rename to src/asset/type/assetchunk.cpp index d4e8063..03c44f9 100644 --- a/src/asset/type/assetchunk.c +++ b/src/asset/type/assetchunk.cpp @@ -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 { diff --git a/src/asset/type/assetchunk.h b/src/asset/type/assetchunk.hpp similarity index 87% rename from src/asset/type/assetchunk.h rename to src/asset/type/assetchunk.hpp index 98c94ee..da81504 100644 --- a/src/asset/type/assetchunk.h +++ b/src/asset/type/assetchunk.hpp @@ -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; diff --git a/src/asset/type/assetlanguage.c b/src/asset/type/assetlanguage.cpp similarity index 96% rename from src/asset/type/assetlanguage.c rename to src/asset/type/assetlanguage.cpp index c866581..63dc0c0 100644 --- a/src/asset/type/assetlanguage.c +++ b/src/asset/type/assetlanguage.cpp @@ -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"); diff --git a/src/asset/type/assetlanguage.h b/src/asset/type/assetlanguage.hpp similarity index 95% rename from src/asset/type/assetlanguage.h rename to src/asset/type/assetlanguage.hpp index 676a6b3..0eaa9f4 100644 --- a/src/asset/type/assetlanguage.h +++ b/src/asset/type/assetlanguage.hpp @@ -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 #define ASSET_LANG_CHUNK_CACHE 4 // Number of chunks to cache in memory diff --git a/src/asset/type/assetmap.c b/src/asset/type/assetmap.cpp similarity index 80% rename from src/asset/type/assetmap.c rename to src/asset/type/assetmap.cpp index 875db74..8dce266 100644 --- a/src/asset/type/assetmap.c +++ b/src/asset/type/assetmap.cpp @@ -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"); diff --git a/src/asset/type/assetmap.h b/src/asset/type/assetmap.hpp similarity index 82% rename from src/asset/type/assetmap.h rename to src/asset/type/assetmap.hpp index 7411ce3..81f5193 100644 --- a/src/asset/type/assetmap.h +++ b/src/asset/type/assetmap.hpp @@ -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. diff --git a/src/asset/type/assetpaletteimage.c b/src/asset/type/assetpaletteimage.cpp similarity index 88% rename from src/asset/type/assetpaletteimage.c rename to src/asset/type/assetpaletteimage.cpp index 6ff0eba..04f40f0 100644 --- a/src/asset/type/assetpaletteimage.c +++ b/src/asset/type/assetpaletteimage.cpp @@ -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."); diff --git a/src/asset/type/assetpaletteimage.h b/src/asset/type/assetpaletteimage.hpp similarity index 96% rename from src/asset/type/assetpaletteimage.h rename to src/asset/type/assetpaletteimage.hpp index 2254d07..4c7671e 100644 --- a/src/asset/type/assetpaletteimage.h +++ b/src/asset/type/assetpaletteimage.hpp @@ -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 diff --git a/src/asset/type/assetscript.c b/src/asset/type/assetscript.cpp similarity index 95% rename from src/asset/type/assetscript.c rename to src/asset/type/assetscript.cpp index 9077225..a6cca06 100644 --- a/src/asset/type/assetscript.c +++ b/src/asset/type/assetscript.cpp @@ -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"); diff --git a/src/asset/type/assetscript.h b/src/asset/type/assetscript.hpp similarity index 93% rename from src/asset/type/assetscript.h rename to src/asset/type/assetscript.hpp index 0a3a2d4..93fcb72 100644 --- a/src/asset/type/assetscript.h +++ b/src/asset/type/assetscript.hpp @@ -6,10 +6,10 @@ */ #pragma once -#include "error/error.h" -#include "duskdefs.h" +#include "error/error.hpp" +#include "duskdefs.hpp" #include -#include +#include "script/scriptcontext.hpp" #define ASSET_SCRIPT_BUFFER_SIZE 1024 diff --git a/src/debug/CMakeLists.txt b/src/debug/CMakeLists.txt index 1bd53e4..0f87c07 100644 --- a/src/debug/CMakeLists.txt +++ b/src/debug/CMakeLists.txt @@ -6,7 +6,7 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - debug.c + debug.cpp ) # Subdirs \ No newline at end of file diff --git a/src/debug/debug.c b/src/debug/debug.cpp similarity index 95% rename from src/debug/debug.c rename to src/debug/debug.cpp index 4a9f7e1..9a5b678 100644 --- a/src/debug/debug.c +++ b/src/debug/debug.cpp @@ -5,7 +5,7 @@ * https://opensource.org/licenses/MIT */ -#include "debug.h" +#include "debug.hpp" void debugPrint(const char_t *message, ...) { va_list args; diff --git a/src/debug/debug.h b/src/debug/debug.hpp similarity index 94% rename from src/debug/debug.h rename to src/debug/debug.hpp index 8fcc6d7..cd01fd1 100644 --- a/src/debug/debug.h +++ b/src/debug/debug.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" /** * Prints a debug message to the debug console. diff --git a/src/display/CMakeLists.txt b/src/display/CMakeLists.txt index a48f0d0..15e77c8 100644 --- a/src/display/CMakeLists.txt +++ b/src/display/CMakeLists.txt @@ -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 diff --git a/src/display/camera.c b/src/display/camera.cpp similarity index 93% rename from src/display/camera.c rename to src/display/camera.cpp index 15cb8be..b7262b6 100644 --- a/src/display/camera.c +++ b/src/display/camera.cpp @@ -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"); diff --git a/src/display/camera.h b/src/display/camera.hpp similarity index 86% rename from src/display/camera.h rename to src/display/camera.hpp index 6a7ae88..00b3ab4 100644 --- a/src/display/camera.h +++ b/src/display/camera.hpp @@ -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; diff --git a/src/display/color.h b/src/display/color.hpp similarity index 99% rename from src/display/color.h rename to src/display/color.hpp index 4f9daeb..c3cda3f 100644 --- a/src/display/color.h +++ b/src/display/color.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" typedef float_t colorchannelf_t; typedef uint8_t colorchannelb_t; diff --git a/src/display/display.c b/src/display/display.cpp similarity index 92% rename from src/display/display.c rename to src/display/display.cpp index 26a9cd1..a323174 100644 --- a/src/display/display.c +++ b/src/display/display.cpp @@ -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; diff --git a/src/display/display.h b/src/display/display.hpp similarity index 81% rename from src/display/display.h rename to src/display/display.hpp index 34d1397..a3c6059 100644 --- a/src/display/display.h +++ b/src/display/display.hpp @@ -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 diff --git a/src/display/displaydefs.h b/src/display/displaydefs.hpp similarity index 100% rename from src/display/displaydefs.h rename to src/display/displaydefs.hpp diff --git a/src/display/framebuffer.c b/src/display/framebuffer.cpp similarity index 93% rename from src/display/framebuffer.c rename to src/display/framebuffer.cpp index 7b7e340..86f85bb 100644 --- a/src/display/framebuffer.c +++ b/src/display/framebuffer.cpp @@ -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); diff --git a/src/display/framebuffer.h b/src/display/framebuffer.hpp similarity index 98% rename from src/display/framebuffer.h rename to src/display/framebuffer.hpp index b33b19c..fdcdfae 100644 --- a/src/display/framebuffer.h +++ b/src/display/framebuffer.hpp @@ -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) diff --git a/src/display/mesh/CMakeLists.txt b/src/display/mesh/CMakeLists.txt index 9befe9a..15a473e 100644 --- a/src/display/mesh/CMakeLists.txt +++ b/src/display/mesh/CMakeLists.txt @@ -6,6 +6,6 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - mesh.c - quad.c + mesh.cpp + quad.cpp ) \ No newline at end of file diff --git a/src/display/mesh/mesh.c b/src/display/mesh/mesh.cpp similarity index 96% rename from src/display/mesh/mesh.c rename to src/display/mesh/mesh.cpp index 0e0882c..72d6856 100644 --- a/src/display/mesh/mesh.c +++ b/src/display/mesh/mesh.cpp @@ -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, diff --git a/src/display/mesh/mesh.h b/src/display/mesh/mesh.hpp similarity index 96% rename from src/display/mesh/mesh.h rename to src/display/mesh/mesh.hpp index 56f5ff4..7ec0692 100644 --- a/src/display/mesh/mesh.h +++ b/src/display/mesh/mesh.hpp @@ -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 diff --git a/src/display/mesh/quad.c b/src/display/mesh/quad.cpp similarity index 98% rename from src/display/mesh/quad.c rename to src/display/mesh/quad.cpp index 49a1d0f..1420b36 100644 --- a/src/display/mesh/quad.c +++ b/src/display/mesh/quad.cpp @@ -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] = { diff --git a/src/display/mesh/quad.h b/src/display/mesh/quad.hpp similarity index 97% rename from src/display/mesh/quad.h rename to src/display/mesh/quad.hpp index 9dcd410..f0792bc 100644 --- a/src/display/mesh/quad.h +++ b/src/display/mesh/quad.hpp @@ -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 diff --git a/src/display/palette/palette.h b/src/display/palette/palette.hpp similarity index 89% rename from src/display/palette/palette.h rename to src/display/palette/palette.hpp index ecce9e8..b2a54f5 100644 --- a/src/display/palette/palette.h +++ b/src/display/palette/palette.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "display/color.h" +#include "display/color.hpp" typedef struct { const uint8_t colorCount; diff --git a/src/display/screen.c b/src/display/screen.cpp similarity index 99% rename from src/display/screen.c rename to src/display/screen.cpp index 3b72c9e..80329f3 100644 --- a/src/display/screen.c +++ b/src/display/screen.cpp @@ -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; diff --git a/src/display/screen.h b/src/display/screen.hpp similarity index 94% rename from src/display/screen.h rename to src/display/screen.hpp index ff9ace7..da5f1a1 100644 --- a/src/display/screen.h +++ b/src/display/screen.hpp @@ -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 diff --git a/src/display/spritebatch.c b/src/display/spritebatch.cpp similarity index 95% rename from src/display/spritebatch.c rename to src/display/spritebatch.cpp index 06ef550..5585a0c 100644 --- a/src/display/spritebatch.c +++ b/src/display/spritebatch.cpp @@ -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; diff --git a/src/display/spritebatch.h b/src/display/spritebatch.hpp similarity index 97% rename from src/display/spritebatch.h rename to src/display/spritebatch.hpp index b2da2d9..0e74220 100644 --- a/src/display/spritebatch.h +++ b/src/display/spritebatch.hpp @@ -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) diff --git a/src/display/texture.c b/src/display/texture.cpp similarity index 94% rename from src/display/texture.c rename to src/display/texture.cpp index 63f24d7..722218c 100644 --- a/src/display/texture.c +++ b/src/display/texture.cpp @@ -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"); diff --git a/src/display/texture.h b/src/display/texture.hpp similarity index 95% rename from src/display/texture.h rename to src/display/texture.hpp index be6ac48..ec3bb90 100644 --- a/src/display/texture.h +++ b/src/display/texture.hpp @@ -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 diff --git a/src/display/tileset/CMakeLists.txt b/src/display/tileset/CMakeLists.txt index 2be6457..31e099e 100644 --- a/src/display/tileset/CMakeLists.txt +++ b/src/display/tileset/CMakeLists.txt @@ -6,5 +6,5 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - tileset.c + tileset.cpp ) \ No newline at end of file diff --git a/src/display/tileset/tileset.c b/src/display/tileset/tileset.cpp similarity index 96% rename from src/display/tileset/tileset.c rename to src/display/tileset/tileset.cpp index 5dc79d7..41ec22c 100644 --- a/src/display/tileset/tileset.c +++ b/src/display/tileset/tileset.cpp @@ -5,7 +5,7 @@ * https://opensource.org/licenses/MIT */ -#include "tileset.h" +#include "tileset.hpp" void tilesetTileGetUV( const tileset_t *tileset, diff --git a/src/display/tileset/tileset.h b/src/display/tileset/tileset.hpp similarity index 96% rename from src/display/tileset/tileset.h rename to src/display/tileset/tileset.hpp index 6ec5588..e6e98c5 100644 --- a/src/display/tileset/tileset.h +++ b/src/display/tileset/tileset.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" typedef struct tileset_s { const uint16_t tileWidth; diff --git a/src/dusk.h b/src/dusk.h deleted file mode 100644 index a794c2d..0000000 --- a/src/dusk.h +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#if PSP - #include - #include - #include - #include - #include -#endif - -typedef bool bool_t; -typedef int int_t; -typedef float float_t; -typedef char char_t; \ No newline at end of file diff --git a/src/dusk.hpp b/src/dusk.hpp new file mode 100644 index 0000000..e01b735 --- /dev/null +++ b/src/dusk.hpp @@ -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 + #include + #include + #include + #include + #include + #include + #include + #include + #include + + #include + #include + #include + + #if PSP + #include + #include + #include + #include + #include + #endif + + typedef bool bool_t; + typedef int int_t; + typedef float float_t; + typedef char char_t; +} \ No newline at end of file diff --git a/src/engine/CMakeLists.txt b/src/engine/CMakeLists.txt index 48dfead..a37f361 100644 --- a/src/engine/CMakeLists.txt +++ b/src/engine/CMakeLists.txt @@ -6,5 +6,5 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - engine.c + engine.cpp ) \ No newline at end of file diff --git a/src/engine/engine.c b/src/engine/engine.cpp similarity index 77% rename from src/engine/engine.c rename to src/engine/engine.cpp index a235611..72aec3b 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.cpp @@ -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; diff --git a/src/engine/engine.h b/src/engine/engine.hpp similarity index 86% rename from src/engine/engine.h rename to src/engine/engine.hpp index b75d350..f4ef826 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.hpp @@ -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; diff --git a/src/error/CMakeLists.txt b/src/error/CMakeLists.txt index b246fdb..08f7df7 100644 --- a/src/error/CMakeLists.txt +++ b/src/error/CMakeLists.txt @@ -6,5 +6,5 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - error.c + error.cpp ) \ No newline at end of file diff --git a/src/error/error.c b/src/error/error.cpp similarity index 96% rename from src/error/error.c rename to src/error/error.cpp index 4339ca4..0f14b2f 100644 --- a/src/error/error.c +++ b/src/error/error.cpp @@ -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 }; diff --git a/src/error/error.h b/src/error/error.hpp similarity index 99% rename from src/error/error.h rename to src/error/error.hpp index 0ab8a69..2bc9f9f 100644 --- a/src/error/error.h +++ b/src/error/error.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" typedef uint8_t errorcode_t; diff --git a/src/input/CMakeLists.txt b/src/input/CMakeLists.txt index 1426f89..3a9c7bb 100644 --- a/src/input/CMakeLists.txt +++ b/src/input/CMakeLists.txt @@ -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") diff --git a/src/input/input.c b/src/input/input.cpp similarity index 97% rename from src/input/input.c rename to src/input/input.cpp index 73c4ff4..fac1166 100644 --- a/src/input/input.c +++ b/src/input/input.cpp @@ -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; diff --git a/src/input/input.h b/src/input/input.hpp similarity index 98% rename from src/input/input.h rename to src/input/input.hpp index f4fd861..1dc0825 100644 --- a/src/input/input.h +++ b/src/input/input.hpp @@ -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]; diff --git a/src/input/inputaction.c b/src/input/inputaction.cpp similarity index 84% rename from src/input/inputaction.c rename to src/input/inputaction.cpp index db84312..40fd869 100644 --- a/src/input/inputaction.c +++ b/src/input/inputaction.cpp @@ -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"); diff --git a/src/input/inputaction.h b/src/input/inputaction.hpp similarity index 71% rename from src/input/inputaction.h rename to src/input/inputaction.hpp index 6937bb4..c3ac86f 100644 --- a/src/input/inputaction.h +++ b/src/input/inputaction.hpp @@ -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; diff --git a/src/input/inputbutton.c b/src/input/inputbutton.c deleted file mode 100644 index 087bcd9..0000000 --- a/src/input/inputbutton.c +++ /dev/null @@ -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; - } - } -} \ No newline at end of file diff --git a/src/input/inputbutton.cpp b/src/input/inputbutton.cpp new file mode 100644 index 0000000..6fe65fe --- /dev/null +++ b/src/input/inputbutton.cpp @@ -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; + } + } +} \ No newline at end of file diff --git a/src/input/inputbutton.h b/src/input/inputbutton.hpp similarity index 98% rename from src/input/inputbutton.h rename to src/input/inputbutton.hpp index ae3daa6..9895149 100644 --- a/src/input/inputbutton.h +++ b/src/input/inputbutton.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "inputaction.h" +#include "inputaction.hpp" #if INPUT_SDL2 == 1 #include diff --git a/src/locale/CMakeLists.txt b/src/locale/CMakeLists.txt index 6ba5c6d..ef56795 100644 --- a/src/locale/CMakeLists.txt +++ b/src/locale/CMakeLists.txt @@ -6,5 +6,5 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - localemanager.c + localemanager.cpp ) \ No newline at end of file diff --git a/src/locale/localemanager.c b/src/locale/localemanager.cpp similarity index 88% rename from src/locale/localemanager.c rename to src/locale/localemanager.cpp index 295aba0..000940b 100644 --- a/src/locale/localemanager.c +++ b/src/locale/localemanager.cpp @@ -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; diff --git a/src/locale/localemanager.h b/src/locale/localemanager.hpp similarity index 97% rename from src/locale/localemanager.h rename to src/locale/localemanager.hpp index bc5b303..9787568 100644 --- a/src/locale/localemanager.h +++ b/src/locale/localemanager.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "asset/asset.h" +#include "asset/asset.hpp" typedef enum { DUSK_LOCALE_EN_US, diff --git a/src/main.c b/src/main.cpp similarity index 85% rename from src/main.c rename to src/main.cpp index 532b238..b03bef6 100644 --- a/src/main.c +++ b/src/main.cpp @@ -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 diff --git a/src/rpg/CMakeLists.txt b/src/rpg/CMakeLists.txt index 1a08b8b..122e9ff 100644 --- a/src/rpg/CMakeLists.txt +++ b/src/rpg/CMakeLists.txt @@ -6,9 +6,9 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - rpg.c - rpgcamera.c - rpgtextbox.c + rpg.cpp + rpgcamera.cpp + rpgtextbox.cpp ) # Subdirs diff --git a/src/rpg/cutscene/CMakeLists.txt b/src/rpg/cutscene/CMakeLists.txt index a2d1b86..e35eb25 100644 --- a/src/rpg/cutscene/CMakeLists.txt +++ b/src/rpg/cutscene/CMakeLists.txt @@ -6,8 +6,8 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - cutscenesystem.c - cutscenemode.c + cutscenesystem.cpp + cutscenemode.cpp ) # Subdirs diff --git a/src/rpg/cutscene/cutscene.h b/src/rpg/cutscene/cutscene.hpp similarity index 84% rename from src/rpg/cutscene/cutscene.h rename to src/rpg/cutscene/cutscene.hpp index 7df18ad..daabaec 100644 --- a/src/rpg/cutscene/cutscene.h +++ b/src/rpg/cutscene/cutscene.hpp @@ -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; diff --git a/src/rpg/cutscene/cutscenemode.c b/src/rpg/cutscene/cutscenemode.cpp similarity index 89% rename from src/rpg/cutscene/cutscenemode.c rename to src/rpg/cutscene/cutscenemode.cpp index 39c10b3..b448120 100644 --- a/src/rpg/cutscene/cutscenemode.c +++ b/src/rpg/cutscene/cutscenemode.cpp @@ -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) { diff --git a/src/rpg/cutscene/cutscenemode.h b/src/rpg/cutscene/cutscenemode.hpp similarity index 96% rename from src/rpg/cutscene/cutscenemode.h rename to src/rpg/cutscene/cutscenemode.hpp index cf20a3d..df88bef 100644 --- a/src/rpg/cutscene/cutscenemode.h +++ b/src/rpg/cutscene/cutscenemode.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" typedef enum { CUTSCENE_MODE_NONE, diff --git a/src/rpg/cutscene/cutscenesystem.c b/src/rpg/cutscene/cutscenesystem.cpp similarity index 96% rename from src/rpg/cutscene/cutscenesystem.c rename to src/rpg/cutscene/cutscenesystem.cpp index d803e05..6a0be6f 100644 --- a/src/rpg/cutscene/cutscenesystem.c +++ b/src/rpg/cutscene/cutscenesystem.cpp @@ -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; diff --git a/src/rpg/cutscene/cutscenesystem.h b/src/rpg/cutscene/cutscenesystem.hpp similarity index 94% rename from src/rpg/cutscene/cutscenesystem.h rename to src/rpg/cutscene/cutscenesystem.hpp index 7c3242a..71cb8ea 100644 --- a/src/rpg/cutscene/cutscenesystem.h +++ b/src/rpg/cutscene/cutscenesystem.hpp @@ -6,8 +6,8 @@ */ #pragma once -#include "cutscene.h" -#include "cutscenemode.h" +#include "cutscene.hpp" +#include "cutscenemode.hpp" typedef struct { const cutscene_t *scene; diff --git a/src/rpg/cutscene/item/CMakeLists.txt b/src/rpg/cutscene/item/CMakeLists.txt index 114d521..314b90c 100755 --- a/src/rpg/cutscene/item/CMakeLists.txt +++ b/src/rpg/cutscene/item/CMakeLists.txt @@ -6,5 +6,5 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - cutsceneitem.c + cutsceneitem.cpp ) \ No newline at end of file diff --git a/src/rpg/cutscene/item/cutscenecallback.h b/src/rpg/cutscene/item/cutscenecallback.hpp similarity index 90% rename from src/rpg/cutscene/item/cutscenecallback.h rename to src/rpg/cutscene/item/cutscenecallback.hpp index 494f877..01f404e 100644 --- a/src/rpg/cutscene/item/cutscenecallback.h +++ b/src/rpg/cutscene/item/cutscenecallback.hpp @@ -6,6 +6,6 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" typedef void (*cutscenecallback_t)(void); \ No newline at end of file diff --git a/src/rpg/cutscene/item/cutscenecutscene.h b/src/rpg/cutscene/item/cutscenecutscene.hpp similarity index 61% rename from src/rpg/cutscene/item/cutscenecutscene.h rename to src/rpg/cutscene/item/cutscenecutscene.hpp index 6588720..ad3464e 100644 --- a/src/rpg/cutscene/item/cutscenecutscene.h +++ b/src/rpg/cutscene/item/cutscenecutscene.hpp @@ -6,8 +6,6 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" -typedef struct cutscene_s cutscene_t; - -typedef cutscene_t* cutscenecutscene_t; \ No newline at end of file +typedef struct cutscene_s cutscene_t; \ No newline at end of file diff --git a/src/rpg/cutscene/item/cutsceneitem.c b/src/rpg/cutscene/item/cutsceneitem.cpp similarity index 92% rename from src/rpg/cutscene/item/cutsceneitem.c rename to src/rpg/cutscene/item/cutsceneitem.cpp index 18a8b58..3ed73fc 100644 --- a/src/rpg/cutscene/item/cutsceneitem.c +++ b/src/rpg/cutscene/item/cutsceneitem.cpp @@ -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) { diff --git a/src/rpg/cutscene/item/cutsceneitem.h b/src/rpg/cutscene/item/cutsceneitem.hpp similarity index 87% rename from src/rpg/cutscene/item/cutsceneitem.h rename to src/rpg/cutscene/item/cutsceneitem.hpp index 9c8a3a3..4a11865 100644 --- a/src/rpg/cutscene/item/cutsceneitem.h +++ b/src/rpg/cutscene/item/cutsceneitem.hpp @@ -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; diff --git a/src/rpg/cutscene/item/cutscenetext.h b/src/rpg/cutscene/item/cutscenetext.hpp similarity index 89% rename from src/rpg/cutscene/item/cutscenetext.h rename to src/rpg/cutscene/item/cutscenetext.hpp index 3ad07f2..5d04938 100644 --- a/src/rpg/cutscene/item/cutscenetext.h +++ b/src/rpg/cutscene/item/cutscenetext.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "rpg/rpgtextbox.h" +#include "rpg/rpgtextbox.hpp" typedef struct { char_t text[RPG_TEXTBOX_MAX_CHARS]; diff --git a/src/rpg/cutscene/item/cutscenewait.h b/src/rpg/cutscene/item/cutscenewait.hpp similarity index 91% rename from src/rpg/cutscene/item/cutscenewait.h rename to src/rpg/cutscene/item/cutscenewait.hpp index 9d590df..02990da 100644 --- a/src/rpg/cutscene/item/cutscenewait.h +++ b/src/rpg/cutscene/item/cutscenewait.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" typedef float_t cutscenewait_t; typedef float_t cutscenewaitdata_t; \ No newline at end of file diff --git a/src/rpg/cutscene/scene/testcutscene.h b/src/rpg/cutscene/scene/testcutscene.hpp similarity index 96% rename from src/rpg/cutscene/scene/testcutscene.h rename to src/rpg/cutscene/scene/testcutscene.hpp index bcdffb2..ba37104 100755 --- a/src/rpg/cutscene/scene/testcutscene.h +++ b/src/rpg/cutscene/scene/testcutscene.hpp @@ -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 } }, diff --git a/src/rpg/entity/CMakeLists.txt b/src/rpg/entity/CMakeLists.txt index 08700a1..52bd628 100644 --- a/src/rpg/entity/CMakeLists.txt +++ b/src/rpg/entity/CMakeLists.txt @@ -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 ) \ No newline at end of file diff --git a/src/rpg/entity/entity.c b/src/rpg/entity/entity.cpp similarity index 96% rename from src/rpg/entity/entity.c rename to src/rpg/entity/entity.cpp index 6bda94e..ed1326a 100644 --- a/src/rpg/entity/entity.c +++ b/src/rpg/entity/entity.cpp @@ -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]; diff --git a/src/rpg/entity/entity.h b/src/rpg/entity/entity.hpp similarity index 93% rename from src/rpg/entity/entity.h rename to src/rpg/entity/entity.hpp index 8cf7343..e2c3062 100644 --- a/src/rpg/entity/entity.h +++ b/src/rpg/entity/entity.hpp @@ -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; diff --git a/src/rpg/entity/entityanim.c b/src/rpg/entity/entityanim.cpp similarity index 84% rename from src/rpg/entity/entityanim.c rename to src/rpg/entity/entityanim.cpp index d5730f3..830d5c9 100644 --- a/src/rpg/entity/entityanim.c +++ b/src/rpg/entity/entityanim.cpp @@ -5,5 +5,5 @@ * https://opensource.org/licenses/MIT */ -#include "entityanim.h" +#include "entityanim.hpp" diff --git a/src/rpg/entity/entityanim.h b/src/rpg/entity/entityanim.hpp similarity index 94% rename from src/rpg/entity/entityanim.h rename to src/rpg/entity/entityanim.hpp index 42f7d40..6f11f75 100644 --- a/src/rpg/entity/entityanim.h +++ b/src/rpg/entity/entityanim.hpp @@ -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 diff --git a/src/rpg/entity/entitydir.c b/src/rpg/entity/entitydir.cpp similarity index 95% rename from src/rpg/entity/entitydir.c rename to src/rpg/entity/entitydir.cpp index e272877..435e1f9 100644 --- a/src/rpg/entity/entitydir.c +++ b/src/rpg/entity/entitydir.cpp @@ -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) { diff --git a/src/rpg/entity/entitydir.h b/src/rpg/entity/entitydir.hpp similarity index 82% rename from src/rpg/entity/entitydir.h rename to src/rpg/entity/entitydir.hpp index 3b34b6e..f84e488 100644 --- a/src/rpg/entity/entitydir.h +++ b/src/rpg/entity/entitydir.hpp @@ -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. diff --git a/src/rpg/entity/entitytype.h b/src/rpg/entity/entitytype.hpp similarity index 93% rename from src/rpg/entity/entitytype.h rename to src/rpg/entity/entitytype.hpp index 0e3e4ba..032467b 100644 --- a/src/rpg/entity/entitytype.h +++ b/src/rpg/entity/entitytype.hpp @@ -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; diff --git a/src/rpg/entity/npc.c b/src/rpg/entity/npc.cpp similarity index 83% rename from src/rpg/entity/npc.c rename to src/rpg/entity/npc.cpp index ec6548b..9d73081 100644 --- a/src/rpg/entity/npc.c +++ b/src/rpg/entity/npc.cpp @@ -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"); diff --git a/src/rpg/entity/npc.h b/src/rpg/entity/npc.hpp similarity index 97% rename from src/rpg/entity/npc.h rename to src/rpg/entity/npc.hpp index df36f15..93739fe 100644 --- a/src/rpg/entity/npc.h +++ b/src/rpg/entity/npc.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" typedef struct entity_s entity_t; diff --git a/src/rpg/entity/player.c b/src/rpg/entity/player.cpp similarity index 91% rename from src/rpg/entity/player.c rename to src/rpg/entity/player.cpp index cf33d56..0030b0c 100644 --- a/src/rpg/entity/player.c +++ b/src/rpg/entity/player.cpp @@ -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"); diff --git a/src/rpg/entity/player.h b/src/rpg/entity/player.hpp similarity index 92% rename from src/rpg/entity/player.h rename to src/rpg/entity/player.hpp index 8c10f31..6bb247b 100644 --- a/src/rpg/entity/player.h +++ b/src/rpg/entity/player.hpp @@ -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 } }; /** diff --git a/src/rpg/rpg.c b/src/rpg/rpg.cpp similarity index 83% rename from src/rpg/rpg.c rename to src/rpg/rpg.cpp index e97368d..9568c6a 100644 --- a/src/rpg/rpg.c +++ b/src/rpg/rpg.cpp @@ -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)); diff --git a/src/rpg/rpg.h b/src/rpg/rpg.hpp similarity index 94% rename from src/rpg/rpg.h rename to src/rpg/rpg.hpp index 7460dfb..80abd1e 100644 --- a/src/rpg/rpg.h +++ b/src/rpg/rpg.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "error/error.h" +#include "error/error.hpp" typedef struct { int32_t nothing; diff --git a/src/rpg/rpgcamera.c b/src/rpg/rpgcamera.cpp similarity index 88% rename from src/rpg/rpgcamera.c rename to src/rpg/rpgcamera.cpp index 355cc13..f1cf7ea 100644 --- a/src/rpg/rpgcamera.c +++ b/src/rpg/rpgcamera.cpp @@ -5,11 +5,11 @@ * https://opensource.org/licenses/MIT */ -#include "rpgcamera.h" -#include "util/memory.h" -#include "rpg/entity/entity.h" -#include "rpg/world/map.h" -#include "assert/assert.h" +#include "rpgcamera.hpp" +#include "util/memory.hpp" +#include "rpg/entity/entity.hpp" +#include "rpg/world/map.hpp" +#include "assert/assert.hpp" rpgcamera_t RPG_CAMERA; diff --git a/src/rpg/rpgcamera.h b/src/rpg/rpgcamera.hpp similarity index 90% rename from src/rpg/rpgcamera.h rename to src/rpg/rpgcamera.hpp index 07cf991..6e4406d 100644 --- a/src/rpg/rpgcamera.h +++ b/src/rpg/rpgcamera.hpp @@ -6,8 +6,8 @@ */ #pragma once -#include "rpg/world/worldpos.h" -#include "error/error.h" +#include "rpg/world/worldpos.hpp" +#include "error/error.hpp" typedef enum { RPG_CAMERA_MODE_FREE, diff --git a/src/rpg/rpgtextbox.c b/src/rpg/rpgtextbox.cpp similarity index 84% rename from src/rpg/rpgtextbox.c rename to src/rpg/rpgtextbox.cpp index 6fba985..0eb4986 100644 --- a/src/rpg/rpgtextbox.c +++ b/src/rpg/rpgtextbox.cpp @@ -5,10 +5,10 @@ * https://opensource.org/licenses/MIT */ -#include "rpgtextbox.h" -#include "util/memory.h" -#include "util/string.h" -#include "assert/assert.h" +#include "rpgtextbox.hpp" +#include "util/memory.hpp" +#include "util/string.hpp" +#include "assert/assert.hpp" rpgtextbox_t RPG_TEXTBOX; diff --git a/src/rpg/rpgtextbox.h b/src/rpg/rpgtextbox.hpp similarity index 97% rename from src/rpg/rpgtextbox.h rename to src/rpg/rpgtextbox.hpp index 02e8cd9..d47112b 100644 --- a/src/rpg/rpgtextbox.h +++ b/src/rpg/rpgtextbox.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" #define RPG_TEXTBOX_MAX_CHARS 256 diff --git a/src/rpg/world/CMakeLists.txt b/src/rpg/world/CMakeLists.txt index b2284d7..0566877 100644 --- a/src/rpg/world/CMakeLists.txt +++ b/src/rpg/world/CMakeLists.txt @@ -6,8 +6,8 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - chunk.c - map.c - worldpos.c - tile.c + chunk.cpp + map.cpp + worldpos.cpp + tile.cpp ) \ No newline at end of file diff --git a/src/rpg/world/chunk.c b/src/rpg/world/chunk.cpp similarity index 95% rename from src/rpg/world/chunk.c rename to src/rpg/world/chunk.cpp index 19a9999..4c18905 100644 --- a/src/rpg/world/chunk.c +++ b/src/rpg/world/chunk.cpp @@ -5,7 +5,7 @@ * https://opensource.org/licenses/MIT */ -#include "chunk.h" +#include "chunk.hpp" uint32_t chunkGetTileIndex(const chunkpos_t position) { return ( diff --git a/src/rpg/world/chunk.h b/src/rpg/world/chunk.hpp similarity index 90% rename from src/rpg/world/chunk.h rename to src/rpg/world/chunk.hpp index 7f1079b..2b5c5f1 100644 --- a/src/rpg/world/chunk.h +++ b/src/rpg/world/chunk.hpp @@ -6,9 +6,9 @@ */ #pragma once -#include "rpg/world/tile.h" -#include "worldpos.h" -#include "display/mesh/quad.h" +#include "rpg/world/tile.hpp" +#include "worldpos.hpp" +#include "display/mesh/quad.hpp" typedef struct chunk_s { chunkpos_t position; diff --git a/src/rpg/world/map.c b/src/rpg/world/map.cpp similarity index 97% rename from src/rpg/world/map.c rename to src/rpg/world/map.cpp index afe66e5..e4be5b2 100644 --- a/src/rpg/world/map.c +++ b/src/rpg/world/map.cpp @@ -5,11 +5,11 @@ * https://opensource.org/licenses/MIT */ -#include "map.h" -#include "util/memory.h" -#include "assert/assert.h" -#include "asset/asset.h" -#include "rpg/entity/entity.h" +#include "map.hpp" +#include "util/memory.hpp" +#include "assert/assert.hpp" +#include "asset/asset.hpp" +#include "rpg/entity/entity.hpp" map_t MAP; diff --git a/src/rpg/world/map.h b/src/rpg/world/map.hpp similarity index 98% rename from src/rpg/world/map.h rename to src/rpg/world/map.hpp index bb494e2..337f5c6 100644 --- a/src/rpg/world/map.h +++ b/src/rpg/world/map.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "rpg/world/chunk.h" +#include "rpg/world/chunk.hpp" typedef struct map_s { chunk_t chunks[MAP_CHUNK_COUNT]; diff --git a/src/rpg/world/tile.c b/src/rpg/world/tile.cpp similarity index 97% rename from src/rpg/world/tile.c rename to src/rpg/world/tile.cpp index cc25881..526aceb 100644 --- a/src/rpg/world/tile.c +++ b/src/rpg/world/tile.cpp @@ -5,7 +5,7 @@ * https://opensource.org/licenses/MIT */ -#include "tile.h" +#include "tile.hpp" bool_t tileIsWalkable(const tile_t tile) { switch(tile) { diff --git a/src/rpg/world/tile.h b/src/rpg/world/tile.hpp similarity index 93% rename from src/rpg/world/tile.h rename to src/rpg/world/tile.hpp index 6b1d11b..7de3618 100644 --- a/src/rpg/world/tile.h +++ b/src/rpg/world/tile.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "rpg/entity/entitydir.h" +#include "rpg/entity/entitydir.hpp" typedef uint8_t tile_t; diff --git a/src/rpg/world/worldpos.c b/src/rpg/world/worldpos.cpp similarity index 98% rename from src/rpg/world/worldpos.c rename to src/rpg/world/worldpos.cpp index 3cdd710..c550904 100644 --- a/src/rpg/world/worldpos.c +++ b/src/rpg/world/worldpos.cpp @@ -5,8 +5,8 @@ * https://opensource.org/licenses/MIT */ -#include "worldpos.h" -#include "assert/assert.h" +#include "worldpos.hpp" +#include "assert/assert.hpp" bool_t worldPosIsEqual(const worldpos_t a, const worldpos_t b) { return a.x == b.x && a.y == b.y && a.z == b.z; diff --git a/src/rpg/world/worldpos.h b/src/rpg/world/worldpos.hpp similarity index 97% rename from src/rpg/world/worldpos.h rename to src/rpg/world/worldpos.hpp index a9432e4..105a41e 100644 --- a/src/rpg/world/worldpos.h +++ b/src/rpg/world/worldpos.hpp @@ -6,8 +6,8 @@ */ #pragma once -#include "dusk.h" -#include "duskdefs.h" +#include "dusk.hpp" +#include "duskdefs.hpp" #define CHUNK_TILE_COUNT (CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH) diff --git a/src/scene/CMakeLists.txt b/src/scene/CMakeLists.txt index 61b0f0a..6dfc37c 100644 --- a/src/scene/CMakeLists.txt +++ b/src/scene/CMakeLists.txt @@ -6,7 +6,7 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - scenemanager.c + scenemanager.cpp ) # Subdirs diff --git a/src/scene/scene.h b/src/scene/scene.hpp similarity index 85% rename from src/scene/scene.h rename to src/scene/scene.hpp index 39c89a4..19f3356 100644 --- a/src/scene/scene.h +++ b/src/scene/scene.hpp @@ -6,9 +6,9 @@ */ #pragma once -#include "dusk.h" -#include "error/error.h" -#include "display/color.h" +#include "dusk.hpp" +#include "error/error.hpp" +#include "display/color.hpp" #define SCENE_FLAG_INITIALIZED (1 << 0) diff --git a/src/scene/scene/CMakeLists.txt b/src/scene/scene/CMakeLists.txt index a7e70c6..7c24e1d 100644 --- a/src/scene/scene/CMakeLists.txt +++ b/src/scene/scene/CMakeLists.txt @@ -6,8 +6,8 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - scenetest.c - scenemap.c + scenetest.cpp + scenemap.cpp ) # Subdirs \ No newline at end of file diff --git a/src/scene/scene/scenemap.c b/src/scene/scene/scenemap.cpp similarity index 94% rename from src/scene/scene/scenemap.c rename to src/scene/scene/scenemap.cpp index 7d047e8..1caad84 100644 --- a/src/scene/scene/scenemap.c +++ b/src/scene/scene/scenemap.cpp @@ -5,17 +5,17 @@ * https://opensource.org/licenses/MIT */ -#include "scenemap.h" -#include "scene/scenedata.h" -#include "display/spritebatch.h" -#include "assert/assert.h" -#include "asset/asset.h" -#include "rpg/entity/entity.h" -#include "rpg/world/map.h" -#include "display/screen.h" -#include "rpg/rpgcamera.h" -#include "util/memory.h" -#include "duskdefs.h" +#include "scenemap.hpp" +#include "scene/scenedata.hpp" +#include "display/spritebatch.hpp" +#include "assert/assert.hpp" +#include "asset/asset.hpp" +#include "rpg/entity/entity.hpp" +#include "rpg/world/map.hpp" +#include "display/screen.hpp" +#include "rpg/rpgcamera.hpp" +#include "util/memory.hpp" +#include "duskdefs.hpp" errorret_t sceneMapInit(scenedata_t *data) { // Init the camera. diff --git a/src/scene/scene/scenemap.h b/src/scene/scene/scenemap.hpp similarity index 84% rename from src/scene/scene/scenemap.h rename to src/scene/scene/scenemap.hpp index 86f8766..e8fbff6 100644 --- a/src/scene/scene/scenemap.h +++ b/src/scene/scene/scenemap.hpp @@ -6,10 +6,10 @@ */ #pragma once -#include "scene/scene.h" -#include "rpg/entity/entity.h" -#include "display/camera.h" -#include "asset/asset.h" +#include "scene/scene.hpp" +#include "rpg/entity/entity.hpp" +#include "display/camera.hpp" +#include "asset/asset.hpp" typedef struct { camera_t camera; diff --git a/src/scene/scene/scenetest.c b/src/scene/scene/scenetest.cpp similarity index 86% rename from src/scene/scene/scenetest.c rename to src/scene/scene/scenetest.cpp index 1fba899..c644080 100644 --- a/src/scene/scene/scenetest.c +++ b/src/scene/scene/scenetest.cpp @@ -5,8 +5,8 @@ * https://opensource.org/licenses/MIT */ -#include "scenetest.h" -#include "scene/scenedata.h" +#include "scenetest.hpp" +#include "scene/scenedata.hpp" errorret_t sceneTestInit(scenedata_t *data) { data->sceneTest.nothing = 0; diff --git a/src/scene/scene/scenetest.h b/src/scene/scene/scenetest.hpp similarity index 95% rename from src/scene/scene/scenetest.h rename to src/scene/scene/scenetest.hpp index de8051d..859a304 100644 --- a/src/scene/scene/scenetest.h +++ b/src/scene/scene/scenetest.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "scene/scene.h" +#include "scene/scene.hpp" typedef struct { int32_t nothing; diff --git a/src/scene/scenedata.h b/src/scene/scenedata.hpp similarity index 72% rename from src/scene/scenedata.h rename to src/scene/scenedata.hpp index 4122c42..3e1f98b 100644 --- a/src/scene/scenedata.h +++ b/src/scene/scenedata.hpp @@ -6,10 +6,10 @@ */ #pragma once -#include "scene/scene.h" +#include "scene/scene.hpp" -#include "scene/scene/scenetest.h" -#include "scene/scene/scenemap.h" +#include "scene/scene/scenetest.hpp" +#include "scene/scene/scenemap.hpp" typedef struct scenedata_s { union { diff --git a/src/scene/scenemanager.c b/src/scene/scenemanager.cpp similarity index 94% rename from src/scene/scenemanager.c rename to src/scene/scenemanager.cpp index 972dd03..ea4e4b7 100644 --- a/src/scene/scenemanager.c +++ b/src/scene/scenemanager.cpp @@ -5,11 +5,11 @@ * https://opensource.org/licenses/MIT */ -#include "scenemanager.h" -#include "util/memory.h" -#include "assert/assert.h" -#include "display/framebuffer.h" -#include "util/string.h" +#include "scenemanager.hpp" +#include "util/memory.hpp" +#include "assert/assert.hpp" +#include "display/framebuffer.hpp" +#include "util/string.hpp" scenemanager_t SCENE_MANAGER; diff --git a/src/scene/scenemanager.h b/src/scene/scenemanager.hpp similarity index 96% rename from src/scene/scenemanager.h rename to src/scene/scenemanager.hpp index 0b6c765..2e4dee0 100644 --- a/src/scene/scenemanager.h +++ b/src/scene/scenemanager.hpp @@ -6,8 +6,8 @@ */ #pragma once -#include "scene.h" -#include "scenedata.h" +#include "scene.hpp" +#include "scenedata.hpp" #define SCENE_MANAGER_SCENE_COUNT_MAX 32 diff --git a/src/script/CMakeLists.txt b/src/script/CMakeLists.txt index 1e60d85..e6138cd 100644 --- a/src/script/CMakeLists.txt +++ b/src/script/CMakeLists.txt @@ -6,6 +6,6 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - scriptmanager.c - scriptcontext.c + scriptmanager.cpp + scriptcontext.cpp ) \ No newline at end of file diff --git a/src/script/func/scriptfunccamera.h b/src/script/func/scriptfunccamera.hpp similarity index 80% rename from src/script/func/scriptfunccamera.h rename to src/script/func/scriptfunccamera.hpp index de86975..ac0ebbc 100644 --- a/src/script/func/scriptfunccamera.h +++ b/src/script/func/scriptfunccamera.hpp @@ -6,8 +6,8 @@ */ #pragma once -#include "script/scriptcontext.h" -#include "assert/assert.h" +#include "script/scriptcontext.hpp" +#include "assert/assert.hpp" diff --git a/src/script/func/scriptfuncentity.h b/src/script/func/scriptfuncentity.hpp similarity index 97% rename from src/script/func/scriptfuncentity.h rename to src/script/func/scriptfuncentity.hpp index ea0d3a7..66ec082 100644 --- a/src/script/func/scriptfuncentity.h +++ b/src/script/func/scriptfuncentity.hpp @@ -6,9 +6,9 @@ */ #pragma once -#include "script/scriptcontext.h" -#include "rpg/entity/entity.h" -#include "assert/assert.h" +#include "script/scriptcontext.hpp" +#include "rpg/entity/entity.hpp" +#include "assert/assert.hpp" int32_t scriptFuncEntityAdd(lua_State *L) { assertNotNull(L, "Lua state cannot be NULL"); diff --git a/src/script/func/scriptfuncsystem.h b/src/script/func/scriptfuncsystem.hpp similarity index 90% rename from src/script/func/scriptfuncsystem.h rename to src/script/func/scriptfuncsystem.hpp index c022377..6c44078 100644 --- a/src/script/func/scriptfuncsystem.h +++ b/src/script/func/scriptfuncsystem.hpp @@ -6,9 +6,9 @@ */ #pragma once -#include "script/scriptcontext.h" -#include "debug/debug.h" -#include "assert/assert.h" +#include "script/scriptcontext.hpp" +#include "debug/debug.hpp" +#include "assert/assert.hpp" int32_t scriptContextPrint(lua_State *L) { assertNotNull(L, "Lua state cannot be NULL"); diff --git a/src/script/scriptcontext.c b/src/script/scriptcontext.cpp similarity index 94% rename from src/script/scriptcontext.c rename to src/script/scriptcontext.cpp index 361edda..673414f 100644 --- a/src/script/scriptcontext.c +++ b/src/script/scriptcontext.cpp @@ -5,15 +5,15 @@ * https://opensource.org/licenses/MIT */ -#include "scriptcontext.h" -#include "assert/assert.h" -#include "asset/asset.h" -#include "util/memory.h" -#include "debug/debug.h" +#include "scriptcontext.hpp" +#include "assert/assert.hpp" +#include "asset/asset.hpp" +#include "util/memory.hpp" +#include "debug/debug.hpp" -#include "script/func/scriptfunccamera.h" -#include "script/func/scriptfuncentity.h" -#include "script/func/scriptfuncsystem.h" +#include "script/func/scriptfunccamera.hpp" +#include "script/func/scriptfuncentity.hpp" +#include "script/func/scriptfuncsystem.hpp" errorret_t scriptContextInit(scriptcontext_t *context) { assertNotNull(context, "Script context cannot be NULL"); diff --git a/src/script/scriptcontext.h b/src/script/scriptcontext.hpp similarity index 93% rename from src/script/scriptcontext.h rename to src/script/scriptcontext.hpp index b78eb57..2a2c67b 100644 --- a/src/script/scriptcontext.h +++ b/src/script/scriptcontext.hpp @@ -6,11 +6,14 @@ */ #pragma once -#include "error/error.h" -#include "scriptvalue.h" -#include -#include -#include +#include "error/error.hpp" +#include "scriptvalue.hpp" + +extern "C" { + #include + #include + #include +} typedef struct scriptcontext_s { lua_State *luaState; diff --git a/src/script/scriptmanager.c b/src/script/scriptmanager.cpp similarity index 70% rename from src/script/scriptmanager.c rename to src/script/scriptmanager.cpp index d773329..ff8ab68 100644 --- a/src/script/scriptmanager.c +++ b/src/script/scriptmanager.cpp @@ -5,11 +5,11 @@ * https://opensource.org/licenses/MIT */ -#include "scriptmanager.h" -#include "util/memory.h" -#include "assert/assert.h" -#include "debug/debug.h" -#include "asset/asset.h" +#include "scriptmanager.hpp" +#include "util/memory.hpp" +#include "assert/assert.hpp" +#include "debug/debug.hpp" +#include "asset/asset.hpp" scriptmanager_t SCRIPT_MANAGER; diff --git a/src/script/scriptmanager.h b/src/script/scriptmanager.hpp similarity index 90% rename from src/script/scriptmanager.h rename to src/script/scriptmanager.hpp index 04ebe8e..0c8932f 100644 --- a/src/script/scriptmanager.h +++ b/src/script/scriptmanager.hpp @@ -6,8 +6,8 @@ */ #pragma once -#include "error/error.h" -#include "scriptcontext.h" +#include "error/error.hpp" +#include "scriptcontext.hpp" typedef struct scriptmanager_s { scriptcontext_t mainContext; diff --git a/src/script/scriptvalue.h b/src/script/scriptvalue.hpp similarity index 96% rename from src/script/scriptvalue.h rename to src/script/scriptvalue.hpp index 3431574..fb97a51 100644 --- a/src/script/scriptvalue.h +++ b/src/script/scriptvalue.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" #define SCRIPT_VALUE_TYPE_NIL 0 #define SCRIPT_VALUE_TYPE_INT 1 diff --git a/src/thread/CMakeLists.txt b/src/thread/CMakeLists.txt index 89404af..3b91cef 100644 --- a/src/thread/CMakeLists.txt +++ b/src/thread/CMakeLists.txt @@ -6,8 +6,8 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - thread.c - threadmutex.c + thread.cpp + threadmutex.cpp ) # Compiler flags. diff --git a/src/thread/thread.c b/src/thread/thread.cpp similarity index 97% rename from src/thread/thread.c rename to src/thread/thread.cpp index 83a22de..b1841a9 100644 --- a/src/thread/thread.c +++ b/src/thread/thread.cpp @@ -5,9 +5,9 @@ * https://opensource.org/licenses/MIT */ -#include "thread.h" -#include "util/memory.h" -#include "assert/assert.h" +#include "thread.hpp" +#include "util/memory.hpp" +#include "assert/assert.hpp" void threadInit(thread_t *thread, const threadcallback_t callback) { assertNotNull(thread, "Thread cannot be NULL."); diff --git a/src/thread/thread.h b/src/thread/thread.hpp similarity index 98% rename from src/thread/thread.h rename to src/thread/thread.hpp index 8235f33..b787580 100644 --- a/src/thread/thread.h +++ b/src/thread/thread.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "thread/threadmutex.h" +#include "thread/threadmutex.hpp" #if THREAD_PTHREAD #include diff --git a/src/thread/threadmutex.c b/src/thread/threadmutex.cpp similarity index 97% rename from src/thread/threadmutex.c rename to src/thread/threadmutex.cpp index e19164a..9346e38 100644 --- a/src/thread/threadmutex.c +++ b/src/thread/threadmutex.cpp @@ -5,7 +5,7 @@ * https://opensource.org/licenses/MIT */ -#include "threadmutex.h" +#include "threadmutex.hpp" void threadMutexInit(threadmutex_t *lock) { #if THREAD_PTHREAD diff --git a/src/thread/threadmutex.h b/src/thread/threadmutex.hpp similarity index 98% rename from src/thread/threadmutex.h rename to src/thread/threadmutex.hpp index 4a684a2..4532fc2 100644 --- a/src/thread/threadmutex.h +++ b/src/thread/threadmutex.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" #if THREAD_PTHREAD #include diff --git a/src/time/CMakeLists.txt b/src/time/CMakeLists.txt index 2f93036..66bf87b 100644 --- a/src/time/CMakeLists.txt +++ b/src/time/CMakeLists.txt @@ -6,7 +6,7 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - time.c + time.cpp ) # Compiler defs diff --git a/src/time/time.c b/src/time/time.cpp similarity index 93% rename from src/time/time.c rename to src/time/time.cpp index de12317..dfced72 100644 --- a/src/time/time.c +++ b/src/time/time.cpp @@ -5,9 +5,9 @@ * https://opensource.org/licenses/MIT */ -#include "time.h" -#include "util/memory.h" -#include "assert/assert.h" +#include "time.hpp" +#include "util/memory.hpp" +#include "assert/assert.hpp" #if TIME_SDL2 #include diff --git a/src/time/time.h b/src/time/time.hpp similarity index 96% rename from src/time/time.h rename to src/time/time.hpp index e95ae54..c237750 100644 --- a/src/time/time.h +++ b/src/time/time.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" #define TIME_STEP (1.0f / 60.0f) // 60 Ticks per second (what we are aiming for) diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index eacb921..e33ea9b 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -6,11 +6,11 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - ui.c - uitext.c - uidebug.c - uiframe.c - uitextbox.c + ui.cpp + uitext.cpp + uidebug.cpp + uiframe.cpp + uitextbox.cpp ) # Subdirs diff --git a/src/ui/element/uielementtype.h b/src/ui/element/uielementtype.hpp similarity index 100% rename from src/ui/element/uielementtype.h rename to src/ui/element/uielementtype.hpp diff --git a/src/ui/ui.c b/src/ui/ui.cpp similarity index 85% rename from src/ui/ui.c rename to src/ui/ui.cpp index d575ea5..dd1b0fd 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.cpp @@ -5,13 +5,13 @@ * https://opensource.org/licenses/MIT */ -#include "ui.h" -#include "assert/assert.h" -#include "ui/uidebug.h" -#include "util/memory.h" -#include "display/tileset/tileset_minogram.h" -#include "display/screen.h" -#include "ui/uitextbox.h" +#include "ui.hpp" +#include "assert/assert.hpp" +#include "ui/uidebug.hpp" +#include "util/memory.hpp" +#include "display/tileset/tileset_minogram.hpp" +#include "display/screen.hpp" +#include "ui/uitextbox.hpp" ui_t UI; diff --git a/src/ui/ui.h b/src/ui/ui.hpp similarity index 87% rename from src/ui/ui.h rename to src/ui/ui.hpp index 93a364d..e16ac85 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.hpp @@ -6,10 +6,10 @@ */ #pragma once -#include "asset/asset.h" -#include "display/texture.h" -#include "display/tileset/tileset.h" -#include "display/camera.h" +#include "asset/asset.hpp" +#include "display/texture.hpp" +#include "display/tileset/tileset.hpp" +#include "display/camera.hpp" typedef struct { camera_t camera; diff --git a/src/ui/uidebug.c b/src/ui/uidebug.cpp similarity index 91% rename from src/ui/uidebug.c rename to src/ui/uidebug.cpp index abe1588..499744e 100644 --- a/src/ui/uidebug.c +++ b/src/ui/uidebug.cpp @@ -5,13 +5,13 @@ * https://opensource.org/licenses/MIT */ -#include "uidebug.h" -#include "time/time.h" -#include "util/string.h" -#include "ui/uitext.h" -#include "display/screen.h" -#include "display/spritebatch.h" -#include "rpg/entity/entity.h" +#include "uidebug.hpp" +#include "time/time.hpp" +#include "util/string.hpp" +#include "ui/uitext.hpp" +#include "display/screen.hpp" +#include "display/spritebatch.hpp" +#include "rpg/entity/entity.hpp" bool_t UI_DEBUG_DRAW = true; diff --git a/src/ui/uidebug.h b/src/ui/uidebug.hpp similarity index 84% rename from src/ui/uidebug.h rename to src/ui/uidebug.hpp index 3f106df..d34a852 100644 --- a/src/ui/uidebug.h +++ b/src/ui/uidebug.hpp @@ -6,8 +6,8 @@ */ #pragma once -#include "display/tileset/tileset.h" -#include "display/texture.h" +#include "display/tileset/tileset.hpp" +#include "display/texture.hpp" /** * Renders the debug information UI element. diff --git a/src/ui/uiframe.c b/src/ui/uiframe.cpp similarity index 98% rename from src/ui/uiframe.c rename to src/ui/uiframe.cpp index d47509d..bb18898 100644 --- a/src/ui/uiframe.c +++ b/src/ui/uiframe.cpp @@ -5,9 +5,9 @@ * https://opensource.org/licenses/MIT */ -#include "uiframe.h" -#include "display/spritebatch.h" -#include "assert/assert.h" +#include "uiframe.hpp" +#include "display/spritebatch.hpp" +#include "assert/assert.hpp" #include void uiFrameDraw( diff --git a/src/ui/uiframe.h b/src/ui/uiframe.hpp similarity index 96% rename from src/ui/uiframe.h rename to src/ui/uiframe.hpp index 2a9e9d0..9d6a3ef 100644 --- a/src/ui/uiframe.h +++ b/src/ui/uiframe.hpp @@ -6,8 +6,8 @@ */ #pragma once -#include "display/tileset/tileset.h" -#include "display/texture.h" +#include "display/tileset/tileset.hpp" +#include "display/texture.hpp" /** * Draw a UI Frame (using the 9-slice technique). diff --git a/src/ui/uitext.c b/src/ui/uitext.cpp similarity index 94% rename from src/ui/uitext.c rename to src/ui/uitext.cpp index 2b43a2b..113d51c 100644 --- a/src/ui/uitext.c +++ b/src/ui/uitext.cpp @@ -5,10 +5,10 @@ // * https://opensource.org/licenses/MIT // */ -#include "uitext.h" -#include "assert/assert.h" -#include "util/memory.h" -#include "display/spritebatch.h" +#include "uitext.hpp" +#include "assert/assert.hpp" +#include "util/memory.hpp" +#include "display/spritebatch.hpp" void uiTextDrawChar( const float_t x, diff --git a/src/ui/uitext.h b/src/ui/uitext.hpp similarity index 94% rename from src/ui/uitext.h rename to src/ui/uitext.hpp index 210f051..5cbcd26 100644 --- a/src/ui/uitext.h +++ b/src/ui/uitext.hpp @@ -6,9 +6,9 @@ */ #pragma once -#include "asset/asset.h" -#include "display/texture.h" -#include "display/tileset/tileset_minogram.h" +#include "asset/asset.hpp" +#include "display/texture.hpp" +#include "display/tileset/tileset_minogram.hpp" #define UI_TEXT_CHAR_START '!' diff --git a/src/ui/uitextbox.c b/src/ui/uitextbox.cpp similarity index 80% rename from src/ui/uitextbox.c rename to src/ui/uitextbox.cpp index 47b0a87..c673e66 100644 --- a/src/ui/uitextbox.c +++ b/src/ui/uitextbox.cpp @@ -5,13 +5,13 @@ * https://opensource.org/licenses/MIT */ -#include "uitextbox.h" -#include "ui/ui.h" -#include "ui/uitext.h" -#include "rpg/rpgtextbox.h" -#include "display/screen.h" -#include "display/spritebatch.h" -#include "input/input.h" +#include "uitextbox.hpp" +#include "ui/ui.hpp" +#include "ui/uitext.hpp" +#include "rpg/rpgtextbox.hpp" +#include "display/screen.hpp" +#include "display/spritebatch.hpp" +#include "input/input.hpp" void uiTextboxUpdate() { if(!rpgTextboxIsVisible()) return; diff --git a/src/ui/uitextbox.h b/src/ui/uitextbox.hpp similarity index 93% rename from src/ui/uitextbox.h rename to src/ui/uitextbox.hpp index 09b2823..c29ee43 100644 --- a/src/ui/uitextbox.h +++ b/src/ui/uitextbox.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" /** * Updates the RPG textbox state. diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 75b1187..95bf988 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -6,7 +6,7 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - memory.c - string.c - math.c + memory.cpp + string.cpp + math.cpp ) \ No newline at end of file diff --git a/src/util/math.c b/src/util/math.cpp similarity index 95% rename from src/util/math.c rename to src/util/math.cpp index 55f8f7a..8911939 100644 --- a/src/util/math.c +++ b/src/util/math.cpp @@ -5,7 +5,7 @@ * https://opensource.org/licenses/MIT */ -#include "math.h" +#include "math.hpp" uint32_t mathNextPowTwo(uint32_t value) { if(value == 0) return 1; // Handle zero case diff --git a/src/util/math.h b/src/util/math.hpp similarity index 98% rename from src/util/math.h rename to src/util/math.hpp index 3e93b98..dfc029d 100644 --- a/src/util/math.h +++ b/src/util/math.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" /** * Finds the next power of two greater than or equal to the given value. diff --git a/src/util/memory.c b/src/util/memory.cpp similarity index 98% rename from src/util/memory.c rename to src/util/memory.cpp index 3e0fea8..9553fd5 100644 --- a/src/util/memory.c +++ b/src/util/memory.cpp @@ -5,8 +5,8 @@ * https://opensource.org/licenses/MIT */ -#include "memory.h" -#include "assert/assert.h" +#include "memory.hpp" +#include "assert/assert.hpp" void * memoryAllocate(const size_t size) { assertTrue(size > 0, "Cannot allocate 0 bytes of memory."); diff --git a/src/util/memory.h b/src/util/memory.hpp similarity index 99% rename from src/util/memory.h rename to src/util/memory.hpp index 1e08137..73b73f7 100644 --- a/src/util/memory.h +++ b/src/util/memory.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" /** * Allocates memory. diff --git a/src/util/string.c b/src/util/string.cpp similarity index 98% rename from src/util/string.c rename to src/util/string.cpp index 319cc5f..31df77a 100644 --- a/src/util/string.c +++ b/src/util/string.cpp @@ -5,9 +5,9 @@ * https://opensource.org/licenses/MIT */ -#include "string.h" -#include "assert/assert.h" -#include "util/memory.h" +#include "string.hpp" +#include "assert/assert.hpp" +#include "util/memory.hpp" bool_t stringIsWhitespace(const char_t c) { return isspace(c); diff --git a/src/util/string.h b/src/util/string.hpp similarity index 99% rename from src/util/string.h rename to src/util/string.hpp index f269573..c6011e0 100644 --- a/src/util/string.h +++ b/src/util/string.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "dusk.h" +#include "dusk.hpp" /** * Determines if a character is whitespace. diff --git a/tools/assetstool/processlanguage.py b/tools/assetstool/processlanguage.py index 30673bb..692c2a9 100644 --- a/tools/assetstool/processlanguage.py +++ b/tools/assetstool/processlanguage.py @@ -16,7 +16,7 @@ def processLanguageList(): # Language keys header data headerKeys = "// Auto-generated language keys header file.\n" headerKeys += "#pragma once\n" - headerKeys += "#include \"dusk.h\"\n\n" + headerKeys += "#include \"dusk.hpp\"\n\n" # This is the desired chunk groups list.. if a language key STARTS with any # of the keys in this list we would "like to" put it in that chunk group. @@ -144,7 +144,7 @@ def processLanguageList(): # Write out the language keys header file - outputFile = os.path.join(args.headers_dir, "locale", "language", "keys.h") + outputFile = os.path.join(args.headers_dir, "locale", "language", "keys.hpp") os.makedirs(os.path.dirname(outputFile), exist_ok=True) with open(outputFile, "w") as f: f.write(headerKeys) diff --git a/tools/assetstool/processpalette.py b/tools/assetstool/processpalette.py index 487a95b..8583985 100644 --- a/tools/assetstool/processpalette.py +++ b/tools/assetstool/processpalette.py @@ -45,7 +45,7 @@ def processPalette(asset): # Header now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") data = f"// Palette Generated for {asset['path']} at {now}\n" - data += f"#include \"display/palette/palette.h\"\n\n" + data += f"#include \"display/palette/palette.hpp\"\n\n" data += f"#define PALETTE_{paletteIndex}_COLOR_COUNT {len(pixels)}\n\n" data += f"#pragma pack(push, 1)\n" data += f"static const color_t PALETTE_{paletteIndex}_COLORS[PALETTE_{paletteIndex}_COLOR_COUNT] = {{\n" @@ -59,7 +59,7 @@ def processPalette(asset): data += f"}};\n" # Write Header - outputFile = os.path.join(args.headers_dir, "display", "palette", f"palette_{paletteIndex}.h") + outputFile = os.path.join(args.headers_dir, "display", "palette", f"palette_{paletteIndex}.hpp") os.makedirs(os.path.dirname(outputFile), exist_ok=True) with open(outputFile, "w") as f: f.write(data) @@ -88,7 +88,7 @@ def processPaletteList(): data += f"}};\n" # Write the palette list to a header file - outputFile = os.path.join(args.headers_dir, "display", "palette", "palettelist.h") + outputFile = os.path.join(args.headers_dir, "display", "palette", "palettelist.hpp") os.makedirs(os.path.dirname(outputFile), exist_ok=True) with open(outputFile, "w") as f: f.write(data) \ No newline at end of file diff --git a/tools/assetstool/processtileset.py b/tools/assetstool/processtileset.py index 1208d1a..2c675c1 100644 --- a/tools/assetstool/processtileset.py +++ b/tools/assetstool/processtileset.py @@ -124,7 +124,7 @@ def processTileset(asset): # Create header data = f"// Tileset Generated for {asset['path']} at {now}\n" data += f"#pragma once\n" - data += f"#include \"display/tileset/tileset.h\"\n\n" + data += f"#include \"display/tileset/tileset.hpp\"\n\n" data += f"static const tileset_t TILESET_{tilesetNameUpper} = {{\n" data += f" .tileWidth = {tilesetData['tileWidth']},\n" data += f" .tileHeight = {tilesetData['tileHeight']},\n" @@ -137,7 +137,7 @@ def processTileset(asset): # Write Header - outputFile = os.path.join(args.headers_dir, "display", "tileset", f"tileset_{tilesetName}.h") + outputFile = os.path.join(args.headers_dir, "display", "tileset", f"tileset_{tilesetName}.hpp") os.makedirs(os.path.dirname(outputFile), exist_ok=True) with open(outputFile, 'w') as f: f.write(data)