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.

Newcomers DBPro Corner / Clearing everything

Author
Message
Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 30th Sep 2009 21:06
Hello everybody!

I have a question: How would I properly end a game loop, clear absolutely everything, like loaded .dbo's and models to proceed and reload the next map?


Thanks a lot!

Regards,
Sph!nx
www.DevEd-portal.com
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 30th Sep 2009 22:04
You store their indices when loading / setting them up, which you will then use to delete all loaded media. As for arrays, there are the empty array and undim commands (check them up if you don't know them). For strings you have the syntax
, if you need to clear them. This is neccessary when purging arrays of user defined types containing strings; if you don't free the string's memory yourself, it will be locked up forever (or well, until you restart your computer) from when its pointer / reference (the string type in DBP) is lost.
In case you use raw memory, there's the delete memory command. Watch out with that one though; deleting (or more accurately, freeing) memory that does not belong to you (as in you have allocated it yourself) causes inpredictable behaviour of everything currently running on your computer and could potentially even screw things up permanently.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 1st Oct 2009 12:47
from a practical point of view, I always write my Init() and DeInit() functions in tandem. When I update Init(), then DeInit() gets the necessary update too.

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 1st Oct 2009 14:38 Edited at: 1st Oct 2009 14:39
I noticed that using a global like CurrentObjectCreationNumber and then writing functions like:



can come in quite handy. When clearing those files, you can be pretty sure all object numbers range from 1 to CurrentObjectCreationNumber.
So Deleting them would be:



From the moment you're creating and deleting objects within the game itself (like bullets or particles/effects), you can't use this method anymore (unless you make some modifications) because global variable will keep increasing in value.

[edit] Of course this method can be used for images, sounds, music and anything that has a number in DBP.

Sven B

Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 1st Oct 2009 16:15 Edited at: 1st Oct 2009 16:15
Thanks all!

My map does not have many objects so I only need to clear the map file itself. Stil, whenever I relead the map, the polycounts gets doubled... Here's my code.



Whenever I have more objects, should I make a loop to delete every instance of it, or is a one time command enough to delete every instance of the same type?

Thanks a lot!

Regards,
Sph!nx
www.DevEd-portal.com
Serial Velocity
16
Years of Service
User Offline
Joined: 24th Aug 2008
Location:
Posted: 1st Oct 2009 18:01 Edited at: 2nd Oct 2009 17:31
If you want to delete every object then you should use a for/next loop which checks all the objects from 1 to some random high number, like this:



zeroSlave
15
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 1st Oct 2009 19:19 Edited at: 1st Oct 2009 19:20
I call a function to create new stuff and fill in the gaps from deleted objects. The global 'MaxObjectNumber' being only affected when all gaps are full:



Then, to delete everything i use a function like so:



An example with deleting random objects and accounting for them in the global 'MaxObjectNumber':



This way, when you want to delete everything, you are not going past the highest object number being used while running your delete loop. It also resets the the MaxObjectNumber before it ends the function.

There's something in this room that makes you can't speak well.
Zeus
18
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 1st Oct 2009 22:37
I know a guy named Pyramid Games who made a really handy function that deletes everything for you.

Here is the code,



Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 2nd Oct 2009 17:04 Edited at: 2nd Oct 2009 17:45
Thanks a lot guys! I will first try the code Zeus provided!

Edit:
Hmmm, did not fully understood Zeus code, though the code from CoughMist is a bit bigger, I can understand that better.

Still learning this!

Regards,
Sph!nx
www.DevEd-portal.com
Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 2nd Oct 2009 18:07
Well, with my own, previously posted code, I can manage to delete the object. Judging from the ingame polycount counter, I see no polies.

The problem is when i reload the map, then I have the double in polies. Don't know how to implement it properly in my code. Here is the map code if you want to take a look at it.


Regards,
Sph!nx
www.DevEd-portal.com
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 2nd Oct 2009 19:30
Zeus; but nowadays we can have higher image and object numbers than 65535
Also, that kind of function must take annoyingly long time to process.

@Sph!nx: the Extends commands are a bit sneaky, and are rather incompatible if you use them mixed in with the core DBP functions. It might also simply be an issue with Extends itself, and not DBPro's fault.
I can see no direct faults in your code, but be aware that it is quite ineccessary to have the initial setup performed whenever changing a map, like you are doing now. The global declarations, sync on, etc. would do to just be called once at the beginning of your program.

Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 3rd Oct 2009 15:03 Edited at: 3rd Oct 2009 16:19
Thanks Rudolpho!

right when I went to bed last night, I figured the double in resource usage, could be indeed the fact than whenever I load a new map, I did have cleared the content of the previous map, but the original loop was still running, so when a new map is running, the old one still runs in the background.

I think I might be able to fix the problem if I make it so that the original, first, loop will completely end, before I run another instance. Gonna fiddle with this! I really appreciate all the help given so far! ^^

Edit: Hmmm, changing the map running loop condition, has no effect. Perhaps I should turn the loop into a separate function that completely gets ended with a map end/change.

Edit 2: Hmmm, I've tried a line of code, but it won't run at all. I still need something like that. I've put a big arrow at my closing function, so if anybody has an idea how to do it, please tell!



Regards,
Sph!nx
www.DevEd-portal.com
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 4th Oct 2009 13:17
Aw, I had written a rather long reply here, and then my connection failed when sending it...

Anyway, at the core of my message was:

You can't end other functions than the one you are currently in using endfunction. Endfunction must also be the last statement in a function block (if you wish to return from a function earlier, you would use exitfunction). Your current code will thus not even compile.

The problem seems to be that you lock the backbuffer in your run_map() function, then check if the map should be changed and in such an event delete the map object before unlocking the buffer again.
Try moving the
part to the end or beginning of your run_map() function, or at least out of the part where the backbuffer is locked.
Alternatively, you could add a call to unlock backbuffer to the beginning of your changemap() function. It is however possible that there will be issues when trying to unlock the buffer again, when it is not locked, once returning to the run_map() function. If that is the case, you can of course use variables to check whether it is locked or not, but the easiest solution would be the one I first proposed.
I'm not sure if this is what causes the problem though; if you would post your full source along with any media, we could try to compile and debug it ourselves.

Cheers,
Rudolpho

Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 4th Oct 2009 15:58 Edited at: 4th Oct 2009 16:12
Thanks so much!

I will try this first myself and if I do not succeed, I will pack the source code and media!

Edit: Attached the source! Rudolpho, if you would take a look at it, you'd make me very happy! Anybody else is welcome to take a look at it too!

Regards,
Sph!nx
www.DevEd-portal.com
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 4th Oct 2009 16:30
Hm... I don't have all the enhancements you've used in there. Don't have time to strip out the code right now; maybe I can do it later tonight though.

Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 4th Oct 2009 17:21
Thanks m8. I appreciate it!

Regards,
Sph!nx
www.DevEd-portal.com
Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 6th Oct 2009 15:05
Perhaps anyone else can help me? I really need this...

Thanks!

Regards,
Sph!nx
www.DevEd-portal.com
Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 8th Oct 2009 18:49 Edited at: 8th Oct 2009 18:49
I've tried many things but I can't get it to work. Everything I do, the game still doubles in poly-count, while the previous items are completely removed.

I don't know, but I perhaps need to free video memory... Can anyone tell me how to do that?

Here is my cleaned up and up to date source code:
http://www.deved-portal.com/sphinx/FTP/origin/sources/source02.rar

Regards,
Sph!nx
www.DevEd-portal.com
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 8th Oct 2009 20:00
Well, sorry, but I just can't get it to run.
First eXtends can't initiate correctly, then if I replace all those commands with the standard DBPro ones, your console won't display when pressing the relevant key. I tried changing it to listen for other keys as well, but no luck :/

Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 8th Oct 2009 20:50 Edited at: 9th Oct 2009 01:36
No problem, thanks a lot for trying! I don't necessarily need an example in my own code, that would work best though, but a more general example would be helpful too.

I will continue to try things.


Edit:
I've made a test program and made one single loop, and made the object and deleted the object properly, so I know it has to do something with the loop. In this case, I will take a look at my whole program structure and see if I can simplify things and keep it to one single loop, like now, but not try to end it and reopen it, like I've been trying now.

I will post my findings!

Edit 2:
I now know it's my whole progrom structure. What would be best to use? Option A or B?



Option B would have the loops inside the function, where needed.

Edit 3:
I've tried option A and it runs just like before. With the same result. When clearing the map, it still counts the polys when a new map is loaded. I've updated my sources here:
http://www.deved-portal.com/sphinx/FTP/origin/sources/source02.rar

Perhaps you can get it to work now, Rudolpho, or anybody? Could it have something to do with freeing video memory or something (FLUSH VIDEO MEMORY and CLS does not seem to be sufficient)?

Thanks!

Regards,
Sph!nx
www.DevEd-portal.com
Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 9th Oct 2009 18:19 Edited at: 9th Oct 2009 21:45
Still can't get it to work. The error remains the same. It removes the stuff fine, but when I reload it doubles in polies for some reason.

This is my deletion code:

(See the post above for the full source code)

Anybody got a little example of how to properly load and unload a .dbo (with limbs)?


Edit :
After having brutally ripped apart my precious code I've found the source of my problem!

It's the loop I use to find all .dbo children:


I really need to have this part of the loading code, so I probably need to write a certain deletion code for this loop... Any thoughts?


Edit 2:
I've found the source of my problem and fixed it! It was the camera, it was created inside the limb-count code. Now I've created it separately and I can delete and (re)load it with out doubling its resources.

Anyone has a thought why it works like that?

Anyway, thanks for reading all my jibberish (specially Rudolpho!)

Regards,
Sph!nx
www.DevEd-portal.com

Login to post a reply

Server time is: 2024-11-25 01:34:56
Your offset time is: 2024-11-25 01:34:56