[Orxonox-commit 6177] r10835 - in code/branches/hoverHS15: cmake src/modules/hover

meierman at orxonox.net meierman at orxonox.net
Mon Nov 23 15:32:48 CET 2015


Author: meierman
Date: 2015-11-23 15:32:48 +0100 (Mon, 23 Nov 2015)
New Revision: 10835

Modified:
   code/branches/hoverHS15/cmake/CompilerConfigGCC.cmake
   code/branches/hoverHS15/src/modules/hover/Hover.cc
   code/branches/hoverHS15/src/modules/hover/Hover.h
Log:
Maze Generator works

Modified: code/branches/hoverHS15/cmake/CompilerConfigGCC.cmake
===================================================================
--- code/branches/hoverHS15/cmake/CompilerConfigGCC.cmake	2015-11-23 12:24:51 UTC (rev 10834)
+++ code/branches/hoverHS15/cmake/CompilerConfigGCC.cmake	2015-11-23 14:32:48 UTC (rev 10835)
@@ -71,6 +71,7 @@
 # Never omit frame pointers that could interfere with proper stack traces
 ADD_COMPILER_FLAGS("-fno-omit-frame-pointer" CACHE)
 
+
 # Enable non standard floating point optimisations
 ADD_COMPILER_FLAGS("-ffast-math" CACHE)
 

Modified: code/branches/hoverHS15/src/modules/hover/Hover.cc
===================================================================
--- code/branches/hoverHS15/src/modules/hover/Hover.cc	2015-11-23 12:24:51 UTC (rev 10834)
+++ code/branches/hoverHS15/src/modules/hover/Hover.cc	2015-11-23 14:32:48 UTC (rev 10835)
@@ -37,26 +37,65 @@
 #include "HoverWall.h"
 #include "core/CoreIncludes.h"
 
