Types

Blitz3D Forums/Blitz3D Beginners Area/Types

Eric(Posted 2004) [#1]
I'm not sure if this is where to put this, I don't think its a beginners topic. but...

I create a list of Types the normal way.
I use the forbidden Object and Handle commands quiet frequently.

I create a type of an object the 1st one's "Handle" is 1.

If I delete this type and create another instance.. the Handle is now 2. Delete and add 3...4...5 even though Ive delete the previous ones.
This is causing me problem.. Does anyone have experience with these commands. Am I adding my types wrong?

Regards,
Eric

ps hope that made sense.


bradford6(Posted 2004) [#2]
pls post code


Ross C(Posted 2004) [#3]
No, i've been reading other threads on using Object and Handle. You can only use them a finite amount of times. I don't know if it's the size of an integer, but it's a VERY large number. But, it's still possible to "run" out if you know what i mean :o)


GW(Posted 2004) [#4]
If you create a type and get its handle for some other purpose and then later delete the type, the handle you have then becomes invalid. If your referencing a lot of types by their handle, you should alway check the object against NULL before you cast the object.


Eric(Posted 2004) [#5]
Bill there really isn't code to post ...

Ross..thanks I will look into that.

GW... I do use a Null Check. Thanks.


big10p(Posted 2004) [#6]
Eric, the ID number returned by Handle() has nothing to do with the position of the type instance in the list. IDs issued by Handle() are sequential and never reused, even if you then delete an instance.


Eric(Posted 2004) [#7]
Is there anyway you know of to reset it to zero?


big10p(Posted 2004) [#8]
Not without re-running your code. :)

Can you explain why you want to be able to use Handle in this way? We may be able to suggest something.


Eric(Posted 2004) [#9]
Well, Currently there is not a problem... but I can see it happening in the future.

Ok the Brief Version.. I have a game (obviously) :) And there are boxes that get eatten by Enemies. I use Tokamak for Collision and Physics. Tokamak has User Data that I can assign, so I choose to use the Handle() Value so when a collision occurs, I don't have to cycle through all the boxes I can just use the User Data returned from Tokamak.

To be honest I thought that this would be a problem, because I don't know what the Variable size is that holds the User Data. If it was a byte, this would cause some immediate problems because after 255 the my system would not work.. If its a word then 65536 would be my limit. I don't like that there would be a limit, even though 65536 is a lot of items to collect... but over a course of play it Could happen. I can rework this, but it would take a lot of work.

It's not a big deal really, I'll work it out. I was just hoping for a way to reset the Type lists Handle() value.

So with this said there must be a limit to the number of types you can add and delete from one type list.
Time for some tests.

Regards,
Eric


(tu) sinu(Posted 2004) [#10]
i doubt their is a problem, do a test, create 10000000 types and use the handle/object on the last one to see if it works


BobR3D(Posted 2004) [#11]
Just on a practical note.. do you know how BIG a number 65,536 really is..?

How fast do "boxes get eatten by Enemies"..?

If we take PacMan as a known example (which is probably faster than your game eats its boxes), it appears that 3 dots get eaten per second (wacka, wacka, wacka).

Now, assuming a PacMan could eat a continuous line of dots with no pauses for level changes, avoiding ghosts or bathroom breaks, 65,536 divided by 3 dots per second means it would take approximately 21845 seconds to eat all 65,536 dots.

That translates to 364 minutes, or approximately 6.07 hours of continuous play.

If your game only eats 1 box per second, multiply that by three.. or over 18 hours of playtime on a single game before you'd run out of 65,536 handles.

Just one of those things that makes you go hmmmmm....


Eric(Posted 2004) [#12]
hahah Yeah, I guess you are right...time to wake up

Thanks Bob... :)

Regards,
Eric


_PJ_(Posted 2004) [#13]
Is it possible to erase Types?

To completely destroy a Type structure?

Otherwise, even in the example above, the value would still increment. It wouldn't need to be in one 'go', but for the entire duration the game is running. 6 hours of PacMan is not at all unfeasable....


morduun(Posted 2004) [#14]
Handles are signed ints, so in theory you should have about four billion handles per type definition before you start getting undefined results.

Out of curiosity I ran a little test on my own rig, creating type instances, grabbing their handle and then deleting them. It ran as expected through the 2 billion mark, then switched over to -2bil (obviously using an unsigned int internally) and counted upwards from there. Once it hit positive numbers it just kept going, so it's just an incrementing operator with 4 billion possible values.

On the plus side, that means you can do that as often as you like, and so long as you don't have four billion actual type instances running simultaneously (HIGHLY unlikely) you should be fine.

On the down side, if for some reason you've kept the first instance around when that happens (as a prototype, say), it may be overwritten (I say 'may' because I didn't actually keep the first instance around to test this for certain, but I think it's likely).