--Called during a regular (non discrete) update.
--This is called once per frame.
function p.perform_update()
    game_update_user.perform_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.perform_update()

    -- -- --Hurt sound.
    game_hurt_sound.perform_update()

    --Setting dependent variables.
    game_var_helpers.set_dep_vars()

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

    --Shooting weapons.
    game_inv_exec.perform_update()

    --Hive attack.
    game_ment_hive_attack.perform_update()

    --Playing a playlist.
    game_music.play_music_maybe()

    --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.perform_update_passive()
    game_update_user.perform_update_passive()

    --This is also here in passive, because
    --need to play the next song if the player
    --is in the main menu.
    game_music.play_music_maybe()
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.perform_update_discrete_pre()
    game_update_user.perform_update_discrete_pre()
    --Nothing more to do.
end

function p.perform_update_discrete_post()
    if( ga_get_b("xar.cheat.inf2.enabled") ) then
        --Easter egg (moving with gravity).
        game_inf2.movement_update_discrete()
        game_inf2.perform_update_discrete_post() --Could combine into one.
    else
        game_movement.perform_update_discrete()
    end
    --more?

    --Moved this to update passive.
    -- game_music.play_music_maybe()

    game_update_user.perform_update_discrete_post()
end
