Index: trunk/src/world_entities/environments/water.cc
===================================================================
--- trunk/src/world_entities/skybox.cc	(revision 6341)
+++ trunk/src/world_entities/environments/water.cc	(revision 6455)
@@ -16,262 +16,61 @@
 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
 
-#include "skybox.h"
+#include "water.h"
+#include "factory.h"
+#include "load_param.h"
 
-#include "load_param.h"
-#include "factory.h"
-#include "static_model.h"
-#include "material.h"
-#include "network_game_manager.h"
-#include "converter.h"
+#include "grid.h"
 
 using namespace std;
 
-CREATE_FACTORY(SkyBox, CL_SKYBOX);
+CREATE_FACTORY(Water, CL_WATER);
 
-/**
- * Constructs a SkyBox and takes fileName as a map.
- * @param fileName the file to take as input for the SkyBox
-*/
-SkyBox::SkyBox(const char* fileName)
+
+Water::Water(const TiXmlElement* root)
 {
-  this->preInit();
-  if (fileName)
-    this->setTextureAndType(fileName, ".jpg");
-  this->postInit();
+  this->resX = this->resY = 10;
+  this->sizeX = this->sizeY = 1.0;
+  this->grid = NULL;
+
+  if (root != NULL)
+    this->loadParams(root);
 }
 
-/**
- *  initializes a skybox from a XmlElement
-*/
-SkyBox::SkyBox(const TiXmlElement* root)
+Water::~Water()
 {
-  this->preInit();
 
-  this->loadParams(root);
-
-  this->postInit();
 }
 
-void SkyBox::loadParams(const TiXmlElement* root)
+void Water::loadParams(const TiXmlElement* root)
 {
-  static_cast<WorldEntity*>(this)->loadParams(root);
+  WorldEntity::loadParams(root);
 
-  LoadParam(root, "Materialset", this, SkyBox, setTexture)
-      .describe("Sets the material on the SkyBox. The string must be the path relative to the data-dir, and without a trailing .jpg");
+  LoadParam(root, "size", this, Water, setSize)
+      .describe("the size of the WaterSurface")
+      .defaultValues(2, 1.0f, 1.0f);
 
-  LoadParam(root, "Size", this, SkyBox, setSize)
-      .describe("Sets the Size of the SkyBox (normally this should be 90% of the maximal viewing Distance).");
+  LoadParam(root, "resolution", this, Water, setResolution)
+      .describe("sets the resolution of the water surface")
+      .defaultValues(2, 10, 10);
 }
 
-void SkyBox::preInit()
+void Water::rebuildGrid()
 {
-  this->setClassID(CL_SKYBOX, "SkyBox");
-  this->toList(OM_ENVIRON_NOTICK);
-  this->size = 100.0;
+  if (this->grid != NULL)
+    delete this->grid;
+  this->grid = new Grid(this->sizeX, this->sizeY, this->resX, this->resY);
 
-  for (int i = 0; i < 6; i++)
-    {
-      this->material[i] = new Material();
-      this->material[i]->setIllum(3);
-      this->material[i]->setDiffuse(0.0,0.0,0.0);
-      this->material[i]->setSpecular(0.0,0.0,0.0);
-      this->material[i]->setAmbient(2.0, 2.0, 2.0);
-    }
-  this->setParentMode(PNODE_MOVEMENT);
-
-  this->textureName = NULL;
 }
 
-void SkyBox::postInit()
+void Water::setResolution(unsigned int resX, unsigned int resY)
 {
-  this->rebuild();
+  this->resX = resX;
+  this->resY = resY;
 }
 
-
-/**
- *  default destructor
-*/
-SkyBox::~SkyBox()
+void Water::setSize(float sizeX, float sizeY)
 {
-  PRINTF(5)("Deleting SkyBox\n");
-  this->setModel(NULL); //< so that WorldEntity does not try to delete it again.
-  for (int i = 0; i < 6; i++)
-    delete this->material[i];
+  this->sizeX = sizeX;
+  this->sizeY = sizeY;
 }
 
