From a33337dc2b1ecc5b22462e7b9b65cd9d6b323017 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 17 Jan 2019 22:29:07 +0800 Subject: *graphics --- Source/Asura/Component.h | 2 +- Source/Asura/GameObject.h | 6 +++ Source/Asura/Graphics/Animation.cpp | 21 +++++++++ Source/Asura/Graphics/Animation.h | 78 ++++++++++++++++++++++++++++++++-- Source/Asura/Graphics/Camera.h | 5 +++ Source/Asura/Graphics/Image.h | 33 +++++++++++++- Source/Asura/Graphics/Material.h | 6 +++ Source/Asura/Graphics/Shader.h | 6 +++ Source/Asura/Graphics/Sprite.h | 16 ++++--- Source/Asura/Graphics/SpriteRenderer.h | 3 ++ Source/Asura/Manager.hpp | 14 ++++++ Source/Asura/Scene.h | 11 +++++ 12 files changed, 189 insertions(+), 12 deletions(-) create mode 100644 Source/Asura/Manager.hpp (limited to 'Source') diff --git a/Source/Asura/Component.h b/Source/Asura/Component.h index a602d50..5a9073d 100644 --- a/Source/Asura/Component.h +++ b/Source/Asura/Component.h @@ -1,7 +1,7 @@ #ifndef __AE_COMPONENT_H__ #define __AE_COMPONENT_H__ -#include "Object.h" +#include "GameObject.h" namespace AsuraEngine { diff --git a/Source/Asura/GameObject.h b/Source/Asura/GameObject.h index f4c4eb8..8e79b65 100644 --- a/Source/Asura/GameObject.h +++ b/Source/Asura/GameObject.h @@ -37,6 +37,12 @@ namespace AsuraEngine void SetScale(const Math::Vector2& scale); void SetRotation(const Math::Vector2& rotation); + template + inline T GetComponent() + { + return NULL; + } + private: Transform mTransform; diff --git a/Source/Asura/Graphics/Animation.cpp b/Source/Asura/Graphics/Animation.cpp index e69de29..47643aa 100644 --- a/Source/Asura/Graphics/Animation.cpp +++ b/Source/Asura/Graphics/Animation.cpp @@ -0,0 +1,21 @@ +#include "Animation.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + void Animation::OnEnable() + { + mSpriteRenderer = mGameObject->GetComponent(); + } + + void Animation::OnUpdate(uint32 milliseconds) + { + if (!mSpriteRenderer) + return; + mSpriteRenderer->SetSprite(NULL); + } + + } +} diff --git a/Source/Asura/Graphics/Animation.h b/Source/Asura/Graphics/Animation.h index e3d82b7..0e4bd5a 100644 --- a/Source/Asura/Graphics/Animation.h +++ b/Source/Asura/Graphics/Animation.h @@ -3,6 +3,11 @@ #include "Sprite.h" #include "Component.h" +#include "Manager.hpp" +#include "SpriteRenderer.h" +#include "Containers/Map.h" +#include "Containers/Vector.hpp" +#include "Containers/StringMap.hpp" namespace AsuraEngine { @@ -12,9 +17,10 @@ namespace AsuraEngine /// /// 关键帧 /// - class AnimationKeyFrame + struct AnimationKeyFrame { - + float time; + Sprite* sprite; }; /// @@ -24,12 +30,78 @@ namespace AsuraEngine { public: + enum UpdateMask + { + Scale = 1, + Position = 1 << 1, + Rotation = 1 << 2, + Sprite = 1 << 3 + }; + + struct Definition + { + + }; + + void OnEnable() override; + void OnUpdate(uint32 milliseconds) override; + + void SetSpeed(float speed); + + private: + + Containers::Vector mFrames; + + float mTime; + + bool mLoop; + + /// + /// 速度,默认为1 + /// + float mSpeed; + + /// + /// + /// + uint mKey; + + Containers::String mName; + + UpdateMask mUpdateMask; + + SpriteRenderer* mSpriteRenderer; + + }; + + class AnimationManager : public Manager + { + public: + + Containers::String GetAnimationName(uint ID); + + uint GetAnimationID(const Containers::String& name); + + Animation* GetAnimation(uint ID); + + Animation* GetAnimation(const Containers::String& name); + + /// + /// 添加动画并返回ID + /// + uint AddAnimation(Animation* animation); + private: /// + /// 映射ID到animation + /// + Containers::StringMap mAnimationIDs; + /// + /// 映射key到animation /// - Sprite* mSprite; + Containers::Map mAnimations; }; diff --git a/Source/Asura/Graphics/Camera.h b/Source/Asura/Graphics/Camera.h index 9da6ab0..699d342 100644 --- a/Source/Asura/Graphics/Camera.h +++ b/Source/Asura/Graphics/Camera.h @@ -29,6 +29,11 @@ namespace AsuraEngine /// bool mIsOnScreen; + /// + /// 裁剪 + /// + bool mIsCulling; + }; } diff --git a/Source/Asura/Graphics/Image.h b/Source/Asura/Graphics/Image.h index 198ad9e..34a83ce 100644 --- a/Source/Asura/Graphics/Image.h +++ b/Source/Asura/Graphics/Image.h @@ -2,6 +2,7 @@ #define __AE_IMAGE_H__ #include "Math/Vector2.h" +#include "Manager.hpp" #include "Object.h" namespace AsuraEngine @@ -10,8 +11,8 @@ namespace AsuraEngine { /// - /// Image是图片从内存中载入后,读取进游戏后保存的结果。一个Image在内存、显存中只会保存一份,不会产生副本。需要特 - /// 征化的区别image,如锚点位置,缩放和旋转角度,使用sprite。基本是一个只读类。 + /// Image是图片从内存中载入后,读取进游戏后保存的结果。一个Image在内存、显存中只会保存一份,不会产生副本。需要特征 + /// 化的区别image,如锚点位置,缩放和旋转角度,使用sprite。基本是一个只读类。 /// class Image final : public Object { @@ -30,6 +31,34 @@ namespace AsuraEngine }; + class ImageManager : public Manager + { + public: + + uint GetImagePath(uint ID); + + uint GetImageID(const Containers::String& path); + + Image* GetImage(const Containers::String& path); + + Image* GetImage(const Containers::String& id); + + uint AddImage(const Containers::String& path, Image* image); + + private: + + /// + /// 所有的image + /// + Containers::Map mImages; + + /// + /// 所有的image,路径和ID的映射 + /// + Containers::StringMap mImageIDs; + + }; + } } diff --git a/Source/Asura/Graphics/Material.h b/Source/Asura/Graphics/Material.h index 13c066a..56db3d9 100644 --- a/Source/Asura/Graphics/Material.h +++ b/Source/Asura/Graphics/Material.h @@ -11,6 +11,7 @@ #include "Shader.h" #include "Texture.h" +#include "Manager.hpp" namespace AsuraEngine { @@ -143,6 +144,11 @@ namespace AsuraEngine }; + class MaterialManager : public Manager + { + + }; + } } diff --git a/Source/Asura/Graphics/Shader.h b/Source/Asura/Graphics/Shader.h index ccd38af..b1e9c7a 100644 --- a/Source/Asura/Graphics/Shader.h +++ b/Source/Asura/Graphics/Shader.h @@ -7,6 +7,7 @@ #include "Containers/StringMap.hpp" #include "Object.h" #include "Color.h" +#include "Manager.hpp" namespace AsuraEngine { @@ -54,6 +55,11 @@ namespace AsuraEngine }; + class ShaderManager final : public Manager + { + + }; + } } diff --git a/Source/Asura/Graphics/Sprite.h b/Source/Asura/Graphics/Sprite.h index b573c45..581ee87 100644 --- a/Source/Asura/Graphics/Sprite.h +++ b/Source/Asura/Graphics/Sprite.h @@ -31,7 +31,16 @@ namespace AsuraEngine }; - void SetImage(Image* image); + struct SpriteDef + { + Image* image; + Align align; + Math::Vector2 anchor; + Math::Vector2 size; + }; + + Sprite(SpriteDef definition); + ~Sprite(); private: @@ -45,11 +54,6 @@ namespace AsuraEngine /// Math::Vector2 size; - /// - /// 相对于GameObject的transform。 - /// - Transform mTransform; - /// /// 绑定的image /// diff --git a/Source/Asura/Graphics/SpriteRenderer.h b/Source/Asura/Graphics/SpriteRenderer.h index 4df932c..bd81509 100644 --- a/Source/Asura/Graphics/SpriteRenderer.h +++ b/Source/Asura/Graphics/SpriteRenderer.h @@ -12,6 +12,9 @@ namespace AsuraEngine class SpriteRenderer final : public Renderer { public: + + void SetSprite(Sprite* sprite); + void OnRender() override; private: diff --git a/Source/Asura/Manager.hpp b/Source/Asura/Manager.hpp new file mode 100644 index 0000000..5a94889 --- /dev/null +++ b/Source/Asura/Manager.hpp @@ -0,0 +1,14 @@ +#ifndef __AE_MANAGER_H__ +#define __AE_MANAGER_H__ + +namespace AsuraEngine +{ + + class Manager + { + + }; + +} + +#endif \ No newline at end of file diff --git a/Source/Asura/Scene.h b/Source/Asura/Scene.h index 2fc4649..c873751 100644 --- a/Source/Asura/Scene.h +++ b/Source/Asura/Scene.h @@ -1,11 +1,22 @@ #ifndef __AE_SCENE_H__ #define __AE_SCENE_H__ +#include "Containers/Vector.hpp" +#include "GameObject.h" + namespace AsuraEngine { + /// + /// 游戏场景 + /// class Scene { + public: + + private: + + Containers::Vector mGameObjects; }; -- cgit v1.1-26-g67d0