Skip to content

Commit

Permalink
Added health variable to membrane that adds damage effects
Browse files Browse the repository at this point in the history
c++ and scripts side

This should be pretty much it really on the code, the rest is just shader work

removing silly tabs

Appeasing the clang-format gods

Doing the suggested changes

cLaNG fOrMaT
  • Loading branch information
crodnu authored and hhyyrylainen committed Mar 1, 2019
1 parent 756b3e8 commit e02efe3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
8 changes: 7 additions & 1 deletion scripts/microbe_stage/microbe.as
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class MicrobeComponent : ScriptComponent{

// TODO: initialize
float hitpoints = DEFAULT_HEALTH;
float previousHitpoints = DEFAULT_HEALTH;
float maxHitpoints = DEFAULT_HEALTH;
bool dead = false;
uint deathTimer = 0;
Expand Down Expand Up @@ -381,7 +382,7 @@ class MicrobeSystem : ScriptSystem{
atpDamage(microbeEntity);
}

// Handle hitpoints
// Handle hitpoints
if((microbeComponent.hitpoints < microbeComponent.maxHitpoints))
{
if(MicrobeOperations::getCompoundAmount(world, microbeEntity,
Expand Down Expand Up @@ -504,6 +505,11 @@ class MicrobeSystem : ScriptSystem{
applyCellMovement(components, logicTime);

compoundAbsorberComponent.setAbsorbtionCapacity(microbeComponent.capacity);

if(microbeComponent.hitpoints != microbeComponent.previousHitpoints)
membraneComponent.setHealthFraction(microbeComponent.hitpoints / microbeComponent.maxHitpoints);

microbeComponent.previousHitpoints = microbeComponent.hitpoints;
}

private void updateDeadCell(MicrobeSystemCached@ &in components, uint logicTime)
Expand Down
28 changes: 26 additions & 2 deletions src/microbe_stage/membrane_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <OgreTechnique.h>
#include <OgreTextureUnitState.h>

#include <algorithm>
#include <atomic>

using namespace thrive;
Expand Down Expand Up @@ -198,10 +199,21 @@ void
->getPass(0)
->getFragmentProgramParameters()
->setNamedConstant("membraneColour", colour);
coloredMaterial->compile();
}
}

void
MembraneComponent::setHealthFraction(float value)
{
healthFraction = std::clamp(value, 0.0f, 1.0f);

// If we already have created a material we need to re-apply it
if(coloredMaterial) {
coloredMaterial->getTechnique(0)
->getPass(0)
->getTextureUnitState(0)
->setHardwareGammaEnabled(true);
->getFragmentProgramParameters()
->setNamedConstant("healthPercentage", healthFraction);
coloredMaterial->compile();
}
}
Expand Down Expand Up @@ -326,6 +338,18 @@ void
->getPass(0)
->getFragmentProgramParameters()
->setNamedConstant("membraneColour", colour);

coloredMaterial->getTechnique(0)
->getPass(0)
->getFragmentProgramParameters()
->setNamedConstant("healthPercentage", healthFraction);
coloredMaterial->compile();

coloredMaterial->getTechnique(0)
->getPass(0)
->getTextureUnitState(0)
->setHardwareGammaEnabled(true);

coloredMaterial->compile();
}

Expand Down
8 changes: 8 additions & 0 deletions src/microbe_stage/membrane_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class MembraneComponent : public Leviathan::Component {
void
setColour(const Float4& value);

//! Should set the health percentage.
void
setHealthFraction(float value);

//! Returns the last set colour
Float4
getColour() const;
Expand Down Expand Up @@ -213,6 +217,10 @@ class MembraneComponent : public Leviathan::Component {
//! The amount of compounds stored in the membrane.
int compoundAmount = 0;

// The health percentage of a cell, in the range [0.0, 1.0], used to get
// damage effects in the membrane.
float healthFraction = 1.0;

private:
};

Expand Down
7 changes: 7 additions & 0 deletions src/scripting/script_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,13 @@ bool
ANGELSCRIPT_REGISTERFAIL;
}

if(engine->RegisterObjectMethod("MembraneComponent",
"void setHealthFraction(float value)",
asMETHOD(MembraneComponent, setHealthFraction),
asCALL_THISCALL) < 0) {
ANGELSCRIPT_REGISTERFAIL;
}


if(engine->RegisterEnum("MEMBRANE_TYPE") < 0) {
ANGELSCRIPT_REGISTERFAIL;
Expand Down

0 comments on commit e02efe3

Please sign in to comment.