Some code about screen recovery:
Rem ***** Main Source File *****
`Written by Mage Jan 2013
`This program demonstrates recovering after a lost screen device. And demonstrates how to reload content safely during additional screen loss.
`Setup Screen
Set Window off
`Set Display Mode 800,600,32
`backdrop on
sync on
sync rate 0
`Initilize Recovery Mode
RecoveryMode_Init()
`Demo Variables - Not Needed
Global CrashCounter as integer
global yAngle
`Load The Game
Game_LoadScene()
`---Game Loop---------------------------------------------|
Do
Sync
`Check If Screen Was Lost First Thing After Sync
If RecoveryMode_ScreenValid() = 0
`Handle Recovery Of Game Assets
RecoveryMode_Main()
`Increment Crash Counter For The Demo Purposes
`lastCrashCounter = CrashCounter
INC CrashCounter
EndIf
if timer() >= timestamp+2
lastCrashCounter = CrashCounter
timestamp = timer()
endif
`Check If Screen Was Lost First Thing After Sync
`If it's not begin shadow copy of values
If RecoveryMode_ScreenValid() = 1 and lastCrashCounter = CrashCounter
yAngle = object angle y(1)
EndIf
`Operate The Game
YRotate Object 1, Object Angle Y(1) + 0.01
Text 10, 10, "Crashed " + Str$(CrashCounter) + " times."
Text 10, 30, "yAngle " +Str$(yAngle)
Loop
End
`----------------------GAME LOADING FUNCTIONS---------------------|
`Loads All Game Assets, Exits Early If Screen Is Lost During Load
`The purpose is to demonstrate loading with an animated screen and aborting early if screen is lost again.
Function Game_LoadScene()
`Check If Screen Was Lost, Abort Load if lost
If RecoveryMode_ScreenValid() = 0 Then ExitFunction
`Reload Some of the game assets...
Make Object Cube 1, 1
Position Object 1, 0, 0, 1
Xrotate Object 1, 45
YRotate Object 1,yAngle
`Again check if screen was lost and abort if lost
If RecoveryMode_ScreenValid() = 0 Then ExitFunction
EndFunction
`-----------------RECOVERY MODE FUNCTIONS------------------|
`Handles recovery of game assets when screen is lost. The game will attempt to reload everything but this function will
`retry if the loading code aborts from being interupted by another lost screen.
function RecoveryMode_Main()
`Keep attempting recovery while the screen is lost.
While RecoveryMode_ScreenValid() = 0
`Init Recovery Mode Detection (try to create an image then below we will sync and see if it got deleted, if deleted the screen still isnt available)
RecoveryMode_Init()
`Sync To Test If Screen has been restored
Sync
`If Screen was restored, then begin reloading the game assets
If RecoveryMode_ScreenValid() = 1
`Load Game Assets
Game_LoadScene()
EndIf
EndWhile
endfunction
`Sets up Recovery Mode Detection Method, an image is created off screen. If the screen is lost, this image will be deleted.
`We can test for this image to detect if the screen was lost.
Function RecoveryMode_Init()
`Create an image from memory so the demo doesnt need extra files.
Make Image 10, 1, 1
EndFunction
`Tests whether Screen was lost, based on loaded image being deleted when screen is lost.
Function RecoveryMode_ScreenValid()
retVal = Image Exist(10)
EndFunction retVal
Coding is My Kung Fu!
And My Kung Fu is better than Yours!