Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/netp/src/network/synchronisable/SynchronisableVariableSpecialisations.h @ 3060

Last change on this file since 3060 was 2794, checked in by scheusso, 16 years ago

some optimisations (mostly inlined SynchronisableVariable functions)
trying to track down a bug with enet connections

  • Property svn:eol-style set to native
  • Property svn:mergeinfo set to (toggle deleted branches)
    /code/branches/pickups/src/network/synchronisable/SynchronisableVariable.ccmergedeligible
    /code/branches/pickups2/src/network/synchronisable/SynchronisableVariable.ccmergedeligible
    /code/branches/buildsystem/src/network/synchronisable/SynchronisableVariable.cc1874-2276,​2278-2400
    /code/branches/buildsystem2/src/network/synchronisable/SynchronisableVariable.cc2506-2658
    /code/branches/buildsystem3/src/network/synchronisable/SynchronisableVariable.cc2662-2708
    /code/branches/ceguilua/src/network/synchronisable/SynchronisableVariable.cc1802-1808
    /code/branches/core3/src/network/synchronisable/SynchronisableVariable.cc1572-1739
    /code/branches/gcc43/src/network/synchronisable/SynchronisableVariable.cc1580
    /code/branches/gui/src/network/synchronisable/SynchronisableVariable.cc1635-1723
    /code/branches/input/src/network/synchronisable/SynchronisableVariable.cc1629-1636
    /code/branches/lodfinal/src/network/synchronisable/SynchronisableVariable.cc2372-2411
    /code/branches/network/src/network/synchronisable/SynchronisableVariable.cc2356
    /code/branches/network64/src/network/synchronisable/SynchronisableVariable.cc2210-2355
    /code/branches/objecthierarchy/src/network/synchronisable/SynchronisableVariable.cc1911-2085,​2100,​2110-2169
    /code/branches/objecthierarchy2/src/network/synchronisable/SynchronisableVariable.cc2171-2479
    /code/branches/overlay/src/network/synchronisable/SynchronisableVariable.cc2117-2385
    /code/branches/physics/src/network/synchronisable/SynchronisableVariable.cc1912-2055,​2107-2439
    /code/branches/physics_merge/src/network/synchronisable/SynchronisableVariable.cc2436-2457
    /code/branches/presentation/src/network/synchronisable/SynchronisableVariable.cc2369-2652,​2654-2660
    /code/branches/questsystem/src/network/synchronisable/SynchronisableVariable.cc1894-2088
    /code/branches/questsystem2/src/network/synchronisable/SynchronisableVariable.cc2107-2259
    /code/branches/script_trigger/src/network/synchronisable/SynchronisableVariable.cc1295-1953,​1955
    /code/branches/weapon/src/network/synchronisable/SynchronisableVariable.cc1925-2094
    /code/branches/weapon2/src/network/synchronisable/SynchronisableVariable.cc2107-2488
