diff options
Diffstat (limited to 'source/modules')
315 files changed, 8528 insertions, 682 deletions
diff --git a/source/modules/asura-base/Config.h b/source/modules/asura-base/Config.h new file mode 100644 index 0000000..024ac79 --- /dev/null +++ b/source/modules/asura-base/Config.h @@ -0,0 +1,69 @@ +#ifndef __ASURA_BASE_CONFIG_H__ +#define __ASURA_BASE_CONFIG_H__ + +// ڱ༭»Ĵ +#define ASURA_EDITOR 1 + +// ʱеĴ +#define ASURA_RUNTIME 1 + +//--------------------------------------------------------------------------------// + +#ifndef ASSERT +#ifdef NDEBUG +#define ASSERT(x) { false ? (void)(x) : (void)0; } +#else +#ifdef _WIN32 +#define ASURA_DEBUG_BREAK() __debugbreak() +#else +#define ASURA_DEBUG_BREAK() raise(SIGTRAP) +#endif +#define ASSERT(x) do { const volatile bool asura_assert_b____ = !(x); if(asura_assert_b____) ASURA_DEBUG_BREAK(); } while (false) +#endif +#endif + +//--------------------------------------------------------------------------------// + +#ifdef _WIN32 + #define ASURA_FINAL final + #define ASURA_EXPORT __declspec(dllexport) + #define ASURA_IMPORT __declspec(dllimport) + #define ASURA_FORCE_INLINE __forceinline + #define ASURA_RESTRICT __restrict + #define ASURA_API ASURA_EXPORT + #define ASURA_ATTRIBUTE_USED + #define ASURA_ABSTRACT + #define ASURA_WINDOWS 1 +#else + #define ASURA_FINAL final + #define ASURA_EXPORT __attribute__((visibility("default"))) + #define ASURA_IMPORT + #define ASURA_FORCE_INLINE __attribute__((always_inline)) inline + #define ASURA_RESTRICT __restrict__ + #define ASURA_ATTRIBUTE_USED __attribute__((used)) + #define ASURA_ABSTRACT + #define ASURA_API ASURA_EXPORT +#endif + +/// +/// ƶָȨ +/// +#define ASURA_MOVE + +#define ASURA_DEBUG 0 + +//--------------------------------------------------------------------------------// + +#define ASURA_SDL_HOST 1 + +#define ASURA_LITTLE_ENDIAN 1 + +//--------------------------------------------------------------------------------// +// չؼ + +#define ASURA_THROW(ex) throw(ex) // ʾ׳쳣 + +#define ASURA_OUT +#define ASURA_REF + +#endif
\ No newline at end of file diff --git a/source/modules/asura-box2d/box2d_module.cpp b/source/modules/asura-box2d/Box2DModule.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-box2d/box2d_module.cpp +++ b/source/modules/asura-box2d/Box2DModule.cpp diff --git a/source/modules/asura-box2d/box2d_module.h b/source/modules/asura-box2d/Box2DModule.h index 052078a..1a00608 100644 --- a/source/modules/asura-box2d/box2d_module.h +++ b/source/modules/asura-box2d/Box2DModule.h @@ -1,7 +1,7 @@ #ifndef __ASURA_BOX2D_MODULE_H__ #define __ASURA_BOX2D_MODULE_H__ -#include <asura-utils/module.h> +#include <asura-utils/Module.h> namespace AsuraEngine { diff --git a/source/modules/asura-box2d/Physics/Body.h b/source/modules/asura-box2d/Physics/Body.h new file mode 100644 index 0000000..e5af76a --- /dev/null +++ b/source/modules/asura-box2d/Physics/Body.h @@ -0,0 +1,67 @@ +#ifndef __ASURA_BOX2D_BODY_H__ +#define __ASURA_BOX2D_BODY_H__ + +#include <Box2D/Box2D.h> + +#include <asura-utils/Scripting/Portable.hpp> + +namespace AsuraEngine +{ + namespace Physics + { + + class World; + class Joint; + + enum BodyType + { + BODY_TYPE_INVALID, + BODY_TYPE_STATIC, + BODY_TYPE_DYNAMIC, + BODY_TYPE_KINEMATIC + }; + + class Body + : public AEScripting::Portable<Body> + { + public: + + private: + + friend class Joint; + + //----------------------------------------------------------------------------// + + LUAX_DECL_FACTORY(Body); + + 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; + + }; + + } +} + +#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 new file mode 100644 index 0000000..2ce19fb --- /dev/null +++ b/source/modules/asura-box2d/Physics/ChainShape.h @@ -0,0 +1,29 @@ +#ifndef __ASURA_CHAIN_SHAPE_H__ +#define __ASURA_CHAIN_SHAPE_H__ + +#include <Box2D/Collision/Shapes/b2ChainShape.h> + +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Physics) + +class ChainShape + : AEScripting::Portable<ChainShape> +{ +public: + + ChainShape(); + ~ChainShape(); + +private: + + b2ChainShape* mShape; + +}; + +namespace_end +namespace_end + +#endif
\ No newline at end of file diff --git a/source/modules/asura-box2d/physics/circle_shape.h b/source/modules/asura-box2d/Physics/CircleShape.h index e69de29..e69de29 100644 --- a/source/modules/asura-box2d/physics/circle_shape.h +++ b/source/modules/asura-box2d/Physics/CircleShape.h diff --git a/source/modules/asura-box2d/physics/distance_joint.h b/source/modules/asura-box2d/Physics/Contact.h index e69de29..e69de29 100644 --- a/source/modules/asura-box2d/physics/distance_joint.h +++ b/source/modules/asura-box2d/Physics/Contact.h diff --git a/source/modules/asura-box2d/Physics/DebugDraw.h b/source/modules/asura-box2d/Physics/DebugDraw.h new file mode 100644 index 0000000..a92be43 --- /dev/null +++ b/source/modules/asura-box2d/Physics/DebugDraw.h @@ -0,0 +1,9 @@ +#ifndef _ASURA_BOX2D_DEBUG_DRAW_H_ +#define _ASURA_BOX2D_DEBUG_DRAW_H_ + +namespace AsuraEngine +{ + +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-box2d/physics/edge_shape.h b/source/modules/asura-box2d/Physics/DistanceJoint.h index e69de29..e69de29 100644 --- a/source/modules/asura-box2d/physics/edge_shape.h +++ b/source/modules/asura-box2d/Physics/DistanceJoint.h diff --git a/source/modules/asura-box2d/physics/friction_joint.h b/source/modules/asura-box2d/Physics/EdgeShape.h index e69de29..e69de29 100644 --- a/source/modules/asura-box2d/physics/friction_joint.h +++ b/source/modules/asura-box2d/Physics/EdgeShape.h diff --git a/source/modules/asura-box2d/physics/gear_joint.h b/source/modules/asura-box2d/Physics/Fixture.h index e69de29..e69de29 100644 --- a/source/modules/asura-box2d/physics/gear_joint.h +++ b/source/modules/asura-box2d/Physics/Fixture.h diff --git a/source/modules/asura-box2d/physics/motor_joint.h b/source/modules/asura-box2d/Physics/FrictionJoint.h index e69de29..e69de29 100644 --- a/source/modules/asura-box2d/physics/motor_joint.h +++ b/source/modules/asura-box2d/Physics/FrictionJoint.h diff --git a/source/modules/asura-box2d/physics/mouse_joint.h b/source/modules/asura-box2d/Physics/GearJoint.h index e69de29..e69de29 100644 --- a/source/modules/asura-box2d/physics/mouse_joint.h +++ b/source/modules/asura-box2d/Physics/GearJoint.h diff --git a/source/modules/asura-box2d/physics/polygon_shape.h b/source/modules/asura-box2d/Physics/Joint.h index e69de29..e69de29 100644 --- a/source/modules/asura-box2d/physics/polygon_shape.h +++ b/source/modules/asura-box2d/Physics/Joint.h diff --git a/source/modules/asura-box2d/physics/prismatic_joint.h b/source/modules/asura-box2d/Physics/MotorJoint.h index e69de29..e69de29 100644 --- a/source/modules/asura-box2d/physics/prismatic_joint.h +++ b/source/modules/asura-box2d/Physics/MotorJoint.h diff --git a/source/modules/asura-box2d/physics/pulley_joint.h b/source/modules/asura-box2d/Physics/MouseJoint.h index e69de29..e69de29 100644 --- a/source/modules/asura-box2d/physics/pulley_joint.h +++ b/source/modules/asura-box2d/Physics/MouseJoint.h diff --git a/source/modules/asura-box2d/physics/revolute_joint.h b/source/modules/asura-box2d/Physics/PolygonShape.h index e69de29..e69de29 100644 --- a/source/modules/asura-box2d/physics/revolute_joint.h +++ b/source/modules/asura-box2d/Physics/PolygonShape.h diff --git a/source/modules/asura-box2d/physics/rope_joint.h b/source/modules/asura-box2d/Physics/PrismaticJoint.h index e69de29..e69de29 100644 --- a/source/modules/asura-box2d/physics/rope_joint.h +++ b/source/modules/asura-box2d/Physics/PrismaticJoint.h diff --git a/source/modules/asura-box2d/physics/weld_joint.h b/source/modules/asura-box2d/Physics/PulleyJoint.h index e69de29..e69de29 100644 --- a/source/modules/asura-box2d/physics/weld_joint.h +++ b/source/modules/asura-box2d/Physics/PulleyJoint.h diff --git a/source/modules/asura-box2d/physics/wheel_joint.h b/source/modules/asura-box2d/Physics/RevoluteJoint.h index e69de29..e69de29 100644 --- a/source/modules/asura-box2d/physics/wheel_joint.h +++ b/source/modules/asura-box2d/Physics/RevoluteJoint.h diff --git a/source/modules/asura-core/graphics/color_palette.h b/source/modules/asura-box2d/Physics/RopeJoint.h index e69de29..e69de29 100644 --- a/source/modules/asura-core/graphics/color_palette.h +++ b/source/modules/asura-box2d/Physics/RopeJoint.h diff --git a/source/modules/asura-core/graphics/render_target.cpp b/source/modules/asura-box2d/Physics/Shape.h index e69de29..e69de29 100644 --- a/source/modules/asura-core/graphics/render_target.cpp +++ b/source/modules/asura-box2d/Physics/Shape.h diff --git a/source/modules/asura-core/graphics/sprite_batch.cpp b/source/modules/asura-box2d/Physics/WeldJoint.h index e69de29..e69de29 100644 --- a/source/modules/asura-core/graphics/sprite_batch.cpp +++ b/source/modules/asura-box2d/Physics/WeldJoint.h diff --git a/source/modules/asura-core/input/input_device.cpp b/source/modules/asura-box2d/Physics/WheelJoint.h index e69de29..e69de29 100644 --- a/source/modules/asura-core/input/input_device.cpp +++ b/source/modules/asura-box2d/Physics/WheelJoint.h diff --git a/source/modules/asura-box2d/Physics/World.h b/source/modules/asura-box2d/Physics/World.h new file mode 100644 index 0000000..b6d00ca --- /dev/null +++ b/source/modules/asura-box2d/Physics/World.h @@ -0,0 +1,19 @@ +#ifndef __ASURA_BOX2D_WORLD_H__ +#define __ASURA_BOX2D_WORLD_H__ + +#include <asura-utils/Scripting/Portable.hpp> + +namespace AsuraEngine +{ + namespace Physics + { + + class World : public AEScripting::Portable<World> + { + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-box2d/Physics/binding/_body.cpp b/source/modules/asura-box2d/Physics/binding/_body.cpp new file mode 100644 index 0000000..0c9e3e8 --- /dev/null +++ b/source/modules/asura-box2d/Physics/binding/_body.cpp @@ -0,0 +1,171 @@ +#include "../Body.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Physics + { + + LUAX_REGISTRY(Body) + { + LUAX_REGISTER_METHODS(state, + { "GetType", _GetType }, + { "GetX", _GetX }, + { "GetY", _GetY }, + { "GetAngle", _GetAngle }, + { "GetPosition", _GetPosition }, + { "GetLinearVelocity", _GetLinearVelocity }, + { "GetWorldCenter", _GetWorldCenter }, + { "GetLocalCenter", _GetLocalCenter }, + { "GetAngularVelocity", _GetAngularVelocity }, + { "GetMass", _GetMass }, + { "GetInertia", _GetInertia }, + { "GetMassData", _GetMassData }, + { "GetAngularDamping", _GetAngularDamping }, + { "GetLinearDamping", _GetLinearDamping }, + { "GetGravityScale", _GetGravityScale }, + { "GetGravityScale", _GetGravityScale } + ); + } + + LUAX_POSTPROCESS(Body) + { + LUAX_REGISTER_ENUM(state, "EBodyType", + { "INVALID", BODY_TYPE_INVALID }, + { "STATIC", BODY_TYPE_STATIC }, + { "DYNAMIC", BODY_TYPE_DYNAMIC }, + { "KINEMATIC", BODY_TYPE_KINEMATIC } + ); + + } + + // body:GetType() + LUAX_IMPL_METHOD(Body, _GetType) + { + LUAX_PREPARE(L, Body); + return 0; + } + + // body:GetX() + LUAX_IMPL_METHOD(Body, _GetX) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetY() + LUAX_IMPL_METHOD(Body, _GetY) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetAngle() + LUAX_IMPL_METHOD(Body, _GetAngle) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetPosition() + LUAX_IMPL_METHOD(Body, _GetPosition) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetLinearVelocity() + LUAX_IMPL_METHOD(Body, _GetLinearVelocity) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetWorldCenter() + LUAX_IMPL_METHOD(Body, _GetWorldCenter) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetLocalCenter() + LUAX_IMPL_METHOD(Body, _GetLocalCenter) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetAngularVelocity() + LUAX_IMPL_METHOD(Body, _GetAngularVelocity) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetMass() + LUAX_IMPL_METHOD(Body, _GetMass) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetInertia() + LUAX_IMPL_METHOD(Body, _GetInertia) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetMassData() + LUAX_IMPL_METHOD(Body, _GetMassData) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetAngularDamping() + LUAX_IMPL_METHOD(Body, _GetAngularDamping) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetLinearDamping() + LUAX_IMPL_METHOD(Body, _GetLinearDamping) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetGravityScale() + LUAX_IMPL_METHOD(Body, _GetGravityScale) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetGravityScale() + LUAX_IMPL_METHOD(Body, _GetGravityScale) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + } +} diff --git a/source/modules/asura-box2d/Physics/binding/_world.cpp b/source/modules/asura-box2d/Physics/binding/_world.cpp new file mode 100644 index 0000000..0940959 --- /dev/null +++ b/source/modules/asura-box2d/Physics/binding/_world.cpp @@ -0,0 +1,21 @@ +#include "../World.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Physics + { + /* + LUAX_REGISTRY(World) + { + + } + + LUAX_POSTPROCESS(World) + { + + } +*/ + } +} diff --git a/source/modules/asura-box2d/physics/binding/_body.cpp b/source/modules/asura-box2d/physics/binding/_body.cpp index 0dbd292..0c9e3e8 100644 --- a/source/modules/asura-box2d/physics/binding/_body.cpp +++ b/source/modules/asura-box2d/physics/binding/_body.cpp @@ -1,4 +1,4 @@ -#include "../body.h" +#include "../Body.h" using namespace std; diff --git a/source/modules/asura-box2d/physics/binding/_world.cpp b/source/modules/asura-box2d/physics/binding/_world.cpp index 1ebcbd1..0940959 100644 --- a/source/modules/asura-box2d/physics/binding/_world.cpp +++ b/source/modules/asura-box2d/physics/binding/_world.cpp @@ -1,4 +1,4 @@ -#include "../world.h" +#include "../World.h" using namespace std; diff --git a/source/modules/asura-box2d/physics/body.h b/source/modules/asura-box2d/physics/body.h index 3a4aa5f..e5af76a 100644 --- a/source/modules/asura-box2d/physics/body.h +++ b/source/modules/asura-box2d/physics/body.h @@ -3,7 +3,7 @@ #include <Box2D/Box2D.h> -#include <asura-utils/scripting/portable.hpp> +#include <asura-utils/Scripting/Portable.hpp> namespace AsuraEngine { diff --git a/source/modules/asura-box2d/physics/chain_shape.h b/source/modules/asura-box2d/physics/chain_shape.h deleted file mode 100644 index dd03ddf..0000000 --- a/source/modules/asura-box2d/physics/chain_shape.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef __ASURA_CHAIN_SHAPE_H__ -#define __ASURA_CHAIN_SHAPE_H__ - -// 3rd-party -#include <Box2D/Collision/Shapes/b2ChainShape.h> - -// asura modules -#include <asura-utils/scripting/portable.hpp> - -namespace AsuraEngine -{ - namespace Physics - { - - class ChainShape - : AEScripting::Portable<ChainShape> - { - public: - - ChainShape(); - ~ChainShape(); - - private: - - b2ChainShape* mShape; - - }; - - } -} - -#endif
\ No newline at end of file diff --git a/source/modules/asura-box2d/physics/debug_draw.h b/source/modules/asura-box2d/physics/debug_draw.h deleted file mode 100644 index cff682b..0000000 --- a/source/modules/asura-box2d/physics/debug_draw.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __ASURA_BOX2D_DEBUG_DRAW_H__ -#define __ASURA_BOX2D_DEBUG_DRAW_H__ - -namespace AsuraEngine -{ - -} - -#endif
\ No newline at end of file diff --git a/source/modules/asura-box2d/physics/world.h b/source/modules/asura-box2d/physics/world.h index 0aac0c8..b6d00ca 100644 --- a/source/modules/asura-box2d/physics/world.h +++ b/source/modules/asura-box2d/physics/world.h @@ -1,7 +1,7 @@ #ifndef __ASURA_BOX2D_WORLD_H__ #define __ASURA_BOX2D_WORLD_H__ -#include <asura-utils/scripting/portable.hpp> +#include <asura-utils/Scripting/Portable.hpp> namespace AsuraEngine { diff --git a/source/modules/asura-core/Application.cpp b/source/modules/asura-core/Application.cpp new file mode 100644 index 0000000..2f20e45 --- /dev/null +++ b/source/modules/asura-core/Application.cpp @@ -0,0 +1,23 @@ +#include "Application.h" + +using namespace Luax; + +namespace AsuraEngine +{ + +Application::Application() +{ + +} + +Application::~Application() +{ + +} + +bool Application::InitSubModules(uint flag) +{ + return false; +} + +}
\ No newline at end of file diff --git a/source/modules/asura-core/Application.h b/source/modules/asura-core/Application.h new file mode 100644 index 0000000..ea5faa7 --- /dev/null +++ b/source/modules/asura-core/Application.h @@ -0,0 +1,81 @@ +#ifndef _ASURA_ENGINE_APPLICATION_H_ +#define _ASURA_ENGINE_APPLICATION_H_ + +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Module.h> +#include <asura-utils/Classes.h> +#include <queue> + +#include "CoreConfig.h" + +namespace_begin(AsuraEngine) + +/// ģ +enum SubModules +{ + ASURA_MODULE_NONE = 0X00000000U, + + ASURA_MODULE_GRAPHICS = 1 << 1, + ASURA_MODULE_AUDIO = 1 << 2, + ASURA_MODULE_FONT = 1 << 3, + ASURA_MODULE_INPUT = 1 << 4, + ASURA_MODULE_MATH = 1 << 5, + ASURA_MODULE_PHYSICS = 1 << 6, + ASURA_MODULE_TIME = 1 << 7, + ASURA_MODULE_WINDOW = 1 << 8, + + ASURA_MODULE_ALL = 0XFFFFFFFFU +}; + +/// +/// ѭ +/// +class Application +{ +public: + + Application(); + + virtual ~Application(); + + /// + /// ʼǰϵͳ + /// + bool InitSubModules(uint flag = ASURA_MODULE_ALL); + + /// + /// + /// + virtual void Run(int argc, char* args[]); + + /// + /// ˳runʱĴ + /// + virtual void OnExit(); + +protected: + + /// + /// 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ᰴն˳ʼ˳ʱִ˳ + /// + std::queue<Module*> m_Modules; + +}; + +namespace_end + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/core_config.h b/source/modules/asura-core/CoreConfig.h index 8a0e8c7..2dd0b03 100644 --- a/source/modules/asura-core/core_config.h +++ b/source/modules/asura-core/CoreConfig.h @@ -1,5 +1,5 @@ -#ifndef __ASURA_CORE_CONFIG_H__ -#define __ASURA_CORE_CONFIG_H__ +#ifndef _ASURA_CORE_CONFIG_H_ +#define _ASURA_CORE_CONFIG_H_ #define ASURA_WINDOW_SDL 1 diff --git a/source/modules/asura-core/core_module.cpp b/source/modules/asura-core/CoreModule.cpp index e91dd8f..93f8ca0 100644 --- a/source/modules/asura-core/core_module.cpp +++ b/source/modules/asura-core/CoreModule.cpp @@ -1,4 +1,4 @@ -#include "core_module.h" +#include "CoreModule.h" using namespace AEThreading; using namespace AEGraphics; @@ -13,7 +13,7 @@ namespace AsuraEngine LUAX_REGISTER_FACTORY(state, AEGraphics::Image); // Wnd LUAX_REGISTER_SINGLETON(state, AEWindow::Window); - // Threading + // Threads //LUAX_REGISTER_FACTORY(state, ThreadEx); } diff --git a/source/modules/asura-core/CoreModule.h b/source/modules/asura-core/CoreModule.h new file mode 100644 index 0000000..1781885 --- /dev/null +++ b/source/modules/asura-core/CoreModule.h @@ -0,0 +1,26 @@ +#ifndef _ASURA_CORE_MODULE_H_ +#define _ASURA_CORE_MODULE_H_ + +#include <asura-utils/Module.h> +#include <asura-utils/Classes.h> + +#include "graphics/image.h" +#include "graphics/texture.h" +#include "window/window.h" +#include "Threads/ThreadEx.h" + +namespace_begin(AsuraEngine) + +class CoreModule : public Module +{ +public: + + void Initialize(Luax::LuaxState& state) override; + + void Finalize(Luax::LuaxState& state) override; + +}; + +namespace_end + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/input/input_manager.cpp b/source/modules/asura-core/Font/Glyph.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-core/input/input_manager.cpp +++ b/source/modules/asura-core/Font/Glyph.cpp diff --git a/source/modules/asura-core/input/joystick_state.h b/source/modules/asura-core/Font/Glyph.h index e69de29..e69de29 100644 --- a/source/modules/asura-core/input/joystick_state.h +++ b/source/modules/asura-core/Font/Glyph.h diff --git a/source/modules/asura-core/Font/String.cpp b/source/modules/asura-core/Font/String.cpp new file mode 100644 index 0000000..1731338 --- /dev/null +++ b/source/modules/asura-core/Font/String.cpp @@ -0,0 +1,376 @@ +//#include "String.hpp" +//#include "Utf.hpp" +// +//namespace AsuraEngine +//{ +// namespace Text +// { +// +// +// //////////////////////////////////////////////////////////// +// const std::size_t String::InvalidPos = std::basic_string<uint32>::npos; +// +// +// //////////////////////////////////////////////////////////// +// String::String() +// { +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(char ansiChar, const std::locale& locale) +// { +// m_String += Utf32::DecodeAnsi(ansiChar, locale); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(wchar_t wideChar) +// { +// m_String += Utf32::DecodeWide(wideChar); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(uint32 utf32Char) +// { +// m_String += utf32Char; +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const char* ansiString, const std::locale& locale) +// { +// if (ansiString) +// { +// std::size_t length = strlen(ansiString); +// if (length > 0) +// { +// m_String.reserve(length + 1); +// Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(m_String), locale); +// } +// } +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const std::string& ansiString, const std::locale& locale) +// { +// m_String.reserve(ansiString.length() + 1); +// Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(m_String), locale); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const wchar_t* wideString) +// { +// if (wideString) +// { +// std::size_t length = std::wcslen(wideString); +// if (length > 0) +// { +// m_String.reserve(length + 1); +// Utf32::FromWide(wideString, wideString + length, std::back_inserter(m_String)); +// } +// } +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const std::wstring& wideString) +// { +// m_String.reserve(wideString.length() + 1); +// Utf32::FromWide(wideString.begin(), wideString.end(), std::back_inserter(m_String)); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const uint32* utf32String) +// { +// if (utf32String) +// m_String = utf32String; +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const std::basic_string<uint32>& utf32String) : +// m_String(utf32String) +// { +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const String& copy) : +// m_String(copy.mString) +// { +// } +// +// +// //////////////////////////////////////////////////////////// +// String::operator std::string() const +// { +// return ToAnsiString(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::operator std::wstring() const +// { +// return ToWideString(); +// } +// +// +// //////////////////////////////////////////////////////////// +// std::string String::ToAnsiString(const std::locale& locale) const +// { +// // Prepare the output string +// std::string output; +// output.reserve(m_String.length() + 1); +// +// // Convert +// Utf32::ToAnsi(m_String.begin(), m_String.end(), std::back_inserter(output), 0, locale); +// +// return output; +// } +// +// +// //////////////////////////////////////////////////////////// +// std::wstring String::ToWideString() const +// { +// // Prepare the output string +// std::wstring output; +// output.reserve(m_String.length() + 1); +// +// // Convert +// Utf32::ToWide(m_String.begin(), m_String.end(), std::back_inserter(output), 0); +// +// return output; +// } +// +// +// //////////////////////////////////////////////////////////// +// std::basic_string<uint8> String::ToUtf8() const +// { +// // Prepare the output string +// std::basic_string<uint8> output; +// output.reserve(m_String.length()); +// +// // Convert +// Utf32::ToUtf8(m_String.begin(), m_String.end(), std::back_inserter(output)); +// +// return output; +// } +// +// +// //////////////////////////////////////////////////////////// +// std::basic_string<uint16> String::ToUtf16() const +// { +// // Prepare the output string +// std::basic_string<uint16> output; +// output.reserve(m_String.length()); +// +// // Convert +// Utf32::ToUtf16(m_String.begin(), m_String.end(), std::back_inserter(output)); +// +// return output; +// } +// +// +// //////////////////////////////////////////////////////////// +// std::basic_string<uint32> String::ToUtf32() const +// { +// return m_String; +// } +// +// +// //////////////////////////////////////////////////////////// +// String& String::operator =(const String& right) +// { +// m_String = right.mString; +// return *this; +// } +// +// +// //////////////////////////////////////////////////////////// +// String& String::operator +=(const String& right) +// { +// m_String += right.mString; +// return *this; +// } +// +// +// //////////////////////////////////////////////////////////// +// uint32 String::operator [](std::size_t index) const +// { +// return m_String[index]; +// } +// +// +// //////////////////////////////////////////////////////////// +// uint32& String::operator [](std::size_t index) +// { +// return m_String[index]; +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Clear() +// { +// m_String.clear(); +// } +// +// +// //////////////////////////////////////////////////////////// +// std::size_t String::GetSize() const +// { +// return m_String.size(); +// } +// +// +// //////////////////////////////////////////////////////////// +// bool String::IsEmpty() const +// { +// return m_String.empty(); +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Erase(std::size_t position, std::size_t count) +// { +// m_String.erase(position, count); +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Insert(std::size_t position, const String& str) +// { +// m_String.insert(position, str.mString); +// } +// +// +// //////////////////////////////////////////////////////////// +// std::size_t String::Find(const String& str, std::size_t start) const +// { +// return m_String.find(str.mString, start); +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Replace(std::size_t position, std::size_t length, const String& replaceWith) +// { +// m_String.replace(position, length, replaceWith.mString); +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Replace(const String& searchFor, const String& replaceWith) +// { +// std::size_t step = replaceWith.GetSize(); +// std::size_t len = searchFor.GetSize(); +// std::size_t pos = Find(searchFor); +// +// // Replace each occurrence of search +// while (pos != InvalidPos) +// { +// Replace(pos, len, replaceWith); +// pos = Find(searchFor, pos + step); +// } +// } +// +// +// //////////////////////////////////////////////////////////// +// String String::Substring(std::size_t position, std::size_t length) const +// { +// return m_String.substr(position, length); +// } +// +// +// //////////////////////////////////////////////////////////// +// const uint32* String::GetData() const +// { +// return m_String.c_str(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::Iterator String::Begin() +// { +// return m_String.begin(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::ConstIterator String::Begin() const +// { +// return m_String.begin(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::Iterator String::End() +// { +// return m_String.end(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::ConstIterator String::End() const +// { +// return m_String.end(); +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator ==(const String& left, const String& right) +// { +// return left.mString == right.mString; +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator !=(const String& left, const String& right) +// { +// return !(left == right); +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator <(const String& left, const String& right) +// { +// return left.mString < right.mString; +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator >(const String& left, const String& right) +// { +// return right < left; +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator <=(const String& left, const String& right) +// { +// return !(right < left); +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator >=(const String& left, const String& right) +// { +// return !(left < right); +// } +// +// +// //////////////////////////////////////////////////////////// +// String operator +(const String& left, const String& right) +// { +// String string = left; +// string += right; +// +// return string; +// } +// +// +// } +//} diff --git a/source/modules/asura-core/Font/String.hpp b/source/modules/asura-core/Font/String.hpp new file mode 100644 index 0000000..13a8b2d --- /dev/null +++ b/source/modules/asura-core/Font/String.hpp @@ -0,0 +1,595 @@ +//#ifndef _ASURA_ENGINE_STRING_H_ +//#define _ASURA_ENGINE_STRING_H_ +// +//#include <asura-utils/type.h> +// +//#include <iterator> +//#include <locale> +//#include <string> +// +//namespace AsuraEngine +//{ +// namespace Text +// { +// +// +// //////////////////////////////////////////////////////////// +// /// \brief Utility string class that automatically handles +// /// conversions between types and encodings +// /// +// //////////////////////////////////////////////////////////// +// class String +// { +// public: +// +// //////////////////////////////////////////////////////////// +// // Types +// //////////////////////////////////////////////////////////// +// typedef std::basic_string<uint32>::iterator Iterator; ///< Iterator type +// typedef std::basic_string<uint32>::const_iterator ConstIterator; ///< Read-only iterator type +// +// //////////////////////////////////////////////////////////// +// // Static member data +// //////////////////////////////////////////////////////////// +// static const std::size_t InvalidPos; ///< Represents an invalid position in the string +// +// //////////////////////////////////////////////////////////// +// /// \brief Default constructor +// /// +// /// This constructor creates an empty string. +// /// +// //////////////////////////////////////////////////////////// +// String(); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from a single ANSI character and a locale +// /// +// /// The source character is converted to UTF-32 according +// /// to the given locale. +// /// +// /// \param ansiChar ANSI character to convert +// /// \param locale Locale to use for conversion +// /// +// //////////////////////////////////////////////////////////// +// String(char ansiChar, const std::locale& locale = std::locale()); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from single wide character +// /// +// /// \param wideChar Wide character to convert +// /// +// //////////////////////////////////////////////////////////// +// String(wchar_t wideChar); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from single UTF-32 character +// /// +// /// \param utf32Char UTF-32 character to convert +// /// +// //////////////////////////////////////////////////////////// +// String(uint utf32Char); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from a null-terminated C-style ANSI string and a locale +// /// +// /// The source string is converted to UTF-32 according +// /// to the given locale. +// /// +// /// \param ansiString ANSI string to convert +// /// \param locale Locale to use for conversion +// /// +// //////////////////////////////////////////////////////////// +// String(const char* ansiString, const std::locale& locale = std::locale()); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from an ANSI string and a locale +// /// +// /// The source string is converted to UTF-32 according +// /// to the given locale. +// /// +// /// \param ansiString ANSI string to convert +// /// \param locale Locale to use for conversion +// /// +// //////////////////////////////////////////////////////////// +// String(const std::string& ansiString, const std::locale& locale = std::locale()); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from null-terminated C-style wide string +// /// +// /// \param wideString Wide string to convert +// /// +// //////////////////////////////////////////////////////////// +// String(const wchar_t* wideString); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from a wide string +// /// +// /// \param wideString Wide string to convert +// /// +// //////////////////////////////////////////////////////////// +// String(const std::wstring& wideString); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from a null-terminated C-style UTF-32 string +// /// +// /// \param utf32String UTF-32 string to assign +// /// +// //////////////////////////////////////////////////////////// +// String(const uint* utf32String); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from an UTF-32 string +// /// +// /// \param utf32String UTF-32 string to assign +// /// +// //////////////////////////////////////////////////////////// +// String(const std::basic_string<uint>& utf32String); +// +// //////////////////////////////////////////////////////////// +// /// \brief Copy constructor +// /// +// /// \param copy Instance to copy +// /// +// //////////////////////////////////////////////////////////// +// String(const String& copy); +// +// //////////////////////////////////////////////////////////// +// /// \brief Create a new sf::String from a UTF-8 encoded string +// /// +// /// \param begin Forward iterator to the beginning of the UTF-8 sequence +// /// \param end Forward iterator to the end of the UTF-8 sequence +// /// +// /// \return A sf::String containing the source string +// /// +// /// \see fromUtf16, fromUtf32 +// /// +// //////////////////////////////////////////////////////////// +// template <typename T> +// static String FromUtf8(T begin, T end); +// +// //////////////////////////////////////////////////////////// +// /// \brief Create a new sf::String from a UTF-16 encoded string +// /// +// /// \param begin Forward iterator to the beginning of the UTF-16 sequence +// /// \param end Forward iterator to the end of the UTF-16 sequence +// /// +// /// \return A sf::String containing the source string +// /// +// /// \see fromUtf8, fromUtf32 +// /// +// //////////////////////////////////////////////////////////// +// template <typename T> +// static String FromUtf16(T begin, T end); +// +// //////////////////////////////////////////////////////////// +// /// \brief Create a new sf::String from a UTF-32 encoded string +// /// +// /// This function is provided for consistency, it is equivalent to +// /// using the constructors that takes a const sf::uint* or +// /// a std::basic_string<sf::uint>. +// /// +// /// \param begin Forward iterator to the beginning of the UTF-32 sequence +// /// \param end Forward iterator to the end of the UTF-32 sequence +// /// +// /// \return A sf::String containing the source string +// /// +// /// \see fromUtf8, fromUtf16 +// /// +// //////////////////////////////////////////////////////////// +// template <typename T> +// static String FromUtf32(T begin, T end); +// +// //////////////////////////////////////////////////////////// +// /// \brief Implicit conversion operator to std::string (ANSI string) +// /// +// /// The current global locale is used for conversion. If you +// /// want to explicitly specify a locale, see toAnsiString. +// /// Characters that do not fit in the target encoding are +// /// discarded from the returned string. +// /// This operator is defined for convenience, and is equivalent +// /// to calling toAnsiString(). +// /// +// /// \return Converted ANSI string +// /// +// /// \see toAnsiString, operator std::wstring +// /// +// //////////////////////////////////////////////////////////// +// operator std::string() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Implicit conversion operator to std::wstring (wide string) +// /// +// /// Characters that do not fit in the target encoding are +// /// discarded from the returned string. +// /// This operator is defined for convenience, and is equivalent +// /// to calling toWideString(). +// /// +// /// \return Converted wide string +// /// +// /// \see toWideString, operator std::string +// /// +// //////////////////////////////////////////////////////////// +// operator std::wstring() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to an ANSI string +// /// +// /// The UTF-32 string is converted to an ANSI string in +// /// the encoding defined by \a locale. +// /// Characters that do not fit in the target encoding are +// /// discarded from the returned string. +// /// +// /// \param locale Locale to use for conversion +// /// +// /// \return Converted ANSI string +// /// +// /// \see toWideString, operator std::string +// /// +// //////////////////////////////////////////////////////////// +// std::string ToAnsiString(const std::locale& locale = std::locale()) const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to a wide string +// /// +// /// Characters that do not fit in the target encoding are +// /// discarded from the returned string. +// /// +// /// \return Converted wide string +// /// +// /// \see toAnsiString, operator std::wstring +// /// +// //////////////////////////////////////////////////////////// +// std::wstring ToWideString() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to a UTF-8 string +// /// +// /// \return Converted UTF-8 string +// /// +// /// \see toUtf16, toUtf32 +// /// +// //////////////////////////////////////////////////////////// +// std::basic_string<uint8> ToUtf8() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to a UTF-16 string +// /// +// /// \return Converted UTF-16 string +// /// +// /// \see toUtf8, toUtf32 +// /// +// //////////////////////////////////////////////////////////// +// std::basic_string<uint16> ToUtf16() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to a UTF-32 string +// /// +// /// This function doesn't perform any conversion, since the +// /// string is already stored as UTF-32 internally. +// /// +// /// \return Converted UTF-32 string +// /// +// /// \see toUtf8, toUtf16 +// /// +// //////////////////////////////////////////////////////////// +// std::basic_string<uint> ToUtf32() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Overload of assignment operator +// /// +// /// \param right Instance to assign +// /// +// /// \return Reference to self +// /// +// //////////////////////////////////////////////////////////// +// String& operator =(const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \brief Overload of += operator to append an UTF-32 string +// /// +// /// \param right String to append +// /// +// /// \return Reference to self +// /// +// //////////////////////////////////////////////////////////// +// String& operator +=(const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \brief Overload of [] operator to access a character by its position +// /// +// /// This function provides read-only access to characters. +// /// Note: the behavior is undefined if \a index is out of range. +// /// +// /// \param index Index of the character to get +// /// +// /// \return Character at position \a index +// /// +// //////////////////////////////////////////////////////////// +// uint operator [](std::size_t index) const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Overload of [] operator to access a character by its position +// /// +// /// This function provides read and write access to characters. +// /// Note: the behavior is undefined if \a index is out of range. +// /// +// /// \param index Index of the character to get +// /// +// /// \return Reference to the character at position \a index +// /// +// //////////////////////////////////////////////////////////// +// uint& operator [](std::size_t index); +// +// //////////////////////////////////////////////////////////// +// /// \brief Clear the string +// /// +// /// This function removes all the characters from the string. +// /// +// /// \see isEmpty, erase +// /// +// //////////////////////////////////////////////////////////// +// void Clear(); +// +// //////////////////////////////////////////////////////////// +// /// \brief Get the size of the string +// /// +// /// \return Number of characters in the string +// /// +// /// \see isEmpty +// /// +// //////////////////////////////////////////////////////////// +// std::size_t GetSize() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Check whether the string is empty or not +// /// +// /// \return True if the string is empty (i.e. contains no character) +// /// +// /// \see clear, getSize +// /// +// //////////////////////////////////////////////////////////// +// bool IsEmpty() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Erase one or more characters from the string +// /// +// /// This function removes a sequence of \a count characters +// /// starting from \a position. +// /// +// /// \param position Position of the first character to erase +// /// \param count Number of characters to erase +// /// +// //////////////////////////////////////////////////////////// +// void Erase(std::size_t position, std::size_t count = 1); +// +// //////////////////////////////////////////////////////////// +// /// \brief Insert one or more characters into the string +// /// +// /// This function inserts the characters of \a str +// /// into the string, starting from \a position. +// /// +// /// \param position Position of insertion +// /// \param str Characters to insert +// /// +// //////////////////////////////////////////////////////////// +// void Insert(std::size_t position, const String& str); +// +// //////////////////////////////////////////////////////////// +// /// \brief Find a sequence of one or more characters in the string +// /// +// /// This function searches for the characters of \a str +// /// in the string, starting from \a start. +// /// +// /// \param str Characters to find +// /// \param start Where to begin searching +// /// +// /// \return Position of \a str in the string, or String::InvalidPos if not found +// /// +// //////////////////////////////////////////////////////////// +// std::size_t Find(const String& str, std::size_t start = 0) const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Replace a substring with another string +// /// +// /// This function replaces the substring that starts at index \a position +// /// and spans \a length characters with the string \a replaceWith. +// /// +// /// \param position Index of the first character to be replaced +// /// \param length Number of characters to replace. You can pass InvalidPos to +// /// replace all characters until the end of the string. +// /// \param replaceWith String that replaces the given substring. +// /// +// //////////////////////////////////////////////////////////// +// void Replace(std::size_t position, std::size_t length, const String& replaceWith); +// +// //////////////////////////////////////////////////////////// +// /// \brief Replace all occurrences of a substring with a replacement string +// /// +// /// This function replaces all occurrences of \a searchFor in this string +// /// with the string \a replaceWith. +// /// +// /// \param searchFor The value being searched for +// /// \param replaceWith The value that replaces found \a searchFor values +// /// +// //////////////////////////////////////////////////////////// +// void Replace(const String& searchFor, const String& replaceWith); +// +// //////////////////////////////////////////////////////////// +// /// \brief Return a part of the string +// /// +// /// This function returns the substring that starts at index \a position +// /// and spans \a length characters. +// /// +// /// \param position Index of the first character +// /// \param length Number of characters to include in the substring (if +// /// the string is shorter, as many characters as possible +// /// are included). \ref InvalidPos can be used to include all +// /// characters until the end of the string. +// /// +// /// \return String object containing a substring of this object +// /// +// //////////////////////////////////////////////////////////// +// String Substring(std::size_t position, std::size_t length = InvalidPos) const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Get a pointer to the C-style array of characters +// /// +// /// This functions provides a read-only access to a +// /// null-terminated C-style representation of the string. +// /// The returned pointer is temporary and is meant only for +// /// immediate use, thus it is not recommended to store it. +// /// +// /// \return Read-only pointer to the array of characters +// /// +// //////////////////////////////////////////////////////////// +// const uint* GetData() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Return an iterator to the beginning of the string +// /// +// /// \return Read-write iterator to the beginning of the string characters +// /// +// /// \see end +// /// +// //////////////////////////////////////////////////////////// +// Iterator Begin(); +// +// //////////////////////////////////////////////////////////// +// /// \brief Return an iterator to the beginning of the string +// /// +// /// \return Read-only iterator to the beginning of the string characters +// /// +// /// \see end +// /// +// //////////////////////////////////////////////////////////// +// ConstIterator Begin() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Return an iterator to the end of the string +// /// +// /// The end iterator refers to 1 position past the last character; +// /// thus it represents an invalid character and should never be +// /// accessed. +// /// +// /// \return Read-write iterator to the end of the string characters +// /// +// /// \see begin +// /// +// //////////////////////////////////////////////////////////// +// Iterator End(); +// +// //////////////////////////////////////////////////////////// +// /// \brief Return an iterator to the end of the string +// /// +// /// The end iterator refers to 1 position past the last character; +// /// thus it represents an invalid character and should never be +// /// accessed. +// /// +// /// \return Read-only iterator to the end of the string characters +// /// +// /// \see begin +// /// +// //////////////////////////////////////////////////////////// +// ConstIterator End() const; +// +// private: +// +// friend bool operator ==(const String& left, const String& right); +// friend bool operator <(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// // Member data +// //////////////////////////////////////////////////////////// +// std::basic_string<uint> m_String; ///< Internal string of UTF-32 characters +// }; +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of == operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if both strings are equal +// /// +// //////////////////////////////////////////////////////////// +// bool operator ==(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of != operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if both strings are different +// /// +// //////////////////////////////////////////////////////////// +// bool operator !=(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of < operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if \a left is lexicographically before \a right +// /// +// //////////////////////////////////////////////////////////// +// bool operator <(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of > operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if \a left is lexicographically after \a right +// /// +// //////////////////////////////////////////////////////////// +// bool operator >(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of <= operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if \a left is lexicographically before or equivalent to \a right +// /// +// //////////////////////////////////////////////////////////// +// bool operator <=(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of >= operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if \a left is lexicographically after or equivalent to \a right +// /// +// //////////////////////////////////////////////////////////// +// bool operator >=(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of binary + operator to concatenate two strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return Concatenated string +// /// +// //////////////////////////////////////////////////////////// +// String operator +(const String& left, const String& right); +// +// #include "String.inc" +// +// } +//} +// +//#endif
\ No newline at end of file diff --git a/source/modules/asura-core/font/string.inl b/source/modules/asura-core/Font/String.inc index ef18228..ef18228 100644 --- a/source/modules/asura-core/font/string.inl +++ b/source/modules/asura-core/Font/String.inc diff --git a/source/modules/asura-core/input/mouse_state.h b/source/modules/asura-core/Font/TTF.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-core/input/mouse_state.h +++ b/source/modules/asura-core/Font/TTF.cpp diff --git a/source/modules/asura-core/Font/TTF.h b/source/modules/asura-core/Font/TTF.h new file mode 100644 index 0000000..b83cf76 --- /dev/null +++ b/source/modules/asura-core/Font/TTF.h @@ -0,0 +1,17 @@ +#ifndef _ASURA_TTF_H_ +#define _ASURA_TTF_H_ + +namespace AsuraEngine +{ + namespace Text + { + + class TTF + { + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/Font/Utf.hpp b/source/modules/asura-core/Font/Utf.hpp new file mode 100644 index 0000000..59f62ed --- /dev/null +++ b/source/modules/asura-core/Font/Utf.hpp @@ -0,0 +1,720 @@ +#ifndef _ASURA_UTF_HPP_ +#define _ASURA_UTF_HPP_ + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <algorithm> +#include <locale> +#include <string> +#include <cstdlib> + +namespace AsuraEngine +{ + namespace Text + { + + template <unsigned int N> + class Utf; + + //////////////////////////////////////////////////////////// + /// \brief Specialization of the Utf template for UTF-8 + /// + //////////////////////////////////////////////////////////// + template <> + class Utf<8> + { + public: + + //////////////////////////////////////////////////////////// + /// \brief Decode a single UTF-8 character + /// + /// Decoding a character means finding its unique 32-bits + /// code (called the codepoint) in the Unicode standard. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Codepoint of the decoded UTF-8 character + /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-8 character + /// + /// Encoding a character means converting a unique 32-bits + /// code (called the codepoint) in the target encoding, UTF-8. + /// + /// \param input Codepoint to encode as UTF-8 + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to UTF-8 (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename Out> + static Out Encode(Uint32 input, Out output, Uint8 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Advance to the next UTF-8 character + /// + /// This function is necessary for multi-elements encodings, as + /// a single character may use more than 1 storage element. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static In Next(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Count the number of characters of a UTF-8 sequence + /// + /// This function is necessary for multi-elements encodings, as + /// a single character may use more than 1 storage element, thus the + /// total size can be different from (begin - end). + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static std::size_t Count(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Convert an ANSI characters range to UTF-8 + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert a wide characters range to UTF-8 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromWide(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-8 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromLatin1(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-8 characters range to ANSI characters + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-8 characters range to wide characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-8 characters range to latin-1 (ISO-5589-1) characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToLatin1(In begin, In end, Out output, char replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-8 characters range to UTF-8 + /// + /// This functions does nothing more than a direct copy; + /// it is defined only to provide the same interface as other + /// specializations of the sf::Utf<> template, and allow + /// generic code to be written on top of it. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf8(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-8 characters range to UTF-16 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf16(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-8 characters range to UTF-32 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf32(In begin, In end, Out output); + }; + + //////////////////////////////////////////////////////////// + /// \brief Specialization of the Utf template for UTF-16 + /// + //////////////////////////////////////////////////////////// + template <> + class Utf<16> + { + public: + + //////////////////////////////////////////////////////////// + /// \brief Decode a single UTF-16 character + /// + /// Decoding a character means finding its unique 32-bits + /// code (called the codepoint) in the Unicode standard. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Codepoint of the decoded UTF-16 character + /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-16 character + /// + /// Encoding a character means converting a unique 32-bits + /// code (called the codepoint) in the target encoding, UTF-16. + /// + /// \param input Codepoint to encode as UTF-16 + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to UTF-16 (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename Out> + static Out Encode(Uint32 input, Out output, Uint16 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Advance to the next UTF-16 character + /// + /// This function is necessary for multi-elements encodings, as + /// a single character may use more than 1 storage element. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static In Next(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Count the number of characters of a UTF-16 sequence + /// + /// This function is necessary for multi-elements encodings, as + /// a single character may use more than 1 storage element, thus the + /// total size can be different from (begin - end). + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static std::size_t Count(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Convert an ANSI characters range to UTF-16 + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert a wide characters range to UTF-16 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromWide(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-16 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromLatin1(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-16 characters range to ANSI characters + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-16 characters range to wide characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToLatin1(In begin, In end, Out output, char replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-16 characters range to UTF-8 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf8(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-16 characters range to UTF-16 + /// + /// This functions does nothing more than a direct copy; + /// it is defined only to provide the same interface as other + /// specializations of the sf::Utf<> template, and allow + /// generic code to be written on top of it. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf16(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-16 characters range to UTF-32 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf32(In begin, In end, Out output); + }; + + //////////////////////////////////////////////////////////// + /// \brief Specialization of the Utf template for UTF-32 + /// + //////////////////////////////////////////////////////////// + template <> + class Utf<32> + { + public: + + //////////////////////////////////////////////////////////// + /// \brief Decode a single UTF-32 character + /// + /// Decoding a character means finding its unique 32-bits + /// code (called the codepoint) in the Unicode standard. + /// For UTF-32, the character value is the same as the codepoint. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Codepoint of the decoded UTF-32 character + /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-32 character + /// + /// Encoding a character means converting a unique 32-bits + /// code (called the codepoint) in the target encoding, UTF-32. + /// For UTF-32, the codepoint is the same as the character value. + /// + /// \param input Codepoint to encode as UTF-32 + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to UTF-32 (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename Out> + static Out Encode(Uint32 input, Out output, Uint32 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Advance to the next UTF-32 character + /// + /// This function is trivial for UTF-32, which can store + /// every character in a single storage element. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static In Next(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Count the number of characters of a UTF-32 sequence + /// + /// This function is trivial for UTF-32, which can store + /// every character in a single storage element. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static std::size_t Count(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Convert an ANSI characters range to UTF-32 + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert a wide characters range to UTF-32 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromWide(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-32 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromLatin1(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-32 characters range to ANSI characters + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-32 characters range to wide characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToLatin1(In begin, In end, Out output, char replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-32 characters range to UTF-8 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf8(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-32 characters range to UTF-16 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf16(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-32 characters range to UTF-32 + /// + /// This functions does nothing more than a direct copy; + /// it is defined only to provide the same interface as other + /// specializations of the sf::Utf<> template, and allow + /// generic code to be written on top of it. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf32(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Decode a single ANSI character to UTF-32 + /// + /// This function does not exist in other specializations + /// of sf::Utf<>, it is defined for convenience (it is used by + /// several other conversion functions). + /// + /// \param input Input ANSI character + /// \param locale Locale to use for conversion + /// + /// \return Converted character + /// + //////////////////////////////////////////////////////////// + template <typename In> + static Uint32 DecodeAnsi(In input, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Decode a single wide character to UTF-32 + /// + /// This function does not exist in other specializations + /// of sf::Utf<>, it is defined for convenience (it is used by + /// several other conversion functions). + /// + /// \param input Input wide character + /// + /// \return Converted character + /// + //////////////////////////////////////////////////////////// + template <typename In> + static Uint32 DecodeWide(In input); + + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-32 character to ANSI + /// + /// This function does not exist in other specializations + /// of sf::Utf<>, it is defined for convenience (it is used by + /// several other conversion functions). + /// + /// \param codepoint Iterator pointing to the beginning of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement if the input character is not convertible to ANSI (use 0 to skip it) + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename Out> + static Out EncodeAnsi(Uint32 codepoint, Out output, char replacement = 0, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-32 character to wide + /// + /// This function does not exist in other specializations + /// of sf::Utf<>, it is defined for convenience (it is used by + /// several other conversion functions). + /// + /// \param codepoint Iterator pointing to the beginning of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement if the input character is not convertible to wide (use 0 to skip it) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename Out> + static Out EncodeWide(Uint32 codepoint, Out output, wchar_t replacement = 0); + }; + +#include "Utf.inc" + + // Make typedefs to get rid of the template syntax + typedef Utf<8> Utf8; + typedef Utf<16> Utf16; + typedef Utf<32> Utf32; + + } // namespace sf + +} + + +#endif // SFML_UTF_HPP diff --git a/source/modules/asura-core/font/utf.inl b/source/modules/asura-core/Font/Utf.inc index 69a523b..69a523b 100644 --- a/source/modules/asura-core/font/utf.inl +++ b/source/modules/asura-core/Font/Utf.inc diff --git a/source/modules/asura-core/Graphics/BlendMode.h b/source/modules/asura-core/Graphics/BlendMode.h new file mode 100644 index 0000000..7a31eed --- /dev/null +++ b/source/modules/asura-core/Graphics/BlendMode.h @@ -0,0 +1,17 @@ +#ifndef _ASURA_ENGINE_BLEND_MODE_H_ +#define _ASURA_ENGINE_BLEND_MODE_H_ + +#include <asura-utils/Classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +enum BlendMode +{ + +}; + +namespace_end +namespace_end + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Canvas.cpp b/source/modules/asura-core/Graphics/Canvas.cpp new file mode 100644 index 0000000..60c8f87 --- /dev/null +++ b/source/modules/asura-core/Graphics/Canvas.cpp @@ -0,0 +1,49 @@ +#include "Canvas.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +Canvas::Canvas() + : m_Width(0) + , m_Height(0) + , m_FBO(0) +{ + // Fix: ôСʼʱframebufferԴ + //glGenFramebuffers(1, &m_FBO); + //GLint current_fbo; + //glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); + //glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); + //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TexID, 0); + //glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); +} + +void Canvas::SetSize(uint w, uint h) +{ + if (m_FBO == 0) + { + glGenFramebuffers(1, &m_FBO); + if (m_FBO == 0) + throw Exception("OpenGL glGenFramebuffers cannot generate frame buffer object."); + // + if (m_TexID == 0) + { + glGenTextures(1, &m_TexID); + if (m_TexID == 0) + throw Exception("OpenGL glGenTextures cannot generate texture."); + } + GLint current_fbo; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TexID, 0); + glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); + } + GLint current_tex; + glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex); + glBindTexture(GL_TEXTURE_2D, m_TexID); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glBindTexture(GL_TEXTURE_2D, current_tex); +} + +namespace_end + +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Canvas.h b/source/modules/asura-core/Graphics/Canvas.h new file mode 100644 index 0000000..0ec55bc --- /dev/null +++ b/source/modules/asura-core/Graphics/Canvas.h @@ -0,0 +1,73 @@ +#ifndef _ASURA_ENGINE_CANVAS_H_ +#define _ASURA_ENGINE_CANVAS_H_ + +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Math/Rect.hpp> +#include <asura-utils/Math/Vector2.hpp> +#include <asura-utils/Exceptions/Exception.h> + +#include "GfxDevice.h" +#include "Texture.h" +#include "RenderTarget.h" +#include "RenderState.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + +/// +/// CanvasҲԳΪrender textureҲΪtextureȾ +/// +class Canvas ASURA_FINAL + : public Scripting::Portable<Canvas, RenderTarget> +{ +public: + + Canvas(); + + ~Canvas(); + + /// + /// render textureĴС + /// + void SetSize(uint w, uint h) ASURA_THROW(Exception); + + void Clear(const Color& col = Color::Black) override; +/* + void Clear(const Math::Recti& quad, const Color& col = Color::Black) override; +*/ + void Render(const RenderTarget* rt, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); + + void Render(const RenderTarget* rt, const Math::Rectf& quad, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); + + void Draw(const Drawable* texture, const RenderState& state); + + void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state); + +private: + + GLuint m_FBO; + + GLuint m_TexID; + + uint m_Width, m_Height; + +luaxport: + + LUAX_DECL_FACTORY(Canvas, RenderTarget); + + LUAX_DECL_METHOD(_SetSize); + LUAX_DECL_METHOD(_Bind); + LUAX_DECL_METHOD(_Unbind); + +}; + +/// +/// CanvasΪRenderTexture +/// +typedef Canvas RenderTexture; + +} // Graphics +} // AsuraEngine + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Color.cpp b/source/modules/asura-core/Graphics/Color.cpp new file mode 100644 index 0000000..5a66291 --- /dev/null +++ b/source/modules/asura-core/Graphics/Color.cpp @@ -0,0 +1,58 @@ +#include "Color.h" +#include "Color32.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +Color::Color() +{ + r = g = b = a = 0; +} + +Color::Color(const Color& c) +{ + r = c.r; + g = c.g; + b = c.b; + a = c.a; +} + +Color::Color(float r, float g, float b, float a) +{ + this->r = r; + this->g = g; + this->b = b; + this->a = a; +} + +Color::Color(const Color32& c) +{ + r = c.r / 255.f; + g = c.g / 255.f; + b = c.b / 255.f; + a = c.a / 255.f; +} + +Color::~Color() +{ +} + +void Color::Set(float r, float g, float b, float a) +{ + this->r = r; + this->g = g; + this->b = b; + this->a = a; +} + +//Color Color::operator *(const Color& c) +//{ +// r *= c.r; +// g *= c.g; +// b *= c.b; +// a *= c.a; + +//} + +namespace_end +namespace_end diff --git a/source/modules/asura-core/Graphics/Color.h b/source/modules/asura-core/Graphics/Color.h new file mode 100644 index 0000000..a16f17d --- /dev/null +++ b/source/modules/asura-core/Graphics/Color.h @@ -0,0 +1,75 @@ +#ifndef _ASURA_ENGINE_COLOR_H_ +#define _ASURA_ENGINE_COLOR_H_ + +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Classes.h> + +#include "../CoreConfig.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +class Color32; + +/// +/// 淶ɫColor32иIJԡ +/// +class Color ASURA_FINAL + : public Scripting::Portable<Color> +{ +public: + + static Color Black; + static Color White; + static Color Red; + static Color Green; + static Color Blue; + + Color(); + + Color(const Color& c); + + Color(float r, float g, float b, float a); + + Color(const Color32& c); + + ~Color(); + + Color operator *(const Color& c); + + void Set(float r, float g, float b, float a); + + GET_SET(float, Red, r); + GET_SET(float, Green, g); + GET_SET(float, Blue, b); + GET_SET(float, Alpha, a); + + float r, g, b, a; + +luaxport: + + LUAX_DECL_FACTORY(Color); + + LUAX_DECL_METHOD(_ToColor32); + LUAX_DECL_METHOD(_SetColor); + LUAX_DECL_METHOD(_GetColor); + LUAX_DECL_METHOD(_GetR); + LUAX_DECL_METHOD(_GetG); + LUAX_DECL_METHOD(_GetB); + LUAX_DECL_METHOD(_GetA); + + // Ԫ + LUAX_DECL_METHOD(___eq); // __eq + LUAX_DECL_METHOD(___add); // __add + LUAX_DECL_METHOD(___sub); // __sub + LUAX_DECL_METHOD(___mul); // __mul + LUAX_DECL_METHOD(___div); // __div + +}; + +namespace_end +namespace_end + +namespace AEGraphics = AsuraEngine::Graphics; + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Color32.cpp b/source/modules/asura-core/Graphics/Color32.cpp new file mode 100644 index 0000000..f1f0b74 --- /dev/null +++ b/source/modules/asura-core/Graphics/Color32.cpp @@ -0,0 +1,53 @@ +#include "Color.h" +#include "Color32.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +#if ASURA_LITTLE_ENDIAN +// СˣֽڵAlphaڸߵַ +const uint32 Color32::RMASK = 0x000000ff; +const uint32 Color32::GMASK = 0x0000ff00; +const uint32 Color32::BMASK = 0x00ff0000; +const uint32 Color32::AMASK = 0xff000000; +#endif + +Color32::Color32() +{ + r = g = b = a = 0; +} + +Color32::Color32(const Color32& c) +{ + r = c.r; + g = c.g; + b = c.b; + a = c.a; +} + +Color32::Color32(const Color& c) +{ + r = 255.f * c.r; + g = 255.f * c.g; + b = 255.f * c.b; + a = 255.f * c.a; +} + +Color32::Color32(byte r, byte g, byte b, byte a) +{ + this->r = r; + this->g = g; + this->b = b; + this->a = a; +} + +void Color32::Set(const Color32& c32) +{ + r = c32.r; + g = c32.g; + b = c32.b; + a = c32.a; +} + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Color32.h b/source/modules/asura-core/Graphics/Color32.h new file mode 100644 index 0000000..aa445fe --- /dev/null +++ b/source/modules/asura-core/Graphics/Color32.h @@ -0,0 +1,58 @@ +#ifndef _ASURA_ENGINE_COLOR32_H__ +#define _ASURA_ENGINE_COLOR32_H__ + +#include <asura-utils/Classes.h> +#include <asura-utils/Scripting/Portable.hpp> + +#include "../CoreConfig.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +class Color; + +/// +/// 32bitsɫ +/// +class Color32 ASURA_FINAL + : public Scripting::Portable<Color32> +{ +public: + + static const uint32 RMASK; + static const uint32 GMASK; + static const uint32 BMASK; + static const uint32 AMASK; + + Color32(); + + ~Color32(); + + Color32(const Color32& c); + + Color32(const Color& c); + + Color32(byte r, byte g, byte b, byte a); + + void Set(const Color32& c32); + + byte r, g, b, a; + +luaxport: + + LUAX_DECL_FACTORY(Color32); + + LUAX_DECL_METHOD(_ToColor); + LUAX_DECL_METHOD(_SetColor); + LUAX_DECL_METHOD(_GetColor); + LUAX_DECL_METHOD(_GetRed); + LUAX_DECL_METHOD(_GetGreen); + LUAX_DECL_METHOD(_GetBlue); + LUAX_DECL_METHOD(_GetAlpha); + +}; + +namespace_end +namespace_end + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/mesh/mesh2d_data.cpp b/source/modules/asura-core/Graphics/ColorPalette.h index e69de29..e69de29 100644 --- a/source/modules/asura-core/mesh/mesh2d_data.cpp +++ b/source/modules/asura-core/Graphics/ColorPalette.h diff --git a/source/modules/asura-core/Graphics/DrawInfo.cpp b/source/modules/asura-core/Graphics/DrawInfo.cpp new file mode 100644 index 0000000..c7a6912 --- /dev/null +++ b/source/modules/asura-core/Graphics/DrawInfo.cpp @@ -0,0 +1,10 @@ +#include "DrawInfo.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + + +namespace_end +namespace_end diff --git a/source/modules/asura-core/Graphics/DrawInfo.h b/source/modules/asura-core/Graphics/DrawInfo.h new file mode 100644 index 0000000..f0e375b --- /dev/null +++ b/source/modules/asura-core/Graphics/DrawInfo.h @@ -0,0 +1,18 @@ +#ifndef _ASURA_ENGINE_DRAWINFO_H_ +#define _ASURA_ENGINE_DRAWINFO_H_ + +#include <asura-utils/Classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +struct DrawInfo +{ + +}; + + +namespace_end +namespace_end + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/gpu_buffer.cpp b/source/modules/asura-core/Graphics/GPUBuffer.cpp index 4271b70..f28b914 100644 --- a/source/modules/asura-core/graphics/gpu_buffer.cpp +++ b/source/modules/asura-core/Graphics/GPUBuffer.cpp @@ -1,4 +1,4 @@ -#include "gpu_buffer.h" +#include "GPUBuffer.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/graphics/gpu_buffer.h b/source/modules/asura-core/Graphics/GPUBuffer.h index 3153904..bb40055 100644 --- a/source/modules/asura-core/graphics/gpu_buffer.h +++ b/source/modules/asura-core/Graphics/GPUBuffer.h @@ -1,11 +1,11 @@ -#ifndef __ASURA_GPU_BUFFER_H__ -#define __ASURA_GPU_BUFFER_H__ +#ifndef _ASURA_GPU_BUFFER_H_ +#define _ASURA_GPU_BUFFER_H_ -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/exceptions/exception.h> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Exceptions/Exception.h> #include <asura-utils/type.h> -#include "gfx_device.h" +#include "GfxDevice.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/graphics/gfx_device.cpp b/source/modules/asura-core/Graphics/GfxDevice.cpp index 2751a9d..ef324e3 100644 --- a/source/modules/asura-core/graphics/gfx_device.cpp +++ b/source/modules/asura-core/Graphics/GfxDevice.cpp @@ -1,11 +1,11 @@ #include <asura-utils/type.h> -#include "../core_config.h" +#include "../CoreConfig.h" -#include "gfx_device.h" -#include "shader.h" -#include "matrix_stack.h" -#include "color.h" +#include "GfxDevice.h" +#include "Shader.h" +#include "MatrixStack.h" +#include "Color.h" using namespace AEMath; diff --git a/source/modules/asura-core/graphics/gfx_device.h b/source/modules/asura-core/Graphics/GfxDevice.h index fa22dd4..1f50b57 100644 --- a/source/modules/asura-core/graphics/gfx_device.h +++ b/source/modules/asura-core/Graphics/GfxDevice.h @@ -1,17 +1,17 @@ -#ifndef __ASURA_ENGINE_GFX_DEVICE_H__ -#define __ASURA_ENGINE_GFX_DEVICE_H__ +#ifndef _ASURA_ENGINE_GFX_DEVICE_H_ +#define _ASURA_ENGINE_GFX_DEVICE_H_ #include <stack> #include <glad/glad.h> -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/math/rect.hpp> -#include <asura-utils/math/matrix44.h> -#include <asura-utils/math/vector4.h> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Math/Rect.hpp> +#include <asura-utils/Math/matrix44.h> +#include <asura-utils/Math/vector4.h> -#include "color.h" -#include "matrix_stack.h" +#include "Color.h" +#include "MatrixStack.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) @@ -42,47 +42,47 @@ 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); + 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(); AEMath::Matrix44& GetMatrix(MatrixMode mode); AEMath::Matrix44 GetMVPMatrix(); - void SetDrawColor(float r, float g, float b, float a); - Color& GetDrawColor(); + void SetDrawColor(float r, float g, float b, float a); + Color& GetDrawColor(); - void SetActiveCanvas(Canvas* = NULL); - Canvas* GetActiveCanvas() const; + void SetActiveCanvas(Canvas* = NULL); + Canvas* GetActiveCanvas() const; - void SetActiveShader(Shader* = NULL); - Shader* GetActiveShader() const; + void SetActiveShader(Shader* = NULL); + Shader* GetActiveShader() const; - void DrawArrays(GLenum mode, GLint first, GLsizei count); + void DrawArrays(GLenum mode, GLint first, GLsizei count); - void WipeError(); - bool HasError(); - GLenum GetError(); + void WipeError(); + bool HasError(); + GLenum GetError(); private: diff --git a/source/modules/asura-core/Graphics/Image.cpp b/source/modules/asura-core/Graphics/Image.cpp new file mode 100644 index 0000000..d2b2ec9 --- /dev/null +++ b/source/modules/asura-core/Graphics/Image.cpp @@ -0,0 +1,103 @@ +#include <asura-utils/Exceptions/Exception.h> + +#include "../CoreConfig.h" + +#include "Shader.h" +#include "Image.h" +#include "GfxDevice.h" + +using namespace AEIO; +using namespace AEImage; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +Image::Image() + : m_Width(0) + , m_Height(0) +{ +} + +Image::~Image() +{ +} + +bool Image::Load(ImageData* imgData) +{ + if (!imgData) return false; + + if (m_TexID == 0) + { + glGenTextures(1, &m_TexID); + if (m_TexID == 0) + throw Exception("OpenGL glGenTextures failed."); + } + + glBindTexture(GL_TEXTURE_2D, m_TexID); + imgData->Lock(); + int width = imgData->width; + int height = imgData->height; + TextureFormat tf = ConvertColorFormat(imgData->format); + glTexImage2D( + GL_TEXTURE_2D + , 0 + , tf.internalformat + , width, height + , 0 + , tf.externalformat + , tf.type + , imgData->pixels + ); + + m_Width = imgData->width; + m_Height = imgData->height; + imgData->Unlock(); + GLenum err = glGetError(); + if (err != GL_NO_ERROR) + throw Exception("OpenGL glTexImage2D cause error, error code=%d", err); + glBindTexture(GL_TEXTURE_2D, 0); + + return true; +} + +bool Image::Load(ImageData* imgData, const AEMath::Vector2i& pos) +{ + if (!imgData) return false; + + glBindTexture(GL_TEXTURE_2D, m_TexID); + imgData->Lock(); + int width = imgData->width; + int height = imgData->height; + TextureFormat tf = ConvertColorFormat(imgData->format); + glTexSubImage2D( + GL_TEXTURE_2D + , 0 + , pos.x + , pos.y + , imgData->width + , imgData->height + , tf.externalformat + , tf.type + , imgData->pixels + ); + imgData->Unlock(); + GLenum err = glGetError(); + if (err != GL_NO_ERROR) + throw Exception("OpenGL glTexSubImage2D cause error, error code=%d", err); + glBindTexture(GL_TEXTURE_2D, 0); + + return true; +} + +uint32 Image::GetWidth() +{ + return m_Width; +} + +uint32 Image::GetHeight() +{ + return m_Height; +} + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Image.h b/source/modules/asura-core/Graphics/Image.h new file mode 100644 index 0000000..5cbfe23 --- /dev/null +++ b/source/modules/asura-core/Graphics/Image.h @@ -0,0 +1,63 @@ +#ifndef _ASURA_ENGINE_IMAGE_H_ +#define _ASURA_ENGINE_IMAGE_H_ + +// asura modules +#include <asura-utils/Math/Rect.hpp> +#include <asura-utils/Math/Vector2.hpp> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/IO/Renewable.h> +#include <asura-utils/Stringmap.hpp> +#include <asura-utils/Manager.hpp> + +// module +#include "../Image/ImageData.h" + +// folder +#include "Color.h" +#include "Color32.h" +#include "RenderState.h" +#include "GPUBuffer.h" +#include "Texture.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +class Image ASURA_FINAL : public AEScripting::Portable<Image, Texture> +{ +public: + + Image(); + ~Image(); + + bool Load(AEImage::ImageData* decodeData); + bool Load(AEImage::ImageData* decodeData, const AEMath::Vector2i& pos); + + uint GetWidth(); + uint GetHeight(); + + GPUBuffer* GenGPUBuffer(); + +private: + + uint32 m_Width, m_Height; + +luaxport: + + LUAX_DECL_FACTORY(Image, Texture); + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Load); + LUAX_DECL_METHOD(_GetWidth); + LUAX_DECL_METHOD(_GetHeight); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_GetPixel); + LUAX_DECL_METHOD(_Render); + +}; + +namespace_end +namespace_end + +namespace AEGraphics = AsuraEngine::Graphics; + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/index_buffer.cpp b/source/modules/asura-core/Graphics/IndexBuffer.cpp index 9d7416f..bb3eea7 100644 --- a/source/modules/asura-core/graphics/index_buffer.cpp +++ b/source/modules/asura-core/Graphics/IndexBuffer.cpp @@ -1,4 +1,4 @@ -#include "index_buffer.h" +#include "IndexBuffer.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/graphics/index_buffer.h b/source/modules/asura-core/Graphics/IndexBuffer.h index 538b43b..73a6f9b 100644 --- a/source/modules/asura-core/graphics/index_buffer.h +++ b/source/modules/asura-core/Graphics/IndexBuffer.h @@ -1,9 +1,9 @@ -#ifndef __ASURA_INDEX_BUFFER_H__ -#define __ASURA_INDEX_BUFFER_H__ +#ifndef _ASURA_INDEX_BUFFER_H_ +#define _ASURA_INDEX_BUFFER_H_ -#include <asura-utils/scripting/portable.hpp> +#include <asura-utils/Scripting/Portable.hpp> -#include "gpu_buffer.h" +#include "GPUBuffer.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/graphics/matrix_stack.cpp b/source/modules/asura-core/Graphics/MatrixStack.cpp index eaa686f..987d29c 100644 --- a/source/modules/asura-core/graphics/matrix_stack.cpp +++ b/source/modules/asura-core/Graphics/MatrixStack.cpp @@ -1,4 +1,4 @@ -#include "matrix_stack.h" +#include "MatrixStack.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/graphics/matrix_stack.h b/source/modules/asura-core/Graphics/MatrixStack.h index ad32bb4..867011e 100644 --- a/source/modules/asura-core/graphics/matrix_stack.h +++ b/source/modules/asura-core/Graphics/MatrixStack.h @@ -1,9 +1,9 @@ -#ifndef __ASURA_MATRIX_STACK_H__ -#define __ASURA_MATRIX_STACK_H__ +#ifndef _ASURA_MATRIX_STACK_H_ +#define _ASURA_MATRIX_STACK_H_ -#include <asura-utils/type.h> -#include <asura-utils/math/matrix44.h> -#include <asura-utils/classes.h> +#include <asura-utils/Type.h> +#include <asura-utils/Math/Matrix44.h> +#include <asura-utils/Classes.h> namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/mesh/mesh2d_handler.cpp b/source/modules/asura-core/Graphics/Mesh2D.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-core/mesh/mesh2d_handler.cpp +++ b/source/modules/asura-core/Graphics/Mesh2D.cpp diff --git a/source/modules/asura-core/Graphics/Mesh2D.h b/source/modules/asura-core/Graphics/Mesh2D.h new file mode 100644 index 0000000..1546765 --- /dev/null +++ b/source/modules/asura-core/Graphics/Mesh2D.h @@ -0,0 +1,52 @@ +#ifndef _ASURA_ENGINE_MESH2D_H__ +#define _ASURA_ENGINE_MESH2D_H__ + +// cpp +#include <vector> + +// asura modules +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Math/Vector2.hpp> + +// module +#include "../Mesh/Mesh2dData.h" + +// folder +#include "Color.h" +#include "VertexBuffer.h" +#include "IndexBuffer.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// 2D meshһЩ㶯 +/// https://en.wikipedia.org/wiki/Polygon_mesh +/// +class Mesh2D ASURA_FINAL + : public Scripting::Portable<Mesh2D> +{ +public: + + Mesh2D(); + ~Mesh2D(); + + bool Load(AEMesh::Mesh2DData* data); + +private: + + VertexBuffer* m_VBO; ///< vertex buffer + IndexBuffer* m_IBO; ///< index buffer + +luaxport: + + LUAX_DECL_FACTORY(Mesh2D); + + LUAX_DECL_METHOD(_SetVertex); + +}; + +namespace_end +namespace_end + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/mesh/obj_handler.cpp b/source/modules/asura-core/Graphics/Quad.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-core/mesh/obj_handler.cpp +++ b/source/modules/asura-core/Graphics/Quad.cpp diff --git a/source/modules/asura-core/Graphics/Quad.h b/source/modules/asura-core/Graphics/Quad.h new file mode 100644 index 0000000..b7dd3d9 --- /dev/null +++ b/source/modules/asura-core/Graphics/Quad.h @@ -0,0 +1 @@ +// Quadrectڣrectǵıƫᣬquadһ diff --git a/source/modules/asura-core/graphics/render_state.h b/source/modules/asura-core/Graphics/RenderState.h index 9f138c0..5dcf12d 100644 --- a/source/modules/asura-core/graphics/render_state.h +++ b/source/modules/asura-core/Graphics/RenderState.h @@ -1,10 +1,10 @@ -#ifndef __ASURA_ENGINE_RENDER_STATE_H__ -#define __ASURA_ENGINE_RENDER_STATE_H__ +#ifndef _ASURA_ENGINE_RENDER_STATE_H_ +#define _ASURA_ENGINE_RENDER_STATE_H_ -#include <asura-utils/math/vector2.hpp> -#include <asura-utils/math/transform.h> +#include <asura-utils/Math/Vector2.hpp> +#include <asura-utils/Math/Transform.h> -#include "blend_mode.h" +#include "BlendMode.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/mesh/obj_handler.h b/source/modules/asura-core/Graphics/RenderTarget.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-core/mesh/obj_handler.h +++ b/source/modules/asura-core/Graphics/RenderTarget.cpp diff --git a/source/modules/asura-core/graphics/render_target.h b/source/modules/asura-core/Graphics/RenderTarget.h index a52e7b0..bcd7276 100644 --- a/source/modules/asura-core/graphics/render_target.h +++ b/source/modules/asura-core/Graphics/RenderTarget.h @@ -1,12 +1,12 @@ -#ifndef __ASURA_ENGINE_RENDERTARGET_H__ -#define __ASURA_ENGINE_RENDERTARGET_H__ +#ifndef _ASURA_ENGINE_RENDERTARGET_H_ +#define _ASURA_ENGINE_RENDERTARGET_H_ -#include <asura-utils/math/vector2.hpp> -#include <asura-utils/math/rect.hpp> -#include <asura-utils/scripting/portable.hpp> +#include <asura-utils/Math/Vector2.hpp> +#include <asura-utils/Math/Rect.hpp> +#include <asura-utils/Scripting/Portable.hpp> -#include "texture.h" -#include "color.h" +#include "Texture.h" +#include "Color.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/Graphics/Shader.cpp b/source/modules/asura-core/Graphics/Shader.cpp new file mode 100644 index 0000000..30e0161 --- /dev/null +++ b/source/modules/asura-core/Graphics/Shader.cpp @@ -0,0 +1,282 @@ +#include <asura-utils/Exceptions/Exception.h> + +#include "GfxDevice.h" +#include "Shader.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +// texture unit +static uint8 texUnit = 0; + +Shader::Shader() +{ +} + +Shader::~Shader() +{ + if(m_VertShader) glDeleteShader(m_VertShader); + if(m_FragShader) glDeleteShader(m_FragShader); + if(m_Program) glDeleteProgram(m_Program); +} + +void Shader::SetActive(Shader* shader) +{ + g_Device.SetActiveShader(shader); +} + +Shader* Shader::GetActive() +{ + return g_Device.GetActiveShader(); +} + +bool Shader::Load(const string& vert, const string& frag) +{ + string warnning = ""; + + if (!m_Program) + { + m_Program = glCreateProgram(); + if (!m_Program) + throw Exception("Cannot create OpenGL shader program."); + } + + if (!CompileVertexShader(vert, warnning)) + { + throw Exception("Compile vertex shader failed:%s", warnning); + } + + if (!CompileFragementShader(frag, warnning)) + { + throw Exception("Compile fragment shader failed:%s", warnning); + } + + glAttachShader(m_Program, m_VertShader); + glAttachShader(m_Program, m_FragShader); + + glLinkProgram(m_Program); + GLint success; + glGetProgramiv(m_Program, GL_LINK_STATUS, &success); + if (success == GL_FALSE) + { + warnning = GetProgramWarnings(); + throw Exception("Link shader program failed:\n%s", warnning.c_str()); + } + + return true; +} + +bool Shader::CompileVertexShader(const string& vert, string& outError) +{ + if (!m_VertShader) + { + m_VertShader = glCreateShader(GL_VERTEX_SHADER); + if (!m_VertShader) + { + outError = "Cannot create OpenGL Vertex shader."; + return false; + } + } + + const GLchar* source = vert.c_str(); + GLint success; + + glShaderSource(m_VertShader, 1, &source, NULL); + glCompileShader(m_VertShader); + glGetShaderiv(m_VertShader, GL_COMPILE_STATUS, &success); + if (success == GL_FALSE) + { + outError = GetShaderWarnings(m_VertShader); + return false; + } + + return true; +} + +bool Shader::CompileFragementShader(const string& frag, string& outError) +{ + if (!m_FragShader) + { + m_FragShader = glCreateShader(GL_FRAGMENT_SHADER); + if (!m_FragShader) + { + outError = "Cannot create OpenGL fragment shader."; + return false; + } + } + + const GLchar* source = frag.c_str(); + GLint success; + + source = frag.c_str(); + glShaderSource(m_FragShader, 1, &source, NULL); + glCompileShader(m_FragShader); + glGetShaderiv(m_FragShader, GL_COMPILE_STATUS, &success); + if (success == GL_FALSE) + { + outError = GetShaderWarnings(m_FragShader); + return false; + } + + return true; +} + +void Shader::OnEnable() +{ + texUnit = 0; +} + +void Shader::OnDisable() +{ + texUnit = 0; +} + +void Shader::OnUsed() +{ + texUnit = 0; +} + +uint Shader::GetUniformLocation(const std::string& uniform) +{ + GLint loc = glGetUniformLocation(m_Program, uniform.c_str()); + return loc; +} + +bool Shader::HasUniform(const std::string& uniform) +{ + GLint loc = glGetUniformLocation(m_Program, uniform.c_str()); + return loc != -1; +} + +GLuint Shader::GetGLProgram() +{ + return m_Program; +} + +void Shader::SetUniformFloat(uint loc, float value) +{ + if(g_Device.GetActiveShader() == this) + glUniform1f(loc, value); +} + +bool Shader::SetUniformTexture(uint loc, const Texture& texture) +{ + if (g_Device.GetActiveShader() != this) + return false; + + g_Device.WipeError(); + glActiveTexture(GL_TEXTURE0 + texUnit); + if (g_Device.HasError()) + return false; + GLint tex = texture.GetGLTexture(); + glBindTexture(GL_TEXTURE_2D, tex); + if (g_Device.HasError()) + return false; + glUniform1i(loc, texUnit); + if (g_Device.HasError()) + return false; + ++texUnit; +} + +void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2) +{ + if (g_Device.GetActiveShader() == this) + glUniform2f(loc, vec2.x, vec2.y); +} + +void Shader::SetUniformVector3(uint loc, const Math::Vector3f& vec3) +{ + if (g_Device.GetActiveShader() == this) + glUniform3f(loc, vec3.x, vec3.y, vec3.z); +} + +void Shader::SetUniformVector4(uint loc, const Math::Vector4f& vec4) +{ + if (g_Device.GetActiveShader() == this) + glUniform4f(loc, vec4.x, vec4.y, vec4.z, vec4.w); +} + +void Shader::SetUniformMatrix44(uint loc, const Math::Matrix44& mat) +{ + if (g_Device.GetActiveShader() == this) + glUniformMatrix4fv(loc, 1, GL_FALSE, mat.GetElements()); +} + +void Shader::SetUniformColor(uint loc, const Color& color) +{ + if (g_Device.GetActiveShader() == this) + glUniform4f(loc, color.r, color.g, color.b, color.a); +} + +uint Shader::GetGLTextureUnitCount() +{ + GLint maxTextureUnits; + glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits); + return (uint)maxTextureUnits; +} + +std::string Shader::GetProgramWarnings() +{ + GLint strsize, nullpos; + glGetProgramiv(m_Program, GL_INFO_LOG_LENGTH, &strsize); + + if (strsize == 0) + return ""; + + char *tempstr = new char[strsize]; + + memset(tempstr, '\0', strsize); + glGetProgramInfoLog(m_Program, strsize, &nullpos, tempstr); + tempstr[nullpos] = '\0'; + + std::string warnings(tempstr); + delete[] tempstr; + + return warnings; +} + +std::string Shader::GetShaderWarnings(GLuint shader) +{ + GLint strsize, nullpos; + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &strsize); + + if (strsize == 0) + return ""; + + char *tempstr = new char[strsize]; + + memset(tempstr, '\0', strsize); + glGetShaderInfoLog(shader, strsize, &nullpos, tempstr); + tempstr[nullpos] = '\0'; + + std::string warnings(tempstr); + delete[] tempstr; + + return warnings; +} + +void Shader::SetAttribute(int loc, VertexBuffer* vbo, uint offseti, uint stridei, bool normalized) +{ + GLsizei offset = offseti * vbo->GetDataTypeSize(); + GLsizei stride = stridei * vbo->GetDataTypeSize(); + glEnableVertexAttribArray(loc); + vbo->Bind(); + glVertexAttribPointer(loc, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset); + vbo->UnBind(); +} + +int Shader::GetAttributeLocation(const std::string& attribute) +{ + int loc = glGetAttribLocation(m_Program, attribute.c_str()); + return loc; +} + +void Shader::DisableAttribute(int loc) +{ + glDisableVertexAttribArray(loc); +} + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Shader.h b/source/modules/asura-core/Graphics/Shader.h new file mode 100644 index 0000000..c96b99f --- /dev/null +++ b/source/modules/asura-core/Graphics/Shader.h @@ -0,0 +1,117 @@ +#ifndef _ASURA_ENGINE_SHADER_H_ +#define _ASURA_ENGINE_SHADER_H_ + +#include <map> +#include <string> + +#include <asura-utils/Exceptions/Exception.h> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/IO/Renewable.h> +#include <asura-utils/Math/Vector2.hpp> +#include <asura-utils/Math/vector3.hpp> +#include <asura-utils/Math/vector4.h> +#include <asura-utils/Math/matrix44.h> +#include <asura-utils/Stringmap.hpp> +#include <asura-utils/Manager.hpp> + +#include "GfxDevice.h" +#include "Color.h" +#include "Texture.h" +#include "VertexBuffer.h" +#include "IndexBuffer.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩ uniformsuseɫ +/// ķ༭ÿshaderͨshaderҵuniforms¶frameworkmaterial +/// á +/// +class Shader ASURA_FINAL + : public Scripting::Portable<Shader> + , public AEIO::Renewable +{ +public: + + Shader(); + + ~Shader(); + + static void SetActive(Shader* shader); + static Shader* GetActive(); + + bool Load(const std::string& vert, const std::string& frag) ASURA_THROW(Exception); + + // ʹSetActiveлshaderʱ + void OnEnable(); + void OnDisable(); + // Draw call֮ + void OnUsed(); + + void SetAttribute(int loc, VertexBuffer* vbo, uint offseti = 0, uint stridei = 0, bool normalized = false); + int GetAttributeLocation(const std::string& attribute); + void DisableAttribute(int loc); + + bool HasUniform(const std::string& uniform); + uint GetUniformLocation(const std::string& uniform); + void SetUniformFloat(uint loc, float value); + void SetUniformVector2(uint loc, const Math::Vector2f& vec2); + void SetUniformVector3(uint loc, const Math::Vector3f& vec3); + void SetUniformVector4(uint loc, const Math::Vector4f& vec4); + void SetUniformColor(uint loc, const Color& color); + void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44); + bool SetUniformTexture(uint loc, const Texture& texture); + + float GetUniformFloat(uint loc); + AEMath::Vector2f GetUniformVector2(uint loc); + AEMath::Vector3f GetUniformVector3(uint loc); + AEMath::Vector4f GetUniformVector4s(uint loc); + AEMath::Matrix44 GetUniformMatrix44(uint loc); + + GLuint GetGLProgram(); + + static uint GetGLTextureUnitCount(); + +private: + + bool CompileVertexShader(const std::string& vert, std::string& outError); + bool CompileFragementShader(const std::string& frag, std::string& outError); + + std::string GetProgramWarnings(); + std::string GetShaderWarnings(GLuint shader); + + GLuint m_Program; + GLuint m_VertShader; + GLuint m_FragShader; + +luaxport: + + LUAX_DECL_FACTORY(Shader); + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Load); + LUAX_DECL_METHOD(_Update); + LUAX_DECL_METHOD(_HasUniform); + LUAX_DECL_METHOD(_GetUniformLocation); + LUAX_DECL_METHOD(_SetUniformFloat); + LUAX_DECL_METHOD(_SetUniformTexture); + LUAX_DECL_METHOD(_SetUniformVector2); + LUAX_DECL_METHOD(_SetUniformVector3); + LUAX_DECL_METHOD(_SetUniformVector4); + LUAX_DECL_METHOD(_SetUniformColor); + + LUAX_DECL_METHOD(_GetAttributeLocation); + LUAX_DECL_METHOD(_SetAttribute); + LUAX_DECL_METHOD(_DisableAttribute); + + LUAX_DECL_METHOD(_SetBuiltInUniforms); + +}; + +typedef Shader GpuProgram; + +namespace_end +namespace_end + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/profiler/gpu_profiler.cpp b/source/modules/asura-core/Graphics/Shape.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-core/profiler/gpu_profiler.cpp +++ b/source/modules/asura-core/Graphics/Shape.cpp diff --git a/source/modules/asura-core/profiler/gpu_profiler.h b/source/modules/asura-core/Graphics/Shape.h index e69de29..e69de29 100644 --- a/source/modules/asura-core/profiler/gpu_profiler.h +++ b/source/modules/asura-core/Graphics/Shape.h diff --git a/source/modules/asura-core/threading/channel.cpp b/source/modules/asura-core/Graphics/SpriteBatch.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-core/threading/channel.cpp +++ b/source/modules/asura-core/Graphics/SpriteBatch.cpp diff --git a/source/modules/asura-core/graphics/sprite_batch.h b/source/modules/asura-core/Graphics/SpriteBatch.h index 7f22da0..a98d1f4 100644 --- a/source/modules/asura-core/graphics/sprite_batch.h +++ b/source/modules/asura-core/Graphics/SpriteBatch.h @@ -1,9 +1,9 @@ -#ifndef __ASURA_ENGINE_SPRITE_BATCH_H__ -#define __ASURA_ENGINE_SPRITE_BATCH_H__ +#ifndef _ASURA_ENGINE_SPRITE_BATCH_H_ +#define _ASURA_ENGINE_SPRITE_BATCH_H_ -#include <asura-utils/scripting/portable.hpp> +#include <asura-utils/Scripting/Portable.hpp> -#include "gpu_buffer.h" +#include "GPUBuffer.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/Graphics/Texture.cpp b/source/modules/asura-core/Graphics/Texture.cpp new file mode 100644 index 0000000..bae0f7c --- /dev/null +++ b/source/modules/asura-core/Graphics/Texture.cpp @@ -0,0 +1,47 @@ +#include <asura-utils/Exceptions/Exception.h> + +#include "Texture.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +Texture::Texture() + : m_TexID(0) +{ +} + +Texture::~Texture() +{ + // ͷԴ + if(m_TexID != 0) + glDeleteTextures(1, &m_TexID); +} + +GLuint Texture::GetGLTexture() const +{ + return m_TexID; +} + +TextureFormat Texture::ConvertColorFormat(const ColorFormat& colorformat) +{ + TextureFormat t; + switch (colorformat) + { + case COLOR_FORMAT_RGBA8: + t.internalformat = GL_RGBA8; // 4*sizeof(byte) ~= 4 bytes + t.externalformat = GL_RGBA; + t.type = GL_UNSIGNED_BYTE; + break; + case COLOR_FORMAT_RGBA32F: + t.internalformat = GL_RGBA32F; // 4*sizeof(float) = 16 bytes + t.externalformat = GL_RGBA; + t.type = GL_FLOAT; + break; + default: + ASSERT(false); + } + return t; +} + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Texture.h b/source/modules/asura-core/Graphics/Texture.h new file mode 100644 index 0000000..7d37c31 --- /dev/null +++ b/source/modules/asura-core/Graphics/Texture.h @@ -0,0 +1,101 @@ +#ifndef _ASURA_TEXTURE_H_ +#define _ASURA_TEXTURE_H_ + +#include <asura-utils/Math/Vector2.hpp> +#include <asura-utils/Math/Rect.hpp> + +#include "../CoreConfig.h" + +#include "RenderState.h" +#include "GfxDevice.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +class RenderTarget; + +/// UVʽ +enum WrapMode +{ + WRAP_MODE_REPEAT, + WRAP_MODE_MIRROR, + WRAP_MODE_CLAMPTOEDGE, + WRAP_MODE_CLAMPTOBORDER, +}; + +/// ˲ģʽ +enum FilterMode +{ + FILTER_MODE_NEAREST, + FILTER_MODE_LINEAR, +}; + +/// ͼݵɫʽ +enum ColorFormat +{ + COLOR_FORMAT_UNKNOWN, + COLOR_FORMAT_RGBA8, ///< RGBA8bits int + COLOR_FORMAT_RGBA32F, ///< RGBA32bits float +}; + +/// ʽGPUڲCPUⲿʽ +struct TextureFormat +{ + GLenum internalformat; ///< GPUڲʽ + GLenum externalformat; ///< CPUⲿʽ + GLenum type; ///< ⲿʽÿchannelֵ +}; + +/// +/// 2D࣬2d meshrender targetбʹáTextureȾԭϽǣϷϲԵѿ +/// ϵΪEditorҲϽΪԭ㣬Ϊ˷㡣 +/// +ASURA_ABSTRACT class Texture : public AEScripting::Object +{ +public: + + LUAX_DECL_ABSTRACT_FACTORY(Texture); + + Texture(); + virtual ~Texture(); + + GLuint GetGLTexture() const; + + void SetFilterMode(FilterMode min, FilterMode mag); + void SetWrapMode(WrapMode wrapMode); + + void GetFilterMode(); + void GetWrapMode(); + + /// UVfilterΪ + bool IsGenMipmap(); + +protected: + + /// תcolor formatΪtexture format + TextureFormat ConvertColorFormat(const ColorFormat& colorformat); + + GLuint m_TexID; + FilterMode m_MinFilter; + FilterMode m_MagFilter; + WrapMode m_WrapMode; + bool m_IsGenMipmap; + + LUAX_DECL_ENUM(ColorFormat, 1); + LUAX_DECL_ENUM(FilterMode, 1); + LUAX_DECL_ENUM(WrapMode, 1); + + LUAX_DECL_METHOD(_SetFilterMode); + LUAX_DECL_METHOD(_SetWrapMode); + LUAX_DECL_METHOD(_GetFilterMode); + LUAX_DECL_METHOD(_GetWrapMode); + LUAX_DECL_METHOD(_IsGenMipmap); + +}; + +typedef Texture Drawable; + +namespace_end +namespace_end + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/vertex_buffer.cpp b/source/modules/asura-core/Graphics/VertexBuffer.cpp index 7fcd3d4..c44e9be 100644 --- a/source/modules/asura-core/graphics/vertex_buffer.cpp +++ b/source/modules/asura-core/Graphics/VertexBuffer.cpp @@ -1,4 +1,4 @@ -#include "vertex_buffer.h" +#include "VertexBuffer.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/graphics/vertex_buffer.h b/source/modules/asura-core/Graphics/VertexBuffer.h index f0bfb9e..83e9b09 100644 --- a/source/modules/asura-core/graphics/vertex_buffer.h +++ b/source/modules/asura-core/Graphics/VertexBuffer.h @@ -1,9 +1,9 @@ -#ifndef __ASURA_VERTEX_BUFFER_H__ -#define __ASURA_VERTEX_BUFFER_H__ +#ifndef _ASURA_VERTEX_BUFFER_H_ +#define _ASURA_VERTEX_BUFFER_H_ -#include <asura-utils/scripting/portable.hpp> +#include <asura-utils/Scripting/Portable.hpp> -#include "gpu_buffer.h" +#include "GPUBuffer.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/Graphics/binding/_canvas.cpp b/source/modules/asura-core/Graphics/binding/_canvas.cpp new file mode 100644 index 0000000..44841f5 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_canvas.cpp @@ -0,0 +1,48 @@ +#include "../Canvas.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(Canvas) + { + LUAX_REGISTER_METHODS(state, + { "SetSize", _SetSize }, + { "Bind", _Bind }, + { "Unbind", _Unbind } + ); + } + + LUAX_POSTPROCESS(Canvas) + { + + } + + // canvas:SetSize() + LUAX_IMPL_METHOD(Canvas, _SetSize) + { + LUAX_PREPARE(L, Canvas); + return 0; + + } + + // canvas:Bind() + LUAX_IMPL_METHOD(Canvas, _Bind) + { + LUAX_PREPARE(L, Canvas); + + return 0; + } + + // canvas:Unbind() + LUAX_IMPL_METHOD(Canvas, _Unbind) + { + LUAX_PREPARE(L, Canvas); + return 0; + + } + + } +} diff --git a/source/modules/asura-core/Graphics/binding/_color.cpp b/source/modules/asura-core/Graphics/binding/_color.cpp new file mode 100644 index 0000000..008d9c2 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_color.cpp @@ -0,0 +1,130 @@ +#include "../Color.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + +LUAX_REGISTRY(Color) +{ + LUAX_REGISTER_METHODS(state, + { "ToColor32", _ToColor32 }, + { "SetColor", _SetColor }, + { "GetColor", _GetColor }, + { "GetR", _GetR }, + { "GetG", _GetG }, + { "GetB", _GetB }, + { "GetA", _GetA }, + { "__eq", ___eq }, + { "__add", ___add }, + { "__sub", ___sub }, + { "__mul", ___mul }, + { "__div", ___div } + ); +} + +LUAX_POSTPROCESS(Color) +{ + +} + +// color:ToColor32() +LUAX_IMPL_METHOD(Color, _ToColor32) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:SetColor() +LUAX_IMPL_METHOD(Color, _SetColor) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetColor() +LUAX_IMPL_METHOD(Color, _GetColor) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetR() +LUAX_IMPL_METHOD(Color, _GetR) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetG() +LUAX_IMPL_METHOD(Color, _GetG) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetB() +LUAX_IMPL_METHOD(Color, _GetB) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetA() +LUAX_IMPL_METHOD(Color, _GetA) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__eq() +LUAX_IMPL_METHOD(Color, ___eq) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__add() +LUAX_IMPL_METHOD(Color, ___add) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__sub() +LUAX_IMPL_METHOD(Color, ___sub) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__mul() +LUAX_IMPL_METHOD(Color, ___mul) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__div() +LUAX_IMPL_METHOD(Color, ___div) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +} +}
\ No newline at end of file diff --git a/source/modules/asura-core/Graphics/binding/_color32.cpp b/source/modules/asura-core/Graphics/binding/_color32.cpp new file mode 100644 index 0000000..7613361 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_color32.cpp @@ -0,0 +1,66 @@ +#include "../Color32.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(Color32) + { + LUAX_REGISTER_METHODS(state, + { "ToColor", _ToColor }, + { "GetRed", _GetRed }, + { "GetGreen", _GetGreen }, + { "GetBlue", _GetBlue }, + { "GetAlpha", _GetAlpha } + ); + } + + LUAX_POSTPROCESS(Color32) + { + + } + + // color32:ToColor() + LUAX_IMPL_METHOD(Color32, _ToColor) + { + LUAX_PREPARE(L, Color32); + return 0; + + } + + // color32:GetRed() + LUAX_IMPL_METHOD(Color32, _GetRed) + { + LUAX_PREPARE(L, Color32); + return 0; + } + + // color32:GetGreen() + LUAX_IMPL_METHOD(Color32, _GetGreen) + { + LUAX_PREPARE(L, Color32); + + return 0; + } + + // color32:GetBlue() + LUAX_IMPL_METHOD(Color32, _GetBlue) + { + LUAX_PREPARE(L, Color32); + + return 0; + } + + // color32:GetAlpha() + LUAX_IMPL_METHOD(Color32, _GetAlpha) + { + LUAX_PREPARE(L, Color32); + + return 0; + } + + } +} +
\ No newline at end of file diff --git a/source/modules/asura-core/Graphics/binding/_gfx_device.cpp b/source/modules/asura-core/Graphics/binding/_gfx_device.cpp new file mode 100644 index 0000000..f6c2004 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_gfx_device.cpp @@ -0,0 +1,151 @@ +#include "../GfxDevice.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(GfxDevice) + { + LUAX_REGISTER_METHODS(state, + { "SetMatrixMode", _SetMatrixMode }, + { "GetMatrixMode", _GetMatrixMode }, + { "PushMatrix", _PushMatrix }, + { "PopMatrix", _PopMatrix }, + { "LoadIdentity", _LoadIdentity }, + { "Rotate", _Rotate }, + { "Translate", _Translate }, + { "Scale", _Scale }, + { "Ortho", _Ortho }, + { "GetMatrixDepth", _GetMatrixDepth }, + { "GetMatrixIndex", _GetMatrixIndex }, + { "UseShader", _UseShader }, + { "UnuseShader", _UnuseShader } + ); + } + + LUAX_POSTPROCESS(GfxDevice) + { + LUAX_REGISTER_ENUM(state, "EMatrixMode", + { "PROJECTION", MATRIX_MODE_PROJECTION }, + { "0", 0 }, + { "MODEL", MATRIX_MODE_MODEL }, + { "1", 1 }, + { "VIEW", MATRIX_MODE_VIEW }, + { "2", 2 } + ); + LUAX_REGISTER_ENUM(state, "EGLParams", + { "MAX_TEXTURE_UNIT", GL_PARAM_MAX_TEXTURE_UNIT }, + { "1", 1 } + ); + + } + + // gfxdevice:SetMatrixMode() + LUAX_IMPL_METHOD(GfxDevice, _SetMatrixMode) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:GetMatrixMode() + LUAX_IMPL_METHOD(GfxDevice, _GetMatrixMode) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:PushMatrix() + LUAX_IMPL_METHOD(GfxDevice, _PushMatrix) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:PopMatrix() + LUAX_IMPL_METHOD(GfxDevice, _PopMatrix) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:LoadIdentity() + LUAX_IMPL_METHOD(GfxDevice, _LoadIdentity) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:Rotate() + LUAX_IMPL_METHOD(GfxDevice, _Rotate) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:Translate() + LUAX_IMPL_METHOD(GfxDevice, _Translate) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:Scale() + LUAX_IMPL_METHOD(GfxDevice, _Scale) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:Ortho() + LUAX_IMPL_METHOD(GfxDevice, _Ortho) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:GetMatrixDepth() + LUAX_IMPL_METHOD(GfxDevice, _GetMatrixDepth) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:GetMatrixIndex() + LUAX_IMPL_METHOD(GfxDevice, _GetMatrixIndex) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:UseShader() + LUAX_IMPL_METHOD(GfxDevice, _UseShader) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:UnuseShader() + LUAX_IMPL_METHOD(GfxDevice, _UnuseShader) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + } +} diff --git a/source/modules/asura-core/Graphics/binding/_gpu_buffer.cpp b/source/modules/asura-core/Graphics/binding/_gpu_buffer.cpp new file mode 100644 index 0000000..8c39a59 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_gpu_buffer.cpp @@ -0,0 +1,118 @@ +#include <stdlib.h> + +#include "../image.h" +#include "../GPUBuffer.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(GPUBuffer) + { + LUAX_REGISTER_METHODS(state, + { "Fill", _Fill }, + { "GetSize", _GetSize }, + { "GetCount", _GetCount } + ); + } + + LUAX_POSTPROCESS(GPUBuffer) + { + LUAX_REGISTER_ENUM(state, "EBufferType", + { "VERTEX", BUFFER_TYPE_VERTEX }, + { "INDEX", BUFFER_TYPE_INDEX } + ); + LUAX_REGISTER_ENUM(state, "EBufferUsage", + { "STREAM", BUFFER_USAGE_STREAM }, + { "DYNAMIC", BUFFER_USAGE_DYNAMIC }, + { "STATIC", BUFFER_USAGE_STATIC } + ); + LUAX_REGISTER_ENUM(state, "EBufferDataType", + { "INT", BUFFER_DATA_TYPE_INT }, + { "FLOAT", BUFFER_DATA_TYPE_FLOAT }, + { "UNSIGNED_BYTE", BUFFER_DATA_TYPE_UNSIGNED_BYTE } + ); + + } + + // buffer = GPUBuffer.New(bufferType, bufferUsage, bufferDataType, size) + // buffer = GPUBuffer.New(image) + // buffer = GPUBuffer.New(mesh2d) + // buffer = GPUBuffer.New(canvas) + // buffer = GPUBuffer.New(shape) + //LUAX_IMPL_METHOD(GPUBuffer, _New) + //{ + // LUAX_STATE(L); + + // return 0; + //} + + // gpubuffer:Fill({data_unit_list}, offseti) + // data_unit_list ݵtable + // offseti : ʼǵĵطڵ(0ʼ + LUAX_IMPL_METHOD(GPUBuffer, _Fill) + { + LUAX_PREPARE(L, GPUBuffer); + + // ʹbufferӦbufferڵһεʱʼsizeСbufferȻ䡣 + int offset = state.GetValue(3, 0); + int count = lua_objlen(L, 2); + int size = count * self->GetDataTypeSize(); + byte* data = (byte*)malloc(size); + int unit = self->GetDataTypeSize(); + int i = 1; + lua_rawgeti(L, 2, i); + while (!lua_isnil(L, -1)) + { + switch (self->m_DataType) + { + case GL_INT: + { + int n = state.CheckValue<int>(-1); + memcpy(data + (i - 1)*unit, &n, unit); + break; + } + case GL_FLOAT: + { + float n = state.CheckValue<float>(-1); + memcpy(data + (i - 1)*unit, &n, unit); + break; + } + case GL_UNSIGNED_BYTE: + { + unsigned char n = state.CheckValue<unsigned char>(-1); + memcpy(data + (i - 1)*unit, &n, unit); + break; + } + } + state.Pop(1); // value + lua_rawgeti(L, 2, ++i); + } + state.Pop(); // nil + + self->Fill(data, size, offset * unit); + + free(data); + return 0; + } + + // gpubuffer:GetSize() + LUAX_IMPL_METHOD(GPUBuffer, _GetSize) + { + LUAX_PREPARE(L, GPUBuffer); + state.Push(self->m_Size); + return 0; + } + + LUAX_IMPL_METHOD(GPUBuffer, _GetCount) + { + LUAX_PREPARE(L, GPUBuffer); + state.Push(self->m_Size / self->GetDataTypeSize()); + return 0; + } + + } +} diff --git a/source/modules/asura-core/Graphics/binding/_image.cpp b/source/modules/asura-core/Graphics/binding/_image.cpp new file mode 100644 index 0000000..0e4cb16 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_image.cpp @@ -0,0 +1,71 @@ +#include "../image.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(Image) + { + LUAX_INHERIT(state, Texture); + + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "GetWidth", _GetWidth }, + { "GetHeight", _GetHeight }, + { "GetSize", _GetSize }, + { "Render", _Render } + ); + } + + LUAX_POSTPROCESS(Image) + { + } + + // image = Image.New() + LUAX_IMPL_METHOD(Image, _New) + { + LUAX_STATE(L); + Image* img = new Image(); + img->PushLuaxUserdata(state); + return 1; + } + + // width = image:GetWidth() + LUAX_IMPL_METHOD(Image, _GetWidth) + { + LUAX_PREPARE(L, Image); + state.Push(self->GetWidth()); + return 1; + } + + // height = image:GetHeight() + LUAX_IMPL_METHOD(Image, _GetHeight) + { + LUAX_PREPARE(L, Image); + state.Push(self->GetHeight()); + return 1; + } + + // width, height = image:GetSize() + LUAX_IMPL_METHOD(Image, _GetSize) + { + LUAX_PREPARE(L, Image); + int width = self->GetWidth(); + int height = self->GetHeight(); + state.Push(width); + state.Push(height); + return 2; + } + + // image:Render() + LUAX_IMPL_METHOD(Image, _Render) + { + LUAX_PREPARE(L, Image); + + return 0; + } + + } +} diff --git a/source/modules/asura-core/Graphics/binding/_index_buffer.cpp b/source/modules/asura-core/Graphics/binding/_index_buffer.cpp new file mode 100644 index 0000000..151dc98 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_index_buffer.cpp @@ -0,0 +1,31 @@ +#include "../IndexBuffer.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(IndexBuffer) + { + LUAX_REGISTER_METHODS(state, + { "New", _New } + ); + } + + LUAX_POSTPROCESS(IndexBuffer) + { + + } + + // IndexBuffer.New() + LUAX_IMPL_METHOD(IndexBuffer, _New) + { + LUAX_STATE(L); + + return 0; + } + + } +} diff --git a/source/modules/asura-core/Graphics/binding/_mesh2d.cpp b/source/modules/asura-core/Graphics/binding/_mesh2d.cpp new file mode 100644 index 0000000..4e3f426 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_mesh2d.cpp @@ -0,0 +1,20 @@ +#include "../mesh2d.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(Mesh2D) + { + + } + + LUAX_POSTPROCESS(Mesh2D) + { + + } + + } +} diff --git a/source/modules/asura-core/Graphics/binding/_shader.cpp b/source/modules/asura-core/Graphics/binding/_shader.cpp new file mode 100644 index 0000000..85fd388 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_shader.cpp @@ -0,0 +1,131 @@ +#include "../shader.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(Shader) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "Load", _Load }, + { "Update", _Update }, + { "HasUniform", _HasUniform }, + { "GetUniformLocation", _GetUniformLocation }, + { "SetBuiltInUniforms", _SetBuiltInUniforms }, + { "SetUniformFloat", _SetUniformFloat }, + { "SetUniformTexture", _SetUniformTexture }, + { "SetUniformVector2", _SetUniformVector2 }, + { "SetUniformVector3", _SetUniformVector3 }, + { "SetUniformVector4", _SetUniformVector4 }, + { "SetUniformColor", _SetUniformColor }, + { "SetBuiltInUniforms", _SetBuiltInUniforms } + ); + } + + LUAX_POSTPROCESS(Shader) + { + + } + + // Shader.New() + LUAX_IMPL_METHOD(Shader, _New) + { + LUAX_STATE(L); + + return 0; + } + + // shader:Load() + LUAX_IMPL_METHOD(Shader, _Load) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:Update() + LUAX_IMPL_METHOD(Shader, _Update) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:HasUniform() + LUAX_IMPL_METHOD(Shader, _HasUniform) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:GetUniformLocation() + LUAX_IMPL_METHOD(Shader, _GetUniformLocation) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetBuiltInUniforms() + LUAX_IMPL_METHOD(Shader, _SetBuiltInUniforms) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformFloat() + LUAX_IMPL_METHOD(Shader, _SetUniformFloat) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformTexture() + LUAX_IMPL_METHOD(Shader, _SetUniformTexture) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformVector2() + LUAX_IMPL_METHOD(Shader, _SetUniformVector2) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformVector3() + LUAX_IMPL_METHOD(Shader, _SetUniformVector3) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformVector4() + LUAX_IMPL_METHOD(Shader, _SetUniformVector4) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformColor() + LUAX_IMPL_METHOD(Shader, _SetUniformColor) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + } +} diff --git a/source/modules/asura-core/Graphics/binding/_sprite_batch.cpp b/source/modules/asura-core/Graphics/binding/_sprite_batch.cpp new file mode 100644 index 0000000..6b7d25c --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_sprite_batch.cpp @@ -0,0 +1,20 @@ +#include "../SpriteBatch.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(SpriteBatch) + { + + } + + LUAX_POSTPROCESS(SpriteBatch) + { + + } + + } +} diff --git a/source/modules/asura-core/Graphics/binding/_texture.cpp b/source/modules/asura-core/Graphics/binding/_texture.cpp new file mode 100644 index 0000000..f5e5f17 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_texture.cpp @@ -0,0 +1,85 @@ +#include "../texture.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(Texture) + { + LUAX_REGISTER_METHODS(state, + { "SetFilterMode", _SetFilterMode }, + { "SetWrapMode", _SetWrapMode }, + { "GetFilterMode", _GetFilterMode }, + { "GetWrapMode", _GetWrapMode }, + { "IsGenMipmap", _IsGenMipmap } + ); + } + + LUAX_POSTPROCESS(Texture) + { + LUAX_REGISTER_ENUM(state, "EColorFormat", + { "UNKNOWN", COLOR_FORMAT_UNKNOWN }, + { "RGBA8", COLOR_FORMAT_RGBA8 }, + { "RGBA32F", COLOR_FORMAT_RGBA32F } + ); + LUAX_REGISTER_ENUM(state, "EFilterMode", + { "NEAREST", FILTER_MODE_NEAREST }, + { "LINEAR", FILTER_MODE_LINEAR } + ); + LUAX_REGISTER_ENUM(state, "EWrapMode", + { "REPEAT", WRAP_MODE_REPEAT }, + { "MIRROR", WRAP_MODE_MIRROR }, + { "CLAMPTOEDGE", WRAP_MODE_CLAMPTOEDGE }, + { "CLAMPTOBORDER", WRAP_MODE_CLAMPTOBORDER } + ); + + } + + // texture:SetFilterMode(minFilter, magFilter) + LUAX_IMPL_METHOD(Texture, _SetFilterMode) + { + LUAX_PREPARE(L, Texture); + FilterMode min = (FilterMode)state.CheckValue<int>(2); + FilterMode mag = (FilterMode)state.CheckValue<int>(3); + self->SetFilterMode(min, mag); + return 0; + } + + // texture:SetWrapMode(wrap_mode) + LUAX_IMPL_METHOD(Texture, _SetWrapMode) + { + LUAX_PREPARE(L, Texture); + WrapMode wrap_mode = (WrapMode)state.CheckValue<int>(2); + self->SetWrapMode(wrap_mode); + return 0; + } + + // min, mag = texture:GetFilterMode() + LUAX_IMPL_METHOD(Texture, _GetFilterMode) + { + LUAX_PREPARE(L, Texture); + state.Push((int)self->m_MinFilter); + state.Push((int)self->m_MagFilter); + return 2; + } + + // wrapmode= texture:GetWrapMode() + LUAX_IMPL_METHOD(Texture, _GetWrapMode) + { + LUAX_PREPARE(L, Texture); + state.Push((int)self->m_WrapMode); + return 1; + } + + // texture:IsGenMipmap() + LUAX_IMPL_METHOD(Texture, _IsGenMipmap) + { + LUAX_PREPARE(L, Texture); + state.Push(self->IsGenMipmap()); + return 1; + } + + } +}
\ No newline at end of file diff --git a/source/modules/asura-core/Graphics/binding/_vertex_buffer.cpp b/source/modules/asura-core/Graphics/binding/_vertex_buffer.cpp new file mode 100644 index 0000000..8ed487b --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_vertex_buffer.cpp @@ -0,0 +1,38 @@ +#include "../VertexBuffer.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(VertexBuffer) + { + LUAX_REGISTER_METHODS(state, + { "New", _New } + ); + } + + LUAX_POSTPROCESS(VertexBuffer) + { + + } + + // vbo = VertexBuffer.New(usage, data_type, count) + LUAX_IMPL_METHOD(VertexBuffer, _New) + { + LUAX_STATE(L); + + BufferUsage usage = (BufferUsage)state.CheckValue<uint>(1); + BufferDataType datatype = (BufferDataType)state.CheckValue<uint>(2); + uint count = state.CheckValue<uint>(3); + + VertexBuffer* vbo = new VertexBuffer(usage, datatype, count * GPUBuffer::GetDataTypeSize(datatype)); + vbo->PushLuaxUserdata(state); + + return 1; + } + + } +} diff --git a/source/modules/asura-core/image/image_data.cpp b/source/modules/asura-core/Image/ImageData.cpp index 1de70cd..c75166f 100644 --- a/source/modules/asura-core/image/image_data.cpp +++ b/source/modules/asura-core/Image/ImageData.cpp @@ -1,7 +1,7 @@ -#include "image_data.h" -#include "png_decoder.h" -#include "stb_decoder.h" -#include "image_decoder.h" +#include "ImageData.h" +#include "PngDecoder.h" +#include "StbDecoder.h" +#include "ImageDecoder.h" using namespace std; diff --git a/source/modules/asura-core/image/image_data.h b/source/modules/asura-core/Image/ImageData.h index 93e3448..cd2fe1a 100644 --- a/source/modules/asura-core/image/image_data.h +++ b/source/modules/asura-core/Image/ImageData.h @@ -1,16 +1,16 @@ -#ifndef __ASURA_ENGINE_IMAGEDATA_H__ -#define __ASURA_ENGINE_IMAGEDATA_H__ +#ifndef _ASURA_ENGINE_IMAGEDATA_H_ +#define _ASURA_ENGINE_IMAGEDATA_H_ #include <list> -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/io/decoded_data.h> -#include <asura-utils/io/data_buffer.h> -#include <asura-utils/threading/thread.h> -#include <asura-utils/threading/mutex.h> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/IO/DecodedData.h> +#include <asura-utils/IO/DataBuffer.h> +#include <asura-utils/Threads/Thread.h> +#include <asura-utils/Threads/Mutex.h> -#include "../graphics/texture.h" -#include "../graphics/color.h" +#include "../Graphics/Texture.h" +#include "../Graphics/Color.h" namespace_begin(AsuraEngine) namespace_begin(Image) diff --git a/source/modules/asura-core/image/image_decode_task.cpp b/source/modules/asura-core/Image/ImageDecodeTask.cpp index 3cadb43..16c166e 100644 --- a/source/modules/asura-core/image/image_decode_task.cpp +++ b/source/modules/asura-core/Image/ImageDecodeTask.cpp @@ -1,4 +1,4 @@ -#include "image_decode_task.h" +#include "ImageDecodeTask.h" namespace_begin(AsuraEngine) namespace_begin(Image) diff --git a/source/modules/asura-core/image/image_decode_task.h b/source/modules/asura-core/Image/ImageDecodeTask.h index 3726514..74ecf24 100644 --- a/source/modules/asura-core/image/image_decode_task.h +++ b/source/modules/asura-core/Image/ImageDecodeTask.h @@ -1,9 +1,9 @@ -#ifndef __ASURA_IMAGE_DECODE_TASK_H__ -#define __ASURA_IMAGE_DECODE_TASK_H__ +#ifndef _ASURA_IMAGE_DECODE_TASK_H_ +#define _ASURA_IMAGE_DECODE_TASK_H_ -#include <asura-utils/threading/task.h> -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/classes.h> +#include <asura-utils/Threads/task.h> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Classes.h> namespace_begin(AsuraEngine) namespace_begin(Image) diff --git a/source/modules/asura-core/image/image_decoder.h b/source/modules/asura-core/Image/ImageDecoder.h index 30e65d3..7de92d6 100644 --- a/source/modules/asura-core/image/image_decoder.h +++ b/source/modules/asura-core/Image/ImageDecoder.h @@ -1,9 +1,9 @@ -#ifndef __ASURA_ENGINE_IMAGE_DECODER_H__ -#define __ASURA_ENGINE_IMAGE_DECODER_H__ +#ifndef _ASURA_ENGINE_IMAGE_DECODER_H_ +#define _ASURA_ENGINE_IMAGE_DECODER_H_ -#include <asura-utils/io/data_buffer.h> +#include <asura-utils/IO/DataBuffer.h> -#include "image_data.h" +#include "ImageData.h" namespace_begin(AsuraEngine) namespace_begin(Image) diff --git a/source/modules/asura-core/image/png_decoder.cpp b/source/modules/asura-core/Image/PngDecoder.cpp index bf33959..618c16e 100644 --- a/source/modules/asura-core/image/png_decoder.cpp +++ b/source/modules/asura-core/Image/PngDecoder.cpp @@ -1,4 +1,4 @@ -#include "png_decoder.h" +#include "PngDecoder.h" namespace_begin(AsuraEngine) namespace_begin(Image) diff --git a/source/modules/asura-core/image/png_decoder.h b/source/modules/asura-core/Image/PngDecoder.h index af67186..b6ea3ba 100644 --- a/source/modules/asura-core/image/png_decoder.h +++ b/source/modules/asura-core/Image/PngDecoder.h @@ -1,7 +1,7 @@ -#ifndef __ASURA_ENGINE_PNGDECODER_H__ -#define __ASURA_ENGINE_PNGDECODER_H__ +#ifndef _ASURA_ENGINE_PNGDECODER_H_ +#define _ASURA_ENGINE_PNGDECODER_H_ -#include "image_decoder.h" +#include "ImageDecoder.h" namespace_begin(AsuraEngine) namespace_begin(Image) diff --git a/source/modules/asura-core/image/stb_decoder.cpp b/source/modules/asura-core/Image/StbDecoder.cpp index ed61aa4..8d3537c 100644 --- a/source/modules/asura-core/image/stb_decoder.cpp +++ b/source/modules/asura-core/Image/StbDecoder.cpp @@ -1,6 +1,6 @@ -#include <asura-utils/exceptions/exception.h> +#include <asura-utils/Exceptions/Exception.h> -#include "stb_decoder.h" +#include "StbDecoder.h" #define STB_IMAGE_IMPLEMENTATION #include <stb/stb_image.h> diff --git a/source/modules/asura-core/image/stb_decoder.h b/source/modules/asura-core/Image/StbDecoder.h index 6158b21..a86073a 100644 --- a/source/modules/asura-core/image/stb_decoder.h +++ b/source/modules/asura-core/Image/StbDecoder.h @@ -1,7 +1,7 @@ -#ifndef __ASURA_ENGINE_STBDECODER_H__ -#define __ASURA_ENGINE_STBDECODER_H__ +#ifndef _ASURA_ENGINE_STBDECODER_H_ +#define _ASURA_ENGINE_STBDECODER_H_ -#include "image_decoder.h" +#include "ImageDecoder.h" namespace_begin(AsuraEngine) namespace_begin(Image) diff --git a/source/modules/asura-core/Image/binding/_image_data.cpp b/source/modules/asura-core/Image/binding/_image_data.cpp new file mode 100644 index 0000000..77f3a96 --- /dev/null +++ b/source/modules/asura-core/Image/binding/_image_data.cpp @@ -0,0 +1,108 @@ +#include <asura-utils/Threads/Thread.h> +#include <asura-utils/IO/DataBuffer.h> + +#include "../ImageData.h" + +using namespace std; +using namespace AEThreading; +using namespace AEIO; + +namespace_begin(AsuraEngine) +namespace_begin(Image) +LUAX_REGISTRY(ImageData) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "GetPixel", _GetPixel }, + { "GetSize", _GetSize }, + { "GetWidth", _GetWidth }, + { "GetHeight", _GetHeight }, + { "GetPixelFormat", _GetPixelFormat }, + { "Decode", _Decode }, + { "DecodeAsync", _DecodeAsync }, + { "IsAvailable", _IsAvailable } + ); + } + + LUAX_POSTPROCESS(ImageData) + { + + } + + // ImageData.New() + LUAX_IMPL_METHOD(ImageData, _New) + { + LUAX_STATE(L); + + return 0; + } + + // imagedata:GetPixel() + LUAX_IMPL_METHOD(ImageData, _GetPixel) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:GetSize() + LUAX_IMPL_METHOD(ImageData, _GetSize) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:GetWidth() + LUAX_IMPL_METHOD(ImageData, _GetWidth) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:GetHeight() + LUAX_IMPL_METHOD(ImageData, _GetHeight) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:GetPixelFormat() + LUAX_IMPL_METHOD(ImageData, _GetPixelFormat) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:Decode() + LUAX_IMPL_METHOD(ImageData, _Decode) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:DecodeAsync(thread, databuffer, callback) + LUAX_IMPL_METHOD(ImageData, _DecodeAsync) + { + LUAX_PREPARE(L, ImageData); + + Thread* thread = state.CheckUserdata<Thread>(2); + DataBuffer* buffer = state.CheckUserdata<DataBuffer>(3); + + return 0; + } + + // imagedata:IsAvailable() + LUAX_IMPL_METHOD(ImageData, _IsAvailable) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + } +} diff --git a/source/modules/asura-core/Image/binding/_image_decode_task.cpp b/source/modules/asura-core/Image/binding/_image_decode_task.cpp new file mode 100644 index 0000000..3c8ed4b --- /dev/null +++ b/source/modules/asura-core/Image/binding/_image_decode_task.cpp @@ -0,0 +1,19 @@ +#include "../ImageDecodeTask.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Image) + +LUAX_REGISTRY(ImageDecodeTask) +{ + +} + +LUAX_POSTPROCESS(ImageDecodeTask) +{ + +} + +} +} diff --git a/source/modules/asura-core/Input/Button.h b/source/modules/asura-core/Input/Button.h new file mode 100644 index 0000000..5c3c0de --- /dev/null +++ b/source/modules/asura-core/Input/Button.h @@ -0,0 +1,31 @@ +#ifndef __BUTTON_H__ +#define __BUTTON_H__ + +#include <asura-utils/Classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Input) + +/// keyboard button \ mouse button \ joystick button +class Button +{ +public: + inline Button(int key, bool state) : + key(key), + state(state) + { + } + + inline int GetKey(void) const { return this->key; } + inline bool GetState(void) const { return this->state; } + +private: + int key; + bool state; + +}; + +namespace_end +namespace_end + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/window/window_impl_glew.cpp b/source/modules/asura-core/Input/ClipBoard.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-core/window/window_impl_glew.cpp +++ b/source/modules/asura-core/Input/ClipBoard.cpp diff --git a/source/modules/asura-core/window/window_impl_glew.h b/source/modules/asura-core/Input/ClipBoard.h index e69de29..e69de29 100644 --- a/source/modules/asura-core/window/window_impl_glew.h +++ b/source/modules/asura-core/Input/ClipBoard.h diff --git a/source/modules/asura-core/window/window_impl_glut.cpp b/source/modules/asura-core/Input/InputDevice.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-core/window/window_impl_glut.cpp +++ b/source/modules/asura-core/Input/InputDevice.cpp diff --git a/source/modules/asura-core/input/input_device.h b/source/modules/asura-core/Input/InputDevice.h index 1c116e6..39f3d37 100644 --- a/source/modules/asura-core/input/input_device.h +++ b/source/modules/asura-core/Input/InputDevice.h @@ -1,13 +1,13 @@ -#ifndef __ASURA_ENGINE_INPUT_BASE_H__ -#define __ASURA_ENGINE_INPUT_BASE_H__ +#ifndef _ASURA_ENGINE_INPUT_BASE_H_ +#define _ASURA_ENGINE_INPUT_BASE_H_ -#include <asura-utils/math/vector2.hpp> -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/singleton.hpp> +#include <asura-utils/Math/Vector2.hpp> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Singleton.hpp> -#include "../core_config.h" +#include "../CoreConfig.h" -#include "keyboard_state.h" +#include "KeyboardState.h" namespace_begin(AsuraEngine) namespace_begin(Input) diff --git a/source/modules/asura-core/window/window_impl_glut.h b/source/modules/asura-core/Input/InputManager.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-core/window/window_impl_glut.h +++ b/source/modules/asura-core/Input/InputManager.cpp diff --git a/source/modules/asura-core/input/input_manager.h b/source/modules/asura-core/Input/InputManager.h index 7e24b4e..dd11b2f 100644 --- a/source/modules/asura-core/input/input_manager.h +++ b/source/modules/asura-core/Input/InputManager.h @@ -1,9 +1,9 @@ #ifndef __INPUT_MAMANGER_H__ #define __INPUT_MAMANGER_H__ -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/singleton.hpp> -#include <asura-utils/classes.h> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Singleton.hpp> +#include <asura-utils/Classes.h> namespace_begin(AsuraEngine) namespace_begin(Input) diff --git a/source/modules/asura-json/json_module.cpp b/source/modules/asura-core/Input/JoystickState.h index e69de29..e69de29 100644 --- a/source/modules/asura-json/json_module.cpp +++ b/source/modules/asura-core/Input/JoystickState.h diff --git a/source/modules/asura-core/input/keyboard_state.h b/source/modules/asura-core/Input/KeyboardState.h index 5c43dff..96d22e7 100644 --- a/source/modules/asura-core/input/keyboard_state.h +++ b/source/modules/asura-core/Input/KeyboardState.h @@ -3,7 +3,7 @@ #include <vector> -#include "button.h" +#include "Button.h" namespace_begin(AsuraEngine) namespace_begin(Input) diff --git a/source/modules/asura-core/Input/Keys.h b/source/modules/asura-core/Input/Keys.h new file mode 100644 index 0000000..8f04dc2 --- /dev/null +++ b/source/modules/asura-core/Input/Keys.h @@ -0,0 +1,482 @@ + +/** +* 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-json/json_module.h b/source/modules/asura-core/Input/MouseState.h index e69de29..e69de29 100644 --- a/source/modules/asura-json/json_module.h +++ b/source/modules/asura-core/Input/MouseState.h diff --git a/source/modules/asura-core/mesh/am2_handler.cpp b/source/modules/asura-core/Mesh/Am2Handler.cpp index d0b9252..115797f 100644 --- a/source/modules/asura-core/mesh/am2_handler.cpp +++ b/source/modules/asura-core/Mesh/Am2Handler.cpp @@ -1,4 +1,4 @@ -#include "am2_handler.h" +#include "Am2Handler.h" namespace_begin(AsuraEngine) namespace_begin(Mesh) diff --git a/source/modules/asura-core/mesh/am2_handler.h b/source/modules/asura-core/Mesh/Am2Handler.h index 4fa8ba5..8bd0612 100644 --- a/source/modules/asura-core/mesh/am2_handler.h +++ b/source/modules/asura-core/Mesh/Am2Handler.h @@ -1,7 +1,7 @@ -#ifndef __ASURA_MESH2D_AM2_HANDLER_H__ -#define __ASURA_MESH2D_AM2_HANDLER_H__ +#ifndef _ASURA_MESH2D_AM2_HANDLER_H__ +#define _ASURA_MESH2D_AM2_HANDLER_H__ -#include "mesh2d_handler.h" +#include "Mesh2dHandler.h" namespace_begin(AsuraEngine) namespace_begin(Mesh) diff --git a/source/modules/asura-network/network_module.h b/source/modules/asura-core/Mesh/Mesh2DData.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-network/network_module.h +++ b/source/modules/asura-core/Mesh/Mesh2DData.cpp diff --git a/source/modules/asura-core/mesh/mesh2d_data.h b/source/modules/asura-core/Mesh/Mesh2DData.h index 024ba02..1144846 100644 --- a/source/modules/asura-core/mesh/mesh2d_data.h +++ b/source/modules/asura-core/Mesh/Mesh2DData.h @@ -1,17 +1,17 @@ -#ifndef __ASURA_MESH2D_DATA_H__ -#define __ASURA_MESH2D_DATA_H__ +#ifndef _ASURA_MESH2D_DATA_H__ +#define _ASURA_MESH2D_DATA_H__ // cpp #include <vector> // asura modules -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/math/vector2.hpp> -#include <asura-utils/io/decoded_data.h> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Math/Vector2.hpp> +#include <asura-utils/IO/DecodedData.h> // module -#include "../graphics/color.h" -#include "../graphics/gpu_buffer.h" +#include "../Graphics/Color.h" +#include "../Graphics/GPUBuffer.h" namespace_begin(AsuraEngine) namespace_begin(Mesh) diff --git a/source/modules/asura-openal/audio/mpg123_decoder.cpp b/source/modules/asura-core/Mesh/Mesh2DHandler.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-openal/audio/mpg123_decoder.cpp +++ b/source/modules/asura-core/Mesh/Mesh2DHandler.cpp diff --git a/source/modules/asura-core/mesh/mesh2d_handler.h b/source/modules/asura-core/Mesh/Mesh2DHandler.h index c8ae32e..e50ace8 100644 --- a/source/modules/asura-core/mesh/mesh2d_handler.h +++ b/source/modules/asura-core/Mesh/Mesh2DHandler.h @@ -1,10 +1,10 @@ -#ifndef __ASURA_MESH2D_HANDLER_H__ -#define __ASURA_MESH2D_HANDLER_H__ +#ifndef _ASURA_MESH2D_HANDLER_H__ +#define _ASURA_MESH2D_HANDLER_H__ -#include <asura-utils/io/data_buffer.h> -#include <asura-utils/type.h> +#include <asura-utils/IO/DataBuffer.h> +#include <asura-utils/Type.h> -#include "mesh2d_data.h" +#include "Mesh2dData.h" namespace_begin(AsuraEngine) namespace_begin(Mesh) diff --git a/source/modules/asura-openal/audio/mpg123_decoder.h b/source/modules/asura-core/Mesh/ObjHandler.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-openal/audio/mpg123_decoder.h +++ b/source/modules/asura-core/Mesh/ObjHandler.cpp diff --git a/source/modules/asura-openal/audio/sound_data.cpp b/source/modules/asura-core/Mesh/ObjHandler.h index e69de29..e69de29 100644 --- a/source/modules/asura-openal/audio/sound_data.cpp +++ b/source/modules/asura-core/Mesh/ObjHandler.h diff --git a/source/modules/asura-openal/audio/sound_data.h b/source/modules/asura-core/Profiler/GPUProfiler.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-openal/audio/sound_data.h +++ b/source/modules/asura-core/Profiler/GPUProfiler.cpp diff --git a/source/modules/asura-openal/audio/sound_decode_task.cpp b/source/modules/asura-core/Profiler/GPUProfiler.h index e69de29..e69de29 100644 --- a/source/modules/asura-openal/audio/sound_decode_task.cpp +++ b/source/modules/asura-core/Profiler/GPUProfiler.h diff --git a/source/modules/asura-openal/audio/vorbis_decoder.cpp b/source/modules/asura-core/Profiler/Stats.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-openal/audio/vorbis_decoder.cpp +++ b/source/modules/asura-core/Profiler/Stats.cpp diff --git a/source/modules/asura-openal/audio/vorbis_decoder.h b/source/modules/asura-core/Profiler/Stats.h index e69de29..e69de29 100644 --- a/source/modules/asura-openal/audio/vorbis_decoder.h +++ b/source/modules/asura-core/Profiler/Stats.h diff --git a/source/modules/asura-utils/io/io_batch_task.cpp b/source/modules/asura-core/Threads/Channel.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-utils/io/io_batch_task.cpp +++ b/source/modules/asura-core/Threads/Channel.cpp diff --git a/source/modules/asura-core/Threads/Channel.h b/source/modules/asura-core/Threads/Channel.h new file mode 100644 index 0000000..01b9ded --- /dev/null +++ b/source/modules/asura-core/Threads/Channel.h @@ -0,0 +1,18 @@ +#ifndef _ASURA_THREAD_CHANNEL_H_ +#define _ASURA_THREAD_CHANNEL_H_ + +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Threads) + +class Channel +{ + +}; + +namespace_end +namespace_end + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/threading/thread_ex.cpp b/source/modules/asura-core/Threads/ThreadEx.cpp index da806f4..cc8107c 100644 --- a/source/modules/asura-core/threading/thread_ex.cpp +++ b/source/modules/asura-core/Threads/ThreadEx.cpp @@ -1,9 +1,9 @@ -#include <asura-utils/classes.h> +#include <asura-utils/Classes.h> -#include "thread_ex.h" +#include "ThreadEx.h" namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) int ThreadEx::Process() { diff --git a/source/modules/asura-core/threading/thread_ex.h b/source/modules/asura-core/Threads/ThreadEx.h index 0015f61..53600a6 100644 --- a/source/modules/asura-core/threading/thread_ex.h +++ b/source/modules/asura-core/Threads/ThreadEx.h @@ -1,11 +1,11 @@ -#ifndef __ASURA_THREAD_EX_H__ -#define __ASURA_THREAD_EX_H__ +#ifndef _ASURA_THREAD_EX_H_ +#define _ASURA_THREAD_EX_H_ -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/threading/thread.h> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Threads/Thread.h> namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) /// /// ThreadExеͬͨ˶ͨݡ diff --git a/source/modules/asura-utils/math/ranged_value.cpp b/source/modules/asura-core/Time/Timer.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-utils/math/ranged_value.cpp +++ b/source/modules/asura-core/Time/Timer.cpp diff --git a/source/modules/asura-utils/math/ranged_value.h b/source/modules/asura-core/Time/Timer.h index e69de29..e69de29 100644 --- a/source/modules/asura-utils/math/ranged_value.h +++ b/source/modules/asura-core/Time/Timer.h diff --git a/source/modules/asura-core/Type.h b/source/modules/asura-core/Type.h new file mode 100644 index 0000000..39880e2 --- /dev/null +++ b/source/modules/asura-core/Type.h @@ -0,0 +1,11 @@ +#ifndef _ASURA_ENGINE_TYPE_H_ +#define _ASURA_ENGINE_TYPE_H_ + +#include <stdint.h> + +namespace AsuraEngine +{ + +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/Window/Window.cpp b/source/modules/asura-core/Window/Window.cpp new file mode 100644 index 0000000..adba7c9 --- /dev/null +++ b/source/modules/asura-core/Window/Window.cpp @@ -0,0 +1,104 @@ +#include <asura-utils/Exceptions/Exception.h> + +#include "window.h" + +#include "WindowImplSDL.h" +#include "WindowImplGlew.h" +#include "WindowImplGlut.h" + +namespace_begin(AsuraEngine) +namespace_begin(Window) + + Window::Window() + : m_Impl(nullptr) + { + } + + Window::~Window() + { + if (m_Impl) + delete m_Impl; + } + +#define try_init_window(impl) \ + if (!m_Impl) \ + { \ + m_Impl = new impl(); \ + if (!m_Impl->Init(config)) \ + { \ + delete m_Impl; \ + m_Impl = nullptr; \ + } \ + } + + bool Window::Init(const WindowConfig& config) + { + ASSERT(!m_Impl); +#if ASURA_WINDOW_SDL + try_init_window(WindowImplSDL); +#endif + return m_Impl != nullptr; + } + + void Window::Exit() + { + if (m_Impl) + delete m_Impl; + } + + void Window::SetPosition(int x, int y) + { + ASSERT(m_Impl); + m_Impl->SetPosition(x, y); + } + + void Window::SetTitle(const std::string& title) + { + ASSERT(m_Impl); + m_Impl->SetTitils(title); + } + + void Window::Show() + { + ASSERT(m_Impl); + m_Impl->Show(); + } + + void Window::Hide() + { + ASSERT(m_Impl); + m_Impl->Hide(); + } + + void Window::SwapRenderBuffer() + { + ASSERT(m_Impl); + m_Impl->SwapRenderBuffer(); + } + + void Window::Clear(const AEGraphics::Color& col /*= AEGraphics::Color::Black*/) + { + ASSERT(m_Impl); + glClearColor(col.r, col.g, col.b, col.a); + } + + //void Window::Clear(const Math::Recti& quad, const AEGraphics::Color& col /*= AEGraphics::Color::Black*/) + //{ + // ASSERT(m_Impl); + + //} + + void Window::Draw(const AEGraphics::Drawable* texture, const AEGraphics::RenderState& state) + { + ASSERT(m_Impl); + + } +/* + void Window::Draw(const AEGraphics::Drawable* texture, const Math::Recti& quad, const AEGraphics::RenderState& state) + { + ASSERT(m_Impl); + + } +*/ + } +} diff --git a/source/modules/asura-core/Window/Window.h b/source/modules/asura-core/Window/Window.h new file mode 100644 index 0000000..f5498c1 --- /dev/null +++ b/source/modules/asura-core/Window/Window.h @@ -0,0 +1,138 @@ +#ifndef _ASURA_ENGINE_WINDOW_H_ +#define _ASURA_ENGINE_WINDOW_H_ + +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Math/Vector2.hpp> +#include <asura-utils/Singleton.hpp> + +#include "../Graphics/Image.h" +#include "../Graphics/RenderState.h" +#include "../Graphics/RenderTarget.h" + +namespace_begin(AsuraEngine) +namespace_begin(Window) + +class WindowImpl; + +/// +/// SDLģһЩõġ +/// +enum WindowFlag +{ + WINDOW_FULLSCREEN = 1 << 1, ///< fullscreen window + WINDOW_OPENGL = 1 << 2, ///< window usable with OpenGL context + WINDOW_SHOWN = 1 << 3, ///< window is visible + WINDOW_HIDDEN = 1 << 4, ///< window is not visible + WINDOW_BORDERLESS = 1 << 5, ///< no window decoration + WINDOW_RESIZABLE = 1 << 6, ///< window can be resized + WINDOW_MINIMIZED = 1 << 7, ///< window is minimized + WINDOW_MAXIMIZED = 1 << 8, ///< window is maximized + WINDOW_INPUT_GRABBED = 1 << 9, ///< window has grabbed input focus + WINDOW_INPUT_FOCUS = 1 << 10, ///< window has input focus + WINDOW_MOUSE_FOCUS = 1 << 11, ///< window has mouse focus + WINDOW_ALLOW_HIGHDPI = 1 << 12, ///< window should be created in high-DPI mode if supported. + ///< On macOS NSHighResolutionCapable must be set true in the + ///< application's Info.plist for this to have any effect. + WINDOW_MOUSE_CAPTURE = 1 << 13, ///< window has mouse captured (unrelated to INPUT_GRABBED) + WINDOW_ALWAYS_ON_TOP = 1 << 14, ///< window should always be above others +}; + +/// Windowʼ +struct WindowConfig +{ + uint width, height; ///< ߴ + int x, y; ///< ڳʼ + std::string title; ///< + bool vsync; ///< ֱͬ + AEImage::ImageData* icon; ///< ͼ + bool show; ///< Ƿʾ + int flag; ///< ڱ +}; + +/// +/// ϷĵڣrunnerֻҪһڡͬĿͻʵִ˽ӿڲֶעᵽlua༭ +/// ᵼ࣬ӵ༭ⴰϡ +/// +class Window ASURA_FINAL + : public AEScripting::Portable<Window, AEGraphics::RenderTarget> + , public Singleton<Window> +{ +public: + + /// ϷʱĴΨһģ༭õࡣ + LUAX_DECL_SINGLETON(Window); + + Window(); + ~Window(); + + /// ڡ + bool Init(const WindowConfig& config); + void Exit(); + + void SetSize(uint width, uint height); + void SetPosition(int x, int y); + void SetTitle(const std::string& title); + void SetIcon(AEImage::ImageData* imgData); + + void Show(); + void Hide(); + + /// ǿ˫ĴڣҪչʾǰ̨ + void SwapRenderBuffer(); + + void Clear(const AEGraphics::Color& col = AEGraphics::Color::Black) override; + void Clear(const Math::Recti& quad, const AEGraphics::Color& col = AEGraphics::Color::Black) override; + + void Draw(const AEGraphics::Drawable* texture, const AEGraphics::RenderState& state) override; + void Draw(const AEGraphics::Drawable* texture, const Math::Recti& quad, const AEGraphics::RenderState& state) override; + +private: + + WindowImpl* m_Impl; + +luaxport: + + LUAX_DECL_ENUM(WindowFlag, 0); + + LUAX_DECL_METHOD(_Init); + LUAX_DECL_METHOD(_Exit); + LUAX_DECL_METHOD(_Show); + LUAX_DECL_METHOD(_Hide); + LUAX_DECL_METHOD(_SetSize); + LUAX_DECL_METHOD(_SetPosition); + LUAX_DECL_METHOD(_SetTitle); + LUAX_DECL_METHOD(_SetIcon); + LUAX_DECL_METHOD(_SwapRenderBuffer); + LUAX_DECL_METHOD(_Clear); + LUAX_DECL_METHOD(_Draw); + +}; + +using RenderWindow = Window; + +ASURA_ABSTRACT class WindowImpl +{ +public: + + WindowImpl() {}; + virtual ~WindowImpl() {}; + + virtual bool Init(const WindowConfig& config); + + virtual void SetSize(uint width, uint height) = 0; + virtual void SetPosition(int x, int y) = 0; + virtual void SetTitils(const std::string& title) = 0; + + virtual void Show() = 0; + virtual void Hide() = 0; + + virtual void SwapRenderBuffer() = 0; + +}; + +namespace_end +namespace_end + +namespace AEWindow = AsuraEngine::Window; + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/thread_impl_sdl.cpp b/source/modules/asura-core/Window/WindowImplGlew.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-utils/threading/thread_impl_sdl.cpp +++ b/source/modules/asura-core/Window/WindowImplGlew.cpp diff --git a/source/modules/asura-utils/threading/thread_impl_sdl.h b/source/modules/asura-core/Window/WindowImplGlew.h index e69de29..e69de29 100644 --- a/source/modules/asura-utils/threading/thread_impl_sdl.h +++ b/source/modules/asura-core/Window/WindowImplGlew.h diff --git a/source/modules/asura-utils/threading/thread_impl_std.cpp b/source/modules/asura-core/Window/WindowImplGlut.h index e69de29..e69de29 100644 --- a/source/modules/asura-utils/threading/thread_impl_std.cpp +++ b/source/modules/asura-core/Window/WindowImplGlut.h diff --git a/source/modules/asura-core/window/window_impl_sdl.cpp b/source/modules/asura-core/Window/WindowImplSDL.cpp index 59562a4..3cbad70 100644 --- a/source/modules/asura-core/window/window_impl_sdl.cpp +++ b/source/modules/asura-core/Window/WindowImplSDL.cpp @@ -1,12 +1,12 @@ -#include "../core_config.h" +#include "../CoreConfig.h" #if ASURA_WINDOW_SDL #include <SDL2/SDL.h> -#include <asura-utils/exceptions/exception.h> +#include <asura-utils/Exceptions/Exception.h> -#include "window_impl_sdl.h" +#include "WindowImplSDL.h" using namespace AEGraphics; using namespace AEImage; diff --git a/source/modules/asura-core/window/window_impl_sdl.h b/source/modules/asura-core/Window/WindowImplSDL.h index 20f5c95..5971351 100644 --- a/source/modules/asura-core/window/window_impl_sdl.h +++ b/source/modules/asura-core/Window/WindowImplSDL.h @@ -1,13 +1,13 @@ -#ifndef __ASURA_WINDOW_SDL_H_ -#define __ASURA_WINDOW_SDL_H_ +#ifndef _ASURA_WINDOW_SDL_H_ +#define _ASURA_WINDOW_SDL_H_ -#include "../core_config.h" +#include "../CoreConfig.h" #if ASURA_WINDOW_SDL #include <SDL2/SDL.h> -#include "window.h" +#include "Window.h" namespace_begin(AsuraEngine) namespace_begin(Window) diff --git a/source/modules/asura-core/Window/WinodwImplGlut.cpp b/source/modules/asura-core/Window/WinodwImplGlut.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/Window/WinodwImplGlut.cpp diff --git a/source/modules/asura-core/Window/binding/_window.cpp b/source/modules/asura-core/Window/binding/_window.cpp new file mode 100644 index 0000000..1e14a3a --- /dev/null +++ b/source/modules/asura-core/Window/binding/_window.cpp @@ -0,0 +1,179 @@ +#include "../../Image/ImageData.h" + +#include "../Window.h" + +using namespace std; +using namespace AEGraphics; +using namespace AEImage; + +namespace_begin(AsuraEngine) +namespace_begin(Window) + + LUAX_REGISTRY(Window) + { + LUAX_REGISTER_METHODS(state, + { "Init", _Init }, + { "Exit", _Exit }, + { "Show", _Show }, + { "Hide", _Hide }, + { "SetSize", _SetSize }, + { "SetPosition", _SetPosition }, + { "SetTitle", _SetTitle }, + { "SetIcon", _SetIcon }, + { "SwapRenderBuffer", _SwapRenderBuffer }, + { "Clear", _Clear }, + { "Draw", _Draw } + ); + } + + LUAX_POSTPROCESS(Window) + { + LUAX_REGISTER_ENUM(state, "EWindowFlag", + { "FULLSCREEN", WINDOW_FULLSCREEN }, + { "OPENGL", WINDOW_OPENGL }, + { "SHOWN", WINDOW_SHOWN }, + { "HIDDEN", WINDOW_HIDDEN }, + { "BORDERLESS", WINDOW_BORDERLESS }, + { "RESIZABLE", WINDOW_RESIZABLE }, + { "MINIMIZED", WINDOW_MINIMIZED }, + { "MAXIMIZED", WINDOW_MAXIMIZED }, + { "INPUT_GRABBED", WINDOW_INPUT_GRABBED }, + { "INPUT_FOCUS", WINDOW_INPUT_FOCUS }, + { "MOUSE_FOCUS", WINDOW_MOUSE_FOCUS }, + { "ALLOW_HIGHDPI", WINDOW_ALLOW_HIGHDPI }, + { "MOUSE_CAPTURE", WINDOW_MOUSE_CAPTURE }, + { "ALWAYS_ON_TOP", WINDOW_ALWAYS_ON_TOP } + ); + + } + + // Window.Init(config_table) + LUAX_IMPL_METHOD(Window, _Init) + { + LUAX_PREPARE(L, Window); + + WindowConfig config; + + if (!state.IsType(1, LUA_TTABLE)) + return state.ErrorType(1, "window config table"); + + config.width = state.GetField(1, "width", 0); + config.height = state.GetField(1, "height", 0); + config.x = state.GetField(1, "x", 0); + config.y = state.GetField(1, "y", 0); + config.flag = state.GetField(1, "flag", WINDOW_OPENGL); + config.title = state.GetField(1, "title", ""); + config.vsync = state.GetField(1, "vsync", true); + config.show = state.GetField(1, "show", true); + + // try set window icon + state.GetField(1, "icon"); + if (state.IsType(1, LUA_TUSERDATA)) + { + ImageData* data = state.CheckUserdata<ImageData>(-1); + if (data) + { + data->Lock(); + config.icon = data; + Window::Get()->Init(config); + data->Unlock(); + return 0; + } + } + else + state.Pop(); + + Window::Get()->Init(config); + + return 0; + } + + // Window.Exit() + LUAX_IMPL_METHOD(Window, _Exit) + { + LUAX_PREPARE(L, Window); + Window::Get()->Exit(); + return 0; + } + + // Window.Show() + LUAX_IMPL_METHOD(Window, _Show) + { + LUAX_PREPARE(L, Window); + Window::Get()->Show(); + return 0; + } + + // Window.Hide() + LUAX_IMPL_METHOD(Window, _Hide) + { + LUAX_PREPARE(L, Window); + Window::Get()->Hide(); + return 0; + } + + // Window.SetSize(w, h) + LUAX_IMPL_METHOD(Window, _SetSize) + { + LUAX_PREPARE(L, Window); + uint w = state.CheckValue<uint>(1); + uint h = state.CheckValue<uint>(2); + Window::Get()->SetSize(w, h); + return 0; + } + + // Window.SetPosition(x, y) + LUAX_IMPL_METHOD(Window, _SetPosition) + { + LUAX_PREPARE(L, Window); + int x = state.CheckValue<int>(1); + int y = state.CheckValue<int>(2); + Window::Get()->SetPosition(x, y); + return 0; + } + + // Window.SetTitle(title) + LUAX_IMPL_METHOD(Window, _SetTitle) + { + LUAX_PREPARE(L, Window); + std::string title = state.CheckValue<string>(1); + Window::Get()->SetTitle(title); + return 0; + } + + // Window.SetIcon(imageData) + LUAX_IMPL_METHOD(Window, _SetIcon) + { + LUAX_PREPARE(L, Window); + ImageData* imgData = state.CheckUserdata<ImageData>(1); + imgData->Lock(); + Window::Get()->SetIcon(imgData); + imgData->Unlock(); + return 0; + } + + // Window.SwapRenderBuffer() + LUAX_IMPL_METHOD(Window, _SwapRenderBuffer) + { + LUAX_PREPARE(L, Window); + Window::Get()->SwapRenderBuffer(); + return 0; + } + + // Window.Clear() + LUAX_IMPL_METHOD(Window, _Clear) + { + LUAX_PREPARE(L, Window); + Window::Get()->Clear(); + return 0; + } + + // Window.Draw() + LUAX_IMPL_METHOD(Window, _Draw) + { + LUAX_PREPARE(L, Window); + return 0; + } + + } +}
\ No newline at end of file diff --git a/source/modules/asura-core/application.h b/source/modules/asura-core/application.h index 62eefe7..ea5faa7 100644 --- a/source/modules/asura-core/application.h +++ b/source/modules/asura-core/application.h @@ -1,18 +1,16 @@ -#ifndef __ASURA_ENGINE_APPLICATION_H__ -#define __ASURA_ENGINE_APPLICATION_H__ +#ifndef _ASURA_ENGINE_APPLICATION_H_ +#define _ASURA_ENGINE_APPLICATION_H_ -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/module.h> -#include <asura-utils/classes.h> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Module.h> +#include <asura-utils/Classes.h> #include <queue> -#include "core_config.h" +#include "CoreConfig.h" namespace_begin(AsuraEngine) -/// /// ģ -/// enum SubModules { ASURA_MODULE_NONE = 0X00000000U, diff --git a/source/modules/asura-core/core_module.h b/source/modules/asura-core/core_module.h deleted file mode 100644 index 443aea4..0000000 --- a/source/modules/asura-core/core_module.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __ASURA_CORE_MODULE_H__ -#define __ASURA_CORE_MODULE_H__ - -#include <asura-utils/module.h> - -#include "graphics/image.h" -#include "graphics/texture.h" - -#include "window/window.h" - -#include "threading/thread_ex.h" - -namespace AsuraEngine -{ - - class CoreModule : public Module - { - public: - - void Initialize(Luax::LuaxState& state) override; - - void Finalize(Luax::LuaxState& state) override; - - }; - -} - -#endif
\ No newline at end of file diff --git a/source/modules/asura-core/font/string.hpp b/source/modules/asura-core/font/string.hpp index 2c6c845..13a8b2d 100644 --- a/source/modules/asura-core/font/string.hpp +++ b/source/modules/asura-core/font/string.hpp @@ -1,5 +1,5 @@ -//#ifndef __ASURA_ENGINE_STRING_H__ -//#define __ASURA_ENGINE_STRING_H__ +//#ifndef _ASURA_ENGINE_STRING_H_ +//#define _ASURA_ENGINE_STRING_H_ // //#include <asura-utils/type.h> // @@ -587,7 +587,7 @@ // //////////////////////////////////////////////////////////// // String operator +(const String& left, const String& right); // -// #include "String.inl" +// #include "String.inc" // // } //} diff --git a/source/modules/asura-core/font/ttf.h b/source/modules/asura-core/font/ttf.h index 840b63e..b83cf76 100644 --- a/source/modules/asura-core/font/ttf.h +++ b/source/modules/asura-core/font/ttf.h @@ -1,5 +1,5 @@ -#ifndef __ASURA_TTF_H__ -#define __ASURA_TTF_H__ +#ifndef _ASURA_TTF_H_ +#define _ASURA_TTF_H_ namespace AsuraEngine { diff --git a/source/modules/asura-core/font/utf.hpp b/source/modules/asura-core/font/utf.hpp index 2e04ee4..59f62ed 100644 --- a/source/modules/asura-core/font/utf.hpp +++ b/source/modules/asura-core/font/utf.hpp @@ -1,5 +1,5 @@ -#ifndef __ASURA_UTF_HPP__ -#define __ASURA_UTF_HPP__ +#ifndef _ASURA_UTF_HPP_ +#define _ASURA_UTF_HPP_ //////////////////////////////////////////////////////////// // Headers @@ -705,7 +705,7 @@ namespace AsuraEngine static Out EncodeWide(Uint32 codepoint, Out output, wchar_t replacement = 0); }; -#include "Utf.inl" +#include "Utf.inc" // Make typedefs to get rid of the template syntax typedef Utf<8> Utf8; diff --git a/source/modules/asura-core/graphics/binding/_canvas.cpp b/source/modules/asura-core/graphics/binding/_canvas.cpp index 6dda773..44841f5 100644 --- a/source/modules/asura-core/graphics/binding/_canvas.cpp +++ b/source/modules/asura-core/graphics/binding/_canvas.cpp @@ -1,4 +1,4 @@ -#include "../canvas.h" +#include "../Canvas.h" using namespace std; diff --git a/source/modules/asura-core/graphics/binding/_color.cpp b/source/modules/asura-core/graphics/binding/_color.cpp index c990d8b..008d9c2 100644 --- a/source/modules/asura-core/graphics/binding/_color.cpp +++ b/source/modules/asura-core/graphics/binding/_color.cpp @@ -1,4 +1,4 @@ -#include "../color.h" +#include "../Color.h" using namespace std; using namespace Luax; diff --git a/source/modules/asura-core/graphics/binding/_color32.cpp b/source/modules/asura-core/graphics/binding/_color32.cpp index 96c63af..7613361 100644 --- a/source/modules/asura-core/graphics/binding/_color32.cpp +++ b/source/modules/asura-core/graphics/binding/_color32.cpp @@ -1,4 +1,4 @@ -#include "../color32.h" +#include "../Color32.h" using namespace std; diff --git a/source/modules/asura-core/graphics/binding/_gfx_device.cpp b/source/modules/asura-core/graphics/binding/_gfx_device.cpp index 60a0b0b..f6c2004 100644 --- a/source/modules/asura-core/graphics/binding/_gfx_device.cpp +++ b/source/modules/asura-core/graphics/binding/_gfx_device.cpp @@ -1,4 +1,4 @@ -#include "../gfx_device.h" +#include "../GfxDevice.h" using namespace std; using namespace Luax; diff --git a/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp b/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp index 479901e..8c39a59 100644 --- a/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp +++ b/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp @@ -1,7 +1,7 @@ #include <stdlib.h> #include "../image.h" -#include "../gpu_buffer.h" +#include "../GPUBuffer.h" using namespace std; using namespace Luax; diff --git a/source/modules/asura-core/graphics/binding/_index_buffer.cpp b/source/modules/asura-core/graphics/binding/_index_buffer.cpp index eb81699..151dc98 100644 --- a/source/modules/asura-core/graphics/binding/_index_buffer.cpp +++ b/source/modules/asura-core/graphics/binding/_index_buffer.cpp @@ -1,4 +1,4 @@ -#include "../index_buffer.h" +#include "../IndexBuffer.h" using namespace std; using namespace Luax; diff --git a/source/modules/asura-core/graphics/binding/_sprite_batch.cpp b/source/modules/asura-core/graphics/binding/_sprite_batch.cpp index 7795d26..6b7d25c 100644 --- a/source/modules/asura-core/graphics/binding/_sprite_batch.cpp +++ b/source/modules/asura-core/graphics/binding/_sprite_batch.cpp @@ -1,4 +1,4 @@ -#include "../sprite_batch.h" +#include "../SpriteBatch.h" using namespace std; diff --git a/source/modules/asura-core/graphics/binding/_vertex_buffer.cpp b/source/modules/asura-core/graphics/binding/_vertex_buffer.cpp index b181df3..8ed487b 100644 --- a/source/modules/asura-core/graphics/binding/_vertex_buffer.cpp +++ b/source/modules/asura-core/graphics/binding/_vertex_buffer.cpp @@ -1,4 +1,4 @@ -#include "../vertex_buffer.h" +#include "../VertexBuffer.h" using namespace std; using namespace Luax; diff --git a/source/modules/asura-core/graphics/blend_mode.h b/source/modules/asura-core/graphics/blend_mode.h deleted file mode 100644 index 73e1a41..0000000 --- a/source/modules/asura-core/graphics/blend_mode.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __ASURA_ENGINE_BLEND_MODE_H__ -#define __ASURA_ENGINE_BLEND_MODE_H__ - -#include <asura-utils/classes.h> - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - -enum BlendMode -{ - -}; - -namespace_end -namespace_end - -#endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/canvas.h b/source/modules/asura-core/graphics/canvas.h index bbd098a..0ec55bc 100644 --- a/source/modules/asura-core/graphics/canvas.h +++ b/source/modules/asura-core/graphics/canvas.h @@ -1,15 +1,15 @@ -#ifndef __ASURA_ENGINE_CANVAS_H__ -#define __ASURA_ENGINE_CANVAS_H__ - -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/math/rect.hpp> -#include <asura-utils/math/vector2.hpp> -#include <asura-utils/exceptions/exception.h> - -#include "gfx_device.h" -#include "texture.h" -#include "render_target.h" -#include "render_state.h" +#ifndef _ASURA_ENGINE_CANVAS_H_ +#define _ASURA_ENGINE_CANVAS_H_ + +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Math/Rect.hpp> +#include <asura-utils/Math/Vector2.hpp> +#include <asura-utils/Exceptions/Exception.h> + +#include "GfxDevice.h" +#include "Texture.h" +#include "RenderTarget.h" +#include "RenderState.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/graphics/color.cpp b/source/modules/asura-core/graphics/color.cpp index 47e039f..5a66291 100644 --- a/source/modules/asura-core/graphics/color.cpp +++ b/source/modules/asura-core/graphics/color.cpp @@ -1,5 +1,5 @@ -#include "color.h" -#include "color32.h" +#include "Color.h" +#include "Color32.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/graphics/color.h b/source/modules/asura-core/graphics/color.h index 99a9b00..a16f17d 100644 --- a/source/modules/asura-core/graphics/color.h +++ b/source/modules/asura-core/graphics/color.h @@ -1,10 +1,10 @@ -#ifndef __ASURA_ENGINE_COLOR_H__ -#define __ASURA_ENGINE_COLOR_H__ +#ifndef _ASURA_ENGINE_COLOR_H_ +#define _ASURA_ENGINE_COLOR_H_ -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/classes.h> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Classes.h> -#include "../core_config.h" +#include "../CoreConfig.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/graphics/color32.cpp b/source/modules/asura-core/graphics/color32.cpp index 11239c8..f1f0b74 100644 --- a/source/modules/asura-core/graphics/color32.cpp +++ b/source/modules/asura-core/graphics/color32.cpp @@ -1,5 +1,5 @@ -#include "color.h" -#include "color32.h" +#include "Color.h" +#include "Color32.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/graphics/color32.h b/source/modules/asura-core/graphics/color32.h index 52405e9..aa445fe 100644 --- a/source/modules/asura-core/graphics/color32.h +++ b/source/modules/asura-core/graphics/color32.h @@ -1,10 +1,10 @@ -#ifndef __ASURA_ENGINE_COLOR32_H__ -#define __ASURA_ENGINE_COLOR32_H__ +#ifndef _ASURA_ENGINE_COLOR32_H__ +#define _ASURA_ENGINE_COLOR32_H__ -#include <asura-utils/classes.h> -#include <asura-utils/scripting/portable.hpp> +#include <asura-utils/Classes.h> +#include <asura-utils/Scripting/Portable.hpp> -#include "../core_config.h" +#include "../CoreConfig.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index 32fa870..d2b2ec9 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -1,10 +1,10 @@ -#include <asura-utils/exceptions/exception.h> +#include <asura-utils/Exceptions/Exception.h> -#include "../core_config.h" +#include "../CoreConfig.h" -#include "shader.h" -#include "image.h" -#include "gfx_device.h" +#include "Shader.h" +#include "Image.h" +#include "GfxDevice.h" using namespace AEIO; using namespace AEImage; diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h index 72f1281..5cbfe23 100644 --- a/source/modules/asura-core/graphics/image.h +++ b/source/modules/asura-core/graphics/image.h @@ -1,23 +1,23 @@ -#ifndef __ASURA_ENGINE_IMAGE_H__ -#define __ASURA_ENGINE_IMAGE_H__ +#ifndef _ASURA_ENGINE_IMAGE_H_ +#define _ASURA_ENGINE_IMAGE_H_ // asura modules -#include <asura-utils/math/rect.hpp> -#include <asura-utils/math/vector2.hpp> -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/io/renewable.h> -#include <asura-utils/stringmap.hpp> -#include <asura-utils/manager.hpp> +#include <asura-utils/Math/Rect.hpp> +#include <asura-utils/Math/Vector2.hpp> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/IO/Renewable.h> +#include <asura-utils/Stringmap.hpp> +#include <asura-utils/Manager.hpp> // module -#include "../image/image_data.h" +#include "../Image/ImageData.h" // folder -#include "color.h" -#include "color32.h" -#include "render_state.h" -#include "gpu_buffer.h" -#include "texture.h" +#include "Color.h" +#include "Color32.h" +#include "RenderState.h" +#include "GPUBuffer.h" +#include "Texture.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/graphics/mesh2d.h b/source/modules/asura-core/graphics/mesh2d.h index d2d7d3b..1546765 100644 --- a/source/modules/asura-core/graphics/mesh2d.h +++ b/source/modules/asura-core/graphics/mesh2d.h @@ -1,20 +1,20 @@ -#ifndef __ASURA_ENGINE_MESH2D_H__ -#define __ASURA_ENGINE_MESH2D_H__ +#ifndef _ASURA_ENGINE_MESH2D_H__ +#define _ASURA_ENGINE_MESH2D_H__ // cpp #include <vector> // asura modules -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/math/vector2.hpp> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Math/Vector2.hpp> // module -#include "../mesh/mesh2d_data.h" +#include "../Mesh/Mesh2dData.h" // folder -#include "color.h" -#include "vertex_buffer.h" -#include "index_buffer.h" +#include "Color.h" +#include "VertexBuffer.h" +#include "IndexBuffer.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp index 74bf7a8..30e0161 100644 --- a/source/modules/asura-core/graphics/shader.cpp +++ b/source/modules/asura-core/graphics/shader.cpp @@ -1,7 +1,7 @@ -#include <asura-utils/exceptions/exception.h> +#include <asura-utils/Exceptions/Exception.h> -#include "gfx_device.h" -#include "shader.h" +#include "GfxDevice.h" +#include "Shader.h" using namespace std; diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h index c535570..c96b99f 100644 --- a/source/modules/asura-core/graphics/shader.h +++ b/source/modules/asura-core/graphics/shader.h @@ -1,24 +1,24 @@ -#ifndef __ASURA_ENGINE_SHADER_H__ -#define __ASURA_ENGINE_SHADER_H__ +#ifndef _ASURA_ENGINE_SHADER_H_ +#define _ASURA_ENGINE_SHADER_H_ #include <map> #include <string> -#include <asura-utils/exceptions/exception.h> -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/io/renewable.h> -#include <asura-utils/math/vector2.hpp> -#include <asura-utils/math/vector3.hpp> -#include <asura-utils/math/vector4.h> -#include <asura-utils/math/matrix44.h> -#include <asura-utils/stringmap.hpp> -#include <asura-utils/manager.hpp> - -#include "gfx_device.h" -#include "color.h" -#include "texture.h" -#include "vertex_buffer.h" -#include "index_buffer.h" +#include <asura-utils/Exceptions/Exception.h> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/IO/Renewable.h> +#include <asura-utils/Math/Vector2.hpp> +#include <asura-utils/Math/vector3.hpp> +#include <asura-utils/Math/vector4.h> +#include <asura-utils/Math/matrix44.h> +#include <asura-utils/Stringmap.hpp> +#include <asura-utils/Manager.hpp> + +#include "GfxDevice.h" +#include "Color.h" +#include "Texture.h" +#include "VertexBuffer.h" +#include "IndexBuffer.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/graphics/texture.cpp b/source/modules/asura-core/graphics/texture.cpp index 42e3851..bae0f7c 100644 --- a/source/modules/asura-core/graphics/texture.cpp +++ b/source/modules/asura-core/graphics/texture.cpp @@ -1,4 +1,4 @@ -#include <asura-utils/exceptions/exception.h> +#include <asura-utils/Exceptions/Exception.h> #include "Texture.h" diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h index 458e35a..7d37c31 100644 --- a/source/modules/asura-core/graphics/texture.h +++ b/source/modules/asura-core/graphics/texture.h @@ -1,13 +1,13 @@ -#ifndef __ASURA_TEXTURE_H__ -#define __ASURA_TEXTURE_H__ +#ifndef _ASURA_TEXTURE_H_ +#define _ASURA_TEXTURE_H_ -#include <asura-utils/math/vector2.hpp> -#include <asura-utils/math/rect.hpp> +#include <asura-utils/Math/Vector2.hpp> +#include <asura-utils/Math/Rect.hpp> -#include "../core_config.h" +#include "../CoreConfig.h" -#include "render_state.h" -#include "gfx_device.h" +#include "RenderState.h" +#include "GfxDevice.h" namespace_begin(AsuraEngine) namespace_begin(Graphics) diff --git a/source/modules/asura-core/image/binding/_image_data.cpp b/source/modules/asura-core/image/binding/_image_data.cpp index 93e63ce..77f3a96 100644 --- a/source/modules/asura-core/image/binding/_image_data.cpp +++ b/source/modules/asura-core/image/binding/_image_data.cpp @@ -1,7 +1,7 @@ -#include <asura-utils/threading/thread.h> -#include <asura-utils/io/data_buffer.h> +#include <asura-utils/Threads/Thread.h> +#include <asura-utils/IO/DataBuffer.h> -#include "../image_data.h" +#include "../ImageData.h" using namespace std; using namespace AEThreading; diff --git a/source/modules/asura-core/image/binding/_image_decode_task.cpp b/source/modules/asura-core/image/binding/_image_decode_task.cpp index 0181628..3c8ed4b 100644 --- a/source/modules/asura-core/image/binding/_image_decode_task.cpp +++ b/source/modules/asura-core/image/binding/_image_decode_task.cpp @@ -1,18 +1,19 @@ -#include "../image_decode_task.h" +#include "../ImageDecodeTask.h" using namespace std; namespace_begin(AsuraEngine) namespace_begin(Image) + LUAX_REGISTRY(ImageDecodeTask) - { +{ - } +} - LUAX_POSTPROCESS(ImageDecodeTask) - { +LUAX_POSTPROCESS(ImageDecodeTask) +{ - } +} - } +} } diff --git a/source/modules/asura-core/input/button.h b/source/modules/asura-core/input/button.h index 78f9b6d..5c3c0de 100644 --- a/source/modules/asura-core/input/button.h +++ b/source/modules/asura-core/input/button.h @@ -1,7 +1,7 @@ #ifndef __BUTTON_H__ #define __BUTTON_H__ -#include <asura-utils/classes.h> +#include <asura-utils/Classes.h> namespace_begin(AsuraEngine) namespace_begin(Input) diff --git a/source/modules/asura-core/threading/channel.h b/source/modules/asura-core/threading/channel.h deleted file mode 100644 index ede43e4..0000000 --- a/source/modules/asura-core/threading/channel.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __ASURA_THREAD_CHANNEL_H__ -#define __ASURA_THREAD_CHANNEL_H__ - -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/classes.h> - -namespace_begin(AsuraEngine) -namespace_begin(Threading) - -class Channel -{ - -}; - -namespace_end -namespace_end - -#endif
\ No newline at end of file diff --git a/source/modules/asura-core/type.h b/source/modules/asura-core/type.h index 88848d5..39880e2 100644 --- a/source/modules/asura-core/type.h +++ b/source/modules/asura-core/type.h @@ -1,5 +1,5 @@ -#ifndef __ASURA_ENGINE_TYPE_H__ -#define __ASURA_ENGINE_TYPE_H__ +#ifndef _ASURA_ENGINE_TYPE_H_ +#define _ASURA_ENGINE_TYPE_H_ #include <stdint.h> diff --git a/source/modules/asura-core/window/binding/_window.cpp b/source/modules/asura-core/window/binding/_window.cpp index 7119cd2..1e14a3a 100644 --- a/source/modules/asura-core/window/binding/_window.cpp +++ b/source/modules/asura-core/window/binding/_window.cpp @@ -1,6 +1,6 @@ -#include "../../image/image_data.h" +#include "../../Image/ImageData.h" -#include "../window.h" +#include "../Window.h" using namespace std; using namespace AEGraphics; diff --git a/source/modules/asura-core/window/window.cpp b/source/modules/asura-core/window/window.cpp index bbcb949..adba7c9 100644 --- a/source/modules/asura-core/window/window.cpp +++ b/source/modules/asura-core/window/window.cpp @@ -1,10 +1,10 @@ -#include <asura-utils/exceptions/exception.h> +#include <asura-utils/Exceptions/Exception.h> #include "window.h" -#include "window_impl_sdl.h" -#include "window_impl_glew.h" -#include "window_impl_glut.h" +#include "WindowImplSDL.h" +#include "WindowImplGlew.h" +#include "WindowImplGlut.h" namespace_begin(AsuraEngine) namespace_begin(Window) diff --git a/source/modules/asura-core/window/window.h b/source/modules/asura-core/window/window.h index 872c40f..f5498c1 100644 --- a/source/modules/asura-core/window/window.h +++ b/source/modules/asura-core/window/window.h @@ -1,13 +1,13 @@ -#ifndef __ASURA_ENGINE_WINDOW_H__ -#define __ASURA_ENGINE_WINDOW_H__ +#ifndef _ASURA_ENGINE_WINDOW_H_ +#define _ASURA_ENGINE_WINDOW_H_ -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/math/vector2.hpp> -#include <asura-utils/singleton.hpp> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Math/Vector2.hpp> +#include <asura-utils/Singleton.hpp> -#include "../graphics/image.h" -#include "../graphics/render_state.h" -#include "../graphics/render_target.h" +#include "../Graphics/Image.h" +#include "../Graphics/RenderState.h" +#include "../Graphics/RenderTarget.h" namespace_begin(AsuraEngine) namespace_begin(Window) diff --git a/source/modules/asura-fmod/Audio/Source.h b/source/modules/asura-fmod/Audio/Source.h new file mode 100644 index 0000000..4585415 --- /dev/null +++ b/source/modules/asura-fmod/Audio/Source.h @@ -0,0 +1,20 @@ +#ifndef __ASURA_FMOD_SOURCE_H__ +#define __ASURA_FMOD_SOURCE_H__ + +namespace AsruaEngine +{ + namespace Audio + { + + /// + /// fmod + /// + class Source + { + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-fmod/fmod_module.h b/source/modules/asura-fmod/FMODModule.h index 67b8618..67b8618 100644 --- a/source/modules/asura-fmod/fmod_module.h +++ b/source/modules/asura-fmod/FMODModule.h diff --git a/source/modules/asura-json/Json/Json.cpp b/source/modules/asura-json/Json/Json.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-json/Json/Json.cpp diff --git a/source/modules/asura-json/Json/Json.h b/source/modules/asura-json/Json/Json.h new file mode 100644 index 0000000..2bdaf53 --- /dev/null +++ b/source/modules/asura-json/Json/Json.h @@ -0,0 +1,14 @@ +#ifndef __ASURA_JSON_H__ +#define __ASURA_JSON_H__ + +namespace AsuraEngine +{ + namespace Json + { + + + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-json/JsonModule.cpp b/source/modules/asura-json/JsonModule.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-json/JsonModule.cpp diff --git a/source/modules/asura-json/JsonModule.h b/source/modules/asura-json/JsonModule.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-json/JsonModule.h diff --git a/source/modules/asura-network/NetworkModule.h b/source/modules/asura-network/NetworkModule.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-network/NetworkModule.h diff --git a/source/modules/asura-openal/Audio/Audio.cpp b/source/modules/asura-openal/Audio/Audio.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-openal/Audio/Audio.cpp diff --git a/source/modules/asura-openal/Audio/Audio.h b/source/modules/asura-openal/Audio/Audio.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-openal/Audio/Audio.h diff --git a/source/modules/asura-openal/Audio/MPG123Decoder.cpp b/source/modules/asura-openal/Audio/MPG123Decoder.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-openal/Audio/MPG123Decoder.cpp diff --git a/source/modules/asura-openal/Audio/MPG123Decoder.h b/source/modules/asura-openal/Audio/MPG123Decoder.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-openal/Audio/MPG123Decoder.h diff --git a/source/modules/asura-openal/Audio/Sound.cpp b/source/modules/asura-openal/Audio/Sound.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-openal/Audio/Sound.cpp diff --git a/source/modules/asura-openal/Audio/Sound.h b/source/modules/asura-openal/Audio/Sound.h new file mode 100644 index 0000000..ab309f3 --- /dev/null +++ b/source/modules/asura-openal/Audio/Sound.h @@ -0,0 +1,31 @@ +#ifndef __ASURA_ENGINE_SOUND_H__ +#define __ASURA_ENGINE_SOUND_H__ + +#include <asura-utils/Scripting/Portable.hpp> + +namespace AsuraEngine +{ + namespace Audio + { + + /// + /// Ƶļ + /// + class Sound ASURA_FINAL + : public AEScripting::Portable<Sound> + { + public: + + Sound(); + ~Sound(); + + private: + + + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-openal/Audio/SoundData.cpp b/source/modules/asura-openal/Audio/SoundData.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-openal/Audio/SoundData.cpp diff --git a/source/modules/asura-openal/Audio/SoundData.h b/source/modules/asura-openal/Audio/SoundData.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-openal/Audio/SoundData.h diff --git a/source/modules/asura-openal/Audio/SoundDecodeTask.cpp b/source/modules/asura-openal/Audio/SoundDecodeTask.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-openal/Audio/SoundDecodeTask.cpp diff --git a/source/modules/asura-openal/Audio/SoundDecodeTask.h b/source/modules/asura-openal/Audio/SoundDecodeTask.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-openal/Audio/SoundDecodeTask.h diff --git a/source/modules/asura-openal/Audio/SoundDecoder.cpp b/source/modules/asura-openal/Audio/SoundDecoder.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-openal/Audio/SoundDecoder.cpp diff --git a/source/modules/asura-openal/audio/sound_decoder.h b/source/modules/asura-openal/Audio/SoundDecoder.h index e28a5a9..c149d6f 100644 --- a/source/modules/asura-openal/audio/sound_decoder.h +++ b/source/modules/asura-openal/Audio/SoundDecoder.h @@ -1,7 +1,7 @@ #ifndef __ASURA_ENGINE_SOUND_DECODER_H__ #define __ASURA_ENGINE_SOUND_DECODER_H__ -#include <asura-utils/io/data_buffer.h> +#include <asura-utils/IO/DataBuffer.h> #include "sound.h" diff --git a/source/modules/asura-openal/Audio/Source.cpp b/source/modules/asura-openal/Audio/Source.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-openal/Audio/Source.cpp diff --git a/source/modules/asura-openal/Audio/Source.h b/source/modules/asura-openal/Audio/Source.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-openal/Audio/Source.h diff --git a/source/modules/asura-openal/Audio/VorbisDecoder.cpp b/source/modules/asura-openal/Audio/VorbisDecoder.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-openal/Audio/VorbisDecoder.cpp diff --git a/source/modules/asura-openal/Audio/VorbisDecoder.h b/source/modules/asura-openal/Audio/VorbisDecoder.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-openal/Audio/VorbisDecoder.h diff --git a/source/modules/asura-openal/audio/sound.h b/source/modules/asura-openal/audio/sound.h index 2b0eab0..ab309f3 100644 --- a/source/modules/asura-openal/audio/sound.h +++ b/source/modules/asura-openal/audio/sound.h @@ -1,7 +1,7 @@ #ifndef __ASURA_ENGINE_SOUND_H__ #define __ASURA_ENGINE_SOUND_H__ -#include <asura-utils/scripting/portable.hpp> +#include <asura-utils/Scripting/Portable.hpp> namespace AsuraEngine { diff --git a/source/modules/asura-openal/audio/sound_decode_task.h b/source/modules/asura-openal/audio/sound_decode_task.h deleted file mode 100644 index 9587276..0000000 --- a/source/modules/asura-openal/audio/sound_decode_task.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef __ASURA_OPENAL_SOUND_DECODER_TASK_H__ -#define __ASURA_OPENAL_SOUND_DECODER_TASK_H__ - -#include <asura-utils/threading/thread_task.h> - -namespace AsuraEngine -{ - namespace OpenAL - { - - /// - /// Ƶļ - /// - class SoundDecodeTask : public AEThreading::ThreadTask - { - public: - - private: - - }; - - } -} - -#endif
\ No newline at end of file diff --git a/source/modules/asura-openal/audio/sound_decoder.cpp b/source/modules/asura-openal/audio/sound_decoder.cpp deleted file mode 100644 index ad9f761..0000000 --- a/source/modules/asura-openal/audio/sound_decoder.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __ASURA_ENGINE_SOUND_DECODER_H__ -#define __ASURA_ENGINE_SOUND_DECODER_H__ - -#include "Sound.h" -#include "FileSystem/DataBuffer.h" - -namespace AsuraEngine -{ - namespace Audio - { - - /// - /// Ƶļ - /// - class SoundDecoder - { - public: - - SoundDecoder(); - virtual ~SoundDecoder(); - - virtual Sound* Decode(const Filesystem::DataBuffer* db); - - }; - - } -} - -#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/Classes.h b/source/modules/asura-utils/Classes.h new file mode 100644 index 0000000..d92c3d4 --- /dev/null +++ b/source/modules/asura-utils/Classes.h @@ -0,0 +1,9 @@ +#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 namespace_begin(NAMESPACE) namespace NAMESPACE { +#define namespace_end } + +#endif diff --git a/source/modules/asura-utils/Exceptions/Exception.cpp b/source/modules/asura-utils/Exceptions/Exception.cpp new file mode 100644 index 0000000..5240c49 --- /dev/null +++ b/source/modules/asura-utils/Exceptions/Exception.cpp @@ -0,0 +1,40 @@ +#include "Exception.h" + +#include <cstdarg> +#include <iostream> + +namespace AsuraEngine +{ + + Exception::Exception(const char *fmt, ...) + { + va_list args; + int size_buffer = 256, size_out; + char *buffer; + while (true) + { + buffer = new char[size_buffer]; + memset(buffer, 0, size_buffer); + + va_start(args, fmt); + size_out = vsnprintf(buffer, size_buffer, fmt, args); + va_end(args); + + if (size_out == size_buffer || size_out == -1 || size_out == size_buffer - 1) + size_buffer *= 2; + else if (size_out > size_buffer) + size_buffer = size_out + 2; + else + break; + + delete[] buffer; + } + message = std::string(buffer); + delete[] buffer; + } + + Exception::~Exception() throw() + { + } + +} diff --git a/source/modules/asura-utils/Exceptions/Exception.h b/source/modules/asura-utils/Exceptions/Exception.h new file mode 100644 index 0000000..73c0861 --- /dev/null +++ b/source/modules/asura-utils/Exceptions/Exception.h @@ -0,0 +1,30 @@ +#ifndef _ASURA_ENGINE_EXCEPTION_H_ +#define _ASURA_ENGINE_EXCEPTION_H_ + +#include <string> +#include <exception> + +namespace AsuraEngine +{ + +class Exception : public std::exception +{ +public: + + Exception(const char *fmt, ...); + virtual ~Exception() throw(); + + inline virtual const char *what() const throw() + { + return message.c_str(); + } + +private: + + std::string message; + +}; // Exception + +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/IO/Compressor.cpp b/source/modules/asura-utils/IO/Compressor.cpp new file mode 100644 index 0000000..4202263 --- /dev/null +++ b/source/modules/asura-utils/IO/Compressor.cpp @@ -0,0 +1,11 @@ +#include "Compressor.h" + +namespace AsuraEngine +{ + namespace IO + { + + + + } +}
\ No newline at end of file diff --git a/source/modules/asura-utils/IO/Compressor.h b/source/modules/asura-utils/IO/Compressor.h new file mode 100644 index 0000000..dc25e2a --- /dev/null +++ b/source/modules/asura-utils/IO/Compressor.h @@ -0,0 +1,28 @@ +#ifndef _ASURA_COMPRESSOR_H_ +#define _ASURA_COMPRESSOR_H_ + +#include "../Scripting/Portable.hpp" + +namespace AsuraEngine +{ + namespace IO + { + + class Compressor ASURA_FINAL + : public AEScripting::Portable<Compressor> + { + public: + + LUAX_DECL_SINGLETON(Compressor); + + private: + + LUAX_DECL_METHOD(_Compress); + LUAX_DECL_METHOD(_Decompress); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/io/data_buffer.cpp b/source/modules/asura-utils/IO/DataBuffer.cpp index 37f749c..6660a94 100644 --- a/source/modules/asura-utils/io/data_buffer.cpp +++ b/source/modules/asura-utils/IO/DataBuffer.cpp @@ -1,6 +1,6 @@ #include <cstdlib> #include <cstring> -#include "data_buffer.h" +#include "DataBuffer.h" using namespace AEThreading; diff --git a/source/modules/asura-utils/io/data_buffer.h b/source/modules/asura-utils/IO/DataBuffer.h index 53ed603..93fac6e 100644 --- a/source/modules/asura-utils/io/data_buffer.h +++ b/source/modules/asura-utils/IO/DataBuffer.h @@ -1,10 +1,10 @@ -#ifndef __ASURA_ENGINE_DATABUFFER_H__ -#define __ASURA_ENGINE_DATABUFFER_H__ +#ifndef _ASURA_ENGINE_DATABUFFER_H_ +#define _ASURA_ENGINE_DATABUFFER_H_ #include <cstdlib> -#include "../scripting/portable.hpp" -#include "../threading/mutex.h" +#include "../Scripting/Portable.hpp" +#include "../Threads/Mutex.h" namespace AsuraEngine { diff --git a/source/modules/asura-utils/io/decoded_data.h b/source/modules/asura-utils/IO/DecodedData.h index 882556c..73a2f74 100644 --- a/source/modules/asura-utils/io/decoded_data.h +++ b/source/modules/asura-utils/IO/DecodedData.h @@ -1,13 +1,13 @@ -#ifndef __ASURA_ENGINE_DATA_H__ -#define __ASURA_ENGINE_DATA_H__ +#ifndef _ASURA_ENGINE_DATA_H_ +#define _ASURA_ENGINE_DATA_H_ #include <cstdlib> -#include <asura-utils/threading/thread.h> +#include <asura-utils/Threads/Thread.h> -#include "../scripting/portable.hpp" +#include "../Scripting/Portable.hpp" -#include "data_buffer.h" +#include "DataBuffer.h" namespace AsuraEngine { diff --git a/source/modules/asura-utils/IO/File.cpp b/source/modules/asura-utils/IO/File.cpp new file mode 100644 index 0000000..6d5f4eb --- /dev/null +++ b/source/modules/asura-utils/IO/File.cpp @@ -0,0 +1,294 @@ +#include <physfs/physfs.h> + +#include <asura-utils/Exceptions/Exception.h> + +#include "File.h" + +namespace AsuraEngine +{ + namespace IO + { + + File::File(const std::string& filename) + : m_FileName(filename) + , m_FileHandle(nullptr) + , m_Mode(FILE_MODE_CLOSED) + , m_BufferMode(BUFFER_MODE_NONE) + , m_BufferSize(0) + { + size_t dot = filename.rfind('.'); + if (dot != std::string::npos) + { + m_Extension = filename.substr(dot + 1); + m_Name = filename.substr(0, dot); + } + else + m_Name = filename; + } + + File::~File() + { + if (m_Mode != FILE_MODE_CLOSED) + Close(); + } + + bool File::Open(FileMode mode) + { + if (!PHYSFS_isInit()) + throw Exception("Physfs is NOT initialized."); + + if (mode == FILE_MODE_CLOSED) + return false; + + if (mode == FILE_MODE_READ && !PHYSFS_exists(m_FileName.c_str())) + throw Exception("Could NOT open file %s. Does not exist.", m_FileName.c_str()); + + if (mode == FILE_MODE_APPEND || mode == FILE_MODE_WRITE) + { + if (!PHYSFS_getWriteDir()) + { + throw Exception("Could NOT set write directory."); + } + } + + // Ѿ֮ǰͲٴµhandle + if (m_FileHandle != nullptr) + return true; + + PHYSFS_getLastErrorCode(); + + PHYSFS_File* handle = nullptr; + + switch (mode) + { + case FILE_MODE_READ: + handle = PHYSFS_openRead(m_FileName.c_str()); + break; + case FILE_MODE_APPEND: + handle = PHYSFS_openAppend(m_FileName.c_str()); + break; + case FILE_MODE_WRITE: + handle = PHYSFS_openWrite(m_FileName.c_str()); + break; + } + + if (handle == nullptr) + { + const char *err = PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()); + if (err == nullptr) + err = "unknown error"; + throw Exception("Could not open file %s (%s)", m_FileName.c_str(), err); + } + + m_FileHandle = handle; + m_Mode = mode; + + if (m_FileHandle && !SetBuffer(m_BufferMode,m_BufferSize)) + { + m_BufferMode = BUFFER_MODE_NONE; + m_BufferSize = 0; + } + + return m_FileHandle != nullptr; + } + + bool File::Close() + { + if (m_FileHandle == nullptr || !PHYSFS_close(m_FileHandle)) + return false; + m_Mode = FILE_MODE_CLOSED; + m_FileHandle = nullptr; + return true; + } + + bool File::IsOpen() + { + return m_Mode != FILE_MODE_CLOSED && m_FileHandle != nullptr; + } + + size_t File::GetSize() + { + if (m_FileHandle == nullptr) + { + Open(FILE_MODE_READ); + size_t size = PHYSFS_fileLength(m_FileHandle); + Close(); + return size; + } + return PHYSFS_fileLength(m_FileHandle); + } + + size_t File::Read(ASURA_OUT DataBuffer* dst, size_t length) + { + ASSERT(dst); + + if (dst->GetCapacity() < length) + throw Exception("Data buffer is too small compares to read length."); + + if (!m_FileHandle || m_Mode != FILE_MODE_READ) + throw Exception("File \"%s\" is not opened for reading", m_FileName); + + size_t max = PHYSFS_fileLength(m_FileHandle); + length = (length > max) ? max : length; + + if (length < 0) + throw Exception("Invalid read size."); + + dst->Lock(); + size_t size = PHYSFS_readBytes(m_FileHandle, dst->GetData(), length); + dst->Unlock(); + return size; + } + + size_t File::ReadAll(ASURA_OUT DataBuffer* dst) + { + ASSERT(dst); + + if (!m_FileHandle || m_Mode != FILE_MODE_READ) + throw Exception("File \"%s\" is not opened for reading", m_FileName); + + size_t length = PHYSFS_fileLength(m_FileHandle); + + if (dst->GetCapacity() < length) + throw Exception("Data buffer is too small compares to file length."); + + dst->Lock(); + byte* data = dst->GetData(); + size_t size = PHYSFS_readBytes(m_FileHandle, data, length); + dst->Move(data, length); + dst->Unlock(); + return size; + } + +#ifdef ASURA_WINDOWS + inline bool test_eof(File *that, PHYSFS_File *) + { + int64 pos = that->Tell(); + int64 size = that->GetSize(); + return pos == -1 || size == -1 || pos >= size; + } +#else + inline bool test_eof(File *, PHYSFS_File *file) + { + return PHYSFS_eof(file); + } +#endif + + bool File::IsEOF() + { + return m_FileHandle == nullptr || test_eof(this, m_FileHandle); + } + + size_t File::Tell() + { + if (!m_FileHandle) + return - 1; + + return PHYSFS_tell(m_FileHandle); + } + + bool File::Seek(size_t pos) + { + return m_FileHandle != nullptr && PHYSFS_seek(m_FileHandle, pos) != 0; + } + + bool File::Write(ASURA_REF DataBuffer* src) + { + if (!m_FileHandle || (m_Mode != FILE_MODE_APPEND && m_Mode != FILE_MODE_WRITE)) + throw Exception("File is not opened for writing."); + + byte* data = src->GetData(); + int size = src->GetSize(); + + if (size < 0) + throw Exception("Invalid write size."); + + size_t written = PHYSFS_writeBytes(m_FileHandle, data, size); + + if (written != src->GetSize()) + return false; + + // л + if (m_BufferSize == BUFFER_MODE_LINE && m_BufferSize > size) + { + if (memchr(data, '\n', size) != nullptr) + Flush(); + } + + return true; + } + + bool File::Flush() + { + if (!m_FileHandle || (m_Mode != FILE_MODE_WRITE && m_Mode != FILE_MODE_APPEND)) + throw Exception("File is not opened for writing."); + + return PHYSFS_flush(m_FileHandle) != 0; + } + + bool File::SetBuffer(BufferMode mode, size_t size) + { + if (size < 0) + return false; + + // If the file isn't open, we'll make sure the buffer values are set in + // File::open. + if (!IsOpen()) + { + m_BufferMode = mode; + m_BufferSize = size; + return true; + } + + int ret = 1; + + switch (mode) + { + case BUFFER_MODE_NONE: + default: + ret = PHYSFS_setBuffer(m_FileHandle, 0); + size = 0; + break; + case BUFFER_MODE_LINE: + case BUFFER_MODE_FULL: + ret = PHYSFS_setBuffer(m_FileHandle, size); + break; + } + + if (ret == 0) + return false; + + m_BufferMode = mode; + m_BufferSize = size; + + return true; + } + + File::BufferMode File::GetBuffer(ASURA_OUT size_t& size) + { + size = m_BufferSize; + return m_BufferMode; + } + + const std::string& File::GetFileName() + { + return m_FileName; + } + + const std::string& File::GetName() + { + return m_Name; + } + + const std::string& File::GetExtension() + { + return m_Extension; + } + + File::FileMode File::GetMode() + { + return m_Mode; + } + + } +}
\ No newline at end of file diff --git a/source/modules/asura-utils/IO/File.h b/source/modules/asura-utils/IO/File.h new file mode 100644 index 0000000..d11fa4f --- /dev/null +++ b/source/modules/asura-utils/IO/File.h @@ -0,0 +1,146 @@ +#ifndef _ASURA_ENGINE_FILE_H_ +#define _ASURA_ENGINE_FILE_H_ + +#include "physfs/physfs.h" + +#include "../Scripting/Portable.hpp" +#include "../Threads/Thread.h" + +#include "FileData.h" + +namespace AsuraEngine +{ + namespace IO + { + + /// + /// ʽļָд㡢Сʹȡʱʹñ࣬ʹFilesystem.read()ֱӶȡļȫ + /// ݣһFileData + /// + class File ASURA_FINAL + : public AEScripting::Portable<File> + { + public: + + LUAX_DECL_FACTORY(File); + + /// + /// ļдģʽ + /// + enum FileMode + { + FILE_MODE_CLOSED, + FILE_MODE_READ, + FILE_MODE_WRITE, + FILE_MODE_APPEND, + }; + + /// + /// ļдʱΪ + /// + enum BufferMode + { + BUFFER_MODE_NONE, ///< ʹû壬дļ + BUFFER_MODE_LINE, ///< л壬зߴﵽСʱдļ + BUFFER_MODE_FULL, ///< ȫ壬ʱдļ + }; + + File(const std::string& filename); + ~File(); + + bool Open(FileMode mode); + bool Close(); + bool IsOpen(); + FileMode GetMode(); + size_t GetSize(); + + /// + /// ȡdata bufferض + /// + size_t Read(ASURA_OUT DataBuffer* dst, size_t length); + size_t ReadAll(ASURA_OUT DataBuffer* dst); + size_t ReadAsync(ASURA_OUT DataBuffer* dst); + + /// + /// Ƿļβ + /// + bool IsEOF(); + + /// + /// data bufferед룬Ƿɹ + /// + bool Write(ASURA_REF DataBuffer* src); + + /// + /// 첽дļдļtaskthreadĶС + /// + bool WriteAsync(ASURA_REF DataBuffer* src, AEThreading::Thread* thread); + + /// + /// ˻壬ǿջдļ + /// + bool Flush(); + + /// + /// صǰдλ + /// + size_t Tell(); + + /// + /// Ӧλ + /// + bool Seek(size_t pos); + + /// + /// ûСģʽ + /// + bool SetBuffer(BufferMode mode, size_t size); + + /// + /// ȡСģʽ + /// + BufferMode GetBuffer(ASURA_OUT size_t& size); + + const std::string& GetFileName(); + const std::string& GetName(); + const std::string& GetExtension(); + + private: + + PHYSFS_File* m_FileHandle; ///< physfs ļ + std::string m_FileName; ///< ļ + std::string m_Extension; ///< չ + std::string m_Name; ///< չļ + FileMode m_Mode; ///< ļģʽ + BufferMode m_BufferMode; ///< д뻺ģʽ + size_t m_BufferSize; ///< д뻺С + + LUAX_DECL_ENUM(FileMode); + LUAX_DECL_ENUM(BufferMode); + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Open); + LUAX_DECL_METHOD(_Close); + LUAX_DECL_METHOD(_IsOpen); + LUAX_DECL_METHOD(_GetMode); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_Read); + LUAX_DECL_METHOD(_Write); + LUAX_DECL_METHOD(_ReadAsync); + LUAX_DECL_METHOD(_WriteAsync); + LUAX_DECL_METHOD(_IsEOF); + LUAX_DECL_METHOD(_Flush); + LUAX_DECL_METHOD(_Tell); + LUAX_DECL_METHOD(_Seek); + LUAX_DECL_METHOD(_SetBuffer); + LUAX_DECL_METHOD(_GetBuffer); + LUAX_DECL_METHOD(_GetFileName); + LUAX_DECL_METHOD(_GetExtension); + LUAX_DECL_METHOD(_GetName); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/io/file_data.cpp b/source/modules/asura-utils/IO/FileData.cpp index 30fa5bf..ca1cce7 100644 --- a/source/modules/asura-utils/io/file_data.cpp +++ b/source/modules/asura-utils/IO/FileData.cpp @@ -1,4 +1,4 @@ -#include "file_data.h" +#include "FileData.h" namespace AsuraEngine { diff --git a/source/modules/asura-utils/io/file_data.h b/source/modules/asura-utils/IO/FileData.h index ecc072b..f93040c 100644 --- a/source/modules/asura-utils/io/file_data.h +++ b/source/modules/asura-utils/IO/FileData.h @@ -1,11 +1,11 @@ -#ifndef __ASURA_ENGINE_FILE_DATA_H__ -#define __ASURA_ENGINE_FILE_DATA_H__ +#ifndef _ASURA_ENGINE_FILE_DATA_H_ +#define _ASURA_ENGINE_FILE_DATA_H_ #include <string> -#include <asura-utils/scripting/portable.hpp> +#include <asura-utils/Scripting/Portable.hpp> -#include "data_buffer.h" +#include "DataBuffer.h" namespace AsuraEngine { diff --git a/source/modules/asura-utils/io/file_system.cpp b/source/modules/asura-utils/IO/FileSystem.cpp index f68bad6..9d0acf0 100644 --- a/source/modules/asura-utils/io/file_system.cpp +++ b/source/modules/asura-utils/IO/FileSystem.cpp @@ -2,9 +2,9 @@ #include "../exceptions/exception.h" -#include "file.h" -#include "file_data.h" -#include "file_system.h" +#include "File.h" +#include "FileData.h" +#include "FileSystem.h" using namespace std; diff --git a/source/modules/asura-utils/io/file_system.h b/source/modules/asura-utils/IO/FileSystem.h index 9b4c4be..f0ac6ba 100644 --- a/source/modules/asura-utils/io/file_system.h +++ b/source/modules/asura-utils/IO/FileSystem.h @@ -1,15 +1,15 @@ -#ifndef __ASURA_ENGINE_FILESYSTEM_H__ -#define __ASURA_ENGINE_FILESYSTEM_H__ +#ifndef _ASURA_ENGINE_FILESYSTEM_H_ +#define _ASURA_ENGINE_FILESYSTEM_H_ #include <map> #include <string> -#include "../scripting/portable.hpp" -#include "../singleton.hpp" -#include "../type.h" +#include "../Scripting/Portable.hpp" +#include "../Singleton.hpp" +#include "../Type.h" -#include "file_data.h" -#include "file.h" +#include "FileData.h" +#include "File.h" namespace AsuraEngine { diff --git a/source/modules/asura-utils/IO/IOBatchTask.cpp b/source/modules/asura-utils/IO/IOBatchTask.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-utils/IO/IOBatchTask.cpp diff --git a/source/modules/asura-utils/io/io_batch_task.h b/source/modules/asura-utils/IO/IOBatchTask.h index 0a551e8..a9355d5 100644 --- a/source/modules/asura-utils/io/io_batch_task.h +++ b/source/modules/asura-utils/IO/IOBatchTask.h @@ -1,7 +1,7 @@ -#ifndef __ASURA_IO_BATCH_TASK_H__ -#define __ASURA_IO_BATCH_TASK_H__ +#ifndef _ASURA_IO_BATCH_TASK_H_ +#define _ASURA_IO_BATCH_TASK_H_ -#include "io_task.h" +#include "IOTask.h" namespace AsuraEngine { diff --git a/source/modules/asura-utils/io/io_task.cpp b/source/modules/asura-utils/IO/IOTask.cpp index 6c323de..bfa6726 100644 --- a/source/modules/asura-utils/io/io_task.cpp +++ b/source/modules/asura-utils/IO/IOTask.cpp @@ -1,5 +1,5 @@ -#include "file_system.h" -#include "io_task.h" +#include "FileSystem.h" +#include "IOTask.h" #include <iostream> diff --git a/source/modules/asura-utils/io/io_task.h b/source/modules/asura-utils/IO/IOTask.h index 8026a24..a35fc54 100644 --- a/source/modules/asura-utils/io/io_task.h +++ b/source/modules/asura-utils/IO/IOTask.h @@ -1,12 +1,12 @@ -#ifndef __ASURA_IO_TASK_H__ -#define __ASURA_IO_TASK_H__ +#ifndef _ASURA_IO_TASK_H_ +#define _ASURA_IO_TASK_H_ #include <string> -#include "../scripting/portable.hpp" -#include "../threading/task.h" +#include "../Scripting/Portable.hpp" +#include "../Threads/Task.h" -#include "data_buffer.h" +#include "DataBuffer.h" namespace AsuraEngine { diff --git a/source/modules/asura-utils/IO/Renewable.h b/source/modules/asura-utils/IO/Renewable.h new file mode 100644 index 0000000..90867f2 --- /dev/null +++ b/source/modules/asura-utils/IO/Renewable.h @@ -0,0 +1,29 @@ +#ifndef __ASURA_ENGINE_RENEWABLE_H__ +#define __ASURA_ENGINE_RENEWABLE_H__ + +#include "../scripting/portable.hpp" + +#include "DecodedData.h" + +namespace AsuraEngine +{ + namespace IO + { + + /// + /// ¹ݽṹͼƬƵ֣ӽݿֱӹڱ༭ + /// ¹handleֵı䲻߱ƻԣڲıhandleԴ + /// + ASURA_ABSTRACT class Renewable + { + public: + Renewable() {}; + virtual ~Renewable() {}; + }; + + } +} + +namespace AEIO = AsuraEngine::IO; + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/IO/binding/_compressor.cpp b/source/modules/asura-utils/IO/binding/_compressor.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-utils/IO/binding/_compressor.cpp diff --git a/source/modules/asura-utils/IO/binding/_data_buffer.cpp b/source/modules/asura-utils/IO/binding/_data_buffer.cpp new file mode 100644 index 0000000..9d3f3a0 --- /dev/null +++ b/source/modules/asura-utils/IO/binding/_data_buffer.cpp @@ -0,0 +1,132 @@ +#include "../DataBuffer.h" + +using namespace Luax; + +namespace AsuraEngine +{ + namespace IO + { + + LUAX_REGISTRY(DataBuffer) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "GetData", _GetData }, + { "GetSize", _GetSize }, + { "GetCapacity", _GetCapacity }, + { "Refactor", _Refactor }, + { "Load", _Load }, + { "Clear", _Clear } + ); + } + + LUAX_POSTPROCESS(DataBuffer) + { + } + + // databuffer = DataBuffer.New(lstring) + // databuffer = DataBuffer.New(capacity) + LUAX_IMPL_METHOD(DataBuffer, _New) + { + LUAX_STATE(L); + + if (state.IsType(1, LUA_TSTRING)) + { + size_t size; + const byte* bytes = lua_tolstring(L, 1, &size); + DataBuffer* buffer = new DataBuffer(bytes, size); + buffer->PushLuaxUserdata(state); + return 1; + } + else if (state.IsType(1, LUA_TNUMBER)) + { + size_t capacity = lua_tonumber(L, 1); + DataBuffer* buffer = new DataBuffer(capacity); + buffer->PushLuaxUserdata(state); + return 1; + } + else + { + return state.ErrorType(1, "number or string"); + } + } + + // lsting, len = databuffer:GetData() + LUAX_IMPL_METHOD(DataBuffer, _GetData) + { + LUAX_SETUP(L, "U"); + + DataBuffer* self = state.GetUserdata<DataBuffer>(1); + lua_pushlstring(L, self->GetData(), self->GetSize()); + return 1; + } + + // length = databuffer:GetSize() + LUAX_IMPL_METHOD(DataBuffer, _GetSize) + { + LUAX_SETUP(L, "U"); + + DataBuffer* self = state.GetUserdata<DataBuffer>(1); + lua_pushinteger(L, self->GetSize()); + return 1; + } + + // capacity = databuffer:GetCapacity() + LUAX_IMPL_METHOD(DataBuffer, _GetCapacity) + { + LUAX_SETUP(L, "U"); + + DataBuffer* self = state.GetUserdata<DataBuffer>(1); + lua_pushinteger(L, self->GetCapacity()); + return 1; + } + + // databuffer:Refactor(capacity) + LUAX_IMPL_METHOD(DataBuffer, _Refactor) + { + LUAX_PREPARE(L, DataBuffer); + + size_t capacity = state.CheckValue<int>(2); + self->Refactor(capacity); + return 0; + } + + // size = databuffer:Load(lstring) + // size = databuffer:Load(src) + LUAX_IMPL_METHOD(DataBuffer, _Load) + { + LUAX_STATE(L); + + DataBuffer* buffer = state.GetUserdata<DataBuffer>(1); + const byte* data; + size_t size; + if (state.IsType(2, LUA_TSTRING)) + { + data = lua_tolstring(L, 2, &size); + buffer->Load(data, size); + return 0; + } + else if(state.IsType(2, LUA_TUSERDATA)) + { + DataBuffer* src = state.CheckUserdata<DataBuffer>(2); + buffer->Load(*src); + return 0; + } + else + { + return state.ErrorType(1, "lstring or DataBuffer"); + } + } + + // databuffer:Clear() + LUAX_IMPL_METHOD(DataBuffer, _Clear) + { + LUAX_SETUP(L, "U"); + + DataBuffer* self = state.GetUserdata<DataBuffer>(1); + self->Clear(); + return 0; + } + + } +}
\ No newline at end of file diff --git a/source/modules/asura-utils/IO/binding/_file.cpp b/source/modules/asura-utils/IO/binding/_file.cpp new file mode 100644 index 0000000..c44bc90 --- /dev/null +++ b/source/modules/asura-utils/IO/binding/_file.cpp @@ -0,0 +1,223 @@ +#include "../file.h" + +namespace AsuraEngine +{ + namespace IO + { + + LUAX_REGISTRY(File) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "Open", _Open }, + { "Close", _Close }, + { "IsOpen", _IsOpen }, + { "GetMode", _GetMode }, + { "GetSize", _GetSize }, + { "Read", _Read }, + { "IsEOF", _IsEOF }, + { "Write", _Write }, + { "Flush", _Flush }, + { "Tell", _Tell }, + { "Seek", _Seek }, + { "SetBuffer", _SetBuffer }, + { "GetBuffer", _GetBuffer }, + { "GetFileName", _GetFileName }, + { "GetExtension", _GetExtension }, + { "GetName", _GetName } + ); + } + + LUAX_POSTPROCESS(File) + { + LUAX_REGISTER_ENUM(state, "EFileMode", + { "CLOSED", FILE_MODE_CLOSED }, + { "READ", FILE_MODE_READ }, + { "WRITE", FILE_MODE_WRITE }, + { "APPEND", FILE_MODE_APPEND } + ); + + LUAX_REGISTER_ENUM(state, "EBufferMode", + { "NONE", BUFFER_MODE_NONE}, + { "LINE", BUFFER_MODE_LINE}, + { "FULL", BUFFER_MODE_FULL} + ); + } + + // file = File.New(name) + LUAX_IMPL_METHOD(File, _New) + { + LUAX_STATE(L); + + cc8* name = state.CheckValue<cc8*>(1); + File* file = new File(name); + file->PushLuaxUserdata(state); + return 1; + } + + // successsed = file:Open(mode) + LUAX_IMPL_METHOD(File, _Open) + { + LUAX_PREPARE(L, File); + + File::FileMode mode = (File::FileMode)state.CheckValue<int>(2); + state.Push(self->Open(mode)); + return 1; + } + + // successed = file:Close() + LUAX_IMPL_METHOD(File, _Close) + { + LUAX_PREPARE(L, File); + + state.Push(self->Close()); + return 1; + } + + // opened = file:IsOpen() + LUAX_IMPL_METHOD(File, _IsOpen) + { + LUAX_PREPARE(L, File); + + state.Push(self->IsOpen()); + return 1; + } + + // mode = file:GetMode() + LUAX_IMPL_METHOD(File, _GetMode) + { + LUAX_PREPARE(L, File); + + File::FileMode mode = self->GetMode(); + state.Push((int)mode); + return 1; + } + + // size = file:GetSize() + LUAX_IMPL_METHOD(File, _GetSize) + { + LUAX_PREPARE(L, File); + + state.Push(self->GetSize()); + return 1; + } + + // size = file:Read(dst, len) + // returns: + // size ʵʶĴС + // params: + // self ļ + // dst Ŀ껺 + // len ĴС + LUAX_IMPL_METHOD(File, _Read) + { + LUAX_PREPARE(L, File); + + DataBuffer* db = state.CheckUserdata<DataBuffer>(2); + if (!db) return state.ErrorType(2, "DataBuffer"); + int len = state.CheckValue<int>(3); + int size = self->Read(db, len); + state.Push(size); + return 1; + } + + // isEOF = file:IsEOF() + LUAX_IMPL_METHOD(File, _IsEOF) + { + LUAX_PREPARE(L, File); + + state.Push(self->IsEOF()); + return 1; + } + + // isWrite = file:Write(data buffer[, size]) + LUAX_IMPL_METHOD(File, _Write) + { + LUAX_PREPARE(L, File); + + DataBuffer* db = state.CheckUserdata<DataBuffer>(2); + if (!db) return state.ErrorType(2, "DataBuffer"); + state.Push(self->Write(db)); + return 1; + } + + // isFlushed = file:Flush() + LUAX_IMPL_METHOD(File, _Flush) + { + LUAX_PREPARE(L, File); + + state.Push(self->Flush()); + return 1; + } + + // pos = file:Tell() + LUAX_IMPL_METHOD(File, _Tell) + { + LUAX_PREPARE(L, File); + + state.Push(self->Tell()); + return 1; + } + + // isSeek = file:Seek(pos) + LUAX_IMPL_METHOD(File, _Seek) + { + LUAX_PREPARE(L, File); + + int pos = state.CheckValue<int>(2); + state.Push(self->Seek(pos)); + return 1; + } + + // isSetted = file:SetBuffer(mode, size) + LUAX_IMPL_METHOD(File, _SetBuffer) + { + LUAX_PREPARE(L, File); + + BufferMode mode = (BufferMode)state.CheckValue<int>(2); + int size = state.CheckValue<int>(3); + state.Push(self->SetBuffer(mode, size)); + return 1; + } + + // size, mode = file:GetBuffer() + LUAX_IMPL_METHOD(File, _GetBuffer) + { + LUAX_PREPARE(L, File); + + size_t size = 0; + BufferMode mode = self->GetBuffer(ASURA_OUT size); + state.Push((int)size); + state.Push((int)mode); + return 2; + } + + // name = file:GetFileName() + LUAX_IMPL_METHOD(File, _GetFileName) + { + LUAX_PREPARE(L, File); + + state.Push(self->GetFileName()); + return 1; + } + + // name = file:GetExtension() + LUAX_IMPL_METHOD(File, _GetExtension) + { + LUAX_PREPARE(L, File); + + state.Push(self->GetExtension()); + return 1; + } + + // name = file:GetName() + LUAX_IMPL_METHOD(File, _GetName) + { + LUAX_PREPARE(L, File); + + state.Push(self->GetName()); + return 1; + } + + } +}
\ No newline at end of file diff --git a/source/modules/asura-utils/IO/binding/_file_data.cpp b/source/modules/asura-utils/IO/binding/_file_data.cpp new file mode 100644 index 0000000..55cbc8b --- /dev/null +++ b/source/modules/asura-utils/IO/binding/_file_data.cpp @@ -0,0 +1,60 @@ +#include "../FileData.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace IO + { + + LUAX_REGISTRY(FileData) + { + LUAX_REGISTER_METHODS(state, + { "GetFileName", _GetFileName }, + { "GetExtension", _GetExtension }, + { "GetName", _GetName }, + { "GetDataBuffer", _GetDataBuffer } + ); + } + + LUAX_POSTPROCESS(FileData) + { + } + + // filename = filedata:GetFileName() + LUAX_IMPL_METHOD(FileData, _GetFileName) + { + LUAX_PREPARE(L, FileData); + string filename = self->GetFileName(); + state.Push(filename); + return 1; + } + + // extension = filedata:GetExtension() + LUAX_IMPL_METHOD(FileData, _GetExtension) + { + LUAX_PREPARE(L, FileData); + string extension = self->GetExtension(); + state.Push(extension); + return 1; + } + + // name = filedata:GetName() + LUAX_IMPL_METHOD(FileData, _GetName) + { + LUAX_PREPARE(L, FileData); + string extension = self->GetName(); + state.Push(extension); + return 1; + } + + // databuffer = filedata:GetDataBuffer() + LUAX_IMPL_METHOD(FileData, _GetDataBuffer) + { + LUAX_PREPARE(L, FileData); + self->PushLuaxMemberRef(state, self->m_DataRef); + return 1; + } + + } +}
\ No newline at end of file diff --git a/source/modules/asura-utils/IO/binding/_file_system.cpp b/source/modules/asura-utils/IO/binding/_file_system.cpp new file mode 100644 index 0000000..ace3c5f --- /dev/null +++ b/source/modules/asura-utils/IO/binding/_file_system.cpp @@ -0,0 +1,265 @@ +#include "../FileSystem.h" + +using namespace Luax; + +namespace AsuraEngine +{ + namespace IO + { + +#define PREPARE(l) \ + LUAX_STATE(l); \ + Filesystem* fs = Filesystem::Get(); + + LUAX_REGISTRY(Filesystem) + { + LUAX_REGISTER_METHODS(state, + { "Init", _Init }, + { "Mount", _Mount }, + { "Unmount", _Unmount }, + { "GetMountPoint", _GetMountPoint }, + { "SetWriteDirectory", _SetWriteDirectory }, + { "GetWriteDirectory", _GetWriteDirectory }, + { "CreateFile", _CreateFile }, + { "CreateDirectory", _CreateDirectory }, + { "Write", _Write }, + { "Append", _Append }, + { "Remove", _Remove }, + { "Read", _Read }, + { "GetFileInfo", _GetFileInfo }, + { "GetDirectoryItems", _GetDirectoryItems } + ); + } + + LUAX_POSTPROCESS(Filesystem) + { + LUAX_REGISTER_ENUM(state, "EFileType", + { "FILE", FILE_TYPE_FILE }, + { "DIRECTORY", FILE_TYPE_DIRECTORY }, + { "SYMLINK", FILE_TYPE_SYMLINK }, + { "OTHER", FILE_TYPE_OTHER } + ); + } + + // Filesystem.Init(arg0) + LUAX_IMPL_METHOD(Filesystem, _Init) + { + PREPARE(L); + + const char* arg0 = state.CheckValue<const char*>(1); + fs->Init(arg0); + return 0; + } + + // successed = Filesystem.Mount(path, mountpoint[, prepend = false]) + // successed = Filesystem.Mount(data buffer, archievename, mountpoint[, prepend = false]) + LUAX_IMPL_METHOD(Filesystem, _Mount) + { + PREPARE(L); + bool mounted = false; + + if (state.IsType(1, LUA_TSTRING)) + { + cc8* path = state.GetValue<cc8*>(1, ""); + cc8* moutpoint = state.GetValue<cc8*>(2, "/"); + bool prepend = state.GetValue<bool>(3, false); + mounted = fs->Mount(path, moutpoint, prepend); + } + else if (state.IsType(1, LUA_TUSERDATA)) + { + DataBuffer* db = state.CheckUserdata<DataBuffer>(1); + if (!db) + return state.ErrorType(1, "Data Buffer"); + cc8* arcname = state.GetValue<cc8*>(2, ""); + cc8* mountpoint = state.GetValue<cc8*>(3, "/"); + bool prepend = state.GetValue<bool>(4, false); + mounted = fs->Mount(db, arcname, mountpoint, prepend); + // retain + fs->LuaxRetain<DataBuffer>(state, db); + } + state.Push(mounted); + return 1; + } + + // successed = Filesystem.Unmount(path) + // successed = Filesystem.Unmount(data buffer) + LUAX_IMPL_METHOD(Filesystem, _Unmount) + { + PREPARE(L); + bool unmounted = false; + + if (state.IsType(1, LUA_TSTRING)) + { + cc8* path = state.GetValue<cc8*>(1, ""); + unmounted = fs->Unmount(path); + } + else if (state.IsType(1, LUA_TUSERDATA)) + { + DataBuffer* db = state.CheckUserdata<DataBuffer>(1); + if (!db) + return state.ErrorType(1, "Data Buffer"); + unmounted = fs->Unmount(db); + if (unmounted) + fs->LuaxRelease<DataBuffer>(state, db); + } + state.Push(unmounted); + return 1; + } + + // moutpoint = Filesystem.GetMountPoint(path) + LUAX_IMPL_METHOD(Filesystem, _GetMountPoint) + { + PREPARE(L); + + cc8* path = state.CheckValue<cc8*>(1); + std::string mp; + if (fs->GetMountPoint(path, ASURA_OUT mp)) + state.Push(mp); + else + state.PushNil(); + + return 1; + } + + // Filesystem.SetWriteDirectory(dir) + LUAX_IMPL_METHOD(Filesystem, _SetWriteDirectory) + { + PREPARE(L); + + cc8* dir = state.CheckValue<cc8*>(1); + fs->SetWriteDirectory(dir); + return 0; + } + + // dir = Filesystem.GetWriteDirectory() + LUAX_IMPL_METHOD(Filesystem, _GetWriteDirectory) + { + PREPARE(L); + + std::string dir = fs->GetWriteDirectory(); + state.Push(dir); + return 1; + } + + // file = Filesystem.CreateFile(name) + LUAX_IMPL_METHOD(Filesystem, _CreateFile) + { + PREPARE(L); + + cc8* name = state.CheckValue<cc8*>(1); + File* file = fs->NewFile(name); + if (file) + file->PushLuaxUserdata(state); + else + state.PushNil(); + return 1; + } + + // successed = Filesystem.CreateDirectory(name) + LUAX_IMPL_METHOD(Filesystem, _CreateDirectory) + { + PREPARE(L); + + cc8* path = state.CheckValue<cc8*>(1); + state.Push(fs->NewDirectory(path)); + return 1; + } + + // successed = Filesystem.Write(path, data buffer) + LUAX_IMPL_METHOD(Filesystem, _Write) + { + PREPARE(L); + + cc8* path = state.CheckValue<cc8*>(1); + DataBuffer* db = state.CheckUserdata<DataBuffer>(2); + state.Push(fs->Write(path, db)); + return 1; + } + + // successed = Filesystem.Append(path, data buffer) + LUAX_IMPL_METHOD(Filesystem, _Append) + { + PREPARE(L); + + cc8* path = state.CheckValue<cc8*>(1); + DataBuffer* db = state.CheckUserdata<DataBuffer>(2); + state.Push(fs->Append(path, db)); + return 1; + } + + // successed = Filesystem.Remove(path) + LUAX_IMPL_METHOD(Filesystem, _Remove) + { + PREPARE(L); + + cc8* path = state.CheckValue<cc8*>(1); + state.Push(fs->Remove(path)); + return 1; + } + + // filedata = Filesystem.Read(path) + LUAX_IMPL_METHOD(Filesystem, _Read) + { + PREPARE(L); + + cc8* path = state.CheckValue<cc8*>(1); + FileData* fd = fs->Read(path); + if (fd) + { + fd->m_Data->PushLuaxUserdata(state); + fd->SetLuaxMemberRef(state, fd->m_DataRef, -1); // fd->m_DataRef = data buffer + state.Pop(1); // data buffer + fd->PushLuaxUserdata(state); + } + else + { + state.PushNil(); + } + return 1; + } + + // fileinfo = Filesystem.GetFileInfo(path) + LUAX_IMPL_METHOD(Filesystem, _GetFileInfo) + { + PREPARE(L); + + cc8* path = state.CheckValue<cc8*>(1); + FileInfo info; + if (fs->GetFileInfo(path, &info)) + { + lua_newtable(L); // info table + state.SetField(-1, "size", info.size); + state.SetField(-1, "modtime", info.modtime); + state.SetField(-1, "type", info.type); + } + else + { + state.PushNil(); + } + return 1; + } + + // items = Filesystem.GetDirectoryItems(path) + LUAX_IMPL_METHOD(Filesystem, _GetDirectoryItems) + { + PREPARE(L); + + cc8* path = state.CheckValue<cc8*>(1); + std::vector<std::string> items; + if(fs->GetDirectoryItems(path, ASURA_OUT items)) + { + lua_newtable(L); // item list + for (int i = 0; i < items.size(); ++i) + { + state.SetFieldByIndex(-1, i + 1, items[i]); + } + } + else + { + state.PushNil(); + } + return 1; + } + + } +}
\ No newline at end of file diff --git a/source/modules/asura-utils/IO/binding/_io_task.cpp b/source/modules/asura-utils/IO/binding/_io_task.cpp new file mode 100644 index 0000000..058f4fd --- /dev/null +++ b/source/modules/asura-utils/IO/binding/_io_task.cpp @@ -0,0 +1,46 @@ +#include "../IOTask.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace IO + { + + LUAX_REGISTRY(IOTask) + { + LUAX_REGISTER_METHODS(state, + { "New", _New } + ); + } + + LUAX_POSTPROCESS(IOTask) + { + LUAX_REGISTER_ENUM(state, "EIOTaskType", + { "READ", IOTASK_TYPE_READ }, + { "WRITE", IOTASK_TYPE_WRITE }, + { "APPEND", IOTASK_TYPE_APPEND } + ); + + } + + // task = IOTask.New(path, buffer, type, callback) + LUAX_IMPL_METHOD(IOTask, _New) + { + LUAX_STATE(L); + + cc8* path = state.CheckValue<cc8*>(1); + DataBuffer* db = state.CheckUserdata<DataBuffer>(2); + IOTaskType type = (IOTaskType)state.CheckValue<int>(3); + bool cbk = state.GetTop() >= 4 && state.IsType(4, LUA_TFUNCTION); + + IOTask* task = new IOTask(path, db, type); + task->SetLuaxMemberRef(state, task->m_BufferRef, 2); + if(cbk) + task->SetLuaxMemberRef(state, task->m_Callback, 4); + task->PushLuaxUserdata(state); + return 1; + } + + } +} diff --git a/source/modules/asura-utils/Manager.hpp b/source/modules/asura-utils/Manager.hpp new file mode 100644 index 0000000..c6817b1 --- /dev/null +++ b/source/modules/asura-utils/Manager.hpp @@ -0,0 +1,14 @@ +#ifndef _ASURA_ENGINE_MANAGER_H_ +#define _ASURA_ENGINE_MANAGER_H_ + +namespace AsuraEngine +{ + + class Manager + { + + }; + +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/Math/Curve.cpp b/source/modules/asura-utils/Math/Curve.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-utils/Math/Curve.cpp diff --git a/source/modules/asura-utils/Math/Curve.h b/source/modules/asura-utils/Math/Curve.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-utils/Math/Curve.h diff --git a/source/modules/asura-utils/Math/Functions.cpp b/source/modules/asura-utils/Math/Functions.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-utils/Math/Functions.cpp diff --git a/source/modules/asura-utils/Math/Functions.h b/source/modules/asura-utils/Math/Functions.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-utils/Math/Functions.h diff --git a/source/modules/asura-utils/Math/Matrix44.cpp b/source/modules/asura-utils/Math/Matrix44.cpp new file mode 100644 index 0000000..9ecf448 --- /dev/null +++ b/source/modules/asura-utils/Math/Matrix44.cpp @@ -0,0 +1,217 @@ +#include "Matrix44.h" + +#include <cstring> // memcpy +#include <cmath> + +namespace AsuraEngine +{ + namespace Math + { + + const Matrix44 Matrix44::Identity; + + // | e0 e4 e8 e12 | + // | e1 e5 e9 e13 | + // | e2 e6 e10 e14 | + // | e3 e7 e11 e15 | + + Matrix44::Matrix44() + { + SetIdentity(); + } + + Matrix44::Matrix44(const Matrix44& m) + { + memcpy(&e, &m.e, 16 * sizeof(float)); + } + + Matrix44::~Matrix44() + { + } + + void Matrix44::operator = (const Matrix44& m) + { + memcpy(&e, &m.e, 16 * sizeof(float)); + } + + void Matrix44::SetOrtho(float l, float r, float b, float t, float n, float f) + { + SetIdentity(); + float w = r - l; + float h = t - b; + float z = f - n; + e[0] = 2 / w; + e[5] = 2 / h; + e[10] = -2 / z; + e[12] = -(r + l) / w; + e[13] = -(t + b) / h; + e[14] = -(f + n) / z; + e[15] = 1; + } + + // | e0 e4 e8 e12 | + // | e1 e5 e9 e13 | + // | e2 e6 e10 e14 | + // | e3 e7 e11 e15 | + // | e0 e4 e8 e12 | + // | e1 e5 e9 e13 | + // | e2 e6 e10 e14 | + // | e3 e7 e11 e15 | + + Matrix44 Matrix44::operator * (const Matrix44 & m) const + { + Matrix44 t; + + t.e[0] = (e[0] * m.e[0]) + (e[4] * m.e[1]) + (e[8] * m.e[2]) + (e[12] * m.e[3]); + t.e[4] = (e[0] * m.e[4]) + (e[4] * m.e[5]) + (e[8] * m.e[6]) + (e[12] * m.e[7]); + t.e[8] = (e[0] * m.e[8]) + (e[4] * m.e[9]) + (e[8] * m.e[10]) + (e[12] * m.e[11]); + t.e[12] = (e[0] * m.e[12]) + (e[4] * m.e[13]) + (e[8] * m.e[14]) + (e[12] * m.e[15]); + + t.e[1] = (e[1] * m.e[0]) + (e[5] * m.e[1]) + (e[9] * m.e[2]) + (e[13] * m.e[3]); + t.e[5] = (e[1] * m.e[4]) + (e[5] * m.e[5]) + (e[9] * m.e[6]) + (e[13] * m.e[7]); + t.e[9] = (e[1] * m.e[8]) + (e[5] * m.e[9]) + (e[9] * m.e[10]) + (e[13] * m.e[11]); + t.e[13] = (e[1] * m.e[12]) + (e[5] * m.e[13]) + (e[9] * m.e[14]) + (e[13] * m.e[15]); + + t.e[2] = (e[2] * m.e[0]) + (e[6] * m.e[1]) + (e[10] * m.e[2]) + (e[14] * m.e[3]); + t.e[6] = (e[2] * m.e[4]) + (e[6] * m.e[5]) + (e[10] * m.e[6]) + (e[14] * m.e[7]); + t.e[10] = (e[2] * m.e[8]) + (e[6] * m.e[9]) + (e[10] * m.e[10]) + (e[14] * m.e[11]); + t.e[14] = (e[2] * m.e[12]) + (e[6] * m.e[13]) + (e[10] * m.e[14]) + (e[14] * m.e[15]); + + t.e[3] = (e[3] * m.e[0]) + (e[7] * m.e[1]) + (e[11] * m.e[2]) + (e[15] * m.e[3]); + t.e[7] = (e[3] * m.e[4]) + (e[7] * m.e[5]) + (e[11] * m.e[6]) + (e[15] * m.e[7]); + t.e[11] = (e[3] * m.e[8]) + (e[7] * m.e[9]) + (e[11] * m.e[10]) + (e[15] * m.e[11]); + t.e[15] = (e[3] * m.e[12]) + (e[7] * m.e[13]) + (e[11] * m.e[14]) + (e[15] * m.e[15]); + + return t; + } + + void Matrix44::operator *= (const Matrix44 & m) + { + Matrix44 t = (*this) * m; + memcpy((void*)this->e, (void*)t.e, sizeof(float) * 16); + } + + const float * Matrix44::GetElements() const + { + return e; + } + + void Matrix44::SetIdentity() + { + memset(e, 0, sizeof(float) * 16); + e[0] = e[5] = e[10] = e[15] = 1; + } + + void Matrix44::SetTranslation(float x, float y) + { + SetIdentity(); + e[12] = x; + e[13] = y; + } + + void Matrix44::SetRotation(float rad) + { + SetIdentity(); + float c = cos(rad), s = sin(rad); + e[0] = c; e[4] = -s; + e[1] = s; e[5] = c; + } + + void Matrix44::SetScale(float sx, float sy) + { + SetIdentity(); + e[0] = sx; + e[5] = sy; + } + + void Matrix44::SetShear(float kx, float ky) + { + SetIdentity(); + e[1] = ky; + e[4] = kx; + } + + void Matrix44::SetTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy) + { + memset(e, 0, sizeof(float) * 16); // zero out matrix + float c = cos(angle), s = sin(angle); + // matrix multiplication carried out on paper: + // |1 x| |c -s | |sx | |1 -ox| + // | 1 y| |s c | | sy | | 1 -oy| + // | 1 | | 1 | | 1 | | 1 | + // | 1| | 1| | 1| | 1 | + // move rotate scale origin + e[10] = e[15] = 1.0f; + e[0] = c * sx; // = a + e[1] = s * sx; // = b + e[4] = -s * sy; // = c + e[5] = c * sy; // = d + e[12] = x - ox * e[0] - oy * e[4]; + e[13] = y - ox * e[1] - oy * e[5]; + } + + void Matrix44::Translate(float x, float y) + { + Matrix44 t; + t.SetTranslation(x, y); + this->operator *=(t); + } + + void Matrix44::Rotate(float rad) + { + Matrix44 t; + t.SetRotation(rad); + this->operator *=(t); + } + + void Matrix44::Scale(float sx, float sy) + { + Matrix44 t; + t.SetScale(sx, sy); + this->operator *=(t); + } + + void Matrix44::Shear(float kx, float ky) + { + Matrix44 t; + t.SetShear(kx, ky); + this->operator *=(t); + } + + void Matrix44::Transform(float x, float y, float angle, float sx, float sy, float ox, float oy) + { + Matrix44 t; + t.SetTransformation(x, y, angle, sx, sy, ox, oy); + this->operator *=(t); + } + + void Matrix44::Ortho(float left, float right, float bottom, float top, float near, float far) + { + Matrix44 t; + t.SetOrtho(left, right, bottom, top, near, far); + this->operator *=(t); + } + + // | x | + // | y | + // | 0 | + // | 1 | + // | e0 e4 e8 e12 | + // | e1 e5 e9 e13 | + // | e2 e6 e10 e14 | + // | e3 e7 e11 e15 | + + //void Matrix44::transform(Graphics::Vertex* dst, const Graphics::Vertex* src, int size) const + //{ + // for (int i = 0; i<size; ++i) + // { + // // Store in temp variables in case src = dst + // float x = (e[0] * src[i].xy.x()) + (e[4] * src[i].xy.y()) + (0) + (e[12]); + // float y = (e[1] * src[i].xy.x()) + (e[5] * src[i].xy.y()) + (0) + (e[13]); + + // dst[i].xy.Set(x, y); + // } + //} + + } // namespace Math +} // namespace JinEngine
\ No newline at end of file diff --git a/source/modules/asura-utils/Math/Matrix44.h b/source/modules/asura-utils/Math/Matrix44.h new file mode 100644 index 0000000..7b66920 --- /dev/null +++ b/source/modules/asura-utils/Math/Matrix44.h @@ -0,0 +1,98 @@ +#ifndef _ASURA_MATRIX_H_ +#define _ASURA_MATRIX_H_ + +#include "../Scripting/Portable.hpp" + +namespace AsuraEngine +{ + namespace Math + { + + /// + /// ҪתõOpenGLglm::mat4 + /// https://blog.csdn.net/candycat1992/article/details/8830894 + /// + class Matrix44 + { + public: + + static const Matrix44 Identity; + + Matrix44(); + + Matrix44(const Matrix44& m); + + ~Matrix44(); + + void operator = (const Matrix44& m); + + void SetOrtho(float _left, float _right, float _bottom, float _top, float _near, float _far); + + Matrix44 operator * (const Matrix44 & m) const; + + void operator *= (const Matrix44 & m); + + const float* GetElements() const; + + void SetIdentity(); + + void SetTranslation(float x, float y); + + void SetRotation(float r); + + void SetScale(float sx, float sy); + + void SetShear(float kx, float ky); + + void SetTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy); + + void Translate(float x, float y); + + void Rotate(float r); + + void Scale(float sx, float sy); + + 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); + + 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; + + /// + /// ʽ + /// + float Calculate(); + + private: + + /// + /// | e0 e4 e8 e12 | + /// | e1 e5 e9 e13 | + /// | e2 e6 e10 e14 | + /// | e3 e7 e11 e15 | + /// + float e[16]; + + }; + + } +} + +namespace AEMath = AsuraEngine::Math; + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/Math/Quaternion.cpp b/source/modules/asura-utils/Math/Quaternion.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-utils/Math/Quaternion.cpp diff --git a/source/modules/asura-utils/Math/Quaternion.h b/source/modules/asura-utils/Math/Quaternion.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-utils/Math/Quaternion.h diff --git a/source/modules/asura-utils/Math/Rand/Rand.h b/source/modules/asura-utils/Math/Rand/Rand.h new file mode 100644 index 0000000..efda8db --- /dev/null +++ b/source/modules/asura-utils/Math/Rand/Rand.h @@ -0,0 +1,89 @@ +#ifndef RAND_H +#define RAND_H + +#include "../../Type.h" +#include "../../Classes.h" + +namespace_begin(AsuraEngine) +namespace_begin(Math) + +/* +Some random generator timings: +MacBook Pro w/ Core 2 Duo 2.4GHz. Times are for gcc 4.0.1 (OS X 10.6.2) / VS2008 SP1 (Win XP SP3), +in milliseconds for this loop (4915200 calls): + +for (int j = 0; j < 100; ++j) +for (int i = 0; i < 128*128*3; ++i) +data[i] = (rnd.get() & 0x3) << 6; + +gcc vs2008 Size +C's rand(): 57.0 109.3 ms 1 +Mersenne Twister: 56.0 37.4 ms 2500 +Unity 2.x LCG: 11.1 9.2 ms 4 +Xorshift 128: 15.0 17.8 ms 16 +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 +class Rand { +public: + + Rand(uint32 seed = 0) + { + SetSeed(seed); + } + + uint32 Get() + { + uint32 t; + t = x ^ (x << 11); + x = y; y = z; z = w; + return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); + } + + inline static float GetFloatFromInt(uint32 value) + { + // take 23 bits of integer, and divide by 2^23-1 + return float(value & 0x007FFFFF) * (1.0f / 8388607.0f); + } + + inline static uint8 GetByteFromInt(uint32 value) + { + // take the most significant byte from the 23-bit value + return uint8(value >> (23 - 8)); + } + + // random number between 0.0 and 1.0 + float GetFloat() + { + return GetFloatFromInt(Get()); + } + + // random number between -1.0 and 1.0 + float GetSignedFloat() + { + return GetFloat() * 2.0f - 1.0f; + } + + void SetSeed(uint32 seed) + { + x = seed; + y = x * 1812433253U + 1; + z = y * 1812433253U + 1; + w = z * 1812433253U + 1; + } + + uint32 GetSeed() const { return x; } + +private: + uint32 x, y, z, w; +}; + +namespace_end +namespace_end + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/Math/Rand/Random.h b/source/modules/asura-utils/Math/Rand/Random.h new file mode 100644 index 0000000..cf2fc54 --- /dev/null +++ b/source/modules/asura-utils/Math/Rand/Random.h @@ -0,0 +1,9 @@ +#include "Rand.h" + +namespace_begin(AsuraEngine) +namespace_begin(Math) + + + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-utils/Math/RangedValue.cpp b/source/modules/asura-utils/Math/RangedValue.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-utils/Math/RangedValue.cpp diff --git a/source/modules/asura-utils/Math/RangedValue.h b/source/modules/asura-utils/Math/RangedValue.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-utils/Math/RangedValue.h diff --git a/source/modules/asura-utils/Math/Rect.hpp b/source/modules/asura-utils/Math/Rect.hpp new file mode 100644 index 0000000..45bf1ba --- /dev/null +++ b/source/modules/asura-utils/Math/Rect.hpp @@ -0,0 +1,50 @@ +#ifndef _ASURA_ENGINE_RECT_H_ +#define _ASURA_ENGINE_RECT_H_ + +namespace AsuraEngine +{ + namespace Math + { + + template<typename T> + struct Rect + { + public: + Rect(); + Rect(T x, T y, T w, T h); + ~Rect() {}; + + /// + /// x,yǷrectڡ + /// + bool Contain(T x, T y); + + /// + /// Ƿཻཻľ + /// + bool Intersect(const Rect& src, Rect& intersection); + + /// + /// Ƿཻཻľ + /// + static bool Intersect(const Rect<T>& src1, const Rect<T>& src2, Rect<T>& intersection); + + void Set(T x, T y, T w, T h); + + T x, y, w, h; + }; + +#include "Rect.inc" + + // Define the most common types + typedef Rect<int> Recti; + typedef Rect<unsigned int> Rectu; + typedef Rect<float> Rectf; + typedef Rect<long> Reftl; + + } +} + +namespace AEMath = AsuraEngine::Math; + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/math/rect.inl b/source/modules/asura-utils/Math/Rect.inc index efafbf9..efafbf9 100644 --- a/source/modules/asura-utils/math/rect.inl +++ b/source/modules/asura-utils/Math/Rect.inc diff --git a/source/modules/asura-utils/Math/Transform.cpp b/source/modules/asura-utils/Math/Transform.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-utils/Math/Transform.cpp diff --git a/source/modules/asura-utils/Math/Transform.h b/source/modules/asura-utils/Math/Transform.h new file mode 100644 index 0000000..23d0709 --- /dev/null +++ b/source/modules/asura-utils/Math/Transform.h @@ -0,0 +1,30 @@ +#ifndef _ASURA_ENGINE_TRANSFORM_H_ +#define _ASURA_ENGINE_TRANSFORM_H_ + +#include "../scripting/Portable.hpp" + +namespace AsuraEngine +{ + namespace Math + { + + class Transform + { + public: + + void Set(float x, float y, float sx, float sy, float ox, float oy, float r); + + void LoadIdentity(); + + void Move(float dx = 0, float dy = 0); + void Rotate(float r); + void Scale(float sx, float sy); + + float m[16]; //4x4 matrix + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/Math/Vector2.hpp b/source/modules/asura-utils/Math/Vector2.hpp new file mode 100644 index 0000000..f2405eb --- /dev/null +++ b/source/modules/asura-utils/Math/Vector2.hpp @@ -0,0 +1,72 @@ +#ifndef _ASURA_ENGINE_VECTOR2_H__ +#define _ASURA_ENGINE_VECTOR2_H__ + +namespace AsuraEngine +{ + namespace Math + { + template <typename T> + class Vector2 + { + public: + Vector2(); + Vector2(T X, T Y); + + template <typename U> + explicit Vector2(const Vector2<U>& vector); + + void Set(T X, T Y); + + 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 +=(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, 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 /(const 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); + +#include "Vector2.inc" + + // Define the most common types + typedef Vector2<int> Vector2i; + typedef Vector2<unsigned int> Vector2u; + typedef Vector2<float> Vector2f; + + } +} + +namespace AEMath = AsuraEngine::Math; + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/math/vector2.inl b/source/modules/asura-utils/Math/Vector2.inc index 155432a..155432a 100644 --- a/source/modules/asura-utils/math/vector2.inl +++ b/source/modules/asura-utils/Math/Vector2.inc diff --git a/source/modules/asura-utils/Math/Vector3.hpp b/source/modules/asura-utils/Math/Vector3.hpp new file mode 100644 index 0000000..8da57cf --- /dev/null +++ b/source/modules/asura-utils/Math/Vector3.hpp @@ -0,0 +1,233 @@ +#ifndef _ASURA_ENGINE_VECTOR3_H__ +#define _ASURA_ENGINE_VECTOR3_H__ + +namespace AsuraEngine +{ + namespace Math + { + template <typename T> + class Vector3 + { + public: + + //////////////////////////////////////////////////////////// + /// \brief Default constructor + /// + /// Creates a Vector3(0, 0, 0). + /// + //////////////////////////////////////////////////////////// + Vector3(); + + //////////////////////////////////////////////////////////// + /// \brief Construct the vector from its coordinates + /// + /// \param X X coordinate + /// \param Y Y coordinate + /// \param Z Z coordinate + /// + //////////////////////////////////////////////////////////// + Vector3(T X, T Y, T Z); + + //////////////////////////////////////////////////////////// + /// \brief Construct the vector from another type of vector + /// + /// This constructor doesn't replace the copy constructor, + /// it's called only when U != T. + /// A call to this constructor will fail to compile if U + /// is not convertible to T. + /// + /// \param vector Vector to convert + /// + //////////////////////////////////////////////////////////// + template <typename U> + explicit Vector3(const Vector3<U>& vector); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + T x; ///< X coordinate of the vector + T y; ///< Y coordinate of the vector + T z; ///< Z coordinate of the vector + }; + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of unary operator - + /// + /// \param left Vector to negate + /// + /// \return Memberwise opposite of the vector + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T> operator -(const Vector3<T>& left); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator += + /// + /// This operator performs a memberwise addition of both vectors, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T>& operator +=(Vector3<T>& left, const Vector3<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator -= + /// + /// This operator performs a memberwise subtraction of both vectors, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T>& operator -=(Vector3<T>& left, const Vector3<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator + + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Memberwise addition of both vectors + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T> operator +(const Vector3<T>& left, const Vector3<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator - + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Memberwise subtraction of both vectors + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T> operator -(const Vector3<T>& left, const Vector3<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator * + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Memberwise multiplication by \a right + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T> operator *(const Vector3<T>& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator * + /// + /// \param left Left operand (a scalar value) + /// \param right Right operand (a vector) + /// + /// \return Memberwise multiplication by \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T> operator *(T left, const Vector3<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator *= + /// + /// This operator performs a memberwise multiplication by \a right, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T>& operator *=(Vector3<T>& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator / + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Memberwise division by \a right + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T> operator /(const Vector3<T>& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator /= + /// + /// This operator performs a memberwise division by \a right, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T>& operator /=(Vector3<T>& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator == + /// + /// This operator compares strict equality between two vectors. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return True if \a left is equal to \a right + /// + //////////////////////////////////////////////////////////// + template <typename T> + bool operator ==(const Vector3<T>& left, const Vector3<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator != + /// + /// This operator compares strict difference between two vectors. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return True if \a left is not equal to \a right + /// + //////////////////////////////////////////////////////////// + template <typename T> + bool operator !=(const Vector3<T>& left, const Vector3<T>& right); + +#include "Vector3.inc" + + // Define the most common types + typedef Vector3<int> Vector3i; + typedef Vector3<float> Vector3f; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/math/vector3.inl b/source/modules/asura-utils/Math/Vector3.inc index 3a2aa93..3a2aa93 100644 --- a/source/modules/asura-utils/math/vector3.inl +++ b/source/modules/asura-utils/Math/Vector3.inc diff --git a/source/modules/asura-utils/Math/Vector4.h b/source/modules/asura-utils/Math/Vector4.h new file mode 100644 index 0000000..a5bf549 --- /dev/null +++ b/source/modules/asura-utils/Math/Vector4.h @@ -0,0 +1,234 @@ +#ifndef _ASURA_ENGINE_VECTOR4_H__ +#define _ASURA_ENGINE_VECTOR4_H__ + +namespace AsuraEngine +{ + namespace Math + { + template <typename T> + class Vector4 + { + public: + + //////////////////////////////////////////////////////////// + /// \brief Default constructor + /// + /// Creates a Vector4(0, 0, 0). + /// + //////////////////////////////////////////////////////////// + Vector4(); + + //////////////////////////////////////////////////////////// + /// \brief Construct the vector from its coordinates + /// + /// \param X X coordinate + /// \param Y Y coordinate + /// \param Z Z coordinate + /// + //////////////////////////////////////////////////////////// + Vector4(T X, T Y, T Z, T W); + + //////////////////////////////////////////////////////////// + /// \brief Construct the vector from another type of vector + /// + /// This constructor doesn't replace the copy constructor, + /// it's called only when U != T. + /// A call to this constructor will fail to compile if U + /// is not convertible to T. + /// + /// \param vector Vector to convert + /// + //////////////////////////////////////////////////////////// + template <typename U> + explicit Vector4(const Vector4<U>& vector); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + T x; ///< X coordinate of the vector + T y; ///< Y coordinate of the vector + T z; ///< Z coordinate of the vector + T w; ///< W coordinate of the vector + }; + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of unary operator - + /// + /// \param left Vector to negate + /// + /// \return Memberwise opposite of the vector + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T> operator -(const Vector4<T>& left); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator += + /// + /// This operator performs a memberwise addition of both vectors, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T>& operator +=(Vector4<T>& left, const Vector4<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator -= + /// + /// This operator performs a memberwise subtraction of both vectors, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T>& operator -=(Vector4<T>& left, const Vector4<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator + + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Memberwise addition of both vectors + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T> operator +(const Vector4<T>& left, const Vector4<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator - + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Memberwise subtraction of both vectors + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T> operator -(const Vector4<T>& left, const Vector4<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator * + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Memberwise multiplication by \a right + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T> operator *(const Vector4<T>& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator * + /// + /// \param left Left operand (a scalar value) + /// \param right Right operand (a vector) + /// + /// \return Memberwise multiplication by \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T> operator *(T left, const Vector4<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator *= + /// + /// This operator performs a memberwise multiplication by \a right, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T>& operator *=(Vector4<T>& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator / + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Memberwise division by \a right + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T> operator /(const Vector4<T>& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator /= + /// + /// This operator performs a memberwise division by \a right, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T>& operator /=(Vector4<T>& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator == + /// + /// This operator compares strict equality between two vectors. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return True if \a left is equal to \a right + /// + //////////////////////////////////////////////////////////// + template <typename T> + bool operator ==(const Vector4<T>& left, const Vector4<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator != + /// + /// This operator compares strict difference between two vectors. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return True if \a left is not equal to \a right + /// + //////////////////////////////////////////////////////////// + template <typename T> + bool operator !=(const Vector4<T>& left, const Vector4<T>& right); + +#include "Vector4.inc" + + // Define the most common types + typedef Vector4<int> Vector4i; + typedef Vector4<float> Vector4f; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/math/vector4.inl b/source/modules/asura-utils/Math/Vector4.inc index 4b043a1..4b043a1 100644 --- a/source/modules/asura-utils/math/vector4.inl +++ b/source/modules/asura-utils/Math/Vector4.inc diff --git a/source/modules/asura-utils/Module.h b/source/modules/asura-utils/Module.h new file mode 100644 index 0000000..2cc91d6 --- /dev/null +++ b/source/modules/asura-utils/Module.h @@ -0,0 +1,32 @@ +#ifndef _ASURA_MODULE_H_ +#define _ASURA_MODULE_H_ + +#include "Type.h" +#include "Scripting/Portable.hpp" + +namespace AsuraEngine +{ + + /// + /// Asura libs Ҫ̳д࣬Կעᡣģа˳Щģ飬Ȼ˳InitializeFinalizeʼ + /// رЩģ顣 + /// + ASURA_ABSTRACT class Module + { + public: + + /// + /// ʼģ顣 + /// + virtual void Initialize(Luax::LuaxState& state) = 0; + + /// + /// رģ顣 + /// + virtual void Finalize(Luax::LuaxState& state) = 0; + + }; + +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/Scripting/Portable.hpp b/source/modules/asura-utils/Scripting/Portable.hpp new file mode 100644 index 0000000..1eee123 --- /dev/null +++ b/source/modules/asura-utils/Scripting/Portable.hpp @@ -0,0 +1,31 @@ +#ifndef _ASURA_ENGINE_PORTABLE_H_ +#define _ASURA_ENGINE_PORTABLE_H_ + +extern "C" { +#include <lua51/lua.h> +#include <lua51/lualib.h> +#include <lua51/lauxlib.h> +} + +#include <luax/luax.h> + +#include "../Type.h" +#include "../Classes.h" + +namespace_begin(AsuraEngine) +namespace_begin(Scripting) + + +/// ҪΪ࣬userdatamember ref̳д࣬ע̳С +using Object = Luax::LuaxObject; + +/// ҪעluanativeҪ̳дģ塣BASEָ࣬ĬLuaxObjectָLuaxObjectࡢ +template<typename TYPE, typename BASE = Luax::LuaxObject> +using Portable = Luax::LuaxNativeClass<TYPE, BASE>; + +namespace_end +namespace_end + +namespace AEScripting = AsuraEngine::Scripting; + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/Singleton.hpp b/source/modules/asura-utils/Singleton.hpp new file mode 100644 index 0000000..9bb7336 --- /dev/null +++ b/source/modules/asura-utils/Singleton.hpp @@ -0,0 +1,59 @@ +#ifndef _ASURA_SINGLETON_H_ +#define _ASURA_SINGLETON_H_ + +#include "UtilsConfig.h" + +namespace AsuraEngine +{ + + /// + /// ̳Singletonڵһʵʱʵ֮ٴʵᱨ + /// + template<class T> + class Singleton + { + public: + + static T* Get() + { + // ֮ǰûдһ + if (!instance) instance = new T; + // ʵ + return instance; + } + + static void Destroy() + { + delete instance; + instance = nullptr; + } + + protected: + + Singleton() + { + // instanceζִһʵǴġ + ASSERT(!instance); + // ʵΪʵ + instance = static_cast<T*>(this); + }; + + virtual ~Singleton() {}; + + static T* instance; + + private: + + Singleton(const Singleton& singleton); + + Singleton& operator = (const Singleton& singleton); + + }; + + // ʵʼΪ + template<class T> + T* Singleton<T>::instance = nullptr; + +} + +#endif // _ASURA_SINGLETON_H_
\ No newline at end of file diff --git a/source/modules/asura-utils/StringMap.cpp b/source/modules/asura-utils/StringMap.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-utils/StringMap.cpp diff --git a/source/modules/asura-utils/StringMap.hpp b/source/modules/asura-utils/StringMap.hpp new file mode 100644 index 0000000..15d28ee --- /dev/null +++ b/source/modules/asura-utils/StringMap.hpp @@ -0,0 +1,29 @@ +#ifndef _ASURA_ENGINE_STRINGMAP_H_ +#define _ASURA_ENGINE_STRINGMAP_H_ + +#include <string> + +namespace AsuraEngine +{ + + /// + /// һ˫һһӦӳ䣬shader uniformsstatemathine state parameterID + /// + template<typename key_type> + class StringMap + { + public: + + bool ContainsKey(const key_type& key); + + bool ContainsString(const std::string& str); + + std::string GetStringByKey(const key_type& key); + + key_type GetKeyByString(const std::string& str); + + }; + +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/conditional.cpp b/source/modules/asura-utils/Threads/Conditional.cpp index c4d32d9..f86a81e 100644 --- a/source/modules/asura-utils/threading/conditional.cpp +++ b/source/modules/asura-utils/Threads/Conditional.cpp @@ -1,7 +1,7 @@ -#include "conditional.h" +#include "Conditional.h" namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) Conditional::Conditional() : m_Waiting(0) diff --git a/source/modules/asura-utils/threading/conditional.h b/source/modules/asura-utils/Threads/Conditional.h index ff832ac..7a99ea1 100644 --- a/source/modules/asura-utils/threading/conditional.h +++ b/source/modules/asura-utils/Threads/Conditional.h @@ -1,13 +1,13 @@ -#ifndef __ASURA_CONDITIONAL_H__ -#define __ASURA_CONDITIONAL_H__ +#ifndef _ASURA_CONDITIONAL_H_ +#define _ASURA_CONDITIONAL_H_ -#include <asura-utils/classes.h> +#include <asura-utils/Classes.h> -#include "mutex.h" -#include "semaphore.h" +#include "Mutex.h" +#include "Semaphore.h" namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) /// /// diff --git a/source/modules/asura-utils/threading/coroutine.cpp b/source/modules/asura-utils/Threads/Coroutine.cpp index 552a415..5c4ab68 100644 --- a/source/modules/asura-utils/threading/coroutine.cpp +++ b/source/modules/asura-utils/Threads/Coroutine.cpp @@ -1,7 +1,7 @@ #include "coroutine.h" namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) /* Coroutine::Coroutine() diff --git a/source/modules/asura-utils/threading/coroutine.h b/source/modules/asura-utils/Threads/Coroutine.h index 830dcd2..cdb21f8 100644 --- a/source/modules/asura-utils/threading/coroutine.h +++ b/source/modules/asura-utils/Threads/Coroutine.h @@ -1,12 +1,12 @@ -#ifndef __ASURA_COROUTINE_H__ -#define __ASURA_COROUTINE_H__ +#ifndef _ASURA_COROUTINE_H_ +#define _ASURA_COROUTINE_H_ -#include <asura-utils/classes.h> +#include <asura-utils/Classes.h> -#include "../scripting/portable.hpp" +#include "../Scripting/Portable.hpp" namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) /// /// luaЭ̣һЩ @@ -35,6 +35,6 @@ private: namespace_end namespace_end -namespace AEThreading = AsuraEngine::Threading; +namespace AEThreading = AsuraEngine::Threads; #endif
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/mutex.cpp b/source/modules/asura-utils/Threads/Mutex.cpp index ff0b3fa..501a0ed 100644 --- a/source/modules/asura-utils/threading/mutex.cpp +++ b/source/modules/asura-utils/Threads/Mutex.cpp @@ -1,9 +1,9 @@ -#include <asura-utils/exceptions/exception.h> +#include <asura-utils/Exceptions/Exception.h> -#include "mutex.h" +#include "Mutex.h" namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) #define try_create_mutex(impl)\ if (!m_Impl) \ diff --git a/source/modules/asura-utils/threading/mutex.h b/source/modules/asura-utils/Threads/Mutex.h index 623a3db..4269c05 100644 --- a/source/modules/asura-utils/threading/mutex.h +++ b/source/modules/asura-utils/Threads/Mutex.h @@ -1,17 +1,17 @@ -#ifndef __ASURA_MUTEX_H__ -#define __ASURA_MUTEX_H__ +#ifndef _ASURA_MUTEX_H_ +#define _ASURA_MUTEX_H_ -#include <asura-utils/type.h> -#include <asura-utils/classes.h> +#include <asura-utils/Type.h> +#include <asura-utils/Classes.h> -#include "../utils_config.h" +#include "../UtilsConfig.h" #if ASURA_THREAD_WIN32 #include <windows.h> #endif namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) #define ASURA_MUTEX_MAXWAIT (~(uint32)0) @@ -123,6 +123,6 @@ class MutexImplSTD ASURA_FINAL : public MutexImpl namespace_end namespace_end -namespace AEThreading = AsuraEngine::Threading; +namespace AEThreading = AsuraEngine::Threads; #endif
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/semaphore.cpp b/source/modules/asura-utils/Threads/Semaphore.cpp index f9ffb35..a222f3d 100644 --- a/source/modules/asura-utils/threading/semaphore.cpp +++ b/source/modules/asura-utils/Threads/Semaphore.cpp @@ -1,11 +1,11 @@ -#include "../exceptions/exception.h" -#include "../type.h" +#include "../Exceptions/Exception.h" +#include "../Type.h" -#include "mutex.h" -#include "semaphore.h" +#include "Mutex.h" +#include "Semaphore.h" namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) #define try_create_semaphore(impl) \ if (!m_Impl) \ diff --git a/source/modules/asura-utils/threading/semaphore.h b/source/modules/asura-utils/Threads/Semaphore.h index ae7b10b..41b1fd2 100644 --- a/source/modules/asura-utils/threading/semaphore.h +++ b/source/modules/asura-utils/Threads/Semaphore.h @@ -1,14 +1,14 @@ -#ifndef __ASURA_SEMAPHORE_H__ -#define __ASURA_SEMAPHORE_H__ +#ifndef _ASURA_SEMAPHORE_H_ +#define _ASURA_SEMAPHORE_H_ -#include "../utils_config.h" +#include "../UtilsConfig.h" #if ASURA_THREAD_WIN32 #include <windows.h> #endif namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) class SemaphoreImpl; diff --git a/source/modules/asura-utils/threading/task.cpp b/source/modules/asura-utils/Threads/Task.cpp index ea3f68e..9666cc6 100644 --- a/source/modules/asura-utils/threading/task.cpp +++ b/source/modules/asura-utils/Threads/Task.cpp @@ -1,10 +1,10 @@ #include "task.h" -#include "../scripting/portable.hpp" +#include "../scripting/Portable.hpp" using namespace AEScripting; namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) namespace_end namespace_end diff --git a/source/modules/asura-utils/threading/task.h b/source/modules/asura-utils/Threads/Task.h index b959012..b871303 100644 --- a/source/modules/asura-utils/threading/task.h +++ b/source/modules/asura-utils/Threads/Task.h @@ -1,12 +1,12 @@ -#ifndef __ASURA_THRAD_TASK_H__ -#define __ASURA_THRAD_TASK_H__ +#ifndef _ASURA_THRAD_TASK_H_ +#define _ASURA_THRAD_TASK_H_ -#include <asura-utils/type.h> -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/classes.h> +#include <asura-utils/Type.h> +#include <asura-utils/Scripting/Portable.hpp> +#include <asura-utils/Classes.h> namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) /// /// ϣһ̴̳߳TaskдExecute @@ -38,6 +38,6 @@ protected: namespace_end namespace_end -namespace AEThreading = AsuraEngine::Threading; +namespace AEThreading = AsuraEngine::Threads; #endif
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/thread.cpp b/source/modules/asura-utils/Threads/Thread.cpp index cb71d32..1153912 100644 --- a/source/modules/asura-utils/threading/thread.cpp +++ b/source/modules/asura-utils/Threads/Thread.cpp @@ -1,12 +1,12 @@ -#include "thread.h" +#include "Thread.h" -#include "thread_impl_win32.h" -#include "thread_impl_posix.h" -#include "thread_impl_sdl.h" -#include "thread_impl_std.h" +#include "ThreadImplWin32.h" +#include "ThreadImplPosix.h" +#include "ThreadImplSdl.h" +#include "ThreadImplStd.h" namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) Thread::Thread(lua_State* luaThread, ThreadType type /*= THREAD_TYPE_DEFERRED*/, uint sleepTime /*= 0*/, const std::string& name /*= ""*/) : m_Name(name) diff --git a/source/modules/asura-utils/threading/thread.h b/source/modules/asura-utils/Threads/Thread.h index 0235b6a..bc6f14e 100644 --- a/source/modules/asura-utils/threading/thread.h +++ b/source/modules/asura-utils/Threads/Thread.h @@ -1,18 +1,18 @@ -#ifndef __ASURA_THREAD_H__ -#define __ASURA_THREAD_H__ +#ifndef _ASURA_THREAD_H_ +#define _ASURA_THREAD_H_ #include <string> #include <queue> -#include <asura-utils/scripting/portable.hpp> +#include <asura-utils/Scripting/Portable.hpp> -#include "task.h" -#include "mutex.h" -#include "semaphore.h" -#include "threadable.h" +#include "Task.h" +#include "Mutex.h" +#include "Semaphore.h" +#include "Threadable.h" namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) class ThreadImpl; diff --git a/source/modules/asura-utils/Threads/ThreadImplPosix.cpp b/source/modules/asura-utils/Threads/ThreadImplPosix.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-utils/Threads/ThreadImplPosix.cpp diff --git a/source/modules/asura-utils/Threads/ThreadImplPosix.h b/source/modules/asura-utils/Threads/ThreadImplPosix.h new file mode 100644 index 0000000..3089f0a --- /dev/null +++ b/source/modules/asura-utils/Threads/ThreadImplPosix.h @@ -0,0 +1,2 @@ +#include <asura-utils/Classes.h> + diff --git a/source/modules/asura-utils/Threads/ThreadImplSDL.cpp b/source/modules/asura-utils/Threads/ThreadImplSDL.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-utils/Threads/ThreadImplSDL.cpp diff --git a/source/modules/asura-utils/Threads/ThreadImplSDL.h b/source/modules/asura-utils/Threads/ThreadImplSDL.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-utils/Threads/ThreadImplSDL.h diff --git a/source/modules/asura-utils/Threads/ThreadImplStd.cpp b/source/modules/asura-utils/Threads/ThreadImplStd.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-utils/Threads/ThreadImplStd.cpp diff --git a/source/modules/asura-utils/threading/thread_impl_std.h b/source/modules/asura-utils/Threads/ThreadImplStd.h index a2623ee..452f569 100644 --- a/source/modules/asura-utils/threading/thread_impl_std.h +++ b/source/modules/asura-utils/Threads/ThreadImplStd.h @@ -1,16 +1,16 @@ -#ifndef __ASURA_THREAD_STD_H__ -#define __ASURA_THREAD_STD_H__ +#ifndef _ASURA_THREAD_STD_H_ +#define _ASURA_THREAD_STD_H_ -#include "../utils_config.h" +#include "../UtilsConfig.h" #if ASURA_THREAD_STD #include <windows.h> -#include "thread.h" +#include "Thread.h" namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) /// /// Threadstd::threadʵ֡ @@ -38,4 +38,4 @@ namespace_end #endif // #if ASURA_THREAD_STD -#endif // __ASURA_THREAD_STD_H__
\ No newline at end of file +#endif // _ASURA_THREAD_STD_H_
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/thread_impl_win32.cpp b/source/modules/asura-utils/Threads/ThreadImplWin32.cpp index c876be9..2467f87 100644 --- a/source/modules/asura-utils/threading/thread_impl_win32.cpp +++ b/source/modules/asura-utils/Threads/ThreadImplWin32.cpp @@ -1,12 +1,12 @@ -#include "thread_impl_win32.h" -#include "thread.h" +#include "ThreadImplWin32.h" +#include "Thread.h" #include <iostream> #if ASURA_THREAD_WIN32 namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) static DWORD WINAPI _thread_win32_runner(LPVOID param) { diff --git a/source/modules/asura-utils/threading/thread_impl_win32.h b/source/modules/asura-utils/Threads/ThreadImplWin32.h index 846670b..93ca477 100644 --- a/source/modules/asura-utils/threading/thread_impl_win32.h +++ b/source/modules/asura-utils/Threads/ThreadImplWin32.h @@ -1,7 +1,7 @@ -#ifndef __ASURA_THREAD_WIN32_H__ -#define __ASURA_THREAD_WIN32_H__ +#ifndef _ASURA_THREAD_WIN32_H__ +#define _ASURA_THREAD_WIN32_H__ -#include "../utils_config.h" +#include "../UtilsConfig.h" #if ASURA_THREAD_WIN32 @@ -10,7 +10,7 @@ #include "thread.h" namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) /// /// Threadwin32ʵ֡ @@ -41,4 +41,4 @@ namespace_end namespace_end #endif // #if ASURA_THREAD_WIN32 -#endif // __ASURA_THREAD_WIN32_H__
\ No newline at end of file +#endif // _ASURA_THREAD_WIN32_H__
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/threadable.h b/source/modules/asura-utils/Threads/Threadable.h index 66973c5..fce7350 100644 --- a/source/modules/asura-utils/threading/threadable.h +++ b/source/modules/asura-utils/Threads/Threadable.h @@ -1,10 +1,10 @@ -#ifndef __ASURA_THREADABLE_H__ -#define __ASURA_THREADABLE_H__ +#ifndef _ASURA_THREADABLE_H_ +#define _ASURA_THREADABLE_H_ -#include "../type.h" +#include "../Type.h" namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) ASURA_ABSTRACT class Threadable { diff --git a/source/modules/asura-utils/threading/binding/_coroutine.cpp b/source/modules/asura-utils/Threads/binding/_coroutine.cpp index a710623..0656079 100644 --- a/source/modules/asura-utils/threading/binding/_coroutine.cpp +++ b/source/modules/asura-utils/Threads/binding/_coroutine.cpp @@ -1,9 +1,9 @@ -#include "../coroutine.h" +#include "../Coroutine.h" using namespace std; namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) LUAX_REGISTRY(Coroutine) { diff --git a/source/modules/asura-utils/threading/binding/_thread.cpp b/source/modules/asura-utils/Threads/binding/_thread.cpp index b835453..aaa9e8d 100644 --- a/source/modules/asura-utils/threading/binding/_thread.cpp +++ b/source/modules/asura-utils/Threads/binding/_thread.cpp @@ -1,9 +1,9 @@ -#include "../thread.h" +#include "../Thread.h" using namespace std; namespace_begin(AsuraEngine) -namespace_begin(Threading) +namespace_begin(Threads) LUAX_REGISTRY(Thread) { diff --git a/source/modules/asura-utils/Type.h b/source/modules/asura-utils/Type.h new file mode 100644 index 0000000..f7e54c6 --- /dev/null +++ b/source/modules/asura-utils/Type.h @@ -0,0 +1,34 @@ +#ifndef _ASURA_UTILS_TYPE_H_ +#define _ASURA_UTILS_TYPE_H_ + +#include <cstdlib> +#include <stdint.h> + +#include "asura-base/Config.h" + +namespace AsuraEngine +{ + + //--------------------------------------------------------------------------------// + + typedef int8_t int8; + typedef uint8_t uint8; + //typedef uint8 byte; + typedef char byte; + typedef int16_t int16; + typedef uint16_t uint16; + typedef int32_t int32; + typedef uint32_t uint32; + typedef int64_t int64; + typedef uint64_t uint64; + + typedef uint32_t uint; + typedef int32_t sint; + + typedef std::size_t size_t; + + typedef const char cc8; + +} // namespace AsuraEngine + +#endif // _ASURA_CONFIG_H_
\ No newline at end of file diff --git a/source/modules/asura-utils/Utils.h b/source/modules/asura-utils/Utils.h new file mode 100644 index 0000000..dfcd2a6 --- /dev/null +++ b/source/modules/asura-utils/Utils.h @@ -0,0 +1,6 @@ +#ifndef _ASURA_UTILS_H_ +#define _ASURA_UTILS_H_ + +#include "UtilsModule.h" + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/utils_config.h b/source/modules/asura-utils/UtilsConfig.h index 7b120f0..89a605d 100644 --- a/source/modules/asura-utils/utils_config.h +++ b/source/modules/asura-utils/UtilsConfig.h @@ -1,8 +1,8 @@ -#ifndef __ASURA_UTILS_CONFIG_H__ -#define __ASURA_UTILS_CONFIG_H__ +#ifndef _ASURA_UTILS_CONFIG_H_ +#define _ASURA_UTILS_CONFIG_H_ // ı -#include "asura-base/config.h" +#include "asura-base/Config.h" #define ASURA_THREAD_WIN32 1 #define ASURA_THREAD_STD 1 diff --git a/source/modules/asura-utils/utils_module.cpp b/source/modules/asura-utils/UtilsModule.cpp index 5616be4..5735270 100644 --- a/source/modules/asura-utils/utils_module.cpp +++ b/source/modules/asura-utils/UtilsModule.cpp @@ -1,7 +1,7 @@ -#include "utils_module.h" +#include "UtilsModule.h" using namespace AsuraEngine::IO; -using namespace AsuraEngine::Threading; +using namespace AsuraEngine::Threads; namespace AsuraEngine { @@ -14,7 +14,7 @@ namespace AsuraEngine LUAX_REGISTER_FACTORY(state, DataBuffer); LUAX_REGISTER_FACTORY(state, FileData); LUAX_REGISTER_FACTORY(state, File); - // Threading + // Threads LUAX_REGISTER_FACTORY(state, Thread); } diff --git a/source/modules/asura-utils/UtilsModule.h b/source/modules/asura-utils/UtilsModule.h new file mode 100644 index 0000000..b61dca9 --- /dev/null +++ b/source/modules/asura-utils/UtilsModule.h @@ -0,0 +1,34 @@ +#ifndef _ASURA_LIBS_UTIL_MODULE_H_ +#define _ASURA_LIBS_UTIL_MODULE_H_ + +#include "IO/FileSystem.h" +#include "IO/DataBuffer.h" +#include "IO/FileData.h" +#include "IO/file.h" +#include "IO/IOTask.h" + +#include "Threads/Thread.h" + +#include "Module.h" + +#include "Classes.h" + +namespace AsuraEngine +{ + + /// + /// Asuraģ + /// + class UtilsModule ASURA_FINAL : public Module + { + public: + + void Initialize(Luax::LuaxState& state) override; + + void Finalize(Luax::LuaxState& state) override; + + }; + +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/classes.h b/source/modules/asura-utils/classes.h index 8c89b6a..d92c3d4 100644 --- a/source/modules/asura-utils/classes.h +++ b/source/modules/asura-utils/classes.h @@ -1,5 +1,5 @@ -#ifndef __ASURAENGINE_CLASSES_H__ -#define __ASURAENGINE_CLASSES_H__ +#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; } diff --git a/source/modules/asura-utils/exceptions/exception.h b/source/modules/asura-utils/exceptions/exception.h index 4acbc1e..73c0861 100644 --- a/source/modules/asura-utils/exceptions/exception.h +++ b/source/modules/asura-utils/exceptions/exception.h @@ -1,5 +1,5 @@ -#ifndef __ASURA_ENGINE_EXCEPTION_H__ -#define __ASURA_ENGINE_EXCEPTION_H__ +#ifndef _ASURA_ENGINE_EXCEPTION_H_ +#define _ASURA_ENGINE_EXCEPTION_H_ #include <string> #include <exception> diff --git a/source/modules/asura-utils/io/binding/_data_buffer.cpp b/source/modules/asura-utils/io/binding/_data_buffer.cpp index ac240e5..9d3f3a0 100644 --- a/source/modules/asura-utils/io/binding/_data_buffer.cpp +++ b/source/modules/asura-utils/io/binding/_data_buffer.cpp @@ -1,4 +1,4 @@ -#include "../data_buffer.h" +#include "../DataBuffer.h" using namespace Luax; diff --git a/source/modules/asura-utils/io/binding/_file_data.cpp b/source/modules/asura-utils/io/binding/_file_data.cpp index f4f6584..55cbc8b 100644 --- a/source/modules/asura-utils/io/binding/_file_data.cpp +++ b/source/modules/asura-utils/io/binding/_file_data.cpp @@ -1,4 +1,4 @@ -#include "../file_data.h" +#include "../FileData.h" using namespace std; diff --git a/source/modules/asura-utils/io/binding/_file_system.cpp b/source/modules/asura-utils/io/binding/_file_system.cpp index 0dc24d0..ace3c5f 100644 --- a/source/modules/asura-utils/io/binding/_file_system.cpp +++ b/source/modules/asura-utils/io/binding/_file_system.cpp @@ -1,4 +1,4 @@ -#include "../file_system.h" +#include "../FileSystem.h" using namespace Luax; diff --git a/source/modules/asura-utils/io/binding/_io_task.cpp b/source/modules/asura-utils/io/binding/_io_task.cpp index 4da8dc3..058f4fd 100644 --- a/source/modules/asura-utils/io/binding/_io_task.cpp +++ b/source/modules/asura-utils/io/binding/_io_task.cpp @@ -1,4 +1,4 @@ -#include "../io_task.h" +#include "../IOTask.h" using namespace std; diff --git a/source/modules/asura-utils/io/compressor.cpp b/source/modules/asura-utils/io/compressor.cpp index 095eff4..4202263 100644 --- a/source/modules/asura-utils/io/compressor.cpp +++ b/source/modules/asura-utils/io/compressor.cpp @@ -1,4 +1,4 @@ -#include "compressor.h" +#include "Compressor.h" namespace AsuraEngine { diff --git a/source/modules/asura-utils/io/compressor.h b/source/modules/asura-utils/io/compressor.h index 65fd88a..dc25e2a 100644 --- a/source/modules/asura-utils/io/compressor.h +++ b/source/modules/asura-utils/io/compressor.h @@ -1,7 +1,7 @@ -#ifndef __ASURA_COMPRESSOR_H__ -#define __ASURA_COMPRESSOR_H__ +#ifndef _ASURA_COMPRESSOR_H_ +#define _ASURA_COMPRESSOR_H_ -#include "../scripting/portable.hpp" +#include "../Scripting/Portable.hpp" namespace AsuraEngine { diff --git a/source/modules/asura-utils/io/file.cpp b/source/modules/asura-utils/io/file.cpp index a2f7403..6d5f4eb 100644 --- a/source/modules/asura-utils/io/file.cpp +++ b/source/modules/asura-utils/io/file.cpp @@ -1,8 +1,8 @@ #include <physfs/physfs.h> -#include <asura-utils/exceptions/exception.h> +#include <asura-utils/Exceptions/Exception.h> -#include "file.h" +#include "File.h" namespace AsuraEngine { diff --git a/source/modules/asura-utils/io/file.h b/source/modules/asura-utils/io/file.h index 16de42b..d11fa4f 100644 --- a/source/modules/asura-utils/io/file.h +++ b/source/modules/asura-utils/io/file.h @@ -1,12 +1,12 @@ -#ifndef __ASURA_ENGINE_FILE_H__ -#define __ASURA_ENGINE_FILE_H__ +#ifndef _ASURA_ENGINE_FILE_H_ +#define _ASURA_ENGINE_FILE_H_ #include "physfs/physfs.h" -#include "../scripting/portable.hpp" -#include "../threading/thread.h" +#include "../Scripting/Portable.hpp" +#include "../Threads/Thread.h" -#include "file_data.h" +#include "FileData.h" namespace AsuraEngine { diff --git a/source/modules/asura-utils/io/renewable.h b/source/modules/asura-utils/io/renewable.h index fd6c638..90867f2 100644 --- a/source/modules/asura-utils/io/renewable.h +++ b/source/modules/asura-utils/io/renewable.h @@ -3,7 +3,7 @@ #include "../scripting/portable.hpp" -#include "decoded_data.h" +#include "DecodedData.h" namespace AsuraEngine { diff --git a/source/modules/asura-utils/manager.hpp b/source/modules/asura-utils/manager.hpp index 7b4e272..c6817b1 100644 --- a/source/modules/asura-utils/manager.hpp +++ b/source/modules/asura-utils/manager.hpp @@ -1,5 +1,5 @@ -#ifndef __ASURA_ENGINE_MANAGER_H__ -#define __ASURA_ENGINE_MANAGER_H__ +#ifndef _ASURA_ENGINE_MANAGER_H_ +#define _ASURA_ENGINE_MANAGER_H_ namespace AsuraEngine { diff --git a/source/modules/asura-utils/math/matrix44.cpp b/source/modules/asura-utils/math/matrix44.cpp index 4472cd8..9ecf448 100644 --- a/source/modules/asura-utils/math/matrix44.cpp +++ b/source/modules/asura-utils/math/matrix44.cpp @@ -1,4 +1,4 @@ -#include "matrix44.h" +#include "Matrix44.h" #include <cstring> // memcpy #include <cmath> diff --git a/source/modules/asura-utils/math/matrix44.h b/source/modules/asura-utils/math/matrix44.h index 30033c5..7b66920 100644 --- a/source/modules/asura-utils/math/matrix44.h +++ b/source/modules/asura-utils/math/matrix44.h @@ -1,7 +1,7 @@ -#ifndef __ASURA_MATRIX_H__ -#define __ASURA_MATRIX_H__ +#ifndef _ASURA_MATRIX_H_ +#define _ASURA_MATRIX_H_ -#include "../scripting/portable.hpp" +#include "../Scripting/Portable.hpp" namespace AsuraEngine { diff --git a/source/modules/asura-utils/math/rect.hpp b/source/modules/asura-utils/math/rect.hpp index 010a5db..45bf1ba 100644 --- a/source/modules/asura-utils/math/rect.hpp +++ b/source/modules/asura-utils/math/rect.hpp @@ -1,5 +1,5 @@ -#ifndef __ASURA_ENGINE_RECT_H__ -#define __ASURA_ENGINE_RECT_H__ +#ifndef _ASURA_ENGINE_RECT_H_ +#define _ASURA_ENGINE_RECT_H_ namespace AsuraEngine { @@ -34,7 +34,7 @@ namespace AsuraEngine T x, y, w, h; }; -#include "Rect.inl" +#include "Rect.inc" // Define the most common types typedef Rect<int> Recti; diff --git a/source/modules/asura-utils/math/transform.h b/source/modules/asura-utils/math/transform.h index be4c850..23d0709 100644 --- a/source/modules/asura-utils/math/transform.h +++ b/source/modules/asura-utils/math/transform.h @@ -1,7 +1,7 @@ -#ifndef __ASURA_ENGINE_TRANSFORM_H__ -#define __ASURA_ENGINE_TRANSFORM_H__ +#ifndef _ASURA_ENGINE_TRANSFORM_H_ +#define _ASURA_ENGINE_TRANSFORM_H_ -#include "../scripting/portable.hpp" +#include "../scripting/Portable.hpp" namespace AsuraEngine { diff --git a/source/modules/asura-utils/math/vector2.hpp b/source/modules/asura-utils/math/vector2.hpp index e18bbdf..f2405eb 100644 --- a/source/modules/asura-utils/math/vector2.hpp +++ b/source/modules/asura-utils/math/vector2.hpp @@ -1,5 +1,5 @@ -#ifndef __ASURA_ENGINE_VECTOR2_H__ -#define __ASURA_ENGINE_VECTOR2_H__ +#ifndef _ASURA_ENGINE_VECTOR2_H__ +#define _ASURA_ENGINE_VECTOR2_H__ namespace AsuraEngine { @@ -57,7 +57,7 @@ namespace AsuraEngine template <typename T> bool operator !=(const Vector2<T>& left, const Vector2<T>& right); -#include "Vector2.inl" +#include "Vector2.inc" // Define the most common types typedef Vector2<int> Vector2i; diff --git a/source/modules/asura-utils/math/vector3.hpp b/source/modules/asura-utils/math/vector3.hpp index 2b23406..8da57cf 100644 --- a/source/modules/asura-utils/math/vector3.hpp +++ b/source/modules/asura-utils/math/vector3.hpp @@ -1,5 +1,5 @@ -#ifndef __ASURA_ENGINE_VECTOR3_H__ -#define __ASURA_ENGINE_VECTOR3_H__ +#ifndef _ASURA_ENGINE_VECTOR3_H__ +#define _ASURA_ENGINE_VECTOR3_H__ namespace AsuraEngine { @@ -221,7 +221,7 @@ namespace AsuraEngine template <typename T> bool operator !=(const Vector3<T>& left, const Vector3<T>& right); -#include "Vector3.inl" +#include "Vector3.inc" // Define the most common types typedef Vector3<int> Vector3i; diff --git a/source/modules/asura-utils/math/vector4.h b/source/modules/asura-utils/math/vector4.h index 13a9d8a..a5bf549 100644 --- a/source/modules/asura-utils/math/vector4.h +++ b/source/modules/asura-utils/math/vector4.h @@ -1,5 +1,5 @@ -#ifndef __ASURA_ENGINE_VECTOR4_H__ -#define __ASURA_ENGINE_VECTOR4_H__ +#ifndef _ASURA_ENGINE_VECTOR4_H__ +#define _ASURA_ENGINE_VECTOR4_H__ namespace AsuraEngine { @@ -222,7 +222,7 @@ namespace AsuraEngine template <typename T> bool operator !=(const Vector4<T>& left, const Vector4<T>& right); -#include "Vector4.inl" +#include "Vector4.inc" // Define the most common types typedef Vector4<int> Vector4i; diff --git a/source/modules/asura-utils/module.h b/source/modules/asura-utils/module.h index b22c68c..2cc91d6 100644 --- a/source/modules/asura-utils/module.h +++ b/source/modules/asura-utils/module.h @@ -1,8 +1,8 @@ -#ifndef __ASURA_MODULE_H__ -#define __ASURA_MODULE_H__ +#ifndef _ASURA_MODULE_H_ +#define _ASURA_MODULE_H_ -#include "type.h" -#include "scripting/portable.hpp" +#include "Type.h" +#include "Scripting/Portable.hpp" namespace AsuraEngine { diff --git a/source/modules/asura-utils/scripting/portable.hpp b/source/modules/asura-utils/scripting/portable.hpp index d691455..1eee123 100644 --- a/source/modules/asura-utils/scripting/portable.hpp +++ b/source/modules/asura-utils/scripting/portable.hpp @@ -1,5 +1,5 @@ -#ifndef __ASURA_ENGINE_PORTABLE_H__ -#define __ASURA_ENGINE_PORTABLE_H__ +#ifndef _ASURA_ENGINE_PORTABLE_H_ +#define _ASURA_ENGINE_PORTABLE_H_ extern "C" { #include <lua51/lua.h> @@ -8,12 +8,12 @@ extern "C" { } #include <luax/luax.h> -#include "../type.h" -namespace AsuraEngine -{ -namespace Scripting -{ +#include "../Type.h" +#include "../Classes.h" + +namespace_begin(AsuraEngine) +namespace_begin(Scripting) /// ҪΪ࣬userdatamember ref̳д࣬ע̳С @@ -23,8 +23,8 @@ using Object = Luax::LuaxObject; template<typename TYPE, typename BASE = Luax::LuaxObject> using Portable = Luax::LuaxNativeClass<TYPE, BASE>; -} -} +namespace_end +namespace_end namespace AEScripting = AsuraEngine::Scripting; diff --git a/source/modules/asura-utils/singleton.hpp b/source/modules/asura-utils/singleton.hpp index 0d2777e..9bb7336 100644 --- a/source/modules/asura-utils/singleton.hpp +++ b/source/modules/asura-utils/singleton.hpp @@ -1,7 +1,7 @@ -#ifndef __ASURA_SINGLETON_H__ -#define __ASURA_SINGLETON_H__ +#ifndef _ASURA_SINGLETON_H_ +#define _ASURA_SINGLETON_H_ -#include "utils_config.h" +#include "UtilsConfig.h" namespace AsuraEngine { @@ -56,4 +56,4 @@ namespace AsuraEngine } -#endif // __ASURA_SINGLETON_H__
\ No newline at end of file +#endif // _ASURA_SINGLETON_H_
\ No newline at end of file diff --git a/source/modules/asura-utils/stringmap.hpp b/source/modules/asura-utils/stringmap.hpp index 8d8f231..15d28ee 100644 --- a/source/modules/asura-utils/stringmap.hpp +++ b/source/modules/asura-utils/stringmap.hpp @@ -1,5 +1,5 @@ -#ifndef __ASURA_ENGINE_STRINGMAP_H__ -#define __ASURA_ENGINE_STRINGMAP_H__ +#ifndef _ASURA_ENGINE_STRINGMAP_H_ +#define _ASURA_ENGINE_STRINGMAP_H_ #include <string> diff --git a/source/modules/asura-utils/threading/thread_impl_posix.cpp b/source/modules/asura-utils/threading/thread_impl_posix.cpp deleted file mode 100644 index d59bd8f..0000000 --- a/source/modules/asura-utils/threading/thread_impl_posix.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "thread_impl_posix.h" - -namespace_begin(AsuraEngine) -namespace_begin(Threading) - - - -namespace_end -namespace_end
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/thread_impl_posix.h b/source/modules/asura-utils/threading/thread_impl_posix.h deleted file mode 100644 index a65a2ca..0000000 --- a/source/modules/asura-utils/threading/thread_impl_posix.h +++ /dev/null @@ -1,2 +0,0 @@ -#include <asura-utils/classes.h> - diff --git a/source/modules/asura-utils/type.h b/source/modules/asura-utils/type.h index 2976d3e..f7e54c6 100644 --- a/source/modules/asura-utils/type.h +++ b/source/modules/asura-utils/type.h @@ -1,10 +1,10 @@ -#ifndef __ASURA_UTILS_TYPE_H__ -#define __ASURA_UTILS_TYPE_H__ +#ifndef _ASURA_UTILS_TYPE_H_ +#define _ASURA_UTILS_TYPE_H_ #include <cstdlib> #include <stdint.h> -#include "asura-base/config.h" +#include "asura-base/Config.h" namespace AsuraEngine { @@ -31,4 +31,4 @@ namespace AsuraEngine } // namespace AsuraEngine -#endif // __ASURA_CONFIG_H__
\ No newline at end of file +#endif // _ASURA_CONFIG_H_
\ No newline at end of file diff --git a/source/modules/asura-utils/utils.h b/source/modules/asura-utils/utils.h index ce1c6a1..dfcd2a6 100644 --- a/source/modules/asura-utils/utils.h +++ b/source/modules/asura-utils/utils.h @@ -1,6 +1,6 @@ -#ifndef __ASURA_UTILS_H__ -#define __ASURA_UTILS_H__ +#ifndef _ASURA_UTILS_H_ +#define _ASURA_UTILS_H_ -#include "utils_module.h" +#include "UtilsModule.h" #endif
\ No newline at end of file diff --git a/source/modules/asura-utils/utils_module.h b/source/modules/asura-utils/utils_module.h deleted file mode 100644 index 479b052..0000000 --- a/source/modules/asura-utils/utils_module.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef __ASURA_LIBS_UTIL_MODULE_H__ -#define __ASURA_LIBS_UTIL_MODULE_H__ - -#include "io/file_system.h" -#include "io/data_buffer.h" -#include "io/file_data.h" -#include "io/file.h" -#include "io/io_task.h" - -#include "threading/thread.h" - -#include "module.h" - -#include "classes.h" - -namespace AsuraEngine -{ - - /// - /// Asuraģ - /// - class UtilsModule ASURA_FINAL : public Module - { - public: - - void Initialize(Luax::LuaxState& state) override; - - void Finalize(Luax::LuaxState& state) override; - - }; - -} - -#endif
\ No newline at end of file |