Eluna fix TC errors from previous commits, fix merge and fix a crash on osx

This commit is contained in:
Rochet2
2014-12-15 23:24:51 +02:00
parent 525e108b83
commit 7671054425
7 changed files with 133 additions and 71 deletions

View File

@@ -51,7 +51,7 @@ ElunaEventProcessor::ElunaEventProcessor(Eluna** _E, WorldObject* _obj) : m_time
ElunaEventProcessor::~ElunaEventProcessor() ElunaEventProcessor::~ElunaEventProcessor()
{ {
RemoveEvents(); RemoveEvents_internal();
if (obj) if (obj)
{ {
@@ -87,6 +87,12 @@ void ElunaEventProcessor::Update(uint32 diff)
} }
void ElunaEventProcessor::RemoveEvents() void ElunaEventProcessor::RemoveEvents()
{
for (EventList::iterator it = eventList.begin(); it != eventList.end(); ++it)
it->second->to_Abort = true;
}
void ElunaEventProcessor::RemoveEvents_internal()
{ {
//if (!final) //if (!final)
//{ //{
@@ -125,7 +131,13 @@ EventMgr::EventMgr(Eluna** _E) : globalProcessor(new ElunaEventProcessor(_E, NUL
EventMgr::~EventMgr() EventMgr::~EventMgr()
{ {
RemoveEvents(); {
ReadGuard lock(GetLock());
if (!processors.empty())
for (ProcessorSet::const_iterator it = processors.begin(); it != processors.end(); ++it) // loop processors
(*it)->RemoveEvents_internal();
globalProcessor->RemoveEvents_internal();
}
delete globalProcessor; delete globalProcessor;
globalProcessor = NULL; globalProcessor = NULL;
} }

View File

@@ -45,6 +45,7 @@ private:
class ElunaEventProcessor class ElunaEventProcessor
{ {
friend class LuaEvent; friend class LuaEvent;
friend class EventMgr;
public: public:
typedef std::multimap<uint64, LuaEvent*> EventList; typedef std::multimap<uint64, LuaEvent*> EventList;
@@ -54,7 +55,7 @@ public:
~ElunaEventProcessor(); ~ElunaEventProcessor();
void Update(uint32 diff); void Update(uint32 diff);
// instantly removes all timed events // removes all timed events on next tick or at tick end
void RemoveEvents(); void RemoveEvents();
// set the event to be removed when executing // set the event to be removed when executing
void RemoveEvent(int eventId); void RemoveEvent(int eventId);
@@ -62,7 +63,9 @@ public:
EventMap eventMap; EventMap eventMap;
private: private:
void RemoveEvents_internal();
void AddEvent(LuaEvent* Event); void AddEvent(LuaEvent* Event);
bool removeAllEvents;
EventList eventList; EventList eventList;
uint64 m_time; uint64 m_time;
WorldObject* obj; WorldObject* obj;

View File

@@ -1435,7 +1435,7 @@ namespace LuaGlobalFunctions
creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase); creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase);
uint32 db_lowguid = creature->GetDBTableGUIDLow(); uint32 db_lowguid = creature->GetDBTableGUIDLow();
if (!creaturLoadCreatureFromDB(db_lowguid, map)) if (!creature->LoadCreatureFromDB(db_lowguid, map))
{ {
delete creature; delete creature;
Eluna::Push(L); Eluna::Push(L);
@@ -2260,9 +2260,9 @@ namespace LuaGlobalFunctions
* *
* @return uint32 currTime * @return uint32 currTime
*/ */
int GetCurrTime(Eluna* E) int GetCurrTime(Eluna* /*E*/, lua_State* L)
{ {
Eluna::Push(E->L, ElunaUtil::GetCurrTime()); Eluna::Push(L, ElunaUtil::GetCurrTime());
return 1; return 1;
} }
@@ -2272,19 +2272,19 @@ namespace LuaGlobalFunctions
* @param uint32 oldTime * @param uint32 oldTime
* @return uint32 timeDiff * @return uint32 timeDiff
*/ */
int GetTimeDiff(Eluna* E) int GetTimeDiff(Eluna* /*E*/, lua_State* L)
{ {
uint32 oldtimems = Eluna::CHECKVAL<uint32>(E->L, 1); uint32 oldtimems = Eluna::CHECKVAL<uint32>(L, 1);
Eluna::Push(E->L, ElunaUtil::GetTimeDiff(oldtimems)); Eluna::Push(L, ElunaUtil::GetTimeDiff(oldtimems));
return 1; return 1;
} }
std::string GetStackAsString(Eluna* E) std::string GetStackAsString(lua_State* L)
{ {
std::ostringstream oss; std::ostringstream oss;
for (int i = 1; i <= lua_gettop(E->L); ++i) for (int i = 1; i <= lua_gettop(L); ++i)
oss << luaL_tolstring(E->L, i, NULL); oss << luaL_tolstring(L, i, NULL);
return oss.str(); return oss.str();
} }
@@ -2293,9 +2293,9 @@ namespace LuaGlobalFunctions
* *
* @param ... variableArguments * @param ... variableArguments
*/ */
int PrintInfo(Eluna* E) int PrintInfo(Eluna* /*E*/, lua_State* L)
{ {
ELUNA_LOG_INFO("%s", GetStackAsString(E).c_str()); ELUNA_LOG_INFO("%s", GetStackAsString(L).c_str());
return 0; return 0;
} }
@@ -2304,9 +2304,9 @@ namespace LuaGlobalFunctions
* *
* @param ... variableArguments * @param ... variableArguments
*/ */
int PrintError(Eluna* E) int PrintError(Eluna* /*E*/, lua_State* L)
{ {
ELUNA_LOG_ERROR("%s", GetStackAsString(E).c_str()); ELUNA_LOG_ERROR("%s", GetStackAsString(L).c_str());
return 0; return 0;
} }
@@ -2315,9 +2315,9 @@ namespace LuaGlobalFunctions
* *
* @param ... variableArguments * @param ... variableArguments
*/ */
int PrintDebug(Eluna* E) int PrintDebug(Eluna* /*E*/, lua_State* L)
{ {
ELUNA_LOG_DEBUG("%s", GetStackAsString(E).c_str()); ELUNA_LOG_DEBUG("%s", GetStackAsString(L).c_str());
return 0; return 0;
} }
} }

View File

@@ -1442,15 +1442,6 @@ uint32 Eluna::GetDialogStatus(Player* pPlayer, Creature* pCreature)
return DIALOG_STATUS_SCRIPTED_NO_STATUS; return DIALOG_STATUS_SCRIPTED_NO_STATUS;
} }
void Eluna::OnSummoned(Creature* pCreature, Unit* pSummoner)
{
ENTRY_BEGIN(CreatureEventBindings, pCreature->GetEntry(), CREATURE_EVENT_ON_SUMMONED, return);
Push(L, pCreature);
Push(L, pSummoner);
ENTRY_EXECUTE(0);
ENDCALL();
}
void Eluna::OnAddToWorld(Creature* creature) void Eluna::OnAddToWorld(Creature* creature)
{ {
ENTRY_BEGIN(CreatureEventBindings, creature->GetEntry(), CREATURE_EVENT_ON_ADD, return); ENTRY_BEGIN(CreatureEventBindings, creature->GetEntry(), CREATURE_EVENT_ON_ADD, return);
@@ -1467,6 +1458,22 @@ void Eluna::OnRemoveFromWorld(Creature* creature)
ENDCALL(); ENDCALL();
} }
bool Eluna::OnSummoned(Creature* pCreature, Unit* pSummoner)
{
bool result = false;
ENTRY_BEGIN(CreatureEventBindings, pCreature->GetEntry(), CREATURE_EVENT_ON_SUMMONED, return false);
Push(L, pCreature);
Push(L, pSummoner);
ENTRY_EXECUTE(1);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
}
bool Eluna::UpdateAI(Creature* me, const uint32 diff) bool Eluna::UpdateAI(Creature* me, const uint32 diff)
{ {
bool result = false; bool result = false;
@@ -1474,7 +1481,9 @@ bool Eluna::UpdateAI(Creature* me, const uint32 diff)
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, diff); Eluna::Push(L, diff);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1490,7 +1499,9 @@ bool Eluna::EnterCombat(Creature* me, Unit* target)
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, target); Eluna::Push(L, target);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1526,7 +1537,9 @@ bool Eluna::JustDied(Creature* me, Unit* killer)
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, killer); Eluna::Push(L, killer);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1541,7 +1554,9 @@ bool Eluna::KilledUnit(Creature* me, Unit* victim)
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, victim); Eluna::Push(L, victim);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1556,7 +1571,9 @@ bool Eluna::JustSummoned(Creature* me, Creature* summon)
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, summon); Eluna::Push(L, summon);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1571,7 +1588,9 @@ bool Eluna::SummonedCreatureDespawn(Creature* me, Creature* summon)
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, summon); Eluna::Push(L, summon);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1587,7 +1606,9 @@ bool Eluna::MovementInform(Creature* me, uint32 type, uint32 id)
Eluna::Push(L, type); Eluna::Push(L, type);
Eluna::Push(L, id); Eluna::Push(L, id);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1602,7 +1623,9 @@ bool Eluna::AttackStart(Creature* me, Unit* target)
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, target); Eluna::Push(L, target);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1617,7 +1640,9 @@ bool Eluna::EnterEvadeMode(Creature* me)
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_LEAVE_COMBAT, return false); ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_LEAVE_COMBAT, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1632,7 +1657,9 @@ bool Eluna::AttackedBy(Creature* me, Unit* attacker)
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, attacker); Eluna::Push(L, attacker);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1647,7 +1674,9 @@ bool Eluna::JustRespawned(Creature* me)
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SPAWN, return false); ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SPAWN, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1661,7 +1690,9 @@ bool Eluna::JustReachedHome(Creature* me)
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_REACH_HOME, return false); ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_REACH_HOME, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1677,7 +1708,9 @@ bool Eluna::ReceiveEmote(Creature* me, Player* player, uint32 emoteId)
Eluna::Push(L, player); Eluna::Push(L, player);
Eluna::Push(L, emoteId); Eluna::Push(L, emoteId);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1710,7 +1743,9 @@ bool Eluna::MoveInLineOfSight(Creature* me, Unit* who)
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, who); Eluna::Push(L, who);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1735,7 +1770,9 @@ bool Eluna::SpellHit(Creature* me, Unit* caster, SpellInfo const* spell)
Eluna::Push(L, caster); Eluna::Push(L, caster);
Eluna::Push(L, spell->Id); // Pass spell object? Eluna::Push(L, spell->Id); // Pass spell object?
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1751,7 +1788,9 @@ bool Eluna::SpellHitTarget(Creature* me, Unit* target, SpellInfo const* spell)
Eluna::Push(L, target); Eluna::Push(L, target);
Eluna::Push(L, spell->Id); // Pass spell object? Eluna::Push(L, spell->Id); // Pass spell object?
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1768,7 +1807,9 @@ bool Eluna::SummonedCreatureDies(Creature* me, Creature* summon, Unit* killer)
Eluna::Push(L, summon); Eluna::Push(L, summon);
Eluna::Push(L, killer); Eluna::Push(L, killer);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1783,7 +1824,9 @@ bool Eluna::OwnerAttackedBy(Creature* me, Unit* attacker)
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, attacker); Eluna::Push(L, attacker);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();
@@ -1798,7 +1841,9 @@ bool Eluna::OwnerAttacked(Creature* me, Unit* target)
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, target); Eluna::Push(L, target);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(1);
FOR_RETS(i) { FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false); result = CHECKVAL<bool>(L, i, false);
} }
ENDCALL(); ENDCALL();

