From 48173231d90de6bfc193260eab6369f7c88ca742 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 30 Dec 2018 12:21:18 +0800 Subject: -C++ examples --- bin/game/main.lua | 4 +- bin/jin.exe | Bin 572928 -> 572928 bytes build/vc++/examples/Animation/Animation.vcxproj | 141 ---------------- .../examples/Animation/Animation.vcxproj.filters | 6 - .../vc++/examples/Animation/Animation.vcxproj.user | 8 - .../examples/ParticleSystem/ParticleSystem.vcxproj | 147 ---------------- .../ParticleSystem/ParticleSystem.vcxproj.filters | 6 - .../ParticleSystem/ParticleSystem.vcxproj.user | 7 - .../examples/StateMachine/StateMachine.vcxproj | 145 ---------------- .../StateMachine/StateMachine.vcxproj.filters | 6 - .../StateMachine/StateMachine.vcxproj.user | 4 - build/vc++/jin.sln | 35 ---- examples/animation/main.cpp | 104 ------------ examples/particle_system/main.cpp | 186 --------------------- examples/state_machine/main.cpp | 124 -------------- 15 files changed, 2 insertions(+), 921 deletions(-) delete mode 100644 build/vc++/examples/Animation/Animation.vcxproj delete mode 100644 build/vc++/examples/Animation/Animation.vcxproj.filters delete mode 100644 build/vc++/examples/Animation/Animation.vcxproj.user delete mode 100644 build/vc++/examples/ParticleSystem/ParticleSystem.vcxproj delete mode 100644 build/vc++/examples/ParticleSystem/ParticleSystem.vcxproj.filters delete mode 100644 build/vc++/examples/ParticleSystem/ParticleSystem.vcxproj.user delete mode 100644 build/vc++/examples/StateMachine/StateMachine.vcxproj delete mode 100644 build/vc++/examples/StateMachine/StateMachine.vcxproj.filters delete mode 100644 build/vc++/examples/StateMachine/StateMachine.vcxproj.user delete mode 100644 examples/animation/main.cpp delete mode 100644 examples/particle_system/main.cpp delete mode 100644 examples/state_machine/main.cpp diff --git a/bin/game/main.lua b/bin/game/main.lua index b5723ad..ff8670d 100644 --- a/bin/game/main.lua +++ b/bin/game/main.lua @@ -350,8 +350,8 @@ function jin.core.onDraw() jin.graphics.print("Stats\n----------------\n" .. jin.graphics.getStatsStr(), 450, 10) jin.graphics.unuseShader() jin.graphics.unbindCanvas(screen) - - --jin.graphics.useShader(rgbsplit) + + jin.graphics.useShader(rgbsplit) local mode = jin.graphics.getBlendMode() jin.graphics.setBlendMode(jin.graphics.BlendMode.PREMULTIPLIEDALPHA) jin.graphics.draw(screen, 0, 0) diff --git a/bin/jin.exe b/bin/jin.exe index b2763a6..a718669 100644 Binary files a/bin/jin.exe and b/bin/jin.exe differ diff --git a/build/vc++/examples/Animation/Animation.vcxproj b/build/vc++/examples/Animation/Animation.vcxproj deleted file mode 100644 index 83e5dd3..0000000 --- a/build/vc++/examples/Animation/Animation.vcxproj +++ /dev/null @@ -1,141 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {3191C07B-085A-46BC-9436-469B4E2BF5F0} - Animation - 10.0.17134.0 - - - - Application - true - v141 - MultiByte - - - Application - false - v141 - true - MultiByte - - - Application - true - v141 - MultiByte - - - Application - false - v141 - true - MultiByte - - - - - - - - - - - - - - - - - - - - - $(SolutionDir)..\..\bin - - - - Level3 - Disabled - true - true - $(SolutionDir)..\..\src\;$(SolutionDir)..\..\src\3rdparty\SDL2\include;$(SolutionDir)..\..\src\3rdparty\LuaJIT-2.0.5\include;$(SolutionDir)..\..\src\3rdparty\ - true - - - $(SolutionDir)libs\SDL2-2.0.5\lib\x86;%(AdditionalLibraryDirectories) - opengl32.lib;%(AdditionalDependencies) - Console - - - true - - - - - Level3 - Disabled - true - true - - - - - Level3 - MaxSpeed - true - true - true - true - $(SolutionDir)..\..\src\;$(SolutionDir)..\..\src\3rdparty\SDL2\include;$(SolutionDir)..\..\src\3rdparty\LuaJIT-2.0.5\include;$(SolutionDir)..\..\src\3rdparty\ - - - true - true - - - - - Level3 - MaxSpeed - true - true - true - true - - - true - true - - - - - - - - {9ee02090-c15e-4520-9c05-c435e45ef2fc} - - - - - - \ No newline at end of file diff --git a/build/vc++/examples/Animation/Animation.vcxproj.filters b/build/vc++/examples/Animation/Animation.vcxproj.filters deleted file mode 100644 index 57272c2..0000000 --- a/build/vc++/examples/Animation/Animation.vcxproj.filters +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/build/vc++/examples/Animation/Animation.vcxproj.user b/build/vc++/examples/Animation/Animation.vcxproj.user deleted file mode 100644 index 307fc45..0000000 --- a/build/vc++/examples/Animation/Animation.vcxproj.user +++ /dev/null @@ -1,8 +0,0 @@ - - - - $(SolutionDir)..\..\bin - false - WindowsLocalDebugger - - \ No newline at end of file diff --git a/build/vc++/examples/ParticleSystem/ParticleSystem.vcxproj b/build/vc++/examples/ParticleSystem/ParticleSystem.vcxproj deleted file mode 100644 index faadeec..0000000 --- a/build/vc++/examples/ParticleSystem/ParticleSystem.vcxproj +++ /dev/null @@ -1,147 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {984764C1-0471-4A36-9B2B-BF846817C95F} - ParticleSystem - 10.0.17134.0 - - - - Application - true - v141 - MultiByte - - - Application - false - v141 - true - MultiByte - - - Application - true - v141 - MultiByte - - - Application - false - v141 - true - MultiByte - - - - - - - - - - - - - - - - - - - - - $(SolutionDir)..\..\bin - - - $(SolutionDir)..\..\bin - - - - Level3 - MaxSpeed - true - true - true - true - $(SolutionDir)..\..\src\;$(SolutionDir)..\..\src\3rdparty\SDL2\include;$(SolutionDir)..\..\src\3rdparty\LuaJIT-2.0.5\include;$(SolutionDir)..\..\src\3rdparty\ - - - true - true - Console - $(SolutionDir)libs\SDL2-2.0.5\lib\x86;%(AdditionalLibraryDirectories) - opengl32.lib;%(AdditionalDependencies) - - - - - Level3 - Disabled - true - true - $(SolutionDir)..\..\src\;$(SolutionDir)..\..\src\3rdparty\SDL2\include;$(SolutionDir)..\..\src\3rdparty\LuaJIT-2.0.5\include;$(SolutionDir)..\..\src\3rdparty\ - true - - - Console - $(SolutionDir)libs\SDL2-2.0.5\lib\x86;%(AdditionalLibraryDirectories) - opengl32.lib;%(AdditionalDependencies) - - - true - - - - - Level3 - Disabled - true - true - - - - - Level3 - MaxSpeed - true - true - true - true - - - true - true - - - - - - - - {9ee02090-c15e-4520-9c05-c435e45ef2fc} - - - - - - \ No newline at end of file diff --git a/build/vc++/examples/ParticleSystem/ParticleSystem.vcxproj.filters b/build/vc++/examples/ParticleSystem/ParticleSystem.vcxproj.filters deleted file mode 100644 index fa43442..0000000 --- a/build/vc++/examples/ParticleSystem/ParticleSystem.vcxproj.filters +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/build/vc++/examples/ParticleSystem/ParticleSystem.vcxproj.user b/build/vc++/examples/ParticleSystem/ParticleSystem.vcxproj.user deleted file mode 100644 index 56251fe..0000000 --- a/build/vc++/examples/ParticleSystem/ParticleSystem.vcxproj.user +++ /dev/null @@ -1,7 +0,0 @@ - - - - $(SolutionDir)..\..\bin - WindowsLocalDebugger - - \ No newline at end of file diff --git a/build/vc++/examples/StateMachine/StateMachine.vcxproj b/build/vc++/examples/StateMachine/StateMachine.vcxproj deleted file mode 100644 index 55a0815..0000000 --- a/build/vc++/examples/StateMachine/StateMachine.vcxproj +++ /dev/null @@ -1,145 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {C70BFD61-6462-49D2-9F54-F16D77FF434A} - StateMachine - 10.0.17134.0 - - - - Application - true - v141 - MultiByte - - - Application - false - v141 - true - MultiByte - - - Application - true - v141 - MultiByte - - - Application - false - v141 - true - MultiByte - - - - - - - - - - - - - - - - - - - - - $(SolutionDir)..\..\bin - - - $(SolutionDir)..\..\bin - - - - Level3 - Disabled - true - true - $(SolutionDir)..\..\src\;$(SolutionDir)..\..\src\3rdparty\SDL2\include;$(SolutionDir)..\..\src\3rdparty\LuaJIT-2.0.5\include;$(SolutionDir)..\..\src\3rdparty\ - true - - - Console - opengl32.lib;%(AdditionalDependencies) - - - true - - - - - Level3 - Disabled - true - true - - - - - Level3 - MaxSpeed - true - true - true - true - $(SolutionDir)..\..\src\;$(SolutionDir)..\..\src\3rdparty\SDL2\include;$(SolutionDir)..\..\src\3rdparty\LuaJIT-2.0.5\include;$(SolutionDir)..\..\src\3rdparty\ - - - true - true - Console - opengl32.lib;%(AdditionalDependencies) - - - - - Level3 - MaxSpeed - true - true - true - true - - - true - true - - - - - - - - {9ee02090-c15e-4520-9c05-c435e45ef2fc} - - - - - - \ No newline at end of file diff --git a/build/vc++/examples/StateMachine/StateMachine.vcxproj.filters b/build/vc++/examples/StateMachine/StateMachine.vcxproj.filters deleted file mode 100644 index 3a52c98..0000000 --- a/build/vc++/examples/StateMachine/StateMachine.vcxproj.filters +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/build/vc++/examples/StateMachine/StateMachine.vcxproj.user b/build/vc++/examples/StateMachine/StateMachine.vcxproj.user deleted file mode 100644 index be25078..0000000 --- a/build/vc++/examples/StateMachine/StateMachine.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/build/vc++/jin.sln b/build/vc++/jin.sln index a143e41..1d81611 100644 --- a/build/vc++/jin.sln +++ b/build/vc++/jin.sln @@ -7,10 +7,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libjin-lua", "libjin-lua\li EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libjin", "libjin\libjin.vcxproj", "{9EE02090-C15E-4520-9C05-C435E45EF2FC}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Example", "Example", "{6FC112F9-B317-4444-B4FB-2E0BF70328F1}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ParticleSystem", "examples\ParticleSystem\ParticleSystem.vcxproj", "{984764C1-0471-4A36-9B2B-BF846817C95F}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3rdParty", "3rdParty", "{65DFFFA6-F434-47FB-9DB2-DCF019060B92}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "stb", "3rdparty\stb\stb.vcxproj", "{E9A7ECC9-1437-45A8-B970-E9E75BD1F8E0}" @@ -37,10 +33,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SDL", "SDL", "{CD378AC6-A4F EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2main", "3rdparty\SDL2main\SDL2main.vcxproj", "{5522BDBA-3F18-4EDD-B6E4-CE6A70D9D794}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StateMachine", "examples\StateMachine\StateMachine.vcxproj", "{C70BFD61-6462-49D2-9F54-F16D77FF434A}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Animation", "examples\Animation\Animation.vcxproj", "{3191C07B-085A-46BC-9436-469B4E2BF5F0}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LuaJIT-2.0.5", "3rdparty\LuaJIT-2.0.5\LuaJIT-2.0.5.vcxproj", "{45AC0438-98A8-4369-A21D-BBCBE7995B34}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "luax", "3rdparty\luax\luax.vcxproj", "{C6B16179-5640-4D41-8756-0525D25EB569}" @@ -73,14 +65,6 @@ Global {9EE02090-C15E-4520-9C05-C435E45EF2FC}.Release|x64.Build.0 = Release|x64 {9EE02090-C15E-4520-9C05-C435E45EF2FC}.Release|x86.ActiveCfg = Release|Win32 {9EE02090-C15E-4520-9C05-C435E45EF2FC}.Release|x86.Build.0 = Release|Win32 - {984764C1-0471-4A36-9B2B-BF846817C95F}.Debug|x64.ActiveCfg = Debug|x64 - {984764C1-0471-4A36-9B2B-BF846817C95F}.Debug|x64.Build.0 = Debug|x64 - {984764C1-0471-4A36-9B2B-BF846817C95F}.Debug|x86.ActiveCfg = Debug|Win32 - {984764C1-0471-4A36-9B2B-BF846817C95F}.Debug|x86.Build.0 = Debug|Win32 - {984764C1-0471-4A36-9B2B-BF846817C95F}.Release|x64.ActiveCfg = Release|x64 - {984764C1-0471-4A36-9B2B-BF846817C95F}.Release|x64.Build.0 = Release|x64 - {984764C1-0471-4A36-9B2B-BF846817C95F}.Release|x86.ActiveCfg = Release|Win32 - {984764C1-0471-4A36-9B2B-BF846817C95F}.Release|x86.Build.0 = Release|Win32 {E9A7ECC9-1437-45A8-B970-E9E75BD1F8E0}.Debug|x64.ActiveCfg = Debug|x64 {E9A7ECC9-1437-45A8-B970-E9E75BD1F8E0}.Debug|x64.Build.0 = Debug|x64 {E9A7ECC9-1437-45A8-B970-E9E75BD1F8E0}.Debug|x86.ActiveCfg = Debug|Win32 @@ -145,22 +129,6 @@ Global {5522BDBA-3F18-4EDD-B6E4-CE6A70D9D794}.Release|x64.Build.0 = Release|x64 {5522BDBA-3F18-4EDD-B6E4-CE6A70D9D794}.Release|x86.ActiveCfg = Release|Win32 {5522BDBA-3F18-4EDD-B6E4-CE6A70D9D794}.Release|x86.Build.0 = Release|Win32 - {C70BFD61-6462-49D2-9F54-F16D77FF434A}.Debug|x64.ActiveCfg = Debug|x64 - {C70BFD61-6462-49D2-9F54-F16D77FF434A}.Debug|x64.Build.0 = Debug|x64 - {C70BFD61-6462-49D2-9F54-F16D77FF434A}.Debug|x86.ActiveCfg = Debug|Win32 - {C70BFD61-6462-49D2-9F54-F16D77FF434A}.Debug|x86.Build.0 = Debug|Win32 - {C70BFD61-6462-49D2-9F54-F16D77FF434A}.Release|x64.ActiveCfg = Release|x64 - {C70BFD61-6462-49D2-9F54-F16D77FF434A}.Release|x64.Build.0 = Release|x64 - {C70BFD61-6462-49D2-9F54-F16D77FF434A}.Release|x86.ActiveCfg = Release|Win32 - {C70BFD61-6462-49D2-9F54-F16D77FF434A}.Release|x86.Build.0 = Release|Win32 - {3191C07B-085A-46BC-9436-469B4E2BF5F0}.Debug|x64.ActiveCfg = Debug|x64 - {3191C07B-085A-46BC-9436-469B4E2BF5F0}.Debug|x64.Build.0 = Debug|x64 - {3191C07B-085A-46BC-9436-469B4E2BF5F0}.Debug|x86.ActiveCfg = Debug|Win32 - {3191C07B-085A-46BC-9436-469B4E2BF5F0}.Debug|x86.Build.0 = Debug|Win32 - {3191C07B-085A-46BC-9436-469B4E2BF5F0}.Release|x64.ActiveCfg = Release|x64 - {3191C07B-085A-46BC-9436-469B4E2BF5F0}.Release|x64.Build.0 = Release|x64 - {3191C07B-085A-46BC-9436-469B4E2BF5F0}.Release|x86.ActiveCfg = Release|Win32 - {3191C07B-085A-46BC-9436-469B4E2BF5F0}.Release|x86.Build.0 = Release|Win32 {45AC0438-98A8-4369-A21D-BBCBE7995B34}.Debug|x64.ActiveCfg = Debug|x64 {45AC0438-98A8-4369-A21D-BBCBE7995B34}.Debug|x64.Build.0 = Debug|x64 {45AC0438-98A8-4369-A21D-BBCBE7995B34}.Debug|x86.ActiveCfg = Debug|Win32 @@ -200,7 +168,6 @@ Global GlobalSection(NestedProjects) = preSolution {A3E35ECA-62EB-45CE-8152-674FBC7F7A3B} = {60F334B9-B068-47CE-8CD9-431A356CB31B} {9EE02090-C15E-4520-9C05-C435E45EF2FC} = {60F334B9-B068-47CE-8CD9-431A356CB31B} - {984764C1-0471-4A36-9B2B-BF846817C95F} = {6FC112F9-B317-4444-B4FB-2E0BF70328F1} {E9A7ECC9-1437-45A8-B970-E9E75BD1F8E0} = {65DFFFA6-F434-47FB-9DB2-DCF019060B92} {8828F6B1-F167-4BC9-B7C7-7CC34CDDEE8A} = {65DFFFA6-F434-47FB-9DB2-DCF019060B92} {B88DC691-FE8A-4C5E-8D57-EBCC6B13C744} = {65DFFFA6-F434-47FB-9DB2-DCF019060B92} @@ -211,8 +178,6 @@ Global {2A2F610D-E42B-426F-8DC8-79E0C6FCCDD2} = {65DFFFA6-F434-47FB-9DB2-DCF019060B92} {CD378AC6-A4FE-48F7-984A-EB68C60A211B} = {65DFFFA6-F434-47FB-9DB2-DCF019060B92} {5522BDBA-3F18-4EDD-B6E4-CE6A70D9D794} = {CD378AC6-A4FE-48F7-984A-EB68C60A211B} - {C70BFD61-6462-49D2-9F54-F16D77FF434A} = {6FC112F9-B317-4444-B4FB-2E0BF70328F1} - {3191C07B-085A-46BC-9436-469B4E2BF5F0} = {6FC112F9-B317-4444-B4FB-2E0BF70328F1} {45AC0438-98A8-4369-A21D-BBCBE7995B34} = {2A2F610D-E42B-426F-8DC8-79E0C6FCCDD2} {C6B16179-5640-4D41-8756-0525D25EB569} = {65DFFFA6-F434-47FB-9DB2-DCF019060B92} {4156CD69-6FC4-4B32-B008-BB94C8AE17F5} = {2A2F610D-E42B-426F-8DC8-79E0C6FCCDD2} diff --git a/examples/animation/main.cpp b/examples/animation/main.cpp deleted file mode 100644 index b5ad60f..0000000 --- a/examples/animation/main.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include - -#include "libjin/jin.h" - -using namespace std; -using namespace JinEngine::AI; -using namespace JinEngine::Game; -using namespace JinEngine::Math; -using namespace JinEngine::Input; -using namespace JinEngine::Graphics; -using namespace JinEngine::Graphics::Shaders; -using namespace JinEngine::Graphics::Particles; -using namespace JinEngine::Graphics::Animations; -using namespace JinEngine::Filesystem; -using namespace JinEngine::Time; - -Timer timer; -Timer::Handler* hnd; -Texture* tex; -Shader* shader; -Animation anim; -Animator animator; -const char* shader_code = R"( -#VERTEX_SHADER -Vertex vert(Vertex v) -{ - return v; -} -#END_VERTEX_SHADER -#FRAGMENT_SHADER -Color frag(Color col, Texture tex, Vertex v) -{ - Color c = texel(tex, v.uv); - return c * col; -} -#END_FRAGMENT_SHADER -)"; -const float Pi = 3.14f; -void onLoad() -{ - tex = Texture::createTexture("anim.png"); - shader = Shader::createShader(shader_code); - SpriteSheet ss = SpriteSheet(tex); - vector frames = ss.createSprites(19, 1, 19, 246, 238, Origin::BottomCenter); - anim.addFrames(frames); - anim.setSpeed(10); - animator.setAnimation(&anim); -} - -void onEvent(Event* e) -{ - static Application* Application = Application::get(); - if (e->type == EventType::QUIT) - Application->stop(); -} - -void onUpdate(int ms) -{ - animator.update(ms / 1000.f); - timer.update(ms); -} - -void onDraw() -{ - shader->use(); - Mouse* m = Mouse::get(); - int x, y; - m->getState(&x, &y); - animator.render(x, y, 1, 1, 0); - shader->unuse(); -} - -int main(int argc, char* argv[]) -{ - Application* Application = Application::get(); - Application::Setting setting; - setting.loader = onLoad; - setting.eventHandler = onEvent; - setting.updater = onUpdate; - setting.drawer = onDraw; - Application->init(&setting); - - AssetDatabase::get()->mount("."); - - Window* wnd = Window::get(); - Window::Setting wndSetting; - wndSetting.width = 600; - wndSetting.height = 512; - wndSetting.title = "Jin v0.1.1"; - wndSetting.fps = 60; - wndSetting.vsync = false; - wndSetting.fullscreen = false; - wndSetting.resizable = false; - wndSetting.icon = "."; - wnd->init(&wndSetting); - wnd->show(); - - Application->run(); - - Application->quit(); - wnd->quit(); - - return 0; -} \ No newline at end of file diff --git a/examples/particle_system/main.cpp b/examples/particle_system/main.cpp deleted file mode 100644 index 93efc82..0000000 --- a/examples/particle_system/main.cpp +++ /dev/null @@ -1,186 +0,0 @@ -#include - -#include "libjin/jin.h" - -using namespace std; -using namespace JinEngine::AI; -using namespace JinEngine::Game; -using namespace JinEngine::Math; -using namespace JinEngine::Input; -using namespace JinEngine::Graphics; -using namespace JinEngine::Graphics::Shaders; -using namespace JinEngine::Graphics::Particles; -using namespace JinEngine::Filesystem; -using namespace JinEngine::Time; - -ParticleSystem* p; -Timer timer; -Timer::Handler* hnd; -Shader* shader; -Texture* tex; -Sprite* spr; -Texture* tex1; -Sprite* spr1; -Texture* tex2; -Sprite* spr2; -const char* shader_code = R"( -#VERTEX_SHADER - Vertex vert(Vertex v) - { - return v; - } -#END_VERTEX_SHADER -#FRAGMENT_SHADER - Color frag(Color col, Texture tex, Vertex v) - { - Color c = texel(tex, v.uv); - return c * col; - } -#END_FRAGMENT_SHADER -)"; -const float Pi = 3.14f; -Texture* textures[10]; -Sprite* sprites[10]; -void onLoad() -{ - for (int i = 0; i < 10; ++i) - { - string name = string("dust/s_dust_A_") + std::to_string(i) + ".png"; - textures[i] = new Texture(name.c_str()); - sprites[i] = new Sprite(textures[i], Origin::MIDDLECENTER); - } - tex = new Texture("particle.png"); - spr = new Sprite(tex, Origin::MIDDLECENTER); - tex1 = new Texture("texture.png"); - spr1 = new Sprite(tex1, Origin::MIDDLECENTER); - tex2 = new Texture("splash.png"); - spr2 = new Sprite(tex2, Origin::MIDDLECENTER); - shader = new Shader(shader_code); -/* - ParticleSystemDef def; - def.maxParticleCount = 30; - - def.emitterDef.emitRateDef.rate.rate = 0.01f; - - def.emitterDef.forceDef.enableRandom = true; - def.emitterDef.forceDef.force.random.floor = 80; - def.emitterDef.forceDef.force.random.ceil = 150; - - def.emitterDef.positionDef.enableRandom = true; - def.emitterDef.positionDef.position.random.floor = Vector2(-2, -2); - def.emitterDef.positionDef.position.random.ceil = Vector2(2, 2); - - def.emitterDef.directionDef.enableRandom = true; - def.emitterDef.directionDef.direction.random.floor = -Pi / 8 - Pi / 2 ; - def.emitterDef.directionDef.direction.random.ceil = Pi / 8 - Pi / 2 ; - - def.particleDef.linearAccelarationDef.linearAccelaration = Vector2(0, 10); - - def.particleDef.spritesDef.mode = SpriteMode::RANDOM; - def.particleDef.spritesDef.sprites.push_back(spr); - def.particleDef.spritesDef.sprites.push_back(spr1); - //def.particleDef.spritesDef.sprites.push_back(spr2); - - def.particleDef.colorDef.color = Color(255, 40, 40, 255); - def.particleDef.colorDef.overTime.enable = true; - def.particleDef.colorDef.overTime.value.addColor(Color(255, 100, 0, 255), 0); - //def.particleDef.colorDef.overTime.value.addColor(Color(255, 255, 0, 100), 0.3); - def.particleDef.colorDef.overTime.value.addColor(Color(0, 255, 100, 255), 0.5); - def.particleDef.colorDef.overTime.value.addColor(Color(255, 0, 0, 255), 1); - - def.particleDef.transparencyDef.overTime.enable = true; - def.particleDef.transparencyDef.overTime.value.addPoint(0, 1); - def.particleDef.transparencyDef.overTime.value.addPoint(0.6, 0); - - def.particleDef.blendDef.additive = true; - - def.particleDef.lifeTimeDef.enableRandom = true; - def.particleDef.lifeTimeDef.life.random.floor = 0.5; - def.particleDef.lifeTimeDef.life.random.ceil = 2; - - def.particleDef.scaleDef.overTime.enable = true; - def.particleDef.scaleDef.overTime.value.addPoint(0, 1); - def.particleDef.scaleDef.overTime.value.addPoint(1, 0.7); -*/ - p = new ParticleSystem(); - p->setEmitRate(0.02); - p->setEmitForce(80, 120); - //p->setEmitPosition(Vector2(-2, -2), Vector2(2, 2)); - p->setEmitPosition(Vector2()); - p->setEmitDirection(-Pi / 10 - Pi / 2, Pi / 10 - Pi / 2); - p->setParticleLinearAccelaration(Vector2(0, 10)); - p->setParticleSpritesMode(SpriteMode::ANIMATED); - //p->addParticleSprites(2, spr, spr1, spr2); - for (int i = 0; i < 10; ++i) - p->addParticleSprite(sprites[i]); - //p->addParticleColorPoint(Color(255, 100, 0, 255), 0); - //p->addParticleColorPoint(Color(0, 255, 100, 255), 0.5); - //p->addParticleColorPoint(Color(255, 0, 0, 255), 1); - p->setParticleColor(Color(255, 30, 0, 255)); - p->addParticleTransparencyPoint(1, 0); - p->addParticleTransparencyPoint(0, 0.5); - p->enableParticleBlendAdditive(true); - p->setParticleLife(0.5, 2); - p->addParticleScalePoint(3, 0); - p->addParticleScalePoint(0, 1); - timer.every(3, [=](void*)->void { - //p->setEmitForce() - }); -} - -void onEvent(Event* e) -{ - static Application* Application = Application::get(); - if (e->type == EventType::QUIT) - Application->stop(); -} - -void onUpdate(int ms) -{ - p->update(ms / 1000.f); - timer.update(ms); -} - -void onDraw() -{ - gl.useShader(shader); - Mouse* m = Mouse::get(); - int x, y; - m->getState(&x, &y); - p->setPosition(x, y); - p->render(); - gl.unuseShader(); -} - -int main(int argc, char* argv[]) -{ - Application* app = Application::get(); - Application::Setting setting; - setting.loader = onLoad; - setting.eventHandler = onEvent; - setting.updater = onUpdate; - setting.drawer = onDraw; - app->start(&setting); - - AssetDatabase::get()->mount("."); - - Window* wnd = Window::get(); - Window::Setting wndSetting; - wndSetting.width = 600; - wndSetting.height = 512; - wndSetting.title = "Jin v0.1.1"; - wndSetting.fps = 60; - wndSetting.vsync = false; - wndSetting.fullscreen = false; - wndSetting.resizable = false; - wndSetting.icon = "."; - wnd->start(&wndSetting); - wnd->show(); - - app->run(); - - app->quit(); - wnd->quit(); - - return 0; -} \ No newline at end of file diff --git a/examples/state_machine/main.cpp b/examples/state_machine/main.cpp deleted file mode 100644 index c061a81..0000000 --- a/examples/state_machine/main.cpp +++ /dev/null @@ -1,124 +0,0 @@ -#include - -#include "libjin/jin.h" - -using namespace std; -using namespace JinEngine::AI; -using namespace JinEngine::Game; -using namespace JinEngine::Input; -using namespace JinEngine::Graphics; -using namespace JinEngine::Graphics::Particles; -using namespace JinEngine::Filesystem; -using namespace JinEngine::Time; - -ParticleSystem* p; -StateMachine sm; -Timer timer; -enum -{ - STATE_EMPTY = 0, - STATE_RUN, - STATE_IDLE, - STATE_SLEEP, - STATE_JUMP -}; - -enum -{ - PARAM_RUN = 1, - PARAM_IDLE = 2, - PARAM_IDLE2 = 3, - PARAM_RUN = 4 -}; - -void onLoad() -{ - sm.addState(STATE_RUN); - sm.addState(STATE_IDLE); - sm.addState(STATE_SLEEP); - sm.addState(STATE_JUMP); - sm.addParametert(PARAM_RUN); - sm.addParameterb(PARAM_IDLE); - sm.addParameterb(PARAM_IDLE2); - sm.addTransition(STATE_EMPTY, STATE_IDLE, StateMachine::Conditions().andt(PARAM_RUN)); - sm.addTransition("Idle", "Run", StateMachine::Conditions().andb("idle", StateMachine::BOOL_IS, true).andb("idle2", StateMachine::BOOL_IS, true)); - sm.setEnterListener([](const string& state, void* p) { - cout << "Enter: " << state << endl; - }); - sm.addEnterListener("Run", [](void* p) { - cout << "A Run state enter callback" << endl; - }); - sm.addTranslateListener("Idle", "Run", [](void* p) { - cout << "From Idle to Run" << endl; - }); - sm.addUpdateListener("Run", [](void* p) { - cout << "run" << endl; - }); - Window::get()->show(); - Timer::Handler* hnd = timer.every(500, [](void*) { - cout << sm.getCurrentState() << endl; - }, NULL); - timer.after(2500, [](void*) { - //sm.setParameterb("run", true); - sm.setParametert("run"); - }, NULL); - timer.after(5000, [=](void*) { - sm.setParameterb("idle", true); - sm.setParametert("run"); - timer.cancel(hnd); - //sm.setParameterb("run", false); - }, NULL); - timer.after(8000, [](void*) { - sm.setParameterb("idle2", true); - //sm.setParameterb("run", false); - }, NULL); -} - -void onEvent(Event* e) -{ - static Application* Application = Application::get(); - if (e->type == EventType::QUIT) - Application->stop(); -} - -void onUpdate(int ms) -{ - timer.update(ms); - sm.update(); -} - -void onDraw() -{ -} - -int main(int argc, char* argv[]) -{ - Application* Application = Application::get(); - Application::Setting setting; - setting.loader = onLoad; - setting.eventHandler = onEvent; - setting.updater = onUpdate; - setting.drawer = onDraw; - Application->init(&setting); - - AssetDatabase::get()->mount("."); - - Window* wnd = Window::get(); - Window::Setting wndSetting; - wndSetting.width = 600; - wndSetting.height = 512; - wndSetting.title = "Jin v0.1.1"; - wndSetting.fps = 60; - wndSetting.vsync = false; - wndSetting.fullscreen = false; - wndSetting.resizable = false; - wndSetting.icon = "."; - wnd->init(&wndSetting); - - Application->run(); - - Application->quit(); - wnd->quit(); - - return 0; -} \ No newline at end of file -- cgit v1.1-26-g67d0