Testing around with asset loading.

This commit is contained in:
2021-11-03 23:49:38 -07:00
parent a2c622ddc1
commit 11cf4c7831
12 changed files with 133 additions and 36 deletions

View File

@ -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) {

View File

@ -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[];

View File

@ -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);

View File

@ -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);

View File

@ -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"

View File

@ -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;

View File

@ -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);
}

View File

@ -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;
/**

View File

@ -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++;

View File

@ -7,7 +7,6 @@
#include "game.h"
bool sandboxGameInit(sandboxgame_t *game) {
quadInit(&game->quad, 0, 0,0,0,0, 500,500,1,1);

32
src/scenes/loadingscene.c Normal file
View File

@ -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) {
}

26
src/scenes/loadingscene.h Normal file
View File

@ -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);