Index: trunk/src/defs/class_id.h
===================================================================
--- trunk/src/defs/class_id.h	(revision 6814)
+++ trunk/src/defs/class_id.h	(revision 6815)
@@ -118,4 +118,6 @@
   CL_VERTEX_ARRAY_MODEL         =    0x00004000,
 
+
+  CL_BILLBOARD                  =    0x10000001,
 
   // subsuper-classes derivations taken : 1, 2, 5, a, b, c.     << THIS IS A LIST OF ALL THE DCL_MASK_SUBSUPERCLASS_ID's taken
@@ -264,4 +266,5 @@
   CL_SHADER                     =    0x00000822,
   CL_FOG_EFFECT                 =    0x70000001,
+  CL_LENSE_FLARE                =    0x70000002,
 
   // GL-GUI
Index: trunk/src/lib/coord/p_node.cc
===================================================================
--- trunk/src/lib/coord/p_node.cc	(revision 6814)
+++ trunk/src/lib/coord/p_node.cc	(revision 6815)
@@ -1077,5 +1077,5 @@
   SYNCHELP_READ_BEGIN();
 
-  SYNCHELP_READ_FKT( BaseObject::writeState );
+  SYNCHELP_READ_FKT( BaseObject::writeState, NWT_PN_BO_WRITESTATE );
 
 //   char * parentName = NULL;
@@ -1094,19 +1094,19 @@
 
   int parentMode;
-  SYNCHELP_READ_INT( parentMode );
+  SYNCHELP_READ_INT( parentMode, NWT_PN_PARENTMODE );
   this->setParentMode((PARENT_MODE)parentMode);
 
   float f1, f2, f3, f4;
 
-  SYNCHELP_READ_FLOAT( f1 );
-  SYNCHELP_READ_FLOAT( f2 );
-  SYNCHELP_READ_FLOAT( f3 );
+  SYNCHELP_READ_FLOAT( f1, NWT_PN_COORX );
+  SYNCHELP_READ_FLOAT( f2, NWT_PN_COORY );
+  SYNCHELP_READ_FLOAT( f3, NWT_PN_COORZ );
   this->setRelCoor( f1, f2, f3 );
 
 
-  SYNCHELP_READ_FLOAT( f1 );
-  SYNCHELP_READ_FLOAT( f2 );
-  SYNCHELP_READ_FLOAT( f3 );
-  SYNCHELP_READ_FLOAT( f4 );
+  SYNCHELP_READ_FLOAT( f1, NWT_PN_ROTV );
+  SYNCHELP_READ_FLOAT( f2, NWT_PN_ROTX );
+  SYNCHELP_READ_FLOAT( f3, NWT_PN_ROTY );
+  SYNCHELP_READ_FLOAT( f4, NWT_PN_ROTZ );
   this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) );
 
@@ -1140,5 +1140,5 @@
   SYNCHELP_WRITE_BEGIN();
 
-  SYNCHELP_WRITE_FKT( BaseObject::readState );
+  SYNCHELP_WRITE_FKT( BaseObject::readState, NWT_PN_BO_WRITESTATE );
 
 //   if ( this->parent )
@@ -1151,14 +1151,14 @@
 //   }
 
-  SYNCHELP_WRITE_INT( this->parentMode );
-
-  SYNCHELP_WRITE_FLOAT( this->relCoordinate.x );
-  SYNCHELP_WRITE_FLOAT( this->relCoordinate.y );
-  SYNCHELP_WRITE_FLOAT( this->relCoordinate.z );
-
-  SYNCHELP_WRITE_FLOAT( this->relDirection.w );
-  SYNCHELP_WRITE_FLOAT( this->relDirection.v.x );
-  SYNCHELP_WRITE_FLOAT( this->relDirection.v.y );
-  SYNCHELP_WRITE_FLOAT( this->relDirection.v.z );
+  SYNCHELP_WRITE_INT( this->parentMode, NWT_PN_PARENTMODE );
+
+  SYNCHELP_WRITE_FLOAT( this->relCoordinate.x, NWT_PN_COORX );
+  SYNCHELP_WRITE_FLOAT( this->relCoordinate.y, NWT_PN_COORY );
+  SYNCHELP_WRITE_FLOAT( this->relCoordinate.z, NWT_PN_COORZ );
+
+  SYNCHELP_WRITE_FLOAT( this->relDirection.w, NWT_PN_ROTV );
+  SYNCHELP_WRITE_FLOAT( this->relDirection.v.x, NWT_PN_ROTX );
+  SYNCHELP_WRITE_FLOAT( this->relDirection.v.y, NWT_PN_ROTY );
+  SYNCHELP_WRITE_FLOAT( this->relDirection.v.z, NWT_PN_ROTZ );
 
 //   int n = children.size();
@@ -1209,5 +1209,5 @@
 
   byte flags = 0;
-  SYNCHELP_READ_BYTE( flags );
+  SYNCHELP_READ_BYTE( flags, NWT_PN_FLAGS );
   //PRINTF(0)("%s::FLAGS = %d\n", this->getName(), flags);
 
