Add a free four-byte slot to the entity structure

Blitz3D Forums/Blitz3D Programming/Add a free four-byte slot to the entity structure

JoshK(Posted 2003) [#1]
It would be extremely convenient if the internal Blitz3D entity structure had an empty four-byte slot where you could poke a pointer to a bank, where entity parameters are stored. I suspect there must be a free slot, or at least one that doesn't get used for what I am doing.

Then you could write functions like EntityVelocity(), EntityHealth(), etc. As it is, I am cycling through my bank of entities and then returning a buffer with the entity's parameters. I gave up on types because they are too hard to use with my trigger/target system, where I have tons of different types referencing each other.

This is a pretty advanced request, but not difficult to implement, and I think people would understand it isn't under warranty.

Hmmmm...EntityRadiusY is pretty useless, in my program at least...

...wait that could be extremely bad if the y radius was 48567467!


Skitchy(Posted 2003) [#2]
There seem to be LOADS of free bytes in the ImageBuffer structure - not that that means anything to you, but there could be one lurking somewhere in the entity structure too ;)


*(Posted 2003) [#3]
Couldnt you use NameEntity and EntityName for this?


JoshK(Posted 2003) [#4]
No...Blitz tries to free the string bank on exit and crashes. However, EntityRadiusZ doesn't appear to do anything!

Here you go. This lets you store data directly in Blitz entities. Values are indexed from 0 to infinity. Sweeeeet! Write your own entity structures for physics, entity parameters, triggers/targets. If an entity collides with another entity, you can instantly find out that it is a "door" or a "monster". This should be much faster than cycling through a bunch of type, looking for your entity.

SetEntityInt entity,index,value%
GetEntityInt entity,index,[defaultvalue%]

So you can write functions that return properties with just the entity variable:

EntityVelocityX#( PickedEntity() )
EntityHealth( GetParent(entity) )


Graphics3D 400,300,16,2

entity=CreatePivot()

SetEntityInt entity,0,50

SetEntityFloat entity,1,3.14

SetEntityString entity,7,"HEYA"

Print GetEntityInt(entity,0)
Print GetEntityFloat(entity,1)
Print GetEntityString(entity,7)
WaitKey
End



;==========================================
;==========================================
Const BLITZ_ENTITY_RADIUS_Z=240

Function SetEntityInt(entity%,index%,value%)
parameters=PeekL(entity+BLITZ_ENTITY_RADIUS_Z)
If parameters=0 Or parameters=1065353216
	parameters=CreateBank((index+1)*4)
	PokeL entity+BLITZ_ENTITY_RADIUS_Z,parameters
	EndIf
If (index+1)*4>BankSize(parameters) ResizeBank parameters,(index+1)*4
PokeInt parameters,4*index,value
End Function

Function GetEntityInt%(entity%,index%,defaultvalue%=0)
parameters=PeekL(entity+BLITZ_ENTITY_RADIUS_Z)
If parameters=0 Or parameters=1065353216 Return defaultvalue
If (index+1)*4>BankSize(parameters) Return defaultvalue
Return PeekInt(parameters,index*4)
End Function

Function SetEntityFloat(entity%,index%,value#)
parameters=PeekL(entity+BLITZ_ENTITY_RADIUS_Z)
If parameters=0 Or parameters=1065353216
	parameters=CreateBank((index+1)*4)
	PokeL entity+BLITZ_ENTITY_RADIUS_Z,parameters
	EndIf
If (index+1)*4>BankSize(parameters) ResizeBank parameters,(index+1)*4
PokeFloat parameters,4*index,value
End Function

Function GetEntityFloat#(entity%,index%,defaultvalue#=0)
parameters=PeekL(entity+BLITZ_ENTITY_RADIUS_Z)
If parameters=0 Or parameters=1065353216 Return defaultvalue
If (index+1)*4>BankSize(parameters) Return defaultvalue
Return PeekFloat(parameters,index*4)
End Function

Function SetEntityString(entity%,index%,value$)
parameters=PeekL(entity+BLITZ_ENTITY_RADIUS_Z)
If parameters=0 Or parameters=1065353216
	parameters=CreateBank((index+1)*4)
	PokeL entity+BLITZ_ENTITY_RADIUS_Z,parameters
	EndIf
If (index+1)*4>BankSize(parameters) ResizeBank parameters,(index+1)*4
sbank=PeekInt(parameters,4*index)
If sbank
	ResizeBank sbank,Len(value)+1
	Else
	sbank=CreateBank(Len(value)+1)
	PokeInt(parameters,4*index,sbank)
	EndIf
PokeString sbank,0,value
End Function

Function GetEntityString$(entity%,index%,defaultvalue$="")
parameters=PeekL(entity+BLITZ_ENTITY_RADIUS_Z)
If parameters=0 Or parameters=1065353216 Return defaultvalue
If (index+1)*4>BankSize(parameters) Return defaultvalue
sbank=PeekInt(parameters,index*4)
If Not sbank Return defaultvalue
Return PeekString(sbank,0)
End Function



JoshK(Posted 2003) [#5]
Whoa. You can do some pretty cool stuff with this:

Engine structure format

0 - generic*
	0 - target*
	1 - targetname$
	2 - triggermode%
	3 - targetdelay%
1 - physics*
	0 - velocityx#
	1 - velocityy#
	2 - velocityz#
	3 - mass#
	4 - friction#
	5 - flags%
2 - behavior*
	0 - class

	This structure varies depending on entity class.

	Classes
	
	Flare
	0 - range#
	1 - color%

	Player
	0 - name$
	1 - health%

GetEntityTarget()
GetEntityTargetname$()
GetFlareRange#()

etc...



RetroBooster(Posted 2003) [#6]
-ignore-
(something went wrong with a certain test)


JoshK(Posted 2003) [#7]
Whoa...you can load pre-defined entity structures for all your entities. This is powerful.

range#=0 : "range"
color&=16777215 : "color"
size#=300 : "size"
alpha#=0.0

The first value is a variable name and type. The second is the default value. The third is the keyvalue to get the property from the CShop entity. If you load this sturcture, it creates a structure within the entity with the appropriate values.

This is pretty mind-bending stuff! It's the kind of code/entity/editor integration I have always wanted.


JoshK(Posted 2003) [#8]
After playing with this for a little while, it seems like the most efficient way of coding is a combination of types and structures.

I WOULD continue to use For Each Type : UpdateType : Next. It can be very confusing to try to store entity data in banks.

What I think this is good for is storing handles to an entity's type(s). In my engine, entities have a trigger type, a physics type, and a behavior type. Having the ability to retrieve an entity's type and "kind" of type are invaluable. For example, if I land on a moving platform, I want to be able to instantly know its identity as a platform, and retrieve its type object so I can get the velocity.


I would NOT use this for storing all your data, just for allowing a way to reference a type from an entity variable.


slenkar(Posted 2003) [#9]
I dont understand, need a dumb persons explanation.


Beaker(Posted 2003) [#10]
If you don't understand it then you probably don't need it.


slenkar(Posted 2003) [#11]
maybe, but a tutorial wouldnt hurt, I had to read a long tutorial over at blitzcoder to understand types.


Beaker(Posted 2003) [#12]
It's not the same. Types are part of the Blitz programming language, what Halo is doing is outside of it. He is hacking blitz internal structures using an external DLL.


Genexi2(Posted 2003) [#13]
Any chance your work here hackin' into Blitz could be screwed over in a new Blitz update Halo?


Bot Builder(Posted 2003) [#14]
Genexi2-

yep. the good thing is that it should be easy enough to be ok. jsut change the entity_radius_z position assuming it isn't used for somthing. Of course, there might be the problem of no free 4 byte spaces... hm. Better make sure mark keeps at least one.