When you say "controller input could have been null" you actually mean input values are 0 because nothing is pressed/moved on controller? Because pointer will never be NULL there - game always passes controller structure to ExecuteBrainHero()
. But if user does not press any buttons and not move analog sticks, the input values will be 0, and that is perfectly fine - code won't do any movement/action if not needed. They way calculations are written they take analog stick value as "amount to move per time unit". If amount is 0 then it won't move. Just like when speed of car is 0, the car does not move.
Some of hero state is stored in GameState->ControlledHeroes
array - one per each controller. You can find definition of this array in game_state
structure inside handmade.h
header. And some of hero state is stored in brain
/ brain_hero
structures from handmade_brain.h
header - that deals with entities.
if(Head && Body)
check is just sanity check if entities are actually loaded. It may be that this code is not needed anymore? Or maybe it is planned that hero can lose body in some action/event? Not sure, I don't remember exactly why. But both of those - Head & Body are always created added in AddPlayer
function that is called from CheckForJoiningPlayers
.
Hopping logic happens inside if(HopRequested)
statement. You can see there logic determining where it wants to go and sets MovementMode on Body
. This movement mode is executed as part of generic entity code - doesn't matter hero or enemy or otherwise. Look in UpdateAndRenderEntities
function from handmade_entity.cpp
file.