X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fmain.cpp;h=9d336825ec3a25b69b59b3d11b9a7be92cf43bf3;hb=58e6d25e033c76dc91aaac18fdeda92ac23fe0e1;hp=5a0be2f75df5ad691f37a5d62cafa0fec8fc6328;hpb=d4245e6cac58a57ad2498eee2c17e851f3292296;p=oweals%2Fminetest.git diff --git a/src/main.cpp b/src/main.cpp index 5a0be2f75..9d336825e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -79,15 +79,20 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "httpfetch.h" #include "guiEngine.h" #include "mapsector.h" +#include "player.h" #include "database-sqlite3.h" #ifdef USE_LEVELDB #include "database-leveldb.h" #endif + #if USE_REDIS #include "database-redis.h" #endif +#ifdef HAVE_TOUCHSCREENGUI +#include "touchscreengui.h" +#endif /* Settings. These are loaded from the config file. @@ -253,6 +258,11 @@ public: React to nothing here if a menu is active */ if (noMenuActive() == false) { +#ifdef HAVE_TOUCHSCREENGUI + if (m_touchscreengui != 0) { + m_touchscreengui->Toggle(false); + } +#endif return g_menumgr.preprocessEvent(event); } @@ -266,7 +276,16 @@ public: } } - if (event.EventType == irr::EET_MOUSE_INPUT_EVENT) { +#ifdef HAVE_TOUCHSCREENGUI + // case of touchscreengui we have to handle different events + if ((m_touchscreengui != 0) && + (event.EventType == irr::EET_TOUCH_INPUT_EVENT)) { + m_touchscreengui->translateEvent(event); + return true; + } +#endif + // handle mouse events + if(event.EventType == irr::EET_MOUSE_INPUT_EVENT) { if (noMenuActive() == false) { left_active = false; middle_active = false; @@ -293,8 +312,8 @@ public: } } } - if (event.EventType == irr::EET_LOG_TEXT_EVENT) { - dstream << "Irrlicht log: " << event.LogEvent.Text << std::endl; + if(event.EventType == irr::EET_LOG_TEXT_EVENT) { + dstream<< std::string("Irrlicht log: ") + std::string(event.LogEvent.Text)<getCursorControl()->getPosition(); + if (m_device->getCursorControl()) { + return m_device->getCursorControl()->getPosition(); + } + else { + return m_mousepos; + } } virtual void setMousePos(s32 x, s32 y) { - m_device->getCursorControl()->setPosition(x, y); + if (m_device->getCursorControl()) { + m_device->getCursorControl()->setPosition(x, y); + } + else { + m_mousepos = v2s32(x,y); + } } virtual bool getLeftState() @@ -445,8 +481,9 @@ public: m_receiver->clearInput(); } private: - IrrlichtDevice *m_device; + IrrlichtDevice *m_device; MyEventReceiver *m_receiver; + v2s32 m_mousepos; }; class RandomInputHandler : public InputHandler @@ -855,8 +892,18 @@ int main(int argc, char *argv[]) porting::initializePaths(); +#ifdef __ANDROID__ + porting::initAndroid(); + + porting::setExternalStorageDir(porting::jnienv); + if (!fs::PathExists(porting::path_user)) { + fs::CreateDir(porting::path_user); + } + porting::copyAssets(); +#else // Create user data directory fs::CreateDir(porting::path_user); +#endif infostream << "path_share = " << porting::path_share << std::endl; infostream << "path_user = " << porting::path_user << std::endl; @@ -975,14 +1022,15 @@ int main(int argc, char *argv[]) // Initialize HTTP fetcher httpfetch_init(g_settings->getS32("curl_parallel_limit")); +#ifndef __ANDROID__ /* Run unit tests */ - if ((ENABLE_TESTS && cmd_args.getFlag("disable-unittests") == false) || cmd_args.getFlag("enable-unittests") == true) { run_tests(); } +#endif #ifdef _MSC_VER init_gettext((porting::path_share + DIR_DELIM + "locale").c_str(), g_settings->get("language"), argc, argv); @@ -1249,9 +1297,13 @@ int main(int argc, char *argv[]) new_db->beginSave(); for (std::list::iterator i = blocks.begin(); i != blocks.end(); i++) { MapBlock *block = old_map.loadBlock(*i); - new_db->saveBlock(block); - MapSector *sector = old_map.getSectorNoGenerate(v2s16(i->X, i->Z)); - sector->deleteBlock(block); + if (!block) { + errorstream << "Failed to load block " << PP(*i) << ", skipping it."; + } else { + old_map.saveBlock(block, new_db); + MapSector *sector = old_map.getSectorNoGenerate(v2s16(i->X, i->Z)); + sector->deleteBlock(block); + } ++count; if (count % 500 == 0) actionstream << "Migrated " << count << " blocks " @@ -1313,42 +1365,44 @@ int main(int argc, char *argv[]) u16 fsaa = g_settings->getU16("fsaa"); // Determine driver - - video::E_DRIVER_TYPE driverType; - - std::string driverstring = g_settings->get("video_driver"); - - if (driverstring == "null") - driverType = video::EDT_NULL; - else if (driverstring == "software") - driverType = video::EDT_SOFTWARE; - else if (driverstring == "burningsvideo") - driverType = video::EDT_BURNINGSVIDEO; - else if (driverstring == "direct3d8") - driverType = video::EDT_DIRECT3D8; - else if (driverstring == "direct3d9") - driverType = video::EDT_DIRECT3D9; - else if (driverstring == "opengl") - driverType = video::EDT_OPENGL; + video::E_DRIVER_TYPE driverType = video::EDT_OPENGL; + static const char* driverids[] = { + "null", + "software", + "burningsvideo", + "direct3d8", + "direct3d9", + "opengl" #ifdef _IRR_COMPILE_WITH_OGLES1_ - else if (driverstring == "ogles1") - driverType = video::EDT_OGLES1; + ,"ogles1" #endif #ifdef _IRR_COMPILE_WITH_OGLES2_ - else if (driverstring == "ogles2") - driverType = video::EDT_OGLES2; + ,"ogles2" #endif - else { - errorstream << "WARNING: Invalid video_driver specified; defaulting " - << "to opengl" << std::endl; - driverType = video::EDT_OPENGL; + ,"invalid" + }; + + std::string driverstring = g_settings->get("video_driver"); + for (unsigned int i = 0; + i < (sizeof(driverids)/sizeof(driverids[0])); + i++) + { + if (strcasecmp(driverstring.c_str(), driverids[i]) == 0) { + driverType = (video::E_DRIVER_TYPE) i; + break; + } + + if (strcasecmp("invalid", driverids[i]) == 0) { + errorstream << "WARNING: Invalid video_driver specified; defaulting " + << "to opengl" << std::endl; + break; + } } /* List video modes if requested */ - - MyEventReceiver receiver; + MyEventReceiver* receiver = new MyEventReceiver(); if (cmd_args.getFlag("videomodes")) { IrrlichtDevice *nulldevice; @@ -1361,7 +1415,7 @@ int main(int argc, char *argv[]) params.Fullscreen = false; params.Stencilbuffer = false; params.Vsync = vsync; - params.EventReceiver = &receiver; + params.EventReceiver = receiver; params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu"); nulldevice = createDeviceEx(params); @@ -1397,15 +1451,13 @@ int main(int argc, char *argv[]) nulldevice->drop(); + delete receiver; return 0; } /* Create device and exit if creation failed */ - - IrrlichtDevice *device; - SIrrlichtCreationParameters params = SIrrlichtCreationParameters(); params.DriverType = driverType; params.WindowSize = core::dimension2d(screenW, screenH); @@ -1414,12 +1466,18 @@ int main(int argc, char *argv[]) params.Fullscreen = fullscreen; params.Stencilbuffer = false; params.Vsync = vsync; - params.EventReceiver = &receiver; + params.EventReceiver = receiver; params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu"); +#ifdef __ANDROID__ + params.PrivateData = porting::app_global; + params.OGLES2ShaderPath = std::string(porting::path_user + DIR_DELIM + + "media" + DIR_DELIM + "Shaders" + DIR_DELIM).c_str(); +#endif - device = createDeviceEx(params); + IrrlichtDevice * device = createDeviceEx(params); if (device == 0) { + delete receiver; return 1; // could not create selected driver. } @@ -1476,10 +1534,11 @@ int main(int argc, char *argv[]) bool random_input = g_settings->getBool("random_input") || cmd_args.getFlag("random-input"); InputHandler *input = NULL; + if (random_input) { input = new RandomInputHandler(); } else { - input = new RealInputHandler(device, &receiver); + input = new RealInputHandler(device,receiver); } scene::ISceneManager* smgr = device->getSceneManager(); @@ -1564,7 +1623,8 @@ int main(int argc, char *argv[]) /* Menu-game loop */ - while (device->run() && kill == false) + while (device->run() && (kill == false) && + (g_gamecallback->shutdown_requested == false)) { // Set the window caption wchar_t* text = wgettext("Main Menu"); @@ -1612,7 +1672,9 @@ int main(int argc, char *argv[]) first_loop = false; // Cursor can be non-visible when coming from the game + #ifndef ANDROID device->getCursorControl()->setVisible(true); + #endif // Some stuff are left to scene manager when coming from the game // (map at least?) smgr->clear(); @@ -1661,10 +1723,9 @@ int main(int argc, char *argv[]) } infostream << "Waited for other menus" << std::endl; - GUIEngine* temp = new GUIEngine(device, guiroot, - &g_menumgr, smgr, &menudata, kill); + /* show main menu */ + GUIEngine mymenu(device, guiroot, &g_menumgr,smgr,&menudata,kill); - delete temp; //once finished you'll never end up here smgr->clear(); } @@ -1785,9 +1846,20 @@ int main(int argc, char *argv[]) break; } + if (current_playername.length() > PLAYERNAME_SIZE-1) { + error_message = wgettext("Player name too long."); + playername = current_playername.substr(0,PLAYERNAME_SIZE-1); + g_settings->set("name", playername); + continue; + } + /* Run game */ +#ifdef HAVE_TOUCHSCREENGUI + receiver->m_touchscreengui = new TouchScreenGUI(device, receiver); + g_touchscreengui = receiver->m_touchscreengui; +#endif the_game( kill, random_input, @@ -1805,6 +1877,11 @@ int main(int argc, char *argv[]) simple_singleplayer_mode ); smgr->clear(); +#ifdef HAVE_TOUCHSCREENGUI + delete g_touchscreengui; + g_touchscreengui = NULL; + receiver->m_touchscreengui = NULL; +#endif } //try catch(con::PeerNotFoundException &e) @@ -1849,7 +1926,7 @@ int main(int argc, char *argv[]) if (use_freetype) font->drop(); #endif - + delete receiver; #endif // !SERVER // Update configuration file @@ -1884,4 +1961,3 @@ int main(int argc, char *argv[]) } //END -