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 / GUI with coroutines

Author
Message
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 22nd Dec 2010 19:18
Hey, I came up with this solution to GUI in games, I thought it was clever way of linking gui to specific functions without having to hardcore it with ifs.

You will need IanM's plugins for this one, but I hope it's helpful.




=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 22nd Dec 2010 19:29
This looks like it has some potential

I'll have to have a proper experiment with it later, but good work and thank you for sharing

Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 22nd Dec 2010 19:40
Thanks It's not a problem, it's about time I gave something back here.

I haven't yet thought of a way to pass parameters to these functions however, I will have to keep thinking.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd Dec 2010 14:17
TBH, I don't see what you have done here that you couldn't already do with a straight call of a function pointer.

However, you'll be pleased to hear that I've amended coroutines a little in todays release:
- You can now have up to 4096 coroutines instead of the 256 you were limited to previously.
- you have more control over the size of the stack - rather than specifying stack size in MB, you can now specify it in KB and it will be rounded to a multiple of 64 KB. A 64 KB stack is enough to allow you to carry out most operations in DBPro, including syncing with objects.

You are still limited to windows 32 bit limit of 2 GB of usable memory, so you still need to take care of how many coroutines you create, even with the added control of memory usage.

Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 23rd Dec 2010 15:43 Edited at: 23rd Dec 2010 15:57
Quote: "TBH, I don't see what you have done here that you couldn't already do with a straight call of a function pointer."


I'm not aware of how to do this, any hints?

Quote: "so you still need to take care of how many coroutines you create, even with the added control of memory usage."


I see, I thought the coroutines that were called in this snippet were destroyed once run.

EDIT: Wasn't hard, I edited the activate_gui function to just use function calls.




Thanks again IanM

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd Dec 2010 19:36
Coroutines do not destroy themselves when the code completes, they just go into an inactive state, from which you can restart them, unless you specifically override that behaviour, in which case they start again automatically. You have to specifically delete them when you are done.

Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 23rd Dec 2010 19:40
Quote: "You have to specifically delete them when you are done."


I could've sworn I got a error saying the coroutine doesn't exist first time I tried this, but in a simpler program it seems fine. Thanks for the help, and thanks for the excellent plugins, as always

Login to post a reply

Server time is: 2026-07-21 18:13:52
Your offset time is: 2026-07-21 18:13:52