#551 posted by necros on 2011/04/25 01:20:10
thanks, i hadn't thought about the 'premature triggering'. yeah, a proxy looks like the best bet.
when i needed a walkmove check to move through monsters, i just set all monsters to non-solid. :P
#552 posted by necros on 2011/04/25 01:20:43
or a flag on the entity you toggle on temporarily that you code into all triggers 'don't activate when this flag is on'.
Addendum
#553 posted by Preach on 2011/04/25 01:25:44
The takehome message of the last post is:
During a walkmove or movetogoal the monster will only collide with SOLID_TRIGGER entities.
I want to add that only the trigger's touch function is activated, the engine does not call the monster's touch function with the trigger as other.
In Error
#554 posted by Preach on 2011/05/01 22:59:30
So I adapted the code which I wrote last week answer that question about movetogoal. It turns out that even through touch functions, it restores the QC state correctly and doesn't overwrite self. This is admittedly run from a think function - it's possible that you could create a more complex scenario like calling movetogoal from a touch function and then causing another touch function.
But I thought I'd share it with you because it made me practice a few diagnostic tools for QC, some of which you may not be aware of.
The first is just chucking in a load of dprint statements, I'm sure most people have done that before. Don't forget that you can use ftos() and vtos() to put more information into the statements. If you need to confirm the value of an entity variable (as I wanted to with self) you can use the eprint() function instead.
The second tool is a bit of a hack. It allows you to get a stack trace. This was particularly valuable in this case because of the concern that the touch function might be trashing the stack. But it would be of use in any case where you have an interaction between think and touch functions causing a bug, and you want to know what is calling what.
There's no command or QC builtin for a stack trace, but you get one if you manage to perform an invalid operation in QC. The infinite loop is one way to do this, but personally I prefer the null function call, it's a bit quicker. Just throw something like
world.think1();
and unless the map is particularly weird you'll get your error. Of course, this does shut down the entire server, so it's not for general use.
The last trick is pretty powerful but also has the potential to spam the entire console out. The QC builtins traceon() and traceoff() allow you to enable console output of every Qasm instruction that the server reads - including the register values that were employed.
I believe Qasm is a neologism, and if so I demand it be pronounced as "chasm". It refers to the bytecode that a QC compiler creates - effectively Quake Assembly code. You can use one of the options in FTEQCC to output the assembly to a file, which is a good way to learn what the trace output means.
(As an aside FTEQCC also lets you enter segments entirely in Qasm. This is in the same way as c compilers accept asm segments - and indeed the original quake engine did just that in the renderer to get tight loops fast enough for the Pentium 75s to run the game. I believe most modern ports strip the assembly out. Even so, in quake Qasm is a great way to do naughty things that the compiler won't let you...)
Are You Sure?
#555 posted by necros on 2011/05/02 00:29:27
because i distinctly remember after putting in the self restoration bit that it fixed a problem with walkmoves not being called after movetogoal.
Yeah
#556 posted by Preach on 2011/05/02 01:06:07
We might have to share some code here to determine why we're getting different results. If you whack an eprint(self) in before you restore self do you get the trigger entity that you touched come up?
Heh
#557 posted by necros on 2011/05/02 02:37:38
yeah, i guess i could have at least tried it out to see.
you're right, self isn't being lost when touching triggers. trying to figure out now would be pointless though, because the code has change by a huge amount since last time i posted about it.
SV_TouchLinks: Next != L->next
#558 posted by necros on 2011/05/08 20:20:10
is it bad to call setorigin(self) in a touch function? does that cause the touchlinks warning in fitz?
i googled the forums, but i don't think it was ever really explained what this error is, only that it used to crash in e2m2.
Potentially
#559 posted by Preach on 2011/05/09 00:29:39
I'm not brilliant at following how the engine handles this touch stuff, but here goes:
The following functions could cause problems with sv_touchlinks:
setorigin
setsize
droptofloor
movetogoal
walkmove
All these functions can cause the entity to be relinked, which potentially causes the issue. There are some other conditions that need to be met before the error is encountered: firstly the entity has to be part of the same areanode as the touch is coming from*. My understanding is that there are 32 areanodes in a map to reduce the number of entities considered in the collision code by approx. that factor.
The other important thing is that the entity has to actually break the chain of linked entities at exactly the point that sv_touchlinks is operating. I believe that this translates to applying any of the dangerous functions to other, but again not too sure how all the code fits together.
A final small point is that even if do apply one of the dangerous functions to other (and since we're in a touch function with other it's safe to assume by now that they share an areanode) we might still get away with it. This case would occur when other is the first entity in the areanode - relinking it will reinsert it in the same place as before. There's no safe way to exploit this though, as it's determined entirely engine-side.
The last thing to remember is that sv_touchlinks only looks through the list of triggers, so anything that's not SOLID_TRIGGER* ought to be safe. Best of luck!
*Technically that should read "that wasn't SOLID_TRIGGER last time the entity got linked into the world" but that's a bit of a mouthful. All that means is that you can't quickly set the entity to SOLID_NOT and get away with anything, it's about whether the entity is truly a trigger according to the engine at that time...
Footnote
#560 posted by Preach on 2011/05/09 00:31:10
That first asterisk should have been removed, the footnote is about the SOLID_TRIGGER statement - though most of you spotted that anyway I expect...
#561 posted by necros on 2011/05/09 00:54:07
yeah, this is happening with some of my code. unfortunately, i have the report from a third party and haven't been able to reproduce it myself. apparently, occasionally, it spams the console with sv_touchlinks errors in fitz085.
i noticed this tiny comment in defs.qc for setmodel:
void(entity e, string m) setmodel = #3; // set movetype and solid first
and i checked that entity and found that i was setting self.model before movetype. so i fixed that anyway, but maybe that might also have been the problem? the entity wasn't properly linked in the first place?
geez, i dunno. :P
it's supposed to be a visible solid_trigger entity that changes origin when you touch it.
i was wondering, maybe if i used to bad method of just setting self.origin in the touch function, that way, it's not breaking whatever links?
Danger
#562 posted by Preach on 2011/05/09 09:11:32
From what I've gleaned, that is the most dangerous thing you could do in a touch function, although I didn't post it correctly. I was talking about the danger of moving other, but I should have been talking about self. I had the two muddled up and I'm sorry about that.
The standard way to cope with this is to set up a quick think function from the touch function, and have that think reset the origin. You can put a guard into the touch function to prevent multiple touches before it moves - set up a flag on the entity and toggle it in the touch and think.
Hm Ok
#563 posted by necros on 2011/05/09 20:57:07
so what i can do is just set a flag after the touch function to disallow further touches until the think function has been run. that should work i guess. a little roundabout but last thing i want to do is start causing crashes. :P
Speed-up
#564 posted by Preach on 2011/05/09 22:19:31
You can also use a little trick to make sure the think function runs as soon as possible (either this frame or the next). Just set self.nextthink = 0.05; - note that we are deliberately omitting time from the assignment. Since this will be in the past for every frame the engine runs (frame 1 runs at time = 0.1) it will execute the think as soon as the entity is checked by the engine.
The flag works a bit like the way that
if (self.nextthink > time) line works for a trigger_multiple, so if you don't want to use another field that approach is an option. My feeling is that the flag is simpler because you don't need the flexibility of a custom delay but it's basically a preference thing.
Spot The Deliberate Mistake?
#565 posted by Lardarse on 2011/05/10 19:59:18
(frame 1 runs at time = 0.1)
Time starts at 1, not 0. This is one of the quirks of the system, that makes very little difference, except for when it trips you up (and when it does, it hurts). For example (from the id1 code):
self.nextthink = self.nextthink + random()*0.5;
This line appears in all of the $foomonster_start functions. The original intention was for monsters to not all do their setup on the same frame, to reduce computer load. However, what actually happens, is that on a roughly 1 in 32000 chance (or, according to LordHavoc, 1 in 2 billion on Linux), self.nextthink is set to 0, which means that it never thinks again (as .nextthink is set to 0 before the think function is called), and the rest of the time, it happens on the next frame.
Thinking About The Other One
#566 posted by Lardarse on 2011/05/10 20:00:41
When a think function is being called, what is other set to? Does it get set to something predictable, or is it just left as whatever it was last time?
#567 posted by necros on 2011/05/10 20:30:38
so that bit of code doesn't actually do anything then?
might be a good idea to change to it 1 + random() * 0.5 then? because that must mean thinks are being all processed on the same frame.
also, on other, a few think functions steal other for their own uses so even if it is being reset every frame, you might get a semi-random entity if one of those thinks happened during the frame?
I'd Say
(1 + random()) * 0.5
#569 posted by necros on 2011/05/10 22:09:03
won't that still generate nextthinks < 1?
Depends
Is nextthink a float or an int, and how do conversions work in QC? If it is like in C, then yeah. I just thought it's closer to the original, but heh we don't really want that.
<1
#571 posted by Preach on 2011/05/10 22:42:23
It's ok to generate thinks which are less than 1 in this case, because as long as it's non-zero the think function will run, and you'll still spread the monsters out over many frames because not all of them are going to get the same random number.
And if they did, they'd all be set off on the same frame no matter what function you did...
Good catch on the server starting at 1 there though, I must remember that. Either way, as long as you don't set nextthink to 0, any value less than 1 will give you the soonest think function possible.
However
#572 posted by Lardarse on 2011/05/11 00:41:39
any value less than time will give you the soonest think function possible
As Spike has pointed out a few times, when a think function is called, for that dive into the code only, time is set to what .nextthink was before being reset. So the most reliable way for a "do this next frame" is probably self.nextthink = time;
Well
#573 posted by Preach on 2011/05/11 00:52:53
Only if your code depends on the value of time in some way. If all you need is for it to run in the next server frame then you can take the shortcut. If time cannot every be less than 1 then a value less than 1 is always less than time...
#574 posted by necros on 2011/05/11 01:27:20
i think it's more about successive thinks.
the less aligned monster thinks are, the less impact the ai routine has when it's run, i would think.
if you just set nextthink to 1, every monster will be thinking at the same time.
Shadow Casting Bmodels
#575 posted by necros on 2011/05/14 23:03:56
could someone modify MH's Aguirre's light utility so that it casts shadows from bmodels?
and maybe a new key '_noshadows' to disable shadows on that particular bmodel?
or is it not possible? like bmodels can't be used for some reason?
|