]> git.treefish.org Git - seamulator.git/blobdiff - seamulator.cpp
Replaced sea and surface refs with shared pointers
[seamulator.git] / seamulator.cpp
index 6bb51c9460df936cb0da508eadd6279ccecdc85c..b6739b5641f1a3332f6f2ddf63f8d2aa931a1e7d 100644 (file)
@@ -8,20 +8,20 @@
 const int LATTICE_SIZE = 10;
 const int LATTICE_UNIT = 1;
 
-WaterSurface surface(LATTICE_SIZE);
-Sea sea(surface);
+SeaPtr sea;
+WaterSurfacePtr surface;
 
 void drawSingleTile(int x, int y)
 {
   glBegin(GL_TRIANGLES);
 
-  glVertex3f(x, y, surface.at(x, y).getHeight());
-  glVertex3f(x+1, y, surface.at(x+1, y).getHeight());
-  glVertex3f(x+1, y+1, surface.at(x+1, y+1).getHeight());
+  glVertex3f(x, y, surface->at(x, y).getHeight());
+  glVertex3f(x+1, y, surface->at(x+1, y).getHeight());
+  glVertex3f(x+1, y+1, surface->at(x+1, y+1).getHeight());
 
-  glVertex3f(x, y, surface.at(x, y).getHeight());
-  glVertex3f(x, y+1, surface.at(x, y+1).getHeight());
-  glVertex3f(x+1, y+1, surface.at(x+1, y+1).getHeight());
+  glVertex3f(x, y, surface->at(x, y).getHeight());
+  glVertex3f(x, y+1, surface->at(x, y+1).getHeight());
+  glVertex3f(x+1, y+1, surface->at(x+1, y+1).getHeight());
 
   glEnd();
 }
@@ -37,7 +37,7 @@ void displayMe(void)
 
   glClear(GL_COLOR_BUFFER_BIT);
 
-  sea.update();
+  sea->update();
 
   glScalef(LATTICE_UNIT, LATTICE_UNIT, 1.0f);
   glTranslatef(-(float)(LATTICE_SIZE-1)/2, -(float)(LATTICE_SIZE-1)/2, 0);
@@ -56,6 +56,9 @@ int main(int argc, char** argv)
 {
   std::srand(std::time(0));
 
+  surface = std::make_shared<WaterSurface>(LATTICE_SIZE);
+  sea = std::make_shared<Sea>(surface);
+
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
   glEnable(GL_DEPTH_TEST);