cleaning up main.cpp a bit
authorPerttu Ahola <celeron55@gmail.com>
Sat, 23 Apr 2011 13:01:49 +0000 (16:01 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sat, 23 Apr 2011 13:01:49 +0000 (16:01 +0300)
src/main.cpp

index 2dfef7d1b8db27096cfee1dfc2ce9f611a84d6e8..af94387f678aba1b2ee386c2a76928d084b7ed75 100644 (file)
@@ -336,7 +336,7 @@ MapDrawControl draw_control;
 */\r
 \r
 Settings g_settings;\r
-\r
+// This is located in defaultsettings.cpp\r
 extern void set_default_settings();\r
 \r
 /*\r
@@ -346,12 +346,6 @@ extern void set_default_settings();
 IrrlichtDevice *g_device = NULL;\r
 Client *g_client = NULL;\r
 \r
-/*const s16 quickinv_size = 40;\r
-const s16 quickinv_padding = 8;\r
-const s16 quickinv_spacing = quickinv_size + quickinv_padding;\r
-const s16 quickinv_outer_padding = 4;\r
-const s16 quickinv_itemcount = 8;*/\r
-\r
 const s32 hotbar_itemcount = 8;\r
 const s32 hotbar_imagesize = 36;\r
 \r
@@ -362,6 +356,8 @@ const s32 hotbar_imagesize = 36;
 gui::IGUIEnvironment* guienv = NULL;\r
 gui::IGUIStaticText *guiroot = NULL;\r
 \r
+// Handler for the modal menus\r
+\r
 class MainMenuManager : public IMenuManager\r
 {\r
 public:\r
@@ -421,11 +417,16 @@ bool noMenuActive()
        return (g_menumgr.menuCount() == 0);\r
 }\r
 \r
-bool g_disconnect_requested = false;\r
+// Passed to menus to allow disconnecting and exiting\r
 \r
 class MainGameCallback : public IGameCallback\r
 {\r
 public:\r
+       MainGameCallback():\r
+               disconnect_requested(false)\r
+       {\r
+       }\r
+\r
        virtual void exitToOS()\r
        {\r
                g_device->closeDevice();\r
@@ -433,23 +434,25 @@ public:
 \r
        virtual void disconnect()\r
        {\r
-               g_disconnect_requested = true;\r
+               disconnect_requested = true;\r
        }\r
+\r
+       bool disconnect_requested;\r
 };\r
 \r
 MainGameCallback g_gamecallback;\r
 \r
+/*\r
+       Inventory stuff\r
+*/\r
+\r
 // Inventory actions from the menu are buffered here before sending\r
-// TODO: Get rid of this\r
 Queue<InventoryAction*> inventory_action_queue;\r
 // This is a copy of the inventory that the client's environment has\r
 Inventory local_inventory;\r
 \r
 u16 g_selected_item = 0;\r
 \r
-/*bool g_show_map_plot = false;\r
-bool g_refresh_map_plot = false;*/\r
-\r
 /*\r
        Debug streams\r
 */\r
@@ -562,6 +565,10 @@ struct TextDestSignNode : public TextDest
        Client *m_client;\r
 };\r
 \r
+/*\r
+       Event handler for Irrlicht\r
+*/\r
+\r
 class MyEventReceiver : public IEventReceiver\r
 {\r
 public:\r
@@ -801,6 +808,10 @@ private:
        IrrlichtDevice *m_device;\r
 };\r
 \r
+/*\r
+       Separated input handler\r
+*/\r
+\r
 class InputHandler\r
 {\r
 public:\r
@@ -1072,6 +1083,10 @@ private:
        bool rightreleased;\r
 };\r
 \r
+/*\r
+       Render distance feedback loop\r
+*/\r
+\r
 void updateViewingRange(f32 frametime_in, Client *client)\r
 {\r
        if(draw_control.range_all == true)\r
@@ -1203,6 +1218,10 @@ void updateViewingRange(f32 frametime_in, Client *client)
        frametime_old = frametime;\r
 }\r
 \r
+/*\r
+       Hotbar draw routine\r
+*/\r
+\r
 void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,\r
                v2s32 centerlowerpos, s32 imgsize, s32 itemcount,\r
                Inventory *inventory, s32 halfheartcount)\r
@@ -1290,150 +1309,6 @@ void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
        }\r
 }\r
 \r
