backing up some stuff
authorPerttu Ahola <celeron55@gmail.com>
Wed, 26 Jan 2011 15:13:19 +0000 (17:13 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Wed, 26 Jan 2011 15:13:19 +0000 (17:13 +0200)
src/debug.cpp
src/main.cpp
src/mapblock.cpp
src/mapnode.cpp
src/utility.cpp
src/utility.h

index ca49c9b770f831b008e899af1f36d1cf46ddcd0e..f267790fd3df64881ebdbd39ce9105847e81fd01 100644 (file)
@@ -32,6 +32,8 @@ void debugstreams_init(bool disable_stderr, const char *filename)
 {
        if(disable_stderr)
                g_debugstreams[0] = NULL;
+       else
+               g_debugstreams[0] = stderr;
 
        if(filename)
                g_debugstreams[1] = fopen(filename, "a");
@@ -42,6 +44,9 @@ void debugstreams_init(bool disable_stderr, const char *filename)
                fprintf(g_debugstreams[1],     "  Separator  \n");
                fprintf(g_debugstreams[1],     "-------------\n\n");
        }
+       
+       DEBUGPRINT("Debug streams initialized, disable_stderr=%d\n",
+                       disable_stderr);
 }
 
 void debugstreams_deinit()
index d2b67e9a879571469977e01da32f204187f00647..388ab8089eeb166888f48b80b88993fdeb892130 100644 (file)
@@ -104,12 +104,8 @@ SUGG: Meshes of blocks could be split into 6 meshes facing into
 Gaming ideas:\r
 -------------\r
 \r
-- How would some GTA-style ideas work?\r
-  - Cars? Stealing? Unlawful stuff and cops? Lots of guns?\r
+- Aim for something like controlling a single dwarf in Dwarf Fortress.\r
 \r
-- RPG style?\r
-\r
-- Space racer style?\r
 \r
 Documentation:\r
 --------------\r
@@ -286,9 +282,16 @@ TODO: Remove duplicate lighting implementation from Map (leave
       VoxelManipulator, which is faster)\r
 \r
 FIXME: The new texture stuff is slow on wine\r
-       - Actually it is not too slow; updating excess amount of meshes\r
-         when making footprints is too slow. It has to be fixed.\r
+       - A basic grassy ground block takes 20-40ms\r
+       - A bit more complicated block can take 270ms\r
+         - On linux, a similar one doesn't take long at all (14ms)\r
+           - Is it a bad std::string implementation of MSVC?\r
+       - Can take up to 200ms? Is it when loading textures or always?\r
+       - Updating excess amount of meshes when making footprints is too\r
+         slow. It has to be fixed.\r
          -> implement Map::updateNodeMeshes()\r
+       TODO: Optimize TileSpec to only contain a reference number that\r
+             is fast to compare, which refers to a cached string\r
 \r
 Doing now:\r
 ----------\r
@@ -1266,41 +1269,106 @@ struct ChatLine
        std::wstring text;\r
 };\r
 \r
