summaryrefslogtreecommitdiff
path: root/source/libs
diff options
context:
space:
mode:
Diffstat (limited to 'source/libs')
-rw-r--r--source/libs/asura-lib-core/graphics/binding/_image.cpp4
-rw-r--r--source/libs/asura-lib-core/graphics/image.h9
-rw-r--r--source/libs/asura-lib-core/graphics/shader.h2
-rw-r--r--source/libs/asura-lib-core/input/mouse.h4
-rw-r--r--source/libs/asura-lib-core/window/window.cpp (renamed from source/libs/asura-lib-core/graphics/window.cpp)0
-rw-r--r--source/libs/asura-lib-core/window/window.h (renamed from source/libs/asura-lib-core/graphics/window.h)4
-rw-r--r--source/libs/asura-lib-core/window/window_impl_glew.cpp (renamed from source/libs/asura-lib-core/graphics/window_impl_glew.cpp)0
-rw-r--r--source/libs/asura-lib-core/window/window_impl_glew.h (renamed from source/libs/asura-lib-core/graphics/window_impl_glew.h)0
-rw-r--r--source/libs/asura-lib-core/window/window_impl_glut.cpp (renamed from source/libs/asura-lib-core/graphics/window_impl_glut.cpp)0
-rw-r--r--source/libs/asura-lib-core/window/window_impl_glut.h (renamed from source/libs/asura-lib-core/graphics/window_impl_glut.h)0
-rw-r--r--source/libs/asura-lib-core/window/window_impl_sdl.cpp (renamed from source/libs/asura-lib-core/graphics/window_impl_sdl.cpp)0
-rw-r--r--source/libs/asura-lib-core/window/window_impl_sdl.h (renamed from source/libs/asura-lib-core/graphics/window_impl_sdl.h)0
-rw-r--r--source/libs/asura-lib-openal/sound.h8
-rw-r--r--source/libs/asura-lib-openal/sound_decode_task.cpp0
-rw-r--r--source/libs/asura-lib-openal/sound_decode_task.h25
-rw-r--r--source/libs/asura-lib-openal/sound_decoder.cpp29
-rw-r--r--source/libs/asura-lib-openal/sound_decoder.h7
-rw-r--r--source/libs/asura-lib-utils/io/binding/_data_buffer.cpp18
-rw-r--r--source/libs/asura-lib-utils/io/binding/_file.cpp12
-rw-r--r--source/libs/asura-lib-utils/io/binding/_file_system.cpp22
-rw-r--r--source/libs/asura-lib-utils/io/binding/_io_task.cpp18
-rw-r--r--source/libs/asura-lib-utils/io/data_buffer.cpp10
-rw-r--r--source/libs/asura-lib-utils/io/data_buffer.h3
-rw-r--r--source/libs/asura-lib-utils/io/file.cpp10
-rw-r--r--source/libs/asura-lib-utils/io/io_task.cpp25
-rw-r--r--source/libs/asura-lib-utils/io/io_task.h26
-rw-r--r--source/libs/asura-lib-utils/scripting/lua_env.h28
-rw-r--r--source/libs/asura-lib-utils/threading/binding/_thread.cpp21
-rw-r--r--source/libs/asura-lib-utils/threading/mutex.h16
-rw-r--r--source/libs/asura-lib-utils/threading/task.cpp12
-rw-r--r--source/libs/asura-lib-utils/threading/task.h11
-rw-r--r--source/libs/asura-lib-utils/threading/thread.cpp14
-rw-r--r--source/libs/asura-lib-utils/threading/thread.h52
-rw-r--r--source/libs/asura-lib-utils/threading/thread_impl_posix.cpp9
-rw-r--r--source/libs/asura-lib-utils/threading/thread_impl_win32.cpp8
-rw-r--r--source/libs/asura-lib-utils/threading/thread_task.cpp0
-rw-r--r--source/libs/asura-lib-utils/threading/thread_task.h44
-rw-r--r--source/libs/asura-lib-utils/type.h8
-rw-r--r--source/libs/asura-lib-utils/utils_module.cpp1
-rw-r--r--source/libs/asura-lib-utils/utils_module.h1
40 files changed, 361 insertions, 100 deletions
diff --git a/source/libs/asura-lib-core/graphics/binding/_image.cpp b/source/libs/asura-lib-core/graphics/binding/_image.cpp
index b455ad5..cb008d3 100644
--- a/source/libs/asura-lib-core/graphics/binding/_image.cpp
+++ b/source/libs/asura-lib-core/graphics/binding/_image.cpp
@@ -80,8 +80,8 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, Image);
- uint x = state.CheckParam<uint>(2);
- uint y = state.CheckParam<uint>(3);
+ uint x = state.CheckValue<uint>(2);
+ uint y = state.CheckValue<uint>(3);
Color32* c32 = new Color32(self->GetPixel(x, y));
c32->PushLuaxUserdata(state);
return 1;
diff --git a/source/libs/asura-lib-core/graphics/image.h b/source/libs/asura-lib-core/graphics/image.h
index 4c1c7b5..4d9787b 100644
--- a/source/libs/asura-lib-core/graphics/image.h
+++ b/source/libs/asura-lib-core/graphics/image.h
@@ -22,8 +22,9 @@ namespace AsuraEngine
class ImageFactory;
///
- /// ImageͼƬڴ󣬶ȡϷ󱣴ĽһImageڴ桢ԴֻᱣһݣҪ
- /// imageêλãźתǶȣʹspriteһֻࡣҪǿǵeditorengineʹòͬķװ
+ /// ImageͼƬڴ󣬶ȡϷ󱣴ĽһImageڴ桢Դֻᱣһ
+ /// ݣҪimageêλãźתǶȣʹsprite
+ /// һֻࡣҪǿǵeditorengineʹòͬķװ
///
class Image ASURA_FINAL
: public Drawable
@@ -39,8 +40,8 @@ namespace AsuraEngine
~Image();
///
- /// bufferimageϢmPixelsΪգݡ¹imageʹglTexImage2Dύimage
- /// ݡ
+ /// bufferimageϢmPixelsΪգݡ¹image
+ /// ʹglTexImage2Dύimageݡ
///
bool Load(ImageData* data);
diff --git a/source/libs/asura-lib-core/graphics/shader.h b/source/libs/asura-lib-core/graphics/shader.h
index 575a37e..1c81355 100644
--- a/source/libs/asura-lib-core/graphics/shader.h
+++ b/source/libs/asura-lib-core/graphics/shader.h
@@ -94,7 +94,7 @@ namespace AsuraEngine
///
GLuint mProgramHandle;
- //------------------------------------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------//
public:
diff --git a/source/libs/asura-lib-core/input/mouse.h b/source/libs/asura-lib-core/input/mouse.h
index 0f34fdd..3ab67fa 100644
--- a/source/libs/asura-lib-core/input/mouse.h
+++ b/source/libs/asura-lib-core/input/mouse.h
@@ -1,8 +1,8 @@
#ifndef __ASURA_ENGINE_MOUSE_H__
#define __ASURA_ENGINE_MOUSE_H__
-#include "Cursor.h"
-#include "InputDevice.hpp"
+#include "cursor.h"
+#include "input_device.hpp"
namespace AsuraEngine
{
diff --git a/source/libs/asura-lib-core/graphics/window.cpp b/source/libs/asura-lib-core/window/window.cpp
index 83a4f53..83a4f53 100644
--- a/source/libs/asura-lib-core/graphics/window.cpp
+++ b/source/libs/asura-lib-core/window/window.cpp
diff --git a/source/libs/asura-lib-core/graphics/window.h b/source/libs/asura-lib-core/window/window.h
index 1b219a2..39db73e 100644
--- a/source/libs/asura-lib-core/graphics/window.h
+++ b/source/libs/asura-lib-core/window/window.h
@@ -4,8 +4,8 @@
#include <asura-lib-utils/scripting/portable.hpp>
#include <asura-lib-utils/math/vector2.hpp>
-#include "render_state.h"
-#include "render_target.h"
+#include "../graphics/render_state.h"
+#include "../graphics/render_target.h"
namespace AsuraEngine
{
diff --git a/source/libs/asura-lib-core/graphics/window_impl_glew.cpp b/source/libs/asura-lib-core/window/window_impl_glew.cpp
index e69de29..e69de29 100644
--- a/source/libs/asura-lib-core/graphics/window_impl_glew.cpp
+++ b/source/libs/asura-lib-core/window/window_impl_glew.cpp
diff --git a/source/libs/asura-lib-core/graphics/window_impl_glew.h b/source/libs/asura-lib-core/window/window_impl_glew.h
index e69de29..e69de29 100644
--- a/source/libs/asura-lib-core/graphics/window_impl_glew.h
+++ b/source/libs/asura-lib-core/window/window_impl_glew.h
diff --git a/source/libs/asura-lib-core/graphics/window_impl_glut.cpp b/source/libs/asura-lib-core/window/window_impl_glut.cpp
index e69de29..e69de29 100644
--- a/source/libs/asura-lib-core/graphics/window_impl_glut.cpp
+++ b/source/libs/asura-lib-core/window/window_impl_glut.cpp
diff --git a/source/libs/asura-lib-core/graphics/window_impl_glut.h b/source/libs/asura-lib-core/window/window_impl_glut.h
index e69de29..e69de29 100644
--- a/source/libs/asura-lib-core/graphics/window_impl_glut.h
+++ b/source/libs/asura-lib-core/window/window_impl_glut.h
diff --git a/source/libs/asura-lib-core/graphics/window_impl_sdl.cpp b/source/libs/asura-lib-core/window/window_impl_sdl.cpp
index e69de29..e69de29 100644
--- a/source/libs/asura-lib-core/graphics/window_impl_sdl.cpp
+++ b/source/libs/asura-lib-core/window/window_impl_sdl.cpp
diff --git a/source/libs/asura-lib-core/graphics/window_impl_sdl.h b/source/libs/asura-lib-core/window/window_impl_sdl.h
index e69de29..e69de29 100644
--- a/source/libs/asura-lib-core/graphics/window_impl_sdl.h
+++ b/source/libs/asura-lib-core/window/window_impl_sdl.h
diff --git a/source/libs/asura-lib-openal/sound.h b/source/libs/asura-lib-openal/sound.h
index 095bdb7..6c2d7c2 100644
--- a/source/libs/asura-lib-openal/sound.h
+++ b/source/libs/asura-lib-openal/sound.h
@@ -1,14 +1,18 @@
#ifndef __ASURA_ENGINE_SOUND_H__
#define __ASURA_ENGINE_SOUND_H__
-#include "Scripting/Portable.h"
+#include <asura-lib-utils/scripting/portable.hpp>
namespace AsuraEngine
{
namespace Audio
{
- class Sound ASURA_FINAL: virtual public Scripting::Portable
+ ///
+ /// Ƶļ
+ ///
+ class Sound ASURA_FINAL
+ : public AEScripting::Portable<Sound>
{
public:
diff --git a/source/libs/asura-lib-openal/sound_decode_task.cpp b/source/libs/asura-lib-openal/sound_decode_task.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/libs/asura-lib-openal/sound_decode_task.cpp
diff --git a/source/libs/asura-lib-openal/sound_decode_task.h b/source/libs/asura-lib-openal/sound_decode_task.h
new file mode 100644
index 0000000..d39013f
--- /dev/null
+++ b/source/libs/asura-lib-openal/sound_decode_task.h
@@ -0,0 +1,25 @@
+#ifndef __ASURA_OPENAL_SOUND_DECODER_TASK_H__
+#define __ASURA_OPENAL_SOUND_DECODER_TASK_H__
+
+#include <asura-lib-utils/threading/thread_task.h>
+
+namespace AsuraEngine
+{
+ namespace OpenAL
+ {
+
+ ///
+ /// Ƶļ
+ ///
+ class SoundDecodeTask : public AEThreading::ThreadTask
+ {
+ public:
+
+ private:
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-openal/sound_decoder.cpp b/source/libs/asura-lib-openal/sound_decoder.cpp
new file mode 100644
index 0000000..ad9f761
--- /dev/null
+++ b/source/libs/asura-lib-openal/sound_decoder.cpp
@@ -0,0 +1,29 @@
+#ifndef __ASURA_ENGINE_SOUND_DECODER_H__
+#define __ASURA_ENGINE_SOUND_DECODER_H__
+
+#include "Sound.h"
+#include "FileSystem/DataBuffer.h"
+
+namespace AsuraEngine
+{
+ namespace Audio
+ {
+
+ ///
+ /// Ƶļ
+ ///
+ class SoundDecoder
+ {
+ public:
+
+ SoundDecoder();
+ virtual ~SoundDecoder();
+
+ virtual Sound* Decode(const Filesystem::DataBuffer* db);
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-openal/sound_decoder.h b/source/libs/asura-lib-openal/sound_decoder.h
index ad9f761..2a3f087 100644
--- a/source/libs/asura-lib-openal/sound_decoder.h
+++ b/source/libs/asura-lib-openal/sound_decoder.h
@@ -1,8 +1,9 @@
#ifndef __ASURA_ENGINE_SOUND_DECODER_H__
#define __ASURA_ENGINE_SOUND_DECODER_H__
-#include "Sound.h"
-#include "FileSystem/DataBuffer.h"
+#include <asura-lib-utils/io/data_buffer.h>
+
+#include "sound.h"
namespace AsuraEngine
{
@@ -19,7 +20,7 @@ namespace AsuraEngine
SoundDecoder();
virtual ~SoundDecoder();
- virtual Sound* Decode(const Filesystem::DataBuffer* db);
+ virtual Sound* Decode(const AEIO::DataBuffer* db);
};
diff --git a/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp b/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp
index c42888c..6725bc4 100644
--- a/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp
+++ b/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp
@@ -10,12 +10,12 @@ namespace AsuraEngine
LUAX_REGISTRY(DataBuffer)
{
LUAX_REGISTER_METHODS(state,
- { "New", _New },
- { "GetBuffer", _GetData },
- { "GetSize", _GetSize },
- { "Refactor", _Refactor },
- { "Load", _Load },
- { "Clear", _Clear }
+ { "New", _New },
+ { "GetData", _GetData },
+ { "GetSize", _GetSize },
+ { "Refactor", _Refactor },
+ { "Load", _Load },
+ { "Clear", _Clear }
);
}
@@ -49,14 +49,14 @@ namespace AsuraEngine
}
}
- // lsting, len = databuffer:GetBuffer()
+ // lsting, len = databuffer:GetData()
LUAX_IMPL_METHOD(DataBuffer, _GetData)
{
LUAX_SETUP(L, "U");
DataBuffer* self = state.GetUserdata<DataBuffer>(1);
lua_pushlstring(L, self->GetData(), self->GetSize());
- return 2;
+ return 1;
}
// length = databuffer:GetSize()
@@ -74,7 +74,7 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, DataBuffer);
- size_t size = state.CheckParam<int>(2);
+ size_t size = state.CheckValue<int>(2);
self->Refactor(size);
return 0;
}
diff --git a/source/libs/asura-lib-utils/io/binding/_file.cpp b/source/libs/asura-lib-utils/io/binding/_file.cpp
index 0670379..c44bc90 100644
--- a/source/libs/asura-lib-utils/io/binding/_file.cpp
+++ b/source/libs/asura-lib-utils/io/binding/_file.cpp
@@ -49,7 +49,7 @@ namespace AsuraEngine
{
LUAX_STATE(L);
- cc8* name = state.CheckParam<cc8*>(1);
+ cc8* name = state.CheckValue<cc8*>(1);
File* file = new File(name);
file->PushLuaxUserdata(state);
return 1;
@@ -60,7 +60,7 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, File);
- File::FileMode mode = (File::FileMode)state.CheckParam<int>(2);
+ File::FileMode mode = (File::FileMode)state.CheckValue<int>(2);
state.Push(self->Open(mode));
return 1;
}
@@ -115,7 +115,7 @@ namespace AsuraEngine
DataBuffer* db = state.CheckUserdata<DataBuffer>(2);
if (!db) return state.ErrorType(2, "DataBuffer");
- int len = state.CheckParam<int>(3);
+ int len = state.CheckValue<int>(3);
int size = self->Read(db, len);
state.Push(size);
return 1;
@@ -164,7 +164,7 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, File);
- int pos = state.CheckParam<int>(2);
+ int pos = state.CheckValue<int>(2);
state.Push(self->Seek(pos));
return 1;
}
@@ -174,8 +174,8 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, File);
- BufferMode mode = (BufferMode)state.CheckParam<int>(2);
- int size = state.CheckParam<int>(3);
+ BufferMode mode = (BufferMode)state.CheckValue<int>(2);
+ int size = state.CheckValue<int>(3);
state.Push(self->SetBuffer(mode, size));
return 1;
}
diff --git a/source/libs/asura-lib-utils/io/binding/_file_system.cpp b/source/libs/asura-lib-utils/io/binding/_file_system.cpp
index 7132456..3843451 100644
--- a/source/libs/asura-lib-utils/io/binding/_file_system.cpp
+++ b/source/libs/asura-lib-utils/io/binding/_file_system.cpp
@@ -46,7 +46,7 @@ namespace AsuraEngine
{
PREPARE(L);
- const char* arg0 = state.CheckParam<const char*>(1);
+ const char* arg0 = state.CheckValue<const char*>(1);
fs->Init(arg0);
return 0;
}
@@ -111,7 +111,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
std::string mp;
if (fs->GetMountPoint(path, ASURA_OUT mp))
state.Push(mp);
@@ -126,7 +126,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* dir = state.CheckParam<cc8*>(1);
+ cc8* dir = state.CheckValue<cc8*>(1);
fs->SetWriteDirectory(dir);
return 0;
}
@@ -146,7 +146,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* name = state.CheckParam<cc8*>(1);
+ cc8* name = state.CheckValue<cc8*>(1);
File* file = fs->NewFile(name);
if (file)
file->PushLuaxUserdata(state);
@@ -160,7 +160,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
state.Push(fs->NewDirectory(path));
return 1;
}
@@ -170,7 +170,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
DataBuffer* db = state.CheckUserdata<DataBuffer>(2);
state.Push(fs->Write(path, db));
return 1;
@@ -181,7 +181,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
DataBuffer* db = state.CheckUserdata<DataBuffer>(2);
state.Push(fs->Append(path, db));
return 1;
@@ -192,7 +192,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
state.Push(fs->Remove(path));
return 1;
}
@@ -202,7 +202,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
FileData* fd = fs->Read(path);
if (fd)
{
@@ -223,7 +223,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
FileInfo info;
if (fs->GetFileInfo(path, &info))
{
@@ -244,7 +244,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
std::vector<std::string> items;
if(fs->GetDirectoryItems(path, ASURA_OUT items))
{
diff --git a/source/libs/asura-lib-utils/io/binding/_io_task.cpp b/source/libs/asura-lib-utils/io/binding/_io_task.cpp
index c03ff2a..b3c5988 100644
--- a/source/libs/asura-lib-utils/io/binding/_io_task.cpp
+++ b/source/libs/asura-lib-utils/io/binding/_io_task.cpp
@@ -16,19 +16,29 @@ namespace AsuraEngine
LUAX_POSTPROCESS(IOTask)
{
+ LUAX_REGISTER_ENUM(state, "EIOTaskType",
+ { "READ", IOTASK_TYPE_READ },
+ { "WRITE", IOTASK_TYPE_WRITE },
+ { "APPEND", IOTASK_TYPE_APPEND }
+ );
}
- // task = IOTask.New(path, dst)
+ // task = IOTask.New(path, buffer, type, callback)
LUAX_IMPL_METHOD(IOTask, _New)
{
LUAX_STATE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
DataBuffer* db = state.CheckUserdata<DataBuffer>(2);
- IOTask* task = new IOTask(path, db);
+ IOTaskType type = (IOTaskType)state.CheckValue<int>(3);
+ bool cbk = state.GetTop() >= 4 && state.IsType(4, LUA_TFUNCTION);
+
+ IOTask* task = new IOTask(path, db, type);
+ task->SetLuaxMemberRef(state, task->mBufferRef, 2);
+ if(cbk)
+ task->SetLuaxMemberRef(state, task->mCallback, 4);
task->PushLuaxUserdata(state);
- task->SetLuaxMemberRef(state, task->mDstRef, 2);
return 1;
}
diff --git a/source/libs/asura-lib-utils/io/data_buffer.cpp b/source/libs/asura-lib-utils/io/data_buffer.cpp
index 000869d..5049b38 100644
--- a/source/libs/asura-lib-utils/io/data_buffer.cpp
+++ b/source/libs/asura-lib-utils/io/data_buffer.cpp
@@ -88,5 +88,15 @@ namespace AsuraEngine
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
index 9dfe541..445bdf4 100644
--- a/source/libs/asura-lib-utils/io/data_buffer.h
+++ b/source/libs/asura-lib-utils/io/data_buffer.h
@@ -34,6 +34,9 @@ namespace AsuraEngine
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:
diff --git a/source/libs/asura-lib-utils/io/file.cpp b/source/libs/asura-lib-utils/io/file.cpp
index 976203d..0ff8c90 100644
--- a/source/libs/asura-lib-utils/io/file.cpp
+++ b/source/libs/asura-lib-utils/io/file.cpp
@@ -134,7 +134,10 @@ namespace AsuraEngine
if (length < 0)
throw Exception("Invalid read size.");
- return PHYSFS_readBytes(mFileHandle, dst->GetData(), length);
+ dst->Lock();
+ size_t size = PHYSFS_readBytes(mFileHandle, dst->GetData(), length);
+ dst->Unlock();
+ return size;
}
size_t File::ReadAll(ASURA_OUT DataBuffer* dst)
@@ -149,7 +152,10 @@ namespace AsuraEngine
if (dst->GetSize() < length)
throw Exception("Data buffer is too small compares to file length.");
- return PHYSFS_readBytes(mFileHandle, dst->GetData(), length);
+ dst->Lock();
+ size_t size = PHYSFS_readBytes(mFileHandle, dst->GetData(), length);
+ dst->Unlock();
+ return size;
}
#ifdef ASURA_WINDOWS
diff --git a/source/libs/asura-lib-utils/io/io_task.cpp b/source/libs/asura-lib-utils/io/io_task.cpp
index 1a50e56..7203175 100644
--- a/source/libs/asura-lib-utils/io/io_task.cpp
+++ b/source/libs/asura-lib-utils/io/io_task.cpp
@@ -1,5 +1,8 @@
+#include "file_system.h"
#include "io_task.h"
+#include <iostream>
+
using namespace AEScripting;
using namespace Luax;
@@ -8,9 +11,9 @@ namespace AsuraEngine
namespace IO
{
- IOTask::IOTask(const std::string& path, DataBuffer* buffer)
+ IOTask::IOTask(const std::string& path, DataBuffer* buffer, IOTaskType type)
: mPath(path)
- , mDst(buffer)
+ , mBuffer(buffer)
{
}
@@ -20,17 +23,29 @@ namespace AsuraEngine
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* thread)
+ void IOTask::Invoke()
{
if (mCallback)
{
- LuaxScopedState state(thread);
+ LuaxScopedState state(LuaEnv::Get()->GetMainState());
if (PushLuaxMemberRef(state, mCallback))
{
- PushLuaxMemberRef(state, mDstRef);
+ 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
index a79b2a8..5f454ee 100644
--- a/source/libs/asura-lib-utils/io/io_task.h
+++ b/source/libs/asura-lib-utils/io/io_task.h
@@ -13,32 +13,42 @@ namespace AsuraEngine
namespace IO
{
+ enum IOTaskType
+ {
+ IOTASK_TYPE_READ,
+ IOTASK_TYPE_WRITE,
+ IOTASK_TYPE_APPEND,
+ };
+
///
/// ȡļ
///
class IOTask ASURA_FINAL
- : public AEScripting::Portable<IOTask>
- , public AEThreading::Task
+ : public AEThreading::Task
+ , public AEScripting::Portable<IOTask>
{
public:
LUAX_DECL_FACTORY(IOTask);
- IOTask(const std::string& path, DataBuffer* buffer);
+ IOTask(const std::string& path, DataBuffer* buffer, IOTaskType type);
~IOTask();
bool Execute() override ;
- void Invoke(lua_State* thread) override;
+ void Invoke() override;
private:
- std::string mPath;
-
- DataBuffer* mDst;
- Luax::LuaxMemberRef mDstRef;
+ LUAX_DECL_ENUM(IOTaskType);
LUAX_DECL_METHOD(_New);
+ std::string mPath;
+ IOTaskType mType;
+
+ ASURA_REF DataBuffer* mBuffer;
+ Luax::LuaxMemberRef mBufferRef;
+
};
}
diff --git a/source/libs/asura-lib-utils/scripting/lua_env.h b/source/libs/asura-lib-utils/scripting/lua_env.h
index a467479..3bef3df 100644
--- a/source/libs/asura-lib-utils/scripting/lua_env.h
+++ b/source/libs/asura-lib-utils/scripting/lua_env.h
@@ -16,21 +16,41 @@ namespace AsuraEngine
{
///
- /// ͨӿڷlua state
+ /// ͨӿڷlua stateAsura˼ǣ߳άһluaӦõҪ߼ڴlua
+ /// ߳߽ջ
///
class LuaEnv ASURA_FINAL : public Singleton<LuaEnv>
{
public:
- LuaEnv() : mMainState(0){};
+ LuaEnv() : mMainState(0) {};
~LuaEnv() {};
///
/// ִջ
///
- inline void Init(lua_State* L) { ASSERT(!mMainState); mMainState = L; };
+ inline void Init()
+ {
+ ASSERT(!mMainState);
+ // ߳
+ mMainState = Luax::LuaxRuntime::Get().Open();
+ ASSERT(mMainState);
+ };
- inline lua_State* GetMainState() { return mMainState; };
+ inline lua_State* GetMainState()
+ {
+ return mMainState;
+ };
+
+ inline Luax::LuaxState& GetMainLuaxState()
+ {
+ return Luax::LuaxRuntime::Get()[mMainState].state;
+ };
+
+ inline void Exit()
+ {
+ Luax::LuaxRuntime::Get().Close(mMainState);
+ }
private:
diff --git a/source/libs/asura-lib-utils/threading/binding/_thread.cpp b/source/libs/asura-lib-utils/threading/binding/_thread.cpp
index 00252a9..9403486 100644
--- a/source/libs/asura-lib-utils/threading/binding/_thread.cpp
+++ b/source/libs/asura-lib-utils/threading/binding/_thread.cpp
@@ -18,7 +18,8 @@ namespace AsuraEngine
{ "AddTask", _AddTask },
{ "IsRunning", _IsRunning },
{ "IsCurrent", _IsCurrent },
- { "GetName", _GetName }
+ { "GetName", _GetName },
+ { "Sleep", _Sleep }
);
}
@@ -81,7 +82,7 @@ namespace AsuraEngine
LUAX_PREPARE(L, Thread);
state.Push(self->IsRunning());
- return 0;
+ return 1;
}
// thread:IsCurrent()
@@ -90,7 +91,7 @@ namespace AsuraEngine
LUAX_PREPARE(L, Thread);
state.Push(self->IsCurrent());
- return 0;
+ return 1;
}
// thread:GetName()
@@ -98,6 +99,20 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, Thread);
+ state.Push(self->GetName());
+ return 1;
+ }
+
+ // Thread.Sleep(milliseconds)
+ LUAX_IMPL_METHOD(Thread, _Sleep)
+ {
+ LUAX_STATE(L);
+ int ms = state.CheckValue<int>(1);
+#if ASURA_THREAD_WIN32
+ ::Sleep(ms);
+#elif ASURA_THREAD_STD
+
+#endif
return 0;
}
diff --git a/source/libs/asura-lib-utils/threading/mutex.h b/source/libs/asura-lib-utils/threading/mutex.h
index 51fe63e..7e7d877 100644
--- a/source/libs/asura-lib-utils/threading/mutex.h
+++ b/source/libs/asura-lib-utils/threading/mutex.h
@@ -32,15 +32,15 @@ namespace AsuraEngine
};
- class Lock
+ class _mutex_locker
{
public:
- Lock(Mutex& mutex)
+ _mutex_locker(Mutex& mutex)
: m(mutex)
{
m.Lock();
};
- ~Lock()
+ ~_mutex_locker()
{
m.Unlock();
}
@@ -50,11 +50,11 @@ namespace AsuraEngine
};
// ڵջӴλÿʼջΪٽ
-#define lock(mutex) Lock _asura_scoped_lock_0x0_(mutex)
-#define lock2(mutex) Lock _asura_scoped_lock_0x1_(mutex)
-#define lock3(mutex) Lock _asura_scoped_lock_0x2_(mutex)
-#define lock4(mutex) Lock _asura_scoped_lock_0x3_(mutex)
-#define lock5(mutex) Lock _asura_scoped_lock_0x4_(mutex)
+#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
{
diff --git a/source/libs/asura-lib-utils/threading/task.cpp b/source/libs/asura-lib-utils/threading/task.cpp
index e69de29..2e84ed4 100644
--- a/source/libs/asura-lib-utils/threading/task.cpp
+++ b/source/libs/asura-lib-utils/threading/task.cpp
@@ -0,0 +1,12 @@
+#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
index 9f78860..9c0b12c 100644
--- a/source/libs/asura-lib-utils/threading/task.h
+++ b/source/libs/asura-lib-utils/threading/task.h
@@ -13,12 +13,12 @@ namespace AsuraEngine
/// ϣһ̴߳񣬼̳TaskдExecute
///
ASURA_ABSTRACT class Task
- : virtual public AEScripting::NativeAccessor
+ : public virtual AEScripting::NativeAccessor
{
public:
- Task();
- virtual ~Task();
+ Task() {};
+ virtual ~Task() {};
///
/// ִɺ󷵻trueûص
@@ -28,10 +28,11 @@ namespace AsuraEngine
///
/// ûص
///
- virtual void Invoke(lua_State* thread) = 0;
+ virtual void Invoke() = 0;
- protected:
+ protected:
+ // ȡص
Luax::LuaxMemberRef mCallback;
};
diff --git a/source/libs/asura-lib-utils/threading/thread.cpp b/source/libs/asura-lib-utils/threading/thread.cpp
index 51738de..9c71ace 100644
--- a/source/libs/asura-lib-utils/threading/thread.cpp
+++ b/source/libs/asura-lib-utils/threading/thread.cpp
@@ -13,9 +13,6 @@ namespace AsuraEngine
Thread::Thread(Luax::LuaxState& father, const std::string& name)
: mName(name)
{
- mState = lua_newthread(father);
- SetLuaxMemberRef(father, mStateRef, -1);
- lua_pop(father, 1); // mState
}
Thread::~Thread()
@@ -79,13 +76,18 @@ namespace AsuraEngine
return mName;
}
- void Thread::Execute()
+ void Thread::Process()
{
+ LUAX_STATE(AEScripting::LuaEnv::Get()->GetMainState());
while (!mTaskQueue.empty())
{
Task* task = mTaskQueue.front();
- if (task->Execute())
- task->Invoke(mState);
+ if (task && task->Execute())
+ {
+ // unsafe
+ task->Invoke();
+ this->LuaxRelease<Task>(state, task);
+ }
mMutex.Lock();
mTaskQueue.pop();
diff --git a/source/libs/asura-lib-utils/threading/thread.h b/source/libs/asura-lib-utils/threading/thread.h
index 1bd5f15..3fa079a 100644
--- a/source/libs/asura-lib-utils/threading/thread.h
+++ b/source/libs/asura-lib-utils/threading/thread.h
@@ -17,6 +17,28 @@ namespace AsuraEngine
class ThreadImpl;
///
+ /// ̵߳ļֲͬʵ֣
+ /// 1: Deferredӳģʽ߳ϵɺҪ̵ֶ߳Post
+ /// ̵߳ص첽Ϊͬlua_Stateͻ⡣
+ /// 2: Immediateģʽÿһ߳άһlua_newthreadlua_State
+ /// صڲͬlua_Stateеãⲻ̷ͬ߳ͬһlua_State
+ /// 3: Daemonػģʽ̻߳һֱں̨
+ ///
+ enum ThreadType
+ {
+ THREAD_TYPE_DEFERRED,
+ THREAD_TYPE_IMMEDIATE,
+ THREAD_TYPE_DAEMON
+ };
+
+ enum ThreadState
+ {
+ THREAD_STATE_RUNNING,
+ THREAD_STATE_DEAD,
+ THREAD_STATE_SUSPEND,
+ };
+
+ ///
/// ߳壬ÿ߳άһtask queue
///
class Thread ASURA_FINAL
@@ -26,7 +48,7 @@ namespace AsuraEngine
LUAX_DECL_FACTORY(Thread);
- Thread(Luax::LuaxState& father, const std::string& name = "");
+ Thread(ThreadType type, Luax::LuaxState& luaThread, const std::string& name = "");
~Thread();
bool AddTask(Task* task);
@@ -34,8 +56,10 @@ namespace AsuraEngine
void Start(uint32 stacksize = 0);
///
- /// ǿֹ̡߳עҪnewdeleteִ֮TerminateThread򽫲ڼʹnewˡ
+ /// ǿֹ̡߳עҪnewdeleteִ֮TerminateThread򽫲ڼ
+ /// ʹnewˡ
/// https://blog.csdn.net/anye3000/article/details/7470674
+ /// ע⣺ҪʹӿڣӦ߳Լеյ㣬ֶر
///
void Kill();
@@ -51,12 +75,21 @@ namespace AsuraEngine
///
/// ִС
///
- void Execute();
+ void Process();
const std::string& GetName();
+ ///
+ /// ص
+ ///
+ void Post();
+
private:
+ //----------------------------------------------------------------------------//
+
+ LUAX_DECL_ENUM(ThreadType);
+
LUAX_DECL_METHOD(_New);
LUAX_DECL_METHOD(_Start);
LUAX_DECL_METHOD(_Join);
@@ -65,6 +98,10 @@ namespace AsuraEngine
LUAX_DECL_METHOD(_IsRunning);
LUAX_DECL_METHOD(_IsCurrent);
LUAX_DECL_METHOD(_GetName);
+ LUAX_DECL_METHOD(_Sleep);
+ LUAX_DECL_METHOD(_Post);
+
+ //----------------------------------------------------------------------------//
ThreadImpl* mImpl;
std::string mName;
@@ -75,11 +112,10 @@ namespace AsuraEngine
std::queue<Task*> mTaskQueue;
Mutex mMutex;
- ///
- /// ̵߳luaִջΪ˱ִջͻ
- ///
- lua_State* mState;
- Luax::LuaxMemberRef mStateRef;
+ lua_State* mLuaThread;
+
+ std::queue<Task*> mFinishedTasks;
+ Mutex mFinishedMutex;
};
diff --git a/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp b/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp
index e69de29..d2ad7af 100644
--- a/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp
+++ b/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp
@@ -0,0 +1,9 @@
+#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_win32.cpp b/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp
index fd1b066..ad859b6 100644
--- a/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp
+++ b/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp
@@ -1,6 +1,8 @@
#include "thread_impl_win32.h"
#include "thread.h"
+#include <iostream>
+
namespace AsuraEngine
{
namespace Threading
@@ -9,7 +11,11 @@ namespace AsuraEngine
static DWORD WINAPI _thread_win32_runner(LPVOID param)
{
Thread* thread = (Thread*)param;
- thread->Execute();
+ while (thread->IsRunning())
+ {
+ thread->Process();
+ ::Sleep(100);
+ }
return 0;
}
diff --git a/source/libs/asura-lib-utils/threading/thread_task.cpp b/source/libs/asura-lib-utils/threading/thread_task.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/thread_task.cpp
diff --git a/source/libs/asura-lib-utils/threading/thread_task.h b/source/libs/asura-lib-utils/threading/thread_task.h
new file mode 100644
index 0000000..1ea0a1a
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/thread_task.h
@@ -0,0 +1,44 @@
+#ifndef __ASURA_THRAD_TASK_H__
+#define __ASURA_THRAD_TASK_H__
+
+#include <asura-lib-utils/type.h>
+#include <asura-lib-utils/scripting/portable.hpp>
+
+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
index aa00108..1ed2d42 100644
--- a/source/libs/asura-lib-utils/type.h
+++ b/source/libs/asura-lib-utils/type.h
@@ -7,7 +7,7 @@
namespace AsuraEngine
{
- //----------------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------//
typedef int8_t int8;
typedef uint8_t uint8;
@@ -27,7 +27,7 @@ namespace AsuraEngine
typedef const char cc8;
- //----------------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------//
#ifndef ASSERT
#ifdef NDEBUG
@@ -42,7 +42,7 @@ namespace AsuraEngine
#endif
#endif
- //----------------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------//
#ifdef _WIN32
#define ASURA_FINAL final
@@ -76,7 +76,7 @@ namespace AsuraEngine
///
#define ASURA_MOVE
- //----------------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------//
#define ASURA_SDL_HOST 1
diff --git a/source/libs/asura-lib-utils/utils_module.cpp b/source/libs/asura-lib-utils/utils_module.cpp
index a0539ed..61780e6 100644
--- a/source/libs/asura-lib-utils/utils_module.cpp
+++ b/source/libs/asura-lib-utils/utils_module.cpp
@@ -13,6 +13,7 @@ namespace AsuraEngine
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);
}
diff --git a/source/libs/asura-lib-utils/utils_module.h b/source/libs/asura-lib-utils/utils_module.h
index ae875b9..e802730 100644
--- a/source/libs/asura-lib-utils/utils_module.h
+++ b/source/libs/asura-lib-utils/utils_module.h
@@ -5,6 +5,7 @@
#include "io/data_buffer.h"
#include "io/file_data.h"
#include "io/file.h"
+#include "io/io_task.h"
#include "threading/thread.h"