2010-06-06 09:34:36 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-02-06 16:03:52 +01:00
|
|
|
#if defined(__ANDROID__)
|
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
#include <sys/time.h>
|
2011-02-26 14:53:02 +01:00
|
|
|
#include <sys/resource.h>
|
2010-06-06 09:34:36 +00:00
|
|
|
#include <time.h>
|
2011-02-20 17:01:46 +01:00
|
|
|
#include <unistd.h>
|
2010-06-06 09:34:36 +00:00
|
|
|
|
|
|
|
#include "common/util.h"
|
|
|
|
#include "common/rect.h"
|
|
|
|
#include "common/queue.h"
|
|
|
|
#include "common/mutex.h"
|
|
|
|
#include "common/events.h"
|
|
|
|
#include "common/config-manager.h"
|
|
|
|
|
|
|
|
#include "backends/keymapper/keymapper.h"
|
|
|
|
#include "backends/saves/default/default-saves.h"
|
|
|
|
#include "backends/timer/default/default-timer.h"
|
|
|
|
|
2011-02-24 00:45:41 +01:00
|
|
|
#include "backends/platform/android/jni.h"
|
2011-02-20 17:01:46 +01:00
|
|
|
#include "backends/platform/android/android.h"
|
2010-06-06 09:34:36 +00:00
|
|
|
|
2011-02-19 17:30:30 +01:00
|
|
|
const char *android_log_tag = "ScummVM";
|
2010-06-06 09:34:36 +00:00
|
|
|
|
2011-02-14 17:51:58 +01:00
|
|
|
// This replaces the bionic libc assert functions with something that
|
2010-06-08 13:25:00 +00:00
|
|
|
// actually prints the assertion failure before aborting.
|
2011-02-14 17:51:58 +01:00
|
|
|
extern "C" {
|
|
|
|
void __assert(const char *file, int line, const char *expr) {
|
2011-02-19 17:30:30 +01:00
|
|
|
__android_log_assert(expr, android_log_tag,
|
2011-02-19 16:18:15 +01:00
|
|
|
"Assertion failure: '%s' in %s:%d",
|
|
|
|
expr, file, line);
|
2011-02-14 17:51:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void __assert2(const char *file, int line, const char *func, const char *expr) {
|
2011-02-19 17:30:30 +01:00
|
|
|
__android_log_assert(expr, android_log_tag,
|
2011-02-19 16:18:15 +01:00
|
|
|
"Assertion failure: '%s' in %s:%d (%s)",
|
|
|
|
expr, file, line, func);
|
2011-02-14 17:51:58 +01:00
|
|
|
}
|
2010-06-08 13:25:00 +00:00
|
|
|
}
|
|
|
|
|
2011-02-19 17:30:30 +01:00
|
|
|
#ifdef ANDROID_DEBUG_GL
|
|
|
|
static const char *getGlErrStr(GLenum error) {
|
|
|
|
switch (error) {
|
|
|
|
case GL_INVALID_ENUM:
|
|
|
|
return "GL_INVALID_ENUM";
|
|
|
|
case GL_INVALID_VALUE:
|
|
|
|
return "GL_INVALID_VALUE";
|
|
|
|
case GL_INVALID_OPERATION:
|
|
|
|
return "GL_INVALID_OPERATION";
|
|
|
|
case GL_STACK_OVERFLOW:
|
|
|
|
return "GL_STACK_OVERFLOW";
|
|
|
|
case GL_STACK_UNDERFLOW:
|
|
|
|
return "GL_STACK_UNDERFLOW";
|
|
|
|
case GL_OUT_OF_MEMORY:
|
|
|
|
return "GL_OUT_OF_MEMORY";
|
|
|
|
}
|
|
|
|
|
|
|
|
static char buf[40];
|
|
|
|
snprintf(buf, sizeof(buf), "(Unknown GL error code 0x%x)", error);
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void checkGlError(const char *expr, const char *file, int line) {
|
|
|
|
GLenum error = glGetError();
|
|
|
|
|
|
|
|
if (error != GL_NO_ERROR)
|
|
|
|
LOGE("GL ERROR: %s on %s (%s:%d)", getGlErrStr(error), expr, file, line);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-02-19 16:18:15 +01:00
|
|
|
// floating point. use sparingly
|
2010-06-06 09:34:36 +00:00
|
|
|
template <class T>
|
|
|
|
static inline T scalef(T in, float numerator, float denominator) {
|
|
|
|
return static_cast<float>(in) * numerator / denominator;
|
|
|
|
}
|
|
|
|
|
2011-02-26 14:53:02 +01:00
|
|
|
OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) :
|
|
|
|
_audio_sample_rate(audio_sample_rate),
|
|
|
|
_audio_buffer_size(audio_buffer_size),
|
2011-02-19 16:18:15 +01:00
|
|
|
_screen_changeid(0),
|
|
|
|
_force_redraw(false),
|
|
|
|
_game_texture(0),
|
|
|
|
_overlay_texture(0),
|
|
|
|
_mouse_texture(0),
|
|
|
|
_use_mouse_palette(false),
|
|
|
|
_show_mouse(false),
|
|
|
|
_show_overlay(false),
|
|
|
|
_enable_zoning(false),
|
|
|
|
_savefile(0),
|
|
|
|
_mixer(0),
|
|
|
|
_timer(0),
|
|
|
|
_fsFactory(new POSIXFilesystemFactory()),
|
|
|
|
_shake_offset(0),
|
|
|
|
_event_queue_lock(createMutex()) {
|
2010-06-06 09:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OSystem_Android::~OSystem_Android() {
|
2011-02-19 17:30:30 +01:00
|
|
|
ENTER();
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
delete _game_texture;
|
|
|
|
delete _overlay_texture;
|
|
|
|
delete _mouse_texture;
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2011-02-24 00:45:41 +01:00
|
|
|
JNI::destroySurface();
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
delete _savefile;
|
|
|
|
delete _mixer;
|
|
|
|
delete _timer;
|
|
|
|
delete _fsFactory;
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
deleteMutex(_event_queue_lock);
|
|
|
|
}
|
|
|
|
|
2011-02-19 16:18:15 +01:00
|
|
|
void *OSystem_Android::timerThreadFunc(void *arg) {
|
|
|
|
OSystem_Android *system = (OSystem_Android *)arg;
|
|
|
|
DefaultTimerManager *timer = (DefaultTimerManager *)(system->_timer);
|
2010-06-06 09:34:36 +00:00
|
|
|
|
2011-02-26 14:53:02 +01:00
|
|
|
// renice this thread to boost the audio thread
|
|
|
|
if (setpriority(PRIO_PROCESS, 0, 19) < 0)
|
2011-02-27 20:16:52 +01:00
|
|
|
LOGW("couldn't renice the timer thread");
|
2011-02-26 14:53:02 +01:00
|
|
|
|
2011-02-23 22:44:33 +01:00
|
|
|
JNI::attachThread();
|
2011-02-14 18:48:33 +01:00
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
struct timespec tv;
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_nsec = 100 * 1000 * 1000; // 100ms
|
|
|
|
|
|
|
|
while (!system->_timer_thread_exit) {
|
|
|
|
timer->handler();
|
2011-02-19 16:18:15 +01:00
|
|
|
nanosleep(&tv, 0);
|
2010-06-06 09:34:36 +00:00
|
|
|
}
|
|
|
|
|
2011-02-23 22:44:33 +01:00
|
|
|
JNI::detachThread();
|
2011-02-14 18:48:33 +01:00
|
|
|
|
2011-02-19 16:18:15 +01:00
|
|
|
return 0;
|
2010-06-06 09:34:36 +00:00
|
|
|
}
|
|
|
|
|
2011-02-26 14:53:02 +01:00
|
|
|
void *OSystem_Android::audioThreadFunc(void *arg) {
|
|
|
|
JNI::attachThread();
|
|
|
|
|
|
|
|
OSystem_Android *system = (OSystem_Android *)arg;
|
|
|
|
Audio::MixerImpl *mixer = system->_mixer;
|
|
|
|
|
|
|
|
uint buf_size = system->_audio_buffer_size;
|
|
|
|
|
|
|
|
JNIEnv *env = JNI::getEnv();
|
|
|
|
|
|
|
|
jbyteArray bufa = env->NewByteArray(buf_size);
|
|
|
|
|
2011-02-26 18:44:17 +01:00
|
|
|
bool paused = true;
|
|
|
|
|
2011-02-26 14:53:02 +01:00
|
|
|
byte *buf;
|
|
|
|
int offset, left, written;
|
2011-02-26 22:23:17 +01:00
|
|
|
int samples, i;
|
2011-02-26 14:53:02 +01:00
|
|
|
|
2011-02-26 18:44:17 +01:00
|
|
|
struct timespec tv_delay;
|
|
|
|
tv_delay.tv_sec = 0;
|
|
|
|
tv_delay.tv_nsec = 20 * 1000 * 1000;
|
|
|
|
|
|
|
|
uint msecs_full = buf_size * 1000 / (mixer->getOutputRate() * 2 * 2);
|
|
|
|
|
|
|
|
struct timespec tv_full;
|
|
|
|
tv_full.tv_sec = 0;
|
|
|
|
tv_full.tv_nsec = msecs_full * 1000 * 1000;
|
|
|
|
|
2011-02-26 22:23:17 +01:00
|
|
|
bool silence;
|
2011-02-27 11:25:03 +01:00
|
|
|
uint silence_count = 33;
|
2011-02-26 14:53:02 +01:00
|
|
|
|
|
|
|
while (!system->_audio_thread_exit) {
|
|
|
|
buf = (byte *)env->GetPrimitiveArrayCritical(bufa, 0);
|
|
|
|
assert(buf);
|
|
|
|
|
2011-02-26 18:44:17 +01:00
|
|
|
samples = mixer->mixCallback(buf, buf_size);
|
2011-02-26 14:53:02 +01:00
|
|
|
|
2011-02-26 22:23:17 +01:00
|
|
|
silence = samples < 1;
|
|
|
|
|
|
|
|
// looks stupid, and it is, but currently there's no way to detect
|
|
|
|
// silence-only buffers from the mixer
|
|
|
|
if (!silence) {
|
|
|
|
silence = true;
|
|
|
|
|
|
|
|
for (i = 0; i < samples; i += 2)
|
|
|
|
// SID streams constant crap
|
|
|
|
if (READ_UINT16(buf + i) > 32) {
|
|
|
|
silence = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-26 14:53:02 +01:00
|
|
|
env->ReleasePrimitiveArrayCritical(bufa, buf, 0);
|
|
|
|
|
2011-02-26 22:23:17 +01:00
|
|
|
if (silence) {
|
2011-02-26 18:44:17 +01:00
|
|
|
if (!paused)
|
|
|
|
silence_count++;
|
|
|
|
|
|
|
|
// only pause after a while to prevent toggle mania
|
|
|
|
if (silence_count > 32) {
|
|
|
|
if (!paused) {
|
|
|
|
LOGD("AudioTrack pause");
|
|
|
|
|
|
|
|
JNI::setAudioPause();
|
|
|
|
paused = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nanosleep(&tv_full, 0);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (paused) {
|
|
|
|
LOGD("AudioTrack play");
|
|
|
|
|
|
|
|
JNI::setAudioPlay();
|
|
|
|
paused = false;
|
|
|
|
|
|
|
|
silence_count = 0;
|
|
|
|
}
|
|
|
|
|
2011-02-26 14:53:02 +01:00
|
|
|
offset = 0;
|
|
|
|
left = buf_size;
|
|
|
|
written = 0;
|
|
|
|
|
|
|
|
while (left > 0) {
|
|
|
|
written = JNI::writeAudio(env, bufa, offset, left);
|
|
|
|
|
|
|
|
if (written < 0) {
|
2011-02-27 20:16:52 +01:00
|
|
|
LOGE("AudioTrack error: %d", written);
|
2011-02-26 14:53:02 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// buffer full
|
|
|
|
if (written < left)
|
2011-02-26 18:44:17 +01:00
|
|
|
nanosleep(&tv_delay, 0);
|
2011-02-26 14:53:02 +01:00
|
|
|
|
|
|
|
offset += written;
|
|
|
|
left -= written;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (written < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// sleep a little, prepare the next buffer, and run into the
|
|
|
|
// blocking AudioTrack.write
|
2011-02-26 18:44:17 +01:00
|
|
|
nanosleep(&tv_delay, 0);
|
2011-02-26 14:53:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNI::setAudioStop();
|
|
|
|
|
|
|
|
env->DeleteLocalRef(bufa);
|
|
|
|
|
|
|
|
JNI::detachThread();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
void OSystem_Android::initBackend() {
|
2011-02-19 17:30:30 +01:00
|
|
|
ENTER();
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2011-02-24 18:24:27 +01:00
|
|
|
_main_thread = pthread_self();
|
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
ConfMan.setInt("autosave_period", 0);
|
2011-02-27 11:23:11 +01:00
|
|
|
ConfMan.setBool("FM_high_quality", false);
|
|
|
|
ConfMan.setBool("FM_medium_quality", true);
|
2010-06-06 09:34:36 +00:00
|
|
|
|
|
|
|
// must happen before creating TimerManager to avoid race in
|
|
|
|
// creating EventManager
|
|
|
|
setupKeymapper();
|
|
|
|
|
|
|
|
// BUG: "transient" ConfMan settings get nuked by the options
|
2011-02-19 16:18:15 +01:00
|
|
|
// screen. Passing the savepath in this way makes it stick
|
2010-06-06 09:34:36 +00:00
|
|
|
// (via ConfMan.registerDefault)
|
|
|
|
_savefile = new DefaultSaveFileManager(ConfMan.get("savepath"));
|
|
|
|
_timer = new DefaultTimerManager();
|
|
|
|
|
2011-02-19 16:18:15 +01:00
|
|
|
gettimeofday(&_startTime, 0);
|
2010-06-06 09:34:36 +00:00
|
|
|
|
2011-02-26 14:53:02 +01:00
|
|
|
_mixer = new Audio::MixerImpl(this, _audio_sample_rate);
|
2010-06-06 09:34:36 +00:00
|
|
|
_mixer->setReady(true);
|
|
|
|
|
2011-02-24 00:45:41 +01:00
|
|
|
JNI::initBackend();
|
2010-06-06 09:34:36 +00:00
|
|
|
|
|
|
|
_timer_thread_exit = false;
|
2011-02-19 16:18:15 +01:00
|
|
|
pthread_create(&_timer_thread, 0, timerThreadFunc, this);
|
2010-06-06 09:34:36 +00:00
|
|
|
|
2011-02-26 14:53:02 +01:00
|
|
|
_audio_thread_exit = false;
|
|
|
|
pthread_create(&_audio_thread, 0, audioThreadFunc, this);
|
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
OSystem::initBackend();
|
|
|
|
|
2011-02-24 00:45:41 +01:00
|
|
|
setupSurface();
|
2011-02-26 14:53:02 +01:00
|
|
|
|
|
|
|
// renice this thread to boost the audio thread
|
|
|
|
if (setpriority(PRIO_PROCESS, 0, 19) < 0)
|
|
|
|
warning("couldn't renice the main thread");
|
2010-06-06 09:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_Android::addPluginDirectories(Common::FSList &dirs) const {
|
2011-02-19 17:30:30 +01:00
|
|
|
ENTER();
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2011-02-24 00:45:41 +01:00
|
|
|
JNI::getPluginDirectories(dirs);
|
2010-06-06 09:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OSystem_Android::hasFeature(Feature f) {
|
|
|
|
return (f == kFeatureCursorHasPalette ||
|
2011-02-19 16:18:15 +01:00
|
|
|
f == kFeatureVirtualKeyboard ||
|
|
|
|
f == kFeatureOverlaySupportsAlpha);
|
2010-06-06 09:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_Android::setFeatureState(Feature f, bool enable) {
|
2011-02-19 17:30:30 +01:00
|
|
|
ENTER("%d, %d", f, enable);
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
switch (f) {
|
|
|
|
case kFeatureVirtualKeyboard:
|
|
|
|
_virtkeybd_on = enable;
|
|
|
|
showVirtualKeyboard(enable);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OSystem_Android::getFeatureState(Feature f) {
|
|
|
|
switch (f) {
|
|
|
|
case kFeatureVirtualKeyboard:
|
|
|
|
return _virtkeybd_on;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_Android::setupKeymapper() {
|
|
|
|
#ifdef ENABLE_KEYMAPPER
|
|
|
|
using namespace Common;
|
|
|
|
|
|
|
|
Keymapper *mapper = getEventManager()->getKeymapper();
|
|
|
|
|
|
|
|
HardwareKeySet *keySet = new HardwareKeySet();
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
keySet->addHardwareKey(
|
|
|
|
new HardwareKey("n", KeyState(KEYCODE_n), "n (vk)",
|
|
|
|
kTriggerLeftKeyType,
|
|
|
|
kVirtualKeyboardActionType));
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
mapper->registerHardwareKeySet(keySet);
|
|
|
|
|
|
|
|
Keymap *globalMap = new Keymap("global");
|
|
|
|
Action *act;
|
|
|
|
|
|
|
|
act = new Action(globalMap, "VIRT", "Display keyboard",
|
2011-02-19 16:18:15 +01:00
|
|
|
kVirtualKeyboardActionType);
|
2010-06-06 09:34:36 +00:00
|
|
|
act->addKeyEvent(KeyState(KEYCODE_F7, ASCII_F7, 0));
|
|
|
|
|
|
|
|
mapper->addGlobalKeymap(globalMap);
|
|
|
|
|
|
|
|
mapper->pushKeymap("global");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OSystem_Android::pollEvent(Common::Event &event) {
|
2011-02-19 17:30:30 +01:00
|
|
|
//ENTER();
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
lockMutex(_event_queue_lock);
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
if (_event_queue.empty()) {
|
|
|
|
unlockMutex(_event_queue_lock);
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
event = _event_queue.pop();
|
|
|
|
unlockMutex(_event_queue_lock);
|
|
|
|
|
|
|
|
switch (event.type) {
|
|
|
|
case Common::EVENT_MOUSEMOVE:
|
|
|
|
// TODO: only dirty/redraw move bounds
|
|
|
|
_force_redraw = true;
|
|
|
|
// fallthrough
|
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
|
|
|
case Common::EVENT_LBUTTONUP:
|
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
|
|
|
case Common::EVENT_RBUTTONUP:
|
|
|
|
case Common::EVENT_WHEELUP:
|
|
|
|
case Common::EVENT_WHEELDOWN:
|
|
|
|
case Common::EVENT_MBUTTONDOWN:
|
|
|
|
case Common::EVENT_MBUTTONUP: {
|
2011-02-19 16:18:15 +01:00
|
|
|
// relative mouse hack
|
|
|
|
if (event.kbd.flags == 1) {
|
2010-06-06 09:34:36 +00:00
|
|
|
// Relative (trackball) mouse hack.
|
|
|
|
const Common::Point& mouse_pos =
|
|
|
|
getEventManager()->getMousePos();
|
|
|
|
event.mouse.x += mouse_pos.x;
|
|
|
|
event.mouse.y += mouse_pos.y;
|
|
|
|
event.mouse.x = CLIP(event.mouse.x, (int16)0, _show_overlay ?
|
2011-02-19 16:18:15 +01:00
|
|
|
getOverlayWidth() : getWidth());
|
2010-06-06 09:34:36 +00:00
|
|
|
event.mouse.y = CLIP(event.mouse.y, (int16)0, _show_overlay ?
|
2011-02-19 16:18:15 +01:00
|
|
|
getOverlayHeight() : getHeight());
|
2010-06-06 09:34:36 +00:00
|
|
|
} else {
|
|
|
|
// Touchscreen events need to be converted
|
|
|
|
// from device to game coords first.
|
2011-02-19 16:18:15 +01:00
|
|
|
const GLESTexture *tex = _show_overlay
|
|
|
|
? static_cast<GLESTexture *>(_overlay_texture)
|
|
|
|
: static_cast<GLESTexture *>(_game_texture);
|
2010-06-06 09:34:36 +00:00
|
|
|
event.mouse.x = scalef(event.mouse.x, tex->width(),
|
2011-02-19 16:18:15 +01:00
|
|
|
_egl_surface_width);
|
2010-06-06 09:34:36 +00:00
|
|
|
event.mouse.y = scalef(event.mouse.y, tex->height(),
|
2011-02-19 16:18:15 +01:00
|
|
|
_egl_surface_height);
|
2010-06-06 09:34:36 +00:00
|
|
|
event.mouse.x -= _shake_offset;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Common::EVENT_SCREEN_CHANGED:
|
|
|
|
debug("EVENT_SCREEN_CHANGED");
|
|
|
|
_screen_changeid++;
|
2011-02-24 00:45:41 +01:00
|
|
|
JNI::destroySurface();
|
|
|
|
setupSurface();
|
2010-06-06 09:34:36 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_Android::pushEvent(const Common::Event& event) {
|
|
|
|
lockMutex(_event_queue_lock);
|
|
|
|
|
|
|
|
// Try to combine multiple queued mouse move events
|
|
|
|
if (event.type == Common::EVENT_MOUSEMOVE &&
|
2011-02-19 16:18:15 +01:00
|
|
|
!_event_queue.empty() &&
|
|
|
|
_event_queue.back().type == Common::EVENT_MOUSEMOVE) {
|
|
|
|
Common::Event tail = _event_queue.back();
|
|
|
|
if (event.kbd.flags) {
|
|
|
|
// relative movement hack
|
|
|
|
tail.mouse.x += event.mouse.x;
|
|
|
|
tail.mouse.y += event.mouse.y;
|
|
|
|
} else {
|
|
|
|
// absolute position, clear relative flag
|
|
|
|
tail.kbd.flags = 0;
|
|
|
|
tail.mouse.x = event.mouse.x;
|
|
|
|
tail.mouse.y = event.mouse.y;
|
|
|
|
}
|
|
|
|
} else {
|
2010-06-06 09:34:36 +00:00
|
|
|
_event_queue.push(event);
|
2011-02-19 16:18:15 +01:00
|
|
|
}
|
2010-06-06 09:34:36 +00:00
|
|
|
|
|
|
|
unlockMutex(_event_queue_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 OSystem_Android::getMillis() {
|
|
|
|
timeval curTime;
|
2011-02-19 16:18:15 +01:00
|
|
|
|
|
|
|
gettimeofday(&curTime, 0);
|
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
return (uint32)(((curTime.tv_sec - _startTime.tv_sec) * 1000) + \
|
|
|
|
((curTime.tv_usec - _startTime.tv_usec) / 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_Android::delayMillis(uint msecs) {
|
|
|
|
usleep(msecs * 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
OSystem::MutexRef OSystem_Android::createMutex() {
|
|
|
|
pthread_mutexattr_t attr;
|
2011-02-24 18:24:27 +01:00
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
pthread_mutexattr_init(&attr);
|
|
|
|
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
|
|
|
|
|
|
|
pthread_mutex_t *mutex = new pthread_mutex_t;
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
if (pthread_mutex_init(mutex, &attr) != 0) {
|
2010-09-18 10:55:16 +00:00
|
|
|
warning("pthread_mutex_init() failed");
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
delete mutex;
|
2011-02-19 16:18:15 +01:00
|
|
|
|
|
|
|
return 0;
|
2010-06-06 09:34:36 +00:00
|
|
|
}
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
return (MutexRef)mutex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_Android::lockMutex(MutexRef mutex) {
|
2011-02-19 16:18:15 +01:00
|
|
|
if (pthread_mutex_lock((pthread_mutex_t *)mutex) != 0)
|
2010-09-18 10:55:16 +00:00
|
|
|
warning("pthread_mutex_lock() failed");
|
2010-06-06 09:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_Android::unlockMutex(MutexRef mutex) {
|
2011-02-19 16:18:15 +01:00
|
|
|
if (pthread_mutex_unlock((pthread_mutex_t *)mutex) != 0)
|
2010-09-18 10:55:16 +00:00
|
|
|
warning("pthread_mutex_unlock() failed");
|
2010-06-06 09:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_Android::deleteMutex(MutexRef mutex) {
|
2011-02-19 16:18:15 +01:00
|
|
|
pthread_mutex_t *m = (pthread_mutex_t *)mutex;
|
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
if (pthread_mutex_destroy(m) != 0)
|
2010-09-18 10:55:16 +00:00
|
|
|
warning("pthread_mutex_destroy() failed");
|
2010-06-06 09:34:36 +00:00
|
|
|
else
|
|
|
|
delete m;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_Android::quit() {
|
2011-02-19 17:30:30 +01:00
|
|
|
ENTER();
|
2010-06-06 09:34:36 +00:00
|
|
|
|
2011-02-26 14:53:02 +01:00
|
|
|
_audio_thread_exit = true;
|
|
|
|
pthread_join(_audio_thread, 0);
|
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
_timer_thread_exit = true;
|
2011-02-19 16:18:15 +01:00
|
|
|
pthread_join(_timer_thread, 0);
|
2010-06-06 09:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_Android::setWindowCaption(const char *caption) {
|
2011-02-19 17:30:30 +01:00
|
|
|
ENTER("%s", caption);
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2011-02-24 00:45:41 +01:00
|
|
|
JNI::setWindowCaption(caption);
|
2010-06-06 09:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_Android::displayMessageOnOSD(const char *msg) {
|
2011-02-19 17:30:30 +01:00
|
|
|
ENTER("%s", msg);
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2011-02-24 00:45:41 +01:00
|
|
|
JNI::displayMessageOnOSD(msg);
|
2010-06-06 09:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_Android::showVirtualKeyboard(bool enable) {
|
2011-02-19 17:30:30 +01:00
|
|
|
ENTER("%d", enable);
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2011-02-24 00:45:41 +01:00
|
|
|
JNI::showVirtualKeyboard(enable);
|
2010-06-06 09:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::SaveFileManager *OSystem_Android::getSavefileManager() {
|
|
|
|
assert(_savefile);
|
|
|
|
return _savefile;
|
|
|
|
}
|
|
|
|
|
|
|
|
Audio::Mixer *OSystem_Android::getMixer() {
|
|
|
|
assert(_mixer);
|
|
|
|
return _mixer;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::TimerManager *OSystem_Android::getTimerManager() {
|
|
|
|
assert(_timer);
|
|
|
|
return _timer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_Android::getTimeAndDate(TimeDate &td) const {
|
|
|
|
struct tm tm;
|
2011-02-19 16:18:15 +01:00
|
|
|
const time_t curTime = time(0);
|
|
|
|
|
2010-06-06 09:34:36 +00:00
|
|
|
localtime_r(&curTime, &tm);
|
|
|
|
td.tm_sec = tm.tm_sec;
|
|
|
|
td.tm_min = tm.tm_min;
|
|
|
|
td.tm_hour = tm.tm_hour;
|
|
|
|
td.tm_mday = tm.tm_mday;
|
|
|
|
td.tm_mon = tm.tm_mon;
|
|
|
|
td.tm_year = tm.tm_year;
|
|
|
|
}
|
|
|
|
|
|
|
|
FilesystemFactory *OSystem_Android::getFilesystemFactory() {
|
|
|
|
return _fsFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_Android::addSysArchivesToSearchSet(Common::SearchSet &s,
|
2011-02-19 16:18:15 +01:00
|
|
|
int priority) {
|
2011-02-24 00:45:41 +01:00
|
|
|
ENTER("");
|
2011-02-19 16:18:15 +01:00
|
|
|
|
2011-02-24 00:45:41 +01:00
|
|
|
JNI::addSysArchivesToSearchSet(s, priority);
|
2010-06-06 09:34:36 +00:00
|
|
|
}
|
|
|
|
|
2010-11-18 19:12:14 +00:00
|
|
|
void OSystem_Android::logMessage(LogMessageType::Type type, const char *message) {
|
|
|
|
switch (type) {
|
|
|
|
case LogMessageType::kDebug:
|
2011-02-19 17:30:30 +01:00
|
|
|
__android_log_write(ANDROID_LOG_DEBUG, android_log_tag, message);
|
2010-11-18 19:12:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LogMessageType::kWarning:
|
2011-02-19 17:30:30 +01:00
|
|
|
__android_log_write(ANDROID_LOG_WARN, android_log_tag, message);
|
2010-11-18 19:12:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LogMessageType::kError:
|
2011-02-19 17:30:30 +01:00
|
|
|
__android_log_write(ANDROID_LOG_ERROR, android_log_tag, message);
|
2010-11-18 19:12:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-06-06 09:34:36 +00:00
|
|
|
|
|
|
|
#ifdef DYNAMIC_MODULES
|
|
|
|
void AndroidPluginProvider::addCustomDirectories(Common::FSList &dirs) const {
|
2011-02-23 22:44:33 +01:00
|
|
|
((OSystem_Android *)g_system)->addPluginDirectories(dirs);
|
2010-06-06 09:34:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
2011-02-20 17:01:46 +01:00
|
|
|
|