Where is SimEvent::process() ?
by Tim "Zear" Hammock · in Torque Game Engine · 02/07/2002 (1:04 pm) · 6 replies
I'm doing a component that is somewhat animated (long story). Basically, I need to create events for the component from C++. I could set it up to go thru the scripting engine, but that seems back-a__ward to me.
So in tracing through the scheduling code, I see how events are added to the event queue and then triggered as they are stripped out in advanceTime(). The call to trigger is event->process(obj) where event is a SimEvent and obj is the SimObject that is going to receive the event.
Problem is, I can't seem to find the code where process() is implemented. Doh (I'm such an amateur). I see SimConsoleEvent::process(), but that results in console execution - not what I want (and it's a SimConsoleEvent - mebbe SimEvent is only actually implemented through that object? Nononono, please no). I would much rather send the event directly to the object.
Anybody know where SimEvent::process() is implemented? Or failing that, what mechanism transmits the event to the object? Or failing that an example of an object sheduling a message to itself and receiving the message (I know there HAS to be examples of that in the source, but darned if I can find a clear one)?
I'll keep looking, but I would love a pointer on this one.
So in tracing through the scheduling code, I see how events are added to the event queue and then triggered as they are stripped out in advanceTime(). The call to trigger is event->process(obj) where event is a SimEvent and obj is the SimObject that is going to receive the event.
Problem is, I can't seem to find the code where process() is implemented. Doh (I'm such an amateur). I see SimConsoleEvent::process(), but that results in console execution - not what I want (and it's a SimConsoleEvent - mebbe SimEvent is only actually implemented through that object? Nononono, please no). I would much rather send the event directly to the object.
Anybody know where SimEvent::process() is implemented? Or failing that, what mechanism transmits the event to the object? Or failing that an example of an object sheduling a message to itself and receiving the message (I know there HAS to be examples of that in the source, but darned if I can find a clear one)?
I'll keep looking, but I would love a pointer on this one.
#2
02/07/2002 (1:29 pm)
SimEvent is the base class for all specific event classes you create - basically it encapsulates the behavior "call me at some later time with a certain object as a parameter". So the idea is you subclass SimEvent and override process to do your special processing - for an example of this, check engine/game/net/serverQuery.cc - it has a bunch of SimEvent derivatives to handle pings, queries, heartbeat packets, etc.
#3
Thank you anyway.
02/07/2002 (1:33 pm)
Yeah I kinda figured that out (and from the object you mention as well). I wish I could delete the entire thread - I feel lame now. :)Thank you anyway.
#4
Here's what I have...
Created an event object:
Then the line 'Sim::postEvent(this, evt, 20);' produces the error
I know that GG staff is busy. For that matter everyone is, really. But if anyone can offer insight into what I'm doing wrong, or mebbe just a general sketch of how to get what I'm looking for, I would sincerely appreciate it.
02/08/2002 (11:31 am)
Yeesh. I'm starting to feel like a leech here, but can anyone offer further insight? I'm stuck.Here's what I have...
Created an event object:
class GuiActiveScreenEvent : public SimEvent
{
S32 tx;
S32 ty;
S32 tw;
S32 th;
public:
GuiActiveScreenEvent(S32 x, S32 y, S32 w, S32 h)
{
tx = x;
ty = y;
tw = w;
th = h;
}
void process(SimObject* obj)
{
((GuiActiveScreen*)obj)->handleEvent(tx, ty, tw, th);
}
};and I implemented GuiActiveScreen::handleEvent(). This compiles fine. Next, I need my object to be able to clear any existing events associated with it and insert a new event. I envisioned doing something likeSim::cancelPendingEvents(this); GuiActiveScreenEvent evt = GuiActiveScreenEvent(0,0,100,100); Sim::postEvent(this, evt, 20);but that fails miserably. The call to cancelPendingEvents() results in:
<blahblah>\guiActiveScreen.cc(127) : error C2039: 'cancelPendingEvents' : is not a member of 'Sim' <blahblah>\guiActiveScreen.cc(127) : error C2065: 'cancelPendingEvents' : undeclared identifierI looked at the implementation of cancelPendingEvents() in console\simManager.cc and I see
namespace Sim
{
...
static void cancelPendingEvents(SimObject *obj)
{
...and the only other place I see a call to that function uses the same syntax I used. I assume this is some bit of C++ wisdom I'm not privy to -- prolly related to the namespace. I'm stumped tho.Then the line 'Sim::postEvent(this, evt, 20);' produces the error
<blahblah>\guiActiveScreen.cc(130) : error C2665: 'postEvent' : none of the 3 overloads can convert parameter 2 from type 'class GuiActiveScreenEvent'I've no idea there. I will continue looking, but like I said, I think I may be missing something fundamental. I simply want to be able to queue up events for a GuiControl-derived class without going the ugly path of using console events - the point of writing this class was to avoid that overhead in the first place.
I know that GG staff is busy. For that matter everyone is, really. But if anyone can offer insight into what I'm doing wrong, or mebbe just a general sketch of how to get what I'm looking for, I would sincerely appreciate it.
#5
SimObject::unregisterObject()
{
...
Sim::cancelPendingEvents(this);
}
Just for reference a static function can only be called within the file itself, so only in the simManager can you call cancelPendingEvents(). So you could just create a function in simManager that is not static to call cancelPendingEvents()
02/08/2002 (3:30 pm)
It has to do with the fact that the function is static. The one place where the function is called is within the file on:SimObject::unregisterObject()
{
...
Sim::cancelPendingEvents(this);
}
Just for reference a static function can only be called within the file itself, so only in the simManager can you call cancelPendingEvents(). So you could just create a function in simManager that is not static to call cancelPendingEvents()
#6
02/08/2002 (4:22 pm)
I knew I was spending too much time on Java... (thank my employers, who had me doing Java _only_ for way too many years). Thanks. Now to figure out the other error.
Torque Owner Tim "Zear" Hammock
That being the case, I'll just make my own...