forked from Revolutionary-Games/Thrive
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
1e2dc67
commit 87dad48
Showing
3 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |