Skip to content

Commit

Permalink
Cleaned up the player sizing as bacteria and a few other places
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyyrylainen committed Mar 15, 2019
1 parent 7c93617 commit 8f0837d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 40 deletions.
3 changes: 2 additions & 1 deletion scripts/microbe_stage/configs.as
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ const dictionary STARTER_MICROBES = {
"Default",
MicrobeTemplate(1/14000,
{
//for testing
// For testing
{"atp", InitialCompound(60)},
{"glucose", InitialCompound(60)},
{"ammonia", InitialCompound(0)},
Expand All @@ -360,6 +360,7 @@ const dictionary STARTER_MICROBES = {
OrganelleTemplatePlaced("cytoplasm", 0, 0, 0)
},
Float4(1, 1, 1, 1),
// Player starts as bacteria
true,
MEMBRANE_TYPE::MEMBRANE)
}
Expand Down
7 changes: 3 additions & 4 deletions scripts/microbe_stage/microbe_editor/microbe_editor.as
Original file line number Diff line number Diff line change
Expand Up @@ -963,16 +963,15 @@ class MicrobeEditor{

templateOrganelles = newOrganelles;

// Grab render of player cell
// Grab render node of player cell
auto node = world.GetComponent_RenderNode(player);

//! Change player species cell size depending on presence or not of nucleus
// Change player species cell size depending on whether they are a bacteria or not
if(checkIsNucleusPresent()) {
playerSpecies.isBacteria = false;
node.Scale = Float3(1.0, 1.0, 1.0);
node.Marked = true;
}
else {
} else {
playerSpecies.isBacteria = true;
node.Scale = Float3(0.5, 0.5, 0.5);
node.Marked = true;
Expand Down
30 changes: 17 additions & 13 deletions scripts/microbe_stage/microbe_operations.as
Original file line number Diff line number Diff line change
Expand Up @@ -679,35 +679,39 @@ void emitAgent(CellStageWorld@ world, ObjectID microbeEntity, CompoundId compoun
}
}

void playSoundWithDistance(CellStageWorld@ world, const string &in soundPath, ObjectID microbeEntity)
{
void playSoundWithDistance(CellStageWorld@ world, const string &in soundPath,
ObjectID microbeEntity)
{
auto location = world.GetComponent_Position(microbeEntity)._Position;
auto playerEntity = GetThriveGame().playerData().activeCreature();

Position@ thisPosition = world.GetComponent_Position(playerEntity);
MicrobeComponent@ microbeComponent = getMicrobeComponent(world, microbeEntity);

// Length is squared so also square the variable we are dividing
float thisVolume = 1000.0f/(sqrt(((thisPosition._Position-location).LengthSquared()))+1);
float soundVolume = thisVolume;

// Play sound
if (@microbeComponent.otherAudio is null ||
if (microbeComponent.otherAudio is null ||
!microbeComponent.otherAudio.Get().isPlaying())
{
@microbeComponent.otherAudio = GetEngine().GetSoundDevice().Play2DSound(
{
@microbeComponent.otherAudio = GetEngine().GetSoundDevice().Play2DSound(
soundPath, false, true);
if(microbeComponent.otherAudio !is null){
if(microbeComponent.otherAudio.HasInternalSource()){
microbeComponent.otherAudio.Get().setVolume(soundVolume);
microbeComponent.otherAudio.Get().play();
} else {
LOG_ERROR("Created sound player doesn't have internal "
"sound source");
}
microbeComponent.otherAudio.Get().setVolume(soundVolume);
microbeComponent.otherAudio.Get().play();
} else {
//this was happening so often it caused lag
//LOG_ERROR("Failed to create sound player");
LOG_ERROR("Created sound player doesn't have internal "
"sound source");
}
} else {
//this was happening so often it caused lag
//LOG_ERROR("Failed to create sound player");
}
}
}

// Default version of toggleEngulfMode that takes ObjectID
void toggleEngulfMode(CellStageWorld@ world, ObjectID microbeEntity)
Expand Down
40 changes: 19 additions & 21 deletions scripts/microbe_stage/organelle.as
Original file line number Diff line number Diff line change
Expand Up @@ -679,31 +679,31 @@ class PlacedOrganelle : SpeciesStoredOrganelleType{

microbeEntity = microbe;

bool bacteria = false;

// This should be the only species check any organelle ever makes.
auto species = MicrobeOperations::getSpeciesComponent(world, microbeEntity);
if (species !is null){
this.speciesColour = species.colour;
bacteria = species.isBacteria;
}
// Our coordinates are already set when this is called
// so just cache this
this.cartesianPosition = Hex::axialToCartesian(q, r);

// Calculate hexSize depending if species is baceteria or not
// Scaling parameters that we need to scale
double hexSize = 0;
if(species.isBacteria) {
this.cartesianPosition /= 2;
hexSize = 0.375;
}
else
hexSize = HEX_SIZE;
float hexSize = HEX_SIZE;

// Scale the hex size down for bacteria
if(bacteria)
hexSize /= 2.f;

assert(organelleEntity == NULL_OBJECT, "PlacedOrganelle already had an entity");

Float3 offset = organelle.calculateCenterOffset();

RenderNode@ renderNode;

// Graphics setup
if(IsInGraphicalMode()){

organelleEntity = world.CreateEntity();
Expand All @@ -719,17 +719,17 @@ class PlacedOrganelle : SpeciesStoredOrganelleType{
@renderNode = world.Create_RenderNode(organelleEntity);
renderNode.Scale = Float3(HEX_SIZE, HEX_SIZE, HEX_SIZE);
renderNode.Marked = true;
}

// For performance reasons we set the position here directly
// instead of with the position system
renderNode.Node.setPosition(offset + this.cartesianPosition);
// TODO: this MUST BE moved to the mesh file. Otherwise this mess will grow over time
//maybe instead of changing this here we should do so in the generation routine.
renderNode.Node.setOrientation(Ogre::Quaternion(Ogre::Degree(90),
// For performance reasons we set the position here directly
// instead of with the position system
renderNode.Node.setPosition(offset + this.cartesianPosition);

renderNode.Node.setOrientation(Ogre::Quaternion(Ogre::Degree(90),
Ogre::Vector3(1, 0, 0)) * Ogre::Quaternion(Ogre::Degree(180),
Ogre::Vector3(0, 1, 0)) * Ogre::Quaternion(Ogre::Degree(rotation),
Ogre::Vector3(0, 0, 1)));
}

// Add hex collision shapes
auto hexes = organelle.getHexes();

Expand All @@ -740,14 +740,12 @@ class PlacedOrganelle : SpeciesStoredOrganelleType{
// Also add our offset to the hex offset
Float3 translation = Hex::axialToCartesian(hex.q, hex.r) + this.cartesianPosition;

// Create the matrix with the offset
Ogre::Matrix4 hexFinalOffset(translation);
// Scale for bacteria physics. This might be pretty expensive to be in this loop...
if(bacteria)
translation /= 2.f;

PhysicsShape@ hexCollision = world.GetPhysicalWorld().CreateSphere(hexSize * 2);

if(hexCollision is null)
assert(false, "Failed to create Sphere for hex");

collisionShape.AddChildShape(hexCollision, translation);
_addedCollisions.insertLast(hexCollision);
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/microbe_stage/species_system.as
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,8 @@ void restoreOrganelleLayout(CellStageWorld@ world, ObjectID microbeEntity,
MicrobeOperations::addOrganelle(world, microbeEntity, organelle, editShape);
}

// cache isBacteria from species
// Cache isBacteria from species. This can be changed depending on
// the added organelles in the editor
microbeComponent.isBacteria = species.isBacteria;
}

Expand Down

0 comments on commit 8f0837d

Please sign in to comment.