This commit is contained in:
Vladislav Khorev 2013-02-10 12:47:51 +00:00
parent 287ab26da1
commit b3eb112ae3
7 changed files with 44 additions and 86 deletions

View File

@ -1,11 +1,9 @@
#include "android_api.h" #include "android_api.h"
#include "main_code.h" #include "main_code.h"
#include "boost\thread.hpp" #include "boost/thread.hpp"
std::shared_ptr<TAndroidApplication> App(new TAndroidApplication); TAndroidApplication* Application = NULL;
boost::mutex RenderMutex;
float lastOffsetX = 0.5f; float lastOffsetX = 0.5f;
@ -16,13 +14,17 @@ bool RedBkgPref = false;
JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height) JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height)
{ {
Application = JniInitApp<TAndroidApplication>(width, height, 800.f, 480.f);
boost::get<TPanoramicCamera>(Renderer->Camera).SetAlpha((lastOffsetX) * pi / 180.f);
/*
RenderMutex.lock(); RenderMutex.lock();
try try
{ {
if (App->IsInited()) if (Application->IsInited())
{ {
App->OuterDeinit(); //Clean up what is left at previous launch (if applicable) App->OuterDeinit(); //Clean up what is left at previous launch (if applicable)
} }
@ -48,57 +50,11 @@ JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_Init(JNIEn
throw; throw;
} }
RenderMutex.unlock(); RenderMutex.unlock();*/
} }
JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_Update(JNIEnv * env, jobject obj, long dt)
{
RenderMutex.unlock();
try
{
if (App->IsInited())
{
App->OuterDraw();
App->OuterUpdate(dt);
if (OffsetChanged)
{
Renderer->SetAlpha((lastOffsetX) * pi / 180.f);
}
}
}
catch (...)
{
throw;
}
RenderMutex.unlock();
}
JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_OnTapMove(JNIEnv * env, jobject obj, jfloat x, jfloat y)
{
try
{
if (App->IsInited())
{
vec2 offset = vec2(x*Renderer->GetMatrixWidth()/static_cast<float>(App->Width), y*Renderer->GetMatrixHeight()/static_cast<float>(App->Height));
App->OuterOnMove(offset);
}
}
catch (...)
{
throw;
}
}
JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_SetOffset(JNIEnv * env, jobject obj, jfloat offsetX, jfloat offsetY) JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_SetOffset(JNIEnv * env, jobject obj, jfloat offsetX, jfloat offsetY)
{ {
@ -109,10 +65,6 @@ JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_SetOffset(
} }
} }
JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_SetOrientation(JNIEnv * env, jobject obj, int isLandscape)
{
}
JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_SetRedBkgPref(JNIEnv * env, jobject obj, jboolean r) JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_SetRedBkgPref(JNIEnv * env, jobject obj, jboolean r)
{ {
RedBkgPref = r; RedBkgPref = r;

View File

@ -16,14 +16,8 @@ extern "C" {
JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height); JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height);
JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_Update(JNIEnv * env, jobject obj, long dt);
JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_OnTapMove(JNIEnv * env, jobject obj, jfloat x, jfloat y);
JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_SetOffset(JNIEnv * env, jobject obj, jfloat offsetX, jfloat offsetY); JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_SetOffset(JNIEnv * env, jobject obj, jfloat offsetX, jfloat offsetY);
JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_SetOrientation(JNIEnv * env, jobject obj, int isLandscape);
JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_SetRedBkgPref(JNIEnv * env, jobject obj, jboolean r); JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_SetRedBkgPref(JNIEnv * env, jobject obj, jboolean r);
}; };

View File

