Changeset 5f868c0 in network-game for common/WorldMap.cpp


Ignore:
Timestamp:
May 22, 2013, 10:34:42 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
45b2750
Parents:
6e66ffd
Message:

Added partial server support for new messages for sending item info

File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/WorldMap.cpp

    r6e66ffd r5f868c0  
    66#include <sstream>
    77#include <cstdlib>
     8#include <cstring>
    89
    910using namespace std;
     
    6465}
    6566
     67vector<WorldMap::Object> WorldMap::getObjects() {
     68   return *vctObjects;
     69}
    6670vector<WorldMap::Object> WorldMap::getObjects(int x, int y) {
    6771   vector<WorldMap::Object> vctObjectsInRegion;
     
    7882// used by the server to create new objects
    7983void 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);
    8185   vctObjects->push_back(o);
    8286}
     
    96100
    97101   if (!foundObject) {
    98       WorldMap::Object o(t, id, x, y);
     102      WorldMap::Object o(id, t, x, y);
    99103      vctObjects->push_back(o);
    100104   }
     105}
     106
     107bool 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
    101118}
    102119
     
    240257/*** Functions for Object ***/
    241258
    242 WorldMap::Object::Object(ObjectType type, int id, int x, int y) {
     259WorldMap::Object::Object(int id, ObjectType type, int x, int y) {
    243260   this->type = type;
    244261   this->id = id;
     
    247264}
    248265
    249 WorldMap::Object::Object(ObjectType type, int id, POSITION pos) {
     266WorldMap::Object::Object(int id, ObjectType type, POSITION pos) {
    250267   this->type = type;
    251268   this->id = id;
     
    255272WorldMap::Object::~Object() {
    256273}
     274
     275void 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
     282void 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.