@DejaVu @pekfos
Dzięki za wskazówki.
Zrobiłem tak jak napisałeś tj.
void ActionScript::internalAddPositionEx( lua_State * L, const PositionEx & pos )
{
#ifdef MUTEXY_FIX
std::lock_guard < std::mutex > guard( actionsMutex );
#endif lua_newtable( L );
setField( L, "z", pos.z );
setField( L, "y", pos.y );
setField( L, "x", pos.x );
setField( L, "stackpos", pos.stackpos );
}
oraz w actions.h pod protected: dodałem
#ifdef MUTEXY_FIX
mutable std::mutex actionsMutex;
#endif
to wywala błąd:
actions.cpp: In static member function âstatic void ActionScript::internalAddPositionEx(lua_State*, const PositionEx&)â:
actions.cpp:1175:37: error: invalid use of member âActionScript::actionsMutexâ in static member function
std::lock_guard <std::mutex> guard(actionsMutex);
^~~~~~~~~~~~
In file included from player.h:10,
from actions.cpp:8:
actions.h:274:21: note: declared here
mutable std::mutex actionsMutex;
^~~~~~~~~~~~
Próbowałem też innym sposobem tzn.
Zwróciłeś uwage jak są zrobione locki w protocol76.cpp - gdybym tak zrobił analogicznie dla spells.cpp i actions.cpp i creature.cpp miałoby to sens? np.
void ActionScript::internalAddPositionEx( lua_State * L, const PositionEx & pos )
{
#ifdef MUTEXY_FIX
OTSYS_THREAD_LOCK_CLASS lockClass( game->gameLock, "ActionScript::internalAddPositionEx()" );
#endif lua_newtable( L );
setField( L, "z", pos.z );
setField( L, "y", pos.y );
setField( L, "x", pos.x );
setField( L, "stackpos", pos.stackpos );
}
z tym, że wywala podobny błąd:
actions.cpp: In static member function âstatic void ActionScript::internalAddPositionEx(lua_State*, const PositionEx&)â:
actions.cpp:1175:39: error: invalid use of member âActionScript::gameâ in static member function
OTSYS_THREAD_LOCK_CLASS lockClass(game->gameLock, "ActionScript::internalAddPositionEx()");
^~~~
In file included from player.h:10,
from actions.cpp:8:
actions.h:274:8: note: declared here
Game *game;
^~~~
Na tyle rozumiem, że problem jest w tym ze jest zadeklarowana jako metoda statyczna tj:
static void internalAddPositionEx( lua_State * L, const PositionEx & pos );
Da się jakoś inaczej obejsć ten problem niz kasujac slowo kluczowe static? Bo jak zmieniam ta metode kasujac słowo static to w ogóle zaczyna się krzaczyć w kilku innych miejscach.
np.
actions.cpp: In static member function âstatic int32_t ActionScript::internalGetPlayerInfo(lua_State*, ePlayerInfo)â:
actions.cpp:1241:31: error: cannot call member function âvoid ActionScript::internalAddPositionEx(lua_State*, const PositionEx&)â without object
internalAddPositionEx(L,pos);
^
actions.cpp:1246:31: error: cannot call member function âvoid ActionScript::internalAddPositionEx(lua_State*, const PositionEx&)â without object
internalAddPositionEx(L,pos);
Oczywiście w actions.h mam kilka klas np.
class ActionScript;
class Action;
Jeżeli chodzi np. już o Action::executeUse(......)
to zadziałało bez problemu jednym i drugim sposobem np:
bool Action::executeUse( Player * player, Item * item, PositionEx & posFrom, PositionEx & posTo )
{
#ifdef MUTEXY_FIX
OTSYS_THREAD_LOCK_CLASS lockClass( game->gameLock, "Action::executeUse()" );
#endif
ale tutaj metoda już nie jest oznaczona jako "static"
bool executeUse( Player * player, Item * item, PositionEx & posFrom, PositionEx & posTo );
Także jak sobie poradzić gdy metoda jest oznaczona jako static i chciałbym użyć np.
#ifdef MUTEXY_FIX
OTSYS_THREAD_LOCK_CLASS lockClass( game->gameLock, "ActionScript::internalAddPositionEx()" );
#endif