Remove event hook threads, as it caused issues when being called from dotnet.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
@@ -19,7 +19,6 @@ namespace CreatureLib::Battling {
|
||||
size_t _offset;
|
||||
size_t _capacity;
|
||||
uint8_t* _memory = nullptr;
|
||||
std::thread* _currentThread = nullptr;
|
||||
|
||||
static constexpr size_t initialSize = 2048;
|
||||
static constexpr size_t stepSize = 1024;
|
||||
@@ -35,13 +34,7 @@ namespace CreatureLib::Battling {
|
||||
EventHook(const EventHook&) = delete;
|
||||
EventHook& operator=(const EventHook&) = delete;
|
||||
|
||||
~EventHook() {
|
||||
free(_memory);
|
||||
if (_currentThread != nullptr && _currentThread->joinable()) {
|
||||
_currentThread->join();
|
||||
}
|
||||
delete _currentThread;
|
||||
}
|
||||
~EventHook() { free(_memory); }
|
||||
|
||||
size_t GetPosition() const noexcept { return _offset; }
|
||||
size_t GetCapacity() const noexcept { return _capacity; }
|
||||
@@ -49,10 +42,6 @@ namespace CreatureLib::Battling {
|
||||
template <class T, class... parameters> void Trigger(parameters... args) {
|
||||
if (_listeners.size() == 0)
|
||||
return;
|
||||
if (_currentThread != nullptr && _currentThread->joinable()) {
|
||||
_currentThread->join();
|
||||
}
|
||||
delete _currentThread;
|
||||
|
||||
if (_offset + sizeof(T) >= _capacity) {
|
||||
_capacity += stepSize;
|
||||
@@ -65,25 +54,14 @@ namespace CreatureLib::Battling {
|
||||
uint8_t* ptr = _memory + _offset;
|
||||
T* event = new (ptr) T(args...);
|
||||
_offset += sizeof(T);
|
||||
_currentThread = new std::thread(&EventHook::RunListeners, this, event);
|
||||
}
|
||||
|
||||
void RegisterListener(const EventHookFunc& func) { _listeners.push_back(func); }
|
||||
|
||||
void FinishListening() {
|
||||
if (_currentThread != nullptr && _currentThread->joinable()) {
|
||||
_currentThread->join();
|
||||
}
|
||||
delete _currentThread;
|
||||
_currentThread = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
void RunListeners(EventData* event) {
|
||||
for (auto listener : _listeners) {
|
||||
try_creature(listener(event), "Exception in event listener");
|
||||
}
|
||||
}
|
||||
|
||||
void RegisterListener(const EventHookFunc& func) { _listeners.push_back(func); }
|
||||
|
||||
private:
|
||||
};
|
||||
}
|
||||
#endif // CREATURELIB_EVENTHOOK_HPP
|
||||
|
||||
@@ -89,7 +89,6 @@ void Battle::CheckChoicesSetAndRun() {
|
||||
this->_currentTurnQueue = nullptr;
|
||||
}
|
||||
TriggerEventListener<TurnEndEvent>();
|
||||
_eventHook.FinishListening();
|
||||
}
|
||||
|
||||
ArbUt::BorrowedPtr<ChoiceQueue> Battle::GetCurrentTurnQueue() const noexcept { return _currentTurnQueue; }
|
||||
|
||||
@@ -95,6 +95,7 @@ namespace CreatureLib::Battling {
|
||||
void RemoveVolatileScript(Script* script);
|
||||
bool HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); }
|
||||
bool HasVolatileScript(uint32_t keyHash) const { return _volatile.Has(keyHash); }
|
||||
EventHook& GetEventHook() noexcept { return _eventHook; }
|
||||
const EventHook& GetEventHook() const noexcept { return _eventHook; }
|
||||
|
||||
void DisplayText(const ArbUt::StringView& text);
|
||||
|
||||
Reference in New Issue
Block a user