Skip to content

Commit

Permalink
Started implementing CompoundVenterSystem and CompoundVenterComponent
Browse files Browse the repository at this point in the history
ran clang format

Continued work on compoundVenterSystem and component

CompoundVenter now also uses position components

Position component is now deleted properly when the venter is deleted

Compound venter system now uses cell stage world
  • Loading branch information
Untrustedlife authored and hhyyrylainen committed Feb 15, 2019
1 parent 1e2dc67 commit 87dad48
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/engine/component_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum class THRIVE_COMPONENT : uint16_t {
ABSORBER,
TIMED_LIFE,
PROPERTIES,
COMPOUND_VENTER,

// TODO: check is this needed for anything
// INVALID
Expand Down
43 changes: 43 additions & 0 deletions src/microbe_stage/compound_venter_system.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>

#include "engine/serialization.h"

#include "general/thrive_math.h"
#include "simulation_parameters.h"

#include "microbe_stage/compound_venter_system.h"
#include "microbe_stage/process_system.h"

#include "generated/cell_stage_world.h"
#include <Entities/GameWorld.h>

using namespace thrive;

void
CompoundVenterSystem::Run(CellStageWorld& world)
{
if(!world.GetNetworkSettings().IsAuthoritative)
return;

for(auto& value : CachedComponents.GetIndex()) {

CompoundBagComponent& bag = std::get<0>(*value.second);
CompoundVenterComponent& venter = std::get<1>(*value.second);
Leviathan::Position& position = std::get<2>(*value.second);

venter.ventCompound(position,
SimulationParameters::compoundRegistry.getTypeId("iron"), world);
}
}

void
CompoundVenterComponent::ventCompound(Leviathan::Position& pos,
CompoundId compound,
CellStageWorld& world)
{
world.GetCompoundCloudSystem().addCloud(
compound, 15000, pos.Members._Position);
}
84 changes: 84 additions & 0 deletions src/microbe_stage/compound_venter_system.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#pragma once
#include "engine/component_types.h"
#include "engine/typedefs.h"

#include <Entities/Component.h>
#include <Entities/System.h>
//#include <Entities/Components.h>
#include "process_system.h"
#include <unordered_map>
#include <vector>

namespace Leviathan {
class GameWorld;
}

namespace thrive {

class CellStageWorld;
class CompoundVenterComponent : public Leviathan::Component {
public:
CompoundVenterComponent();

double storageSpace;
double storageSpaceOccupied;
float x, y;

REFERENCE_HANDLE_UNCOUNTED_TYPE(CompoundVenterComponent);

static constexpr auto TYPE =
componentTypeConvert(THRIVE_COMPONENT::COMPOUND_VENTER);

void
ventCompound(Leviathan::Position& pos,
CompoundId ourCompound,
CellStageWorld& world);
};

class CompoundVenterSystem
: public Leviathan::System<std::tuple<CompoundBagComponent&,
CompoundVenterComponent&,
Leviathan::Position&>> {
public:
/**
* @brief Updates the system
* @todo Make it releases a specific amount of compounds each second
*/
void
Run(CellStageWorld& world);

void
CreateNodes(
const std::vector<std::tuple<CompoundBagComponent*, ObjectID>>&
firstdata,
const std::vector<std::tuple<CompoundVenterComponent*, ObjectID>>&
seconddata,
const std::vector<std::tuple<Leviathan::Position*, ObjectID>>&
thirdData,
const ComponentHolder<CompoundBagComponent>& firstholder,
const ComponentHolder<CompoundVenterComponent>& secondholder,
const ComponentHolder<Leviathan::Position>& thirdHolder)
{
TupleCachedComponentCollectionHelper(CachedComponents, firstdata,
seconddata, thirdData, firstholder, secondholder, thirdHolder);
}

void
DestroyNodes(
const std::vector<std::tuple<CompoundBagComponent*, ObjectID>>&
firstdata,
const std::vector<std::tuple<CompoundVenterComponent*, ObjectID>>&
seconddata,
const std::vector<std::tuple<Leviathan::Position*, ObjectID>>&
thirdData)
{
CachedComponents.RemoveBasedOnKeyTupleList(firstdata);
CachedComponents.RemoveBasedOnKeyTupleList(seconddata);
CachedComponents.RemoveBasedOnKeyTupleList(thirdData);
}

protected:
private:
static constexpr double TIME_SCALING_FACTOR = 1000;
};
} // namespace thrive

0 comments on commit 87dad48

Please sign in to comment.