January 15, 2021, 04:45:28 PM

Author Topic: [bb] Object and Handle with Entities by Rob [ 1+ years ago ]  (Read 420 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Object and Handle with Entities
Author : Rob
Posted : 1+ years ago

Description : Example on how to use object and handle to hold unlimited data about entities with very low lookup time.

Code :
Code: BlitzBasic
  1. ; Example on how to use object and handle
  2. ; to hold unlimited data about entities with
  3. ; very low lookup time.
  4. ; By Rob Cummings
  5.  
  6. Graphics3D 640,480,0,2
  7.  
  8. Type info
  9.         Field name$,a,b,c,stuff,mass#,physics,etc
  10. End Type
  11.  
  12. ;create a ball and some related information.
  13. a.info=New info
  14. a
  15. ame$="bowling ball"
  16. amass#=0.9
  17. ball=CreateSphere()
  18. NameEntity ball,Handle(a) ; the type handle held within the entity name.
  19.  
  20.  
  21. ;now all you do is grab the entity using any of Blitz's own commands.
  22. ;This could be LinePicks, Collisions And so forth.
  23.  
  24.  
  25. ;uncomment for a proper example within a collision framework
  26. ;ent = EntityCollided(bat,collisiontype_ball)
  27. ent=ball ; test
  28.  
  29. If ent
  30.         a.info = Object.info(EntityName(ent)) ; quickly retrieve source type
  31.         Print a
  32. ame$
  33.         Print amass#
  34. EndIf


Comments :


Techlord(Posted 1+ years ago)

 Another option is to use a Array of Types. Ideal for managing types with a specified collection amount and provides faster access than using Object/Handle.
Code: [Select]
; Example on how to use array of types
; to look up types with a extremly low lookup time.
; By Rob Cummings and Frankie Taylor

Graphics3D 640,480,0,2

Type info
Field name$,a,b,c,ball,stuff,mass#,physics,etc
End Type
Dim infoHandle.info(100) ;<-- arrays of types

; Part I create a ball and some related information.
now=MilliSecs()
a.info=New info
a
ame$="bowling ball"
amass#=0.9
aall=CreateSphere()
NameEntity aall,Handle(a) ; the type handle held within the entity name.


;now all you do is grab the entity using any of Blitz's own commands.
;This could be LinePicks, Collisions And so forth.


;uncomment for a proper example within a collision framework
;ent = EntityCollided(bat,collisiontype_ball)
ent=aall ; test

If ent
a.info = Object.info(EntityName(ent)) ; quickly retrieve source type
Print a
ame$
Print amass#
EndIf
Print "time:"+Str(MilliSecs()-now)





;Part II using a Array of Types
now=MilliSecs()
b.info=New info
b
ame$="bowling ball2"
bmass#=0.9
ball=CreateSphere()
infoHandle(2)=b ;we store our second type in the second array element

;now all you do is grab the entity accessing the array element.
;This could be LinePicks, Collisions And so forth.

;uncomment for a proper example within a collision framework
;ent = EntityCollided(bat,collisiontype_ball)
ent=ball ; test

If ent
b.info = infoHandle.info(2) ; quickly retrieve source type
Print b
ame$
Print bmass#
EndIf
Print "time:"+Str(MilliSecs()-now)

WaitKey()



Dabbede(Posted 1+ years ago)

 I prefer the 1st solution! Great!


Mikorians(Posted 1+ years ago)

 Techlord's 2nd infohandle solution didn't work out and alwaysRetrieves type 2.Are we supposed to iterate through each infohandle?Could you finish your line of thought please?Basically- Ent had no connection to infohandle at the end of the program. [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal