Fix things for Android

This commit is contained in:
RadialApps 2017-08-08 16:07:43 +05:30
parent 085534ee72
commit 70bf373271
10 changed files with 402 additions and 4 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.xxd
*.o *.o
*.pro.* *.pro.*
*.bak *.bak

88
Android.mk Normal file
View File

@ -0,0 +1,88 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= mkxp
LOCAL_CPPFLAGS:=-DSHARED_FLUID -DGLES2_HEADER -DFULL_MKXP_PATH=\"/data/data/com.radial.exitfate/files/mkxp.conf\"
ifeq ($(TARGET_ARCH_ABI), armeabi)
LOCAL_CPPFLAGS += -DARCH_32BIT
else ifeq ($(TARGET_ARCH_ABI), armeabi-v7a)
LOCAL_CPPFLAGS += -DARCH_32BIT
else ifeq ($(TARGET_ARCH_ABI), x86)
LOCAL_CPPFLAGS += -DARCH_32BIT
else ifeq ($(TARGET_ARCH_ABI), mips)
LOCAL_CPPFLAGS += -DARCH_32BIT
endif
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../OpenAL $(LOCAL_PATH)/../SDL_sound \
$(LOCAL_PATH)/../libsigc++ $(LOCAL_PATH) \
$(LOCAL_PATH)/../boost_headers $(LOCAL_PATH)/../pixman/pixman/pixman \
$(LOCAL_PATH)/../OpenAL/include/AL $(LOCAL_PATH)/../physfs/src \
$(LOCAL_PATH)/../vorbis-include $(LOCAL_PATH)/src $(LOCAL_PATH)/shader \
$(LOCAL_PATH)/assets $(LOCAL_PATH)/../ruby/include $(LOCAL_PATH)/../fluidsynth/include
LOCAL_SRC_FILES := \
$(LOCAL_PATH)/src/main.cpp \
$(LOCAL_PATH)/src/audio.cpp \
$(LOCAL_PATH)/src/bitmap.cpp \
$(LOCAL_PATH)/src/eventthread.cpp \
$(LOCAL_PATH)/src/filesystem.cpp \
$(LOCAL_PATH)/src/font.cpp \
$(LOCAL_PATH)/src/input.cpp \
$(LOCAL_PATH)/src/plane.cpp \
$(LOCAL_PATH)/src/scene.cpp \
$(LOCAL_PATH)/src/sprite.cpp \
$(LOCAL_PATH)/src/table.cpp \
$(LOCAL_PATH)/src/tilequad.cpp \
$(LOCAL_PATH)/src/viewport.cpp \
$(LOCAL_PATH)/src/window.cpp \
$(LOCAL_PATH)/src/texpool.cpp \
$(LOCAL_PATH)/src/shader.cpp \
$(LOCAL_PATH)/src/glstate.cpp \
$(LOCAL_PATH)/src/tilemap.cpp \
$(LOCAL_PATH)/src/autotiles.cpp \
$(LOCAL_PATH)/src/graphics.cpp \
$(LOCAL_PATH)/src/gl-debug.cpp \
$(LOCAL_PATH)/src/etc.cpp \
$(LOCAL_PATH)/src/config.cpp \
$(LOCAL_PATH)/src/settingsmenu.cpp \
$(LOCAL_PATH)/src/keybindings.cpp \
$(LOCAL_PATH)/src/tileatlas.cpp \
$(LOCAL_PATH)/src/sharedstate.cpp \
$(LOCAL_PATH)/src/gl-fun.cpp \
$(LOCAL_PATH)/src/gl-meta.cpp \
$(LOCAL_PATH)/src/vertex.cpp \
$(LOCAL_PATH)/src/soundemitter.cpp \
$(LOCAL_PATH)/src/sdlsoundsource.cpp \
$(LOCAL_PATH)/src/alstream.cpp \
$(LOCAL_PATH)/src/audiostream.cpp \
$(LOCAL_PATH)/src/rgssad.cpp \
$(LOCAL_PATH)/src/bundledfont.cpp \
$(LOCAL_PATH)/src/vorbissource.cpp \
$(LOCAL_PATH)/src/windowvx.cpp \
$(LOCAL_PATH)/src/tilemapvx.cpp \
$(LOCAL_PATH)/src/tileatlasvx.cpp \
$(LOCAL_PATH)/src/autotilesvx.cpp \
$(LOCAL_PATH)/src/midisource.cpp \
$(LOCAL_PATH)/src/fluid-fun.cpp \
$(LOCAL_PATH)/binding-mri/binding-mri.cpp \
$(LOCAL_PATH)/binding-mri/binding-util.cpp \
$(LOCAL_PATH)/binding-mri/bitmap-binding.cpp \
$(LOCAL_PATH)/binding-mri/table-binding.cpp \
$(LOCAL_PATH)/binding-mri/etc-binding.cpp \
$(LOCAL_PATH)/binding-mri/font-binding.cpp \
$(LOCAL_PATH)/binding-mri/graphics-binding.cpp \
$(LOCAL_PATH)/binding-mri/input-binding.cpp \
$(LOCAL_PATH)/binding-mri/sprite-binding.cpp \
$(LOCAL_PATH)/binding-mri/viewport-binding.cpp \
$(LOCAL_PATH)/binding-mri/plane-binding.cpp \
$(LOCAL_PATH)/binding-mri/window-binding.cpp \
$(LOCAL_PATH)/binding-mri/tilemap-binding.cpp \
$(LOCAL_PATH)/binding-mri/audio-binding.cpp \
$(LOCAL_PATH)/binding-mri/module_rpg.cpp \
$(LOCAL_PATH)/binding-mri/filesystem-binding.cpp \
$(LOCAL_PATH)/binding-mri/windowvx-binding.cpp \
$(LOCAL_PATH)/binding-mri/tilemapvx-binding.cpp \
LOCAL_STATIC_LIBRARIES:=vorbis physfs sigc++ pixman boost_program_options ruby SDL2_static SDL2_ttf SDL2_sound SDL2_image fluidsynth ogg OpenAL
LOCAL_LDLIBS:=-lz -llog -ldl -lm -lOpenSLES
include $(BUILD_SHARED_LIBRARY)

