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.

Code Snippets / [DBP] - [Matrix1Utils] - Resizable window, lost d3d surface recovery & coroutine asset loading

Author
Message
MonoCoder
18
Years of Service
User Offline
Joined: 4th Dec 2005
Location: england
Posted: 22nd Aug 2012 11:30 Edited at: 22nd Aug 2012 21:51
edit: also requires Diggsey's advanced2d plugin, but uses of it can be substituted.
edit2: forgot - you'll also need four images of about 512x512 for it to load. The images I've used are attached to this post.

This is in small part my own code but moreso a convenient amalgamation of a number of techniques from such members as IanM, CodemanV, and probably one or two other people. To clarify, most of this code is not mine, but I imagine it will be useful as a basis for app development, particularly editors.



Features
- This demo's window can be resized and the client will adjust it's resolution to fit (ie. it isn't left stretched), like a normal program.
- Will recover lost assets without crashing in the event of resizing, computer lock, ctrl+alt+del, computer sleep - anything that causes d3d surface loss.
- Can draw stuff while being dragged around.
- Assets are loaded using a coroutine (ie. "in the background", though not technically). Demo's a simple working progress bar.
- Rejects mouse clicks in window border (noticed this happening when I clicked the title to drag the window and the program thought I wanted to load assets again).
- Responds to windows messages. Also catches close button press, popping open a dialog.

Try
- Left-click to repeat asset loading (note: this won't delete images, just "overwrites" them).
- Up/down arrow keys change pbTickRate. Specifies number of milliseconds to spend at a time loading assets before switching back to drawing. Higher values -> more stuttery screen.
- Maximising window; restoring window and resizing; moving window; minimising; locking, ctrl+alt+del'ing; closing.
- When assets have loaded, sweep the mouse back and forth to "flip" through loaded images (just to show/prove that prove they're there).
- Adjusting numAssetToLoad.

Issues/Concerns
- On resize I limit the window dimensions to desktop dimension() - 1. For some reason, missing off the -1 and then maximising causes a "Display Using 32 Bit is not supported by available hardware at line 0" error. When maximised (here, to 1440x821), there is a doubled-up/skipped vertical line of pixels in the middle indicative of a slightly-off resolution (it seems to be off by 1, but as per above, trying to make it up crashes it). This doesn't occur when not maximised.
- You can sometimes see flickers of backdrop when you start manipulating the window (blue previously; since using color backdrop it's become unnoticable - but might be an issue in cases where there are various colours on screen).
- Drawing during window manipulation only happens once every second, or if currently dragging.

Code


edit: circles animate properly now.

Ta

Attachments

Login to view attachments
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 22nd Aug 2012 12:30
Will try this as soon as I can...

Thanks...

Also please link to advanced2d as well in your post above...

thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 23rd Aug 2012 14:00
This is fantastic. I've never seen all these tricks used at once. Something I'm certainly going to use in a game

GIDustin
15
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 31st Aug 2012 20:41 Edited at: 31st Aug 2012 20:47
I have been trying to uncap your code from 60 FPS and I am not having any luck. I replaced the sync rate 60 with sync rate 0 but it still caps at 60.

Are the tickers affecting that somehow?

Edit: For some reason, it caps at 60 fps on one of my monitors, but if I drag it over to the other, it goes up to 100... Very weird...
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 3rd Sep 2012 03:58
I could not compile the code... I have IanMs and A2D installed but it will not work for me for some reason... says it cannot understand some constructs...

Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 9th Oct 2012 15:45
This is a very nice code example. Compiles and runs for me.
This should get rid of the myth that you can't handle a lost device in DBpro.

[img][/img]


WindowsXP SP3,Vista,Windows 7 SP1, DBpro v7.7RC7
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 9th Oct 2012 17:04
Any updates?

Quote: "This should get rid of the myth that you can't handle a lost device in DBpro."


Not just yet...

Login to post a reply

Server time is: 2024-03-29 01:38:02
Your offset time is: 2024-03-29 01:38:02