Guest User

Untitled

a guest
Feb 2nd, 2012
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 20.26 KB | None | 0 0
  1. #include "ClientMapManagement.h"
  2.  
  3. ClientMapManagement::ClientMapManagement()
  4. {
  5.     current_map=NULL;
  6.     stopIt=false;
  7.     basePath=QCoreApplication::applicationDirPath()+"/datapack/map/tmx/";
  8. }
  9.  
  10. ClientMapManagement::~ClientMapManagement()
  11. {
  12.     stopIt=true;
  13.     QMutexLocker lock(&mutex);
  14.     wait_the_end.acquire();
  15. }
  16.  
  17. void ClientMapManagement::setBasePath(const QString &basePath)
  18. {
  19.     this->basePath=basePath;
  20. }
  21.  
  22. void ClientMapManagement::stop()
  23. {
  24.     stopIt=true;
  25. }
  26.  
  27. Map_player_info ClientMapManagement::getMapPlayerInfo()
  28. {
  29.     Map_player_info temp;
  30.     if(current_map==NULL)
  31.         temp.loaded=false;
  32.     else
  33.     {
  34.         temp.map        = current_map->map_final;
  35.         temp.map_file_path  = current_map->mapName();
  36.         temp.x          = x;
  37.         temp.y          = y;
  38.         temp.loaded     = true;
  39.     }
  40.     return temp;
  41. }
  42.  
  43. void ClientMapManagement::setVariable(QList<Map_custom *> *map_list,EventThreader* map_loader_thread)
  44. {
  45.     this->map_loader_thread=map_loader_thread;
  46.     this->map_list=map_list;
  47. }
  48.  
  49. void ClientMapManagement::askIfIsReadyToStop()
  50. {
  51.     stopIt=true;
  52.     QMutexLocker lock(&mutex);
  53.     wait_the_end.release();
  54.     if(current_map==NULL)
  55.     {
  56.         emit isReadyToStop();
  57.         return;
  58.     }
  59.     unloadFromCurrentMap();
  60.     to_send_map_management_insert.clear();
  61.     to_send_map_management_move.clear();
  62.     to_send_map_management_remove.clear();
  63.     //virtual stop the player
  64.     if(last_direction>4)
  65.         last_direction=Direction((quint8)last_direction-4);
  66.     Orientation orientation=(Orientation)last_direction;
  67.     if(current_map->mapName()!=at_start_map_name || x!=at_start_x || y!=at_start_y || orientation!=at_start_orientation)
  68.     {
  69.         emit updatePlayerPosition(current_map->mapName(),x,y,orientation);
  70.         #ifdef DEBUG_MESSAGE_CLIENT_MOVE
  71.         DebugClass::debugConsole(
  72.                     QString("current_map->mapName(): %1,x: %2,y: %3, orientation: %4")
  73.                     .arg(current_map->mapName())
  74.                     .arg(x)
  75.                     .arg(y)
  76.                     .arg(orientation)
  77.                     );
  78.         #endif
  79.     }
  80.     unloadMapIfNeeded(current_map);
  81.     current_map=NULL;
  82.     emit isReadyToStop();
  83. }
  84.  
  85. void ClientMapManagement::unloadFromCurrentMap()
  86. {
  87.     //remove player to current map
  88.     if(current_map->clients.removeAll(this)!=1)
  89.     //if(!current_map->clients.removeOne(this))
  90.     {
  91.         emit message("unable to remove the player from the map");
  92.         return;
  93.     }
  94.     //tell at all other client the disconnect of this
  95.     if(current_map->map_loaded)
  96.     {
  97.         int index_maps_clients=0;
  98.         QList<ClientMapManagement *> client_near=current_map->clients;
  99.         int list_size_maps_clients=client_near.size();
  100.         while(index_maps_clients<list_size_maps_clients)
  101.         {
  102.             client_near.at(index_maps_clients)->removeClient(player_id);
  103.             index_maps_clients++;
  104.         }
  105.     }
  106. }
  107.  
  108. void ClientMapManagement::unloadMapIfNeeded(Map_custom * map)
  109. {
  110.     //not more client, can unload the map
  111.     if(map->clients.size()==0)
  112.     {
  113.         map_list->removeOne(map);
  114.         /// \note auto unregistred on other map by destructor
  115.         delete map;
  116.     }
  117. }
  118.  
  119. void ClientMapManagement::put_on_the_map(const quint32 &player_id,const QString & map,const quint16 &x,const quint16 &y,const Orientation &orientation)
  120. {
  121.     have_diff=false;
  122.     at_start_x=x;
  123.     at_start_y=y;
  124.     at_start_orientation=orientation;
  125.     last_direction=(Direction)orientation;
  126.     at_start_map_name=map;
  127.     this->player_id=player_id;
  128.     this->x=x;
  129.     this->y=y;
  130.     current_map=getMap(map);
  131.     current_map->clients << this;
  132.     propagate();
  133. }
  134.  
  135. void ClientMapManagement::put_on_the_map_by_diff(const QString & map,const quint16 &x,const quint16 &y)
  136. {
  137.     DebugClass::debugConsole(QString("try load map by diff for for player: %1").arg(player_id));
  138.     have_diff=true;
  139.     this->x=x;
  140.     this->y=y;
  141.     current_map=getMap(map);
  142.     current_map->clients << this;
  143.     propagate();
  144.     //set to 0 or map max size
  145.     //moveThePlayer() to check colision and do real move
  146. }
  147.  
  148. void ClientMapManagement::propagate()
  149. {
  150.     if(current_map==NULL)
  151.     {
  152.         DebugClass::debugConsole(QString("current_map==NULL and should not: %1").arg(player_id));
  153.         return;
  154.     }
  155.     if(current_map->map_loaded)
  156.     {
  157.         if(have_diff)
  158.         {
  159.             have_diff=false;
  160.             switch(last_direction)
  161.             {
  162.                 case 0x05:
  163.                     y+=0;//useless but it's y=0 + offset stored into y
  164.                 break;
  165.                 case 0x06:
  166.                     x+=0;//useless but it's x=0 + offset stored into x
  167.                 break;
  168.                 case 0x07:
  169.                     y+=current_map->height;//it's y=height + offset stored into y, then y=y+height
  170.                 break;
  171.                 case 0x08:
  172.                     x+=current_map->height;//it's x=height + offset stored into x, then x=x+height
  173.                 break;
  174.                 default:
  175.                 break;
  176.             }
  177.         }
  178.         else
  179.         {
  180.             current_map->check_client_position(current_map->clients.size()-1);
  181.             int index_maps_clients=0;
  182.             int list_size_map_custom=current_map->clients.size();
  183.             while(index_maps_clients<list_size_map_custom)
  184.             {
  185.                 ClientMapManagement *other_client=current_map->clients.at(index_maps_clients);
  186.                 if(other_client!=this)
  187.                     other_client->insertClient(player_id,current_map->mapName(),x,y,last_direction);
  188.                 insertClient(other_client->player_id,
  189.                          other_client->current_map->mapName(),
  190.                          other_client->x,
  191.                          other_client->y,
  192.                          other_client->last_direction);
  193.                 index_maps_clients++;
  194.             }
  195.         }
  196.     }
  197. }
  198.  
  199. QList<ClientMapManagement *> ClientMapManagement::preMapMove()
  200. {
  201.     QList<ClientMapManagement *> previousClient;
  202.     if(stopIt)
  203.         return previousClient;
  204.     getNearClient(previousClient);
  205.     unloadFromCurrentMap();
  206.     old_map=current_map;
  207.     return previousClient;
  208. }
  209.  
  210. void ClientMapManagement::postMapMove(const QList<ClientMapManagement *> &previousClient,const quint8 &previousMovedUnit,const Direction &direction)
  211. {
  212.     if(stopIt)
  213.         return;
  214.     postMapMove_nextClient.clear();
  215.     getNearClient(postMapMove_nextClient);
  216.     #ifdef DEBUG_MESSAGE_CLIENT_COMPLEXITY_LINEARE
  217.     emit message(QString("postMapMove start: %1, getNearClient: %2, previousClient: %3").arg(player_id).arg(postMapMove_nextClient.size()).arg(previousClient.size()));
  218.     #endif // DEBUG_MESSAGE_CLIENT_COMPLEXITY_LINEARE
  219.     index=0;
  220.     list_size=previousClient.size();
  221.     while(index<list_size)
  222.     {
  223.         if(postMapMove_nextClient.contains(previousClient.at(index)))
  224.         {
  225.             previousClient.at(index)->moveClient(player_id,previousMovedUnit,direction);
  226.             postMapMove_nextClient.removeOne(previousClient.at(index));
  227.         }
  228.         else
  229.             previousClient.at(index)->removeClient(player_id);
  230.         index++;
  231.     }
  232.     postMapMove_size=postMapMove_nextClient.size();
  233.     while(postMapMove_size>0)
  234.     {
  235.         postMapMove_nextClient.first()->insertClient(player_id,current_map->mapName(),x,y,(Direction)direction);
  236.         postMapMove_nextClient.removeFirst();
  237.         postMapMove_size--;
  238.     }
  239.     unloadMapIfNeeded(old_map);
  240.     return;
  241. }
  242.  
  243. /// \note The second heavy function
  244. void ClientMapManagement::moveThePlayer(const quint8 &previousMovedUnit,const Direction &direction)
  245. {
  246.     if(stopIt)
  247.         return;
  248.     if(current_map==NULL)
  249.     {
  250.         emit message(QString("internal error, map pointer == NULL, for player: %1").arg(player_id));
  251.         return;
  252.     }
  253.     if(current_map->map_loaded)
  254.     {
  255.         #ifdef DEBUG_MESSAGE_CLIENT_COMPLEXITY_SQUARE
  256.         emit message(QString("for player (%1,%2): %3, previousMovedUnit: %4, direction: %5").arg(x).arg(y).arg(player_id).arg(previousMovedUnit).arg(Map_custom::directionToString((Direction)direction)));
  257.         #endif
  258.         moveThePlayer_index_move=0;
  259.         switch(last_direction)
  260.         {
  261.             case Direction_move_at_top:
  262.                 if(previousMovedUnit==0)
  263.                     emit error(QString("Previous action is moving: %1").arg(last_direction));
  264.                 while(moveThePlayer_index_move<previousMovedUnit)
  265.                 {
  266.                     if(0==y)
  267.                     {
  268.                         if(current_map->map_border_top.fileName.isEmpty())
  269.                             emit error(QString("moveThePlayer(), out of map: %1, file name: \"%2\"").arg(current_map->mapName()).arg(current_map->map_border_top.fileName));
  270.                         else
  271.                         {
  272.                             QList<ClientMapManagement *> previousClient=preMapMove();
  273.                             put_on_the_map_by_diff(current_map->map_border_top.fileName,current_map->map_border_top.x_offset+x,-(previousMovedUnit-moveThePlayer_index_move));
  274.                             postMapMove(previousClient,previousMovedUnit,direction);
  275.                         }
  276.                         return;
  277.                     }
  278.                     y--;
  279.                     if(!current_map->is_walkalble(x,y))
  280.                     {
  281.                         emit error(QString("move at top, can wall at: %1,%2 on map: %3").arg(x).arg(y).arg(current_map->mapName()));
  282.                         return;
  283.                     }
  284.                     moveThePlayer_index_move++;
  285.                 }
  286.             break;
  287.             case Direction_look_at_top:
  288.                 if(previousMovedUnit>0)
  289.                     emit error(QString("Previous action is not moving: %1").arg(last_direction));
  290.             break;
  291.             case Direction_move_at_right:
  292.                 if(previousMovedUnit==0)
  293.                     emit error(QString("Previous action is moving: %1").arg(last_direction));
  294.                 while(moveThePlayer_index_move<previousMovedUnit)
  295.                 {
  296.                     if(current_map->width==x)
  297.                     {
  298.                         if(current_map->map_border_right.fileName.isEmpty())
  299.                             emit error(QString("moveThePlayer(): move at right, out of map: %1, file name: \"%2\"").arg(current_map->mapName()).arg(current_map->map_border_right.fileName));
  300.                         else
  301.                         {
  302.                             QList<ClientMapManagement *> previousClient=preMapMove();
  303.                             put_on_the_map_by_diff(current_map->map_border_right.fileName,current_map->map_border_right.y_offset+y,(previousMovedUnit-moveThePlayer_index_move));
  304.                             postMapMove(previousClient,previousMovedUnit,direction);
  305.                         }
  306.                         return;
  307.                     }
  308.                     x++;
  309.                     if(!current_map->is_walkalble(x,y))
  310.                     {
  311.                         emit error(QString("move at right, can wall at: %1,%2 on map: %3").arg(x).arg(y).arg(current_map->mapName()));
  312.                         return;
  313.                     }
  314.                     moveThePlayer_index_move++;
  315.                 }
  316.             break;
  317.             case Direction_look_at_right:
  318.                 if(previousMovedUnit>0)
  319.                     emit error(QString("Previous action is not moving: %1").arg(last_direction));
  320.             break;
  321.             case Direction_move_at_bottom:
  322.                 if(previousMovedUnit==0)
  323.                     emit error(QString("Previous action is moving: %1").arg(last_direction));
  324.                 while(moveThePlayer_index_move<previousMovedUnit)
  325.                 {
  326.                     if(current_map->height==y)
  327.                     {
  328.                         if(current_map->map_border_bottom.fileName.isEmpty())
  329.                             emit error(QString("moveThePlayer(): move at bottom, out of map: %1, file name: \"%2\"").arg(current_map->mapName()).arg(current_map->map_border_bottom.fileName));
  330.                         else
  331.                         {
  332.                             QList<ClientMapManagement *> previousClient=preMapMove();
  333.                             put_on_the_map_by_diff(current_map->map_border_bottom.fileName,current_map->map_border_bottom.x_offset+x,(previousMovedUnit-moveThePlayer_index_move));
  334.                             postMapMove(previousClient,previousMovedUnit,direction);
  335.                         }
  336.                         return;
  337.                     }
  338.                     y++;
  339.                     if(!current_map->is_walkalble(x,y))
  340.                     {
  341.                         emit error(QString("move at bottom, can wall at: %1,%2 on map: %3").arg(x).arg(y).arg(current_map->mapName()));
  342.                         return;
  343.                     }
  344.                     moveThePlayer_index_move++;
  345.                 }
  346.             break;
  347.             case Direction_look_at_bottom:
  348.                 if(previousMovedUnit>0)
  349.                     emit error(QString("Previous action is not moving: %1").arg(last_direction));
  350.             break;
  351.             case Direction_move_at_left:
  352.                 if(previousMovedUnit==0)
  353.                     emit error(QString("Previous action is moving: %1").arg(last_direction));
  354.                 while(moveThePlayer_index_move<previousMovedUnit)
  355.                 {
  356.                     if(0==x)
  357.                     {
  358.                         if(current_map->map_border_left.fileName.isEmpty())
  359.                             emit error(QString("moveThePlayer(): move at left, out of map: %1, file name: \"%2\"").arg(current_map->mapName()).arg(current_map->map_border_left.fileName));
  360.                         else
  361.                         {
  362.                             QList<ClientMapManagement *> previousClient=preMapMove();
  363.                             put_on_the_map_by_diff(current_map->map_border_left.fileName,current_map->map_border_left.y_offset+y,-(previousMovedUnit-moveThePlayer_index_move));
  364.                             postMapMove(previousClient,previousMovedUnit,direction);
  365.                         }
  366.                         return;
  367.                     }
  368.                     x--;
  369.                     if(!current_map->is_walkalble(x,y))
  370.                     {
  371.                         emit error(QString("can wall at: %1,%2 on map: %3").arg(x).arg(y).arg(current_map->mapName()));
  372.                         return;
  373.                     }
  374.                     moveThePlayer_index_move++;
  375.                 }
  376.             break;
  377.             case Direction_look_at_left:
  378.                 if(previousMovedUnit>0)
  379.                     emit error(QString("Previous action is not moving: %1").arg(last_direction));
  380.             break;
  381.             default:
  382.             break;
  383.         }
  384.         moveThePlayer_returnList.clear();
  385.         getNearClient(moveThePlayer_returnList);
  386.         moveThePlayer_index=0;
  387.         moveThePlayer_list_size=moveThePlayer_returnList.size();
  388.         while(moveThePlayer_index<moveThePlayer_list_size)
  389.         {
  390.             moveThePlayer_returnList[moveThePlayer_index]->moveClient(player_id,previousMovedUnit,(Direction)direction);
  391.             moveThePlayer_index++;
  392.         }
  393.         last_direction=(Direction)direction;
  394.         #ifdef DEBUG_MESSAGE_CLIENT_MOVE
  395.         emit message(QString("after %4: (%1,%2): %3, send at %5 player(s)").arg(x).arg(y).arg(player_id).arg(Map_custom::directionToString((Direction)direction)).arg(moveThePlayer_list_size));
  396.         #endif
  397.     }
  398.     else
  399.     {
  400. /*      map_management_movement temp;
  401.         temp.movedUnit=previousMovedUnit;
  402.         temp.direction=(Direction)direction;
  403.         delayed_map_management_move << temp;*/
  404.     }
  405. }
  406.  
  407. //send client only on near map loaded and not the current player
  408. void ClientMapManagement::getNearClient(QList<ClientMapManagement *> & returnList)
  409. {
  410.     if(!current_map->map_loaded)
  411.         return;
  412.     returnList << current_map->clients;
  413.     /// \todo uncomment and fix this code
  414.     /*
  415.     getNearClient_index=0;
  416.     getNearClient_list_size=current_map->clients.size();
  417.     while(getNearClient_index<getNearClient_list_size)
  418.     {
  419.         if(current_map->clients.at(getNearClient_index)!=this)
  420.             returnList << current_map->clients.at(getNearClient_index);
  421.         getNearClient_index++;
  422.     }*/
  423. }
  424.  
  425. void ClientMapManagement::insertClient(const quint32 &player_id,const QString &map,const quint16 &x,const quint16 &y,const Direction &direction)
  426. {
  427.     if(current_map==NULL)
  428.     {
  429.         emit message("internal error, map pointer == NULL at insertClient()");
  430.         return;
  431.     }
  432.     insertClient_temp.fileName=map;
  433.     insertClient_temp.id=player_id;
  434.     insertClient_temp.direction=direction;
  435.     insertClient_temp.x=x;
  436.     insertClient_temp.y=y;
  437.     to_send_map_management_insert << insertClient_temp;
  438. }
  439.  
  440. /// \note The first heavy function
  441. void ClientMapManagement::moveClient(const quint32 &player_id,const quint8 &movedUnit,const Direction &direction)
  442. {
  443.     if(current_map==NULL)
  444.     {
  445.         emit message("internal error, map pointer == NULL at moveClient()");
  446.         return;
  447.     }
  448.     #ifdef DEBUG_MESSAGE_CLIENT_COMPLEXITY_SQUARE
  449.     emit message(QString("moveClient(%1,%2,%3)").arg(player_id).arg(movedUnit).arg(Map_custom::directionToString((Direction)direction)));
  450.     #endif
  451.     moveClient_tempMov.movedUnit=movedUnit;
  452.     moveClient_tempMov.direction=direction;
  453.     //multi-threaded access to to_send_map_management_move ?
  454.     moveClient_list_size=to_send_map_management_move.size();
  455.     moveClient_index=0;
  456.     while(moveClient_index<moveClient_list_size)
  457.     {
  458.         if(to_send_map_management_move[moveClient_index].id==player_id)
  459.         {
  460.             to_send_map_management_move[moveClient_index].movement_list << moveClient_tempMov;
  461.             return;
  462.         }
  463.         moveClient_index++;
  464.     }
  465.     moveClient_temp.id=player_id;
  466.     moveClient_temp.movement_list.clear();
  467.     moveClient_temp.movement_list << moveClient_tempMov;
  468.     to_send_map_management_move << moveClient_temp;
  469. }
  470.  
  471. void ClientMapManagement::removeClient(const quint32 &player_id)
  472. {
  473.     if(current_map==NULL)
  474.     {
  475.         emit message("internal error, map pointer == NULL at removeClient()");
  476.         return;
  477.     }
  478.     if(stopIt)
  479.         return;
  480.     if(to_send_map_management_remove.contains(player_id))
  481.         emit message("try dual remove");
  482.     else
  483.     {
  484.         list_size=to_send_map_management_move.size();
  485.         index=0;
  486.         while(index<list_size)
  487.         {
  488.             if(to_send_map_management_move.at(index).id==player_id)
  489.             {
  490.                 to_send_map_management_move.removeAt(index);
  491.                 return;
  492.             }
  493.             index++;
  494.         }
  495.         to_send_map_management_remove << player_id;
  496.     }
  497. }
  498.  
  499. void ClientMapManagement::purgeBuffer()
  500. {
  501.     if(to_send_map_management_insert.size()==0 && to_send_map_management_move.size()==0 && to_send_map_management_remove.size()==0)
  502.         return;
  503.     if(stopIt)
  504.         return;
  505.     QMutexLocker lock(&mutex);
  506.  
  507.     #ifdef DEBUG_MESSAGE_CLIENT_COMPLEXITY_LINEARE
  508.     emit message("purgeBuffer() runing....");
  509.     #endif
  510.  
  511.     purgeBuffer_player_affected=0;
  512.  
  513.     purgeBuffer_outputData.clear();
  514.     QDataStream out(&purgeBuffer_outputData, QIODevice::WriteOnly);
  515.     out.setVersion(QDataStream::Qt_4_4);
  516.     out << (quint8)0xC0;
  517.     purgeBuffer_outputDataLoop.clear();
  518.     QDataStream outLoop(&purgeBuffer_outputDataLoop, QIODevice::WriteOnly);
  519.     outLoop.setVersion(QDataStream::Qt_4_4);
  520.  
  521.     purgeBuffer_index=0;
  522.     purgeBuffer_list_size=to_send_map_management_remove.size();
  523.     while(purgeBuffer_index<purgeBuffer_list_size)
  524.     {
  525.         if(stopIt)
  526.             return;
  527.         #ifdef DEBUG_MESSAGE_CLIENT_COMPLEXITY_SQUARE
  528.         emit message(
  529.                     QString("player_id to remove: %1, for player: %2")
  530.                     .arg(to_send_map_management_remove.at(purgeBuffer_index))
  531.                     .arg(player_id)
  532.                      );
  533.         #endif
  534.         outLoop << to_send_map_management_remove.at(purgeBuffer_index);
  535.         outLoop << (quint8)0x03;
  536.         purgeBuffer_index++;
  537.         purgeBuffer_player_affected++;
  538.     }
  539.     to_send_map_management_remove.clear();
  540.  
  541.     purgeBuffer_index=0;
  542.     purgeBuffer_list_size=to_send_map_management_insert.size();
  543.     while(purgeBuffer_index<purgeBuffer_list_size)
  544.     {
  545.         if(stopIt)
  546.             return;
  547.         #ifdef DEBUG_MESSAGE_CLIENT_COMPLEXITY_SQUARE
  548.         emit message(
  549.                     QString("insert player_id: %1,mapName %2,x: %3,y: %4,direction: %5, for player: %6")
  550.                     .arg(to_send_map_management_insert.at(purgeBuffer_index).id)
  551.                     .arg(to_send_map_management_insert.at(purgeBuffer_index).fileName)
  552.                     .arg(to_send_map_management_insert.at(purgeBuffer_index).x)
  553.                     .arg(to_send_map_management_insert.at(purgeBuffer_index).y)
  554.                     .arg(Map_custom::directionToString(to_send_map_management_insert.at(purgeBuffer_index).direction))
  555.                     .arg(player_id)
  556.                      );
  557.         #endif
  558.         outLoop << to_send_map_management_insert.at(purgeBuffer_index).id;
  559.         outLoop << (quint8)0x01;
  560.         outLoop << to_send_map_management_insert.at(purgeBuffer_index).fileName;
  561.         outLoop << to_send_map_management_insert.at(purgeBuffer_index).x;
  562.         outLoop << to_send_map_management_insert.at(purgeBuffer_index).y;
  563.         outLoop << (quint8)to_send_map_management_insert.at(purgeBuffer_index).direction;
  564.         purgeBuffer_index++;
  565.         purgeBuffer_player_affected++;
  566.     }
  567.     to_send_map_management_insert.clear();
  568.  
  569.     purgeBuffer_index=0;
  570.     purgeBuffer_list_size=to_send_map_management_move.size();
  571.     purgeBuffer_list_size_internal=0;
  572.     purgeBuffer_indexMovement=0;
  573.  
  574.     while(purgeBuffer_index<purgeBuffer_list_size)
  575.     {
  576.         if(stopIt)
  577.             return;
  578.         purgeBuffer_move=to_send_map_management_move.at(purgeBuffer_index);
  579.         #ifdef DEBUG_MESSAGE_CLIENT_COMPLEXITY_SQUARE
  580.         emit message(
  581.                     QString("move player_id: %1, for player: %2")
  582.                     .arg(purgeBuffer_move.id)
  583.                     .arg(player_id)
  584.                      );
  585.         #endif
  586.         outLoop << purgeBuffer_move.id;
  587.         outLoop << (quint8)0x02;
  588.         purgeBuffer_list_size_internal=purgeBuffer_move.movement_list.size();
  589.         if(purgeBuffer_list_size_internal==0)
  590.             DebugClass::debugConsole(QString("for player: %1, list_size_internal==0").arg(this->player_id));
  591.         outLoop << (quint8)purgeBuffer_list_size_internal;
  592.         purgeBuffer_indexMovement=0;
  593.         while(purgeBuffer_indexMovement<purgeBuffer_list_size_internal)
  594.         {
  595.             if(stopIt)
  596.                 return;
  597.             outLoop << purgeBuffer_move.movement_list.at(purgeBuffer_indexMovement).movedUnit;
  598.             outLoop << (quint8)purgeBuffer_move.movement_list.at(purgeBuffer_indexMovement).direction;
  599.             purgeBuffer_indexMovement++;
  600.         }
  601.         purgeBuffer_player_affected++;
  602.         purgeBuffer_index++;
  603.         if(stopIt)
  604.             return;
  605.     }
  606.     if(stopIt)
  607.         return;
  608.     to_send_map_management_move.clear();
  609.  
  610.     if(stopIt)
  611.         return;
  612.  
  613.     #ifdef DEBUG_MESSAGE_CLIENT_COMPLEXITY_SQUARE
  614.     emit message(QString("player_affected: %1").arg(purgeBuffer_player_affected));
  615.     #endif
  616.     out << purgeBuffer_player_affected;
  617.     purgeBuffer_outputData+=purgeBuffer_outputDataLoop;
  618.     emit sendPacket(purgeBuffer_outputData);
  619. }
  620.  
  621. Map_custom * ClientMapManagement::getMap(const QString & mapName)
  622. {
  623.     int index=0;
  624.     int map_list_size=map_list->size();
  625.     while(index<map_list_size)
  626.     {
  627.         //current map found in already loaded
  628.         if(map_list->at(index)->mapName()==mapName)
  629.             return map_list->at(index);
  630.         index++;
  631.     }
  632.     *map_list << new Map_custom(map_loader_thread,map_list);
  633.     map_list->last()->moveToThread(this->thread());
  634.     map_list->last()->loadMap(mapName,basePath);
  635.     return map_list->last();
  636. }
  637.  
  638. void ClientMapManagement::mapError(QString errorString)
  639. {
  640.     QByteArray outputData;
  641.     QDataStream out(&outputData, QIODevice::WriteOnly);
  642.     out.setVersion(QDataStream::Qt_4_4);
  643.     out << (quint8)0xC2;
  644.     out << (quint32)0x00000008;
  645.     out << (quint8)0x03;
  646.     out << "Unable to load the current map";
  647.     emit sendPacket(outputData);
  648.     emit error(errorString);
  649. }
Advertisement
Add Comment
Please, Sign In to add comment