-/**
- *  sets A set of textures when just giving a Name and an extension:
-
-   usage: give this function an argument like
-   setTexture("skybox", "jpg");
-   and it will convert this to
-   setTextures("skybox_top.jpg", "skybox_bottom.jpg", "skybox_left.jpg",
-               "skybox_right.jpg", "skybox_front.jpg", "skybox_back.jpg");
-*/
-void SkyBox::setTextureAndType(const char* name, const char* extension)
-{
-  char* top    = new char[strlen(name)+strlen(extension)+ 10];
-  char* bottom = new char[strlen(name)+strlen(extension)+ 10];
-  char* left   = new char[strlen(name)+strlen(extension)+ 10];
-  char* right  = new char[strlen(name)+strlen(extension)+ 10];
-  char* front  = new char[strlen(name)+strlen(extension)+ 10];
-  char* back   = new char[strlen(name)+strlen(extension)+ 10];
-
-  sprintf(top, "%s_top.%s", name, extension);
-  sprintf(bottom, "%s_bottom.%s", name, extension);
-  sprintf(left, "%s_left.%s", name, extension);
-  sprintf(right, "%s_right.%s", name, extension);
-  sprintf(front, "%s_front.%s", name, extension);
-  sprintf(back, "%s_back.%s", name, extension);
-
-  this->setTextures(top, bottom, left, right, front, back);
-
-  // deleted alocated memory of this function
-  delete []top;
-  delete []bottom;
-  delete []left;
-  delete []right;
-  delete []front;
-  delete []back;
-}
-
-/**
- *  Defines which textures should be loaded onto the SkyBox.
- * @param top the top texture.
- * @param bottom the bottom texture.
- * @param left the left texture.
- * @param right the right texture.
- * @param front the front texture.
- * @param back the back texture.
-*/
-void SkyBox::setTextures(const char* top, const char* bottom, const char* left, const char* right, const char* front, const char* back)
-{
-  this->material[0]->setDiffuseMap(top);
-  this->material[1]->setDiffuseMap(bottom);
-  this->material[2]->setDiffuseMap(left);
-  this->material[3]->setDiffuseMap(right);
-  this->material[4]->setDiffuseMap(front);
-  this->material[5]->setDiffuseMap(back);
-}
-
-/**
- * @param size The new size of the SkyBox
-
- * do not forget to rebuild the SkyBox after this.
-*/
-void SkyBox::setSize(float size)
-{
-  this->size = size;
-}
-
-/**
- *  rebuilds the SkyBox
-
-   this must be done, when changing the Size of the Skybox (runtime-efficency)
-*/
-void SkyBox::rebuild()
-{
-  StaticModel* model = new StaticModel();
-
-  model->addVertex (-0.5*size, -0.5*size, 0.5*size);
-  model->addVertex (0.5*size, -0.5*size, 0.5*size);
-  model->addVertex (-0.5*size, 0.5*size, 0.5*size);
-  model->addVertex (0.5*size, 0.5*size, 0.5*size);
-  model->addVertex (-0.5*size, 0.5*size, -0.5*size);
-  model->addVertex (0.5*size, 0.5*size, -0.5*size);
-  model->addVertex (-0.5*size, -0.5*size, -0.5*size);
-  model->addVertex (0.5*size, -0.5*size, -0.5*size);
-
-  model->addVertexTexture (0.0, 1.0);
-  model->addVertexTexture (1.0, 1.0);
-  model->addVertexTexture (1.0, 0.0);
-  model->addVertexTexture (0.0, 0.0);
-
-  model->addVertexNormal (0.0, 0.0, 1.0);
-  model->addVertexNormal (0.0, 1.0, 0.0);
-  model->addVertexNormal (0.0, 0.0, -1.0);
-  model->addVertexNormal (0.0, -1.0, 0.0);
-  model->addVertexNormal (1.0, 0.0, 0.0);
-  model->addVertexNormal (-1.0, 0.0, 0.0);
-
-  model->setMaterial(material[0]);
-  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,0,3, 3,1,3, 5,2,3, 4,3,3); // top
-  model->setMaterial(material[1]);
-  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,0,1, 7,1,1, 1,2,1, 0,3,1); // bottom
-  model->setMaterial(material[2]);
-  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 4,2,2, 5,3,2, 7,0,2, 6,1,2); // left
-  model->setMaterial(material[3]);
-  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 0,0,0, 1,1,0, 3,2,0, 2,3,0); // right
-  model->setMaterial(material[4]);
-  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,0,5, 7,1,5, 5,2,5, 3,3,5); // front
-  model->setMaterial(material[5]);
-  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,0,4, 0,1,4, 2,2,4, 4,3,4); // back
-
-  model->finalize();
-
-  this->setModel(model);
-}
-
-int SkyBox::writeBytes( const byte * data, int length, int sender )
-{
-  setRequestedSync( false );
-  setIsOutOfSync( false );
-
-  SYNCHELP_READ_BEGIN();
-
-  SYNCHELP_READ_FKT( WorldEntity::writeState );
-
-  SYNCHELP_READ_FLOAT( size );
-  if ( textureName )
-  {
-    delete[] textureName;
-    textureName = NULL;
-  }
-  SYNCHELP_READ_STRINGM( textureName );
-
-  PRINT(0)("GOT DATA: size=%f texture='%s'\n", size, textureName);
-
-  this->setSize( size );
-  this->setTextureAndType( textureName, "jpg" );
-  this->rebuild();
-
-  return SYNCHELP_READ_N;
-}
-
-
-
-int SkyBox::readBytes( byte * data, int maxLength, int * reciever )
-{
-  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
-  {
-    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
-    setRequestedSync( true );
-  }
-
-  int rec = this->getRequestSync();
-  if ( rec > 0 )
-  {
-    PRINT(0)("SEND DATA: size=%f texture='%s'\n", size, textureName);
-    *reciever = rec;
-
-    SYNCHELP_WRITE_BEGIN();
-
-    SYNCHELP_WRITE_FKT( WorldEntity::readState );
-
-    SYNCHELP_WRITE_FLOAT(this->size);
-    SYNCHELP_WRITE_STRING(this->textureName);
-
-    return SYNCHELP_WRITE_N;
-  }
-
-  *reciever = 0;
-  return 0;
-}
-
-void SkyBox::writeDebug( ) const
-{
-}
-
-void SkyBox::readDebug( ) const
-{
-}
