Skip to content

Commit

Permalink
- cleanup game application init/deinit flow a bit
Browse files Browse the repository at this point in the history
- add missing extend to pinned array
- avoid calling fetchresult on physx scene on shutdown if it wasnt simulating
- set max voices in soloud
  • Loading branch information
kaffeewolf committed Mar 2, 2024
1 parent c827d52 commit 61402b6
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 19 deletions.
26 changes: 19 additions & 7 deletions code/application/appgame/gameapplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "io/fswrapper.h"
#include "jobs2/jobs2.h"
#include "input/inputserver.h"
#include "basegamefeature/basegamefeatureunit.h"

#include "profiling/profiling.h"

Expand Down Expand Up @@ -147,7 +148,11 @@ GameApplication::Open()
// create our game server and open it
this->gameServer = Game::GameServer::Create();
this->gameServer->SetCmdLineArgs(this->GetCmdLineArgs());


// always attach the base game feature
this->baseGameFeature = BaseGameFeature::BaseGameFeatureUnit::Create();
this->gameServer->AttachGameFeature(this->baseGameFeature);

// create and add new game features
this->SetupGameFeatures();
// open the game server
Expand All @@ -174,18 +179,21 @@ GameApplication::Close()
//_discard_timer(GameApplicationFrameTimeAll);

// shutdown basic Nebula runtime
this->CleanupGameFeatures();
this->gameServer->Stop();
this->gameServer->CleanupWorld(Game::GetWorld(WORLD_DEFAULT));

this->gameServer->Close();

this->CleanupGameFeatures();
this->gameServer->RemoveGameFeature(this->baseGameFeature);
this->baseGameFeature->Release();
this->baseGameFeature = nullptr;

this->gameServer = nullptr;

this->gameContentServer->Discard();
this->gameContentServer = nullptr;

this->ioInterface->Close();
this->ioInterface = nullptr;
this->ioServer = nullptr;

this->resourceServer->Close();
this->resourceServer = nullptr;

Expand All @@ -199,6 +207,10 @@ GameApplication::Close()
this->httpInterface = nullptr;
#endif

this->ioInterface->Close();
this->ioInterface = nullptr;
this->ioServer = nullptr;

this->coreServer->Close();
this->coreServer = nullptr;

Expand Down Expand Up @@ -274,7 +286,7 @@ GameApplication::StepFrame()
void
GameApplication::SetupGameFeatures()
{
// create any features in derived class

}

//------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions code/application/appgame/gameapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "resources/resourceserver.h"
#include "http/httpinterface.h"
#include "http/httpserverproxy.h"
#include "basegamefeature/basegamefeatureunit.h"

//------------------------------------------------------------------------------
namespace App
Expand Down Expand Up @@ -59,6 +60,7 @@ class GameApplication : public Application
Ptr<Resources::ResourceServer> resourceServer;
Ptr<IO::IoServer> ioServer;
Ptr<IO::IoInterface> ioInterface;
Ptr<BaseGameFeature::BaseGameFeatureUnit> baseGameFeature;


#if __NEBULA_HTTP__
Expand Down
3 changes: 0 additions & 3 deletions code/application/game/gameserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ GameServer::GameServer()

this->state.templateDatabase = MemDb::Database::Create();
this->CreateWorld(WORLD_DEFAULT);

// always attach the base game feature
this->AttachGameFeature(BaseGameFeature::BaseGameFeatureUnit::Create());
}

//------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion code/application/game/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ World::AddComponent(Entity entity)
n_assert2(!this->pipeline.IsRunningAsync(), "Adding component to entities while in an async processor is currently not supported!");
#endif
Game::ComponentId id = Game::GetComponentId<TYPE>();
#if _DEBUG
#if NEBULA_DEBUG
n_assert(MemDb::AttributeRegistry::TypeSize(id) == sizeof(TYPE));
//n_assert(!this->HasComponent<TYPE>(entity));
#endif
Expand Down
10 changes: 6 additions & 4 deletions code/audio/audio/audiodevice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ AudioDevice::Open()
{
soloud = new SoLoud::Soloud;
soloud->init(SoLoud::Soloud::CLIP_ROUNDOFF);

soloud->setMaxActiveVoiceCount(32);
this->ResetListener();

_setup_grouped_timer(AudioOnFrameTime, "Audio Subsystem");
Expand All @@ -56,6 +56,8 @@ AudioDevice::Close()
delete soloud;

_discard_timer(AudioOnFrameTime);
_end_counter(AudioNumberOfSoundsPlaying);
_discard_counter(AudioNumberOfSoundsPlaying);

return true;
}
Expand All @@ -71,9 +73,9 @@ AudioDevice::OnFrame()
soloud->update3dAudio();

