Was wondering is there a difference between :
entity THIS;
and
THIS = spawn ();
?
From what I have seen, you can assign THIS paramaters with just it being a global float, such as THIS = THAT; etc
....so I was believing merely floating it globally was like spawning it, but I guess spawn () means its now a dynamic entity and therefore can be removed?
Lets say we walked the ent list via prvm_edicts ....would we see the the global float listed or no? Is the flobal float considered a static ent? Id think no, because we can assign it paramaters via qc....
Entities
Re: Entities
you're confusing yourself now.
if 'entity this' was equivelent to 'this = spawn()' then all those statements that change self=foo all the time would require spawning new entities! expensive as heck, especially when you consider self.enemy.enemy.enemy.enemy.enemy...
all entity _variables_ are merely references to an entity object. uninitialised ones refer to the world (aka: worldspawn) entity.
thus 'entity this;' is generally equivelent to 'entity this = world;'
internally the vanilla engine has a pre-allocated array of entities.
your qc entity variables are actually an integer indexing into that array.
world is entity index 0, and thus uninitialised ents are equivelent to world.
if 'entity this' was equivelent to 'this = spawn()' then all those statements that change self=foo all the time would require spawning new entities! expensive as heck, especially when you consider self.enemy.enemy.enemy.enemy.enemy...
all entity _variables_ are merely references to an entity object. uninitialised ones refer to the world (aka: worldspawn) entity.
thus 'entity this;' is generally equivelent to 'entity this = world;'
internally the vanilla engine has a pre-allocated array of entities.
your qc entity variables are actually an integer indexing into that array.
world is entity index 0, and thus uninitialised ents are equivelent to world.
Re: Entities
Yep.....and the engine is NEVER confused unless we are firstSpike wrote:you're confusing yourself now.
By ' uninitialized ' I guess you are meaning no specifics have been assigned to it yet. Once you say, THIS = THAT; , now its no longer considered referenced to world, and is now ' initialized ' correct? Unless THAT happens to be world. Therefore THIS = spawn (), is considered an initialized entity, and NOT world, right?
Re: Entities
spawn allocates a new entity and returns a reference to that entity. one that isn't world.
Re: Entities
The entity data type stores addresses.
When you do
And when you do
All blank addresses references the world entity, which is iinitialized by the worldspawn function. So, if you do... the address stored in THAT variable is still the address of the world entity, because you're just copying a blank value. Nothing is being created.
When you do
... you're creating a blank entry to store an address.Cobalt wrote:entity THIS;
And when you do
... you're storing the address of a new entity into that entry.Cobalt wrote:THIS = spawn ();
All blank addresses references the world entity, which is iinitialized by the worldspawn function. So, if you do
Code: Select all
entity THIS, THAT;
THAT = THIS;
Re: Entities
There are different kinds of initializations.Cobalt wrote:Therefore THIS = spawn (), is considered an initialized entity, and NOT world, right?
THIS = spawn(); just means that THIS refers to a new entity. For the entity to react to physics, to .think functions, and to be visible to the clients, specific requirements must be initialized, such as .model (through setmodel() ), .solid and .movetype .
If you create a new entity variable, and allocate the address of a new entity into it but don't initialize it, you can use it just to store values. Spawnpoints are an example of that - they just hold the value of the angles and of the position where the player should be spawned into the game.
Re: Entities
Hmm interesting. Did some real tests with the Darkplaces engine.
entity THIS;
if (THIS == world)
eprint (THIS);
[ prints nothing , eprint ignored ]
Remove the ' if ' statement and you get:
server: FREE
Replace the ' if ' statement with :
THIS = spawn ();
and eprint returns.....
server EDICT 229:
So spawn () is giving it an edict number and no other paramaters. If its got an edict num != 0 its not world I believe.
So neither of these are technicly ' world ' , though I guess calling any .entity definitions for them would return world by default.
I was curious about this to solve an issue where the local spawn () entity would be removed, the next frame, but it was being carried to another function before that frame, yet the other function was still seeing it as a freed entity....and returning a world origin. Im guessing the only way to fix it is also put it in the global after the local is spawned, and use the global in the other function , rather than returning it as an entity (). Thanks people.
entity THIS;
if (THIS == world)
eprint (THIS);
[ prints nothing , eprint ignored ]
Remove the ' if ' statement and you get:
server: FREE
Replace the ' if ' statement with :
THIS = spawn ();
and eprint returns.....
server EDICT 229:
So spawn () is giving it an edict number and no other paramaters. If its got an edict num != 0 its not world I believe.
So neither of these are technicly ' world ' , though I guess calling any .entity definitions for them would return world by default.
I was curious about this to solve an issue where the local spawn () entity would be removed, the next frame, but it was being carried to another function before that frame, yet the other function was still seeing it as a freed entity....and returning a world origin. Im guessing the only way to fix it is also put it in the global after the local is spawned, and use the global in the other function , rather than returning it as an entity (). Thanks people.