--Called during a regular (non discrete) update.
--This is called once per frame.
function p.update()
    game_update_user.update()

    -- ga_print("top.update")

    --Debuggin:
    -- aaa_check_api.main()

    --Do we want to seed the random number generated?

    --Getting the initial starting position
    --(when starting a new game).
    if( ga_get_s("xar.create_start_pos.state") ~= "done" ) then
        game_create_start_pos.main()
        return
    end

    --Death checking.
    if ga_get_i("xar.player.health.amount") < 0 then
        ga_print("health is negative in top.update")
        if ga_get_sys_b("game.player.alive") then
            ga_print("calling ga_kill_player")
            ga_kill_player()
        end
    end
    if not ga_get_sys_b("game.player.alive") then
        -- ga_window_push("win_death")
        ga_hud_window_add("win_death", 1000)
    end

    --Damage.
    game_damage.update()

    --Hurt sound.
    game_hurt_sound.update()

    --Setting dependent variables.
    game_var_helpers.set_dep_vars()

    --Inventory regen, etc.
    game_inv_regen.update()

    --Shooting weapons.
    game_inv_exec.update()

    --Hive attack.
    game_ment_hive_attack.update()

    --Dealing with markers.
    if ga_get_b("xar.input.holding_drop_marker") and
        (   ga_get_sys_f("game.time.total") >
            ga_get_f("xar.input.holding_drop_marker_start") + 1.0 )
    then
        -- ga_print("debug: trying to drop long marker alpha!!!")
        game_drop_markers.drop_marker_long()
        ga_set_b("xar.input.holding_drop_marker", false)
    end

    -- ga_print("top.update end")
end

--When the game is paused,
--such as when in a menu.
function p.update_passive()
    game_update_user.update_passive()
    --Nothing more to do.
end

--Gets called first during a (discrete) update cycle.
--The the engine performs its own discrete update.
--Then the update_discrete_post function gets called
--There are 25 discrete updates per second.
function p.update_discrete_pre()
    game_update_user.update_discrete_pre()
    --Nothing more to do.
end

function p.update_discrete_post()
    if( ga_get_b("xar.cheat.inf2.enabled") ) then
        --Easter egg (moving with gravity).
        game_inf2.movement_update_discrete()
    else
        game_movement.update_discrete()
    end
    --more?

    game_inf2.update_discrete_post()

    game_music.play_music_maybe()

    game_update_user.update_discrete_post()
end
