mirror of
https://github.com/PrimeDecomp/prime.git
synced 2025-12-16 17:37:02 +00:00
Start matching CScriptPlatform; more CScriptMazeNode
Former-commit-id: 135d63412c
This commit is contained in:
@@ -1,15 +1,29 @@
|
||||
#ifndef _RSTL_MATH_HPP
|
||||
#define _RSTL_MATH_HPP
|
||||
|
||||
#include "rstl/pointer_iterator.hpp"
|
||||
|
||||
namespace rstl {
|
||||
template <typename T>
|
||||
template < typename T >
|
||||
inline const T& min_val(const T& a, const T& b) {
|
||||
return (b < a) ? b : a;
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template < typename T >
|
||||
inline const T& max_val(const T& a, const T& b) {
|
||||
return (a < b) ? b : a;
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
|
||||
template < class Iter, class T >
|
||||
inline Iter find(Iter first, Iter last, const T& val) {
|
||||
return find(first, last, val, typename Iter::iterator_category());
|
||||
}
|
||||
|
||||
template < class Iter, class T >
|
||||
inline Iter find(Iter first, Iter last, const T& val, input_iterator_tag) {
|
||||
while (first != last && !(*first == val))
|
||||
++first;
|
||||
return first;
|
||||
}
|
||||
} // namespace rstl
|
||||
#endif // _RSTL_MATH_HPP
|
||||
|
||||
@@ -9,8 +9,13 @@ namespace rstl {
|
||||
template < typename T >
|
||||
class optional_object {
|
||||
public:
|
||||
optional_object() : x4_valid(false) {}
|
||||
optional_object(const T& item) : x0_item(item), x4_valid(true) {}
|
||||
optional_object() : m_valid(false) {}
|
||||
optional_object(const T& item) : m_valid(true) { rstl::construct< T >(m_data, item); }
|
||||
optional_object(const optional_object& other) : m_valid(other.m_valid) {
|
||||
if (other.m_valid) {
|
||||
rstl::construct< T >(m_data, other.data());
|
||||
}
|
||||
}
|
||||
~optional_object() { clear(); }
|
||||
|
||||
optional_object& operator=(const T& item) {
|
||||
@@ -18,24 +23,30 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
T& data() { return x0_item; }
|
||||
T* get_ptr() { return &x0_item; }
|
||||
operator bool() const { return x4_valid; }
|
||||
T& data() { return *get_ptr(); }
|
||||
const T& data() const { return *get_ptr(); }
|
||||
T* get_ptr() { return reinterpret_cast< T* >(m_data); }
|
||||
const T* get_ptr() const { return reinterpret_cast< const T* >(m_data); }
|
||||
bool valid() const { return m_valid; }
|
||||
operator bool() const { return m_valid; } // replace with valid()?
|
||||
void clear() {
|
||||
rstl::destroy(&x0_item);
|
||||
x4_valid = false;
|
||||
if (m_valid) {
|
||||
rstl::destroy(get_ptr());
|
||||
}
|
||||
m_valid = false;
|
||||
}
|
||||
|
||||
T& operator*() { return data(); }
|
||||
T* operator->() { return data(); }
|
||||
|
||||
private:
|
||||
T x0_item;
|
||||
bool x4_valid;
|
||||
u8 m_data[sizeof(T)];
|
||||
bool m_valid;
|
||||
|
||||
void assign(const T& item) {
|
||||
if (!x4_valid) {
|
||||
if (!m_valid) {
|
||||
rstl::construct(get_ptr(), item);
|
||||
x4_valid = true;
|
||||
m_valid = true;
|
||||
} else {
|
||||
data() = item;
|
||||
}
|
||||
|
||||
@@ -6,16 +6,24 @@
|
||||
#include "rstl/construct.hpp"
|
||||
|
||||
namespace rstl {
|
||||
struct input_iterator_tag {};
|
||||
struct output_iterator_tag {};
|
||||
struct forward_iterator_tag : public input_iterator_tag {};
|
||||
struct bidirectional_iterator_tag : public forward_iterator_tag {};
|
||||
struct random_access_iterator_tag : public bidirectional_iterator_tag {};
|
||||
|
||||
template < typename T, typename Vec, typename Alloc >
|
||||
class const_pointer_iterator {
|
||||
protected:
|
||||
const T* current;
|
||||
|
||||
public:
|
||||
typedef random_access_iterator_tag iterator_category;
|
||||
|
||||
const_pointer_iterator() : current(nullptr) {}
|
||||
const_pointer_iterator(const T* begin) : current(begin) {}
|
||||
void operator++() { ++current; }
|
||||
void operator--() { --current; }
|
||||
const_pointer_iterator& operator++() { ++current; return *this; }
|
||||
const_pointer_iterator& operator--() { --current; return *this; }
|
||||
T* get_pointer() const { return const_cast< T* >(current); }
|
||||
const T& operator*() const { return *get_pointer(); }
|
||||
const T* operator->() const { return get_pointer(); }
|
||||
@@ -46,6 +54,8 @@ public:
|
||||
rstl::destroy(get_pointer());
|
||||
}
|
||||
}
|
||||
pointer_iterator& operator++() { ++current; return *this; }
|
||||
pointer_iterator& operator--() { --current; return *this; }
|
||||
|
||||
friend pointer_iterator operator+(const pointer_iterator& x, int v) { return pointer_iterator(x.get_pointer() + v); }
|
||||
friend pointer_iterator operator-(const pointer_iterator& x, int v) { return pointer_iterator(x.get_pointer() - v); }
|
||||
|
||||
@@ -24,9 +24,14 @@ public:
|
||||
bool null() const { return x0_ptr == nullptr; }
|
||||
T& operator*() { return *x0_ptr; }
|
||||
const T& operator*() const { return *x0_ptr; }
|
||||
T* release() {
|
||||
T* ptr = x0_ptr;
|
||||
x0_ptr = nullptr;
|
||||
return ptr;
|
||||
}
|
||||
};
|
||||
|
||||
typedef single_ptr<void> unk_singleptr;
|
||||
typedef single_ptr< void > unk_singleptr;
|
||||
CHECK_SIZEOF(unk_singleptr, 0x4);
|
||||
} // namespace rstl
|
||||
|
||||
|
||||
Reference in New Issue
Block a user