First blood

This commit is contained in:
vladislav.khorev committed 2013-01-19 20:02:34 +00:00
1 parent 04f270f322
commit 5720f8322b
250 files changed
+33215

No files matched your search

@@ -0,0 +1,77 @@
# 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.org/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.
#
LPATH := $(call my-dir)
ENGINE_PATH = $(SalmonEnginePathCygwin)
BOOST_PATH = $(LibsPathCygwin)/boost_1_47_0
OGG_PATH = $(LibsPathCygwin)/libogg-1.3.0
VORBIS_PATH = $(LibsPathCygwin)/libvorbis-1.3.2
SQUIRREL_PATH = $(LibsPathCygwin)/sqplus
LIBPNG_PATH = $(LibsPathCygwin)/libpng_1.4.1_android
ZIP_PATH = $(LibsPathCygwin)/julienr-libzip-android/jni
#====== ENGINE AND LIBS =====================
include $(ENGINE_PATH)/Android_Salmon_Engine.mk
#================= THE GAME =======================
LOCAL_PATH:= $(LPATH)
include $(CLEAR_VARS)
LOCAL_CFLAGS := -DTARGET_ANDROID -DNOSOUND -DTARGET_SALMON -std=gnu++11 --std=c++11
LOCAL_STATIC_LIBRARIES := boost
LOCAL_STATIC_LIBRARIES += squirrel
LOCAL_STATIC_LIBRARIES += png_lib
LOCAL_STATIC_LIBRARIES += zip
LOCAL_SHARED_LIBRARIES := SalmonEngine
LOCAL_SHARED_LIBRARIES += gnustl_shared
LOCAL_C_INCLUDES := $(ENGINE_PATH)
LOCAL_C_INCLUDES += $(BOOST_PATH)
LOCAL_C_INCLUDES += $(VORBIS_PATH)/include
LOCAL_C_INCLUDES += $(VORBIS_PATH)/include/vorbis
LOCAL_C_INCLUDES += $(VORBIS_PATH)/lib
LOCAL_C_INCLUDES += $(VORBIS_PATH)/lib/books
LOCAL_C_INCLUDES += $(VORBIS_PATH)/lib/modes
LOCAL_C_INCLUDES += $(OGG_PATH)/include
LOCAL_C_INCLUDES += $(OGG_PATH)/include/ogg
LOCAL_C_INCLUDES += $(SQUIRREL_PATH)/include
LOCAL_C_INCLUDES += $(SQUIRREL_PATH)/sqplus
LOCAL_C_INCLUDES += $(SQUIRREL_PATH)/squirrel
LOCAL_C_INCLUDES += $(SQUIRREL_PATH)/sqstdlib
LOCAL_C_INCLUDES += $(LIBPNG_PATH)
LOCAL_C_INCLUDES += $(ZIP_PATH)
LOCAL_MODULE := SalmonWallpaper
LOCAL_SRC_FILES := main_code.cpp
LOCAL_SRC_FILES += android_api.cpp
LOCAL_LDLIBS := -lGLESv2
LOCAL_LDLIBS += -llog -Wl
#debug
#LOCAL_CFLAGS += -g -ggdb -O0
#LOCAL_LDLIBS += -g -ggdb
include $(BUILD_SHARED_LIBRARY)
@@ -0,0 +1,3 @@
APP_STL := gnustl_shared
APP_CPPFLAGS += -fexceptions
APP_CPPFLAGS += -frtti
@@ -0,0 +1,119 @@
#include "android_api.h"
#include "main_code.h"
#include "boost\thread.hpp"
std::shared_ptr<TAndroidApplication> App(new TAndroidApplication);
boost::mutex RenderMutex;
float lastOffsetX = 0.5f;
bool OffsetChanged = false;
bool RedBkgPref = false;
JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height)
{
RenderMutex.lock();
try
{
if (App->IsInited())
{
App->OuterDeinit(); //Clean up what is left at previous launch (if applicable)
}
App->Width = width;
App->Height = height;
if (width > height)
{
App->OuterInit(width, height, 800.f, 480.f);
}
else
{
App->OuterInit(width, height, 480.f, 800.f);
}
Renderer->SetAlpha((lastOffsetX) * pi / 180.f);
App->Inited = true;
}
catch (...)
{
throw;
}
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)
{
if (Renderer != NULL)
{
OffsetChanged = true;
lastOffsetX = offsetX;
}
}
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)
{
RedBkgPref = r;
}
@@ -0,0 +1,31 @@
#ifndef ANDROID_API_H_INCLUDED
#define ANDROID_API_H_INCLUDED
#include <jni.h>
#include <android/log.h>
#include <GLES/gl.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include "boost/shared_ptr.hpp"
#include "main_code.h"
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_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_SetOrientation(JNIEnv * env, jobject obj, int isLandscape);
JNIEXPORT void JNICALL Java_fishrungames_wallpapertemplate_JniWrapper_SetRedBkgPref(JNIEnv * env, jobject obj, jboolean r);
};
#endif
@@ -0,0 +1,183 @@
#include "main_code.h"
#ifdef TARGET_ANDROID
#include "android_api.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "include/Engine.h"
#include "main_code.h"
extern float lastOffsetX;
#ifdef TARGET_WIN32
bool RedBkgPref = true;
#else
extern bool RedBkgPref;
#endif
TAndroidApplication::TAndroidApplication()
: TApplication()
, Inited(false)
//, LiteModel(NULL)
{
}
void TAndroidApplication::LoadModels()
{
mat3 m(vec4(0,1*sin(pi/8 + pi/2),0,1*cos(pi/8 + pi/2)));
/*
LiteModel = new TLiteModel;
LiteModel->LoadModel("bt_box_yellow.lm1");
LiteModel->ScaleModel(10.0f);
LiteModel->RotateModel(m);
LiteModel->UpdateVBO();*/
FlexModel = ResourceManager->FlexModelManager.InstanciateModel("model.xml");
//FlexModel.MoveModel(vec3(1, -4, -4));
FlexModel.ScaleModel(1.5f);
FlexModel.RotateModel(m);
FlexModel.RefreshBuffer();
}
void TAndroidApplication::DrawAllScene()
{
glClearColor(0.f, 0.f, 0.f, 1.0f);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
Renderer->PushProjectionMatrix(1,1);
Renderer->LoadIdentity();
if (RedBkgPref)
{
glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["bkg_red.png"]);
}
else
{
glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["bkg_blue.png"]);
}
Renderer->DrawRect(vec2(0.0f, 0.f), vec2(1.f, 1.f), vec2(0.f, 0.f), vec2(1.f, 1.f));
Renderer->PopProjectionMatrix();
glClear(GL_DEPTH_BUFFER_BIT);
Renderer->SetGLCamView();
//LiteModel->DrawVBO();
FlexModel.Draw();
}
void TAndroidApplication::InnerInit()
{
RenderMutex.lock();
CheckGlError();
glEnable(GL_BLEND);
*Console<<"Inner init go!\n";
#ifdef TARGET_ANDROID
ResourceManager->PathToResources = "";
#endif
#ifdef TARGET_WIN32
ResourceManager->PathToResources = "../../assets/";
#endif
ResourceManager->ShaderManager.AddShader("DefaultShader", "gui_transparent.vertex", "gui_transparent.fragment");
Renderer->PushShader("DefaultShader");
ResourceManager->TexList.AddTexture("bkg_red.png");
ResourceManager->TexList.AddTexture("bkg_blue.png");
CheckGlError();
Renderer->MovePhi(pi/32);
//ResourceManager->ModelManager.AddLiteModel("bt_box_yellow.lm1");
ResourceManager->TexList.AddTexture("bt_box_yellow.bmp");
ResourceManager->FlexModelManager.LoadModelFromXml("model.xml");
LoadModels();
if (Width > Height)
{
Renderer->MoveDist(30.f);
}
else
{
Renderer->MoveDist(45.f);
}
CheckGlError();
Renderer->SetPerspectiveFullScreenViewport();
*Console<<"Inner init end!\n";
RenderMutex.unlock();
}
void TAndroidApplication::InnerDeinit()
{
RenderMutex.lock();
Inited = false;
/*
if (LiteModel != NULL)
{
LiteModel->FreeModel();
delete LiteModel;
LiteModel = NULL;
}*/
RenderMutex.unlock();
}
void TAndroidApplication::InnerDraw()
{
RenderMutex.lock();
DrawAllScene();
RenderMutex.unlock();
}
void TAndroidApplication::InnerUpdate(cardinal dt)
{
}
void TAndroidApplication::InnerOnMove(vec2 shift)
{
Renderer->MoveAlpha(-pi*shift.v[0]*0.1f);
}
void TAndroidApplication::OnMouseDown(TMouseState& mouseState)
{
}
@@ -0,0 +1,67 @@
#ifndef GL_CODE_H_INCLUDED
#define GL_CODE_H_INCLUDED
#ifdef TARGET_ANDROID
//#include "android_api.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#ifdef TARGET_ANDROID
#include <GLES/gl.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#endif
#include "boost/shared_ptr.hpp"
#include "boost/thread/thread.hpp"
#include "boost/asio.hpp"
#include "boost/signal.hpp"
#include "boost/assign.hpp"
#include "boost/variant.hpp"
#include "boost/function.hpp"
#include "boost/bind.hpp"
#include "include/Engine.h"
using namespace SE;
class TAndroidApplication : public TApplication
{
protected:
void LoadModels();
public:
bool Inited;
boost::mutex RenderMutex;
//TLiteModel* LiteModel;
TFlexModel FlexModel;
TAndroidApplication();
virtual void InnerInit();
virtual void InnerDeinit();
virtual void InnerDraw();
virtual void InnerUpdate(cardinal dt);
virtual void InnerOnMove(vec2 shift);
virtual void OnMouseDown(TMouseState& mouseState);
bool IsInited() { return Inited; }
void DrawAllScene();
};
#endif