Advertisement
Guest User

Untitled

a guest
May 21st, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.07 KB | None | 0 0
  1.  
  2. --unsafe state loader, but will refresh the screen faster
  3. function stateLoader(checkPointToLoad, isDesyncFix)
  4.     if(checkPointToLoad ~= nil) then       
  5.         newCheckPoint = savestate.create(3)
  6.         savestate.save(newCheckPoint)
  7.  
  8.         linda:set("finish", "start")
  9.         linda:set("screenValue",  "start")
  10.  
  11.         lanes.gen("*",prepareScreen)(print, emu, gui, stringHash)
  12.         redrawCheckpoint(checkPointToLoad, isDesyncFix);
  13.         emu.pause(); --pausing while kkapture still capture, might create some duplicate...
  14.  
  15.         screenVal = "start"
  16.         while screenVal == "start" do
  17.             screenVal=linda:receive(2.0,  "screenValue")
  18.         end
  19.         lastCheckPointScreenshotValue = screenVal;
  20.         lastCheckPoint = emu.framecount();
  21.  
  22.         redrawCheckpoint(checkPointToLoad, isDesyncFix);
  23.  
  24.         --print("Loading checkpoint #" .. checkPointToLoad)    
  25.         print("Loading checkpoint #" .. emu.framecount())
  26.     end
  27. end
  28.  
  29.  
  30. function prepareScreen(print, emu, gui, stringHash)
  31.     for i=1,100 do
  32.         linda:send( "x", i )    -- TODO some busy wait loop... might help for waiting time. Should be a better way to wait..
  33.     end
  34.  
  35.     co2 = coroutine.create(
  36.         function (x)
  37.             emu.unpause();
  38.             coroutine.yield()
  39.         end
  40.         )
  41.     screenValue=stringHash(gui.gdscreenshot());
  42.     linda:send( "screenValue", screenValue )
  43.  
  44.     coroutine.resume(co2)
  45. end
  46.  
  47.  
  48.  
  49. local function waitingThread(maxWait, checkPointToLoad, print, emu, gui, saveStateFolder, saveStateName,movieSaveStateFolder,movieName, savestate, isDesyncFix, separateThreadLoadState, gen)
  50.  
  51.     for i=1,maxWait do
  52.         linda:send( "x", i )    -- looping as a way to wait for the other thread to end...
  53.     end
  54.  
  55.     gen("*",separateThreadLoadState)(checkPointToLoad, print, emu, gui, saveStateFolder, saveStateName,movieSaveStateFolder,movieName, savestate, isDesyncFix)
  56.  
  57.     finish = "start"
  58.     linda:set( "finish", "start" )
  59.     while finish =="start" do
  60.         finish=linda:receive(2.0,  "finish")
  61.     end
  62.  
  63. end
  64.  
  65. function separateThreadLoadState(checkPointToLoad, print, emu, gui, saveStateFolder, saveStateName, movieSaveStateFolder, movieName, savestate, isDesyncFix)
  66.     newCheckPoint = nil;
  67.  
  68.     if(checkPointToLoad == "current") then
  69.         newCheckPoint = savestate.create(3)
  70.         savestate.save(newCheckPoint)
  71.     else
  72.         newCheckPoint = savestate.create(1)    
  73.  
  74.         pathSaveState  = (isDesyncFix==true and (desyncSaveStateFolder .. "/" .. desyncSaveStateName)
  75.                                             or (saveStateFolder .. "/" .. saveStateName))
  76.  
  77.         saveStateFile = io.open(pathSaveState .. "-" .. checkPointToLoad, "rb")
  78.         save = saveStateFile:read("*all")
  79.  
  80.         loadStateFile = io.open (movieSaveStateFolder .. "/" .. movieName .. ".000", "wb")
  81.         loadStateFile:write(save)
  82.         io.close(loadStateFile)
  83.     end
  84.  
  85.     savestate.load(newCheckPoint)
  86.     savestate.save(newCheckPoint) --save at slot1
  87.  
  88.     savestate.load(newCheckPoint)
  89.  
  90.     linda:send( "finish", "end" )  
  91. end
  92.  
  93.  
  94. function redrawCheckpoint(checkPointToLoad, isDesyncFix)
  95.     --TODO: use some table instead of using so many params
  96.     lanes.gen("*",waitingThread)(100,checkPointToLoad,print,emu,gui,saveStateFolder,saveStateName,movieSaveStateFolder,movieName,savestate,isDesyncFix,separateThreadLoadState,lanes.gen)
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement