Skip to content

Commit abd8675

Browse files
committed
Add atmosphere scattering to planet entities
1 parent 433aa4e commit abd8675

6 files changed

Lines changed: 33 additions & 10 deletions

File tree

include/ClientLib/Entities/ClientChunkClassLibrary.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ namespace tsom
2020
ClientChunkClassLibrary(Nz::ApplicationBase& app, const ClientBlockLibrary& blockLibrary);
2121

2222
private:
23-
void InitializeChunkEntity(entt::handle entity) override;
23+
void InitializePlanetEntity(entt::handle entity) override;
24+
void InitializeShipEntity(entt::handle entity) override;
2425
std::unique_ptr<ChunkEntities> SetupChunkEntities(Nz::EnttWorld& world, ChunkContainer& chunkContainer, std::size_t layerIndex) override;
2526
};
2627
}

include/CommonLib/Entities/ChunkClassLibrary.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ namespace tsom
3838
ChunkClassLibrary& operator=(ChunkClassLibrary&&) = delete;
3939

4040
protected:
41-
virtual void InitializeChunkEntity(entt::handle entity);
41+
virtual void InitializePlanetEntity(entt::handle entity);
42+
virtual void InitializeShipEntity(entt::handle entity);
4243
virtual std::unique_ptr<ChunkEntities> SetupChunkEntities(Nz::EnttWorld& world, ChunkContainer& chunkContainer, std::size_t layerIndex);
4344

4445
Nz::ApplicationBase& m_app;

src/ClientLib/Entities/ClientChunkClassLibrary.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#include <ClientLib/Entities/ClientChunkClassLibrary.hpp>
66
#include <ClientLib/ClientBlockLibrary.hpp>
77
#include <ClientLib/ClientChunkEntities.hpp>
8+
#include <CommonLib/AtmosphereScattering.hpp>
89
#include <ClientLib/Components/ChunkNetworkMapComponent.hpp>
10+
#include <CommonLib/Components/ClassInstanceComponent.hpp>
911

1012
namespace tsom
1113
{
@@ -14,7 +16,18 @@ namespace tsom
1416
{
1517
}
1618

17-
void ClientChunkClassLibrary::InitializeChunkEntity(entt::handle entity)
19+
void ClientChunkClassLibrary::InitializePlanetEntity(entt::handle entity)
20+
{
21+
entity.emplace<ChunkNetworkMapComponent>();
22+
auto& atmosphereScattering = entity.emplace<AtmosphereScattering>();
23+
24+
auto& entityInstance = entity.get<ClassInstanceComponent>();
25+
26+
atmosphereScattering.planetCornerRadius = entityInstance.GetProperty<EntityPropertyType::Float>("CornerRadius");
27+
atmosphereScattering.planetDimensions = entityInstance.GetProperty<EntityPropertyType::FloatSize3D>("AtmospherePlanetDims");
28+
}
29+
30+
void ClientChunkClassLibrary::InitializeShipEntity(entt::handle entity)
1831
{
1932
entity.emplace<ChunkNetworkMapComponent>();
2033
}

src/ClientLib/Rendering/AtmosphereScatteringPipelinePass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,10 @@ namespace tsom
196196
{
197197
auto&& [planetPos, atmosphereScattering] = *rit;
198198

199+
Nz::AccessByOffset<Nz::Vector3f&>(atmosphereBasePtr, AtmosphereScatteringFields.planetPositionOffset) = planetPos;
200+
199201
Nz::AccessByOffset<Nz::Vector3f&>(atmosphereBasePtr, AtmosphereScatteringFields.sunDirOffset) = atmosphereScattering->sunDir;
200202
Nz::AccessByOffset<Nz::Vector3f&>(atmosphereBasePtr, AtmosphereScatteringFields.sunIntensityOffset) = atmosphereScattering->sunIntensity;
201-
Nz::AccessByOffset<Nz::Vector3f&>(atmosphereBasePtr, AtmosphereScatteringFields.planetPositionOffset) = atmosphereScattering->planetPosition;
202203
Nz::AccessByOffset<Nz::Vector3f&>(atmosphereBasePtr, AtmosphereScatteringFields.planetDimensionsOffset) = atmosphereScattering->planetDimensions;
203204
Nz::AccessByOffset<float&>(atmosphereBasePtr, AtmosphereScatteringFields.planetCornerRadiusOffset) = atmosphereScattering->planetCornerRadius;
204205
Nz::AccessByOffset<float&>(atmosphereBasePtr, AtmosphereScatteringFields.atmosphereMaxHeightOffset) = atmosphereScattering->atmosphereMaxHeight;

src/CommonLib/ChunkEntities.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ namespace tsom
8484
{
8585
for (auto it = m_updateJobs.begin(); it != m_updateJobs.end(); ++it)
8686
{
87+
//FIXME: If applyFunc inserts a new job it will invalidate the iterators
88+
8789
UpdateJob& job = *it->second;
8890
if (!job.HasFinished())
8991
continue;

src/CommonLib/Entities/ChunkClassLibrary.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ namespace tsom
1818
{
1919
registry.RegisterClass(EntityClass("planet", {
2020
{
21-
EntityClass::Property { .name = "CellSize", .type = EntityPropertyType::Float, .defaultValue = EntityPropertySingleValue<EntityPropertyType::Float>(1.f), .isNetworked = true },
22-
EntityClass::Property { .name = "CornerRadius", .type = EntityPropertyType::Float, .defaultValue = EntityPropertySingleValue<EntityPropertyType::Float>(16.f), .isNetworked = true },
23-
EntityClass::Property { .name = "Gravity", .type = EntityPropertyType::Float, .defaultValue = EntityPropertySingleValue<EntityPropertyType::Float>(9.81f), .isNetworked = true }
21+
EntityClass::Property { .name = "CellSize", .type = EntityPropertyType::Float, .defaultValue = EntityPropertySingleValue<EntityPropertyType::Float>(1.f), .isNetworked = true },
22+
EntityClass::Property { .name = "CornerRadius", .type = EntityPropertyType::Float, .defaultValue = EntityPropertySingleValue<EntityPropertyType::Float>(16.f), .isNetworked = true },
23+
EntityClass::Property { .name = "Gravity", .type = EntityPropertyType::Float, .defaultValue = EntityPropertySingleValue<EntityPropertyType::Float>(9.81f), .isNetworked = true },
24+
EntityClass::Property { .name = "AtmospherePlanetDims", .type = EntityPropertyType::FloatSize3D, .defaultValue = EntityPropertySingleValue<EntityPropertyType::FloatSize3D>(Nz::Vector3f(60.f)), .isNetworked = true },
2425
}
2526
},
2627
{
@@ -45,7 +46,7 @@ namespace tsom
4546
planetComponent.planetEntities[layerIndex]->SetParentEntity(entity);
4647
}
4748

48-
InitializeChunkEntity(entity);
49+
InitializePlanetEntity(entity);
4950
}
5051
},
5152
{}));
@@ -75,13 +76,17 @@ namespace tsom
7576
shipComponent.shipEntities[layerIndex]->SetParentEntity(entity);
7677
}
7778

78-
InitializeChunkEntity(entity);
79+
InitializeShipEntity(entity);
7980
}
8081
},
8182
{}));
8283
}
8384

84-
void ChunkClassLibrary::InitializeChunkEntity(entt::handle entity)
85+
void ChunkClassLibrary::InitializePlanetEntity(entt::handle entity)
86+
{
87+
}
88+
89+
void ChunkClassLibrary::InitializeShipEntity(entt::handle entity)
8590
{
8691
}
8792

0 commit comments

Comments
 (0)