Jump to content
  • Advertisement
Sign in to follow this  
3dcgmodeling

message based programming

This topic is 4260 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

many system use message to construct their system.for example windows or GUI of game.though several year programming experience ,but I do not see different between system that based message and system not. for exmaple: Wheneve you need do a thing ,(collision detection? show fx? launch bullet?) just sendMsg(); than it call msgProc(); msgProc() { msg1: handler1(); msg2: handler2(); msg3: handler3(); } but if you not use a message system, what you do is similar: wheneve you need do a thing ,just call function directly handler1(); handler2(); handler3(); so message system just use a function other than many funcion to do thing. what are different between them? it confuse me for many year.seek help.

Share this post


Link to post
Share on other sites
Advertisement
Thats the common (only?) way to do networking.

Everything is based off of packets, which are like messages.

Windows also has a message queue.. which you can do something similiar via WndProc

I think this is what you mean?

Share this post


Link to post
Share on other sites
Firstly, with a message system you probably dont have that type of code.
You probably have something with a:
RegisterHandler ( obj, ID, call_back );
TriggerMsg ( obj, ID, params );
WaitOnMsg ( obj, ID );


SO,

1) Since your process is message based, you can have either obj-local message processing/queing,
or a global system. With a global system you can achive effects similar to Stackless python.
The idea being that you only process objects with messages waiting, and everything else is in a sleeping queue.
When you get a message you wake up the object.

2) Since you have a message queue, you can choose to process only X events a frame to get a steady framerate.
And you can process all events at once, wich can be really good. i.e.:

loop_over_things
at step i, entity gives an ammo pack to his buddy(i+1),
so when the loop moves on, buddy has the ammo.

BUT if you do this:

loop_over_things
at step i, entity gives an ammo pack to his buddy[i-1],
it takes till the next frame for the buddy to have the ammo.

BUT if you do this:
Message Passing, then all decisions are made once, and all effects take place next time messages are handled.
If you dont let objects that get woken up get put into the current live queue untill this round of
processing is done, then buddy would always get the ammo next frame.
This may seem trivial, but if you aren't talking per-frame, but more per-simulation-cycle,
then it can be a huge difference in the outcome of your simulation.

3) You can do replays really easily, since all master messages could get saved, then by replaying those messages into the game,
you have a replay.

4) With an event handler/register thing, you can add functionality through scripting, since you can
expose the message system to your scripts, and then extend things by adding messages that corospond to
running other scripts.

There are probably a dozen other things you can do with a message passing system that would be hard with a functional system, but
I'm sure someone else can come around and point em out.

Share this post


Link to post
Share on other sites
KulSeran ,your reply is extremely helpful. thanks share your knoweledge. your reply is one of most value post in the gamedev.net. You should be the man to medal. :-)
KulSeran, I love to be your slave.

Share this post


Link to post
Share on other sites
Another useful thing that KulSeran mentioned, is that a Message based system can be quite handy for multiplayer gaming. Rather than passing around each player's input (a rather bad idea) you pass around messages saying that the player has moved. This frees up the server from doing all the processing, and allows a minimal amount of info to get passed, rather than sending everything across.

Mind you, this can also make cheating easier, but that is a different can of worms.

Share this post


Link to post
Share on other sites
A common use of message systems is when you don't know what is listening to the message and how it will react. E.g. in windows several message are generated on every key press. Any application can listen to the messages and act accordingly, even if the don't have focus.

This can be useful in game AI when each AI character is an object.
A character may generate a message like iNeedHelpAt(x,y). The message handlers would then pass the message onto all nearby characters. The receiving (if any) AI character/s would then decide what do based on its own states. Move towards message, move away from message, or even post its own message e.g. imOverThisWay(x,y).

Admin [HexAttack

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!