|
@@ -1,5 +1,6 @@
|
|
#include "BiomGenerator.h"
|
|
#include "BiomGenerator.h"
|
|
|
|
|
|
|
|
+#include "AddEntityUpdate.h"
|
|
#include "Constants.h"
|
|
#include "Constants.h"
|
|
#include "Game.h"
|
|
#include "Game.h"
|
|
#include "JNoise.h"
|
|
#include "JNoise.h"
|
|
@@ -20,6 +21,10 @@ void BiomGenerator::initialize(JExpressionMemory* zMemory)
|
|
{
|
|
{
|
|
rule->initialize(zMemory);
|
|
rule->initialize(zMemory);
|
|
}
|
|
}
|
|
|
|
+ for (EntityGenerator* entity : entityGenerators)
|
|
|
|
+ {
|
|
|
|
+ entity->initialize(zMemory);
|
|
|
|
+ }
|
|
for (StructureTemplateCollection* collection : templates)
|
|
for (StructureTemplateCollection* collection : templates)
|
|
{
|
|
{
|
|
collection->initialize(zMemory);
|
|
collection->initialize(zMemory);
|
|
@@ -79,6 +84,22 @@ void BiomGenerator::generateStructures(int x,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void BiomGenerator::generateEntities(
|
|
|
|
+ int x, int y, int z, int dimensionId, JExpressionMemory* zMemory)
|
|
|
|
+{
|
|
|
|
+ for (EntityGenerator* entityGen : entityGenerators)
|
|
|
|
+ {
|
|
|
|
+ if (entityGen->isGenerated(x, y, z, dimensionId, zMemory))
|
|
|
|
+ {
|
|
|
|
+ Entity* entity = entityGen->generate(
|
|
|
|
+ Framework::Vec3<float>((float)x, (float)y, (float)z),
|
|
|
|
+ dimensionId);
|
|
|
|
+ Game::INSTANCE->requestWorldUpdate(
|
|
|
|
+ new AddEntityUpdate(entity, dimensionId));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
const Framework::RCArray<StructureTemplateCollection>&
|
|
const Framework::RCArray<StructureTemplateCollection>&
|
|
BiomGenerator::getTemplates() const
|
|
BiomGenerator::getTemplates() const
|
|
{
|
|
{
|
|
@@ -186,6 +207,12 @@ void BiomGeneratorFactory::fromJson(
|
|
zResult->addGeneratorRule(
|
|
zResult->addGeneratorRule(
|
|
Game::INSTANCE->zTypeRegistry()->fromJson<GeneratorRule>(value));
|
|
Game::INSTANCE->zTypeRegistry()->fromJson<GeneratorRule>(value));
|
|
}
|
|
}
|
|
|
|
+ for (Framework::JSON::JSONValue* value :
|
|
|
|
+ *zJson->asObject()->zValue("entities")->asArray())
|
|
|
|
+ {
|
|
|
|
+ zResult->addEntityGenerator(
|
|
|
|
+ Game::INSTANCE->zTypeRegistry()->fromJson<EntityGenerator>(value));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
void BiomGeneratorFactory::toJson(
|
|
void BiomGeneratorFactory::toJson(
|
|
@@ -211,6 +238,13 @@ void BiomGeneratorFactory::toJson(
|
|
Game::INSTANCE->zTypeRegistry()->toJson<GeneratorRule>(rule));
|
|
Game::INSTANCE->zTypeRegistry()->toJson<GeneratorRule>(rule));
|
|
}
|
|
}
|
|
zResult->addValue("blocks", rules);
|
|
zResult->addValue("blocks", rules);
|
|
|
|
+ Framework::JSON::JSONArray* entities = new Framework::JSON::JSONArray();
|
|
|
|
+ for (EntityGenerator* entity : zObject->getEntityGenerators())
|
|
|
|
+ {
|
|
|
|
+ entities->addValue(
|
|
|
|
+ Game::INSTANCE->zTypeRegistry()->toJson<EntityGenerator>(entity));
|
|
|
|
+ }
|
|
|
|
+ zResult->addValue("entities", entities);
|
|
}
|
|
}
|
|
|
|
|
|
JSONObjectValidationBuilder* BiomGeneratorFactory::addToValidator(
|
|
JSONObjectValidationBuilder* BiomGeneratorFactory::addToValidator(
|
|
@@ -228,5 +262,9 @@ JSONObjectValidationBuilder* BiomGeneratorFactory::addToValidator(
|
|
->withRequiredArray("blocks")
|
|
->withRequiredArray("blocks")
|
|
->addAcceptedTypeInArray(
|
|
->addAcceptedTypeInArray(
|
|
Game::INSTANCE->zTypeRegistry()->getValidator<GeneratorRule>())
|
|
Game::INSTANCE->zTypeRegistry()->getValidator<GeneratorRule>())
|
|
|
|
+ ->finishArray()
|
|
|
|
+ ->withRequiredArray("entities")
|
|
|
|
+ ->addAcceptedTypeInArray(
|
|
|
|
+ Game::INSTANCE->zTypeRegistry()->getValidator<EntityGenerator>())
|
|
->finishArray();
|
|
->finishArray();
|
|
}
|
|
}
|