glob2-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[glob2-devel] Cleanups...


From: simon schuler
Subject: [glob2-devel] Cleanups...
Date: Sun, 23 Jan 2005 17:36:30 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041229

I was a bit browsing through the code today, triing to understand the whole code. Sometimes the code isn't easy to understand, but that's normal for such a project... I found a lot of loops, which are (in my opinion) useless. I have attached a patch to remove some useless loops, and replace them with equivalent code.

Summary of the patch: I removed the bool gradientUpdated[32][MAX_NB_RESSOURCES][2] array and replaced it with equivalent faster code.

simon


diff -up globold/src/Map.cpp glob2/src/Map.cpp
--- globold/src/Map.cpp 2005-01-23 17:09:52.228982952 +0000
+++ glob2/src/Map.cpp   2005-01-23 17:09:01.190741944 +0000
@@ -80,12 +80,12 @@ Map::Map()
        fogOfWarA=NULL;
        fogOfWarB=NULL;
        cases=NULL;
+       resetgradients=true;
        for (int t=0; t<32; t++)
                for (int r=0; r<MAX_NB_RESSOURCES; r++)
                        for (int s=0; s<2; s++)
                        {
                                ressourcesGradient[t][r][s] = NULL;
-                               gradientUpdated[t][r][s] = false;
                        }
        for (int t=0; t<32; t++)
                for (int s=0; s<2; s++)
@@ -285,10 +285,7 @@ void Map::clear()
        wSector=hSector=0;
        sizeSector=0;
        
-       for (int t=0; t<32; t++)
-               for (int r=0; r<MAX_RESSOURCES; r++)
-                       for (int s=0; s<2; s++)
-                               gradientUpdated[t][r][s]=false;
+       resetgradients=true;
        
        
        fprintf(logFile, "\n");
@@ -992,10 +989,7 @@ bool Map::load(GAGCore::InputStream *str
                                        ressourcesGradient[t][r][s]=new 
Uint8[size];
                                        updateRessourcesGradient(t, r, (bool)s);
                                }
-               for (int t=0; t<32; t++)
-                       for (int r=0; r<MAX_RESSOURCES; r++)
-                               for (int s=0; s<1; s++)
-                                       gradientUpdated[t][r][s]=false;
+               resetgradients=true;
 
                for (int t=0; t<sessionGame->numberOfTeam; t++)
                        for (int s=0; s<2; s++)
@@ -1208,23 +1202,26 @@ void Map::syncStep(Uint32 stepCounter)
                sectors[i].step();
        
        // We only update one gradient per step:
-       bool updated=false;
-       while (!updated)
+       static unsigned int t=0,  r=0, s=0;
+       if(resetgradients)
        {
-               int numberOfTeam=game->session.numberOfTeam;
-               for (int t=0; t<numberOfTeam; t++)
-                       for (int r=0; r<MAX_RESSOURCES; r++)
-                               for (int s=0; s<2; s++)
-                                       if (!gradientUpdated[t][r][s])
-                                       {
-                                               updateRessourcesGradient(t, r, 
(bool)s);
-                                               gradientUpdated[t][r][s]=true;
-                                               return;
-                                       }
-               for (int t=0; t<numberOfTeam; t++)
-                       for (int r=0; r<MAX_RESSOURCES; r++)
-                               for (int s=0; s<2; s++)
-                                       gradientUpdated[t][r][s]=false;
+               t=r=s=0;
+               resetgradients=false;
+       }
+       int numberOfTeam=game->session.numberOfTeam;
+       updateRessourcesGradient(t, r, (bool)s);
+       s++;
+       if(s>=2)
+       {
+               s=0;
+               r++;
+               if(r>=MAX_RESSOURCES)
+               {
+                       r=0;
+                       t++;
+                       if(t>=numberOfTeam)
+                               t=0;
+               }
        }
 }
 
diff -up globold/src/Map.h glob2/src/Map.h
--- globold/src/Map.h   2005-01-23 17:09:52.230982648 +0000
+++ glob2/src/Map.h     2005-01-23 17:04:33.446445264 +0000
@@ -558,7 +558,7 @@ public:
        
 protected:
        //Used for scheduling computation time.
-       bool gradientUpdated[32][MAX_NB_RESSOURCES][2];
+       bool resetgradients;
        Uint8 *undermap;
        size_t size;
        

reply via email to

[Prev in Thread] Current Thread [Next in Thread]