Optimize lua object push
* Optimize position hash * Fix minimap reload
This commit is contained in:
parent
b35063b022
commit
eec6114b2d
|
@ -74,6 +74,7 @@ function Minimap.terminate()
|
||||||
disconnect(g_game, { onGameStart = Minimap.reset })
|
disconnect(g_game, { onGameStart = Minimap.reset })
|
||||||
Keyboard.unbindKeyDown('Ctrl+M')
|
Keyboard.unbindKeyDown('Ctrl+M')
|
||||||
|
|
||||||
|
minimapButton:destroy()
|
||||||
minimapWindow:destroy()
|
minimapWindow:destroy()
|
||||||
minimapWindow = nil
|
minimapWindow = nil
|
||||||
minimapWidget = nil
|
minimapWidget = nil
|
||||||
|
|
|
@ -1052,8 +1052,7 @@ void LuaInterface::pushObject(const LuaObjectPtr& obj)
|
||||||
new(newUserdata(sizeof(LuaObjectPtr))) LuaObjectPtr(obj);
|
new(newUserdata(sizeof(LuaObjectPtr))) LuaObjectPtr(obj);
|
||||||
m_totalObjRefs++;
|
m_totalObjRefs++;
|
||||||
|
|
||||||
// set the userdata metatable
|
obj->luaGetMetatable();
|
||||||
getGlobal(stdext::format("%s_mt", obj->getClassName()));
|
|
||||||
assert(!isNil());
|
assert(!isNil());
|
||||||
setMetatable();
|
setMetatable();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
#include <framework/application.h>
|
#include <framework/application.h>
|
||||||
|
|
||||||
LuaObject::LuaObject() :
|
LuaObject::LuaObject() :
|
||||||
m_fieldsTableRef(-1)
|
m_fieldsTableRef(-1),
|
||||||
|
m_metatableRef(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +35,11 @@ LuaObject::~LuaObject()
|
||||||
{
|
{
|
||||||
assert(!g_app.isTermianted());
|
assert(!g_app.isTermianted());
|
||||||
releaseLuaFieldsTable();
|
releaseLuaFieldsTable();
|
||||||
|
|
||||||
|
if(m_metatableRef != -1) {
|
||||||
|
g_lua.unref(m_metatableRef);
|
||||||
|
m_metatableRef = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaObject::hasLuaField(const std::string& field)
|
bool LuaObject::hasLuaField(const std::string& field)
|
||||||
|
@ -81,6 +87,17 @@ void LuaObject::luaGetField(const std::string& key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LuaObject::luaGetMetatable()
|
||||||
|
{
|
||||||
|
if(m_metatableRef == -1) {
|
||||||
|
// set the userdata metatable
|
||||||
|
g_lua.getGlobal(stdext::format("%s_mt", getClassName()));
|
||||||
|
m_metatableRef = g_lua.ref();
|
||||||
|
}
|
||||||
|
|
||||||
|
g_lua.getRef(m_metatableRef);
|
||||||
|
}
|
||||||
|
|
||||||
void LuaObject::luaGetFieldsTable()
|
void LuaObject::luaGetFieldsTable()
|
||||||
{
|
{
|
||||||
if(m_fieldsTableRef != -1)
|
if(m_fieldsTableRef != -1)
|
||||||
|
|
|
@ -61,6 +61,9 @@ public:
|
||||||
/// Gets a field from this lua object, the result is pushed onto the stack
|
/// Gets a field from this lua object, the result is pushed onto the stack
|
||||||
void luaGetField(const std::string& key);
|
void luaGetField(const std::string& key);
|
||||||
|
|
||||||
|
/// Get object's metatable
|
||||||
|
void luaGetMetatable();
|
||||||
|
|
||||||
/// Gets the table containing all stored fields of this lua object, the result is pushed onto the stack
|
/// Gets the table containing all stored fields of this lua object, the result is pushed onto the stack
|
||||||
void luaGetFieldsTable();
|
void luaGetFieldsTable();
|
||||||
|
|
||||||
|
@ -78,6 +81,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_fieldsTableRef;
|
int m_fieldsTableRef;
|
||||||
|
int m_metatableRef;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "luainterface.h"
|
#include "luainterface.h"
|
||||||
|
|
|
@ -214,7 +214,7 @@ public:
|
||||||
|
|
||||||
struct PositionHasher : std::unary_function<Position, std::size_t> {
|
struct PositionHasher : std::unary_function<Position, std::size_t> {
|
||||||
std::size_t operator()(const Position& pos) const {
|
std::size_t operator()(const Position& pos) const {
|
||||||
return ((((pos.x * 32768) + pos.y) * 16) + pos.z) % 1000000;
|
return ((((pos.x * 2048) + pos.y) * 16) + pos.z) % (2048*2048);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue