Some basic changes for Android support. DONT_BUILD.

git-svn-id: https://svn.eduke32.com/eduke32@4386 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2014-03-22 09:25:51 +00:00
parent ba0c64971c
commit 3fd83632fb
11 changed files with 1458 additions and 0 deletions

143
polymer/eduke32/Android.mk Normal file
View file

@ -0,0 +1,143 @@
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.crg/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := duke
LOCAL_CFLAGS := -fPIC -Wimplicit -Wdeclaration-after-statement -O2 -funswitch-loops -fomit-frame-pointer -DNDEBUG -DUSING_LTO -flto -fno-stack-protector -W -Werror-implicit-function-declaration -Wpointer-arith -Wextra -funsigned-char -fno-strict-aliasing -DNO_GCC_BUILTINS -D_FORTIFY_SOURCE=2 -fjump-tables -Wno-unused-result -Wno-char-subscripts -DUSE_LIBPNG -pthread -I/usr/lib/i386-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -DHAVE_INTTYPES -D_GNU_SOURCE=1 -D_REENTRANT -DRENDERTYPESDL=1 -Wno-strict-overflow -DUSE_OPENGL -Wno-attributes
#Needed my jaudiolib
LOCAL_CFLAGS += -DHAVE_SDL
LOCAL_LDLIBS += -lGLESv1_CM -lEGL
LOCAL_LDLIBS += -llog
LOCAL_CFLAGS += -march=armv7-a -mfloat-abi=softfp
LOCAL_LDLIBS += -Wl,--fix-cortex-a8
LOCAL_C_INCLUDES := $(LOCAL_PATH)/source $(LOCAL_PATH)/source/jmact $(LOCAL_PATH)/source/jaudiolib/include $(LOCAL_PATH)/source/enet/include $(LOCAL_PATH)/build/include $(TOP_DIR)/SDL2/include $(TOP_DIR)/SDL2_mixer $(IDTECH_DIR)/libpng $(IDTECH_DIR)/TinyXML $(IDTECH_DIR)/TouchControls $(IDTECH_DIR)/
ANDROID_SRC = \
source/android/android-jni.cpp \
source/android/in_android.c
BUILD_SRC = \
build/src/a-c.c \
build/src/baselayer.c \
build/src/cache1d.c \
build/src/compat.c \
build/src/crc32.c \
build/src/defs.c \
build/src/engine.c \
build/src/polymost.c \
build/src/texcache.c \
build/src/dxtfilter.c \
build/src/hightile.c \
build/src/textfont.c \
build/src/smalltextfont.c \
build/src/kplib.c \
build/src/lz4.c \
build/src/osd.c \
build/src/pragmas.c \
build/src/scriptfile.c \
build/src/mutex.c
GL_SRC = \
build/src/mdsprite.c \
build/src/glbuild_android.c \
SDL_SRC = \
build/src/sdlayer.c \
JMACT_SRC=source/jmact/file_lib.c \
source/jmact//control.c \
source/jmact//keyboard.c \
source/jmact//mouse.c \
source/jmact//joystick.c \
source/jmact//mathutil.c \
source/jmact//scriplib.c \
source/jmact//animlib.c
GAME_SRC=source/game.c \
source/actors.c \
source/anim.c \
source/common.c \
source/config.c \
source/demo.c \
source/gamedef.c \
source/gameexec.c \
source/gamevars.c \
source/global.c \
source/input.c \
source/menus.c \
source/namesdyn.c \
source/net.c \
source/player.c \
source/premap.c \
source/savegame.c \
source/sector.c \
source/rts.c \
source/osdfuncs.c \
source/osdcmds.c \
source/grpscan.c \
source/sounds.c \
source/soundsdyn.c \
source/sdlmusic.c \
JAUDIO_SRC=source/jaudiolib/src/drivers.c \
source/jaudiolib/src//fx_man.c \
source/jaudiolib/src//multivoc.c \
source/jaudiolib/src//mix.c \
source/jaudiolib/src//mixst.c \
source/jaudiolib/src//pitch.c \
source/jaudiolib/src//formats.c \
source/jaudiolib/src//vorbis.c \
source/jaudiolib/src//flac.c \
source/jaudiolib/src//xa.c \
source/jaudiolib/src//driver_nosound.c \
source/jaudiolib/src//driver_sdl.c
ENET_SRC=source/enet/src/callbacks.c \
source/enet/src/host.c \
source/enet/src/list.c \
source/enet/src/packet.c \
source/enet/src/peer.c \
source/enet/src/protocol.c \
source/enet/src/compress.c \
source/enet/src/unix.c
LOCAL_SRC_FILES = $(ANDROID_SRC) $(ENET_SRC) $(JAUDIO_SRC) $(JMACT_SRC) $(GAME_SRC) $(BUILD_SRC) $(GL_SRC) $(SDL_SRC)
LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog -lOpenSLES -lz
LOCAL_STATIC_LIBRARIES := nanogl SDL2_net libjpeg libpng
LOCAL_SHARED_LIBRARIES := touchcontrols openal SDL2 SDL2_mixer SDL2_image
include $(BUILD_SHARED_LIBRARY)

View file

@ -282,6 +282,8 @@
<ClInclude Include="build\src\engine_priv.h" />
<ClInclude Include="source\actors.h" />
<ClInclude Include="source\actors_inline.h" />
<ClInclude Include="source\android.h" />
<ClInclude Include="source\android\in_android.h" />
<ClInclude Include="source\anim.h" />
<ClInclude Include="source\animvpx.h" />
<ClInclude Include="source\common_game.h" />
@ -392,6 +394,8 @@
<ClCompile Include="build\src\winlayer.c" />
<ClCompile Include="source\actors.c" />
<ClCompile Include="source\actors_inline.c" />
<ClCompile Include="source\android\android-jni.cpp" />
<ClCompile Include="source\android\in_android.c" />
<ClCompile Include="source\anim.c" />
<ClCompile Include="source\animvpx.c" />
<ClCompile Include="source\astub.c" />