@@ -1216,7 +1216,7 @@
   if ( flags & __FLAG_COOR )
   {
-    SYNCHELP_READ_FLOAT( f1 );
-    SYNCHELP_READ_FLOAT( f2 );
-    SYNCHELP_READ_FLOAT( f3 );
+    SYNCHELP_READ_FLOAT( f1, NWT_PN_SCOORX );
+    SYNCHELP_READ_FLOAT( f2, NWT_PN_SCOORY );
+    SYNCHELP_READ_FLOAT( f3, NWT_PN_SCOORZ );
     PRINTF(0)("RCVD COOR: %f %f %f\n", f1, f2, f3);
     this->setRelCoor( f1, f2, f3 );
@@ -1225,8 +1225,8 @@
   if ( flags & __FLAG_ROT )
   {
-    SYNCHELP_READ_FLOAT( f1 );
-    SYNCHELP_READ_FLOAT( f2 );
-    SYNCHELP_READ_FLOAT( f3 );
-    SYNCHELP_READ_FLOAT( f4 );
+    SYNCHELP_READ_FLOAT( f1, NWT_PN_SROTV );
+    SYNCHELP_READ_FLOAT( f2, NWT_PN_SROTX );
+    SYNCHELP_READ_FLOAT( f3, NWT_PN_SROTY );
+    SYNCHELP_READ_FLOAT( f4, NWT_PN_SROTZ );
     PRINTF(0)("RCVD QUAT: %f %f %f %f\n", f1, f2, f3, f4);
     //this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) );
@@ -1250,4 +1250,5 @@
 int PNode::readSync( byte * data, int maxLength )
 {
+  //WARNING: if you change this file make sure you also change needsReadSync
   SYNCHELP_WRITE_BEGIN();
 
@@ -1270,5 +1271,5 @@
 
 
-  SYNCHELP_WRITE_BYTE( flags );
+  SYNCHELP_WRITE_BYTE( flags, NWT_PN_FLAGS );
   //PRINTF(0)("FLAGS = %d\n", flags);
 
@@ -1276,9 +1277,9 @@
   {
 
-    PRINTF(0)("SEND COOR: %f %f %f\n", this->relCoordinate.x, this->relCoordinate.y, this->relCoordinate.z);
-
-    SYNCHELP_WRITE_FLOAT( this->relCoordinate.x );
-    SYNCHELP_WRITE_FLOAT( this->relCoordinate.y );
-    SYNCHELP_WRITE_FLOAT( this->relCoordinate.z );
+    //PRINTF(0)("SEND COOR: %f %f %f\n", this->relCoordinate.x, this->relCoordinate.y, this->relCoordinate.z);
+
+    SYNCHELP_WRITE_FLOAT( this->relCoordinate.x, NWT_PN_SCOORX );
+    SYNCHELP_WRITE_FLOAT( this->relCoordinate.y, NWT_PN_SCOORY );
+    SYNCHELP_WRITE_FLOAT( this->relCoordinate.z, NWT_PN_SCOORZ );
 
     coorx = relCoordinate.x;
@@ -1290,10 +1291,10 @@
   {
 
-    PRINTF(0)("SEND QUAT: %f %f %f %f\n", this->absDirection.w, this->absDirection.v.x, this->absDirection.v.y, this->absDirection.v.z);
-
-    SYNCHELP_WRITE_FLOAT( this->absDirection.w );
-    SYNCHELP_WRITE_FLOAT( this->absDirection.v.x );
-    SYNCHELP_WRITE_FLOAT( this->absDirection.v.y );
-    SYNCHELP_WRITE_FLOAT( this->absDirection.v.z );
+    //PRINTF(0)("SEND QUAT: %f %f %f %f\n", this->absDirection.w, this->absDirection.v.x, this->absDirection.v.y, this->absDirection.v.z);
+
+    SYNCHELP_WRITE_FLOAT( this->absDirection.w, NWT_PN_SROTV );
+    SYNCHELP_WRITE_FLOAT( this->absDirection.v.x, NWT_PN_SROTX );
+    SYNCHELP_WRITE_FLOAT( this->absDirection.v.y, NWT_PN_SROTY );
+    SYNCHELP_WRITE_FLOAT( this->absDirection.v.z, NWT_PN_SROTZ );
 
     rotw = absDirection.w;
@@ -1305,2 +1306,18 @@
   return SYNCHELP_WRITE_N;
 }
+
+bool PNode::needsReadSync( )
+{
+  if ( fabs( coorx - relCoordinate.x ) > __OFFSET_POS ||
+       fabs( coory - relCoordinate.y ) > __OFFSET_POS ||
+       fabs( coorz - relCoordinate.z ) > __OFFSET_POS )
+    return true;
+
+  if ( fabs( rotw - absDirection.w ) > __OFFSET_ROT ||
+       fabs( rotx - absDirection.v.x ) > __OFFSET_ROT ||
+       fabs( roty - absDirection.v.y ) > __OFFSET_ROT ||
+       fabs( rotz - absDirection.v.z ) > __OFFSET_ROT )
+    return true;
+  
+  return false;
+}
Index: trunk/src/lib/coord/p_node.h
===================================================================
--- trunk/src/lib/coord/p_node.h	(revision 6814)
+++ trunk/src/lib/coord/p_node.h	(revision 6815)
@@ -190,4 +190,5 @@
   int       writeSync(const byte* data, int length, int sender);
   int       readSync(byte* data, int maxLength );
+  bool      needsReadSync();
 
  private:
Index: trunk/src/lib/graphics/Makefile.am
===================================================================
--- trunk/src/lib/graphics/Makefile.am	(revision 6814)
+++ trunk/src/lib/graphics/Makefile.am	(revision 6815)
@@ -9,9 +9,12 @@
 			   render2D/render_2d.cc \
 			   render2D/element_2d.cc \
+			   render2D/billboard.cc \
 			   text_engine/text_engine.cc \
 			   text_engine/text.cc \
 			   text_engine/font.cc \
 			   effects/graphics_effect.cc \
-			   effects/fog_effect.cc
+			   effects/fog_effect.cc \
+			   effects/lense_flare.cc
+
 
 noinst_HEADERS = graphics_engine.h \
@@ -20,9 +23,11 @@
 		 render2D/render_2d.h \
 		 render2D/element_2d.h \
+		 render2D/billboard.h \
 		 text_engine/text_engine.h \
 		 text_engine/text.h \
 		 text_engine/font.h \
 		 effects/graphics_effect.h \
-		 effects/fog_effect.h
+		 effects/fog_effect.h \
+		 effects/lense_flare.h
 
 
Index: trunk/src/lib/graphics/effects/fog_effect.cc
===================================================================
--- trunk/src/lib/graphics/effects/fog_effect.cc	(revision 6814)
+++ trunk/src/lib/graphics/effects/fog_effect.cc	(revision 6815)
@@ -62,7 +62,8 @@
 void FogEffect::loadParams(const TiXmlElement* root)
 {
+  printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.loadParms\n\n");
   GraphicsEffect::loadParams(root);
 
-   LoadParam(root, "fog-effect", this, FogEffect, setFogMode)
+   LoadParam(root, "fog-mode", this, FogEffect, setFogMode)
        .describe("sets the the fog mode {GL_LINEAR, GL_EXP, GL_EXP2}");
 
@@ -87,4 +88,5 @@
 bool FogEffect::activate()
 {
+  printf("fog==============================================>>>>>>>>>>>>>>>>>>>>>>>>...\n\n");
   PRINTF(4)( "Enabling Fog Effect, mode: %i, density: %f, start: %f, end: %f\n", this->fogMode, this->fogDensity,
              this->fogStart, this->fogEnd);
@@ -92,5 +94,5 @@
   glEnable(GL_FOG);
   {
-    GLfloat fogColor[4] = {0.5, 0.5, 0.5, 1.0};
+    GLfloat fogColor[4] = {0.6, 0.6, 0.6, 1.0};
 
     glFogi(GL_FOG_MODE, this->fogMode);
Index: trunk/src/lib/graphics/effects/graphics_effect.cc
===================================================================
--- trunk/src/lib/graphics/effects/graphics_effect.cc	(revision 6814)
+++ trunk/src/lib/graphics/effects/graphics_effect.cc	(revision 6815)
@@ -72,2 +72,18 @@
 bool GraphicsEffect::init()
 {}
+
+
+
+/**
+ * draws the effect, if needed
+ */
+void GraphicsEffect::draw() const
+{}
+
+
+
+/**
+ * ticks the effect if there is any time dependancy
+ */
+void GraphicsEffect::tick(float dt)
+{}
Index: trunk/src/lib/graphics/effects/graphics_effect.h
===================================================================
--- trunk/src/lib/graphics/effects/graphics_effect.h	(revision 6814)
+++ trunk/src/lib/graphics/effects/graphics_effect.h	(revision 6815)
@@ -25,5 +25,8 @@
     virtual bool deactivate() = 0;
 
-    inline bool isActivated() { return this->bActivated; }
+    virtual void draw() const;
+    virtual void tick(float dt);
+
+    inline bool isActivated() const { return this->bActivated; }
 
 
Index: trunk/src/lib/graphics/effects/lense_flare.cc
===================================================================
--- trunk/src/lib/graphics/effects/lense_flare.cc	(revision 6815)
+++ trunk/src/lib/graphics/effects/lense_flare.cc	(revision 6815)
@@ -0,0 +1,188 @@
+
+
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+### File Specific:
+   main-programmer: Patrick Boenzli
+*/
+
+#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
+
+#include "lense_flare.h"
+
+#include "load_param.h"
+#include "factory.h"
+
+#include "glincl.h"
+#include "texture.h"
+
+#include "light.h"
+#include "state.h"
+
+#include "render2D/billboard.h"
+
+using namespace std;
+
+CREATE_FACTORY(LenseFlare, CL_LENSE_FLARE);
+
+
+
+/**
+ *  default constructor
+ * @param root The XML-element to load the LenseFlare from
+ */
+ LenseFlare::LenseFlare(const TiXmlElement* root)
+{
+  if (root != NULL)
+    this->loadParams(root);
+
+  this->flareMatrix = new float[14];
+  /*          length                      image scale */
+  this->flareMatrix[0] = 1.0f; this->flareMatrix[1] = 1.0f;
+  this->flareMatrix[2] = 0.5f; this->flareMatrix[3] = 0.5f;
+  this->flareMatrix[4] = 0.33f; this->flareMatrix[5] = 0.25f;
+  this->flareMatrix[6] = 0.125f; this->flareMatrix[7] = 1.0f;
+  this->flareMatrix[8] = -0.5f; this->flareMatrix[9] = 0.5f;
+  this->flareMatrix[10] = -0.25f; this->flareMatrix[11] = 0.25f;
+  this->flareMatrix[12] = 1.82f; this->flareMatrix[13] = 0.25f;
+}
+
+
+/**
+ *  destroys a LenseFlare
+ */
+LenseFlare::~LenseFlare()
+{
+  std::vector<Billboard*>::iterator it;
+  for( it = flares.begin(); it != flares.end(); it++)
+    delete (*it);
+}
+
+
+/**
+ * @param root The XML-element to load the LenseFlare from
+ */
+void LenseFlare::loadParams(const TiXmlElement* root)
+{
+  GraphicsEffect::loadParams(root);
+
+    LoadParam(root, "add-flare-texture", this, LenseFlare, addFlare)
+        .describe("adds a lensflare texture to the engine");
+}
+
+
+/**
+ * initializes the fog effect
+ */
+bool LenseFlare::init()
+{}
+
+
+/**
+ * activates the fog effect
+ */
+bool LenseFlare::activate()
+{
+  this->bActivated = true;
+}
+
+
+/**
+ * deactivates the fog effect
+ */
+bool LenseFlare::deactivate()
+{
+  this->bActivated = false;
+}
+
+
+/**
+ * converts a gl mode char to a GLint
+ * @param mode the mode character
+ */
+GLint LenseFlare::charToFogMode(const char* mode)
+{}
+
+
+/**
+ * adds a texture flare
+ * @param textureName the name of the flare texture
+ *
+ *  1st: Texture of the Sun/Light source itself
+ *  2nd: Texture of the fist halo
+ *  3rd: Texture of small burst
+ *  4th: Texture of the second halo
+ *  5th: Texutre of the second burst
+ *  6th: Texture of the third halo
+ *  7th: Texture of the third burst
+ */
+void LenseFlare::addFlare(const char* textureName)
+{
+  if( this->flares.size() < LF_MAX_FLARES)
+  {
+    PRINTF(2)("You tried to add more than %i lense flares, ignoring\n", LF_MAX_FLARES);
+    return;
+  }
+
+  Billboard* bb = new Billboard(NULL);
+  bb->setTexture(textureName);
+  this->flares.push_back(bb);
+  PRINTF(0)("Added a Lenseflare Billboard with texture %s\n", textureName);
+
+  // the first flare belongs to the light source
+  if( this->flares.size() == 1 && this->lightSource != NULL)
+  {
+    bb->setBindNode(static_cast<PNode*>(this->lightSource));
+  }
+}
+
+
+
+/**
+ * tick the effect
+ */
+void LenseFlare::tick(float dt)
+{
+  if( unlikely(!this->bActivated || this->flares.size() == 0))
+    return;
+  // always update the screen center, it could be, that the window is resized
+  this->screenCenter = Vector(State::getResX()/2.0f, State::getResY()/2.0f, 0.0f);
+  // flare vector is the direction from the center to the light source
+  this->flareVector = this->flares[0]->getAbsCoor2D();
+  this->distance = this->flareVector.len();
+  this->flareVector.normalize();
+
+  // now calculate the new coordinates of the billboards
+  std::vector<Billboard*>::iterator it;
+  int i;
+  for( it = flares.begin(), i = 0; it != flares.end(); it++, i++)
+  {
+    // set the new position
+    (*it)->setAbsCoor2D(this->flareVector * this->flareMatrix[i * 2]);
+    PRINTF(0)("Drawing flare %i @ (%f, %f)\n", i, (this->flareVector * this->flareMatrix[i * 2]).x, (this->flareVector * this->flareMatrix[i * 2]).y);
+    // tick them
+    (*it)->tick(dt);
+  }
+}
+
+
+/**
+ * draws the LenseFlares
+ */
+void LenseFlare::draw() const
+{
+  if( !this->bActivated)
+    return;
+
+  std::vector<Billboard*>::const_iterator it;
+  for( it = flares.begin(); it != flares.end(); it++)
+    (*it)->draw();
+}
Index: trunk/src/lib/graphics/effects/lense_flare.h
===================================================================
--- trunk/src/lib/graphics/effects/lense_flare.h	(revision 6815)
+++ trunk/src/lib/graphics/effects/lense_flare.h	(revision 6815)
@@ -0,0 +1,59 @@
+/**
+ * @file lense_flare.h
+ *  lense flare effect
+ */
+
+#ifndef _LENSE_FLARE
+#define _LENSE_FLARE
+
+#include "graphics_effect.h"
+
+#include <vector>
+
+#include "vector.h"
+
+
+#define LF_MAX_FLARES 7
+
+
+class TiXmlElement;
+class Light;
+class Billboard;
+
+//! A class that handles LenseFlares. The LenseFlareManager operates on this.
+class LenseFlare : public GraphicsEffect
+{
+  public:
+    LenseFlare(const TiXmlElement* root = NULL);
+    virtual ~LenseFlare();
+
+    virtual void loadParams(const TiXmlElement* root);
+
+    virtual bool init();
+
+    virtual bool activate();
+    virtual bool deactivate();
+
+    virtual void draw() const;
+    virtual void tick(float dt);
+
+    void addFlare(const char* textureName);
+
+
+  private:
+    GLint charToFogMode(const char* mode);
+
+
+  private:
+    Light*                   lightSource;        //!< reference to the sun (or primary light source)
+    std::vector<Billboard*>  flares;             //!< the flares array
+
+    Vector                   flareVector;        //!< the axis to draw the flares on
+    float                    distance;           //!< distance from center to source
+    Vector                   screenCenter;       //!< the vector marking the center of the screen
+
+    float*                   flareMatrix;
+};
+
+
+#endif /* _LENSE_FLARE */
Index: trunk/src/lib/graphics/graphics_engine.cc
===================================================================
--- trunk/src/lib/graphics/graphics_engine.cc	(revision 6814)
+++ trunk/src/lib/graphics/graphics_engine.cc	(revision 6815)
@@ -41,4 +41,9 @@
 #include "shell_command.h"
 
+
+#include "parser/tinyxml/tinyxml.h"
+#include "load_param.h"
+#include "factory.h"
+
 #ifdef __WIN32__
  #include "class_list.h"
@@ -113,4 +118,16 @@
   GraphicsEngine::singletonRef = NULL;
 }
+
+
+/**
+ * loads the GraphicsEngine Specific Parameters.
+ * @param root: the XML-Element to load the Data From
+ */
+void GraphicsEngine::loadParams(const TiXmlElement* root)
+{
+  LoadParamXML(root, "load-effect", this, GraphicsEngine, loadGraphicsEffectXML)
+      .describe("loads a graphics effect");
+}
+
 
 /**
@@ -150,8 +167,8 @@
   this->initVideo(atoi(resolution.getString(0)), atoi(resolution.getString(1)), 16);
 
-  GraphicsEffect* fe = new FogEffect(NULL);
-  this->loadGraphicsEffect(fe);
-  fe->activate();
-  PRINTF(0)("--------------------------------------------------------------\n");
+//   GraphicsEffect* fe = new FogEffect(NULL);
+//   this->loadGraphicsEffect(fe);
+//   fe->activate();
+//   PRINTF(0)("--------------------------------------------------------------\n");
 }
 
@@ -571,7 +588,12 @@
 #endif /* NO_TEXT */
 
-
-  }
+  }
+
   Render2D::getInstance()->tick(dt);
+
+  // tick the graphics effects
+  list<GraphicsEffect*>::iterator it;
+  for (it = this->graphicsEffects.begin(); it != this->graphicsEffects.end(); it++)
+    (*it)->tick(dt);
 }
 
@@ -587,4 +609,9 @@
   Render2D::getInstance()->draw(E2D_LAYER_ALL);
   Shader::restoreShader();
+
+  //draw the graphics
+  list<GraphicsEffect*>::const_iterator it;
+  for (it = this->graphicsEffects.begin(); it != this->graphicsEffects.end(); it++)
+    (*it)->draw();
 }
 
@@ -661,4 +688,20 @@
 
 /**
+ * @param root The XML-element to load GraphicsEffects from
+ */
+void GraphicsEngine::loadGraphicsEffectXML(const TiXmlElement* root)
+{
+  const TiXmlElement* element = root->FirstChildElement();
+
+  while (element != NULL)
+  {
+    Factory::fabricate(element);
+
+    element = element->NextSiblingElement();
+  }
+}
+
+
+/**
  * loads a GraphicsEffect into the engine
  * @param effect the GraphicsEffect to add
Index: trunk/src/lib/graphics/graphics_engine.h
===================================================================
--- trunk/src/lib/graphics/graphics_engine.h	(revision 6814)
+++ trunk/src/lib/graphics/graphics_engine.h	(revision 6815)
@@ -23,4 +23,5 @@
 class WorldEntity;
 class GraphicsEffect;
+class TiXmlElement;
 
 //! class to handle graphics
@@ -34,4 +35,6 @@
     /** @returns a Pointer to the only object of this Class */
     inline static GraphicsEngine* getInstance() { if (!GraphicsEngine::singletonRef) GraphicsEngine::singletonRef = new GraphicsEngine();  return GraphicsEngine::singletonRef; };
+
+    virtual void loadParams(const TiXmlElement* root);
 
     int init();
@@ -83,4 +86,5 @@
     void process(const Event  &event);
 
+    void loadGraphicsEffectXML(const TiXmlElement* root);
     bool loadGraphicsEffect(GraphicsEffect* effect);
     bool unloadGraphicsEffect(GraphicsEffect* effect);
Index: trunk/src/lib/graphics/render2D/billboard.cc
===================================================================
--- trunk/src/lib/graphics/render2D/billboard.cc	(revision 6815)
+++ trunk/src/lib/graphics/render2D/billboard.cc	(revision 6815)
@@ -0,0 +1,168 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+### File Specific:
+   main-programmer: Patrick Boenzli
+*/
+
+#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
+
+#include "billboard.h"
+
+#include "load_param.h"
+#include "factory.h"
+
+#include "graphics_engine.h"
+#include "material.h"
+#include "glincl.h"
+#include "state.h"
+#include "p_node.h"
+
+
+using namespace std;
+
+
+CREATE_FACTORY(Billboard, CL_IMAGE_ENTITY);
+
+
+/**
+ * standart constructor
+ */
+Billboard::Billboard (const TiXmlElement* root)
+{
+  this->init();
+
+  if( root)
+    this->loadParams(root);
+}
+
+
+/**
+ * destroys a Billboard
+ */
+Billboard::~Billboard ()
+{
+  if (this->material)
+    delete this->material;
+}
+
+
+/**
+ * initializes the Billboard
+ */
+void Billboard::init()
+{
+  this->setClassID(CL_BILLBOARD, "Billboard");
+  this->setName("Billboard");
+
+  this->setLayer(E2D_LAYER_TOP);
+  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0, GraphicsEngine::getInstance()->getResolutionY()/10.0);
+
+  //this->setBindNode(this);
+  this->material = new Material();
+  this->setTexture("pictures/error_texture.png");
+}
+
+
+/**
+ *  load params
+ * @param root TiXmlElement object
+ */
+void Billboard::loadParams(const TiXmlElement* root)
+{
+  LoadParam(root, "texture", this, Billboard, setTexture)
+      .describe("the texture-file to load onto the Billboard");
+
+  LoadParam(root, "size", this, Billboard, setSize)
+      .describe("the size of the Billboard in Pixels");
+}
+
+
+/**
+ * sets the size of the Billboard.
+ * @param size the size in pixels
+ */
+void Billboard::setSize(float sizeX, float sizeY)
+{
+  this->setSize2D(sizeX, sizeY);
+}
+
+
+/**
+ * sets the material to load
+ * @param textureFile The texture-file to load onto the crosshair
+ */
+void Billboard::setTexture(const char* textureFile)
+{
+  this->material->setDiffuseMap(textureFile);
+}
+
+
+/**
+ * attaches this billboard to a parent
+ * @param pNode node to attach to
+ */
+void Billboard::attachTo(PNode* pNode)
+{
+  this->source->setParent(pNode);
+}
+
+
+/**
+ * ticks the Billboard
+ * @param dt the time to ticks
+ */
+void Billboard::tick(float dt)
+{
+  float z = 0.0f;
+  glReadPixels ((int)this->getAbsCoor2D().x,
+                 GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
+                 1,
+                 1,
+                 GL_DEPTH_COMPONENT,
+                 GL_FLOAT,
+                 &z);
+
+  GLdouble objX=.0, objY=.0, objZ=.0;
+  gluUnProject(this->getAbsCoor2D().x,
+               GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
+               .99,  // z
+               GraphicsEngine::modMat,
+               GraphicsEngine::projMat,
+               GraphicsEngine::viewPort,
+               &objX,
+               &objY,
+               &objZ );
+}
+
+
+/**
+ * draws the billboard
+ */
+void Billboard::draw() const
+{
+  glPushMatrix();
+
+  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
+  this->material->select();
+
+  glBegin(GL_TRIANGLE_STRIP);
+  glTexCoord2f(0, 0);
+  glVertex2f(-this->getSizeX2D(), -this->getSizeY2D());
+  glTexCoord2f(1, 0);
+  glVertex2f(this->getSizeX2D(), -this->getSizeY2D());
+  glTexCoord2f(0, 1);
+  glVertex2f(-this->getSizeX2D(), this->getSizeY2D());
+  glTexCoord2f(1, 1);
+  glVertex2f(this->getSizeX2D(), this->getSizeY2D());
+  glEnd();
+
+  glPopMatrix();
+}
Index: trunk/src/lib/graphics/render2D/billboard.h
===================================================================
--- trunk/src/lib/graphics/render2D/billboard.h	(revision 6815)
+++ trunk/src/lib/graphics/render2D/billboard.h	(revision 6815)
@@ -0,0 +1,47 @@
+/*!
+ * @file billboard.h
+ *  Definition of a billboard
+ */
+
+#ifndef _BILLBOARD_H
+#define _BILLBOARD_H
+
+
+#include "element_2d.h"
+
+#include "vector.h"
+
+
+
+class Model;
+class Material;
+class TiXmlElement;
+
+//! A class that enables the
+class Billboard :  public Element2D
+{
+
+  public:
+    Billboard(const TiXmlElement* root = NULL);
+    virtual ~Billboard();
+
+    void init();
+    void loadParams(const TiXmlElement* root);
+
+    void setSize(float sizeX, float sizeY);
+    void setTexture(const char* textureFile);
+    void attachTo(PNode* pnode);
+
+    virtual void tick(float dt);
+    virtual void draw() const;
+
+
+  private:
+    Material*        material;             //!< a material for the Billboard
+    float            rotationSpeed;        //!< Speed of the Rotation.
+
+    PNode*           source;               //!< the source attached to it
+
+};
+
+#endif /* _BILLBOARD_H */
Index: trunk/src/lib/lang/base_object.cc
===================================================================
--- trunk/src/lib/lang/base_object.cc	(revision 6814)
+++ trunk/src/lib/lang/base_object.cc	(revision 6815)
@@ -204,5 +204,5 @@
     objectName = NULL;
   }
