Skip to content

Commit

Permalink
renaming certain classes with pure static members to services
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Oct 28, 2023
1 parent 85fdc4f commit 670e358
Show file tree
Hide file tree
Showing 40 changed files with 298 additions and 298 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "AuxiliaryDataParser.h"
#include "AuxiliaryDataParserService.h"

#include "GeneralSettings.h"
#include "Settings.h"
Expand Down Expand Up @@ -883,28 +883,28 @@ namespace
}
}

boost::property_tree::ptree AuxiliaryDataParser::encodeAuxiliaryData(AuxiliaryData const& data)
boost::property_tree::ptree AuxiliaryDataParserService::encodeAuxiliaryData(AuxiliaryData const& data)
{
boost::property_tree::ptree tree;
encodeDecode(tree, const_cast<AuxiliaryData&>(data), ParserTask::Encode);
return tree;
}

AuxiliaryData AuxiliaryDataParser::decodeAuxiliaryData(boost::property_tree::ptree tree)
AuxiliaryData AuxiliaryDataParserService::decodeAuxiliaryData(boost::property_tree::ptree tree)
{
AuxiliaryData result;
encodeDecode(tree, result, ParserTask::Decode);
return result;
}

boost::property_tree::ptree AuxiliaryDataParser::encodeSimulationParameters(SimulationParameters const& data)
boost::property_tree::ptree AuxiliaryDataParserService::encodeSimulationParameters(SimulationParameters const& data)
{
boost::property_tree::ptree tree;
encodeDecode(tree, const_cast<SimulationParameters&>(data), ParserTask::Encode);
return tree;
}

SimulationParameters AuxiliaryDataParser::decodeSimulationParameters(boost::property_tree::ptree tree)
SimulationParameters AuxiliaryDataParserService::decodeSimulationParameters(boost::property_tree::ptree tree)
{
SimulationParameters result;
encodeDecode(tree, result, ParserTask::Decode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "AuxiliaryData.h"
#include "Definitions.h"

class AuxiliaryDataParser
class AuxiliaryDataParserService
{
public:
static boost::property_tree::ptree encodeAuxiliaryData(AuxiliaryData const& data);
Expand Down
16 changes: 8 additions & 8 deletions source/EngineInterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
add_library(alien_engine_interface_lib
ArraySizes.h
AuxiliaryData.h
AuxiliaryDataParser.cpp
AuxiliaryDataParser.h
AuxiliaryDataParserService.cpp
AuxiliaryDataParserService.h
CellFunctionConstants.h
Colors.h
Definitions.h
DescriptionHelper.cpp
DescriptionHelper.h
DescriptionEditService.cpp
DescriptionEditService.h
Descriptions.cpp
Descriptions.h
FundamentalConstants.h
GenomeConstants.h
GenomeDescriptionConverter.cpp
GenomeDescriptionConverter.h
GenomeDescriptionService.cpp
GenomeDescriptionService.h
GenomeDescriptions.h
GeneralSettings.h
GpuSettings.h
InspectedEntityIds.h
Motion.h
MutationType.h
OverlayDescriptions.h
PreviewDescriptionConverter.cpp
PreviewDescriptionConverter.h
PreviewDescriptionService.cpp
PreviewDescriptionService.h
PreviewDescriptions.h
RadiationSource.h
SelectionShallowData.h
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "DescriptionHelper.h"
#include "DescriptionEditService.h"

#include <cmath>
#include <boost/range/adaptor/indexed.hpp>
Expand All @@ -8,9 +8,9 @@
#include "Base/Math.h"
#include "GenomeDescriptions.h"
#include "SpaceCalculator.h"
#include "GenomeDescriptionConverter.h"
#include "GenomeDescriptionService.h"

DataDescription DescriptionHelper::createRect(CreateRectParameters const& parameters)
DataDescription DescriptionEditService::createRect(CreateRectParameters const& parameters)
{
DataDescription result;
auto creatureId = parameters._randomCreatureId ? toInt(NumberGenerator::getInstance().getRandomInt(std::numeric_limits<int>::max())) : 0;
Expand All @@ -35,7 +35,7 @@ DataDescription DescriptionHelper::createRect(CreateRectParameters const& parame
return result;
}

DataDescription DescriptionHelper::createHex(CreateHexParameters const& parameters)
DataDescription DescriptionEditService::createHex(CreateHexParameters const& parameters)
{
DataDescription result;
auto creatureId = parameters._randomCreatureId ? toInt(NumberGenerator::getInstance().getRandomInt(std::numeric_limits<int>::max())) : 0;
Expand Down Expand Up @@ -78,7 +78,7 @@ DataDescription DescriptionHelper::createHex(CreateHexParameters const& paramete
return result;
}

DataDescription DescriptionHelper::createUnconnectedCircle(CreateUnconnectedCircleParameters const& parameters)
DataDescription DescriptionEditService::createUnconnectedCircle(CreateUnconnectedCircleParameters const& parameters)
{
DataDescription result;
auto creatureId = parameters._randomCreatureId ? toInt(NumberGenerator::getInstance().getRandomInt(std::numeric_limits<int>::max())) : 0;
Expand Down Expand Up @@ -162,7 +162,7 @@ namespace
}
}

void DescriptionHelper::duplicate(ClusteredDataDescription& data, IntVector2D const& origSize, IntVector2D const& size)
void DescriptionEditService::duplicate(ClusteredDataDescription& data, IntVector2D const& origSize, IntVector2D const& size)
{
ClusteredDataDescription result;

Expand Down Expand Up @@ -232,7 +232,7 @@ namespace
}
}

DataDescription DescriptionHelper::gridMultiply(DataDescription const& input, GridMultiplyParameters const& parameters)
DataDescription DescriptionEditService::gridMultiply(DataDescription const& input, GridMultiplyParameters const& parameters)
{
DataDescription result;
auto clone = input;
Expand Down Expand Up @@ -261,7 +261,7 @@ DataDescription DescriptionHelper::gridMultiply(DataDescription const& input, Gr
return result;
}

DataDescription DescriptionHelper::randomMultiply(
DataDescription DescriptionEditService::randomMultiply(
DataDescription const& input,
RandomMultiplyParameters const& parameters,
IntVector2D const& worldSize,
Expand Down Expand Up @@ -334,7 +334,7 @@ DataDescription DescriptionHelper::randomMultiply(
return result;
}

void DescriptionHelper::addIfSpaceAvailable(
void DescriptionEditService::addIfSpaceAvailable(
DataDescription& result,
Occupancy& cellOccupancy,
DataDescription const& toAdd,
Expand All @@ -351,7 +351,7 @@ void DescriptionHelper::addIfSpaceAvailable(
}
}

void DescriptionHelper::reconnectCells(DataDescription& data, float maxDistance)
void DescriptionEditService::reconnectCells(DataDescription& data, float maxDistance)
{
std::unordered_map<int, std::unordered_map<int, std::vector<int>>> cellIndicesBySlot;

Expand All @@ -378,14 +378,14 @@ void DescriptionHelper::reconnectCells(DataDescription& data, float maxDistance)
}
}

void DescriptionHelper::removeStickiness(DataDescription& data)
void DescriptionEditService::removeStickiness(DataDescription& data)
{
for (auto& cell : data.cells) {
cell.maxConnections = toInt(cell.connections.size());
}
}

void DescriptionHelper::correctConnections(ClusteredDataDescription& data, IntVector2D const& worldSize)
void DescriptionEditService::correctConnections(ClusteredDataDescription& data, IntVector2D const& worldSize)
{
auto threshold = std::min(worldSize.x, worldSize.y) /3;
std::unordered_map<uint64_t, CellDescription&> cellById;
Expand Down Expand Up @@ -416,7 +416,7 @@ void DescriptionHelper::correctConnections(ClusteredDataDescription& data, IntVe
}
}

void DescriptionHelper::randomizeCellColors(ClusteredDataDescription& data, std::vector<int> const& colorCodes)
void DescriptionEditService::randomizeCellColors(ClusteredDataDescription& data, std::vector<int> const& colorCodes)
{
for (auto& cluster : data.clusters) {
auto newColor = colorCodes[NumberGenerator::getInstance().getRandomInt(toInt(colorCodes.size()))];
Expand All @@ -430,18 +430,18 @@ namespace
{
void colorizeGenomeNodes(std::vector<uint8_t>& genome, int color)
{
auto desc = GenomeDescriptionConverter::convertBytesToDescription(genome);
auto desc = GenomeDescriptionService::convertBytesToDescription(genome);
for (auto& node : desc.cells) {
node.color = color;
if (node.hasGenome()) {
colorizeGenomeNodes(node.getGenomeRef(), color);
}
}
genome = GenomeDescriptionConverter::convertDescriptionToBytes(desc);
genome = GenomeDescriptionService::convertDescriptionToBytes(desc);
}
}

void DescriptionHelper::randomizeGenomeColors(ClusteredDataDescription& data, std::vector<int> const& colorCodes)
void DescriptionEditService::randomizeGenomeColors(ClusteredDataDescription& data, std::vector<int> const& colorCodes)
{
for (auto& cluster : data.clusters) {
auto newColor = colorCodes[NumberGenerator::getInstance().getRandomInt(toInt(colorCodes.size()))];
Expand All @@ -453,7 +453,7 @@ void DescriptionHelper::randomizeGenomeColors(ClusteredDataDescription& data, st
}
}

void DescriptionHelper::randomizeEnergies(ClusteredDataDescription& data, float minEnergy, float maxEnergy)
void DescriptionEditService::randomizeEnergies(ClusteredDataDescription& data, float minEnergy, float maxEnergy)
{
for (auto& cluster : data.clusters) {
auto energy = NumberGenerator::getInstance().getRandomReal(toDouble(minEnergy), toDouble(maxEnergy));
Expand All @@ -463,7 +463,7 @@ void DescriptionHelper::randomizeEnergies(ClusteredDataDescription& data, float
}
}

void DescriptionHelper::randomizeAges(ClusteredDataDescription& data, int minAge, int maxAge)
void DescriptionEditService::randomizeAges(ClusteredDataDescription& data, int minAge, int maxAge)
{
for (auto& cluster : data.clusters) {
auto age = NumberGenerator::getInstance().getRandomReal(toDouble(minAge), toDouble(maxAge));
Expand All @@ -473,7 +473,7 @@ void DescriptionHelper::randomizeAges(ClusteredDataDescription& data, int minAge
}
}

void DescriptionHelper::randomizeCountdowns(ClusteredDataDescription& data, int minValue, int maxValue)
void DescriptionEditService::randomizeCountdowns(ClusteredDataDescription& data, int minValue, int maxValue)
{
for (auto& cluster : data.clusters) {
auto countdown = NumberGenerator::getInstance().getRandomReal(toDouble(minValue), toDouble(maxValue));
Expand All @@ -485,7 +485,7 @@ void DescriptionHelper::randomizeCountdowns(ClusteredDataDescription& data, int
}
}

void DescriptionHelper::generateExecutionOrderNumbers(DataDescription& data, std::unordered_set<uint64_t> const& cellIds, int maxBranchNumbers)
void DescriptionEditService::generateExecutionOrderNumbers(DataDescription& data, std::unordered_set<uint64_t> const& cellIds, int maxBranchNumbers)
{
std::unordered_map<uint64_t, int> idToIndexMap;
for (auto const& [index, cell] : data.cells | boost::adaptors::indexed(0)) {
Expand Down Expand Up @@ -536,7 +536,7 @@ void DescriptionHelper::generateExecutionOrderNumbers(DataDescription& data, std
} while (origNumVisitedCells != visitedCellIds.size());
}

void DescriptionHelper::removeMetadata(DataDescription& data)
void DescriptionEditService::removeMetadata(DataDescription& data)
{
for(auto& cell : data.cells) {
removeMetadata(cell);
Expand All @@ -562,7 +562,7 @@ namespace

}

void DescriptionHelper::generateNewCreatureIds(DataDescription& data)
void DescriptionEditService::generateNewCreatureIds(DataDescription& data)
{
std::unordered_map<int, int> origToNewCreatureIdMap;
for (auto& cell : data.cells) {
Expand All @@ -576,7 +576,7 @@ void DescriptionHelper::generateNewCreatureIds(DataDescription& data)
}
}

void DescriptionHelper::generateNewCreatureIds(ClusteredDataDescription& data)
void DescriptionEditService::generateNewCreatureIds(ClusteredDataDescription& data)
{
std::unordered_map<int, int> origToNewCreatureIdMap;
for (auto& cluster: data.clusters) {
Expand All @@ -593,13 +593,13 @@ void DescriptionHelper::generateNewCreatureIds(ClusteredDataDescription& data)
}


void DescriptionHelper::removeMetadata(CellDescription& cell)
void DescriptionEditService::removeMetadata(CellDescription& cell)
{
cell.metadata.description.clear();
cell.metadata.name.clear();
}

bool DescriptionHelper::isCellPresent(Occupancy const& cellPosBySlot, SpaceCalculator const& spaceCalculator, RealVector2D const& posToCheck, float distance)
bool DescriptionEditService::isCellPresent(Occupancy const& cellPosBySlot, SpaceCalculator const& spaceCalculator, RealVector2D const& posToCheck, float distance)
{
auto intPos = toIntVector2D(posToCheck);

Expand Down Expand Up @@ -632,23 +632,23 @@ bool DescriptionHelper::isCellPresent(Occupancy const& cellPosBySlot, SpaceCalcu
return false;
}

uint64_t DescriptionHelper::getId(CellOrParticleDescription const& entity)
uint64_t DescriptionEditService::getId(CellOrParticleDescription const& entity)
{
if (std::holds_alternative<CellDescription>(entity)) {
return std::get<CellDescription>(entity).id;
}
return std::get<ParticleDescription>(entity).id;
}

RealVector2D DescriptionHelper::getPos(CellOrParticleDescription const& entity)
RealVector2D DescriptionEditService::getPos(CellOrParticleDescription const& entity)
{
if (std::holds_alternative<CellDescription>(entity)) {
return std::get<CellDescription>(entity).pos;
}
return std::get<ParticleDescription>(entity).pos;
}

std::vector<CellOrParticleDescription> DescriptionHelper::getObjects(
std::vector<CellOrParticleDescription> DescriptionEditService::getObjects(
DataDescription const& data)
{
std::vector<CellOrParticleDescription> result;
Expand Down Expand Up @@ -685,7 +685,7 @@ namespace
}
}

std::vector<CellOrParticleDescription> DescriptionHelper::getConstructorToMainGenomes(DataDescription const& data)
std::vector<CellOrParticleDescription> DescriptionEditService::getConstructorToMainGenomes(DataDescription const& data)
{
std::map<std::vector<uint8_t>, size_t> genomeToCellIndex;
for (auto const& [index, cell] : data.cells | boost::adaptors::indexed(0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "Base/Definitions.h"
#include "Descriptions.h"

class DescriptionHelper
class DescriptionEditService
{
public:
struct CreateRectParameters
Expand Down
6 changes: 3 additions & 3 deletions source/EngineInterface/Descriptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

#include <boost/range/adaptors.hpp>

#include "GenomeDescriptionConverter.h"
#include "GenomeDescriptionService.h"
#include "Base/Math.h"
#include "Base/Physics.h"

ConstructorDescription::ConstructorDescription()
{
genome = GenomeDescriptionConverter::convertDescriptionToBytes(GenomeDescription());
genome = GenomeDescriptionService::convertDescriptionToBytes(GenomeDescription());
}

InjectorDescription::InjectorDescription()
{
genome = GenomeDescriptionConverter::convertDescriptionToBytes(GenomeDescription());
genome = GenomeDescriptionService::convertDescriptionToBytes(GenomeDescription());
}

CellFunction CellDescription::getCellFunctionType() const
Expand Down
Loading

0 comments on commit 670e358

Please sign in to comment.