Skip to content

Commit

Permalink
ThriveServer can now be started and shutdown without segfaulting
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyyrylainen committed Dec 4, 2018
1 parent 7f0f7ee commit f1f2b19
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 28 deletions.
2 changes: 1 addition & 1 deletion SetupThrive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def parseExtraArgs
leviathan = Leviathan.new(
# Use this if you always want the latest commit
# version: "develop",
version: "e6c7f7f82be32fe48f92c11a21d91d4fde44da1a",
version: "5f3f3d1b3ef74b27f3ae7e1fb5f32a740dfcd813",
# Doesn't actually work, but leviathan doesn't install with sudo by
# default, or install at all for that matter
noInstallSudo: true
Expand Down
25 changes: 25 additions & 0 deletions scripts/microbe_stage/setup.as
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ void setupScriptsForWorld(CellStageWorld@ world)
setupSpawnSystem(world);
}

//! Server variant of setupScriptsForWorld
void setupScriptsForWorld_Server(CellStageWorld@ world)
{
setupSpecies(world);
setupSystemsForWorld_Server(world);
// setupSpawnSystem_Server(world);
}

// This function should be the entry point for all player initial-species generation
// For now, it can go through the XML and instantiate all the species, but later this
// would be all procedural.
Expand Down Expand Up @@ -75,6 +83,23 @@ void setupSystemsForWorld(CellStageWorld@ world)
world.RegisterScriptSystem("MicrobeAISystem", MicrobeAISystem());
}

//! Server variant of setupSystemsForWorld
void setupSystemsForWorld_Server(CellStageWorld@ world)
{
// Fail if compound registry is empty //
assert(SimulationParameters::compoundRegistry().getSize() > 0,
"Compound registry is empty");

world.RegisterScriptComponentType("MicrobeComponent", @MicrobeComponentFactory);
world.RegisterScriptComponentType("MicrobeAIControllerComponent",
@MicrobeAIControllerComponentFactory);

// Add any new systems and component types that are defined in scripts here
world.RegisterScriptSystem("MicrobeSystem", MicrobeSystem());
world.RegisterScriptSystem("SpeciesSystem", SpeciesSystem());
world.RegisterScriptSystem("MicrobeAISystem", MicrobeAISystem());
}


//! This spawns the player
void setupPlayer(CellStageWorld@ world)
Expand Down
48 changes: 33 additions & 15 deletions src/microbe_stage/compound_cloud_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ void
{
m_position = newPosition;

m_sceneNode->setPosition(m_position.X, CLOUD_Y_COORDINATE, m_position.Z);
// This check is for non-graphical mode
if(m_sceneNode)
m_sceneNode->setPosition(
m_position.X, CLOUD_Y_COORDINATE, m_position.Z);

// Clear data. Maybe there is a faster way
for(size_t x = 0; x < m_density1.size(); ++x) {
Expand Down Expand Up @@ -317,6 +320,9 @@ void
// field.
createVelocityField();

// Skip if no graphics
if(!Ogre::Root::getSingletonPtr())
return;

// Create a background plane on which the fluid clouds will be drawn.
Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 1.0);
Expand Down Expand Up @@ -363,6 +369,10 @@ void
world.DestroyEntity(m_managedClouds.begin()->first);
}

// Skip if no graphics
if(!Ogre::Root::getSingletonPtr())
return;

// Destroy the shared mesh
Ogre::MeshManager::getSingleton().remove(m_planeMesh);
}
Expand Down Expand Up @@ -831,18 +841,6 @@ void
{
LOG_INFO("Initializing a new compound cloud entity");

// Create where the eventually created plane object will be attached
cloud.m_sceneNode = scene->getRootSceneNode()->createChildSceneNode();

// set the position properly
cloud.m_sceneNode->setPosition(
cloud.m_position.X, CLOUD_Y_COORDINATE, cloud.m_position.Z);

// Because of the way Ogre generates the UVs for a plane we need to rotate
// the plane to match up with world coordinates
cloud.m_sceneNode->setOrientation(
Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3::UNIT_Y));