-  SYNCHELP_READ_STRINGM( this->objectName );
+  SYNCHELP_READ_STRINGM( this->objectName, NWT_BO_NAME );
   if ( this->objectName && !strcmp(this->objectName, "") )
   {
@@ -225,5 +225,5 @@
 
   //PRINTF(0)("objectname = %s\n", this->objectName);
-  SYNCHELP_WRITE_STRING( this->objectName );
+  SYNCHELP_WRITE_STRING( this->objectName, NWT_BO_NAME );
 
   return SYNCHELP_WRITE_N;
Index: trunk/src/lib/network/handshake.cc
===================================================================
--- trunk/src/lib/network/handshake.cc	(revision 6814)
+++ trunk/src/lib/network/handshake.cc	(revision 6815)
@@ -95,16 +95,16 @@
   if ( !isServer() && hasState( HS_RECVD_VER ) && !hasState( HS_RECVD_HID ) )
   {
-    if ( length != INTSIZE+INTSIZE )
-    {
-      PRINTF(0)("hostID packet has wrong size %d instead of %d\n", length, 1);
-      setState( HS_COMPLETED );
-      return 0;
-    }
+    /*if ( length != INTSIZE+INTSIZE )
+    {
+      PRINTF(0)("hostID packet has wrong size %d instead of %d\n", length, INTSIZE+INTSIZE);
+      setState( HS_COMPLETED );
+      return 0;
+  }*/
 
     setState( HS_COMPLETED );
     setState( HS_RECVD_HID );
     this->isOk = true;
-    SYNCHELP_READ_INT( this->newHostId );
-    SYNCHELP_READ_INT( this->newNetworkGameManagerId );
+    SYNCHELP_READ_INT( this->newHostId, NWT_HS_HOST_ID );
+    SYNCHELP_READ_INT( this->newNetworkGameManagerId, NWT_HS_NGM_ID );
 
     if ( newHostId == 0 )
@@ -180,6 +180,6 @@
       isOk = false;
       //memcpy(data, (byte*)0, 4);
-      SYNCHELP_WRITE_INT( 0 );
-      SYNCHELP_WRITE_INT( 0 );
+      SYNCHELP_WRITE_INT( 0, NWT_HS_HOST_ID);
+      SYNCHELP_WRITE_INT( 0, NWT_HS_NGM_ID);
     }
     else
@@ -187,6 +187,6 @@
       isOk = true;
       //memcpy(data, &clientId, 4);
-      SYNCHELP_WRITE_INT( clientId );
-      SYNCHELP_WRITE_INT( networkGameManagerId );
+      SYNCHELP_WRITE_INT( clientId, NWT_HS_HOST_ID );
+      SYNCHELP_WRITE_INT( networkGameManagerId, NWT_HS_NGM_ID );
     }
     *reciever = clientId;
