When calling script hooks from another script, re-use existing script context.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
b8b692d4d6
commit
af2f62a278
|
@ -33,7 +33,14 @@ public:
|
||||||
auto s = _type->Get##name(); \
|
auto s = _type->Get##name(); \
|
||||||
if (!s.Exists) \
|
if (!s.Exists) \
|
||||||
return; \
|
return; \
|
||||||
auto ctx = _ctxPool->RequestContext(); \
|
auto ctx = asGetActiveContext(); \
|
||||||
|
bool newContext = false; \
|
||||||
|
if (ctx == nullptr) { \
|
||||||
|
ctx = _ctxPool->RequestContext(); \
|
||||||
|
newContext = true; \
|
||||||
|
} else { \
|
||||||
|
ctx->PushState(); \
|
||||||
|
} \
|
||||||
ctx->Prepare(s.Function); \
|
ctx->Prepare(s.Function); \
|
||||||
ctx->SetObject(_obj); \
|
ctx->SetObject(_obj); \
|
||||||
setup; \
|
setup; \
|
||||||
|
@ -41,11 +48,15 @@ public:
|
||||||
if (scriptResult != 0) { \
|
if (scriptResult != 0) { \
|
||||||
throw CreatureException("Script didn't finish properly; message " + std::to_string(scriptResult)); \
|
throw CreatureException("Script didn't finish properly; message " + std::to_string(scriptResult)); \
|
||||||
} \
|
} \
|
||||||
_ctxPool->ReturnContextToPool(ctx);
|
if (newContext) { \
|
||||||
|
_ctxPool->ReturnContextToPool(ctx); \
|
||||||
|
} else { \
|
||||||
|
ctx->PopState(); \
|
||||||
|
}
|
||||||
|
|
||||||
void Stack() override { CALLHOOK(Stack,); }
|
void Stack() override { CALLHOOK(Stack, ); }
|
||||||
|
|
||||||
void OnRemove() override { CALLHOOK(OnRemove,); }
|
void OnRemove() override { CALLHOOK(OnRemove, ); }
|
||||||
|
|
||||||
void OnBeforeTurn(const CreatureLib::Battling::BaseTurnChoice* choice) override {
|
void OnBeforeTurn(const CreatureLib::Battling::BaseTurnChoice* choice) override {
|
||||||
throw NotImplementedException(); // TODO
|
throw NotImplementedException(); // TODO
|
||||||
|
|
Loading…
Reference in New Issue