Added asset manager into the game engine itself.

This commit is contained in:
2021-11-09 08:14:20 -08:00
parent b86b66dae6
commit 2d05d9e60e
8 changed files with 38 additions and 36 deletions

View File

@ -20,11 +20,16 @@ void engineInit(engine_t *engine) {
epochInit(&engine->time);
renderInit();
inputInit(&engine->input);
assetManagerInit(&engine->assetManager);
assetManagerStart(&engine->assetManager);
}
void engineUpdateStart(engine_t *engine, float delta) {
epochUpdate(&engine->time, delta);
inputUpdate(&engine->input);
assetManagerUpdate(&engine->assetManager);
renderFrameStart(&engine->render);
}
@ -37,6 +42,7 @@ bool engineUpdateEnd(engine_t *engine) {
}
void engineDispose(engine_t *engine) {
assetManagerDispose(&engine->assetManager);
inputDispose(&engine->input);
renderDispose();
}

View File

@ -12,6 +12,7 @@
#include "../input/input.h"
#include "../epoch/epoch.h"
#include "../display/render.h"
#include "../file/assetmanager.h"
// #if !defined(GAME_NAME)
// #error You need to define the GAME_NAME string
@ -27,6 +28,9 @@ typedef struct {
/** Render Manager for the game */
render_t render;
/** Asset Manager for the game */
assetmanager_t assetManager;
/** Input Manager for the game */
input_t input;

View File

@ -101,18 +101,4 @@ int32_t assetBufferSkip(assetbuffer_t *buffer, long n) {
size_t assetBufferGetCurrentPosition(assetbuffer_t *buffer) {
return ftell((FILE *)buffer);
}
void assetScripterAppend(scripter_t *scripter, char *fileName) {
char *data;
data = assetStringLoad(fileName);
duk_push_global_object(scripter->context);
duk_push_lstring(scripter->context, data, strlen(data));
if(duk_peval(scripter->context) != 0) {
printf("Error running: %s\n", duk_safe_to_string(scripter->context, -1));
}
free(data);
}

View File

@ -10,7 +10,6 @@
#include "../display/shader.h"
#include "../display/texture.h"
#include "../display/font.h"
#include "../script/scripter.h"
#if !defined(ASSET_PREFIX)
#error Asset Prefix has not been defined.
@ -88,7 +87,4 @@ int32_t assetBufferSkip(assetbuffer_t *buffer, long n);
* @param buffer Buffer to get the position of.
* @return Position (in bytes) that the current seek is at.
*/
size_t assetBufferGetCurrentPosition(assetbuffer_t *buffer);
/** @deprecated */
void assetScripterAppend(scripter_t *scripter, char *fileName);
size_t assetBufferGetCurrentPosition(assetbuffer_t *buffer);

View File

@ -109,6 +109,22 @@ void assetManagerDisposeReleased(assetmanager_t *man) {
}
}
void assetManagerDispose(assetmanager_t *man) {
uint8_t i;
assetmanagerloader_t *disp;
assetmanageritem_t *item;
for(i = 0; i < man->itemCount; i++) {
item = man->items + i;
disp = ASSET_MANAGER_LOADERS[item->type].dispose;
if(item->holderCount > 0) continue;
if(disp != NULL) disp(item);
}
man->itemCount = 0;
man->holderCount = 0;
}
// Thread Management
void assetManagerStart(assetmanager_t *manager) {
threadStart(&manager->thread);

View File

@ -129,6 +129,7 @@ float assetManagerProgressGet(assetmanager_t *manager);
uint8_t assetManagerHolderCreate(assetmanager_t *man);
void assetManagerHolderRelease(assetmanager_t *man, uint8_t hold);
void assetManagerDisposeReleased(assetmanager_t *man);
void assetManagerDispose(assetmanager_t *man);
////////////////////////////////////////////////////////////////////////////////

View File

@ -10,27 +10,25 @@
bool sandboxGameInit(sandboxgame_t *game) {
quadInit(&game->quad, 0, 0,0,0,0, 500,500,1,1);
assetManagerInit(&game->assetManager);
game->assetOwner = assetManagerHolderCreate(&game->assetManager);
game->assetOwner = assetManagerHolderCreate(&game->engine.assetManager);
assetManagerLoadFont(
&game->assetManager, game->assetOwner,
&game->engine.assetManager, game->assetOwner,
&game->font, "fonts/opensans/OpenSans-Regular.ttf"
);
assetManagerLoadShader(
&game->assetManager, game->assetOwner,
&game->engine.assetManager, game->assetOwner,
&game->shader, "shaders/textured.vert", "shaders/textured.frag"
);
assetManagerLoadScaledTexture(
&game->assetManager, game->assetOwner,
&game->engine.assetManager, game->assetOwner,
&game->st, "poker/characters/sammy", "sprite"
);
assetManagerLoadTextureScale(
&game->assetManager, game->assetOwner,
&game->engine.assetManager, game->assetOwner,
&game->st, &game->texture, 0
);
assetManagerStart(&game->assetManager);
return true;
}
@ -38,11 +36,8 @@ void sandboxGameUpdate(sandboxgame_t *game) {
camera_t camera;
float n;
n = assetManagerProgressGet(&game->assetManager);
if(n < 1.0f) {
assetManagerUpdate(&game->assetManager);
return;
}
n = assetManagerProgressGet(&game->engine.assetManager);
if(n < 1.0f) return;
cameraOrtho(&camera,
0, game->engine.render.width,
@ -59,6 +54,6 @@ void sandboxGameUpdate(sandboxgame_t *game) {
}
void sandboxGameDispose(sandboxgame_t *game) {
assetManagerHolderRelease(&game->assetManager, game->assetOwner);
assetManagerHolderRelease(&game->engine.assetManager, game->assetOwner);
primitiveDispose(&game->quad);
}

View File

@ -17,13 +17,11 @@
#include "../../ui/label.h"
#include "../../ui/breakpoint.h"
#include "../../file/assetmanager.h"
#include "../../file/xml.h"
#include "../../engine/engine.h"
typedef struct {
engine_t engine;
assetmanager_t assetManager;
uint8_t assetOwner;
shader_t shader;