Index: trunk/src/lib/network/network_game_manager.cc
===================================================================
--- trunk/src/lib/network/network_game_manager.cc	(revision 6814)
+++ trunk/src/lib/network/network_game_manager.cc	(revision 6815)
@@ -167,9 +167,8 @@
   if ( !isServer() && !hasRequestedWorld )
   {
-    SYNCHELP_WRITE_BEGIN();
-    byte b = NET_REQUEST_ENTITY_LIST;
-    SYNCHELP_WRITE_BYTE( b );
+    assert( maxLength >= 1 );
+    data[0] = NET_REQUEST_ENTITY_LIST;
     hasRequestedWorld = true;
-    return SYNCHELP_WRITE_N;
+    return 1;
   }
 
Index: trunk/src/lib/network/synchronizeable.h
===================================================================
--- trunk/src/lib/network/synchronizeable.h	(revision 6814)
+++ trunk/src/lib/network/synchronizeable.h	(revision 6815)
@@ -20,4 +20,76 @@
 #define STATE_OUTOFSYNC 2
 #define STATE_REQUESTEDSYNC 4
+
+enum {
+  NWT_SS_WE_STATE = 1000000,
+  NWT_SS_B,
+  NWT_SS_FLAGS,
+  NWT_SS_MOUSEDIRX,
+  NWT_SS_MOUSEDIRY,
+  NWT_SS_MOUSEDIRZ,
+  NWT_SS_MOUSEDIRW,
+  NWT_SS_PN_SYNC,
+  NWT_SS_VELX,
+  NWT_SS_VELY,
+  NWT_SS_VELZ,
+  
+  NWT_HS_HOST_ID,
+  NWT_HS_NGM_ID,
+  
+  NWT_PN_BO_WRITESTATE,
+  NWT_PN_PARENTMODE,
+  NWT_PN_COORX,
+  NWT_PN_COORY,
+  NWT_PN_COORZ,
+  NWT_PN_ROTX,
+  NWT_PN_ROTY,
+  NWT_PN_ROTZ,
+  NWT_PN_ROTV,
+  
+  NWT_PN_FLAGS,
+  NWT_PN_SCOORX,
+  NWT_PN_SCOORY,
+  NWT_PN_SCOORZ,
+  NWT_PN_SROTX,
+  NWT_PN_SROTY,
+  NWT_PN_SROTZ,
+  NWT_PN_SROTV,
+  
+  NWT_BO_NAME,
+  
+  NWT_WE_PN_WRITESTATE,
+  NWT_WE_PN_MODELFILENAME,
+  NWT_WE_PN_SCALING,
+  
+  NWT_GT_WE_STATE,
+  
+  NWT_SB_WE_STATE,
+  NWT_SB_SIZE,
+  NWT_SB_TEXTURENAME,
+  
+  NWT_TER_WE_STATE,
+  
+  NWT_PU_WE_STATE,
+  
+  NWT_TPU_WE_STATE,
+  
+  NWT_LPU_WE_STATE,
+  
+  NWT_WPU_WE_STATE,
+  
+  NWT_PPU_WE_STATE,
+  NWT_PPU_TYPE,
+  NWT_PPU_VALUE,
+  NWT_PPU_MINVALUE,
+  NWT_PPU_MAXVALUE,
+
+  NWT_WAT_STATE,
+  NWT_WAT_WE_STATE,
+  NWT_WAT_SIZEX,
+  NWT_WAT_SIZEY,
+  NWT_WAT_RESX,
+  NWT_WAT_RESY,
+  NWT_WAT_HEIGHT
+};
 
 
@@ -58,7 +130,25 @@
  *
  */
