mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add support for Android 2.3+
There have been plenty of ppl involved in creating this version. I don't wanna mention names as I'm sure I'd forget someone so I just tell where help has been done: - The partial android versions done by various ppl - Testing on different android devices - reviewing code (especially the in core changes) - testing controls - reviewing texts A big thank you to everyone helping this to be completed!
This commit is contained in:
parent
ff36071d93
commit
1cc40c0a7c
66 changed files with 4425 additions and 162 deletions
107
src/main.cpp
107
src/main.cpp
|
@ -84,10 +84,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#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 +257,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 +275,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 +311,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)<<std::endl;
|
||||
return true;
|
||||
}
|
||||
/* always return false in order to continue processing events */
|
||||
|
@ -342,6 +360,9 @@ public:
|
|||
MyEventReceiver()
|
||||
{
|
||||
clearInput();
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
m_touchscreengui = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool leftclicked;
|
||||
|
@ -355,7 +376,12 @@ public:
|
|||
|
||||
s32 mouse_wheel;
|
||||
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
TouchScreenGUI* m_touchscreengui;
|
||||
#endif
|
||||
|
||||
private:
|
||||
IrrlichtDevice *m_device;
|
||||
|
||||
// The current state of keys
|
||||
KeyList keyIsDown;
|
||||
|
@ -372,7 +398,8 @@ class RealInputHandler : public InputHandler
|
|||
public:
|
||||
RealInputHandler(IrrlichtDevice *device, MyEventReceiver *receiver):
|
||||
m_device(device),
|
||||
m_receiver(receiver)
|
||||
m_receiver(receiver),
|
||||
m_mousepos(0,0)
|
||||
{
|
||||
}
|
||||
virtual bool isKeyDown(const KeyPress &keyCode)
|
||||
|
@ -385,11 +412,21 @@ public:
|
|||
}
|
||||
virtual v2s32 getMousePos()
|
||||
{
|
||||
return m_device->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 +482,9 @@ public:
|
|||
m_receiver->clearInput();
|
||||
}
|
||||
private:
|
||||
IrrlichtDevice *m_device;
|
||||
IrrlichtDevice *m_device;
|
||||
MyEventReceiver *m_receiver;
|
||||
v2s32 m_mousepos;
|
||||
};
|
||||
|
||||
class RandomInputHandler : public InputHandler
|
||||
|
@ -855,8 +893,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 +1023,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);
|
||||
|
@ -1348,7 +1397,7 @@ int main(int argc, char *argv[])
|
|||
List video modes if requested
|
||||
*/
|
||||
|
||||
MyEventReceiver receiver;
|
||||
MyEventReceiver* receiver = new MyEventReceiver();
|
||||
|
||||
if (cmd_args.getFlag("videomodes")) {
|
||||
IrrlichtDevice *nulldevice;
|
||||
|
@ -1361,7 +1410,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 +1446,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<u32>(screenW, screenH);
|
||||
|
@ -1414,12 +1461,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 +1529,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 +1618,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 +1667,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 +1718,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();
|
||||
}
|
||||
|
@ -1788,6 +1844,10 @@ int main(int argc, char *argv[])
|
|||
/*
|
||||
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 +1865,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 +1914,7 @@ int main(int argc, char *argv[])
|
|||
if (use_freetype)
|
||||
font->drop();
|
||||
#endif
|
||||
|
||||
delete receiver;
|
||||
#endif // !SERVER
|
||||
|
||||
// Update configuration file
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue