Skip to content

Commit

Permalink
fixed issue with terrain serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed Mar 7, 2024
1 parent 0219334 commit 303d49c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions WickedEngine/wiECS.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ namespace wi::ecs
return next.fetch_add(1);
}

class ComponentLibrary;
struct EntitySerializer
{
wi::jobsystem::context ctx; // allow components to spawn serialization subtasks
wi::unordered_map<uint64_t, Entity> remap;
bool allow_remap = true;
uint64_t version = 0; // The ComponentLibrary serialization will modify this by the registered component's version number
wi::unordered_set<std::string> resource_registration; // register for resource manager serialization
ComponentLibrary* componentlibrary = nullptr;

~EntitySerializer()
{
Expand Down Expand Up @@ -470,6 +472,7 @@ namespace wi::ecs
// Serialize all registered component managers
inline void Serialize(wi::Archive& archive, EntitySerializer& seri)
{
seri.componentlibrary = this;
if(archive.IsReadMode())
{
bool has_next = false;
Expand Down Expand Up @@ -516,6 +519,7 @@ namespace wi::ecs
// Serialize all components for one entity
inline void Entity_Serialize(Entity entity, wi::Archive& archive, EntitySerializer& seri)
{
seri.componentlibrary = this;
if(archive.IsReadMode())
{
bool has_next = false;
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiScene_Serializers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ namespace wi::scene
archive << textures[ANISOTROPYMAP].uvset;
}

if (seri.GetVersion() >= 2)
if (seri.GetVersion() >= 3)
{
archive << wi::helper::GetPathRelative(dir, textures[TRANSPARENCYMAP].name);
archive << textures[TRANSPARENCYMAP].uvset;
Expand Down
24 changes: 23 additions & 1 deletion WickedEngine/wiTerrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1638,11 +1638,17 @@ namespace wi::terrain
{
Generation_Cancel();

// Note: separate component types serialized within terrain must NOT use the version of the terrain, but their own!
const uint64_t terrain_version = seri.GetVersion();
const uint64_t grass_version = seri.componentlibrary->entries["wi::scene::Scene::hairs"].version;
const uint64_t material_version = seri.componentlibrary->entries["wi::scene::Scene::materials"].version;
const uint64_t weather_version = seri.componentlibrary->entries["wi::scene::Scene::weathers"].version;

if (archive.IsReadMode())
{
archive >> _flags;
archive >> lod_multiplier;
if (seri.GetVersion() < 3)
if (terrain_version < 3)
{
float texlod;
archive >> texlod;
Expand Down Expand Up @@ -1757,7 +1763,11 @@ namespace wi::terrain
SerializeEntity(archive, chunk_data.grass_entity, seri);
SerializeEntity(archive, chunk_data.props_entity, seri);
archive >> chunk_data.prop_density_current;

seri.version = grass_version;
chunk_data.grass.Serialize(archive, seri);
seri.version = terrain_version;

archive >> chunk_data.grass_density_current;
archive >> chunk_data.region_weights;
archive >> chunk_data.sphere.center;
Expand Down Expand Up @@ -1880,7 +1890,11 @@ namespace wi::terrain
SerializeEntity(archive, chunk_data.grass_entity, seri);
SerializeEntity(archive, chunk_data.props_entity, seri);
archive << chunk_data.prop_density_current;

seri.version = grass_version;
chunk_data.grass.Serialize(archive, seri);
seri.version = terrain_version;

archive << chunk_data.grass_density_current;
archive << chunk_data.region_weights;
archive << chunk_data.sphere.center;
Expand Down Expand Up @@ -1922,13 +1936,21 @@ namespace wi::terrain
}
}

// Caution: seri.version changes must be handled carefully!
seri.version = material_version;
material_Base.Serialize(archive, seri);
material_Slope.Serialize(archive, seri);
material_LowAltitude.Serialize(archive, seri);
material_HighAltitude.Serialize(archive, seri);
material_GrassParticle.Serialize(archive, seri);

seri.version = weather_version;
weather.Serialize(archive, seri);

seri.version = grass_version;
grass_properties.Serialize(archive, seri);
seri.version = terrain_version;

perlin_noise.Serialize(archive);
}

Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace wi::version
// minor features, major updates, breaking compatibility changes
const int minor = 71;
// minor bug fixes, alterations, refactors, updates
const int revision = 391;
const int revision = 392;

const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);

Expand Down

0 comments on commit 303d49c

Please sign in to comment.