Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/network/packet/DeleteObjects.cc @ 2769

Last change on this file since 2769 was 2756, checked in by rgrieder, 16 years ago

Minimising problems when including windows.h because it defines macros like "min" and "max" if not explicitly specified.
There are two headers we use that include windows.h: OgreWindowEventUtilities.h and enet.h. I had to tweak a little bit there as well.

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Oliver Scheuss, (C) 2008
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29
30#include "DeleteObjects.h"
31#ifndef WIN32_LEAN_AND_MEAN
32#  define WIN32_LEAN_AND_MEAN
33#endif
34#define NOMINMAX // required to stop windows.h screwing up std::min definition
35#include <enet/enet.h>
36#include "network/synchronisable/Synchronisable.h"
37#include "core/CoreIncludes.h"
38#include <assert.h>
39
40namespace orxonox {
41namespace packet {
42
43#define PACKET_FLAG_DELETE  ENET_PACKET_FLAG_RELIABLE
44#define _PACKETID           0
45#define _QUANTITY           _PACKETID + sizeof(ENUM::Type)
46#define _OBJECTIDS          _QUANTITY + sizeof(uint32_t)
47 
48DeleteObjects::DeleteObjects()
49 : Packet()
50{
51  flags_ = flags_ | PACKET_FLAG_DELETE;
52}
53
54DeleteObjects::DeleteObjects( uint8_t *data, unsigned int clientID )
55  : Packet(data, clientID)
56{
57}
58
59DeleteObjects::~DeleteObjects()
60{
61}
62
63bool DeleteObjects::fetchIDs(){
64  unsigned int number = Synchronisable::getNumberOfDeletedObject();
65  if(number==0)
66    return false;
67  COUT(4) << "sending DeleteObjects: ";
68  unsigned int size = sizeof(ENUM::Type) + sizeof(uint32_t)*(number+1);
69  data_ = new uint8_t[size];
70  uint8_t *tdata = data_;
71  *reinterpret_cast<ENUM::Type*>(tdata) = ENUM::DeleteObjects;
72  tdata += sizeof(ENUM::Type);
73  *(uint32_t *)tdata = number;
74  tdata += sizeof(uint32_t);
75  for(unsigned int i=0; i<number; i++){
76    unsigned int temp = Synchronisable::popDeletedObject();
77//     assert(temp<10000); //ugly hack
78    *reinterpret_cast<uint32_t*>(tdata) = temp;
79    COUT(4) << temp << " ";
80    tdata += sizeof(uint32_t);
81  }
82  COUT(4) << std::endl;
83  return true;
84}
85
86unsigned int DeleteObjects::getSize() const{
87  assert(data_);
88  return _OBJECTIDS + *(uint32_t*)(data_+_QUANTITY)*sizeof(uint32_t);
89}
90
91bool DeleteObjects::process(){
92  for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++){
93    COUT(4) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl;
94    Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) );
95  }
96  return true;
97}
98
99
100} //namespace packet
101} //namespace orxonox
Note: See TracBrowser for help on using the repository browser.