_stop_timer(AudioOnFrameTime);
//_begin_counter(AudioNumberOfSoundsPlaying);
//_set_counter(AudioNumberOfSoundsPlaying, soloud->getActiveVoiceCount());
//_end_counter(AudioNumberOfSoundsPlaying);
_begin_counter(AudioNumberOfSoundsPlaying);
_set_counter(AudioNumberOfSoundsPlaying, soloud->getActiveVoiceCount());
_end_counter(AudioNumberOfSoundsPlaying);
}

//------------------------------------------------------------------------------
Expand Down
16 changes: 16 additions & 0 deletions code/foundation/util/pinnedarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class PinnedArray : public Array<TYPE>
void Realloc(SizeT capacity, SizeT grow);
/// Resize to fit, destroys elements outside of new size
void Resize(SizeT num);
/// Resize to fit the provided value, but don't shrink if the new size is smaller
void Extend(SizeT num);

/// Free memory
void Free();
Expand Down Expand Up @@ -619,6 +621,20 @@ PinnedArray<MAX_ALLOCS, TYPE>::Resize(SizeT num)
this->count = num;
}

//------------------------------------------------------------------------------
/**
*/
template<int MAX_ALLOCS, class TYPE>
inline void
PinnedArray<MAX_ALLOCS, TYPE>::Extend(SizeT num)
{
if (num > this->capacity)
{
this->GrowTo(num);
}
this->count = Math::max(num, this->count);
}

//------------------------------------------------------------------------------
/**
*/
Expand Down
6 changes: 5 additions & 1 deletion code/physics/physics/physxstate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,11 @@ PhysxState::FlushSimulation(IndexT sceneId)
{
n_assert(this->activeSceneIds.FindIndex(sceneId) != InvalidIndex);
Physics::Scene& scene = this->activeScenes[sceneId];
scene.scene->fetchResults(true);
if (scene.isSimulating)
{
scene.scene->fetchResults(true);
scene.isSimulating = false;
}
}

PhysxState state;
Expand Down
4 changes: 2 additions & 2 deletions code/render/graphics/environmentcontext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Math::vec4
CalculateZenithLuminanceYxy(float t, float thetaS)
{
float chi = (4.0 / 9.0 - t / 120.0) * (PI - 2.0 * thetaS);
float Yz = (4.0453 * t - 4.9710) * tan(chi) - 0.2155 * t + 2.4192;
float Yz = (4.0453 * t - 4.9710) * Math::tan(chi) - 0.2155 * t + 2.4192;

float theta2 = thetaS * thetaS;
float theta3 = theta2 * thetaS;
Expand Down Expand Up @@ -175,7 +175,7 @@ EnvironmentContext::OnBeforeFrame(const Graphics::FrameContext& ctx)
D.store(tickParams.D);
E.store(tickParams.E);

float thetaS = acos(Math::dot3(sunDir, Math::vec4(0, 1, 0, 0)));
float thetaS = Math::acos(Math::dot3(sunDir, Math::vec4(0, 1, 0, 0)));
Z = CalculateZenithLuminanceYxy(envState.skyTurbidity, thetaS);
Z.store(tickParams.Z);

Expand Down
2 changes: 1 addition & 1 deletion code/render/renderutil/geometryhelpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ GeometryHelpers::CreateDisk(SizeT numPoints)
for (int i = 0; i < numPoints + 1; i++)
{
Vertex v;
v.pos = Math::float3{ sin(i * 2 * N_PI / float(numPoints)) * 0.5f, cos(i * 2 * N_PI / float(numPoints)) * 0.5f, 0 };
v.pos = Math::float3{ Math::sin(i * 2 * N_PI / float(numPoints)) * 0.5f, Math::cos(i * 2 * N_PI / float(numPoints)) * 0.5f, 0};
v.uv = Math::float2{ 0, 0 };
vertices.Append(v);
indices.Append(i + 1);
Expand Down

0 comments on commit 61402b6

Please sign in to comment.