View file

@ -67,6 +67,12 @@
<Filter Include="eduke32\source\lunatic\lua">
<UniqueIdentifier>{f1025787-c43f-43de-8b46-143ea0462fc1}</UniqueIdentifier>
</Filter>
<Filter Include="eduke32\headers\android">
<UniqueIdentifier>{52ce6149-4982-41a4-9adf-c7a9468421fd}</UniqueIdentifier>
</Filter>
<Filter Include="eduke32\source\android">
<UniqueIdentifier>{d3b67b4f-6b78-43e0-88ab-f081b977499a}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="build\include\a.h">
@ -417,6 +423,12 @@
<ClInclude Include="source\lunatic\lunatic_m32.h">
<Filter>eduke32\source\lunatic\headers</Filter>
</ClInclude>
<ClInclude Include="source\android\in_android.h">
<Filter>eduke32\headers\android</Filter>
</ClInclude>
<ClInclude Include="source\android.h">
<Filter>eduke32\headers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="build\src\a-c.c">
@ -734,6 +746,12 @@
<ClCompile Include="source\lunatic\lunatic_m32.c">
<Filter>eduke32\source\lunatic\source</Filter>
</ClCompile>
<ClCompile Include="source\android\android-jni.cpp">
<Filter>eduke32\source\android</Filter>
</ClCompile>
<ClCompile Include="source\android\in_android.c">
<Filter>eduke32\source\android</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Makefile.msvc">

View file

