Inside3D!
     

Detecting removed entities

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
frag.machine



Joined: 25 Nov 2006
Posts: 728

PostPosted: Sun Feb 21, 2010 12:10 pm    Post subject: Detecting removed entities Reply with quote

Is there a quick, fail-safe way to do this ? I have entities that keeps references to other entities which may be removed between execution cycles (touched items, killed monsters, etc). At this moment I am resorting to intercept all calls to remove() and assigning string_null to classname before actually calling the built-in function (so my entity can check if it's reference stills valid), but this is awkward.

EDIT: Actually, if there's no way in standard QuakeC to verify if an entity stills valid, it would be a worthy addition to QSB 1.0 wish list.
_________________
frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/
Back to top
View user's profile Send private message Visit poster's website
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Sun Feb 21, 2010 1:00 pm    Post subject: Reply with quote

csqc specifies a builtin that can do it :)

you shouldn't really be poking an entity that has been freed, you ought to have removed all links to it before freeing.

that said, an entity will not be reused during the same qc invocation, and it can be useful to see if a called function removed it (like a touch, hence why the builtin in csqc).
The standard remove builtin does clear out some fields, including:
model
takedamage
modelindex
colormap
skin
frame
origin
angles
nextthink
solid

Actually, when I say clear, I partly lie. nextthink is not cleared. Interestingly, it is set to -1. Spawn then clears the entire entity to 0, resetting nextthink to 0 also.
So you can test nextthink==-1 to see if an entity is freed.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
frag.machine



Joined: 25 Nov 2006
Posts: 728

PostPosted: Sun Feb 21, 2010 2:40 pm    Post subject: Reply with quote

Well, since my code is part of server-side AI, CSQC won't help me on that Smile

Ah well, guess I'll keep my classname clearing code, then Rolling Eyes . Thanks for the info, Spike.
_________________
frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/
Back to top
View user's profile Send private message Visit poster's website
Sajt



Joined: 16 Oct 2004
Posts: 1026

PostPosted: Sun Feb 21, 2010 7:40 pm    Post subject: Reply with quote

This classname clearing idea is clever but I don't know if it's portable. A "good" VM (DarkPlaces might do this?) wouldn't let you access entities marked for removal at all. Have you tested your code with DarkPlaces?
_________________
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Back to top
View user's profile Send private message
Teiman



Joined: 03 Jun 2007
Posts: 309

PostPosted: Sun Feb 21, 2010 9:39 pm    Post subject: Re: Detecting removed entities Reply with quote

frag.machine wrote:
Is there a quick, fail-safe way to do this ? I have entities that keeps references to other entities which may be removed between execution cycles (touched items, killed monsters, etc). At this moment I am resorting to intercept all calls to remove() and assigning string_null to classname before actually calling the built-in function (so my entity can check if it's reference stills valid), but this is awkward.

EDIT: Actually, if there's no way in standard QuakeC to verify if an entity stills valid, it would be a worthy addition to QSB 1.0 wish list.


you can have your own remove() func that set .isRemoved = 1;


pseudocode follows:

void( entity ent) remove =
{

ent.isRemoved = 1;

buitin_remove( ent );

}
Back to top
View user's profile Send private message
frag.machine



Joined: 25 Nov 2006
Posts: 728

PostPosted: Sun Feb 21, 2010 11:41 pm    Post subject: Reply with quote

Sajt wrote:
This classname clearing idea is clever but I don't know if it's portable. A "good" VM (DarkPlaces might do this?) wouldn't let you access entities marked for removal at all. Have you tested your code with DarkPlaces?


Nope, tested only in FitzQuake 0.85, seems to work OK.
But I agree, a "good" VM shouldn't allow me to refer discarded entities. OTOH, a "good" VM should also supply me some secure way to test if an entity reference stills valid (for example, a builtin). That's why I mentioned adding this to QSB 1.0 wish list (it's simple to implement and really useful for QC coders).

@Teiman: what I did was almost like what you suggested, only without the extra field. I assumed that any active entity should have at least the .classname set:
Code:

void(entity e) _remove                          = #15;
void(entity e) remove =
{
    e.classname = string_null;
    _remove (e);
};

_________________
frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/
Back to top
View user's profile Send private message Visit poster's website
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Sun Feb 21, 2010 11:44 pm    Post subject: Reply with quote

too many mods reference dead entities one way or another. a generic engine could never do it.
I had a warning about it in FTE a while back, but it was just too spammy.
Its not a problem so long as its the same frame in which they were removed.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Sajt



Joined: 16 Oct 2004
Posts: 1026

PostPosted: Mon Feb 22, 2010 7:20 am    Post subject: Reply with quote

Ah, I forgot about that most fun part of Quake engine coding. (Badly coded mods from 1997.)

Anyway, the "good" VM (no longer talking about Quake) would clear all your references to null automatically, because a good VM should never let you get garbage...
_________________
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group