Fixed layers saving/loading
Global scenery save/load testing was also improved to detect these cases better
This commit is contained in:
parent
46e9e73793
commit
6062c755b5
6 changed files with 50 additions and 4 deletions
|
@ -65,6 +65,11 @@ void NoiseGenerator::load(PackStream* stream)
|
||||||
stream->read(&height_offset);
|
stream->read(&height_offset);
|
||||||
stream->read(&level_count);
|
stream->read(&level_count);
|
||||||
|
|
||||||
|
if (level_count > MAX_LEVEL_COUNT)
|
||||||
|
{
|
||||||
|
level_count = MAX_LEVEL_COUNT;
|
||||||
|
}
|
||||||
|
|
||||||
for (x = 0; x < level_count; x++)
|
for (x = 0; x < level_count; x++)
|
||||||
{
|
{
|
||||||
NoiseLevel* level = levels + x;
|
NoiseLevel* level = levels + x;
|
||||||
|
|
|
@ -29,6 +29,12 @@ void NoiseState::load(PackStream *stream)
|
||||||
int levels;
|
int levels;
|
||||||
stream->read(&levels);
|
stream->read(&levels);
|
||||||
level_offsets.clear();
|
level_offsets.clear();
|
||||||
|
|
||||||
|
if (levels > 1000)
|
||||||
|
{
|
||||||
|
levels = 1000;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < levels; i++)
|
for (int i = 0; i < levels; i++)
|
||||||
{
|
{
|
||||||
NoiseOffset level_offset;
|
NoiseOffset level_offset;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "Layers.h"
|
#include "Layers.h"
|
||||||
|
|
||||||
|
#include "PackStream.h"
|
||||||
#include "Logs.h"
|
#include "Logs.h"
|
||||||
|
|
||||||
Layers::Layers(DefinitionNode* parent, const std::string &name, LayerConstructor layer_constructor):
|
Layers::Layers(DefinitionNode* parent, const std::string &name, LayerConstructor layer_constructor):
|
||||||
|
@ -15,6 +16,32 @@ Layers::~Layers()
|
||||||
delete null_layer;
|
delete null_layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Layers::save(PackStream *stream) const
|
||||||
|
{
|
||||||
|
int layer_count = (int)layers.size();
|
||||||
|
stream->write(&layer_count);
|
||||||
|
|
||||||
|
DefinitionNode::save(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Layers::load(PackStream *stream)
|
||||||
|
{
|
||||||
|
int layer_count;
|
||||||
|
stream->read(&layer_count);
|
||||||
|
|
||||||
|
if (layer_count > max_layer_count)
|
||||||
|
{
|
||||||
|
layer_count = max_layer_count;
|
||||||
|
}
|
||||||
|
clear();
|
||||||
|
for (int i = 0; i < layer_count; i++)
|
||||||
|
{
|
||||||
|
addLayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
DefinitionNode::load(stream);
|
||||||
|
}
|
||||||
|
|
||||||
void Layers::copy(DefinitionNode* destination_) const
|
void Layers::copy(DefinitionNode* destination_) const
|
||||||
{
|
{
|
||||||
DefinitionNode::copy(destination_);
|
DefinitionNode::copy(destination_);
|
||||||
|
|
|
@ -19,6 +19,8 @@ public:
|
||||||
Layers(DefinitionNode* parent, const std::string &name, LayerConstructor layer_constructor);
|
Layers(DefinitionNode* parent, const std::string &name, LayerConstructor layer_constructor);
|
||||||
virtual ~Layers();
|
virtual ~Layers();
|
||||||
|
|
||||||
|
virtual void save(PackStream *stream) const override;
|
||||||
|
virtual void load(PackStream *stream) override;
|
||||||
virtual void copy(DefinitionNode* destination) const override;
|
virtual void copy(DefinitionNode* destination) const override;
|
||||||
Layers* newCopy() const;
|
Layers* newCopy() const;
|
||||||
|
|
||||||
|
@ -48,6 +50,7 @@ public:
|
||||||
int max_layer_count;
|
int max_layer_count;
|
||||||
std::vector<DefinitionNode*> layers;
|
std::vector<DefinitionNode*> layers;
|
||||||
DefinitionNode* null_layer;
|
DefinitionNode* null_layer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,10 @@ Scenery::FileOperationResult Scenery::loadGlobal(const std::string &filepath)
|
||||||
|
|
||||||
load(&stream);
|
load(&stream);
|
||||||
|
|
||||||
|
// Reset read headers, to test them again
|
||||||
|
app_header = -1;
|
||||||
|
version_header = -1;
|
||||||
|
|
||||||
stream.read(&version_header);
|
stream.read(&version_header);
|
||||||
if ((int)version_header != DATA_VERSION)
|
if ((int)version_header != DATA_VERSION)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,12 +4,13 @@
|
||||||
|
|
||||||
TEST(Scenery, saveGlobal)
|
TEST(Scenery, saveGlobal)
|
||||||
{
|
{
|
||||||
Scenery scenery;
|
Scenery scenery1;
|
||||||
scenery.autoPreset();
|
scenery1.autoPreset();
|
||||||
|
|
||||||
Scenery::FileOperationResult result = scenery.saveGlobal("/tmp/test_paysages_scenery");
|
Scenery::FileOperationResult result = scenery1.saveGlobal("/tmp/test_paysages_scenery");
|
||||||
EXPECT_EQ((int)Scenery::FILE_OPERATION_OK, result);
|
EXPECT_EQ((int)Scenery::FILE_OPERATION_OK, result);
|
||||||
|
|
||||||
result = scenery.loadGlobal("/tmp/test_paysages_scenery");
|
Scenery scenery2;
|
||||||
|
result = scenery2.loadGlobal("/tmp/test_paysages_scenery");
|
||||||
EXPECT_EQ((int)Scenery::FILE_OPERATION_OK, result);
|
EXPECT_EQ((int)Scenery::FILE_OPERATION_OK, result);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue