Support basic linked elements
This commit is contained in:
56
include/PSX/GPU/Primitives/linked_elements.hpp
Normal file
56
include/PSX/GPU/Primitives/linked_elements.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef __JABYENGINE_LINKED_ELEMENTS_HPP__
|
||||
#define __JABYENGINE_LINKED_ELEMENTS_HPP__
|
||||
#include "../../Auxiliary/bits.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace GPU {
|
||||
struct Link {
|
||||
static constexpr auto AdrRange = BitRange::from_to(0, 23);
|
||||
static constexpr auto SizeRange = BitRange::from_to(24, 31);
|
||||
|
||||
static constexpr uint32_t TerminationValue = 0x00FFFFFF;
|
||||
|
||||
uint32_t value = TerminationValue;
|
||||
|
||||
constexpr Link() = default;
|
||||
constexpr Link(size_t size) : value(SizeRange.as_value(size >> 2) | TerminationValue) {
|
||||
}
|
||||
|
||||
//void add
|
||||
|
||||
constexpr void terminate() {
|
||||
this->value |= TerminationValue;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct LinkedElement : public Link {
|
||||
T element;
|
||||
|
||||
constexpr LinkedElement() : Link(sizeof(T)), element() {
|
||||
}
|
||||
|
||||
constexpr LinkedElement(const T& element) : Link(sizeof(T)), element(element) {
|
||||
}
|
||||
|
||||
constexpr const T* operator->() const {
|
||||
return &this->element;
|
||||
}
|
||||
|
||||
constexpr T* operator->() {
|
||||
return &this->element;
|
||||
}
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
template<typename T>
|
||||
struct LinkedElementCreator {
|
||||
constexpr LinkedElement<T> linked() {
|
||||
return LinkedElement<T>(*static_cast<T*>(this));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !__JABYENGINE_LINKED_ELEMENTS_HPP__
|
Reference in New Issue
Block a user