From 03b3b8ae80559745f98ef94569b421adddeb441f Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Mar 2019 23:46:59 +0800 Subject: *misc --- .../filesystem/binding/data_buffer.binding.cpp | 110 --------------------- .../asura-lib-utils/filesystem/data_buffer.cpp | 67 ------------- .../libs/asura-lib-utils/filesystem/data_buffer.h | 55 ----------- .../asura-lib-utils/filesystem/decoded_data.cpp | 20 ---- .../libs/asura-lib-utils/filesystem/decoded_data.h | 42 -------- .../libs/asura-lib-utils/filesystem/reloadable.h | 27 ----- .../filesystem/resource_manager.cpp | 0 .../asura-lib-utils/filesystem/resource_manager.h | 48 --------- 8 files changed, 369 deletions(-) delete mode 100644 source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp delete mode 100644 source/libs/asura-lib-utils/filesystem/data_buffer.cpp delete mode 100644 source/libs/asura-lib-utils/filesystem/data_buffer.h delete mode 100644 source/libs/asura-lib-utils/filesystem/decoded_data.cpp delete mode 100644 source/libs/asura-lib-utils/filesystem/decoded_data.h delete mode 100644 source/libs/asura-lib-utils/filesystem/reloadable.h delete mode 100644 source/libs/asura-lib-utils/filesystem/resource_manager.cpp delete mode 100644 source/libs/asura-lib-utils/filesystem/resource_manager.h (limited to 'source/libs/asura-lib-utils/filesystem') diff --git a/source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp b/source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp deleted file mode 100644 index 8e92eee..0000000 --- a/source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include "../data_buffer.h" - -using namespace Luax; - -namespace AsuraEngine -{ - namespace Filesystem - { - - LUAX_REGISTRY(DataBuffer) - { - LUAX_REGISTER_METHODS(state, - { "New", _New }, - { "GetBuffer", _GetBuffer }, - { "GetSize", _GetSize }, - { "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)) - { - byte* bytes; - size_t size; - 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); - } - else - { - return state.ErrorType(1, "number or string"); - } - } - - // lsting, len = databuffer:GetBuffer() - LUAX_IMPL_METHOD(DataBuffer, _GetBuffer) - { - LUAX_SETUP(L, "U"); - - DataBuffer* self = state.GetUserdata(1); - lua_pushlstring(L, self->GetBuffer(), self->GetSize()); - return 2; - } - - // 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:Load(lstring) - // 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); - buffer->Load(data, size); - return 0; - } - else if(state.IsType(2, LUA_TUSERDATA)) - { - DataBuffer* src = state.CheckUserdata(2); - buffer->Load(*src); - return 0; - } - else - { - return state.ErrorType(1, "lstring or DataBuffer"); - } - } - - // databuffer:Clear() - LUAX_IMPL_METHOD(DataBuffer, _Clear) - { - LUAX_SETUP(L, "U"); - - DataBuffer* self = state.GetUserdata(1); - self->Clear(); - return 0; - } - - } -} \ No newline at end of file diff --git a/source/libs/asura-lib-utils/filesystem/data_buffer.cpp b/source/libs/asura-lib-utils/filesystem/data_buffer.cpp deleted file mode 100644 index 32a123f..0000000 --- a/source/libs/asura-lib-utils/filesystem/data_buffer.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include -#include -#include "data_buffer.h" - -namespace AsuraEngine -{ - namespace Filesystem - { - - DataBuffer::DataBuffer(DataBuffer& src) - { - Load(src); - } - - DataBuffer::DataBuffer(std::size_t size) - : mSize(size) - , mBytes(nullptr) - { - 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::Load(DataBuffer& db) - { - Load(db.GetBuffer(), db.GetSize()); - } - - void DataBuffer::Load(const void* data, std::size_t size) - { - if (!mBytes || mSize != size) - { - delete[] mBytes; - mBytes = new byte[size]; - } - memcpy(mBytes, data, size); - } - - byte* DataBuffer::GetBuffer() - { - return mBytes; - } - - void DataBuffer::Clear() - { - if (mBytes) - memset(mBytes, 0, mSize); - } - - std::size_t DataBuffer::GetSize() - { - return mSize; - } - - } -} \ No newline at end of file diff --git a/source/libs/asura-lib-utils/filesystem/data_buffer.h b/source/libs/asura-lib-utils/filesystem/data_buffer.h deleted file mode 100644 index 5c80efb..0000000 --- a/source/libs/asura-lib-utils/filesystem/data_buffer.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef __ASURA_ENGINE_DATABUFFER_H__ -#define __ASURA_ENGINE_DATABUFFER_H__ - -#include - -#include "../scripting/portable.hpp" - -namespace AsuraEngine -{ - namespace Filesystem - { - - /// - /// 对内存数据的封装,所有的数据使用Data buffer包装,不直接使用const void*。通过resource manager读取。 - /// - class DataBuffer ASURA_FINAL - : public Scripting::Portable - { - public: - - DataBuffer(DataBuffer& src); - DataBuffer(std::size_t size); - DataBuffer(const void* bytes, std::size_t size); - ~DataBuffer(); - - byte* GetBuffer(); - size_t GetSize(); - - void Load(DataBuffer& db); - void Load(const void* bytes, std::size_t size); - void Clear(); - - private: - - byte* mBytes; - size_t mSize; - - //------------------------------------------------------------------------------------------------------------ - - public: - - LUAX_DECL_FACTORY(DataBuffer); - - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_GetBuffer); - LUAX_DECL_METHOD(_GetSize); - LUAX_DECL_METHOD(_Load); - LUAX_DECL_METHOD(_Clear); - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/filesystem/decoded_data.cpp b/source/libs/asura-lib-utils/filesystem/decoded_data.cpp deleted file mode 100644 index 125c652..0000000 --- a/source/libs/asura-lib-utils/filesystem/decoded_data.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "DecodedData.h" -#include "Exceptions/Exception.h" - -namespace AsuraEngine -{ - namespace Filesystem - { - - DecodedData::DecodedData(const DataBuffer* databuffer) - { - Decode(databuffer); - } - - DecodedData::~DecodedData() - { - - } - - } -} diff --git a/source/libs/asura-lib-utils/filesystem/decoded_data.h b/source/libs/asura-lib-utils/filesystem/decoded_data.h deleted file mode 100644 index 49b5815..0000000 --- a/source/libs/asura-lib-utils/filesystem/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 Filesystem - { - - /// - /// 可以在另一个线程构建的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/filesystem/reloadable.h b/source/libs/asura-lib-utils/filesystem/reloadable.h deleted file mode 100644 index 7c4ea52..0000000 --- a/source/libs/asura-lib-utils/filesystem/reloadable.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef __ASURA_ENGINE_RELOADABLE_H__ -#define __ASURA_ENGINE_RELOADABLE_H__ - -#include "../scripting/portable.hpp" - -namespace AsuraEngine -{ - namespace Filesystem - { - - /// - /// 可以重新构建的数据结构。比如图片、音频这种,从外部数据可以直接构建,可以在编辑器内重新构建,适用于不改变handle的资源。 - /// - ASURA_ABSTRACT class Reloadable - { - public: - Reloadable(); - virtual ~Reloadable(); - - // 继承Reloadable的需要提供一个load方法 - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/libs/asura-lib-utils/filesystem/resource_manager.cpp b/source/libs/asura-lib-utils/filesystem/resource_manager.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/libs/asura-lib-utils/filesystem/resource_manager.h b/source/libs/asura-lib-utils/filesystem/resource_manager.h deleted file mode 100644 index 36d46cf..0000000 --- a/source/libs/asura-lib-utils/filesystem/resource_manager.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef __ASURA_ENGINE_RESOURCE_MANAGER_H__ -#define __ASURA_ENGINE_RESOURCE_MANAGER_H__ - -#include - -#include "../scripting/portable.hpp" -#include "data_buffer.h" - -namespace AsuraEngine -{ - namespace Filesystem - { - - /// - /// 资源管理,负责加载、存储资源,指定根目录等。 - /// - class ResourceManager ASURA_FINAL - { - public: - - ResourceManager(); - ~ResourceManager(); - - /// - /// 装载根目录 - /// - void Mount(const std::string& root); - - /// - /// 读取文件并返回一个data buffer,注意如果要确保正确回收内存,在调用处使用unique_ptr - /// - DataBuffer* LoadFile(const std::string& path); - - /// - /// 保存data buffer里的数据 - /// - void SaveFile(const std::string& path, const DataBuffer* buffer); - - //---------------------------------------------------------------------------------------------------------- - - LUAX_DECL_SINGLETON(ResourceManager); - - }; - - } -} - -#endif \ No newline at end of file -- cgit v1.1-26-g67d0