+#include <iostream>
+#include <string>
+#include <time.h>
+#include <stdlib.h>
+#include <memory.h>
+#include <stdint.h>
+#include <fstream>
+
+
 namespace orxonox
 {
     bool firstTick = true;
     int levelcode[10][10] =
         {
-        { 0,0,0,0,0,0,0,0,0,0 }, // row 0
-        { 1,0,0,0,0,0,0,0,0,0 }, // row 0
-        { 1,0,0,0,0,0,0,0,0,0 }, // row 0
-        { 1,1,3,0,1,3,0,0,0,0 }, // row 0
-        { 1,0,3,2,3,2,0,0,0,0 }, // row 0
-        { 1,0,1,0,1,0,0,0,0,0 }, // row 0
-        { 1,2,2,0,0,0,0,0,0,0 }, // row 0
-        { 1,0,0,0,0,0,0,0,0,0 },  // row 0
-        { 1,0,0,0,0,0,0,0,1,0 },// row 1
-        { 1,0,0,0,0,0,0,1,2,0 } // row 2
+        { 0,0,0,0,0,0,0,0,0,0 }, 
+        { 0,0,0,0,0,0,0,0,0,0 }, 
+        { 0,0,0,0,0,0,0,0,0,0 }, 
+        { 0,0,0,0,0,0,0,0,0,0 }, 
+        { 0,0,0,0,0,0,0,0,0,0 }, 
+        { 0,0,0,0,0,0,0,0,0,0 }, 
+        { 0,0,0,0,0,0,0,0,0,0 }, 
+        { 0,0,0,0,0,0,0,0,0,0 }, 
+        { 0,0,0,0,0,0,0,0,0,0 }, 
+        { 0,0,0,0,0,0,0,0,0,0 }
         };
 
+    const int NumCells  = 10;
+    unsigned char* g_Maze = new unsigned char[ NumCells* NumCells ];
 
+    // current traversing position
+    int g_PtX;
+    int g_PtY;
+
+    // return the current index in g_Maze
+    int Hover::CellIdx()
+    {
+        return g_PtX + NumCells * g_PtY;
+    }   
+
+
+    int Hover::RandomInt()
+    {
+        return (rand() % NumCells);
+    }
+
+    int Hover::RandomInt4()
+    {
+        return (rand() % 4);
+    }
+
+
     RegisterUnloadableClass(Hover);
 
+
+
+
+
+
+
     Hover::Hover(Context* context) : Gametype(context)
     {
         
@@ -75,11 +114,17 @@
 
         if(firstTick)
         {
+            std::fill( g_Maze, g_Maze + NumCells * NumCells, 0 );
+            g_PtX=0;
+            g_PtY=0;
+            GenerateMaze();
+            MazeOut();
+            RenderMaze();
+            LevelOut();
             firstTick = false;
 
             for(int y=0; y<10; y++){
                 for(int x=0; x<10; x++){
-
                     switch(levelcode[y][x]){
                         case 1: new HoverWall(origin_->getContext(), x+1, 10-y, 1);
                                 break;
@@ -95,8 +140,9 @@
 
 
             
-            //new HoverWall(origin_->getContext(), 1, 1, 1);
-            //new HoverWall(origin_->getContext(), 1, 1, 0);
+            //new HoverWall(origin_->getContext(), 1, 1, 1); //Rechts in Y Richtung
+            //new HoverWall(origin_->getContext(), 5, 6, 0); //Ueber in x richtung
+            //new HoverWall(origin_->getContext(), 5, 5, 0); //Ueber in x richtung
         }      
 
 
@@ -121,4 +167,166 @@
         // Instead startMainMenu, this won't crash.
         GSLevel::startMainMenu();
     }
+
+
+
+
+    ////////////////////////////////////////////////////////////////////////////
+
+
+    //                   0  1  2  3  4  5  6  7  8
+    //                      U  R     D           L
+    int Heading_X[9] = { 0, 0,+1, 0, 0, 0, 0, 0,-1 };
+    int Heading_Y[9] = { 0,-1, 0, 0,+1, 0, 0, 0, 0 };
+    int Mask[9]      = {
+                                0,
+                                eDirection_Down | eDirection_Down << 4,
+                                eDirection_Left | eDirection_Left << 4,
+                                0,
+                                eDirection_Up | eDirection_Up << 4,
+                                0,
+                                0,
+                                0,
+                                eDirection_Right | eDirection_Right << 4
+                            };
+
+
+    ////////////////////////////////////////////////////////////////////////////
+
+    bool Hover::IsDirValid( eDirection Dir )
+    {
+        int NewX = g_PtX + Heading_X[ Dir ];
+        int NewY = g_PtY + Heading_Y[ Dir ];
+
+        if ( !Dir || NewX < 0 || NewY < 0 || NewX >= NumCells || NewY >= NumCells ) return false;
+
+        return !g_Maze[ NewX + NumCells * NewY ];
+    }
+
+    eDirection Hover::GetDirection()
+    {
+        eDirection Dir = eDirection( 1 << RandomInt4() );
+
+        while ( true )
+        {
+            for ( int x = 0; x < 4; x++ )
+            {
+                if ( IsDirValid( Dir ) ) { return eDirection( Dir ); }
+
+                Dir = eDirection( Dir << 1 );
+
+                if ( Dir > eDirection_Left ) { Dir = eDirection_Up; }
+            }
+
+            Dir = eDirection( ( g_Maze[ CellIdx() ] & 0xf0 ) >> 4 );
+
+            // nowhere to go
+            if ( !Dir ) return eDirection_Invalid;
+
+            g_PtX += Heading_X[ Dir ];
+            g_PtY += Heading_Y[ Dir ];
+
+            Dir = eDirection( 1 << RandomInt4() );
+        }
+    }
+
+    void Hover::GenerateMaze()
+    {
+        int Cells = 0;
+
+        for ( eDirection Dir = GetDirection(); Dir != eDirection_Invalid; Dir = GetDirection() )
+        {
+            // a progress indicator, kind of
+           // if ( ++Cells % 1000 == 0 ) std::cout << ".";
+
+            g_Maze[ CellIdx() ] |= Dir;
+
+            g_PtX += Heading_X[ Dir ];
+            g_PtY += Heading_Y[ Dir ];
+
+            g_Maze[ CellIdx() ] = Mask[ Dir ];
+        }
+
+        std::cout << std::endl;
+    }  
+    
+
+    void Hover::MazeOut(){
+        for ( int y = 0; y < NumCells; y++ )
+        {
+            for ( int x = 0; x < NumCells; x++ )
+            {
+                char v = g_Maze[ y * NumCells + x ];
+                orxout()<<"[";
+                if ( ( v & eDirection_Up    ) ) orxout()<<"U";
+                else orxout()<<" ";
+                if ( ( v & eDirection_Right ) ) orxout()<<"R";
+                else orxout()<<" ";
+                if ( ( v & eDirection_Down  ) ) orxout()<<" ";
+                else orxout()<<" ";
+                if ( ( v & eDirection_Left  ) ) orxout()<<" ";
+                else orxout()<<" ";
+                orxout()<<"]";
+            }
+            orxout()<<endl;
+        }
+
+    }
+
+    void Hover::LevelOut(){
+        for ( int y = 0; y < NumCells; y++ )
+        {
+            for ( int x = 0; x < NumCells; x++ )
+            {
+                /*orxout()<<"[";
+                if ( levelcode[x][y] < 2) orxout()<<"U";
+                else orxout()<<" ";
+                if ( levelcode[x][y] % 2 == 0) orxout()<<"R";
+                else orxout()<<" ";
+
+                orxout()<<" ";
+                orxout()<<" ";
+                orxout()<<"]";*/
+
+                orxout()<<levelcode[x][y];
+            }
+            orxout()<<endl;
+        }
+
+
+
+    }
+
+    void Hover::RenderMaze()
+    {
+        for ( int y = 0; y < NumCells; y++ )
+        {
+            for ( int x = 0; x < NumCells; x++ )
+            {
+                char v = g_Maze[ y * NumCells + x ];
+
+                if ( !( v & eDirection_Up    ) && y >0) levelcode[y][x] |= 2;
+                if ( !( v & eDirection_Right ) && x <9) levelcode[y][x] |= 1;
+                //if ( !( v & eDirection_Down  ) && y>0) levelcode[x][y-1] += 2;
+                //if ( !( v & eDirection_Left  ) && x>0) levelcode[x-1][y] += 1;
+            }
+        }
+        for ( int y = 3; y < 7; y++ )
+        {
+            for ( int x = 3; x < 7; x++ )
+            {
+
+                if(y == 3 && x != 7)
+                    levelcode[y][x] &= 2;
+                else if (x == 7 && y != 3)
+                    levelcode[y][x] &= 1;
+                else if(x != 7)
+                    levelcode[y][x] = 0;
+            }
+        }
+
+    }
+
+
+
 }

Modified: code/branches/hoverHS15/src/modules/hover/Hover.h
===================================================================
--- code/branches/hoverHS15/src/modules/hover/Hover.h	2015-11-23 12:24:51 UTC (rev 10834)
+++ code/branches/hoverHS15/src/modules/hover/Hover.h	2015-11-23 14:32:48 UTC (rev 10835)
@@ -57,9 +57,20 @@
 
 #include "tools/Timer.h"
 
+
+
 namespace orxonox
 {
 
+    enum eDirection
+    {
+        eDirection_Invalid = 0,
+        eDirection_Up      = 1,
+        eDirection_Right   = 2,
+        eDirection_Down    = 4,
+        eDirection_Left    = 8
+    }; 
+
     class _HoverExport Hover : public Gametype
     {
        public:
@@ -79,6 +90,20 @@
 
             WeakPtr<HoverOrigin> origin_;
 
+        private:
+            int CellIdx();
+            int RandomInt();
+            int RandomInt4();
+
+
+            bool IsDirValid( eDirection Dir );
+            eDirection GetDirection();
+            void GenerateMaze();
+            void RenderMaze();
+            void MazeOut();
+            void LevelOut();
+
+
     };
 }
 




More information about the Orxonox-commit mailing list