Bug fixes and scene changes #267

Merged
glencelow merged 15 commits from PlayerController into main 2022-11-23 20:53:44 +08:00
8 changed files with 76 additions and 39 deletions
Showing only changes of commit ca60b64a89 - Show all commits

View File

@ -8,6 +8,7 @@ namespace SHADE
SHCameraArmComponent::SHCameraArmComponent() SHCameraArmComponent::SHCameraArmComponent()
:pitch(0.0f), yaw(0.0f), armLength(1.0f),offset(), dirty(true), lookAtCameraOrigin(true) :pitch(0.0f), yaw(0.0f), armLength(1.0f),offset(), dirty(true), lookAtCameraOrigin(true)
, targetOffset(0.0f)
{ {
} }
@ -33,6 +34,11 @@ namespace SHADE
return armLength; return armLength;
} }
SHVec3 SHCameraArmComponent::GetTargetOffset() const noexcept
{
return targetOffset;
}
void SHCameraArmComponent::SetPitch(float pitch) noexcept void SHCameraArmComponent::SetPitch(float pitch) noexcept
{ {
this->pitch = pitch; this->pitch = pitch;
@ -50,6 +56,11 @@ namespace SHADE
this->armLength = length; this->armLength = length;
dirty = true; dirty = true;
} }
void SHCameraArmComponent::SetTargetOffset(SHVec3 offset) noexcept
{
this->targetOffset = offset;
}
}//namespace SHADE }//namespace SHADE
@ -63,6 +74,8 @@ RTTR_REGISTRATION
.property("Arm Pitch", &SHCameraArmComponent::GetPitch, &SHCameraArmComponent::SetPitch) .property("Arm Pitch", &SHCameraArmComponent::GetPitch, &SHCameraArmComponent::SetPitch)
.property("Arm Yaw", &SHCameraArmComponent::GetYaw, &SHCameraArmComponent::SetYaw) .property("Arm Yaw", &SHCameraArmComponent::GetYaw, &SHCameraArmComponent::SetYaw)
.property("Arm Length", &SHCameraArmComponent::GetArmLength, &SHCameraArmComponent::SetArmLength) .property("Arm Length", &SHCameraArmComponent::GetArmLength, &SHCameraArmComponent::SetArmLength)
.property("Look At Camera Origin", &SHCameraArmComponent::lookAtCameraOrigin); .property("Look At Camera Origin", &SHCameraArmComponent::lookAtCameraOrigin)
.property("Target Offset", &SHCameraArmComponent::GetTargetOffset, &SHCameraArmComponent::SetTargetOffset)
;
} }

View File

@ -17,7 +17,7 @@ namespace SHADE
bool dirty; bool dirty;
SHVec3 offset; SHVec3 offset;
SHVec3 targetOffset;
public: public:
friend class SHCameraSystem; friend class SHCameraSystem;
SHCameraArmComponent(); SHCameraArmComponent();
@ -30,11 +30,13 @@ namespace SHADE
float GetPitch() const noexcept; float GetPitch() const noexcept;
float GetYaw() const noexcept; float GetYaw() const noexcept;
float GetArmLength() const noexcept; float GetArmLength() const noexcept;
SHVec3 GetTargetOffset() const noexcept;
//Setters //Setters
void SetPitch(float pitch) noexcept; void SetPitch(float pitch) noexcept;
void SetYaw(float yaw) noexcept; void SetYaw(float yaw) noexcept;
void SetArmLength(float length) noexcept; void SetArmLength(float length) noexcept;
void SetTargetOffset(SHVec3 offset)noexcept;
protected: protected:

View File

@ -182,7 +182,7 @@ namespace SHADE
{ {
camera.offset = arm->GetOffset(); camera.offset = arm->GetOffset();
if (arm->lookAtCameraOrigin) if (arm->lookAtCameraOrigin)
CameraLookAt(camera, camera.position); CameraLookAt(camera, camera.position + arm->GetTargetOffset());
} }
} }

View File

