From da1a5a3f1b49c4174d828c928f3399f70fe3e2a8 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Fri, 3 Apr 2026 12:56:04 -0500 Subject: [PATCH] Asset refactor --- .../type => archive/loader}/CMakeLists.txt | 2 - .../type => archive/loader}/assetlanguage.c | 0 .../type => archive/loader}/assetlanguage.h | 0 .../type => archive/loader}/assetscript.c | 0 .../type => archive/loader}/assetscript.h | 0 .../type => archive/loader}/assettexture.c | 0 .../type => archive/loader}/assettexture.h | 0 .../type => archive/loader}/assettileset.c | 0 .../type => archive/loader}/assettileset.h | 0 assets/init.lua | 2 +- assets/main_palette.dpf | Bin 17 -> 0 bytes assets/scene/main_menu/main_menu.lua | 44 +++ assets/scene/minesweeper.lua | 264 ------------------ assets/test.json | 19 ++ assets/ui/minogram.dtx | Bin 32781 -> 0 bytes assets/ui/minogram.png | Bin 0 -> 1260 bytes cmake/modules/Findstb.cmake | 31 ++ cmake/modules/Findyyjson.cmake | 18 ++ src/CMakeLists.txt | 3 +- src/dusk/CMakeLists.txt | 18 ++ src/dusk/asset/CMakeLists.txt | 3 +- src/dusk/asset/asset.c | 111 ++------ src/dusk/asset/asset.h | 15 +- src/dusk/asset/assetfile.c | 53 ++++ src/dusk/asset/assetfile.h | 57 ++++ src/dusk/asset/assettype.h | 84 ------ src/dusk/asset/loader/CMakeLists.txt | 12 + src/dusk/asset/loader/display/CMakeLists.txt | 11 + .../asset/loader/display/assettextureloader.c | 115 ++++++++ .../asset/loader/display/assettextureloader.h | 50 ++++ .../asset/loader/display/assettilesetloader.c | 80 ++++++ .../asset/loader/display/assettilesetloader.h | 30 ++ src/dusk/asset/loader/json/CMakeLists.txt | 10 + src/dusk/asset/loader/json/assetjsonloader.c | 53 ++++ src/dusk/asset/loader/json/assetjsonloader.h | 45 +++ src/dusk/asset/loader/locale/CMakeLists.txt | 10 + .../asset/loader/locale/assetlocaleloader.c | 19 ++ .../asset/loader/locale/assetlocaleloader.h | 34 +++ src/dusk/asset/loader/script/CMakeLists.txt | 10 + .../asset/loader/script/assetscriptloader.c | 82 ++++++ .../asset/loader/script/assetscriptloader.h | 48 ++++ src/dusk/asset/type/assetmap.c | 15 - src/dusk/asset/type/assetmap.h | 20 -- src/dusk/asset/type/assetmapchunk.c | 185 ------------ src/dusk/asset/type/assetmapchunk.h | 19 -- src/dusk/display/camera/camera.c | 4 +- src/dusk/display/text/text.c | 19 +- src/dusk/engine/engine.c | 26 +- src/dusk/locale/localemanager.c | 3 - src/dusk/locale/localemanager.h | 4 +- .../script/module/display/moduletexture.c | 13 +- src/dusk/script/scriptcontext.c | 22 +- src/dusktrivia/CMakeLists.txt | 14 + src/dusktrivia/game/CMakeLists.txt | 10 + src/dusktrivia/game/game.c | 20 ++ src/dusktrivia/game/game.h | 30 ++ src/dusktrivia/script/CMakeLists.txt | 7 + src/dusktrivia/script/module/CMakeLists.txt | 6 + src/dusktrivia/script/scriptgame.h | 8 + 59 files changed, 1032 insertions(+), 726 deletions(-) rename {src/dusk/asset/type => archive/loader}/CMakeLists.txt (88%) rename {src/dusk/asset/type => archive/loader}/assetlanguage.c (100%) rename {src/dusk/asset/type => archive/loader}/assetlanguage.h (100%) rename {src/dusk/asset/type => archive/loader}/assetscript.c (100%) rename {src/dusk/asset/type => archive/loader}/assetscript.h (100%) rename {src/dusk/asset/type => archive/loader}/assettexture.c (100%) rename {src/dusk/asset/type => archive/loader}/assettexture.h (100%) rename {src/dusk/asset/type => archive/loader}/assettileset.c (100%) rename {src/dusk/asset/type => archive/loader}/assettileset.h (100%) delete mode 100644 assets/main_palette.dpf create mode 100644 assets/scene/main_menu/main_menu.lua delete mode 100644 assets/scene/minesweeper.lua create mode 100644 assets/test.json delete mode 100644 assets/ui/minogram.dtx create mode 100644 assets/ui/minogram.png create mode 100644 cmake/modules/Findstb.cmake create mode 100644 cmake/modules/Findyyjson.cmake create mode 100644 src/dusk/asset/assetfile.c create mode 100644 src/dusk/asset/assetfile.h delete mode 100644 src/dusk/asset/assettype.h create mode 100644 src/dusk/asset/loader/CMakeLists.txt create mode 100644 src/dusk/asset/loader/display/CMakeLists.txt create mode 100644 src/dusk/asset/loader/display/assettextureloader.c create mode 100644 src/dusk/asset/loader/display/assettextureloader.h create mode 100644 src/dusk/asset/loader/display/assettilesetloader.c create mode 100644 src/dusk/asset/loader/display/assettilesetloader.h create mode 100644 src/dusk/asset/loader/json/CMakeLists.txt create mode 100644 src/dusk/asset/loader/json/assetjsonloader.c create mode 100644 src/dusk/asset/loader/json/assetjsonloader.h create mode 100644 src/dusk/asset/loader/locale/CMakeLists.txt create mode 100644 src/dusk/asset/loader/locale/assetlocaleloader.c create mode 100644 src/dusk/asset/loader/locale/assetlocaleloader.h create mode 100644 src/dusk/asset/loader/script/CMakeLists.txt create mode 100644 src/dusk/asset/loader/script/assetscriptloader.c create mode 100644 src/dusk/asset/loader/script/assetscriptloader.h delete mode 100644 src/dusk/asset/type/assetmap.c delete mode 100644 src/dusk/asset/type/assetmap.h delete mode 100644 src/dusk/asset/type/assetmapchunk.c delete mode 100644 src/dusk/asset/type/assetmapchunk.h create mode 100644 src/dusktrivia/CMakeLists.txt create mode 100644 src/dusktrivia/game/CMakeLists.txt create mode 100644 src/dusktrivia/game/game.c create mode 100644 src/dusktrivia/game/game.h create mode 100644 src/dusktrivia/script/CMakeLists.txt create mode 100644 src/dusktrivia/script/module/CMakeLists.txt create mode 100644 src/dusktrivia/script/scriptgame.h diff --git a/src/dusk/asset/type/CMakeLists.txt b/archive/loader/CMakeLists.txt similarity index 88% rename from src/dusk/asset/type/CMakeLists.txt rename to archive/loader/CMakeLists.txt index 0450182..638a677 100644 --- a/src/dusk/asset/type/CMakeLists.txt +++ b/archive/loader/CMakeLists.txt @@ -10,6 +10,4 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME} assettileset.c assetlanguage.c assetscript.c - assetmap.c - assetmapchunk.c ) \ No newline at end of file diff --git a/src/dusk/asset/type/assetlanguage.c b/archive/loader/assetlanguage.c similarity index 100% rename from src/dusk/asset/type/assetlanguage.c rename to archive/loader/assetlanguage.c diff --git a/src/dusk/asset/type/assetlanguage.h b/archive/loader/assetlanguage.h similarity index 100% rename from src/dusk/asset/type/assetlanguage.h rename to archive/loader/assetlanguage.h diff --git a/src/dusk/asset/type/assetscript.c b/archive/loader/assetscript.c similarity index 100% rename from src/dusk/asset/type/assetscript.c rename to archive/loader/assetscript.c diff --git a/src/dusk/asset/type/assetscript.h b/archive/loader/assetscript.h similarity index 100% rename from src/dusk/asset/type/assetscript.h rename to archive/loader/assetscript.h diff --git a/src/dusk/asset/type/assettexture.c b/archive/loader/assettexture.c similarity index 100% rename from src/dusk/asset/type/assettexture.c rename to archive/loader/assettexture.c diff --git a/src/dusk/asset/type/assettexture.h b/archive/loader/assettexture.h similarity index 100% rename from src/dusk/asset/type/assettexture.h rename to archive/loader/assettexture.h diff --git a/src/dusk/asset/type/assettileset.c b/archive/loader/assettileset.c similarity index 100% rename from src/dusk/asset/type/assettileset.c rename to archive/loader/assettileset.c diff --git a/src/dusk/asset/type/assettileset.h b/archive/loader/assettileset.h similarity index 100% rename from src/dusk/asset/type/assettileset.h rename to archive/loader/assettileset.h diff --git a/assets/init.lua b/assets/init.lua index 34ef1e8..7599ea9 100644 --- a/assets/init.lua +++ b/assets/init.lua @@ -75,4 +75,4 @@ else print("Unknown platform, no default input bindings set.") end -sceneSet('scene/minesweeper.lua') \ No newline at end of file +sceneSet('scene/main_menu/main_menu.lua') \ No newline at end of file diff --git a/assets/main_palette.dpf b/assets/main_palette.dpf deleted file mode 100644 index bae39084b5e7356cb76d3402a366adbacd3af09e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17 ScmZ<>aARa-0D}KO0HOdWuLalu diff --git a/assets/scene/main_menu/main_menu.lua b/assets/scene/main_menu/main_menu.lua new file mode 100644 index 0000000..2d0642c --- /dev/null +++ b/assets/scene/main_menu/main_menu.lua @@ -0,0 +1,44 @@ +module('spritebatch') +module('camera') +module('color') +module('ui') +module('screen') +module('time') +module('text') +module('tileset') +module('texture') +module('input') +module('shader') +module('locale') + +screenSetBackground(colorCornflowerBlue()) +camera = cameraCreate(CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) + +function sceneDispose() +end + +function sceneUpdate() +end + +function sceneRender() + -- Update camera + camera.top = screenGetHeight() + camera.right = screenGetWidth() + + shaderBind(SHADER_UNLIT) + proj = cameraGetProjectionMatrix(camera) + shaderSetMatrix(SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj) + view = cameraGetViewMatrix(camera) + shaderSetMatrix(SHADER_UNLIT, SHADER_UNLIT_VIEW, view) + + -- shaderSetTexture(SHADER_UNLIT, SHADER_UNLIT_TEXTURE, nil) + -- spriteBatchPush( + -- 32, 32, + -- 64, 64, + -- colorWhite() + -- ) + -- spriteBatchFlush() + + textDraw(10, 10, "Hello World\nHow are you?", colorRed()) + spriteBatchFlush() +end \ No newline at end of file diff --git a/assets/scene/minesweeper.lua b/assets/scene/minesweeper.lua deleted file mode 100644 index 37a29fb..0000000 --- a/assets/scene/minesweeper.lua +++ /dev/null @@ -1,264 +0,0 @@ -module('spritebatch') -module('camera') -module('color') -module('ui') -module('screen') -module('time') -module('glm') -module('text') -module('tileset') -module('texture') -module('input') -module('shader') - -CELL_STATE_DEFAULT = 0 -CELL_STATE_HOVER = 1 -CELL_STATE_DOWN = 2 -CELL_STATE_DISABLED = 3 - -screenSetBackground(colorCornflowerBlue()) -camera = cameraCreate(CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) - --- tilesetUi = tilesetGetByName("ui") --- textureUi = textureLoad(tilesetUi.texture) - --- tilesetBorder = tilesetGetByName("border") --- textureBorder = textureLoad(tilesetBorder.texture) - --- textureGrid = textureLoad("minesweeper/grid_bg.dpi") - --- tilesetCell = tilesetGetByName("cell") --- textureCell = textureLoad(tilesetCell.texture) --- cellSliceDefault = tilesetPositionGetUV(tilesetCell, 3, 5) --- cellSliceHover = tilesetPositionGetUV(tilesetCell, 3, 4) --- cellSliceDown = tilesetPositionGetUV(tilesetCell, 3, 6) --- cellSliceDisabled = tilesetPositionGetUV(tilesetCell, 3, 7) - --- sweepwerCols = 10 --- sweeperRows = 14 - --- mouseX = -1 --- mouseY = -1 --- centerX = 0 --- centerY = 0 --- boardWidth = sweepwerCols * tilesetCell.tileWidth --- boardHeight = sweeperRows * tilesetCell.tileHeight - --- i = 0 --- cells = {} --- for y = 1, sweeperRows do --- for x = 1, sweepwerCols do --- cells[i] = CELL_STATE_DEFAULT --- i = i + 1 --- end --- end - -function cellDraw(x, y, type) - local slice = cellSliceDefault - if type == CELL_STATE_HOVER then - slice = cellSliceHover - elseif type == CELL_STATE_DOWN then - slice = cellSliceDown - elseif type == CELL_STATE_DISABLED then - slice = cellSliceDisabled - end - - spriteBatchPush( - x, y, - x + tilesetCell.tileWidth, y + tilesetCell.tileHeight, - colorWhite(), - slice.u0, slice.v0, - slice.u1, slice.v1 - ) -end - -function backgroundDraw() - local t = (TIME.time / 40) % 1 - local scaleX = screenGetWidth() / textureGrid.width - local scaleY = screenGetHeight() / textureGrid.height - local u0 = t * scaleX - local v0 = t * scaleY - local u1 = scaleX + u0 - local v1 = scaleY + v0 - - spriteBatchPush(textureGrid, - 0, 0, - screenGetWidth(), screenGetHeight(), - colorWhite(), - u0, v0, - u1, v1 - ) -end - -function borderDraw(x, y, innerWidth, innerHeight) - -- Top Left - local uv = tilesetPositionGetUV(tilesetBorder, 0, 0) - spriteBatchPush(textureBorder, - x - tilesetBorder.tileWidth, y - tilesetBorder.tileWidth, - x, y, - colorWhite(), - uv.u0, uv.v0, - uv.u1, uv.v1 - ) - - -- Top Right - uv = tilesetPositionGetUV(tilesetBorder, 10, 0) - spriteBatchPush(textureBorder, - x + innerWidth, y - tilesetBorder.tileHeight, - x + innerWidth + tilesetBorder.tileWidth, y, - colorWhite(), - uv.u0, uv.v0, - uv.u1, uv.v1 - ) - - -- Bottom Left - uv = tilesetPositionGetUV(tilesetBorder, 0, 10) - spriteBatchPush(textureBorder, - x - tilesetBorder.tileWidth, y + innerHeight, - x, y + innerHeight + tilesetBorder.tileHeight, - colorWhite(), - uv.u0, uv.v0, - uv.u1, uv.v1 - ) - - -- Bottom Right - uv = tilesetPositionGetUV(tilesetBorder, 10, 10) - spriteBatchPush(textureBorder, - x + innerWidth, y + innerHeight, - x + innerWidth + tilesetBorder.tileWidth, y + innerHeight + tilesetBorder.tileHeight, - colorWhite(), - uv.u0, uv.v0, - uv.u1, uv.v1 - ) - - -- Top - uv = tilesetPositionGetUV(tilesetBorder, 1, 0) - spriteBatchPush(textureBorder, - x, y - tilesetBorder.tileHeight, - x + innerWidth, y, - colorWhite(), - uv.u0, uv.v0, - uv.u1, uv.v1 - ) - - -- Bottom - uv = tilesetPositionGetUV(tilesetBorder, 1, 10) - spriteBatchPush(textureBorder, - x, y + innerHeight, - x + innerWidth, y + innerHeight + tilesetBorder.tileHeight, - colorWhite(), - uv.u0, uv.v0, - uv.u1, uv.v1 - ) - - -- Left - uv = tilesetPositionGetUV(tilesetBorder, 0, 1) - spriteBatchPush(textureBorder, - x - tilesetBorder.tileWidth, y, - x, y + innerHeight, - colorWhite(), - uv.u0, uv.v0, - uv.u1, uv.v1 - ) - - -- Right - uv = tilesetPositionGetUV(tilesetBorder, 10, 1) - spriteBatchPush(textureBorder, - x + innerWidth, y, - x + innerWidth + tilesetBorder.tileWidth, y + innerHeight, - colorWhite(), - uv.u0, uv.v0, - uv.u1, uv.v1 - ) -end - -x = 0 -y = 0 - -function sceneDispose() -end - -function sceneUpdate() - x = x + inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT) - y = y + inputAxis(INPUT_ACTION_UP, INPUT_ACTION_DOWN) -end - -function sceneRender() - -- Update camera - camera.bottom = 0 - camera.top = screenGetHeight() - camera.right = screenGetWidth() - - shaderBind(SHADER_UNLIT) - proj = cameraGetProjectionMatrix(camera) - shaderSetMatrix(SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj) - view = cameraGetViewMatrix(camera) - shaderSetMatrix(SHADER_UNLIT, SHADER_UNLIT_VIEW, view) - - shaderSetTexture(SHADER_UNLIT, SHADER_UNLIT_TEXTURE, nil) - spriteBatchPush( - x, y, - x + 32, y + 32, - colorWhite() - ) - spriteBatchFlush() - - textDraw(10, 10, "Hello World\nHow are you?", colorRed()) - spriteBatchFlush() - - -- Update mouse position - -- if INPUT_POINTER then - -- mouseX = inputGetValue(INPUT_ACTION_POINTERX) * screenGetWidth() - -- mouseY = inputGetValue(INPUT_ACTION_POINTERY) * screenGetHeight() - - -- -- Draw cursor - -- spriteBatchPush( - -- nil, - -- mouseX - 2, mouseY - 2, - -- mouseX + 2, mouseY + 2, - -- colorRed(), - -- 0, 0, - -- 1, 1 - -- ) - -- end - - - -- textDraw(10, 10, "Hello World") - - -- centerX = math.floor(screenGetWidth() / 2) - -- centerY = math.floor(screenGetHeight() / 2) - - -- Draw elements - -- backgroundDraw() - -- borderDraw( - -- centerX - (boardWidth / 2), centerY - (boardHeight / 2), - -- boardWidth, boardHeight - -- ) - - -- i = 0 - -- -- Foreach cell - -- local offX = centerX - (boardWidth / 2) - -- local offY = centerY - (boardHeight / 2) - -- for y = 0, sweeperRows - 1 do - -- for x = 0, sweepwerCols - 1 do - -- i = y * sweepwerCols + x - - -- -- Hovered - -- if - -- cells[i] == CELL_STATE_DEFAULT and - -- mouseX >= x * tilesetCell.tileWidth + offX and mouseX < (x + 1) * tilesetCell.tileWidth + offX and - -- mouseY >= y * tilesetCell.tileHeight + offY and mouseY < (y + 1) * tilesetCell.tileHeight + offY - -- then - -- cells[i] = CELL_STATE_HOVER - -- else - -- cells[i] = CELL_STATE_DEFAULT - -- end - - -- cellDraw( - -- x * tilesetCell.tileWidth + offX, - -- y * tilesetCell.tileHeight + offY, - -- cells[i] - -- ) - -- end - -- end -end \ No newline at end of file diff --git a/assets/test.json b/assets/test.json new file mode 100644 index 0000000..94ce366 --- /dev/null +++ b/assets/test.json @@ -0,0 +1,19 @@ +{ + "name": "Dominic", + "age": 31, + "likes": [ + "thing1", + "thing2" + ], + "options": { + "someParam": true, + "someSubObject": { + "someSubSubParam": 52 + }, + "someArray": [ + 1, + 2, + 3 + ] + } +} \ No newline at end of file diff --git a/assets/ui/minogram.dtx b/assets/ui/minogram.dtx deleted file mode 100644 index af45a07d1c8c54d0a776f4b3e919d496e4475320..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32781 zcmeH|U2Y^d41}GV1`fI| zjU!z(esVl8eea|8EZV5=Xx?Xjw)VTd9_{bsl}^*?C8IArEq|I0p@sP7Qjt^2s@Nxk_igd#+LY{H)11W~SoG zyADtE%vCizt=z9{9`BPU4t90t`>d+=KKE0HC(?rse>CQNaUJgQ8tpE~?x6No?T2rX zMorE!YtL47&Li^(y_>-uiCwE2|?7bib=Jo4o6r=||^u z`H?P9XSU1szxD<8@8oOWd*8NSV86iYyg>E;KWQA_6itZkwKTXekN4nJ+Q=g>BqwzJ zY`r?C%Sq?>4roHxuddn4_sAXLAXzv#)6<7{$Xt*d986t2Ju)La+LQT?yRKSiw8vL_ zvwb=r9b|7fhz@o-K1dE+)s@R0dONK0((+`#{M6uh9g@2m*{|B8@}%jIe`g*T5*e|eOV86hAfz=nN{w}$ef6LtC4%a-NI$o!1 zo_ju@nhfZ9=6jZ$BR+W$9ZVe#Rylbb_tAvtS7Yu12iXq}p4GDt4j!G~^`V2z1*La2 zJ!HrUbWn?;b7*SQ!7gicKxZtufoy3 z@;K}#PVJaFTgH z9S+X&_?d@;v)s&Q4%p>8ojy=G)jHJlI>&eK73$mz4zeR0Jga9P96UOI)|bA|?`nF4 zo^k$J-S4=v9({*Aj_-&jM0ahZ{o~^S7nD^xl?t5MJyMO08-vAEs zZE!I4qr98*D4l)4ZZ7@|vwxPqi=W>G2l);-h@O~!$B*i|haQl-;UGF#>6J#l!lU_W z#w%+1U2vfv-@Vh7k(b$ucezeyM*5G|nU~nzo4LF3{4O}i_ayK1%#Ao6sF~D>mB$Y5 z%`|-G!)JIjKb!X|ets7mWKTGl`WenFP%~8PR5f?t9pRp>`qNL&PN{zf{_Da2|H1d< z_d2igU7z$LdB2BVN7XuA?%n-(C->vgpEKO|y6SiTyVSqScYc@O*Zz+E0{aE_3q0cm zR{u73cdz!Z{>_=qTlKr#>K@(qemA{)r`7LV>GzD+)g3dx>Z!ERoRL?}`YxKj+mF7> zxoZDb_d4BsMtSe2_B?YcE%We1dZjaujB~Hur{8_oT;~q_*&O_eL{{m;Tj%y~rbE9~%y@7Oc;3v@4Vw}0cS`>y7?clllPJH6AuBQeE z$-=?Z#qmJbs(hz;KbaLg+qW|Ns!V8bdsaJF4?~Hf<*1PY2^}n4vzMppHT>XCg{`~^`1@;T< P7uYYbUtqt$tG~d1MnoZj diff --git a/assets/ui/minogram.png b/assets/ui/minogram.png new file mode 100644 index 0000000000000000000000000000000000000000..c41f917ac2882308e41c4beb580f5753860562e8 GIT binary patch literal 1260 zcmV z?Q*Oj42Gf8`@dz+pVG-m-+Vz3ba`fW++swO5Xp->t=Dyx!#ZlMOV9uHvz5Hy681~w zT3x@ei_^{FHh?dWywYz<`aDpBO;2lf1 ztz&BW+ezGJHmjqAcCA}4A%+O!4D0V0i(A^;y**2td?nkQI9N4GY=K*^M zY|-%z?;JpTJV+r9*=qJyl#p(;mO@5u^hoY5iCJ59Hp1fo){UWx9zU)K_cMr7X>olZGQUZduIRi`)Y zT|&kjVD?4Ks(+S7@F+YwKx3pMdXzx#LQ!vfqSvE|I^MdrOan{tNvR_tYa|WyI1fT= zZ?xkyBFf$tolc>PK}gQ^@YFDvDamfvv0i!}0h*%a9j(^LkFKuq?_R}{M}mx*`j(2H zL_K-&T6Xzu;Ne60I3-Xb`mW&Wk(&kmT>yXEMSBazV~FR^rw34?kq5fwPeWoXBF%f#CUhxRg_)@(9+*MfFA&Wu$r! zgpr?z&jfX}6!xt;4hrp+ut-SHwAVs9IyQ=>>_wJ?UkO(Nsg(Lre5ww>CxP#{s)L)e z7O;?DdnThJ`(KIlMo{E!9M4-io~*(1 z{(yB}scvn*l?iy-BDKeBzYJ+Dpb=RMkm}LwshzZzV6~@}YY{}+?@a^g_4TfmNcKy~ zSPt&Zqch*ji}JDQE+@kQJe|1PjoxkLav4Yoq(l~jqqWK<_Bkp2aJG=U=S@?D|Sr#zYc1euYX`IbVZ>92sFkl|wGz0J z$eiHy?*v}#Q`nYYe8e6ddsjJX=Ye1;fpnjwbTwuRJCYiw**7vWf|bJ6G`#;ZhJJ51 zV)m%YQV)@RPe^}V=ajZo~z$+<7&iTqt%fwOw5!$L2%DuJv(TJ8pJyPtn z`q3OgI*-L`9SQx%5KB(&(fze!G<)<2LVriv?`>C)-Q(C*35;?Szr*2hI2;a#0RI5C W$o0rJ!cj&50000extension == NULL) continue; - if(!stringEndsWithCaseInsensitive(filename, cmp->extension)) continue; - def = cmp; - break; - } - if(def == NULL) { - errorThrow("Unknown asset type for file: %s", filename); - } + assertNotNull(loader, "Asset file loader cannot be NULL."); + + assetfile_t file = { + .filename = filename, + .params = params, + .output = output, + .zipFile = NULL, + .size = 0 + }; // Get file size of the asset. - zip_stat_t st; - zip_stat_init(&st); - if(!zip_stat(ASSET.zip, filename, 0, &st) == 0) { + zip_stat_init(&file.stat); + if(!zip_stat(ASSET.zip, filename, 0, &file.stat) == 0) { errorThrow("Failed to stat asset file: %s", filename); } // Minimum file size. - zip_int64_t fileSize = (zip_int64_t)st.size; - if(fileSize <= 0) { + file.size = (zip_int64_t)file.stat.size; + if(file.size <= 0) { errorThrow("Asset file is empty: %s", filename); } - // Try to open the file - zip_file_t *file = zip_fopen(ASSET.zip, filename, 0); - if(file == NULL) { - errorThrow("Failed to open asset file: %s", filename); - } - - // Load the asset data - switch(def->loadStrategy) { - case ASSET_LOAD_STRAT_ENTIRE: - assertNotNull(def->entire, "Asset load function cannot be NULL."); - - // Must have more to read - if(fileSize <= 0) { - zip_fclose(file); - errorThrow("No data remaining to read for asset: %s", filename); - } - - if(fileSize > def->dataSize) { - zip_fclose(file); - errorThrow( - "Asset file has too much data remaining after header: %s", - filename - ); - } - - // Create space to read the entire asset data - void *data = memoryAllocate(fileSize); - if(!data) { - zip_fclose(file); - errorThrow( - "Failed to allocate memory for asset data of file: %s", filename - ); - } - - // Read in the asset data. - zip_int64_t bytesRead = zip_fread(file, data, fileSize); - if(bytesRead == 0 || bytesRead > fileSize) { - memoryFree(data); - zip_fclose(file); - errorThrow("Failed to read asset data for file: %s", filename); - } - fileSize -= bytesRead; - - // Close the file now we have the data - zip_fclose(file); - - // Pass to the asset type loader - assetentire_t entire = { - .data = data, - .output = output - }; - errorret_t ret = def->entire(entire); - memoryFree(data); - - errorChain(ret); - break; - - case ASSET_LOAD_STRAT_CUSTOM: - assertNotNull(def->custom, "Asset load function cannot be NULL."); - assetcustom_t customData = { - .zipFile = file, - .output = output - }; - errorChain(def->custom(customData)); - break; - - default: - assertUnreachable("Unknown asset load strategy."); - } + errorChain(loader(&file)); + assertNull(file.zipFile, "Asset file loader did not close the file."); errorOk(); } diff --git a/src/dusk/asset/asset.h b/src/dusk/asset/asset.h index 26bc203..fb25bce 100644 --- a/src/dusk/asset/asset.h +++ b/src/dusk/asset/asset.h @@ -7,8 +7,8 @@ #pragma once #include "error/error.h" -#include "assettype.h" #include "asset/assetplatform.h" +#include "assetfile.h" #ifndef assetInitPlatform #error "Platform must define assetInitPlatform function." @@ -20,7 +20,7 @@ #define ASSET_FILE_NAME "dusk.dsk" #define ASSET_HEADER_SIZE 3 -typedef struct { +typedef struct asset_s { zip_t *zip; assetplatform_t platform; } asset_t; @@ -41,13 +41,20 @@ errorret_t assetInit(void); bool_t assetFileExists(const char_t *filename); /** - * Loads an asset by its filename, the output type depends on the asset type. + * Loads an asset by its filename, * * @param filename The filename of the asset to retrieve. + * @param loader Loader to use for loading the asset file. + * @param params Parameters to pass to the loader. * @param output The output pointer to store the loaded asset data. * @return An error code if the asset could not be loaded. */ -errorret_t assetLoad(const char_t *filename, void *output); +errorret_t assetLoad( + const char_t *filename, + assetfileloader_t loader, + void *params, + void *output +); /** * Disposes/cleans up the asset system. diff --git a/src/dusk/asset/assetfile.c b/src/dusk/asset/assetfile.c new file mode 100644 index 0000000..898bd01 --- /dev/null +++ b/src/dusk/asset/assetfile.c @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "asset/asset.h" +#include "assert/assert.h" + +errorret_t assetFileOpen(assetfile_t *file) { + assertNotNull(file, "Asset file cannot be NULL."); + assertNotNull(file->filename, "Asset file filename cannot be NULL."); + assertNotNull(ASSET.zip, "Asset zip cannot be NULL."); + assertNull(file->zipFile, "Asset file already open."); + + file->zipFile = zip_fopen(ASSET.zip, file->filename, 0); + if(file->zipFile == NULL) { + errorThrow("Failed to open asset file: %s", file->filename); + } + file->position = 0; + errorOk(); +} + +errorret_t assetFileRead( + assetfile_t *file, + void *buffer, + const size_t bufferSize +) { + assertNotNull(file, "Asset file cannot be NULL."); + assertNotNull(file->zipFile, "Asset file must be opened before reading."); + + // I assume zip_fread takes buffer NULL for skipping? + zip_int64_t bytesRead = zip_fread(file->zipFile, buffer, bufferSize); + if(bytesRead < 0) { + errorThrow("Failed to read from asset file: %s", file->filename); + } + file->position += bytesRead; + file->lastRead = bytesRead; + errorOk(); +} + +errorret_t assetFileClose(assetfile_t *file) { + assertNotNull(file, "Asset file cannot be NULL."); + assertNotNull(file->zipFile, "Asset file must be opened before closing."); + + if(zip_fclose(file->zipFile) != 0) { + errorThrow("Failed to close asset file: %s", file->filename); + } + file->zipFile = NULL; + file->position = 0; + errorOk(); +} \ No newline at end of file diff --git a/src/dusk/asset/assetfile.h b/src/dusk/asset/assetfile.h new file mode 100644 index 0000000..e97f5e7 --- /dev/null +++ b/src/dusk/asset/assetfile.h @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "error/error.h" +#include + +typedef struct assetfile_s assetfile_t; + +typedef errorret_t (*assetfileloader_t)(assetfile_t *file); + +typedef struct assetfile_s { + const char_t *filename; + void *params; + void *output; + + zip_stat_t stat; + zip_int64_t size; + zip_int64_t position; + zip_int64_t lastRead; + zip_file_t *zipFile; +} assetfile_t; + +/** + * Opens the asset file for reading. After opening the loader is responsible + * for closing the file. + * + * @param file The asset file to open. + * @return An error code if the file could not be opened. + */ +errorret_t assetFileOpen(assetfile_t *file); + +/** + * Read bytes from the asset file. Assumes the file has already been opened + * prior to trying to read anything. + * + * @param file File to read from. + * @param buffer Buffer to read the file data into., or NULL to skip bytes. + * @param size Size of the buffer to read into. + */ +errorret_t assetFileRead( + assetfile_t *file, + void *buffer, + const size_t bufferSize +); + +/** + * Closes the asset file and releases any resources associated with it. + * + * @param file The asset file to close. + * @return An error code if the file could not be closed properly. + */ +errorret_t assetFileClose(assetfile_t *file); \ No newline at end of file diff --git a/src/dusk/asset/assettype.h b/src/dusk/asset/assettype.h deleted file mode 100644 index f5dfa36..0000000 --- a/src/dusk/asset/assettype.h +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright (c) 2025 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#pragma once -#include "type/assettexture.h" -// #include "type/assetpalette.h" -#include "type/assettileset.h" -#include "type/assetlanguage.h" -#include "type/assetscript.h" -#include "type/assetmap.h" -#include "type/assetmapchunk.h" -#include - -typedef enum { - ASSET_TYPE_NULL, - - ASSET_TYPE_TEXTURE, - ASSET_TYPE_TILESET, - ASSET_TYPE_LANGUAGE, - ASSET_TYPE_SCRIPT, - - ASSET_TYPE_COUNT, -} assettype_t; - -typedef enum { - ASSET_LOAD_STRAT_ENTIRE, - ASSET_LOAD_STRAT_CUSTOM -} assetloadstrat_t; - -typedef struct assetentire_s { - void *data; - void *output; -} assetentire_t; - -typedef struct assetcustom_s { - zip_file_t *zipFile; - void *output; -} assetcustom_t; - -typedef struct { - const char_t *extension; - const size_t dataSize; - const assetloadstrat_t loadStrategy; - union { - errorret_t (*entire)(assetentire_t entire); - errorret_t (*custom)(assetcustom_t custom); - }; -} assettypedef_t; - -static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = { - [ASSET_TYPE_NULL] = { - 0 - }, - - [ASSET_TYPE_TEXTURE] = { - .extension = "DTX", - .loadStrategy = ASSET_LOAD_STRAT_ENTIRE, - .dataSize = sizeof(assettexture_t), - .entire = assetTextureLoad - }, - - [ASSET_TYPE_TILESET] = { - .extension = "DTF", - .loadStrategy = ASSET_LOAD_STRAT_ENTIRE, - .dataSize = sizeof(assettileset_t), - .entire = assetTilesetLoad - }, - - [ASSET_TYPE_LANGUAGE] = { - .extension = "DLF", - .loadStrategy = ASSET_LOAD_STRAT_CUSTOM, - .custom = assetLanguageHandler - }, - - [ASSET_TYPE_SCRIPT] = { - .extension = "lua", - .loadStrategy = ASSET_LOAD_STRAT_CUSTOM, - .custom = assetScriptHandler - }, -}; \ No newline at end of file diff --git a/src/dusk/asset/loader/CMakeLists.txt b/src/dusk/asset/loader/CMakeLists.txt new file mode 100644 index 0000000..c567af9 --- /dev/null +++ b/src/dusk/asset/loader/CMakeLists.txt @@ -0,0 +1,12 @@ +# Copyright (c) 2026 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources + +# Subdirs +add_subdirectory(display) +add_subdirectory(locale) +add_subdirectory(script) +add_subdirectory(json) \ No newline at end of file diff --git a/src/dusk/asset/loader/display/CMakeLists.txt b/src/dusk/asset/loader/display/CMakeLists.txt new file mode 100644 index 0000000..562a129 --- /dev/null +++ b/src/dusk/asset/loader/display/CMakeLists.txt @@ -0,0 +1,11 @@ +# Copyright (c) 2026 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DUSK_LIBRARY_TARGET_NAME} + PUBLIC + assettextureloader.c + assettilesetloader.c +) \ No newline at end of file diff --git a/src/dusk/asset/loader/display/assettextureloader.c b/src/dusk/asset/loader/display/assettextureloader.c new file mode 100644 index 0000000..ca35f4c --- /dev/null +++ b/src/dusk/asset/loader/display/assettextureloader.c @@ -0,0 +1,115 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "assettextureloader.h" +#include "assert/assert.h" +#define STB_IMAGE_IMPLEMENTATION +#include "stb_image.h" +#include "log/log.h" +#include "util/endian.h" + +stbi_io_callbacks ASSET_TEXTURE_STB_CALLBACKS = { + .read = assetTextureReader, + .skip = assetTextureSkipper, + .eof = assetTextureEOF +}; + +int assetTextureReader(void *user, char *data, int size) { + assertNotNull(data, "Data buffer for stb_image callbacks cannot be NULL."); + + assetfile_t *file = (assetfile_t*)user; + assertNotNull(file, "Asset file in stb_image callbacks cannot be NULL."); + + errorret_t ret = assetFileRead(file, data, (size_t)size); + if(ret.code != ERROR_OK) { + errorCatch(errorPrint(ret)); + return -1; + } + + return file->lastRead; +} + +void assetTextureSkipper(void *user, int n) { + assetfile_t *file = (assetfile_t*)user; + assertNotNull(file, "Asset file in stb_image callbacks cannot be NULL."); + + errorret_t ret = assetFileRead(file, NULL, (size_t)n); + if(ret.code != ERROR_OK) { + errorCatch(errorPrint(ret)); + } +} + +int assetTextureEOF(void *user) { + assetfile_t *file = (assetfile_t*)user; + assertNotNull(file, "Asset file in stb_image callbacks cannot be NULL."); + + return file->position >= file->size; +} + +errorret_t assetTextureLoader(assetfile_t *file) { + assertNotNull(file, "Asset file cannot be NULL."); + assertNotNull(file->params, "Asset file parameters cannot be NULL."); + assertNotNull(file->output, "Asset file output cannot be NULL."); + + assettextureloaderparams_t *p = (assettextureloaderparams_t*)file->params; + assertNotNull(p, "Asset texture loader parameters cannot be NULL."); + + int channelsDesired; + switch(p->format) { + case TEXTURE_FORMAT_RGBA: + channelsDesired = 4; + break; + + default: + errorThrow("Bad texture format."); + } + + int width, height, channels; + errorChain(assetFileOpen(file)); + uint8_t *data = stbi_load_from_callbacks( + &ASSET_TEXTURE_STB_CALLBACKS, + file, + &width, + &height, + &channels, + channelsDesired + ); + errorChain(assetFileClose(file)); + + if(data == NULL) { + const char_t *errorStr = stbi_failure_reason(); + errorThrow("Failed to load texture from file %s.", errorStr); + } + + // Fixes a specific bug probably with Dolphin but for now just assuming endian + if(!isHostLittleEndian()) { + stbi__vertical_flip(data, width, height, channelsDesired); + } + + errorChain(textureInit( + (texture_t*)file->output, + (int32_t)width, (int32_t)height, + p->format, + (texturedata_t){ + .rgbaColors = (color_t*)data + } + )); + + stbi_image_free(data); + errorOk(); +} + +errorret_t assetTextureLoad( + const char_t *path, + texture_t *out, + const textureformat_t format +) { + assettextureloaderparams_t params = { + .format = format + }; + return assetLoad(path, assetTextureLoader, ¶ms, out); +} \ No newline at end of file diff --git a/src/dusk/asset/loader/display/assettextureloader.h b/src/dusk/asset/loader/display/assettextureloader.h new file mode 100644 index 0000000..e98b5df --- /dev/null +++ b/src/dusk/asset/loader/display/assettextureloader.h @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "asset/asset.h" +#include "display/texture/texture.h" + +typedef struct { + textureformat_t format; +} assettextureloaderparams_t; + +/** + * STB image read callback for asset files. + * + * @param user User data passed to the callback, should be an assetfile_t*. + * @param data Buffer to read the file data into. + * @param size Size of the buffer to read into. + * @return Number of bytes read, or -1 on error. + */ +int assetTextureReader(void *user, char *data, int size); + +void assetTextureSkipper(void *user, int n); + +int assetTextureEOF(void *user); + +/** + * Handler for texture assets. + * + * @param file Asset file to load the texture from. + * @return Any error that occurs during loading. + */ +errorret_t assetTextureLoader(assetfile_t *file); + +/** + * Loads a texture from the specified path. + * + * @param path Path to the texture asset. + * @param out Output texture to load into. + * @param format Format of the texture to load. + * @return Any error that occurs during loading. + */ +errorret_t assetTextureLoad( + const char_t *path, + texture_t *out, + const textureformat_t format +); \ No newline at end of file diff --git a/src/dusk/asset/loader/display/assettilesetloader.c b/src/dusk/asset/loader/display/assettilesetloader.c new file mode 100644 index 0000000..25aca58 --- /dev/null +++ b/src/dusk/asset/loader/display/assettilesetloader.c @@ -0,0 +1,80 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "assettilesetloader.h" +#include "assert/assert.h" +#include "util/memory.h" +#include "util/endian.h" + +errorret_t assetTilesetLoader(assetfile_t *file) { + assertNotNull(file, "Asset file pointer for tileset loader is null."); + + tileset_t *out = (tileset_t *)file->output; + assertNotNull(out, "Output pointer for tileset loader is null."); + + uint8_t *entire = memoryAllocate(file->size); + errorChain(assetFileOpen(file)); + errorChain(assetFileRead(file, entire, file->size)); + errorChain(assetFileClose(file)); + assertTrue(file->lastRead == file->size, "Failed to read entire file."); + + + if( + entire[0] != 'D' || + entire[1] != 'T' || + entire[2] != 'F' + ) { + errorThrow("Invalid tileset header"); + } + + if(entire[3] != 0x00) { + errorThrow("Unsupported tileset version"); + } + + // Fix endianness + + out->tileWidth = endianLittleToHost16(*(uint16_t *)(entire + 4)); + out->tileHeight = endianLittleToHost16(*(uint16_t *)(entire + 6)); + out->columns = endianLittleToHost16(*(uint16_t *)(entire + 8)); + out->rows = endianLittleToHost16(*(uint16_t *)(entire + 10)); + // out->right = endianLittleToHost16(*(uint16_t *)(entire + 12)); + // out->bottom = endianLittleToHost16(*(uint16_t *)(entire + 14)); + + if(out->tileWidth == 0) { + errorThrow("Tile width cannot be 0"); + } + if(out->tileHeight == 0) { + errorThrow("Tile height cannot be 0"); + } + if(out->columns == 0) { + errorThrow("Column count cannot be 0"); + } + if(out->rows == 0) { + errorThrow("Row count cannot be 0"); + } + + out->uv[0] = endianLittleToHostFloat(*(float *)(entire + 16)); + out->uv[1] = endianLittleToHostFloat(*(float *)(entire + 20)); + + if(out->uv[1] < 0.0f || out->uv[1] > 1.0f) { + errorThrow("Invalid v0 value in tileset"); + } + + // Setup tileset + out->tileCount = out->columns * out->rows; + + memoryFree(entire); + + errorOk(); +} + +errorret_t assetTilesetLoad( + const char_t *path, + tileset_t *out +) { + return assetLoad(path, assetTilesetLoader, NULL, out); +} \ No newline at end of file diff --git a/src/dusk/asset/loader/display/assettilesetloader.h b/src/dusk/asset/loader/display/assettilesetloader.h new file mode 100644 index 0000000..cee5229 --- /dev/null +++ b/src/dusk/asset/loader/display/assettilesetloader.h @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "asset/asset.h" +#include "display/texture/tileset.h" + +/** + * Handler for tileset assets. + * + * @param file Asset file to load the tileset from. + * @return Any error that occurs during loading. + */ +errorret_t assetTilesetLoader(assetfile_t *file); + +/** + * Loads a tileset from the specified path. + * + * @param path Path to the tileset asset. + * @param out Output tileset to load into. + * @return Any error that occurs during loading. + */ +errorret_t assetTilesetLoad( + const char_t *path, + tileset_t *out +); \ No newline at end of file diff --git a/src/dusk/asset/loader/json/CMakeLists.txt b/src/dusk/asset/loader/json/CMakeLists.txt new file mode 100644 index 0000000..7215ecb --- /dev/null +++ b/src/dusk/asset/loader/json/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2026 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DUSK_LIBRARY_TARGET_NAME} + PUBLIC + assetjsonloader.c +) \ No newline at end of file diff --git a/src/dusk/asset/loader/json/assetjsonloader.c b/src/dusk/asset/loader/json/assetjsonloader.c new file mode 100644 index 0000000..0b88da6 --- /dev/null +++ b/src/dusk/asset/loader/json/assetjsonloader.c @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "assetjsonloader.h" +#include "util/memory.h" +#include "assert/assert.h" + +errorret_t assetJsonLoadFileToDoc(assetfile_t *file, yyjson_doc **outDoc) { + assertNotNull(file, "Asset file pointer for JSON loader is null."); + assertNotNull(outDoc, "Output pointer for JSON loader is null."); + + if(file->size > ASSET_JSON_FILE_SIZE_MAX) { + errorThrow("JSON exceeds maximum allowed size"); + } + + // Create buffer + uint8_t *buffer = memoryAllocate(file->size); + + errorChain(assetFileOpen(file)); + + // Read entire file + errorChain(assetFileRead(file, buffer, file->size)); + assertTrue(file->lastRead == file->size, "Failed to read entire JSON file."); + + errorChain(assetFileClose(file)); + + *outDoc = yyjson_read( + buffer, + file->size, + YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS + ); + memoryFree(buffer); + + if(!*outDoc) errorThrow("Failed to parse JSON"); + errorOk(); +} + +errorret_t assetJsonLoader(assetfile_t *file) { + yyjson_doc **outDoc = (yyjson_doc **)file->output; + assertNotNull(outDoc, "Output pointer for JSON loader is null."); + return assetJsonLoadFileToDoc(file, outDoc); +} + +errorret_t assetJsonLoad( + const char_t *path, + yyjson_doc **outDoc +) { + return assetLoad(path, assetJsonLoader, NULL, outDoc); +} \ No newline at end of file diff --git a/src/dusk/asset/loader/json/assetjsonloader.h b/src/dusk/asset/loader/json/assetjsonloader.h new file mode 100644 index 0000000..ed49414 --- /dev/null +++ b/src/dusk/asset/loader/json/assetjsonloader.h @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "asset/asset.h" +#include "yyjson.h" + +#define ASSET_JSON_FILE_SIZE_MAX 1024*256 + +typedef struct { + void *nothing; +} assetjsonloaderparams_t; + +/** + * Loads a JSON document from the specified asset file. + * + * @param file Asset file to load the JSON document from. + * @param outDoc Pointer to store the loaded JSON document. + * @return Any error that occurs during loading. + */ +errorret_t assetJsonLoadFileToDoc(assetfile_t *file, yyjson_doc **outDoc); + +/** + * Handler for locale assets. + * + * @param file Asset file to load the locale from. + * @return Any error that occurs during loading. + */ +errorret_t assetJsonLoader(assetfile_t *file); + +/** + * Loads a locale from the specified path. + * + * @param path Path to the locale asset. + * @param outDoc Pointer to store the loaded JSON document. + * @return Any error that occurs during loading. + */ +errorret_t assetJsonLoad( + const char_t *path, + yyjson_doc **outDoc +); \ No newline at end of file diff --git a/src/dusk/asset/loader/locale/CMakeLists.txt b/src/dusk/asset/loader/locale/CMakeLists.txt new file mode 100644 index 0000000..256a514 --- /dev/null +++ b/src/dusk/asset/loader/locale/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2026 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DUSK_LIBRARY_TARGET_NAME} + PUBLIC + assetlocaleloader.c +) \ No newline at end of file diff --git a/src/dusk/asset/loader/locale/assetlocaleloader.c b/src/dusk/asset/loader/locale/assetlocaleloader.c new file mode 100644 index 0000000..815634c --- /dev/null +++ b/src/dusk/asset/loader/locale/assetlocaleloader.c @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "assetlocaleloader.h" + +errorret_t assetLocaleLoader(assetfile_t *file) { + errorThrow("Locale asset loading is not yet implemented."); +} + +errorret_t assetLocaleLoad( + const char_t *path, + void *nothing +) { + errorThrow("Locale asset loading is not yet implemented."); +} \ No newline at end of file diff --git a/src/dusk/asset/loader/locale/assetlocaleloader.h b/src/dusk/asset/loader/locale/assetlocaleloader.h new file mode 100644 index 0000000..880f4e4 --- /dev/null +++ b/src/dusk/asset/loader/locale/assetlocaleloader.h @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "asset/asset.h" +#include "locale/localemanager.h" + +typedef struct { + void *nothing; +} assetlocaleloaderparams_t; + +/** + * Handler for locale assets. + * + * @param file Asset file to load the locale from. + * @return Any error that occurs during loading. + */ +errorret_t assetLocaleLoader(assetfile_t *file); + +/** + * Loads a locale from the specified path. + * + * @param path Path to the locale asset. + * @param nothing Nothing yet. + * @return Any error that occurs during loading. + */ +errorret_t assetLocaleLoad( + const char_t *path, + void *nothing +); \ No newline at end of file diff --git a/src/dusk/asset/loader/script/CMakeLists.txt b/src/dusk/asset/loader/script/CMakeLists.txt new file mode 100644 index 0000000..64d200b --- /dev/null +++ b/src/dusk/asset/loader/script/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2026 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DUSK_LIBRARY_TARGET_NAME} + PUBLIC + assetscriptloader.c +) \ No newline at end of file diff --git a/src/dusk/asset/loader/script/assetscriptloader.c b/src/dusk/asset/loader/script/assetscriptloader.c new file mode 100644 index 0000000..ba99edd --- /dev/null +++ b/src/dusk/asset/loader/script/assetscriptloader.c @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "assetscriptloader.h" +#include "assert/assert.h" + +errorret_t assetScriptLoader(assetfile_t *file) { + assertNotNull(file, "Asset file cannot be NULL"); + assertNull(file->zipFile, "Asset file zip handle must be NULL"); + assertNotNull(file->output, "Asset file output cannot be NULL"); + + assetscript_t *script = (assetscript_t *)file->output; + + // Open the asset for buffering + errorChain(assetFileOpen(file)); + + // Request loading + if(!lua_load( + script->ctx->luaState, + assetScriptReader, + file, + file->filename, + NULL + ) == LUA_OK) { + const char_t *strErr = lua_tostring(script->ctx->luaState, -1); + lua_pop(script->ctx->luaState, 1); + errorThrow("Failed to load Lua script: %s", strErr); + } + + // Now loaded, exec + if(lua_pcall(script->ctx->luaState, 0, LUA_MULTRET, 0) != LUA_OK) { + const char_t *strErr = lua_tostring(script->ctx->luaState, -1); + lua_pop(script->ctx->luaState, 1); + errorThrow("Failed to execute Lua script: %s", strErr); + } + + // Close the file + return assetFileClose(file); +} + +errorret_t assetScriptLoad(const char_t *path, scriptcontext_t *ctx) { + assertNotNull(path, "Script path cannot be NULL"); + assertNotNull(ctx, "Script context cannot be NULL"); + + assetscript_t script; + script.ctx = ctx; + + return assetLoad( + path, + assetScriptLoader, + NULL, + &script + ); +} + +const char_t * assetScriptReader(lua_State* L, void* data, size_t* size) { + assetfile_t *file = (assetfile_t*)data; + assertNotNull(file, "Script asset file cannot be NULL"); + assertNotNull(file->zipFile, "Script asset zip handle cannot be NULL"); + assertNotNull(file->output, "Script asset output cannot be NULL"); + + assetscript_t *script = (assetscript_t *)file->output; + assertNotNull(script, "Script asset output cannot be NULL"); + + zip_int64_t read = zip_fread( + file->zipFile, + script->buffer, + sizeof(script->buffer) + ); + + if(read < 0) { + *size = 0; + return NULL; + } + + *size = (size_t)read; + return script->buffer; +} \ No newline at end of file diff --git a/src/dusk/asset/loader/script/assetscriptloader.h b/src/dusk/asset/loader/script/assetscriptloader.h new file mode 100644 index 0000000..847f4f1 --- /dev/null +++ b/src/dusk/asset/loader/script/assetscriptloader.h @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "asset/asset.h" +#include "script/scriptcontext.h" + +#define ASSET_SCRIPT_BUFFER_SIZE 1024 + +typedef struct { + void *nothing; +} assetscriptloaderparams_t; + +typedef struct { + scriptcontext_t *ctx; + char_t buffer[ASSET_SCRIPT_BUFFER_SIZE]; +} assetscript_t; + +/** + * Handler for script assets. + * + * @param file Asset file to load the script from. + * @return Any error that occurs during loading. + */ +errorret_t assetScriptLoader(assetfile_t *file); + +/** + * Loads a script from the specified path. + * + * @param path Path to the script asset. + * @param ctx Script context to load the script into. + * @return Any error that occurs during loading. + */ +errorret_t assetScriptLoad(const char_t *path, scriptcontext_t *ctx); + +/** + * Reader function for Lua to read script data from the asset. + * + * @param L Lua state. + * @param data Pointer to the scriptcontext_t structure. + * @param size Pointer to store the size of the read data. + * @return Pointer to the read data buffer. + */ +const char_t * assetScriptReader(lua_State* L, void* data, size_t* size); \ No newline at end of file diff --git a/src/dusk/asset/type/assetmap.c b/src/dusk/asset/type/assetmap.c deleted file mode 100644 index 03460cf..0000000 --- a/src/dusk/asset/type/assetmap.c +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Copyright (c) 2025 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#include "asset/asset.h" -#include "assert/assert.h" -#include "util/memory.h" - -errorret_t assetMapHandler(assetcustom_t custom) { - printf("Map Loaded from asset!\n"); - errorOk(); -} \ No newline at end of file diff --git a/src/dusk/asset/type/assetmap.h b/src/dusk/asset/type/assetmap.h deleted file mode 100644 index 772c32d..0000000 --- a/src/dusk/asset/type/assetmap.h +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (c) 2025 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#pragma once -#include "error/error.h" - -typedef struct assetcustom_s assetcustom_t; - -/** - * Loads a map asset from the given data pointer into the output map structure. - * - * @param data Pointer to the raw assetmap_t data. - * @param output Pointer to the map_t to load the map into. - * @return An error code. - */ -errorret_t assetMapHandler(assetcustom_t custom); \ No newline at end of file diff --git a/src/dusk/asset/type/assetmapchunk.c b/src/dusk/asset/type/assetmapchunk.c deleted file mode 100644 index dbab6b5..0000000 --- a/src/dusk/asset/type/assetmapchunk.c +++ /dev/null @@ -1,185 +0,0 @@ -/** - * Copyright (c) 2025 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#include "asset/asset.h" -#include "assert/assert.h" -#include "map/mapchunk.h" -#include "util/endian.h" - -#pragma pack(push, 1) -typedef struct { - uint32_t tileCount; - uint8_t modelCount; - uint8_t entityCount; -} assetchunkheader_t; -#pragma pack(pop) - -#pragma pack(push, 1) -typedef struct { - maptile_t tile; -} assetchunktiledata_t; -#pragma pack(pop) - -#pragma pack(push, 1) -typedef struct { - uint32_t vertexCount; -} assetchunkmodelheader_t; -#pragma pack(pop) - -#pragma pack(push, 1) -typedef struct { - uint8_t entityType; - uint8_t localX; - uint8_t localY; - uint8_t localZ; -} assetchunkentityheader_t; -#pragma pack(pop) - -errorret_t assetMapChunkHandler(assetcustom_t custom) { - assertNotNull(custom.output, "Output pointer cannot be NULL"); - assertNotNull(custom.zipFile, "Zip file pointer cannot be NULL"); - - mapchunk_t *chunk = (mapchunk_t *)custom.output; - assertTrue(chunk->meshCount == 0, "Chunk is not in a good state"); - - // Read header - assetchunkheader_t header; - size_t bytesRead = zip_fread( - custom.zipFile, &header, sizeof(assetchunkheader_t) - ); - if(bytesRead != sizeof(assetchunkheader_t)) { - zip_fclose(custom.zipFile); - errorThrow("Failed to read chunk asset header."); - } - - // Fix endianess if necessary - header.tileCount = endianLittleToHost32(header.tileCount); - - if(header.tileCount != CHUNK_TILE_COUNT) { - zip_fclose(custom.zipFile); - errorThrow( - "Chunk asset has invalid tile count: %d (expected %d).", - header.tileCount, - CHUNK_TILE_COUNT - ); - } - - if(header.modelCount > CHUNK_MESH_COUNT_MAX) { - zip_fclose(custom.zipFile); - errorThrow( - "Chunk asset has too many models: %d (max %d).", - header.modelCount, - CHUNK_MESH_COUNT_MAX - ); - } - - if(header.entityCount > CHUNK_ENTITY_COUNT_MAX) { - zip_fclose(custom.zipFile); - errorThrow( - "Chunk asset has too many entities: %d (max %d).", - header.entityCount, - CHUNK_ENTITY_COUNT_MAX - ); - } - - chunk->meshCount = header.modelCount; - - // Read tile data - bytesRead = zip_fread( - custom.zipFile, - chunk->tiles, - sizeof(assetchunktiledata_t) * header.tileCount - ); - if(bytesRead != sizeof(assetchunktiledata_t) * header.tileCount) { - zip_fclose(custom.zipFile); - errorThrow("Failed to read chunk tile data."); - } - - // For each model... - uint32_t vertexIndex = 0; - for(uint8_t i = 0; i < header.modelCount; i++) { - assetchunkmodelheader_t modelHeader; - bytesRead = zip_fread( - custom.zipFile, &modelHeader, sizeof(assetchunkmodelheader_t) - ); - if(bytesRead != sizeof(assetchunkmodelheader_t)) { - zip_fclose(custom.zipFile); - errorThrow("Failed to read chunk model header."); - } - - // Fix endianess if necessary - modelHeader.vertexCount = endianLittleToHost32(modelHeader.vertexCount); - - if( - vertexIndex + modelHeader.vertexCount > - CHUNK_VERTEX_COUNT_MAX - ) { - zip_fclose(custom.zipFile); - errorThrow("Chunk model vertex count exceeds maximum."); - } - - // Read vertex data. - bytesRead = zip_fread( - custom.zipFile, - &chunk->vertices[vertexIndex], - sizeof(meshvertex_t) * modelHeader.vertexCount - ); - if(bytesRead != sizeof(meshvertex_t) * modelHeader.vertexCount) { - zip_fclose(custom.zipFile); - errorThrow("Failed to read chunk model vertex data."); - } - - // Init the mesh - if(modelHeader.vertexCount > 0) { - mesh_t *mesh = &chunk->meshes[i]; - meshInit( - mesh, - MESH_PRIMITIVE_TYPE_TRIANGLES, - modelHeader.vertexCount, - &chunk->vertices[vertexIndex] - ); - - vertexIndex += modelHeader.vertexCount; - } else { - // chunk->meshes[i].vertexCount = 0; - } - } - - // Read entity data - // for(uint8_t i = 0; i < header.entityCount; i++) { - // assetchunkentityheader_t entityHeader; - // bytesRead = zip_fread( - // custom.zipFile, &entityHeader, sizeof(assetchunkentityheader_t) - // ); - // if(bytesRead != sizeof(assetchunkentityheader_t)) { - // zip_fclose(custom.zipFile); - // errorThrow("Failed to read chunk entity header."); - // } - - // uint8_t entityIndex = entityGetAvailable(); - // if(entityIndex == 0xFF) { - // zip_fclose(custom.zipFile); - // errorThrow("No available entity slots."); - // } - - // entity_t *entity = &ENTITIES[entityIndex]; - // entityInit(entity, (entitytype_t)entityHeader.entityType); - // entity->position.x = ( - // (chunk->position.x * CHUNK_WIDTH) + entityHeader.localX - // ); - // entity->position.y = ( - // (chunk->position.y * CHUNK_HEIGHT) + entityHeader.localY - // ); - // entity->position.z = ( - // (chunk->position.z * CHUNK_DEPTH) + entityHeader.localZ - // ); - - // chunk->entities[i] = entityIndex; - // } - - errorOk(); -} \ No newline at end of file diff --git a/src/dusk/asset/type/assetmapchunk.h b/src/dusk/asset/type/assetmapchunk.h deleted file mode 100644 index f80e47b..0000000 --- a/src/dusk/asset/type/assetmapchunk.h +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2025 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#pragma once -#include "error/error.h" - -typedef struct assetcustom_s assetcustom_t; - -/** - * Handles loading of map chunk data from a map chunk asset file. - * - * @param custom The custom asset loading parameters. - * @return An error code. - */ -errorret_t assetMapChunkHandler(assetcustom_t custom); \ No newline at end of file diff --git a/src/dusk/display/camera/camera.c b/src/dusk/display/camera/camera.c index a569284..94379fa 100644 --- a/src/dusk/display/camera/camera.c +++ b/src/dusk/display/camera/camera.c @@ -35,8 +35,8 @@ void cameraInitOrthographic(camera_t *camera) { camera->projType = CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC; camera->orthographic.left = 0.0f; camera->orthographic.right = SCREEN.width; - camera->orthographic.top = 0.0f; - camera->orthographic.bottom = SCREEN.height; + camera->orthographic.top = SCREEN.height; + camera->orthographic.bottom = 0.0f; camera->nearClip = 0.1f; camera->farClip = 1.0f; diff --git a/src/dusk/display/text/text.c b/src/dusk/display/text/text.c index f951365..73eb5a6 100644 --- a/src/dusk/display/text/text.c +++ b/src/dusk/display/text/text.c @@ -9,16 +9,18 @@ #include "assert/assert.h" #include "util/memory.h" #include "display/spritebatch/spritebatch.h" -#include "asset/asset.h" - +#include "asset/loader/display/assettextureloader.h" +#include "asset/loader/display/assettilesetloader.h" #include "display/shader/shaderunlit.h" texture_t DEFAULT_FONT_TEXTURE; tileset_t DEFAULT_FONT_TILESET; errorret_t textInit(void) { - errorChain(assetLoad("ui/minogram.dtx", &DEFAULT_FONT_TEXTURE)); - errorChain(assetLoad("ui/minogram.dtf", &DEFAULT_FONT_TILESET)); + errorChain(assetTextureLoad( + "ui/minogram.png", &DEFAULT_FONT_TEXTURE, TEXTURE_FORMAT_RGBA + )); + errorChain(assetTilesetLoad("ui/minogram.dtf", &DEFAULT_FONT_TILESET)); errorOk(); } @@ -75,6 +77,15 @@ errorret_t textDraw( errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, texture)); + // errorChain(spriteBatchPush( + // // texture, + // posX, posY, + // posX + texture->width * 1, posY + texture->height * 1, + // color, + // 0.0f, 0.0f, 1.0f, 1.0f + // )); + // errorOk(); + char_t c; int32_t i = 0; while((c = text[i++]) != '\0') { diff --git a/src/dusk/engine/engine.c b/src/dusk/engine/engine.c index 83ee8c3..4a3d385 100644 --- a/src/dusk/engine/engine.c +++ b/src/dusk/engine/engine.c @@ -14,10 +14,11 @@ #include "scene/scene.h" #include "asset/asset.h" #include "ui/ui.h" -#include "map/map.h" #include "script/scriptmanager.h" -#include "item/backpack.h" #include "assert/assert.h" +#include "game/game.h" + +#include "asset/loader/json/assetjsonloader.h" engine_t ENGINE; @@ -35,9 +36,22 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) { errorChain(scriptManagerInit()); errorChain(displayInit()); errorChain(uiInit()); - errorChain(mapInit()); errorChain(sceneInit()); - backpackInit(); + errorChain(gameInit()); + + // JSON test. + yyjson_doc *doc; + assetJsonLoad("test.json", &doc); + + yyjson_val *root = yyjson_doc_get_root(doc); + assertTrue(root, "JSON root is null."); + + yyjson_val *name = yyjson_obj_get(root, "name"); + assertTrue(name && yyjson_is_str(name), "JSON 'name' field is missing or not a string."); + const char *nameStr = yyjson_get_str(name); + printf("Name: %s\n", nameStr); + + yyjson_doc_free(doc); // Run the initial script. scriptcontext_t ctx; @@ -54,7 +68,7 @@ errorret_t engineUpdate(void) { uiUpdate(); errorChain(sceneUpdate()); - mapUpdate(); + errorChain(gameUpdate()); errorChain(displayUpdate()); if(inputPressed(INPUT_ACTION_RAGEQUIT)) ENGINE.running = false; @@ -68,7 +82,7 @@ void engineExit(void) { errorret_t engineDispose(void) { sceneDispose(); - mapDispose(); + errorChain(gameDispose()); localeManagerDispose(); uiDispose(); errorChain(displayDispose()); diff --git a/src/dusk/locale/localemanager.c b/src/dusk/locale/localemanager.c index 82ae301..e03487e 100644 --- a/src/dusk/locale/localemanager.c +++ b/src/dusk/locale/localemanager.c @@ -7,8 +7,6 @@ #include "localemanager.h" #include "util/memory.h" -#include "asset/asset.h" -#include "assert/assert.h" localemanager_t LOCALE; @@ -34,5 +32,4 @@ errorret_t localeManagerSetLocale(const dusklocale_t locale) { } void localeManagerDispose() { - assetLanguageDispose(&LOCALE.language); } \ No newline at end of file diff --git a/src/dusk/locale/localemanager.h b/src/dusk/locale/localemanager.h index 8dbc4f7..f60343d 100644 --- a/src/dusk/locale/localemanager.h +++ b/src/dusk/locale/localemanager.h @@ -6,13 +6,13 @@ */ #pragma once -#include "asset/asset.h" +#include "error/error.h" #include "localemanager.h" #include "locale/locale.h" typedef struct { dusklocale_t locale; - assetlanguage_t language; + // assetlanguage_t language; } localemanager_t; extern localemanager_t LOCALE; diff --git a/src/dusk/script/module/display/moduletexture.c b/src/dusk/script/module/display/moduletexture.c index 1c1732b..197886d 100644 --- a/src/dusk/script/module/display/moduletexture.c +++ b/src/dusk/script/module/display/moduletexture.c @@ -6,9 +6,9 @@ */ #include "moduletexture.h" -#include "asset/asset.h" -#include "display/texture/texture.h" #include "assert/assert.h" +#include "display/texture/texture.h" +#include "asset/loader/display/assettextureloader.h" #include "util/memory.h" #include "util/string.h" @@ -83,6 +83,11 @@ int moduleTextureLoad(lua_State *l) { luaL_error(l, "First argument must be a string filename."); return 0; } + + if(!lua_isnumber(l, 2)) { + luaL_error(l, "Second argument must be a number format."); + return 0; + } const char_t *filename = lua_tostring(l, 1); assertNotNull(filename, "Filename cannot be NULL."); @@ -92,7 +97,9 @@ int moduleTextureLoad(lua_State *l) { texture_t *tex = (texture_t *)lua_newuserdata(l, sizeof(texture_t)); memoryZero(tex, sizeof(texture_t)); - errorret_t ret = assetLoad(filename, tex); + textureformat_t format = (textureformat_t)lua_tonumber(l, 2); + + errorret_t ret = assetTextureLoad(filename, tex, format); if(ret.code != ERROR_OK) { errorCatch(errorPrint(ret)); luaL_error(l, "Failed to load texture asset: %s", filename); diff --git a/src/dusk/script/scriptcontext.c b/src/dusk/script/scriptcontext.c index 978aedd..b429f0f 100644 --- a/src/dusk/script/scriptcontext.c +++ b/src/dusk/script/scriptcontext.c @@ -11,6 +11,7 @@ #include "util/memory.h" #include "script/scriptmodule.h" #include "event/event.h" +#include "asset/loader/script/assetscriptloader.h" errorret_t scriptContextInit(scriptcontext_t *context) { assertNotNull(context, "Script context cannot be NULL"); @@ -53,26 +54,7 @@ errorret_t scriptContextExec(scriptcontext_t *context, const char_t *script) { errorret_t scriptContextExecFile(scriptcontext_t *ctx, const char_t *fname) { assertNotNull(ctx, "Script context cannot be NULL"); assertNotNull(fname, "Filename cannot be NULL"); - - assetscript_t script; - errorChain(assetLoad(fname, &script)); - - if(lua_load( - ctx->luaState, assetScriptReader, &script, fname, NULL - ) != LUA_OK) { - const char_t *strErr = lua_tostring(ctx->luaState, -1); - lua_pop(ctx->luaState, 1); - errorThrow("Failed to load Lua script: %s", strErr); - } - - if(lua_pcall(ctx->luaState, 0, LUA_MULTRET, 0) != LUA_OK) { - const char_t *strErr = lua_tostring(ctx->luaState, -1); - lua_pop(ctx->luaState, 1); - errorThrow("Failed to execute Lua script: %s", strErr); - } - - errorChain(assetScriptDispose(&script)); - errorOk(); + return assetScriptLoad(fname, ctx); } void scriptContextDispose(scriptcontext_t *context) { diff --git a/src/dusktrivia/CMakeLists.txt b/src/dusktrivia/CMakeLists.txt new file mode 100644 index 0000000..f0d950a --- /dev/null +++ b/src/dusktrivia/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2026 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Includes +target_include_directories(${DUSK_LIBRARY_TARGET_NAME} + PUBLIC + ${CMAKE_CURRENT_LIST_DIR} +) + +# Subdirs +add_subdirectory(game) +add_subdirectory(script) \ No newline at end of file diff --git a/src/dusktrivia/game/CMakeLists.txt b/src/dusktrivia/game/CMakeLists.txt new file mode 100644 index 0000000..be80fa0 --- /dev/null +++ b/src/dusktrivia/game/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2026 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DUSK_LIBRARY_TARGET_NAME} + PUBLIC + game.c +) \ No newline at end of file diff --git a/src/dusktrivia/game/game.c b/src/dusktrivia/game/game.c new file mode 100644 index 0000000..37222d5 --- /dev/null +++ b/src/dusktrivia/game/game.c @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "game.h" + +errorret_t gameInit(void) { + errorOk(); +} + +errorret_t gameUpdate(void) { + errorOk(); +} + +errorret_t gameDispose(void) { + errorOk(); +} \ No newline at end of file diff --git a/src/dusktrivia/game/game.h b/src/dusktrivia/game/game.h new file mode 100644 index 0000000..45d1c71 --- /dev/null +++ b/src/dusktrivia/game/game.h @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "error/error.h" + +/** + * Initializes the game. + * + * @return An error code indicating success or failure. + */ +errorret_t gameInit(void); + +/** + * Updates the game state. Should be called every frame. + * + * @return An error code indicating success or failure. + */ +errorret_t gameUpdate(void); + +/** + * Disposes of game resources. Should be called when the game is shutting down. + * + * @return An error code indicating success or failure. + */ +errorret_t gameDispose(void); \ No newline at end of file diff --git a/src/dusktrivia/script/CMakeLists.txt b/src/dusktrivia/script/CMakeLists.txt new file mode 100644 index 0000000..26438bb --- /dev/null +++ b/src/dusktrivia/script/CMakeLists.txt @@ -0,0 +1,7 @@ +# Copyright (c) 2026 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Subdirs +add_subdirectory(module) \ No newline at end of file diff --git a/src/dusktrivia/script/module/CMakeLists.txt b/src/dusktrivia/script/module/CMakeLists.txt new file mode 100644 index 0000000..2e6d0d1 --- /dev/null +++ b/src/dusktrivia/script/module/CMakeLists.txt @@ -0,0 +1,6 @@ +# Copyright (c) 2026 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Subdirectories \ No newline at end of file diff --git a/src/dusktrivia/script/scriptgame.h b/src/dusktrivia/script/scriptgame.h new file mode 100644 index 0000000..127e1eb --- /dev/null +++ b/src/dusktrivia/script/scriptgame.h @@ -0,0 +1,8 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once \ No newline at end of file