Skip to content

Commit 9672c4c

Browse files
committed
优化U3D在WIndows平台下操作。
Former-commit-id: 3babaf8779e784e0ebd60a1fb4729d1bb4975a65
1 parent 3601d48 commit 9672c4c

6 files changed

Lines changed: 63 additions & 6 deletions

File tree

9 KB
Binary file not shown.

Source/Unity3D/Windows/LuaScriptCore/LuaScriptCore.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<ClCompile Include="..\..\..\lua-common\LuaObjectManager.cpp" />
101101
<ClCompile Include="..\..\..\lua-common\LuaPointer.cpp" />
102102
<ClCompile Include="..\..\..\lua-common\LuaSession.cpp" />
103+
<ClCompile Include="..\..\..\lua-common\LuaTmpValue.cpp" />
103104
<ClCompile Include="..\..\..\lua-common\LuaTuple.cpp" />
104105
<ClCompile Include="..\..\..\lua-common\LuaValue.cpp" />
105106
<ClCompile Include="..\..\..\lua-common\StringUtils.cpp" />
@@ -165,6 +166,7 @@
165166
<ClInclude Include="..\..\..\lua-common\LuaObjectSerializationTypes.h" />
166167
<ClInclude Include="..\..\..\lua-common\LuaPointer.h" />
167168
<ClInclude Include="..\..\..\lua-common\LuaSession.h" />
169+
<ClInclude Include="..\..\..\lua-common\LuaTmpValue.hpp" />
168170
<ClInclude Include="..\..\..\lua-common\LuaTuple.h" />
169171
<ClInclude Include="..\..\..\lua-common\LuaValue.h" />
170172
<ClInclude Include="..\..\..\lua-common\StringUtils.h" />

Source/Unity3D/Windows/LuaScriptCore/LuaScriptCore.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@
216216
<ClCompile Include="..\..\..\lua-common\LuaEngineAdapter.cpp">
217217
<Filter>Source Files\lua-common</Filter>
218218
</ClCompile>
219+
<ClCompile Include="..\..\..\lua-common\LuaTmpValue.cpp">
220+
<Filter>Source Files\lua-common</Filter>
221+
</ClCompile>
219222
</ItemGroup>
220223
<ItemGroup>
221224
<ClInclude Include="..\..\..\lua-core\src\lapi.h">
@@ -386,5 +389,8 @@
386389
<ClInclude Include="..\..\..\lua-common\LuaEngineAdapter.hpp">
387390
<Filter>Header Files\lua-common</Filter>
388391
</ClInclude>
392+
<ClInclude Include="..\..\..\lua-common\LuaTmpValue.hpp">
393+
<Filter>Header Files\lua-common</Filter>
394+
</ClInclude>
389395
</ItemGroup>
390396
</Project>

Source/lua-common/LuaContext.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,19 @@
1717
#include <sstream>
1818
#include <thread>
1919
#include <signal.h>
20+
21+
#if _WINDOWS
22+
23+
#include <windows.h>
24+
#pragma comment(lib,"Winmm.lib")
25+
26+
#else
27+
2028
#include <sys/time.h>
2129
#include <unistd.h>
2230

31+
#endif
32+
2333
using namespace cn::vimfung::luascriptcore;
2434

2535
/**
@@ -32,6 +42,7 @@ static const char * CatchLuaExceptionHandlerName = "__catchExcepitonHandler";
3242
*/
3343
static std::vector<LuaContext *> _needsGCContextList;
3444

45+
3546
/**
3647
* 方法路由处理器
3748
*
@@ -93,13 +104,35 @@ static LuaValue* catchLuaExceptionHandler (LuaContext *context, std::string meth
93104
return NULL;
94105
}
95106

107+
#if _WINDOWS
108+
109+
void WINAPI contextGCHandler(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dwl, DWORD dw2)
110+
{
111+
unityDebug("gc handler...");
112+
113+
//重置计时器
114+
timeKillEvent(wTimerID);
115+
116+
//进行内存回收
117+
for (std::vector<LuaContext *>::iterator it = _needsGCContextList.begin(); it != _needsGCContextList.end(); it++)
118+
{
119+
LuaContext *context = *it;
120+
context->gcHandler();
121+
context->release(); // 回收后释放
122+
}
123+
//清空
124+
_needsGCContextList.clear();
125+
}
126+
127+
#else
96128
/**
97129
上下文内存回收处理
98130
99131
@param signo 信号
100132
*/
101133
static void contextGCHandler(int signo)
102134
{
135+
103136
//重置计时器
104137
struct itimerval itv;
105138
itv.it_value.tv_sec = 0;
@@ -118,6 +151,8 @@ static void contextGCHandler(int signo)
118151
_needsGCContextList.clear();
119152
}
120153

154+
#endif
155+
121156
/**
122157
上下文开始回收
123158
@@ -141,6 +176,16 @@ static void contextStartGC(LuaContext *context)
141176
context -> retain();
142177
_needsGCContextList.push_back(context);
143178

179+
#if _WINDOWS
180+
181+
MMRESULT gcTimerId = timeSetEvent(100, 1, (LPTIMECALLBACK)contextGCHandler, NULL, TIME_ONESHOT);
182+
if (NULL == gcTimerId)
183+
{
184+
unityDebug("gc timer create error!");
185+
}
186+
187+
#else
188+
144189
//监听定时器信号
145190
signal(SIGALRM, contextGCHandler);
146191

@@ -150,6 +195,9 @@ static void contextStartGC(LuaContext *context)
150195
itv.it_value.tv_usec = 100000;
151196
itv.it_interval = itv.it_value;
152197
setitimer(ITIMER_REAL, &itv, NULL);
198+
199+
#endif
200+
153201
}
154202
}
155203

Source/lua-common/LuaObjectDescriptor.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ namespace cn {
3535
{
3636
private:
3737

38-
/**
39-
类型描述器
40-
*/
41-
LuaExportTypeDescriptor *_typeDescriptor;
42-
4338
/**
4439
* 对象
4540
*/
4641
void *_object;
42+
43+
/**
44+
类型描述器
45+
*/
46+
LuaExportTypeDescriptor *_typeDescriptor;
4747

4848
/**
4949
* 用户自定义数据

Source/lua-common/StringUtils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ std::string StringUtils::format (const char *format, ...)
4343
va_start(marker, format);
4444

4545
char buffer[1024] = {0};
46-
int size = vsprintf(buffer, format, marker);
46+
int size = vsnprintf_s(buffer, 1024, format, marker);
47+
//vsprintf(buffer, format, marker);
4748

4849
va_end(marker);
4950

0 commit comments

Comments
 (0)