+#define SYNCHELP_WRITE_DEBUG(n) {\
+  __synchelp_write_n = Converter::intToByteArray( n, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
+  assert( __synchelp_write_n == INTSIZE ); \
+  __synchelp_write_i += __synchelp_write_n; \
+}
+
+#define SYNCHELP_READ_DEBUG(n) {  \
+  int nn; \
+  __synchelp_read_n = Converter::byteArrayToInt( data+__synchelp_read_i, &nn );  \
+  assert( __synchelp_read_n == INTSIZE ); \
+  if ( n != nn ) { \
+    PRINTF(1)("Check your code! read/writes not in right order! read %d instead of %d\n", nn, n); \
+    assert( false ); \
+  } \
+  __synchelp_read_i += __synchelp_read_n; \
+}
+
 #define SYNCHELP_WRITE_BEGIN()    int __synchelp_write_i = 0; \
                                   int __synchelp_write_n
-#define SYNCHELP_WRITE_INT(i) { __synchelp_write_n = \
+#define SYNCHELP_WRITE_INT(i,n) { SYNCHELP_WRITE_DEBUG(n); \
+                                __synchelp_write_n = \
                                 Converter::intToByteArray( i, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
                                 assert( __synchelp_write_n == INTSIZE ); \
@@ -70,5 +160,6 @@
                                 __synchelp_write_i += __synchelp_write_n; \
 }
-#define SYNCHELP_WRITE_FLOAT(f) { __synchelp_write_n = \
+#define SYNCHELP_WRITE_FLOAT(f,n) { SYNCHELP_WRITE_DEBUG(n); \
+                                __synchelp_write_n = \
                                 Converter::floatToByteArray( f, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
                                 assert( __synchelp_write_n == FLOATSIZE ); \
@@ -80,5 +171,6 @@
                                 __synchelp_write_i += __synchelp_write_n; \
 }
-#define SYNCHELP_WRITE_BYTE(b) { \
+#define SYNCHELP_WRITE_BYTE(b,n) { SYNCHELP_WRITE_DEBUG(n); \
+                                \
                                 if (maxLength - __synchelp_write_i < 1) \
 { \
@@ -89,5 +181,6 @@
                                 __synchelp_write_i++; \
 }
-#define SYNCHELP_WRITE_STRING(s) { if (s!=NULL) {\
+#define SYNCHELP_WRITE_STRING(s,n) { SYNCHELP_WRITE_DEBUG(n); \
+                                if (s!=NULL) {\
                                 __synchelp_write_n = \
                                 Converter::stringToByteArray( s, data+__synchelp_write_i, strlen(s), maxLength-__synchelp_write_i ); \
@@ -105,5 +198,5 @@
 }
 #define SYNCHELP_WRITE_N        __synchelp_write_i
-#define SYNCHELP_WRITE_FKT(f)   { \
+#define SYNCHELP_WRITE_FKT(f,n)   { SYNCHELP_WRITE_DEBUG(n); \
                                   __synchelp_write_i += \
                                   f( data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
@@ -114,5 +207,5 @@
                                   int __synchelp_read_n
 
-#define SYNCHELP_READ_INT(i)       { \
+#define SYNCHELP_READ_INT(i,n)       { SYNCHELP_READ_DEBUG(n); \
                                     if ( length-__synchelp_read_i < INTSIZE ) \
 { \
@@ -124,5 +217,5 @@
                                     __synchelp_read_i += __synchelp_read_n; \
 }
-#define SYNCHELP_READ_FLOAT(f)    { \
+#define SYNCHELP_READ_FLOAT(f,n)    { SYNCHELP_READ_DEBUG(n); \
                                     if ( length-__synchelp_read_i < FLOATSIZE ) \
 { \
@@ -134,5 +227,5 @@
                                     __synchelp_read_i += __synchelp_read_n; \
 }
-#define SYNCHELP_READ_STRING(s,l)    { \
+#define SYNCHELP_READ_STRING(s,l,n)    {SYNCHELP_READ_DEBUG(n); \
                                     __synchelp_read_n = Converter::byteArrayToString( data+__synchelp_read_i, s, l );  \
                                     assert( __synchelp_read_n == strlen(s)+INTSIZE ) ;\
@@ -144,5 +237,5 @@
                                     __synchelp_read_i += __synchelp_read_n; \
 }
-#define SYNCHELP_READ_STRINGM(s)    { \
+#define SYNCHELP_READ_STRINGM(s,n)    { SYNCHELP_READ_DEBUG(n); \
                                     __synchelp_read_n = Converter::byteArrayToStringM( data+__synchelp_read_i, s );  \
                                     assert( __synchelp_read_n == strlen(s)+INTSIZE ) ;\
@@ -154,5 +247,5 @@
                                     __synchelp_read_i += __synchelp_read_n; \
 }
-#define SYNCHELP_READ_BYTE(b)      { \
+#define SYNCHELP_READ_BYTE(b,n)      { SYNCHELP_READ_DEBUG(n); \
                                     if ( length-__synchelp_read_i < 1 ) \
 { \
@@ -163,8 +256,10 @@
                                     __synchelp_read_i ++;  \
 }
-#define SYNCHELP_READ_FKT(f)   { \
+#define SYNCHELP_READ_FKT(f,n)   { SYNCHELP_READ_DEBUG(n); \
                                   __synchelp_read_i += \
                                   f( data+__synchelp_read_i, length-__synchelp_read_i, sender); \
                                   }