@ -0,0 +1,38 @@
//-------------------------------------------------------------------------
/*
Copyright (C) 2010 EDuke32 developers and contributors
This file is part of EDuke32.
EDuke32 is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
//-------------------------------------------------------------------------
#ifndef __android_h__
#define __android_h__
#ifdef __ANDROID__
#include "compat.h"
#include "control.h"
extern int android_screen_width;
extern int android_screen_height;
extern void CONTROL_Android_ClearButton(int32_t whichbutton);
extern void CONTROL_Android_PollDevices(ControlInfo *info);
extern void setLastWeapon(int w);
#endif
#endif

View file

@ -0,0 +1,881 @@
/*
*
* Designed by Emile Belanger
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <jni.h>
#include <android/log.h>
#include "SDL_scancode.h"
#include "TouchControlsContainer.h"
extern "C"
{
//This is a new function I put into SDL2, file SDL_androidgl.c
extern void SDL_SetSwapBufferCallBack(void (*pt2Func)(void));
#include "in_android.h"
#include "../GL/gl.h"
#include "../GL/nano_gl.h"
#ifndef LOGI
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO,"DUKE", __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "DUKE", __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR,"DUKE", __VA_ARGS__))
#endif
#define REND_SOFT 0
#define REND_GL 1
static int curRenderer;
int android_screen_width;
int android_screen_height;
#define KEY_QUICK_CMD 0x1005
#define KEY_SHOW_KBRD 0x1008
#define KEY_SHOW_INVEN 0x1009
#define KEY_QUICK_SAVE 0x100A
#define KEY_QUICK_LOAD 0x100B
#define KEY_SNIPER 0x100C
#define KEY_QUICK_KEY1 0x1011
#define KEY_QUICK_KEY2 0x1012
#define KEY_QUICK_KEY3 0x1013
#define KEY_QUICK_KEY4 0x1014
float gameControlsAlpha = 0.5;
bool showWeaponCycle = false;
bool turnMouseMode = true;
bool invertLook = false;
bool precisionShoot = false;
bool showSticks = true;
bool hideTouchControls = true;
bool shooting = false;
bool sniperMode = false;
static int controlsCreated = 0;
touchcontrols::TouchControlsContainer controlsContainer;
touchcontrols::TouchControls *tcMenuMain=0;
touchcontrols::TouchControls *tcGameMain=0;
touchcontrols::TouchControls *tcGameWeapons=0;
touchcontrols::TouchControls *tcAutomap=0;
touchcontrols::TouchControls *tcInventory=0;
touchcontrols::TouchControls *tcGameLook=0; //Just used for whole screen look mode
touchcontrols::TouchJoy *touchJoyLeft;
touchcontrols::TouchJoy *touchJoyRight;
touchcontrols::WheelSelect *weaponWheel;
extern JNIEnv* env_;
void openGLStart()
{
if (curRenderer == REND_GL)
{
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof (0, android_screen_width, android_screen_height, 0, 0, 1);
//glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
//glClear(GL_COLOR_BUFFER_BIT);
//LOGI("openGLStart");
glDisable(GL_ALPHA_TEST);
glDisable(GL_DEPTH_TEST);
glDisable(GL_FOG);
glEnable(GL_TEXTURE_2D);
glEnable (GL_BLEND);
glColor4f(1,1,1,1);
glDisableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY );
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_CULL_FACE);
glMatrixMode(GL_MODELVIEW);
nanoPushState();
}
else //software mode
{
glDisable(GL_ALPHA_TEST);
glDisableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY );
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable (GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glDisable(GL_CULL_FACE);
glMatrixMode(GL_MODELVIEW);
}
}
void openGLEnd()
{
if (curRenderer == REND_GL)
{
//glPopMatrix();
nanoPopState();
glPopMatrix();
}
else// Software mode
{
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glMatrixMode(GL_MODELVIEW);
}
}
void gameSettingsButton(int state)
{
//LOGTOUCH("gameSettingsButton %d",state);
if (state == 1)
{
jclass helloWorldClass;
jmethodID mainMethod;
helloWorldClass = env_->FindClass("com/beloko/duke/QuakeTouchControlsSettings");
mainMethod = env_->GetStaticMethodID(helloWorldClass, "showSettings", "()V");
env_->CallStaticVoidMethod(helloWorldClass, mainMethod);
}
}
void showCustomCommands()
{
jclass helloWorldClass;
jmethodID mainMethod;
helloWorldClass = env_->FindClass("com/beloko/duke/QuakeCustomCommands");
mainMethod = env_->GetStaticMethodID(helloWorldClass, "showCommands", "()V");
env_->CallStaticVoidMethod(helloWorldClass, mainMethod);
}
void toggleKeyboard()
{
LOGI("toggleKeyboard");
jclass helloWorldClass;
jmethodID mainMethod;
helloWorldClass = env_->FindClass("com/beloko/duke/ShowKeyboard");
mainMethod = env_->GetStaticMethodID(helloWorldClass, "toggleKeyboard", "()V");
env_->CallStaticVoidMethod(helloWorldClass, mainMethod);
}
//Because there is no Frame(), we need to check back to java each frame to see if the app hase paused
static jclass NativeLibClass = 0;
static jmethodID checkPauseMethod = 0;
void swapBuffers()
{
if (NativeLibClass == 0)
{
NativeLibClass = env_->FindClass("com/beloko/duke/engine/NativeLib");
checkPauseMethod = env_->GetStaticMethodID(NativeLibClass, "swapBuffers", "()V");
}
env_->CallStaticVoidMethod(NativeLibClass, checkPauseMethod);
}
void gameButton(int state,int code)
{
if (code == gamefunc_Fire)
{
shooting = state;
PortableAction(state, code);
}
if (code == KEY_SNIPER)
{
sniperMode = state;
}
else if (code == KEY_SHOW_KBRD)
{
if (state)
toggleKeyboard();
PortableKeyEvent(state, SDL_SCANCODE_GRAVE,0);
}
else if (code == KEY_QUICK_CMD){
if (state == 1)
showCustomCommands();
}
else if (code == KEY_SHOW_INVEN){
if (state == 1)
{
if (!tcInventory->isEnabled())
{
tcInventory->setEnabled(true);
tcInventory->fade(0,5);
//disable weapon wheel so it does not show, enabled again after inventory cleared
tcGameWeapons->setEnabled(false);
}
else
{
tcInventory->setEnabled(false);
tcGameWeapons->setEnabled(true);
}
}
}
else if (code == KEY_QUICK_SAVE){
LOGI("QUICK SAVE");
PortableKeyEvent(state, SDL_SCANCODE_F6,0);
}
else if (code == KEY_QUICK_LOAD){
LOGI("QUICK LOAD");
PortableKeyEvent(state, SDL_SCANCODE_F9,0);
}
else
PortableAction(state, code);
}
void automapButton(int state,int code)
{
PortableAction(state,code);
}
void inventoryButton(int state,int code)
{
PortableAction(state,code);
if (state == 0)
{
tcGameWeapons->setEnabled(true);
tcInventory->setEnabled(false);
}
}
void menuButton(int state,int code)
{
PortableKeyEvent(state, code,code);
}
static int weaponWheelVisible = false;
void weaponWheelSelected(int enabled)
{
if (enabled)
{
for (int n=0;n<10;n++)
{
weaponWheel->setSegmentEnabled(n,(PortableGetWeapons() >> n) & 0x1);
}
tcGameWeapons->fade(0,5); //fade in
weaponWheelVisible = true;
}
else
{
tcGameWeapons->fade(1,5);
weaponWheelVisible = false;
}
}
void weaponWheelChosen(int segment)
{
LOGI("weaponWheel %d",segment);
if (segment != -1)
{
PortableAction(1, gamefunc_Weapon_1 + segment);
PortableAction(0, gamefunc_Weapon_1 + segment);
}
else //Nothing was selected
{
if (getLastWeapon() != -1)
{
PortableAction(1, gamefunc_Weapon_1 + getLastWeapon());
PortableAction(0, gamefunc_Weapon_1 + getLastWeapon());
}
}
}
int left_double_action;
int right_double_action;
void left_double_tap(int state)
{
//LOGTOUCH("L double %d",state);
if (left_double_action)
PortableAction(state,left_double_action);
}
void right_double_tap(int state)
{
//LOGTOUCH("R double %d",state);
if (right_double_action)
PortableAction(state,right_double_action);
}
//To be set by android
float strafe_sens,forward_sens;
float pitch_sens,yaw_sens;
void left_stick(float joy_x, float joy_y,float mouse_x, float mouse_y)
{
joy_x *=10;
float strafe = joy_x*joy_x;
//float strafe = joy_x;
if (joy_x < 0)
strafe *= -1;
PortableMove(joy_y * 15 * forward_sens,-strafe * strafe_sens);
}
extern int crouchToggleState; //Set in anroid_in.c
void right_stick(float joy_x, float joy_y,float mouse_x, float mouse_y)
{
//LOGI(" mouse x = %f",mouse_x);
int invert = invertLook?-1:1;
float scale = ((shooting && precisionShoot) || crouchToggleState)?0.3:1;
PortableLookPitch(LOOK_MODE_MOUSE,-mouse_y * pitch_sens * invert * scale);
if (turnMouseMode)
PortableLookYaw(LOOK_MODE_MOUSE,mouse_x*2*yaw_sens * scale);
else
PortableLookYaw(LOOK_MODE_JOYSTICK,joy_x*6*yaw_sens * scale);
}
void mouseMove(int action,float x, float y,float dx, float dy)
{
LOGI(" mouse dx = %f",dx);
if (weaponWheelVisible)
return;
/*
if (abs(dx) < 0.001)
{
dx * 0.1;
}
*/
int invert = invertLook?-1:1;
float scale;
if (sniperMode)
scale = 0.2;
else
scale = ((shooting && precisionShoot) || crouchToggleState)?0.2:1;
PortableLookPitch(LOOK_MODE_MOUSE,-dy * pitch_sens * invert * scale);
PortableLookYaw(LOOK_MODE_MOUSE,dx*2*yaw_sens * scale);
}
void setHideSticks(bool v)
{
if (touchJoyLeft) touchJoyLeft->setHideGraphics(v);
if (touchJoyRight) touchJoyRight->setHideGraphics(v);
}
void touchSettingsButton(int state)
{
//We wanna pause the game when doign settings
if (state && !isPaused())
{
PortableKeyEvent(1,SDL_SCANCODE_PAUSE,0);
PortableKeyEvent(0,SDL_SCANCODE_PAUSE,0);
}
else if (!state && isPaused())
{
PortableKeyEvent(1,SDL_SCANCODE_PAUSE,0);
PortableKeyEvent(0,SDL_SCANCODE_PAUSE,0);
}
}
void initControls(int width, int height,const char * graphics_path,const char *settings_file)
{
touchcontrols::GLScaleWidth = (float)width;
touchcontrols::GLScaleHeight = (float)height;
LOGI("initControls %d x %d,x path = %s, settings = %s",width,height,graphics_path,settings_file);
if (!controlsCreated)
{
LOGI("creating controls");
touchcontrols::setGraphicsBasePath(graphics_path);
controlsContainer.openGL_start.connect( sigc::ptr_fun(&openGLStart));
controlsContainer.openGL_end.connect( sigc::ptr_fun(&openGLEnd));
controlsContainer.signal_settings.connect( sigc::ptr_fun(&touchSettingsButton));
tcMenuMain = new touchcontrols::TouchControls("menu",true,false);
tcGameMain = new touchcontrols::TouchControls("game",false,true,1,true);
tcGameWeapons = new touchcontrols::TouchControls("weapons",false,true,1,false);
tcAutomap = new touchcontrols::TouchControls("automap",false,true,1,false);
tcInventory = new touchcontrols::TouchControls("inventory",false,true,1,false);
tcGameLook = new touchcontrols::TouchControls("mouse",true,false);
controlsContainer.dukeHack = 1;
tcGameMain->signal_settingsButton.connect( sigc::ptr_fun(&gameSettingsButton) );
//Menu
tcMenuMain->addControl(new touchcontrols::Button("down_arrow",touchcontrols::RectF(20,13,23,16),"arrow_down",SDL_SCANCODE_DOWN,true)); //Repeating buttons
tcMenuMain->addControl(new touchcontrols::Button("up_arrow",touchcontrols::RectF(20,10,23,13),"arrow_up",SDL_SCANCODE_UP,true));
tcMenuMain->addControl(new touchcontrols::Button("left_arrow",touchcontrols::RectF(17,13,20,16),"arrow_left",SDL_SCANCODE_LEFT,true));
tcMenuMain->addControl(new touchcontrols::Button("right_arrow",touchcontrols::RectF(23,13,26,16),"arrow_right",SDL_SCANCODE_RIGHT,true));
tcMenuMain->addControl(new touchcontrols::Button("enter",touchcontrols::RectF(0,12,4,16),"enter",SDL_SCANCODE_RETURN));
tcMenuMain->addControl(new touchcontrols::Button("esc",touchcontrols::RectF(0,9,4,12),"esc",SDL_SCANCODE_ESCAPE));
tcMenuMain->signal_button.connect( sigc::ptr_fun(&menuButton) );
tcMenuMain->setAlpha(0.5);
tcInventory->addControl(new touchcontrols::Button("jetpack", touchcontrols::RectF(4,3,7,6),"jetpack",gamefunc_Jetpack));
tcInventory->addControl(new touchcontrols::Button("medkit", touchcontrols::RectF(7,3,10,6),"medkit",gamefunc_MedKit));
tcInventory->addControl(new touchcontrols::Button("nightv", touchcontrols::RectF(4,6,7,9),"nightvision",gamefunc_NightVision));
tcInventory->addControl(new touchcontrols::Button("holoduke",touchcontrols::RectF(7,6,10,9),"holoduke",gamefunc_Holo_Duke));
tcInventory->addControl(new touchcontrols::Button("steroids",touchcontrols::RectF(4,9,7,12),"steroids",gamefunc_Steroids));
tcMenuMain->setAlpha(1);
tcInventory->signal_button.connect( sigc::ptr_fun(&inventoryButton));
/*
//Automap
tcAutomap->addControl(new touchcontrols::Button("down_arrow",touchcontrols::RectF(2,14,4,16),"arrow_down",PORT_ACT_MAP_DOWN));
tcAutomap->addControl(new touchcontrols::Button("up_arrow",touchcontrols::RectF(2,10,4,12),"arrow_up",PORT_ACT_MAP_UP));
tcAutomap->addControl(new touchcontrols::Button("left_arrow",touchcontrols::RectF(0,12,2,14),"arrow_left",PORT_ACT_MAP_LEFT));
tcAutomap->addControl(new touchcontrols::Button("right_arrow",touchcontrols::RectF(4,12,6,14),"arrow_right",PORT_ACT_MAP_RIGHT));
tcAutomap->addControl(new touchcontrols::Button("zoom_in",touchcontrols::RectF(4,10,6,12),"zoom_in",PORT_ACT_MAP_ZOOM_IN));
tcAutomap->addControl(new touchcontrols::Button("zoom_out",touchcontrols::RectF(4,14,6,16),"zoom_out",PORT_ACT_MAP_ZOOM_OUT));
tcAutomap->signal_button.connect( sigc::ptr_fun(&automapButton) );
tcAutomap->setAlpha(0.5);
*/
//Game
tcGameMain->setAlpha(gameControlsAlpha);
controlsContainer.editButtonAlpha = gameControlsAlpha;
tcGameMain->addControl(new touchcontrols::Button("use",touchcontrols::RectF(23,4,26,7),"use",gamefunc_Open));
tcGameMain->addControl(new touchcontrols::Button("attack",touchcontrols::RectF(20,7,23,10),"fire2",gamefunc_Fire));
tcGameMain->addControl(new touchcontrols::Button("jump",touchcontrols::RectF(23,7,26,10),"jump",gamefunc_Jump));
tcGameMain->addControl(new touchcontrols::Button("crouch",touchcontrols::RectF(24,14,26,16),"crouch",gamefunc_Crouch));
tcGameMain->addControl(new touchcontrols::Button("kick",touchcontrols::RectF(20,4,23,7),"boot",gamefunc_Quick_Kick));
tcGameMain->addControl(new touchcontrols::Button("quick_save",touchcontrols::RectF(24,0,26,2),"save",KEY_QUICK_SAVE));
tcGameMain->addControl(new touchcontrols::Button("quick_load",touchcontrols::RectF(20,0,22,2),"load",KEY_QUICK_LOAD));
tcGameMain->addControl(new touchcontrols::Button("map",touchcontrols::RectF(4,0,6,2),"map",gamefunc_Map));
tcGameMain->addControl(new touchcontrols::Button("keyboard",touchcontrols::RectF(8,0,10,2),"keyboard",KEY_SHOW_KBRD));
tcGameMain->addControl(new touchcontrols::Button("show_inventory",touchcontrols::RectF(0,0,2,3),"inv",KEY_SHOW_INVEN));
tcGameMain->addControl(new touchcontrols::Button("next_weapon",touchcontrols::RectF(0,3,3,5),"next_weap",gamefunc_Next_Weapon));
tcGameMain->addControl(new touchcontrols::Button("prev_weapon",touchcontrols::RectF(0,7,3,9),"prev_weap",gamefunc_Previous_Weapon));
//tcGameMain->addControl(new touchcontrols::Button("sniper",touchcontrols::RectF(0,5,3,7),"sniper",KEY_SNIPER));
//quick actions binds
tcGameMain->addControl(new touchcontrols::Button("quick_key_1",touchcontrols::RectF(4,3,6,5),"quick_key_1",KEY_QUICK_KEY1,false,true));
tcGameMain->addControl(new touchcontrols::Button("quick_key_2",touchcontrols::RectF(6,3,8,5),"quick_key_2",KEY_QUICK_KEY2,false,true));
tcGameMain->addControl(new touchcontrols::Button("quick_key_3",touchcontrols::RectF(8,3,10,5),"quick_key_3",KEY_QUICK_KEY3,false,true));
tcGameMain->addControl(new touchcontrols::Button("quick_key_4",touchcontrols::RectF(10,3,12,5),"quick_key_4",KEY_QUICK_KEY4,false,true));
//Left stick
touchJoyLeft = new touchcontrols::TouchJoy("stick",touchcontrols::RectF(0,7,8,16),"strafe_arrow");
tcGameMain->addControl(touchJoyLeft);
touchJoyLeft->signal_move.connect(sigc::ptr_fun(&left_stick) );
touchJoyLeft->signal_double_tap.connect(sigc::ptr_fun(&left_double_tap) );
//Right stick
touchJoyRight = new touchcontrols::TouchJoy("touch",touchcontrols::RectF(17,7,26,16),"look_arrow");
tcGameMain->addControl(touchJoyRight);
touchJoyRight->signal_move.connect(sigc::ptr_fun(&right_stick) );
touchJoyRight->signal_double_tap.connect(sigc::ptr_fun(&right_double_tap) );
touchJoyRight->setEnabled(false);
tcGameMain->signal_button.connect( sigc::ptr_fun(&gameButton) );
//Mouse look for whole screen
touchcontrols::Mouse *mouse = new touchcontrols::Mouse("mouse",touchcontrols::RectF(3,0,26,16),"");
mouse->signal_action.connect(sigc::ptr_fun(&mouseMove));
mouse->signal_double_tap.connect(sigc::ptr_fun(&right_double_tap) );
mouse->setHideGraphics(true);
tcGameLook->addControl(mouse);
//Weapons
weaponWheel = new touchcontrols::WheelSelect("weapon_wheel",touchcontrols::RectF(7,2,19,14),"weapon_wheel",10);
weaponWheel->signal_selected.connect(sigc::ptr_fun(&weaponWheelChosen) );
weaponWheel->signal_enabled.connect(sigc::ptr_fun(&weaponWheelSelected));
tcGameWeapons->addControl(weaponWheel);
tcGameWeapons->setAlpha(0.9);
controlsContainer.addControlGroup(tcMenuMain);
controlsContainer.addControlGroup(tcInventory);//Need to be above tcGameMain incase buttons over stick
controlsContainer.addControlGroup(tcGameMain);
controlsContainer.addControlGroup(tcGameWeapons);
//controlsContainer.addControlGroup(tcAutomap);
controlsContainer.addControlGroup(tcGameLook);
controlsCreated = 1;
tcGameMain->setXMLFile((std::string)graphics_path + "/game.xml");
tcGameWeapons->setXMLFile((std::string)graphics_path + "/weapons.xml");
tcAutomap->setXMLFile((std::string)graphics_path + "/automap.xml");
tcInventory->setXMLFile((std::string)graphics_path + "/inventory.xml");
}
else
LOGI("NOT creating controls");
//controlsContainer.initGL();
}
int loadedGLImages=0;
int inMenuLast = 1;
int inAutomapLast = 0;
void frameControls()
{
//LOGI("frameControls");
//We need to do this here now because duke loads a new gl context
if (!loadedGLImages)
{
touchJoyRight->setEnabled(false);
controlsContainer.initGL();
loadedGLImages = 1;
}
//LOGI("frameControls");
if (PortableIsSoftwareMode())
curRenderer = REND_SOFT;
else
curRenderer = REND_GL;
int inMenuNew = PortableInMenu();
if (inMenuLast != inMenuNew)
{
inMenuLast = inMenuNew;
if (!inMenuNew)
{
tcGameMain->setEnabled(true);
tcGameWeapons->setEnabled(true);
tcGameWeapons->fade(1,5);
tcMenuMain->setEnabled(false);
}
else
{
tcGameMain->setEnabled(false);
tcGameWeapons->setEnabled(false);
tcMenuMain->setEnabled(true);
}
}
int inAutomapNew = PortableInAutomap() && !inMenuLast; //Dont show if menu comes up
if (inAutomapLast != inAutomapNew)
{
inAutomapLast = inAutomapNew;
if (inAutomapNew)
{
tcAutomap->animateIn(5);
}
else
{
tcAutomap->animateOut(5);
}
}
setHideSticks(!showSticks);
controlsContainer.draw();
}
void setTouchSettings(float alpha,float strafe,float fwd,float pitch,float yaw,int other)
{
gameControlsAlpha = alpha;
if (tcGameMain)
{
tcGameMain->setAlpha(gameControlsAlpha);
controlsContainer.editButtonAlpha = gameControlsAlpha;
}
showWeaponCycle = other & 0x1?true:false;
turnMouseMode = other & 0x2?true:false;
invertLook = other & 0x4?true:false;
precisionShoot = other & 0x8?true:false;
showSticks = other & 0x1000?true:false;
hideTouchControls = other & 0x80000000?true:false;
switch ((other>>4) & 0xF)
{
case 1:
left_double_action = gamefunc_Fire;
break;
case 2:
left_double_action = gamefunc_Jump;
break;
default:
left_double_action = 0;
}
switch ((other>>8) & 0xF)
{
case 1:
right_double_action = gamefunc_Fire;
break;
case 2:
right_double_action = gamefunc_Jump;
break;
default:
right_double_action = 0;
}
strafe_sens = strafe;
forward_sens = fwd;
pitch_sens = pitch;
yaw_sens = yaw;
}
int quit_now = 0;
#define EXPORT_ME __attribute__ ((visibility("default")))
JNIEnv* env_;
int argc=1;
const char * argv[32];
std::string graphicpath;
std::string doom_path;
const char * getDoomPath()
{
return doom_path.c_str();
}
jint EXPORT_ME
Java_com_beloko_duke_engine_NativeLib_init( JNIEnv* env,
jobject thiz,jstring graphics_dir,jint mem_mb,jobjectArray argsArray,jint renderer,jstring doom_path_ )
{
env_ = env;
curRenderer = renderer;
//curRenderer = REND_SOFT;
curRenderer = REND_GL;
argv[0] = "eduke32";
int argCount = (env)->GetArrayLength( argsArray);
LOGI("argCount = %d",argCount);
for (int i=0; i<argCount; i++) {
jstring string = (jstring) (env)->GetObjectArrayElement( argsArray, i);
argv[argc] = (char *)(env)->GetStringUTFChars( string, 0);
LOGI("arg = %s",argv[argc]);
argc++;
}
doom_path = (char *)(env)->GetStringUTFChars( doom_path_, 0);
//Change working dir, save games etc
chdir(getDoomPath());
putenv("TIMIDITY_CFG=../timidity.cfg");
LOGI("doom_path = %s",getDoomPath());
//argv[0] = "vavoom";
//argv[1] = "-basedir";
//argv[2] = "/sdcard/Beloko/Quake/FULL";
//args[3] = "-doom";
const char * p = env->GetStringUTFChars(graphics_dir,NULL);
graphicpath = std::string(p);
initControls(android_screen_width,-android_screen_height,graphicpath.c_str(),(graphicpath + "/touch_controls.xml").c_str());
//initControls(2,-2,graphicpath.c_str(),(graphicpath + "/prdoom.xml").c_str());
/*
if (renderer != REND_SOFT)
SDL_SetSwapBufferCallBack(frameControls);
if (renderer == REND_SOFT)// In soft mode SDL calls swap buffer, disable so it does not flicker
SDL_SwapBufferPerformsSwap(false);
*/
SDL_SetSwapBufferCallBack(frameControls);
//Now doen in java to keep context etc
//SDL_SwapBufferPerformsSwap(false);
PortableInit(argc,argv);
return 0;
}
jint EXPORT_ME
Java_com_beloko_duke_engine_NativeLib_frame( JNIEnv* env,
jobject thiz )
{
LOGI("Java_com_beloko_duke_engine_NativeLib_frame");
PortableFrame();
frameControls();
return 0;
}
__attribute__((visibility("default"))) jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
LOGI("JNI_OnLoad");
return JNI_VERSION_1_4;
}
void EXPORT_ME
Java_com_beloko_duke_engine_NativeLib_keypress(JNIEnv *env, jobject obj,
jint down, jint keycode, jint unicode)
{
LOGI("keypress %d",keycode);
if (controlsContainer.isEditing())
{
if (down && (keycode == SDL_SCANCODE_ESCAPE ))
controlsContainer.finishEditing();
}
else
PortableKeyEvent(down,keycode,unicode);
}
void EXPORT_ME
Java_com_beloko_duke_engine_NativeLib_touchEvent(JNIEnv *env, jobject obj,
jint action, jint pid, jfloat x, jfloat y)
{
//LOGI("TOUCHED");
controlsContainer.processPointer(action,pid,x,y);
}
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_doAction(JNIEnv *env, jobject obj,
jint state, jint action)
{
//gamepadButtonPressed();
if (hideTouchControls)
if (tcGameMain->isEnabled())
tcGameMain->animateOut(30);
LOGI("doAction %d %d",state,action);
PortableAction(state,action);
}
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogFwd(JNIEnv *env, jobject obj,
jfloat v)
{
PortableMoveFwd(v);
}
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogSide(JNIEnv *env, jobject obj,
jfloat v)
{
PortableMoveSide(v);
}
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogPitch(JNIEnv *env, jobject obj,
jint mode,jfloat v)
{
PortableLookPitch(mode, v);
}
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogYaw(JNIEnv *env, jobject obj,
jint mode,jfloat v)
{
PortableLookYaw(mode, v);
}
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_setTouchSettings(JNIEnv *env, jobject obj,
jfloat alpha,jfloat strafe,jfloat fwd,jfloat pitch,jfloat yaw,int other)
{
setTouchSettings(alpha,strafe,fwd,pitch,yaw,other);
}
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_resetTouchSettings(JNIEnv *env, jobject obj)
{
controlsContainer.resetDefaults();
}
std::string quickCommandString;
jint EXPORT_ME
Java_com_beloko_duke_engine_NativeLib_quickCommand(JNIEnv *env, jobject obj,
jstring command)
{
const char * p = env->GetStringUTFChars(command,NULL);
quickCommandString = std::string(p) + "\n";
env->ReleaseStringUTFChars(command, p);
PortableCommand(quickCommandString.c_str());
}
void EXPORT_ME
Java_com_beloko_duke_engine_NativeLib_setScreenSize( JNIEnv* env,
jobject thiz, jint width, jint height)
{
android_screen_width = width;
android_screen_height = height;
}
#include "SDL_main.h"
extern void SDL_Android_Init(JNIEnv* env, jclass cls);
void Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls)
{
/* This interface could expand with ABI negotiation, calbacks, etc. */
SDL_Android_Init(env, cls);
SDL_SetMainReady();
// SDL_EventState(SDL_TEXTINPUT,SDL_ENABLE);
}
}

