Re: Modeling events that occur in a game world



On 22 Apr 2007 19:04:45 -0700, Aaron J. M. wrote:

On Apr 22, 12:29 pm, "Dmitry A. Kazakov" <mail...@xxxxxxxxxxxxxxxxx>
wrote:
Not necessarily. Others would sense the creature using their own sensors,
which might be less inaccurate than the self-feeling, or reverse. (What
irritates me in some RPGs is that when you do something, like stealing a
thing, all NPCs become instantly aware of your action. Why should they?)

Could you explain how these sensors would work/go? With the event model I've
been wrestling with above an AI would poll the event queue and pick an action
for its Creature depending on any events it had interest in.

The difference is that you attach the queue to the object. But in "reality"
objects don't communicate directly except than when they are talking to
each other, which is also an abstraction of some complex short-range
process. The objects communicate with the local environment. You already
have it in the form of the map where the objects are located. It is a form
of communication. I guess the objects will have get-my-X,Y,Z-co-ordinates
and set-my-X,Y,Z-co-ordinates. The first is "sensor", the second is
"actuator." You could implement the most of physics this way, by adding
forces applied at the position X,Y,Z, terrain constraints etc.

The Creature's
actions would generate more actions to go on the queue.

This has a problem of determining the queue into which the action need to
be placed. An object has to know too much about what it is going to do
that. This is why the event abstraction is not that good for more or less
elaborated physics. It would make the design of objects way too complex.
When an object is thrown, it is not a collaboration between it and the
thrower. It just flies, it need not to know what has thrown it. You could
still use it for higher-order things like speech, which are hard-wired
rather than simulated. I mean it is a trade-off, more complex your
simulation becomes, less the model of objects "talking" to each other pays
off.

Of course there has
to be a way of getting rid of old events that everyone has already seen before.

If you want broadcast events, then in your model you just put the event
into each and every queue. You don't need to get rid of it, it is the
problem of somebody who reads the queue out. You will need handles (smart
pointers) to the event parameters which aren't marshaled, to prevent them
from disappearing before the event gets dequeued. And you will have a hell
with race condition problems, which are typical for any event-based system.

An alternative design for broadcast / multicast events is the blackboard.
You put the event there and everybody scans the blackboard for the news.
The blackboard is a large ring buffer which gets overridden. Events in the
buffer have the sequence number so that the consumers can detect the last
event when they scan the buffer. This has less problems with non-marshaled
parameters, which live until the ring buffer overrun. But it consumes more
memory and race conditions are all yours anyway.

As for the thievery example, I'd add a line-of-sight check to eliminate any
omniscience. ;)

I.e. you will need to filter the events.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
.



Relevant Pages

  • Re: [take25 1/6] kevent: Description.
    ... To ensure every connection is handled as quickly as possible you stuff them all in the same queue and then have all threads use this one queue. ... In nscd, for instance, we have one single thread waiting for incoming connections and it then has to wake up a worker thread to handle the processing. ... With the new event handling this wouldn't be the case, one thread only is woken and we don't have to wake worker threads. ... I think I already gave my opinion on a ring buffer, ...
    (Linux-Kernel)
  • Re: [take19 1/4] kevent: Core files.
    ... the queue when it's copy was in mapped buffer, ... ring buffer entry, so when event is removed from the ready queue (using ... Be able to syscall and wait for an event. ...
    (Linux-Kernel)
  • Re: Dumb RTOS Question
    ... shows up in the queue. ... an option to work like a ring buffer but that does not seem to be the ... and I'm thinking that you need to go digging for a basic tutorial on using an RTOS. ... using a queue here -- just set a semaphore from your timer ...
    (comp.arch.embedded)
  • Re: [take19 1/4] kevent: Core files.
    ... queue when it's copy was in mapped buffer, but in that case it's user's ... buffer entry, so when event is removed from the ready queue (using ... appropriate entry in the ring buffer will be ... Be able to syscall and wait for an event. ...
    (Linux-Kernel)
  • Re: How to send a var to stdin of an external software
    ... Race condition. ... myVar = str) # arbitrary test data. ... Could you explain me why you use a queue instead of a simple array for getting the piped var? ... At that point in the program, we had already waited for cat to ...
    (comp.lang.python)