Changeset 5f868c0 in network-game for common/WorldMap.cpp
- Timestamp:
- May 22, 2013, 10:34:42 PM (12 years ago)
- Branches:
- master
- Children:
- 45b2750
- Parents:
- 6e66ffd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.