// All the densities
if(cloud.m_compoundId1 != NULL_COMPOUND) {
cloud.m_density1.resize(CLOUD_SIMULATION_WIDTH,
Expand All @@ -869,6 +867,24 @@ void
std::vector<float>(CLOUD_SIMULATION_HEIGHT, 0));
}

cloud.m_initialized = true;

// Skip if no graphics
if(!Ogre::Root::getSingletonPtr())
return;

// Create where the eventually created plane object will be attached
cloud.m_sceneNode = scene->getRootSceneNode()->createChildSceneNode();

// set the position properly
cloud.m_sceneNode->setPosition(
cloud.m_position.X, CLOUD_Y_COORDINATE, cloud.m_position.Z);

// Because of the way Ogre generates the UVs for a plane we need to rotate
// the plane to match up with world coordinates
cloud.m_sceneNode->setOrientation(
Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3::UNIT_Y));

// Create a modified material that uses
cloud.m_planeMaterial = Ogre::MaterialManager::getSingleton().create(
cloud.m_textureName + "_material", "Generated");
Expand Down Expand Up @@ -981,8 +997,6 @@ void
// currently initializing one so it is fine
cloud.m_compoundCloudsPlane->setMaterialName(
cloud.m_planeMaterial->getName());

cloud.m_initialized = true;
}
// ------------------------------------ //
void
Expand Down Expand Up @@ -1032,6 +1046,10 @@ void
advect(cloud.m_oldDens4, cloud.m_density4, renderTime);
}

// No graphics check
if(!cloud.m_texture)
return;

// Store the pixel data in a hardware buffer for quick access.
auto pixelBuffer = cloud.m_texture->getBuffer();

Expand Down
16 changes: 4 additions & 12 deletions src/server/ThriveServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ class ThriveServer::Implementation {
std::shared_ptr<CellStageWorld> m_cellStage;
// std::shared_ptr<MicrobeEditorWorld> m_microbeEditor;

// This contains all the microbe_stage AngelScript code
Leviathan::GameModule::pointer m_microbeScripts;

// This is "temporarily" merged with the microbe scripts as this needs to
// share some types
// // This contains all the microbe_editor AngelScript code
// Leviathan::GameModule::pointer m_MicrobeEditorScripts;

// std::shared_ptr<PlayerMicrobeControl> m_cellStageKeys;
};

Expand All @@ -64,7 +56,7 @@ ThriveServer::~ThriveServer()
std::string
ThriveServer::GenerateWindowTitle()
{
return "Thrive " GAME_VERSIONS;
return "Thrive Server " GAME_VERSIONS;
}

ThriveServer*
Expand Down Expand Up @@ -137,14 +129,14 @@ void
// Let the script do setup //
// This registers all the script defined systems to run and be
// available from the world
LEVIATHAN_ASSERT(m_impl->m_microbeScripts, "microbe scripts not loaded");
LEVIATHAN_ASSERT(getMicrobeScripts(), "microbe scripts not loaded");

LOG_INFO("Calling world setup script setupScriptsForWorld_Server");

ScriptRunningSetup setup;
setup.SetEntrypoint("setupScriptsForWorld_Server");

auto result = m_impl->m_microbeScripts->ExecuteOnModule<void>(
auto result = getMicrobeScripts()->ExecuteOnModule<void>(
setup, false, m_impl->m_cellStage.get());

if(result.Result != SCRIPT_RUN_RESULT::Success) {
Expand All @@ -160,7 +152,7 @@ void
// // Spawn player //
// setup = ScriptRunningSetup("setupPlayer");

// result = m_impl->m_microbeScripts->ExecuteOnModule<void>(
// result = getMicrobeScripts()->ExecuteOnModule<void>(
// setup, false, m_impl->m_cellStage.get());

// if(result.Result != SCRIPT_RUN_RESULT::Success) {
Expand Down

0 comments on commit f1f2b19

Please sign in to comment.