interaction system based on messages

G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

How to make a system of interaction between objects? I was thinking
about system based on messages (maybe windows-like?); after any action a
proper message is being sent to a global message queue, further all the
messages are processed, when the queue is empty time (?) is increased
(or other actions are performed). Examples of messages: MSG_MOVE,
MSG_EAT, MSG_POISON, MSG_...

Message processing function would send it to destination object, if the
object don't know how to handle the message, it is ignored.

What do you think about that? It looks quite flexible; how it is made in
other roguelikes?
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

I was contemplating a similar system, based on sensory information.
Each "message" has a type, strength, location, and duration, and
monsters/items/whatever could respond accordingly. Rather than have
destination objects, each object would sample the message queue for
detectable messages every turn, then the message queue would update
(remove old messages, change strength of other messages - smell wears
out after a while). Its something I want to try including in a future
release, but not my initial one.
 

Thomas

Distinguished
Jun 27, 2003
449
0
18,780
Archived from groups: rec.games.roguelike.development (More info?)

Chazm is using this system. I have a command object that handles all
commands in AnsiString form from the player or from the AI....

-Thomas
RL: CHAZM
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

At Thu, 11 Aug 2005 23:34:41 +0200,
Kolczuga wrote:

> How to make a system of interaction between objects? I was thinking
> about system based on messages (maybe windows-like?); after any action a
> proper message is being sent to a global message queue, further all the
> messages are processed, when the queue is empty time (?) is increased
> (or other actions are performed). Examples of messages: MSG_MOVE,
> MSG_EAT, MSG_POISON, MSG_...

> Message processing function would send it to destination object, if the
> object don't know how to handle the message, it is ignored.

> What do you think about that? It looks quite flexible; how it is made in
> other roguelikes?


What would you need uch a system for? Most roguelikes do the interaction
using roughly two functions, something like:

attack(attacker, attackee, attack)
magic(caster, target, spell)

You usually don't need more complicated messages -- combat events are
handled in 'push' style, most others, like spotting creatures and items,
are handled in 'pull' manner -- the creature just checks whether there are
any interestring things in it's vicinity.

Start playing with message passing and similar things and you soon find
yourself implementing an OO language on top of the labguage you're already
using.

In C, C++ and Java messages are method calls -- and that's it ;)
--
Radomir `The Sheep' Dopieralski @**@_
(--) 3 ..zzZZ
. . . ..v.vVvVVvVvv.v.. .
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

Kolczuga wrote:
> How to make a system of interaction between objects? I was thinking
> about system based on messages (maybe windows-like?); after any action a
> proper message is being sent to a global message queue, further all the
> messages are processed, when the queue is empty time (?) is increased
> (or other actions are performed). Examples of messages: MSG_MOVE,
> MSG_EAT, MSG_POISON, MSG_...
>
> Message processing function would send it to destination object, if the
> object don't know how to handle the message, it is ignored.

Obsever design pattern?

http://sern.ucalgary.ca/courses/SENG/609.04/W98/lamsh/observerLib.html

--
Rani Saarinen
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

jimrandomh wrote:
> No, it's actually not at all flexible. Because you have a global queue,
> there is some function somewhere which must understand every type of
> message. That precludes much of the encapsulation you'd otherwise want
> to do.

Im not QUITE sure what you're saying - either that you need a single
function that is able to undertand ALL messages, or you need a function
for each kind of message. Both of which, if the system is designed
correctly, is not needed.

You can have three classes:

An object class (which can be subdivided into a player class, monster
class, item class, door class, torch class, etc)
A message class (probably not subdivided, just have a generic class for
this)
A messaging system class

The system would work by having an object invoke a public function in
the message system to create a new message in the queue, and initialize
its data (such as what type of message it is, and the location of the
message). Each turn, all the objects query the queue for messages that
are within range.

The bigger problem is efficiency. Each object is going to go through
the entire list of messages every turn, and many objects will generate
one, if not several, messages. Including this system with a complex
FOV/LOS system would quickly bog down the game on all but the fastest
of the fastest machines.
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

Kolczuga <burakozol@wp.pl> wrote:
> How to make a system of interaction between objects? I was
> thinking about system based on messages (maybe windows-like?);
> after any action a proper message is being sent to a global
> message queue, further all the messages are processed, when the
> queue is empty time (?) is increased (or other actions are
> performed). Examples of messages: MSG_MOVE, MSG_EAT, MSG_POISON,
> MSG_...
>
> Message processing function would send it to destination object,
> if the object don't know how to handle the message, it is ignored.
>
> What do you think about that? It looks quite flexible; how it is
> made in other roguelikes?

No, it's actually not at all flexible. Because you have a global queue,
there is some function somewhere which must understand every type of
message. That precludes much of the encapsulation you'd otherwise want
to do.

--
CalcRogue: TI-89, TI-92+, PalmOS, Windows and Linux.
http://calcrogue.jimrandomh.org/
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

In article <Xns96B0ED563B9BAjimrandomh@207.69.189.191>,
jimrandomh <usenetNOSPAM@jimrandomh.org> wrote:
>Kolczuga <burakozol@wp.pl> wrote:
>> How to make a system of interaction between objects? I was
>> thinking about system based on messages (maybe windows-like?);
>> after any action a proper message is being sent to a global
>> message queue, further all the messages are processed, when the
>> queue is empty time (?) is increased (or other actions are
>> performed). Examples of messages: MSG_MOVE, MSG_EAT, MSG_POISON,
>> MSG_...
>>
>> Message processing function would send it to destination object,
>> if the object don't know how to handle the message, it is ignored.
>>
>> What do you think about that? It looks quite flexible; how it is
>> made in other roguelikes?
>
>No, it's actually not at all flexible. Because you have a global queue,
>there is some function somewhere which must understand every type of
>message. That precludes much of the encapsulation you'd otherwise want
>to do.

Why is that true? The only things the central message queue has to
understand are how to accept messages and then how to route them to the
appropriate recepient(s). It doesn't need to understand the meaning behind
the messages its sending.... I wouldn't think.

An analogy: The Win32 message queue doesn't know the difference between
WM_NCCALCSIZE and WM_CHAR, it just sends them to the right place. There is
special case handling for WM_PAINT, but that's more the exception than the
rule.

-Mike
--
http://www.mschaef.com
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

jimrandomh wrote:

> No, it's actually not at all flexible. Because you have a global queue,
> there is some function somewhere which must understand every type of
> message. That precludes much of the encapsulation you'd otherwise want
> to do.

Dude. Why do you have more than one type of message?

The messages he was talking about are simple, and can all have
the same declared type, probably either an int or a struct.

All the function that manages the global queue has to do, in
a simple implementation, is maintain a queue of 'em, hand
them out to the various other functions that ask for them
by value, and delete them when it's told to.

Alternatively, if you want to do it efficiently, the global
queue can just maintain a vector of function pointers and use
the message itself as an index to find the right function to
handle the message. So the only message it needs to understand
is the one that says, "register procedure FOO to handle messages
having value BAR," whereupon it stores a pointer to FOO in
handler_array[BAR]. Any other message it just looks up in
the handler array and calls the handler. Okay, some special
or default code to handle NULLs in the handler array, but no
major complications.

Bear