THANK YOU VERY VERY VERY MUCH Pope!! A very great lesson learned!
push @s, &share( { $cmd => time } }; ## The & before share() is import
+ant here; and one of the few times you should ever use it.
## or
push @s, &share_clone( { $cmd => time } };
## or
my %hash : shared = ( $cmd => time() );
push @s, \%hash;
my @array : shared;
$array[ 0 ] = 'fred'; ## ok
$array[ 1 ] = 12345; ## ok
$array[ 2 ] = [ 1,2,3 ] ## NOT OK
$array[ 2 ] = &share( [ 1,2,3 ] ); ## OK
$array[ 3 ] = { 'a'..'z' }; ## NOT OK
my %hash : shared = ( 'a' .. 'z' );
$array[ 3 ] = \%hash; ## OK
These examples explained everything that I was missing.
My real project is hard to explain, as the project scope is still defining, but from what I can understand, the structure is sound like a "online ARPG game".
So, there's a World Map, and there's monsters, and players.
$World = {
Players => [
"player1" => { # each key is a player id
ID=>"player1", HP=>9999, MP=>2000, coX=>0, coY=>0,
Equip => [ qw/xxxSword yyyShield/ ],
Magic => [ qw/Earthquake/ ],
Invent => { Cure => 1, Poison => 3 }
},
"playerx" => { ... }
],
Monsters=>{
MonsterA => [
"coX1-coY1", "coX2-coY2", ...
]
MonsterB => [
"coX1-coY1", "coX2-coY2", ...
]
}
};
So, whenever a player is connected, a new thread created, while everyone will access the same world map. When players walk, they may able to see monster or other players. and their coords changed, which should able to reflect to other players. And by certain time, killed monsters will reborn.
This is almost the case I am likely to face. Indeed, this is more safe in the "queue" approach, but on the other side, I believe I will create more bugs while coding as the full picture is harder to retrieve.
However one situation is true here which is fuzzy condition acceptable. Glitch from time race is acceptable in a certain amount of range.
Indeed, I still can't decide which approach is better for me
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.