From 55b042a9797382dbfda4252352b8def0a7729629 Mon Sep 17 00:00:00 2001 From: Emil Kabirov Date: Mon, 15 Oct 2018 17:29:14 +0500 Subject: [PATCH 1/2] working on opengl resources reinitialization --- game/gamecode.cpp | 3 + game/main_code.cpp | 162 ++++++++++-------- game/main_code.h | 10 +- .../doublehitballs/GL2JNIActivity.java | 2 +- 4 files changed, 100 insertions(+), 77 deletions(-) diff --git a/game/gamecode.cpp b/game/gamecode.cpp index b72f785..48102fb 100755 --- a/game/gamecode.cpp +++ b/game/gamecode.cpp @@ -918,6 +918,9 @@ void TGameLevel::InnerDraw(int screenWidth, int screenHeight, int matrixWidth, i } // ::::::::::: + *SE::Console << BkgTexture; + *SE::Console << std::to_string(ResourceManager->TexList[BkgTexture]); + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[BkgTexture]); //Renderer->DrawRect(Vector2f(xlOffset, ylOffset), Vector2f(xlOffset+tSW, ylOffset+tSH),Vector2f(0.f, 0.f), Vector2f(1.f, 1.f)); Renderer->DrawRect(Vector2f(bkgSWO, bkgSHO), Vector2f(bkgSWO + bkgSW, bkgSHO + bkgSH), Vector2f(0.f, 0.f), Vector2f(1.f, 1.f)); diff --git a/game/main_code.cpp b/game/main_code.cpp index fb33341..a580108 100755 --- a/game/main_code.cpp +++ b/game/main_code.cpp @@ -152,8 +152,6 @@ void TMyApplication::InnerInit() ST::PathToResources = ""; #endif - LoadUserProgress(); - if (Console != NULL) { *Console<<"APP INIT\n"; @@ -162,59 +160,62 @@ void TMyApplication::InnerInit() GameState = CONST_GAMESTATE_PRELOADING; StateTimer = 0.f; - /* - ResourceManager->ShaderManager.AddShader("DefaultShader", "shader1vertex", "shader1fragment.txt"); - ResourceManager->ShaderManager.AddShader("FrameShader", "frameshader_vertex.txt", "frameshader_fragment.txt"); - ResourceManager->ShaderManager.AddShader("BrickShader", "brickshader_vertex.txt", "brickshader_fragment.txt"); - Renderer->PushShader("DefaultShader"); - */ - - //ResourceManager->ShaderManager.AddShader("DefaultShader", "shaders/texture-shader.vertex", "shaders/texture-shader.fragment"); ResourceManager->ShaderManager.AddShader("DefaultShader", "shaders/gui_transparent.vertex", "shaders/gui_transparent.fragment"); - ResourceManager->ShaderManager.AddShader("HoverableButtonShader", "shaders/gui_transparent.vertex", "shaders/hoverable-button.fragment"); - ResourceManager->ShaderManager.AddShader("BlackAndWhiteShader", "shaders/gui_transparent_blackandwhite.vertex", "shaders/gui_transparent_blackandwhite.fragment"); - ResourceManager->ShaderManager.AddShader("ColorShader", "shaders/color-shader.vertex", "shaders/color-shader.fragment"); - ResourceManager->ShaderManager.AddShader("FrameShader", "shaders/frameshader_vertex.txt", "shaders/frameshader_fragment.txt"); - ResourceManager->ShaderManager.AddShader("BrickShader", "shaders/brickshader_vertex.txt", "shaders/brickshader_fragment.txt"); - ResourceManager->ShaderManager.AddShader(ParticleEffect::PARTICLE_SHADER, "shaders/particle-shader.vertex", "shaders/particle-shader.fragment"); - Renderer->PushShader("DefaultShader"); + Renderer->PushShader("DefaultShader"); - //ResourceManager->TexList.AddTexture(CONST_LOADING_BACKGROUND_BLACK + ".png", CONST_LOADING_BACKGROUND_BLACK); - //ResourceManager->TexList.AddTexture(CONST_LOADING_TEXTURE + ".png", CONST_LOADING_TEXTURE); - //ResourceManager->TexList.AddTexture(CONST_LOGO_SMALL_TEXTURE + ".png", CONST_LOGO_SMALL_TEXTURE); + ResourceManager->TexList.AddTexture("console_bkg.bmp"); + ResourceManager->TexList.AddTexture("white.bmp"); - ResourceManager->TexList.AddTexture("console_bkg.bmp"); - ResourceManager->TexList.AddTexture("white.bmp"); + ResourceManager->FontManager.AddFont("arial32", "arial32.png", "arial32.txt"); + ResourceManager->FontManager.AddFont("lucon12", "lucon12.png", "lucon12.txt"); + ResourceManager->FontManager.PushFont("lucon12"); + Renderer->SetOrthoProjection(); - ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 256, 256); - - //OnDrawSignal.connect(boost::bind(&TGameLoading::Draw, boost::ref(GameLoading))); - Inited = true; + Renderer->SetFullScreenViewport(); - Renderer->SetOrthoProjection(); + ResourceManager->newGuiManager.LoadFromConfig("gui_loading.json"); - Renderer->SetFullScreenViewport(); - Application->SetGameLevelScreenScale(); - //GameLevel.SetLevelScale(); - EffectsInit(); - - // ------- UI ------- - ResourceManager->FontManager.AddFont("arial32", "arial32.png", "arial32.txt"); - ResourceManager->FontManager.AddFont("lucon12", "lucon12.png", "lucon12.txt"); - ResourceManager->FontManager.PushFont("lucon12"); - //ResourceManager->newGuiManager.LoadFromConfig("gui_main_menu.json"); - ResourceManager->newGuiManager.LoadFromConfig("gui_loading.json"); + skipUpdateToUpdateScreen = true; + StateTimer = 0.f; +} - // ------- UI ------- +void TMyApplication::InnerReinitGLResources() +{ + RenderLevelSnapshots(); - // TESTS of menu - if (Menu.GalaxMenu.InitGalaxyMenu("levels/galaxy_ptree.json")) { - std::cout << "ok" << std::endl; - } - else { - std::cout << "menu error" << std::endl; - } + lsparkler.reinitGlResources(); + rsparkler.reinitGlResources(); + tsparkler.reinitGlResources(); + bsparkler.reinitGlResources(); + lvlFirework.reinitGlResources(); +} + +void TMyApplication::RenderLevelSnapshots() +{ + Renderer->SwitchToFrameBuffer("LevelBuffer"); + + Renderer->SetProjectionMatrix(768, 480); + + Renderer->LoadIdentity(); + + for (auto &star : Menu.GalaxMenu.galaxies[0].Stars) + { + for (auto level : star.selectionMenu.gameLevels) + { + level->DrawSnapshot("LevelBuffer", false); + + Renderer->PushShader("BlackAndWhiteShader"); + + level->DrawSnapshot("LevelBuffer", true); + + Renderer->PopShader(); + } + } + + Renderer->SwitchToScreen(); + + Renderer->SetOrthoProjection(); } void TMyApplication::InnerDeinit() @@ -494,10 +495,48 @@ void TMyApplication::InnerUpdate(size_t dt) StateTimer += dt/1000.f; if (StateTimer >= 1.f) { - LoadResources(); - GameState = CONST_GAMESTATE_LOADING; - StateTimer = 0.f; + StateTimer -= 1.f; + skipUpdateToUpdateScreen = false; } + + if (skipUpdateToUpdateScreen) + { + return; + } + + LoadUserProgress(); + + ResourceManager->ShaderManager.AddShader("HoverableButtonShader", "shaders/gui_transparent.vertex", "shaders/hoverable-button.fragment"); + ResourceManager->ShaderManager.AddShader("BlackAndWhiteShader", "shaders/gui_transparent_blackandwhite.vertex", "shaders/gui_transparent_blackandwhite.fragment"); + ResourceManager->ShaderManager.AddShader("ColorShader", "shaders/color-shader.vertex", "shaders/color-shader.fragment"); + ResourceManager->ShaderManager.AddShader("FrameShader", "shaders/frameshader_vertex.txt", "shaders/frameshader_fragment.txt"); + ResourceManager->ShaderManager.AddShader("BrickShader", "shaders/brickshader_vertex.txt", "shaders/brickshader_fragment.txt"); + ResourceManager->ShaderManager.AddShader(ParticleEffect::PARTICLE_SHADER, "shaders/particle-shader.vertex", "shaders/particle-shader.fragment"); + + + ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 256, 256); + + + //OnDrawSignal.connect(boost::bind(&TGameLoading::Draw, boost::ref(GameLoading))); + Inited = true; + Application->SetGameLevelScreenScale(); + //GameLevel.SetLevelScale(); + EffectsInit(); + + // ------- UI ------- + + // TESTS of menu + if (Menu.GalaxMenu.InitGalaxyMenu("levels/galaxy_ptree.json")) { + std::cout << "ok" << std::endl; + } + else { + std::cout << "menu error" << std::endl; + } + + RenderLevelSnapshots(); + + LoadResources(); + GameState = CONST_GAMESTATE_LOADING; } else if (GameState == CONST_GAMESTATE_LOADING) { @@ -516,31 +555,6 @@ void TMyApplication::InnerUpdate(size_t dt) } else { - - Renderer->SwitchToFrameBuffer("LevelBuffer"); - - Renderer->SetProjectionMatrix(768, 480); - - Renderer->LoadIdentity(); - - for (auto &star : Menu.GalaxMenu.galaxies[0].Stars) - { - for (auto level : star.selectionMenu.gameLevels) - { - level->DrawSnapshot("LevelBuffer", false); - - Renderer->PushShader("BlackAndWhiteShader"); - - level->DrawSnapshot("LevelBuffer", true); - - Renderer->PopShader(); - } - } - - Renderer->SwitchToScreen(); - - Renderer->SetOrthoProjection(); - GameState = CONST_GAMESTATE_MENU; ApplySignalsToMenu(); diff --git a/game/main_code.h b/game/main_code.h index 4cc3afc..c1c73c1 100755 --- a/game/main_code.h +++ b/game/main_code.h @@ -89,6 +89,8 @@ const int CONST_GAMESTATE_PRELOADING = 7; class TMyApplication : public TApplication { protected: + bool skipUpdateToUpdateScreen; + int levelScreenWidth; int levelScreenHeight; float levelScreenRatio = 1.6; @@ -137,12 +139,16 @@ public: bool Loaded; TMyApplication() : TApplication(), Loaded(false), Inited(false) { } - - void LoadUserProgress(); + + void LoadUserProgress(); void SaveUserProgress(int levelStar, int levelIndex); virtual void InnerInit(); + virtual void RenderLevelSnapshots(); + + virtual void InnerReinitGLResources(); + virtual void InnerDeinit(); virtual void InnerDraw(); diff --git a/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/GL2JNIActivity.java b/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/GL2JNIActivity.java index 32f841e..b0fb16a 100755 --- a/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/GL2JNIActivity.java +++ b/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/GL2JNIActivity.java @@ -65,7 +65,7 @@ public class GL2JNIActivity extends Activity @Override protected void onPause() { - EngineWrapper.CallDestroy(); + //EngineWrapper.CallDestroy(); super.onPause(); mView.onPause(); } From 21c4c2a6854dfc50dffca456021ff6c9bff31bea Mon Sep 17 00:00:00 2001 From: Emil Kabirov Date: Mon, 19 Nov 2018 00:02:23 +0500 Subject: [PATCH 2/2] save --- .idea/workspace.xml | 125 ++++++++----------------- game/main_code.cpp | 4 +- proj.android-studio/app/CMakeLists.txt | 2 +- proj.android-studio/app/build.gradle | 6 +- proj.android-studio/build.gradle | 12 ++- 5 files changed, 57 insertions(+), 92 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c962845..2d1ca10 100755 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,14 @@ + + + + + - + + +