From 11cf4c78310ac74735ab1c8bb269851c7264a3b7 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Wed, 3 Nov 2021 23:49:38 -0700 Subject: [PATCH] Testing around with asset loading. --- src/file/assetmanager.c | 5 +++ src/file/assetmanager.h | 2 +- src/game/poker/characters/characters.h | 1 + src/game/poker/game.c | 45 ++++++++++++++++---------- src/game/poker/game.h | 1 + src/game/poker/pokergame.h | 7 +++- src/game/poker/pokergameassets.c | 43 ++++++++++++++++-------- src/game/poker/pokergameassets.h | 5 ++- src/game/poker/pokerworld.c | 1 - src/game/sandbox/game.c | 1 - src/scenes/loadingscene.c | 32 ++++++++++++++++++ src/scenes/loadingscene.h | 26 +++++++++++++++ 12 files changed, 133 insertions(+), 36 deletions(-) create mode 100644 src/scenes/loadingscene.c create mode 100644 src/scenes/loadingscene.h diff --git a/src/file/assetmanager.c b/src/file/assetmanager.c index 64ad62da..fb21d39d 100644 --- a/src/file/assetmanager.c +++ b/src/file/assetmanager.c @@ -27,6 +27,7 @@ void assetManagerInit(assetmanager_t *manager) { threadInit(&manager->thread, &_assetManagerThread); manager->thread.user = manager; manager->itemCount = 0; + manager->finished = false; } void assetManagerStart(assetmanager_t *manager) { @@ -90,6 +91,8 @@ int32_t _assetManagerThread(thread_t *thread) { } } + manager->finished = assetManagerProgressGet(manager) >= 1.0f; + return 0; } @@ -123,6 +126,8 @@ void assetManagerUpdate(assetmanager_t *manager) { item->state = ASSET_MANAGER_STATE_SYNC_DONE; } } + + manager->finished = assetManagerProgressGet(manager) >= 1.0f; } assetmanageritem_t * assetManagerItemAdd(assetmanager_t *manager) { diff --git a/src/file/assetmanager.h b/src/file/assetmanager.h index b409794c..9a7c6354 100644 --- a/src/file/assetmanager.h +++ b/src/file/assetmanager.h @@ -75,9 +75,9 @@ typedef struct { // Manager typedef struct { thread_t thread; - assetmanageritem_t items[ASSET_MANAGER_ITEMS_MAX]; uint8_t itemCount; + bool finished; } assetmanager_t; extern assetmanagerloaderdefinition_t ASSET_MANAGER_LOADERS[]; diff --git a/src/game/poker/characters/characters.h b/src/game/poker/characters/characters.h index d0cfc79c..e71e2393 100644 --- a/src/game/poker/characters/characters.h +++ b/src/game/poker/characters/characters.h @@ -23,6 +23,7 @@ typedef struct { pokercharacterinitmethod_t *init; } pokercharacterdefinition_t; +#define POKER_CHARACTER_DEFINITIONS_COUNT 0x05 extern pokercharacterdefinition_t POKER_CHARACTER_DEFINITIONS[]; void pokerCharacterInit(vncharacter_t *crctr, texture_t *txtr, uint8_t i); \ No newline at end of file diff --git a/src/game/poker/game.c b/src/game/poker/game.c index 5a5fa963..b5f8ac0c 100644 --- a/src/game/poker/game.c +++ b/src/game/poker/game.c @@ -8,29 +8,40 @@ #include "game.h" bool pokerGameInit(pokergame_t *game) { - // Load the Assets. + // Begin to load the assets. pokerGameAssetsInit(&game->assets); - - // Initialize the Visual Novel Engine. - vnSceneInit(&game->scene, - &game->assets.font, - &game->assets.testTexture - ); - - // Initialize the world - pokerWorldInit(&game->world, &game->scene, &game->assets); - - // Initialize the UI. - pokerUiInit(&game->ui); - - // Add the first action, the game action, and then start the action queue. - pokerGameActionStartAdd(game); - queueNext(&game->scene.conversation.actionQueue); + loadingSceneInit(&game->loadingScene, &game->assets.manager); + loadingSceneStart(&game->loadingScene); return true; } void pokerGameUpdate(pokergame_t *game) { + bool t; + if(!game->loadingScene.manager->finished) { + t = loadingSceneUpdate(&game->loadingScene); + if(t) { + // Initialize the Visual Novel Engine. + vnSceneInit(&game->scene, + &game->assets.font, + &game->assets.testTexture + ); + + // Initialize the world + pokerWorldInit(&game->world, &game->scene, &game->assets); + + // Initialize the UI. + pokerUiInit(&game->ui); + + // Add the first action, the game action, and then start the action queue. + pokerGameActionStartAdd(game); + queueNext(&game->scene.conversation.actionQueue); + } else { + loadingSceneRender(&game->loadingScene); + return; + } + } + // Update the VN Engine. vnSceneUpdate(&game->scene, &game->engine); diff --git a/src/game/poker/game.h b/src/game/poker/game.h index df0e1c79..a1c9ab26 100644 --- a/src/game/poker/game.h +++ b/src/game/poker/game.h @@ -12,6 +12,7 @@ #include "../../vn/vnscene.h" #include "../../util/array.h" #include "../../engine/thread.h" +#include "../../scenes/loadingscene.h" #include "pokergame.h" #include "pokergameassets.h" #include "pokerui.h" diff --git a/src/game/poker/pokergame.h b/src/game/poker/pokergame.h index e2432c6f..244c8bcf 100644 --- a/src/game/poker/pokergame.h +++ b/src/game/poker/pokergame.h @@ -7,16 +7,21 @@ #pragma once #include "../../libs.h" -#include "pokergameassets.h" #include "../../poker/poker.h" #include "../../vn/conversation/talk.h" #include "../../vn/vnscene.h" #include "../../util/array.h" +#include "../../scenes/loadingscene.h" +#include "pokergameassets.h" #include "pokerui.h" #include "pokerworld.h" #include "pokergameaction.h" typedef struct { + loadingscene_t loadingScene; + + + /** Game Engine Instance */ engine_t engine; diff --git a/src/game/poker/pokergameassets.c b/src/game/poker/pokergameassets.c index 44433846..5e5b96d8 100644 --- a/src/game/poker/pokergameassets.c +++ b/src/game/poker/pokergameassets.c @@ -7,21 +7,38 @@ #include "pokergameassets.h" bool pokerGameAssetsInit(pokergameassets_t *assets) { - // Load the game's shader - assetShaderLoad(&assets->shader, - "shaders/textured.vert", "shaders/textured.frag" - ); - - // Load the game's font - assetFontLoad(&assets->font, "fonts/opensans/OpenSans-Bold.ttf"); + uint8_t i; + assetManagerInit(&assets->manager); // Initialize the language buffer. languageInit(&assets->language, "locale/language/en-US.csv"); + + assetManagerShaderLoad(&assets->manager, &assets->shader, + "shaders/textured.vert", "shaders/textured.frag" + ); + + assetManagerLoadFont(&assets->manager, &assets->font, + "fonts/opensans/OpenSans-Bold.ttf" + ); + // Load the world textures. - assetTextureLoad(&assets->testTexture, "textures/test_texture.png"); - assetTextureLoad(&assets->cardTexture, "poker/cards.png"); - assetTextureLoad(&assets->roomTexture, "poker/pub_skywall.png"); + assetManagerLoadTexture(&assets->manager, &assets->testTexture, + "textures/test_texture.png" + ); + assetManagerLoadTexture(&assets->manager, &assets->cardTexture, + "poker/cards.png" + ); + assetManagerLoadTexture(&assets->manager, &assets->roomTexture, + "poker/pub_skywall.png" + ); + + // Load character textures. + for(i = 0; i < POKER_CHARACTER_DEFINITIONS_COUNT; i++) { + assetManagerLoadTexture(&assets->manager, assets->characterTextures + i, + POKER_CHARACTER_DEFINITIONS[i].fileTexture + ); + } return true; } @@ -30,10 +47,8 @@ void pokerGameAssetsDispose(pokergameassets_t *assets) { // Now we unload in what is essentially the reverse of the above. textureDispose(&assets->roomTexture); textureDispose(&assets->testTexture); - - languageDispose(&assets->language); - + textureDispose(&assets->cardTexture); fontDispose(&assets->font); - shaderDispose(&assets->shader); + languageDispose(&assets->language); } \ No newline at end of file diff --git a/src/game/poker/pokergameassets.h b/src/game/poker/pokergameassets.h index 92c36d76..ebecb596 100644 --- a/src/game/poker/pokergameassets.h +++ b/src/game/poker/pokergameassets.h @@ -8,6 +8,7 @@ #pragma once #include "../../libs.h" #include "../../file/asset.h" +#include "../../file/assetmanager.h" #include "../../locale/language.h" #include "../../display/texture.h" #include "../../vn/vncharacter.h" @@ -15,6 +16,8 @@ #include "characters/characters.h" typedef struct { + assetmanager_t manager; + font_t font; shader_t shader; language_t language; @@ -23,7 +26,7 @@ typedef struct { texture_t roomTexture; texture_t cardTexture; - texture_t characterTextures[POKER_PLAYER_COUNT_MAX]; + texture_t characterTextures[POKER_CHARACTER_DEFINITIONS_COUNT]; } pokergameassets_t; /** diff --git a/src/game/poker/pokerworld.c b/src/game/poker/pokerworld.c index 37b42cdb..c17455a7 100644 --- a/src/game/poker/pokerworld.c +++ b/src/game/poker/pokerworld.c @@ -26,7 +26,6 @@ void pokerWorldInit( for(i = 0x00; i < POKER_PLAYER_COUNT_MAX; i++) { character = scene->characters + scene->characterCount; texture = assets->characterTextures + i; - assetTextureLoad(texture, POKER_CHARACTER_DEFINITIONS[i].fileTexture); pokerCharacterInit(character, texture, i); pokerWorldSitCharacter(character, POKER_WORLD_SEAT_FOR_PLAYER(i)); scene->characterCount++; diff --git a/src/game/sandbox/game.c b/src/game/sandbox/game.c index 00a7261e..01074b9d 100644 --- a/src/game/sandbox/game.c +++ b/src/game/sandbox/game.c @@ -7,7 +7,6 @@ #include "game.h" - bool sandboxGameInit(sandboxgame_t *game) { quadInit(&game->quad, 0, 0,0,0,0, 500,500,1,1); diff --git a/src/scenes/loadingscene.c b/src/scenes/loadingscene.c new file mode 100644 index 00000000..de9d01b3 --- /dev/null +++ b/src/scenes/loadingscene.c @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "loadingscene.h" + +void loadingSceneInit( + loadingscene_t *scene, + assetmanager_t *assetManager +) { + scene->manager = assetManager; +} + +void loadingSceneStart(loadingscene_t *scene) { + assetManagerStart(scene->manager); +} + +bool loadingSceneUpdate(loadingscene_t *scene) { + assetManagerUpdate(scene->manager); + return scene->manager->finished; +} + +void loadingSceneRender(loadingscene_t *scene) { + +} + +void loadingSceneDispose(loadingscene_t *scene) { + +} \ No newline at end of file diff --git a/src/scenes/loadingscene.h b/src/scenes/loadingscene.h new file mode 100644 index 00000000..cecfd613 --- /dev/null +++ b/src/scenes/loadingscene.h @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "../file/assetmanager.h" + +typedef struct { + assetmanager_t *manager; +} loadingscene_t; + +void loadingSceneInit( + loadingscene_t *scene, + assetmanager_t *assetManager +); + +void loadingSceneStart(loadingscene_t *scene); + +bool loadingSceneUpdate(loadingscene_t *scene); + +void loadingSceneRender(loadingscene_t *scene); + +void loadingSceneDispose(loadingscene_t *scene); \ No newline at end of file