View file

@ -0,0 +1,303 @@
#include "sdl_inc.h"
#include "baselayer.h"
#include "keys.h"
#include "duke3d.h"
#include "common_game.h"
#include "osd.h"
#include "player.h"
#include "jmact/keyboard.h"
#include "jmact/control.h"
#include "../src/video/android/SDL_androidkeyboard.h"
#include "in_android.h"
#include <android/log.h>
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO,"DUKE", __VA_ARGS__))
extern int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode);
extern int SDL_SendKeyboardText(const char *text);
char sdl_text[2];
int PortableKeyEvent(int state, int code,int unicode){
LOGI("PortableKeyEvent %d %d %d",state,code,unicode);
/*
if (state)
Android_OnKeyDown(code);
else
Android_OnKeyUp(code);
return;
*/
if (state)
SDL_SendKeyboardKey(SDL_PRESSED, code);
else
SDL_SendKeyboardKey(SDL_RELEASED, code);
SDL_EventState(SDL_TEXTINPUT,SDL_ENABLE);
if (code == 42)
unicode = 42;
if (state)
{
//if (unicode < 128)
{
sdl_text[0] = unicode;
sdl_text[1] = 0;
int posted = SDL_SendKeyboardText((const char*)sdl_text);
LOGI("posted = %d",posted);
}
}
return 0;
}
int crouchToggleState=0;
#define BUTTONSET(x,value) (CONTROL_ButtonState |= ((uint64_t)value<<((uint64_t)(x))))
#define BUTTONCLEAR(x) (CONTROL_ButtonState &= ~((uint64_t)1<<((uint64_t)(x))))
uint64_t functionSticky = 0; //To let at least one tick
uint64_t functionHeld = 0;
void changeActionState(int state, int action)
{
if (state)
{
//BUTTONSET(action,1);
functionSticky |= ((uint64_t)1<<((uint64_t)(action)));
functionHeld |= ((uint64_t)1<<((uint64_t)(action)));
}
else
{
//BUTTONCLEAR(action);
functionHeld &= ~((uint64_t)1<<((uint64_t)(action)));
}
}
void PortableAction(int state, int action)
{
LOGI("PortableAction action = %d, state = %d",action,state);
//Special toggle for crouch, NOT when using jetpack or in water
if (!g_player[myconnectindex].ps->jetpack_on &&
g_player[myconnectindex].ps->on_ground &&
(sector[g_player[myconnectindex].ps->cursectnum].lotag != 2))// This means underwater!
{
if (action == gamefunc_Crouch)
{
if (state)
{
crouchToggleState =!crouchToggleState;
}
state = crouchToggleState;
}
}
//Check if jumping while crouched
if (action == gamefunc_Jump)
{
if (crouchToggleState)
{
crouchToggleState = 0;
changeActionState(0,gamefunc_Crouch);
}
}
changeActionState(state,action);
LOGI("PortableAction state = 0x%016llX",CONTROL_ButtonState);
}
// =================== FORWARD and SIDE MOVMENT ==============
float forwardmove, sidemove; //Joystick mode
void PortableMoveFwd(float fwd)
{
if (fwd > 1)
fwd = 1;
else if (fwd < -1)
fwd = -1;
forwardmove = fwd;
}
void PortableMoveSide(float strafe)
{
if (strafe > 1)
strafe = 1;
else if (strafe < -1)
strafe = -1;
sidemove = strafe;
}
void PortableMove(float fwd, float strafe)
{
PortableMoveFwd(fwd);
PortableMoveSide(strafe);
}
//======================================================================
//Look up and down
int look_pitch_mode;
float look_pitch_mouse,look_pitch_abs,look_pitch_joy;
void PortableLookPitch(int mode, float pitch)
{
//LOGI("PortableLookPitch %d %f",mode, pitch);
look_pitch_mode = mode;
switch(mode)
{
case LOOK_MODE_MOUSE:
look_pitch_mouse += pitch;
break;
case LOOK_MODE_ABSOLUTE:
look_pitch_abs = pitch;
break;
case LOOK_MODE_JOYSTICK:
look_pitch_joy = pitch;
break;
}
}
//left right
int look_yaw_mode;
float look_yaw_mouse,look_yaw_joy;
void PortableLookYaw(int mode, float yaw)
{
look_yaw_mode = mode;
switch(mode)
{
case LOOK_MODE_MOUSE:
look_yaw_mouse += yaw;
break;
case LOOK_MODE_JOYSTICK:
look_yaw_joy = yaw;
break;
}
}
void PortableCommand(const char * cmd){}
extern int32_t main(int32_t argc, char *argv[]);
void PortableInit(int argc,const char ** argv){
main(argc,argv);
}
void PortableFrame(){
//NOT USED for DUKE
}
int PortableInMenu(){
return ( (g_player[myconnectindex].ps->gm & MODE_MENU) || !(g_player[myconnectindex].ps->gm & MODE_GAME))?1:0;
}
unsigned int PortableGetWeapons()
{
return g_player[myconnectindex].ps->gotweapon;
}
int PortableInAutomap()
{
return 0;
}
int PortableShowKeyboard(){
return 0;
}
int PortableIsSoftwareMode()
{
if (getrendermode() >= REND_POLYMOST)
return 0;
else
return 1;
}
static int lastWeapon = -1;
int getLastWeapon(){
return lastWeapon;
}
extern user_defs ud;
int isPaused()
{
return ud.pause_on;
}
///This stuff is called from the game/engine
void setLastWeapon(int w)
{
LOGI("setLastWeapon %d",w);
lastWeapon = w;
}
void CONTROL_Android_ClearButton(int32_t whichbutton)
{
BUTTONCLEAR(whichbutton);
functionHeld &= ~((uint64_t)1<<((uint64_t)(whichbutton)));
}
void CONTROL_Android_PollDevices(ControlInfo *info)
{
//LOGI("CONTROL_Android_PollDevices %f %f",forwardmove,sidemove);
info->dz = -forwardmove * 5000;
info->dx = sidemove * 200;
switch(look_pitch_mode)
{
case LOOK_MODE_MOUSE:
info->dpitch = look_pitch_mouse * 100000;
look_pitch_mouse = 0;
break;
case LOOK_MODE_ABSOLUTE:
//cl.viewangles[0] = look_pitch_abs * 80;
break;
case LOOK_MODE_JOYSTICK:
info->dpitch = look_pitch_joy * 2000;
break;
}
switch(look_yaw_mode)
{
case LOOK_MODE_MOUSE:
info->dyaw = -look_yaw_mouse * 80000;
look_yaw_mouse = 0;
break;
case LOOK_MODE_JOYSTICK:
info->dyaw = -look_yaw_joy * 4000;
break;
}
CONTROL_ButtonState = 0;
CONTROL_ButtonState |= functionSticky;
CONTROL_ButtonState |= functionHeld;
functionSticky = 0;
//LOGI("poll state = 0x%016llX",CONTROL_ButtonState);
}

