Merge update with render section in update loop
This commit is contained in:
parent
4541023396
commit
129234fbeb
@ -183,7 +183,7 @@ void renderer_string(Renderer *const renderer, v4 cameraBounds,
|
|||||||
{
|
{
|
||||||
// NOTE(doyle): Atlas packs fonts tightly, so offset the codepoint
|
// NOTE(doyle): Atlas packs fonts tightly, so offset the codepoint
|
||||||
// to its actual atlas index, i.e. we skip the first 31 glyphs
|
// to its actual atlas index, i.e. we skip the first 31 glyphs
|
||||||
i32 codepoint = string[i];
|
i32 codepoint = string[i];
|
||||||
i32 relativeIndex = CAST(i32)(codepoint - font->codepointRange.x);
|
i32 relativeIndex = CAST(i32)(codepoint - font->codepointRange.x);
|
||||||
CharMetrics charMetric = font->charMetrics[relativeIndex];
|
CharMetrics charMetric = font->charMetrics[relativeIndex];
|
||||||
pos.y = baseline - (scale * charMetric.offset.y);
|
pos.y = baseline - (scale * charMetric.offset.y);
|
||||||
|
@ -398,11 +398,16 @@ INTERNAL void parseInput(GameState *state, const f32 dt)
|
|||||||
spaceBarWasDown = TRUE;
|
spaceBarWasDown = TRUE;
|
||||||
setActiveEntityAnim(hero, entityanimid_tackle);
|
setActiveEntityAnim(hero, entityanimid_tackle);
|
||||||
|
|
||||||
hero->dPos.x += (1.0f * METERS_TO_PIXEL);
|
|
||||||
if (hero->direction == direction_east)
|
if (hero->direction == direction_east)
|
||||||
|
{
|
||||||
ddPos.x = 1.0f;
|
ddPos.x = 1.0f;
|
||||||
|
hero->dPos.x += (1.0f * METERS_TO_PIXEL);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
ddPos.x = -1.0f;
|
ddPos.x = -1.0f;
|
||||||
|
hero->dPos.x -= (1.0f * METERS_TO_PIXEL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!state->keys[GLFW_KEY_SPACE])
|
else if (!state->keys[GLFW_KEY_SPACE])
|
||||||
@ -544,54 +549,42 @@ void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt)
|
|||||||
|
|
||||||
if (cameraBounds.w <= world->bounds.w) cameraBounds.w = world->bounds.w;
|
if (cameraBounds.w <= world->bounds.w) cameraBounds.w = world->bounds.w;
|
||||||
|
|
||||||
/* Render entity and logic loop */
|
/* Update and render entity loop */
|
||||||
ASSERT(world->freeEntityIndex < world->maxEntities);
|
ASSERT(world->freeEntityIndex < world->maxEntities);
|
||||||
for (i32 i = 0; i < world->freeEntityIndex; i++)
|
for (i32 i = 0; i < world->freeEntityIndex; i++)
|
||||||
{
|
{
|
||||||
/* Render entities */
|
/* Game logic */
|
||||||
Entity *const entity = &world->entities[i];
|
Entity *const entity = &world->entities[i];
|
||||||
u32 oldAnimCycleCount = entity->currAnimCyclesCompleted;
|
u32 oldAnimCycleCount = entity->currAnimCyclesCompleted;
|
||||||
updateEntityAnim(entity, dt);
|
updateEntityAnim(entity, dt);
|
||||||
|
|
||||||
v2 entityRenderSize = entity->size;
|
v2 entityRenderSize = entity->size;
|
||||||
switch (entity->type)
|
if (entity->type == entitytype_hero)
|
||||||
{
|
{
|
||||||
case entitytype_mob:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case entitytype_hero:
|
|
||||||
#ifdef DENGINE_DEBUG
|
#ifdef DENGINE_DEBUG
|
||||||
DEBUG_PUSH_STRING("HeroAnimCycleCount: %d",
|
DEBUG_PUSH_STRING("HeroAnimCycleCount: %d",
|
||||||
entity->currAnimCyclesCompleted, "i32");
|
entity->currAnimCyclesCompleted, "i32");
|
||||||
#endif
|
#endif
|
||||||
|
// NOTE(doyle): If dynamic entity, allow animations to exceed
|
||||||
|
// the actual hitbox of character
|
||||||
|
EntityAnim *anim = &entity->anim[entity->currAnimId];
|
||||||
|
v4 texRect = anim->rect[anim->currRectIndex];
|
||||||
|
entityRenderSize = math_getRectSize(texRect);
|
||||||
|
|
||||||
// NOTE(doyle): If dynamic entity, allow animations to exceed
|
if (oldAnimCycleCount != entity->currAnimCyclesCompleted)
|
||||||
// the actual hitbox of character
|
{
|
||||||
EntityAnim *anim = &entity->anim[entity->currAnimId];
|
if (entity->currAnimId == entityanimid_tackle)
|
||||||
v4 texRect = anim->rect[anim->currRectIndex];
|
|
||||||
entityRenderSize = math_getRectSize(texRect);
|
|
||||||
|
|
||||||
if (oldAnimCycleCount != entity->currAnimCyclesCompleted)
|
|
||||||
{
|
{
|
||||||
if (entity->currAnimId == entityanimid_tackle)
|
setActiveEntityAnim(entity, entityanimid_idle);
|
||||||
{
|
if (hero->direction == direction_east)
|
||||||
setActiveEntityAnim(entity, entityanimid_idle);
|
hero->dPos.x -= (1.0f * METERS_TO_PIXEL);
|
||||||
hero->dPos.x -= (1.0f * METERS_TO_PIXEL);
|
else
|
||||||
}
|
hero->dPos.x += (1.0f * METERS_TO_PIXEL);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
f32 rotate = 0.0f;
|
|
||||||
renderer_entity(&state->renderer, cameraBounds, entity,
|
|
||||||
entityRenderSize, rotate, V4(1, 1, 1, 1));
|
|
||||||
|
|
||||||
/* Game logic */
|
|
||||||
|
|
||||||
// TODO(doyle): Undefined behaviour when multiple entities on screen
|
// TODO(doyle): Undefined behaviour when multiple entities on screen
|
||||||
if (entity->type == entitytype_mob)
|
else if (entity->type == entitytype_mob)
|
||||||
{
|
{
|
||||||
// TODO(doyle): Currently calculated in pixels, how about meaningful
|
// TODO(doyle): Currently calculated in pixels, how about meaningful
|
||||||
// game units?
|
// game units?
|
||||||
@ -657,6 +650,10 @@ void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f32 rotate = 0.0f;
|
||||||
|
renderer_entity(&state->renderer, cameraBounds, entity,
|
||||||
|
entityRenderSize, rotate, V4(1, 1, 1, 1));
|
||||||
|
|
||||||
#ifdef DENGINE_DEBUG
|
#ifdef DENGINE_DEBUG
|
||||||
/* Render debug markers on entities */
|
/* Render debug markers on entities */
|
||||||
v4 color = V4(1, 1, 1, 1);
|
v4 color = V4(1, 1, 1, 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user