Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Pro Tip: Recover From Device Lost / Lost Screen Device

Author
Message
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 16th Jan 2013 08:12 Edited at: 19th May 2018 07:42
Turn your game on. Press CTRL + ALT + DEL, close your laptop lid, or wait for the Power Policy to shut off the screen. When you return, you realize your game just crashed.

This is a streamlined, no frills, no distractions demonstration of how to recover from the loss of a screen device. This is one of the fundamental problems people face when making a commercial game with DBP.
My purpose here is to help improve the overall quality of material the community is producing. If I could be so bold...




Previous Discussions On The Issue.
On the rare occasion this problem has been talked about before. I have noticed at times some incorrect or out of date information was allowed to linger. I want to try to iron some of that out. Other times workable demos were circulated, but were either unnecessarily complex, or not specifically purposed to this problem. There was fluff, and/or unresolved issues. I want to try to address this also.


Program Behavior During Screen Loss.
The problem here is when your game is running, and the screen device is lost, such as locking the computer at the Windows login screen, the program will crash. I've tested that the program will not crash and will continue to normally operate the entire time, until the moment the screen is restored. At this time all game assets like images/objects/sprites are deleted. If they aren't reloaded before your program code attempts to use them then the program will crash. However, you can sync the screen while they have been deleted. If you try to position/rotate/etc anything that got deleted that's when a crash occurs. So you can load an image and detect screen loss when it becomes deleted. Deletion actually occurs during first Sync command executed after the screen is restored. So we detect deletion after each sync, and reload the game assets if needed.


Problems with old forum demos and examples.
Some misconceptions have been to use a sprite for detection. All you need is an image. Commonly people have written demos thinking that the screen is lost as soon as the computer is locked or laptop shut, instead of when the screen is returned. So they make loops for the program to sit in for long periods of time that don't even get used. They don't realize the game is playing up until the time the screen comes back. Some people wrote mandatory key presses to begin reloading when the screen returns in their demo, but they should pause after reloading instead... if at all. Screen Invalid() appears to be almost useless and doesn't operate as most people think, intuitively. I haven't seen anyone demonstrate code animating a loading screen, and protecting it against further screen loss, but did see 1 video. Many demos/examples require a rewrite to be capable of this, something every modern game has.




Demo Here - No Media Required


The Details.
In this demo I have attempted to cut the code down to just the basics. Some unnecessary things we saw before have been removed. No fluff. I've attempted to also include practical aspects. The content will reload through a simple function. Reloading supports an animated loading screen and will abort early if the screen is lost again. None of the base system requires any media. The intention here is a clean platform to expand on.

I didn't include any performance optimizations, like timer movement or frame limiters so I could keep the code as clear and clean as possible. I could have made this pretty, instead I'm showing the nuts and bolts in the most simplified terms. All business.


I hope this improves the quality of people's work across the community.
Any suggestions and improvements are welcome.


This work is improved and based upon this discussion:
http://forum.thegamecreators.com/?m=forum_view&t=200645&b=1&msg=2400136#m2400136

See my previous tip here...
http://forum.thegamecreators.com/?m=forum_view&t=202812&b=1
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 16th Jan 2013 09:10
Very Sweet!

I was going to post something on this relating to the image check, love how you placed sync at the top...

Here is your code with code lang=dbp attached



I will see about implementing something similar off-of this and try to report back here...

Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 16th Jan 2013 09:17 Edited at: 16th Jan 2013 09:18
Quote: "Very Sweet!

I was going to post something on this relating to the image check, love how you placed sync at the top...

Here is your code with code lang=dbp attached"


Thanks I just fixed that. Good tip to know.

MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 16th Jan 2013 09:22
Lot of hidden gems on this forum

Login to post a reply

Server time is: 2024-03-28 20:38:45
Your offset time is: 2024-03-28 20:38:45