-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from hyperlogic/feature/loading-optimizations
loading and rendering optimizations
- Loading branch information
Showing
18 changed files
with
1,192 additions
and
520 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Copyright (c) 2024 Anthony J. Thibault | ||
This software is licensed under the MIT License. See LICENSE for more details. | ||
*/ | ||
|
||
#include "binaryattribute.h" | ||
|
||
static uint32_t propertyTypeSizeArr[(size_t)BinaryAttribute::Type::NumTypes] = { | ||
0, // Unknown | ||
sizeof(int8_t), // Char | ||
sizeof(uint8_t), // UChar | ||
sizeof(int16_t), // Short | ||
sizeof(uint16_t), // UShort | ||
sizeof(int32_t), // Int | ||
sizeof(uint32_t), // UInt | ||
sizeof(float), // Float | ||
sizeof(double) // Double | ||
}; | ||
|
||
BinaryAttribute::BinaryAttribute(Type typeIn, size_t offsetIn) : | ||
type(typeIn), | ||
size(propertyTypeSizeArr[(uint32_t)typeIn]), | ||
offset(offsetIn) | ||
{ | ||
; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
Copyright (c) 2024 Anthony J. Thibault | ||
This software is licensed under the MIT License. See LICENSE for more details. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cassert> | ||
#include <cstdint> | ||
#include <functional> | ||
|
||
class BinaryAttribute | ||
{ | ||
public: | ||
enum class Type | ||
{ | ||
Unknown, | ||
Char, | ||
UChar, | ||
Short, | ||
UShort, | ||
Int, | ||
UInt, | ||
Float, | ||
Double, | ||
NumTypes | ||
}; | ||
|
||
BinaryAttribute() : type(Type::Unknown), size(0), offset(0) {} | ||
BinaryAttribute(Type typeIn, size_t offsetIn); | ||
|
||
template <typename T> | ||
const T* Get(const void* data) const | ||
{ | ||
if (type == Type::Unknown) | ||
{ | ||
return nullptr; | ||
} | ||
else | ||
{ | ||
assert(size == sizeof(T)); | ||
return reinterpret_cast<const T*>(static_cast<const uint8_t*>(data) + offset); | ||
} | ||
} | ||
|
||
template <typename T> | ||
T* Get(void* data) | ||
{ | ||
if (type == Type::Unknown) | ||
{ | ||
return nullptr; | ||
} | ||
else | ||
{ | ||
assert(size == sizeof(T)); | ||
return reinterpret_cast<T*>(static_cast<uint8_t*>(data) + offset); | ||
} | ||
} | ||
|
||
template <typename T> | ||
const T Read(const void* data) const | ||
{ | ||
const T* ptr = Get<T>(data); | ||
return ptr ? *ptr : 0; | ||
} | ||
|
||
template <typename T> | ||
bool Write(void* data, const T& val) | ||
{ | ||
T* ptr = Get<T>(data); | ||
if (ptr) | ||
{ | ||
*ptr = val; | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
template<typename T> | ||
void ForEachMut(void* data, size_t stride, size_t count, const std::function<void(T*)>& cb) | ||
{ | ||
assert(type != Type::Unknown); | ||
assert(data); | ||
uint8_t* ptr = (uint8_t*)data; | ||
for (size_t i = 0; i < count; i++) | ||
{ | ||
cb((T*)(ptr + offset)); | ||
ptr += stride; | ||
} | ||
} | ||
|
||
template<typename T> | ||
void ForEach(const void* data, size_t stride, size_t count, const std::function<void(const T*)>& cb) const | ||
{ | ||
assert(type != Type::Unknown); | ||
assert(data); | ||
const uint8_t* ptr = (const uint8_t*)data; | ||
for (size_t i = 0; i < count; i++) | ||
{ | ||
cb((const T*)(ptr + offset)); | ||
ptr += stride; | ||
} | ||
} | ||
|
||
Type type; | ||
size_t size; | ||
size_t offset; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.