2016-02-13 09:02:47 +00:00
|
|
|
#ifndef __PSHAG_TYPES_HPP__
|
|
|
|
#define __PSHAG_TYPES_HPP__
|
2015-08-17 20:33:58 +00:00
|
|
|
|
2015-08-20 02:52:07 +00:00
|
|
|
#include <vector>
|
2015-08-18 05:54:43 +00:00
|
|
|
#include <utility>
|
2015-08-22 01:58:41 +00:00
|
|
|
#include <string>
|
2015-08-17 20:33:58 +00:00
|
|
|
#include "GCNTypes.hpp"
|
2015-08-22 01:58:41 +00:00
|
|
|
#include "rstl.hpp"
|
|
|
|
#include "DataSpec/DNACommon/DNACommon.hpp"
|
2016-04-11 07:10:28 +00:00
|
|
|
#include "IOStreams.hpp"
|
2015-08-17 20:33:58 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2015-08-17 22:05:00 +00:00
|
|
|
{
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
using FourCC = hecl::FourCC;
|
2016-02-20 12:40:58 +00:00
|
|
|
using TResId = u64;
|
2015-08-23 06:42:29 +00:00
|
|
|
|
2015-08-22 01:58:41 +00:00
|
|
|
struct SObjectTag
|
|
|
|
{
|
|
|
|
FourCC type;
|
2016-02-07 07:25:34 +00:00
|
|
|
TResId id = -1;
|
2016-03-26 00:51:59 +00:00
|
|
|
operator bool() const {return id != -1;}
|
2015-08-23 06:42:29 +00:00
|
|
|
bool operator!=(const SObjectTag& other) const {return id != other.id;}
|
|
|
|
bool operator==(const SObjectTag& other) const {return id == other.id;}
|
2016-02-17 03:42:27 +00:00
|
|
|
SObjectTag() = default;
|
|
|
|
SObjectTag(FourCC tp, TResId rid) : type(tp), id(rid) {}
|
2016-04-11 07:10:28 +00:00
|
|
|
SObjectTag(CInputStream& in)
|
|
|
|
{
|
|
|
|
in.readBytesToBuf(&type, 4);
|
|
|
|
id = in.readUint32Big();
|
|
|
|
}
|
2015-08-22 01:58:41 +00:00
|
|
|
};
|
|
|
|
|
2015-08-17 20:33:58 +00:00
|
|
|
/**
|
2015-08-19 05:48:57 +00:00
|
|
|
* @brief singleton static-allocator
|
2015-08-17 20:33:58 +00:00
|
|
|
*/
|
|
|
|
template<class T>
|
|
|
|
class TOneStatic
|
|
|
|
{
|
2015-08-18 05:54:43 +00:00
|
|
|
static u8 m_allocspace[sizeof(T)];
|
2015-08-19 05:48:57 +00:00
|
|
|
static u32 m_refCount;
|
2015-08-17 20:33:58 +00:00
|
|
|
public:
|
2015-08-18 05:54:43 +00:00
|
|
|
static T* GetAllocSpace() {return (T*)m_allocspace;}
|
2015-08-17 20:33:58 +00:00
|
|
|
static u32& ReferenceCount() {return m_refCount;}
|
2015-08-18 05:54:43 +00:00
|
|
|
T* operator->() const {return (T*)m_allocspace;}
|
2015-08-18 23:30:23 +00:00
|
|
|
T& operator*() const {return *(T*)m_allocspace;}
|
2015-08-18 05:54:43 +00:00
|
|
|
|
|
|
|
void* operator new(size_t) = delete;
|
|
|
|
void operator delete(void*) = delete;
|
|
|
|
|
|
|
|
template<typename U = T>
|
|
|
|
TOneStatic(typename std::enable_if<!std::is_default_constructible<U>::value>::type* = 0)
|
2015-08-22 01:58:41 +00:00
|
|
|
{++m_refCount;}
|
2015-08-18 05:54:43 +00:00
|
|
|
template<typename U = T>
|
|
|
|
TOneStatic(typename std::enable_if<std::is_default_constructible<U>::value>::type* = 0)
|
2015-08-22 01:58:41 +00:00
|
|
|
{++m_refCount; new (m_allocspace) T();}
|
2015-08-18 05:54:43 +00:00
|
|
|
|
|
|
|
template<typename... Args> TOneStatic(Args&&... args)
|
2015-08-22 01:58:41 +00:00
|
|
|
{++m_refCount; new (m_allocspace) T(std::forward<Args>(args)...);}
|
2015-08-18 05:54:43 +00:00
|
|
|
|
2015-08-22 01:58:41 +00:00
|
|
|
~TOneStatic() {--m_refCount;}
|
2015-08-18 05:54:43 +00:00
|
|
|
|
|
|
|
template<typename... Args> void reset(Args&&... args)
|
2015-08-18 19:45:28 +00:00
|
|
|
{new (m_allocspace) T(std::forward<Args>(args)...);}
|
2015-08-17 20:33:58 +00:00
|
|
|
};
|
2015-08-18 05:54:43 +00:00
|
|
|
template<class T> u8 TOneStatic<T>::m_allocspace[sizeof(T)];
|
2015-08-17 20:33:58 +00:00
|
|
|
template<class T> u32 TOneStatic<T>::m_refCount;
|
|
|
|
|
2015-08-20 02:52:07 +00:00
|
|
|
using TUniqueId = u16;
|
2015-08-19 05:48:57 +00:00
|
|
|
using TEditorId = u32;
|
|
|
|
using TAreaId = u32;
|
|
|
|
|
2015-08-20 02:52:07 +00:00
|
|
|
#define kInvalidEditorId TEditorId(-1)
|
|
|
|
#define kInvalidUniqueId TUniqueId(-1)
|
|
|
|
#define kInvalidAreaId TAreaId(-1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-23 06:42:29 +00:00
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
template<>
|
2016-03-04 23:04:53 +00:00
|
|
|
struct hash<urde::SObjectTag>
|
2015-08-23 06:42:29 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
inline size_t operator()(const urde::SObjectTag& tag) const
|
2015-08-23 06:42:29 +00:00
|
|
|
{return tag.id;}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-02-13 09:02:47 +00:00
|
|
|
#endif // __PSHAG_TYPES_HPP__
|