-int main(int argc, char *argv[])\r
+// These are defined global so that they're not optimized too much.\r
+// Can't change them to volatile.\r
+s16 temp16;\r
+f32 tempf;\r
+v3f tempv3f1;\r
+v3f tempv3f2;\r
+std::string tempstring;\r
+std::string tempstring2;\r
+\r
+void SpeedTests()\r
 {\r
-       /*\r
-               Low-level initialization\r
-       */\r
+       {\r
+               dstream<<"The following test should take around 20ms."<<std::endl;\r
+               TimeTaker timer("Testing std::string speed");\r
+               const u32 jj = 10000;\r
+               for(u32 j=0; j<jj; j++)\r
+               {\r
+                       tempstring = "";\r
+                       tempstring2 = "";\r
+                       const u32 ii = 10;\r
+                       for(u32 i=0; i<ii; i++){\r
+                               tempstring2 += "asd";\r
+                       }\r
+                       for(u32 i=0; i<ii+1; i++){\r
+                               tempstring += "asd";\r
+                               if(tempstring == tempstring2)\r
+                                       break;\r
+                       }\r
+               }\r
+       }\r
+       \r
+       dstream<<"All of the following tests should take around 100ms each."\r
+                       <<std::endl;\r
 \r
-       bool disable_stderr = false;\r
-#ifdef _WIN32\r
-       disable_stderr = true;\r
-#endif\r
+       {\r
+               TimeTaker timer("Testing floating-point conversion speed");\r
+               tempf = 0.001;\r
+               for(u32 i=0; i<4000000; i++){\r
+                       temp16 += tempf;\r
+                       tempf += 0.001;\r
+               }\r
+       }\r
+       \r
+       {\r
+               TimeTaker timer("Testing floating-point vector speed");\r
 \r
-       // Initialize debug streams\r
-       debugstreams_init(disable_stderr, DEBUGFILE);\r
-       // Initialize debug stacks\r
-       debug_stacks_init();\r
+               tempv3f1 = v3f(1,2,3);\r
+               tempv3f2 = v3f(4,5,6);\r
+               for(u32 i=0; i<10000000; i++){\r
+                       tempf += tempv3f1.dotProduct(tempv3f2);\r
+                       tempv3f2 += v3f(7,8,9);\r
+               }\r
+       }\r
 \r
-       DSTACK(__FUNCTION_NAME);\r
+       {\r
+               TimeTaker timer("Testing core::map speed");\r
+               \r
+               core::map<v2s16, f32> map1;\r
+               tempf = -324;\r
+               const s16 ii=300;\r
+               for(s16 y=0; y<ii; y++){\r
+                       for(s16 x=0; x<ii; x++){\r
+                               map1.insert(v2s16(x,y), tempf);\r
+                               tempf += 1;\r
+                       }\r
+               }\r
+               for(s16 y=ii-1; y>=0; y--){\r
+                       for(s16 x=0; x<ii; x++){\r
+                               tempf = map1[v2s16(x,y)];\r
+                       }\r
+               }\r
+       }\r
 \r
-       porting::initializePaths();\r
-       // Create user data directory\r
-       fs::CreateDir(porting::path_userdata);\r
-       \r
-       // C-style stuff initialization\r
-       initializeMaterialProperties();\r
-       init_mapnode();\r
+       {\r
+               dstream<<"Around 5000/ms should do well here."<<std::endl;\r
+               TimeTaker timer("Testing mutex speed");\r
+               \r
+               JMutex m;\r
+               m.Init();\r
+               u32 n = 0;\r
+               u32 i = 0;\r
+               do{\r
+                       n += 10000;\r
+                       for(; i<n; i++){\r
+                               m.Lock();\r
+                               m.Unlock();\r
+                       }\r
+               }\r
+               // Do at least 10ms\r
+               while(timer.getTime() < 10);\r
 \r
-       // Debug handler\r
-       BEGIN_DEBUG_EXCEPTION_HANDLER\r
+               u32 dtime = timer.stop();\r
+               u32 per_ms = n / dtime;\r
+               std::cout<<"Done. "<<dtime<<"ms, "\r
+                               <<per_ms<<"/ms"<<std::endl;\r
+       }\r
+}\r
 \r
-       // Print startup message\r
-       dstream<<DTIME<<"minetest-c55"\r
-                       " with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST\r
-                       <<", "<<BUILD_INFO\r
-                       <<std::endl;\r
-       \r
+int main(int argc, char *argv[])\r
+{\r
        /*\r
                Parse command line\r
        */\r
@@ -1318,6 +1386,10 @@ int main(int argc, char *argv[])
        allowed_options.insert("disable-unittests", ValueSpec(VALUETYPE_FLAG));\r
        allowed_options.insert("enable-unittests", ValueSpec(VALUETYPE_FLAG));\r
        allowed_options.insert("map-dir", ValueSpec(VALUETYPE_STRING));\r
+#ifdef _WIN32\r
+       allowed_options.insert("dstream-on-stderr", ValueSpec(VALUETYPE_FLAG));\r
+#endif\r
+       allowed_options.insert("speedtests", ValueSpec(VALUETYPE_FLAG));\r
 \r
        Settings cmd_args;\r
        \r
@@ -1349,8 +1421,41 @@ int main(int argc, char *argv[])
 \r
                return cmd_args.getFlag("help") ? 0 : 1;\r
        }\r
