Use stl style on stl replacement classes

This commit is contained in:
Joshua Ashton 2022-08-25 06:27:11 +00:00
parent f0965cf499
commit c2fa5f2b94
15 changed files with 89 additions and 89 deletions

View File

@ -28,10 +28,10 @@ namespace orange
static_assert(sizeof...(Args) == N);
}
constexpr T* Data() { return &m_data[0]; }
constexpr const T* Data() const { return &m_data[0]; }
constexpr T* data() { return &m_data[0]; }
constexpr const T* data() const { return &m_data[0]; }
constexpr size_t Size() const { return N; }
constexpr size_t size() const { return N; }
constexpr Array(const Array& other) = default;

View File

@ -68,7 +68,7 @@ namespace orange
}
constexpr void setAll()
constexpr void set_all()
{
if constexpr (BitCount % 32u == 0u)
{
@ -85,7 +85,7 @@ namespace orange
}
constexpr void clearAll()
constexpr void clear_all()
{
for (size_t i = 0; i < DwordCount; i++)
dwords[i] = 0u;

View File

@ -4,24 +4,24 @@
namespace orange
{
constexpr uint32_t HashString(const char* s, size_t count)
constexpr uint32_t hash_string(const char* s, size_t count)
{
return ((count ? HashString(s, count - 1) : 2166136261u) ^ s[count]) * 16777619u;
return ((count ? hash_string(s, count - 1) : 2166136261u) ^ s[count]) * 16777619u;
}
constexpr uint32_t operator"" _hash(const char* s, size_t count)
{
return HashString(s, count);
return hash_string(s, count);
}
inline size_t& hashCombine(size_t& seed) { (void)seed; return seed; }
inline size_t& hash_combine(size_t& seed) { (void)seed; return seed; }
template <typename T, typename... Rest>
inline size_t& hashCombine(size_t& seed, const T& v, Rest... rest)
inline size_t& hash_combine(size_t& seed, const T& v, Rest... rest)
{
std::hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
hashCombine(seed, rest...);
hash_combine(seed, rest...);
return seed;
}
}

View File

@ -75,7 +75,7 @@ namespace orange::stream
while (!EndOfStream(first, end) && !CharMatches(*first, delims))
{
if (array)
array->PushBack(*first);
array->push_back(*first);
first++;
count++;
}

View File

@ -50,7 +50,7 @@ namespace orange
T& back() { return data[size - 1]; }
const T& back() const { return data[size - 1]; }
void Copy(void* dst)
void copy(void* dst)
{
memcpy(dst, data, sizeof(T) * size);
}

View File

@ -21,8 +21,8 @@ namespace orange
static inline time_point now() noexcept
{
// Keep the frequency static, this doesn't change at all.
static const int64_t freq = getFrequency();
const int64_t counter = getCounter();
static const int64_t freq = get_frequency();
const int64_t counter = get_counter();
const int64_t whole = (counter / freq) * period::den;
const int64_t part = (counter % freq) * period::den / freq;
@ -30,7 +30,7 @@ namespace orange
return time_point(duration(whole + part));
}
static inline int64_t getFrequency() noexcept
static inline int64_t get_frequency() noexcept
{
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
@ -38,7 +38,7 @@ namespace orange
return freq.QuadPart;
}
static inline int64_t getCounter() noexcept
static inline int64_t get_counter() noexcept
{
LARGE_INTEGER count;
QueryPerformanceCounter(&count);

View File

@ -12,32 +12,32 @@ namespace orange
public:
SmallVector() {}
SmallVector(size_t size) { Resize(size); }
SmallVector(size_t size) { resize(size); }
SmallVector(Span<T> span)
{
Reserve(span.size);
reserve(span.size);
for (const auto& val : span)
PushBack(val);
push_back(val);
}
constexpr SmallVector(std::initializer_list<T> list)
{
Reserve(list.size());
reserve(list.size());
for (const auto& val : list)
PushBack(val);
push_back(val);
}
SmallVector (const SmallVector& x)
{
Reserve(x.Size());
reserve(x.size());
for (const auto& val : x)
PushBack(val);
push_back(val);
}
SmallVector& operator = (const SmallVector& x)
{
Clear();
Reserve(x.Size());
clear();
reserve(x.size());
for (const auto& val : x)
PushBack(val);
push_back(val);
}
~SmallVector()
@ -60,7 +60,7 @@ namespace orange
return Span<T>(*this) == StringView(x);
}
void Reserve(size_t n)
void reserve(size_t n)
{
n = PickCapacity(n);
@ -82,19 +82,19 @@ namespace orange
u.m_ptr = data;
}
size_t Size() const { return m_size; }
size_t size() const { return m_size; }
const T* Data() const { return Ptr(0); }
T* Data() { return Ptr(0); }
const T* data() const { return Ptr(0); }
T* data() { return Ptr(0); }
void Clear()
void clear()
{
Resize(0);
resize(0);
}
void Resize(size_t n)
void resize(size_t n)
{
Reserve(n);
reserve(n);
for (size_t i = n; i < m_size; i++)
Ptr(i)->~T();
@ -105,29 +105,29 @@ namespace orange
m_size = n;
}
size_t PushBack(const T& object)
size_t push_back(const T& object)
{
Reserve(m_size + 1);
reserve(m_size + 1);
new (Ptr(m_size++)) T(object);
return m_size - 1;
}
size_t PushBack(T&& object)
size_t push_back(T&& object)
{
Reserve(m_size + 1);
reserve(m_size + 1);
new (Ptr(m_size++)) T(Move(object));
return m_size - 1;
}
template<typename... Args>
size_t EmplaceBack(Args... args)
size_t emplace_back(Args... args)
{
Reserve(m_size + 1);
reserve(m_size + 1);
new (Ptr(m_size++)) T(Forward<Args>(args)...);
return m_size - 1;
}
void Erase(size_t idx)
void erase(size_t idx)
{
Ptr(idx)->~T();
@ -138,19 +138,19 @@ namespace orange
}
}
void PopBack()
void pop_back()
{
Ptr(--m_size)->~T();
}
bool Empty() const
bool empty() const
{
return Size() == 0;
return size() == 0;
}
constexpr static size_t InvalidIdx = ~(0zu);
size_t FindIdx(const T& x) const
size_t find_idx(const T& x) const
{
for (size_t i = 0; i < m_size; i++)
{
@ -161,12 +161,12 @@ namespace orange
return InvalidIdx;
}
bool Contains(const T& x) const
bool contains(const T& x) const
{
return FindIdx(x) != InvalidIdx;
return find_idx(x) != InvalidIdx;
}
void Copy(void* dst)
void copy(void* dst)
{
memcpy(dst, Ptr(0), sizeof(T) * m_size);
}

View File

@ -64,7 +64,7 @@ namespace orange
uint32_t VertexCount() const
{
// Type doesn't matter here, just want to grab m_size.
return uint32_t(vertices.Get<Vector<uint8_t>>().Size());
return uint32_t(vertices.Get<Vector<uint8_t>>().size());
}
MeshVertexType vertexType;

View File

@ -85,7 +85,7 @@ namespace orange
constexpr Swizzle(const T components[2])
{
Copy(&components[0], &components[2], data.begin());
copy(&components[0], &components[2], data.begin());
}
template <typename... Args>
@ -128,7 +128,7 @@ namespace orange
constexpr Swizzle(const T components[3])
{
Copy(&components[0], &components[3], data.begin());
copy(&components[0], &components[3], data.begin());
}
template <typename... Args>
@ -173,7 +173,7 @@ namespace orange
constexpr Swizzle(const T components[4])
{
Copy(&components[0], &components[4], data.begin());
copy(&components[0], &components[4], data.begin());
}
template <typename... Args>

View File

@ -182,7 +182,7 @@ namespace orange::Input
void flushKeys()
{
m_firstPressed.clearAll();
m_firstPressed.clear_all();
}
void addMouseMotionDelta(MouseDelta delta)

View File

@ -12,11 +12,11 @@ namespace orange
uint32_t count = 0;
function(arguments..., &count, nullptr);
outArray.Resize(count);
outArray.resize(count);
if (!count)
return 0;
function(Forward<Args>(arguments)..., &count, outArray.Data());
function(Forward<Args>(arguments)..., &count, outArray.data());
return count;
}

View File

@ -69,8 +69,8 @@ static VulkanResult<VkPipeline> CreateGraphicsPipeline(VkDevice device, const Mi
VkPipelineDynamicStateCreateInfo dynamicStateInfo =
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
.dynamicStateCount = uint32_t(dynamicStates.Size()),
.pDynamicStates = dynamicStates.Data(),
.dynamicStateCount = uint32_t(dynamicStates.size()),
.pDynamicStates = dynamicStates.data(),
};
VkVertexInputBindingDescription inputBindingDescription =
@ -239,34 +239,34 @@ int main(int argc, char** argv)
auto r_mesh = ParseOBJ(*r_objData);
auto newVertexSlice = *pooler.AllocSlice(sizeof(StaticVertex) * r_mesh->vertexData.VertexCount(), sizeof(StaticVertex));
auto newIndexSlice = *pooler.AllocSlice(sizeof(IndexType) * r_mesh->indices.Size(), sizeof(IndexType));
r_mesh->vertexData.GetStaticVertices().Copy((uint8_t*)(r_buffer->ptr) + newVertexSlice.offset);
r_mesh->indices.Copy ((uint8_t*)(r_buffer->ptr) + newIndexSlice.offset);
auto newIndexSlice = *pooler.AllocSlice(sizeof(IndexType) * r_mesh->indices.size(), sizeof(IndexType));
r_mesh->vertexData.GetStaticVertices().copy((uint8_t*)(r_buffer->ptr) + newVertexSlice.offset);
r_mesh->indices.copy ((uint8_t*)(r_buffer->ptr) + newIndexSlice.offset);
uint32_t meshIdx = uint32_t(g_meshes.EmplaceBack(Mesh
uint32_t meshIdx = uint32_t(g_meshes.emplace_back(Mesh
{
.textureIdx = 0,
.vertexOffset = uint32_t(newVertexSlice.offset / sizeof(StaticVertex)),
.indexOffset = uint32_t(newIndexSlice.offset / sizeof(IndexType)),
.indexCount = uint32_t(r_mesh->indices.Size()),
.indexCount = uint32_t(r_mesh->indices.size()),
.bounds = r_mesh->bounds,
}));
g_renderables.EmplaceBack(Renderable
g_renderables.emplace_back(Renderable
{
.transform = mat4{},
.meshIdx = meshIdx,
.color = 16_vec3,
});
g_renderables.EmplaceBack(Renderable
g_renderables.emplace_back(Renderable
{
.transform = Math::translate(32_vec3),
.meshIdx = meshIdx,
.color = 1_vec3,
});
g_renderables.EmplaceBack(Renderable
g_renderables.emplace_back(Renderable
{
.transform = Math::translate(-32_vec3),
.meshIdx = meshIdx,
@ -486,7 +486,7 @@ int main(int argc, char** argv)
};
vkUpdateDescriptorSets(r_renderContext->Device(), Size(writeImageDescriptorSet), writeImageDescriptorSet, 0, nullptr);
imageUploads.PushBack(ImageUpload
imageUploads.push_back(ImageUpload
{
.from = pngLinearSlice,
.to = *r_texture,
@ -567,7 +567,7 @@ int main(int argc, char** argv)
auto indirectBuffer = *pooler.AllocSlice(1024 * sizeof(VkDrawIndexedIndirectCommand), 256);
auto indirectPtr = reinterpret_cast<VkDrawIndexedIndirectCommand *>(indirectBuffer.ptr);
for (size_t i = 0; i < g_renderables.Size(); i++) {
for (size_t i = 0; i < g_renderables.size(); i++) {
const auto& renderable = g_renderables[i];
const uint32_t meshIdx = 0;//renderable.meshIdx;
@ -583,7 +583,7 @@ int main(int argc, char** argv)
auto countBuffer = *pooler.AllocSlice(sizeof(uint32_t), 16);
auto countPtr = reinterpret_cast<uint32_t*>(countBuffer.ptr);
*countPtr = uint32_t(g_renderables.Size());
*countPtr = uint32_t(g_renderables.size());
auto t1 = Time::now();
while (r_window->Update(handler))
@ -617,7 +617,7 @@ int main(int argc, char** argv)
.view = camera.view(),
};
g_renderables.Copy(gpuRenderables[r_swapchain->CurrentFrame()].renderables);
g_renderables.copy(gpuRenderables[r_swapchain->CurrentFrame()].renderables);
const float movementSpeed = handler.get(Input::ButtonCodes::Key_LShift) ? 64.0f : 16.0f;
@ -657,7 +657,7 @@ int main(int argc, char** argv)
};
vkCmdCopyBufferToImage(cmdBuf, upload.from.buffer, upload.to, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 1, &region);
}
imageUploads.Clear();
imageUploads.clear();
VkViewport viewport =
{

View File

@ -14,7 +14,7 @@ namespace orange
size_t operator() (const StaticVertex& key) const
{
size_t hash = 0;
return hashCombine(hash, key.pos.x, key.pos.y, key.pos.z, key.uv.x, key.uv.y, key.normal.x, key.normal.y, key.normal.z);
return hash_combine(hash, key.pos.x, key.pos.y, key.pos.z, key.uv.x, key.uv.y, key.normal.x, key.normal.y, key.normal.z);
}
};
@ -47,11 +47,11 @@ namespace orange
}
if (element == "v")
positions.EmplaceBack(vtx[0], -vtx[2], vtx[1]); // TODO remove hack and make this customizable
positions.emplace_back(vtx[0], -vtx[2], vtx[1]); // TODO remove hack and make this customizable
else if (element == "vt")
uvs.EmplaceBack(vtx[0], 1.0f - vtx[1]); // Fix the space from gl -> vk/dx
uvs.emplace_back(vtx[0], 1.0f - vtx[1]); // Fix the space from gl -> vk/dx
else if (element == "vn")
normals.EmplaceBack(vtx[0], vtx[1], vtx[2]);
normals.emplace_back(vtx[0], vtx[1], vtx[2]);
}
else if (element == "g" || element == "o")
{
@ -59,11 +59,11 @@ namespace orange
SmallVector<char, 32> name;
stream::ReadString(obj, end, " #\n", name);
name.PushBack('\0');
name.push_back('\0');
if (element == "g")
log::info("Group name: %s", name.Data());
log::info("Group name: %s", name.data());
else
log::info("Object name: %s", name.Data());
log::info("Object name: %s", name.data());
}
else if (element == "f")
{
@ -102,20 +102,20 @@ namespace orange
if (iter == indexTracker.end())
{
data.bounds.Extend(vertex.pos);
vertexIdx = vertices.PushBack(vertex);
vertexIdx = vertices.push_back(vertex);
indexTracker.emplace(vertex, vertexIdx);
}
else
vertexIdx = iter->second;
Assert(vertexIdx < MaxMeshIndex);
data.indices.PushBack(IndexType(vertexIdx));
data.indices.push_back(IndexType(vertexIdx));
}
}
else if (!element.Empty())
else if (!element.empty())
{
element.PushBack('\0');
log::info("Unknown element: %s", element.Data());
element.push_back('\0');
log::info("Unknown element: %s", element.data());
}
stream::AdvancePast(obj, end, "\n");

View File

@ -35,8 +35,8 @@ namespace orange
{
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.pApplicationInfo = &appInfo,
.enabledExtensionCount = uint32_t(instanceExtensions.Size()),
.ppEnabledExtensionNames = instanceExtensions.Data(),
.enabledExtensionCount = uint32_t(instanceExtensions.size()),
.ppEnabledExtensionNames = instanceExtensions.data(),
};
VkResult result = VK_SUCCESS;
@ -52,7 +52,7 @@ namespace orange
SmallVector<VkQueueFamilyProperties, 32> queueFamilyProperties;
VkEnumerate(vkGetPhysicalDeviceQueueFamilyProperties, queueFamilyProperties, physicalDevice);
for (uint32_t i = 0; i < queueFamilyProperties.Size(); i++)
for (uint32_t i = 0; i < queueFamilyProperties.size(); i++)
{
const auto& family = queueFamilyProperties[i];
if (family.queueFlags & VK_QUEUE_GRAPHICS_BIT)

View File

@ -118,8 +118,8 @@ namespace orange
if (!VkEnumerate(vkGetSwapchainImagesKHR, swapchainImages, context.Device(), swapchain))
return Result<Swapchain>::PrintError("Failed to get swapchain images");
SmallVector<VkImageView, 6> swapchainImageViews{ swapchainImages.Size() };
for (size_t i = 0; i < swapchainImages.Size(); i++)
SmallVector<VkImageView, 6> swapchainImageViews{ swapchainImages.size() };
for (size_t i = 0; i < swapchainImages.size(); i++)
{
VkImageViewCreateInfo imageViewInfo =
{
@ -144,7 +144,7 @@ namespace orange
.commandBufferCount = DefaultFramesInFlight,
};
if (vkAllocateCommandBuffers(context.Device(), &commandBufferInfo, commandBuffers.Data()) != VK_SUCCESS)
if (vkAllocateCommandBuffers(context.Device(), &commandBufferInfo, commandBuffers.data()) != VK_SUCCESS)
return Result<Swapchain>::PrintError("Failed to get swapchain image view");
}