Changeset e6c26b8 in network-game for common


Ignore:
Timestamp:
Oct 1, 2013, 8:08:24 PM (11 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
master
Children:
95ffe57
Parents:
373089e
Message:

The client dynamically allocates memory for players and passes around a map with player pointers and some includes are now in individual files instead of in Common.h

Location:
common
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • common/Common.h

    r373089e re6c26b8  
    11#ifndef _COMMON_H
    22#define _COMMON_H
    3 
    4 #include "Compiler.h"
    5 
    6 #if defined WINDOWS
    7    #include <winsock2.h>
    8    #include <ws2tcpip.h>
    9 #elif defined LINUX
    10    #include <fcntl.h>
    11    #include <assert.h>
    12 #endif
    133
    144#include <string>
  • common/MessageContainer.h

    r373089e re6c26b8  
    44#include <string>
    55
    6 #include "Common.h"
     6#include "Compiler.h"
    77
    8 #if defined LINUX
     8#if defined WINDOWS
     9   #include <winsock2.h>
     10#elif defined LINUX
    911   #include <netinet/in.h>
    1012#endif
  • common/MessageProcessor.cpp

    r373089e re6c26b8  
    33#include <iostream>
    44#include <fstream>
     5
     6#include "Compiler.h"
     7
     8#if defined WINDOWS
     9   #include <ws2tcpip.h>
     10#endif
     11
     12#include "Common.h"
    513
    614MessageProcessor::MessageProcessor() {
  • common/Player.cpp

    r373089e re6c26b8  
    206206}
    207207
    208 bool Player::updateTarget(map<unsigned int, Player>& mapPlayers) {
     208bool Player::updateTarget(map<unsigned int, Player*>& mapPlayers) {
    209209   if (this->isChasing) {
    210       this->target.x = mapPlayers[this->targetPlayer].pos.x;
    211       this->target.y = mapPlayers[this->targetPlayer].pos.y;
     210      this->target.x = mapPlayers[this->targetPlayer]->pos.x;
     211      this->target.y = mapPlayers[this->targetPlayer]->pos.y;
    212212
    213213      if (posDistance(this->pos, this->target.toFloat()) <= this->range) {
  • common/Player.h

    r373089e re6c26b8  
    55#include <map>
    66
    7 #include "Common.h"
     7#include "Compiler.h"
    88
    9 #if defined LINUX
     9#if defined WINDOWS
     10   #include <winsock2.h>
     11#elif defined LINUX
    1012   #include <netinet/in.h>
    1113#endif
     
    4648   void deserialize(char* buffer);
    4749
    48    bool updateTarget(map<unsigned int, Player>& mapPlayers);
     50   bool updateTarget(map<unsigned int, Player*>& mapPlayers);
    4951   bool move(WorldMap *map);
    5052
  • common/Projectile.cpp

    r373089e re6c26b8  
    7171}
    7272
    73 bool Projectile::move(map<unsigned int, Player>& mapPlayers) {
     73bool Projectile::move(map<unsigned int, Player*>& mapPlayers) {
    7474   // if the current target logs off, this method will run into problems
    7575
    7676   unsigned long long curTime = getCurrentMillis();
    7777
    78    Player targetP = mapPlayers[target];
     78   Player* targetP = mapPlayers[target];
    7979
    8080   if (timeLastUpdated == 0) {
     
    8585
    8686   float pixels = speed * (curTime-timeLastUpdated) / 1000.0;
    87    double angle = atan2(targetP.pos.y-pos.y, targetP.pos.x-pos.x);
    88    float dist = sqrt(pow(targetP.pos.x-pos.x, 2) + pow(targetP.pos.y-pos.y, 2));
     87   double angle = atan2(targetP->pos.y-pos.y, targetP->pos.x-pos.x);
     88   float dist = sqrt(pow(targetP->pos.x-pos.x, 2) + pow(targetP->pos.y-pos.y, 2));
    8989
    9090   if (dist <= pixels) {
    91       pos.x = targetP.pos.x;
    92       pos.y = targetP.pos.y;
     91      pos.x = targetP->pos.x;
     92      pos.y = targetP->pos.y;
    9393      return true;
    9494   }else {
  • common/Projectile.h

    r373089e re6c26b8  
    2626
    2727   // returns true if it reached the target and should be deleted
    28    bool move(map<unsigned int, Player>& mapPlayers);
     28   bool move(map<unsigned int, Player*>& mapPlayers);
     29
     30   /*
     31    * target should become a Player*. When this object gets serialized, the player's id should be sent.
     32    * Deserialization in this case might be tricky since it will require a playerMap to turn the id into a Plauyer*
     33    */
    2934
    3035   int id;
Note: See TracChangeset for help on using the changeset viewer.