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 | |
---|
40 | namespace orxonox { |
---|
41 | namespace 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 | |
---|
48 | DeleteObjects::DeleteObjects() |
---|
49 | : Packet() |
---|
50 | { |
---|
51 | flags_ = flags_ | PACKET_FLAG_DELETE; |
---|
52 | } |
---|
53 | |
---|
54 | DeleteObjects::DeleteObjects( uint8_t *data, unsigned int clientID ) |
---|
55 | : Packet(data, clientID) |
---|
56 | { |
---|
57 | } |
---|
58 | |
---|
59 | DeleteObjects::~DeleteObjects() |
---|
60 | { |
---|
61 | } |
---|
62 | |
---|
63 | bool 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 | |
---|
86 | unsigned int DeleteObjects::getSize() const{ |
---|
87 | assert(data_); |
---|
88 | return _OBJECTIDS + *(uint32_t*)(data_+_QUANTITY)*sizeof(uint32_t); |
---|
89 | } |
---|
90 | |
---|
91 | bool 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 |
---|