From c302f5ae5f9e30a28e487e8a764d9cc31546bbea Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 29 Mar 2019 22:51:04 +0800 Subject: *rename --- .../libs/asura-lib-utils/exceptions/exception.cpp | 47 ---- source/libs/asura-lib-utils/exceptions/exception.h | 44 ---- .../asura-lib-utils/io/binding/_compressor.cpp | 0 .../asura-lib-utils/io/binding/_data_buffer.cpp | 123 --------- source/libs/asura-lib-utils/io/binding/_file.cpp | 223 ---------------- .../libs/asura-lib-utils/io/binding/_file_data.cpp | 60 ----- .../asura-lib-utils/io/binding/_file_system.cpp | 265 ------------------- .../libs/asura-lib-utils/io/binding/_io_task.cpp | 46 ---- source/libs/asura-lib-utils/io/compressor.cpp | 11 - source/libs/asura-lib-utils/io/compressor.h | 30 --- source/libs/asura-lib-utils/io/data_buffer.cpp | 102 ------- source/libs/asura-lib-utils/io/data_buffer.h | 62 ----- source/libs/asura-lib-utils/io/decoded_data.cpp | 21 -- source/libs/asura-lib-utils/io/decoded_data.h | 42 --- source/libs/asura-lib-utils/io/file.cpp | 292 --------------------- source/libs/asura-lib-utils/io/file.h | 146 ----------- source/libs/asura-lib-utils/io/file_data.cpp | 52 ---- source/libs/asura-lib-utils/io/file_data.h | 69 ----- source/libs/asura-lib-utils/io/file_system.cpp | 198 -------------- source/libs/asura-lib-utils/io/file_system.h | 112 -------- source/libs/asura-lib-utils/io/io_batch_task.cpp | 0 source/libs/asura-lib-utils/io/io_batch_task.h | 31 --- source/libs/asura-lib-utils/io/io_task.cpp | 55 ---- source/libs/asura-lib-utils/io/io_task.h | 57 ---- source/libs/asura-lib-utils/io/reloadable.h | 29 -- source/libs/asura-lib-utils/manager.hpp | 14 - source/libs/asura-lib-utils/math/curve.cpp | 0 source/libs/asura-lib-utils/math/curve.h | 0 source/libs/asura-lib-utils/math/functions.cpp | 0 source/libs/asura-lib-utils/math/functions.h | 0 source/libs/asura-lib-utils/math/matrix44.cpp | 0 source/libs/asura-lib-utils/math/matrix44.h | 24 -- source/libs/asura-lib-utils/math/quaternion.cpp | 0 source/libs/asura-lib-utils/math/quaternion.h | 0 source/libs/asura-lib-utils/math/ranged_value.cpp | 0 source/libs/asura-lib-utils/math/ranged_value.h | 0 source/libs/asura-lib-utils/math/rect.hpp | 47 ---- source/libs/asura-lib-utils/math/rect.inl | 19 -- source/libs/asura-lib-utils/math/transform.cpp | 0 source/libs/asura-lib-utils/math/transform.h | 30 --- source/libs/asura-lib-utils/math/vector2.hpp | 70 ----- source/libs/asura-lib-utils/math/vector2.inl | 114 -------- source/libs/asura-lib-utils/math/vector3.hpp | 233 ---------------- source/libs/asura-lib-utils/math/vector3.inl | 145 ---------- source/libs/asura-lib-utils/math/vector4.h | 234 ----------------- source/libs/asura-lib-utils/math/vector4.inl | 152 ----------- source/libs/asura-lib-utils/module.h | 32 --- source/libs/asura-lib-utils/scripting/lua_env.h | 72 ----- source/libs/asura-lib-utils/scripting/portable.hpp | 29 -- source/libs/asura-lib-utils/singleton.hpp | 59 ----- source/libs/asura-lib-utils/stringmap.cpp | 0 source/libs/asura-lib-utils/stringmap.hpp | 29 -- .../threading/binding/_coroutine.cpp | 40 --- .../asura-lib-utils/threading/binding/_thread.cpp | 210 --------------- .../libs/asura-lib-utils/threading/coroutine.cpp | 16 -- source/libs/asura-lib-utils/threading/coroutine.h | 40 --- source/libs/asura-lib-utils/threading/mutex.cpp | 106 -------- source/libs/asura-lib-utils/threading/mutex.h | 126 --------- .../libs/asura-lib-utils/threading/semaphore.cpp | 88 ------- source/libs/asura-lib-utils/threading/semaphore.h | 70 ----- source/libs/asura-lib-utils/threading/task.cpp | 12 - source/libs/asura-lib-utils/threading/task.h | 45 ---- source/libs/asura-lib-utils/threading/thread.cpp | 272 ------------------- source/libs/asura-lib-utils/threading/thread.h | 221 ---------------- .../threading/thread_impl_posix.cpp | 9 - .../asura-lib-utils/threading/thread_impl_posix.h | 0 .../asura-lib-utils/threading/thread_impl_sdl.cpp | 0 .../asura-lib-utils/threading/thread_impl_sdl.h | 0 .../asura-lib-utils/threading/thread_impl_std.cpp | 0 .../asura-lib-utils/threading/thread_impl_std.h | 43 --- .../threading/thread_impl_win32.cpp | 76 ------ .../asura-lib-utils/threading/thread_impl_win32.h | 47 ---- .../libs/asura-lib-utils/threading/thread_task.cpp | 0 .../libs/asura-lib-utils/threading/thread_task.h | 44 ---- source/libs/asura-lib-utils/type.h | 85 ------ source/libs/asura-lib-utils/utils.h | 6 - source/libs/asura-lib-utils/utils_config.h | 10 - source/libs/asura-lib-utils/utils_module.cpp | 25 -- source/libs/asura-lib-utils/utils_module.h | 32 --- 79 files changed, 5043 deletions(-) delete mode 100644 source/libs/asura-lib-utils/exceptions/exception.cpp delete mode 100644 source/libs/asura-lib-utils/exceptions/exception.h delete mode 100644 source/libs/asura-lib-utils/io/binding/_compressor.cpp delete mode 100644 source/libs/asura-lib-utils/io/binding/_data_buffer.cpp delete mode 100644 source/libs/asura-lib-utils/io/binding/_file.cpp delete mode 100644 source/libs/asura-lib-utils/io/binding/_file_data.cpp delete mode 100644 source/libs/asura-lib-utils/io/binding/_file_system.cpp delete mode 100644 source/libs/asura-lib-utils/io/binding/_io_task.cpp delete mode 100644 source/libs/asura-lib-utils/io/compressor.cpp delete mode 100644 source/libs/asura-lib-utils/io/compressor.h delete mode 100644 source/libs/asura-lib-utils/io/data_buffer.cpp delete mode 100644 source/libs/asura-lib-utils/io/data_buffer.h delete mode 100644 source/libs/asura-lib-utils/io/decoded_data.cpp delete mode 100644 source/libs/asura-lib-utils/io/decoded_data.h delete mode 100644 source/libs/asura-lib-utils/io/file.cpp delete mode 100644 source/libs/asura-lib-utils/io/file.h delete mode 100644 source/libs/asura-lib-utils/io/file_data.cpp delete mode 100644 source/libs/asura-lib-utils/io/file_data.h delete mode 100644 source/libs/asura-lib-utils/io/file_system.cpp delete mode 100644 source/libs/asura-lib-utils/io/file_system.h delete mode 100644 source/libs/asura-lib-utils/io/io_batch_task.cpp delete mode 100644 source/libs/asura-lib-utils/io/io_batch_task.h delete mode 100644 source/libs/asura-lib-utils/io/io_task.cpp delete mode 100644 source/libs/asura-lib-utils/io/io_task.h delete mode 100644 source/libs/asura-lib-utils/io/reloadable.h delete mode 100644 source/libs/asura-lib-utils/manager.hpp delete mode 100644 source/libs/asura-lib-utils/math/curve.cpp delete mode 100644 source/libs/asura-lib-utils/math/curve.h delete mode 100644 source/libs/asura-lib-utils/math/functions.cpp delete mode 100644 source/libs/asura-lib-utils/math/functions.h delete mode 100644 source/libs/asura-lib-utils/math/matrix44.cpp delete mode 100644 source/libs/asura-lib-utils/math/matrix44.h delete mode 100644 source/libs/asura-lib-utils/math/quaternion.cpp delete mode 100644 source/libs/asura-lib-utils/math/quaternion.h delete mode 100644 source/libs/asura-lib-utils/math/ranged_value.cpp delete mode 100644 source/libs/asura-lib-utils/math/ranged_value.h delete mode 100644 source/libs/asura-lib-utils/math/rect.hpp delete mode 100644 source/libs/asura-lib-utils/math/rect.inl delete mode 100644 source/libs/asura-lib-utils/math/transform.cpp delete mode 100644 source/libs/asura-lib-utils/math/transform.h delete mode 100644 source/libs/asura-lib-utils/math/vector2.hpp delete mode 100644 source/libs/asura-lib-utils/math/vector2.inl delete mode 100644 source/libs/asura-lib-utils/math/vector3.hpp delete mode 100644 source/libs/asura-lib-utils/math/vector3.inl delete mode 100644 source/libs/asura-lib-utils/math/vector4.h delete mode 100644 source/libs/asura-lib-utils/math/vector4.inl delete mode 100644 source/libs/asura-lib-utils/module.h delete mode 100644 source/libs/asura-lib-utils/scripting/lua_env.h delete mode 100644 source/libs/asura-lib-utils/scripting/portable.hpp delete mode 100644 source/libs/asura-lib-utils/singleton.hpp delete mode 100644 source/libs/asura-lib-utils/stringmap.cpp delete mode 100644 source/libs/asura-lib-utils/stringmap.hpp delete mode 100644 source/libs/asura-lib-utils/threading/binding/_coroutine.cpp delete mode 100644 source/libs/asura-lib-utils/threading/binding/_thread.cpp delete mode 100644 source/libs/asura-lib-utils/threading/coroutine.cpp delete mode 100644 source/libs/asura-lib-utils/threading/coroutine.h delete mode 100644 source/libs/asura-lib-utils/threading/mutex.cpp delete mode 100644 source/libs/asura-lib-utils/threading/mutex.h delete mode 100644 source/libs/asura-lib-utils/threading/semaphore.cpp delete mode 100644 source/libs/asura-lib-utils/threading/semaphore.h delete mode 100644 source/libs/asura-lib-utils/threading/task.cpp delete mode 100644 source/libs/asura-lib-utils/threading/task.h delete mode 100644 source/libs/asura-lib-utils/threading/thread.cpp delete mode 100644 source/libs/asura-lib-utils/threading/thread.h delete mode 100644 source/libs/asura-lib-utils/threading/thread_impl_posix.cpp delete mode 100644 source/libs/asura-lib-utils/threading/thread_impl_posix.h delete mode 100644 source/libs/asura-lib-utils/threading/thread_impl_sdl.cpp delete mode 100644 source/libs/asura-lib-utils/threading/thread_impl_sdl.h delete mode 100644 source/libs/asura-lib-utils/threading/thread_impl_std.cpp delete mode 100644 source/libs/asura-lib-utils/threading/thread_impl_std.h delete mode 100644 source/libs/asura-lib-utils/threading/thread_impl_win32.cpp delete mode 100644 source/libs/asura-lib-utils/threading/thread_impl_win32.h delete mode 100644 source/libs/asura-lib-utils/threading/thread_task.cpp delete mode 100644 source/libs/asura-lib-utils/threading/thread_task.h delete mode 100644 source/libs/asura-lib-utils/type.h delete mode 100644 source/libs/asura-lib-utils/utils.h delete mode 100644 source/libs/asura-lib-utils/utils_config.h delete mode 100644 source/libs/asura-lib-utils/utils_module.cpp delete mode 100644 source/libs/asura-lib-utils/utils_module.h (limited to 'source/libs/asura-lib-utils') diff --git a/source/libs/asura-lib-utils/exceptions/exception.cpp b/source/libs/asura-lib-utils/exceptions/exception.cpp deleted file mode 100644 index dbb36ca..0000000 --- a/source/libs/asura-lib-utils/exceptions/exception.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "Exception.h" - -#include -#include - -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); - - // see http://perfec.to/vsnprintf/pasprintf.c - // if size_out ... - // == -1 --> output was truncated - // == size_buffer --> output was truncated - // == size_buffer-1 --> ambiguous, /may/ have been truncated - // > size_buffer --> output was truncated, and size_out - // bytes would have been written - 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; // to avoid the ambiguous case - else - break; - - delete[] buffer; - } - message = std::string(buffer); - delete[] buffer; - } - - Exception::~Exception() throw() - { - } - -} diff --git a/source/libs/asura-lib-utils/exceptions/exception.h b/source/libs/asura-lib-utils/exceptions/exception.h deleted file mode 100644 index 57c9ed6..0000000 --- a/source/libs/asura-lib-utils/exceptions/exception.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef __ASURA_ENGINE_EXCEPTION_H__ -#define __ASURA_ENGINE_EXCEPTION_H__ - -#include -#include - -namespace AsuraEngine -{ - - /** - * A convenient vararg-enabled exception class. - **/ - class Exception : public std::exception - { - public: - - /** - * Creates a new Exception according to printf-rules. - * - * See: http://www.cplusplus.com/reference/clibrary/cstdio/printf/ - * - * @param fmt The format string (see printf). - **/ - Exception(const char *fmt, ...); - virtual ~Exception() throw(); - - /** - * Returns a string containing reason for the exception. - * @return A description of the exception. - **/ - 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/libs/asura-lib-utils/io/binding/_compressor.cpp b/source/libs/asura-lib-utils/io/binding/_compressor.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp b/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp deleted file mode 100644 index cd73b31..0000000 --- a/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp +++ /dev/null @@ -1,123 +0,0 @@ -#include "../data_buffer.h" - -using namespace Luax; - -namespace AsuraEngine -{ - namespace IO - { - - LUAX_REGISTRY(DataBuffer) - { - LUAX_REGISTER_METHODS(state, - { "New", _New }, - { "GetData", _GetData }, - { "GetSize", _GetSize }, - { "Refactor", _Refactor }, - { "Load", _Load }, - { "Clear", _Clear } - ); - } - - LUAX_POSTPROCESS(DataBuffer) - { - } - - // databuffer = DataBuffer.New(lstring) - // databuffer = DataBuffer.New(size) - 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 size = lua_tonumber(L, 1); - DataBuffer* buffer = new DataBuffer(size); - 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(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(1); - lua_pushinteger(L, self->GetSize()); - return 1; - } - - // databuffer:Refactor(size) - LUAX_IMPL_METHOD(DataBuffer, _Refactor) - { - LUAX_PREPARE(L, DataBuffer); - - size_t size = state.CheckValue(2); - self->Refactor(size); - return 0; - } - - // size = databuffer:Load(lstring) - // size = databuffer:Load(src) - LUAX_IMPL_METHOD(DataBuffer, _Load) - { - LUAX_STATE(L); - - DataBuffer* buffer = state.GetUserdata(1); - const byte* data; - size_t size; - if (state.IsType(2, LUA_TSTRING)) - { - data = lua_tolstring(L, 2, &size); - size_t len = buffer->Load(data, size); - state.Push(len); - return 1; - } - else if(state.IsType(2, LUA_TUSERDATA)) - { - DataBuffer* src = state.CheckUserdata(2); - size_t len = buffer->Load(*src); - state.Push(len); - return 1; - } - else - { - return state.ErrorType(1, "lstring or DataBuffer"); - } - } - - // databuffer:Clear() - LUAX_IMPL_METHOD(DataBuffer, _Clear) - { - LUAX_SETUP(L, "U"); - - DataBuffer* self = state.GetUserdata(1); - self->Clear(); - return 0; - } - - } -} \ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/binding/_file.cpp b/source/libs/asura-lib-utils/io/binding/_file.cpp deleted file mode 100644 index c44bc90..0000000 --- a/source/libs/asura-lib-utils/io/binding/_file.cpp +++ /dev/null @@ -1,223 +0,0 @@ -#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(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(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(2); - if (!db) return state.ErrorType(2, "DataBuffer"); - int len = state.CheckValue(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(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(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(2); - int size = state.CheckValue(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/libs/asura-lib-utils/io/binding/_file_data.cpp b/source/libs/asura-lib-utils/io/binding/_file_data.cpp deleted file mode 100644 index 09a0643..0000000 --- a/source/libs/asura-lib-utils/io/binding/_file_data.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "../file_data.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->mDataRef); - return 1; - } - - } -} \ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/binding/_file_system.cpp b/source/libs/asura-lib-utils/io/binding/_file_system.cpp deleted file mode 100644 index 3843451..0000000 --- a/source/libs/asura-lib-utils/io/binding/_file_system.cpp +++ /dev/null @@ -1,265 +0,0 @@ -#include "../file_system.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(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(1, ""); - cc8* moutpoint = state.GetValue(2, "/"); - bool prepend = state.GetValue(3, false); - mounted = fs->Mount(path, moutpoint, prepend); - } - else if (state.IsType(1, LUA_TUSERDATA)) - { - DataBuffer* db = state.CheckUserdata(1); - if (!db) - return state.ErrorType(1, "Data Buffer"); - cc8* arcname = state.GetValue(2, ""); - cc8* mountpoint = state.GetValue(3, "/"); - bool prepend = state.GetValue(4, false); - mounted = fs->Mount(db, arcname, mountpoint, prepend); - // retain - fs->LuaxRetain(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(1, ""); - unmounted = fs->Unmount(path); - } - else if (state.IsType(1, LUA_TUSERDATA)) - { - DataBuffer* db = state.CheckUserdata(1); - if (!db) - return state.ErrorType(1, "Data Buffer"); - unmounted = fs->Unmount(db); - if (unmounted) - fs->LuaxRelease(state, db); - } - state.Push(unmounted); - return 1; - } - - // moutpoint = Filesystem.GetMountPoint(path) - LUAX_IMPL_METHOD(Filesystem, _GetMountPoint) - { - PREPARE(L); - - cc8* path = state.CheckValue(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(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(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(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(1); - DataBuffer* db = state.CheckUserdata(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(1); - DataBuffer* db = state.CheckUserdata(2); - state.Push(fs->Append(path, db)); - return 1; - } - - // successed = Filesystem.Remove(path) - LUAX_IMPL_METHOD(Filesystem, _Remove) - { - PREPARE(L); - - cc8* path = state.CheckValue(1); - state.Push(fs->Remove(path)); - return 1; - } - - // filedata = Filesystem.Read(path) - LUAX_IMPL_METHOD(Filesystem, _Read) - { - PREPARE(L); - - cc8* path = state.CheckValue(1); - FileData* fd = fs->Read(path); - if (fd) - { - fd->mData->PushLuaxUserdata(state); - fd->SetLuaxMemberRef(state, fd->mDataRef, -1); // fd->mDataRef = 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(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(1); - std::vector 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/libs/asura-lib-utils/io/binding/_io_task.cpp b/source/libs/asura-lib-utils/io/binding/_io_task.cpp deleted file mode 100644 index b3c5988..0000000 --- a/source/libs/asura-lib-utils/io/binding/_io_task.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "../io_task.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(1); - DataBuffer* db = state.CheckUserdata(2); - IOTaskType type = (IOTaskType)state.CheckValue(3); - bool cbk = state.GetTop() >= 4 && state.IsType(4, LUA_TFUNCTION); - - IOTask* task = new IOTask(path, db, type); - task->SetLuaxMemberRef(state, task->mBufferRef, 2); - if(cbk) - task->SetLuaxMemberRef(state, task->mCallback, 4); - task->PushLuaxUserdata(state); - return 1; - } - - } -} diff --git a/source/libs/asura-lib-utils/io/compressor.cpp b/source/libs/asura-lib-utils/io/compressor.cpp deleted file mode 100644 index 095eff4..0000000 --- a/source/libs/asura-lib-utils/io/compressor.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "compressor.h" - -namespace AsuraEngine -{ - namespace IO - { - - - - } -} \ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/compressor.h b/source/libs/asura-lib-utils/io/compressor.h deleted file mode 100644 index 30a074c..0000000 --- a/source/libs/asura-lib-utils/io/compressor.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __ASURA_COMPRESSOR_H__ -#define __ASURA_COMPRESSOR_H__ - -#include "../scripting/portable.hpp" - -namespace AsuraEngine -{ - namespace IO - { - - class Compressor ASURA_FINAL - : public AEScripting::Portable - { - 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/libs/asura-lib-utils/io/data_buffer.cpp b/source/libs/asura-lib-utils/io/data_buffer.cpp deleted file mode 100644 index 5049b38..0000000 --- a/source/libs/asura-lib-utils/io/data_buffer.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include -#include -#include "data_buffer.h" - -using namespace AEThreading; - -namespace AsuraEngine -{ - namespace IO - { - - DataBuffer::DataBuffer(DataBuffer& src) - { - Load(src); - } - - DataBuffer::DataBuffer(std::size_t size) - : mSize(size) - , mBytes(nullptr) - { - lock(mMutex); - mBytes = new byte[size]; - memset(mBytes, 0, size); - } - - DataBuffer::DataBuffer(const void* data, std::size_t size) - : mSize(size) - , mBytes(nullptr) - { - Load(data, size); - } - - DataBuffer::~DataBuffer() - { - delete[] mBytes; - } - - void DataBuffer::Refactor(size_t size) - { - lock(mMutex); - if (!mBytes || mSize != size) - { - delete[] mBytes; - mBytes = new byte[size]; - mSize = size; - } - memset(mBytes, 0, size * sizeof(byte)); - } - - size_t DataBuffer::Load(DataBuffer& db) - { - return Load(db.GetData(), db.GetSize()); - } - - size_t DataBuffer::Load(const void* data, std::size_t size) - { - lock(mMutex); - size_t len = mSize > size ? size : mSize; - memcpy(mBytes, data, len); - return len; - } - - void DataBuffer::Move(void* bytes, std::size_t size) - { - lock(mMutex); - if (!mBytes) - { - delete[] mBytes; - } - mBytes = (byte*)bytes; - mSize = size; - } - - byte* DataBuffer::GetData() - { - return mBytes; - } - - void DataBuffer::Clear() - { - lock(mMutex); - if (mBytes) - memset(mBytes, 0, mSize); - } - - std::size_t DataBuffer::GetSize() - { - return mSize; - } - - void DataBuffer::Lock() - { - mMutex.Lock(); - } - - void DataBuffer::Unlock() - { - mMutex.Unlock(); - } - - } -} \ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/data_buffer.h b/source/libs/asura-lib-utils/io/data_buffer.h deleted file mode 100644 index 445bdf4..0000000 --- a/source/libs/asura-lib-utils/io/data_buffer.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef __ASURA_ENGINE_DATABUFFER_H__ -#define __ASURA_ENGINE_DATABUFFER_H__ - -#include - -#include "../scripting/portable.hpp" -#include "../threading/mutex.h" - -namespace AsuraEngine -{ - namespace IO - { - - /// - /// 对内存数据的封装,所有的数据使用Data buffer包装,不直接使用const void*。通过resource manager读取。 - /// - class DataBuffer ASURA_FINAL - : public AEScripting::Portable - { - public: - - LUAX_DECL_FACTORY(DataBuffer); - - DataBuffer(DataBuffer& src); - DataBuffer(std::size_t size); - DataBuffer(const void* bytes, std::size_t size); - ~DataBuffer(); - - byte* GetData(); - size_t GetSize(); - - void Refactor(size_t size); - size_t Load(DataBuffer& db); - size_t Load(const void* bytes, std::size_t size); - void Move(void* bytes, std::size_t size); - void Clear(); - - void Lock(); - void Unlock(); - - private: - - byte* mBytes; - size_t mSize; - - AEThreading::Mutex mMutex; - - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_GetData); - LUAX_DECL_METHOD(_GetSize); - LUAX_DECL_METHOD(_Refactor); - LUAX_DECL_METHOD(_Load); - LUAX_DECL_METHOD(_Clear); - - }; - - } -} - -namespace AEIO = AsuraEngine::IO; - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/decoded_data.cpp b/source/libs/asura-lib-utils/io/decoded_data.cpp deleted file mode 100644 index 358a7a5..0000000 --- a/source/libs/asura-lib-utils/io/decoded_data.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "../exceptions/exception.h" - -#include "decoded_data.h" - -namespace AsuraEngine -{ - namespace IO - { - - DecodedData::DecodedData(const DataBuffer& databuffer) - { - Decode(databuffer); - } - - DecodedData::~DecodedData() - { - - } - - } -} diff --git a/source/libs/asura-lib-utils/io/decoded_data.h b/source/libs/asura-lib-utils/io/decoded_data.h deleted file mode 100644 index e201e91..0000000 --- a/source/libs/asura-lib-utils/io/decoded_data.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef __ASURA_ENGINE_DATA_H__ -#define __ASURA_ENGINE_DATA_H__ - -#include - -#include "../scripting/portable.hpp" - -#include "data_buffer.h" - -namespace AsuraEngine -{ - namespace IO - { - - /// - /// 可以在另一个线程构建的data继承此类。如图片数据、音频数据等,可以在另一个线程中解析原文件,生成内部数据格式,如像素 - /// 等。 - /// - ASURA_ABSTRACT class DecodedData - { - public: - - /// - /// 从内存中构建data,可以放在另一个线程里面,从资源管理系统里面加载。 - /// - DecodedData(const DataBuffer& databuffer); - - virtual ~DecodedData(); - - protected: - - /// - /// 解码内存中的数据。 - /// - virtual void Decode(const DataBuffer& buffer) = 0; - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/file.cpp b/source/libs/asura-lib-utils/io/file.cpp deleted file mode 100644 index 0ff8c90..0000000 --- a/source/libs/asura-lib-utils/io/file.cpp +++ /dev/null @@ -1,292 +0,0 @@ -#include - -#include - -#include "file.h" - -namespace AsuraEngine -{ - namespace IO - { - - File::File(const std::string& filename) - : mFileName(filename) - , mFileHandle(nullptr) - , mMode(FILE_MODE_CLOSED) - , mBufferMode(BUFFER_MODE_NONE) - , mBufferSize(0) - { - size_t dot = filename.rfind('.'); - if (dot != std::string::npos) - { - mExtension = filename.substr(dot + 1); - mName = filename.substr(0, dot); - } - else - mName = filename; - } - - File::~File() - { - if (mMode != 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(mFileName.c_str())) - throw Exception("Could NOT open file %s. Does not exist.", mFileName.c_str()); - - if (mode == FILE_MODE_APPEND || mode == FILE_MODE_WRITE) - { - if (!PHYSFS_getWriteDir()) - { - throw Exception("Could NOT set write directory."); - } - } - - // 已经在之前打开过,就不再创建新的handle了 - if (mFileHandle != nullptr) - return true; - - PHYSFS_getLastErrorCode(); - - PHYSFS_File* handle = nullptr; - - switch (mode) - { - case FILE_MODE_READ: - handle = PHYSFS_openRead(mFileName.c_str()); - break; - case FILE_MODE_APPEND: - handle = PHYSFS_openAppend(mFileName.c_str()); - break; - case FILE_MODE_WRITE: - handle = PHYSFS_openWrite(mFileName.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)", mFileName.c_str(), err); - } - - mFileHandle = handle; - mMode = mode; - - if (mFileHandle && !SetBuffer(mBufferMode,mBufferSize)) - { - mBufferMode = BUFFER_MODE_NONE; - mBufferSize = 0; - } - - return mFileHandle != nullptr; - } - - bool File::Close() - { - if (mFileHandle == nullptr || !PHYSFS_close(mFileHandle)) - return false; - mMode = FILE_MODE_CLOSED; - mFileHandle = nullptr; - return true; - } - - bool File::IsOpen() - { - return mMode != FILE_MODE_CLOSED && mFileHandle != nullptr; - } - - size_t File::GetSize() - { - if (mFileHandle == nullptr) - { - Open(FILE_MODE_READ); - size_t size = PHYSFS_fileLength(mFileHandle); - Close(); - return size; - } - return PHYSFS_fileLength(mFileHandle); - } - - size_t File::Read(ASURA_OUT DataBuffer* dst, size_t length) - { - ASSERT(dst); - - if (dst->GetSize() < length) - throw Exception("Data buffer is too small compares to read length."); - - if (!mFileHandle || mMode != FILE_MODE_READ) - throw Exception("File \"%s\" is not opened for reading", mFileName); - - size_t max = PHYSFS_fileLength(mFileHandle); - length = (length > max) ? max : length; - - if (length < 0) - throw Exception("Invalid read size."); - - dst->Lock(); - size_t size = PHYSFS_readBytes(mFileHandle, dst->GetData(), length); - dst->Unlock(); - return size; - } - - size_t File::ReadAll(ASURA_OUT DataBuffer* dst) - { - ASSERT(dst); - - if (!mFileHandle || mMode != FILE_MODE_READ) - throw Exception("File \"%s\" is not opened for reading", mFileName); - - size_t length = PHYSFS_fileLength(mFileHandle); - - if (dst->GetSize() < length) - throw Exception("Data buffer is too small compares to file length."); - - dst->Lock(); - size_t size = PHYSFS_readBytes(mFileHandle, dst->GetData(), 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 mFileHandle == nullptr || test_eof(this, mFileHandle); - } - - size_t File::Tell() - { - if (!mFileHandle) - return - 1; - - return PHYSFS_tell(mFileHandle); - } - - bool File::Seek(size_t pos) - { - return mFileHandle != nullptr && PHYSFS_seek(mFileHandle, pos) != 0; - } - - bool File::Write(ASURA_REF DataBuffer* src) - { - if (!mFileHandle || (mMode != FILE_MODE_APPEND && mMode != 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(mFileHandle, data, size); - - if (written != src->GetSize()) - return false; - - // 处理行缓冲 - if (mBufferSize == BUFFER_MODE_LINE && mBufferSize > size) - { - if (memchr(data, '\n', size) != nullptr) - Flush(); - } - - return true; - } - - bool File::Flush() - { - if (!mFileHandle || (mMode != FILE_MODE_WRITE && mMode != FILE_MODE_APPEND)) - throw Exception("File is not opened for writing."); - - return PHYSFS_flush(mFileHandle) != 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()) - { - mBufferMode = mode; - mBufferSize = size; - return true; - } - - int ret = 1; - - switch (mode) - { - case BUFFER_MODE_NONE: - default: - ret = PHYSFS_setBuffer(mFileHandle, 0); - size = 0; - break; - case BUFFER_MODE_LINE: - case BUFFER_MODE_FULL: - ret = PHYSFS_setBuffer(mFileHandle, size); - break; - } - - if (ret == 0) - return false; - - mBufferMode = mode; - mBufferSize = size; - - return true; - } - - File::BufferMode File::GetBuffer(ASURA_OUT size_t& size) - { - size = mBufferSize; - return mBufferMode; - } - - const std::string& File::GetFileName() - { - return mFileName; - } - - const std::string& File::GetName() - { - return mName; - } - - const std::string& File::GetExtension() - { - return mExtension; - } - - File::FileMode File::GetMode() - { - return mMode; - } - - } -} \ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/file.h b/source/libs/asura-lib-utils/io/file.h deleted file mode 100644 index 56077e0..0000000 --- a/source/libs/asura-lib-utils/io/file.h +++ /dev/null @@ -1,146 +0,0 @@ -#ifndef __ASURA_ENGINE_FILE_H__ -#define __ASURA_ENGINE_FILE_H__ - -#include "physfs/physfs.h" - -#include "../scripting/portable.hpp" -#include "../threading/thread.h" - -#include "file_data.h" - -namespace AsuraEngine -{ - namespace IO - { - - /// - /// 以流的形式打开文件,可以指定读写起点、大小。在期望使用流读取时使用本类,否则使用Filesystem.read()直接读取文件全部 - /// 内容,并返回一个FileData对象。 - /// - class File ASURA_FINAL - : public AEScripting::Portable - { - 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); - - /// - /// 异步写文件,将写文件task加入thread的队列。 - /// - 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* mFileHandle; ///< physfs 文件 - std::string mFileName; ///< 文件名 - std::string mExtension; ///< 不包含点的扩展名 - std::string mName; ///< 不包含点和扩展名的文件名 - FileMode mMode; ///< 文件打开模式 - BufferMode mBufferMode; ///< 写入缓冲区模式 - size_t mBufferSize; ///< 写入缓冲区大小 - - 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/libs/asura-lib-utils/io/file_data.cpp b/source/libs/asura-lib-utils/io/file_data.cpp deleted file mode 100644 index 92333cf..0000000 --- a/source/libs/asura-lib-utils/io/file_data.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "file_data.h" - -namespace AsuraEngine -{ - namespace IO - { - - FileData::FileData(const std::string& filename) - : mData(nullptr) - , mFileName(filename) - { - size_t dot = filename.rfind('.'); - if (dot != std::string::npos) - { - mExtension = filename.substr(dot + 1); - mName = filename.substr(0, dot); - } - else - mName = filename; - } - - FileData::~FileData() - { - } - - const std::string& FileData::GetFileName() - { - return mFileName; - } - - const std::string& FileData::GetExtension() - { - return mExtension; - } - - const std::string& FileData::GetName() - { - return mName; - } - - void FileData::BindData(ASURA_MOVE DataBuffer* buffer) - { - mData = buffer; - } - - DataBuffer* FileData::GetDataBuffer() - { - return mData; - } - - } -} diff --git a/source/libs/asura-lib-utils/io/file_data.h b/source/libs/asura-lib-utils/io/file_data.h deleted file mode 100644 index 9aa0e3b..0000000 --- a/source/libs/asura-lib-utils/io/file_data.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef __ASURA_ENGINE_FILE_DATA_H__ -#define __ASURA_ENGINE_FILE_DATA_H__ - -#include - -#include - -#include "data_buffer.h" - -namespace AsuraEngine -{ - namespace IO - { - - class Filesystem; - - /// - /// 当从filesystem直接读取整个文件时,返回FileData对象描述文件内容和其他信息。由Filesystem创建。 - /// - class FileData ASURA_FINAL - : public AEScripting::Portable - { - public: - - LUAX_DECL_FACTORY(FileData); - - ~FileData(); - - /// - /// 返回文件内容,可以通过Databuffer获得内容和大小。由于内部接口都是以Data buffer作为参数,所以这里也返回data buffer。 - /// - DataBuffer* GetDataBuffer(); - - const std::string& GetFileName(); - const std::string& GetExtension(); - const std::string& GetName(); - - private: - - friend class Filesystem; - - FileData(const std::string& name); - - /// - /// 绑定data buffer。 - /// - void BindData(ASURA_MOVE DataBuffer* buffer); - - /// - /// Data buffer不会再filedata析构时销毁,当lua引用计数为0时由lua调用GC销毁。创建mData时会添加一个成员引用。 - /// - ASURA_REF DataBuffer* mData; - Luax::LuaxMemberRef mDataRef; - - std::string mFileName; ///< 包含扩展名的文件名 - std::string mExtension; ///< 不包含点的扩展名 - std::string mName; ///< 不包含点和后缀的文件名 - - LUAX_DECL_METHOD(_GetDataBuffer); - LUAX_DECL_METHOD(_GetFileName); - LUAX_DECL_METHOD(_GetExtension); - LUAX_DECL_METHOD(_GetName); - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/file_system.cpp b/source/libs/asura-lib-utils/io/file_system.cpp deleted file mode 100644 index 20f3cb2..0000000 --- a/source/libs/asura-lib-utils/io/file_system.cpp +++ /dev/null @@ -1,198 +0,0 @@ -#include - -#include "../exceptions/exception.h" - -#include "file.h" -#include "file_data.h" -#include "file_system.h" - -using namespace std; - -namespace AsuraEngine -{ - namespace IO - { - -#ifdef ASURA_WINDOWS - #include - #include -#else - #include - #include -#endif - - Filesystem::~Filesystem() - { - if (mInited) //PHYSFS_isInit - PHYSFS_deinit(); - } - - void Filesystem::Init(const char* arg0) - { - if (!PHYSFS_init(arg0)) - throw Exception("Failed to initialize filesystem: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); - - mInited = true; - } - - bool Filesystem::Mount(const std::string& locpath, const std::string& montpoint/* = "/"*/, bool prepend /*= false*/) - { - if (!mInited) - return false; - - return PHYSFS_mount(locpath.c_str(), montpoint.c_str(), !prepend); - } - - bool Filesystem::Mount(DataBuffer* db, const std::string& archivename, const std::string& mountpoint /*= "/"*/, bool prepend /*= false*/) - { - if (!mInited) - return false; - if (PHYSFS_mountMemory(db->GetData(), db->GetSize(), nullptr, archivename.c_str(), mountpoint.c_str(), !prepend)) - { - mMountData[archivename] = db; - return true; - } - return false; - } - - bool Filesystem::Unmount(const std::string& locpath) - { - if (!mInited) - return false; - - // 如果是归档,从映射中删除它 - auto datait = mMountData.find(locpath); - if (datait != mMountData.end() && PHYSFS_unmount(locpath.c_str()) != 0) - { - mMountData.erase(datait); - return true; - } - - return PHYSFS_unmount(locpath.c_str()); - } - - bool Filesystem::Unmount(DataBuffer* db) - { - for (const auto& dp : mMountData) - { - if (dp.second == db) - { - std::string archive = dp.first; - return Unmount(archive); - } - } - } - - bool Filesystem::GetMountPoint(const std::string& locpath, ASURA_OUT std::string& mountpoint) - { - if (!mInited) - return false; - const char* point = PHYSFS_getMountPoint(locpath.c_str()); - if (point != nullptr) - { - mountpoint = point; - return true; - } - return false; - } - - void Filesystem::SetWriteDirectory(const std::string locpath) - { - if (!mInited) - return; - if (!PHYSFS_setWriteDir(locpath.c_str())) - throw Exception("Failed to set write directory %s", locpath.c_str()); - } - - std::string Filesystem::GetWriteDirectory() - { - return PHYSFS_getWriteDir(); - } - - File* Filesystem::NewFile(const std::string& name) - { - return new File(name); - } - - bool Filesystem::NewDirectory(const std::string& path) - { - if (!mInited) - return false; - if (!PHYSFS_getWriteDir()) - return false; - if (!PHYSFS_mkdir(path.c_str())) - return false; - return true; - } - - bool Filesystem::Write(const std::string& name, ASURA_REF DataBuffer* buffer) - { - File file(name); - file.Open(File::FILE_MODE_WRITE); - if (!file.Write(buffer)) - throw Exception("Data could not be written."); - } - - bool Filesystem::Append(const std::string& name, ASURA_REF DataBuffer* buffer) - { - File file(name); - file.Open(File::FILE_MODE_APPEND); - if (!file.Write(buffer)) - throw Exception("Data could not be append."); - } - - FileData* Filesystem::Read(const std::string& name) - { - File file = File(name); - file.Open(File::FILE_MODE_READ); - int size = file.GetSize(); - DataBuffer* db = new DataBuffer(size); - if (db) - { - file.ReadAll(db); - FileData* fd = new FileData(name); - fd->BindData(db); - return fd; - } - return nullptr; - } - - bool Filesystem::Remove(const std::string& path) - { - if (!mInited) - return false; - if (PHYSFS_getWriteDir() == 0) - return false; - - if (!PHYSFS_delete(path.c_str())) - return false; - - return true; - } - - bool Filesystem::GetFileInfo(const std::string& filepath, ASURA_OUT FileInfo* info) - { - if (!mInited) - return false; - - PHYSFS_Stat stat = {}; - if (!PHYSFS_stat(filepath.c_str(), &stat)) - return false; - - info->size = (int64)stat.filesize; - info->modtime = (int64)stat.modtime; - - if (stat.filetype == PHYSFS_FILETYPE_REGULAR) - info->type = FILE_TYPE_FILE; - else if (stat.filetype == PHYSFS_FILETYPE_DIRECTORY) - info->type = FILE_TYPE_DIRECTORY; - else if (stat.filetype == PHYSFS_FILETYPE_SYMLINK) - info->type = FILE_TYPE_SYMLINK; - else - info->type = FILE_TYPE_OTHER; - - return true; - } - - } -} \ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/file_system.h b/source/libs/asura-lib-utils/io/file_system.h deleted file mode 100644 index 849cbb6..0000000 --- a/source/libs/asura-lib-utils/io/file_system.h +++ /dev/null @@ -1,112 +0,0 @@ -#ifndef __ASURA_ENGINE_FILESYSTEM_H__ -#define __ASURA_ENGINE_FILESYSTEM_H__ - -#include -#include - -#include "../scripting/portable.hpp" -#include "../singleton.hpp" -#include "../type.h" - -#include "file_data.h" -#include "file.h" - -namespace AsuraEngine -{ - namespace IO - { - - enum FileType - { - FILE_TYPE_FILE, ///< 文件 - FILE_TYPE_DIRECTORY, ///< 文件夹 - FILE_TYPE_SYMLINK, ///< 链接 - FILE_TYPE_OTHER, ///< 其他 - }; - - struct FileInfo - { - int64 size; - int64 modtime; - FileType type; - }; - - /// - /// 资源管理,负责加载、存储资源,指定根目录等。无论编辑器还是运行时,都需要限制访问的机制,将用户的操作限制在游戏目录 - /// 下,file system就是做这件事的。Filesystem是运行时和编辑器共用的类,AssetDatabase是用来管理资源的类,在framework - /// 里实现,单纯是逻辑处理,读写还是用Filesystem实现,AssetDatabase提供根据文件内容创建对应资源的方法。 - /// - class Filesystem ASURA_FINAL - : public Singleton - , public AEScripting::Portable - { - public: - - LUAX_DECL_SINGLETON(Filesystem); - - ~Filesystem(); - - void Init(const char* arg0); - - /// - /// 当前可执行文件的所在文件夹 - /// - std::string GetWorkingDirectory(); - - bool Mount(const std::string& locpath, const std::string& montpoint = "/", bool prepend = false); - bool Mount(DataBuffer* db, const std::string& archivename, const std::string& mountpoint = "/", bool prepend = false); - - bool Unmount(const std::string& locpath); - bool Unmount(DataBuffer* db); - - bool GetMountPoint(const std::string& locpath, ASURA_OUT std::string& mountpoint); - - void SetWriteDirectory(const std::string locpath); - std::string GetWriteDirectory(); - File* NewFile(const std::string& name); - bool NewDirectory(const std::string& path); - bool Write(const std::string& path, ASURA_REF DataBuffer* buffer); - bool Append(const std::string& path, ASURA_REF DataBuffer* buffer); - bool Remove(const std::string& path); - - FileData* Read(const std::string& path); - bool GetFileInfo(const std::string& path, ASURA_OUT FileInfo* info); - - bool GetDirectoryItems(const std::string& path, ASURA_OUT std::vector& items) { return false; }; - - private: - - typedef std::map MountDataMap; - - bool mInited; ///< 是否初始化成功 - std::string mCwd; ///< 当前执行文件的工作目录 - MountDataMap mMountData; ///< 从路径到压缩文档的映射 - - LUAX_DECL_METHOD(_Init); - LUAX_DECL_METHOD(_Mount); - LUAX_DECL_METHOD(_Unmount); - LUAX_DECL_METHOD(_GetMountPoint); - - LUAX_DECL_METHOD(_SetWriteDirectory); - LUAX_DECL_METHOD(_GetWriteDirectory); - LUAX_DECL_METHOD(_CreateFile); - LUAX_DECL_METHOD(_CreateDirectory); - - LUAX_DECL_METHOD(_Write); - LUAX_DECL_METHOD(_Append); - LUAX_DECL_METHOD(_Remove); - - LUAX_DECL_METHOD(_Read); - - LUAX_DECL_METHOD(_GetFileInfo); - - LUAX_DECL_METHOD(_GetDirectoryItems); - - }; - - } -} - -namespace AEIO = AsuraEngine::IO; - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/io_batch_task.cpp b/source/libs/asura-lib-utils/io/io_batch_task.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/io/io_batch_task.h b/source/libs/asura-lib-utils/io/io_batch_task.h deleted file mode 100644 index c0be921..0000000 --- a/source/libs/asura-lib-utils/io/io_batch_task.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef __ASURA_IO_BATCH_TASK_H__ -#define __ASURA_IO_BATCH_TASK_H__ - -#include "io_task.h" - -namespace AsuraEngine -{ - namespace IO - { - - /// - /// 批量处理读或者写。一次性提交一个table,依次处理后返回结果。 - /// - class IOBatchTask ASURA_FINAL : public AEThreading::Task - { - public: - - private: - - /// - /// 任务表,每一条的结构如下: - /// { path = "", } - /// - Luax::LuaxMemberRef mTasks; - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/io_task.cpp b/source/libs/asura-lib-utils/io/io_task.cpp deleted file mode 100644 index 361b9c5..0000000 --- a/source/libs/asura-lib-utils/io/io_task.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "file_system.h" -#include "io_task.h" - -#include - -using namespace AEScripting; -using namespace Luax; - -namespace AsuraEngine -{ - namespace IO - { - - IOTask::IOTask(const std::string& path, DataBuffer* buffer, IOTaskType type) - : mPath(path) - , mBuffer(buffer) - { - } - - IOTask::~IOTask() - { - } - - bool IOTask::Execute() - { - File file(mPath); - if (mType == IOTASK_TYPE_WRITE) - { - - } - // 从path读取内容保存在mBuffer中 - else if (mType == IOTASK_TYPE_READ) - { - file.Open(File::FILE_MODE_READ); - file.ReadAll(mBuffer); - file.Close(); - } - return true; - } - - void IOTask::Invoke(lua_State* invokeThreaad) - { - if (mCallback) - { - LuaxScopedState state(invokeThreaad); - if (PushLuaxMemberRef(state, mCallback)) - { - PushLuaxMemberRef(state, mBufferRef); - state.Call(1, 0); - } - } - } - - } -} diff --git a/source/libs/asura-lib-utils/io/io_task.h b/source/libs/asura-lib-utils/io/io_task.h deleted file mode 100644 index 8f04142..0000000 --- a/source/libs/asura-lib-utils/io/io_task.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef __ASURA_IO_TASK_H__ -#define __ASURA_IO_TASK_H__ - -#include - -#include "../scripting/portable.hpp" -#include "../threading/task.h" - -#include "data_buffer.h" - -namespace AsuraEngine -{ - namespace IO - { - - enum IOTaskType - { - IOTASK_TYPE_READ, - IOTASK_TYPE_WRITE, - IOTASK_TYPE_APPEND, - }; - - /// - /// 读取文件任务。 - /// - class IOTask ASURA_FINAL - : public AEThreading::Task - , public AEScripting::Portable - { - public: - - LUAX_DECL_FACTORY(IOTask); - - IOTask(const std::string& path, DataBuffer* buffer, IOTaskType type); - ~IOTask(); - - bool Execute() override ; - void Invoke(lua_State* invokeThreaad) override; - - private: - - LUAX_DECL_ENUM(IOTaskType); - - LUAX_DECL_METHOD(_New); - - std::string mPath; - IOTaskType mType; - - ASURA_REF DataBuffer* mBuffer; - Luax::LuaxMemberRef mBufferRef; - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/reloadable.h b/source/libs/asura-lib-utils/io/reloadable.h deleted file mode 100644 index 22a721c..0000000 --- a/source/libs/asura-lib-utils/io/reloadable.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __ASURA_ENGINE_RELOADABLE_H__ -#define __ASURA_ENGINE_RELOADABLE_H__ - -#include "../scripting/portable.hpp" - -namespace AsuraEngine -{ - namespace IO - { - - /// - /// 可以重新构建的数据结构。比如图片、音频这种,从外部数据可以直接构建,可以在编辑器内重新构建,适用于不改变handle的资源。 - /// - ASURA_ABSTRACT class Reloadable - { - public: - Reloadable(); - virtual ~Reloadable(); - - // 继承Reloadable的需要提供一个load方法 - - }; - - } -} - -namespace AEIO = AsuraEngine::IO; - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/manager.hpp b/source/libs/asura-lib-utils/manager.hpp deleted file mode 100644 index 7b4e272..0000000 --- a/source/libs/asura-lib-utils/manager.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#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/libs/asura-lib-utils/math/curve.cpp b/source/libs/asura-lib-utils/math/curve.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/math/curve.h b/source/libs/asura-lib-utils/math/curve.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/math/functions.cpp b/source/libs/asura-lib-utils/math/functions.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/math/functions.h b/source/libs/asura-lib-utils/math/functions.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/math/matrix44.cpp b/source/libs/asura-lib-utils/math/matrix44.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/math/matrix44.h b/source/libs/asura-lib-utils/math/matrix44.h deleted file mode 100644 index 4ab3c0b..0000000 --- a/source/libs/asura-lib-utils/math/matrix44.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef __ASURA_ENGINE_MATRIX44_H__ -#define __ASURA_ENGINE_MATRIX44_H__ - -namespace AsuraEngine -{ - namespace Math - { - - /// - /// 4x4矩阵 - /// - class Matrix44 - { - public: - - private: - - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/math/quaternion.cpp b/source/libs/asura-lib-utils/math/quaternion.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/math/quaternion.h b/source/libs/asura-lib-utils/math/quaternion.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/math/ranged_value.cpp b/source/libs/asura-lib-utils/math/ranged_value.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/math/ranged_value.h b/source/libs/asura-lib-utils/math/ranged_value.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/math/rect.hpp b/source/libs/asura-lib-utils/math/rect.hpp deleted file mode 100644 index 1751634..0000000 --- a/source/libs/asura-lib-utils/math/rect.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef __ASURA_ENGINE_RECT_H__ -#define __ASURA_ENGINE_RECT_H__ - -namespace AsuraEngine -{ - namespace Math - { - - template - struct Rect - { - public: - Rect(); - ~Rect(T x, T y, T w, T h); - - /// - /// x,y是否落在rect内。 - /// - bool Contain(T x, T y); - - /// - /// 两个矩形是否相交,并返回相交的矩形 - /// - bool Intersect(const Rect& src, Rect& intersection); - - /// - /// 两个矩形是否相交,并返回相交的矩形 - /// - static bool Intersect(const Rect& src1, const Rect& src2, Rect& intersection); - - T x, y, w, h; - }; - -#include "Rect.inl" - - // Define the most common types - typedef Rect Recti; - typedef Rect Rectu; - typedef Rect Rectf; - typedef Rect Reftl; - - } -} - -namespace AEMath = AsuraEngine::Math; - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/math/rect.inl b/source/libs/asura-lib-utils/math/rect.inl deleted file mode 100644 index 891a3f8..0000000 --- a/source/libs/asura-lib-utils/math/rect.inl +++ /dev/null @@ -1,19 +0,0 @@ -template -inline Rect::Rect() - : x(0) - , y(0) - , w(0) - , h(0) -{ - -} - -template -inline Rect::Rect(T X, T Y, T W, T H) - : x(X) - , y(Y) - , w(W) - , h(H) -{ - -} diff --git a/source/libs/asura-lib-utils/math/transform.cpp b/source/libs/asura-lib-utils/math/transform.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/math/transform.h b/source/libs/asura-lib-utils/math/transform.h deleted file mode 100644 index be4c850..0000000 --- a/source/libs/asura-lib-utils/math/transform.h +++ /dev/null @@ -1,30 +0,0 @@ -#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/libs/asura-lib-utils/math/vector2.hpp b/source/libs/asura-lib-utils/math/vector2.hpp deleted file mode 100644 index df78255..0000000 --- a/source/libs/asura-lib-utils/math/vector2.hpp +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef __ASURA_ENGINE_VECTOR2_H__ -#define __ASURA_ENGINE_VECTOR2_H__ - -namespace AsuraEngine -{ - namespace Math - { - template - class Vector2 - { - public: - Vector2(); - Vector2(T X, T Y); - - template - explicit Vector2(const Vector2& vector); - - Set(T X, T Y); - - T x; ///< X coordinate of the vector - T y; ///< Y coordinate of the vector - }; - - template - Vector2 operator -(const Vector2& right); - - template - Vector2& operator +=(Vector2& left, const Vector2& right); - - template - Vector2& operator -=(Vector2& left, const Vector2& right); - - template - Vector2 operator +(const Vector2& left, const Vector2& right); - - template - Vector2 operator -(const Vector2& left, const Vector2& right); - - template - Vector2 operator *(const Vector2& left, T right); - - template - Vector2 operator *(T left, const Vector2& right); - - template - Vector2& operator *=(Vector2& left, T right); - - template - Vector2 operator /(const Vector2& left, T right); - - template - Vector2& operator /=(Vector2& left, T right); - - template - bool operator ==(const Vector2& left, const Vector2& right); - - template - bool operator !=(const Vector2& left, const Vector2& right); - -#include "Vector2.inl" - - // Define the most common types - typedef Vector2 Vector2i; - typedef Vector2 Vector2u; - typedef Vector2 Vector2f; - - } -} - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/math/vector2.inl b/source/libs/asura-lib-utils/math/vector2.inl deleted file mode 100644 index 9e131a7..0000000 --- a/source/libs/asura-lib-utils/math/vector2.inl +++ /dev/null @@ -1,114 +0,0 @@ -template -inline Vector2::Vector2() : - x(0), - y(0) -{ - -} - -template -inline Vector2::Vector2(T X, T Y) : - x(X), - y(Y) -{ - -} - -template -template -inline Vector2::Vector2(const Vector2& vector) : - x(static_cast(vector.x)), - y(static_cast(vector.y)) -{ -} - -template -inline Vector2::Set(T X, T Y) -{ - x = X; - y = Y; -} - -template -inline Vector2 operator -(const Vector2& right) -{ - return Vector2(-right.x, -right.y); -} - -template -inline Vector2& operator +=(Vector2& left, const Vector2& right) -{ - left.x += right.x; - left.y += right.y; - - return left; -} - -template -inline Vector2& operator -=(Vector2& left, const Vector2& right) -{ - left.x -= right.x; - left.y -= right.y; - - return left; -} - -template -inline Vector2 operator +(const Vector2& left, const Vector2& right) -{ - return Vector2(left.x + right.x, left.y + right.y); -} - -template -inline Vector2 operator -(const Vector2& left, const Vector2& right) -{ - return Vector2(left.x - right.x, left.y - right.y); -} - -template -inline Vector2 operator *(const Vector2& left, T right) -{ - return Vector2(left.x * right, left.y * right); -} - -template -inline Vector2 operator *(T left, const Vector2& right) -{ - return Vector2(right.x * left, right.y * left); -} - -template -inline Vector2& operator *=(Vector2& left, T right) -{ - left.x *= right; - left.y *= right; - - return left; -} - -template -inline Vector2 operator /(const Vector2& left, T right) -{ - return Vector2(left.x / right, left.y / right); -} - -template -inline Vector2& operator /=(Vector2& left, T right) -{ - left.x /= right; - left.y /= right; - - return left; -} - -template -inline bool operator ==(const Vector2& left, const Vector2& right) -{ - return (left.x == right.x) && (left.y == right.y); -} - -template -inline bool operator !=(const Vector2& left, const Vector2& right) -{ - return (left.x != right.x) || (left.y != right.y); -} diff --git a/source/libs/asura-lib-utils/math/vector3.hpp b/source/libs/asura-lib-utils/math/vector3.hpp deleted file mode 100644 index 2b23406..0000000 --- a/source/libs/asura-lib-utils/math/vector3.hpp +++ /dev/null @@ -1,233 +0,0 @@ -#ifndef __ASURA_ENGINE_VECTOR3_H__ -#define __ASURA_ENGINE_VECTOR3_H__ - -namespace AsuraEngine -{ - namespace Math - { - template - 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 - explicit Vector3(const Vector3& 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 - Vector3 operator -(const Vector3& 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 - Vector3& operator +=(Vector3& left, const Vector3& 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 - Vector3& operator -=(Vector3& left, const Vector3& 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 - Vector3 operator +(const Vector3& left, const Vector3& 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 - Vector3 operator -(const Vector3& left, const Vector3& 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 - Vector3 operator *(const Vector3& 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 - Vector3 operator *(T left, const Vector3& 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 - Vector3& operator *=(Vector3& 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 - Vector3 operator /(const Vector3& 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 - Vector3& operator /=(Vector3& 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 - bool operator ==(const Vector3& left, const Vector3& 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 - bool operator !=(const Vector3& left, const Vector3& right); - -#include "Vector3.inl" - - // Define the most common types - typedef Vector3 Vector3i; - typedef Vector3 Vector3f; - - } -} - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/math/vector3.inl b/source/libs/asura-lib-utils/math/vector3.inl deleted file mode 100644 index 3a2aa93..0000000 --- a/source/libs/asura-lib-utils/math/vector3.inl +++ /dev/null @@ -1,145 +0,0 @@ - - -//////////////////////////////////////////////////////////// -template -inline Vector3::Vector3() : - x(0), - y(0), - z(0) -{ - -} - - -//////////////////////////////////////////////////////////// -template -inline Vector3::Vector3(T X, T Y, T Z) : - x(X), - y(Y), - z(Z) -{ - -} - - -//////////////////////////////////////////////////////////// -template -template -inline Vector3::Vector3(const Vector3& vector) : - x(static_cast(vector.x)), - y(static_cast(vector.y)), - z(static_cast(vector.z)) -{ -} - - -//////////////////////////////////////////////////////////// -template -inline Vector3 operator -(const Vector3& left) -{ - return Vector3(-left.x, -left.y, -left.z); -} - - -//////////////////////////////////////////////////////////// -template -inline Vector3& operator +=(Vector3& left, const Vector3& right) -{ - left.x += right.x; - left.y += right.y; - left.z += right.z; - - return left; -} - - -//////////////////////////////////////////////////////////// -template -inline Vector3& operator -=(Vector3& left, const Vector3& right) -{ - left.x -= right.x; - left.y -= right.y; - left.z -= right.z; - - return left; -} - - -//////////////////////////////////////////////////////////// -template -inline Vector3 operator +(const Vector3& left, const Vector3& right) -{ - return Vector3(left.x + right.x, left.y + right.y, left.z + right.z); -} - - -//////////////////////////////////////////////////////////// -template -inline Vector3 operator -(const Vector3& left, const Vector3& right) -{ - return Vector3(left.x - right.x, left.y - right.y, left.z - right.z); -} - - -//////////////////////////////////////////////////////////// -template -inline Vector3 operator *(const Vector3& left, T right) -{ - return Vector3(left.x * right, left.y * right, left.z * right); -} - - -//////////////////////////////////////////////////////////// -template -inline Vector3 operator *(T left, const Vector3& right) -{ - return Vector3(right.x * left, right.y * left, right.z * left); -} - - -//////////////////////////////////////////////////////////// -template -inline Vector3& operator *=(Vector3& left, T right) -{ - left.x *= right; - left.y *= right; - left.z *= right; - - return left; -} - - -//////////////////////////////////////////////////////////// -template -inline Vector3 operator /(const Vector3& left, T right) -{ - return Vector3(left.x / right, left.y / right, left.z / right); -} - - -//////////////////////////////////////////////////////////// -template -inline Vector3& operator /=(Vector3& left, T right) -{ - left.x /= right; - left.y /= right; - left.z /= right; - - return left; -} - - -//////////////////////////////////////////////////////////// -template -inline bool operator ==(const Vector3& left, const Vector3& right) -{ - return (left.x == right.x) && (left.y == right.y) && (left.z == right.z); -} - - -//////////////////////////////////////////////////////////// -template -inline bool operator !=(const Vector3& left, const Vector3& right) -{ - return (left.x != right.x) || (left.y != right.y) || (left.z != right.z); -} diff --git a/source/libs/asura-lib-utils/math/vector4.h b/source/libs/asura-lib-utils/math/vector4.h deleted file mode 100644 index 13a9d8a..0000000 --- a/source/libs/asura-lib-utils/math/vector4.h +++ /dev/null @@ -1,234 +0,0 @@ -#ifndef __ASURA_ENGINE_VECTOR4_H__ -#define __ASURA_ENGINE_VECTOR4_H__ - -namespace AsuraEngine -{ - namespace Math - { - template - 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 - explicit Vector4(const Vector4& 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 - Vector4 operator -(const Vector4& 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 - Vector4& operator +=(Vector4& left, const Vector4& 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 - Vector4& operator -=(Vector4& left, const Vector4& 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 - Vector4 operator +(const Vector4& left, const Vector4& 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 - Vector4 operator -(const Vector4& left, const Vector4& 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 - Vector4 operator *(const Vector4& 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 - Vector4 operator *(T left, const Vector4& 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 - Vector4& operator *=(Vector4& 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 - Vector4 operator /(const Vector4& 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 - Vector4& operator /=(Vector4& 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 - bool operator ==(const Vector4& left, const Vector4& 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 - bool operator !=(const Vector4& left, const Vector4& right); - -#include "Vector4.inl" - - // Define the most common types - typedef Vector4 Vector4i; - typedef Vector4 Vector4f; - - } -} - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/math/vector4.inl b/source/libs/asura-lib-utils/math/vector4.inl deleted file mode 100644 index 025bfcc..0000000 --- a/source/libs/asura-lib-utils/math/vector4.inl +++ /dev/null @@ -1,152 +0,0 @@ - - -//////////////////////////////////////////////////////////// -template -inline Vector4::Vector4() : - x(0), - y(0), - z(0), - w(0) -{ - -} - - -//////////////////////////////////////////////////////////// -template -inline Vector4::Vector4(T X, T Y, T Z) : - x(X), - y(Y), - z(Z), - w(0) -{ - -} - - -//////////////////////////////////////////////////////////// -template -template -inline Vector4::Vector4(const Vector4& vector) : - x(static_cast(vector.x)), - y(static_cast(vector.y)), - z(static_cast(vector.z)) - w(static_cast(vector.w)) -{ -} - - -//////////////////////////////////////////////////////////// -template -inline Vector4 operator -(const Vector4& left) -{ - return Vector4(-left.x, -left.y, -left.z, -left.w); -} - - -//////////////////////////////////////////////////////////// -template -inline Vector4& operator +=(Vector4& left, const Vector4& right) -{ - left.x += right.x; - left.y += right.y; - left.z += right.z; - left.w += right.w; - - return left; -} - - -//////////////////////////////////////////////////////////// -template -inline Vector4& operator -=(Vector4& left, const Vector4& right) -{ - left.x -= right.x; - left.y -= right.y; - left.z -= right.z; - left.w -= right.w; - - return left; -} - - -//////////////////////////////////////////////////////////// -template -inline Vector4 operator +(const Vector4& left, const Vector4& right) -{ - return Vector4(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w); -} - - -//////////////////////////////////////////////////////////// -template -inline Vector4 operator -(const Vector4& left, const Vector4& right) -{ - return Vector4(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w); -} - - -//////////////////////////////////////////////////////////// -template -inline Vector4 operator *(const Vector4& left, T right) -{ - return Vector4(left.x * right, left.y * right, left.z * right, left.w * right); -} - - -//////////////////////////////////////////////////////////// -template -inline Vector4 operator *(T left, const Vector4& right) -{ - return Vector4(right.x * left, right.y * left, right.z * left, right.w * left); -} - - -//////////////////////////////////////////////////////////// -template -inline Vector4& operator *=(Vector4& left, T right) -{ - left.x *= right; - left.y *= right; - left.z *= right; - left.w *= right; - - return left; -} - - -//////////////////////////////////////////////////////////// -template -inline Vector4 operator /(const Vector4& left, T right) -{ - return Vector4(left.x / right, left.y / right, left.z / right, left.w / right); -} - - -//////////////////////////////////////////////////////////// -template -inline Vector4& operator /=(Vector4& left, T right) -{ - left.x /= right; - left.y /= right; - left.z /= right; - left.w /= right; - - return left; -} - - -//////////////////////////////////////////////////////////// -template -inline bool operator ==(const Vector4& left, const Vector4& right) -{ - return (left.x == right.x) && (left.y == right.y) && (left.z == right.z) && (left.w == right.w); -} - - -//////////////////////////////////////////////////////////// -template -inline bool operator !=(const Vector4& left, const Vector4& right) -{ - return (left.x != right.x) || (left.y != right.y) || (left.z != right.z) || (left.w != right.w); -} diff --git a/source/libs/asura-lib-utils/module.h b/source/libs/asura-lib-utils/module.h deleted file mode 100644 index b22c68c..0000000 --- a/source/libs/asura-lib-utils/module.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef __ASURA_MODULE_H__ -#define __ASURA_MODULE_H__ - -#include "type.h" -#include "scripting/portable.hpp" - -namespace AsuraEngine -{ - - /// - /// Asura libs 需要继承此类,以开启注册。在模块队列中按顺序添加这些模块,然后顺序调用Initialize和Finalize方法来初始化和 - /// 关闭这些模块。 - /// - 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/libs/asura-lib-utils/scripting/lua_env.h b/source/libs/asura-lib-utils/scripting/lua_env.h deleted file mode 100644 index e2fc4fc..0000000 --- a/source/libs/asura-lib-utils/scripting/lua_env.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef __ASURA_LUA_ENV_H__ -#define __ASURA_LUA_ENV_H__ - -extern "C" -{ -#include -#include -} -#include - -#include "../singleton.hpp" - -namespace AsuraEngine -{ - namespace Scripting - { - - /// - /// 程序通过这个接口访问主lua state。Asura程序的思想是,进程主线程维护一个lua虚拟机,应用 - /// 的主要逻辑跑在此虚拟机的主lua线程里(或者叫主栈里)。 - /// - class LuaEnv ASURA_FINAL : public Singleton - { - public: - - LuaEnv() : mVM(0) {}; - ~LuaEnv() {}; - - /// - /// 设置主虚拟机的主执行栈。 - /// - inline void Init() - { - ASSERT(!mVM); - mVM = new Luax::LuaxVM(); - ASSERT(mVM); - mVM->Setup(); - }; - - inline lua_State* GetMainThread() - { - return mVM->GetMainThread(); - }; - - inline void Exit() - { - delete mVM; - mVM = nullptr; - } - - private: - - /// - /// 主线程保存一个主lua虚拟机。一个Asura程序永远只有一个主虚拟机,大部分代码都在这个虚 - /// 拟机中运行,且只能设置一次。主线程\主执行栈对应的是global_State里面的: - /// - /// struct lua_State *mainthread; - /// - /// 使用lua_newstate(),会创建一个虚拟机,包含一个global_State结构,并创建一个这个虚 - /// 拟机的主线程lua_State并返回。global_State由这个虚拟机的所有线程共享,除了第一个主 - /// 线程由lua_newstate()创建外,其余线程由lua_newthread()创建。 - /// - Luax::LuaxVM* mVM; - - }; - - } -} - -namespace AEScripting = AsuraEngine::Scripting; - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/scripting/portable.hpp b/source/libs/asura-lib-utils/scripting/portable.hpp deleted file mode 100644 index 5badf8d..0000000 --- a/source/libs/asura-lib-utils/scripting/portable.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __ASURA_ENGINE_PORTABLE_H__ -#define __ASURA_ENGINE_PORTABLE_H__ - -#include "../type.h" - -#include "lua_env.h" - -namespace AsuraEngine -{ - namespace Scripting - { - - /// - /// 要注册给lua的native类需要继承此模板。 - /// - template - using Portable = Luax::LuaxNativeClass; - - /// - /// 需要作为基类,访问userdata和member ref的类继承此类,注意必须是虚继承。 - /// - using NativeAccessor = Luax::ILuaxNativeAccessor; - - } -} - -namespace AEScripting = AsuraEngine::Scripting; - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/singleton.hpp b/source/libs/asura-lib-utils/singleton.hpp deleted file mode 100644 index 0d2777e..0000000 --- a/source/libs/asura-lib-utils/singleton.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef __ASURA_SINGLETON_H__ -#define __ASURA_SINGLETON_H__ - -#include "utils_config.h" - -namespace AsuraEngine -{ - - /// - /// 继承Singleton的类在第一次实例化时保存实例,之后如果再次实例化会报错。 - /// - template - 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(this); - }; - - virtual ~Singleton() {}; - - static T* instance; - - private: - - Singleton(const Singleton& singleton); - - Singleton& operator = (const Singleton& singleton); - - }; - - // 实例初始化为空 - template - T* Singleton::instance = nullptr; - -} - -#endif // __ASURA_SINGLETON_H__ \ No newline at end of file diff --git a/source/libs/asura-lib-utils/stringmap.cpp b/source/libs/asura-lib-utils/stringmap.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/stringmap.hpp b/source/libs/asura-lib-utils/stringmap.hpp deleted file mode 100644 index ddba128..0000000 --- a/source/libs/asura-lib-utils/stringmap.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __ASURA_ENGINE_STRINGMAP_H__ -#define __ASURA_ENGINE_STRINGMAP_H__ - -#include - -namespace AsuraEngine -{ - - /// - /// 一个双向一一对应的映射,用来储存shader uniforms、statemathine state parameter的ID。 - /// - template - class StringMap - { - public: - - bool ContainsKey(const key_type& key); - - bool ContainsString(const String& str); - - std::string GetStringByKey(const key_type& key); - - key_type GetKeyByString(const String& str); - - }; - -} - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/binding/_coroutine.cpp b/source/libs/asura-lib-utils/threading/binding/_coroutine.cpp deleted file mode 100644 index 7f74cca..0000000 --- a/source/libs/asura-lib-utils/threading/binding/_coroutine.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "../coroutine.h" - -using namespace std; - -namespace AsuraEngine -{ - namespace Threading - { - - LUAX_REGISTRY(Coroutine) - { - LUAX_REGISTER_METHODS(state, - { "New", _New }, - { "Run", _Run } - ); - } - - LUAX_POSTPROCESS(Coroutine) - { - - } - - // Coroutine.New() - LUAX_IMPL_METHOD(Coroutine, _New) - { - LUAX_STATE(L); - - return 0; - } - - // coroutine:Run() - LUAX_IMPL_METHOD(Coroutine, _Run) - { - LUAX_PREPARE(L, Coroutine); - - return 0; - } - - } -} diff --git a/source/libs/asura-lib-utils/threading/binding/_thread.cpp b/source/libs/asura-lib-utils/threading/binding/_thread.cpp deleted file mode 100644 index a5aff03..0000000 --- a/source/libs/asura-lib-utils/threading/binding/_thread.cpp +++ /dev/null @@ -1,210 +0,0 @@ -#include "../thread.h" - -using namespace std; - -namespace AsuraEngine -{ - namespace Threading - { - - LUAX_REGISTRY(Thread) - { - LUAX_REGISTER_METHODS(state, - { "New", _New }, - { "AddTask", _AddTask }, - { "Start", _Start }, - { "Idle", _Idle }, - { "Pause", _Pause }, - { "Resume", _Resume }, - { "Stop", _Stop }, - { "Join", _Join }, - { "IsRunning", _IsRunning }, - { "IsPaused", _IsPaused }, - { "IsStopped", _IsStopped }, - { "IsCurrent", _IsCurrent }, - { "Sleep", _Sleep }, - { "Post", _Post }, - { "GetName", _GetName }, - { "GetType", _GetType }, - { "GetState", _GetState } - ); - } - - LUAX_POSTPROCESS(Thread) - { - LUAX_REGISTER_ENUM(state, "EThreadType", - { "DEFERRED", THREAD_TYPE_DEFERRED }, - { "IMMEDIATE", THREAD_TYPE_IMMEDIATE } - ); - LUAX_REGISTER_ENUM(state, "EThreadState", - { "READY", THREAD_STATE_IDLE }, - { "RUNNING", THREAD_STATE_RUNNING }, - { "PAUSED", THREAD_STATE_PAUSED }, - { "STOPPED", THREAD_STATE_STOPPED } - ); - } - - // thread = Thread.New(thread_type, sleepTime, name) - LUAX_IMPL_METHOD(Thread, _New) - { - LUAX_STATE(L); - - ThreadType type = (ThreadType)state.GetValue(1, THREAD_TYPE_DEFERRED); - uint sleepTime = state.GetValue(2,1); - cc8* name = state.GetValue(3, ""); - - Thread* thread = new Thread(state, type, sleepTime, name); - thread->PushLuaxUserdata(state); - - return 1; - } - - // thread:AddTask(task) - LUAX_IMPL_METHOD(Thread, _AddTask) - { - LUAX_PREPARE(L, Thread); - - Task* task = state.GetUserdata(2); - self->AddTask(task); - self->LuaxRetain(state, task); - return 0; - } - - // successed = thread:Start(isDeamon, stackSize) - LUAX_IMPL_METHOD(Thread, _Start) - { - LUAX_PREPARE(L, Thread); - - bool isDaemon = state.GetValue(2, true); - uint stackSize = state.GetValue(3, 0); - - state.Push(self->Start(isDaemon, stackSize)); - return 1; - } - - // thread:Idle() - LUAX_IMPL_METHOD(Thread, _Idle) - { - LUAX_PREPARE(L, Thread); - self->Idle(); - return 0; - } - - // thread:Pause() - LUAX_IMPL_METHOD(Thread, _Pause) - { - LUAX_PREPARE(L, Thread); - self->Pause(); - return 0; - } - - // thread:Resume() - LUAX_IMPL_METHOD(Thread, _Resume) - { - LUAX_PREPARE(L, Thread); - self->Resume(); - return 0; - } - - // thread:Stop() - LUAX_IMPL_METHOD(Thread, _Stop) - { - LUAX_PREPARE(L, Thread); - self->Stop(); - return 0; - } - - // thread:Join() - LUAX_IMPL_METHOD(Thread, _Join) - { - LUAX_PREPARE(L, Thread); - self->Join(); - return 0; - } - - // thread:IsRunning() - LUAX_IMPL_METHOD(Thread, _IsRunning) - { - LUAX_PREPARE(L, Thread); - state.Push(self->IsRunning()); - return 1; - } - - // thread:IsPaused() - LUAX_IMPL_METHOD(Thread, _IsPaused) - { - LUAX_PREPARE(L, Thread); - state.Push(self->IsPaused()); - return 1; - } - - // thread:IsStopped() - LUAX_IMPL_METHOD(Thread, _IsStopped) - { - LUAX_PREPARE(L, Thread); - state.Push(self->IsStopped()); - return 1; - } - - // thread:IsCurrent() - LUAX_IMPL_METHOD(Thread, _IsCurrent) - { - LUAX_PREPARE(L, Thread); - state.Push(self->IsCurrent()); - return 1; - } - - // Thread.Sleep(ms) - LUAX_IMPL_METHOD(Thread, _Sleep) - { - LUAX_STATE(L); - uint ms = state.GetValue(1, 0); -#ifdef _WIN32 - ::Sleep(ms); -#endif - return 0; - } - - // thread:Post() - LUAX_IMPL_METHOD(Thread, _Post) - { - LUAX_PREPARE(L, Thread); - self->Post(); - return 0; - } - - // thread:GetName() - LUAX_IMPL_METHOD(Thread, _GetName) - { - LUAX_PREPARE(L, Thread); - state.Push(self->GetName()); - return 1; - } - - // thread:GetType() - LUAX_IMPL_METHOD(Thread, _GetType) - { - LUAX_PREPARE(L, Thread); - state.Push(self->mType); - return 1; - } - - // thread:GetState() - LUAX_IMPL_METHOD(Thread, _GetState) - { - LUAX_PREPARE(L, Thread); - state.Push(self->mState); - return 1; - } - - // thread:SetSleepTime(sleepTime) - LUAX_IMPL_METHOD(Thread, _SetSleepTime) - { - LUAX_PREPARE(L, Thread); - uint time = state.CheckValue(2); - self->SetSleepTime(time); - return 0; - } - - } -} diff --git a/source/libs/asura-lib-utils/threading/coroutine.cpp b/source/libs/asura-lib-utils/threading/coroutine.cpp deleted file mode 100644 index 9f65c5f..0000000 --- a/source/libs/asura-lib-utils/threading/coroutine.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "coroutine.h" - -namespace AsuraEngine -{ - namespace Threading - { -/* - Coroutine::Coroutine() - { - - } -*/ - - - } -} diff --git a/source/libs/asura-lib-utils/threading/coroutine.h b/source/libs/asura-lib-utils/threading/coroutine.h deleted file mode 100644 index 01af654..0000000 --- a/source/libs/asura-lib-utils/threading/coroutine.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef __ASURA_COROUTINE_H__ -#define __ASURA_COROUTINE_H__ - -#include "../scripting/portable.hpp" - -namespace AsuraEngine -{ - namespace Threading - { - - /// - /// lua协程,用来做一些逻辑并发操作。 - /// - class Coroutine ASURA_FINAL - : public AEScripting::Portable - { - public: - - LUAX_DECL_FACTORY(Coroutine); - - - - private: - - /// - /// 当前协程的state - /// - lua_State* mThreadState; - - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_Run); - - }; - - } -} - -namespace AEThreading = AsuraEngine::Threading; - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/mutex.cpp b/source/libs/asura-lib-utils/threading/mutex.cpp deleted file mode 100644 index 663ac28..0000000 --- a/source/libs/asura-lib-utils/threading/mutex.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include - -#include "mutex.h" - -namespace AsuraEngine -{ - namespace Threading - { - -#define try_create_mutex(impl)\ - if (!mImpl) \ - { \ - try \ - { \ - mImpl = new impl(); \ - } \ - catch (Exception& e) \ - { \ - mImpl = nullptr; \ - } \ - } - - Mutex::Mutex() - : mImpl(nullptr) - { -#if ASURA_MUTEX_WIN32_CRITICLE_SECTION - try_create_mutex(MutexImplWin32_CS); -#endif -#if ASURA_MUTEX_WIN32_KERNAL_MUTEX - try_create_mutex(MutexImplWin32_KM); -#endif - ASSERT(mImpl); - } - - Mutex::~Mutex() - { - delete mImpl; - } - - void Mutex::Lock() - { - ASSERT(mImpl); - - mImpl->Lock(); - } - - void Mutex::Unlock() - { - ASSERT(mImpl); - - mImpl->Unlock(); - } - -#if ASURA_MUTEX_WIN32_CRITICLE_SECTION - - MutexImplWin32_CS::MutexImplWin32_CS() - { - ::InitializeCriticalSection(&mMutex); - } - - MutexImplWin32_CS::~MutexImplWin32_CS() - { - ::DeleteCriticalSection(&mMutex); - } - - void MutexImplWin32_CS::Lock() - { - ::EnterCriticalSection(&mMutex); - } - - void MutexImplWin32_CS::Unlock() - { - ::LeaveCriticalSection(&mMutex); - } - -#endif // ASURA_MUTEX_WIN32_CRITICLE_SECTION - -#if ASURA_MUTEX_WIN32_KERNAL_MUTEX - - MutexImplWin32_KM::MutexImplWin32_KM() - { - mHandle = ::CreateMutex(NULL, FALSE, NULL); - if (!mHandle) - throw Exception("Cant use win32 mutex."); - } - - MutexImplWin32_KM::~MutexImplWin32_KM() - { - ::CloseHandle(mHandle); - mHandle = NULL; - } - - void MutexImplWin32_KM::Lock() - { - ::WaitForSingleObject(mHandle, INFINITE); - } - - void MutexImplWin32_KM::Unlock() - { - ::ReleaseMutex(mHandle); - } - -#endif // ASURA_MUTEX_WIN32_KERNAL_MUTEX - - } -} diff --git a/source/libs/asura-lib-utils/threading/mutex.h b/source/libs/asura-lib-utils/threading/mutex.h deleted file mode 100644 index 7e7d877..0000000 --- a/source/libs/asura-lib-utils/threading/mutex.h +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef __ASURA_MUTEX_H__ -#define __ASURA_MUTEX_H__ - -#include - -#include "../utils_config.h" - -#if ASURA_THREAD_WIN32 - #include -#endif - -namespace AsuraEngine -{ - namespace Threading - { - - class MutexImpl; - - class Mutex - { - public: - - Mutex(); - ~Mutex(); - - void Lock(); - void Unlock(); - - private: - - MutexImpl* mImpl; - - }; - - class _mutex_locker - { - public: - _mutex_locker(Mutex& mutex) - : m(mutex) - { - m.Lock(); - }; - ~_mutex_locker() - { - m.Unlock(); - } - private: - void* operator new(size_t); - Mutex& m; - }; - -// 将所在的栈从此位置开始到退栈处作为临界区锁定。 -#define lock(mutex) _mutex_locker _asura_scoped_lock_0x0(mutex) -#define lock2(mutex) _mutex_locker _asura_scoped_lock_0x1(mutex) -#define lock3(mutex) _mutex_locker _asura_scoped_lock_0x2(mutex) -#define lock4(mutex) _mutex_locker _asura_scoped_lock_0x3(mutex) -#define lock5(mutex) _mutex_locker _asura_scoped_lock_0x4(mutex) - - ASURA_ABSTRACT class MutexImpl - { - public: - - MutexImpl() {}; - virtual ~MutexImpl() {}; - - virtual void Lock() = 0; - virtual void Unlock() = 0; - - }; - -#if ASURA_MUTEX_WIN32_CRITICLE_SECTION - - //https://blog.csdn.net/l799623787/article/details/18259949 - class MutexImplWin32_CS ASURA_FINAL : public MutexImpl - { - public: - - MutexImplWin32_CS(); - ~MutexImplWin32_CS(); - - void Lock() override; - void Unlock() override; - - private: - - //HANDLE mHandle; - CRITICAL_SECTION mMutex; - - }; - -#endif // ASURA_MUTEX_WIN32_CRITICLE_SECTION - -#if ASURA_MUTEX_WIN32_KERNAL_MUTEX - - class MutexImplWin32_KM ASURA_FINAL : public MutexImpl - { - public: - - MutexImplWin32_KM(); - ~MutexImplWin32_KM(); - - void Lock() override; - void Unlock() override; - - private: - - HANDLE mHandle; - - }; - -#endif // ASURA_MUTEX_WIN32_KERNAL_MUTEX - -#if ASURA_THREAD_STD - - class MutexImplSTD ASURA_FINAL : public MutexImpl - { - }; - -#endif // ASURA_THREAD_STD - - } -} - -namespace AEThreading = AsuraEngine::Threading; - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/semaphore.cpp b/source/libs/asura-lib-utils/threading/semaphore.cpp deleted file mode 100644 index d59ec78..0000000 --- a/source/libs/asura-lib-utils/threading/semaphore.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include "../exceptions/exception.h" -#include "../type.h" - -#include "semaphore.h" - -namespace AsuraEngine -{ - namespace Threading - { - -#define try_create_semaphore(impl) \ - if (!mImpl) \ - { \ - try \ - { \ - mImpl = new impl(init_count); \ - } \ - catch (Exception& e) \ - { \ - mImpl = nullptr; \ - } \ - } - - Semaphore::Semaphore(unsigned int init_count) - : mImpl(nullptr) - { -#ifdef ASURA_THREAD_WIN32 - try_create_semaphore(SemaphoreWin32); -#endif - ASSERT(mImpl); - } - - Semaphore::~Semaphore() - { - if (mImpl) delete mImpl; - } - - void Semaphore::Signal() - { - ASSERT(mImpl); - mImpl->Signal(); - } - - void Semaphore::Wait(int timeout) - { - ASSERT(mImpl); - mImpl->Wait(timeout); - } - -#if ASURA_THREAD_WIN32 - - SemaphoreWin32::SemaphoreWin32(unsigned int init_value) - : SemaphoreImpl(init_value) - { - mSem = CreateSemaphore(NULL, init_value, UINT_MAX, NULL); - if (!mSem) - throw Exception("Cant use win32 semaphore."); - } - - SemaphoreWin32::~SemaphoreWin32() - { - CloseHandle(mSem); - } - - void SemaphoreWin32::Signal() - { - InterlockedIncrement(&mCount); - if (ReleaseSemaphore(mSem, 1, NULL) == FALSE) - InterlockedDecrement(&mCount); - } - - bool SemaphoreWin32::Wait(int timeout) - { - int result; - result = WaitForSingleObject(mSem, timeout < 0 ? INFINITE : timeout); - if (result == WAIT_OBJECT_0) - { - InterlockedDecrement(&mCount); - return true; - } - else - return false; - } - -#endif // ASURA_THREAD_WIN32 - - } -} \ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/semaphore.h b/source/libs/asura-lib-utils/threading/semaphore.h deleted file mode 100644 index 80773d8..0000000 --- a/source/libs/asura-lib-utils/threading/semaphore.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef __ASURA_SEMAPHORE_H__ -#define __ASURA_SEMAPHORE_H__ - -#include "../utils_config.h" - -#if ASURA_THREAD_WIN32 -#include -#endif - -namespace AsuraEngine -{ - namespace Threading - { - - class SemaphoreImpl; - - /// - /// 信号量 - /// - class Semaphore - { - public: - - Semaphore(unsigned int init_count = 1); - ~Semaphore(); - - void Signal(); - void Wait(int timeout = 0); - - private: - SemaphoreImpl* mImpl; - }; - - class SemaphoreImpl - { - public: - SemaphoreImpl(unsigned int init_value) - : mCount(init_value) - { - }; - virtual ~SemaphoreImpl() {}; - virtual void Signal() = 0; - virtual bool Wait(int timeout) = 0; - inline int Current() { return mCount; } - protected: - unsigned int mCount; - }; - -#define wait(sem) sem.Wait(); -#define signal(sem) sem.Signal(); - -#if ASURA_THREAD_WIN32 - - class SemaphoreWin32 : public SemaphoreImpl - { - public: - SemaphoreWin32(unsigned int init_value); - ~SemaphoreWin32(); - void Signal() override; - bool Wait(int timeout) override; - private: - HANDLE mSem; - }; - -#endif // ASURA_THREAD_WIN32 - - } -} - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/task.cpp b/source/libs/asura-lib-utils/threading/task.cpp deleted file mode 100644 index 2e84ed4..0000000 --- a/source/libs/asura-lib-utils/threading/task.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "task.h" -#include "../scripting/lua_env.h" - -using namespace AEScripting; - -namespace AsuraEngine -{ - namespace Threading - { - - } -} diff --git a/source/libs/asura-lib-utils/threading/task.h b/source/libs/asura-lib-utils/threading/task.h deleted file mode 100644 index fb7aa5f..0000000 --- a/source/libs/asura-lib-utils/threading/task.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef __ASURA_THRAD_TASK_H__ -#define __ASURA_THRAD_TASK_H__ - -#include -#include - -namespace AsuraEngine -{ - namespace Threading - { - - /// - /// 希望放在另一个线程处理的任务,继承Task并重写Execute方法。 - /// - ASURA_ABSTRACT class Task - : public virtual AEScripting::NativeAccessor - { - public: - - Task() {}; - virtual ~Task() {}; - - /// - /// 执行任务,完成后返回true,调用回调函数。 - /// - virtual bool Execute() = 0; - - /// - /// 调用回调。在invoke thread里面回调。 - /// - virtual void Invoke(lua_State* invokeThreaad) = 0; - - protected: - - // 取回调函数 - Luax::LuaxMemberRef mCallback; - - }; - - } -} - -namespace AEThreading = AsuraEngine::Threading; - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/thread.cpp b/source/libs/asura-lib-utils/threading/thread.cpp deleted file mode 100644 index 0f4f5da..0000000 --- a/source/libs/asura-lib-utils/threading/thread.cpp +++ /dev/null @@ -1,272 +0,0 @@ -#include "thread.h" - -#include "thread_impl_win32.h" -#include "thread_impl_posix.h" -#include "thread_impl_sdl.h" -#include "thread_impl_std.h" - -namespace AsuraEngine -{ - namespace Threading - { - - Thread::Thread(lua_State* luaThread, ThreadType type /*= THREAD_TYPE_DEFERRED*/, uint sleepTime /*= 0*/, const std::string& name /*= ""*/) - : mName(name) - , mState(THREAD_STATE_IDLE) - , mType(type) - , mLuaThread(luaThread) - , mCallbackThread(nullptr) - , mSleepTime(sleepTime) - { - LUAX_STATE(luaThread); - if (type == THREAD_TYPE_IMMEDIATE) - { - Luax::LuaxVM* vm = state.GetVM(); - ASSERT(vm); - mCallbackThread = vm->CreateThread(); - ASSERT(mCallbackThread); - SetLuaxMemberRef(state, mCallbackThreadRef, -1); - state.Pop(); // callback thread - } - } - - Thread::~Thread() - { - if (mImpl) - { - delete mImpl; - mImpl = nullptr; - } - } - - bool Thread::AddTask(Task* task) - { - lock(mTaskQueueMutex); - mTaskQueue.push(task); - return true; - } - - uint Thread::GetTaskCount() - { - return mTaskQueue.size(); - } - - void Thread::Idle() - { - mState = THREAD_STATE_IDLE; - } - -#define try_start_thread(impl)\ - if (!mImpl) \ - { \ - mImpl = new impl(); \ - if (!mImpl->Start(this, stacksize)) \ - { \ - delete mImpl; \ - mImpl = nullptr; \ - } \ - } - - bool Thread::Start(bool isDaemon /*= true*/, uint32 stacksize /*= 0*/) - { - if (mState != THREAD_STATE_IDLE) - return false; - - // 如果已经存在一个之前创建的,关闭它。 - if (mImpl) - { - delete mImpl; - mImpl = nullptr; - } - -#if ASURA_THREAD_WIN32 - try_start_thread(ThreadImplWin32); -#endif - - if (!mImpl) - return false; - - mIsDaemon = isDaemon; - mStateMutex.Lock(); - mState = THREAD_STATE_RUNNING; - mStateMutex.Unlock(); - } - - void Thread::Pause() - { - ASSERT(mImpl); - - lock(mStateMutex); - mState = THREAD_STATE_PAUSED; - } - - void Thread::Resume() - { - ASSERT(mImpl); - - lock(mStateMutex); - if(mState == THREAD_STATE_PAUSED) - mState = THREAD_STATE_RUNNING; - } - - void Thread::Stop() - { - ASSERT(mImpl); - - lock(mStateMutex); - mState = THREAD_STATE_STOPPED; - } - - void Thread::PauseSync() - { - Pause(); - wait(mSemPause); - } - - void Thread::ResumeSync() - { - Resume(); - wait(mSemResume); - } - - void Thread::StopSync() - { - Stop(); - wait(mSemStop); - } - - void Thread::Join() - { - ASSERT(mImpl); - mImpl->Join(); - } - - ThreadState Thread::GetState() - { - ThreadState state; - mStateMutex.Lock(); - state = mState; - mStateMutex.Unlock(); - return state; - } - - bool Thread::IsRunning() - { - ASSERT(mImpl); - - return GetState() == THREAD_STATE_RUNNING; - } - - bool Thread::IsPaused() - { - ASSERT(mImpl); - - return GetState() == THREAD_STATE_PAUSED; - } - - bool Thread::IsStopped() - { - ASSERT(mImpl); - - return GetState() == THREAD_STATE_STOPPED; - } - - bool Thread::IsCurrent() - { - ASSERT(mImpl); - - return mImpl->IsCurrent(); - } - - const std::string& Thread::GetName() - { - return mName; - } - - void Thread::Process() - { - LUAX_STATE(mLuaThread); - - do{ - if (IsRunning()) - { - while (!mTaskQueue.empty()) - { - Task* task = mTaskQueue.front(); - if (task && task->Execute()) - { - if (mType == THREAD_TYPE_DEFERRED) - { - mFinishedMutex.Lock(); - mFinishedTasks.push(task); - mFinishedMutex.Unlock(); - } - else if (mType == THREAD_TYPE_IMMEDIATE) - { - task->Invoke(mCallbackThread); - this->LuaxRelease(state, task); - } - mTaskQueueMutex.Lock(); - mTaskQueue.pop(); - mTaskQueueMutex.Unlock(); - } - } - } - - // 退出循环 - if (IsStopped()) - break; - - // 降低CPU使用率 - Sleep(mSleepTime); - - } while (mIsDaemon); - - // 非守护线程,先切到stop状态 - if (!mIsDaemon) - Stop(); - - signal(mSemStop); - - // 重置状态为Idle - Idle(); - } - - /// - /// 延迟模式主动发布回调、 - /// - void Thread::Post() - { - ASSERT(mType == THREAD_TYPE_DEFERRED); - - LUAX_STATE(mLuaThread); - while (!mFinishedTasks.empty()) - { - Task* task = mFinishedTasks.front(); - if (task) - { - task->Invoke(mLuaThread); - this->LuaxRelease(state, task); - mFinishedMutex.Lock(); - mFinishedTasks.pop(); - mFinishedMutex.Unlock(); - } - } - } - - void Thread::Sleep(uint ms) - { - ASSERT(mImpl); - if (mImpl) - { - mImpl->Sleep(ms); - } - } - - void Thread::SetSleepTime(uint ms) - { - mSleepTime = ms; - } - - } -} \ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/thread.h b/source/libs/asura-lib-utils/threading/thread.h deleted file mode 100644 index 0e75770..0000000 --- a/source/libs/asura-lib-utils/threading/thread.h +++ /dev/null @@ -1,221 +0,0 @@ -#ifndef __ASURA_THREAD_H__ -#define __ASURA_THREAD_H__ - -#include -#include - -#include - -#include "task.h" -#include "mutex.h" -#include "semaphore.h" - -namespace AsuraEngine -{ - namespace Threading - { - - class ThreadImpl; - - /// - /// 线程的几种不同的实现: - /// 1: Deferred(延迟模式),线程上的任务完成后,需要手动在主线程调用Post方法, - /// 在主线程调回调函数,将发布从异步改为同步操作,解决主lua_State冲突的问题。 - /// 2: Immediate(立即模式),每一个线程维护一个lua_newthread创建出来的lua_State。 - /// 回调函数在不同的lua_State中调用,避免不同的线程访问同一个lua_State。 - /// - enum ThreadType - { - THREAD_TYPE_DEFERRED, - THREAD_TYPE_IMMEDIATE, - }; - - enum ThreadState - { - THREAD_STATE_IDLE, ///< 闲置,还未创建内核对象 - THREAD_STATE_RUNNING, ///< 正在运行循环 - THREAD_STATE_PAUSED, ///< 在循环中暂停 - THREAD_STATE_STOPPED, ///< 退出循环 - }; - - /// - /// 线程主体,每个线程维护一个task queue。 - /// - class Thread ASURA_FINAL - : public AEScripting::Portable - { - public: - - LUAX_DECL_FACTORY(Thread); - - Thread(lua_State* luaThread, ThreadType type = THREAD_TYPE_DEFERRED, uint sleepTime = 1, const std::string& name = ""); - ~Thread(); - - bool AddTask(Task* task); - /// - /// 获得等待处理的任务数 - /// - uint GetTaskCount(); - - void Idle(); - - /// - /// 创建内核对象,并运行。如果是daemon,会等待手动stop。否则会在某时刻队列完成后自动stop。 - /// - bool Start(bool daemon = true, uint32 stacksize = 0); - - /// - /// 非同步线程控制,不是实时的。可能需要在主线程里使用Is函数确认到达指定状态。 - /// - void Pause(); - void Resume(); - void Stop(); - - /// - /// 同步线程控制,会等返回来信号后继续向下执行。会造成主线程等待。 - /// - void PauseSync(); - void ResumeSync(); - void StopSync(); - - /// - /// 父线程等待本线程结束后才继续执行。 - /// - void Join(); - - ThreadState GetState(); - - /// - /// 逻辑层面的线程状态: - /// 1: Idle(空闲),线程创建后的默认状态,可以随时加任务并且Start。 - /// 2: Running(运行),内核对象呗创建,已经处于内核调度中,并处理具体Task。 - /// 3: Paused(暂停),依然存在于内核中,但是跳过了对任务的处理,逻辑上暂停。 - /// 4: Stopped(停止),依然存在于内核中,但是已经无法继续处理任务。 - /// - bool IsIdle(); - bool IsRunning(); - bool IsPaused(); - bool IsStopped(); - - bool IsCurrent(); - - /// - /// 执行任务队列。 - /// - void Process(); - - const std::string& GetName(); - - /// - /// 回调。 - /// - void Post(); - - /// - /// 休眠函数 - /// - void Sleep(uint ms); - - /// - /// 设置休眠时间 - /// - void SetSleepTime(uint ms); - - private: - - //----------------------------------------------------------------------------// - - LUAX_DECL_ENUM(ThreadType); - LUAX_DECL_ENUM(ThreadState); - - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_AddTask); - LUAX_DECL_METHOD(_Start); - LUAX_DECL_METHOD(_Idle); - LUAX_DECL_METHOD(_Pause); - LUAX_DECL_METHOD(_Resume); - LUAX_DECL_METHOD(_Stop); - LUAX_DECL_METHOD(_Join); - LUAX_DECL_METHOD(_IsRunning); - LUAX_DECL_METHOD(_IsPaused); - LUAX_DECL_METHOD(_IsStopped); - LUAX_DECL_METHOD(_IsCurrent); - LUAX_DECL_METHOD(_Sleep); - LUAX_DECL_METHOD(_Post); - LUAX_DECL_METHOD(_GetName); - LUAX_DECL_METHOD(_GetType); - LUAX_DECL_METHOD(_GetState); - LUAX_DECL_METHOD(_SetSleepTime); - - //----------------------------------------------------------------------------// - - /// - /// 此次运行是否是守护模式。 - /// - bool mIsDaemon; - - lua_State* mLuaThread; - - ThreadImpl* mImpl; - std::string mName; - ThreadType mType; - uint mSleepTime; - - ThreadState mState; - Mutex mStateMutex; - - /// - /// 同步控制相关的信号量 - /// - Semaphore mSemPause; - Semaphore mSemResume; - Semaphore mSemStop; - - /// - /// 待处理的任务队列。 - /// - std::queue mTaskQueue; - Mutex mTaskQueueMutex; - - /// - /// 延迟模式使用 - /// - std::queue mFinishedTasks; - Mutex mFinishedMutex; - - /// - /// 立即模式使用,回调使用的lua线程 - /// - lua_State* mCallbackThread; - Luax::LuaxMemberRef mCallbackThreadRef; - - }; - - /// - /// 线程的具体实现,对用户是透明的,一共准备了四种策略: - /// 1: win32 - /// 2: posix - /// 3: SDL - /// 4: std::thread - /// - ASURA_ABSTRACT class ThreadImpl - { - public: - ThreadImpl() {}; - virtual ~ThreadImpl() {}; - - virtual bool Start(Thread* thread, uint32 stacksize = 0) = 0; - virtual void Join() = 0; - virtual void Kill() = 0; - - virtual void Sleep(uint ms) = 0; - - virtual bool IsRunning() = 0; - virtual bool IsCurrent() = 0; - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp b/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp deleted file mode 100644 index d2ad7af..0000000 --- a/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "thread_impl_posix.h" - -namespace AsuraEngine -{ - namespace Threading - { - - } -} \ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/thread_impl_posix.h b/source/libs/asura-lib-utils/threading/thread_impl_posix.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/threading/thread_impl_sdl.cpp b/source/libs/asura-lib-utils/threading/thread_impl_sdl.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/threading/thread_impl_sdl.h b/source/libs/asura-lib-utils/threading/thread_impl_sdl.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/threading/thread_impl_std.cpp b/source/libs/asura-lib-utils/threading/thread_impl_std.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/threading/thread_impl_std.h b/source/libs/asura-lib-utils/threading/thread_impl_std.h deleted file mode 100644 index 0e7d3da..0000000 --- a/source/libs/asura-lib-utils/threading/thread_impl_std.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef __ASURA_THREAD_STD_H__ -#define __ASURA_THREAD_STD_H__ - -#include "../utils_config.h" - -#if ASURA_THREAD_STD - -#include - -#include "thread.h" - -namespace AsuraEngine -{ - namespace Threading - { - - /// - /// Thread的std::thread实现。 - /// - class ThreadImplSTD : public ThreadImpl - { - public: - - ThreadImplSTD(); - ~ThreadImplSTD(); - - bool Start(Thread* thread, uint32 stacksize) override; - void Join() override; - void Kill() override; - - bool IsRunning() override; - bool IsCurrent() override; - - private: - - }; - - } -} - -#endif // #if ASURA_THREAD_STD - -#endif // __ASURA_THREAD_STD_H__ \ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp b/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp deleted file mode 100644 index 6871c2d..0000000 --- a/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "thread_impl_win32.h" -#include "thread.h" - -#include - -namespace AsuraEngine -{ - namespace Threading - { - - static DWORD WINAPI _thread_win32_runner(LPVOID param) - { - Thread* thread = (Thread*)param; - thread->Process(); - return 0; - } - - ThreadImplWin32::ThreadImplWin32() - { - } - - ThreadImplWin32::~ThreadImplWin32() - { - if (!mHandle) return; - ::CloseHandle(mHandle); - mHandle = 0; - } - - bool ThreadImplWin32::Start(Thread* thread, uint32 stacksize/*=0*/) - { - assert(!IsRunning()); - mHandle = ::CreateThread( - NULL - , stacksize - , _thread_win32_runner - , thread - , 0 /*创建后立即进行调度*/ - , NULL); - - return mHandle; - } - - void ThreadImplWin32::Join() - { - // 父线程等待此线程返回 - ::WaitForSingleObject(mHandle, INFINITE); - } - - void ThreadImplWin32::Kill() - { - ::TerminateThread(mHandle, FALSE); - } - - void ThreadImplWin32::Sleep(uint ms) - { - ::Sleep(ms); - } - - bool ThreadImplWin32::IsRunning() - { - if (mHandle) { - DWORD exitCode = 0; - // https://blog.csdn.net/yuanmeng567/article/details/19485719 - ::GetExitCodeThread(mHandle, &exitCode); - return exitCode == STILL_ACTIVE; - } - return false; - } - - bool ThreadImplWin32::IsCurrent() - { - return mHandle == ::GetCurrentThread(); - } - - } -} \ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/thread_impl_win32.h b/source/libs/asura-lib-utils/threading/thread_impl_win32.h deleted file mode 100644 index a22aeef..0000000 --- a/source/libs/asura-lib-utils/threading/thread_impl_win32.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef __ASURA_THREAD_WIN32_H__ -#define __ASURA_THREAD_WIN32_H__ - -#include "../utils_config.h" - -#if ASURA_THREAD_WIN32 - -#include - -#include "thread.h" - -namespace AsuraEngine -{ - namespace Threading - { - - /// - /// Thread的win32实现。 - /// - class ThreadImplWin32 : public ThreadImpl - { - public: - - ThreadImplWin32(); - ~ThreadImplWin32(); - - bool Start(Thread* thread, uint32 stacksize) override; - void Join() override; - void Kill() override; - - void Sleep(uint ms) override; - - bool IsRunning() override; - bool IsCurrent() override; - - private: - - HANDLE mHandle; - - }; - - } -} - -#endif // #if ASURA_THREAD_WIN32 - -#endif // __ASURA_THREAD_WIN32_H__ \ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/thread_task.cpp b/source/libs/asura-lib-utils/threading/thread_task.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/threading/thread_task.h b/source/libs/asura-lib-utils/threading/thread_task.h deleted file mode 100644 index 1ea0a1a..0000000 --- a/source/libs/asura-lib-utils/threading/thread_task.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef __ASURA_THRAD_TASK_H__ -#define __ASURA_THRAD_TASK_H__ - -#include -#include - -namespace AsuraEngine -{ - namespace Threading - { - - /// - /// 希望放在另一个线程处理的任务,继承Task并重写Execute方法。 - /// - ASURA_ABSTRACT class ThreadTask - : virtual public AEScripting::NativeAccessor - { - public: - - ThreadTask(); - virtual ~ThreadTask(); - - /// - /// 执行任务,完成后返回true,调用回调函数。 - /// - virtual bool Execute() = 0; - - /// - /// 调用回调。 - /// - virtual void Invoke() = 0; - - protected: - - Luax::LuaxMemberRef mCallback; - - }; - - } -} - -namespace AEThreading = AsuraEngine::Threading; - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/type.h b/source/libs/asura-lib-utils/type.h deleted file mode 100644 index 1ed2d42..0000000 --- a/source/libs/asura-lib-utils/type.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef __ASURA_UTILS_TYPE_H__ -#define __ASURA_UTILS_TYPE_H__ - -#include -#include - -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; - - //--------------------------------------------------------------------------------// - -#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_LIBRARY_EXPORT __declspec(dllexport) - #define ASURA_LIBRARY_IMPORT __declspec(dllimport) - #define ASURA_FORCE_INLINE __forceinline - #define ASURA_RESTRICT __restrict - #define ASURA_ATTRIBUTE_USED - #define ASURA_ABSTRACT - #define ASURA_API ASURA_LIBRARY_EXPORT - - #define ASURA_WINDOWS 1 -#else - #define ASURA_FINAL final - #define ASURA_LIBRARY_EXPORT __attribute__((visibility("default"))) - #define ASURA_LIBRARY_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_LIBRARY_EXPORT -#endif - - /// - /// 表明输出和引用参数 - /// -#define ASURA_OUT -#define ASURA_REF - /// - /// 表明移动指针所有权 - /// -#define ASURA_MOVE - - //--------------------------------------------------------------------------------// - -#define ASURA_SDL_HOST 1 - -} // namespace AsuraEngine - -#endif // __ASURA_CONFIG_H__ \ No newline at end of file diff --git a/source/libs/asura-lib-utils/utils.h b/source/libs/asura-lib-utils/utils.h deleted file mode 100644 index ce1c6a1..0000000 --- a/source/libs/asura-lib-utils/utils.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __ASURA_UTILS_H__ -#define __ASURA_UTILS_H__ - -#include "utils_module.h" - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/utils_config.h b/source/libs/asura-lib-utils/utils_config.h deleted file mode 100644 index 02837dc..0000000 --- a/source/libs/asura-lib-utils/utils_config.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __ASURA_UTILS_CONFIG_H__ -#define __ASURA_UTILS_CONFIG_H__ - -#define ASURA_THREAD_WIN32 1 -#define ASURA_THREAD_STD 1 - -#define ASURA_MUTEX_WIN32_CRITICLE_SECTION 1 -#define ASURA_MUTEX_WIN32_KERNAL_MUTEX 1 - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/utils_module.cpp b/source/libs/asura-lib-utils/utils_module.cpp deleted file mode 100644 index 61780e6..0000000 --- a/source/libs/asura-lib-utils/utils_module.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "utils_module.h" - -using namespace AsuraEngine::IO; -using namespace AsuraEngine::Threading; - -namespace AsuraEngine -{ - - void UtilsModule::Initialize(Luax::LuaxState& state) - { - // IO - LUAX_REGISTER_SINGLETON(state, Filesystem); - LUAX_REGISTER_FACTORY(state, DataBuffer); - LUAX_REGISTER_FACTORY(state, FileData); - LUAX_REGISTER_FACTORY(state, File); - LUAX_REGISTER_FACTORY(state, IOTask); - // Threading - LUAX_REGISTER_FACTORY(state, Thread); - } - - void UtilsModule::Finalize(Luax::LuaxState& state) - { - } - -} \ No newline at end of file diff --git a/source/libs/asura-lib-utils/utils_module.h b/source/libs/asura-lib-utils/utils_module.h deleted file mode 100644 index e802730..0000000 --- a/source/libs/asura-lib-utils/utils_module.h +++ /dev/null @@ -1,32 +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" - -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 -- cgit v1.1-26-g67d0