From 87dad48129f66ca85635143e90647a82e15002e2 Mon Sep 17 00:00:00 2001 From: Untrustedlife Date: Tue, 5 Feb 2019 15:48:38 -0600 Subject: [PATCH] Started implementing CompoundVenterSystem and CompoundVenterComponent 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 --- src/engine/component_types.h | 1 + src/microbe_stage/compound_venter_system.cpp | 43 ++++++++++ src/microbe_stage/compound_venter_system.h | 84 ++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 src/microbe_stage/compound_venter_system.cpp create mode 100644 src/microbe_stage/compound_venter_system.h diff --git a/src/engine/component_types.h b/src/engine/component_types.h index 6f5c0b949c8..5311d147e6f 100644 --- a/src/engine/component_types.h +++ b/src/engine/component_types.h @@ -21,6 +21,7 @@ enum class THRIVE_COMPONENT : uint16_t { ABSORBER, TIMED_LIFE, PROPERTIES, + COMPOUND_VENTER, // TODO: check is this needed for anything // INVALID diff --git a/src/microbe_stage/compound_venter_system.cpp b/src/microbe_stage/compound_venter_system.cpp new file mode 100644 index 00000000000..1fe8dd05277 --- /dev/null +++ b/src/microbe_stage/compound_venter_system.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include + +#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 + +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); +} \ No newline at end of file diff --git a/src/microbe_stage/compound_venter_system.h b/src/microbe_stage/compound_venter_system.h new file mode 100644 index 00000000000..90f65695b7f --- /dev/null +++ b/src/microbe_stage/compound_venter_system.h @@ -0,0 +1,84 @@ +#pragma once +#include "engine/component_types.h" +#include "engine/typedefs.h" + +#include +#include +//#include +#include "process_system.h" +#include +#include + +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> { +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>& + firstdata, + const std::vector>& + seconddata, + const std::vector>& + thirdData, + const ComponentHolder& firstholder, + const ComponentHolder& secondholder, + const ComponentHolder& thirdHolder) + { + TupleCachedComponentCollectionHelper(CachedComponents, firstdata, + seconddata, thirdData, firstholder, secondholder, thirdHolder); + } + + void + DestroyNodes( + const std::vector>& + firstdata, + const std::vector>& + seconddata, + const std::vector>& + thirdData) + { + CachedComponents.RemoveBasedOnKeyTupleList(firstdata); + CachedComponents.RemoveBasedOnKeyTupleList(seconddata); + CachedComponents.RemoveBasedOnKeyTupleList(thirdData); + } + +protected: +private: + static constexpr double TIME_SCALING_FACTOR = 1000; +}; +} // namespace thrive \ No newline at end of file