diff --git a/Editor/AnimationWindow.cpp b/Editor/AnimationWindow.cpp index 15a3a181e..5b66301a1 100644 --- a/Editor/AnimationWindow.cpp +++ b/Editor/AnimationWindow.cpp @@ -38,7 +38,7 @@ AnimationWindow::AnimationWindow(wiGUI* gui) :GUI(gui) AnimationComponent* animation = wiRenderer::GetScene().animations.GetComponent(entity); if (animation != nullptr) { - animation->looped = args.bValue; + animation->SetLooped(args.bValue); } }); animWindow->AddWidget(loopedCheckBox); diff --git a/Editor/DecalWindow.cpp b/Editor/DecalWindow.cpp index 291a90d8c..85eeb08d5 100644 --- a/Editor/DecalWindow.cpp +++ b/Editor/DecalWindow.cpp @@ -20,30 +20,17 @@ DecalWindow::DecalWindow(wiGUI* gui) : GUI(gui) float x = 200; float y = 0; - opacitySlider = new wiSlider(0, 1, 1, 100000, "Opacity: "); - opacitySlider->SetSize(XMFLOAT2(100, 30)); - opacitySlider->SetPos(XMFLOAT2(x, y += 30)); - opacitySlider->OnSlide([&](wiEventArgs args) { - DecalComponent* decal = wiRenderer::GetScene().decals.GetComponent(entity); - if (decal != nullptr) + decalNameField = new wiTextInputField("MaterialName"); + decalNameField->SetPos(XMFLOAT2(10, 30)); + decalNameField->SetSize(XMFLOAT2(300, 20)); + decalNameField->OnInputAccepted([&](wiEventArgs args) { + NameComponent* name = wiRenderer::GetScene().names.GetComponent(entity); + if (name != nullptr) { - decal->color.w = args.fValue; + *name = args.sValue; } }); - decalWindow->AddWidget(opacitySlider); - - emissiveSlider = new wiSlider(0, 100, 0, 100000, "Emissive: "); - emissiveSlider->SetSize(XMFLOAT2(100, 30)); - emissiveSlider->SetPos(XMFLOAT2(x, y += 30)); - emissiveSlider->OnSlide([&](wiEventArgs args) { - DecalComponent* decal = wiRenderer::GetScene().decals.GetComponent(entity); - if (decal != nullptr) - { - decal->emissive = args.fValue; - } - }); - decalWindow->AddWidget(emissiveSlider); - + decalWindow->AddWidget(decalNameField); decalWindow->Translate(XMFLOAT3(30, 30, 0)); decalWindow->SetVisible(false); @@ -66,16 +53,19 @@ void DecalWindow::SetEntity(Entity entity) this->entity = entity; - const DecalComponent* decal = wiRenderer::GetScene().decals.GetComponent(entity); + Scene& scene = wiRenderer::GetScene(); + const DecalComponent* decal = scene.decals.GetComponent(entity); if (decal != nullptr) { - opacitySlider->SetValue(decal->color.w); - emissiveSlider->SetValue(decal->emissive); + const NameComponent& name = *scene.names.GetComponent(entity); + + decalNameField->SetValue(name.name); decalWindow->SetEnabled(true); } else { + decalNameField->SetValue("No decal selected"); decalWindow->SetEnabled(false); } } diff --git a/Editor/DecalWindow.h b/Editor/DecalWindow.h index 8511b253d..204dae35a 100644 --- a/Editor/DecalWindow.h +++ b/Editor/DecalWindow.h @@ -17,8 +17,8 @@ public: wiECS::Entity entity; void SetEntity(wiECS::Entity entity); + wiTextInputField* decalNameField; + wiWindow* decalWindow; - wiSlider* opacitySlider; - wiSlider* emissiveSlider; }; diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 2bfd7db9b..c81c1044e 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -479,7 +479,7 @@ void EditorComponent::Load() wiButton* saveButton = new wiButton("Save"); - saveButton->SetTooltip("Save the current scene as a model"); + saveButton->SetTooltip("Save the current scene"); saveButton->SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 5, 0)); saveButton->SetSize(XMFLOAT2(100, 40)); saveButton->SetColor(wiColor(0, 198, 101, 200), wiWidget::WIDGETSTATE::IDLE); @@ -498,7 +498,7 @@ void EditorComponent::Load() // use the contents of szFile to initialize itself. ofn.lpstrFile[0] = '\0'; ofn.nMaxFile = sizeof(szFile); - ofn.lpstrFilter = "Wicked Model Format\0*.wimf\0"; + ofn.lpstrFilter = "Wicked Scene\0*.wiscene\0"; ofn.nFilterIndex = 1; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; @@ -506,35 +506,16 @@ void EditorComponent::Load() ofn.Flags = OFN_OVERWRITEPROMPT; if (GetSaveFileNameA(&ofn) == TRUE) { string fileName = ofn.lpstrFile; - if (fileName.substr(fileName.length() - 5).compare(".wimf") != 0) + if (fileName.substr(fileName.length() - 8).compare(".wiscene") != 0) { - fileName += ".wimf"; + fileName += ".wiscene"; } wiArchive archive(fileName, false); if (archive.IsOpen()) { - const Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiRenderer::GetScene(); - //Model* fullModel = new Model; - //for(auto& x : scene.models) - //{ - // if (x != nullptr) - // { - // fullModel->Add(x); - // } - //} - //fullModel->Serialize(archive); - - //// Clear out the temporary model so that resources won't be deleted on destruction: - //fullModel->objects.clear(); - //fullModel->lights.clear(); - //fullModel->decals.clear(); - //fullModel->meshes.clear(); - //fullModel->materials.clear(); - //fullModel->armatures.clear(); - //fullModel->forces.clear(); - //fullModel->environmentProbes.clear(); - //SAFE_DELETE(fullModel); + scene.Serialize(archive); ResetHistory(); } @@ -548,7 +529,7 @@ void EditorComponent::Load() wiButton* modelButton = new wiButton("Load Model"); - modelButton->SetTooltip("Load a model into the editor..."); + modelButton->SetTooltip("Load a scene / import model into the editor..."); modelButton->SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 4, 0)); modelButton->SetSize(XMFLOAT2(100, 40)); modelButton->SetColor(wiColor(0, 89, 255, 200), wiWidget::WIDGETSTATE::IDLE); @@ -566,7 +547,7 @@ void EditorComponent::Load() // use the contents of szFile to initialize itself. ofn.lpstrFile[0] = '\0'; ofn.nMaxFile = sizeof(szFile); - ofn.lpstrFilter = "Model Formats\0*.obj;*.gltf;*.glb\0"; + ofn.lpstrFilter = "Model Formats\0*.wiscene;*.obj;*.gltf;*.glb\0"; ofn.nFilterIndex = 1; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; @@ -579,7 +560,13 @@ void EditorComponent::Load() loader->addLoadingFunction([=] { string extension = wiHelper::toUpper(wiHelper::GetExtensionFromFileName(fileName)); - if (!extension.compare("OBJ")) // wavefront-obj + if (!extension.compare("WISCENE")) // engine-serialized + { + wiArchive archive(fileName, true); + Scene& scene = wiRenderer::GetScene(); + scene.Serialize(archive); + } + else if (!extension.compare("OBJ")) // wavefront-obj { ImportModel_OBJ(fileName); } @@ -646,29 +633,6 @@ void EditorComponent::Load() shaderButton->SetColor(wiColor(255, 33, 140, 200), wiWidget::WIDGETSTATE::IDLE); shaderButton->SetColor(wiColor(255, 100, 140, 255), wiWidget::WIDGETSTATE::FOCUS); shaderButton->OnClick([=](wiEventArgs args) { - //thread([&] { - // char szFile[260]; - - // OPENFILENAMEA ofn; - // ZeroMemory(&ofn, sizeof(ofn)); - // ofn.lStructSize = sizeof(ofn); - // ofn.hwndOwner = nullptr; - // ofn.lpstrFile = szFile; - // // Set lpstrFile[0] to '\0' so that GetOpenFileName does not - // // use the contents of szFile to initialize itself. - // ofn.lpstrFile[0] = '\0'; - // ofn.nMaxFile = sizeof(szFile); - // ofn.lpstrFilter = "Compiled shader object file\0*.cso\0"; - // ofn.nFilterIndex = 1; - // ofn.lpstrFileTitle = NULL; - // ofn.nMaxFileTitle = 0; - // ofn.lpstrInitialDir = NULL; - // ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; - // if (GetOpenFileNameA(&ofn) == TRUE) { - // string fileName = ofn.lpstrFile; - // wiRenderer::ReloadShaders(wiHelper::GetDirectoryFromPath(fileName)); - // } - //}).detach(); wiRenderer::ReloadShaders(); diff --git a/Editor/EmitterWindow.cpp b/Editor/EmitterWindow.cpp index f674ac87e..a992a7736 100644 --- a/Editor/EmitterWindow.cpp +++ b/Editor/EmitterWindow.cpp @@ -94,7 +94,7 @@ EmitterWindow::EmitterWindow(wiGUI* gui) : GUI(gui) auto emitter = GetEmitter(); if (emitter != nullptr) { - emitter->SORTING = args.bValue; + emitter->SetSorted(args.bValue); } }); sortCheckBox->SetCheck(false); @@ -108,7 +108,7 @@ EmitterWindow::EmitterWindow(wiGUI* gui) : GUI(gui) auto emitter = GetEmitter(); if (emitter != nullptr) { - emitter->DEPTHCOLLISIONS = args.bValue; + emitter->SetDepthCollisionEnabled(args.bValue); } }); depthCollisionsCheckBox->SetCheck(false); @@ -122,7 +122,7 @@ EmitterWindow::EmitterWindow(wiGUI* gui) : GUI(gui) auto emitter = GetEmitter(); if (emitter != nullptr) { - emitter->SPH_FLUIDSIMULATION = args.bValue; + emitter->SetSPHEnabled(args.bValue); } }); sphCheckBox->SetCheck(false); @@ -136,7 +136,7 @@ EmitterWindow::EmitterWindow(wiGUI* gui) : GUI(gui) auto emitter = GetEmitter(); if (emitter != nullptr) { - emitter->PAUSED = args.bValue; + emitter->SetPaused(args.bValue); } }); pauseCheckBox->SetCheck(false); @@ -150,7 +150,7 @@ EmitterWindow::EmitterWindow(wiGUI* gui) : GUI(gui) auto emitter = GetEmitter(); if (emitter != nullptr) { - emitter->DEBUG = args.bValue; + emitter->SetDebug(args.bValue); } }); debugCheckBox->SetCheck(false); @@ -429,7 +429,7 @@ void EmitterWindow::SetEntity(Entity entity) // first try to turn off any debug readbacks for emitters: if (GetEmitter() != nullptr) { - GetEmitter()->DEBUG = false; + GetEmitter()->SetDebug(false); } debugCheckBox->SetCheck(false); @@ -439,10 +439,10 @@ void EmitterWindow::SetEntity(Entity entity) if (emitter != nullptr) { - sortCheckBox->SetCheck(emitter->SORTING); - depthCollisionsCheckBox->SetCheck(emitter->DEPTHCOLLISIONS); - sphCheckBox->SetCheck(emitter->SPH_FLUIDSIMULATION); - pauseCheckBox->SetCheck(emitter->PAUSED); + sortCheckBox->SetCheck(emitter->IsSorted()); + depthCollisionsCheckBox->SetCheck(emitter->IsDepthCollisionEnabled()); + sphCheckBox->SetCheck(emitter->IsSPHEnabled()); + pauseCheckBox->SetCheck(emitter->IsPaused()); maxParticlesSlider->SetValue((float)emitter->GetMaxParticleCount()); emitCountSlider->SetValue(emitter->count); diff --git a/Editor/EnvProbeWindow.cpp b/Editor/EnvProbeWindow.cpp index f01114fb1..35e9015e5 100644 --- a/Editor/EnvProbeWindow.cpp +++ b/Editor/EnvProbeWindow.cpp @@ -25,8 +25,8 @@ EnvProbeWindow::EnvProbeWindow(wiGUI* gui) : GUI(gui) EnvironmentProbeComponent* probe = wiRenderer::GetScene().probes.GetComponent(entity); if (probe != nullptr) { - probe->realTime = args.bValue; - probe->isUpToDate = false; + probe->SetRealTime(args.bValue); + probe->SetDirty(); } }); envProbeWindow->AddWidget(realTimeCheckBox); @@ -47,7 +47,7 @@ EnvProbeWindow::EnvProbeWindow(wiGUI* gui) : GUI(gui) EnvironmentProbeComponent* probe = wiRenderer::GetScene().probes.GetComponent(entity); if (probe != nullptr) { - probe->isUpToDate = false; + probe->SetDirty(); } }); envProbeWindow->AddWidget(refreshButton); @@ -60,7 +60,7 @@ EnvProbeWindow::EnvProbeWindow(wiGUI* gui) : GUI(gui) for (size_t i = 0; i < scene.probes.GetCount(); ++i) { EnvironmentProbeComponent& probe = scene.probes[i]; - probe.isUpToDate = false; + probe.SetDirty(); } }); envProbeWindow->AddWidget(refreshAllButton); @@ -95,7 +95,7 @@ void EnvProbeWindow::SetEntity(Entity entity) } else { - realTimeCheckBox->SetCheck(probe->realTime); + realTimeCheckBox->SetCheck(probe->IsRealTime()); realTimeCheckBox->SetEnabled(true); refreshButton->SetEnabled(true); } diff --git a/Editor/LightWindow.cpp b/Editor/LightWindow.cpp index 30e5878d6..daa32738e 100644 --- a/Editor/LightWindow.cpp +++ b/Editor/LightWindow.cpp @@ -125,7 +125,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); if (light != nullptr) { - light->shadow = args.bValue; + light->SetCastShadow(args.bValue); } }); shadowCheckBox->SetEnabled(false); @@ -138,7 +138,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); if (light != nullptr) { - light->volumetrics = args.bValue; + light->SetVolumetricsEnabled(args.bValue); } }); volumetricsCheckBox->SetEnabled(false); @@ -151,7 +151,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); if (light != nullptr) { - light->visualizer = args.bValue; + light->SetVisualizerEnabled(args.bValue); } }); haloCheckBox->SetEnabled(false); @@ -241,11 +241,11 @@ void LightWindow::SetEntity(Entity entity) biasSlider->SetEnabled(true); biasSlider->SetValue(light->shadowBias); shadowCheckBox->SetEnabled(true); - shadowCheckBox->SetCheck(light->shadow); + shadowCheckBox->SetCheck(light->IsCastingShadow()); haloCheckBox->SetEnabled(true); - haloCheckBox->SetCheck(light->visualizer); + haloCheckBox->SetCheck(light->IsVisualizerEnabled()); volumetricsCheckBox->SetEnabled(true); - volumetricsCheckBox->SetCheck(light->volumetrics); + volumetricsCheckBox->SetCheck(light->IsVolumetricsEnabled()); colorPicker->SetEnabled(true); typeSelectorComboBox->SetEnabled(true); typeSelectorComboBox->SetSelected((int)light->GetType()); diff --git a/Editor/ObjectWindow.cpp b/Editor/ObjectWindow.cpp index 3cd9e4151..b6b848042 100644 --- a/Editor/ObjectWindow.cpp +++ b/Editor/ObjectWindow.cpp @@ -31,7 +31,7 @@ ObjectWindow::ObjectWindow(wiGUI* gui) : GUI(gui) ObjectComponent* object = wiRenderer::GetScene().objects.GetComponent(entity); if (object != nullptr) { - object->renderable = args.bValue; + object->SetRenderable(args.bValue); } }); objectWindow->AddWidget(renderableCheckBox); @@ -57,7 +57,7 @@ ObjectWindow::ObjectWindow(wiGUI* gui) : GUI(gui) ObjectComponent* object = wiRenderer::GetScene().objects.GetComponent(entity); if (object != nullptr) { - object->cascadeMask = args.iValue; + object->cascadeMask = (uint32_t)args.iValue; } }); objectWindow->AddWidget(cascadeMaskSlider); @@ -208,7 +208,7 @@ void ObjectWindow::SetEntity(Entity entity) if (object != nullptr) { - renderableCheckBox->SetCheck(object->renderable); + renderableCheckBox->SetCheck(object->IsRenderable()); cascadeMaskSlider->SetValue((float)object->cascadeMask); ditherSlider->SetValue(object->GetTransparency()); diff --git a/Editor/WorldWindow.cpp b/Editor/WorldWindow.cpp index cbfbadb86..34d2b6999 100644 --- a/Editor/WorldWindow.cpp +++ b/Editor/WorldWindow.cpp @@ -124,7 +124,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) Scene& scene = wiRenderer::GetScene(); for (size_t i = 0; i < scene.probes.GetCount(); ++i) { - scene.probes[i].isUpToDate = false; + scene.probes[i].SetDirty(); } }); @@ -154,7 +154,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) // Also, we invalidate all environment probes to reflect the sky changes. for (size_t i = 0; i < scene.probes.GetCount(); ++i) { - scene.probes[i].isUpToDate = false; + scene.probes[i].SetDirty(); } }); @@ -179,7 +179,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) // Also, we invalidate all environment probes to reflect the sky changes. for (size_t i = 0; i < scene.probes.GetCount(); ++i) { - scene.probes[i].isUpToDate = false; + scene.probes[i].SetDirty(); } }); @@ -204,7 +204,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) // Also, we invalidate all environment probes to reflect the sky changes. for (size_t i = 0; i < scene.probes.GetCount(); ++i) { - scene.probes[i].isUpToDate = false; + scene.probes[i].SetDirty(); } }); @@ -229,7 +229,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) // Also, we invalidate all environment probes to reflect the sky changes. for (size_t i = 0; i < scene.probes.GetCount(); ++i) { - scene.probes[i].isUpToDate = false; + scene.probes[i].SetDirty(); } }); diff --git a/WickedEngine/wiArchive.h b/WickedEngine/wiArchive.h index 5029e07c4..b2df11cfb 100644 --- a/WickedEngine/wiArchive.h +++ b/WickedEngine/wiArchive.h @@ -3,6 +3,7 @@ #include #include +#include class wiArchive { @@ -123,6 +124,21 @@ public: _write(data); return *this; } + inline wiArchive& operator<<(const XMUINT2& data) + { + _write(data); + return *this; + } + inline wiArchive& operator<<(const XMUINT3& data) + { + _write(data); + return *this; + } + inline wiArchive& operator<<(const XMUINT4& data) + { + _write(data); + return *this; + } inline wiArchive& operator<<(const std::string& data) { uint64_t len = (uint64_t)(data.length() + 1); // +1 for the null-terminator @@ -130,6 +146,17 @@ public: _write(*data.c_str(), len); return *this; } + template + inline wiArchive& operator<<(const std::vector& data) + { + // Here we will use the << operator so that non-specified types will have compile error! + (*this) << data.size(); + for (const T& x : data) + { + (*this) << x; + } + return *this; + } // Read operations inline wiArchive& operator >> (bool& data) @@ -235,6 +262,21 @@ public: _read(data); return *this; } + inline wiArchive& operator >> (XMUINT2& data) + { + _read(data); + return *this; + } + inline wiArchive& operator >> (XMUINT3& data) + { + _read(data); + return *this; + } + inline wiArchive& operator >> (XMUINT4& data) + { + _read(data); + return *this; + } inline wiArchive& operator >> (std::string& data) { uint64_t len; @@ -246,6 +288,19 @@ public: delete[] str; return *this; } + template + inline wiArchive& operator >> (std::vector& data) + { + // Here we will use the >> operator so that non-specified types will have compile error! + size_t count; + (*this) >> count; + data.resize(count); + for (size_t i = 0; i < count; ++i) + { + (*this) >> data[i]; + } + return *this; + } diff --git a/WickedEngine/wiEmittedParticle.cpp b/WickedEngine/wiEmittedParticle.cpp index 8b929b10b..eae92862e 100644 --- a/WickedEngine/wiEmittedParticle.cpp +++ b/WickedEngine/wiEmittedParticle.cpp @@ -205,14 +205,14 @@ uint32_t wiEmittedParticle::GetMemorySizeInBytes() const void wiEmittedParticle::Update(float dt) { - if (PAUSED) + if (IsPaused()) return; emit += (float)count*dt; } void wiEmittedParticle::Burst(float num) { - if (PAUSED) + if (IsPaused()) return; emit += num; @@ -220,7 +220,7 @@ void wiEmittedParticle::Burst(float num) void wiEmittedParticle::Restart() { buffersUpToDate = false; - PAUSED = false; + SetPaused(false); } //#define DEBUG_SORTING // slow but great for debug!! @@ -231,7 +231,7 @@ void wiEmittedParticle::UpdateRenderData(const TransformComponent& transform, co GraphicsDevice* device = wiRenderer::GetDevice(); - if (!PAUSED) + if (!IsPaused()) { device->EventBegin("UpdateEmittedParticles", threadID); @@ -268,7 +268,7 @@ void wiEmittedParticle::UpdateRenderData(const TransformComponent& transform, co cb.xSPH_K = SPH_K; cb.xSPH_p0 = SPH_p0; cb.xSPH_e = SPH_e; - cb.xSPH_ENABLED = SPH_FLUIDSIMULATION ? 1 : 0; + cb.xSPH_ENABLED = IsSPHEnabled() ? 1 : 0; device->UpdateBuffer(constantBuffer.get(), &cb, threadID); device->BindConstantBuffer(CS, constantBuffer.get(), CB_GETBINDSLOT(EmittedParticleCB), threadID); @@ -311,7 +311,7 @@ void wiEmittedParticle::UpdateRenderData(const TransformComponent& transform, co device->UAVBarrier(uavs, ARRAYSIZE(uavs), threadID); device->EventEnd(threadID); - if (SPH_FLUIDSIMULATION) + if (IsSPHEnabled()) { wiProfiler::GetInstance().BeginRange("SPH - Simulation", wiProfiler::DOMAIN_GPU, threadID); @@ -420,9 +420,9 @@ void wiEmittedParticle::UpdateRenderData(const TransformComponent& transform, co device->BindResources(CS, resources, TEXSLOT_ONDEMAND0, ARRAYSIZE(resources), threadID); // update CURRENT alive list, write NEW alive list - if (SORTING) + if (IsSorted()) { - if (DEPTHCOLLISIONS) + if (IsDepthCollisionEnabled()) { device->BindComputePSO(&CPSO_simulate_SORTING_DEPTHCOLLISIONS, threadID); } @@ -433,7 +433,7 @@ void wiEmittedParticle::UpdateRenderData(const TransformComponent& transform, co } else { - if (DEPTHCOLLISIONS) + if (IsDepthCollisionEnabled()) { device->BindComputePSO(&CPSO_simulate_DEPTHCOLLISIONS, threadID); } @@ -454,7 +454,7 @@ void wiEmittedParticle::UpdateRenderData(const TransformComponent& transform, co } - if (SORTING) + if (IsSorted()) { #ifdef DEBUG_SORTING vector before(MAX_PARTICLES); @@ -522,7 +522,7 @@ void wiEmittedParticle::UpdateRenderData(const TransformComponent& transform, co #endif // DEBUG_SORTING } - if (!PAUSED) + if (!IsPaused()) { // finish updating, update draw argument buffer: device->EventBegin("FinishUpdate", threadID); @@ -551,7 +551,7 @@ void wiEmittedParticle::UpdateRenderData(const TransformComponent& transform, co emit -= (UINT)emit; } - if (DEBUG) + if (IsDebug()) { device->DownloadResource(counterBuffer.get(), debugDataReadbackBuffer.get(), &debugData, threadID); } @@ -791,9 +791,47 @@ void wiEmittedParticle::Serialize(wiArchive& archive) { if (archive.IsReadMode()) { + archive >> _flags; + archive >> (uint32_t&)shaderType; + archive >> meshID; + archive >> FIXED_TIMESTEP; + archive >> size; + archive >> random_factor; + archive >> normal_factor; + archive >> count; + archive >> life; + archive >> random_life; + archive >> scaleX; + archive >> scaleY; + archive >> rotation; + archive >> motionBlurAmount; + archive >> mass; + archive >> SPH_h; + archive >> SPH_K; + archive >> SPH_p0; + archive >> SPH_e; } else { + archive << _flags; + archive << (uint32_t)shaderType; + archive << meshID; + archive << FIXED_TIMESTEP; + archive << size; + archive << random_factor; + archive << normal_factor; + archive << count; + archive << life; + archive << random_life; + archive << scaleX; + archive << scaleY; + archive << rotation; + archive << motionBlurAmount; + archive << mass; + archive << SPH_h; + archive << SPH_K; + archive << SPH_p0; + archive << SPH_e; } } diff --git a/WickedEngine/wiEmittedParticle.h b/WickedEngine/wiEmittedParticle.h index 91f507bae..878e18e98 100644 --- a/WickedEngine/wiEmittedParticle.h +++ b/WickedEngine/wiEmittedParticle.h @@ -21,6 +21,7 @@ public: SOFT_DISTORTION, SIMPLEST, PARTICLESHADERTYPE_COUNT, + ENUM_FORCE_UINT32 = 0xFFFFFFFF, }; private: @@ -70,23 +71,29 @@ public: void Burst(float num); void Restart(); - wiECS::Entity meshID = wiECS::INVALID_ENTITY; - // Must have a transform and material component, but mesh is optional void UpdateRenderData(const TransformComponent& transform, const MaterialComponent& material, const MeshComponent* mesh, GRAPHICSTHREAD threadID); void Draw(const MaterialComponent& material, GRAPHICSTHREAD threadID); - bool DEBUG = false; ParticleCounters GetDebugData() { return debugData; } - bool PAUSED = false; - bool SORTING = false; - bool DEPTHCOLLISIONS = false; - bool SPH_FLUIDSIMULATION = false; - float FIXED_TIMESTEP = -1.0f; // -1 : variable timestep; >=0 : fixed timestep + enum FLAGS + { + EMPTY = 0, + DEBUG = 1 << 0, + PAUSED = 1 << 1, + SORTING = 1 << 2, + DEPTHCOLLISION = 1 << 3, + SPH_FLUIDSIMULATION = 1 << 4, + }; + uint32_t _flags = EMPTY; PARTICLESHADERTYPE shaderType = SOFT; + wiECS::Entity meshID = wiECS::INVALID_ENTITY; + + float FIXED_TIMESTEP = -1.0f; // -1 : variable timestep; >=0 : fixed timestep + float size = 1.0f; float random_factor = 1.0f; float normal_factor = 1.0f; @@ -108,6 +115,18 @@ public: uint32_t GetMaxParticleCount() const { return MAX_PARTICLES; } uint32_t GetMemorySizeInBytes() const; + inline bool IsDebug() const { return _flags & DEBUG; } + inline bool IsPaused() const { return _flags & PAUSED; } + inline bool IsSorted() const { return _flags & SORTING; } + inline bool IsDepthCollisionEnabled() const { return _flags & DEPTHCOLLISION; } + inline bool IsSPHEnabled() const { return _flags & SPH_FLUIDSIMULATION; } + + inline void SetDebug(bool value) { if (value) { _flags |= DEBUG; } else { _flags &= ~DEBUG; } } + inline void SetPaused(bool value) { if (value) { _flags |= PAUSED; } else { _flags &= ~PAUSED; } } + inline void SetSorted(bool value) { if (value) { _flags |= SORTING; } else { _flags &= ~SORTING; } } + inline void SetDepthCollisionEnabled(bool value) { if (value) { _flags |= DEPTHCOLLISION; } else { _flags &= ~DEPTHCOLLISION; } } + inline void SetSPHEnabled(bool value) { if (value) { _flags |= SPH_FLUIDSIMULATION; } else { _flags &= ~SPH_FLUIDSIMULATION; } } + void Serialize(wiArchive& archive); }; diff --git a/WickedEngine/wiGraphicsDevice_DX11.cpp b/WickedEngine/wiGraphicsDevice_DX11.cpp index a31063904..20b313385 100644 --- a/WickedEngine/wiGraphicsDevice_DX11.cpp +++ b/WickedEngine/wiGraphicsDevice_DX11.cpp @@ -1573,7 +1573,7 @@ void GraphicsDevice_DX11::CreateBackBufferResources() void GraphicsDevice_DX11::SetResolution(int width, int height) { - if (width != SCREENWIDTH || height != SCREENHEIGHT) + if ((width != SCREENWIDTH || height != SCREENHEIGHT) && width > 0 && height > 0) { SCREENWIDTH = width; SCREENHEIGHT = height; diff --git a/WickedEngine/wiGraphicsDevice_DX12.cpp b/WickedEngine/wiGraphicsDevice_DX12.cpp index 8d26a127d..13d242b3b 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.cpp +++ b/WickedEngine/wiGraphicsDevice_DX12.cpp @@ -2034,7 +2034,7 @@ namespace wiGraphicsTypes void GraphicsDevice_DX12::SetResolution(int width, int height) { - if (width != SCREENWIDTH || height != SCREENHEIGHT) + if ((width != SCREENWIDTH || height != SCREENHEIGHT) && width > 0 && height > 0) { SCREENWIDTH = width; SCREENHEIGHT = height; diff --git a/WickedEngine/wiHairParticle.cpp b/WickedEngine/wiHairParticle.cpp index 64bc6f937..d5034ef36 100644 --- a/WickedEngine/wiHairParticle.cpp +++ b/WickedEngine/wiHairParticle.cpp @@ -356,9 +356,27 @@ void wiHairParticle::Serialize(wiArchive& archive) { if (archive.IsReadMode()) { + archive >> _flags; + archive >> meshID; + archive >> strandCount; + archive >> segmentCount; + archive >> randomSeed; + archive >> length; + archive >> stiffness; + archive >> randomness; + archive >> viewDistance; } else { + archive << _flags; + archive << meshID; + archive << strandCount; + archive << segmentCount; + archive << randomSeed; + archive << length; + archive << stiffness; + archive << randomness; + archive << viewDistance; } } diff --git a/WickedEngine/wiHairParticle.h b/WickedEngine/wiHairParticle.h index f1d4d5b3f..795cf0452 100644 --- a/WickedEngine/wiHairParticle.h +++ b/WickedEngine/wiHairParticle.h @@ -38,15 +38,23 @@ public: static void CleanUpStatic(); static void SetUpStatic(); + enum FLAGS + { + EMPTY = 0, + }; + uint32_t _flags = EMPTY; + + wiECS::Entity meshID = wiECS::INVALID_ENTITY; + uint32_t strandCount = 0; + uint32_t segmentCount = 1; + uint32_t randomSeed = 1; float length = 1.0f; float stiffness = 10.0f; float randomness = 0.2f; - uint32_t segmentCount = 1; - uint32_t randomSeed = 1; float viewDistance = 200; - wiECS::Entity meshID = wiECS::INVALID_ENTITY; + // Non-serialized attributes: XMFLOAT4X4 world; AABB aabb; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 3bfc25050..b4bb9aafd 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -3026,7 +3026,7 @@ void wiRenderer::UpdatePerFrameData(float dt) light.shadowMap_index = -1; - if (light.shadow) + if (light.IsCastingShadow()) { switch (light.GetType()) { @@ -3209,7 +3209,7 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) entityArray[entityCounter].directionWS = light.direction; entityArray[entityCounter].shadowKernel = 1.0f / SHADOWRES_2D; - if (light.shadow && shadowIndex >= 0 && !light.shadowCam_dirLight.empty()) + if (light.IsCastingShadow() && shadowIndex >= 0 && !light.shadowCam_dirLight.empty()) { matrixArray[shadowIndex + 0] = light.shadowCam_dirLight[0].getVP(); matrixArray[shadowIndex + 1] = light.shadowCam_dirLight[1].getVP(); @@ -3225,7 +3225,7 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) XMStoreFloat3(&entityArray[entityCounter].directionVS, XMVector3TransformNormal(XMLoadFloat3(&entityArray[entityCounter].directionWS), viewMatrix)); entityArray[entityCounter].shadowKernel = 1.0f / SHADOWRES_2D; - if (light.shadow && shadowIndex >= 0 && !light.shadowCam_spotLight.empty()) + if (light.IsCastingShadow() && shadowIndex >= 0 && !light.shadowCam_spotLight.empty()) { matrixArray[shadowIndex + 0] = light.shadowCam_spotLight[0].getVP(); matrixCounter = max(matrixCounter, (UINT)shadowIndex + 1); @@ -3556,7 +3556,7 @@ void wiRenderer::OcclusionCulling_Render(GRAPHICSTHREAD threadID) for (Entity entity : culling.culledObjects) { ObjectComponent& object = *scene.objects.GetComponent(entity); - if (!object.renderable) + if (!object.IsRenderable()) { continue; } @@ -3623,7 +3623,7 @@ void wiRenderer::OcclusionCulling_Read() for (Entity entity : culling.culledObjects) { ObjectComponent& object = *scene.objects.GetComponent(entity); - if (!object.renderable) + if (!object.IsRenderable()) { continue; } @@ -4333,7 +4333,7 @@ void wiRenderer::DrawLightVisualizers(CameraComponent* camera, GRAPHICSTHREAD th { LightComponent& light = scene.lights[i]; - if (light.GetType() == type && light.visualizer) + if (light.GetType() == type && light.IsVisualizerEnabled()) { VolumeLightCB lcb; @@ -4453,7 +4453,7 @@ void wiRenderer::DrawVolumeLights(CameraComponent* camera, GRAPHICSTHREAD thread for (Entity entity : culledLights) { const LightComponent& light = *scene.lights.GetComponent(entity); - if (light.GetType() == type && light.volumetrics) + if (light.GetType() == type && light.IsVolumetricsEnabled()) { switch (type) @@ -4679,7 +4679,7 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID, uint32_t layerMask) for (Entity entity : culledLights) { const LightComponent& light = *scene.lights.GetComponent(entity); - if (light.GetType() != type || !light.shadow) + if (light.GetType() != type || !light.IsCastingShadow()) { continue; } @@ -4692,7 +4692,7 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID, uint32_t layerMask) break; shadowCounter_2D += 3; // shadow indices are already complete so a shadow slot is consumed here even if no rendering actually happens! - for (int cascade = 0; cascade < 3; ++cascade) + for (uint32_t cascade = 0; cascade < 3; ++cascade) { const float siz = light.shadowCam_dirLight[cascade].size * 0.5f; const float f = light.shadowCam_dirLight[cascade].farplane * 0.5f; @@ -5614,13 +5614,13 @@ void wiRenderer::RefreshEnvProbes(GRAPHICSTHREAD threadID) } } - if (probe.isUpToDate) + if (!probe.IsDirty()) { continue; } - if (!probe.realTime) + if (!probe.IsRealTime()) { - probe.isUpToDate = true; + probe.SetDirty(false); } GetDevice()->BindRenderTargets(1, (Texture2D**)&textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], envrenderingDepthBuffer, threadID, probe.textureIndex); @@ -6186,8 +6186,8 @@ void wiRenderer::GenerateMipChain(Texture2D* texture, MIPGENFILTER filter, GRAPH { GetDevice()->BindUAV(CS, texture, 0, threadID, i + 1); GetDevice()->BindResource(CS, texture, TEXSLOT_UNIQUE0, threadID, i); - desc.Width = max(1, (UINT)ceilf(desc.Width * 0.5f)); - desc.Height = max(1, (UINT)ceilf(desc.Height * 0.5f)); + desc.Width = max(1, desc.Width / 2); + desc.Height = max(1, desc.Height / 2); GenerateMIPChainCB cb; cb.outputResolution.x = desc.Width; @@ -6234,8 +6234,8 @@ void wiRenderer::GenerateMipChain(Texture2D* texture, MIPGENFILTER filter, GRAPH { GetDevice()->BindUAV(CS, texture, 0, threadID, i + 1); GetDevice()->BindResource(CS, texture, TEXSLOT_UNIQUE0, threadID, i); - desc.Width = max(1, (UINT)ceilf(desc.Width * 0.5f)); - desc.Height = max(1, (UINT)ceilf(desc.Height * 0.5f)); + desc.Width = max(1, desc.Width / 2); + desc.Height = max(1, desc.Height / 2); GenerateMIPChainCB cb; cb.outputResolution.x = desc.Width; @@ -6288,8 +6288,8 @@ void wiRenderer::GenerateMipChain(Texture2D* texture, MIPGENFILTER filter, GRAPH { GetDevice()->BindUAV(CS, texture, 0, threadID, i + 1); GetDevice()->BindResource(CS, texture, TEXSLOT_UNIQUE0, threadID, i); - desc.Width = max(1, (UINT)ceilf(desc.Width * 0.5f)); - desc.Height = max(1, (UINT)ceilf(desc.Height * 0.5f)); + desc.Width = max(1, desc.Width / 2); + desc.Height = max(1, desc.Height / 2); GenerateMIPChainCB cb; cb.outputResolution.x = desc.Width; @@ -6363,9 +6363,9 @@ void wiRenderer::GenerateMipChain(Texture3D* texture, MIPGENFILTER filter, GRAPH { GetDevice()->BindUAV(CS, texture, 0, threadID, i + 1); GetDevice()->BindResource(CS, texture, TEXSLOT_UNIQUE0, threadID, i); - desc.Width = max(1, (UINT)ceilf(desc.Width * 0.5f)); - desc.Height = max(1, (UINT)ceilf(desc.Height * 0.5f)); - desc.Depth = max(1, (UINT)ceilf(desc.Depth * 0.5f)); + desc.Width = max(1, desc.Width / 2); + desc.Height = max(1, desc.Height / 2); + desc.Depth = max(1, desc.Depth / 2); GenerateMIPChainCB cb; cb.outputResolution.x = desc.Width; @@ -7879,101 +7879,6 @@ wiRenderer::RayIntersectWorldResult wiRenderer::RayIntersectWorld(const RAY& ray return result; } -Entity wiRenderer::LoadModel(const std::string& fileName, const XMMATRIX& transform) -{ - //Model* model = nullptr; - - //wiArchive archive(fileName, true); - //if (archive.IsOpen()) - //{ - // model = new Model; - // model->Serialize(archive); - // model->transform(transform); - - // AddModel(model); - //} - //else - //{ - // wiHelper::messageBox("Could not open archive!", "Error!"); - //} - - //LoadWorldInfo(fileName); - - //return model; - - return INVALID_ENTITY; -} -void wiRenderer::LoadWorldInfo(const std::string& fileName) -{ - Scene& scene = GetScene(); - - string extension = wiHelper::GetExtensionFromFileName(fileName); - - string realName; - if (!extension.compare("wiw")) - { - realName = fileName; - } - else if (extension.empty()) - { - realName = fileName + ".wiw"; - } - else - { - realName = fileName; - wiHelper::RemoveExtensionFromFileName(realName); - realName += ".wiw"; - } - - ifstream file(realName); - if (file) - { - while (!file.eof()) - { - string read = ""; - file >> read; - switch (read[0]) - { - case 'h': - file >> scene.horizon.x >> scene.horizon.y >> scene.horizon.z; - // coming from blender, de-apply gamma correction: - scene.horizon.x = powf(scene.horizon.x, 1.0f / 2.2f); - scene.horizon.y = powf(scene.horizon.y, 1.0f / 2.2f); - scene.horizon.z = powf(scene.horizon.z, 1.0f / 2.2f); - break; - case 'z': - file >> scene.zenith.x >> scene.zenith.y >> scene.zenith.z; - // coming from blender, de-apply gamma correction: - scene.zenith.x = powf(scene.zenith.x, 1.0f / 2.2f); - scene.zenith.y = powf(scene.zenith.y, 1.0f / 2.2f); - scene.zenith.z = powf(scene.zenith.z, 1.0f / 2.2f); - break; - case 'a': - file >> scene.ambient.x >> scene.ambient.y >> scene.ambient.z; - // coming from blender, de-apply gamma correction: - scene.zenith.x = powf(scene.zenith.x, 1.0f / 2.2f); - scene.zenith.y = powf(scene.zenith.y, 1.0f / 2.2f); - scene.zenith.z = powf(scene.zenith.z, 1.0f / 2.2f); - break; - case 'W': - { - XMFLOAT4 r; - float s; - file >> r.x >> r.y >> r.z >> r.w >> s; - XMStoreFloat3(&scene.windDirection, XMVector3Transform(XMVectorSet(0, s, 0, 0), XMMatrixRotationQuaternion(XMLoadFloat4(&r)))); - } - break; - case 'm': - { - file >> scene.fogStart >> scene.fogEnd >> scene.fogHeight; - } - break; - default:break; - } - } - } - file.close(); -} Scene& wiRenderer::GetScene() { if (scene == nullptr) diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index f0189f42d..febb5e45f 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -465,9 +465,6 @@ public: static void SetOceanEnabled(bool enabled, const wiOceanParameter& params); static wiOcean* GetOcean() { return ocean; } - static wiECS::Entity LoadModel(const std::string& fileName, const XMMATRIX& transform = XMMatrixIdentity()); - static void LoadWorldInfo(const std::string& fileName); - static void CreateImpostor(wiECS::Entity, GRAPHICSTHREAD threadID); static std::vector> renderableBoxes; diff --git a/WickedEngine/wiSceneSystem.cpp b/WickedEngine/wiSceneSystem.cpp index 921cedc71..9f2e38254 100644 --- a/WickedEngine/wiSceneSystem.cpp +++ b/WickedEngine/wiSceneSystem.cpp @@ -47,7 +47,7 @@ namespace wiSceneSystem { if (IsDirty()) { - SetClean(); + SetDirty(false); XMVECTOR S_local = XMLoadFloat3(&scale_local); XMVECTOR R_local = XMLoadFloat4(&rotation_local); @@ -261,9 +261,8 @@ namespace wiSceneSystem uint32_t counter = 0; uint8_t stride; void* gpuIndexData; - if (vertex_positions.size() > 65535) + if (GetIndexFormat() == INDEXFORMAT_32BIT) { - indexFormat = INDEXFORMAT_32BIT; gpuIndexData = new uint32_t[indices.size()]; stride = sizeof(uint32_t); @@ -275,7 +274,6 @@ namespace wiSceneSystem } else { - indexFormat = INDEXFORMAT_16BIT; gpuIndexData = new uint16_t[indices.size()]; stride = sizeof(uint16_t); @@ -780,7 +778,7 @@ namespace wiSceneSystem RunCameraUpdateSystem(transforms, cameras); - RunDecalUpdateSystem(transforms, aabb_decals, decals); + RunDecalUpdateSystem(transforms, materials, aabb_decals, decals); RunProbeUpdateSystem(transforms, aabb_probes, probes); @@ -1005,10 +1003,7 @@ namespace wiSceneSystem aabb_probes.Create(entity); - EnvironmentProbeComponent& probe = probes.Create(entity); - probe.isUpToDate = false; - probe.realTime = false; - probe.textureIndex = -1; + probes.Create(entity); return entity; } @@ -1030,17 +1025,19 @@ namespace wiSceneSystem aabb_decals.Create(entity); - DecalComponent& decal = decals.Create(entity); - decal.textureName = textureName; - decal.normalMapName = normalMapName; + decals.Create(entity); - if (!decal.textureName.empty()) + MaterialComponent& material = materials.Create(entity); + + if (!textureName.empty()) { - decal.texture = (Texture2D*)wiResourceManager::GetGlobal()->add(decal.textureName); + material.baseColorMapName = textureName; + material.baseColorMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material.baseColorMapName); } - if (!decal.normalMapName.empty()) + if (!normalMapName.empty()) { - decal.normal = (Texture2D*)wiResourceManager::GetGlobal()->add(decal.normalMapName); + material.normalMapName = normalMapName; + material.normalMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material.normalMapName); } return entity; @@ -1219,7 +1216,7 @@ namespace wiSceneSystem for (size_t i = 0; i < animations.GetCount(); ++i) { AnimationComponent& animation = animations[i]; - if (!animation.playing && animation.timer == 0.0f) + if (!animation.IsPlaying() && animation.timer == 0.0f) { continue; } @@ -1326,12 +1323,12 @@ namespace wiSceneSystem } - if (animation.playing) + if (animation.IsPlaying()) { animation.timer += dt; } - if (animation.looped && animation.timer > animation.length) + if (animation.IsLooped() && animation.timer > animation.length) { animation.timer = 0.0f; } @@ -1503,8 +1500,8 @@ namespace wiSceneSystem aabb.create(XMFLOAT3(FLT_MAX, FLT_MAX, FLT_MAX), XMFLOAT3(-FLT_MAX, -FLT_MAX, -FLT_MAX)); object.rendertypeMask = 0; - object.dynamic = false; - object.cast_shadow = false; + object.SetDynamic(false); + object.SetCastShadow(false); if (object.meshID != INVALID_ENTITY) { @@ -1518,7 +1515,7 @@ namespace wiSceneSystem if (mesh->IsSkinned() || mesh->IsDynamic()) { - object.dynamic = true; + object.SetDynamic(true); } for (auto& subset : mesh->subsets) @@ -1544,7 +1541,7 @@ namespace wiSceneSystem XMStoreFloat4(&waterPlane, _refPlane); } - object.cast_shadow |= material->IsCastingShadow(); + object.SetCastShadow(material->IsCastingShadow()); } } } @@ -1566,6 +1563,7 @@ namespace wiSceneSystem } void RunDecalUpdateSystem( const ComponentManager& transforms, + const ComponentManager& materials, ComponentManager& aabb_decals, ComponentManager& decals ) @@ -1594,6 +1592,12 @@ namespace wiSceneSystem AABB& aabb = aabb_decals[i]; aabb.createFromHalfWidth(XMFLOAT3(0, 0, 0), XMFLOAT3(1, 1, 1)); aabb = aabb.get(transform.world); + + const MaterialComponent& material = *materials.GetComponent(entity); + decal.color = material.baseColor; + decal.emissive = material.emissive; + decal.texture = material.GetBaseColorMap(); + decal.normal = material.GetNormalMap(); } } void RunProbeUpdateSystem( @@ -1672,7 +1676,7 @@ namespace wiSceneSystem sunDirection = light.direction; sunColor = light.color; - if (light.shadow) + if (light.IsCastingShadow()) { XMFLOAT2 screen = XMFLOAT2((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y); float nearPlane = cascadeCamera.zNearP; @@ -1744,7 +1748,7 @@ namespace wiSceneSystem break; case LightComponent::SPOT: { - if (light.shadow) + if (light.IsCastingShadow()) { if (light.shadowCam_spotLight.empty()) { @@ -1764,7 +1768,7 @@ namespace wiSceneSystem case LightComponent::RECTANGLE: case LightComponent::TUBE: { - if (light.shadow) + if (light.IsCastingShadow()) { if (light.shadowCam_pointLight.empty()) { diff --git a/WickedEngine/wiSceneSystem.h b/WickedEngine/wiSceneSystem.h index 6fe527972..ca1e19a78 100644 --- a/WickedEngine/wiSceneSystem.h +++ b/WickedEngine/wiSceneSystem.h @@ -55,10 +55,10 @@ namespace wiSceneSystem XMFLOAT4 rotation_local = XMFLOAT4(0, 0, 0, 1); XMFLOAT3 translation_local = XMFLOAT3(0, 0, 0); + // Non-serialized attributes: XMFLOAT4X4 world = IDENTITYMATRIX; - inline void SetDirty() { _flags |= DIRTY; } - inline void SetClean() { _flags &= ~DIRTY; } + inline void SetDirty(bool value = true) { if (value) { _flags |= DIRTY; } else { _flags &= ~DIRTY; } } inline bool IsDirty() const { return _flags & DIRTY; } XMFLOAT3 GetPosition() const; @@ -85,6 +85,7 @@ namespace wiSceneSystem struct PreviousFrameTransformComponent { + // Non-serialized attributes: XMFLOAT4X4 world_prev; void Serialize(wiArchive& archive); @@ -133,17 +134,15 @@ namespace wiSceneSystem float texAnimSleep = 0.0f; std::string baseColorMapName; - wiGraphicsTypes::Texture2D* baseColorMap = nullptr; - std::string surfaceMapName; - wiGraphicsTypes::Texture2D* surfaceMap = nullptr; - std::string normalMapName; - wiGraphicsTypes::Texture2D* normalMap = nullptr; - std::string displacementMapName; - wiGraphicsTypes::Texture2D* displacementMap = nullptr; + // Non-serialized attributes: + wiGraphicsTypes::Texture2D* baseColorMap = nullptr; + wiGraphicsTypes::Texture2D* surfaceMap = nullptr; + wiGraphicsTypes::Texture2D* normalMap = nullptr; + wiGraphicsTypes::Texture2D* displacementMap = nullptr; std::unique_ptr constantBuffer; inline void SetUserStencilRef(uint8_t value) @@ -195,6 +194,66 @@ namespace wiSceneSystem struct MeshComponent { + enum FLAGS + { + EMPTY = 0, + RENDERABLE = 1 << 0, + DOUBLE_SIDED = 1 << 1, + DYNAMIC = 1 << 2, + }; + uint32_t _flags = RENDERABLE; + + std::vector vertex_positions; + std::vector vertex_normals; + std::vector vertex_texcoords; + std::vector vertex_boneindices; + std::vector vertex_boneweights; + std::vector indices; + + struct MeshSubset + { + wiECS::Entity materialID = wiECS::INVALID_ENTITY; + uint32_t indexOffset = 0; + uint32_t indexCount = 0; + }; + std::vector subsets; + + float tessellationFactor = 0.0f; + float impostorDistance = 100.0f; + wiECS::Entity armatureID = wiECS::INVALID_ENTITY; + + // Non-serialized attributes: + AABB aabb; + std::unique_ptr indexBuffer; + std::unique_ptr vertexBuffer_POS; + std::unique_ptr vertexBuffer_TEX; + std::unique_ptr vertexBuffer_BON; + std::unique_ptr streamoutBuffer_POS; + std::unique_ptr streamoutBuffer_PRE; + wiRenderTarget impostorTarget; + + + inline void SetRenderable(bool value) { if (value) { _flags |= RENDERABLE; } else { _flags &= ~RENDERABLE; } } + inline void SetDoubleSided(bool value) { if (value) { _flags |= DOUBLE_SIDED; } else { _flags &= ~DOUBLE_SIDED; } } + inline void SetDynamic(bool value) { if (value) { _flags |= DYNAMIC; } else { _flags &= ~DYNAMIC; } } + + inline bool IsRenderable() const { return _flags & RENDERABLE; } + inline bool IsDoubleSided() const { return _flags & DOUBLE_SIDED; } + inline bool IsDynamic() const { return _flags & DYNAMIC; } + + bool HasImpostor() const { return impostorTarget.IsInitialized(); } + inline float GetTessellationFactor() const { return tessellationFactor; } + inline wiGraphicsTypes::INDEXBUFFER_FORMAT GetIndexFormat() const { return vertex_positions.size() > 65535 ? wiGraphicsTypes::INDEXFORMAT_32BIT : wiGraphicsTypes::INDEXFORMAT_16BIT; } + inline bool IsSkinned() const { return armatureID != wiECS::INVALID_ENTITY; } + + void CreateRenderData(); + void ComputeNormals(bool smooth); + void FlipCulling(); + void FlipNormals(); + + void Serialize(wiArchive& archive); + + struct Vertex_POS { XMFLOAT3 pos = XMFLOAT3(0.0f, 0.0f, 0.0f); @@ -306,78 +365,25 @@ namespace wiSceneSystem } }; - enum FLAGS - { - EMPTY = 0, - RENDERABLE = 1 << 0, - DOUBLE_SIDED = 1 << 1, - DYNAMIC = 1 << 2, - }; - uint32_t _flags = RENDERABLE; - - std::vector vertex_positions; - std::vector vertex_normals; - std::vector vertex_texcoords; - std::vector vertex_boneindices; - std::vector vertex_boneweights; - std::vector indices; - - struct MeshSubset - { - wiECS::Entity materialID = wiECS::INVALID_ENTITY; - uint32_t indexOffset = 0; - uint32_t indexCount = 0; - }; - std::vector subsets; - - wiGraphicsTypes::INDEXBUFFER_FORMAT indexFormat = wiGraphicsTypes::INDEXFORMAT_16BIT; - - AABB aabb; - float tessellationFactor = 0.0f; - float impostorDistance = 100.0f; - wiECS::Entity armatureID = wiECS::INVALID_ENTITY; - - - std::unique_ptr indexBuffer; - std::unique_ptr vertexBuffer_POS; - std::unique_ptr vertexBuffer_TEX; - std::unique_ptr vertexBuffer_BON; - std::unique_ptr streamoutBuffer_POS; - std::unique_ptr streamoutBuffer_PRE; - wiRenderTarget impostorTarget; - - - inline void SetRenderable(bool value) { if (value) { _flags |= RENDERABLE; } else { _flags &= ~RENDERABLE; } } - inline void SetDoubleSided(bool value) { if (value) { _flags |= DOUBLE_SIDED; } else { _flags &= ~DOUBLE_SIDED; } } - inline void SetDynamic(bool value) { if (value) { _flags |= DYNAMIC; } else { _flags &= ~DYNAMIC; } } - - inline bool IsRenderable() const { return _flags & RENDERABLE; } - inline bool IsDoubleSided() const { return _flags & DOUBLE_SIDED; } - inline bool IsDynamic() const { return _flags & DYNAMIC; } - - bool HasImpostor() const { return impostorTarget.IsInitialized(); } - inline float GetTessellationFactor() const { return tessellationFactor; } - inline wiGraphicsTypes::INDEXBUFFER_FORMAT GetIndexFormat() const { return indexFormat; } - inline bool IsSkinned() const { return armatureID != wiECS::INVALID_ENTITY; } - - void CreateRenderData(); - void ComputeNormals(bool smooth); - void FlipCulling(); - void FlipNormals(); - - void Serialize(wiArchive& archive); }; struct ObjectComponent { + enum FLAGS + { + EMPTY = 0, + RENDERABLE = 1 << 0, + CAST_SHADOW = 1 << 1, + DYNAMIC = 1 << 2, + }; + uint32_t _flags = RENDERABLE | CAST_SHADOW; + wiECS::Entity meshID = wiECS::INVALID_ENTITY; - bool renderable = true; - bool dynamic = false; - bool cast_shadow = false; - int cascadeMask = 0; // which shadow cascades to skip (0: skip none, 1: skip first, etc...) + uint32_t cascadeMask = 0; // which shadow cascades to skip (0: skip none, 1: skip first, etc...) + uint32_t rendertypeMask = 0; XMFLOAT4 color = XMFLOAT4(1, 1, 1, 1); - uint32_t rendertypeMask = 0; + // Non-serialized attributes: // occlusion result history bitfield (32 bit->32 frame history) uint32_t occlusionHistory = ~0; @@ -392,8 +398,15 @@ namespace wiSceneSystem // If it pops up for a frame after occluded, it is visible again for some frames return ((occlusionQueryID >= 0) && (occlusionHistory & 0xFFFFFFFF) == 0); } - inline bool IsDynamic() const { return dynamic; } - inline bool IsCastingShadow() const { return cast_shadow; } + + inline void SetRenderable(bool value) { if (value) { _flags |= RENDERABLE; } else { _flags &= ~RENDERABLE; } } + inline void SetCastShadow(bool value) { if (value) { _flags |= CAST_SHADOW; } else { _flags &= ~CAST_SHADOW; } } + inline void SetDynamic(bool value) { if (value) { _flags |= DYNAMIC; } else { _flags &= ~DYNAMIC; } } + + inline bool IsRenderable() const { return _flags & RENDERABLE; } + inline bool IsCastingShadow() const { return _flags & CAST_SHADOW; } + inline bool IsDynamic() const { return _flags & DYNAMIC; } + inline float GetTransparency() const { return 1 - color.w; } inline uint32_t GetRenderTypes() const { return rendertypeMask; } @@ -402,40 +415,69 @@ namespace wiSceneSystem struct RigidBodyPhysicsComponent { - enum class CollisionShape + enum FLAGS + { + EMPTY = 0, + DISABLE_DEACTIVATION = 1 << 0, + KINEMATIC = 1 << 1, + }; + uint32_t _flags = EMPTY; + + enum CollisionShape { BOX, SPHERE, CAPSULE, CONVEX_HULL, TRIANGLE_MESH, + ENUM_FORCE_UINT32 = 0xFFFFFFFF }; CollisionShape shape; - int physicsObjectID = -1; bool kinematic = false; float mass = 1.0f; float friction = 1.0f; float restitution = 1.0f; float damping = 1.0f; + // Non-serialized attributes: + int physicsObjectID = -1; + void Serialize(wiArchive& archive); }; struct SoftBodyPhysicsComponent { - int physicsObjectID = -1; + enum FLAGS + { + EMPTY = 0, + DISABLE_DEACTIVATION = 1 << 0, + }; + uint32_t _flags = EMPTY; + float mass = 1.0f; float friction = 1.0f; std::vector physicsvertices; std::vector physicsindices; + // Non-serialized attributes: + int physicsObjectID = -1; + void Serialize(wiArchive& archive); }; struct ArmatureComponent { + enum FLAGS + { + EMPTY = 0, + }; + uint32_t _flags = EMPTY; + std::vector boneCollection; std::vector inverseBindMatrices; + XMFLOAT4X4 remapMatrix = IDENTITYMATRIX; // Use this to eg. mirror the armature + + // Non-serialized attributes: std::vector skinningMatrices; GFX_STRUCT ShaderBoneType @@ -456,26 +498,66 @@ namespace wiSceneSystem std::vector boneData; std::unique_ptr boneBuffer; - // Use this to eg. mirror the armature: - XMFLOAT4X4 remapMatrix = IDENTITYMATRIX; - void Serialize(wiArchive& archive); }; struct LightComponent { - enum LightType { - DIRECTIONAL = ENTITY_TYPE_DIRECTIONALLIGHT, - POINT = ENTITY_TYPE_POINTLIGHT, - SPOT = ENTITY_TYPE_SPOTLIGHT, - SPHERE = ENTITY_TYPE_SPHERELIGHT, - DISC = ENTITY_TYPE_DISCLIGHT, - RECTANGLE = ENTITY_TYPE_RECTANGLELIGHT, - TUBE = ENTITY_TYPE_TUBELIGHT, - LIGHTTYPE_COUNT, - } type = POINT; + enum FLAGS + { + EMPTY = 0, + CAST_SHADOW = 1 << 0, + VOLUMETRICS = 1 << 1, + VISUALIZER = 1 << 2, + }; + uint32_t _flags = EMPTY; + XMFLOAT3 color = XMFLOAT3(1, 1, 1); - inline void SetType(LightType val) { + enum LightType + { + DIRECTIONAL = ENTITY_TYPE_DIRECTIONALLIGHT, + POINT = ENTITY_TYPE_POINTLIGHT, + SPOT = ENTITY_TYPE_SPOTLIGHT, + SPHERE = ENTITY_TYPE_SPHERELIGHT, + DISC = ENTITY_TYPE_DISCLIGHT, + RECTANGLE = ENTITY_TYPE_RECTANGLELIGHT, + TUBE = ENTITY_TYPE_TUBELIGHT, + LIGHTTYPE_COUNT, + ENUM_FORCE_UINT32 = 0xFFFFFFFF, + }; + LightType type = POINT; + float energy = 1.0f; + float range = 10.0f; + float fov = XM_PIDIV4; + float shadowBias = 0.0001f; + float radius = 1.0f; // area light + float width = 1.0f; // area light + float height = 1.0f; // area light + + std::vector lensFlareNames; + + // Non-serialized attributes: + XMFLOAT3 position; + XMFLOAT3 direction; + XMFLOAT4 rotation; + XMFLOAT3 front; + XMFLOAT3 right; + int shadowMap_index = -1; + int entityArray_index = -1; + + std::vector lensFlareRimTextures; + + inline void SetCastShadow(bool value) { if (value) { _flags |= CAST_SHADOW; } else { _flags &= ~CAST_SHADOW; } } + inline void SetVolumetricsEnabled(bool value) { if (value) { _flags |= VOLUMETRICS; } else { _flags &= ~VOLUMETRICS; } } + inline void SetVisualizerEnabled(bool value) { if (value) { _flags |= VISUALIZER; } else { _flags &= ~VISUALIZER; } } + + inline bool IsCastingShadow() const { return _flags & CAST_SHADOW; } + inline bool IsVolumetricsEnabled() const { return _flags & VOLUMETRICS; } + inline bool IsVisualizerEnabled() const { return _flags & VISUALIZER; } + + inline float GetRange() const { return range; } + + inline void SetType(LightType val) { type = val; switch (type) { @@ -495,34 +577,6 @@ namespace wiSceneSystem } inline LightType GetType() const { return type; } - XMFLOAT3 color = XMFLOAT3(1, 1, 1); - float energy = 1.0f; - float range = 10.0f; - float fov = XM_PIDIV4; - bool volumetrics = false; - bool visualizer = false; - bool shadow = false; - std::vector lensFlareRimTextures; - std::vector lensFlareNames; - - XMFLOAT3 position; - XMFLOAT3 direction; - XMFLOAT4 rotation; - - int shadowMap_index = -1; - int entityArray_index = -1; - - float shadowBias = 0.0001f; - - // area light props: - float radius = 1.0f; - float width = 1.0f; - float height = 1.0f; - XMFLOAT3 front; - XMFLOAT3 right; - - inline float GetRange() const { return range; } - struct SHCAM { XMFLOAT4X4 View, Projection; @@ -618,9 +672,19 @@ namespace wiSceneSystem struct CameraComponent { - float width = 0.0f, height = 0.0f; - float zNearP = 0.001f, zFarP = 800.0f; + enum FLAGS + { + EMPTY = 0, + }; + uint32_t _flags = EMPTY; + + float width = 0.0f; + float height = 0.0f; + float zNearP = 0.001f; + float zFarP = 800.0f; float fov = XM_PI / 3.0f; + + // Non-serialized attributes: XMFLOAT3 Eye, At, Up; XMFLOAT3X3 rotationMatrix; XMFLOAT4X4 View, Projection, VP; @@ -650,21 +714,42 @@ namespace wiSceneSystem struct EnvironmentProbeComponent { + enum FLAGS + { + EMPTY = 0, + DIRTY = 1 << 0, + REALTIME = 1 << 1, + }; + uint32_t _flags = DIRTY; + + // Non-serialized attributes: int textureIndex = -1; - bool realTime = false; - bool isUpToDate = false; XMFLOAT3 position; float range; XMFLOAT4X4 inverseMatrix; + inline void SetDirty(bool value = true) { if (value) { _flags |= DIRTY; } else { _flags &= ~DIRTY; } } + inline void SetRealTime(bool value) { if (value) { _flags |= REALTIME; } else { _flags &= ~REALTIME; } } + + inline bool IsDirty() const { return _flags & DIRTY; } + inline bool IsRealTime() const { return _flags & REALTIME; } + void Serialize(wiArchive& archive); }; struct ForceFieldComponent { + enum FLAGS + { + EMPTY = 0, + }; + uint32_t _flags = EMPTY; + int type = ENTITY_TYPE_FORCEFIELD_POINT; float gravity = 0.0f; // negative = deflector, positive = attractor float range = 0.0f; // affection range + + // Non-serialized attributes: XMFLOAT3 position; XMFLOAT3 direction; @@ -673,19 +758,22 @@ namespace wiSceneSystem struct DecalComponent { - XMFLOAT4 color = XMFLOAT4(1, 1, 1, 1); - XMFLOAT4 atlasMulAdd = XMFLOAT4(0, 0, 0, 0); - XMFLOAT4X4 world; + enum FLAGS + { + EMPTY = 0, + }; + uint32_t _flags = EMPTY; + + // Non-serialized attributes: + XMFLOAT4 color; + float emissive; XMFLOAT3 front; XMFLOAT3 position; float range; + XMFLOAT4 atlasMulAdd; + XMFLOAT4X4 world; - float emissive = 0; - - std::string textureName; wiGraphicsTypes::Texture2D* texture = nullptr; - - std::string normalMapName; wiGraphicsTypes::Texture2D* normal = nullptr; inline float GetOpacity() const { return color.w; } @@ -695,37 +783,54 @@ namespace wiSceneSystem struct AnimationComponent { - bool playing = false; - bool looped = true; - float timer = 0.0f; + enum FLAGS + { + EMPTY = 0, + PLAYING = 1 << 0, + LOOPED = 1 << 1, + }; + uint32_t _flags = LOOPED; float length = 0.0f; struct AnimationChannel { + enum FLAGS + { + EMPTY = 0, + }; + uint32_t _flags = EMPTY; + wiECS::Entity target = wiECS::INVALID_ENTITY; - enum class Type + enum Type { TRANSLATION, ROTATION, - SCALE - } type = Type::TRANSLATION; - enum class Mode + SCALE, + TYPE_FORCE_UINT32 = 0xFFFFFFFF + } type = TRANSLATION; + enum Mode { LINEAR, STEP, - } mode = Mode::LINEAR; + MODE_FORCE_UINT32 = 0xFFFFFFFF + } mode = LINEAR; + std::vector keyframe_times; std::vector keyframe_data; }; std::vector channels; - inline bool IsPlaying() const { return playing; } - inline bool IsLooped() const { return looped; } + // Non-serialized attributes: + float timer = 0.0f; - inline void Play() { playing = true; } - inline void Pause() { playing = false; } - inline void Stop() { playing = false; timer = 0.0f; } + inline bool IsPlaying() const { return _flags & PLAYING; } + inline bool IsLooped() const { return _flags & LOOPED; } + + inline void Play() { _flags |= PLAYING; } + inline void Pause() { _flags &= ~PLAYING; } + inline void Stop() { Pause(); timer = 0.0f; } + inline void SetLooped(bool value = true) { if (value) { _flags |= LOOPED; } else { _flags &= ~LOOPED; } } void Serialize(wiArchive& archive); }; @@ -758,7 +863,6 @@ namespace wiSceneSystem wiECS::ComponentManager emitters; wiECS::ComponentManager hairs; - AABB bounds; XMFLOAT3 sunDirection = XMFLOAT3(0, 1, 0); XMFLOAT3 sunColor = XMFLOAT3(0, 0, 0); XMFLOAT3 horizon = XMFLOAT3(0.0f, 0.0f, 0.0f); @@ -767,7 +871,6 @@ namespace wiSceneSystem float fogStart = 100; float fogEnd = 1000; float fogHeight = 0; - XMFLOAT4 waterPlane = XMFLOAT4(0, 1, 0, 0); float cloudiness = 0.0f; float cloudScale = 0.0003f; float cloudSpeed = 0.1f; @@ -775,6 +878,10 @@ namespace wiSceneSystem float windRandomness = 5; float windWaveSize = 1; + // Non-serialized attributes: + AABB bounds; + XMFLOAT4 waterPlane = XMFLOAT4(0, 1, 0, 0); + // Update all components by a given timestep (in seconds): void Update(float dt); // Remove everything from the scene that it owns: @@ -883,6 +990,7 @@ namespace wiSceneSystem ); void RunDecalUpdateSystem( const wiECS::ComponentManager& transforms, + const wiECS::ComponentManager& materials, wiECS::ComponentManager& aabb_decals, wiECS::ComponentManager& decals ); diff --git a/WickedEngine/wiSceneSystem_Serializers.cpp b/WickedEngine/wiSceneSystem_Serializers.cpp index 71d192ac0..01d9b4046 100644 --- a/WickedEngine/wiSceneSystem_Serializers.cpp +++ b/WickedEngine/wiSceneSystem_Serializers.cpp @@ -1,4 +1,6 @@ #include "wiSceneSystem.h" +#include "wiResourceManager.h" +#include "wiArchive.h" namespace wiSceneSystem { @@ -36,6 +38,8 @@ namespace wiSceneSystem archive >> scale_local; archive >> rotation_local; archive >> translation_local; + + SetDirty(); } else { @@ -86,12 +90,31 @@ namespace wiSceneSystem archive >> alphaRef; archive >> texAnimDirection; archive >> texAnimFrameRate; + archive >> texAnimSleep; archive >> baseColorMapName; archive >> surfaceMapName; archive >> normalMapName; archive >> displacementMapName; + SetDirty(); + if (!baseColorMapName.empty()) + { + baseColorMap = (wiGraphicsTypes::Texture2D*)wiResourceManager::GetGlobal()->add(baseColorMapName); + } + if (!surfaceMapName.empty()) + { + surfaceMap = (wiGraphicsTypes::Texture2D*)wiResourceManager::GetGlobal()->add(surfaceMapName); + } + if (!normalMapName.empty()) + { + normalMap = (wiGraphicsTypes::Texture2D*)wiResourceManager::GetGlobal()->add(normalMapName); + } + if (!displacementMapName.empty()) + { + displacementMap = (wiGraphicsTypes::Texture2D*)wiResourceManager::GetGlobal()->add(displacementMapName); + } + } else { @@ -112,6 +135,7 @@ namespace wiSceneSystem archive << alphaRef; archive << texAnimDirection; archive << texAnimFrameRate; + archive << texAnimSleep; archive << baseColorMapName; archive << surfaceMapName; @@ -123,99 +147,262 @@ namespace wiSceneSystem { if (archive.IsReadMode()) { + archive >> _flags; + archive >> vertex_positions; + archive >> vertex_normals; + archive >> vertex_texcoords; + archive >> vertex_boneindices; + archive >> vertex_boneweights; + archive >> indices; + + size_t subsetCount; + archive >> subsetCount; + subsets.resize(subsetCount); + for (size_t i = 0; i < subsetCount; ++i) + { + archive >> subsets[i].materialID; + archive >> subsets[i].indexOffset; + archive >> subsets[i].indexCount; + } + + archive >> tessellationFactor; + archive >> impostorDistance; + archive >> armatureID; + + CreateRenderData(); } else { + archive << _flags; + archive << vertex_positions; + archive << vertex_normals; + archive << vertex_texcoords; + archive << vertex_boneindices; + archive << vertex_boneweights; + archive << indices; + + archive << subsets.size(); + for (size_t i = 0; i < subsets.size(); ++i) + { + archive << subsets[i].materialID; + archive << subsets[i].indexOffset; + archive << subsets[i].indexCount; + } + + archive << tessellationFactor; + archive << impostorDistance; + archive << armatureID; + } } void ObjectComponent::Serialize(wiArchive& archive) { if (archive.IsReadMode()) { + archive >> _flags; + archive >> meshID; + archive >> cascadeMask; + archive >> rendertypeMask; + archive >> color; } else { + archive << _flags; + archive << meshID; + archive << cascadeMask; + archive << rendertypeMask; + archive << color; } } void RigidBodyPhysicsComponent::Serialize(wiArchive& archive) { if (archive.IsReadMode()) { + archive >> _flags; + archive >> (uint32_t&)shape; + archive >> kinematic; + archive >> mass; + archive >> friction; + archive >> restitution; + archive >> damping; } else { + archive << _flags; + archive << (uint32_t&)shape; + archive << kinematic; + archive << mass; + archive << friction; + archive << restitution; + archive << damping; } } void SoftBodyPhysicsComponent::Serialize(wiArchive& archive) { if (archive.IsReadMode()) { + archive >> _flags; + archive >> mass; + archive >> friction; + archive >> physicsvertices; + archive >> physicsindices; } else { + archive << _flags; + archive << mass; + archive << friction; + archive << physicsvertices; + archive << physicsindices; } } void ArmatureComponent::Serialize(wiArchive& archive) { if (archive.IsReadMode()) { + archive >> _flags; + archive >> boneCollection; + archive >> inverseBindMatrices; + archive >> remapMatrix; } else { + archive << _flags; + archive << boneCollection; + archive << inverseBindMatrices; + archive << remapMatrix; } } void LightComponent::Serialize(wiArchive& archive) { if (archive.IsReadMode()) { + archive >> _flags; + archive >> color; + archive >> (uint32_t&)type; + archive >> energy; + archive >> range; + archive >> fov; + archive >> shadowBias; + archive >> radius; + archive >> width; + archive >> height; + + archive >> lensFlareNames; } else { + archive << _flags; + archive << color; + archive << (uint32_t&)type; + archive << energy; + archive << range; + archive << fov; + archive << shadowBias; + archive << radius; + archive << width; + archive << height; + + archive << lensFlareNames; } } void CameraComponent::Serialize(wiArchive& archive) { if (archive.IsReadMode()) { + archive >> _flags; + archive >> width; + archive >> height; + archive >> zNearP; + archive >> zFarP; + archive >> fov; } else { + archive << _flags; + archive << width; + archive << height; + archive << zNearP; + archive << zFarP; + archive << fov; } } void EnvironmentProbeComponent::Serialize(wiArchive& archive) { if (archive.IsReadMode()) { + archive >> _flags; + + SetDirty(); } else { + archive << _flags; } } void ForceFieldComponent::Serialize(wiArchive& archive) { if (archive.IsReadMode()) { + archive >> _flags; + archive >> type; + archive >> gravity; + archive >> range; } else { + archive << _flags; + archive << type; + archive << gravity; + archive << range; } } void DecalComponent::Serialize(wiArchive& archive) { if (archive.IsReadMode()) { + archive >> _flags; } else { + archive << _flags; } } void AnimationComponent::Serialize(wiArchive& archive) { if (archive.IsReadMode()) { + archive >> _flags; + archive >> length; + + size_t channelCount; + archive >> channelCount; + channels.resize(channelCount); + for (size_t i = 0; i < channelCount; ++i) + { + archive >> channels[i]._flags; + archive >> channels[i].target; + archive >> (uint32_t&)channels[i].type; + archive >> (uint32_t&)channels[i].mode; + archive >> channels[i].keyframe_times; + archive >> channels[i].keyframe_data; + } } else { + archive << _flags; + archive << length; + + archive << channels.size(); + for (size_t i = 0; i < channels.size(); ++i) + { + archive << channels[i]._flags; + archive << channels[i].target; + archive << (uint32_t&)channels[i].type; + archive << (uint32_t&)channels[i].mode; + archive << channels[i].keyframe_times; + archive << channels[i].keyframe_data; + } } } @@ -244,6 +431,42 @@ namespace wiSceneSystem animations.Serialize(archive); emitters.Serialize(archive); hairs.Serialize(archive); + + if (archive.IsReadMode()) + { + archive >> sunDirection; + archive >> sunColor; + archive >> horizon; + archive >> zenith; + archive >> ambient; + archive >> fogStart; + archive >> fogEnd; + archive >> fogHeight; + archive >> cloudiness; + archive >> cloudScale; + archive >> cloudSpeed; + archive >> windDirection; + archive >> windRandomness; + archive >> windWaveSize; + } + else + { + archive << sunDirection; + archive << sunColor; + archive << horizon; + archive << zenith; + archive << ambient; + archive << fogStart; + archive << fogEnd; + archive << fogHeight; + archive << cloudiness; + archive << cloudScale; + archive << cloudSpeed; + archive << windDirection; + archive << windRandomness; + archive << windWaveSize; + } + } } diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index a20a1803d..e4adfa9d4 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 20; // minor bug fixes, alterations, refactors, updates - const int revision = 5; + const int revision = 6; long GetVersion()