+#define SYNCHELP_READ_REMAINING() ( length-__synchelp_read_i )
+#define SYNCHELP_READ_NEXTBYTE() ( data[__synchelp_read_i] )
 #define SYNCHELP_READ_N           __synchelp_read_i
 
Index: trunk/src/story_entities/game_world_data.cc
===================================================================
--- trunk/src/story_entities/game_world_data.cc	(revision 6814)
+++ trunk/src/story_entities/game_world_data.cc	(revision 6815)
@@ -278,4 +278,5 @@
 {
   LoadParamXML(root, "LightManager", LightManager::getInstance(), LightManager, loadParams);
+  LoadParamXML(root, "GraphicsEngine", GraphicsEngine::getInstance(), GraphicsEngine, loadParams);
 
 //  LoadParamXML(root, "ParticleEngine", ParticleEngine::getInstance(), ParticleEngine, loadParams);
Index: trunk/src/world_entities/environments/water.cc
===================================================================
--- trunk/src/world_entities/environments/water.cc	(revision 6814)
+++ trunk/src/world_entities/environments/water.cc	(revision 6815)
@@ -302,5 +302,5 @@
   SYNCHELP_READ_BEGIN();
 
-  SYNCHELP_READ_FKT( Water::writeState );
+  SYNCHELP_READ_FKT( Water::writeState, NWT_WAT_STATE );
 
   return SYNCHELP_READ_N;
@@ -328,5 +328,5 @@
   {
     *reciever = rec;
-    SYNCHELP_WRITE_FKT( Water::readState );
+    SYNCHELP_WRITE_FKT( Water::readState, NWT_WAT_STATE );
   }
 
@@ -347,16 +347,16 @@
   SYNCHELP_WRITE_BEGIN();
 
-  SYNCHELP_WRITE_FKT( WorldEntity::readState );
+  SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_WAT_WE_STATE );
 
   // sync the size
-  SYNCHELP_WRITE_FLOAT( this->sizeX );
-  SYNCHELP_WRITE_FLOAT( this->sizeY );
+  SYNCHELP_WRITE_FLOAT( this->sizeX, NWT_WAT_SIZEX );
+  SYNCHELP_WRITE_FLOAT( this->sizeY, NWT_WAT_SIZEY );
 
   //sync resolution
-  SYNCHELP_WRITE_INT( this->resX );
-  SYNCHELP_WRITE_INT( this->resY );
+  SYNCHELP_WRITE_INT( this->resX, NWT_WAT_RESX );
+  SYNCHELP_WRITE_INT( this->resY, NWT_WAT_RESY );
 
   //sync the height
-  SYNCHELP_WRITE_FLOAT( this->height );
+  SYNCHELP_WRITE_FLOAT( this->height, NWT_WAT_HEIGHT );
 
   return SYNCHELP_WRITE_N;
@@ -374,5 +374,5 @@
   SYNCHELP_READ_BEGIN();
 
-  SYNCHELP_READ_FKT( WorldEntity::writeState );
+  SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_WAT_WE_STATE );
 
   float f1, f2;
@@ -380,6 +380,6 @@
 
   //read the size
-  SYNCHELP_READ_FLOAT( f1 );
-  SYNCHELP_READ_FLOAT( f2 );
+  SYNCHELP_READ_FLOAT( f1, NWT_WAT_SIZEX );
+  SYNCHELP_READ_FLOAT( f2, NWT_WAT_SIZEY );
   this->sizeX = f1;
   this->sizeY = f2;
@@ -387,6 +387,6 @@
 
   //read the resolution
-  SYNCHELP_READ_INT( i1 );
-  SYNCHELP_READ_INT( i2 );
+  SYNCHELP_READ_INT( i1, NWT_WAT_RESX );
+  SYNCHELP_READ_INT( i2, NWT_WAT_RESY );
   this->resX = i1;
   this->resY = i2;
@@ -394,5 +394,5 @@
 
   //read the height
-  SYNCHELP_READ_FLOAT( f1 );
+  SYNCHELP_READ_FLOAT( f1, NWT_WAT_HEIGHT );
   this->height = f1;
 
Index: trunk/src/world_entities/image_entity.cc
===================================================================
--- trunk/src/world_entities/image_entity.cc	(revision 6814)
+++ trunk/src/world_entities/image_entity.cc	(revision 6815)
@@ -49,10 +49,5 @@
 {
   if (this->material)
-  delete this->material;
-
-  // delete what has to be deleted here
-
-  GraphicsEngine::showMouse(true);
-  GraphicsEngine::stealWMEvents(false);
+    delete this->material;
 }
 
@@ -90,6 +85,6 @@
       .describe("the Speed with which the ImageEntity should rotate");
 
-  LoadParam(root, "billboarding", this, ImageEntity, toggleBillboard)
-      .describe("sets the ImageEntity to always look in the direction of the Player");
+  LoadParam(root, "billboarding", this, ImageEntity, toggleBillboarding)
+      .describe("sets the Billboard to always look in the direction of the Player");
 }
 
@@ -119,5 +114,5 @@
  * This means that the image will always look in the direction of the Player
  */
-void ImageEntity::toggleBillboard()
+void ImageEntity::toggleBillboarding()
 {
   this->bBillboarding = !this->bBillboarding;
Index: trunk/src/world_entities/image_entity.h
===================================================================
--- trunk/src/world_entities/image_entity.h	(revision 6814)
+++ trunk/src/world_entities/image_entity.h	(revision 6815)
@@ -1,7 +1,6 @@
 /*!
- * @file crosshair.h
-  *  Definition of ...
-
-*/
+ * @file image_entity.h
+ *  Definition of an ImageEntity
+ */
 
 #ifndef _IMAGE_ENTITY_H
@@ -34,5 +33,5 @@
   /** @param rotationSpeed the speed at what the crosshair should rotate */
   void setRotationSpeed(float rotationSpeed) { this->rotationSpeed = rotationSpeed; };
-  void toggleBillboard();
+  void toggleBillboarding();
 
   virtual void tick(float dt);
Index: trunk/src/world_entities/npcs/ground_turret.cc
===================================================================
--- trunk/src/world_entities/npcs/ground_turret.cc	(revision 6814)
+++ trunk/src/world_entities/npcs/ground_turret.cc	(revision 6815)
@@ -181,5 +181,5 @@
   SYNCHELP_READ_BEGIN();
 
-  SYNCHELP_READ_FKT( WorldEntity::writeState );
+  SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_GT_WE_STATE );
 
   return SYNCHELP_READ_N;
@@ -207,5 +207,5 @@
     *reciever = rec;
 
-    SYNCHELP_WRITE_FKT( WorldEntity::readState );
+    SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_GT_WE_STATE );
 
   }
Index: trunk/src/world_entities/power_ups/laser_power_up.cc
===================================================================
--- trunk/src/world_entities/power_ups/laser_power_up.cc	(revision 6814)
+++ trunk/src/world_entities/power_ups/laser_power_up.cc	(revision 6815)
@@ -127,5 +127,5 @@
   SYNCHELP_READ_BEGIN();
 
-  SYNCHELP_READ_FKT( PowerUp::writeState );
+  SYNCHELP_READ_FKT( PowerUp::writeState, NWT_LPU_WE_STATE );
 
   return SYNCHELP_READ_N;
@@ -149,5 +149,5 @@
     SYNCHELP_WRITE_BEGIN();
 
-    SYNCHELP_WRITE_FKT( PowerUp::readState );
+    SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_LPU_WE_STATE );
 
     return SYNCHELP_WRITE_N;
Index: trunk/src/world_entities/power_ups/param_power_up.cc
===================================================================
--- trunk/src/world_entities/power_ups/param_power_up.cc	(revision 6814)
+++ trunk/src/world_entities/power_ups/param_power_up.cc	(revision 6815)
@@ -131,15 +131,15 @@
   SYNCHELP_READ_BEGIN();
 
-  SYNCHELP_READ_FKT( PowerUp::writeState );
+  SYNCHELP_READ_FKT( PowerUp::writeState, NWT_PPU_WE_STATE );
 
   int i;
-  SYNCHELP_READ_INT( i );
+  SYNCHELP_READ_INT( i, NWT_PPU_TYPE );
   this->type = (EnumParamPowerUpType)i;
