custom shared_ptr updates (#1324)

This commit is contained in:
Turánszki János
2025-11-25 09:43:19 +01:00
committed by GitHub
parent c45dc7f58f
commit ffcc3abdf6
27 changed files with 375 additions and 290 deletions
@@ -495,7 +495,7 @@ bool IsDoubleSided() const { return _flags & DOUBLE_SIDED; }
void SetDoubleSided(bool value) { if (value) { _flags |= DOUBLE_SIDED; } else { _flags &= ~DOUBLE_SIDED; } }
```
It is good practice to not implement constructors and destructors for components. Wherever possible, initialization of values in declaration should be preferred. If desctructors are defined, move contructors, etc. will also need to be defined for compatibility with the [ComponentManager](#componentmanager), so default constructors and destructors should be preferred. Member objects should be able to desctruct themselves implicitly. If pointers need to be stored within the component that manage object lifetime, std::unique_ptr or std::shared_ptr can be used, which will be destructed implicitly.
It is good practice to not implement constructors and destructors for components. Wherever possible, initialization of values in declaration should be preferred. If desctructors are defined, move contructors, etc. will also need to be defined for compatibility with the [ComponentManager](#componentmanager), so default constructors and destructors should be preferred. Member objects should be able to desctruct themselves implicitly. If pointers need to be stored within the component that manage object lifetime, std::unique_ptr or wi::allocator::shared_ptr can be used, which will be destructed implicitly.
#### NameComponent
[[Header]](../../WickedEngine/wiScene.h) [[Cpp]](../../WickedEngine/wiScene.cpp)
+5 -5
View File
@@ -67,7 +67,7 @@ void ConstraintWindow::Create(EditorComponent* _editor)
collisionCheckBox.SetTooltip("Disable collision between the two bodies that this constraint targets.\nNote: changing this will recreate the constraint in the current pose relative to the bodies.");
collisionCheckBox.OnClick(forEachSelected([] (auto physicscomponent, auto args) {
physicscomponent->SetDisableSelfCollision(args.bValue);
physicscomponent->physicsobject = nullptr;
physicscomponent->physicsobject.reset();
}));
AddWidget(&collisionCheckBox);
@@ -80,7 +80,7 @@ void ConstraintWindow::Create(EditorComponent* _editor)
rebindButton.Create("Rebind Constraint");
rebindButton.OnClick(forEachSelected([](auto physicscomponent, auto args) {
physicscomponent->physicsobject = nullptr;
physicscomponent->physicsobject.reset();
}));
AddWidget(&rebindButton);
@@ -97,7 +97,7 @@ void ConstraintWindow::Create(EditorComponent* _editor)
PhysicsConstraintComponent::Type type = (PhysicsConstraintComponent::Type)args.userdata;
if (physicscomponent->type != type)
{
physicscomponent->physicsobject = nullptr;
physicscomponent->physicsobject.reset();
physicscomponent->type = type;
}
}));
@@ -109,14 +109,14 @@ void ConstraintWindow::Create(EditorComponent* _editor)
bodyAComboBox.Create("Body A: ");
bodyAComboBox.OnSelect(forEachSelected([](auto physicscomponent, auto args) {
physicscomponent->bodyA = args.userdata;
physicscomponent->physicsobject = nullptr;
physicscomponent->physicsobject.reset();
}));
AddWidget(&bodyAComboBox);
bodyBComboBox.Create("Body B: ");
bodyBComboBox.OnSelect(forEachSelected([](auto physicscomponent, auto args) {
physicscomponent->bodyB = args.userdata;
physicscomponent->physicsobject = nullptr;
physicscomponent->physicsobject.reset();
}));
AddWidget(&bodyBComboBox);
+1 -1
View File
@@ -5227,7 +5227,7 @@ void EditorComponent::Open(std::string filename)
wi::jobsystem::Execute(loadmodel_workload, [=] (wi::jobsystem::JobArgs) {
wi::backlog::post("[Editor] started loading model: " + filename);
std::shared_ptr<Scene> scene = std::make_shared<Scene>();
wi::allocator::shared_ptr<Scene> scene = wi::allocator::make_shared_single<Scene>();
if (type == FileType::WISCENE)
{
wi::scene::LoadModel(*scene, filename);
+5 -5
View File
@@ -59,7 +59,7 @@ void RigidBodyWindow::Create(EditorComponent* _editor)
RigidBodyPhysicsComponent::CollisionShape shape = (RigidBodyPhysicsComponent::CollisionShape)args.userdata;
if (physicscomponent->shape != shape)
{
physicscomponent->physicsobject = nullptr;
physicscomponent->physicsobject.reset();
physicscomponent->shape = shape;
}
})(args);
@@ -87,7 +87,7 @@ void RigidBodyWindow::Create(EditorComponent* _editor)
physicscomponent->capsule.height = args.fValue;
break;
}
physicscomponent->physicsobject = nullptr;
physicscomponent->physicsobject.reset();
}));
ZSlider.SetLocalizationEnabled(false);
@@ -106,7 +106,7 @@ void RigidBodyWindow::Create(EditorComponent* _editor)
physicsComponent->capsule.radius = args.fValue;
break;
}
physicsComponent->physicsobject = nullptr;
physicsComponent->physicsobject.reset();
}));
ZSlider.SetLocalizationEnabled(false);
AddWidget(&YSlider);
@@ -121,7 +121,7 @@ void RigidBodyWindow::Create(EditorComponent* _editor)
physicscomponent->box.halfextents.z = args.fValue;
break;
}
physicscomponent->physicsobject = nullptr;
physicscomponent->physicsobject.reset();
}));
ZSlider.SetLocalizationEnabled(false);
AddWidget(&ZSlider);
@@ -173,7 +173,7 @@ void RigidBodyWindow::Create(EditorComponent* _editor)
physicsMeshLODSlider.OnSlide(forEachSelectedPhysicsComponentWithRefresh([](auto physicscomponent, auto args) {
if (physicscomponent->mesh_lod != uint32_t(args.iValue))
{
physicscomponent->physicsobject = nullptr; // will be recreated automatically
physicscomponent->physicsobject.reset(); // will be recreated automatically
physicscomponent->mesh_lod = uint32_t(args.iValue);
}
physicscomponent->mesh_lod = uint32_t(args.iValue);
+5 -5
View File
@@ -919,9 +919,9 @@ void TerrainWindow::Create(EditorComponent* _editor)
break;
}
std::shared_ptr<wi::terrain::PerlinModifier> terrain_perlin = std::make_shared<wi::terrain::PerlinModifier>();
wi::allocator::shared_ptr<wi::terrain::PerlinModifier> terrain_perlin = wi::allocator::make_shared_single<wi::terrain::PerlinModifier>();
terrain->modifiers.emplace_back() = terrain_perlin;
std::shared_ptr<wi::terrain::VoronoiModifier> terrain_voronoi = std::make_shared<wi::terrain::VoronoiModifier>();
wi::allocator::shared_ptr<wi::terrain::VoronoiModifier> terrain_voronoi = wi::allocator::make_shared_single<wi::terrain::VoronoiModifier>();
terrain->modifiers.emplace_back() = terrain_voronoi;
perlin->Bind(terrain_perlin.get());
@@ -959,7 +959,7 @@ void TerrainWindow::Create(EditorComponent* _editor)
case 0:
{
PerlinModifierWindow* ptr = new PerlinModifierWindow;
std::shared_ptr<wi::terrain::PerlinModifier> modifier = std::make_shared<wi::terrain::PerlinModifier>();
wi::allocator::shared_ptr<wi::terrain::PerlinModifier> modifier = wi::allocator::make_shared_single<wi::terrain::PerlinModifier>();
terrain->modifiers.push_back(modifier);
ptr->From(modifier.get());
AddModifier(ptr);
@@ -968,7 +968,7 @@ void TerrainWindow::Create(EditorComponent* _editor)
case 1:
{
VoronoiModifierWindow* ptr = new VoronoiModifierWindow;
std::shared_ptr<wi::terrain::VoronoiModifier> modifier = std::make_shared<wi::terrain::VoronoiModifier>();
wi::allocator::shared_ptr<wi::terrain::VoronoiModifier> modifier = wi::allocator::make_shared_single<wi::terrain::VoronoiModifier>();
terrain->modifiers.push_back(modifier);
ptr->From(modifier.get());
AddModifier(ptr);
@@ -977,7 +977,7 @@ void TerrainWindow::Create(EditorComponent* _editor)
case 2:
{
HeightmapModifierWindow* ptr = new HeightmapModifierWindow;
std::shared_ptr<wi::terrain::HeightmapModifier> modifier = std::make_shared<wi::terrain::HeightmapModifier>();
wi::allocator::shared_ptr<wi::terrain::HeightmapModifier> modifier = wi::allocator::make_shared_single<wi::terrain::HeightmapModifier>();
terrain->modifiers.push_back(modifier);
ptr->From(modifier.get());
AddModifier(ptr);
+270 -185
View File
File diff suppressed because it is too large Load Diff
+8 -8
View File
@@ -206,22 +206,22 @@ namespace wi::audio
constexpr bool IsValid() const { return success; }
};
static std::shared_ptr<AudioInternal> audio_internal;
static wi::allocator::shared_ptr<AudioInternal> audio_internal;
void Initialize()
{
audio_internal = std::make_shared<AudioInternal>();
audio_internal = wi::allocator::make_shared_single<AudioInternal>();
}
struct SoundInternal
{
std::shared_ptr<AudioInternal> audio;
wi::allocator::shared_ptr<AudioInternal> audio;
WAVEFORMATEX wfx = {};
wi::vector<uint8_t> audioData;
};
struct SoundInstanceInternal : public IXAudio2VoiceCallback
{
std::shared_ptr<AudioInternal> audio;
wi::allocator::shared_ptr<AudioInternal> audio;
wi::allocator::shared_ptr<SoundInternal> soundinternal;
IXAudio2SourceVoice* sourceVoice = nullptr;
XAUDIO2_VOICE_DETAILS voiceDetails = {};
@@ -879,20 +879,20 @@ namespace wi::audio
}
constexpr bool IsValid() const { return success; }
};
static std::shared_ptr<AudioInternal> audio_internal;
static wi::allocator::shared_ptr<AudioInternal> audio_internal;
void Initialize()
{
audio_internal = std::make_shared<AudioInternal>();
audio_internal = wi::allocator::make_shared_single<AudioInternal>();
}
struct SoundInternal{
std::shared_ptr<AudioInternal> audio;
wi::allocator::shared_ptr<AudioInternal> audio;
FAudioWaveFormatEx wfx = {};
wi::vector<uint8_t> audioData;
};
struct SoundInstanceInternal{
std::shared_ptr<AudioInternal> audio;
wi::allocator::shared_ptr<AudioInternal> audio;
wi::allocator::shared_ptr<SoundInternal> soundinternal;
FAudioSourceVoice* sourceVoice = nullptr;
FAudioVoiceDetails voiceDetails = {};
+3 -3
View File
@@ -14,11 +14,11 @@ namespace wi::eventhandler
wi::unordered_map<int, std::list<std::function<void(uint64_t)>>> subscribers_once;
std::mutex locker;
};
std::shared_ptr<EventManager> manager = std::make_shared<EventManager>();
wi::allocator::shared_ptr<EventManager> manager = wi::allocator::make_shared_single<EventManager>();
struct EventInternal
{
std::shared_ptr<EventManager> manager;
wi::allocator::shared_ptr<EventManager> manager;
int id = 0;
std::function<void(uint64_t)> callback;
@@ -36,7 +36,7 @@ namespace wi::eventhandler
Handle Subscribe(int id, std::function<void(uint64_t)> callback)
{
Handle handle;
auto eventinternal = std::make_shared<EventInternal>();
auto eventinternal = wi::allocator::make_shared<EventInternal>();
handle.internal_state = eventinternal;
eventinternal->manager = manager;
eventinternal->id = id;
+3 -3
View File
@@ -1,7 +1,7 @@
#pragma once
#include "CommonInclude.h"
#include "wiAllocator.h"
#include <memory>
#include <functional>
namespace wi::eventhandler
@@ -12,8 +12,8 @@ namespace wi::eventhandler
struct Handle
{
std::shared_ptr<void> internal_state;
inline bool IsValid() const { return internal_state.get() != nullptr; }
wi::allocator::shared_ptr<void> internal_state;
constexpr bool IsValid() const { return internal_state.get() != nullptr; }
};
Handle Subscribe(int id, std::function<void(uint64_t)> callback);
+9 -9
View File
@@ -1172,7 +1172,7 @@ namespace dx12_internal
struct SingleDescriptor
{
std::shared_ptr<GraphicsDevice_DX12::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_DX12::AllocationHandler> allocationhandler;
D3D12_CPU_DESCRIPTOR_HANDLE handle = {};
D3D12_DESCRIPTOR_HEAP_TYPE type = {};
int index = -1; // bindless
@@ -1334,7 +1334,7 @@ namespace dx12_internal
struct Resource_DX12
{
std::shared_ptr<GraphicsDevice_DX12::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_DX12::AllocationHandler> allocationhandler;
ComPtr<D3D12MA::Allocation> allocation;
ComPtr<ID3D12Resource> resource;
SingleDescriptor srv;
@@ -1404,7 +1404,7 @@ namespace dx12_internal
};
struct Sampler_DX12
{
std::shared_ptr<GraphicsDevice_DX12::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_DX12::AllocationHandler> allocationhandler;
SingleDescriptor descriptor;
~Sampler_DX12()
@@ -1416,7 +1416,7 @@ namespace dx12_internal
};
struct QueryHeap_DX12
{
std::shared_ptr<GraphicsDevice_DX12::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_DX12::AllocationHandler> allocationhandler;
ComPtr<ID3D12QueryHeap> heap;
~QueryHeap_DX12()
@@ -1428,7 +1428,7 @@ namespace dx12_internal
};
struct PipelineState_DX12
{
std::shared_ptr<GraphicsDevice_DX12::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_DX12::AllocationHandler> allocationhandler;
ComPtr<ID3D12PipelineState> resource;
ComPtr<ID3D12RootSignature> rootSignature;
@@ -1488,7 +1488,7 @@ namespace dx12_internal
};
struct RTPipelineState_DX12
{
std::shared_ptr<GraphicsDevice_DX12::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_DX12::AllocationHandler> allocationhandler;
ComPtr<ID3D12StateObject> resource;
ComPtr<ID3D12StateObjectProperties> stateObjectProperties;
@@ -1508,7 +1508,7 @@ namespace dx12_internal
};
struct SwapChain_DX12
{
std::shared_ptr<GraphicsDevice_DX12::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_DX12::AllocationHandler> allocationhandler;
#ifdef PLATFORM_XBOX
uint32_t bufferIndex = 0;
#else
@@ -1545,7 +1545,7 @@ namespace dx12_internal
};
struct VideoDecoder_DX12
{
std::shared_ptr<GraphicsDevice_DX12::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_DX12::AllocationHandler> allocationhandler;
ComPtr<ID3D12VideoDecoderHeap> decoder_heap;
ComPtr<ID3D12VideoDecoder> decoder;
@@ -2441,7 +2441,7 @@ std::mutex queue_locker;
allocatorDesc.Flags |= D3D12MA::ALLOCATOR_FLAG_DEFAULT_POOLS_NOT_ZEROED;
allocatorDesc.Flags |= D3D12MA::ALLOCATOR_FLAG_MSAA_TEXTURES_ALWAYS_COMMITTED;
allocationhandler = std::make_shared<AllocationHandler>();
allocationhandler = wi::allocator::make_shared_single<AllocationHandler>();
allocationhandler->device = device;
hr = dx12_check(D3D12MA::CreateAllocator(&allocatorDesc, &allocationhandler->allocator));
+1 -1
View File
@@ -617,7 +617,7 @@ namespace wi::graphics
}
}
};
std::shared_ptr<AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<AllocationHandler> allocationhandler;
};
+18 -18
View File
@@ -655,7 +655,7 @@ namespace vulkan_internal
};
struct Buffer_Vulkan
{
std::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
VmaAllocation allocation = nullptr;
VkBuffer resource = VK_NULL_HANDLE;
struct BufferSubresource
@@ -753,7 +753,7 @@ namespace vulkan_internal
};
struct Texture_Vulkan
{
std::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
VmaAllocation allocation = nullptr;
VkImage resource = VK_NULL_HANDLE;
VkImageLayout defaultLayout = VK_IMAGE_LAYOUT_GENERAL;
@@ -864,7 +864,7 @@ namespace vulkan_internal
};
struct Sampler_Vulkan
{
std::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
VkSampler resource = VK_NULL_HANDLE;
int index = -1;
@@ -881,7 +881,7 @@ namespace vulkan_internal
};
struct QueryHeap_Vulkan
{
std::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
VkQueryPool pool = VK_NULL_HANDLE;
~QueryHeap_Vulkan()
@@ -896,11 +896,11 @@ namespace vulkan_internal
};
struct Shader_Vulkan
{
std::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
VkShaderModule shaderModule = VK_NULL_HANDLE;
VkPipeline pipeline_cs = VK_NULL_HANDLE;
VkPipelineShaderStageCreateInfo stageInfo = {};
std::shared_ptr<GraphicsDevice_Vulkan::PSOLayout> layout_lifetime; // lifetime management only
wi::allocator::shared_ptr<GraphicsDevice_Vulkan::PSOLayout> layout_lifetime; // lifetime management only
VkPipelineLayout pipelineLayout_cs = VK_NULL_HANDLE; // no lifetime management here
VkDescriptorSetLayout descriptorSetLayout = VK_NULL_HANDLE; // no lifetime management here
wi::vector<VkDescriptorSetLayoutBinding> layoutBindings;
@@ -928,9 +928,9 @@ namespace vulkan_internal
};
struct PipelineState_Vulkan
{
std::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
VkPipeline pipeline = VK_NULL_HANDLE;
std::shared_ptr<GraphicsDevice_Vulkan::PSOLayout> layout_lifetime; // lifetime management only
wi::allocator::shared_ptr<GraphicsDevice_Vulkan::PSOLayout> layout_lifetime; // lifetime management only
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE; // no lifetime management here
VkDescriptorSetLayout descriptorSetLayout = VK_NULL_HANDLE; // no lifetime management here
wi::vector<VkDescriptorSetLayoutBinding> layoutBindings;
@@ -968,7 +968,7 @@ namespace vulkan_internal
};
struct BVH_Vulkan
{
std::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
VmaAllocation allocation = nullptr;
VkBuffer buffer = VK_NULL_HANDLE;
VkAccelerationStructureKHR resource = VK_NULL_HANDLE;
@@ -996,7 +996,7 @@ namespace vulkan_internal
};
struct RTPipelineState_Vulkan
{
std::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
VkPipeline pipeline;
~RTPipelineState_Vulkan()
@@ -1011,7 +1011,7 @@ namespace vulkan_internal
};
struct SwapChain_Vulkan
{
std::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
VkSwapchainKHR swapChain = VK_NULL_HANDLE;
VkFormat swapChainImageFormat;
VkExtent2D swapChainExtent;
@@ -1061,7 +1061,7 @@ namespace vulkan_internal
};
struct VideoDecoder_Vulkan
{
std::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler;
VkVideoSessionKHR video_session = VK_NULL_HANDLE;
VkVideoSessionParametersKHR session_parameters = VK_NULL_HANDLE;
wi::vector<VmaAllocation> allocations;
@@ -1111,7 +1111,7 @@ namespace vulkan_internal
SwapChain_Vulkan* internal_state,
VkPhysicalDevice physicalDevice,
VkDevice device,
std::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler
wi::allocator::shared_ptr<GraphicsDevice_Vulkan::AllocationHandler> allocationhandler
)
{
// In vulkan, the swapchain recreate can happen whenever it gets outdated, it's not in application's control
@@ -2325,7 +2325,7 @@ using namespace vulkan_internal;
// Issue: https://github.com/KhronosGroup/Vulkan-Docs/issues/2079
capabilities |= GraphicsDeviceCapability::COPY_BETWEEN_DIFFERENT_IMAGE_ASPECTS_NOT_SUPPORTED;
wi::unordered_map<uint32_t, std::shared_ptr<std::mutex>> queue_lockers;
wi::unordered_map<uint32_t, wi::allocator::shared_ptr<std::mutex>> queue_lockers;
TOPLEVEL_ACCELERATION_STRUCTURE_INSTANCE_SIZE = sizeof(VkAccelerationStructureInstanceKHR);
@@ -3087,7 +3087,7 @@ using namespace vulkan_internal;
float queuePriority = 1.0f;
for (uint32_t queueFamily : uniqueQueueFamilies)
{
queue_lockers.emplace(queueFamily, std::make_shared<std::mutex>());
queue_lockers.emplace(queueFamily, wi::allocator::make_shared_single<std::mutex>());
VkDeviceQueueCreateInfo queueCreateInfo = {};
queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
queueCreateInfo.queueFamilyIndex = queueFamily;
@@ -3165,7 +3165,7 @@ using namespace vulkan_internal;
capabilities |= GraphicsDeviceCapability::CACHE_COHERENT_UMA;
}
allocationhandler = std::make_shared<AllocationHandler>();
allocationhandler = wi::allocator::make_shared_single<AllocationHandler>();
allocationhandler->device = device;
allocationhandler->instance = instance;
@@ -5028,7 +5028,7 @@ using namespace vulkan_internal;
if (res == VK_SUCCESS)
{
auto& cached_layout = pso_layout_cache[layout_hasher];
cached_layout = std::make_shared<PSOLayout>();
cached_layout = wi::allocator::make_shared<PSOLayout>();
cached_layout->allocationhandler = allocationhandler;
cached_layout->descriptorSetLayout = internal_state->descriptorSetLayout;
cached_layout->pipelineLayout = internal_state->pipelineLayout_cs;
@@ -5532,7 +5532,7 @@ using namespace vulkan_internal;
if (res == VK_SUCCESS)
{
auto& cached_layout = pso_layout_cache[layout_hasher];
cached_layout = std::make_shared<PSOLayout>();
cached_layout = wi::allocator::make_shared<PSOLayout>();
cached_layout->allocationhandler = allocationhandler;
cached_layout->descriptorSetLayout = internal_state->descriptorSetLayout;
cached_layout->pipelineLayout = internal_state->pipelineLayout;
+4 -4
View File
@@ -210,7 +210,7 @@ namespace wi::graphics
wi::vector<uint32_t> swapchainImageIndices;
bool sparse_binding_supported = false;
std::shared_ptr<std::mutex> locker;
wi::allocator::shared_ptr<std::mutex> locker;
void clear();
void signal(VkSemaphore semaphore);
@@ -894,12 +894,12 @@ namespace wi::graphics
});
}
};
std::shared_ptr<AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<AllocationHandler> allocationhandler;
struct PSOLayout
{
std::shared_ptr<AllocationHandler> allocationhandler;
wi::allocator::shared_ptr<AllocationHandler> allocationhandler;
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
VkDescriptorSetLayout descriptorSetLayout = VK_NULL_HANDLE;
wi::vector<VkDescriptorSet> bindlessSets;
@@ -915,7 +915,7 @@ namespace wi::graphics
allocationhandler->destroylocker.unlock();
}
};
mutable wi::unordered_map<PSOLayoutHash, std::shared_ptr<PSOLayout>> pso_layout_cache;
mutable wi::unordered_map<PSOLayoutHash, wi::allocator::shared_ptr<PSOLayout>> pso_layout_cache;
mutable std::mutex pso_layout_cache_mutex;
};
}
+1 -1
View File
@@ -139,7 +139,7 @@ namespace wi::initializer
}
#ifdef _DEBUG
wilog("\nNumber of shared block allocated types: %d", (int)wi::allocator::get_shared_block_allocator_count());
wilog("\nNumber of shared allocators (there is one per object type): %d", (int)wi::allocator::get_shared_allocator_count());
#endif // _DEBUG
wi::backlog::post("");
+2 -2
View File
@@ -1,14 +1,14 @@
#pragma once
#include "CommonInclude.h"
#include "wiAllocator.h"
#include <memory>
#include <array>
namespace wi::network
{
struct Socket
{
std::shared_ptr<void> internal_state;
wi::allocator::shared_ptr<void> internal_state;
inline bool IsValid() const { return internal_state.get() != nullptr; }
};
+1 -1
View File
@@ -40,7 +40,7 @@ namespace wi::network
bool CreateSocket(Socket* sock)
{
std::shared_ptr<SocketInternal> socketinternal = std::make_shared<SocketInternal>();
wi::allocator::shared_ptr<SocketInternal> socketinternal = wi::allocator::make_shared<SocketInternal>();
sock->internal_state = socketinternal;
socketinternal->handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+4 -4
View File
@@ -37,15 +37,15 @@ namespace wi::network
WSACleanup();
}
};
inline std::shared_ptr<NetworkInternal>& network_internal()
inline wi::allocator::shared_ptr<NetworkInternal>& network_internal()
{
static std::shared_ptr<NetworkInternal> internal_state = std::make_shared<NetworkInternal>();
static wi::allocator::shared_ptr<NetworkInternal> internal_state = wi::allocator::make_shared_single<NetworkInternal>();
return internal_state;
}
struct SocketInternal
{
std::shared_ptr<NetworkInternal> networkinternal;
wi::allocator::shared_ptr<NetworkInternal> networkinternal;
SOCKET handle = NULL;
~SocketInternal()
@@ -65,7 +65,7 @@ namespace wi::network
bool CreateSocket(Socket* sock)
{
std::shared_ptr<SocketInternal> socketinternal = std::make_shared<SocketInternal>();
wi::allocator::shared_ptr<SocketInternal> socketinternal = wi::allocator::make_shared<SocketInternal>();
socketinternal->networkinternal = network_internal();
sock->internal_state = socketinternal;
+1 -1
View File
@@ -235,7 +235,7 @@ namespace wi::physics
struct PickDragOperation
{
std::shared_ptr<void> internal_state;
wi::allocator::shared_ptr<void> internal_state;
inline bool IsValid() const { return internal_state != nullptr; }
};
enum class ConstraintType
+15 -15
View File
@@ -281,7 +281,7 @@ namespace wi::physics
{
if (scene.physics_scene == nullptr)
{
auto physics_scene = std::make_shared<PhysicsScene>();
auto physics_scene = wi::allocator::make_shared_single<PhysicsScene>();
physics_scene->physics_system.Init(
cMaxBodies,
@@ -300,7 +300,7 @@ namespace wi::physics
struct RigidBody
{
std::shared_ptr<void> physics_scene;
wi::allocator::shared_ptr<void> physics_scene;
Entity entity = INVALID_ENTITY;
ShapeRefC shape;
BodyID bodyID;
@@ -384,7 +384,7 @@ namespace wi::physics
};
struct SoftBody
{
std::shared_ptr<void> physics_scene;
wi::allocator::shared_ptr<void> physics_scene;
Entity entity = INVALID_ENTITY;
BodyID bodyID;
float friction = 0;
@@ -415,7 +415,7 @@ namespace wi::physics
};
struct Constraint
{
std::shared_ptr<void> physics_scene;
wi::allocator::shared_ptr<void> physics_scene;
Entity entity = INVALID_ENTITY;
Ref<TwoBodyConstraint> constraint;
BodyID body1_self;
@@ -456,7 +456,7 @@ namespace wi::physics
{
if (physicscomponent.physicsobject == nullptr)
{
physicscomponent.physicsobject = std::make_shared<RigidBody>();
physicscomponent.physicsobject = wi::allocator::make_shared<RigidBody>();
}
return *(RigidBody*)physicscomponent.physicsobject.get();
}
@@ -468,7 +468,7 @@ namespace wi::physics
{
if (physicscomponent.physicsobject == nullptr)
{
physicscomponent.physicsobject = std::make_shared<SoftBody>();
physicscomponent.physicsobject = wi::allocator::make_shared<SoftBody>();
}
return *(SoftBody*)physicscomponent.physicsobject.get();
}
@@ -480,7 +480,7 @@ namespace wi::physics
{
if (physicscomponent.physicsobject == nullptr)
{
physicscomponent.physicsobject = std::make_shared<Constraint>();
physicscomponent.physicsobject = wi::allocator::make_shared<Constraint>();
}
return *(Constraint*)physicscomponent.physicsobject.get();
}
@@ -1289,7 +1289,7 @@ namespace wi::physics
BODYPART_COUNT
};
std::shared_ptr<void> physics_scene;
wi::allocator::shared_ptr<void> physics_scene;
RigidBody rigidbodies[BODYPART_COUNT];
Entity saved_parents[BODYPART_COUNT] = {};
Skeleton skeleton;
@@ -2150,7 +2150,7 @@ namespace wi::physics
}
if (humanoid.ragdoll == nullptr)
{
humanoid.ragdoll = std::make_shared<Ragdoll>(scene, humanoid, humanoidEntity, scale);
humanoid.ragdoll = wi::allocator::make_shared<Ragdoll>(scene, humanoid, humanoidEntity, scale);
}
});
@@ -2160,12 +2160,12 @@ namespace wi::physics
PhysicsConstraintComponent& physicscomponent = scene.constraints[args.jobIndex];
if (physicscomponent.bodyA == INVALID_ENTITY && physicscomponent.bodyB == INVALID_ENTITY)
{
physicscomponent.physicsobject = nullptr;
physicscomponent.physicsobject.reset();
return;
}
if (!scene.rigidbodies.Contains(physicscomponent.bodyA) && !scene.rigidbodies.Contains(physicscomponent.bodyB))
{
physicscomponent.physicsobject = nullptr;
physicscomponent.physicsobject.reset();
return;
}
if (physicscomponent.physicsobject != nullptr)
@@ -2181,7 +2181,7 @@ namespace wi::physics
if (body.bodyID != constraint.body1_ref)
{
// Rigidbody to constraint object mismatch!
physicscomponent.physicsobject = nullptr;
physicscomponent.physicsobject.reset();
return;
}
}
@@ -2195,7 +2195,7 @@ namespace wi::physics
if (body.bodyID != constraint.body2_ref)
{
// Rigidbody to constraint object mismatch!
physicscomponent.physicsobject = nullptr;
physicscomponent.physicsobject.reset();
return;
}
}
@@ -3927,7 +3927,7 @@ namespace wi::physics
struct PickDragOperation_Jolt
{
std::shared_ptr<void> physics_scene;
wi::allocator::shared_ptr<void> physics_scene;
Ref<TwoBodyConstraint> constraint;
float pick_distance = 0;
Body* bodyA = nullptr;
@@ -4005,7 +4005,7 @@ namespace wi::physics
return;
Body* body = (Body*)result.physicsobject;
auto internal_state = std::make_shared<PickDragOperation_Jolt>();
auto internal_state = wi::allocator::make_shared<PickDragOperation_Jolt>();
internal_state->physics_scene = scene.physics_scene;
internal_state->pick_distance = wi::math::Distance(ray.origin, result.position);
internal_state->bodyB = body;
+1 -1
View File
@@ -2640,7 +2640,7 @@ namespace wi
camera.render_to_texture.tileCount = tiledres.tileCount;
camera.render_to_texture.entityTiles = tiledres.entityTiles;
camera.render_to_texture.visibility = std::make_shared<wi::renderer::Visibility>();
camera.render_to_texture.visibility = wi::allocator::make_shared<wi::renderer::Visibility>();
}
if (getSceneUpdateEnabled())
{
+1 -1
View File
@@ -5865,7 +5865,7 @@ namespace wi::scene
if (character.pathfinding_thread == nullptr && character.process_goal)
{
character.pathfinding_thread = std::make_shared<CharacterComponent::PathfindingThreadContext>();
character.pathfinding_thread = wi::allocator::make_shared<CharacterComponent::PathfindingThreadContext>();
}
if (character.pathfinding_thread)
{
+1 -1
View File
@@ -75,7 +75,7 @@ namespace wi::scene
float time = 0;
CameraComponent camera; // for LOD and 3D sound update
std::shared_ptr<void> physics_scene;
wi::allocator::shared_ptr<void> physics_scene;
wi::SpinLock locker;
wi::primitive::AABB bounds;
wi::vector<wi::primitive::AABB> parallel_bounds;
+7 -7
View File
@@ -524,7 +524,7 @@ namespace wi::scene
} character;
// Non-serialized attributes:
std::shared_ptr<void> physicsobject = nullptr; // You can set to null to recreate the physics object the next time phsyics system will be running.
wi::allocator::shared_ptr<void> physicsobject; // You can reset this to recreate the physics object the next time phsyics system will be running.
constexpr void SetDisableDeactivation(bool value) { if (value) { _flags |= DISABLE_DEACTIVATION; } else { _flags &= ~DISABLE_DEACTIVATION; } }
constexpr void SetKinematic(bool value) { if (value) { _flags |= KINEMATIC; } else { _flags &= ~KINEMATIC; } }
@@ -637,7 +637,7 @@ namespace wi::scene
float break_distance = FLT_MAX; // how much the constraint is allowed to be exerted before breaking, calculated as relative distance
// Non-serialized attributes:
std::shared_ptr<void> physicsobject = nullptr; // You can set to null to recreate the physics object the next time phsyics system will be running.
wi::allocator::shared_ptr<void> physicsobject; // You can reset this to recreate the physics object the next time phsyics system will be running.
// Request refreshing of constraint settings without recreating the constraint
constexpr void SetRefreshParametersNeeded(bool value = true) { if (value) { _flags |= REFRESH_PARAMETERS_REQUEST; } else { _flags &= ~REFRESH_PARAMETERS_REQUEST; } }
@@ -1269,7 +1269,7 @@ namespace wi::scene
wi::vector<float> weights; // weight per physics vertex controlling the mass. (0: disable weight (no physics, only animation), 1: default weight)
// Non-serialized attributes:
std::shared_ptr<void> physicsobject = nullptr; // You can set to null to recreate the physics object the next time phsyics system will be running.
wi::allocator::shared_ptr<void> physicsobject; // You can reset this to recreate the physics object the next time phsyics system will be running.
XMFLOAT4X4 worldMatrix = wi::math::IDENTITY_MATRIX;
wi::vector<ShaderTransform> boneData; // simulated soft body nodes as bone matrices that can be fed into skinning
wi::primitive::AABB aabb;
@@ -1284,7 +1284,7 @@ namespace wi::scene
{
physicsIndices.clear();
physicsToGraphicsVertexMapping.clear();
physicsobject = {};
physicsobject.reset();
}
void SetDetail(float loddetail)
@@ -1481,7 +1481,7 @@ namespace wi::scene
wi::graphics::Texture depthstencil_resolved;
XMUINT2 tileCount = {};
wi::graphics::GPUBuffer entityTiles;
std::shared_ptr<void> visibility;
wi::allocator::shared_ptr<void> visibility;
} render_to_texture;
void CreateOrtho(float newWidth, float newHeight, float newNear, float newFar, float newVerticalSize = 1);
@@ -2333,7 +2333,7 @@ namespace wi::scene
XMFLOAT4 lookAtDeltaRotationState_Head = XMFLOAT4(0, 0, 0, 1);
XMFLOAT4 lookAtDeltaRotationState_LeftEye = XMFLOAT4(0, 0, 0, 1);
XMFLOAT4 lookAtDeltaRotationState_RightEye = XMFLOAT4(0, 0, 0, 1);
std::shared_ptr<void> ragdoll = nullptr; // physics system implementation-specific object
wi::allocator::shared_ptr<void> ragdoll; // physics system implementation-specific object
float default_facing = 0; // 0 = not yet computed, otherwise Z direction
float knee_bending = 0; // 0 = not yet computed, otherwise Z direction
@@ -2523,7 +2523,7 @@ namespace wi::scene
wi::jobsystem::Wait(ctx);
}
};
std::shared_ptr<PathfindingThreadContext> pathfinding_thread; // separate allocation, mustn't be reallocated while path finding thread is running
wi::allocator::shared_ptr<PathfindingThreadContext> pathfinding_thread; // separate allocation, mustn't be reallocated while path finding thread is running
const wi::VoxelGrid* voxelgrid = nullptr;
// Apply movement to the character in the next update
+4 -4
View File
@@ -417,7 +417,7 @@ namespace wi::terrain
grass_properties.viewDistance = chunk_width;
generator = std::make_shared<Generator>();
generator = wi::allocator::make_shared_single<Generator>();
materialEntities.resize(MATERIAL_COUNT);
}
@@ -2391,7 +2391,7 @@ namespace wi::terrain
default:
case Modifier::Type::Perlin:
{
std::shared_ptr<PerlinModifier> modifier = std::make_shared<PerlinModifier>();
wi::allocator::shared_ptr<PerlinModifier> modifier = wi::allocator::make_shared_single<PerlinModifier>();
modifiers[i] = modifier;
archive >> modifier->octaves;
archive >> modifier->seed;
@@ -2400,7 +2400,7 @@ namespace wi::terrain
break;
case Modifier::Type::Voronoi:
{
std::shared_ptr<VoronoiModifier> modifier = std::make_shared<VoronoiModifier>();
wi::allocator::shared_ptr<VoronoiModifier> modifier = wi::allocator::make_shared_single<VoronoiModifier>();
modifiers[i] = modifier;
archive >> modifier->fade;
archive >> modifier->shape;
@@ -2412,7 +2412,7 @@ namespace wi::terrain
break;
case Modifier::Type::Heightmap:
{
std::shared_ptr<HeightmapModifier> modifier = std::make_shared<HeightmapModifier>();
wi::allocator::shared_ptr<HeightmapModifier> modifier = wi::allocator::make_shared_single<HeightmapModifier>();
modifiers[i] = modifier;
archive >> modifier->amount;
archive >> modifier->data;
+2 -2
View File
@@ -295,7 +295,7 @@ namespace wi::terrain
// For generating scene on a background thread:
float generation_time_budget_milliseconds = 8; // after this much time, the generation thread will start to exit. This can help avoid a very long running, resource consuming and slow cancellation generation
std::shared_ptr<Generator> generator;
wi::allocator::shared_ptr<Generator> generator;
wi::vector<VirtualTexture*> virtual_textures_in_use;
wi::graphics::Sampler sampler;
@@ -332,7 +332,7 @@ namespace wi::terrain
float region2 = 2;
float region3 = 8;
wi::vector<std::shared_ptr<Modifier>> modifiers;
wi::vector<wi::allocator::shared_ptr<Modifier>> modifiers;
wi::vector<Modifier*> modifiers_to_remove;
Terrain();
+1 -1
View File
@@ -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 = 858;
const int revision = 859;
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);
+1 -1
View File
@@ -17,7 +17,7 @@
<DisplayString>{{ handle={handle} }}</DisplayString>
<Expand>
<Item Name="[ptr]">reinterpret_cast&lt;$T1*&gt;(handle &amp; (~0ull &lt;&lt; 8ull))</Item>
<Item Name="[allocator]">block_allocators[handle &amp; 0xFF]</Item>
<Item Name="[allocator]">shared_allocators[handle &amp; 0xFF]</Item>
</Expand>
</Type>