View file

@ -0,0 +1,46 @@
#include "function.h"
#define LOOK_MODE_MOUSE 0
#define LOOK_MODE_ABSOLUTE 1
#define LOOK_MODE_JOYSTICK 2
#ifdef __cplusplus
extern "C"
{
#endif
int PortableKeyEvent(int state, int code, int unicode);
void PortableAction(int state, int action);
void PortableMove(float fwd, float strafe);
void PortableMoveFwd(float fwd);
void PortableMoveSide(float strafe);
void PortableLookPitch(int mode, float pitch);
void PortableLookYaw(int mode, float pitch);
void PortableCommand(const char * cmd);
void PortableInit(int argc,const char ** argv);
void PortableFrame();
int PortableInMenu();
int PortableShowKeyboard();
int PortableInAutomap();
unsigned int PortableGetWeapons();
int getLastWeapon();
int isPaused();
//check mode, so touch graphcics can adapt
int PortableIsSoftwareMode();
#ifdef __cplusplus
}
#endif

View file

@ -174,9 +174,16 @@ void CONFIG_SetDefaults(void)
int32_t i;
ud.config.scripthandle = -1;
#ifdef __ANDROID__
ud.config.ScreenWidth = android_screen_width;
ud.config.ScreenHeight = android_screen_height;
#else
ud.config.ScreenWidth = 1024;
ud.config.ScreenHeight = 768;
#endif
ud.config.ScreenMode = 0;
#ifdef USE_OPENGL
ud.config.ScreenBPP = 32;
#else

