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/DBC - Automatic Object Numbers - (and other things) Simple but useful

Author
Message
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 22nd Jun 2007 19:50 Edited at: 23rd Jun 2007 19:00
The first thing I found annoying in Dark Basic was the way objects, media etc need to be assigned a number. This code snippet works very well to solve that.

Sample Usage:



NOTE: (DBPro - Sparky DLL Users) Sparky Says no Mesh 255, and I think something else also - so slight mod to this code will make Sparky Safe! Just Make Mesh Counter and the other one??? (I forget) Skip 255.


Source Code:


Have Fun!

Instructions: Place the Source code in your project. Place the Constants in the top of your application so they get "initialized". Then Call the GetNewID or the alternative GetNewID_StartAt function whenever you need a new ID# to use without fear of using a number in use somewhere else in your program.

Note - due to the simple nature of this function - and how it checks if the object exists first before returning you a new id, you can integrate it into existing programs you have written usually without to much hassle - allowing you to add new things without having to remember what the other ID's are.

IMPORTANT: Also due to the nature of how this function get's the ID's - You need to USE the ID you're given as soon as you get it like in the sample usage codesnippet - otherwise you might get the same ID twice because that ID is not yet "in use"

See Ya!

Comments welcome.
Jason

Know way to many languages - Master of none
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 23rd Jun 2007 04:13
FYI - I tried to manually put the code tags but either they didn't take cuz I typed them manually - or I messed them up and they got filtered. Sorry about that.

Know way to many languages - Master of none
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 23rd Jun 2007 19:04
There MUST be exactly the same number of closing code tags as there are opening ones. If they don't match, then NONE of the code tags work.

You had one extra closing code tag at the end of the post - which I just deleted for you.

It's a lot safer to post each section of code in separately, highlight it and click on the Code button once - rather than try to do it manually as you can easily leave in unwanted tags.

TDK_Man

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 24th Jun 2007 04:51 Edited at: 25th Jun 2007 02:33
@TDK - Thank you!

To everyone else. I'm still getting back into DBPro and realize that a case statement would have done some justice in the above snippet as well as perhaps making individual loops for speed's sake versus the one loop constantly checking the "type" of THING you're trying to get an ID for.

Let Me post a tighter version of the code geared for speed and not looks. See Next Post.

Know way to many languages - Master of none
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 24th Jun 2007 15:27 Edited at: 25th Jun 2007 02:34
The constants:



And the function(s):


I guess this forum system doesn't allow us to edit previous posts - or I haven't found the magic button to do it yet

(Edited)

Know way to many languages - Master of none
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 25th Jun 2007 01:10
Quote: "I guess this forum system doesn't allow us to edit previous posts"


It does. You should see 'Edit Own' on the dark grey bar just below your Location on the left.

TDK_Man

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 25th Jun 2007 02:41
@TDK - Boy - Its embarrassing when I miss something like that. Thatnx - just didn't see that Edit Button.

Well, the latest code snippet is fixed and the thread makes more sense. Its always the simple things that get me.

Case and point: I wrote 4000 lines of DBPro code - Messaging System for emulating "events", An emulated "class" of 3d things based on UDT array and a suite of support functions, Input Monitoring for Keyboard, Joystick, Mouse - programmable so it can be reused in any program and still perform fast, "fake" inertia for all axis/angles movements - camera works awesome!!!! But my SHIPS don't move!!!!

One hour later I realize - I "move camera", "Turn camera etc" but not the "move object" commands!!! See - this SHOULD of been the first thing I checked - but instead I checked every subsystem - input, ineria, timer/clock based math, variables names - etc.

At least I basically rechecked all of my 4000 lines of code for good measure - UGH

Good to laugh at myself. BTW - With all these lines of code I'm still getting between 90-115 FPS (though game still quite naked - just navigation in a level) but I'm pleased. I tried to make it smart enough to only process what MUST be handled at any given moment.

Ok - Nuff gabbing - back to da code - Good Day All

Know way to many languages - Master of none

Login to post a reply

Server time is: 2024-11-22 18:47:23
Your offset time is: 2024-11-22 18:47:23