summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-26 09:48:47 +0800
committerchai <chaifix@163.com>2021-10-26 09:48:47 +0800
commitef7aedf5f272c52247d8ee9522d7b2896d21af63 (patch)
treec1259190bd51ed1225017507cd01612cc5a73a8c
parente7c760c884d90ef22fe46508b18081fe6e0f9291 (diff)
*misc
-rw-r--r--Editor/EditorApplication.cpp2
-rw-r--r--Editor/EditorMain.cpp3
-rw-r--r--Resources/DefaultContent/Libraries/GameLab/init.lua2
-rw-r--r--Resources/Scripts/EditorApplication.lua2
-rw-r--r--Runtime/Debug/Log.cpp6
-rw-r--r--Runtime/FileSystem/File.h7
-rw-r--r--Runtime/FileSystem/FileJobs.cpp1
-rw-r--r--Runtime/Threading/JobSystem.cpp15
-rw-r--r--Runtime/Threading/JobSystem.h3
-rw-r--r--Runtime/Threading/Mutex.cpp4
-rw-r--r--Runtime/Threading/Mutex.h10
-rw-r--r--Runtime/Threading/WorkThread.cpp8
12 files changed, 41 insertions, 22 deletions
diff --git a/Editor/EditorApplication.cpp b/Editor/EditorApplication.cpp
index f480e37..5315e77 100644
--- a/Editor/EditorApplication.cpp
+++ b/Editor/EditorApplication.cpp
@@ -11,7 +11,7 @@ EditorApplication::EditorApplication(LuaBind::VM* vm)
Assert(!s_Created);
// 初始化jobsystem
- JobSystem::Instance()->Initilize();
+ JobSystem::Instance()->Initilize(4);
}
EditorApplication::~EditorApplication()
diff --git a/Editor/EditorMain.cpp b/Editor/EditorMain.cpp
index 5f16d63..69c1c1a 100644
--- a/Editor/EditorMain.cpp
+++ b/Editor/EditorMain.cpp
@@ -44,9 +44,6 @@ int main()
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
#endif
{
- WorkThread thread;
- thread.Resume();
-
WindowUtil::RegisterClasses();
LuaBind::VM vm;
diff --git a/Resources/DefaultContent/Libraries/GameLab/init.lua b/Resources/DefaultContent/Libraries/GameLab/init.lua
index 51e1901..c87ace3 100644
--- a/Resources/DefaultContent/Libraries/GameLab/init.lua
+++ b/Resources/DefaultContent/Libraries/GameLab/init.lua
@@ -36,4 +36,6 @@ end
-- classes
GameLab.Class = require("GameLab.Class")
+GameLab.InternalClass = require("GameLab.InternalClass")
+
return GameLab \ No newline at end of file
diff --git a/Resources/Scripts/EditorApplication.lua b/Resources/Scripts/EditorApplication.lua
index 6ac68aa..10ccbc8 100644
--- a/Resources/Scripts/EditorApplication.lua
+++ b/Resources/Scripts/EditorApplication.lua
@@ -16,7 +16,7 @@ end
local mainWindow = GUI.ContainerWindow.New({400, 400, 800, 500}, GUI.EShowMode.MainWindow, {100, 100}, {700, 700})
mainWindow:SetTitle("GameLab")
-mainWindow:SetIcon("./Icon/GameLab.ico")
+mainWindow:SetIcon("./Data/Icon/GameLab.ico")
app:SetMainWindow(mainWindow)
diff --git a/Runtime/Debug/Log.cpp b/Runtime/Debug/Log.cpp
index a84337b..4d28502 100644
--- a/Runtime/Debug/Log.cpp
+++ b/Runtime/Debug/Log.cpp
@@ -42,7 +42,7 @@ void log_open_tag(std::string tag)
void log_info(std::string log)
{
- _lock(s_Mutex) {
+ Lock(s_Mutex) {
#ifdef GAMELAB_WIN
if (s_ConsoleHandle == 0) {
s_ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
@@ -57,7 +57,7 @@ void log_info(std::string log)
void log_warning(std::string log)
{
- _lock(s_Mutex) {
+ Lock(s_Mutex) {
#ifdef GAMELAB_WIN
if (s_ConsoleHandle == 0) {
s_ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
@@ -72,7 +72,7 @@ void log_warning(std::string log)
void log_error(std::string log)
{
- _lock(s_Mutex) {
+ Lock(s_Mutex) {
#ifdef GAMELAB_WIN
if (s_ConsoleHandle == 0) {
s_ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
diff --git a/Runtime/FileSystem/File.h b/Runtime/FileSystem/File.h
index 19e780d..b0d720c 100644
--- a/Runtime/FileSystem/File.h
+++ b/Runtime/FileSystem/File.h
@@ -1,9 +1,12 @@
#pragma once
#include "Runtime/Lua/LuaHelper.h"
-class File
+class File : public LuaBind::NativeClass<File>
{
public:
+ File(LuaBind::VM* vm);
+ char* data;
+ int length;
-};
+}; \ No newline at end of file
diff --git a/Runtime/FileSystem/FileJobs.cpp b/Runtime/FileSystem/FileJobs.cpp
index 29e99a4..554dc5b 100644
--- a/Runtime/FileSystem/FileJobs.cpp
+++ b/Runtime/FileSystem/FileJobs.cpp
@@ -12,6 +12,7 @@ void ReadFilesJob::Dispacth(void* param)
state.Call(0, 0);
}
+// 每次读一个文件
void ReadFilesJob::Process()
{
if (IsFinished())
diff --git a/Runtime/Threading/JobSystem.cpp b/Runtime/Threading/JobSystem.cpp
index a026300..1c62123 100644
--- a/Runtime/Threading/JobSystem.cpp
+++ b/Runtime/Threading/JobSystem.cpp
@@ -1,6 +1,8 @@
#include "JobSystem.h"
+#include "Runtime/Debug/Log.h"
JobSystem::JobSystem()
+ : m_Initialized(false)
{
}
@@ -12,15 +14,26 @@ JobSystem::~JobSystem()
void JobSystem::Initilize(int workThreadCount)
{
+ if (m_Initialized)
+ {
+ log_error("JobSystem has already initialized.");
+ return;
+ }
+
if (workThreadCount <= 0)
return;
+ m_ThreadCount = workThreadCount;
+ m_Cur = 0;
+
for (int i = 0; i < workThreadCount; ++i)
{
WorkThread* thread = new WorkThread();
thread->Resume();
m_Threads.push_back(thread);
}
+
+ m_Initialized = true;
}
void JobSystem::Dispatch(void* param)
@@ -39,5 +52,5 @@ void JobSystem::AddJobAtEnd(Job* job)
WorkThread* JobSystem::SelectThread()
{
- return m_Threads[0];
+ return m_Threads[(++m_Cur)% m_ThreadCount];
} \ No newline at end of file
diff --git a/Runtime/Threading/JobSystem.h b/Runtime/Threading/JobSystem.h
index c95037c..7f8148a 100644
--- a/Runtime/Threading/JobSystem.h
+++ b/Runtime/Threading/JobSystem.h
@@ -17,6 +17,9 @@ public:
private:
WorkThread* SelectThread();
+ bool m_Initialized;
std::vector<WorkThread*> m_Threads;
+ int m_Cur;
+ int m_ThreadCount;
}; \ No newline at end of file
diff --git a/Runtime/Threading/Mutex.cpp b/Runtime/Threading/Mutex.cpp
index eabe48d..6be162f 100644
--- a/Runtime/Threading/Mutex.cpp
+++ b/Runtime/Threading/Mutex.cpp
@@ -14,12 +14,12 @@ Mutex::~Mutex()
m_Handle = NULL;
}
-void Mutex::Lock()
+void Mutex::LockSelf()
{
::WaitForSingleObject(m_Handle, (~(uint32)0));
}
-void Mutex::Unlock()
+void Mutex::UnlockSelf()
{
::ReleaseMutex(m_Handle);
} \ No newline at end of file
diff --git a/Runtime/Threading/Mutex.h b/Runtime/Threading/Mutex.h
index 44f8cb9..eed69aa 100644
--- a/Runtime/Threading/Mutex.h
+++ b/Runtime/Threading/Mutex.h
@@ -7,8 +7,8 @@ public:
Mutex();
~Mutex();
- void Lock();
- void Unlock();
+ void LockSelf();
+ void UnlockSelf();
private:
HANDLE m_Handle;
@@ -22,11 +22,11 @@ public:
MutexLocker(Mutex& mutex)
: m(mutex)
{
- m.Lock();
+ m.LockSelf();
};
~MutexLocker()
{
- m.Unlock();
+ m.UnlockSelf();
}
operator bool() { return false; };
private:
@@ -34,6 +34,6 @@ private:
Mutex& m;
};
-#define _lock(m) \
+#define Lock(m) \
if(MutexLocker lock_##m = m){} else
diff --git a/Runtime/Threading/WorkThread.cpp b/Runtime/Threading/WorkThread.cpp
index f9bb864..31c3ead 100644
--- a/Runtime/Threading/WorkThread.cpp
+++ b/Runtime/Threading/WorkThread.cpp
@@ -5,7 +5,7 @@ void WorkThread::Run()
{
while (true)
{
- _lock(m_PendingMutex)
+ Lock(m_PendingMutex)
{
for (auto iter = m_PendingJobs.begin(); iter != m_PendingJobs.end();)
{
@@ -13,7 +13,7 @@ void WorkThread::Run()
job->Process();
if (job->IsFinished())
{
- _lock(m_FinishedMutex) {
+ Lock(m_FinishedMutex) {
m_FinishedJobs.push_back(job);
}
iter = m_PendingJobs.erase(iter);
@@ -29,7 +29,7 @@ void WorkThread::Run()
void WorkThread::Dispatch(void* param)
{
- _lock(m_FinishedMutex)
+ Lock(m_FinishedMutex)
{
for (int i = 0; i < m_FinishedJobs.size(); ++i)
{
@@ -41,7 +41,7 @@ void WorkThread::Dispatch(void* param)
void WorkThread::AddJobAtEnd(Job* job)
{
- _lock(m_PendingMutex)
+ Lock(m_PendingMutex)
{
m_PendingJobs.push_back(job);
}