├── .gitignore ├── .gitmodules ├── .travis.yml ├── LICENSE ├── README.md └── src ├── AI └── Pathfinding │ ├── PathFindManager.cpp │ ├── PathFindManager.h │ ├── SearchCell.cpp │ └── SearchCell.h ├── Actions ├── Action.cpp ├── Action.h ├── DelayedAction.cpp ├── DelayedAction.h ├── DelayedFramesAction.cpp ├── DelayedFramesAction.h ├── Index.h ├── LoopedAction.cpp ├── LoopedAction.h ├── ScaleAction.cpp ├── ScaleAction.h ├── TimedAction.cpp ├── TimedAction.h ├── TimedFadeAction.cpp ├── TimedFadeAction.h ├── TimedMoveAction.cpp ├── TimedMoveAction.h ├── TimedScaleAction.cpp └── TimedScaleAction.h ├── Android.mk ├── Application.mk ├── BaseGame.h ├── Components ├── AI │ ├── PathFindNodeComponent.cpp │ ├── PathFindNodeComponent.h │ └── index.h ├── BaseComponent.cpp ├── BaseComponent.h ├── CameraComponent.cpp ├── CameraComponent.h ├── Graphics │ ├── SpriteComponent.cpp │ ├── SpriteComponent.h │ ├── SpritesheetComponent.cpp │ ├── SpritesheetComponent.h │ ├── TextComponent.cpp │ └── TextComponent.h ├── Physics │ ├── BaseColliderComponent.cpp │ ├── BaseColliderComponent.h │ ├── CircleColliderComponent.cpp │ ├── CircleColliderComponent.h │ ├── RectangleColliderComponent.cpp │ ├── RectangleColliderComponent.h │ └── index.h ├── TransformComponent.cpp └── TransformComponent.h ├── Console.cpp ├── Console.h ├── Context.h ├── Entity.cpp ├── Entity.h ├── EventLoop.cpp ├── EventLoop.h ├── Graphics ├── Color.cpp ├── Color.h ├── Color.inl ├── Font.cpp ├── Font.h ├── FontManager.cpp ├── FontManager.h ├── GraphicsManager.cpp ├── GraphicsManager.h ├── Resource.cpp ├── Resource.h ├── ScaleSystem.cpp ├── ScaleSystem.h ├── Shader.cpp ├── Shader.h ├── SpriteAnimationManager.cpp ├── SpriteAnimationManager.h ├── SpriteBatch.cpp ├── SpriteBatch.h ├── Texture2D.cpp ├── Texture2D.h ├── TextureManager.cpp ├── TextureManager.h └── UI │ ├── Index.h │ ├── UIAnimatedButton.cpp │ ├── UIAnimatedButton.h │ ├── UIAnimatedImage.cpp │ ├── UIAnimatedImage.h │ ├── UIAnimatedTextButton.cpp │ ├── UIAnimatedTextButton.h │ ├── UIBaseCursor.cpp │ ├── UIBaseCursor.h │ ├── UIButton.cpp │ ├── UIButton.h │ ├── UICursor.cpp │ ├── UICursor.h │ ├── UIDock.cpp │ ├── UIDock.h │ ├── UIImage.cpp │ ├── UIImage.h │ ├── UIObject.cpp │ ├── UIObject.h │ ├── UISimpleTextButton.cpp │ ├── UISimpleTextButton.h │ ├── UISlider.cpp │ ├── UISlider.h │ ├── UIStaticButton.cpp │ ├── UIStaticButton.h │ ├── UIStaticTextButton.cpp │ ├── UIStaticTextButton.h │ ├── UITextButton.cpp │ ├── UITextButton.h │ ├── UITextField.cpp │ ├── UITextField.h │ ├── UIUserElement.cpp │ └── UIUserElement.h ├── Helpers ├── .gitignore ├── 2D │ ├── pos.cpp │ └── pos.h ├── AARect.cpp ├── AARect.h ├── Debug │ ├── DebugDraw.cpp │ └── DebugDraw.h ├── Dictionary.h ├── Dictionary.inl ├── FPS.cpp ├── FPS.h ├── Filepath.cpp ├── Filepath.h ├── GameData.cpp ├── GameData.h ├── GameData.inl ├── HashTag.cpp ├── HashTag.h ├── Helpers.cpp ├── Helpers.h ├── Helpers.inl ├── HelpersAndroid.cpp ├── HelpersAndroid.h ├── HelpersCrossplatform.cpp ├── HelpersCrossplatform.h ├── Math.cpp ├── Math.h ├── Math.inl ├── Rect.cpp ├── Rect.h ├── SerializedData.cpp ├── SerializedData.h ├── Singleton.h ├── Singleton.inl ├── SpriteAnimation.cpp ├── SpriteAnimation.h ├── Spritesheet.cpp ├── Spritesheet.h ├── State.cpp ├── State.h ├── StateManager.cpp ├── StateManager.h ├── Stopwatch.cpp ├── Stopwatch.h ├── Time.cpp ├── Time.h ├── Timer.cpp ├── Timer.h ├── TimerManager.cpp ├── TimerManager.h └── glm │ ├── CMakeLists.txt │ ├── core │ ├── _detail.hpp │ ├── _fixes.hpp │ ├── _swizzle.hpp │ ├── _swizzle_func.hpp │ ├── _vectorize.hpp │ ├── dummy.cpp │ ├── func_common.hpp │ ├── func_common.inl │ ├── func_exponential.hpp │ ├── func_exponential.inl │ ├── func_geometric.hpp │ ├── func_geometric.inl │ ├── func_integer.hpp │ ├── func_integer.inl │ ├── func_matrix.hpp │ ├── func_matrix.inl │ ├── func_noise.hpp │ ├── func_noise.inl │ ├── func_packing.hpp │ ├── func_packing.inl │ ├── func_trigonometric.hpp │ ├── func_trigonometric.inl │ ├── func_vector_relational.hpp │ ├── func_vector_relational.inl │ ├── hint.hpp │ ├── intrinsic_common.hpp │ ├── intrinsic_common.inl │ ├── intrinsic_exponential.hpp │ ├── intrinsic_exponential.inl │ ├── intrinsic_geometric.hpp │ ├── intrinsic_geometric.inl │ ├── intrinsic_matrix.hpp │ ├── intrinsic_matrix.inl │ ├── intrinsic_trigonometric.hpp │ ├── intrinsic_trigonometric.inl │ ├── intrinsic_vector_relational.hpp │ ├── intrinsic_vector_relational.inl │ ├── setup.hpp │ ├── type.hpp │ ├── type_float.hpp │ ├── type_gentype.hpp │ ├── type_gentype.inl │ ├── type_half.hpp │ ├── type_half.inl │ ├── type_int.hpp │ ├── type_mat.hpp │ ├── type_mat.inl │ ├── type_mat2x2.hpp │ ├── type_mat2x2.inl │ ├── type_mat2x3.hpp │ ├── type_mat2x3.inl │ ├── type_mat2x4.hpp │ ├── type_mat2x4.inl │ ├── type_mat3x2.hpp │ ├── type_mat3x2.inl │ ├── type_mat3x3.hpp │ ├── type_mat3x3.inl │ ├── type_mat3x4.hpp │ ├── type_mat3x4.inl │ ├── type_mat4x2.hpp │ ├── type_mat4x2.inl │ ├── type_mat4x3.hpp │ ├── type_mat4x3.inl │ ├── type_mat4x4.hpp │ ├── type_mat4x4.inl │ ├── type_size.hpp │ ├── type_vec.hpp │ ├── type_vec.inl │ ├── type_vec1.hpp │ ├── type_vec1.inl │ ├── type_vec2.hpp │ ├── type_vec2.inl │ ├── type_vec3.hpp │ ├── type_vec3.inl │ ├── type_vec4.hpp │ └── type_vec4.inl │ ├── ext.hpp │ ├── glm.h │ ├── gtc │ ├── constants.hpp │ ├── constants.inl │ ├── epsilon.hpp │ ├── epsilon.inl │ ├── half_float.hpp │ ├── half_float.inl │ ├── matrix_access.hpp │ ├── matrix_access.inl │ ├── matrix_integer.hpp │ ├── matrix_inverse.hpp │ ├── matrix_inverse.inl │ ├── matrix_transform.hpp │ ├── matrix_transform.inl │ ├── noise.hpp │ ├── noise.inl │ ├── quaternion.hpp │ ├── quaternion.inl │ ├── random.hpp │ ├── random.inl │ ├── reciprocal.hpp │ ├── reciprocal.inl │ ├── swizzle.hpp │ ├── swizzle.inl │ ├── type_precision.hpp │ ├── type_precision.inl │ ├── type_ptr.hpp │ ├── type_ptr.inl │ ├── ulp.hpp │ └── ulp.inl │ ├── gtx │ ├── associated_min_max.hpp │ ├── associated_min_max.inl │ ├── bit.hpp │ ├── bit.inl │ ├── closest_point.hpp │ ├── closest_point.inl │ ├── color_cast.hpp │ ├── color_cast.inl │ ├── color_space.hpp │ ├── color_space.inl │ ├── color_space_YCoCg.hpp │ ├── color_space_YCoCg.inl │ ├── compatibility.hpp │ ├── compatibility.inl │ ├── component_wise.hpp │ ├── component_wise.inl │ ├── constants.hpp │ ├── epsilon.hpp │ ├── euler_angles.hpp │ ├── euler_angles.inl │ ├── extend.hpp │ ├── extend.inl │ ├── extented_min_max.hpp │ ├── extented_min_max.inl │ ├── fast_exponential.hpp │ ├── fast_exponential.inl │ ├── fast_square_root.hpp │ ├── fast_square_root.inl │ ├── fast_trigonometry.hpp │ ├── fast_trigonometry.inl │ ├── gradient_paint.hpp │ ├── gradient_paint.inl │ ├── handed_coordinate_space.hpp │ ├── handed_coordinate_space.inl │ ├── inertia.hpp │ ├── inertia.inl │ ├── int_10_10_10_2.hpp │ ├── int_10_10_10_2.inl │ ├── integer.hpp │ ├── integer.inl │ ├── intersect.hpp │ ├── intersect.inl │ ├── log_base.hpp │ ├── log_base.inl │ ├── matrix_cross_product.hpp │ ├── matrix_cross_product.inl │ ├── matrix_interpolation.hpp │ ├── matrix_interpolation.inl │ ├── matrix_major_storage.hpp │ ├── matrix_major_storage.inl │ ├── matrix_operation.hpp │ ├── matrix_operation.inl │ ├── matrix_query.hpp │ ├── matrix_query.inl │ ├── mixed_product.hpp │ ├── mixed_product.inl │ ├── multiple.hpp │ ├── multiple.inl │ ├── noise.hpp │ ├── norm.hpp │ ├── norm.inl │ ├── normal.hpp │ ├── normal.inl │ ├── normalize_dot.hpp │ ├── normalize_dot.inl │ ├── number_precision.hpp │ ├── number_precision.inl │ ├── ocl_type.hpp │ ├── ocl_type.inl │ ├── optimum_pow.hpp │ ├── optimum_pow.inl │ ├── orthonormalize.hpp │ ├── orthonormalize.inl │ ├── perpendicular.hpp │ ├── perpendicular.inl │ ├── polar_coordinates.hpp │ ├── polar_coordinates.inl │ ├── projection.hpp │ ├── projection.inl │ ├── quaternion.hpp │ ├── quaternion.inl │ ├── random.hpp │ ├── raw_data.hpp │ ├── raw_data.inl │ ├── reciprocal.hpp │ ├── rotate_vector.hpp │ ├── rotate_vector.inl │ ├── simd_mat4.hpp │ ├── simd_mat4.inl │ ├── simd_vec4.hpp │ ├── simd_vec4.inl │ ├── spline.hpp │ ├── spline.inl │ ├── std_based_type.hpp │ ├── std_based_type.inl │ ├── string_cast.hpp │ ├── string_cast.inl │ ├── transform.hpp │ ├── transform.inl │ ├── transform2.hpp │ ├── transform2.inl │ ├── ulp.hpp │ ├── unsigned_int.hpp │ ├── unsigned_int.inl │ ├── vec1.hpp │ ├── vec1.inl │ ├── vector_access.hpp │ ├── vector_access.inl │ ├── vector_angle.hpp │ ├── vector_angle.inl │ ├── vector_query.hpp │ ├── vector_query.inl │ ├── verbose_operator.hpp │ ├── verbose_operator.inl │ ├── wrap.hpp │ └── wrap.inl │ └── virtrev │ └── xstream.hpp ├── Input ├── .gitignore ├── Gestures │ ├── BaseGesture.cpp │ ├── BaseGesture.h │ ├── DoubleTapGesture.cpp │ ├── DoubleTapGesture.h │ ├── GestureManager.cpp │ ├── GestureManager.h │ ├── GestureManager.inl │ ├── Index.h │ ├── SwipeGesture.cpp │ ├── SwipeGesture.h │ ├── TapGesture.cpp │ └── TapGesture.h ├── Index.h ├── InputManager.cpp ├── InputManager.h ├── InputManager.inl ├── PugiXML │ ├── contrib │ │ └── foreach.hpp │ ├── scripts │ │ ├── CMakeLists.txt │ │ ├── premake4.lua │ │ ├── pugixml.xcodeproj │ │ │ └── project.pbxproj │ │ ├── pugixml_airplay.mkf │ │ ├── pugixml_codeblocks.cbp │ │ ├── pugixml_codelite.project │ │ ├── pugixml_vs2005.vcproj │ │ ├── pugixml_vs2005_static.vcproj │ │ ├── pugixml_vs2008.vcproj │ │ ├── pugixml_vs2008_static.vcproj │ │ ├── pugixml_vs2010.vcxproj │ │ └── pugixml_vs2010_static.vcxproj │ └── src │ │ ├── pugiconfig.hpp │ │ ├── pugixml.cpp │ │ └── pugixml.hpp ├── XMLContainer.cpp ├── XMLContainer.h ├── XMLFileParser.cpp ├── XMLFileParser.h ├── XMLFileSerializer.cpp ├── XMLFileSerializer.h └── XMLIndex.h ├── Logger.cpp ├── Logger.h ├── Objects ├── BaseCamera.cpp ├── BaseCamera.h ├── FreeCamera.cpp ├── FreeCamera.h ├── Object.cpp ├── Object.h └── Object.inl ├── Physics └── Collision │ ├── CollisionManager.cpp │ └── CollisionManager.h ├── Platforms └── Windows │ ├── Window.cpp │ ├── Window.h │ └── resource.h ├── Scenes ├── BaseScene.cpp ├── BaseScene.h ├── BaseScene.inl ├── SceneManager.cpp ├── SceneManager.h ├── SceneManager.inl ├── SlideScene.cpp ├── SlideScene.h ├── SplashScreen.cpp ├── SplashScreen.h ├── TiledScene.cpp └── TiledScene.h ├── Sound ├── AudioManager.cpp ├── AudioManager.h ├── BaseSound.cpp ├── BaseSound.h ├── SoundEffect.cpp ├── SoundEffect.h ├── SoundFile.cpp └── SoundFile.h ├── StarEngine.cpp ├── StarEngine.h ├── TimeManager.cpp ├── TimeManager.h ├── defines.h ├── defines2D.h ├── definesAndroid.h ├── definesCrossPlatform.cpp ├── definesCrossPlatform.h ├── definesMath.h ├── definesTypes.h └── definesWindows.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | *.dylib 9 | 10 | # Compiled Static libraries 11 | *.lai 12 | *.la 13 | *.a 14 | 15 | # Microsoft Visual Studios 16 | *.sdf 17 | *.opensdf 18 | *.v11.suo 19 | StarEngine.v11.suo 20 | 21 | # Microsoft Visual Studios Performance analyze files 22 | *.psess 23 | *.vspx 24 | 25 | # Generated Directories 26 | bin/ 27 | gen/ 28 | Debug/ 29 | Release/ 30 | Obj/ 31 | .svn/ 32 | 33 | # batch files 34 | *.bat 35 | 36 | # ignore unwanted files 37 | *.lnk 38 | 39 | # ignore game files 40 | .cproject 41 | .classpath 42 | .project 43 | AndroidManifest.xml 44 | AutomatedDeploy.bat 45 | build.xml 46 | Game.sln 47 | Game.vcxproj 48 | Game.vcxproj.filters 49 | Game.vcxproj.user 50 | ic_launcher-web.png 51 | lint.xml 52 | proguard-project.txt 53 | project.properties 54 | stargame.rc 55 | us.stackdump 56 | Win32Manifest.xml 57 | data/ 58 | 59 | # eclipse build 60 | armeabi/ 61 | 62 | # starengine files 63 | *.star 64 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libs/catch"] 2 | path = libs/catch 3 | url = https://github.com/philsquared/Catch 4 | [submodule "libs/box2d"] 5 | path = libs/box2d 6 | url = https://github.com/StarEngine/Box2D.git 7 | [submodule "libs/sdl2"] 8 | path = libs/sdl2 9 | url = https://github.com/StarEngine/SDL2.git 10 | [submodule "libs/protobuf"] 11 | path = libs/protobuf 12 | url = https://github.com/StarEngine/protobuf.git 13 | [submodule "libs/chaiscript"] 14 | path = libs/chaiscript 15 | url = https://github.com/StarEngine/ChaiScript.git 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: 3 | - gcc 4 | - clang 5 | # Change this to your needs 6 | # script: ./configure && make 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StarEngine/engine/c8ede28ac6a56640f54cb94f8af9c2cb44fb6cf3/LICENSE -------------------------------------------------------------------------------- /src/AI/Pathfinding/SearchCell.cpp: -------------------------------------------------------------------------------- 1 | #include "SearchCell.h" 2 | #include 3 | #include "../../Helpers/Math.h" 4 | 5 | namespace star 6 | { 7 | SearchCell::SearchCell(): 8 | x(0), 9 | y(0), 10 | id(0), 11 | parent(nullptr), 12 | g(0), 13 | h(0) 14 | { 15 | } 16 | 17 | SearchCell::SearchCell(int32 x, int32 y, SearchCell *parent): 18 | x(x), 19 | y(y), 20 | id(y * WORLD_SIZE + x), 21 | parent(parent), 22 | g(0), 23 | h(0) 24 | { 25 | } 26 | 27 | SearchCell::~SearchCell() 28 | { 29 | } 30 | 31 | float32 SearchCell::GetF() const 32 | { 33 | return g + h; 34 | } 35 | 36 | float32 SearchCell::ManhattanDistance(SearchCell *nodeEnd) 37 | { 38 | float32 tempX = static_cast( 39 | fabs(static_cast(x - nodeEnd->x)) 40 | ); 41 | float32 tempY = static_cast( 42 | fabs(static_cast(y - nodeEnd->y)) 43 | ); 44 | 45 | return std::max(tempX, tempY); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/AI/Pathfinding/SearchCell.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "../../defines.h" 4 | 5 | namespace star 6 | { 7 | struct SearchCell 8 | { 9 | int32 x, y, id; 10 | SearchCell* parent; 11 | float32 g, h; //f(x) = g(x) + h(x) 12 | static const int32 WORLD_SIZE = 15; 13 | 14 | SearchCell(); 15 | SearchCell(int32 x, int32 y, SearchCell *parent); 16 | ~SearchCell(); 17 | float32 GetF() const; 18 | float32 ManhattanDistance(SearchCell *nodeEnd); 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /src/Actions/Action.cpp: -------------------------------------------------------------------------------- 1 | #include "Action.h" 2 | #include "../Objects/Object.h" 3 | 4 | namespace star 5 | { 6 | Action::Action() 7 | : Entity() 8 | , m_pParent(nullptr) 9 | , m_IsPaused(false) 10 | , m_IsInitialized(false) 11 | { 12 | 13 | } 14 | 15 | Action::Action(const tstring & name) 16 | : Entity(name) 17 | , m_pParent(nullptr) 18 | , m_IsPaused(false) 19 | , m_IsInitialized(false) 20 | { 21 | 22 | } 23 | 24 | Action::~Action() 25 | { 26 | 27 | } 28 | 29 | void Action::Destroy() 30 | { 31 | m_pParent->RemoveAction(this); 32 | } 33 | 34 | void Action::Restart() 35 | { 36 | m_IsPaused = false; 37 | } 38 | 39 | void Action::Pause() 40 | { 41 | m_IsPaused = true; 42 | } 43 | 44 | void Action::Resume() 45 | { 46 | m_IsPaused = false; 47 | } 48 | 49 | void Action::BaseUpdate(const Context & context) 50 | { 51 | if(!m_IsPaused) 52 | { 53 | Update(context); 54 | } 55 | } 56 | 57 | void Action::BaseInitialize() 58 | { 59 | if(!m_IsInitialized) 60 | { 61 | m_IsInitialized = true; 62 | Initialize(); 63 | } 64 | } 65 | 66 | void Action::SetParent(Object * parent) 67 | { 68 | m_pParent = parent; 69 | } 70 | 71 | Object * Action::GetParent() const 72 | { 73 | return m_pParent; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/Actions/Action.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../Entity.h" 4 | 5 | namespace star 6 | { 7 | class Object; 8 | 9 | class Action : public Entity 10 | { 11 | public: 12 | Action(); 13 | Action(const tstring & name); 14 | 15 | virtual ~Action(); 16 | 17 | void Destroy(); 18 | 19 | virtual void Restart(); 20 | virtual void Pause(); 21 | virtual void Resume(); 22 | 23 | void BaseUpdate(const Context & context); 24 | void BaseInitialize(); 25 | 26 | void SetParent(Object * parent); 27 | Object * GetParent() const; 28 | 29 | protected: 30 | virtual void Initialize() = 0; 31 | virtual void Update(const Context & context) = 0; 32 | 33 | Object *m_pParent; 34 | bool m_IsPaused; 35 | bool m_IsInitialized; 36 | 37 | private: 38 | Action & operator=(const Action&); 39 | Action & operator=(Action&&); 40 | Action(const Action&); 41 | Action(Action&&); 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /src/Actions/DelayedAction.cpp: -------------------------------------------------------------------------------- 1 | #include "DelayedAction.h" 2 | #include "../Helpers/Helpers.h" 3 | #include "../Objects/Object.h" 4 | #include "../Scenes/BaseScene.h" 5 | 6 | namespace star 7 | { 8 | uint64 DelayedAction::ID_COUNTER = 0; 9 | 10 | DelayedAction::DelayedAction(float32 seconds) 11 | : Action() 12 | , m_UniqueID(_T("DA_")) 13 | , m_Seconds(seconds) 14 | , m_Callback(nullptr) 15 | , m_HasStarted(false) 16 | { 17 | m_UniqueID += string_cast(ID_COUNTER++); 18 | } 19 | 20 | DelayedAction::DelayedAction( 21 | const tstring & name, 22 | float32 seconds 23 | ) 24 | : Action(name) 25 | , m_UniqueID(_T("DA_")) 26 | , m_Seconds(seconds) 27 | , m_Callback(nullptr) 28 | , m_HasStarted(false) 29 | { 30 | m_UniqueID += string_cast(ID_COUNTER++); 31 | } 32 | 33 | DelayedAction::~DelayedAction() 34 | { 35 | 36 | } 37 | 38 | void DelayedAction::Initialize() 39 | { 40 | CreateTimer(); 41 | } 42 | 43 | void DelayedAction::Restart() 44 | { 45 | if(!m_HasStarted) 46 | { 47 | m_pParent->GetScene()->GetTimerManager()->ResetTimer( 48 | m_UniqueID, 49 | false 50 | ); 51 | } 52 | else 53 | { 54 | m_HasStarted = false; 55 | CreateTimer(); 56 | } 57 | } 58 | 59 | void DelayedAction::Pause() 60 | { 61 | if(!m_HasStarted) 62 | { 63 | m_pParent->GetScene()->GetTimerManager()->PauseTimer( 64 | m_UniqueID, 65 | true 66 | ); 67 | } 68 | } 69 | 70 | void DelayedAction::Resume() 71 | { 72 | if(!m_HasStarted) 73 | { 74 | m_pParent->GetScene()->GetTimerManager()->PauseTimer( 75 | m_UniqueID, 76 | false 77 | ); 78 | } 79 | } 80 | 81 | void DelayedAction::CreateTimer() 82 | { 83 | m_IsPaused = true; 84 | m_pParent->GetScene()->GetTimerManager()->CreateTimer( 85 | m_UniqueID, m_Seconds, false, false, 86 | [&] () { 87 | if(m_Callback) 88 | { 89 | m_Callback(); 90 | m_IsPaused = false; 91 | m_HasStarted = true; 92 | } 93 | Destroy(); 94 | }, false); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/Actions/DelayedAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Action.h" 4 | #include 5 | 6 | namespace star 7 | { 8 | class Object; 9 | 10 | class DelayedAction : public Action 11 | { 12 | public: 13 | DelayedAction(float32 seconds); 14 | DelayedAction( 15 | const tstring & name, 16 | float32 seconds 17 | ); 18 | 19 | virtual ~DelayedAction(); 20 | 21 | virtual void Initialize(); 22 | 23 | virtual void Restart(); 24 | virtual void Pause(); 25 | virtual void Resume(); 26 | 27 | protected: 28 | std::function m_Callback; 29 | float32 m_Seconds; 30 | 31 | private: 32 | void CreateTimer(); 33 | 34 | static uint64 ID_COUNTER; 35 | tstring m_UniqueID; 36 | bool m_HasStarted; 37 | 38 | DelayedAction & operator=(const DelayedAction&); 39 | DelayedAction & operator=(DelayedAction&&); 40 | DelayedAction(const DelayedAction&); 41 | DelayedAction(DelayedAction&&); 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /src/Actions/DelayedFramesAction.cpp: -------------------------------------------------------------------------------- 1 | #include "DelayedFramesAction.h" 2 | 3 | namespace star 4 | { 5 | DelayedFramesAction::DelayedFramesAction(uint32 nrOfFrames) 6 | : Action() 7 | , m_NumberOfFrames(nrOfFrames) 8 | , m_CurrentNrOfFrames(0) 9 | , m_Callback(nullptr) 10 | { 11 | } 12 | 13 | DelayedFramesAction::DelayedFramesAction(const tstring& name, uint32 nrOfFrames) 14 | : Action(name) 15 | , m_NumberOfFrames(nrOfFrames) 16 | , m_CurrentNrOfFrames(0) 17 | , m_Callback(nullptr) 18 | { 19 | } 20 | 21 | DelayedFramesAction::~DelayedFramesAction() 22 | { 23 | 24 | } 25 | 26 | void DelayedFramesAction::Initialize() 27 | { 28 | 29 | } 30 | 31 | void DelayedFramesAction::Update(const Context & context) 32 | { 33 | if(m_CurrentNrOfFrames == m_NumberOfFrames) 34 | { 35 | if(m_Callback) 36 | { 37 | m_Callback(); 38 | } 39 | Destroy(); 40 | } 41 | ++m_CurrentNrOfFrames; 42 | } 43 | 44 | void DelayedFramesAction::SetCallback(const std::function & callback) 45 | { 46 | m_Callback = callback; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Actions/DelayedFramesAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Action.h" 3 | #include 4 | 5 | namespace star 6 | { 7 | class DelayedFramesAction : public Action 8 | { 9 | public: 10 | DelayedFramesAction(uint32 nrOfFrames = 1); 11 | DelayedFramesAction(const tstring& name, uint32 nrOfFrames = 1); 12 | virtual ~DelayedFramesAction(); 13 | 14 | void SetCallback(const std::function & callback); 15 | 16 | protected: 17 | virtual void Initialize(); 18 | virtual void Update(const Context & context); 19 | 20 | std::function m_Callback; 21 | 22 | private: 23 | uint32 m_NumberOfFrames; 24 | uint32 m_CurrentNrOfFrames; 25 | }; 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/Actions/Index.h: -------------------------------------------------------------------------------- 1 | #include "Action.h" 2 | #include "DelayedFramesAction.h" 3 | #include "DelayedAction.h" 4 | #include "LoopedAction.h" 5 | #include "TimedAction.h" 6 | #include "TimedScaleAction.h" 7 | #include "TimedFadeAction.h" 8 | #include "TimedMoveAction.h" 9 | -------------------------------------------------------------------------------- /src/Actions/LoopedAction.cpp: -------------------------------------------------------------------------------- 1 | #include "LoopedAction.h" 2 | #include "../Helpers/Helpers.h" 3 | #include "../Objects/Object.h" 4 | #include "../Scenes/BaseScene.h" 5 | 6 | namespace star 7 | { 8 | uint64 LoopedAction::ID_COUNTER = 0; 9 | 10 | LoopedAction::LoopedAction(float32 seconds) 11 | : Action() 12 | , m_UniqueID(_T("LA_")) 13 | , m_Seconds(seconds) 14 | , m_Callback(nullptr) 15 | { 16 | m_UniqueID += string_cast(ID_COUNTER++); 17 | } 18 | 19 | LoopedAction::LoopedAction( 20 | const tstring & name, 21 | float32 seconds 22 | ) 23 | : Action(name) 24 | , m_UniqueID(_T("LA_")) 25 | , m_Seconds(seconds) 26 | , m_Callback(nullptr) 27 | { 28 | m_UniqueID += string_cast(ID_COUNTER++); 29 | } 30 | 31 | LoopedAction::~LoopedAction() 32 | { 33 | 34 | } 35 | 36 | void LoopedAction::Initialize() 37 | { 38 | m_pParent->GetScene()->GetTimerManager()->CreateTimer( 39 | m_UniqueID, m_Seconds, false, true, 40 | [&] () { 41 | if(m_Callback) 42 | { 43 | m_Callback(); 44 | } 45 | }); 46 | } 47 | 48 | void LoopedAction::Restart() 49 | { 50 | m_pParent->GetScene()->GetTimerManager()->ResetTimer( 51 | m_UniqueID, 52 | false 53 | ); 54 | } 55 | 56 | void LoopedAction::Pause() 57 | { 58 | m_pParent->GetScene()->GetTimerManager()->PauseTimer( 59 | m_UniqueID, 60 | true 61 | ); 62 | } 63 | 64 | void LoopedAction::Resume() 65 | { 66 | m_pParent->GetScene()->GetTimerManager()->PauseTimer( 67 | m_UniqueID, 68 | false 69 | ); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Actions/LoopedAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Action.h" 4 | #include 5 | 6 | namespace star 7 | { 8 | class Object; 9 | 10 | class LoopedAction : public Action 11 | { 12 | public: 13 | LoopedAction(float32 seconds); 14 | LoopedAction( 15 | const tstring & name, 16 | float32 seconds 17 | ); 18 | 19 | virtual ~LoopedAction(); 20 | 21 | virtual void Initialize(); 22 | 23 | virtual void Restart(); 24 | virtual void Pause(); 25 | virtual void Resume(); 26 | 27 | protected: 28 | std::function m_Callback; 29 | float32 m_Seconds; 30 | 31 | private: 32 | static uint64 ID_COUNTER; 33 | tstring m_UniqueID; 34 | 35 | LoopedAction & operator=(const LoopedAction&); 36 | LoopedAction & operator=(LoopedAction&&); 37 | LoopedAction(const LoopedAction&); 38 | LoopedAction(LoopedAction&&); 39 | }; 40 | } 41 | -------------------------------------------------------------------------------- /src/Actions/ScaleAction.cpp: -------------------------------------------------------------------------------- 1 | #include "ScaleAction.h" 2 | #include "../Objects/Object.h" 3 | #include "../Helpers/Math.h" 4 | 5 | namespace star 6 | { 7 | ScaleAction::ScaleAction( 8 | float32 seconds, 9 | float32 begin, 10 | float32 end, 11 | const std::function & callback 12 | ) 13 | : TimedAction(seconds, callback) 14 | , m_BeginValue(begin) 15 | , m_EndValue(end) 16 | , m_CurrentSeconds(0) 17 | { 18 | } 19 | 20 | ScaleAction::ScaleAction( 21 | const tstring & name, 22 | float32 seconds, 23 | float32 begin, 24 | float32 end, 25 | const std::function & callback 26 | ) 27 | : TimedAction(name, seconds, callback) 28 | , m_BeginValue(begin) 29 | , m_EndValue(end) 30 | , m_CurrentSeconds(0) 31 | { 32 | } 33 | 34 | ScaleAction::~ScaleAction() 35 | { 36 | } 37 | 38 | void ScaleAction::Update(const Context & context) 39 | { 40 | float32 dt = float32(context.time->DeltaTime().GetSeconds()); 41 | m_CurrentSeconds += dt; 42 | 43 | m_pParent->GetTransform()->Scale 44 | ( 45 | star::Lerp(m_BeginValue, m_EndValue, m_CurrentSeconds / m_Seconds) 46 | ); 47 | } 48 | 49 | void ScaleAction::Restart() 50 | { 51 | m_CurrentSeconds = 0; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Actions/ScaleAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "TimedAction.h" 4 | 5 | namespace star 6 | { 7 | class ScaleAction : public TimedAction 8 | { 9 | public: 10 | ScaleAction( 11 | float32 seconds, 12 | float32 begin, 13 | float32 end, 14 | const std::function & callback = nullptr 15 | ); 16 | 17 | ScaleAction( 18 | const tstring & name, 19 | float32 seconds, 20 | float32 begin, 21 | float32 end, 22 | const std::function & callback = nullptr 23 | ); 24 | 25 | virtual ~ScaleAction(void); 26 | 27 | virtual void Restart(); 28 | 29 | protected: 30 | virtual void Update(const Context& context); 31 | 32 | float32 m_CurrentSeconds, 33 | m_BeginValue, 34 | m_EndValue; 35 | 36 | private: 37 | ScaleAction & operator=(const ScaleAction&); 38 | ScaleAction & operator=(ScaleAction&&); 39 | ScaleAction(const ScaleAction&); 40 | ScaleAction(ScaleAction&&); 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /src/Actions/TimedAction.cpp: -------------------------------------------------------------------------------- 1 | #include "TimedAction.h" 2 | #include "../Helpers/Helpers.h" 3 | #include "../Objects/Object.h" 4 | #include "../Scenes/BaseScene.h" 5 | 6 | namespace star 7 | { 8 | uint64 TimedAction::ID_COUNTER = 0; 9 | 10 | TimedAction::TimedAction( 11 | float32 seconds, 12 | const std::function & callback 13 | ) 14 | : Action() 15 | , m_UniqueID(_T("TA_")) 16 | , m_Seconds(seconds) 17 | , m_Callback(callback) 18 | { 19 | m_UniqueID += string_cast(ID_COUNTER++); 20 | } 21 | 22 | TimedAction::TimedAction( 23 | const tstring & name, 24 | float32 seconds, 25 | const std::function & callback 26 | ) 27 | : Action(name) 28 | , m_UniqueID(_T("TA_")) 29 | , m_Seconds(seconds) 30 | , m_Callback(callback) 31 | { 32 | m_UniqueID += string_cast(ID_COUNTER++); 33 | } 34 | 35 | TimedAction::~TimedAction() 36 | { 37 | 38 | } 39 | 40 | void TimedAction::Initialize() 41 | { 42 | m_pParent->GetScene()->GetTimerManager()->CreateTimer( 43 | m_UniqueID, m_Seconds, false, false, 44 | [&] () { 45 | if(m_Callback) 46 | { 47 | m_Callback(); 48 | } 49 | Destroy(); 50 | }); 51 | } 52 | 53 | void TimedAction::Restart() 54 | { 55 | m_pParent->GetScene()->GetTimerManager()->ResetTimer( 56 | m_UniqueID, 57 | false 58 | ); 59 | } 60 | 61 | void TimedAction::Pause() 62 | { 63 | m_pParent->GetScene()->GetTimerManager()->PauseTimer( 64 | m_UniqueID, 65 | true 66 | ); 67 | } 68 | 69 | void TimedAction::Resume() 70 | { 71 | m_pParent->GetScene()->GetTimerManager()->PauseTimer( 72 | m_UniqueID, 73 | false 74 | ); 75 | } 76 | 77 | void TimedAction::SetCallback(const std::function & callback) 78 | { 79 | m_Callback = callback; 80 | if(m_pParent && m_pParent->GetScene()) 81 | { 82 | m_pParent->GetScene()->GetTimerManager()->SetFunctionTimer( 83 | m_UniqueID, 84 | m_Callback 85 | ); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/Actions/TimedAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Action.h" 4 | #include 5 | 6 | namespace star 7 | { 8 | class TimedAction : public Action 9 | { 10 | public: 11 | TimedAction( 12 | float32 seconds, 13 | const std::function & callback = nullptr 14 | ); 15 | TimedAction( 16 | const tstring & name, 17 | float32 seconds, 18 | const std::function & callback = nullptr 19 | ); 20 | 21 | virtual ~TimedAction(); 22 | 23 | virtual void Initialize(); 24 | 25 | virtual void Restart(); 26 | virtual void Pause(); 27 | virtual void Resume(); 28 | 29 | void SetCallback(const std::function & callback); 30 | 31 | protected: 32 | std::function m_Callback; 33 | float32 m_Seconds; 34 | 35 | private: 36 | static uint64 ID_COUNTER; 37 | tstring m_UniqueID; 38 | 39 | TimedAction & operator=(const TimedAction&); 40 | TimedAction & operator=(TimedAction&&); 41 | TimedAction(const TimedAction&); 42 | TimedAction(TimedAction&&); 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /src/Actions/TimedFadeAction.cpp: -------------------------------------------------------------------------------- 1 | #include "TimedFadeAction.h" 2 | #include "../Objects/Object.h" 3 | #include "../Helpers/Math.h" 4 | #include "../Components/Graphics/SpriteComponent.h" 5 | 6 | namespace star 7 | { 8 | TimedFadeAction::TimedFadeAction( 9 | float32 seconds, 10 | const Color & begin, 11 | const Color & end, 12 | const std::function & callback 13 | ) 14 | : TimedAction(seconds, callback) 15 | , m_StartColor(begin) 16 | , m_EndColor(end) 17 | , m_CurrentSeconds(0) 18 | , m_pSpriteComponent(nullptr) 19 | { 20 | 21 | } 22 | 23 | TimedFadeAction::TimedFadeAction( 24 | const tstring & name, 25 | float32 seconds, 26 | const Color & begin, 27 | const Color & end, 28 | const std::function & callback 29 | ) 30 | : TimedAction(name, seconds, callback) 31 | , m_StartColor(begin) 32 | , m_EndColor(end) 33 | , m_CurrentSeconds(0) 34 | , m_pSpriteComponent(nullptr) 35 | { 36 | 37 | } 38 | 39 | TimedFadeAction::~TimedFadeAction() 40 | { 41 | 42 | } 43 | 44 | void TimedFadeAction::Initialize() 45 | { 46 | m_pSpriteComponent = m_pParent->GetComponent(); 47 | ASSERT_LOG(m_pSpriteComponent != nullptr, 48 | _T("TimedFadeAction::Initialize: TimedFadeAction needs a SpriteComponent to work!"), 49 | STARENGINE_LOG_TAG); 50 | m_pSpriteComponent->SetColorMultiplier(m_StartColor); 51 | 52 | TimedAction::Initialize(); 53 | } 54 | 55 | void TimedFadeAction::Update(const Context & context) 56 | { 57 | float32 dt = float32(context.time->DeltaTime().GetSeconds()); 58 | m_CurrentSeconds += dt; 59 | m_pSpriteComponent->SetColorMultiplier( 60 | Lerp(m_StartColor, m_EndColor, m_CurrentSeconds / m_Seconds) 61 | ); 62 | } 63 | 64 | void TimedFadeAction::Restart() 65 | { 66 | m_pSpriteComponent->SetColorMultiplier(m_StartColor); 67 | m_CurrentSeconds = 0; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Actions/TimedFadeAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "TimedAction.h" 4 | #include "../Graphics/Color.h" 5 | 6 | namespace star 7 | { 8 | class SpriteComponent; 9 | 10 | class TimedFadeAction : public TimedAction 11 | { 12 | public: 13 | TimedFadeAction( 14 | float32 seconds, 15 | const Color & begin, 16 | const Color & end, 17 | const std::function & callback = nullptr 18 | ); 19 | 20 | TimedFadeAction( 21 | const tstring & name, 22 | float32 seconds, 23 | const Color & begin, 24 | const Color & end, 25 | const std::function & callback = nullptr 26 | ); 27 | 28 | virtual ~TimedFadeAction(); 29 | 30 | virtual void Restart(); 31 | 32 | protected: 33 | virtual void Initialize(); 34 | virtual void Update(const Context & context); 35 | 36 | Color m_StartColor, m_EndColor; 37 | float32 m_CurrentSeconds; 38 | SpriteComponent * m_pSpriteComponent; 39 | 40 | private: 41 | TimedFadeAction & operator=(const TimedFadeAction&); 42 | TimedFadeAction & operator=(TimedFadeAction&&); 43 | TimedFadeAction(const TimedFadeAction&); 44 | TimedFadeAction(TimedFadeAction&&); 45 | }; 46 | } 47 | -------------------------------------------------------------------------------- /src/Actions/TimedMoveAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "TimedAction.h" 4 | 5 | namespace star 6 | { 7 | class TimedMoveAction : public TimedAction 8 | { 9 | public: 10 | TimedMoveAction( 11 | float32 seconds, 12 | const vec2 & target, 13 | const std::function & callback = nullptr 14 | ); 15 | 16 | TimedMoveAction( 17 | const tstring & name, 18 | float32 seconds, 19 | const vec2 & target, 20 | const std::function & callback = nullptr 21 | ); 22 | 23 | TimedMoveAction( 24 | float32 seconds, 25 | const vec2 & direction, 26 | float32 speed, 27 | const std::function & callback = nullptr 28 | ); 29 | 30 | TimedMoveAction( 31 | const tstring & name, 32 | float32 seconds, 33 | const vec2 & direction, 34 | float32 speed, 35 | const std::function & callback = nullptr 36 | ); 37 | 38 | virtual ~TimedMoveAction(); 39 | 40 | void SetStartPosition(const vec2 & pos); 41 | 42 | virtual void Restart(); 43 | 44 | protected: 45 | virtual void Initialize(); 46 | virtual void Update(const Context & context); 47 | 48 | vec2 m_Direction, m_Target, m_StartPosition; 49 | float32 m_Speed, m_CurrentSeconds; 50 | 51 | private: 52 | bool m_StartPosSet; 53 | 54 | TimedMoveAction & operator=(const TimedMoveAction&); 55 | TimedMoveAction & operator=(TimedMoveAction&&); 56 | TimedMoveAction(const TimedMoveAction&); 57 | TimedMoveAction(TimedMoveAction&&); 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /src/Actions/TimedScaleAction.cpp: -------------------------------------------------------------------------------- 1 | #include "TimedScaleAction.h" 2 | #include "../Objects/Object.h" 3 | #include "../Helpers/Math.h" 4 | 5 | namespace star 6 | { 7 | TimedScaleAction::TimedScaleAction( 8 | float32 seconds, 9 | float32 begin, 10 | float32 end, 11 | const std::function & callback 12 | ) 13 | : TimedAction(seconds, callback) 14 | , m_BeginValue(begin) 15 | , m_EndValue(end) 16 | , m_CurrentSeconds(0) 17 | { 18 | } 19 | 20 | TimedScaleAction::TimedScaleAction( 21 | const tstring & name, 22 | float32 seconds, 23 | float32 begin, 24 | float32 end, 25 | const std::function & callback 26 | ) 27 | : TimedAction(name, seconds, callback) 28 | , m_BeginValue(begin) 29 | , m_EndValue(end) 30 | , m_CurrentSeconds(0) 31 | { 32 | } 33 | 34 | TimedScaleAction::~TimedScaleAction() 35 | { 36 | } 37 | 38 | void TimedScaleAction::Update(const Context & context) 39 | { 40 | float32 dt = float32(context.time->DeltaTime().GetSeconds()); 41 | m_CurrentSeconds += dt; 42 | 43 | m_pParent->GetTransform()->Scale 44 | ( 45 | star::Lerp(m_BeginValue, m_EndValue, m_CurrentSeconds / m_Seconds) 46 | ); 47 | } 48 | 49 | void TimedScaleAction::Restart() 50 | { 51 | m_CurrentSeconds = 0; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Actions/TimedScaleAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "TimedAction.h" 4 | 5 | namespace star 6 | { 7 | class TimedScaleAction : public TimedAction 8 | { 9 | public: 10 | TimedScaleAction( 11 | float32 seconds, 12 | float32 begin, 13 | float32 end, 14 | const std::function & callback = nullptr 15 | ); 16 | 17 | TimedScaleAction( 18 | const tstring & name, 19 | float32 seconds, 20 | float32 begin, 21 | float32 end, 22 | const std::function & callback = nullptr 23 | ); 24 | 25 | virtual ~TimedScaleAction(void); 26 | 27 | virtual void Restart(); 28 | 29 | protected: 30 | virtual void Update(const Context& context); 31 | 32 | float32 m_CurrentSeconds, 33 | m_BeginValue, 34 | m_EndValue; 35 | 36 | private: 37 | TimedScaleAction & operator=(const TimedScaleAction&); 38 | TimedScaleAction & operator=(TimedScaleAction&&); 39 | TimedScaleAction(const TimedScaleAction&); 40 | TimedScaleAction(TimedScaleAction&&); 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /src/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LS_CPP=$(subst $(1)/,,$(wildcard $(1)/*.cpp)) 6 | LS_CPP+= $(subst $(1)/,,$(wildcard $(1)/**/*.cpp)) 7 | LS_CPP+= $(subst $(1)/,,$(wildcard $(1)/**/**/*.cpp)) 8 | LS_CPP+= $(subst $(1)/,,$(wildcard $(1)/**/**/**/*.cpp)) 9 | 10 | LOCAL_MODULE := starengine 11 | LOCAL_CFLAGS := -D FT_FREETYPE_H="freetype/freetype.h" 12 | LOCAL_CPPFLAGS := -std=gnu++11 -D STAR2D=1 -D LOGGER_MIN_LEVEL=1 -Ilibs\freetype\jni\include -Ilibs\libpng 13 | LOCAL_SRC_FILES := $(call LS_CPP,$(LOCAL_PATH)) 14 | 15 | LOCAL_STATIC_LIBRARIES := android_native_app_glue freetype libpng 16 | 17 | include $(BUILD_STATIC_LIBRARY) 18 | 19 | $(call import-module,android/native_app_glue) 20 | 21 | $(call import-add-path,libs) 22 | 23 | $(call import-module,freetype) 24 | $(call import-module,libpng) -------------------------------------------------------------------------------- /src/Application.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | NDK_TOOLCHAIN_VERSION=4.8 5 | APP_STL:=gnustl_static 6 | APP_CFLAGS += -Wno-error=format-security 7 | APP_GNUSTL_FORCE_CPP_FEATURES := exceptions rtti -------------------------------------------------------------------------------- /src/BaseGame.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "defines.h" 4 | 5 | namespace star 6 | { 7 | struct Context; 8 | 9 | class BaseGame 10 | { 11 | public: 12 | BaseGame() {} 13 | virtual ~BaseGame() {} 14 | 15 | virtual void Initialize(int32, int32) = 0; 16 | 17 | virtual void Draw() = 0; 18 | virtual void Update(const Context &) = 0; 19 | 20 | virtual void End() = 0; 21 | 22 | private: 23 | BaseGame & operator=(const BaseGame&); 24 | BaseGame & operator=(BaseGame&&); 25 | BaseGame(const BaseGame &); 26 | BaseGame(BaseGame &&); 27 | }; 28 | } -------------------------------------------------------------------------------- /src/Components/AI/PathFindNodeComponent.cpp: -------------------------------------------------------------------------------- 1 | #include "PathFindNodeComponent.h" 2 | #include "../../Logger.h" 3 | #include "../../AI/Pathfinding/PathFindManager.h" 4 | 5 | namespace star 6 | { 7 | PathFindNodeComponent::PathFindNodeComponent(): 8 | BaseComponent() 9 | { 10 | 11 | } 12 | 13 | PathFindNodeComponent::~PathFindNodeComponent(void) 14 | { 15 | } 16 | 17 | void PathFindNodeComponent::InitializeComponent() 18 | { 19 | PathFindManager::GetInstance()->AddObject(m_pParentObject); 20 | } 21 | 22 | void PathFindNodeComponent::Update(const Context& context) 23 | { 24 | 25 | } 26 | 27 | void PathFindNodeComponent::Draw() 28 | { 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Components/AI/PathFindNodeComponent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../BaseComponent.h" 3 | #include "../../defines.h" 4 | #include "../../Helpers/Rect.h" 5 | 6 | namespace star 7 | { 8 | struct Context; 9 | 10 | class PathFindNodeComponent final: public BaseComponent 11 | { 12 | public: 13 | PathFindNodeComponent(); 14 | ~PathFindNodeComponent(void); 15 | 16 | void Update(const Context& context); 17 | void Draw(); 18 | 19 | protected: 20 | void InitializeComponent(); 21 | 22 | PathFindNodeComponent(const PathFindNodeComponent& t); 23 | PathFindNodeComponent(PathFindNodeComponent&& t); 24 | PathFindNodeComponent& operator=(const PathFindNodeComponent& t); 25 | PathFindNodeComponent& operator=(PathFindNodeComponent&& t); 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /src/Components/AI/index.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "PathFindNodeComponent.h" -------------------------------------------------------------------------------- /src/Components/CameraComponent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "..\defines.h" 3 | #include "BaseComponent.h" 4 | 5 | namespace star 6 | { 7 | class CameraComponent : public BaseComponent 8 | { 9 | public: 10 | CameraComponent(); 11 | virtual ~CameraComponent(void); 12 | 13 | virtual void Update(const Context& context); 14 | virtual void Draw(); 15 | 16 | void SetFieldOfView(float32 fov); 17 | void SetOrthoSize(float32 size); 18 | void SetNearClippingPlane(float32 nearPlane); 19 | void SetFarClippingPlane(float32 farPlane); 20 | 21 | void SetActive(); 22 | bool IsActive() const; 23 | void Activate(); 24 | void Deactivate(); 25 | 26 | void SetZoom(float32 zoom); 27 | float32 GetZoom() const; 28 | 29 | const mat4 & GetView() const; 30 | const mat4 & GetProjection() const; 31 | const mat4 & GetViewInverse() const; 32 | mat4 GetProjectionViewInverse() const; 33 | 34 | void Translate(const vec2& translation); 35 | void Translate(float32 x, float32 y); 36 | void TranslateX(float32 x); 37 | void TranslateY(float32 y); 38 | 39 | void ConvertScreenToWorld(vec2 & posInOut); 40 | 41 | protected: 42 | virtual void InitializeComponent(); 43 | 44 | private: 45 | mat4 MatrixPerspectiveFOV(float32 FovY, float32 ratio, float32 nearPlane, float32 farPlane); 46 | mat4 MatrixOrtho(float32 width, float32 height, float32 nearPlane, float32 farPlane); 47 | mat4 MatrixLookAt(const vec3& eye, const vec3& at, const vec3& up); 48 | 49 | mat4 m_Projection, 50 | m_View, 51 | m_ViewInverse; 52 | 53 | float32 m_FarPlane, 54 | m_NearPlane, 55 | m_FOV, 56 | m_Size, 57 | m_Zoom, 58 | m_AspectRatio; 59 | 60 | bool m_bIsActive, 61 | m_bPerspectiveProjection; 62 | 63 | CameraComponent(const CameraComponent& t); 64 | CameraComponent(CameraComponent&& t); 65 | CameraComponent& operator=(const CameraComponent& t); 66 | CameraComponent& operator=(CameraComponent&& t); 67 | }; 68 | } 69 | -------------------------------------------------------------------------------- /src/Components/Physics/BaseColliderComponent.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StarEngine/engine/c8ede28ac6a56640f54cb94f8af9c2cb44fb6cf3/src/Components/Physics/BaseColliderComponent.cpp -------------------------------------------------------------------------------- /src/Components/Physics/RectangleColliderComponent.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StarEngine/engine/c8ede28ac6a56640f54cb94f8af9c2cb44fb6cf3/src/Components/Physics/RectangleColliderComponent.cpp -------------------------------------------------------------------------------- /src/Components/Physics/index.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BaseColliderComponent.h" 4 | 5 | #include "CircleColliderComponent.h" 6 | #include "RectangleColliderComponent.h" -------------------------------------------------------------------------------- /src/Console.cpp: -------------------------------------------------------------------------------- 1 | #include "Console.h" 2 | #include "jni\defines.h" 3 | 4 | namespace star_w 5 | { 6 | static const WORD MAX_CONSOLE_LINES = 500; 7 | 8 | void RedirectIOToConsole() 9 | { 10 | int32 hConHandle; 11 | long lStdHandle; 12 | 13 | CONSOLE_SCREEN_BUFFER_INFO conInfo; 14 | FILE * fp; 15 | 16 | // allocate a console for this app 17 | 18 | AllocConsole(); 19 | 20 | // set the screen buffer to be big enough to let us scroll text 21 | 22 | GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &conInfo); 23 | conInfo.dwSize.Y = MAX_CONSOLE_LINES; 24 | SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), 25 | conInfo.dwSize); 26 | 27 | // redirect unbuffered STDOUT to the console 28 | 29 | lStdHandle = long(GetStdHandle(STD_OUTPUT_HANDLE)); 30 | hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); 31 | fp = _fdopen(hConHandle, "w"); 32 | *stdout = *fp; 33 | setvbuf(stdout, NULL, _IONBF, 0); 34 | 35 | // redirect unbuffered STDIN to the console 36 | 37 | lStdHandle = long(GetStdHandle(STD_INPUT_HANDLE)); 38 | hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); 39 | fp = _fdopen(hConHandle, "r"); 40 | *stdin = *fp; 41 | setvbuf(stdin, NULL, _IONBF, 0); 42 | 43 | // redirect unbuffered STDERR to the console 44 | 45 | lStdHandle = long(GetStdHandle(STD_ERROR_HANDLE)); 46 | hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); 47 | fp = _fdopen(hConHandle, "w"); 48 | *stderr = *fp; 49 | setvbuf(stderr, NULL, _IONBF, 0); 50 | 51 | // make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog 52 | // point to console as well 53 | 54 | std::ios::sync_with_stdio(); 55 | } 56 | 57 | void CleanUpConsole() 58 | { 59 | FreeConsole(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Console.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include //MT 4 | #include //rand() 5 | #include //file info 6 | #include //CComPtr 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace star_w 13 | { 14 | void RedirectIOToConsole(); 15 | void CleanUpConsole(); 16 | } 17 | -------------------------------------------------------------------------------- /src/Context.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "TimeManager.h" 4 | #include "Helpers/Time.h" 5 | #include "Graphics/TextureManager.h" 6 | 7 | namespace star 8 | { 9 | /// 10 | /// Struct that is used to pass around information between all the 11 | /// update functions in the engine classes. 12 | /// 13 | /// 14 | struct Context 15 | { 16 | TimeManager * time; 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /src/Entity.cpp: -------------------------------------------------------------------------------- 1 | #include "Entity.h" 2 | 3 | namespace star 4 | { 5 | Entity::Entity() 6 | : m_Name(EMPTY_STRING) 7 | { 8 | 9 | } 10 | 11 | Entity::Entity(const tstring & name) 12 | : m_Name(name) 13 | { 14 | 15 | } 16 | 17 | Entity::~Entity() 18 | { 19 | 20 | } 21 | 22 | const tstring & Entity::GetName() const 23 | { 24 | return m_Name.GetTag(); 25 | } 26 | 27 | void Entity::SetName(const tstring & name) 28 | { 29 | m_Name.SetTag(name); 30 | } 31 | 32 | bool Entity::CompareName(const tstring & name) 33 | { 34 | return m_Name == name; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Entity.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "defines.h" 4 | #include "Helpers/HashTag.h" 5 | 6 | namespace star 7 | { 8 | class Entity 9 | { 10 | public: 11 | Entity(); 12 | Entity(const tstring & name); 13 | virtual ~Entity(); 14 | 15 | const tstring & GetName() const; 16 | void SetName(const tstring & name); 17 | bool CompareName(const tstring & name); 18 | 19 | virtual void Destroy() = 0; 20 | 21 | protected: 22 | HashTag m_Name; 23 | 24 | private: 25 | Entity(const Entity&); 26 | Entity(Entity&&); 27 | Entity & operator=(const Entity&); 28 | Entity & operator=(Entity&&); 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /src/EventLoop.h: -------------------------------------------------------------------------------- 1 | #ifdef ANDROID 2 | 3 | #pragma once 4 | 5 | #include "defines.h" 6 | #include 7 | #include "BaseGame.h" 8 | #include "Context.h" 9 | #include "TimeManager.h" 10 | 11 | namespace star 12 | { 13 | class SceneManager; 14 | 15 | class EventLoop final 16 | { 17 | public: 18 | ~EventLoop(); 19 | 20 | static EventLoop * GetInstance(); 21 | 22 | void Run(); 23 | void End(); 24 | 25 | void Initialize(android_app* pApplication, BaseGame * pBaseGame); 26 | const android_app * GetAndroidApp() const; 27 | 28 | protected: 29 | 30 | private: 31 | static EventLoop *mEventLoop; 32 | 33 | bool mMainGameInitialized; 34 | bool mEnabled; 35 | bool mQuit; 36 | BaseGame* mMainGame; 37 | Context mContext; 38 | android_app* mApplicationPtr; 39 | 40 | EventLoop(); 41 | 42 | static void activityCallback(android_app* pApplication, int32_t pCommand); 43 | static int32 inputCallback(android_app* pApplication, AInputEvent* pEvent); 44 | }; 45 | } 46 | #endif 47 | -------------------------------------------------------------------------------- /src/Graphics/Color.inl: -------------------------------------------------------------------------------- 1 | #include "../defines.h" 2 | 3 | namespace star 4 | { 5 | template 6 | Color & Color::operator*=(T x) 7 | { 8 | r *= x; 9 | g *= x; 10 | b *= x; 11 | a *= x; 12 | return *this; 13 | } 14 | 15 | template 16 | Color & Color::operator/=(T x) 17 | { 18 | r /= x; 19 | g /= x; 20 | b /= x; 21 | a /= x; 22 | return *this; 23 | } 24 | 25 | template 26 | Color Color::operator*(T x) 27 | { 28 | Color color(*this); 29 | color.r *= x; 30 | color.g *= x; 31 | color.b *= x; 32 | color.a *= x; 33 | return color; 34 | } 35 | 36 | template 37 | Color Color::operator/(T x) 38 | { 39 | Color color(*this); 40 | color.r /= x; 41 | color.g /= x; 42 | color.b /= x; 43 | color.a /= x; 44 | return color; 45 | } 46 | 47 | template 48 | Color operator*(T x, const Color & op2) 49 | { 50 | Color color(op2); 51 | color.r *= x; 52 | color.g *= x; 53 | color.b *= x; 54 | color.a *= x; 55 | return color; 56 | } 57 | 58 | template 59 | Color operator/(T x, const Color & op2) 60 | { 61 | Color color(op2); 62 | color.r /= x; 63 | color.g /= x; 64 | color.b /= x; 65 | color.a /= x; 66 | return color; 67 | } 68 | 69 | template 70 | T Color::FloatToInteger(U yRef) const 71 | { 72 | return T( 255 * yRef ); 73 | } 74 | 75 | template 76 | T Color::IntegerToFloat(U yRef) const 77 | { 78 | return T(yRef) / T(255); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Graphics/Font.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "../defines.h" 5 | #include "../Helpers/FilePath.h" 6 | #include "../Helpers/Helpers.h" 7 | 8 | #include "ft2build.h" 9 | #include "freetype/freetype.h" 10 | 11 | #ifdef DESKTOP 12 | #include 13 | #else 14 | #include 15 | #include 16 | #endif 17 | 18 | namespace star 19 | { 20 | #define FONT_DPI 96 21 | #define FONT_TEXTURES 128 22 | 23 | struct CharacterInfo 24 | { 25 | CharacterInfo() 26 | : vertexDimensions() 27 | , uvDimensions() 28 | , letterDimensions() 29 | { 30 | 31 | } 32 | 33 | vec2 vertexDimensions, 34 | uvDimensions; 35 | ivec2 letterDimensions; 36 | 37 | }; 38 | 39 | class Font 40 | { 41 | public: 42 | Font(); 43 | ~Font(); 44 | 45 | bool Init(const tstring& path, uint32 size, FT_Library& library); 46 | void DeleteFont(); 47 | 48 | const tstring & GetFontPath() const; 49 | 50 | GLuint* GetTextures() const; 51 | uint32 GetFontSize() const; 52 | 53 | const std::unordered_map& GetCharacterInfoMap() const; 54 | const CharacterInfo& GetCharacterInfo(suchar character) const; 55 | int32 GetMaxLetterHeight() const; 56 | int32 GetMinLetterHeight() const; 57 | uint32 GetStringLength(const tstring& string) const; 58 | 59 | private: 60 | void Make_D_List(FT_Face face, suchar ch,GLuint * tex_base); 61 | int32 NextPowerOfTwo(int32 number) const; 62 | 63 | tstring m_FontPath; 64 | FT_Face mFace; 65 | GLuint* mTextures; 66 | int32 mMaxLetterHeight, 67 | mMinLetterHeight; 68 | 69 | #ifdef ANDROID 70 | BYTE* mFontBuffer; 71 | #endif 72 | std::unordered_map mCharacterInfoMap; 73 | uint32 mSize; 74 | }; 75 | } 76 | -------------------------------------------------------------------------------- /src/Graphics/FontManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "../defines.h" 6 | #include "../Helpers/Helpers.h" 7 | #include "../Helpers/Singleton.h" 8 | #include "Font.h" 9 | #include "../Components/TransformComponent.h" 10 | #include "../Graphics/Color.h" 11 | #include "../Graphics/Shader.h" 12 | 13 | #include "ft2build.h" 14 | #include "freetype/freetype.h" 15 | 16 | #ifdef DESKTOP 17 | #include 18 | #else 19 | #include 20 | #include 21 | #endif 22 | 23 | namespace star 24 | { 25 | class FilePath; 26 | 27 | class FontManager final : public Singleton 28 | { 29 | public: 30 | friend Singleton; 31 | 32 | bool LoadFont( 33 | const tstring& path, 34 | const tstring& name, 35 | uint32 size 36 | ); 37 | 38 | const Font* GetFont(const tstring& name); 39 | bool DeleteFont(const tstring& name); 40 | void EraseFonts(); 41 | void SplitIntoLines( 42 | std::vector &list, 43 | const sstring &string 44 | ); 45 | 46 | private: 47 | FT_Library mLibrary; 48 | 49 | std::map mFontList; 50 | 51 | FontManager(); 52 | ~FontManager(); 53 | 54 | void SplitString( 55 | std::vector& wordArrayIn, 56 | const tstring& stringIn, 57 | const tstring& delimiter 58 | ); 59 | 60 | FontManager(const FontManager& yRef); 61 | FontManager(FontManager&& yRef); 62 | FontManager& operator=(const FontManager& yRef); 63 | FontManager& operator=(FontManager&& yRef); 64 | }; 65 | } 66 | -------------------------------------------------------------------------------- /src/Graphics/Resource.cpp: -------------------------------------------------------------------------------- 1 | #include "Resource.h" 2 | //#include "../EventLoop.h" 3 | #include "../Logger.h" 4 | #include "../StarEngine.h" 5 | namespace star 6 | { 7 | Resource::Resource(const tstring & pPath): 8 | mPath(pPath), 9 | mAsset(NULL) 10 | { 11 | } 12 | 13 | const tstring & Resource::GetPath() const 14 | { 15 | return mPath; 16 | } 17 | 18 | bool Resource::Open() 19 | { 20 | mAsset = AAssetManager_open( 21 | StarEngine::GetInstance()->GetAndroidApp()->activity->assetManager, 22 | mPath.c_str(), 23 | AASSET_MODE_UNKNOWN 24 | ); 25 | return mAsset != NULL; 26 | } 27 | 28 | void Resource::Close() 29 | { 30 | if(mAsset != NULL) 31 | { 32 | AAsset_close(mAsset); 33 | mAsset = NULL; 34 | } 35 | } 36 | 37 | bool Resource::Read(void* pBuffer, size_t pCount) 38 | { 39 | int32_t lReadCount = AAsset_read(mAsset, pBuffer, pCount); 40 | return lReadCount == pCount; 41 | } 42 | 43 | off_t Resource::GetLength() const 44 | { 45 | return AAsset_getLength(mAsset); 46 | } 47 | 48 | const void* Resource::GetBufferize() const 49 | { 50 | return AAsset_getBuffer(mAsset); 51 | } 52 | 53 | ResourceDescriptor Resource::DeScript() 54 | { 55 | ResourceDescriptor lDescriptor = { -1, 0, 0 }; 56 | AAsset* lAsset = AAssetManager_open( 57 | StarEngine::GetInstance()->GetAndroidApp()->activity->assetManager, 58 | mPath.c_str(), 59 | AASSET_MODE_UNKNOWN); 60 | if(lAsset != NULL) 61 | { 62 | lDescriptor.mDescriptor = AAsset_openFileDescriptor( 63 | lAsset, 64 | &lDescriptor.mStart, 65 | &lDescriptor.mLength 66 | ); 67 | AAsset_close(lAsset); 68 | } 69 | return lDescriptor; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Graphics/Resource.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef _WIN32 4 | 5 | #include "../defines.h" 6 | #include 7 | 8 | class EventLoop; 9 | 10 | namespace star 11 | { 12 | struct ResourceDescriptor 13 | { 14 | int32 mDescriptor; 15 | off_t mStart; 16 | off_t mLength; 17 | }; 18 | 19 | class Resource 20 | { 21 | public: 22 | Resource(const tstring & pPath); 23 | 24 | const tstring & GetPath() const; 25 | 26 | bool Open(); 27 | void Close(); 28 | bool Read(void* pBuffer, size_t pCount); 29 | 30 | off_t GetLength() const; 31 | const void* GetBufferize() const; 32 | ResourceDescriptor DeScript(); 33 | 34 | private: 35 | tstring mPath; 36 | AAsset* mAsset; 37 | }; 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/Graphics/ScaleSystem.cpp: -------------------------------------------------------------------------------- 1 | #include "ScaleSystem.h" 2 | #include "GraphicsManager.h" 3 | #include "../Logger.h" 4 | 5 | namespace star 6 | { 7 | ScaleSystem::ScaleSystem() 8 | :m_WorkingRes(0,0) 9 | ,m_Scale(0) 10 | ,m_bIninitialized(false) 11 | { 12 | } 13 | 14 | 15 | ScaleSystem::~ScaleSystem() 16 | { 17 | } 18 | 19 | void ScaleSystem::SetWorkingResolution(int32 xPixels, int32 yPixels) 20 | { 21 | vec2 workingRes(xPixels, yPixels); 22 | SetWorkingResolution(workingRes); 23 | } 24 | 25 | const vec2& ScaleSystem::GetWorkingResolution() const 26 | { 27 | return m_WorkingRes; 28 | } 29 | 30 | const vec2 & ScaleSystem::GetActualResolution() const 31 | { 32 | return GraphicsManager::GetInstance()->GetWindowResolution(); 33 | } 34 | 35 | void ScaleSystem::SetWorkingResolution(const vec2& pixels) 36 | { 37 | m_bIninitialized = true; 38 | m_WorkingRes = pixels; 39 | CalculateScale(); 40 | } 41 | 42 | float32 ScaleSystem::GetScale() const 43 | { 44 | return m_Scale; 45 | } 46 | 47 | void ScaleSystem::CalculateScale() 48 | { 49 | if(m_bIninitialized) 50 | { 51 | ASSERT_LOG(m_WorkingRes != vec2(), 52 | _T("ScaleSystem::CalculateScale(): \ 53 | Working resolution is 0! Please set correct working Resolution in the Game.cpp file!"), 54 | STARENGINE_LOG_TAG 55 | ); 56 | m_Scale = GraphicsManager::GetInstance()->GetViewportResolution().x / m_WorkingRes.x; 57 | } 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/Graphics/ScaleSystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "../defines.h" 5 | #include "../Helpers/Singleton.h" 6 | 7 | namespace star 8 | { 9 | /// 10 | /// Provides a resolution independant system. 11 | /// Set your target resolution to the value you specify 12 | /// and code everything as if your window would be that resolution. 13 | /// 14 | class ScaleSystem final : public Singleton 15 | { 16 | public: 17 | friend Singleton; 18 | 19 | /// 20 | /// Sets the working resolution of the game. 21 | /// 22 | /// The amount of pixels horizontally. 23 | /// The amount of pixels vertically. 24 | void SetWorkingResolution(int32 xPixels, int32 yPixels); 25 | /// 26 | /// Sets the working resolution of the game. 27 | /// 28 | /// The amount of pixels. 29 | void SetWorkingResolution(const vec2& pixels); 30 | /// 31 | /// Gets the working resolution of the game. 32 | /// 33 | /// The working resolution 34 | const vec2& GetWorkingResolution() const; 35 | /// 36 | /// Gets the actual resolution of the game. 37 | /// 38 | /// The actual resolution 39 | const vec2& GetActualResolution() const; 40 | /// 41 | /// Gets the scale of the window, expressed as the window resolution / the target resolution. 42 | /// 43 | /// The scale of the window. 44 | float32 GetScale() const; 45 | /// 46 | /// Calculates the scale of the window, expressed as the window resolution / the target resolution. 47 | /// 48 | void CalculateScale(); 49 | 50 | private: 51 | /// 52 | /// Creates a new instance of the 53 | /// Private because of Singleton design pattern. 54 | /// 55 | ScaleSystem(); 56 | 57 | /// 58 | /// Finalizes an instance of the class. 59 | /// 60 | ~ScaleSystem(); 61 | 62 | vec2 m_WorkingRes; 63 | float32 m_Scale; 64 | bool m_bIninitialized; 65 | }; 66 | } 67 | -------------------------------------------------------------------------------- /src/Graphics/SpriteAnimationManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../defines.h" 4 | #include "../Helpers/SpriteSheet.h" 5 | #include "../Helpers/Singleton.h" 6 | #include 7 | 8 | namespace star 9 | { 10 | class SpriteAnimationManager final : public Singleton 11 | { 12 | public: 13 | friend Singleton; 14 | 15 | void AddSpritesheet(const tstring & file, 16 | DirectoryMode mode = DEFAULT_DIRECTORY_MODE); 17 | void AddSpritesheet(const tstring & file, 18 | const tstring & binary_file, 19 | DirectoryMode mode = DEFAULT_DIRECTORY_MODE); 20 | 21 | const SpriteSheet & GetSpritesheet(const tstring & name) const; 22 | 23 | void Clear(); 24 | 25 | private: 26 | static SpriteAnimationManager * m_pManager; 27 | std::map m_Spritesheets; 28 | 29 | SpriteAnimationManager(); 30 | ~SpriteAnimationManager(); 31 | 32 | SpriteAnimationManager(const SpriteAnimationManager &); 33 | SpriteAnimationManager(SpriteAnimationManager &&); 34 | SpriteAnimationManager & operator=(const SpriteAnimationManager &); 35 | SpriteAnimationManager & operator=(SpriteAnimationManager&&); 36 | }; 37 | } -------------------------------------------------------------------------------- /src/Graphics/SpriteBatch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "../defines.h" 4 | #include "../Helpers/Singleton.h" 5 | #include 6 | #include "Shader.h" 7 | #include "../Components/Graphics/SpriteComponent.h" 8 | #include "../Components/Graphics/TextComponent.h" 9 | 10 | namespace star 11 | { 12 | class SpriteBatch final : public Singleton 13 | { 14 | public: 15 | friend Singleton; 16 | 17 | enum SpriteSortingMode 18 | { 19 | BackToFront, 20 | FrontToBack, 21 | TextureID 22 | }; 23 | 24 | void Initialize(); 25 | void Flush(); 26 | void AddSpriteToQueue(const SpriteInfo* spriteInfo); 27 | void AddTextToQueue(const TextInfo* text); 28 | 29 | void SetSpriteSortingMode(SpriteSortingMode mode); 30 | 31 | private: 32 | SpriteBatch(); 33 | ~SpriteBatch(); 34 | 35 | void Begin(); 36 | void End(); 37 | void CreateSpriteQuads(); 38 | void CreateTextQuads(); 39 | void SortSprites(SpriteSortingMode mode); 40 | void DrawSprites(); 41 | void FlushSprites(uint32 start, uint32 size, uint32 texture); 42 | void DrawTextSprites(); 43 | 44 | static const uint32 BATCHSIZE = 50; 45 | static const uint32 VERTEX_AMOUNT = 18; 46 | static const uint32 UV_AMOUNT = 12; 47 | static const uint32 FIRST_REAL_ASCII_CHAR = 31; 48 | 49 | std::vector m_SpriteQueue; 50 | std::vector m_TextQueue; 51 | 52 | //[TODO] Check if can be changed to vector 53 | std::vector m_VertexBuffer; 54 | std::vector m_UvCoordBuffer; 55 | std::vector m_IsHUDBuffer; 56 | std::vector m_ColorBuffer; 57 | 58 | GLuint m_VertexID, 59 | m_UVID, 60 | m_IsHUDID; 61 | 62 | GLuint m_TextureSamplerID, 63 | m_ColorID, 64 | m_ScalingID, 65 | m_ViewInverseID, 66 | m_ProjectionID; 67 | 68 | Shader* m_ShaderPtr; 69 | 70 | SpriteSortingMode m_SpriteSortingMode; 71 | 72 | SpriteBatch(const SpriteBatch& yRef); 73 | SpriteBatch(SpriteBatch&& yRef); 74 | SpriteBatch& operator=(const SpriteBatch& yRef); 75 | SpriteBatch& operator=(SpriteBatch&& yRef); 76 | }; 77 | } 78 | -------------------------------------------------------------------------------- /src/Graphics/Texture2D.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../defines.h" 4 | #include "../Logger.h" 5 | 6 | #ifdef DESKTOP 7 | //#pragma warning (disable : 4172) 8 | //#pragma warning (disable : 4099) 9 | #include 10 | //#pragma warning (default : 4172) 11 | //#pragma warning (default : 4099) 12 | #include 13 | #else 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "Resource.h" 19 | #endif 20 | 21 | 22 | namespace star 23 | { 24 | class Texture2D final 25 | { 26 | public: 27 | //[NOTE] You're not supposed to make Textures yourself. 28 | // Use the TextureManager to load your textures. 29 | // This ensures a same texture is not loaded multiple times 30 | Texture2D(const tstring & pPath); 31 | ~Texture2D(); 32 | 33 | const tstring & GetPath() const; 34 | int32 GetHeight() const; 35 | int32 GetWidth() const; 36 | GLuint GetTextureID() const; 37 | 38 | private: 39 | uint8* ReadPNG(); 40 | void Load(); 41 | 42 | GLuint mTextureId; 43 | GLint mFormat; 44 | int32 mWidth, mHeight; 45 | #ifdef ANDROID 46 | Resource mResource; 47 | static void CallbackRead(png_structp png, png_bytep data, png_size_t size); 48 | #else 49 | tstring mPath; 50 | #endif 51 | static const tstring LIBPNG_LOG_TAG; 52 | 53 | static void CustomErrorFunction(png_structp pngPtr, png_const_charp error); 54 | static void CustomWarningFunction(png_structp pngPtr, png_const_charp warning); 55 | 56 | Texture2D(const Texture2D& yRef); 57 | Texture2D(Texture2D&& yRef); 58 | Texture2D& operator=(const Texture2D& yRef); 59 | Texture2D& operator=(Texture2D&& yRef); 60 | }; 61 | } 62 | 63 | 64 | -------------------------------------------------------------------------------- /src/Graphics/TextureManager.cpp: -------------------------------------------------------------------------------- 1 | #include "TextureManager.h" 2 | #include "../Logger.h" 3 | #include "../Context.h" 4 | #include "Texture2D.h" 5 | 6 | #ifdef ANDROID 7 | #include "../StarEngine.h" 8 | #endif 9 | 10 | namespace star 11 | { 12 | TextureManager::~TextureManager() 13 | { 14 | m_TextureMap.clear(); 15 | m_PathList.clear(); 16 | } 17 | 18 | TextureManager::TextureManager(void) 19 | : m_TextureMap() 20 | , m_PathList() 21 | { 22 | 23 | } 24 | 25 | void TextureManager::LoadTexture(const tstring& path, const tstring& name) 26 | { 27 | 28 | if(m_TextureMap.find(name) != m_TextureMap.end()) 29 | { 30 | return; 31 | } 32 | 33 | auto pathit = m_PathList.find(path); 34 | if(pathit != m_PathList.end()) 35 | { 36 | tstring nameOld = pathit->second; 37 | auto nameit = m_TextureMap.find(nameOld); 38 | if(nameit != m_TextureMap.end()) 39 | { 40 | m_TextureMap[name] = nameit->second; 41 | return; 42 | } 43 | m_PathList.erase(pathit); 44 | return; 45 | } 46 | 47 | m_TextureMap[name] = std::make_shared(path); 48 | 49 | m_PathList[path] = name; 50 | } 51 | 52 | bool TextureManager::DeleteTexture(const tstring& name) 53 | { 54 | auto it = m_TextureMap.find(name); 55 | if(it != m_TextureMap.end()) 56 | { 57 | m_TextureMap.erase(it); 58 | return true; 59 | } 60 | return false; 61 | } 62 | 63 | GLuint TextureManager::GetTextureID(const tstring& name) 64 | { 65 | if(m_TextureMap.find(name) != m_TextureMap.end()) 66 | { 67 | return m_TextureMap[name]->GetTextureID(); 68 | } 69 | return 0; 70 | } 71 | 72 | ivec2 TextureManager::GetTextureDimensions(const tstring& name) 73 | { 74 | auto it = m_TextureMap.find(name); 75 | if(it != m_TextureMap.end()) 76 | { 77 | return (ivec2(it->second->GetWidth(), it->second->GetHeight())); 78 | } 79 | return ivec2(0,0); 80 | } 81 | 82 | void TextureManager::EraseAllTextures() 83 | { 84 | m_TextureMap.clear(); 85 | m_PathList.clear(); 86 | } 87 | 88 | bool TextureManager::ReloadAllTextures() 89 | { 90 | m_TextureMap.clear(); 91 | for(auto it = m_PathList.begin(); it != m_PathList.end(); ++it) 92 | { 93 | m_TextureMap[it->second] = std::make_shared(it->first); 94 | } 95 | return true; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/Graphics/TextureManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "../defines.h" 6 | #include "../Helpers/Singleton.h" 7 | 8 | #ifdef DESKTOP 9 | #include 10 | #else 11 | #include "GLES/gl.h" 12 | #endif 13 | 14 | namespace star 15 | { 16 | class Texture2D; 17 | 18 | class TextureManager final : public Singleton 19 | { 20 | public: 21 | friend Singleton; 22 | 23 | void LoadTexture(const tstring& path, const tstring& name); 24 | bool DeleteTexture(const tstring& name); 25 | GLuint GetTextureID(const tstring& name); 26 | ivec2 GetTextureDimensions(const tstring& name); 27 | void EraseAllTextures(); 28 | bool ReloadAllTextures(); 29 | 30 | private: 31 | std::map> m_TextureMap; 32 | std::map m_PathList; 33 | 34 | TextureManager(); 35 | ~TextureManager(); 36 | 37 | TextureManager(const TextureManager& yRef); 38 | TextureManager(TextureManager&& yRef); 39 | TextureManager& operator=(const TextureManager& yRef); 40 | TextureManager& operator=(TextureManager&& yRef); 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /src/Graphics/UI/Index.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "UICursor.h" 4 | #include "UIObject.h" 5 | #include "UIDock.h" 6 | #include "UIImage.h" 7 | #include "UIAnimatedImage.h" 8 | #include "UISlider.h" 9 | #include "UITextField.h" 10 | #include "UIUserElement.h" 11 | #include "UISimpleTextButton.h" 12 | #include "UIStaticButton.h" 13 | #include "UIStaticTextButton.h" 14 | #include "UIButton.h" 15 | #include "UITextButton.h" 16 | #include "UIAnimatedButton.h" 17 | #include "UIAnimatedTextButton.h" 18 | -------------------------------------------------------------------------------- /src/Graphics/UI/UIAnimatedButton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UIUserElement.h" 3 | 4 | namespace star 5 | { 6 | class SpriteSheetComponent; 7 | 8 | class UIAnimatedButton : public UIUserElement 9 | { 10 | public: 11 | UIAnimatedButton( 12 | const tstring & name, 13 | const tstring & file, 14 | const tstring & spritesheet 15 | ); 16 | 17 | UIAnimatedButton( 18 | const tstring & name, 19 | const tstring & file, 20 | const tstring & spriteName, 21 | const tstring & spritesheet 22 | ); 23 | 24 | virtual ~UIAnimatedButton(); 25 | 26 | virtual void AfterInitialized(); 27 | 28 | virtual void SetHorizontalAlignment( 29 | HorizontalAlignment alignment, 30 | bool redefineCenter = true 31 | ); 32 | virtual void SetVerticalAlignment( 33 | VerticalAlignment alignment, 34 | bool redefineCenter = true 35 | ); 36 | 37 | void EnableContiniousAnimation(bool enabled); 38 | bool IsContiniousAnimationEnabled() const; 39 | 40 | virtual vec2 GetDimensions() const; 41 | 42 | protected: 43 | virtual void GoIdle(); 44 | #ifdef DESKTOP 45 | virtual void GoHover(); 46 | #endif 47 | virtual void GoDown(); 48 | virtual void GoDisable(); 49 | 50 | SpriteSheetComponent *m_pButtonSprite; 51 | bool m_ContiniousAnimation; 52 | 53 | private: 54 | UIAnimatedButton(const UIAnimatedButton &); 55 | UIAnimatedButton(UIAnimatedButton &&); 56 | UIAnimatedButton & operator=(const UIAnimatedButton &); 57 | UIAnimatedButton & operator=(UIAnimatedButton &&); 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /src/Graphics/UI/UIAnimatedImage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UIObject.h" 3 | #include 4 | 5 | namespace star 6 | { 7 | class SpriteSheetComponent; 8 | 9 | class UIAnimatedImage : public UIObject 10 | { 11 | public: 12 | UIAnimatedImage( 13 | const tstring & name, 14 | const tstring & filePath, 15 | const tstring & spritesheet 16 | ); 17 | 18 | UIAnimatedImage( 19 | const tstring & name, 20 | const tstring & filePath, 21 | const tstring & spriteName, 22 | const tstring & spritesheet 23 | ); 24 | 25 | virtual ~UIAnimatedImage(void); 26 | 27 | virtual void SetHorizontalAlignment( 28 | HorizontalAlignment alignment, 29 | bool redefineCenter = true 30 | ); 31 | virtual void SetVerticalAlignment( 32 | VerticalAlignment alignment, 33 | bool redefineCenter = true 34 | ); 35 | 36 | void Play(); 37 | void Restart(); 38 | void Pause(); 39 | void Stop(); 40 | 41 | void PushAnimation( 42 | const tstring & animation, 43 | const std::function & callback = nullptr 44 | ); 45 | void PlayAnimation( 46 | const tstring & animation, 47 | const std::function & callback = nullptr 48 | ); 49 | void PlayAnimation( 50 | const tstring & animation, 51 | int32 startFrame, 52 | const std::function & callback = nullptr 53 | ); 54 | 55 | void PlayNextAnimation(); 56 | void PlayNextAnimation(int32 startFrame); 57 | void Reset(); 58 | 59 | void SetSpritesheet(const tstring & spritesheet); 60 | 61 | tstring GetCurrentAnimation() const; 62 | const tstring & GetCurrentSpritesheet() const; 63 | 64 | int32 GetCurrentFrame() const; 65 | 66 | int32 GetFramesHorizontal() const; 67 | int32 GetFramesVertical() const; 68 | int32 GetWidth() const; 69 | int32 GetHeight() const; 70 | 71 | void SetCallbackAnimations(const std::function & callback); 72 | 73 | bool IsPlaying(); 74 | 75 | protected: 76 | SpriteSheetComponent * m_pSprite; 77 | 78 | private: 79 | UIAnimatedImage(const UIAnimatedImage &); 80 | UIAnimatedImage(UIAnimatedImage &&); 81 | UIAnimatedImage & operator=(const UIAnimatedImage &); 82 | UIAnimatedImage & operator=(UIAnimatedImage &&); 83 | }; 84 | } 85 | -------------------------------------------------------------------------------- /src/Graphics/UI/UIBaseCursor.cpp: -------------------------------------------------------------------------------- 1 | #include "UIBaseCursor.h" 2 | #include "../../Scenes/BaseScene.h" 3 | 4 | namespace star 5 | { 6 | UIBaseCursor::UIBaseCursor(const tstring & name) 7 | : Object(name) 8 | , m_IsLocked(false) 9 | , m_State(UI_STATE_IDLE) 10 | { 11 | } 12 | 13 | UIBaseCursor::~UIBaseCursor() 14 | { 15 | } 16 | 17 | void UIBaseCursor::SetLocked(bool locked) 18 | { 19 | m_IsLocked = locked; 20 | } 21 | 22 | bool UIBaseCursor::IsLocked() const 23 | { 24 | return m_IsLocked; 25 | } 26 | 27 | bool UIBaseCursor::IsIdle() const 28 | { 29 | return m_State == UI_STATE_IDLE; 30 | } 31 | 32 | bool UIBaseCursor::IsHover() const 33 | { 34 | return m_State == UI_STATE_HOVER; 35 | } 36 | 37 | bool UIBaseCursor::IsClick() const 38 | { 39 | return m_State == UI_STATE_CLICK; 40 | } 41 | 42 | void UIBaseCursor::SetState(const tstring & state) 43 | { 44 | if(!m_IsLocked) 45 | { 46 | m_State = state; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Graphics/UI/UIBaseCursor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../defines.h" 3 | #include "../../Context.h" 4 | #include "../../Objects/Object.h" 5 | 6 | namespace star 7 | { 8 | class UIBaseCursor : public Object 9 | { 10 | public: 11 | UIBaseCursor(const tstring & name); 12 | virtual ~UIBaseCursor(); 13 | 14 | void SetLocked(bool locked); 15 | bool IsLocked() const; 16 | 17 | bool IsIdle() const; 18 | bool IsHover() const; 19 | bool IsClick() const; 20 | 21 | virtual void SetState(const tstring & state); 22 | 23 | protected: 24 | bool m_IsLocked; 25 | tstring m_State; 26 | 27 | private: 28 | UIBaseCursor(const UIBaseCursor &); 29 | UIBaseCursor(UIBaseCursor &&); 30 | UIBaseCursor & operator=(const UIBaseCursor &); 31 | UIBaseCursor & operator=(UIBaseCursor&&); 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /src/Graphics/UI/UIButton.cpp: -------------------------------------------------------------------------------- 1 | #include "UIButton.h" 2 | 3 | #include "../../Components/Graphics/SpriteComponent.h" 4 | 5 | namespace star 6 | { 7 | UIButton::UIButton( 8 | const tstring & name, 9 | const tstring & file, 10 | bool isVertical 11 | ) 12 | : UIStaticButton( 13 | name, 14 | file, 15 | isVertical ? 1 : 4, 16 | isVertical ? 4 : 1 17 | ) 18 | , m_IsVertical(isVertical) 19 | { 20 | } 21 | 22 | UIButton::UIButton( 23 | const tstring & name, 24 | const tstring & file, 25 | const tstring & spriteName, 26 | bool isVertical 27 | ) 28 | : UIStaticButton( 29 | name, 30 | file, 31 | spriteName, 32 | isVertical ? 1 : 4, 33 | isVertical ? 4 : 1 34 | ) 35 | , m_IsVertical(isVertical) 36 | { 37 | } 38 | 39 | UIButton::~UIButton(void) 40 | { 41 | 42 | } 43 | 44 | void UIButton::AfterInitialized() 45 | { 46 | GoIdle(); 47 | UIStaticButton::AfterInitialized(); 48 | } 49 | 50 | void UIButton::GoIdle() 51 | { 52 | m_pButtonSprite->SetCurrentSegment( 53 | m_IsVertical ? 0 : int8(m_ElementState), 54 | m_IsVertical ? int8(m_ElementState) : 0 55 | ); 56 | UIUserElement::GoIdle(); 57 | } 58 | 59 | #ifdef DESKTOP 60 | void UIButton::GoHover() 61 | { 62 | m_pButtonSprite->SetCurrentSegment( 63 | m_IsVertical ? 0 : int8(m_ElementState), 64 | m_IsVertical ? int8(m_ElementState) : 0 65 | ); 66 | UIUserElement::GoHover(); 67 | } 68 | #endif 69 | 70 | void UIButton::GoDown() 71 | { 72 | m_pButtonSprite->SetCurrentSegment( 73 | m_IsVertical ? 0 : int8(m_ElementState), 74 | m_IsVertical ? int8(m_ElementState) : 0 75 | ); 76 | UIUserElement::GoDown(); 77 | } 78 | 79 | void UIButton::GoDisable() 80 | { 81 | m_pButtonSprite->SetCurrentSegment( 82 | m_IsVertical ? 0 : int8(m_ElementState), 83 | m_IsVertical ? int8(m_ElementState) : 0 84 | ); 85 | UIUserElement::GoDisable(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/Graphics/UI/UIButton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UIStaticButton.h" 3 | 4 | namespace star 5 | { 6 | class UIButton : public UIStaticButton 7 | { 8 | public: 9 | UIButton( 10 | const tstring & name, 11 | const tstring & file, 12 | bool isVertical = true 13 | ); 14 | 15 | UIButton( 16 | const tstring & name, 17 | const tstring & file, 18 | const tstring & spriteName, 19 | bool isVertical = true 20 | ); 21 | 22 | virtual ~UIButton(); 23 | 24 | virtual void AfterInitialized(); 25 | 26 | protected: 27 | virtual void GoIdle(); 28 | #ifdef DESKTOP 29 | virtual void GoHover(); 30 | #endif 31 | virtual void GoDown(); 32 | virtual void GoDisable(); 33 | 34 | bool m_IsVertical; 35 | 36 | private: 37 | UIButton(const UIButton &); 38 | UIButton(UIButton &&); 39 | UIButton & operator=(const UIButton &); 40 | UIButton & operator=(UIButton &&); 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /src/Graphics/UI/UICursor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UIBaseCursor.h" 3 | #include "../Color.h" 4 | 5 | #include 6 | 7 | namespace star 8 | { 9 | class SpriteSheetComponent; 10 | 11 | class UICursor : public UIBaseCursor 12 | { 13 | public: 14 | UICursor( 15 | const tstring & name, 16 | const tstring & spriteFile, 17 | const tstring & spritesheetName 18 | ); 19 | 20 | UICursor( 21 | const tstring & name, 22 | const tstring & spriteFile, 23 | const tstring & spriteName, 24 | const tstring & spritesheetName 25 | ); 26 | 27 | virtual ~UICursor(); 28 | 29 | void SetCenterPoint(const vec2 & center); 30 | void SetCenterPoint(float32 x, float32 y); 31 | void SetCenterX(float32 x); 32 | void SetCenterY(float32 y); 33 | 34 | void SetDefaultCenterPosition(const vec2 & center); 35 | void SetDefaultCenterPosition(float32 x, float32 y); 36 | 37 | virtual void SetState(const tstring & state); 38 | 39 | void SetStateOffset( 40 | const tstring & state, 41 | const vec2 & offset 42 | ); 43 | 44 | void SetStateOffset( 45 | const tstring & state, 46 | float32 x, 47 | float32 y 48 | ); 49 | 50 | void SetColorMultiplier(const Color & color); 51 | 52 | protected: 53 | virtual void Update(const Context & context); 54 | 55 | SpriteSheetComponent * m_pCursorSprite; 56 | std::unordered_map m_Offsets; 57 | vec2 m_DefaultOffset; 58 | 59 | private: 60 | UICursor(const UICursor &); 61 | UICursor(UICursor &&); 62 | UICursor & operator=(const UICursor &); 63 | UICursor & operator=(UICursor&&); 64 | }; 65 | } 66 | -------------------------------------------------------------------------------- /src/Graphics/UI/UIDock.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UIObject.h" 3 | 4 | namespace star 5 | { 6 | class UIDock : public UIObject 7 | { 8 | public: 9 | UIDock(const tstring & name); 10 | 11 | UIDock( 12 | const tstring & name, 13 | float32 width, 14 | float32 height 15 | ); 16 | virtual ~UIDock(void); 17 | 18 | virtual void SetHorizontalAlignment( 19 | HorizontalAlignment alignment, 20 | bool redefineCenter = true 21 | ); 22 | virtual void SetVerticalAlignment( 23 | VerticalAlignment alignment, 24 | bool redefineCenter = true 25 | ); 26 | 27 | void SetDimensions(const vec2 & dimensions); 28 | void SetDimensions(float32 x, float32 y); 29 | void SetDimensionsX(float32 x); 30 | void SetDimensionsY(float32 y); 31 | 32 | virtual vec2 GetDimensions() const; 33 | 34 | protected: 35 | vec2 m_Dimensions; 36 | virtual bool CheckCulling( 37 | float32 left, 38 | float32 right, 39 | float32 top, 40 | float32 bottom 41 | ); 42 | 43 | private: 44 | UIDock(const UIDock &); 45 | UIDock(UIDock &&); 46 | UIDock & operator=(const UIDock &); 47 | UIDock & operator=(UIDock &&); 48 | }; 49 | } 50 | -------------------------------------------------------------------------------- /src/Graphics/UI/UIImage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UIObject.h" 3 | #include "../Color.h" 4 | 5 | namespace star 6 | { 7 | class SpriteComponent; 8 | 9 | class UIImage : public UIObject 10 | { 11 | public: 12 | UIImage( 13 | const tstring & name, 14 | const tstring & filePath, 15 | uint32 horizontalSegements = 1, 16 | uint32 verticalSegments = 1 17 | ); 18 | 19 | UIImage( 20 | const tstring & name, 21 | const tstring & filePath, 22 | const tstring & spriteName, 23 | uint32 horizontalSegements = 1, 24 | uint32 verticalSegments = 1 25 | ); 26 | 27 | virtual ~UIImage(void); 28 | 29 | virtual void SetHorizontalAlignment( 30 | HorizontalAlignment alignment, 31 | bool redefineCenter = true 32 | ); 33 | virtual void SetVerticalAlignment( 34 | VerticalAlignment alignment, 35 | bool redefineCenter = true 36 | ); 37 | 38 | void SetCurrentSegement(uint32 segmentX, uint32 segmentY); 39 | 40 | void SetColorMultiplier(const Color & color); 41 | 42 | virtual vec2 GetDimensions() const; 43 | 44 | protected: 45 | SpriteComponent * m_pSprite; 46 | 47 | private: 48 | UIImage(const UIImage &); 49 | UIImage(UIImage &&); 50 | UIImage & operator=(const UIImage &); 51 | UIImage & operator=(UIImage &&); 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /src/Graphics/UI/UISlider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UIImage.h" 3 | #include 4 | 5 | namespace star 6 | { 7 | class UIButton; 8 | 9 | class UISlider : public UIImage 10 | { 11 | public: 12 | UISlider( 13 | const tstring & name, 14 | const tstring & file, 15 | const tstring & fileBackground, 16 | bool sliderIsHorizontal, 17 | bool spritesheetIsVertical = true 18 | ); 19 | UISlider( 20 | const tstring & name, 21 | const tstring & file, 22 | const tstring & spriteName, 23 | const tstring & fileBackground, 24 | const tstring & spriteNameBackground, 25 | bool sliderIsHorizontal, 26 | bool spritesheetIsVertical = true 27 | ); 28 | virtual ~UISlider(); 29 | 30 | virtual void AfterInitialized(); 31 | virtual void Update(const Context & context); 32 | 33 | void SetPercent(float32 percent); 34 | float32 GetPercent() const; 35 | 36 | void SetReleasedCallback( 37 | const std::function & callback 38 | ); 39 | 40 | void SetDownCallback( 41 | const std::function & callback 42 | ); 43 | 44 | void SetSliderOffset(float32 min, float32 max); 45 | void SetSliderOffset(const vec2 & offset); 46 | void SetSliderMinOffset(float32 min); 47 | void SetSliderMaxOffset(float32 max); 48 | 49 | void SetSliderOrthogonalAlignmentCentered(bool redefineCenter = true); 50 | void SetSliderOrthogonalAlignmentPositive(bool redefineCenter = true); 51 | void SetSliderOrthogonalAlignmentNegative(bool redefineCenter = true); 52 | 53 | void SetSliderOrthogonalOffset(float32 offset); 54 | 55 | void SetSliderCenterPoint(const vec2 & center); 56 | void SetSliderCenterPoint(float32 x, float32 y); 57 | void SetSliderCenterX(float32 x); 58 | void SetSliderCenterY(float32 y); 59 | 60 | protected: 61 | void SetPositionAccordingToPercent(); 62 | void CalculateSliderDimension(); 63 | 64 | bool m_SliderIsHorizontal; 65 | bool m_SliderIsDown; 66 | 67 | UIButton * m_pSlider; 68 | float32 m_Percent, m_SliderDimension; 69 | vec2 m_SliderOffset; 70 | 71 | std::function 72 | m_ReleasedCallback, 73 | m_DownCallback; 74 | 75 | private: 76 | UISlider(const UISlider &); 77 | UISlider(UISlider &&); 78 | UISlider & operator=(const UISlider &); 79 | UISlider & operator=(UISlider &&); 80 | }; 81 | } 82 | -------------------------------------------------------------------------------- /src/Graphics/UI/UIStaticButton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UIUserElement.h" 3 | #include "../Color.h" 4 | 5 | namespace star 6 | { 7 | class SpriteComponent; 8 | 9 | class UIStaticButton : public UIUserElement 10 | { 11 | public: 12 | UIStaticButton( 13 | const tstring & name, 14 | const tstring & file, 15 | uint32 widthSegements = 1, 16 | uint32 heightSegements = 1 17 | ); 18 | 19 | UIStaticButton( 20 | const tstring & name, 21 | const tstring & file, 22 | const tstring & spriteName, 23 | uint32 widthSegements = 1, 24 | uint32 heightSegements = 1 25 | ); 26 | 27 | virtual ~UIStaticButton(); 28 | 29 | virtual void SetHorizontalAlignment( 30 | HorizontalAlignment alignment, 31 | bool redefineCenter = true 32 | ); 33 | virtual void SetVerticalAlignment( 34 | VerticalAlignment alignment, 35 | bool redefineCenter = true 36 | ); 37 | 38 | void SetCurrentSegement(uint32 segmentX, uint32 segmentY); 39 | 40 | void SetColorMultiplier(const Color & color); 41 | 42 | virtual vec2 GetDimensions() const; 43 | 44 | protected: 45 | SpriteComponent *m_pButtonSprite; 46 | 47 | private: 48 | UIStaticButton(const UIStaticButton &); 49 | UIStaticButton(UIStaticButton &&); 50 | UIStaticButton & operator=(const UIStaticButton &); 51 | UIStaticButton & operator=(UIStaticButton &&); 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /src/Graphics/UI/UIStaticTextButton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "UIStaticButton.h" 4 | #include "../Color.h" 5 | 6 | namespace star 7 | { 8 | class UITextField; 9 | 10 | class UIStaticTextButton : public UIStaticButton 11 | { 12 | public: 13 | UIStaticTextButton( 14 | const tstring & name, 15 | const tstring & file, 16 | const tstring & text, 17 | const tstring & fontName, 18 | const Color & color, 19 | uint32 widthSegements = 1, 20 | uint32 heightSegements = 1 21 | ); 22 | 23 | UIStaticTextButton( 24 | const tstring & name, 25 | const tstring & file, 26 | const tstring & text, 27 | const tstring & fontName, 28 | const tstring & fontPath, 29 | uint32 fontSize, 30 | const Color & color, 31 | uint32 widthSegements = 1, 32 | uint32 heightSegements = 1 33 | ); 34 | 35 | virtual ~UIStaticTextButton(); 36 | virtual void AfterInitialized(); 37 | 38 | void SetTextColor(const Color & color); 39 | 40 | void SetText(const tstring & text); 41 | const tstring & GetText() const; 42 | 43 | void TranslateText(const vec2& translation); 44 | void TranslateText(float32 x, float32 y); 45 | void TranslateTextX(float32 x); 46 | void TranslateTextY(float32 y); 47 | void SetHorizontalAlignmentText( 48 | HorizontalAlignment alignment, 49 | bool redefineCenter = true 50 | ); 51 | void SetVerticalAlignmentText( 52 | VerticalAlignment alignment, 53 | bool redefineCenter = true 54 | ); 55 | 56 | void SetTextCentered(); 57 | 58 | protected: 59 | UITextField * m_pTextField; 60 | 61 | private: 62 | UIStaticTextButton(const UIStaticTextButton &); 63 | UIStaticTextButton(UIStaticTextButton &&); 64 | UIStaticTextButton & operator=(const UIStaticTextButton &); 65 | UIStaticTextButton & operator=(UIStaticTextButton &&); 66 | }; 67 | } 68 | -------------------------------------------------------------------------------- /src/Graphics/UI/UITextField.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UIObject.h" 3 | 4 | namespace star 5 | { 6 | class TextComponent; 7 | 8 | struct Color; 9 | 10 | class UITextField : public UIObject 11 | { 12 | public: 13 | UITextField( 14 | const tstring & name, 15 | const tstring & text, 16 | const tstring & fontName, 17 | const Color & color 18 | ); 19 | 20 | UITextField( 21 | const tstring & name, 22 | const tstring & text, 23 | const tstring & fontName, 24 | const tstring & fontPath, 25 | uint32 fontSize, 26 | const Color & color 27 | ); 28 | 29 | virtual ~UITextField(void); 30 | 31 | virtual void Initialize(); 32 | 33 | virtual void SetHorizontalAlignment( 34 | HorizontalAlignment alignment, 35 | bool redefineCenter = true 36 | ); 37 | virtual void SetVerticalAlignment( 38 | VerticalAlignment alignment, 39 | bool redefineCenter = true 40 | ); 41 | 42 | void SetText(const tstring & text); 43 | const tstring & GetText() const; 44 | 45 | void SetColor(const Color & color); 46 | 47 | virtual vec2 GetDimensions() const; 48 | 49 | int32 GetWidth() const; 50 | int32 GetHeight() const; 51 | 52 | protected: 53 | TextComponent * m_pTextComponent; 54 | 55 | private: 56 | UITextField(const UITextField &); 57 | UITextField(UITextField &&); 58 | UITextField & operator=(const UITextField &); 59 | UITextField & operator=(UITextField &&); 60 | }; 61 | } 62 | -------------------------------------------------------------------------------- /src/Graphics/UI/UIUserElement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UIObject.h" 3 | #include 4 | 5 | namespace star 6 | { 7 | class UIUserElement : public UIObject 8 | { 9 | public: 10 | enum class ElementStates : byte 11 | { 12 | IDLE = 0, 13 | HOVER = 1, 14 | CLICK = 2, 15 | DISABLED = 3, 16 | LOCKED = 4 17 | }; 18 | 19 | UIUserElement(const tstring & name); 20 | virtual ~UIUserElement(); 21 | 22 | virtual void Reset(); 23 | 24 | void SetReleasedCallback(std::function callback); 25 | void SetDownCallback(std::function callback); 26 | 27 | void SetHoverCallback(std::function callback); 28 | void SetUnhoverCallback(std::function callback); 29 | 30 | bool IsIdle() const; 31 | bool IsHover() const; 32 | bool IsDown() const; 33 | 34 | void SetLocked(bool locked); 35 | void SetUIDisabled(bool disable); 36 | 37 | void SetHoverSoundEffect(const tstring & name); 38 | void SetHoverSoundEffect(const tstring & name, float32 volume); 39 | 40 | void SetClickSoundEffect(const tstring & name); 41 | void SetClickSoundEffect(const tstring & name, float32 volume); 42 | 43 | protected: 44 | struct EffectInfo 45 | { 46 | tstring name; 47 | float32 volume; 48 | }; 49 | 50 | virtual void Update(const Context& context); 51 | 52 | virtual void GoIdle(); 53 | #ifdef DESKTOP 54 | virtual void GoHover(); 55 | #endif 56 | virtual void GoDown(); 57 | virtual void GoUp(); 58 | virtual void GoDisable(); 59 | 60 | bool IsFingerWithinRange() const; 61 | 62 | std::function 63 | m_ReleasedCallback; 64 | std::function 65 | m_DownCallback; 66 | std::function 67 | m_HoverCallback, 68 | m_UnhoverCallback; 69 | 70 | ElementStates m_ElementState; 71 | 72 | EffectInfo m_Effects[2]; 73 | 74 | private: 75 | static const uint8 HOVER_EFFECT = 0; 76 | static const uint8 CLICK_EFFECT = 1; 77 | 78 | UIUserElement(const UIUserElement &); 79 | UIUserElement(UIUserElement &&); 80 | UIUserElement & operator=(const UIUserElement &); 81 | UIUserElement & operator=(UIUserElement &&); 82 | }; 83 | } 84 | -------------------------------------------------------------------------------- /src/Helpers/.gitignore: -------------------------------------------------------------------------------- 1 | !Debug/ -------------------------------------------------------------------------------- /src/Helpers/AARect.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "glm\glm.h" 4 | #include 5 | #include "..\Logger.h" 6 | 7 | namespace star 8 | { 9 | class AARect 10 | { 11 | public: 12 | AARect(); 13 | AARect(int32 x, int32 y, int32 width, int32 height); 14 | AARect(const vec2& location,const vec2& size); 15 | ~AARect(); 16 | 17 | int32 GetLeft() const; 18 | int32 GetTop() const; 19 | int32 GetRight() const; 20 | int32 GetBottom() const; 21 | 22 | void SetLeft(int32 left); 23 | void SetTop(int32 top); 24 | void SetRight(int32 right); 25 | void SetBottom(int32 bottom); 26 | 27 | bool Equals(const AARect& rect) const; 28 | bool Contains(int32 x, int32 y) const; 29 | bool Contains(const vec2& pt) const; 30 | bool Contains(AARect& rect) const; 31 | bool Intersect(const AARect& rect); 32 | 33 | static bool Intersect(const AARect& a, const AARect& b); 34 | 35 | private: 36 | int32 m_X; 37 | int32 m_Y; 38 | int32 m_Width; 39 | int32 m_Height; 40 | 41 | int32 m_Left; 42 | int32 m_Right; 43 | int32 m_Top; 44 | int32 m_Bottom; 45 | 46 | AARect* m_IntersectRect; 47 | }; 48 | } 49 | -------------------------------------------------------------------------------- /src/Helpers/FPS.cpp: -------------------------------------------------------------------------------- 1 | #include "FPS.h" 2 | #include "../Context.h" 3 | #include "Time.h" 4 | 5 | namespace star 6 | { 7 | FPS::FPS() 8 | : CurrentFPS(0) 9 | , PreviousFPS(0) 10 | , m_Timer(0) 11 | , m_Counter(0) 12 | { 13 | } 14 | 15 | void FPS::Update(const Context & context) 16 | { 17 | ++m_Counter; 18 | m_Timer += context.time->DeltaTime().GetSeconds(); 19 | if(m_Timer > 1.0) 20 | { 21 | m_Timer -= 1.0; 22 | PreviousFPS = CurrentFPS; 23 | CurrentFPS = m_Counter; 24 | m_Counter = 0; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/Helpers/FPS.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../defines.h" 4 | 5 | namespace star 6 | { 7 | struct Context; 8 | 9 | struct FPS 10 | { 11 | int32 CurrentFPS, PreviousFPS; 12 | 13 | FPS(); 14 | 15 | void Update(const Context & context); 16 | 17 | private: 18 | float64 m_Timer; 19 | int32 m_Counter; 20 | }; 21 | } -------------------------------------------------------------------------------- /src/Helpers/GameData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../defines.h" 4 | #include "../Input/XMLContainer.h" 5 | 6 | namespace star 7 | { 8 | class BaseScene; 9 | 10 | class GameData final 11 | { 12 | public: 13 | GameData( 14 | const tstring & file, 15 | BaseScene * pScene = nullptr, 16 | DirectoryMode mode = DEFAULT_DIRECTORY_MODE 17 | ); 18 | GameData( 19 | const tstring & file, 20 | const tstring & binaryFile, 21 | BaseScene * pScene = nullptr, 22 | DirectoryMode mode = DEFAULT_DIRECTORY_MODE 23 | ); 24 | GameData(const GameData & yRef); 25 | GameData(GameData && yRef); 26 | 27 | ~GameData(); 28 | 29 | GameData & operator=(const GameData & yRef); 30 | GameData & operator=(GameData && yRef); 31 | 32 | void Load(); 33 | void Save(); 34 | 35 | template 36 | T GetData( 37 | const tstring & name, 38 | const tstring & group = DEFAULT_DATA_GROUP 39 | ); 40 | 41 | template 42 | void SetData( 43 | const tstring & name, 44 | const T & value, 45 | const tstring & group = DEFAULT_DATA_GROUP 46 | ); 47 | 48 | void SetAutoSaveEnabled(bool enable, float32 seconds = 60.0f); 49 | 50 | private: 51 | static const tstring DEFAULT_DATA_GROUP; 52 | static const tstring UNIQUE_ID_PREFIX; 53 | static uint64 UNIQUE_ID_COUNTER; 54 | 55 | XMLContainer m_Data; 56 | tstring m_File, m_BinaryFile, m_UniqueID; 57 | DirectoryMode m_DirectoryMode; 58 | bool m_AutoSaveEnabled; 59 | float32 m_AutoSaveSeconds; 60 | BaseScene *m_pScene; 61 | }; 62 | } 63 | 64 | #include "GameData.inl" 65 | -------------------------------------------------------------------------------- /src/Helpers/GameData.inl: -------------------------------------------------------------------------------- 1 | #include "../defines.h" 2 | #include "../Input/XMLContainer.h" 3 | #include "Helpers.h" 4 | 5 | namespace star 6 | { 7 | template 8 | T GameData::GetData( 9 | const tstring & name, 10 | const tstring & group 11 | ) 12 | { 13 | return string_cast( 14 | m_Data.at(group)->at(name)->GetValue() 15 | ); 16 | } 17 | 18 | template 19 | void GameData::SetData( 20 | const tstring & name, 21 | const T & value, 22 | const tstring & group 23 | ) 24 | { 25 | m_Data.at(group)->at(name)->SetValue( 26 | string_cast(value) 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Helpers/HashTag.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../defines.h" 4 | #include "../Logger.h" 5 | 6 | namespace star 7 | { 8 | #define HASH uint32 9 | 10 | class HashTag final 11 | { 12 | public: 13 | HashTag(const tstring & tag); 14 | 15 | HashTag(const HashTag & yRef); 16 | HashTag(HashTag && yRef); 17 | 18 | HashTag & operator=(const HashTag & yRef); 19 | HashTag & operator=(HashTag && yRef); 20 | 21 | bool operator==(const HashTag & other) const; 22 | bool operator!=(const HashTag & other) const; 23 | bool operator==(HashTag && other) const; 24 | bool operator!=(HashTag && other) const; 25 | bool operator==(const tstring & tag) const; 26 | bool operator!=(const tstring & tag) const; 27 | bool operator==(HASH hash) const; 28 | bool operator!=(HASH hash) const; 29 | 30 | void SetTag(const tstring & tag); 31 | const tstring & GetTag() const; 32 | 33 | friend bool operator==(const tstring & tag, const HashTag & other); 34 | friend bool operator!=(const tstring & tag, const HashTag & other); 35 | friend bool operator==(HASH hash, const HashTag & other); 36 | friend bool operator!=(HASH hash, const HashTag & other); 37 | 38 | HASH GetHash() const; 39 | 40 | static void GenerateHash(const tstring & tag, HASH & hash); 41 | 42 | private: 43 | void GenerateHash(); 44 | 45 | tstring m_Tag; 46 | HASH m_Hash; 47 | }; 48 | 49 | #undef HASH 50 | } -------------------------------------------------------------------------------- /src/Helpers/HelpersAndroid.cpp: -------------------------------------------------------------------------------- 1 | #include "HelpersAndroid.h" 2 | 3 | #ifdef ANDROID 4 | 5 | #include 6 | #include 7 | #include "../StarEngine.h" 8 | #include "Helpers.h" 9 | #include "../Logger.h" 10 | 11 | namespace star_a 12 | { 13 | void ReadFileAsset(const tstring & path, star::SerializedData & data) 14 | { 15 | auto app = star::StarEngine::GetInstance()->GetAndroidApp(); 16 | auto manager = app->activity->assetManager; 17 | AAsset* asset = AAssetManager_open( 18 | manager, 19 | star::string_cast(path.c_str()).c_str(), 20 | AASSET_MODE_UNKNOWN 21 | ); 22 | ASSERT_LOG(asset != NULL, 23 | _T("ReadFileAsset: Couldn't find '") + path + _T("'."), STARENGINE_LOG_TAG); 24 | data.size = AAsset_getLength(asset); 25 | data.data = new schar[sizeof(schar) * data.size]; 26 | AAsset_read(asset, data.data, data.size); 27 | AAsset_close(asset); 28 | } 29 | 30 | bool ReadFileAssetSafe(const tstring & path, star::SerializedData & data, bool logWarning) 31 | { 32 | auto app = star::StarEngine::GetInstance()->GetAndroidApp(); 33 | auto manager = app->activity->assetManager; 34 | AAsset* asset = AAssetManager_open( 35 | manager, 36 | star::string_cast(path.c_str()).c_str(), 37 | AASSET_MODE_UNKNOWN 38 | ); 39 | bool result = asset != NULL; 40 | if(result) 41 | { 42 | data.size = AAsset_getLength(asset); 43 | data.data = new schar[sizeof(schar) * data.size]; 44 | AAsset_read(asset, data.data, data.size); 45 | AAsset_close(asset); 46 | } 47 | else if(logWarning) 48 | { 49 | LOG(star::LogLevel::Warning, 50 | _T("ReadFileAssetSafe: Couldn't find '") + path + _T("'."), STARENGINE_LOG_TAG); 51 | } 52 | return result; 53 | } 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/Helpers/HelpersAndroid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef ANDROID 4 | 5 | #include "../defines.h" 6 | #include "SerializedData.h" 7 | 8 | namespace star_a 9 | { 10 | void ReadFileAsset(const tstring & path, star::SerializedData & data); 11 | bool ReadFileAssetSafe(const tstring & path, star::SerializedData & data, bool logWarning = true); 12 | } 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/Helpers/HelpersCrossplatform.cpp: -------------------------------------------------------------------------------- 1 | #include "HelpersCrossplatform.h" 2 | 3 | namespace star_c 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /src/Helpers/HelpersCrossplatform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../defines.h" 4 | #include "SerializedData.h" 5 | 6 | namespace star_c 7 | { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/Helpers/Math.inl: -------------------------------------------------------------------------------- 1 | #include "..\defines.h" 2 | 3 | namespace star 4 | { 5 | template 6 | T DegreesToRadians(T degrees) 7 | { 8 | return T(float64(degrees) * PI / 180); 9 | } 10 | 11 | template 12 | T RadiansToDegrees(T radians) 13 | { 14 | return T(float64(radians) * 180 / PI); 15 | } 16 | 17 | template 18 | T Clamp(T x, T min, T max) 19 | { 20 | return x < min ? min : (x > max ? max : x); 21 | } 22 | 23 | template 24 | T Lerp(const T & start, const T & end, float32 percent) 25 | { 26 | return start + percent * (end - start); 27 | } 28 | 29 | template 30 | T Lerp(const T & start, const T & end, float64 percent) 31 | { 32 | return start + percent * (end - start); 33 | } 34 | 35 | template 36 | T Saturate(T x) 37 | { 38 | return glm::saturate(x); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Helpers/Rect.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StarEngine/engine/c8ede28ac6a56640f54cb94f8af9c2cb44fb6cf3/src/Helpers/Rect.cpp -------------------------------------------------------------------------------- /src/Helpers/Rect.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "../Logger.h" 5 | #include "../defines.h" 6 | 7 | namespace star 8 | { 9 | class Rect 10 | { 11 | public: 12 | Rect(); 13 | Rect(const vec2& leftBottom, const vec2& rightBottom, 14 | const vec2& leftTop, const vec2& rightTop); 15 | Rect operator=(const Rect& yRef); 16 | //[TODO] write operators and copy + move constructors (and non member operators) 17 | 18 | Rect operator*(mat4 matrix) const; 19 | Rect operator*(float32 constant) const; 20 | 21 | Rect operator/(float32 constant) const; 22 | 23 | Rect& operator*=(mat4 matrix); 24 | Rect& operator*=(float32 constant); 25 | 26 | 27 | float32 GetWidth() const; 28 | float32 GetHeight() const; 29 | float32 GetDiagonal() const; 30 | 31 | const vec2& GetLeftTop() const; 32 | const vec2& GetRightTop() const; 33 | const vec2& GetLeftBottom() const; 34 | const vec2& GetRightBottom() const; 35 | 36 | vec2 GetCenterPoint() const; 37 | 38 | float32 GetRealLeft() const; 39 | float32 GetRealRight() const; 40 | float32 GetRealTop() const; 41 | float32 GetRealBottom() const; 42 | 43 | void SetPoints(const vec2& leftBottom, const vec2& rightBottom, 44 | const vec2& leftTop, const vec2& rightTop); 45 | void SetLeftTop(const vec2& pos); 46 | void SetLeftBottom(const vec2& pos); 47 | void SetRightTop(const vec2& pos); 48 | void SetRightBottom(const vec2& pos); 49 | 50 | private: 51 | vec2 m_LeftTop; 52 | vec2 m_RightTop; 53 | vec2 m_LeftBottom; 54 | vec2 m_RightBottom; 55 | 56 | float32 m_Width; 57 | float32 m_Height; 58 | float32 m_Diagonal; 59 | }; 60 | } 61 | -------------------------------------------------------------------------------- /src/Helpers/SerializedData.cpp: -------------------------------------------------------------------------------- 1 | #include "SerializedData.h" 2 | 3 | namespace star 4 | { 5 | SerializedData::SerializedData() 6 | : data(nullptr) 7 | , size(0) 8 | { 9 | 10 | } 11 | 12 | SerializedData::SerializedData(schar * buffer, uint32 n) 13 | : data(buffer) 14 | , size(n) 15 | { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Helpers/SerializedData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../definesTypes.h" 4 | 5 | namespace star 6 | { 7 | struct SerializedData 8 | { 9 | schar * data; 10 | uint32 size; 11 | 12 | SerializedData(); 13 | SerializedData(schar * buffer, uint32 n); 14 | }; 15 | } 16 | -------------------------------------------------------------------------------- /src/Helpers/Singleton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../defines.h" 4 | 5 | namespace star 6 | { 7 | template 8 | class Singleton 9 | { 10 | public: 11 | static ClassType * GetInstance(); 12 | static void DeleteSingleton(); 13 | 14 | protected: 15 | Singleton(); 16 | virtual ~Singleton(); 17 | 18 | private: 19 | static ClassType * m_pSingletonObject; 20 | }; 21 | } 22 | 23 | #include "Singleton.inl" 24 | -------------------------------------------------------------------------------- /src/Helpers/Singleton.inl: -------------------------------------------------------------------------------- 1 | #include "../defines.h" 2 | 3 | namespace star 4 | { 5 | template 6 | ClassType * Singleton::m_pSingletonObject = nullptr; 7 | 8 | template 9 | ClassType * Singleton::GetInstance() 10 | { 11 | if(m_pSingletonObject == nullptr) 12 | { 13 | m_pSingletonObject = new ClassType(); 14 | } 15 | return m_pSingletonObject; 16 | } 17 | 18 | template 19 | void Singleton::DeleteSingleton() 20 | { 21 | delete m_pSingletonObject; 22 | m_pSingletonObject = nullptr; 23 | } 24 | 25 | template 26 | Singleton::Singleton() {} 27 | 28 | template 29 | Singleton::~Singleton() {} 30 | } -------------------------------------------------------------------------------- /src/Helpers/SpriteAnimation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../defines.h" 4 | #include 5 | #include 6 | 7 | namespace star 8 | { 9 | struct Context; 10 | 11 | class SpriteAnimation final 12 | { 13 | public: 14 | SpriteAnimation(); 15 | SpriteAnimation(const tstring & name, const vec2 & uv_scale, 16 | float32 speed, int32 repeat, const tstring & frames, 17 | int32 frames_x, int32 frames_y, int32 amount); 18 | SpriteAnimation(const SpriteAnimation &); 19 | SpriteAnimation(SpriteAnimation &&); 20 | ~SpriteAnimation(); 21 | 22 | SpriteAnimation & operator=(const SpriteAnimation &); 23 | SpriteAnimation & operator=(SpriteAnimation &&); 24 | 25 | void Update(const Context & context); 26 | vec4 GetCurrentUV() const; 27 | 28 | void Play(); 29 | void PlayAtFrame(int32 startFrame); 30 | void Replay(); 31 | void Pause(); 32 | void Stop(); 33 | 34 | const tstring & GetName() const; 35 | bool IsPlaying() const; 36 | 37 | void SetCallback(const std::function & callback); 38 | void SetUserCallback(const std::function & callback); 39 | 40 | int32 GetCurrentFrame() const; 41 | 42 | private: 43 | void ParseFrameString(tstring frames, int32 frames_x, int32 frames_y, int32 amount); 44 | void ParseFrames(const tstring & frame, int32 frames_x, int32 frames_y, int32 amount); 45 | void ParseFrame(int32 frame, int32 frames_x, int32 frames_y, int32 amount); 46 | 47 | tstring m_Name; 48 | float32 m_Speed, m_CurrentFrame; 49 | int32 m_Repeat; 50 | int32 m_CurrentRepeats; 51 | vec2 m_UVScale; 52 | 53 | std::function m_Callback; 54 | std::function m_UserCallback; 55 | 56 | std::vector m_Frames; 57 | bool m_IsPlaying; 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /src/Helpers/Spritesheet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Dictionary.h" 4 | #include "SpriteAnimation.h" 5 | 6 | namespace star 7 | { 8 | class XMLContainer; 9 | 10 | class SpriteSheet final : public Dictionary 11 | { 12 | public: 13 | SpriteSheet(); 14 | SpriteSheet(XMLContainer & spritesheet); 15 | SpriteSheet(const SpriteSheet & yRef); 16 | SpriteSheet(SpriteSheet && yRef); 17 | SpriteSheet(iterator begin, iterator end); 18 | ~SpriteSheet(); 19 | 20 | SpriteSheet & operator=(const SpriteSheet& yRef); 21 | SpriteSheet & operator=(SpriteSheet&& yRef); 22 | 23 | void SetName(const tstring & name); 24 | const tstring & GetName() const; 25 | 26 | const tstring & GetDefaultAnimation() const; 27 | 28 | int32 GetFramesHorizontal() const; 29 | int32 GetFramesVertical() const; 30 | 31 | private: 32 | tstring m_Name; 33 | tstring m_DefaultAnimation; 34 | int32 m_FramesHorizontal; 35 | int32 m_FramesVertical; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /src/Helpers/State.cpp: -------------------------------------------------------------------------------- 1 | #include "State.h" 2 | 3 | namespace star 4 | { 5 | State::~State() 6 | { 7 | 8 | } 9 | 10 | void State::Draw() 11 | { 12 | 13 | } 14 | 15 | void State::Activate() 16 | { 17 | m_Active = true; 18 | } 19 | 20 | void State::Deactivate() 21 | { 22 | m_Active = false; 23 | } 24 | 25 | bool State::IsActive() const 26 | { 27 | return m_Active; 28 | } 29 | 30 | State::State() 31 | : m_Active(false) 32 | { 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Helpers/State.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "..\defines.h" 4 | 5 | namespace star 6 | { 7 | struct Context; 8 | 9 | class State 10 | { 11 | public: 12 | virtual ~State(); 13 | 14 | virtual void Initialize(void) = 0; 15 | virtual void Update(const Context& context) = 0; 16 | virtual void Draw(); 17 | 18 | virtual void Activate(); 19 | virtual void Deactivate(); 20 | 21 | bool IsActive() const; 22 | 23 | protected: 24 | State(); 25 | 26 | bool m_Active; 27 | 28 | private: 29 | State(const State& yRef); 30 | State(State&& yRef); 31 | State& operator=(const State& yRef); 32 | State& operator=(State&& yRef); 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /src/Helpers/StateManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../defines.h" 4 | 5 | #include 6 | 7 | namespace star 8 | { 9 | struct Context; 10 | class State; 11 | 12 | class StateManager 13 | { 14 | public: 15 | StateManager(); 16 | virtual ~StateManager(); 17 | 18 | void Initialize(); 19 | void Update(const Context& context); 20 | void Draw(); 21 | 22 | void AddState(const tstring & name, State * pState); 23 | bool RemoveState(const tstring & name); 24 | void Clear(); 25 | 26 | void SetState(const tstring & name); 27 | void SetPreviousState(); 28 | 29 | const tstring & GetCurrentStateName() const; 30 | State * GetCurrentState() const; 31 | 32 | private: 33 | void DeactiveCurrentState(); 34 | 35 | std::map m_States; 36 | State * m_pCurrentState; 37 | tstring m_CurrentStateName, 38 | m_PreviousStateName; 39 | 40 | StateManager(const StateManager &); 41 | StateManager(StateManager&&); 42 | StateManager & operator=(const StateManager&); 43 | StateManager & operator=(StateManager&&); 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /src/Helpers/Stopwatch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../defines.h" 3 | #include "Time.h" 4 | #include 5 | 6 | namespace star 7 | { 8 | class Stopwatch final 9 | { 10 | public: 11 | Stopwatch(); 12 | Stopwatch(const Stopwatch & yRef); 13 | Stopwatch(Stopwatch && yRef); 14 | ~Stopwatch(); 15 | 16 | Stopwatch & operator=(const Stopwatch & yRef); 17 | Stopwatch & operator=(Stopwatch && yRef); 18 | 19 | void Start(); 20 | void Stop(); 21 | void Reset(); 22 | void Lap(); 23 | const std::vector