Skip to content

Commit

Permalink
fix: Stability fixes.
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Nana <[email protected]>
  • Loading branch information
na2axl committed Nov 2, 2024
1 parent fb2cf46 commit 8c25d89
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/Core/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2256,18 +2256,21 @@ namespace SparkyStudios::Audio::Amplitude
if (_state->paused)
return;

// Execute pending frame callbacks.
Thread::LockMutex(_frameThreadMutex);
if (!_state->stopping)
{
while (!_nextFrameCallbacks.empty())
// Execute pending frame callbacks.
Thread::LockMutex(_frameThreadMutex);
{
const auto& callback = _nextFrameCallbacks.front();
callback(delta);
while (!_nextFrameCallbacks.empty())
{
const auto& callback = _nextFrameCallbacks.front();
callback(delta);

_nextFrameCallbacks.pop();
_nextFrameCallbacks.pop();
}
}
Thread::UnlockMutex(_frameThreadMutex);
}
Thread::UnlockMutex(_frameThreadMutex);

EraseFinishedSounds(_state);

Expand Down
1 change: 0 additions & 1 deletion src/Core/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ namespace SparkyStudios::Audio::Amplitude
if (_event == nullptr)
return;

ampooldelete(eMemoryPoolKind_Engine, EventInstanceImpl, (EventInstanceImpl*)_event);
_event = nullptr;
}

Expand Down
81 changes: 81 additions & 0 deletions tests/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,48 @@ TEST_CASE("Engine Tests", "[engine][core][amplitude]")
}
}

THEN("engine can load event handles by name")
{
EventHandle event1 = amEngine->GetEventHandle("play_throw");
REQUIRE(event1 != nullptr);
}

THEN("engine can load event handles by ID")
{
EventHandle event1 = amEngine->GetEventHandle(123456787654);
REQUIRE(event1 != nullptr);
}

THEN("engine cannot load event handles with invalid names or IDs")
{
EventHandle invalidEvent1 = amEngine->GetEventHandle("invalid_event");
REQUIRE(invalidEvent1 == nullptr);

EventHandle invalidEvent2 = amEngine->GetEventHandle(99999999);
REQUIRE(invalidEvent2 == nullptr);

AND_THEN("engine cannot trigger events with invalid event IDs")
{
const Entity& e = amEngine->AddEntity(99);
EventCanceler canceler = amEngine->Trigger(99999999, e);
REQUIRE_FALSE(canceler.Valid());
}

AND_THEN("engine cannot trigger events with invalid event names")
{
const Entity& e = amEngine->AddEntity(99);
EventCanceler canceler = amEngine->Trigger("invalid_event", e);
REQUIRE_FALSE(canceler.Valid());
}

AND_THEN("engine cannot trigger events of invalid event handles")
{
const Entity& e = amEngine->AddEntity(99);
EventCanceler canceler = amEngine->Trigger(invalidEvent2, e);
REQUIRE_FALSE(canceler.Valid());
}
}

GIVEN("a playing channel")
{
AmVec3 location = { 10.0f, 20.0f, 30.0f };
Expand Down Expand Up @@ -1052,6 +1094,45 @@ TEST_CASE("Engine Tests", "[engine][core][amplitude]")
REQUIRE(rtpc1->GetValue() == rtpc1->GetMinValue());
}
}

GIVEN("an event")
{
EventHandle event1 = amEngine->GetEventHandle("stop_throw");
REQUIRE(event1 != nullptr);

EventHandle event2 = amEngine->GetEventHandle(876);
REQUIRE(event2 != nullptr);

THEN("it can fire and reset")
{
EventCanceler c1 = amEngine->Trigger(event1, amEngine->AddEntity(99));
REQUIRE(c1.Valid());
REQUIRE(c1.GetEvent()->IsRunning());

c1.Cancel();
REQUIRE_FALSE(c1.GetEvent()->IsRunning());
}

THEN("engine can fire and reset by ID")
{
EventCanceler c1 = amEngine->Trigger(5, amEngine->AddEntity(99));
REQUIRE(c1.Valid());
REQUIRE(c1.GetEvent()->IsRunning());

c1.Cancel();
REQUIRE_FALSE(c1.GetEvent()->IsRunning());
}

THEN("engine can fire and reset by name")
{
EventCanceler c1 = amEngine->Trigger(event2->GetName(), amEngine->AddEntity(99));
REQUIRE(c1.Valid());
REQUIRE(c1.GetEvent()->IsRunning());

c1.Cancel();
REQUIRE_FALSE(c1.GetEvent()->IsRunning());
}
}
}
}
}
2 changes: 2 additions & 0 deletions tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ int main(int argc, char* argv[])
ConsoleLogger logger;
Logger::SetLogger(&logger);

RegisterDeviceNotificationCallback(deviceCallback);

MemoryManager::Initialize();

const auto res = Catch::Session().run(argc, argv);
Expand Down

0 comments on commit 8c25d89

Please sign in to comment.