-  SYNCHELP_READ_FLOAT( this->value );
+  SYNCHELP_READ_FLOAT( this->value, NWT_PPU_VALUE );
 
   if ( this->value != 0 )
   {
-    SYNCHELP_READ_FLOAT( this->min_value );
-    SYNCHELP_READ_FLOAT( this->max_value );
+    SYNCHELP_READ_FLOAT( this->min_value, NWT_PPU_MINVALUE );
+    SYNCHELP_READ_FLOAT( this->max_value, NWT_PPU_MAXVALUE );
     respawn();
   }
@@ -165,14 +165,14 @@
     SYNCHELP_WRITE_BEGIN();
 
-    SYNCHELP_WRITE_FKT( PowerUp::readState );
+    SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_PPU_WE_STATE );
 
     int i = (int)this->type;
-    SYNCHELP_WRITE_INT( i );
-    SYNCHELP_WRITE_FLOAT( this->value );
+    SYNCHELP_WRITE_INT( i, NWT_PPU_TYPE );
+    SYNCHELP_WRITE_FLOAT( this->value, NWT_PPU_VALUE );
 
     if ( this->value != 0 )
     {
-      SYNCHELP_WRITE_FLOAT( this->min_value );
-      SYNCHELP_WRITE_FLOAT( this->max_value );
+      SYNCHELP_WRITE_FLOAT( this->min_value, NWT_PPU_MINVALUE );
+      SYNCHELP_WRITE_FLOAT( this->max_value, NWT_PPU_MAXVALUE );
     }
 
Index: trunk/src/world_entities/power_ups/power_up.cc
===================================================================
--- trunk/src/world_entities/power_ups/power_up.cc	(revision 6814)
+++ trunk/src/world_entities/power_ups/power_up.cc	(revision 6815)
@@ -20,4 +20,6 @@
 #include "extendable.h"
 #include "primitive_model.h"
+
+#include "assert.h"
 
 using namespace std;
@@ -124,5 +126,5 @@
 {
   SYNCHELP_WRITE_BEGIN();
-  SYNCHELP_WRITE_FKT( WorldEntity::readState );
+  SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_PU_WE_STATE );
   return SYNCHELP_WRITE_N;
 }
@@ -138,5 +140,5 @@
 {
   SYNCHELP_READ_BEGIN();
-  SYNCHELP_READ_FKT( WorldEntity::writeState );
+  SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_PU_WE_STATE );
   return SYNCHELP_READ_N;
 }
Index: trunk/src/world_entities/power_ups/turret_power_up.cc
===================================================================
--- trunk/src/world_entities/power_ups/turret_power_up.cc	(revision 6814)
+++ trunk/src/world_entities/power_ups/turret_power_up.cc	(revision 6815)
@@ -136,5 +136,5 @@
   SYNCHELP_READ_BEGIN();
 
-  SYNCHELP_READ_FKT( PowerUp::writeState );
+  SYNCHELP_READ_FKT( PowerUp::writeState, NWT_TPU_WE_STATE );
 
   return SYNCHELP_READ_N;
@@ -157,5 +157,5 @@
     SYNCHELP_WRITE_BEGIN();
 
-    SYNCHELP_WRITE_FKT( PowerUp::readState );
+    SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_TPU_WE_STATE );
 
     return SYNCHELP_WRITE_N;
Index: trunk/src/world_entities/power_ups/weapon_power_up.cc
===================================================================
--- trunk/src/world_entities/power_ups/weapon_power_up.cc	(revision 6814)
+++ trunk/src/world_entities/power_ups/weapon_power_up.cc	(revision 6815)
@@ -100,5 +100,5 @@
   SYNCHELP_READ_BEGIN();
 
-  SYNCHELP_READ_FKT( PowerUp::writeState );
+  SYNCHELP_READ_FKT( PowerUp::writeState, NWT_WPU_WE_STATE );
 
   //TODO: sync weapon class ( see loadParams )
@@ -124,5 +124,5 @@
     SYNCHELP_WRITE_BEGIN();
 
-    SYNCHELP_WRITE_FKT( PowerUp::readState );
+    SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_WPU_WE_STATE );
 
     //TODO: sync weapon class ( see loadParams )
Index: trunk/src/world_entities/skybox.cc
===================================================================
--- trunk/src/world_entities/skybox.cc	(revision 6814)
+++ trunk/src/world_entities/skybox.cc	(revision 6815)
@@ -297,7 +297,7 @@
   SYNCHELP_READ_BEGIN();
 
-  SYNCHELP_READ_FKT( WorldEntity::writeState );
-
-  SYNCHELP_READ_FLOAT( size );
+  SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_SB_WE_STATE );
+
+  SYNCHELP_READ_FLOAT( size, NWT_SB_SIZE );
   if ( textureName )
   {
@@ -305,5 +305,5 @@
     textureName = NULL;
   }
-  SYNCHELP_READ_STRINGM( textureName );
+  SYNCHELP_READ_STRINGM( textureName, NWT_SB_TEXTURENAME );
 
   this->setSize( size );
@@ -331,8 +331,8 @@
     SYNCHELP_WRITE_BEGIN();
 
-    SYNCHELP_WRITE_FKT( WorldEntity::readState );
-
-    SYNCHELP_WRITE_FLOAT(this->size);
-    SYNCHELP_WRITE_STRING(this->textureName);
+    SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_SB_WE_STATE );
+
+    SYNCHELP_WRITE_FLOAT(this->size, NWT_SB_SIZE);
+    SYNCHELP_WRITE_STRING(this->textureName, NWT_SB_TEXTURENAME);
 
     return SYNCHELP_WRITE_N;
Index: trunk/src/world_entities/space_ships/space_ship.cc
===================================================================
--- trunk/src/world_entities/space_ships/space_ship.cc	(revision 6814)
+++ trunk/src/world_entities/space_ships/space_ship.cc	(revision 6815)
@@ -523,4 +523,6 @@
 #define DATA_flags       2
 #define DATA_mouse       3
+#define DATA_sync        4
+#define DATA_velocity    5
 
 int SpaceShip::writeBytes( const byte * data, int length, int sender )
@@ -529,26 +531,22 @@
 
   byte b;
-
-  do
-  {
-    SYNCHELP_READ_BYTE( b );
-
-    if ( b == DATA_state /*&& (this->getHostID()!=this->getOwner() || sender==0)*/ )
-    {
-     PRINTF(0)("GOT STATE %d\n", this->getUniqueID());
-     setRequestedSync( false );
-     setIsOutOfSync( false );
-     SYNCHELP_READ_FKT( WorldEntity::writeState );
-     //SYNCHELP_READ_FLOAT( cycle );
-
-      return SYNCHELP_READ_N;
-    }
-
-
-    //TODO: do not recieve data if you are the owner
-    if ( b == DATA_flags /*&& this->getHostID()!=this->getOwner()*/ )
+  
+  while ( SYNCHELP_READ_REMAINING()>0 )
+  {
+    SYNCHELP_READ_BYTE( b, NWT_SS_B );
+    
+    if ( b == DATA_state )
+    {
+      setRequestedSync( false );
+      setIsOutOfSync( false );
+      SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_SS_WE_STATE );
+
+      continue;
+    }
+    
+    if ( b == DATA_flags )
     {
       int flags = 0;
-      SYNCHELP_READ_INT( flags );
+      SYNCHELP_READ_INT( flags, NWT_SS_FLAGS );
 
       bUp = (flags & MASK_bUp) != 0;
@@ -561,28 +559,34 @@
       bRollL = (flags & MASK_bRollL) != 0;
       bRollR = (flags & MASK_bRollR) != 0;
-
-    }
-
-    //TODO: do not recieve data if you are the owner
-    if ( b == DATA_mouse /*&& this->getHostID()!=this->getOwner()*/ )
-    {
-      SYNCHELP_READ_FLOAT( mouseDir.w );
-      SYNCHELP_READ_FLOAT( mouseDir.v.x );
-      SYNCHELP_READ_FLOAT( mouseDir.v.y );
-      SYNCHELP_READ_FLOAT( mouseDir.v.z );
-    }
-  } while( b != 0 );
-
-  /*if ( b == DATA_mouse && this->getHostID()!=this->getOwner() )
-  {
-    SYNCHELP_READ_FLOAT( xMouse );
-    SYNCHELP_READ_FLOAT( yMouse );
-    SYNCHELP_READ_FLOAT( mouseSensitivity );
-    SYNCHELP_READ_FLOAT( cycle );
-}*/
-
-  if ( this->getOwner() != this->getHostID() )
-    SYNCHELP_READ_FKT( PNode::writeSync );
-
+      
+      continue;
+    }
+    
+    if ( b == DATA_mouse )
+    {
+      SYNCHELP_READ_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
+      SYNCHELP_READ_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
+      SYNCHELP_READ_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
+      SYNCHELP_READ_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
+      
+      continue;
+    }
+    
+    if ( b == DATA_sync )
+    {
+      if ( this->getOwner() != this->getHostID() )
+        SYNCHELP_READ_FKT( PNode::writeSync, NWT_SS_PN_SYNC );
+      
+      continue;
+    }
+    
+    if ( b == DATA_velocity )
+    {
+      SYNCHELP_READ_FLOAT( velocity.x, NWT_SS_VELX );
+      SYNCHELP_READ_FLOAT( velocity.y, NWT_SS_VELY );
+      SYNCHELP_READ_FLOAT( velocity.z, NWT_SS_VELZ );
+    }
+  }
+  
   return SYNCHELP_READ_N;
 }
