Skip to content

Commit

Permalink
tried to fix tas, failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Mar 24, 2021
1 parent 71bfafc commit 0613f6c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions examples/gps2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ set_callback(function()
tox = math.floor(ex - xmin + 1)
toy = math.floor(ymin - ey + 1)
co = coroutine.create(recalculate)
coroutine.resume(co)
set_interval(function()
coroutine.resume(co)
end, 15)
Expand Down
35 changes: 31 additions & 4 deletions examples/tas_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,50 @@ meta.version = "WIP"
meta.description = "Simple test for TASing a seeded run. It does desync, I don't think the game is fully deterministic or there's something wrong."
meta.author = "Dregu"

local seed = 0

register_option_combo('mode', 'Mode', 'Record\0Playback\0\0')
register_option_bool('pause', 'Start levels paused (when recording)', true)
register_option_bool('pskip', 'Skip level transitions automatically', true)
-- this probably needs a way to save and load the prng state to work
--[[register_option_button('rslevel', 'Restart level', function()
warp(state.world, state.level, state.theme)
end)]]
register_option_string('seed', 'Seed (empty=random)', '')
register_option_button('zrestart', 'Instant restart', function()
if options.seed ~= '' then
seed = tonumber(options.seed, 16)
else
seed = math.random(0, 0xffffffff)
end
--[[state.world_start = 3
state.theme_start = 4
state.world_next = 3
state.theme_next = 4
state.seed = 0x123
state.quest_flags = 1
state.loading = 1]]

set_seed(seed)
end)

local frames = {}
local stopped = true
local stolen = false

set_seed(math.random(0, 0xffffffff))
local cutcb = -1

set_callback(function()
if options.mode == 1 and options.pause then -- record
state.pause = 0x20
if state.pause == 0 then
state.pause = 0x20
else
cutcb = set_callback(function() -- wait for a cutscene to end. still desyncs on olmec
if state.pause == 0 then
clear_callback(cutcb)
state.pause = 0x20
end
end, ON.GUIFRAME)
end
elseif options.mode == 2 then -- playback
steal_input(players[1].uid)
stopped = false
Expand All @@ -40,7 +67,7 @@ set_callback(function()
if input and stolen then
message('Sending '..string.format('%04x', input)..' '..state.time_level..'/'..#frames[state.level_count])
send_input(players[1].uid, input)
elseif state.time_level > #frames[state.level_count] then
elseif stolen and state.time_level > #frames[state.level_count] then
message('Stopped')
return_input(players[1].uid)
stolen = false
Expand Down
4 changes: 2 additions & 2 deletions src/injected/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,10 +1544,10 @@ bool process_keys(UINT nCode, WPARAM wParam, LPARAM lParam)
{
escape();
}
else if (pressed("move_down", wParam) && (float)rand() / RAND_MAX > 0.99 && !repeat)
/*else if (pressed("move_down", wParam) && (float)rand() / RAND_MAX > 0.99 && !repeat)
{
spawn_entity(to_id("ENT_TYPE_ITEM_BROKEN_ARROW"), 0, -0.5, false, 0, 0, false);
}
}*/
else
{
return false;
Expand Down

0 comments on commit 0613f6c

Please sign in to comment.