-#if 0\r
-video::ITexture *g_map_plot_texture = NULL;\r
-float g_map_plot_texture_scale = 4;\r
-\r
-void updateMapPlotTexture(v2f centerpos, video::IVideoDriver* driver,\r
-               Client *client)\r
-{\r
-       assert(driver);\r
-       assert(client);\r
-\r
-       core::dimension2d<u32> dim(640,480);\r
-       video::IImage *img = driver->createImage(video::ECF_A8R8G8B8, dim);\r
-       assert(img);\r
-       for(u32 y=0; y<dim.Height; y++)\r
-       for(u32 x=0; x<dim.Width; x++)\r
-       {\r
-               v2f pf = v2f(x, dim.Height-y) - v2f(dim.Width, dim.Height)/2;\r
-               pf *= g_map_plot_texture_scale;\r
-               pf += centerpos;\r
-               double h = base_rock_level_2d(client->getMapSeed(), pf);\r
-               video::SColor c;\r
-               //double d1 = 50;\r
-               /*s32 ux = x - centerpos.X / g_map_plot_texture_scale;\r
-               s32 uy = y - centerpos.Y / g_map_plot_texture_scale;*/\r
-                       \r
-               // Screen coordinates that are based on multiples of\r
-               // 1000/g_map_plot_texture_scale and never negative\r
-               u32 ux = x + (u32)(1000/g_map_plot_texture_scale) * 10;\r
-               u32 uy = y + (u32)(1000/g_map_plot_texture_scale) * 10;\r
-               // Offset to center of image\r
-               ux -= dim.Width/2;\r
-               uy -= dim.Height/2;\r
-\r
-               if(uy % (u32)(1000/g_map_plot_texture_scale) == 0\r
-                               || ux % (u32)(1000/g_map_plot_texture_scale) == 0)\r
-                       c.set(255, 255, 255, 255);\r
-               else if(uy % (u32)(100/g_map_plot_texture_scale) == 0\r
-                               || ux % (u32)(100/g_map_plot_texture_scale) == 0)\r
-                       c.set(255, 160, 160, 160);\r
-               else if(h < WATER_LEVEL - 0.5) // Water\r
-                       c.set(255, 50, 50, 255);\r
-#if 0\r
-               else if(get_have_sand_ground(client->getMapSeed(), pf)\r
-                               || (h < WATER_LEVEL + 2\r
-                               && get_have_sand_coast(client->getMapSeed(), pf)))\r
-               {\r
-                       h -= WATER_LEVEL;\r
-                       h /= 50.0;\r
-                       h = 1.0 - exp(-h);\r
-\r
-                       video::SColor c1(255,237,201,175);\r
-                       //video::SColor c2(255,20,20,20);\r
-                       video::SColor c2(255,150,0,0);\r
-                       c = c2.getInterpolated(c1, h);\r
-               }\r
-               else\r
-               {\r
-                       h -= WATER_LEVEL;\r
-                       h /= 50.0;\r
-                       h = 1.0 - exp(-h);\r
-\r
-                       video::SColor c1(255,110,185,90);\r
-                       //video::SColor c2(255,20,20,20);\r
-                       video::SColor c2(255,150,0,0);\r
-                       c = c2.getInterpolated(c1, h);\r
-               }\r
-#endif\r
-#if 1\r
-#if 0\r
-               else if(get_have_sand_ground(client->getMapSeed(), pf))\r
-               {\r
-                       h -= WATER_LEVEL;\r
-                       h /= 20.0;\r
-                       h = 1.0 - exp(-h);\r
-\r
-                       video::SColor c1(255,237,201,175);\r
-                       //video::SColor c2(255,20,20,20);\r
-                       video::SColor c2(255,150,0,0);\r
-                       c = c2.getInterpolated(c1, h);\r
-               }\r
-#endif\r
-               // Sand\r
-               else if(h < WATER_LEVEL + 2\r
-                               && get_have_sand_coast(client->getMapSeed(), pf))\r
-                       c.set(255, 237, 201, 175);\r
-#if 1\r
-               else if(h < WATER_LEVEL + 10)\r
-                       c.set(255, 50, 150, 50); // Green\r
-               else if(h < WATER_LEVEL + 20)\r
-                       c.set(255, 110, 185, 50); // Yellowish green\r
-               else if(h < WATER_LEVEL + 40)\r
-                       c.set(255, 180, 210, 50); // Greenish yellow\r
-               else if(h < WATER_LEVEL + 60)\r
-                       c.set(255, 220, 220, 50); // Yellow\r
-               else if(h < WATER_LEVEL + 80)\r
-                       c.set(255, 200, 200, 110); // Yellowish white\r
-               else if(h < WATER_LEVEL + 100)\r
-                       c.set(255, 190, 190, 190); // Grey\r
-               else\r
-                       c.set(255, 255, 255, 255); // White\r
-#endif\r
-#endif\r
-#if 0\r
-               else\r
-               {\r
-                       h -= WATER_LEVEL;\r
-                       h /= 20.0;\r
-                       h = 1.0 - exp(-h);\r
-\r
-                       video::SColor c1(255,200,200,50);\r
-                       video::SColor c2(255,0,150,0);\r
-                       c = c1.getInterpolated(c2, h);\r
-\r
-                       /*u32 a = (u32)(h*255);\r
-                       if(a > 255)\r
-                               a = 255;\r
-                       a = 255-a;\r
-                       c.set(255, a, a, a);*/\r
-               }\r
-#endif\r
-#if 1\r
-               if(h >= WATER_LEVEL - 0.5\r
-                       && get_have_sand_ground(client->getMapSeed(), pf))\r
-               {\r
-                       video::SColor c1(255,237,201,175);\r
-                       c = c.getInterpolated(c1, 0.5);\r
-               }\r
-#endif\r
-#if 1\r
-               double tf = get_turbulence_factor_2d(client->getMapSeed(), pf);\r
-               if(tf > 0.001)\r
-               {\r
-                       video::SColor c1(255,255,0,0);\r
-                       c = c.getInterpolated(c1, 1.0-(0.5*tf));\r
-               }\r
-#endif\r
-               img->setPixel(x, y, c);\r
-       }\r
-       g_map_plot_texture = driver->addTexture("map_plot", img);\r
-       img->drop();\r
-       assert(g_map_plot_texture);\r
-}\r
-#endif\r
-\r
 // Chat data\r
 struct ChatLine\r
 {\r
@@ -2456,9 +2331,9 @@ int main(int argc, char *argv[])
 \r
        while(device->run() && kill == false)\r
        {\r
-               if(g_disconnect_requested)\r
+               if(g_gamecallback.disconnect_requested)\r
                {\r
-                       g_disconnect_requested = false;\r
+                       g_gamecallback.disconnect_requested = false;\r
                        break;\r
                }\r
 \r