1 /* Copyright (C) 2021 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef INCLUDED_LOADERTHUNKS
19 #define INCLUDED_LOADERTHUNKS
21 // does this return code indicate the coroutine yielded and
22 // wasn't yet finished?
23 static inline bool ldr_was_interrupted(int ret
)
25 return (0 < ret
&& ret
<= 100);
28 template<class T
> struct MemFun_t
30 NONCOPYABLE(MemFun_t
);
34 MemFun_t(T
* this__
, int(T::*func_
)(void))
35 : this_(this__
), func(func_
) {}
38 template<class T
> static int MemFunThunk(std::shared_ptr
<void> param
, double UNUSED(time_left
))
40 MemFun_t
<T
>* const mf
= static_cast<MemFun_t
<T
>*>(param
.get());
41 return (mf
->this_
->*mf
->func
)();
44 template<class T
> void RegMemFun(T
* this_
, int(T::*func
)(void),
45 const wchar_t* description
, int estimated_duration_ms
)
47 LDR_Register(MemFunThunk
<T
>, std::make_shared
<MemFun_t
<T
>>(this_
, func
), description
, estimated_duration_ms
);
51 ////////////////////////////////////////////////////////
54 template<class T
, class Arg
> struct MemFun1_t
56 NONCOPYABLE(MemFun1_t
);
61 MemFun1_t(T
* this__
, int(T::*func_
)(Arg
), Arg arg_
)
62 : this_(this__
), func(func_
), arg(arg_
) {}
65 template<class T
, class Arg
> static int MemFun1Thunk(std::shared_ptr
<void> param
, double UNUSED(time_left
))
67 MemFun1_t
<T
, Arg
>* const mf
= static_cast<MemFun1_t
<T
, Arg
>*>(param
.get());
68 return (mf
->this_
->*mf
->func
)(mf
->arg
);
71 template<class T
, class Arg
> void RegMemFun1(T
* this_
, int(T::*func
)(Arg
), Arg arg
,
72 const wchar_t* description
, int estimated_duration_ms
)
74 LDR_Register(MemFun1Thunk
<T
, Arg
>, std::make_shared
<MemFun1_t
<T
, Arg
> >(this_
, func
, arg
), description
, estimated_duration_ms
);
77 #endif // INCLUDED_LOADERTHUNKS