- Timestamp:
- May 22, 2013, 10:34:42 PM (12 years ago)
- Branches:
- master
- Children:
- 45b2750
- Parents:
- 6e66ffd
- Location:
- common
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Message.h
r6e66ffd r5f868c0 2 2 #define _MESSAGE_H 3 3 4 #define MSG_TYPE_REGISTER 1 5 #define MSG_TYPE_LOGIN 2 6 #define MSG_TYPE_LOGOUT 3 7 #define MSG_TYPE_CHAT 4 8 #define MSG_TYPE_PLAYER 5 // server sends this to update player positions 9 #define MSG_TYPE_PLAYER_MOVE 6 // client sends this when a player wants to move 4 #define MSG_TYPE_REGISTER 1 5 #define MSG_TYPE_LOGIN 2 6 #define MSG_TYPE_LOGOUT 3 7 #define MSG_TYPE_CHAT 4 8 #define MSG_TYPE_PLAYER 5 // server sends this to update player positions 9 #define MSG_TYPE_PLAYER_MOVE 6 // client sends this when a player wants to move 10 #define MSG_TYPE_OBJECT 7 11 #define MSG_TYPE_REMOVE_OBJECT 8 10 12 11 13 typedef struct -
common/WorldMap.cpp
r6e66ffd r5f868c0 6 6 #include <sstream> 7 7 #include <cstdlib> 8 #include <cstring> 8 9 9 10 using namespace std; … … 64 65 } 65 66 67 vector<WorldMap::Object> WorldMap::getObjects() { 68 return *vctObjects; 69 } 66 70 vector<WorldMap::Object> WorldMap::getObjects(int x, int y) { 67 71 vector<WorldMap::Object> vctObjectsInRegion; … … 78 82 // used by the server to create new objects 79 83 void WorldMap::addObject(WorldMap::ObjectType t, int x, int y) { 80 WorldMap::Object o( t, vctObjects->size(), x, y);84 WorldMap::Object o(vctObjects->size(), t, x, y); 81 85 vctObjects->push_back(o); 82 86 } … … 96 100 97 101 if (!foundObject) { 98 WorldMap::Object o( t, id, x, y);102 WorldMap::Object o(id, t, x, y); 99 103 vctObjects->push_back(o); 100 104 } 105 } 106 107 bool WorldMap::removeObject(int id) { 108 vector<WorldMap::Object>::iterator it; 109 110 for (it = vctObjects->begin(); it != vctObjects->end(); it++) { 111 if (it->id == id) { 112 vctObjects->erase(it); 113 return true; 114 } 115 } 116 117 return false; // no object with that id was found 101 118 } 102 119 … … 240 257 /*** Functions for Object ***/ 241 258 242 WorldMap::Object::Object( ObjectType type, int id, int x, int y) {259 WorldMap::Object::Object(int id, ObjectType type, int x, int y) { 243 260 this->type = type; 244 261 this->id = id; … … 247 264 } 248 265 249 WorldMap::Object::Object( ObjectType type, int id, POSITION pos) {266 WorldMap::Object::Object(int id, ObjectType type, POSITION pos) { 250 267 this->type = type; 251 268 this->id = id; … … 255 272 WorldMap::Object::~Object() { 256 273 } 274 275 void WorldMap::Object::serialize(char* buffer) { 276 memcpy(buffer, &this->type, 4); 277 memcpy(buffer+4, &this->id, 4); 278 memcpy(buffer+8, &this->pos.x, 4); 279 memcpy(buffer+12, &this->pos.y, 4); 280 } 281 282 void WorldMap::Object::deserialize(char* buffer) { 283 memcpy(&this->type, buffer, 4); 284 memcpy(&this->id, buffer+4, 4); 285 memcpy(&this->pos.x, buffer+8, 4); 286 memcpy(&this->pos.y, buffer+12, 4); 287 } -
common/WorldMap.h
r6e66ffd r5f868c0 37 37 POSITION pos; 38 38 39 Object( ObjectType type, int id, int x, int y);40 Object( ObjectType type, int id, POSITION pos);39 Object(int id, ObjectType type, int x, int y); 40 Object(int id, ObjectType type, POSITION pos); 41 41 42 42 ~Object(); 43 44 void serialize(char* buffer); 45 void deserialize(char* buffer); 43 46 }; 44 47 … … 58 61 void setStructure(int x, int y, StructureType type); 59 62 63 vector<Object> getObjects(); 60 64 vector<Object> getObjects(int x, int y); 65 61 66 void addObject(ObjectType type, int x, int y); 62 67 void updateObject(int id, WorldMap::ObjectType t, int x, int y); 68 bool removeObject(int id); 63 69 64 70 static WorldMap* createDefaultMap();
Note:
See TracChangeset
for help on using the changeset viewer.