[2938] | 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: |
---|
[7490] | 23 | * Oliver Scheuss <scheusso [at] orxonox.net>, (C) 2010 |
---|
[2938] | 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[7490] | 29 | #include "FunctionCall.h" |
---|
[2938] | 30 | |
---|
| 31 | #include <cassert> |
---|
[3214] | 32 | #include "util/MultiType.h" |
---|
[7490] | 33 | #include "NetworkFunction.h" |
---|
[10624] | 34 | #include "NetworkFunctionManager.h" |
---|
[2938] | 35 | |
---|
| 36 | namespace orxonox { |
---|
[6417] | 37 | |
---|
[7490] | 38 | FunctionCall::FunctionCall() |
---|
| 39 | : nrOfArguments_(-1), objectID_(OBJECTID_UNKNOWN), size_(0) |
---|
[2938] | 40 | { |
---|
| 41 | } |
---|
| 42 | |
---|
[7490] | 43 | FunctionCall::~FunctionCall() |
---|
[2938] | 44 | { |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
[7490] | 48 | bool FunctionCall::execute(){ |
---|
[10624] | 49 | NetworkFunctionBase* fct = NetworkFunctionManager::getInstance().getFunctionByNetworkId( this->functionID_ ); |
---|
[10765] | 50 | assert( fct != nullptr ); |
---|
[10624] | 51 | assert( this->nrOfArguments_==this->arguments_.size() ); |
---|
| 52 | switch(this->nrOfArguments_) |
---|
[2938] | 53 | { |
---|
[10624] | 54 | case 0: |
---|
| 55 | return fct->call(this->objectID_); |
---|
| 56 | case 1: |
---|
| 57 | return fct->call(this->objectID_, this->arguments_[0]); |
---|
| 58 | case 2: |
---|
| 59 | return fct->call(this->objectID_, this->arguments_[0], this->arguments_[1]); |
---|
| 60 | case 3: |
---|
| 61 | return fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2]); |
---|
| 62 | case 4: |
---|
| 63 | return fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3]); |
---|
| 64 | case 5: |
---|
| 65 | return fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3], this->arguments_[4]); |
---|
| 66 | default: |
---|
| 67 | assert(0); |
---|
| 68 | return true; // return true to avoid that this functions gets called over and over again |
---|
[7490] | 69 | } |
---|
[2938] | 70 | } |
---|
| 71 | |
---|
[10624] | 72 | void FunctionCall::setCall( uint32_t networkID, uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5){ |
---|
[6417] | 73 | |
---|
[2938] | 74 | // first determine the size that has to be reserved for this call |
---|
[10624] | 75 | uint32_t callsize = 3*sizeof(uint32_t); //size for network-function-id and nrOfArguments and the objectID |
---|
[2938] | 76 | uint32_t nrOfArguments = 0; |
---|
[10624] | 77 | if(!mt1.null()) |
---|
[2938] | 78 | { |
---|
| 79 | nrOfArguments++; |
---|
[10624] | 80 | callsize += mt1.getNetworkSize(); |
---|
| 81 | this->arguments_.push_back(mt1); |
---|
| 82 | if(!mt2.null()) |
---|
[2938] | 83 | { |
---|
| 84 | nrOfArguments++; |
---|
[10624] | 85 | callsize += mt2.getNetworkSize(); |
---|
| 86 | this->arguments_.push_back(mt2); |
---|
| 87 | if(!mt3.null()) |
---|
[2938] | 88 | { |
---|
| 89 | nrOfArguments++; |
---|
[10624] | 90 | callsize += mt3.getNetworkSize(); |
---|
| 91 | this->arguments_.push_back(mt3); |
---|
| 92 | if(!mt4.null()) |
---|
[2938] | 93 | { |
---|
| 94 | nrOfArguments++; |
---|
[10624] | 95 | callsize += mt4.getNetworkSize(); |
---|
| 96 | this->arguments_.push_back(mt4); |
---|
| 97 | if(!mt5.null()) |
---|
[2938] | 98 | { |
---|
| 99 | nrOfArguments++; |
---|
[10624] | 100 | callsize += mt5.getNetworkSize(); |
---|
| 101 | this->arguments_.push_back(mt5); |
---|
[2938] | 102 | } |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | } |
---|
[7490] | 107 | this->nrOfArguments_ = nrOfArguments; |
---|
| 108 | this->functionID_ = networkID; |
---|
[10624] | 109 | this->objectID_ = objectID; |
---|
[7490] | 110 | this->size_ = callsize; |
---|
| 111 | } |
---|
[6417] | 112 | |
---|
[7490] | 113 | void FunctionCall::loadData(uint8_t*& mem) |
---|
| 114 | { |
---|
| 115 | this->functionID_ = *(uint32_t*)mem; |
---|
[10624] | 116 | this->nrOfArguments_ = *(uint32_t*)(mem+sizeof(uint32_t)); |
---|
| 117 | this->objectID_ = *(uint32_t*)(mem+2*sizeof(uint32_t)); |
---|
| 118 | mem += 3*sizeof(uint32_t); |
---|
[7490] | 119 | for( unsigned int i=0; i<this->nrOfArguments_; ++i ) |
---|
| 120 | { |
---|
| 121 | this->arguments_.push_back(MultiType()); |
---|
| 122 | this->arguments_.back().importData(mem); |
---|
| 123 | } |
---|
| 124 | } |
---|
[6417] | 125 | |
---|
[7490] | 126 | void FunctionCall::saveData(uint8_t*& mem) |
---|
| 127 | { |
---|
| 128 | // now serialise the mt values and copy the function id and isStatic |
---|
| 129 | *(uint32_t*)mem = this->functionID_; |
---|
[10624] | 130 | *(uint32_t*)(mem+sizeof(uint32_t)) = this->nrOfArguments_; |
---|
| 131 | *(uint32_t*)(mem+2*sizeof(uint32_t)) = this->objectID_; |
---|
| 132 | mem += 3*sizeof(uint32_t); |
---|
[10821] | 133 | for(auto & elem : this->arguments_) |
---|
[7490] | 134 | { |
---|
[10821] | 135 | elem.exportData( mem ); |
---|
[7490] | 136 | } |
---|
[2938] | 137 | } |
---|
| 138 | |
---|
| 139 | |
---|
[7490] | 140 | |
---|
[2938] | 141 | } //namespace orxonox |
---|