Index: code/branches/network64/src/network/synchronisable/Synchronisable.h
===================================================================
--- code/branches/network64/src/network/synchronisable/Synchronisable.h	(revision 2211)
+++ code/branches/network64/src/network/synchronisable/Synchronisable.h	(revision 2245)
@@ -35,14 +35,19 @@
 #include <map>
 #include <queue>
-#include "util/Integers.h"
+#include <cassert>
+#include "util/Math.h"
+#include "util/mbool.h"
 #include "core/OrxonoxClass.h"
-#include "core/XMLIncludes.h"
+// TODO: this has to be removed
+// #include <OgreLight.h>
+// #include "OrxonoxPrereqs.h"
+// ============================
 #include "NetworkCallback.h"
-#include "util/Integers.h"
+#include "SynchronisableVariable.h"
 
-#define REGISTERDATA(varname, ...) \
+/*#define REGISTERDATA(varname, ...) \
     registerVariable((void*)&varname, sizeof(varname), DATA, __VA_ARGS__)
 #define REGISTERSTRING(stringname, ...) \
-    registerVariable(&stringname, stringname.length()+1, STRING, __VA_ARGS__)
+    registerVariable(&stringname, stringname.length()+1, STRING, __VA_ARGS__)*/
 
 namespace orxonox
@@ -50,25 +55,11 @@
   static const unsigned int OBJECTID_UNKNOWN = (unsigned int)-1;
 
-  namespace direction{
-    enum syncdirection{
+  namespace objectDirection{
+    enum objectdirection{
       toclient=0x1,
       toserver=0x2,
-      bidirectional=0x3,
-      serverMaster=0x3,
-      clientMaster=0x7
+      bidirectional=0x3
     };
   }
-
-  namespace syncmode{
-    enum mode{
-      once=0,
-      always=1
-    };
-  }
-
-  enum variableType{
-    DATA,
-    STRING,
-  };
 
   struct _NetworkExport synchronisableHeader{
@@ -80,13 +71,4 @@
   };
 
-  struct _NetworkExport synchronisableVariable{
-    size_t size;
-    uint8_t mode; // this determines in which direction the variable gets synchronised
-    void *var;
-    variableType type;
-    NetworkCallbackBase *callback;
-    void *varBuffer;
-    uint8_t varReference;
-  };
 
   /**
@@ -101,6 +83,4 @@
     virtual ~Synchronisable();
 
-
-    virtual bool create();
     static void setClient(bool b);
 
@@ -115,6 +95,7 @@
   protected:
     Synchronisable(BaseObject* creator);
-    void registerVariable(void *var, int size, variableType t, uint8_t mode=0x1, NetworkCallbackBase *cb=0);
-    void unregisterVariable(void *var);
+//     void registerVariable(void *var, int size, variableType t, uint8_t mode=0x1, NetworkCallbackBase *cb=0);
+    template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
+    template <class T> void unregisterVariable(T& var);
     void setObjectMode(uint8_t mode);
     void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; }
@@ -133,5 +114,5 @@
     unsigned int classID;
 
-    std::list<synchronisableVariable *> *syncList;
+    std::list<SynchronisableVariableBase*> syncList;
     static uint8_t state_; // detemines wheter we are server (default) or client
     bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server)
@@ -141,4 +122,43 @@
     static std::queue<unsigned int> deletedObjects_;
   };
+  
+  template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
+  {
+    if (bidirectional)
+      syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));
+    else
+      syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));
+  }
+
+  template <class T> void Synchronisable::unregisterVariable(T& var){
+    std::list<SynchronisableVariableBase*>::iterator it = syncList.begin();
+    while(it!=syncList.end()){
+      if( ((*it)->getReference()) == &var ){
+        delete (*it);
+        syncList.erase(it);
+        return;
+      }
+      else
+        it++;
+    }
+    bool unregistered_nonexistent_variable = false;
+    assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
+    // the variable has not been registered before
+  }
+  
+  // ================= Specialisation declarations
+  template <> void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);template <> void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> void Synchronisable::registerVariable( ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> void Synchronisable::registerVariable( const Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> void Synchronisable::registerVariable( const Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> void Synchronisable::registerVariable( Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> void Synchronisable::registerVariable( const Vector4& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> void Synchronisable::registerVariable( Vector4& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> void Synchronisable::registerVariable( mbool& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+  template <> void Synchronisable::registerVariable( Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+//   template <> void Synchronisable::registerVariable( LODParticle::LOD& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+//   template <> void Synchronisable::registerVariable( Ogre::Light::LightTypes& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
 }
 
