diff options
Diffstat (limited to 'source/modules')
45 files changed, 2140 insertions, 1388 deletions
diff --git a/source/modules/asura-box2d/Physics/Body.h b/source/modules/asura-box2d/Physics/Body.h index e5af76a..ecf5bab 100644 --- a/source/modules/asura-box2d/Physics/Body.h +++ b/source/modules/asura-box2d/Physics/Body.h @@ -3,65 +3,62 @@ #include <Box2D/Box2D.h> +#include <asura-utils/Classes.h> #include <asura-utils/Scripting/Portable.hpp> -namespace AsuraEngine -{ - namespace Physics - { - - class World; - class Joint; +namespace_begin(AsuraEngine) +namespace_begin(Physics) - enum BodyType - { - BODY_TYPE_INVALID, - BODY_TYPE_STATIC, - BODY_TYPE_DYNAMIC, - BODY_TYPE_KINEMATIC - }; +class World; +class Joint; - class Body - : public AEScripting::Portable<Body> - { - public: +enum BodyType +{ + BODY_TYPE_INVALID, + BODY_TYPE_STATIC, + BODY_TYPE_DYNAMIC, + BODY_TYPE_KINEMATIC +}; - private: +class Body : public AEScripting::Portable<Body> +{ +public: - friend class Joint; +private: - //----------------------------------------------------------------------------// + friend class Joint; - LUAX_DECL_FACTORY(Body); + //----------------------------------------------------------------------------// - LUAX_DECL_ENUM(BodyType, 1); + LUAX_DECL_FACTORY(Body); - LUAX_DECL_METHOD(_GetType); - LUAX_DECL_METHOD(_GetX); - LUAX_DECL_METHOD(_GetY); - LUAX_DECL_METHOD(_GetAngle); - LUAX_DECL_METHOD(_GetPosition); - LUAX_DECL_METHOD(_GetLinearVelocity); - LUAX_DECL_METHOD(_GetWorldCenter); - LUAX_DECL_METHOD(_GetLocalCenter); - LUAX_DECL_METHOD(_GetAngularVelocity); - LUAX_DECL_METHOD(_GetMass); - LUAX_DECL_METHOD(_GetInertia); - LUAX_DECL_METHOD(_GetMassData); - LUAX_DECL_METHOD(_GetAngularDamping); - LUAX_DECL_METHOD(_GetLinearDamping); - LUAX_DECL_METHOD(_GetGravityScale); - LUAX_DECL_METHOD(_GetGravityScale); + LUAX_DECL_ENUM(BodyType, 1); - //----------------------------------------------------------------------------// + LUAX_DECL_METHOD(_GetType); + LUAX_DECL_METHOD(_GetX); + LUAX_DECL_METHOD(_GetY); + LUAX_DECL_METHOD(_GetAngle); + LUAX_DECL_METHOD(_GetPosition); + LUAX_DECL_METHOD(_GetLinearVelocity); + LUAX_DECL_METHOD(_GetWorldCenter); + LUAX_DECL_METHOD(_GetLocalCenter); + LUAX_DECL_METHOD(_GetAngularVelocity); + LUAX_DECL_METHOD(_GetMass); + LUAX_DECL_METHOD(_GetInertia); + LUAX_DECL_METHOD(_GetMassData); + LUAX_DECL_METHOD(_GetAngularDamping); + LUAX_DECL_METHOD(_GetLinearDamping); + LUAX_DECL_METHOD(_GetGravityScale); + LUAX_DECL_METHOD(_GetGravityScale); - b2Body *body; + //----------------------------------------------------------------------------// - World* mWorld; + b2Body* m_Body; + World* m_World; - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-box2d/Physics/ChainShape.h b/source/modules/asura-box2d/Physics/ChainShape.h index 2ce19fb..9a88263 100644 --- a/source/modules/asura-box2d/Physics/ChainShape.h +++ b/source/modules/asura-box2d/Physics/ChainShape.h @@ -19,7 +19,7 @@ public: private: - b2ChainShape* mShape; + b2ChainShape* m_Shape; }; diff --git a/source/modules/asura-box2d/Physics/Fixture.h b/source/modules/asura-box2d/Physics/Fixture.h index e69de29..a9f0fc7 100644 --- a/source/modules/asura-box2d/Physics/Fixture.h +++ b/source/modules/asura-box2d/Physics/Fixture.h @@ -0,0 +1,17 @@ +#ifndef _ASRUA_ENGINE_FIXTURE_H_ +#define _ASRUA_ENGINE_FIXTURE_H_ + +#include <asura-utils/Classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Physics) + +class Fixture +{ + +}; + +namespace_end +namespace_end + +#endif diff --git a/source/modules/asura-box2d/Physics/World.h b/source/modules/asura-box2d/Physics/World.h index b6d00ca..0419275 100644 --- a/source/modules/asura-box2d/Physics/World.h +++ b/source/modules/asura-box2d/Physics/World.h @@ -1,19 +1,18 @@ #ifndef __ASURA_BOX2D_WORLD_H__ #define __ASURA_BOX2D_WORLD_H__ +#include <asura-utils/Classes.h> #include <asura-utils/Scripting/Portable.hpp> -namespace AsuraEngine -{ - namespace Physics - { +namespace_begin(AsuraEngine) +namespace_begin(Physics) - class World : public AEScripting::Portable<World> - { +class World : public AEScripting::Portable<World> +{ - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-box2d/physics/body.h b/source/modules/asura-box2d/physics/body.h index e5af76a..ecf5bab 100644 --- a/source/modules/asura-box2d/physics/body.h +++ b/source/modules/asura-box2d/physics/body.h @@ -3,65 +3,62 @@ #include <Box2D/Box2D.h> +#include <asura-utils/Classes.h> #include <asura-utils/Scripting/Portable.hpp> -namespace AsuraEngine -{ - namespace Physics - { - - class World; - class Joint; +namespace_begin(AsuraEngine) +namespace_begin(Physics) - enum BodyType - { - BODY_TYPE_INVALID, - BODY_TYPE_STATIC, - BODY_TYPE_DYNAMIC, - BODY_TYPE_KINEMATIC - }; +class World; +class Joint; - class Body - : public AEScripting::Portable<Body> - { - public: +enum BodyType +{ + BODY_TYPE_INVALID, + BODY_TYPE_STATIC, + BODY_TYPE_DYNAMIC, + BODY_TYPE_KINEMATIC +}; - private: +class Body : public AEScripting::Portable<Body> +{ +public: - friend class Joint; +private: - //----------------------------------------------------------------------------// + friend class Joint; - LUAX_DECL_FACTORY(Body); + //----------------------------------------------------------------------------// - LUAX_DECL_ENUM(BodyType, 1); + LUAX_DECL_FACTORY(Body); - LUAX_DECL_METHOD(_GetType); - LUAX_DECL_METHOD(_GetX); - LUAX_DECL_METHOD(_GetY); - LUAX_DECL_METHOD(_GetAngle); - LUAX_DECL_METHOD(_GetPosition); - LUAX_DECL_METHOD(_GetLinearVelocity); - LUAX_DECL_METHOD(_GetWorldCenter); - LUAX_DECL_METHOD(_GetLocalCenter); - LUAX_DECL_METHOD(_GetAngularVelocity); - LUAX_DECL_METHOD(_GetMass); - LUAX_DECL_METHOD(_GetInertia); - LUAX_DECL_METHOD(_GetMassData); - LUAX_DECL_METHOD(_GetAngularDamping); - LUAX_DECL_METHOD(_GetLinearDamping); - LUAX_DECL_METHOD(_GetGravityScale); - LUAX_DECL_METHOD(_GetGravityScale); + LUAX_DECL_ENUM(BodyType, 1); - //----------------------------------------------------------------------------// + LUAX_DECL_METHOD(_GetType); + LUAX_DECL_METHOD(_GetX); + LUAX_DECL_METHOD(_GetY); + LUAX_DECL_METHOD(_GetAngle); + LUAX_DECL_METHOD(_GetPosition); + LUAX_DECL_METHOD(_GetLinearVelocity); + LUAX_DECL_METHOD(_GetWorldCenter); + LUAX_DECL_METHOD(_GetLocalCenter); + LUAX_DECL_METHOD(_GetAngularVelocity); + LUAX_DECL_METHOD(_GetMass); + LUAX_DECL_METHOD(_GetInertia); + LUAX_DECL_METHOD(_GetMassData); + LUAX_DECL_METHOD(_GetAngularDamping); + LUAX_DECL_METHOD(_GetLinearDamping); + LUAX_DECL_METHOD(_GetGravityScale); + LUAX_DECL_METHOD(_GetGravityScale); - b2Body *body; + //----------------------------------------------------------------------------// - World* mWorld; + b2Body* m_Body; + World* m_World; - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-box2d/physics/fixture.h b/source/modules/asura-box2d/physics/fixture.h index e69de29..a9f0fc7 100644 --- a/source/modules/asura-box2d/physics/fixture.h +++ b/source/modules/asura-box2d/physics/fixture.h @@ -0,0 +1,17 @@ +#ifndef _ASRUA_ENGINE_FIXTURE_H_ +#define _ASRUA_ENGINE_FIXTURE_H_ + +#include <asura-utils/Classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Physics) + +class Fixture +{ + +}; + +namespace_end +namespace_end + +#endif diff --git a/source/modules/asura-box2d/physics/world.h b/source/modules/asura-box2d/physics/world.h index b6d00ca..0419275 100644 --- a/source/modules/asura-box2d/physics/world.h +++ b/source/modules/asura-box2d/physics/world.h @@ -1,19 +1,18 @@ #ifndef __ASURA_BOX2D_WORLD_H__ #define __ASURA_BOX2D_WORLD_H__ +#include <asura-utils/Classes.h> #include <asura-utils/Scripting/Portable.hpp> -namespace AsuraEngine -{ - namespace Physics - { +namespace_begin(AsuraEngine) +namespace_begin(Physics) - class World : public AEScripting::Portable<World> - { +class World : public AEScripting::Portable<World> +{ - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/Application.h b/source/modules/asura-core/Application.h index ea5faa7..696d125 100644 --- a/source/modules/asura-core/Application.h +++ b/source/modules/asura-core/Application.h @@ -38,40 +38,28 @@ public: virtual ~Application(); - /// - /// ʼǰϵͳ - /// + // ʼǰϵͳ bool InitSubModules(uint flag = ASURA_MODULE_ALL); - /// - /// - /// + // virtual void Run(int argc, char* args[]); - /// - /// ˳runʱĴ - /// + // ˳runʱĴ virtual void OnExit(); protected: - /// - /// moduleapplicationӵmoduleȨ - /// + // moduleapplicationӵmoduleȨ void EnqueueModule(Module* module); private: - /// /// ̵߳lua state handleӦѭСһ˵ֻҪ߳һlua_State̲߳Ҫ̼߳ /// lua̫ʹˡC++дȻעһصһ̴߳lua_Stateעắִк /// ̵߳lua_Stateֻ֤һnativeʵ֮һlua_State - /// Luax::LuaxVM* m_VM; - /// - /// Asura libsᰴն˳ʼ˳ʱִ˳ - /// + // Asura libsᰴն˳ʼ˳ʱִ˳ std::queue<Module*> m_Modules; }; diff --git a/source/modules/asura-core/Graphics/DrawInfo.h b/source/modules/asura-core/Graphics/DrawInfo.h index f0e375b..9042f2f 100644 --- a/source/modules/asura-core/Graphics/DrawInfo.h +++ b/source/modules/asura-core/Graphics/DrawInfo.h @@ -6,6 +6,7 @@ namespace_begin(AsuraEngine) namespace_begin(Graphics) +/// struct DrawInfo { diff --git a/source/modules/asura-core/Graphics/DrawUtil.cpp b/source/modules/asura-core/Graphics/DrawUtil.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/Graphics/DrawUtil.cpp diff --git a/source/modules/asura-core/Graphics/DrawUtil.h b/source/modules/asura-core/Graphics/DrawUtil.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/Graphics/DrawUtil.h diff --git a/source/modules/asura-core/Graphics/GPUBuffer.h b/source/modules/asura-core/Graphics/GPUBuffer.h index bb40055..0aa3c29 100644 --- a/source/modules/asura-core/Graphics/GPUBuffer.h +++ b/source/modules/asura-core/Graphics/GPUBuffer.h @@ -31,8 +31,7 @@ enum BufferDataType }; /// -/// VRAM壬ֶ㻺vboebo֣ÿζڴԴϴݡframeworkrenderers -/// +/// VRAM壬ֶ㻺vboebo֣ÿζڴԴϴݡframeworkrenderersй /// ASURA_ABSTRACT class GPUBuffer { @@ -62,10 +61,9 @@ private: GLenum m_Target; GLuint m_Buffer; - /// openglԴ滺岢ûж͵ҪֻglVertexAttribPointerʱָdrawcall ʱݸ - /// ʼַʹbufferȡඥݣԲͬͿԱһbufferСΪ˱ - /// ӿڵļ࣬ڳʼbufferʱָͣڱ͵һ£Բͬ - /// ͷͬbuffer + /// openglԴ滺岢ûж͵ҪֻglVertexAttribPointerʱָdrawcall ʱݸ + /// ʼַʹbufferȡඥݣԲͬͿԱһbufferСΪ˱ֽӿڵļ࣬ + /// ʼbufferʱָͣڱ͵һ£Բͬͷͬbuffer GLenum m_DataType; GLuint m_Usage; diff --git a/source/modules/asura-core/Graphics/GfxDevice.cpp b/source/modules/asura-core/Graphics/GfxDevice.cpp index ef324e3..ea95f54 100644 --- a/source/modules/asura-core/Graphics/GfxDevice.cpp +++ b/source/modules/asura-core/Graphics/GfxDevice.cpp @@ -82,16 +82,6 @@ Color& GfxDevice::GetDrawColor() return state.drawColor; } -Canvas* GfxDevice::GetActiveCanvas() const -{ - return state.canvas; -} - -void GfxDevice::SetActiveCanvas(Canvas* canvas) -{ - state.canvas = canvas; -} - void GfxDevice::SetViewport(const Recti v) { state.viewport = v; @@ -136,16 +126,6 @@ void GfxDevice::DrawArrays(GLenum mode, GLint first, GLsizei count) state.shader->OnUsed(); } -void GfxDevice::SetMatrixMode (MatrixMode mode) -{ - state.matrixMode = mode; -} - -MatrixMode GfxDevice::GetMatrixMode () -{ - return state.matrixMode; -} - void GfxDevice::PushMatrix () { state.matrix[state.matrixMode].Push (); diff --git a/source/modules/asura-core/Graphics/GfxDevice.h b/source/modules/asura-core/Graphics/GfxDevice.h index 1f50b57..02c7392 100644 --- a/source/modules/asura-core/Graphics/GfxDevice.h +++ b/source/modules/asura-core/Graphics/GfxDevice.h @@ -42,47 +42,44 @@ public: static GfxDevice& Get(); - int GetParam(GLParams param); + int GetParam(GLParams param); - bool Init(const AEMath::Recti& viewport); - bool Inited(); + bool Init(const AEMath::Recti& viewport); + bool Inited(); - void SetViewport(const AEMath::Recti viewport); + void SetViewport(const AEMath::Recti viewport); const AEMath::Recti& GetViewport(); - void SetMatrixMode(MatrixMode mode); - MatrixMode GetMatrixMode(); + void PushMatrix(); + void PopMatrix(); - void PushMatrix(); - void PopMatrix(); + void LoadIdentity(); + void Rotate(float angle); + void Translate(float x, float y); + void Scale(float x, float y); + void Ortho(float l, float r, float b, float t, float n, float f); - void LoadIdentity(); - void Rotate(float angle); - void Translate(float x, float y); - void Scale(float x, float y); - void Ortho(float l, float r, float b, float t, float n, float f); + uint GetMatrixDepth(); + uint GetMatrixIndex(); - uint GetMatrixDepth(); - uint GetMatrixIndex(); + void DrawArrays(GLenum mode, GLint first, GLsizei count); AEMath::Matrix44& GetMatrix(MatrixMode mode); AEMath::Matrix44 GetMVPMatrix(); - void SetDrawColor(float r, float g, float b, float a); - Color& GetDrawColor(); - - void SetActiveCanvas(Canvas* = NULL); - Canvas* GetActiveCanvas() const; + void SetDrawColor(float r, float g, float b, float a); + Color& GetDrawColor(); void SetActiveShader(Shader* = NULL); Shader* GetActiveShader() const; - void DrawArrays(GLenum mode, GLint first, GLsizei count); + void WipeError(); + bool HasError(); + GLenum GetError(); - void WipeError(); - bool HasError(); - GLenum GetError(); + GET_SET(MatrixMode, MatrixMode, state.matrixMode); + GET_SET(Canvas*, ActiveCanvas, state.canvas); private: @@ -130,9 +127,14 @@ luaxport: }; -// ȫ GfxDevice extern GfxDevice g_Device; + +#define GL_CALL(x) do { x; /*GLAssert(); */} while(0) + + + + namespace_end namespace_end diff --git a/source/modules/asura-core/Graphics/GraphicsHelper.cpp b/source/modules/asura-core/Graphics/GraphicsHelper.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/Graphics/GraphicsHelper.cpp diff --git a/source/modules/asura-core/Graphics/GraphicsHelper.h b/source/modules/asura-core/Graphics/GraphicsHelper.h new file mode 100644 index 0000000..b93756a --- /dev/null +++ b/source/modules/asura-core/Graphics/GraphicsHelper.h @@ -0,0 +1,15 @@ +#ifndef _ASURA_GRAPHICS_HELPER_H_ +#define _ASURA_GRAPHICS_HELPER_H_ + +#include <asura-utils/Classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + + +namespace_end +namespace_end + +#endif diff --git a/source/modules/asura-core/Graphics/Polygon2D.cpp b/source/modules/asura-core/Graphics/Polygon2D.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/Graphics/Polygon2D.cpp diff --git a/source/modules/asura-core/Graphics/Polygon2D.h b/source/modules/asura-core/Graphics/Polygon2D.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/Graphics/Polygon2D.h diff --git a/source/modules/asura-core/Graphics/VBO.cpp b/source/modules/asura-core/Graphics/VBO.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/Graphics/VBO.cpp diff --git a/source/modules/asura-core/Graphics/VBO.h b/source/modules/asura-core/Graphics/VBO.h new file mode 100644 index 0000000..80f405f --- /dev/null +++ b/source/modules/asura-core/Graphics/VBO.h @@ -0,0 +1,27 @@ +#ifndef _ASURA_ENGINE_VBO_H_ +#define _ASURA_ENGINE_VBO_H_ + +#include <asura-utils/Classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +struct VertexBufferData +{ + +}; + +struct IndexBufferData +{ + +}; + +class VBO +{ + +}; + +namespace_end +namespace_end + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/Input/InputAxis.cpp b/source/modules/asura-core/Input/InputAxis.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/Input/InputAxis.cpp diff --git a/source/modules/asura-core/Input/InputAxis.h b/source/modules/asura-core/Input/InputAxis.h new file mode 100644 index 0000000..3052f0b --- /dev/null +++ b/source/modules/asura-core/Input/InputAxis.h @@ -0,0 +1,15 @@ +#ifndef _ASURA_ENGINE_INPUT_AXIS_H_ +#define _ASURA_ENGINE_INPUT_AXIS_H_ + +#include <asura-utils/Classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Input) + +class InputAxis {}; + + +namespace_end +namespace_end + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/Input/InputDevice.cpp b/source/modules/asura-core/Input/InputDevice.cpp index e69de29..0c9c42f 100644 --- a/source/modules/asura-core/Input/InputDevice.cpp +++ b/source/modules/asura-core/Input/InputDevice.cpp @@ -0,0 +1,10 @@ +#include "InputDevice.h" + +namespace_begin(AsuraEngine) +namespace_begin(Input) + + + + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/Input/InputDevice.h b/source/modules/asura-core/Input/InputDevice.h index 39f3d37..0ecce99 100644 --- a/source/modules/asura-core/Input/InputDevice.h +++ b/source/modules/asura-core/Input/InputDevice.h @@ -8,29 +8,35 @@ #include "../CoreConfig.h" #include "KeyboardState.h" +#include "MouseState.h" +#include "JoystickState.h" namespace_begin(AsuraEngine) namespace_begin(Input) -/// ͬƽ̨̳ಢʵhandleӿ -ASURA_ABSTRACT class InputDevice : public Singleton<InputDevice> +class InputDevice { -protected: +public: - void OnKeyDown(int key); - void OnKeyUp(int key); + InputDevice(); + virtual ~InputDevice(); - void OnMouseMove(const AEMath::Vector2f& position); +protected: - void OnMouseButtonDown(int key); - void OnMouseButtonUp(int key); + virtual bool UpdateState(); - void OnMouseWheel(); + MouseState m_Mouse; + KeyboardState m_Keyboard; + JoystickState m_Joysticks; - void OnInputChar(); +private: + + bool UpdateMousePosition(); }; +//bool ConvertPositionToClientAreaCoord(); + namespace_end namespace_end diff --git a/source/modules/asura-core/Input/InputEvent.cpp b/source/modules/asura-core/Input/InputEvent.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/Input/InputEvent.cpp diff --git a/source/modules/asura-core/Input/InputEvent.h b/source/modules/asura-core/Input/InputEvent.h new file mode 100644 index 0000000..2c5b84b --- /dev/null +++ b/source/modules/asura-core/Input/InputEvent.h @@ -0,0 +1,21 @@ +#ifndef _ASURA_ENGINE_INPUT_EVENT_H_ +#define _ASURA_ENGINE_INPUT_EVENT_H_ + +#include <asura-utils/Classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Input) + +struct InputEvent +{ + InputEvent(); + ~InputEvent(); + +}; + +//InputEvent ConvertInputEvent(); + +namespace_end +namespace_end + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/Input/InputManager.cpp b/source/modules/asura-core/Input/InputManager.cpp index e69de29..fe49c29 100644 --- a/source/modules/asura-core/Input/InputManager.cpp +++ b/source/modules/asura-core/Input/InputManager.cpp @@ -0,0 +1,124 @@ +#include "InputManager.h" + +namespace_begin(AsuraEngine) +namespace_begin(Input) + +InputManager::InputManager() +{ +} + +InputManager::~InputManager() +{ +} + +void InputManager::Reset() +{ +} + +bool InputManager::GetButton(const std::string& name) +{ +} + +bool InputManager::GetButtonDown(const std::string& name) +{ +} + +bool InputManager::GetButtonUp(const std::string& name) +{ +} + +bool InputManager::HasAxisOrButton(const std::string& name) +{ +} + +float InputManager::GetAxis(const std::string& name) +{ +} + +float InputManager::GetAxisRaw(const std::string& name) +{ +} + +bool InputManager::GetMouseButton(int mouseBut) +{ +} + +bool InputManager::GetMouseButtonState(int mouseBut) +{ +} + +bool InputManager::GetMouseButtonDown(int mouseBut) +{ +} + +bool InputManager::GetMouseButtonUp(int mouseBut) +{ +} + + +bool InputManager::GetKey(int key) +{ +} + +bool InputManager::GetKeyDown(int key) +{ +} + +bool InputManager::GetKeyUp(int key) +{ +} + + +const AEMath::Vector2f& InputManager::GetMouseDelta() +{ +} + +const AEMath::Vector2f& InputManager::GetMousePosition() +{ +} + + +float InputManager::GetJoystickPosition() +{ +} + +void InputManager::setJoystickPosition() +{ +} + + +void InputManager::SetKeyState(int key, bool state) +{ + // This ignores keyRepeats (multiple keydown without a keyup event between) + if (state && !m_CurrentKeyState[key]) + m_ThisFrameKeyDown[key] = true; + if (!state && m_CurrentKeyState[key]) + m_ThisFrameKeyUp[key] = true; + + m_CurrentKeyState[key] = state; +} + +void InputManager::SetMouseDelta(const AEMath::Vector2f& delta) +{ +} + +void InputManager::SetMousePosition(const AEMath::Vector2f& pos) +{ +} + +void InputManager::SetMouseButton(int button, bool enabled) +{ +} + + +void InputManager::ProcessInput() +{ +} + +void InputManager::SendInputEvents() +{ +} + + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/Input/InputManager.h b/source/modules/asura-core/Input/InputManager.h index dd11b2f..bbdafd8 100644 --- a/source/modules/asura-core/Input/InputManager.h +++ b/source/modules/asura-core/Input/InputManager.h @@ -1,23 +1,351 @@ -#ifndef __INPUT_MAMANGER_H__ -#define __INPUT_MAMANGER_H__ +#ifndef _ASURA_INPUT_MAMANGER_H_ +#define _ASURA_INPUT_MAMANGER_H_ +#include <asura-utils/Math/Vector2.hpp> #include <asura-utils/Scripting/Portable.hpp> #include <asura-utils/Singleton.hpp> #include <asura-utils/Classes.h> +#include <asura-utils/dynamic_bitset.h> + +#include <string> +#include <vector> + +#include "InputAxis.h" namespace_begin(AsuraEngine) namespace_begin(Input) -/// class InputManager : public Singleton<InputManager> { -public : +public: + + InputManager(); + ~InputManager(); + + void Reset(); + + bool GetButton(const std::string& name); + bool GetButtonDown(const std::string& name); + bool GetButtonUp(const std::string& name); + bool HasAxisOrButton(const std::string& name); + float GetAxis(const std::string& name); + float GetAxisRaw(const std::string& name); + + bool GetMouseButton(int mouseBut); + bool GetMouseButtonState(int mouseBut); + bool GetMouseButtonDown(int mouseBut); + bool GetMouseButtonUp(int mouseBut); + + bool GetKey(int key); + bool GetKeyDown(int key); + bool GetKeyUp(int key); + + const AEMath::Vector2f& GetMouseDelta(); + const AEMath::Vector2f& GetMousePosition(); + + float GetJoystickPosition(); + void setJoystickPosition(); + + void SetKeyState(int key, bool state); + void SetMouseDelta(const AEMath::Vector2f& delta); + void SetMousePosition(const AEMath::Vector2f& pos); + void SetMouseButton(int button, bool enabled); + + void ProcessInput(); + void SendInputEvents(); + +private: + + dynamic_bitset m_CurrentKeyState; + dynamic_bitset m_ThisFrameKeyDown; + dynamic_bitset m_ThisFrameKeyUp; + + std::vector<InputAxis> m_Axis; + + AEMath::Vector2f m_MouseDelta; + AEMath::Vector2f m_MousePos; + bool m_MousePresent; -private : + std::vector<std::vector<float>> m_JoystickPos; + + std::string m_InputString; + std::string m_CompositionString; + + AEMath::Vector2f m_TextFieldCursorPos; + bool m_TextFieldInput; + + bool m_EatKeyPressOnTextFieldFocus; + int m_IMECompositionMode; + bool m_IMEIsSelected; + + int m_LastJoyNum, m_LastJoyAxis; + bool m_ShouldQuit; + bool m_SimulateMouseWithTouches; }; +// keyboard keys +enum { + /* The keyboard syms have been cleverly chosen to map to ASCII */ + SDLK_UNKNOWN = 0, + SDLK_FIRST = 0, + SDLK_BACKSPACE = 8, + SDLK_TAB = 9, + SDLK_CLEAR = 12, + SDLK_RETURN = 13, + SDLK_PAUSE = 19, + SDLK_ESCAPE = 27, + SDLK_SPACE = 32, + SDLK_EXCLAIM = 33, + SDLK_QUOTEDBL = 34, + SDLK_HASH = 35, + SDLK_DOLLAR = 36, + SDLK_AMPERSAND = 38, + SDLK_QUOTE = 39, + SDLK_LEFTPAREN = 40, + SDLK_RIGHTPAREN = 41, + SDLK_ASTERISK = 42, + SDLK_PLUS = 43, + SDLK_COMMA = 44, + SDLK_MINUS = 45, + SDLK_PERIOD = 46, + SDLK_SLASH = 47, + SDLK_0 = 48, + SDLK_1 = 49, + SDLK_2 = 50, + SDLK_3 = 51, + SDLK_4 = 52, + SDLK_5 = 53, + SDLK_6 = 54, + SDLK_7 = 55, + SDLK_8 = 56, + SDLK_9 = 57, + SDLK_COLON = 58, + SDLK_SEMICOLON = 59, + SDLK_LESS = 60, + SDLK_EQUALS = 61, + SDLK_GREATER = 62, + SDLK_QUESTION = 63, + SDLK_AT = 64, + /* + Skip uppercase letters + */ + SDLK_LEFTBRACKET = 91, + SDLK_BACKSLASH = 92, + SDLK_RIGHTBRACKET = 93, + SDLK_CARET = 94, + SDLK_UNDERSCORE = 95, + SDLK_BACKQUOTE = 96, + SDLK_a = 97, + SDLK_b = 98, + SDLK_c = 99, + SDLK_d = 100, + SDLK_e = 101, + SDLK_f = 102, + SDLK_g = 103, + SDLK_h = 104, + SDLK_i = 105, + SDLK_j = 106, + SDLK_k = 107, + SDLK_l = 108, + SDLK_m = 109, + SDLK_n = 110, + SDLK_o = 111, + SDLK_p = 112, + SDLK_q = 113, + SDLK_r = 114, + SDLK_s = 115, + SDLK_t = 116, + SDLK_u = 117, + SDLK_v = 118, + SDLK_w = 119, + SDLK_x = 120, + SDLK_y = 121, + SDLK_z = 122, + SDLK_DELETE = 127, + /* End of ASCII mapped keysyms */ + + /* International keyboard syms */ + SDLK_WORLD_0 = 160, /* 0xA0 */ + SDLK_WORLD_1 = 161, + SDLK_WORLD_2 = 162, + SDLK_WORLD_3 = 163, + SDLK_WORLD_4 = 164, + SDLK_WORLD_5 = 165, + SDLK_WORLD_6 = 166, + SDLK_WORLD_7 = 167, + SDLK_WORLD_8 = 168, + SDLK_WORLD_9 = 169, + SDLK_WORLD_10 = 170, + SDLK_WORLD_11 = 171, + SDLK_WORLD_12 = 172, + SDLK_WORLD_13 = 173, + SDLK_WORLD_14 = 174, + SDLK_WORLD_15 = 175, + SDLK_WORLD_16 = 176, + SDLK_WORLD_17 = 177, + SDLK_WORLD_18 = 178, + SDLK_WORLD_19 = 179, + SDLK_WORLD_20 = 180, + SDLK_WORLD_21 = 181, + SDLK_WORLD_22 = 182, + SDLK_WORLD_23 = 183, + SDLK_WORLD_24 = 184, + SDLK_WORLD_25 = 185, + SDLK_WORLD_26 = 186, + SDLK_WORLD_27 = 187, + SDLK_WORLD_28 = 188, + SDLK_WORLD_29 = 189, + SDLK_WORLD_30 = 190, + SDLK_WORLD_31 = 191, + SDLK_WORLD_32 = 192, + SDLK_WORLD_33 = 193, + SDLK_WORLD_34 = 194, + SDLK_WORLD_35 = 195, + SDLK_WORLD_36 = 196, + SDLK_WORLD_37 = 197, + SDLK_WORLD_38 = 198, + SDLK_WORLD_39 = 199, + SDLK_WORLD_40 = 200, + SDLK_WORLD_41 = 201, + SDLK_WORLD_42 = 202, + SDLK_WORLD_43 = 203, + SDLK_WORLD_44 = 204, + SDLK_WORLD_45 = 205, + SDLK_WORLD_46 = 206, + SDLK_WORLD_47 = 207, + SDLK_WORLD_48 = 208, + SDLK_WORLD_49 = 209, + SDLK_WORLD_50 = 210, + SDLK_WORLD_51 = 211, + SDLK_WORLD_52 = 212, + SDLK_WORLD_53 = 213, + SDLK_WORLD_54 = 214, + SDLK_WORLD_55 = 215, + SDLK_WORLD_56 = 216, + SDLK_WORLD_57 = 217, + SDLK_WORLD_58 = 218, + SDLK_WORLD_59 = 219, + SDLK_WORLD_60 = 220, + SDLK_WORLD_61 = 221, + SDLK_WORLD_62 = 222, + SDLK_WORLD_63 = 223, + SDLK_WORLD_64 = 224, + SDLK_WORLD_65 = 225, + SDLK_WORLD_66 = 226, + SDLK_WORLD_67 = 227, + SDLK_WORLD_68 = 228, + SDLK_WORLD_69 = 229, + SDLK_WORLD_70 = 230, + SDLK_WORLD_71 = 231, + SDLK_WORLD_72 = 232, + SDLK_WORLD_73 = 233, + SDLK_WORLD_74 = 234, + SDLK_WORLD_75 = 235, + SDLK_WORLD_76 = 236, + SDLK_WORLD_77 = 237, + SDLK_WORLD_78 = 238, + SDLK_WORLD_79 = 239, + SDLK_WORLD_80 = 240, + SDLK_WORLD_81 = 241, + SDLK_WORLD_82 = 242, + SDLK_WORLD_83 = 243, + SDLK_WORLD_84 = 244, + SDLK_WORLD_85 = 245, + SDLK_WORLD_86 = 246, + SDLK_WORLD_87 = 247, + SDLK_WORLD_88 = 248, + SDLK_WORLD_89 = 249, + SDLK_WORLD_90 = 250, + SDLK_WORLD_91 = 251, + SDLK_WORLD_92 = 252, + SDLK_WORLD_93 = 253, + SDLK_WORLD_94 = 254, + SDLK_WORLD_95 = 255, /* 0xFF */ + + /* Numeric keypad */ + SDLK_KP0 = 256, + SDLK_KP1 = 257, + SDLK_KP2 = 258, + SDLK_KP3 = 259, + SDLK_KP4 = 260, + SDLK_KP5 = 261, + SDLK_KP6 = 262, + SDLK_KP7 = 263, + SDLK_KP8 = 264, + SDLK_KP9 = 265, + SDLK_KP_PERIOD = 266, + SDLK_KP_DIVIDE = 267, + SDLK_KP_MULTIPLY = 268, + SDLK_KP_MINUS = 269, + SDLK_KP_PLUS = 270, + SDLK_KP_ENTER = 271, + SDLK_KP_EQUALS = 272, + + /* Arrows + Home/End pad */ + SDLK_UP = 273, + SDLK_DOWN = 274, + SDLK_RIGHT = 275, + SDLK_LEFT = 276, + SDLK_INSERT = 277, + SDLK_HOME = 278, + SDLK_END = 279, + SDLK_PAGEUP = 280, + SDLK_PAGEDOWN = 281, + + /* Function keys */ + SDLK_F1 = 282, + SDLK_F2 = 283, + SDLK_F3 = 284, + SDLK_F4 = 285, + SDLK_F5 = 286, + SDLK_F6 = 287, + SDLK_F7 = 288, + SDLK_F8 = 289, + SDLK_F9 = 290, + SDLK_F10 = 291, + SDLK_F11 = 292, + SDLK_F12 = 293, + SDLK_F13 = 294, + SDLK_F14 = 295, + SDLK_F15 = 296, + + /* Key state modifier keys */ + SDLK_NUMLOCK = 300, + SDLK_CAPSLOCK = 301, + SDLK_SCROLLOCK = 302, + SDLK_RSHIFT = 303, + SDLK_LSHIFT = 304, + SDLK_RCTRL = 305, + SDLK_LCTRL = 306, + SDLK_RALT = 307, + SDLK_LALT = 308, + SDLK_RMETA = 309, + SDLK_LMETA = 310, + SDLK_RGUI = 309, + SDLK_LGUI = 310, + SDLK_LSUPER = 311, /* Left "Windows" key */ + SDLK_RSUPER = 312, /* Right "Windows" key */ + SDLK_MODE = 313, /* "Alt Gr" key */ + SDLK_COMPOSE = 314, /* Multi-key compose key */ + + /* Miscellaneous function keys */ + SDLK_HELP = 315, + SDLK_PRINT = 316, + SDLK_SYSREQ = 317, + SDLK_BREAK = 318, + SDLK_MENU = 319, + SDLK_POWER = 320, /* Power Macintosh power key */ + SDLK_EURO = 321, /* Some european keyboards */ + SDLK_UNDO = 322, /* Atari keyboard has Undo */ + + /* Add any other keys here */ + + SDLK_LAST +}; + + namespace_end namespace_end diff --git a/source/modules/asura-core/Input/JoystickState.h b/source/modules/asura-core/Input/JoystickState.h index e69de29..42d0a79 100644 --- a/source/modules/asura-core/Input/JoystickState.h +++ b/source/modules/asura-core/Input/JoystickState.h @@ -0,0 +1,16 @@ +#ifndef _ASURA_JOYSTICKSTATE_H_ +#define _ASURA_JOYSTICKSTATE_H_ + +#include <asura-utils/Classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Input) + +class JoystickState {}; + + +namespace_end +namespace_end + +#endif + diff --git a/source/modules/asura-core/Input/Keys.h b/source/modules/asura-core/Input/Keys.h deleted file mode 100644 index 8f04dc2..0000000 --- a/source/modules/asura-core/Input/Keys.h +++ /dev/null @@ -1,482 +0,0 @@ - -/** -* Keyboard keys. They are dependent on the current layout of the keyboard. -**/ -enum Key -{ - KEY_UNKNOWN, - - KEY_RETURN, - KEY_ESCAPE, - KEY_BACKSPACE, - KEY_TAB, - KEY_SPACE, - KEY_EXCLAIM, - KEY_QUOTEDBL, - KEY_HASH, - KEY_PERCENT, - KEY_DOLLAR, - KEY_AMPERSAND, - KEY_QUOTE, - KEY_LEFTPAREN, - KEY_RIGHTPAREN, - KEY_ASTERISK, - KEY_PLUS, - KEY_COMMA, - KEY_MINUS, - KEY_PERIOD, - KEY_SLASH, - KEY_0, - KEY_1, - KEY_2, - KEY_3, - KEY_4, - KEY_5, - KEY_6, - KEY_7, - KEY_8, - KEY_9, - KEY_COLON, - KEY_SEMICOLON, - KEY_LESS, - KEY_EQUALS, - KEY_GREATER, - KEY_QUESTION, - KEY_AT, - - KEY_LEFTBRACKET, - KEY_BACKSLASH, - KEY_RIGHTBRACKET, - KEY_CARET, - KEY_UNDERSCORE, - KEY_BACKQUOTE, - KEY_A, - KEY_B, - KEY_C, - KEY_D, - KEY_E, - KEY_F, - KEY_G, - KEY_H, - KEY_I, - KEY_J, - KEY_K, - KEY_L, - KEY_M, - KEY_N, - KEY_O, - KEY_P, - KEY_Q, - KEY_R, - KEY_S, - KEY_T, - KEY_U, - KEY_V, - KEY_W, - KEY_X, - KEY_Y, - KEY_Z, - - KEY_CAPSLOCK, - - KEY_F1, - KEY_F2, - KEY_F3, - KEY_F4, - KEY_F5, - KEY_F6, - KEY_F7, - KEY_F8, - KEY_F9, - KEY_F10, - KEY_F11, - KEY_F12, - - KEY_PRINTSCREEN, - KEY_SCROLLLOCK, - KEY_PAUSE, - KEY_INSERT, - KEY_HOME, - KEY_PAGEUP, - KEY_DELETE, - KEY_END, - KEY_PAGEDOWN, - KEY_RIGHT, - KEY_LEFT, - KEY_DOWN, - KEY_UP, - - KEY_NUMLOCKCLEAR, - KEY_KP_DIVIDE, - KEY_KP_MULTIPLY, - KEY_KP_MINUS, - KEY_KP_PLUS, - KEY_KP_ENTER, - KEY_KP_1, - KEY_KP_2, - KEY_KP_3, - KEY_KP_4, - KEY_KP_5, - KEY_KP_6, - KEY_KP_7, - KEY_KP_8, - KEY_KP_9, - KEY_KP_0, - KEY_KP_PERIOD, - KEY_KP_COMMA, - KEY_KP_EQUALS, - - KEY_APPLICATION, - KEY_POWER, - KEY_F13, - KEY_F14, - KEY_F15, - KEY_F16, - KEY_F17, - KEY_F18, - KEY_F19, - KEY_F20, - KEY_F21, - KEY_F22, - KEY_F23, - KEY_F24, - KEY_EXECUTE, - KEY_HELP, - KEY_MENU, - KEY_SELECT, - KEY_STOP, - KEY_AGAIN, - KEY_UNDO, - KEY_CUT, - KEY_COPY, - KEY_PASTE, - KEY_FIND, - KEY_MUTE, - KEY_VOLUMEUP, - KEY_VOLUMEDOWN, - - KEY_ALTERASE, - KEY_SYSREQ, - KEY_CANCEL, - KEY_CLEAR, - KEY_PRIOR, - KEY_RETURN2, - KEY_SEPARATOR, - KEY_OUT, - KEY_OPER, - KEY_CLEARAGAIN, - - KEY_THOUSANDSSEPARATOR, - KEY_DECIMALSEPARATOR, - KEY_CURRENCYUNIT, - KEY_CURRENCYSUBUNIT, - - KEY_LCTRL, - KEY_LSHIFT, - KEY_LALT, - KEY_LGUI, - KEY_RCTRL, - KEY_RSHIFT, - KEY_RALT, - KEY_RGUI, - - KEY_MODE, - - KEY_AUDIONEXT, - KEY_AUDIOPREV, - KEY_AUDIOSTOP, - KEY_AUDIOPLAY, - KEY_AUDIOMUTE, - KEY_MEDIASELECT, - KEY_WWW, - KEY_MAIL, - KEY_CALCULATOR, - KEY_COMPUTER, - KEY_APP_SEARCH, - KEY_APP_HOME, - KEY_APP_BACK, - KEY_APP_FORWARD, - KEY_APP_STOP, - KEY_APP_REFRESH, - KEY_APP_BOOKMARKS, - - KEY_BRIGHTNESSDOWN, - KEY_BRIGHTNESSUP, - KEY_DISPLAYSWITCH, - KEY_KBDILLUMTOGGLE, - KEY_KBDILLUMDOWN, - KEY_KBDILLUMUP, - KEY_EJECT, - KEY_SLEEP, - - KEY_MAX_ENUM -}; - -/** -* Scancodes represent physical keys independent of the current layout. -* Their names may not match the names of the keys printed on the keyboard. -* Some of them are very esoteric... -**/ -enum Scancode -{ - SCANCODE_UNKNOWN, - - SCANCODE_A, - SCANCODE_B, - SCANCODE_C, - SCANCODE_D, - SCANCODE_E, - SCANCODE_F, - SCANCODE_G, - SCANCODE_H, - SCANCODE_I, - SCANCODE_J, - SCANCODE_K, - SCANCODE_L, - SCANCODE_M, - SCANCODE_N, - SCANCODE_O, - SCANCODE_P, - SCANCODE_Q, - SCANCODE_R, - SCANCODE_S, - SCANCODE_T, - SCANCODE_U, - SCANCODE_V, - SCANCODE_W, - SCANCODE_X, - SCANCODE_Y, - SCANCODE_Z, - - SCANCODE_1, - SCANCODE_2, - SCANCODE_3, - SCANCODE_4, - SCANCODE_5, - SCANCODE_6, - SCANCODE_7, - SCANCODE_8, - SCANCODE_9, - SCANCODE_0, - - SCANCODE_RETURN, - SCANCODE_ESCAPE, - SCANCODE_BACKSPACE, - SCANCODE_TAB, - SCANCODE_SPACE, - - SCANCODE_MINUS, - SCANCODE_EQUALS, - SCANCODE_LEFTBRACKET, - SCANCODE_RIGHTBRACKET, - SCANCODE_BACKSLASH, - SCANCODE_NONUSHASH, - SCANCODE_SEMICOLON, - SCANCODE_APOSTROPHE, - SCANCODE_GRAVE, - SCANCODE_COMMA, - SCANCODE_PERIOD, - SCANCODE_SLASH, - - SCANCODE_CAPSLOCK, - - SCANCODE_F1, - SCANCODE_F2, - SCANCODE_F3, - SCANCODE_F4, - SCANCODE_F5, - SCANCODE_F6, - SCANCODE_F7, - SCANCODE_F8, - SCANCODE_F9, - SCANCODE_F10, - SCANCODE_F11, - SCANCODE_F12, - - SCANCODE_PRINTSCREEN, - SCANCODE_SCROLLLOCK, - SCANCODE_PAUSE, - SCANCODE_INSERT, - SCANCODE_HOME, - SCANCODE_PAGEUP, - SCANCODE_DELETE, - SCANCODE_END, - SCANCODE_PAGEDOWN, - SCANCODE_RIGHT, - SCANCODE_LEFT, - SCANCODE_DOWN, - SCANCODE_UP, - - SCANCODE_NUMLOCKCLEAR, - SCANCODE_KP_DIVIDE, - SCANCODE_KP_MULTIPLY, - SCANCODE_KP_MINUS, - SCANCODE_KP_PLUS, - SCANCODE_KP_ENTER, - SCANCODE_KP_1, - SCANCODE_KP_2, - SCANCODE_KP_3, - SCANCODE_KP_4, - SCANCODE_KP_5, - SCANCODE_KP_6, - SCANCODE_KP_7, - SCANCODE_KP_8, - SCANCODE_KP_9, - SCANCODE_KP_0, - SCANCODE_KP_PERIOD, - - SCANCODE_NONUSBACKSLASH, - SCANCODE_APPLICATION, - SCANCODE_POWER, - SCANCODE_KP_EQUALS, - SCANCODE_F13, - SCANCODE_F14, - SCANCODE_F15, - SCANCODE_F16, - SCANCODE_F17, - SCANCODE_F18, - SCANCODE_F19, - SCANCODE_F20, - SCANCODE_F21, - SCANCODE_F22, - SCANCODE_F23, - SCANCODE_F24, - SCANCODE_EXECUTE, - SCANCODE_HELP, - SCANCODE_MENU, - SCANCODE_SELECT, - SCANCODE_STOP, - SCANCODE_AGAIN, - SCANCODE_UNDO, - SCANCODE_CUT, - SCANCODE_COPY, - SCANCODE_PASTE, - SCANCODE_FIND, - SCANCODE_MUTE, - SCANCODE_VOLUMEUP, - SCANCODE_VOLUMEDOWN, - SCANCODE_KP_COMMA, - SCANCODE_KP_EQUALSAS400, - - SCANCODE_INTERNATIONAL1, - SCANCODE_INTERNATIONAL2, - SCANCODE_INTERNATIONAL3, - SCANCODE_INTERNATIONAL4, - SCANCODE_INTERNATIONAL5, - SCANCODE_INTERNATIONAL6, - SCANCODE_INTERNATIONAL7, - SCANCODE_INTERNATIONAL8, - SCANCODE_INTERNATIONAL9, - SCANCODE_LANG1, - SCANCODE_LANG2, - SCANCODE_LANG3, - SCANCODE_LANG4, - SCANCODE_LANG5, - SCANCODE_LANG6, - SCANCODE_LANG7, - SCANCODE_LANG8, - SCANCODE_LANG9, - - SCANCODE_ALTERASE, - SCANCODE_SYSREQ, - SCANCODE_CANCEL, - SCANCODE_CLEAR, - SCANCODE_PRIOR, - SCANCODE_RETURN2, - SCANCODE_SEPARATOR, - SCANCODE_OUT, - SCANCODE_OPER, - SCANCODE_CLEARAGAIN, - SCANCODE_CRSEL, - SCANCODE_EXSEL, - - SCANCODE_KP_00, - SCANCODE_KP_000, - SCANCODE_THOUSANDSSEPARATOR, - SCANCODE_DECIMALSEPARATOR, - SCANCODE_CURRENCYUNIT, - SCANCODE_CURRENCYSUBUNIT, - SCANCODE_KP_LEFTPAREN, - SCANCODE_KP_RIGHTPAREN, - SCANCODE_KP_LEFTBRACE, - SCANCODE_KP_RIGHTBRACE, - SCANCODE_KP_TAB, - SCANCODE_KP_BACKSPACE, - SCANCODE_KP_A, - SCANCODE_KP_B, - SCANCODE_KP_C, - SCANCODE_KP_D, - SCANCODE_KP_E, - SCANCODE_KP_F, - SCANCODE_KP_XOR, - SCANCODE_KP_POWER, - SCANCODE_KP_PERCENT, - SCANCODE_KP_LESS, - SCANCODE_KP_GREATER, - SCANCODE_KP_AMPERSAND, - SCANCODE_KP_DBLAMPERSAND, - SCANCODE_KP_VERTICALBAR, - SCANCODE_KP_DBLVERTICALBAR, - SCANCODE_KP_COLON, - SCANCODE_KP_HASH, - SCANCODE_KP_SPACE, - SCANCODE_KP_AT, - SCANCODE_KP_EXCLAM, - SCANCODE_KP_MEMSTORE, - SCANCODE_KP_MEMRECALL, - SCANCODE_KP_MEMCLEAR, - SCANCODE_KP_MEMADD, - SCANCODE_KP_MEMSUBTRACT, - SCANCODE_KP_MEMMULTIPLY, - SCANCODE_KP_MEMDIVIDE, - SCANCODE_KP_PLUSMINUS, - SCANCODE_KP_CLEAR, - SCANCODE_KP_CLEARENTRY, - SCANCODE_KP_BINARY, - SCANCODE_KP_OCTAL, - SCANCODE_KP_DECIMAL, - SCANCODE_KP_HEXADECIMAL, - - SCANCODE_LCTRL, - SCANCODE_LSHIFT, - SCANCODE_LALT, - SCANCODE_LGUI, - SCANCODE_RCTRL, - SCANCODE_RSHIFT, - SCANCODE_RALT, - SCANCODE_RGUI, - - SCANCODE_MODE, - - SCANCODE_AUDIONEXT, - SCANCODE_AUDIOPREV, - SCANCODE_AUDIOSTOP, - SCANCODE_AUDIOPLAY, - SCANCODE_AUDIOMUTE, - SCANCODE_MEDIASELECT, - SCANCODE_WWW, - SCANCODE_MAIL, - SCANCODE_CALCULATOR, - SCANCODE_COMPUTER, - SCANCODE_AC_SEARCH, - SCANCODE_AC_HOME, - SCANCODE_AC_BACK, - SCANCODE_AC_FORWARD, - SCANCODE_AC_STOP, - SCANCODE_AC_REFRESH, - SCANCODE_AC_BOOKMARKS, - - SCANCODE_BRIGHTNESSDOWN, - SCANCODE_BRIGHTNESSUP, - SCANCODE_DISPLAYSWITCH, - SCANCODE_KBDILLUMTOGGLE, - SCANCODE_KBDILLUMDOWN, - SCANCODE_KBDILLUMUP, - SCANCODE_EJECT, - SCANCODE_SLEEP, - - SCANCODE_APP1, - SCANCODE_APP2, - - SCANCODE_MAX_ENUM -}; diff --git a/source/modules/asura-core/Input/MouseState.h b/source/modules/asura-core/Input/MouseState.h index e69de29..1192a34 100644 --- a/source/modules/asura-core/Input/MouseState.h +++ b/source/modules/asura-core/Input/MouseState.h @@ -0,0 +1,16 @@ +#ifndef _ASURA_MOUSESTATE_H_ +#define _ASURA_MOUSESTATE_H_ + +#include <asura-utils/Classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Input) + +class MouseState {}; + + +namespace_end +namespace_end + +#endif + diff --git a/source/modules/asura-core/application.h b/source/modules/asura-core/application.h index ea5faa7..696d125 100644 --- a/source/modules/asura-core/application.h +++ b/source/modules/asura-core/application.h @@ -38,40 +38,28 @@ public: virtual ~Application(); - /// - /// ʼǰϵͳ - /// + // ʼǰϵͳ bool InitSubModules(uint flag = ASURA_MODULE_ALL); - /// - /// - /// + // virtual void Run(int argc, char* args[]); - /// - /// ˳runʱĴ - /// + // ˳runʱĴ virtual void OnExit(); protected: - /// - /// moduleapplicationӵmoduleȨ - /// + // moduleapplicationӵmoduleȨ void EnqueueModule(Module* module); private: - /// /// ̵߳lua state handleӦѭСһ˵ֻҪ߳һlua_State̲߳Ҫ̼߳ /// lua̫ʹˡC++дȻעһصһ̴߳lua_Stateעắִк /// ̵߳lua_Stateֻ֤һnativeʵ֮һlua_State - /// Luax::LuaxVM* m_VM; - /// - /// Asura libsᰴն˳ʼ˳ʱִ˳ - /// + // Asura libsᰴն˳ʼ˳ʱִ˳ std::queue<Module*> m_Modules; }; diff --git a/source/modules/asura-core/input/keys.h b/source/modules/asura-core/input/keys.h deleted file mode 100644 index 8f04dc2..0000000 --- a/source/modules/asura-core/input/keys.h +++ /dev/null @@ -1,482 +0,0 @@ - -/** -* Keyboard keys. They are dependent on the current layout of the keyboard. -**/ -enum Key -{ - KEY_UNKNOWN, - - KEY_RETURN, - KEY_ESCAPE, - KEY_BACKSPACE, - KEY_TAB, - KEY_SPACE, - KEY_EXCLAIM, - KEY_QUOTEDBL, - KEY_HASH, - KEY_PERCENT, - KEY_DOLLAR, - KEY_AMPERSAND, - KEY_QUOTE, - KEY_LEFTPAREN, - KEY_RIGHTPAREN, - KEY_ASTERISK, - KEY_PLUS, - KEY_COMMA, - KEY_MINUS, - KEY_PERIOD, - KEY_SLASH, - KEY_0, - KEY_1, - KEY_2, - KEY_3, - KEY_4, - KEY_5, - KEY_6, - KEY_7, - KEY_8, - KEY_9, - KEY_COLON, - KEY_SEMICOLON, - KEY_LESS, - KEY_EQUALS, - KEY_GREATER, - KEY_QUESTION, - KEY_AT, - - KEY_LEFTBRACKET, - KEY_BACKSLASH, - KEY_RIGHTBRACKET, - KEY_CARET, - KEY_UNDERSCORE, - KEY_BACKQUOTE, - KEY_A, - KEY_B, - KEY_C, - KEY_D, - KEY_E, - KEY_F, - KEY_G, - KEY_H, - KEY_I, - KEY_J, - KEY_K, - KEY_L, - KEY_M, - KEY_N, - KEY_O, - KEY_P, - KEY_Q, - KEY_R, - KEY_S, - KEY_T, - KEY_U, - KEY_V, - KEY_W, - KEY_X, - KEY_Y, - KEY_Z, - - KEY_CAPSLOCK, - - KEY_F1, - KEY_F2, - KEY_F3, - KEY_F4, - KEY_F5, - KEY_F6, - KEY_F7, - KEY_F8, - KEY_F9, - KEY_F10, - KEY_F11, - KEY_F12, - - KEY_PRINTSCREEN, - KEY_SCROLLLOCK, - KEY_PAUSE, - KEY_INSERT, - KEY_HOME, - KEY_PAGEUP, - KEY_DELETE, - KEY_END, - KEY_PAGEDOWN, - KEY_RIGHT, - KEY_LEFT, - KEY_DOWN, - KEY_UP, - - KEY_NUMLOCKCLEAR, - KEY_KP_DIVIDE, - KEY_KP_MULTIPLY, - KEY_KP_MINUS, - KEY_KP_PLUS, - KEY_KP_ENTER, - KEY_KP_1, - KEY_KP_2, - KEY_KP_3, - KEY_KP_4, - KEY_KP_5, - KEY_KP_6, - KEY_KP_7, - KEY_KP_8, - KEY_KP_9, - KEY_KP_0, - KEY_KP_PERIOD, - KEY_KP_COMMA, - KEY_KP_EQUALS, - - KEY_APPLICATION, - KEY_POWER, - KEY_F13, - KEY_F14, - KEY_F15, - KEY_F16, - KEY_F17, - KEY_F18, - KEY_F19, - KEY_F20, - KEY_F21, - KEY_F22, - KEY_F23, - KEY_F24, - KEY_EXECUTE, - KEY_HELP, - KEY_MENU, - KEY_SELECT, - KEY_STOP, - KEY_AGAIN, - KEY_UNDO, - KEY_CUT, - KEY_COPY, - KEY_PASTE, - KEY_FIND, - KEY_MUTE, - KEY_VOLUMEUP, - KEY_VOLUMEDOWN, - - KEY_ALTERASE, - KEY_SYSREQ, - KEY_CANCEL, - KEY_CLEAR, - KEY_PRIOR, - KEY_RETURN2, - KEY_SEPARATOR, - KEY_OUT, - KEY_OPER, - KEY_CLEARAGAIN, - - KEY_THOUSANDSSEPARATOR, - KEY_DECIMALSEPARATOR, - KEY_CURRENCYUNIT, - KEY_CURRENCYSUBUNIT, - - KEY_LCTRL, - KEY_LSHIFT, - KEY_LALT, - KEY_LGUI, - KEY_RCTRL, - KEY_RSHIFT, - KEY_RALT, - KEY_RGUI, - - KEY_MODE, - - KEY_AUDIONEXT, - KEY_AUDIOPREV, - KEY_AUDIOSTOP, - KEY_AUDIOPLAY, - KEY_AUDIOMUTE, - KEY_MEDIASELECT, - KEY_WWW, - KEY_MAIL, - KEY_CALCULATOR, - KEY_COMPUTER, - KEY_APP_SEARCH, - KEY_APP_HOME, - KEY_APP_BACK, - KEY_APP_FORWARD, - KEY_APP_STOP, - KEY_APP_REFRESH, - KEY_APP_BOOKMARKS, - - KEY_BRIGHTNESSDOWN, - KEY_BRIGHTNESSUP, - KEY_DISPLAYSWITCH, - KEY_KBDILLUMTOGGLE, - KEY_KBDILLUMDOWN, - KEY_KBDILLUMUP, - KEY_EJECT, - KEY_SLEEP, - - KEY_MAX_ENUM -}; - -/** -* Scancodes represent physical keys independent of the current layout. -* Their names may not match the names of the keys printed on the keyboard. -* Some of them are very esoteric... -**/ -enum Scancode -{ - SCANCODE_UNKNOWN, - - SCANCODE_A, - SCANCODE_B, - SCANCODE_C, - SCANCODE_D, - SCANCODE_E, - SCANCODE_F, - SCANCODE_G, - SCANCODE_H, - SCANCODE_I, - SCANCODE_J, - SCANCODE_K, - SCANCODE_L, - SCANCODE_M, - SCANCODE_N, - SCANCODE_O, - SCANCODE_P, - SCANCODE_Q, - SCANCODE_R, - SCANCODE_S, - SCANCODE_T, - SCANCODE_U, - SCANCODE_V, - SCANCODE_W, - SCANCODE_X, - SCANCODE_Y, - SCANCODE_Z, - - SCANCODE_1, - SCANCODE_2, - SCANCODE_3, - SCANCODE_4, - SCANCODE_5, - SCANCODE_6, - SCANCODE_7, - SCANCODE_8, - SCANCODE_9, - SCANCODE_0, - - SCANCODE_RETURN, - SCANCODE_ESCAPE, - SCANCODE_BACKSPACE, - SCANCODE_TAB, - SCANCODE_SPACE, - - SCANCODE_MINUS, - SCANCODE_EQUALS, - SCANCODE_LEFTBRACKET, - SCANCODE_RIGHTBRACKET, - SCANCODE_BACKSLASH, - SCANCODE_NONUSHASH, - SCANCODE_SEMICOLON, - SCANCODE_APOSTROPHE, - SCANCODE_GRAVE, - SCANCODE_COMMA, - SCANCODE_PERIOD, - SCANCODE_SLASH, - - SCANCODE_CAPSLOCK, - - SCANCODE_F1, - SCANCODE_F2, - SCANCODE_F3, - SCANCODE_F4, - SCANCODE_F5, - SCANCODE_F6, - SCANCODE_F7, - SCANCODE_F8, - SCANCODE_F9, - SCANCODE_F10, - SCANCODE_F11, - SCANCODE_F12, - - SCANCODE_PRINTSCREEN, - SCANCODE_SCROLLLOCK, - SCANCODE_PAUSE, - SCANCODE_INSERT, - SCANCODE_HOME, - SCANCODE_PAGEUP, - SCANCODE_DELETE, - SCANCODE_END, - SCANCODE_PAGEDOWN, - SCANCODE_RIGHT, - SCANCODE_LEFT, - SCANCODE_DOWN, - SCANCODE_UP, - - SCANCODE_NUMLOCKCLEAR, - SCANCODE_KP_DIVIDE, - SCANCODE_KP_MULTIPLY, - SCANCODE_KP_MINUS, - SCANCODE_KP_PLUS, - SCANCODE_KP_ENTER, - SCANCODE_KP_1, - SCANCODE_KP_2, - SCANCODE_KP_3, - SCANCODE_KP_4, - SCANCODE_KP_5, - SCANCODE_KP_6, - SCANCODE_KP_7, - SCANCODE_KP_8, - SCANCODE_KP_9, - SCANCODE_KP_0, - SCANCODE_KP_PERIOD, - - SCANCODE_NONUSBACKSLASH, - SCANCODE_APPLICATION, - SCANCODE_POWER, - SCANCODE_KP_EQUALS, - SCANCODE_F13, - SCANCODE_F14, - SCANCODE_F15, - SCANCODE_F16, - SCANCODE_F17, - SCANCODE_F18, - SCANCODE_F19, - SCANCODE_F20, - SCANCODE_F21, - SCANCODE_F22, - SCANCODE_F23, - SCANCODE_F24, - SCANCODE_EXECUTE, - SCANCODE_HELP, - SCANCODE_MENU, - SCANCODE_SELECT, - SCANCODE_STOP, - SCANCODE_AGAIN, - SCANCODE_UNDO, - SCANCODE_CUT, - SCANCODE_COPY, - SCANCODE_PASTE, - SCANCODE_FIND, - SCANCODE_MUTE, - SCANCODE_VOLUMEUP, - SCANCODE_VOLUMEDOWN, - SCANCODE_KP_COMMA, - SCANCODE_KP_EQUALSAS400, - - SCANCODE_INTERNATIONAL1, - SCANCODE_INTERNATIONAL2, - SCANCODE_INTERNATIONAL3, - SCANCODE_INTERNATIONAL4, - SCANCODE_INTERNATIONAL5, - SCANCODE_INTERNATIONAL6, - SCANCODE_INTERNATIONAL7, - SCANCODE_INTERNATIONAL8, - SCANCODE_INTERNATIONAL9, - SCANCODE_LANG1, - SCANCODE_LANG2, - SCANCODE_LANG3, - SCANCODE_LANG4, - SCANCODE_LANG5, - SCANCODE_LANG6, - SCANCODE_LANG7, - SCANCODE_LANG8, - SCANCODE_LANG9, - - SCANCODE_ALTERASE, - SCANCODE_SYSREQ, - SCANCODE_CANCEL, - SCANCODE_CLEAR, - SCANCODE_PRIOR, - SCANCODE_RETURN2, - SCANCODE_SEPARATOR, - SCANCODE_OUT, - SCANCODE_OPER, - SCANCODE_CLEARAGAIN, - SCANCODE_CRSEL, - SCANCODE_EXSEL, - - SCANCODE_KP_00, - SCANCODE_KP_000, - SCANCODE_THOUSANDSSEPARATOR, - SCANCODE_DECIMALSEPARATOR, - SCANCODE_CURRENCYUNIT, - SCANCODE_CURRENCYSUBUNIT, - SCANCODE_KP_LEFTPAREN, - SCANCODE_KP_RIGHTPAREN, - SCANCODE_KP_LEFTBRACE, - SCANCODE_KP_RIGHTBRACE, - SCANCODE_KP_TAB, - SCANCODE_KP_BACKSPACE, - SCANCODE_KP_A, - SCANCODE_KP_B, - SCANCODE_KP_C, - SCANCODE_KP_D, - SCANCODE_KP_E, - SCANCODE_KP_F, - SCANCODE_KP_XOR, - SCANCODE_KP_POWER, - SCANCODE_KP_PERCENT, - SCANCODE_KP_LESS, - SCANCODE_KP_GREATER, - SCANCODE_KP_AMPERSAND, - SCANCODE_KP_DBLAMPERSAND, - SCANCODE_KP_VERTICALBAR, - SCANCODE_KP_DBLVERTICALBAR, - SCANCODE_KP_COLON, - SCANCODE_KP_HASH, - SCANCODE_KP_SPACE, - SCANCODE_KP_AT, - SCANCODE_KP_EXCLAM, - SCANCODE_KP_MEMSTORE, - SCANCODE_KP_MEMRECALL, - SCANCODE_KP_MEMCLEAR, - SCANCODE_KP_MEMADD, - SCANCODE_KP_MEMSUBTRACT, - SCANCODE_KP_MEMMULTIPLY, - SCANCODE_KP_MEMDIVIDE, - SCANCODE_KP_PLUSMINUS, - SCANCODE_KP_CLEAR, - SCANCODE_KP_CLEARENTRY, - SCANCODE_KP_BINARY, - SCANCODE_KP_OCTAL, - SCANCODE_KP_DECIMAL, - SCANCODE_KP_HEXADECIMAL, - - SCANCODE_LCTRL, - SCANCODE_LSHIFT, - SCANCODE_LALT, - SCANCODE_LGUI, - SCANCODE_RCTRL, - SCANCODE_RSHIFT, - SCANCODE_RALT, - SCANCODE_RGUI, - - SCANCODE_MODE, - - SCANCODE_AUDIONEXT, - SCANCODE_AUDIOPREV, - SCANCODE_AUDIOSTOP, - SCANCODE_AUDIOPLAY, - SCANCODE_AUDIOMUTE, - SCANCODE_MEDIASELECT, - SCANCODE_WWW, - SCANCODE_MAIL, - SCANCODE_CALCULATOR, - SCANCODE_COMPUTER, - SCANCODE_AC_SEARCH, - SCANCODE_AC_HOME, - SCANCODE_AC_BACK, - SCANCODE_AC_FORWARD, - SCANCODE_AC_STOP, - SCANCODE_AC_REFRESH, - SCANCODE_AC_BOOKMARKS, - - SCANCODE_BRIGHTNESSDOWN, - SCANCODE_BRIGHTNESSUP, - SCANCODE_DISPLAYSWITCH, - SCANCODE_KBDILLUMTOGGLE, - SCANCODE_KBDILLUMDOWN, - SCANCODE_KBDILLUMUP, - SCANCODE_EJECT, - SCANCODE_SLEEP, - - SCANCODE_APP1, - SCANCODE_APP2, - - SCANCODE_MAX_ENUM -}; diff --git a/source/modules/asura-utils/Classes.h b/source/modules/asura-utils/Classes.h index d92c3d4..b2700f0 100644 --- a/source/modules/asura-utils/Classes.h +++ b/source/modules/asura-utils/Classes.h @@ -1,7 +1,7 @@ #ifndef _ASURAENGINE_CLASSES_H_ #define _ASURAENGINE_CLASSES_H_ -#define GET_SET(TYPE,PROP_NAME,VAR_NAME) void Set##PROP_NAME (TYPE val) { VAR_NAME = val; } const TYPE Get##PROP_NAME () const {return (const TYPE)VAR_NAME; } +#define GET_SET(TYPE,PROP_NAME,VAR_NAME) void Set##PROP_NAME (TYPE val) { VAR_NAME = val; } TYPE Get##PROP_NAME () {return VAR_NAME; } #define namespace_begin(NAMESPACE) namespace NAMESPACE { #define namespace_end } diff --git a/source/modules/asura-utils/Math/Matrix44.h b/source/modules/asura-utils/Math/Matrix44.h index 7b66920..503242f 100644 --- a/source/modules/asura-utils/Math/Matrix44.h +++ b/source/modules/asura-utils/Math/Matrix44.h @@ -1,97 +1,95 @@ #ifndef _ASURA_MATRIX_H_ #define _ASURA_MATRIX_H_ +#include <asura-utils/Classes.h> + #include "../Scripting/Portable.hpp" -namespace AsuraEngine -{ - namespace Math - { +namespace_begin(AsuraEngine) +namespace_begin(Math) - /// - /// ҪתõOpenGLglm::mat4 - /// https://blog.csdn.net/candycat1992/article/details/8830894 - /// - class Matrix44 - { - public: +/// ҪתõOpenGLglm::mat4 +/// https://blog.csdn.net/candycat1992/article/details/8830894 +class Matrix44 +{ +public: - static const Matrix44 Identity; + static const Matrix44 Identity; - Matrix44(); + Matrix44(); - Matrix44(const Matrix44& m); + Matrix44(const Matrix44& m); - ~Matrix44(); + ~Matrix44(); - void operator = (const Matrix44& m); + void operator = (const Matrix44& m); - void SetOrtho(float _left, float _right, float _bottom, float _top, float _near, float _far); + void SetOrtho(float _left, float _right, float _bottom, float _top, float _near, float _far); - Matrix44 operator * (const Matrix44 & m) const; + Matrix44 operator * (const Matrix44 & m) const; - void operator *= (const Matrix44 & m); + void operator *= (const Matrix44 & m); - const float* GetElements() const; + const float* GetElements() const; - void SetIdentity(); + void SetIdentity(); - void SetTranslation(float x, float y); + void SetTranslation(float x, float y); - void SetRotation(float r); + void SetRotation(float r); - void SetScale(float sx, float sy); + void SetScale(float sx, float sy); - void SetShear(float kx, float ky); + void SetShear(float kx, float ky); - void SetTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy); + void SetTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy); - void Translate(float x, float y); + void Translate(float x, float y); - void Rotate(float r); + void Rotate(float r); - void Scale(float sx, float sy); + void Scale(float sx, float sy); - void Transform(float x, float y, float angle, float sx, float sy, float ox, float oy); + void Transform(float x, float y, float angle, float sx, float sy, float ox, float oy); - /// - /// Multiplies this Matrix44 with a shear transformation. - /// @param kx Shear along the x-axis. - /// @param ky Shear along the y-axis. - /// - void Shear(float kx, float ky); + /// + /// Multiplies this Matrix44 with a shear transformation. + /// @param kx Shear along the x-axis. + /// @param ky Shear along the y-axis. + /// + void Shear(float kx, float ky); - void Ortho(float left, float right, float bottom, float top, float near, float far); + void Ortho(float left, float right, float bottom, float top, float near, float far); - ///// - ///// Transforms an array of vertices by this Matrix44. The sources and - ///// destination arrays may be the same. - ///// - ///// @param dst Storage for the transformed vertices. - ///// @param src The source vertices. - ///// @param size The number of vertices. - ///// - //void transform(Graphics::Vertex* dst, const Graphics::Vertex * src, int size) const; + ///// + ///// Transforms an array of vertices by this Matrix44. The sources and + ///// destination arrays may be the same. + ///// + ///// @param dst Storage for the transformed vertices. + ///// @param src The source vertices. + ///// @param size The number of vertices. + ///// + //void transform(Graphics::Vertex* dst, const Graphics::Vertex * src, int size) const; - /// - /// ʽ - /// - float Calculate(); + /// + /// ʽ + /// + float Calculate(); - private: +private: - /// - /// | e0 e4 e8 e12 | - /// | e1 e5 e9 e13 | - /// | e2 e6 e10 e14 | - /// | e3 e7 e11 e15 | - /// - float e[16]; + /// + /// | e0 e4 e8 e12 | + /// | e1 e5 e9 e13 | + /// | e2 e6 e10 e14 | + /// | e3 e7 e11 e15 | + /// + float e[16]; - }; +}; - } -} +namespace_end +namespace_end namespace AEMath = AsuraEngine::Math; diff --git a/source/modules/asura-utils/Math/Rand/Rand.h b/source/modules/asura-utils/Math/Rand/Rand.h index efda8db..74b1102 100644 --- a/source/modules/asura-utils/Math/Rand/Rand.h +++ b/source/modules/asura-utils/Math/Rand/Rand.h @@ -25,7 +25,6 @@ Xorshift 32: 20.6 10.7 ms 4 WELL 512: 43.6 55.1 ms 68 */ - // Xorshift 128 implementation // Xorshift paper: http://www.jstatsoft.org/v08/i14/paper // Wikipedia: http://en.wikipedia.org/wiki/Xorshift diff --git a/source/modules/asura-utils/Math/Vector2.hpp b/source/modules/asura-utils/Math/Vector2.hpp index f2405eb..326a57e 100644 --- a/source/modules/asura-utils/Math/Vector2.hpp +++ b/source/modules/asura-utils/Math/Vector2.hpp @@ -1,71 +1,71 @@ #ifndef _ASURA_ENGINE_VECTOR2_H__ #define _ASURA_ENGINE_VECTOR2_H__ -namespace AsuraEngine +#include <asura-utils/Classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Math) + +template <typename T> +class Vector2 { - namespace Math - { - template <typename T> - class Vector2 - { - public: - Vector2(); - Vector2(T X, T Y); +public: + Vector2(); + Vector2(T X, T Y); - template <typename U> - explicit Vector2(const Vector2<U>& vector); + template <typename U> + explicit Vector2(const Vector2<U>& vector); - void Set(T X, T Y); + void Set(T X, T Y); - T x; ///< X coordinate of the vector - T y; ///< Y coordinate of the vector - }; + T x; ///< X coordinate of the vector + T y; ///< Y coordinate of the vector +}; - template <typename T> - Vector2<T> operator -(const Vector2<T>& right); +template <typename T> +Vector2<T> operator -(const Vector2<T>& right); - template <typename T> - Vector2<T>& operator +=(Vector2<T>& left, const Vector2<T>& right); +template <typename T> +Vector2<T>& operator +=(Vector2<T>& left, const Vector2<T>& right); - template <typename T> - Vector2<T>& operator -=(Vector2<T>& left, const Vector2<T>& right); +template <typename T> +Vector2<T>& operator -=(Vector2<T>& left, const Vector2<T>& right); - template <typename T> - Vector2<T> operator +(const Vector2<T>& left, const Vector2<T>& right); +template <typename T> +Vector2<T> operator +(const Vector2<T>& left, const Vector2<T>& right); - template <typename T> - Vector2<T> operator -(const Vector2<T>& left, const Vector2<T>& right); +template <typename T> +Vector2<T> operator -(const Vector2<T>& left, const Vector2<T>& right); - template <typename T> - Vector2<T> operator *(const Vector2<T>& left, T right); +template <typename T> +Vector2<T> operator *(const Vector2<T>& left, T right); - template <typename T> - Vector2<T> operator *(T left, const Vector2<T>& right); +template <typename T> +Vector2<T> operator *(T left, const Vector2<T>& right); - template <typename T> - Vector2<T>& operator *=(Vector2<T>& left, T right); +template <typename T> +Vector2<T>& operator *=(Vector2<T>& left, T right); - template <typename T> - Vector2<T> operator /(const Vector2<T>& left, T right); +template <typename T> +Vector2<T> operator /(const Vector2<T>& left, T right); - template <typename T> - Vector2<T>& operator /=(Vector2<T>& left, T right); +template <typename T> +Vector2<T>& operator /=(Vector2<T>& left, T right); - template <typename T> - bool operator ==(const Vector2<T>& left, const Vector2<T>& right); +template <typename T> +bool operator ==(const Vector2<T>& left, const Vector2<T>& right); - template <typename T> - bool operator !=(const Vector2<T>& left, const Vector2<T>& right); +template <typename T> +bool operator !=(const Vector2<T>& left, const Vector2<T>& right); #include "Vector2.inc" - // Define the most common types - typedef Vector2<int> Vector2i; - typedef Vector2<unsigned int> Vector2u; - typedef Vector2<float> Vector2f; +typedef Vector2<int> Vector2i; +typedef Vector2<unsigned int> Vector2u; +typedef Vector2<float> Vector2f; - } -} +namespace_end +namespace_end namespace AEMath = AsuraEngine::Math; diff --git a/source/modules/asura-utils/Math/Vector3.hpp b/source/modules/asura-utils/Math/Vector3.hpp index 8da57cf..c526ace 100644 --- a/source/modules/asura-utils/Math/Vector3.hpp +++ b/source/modules/asura-utils/Math/Vector3.hpp @@ -230,4 +230,6 @@ namespace AsuraEngine } } +namespace AEMath = AsuraEngine::Math; + #endif
\ No newline at end of file diff --git a/source/modules/asura-utils/Type.h b/source/modules/asura-utils/Type.h index f7e54c6..318145b 100644 --- a/source/modules/asura-utils/Type.h +++ b/source/modules/asura-utils/Type.h @@ -1,6 +1,7 @@ #ifndef _ASURA_UTILS_TYPE_H_ #define _ASURA_UTILS_TYPE_H_ +#include <assert.h> #include <cstdlib> #include <stdint.h> @@ -29,6 +30,8 @@ namespace AsuraEngine typedef const char cc8; +#define Assert assert + } // namespace AsuraEngine #endif // _ASURA_CONFIG_H_
\ No newline at end of file diff --git a/source/modules/asura-utils/classes.h b/source/modules/asura-utils/classes.h index d92c3d4..b2700f0 100644 --- a/source/modules/asura-utils/classes.h +++ b/source/modules/asura-utils/classes.h @@ -1,7 +1,7 @@ #ifndef _ASURAENGINE_CLASSES_H_ #define _ASURAENGINE_CLASSES_H_ -#define GET_SET(TYPE,PROP_NAME,VAR_NAME) void Set##PROP_NAME (TYPE val) { VAR_NAME = val; } const TYPE Get##PROP_NAME () const {return (const TYPE)VAR_NAME; } +#define GET_SET(TYPE,PROP_NAME,VAR_NAME) void Set##PROP_NAME (TYPE val) { VAR_NAME = val; } TYPE Get##PROP_NAME () {return VAR_NAME; } #define namespace_begin(NAMESPACE) namespace NAMESPACE { #define namespace_end } diff --git a/source/modules/asura-utils/dynamic_bitset.h b/source/modules/asura-utils/dynamic_bitset.h new file mode 100644 index 0000000..2b04d07 --- /dev/null +++ b/source/modules/asura-utils/dynamic_bitset.h @@ -0,0 +1,1150 @@ +#ifndef DYNAMIC_BITSET_H +#define DYNAMIC_BITSET_H +// (C) Copyright Chuck Allison and Jeremy Siek 2001, 2002. +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all +// copies. This software is provided "as is" without express or +// implied warranty, and with no claim as to its suitability for any +// purpose. + +// With optimizations, bug fixes, and improvements by Gennaro Prota. + +// See http://www.boost.org/libs/dynamic_bitset for documentation. + +// ------------------------------------- +// CHANGE LOG: +// +// - corrected workaround for Dinkum lib's allocate() [GP] +// - changed macro test for old iostreams [GP] +// - removed #include <vector> for now. [JGS] +// - Added __GNUC__ to compilers that cannot handle the constructor from basic_string. [JGS] +// - corrected to_block_range [GP] +// - corrected from_block_range [GP] +// - Removed __GNUC__ from compilers that cannot handle the constructor +// from basic_string and added the workaround suggested by GP. [JGS] +// - Removed __BORLANDC__ from the #if around the basic_string +// constructor. Luckily the fix by GP for g++ also fixes Borland. [JGS] + +#include <cassert> +#include <string> +#include <cstring> // for memset, memcpy, memcmp, etc. +#include <algorithm> // for std::swap, std::min, std::copy, std::fill +#include <memory> // for std::swap, std::min, std::copy, std::fill +#include <stdlib.h> + +#include "Type.h" + +namespace std +{ + typedef ::size_t size_t; +} +// (C) Copyright Chuck Allison and Jeremy Siek 2001, 2002. +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all +// copies. This software is provided "as is" without express or +// implied warranty, and with no claim as to its suitability for any +// purpose. + +// With optimizations by Gennaro Prota. + +class dynamic_bitset_base +{ + typedef std::size_t size_type; +public: +#if defined(LINUX) && (defined (__LP64__) || defined(_AMD64_)) + typedef unsigned int Block; +#else + typedef unsigned long Block; +#endif + enum { bits_per_block = 8 * sizeof(Block) }; + + dynamic_bitset_base() + : m_bits(0), m_num_bits(0), m_num_blocks(0) { } + + dynamic_bitset_base(size_type num_bits) : + m_num_bits(num_bits), + m_num_blocks(calc_num_blocks(num_bits)) + { + if (m_num_blocks != 0) + { + m_bits = new Block[m_num_blocks]; + memset(m_bits, 0, m_num_blocks * sizeof(Block)); // G.P.S. ask to Jeremy + } + else + m_bits = 0; + } + ~dynamic_bitset_base() { + delete[]m_bits;; + } + + Block* m_bits; + size_type m_num_bits; + size_type m_num_blocks; + + static size_type word(size_type bit) { return bit / bits_per_block; } // [gps] + static size_type offset(size_type bit) { return bit % bits_per_block; } // [gps] + static Block mask1(size_type bit) { return Block(1) << offset(bit); } + static Block mask0(size_type bit) { return ~(Block(1) << offset(bit)); } + static size_type calc_num_blocks(size_type num_bits) + { + return (num_bits + bits_per_block - 1) / bits_per_block; + } +}; + + +// ------- count table implementation -------------- + +typedef unsigned char byte_t; + +template <bool bogus = true> +struct bitcount { + typedef byte_t element_type; + static const byte_t table[]; + +}; +//typedef count<true> table_t; + + +// the table: wrapped in a class template, so +// that it is only instantiated if/when needed +// +template <bool bogus> +const byte_t bitcount<bogus>::table[] = +{ + // Automatically generated by GPTableGen.exe v.1.0 + // +0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, +1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, +1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, +2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, +1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, +2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, +2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, +3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 +}; + + +// ------------------------------------------------------- +template <typename BlockInputIterator> +std::size_t initial_num_blocks(BlockInputIterator first, + BlockInputIterator last) +{ + std::size_t n = 0; + while (first != last) + ++first, ++n; + return n; +} + +class dynamic_bitset : public dynamic_bitset_base +{ +public: + + typedef Block block_type; + typedef std::size_t size_type; + enum { bits_per_block = 8 * sizeof(Block) }; + + // reference to a bit + class reference + { + friend class dynamic_bitset; + dynamic_bitset* bs; + size_type bit; + reference(); // intentionally not implemented + reference(dynamic_bitset& bs_, size_type bit_) : bs(&bs_), bit(bit_) { } + public: + reference& operator=(bool value) // for b[i] = x + { + if (value) + bs->set(bit); + else + bs->reset(bit); + return *this; + } + reference& operator|=(bool value) // for b[i] |= x + { + if (value) + bs->set(bit); + return *this; + } + reference& operator&=(bool value) // for b[i] &= x + { + if (!(value && bs->test(bit))) + bs->reset(bit); + return *this; + } + reference& operator^=(bool value) // for b[i] ^= x + { + bs->set(bit, bs->test(bit) ^ value); + return *this; + } + reference& operator-=(bool value) // for b[i] -= x + { + if (!value) + bs->reset(bit); + return *this; + } + reference& operator=(const reference& j) // for b[i] = b[j] + { + if (j.bs->test(j.bit)) + bs->set(bit); + else + bs->reset(bit); + return *this; + } + reference& operator|=(const reference& j) // for b[i] |= b[j] + { + if (j.bs->test(j.bit)) + bs->set(bit); + return *this; + } + reference& operator&=(const reference& j) // for b[i] &= b[j] + { + if (!(j.bs->test(j.bit) && bs->test(bit))) + bs->reset(bit); + return *this; + } + reference& operator^=(const reference& j) // for b[i] ^= b[j] + { + bs->set(bit, bs->test(bit) ^ j.bs->test(j.bit)); + return *this; + } + reference& operator-=(const reference& j) // for b[i] -= b[j] + { + if (!j.bs->test(j.bit)) + bs->reset(bit); + return *this; + } + bool operator~() const // flips the bit + { + return !bs->test(bit); + } + operator bool() const // for x = b[i] + { + return bs->test(bit); + } + reference& flip() // for b[i].flip(); + { + bs->flip(bit); + return *this; + } + }; + typedef bool const_reference; + + dynamic_bitset(); + explicit + dynamic_bitset(size_type num_bits, unsigned long value = 0); + + // The parenthesis around std::basic_string<CharT, Traits, Alloc>::npos + // in the code below are to avoid a g++ 3.2 bug and a Borland bug. -JGS + template <typename String> + explicit + dynamic_bitset(const String& s, + typename String::size_type pos = 0, + typename String::size_type n + = (String::npos)) + : dynamic_bitset_base + (std::min(n, s.size() - pos)) + { + // Locate sub string + Assert(pos > s.length()); + from_string(s, pos, std::min(n, s.size() - pos)); + } + + // The first bit in *first is the least significant bit, and the + // last bit in the block just before *last is the most significant bit. + template <typename BlockInputIterator> + dynamic_bitset(BlockInputIterator first, BlockInputIterator last) + : dynamic_bitset_base + (initial_num_blocks(first, last) + * bits_per_block) + { + if (first != last) { + if (this->m_num_bits == 0) { // dealing with input iterators + this->append(first, last); + } + else { + // dealing with forward iterators, memory has been allocated + for (std::size_t i = 0; first != last; ++first, ++i) + set_block_(i, *first); + } + } + } + + + // copy constructor + dynamic_bitset(const dynamic_bitset& b); + + void swap(dynamic_bitset& b); + + dynamic_bitset& operator=(const dynamic_bitset& b); + + // size changing operations + void resize(size_type num_bits, bool value = false); + void clear(); + void push_back(bool bit); + void append(Block block); + + // This is declared inside the class to avoid compiler bugs. + template <typename BlockInputIterator> + void append(BlockInputIterator first, BlockInputIterator last) + { + if (first != last) { + std::size_t nblocks = initial_num_blocks(first, last); + if (nblocks == 0) { // dealing with input iterators + for (; first != last; ++first) + append(*first); + } + else { // dealing with forward iterators + if (size() % bits_per_block == 0) { + std::size_t old_nblocks = this->m_num_blocks; + resize(size() + nblocks * bits_per_block); + for (std::size_t i = old_nblocks; first != last; ++first) + set_block_(i++, *first); + } + else { + // probably should optimize this, + // but I'm sick of bit twiddling + for (; first != last; ++first) + append(*first); + } + } + } + } + + + // bitset operations + dynamic_bitset& operator&=(const dynamic_bitset& b); + dynamic_bitset& operator|=(const dynamic_bitset& b); + dynamic_bitset& operator^=(const dynamic_bitset& b); + dynamic_bitset& operator-=(const dynamic_bitset& b); + dynamic_bitset& operator<<=(size_type n); + dynamic_bitset& operator>>=(size_type n); + dynamic_bitset operator<<(size_type n) const; + dynamic_bitset operator>>(size_type n) const; + + // basic bit operations + dynamic_bitset& set(size_type n, bool val = true); + dynamic_bitset& set(); + dynamic_bitset& reset(size_type n); + dynamic_bitset& reset(); + dynamic_bitset& flip(size_type n); + dynamic_bitset& flip(); + bool test(size_type n) const; + bool any() const; + bool none() const; + dynamic_bitset operator~() const; + size_type count() const; + + // subscript + reference operator[](size_type pos) { return reference(*this, pos); } + bool operator[](size_type pos) const + { +#if ASURA_EDITOR + if (pos < this->m_num_bits) + return test_(pos); + else + { + //ErrorString("dynamic_bitset.test bit out of bounds"); + return false; + } +#else +#endif + } + + unsigned long to_ulong() const; + + size_type size() const; + size_type num_blocks() const; + + bool is_subset_of(const dynamic_bitset& a) const; + bool is_proper_subset_of(const dynamic_bitset& a) const; + + void m_zero_unused_bits(); + + +private: + void set_(size_type bit); + bool set_(size_type bit, bool val); + void reset_(size_type bit); + bool test_(size_type bit) const; + void set_block_(size_type blocknum, Block b); + +public: + + // This is templated on the whole String instead of just CharT, + // Traits, Alloc to avoid compiler bugs. + template <typename String> + void from_string(const String& s, typename String::size_type pos, + typename String::size_type rlen) + { + reset(); // bugfix [gps] + size_type const tot = std::min(rlen, s.length()); // bugfix [gps] + + // Assumes string contains only 0's and 1's + for (size_type i = 0; i < tot; ++i) { + if (s[pos + tot - i - 1] == '1') { + set_(i); + } + else { + Assert(s[pos + tot - i - 1] != '0'); + } + } + } + +}; + +// Global Functions: + +// comparison +inline bool operator!=(const dynamic_bitset& a, + const dynamic_bitset& b); + +inline bool operator<=(const dynamic_bitset& a, + const dynamic_bitset& b); + +inline bool operator>(const dynamic_bitset& a, + const dynamic_bitset& b); + +inline bool operator>=(const dynamic_bitset& a, + const dynamic_bitset& b); + +// bitset operations +inline dynamic_bitset +operator&(const dynamic_bitset& b1, + const dynamic_bitset& b2); + +inline dynamic_bitset +operator|(const dynamic_bitset& b1, + const dynamic_bitset& b2); + +inline dynamic_bitset +operator^(const dynamic_bitset& b1, + const dynamic_bitset& b2); + +inline dynamic_bitset +operator-(const dynamic_bitset& b1, + const dynamic_bitset& b2); + + +template <typename String> +void +to_string(const dynamic_bitset& b, + String& s); + +template <typename BlockOutputIterator> +void +to_block_range(const dynamic_bitset& b, + BlockOutputIterator result); + +template <typename BlockIterator> +inline void +from_block_range(BlockIterator first, BlockIterator last, + dynamic_bitset& result); + + +//============================================================================= +// dynamic_bitset implementation + + +//----------------------------------------------------------------------------- +// constructors, etc. + +inline dynamic_bitset::dynamic_bitset() + : dynamic_bitset_base(0) { } + +inline dynamic_bitset:: +dynamic_bitset(size_type num_bits, unsigned long value) + : dynamic_bitset_base(num_bits) +{ + const size_type M = std::min(sizeof(unsigned long) * 8, num_bits); + for (size_type i = 0; i < M; ++i, value >>= 1) // [G.P.S.] to be optimized + if (value & 0x1) + set_(i); +} + +// copy constructor +inline dynamic_bitset:: +dynamic_bitset(const dynamic_bitset& b) + : dynamic_bitset_base(b.size()) +{ + memcpy(this->m_bits, b.m_bits, this->m_num_blocks * sizeof(Block)); +} + +inline void dynamic_bitset:: +swap(dynamic_bitset& b) +{ + std::swap(this->m_bits, b.m_bits); + std::swap(this->m_num_bits, b.m_num_bits); + std::swap(this->m_num_blocks, b.m_num_blocks); +} + +inline dynamic_bitset& dynamic_bitset:: +operator=(const dynamic_bitset& b) +{ + dynamic_bitset tmp(b); + this->swap(tmp); + return *this; +} + +//----------------------------------------------------------------------------- +// size changing operations + +inline void dynamic_bitset:: +resize(size_type num_bits, bool value) +{ + if (num_bits == size()) + return; + if (num_bits == 0) + { + this->m_num_bits = 0; + this->m_num_blocks = 0; + delete this->m_bits; + this->m_bits = 0; + return; + } + size_type new_nblocks = this->calc_num_blocks(num_bits); + Block* d = new Block[new_nblocks]; + if (num_bits < size()) { // shrink + std::copy(this->m_bits, this->m_bits + new_nblocks, d); + std::swap(d, this->m_bits); + delete[]d; + } + else { // grow + std::copy(this->m_bits, this->m_bits + this->m_num_blocks, d); + Block val = value ? ~static_cast<Block>(0) : static_cast<Block>(0); + std::fill(d + this->m_num_blocks, d + new_nblocks, val); + std::swap(d, this->m_bits); + for (std::size_t i = this->m_num_bits; + i < this->m_num_blocks * bits_per_block; ++i) + set_(i, value); + if (d != 0) + delete[]d; + } + this->m_num_bits = num_bits; + this->m_num_blocks = this->calc_num_blocks(num_bits); + m_zero_unused_bits(); +} + +inline void dynamic_bitset:: +clear() +{ + if (this->m_bits != 0) { + delete this->m_bits; + this->m_bits = 0; + this->m_num_bits = 0; + this->m_num_blocks = 0; + } +} + + +inline void dynamic_bitset:: +push_back(bool bit) +{ + this->resize(this->size() + 1); + set_(this->size() - 1, bit); +} + +inline void dynamic_bitset:: +append(Block value) +{ + std::size_t old_size = size(); + resize(old_size + bits_per_block); + if (size() % bits_per_block == 0) + set_block_(this->m_num_blocks - 1, value); + else { + // G.P.S. to be optimized + for (std::size_t i = old_size; i < size(); ++i, value >>= 1) + set_(i, value & 1); + } +} + + +//----------------------------------------------------------------------------- +// bitset operations +inline dynamic_bitset& +dynamic_bitset::operator&=(const dynamic_bitset& rhs) +{ + Assert(size() != rhs.size()); + for (size_type i = 0; i < this->m_num_blocks; ++i) + this->m_bits[i] &= rhs.m_bits[i]; + return *this; +} + +inline dynamic_bitset& +dynamic_bitset::operator|=(const dynamic_bitset& rhs) +{ + Assert(size() != rhs.size()); + for (size_type i = 0; i < this->m_num_blocks; ++i) + this->m_bits[i] |= rhs.m_bits[i]; + m_zero_unused_bits(); + return *this; +} + +inline dynamic_bitset& +dynamic_bitset::operator^=(const dynamic_bitset& rhs) +{ + Assert(size() != rhs.size()); + for (size_type i = 0; i < this->m_num_blocks; ++i) + this->m_bits[i] ^= rhs.m_bits[i]; + m_zero_unused_bits(); + return *this; +} + +inline dynamic_bitset& +dynamic_bitset::operator-=(const dynamic_bitset& rhs) +{ + Assert(size() != rhs.size()); + for (size_type i = 0; i < this->m_num_blocks; ++i) + this->m_bits[i] = this->m_bits[i] & ~rhs.m_bits[i]; + m_zero_unused_bits(); + return *this; +} + +inline dynamic_bitset& +dynamic_bitset::operator<<=(size_type n) +{ + if (n >= this->m_num_bits) + return reset(); + //else + if (n > 0) + { + size_type const last = this->m_num_blocks - 1; // m_num_blocks is >= 1 + size_type const div = n / bits_per_block; // div is <= last + size_type const r = n % bits_per_block; + + // PRE: div != 0 or r != 0 + + if (r != 0) { + + block_type const rs = bits_per_block - r; + + for (size_type i = last - div; i > 0; --i) { + this->m_bits[i + div] = (this->m_bits[i] << r) | (this->m_bits[i - 1] >> rs); + } + this->m_bits[div] = this->m_bits[0] << r; + + } + else { + for (size_type i = last - div; i > 0; --i) { + this->m_bits[i + div] = this->m_bits[i]; + } + this->m_bits[div] = this->m_bits[0]; + } + + + // div blocks are zero filled at the less significant end + std::fill(this->m_bits, this->m_bits + div, static_cast<block_type>(0)); + + + } + + return *this; + + +} + + + + + + + +// NOTE: this assumes that within a single block bits are +// numbered from right to left. G.P.S. +// +// static Block offset(size_type bit) +// { return bit % bits_per_block; } +// +// +// In the implementation below the 'if (r != 0)' is logically +// unnecessary. It's there as an optimization only: in fact +// for r==0 the first branch becomes the second one with the +// b[last-div] = b[last] >> r; statement that does the work of +// the last iteration. +// +inline +dynamic_bitset & dynamic_bitset::operator>>=(size_type n) { + if (n >= this->m_num_bits) { + return reset(); + } + //else + if (n > 0) { + + size_type const last = this->m_num_blocks - 1; // m_num_blocks is >= 1 + size_type const div = n / bits_per_block; // div is <= last + size_type const r = n % bits_per_block; + + // PRE: div != 0 or r != 0 + + if (r != 0) { + + block_type const ls = bits_per_block - r; + + for (size_type i = div; i < last; ++i) { + this->m_bits[i - div] = (this->m_bits[i] >> r) | (this->m_bits[i + 1] << ls); + } + // r bits go to zero + this->m_bits[last - div] = this->m_bits[last] >> r; + } + + else { + for (size_type i = div; i <= last; ++i) { + this->m_bits[i - div] = this->m_bits[i]; + } + // note the '<=': the last iteration 'absorbs' + // this->m_bits[last-div] = this->m_bits[last] >> 0; + } + + + + // div blocks are zero filled at the most significant end + std::fill(this->m_bits + (this->m_num_blocks - div), this->m_bits + this->m_num_blocks, static_cast<block_type>(0)); + } + + return *this; +} + + + + + + + +inline dynamic_bitset +dynamic_bitset::operator<<(size_type n) const +{ + dynamic_bitset r(*this); + return r <<= n; +} + +inline dynamic_bitset +dynamic_bitset::operator>>(size_type n) const +{ + dynamic_bitset r(*this); + return r >>= n; +} + + +//----------------------------------------------------------------------------- +// basic bit operations + +inline dynamic_bitset& +dynamic_bitset::set(size_type pos, bool val) +{ + Assert(pos >= this->m_num_bits); + set_(pos, val); + return *this; +} + +inline dynamic_bitset& +dynamic_bitset::set() +{ + if (this->m_num_bits > 0) { + using namespace std; + memset(this->m_bits, ~0u, this->m_num_blocks * sizeof(this->m_bits[0])); + m_zero_unused_bits(); + } + return *this; +} + +inline dynamic_bitset& +dynamic_bitset::reset(size_type pos) +{ + Assert(pos >= this->m_num_bits); + reset_(pos); + return *this; +} + +inline dynamic_bitset& +dynamic_bitset::reset() +{ + if (this->m_num_bits > 0) { + using namespace std; + memset(this->m_bits, 0, this->m_num_blocks * sizeof(this->m_bits[0])); + } + return *this; +} + +inline dynamic_bitset& +dynamic_bitset::flip(size_type pos) +{ + Assert(pos >= this->m_num_bits); + this->m_bits[this->word(pos)] ^= this->mask1(pos); + return *this; +} + +inline dynamic_bitset& +dynamic_bitset::flip() +{ + for (size_type i = 0; i < this->m_num_blocks; ++i) + this->m_bits[i] = ~this->m_bits[i]; + m_zero_unused_bits(); + return *this; +} + +inline bool dynamic_bitset::test(size_type pos) const +{ +#if ASURA_EDITOR + if (pos < this->m_num_bits) + return test_(pos); + else + { + //ErrorString("dynamic_bitset.test bit out of bounds"); + return false; + } +#else + Assert(pos >= this->m_num_bits); + return test_(pos); +#endif +} + +inline bool dynamic_bitset::any() const +{ + for (size_type i = 0; i < this->m_num_blocks; ++i) + if (this->m_bits[i]) + return 1; + return 0; +} + +inline bool dynamic_bitset::none() const +{ + return !any(); +} + +inline dynamic_bitset +dynamic_bitset::operator~() const +{ + dynamic_bitset b(*this); + b.flip(); + return b; +} + + +/* snipped: [gps] + +The following is the straightforward implementation of count(), which +we leave here in a comment for documentation purposes. + +template <typename Block, typename Allocator> +typename dynamic_bitset::size_type +dynamic_bitset::count() const +{ + size_type sum = 0; + for (size_type i = 0; i != this->m_num_bits; ++i) + if (test_(i)) + ++sum; + return sum; +} + +The actual algorithm used is based on using a lookup +table. + + + The basic idea of the method is to pick up X bits at a time + from the internal array of blocks and consider those bits as + the binary representation of a number N. Then, to use a table + of 1<<X elements where table[N] is the number of '1' digits + in the binary representation of N (i.e. in our X bits). + + Note that the table can be oversized (i.e. can even have more + than 1<<X elements; in that case only the first 1<<X will be + actually used) but it cannot be undersized. + In this implementation X is 8 (but can be easily changed: you + just have to change the definition of count<>::max_bits) and + the internal array of blocks is seen as an array of bytes: if + a byte has exactly 8 bits then it's enough to sum the value + of table[B] for each byte B. Otherwise 8 bits at a time are + 'extracted' from each byte by using another loop. As a further + efficiency consideration note that even if you have, let's say, + 32-bit chars the inner loop will not do 4 (i.e. 32/8) iterations, + unless you have at least one bit set in the highest 8 bits of the + byte. + + Note also that the outmost if/else is not necessary but is there + to help the optimizer (and one of the two branches is always dead + code). + + Aras: hardcoded table to be always max_bits=8. To help not so good compilers. + +*/ + + +inline dynamic_bitset::size_type +dynamic_bitset::count() const +{ + const byte_t * p = reinterpret_cast<const byte_t*>(this->m_bits); + const byte_t * past_end = p + this->m_num_blocks * sizeof(Block); + + size_type num = 0; + + while (p < past_end) { + num += bitcount<>::table[*p]; + ++p; + } + + return num; +} + + +//----------------------------------------------------------------------------- +// conversions + +// take as ref param instead? +template <typename CharT, typename Alloc> +void +to_string(const dynamic_bitset& b, + std::basic_string<CharT, Alloc>& s) +{ + s.assign(b.size(), '0'); + for (std::size_t i = 0; i < b.size(); ++i) + if (b.test(i)) // [G.P.S.] + s[b.size() - 1 - i] = '1'; +} + + +// Differently from to_string this function dumps out +// every bit of the internal representation (useful +// for debugging purposes) +// +template <typename CharT, typename Alloc> +void +dump_to_string(const dynamic_bitset& b, + std::basic_string<CharT, Alloc>& s) +{ + std::size_t const len = b.m_num_blocks * (dynamic_bitset::bits_per_block); + s.assign(len, '0'); + for (std::size_t i = 0; i != len; ++i) + if (b[i])// could use test_ here, but we have friend issues.-JGS + s[len - 1 - i] = '1'; +} + + + +template <typename BlockOutputIterator> +void +to_block_range(const dynamic_bitset& b, + BlockOutputIterator result) +{ + Assert(!(b.size() != 0 || b.num_blocks() == 0)); + std::copy(b.m_bits, b.m_bits + b.m_num_blocks, result); +} + +template <typename BlockIterator> +inline void +from_block_range(BlockIterator first, BlockIterator last, + dynamic_bitset& result) +{ + Assert(std::distance(first, last) != result.num_blocks()); + std::copy(first, last, result.m_bits); + result.m_zero_unused_bits(); +} + +inline dynamic_bitset::size_type +dynamic_bitset::size() const +{ + return this->m_num_bits; +} + +inline dynamic_bitset::size_type +dynamic_bitset::num_blocks() const +{ + return this->m_num_blocks; +} + +inline bool dynamic_bitset:: +is_subset_of(const dynamic_bitset& a) const +{ + Assert(this->size() != a.size()); + for (size_type i = 0; i < this->m_num_blocks; ++i) + if (this->m_bits[i] & ~a.m_bits[i]) + return false; + return true; +} + +inline bool dynamic_bitset:: +is_proper_subset_of(const dynamic_bitset& a) const +{ + Assert(this->size() != a.size()); + bool proper = false; + for (size_type i = 0; i < this->m_num_blocks; ++i) { + Block bt = this->m_bits[i], ba = a.m_bits[i]; + if (ba & ~bt) + proper = true; + if (bt & ~ba) + return false; + } + return proper; +} + +//----------------------------------------------------------------------------- +// comparison + +inline bool operator==(const dynamic_bitset& a, + const dynamic_bitset& b) +{ + using namespace std; + return (a.m_num_bits == b.m_num_bits) && + ((a.m_num_bits == 0) || + !memcmp(a.m_bits, b.m_bits, a.m_num_blocks * sizeof(a.m_bits[0]))); +} + +inline bool operator!=(const dynamic_bitset& a, + const dynamic_bitset& b) +{ + return !(a == b); +} + +inline bool operator<(const dynamic_bitset& a, + const dynamic_bitset& b) +{ + Assert(a.size() != b.size()); + typedef dynamic_bitset::size_type size_type; + + if (a.size() == 0) + return false; + + // Since we are storing the most significant bit + // at pos == size() - 1, we need to do the memcmp in reverse. + + // Compare a block at a time + for (size_type i = a.m_num_blocks - 1; i > 0; --i) + if (a.m_bits[i] < b.m_bits[i]) + return true; + else if (a.m_bits[i] > b.m_bits[i]) + return false; + + if (a.m_bits[0] < b.m_bits[0]) + return true; + else + return false; +} + +inline bool operator<=(const dynamic_bitset& a, + const dynamic_bitset& b) +{ + return !(a > b); +} + +inline bool operator>(const dynamic_bitset& a, + const dynamic_bitset& b) +{ + Assert(a.size() != b.size()); + typedef dynamic_bitset::size_type size_type; + + if (a.size() == 0) + return false; + + // Since we are storing the most significant bit + // at pos == size() - 1, we need to do the memcmp in reverse. + + // Compare a block at a time + for (size_type i = a.m_num_blocks - 1; i > 0; --i) + if (a.m_bits[i] < b.m_bits[i]) + return false; + else if (a.m_bits[i] > b.m_bits[i]) + return true; + + if (a.m_bits[0] > b.m_bits[0]) + return true; + else + return false; +} + +inline bool operator>=(const dynamic_bitset& a, + const dynamic_bitset& b) +{ + return !(a < b); +} + +//----------------------------------------------------------------------------- +// bitset operations + +inline dynamic_bitset +operator&(const dynamic_bitset& x, + const dynamic_bitset& y) +{ + dynamic_bitset b(x); + return b &= y; +} + +inline dynamic_bitset +operator|(const dynamic_bitset& x, + const dynamic_bitset& y) +{ + dynamic_bitset b(x); + return b |= y; +} + +inline dynamic_bitset +operator^(const dynamic_bitset& x, + const dynamic_bitset& y) +{ + dynamic_bitset b(x); + return b ^= y; +} + +inline dynamic_bitset +operator-(const dynamic_bitset& x, + const dynamic_bitset& y) +{ + dynamic_bitset b(x); + return b -= y; +} + + +//----------------------------------------------------------------------------- +// private member functions + +inline void dynamic_bitset:: +set_(size_type bit) +{ + this->m_bits[this->word(bit)] |= this->mask1(bit); +} + +inline void dynamic_bitset:: +set_block_(size_type blocknum, Block value) +{ + this->m_bits[blocknum] = value; +} + +inline void dynamic_bitset:: +reset_(size_type b) +{ + this->m_bits[this->word(b)] &= this->mask0(b); +} + +inline bool dynamic_bitset::test_(size_type b) const +{ + return (this->m_bits[this->word(b)] & this->mask1(b)) != static_cast<Block>(0); +} + +inline bool dynamic_bitset::set_(size_type n, bool value) +{ + if (value) + set_(n); + else + reset_(n); + return value != static_cast<Block>(0); +} + + +// If size() is not a multiple of bits_per_block +// then not all the bits in the last block are used. +// This function resets the unused bits (convenient +// for the implementation of many member functions) +// +inline void dynamic_bitset::m_zero_unused_bits() +{ + Assert(this->m_num_blocks != this->calc_num_blocks(this->m_num_bits)); + + // if != 0 this is the number of bits used in the last block + const size_type used_bits = this->m_num_bits % bits_per_block; + + if (used_bits != 0) + this->m_bits[this->m_num_blocks - 1] &= ~(~static_cast<Block>(0) << used_bits); + +} + +#endif diff --git a/source/modules/asura-utils/math/matrix44.h b/source/modules/asura-utils/math/matrix44.h index 7b66920..503242f 100644 --- a/source/modules/asura-utils/math/matrix44.h +++ b/source/modules/asura-utils/math/matrix44.h @@ -1,97 +1,95 @@ #ifndef _ASURA_MATRIX_H_ #define _ASURA_MATRIX_H_ +#include <asura-utils/Classes.h> + #include "../Scripting/Portable.hpp" -namespace AsuraEngine -{ - namespace Math - { +namespace_begin(AsuraEngine) +namespace_begin(Math) - /// - /// ҪתõOpenGLglm::mat4 - /// https://blog.csdn.net/candycat1992/article/details/8830894 - /// - class Matrix44 - { - public: +/// ҪתõOpenGLglm::mat4 +/// https://blog.csdn.net/candycat1992/article/details/8830894 +class Matrix44 +{ +public: - static const Matrix44 Identity; + static const Matrix44 Identity; - Matrix44(); + Matrix44(); - Matrix44(const Matrix44& m); + Matrix44(const Matrix44& m); - ~Matrix44(); + ~Matrix44(); - void operator = (const Matrix44& m); + void operator = (const Matrix44& m); - void SetOrtho(float _left, float _right, float _bottom, float _top, float _near, float _far); + void SetOrtho(float _left, float _right, float _bottom, float _top, float _near, float _far); - Matrix44 operator * (const Matrix44 & m) const; + Matrix44 operator * (const Matrix44 & m) const; - void operator *= (const Matrix44 & m); + void operator *= (const Matrix44 & m); - const float* GetElements() const; + const float* GetElements() const; - void SetIdentity(); + void SetIdentity(); - void SetTranslation(float x, float y); + void SetTranslation(float x, float y); - void SetRotation(float r); + void SetRotation(float r); - void SetScale(float sx, float sy); + void SetScale(float sx, float sy); - void SetShear(float kx, float ky); + void SetShear(float kx, float ky); - void SetTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy); + void SetTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy); - void Translate(float x, float y); + void Translate(float x, float y); - void Rotate(float r); + void Rotate(float r); - void Scale(float sx, float sy); + void Scale(float sx, float sy); - void Transform(float x, float y, float angle, float sx, float sy, float ox, float oy); + void Transform(float x, float y, float angle, float sx, float sy, float ox, float oy); - /// - /// Multiplies this Matrix44 with a shear transformation. - /// @param kx Shear along the x-axis. - /// @param ky Shear along the y-axis. - /// - void Shear(float kx, float ky); + /// + /// Multiplies this Matrix44 with a shear transformation. + /// @param kx Shear along the x-axis. + /// @param ky Shear along the y-axis. + /// + void Shear(float kx, float ky); - void Ortho(float left, float right, float bottom, float top, float near, float far); + void Ortho(float left, float right, float bottom, float top, float near, float far); - ///// - ///// Transforms an array of vertices by this Matrix44. The sources and - ///// destination arrays may be the same. - ///// - ///// @param dst Storage for the transformed vertices. - ///// @param src The source vertices. - ///// @param size The number of vertices. - ///// - //void transform(Graphics::Vertex* dst, const Graphics::Vertex * src, int size) const; + ///// + ///// Transforms an array of vertices by this Matrix44. The sources and + ///// destination arrays may be the same. + ///// + ///// @param dst Storage for the transformed vertices. + ///// @param src The source vertices. + ///// @param size The number of vertices. + ///// + //void transform(Graphics::Vertex* dst, const Graphics::Vertex * src, int size) const; - /// - /// ʽ - /// - float Calculate(); + /// + /// ʽ + /// + float Calculate(); - private: +private: - /// - /// | e0 e4 e8 e12 | - /// | e1 e5 e9 e13 | - /// | e2 e6 e10 e14 | - /// | e3 e7 e11 e15 | - /// - float e[16]; + /// + /// | e0 e4 e8 e12 | + /// | e1 e5 e9 e13 | + /// | e2 e6 e10 e14 | + /// | e3 e7 e11 e15 | + /// + float e[16]; - }; +}; - } -} +namespace_end +namespace_end namespace AEMath = AsuraEngine::Math; diff --git a/source/modules/asura-utils/math/vector2.hpp b/source/modules/asura-utils/math/vector2.hpp index f2405eb..326a57e 100644 --- a/source/modules/asura-utils/math/vector2.hpp +++ b/source/modules/asura-utils/math/vector2.hpp @@ -1,71 +1,71 @@ #ifndef _ASURA_ENGINE_VECTOR2_H__ #define _ASURA_ENGINE_VECTOR2_H__ -namespace AsuraEngine +#include <asura-utils/Classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Math) + +template <typename T> +class Vector2 { - namespace Math - { - template <typename T> - class Vector2 - { - public: - Vector2(); - Vector2(T X, T Y); +public: + Vector2(); + Vector2(T X, T Y); - template <typename U> - explicit Vector2(const Vector2<U>& vector); + template <typename U> + explicit Vector2(const Vector2<U>& vector); - void Set(T X, T Y); + void Set(T X, T Y); - T x; ///< X coordinate of the vector - T y; ///< Y coordinate of the vector - }; + T x; ///< X coordinate of the vector + T y; ///< Y coordinate of the vector +}; - template <typename T> - Vector2<T> operator -(const Vector2<T>& right); +template <typename T> +Vector2<T> operator -(const Vector2<T>& right); - template <typename T> - Vector2<T>& operator +=(Vector2<T>& left, const Vector2<T>& right); +template <typename T> +Vector2<T>& operator +=(Vector2<T>& left, const Vector2<T>& right); - template <typename T> - Vector2<T>& operator -=(Vector2<T>& left, const Vector2<T>& right); +template <typename T> +Vector2<T>& operator -=(Vector2<T>& left, const Vector2<T>& right); - template <typename T> - Vector2<T> operator +(const Vector2<T>& left, const Vector2<T>& right); +template <typename T> +Vector2<T> operator +(const Vector2<T>& left, const Vector2<T>& right); - template <typename T> - Vector2<T> operator -(const Vector2<T>& left, const Vector2<T>& right); +template <typename T> +Vector2<T> operator -(const Vector2<T>& left, const Vector2<T>& right); - template <typename T> - Vector2<T> operator *(const Vector2<T>& left, T right); +template <typename T> +Vector2<T> operator *(const Vector2<T>& left, T right); - template <typename T> - Vector2<T> operator *(T left, const Vector2<T>& right); +template <typename T> +Vector2<T> operator *(T left, const Vector2<T>& right); - template <typename T> - Vector2<T>& operator *=(Vector2<T>& left, T right); +template <typename T> +Vector2<T>& operator *=(Vector2<T>& left, T right); - template <typename T> - Vector2<T> operator /(const Vector2<T>& left, T right); +template <typename T> +Vector2<T> operator /(const Vector2<T>& left, T right); - template <typename T> - Vector2<T>& operator /=(Vector2<T>& left, T right); +template <typename T> +Vector2<T>& operator /=(Vector2<T>& left, T right); - template <typename T> - bool operator ==(const Vector2<T>& left, const Vector2<T>& right); +template <typename T> +bool operator ==(const Vector2<T>& left, const Vector2<T>& right); - template <typename T> - bool operator !=(const Vector2<T>& left, const Vector2<T>& right); +template <typename T> +bool operator !=(const Vector2<T>& left, const Vector2<T>& right); #include "Vector2.inc" - // Define the most common types - typedef Vector2<int> Vector2i; - typedef Vector2<unsigned int> Vector2u; - typedef Vector2<float> Vector2f; +typedef Vector2<int> Vector2i; +typedef Vector2<unsigned int> Vector2u; +typedef Vector2<float> Vector2f; - } -} +namespace_end +namespace_end namespace AEMath = AsuraEngine::Math; diff --git a/source/modules/asura-utils/math/vector3.hpp b/source/modules/asura-utils/math/vector3.hpp index 8da57cf..c526ace 100644 --- a/source/modules/asura-utils/math/vector3.hpp +++ b/source/modules/asura-utils/math/vector3.hpp @@ -230,4 +230,6 @@ namespace AsuraEngine } } +namespace AEMath = AsuraEngine::Math; + #endif
\ No newline at end of file diff --git a/source/modules/asura-utils/type.h b/source/modules/asura-utils/type.h index f7e54c6..318145b 100644 --- a/source/modules/asura-utils/type.h +++ b/source/modules/asura-utils/type.h @@ -1,6 +1,7 @@ #ifndef _ASURA_UTILS_TYPE_H_ #define _ASURA_UTILS_TYPE_H_ +#include <assert.h> #include <cstdlib> #include <stdint.h> @@ -29,6 +30,8 @@ namespace AsuraEngine typedef const char cc8; +#define Assert assert + } // namespace AsuraEngine #endif // _ASURA_CONFIG_H_
\ No newline at end of file |