From 8f0837dd0970ce007e13018729ce2ddbc6f4eac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henri=20Hyyryl=C3=A4inen?= Date: Fri, 15 Mar 2019 19:31:22 +0200 Subject: [PATCH] Cleaned up the player sizing as bacteria and a few other places --- scripts/microbe_stage/configs.as | 3 +- .../microbe_editor/microbe_editor.as | 7 ++-- scripts/microbe_stage/microbe_operations.as | 30 ++++++++------ scripts/microbe_stage/organelle.as | 40 +++++++++---------- scripts/microbe_stage/species_system.as | 3 +- 5 files changed, 43 insertions(+), 40 deletions(-) diff --git a/scripts/microbe_stage/configs.as b/scripts/microbe_stage/configs.as index 138fd2aaa15..dd8c3369ca2 100644 --- a/scripts/microbe_stage/configs.as +++ b/scripts/microbe_stage/configs.as @@ -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)}, @@ -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) } diff --git a/scripts/microbe_stage/microbe_editor/microbe_editor.as b/scripts/microbe_stage/microbe_editor/microbe_editor.as index 47cf5b79bfc..60eefb21661 100644 --- a/scripts/microbe_stage/microbe_editor/microbe_editor.as +++ b/scripts/microbe_stage/microbe_editor/microbe_editor.as @@ -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; diff --git a/scripts/microbe_stage/microbe_operations.as b/scripts/microbe_stage/microbe_operations.as index f43a3fa57d8..ccb8f183af4 100644 --- a/scripts/microbe_stage/microbe_operations.as +++ b/scripts/microbe_stage/microbe_operations.as @@ -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) diff --git a/scripts/microbe_stage/organelle.as b/scripts/microbe_stage/organelle.as index 641b852e2ab..76c49fdde5d 100644 --- a/scripts/microbe_stage/organelle.as +++ b/scripts/microbe_stage/organelle.as @@ -679,24 +679,23 @@ 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"); @@ -704,6 +703,7 @@ class PlacedOrganelle : SpeciesStoredOrganelleType{ RenderNode@ renderNode; + // Graphics setup if(IsInGraphicalMode()){ organelleEntity = world.CreateEntity(); @@ -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(); @@ -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); } diff --git a/scripts/microbe_stage/species_system.as b/scripts/microbe_stage/species_system.as index a38d82b3b29..82c3d71e1bb 100644 --- a/scripts/microbe_stage/species_system.as +++ b/scripts/microbe_stage/species_system.as @@ -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; }