@ -108,7 +108,7 @@ void TAndroidApplication::InnerInit()
CheckGlError(); CheckGlError();
Renderer->MovePhi(pi/32); boost::get<TPanoramicCamera>(Renderer->Camera).MovePhi(pi/32);
//ResourceManager->ModelManager.AddLiteModel("bt_box_yellow.lm1"); //ResourceManager->ModelManager.AddLiteModel("bt_box_yellow.lm1");
@ -119,19 +119,21 @@ void TAndroidApplication::InnerInit()
LoadModels(); LoadModels();
if (Width > Height) if (Renderer->GetScreenWidth() > Renderer->GetScreenHeight())
{ {
Renderer->MoveDist(30.f); boost::get<TPanoramicCamera>(Renderer->Camera).MoveDist(30.f);
} }
else else
{ {
Renderer->MoveDist(45.f); boost::get<TPanoramicCamera>(Renderer->Camera).MoveDist(45.f);
} }
CheckGlError(); CheckGlError();
Renderer->SetPerspectiveFullScreenViewport(); glViewport(0, 0, Renderer->GetScreenWidth(), Renderer->GetScreenHeight());
Renderer->SetPerspectiveProjection(pi / 6.f, 1.0f, 100.0f);
*Console<<"Inner init end!\n"; *Console<<"Inner init end!\n";
@ -174,7 +176,7 @@ void TAndroidApplication::InnerUpdate(cardinal dt)
void TAndroidApplication::InnerOnMove(vec2 shift) void TAndroidApplication::InnerOnMove(vec2 shift)
{ {
Renderer->MoveAlpha(-pi*shift.v[0]*0.1f); boost::get<TPanoramicCamera>(Renderer->Camera).MoveAlpha(-pi*shift.v[0]*0.1f);
} }
void TAndroidApplication::OnMouseDown(TMouseState& mouseState) void TAndroidApplication::OnMouseDown(TMouseState& mouseState)

View File

@ -18,6 +18,9 @@ import android.service.wallpaper.WallpaperService;
import android.util.Log; import android.util.Log;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import fishrungames.engine.EngineWrapper;
public class GLWallpaperService extends WallpaperService { public class GLWallpaperService extends WallpaperService {
private static final String TAG = "GLWallpaperService"; private static final String TAG = "GLWallpaperService";
@ -654,7 +657,7 @@ class GLThread extends Thread {
long currentTimeStamp = c.getTimeInMillis(); long currentTimeStamp = c.getTimeInMillis();
JniWrapper.Update(currentTimeStamp - lastTimeStamp); EngineWrapper.Update(currentTimeStamp - lastTimeStamp);
lastTimeStamp = currentTimeStamp; lastTimeStamp = currentTimeStamp;

View File

@ -18,12 +18,6 @@ public class JniWrapper
public static native void Init(int width, int height); public static native void Init(int width, int height);
public static native void Update(long dt);
public static native void OnTapMove(float x, float y);
public static native void SetOffset(float offsetX, float offsetY); public static native void SetOffset(float offsetX, float offsetY);
public static native void SetOrientation(int isLandscape);
} }

View File

@ -19,7 +19,7 @@ import android.view.SurfaceHolder;
//import com.seb.SLWP.SLWP.GlEngine.DownloadTask; //import com.seb.SLWP.SLWP.GlEngine.DownloadTask;
import fishrungames.engine.FileWrapper; import fishrungames.engine.EngineWrapper;
public class MainWallpaperService extends GLWallpaperService implements public class MainWallpaperService extends GLWallpaperService implements
OnSharedPreferenceChangeListener { OnSharedPreferenceChangeListener {
@ -30,7 +30,7 @@ public class MainWallpaperService extends GLWallpaperService implements
*/ */
static static
{ {
FileWrapper.LoadSalmonEngineLibrary(); EngineWrapper.LoadSalmonEngineLibrary();
JniWrapper.LoadLibrary(); JniWrapper.LoadLibrary();
} }
@ -81,8 +81,8 @@ public class MainWallpaperService extends GLWallpaperService implements
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
FileWrapper.SetActivityInstance(this); EngineWrapper.SetActivityInstance(this);
FileWrapper.SetupEnviroment(); EngineWrapper.SetupEnviroment();
String apkFilePath = null; String apkFilePath = null;
ApplicationInfo appInfo = null; ApplicationInfo appInfo = null;
@ -98,7 +98,7 @@ public class MainWallpaperService extends GLWallpaperService implements
} }
apkFilePath = appInfo.sourceDir; apkFilePath = appInfo.sourceDir;
FileWrapper.SetupApkFilePath(apkFilePath); EngineWrapper.SetupApkFilePath(apkFilePath);
Init(); Init();
} }

View File

@ -4,12 +4,25 @@
int APIENTRY WinMain(HINSTANCE hCurrentInst, HINSTANCE hPreviousInst, int APIENTRY WinMain(HINSTANCE hCurrentInst, HINSTANCE hPreviousInst,
LPSTR lpszCmdLine, int nCmdShow) LPSTR lpszCmdLine, int nCmdShow)
{ {
//Create application int width = 800;
TAndroidApplication Application; int height = 480;
Application.Width = 800; if (CreateEngine(width, height))
Application.Height = 480; {
//Start application //MyApplication scope
return MainLoop(Application); {
TAndroidApplication Application;
Application.OuterInit(width, height, width, height);
MainLoop(&Application);
Application.OuterDeinit();
}
DestroyEngine();
}
return 0;
} }