Hello, I am trying to access a CombatParams object in a scheduler function. This is in TFS 1.3.
When compiling I am met with these errors:
As we can see in the compiler message, it seems like CombatParams gets deleted before it can be scheduled. Even if I put like CombatParams test; and use that variable, I still get the error. So how can I make it possible to access a CombatParams in a scheduled function?
This is how I call the function:
g_scheduler.addEvent(createSchedulerTask(100, std::bind(&Game::activateWeaponCombat, &g_game, player->getID(), target->getID(), damage, params)));
If I call it normally (without scheduler), it works fine: Game::activateWeaponCombat(player->getID(), target->getID(), damage, params);
This is how my function looks:
The thing is I want it with a delay though, the function also works fine with scheduler if I remove the need for the combatParams object, but I think that is also necessary for my function, because I have lots of things stored in params.
When compiling I am met with these errors:
Code:
rom /usr/include/c++/5/functional:55:0,
from /home/otsmanager/forgottenserver/src/otpch.h:29,
from /home/otsmanager/forgottenserver/src/cotire/tfs_CXX_prefix.cxx:4,
from /home/otsmanager/forgottenserver/src/cotire/tfs_CXX_prefix.hxx:4:
/usr/include/c++/5/tuple: In instantiation of ‘constexpr std::_Head_base<_Idx, _Head, false>::_Head_base(const _Head&) [with long unsigned int _Idx = 4ul; _Head = CombatParams]’:
/usr/include/c++/5/tuple:206:44: recursively required from ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const _Head&, const _Tail& ...) [with long unsigned int _Idx = 1ul; _Head = unsigned int; _Tail = {unsigned int, CombatDamage, CombatParams}]’
/usr/include/c++/5/tuple:206:44: required from ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const _Head&, const _Tail& ...) [with long unsigned int _Idx = 0ul; _Head = Game*; _Tail = {unsigned int, unsigned int, CombatDamage, CombatParams}]’
/usr/include/c++/5/tuple:473:33: required from ‘constexpr std::tuple< <template-parameter-1-1> >::tuple(const _Elements& ...) [with _Elements = {Game*, unsigned int, unsigned int, CombatDamage, CombatParams}]’
/usr/include/c++/5/functional:1114:70: required from ‘std::_Bind<_Functor(_Bound_args ...)>::_Bind(_Functor&&, _Args&& ...) [with _Args = {Game*, unsigned int, unsigned int, CombatDamage&, const CombatParams&}; _Functor = std::_Mem_fn<void (Game::*)(unsigned int, unsigned int, CombatDamage&, const CombatParams&)>; _Bound_args = {Game*, unsigned int, unsigned int, CombatDamage, CombatParams}]’
/usr/include/c++/5/functional:1468:42: required from ‘typename std::_Bind_helper<std::__is_socketlike<_Func>::value, _Func, _BoundArgs ...>::type std::bind(_Func&&, _BoundArgs&& ...) [with _Func = void (Game::*)(unsigned int, unsigned int, CombatDamage&, const CombatParams&); _BoundArgs = {Game*, unsigned int, unsigned int, CombatDamage&, const CombatParams&}; typename std::_Bind_helper<std::__is_socketlike<_Func>::value, _Func, _BoundArgs ...>::type = std::_Bind<std::_Mem_fn<void (Game::*)(unsigned int, unsigned int, CombatDamage&, const CombatParams&)>(Game*, unsigned int, unsigned int, CombatDamage, CombatParams)>]’
/home/otsmanager/forgottenserver/src/weapons.cpp:420:148: required from here
/usr/include/c++/5/tuple:108:25: error: use of deleted function ‘CombatParams::CombatParams(const CombatParams&)’
: _M_head_impl(__h) { }
^
In file included from /home/otsmanager/forgottenserver/src/weapons.cpp:22:0:
/home/otsmanager/forgottenserver/src/combat.h:63:8: note: ‘CombatParams::CombatParams(const CombatParams&)’ is implicitly deleted because the default definition would be ill-formed:
struct CombatParams {
^
/home/otsmanager/forgottenserver/src/combat.h:63:8: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = ValueCallback; _Dp = std::default_delete<ValueCallback>]’
In file included from /usr/include/c++/5/bits/locale_conv.h:41:0,
from /usr/include/c++/5/locale:43,
from /usr/include/c++/5/iomanip:43,
from /home/otsmanager/forgottenserver/src/otpch.h:30,
from /home/otsmanager/forgottenserver/src/cotire/tfs_CXX_prefix.cxx:4,
from /home/otsmanager/forgottenserver/src/cotire/tfs_CXX_prefix.hxx:4:
/usr/include/c++/5/bits/unique_ptr.h:356:7: note: declared here
unique_ptr(const unique_ptr&) = delete;
^
In file included from /home/otsmanager/forgottenserver/src/weapons.cpp:22:0:
/home/otsmanager/forgottenserver/src/combat.h:63:8: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = TileCallback; _Dp = std::default_delete<TileCallback>]’
struct CombatParams {
^
In file included from /usr/include/c++/5/bits/locale_conv.h:41:0,
from /usr/include/c++/5/locale:43,
from /usr/include/c++/5/iomanip:43,
from /home/otsmanager/forgottenserver/src/otpch.h:30,
from /home/otsmanager/forgottenserver/src/cotire/tfs_CXX_prefix.cxx:4,
from /home/otsmanager/forgottenserver/src/cotire/tfs_CXX_prefix.hxx:4:
/usr/include/c++/5/bits/unique_ptr.h:356:7: note: declared here
unique_ptr(const unique_ptr&) = delete;
^
In file included from /home/otsmanager/forgottenserver/src/weapons.cpp:22:0:
/home/otsmanager/forgottenserver/src/combat.h:63:8: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = TargetCallback; _Dp = std::default_delete<TargetCallback>]’
struct CombatParams {
^
In file included from /usr/include/c++/5/bits/locale_conv.h:41:0,
from /usr/include/c++/5/locale:43,
from /usr/include/c++/5/iomanip:43,
from /home/otsmanager/forgottenserver/src/otpch.h:30,
from /home/otsmanager/forgottenserver/src/cotire/tfs_CXX_prefix.cxx:4,
from /home/otsmanager/forgottenserver/src/cotire/tfs_CXX_prefix.hxx:4:
/usr/include/c++/5/bits/unique_ptr.h:356:7: note: declared here
unique_ptr(const unique_ptr&) = delete;
^
In file included from /home/otsmanager/forgottenserver/src/otpch.h:29:0,
from /home/otsmanager/forgottenserver/src/cotire/tfs_CXX_prefix.cxx:4,
from /home/otsmanager/forgottenserver/src/cotire/tfs_CXX_prefix.hxx:4:
/usr/include/c++/5/functional: In instantiation of ‘static void std::_Function_base::_Base_manager<_Functor>::_M_clone(std::_Any_data&, const std::_Any_data&, std::false_type) [with _Functor = std::_Bind<std::_Mem_fn<void (Game::*)(unsigned int, unsigned int, CombatDamage&, const CombatParams&)>(Game*, unsigned int, unsigned int, CombatDamage, CombatParams)>; std::false_type = std::integral_constant<bool, false>]’:
/usr/include/c++/5/functional:1746:16: required from ‘static bool std::_Function_base::_Base_manager<_Functor>::_M_manager(std::_Any_data&, const std::_Any_data&, std::_Manager_operation) [with _Functor = std::_Bind<std::_Mem_fn<void (Game::*)(unsigned int, unsigned int, CombatDamage&, const CombatParams&)>(Game*, unsigned int, unsigned int, CombatDamage, CombatParams)>]’
/usr/include/c++/5/functional:2256:19: required from ‘std::function<_Res(_ArgTypes ...)>::function(_Functor) [with _Functor = std::_Bind<std::_Mem_fn<void (Game::*)(unsigned int, unsigned int, CombatDamage&, const CombatParams&)>(Game*, unsigned int, unsigned int, CombatDamage, CombatParams)>; <template-parameter-2-2> = void; <template-parameter-2-3> = void; _Res = void; _ArgTypes = {}]’
/home/otsmanager/forgottenserver/src/weapons.cpp:420:149: required from here
/usr/include/c++/5/functional:1710:34: error: use of deleted function ‘std::_Bind<_Functor(_Bound_args ...)>::_Bind(const std::_Bind<_Functor(_Bound_args ...)>&) [with _Functor = std::_Mem_fn<void (Game::*)(unsigned int, unsigned int, CombatDamage&, const CombatParams&)>; _Bound_args = {Game*, unsigned int, unsigned int, CombatDamage, CombatParams}]’
__dest._M_access<_Functor*>() =
^
/usr/include/c++/5/functional:1117:7: note: ‘std::_Bind<_Functor(_Bound_args ...)>::_Bind(const std::_Bind<_Functor(_Bound_args ...)>&) [with _Functor = std::_Mem_fn<void (Game::*)(unsigned int, unsigned int, CombatDamage&, const CombatParams&)>; _Bound_args = {Game*, unsigned int, unsigned int, CombatDamage, CombatParams}]’ is implicitly deleted because the default definition would be ill-formed:
_Bind(const _Bind&) = default;
^
/usr/include/c++/5/functional:1117:7: error: use of deleted function ‘constexpr std::tuple< <template-parameter-1-1> >::tuple(const std::tuple< <template-parameter-1-1> >&) [with _Elements = {Game*, unsigned int, unsigned int, CombatDamage, CombatParams}]’
In file included from /usr/include/c++/5/functional:55:0,
from /home/otsmanager/forgottenserver/src/otpch.h:29,
from /home/otsmanager/forgottenserver/src/cotire/tfs_CXX_prefix.cxx:4,
from /home/otsmanager/forgottenserver/src/cotire/tfs_CXX_prefix.hxx:4:
/usr/include/c++/5/tuple:482:17: note: ‘constexpr std::tuple< <template-parameter-1-1> >::tuple(const std::tuple< <template-parameter-1-1> >&) [with _Elements = {Game*, unsigned int, unsigned int, CombatDamage, CombatParams}]’ is implicitly deleted because the default definition would be ill-formed:
constexpr tuple(const tuple&) = default;
^
/usr/include/c++/5/tuple:482:17: error: use of deleted function ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 0ul; _Head = Game*; _Tail = {unsigned int, unsigned int, CombatDamage, CombatParams}]’
/usr/include/c++/5/tuple:215:17: note: ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 0ul; _Head = Game*; _Tail = {unsigned int, unsigned int, CombatDamage, CombatParams}]’ is implicitly deleted because the default definition would be ill-formed:
constexpr _Tuple_impl(const _Tuple_impl&) = default;
^
/usr/include/c++/5/tuple:215:17: error: use of deleted function ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 1ul; _Head = unsigned int; _Tail = {unsigned int, CombatDamage, CombatParams}]’
/usr/include/c++/5/tuple:215:17: note: ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 1ul; _Head = unsigned int; _Tail = {unsigned int, CombatDamage, CombatParams}]’ is implicitly deleted because the default definition would be ill-formed:
/usr/include/c++/5/tuple:215:17: error: use of deleted function ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 2ul; _Head = unsigned int; _Tail = {CombatDamage, CombatParams}]’
/usr/include/c++/5/tuple:215:17: note: ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 2ul; _Head = unsigned int; _Tail = {CombatDamage, CombatParams}]’ is implicitly deleted because the default definition would be ill-formed:
/usr/include/c++/5/tuple:215:17: error: use of deleted function ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 3ul; _Head = CombatDamage; _Tail = {CombatParams}]’
/usr/include/c++/5/tuple:215:17: note: ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 3ul; _Head = CombatDamage; _Tail = {CombatParams}]’ is implicitly deleted because the default definition would be ill-formed:
/usr/include/c++/5/tuple:215:17: error: use of deleted function ‘constexpr std::_Tuple_impl<_Idx, _Head>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head>&) [with long unsigned int _Idx = 4ul; _Head = CombatParams]’
/usr/include/c++/5/tuple:364:17: note: ‘constexpr std::_Tuple_impl<_Idx, _Head>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head>&) [with long unsigned int _Idx = 4ul; _Head = CombatParams]’ is implicitly deleted because the default definition would be ill-formed:
constexpr _Tuple_impl(const _Tuple_impl&) = default;
^
/usr/include/c++/5/tuple:364:17: error: use of deleted function ‘constexpr std::_Head_base<_Idx, _Head, false>::_Head_base(const std::_Head_base<_Idx, _Head, false>&) [with long unsigned int _Idx = 4ul; _Head = CombatParams]’
/usr/include/c++/5/tuple:110:17: note: ‘constexpr std::_Head_base<_Idx, _Head, false>::_Head_base(const std::_Head_base<_Idx, _Head, false>&) [with long unsigned int _Idx = 4ul; _Head = CombatParams]’ is implicitly deleted because the default definition would be ill-formed:
constexpr _Head_base(const _Head_base&) = default;
^
/usr/include/c++/5/tuple:110:17: error: use of deleted function ‘CombatParams::CombatParams(const CombatParams&)’
CMakeFiles/tfs.dir/build.make:1951: recipe for target 'CMakeFiles/tfs.dir/weapons.cpp.o' failed
make[2]: *** [CMakeFiles/tfs.dir/weapons.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/tfs.dir/all' failed
make[1]: *** [CMakeFiles/tfs.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
As we can see in the compiler message, it seems like CombatParams gets deleted before it can be scheduled. Even if I put like CombatParams test; and use that variable, I still get the error. So how can I make it possible to access a CombatParams in a scheduled function?
This is how I call the function:
g_scheduler.addEvent(createSchedulerTask(100, std::bind(&Game::activateWeaponCombat, &g_game, player->getID(), target->getID(), damage, params)));
If I call it normally (without scheduler), it works fine: Game::activateWeaponCombat(player->getID(), target->getID(), damage, params);
This is how my function looks:
Code:
void Game::activateWeaponCombat(uint32_t casterId, uint32_t targetId, CombatDamage& damage, const CombatParams& params)
{
Creature* caster = getCreatureByID(casterId);
if (!caster) {
return;
}
Creature* target = getCreatureByID(targetId);
if (!target) {
return;
}
Combat::doCombatHealth(caster, target, damage, params);
}
The thing is I want it with a delay though, the function also works fine with scheduler if I remove the need for the combatParams object, but I think that is also necessary for my function, because I have lots of things stored in params.