9
make_xxd.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/sh
rm -f shader/*.xxd*
for i in $(ls shader); do
xxd -i "shader/$i" "shader/$i.xxd"
done
rm -f assets/*.xxd*
for i in $(ls assets); do
xxd -i "assets/$i" "assets/$i.xxd"
done

View File

@ -24,6 +24,8 @@
#include <boost/program_options/options_description.hpp> #include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp> #include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp> #include <boost/program_options/variables_map.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <SDL_filesystem.h> #include <SDL_filesystem.h>
@ -143,7 +145,7 @@ std::set<T> setFromVec(const std::vector<T> &vec)
typedef std::vector<std::string> StringVec; typedef std::vector<std::string> StringVec;
namespace po = boost::program_options; namespace po = boost::program_options;
#define CONF_FILE "mkxp.conf" #define CONF_FILE FULL_MKXP_PATH
Config::Config() Config::Config()
{} {}
@ -175,14 +177,15 @@ void Config::read(int argc, char *argv[])
PO_DESC(dataPathOrg, std::string, "") \ PO_DESC(dataPathOrg, std::string, "") \
PO_DESC(dataPathApp, std::string, "") \ PO_DESC(dataPathApp, std::string, "") \
PO_DESC(iconPath, std::string, "") \ PO_DESC(iconPath, std::string, "") \
PO_DESC(overlayPath, std::string, "") \
PO_DESC(execName, std::string, "Game") \ PO_DESC(execName, std::string, "Game") \
PO_DESC(titleLanguage, std::string, "") \ PO_DESC(titleLanguage, std::string, "") \
PO_DESC(midi.soundFont, std::string, "") \ PO_DESC(midi.soundFont, std::string, "") \
PO_DESC(midi.chorus, bool, false) \ PO_DESC(midi.chorus, bool, false) \
PO_DESC(midi.reverb, bool, false) \ PO_DESC(midi.reverb, bool, false) \
PO_DESC(SE.sourceCount, int, 6) \ PO_DESC(SE.sourceCount, int, 6) \
PO_DESC(customScript, std::string, "") \
PO_DESC(pathCache, bool, true) \ PO_DESC(pathCache, bool, true) \
PO_DESC(customScript, std::string, "") \
PO_DESC(useScriptNames, bool, false) PO_DESC(useScriptNames, bool, false)
// Not gonna take your shit boost // Not gonna take your shit boost
@ -406,3 +409,83 @@ void Config::readGameINI()
setupScreenSize(*this); setupScreenSize(*this);
} }
using namespace boost::property_tree;
using namespace boost::property_tree::json_parser;
static void
parseOverlayButtonDesc(const ptree &pt, TouchOverlay::Button &out)
{
out.id = pt.get<std::string>("id");
out.target = pt.get<std::string>("target");
out.x = pt.get<int>("x");
out.y = pt.get<int>("y");
const std::string &shape = pt.get<std::string>("shape");
if (shape == "rectangle")
{
out.shape = TouchOverlay::Button::Rectangle;
out.u.r.width = pt.get<int>("width");
out.u.r.height = pt.get<int>("height");
}
else if (shape == "circle")
{
out.shape = TouchOverlay::Button::Circle;
out.u.c.radius = pt.get<int>("radius");
}
else if (shape == "triangle")
{
out.shape = TouchOverlay::Button::Triangle;
out.u.t.x1 = pt.get<int>("x1");
out.u.t.y1 = pt.get<int>("y1");
out.u.t.x2 = pt.get<int>("x2");
out.u.t.y2 = pt.get<int>("y2");
}
else
{
throw std::logic_error("unknown button shape: " + shape);
}
}
static void
parseOverlayDesc(const ptree &pt, TouchOverlay &out)
{
out.image = pt.get<std::string>("image");
const ptree &buttons = pt.get_child("buttons");
for (ptree::const_iterator ci = buttons.begin(); ci != buttons.end(); ++ci)
{
const ptree &c = ci->second;
TouchOverlay::Button button;
parseOverlayButtonDesc(c, button);
out.buttons.push_back(button);
}
}
void Config::readOverlayDesc()
{
SDLRWStream descFile(overlayPath.c_str(), "r");
if (descFile)
{
try
{
ptree json;
read_json(descFile.stream(), json);
TouchOverlay ol;
parseOverlayDesc(json, ol);
touchOverlay = ol;
}
catch (const std::exception &e)
{
Debug() << "Error parsing overlay descrption: " << e.what();
}
}
else
{
Debug() << "Didn't parse overlay desc cuz no file";
}
}

View File

@ -26,6 +26,49 @@
#include <vector> #include <vector>
#include <set> #include <set>
struct TouchOverlay
{
std::string image;
struct Button
{
enum Shape
{
Rectangle,
Circle,
Triangle
};
std::string id;
std::string target;
Shape shape;
int x;
int y;
union
{
struct
{
int width;
int height;
} r;
struct
{
int radius;
} c;
struct
{
int x1, y1;
int x2, y2;
} t;
} u;
};
std::vector<Button> buttons;
};
struct Config struct Config
{ {
int rgssVersion; int rgssVersion;
@ -62,6 +105,7 @@ struct Config
std::string dataPathApp; std::string dataPathApp;
std::string iconPath; std::string iconPath;
std::string overlayPath;
std::string execName; std::string execName;
std::string titleLanguage; std::string titleLanguage;
@ -97,10 +141,13 @@ struct Config
std::string customDataPath; std::string customDataPath;
std::string commonDataPath; std::string commonDataPath;
TouchOverlay touchOverlay;
Config(); Config();
void read(int argc, char *argv[]); void read(int argc, char *argv[]);
void readGameINI(); void readGameINI();
void readOverlayDesc();
}; };
#endif // CONFIG_H #endif // CONFIG_H

View File

@ -267,6 +267,7 @@ void EventThread::process(RGSSThreadData &rtData)
break; break;
} }
#ifndef __ANDROID__
if (event.key.keysym.scancode == SDL_SCANCODE_F1) if (event.key.keysym.scancode == SDL_SCANCODE_F1)
{ {
if (!sMenu) if (!sMenu)
@ -277,6 +278,7 @@ void EventThread::process(RGSSThreadData &rtData)
sMenu->raise(); sMenu->raise();
} }
#endif
if (event.key.keysym.scancode == SDL_SCANCODE_F2) if (event.key.keysym.scancode == SDL_SCANCODE_F2)
{ {

View File

@ -476,6 +476,9 @@ struct GraphicsPrivate
TEXFBO frozenScene; TEXFBO frozenScene;
Quad screenQuad; Quad screenQuad;
TEX::ID overlayTex;
Vec2i overlayTexSize;
/* Global list of all live Disposables /* Global list of all live Disposables
* (disposed on reset) */ * (disposed on reset) */
IntruList<Disposable> dispList; IntruList<Disposable> dispList;
@ -504,6 +507,29 @@ struct GraphicsPrivate
screenQuad.setTexPosRect(screenRect, screenRect); screenQuad.setTexPosRect(screenRect, screenRect);
fpsLimiter.resetFrameAdjust(); fpsLimiter.resetFrameAdjust();
const std::string &olImage = rtData->config.touchOverlay.image;
if (!olImage.empty())
{
SDL_RWops *ops = SDL_RWFromFile(olImage.c_str(), "rb");
SDL_Surface *surf = IMG_Load_RW(ops, 1);
if (surf)
{
overlayTex = TEX::gen();
TEX::bind(overlayTex);
TEX::setRepeat(false);
TEX::setSmooth(true);
TEX::uploadImage(surf->w, surf->h, surf->pixels, GL_RGBA);
overlayTexSize = Vec2i(surf->w, surf->h);
}
else
{
Debug() << "failed to load overlay image:" << SDL_GetError();
}
}
} }
~GraphicsPrivate() ~GraphicsPrivate()
@ -598,9 +624,30 @@ struct GraphicsPrivate
threadData->config.smoothScaling); threadData->config.smoothScaling);
} }
void drawOverlay()
{
if (overlayTex == TEX::ID(0))
return;
SimpleShader &shader = shState->shaders().simple;
shader.bind();
shader.applyViewportProj();
shader.setTexSize(overlayTexSize);
shader.setTranslation(Vec2i());
glState.blend.pushSet(true);
TEX::bind(overlayTex);
screenQuad.draw();
glState.blend.pop();
}
void redrawScreen() void redrawScreen()
{ {
screen.composite(); screen.composite();
drawOverlay();
GLMeta::blitBeginScreen(winSize); GLMeta::blitBeginScreen(winSize);
GLMeta::blitSource(screen.getPP().frontBuffer()); GLMeta::blitSource(screen.getPP().frontBuffer());
@ -787,6 +834,7 @@ void Graphics::transition(int duration,
FBO::bind(transBuffer.fbo); FBO::bind(transBuffer.fbo);
FBO::clear(); FBO::clear();
p->screenQuad.draw(); p->screenQuad.draw();
p->drawOverlay();
p->checkResize(); p->checkResize();

View File

@ -32,6 +32,7 @@
#include <vector> #include <vector>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <math.h>
#define BUTTON_CODE_COUNT 24 #define BUTTON_CODE_COUNT 24
@ -202,6 +203,114 @@ struct MsBinding : public Binding
int index; int index;
}; };
static Input::ButtonCode bcFromString(const std::string &str)
{
#define BC_CASE(button) \
else if (str == #button) \
return Input:: button
if (false) {}
BC_CASE(Down);
BC_CASE(Left);
BC_CASE(Right);
BC_CASE(Up);
BC_CASE(A);
BC_CASE(B);
BC_CASE(C);
BC_CASE(X);
BC_CASE(Y);
BC_CASE(Z);
BC_CASE(L);
BC_CASE(R);
return Input::None;
}
static TouchOverlay::Button dummyOlButton;
static int areaSign(int x0, int y0, int x1, int y1, int x2, int y2)
{
return (x0 - x2) * (y1 - y2) - (x1 - x2) * (y0 - y2);
}
/* Touch overlay binding */
struct OlBinding : public Binding
{
OlBinding()
: olb(dummyOlButton)
{}
OlBinding(const TouchOverlay::Button &b)
: Binding(bcFromString(b.target)),
olb(b)
{}
bool sourceActive() const
{
const Vec2i &scOffset = shState->rtData().screenOffset;
const Vec2 &resoRatio = shState->rtData().sizeResoRatio;
for (size_t i = 0; i < MAX_FINGERS; ++i)
{
EventThread::FingerState &f = EventThread::touchState.fingers[i];
if (!f.down)
continue;
int x = (f.x - scOffset.x) * resoRatio.x;
int y = (f.y - scOffset.y) * resoRatio.y;
switch (olb.shape)
{
case TouchOverlay::Button::Rectangle :
{
if ((x >= olb.x && x <= olb.x + olb.u.r.width)
&& y >= olb.y && y <= olb.y + olb.u.r.height)
return true;
break;
}
case TouchOverlay::Button::Circle :
{
int dx = x - olb.x;
int dy = y - olb.y;
int d = sqrt(dx*dx + dy*dy);
if (d <= olb.u.c.radius)
return true;
break;
}
case TouchOverlay::Button::Triangle :
{
bool s0, s1, s2;
s0 = areaSign(x, y, olb.x, olb.y, olb.u.t.x1, olb.u.t.y1) < 0;
s1 = areaSign(x, y, olb.u.t.x1, olb.u.t.y1, olb.u.t.x2, olb.u.t.y2) < 0;
s2 = areaSign(x, y, olb.u.t.x2, olb.u.t.y2, olb.x, olb.y) < 0;
if ((s0 == s1) && (s1 == s2))
return true;
break;
}
}
}
return false;
}
bool sourceRepeatable() const
{
return true;
}
TouchOverlay::Button olb;
};
/* Not rebindable */ /* Not rebindable */
static const KbBindingData staticKbBindings[] = static const KbBindingData staticKbBindings[] =
{ {
@ -272,6 +381,7 @@ struct InputPrivate
std::vector<JsHatBinding> jsHBindings; std::vector<JsHatBinding> jsHBindings;
std::vector<JsButtonBinding> jsBBindings; std::vector<JsButtonBinding> jsBBindings;
std::vector<MsBinding> msBindings; std::vector<MsBinding> msBindings;
std::vector<OlBinding> olBindings;
/* Collective binding array */ /* Collective binding array */
std::vector<Binding*> bindings; std::vector<Binding*> bindings;
@ -300,6 +410,7 @@ struct InputPrivate
{ {
initStaticKbBindings(); initStaticKbBindings();
initMsBindings(); initMsBindings();
initOlBindings(rtData.config.touchOverlay);
/* Main thread should have these posted by now */ /* Main thread should have these posted by now */
checkBindingChange(rtData); checkBindingChange(rtData);
@ -439,6 +550,7 @@ struct InputPrivate
appendBindings(kbStatBindings); appendBindings(kbStatBindings);
appendBindings(msBindings); appendBindings(msBindings);
appendBindings(olBindings);
appendBindings(kbBindings); appendBindings(kbBindings);
appendBindings(jsABindings); appendBindings(jsABindings);
@ -464,6 +576,12 @@ struct InputPrivate
msBindings[i++] = MsBinding(SDL_BUTTON_RIGHT, Input::MouseRight); msBindings[i++] = MsBinding(SDL_BUTTON_RIGHT, Input::MouseRight);
} }
void initOlBindings(const TouchOverlay &ol)
{
for (size_t i = 0; i < ol.buttons.size(); ++i)
olBindings.push_back(OlBinding(ol.buttons[i]));
}
void pollBindings(Input::ButtonCode &repeatCand) void pollBindings(Input::ButtonCode &repeatCand)
{ {
for (size_t i = 0; i < bindings.size(); ++i) for (size_t i = 0; i < bindings.size(); ++i)

View File

@ -232,6 +232,7 @@ int main(int argc, char *argv[])
} }
conf.readGameINI(); conf.readGameINI();
conf.readOverlayDesc();
assert(conf.rgssVersion >= 1 && conf.rgssVersion <= 3); assert(conf.rgssVersion >= 1 && conf.rgssVersion <= 3);
printRgssVersion(conf.rgssVersion); printRgssVersion(conf.rgssVersion);

View File

@ -127,8 +127,9 @@ struct SharedStatePrivate
fclose(tmp); fclose(tmp);
} }
#ifndef __ANDROID__
fileSystem.addPath("."); fileSystem.addPath(".");
#endif
for (size_t i = 0; i < config.rtps.size(); ++i) for (size_t i = 0; i < config.rtps.size(); ++i)
fileSystem.addPath(config.rtps[i].c_str()); fileSystem.addPath(config.rtps[i].c_str());
@ -136,7 +137,6 @@ struct SharedStatePrivate
fileSystem.createPathCache(); fileSystem.createPathCache();
fileSystem.initFontSets(fontState); fileSystem.initFontSets(fontState);
globalTexW = 128; globalTexW = 128;
globalTexH = 64; globalTexH = 64;
@ -154,6 +154,7 @@ struct SharedStatePrivate
/* RGSS3 games will call setup_midi, so there's /* RGSS3 games will call setup_midi, so there's
* no need to do it on startup */ * no need to do it on startup */
if (rgssVer <= 2) if (rgssVer <= 2)
midiState.initIfNeeded(threadData->config); midiState.initIfNeeded(threadData->config);
} }