@ -340,7 +340,7 @@ namespace SHADE
} }
// Transfer to GPU // Transfer to GPU
if (transformDataBuffer[frameIndex]) if (transformDataBuffer[frameIndex] && !drawData.empty())
transformDataBuffer[frameIndex]->WriteToMemory(transformData.data(), static_cast<uint32_t>(transformData.size() * sizeof(SHMatrix)), 0, 0); transformDataBuffer[frameIndex]->WriteToMemory(transformData.data(), static_cast<uint32_t>(transformData.size() * sizeof(SHMatrix)), 0, 0);
} }
@ -369,7 +369,7 @@ namespace SHADE
} }
// Transfer to GPU // Transfer to GPU
if (instancedIntegerBuffer[frameIndex]) if (instancedIntegerBuffer[frameIndex] && !drawData.empty())
instancedIntegerBuffer[frameIndex]->WriteToMemory(instancedIntegerData.data(), static_cast<uint32_t>(instancedIntegerData.size() * sizeof(SHInstancedIntegerData)), 0, 0); instancedIntegerBuffer[frameIndex]->WriteToMemory(instancedIntegerData.data(), static_cast<uint32_t>(instancedIntegerData.size() * sizeof(SHInstancedIntegerData)), 0, 0);
} }
@ -507,33 +507,36 @@ namespace SHADE
isCPUBuffersDirty = false; isCPUBuffersDirty = false;
} }
// Send all buffered data to the GPU buffers // Send all buffered data to the GPU buffers if there is anything to render
using BuffUsage = vk::BufferUsageFlagBits; if (!drawData.empty())
// - Draw Data {
const uint32_t DRAW_DATA_BYTES = static_cast<uint32_t>(drawData.size() * sizeof(vk::DrawIndexedIndirectCommand)); using BuffUsage = vk::BufferUsageFlagBits;
SHVkUtil::EnsureBufferAndCopyHostVisibleData // - Draw Data
( const uint32_t DRAW_DATA_BYTES = static_cast<uint32_t>(drawData.size() * sizeof(vk::DrawIndexedIndirectCommand));
device, drawDataBuffer[frameIndex], drawData.data(), DRAW_DATA_BYTES, SHVkUtil::EnsureBufferAndCopyHostVisibleData
BuffUsage::eIndirectBuffer, (
"Batch Draw Data Buffer" device, drawDataBuffer[frameIndex], drawData.data(), DRAW_DATA_BYTES,
); BuffUsage::eIndirectBuffer,
// - Transform Buffer "Batch Draw Data Buffer"
const uint32_t TF_DATA_BYTES = static_cast<uint32_t>(transformData.size() * sizeof(SHMatrix)); );
SHVkUtil::EnsureBufferAndCopyHostVisibleData // - Transform Buffer
( const uint32_t TF_DATA_BYTES = static_cast<uint32_t>(transformData.size() * sizeof(SHMatrix));
device, transformDataBuffer[frameIndex], transformData.data(), TF_DATA_BYTES, SHVkUtil::EnsureBufferAndCopyHostVisibleData
BuffUsage::eVertexBuffer, (
"Batch Transform Buffer" device, transformDataBuffer[frameIndex], transformData.data(), TF_DATA_BYTES,
); BuffUsage::eVertexBuffer,
const uint32_t EID_DATA_BYTES = static_cast<uint32_t>(instancedIntegerData.size() * sizeof(SHInstancedIntegerData)); "Batch Transform Buffer"
SHVkUtil::EnsureBufferAndCopyHostVisibleData );
( const uint32_t EID_DATA_BYTES = static_cast<uint32_t>(instancedIntegerData.size() * sizeof(SHInstancedIntegerData));
device, instancedIntegerBuffer[frameIndex], instancedIntegerData.data(), EID_DATA_BYTES, SHVkUtil::EnsureBufferAndCopyHostVisibleData
BuffUsage::eVertexBuffer, (
"Batch Instance Data Buffer" device, instancedIntegerBuffer[frameIndex], instancedIntegerData.data(), EID_DATA_BYTES,
); BuffUsage::eVertexBuffer,
// - Material Properties Buffer "Batch Instance Data Buffer"
rebuildMaterialBuffers(frameIndex, descPool); );
// - Material Properties Buffer
rebuildMaterialBuffers(frameIndex, descPool);
}
// Mark this frame as no longer dirty // Mark this frame as no longer dirty
isDirty[frameIndex] = false; isDirty[frameIndex] = false;
@ -551,7 +554,7 @@ namespace SHADE
} }
// Nothing to draw // Nothing to draw
if (subBatches.empty()) if (drawData.empty())
return; return;
// Bind all required objects before drawing // Bind all required objects before drawing
@ -586,7 +589,7 @@ namespace SHADE
void SHBatch::rebuildMaterialBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool) void SHBatch::rebuildMaterialBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool)
{ {
if (matPropsData) if (matPropsData && !drawData.empty())
{ {
SHVkUtil::EnsureBufferAndCopyHostVisibleData SHVkUtil::EnsureBufferAndCopyHostVisibleData
( (

View File

@ -219,10 +219,11 @@ namespace SHADE
static void Exit() noexcept; static void Exit() noexcept;
static std::string GetSceneName() noexcept; static std::string GetSceneName() noexcept;
static void SetCurrentSceneName(std::string const& sceneName) noexcept; static void SetCurrentSceneName(std::string const& sceneName) noexcept;
static AssetID GetCurrentSceneAssetID() noexcept; static AssetID GetCurrentSceneAssetID() noexcept;
//Only if scene doesn't exist, and scene asset id needs to be updated to the new one //Only if scene doesn't exist, and scene asset id needs to be updated to the new one
static void SetCurrentSceneAssetID(AssetID const& newAssetID); static void SetCurrentSceneAssetID(AssetID const& newAssetID);
static bool HasSceneChanged() noexcept { return sceneChanged; }
}; };

View File

@ -48,4 +48,15 @@ namespace SHADE
{ {
GetNativeComponent()->lookAtCameraOrigin = val; GetNativeComponent()->lookAtCameraOrigin = val;
} }
Vector3 CameraArm::TargetOffset::get()
{
return Convert::ToCLI(GetNativeComponent()->GetTargetOffset());
}
void CameraArm::TargetOffset::set(Vector3 val)
{
GetNativeComponent()->SetTargetOffset(Convert::ToNative(val));
}
} }

View File

@ -36,5 +36,11 @@ namespace SHADE
void set(bool val); void set(bool val);
} }
property Vector3 TargetOffset
{
Vector3 get();
void set(Vector3 val);
}
}; };
} }

View File

@ -74,8 +74,9 @@ namespace SHADE
// Add the script in // Add the script in
script->Initialize(GameObject(entity)); script->Initialize(GameObject(entity));
entityScriptList->Insert(System::Math::Clamp(index, 0, entityScriptList->Count), script); entityScriptList->Insert(System::Math::Clamp(index, 0, entityScriptList->Count), script);
if (Application::IsPlaying) if (Application::IsPlaying && !SHSceneManager::HasSceneChanged())
{ {
// Only call immediately if we are in game and is not loading another scene
script->Awake(); script->Awake();
script->Start(); script->Start();
} }