#pragma once #include #include #include #include "BiomGenerator.h" #include "CaveGenerator.h" #include "Chunk.h" #include "JNoise.h" #include "JsonExpression.h" class DimensionGenerator; class WorldHeightLayer : public virtual Framework::ReferenceCounter { private: Framework::JSON::JSONObject* noiseConfig; Noise* noise; Framework::Text name; JFloatExpression* value; public: WorldHeightLayer(); ~WorldHeightLayer(); void initialize(JExpressionMemory* zMemory); void calculateValue(JExpressionMemory* zMemory); void setNoiseConfig(Framework::JSON::JSONObject* noiseConfig); Framework::JSON::JSONObject* zNoiseConfig() const; void setName(Framework::Text name); Framework::Text getName() const; void setValue(JFloatExpression* value); JFloatExpression* zValue() const; }; class WorldHeightLayerFactory : public TypeFactory { public: WorldHeightLayerFactory(); WorldHeightLayer* createValue( Framework::JSON::JSONObject* zJson) const override; void fromJson(WorldHeightLayer* zResult, Framework::JSON::JSONObject* zJson) const override; void toJson(WorldHeightLayer* zObject, Framework::JSON::JSONObject* zResult) const override; JSONObjectValidationBuilder* addToValidator( JSONObjectValidationBuilder* builder) const override; }; class DimensionGenerator : public virtual Framework::ReferenceCounter { private: JExpressionMemory* jExpressionMemory; JFloatExpression* seedExpression; Framework::RCArray heightLayers; Framework::Text name; int dimensionId; protected: DimensionGenerator(); ~DimensionGenerator(); JExpressionMemory* zMemory() const; void calculateHeightLayers(); public: Dimension* createDimension(); virtual void initialize(int worldSeed); virtual Chunk* generateChunk(int centerX, int centerY) = 0; virtual Framework::Either generateBlock( Framework::Vec3 location) = 0; virtual bool spawnStructure(Framework::Vec3 location, std::function filter) = 0; virtual void generateEntities(Chunk* zChunk) = 0; int getDimensionId() const; void addHeightLayer(WorldHeightLayer* layer); const Framework::RCArray& getHeightLayers() const; void setName(Framework::Text name); Framework::Text getName() const; void setId(int id); int getId() const; void setSeed(JFloatExpression* seed); JFloatExpression* zSeed() const; }; template class DimensionGeneratorFactory : public SubTypeFactory { public: DimensionGeneratorFactory() : SubTypeFactory() {} void fromJson(S* zResult, Framework::JSON::JSONObject* zJson) const override { DimensionGenerator* zGenerator = dynamic_cast(zResult); zGenerator->setName(zJson->zValue("name")->asString()->getString()); zGenerator->setId((int)zJson->zValue("id")->asNumber()->getNumber()); zGenerator->setSeed( Game::INSTANCE->zTypeRegistry()->fromJson( zJson->zValue("dimensionSeed"))); for (Framework::JSON::JSONValue* layer : *zJson->zValue("heightLayers")->asArray()) { zGenerator->addHeightLayer( Game::INSTANCE->zTypeRegistry()->fromJson( layer)); } } void toJson(S* zObject, Framework::JSON::JSONObject* zResult) const override { DimensionGenerator* zGenerator = dynamic_cast(zObject); zResult->addValue( "name", new Framework::JSON::JSONString(zGenerator->getName())); zResult->addValue( "id", new Framework::JSON::JSONNumber(zGenerator->getId())); zResult->addValue("dimensionSeed", Game::INSTANCE->zTypeRegistry()->toJson( zGenerator->zSeed())); Framework::JSON::JSONArray* hightLayers = new Framework::JSON::JSONArray(); for (WorldHeightLayer* layer : zGenerator->getHeightLayers()) { hightLayers->addValue( Game::INSTANCE->zTypeRegistry()->toJson(layer)); } zResult->addValue("heightLayers", hightLayers); } JSONObjectValidationBuilder* addToValidator( JSONObjectValidationBuilder* builder) const override { return builder ->withRequiredAttribute("dimensionSeed", Game::INSTANCE->zTypeRegistry() ->getValidator()) ->withRequiredArray("heightLayers") ->addAcceptedTypeInArray(Game::INSTANCE->zTypeRegistry() ->getValidator()) ->finishArray() ->withRequiredString("name") ->finishString() ->withRequiredNumber("id") ->finishNumber(); } }; class BiomGenerator; class BiomedCavedDimensionGenerator : public DimensionGenerator { private: Framework::RCArray biomGenerators; CaveGenerator* caveGenerator; Framework::JSON::JSONObject* noiseConfig; Noise* biomNoise; Framework::Vec3 minStructureOffset; Framework::Vec3 maxStructureOffset; BiomGenerator* zBiomGenerator(); protected: Framework::RCArray* getGeneratedStructoresForArea( Framework::Vec3 minPos, Framework::Vec3 maxPos); public: BiomedCavedDimensionGenerator(); ~BiomedCavedDimensionGenerator(); virtual void initialize(int worldSeed) override; Chunk* generateChunk(int centerX, int centerY); void generateEntities(Chunk* zChunk); Framework::Either generateBlock(Framework::Vec3 location); bool spawnStructure(Framework::Vec3 location, std::function filter); void addBiomGenerator(BiomGenerator* biomGenerator); const Framework::RCArray& getBiomGenerators() const; void setBiomNoiseConfig(Framework::JSON::JSONObject* biomNoiseConfig); Framework::JSON::JSONObject* zBiomNoiseConfig() const; }; class BiomedCavedDimensionGeneratorFactory : public DimensionGeneratorFactory { public: BiomedCavedDimensionGeneratorFactory(); BiomedCavedDimensionGenerator* createValue( Framework::JSON::JSONObject* zJson) const override; void fromJson(BiomedCavedDimensionGenerator* zResult, Framework::JSON::JSONObject* zJson) const override; void toJson(BiomedCavedDimensionGenerator* zObject, Framework::JSON::JSONObject* zResult) const override; JSONObjectValidationBuilder* addToValidator( JSONObjectValidationBuilder* builder) const override; Framework::Text getTypeToken() const override; };