From 1497dccd63a84b7ee2b229b1ad9c5c02718f2a78 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 19 Mar 2019 23:06:27 +0800 Subject: *rename --- .../filesystem/binding/data_buffer.binding.cpp | 68 ++++++++++++++++++++++ .../asura-lib-utils/filesystem/data_buffer.cpp | 29 +++++++++ .../libs/asura-lib-utils/filesystem/data_buffer.h | 45 ++++++++++++++ .../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 | 44 ++++++++++++++ 8 files changed, 275 insertions(+) create mode 100644 source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp create mode 100644 source/libs/asura-lib-utils/filesystem/data_buffer.cpp create mode 100644 source/libs/asura-lib-utils/filesystem/data_buffer.h create mode 100644 source/libs/asura-lib-utils/filesystem/decoded_data.cpp create mode 100644 source/libs/asura-lib-utils/filesystem/decoded_data.h create mode 100644 source/libs/asura-lib-utils/filesystem/reloadable.h create mode 100644 source/libs/asura-lib-utils/filesystem/resource_manager.cpp create 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 new file mode 100644 index 0000000..a9113a7 --- /dev/null +++ b/source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp @@ -0,0 +1,68 @@ +#include "../data_buffer.h" + +using namespace Luax; + +namespace AsuraEngine +{ + namespace Filesystem + { + + LUAX_REGISTRY(DataBuffer) + { + luaL_Reg f[] = { + { "New", _New }, + { "SetContent", _SetContent }, + { "GetContent", _GetContent }, + { "GetContentLength", _GetContentLength }, + {0, 0} + }; + + state.RegisterMethods(f); + } + + LUAX_POSTPROCESS(DataBuffer) + { + + } + + LUAX_IMPL_METHOD(DataBuffer, _New) + { + + } + + // SetContent(dataBuffer, lString) + LUAX_IMPL_METHOD(DataBuffer, _SetContent) + { + LUAX_SETUP(L, "US"); + // params: + // 1: data buffer + // 2: lstring + + DataBuffer* self = state.GetLuaUserdata(1); + size_t size = 0; + const char* str = lua_tolstring(L, 2, &size); + void* data = new char[size]; + memcpy(data, str, size); + self->SetContent(data, size); + return 0; + } + + LUAX_IMPL_METHOD(DataBuffer, _GetContent) + { + LUAX_SETUP(L, "U"); + + DataBuffer* self = state.GetLuaUserdata(1); + lua_pushlstring(L, (const char*)self->data, self->size); + return 1; + } + + LUAX_IMPL_METHOD(DataBuffer, _GetContentLength) + { + LUAX_SETUP(L, "U"); + DataBuffer* self = state.GetLuaUserdata(1); + lua_pushinteger(L, self->size); + return 1; + } + + } +} \ 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 new file mode 100644 index 0000000..629dc92 --- /dev/null +++ b/source/libs/asura-lib-utils/filesystem/data_buffer.cpp @@ -0,0 +1,29 @@ +#include "data_buffer.h" + +namespace AsuraEngine +{ + namespace Filesystem + { + + DataBuffer::DataBuffer(const void* data, std::size_t size) + { + this->data = (const byte*)data; + this->size = size; + } + + DataBuffer::~DataBuffer() + { + delete[] data; + } + + void DataBuffer::SetContent(const void* data, std::size_t siez) + { + if (this->data != nullptr) + delete[] this->data; + + this->data = (const byte*)data; + this->size = size; + } + + } +} \ 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 new file mode 100644 index 0000000..4b013ed --- /dev/null +++ b/source/libs/asura-lib-utils/filesystem/data_buffer.h @@ -0,0 +1,45 @@ +#ifndef __ASURA_ENGINE_DATABUFFER_H__ +#define __ASURA_ENGINE_DATABUFFER_H__ + +#include + +#include "../scripting/Luax.hpp" +#include "../scripting/portable.hpp" + +namespace AsuraEngine +{ + namespace Filesystem + { + + /// + /// 对内存数据的封装,所有的数据使用Data buffer包装,不直接使用const void*。通过resource manager读取。 + /// + class DataBuffer ASURA_FINAL + : public Scripting::Portable + { + public: + + DataBuffer(const void* data, std::size_t size); + + ~DataBuffer(); + + void SetContent(const void* data, std::size_t siez); + + const byte* data; + size_t size; + + //---------------------------------------------------------------------------------------------------------- + + LUAX_DECL_FACTORY(DataBuffer); + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_SetContent); + LUAX_DECL_METHOD(_GetContent); + LUAX_DECL_METHOD(_GetContentLength); + + }; + + } +} + +#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 new file mode 100644 index 0000000..125c652 --- /dev/null +++ b/source/libs/asura-lib-utils/filesystem/decoded_data.cpp @@ -0,0 +1,20 @@ +#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 new file mode 100644 index 0000000..49b5815 --- /dev/null +++ b/source/libs/asura-lib-utils/filesystem/decoded_data.h @@ -0,0 +1,42 @@ +#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 new file mode 100644 index 0000000..7c4ea52 --- /dev/null +++ b/source/libs/asura-lib-utils/filesystem/reloadable.h @@ -0,0 +1,27 @@ +#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 new file mode 100644 index 0000000..e69de29 diff --git a/source/libs/asura-lib-utils/filesystem/resource_manager.h b/source/libs/asura-lib-utils/filesystem/resource_manager.h new file mode 100644 index 0000000..c5d8f06 --- /dev/null +++ b/source/libs/asura-lib-utils/filesystem/resource_manager.h @@ -0,0 +1,44 @@ +#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); + + }; + + } +} + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0