Merge update with render section in update loop

This commit is contained in:
Doyle Thai 2016-07-18 00:54:21 +10:00
parent 4541023396
commit 129234fbeb
2 changed files with 33 additions and 36 deletions

View File

@ -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,27 +549,22 @@ 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 // NOTE(doyle): If dynamic entity, allow animations to exceed
// the actual hitbox of character // the actual hitbox of character
EntityAnim *anim = &entity->anim[entity->currAnimId]; EntityAnim *anim = &entity->anim[entity->currAnimId];
@ -576,22 +576,15 @@ void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt)
if (entity->currAnimId == entityanimid_tackle) if (entity->currAnimId == entityanimid_tackle)
{ {
setActiveEntityAnim(entity, entityanimid_idle); setActiveEntityAnim(entity, entityanimid_idle);
if (hero->direction == direction_east)
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);