View File

@@ -248,6 +248,7 @@ void Eluna::GetScripts(std::string path)
lua_requirepath += lua_requirepath +=
path + "/?;" + path + "/?;" +
path + "/?.lua;" + path + "/?.lua;" +
path + "/?.ext;" +
path + "/?.dll;" + path + "/?.dll;" +
path + "/?.so;"; path + "/?.so;";
@@ -290,6 +291,7 @@ void Eluna::GetScripts(std::string path)
lua_requirepath += lua_requirepath +=
path + "/?;" + path + "/?;" +
path + "/?.lua;" + path + "/?.lua;" +
path + "/?.ext;" +
path + "/?.dll;" + path + "/?.dll;" +
path + "/?.so;"; path + "/?.so;";
@@ -373,7 +375,7 @@ void Eluna::RunScripts()
lua_pop(L, 1); lua_pop(L, 1);
if (!luaL_loadfile(L, it->filepath.c_str()) && !lua_pcall(L, 0, 1, 0)) if (!luaL_loadfile(L, it->filepath.c_str()) && !lua_pcall(L, 0, 1, 0))
{ {
if (!lua_toboolean(L, -1)) if (lua_isnoneornil(L, -1) || (lua_isboolean(L, -1) && !lua_toboolean(L, -1)))
{ {
lua_pop(L, 1); lua_pop(L, 1);
Push(L, true); Push(L, true);

View File

@@ -225,8 +225,8 @@ public:
bool OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest); bool OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest);
bool OnQuestReward(Player* pPlayer, Creature* pCreature, Quest const* pQuest, uint32 opt); bool OnQuestReward(Player* pPlayer, Creature* pCreature, Quest const* pQuest, uint32 opt);
uint32 GetDialogStatus(Player* pPlayer, Creature* pCreature); uint32 GetDialogStatus(Player* pPlayer, Creature* pCreature);
void OnSummoned(Creature* creature, Unit* summoner);
bool OnSummoned(Creature* creature, Unit* summoner);
bool UpdateAI(Creature* me, const uint32 diff); bool UpdateAI(Creature* me, const uint32 diff);
bool EnterCombat(Creature* me, Unit* target); bool EnterCombat(Creature* me, Unit* target);
bool DamageTaken(Creature* me, Unit* attacker, uint32& damage); bool DamageTaken(Creature* me, Unit* attacker, uint32& damage);