View file

@ -18,6 +18,10 @@
#include "osd.h"
#include "pragmas.h"
#ifdef __ANDROID__
#include "android.h"
#endif
int32_t CONTROL_JoyPresent = FALSE;
int32_t CONTROL_JoystickEnabled = FALSE;
int32_t CONTROL_MousePresent = FALSE;
@ -606,6 +610,10 @@ static void CONTROL_PollDevices(ControlInfo *info)
{
memset(info, 0, sizeof(ControlInfo));
#ifdef __ANDROID__
CONTROL_Android_PollDevices(info);
#endif
if (CONTROL_MouseEnabled)
{
int32_t i = MAXMOUSEAXES-1;

View file

@ -3241,6 +3241,10 @@ static void P_ChangeWeapon(DukePlayer_t *p, int32_t weapon)
if (p->holster_weapon)
{
#ifdef __ANDROID__
setLastWeapon(p->last_weapon);
#endif
p->weapon_pos = WEAPON_POS_RAISE;
p->holster_weapon = 0;
p->last_weapon = -1;

View file

@ -56,7 +56,13 @@ static char **external_midi_argv;
static pid_t external_midi_pid=-1;
static int8_t external_midi_restart=0;
#endif
#ifdef __ANDROID__ //TODO fix
static char *external_midi_tempfn = "/sdcard/eduke32-music.mid";
#else
static char *external_midi_tempfn = "/tmp/eduke32-music.mid";
#endif
static int32_t external_midi = 0;
int32_t MUSIC_ErrorCode = MUSIC_Ok;