Skip to content

Commit

Permalink
Added hack to make lua GC more aggressive when using OOP Matrix & Vector
Browse files Browse the repository at this point in the history
  • Loading branch information
ccw808 committed Jan 5, 2017
1 parent 3824f77 commit 6f3fe6d
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Client/mods/deathmatch/logic/lua/LuaCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,28 @@ void lua_pushvector ( lua_State* luaVM, const CVector4D& vector )
{
CLuaVector4D* pVector = new CLuaVector4D ( vector );
lua_pushobject ( luaVM, "Vector4", ( void* ) reinterpret_cast < unsigned int * > ( pVector->GetScriptID () ) );
lua_addtotalbytes(luaVM, LUA_GC_EXTRA_BYTES);
}

void lua_pushvector ( lua_State* luaVM, const CVector& vector )
{
CLuaVector3D* pVector = new CLuaVector3D ( vector );
lua_pushobject ( luaVM, "Vector3", ( void* ) reinterpret_cast < unsigned int * > ( pVector->GetScriptID () ) );
lua_addtotalbytes(luaVM, LUA_GC_EXTRA_BYTES);
}

void lua_pushvector ( lua_State* luaVM, const CVector2D& vector )
{
CLuaVector2D* pVector = new CLuaVector2D ( vector );
lua_pushobject ( luaVM, "Vector2", ( void* ) reinterpret_cast < unsigned int * > ( pVector->GetScriptID () ) );
lua_addtotalbytes(luaVM, LUA_GC_EXTRA_BYTES);
}

void lua_pushmatrix ( lua_State* luaVM, const CMatrix& matrix )
{
CLuaMatrix* pMatrix = new CLuaMatrix ( matrix );
lua_pushobject ( luaVM, "Matrix", ( void* ) reinterpret_cast < unsigned int * > ( pMatrix->GetScriptID () ) );
lua_addtotalbytes(luaVM, LUA_GC_EXTRA_BYTES);
}

// Just do a type check vs LUA_TNONE before calling this, or bant
Expand Down
4 changes: 4 additions & 0 deletions Server/mods/deathmatch/logic/lua/LuaCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,24 +254,28 @@ void lua_pushvector ( lua_State* luaVM, const CVector4D& vector )
{
CLuaVector4D* pVector = new CLuaVector4D ( vector );
lua_pushobject ( luaVM, "Vector4", ( void* ) reinterpret_cast < unsigned int * > ( pVector->GetScriptID () ) );
lua_addtotalbytes(luaVM, LUA_GC_EXTRA_BYTES);
}

void lua_pushvector ( lua_State* luaVM, const CVector& vector )
{
CLuaVector3D* pVector = new CLuaVector3D ( vector );
lua_pushobject ( luaVM, "Vector3", ( void* ) reinterpret_cast < unsigned int * > ( pVector->GetScriptID () ) );
lua_addtotalbytes(luaVM, LUA_GC_EXTRA_BYTES);
}

void lua_pushvector ( lua_State* luaVM, const CVector2D& vector )
{
CLuaVector2D* pVector = new CLuaVector2D ( vector );
lua_pushobject ( luaVM, "Vector2", ( void* ) reinterpret_cast < unsigned int * > ( pVector->GetScriptID () ) );
lua_addtotalbytes(luaVM, LUA_GC_EXTRA_BYTES);
}

void lua_pushmatrix ( lua_State* luaVM, const CMatrix& matrix )
{
CLuaMatrix* pMatrix = new CLuaMatrix ( matrix );
lua_pushobject ( luaVM, "Matrix", ( void* ) reinterpret_cast < unsigned int * > ( pMatrix->GetScriptID () ) );
lua_addtotalbytes(luaVM, LUA_GC_EXTRA_BYTES);
}

// Just do a type check vs LUA_TNONE before calling this, or bant
Expand Down
2 changes: 2 additions & 0 deletions Shared/mods/deathmatch/logic/lua/CLuaShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*****************************************************************************/
#pragma once

#define LUA_GC_EXTRA_BYTES 30 // Used in hack to make lua GC more aggressive when using OOP Matrix & Vector

// Lua function definitions (shared)
#include "luadefs/CLuaBitDefs.h"
#include "luadefs/CLuaCryptDefs.h"
Expand Down
1 change: 1 addition & 0 deletions Shared/mods/deathmatch/logic/luadefs/CLuaMatrixDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ int CLuaMatrixDefs::Destroy ( lua_State* luaVM )
if ( !argStream.HasErrors () )
{
delete pMatrix;
lua_addtotalbytes(luaVM, -LUA_GC_EXTRA_BYTES);
lua_pushboolean ( luaVM, true );
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion Shared/mods/deathmatch/logic/luadefs/CLuaVector2Defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int CLuaVector2Defs::Destroy ( lua_State* luaVM )
if ( !argStream.HasErrors () )
{
delete pVector;

lua_addtotalbytes(luaVM, -LUA_GC_EXTRA_BYTES);
lua_pushboolean ( luaVM, true );
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion Shared/mods/deathmatch/logic/luadefs/CLuaVector3Defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ int CLuaVector3Defs::Destroy ( lua_State* luaVM )
if ( !argStream.HasErrors () )
{
delete pVector;

lua_addtotalbytes(luaVM, -LUA_GC_EXTRA_BYTES);
lua_pushboolean ( luaVM, true );
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion Shared/mods/deathmatch/logic/luadefs/CLuaVector4Defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ int CLuaVector4Defs::Destroy ( lua_State* luaVM )
if ( !argStream.HasErrors () )
{
delete pVector;

lua_addtotalbytes(luaVM, -LUA_GC_EXTRA_BYTES);
lua_pushboolean ( luaVM, true );
return 1;
}
Expand Down
10 changes: 8 additions & 2 deletions vendor/lua/src/lapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ LUA_API int lua_pushthread (lua_State *L) {
}



/*
** get functions (Lua -> stack)
*/
Expand Down Expand Up @@ -898,7 +897,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
}


#ifdef WITH_STRING_DUMP
#ifdef WITH_STRING_DUMP
LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) {
int status;
TValue *o;
Expand Down Expand Up @@ -1128,3 +1127,10 @@ LUA_API int luaX_is_apicheck_enabled()
return 0;
}
#endif

// MTA addition to tweak GC behaviour
LUA_API void lua_addtotalbytes(lua_State *L, int n)
{
global_State *g = G(L);
g->totalbytes += n;
}
2 changes: 1 addition & 1 deletion vendor/lua/src/lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ LUA_API void (lua_pushboolean) (lua_State *L, int b);
LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
LUA_API int (lua_pushthread) (lua_State *L);


/*
** get functions (Lua -> stack)
*/
Expand Down Expand Up @@ -357,6 +356,7 @@ LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
LUA_API lua_Hook lua_gethook (lua_State *L);
LUA_API int lua_gethookmask (lua_State *L);
LUA_API int lua_gethookcount (lua_State *L);
LUA_API void lua_addtotalbytes(lua_State *L, int n);


struct lua_Debug {
Expand Down

0 comments on commit 6f3fe6d

Please sign in to comment.