@@ -608,7 +612,7 @@
     PRINTF(0)("SEND STATE %d %d\n", this->getUniqueID(), rec);
 
-    SYNCHELP_WRITE_BYTE( (byte)DATA_state );
-
-    SYNCHELP_WRITE_FKT( WorldEntity::readState );
+    SYNCHELP_WRITE_BYTE( (byte)DATA_state, NWT_SS_B );
+
+    SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_SS_WE_STATE );
     //SYNCHELP_WRITE_FLOAT( cycle );
 
@@ -617,4 +621,10 @@
 
   *reciever = 0;
+  
+  if ( this->getOwner() == this->getHostID() && PNode::needsReadSync() )
+  {
+    SYNCHELP_WRITE_BYTE( DATA_sync, NWT_SS_B );
+    SYNCHELP_WRITE_FKT( PNode::readSync, NWT_SS_PN_SYNC );
+  }
 
   if ( this->getHostID()==this->getOwner() )
@@ -646,30 +656,40 @@
     {
       oldMask = mask;
-      SYNCHELP_WRITE_BYTE( DATA_flags );
-      SYNCHELP_WRITE_INT( mask );
-    }
-#define __OFFSET_ROT 0.05
-    if ( fabs( oldMouseDir.w - mouseDir.w ) > __OFFSET_ROT ||
-         fabs( oldMouseDir.v.x - mouseDir.v.x ) > __OFFSET_ROT ||
-         fabs( oldMouseDir.v.y - mouseDir.v.y ) > __OFFSET_ROT ||
-         fabs( oldMouseDir.v.z - mouseDir.v.z ) > __OFFSET_ROT )
+      SYNCHELP_WRITE_BYTE( DATA_flags, NWT_SS_B );
+      SYNCHELP_WRITE_INT( mask, NWT_SS_FLAGS );
+    }
+#define __OFFSET_MDIR_W 0.01
+#define __OFFSET_MDIR_V 0.01
+    if ( fabs( oldMouseDir.w - mouseDir.w ) > __OFFSET_MDIR_W ||
+         fabs( oldMouseDir.v.x - mouseDir.v.x ) > __OFFSET_MDIR_V ||
+         fabs( oldMouseDir.v.y - mouseDir.v.y ) > __OFFSET_MDIR_V ||
+         fabs( oldMouseDir.v.z - mouseDir.v.z ) > __OFFSET_MDIR_V )
     {
       oldMouseDir = mouseDir;
 
-      SYNCHELP_WRITE_BYTE( DATA_mouse );
-      SYNCHELP_WRITE_FLOAT( mouseDir.w );
-      SYNCHELP_WRITE_FLOAT( mouseDir.v.x );
-      SYNCHELP_WRITE_FLOAT( mouseDir.v.y );
-      SYNCHELP_WRITE_FLOAT( mouseDir.v.z );
-    }
-
-  }
-
-  SYNCHELP_WRITE_BYTE( 0 );
-
-
-  if ( this->getOwner() == this->getHostID() )
-    SYNCHELP_WRITE_FKT( PNode::readSync );
+      SYNCHELP_WRITE_BYTE( DATA_mouse, NWT_SS_B );
+      PRINTF(0)("SENDING mousedir\n");
+      SYNCHELP_WRITE_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
+      SYNCHELP_WRITE_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
+      SYNCHELP_WRITE_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
+      SYNCHELP_WRITE_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
+    }
+#define __OFFSET_VEL 0.05
+    if ( fabs( oldVelocity.x - velocity.x ) > __OFFSET_VEL*velocity.x ||
+         fabs( oldVelocity.y - velocity.y ) > __OFFSET_VEL*velocity.y ||
+         fabs( oldVelocity.z - velocity.z ) > __OFFSET_VEL*velocity.z )
+    {
+      oldVelocity = velocity;
+      PRINTF(0)("SENDING velocity\n");
+      SYNCHELP_WRITE_BYTE( DATA_velocity, NWT_SS_B );
+      SYNCHELP_WRITE_FLOAT( velocity.x, NWT_SS_VELX );
+      SYNCHELP_WRITE_FLOAT( velocity.y, NWT_SS_VELY );
+      SYNCHELP_WRITE_FLOAT( velocity.z, NWT_SS_VELZ );
+    }
+
+  }
 
   return SYNCHELP_WRITE_N;
 }
+
+
Index: trunk/src/world_entities/space_ships/space_ship.h
===================================================================
--- trunk/src/world_entities/space_ships/space_ship.h	(revision 6814)
+++ trunk/src/world_entities/space_ships/space_ship.h	(revision 6815)
@@ -42,5 +42,4 @@
     virtual int       readBytes(byte* data, int maxLength, int * reciever);
 
-
   private:
     void init();
@@ -70,4 +69,5 @@
 
     Vector                velocity;           //!< the velocity of the player.
+    Vector                oldVelocity;        //!< the velocity the player had last synced
     Quaternion            mouseDir;           //!< the direction where the player wants to fly
     Quaternion            oldMouseDir;        //!< the direction where the player wanted to fly
Index: trunk/src/world_entities/terrain.cc
===================================================================
--- trunk/src/world_entities/terrain.cc	(revision 6814)
+++ trunk/src/world_entities/terrain.cc	(revision 6815)
@@ -325,5 +325,5 @@
 
   SYNCHELP_READ_BEGIN();
-  SYNCHELP_READ_FKT( WorldEntity::writeState );
+  SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_TER_WE_STATE );
 
   return SYNCHELP_READ_N;
@@ -343,5 +343,7 @@
     *reciever = rec;
 
-    return WorldEntity::readState( data, maxLength );
+    SYNCHELP_WRITE_BEGIN();
+    SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_TER_WE_STATE );
+    return SYNCHELP_WRITE_N;
 
   }
Index: trunk/src/world_entities/world_entity.cc
===================================================================
--- trunk/src/world_entities/world_entity.cc	(revision 6814)
+++ trunk/src/world_entities/world_entity.cc	(revision 6815)
@@ -518,8 +518,8 @@
   SYNCHELP_READ_BEGIN();
 
-  SYNCHELP_READ_FKT( PNode::writeState );
-
-  SYNCHELP_READ_STRINGM( modelFileName );
-  SYNCHELP_READ_FLOAT( scaling );
+  SYNCHELP_READ_FKT( PNode::writeState, NWT_WE_PN_WRITESTATE );
+
+  SYNCHELP_READ_STRINGM( modelFileName, NWT_WE_PN_MODELFILENAME );
+  SYNCHELP_READ_FLOAT( scaling, NWT_WE_PN_SCALING );
   //check if modelFileName is relative to datadir or absolute
 
@@ -562,5 +562,5 @@
   SYNCHELP_WRITE_BEGIN();
 
-  SYNCHELP_WRITE_FKT( PNode::readState );
+  SYNCHELP_WRITE_FKT( PNode::readState, NWT_WE_PN_WRITESTATE );
 
   if ( getModel(0) && getModel(0)->getName() )
@@ -573,12 +573,12 @@
     }
 
-    SYNCHELP_WRITE_STRING( name );
+    SYNCHELP_WRITE_STRING( name, NWT_WE_PN_MODELFILENAME );
   }
   else
   {
-    SYNCHELP_WRITE_STRING("");
-  }
-
-  SYNCHELP_WRITE_FLOAT( scaling );
+    SYNCHELP_WRITE_STRING("", NWT_WE_PN_MODELFILENAME);
+  }
+
+  SYNCHELP_WRITE_FLOAT( scaling, NWT_WE_PN_SCALING );
   /*if ( this->md2TextureFileName!=NULL && strcmp(this->md2TextureFileName, "") )
   {
