Returning a handle instead of manually creating one!

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

It will work like this:

Code: Select all

MySprite = LoadSprite(#PB_Any, "sprite.bmp")

DisplaySprite(MySprite, x, y)
This managment is finished and will be available for the next release.
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

What about releasing the Handles?

For example, will there be something like ...

Code: Select all

ReleaseSprite(MySprite)
... which will release the handle held by MySprite and make it available for use when #PB_Any is used again?
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

I am assuming that PB manages an internal table or list to avoid conflicts and so we could do something like:

Code: Select all

For i = 0 to 99
  MySpriteIds(i) = LoadSprite(#PB_Any, "sprite" + str(i) + ".bmp") 
Next
...
...
DisplaySprite(MySpriteIds(n), x, y)
If so, WooooHooooo!

That is exactly what the doctor ordered! :)
Kris_a
User
User
Posts: 92
Joined: Sun Feb 15, 2004 8:04 pm
Location: Manchester, UK

Post by Kris_a »

woo! perfect :D

will this work with other things, too? sprites, dll functions, gadets, etc?
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

GedB wrote:What about releasing the Handles?

For example, will there be something like ...

Code: Select all

ReleaseSprite(MySprite)
... which will release the handle held by MySprite and make it available for use when #PB_Any is used again?
It's simply FreeSprite() which does this.

Dare2: in your example, the actual way is better ;)

Kris_a: yes
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

What about something like this:

Code: Select all

myID = LoadSprite(#PB_Any, "sprite.bmp")

For i=1 to 100
  LoadSprite(i, "sprite" + str(i) + ".bmp")
Next
Will this be possible without risking a conflict?
I can't think about a way to make it safe, except for reserverd number ranges that could be in conflict with older sourcecodes.
The compiler can't do anything about it as it does not know about the content of the variable i and on runtime it can't be predicted too (you can't change myID afterwards).

So what are your thoughts about that, Fred?

P.S.: I know that the example is only fictitious ;-)[/i]
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

You can combine them both savely. (which is really cool btw 8) )

The dynamic created numbers are very high ones (because they are in fact memory pointers)
This is how PB knows the difference.

There is no way, this can produce conflicts with old Code, because you were
never able to use such high numbers, PB would have allocated space for
all items from 0 to that number, which would have been a lot.

I have tested the new system very much, and it works perfectly.

Timo
quidquid Latine dictum sit altum videtur
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

freak wrote:I have tested the new system very much, and it works perfectly.
Good to hear. Is the new Version still in alpha state or already in beta?
Will it be 3.9 or 3.82 ? :D
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

This sounds most excellent! :D
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

I definately agree, it would make game coding much much easier, instead of manual handles.
Post Reply