Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/consolecommands2/src/libraries/network/synchronisable/Serialise.h @ 7284

Last change on this file since 7284 was 6417, checked in by rgrieder, 15 years ago

Merged presentation2 branch back to trunk.
Major new features:

  • Actual GUI with settings, etc.
  • Improved space ship steering (human interaction)
  • Rocket fire and more particle effects
  • Advanced sound framework
  • Property svn:eol-style set to native
File size: 2.6 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
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file
31    @brief Functions to serialise pointers to objects that inherit from Synchronisable
32*/
33
34#ifndef _NetworkSerialise_H__
35#define _NetworkSerialise_H__
36
37#include "util/Serialise.h"
38#include "util/TypeTraits.h"
39#include "core/CorePrereqs.h"
40
41namespace orxonox{
42   
43    // These functions implement loading / saving / etc. for pointer types
44   
45    /** @brief returns the size of the objectID needed to synchronise the pointer */
46    template <class T> inline uint32_t returnSize( T*& variable )
47    {
48      return sizeof(uint32_t);
49    }
50   
51    /** @brief reads the objectID of a pointer out of the bytestream and increases the mem pointer */
52    template <class T> inline void loadAndIncrease( T*& variable, uint8_t*& mem )
53    {
54        *const_cast<typename Loki::TypeTraits<T*>::UnqualifiedType*>(&variable) = dynamic_cast<T*>(variable->getSynchronisable( *(uint32_t*)(mem) ));
55        mem += returnSize( variable );
56    }
57   
58    /** @brief saves the objectID of a pointer into the bytestream and increases the mem pointer */
59    template <class T> inline void saveAndIncrease( T*& variable, uint8_t*& mem )
60    {
61        if ( variable )
62            *(uint32_t*)(mem) = static_cast<uint32_t>(variable->getObjectID());
63        else
64            *(uint32_t*)(mem) = OBJECTID_UNKNOWN;
65        mem += returnSize( variable );
66    }
67   
68    /** @brief checks whether the objectID of the variable is the same as in the bytestream */
69    template <class T> inline  bool checkEquality( T*& variable, uint8_t* mem )
70    {
71        if ( variable )
72            return *(uint32_t*)(mem) == variable->getObjectID();
73        else
74            return *(uint32_t*)(mem) == OBJECTID_UNKNOWN;
75    }
76}
77
78
79#endif
Note: See TracBrowser for help on using the repository browser.