Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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


In reply to Re^4: How to share complex data structure in threads ? by exilepanda
in thread How to share complex data structure in threads ? by exilepanda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-03-28 15:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found