[1775] | 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" |
---|
[2756] | 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 |
---|
[1775] | 35 | #include <enet/enet.h> |
---|
[2662] | 36 | #include "network/synchronisable/Synchronisable.h" |
---|
[1775] | 37 | #include "core/CoreIncludes.h" |
---|
| 38 | #include <assert.h> |
---|
| 39 | |
---|
[2171] | 40 | namespace orxonox { |
---|
[1775] | 41 | namespace packet { |
---|
| 42 | |
---|
[1901] | 43 | #define PACKET_FLAG_DELETE ENET_PACKET_FLAG_RELIABLE |
---|
[1775] | 44 | #define _PACKETID 0 |
---|
| 45 | #define _QUANTITY _PACKETID + sizeof(ENUM::Type) |
---|
[1890] | 46 | #define _OBJECTIDS _QUANTITY + sizeof(uint32_t) |
---|
[1775] | 47 | |
---|
| 48 | DeleteObjects::DeleteObjects() |
---|
| 49 | : Packet() |
---|
| 50 | { |
---|
[1901] | 51 | flags_ = flags_ | PACKET_FLAG_DELETE; |
---|
[1775] | 52 | } |
---|
| 53 | |
---|
[1890] | 54 | DeleteObjects::DeleteObjects( uint8_t *data, unsigned int clientID ) |
---|
[1775] | 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; |
---|
[2662] | 67 | COUT(4) << "sending DeleteObjects: "; |
---|
[1890] | 68 | unsigned int size = sizeof(ENUM::Type) + sizeof(uint32_t)*(number+1); |
---|
| 69 | data_ = new uint8_t[size]; |
---|
[1901] | 70 | uint8_t *tdata = data_; |
---|
[2662] | 71 | *reinterpret_cast<ENUM::Type*>(tdata) = ENUM::DeleteObjects; |
---|
[1901] | 72 | tdata += sizeof(ENUM::Type); |
---|
| 73 | *(uint32_t *)tdata = number; |
---|
| 74 | tdata += sizeof(uint32_t); |
---|
[1775] | 75 | for(unsigned int i=0; i<number; i++){ |
---|
[1901] | 76 | unsigned int temp = Synchronisable::popDeletedObject(); |
---|
| 77 | // assert(temp<10000); //ugly hack |
---|
[2662] | 78 | *reinterpret_cast<uint32_t*>(tdata) = temp; |
---|
| 79 | COUT(4) << temp << " "; |
---|
[1901] | 80 | tdata += sizeof(uint32_t); |
---|
[1775] | 81 | } |
---|
[2662] | 82 | COUT(4) << std::endl; |
---|
[1775] | 83 | return true; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | unsigned int DeleteObjects::getSize() const{ |
---|
| 87 | assert(data_); |
---|
[1890] | 88 | return _OBJECTIDS + *(uint32_t*)(data_+_QUANTITY)*sizeof(uint32_t); |
---|
[1775] | 89 | } |
---|
| 90 | |
---|
| 91 | bool DeleteObjects::process(){ |
---|
| 92 | for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++){ |
---|
[2662] | 93 | COUT(4) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl; |
---|
[1890] | 94 | Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) ); |
---|
[1775] | 95 | } |
---|
| 96 | return true; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | } //namespace packet |
---|
[2171] | 101 | } //namespace orxonox |
---|