Technically refactored.
This commit is contained in:
@ -49,9 +49,9 @@ elseif(TARGET_TYPE STREQUAL game)
|
||||
${ASSETS_SOURCE_DIR}/shared/shaders/textured.vert shaders/textured.vert
|
||||
${ASSETS_SOURCE_DIR}/shared/shaders/textured.frag shaders/textured.frag
|
||||
)
|
||||
tool_copy(shader_test
|
||||
${ASSETS_SOURCE_DIR}/shared/shaders/test.vert shaders/test.vert
|
||||
${ASSETS_SOURCE_DIR}/shared/shaders/test.frag shaders/test.frag
|
||||
tool_copy(shader_singlerenderlist
|
||||
${ASSETS_SOURCE_DIR}/shared/shaders/singlerenderlist.vert shaders/singlerenderlist.vert
|
||||
${ASSETS_SOURCE_DIR}/shared/shaders/singlerenderlist.frag shaders/singlerenderlist.frag
|
||||
)
|
||||
|
||||
# Fonts
|
||||
@ -86,20 +86,20 @@ elseif(TARGET_TYPE STREQUAL game)
|
||||
# Characters
|
||||
set(DIR_CHARS "${ASSETS_SOURCE_DIR}/poker/characters")
|
||||
tool_vn_character(vn_penny
|
||||
${DIR_CHARS}/penny/character.xml ${DIR_CHARS}/penny.png
|
||||
)
|
||||
tool_vn_character(vn_lucy
|
||||
${DIR_CHARS}/lucy/character.xml ${DIR_CHARS}/lucy.png
|
||||
)
|
||||
tool_vn_character(vn_julie
|
||||
${DIR_CHARS}/julie/character.xml ${DIR_CHARS}/julie.png
|
||||
)
|
||||
tool_vn_character(vn_sammy
|
||||
${DIR_CHARS}/sammy/character.xml ${DIR_CHARS}/sammy.png
|
||||
)
|
||||
tool_vn_character(vn_jenny
|
||||
${DIR_CHARS}/jenny/character.xml ${DIR_CHARS}/jenny.png
|
||||
${DIR_CHARS}/penny/character.xml poker/characters/penny/sprite
|
||||
)
|
||||
# tool_vn_character(vn_lucy
|
||||
# ${DIR_CHARS}/lucy/character.xml poker/characters/lucy/sprite
|
||||
# )
|
||||
# tool_vn_character(vn_julie
|
||||
# ${DIR_CHARS}/julie/character.xml poker/characters/julie/sprite
|
||||
# )
|
||||
# tool_vn_character(vn_sammy
|
||||
# ${DIR_CHARS}/sammy/character.xml poker/characters/sammy/sprite
|
||||
# )
|
||||
# tool_vn_character(vn_jenny
|
||||
# ${DIR_CHARS}/jenny/character.xml poker/characters/jenny/sprite
|
||||
# )
|
||||
|
||||
# World
|
||||
tool_copy(texture_pub
|
||||
@ -111,16 +111,17 @@ elseif(TARGET_TYPE STREQUAL game)
|
||||
|
||||
tool_assets(
|
||||
shader_textured
|
||||
shader_singlerenderlist
|
||||
|
||||
font_opensans
|
||||
|
||||
texture_test
|
||||
|
||||
vn_penny
|
||||
vn_lucy
|
||||
vn_julie
|
||||
vn_sammy
|
||||
|
||||
texture_pub
|
||||
texture_cards
|
||||
# vn_lucy
|
||||
# vn_julie
|
||||
# vn_sammy
|
||||
# vn_jenny
|
||||
|
||||
locale_en
|
||||
)
|
||||
@ -145,9 +146,7 @@ elseif(TARGET_TYPE STREQUAL game)
|
||||
tool_assets(
|
||||
vn_penny
|
||||
vn_sammy
|
||||
|
||||
shader_textured
|
||||
shader_test
|
||||
font_opensans
|
||||
texture_test
|
||||
)
|
||||
|
@ -47,9 +47,7 @@ renderpass_t * renderListRenderPass(
|
||||
}
|
||||
|
||||
void renderListRender(
|
||||
renderlist_t *list, shader_t *shader,
|
||||
shaderuniform_t uniformView, shaderuniform_t uniformProjection,
|
||||
shaderuniform_t uniformModel, shaderuniform_t uniformTextures[]
|
||||
renderlist_t *list, shader_t *shader, shaderuniform_t *uniforms
|
||||
) {
|
||||
camera_t camera;
|
||||
int32_t i;
|
||||
@ -64,21 +62,20 @@ void renderListRender(
|
||||
|
||||
// Set the shader
|
||||
shaderUse(shader);
|
||||
shaderUsePosition(shader, uniformModel, 0,0,0, 0,0,0);
|
||||
shaderUseCamera(shader, uniformView, uniformProjection, &camera);
|
||||
shaderUseCamera(shader, uniforms[0], uniforms[1], &camera);
|
||||
shaderUsePosition(shader, uniforms[2], 0,0,0, 0,0,0);
|
||||
|
||||
// Render each pass.
|
||||
for(i = 0; i < list->passCount; i++) {
|
||||
pass = renderListGetPass(list, i);
|
||||
shaderUseTexture(shader, uniformTextures[i], &pass->frame.texture);
|
||||
shaderUseTexture(shader, uniforms[3+i], &pass->frame.texture);
|
||||
primitiveDraw(&list->quad, 0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
void renderListAsBackbuffer(
|
||||
renderlist_t *list, engine_t *engine, shader_t *shader,
|
||||
shaderuniform_t uniformView, shaderuniform_t uniformProjection,
|
||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
|
||||
shaderuniform_t *uniforms
|
||||
) {
|
||||
camera_t camera;
|
||||
|
||||
@ -91,9 +88,9 @@ void renderListAsBackbuffer(
|
||||
|
||||
// Set up the shader.
|
||||
shaderUse(shader);
|
||||
shaderUseTexture(shader, uniformTexture, &list->frame.texture);
|
||||
shaderUseCamera(shader, uniformView, uniformProjection, &camera);
|
||||
shaderUsePosition(shader, uniformModel, 0,0,0, 0,0,0);
|
||||
shaderUseCamera(shader, uniforms[0], uniforms[1], &camera);
|
||||
shaderUsePosition(shader, uniforms[2], 0,0,0, 0,0,0);
|
||||
shaderUseTexture(shader, uniforms[3], &list->frame.texture);
|
||||
|
||||
// Render the quad to the back buffer.
|
||||
primitiveDraw(&list->quad, 0, -1);
|
||||
|
@ -86,15 +86,10 @@ renderpass_t * renderListRenderPass(
|
||||
*
|
||||
* @param list List to render.
|
||||
* @param shader Shader to use while rendering.
|
||||
* @param uniformView Shader uniform to receive the view matrix.
|
||||
* @param uniformProjection Shader uniform to receive the projection matirx.
|
||||
* @param uniformModel Shader uniform to receive the model matrix.
|
||||
* @param uniformTextures Array of uniforms for each rendered pass as textures.
|
||||
* @param uniforms Uniforms for the render list. [ view, proj, model, ...text ]
|
||||
*/
|
||||
void renderListRender(
|
||||
renderlist_t *list, shader_t *shader,
|
||||
shaderuniform_t uniformView, shaderuniform_t uniformProjection,
|
||||
shaderuniform_t uniformModel, shaderuniform_t uniformTextures[]
|
||||
renderlist_t *list, shader_t *shader, shaderuniform_t *uniforms
|
||||
);
|
||||
|
||||
/**
|
||||
@ -105,15 +100,11 @@ void renderListRender(
|
||||
* @param list Render list to render to the backbuffer
|
||||
* @param engine Engine to use when rendering.
|
||||
* @param shader Shader to use to render to the backbuffer.
|
||||
* @param uniformView Shader uniform to receive the view matrix.
|
||||
* @param uniformProjection Shader uniform to receive the projection matirx.
|
||||
* @param uniformModel Shader uniform to receive the model matrix.
|
||||
* @param uniformTexture Shader uniform to receive the texture.
|
||||
* @param uniforms Uniforms for the back buffer. [ view, proj, model, text ]
|
||||
*/
|
||||
void renderListAsBackbuffer(
|
||||
renderlist_t *list, engine_t *engine, shader_t *shader,
|
||||
shaderuniform_t uniformView, shaderuniform_t uniformProjection,
|
||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
|
||||
shaderuniform_t *uniforms
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -100,7 +100,17 @@ shaderuniform_t shaderGetUniform(shader_t *shader, char *name) {
|
||||
for(i = 0; i < shader->uniformCount; i++) {
|
||||
if(strcmp(shader->uniformNames[i], name) == 0) return i;
|
||||
}
|
||||
return (shaderuniform_t)-1;
|
||||
return (shaderuniform_t)0xFFFFFFFF;
|
||||
}
|
||||
|
||||
void shaderGetUniformArray(
|
||||
shader_t *shader, shaderuniform_t *uniformSet,
|
||||
char **uniforms, int32_t uniformCount
|
||||
) {
|
||||
int32_t i;
|
||||
for(i = 0; i < uniformCount; i++) {
|
||||
uniformSet[i] = shaderGetUniform(shader, uniforms[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void shaderDispose(shader_t *shader) {
|
||||
@ -183,4 +193,4 @@ void shaderUseCamera(
|
||||
) {
|
||||
shaderUseMatrix(shader, uniformView, &camera->view);
|
||||
shaderUseMatrix(shader, uniformProjection, &camera->projection);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ typedef GLuint shaderuniform_t;
|
||||
*/
|
||||
typedef struct {
|
||||
/** Pointer to an uploaded vertex shader program */
|
||||
shaderuniform_t shaderVertex;
|
||||
GLuint shaderVertex;
|
||||
|
||||
/** Pointer to an uploaded fragment shader program */
|
||||
GLuint shaderFrag;
|
||||
@ -65,6 +65,19 @@ void shaderInit(shader_t *shader,
|
||||
*/
|
||||
shaderuniform_t shaderGetUniform(shader_t *shader, char *name);
|
||||
|
||||
/**
|
||||
* Return an array of shaderuniform_t's into an array for a given string array.
|
||||
*
|
||||
* @param shader Shader to get the uniforms from.
|
||||
* @param uniformSet Uniform array to get.
|
||||
* @param uniforms Uniform strings to get.
|
||||
* @param uniformCount Count of uniforms you're getting.
|
||||
*/
|
||||
void shaderGetUniformArray(
|
||||
shader_t *shader, shaderuniform_t *uniformSet,
|
||||
char **uniforms, int32_t uniformCount
|
||||
);
|
||||
|
||||
/**
|
||||
* Cleanup and unload a previously loaded shader.
|
||||
* @param shader The shader to unload
|
||||
@ -77,8 +90,6 @@ void shaderDispose(shader_t *shader);
|
||||
*/
|
||||
void shaderUse(shader_t *shader);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Attaches a texture to the shader.
|
||||
*
|
||||
|
@ -15,7 +15,7 @@ typedef struct {
|
||||
int16_t width;
|
||||
int16_t height;
|
||||
uint8_t scale;
|
||||
} scaledtexturescale_t;
|
||||
} texturescalescale_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t channels;
|
||||
@ -24,6 +24,6 @@ typedef struct {
|
||||
int16_t baseWidth;
|
||||
int16_t baseHeight;
|
||||
|
||||
scaledtexturescale_t scales[MANAGED_TEXTURE_SCALE_MAX];
|
||||
texturescalescale_t scales[MANAGED_TEXTURE_SCALE_MAX];
|
||||
uint8_t scaleCount;
|
||||
} scaledtexture_t;
|
||||
} texturescale_t;
|
@ -27,7 +27,7 @@ void threadCancel(thread_t *thread) {
|
||||
}
|
||||
|
||||
void threadSleep(float time) {
|
||||
sleep((time * 1000.0f));
|
||||
sleep((unsigned long)(time * 1000.0f));
|
||||
}
|
||||
|
||||
int32_t _threadWrappedCallback(thread_t *thread) {
|
||||
|
@ -25,13 +25,8 @@ assetmanagerloaderdefinition_t ASSET_MANAGER_LOADERS[] = {
|
||||
},
|
||||
{
|
||||
&_assetManagerLoaderScaledTextureAsync,
|
||||
NULL,
|
||||
NULL
|
||||
},
|
||||
{
|
||||
&_assetManagerLoaderTextureScaleAsync,
|
||||
&_assetManagerLoaderTextureScaleSync,
|
||||
&_assetManagerLoaderTextureScaleDispose
|
||||
&_assetManagerLoaderScaledTextureSync,
|
||||
&_assetManagerLoaderScaledTextureDispose
|
||||
}
|
||||
};
|
||||
|
||||
@ -48,15 +43,42 @@ void assetManagerInit(assetmanager_t *manager) {
|
||||
float assetManagerProgressGet(assetmanager_t *manager) {
|
||||
float done;
|
||||
uint8_t i;
|
||||
assetmanageritem_t *item;
|
||||
|
||||
done = 0.0f;
|
||||
|
||||
for(i = 0; i < manager->itemCount; i++) {
|
||||
if(!assetManagerItemIsFinished(manager->items + i)) continue;
|
||||
done++;
|
||||
item = manager->items + i;
|
||||
done += assetManagerItemIsFinished(
|
||||
item, ASSET_MANAGER_LOADERS + item->type
|
||||
) ? 1 : 0;
|
||||
}
|
||||
return done / ((float)manager->itemCount);
|
||||
}
|
||||
|
||||
return done / ((float) manager->itemCount);
|
||||
float assetManagerProgressGetForHolder(
|
||||
assetmanager_t *manager, assetmanagerowner_t hold
|
||||
) {
|
||||
float done;
|
||||
uint8_t i, j, c;
|
||||
assetmanageritem_t *item;
|
||||
done = 0.0f;
|
||||
c = 0x00;
|
||||
for(i = 0; i < manager->itemCount; i++) {
|
||||
//Is this held by this holder?
|
||||
item = manager->items + i;
|
||||
|
||||
for(j = 0; j < item->holderCount; j++) {
|
||||
if(item->holders[j] != hold) continue;
|
||||
c++;
|
||||
done += assetManagerItemIsFinished(
|
||||
item, ASSET_MANAGER_LOADERS + item->type
|
||||
) ? 1 : 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Is this thing even holding any assets to begin with?
|
||||
if(c == 0x00) return 1.0f;
|
||||
return done / (float)c;
|
||||
}
|
||||
|
||||
assetmanagerowner_t assetManagerHolderCreate(assetmanager_t *man) {
|
||||
@ -215,328 +237,4 @@ void assetManagerUpdate(assetmanager_t *manager) {
|
||||
}
|
||||
|
||||
manager->finished = assetManagerProgressGet(manager) >= 1.0f;
|
||||
}
|
||||
|
||||
assetmanageritem_t * assetManagerItemGet(assetmanager_t *man, char *key) {
|
||||
uint8_t i;
|
||||
assetmanageritem_t *item;
|
||||
|
||||
for(i = 0; i < man->itemCount; i++) {
|
||||
item = man->items + i;
|
||||
if(strcmp(item->key, key) == 0) return item;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
assetmanageritem_t * assetManagerItemAdd(assetmanager_t *manager, char *key) {
|
||||
// Check if key already exists.
|
||||
assetmanageritem_t *item = manager->items + manager->itemCount++;
|
||||
item->state = ASSET_MANAGER_STATE_NOT_READY;
|
||||
memcpy(item->key, key, strlen(key) + 1);
|
||||
item->holderCount = 0x00;
|
||||
return item;
|
||||
}
|
||||
|
||||
uint8_t assetManagerItemGetOrAddHolder(
|
||||
assetmanageritem_t *item, assetmanagerowner_t owner
|
||||
) {
|
||||
uint8_t i, firstEmpty;
|
||||
firstEmpty = 0xFF;
|
||||
|
||||
for(i = 0; i < item->holderCount; i++) {
|
||||
if(item->holders[i] == owner) return i;
|
||||
if(firstEmpty == 0xFF && item->holders[i] == 0xFF) {
|
||||
firstEmpty = i;
|
||||
}
|
||||
}
|
||||
|
||||
if(firstEmpty == 0xFF) firstEmpty = item->holderCount++;
|
||||
item->holders[firstEmpty] = owner;
|
||||
return firstEmpty;
|
||||
}
|
||||
|
||||
bool assetManagerItemIsFinished(assetmanageritem_t *item) {
|
||||
// Sync done is always done
|
||||
if(item->state == ASSET_MANAGER_STATE_SYNC_DONE) return true;
|
||||
// Only check if ASYNC is done.
|
||||
if(item->state != ASSET_MANAGER_STATE_ASYNC_DONE) return false;
|
||||
// Does it need to still sync load?
|
||||
if(ASSET_MANAGER_LOADERS[item->type].loadSync == NULL) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Font
|
||||
assetmanageritem_t * assetManagerLoadFont(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner, char *fileName
|
||||
) {
|
||||
assetmanageritem_t *item;
|
||||
item = assetManagerItemGet(manager, fileName);
|
||||
if(item == NULL) {
|
||||
item = assetManagerItemAdd(manager, fileName);
|
||||
item->type = ASSET_MANAGER_TYPE_FONT;
|
||||
item->data.font.fileName = fileName;
|
||||
}
|
||||
assetManagerItemGetOrAddHolder(item, owner);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderFontAsync(assetmanageritem_t *item) {
|
||||
item->data.font.data = assetStringLoad(item->data.font.fileName);
|
||||
return item->data.font.data != NULL;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderFontSync(assetmanageritem_t *item) {
|
||||
fontInit(&item->data.font.font, item->data.font.data);
|
||||
free(item->data.font.data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderFontDispose(assetmanageritem_t *item) {
|
||||
fontDispose(&item->data.font.font);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Texture
|
||||
assetmanageritem_t * assetManagerLoadTexture(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner, char *fileName
|
||||
) {
|
||||
assetmanageritem_t *item;
|
||||
item = assetManagerItemGet(manager, fileName);
|
||||
if(item == NULL) {
|
||||
item = assetManagerItemAdd(manager, fileName);
|
||||
item->type = ASSET_MANAGER_TYPE_TEXTURE;
|
||||
item->data.texture.fileName = fileName;
|
||||
}
|
||||
assetManagerItemGetOrAddHolder(item, owner);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderTextureAsync(assetmanageritem_t *item) {
|
||||
assetbuffer_t *buffer;
|
||||
int channels;
|
||||
stbi_io_callbacks OPENGL_STBI_CALLBACKS;
|
||||
|
||||
buffer = assetBufferOpen(item->data.texture.fileName);
|
||||
if(buffer == NULL) return false;
|
||||
|
||||
// Setup the interface for STBI
|
||||
OPENGL_STBI_CALLBACKS.read = &assetBufferRead;
|
||||
OPENGL_STBI_CALLBACKS.skip = &assetBufferSkip;
|
||||
OPENGL_STBI_CALLBACKS.eof = &assetBufferEnd;
|
||||
|
||||
// Buffer the image
|
||||
channels = 0;
|
||||
item->data.texture.data = (pixel_t *)stbi_load_from_callbacks(
|
||||
&OPENGL_STBI_CALLBACKS, buffer,
|
||||
&item->data.texture.width, &item->data.texture.height,
|
||||
&channels, STBI_rgb_alpha
|
||||
);
|
||||
|
||||
// Close the buffer
|
||||
assetBufferClose(buffer);
|
||||
if(item->data.texture.data == NULL) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderTextureSync(assetmanageritem_t *item) {
|
||||
// Turn into a texture.
|
||||
textureInit(
|
||||
&item->data.texture.texture,
|
||||
item->data.texture.width,
|
||||
item->data.texture.height,
|
||||
item->data.texture.data
|
||||
);
|
||||
|
||||
// Cleanup
|
||||
stbi_image_free(item->data.texture.data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderTextureDispose(assetmanageritem_t *item) {
|
||||
textureDispose(&item->data.texture.texture);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Scaled Texture
|
||||
assetmanageritem_t * assetManagerLoadScaledTexture(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner, char *path, char *file
|
||||
) {
|
||||
assetmanageritem_t *item;
|
||||
scaledtexture_t *st;
|
||||
char buffer[ASSET_MANAGER_ITEM_NAME_MAX];
|
||||
sprintf(buffer, "%s/%s", path, file);
|
||||
item = assetManagerItemGet(manager, buffer);
|
||||
if(item == NULL) {
|
||||
item = assetManagerItemAdd(manager, buffer);
|
||||
|
||||
item->type = ASSET_MANAGER_TYPE_SCALED_TEXTURE;
|
||||
st = &item->data.scaledTexture.scaledTexture;
|
||||
st->scaleCount = 0;
|
||||
st->baseWidth = 0;
|
||||
st->baseHeight = 0;
|
||||
st->path = path;
|
||||
st->file = file;
|
||||
}
|
||||
assetManagerItemGetOrAddHolder(item, owner);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderScaledTextureAsync(assetmanageritem_t *item) {
|
||||
char buffer[128];
|
||||
char *xmlData;
|
||||
xml_t xml;
|
||||
xml_t *child;
|
||||
int16_t i, j;
|
||||
scaledtexture_t *st;
|
||||
st = &item->data.scaledTexture.scaledTexture;
|
||||
|
||||
// Begin loading texture XML
|
||||
sprintf(buffer, "%s/%s.xml", st->path, st->file);
|
||||
|
||||
xmlData = assetStringLoad(buffer);
|
||||
if(xmlData == NULL) return false;
|
||||
xmlLoad(&xml, xmlData);
|
||||
free(xmlData);
|
||||
|
||||
// Parse root texture info
|
||||
i = xmlGetAttributeByName(&xml, "channels");
|
||||
st->channels = (uint8_t)atoi(xml.attributeDatas[i]);
|
||||
i = xmlGetAttributeByName(&xml, "width");
|
||||
st->baseWidth = (int16_t)atoi(xml.attributeDatas[i]);
|
||||
i = xmlGetAttributeByName(&xml, "height");
|
||||
st->baseHeight = (int16_t)atoi(xml.attributeDatas[i]);
|
||||
|
||||
for(j = 0; j < xml.childrenCount; j++) {
|
||||
child = xml.children + j;
|
||||
i = xmlGetAttributeByName(child, "scale");
|
||||
st->scales[st->scaleCount].scale = (uint8_t)atoi(child->attributeDatas[i]);
|
||||
i = xmlGetAttributeByName(child, "width");
|
||||
st->scales[st->scaleCount].width = (int16_t)atoi(child->attributeDatas[i]);
|
||||
i = xmlGetAttributeByName(child, "height");
|
||||
st->scales[st->scaleCount].height = (int16_t)atoi(child->attributeDatas[i]);
|
||||
st->scaleCount++;
|
||||
}
|
||||
|
||||
// Cleanup XML
|
||||
xmlDispose(&xml);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Texture Scale
|
||||
assetmanageritem_t * assetManagerLoadTextureScale(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
scaledtexture_t *st, uint8_t scale
|
||||
) {
|
||||
assetmanageritem_t *item;
|
||||
char buffer[ASSET_MANAGER_ITEM_NAME_MAX];
|
||||
sprintf(buffer, "%s/%s_%u", st->path, st->file, scale);
|
||||
item = assetManagerItemGet(manager, buffer);
|
||||
if(item == NULL) {
|
||||
item = assetManagerItemAdd(manager, buffer);
|
||||
item->type = ASSET_MANAGER_TYPE_SCALE_TEXTURE;
|
||||
item->data.scaleTexture.scale = scale;
|
||||
item->data.scaleTexture.scaledTexture = st;
|
||||
}
|
||||
assetManagerItemGetOrAddHolder(item, owner);
|
||||
return item;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderTextureScaleAsync(assetmanageritem_t *item) {
|
||||
char buffer[128];
|
||||
scaledtexture_t *st;
|
||||
scaledtexturescale_t *sts;
|
||||
size_t length;
|
||||
|
||||
st = item->data.scaleTexture.scaledTexture;
|
||||
sts = st->scales + item->data.scaleTexture.scale;
|
||||
|
||||
// Get filename
|
||||
sprintf(buffer, "%s/%s_%i.texture", st->path, st->file, sts->scale);
|
||||
|
||||
// Create some space
|
||||
length = assetRawLoad(buffer, NULL);
|
||||
if(length == 0) return false;
|
||||
item->data.scaleTexture.data = malloc(sizeof(pixel_t) * length);
|
||||
|
||||
// Load
|
||||
length = assetRawLoad(buffer, (uint8_t *)item->data.scaleTexture.data);
|
||||
if(length == 0) {
|
||||
free(item->data.scaleTexture.data);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderTextureScaleSync(assetmanageritem_t *item) {
|
||||
scaledtexture_t *st;
|
||||
scaledtexturescale_t *sts;
|
||||
st = item->data.scaleTexture.scaledTexture;
|
||||
sts = st->scales + item->data.scaleTexture.scale;
|
||||
|
||||
textureInit(
|
||||
&item->data.scaleTexture.texture,
|
||||
sts->width, sts->height,
|
||||
item->data.scaleTexture.data
|
||||
);
|
||||
|
||||
free(item->data.scaleTexture.data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderTextureScaleDispose(assetmanageritem_t *item) {
|
||||
textureDispose(&item->data.scaleTexture.texture);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Shader
|
||||
assetmanageritem_t * assetManagerLoadShader(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
char *fileVert, char *fileFrag
|
||||
) {
|
||||
assetmanageritem_t *item;
|
||||
char buffer[ASSET_MANAGER_ITEM_NAME_MAX];
|
||||
sprintf(buffer, "%s/%s", fileVert, fileFrag);
|
||||
item = assetManagerItemGet(manager, buffer);
|
||||
if(item == NULL) {
|
||||
item = assetManagerItemAdd(manager, buffer);
|
||||
item->type = ASSET_MANAGER_TYPE_SHADER;
|
||||
item->data.shader.fileVert = fileVert;
|
||||
item->data.shader.fileFrag = fileFrag;
|
||||
}
|
||||
assetManagerItemGetOrAddHolder(item, owner);
|
||||
return item;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderShaderAsync(assetmanageritem_t *item) {
|
||||
item->data.shader.dataVert = assetStringLoad(item->data.shader.fileVert);
|
||||
if(item->data.shader.dataVert == NULL) return false;
|
||||
|
||||
item->data.shader.dataFrag = assetStringLoad(item->data.shader.fileFrag);
|
||||
if(item->data.shader.dataFrag == NULL) {
|
||||
free(item->data.shader.fileVert);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderShaderSync(assetmanageritem_t *item) {
|
||||
shaderInit(
|
||||
&item->data.shader.shader,
|
||||
item->data.shader.dataVert,
|
||||
item->data.shader.dataFrag
|
||||
);
|
||||
free(item->data.shader.dataFrag);
|
||||
free(item->data.shader.dataVert);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderShaderDispose(assetmanageritem_t *item) {
|
||||
shaderDispose(&item->data.shader.shader);
|
||||
return true;
|
||||
}
|
@ -7,107 +7,12 @@
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "../display/font.h"
|
||||
#include "../display/texture.h"
|
||||
#include "../display/scaledtexture.h"
|
||||
#include "../display/shader/shader.h"
|
||||
#include "../engine/thread.h"
|
||||
#include "../util/array.h"
|
||||
#include "types/common.h"
|
||||
#include "loaders/font.h"
|
||||
#include "loaders/scaledtexture.h"
|
||||
#include "loaders/shader.h"
|
||||
#include "loaders/texture.h"
|
||||
#include "asset.h"
|
||||
#include "xml.h"
|
||||
|
||||
#define ASSET_MANAGER_ITEMS_MAX 64
|
||||
#define ASSET_MANAGER_ITEM_NAME_MAX 96
|
||||
|
||||
#define ASSET_MANAGER_HOLDERS_MAX 8
|
||||
|
||||
#define ASSET_MANAGER_STATE_NOT_READY 0x00
|
||||
#define ASSET_MANAGER_STATE_PENDING 0x01
|
||||
#define ASSET_MANAGER_STATE_ASYNC_LOADING 0x02
|
||||
#define ASSET_MANAGER_STATE_ASYNC_ERROR 0x03
|
||||
#define ASSET_MANAGER_STATE_ASYNC_DONE 0x04
|
||||
#define ASSET_MANAGER_STATE_SYNC_LOADING 0x05
|
||||
#define ASSET_MANAGER_STATE_SYNC_ERROR 0x06
|
||||
#define ASSET_MANAGER_STATE_SYNC_DONE 0x07
|
||||
|
||||
#define ASSET_MANAGER_TYPE_TEXTURE 0x00
|
||||
#define ASSET_MANAGER_TYPE_FONT 0x01
|
||||
#define ASSET_MANAGER_TYPE_SHADER 0x02
|
||||
#define ASSET_MANAGER_TYPE_SCALED_TEXTURE 0x03
|
||||
#define ASSET_MANAGER_TYPE_SCALE_TEXTURE 0x04
|
||||
|
||||
// Loader Types
|
||||
typedef struct {
|
||||
font_t font;
|
||||
char *fileName;
|
||||
char *data;
|
||||
} assetmanagerfont_t;
|
||||
|
||||
typedef struct {
|
||||
texture_t texture;
|
||||
char *fileName;
|
||||
int32_t width, height;
|
||||
pixel_t *data;
|
||||
} assetmanagertexture_t;
|
||||
|
||||
typedef struct {
|
||||
scaledtexture_t scaledTexture;
|
||||
} assetmanagerscaledtexture_t;
|
||||
|
||||
typedef struct {
|
||||
scaledtexture_t *scaledTexture;
|
||||
texture_t texture;
|
||||
uint8_t scale;
|
||||
pixel_t *data;
|
||||
} assetmanagerscaletexture_t;
|
||||
|
||||
typedef struct {
|
||||
shader_t shader;
|
||||
char *fileVert;
|
||||
char *fileFrag;
|
||||
char *dataVert;
|
||||
char *dataFrag;
|
||||
} assetmanagershader_t;
|
||||
|
||||
// Item
|
||||
typedef uint8_t assetmanagerowner_t;
|
||||
|
||||
typedef union {
|
||||
assetmanagertexture_t texture;
|
||||
assetmanagershader_t shader;
|
||||
assetmanagerfont_t font;
|
||||
assetmanagerscaledtexture_t scaledTexture;
|
||||
assetmanagerscaletexture_t scaleTexture;
|
||||
} assetmanagerassetdata_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t type;
|
||||
uint8_t state;
|
||||
char key[ASSET_MANAGER_ITEM_NAME_MAX];
|
||||
assetmanagerassetdata_t data;
|
||||
assetmanagerowner_t holders[ASSET_MANAGER_HOLDERS_MAX];
|
||||
uint8_t holderCount;
|
||||
} assetmanageritem_t;
|
||||
|
||||
// Loader
|
||||
typedef bool assetmanagerloader_t(assetmanageritem_t *item);
|
||||
|
||||
typedef struct {
|
||||
assetmanagerloader_t *loadAsync;
|
||||
assetmanagerloader_t *loadSync;
|
||||
assetmanagerloader_t *dispose;
|
||||
} assetmanagerloaderdefinition_t;
|
||||
|
||||
// Manager
|
||||
typedef struct {
|
||||
thread_t thread;
|
||||
bool finished;
|
||||
assetmanageritem_t items[ASSET_MANAGER_ITEMS_MAX];
|
||||
uint8_t itemCount;
|
||||
assetmanagerowner_t holders[ASSET_MANAGER_HOLDERS_MAX];
|
||||
uint8_t holderCount;
|
||||
bool running;
|
||||
} assetmanager_t;
|
||||
|
||||
// Constants
|
||||
extern assetmanagerloaderdefinition_t ASSET_MANAGER_LOADERS[];
|
||||
@ -128,12 +33,52 @@ void assetManagerInit(assetmanager_t *manager);
|
||||
*/
|
||||
float assetManagerProgressGet(assetmanager_t *manager);
|
||||
|
||||
assetmanagerowner_t assetManagerHolderCreate(assetmanager_t *man);
|
||||
void assetManagerHolderRelease(assetmanager_t *man, uint8_t hold);
|
||||
void assetManagerDisposeReleased(assetmanager_t *man);
|
||||
void assetManagerDispose(assetmanager_t *man);
|
||||
/**
|
||||
* Gets the progress of the assets for only those held by a specific holder.
|
||||
*
|
||||
* @param manager Manager to get the progress from
|
||||
* @param hold Holder to get the items progress from.
|
||||
* @return The percentage (0-1) of the loaded assets.
|
||||
*/
|
||||
float assetManagerProgressGetForHolder(
|
||||
assetmanager_t *manager, assetmanagerowner_t hold
|
||||
);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Creates a holder for a given asset manager. Asset holders are kept track of
|
||||
* so that those who requests assets are responsible for those who free them. It
|
||||
* also ensures only the assets that are actually necessary are kept loaded in
|
||||
* memory at all times.
|
||||
*
|
||||
* @param man Asset manager in question
|
||||
* @return An asset manager owner ID.
|
||||
*/
|
||||
assetmanagerowner_t assetManagerHolderCreate(assetmanager_t *man);
|
||||
|
||||
/**
|
||||
* Release a previously reserved asset manager holder. This will (in turn) cause
|
||||
* all of the assets that manager was holding to also be released.
|
||||
*
|
||||
* @param man Asset manager holder to release for.
|
||||
* @param hold Holder to release.
|
||||
*/
|
||||
void assetManagerHolderRelease(assetmanager_t *man, assetmanagerowner_t hold);
|
||||
|
||||
/**
|
||||
* Disposes all assets that are not currently held (released assets). This can
|
||||
* only happen from the main thread due to synchronous assets such as Textures.
|
||||
*
|
||||
* @param man Manager to dispose.
|
||||
*/
|
||||
void assetManagerDisposeReleased(assetmanager_t *man);
|
||||
|
||||
/**
|
||||
* Completely dispose an asset manager. This will also completely dispose all
|
||||
* of the assets that this asset manager is holding.
|
||||
*
|
||||
* @param man Asset manager to dispose
|
||||
*/
|
||||
void assetManagerDispose(assetmanager_t *man);
|
||||
|
||||
/**
|
||||
* Begin asynchronously loading all of the assets
|
||||
@ -153,132 +98,3 @@ int32_t _assetManagerThread(thread_t *thread);
|
||||
* @param manager Manager to synchronously tick.
|
||||
*/
|
||||
void assetManagerUpdate(assetmanager_t *manager);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Retreive an exisitng asset manager item by its key.
|
||||
*
|
||||
* @param man Manager to get from
|
||||
* @param key Key to search for.
|
||||
* @return The matching asset manager item, or NULL if not found.
|
||||
*/
|
||||
assetmanageritem_t * assetManagerItemGet(assetmanager_t *man, char *key);
|
||||
|
||||
/**
|
||||
* Private method, simply adds an item to the manager and resets the state.
|
||||
*
|
||||
* @param manager Manager to add to.
|
||||
* @param key Key to use when adding.
|
||||
* @return The added and reset item.
|
||||
*/
|
||||
assetmanageritem_t * assetManagerItemAdd(assetmanager_t *manager, char *key);
|
||||
|
||||
/**
|
||||
* Add or get the index that a given holder has as a manager item.
|
||||
*
|
||||
* @param i Asset Item to check.
|
||||
* @param o Owner to get/add.
|
||||
* @return The index within the item that the owner is at.
|
||||
*/
|
||||
uint8_t assetManagerItemGetOrAddHolder(
|
||||
assetmanageritem_t *i, assetmanagerowner_t o
|
||||
);
|
||||
|
||||
/**
|
||||
* Checks if a given asset item is finished or not.
|
||||
*
|
||||
* @param item Item to check.
|
||||
* @return True if finished, otherwise false.
|
||||
*/
|
||||
bool assetManagerItemIsFinished(assetmanageritem_t *item);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Queue a font load onto the asset manager buffer.
|
||||
*
|
||||
* @param manager Manager to queue on to.
|
||||
* @param owner Owner ID requesting to load this resource.
|
||||
* @param font Font to push the result in to.
|
||||
* @param fileName Filename of the asset to load.
|
||||
* @return A pointer to the asset manager item for tracking.
|
||||
*/
|
||||
assetmanageritem_t * assetManagerLoadFont(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner, char *fileName
|
||||
);
|
||||
|
||||
bool _assetManagerLoaderFontAsync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderFontSync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderFontDispose(assetmanageritem_t *item);
|
||||
|
||||
/**
|
||||
* Queue a texture load onto the asset manager buffer.
|
||||
*
|
||||
* @param manager Manager to queue on to.
|
||||
* @param owner Owner ID requesting to load this resource.
|
||||
* @param texture Texture to push the result in to.
|
||||
* @param fileName Texture filename to load.
|
||||
* @return A pointer to the asset manager item for tracking.
|
||||
*/
|
||||
assetmanageritem_t * assetManagerLoadTexture(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner, char *fileName
|
||||
);
|
||||
|
||||
bool _assetManagerLoaderTextureAsync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderTextureSync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderTextureDispose(assetmanageritem_t *item);
|
||||
|
||||
/**
|
||||
* Queue a scaled texture load asset to the asset manager buffer. This will not
|
||||
* actually load the texture, just the scaled texture information.
|
||||
*
|
||||
* @param manager Manager to queue on to.
|
||||
* @param owner Owner ID requesting to load this resource.
|
||||
* @param path Path of the texture files
|
||||
* @param file File name of the texture sets.
|
||||
* @return A pointer to the asset manager item for tracking.
|
||||
*/
|
||||
assetmanageritem_t * assetManagerLoadScaledTexture(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner, char *path, char *file
|
||||
);
|
||||
|
||||
bool _assetManagerLoaderScaledTextureAsync(assetmanageritem_t *item);
|
||||
|
||||
/**
|
||||
* Load the given texture scale for a scaled texture.
|
||||
*
|
||||
* @param manager Manager to queue on to.
|
||||
* @param owner Owner ID requesting to load this resource.
|
||||
* @param st Scaled Texture to load in to.
|
||||
* @param text Texture to load the scale in to.
|
||||
* @param scale Scale to load.
|
||||
* @return A pointer to the asset manager item for tracking.
|
||||
*/
|
||||
assetmanageritem_t * assetManagerLoadTextureScale(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
scaledtexture_t *st, uint8_t scale
|
||||
);
|
||||
|
||||
bool _assetManagerLoaderTextureScaleAsync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderTextureScaleSync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderTextureScaleDispose(assetmanageritem_t *item);
|
||||
|
||||
/**
|
||||
* Queues a shader load onto the asset manager buffer.
|
||||
*
|
||||
* @param manager Manager to queue on to.
|
||||
* @param owner Owner ID requesting to load this resource.
|
||||
* @param shader Shader to push the result in to.
|
||||
* @param fileVert Vertex file in question to load.
|
||||
* @param fileFrag Fragment file in question to load.
|
||||
* @return A pointer to the asset manager item for tracking.
|
||||
*/
|
||||
assetmanageritem_t * assetManagerLoadShader(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
char *fileVert, char *fileFrag
|
||||
);
|
||||
|
||||
bool _assetManagerLoaderShaderAsync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderShaderSync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderShaderDispose(assetmanageritem_t *item);
|
39
src/file/loaders/font.c
Normal file
39
src/file/loaders/font.c
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "font.h"
|
||||
|
||||
assetmanageritem_t * assetManagerLoadFont(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner, char *fileName
|
||||
) {
|
||||
assetmanageritem_t *item;
|
||||
item = assetManagerItemGet(manager, fileName);
|
||||
if(item == NULL) {
|
||||
item = assetManagerItemAdd(manager, fileName);
|
||||
item->type = ASSET_MANAGER_TYPE_FONT;
|
||||
item->data.font.fileName = fileName;
|
||||
}
|
||||
assetManagerItemGetOrAddHolder(item, owner);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderFontAsync(assetmanageritem_t *item) {
|
||||
item->data.font.data = assetStringLoad(item->data.font.fileName);
|
||||
return item->data.font.data != NULL;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderFontSync(assetmanageritem_t *item) {
|
||||
fontInit(&item->data.font.font, item->data.font.data);
|
||||
free(item->data.font.data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderFontDispose(assetmanageritem_t *item) {
|
||||
fontDispose(&item->data.font.font);
|
||||
return true;
|
||||
}
|
27
src/file/loaders/font.h
Normal file
27
src/file/loaders/font.h
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "item.h"
|
||||
#include "../asset.h"
|
||||
|
||||
/**
|
||||
* Queue a font load onto the asset manager buffer.
|
||||
*
|
||||
* @param manager Manager to queue on to.
|
||||
* @param owner Owner ID requesting to load this resource.
|
||||
* @param font Font to push the result in to.
|
||||
* @param fileName Filename of the asset to load.
|
||||
* @return A pointer to the asset manager item for tracking.
|
||||
*/
|
||||
assetmanageritem_t * assetManagerLoadFont(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner, char *fileName
|
||||
);
|
||||
|
||||
bool _assetManagerLoaderFontAsync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderFontSync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderFontDispose(assetmanageritem_t *item);
|
57
src/file/loaders/item.c
Normal file
57
src/file/loaders/item.c
Normal file
@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "item.h"
|
||||
|
||||
assetmanageritem_t * assetManagerItemGet(assetmanager_t *man, char *key) {
|
||||
uint8_t i;
|
||||
assetmanageritem_t *item;
|
||||
|
||||
for(i = 0; i < man->itemCount; i++) {
|
||||
item = man->items + i;
|
||||
if(strcmp(item->key, key) == 0) return item;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
assetmanageritem_t * assetManagerItemAdd(assetmanager_t *manager, char *key) {
|
||||
// Check if key already exists.
|
||||
assetmanageritem_t *item = manager->items + manager->itemCount++;
|
||||
item->state = ASSET_MANAGER_STATE_NOT_READY;
|
||||
memcpy(item->key, key, strlen(key) + 1);
|
||||
item->holderCount = 0x00;
|
||||
return item;
|
||||
}
|
||||
|
||||
uint8_t assetManagerItemGetOrAddHolder(
|
||||
assetmanageritem_t *item, assetmanagerowner_t owner
|
||||
) {
|
||||
uint8_t i, firstEmpty;
|
||||
firstEmpty = 0xFF;
|
||||
|
||||
for(i = 0; i < item->holderCount; i++) {
|
||||
if(item->holders[i] == owner) return i;
|
||||
if(firstEmpty == 0xFF && item->holders[i] == 0xFF) {
|
||||
firstEmpty = i;
|
||||
}
|
||||
}
|
||||
|
||||
if(firstEmpty == 0xFF) firstEmpty = item->holderCount++;
|
||||
item->holders[firstEmpty] = owner;
|
||||
return firstEmpty;
|
||||
}
|
||||
|
||||
bool assetManagerItemIsFinished(assetmanageritem_t *item, assetmanagerloaderdefinition_t *def) {
|
||||
// Sync done is always done
|
||||
if(item->state == ASSET_MANAGER_STATE_SYNC_DONE) return true;
|
||||
// Only check if ASYNC is done.
|
||||
if(item->state != ASSET_MANAGER_STATE_ASYNC_DONE) return false;
|
||||
// Does it need to still sync load?
|
||||
if(def->loadSync == NULL) return true;
|
||||
return false;
|
||||
}
|
49
src/file/loaders/item.h
Normal file
49
src/file/loaders/item.h
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../types/common.h"
|
||||
|
||||
/**
|
||||
* Retreive an exisitng asset manager item by its key.
|
||||
*
|
||||
* @param man Manager to get from
|
||||
* @param key Key to search for.
|
||||
* @return The matching asset manager item, or NULL if not found.
|
||||
*/
|
||||
assetmanageritem_t * assetManagerItemGet(assetmanager_t *man, char *key);
|
||||
|
||||
/**
|
||||
* Private method, simply adds an item to the manager and resets the state.
|
||||
*
|
||||
* @param manager Manager to add to.
|
||||
* @param key Key to use when adding.
|
||||
* @return The added and reset item.
|
||||
*/
|
||||
assetmanageritem_t * assetManagerItemAdd(assetmanager_t *manager, char *key);
|
||||
|
||||
/**
|
||||
* Add or get the index that a given holder has as a manager item.
|
||||
*
|
||||
* @param i Asset Item to check.
|
||||
* @param o Owner to get/add.
|
||||
* @return The index within the item that the owner is at.
|
||||
*/
|
||||
uint8_t assetManagerItemGetOrAddHolder(
|
||||
assetmanageritem_t *i, assetmanagerowner_t o
|
||||
);
|
||||
|
||||
/**
|
||||
* Checks if a given asset item is finished or not.
|
||||
*
|
||||
* @param item Item to check.
|
||||
* @param def Item type definition used for loading.
|
||||
* @return True if finished, otherwise false.
|
||||
*/
|
||||
bool assetManagerItemIsFinished(
|
||||
assetmanageritem_t *item, assetmanagerloaderdefinition_t *def
|
||||
);
|
123
src/file/loaders/scaledtexture.c
Normal file
123
src/file/loaders/scaledtexture.c
Normal file
@ -0,0 +1,123 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "scaledtexture.h"
|
||||
|
||||
assetmanageritem_t * assetManagerLoadScaledTexture(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
char *path, char *file, uint8_t scale
|
||||
) {
|
||||
assetmanageritem_t *item;
|
||||
texturescale_t *st;
|
||||
char buffer[ASSET_MANAGER_ITEM_NAME_MAX];
|
||||
|
||||
sprintf(buffer, "%s/%s_%u", path, file, scale);
|
||||
item = assetManagerItemGet(manager, buffer);
|
||||
|
||||
if(item == NULL) {
|
||||
item = assetManagerItemAdd(manager, buffer);
|
||||
item->type = ASSET_MANAGER_TYPE_SCALED_TEXTURE;
|
||||
item->data.scaledTexture.scale = scale;
|
||||
|
||||
st = &item->data.scaledTexture.textureScale;
|
||||
st->scaleCount = 0;
|
||||
st->baseWidth = 0;
|
||||
st->baseHeight = 0;
|
||||
st->path = path;
|
||||
st->file = file;
|
||||
}
|
||||
|
||||
assetManagerItemGetOrAddHolder(item, owner);
|
||||
return item;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderScaledTextureAsync(assetmanageritem_t *item) {
|
||||
char buffer[128];
|
||||
char *xmlData;
|
||||
xml_t xml;
|
||||
xml_t *child;
|
||||
int16_t i, j;
|
||||
texturescale_t *st;
|
||||
texturescalescale_t *sts;
|
||||
size_t length;
|
||||
|
||||
// TODO: This can be improved if we allow both asset dependencies and
|
||||
// dependency sibling adding
|
||||
|
||||
st = &item->data.scaledTexture.textureScale;
|
||||
|
||||
// Begin loading texture XML
|
||||
sprintf(buffer, "%s/%s.xml", st->path, st->file);
|
||||
|
||||
xmlData = assetStringLoad(buffer);
|
||||
if(xmlData == NULL) return false;
|
||||
xmlLoad(&xml, xmlData);
|
||||
free(xmlData);
|
||||
|
||||
// Parse root texture info
|
||||
i = xmlGetAttributeByName(&xml, "channels");
|
||||
st->channels = (uint8_t)atoi(xml.attributeDatas[i]);
|
||||
i = xmlGetAttributeByName(&xml, "width");
|
||||
st->baseWidth = (int16_t)atoi(xml.attributeDatas[i]);
|
||||
i = xmlGetAttributeByName(&xml, "height");
|
||||
st->baseHeight = (int16_t)atoi(xml.attributeDatas[i]);
|
||||
|
||||
for(j = 0; j < xml.childrenCount; j++) {
|
||||
child = xml.children + j;
|
||||
i = xmlGetAttributeByName(child, "scale");
|
||||
st->scales[st->scaleCount].scale = (uint8_t)atoi(child->attributeDatas[i]);
|
||||
i = xmlGetAttributeByName(child, "width");
|
||||
st->scales[st->scaleCount].width = (int16_t)atoi(child->attributeDatas[i]);
|
||||
i = xmlGetAttributeByName(child, "height");
|
||||
st->scales[st->scaleCount].height = (int16_t)atoi(child->attributeDatas[i]);
|
||||
st->scaleCount++;
|
||||
}
|
||||
|
||||
// Cleanup XML
|
||||
xmlDispose(&xml);
|
||||
|
||||
// Get the scale
|
||||
sts = st->scales + item->data.scaledTexture.scale;
|
||||
|
||||
// Get filename
|
||||
sprintf(buffer, "%s/%s_%i.texture", st->path, st->file, sts->scale);
|
||||
|
||||
// Create some space
|
||||
length = assetRawLoad(buffer, NULL);
|
||||
if(length == 0) return false;
|
||||
item->data.scaledTexture.data = malloc(sizeof(pixel_t) * length);
|
||||
|
||||
// Load
|
||||
length = assetRawLoad(buffer, (uint8_t *)item->data.scaledTexture.data);
|
||||
if(length == 0) {
|
||||
free(item->data.scaledTexture.data);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderScaledTextureSync(assetmanageritem_t *item) {
|
||||
texturescale_t *st;
|
||||
texturescalescale_t *sts;
|
||||
st = &item->data.scaledTexture.textureScale;
|
||||
sts = st->scales + item->data.scaledTexture.scale;
|
||||
|
||||
textureInit(
|
||||
&item->data.scaledTexture.texture,
|
||||
sts->width, sts->height,
|
||||
item->data.scaledTexture.data
|
||||
);
|
||||
|
||||
free(item->data.scaledTexture.data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderScaledTextureDispose(assetmanageritem_t *item) {
|
||||
textureDispose(&item->data.scaledTexture.texture);
|
||||
return true;
|
||||
}
|
30
src/file/loaders/scaledtexture.h
Normal file
30
src/file/loaders/scaledtexture.h
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "item.h"
|
||||
#include "../xml.h"
|
||||
#include "../asset.h"
|
||||
|
||||
/**
|
||||
* Load the given texture scale for a scaled texture.
|
||||
*
|
||||
* @param manager Manager to queue on to.
|
||||
* @param owner Owner ID requesting to load this resource.
|
||||
* @param path Path of the texture size sets
|
||||
* @param file Name of the texture that was generated.
|
||||
* @param scale Scale to load.
|
||||
* @return A pointer to the asset manager item for tracking.
|
||||
*/
|
||||
assetmanageritem_t * assetManagerLoadScaledTexture(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
char *path, char *file, uint8_t scale
|
||||
);
|
||||
|
||||
bool _assetManagerLoaderScaledTextureAsync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderScaledTextureSync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderScaledTextureDispose(assetmanageritem_t *item);
|
55
src/file/loaders/shader.c
Normal file
55
src/file/loaders/shader.c
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "shader.h"
|
||||
|
||||
assetmanageritem_t * assetManagerLoadShader(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
char *fileVert, char *fileFrag
|
||||
) {
|
||||
assetmanageritem_t *item;
|
||||
char buffer[ASSET_MANAGER_ITEM_NAME_MAX];
|
||||
sprintf(buffer, "%s/%s", fileVert, fileFrag);
|
||||
item = assetManagerItemGet(manager, buffer);
|
||||
if(item == NULL) {
|
||||
item = assetManagerItemAdd(manager, buffer);
|
||||
item->type = ASSET_MANAGER_TYPE_SHADER;
|
||||
item->data.shader.fileVert = fileVert;
|
||||
item->data.shader.fileFrag = fileFrag;
|
||||
}
|
||||
assetManagerItemGetOrAddHolder(item, owner);
|
||||
return item;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderShaderAsync(assetmanageritem_t *item) {
|
||||
item->data.shader.dataVert = assetStringLoad(item->data.shader.fileVert);
|
||||
if(item->data.shader.dataVert == NULL) return false;
|
||||
|
||||
item->data.shader.dataFrag = assetStringLoad(item->data.shader.fileFrag);
|
||||
if(item->data.shader.dataFrag == NULL) {
|
||||
free(item->data.shader.fileVert);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderShaderSync(assetmanageritem_t *item) {
|
||||
shaderInit(
|
||||
&item->data.shader.shader,
|
||||
item->data.shader.dataVert,
|
||||
item->data.shader.dataFrag
|
||||
);
|
||||
free(item->data.shader.dataFrag);
|
||||
free(item->data.shader.dataVert);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderShaderDispose(assetmanageritem_t *item) {
|
||||
shaderDispose(&item->data.shader.shader);
|
||||
return true;
|
||||
}
|
29
src/file/loaders/shader.h
Normal file
29
src/file/loaders/shader.h
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "item.h"
|
||||
#include "../asset.h"
|
||||
|
||||
/**
|
||||
* Queues a shader load onto the asset manager buffer.
|
||||
*
|
||||
* @param manager Manager to queue on to.
|
||||
* @param owner Owner ID requesting to load this resource.
|
||||
* @param shader Shader to push the result in to.
|
||||
* @param fileVert Vertex file in question to load.
|
||||
* @param fileFrag Fragment file in question to load.
|
||||
* @return A pointer to the asset manager item for tracking.
|
||||
*/
|
||||
assetmanageritem_t * assetManagerLoadShader(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
char *fileVert, char *fileFrag
|
||||
);
|
||||
|
||||
bool _assetManagerLoaderShaderAsync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderShaderSync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderShaderDispose(assetmanageritem_t *item);
|
69
src/file/loaders/texture.c
Normal file
69
src/file/loaders/texture.c
Normal file
@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "texture.h"
|
||||
|
||||
assetmanageritem_t * assetManagerLoadTexture(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner, char *fileName
|
||||
) {
|
||||
assetmanageritem_t *item;
|
||||
item = assetManagerItemGet(manager, fileName);
|
||||
if(item == NULL) {
|
||||
item = assetManagerItemAdd(manager, fileName);
|
||||
item->type = ASSET_MANAGER_TYPE_TEXTURE;
|
||||
item->data.texture.fileName = fileName;
|
||||
}
|
||||
assetManagerItemGetOrAddHolder(item, owner);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderTextureAsync(assetmanageritem_t *item) {
|
||||
assetbuffer_t *buffer;
|
||||
int channels;
|
||||
stbi_io_callbacks OPENGL_STBI_CALLBACKS;
|
||||
|
||||
buffer = assetBufferOpen(item->data.texture.fileName);
|
||||
if(buffer == NULL) return false;
|
||||
|
||||
// Setup the interface for STBI
|
||||
OPENGL_STBI_CALLBACKS.read = &assetBufferRead;
|
||||
OPENGL_STBI_CALLBACKS.skip = &assetBufferSkip;
|
||||
OPENGL_STBI_CALLBACKS.eof = &assetBufferEnd;
|
||||
|
||||
// Buffer the image
|
||||
channels = 0;
|
||||
item->data.texture.data = (pixel_t *)stbi_load_from_callbacks(
|
||||
&OPENGL_STBI_CALLBACKS, buffer,
|
||||
&item->data.texture.width, &item->data.texture.height,
|
||||
&channels, STBI_rgb_alpha
|
||||
);
|
||||
|
||||
// Close the buffer
|
||||
assetBufferClose(buffer);
|
||||
if(item->data.texture.data == NULL) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderTextureSync(assetmanageritem_t *item) {
|
||||
// Turn into a texture.
|
||||
textureInit(
|
||||
&item->data.texture.texture,
|
||||
item->data.texture.width,
|
||||
item->data.texture.height,
|
||||
item->data.texture.data
|
||||
);
|
||||
|
||||
// Cleanup
|
||||
stbi_image_free(item->data.texture.data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderTextureDispose(assetmanageritem_t *item) {
|
||||
textureDispose(&item->data.texture.texture);
|
||||
return true;
|
||||
}
|
27
src/file/loaders/texture.h
Normal file
27
src/file/loaders/texture.h
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "item.h"
|
||||
#include "../asset.h"
|
||||
|
||||
/**
|
||||
* Queue a texture load onto the asset manager buffer.
|
||||
*
|
||||
* @param manager Manager to queue on to.
|
||||
* @param owner Owner ID requesting to load this resource.
|
||||
* @param texture Texture to push the result in to.
|
||||
* @param fileName Texture filename to load.
|
||||
* @return A pointer to the asset manager item for tracking.
|
||||
*/
|
||||
assetmanageritem_t * assetManagerLoadTexture(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner, char *fileName
|
||||
);
|
||||
|
||||
bool _assetManagerLoaderTextureAsync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderTextureSync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderTextureDispose(assetmanageritem_t *item);
|
80
src/file/types/common.h
Normal file
80
src/file/types/common.h
Normal file
@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "../engine/thread.h"
|
||||
#include "texture.h"
|
||||
#include "font.h"
|
||||
#include "shader.h"
|
||||
#include "scaledtexture.h"
|
||||
|
||||
#define ASSET_MANAGER_ITEMS_MAX 64
|
||||
#define ASSET_MANAGER_ITEM_NAME_MAX 96
|
||||
#define ASSET_MANAGER_HOLDERS_MAX 8
|
||||
|
||||
/** States */
|
||||
#define ASSET_MANAGER_STATE_NOT_READY 0x00
|
||||
#define ASSET_MANAGER_STATE_PENDING 0x01
|
||||
#define ASSET_MANAGER_STATE_ASYNC_LOADING 0x02
|
||||
#define ASSET_MANAGER_STATE_ASYNC_ERROR 0x03
|
||||
#define ASSET_MANAGER_STATE_ASYNC_DONE 0x04
|
||||
#define ASSET_MANAGER_STATE_SYNC_LOADING 0x05
|
||||
#define ASSET_MANAGER_STATE_SYNC_ERROR 0x06
|
||||
#define ASSET_MANAGER_STATE_SYNC_DONE 0x07
|
||||
|
||||
/** Type IDs */
|
||||
#define ASSET_MANAGER_TYPE_TEXTURE 0x00
|
||||
#define ASSET_MANAGER_TYPE_FONT 0x01
|
||||
#define ASSET_MANAGER_TYPE_SHADER 0x02
|
||||
#define ASSET_MANAGER_TYPE_SCALED_TEXTURE 0x03
|
||||
|
||||
// Owner
|
||||
typedef uint8_t assetmanagerowner_t;
|
||||
|
||||
// Union of all the manager types
|
||||
typedef union {
|
||||
assetmanagertexture_t texture;
|
||||
assetmanagershader_t shader;
|
||||
assetmanagerfont_t font;
|
||||
assetmanagerscaledtexture_t scaledTexture;
|
||||
} assetmanagerassetdata_t;
|
||||
|
||||
// Item Type
|
||||
typedef struct {
|
||||
uint8_t type;
|
||||
uint8_t state;
|
||||
char key[ASSET_MANAGER_ITEM_NAME_MAX];
|
||||
assetmanagerassetdata_t data;
|
||||
assetmanagerowner_t holders[ASSET_MANAGER_HOLDERS_MAX];
|
||||
uint8_t holderCount;
|
||||
} assetmanageritem_t;
|
||||
|
||||
// Loader
|
||||
typedef bool assetmanagerloader_t(assetmanageritem_t *item);
|
||||
|
||||
// Loader Definition
|
||||
typedef struct {
|
||||
assetmanagerloader_t *loadAsync;
|
||||
assetmanagerloader_t *loadSync;
|
||||
assetmanagerloader_t *dispose;
|
||||
} assetmanagerloaderdefinition_t;
|
||||
|
||||
|
||||
|
||||
// Manager
|
||||
typedef struct {
|
||||
thread_t thread;
|
||||
bool finished;
|
||||
bool running;
|
||||
|
||||
assetmanageritem_t items[ASSET_MANAGER_ITEMS_MAX];
|
||||
uint8_t itemCount;
|
||||
|
||||
assetmanagerowner_t holders[ASSET_MANAGER_HOLDERS_MAX];
|
||||
uint8_t holderCount;
|
||||
} assetmanager_t;
|
15
src/file/types/font.h
Normal file
15
src/file/types/font.h
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../../display/font.h"
|
||||
|
||||
typedef struct {
|
||||
font_t font;
|
||||
char *fileName;
|
||||
char *data;
|
||||
} assetmanagerfont_t;
|
18
src/file/types/scaledtexture.h
Normal file
18
src/file/types/scaledtexture.h
Normal file
@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "../../display/texture.h"
|
||||
#include "../../display/texturescale.h"
|
||||
|
||||
typedef struct {
|
||||
texturescale_t textureScale;
|
||||
texture_t texture;
|
||||
uint8_t scale;
|
||||
pixel_t *data;
|
||||
} assetmanagerscaledtexture_t;
|
16
src/file/types/shader.h
Normal file
16
src/file/types/shader.h
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "../../display/shader/shader.h"
|
||||
|
||||
typedef struct {
|
||||
shader_t shader;
|
||||
char *fileVert;
|
||||
char *fileFrag;
|
||||
char *dataVert;
|
||||
char *dataFrag;
|
||||
} assetmanagershader_t;
|
15
src/file/types/texture.h
Normal file
15
src/file/types/texture.h
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "../../display/texture.h"
|
||||
|
||||
typedef struct {
|
||||
texture_t texture;
|
||||
char *fileName;
|
||||
int32_t width, height;
|
||||
pixel_t *data;
|
||||
} assetmanagertexture_t;
|
@ -8,76 +8,14 @@
|
||||
#include "game.h"
|
||||
|
||||
bool pokerGameInit(pokergame_t *game) {
|
||||
// Begin to load the assets.
|
||||
pokerGameAssetsInit(&game->assets);
|
||||
loadingSceneInit(&game->loadingScene, &game->assets.manager);
|
||||
loadingSceneStart(&game->loadingScene);
|
||||
|
||||
pokerGameSceneInit(&game->gameScene, &game->engine);
|
||||
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);
|
||||
|
||||
// Update the UI
|
||||
pokerUiUpdate(
|
||||
&game->ui,
|
||||
&game->engine,
|
||||
&game->assets.shader,
|
||||
game->scene.characters,
|
||||
game->poker.players
|
||||
);
|
||||
|
||||
// Bind the shader.
|
||||
shaderUse(&game->assets.shader);
|
||||
|
||||
// Render the visual novel scene.
|
||||
vnSceneRenderWorld(&game->scene, &game->engine, &game->assets.shader);
|
||||
|
||||
pokerWorldRender(&game->world, &game->assets);
|
||||
vnSceneRenderCharacters(&game->scene, &game->assets.shader);
|
||||
|
||||
// Render the UI
|
||||
vnSceneRenderGui(&game->scene, &game->engine, &game->assets.shader);
|
||||
pokerUiRender(&game->ui, &game->engine, &game->assets, &game->poker);
|
||||
pokerGameSceneUpdate(&game->gameScene);
|
||||
}
|
||||
|
||||
void pokerGameDispose(pokergame_t *game) {
|
||||
//Cleanup the UI
|
||||
pokerUiDispose(&game->ui);
|
||||
|
||||
// Cleanup the world
|
||||
pokerWorldDispose(&game->world);
|
||||
|
||||
// Destroy the Visual Novel engine.
|
||||
vnSceneDispose(&game->scene);
|
||||
|
||||
// Unload all assets
|
||||
pokerGameAssetsDispose(&game->assets);
|
||||
pokerGameSceneDispose(&game->gameScene);
|
||||
}
|
||||
|
@ -7,18 +7,17 @@
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "../../poker/poker.h"
|
||||
#include "../../vn/conversation/talk.h"
|
||||
#include "../../vn/vnscene.h"
|
||||
#include "../../util/array.h"
|
||||
#include "../../engine/thread.h"
|
||||
#include "../../scene/loadingscene.h"
|
||||
#include "pokergame.h"
|
||||
#include "pokergameassets.h"
|
||||
#include "pokerui.h"
|
||||
#include "pokerworld.h"
|
||||
#include "pokergameaction.h"
|
||||
#include "actions/start.h"
|
||||
#include "../../scene/scene.h"
|
||||
#include "../file/assetmanager.h"
|
||||
#include "scenes/gamescene.h"
|
||||
|
||||
typedef struct {
|
||||
/** Game Engine Instance */
|
||||
engine_t engine;
|
||||
|
||||
/** Main game scene */
|
||||
pokergamescene_t gameScene;
|
||||
} pokergame_t;
|
||||
|
||||
/**
|
||||
* Initializes the game state for the poker game.
|
||||
|
103
src/game/poker/scenes/gamescene.c
Normal file
103
src/game/poker/scenes/gamescene.c
Normal file
@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "gamescene.h"
|
||||
|
||||
void _pokerGameSceneLoaded(scene_t *scene) {
|
||||
pokergamescene_t *gameScene;
|
||||
char *uniforms[4] = { "u_View", "u_Proj", "u_Model", "u_Text" };
|
||||
|
||||
gameScene = (pokergamescene_t *)scene->user;
|
||||
|
||||
|
||||
shaderGetUniformArray(
|
||||
&gameScene->shaderWorld->data.shader.shader, gameScene->uniformsWorld,
|
||||
uniforms, 4
|
||||
);
|
||||
shaderGetUniformArray(
|
||||
&gameScene->shaderList->data.shader.shader, gameScene->uniformsList,
|
||||
uniforms, 4
|
||||
);
|
||||
|
||||
gameScene->passOnly = renderPassAdd(
|
||||
&scene->renderList, &gameScene->shaderWorld->data.shader.shader
|
||||
);
|
||||
}
|
||||
|
||||
void _pokerGameSceneRender(scene_t *scene) {
|
||||
camera_t camera;
|
||||
pokergamescene_t *gameScene;
|
||||
renderpass_t *pass;
|
||||
|
||||
gameScene = (pokergamescene_t *)scene->user;
|
||||
pass = sceneUsePass(scene, gameScene->passOnly);
|
||||
|
||||
cameraPerspective(&camera, 75,
|
||||
(float)pass->frame.texture.width / (float)pass->frame.texture.height,
|
||||
0.01f, 1000.0f
|
||||
);
|
||||
cameraLookAt(&camera, 3,3,3, 0,0,0);
|
||||
|
||||
shaderUseCamera(pass->shader,
|
||||
gameScene->uniformsWorld[0], gameScene->uniformsWorld[1], &camera
|
||||
);
|
||||
shaderUsePosition(pass->shader, gameScene->uniformsWorld[2],
|
||||
0,0,0, scene->engine->time.current,scene->engine->time.current,0
|
||||
);
|
||||
shaderUseTexture(pass->shader, gameScene->uniformsWorld[3],
|
||||
&gameScene->textureTest->data.scaledTexture.texture
|
||||
);
|
||||
primitiveDraw(&gameScene->cube, 0, -1);
|
||||
}
|
||||
|
||||
void pokerGameSceneInit(pokergamescene_t *gameScene, engine_t *engine) {
|
||||
sceneInit(&gameScene->scene, engine, (void *)gameScene);
|
||||
gameScene->scene.onLoaded = &_pokerGameSceneLoaded;
|
||||
gameScene->scene.onRender = &_pokerGameSceneRender;
|
||||
|
||||
// Fonts
|
||||
gameScene->font = assetManagerLoadFont(
|
||||
&engine->assetManager, gameScene->scene.assetOwner,
|
||||
"fonts/opensans/OpenSans-Bold.ttf"
|
||||
);
|
||||
|
||||
// Shaders
|
||||
gameScene->shaderWorld = assetManagerLoadShader(
|
||||
&engine->assetManager, gameScene->scene.assetOwner,
|
||||
"shaders/textured.vert", "shaders/textured.frag"
|
||||
);
|
||||
|
||||
gameScene->shaderList = assetManagerLoadShader(
|
||||
&engine->assetManager, gameScene->scene.assetOwner,
|
||||
"shaders/singlerenderlist.vert", "shaders/singlerenderlist.frag"
|
||||
);
|
||||
|
||||
// Textures
|
||||
gameScene->textureTest = assetManagerLoadScaledTexture(
|
||||
&engine->assetManager, gameScene->scene.assetOwner,
|
||||
"textures", "test_texture", 0
|
||||
);
|
||||
// gameScene->textureTest = assetManagerLoadTexture(
|
||||
// &engine->assetManager, gameScene->scene.assetOwner, "textures/test_texture.png"
|
||||
// );
|
||||
|
||||
|
||||
// Cube
|
||||
cubeInit(&gameScene->cube, 1, 1, 1);
|
||||
}
|
||||
|
||||
void pokerGameSceneUpdate(pokergamescene_t *gameScene) {
|
||||
int i = 3;
|
||||
sceneUpdateToBackbuffer(&gameScene->scene,
|
||||
&gameScene->shaderList->data.shader.shader, gameScene->uniformsList,
|
||||
&gameScene->shaderWorld->data.shader.shader, gameScene->uniformsWorld
|
||||
);
|
||||
}
|
||||
|
||||
void pokerGameSceneDispose(pokergamescene_t *gameScene) {
|
||||
|
||||
}
|
37
src/game/poker/scenes/gamescene.h
Normal file
37
src/game/poker/scenes/gamescene.h
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../../../libs.h"
|
||||
#include "../../../scene/scene.h"
|
||||
#include "../../../display/primitive/primitive.h"
|
||||
#include "../../../display/primitive/cube.h"
|
||||
#include "../../../file/assetmanager.h"
|
||||
|
||||
typedef struct {
|
||||
scene_t scene;
|
||||
|
||||
assetmanageritem_t *font;
|
||||
|
||||
uint8_t passOnly;
|
||||
|
||||
assetmanageritem_t *shaderWorld;
|
||||
shaderuniform_t uniformsWorld[4];
|
||||
|
||||
assetmanageritem_t *shaderList;
|
||||
shaderuniform_t uniformsList[4];
|
||||
|
||||
assetmanageritem_t *textureTest;
|
||||
|
||||
primitive_t cube;
|
||||
} pokergamescene_t;
|
||||
|
||||
void pokerGameSceneInit(pokergamescene_t *gameScene, engine_t *engine);
|
||||
|
||||
void pokerGameSceneUpdate(pokergamescene_t *gameScene);
|
||||
|
||||
void pokerGameSceneDispose(pokergamescene_t *gameScene);
|
83
src/game/pokerbackup/game.c
Normal file
83
src/game/pokerbackup/game.c
Normal file
@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "game.h"
|
||||
|
||||
bool pokerGameInit(pokergame_t *game) {
|
||||
// Begin to load the assets.
|
||||
pokerGameAssetsInit(&game->assets);
|
||||
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);
|
||||
|
||||
// Update the UI
|
||||
pokerUiUpdate(
|
||||
&game->ui,
|
||||
&game->engine,
|
||||
&game->assets.shader,
|
||||
game->scene.characters,
|
||||
game->poker.players
|
||||
);
|
||||
|
||||
// Bind the shader.
|
||||
shaderUse(&game->assets.shader);
|
||||
|
||||
// Render the visual novel scene.
|
||||
vnSceneRenderWorld(&game->scene, &game->engine, &game->assets.shader);
|
||||
|
||||
pokerWorldRender(&game->world, &game->assets);
|
||||
vnSceneRenderCharacters(&game->scene, &game->assets.shader);
|
||||
|
||||
// Render the UI
|
||||
vnSceneRenderGui(&game->scene, &game->engine, &game->assets.shader);
|
||||
pokerUiRender(&game->ui, &game->engine, &game->assets, &game->poker);
|
||||
}
|
||||
|
||||
void pokerGameDispose(pokergame_t *game) {
|
||||
//Cleanup the UI
|
||||
pokerUiDispose(&game->ui);
|
||||
|
||||
// Cleanup the world
|
||||
pokerWorldDispose(&game->world);
|
||||
|
||||
// Destroy the Visual Novel engine.
|
||||
vnSceneDispose(&game->scene);
|
||||
|
||||
// Unload all assets
|
||||
pokerGameAssetsDispose(&game->assets);
|
||||
}
|
41
src/game/pokerbackup/game.h
Normal file
41
src/game/pokerbackup/game.h
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "../../poker/poker.h"
|
||||
#include "../../vn/conversation/talk.h"
|
||||
#include "../../vn/vnscene.h"
|
||||
#include "../../util/array.h"
|
||||
#include "../../engine/thread.h"
|
||||
#include "../../scene/loadingscene.h"
|
||||
#include "pokergame.h"
|
||||
#include "pokergameassets.h"
|
||||
#include "pokerui.h"
|
||||
#include "pokerworld.h"
|
||||
#include "pokergameaction.h"
|
||||
#include "actions/start.h"
|
||||
|
||||
/**
|
||||
* Initializes the game state for the poker game.
|
||||
*
|
||||
* @param game Game to initialize.
|
||||
* @returns True if successful, otherwise false.
|
||||
*/
|
||||
bool pokerGameInit(pokergame_t *game);
|
||||
|
||||
/**
|
||||
* Updates the poker game instance.
|
||||
* @param game Poker game to update for.
|
||||
*/
|
||||
void pokerGameUpdate(pokergame_t *game);
|
||||
|
||||
/**
|
||||
* Disposes a previously initialized poker game instance.
|
||||
* @param game Game to dispose.
|
||||
*/
|
||||
void pokerGameDispose(pokergame_t *game);
|
@ -7,39 +7,66 @@
|
||||
|
||||
#include "scene.h"
|
||||
|
||||
void sceneInit(scene_t *scene, engine_t *engine) {
|
||||
void sceneInit(scene_t *scene, engine_t *engine, void *user) {
|
||||
scene->engine = engine;
|
||||
scene->assetOwner = assetManagerHolderCreate(&engine->assetManager);
|
||||
renderListInit(&scene->renderList,
|
||||
(int32_t)engine->render.width, (int32_t)engine->render.height
|
||||
);
|
||||
scene->user = user;
|
||||
scene->onLoaded = NULL;
|
||||
scene->onRender = NULL;
|
||||
scene->loaded = false;
|
||||
renderListInit(&scene->renderList, (int32_t)1, (int32_t)1);
|
||||
}
|
||||
|
||||
void sceneRenderStart(scene_t *scene) {
|
||||
renderListResize(&scene->renderList,
|
||||
(int32_t)scene->engine->render.width, (int32_t)scene->engine->render.height
|
||||
);
|
||||
}
|
||||
|
||||
void sceneRenderEnd(
|
||||
scene_t *scene,
|
||||
shader_t *shaderRenderList,
|
||||
shaderuniform_t listUniformView, shaderuniform_t listUniformProjection,
|
||||
shaderuniform_t listUniformModel, shaderuniform_t listUniformTextures[],
|
||||
shader_t *shaderBackBuffer,
|
||||
shaderuniform_t backUniformView, shaderuniform_t backUniformProjection,
|
||||
shaderuniform_t backUniformModel, shaderuniform_t backUniformTexture
|
||||
float sceneUpdate(
|
||||
scene_t *scene, int32_t width, int32_t height, shader_t *shader,
|
||||
shaderuniform_t *uniforms
|
||||
) {
|
||||
if(shaderRenderList == NULL || shaderBackBuffer == NULL) return;
|
||||
renderListRender(&scene->renderList, shaderRenderList,
|
||||
listUniformView, listUniformProjection,listUniformModel, listUniformTextures
|
||||
// First, lets check how loading has been going
|
||||
float n = assetManagerProgressGetForHolder(
|
||||
&scene->engine->assetManager, scene->assetOwner
|
||||
);
|
||||
|
||||
// TODO: Loading screen
|
||||
if(n < 1.0f) return n;
|
||||
|
||||
// Fire event
|
||||
if(!scene->loaded) {
|
||||
scene->loaded = true;
|
||||
if(scene->onLoaded != NULL) scene->onLoaded(scene);
|
||||
}
|
||||
|
||||
// Resize the render list
|
||||
renderListResize(&scene->renderList, width, height);
|
||||
|
||||
// Fire callback
|
||||
if(scene->onRender != NULL) scene->onRender(scene);
|
||||
|
||||
// Render the render list itself.
|
||||
renderListRender(&scene->renderList, shader, uniforms);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void sceneUpdateToBackbuffer(scene_t *scene,
|
||||
shader_t *shaderRenderList, shaderuniform_t *listUniforms,
|
||||
shader_t *shaderBackBuffer, shaderuniform_t *backUniforms
|
||||
) {
|
||||
float n = sceneUpdate(scene,
|
||||
(int32_t)scene->engine->render.width, (int32_t)scene->engine->render.height,
|
||||
shaderRenderList, listUniforms
|
||||
);
|
||||
if(n < 1.0f) return;
|
||||
|
||||
renderListAsBackbuffer(&scene->renderList, scene->engine, shaderBackBuffer,
|
||||
backUniformView, backUniformProjection, backUniformModel, backUniformTexture
|
||||
backUniforms
|
||||
);
|
||||
}
|
||||
|
||||
void sceneDispose(scene_t *scene) {
|
||||
assetManagerHolderRelease(&scene->engine->assetManager, scene->assetOwner);
|
||||
renderListDispose(&scene->renderList);
|
||||
}
|
||||
|
||||
renderpass_t * sceneUsePass(scene_t *scene, uint8_t i) {
|
||||
return renderListRenderPass(&scene->renderList, scene->engine, i);
|
||||
}
|
@ -12,21 +12,39 @@
|
||||
#include "../display/renderlist.h"
|
||||
#include "../display/shader/shader.h"
|
||||
|
||||
typedef struct {
|
||||
// Forwarder for scene_t
|
||||
typedef struct _scene_t scene_t;
|
||||
|
||||
// Callbacks
|
||||
typedef void scenecallback_t(scene_t *scene);
|
||||
|
||||
// Scene Definition
|
||||
typedef struct _scene_t {
|
||||
engine_t *engine;
|
||||
assetmanagerowner_t assetOwner;
|
||||
renderlist_t renderList;
|
||||
void *user;
|
||||
|
||||
bool loaded;
|
||||
|
||||
/** Scene Callbacks */
|
||||
scenecallback_t *onLoaded;
|
||||
scenecallback_t *onRender;
|
||||
} scene_t;
|
||||
|
||||
void sceneInit(scene_t *scene, engine_t *engine);
|
||||
void sceneRenderStart(scene_t *scene);
|
||||
void sceneRenderEnd(
|
||||
scene_t *scene,
|
||||
shader_t *shaderRenderList,
|
||||
shaderuniform_t listUniformView, shaderuniform_t listUniformProjection,
|
||||
shaderuniform_t listUniformModel, shaderuniform_t listUniformTextures[],
|
||||
shader_t *shaderBackBuffer,
|
||||
shaderuniform_t backUniformView, shaderuniform_t backUniformProjection,
|
||||
shaderuniform_t backUniformModel, shaderuniform_t backUniformTexture
|
||||
void sceneInit(scene_t *scene, engine_t *engine, void *user);
|
||||
|
||||
|
||||
float sceneUpdate(
|
||||
scene_t *scene, int32_t width, int32_t height, shader_t *shader,
|
||||
shaderuniform_t *uniforms
|
||||
);
|
||||
void sceneDispose(scene_t *scene);
|
||||
|
||||
void sceneUpdateToBackbuffer(scene_t *scene,
|
||||
shader_t *shaderRenderList, shaderuniform_t *listUniforms,
|
||||
shader_t *shaderBackBuffer, shaderuniform_t *backUniforms
|
||||
);
|
||||
|
||||
void sceneDispose(scene_t *scene);
|
||||
|
||||
renderpass_t * sceneUsePass(scene_t *scene, uint8_t i);
|
@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.13)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
||||
# Build Tool
|
||||
# Texture Build Tool
|
||||
project(texture_generation VERSION 1.0)
|
||||
add_executable(texture_generation)
|
||||
target_sources(texture_generation
|
||||
@ -16,7 +16,7 @@ target_sources(texture_generation
|
||||
../utils/file.c
|
||||
../utils/image.c
|
||||
)
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
target_include_directories(texture_generation
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}/../
|
||||
)
|
||||
|
@ -11,8 +11,4 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <stb_image.h>
|
||||
#include <stb_image_resize.h>
|
||||
#include <stb_image_write.h>
|
||||
#include <string.h>
|
@ -9,6 +9,10 @@
|
||||
#include "common.h"
|
||||
#include "file.h"
|
||||
|
||||
#include <stb_image.h>
|
||||
#include <stb_image_resize.h>
|
||||
#include <stb_image_write.h>
|
||||
|
||||
void imageCopy(
|
||||
uint8_t *source, int32_t sourceWidth, int32_t sourceHeight,
|
||||
uint8_t *dest, int32_t destWidth, int32_t destHeight,
|
||||
|
Reference in New Issue
Block a user