File size: 12.7 KB
RevLine 
[2245]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#include <cstring>
30#include "util/Math.h"
31
[2794]32#ifndef _NETWORK_SYNCHRONISABLEVARIABLESPECIALISATIONS__
33#define _NETWORK_SYNCHRONISABLEVARIABLESPECIALISATIONS__
[2245]34
35namespace orxonox{
36
37
38
39// =================== Template specialisation stuff =============
40
41// =========== bool
42
[2794]43template <> inline uint32_t SynchronisableVariable<const bool>::returnSize()
[2245]44{
45  return sizeof(uint8_t);
46}
47
[2794]48template <> inline void SynchronisableVariable<const bool>::setAndIncrease( uint8_t*& mem )
[2245]49{
50  *(uint8_t*)(&this->variable_) = *static_cast<uint8_t*>(mem);
51  mem += SynchronisableVariable<const bool>::returnSize();
52}
53
[2794]54template <> inline void SynchronisableVariable<const bool>::getAndIncrease( uint8_t*& mem )
[2245]55{
56  *static_cast<uint8_t*>(mem) = *(uint8_t*)(&this->variable_);
57  mem += SynchronisableVariable<const bool>::returnSize();
58}
59
[2794]60template <> inline bool SynchronisableVariable<const bool>::checkEquality( uint8_t* mem )
[2245]61{
62  return *static_cast<uint8_t*>(mem) == *(uint8_t*)(&this->variable_);
63}
64
[2309]65// =========== char
66
[2794]67template <> inline uint32_t SynchronisableVariable<const char>::returnSize()
[2309]68{
69  return sizeof(uint8_t);
70}
71
[2794]72template <> inline void SynchronisableVariable<const char>::setAndIncrease( uint8_t*& mem )
[2309]73{
74  *(uint8_t*)(&this->variable_) = *static_cast<uint8_t*>(mem);
75  mem += SynchronisableVariable<const char>::returnSize();
76}
77
[2794]78template <> inline void SynchronisableVariable<const char>::getAndIncrease( uint8_t*& mem )
[2309]79{
80  *static_cast<uint8_t*>(mem) = *(uint8_t*)(&this->variable_);
81  mem += SynchronisableVariable<const char>::returnSize();
82}
83
[2794]84template <> inline bool SynchronisableVariable<const char>::checkEquality( uint8_t* mem )
[2309]85{
86  return *static_cast<uint8_t*>(mem) == *(uint8_t*)(&this->variable_);
87}
88
[2245]89// =========== unsigned char
90
[2794]91template <> inline uint32_t SynchronisableVariable<const unsigned char>::returnSize()
[2245]92{
93  return sizeof(uint8_t);
94}
95
[2794]96template <> inline void SynchronisableVariable<const unsigned char>::setAndIncrease( uint8_t*& mem )
[2245]97{
98  *(uint8_t*)(&this->variable_) = *static_cast<uint8_t*>(mem);
99  mem += SynchronisableVariable<const unsigned char>::returnSize();
100}
101
[2794]102template <> inline void SynchronisableVariable<const unsigned char>::getAndIncrease( uint8_t*& mem )
[2245]103{
104  *static_cast<uint8_t*>(mem) = *(uint8_t*)(&this->variable_);
105  mem += SynchronisableVariable<const unsigned char>::returnSize();
106}
107
[2794]108template <> inline bool SynchronisableVariable<const unsigned char>::checkEquality( uint8_t* mem )
[2245]109{
110  return *static_cast<uint8_t*>(mem) == *(uint8_t*)(&this->variable_);
111}
112
113// =========== short
114
[2794]115template <> inline uint32_t SynchronisableVariable<const short>::returnSize()
[2245]116{
117  return sizeof(int16_t);
118}
119
[2794]120template <> inline void SynchronisableVariable<const short>::setAndIncrease( uint8_t*& mem )
[2245]121{
122  *(short*)(&this->variable_) = *(int16_t*)(mem);
123  mem += SynchronisableVariable<const short>::returnSize();
124}
125
[2794]126template <> inline void SynchronisableVariable<const short>::getAndIncrease( uint8_t*& mem )
[2245]127{
128  *(int16_t*)(mem) = this->variable_;
129  mem += SynchronisableVariable<const short>::returnSize();
130}
131
[2794]132template <> inline bool SynchronisableVariable<const short>::checkEquality( uint8_t* mem )
[2245]133{
134  return *(int16_t*)(mem) == static_cast<int16_t>(this->variable_);
135}
136
137// =========== unsigned short
138
[2794]139template <> inline uint32_t SynchronisableVariable<const unsigned short>::returnSize()
[2245]140{
141  return sizeof(uint16_t);
142}
143
[2794]144template <> inline void SynchronisableVariable<const unsigned short>::setAndIncrease( uint8_t*& mem )
[2245]145{
146  *(unsigned short*)(&this->variable_) = *(uint16_t*)(mem);
147  mem += SynchronisableVariable<const unsigned short>::returnSize();
148}
149
[2794]150template <> inline void SynchronisableVariable<const unsigned short>::getAndIncrease( uint8_t*& mem )
[2245]151{
152  *(uint16_t*)(mem) = this->variable_;
153  mem += SynchronisableVariable<const unsigned short>::returnSize();
154}
155
[2794]156template <> inline bool SynchronisableVariable<const unsigned short>::checkEquality( uint8_t* mem )
[2245]157{
158  return *(uint16_t*)(mem) == this->variable_;
159}
160
161// =========== int
162
[2794]163template <> inline uint32_t SynchronisableVariable<const int>::returnSize()
[2245]164{
165  return sizeof(int32_t);
166}
167
[2794]168template <> inline void SynchronisableVariable<const int>::setAndIncrease( uint8_t*& mem )
[2245]169{
170  *(int *)(&this->variable_) = *(int32_t*)(mem);
171  mem += SynchronisableVariable<const int>::returnSize();
172}
173
[2794]174template <> inline void SynchronisableVariable<const int>::getAndIncrease( uint8_t*& mem )
[2245]175{
176  *(int32_t*)(mem) = this->variable_;
177  mem += SynchronisableVariable<const int>::returnSize();
178}
179
[2794]180template <> inline bool SynchronisableVariable<const int>::checkEquality( uint8_t* mem )
[2245]181{
182  return *(int32_t*)(mem) == this->variable_;
183}
184
185// =========== unsigned int
186
[2794]187template <> inline uint32_t SynchronisableVariable<const unsigned int>::returnSize()
[2245]188{
189  return sizeof(uint32_t);
190}
191   
[2794]192template <> inline void SynchronisableVariable<const unsigned int>::setAndIncrease( uint8_t*& mem )
[2245]193{
194  *(unsigned int*)(&this->variable_) = *(uint32_t*)(mem);
195  mem += SynchronisableVariable<const unsigned int>::returnSize();
196}
197
[2794]198template <> inline void SynchronisableVariable<const unsigned int>::getAndIncrease( uint8_t*& mem )
[2245]199{
200  *(uint32_t*)(mem) = this->variable_;
201  mem += SynchronisableVariable<const unsigned int>::returnSize();
202}
203
[2794]204template <> inline bool SynchronisableVariable<const unsigned int>::checkEquality( uint8_t* mem )
[2245]205{
206  return *(uint32_t*)(mem) == this->variable_;
207}
208
209// =========== long
210
[2794]211template <> inline uint32_t SynchronisableVariable<const long>::returnSize()
[2245]212{
213  return sizeof(int32_t);
214}
215
[2794]216template <> inline void SynchronisableVariable<const long>::setAndIncrease( uint8_t*& mem )
[2245]217{
218  *(long*)(&this->variable_) = *(int32_t*)(mem);
219  mem += SynchronisableVariable<const long>::returnSize();
220}
221
[2794]222template <> inline void SynchronisableVariable<const long>::getAndIncrease( uint8_t*& mem )
[2245]223{
224  *(int32_t*)(mem) = this->variable_;
225  mem += SynchronisableVariable<const long>::returnSize();
226}
227
[2794]228template <> inline bool SynchronisableVariable<const long>::checkEquality( uint8_t* mem )
[2245]229{
230  return *(int32_t*)(mem) == this->variable_;
231}
232
233// =========== unsigned long
234
[2794]235template <> inline uint32_t SynchronisableVariable<const unsigned long>::returnSize()
[2245]236{
237  return sizeof(uint32_t);
238}
239
[2794]240template <> inline void SynchronisableVariable<const unsigned long>::setAndIncrease( uint8_t*& mem )
[2245]241{
242  *(unsigned long*)(&this->variable_) = *(uint32_t*)(mem);
243  mem += SynchronisableVariable<const unsigned long>::returnSize();
244}
245
[2794]246template <> inline void SynchronisableVariable<const unsigned long>::getAndIncrease( uint8_t*& mem )
[2245]247{
248  *(uint32_t*)(mem) = this->variable_;
249  mem += SynchronisableVariable<const unsigned long>::returnSize();
250}
251
[2794]252template <> inline bool SynchronisableVariable<const unsigned long>::checkEquality( uint8_t* mem )
[2245]253{
254  return *(uint32_t*)(mem) == this->variable_;
255}
256
257// =========== long long
258
[2794]259template <> inline uint32_t SynchronisableVariable<const long long>::returnSize()
[2245]260{
261  return sizeof(int64_t);
262}
263
[2794]264template <> inline void SynchronisableVariable<const long long>::setAndIncrease( uint8_t*& mem )
[2245]265{
266  *(long long*)(&this->variable_) = *(int64_t*)(mem);
267  mem += SynchronisableVariable<const long long>::returnSize();
268}
269
[2794]270template <> inline void SynchronisableVariable<const long long>::getAndIncrease( uint8_t*& mem )
[2245]271{
272  *(int64_t*)(mem) = this->variable_;
273  mem += SynchronisableVariable<const long long>::returnSize();
274}
275
[2794]276template <> inline bool SynchronisableVariable<const long long>::checkEquality( uint8_t* mem )
[2245]277{
278  return *(int64_t*)(mem) == this->variable_;
279}
280
281// =========== unsigned long long
282
[2794]283template <> inline uint32_t SynchronisableVariable<const unsigned long long>::returnSize()
[2245]284{
285  return sizeof(uint64_t);
286}
287
[2794]288template <> inline void SynchronisableVariable<const unsigned long long>::setAndIncrease( uint8_t*& mem )
[2245]289{
290  *(unsigned long long*)(&this->variable_) = *(uint64_t*)(mem);
291  mem += SynchronisableVariable<const unsigned long long>::returnSize();
292}
293
[2794]294template <> inline void SynchronisableVariable<const unsigned long long>::getAndIncrease( uint8_t*& mem )
[2245]295{
296  *(uint64_t*)(mem) = this->variable_;
297  mem += SynchronisableVariable<const unsigned long long>::returnSize();
298}
299
[2794]300template <> inline bool SynchronisableVariable<const unsigned long long>::checkEquality( uint8_t* mem )
[2245]301{
302  return *(uint64_t*)(mem) == this->variable_;
303}
304
305// =========== float
306
[2794]307template <> inline uint32_t SynchronisableVariable<const float>::returnSize()
[2245]308{
309  return sizeof(uint32_t);
310}
311
[2794]312template <> inline void SynchronisableVariable<const float>::setAndIncrease( uint8_t*& mem )
[2245]313{
314  *(uint32_t*)(&this->variable_) = *(uint32_t*)(mem);
315  mem += SynchronisableVariable<const float>::returnSize();
316}
317
[2794]318template <> inline void SynchronisableVariable<const float>::getAndIncrease( uint8_t*& mem )
[2245]319{
320  *(uint32_t*)(mem) = *(uint32_t*)(&this->variable_);
321  mem += SynchronisableVariable<const float>::returnSize();
322}
323
[2794]324template <> inline bool SynchronisableVariable<const float>::checkEquality( uint8_t* mem )
[2245]325{
326  return *(uint32_t*)(mem) == *(uint32_t*)(&this->variable_);
327}
328
329// =========== double
330
[2794]331template <> inline uint32_t SynchronisableVariable<const double>::returnSize()
[2245]332{
333  return sizeof(uint64_t);
334}
335
[2794]336template <> inline void SynchronisableVariable<const double>::setAndIncrease( uint8_t*& mem )
[2245]337{
338  *(uint64_t*)(&this->variable_) = *(uint64_t*)(mem);
339  mem += SynchronisableVariable<const double>::returnSize();
340}
341
[2794]342template <> inline void SynchronisableVariable<const double>::getAndIncrease( uint8_t*& mem )
[2245]343{
344  *(uint64_t*)(mem) = *(uint64_t*)(&this->variable_);
345  mem += SynchronisableVariable<const double>::returnSize();
346}
347
[2794]348template <> inline bool SynchronisableVariable<const double>::checkEquality( uint8_t* mem )
[2245]349{
350  return *(uint64_t*)(mem) == *(uint64_t*)(&this->variable_);
351}
352
353// =========== long double
354
[2794]355template <> inline uint32_t SynchronisableVariable<const long double>::returnSize()
[2245]356{
357  return sizeof(uint64_t);
358}
359
[2794]360template <> inline void SynchronisableVariable<const long double>::setAndIncrease( uint8_t*& mem )
[2245]361{
362  double temp;
[2710]363  memcpy(&temp, mem, sizeof(uint64_t));
[2245]364  *(long double*)(&this->variable_) = static_cast<const long double>(temp);
365  mem += SynchronisableVariable<const long double>::returnSize();
366}
367
[2794]368template <> inline void SynchronisableVariable<const long double>::getAndIncrease( uint8_t*& mem )
[2245]369{
370  double temp = static_cast<double>(this->variable_);
[2710]371  memcpy(mem, &temp, sizeof(uint64_t));
[2245]372  mem += SynchronisableVariable<const long double>::returnSize();
373}
374
[2794]375template <> inline bool SynchronisableVariable<const long double>::checkEquality( uint8_t* mem )
[2245]376{
377  double temp = static_cast<double>(this->variable_);
[2710]378  return memcmp(&temp, mem, sizeof(uint64_t))==0;
[2245]379}
380
381// =========== string
382
[2794]383template <> inline uint32_t SynchronisableVariable<const std::string>::returnSize()
[2245]384{
385  return variable_.length()+1;
386}
387
[2794]388template <> inline void SynchronisableVariable<const std::string>::getAndIncrease( uint8_t*& mem )
[2245]389{
390  memcpy(mem, this->variable_.c_str(), this->variable_.length()+1);
391  mem += this->variable_.length()+1;
392}
393
[2794]394template <> inline void SynchronisableVariable<const std::string>::setAndIncrease( uint8_t*& mem )
[2245]395{
396  *(std::string*)(&this->variable_) = std::string((const char *)mem);
397  mem += this->variable_.length()+1;
398}
399
[2794]400template <> inline bool SynchronisableVariable<const std::string>::checkEquality( uint8_t* mem )
[2245]401{
402  return std::string((const char*)mem)==this->variable_;
403}
404
405// =========== Degree
406
[2794]407template <> inline uint32_t SynchronisableVariable<const Degree>::returnSize()
[2245]408{
409  return sizeof(Ogre::Real);
410}
411
[2794]412template <> inline void SynchronisableVariable<const Degree>::getAndIncrease( uint8_t*& mem )
[2245]413{
414  Ogre::Real r = this->variable_.valueDegrees();
415  memcpy(mem, &r, returnSize());
416  mem += returnSize();
417}
418
[2794]419template <> inline void SynchronisableVariable<const Degree>::setAndIncrease( uint8_t*& mem )
[2245]420{
421  Ogre::Real* r = (Ogre::Real*)mem;
[2255]422  (Degree&)this->variable_ = *r;
[2245]423  mem += returnSize();
424}
425
[2794]426template <> inline bool SynchronisableVariable<const Degree>::checkEquality( uint8_t* mem )
[2245]427{
428  Ogre::Real* r = (Ogre::Real*)mem;
429  return this->variable_==Degree(*r);
430}
431
[2355]432}
[2794]433
434
435#endif
Note: See TracBrowser for help on using the repository browser.