1#ifndef NW4R_G3D_RES_RES_COMMON_H
2#define NW4R_G3D_RES_RES_COMMON_H
3#include <nw4r/types_nw4r.h>
7#include <revolution/GX.h>
18#define NW4R_G3D_RESFILE_NAME_DEF(VAR, STR) \
19 nw4r::g3d::ResNameData27 ResNameData_##VAR ALIGN(32) = {sizeof(STR) - 1, \
26#define NW4R_G3D_OFS_TO_RESNAME(BASE, OFS) \
27 nw4r::g3d::ResName((char*)(BASE) + (OFS) - sizeof(ulong))
33#define NW4R_G3D_RESOURCE_FUNC_DEF(T) \
34 NW4R_G3D_RESOURCE_FUNC_DEF_IMPL(T, T##Data)
35#define NW4R_G3D_RESOURCE_FUNC_DEF_EX(TCLS, TDATA) \
36 NW4R_G3D_RESOURCE_FUNC_DEF_IMPL(TCLS, TDATA)
38#define NW4R_G3D_RESOURCE_FUNC_DEF_IMPL(TCLS, TDATA) \
39 explicit TCLS(void* pData = NULL) : nw4r::g3d::ResCommon<TDATA>(pData) {} \
45 const TDATA& ref() const { \
49 bool operator==(const TCLS& rOther) const { \
50 return ptr() == rOther.ptr(); \
53 bool operator!=(const TCLS& rOther) const { \
54 return ptr() != rOther.ptr(); \
65template <
typename T>
class ResCommon {
67 explicit ResCommon(
void* pData) : mpData(
static_cast<T*
>(pData)) {}
69 explicit ResCommon(
const void* pData)
70 : mpData(
static_cast<const T*
>(pData)) {}
72 bool IsValid()
const {
73 return mpData != NULL;
79 const T* ptr()
const {
86 const T& ref()
const {
90 template <
typename T> T* ofs_to_ptr_raw(s32 ofs) {
91 return reinterpret_cast<T*
>((
char*)mpData + ofs);
93 template <
typename T>
const T* ofs_to_ptr_raw(s32 ofs)
const {
94 return reinterpret_cast<const T*
>((
char*)mpData + ofs);
97 template <
typename T> T* ofs_to_ptr(s32 ofs) {
98 u8* pPtr =
reinterpret_cast<u8*
>(mpData);
101 return reinterpret_cast<T*
>(pPtr + ofs);
106 template <
typename T>
const T* ofs_to_ptr(s32 ofs)
const {
107 const u8* pPtr =
reinterpret_cast<const u8*
>(mpData);
110 return reinterpret_cast<const T*
>(pPtr + ofs);
116 template <
typename T> T ofs_to_obj(s32 ofs) {
117 u8* pPtr =
reinterpret_cast<u8*
>(mpData);
120 return T(pPtr + ofs);
125 template <
typename T>
const T ofs_to_obj(s32 ofs)
const {
126 const u8* pPtr =
reinterpret_cast<const u8*
>(mpData);
129 return T(
const_cast<u8*
>(pPtr + ofs));
152 char str[32 -
sizeof(ulong)];
165class ResName :
public ResCommon<const ResNameData> {
167 explicit ResName(
const void* pData) : ResCommon(pData) {}
169 ulong GetLength()
const {
173 const char* GetName()
const {
177 bool operator==(
const ResName rhs)
const;
191class ResTagDL :
public ResCommon<ResTagDLData> {
193 NW4R_G3D_RESOURCE_FUNC_DEF(ResTagDL);
195 ulong GetBufSize()
const {
196 return ref().bufSize;
199 ulong GetCmdSize()
const {
200 return ref().cmdSize;
204 return const_cast<u8*
>(ofs_to_ptr<u8>(ref().toDL));
206 const u8* GetDL()
const {
207 return ofs_to_ptr<u8>(ref().toDL);
216namespace ResByteCodeData {
293inline u8 ResRead_u8(
const u8* pPtr) {
297inline ulong ResRead_ulong(
const u8* pPtr) {
298 ulong value = ResRead_u8(pPtr++) << 24;
299 value |= ResRead_u8(pPtr++) << 16;
300 value |= ResRead_u8(pPtr++) << 8;
301 value |= ResRead_u8(pPtr++) << 0;
305inline void ResWrite_u8(u8* pPtr, u8 data) {
309inline void ResWrite_u16(u8* pPtr, u16 data) {
310 ResWrite_u8(pPtr++, data >> 8);
311 ResWrite_u8(pPtr++, data >> 0);
314inline void ResWrite_ulong(u8* pPtr, ulong data) {
315 ResWrite_u8(pPtr++, data >> 24);
316 ResWrite_u8(pPtr++, data >> 16);
317 ResWrite_u8(pPtr++, data >> 8);
318 ResWrite_u8(pPtr++, data >> 0);
326inline void ResReadBPCmd(
const u8* pPtr, ulong* pOut) {
328 *pOut = ResRead_ulong(pPtr + 1);
331void ResWriteBPCmd(u8* pPtr, ulong reg);
332void ResWriteBPCmd(u8* pPtr, ulong reg, ulong mask);
333void ResWriteSSMask(u8* pPtr, ulong value);
340inline void ResReadCPCmd(
const u8* pPtr, ulong* pOut) {
342 *pOut = ResRead_ulong(pPtr + 2);
345void ResWriteCPCmd(u8* pPtr, u8 addr, ulong value);
352inline void ResReadXFCmd(
const u8* pPtr, ulong* pOut) {
354 *pOut = ResRead_ulong(pPtr + 5);
357void ResWriteXFCmd(u8* pPtr, u16 addr, ulong value);
364inline GXColor GetRGBA(u8 r, u8 g, u8 b, u8 a) {
365 return (GXColor){r, g, b, a};
367inline GXColorS10 GetRGBAS10(s16 r, s16 g, s16 b, s16 a) {
368 return (GXColorS10){r, g, b, a};
370inline GXColorS10 GetRGBAS10(
const nw4r::ut::Color &col) {
371 return (GXColorS10){col.r, col.g, col.b, col.a};
3D graphics drawing library.