crystal-of-rhylil/jni/main_code.cpp

209 lines
6.1 KiB
C++

#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"
#ifndef TARGET_IOS
boost::shared_ptr<TMyApplication> App(new TMyApplication);
#endif
bool animPaused = false;
struct TOnClickTest
{
void operator()()
{
//ResourceManager->ScriptManager.RunScript("5+5;");
if (animPaused)
{
//animPaused = false;
//ResourceManager->HalibutAnimationManager.StartAnimation("test_anim");
//ResourceManager->HalibutAnimationManager.ShowAnimation("test_anim");
//ResourceManager->SoundManager.PlayMusic("finalogg.ogg");
//App->Match3Controller.Match3Field->StartAnimateChip(4,1);
//App->Match3Controller.Match3Field->HighlightMatch3();
}
else
{
//animPaused = true;
//ResourceManager->HalibutAnimationManager.StopAnimation("test_anim");
//ResourceManager->HalibutAnimationManager.HideAnimation("test_anim");
//ResourceManager->SoundManager.StopMusic("finalogg.ogg");
//App->Match3Controller.Match3Field->StopAnimateChip(4,1);
//App->Match3Controller.Match3Field->HighlightMatch3();
}
}
};
//What to do on init
void TMyApplication::InnerInit()
{
#ifdef TARGET_ANDROID
SE::ST::PathToResources = "";
#endif
#ifdef TARGET_WIN32
#ifdef DEBUG
SE::ST::PathToResources = "../../assets/";
#else
SE::ST::PathToResources = "res/";
#endif
#endif
#ifdef TARGET_IOS
SE::ST::PathToResources = "assets/";
#endif
if (SE::Console != nullptr) {
*SE::Console << "APP INIT\n";
}
SE::ResourceManager->ShaderManager.AddShader("DefaultShader", "shader1vertex.txt", "shader1fragment.txt");
SE::ResourceManager->ShaderManager.AddShader("FrameShader", "frameshader_vertex.txt", "frameshader_fragment.txt");
SE::ResourceManager->ShaderManager.AddShader("BrickShader", "brickshader_vertex.txt", "brickshader_fragment.txt");
SE::Renderer->PushShader("DefaultShader");
const std::string CONST_LOADING_BACKGROUND_BLACK = "loading_background_black";
const std::string CONST_LOADING_TEXTURE = "loading";
const std::string CONST_LOGO_SMALL_TEXTURE = "logo_small";
SE::ResourceManager->TexList.AddTexture(CONST_LOADING_BACKGROUND_BLACK + ".png", CONST_LOADING_BACKGROUND_BLACK);
SE::ResourceManager->TexList.AddTexture(CONST_LOADING_TEXTURE + ".png", CONST_LOADING_TEXTURE);
SE::ResourceManager->TexList.AddTexture(CONST_LOGO_SMALL_TEXTURE + ".png", CONST_LOGO_SMALL_TEXTURE);
SE::ResourceManager->TexList.AddTexture("console_bkg.bmp");
SE::ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 512, 512);
Inited = true;
SE::Renderer->SetOrthoProjection();
SE::Renderer->SetFullScreenViewport();
auto px = SE::FileToPropertyTree("shaders.xml");
SE::ResourceManager->ShaderManager.Serialize(*px);
px = SE::FileToPropertyTree("textures.xml");
SE::ResourceManager->TexList.Serialize(*px);
//this cause exception
//px = SE::FileToPropertyTree("fonts.xml");
//SE::ResourceManager->FontManager.Serialize(*px);
//SE::ResourceManager->FontManager.PushFont("droid_sans14");
Match3Controller.Match3Field = std::make_shared<TMatch3Field>(Match3Controller);
/*
ResourceManager->GUIManager.AddWidgetAndFill(boost::shared_ptr<TInstancingWidgetAncestor>(new TSquareButton),
"ololo", "group1",
boost::shared_ptr<TTriangleListFillerAncestor>(new TSquareButtonTriangleListFiller(vec2(100, 100), vec2(200, 200), "button_normal", "button_pressed")));
ResourceManager->GUIManager.AddWidgetAndFill(boost::shared_ptr<TInstancingWidgetAncestor>(new TSquareStatic),
"Background", "group1",
boost::shared_ptr<TSquareStaticTriangleListFiller>(new TSquareStaticTriangleListFiller(vec2(0, 0), vec2(800, 480), "cave_hd")));
ResourceManager->GUIManager.AddWidget(boost::shared_ptr<TInstancingWidgetAncestor>(new TMatch3Field(Match3Controller)),
"match3", "group1");
ResourceManager->GUIManager.MoveWidget("ololo", vec2(-100, 0));
TOnClickTest OnClickTest;
*/
//ResourceManager->GUIManager.GetOnClickSignal("ololo").connect(OnClickTest);
//testAnimObject.Serialize(FileToPropertyTree("test_animation_xml.xml"));
//ResourceManager->HalibutAnimationManager.AddAnimationObject("test_anim", testAnimObject);
//ResourceManager->HalibutAnimationManager.StartAnimation("test_anim");
//ResourceManager->ShaderManager.AddShader("DefaultShader", "shader_vertex.txt", "shader_fragment.txt");
/*HalibutRender->PushShader("DefaultShader");
ResourceManager->TexList.AddTexture(CONST_CONSOLE_TEX_NAME);
ResourceManager->FontManager.AddFont("droid_sans14", "droid_sans14_font_bitmap.bmp32", "droid_sans14_font_charmap.txt");
ResourceManager->FontManager.PushFont("droid_sans14");*/
//glDisable(GL_CULL_FACE);
}
//What to do on deinit
void TMyApplication::InnerDeinit()
{
Inited = false;
}
//What to do on draw
void TMyApplication::InnerDraw()
{
auto &list = Match3Controller.Match3Field.get()->TriangleListVector;
for (auto j = list.begin(); j != list.end(); ++j)
{
SE::TRenderParamsSetter paramSetter(j->first);
SE::Renderer->DrawTriangleList(j->second);
SE::CheckGlError("TMyApplication::InnerDraw()");
}
}
//What to do on update. timer means how many ms passed since last update
void TMyApplication::InnerUpdate(size_t timer)
{
Match3Controller.Match3Field.get()->Update(timer);
}
void TMyApplication::InnerOnTapDown(Eigen::Vector2f p) {
if (!Match3Controller.Match3Field.get()->CheckClick(p)) {
return;
}
Match3Controller.Match3Field.get()->OnTapDown(p);
}
void TMyApplication::InnerOnTapUp(Eigen::Vector2f p) {
if (!Match3Controller.Match3Field.get()->CheckClick(p)) {
return;
}
Match3Controller.Match3Field.get()->OnTapUp(p);
}
void TMyApplication::InnerOnTapUpAfterMove(Eigen::Vector2f p) {
//Match3Controller.Match3Field.get()->
}
void TMyApplication::InnerOnMove(Eigen::Vector2f pos, Eigen::Vector2f shift) {
if (!Match3Controller.Match3Field.get()->CheckClick(pos)) {
return;
}
Match3Controller.Match3Field.get()->OnMove(pos);
}