+       \r
+       /*\r
+               Low-level initialization\r
+       */\r
+\r
+       bool disable_stderr = false;\r
+#ifdef _WIN32\r
+       if(cmd_args.getFlag("dstream-on-stderr") == false)\r
+               disable_stderr = true;\r
+#endif\r
 \r
+       // Initialize debug streams\r
+       debugstreams_init(disable_stderr, DEBUGFILE);\r
+       // Initialize debug stacks\r
+       debug_stacks_init();\r
 \r
+       DSTACK(__FUNCTION_NAME);\r
+\r
+       porting::initializePaths();\r
+       // Create user data directory\r
+       fs::CreateDir(porting::path_userdata);\r
+       \r
+       // C-style stuff initialization\r
+       initializeMaterialProperties();\r
+       init_mapnode();\r
+\r
+       // Debug handler\r
+       BEGIN_DEBUG_EXCEPTION_HANDLER\r
+\r
+       // Print startup message\r
+       dstream<<DTIME<<"minetest-c55"\r
+                       " with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST\r
+                       <<", "<<BUILD_INFO\r
+                       <<std::endl;\r
+       \r
        /*\r
                Basic initialization\r
        */\r
@@ -1519,7 +1624,15 @@ int main(int argc, char *argv[])
        g_device = device;\r
        g_irrlicht = new IrrlichtWrapper(device);\r
 \r
-       //g_device = device;\r
+       /*\r
+               Speed tests (done after irrlicht is loaded to get timer)\r
+       */\r
+       if(cmd_args.getFlag("speedtests"))\r
+       {\r
+               dstream<<"Running speed tests"<<std::endl;\r
+               SpeedTests();\r
+               return 0;\r
+       }\r
        \r
        device->setResizable(true);\r
 \r
index 15f3ad9a67591748161185b4b17b1d70c86d1e5e..f06dbc81120ab98e99867c91e714d3b6cf4e009b 100644 (file)
@@ -601,7 +601,7 @@ void MapBlock::updateMesh(u32 daynight_ratio)
        */
        
        {
-               //TimeTaker timer2("updateMesh() collect");
+               TimeTaker timer2("updateMesh() collect");
 
                // Lock this, as m_temp_mods will be used directly
                JMutexAutoLock lock(m_temp_mods_mutex);
index ebae055db415baed13fcd00ea65203b7a05d35d1..7625fab68f31a74d61654a3b1eef31b017320dde 100644 (file)
@@ -160,7 +160,9 @@ TileSpec MapNode::getTile(v3s16 dir)
        
        s32 dir_i = -1;
        
-       if(dir == v3s16(0,1,0))
+       if(dir == v3s16(0,0,0))
+               dir_i = -1;
+       else if(dir == v3s16(0,1,0))
                dir_i = 0;
        else if(dir == v3s16(0,-1,0))
                dir_i = 1;
index 65615f9c93e6cd67cfaa7a7f8af4ac3d9676b48e..8b2b78b447f7290f7515acaf7dfd6147863a0925 100644 (file)
@@ -54,6 +54,13 @@ u32 TimeTaker::stop(bool quiet)
        return 0;
 }
 
+u32 TimeTaker::getTime()
+{
+       u32 time2 = getTimeMs();
+       u32 dtime = time2 - m_time1;
+       return dtime;
+}
+
 const v3s16 g_26dirs[26] =
 {
        // +right, +top, +back
index 785ff167cb391c122e3e1d5d4679e04bc1113b68..b517848b1223440d9dc3564d3d3828134075405e 100644 (file)
@@ -409,6 +409,8 @@ public:
 
        u32 stop(bool quiet=false);
 
+       u32 getTime();
+
 private:
        const char *m_name;
        u32 m_time1;