From c722dc6365f1a0759f3aea21e5d5c9c21e8bfca1 Mon Sep 17 00:00:00 2001 From: Velkog Date: Tue, 20 May 2025 22:23:08 -0700 Subject: [PATCH 1/5] Finish remainder of xPtankPool --- src/SB/Core/x/xPtankPool.cpp | 215 ++++++++++++++++++++++++++++++++++- src/SB/Core/x/xPtankPool.h | 9 -- 2 files changed, 209 insertions(+), 15 deletions(-) diff --git a/src/SB/Core/x/xPtankPool.cpp b/src/SB/Core/x/xPtankPool.cpp index 5b881a278..0c0a0750c 100644 --- a/src/SB/Core/x/xPtankPool.cpp +++ b/src/SB/Core/x/xPtankPool.cpp @@ -1,5 +1,7 @@ #include "xPtankPool.h" +#include "xMemMgr.h" + #include #include #include @@ -10,9 +12,19 @@ extern RwInt32 _rpPTankAtomicDataOffset; namespace { -#define NUM_GROUPS 2 #define MAX_PARTICLES 64 +static U8 inited; + +struct ptank_context +{ + ptank_context* next; + class RpAtomic* ptank; + U32 flags; + U32 src_blend; + U32 dst_blend; +}; + struct group_data { U32 max_size; @@ -24,7 +36,7 @@ struct group_data U32 buckets_used; }; -static group_data groups[NUM_GROUPS] = { +static group_data groups[MAX_PGT] = { { 4, rpPTANKDFLAGVTX2TEXCOORDS | rpPTANKDFLAGMATRIX | rpPTANKDFLAGCOLOR, @@ -45,7 +57,7 @@ static group_data groups[NUM_GROUPS] = { }, }; -void sort_buckets(group_data& group) +static void sort_buckets(group_data& group) { memset(group.buckets, 0, group.buckets_used * sizeof(ptank_context*)); group.buckets_used = 2; @@ -99,7 +111,46 @@ void sort_buckets(group_data& group) } } -RpAtomic* create_ptank(U32 flags) +static void init_groups() +{ + U32 total = 0; + + { + group_data* it = groups; + group_data* end = groups + MAX_PGT; + while (it != end) + { + total += it->max_size; + it++; + } + } + + total = total * sizeof(ptank_context) + (total + 4) * sizeof (ptank_context*); + U8* mem = (U8*) xMemAlloc(gActiveHeap, total, 0); + + { + group_data* it = groups; + group_data* end = groups + MAX_PGT; + while (it != end) + { + it->buckets_used = 0; + it->used = 0; + it->size = 0; + it->ptanks = (ptank_context*) mem; + + mem += it->max_size * sizeof(ptank_context); + it->buckets = (ptank_context**) mem; + + it->buckets_used = it->max_size + 2; + mem += it->buckets_used * sizeof(ptank_context**); + sort_buckets(*it); + + it++; + } + } +} + +static RpAtomic* create_ptank(U32 flags) { U32 dataFlags = flags | rpPTANKDFLAGSTRUCTURE; RpAtomic* ptank = RpPTankAtomicCreate(MAX_PARTICLES, dataFlags, rpPTANKDFLAGNONE); @@ -167,7 +218,7 @@ void render_ptank(const ptank_context& context) ptank->renderCallBack(ptank); } -int compare_ptanks(const void* e1, const void* e2) +static S32 compare_ptanks(const void* e1, const void* e2) { ptank_context* p1 = (ptank_context*) e1; ptank_context* p2 = (ptank_context*) e2; @@ -206,6 +257,71 @@ int compare_ptanks(const void* e1, const void* e2) return 0; } +U32 create_ptanks(group_data& group, unsigned long count) +{ + U32 initial_size = group.size; + if (initial_size + count > group.max_size) + { + count = group.max_size - initial_size; + } + + ptank_context* end = group.ptanks + initial_size + count; + ptank_context* it = group.ptanks + initial_size; + while (it < end) + { + RpAtomic* ptank = create_ptank(group.create_flags); + it->ptank = ptank; + + if (it->ptank == NULL) + { + break; + } + + it->flags = rpPTANKDFLAGPOSITION; + it->next = *group.buckets; + *group.buckets = it; + it++; + group.size++; + } + + return group.size - initial_size; +} + +} + +void xPTankPoolSceneEnter() +{ + inited = 1; + init_groups(); + + group_data* it = groups; + group_data* end = groups + MAX_PGT; + while (it != end) + { + double f = it->max_size - 0.f; + float scaled = float(f) * 0.25f + 0.5f; + create_ptanks(*it, (unsigned long) scaled); + + it++; + } +} + +void xPTankPoolSceneExit() +{ + inited = 0; + group_data* g = groups; + group_data* endg = g + MAX_PGT; + while (g != endg) + { + ptank_context* p = g->ptanks; + ptank_context* endp = p + g->size; + while (p != endp) + { + destroy_ptank(p->ptank); + p++; + } + g++; + } } void xPTankPoolRender() @@ -214,7 +330,7 @@ void xPTankPoolRender() RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *) false); group_data* g = groups; - group_data* endg = groups + NUM_GROUPS; + group_data* endg = groups + MAX_PGT; while (g != endg) { if (g->used != 0) @@ -247,3 +363,90 @@ void xPTankPoolRender() g++; } } + +void ptank_pool::grab_block(ptank_group_type type) +{ + this->ptank = NULL; + group_data& group = groups[type]; + if (group.used < group.size || create_ptanks(group, 1) >= 1) + { + ptank_context** end = group.buckets + group.buckets_used; + + { + ptank_context** it = group.buckets + 2; + while (it < end) + { + if (*it != NULL) { + if ( + (*it)->ptank->geometry->matList.materials[0]->texture == this->rs.texture + && (*it)->dst_blend == this->rs.dst_blend + && (*it)->src_blend == this->rs.src_blend + && !(((*it)->flags ^ this->rs.flags) & 0x1)) + { + this->ptank = (*it)->ptank; + (*it)->flags |= rpPTANKDFLAGCNSNORMAL; + *it = (*it)->next; + group.used++; + return; + } + } + it++; + } + } + + { + ptank_context** it = group.buckets; + while (it < end) + { + if (*it != NULL) { + if ((this->rs.flags & rpPTANKDFLAGPOSITION) && !((*it)->flags & rpPTANKDFLAGPOSITION)) { + destroy_ptank((*it)->ptank); + (*it)->ptank = create_ptank(group.create_flags); + } + this->ptank = (*it)->ptank; + RpMaterialSetTexture(*this->ptank->geometry->matList.materials, this->rs.texture); + RPATOMICPTANKPLUGINDATA(this->ptank)->publicData.srcBlend = this->rs.src_blend; + RPATOMICPTANKPLUGINDATA(this->ptank)->publicData.dstBlend = this->rs.dst_blend; + RPATOMICPTANKPLUGINDATA(this->ptank)->instFlags |= rpPTANKDFLAGARRAY; + + (*it)->src_blend = this->rs.src_blend; + (*it)->dst_blend = this->rs.dst_blend; + (*it)->flags = this->rs.flags | rpPTANKDFLAGCNSNORMAL; + *it = (*it)->next; + group.used++; + return; + } + + it++; + } + } + } +} + +void ptank_pool::flush() +{ + if (this->valid() != 0) { + RpPTankAtomicUnlock(this->ptank); + + S32 oldused = RPATOMICPTANKPLUGINDATA(this->ptank)->actPCount; + S32 expand = ((S32) this->used < oldused) ? oldused - this->used : 0; + expand += 0xA; + + if ((S32) (expand + this->used) > 0x40) { + expand = 0x40 - this->used; + } + + S32 total = this->used + expand; + + U8* it = this->hide.data; + U8* end = it + this->hide.stride * expand; + while (it != end) { + memset(it, 0, this->hide.size); + it = (U8*) it + this->hide.stride; + } + + RPATOMICPTANKPLUGINDATA(this->ptank)->instFlags |= 0x800000; + RPATOMICPTANKPLUGINDATA(this->ptank)->actPCount = total; + this->used = 0; + } +} diff --git a/src/SB/Core/x/xPtankPool.h b/src/SB/Core/x/xPtankPool.h index 51592dac5..a00e7d942 100644 --- a/src/SB/Core/x/xPtankPool.h +++ b/src/SB/Core/x/xPtankPool.h @@ -11,15 +11,6 @@ struct xVec2; struct xVec3; struct RpAtomic; -struct ptank_context -{ - ptank_context* next; - class RpAtomic* ptank; - U32 flags; - U32 src_blend; - U32 dst_blend; -}; - enum ptank_group_type { PGT_COLOR_MAT_UV2, From 32a8c1710a1f1ac4631d935f1c2103f715935ade Mon Sep 17 00:00:00 2001 From: Velkog Date: Tue, 20 May 2025 22:31:36 -0700 Subject: [PATCH 2/5] Format xPtankPool --- src/SB/Core/x/xPtankPool.cpp | 467 +++++++++++++++++------------------ src/SB/Core/x/xPtankPool.h | 3 +- 2 files changed, 231 insertions(+), 239 deletions(-) diff --git a/src/SB/Core/x/xPtankPool.cpp b/src/SB/Core/x/xPtankPool.cpp index 0c0a0750c..fb71d9991 100644 --- a/src/SB/Core/x/xPtankPool.cpp +++ b/src/SB/Core/x/xPtankPool.cpp @@ -14,280 +14,266 @@ namespace #define MAX_PARTICLES 64 -static U8 inited; + static U8 inited; -struct ptank_context -{ - ptank_context* next; - class RpAtomic* ptank; - U32 flags; - U32 src_blend; - U32 dst_blend; -}; - -struct group_data -{ - U32 max_size; - U32 create_flags; - ptank_context* ptanks; - ptank_context** buckets; - U32 size; - U32 used; - U32 buckets_used; -}; - -static group_data groups[MAX_PGT] = { + struct ptank_context { - 4, - rpPTANKDFLAGVTX2TEXCOORDS | rpPTANKDFLAGMATRIX | rpPTANKDFLAGCOLOR, - NULL, - NULL, - 0, - 0, - 0 - }, - { - 24, - rpPTANKDFLAGVTX2TEXCOORDS | rpPTANKDFLAGSIZE | rpPTANKDFLAGCOLOR | rpPTANKDFLAGPOSITION, - NULL, - NULL, - 0, - 0, - 0 - }, -}; - -static void sort_buckets(group_data& group) -{ - memset(group.buckets, 0, group.buckets_used * sizeof(ptank_context*)); - group.buckets_used = 2; - - ptank_context* it = group.ptanks; - ptank_context* endp = it + group.size; - while (it != endp) + ptank_context* next; + class RpAtomic* ptank; + U32 flags; + U32 src_blend; + U32 dst_blend; + }; + + struct group_data { - ptank_context** bucket = group.buckets; + U32 max_size; + U32 create_flags; + ptank_context* ptanks; + ptank_context** buckets; + U32 size; + U32 used; + U32 buckets_used; + }; + + static group_data groups[MAX_PGT] = { + { 4, rpPTANKDFLAGVTX2TEXCOORDS | rpPTANKDFLAGMATRIX | rpPTANKDFLAGCOLOR, NULL, NULL, 0, 0, + 0 }, + { 24, + rpPTANKDFLAGVTX2TEXCOORDS | rpPTANKDFLAGSIZE | rpPTANKDFLAGCOLOR | rpPTANKDFLAGPOSITION, + NULL, NULL, 0, 0, 0 }, + }; + + static void sort_buckets(group_data& group) + { + memset(group.buckets, 0, group.buckets_used * sizeof(ptank_context*)); + group.buckets_used = 2; - RwTexture* texture = it->ptank->geometry->matList.materials[0]->texture; - if (texture == NULL) + ptank_context* it = group.ptanks; + ptank_context* endp = it + group.size; + while (it != endp) { - if ((it->flags & 0x1) != 0) + ptank_context** bucket = group.buckets; + + RwTexture* texture = it->ptank->geometry->matList.materials[0]->texture; + if (texture == NULL) { - bucket++; + if ((it->flags & 0x1) != 0) + { + bucket++; + } } - } - else - { - bucket += 2; - ptank_context** end = bucket + group.buckets_used - 2; - - while (bucket < end) + else { - ptank_context* front = *bucket; - if (texture == front->ptank->geometry->matList.materials[0]->texture) + bucket += 2; + ptank_context** end = bucket + group.buckets_used - 2; + + while (bucket < end) { - if ( - it->dst_blend == front->dst_blend - && it->src_blend == front->src_blend - && ((it->flags ^ front->flags) & 0x1) == 0 - ) + ptank_context* front = *bucket; + if (texture == front->ptank->geometry->matList.materials[0]->texture) { - break; + if (it->dst_blend == front->dst_blend && + it->src_blend == front->src_blend && + ((it->flags ^ front->flags) & 0x1) == 0) + { + break; + } } + + bucket++; } - bucket++; + if (bucket == end) + { + group.buckets_used++; + } } - if (bucket == end) - { - group.buckets_used++; - } + it->next = *bucket; + *bucket = it; + it++; } - - it->next = *bucket; - *bucket = it; - it++; } -} - -static void init_groups() -{ - U32 total = 0; + static void init_groups() { - group_data* it = groups; - group_data* end = groups + MAX_PGT; - while (it != end) + U32 total = 0; + { - total += it->max_size; - it++; + group_data* it = groups; + group_data* end = groups + MAX_PGT; + while (it != end) + { + total += it->max_size; + it++; + } } - } - total = total * sizeof(ptank_context) + (total + 4) * sizeof (ptank_context*); - U8* mem = (U8*) xMemAlloc(gActiveHeap, total, 0); + total = total * sizeof(ptank_context) + (total + 4) * sizeof(ptank_context*); + U8* mem = (U8*)xMemAlloc(gActiveHeap, total, 0); - { - group_data* it = groups; - group_data* end = groups + MAX_PGT; - while (it != end) { - it->buckets_used = 0; - it->used = 0; - it->size = 0; - it->ptanks = (ptank_context*) mem; - - mem += it->max_size * sizeof(ptank_context); - it->buckets = (ptank_context**) mem; - - it->buckets_used = it->max_size + 2; - mem += it->buckets_used * sizeof(ptank_context**); - sort_buckets(*it); - - it++; + group_data* it = groups; + group_data* end = groups + MAX_PGT; + while (it != end) + { + it->buckets_used = 0; + it->used = 0; + it->size = 0; + it->ptanks = (ptank_context*)mem; + + mem += it->max_size * sizeof(ptank_context); + it->buckets = (ptank_context**)mem; + + it->buckets_used = it->max_size + 2; + mem += it->buckets_used * sizeof(ptank_context**); + sort_buckets(*it); + + it++; + } } } -} -static RpAtomic* create_ptank(U32 flags) -{ - U32 dataFlags = flags | rpPTANKDFLAGSTRUCTURE; - RpAtomic* ptank = RpPTankAtomicCreate(MAX_PARTICLES, dataFlags, rpPTANKDFLAGNONE); - if (ptank == NULL) + static RpAtomic* create_ptank(U32 flags) { - return NULL; - } + U32 dataFlags = flags | rpPTANKDFLAGSTRUCTURE; + RpAtomic* ptank = RpPTankAtomicCreate(MAX_PARTICLES, dataFlags, rpPTANKDFLAGNONE); + if (ptank == NULL) + { + return NULL; + } - RwFrame* frame = RwFrameCreate(); - if (frame == NULL) - { - RpPTankAtomicDestroy(ptank); - return NULL; - } + RwFrame* frame = RwFrameCreate(); + if (frame == NULL) + { + RpPTankAtomicDestroy(ptank); + return NULL; + } - const F32 f1 = 1.0f; - frame->modelling.at.z = f1; - frame->modelling.up.y = f1; - frame->modelling.right.x = f1; + const F32 f1 = 1.0f; + frame->modelling.at.z = f1; + frame->modelling.up.y = f1; + frame->modelling.right.x = f1; - const F32 f0 = 0.0f; - frame->modelling.up.x = f0; - frame->modelling.right.z = f0; - frame->modelling.right.y = f0; + const F32 f0 = 0.0f; + frame->modelling.up.x = f0; + frame->modelling.right.z = f0; + frame->modelling.right.y = f0; - frame->modelling.at.y = f0; - frame->modelling.at.x = f0; - frame->modelling.up.z = f0; + frame->modelling.at.y = f0; + frame->modelling.at.x = f0; + frame->modelling.up.z = f0; - frame->modelling.pos.z = f0; - frame->modelling.pos.y = f0; - frame->modelling.pos.x = f0; + frame->modelling.pos.z = f0; + frame->modelling.pos.y = f0; + frame->modelling.pos.x = f0; - frame->modelling.flags = frame->modelling.flags | rpPTANKDFLAGCNS2DROTATE | rpPTANKDFLAGCOLOR | rpPTANKDFLAGPOSITION; + frame->modelling.flags = frame->modelling.flags | rpPTANKDFLAGCNS2DROTATE | + rpPTANKDFLAGCOLOR | rpPTANKDFLAGPOSITION; - RpAtomicSetFrame(ptank, frame); + RpAtomicSetFrame(ptank, frame); - RpPTankAtomicExtPrv* ext = RPATOMICPTANKPLUGINDATA(ptank); - ext->publicData.vertexAlphaBlend = 1; + RpPTankAtomicExtPrv* ext = RPATOMICPTANKPLUGINDATA(ptank); + ext->publicData.vertexAlphaBlend = 1; - return ptank; -} + return ptank; + } -void destroy_ptank(RpAtomic *ptank) -{ - if (ptank != NULL) + void destroy_ptank(RpAtomic* ptank) { - RwFrame* frame = (RwFrame*) ptank->object.object.parent; - RpAtomicSetFrame(ptank, NULL); - if (frame != NULL) + if (ptank != NULL) { - RwFrameDestroy(frame); + RwFrame* frame = (RwFrame*)ptank->object.object.parent; + RpAtomicSetFrame(ptank, NULL); + if (frame != NULL) + { + RwFrameDestroy(frame); + } + + RpPTankAtomicDestroy(ptank); } - RpPTankAtomicDestroy(ptank); + return; } - - return; -} -void render_ptank(const ptank_context& context) -{ - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*) !(context.flags & 1)); - RpAtomic* ptank = context.ptank; - ptank->renderCallBack(ptank); -} - -static S32 compare_ptanks(const void* e1, const void* e2) -{ - ptank_context* p1 = (ptank_context*) e1; - ptank_context* p2 = (ptank_context*) e2; - - if (p1->dst_blend < p2->dst_blend) - { - return 1; - } - else if (p1->dst_blend > p2->dst_blend) + void render_ptank(const ptank_context& context) { - return -1; + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)!(context.flags & 1)); + RpAtomic* ptank = context.ptank; + ptank->renderCallBack(ptank); } - if (p1->src_blend < p2->src_blend) + static S32 compare_ptanks(const void* e1, const void* e2) { - return -1; - } - else if (p1->src_blend > p2->src_blend) - { - return 1; - } + ptank_context* p1 = (ptank_context*)e1; + ptank_context* p2 = (ptank_context*)e2; - RwTexture *tex1 = p1->ptank->geometry->matList.materials[0]->texture; - RwTexture *tex2 = p2->ptank->geometry->matList.materials[0]->texture; + if (p1->dst_blend < p2->dst_blend) + { + return 1; + } + else if (p1->dst_blend > p2->dst_blend) + { + return -1; + } - if (tex1 < tex2) - { - return -1; - } + if (p1->src_blend < p2->src_blend) + { + return -1; + } + else if (p1->src_blend > p2->src_blend) + { + return 1; + } - if (tex1 > tex2) - { - return 1; - } + RwTexture* tex1 = p1->ptank->geometry->matList.materials[0]->texture; + RwTexture* tex2 = p2->ptank->geometry->matList.materials[0]->texture; - return 0; -} + if (tex1 < tex2) + { + return -1; + } -U32 create_ptanks(group_data& group, unsigned long count) -{ - U32 initial_size = group.size; - if (initial_size + count > group.max_size) - { - count = group.max_size - initial_size; + if (tex1 > tex2) + { + return 1; + } + + return 0; } - ptank_context* end = group.ptanks + initial_size + count; - ptank_context* it = group.ptanks + initial_size; - while (it < end) + U32 create_ptanks(group_data& group, unsigned long count) { - RpAtomic* ptank = create_ptank(group.create_flags); - it->ptank = ptank; + U32 initial_size = group.size; + if (initial_size + count > group.max_size) + { + count = group.max_size - initial_size; + } - if (it->ptank == NULL) + ptank_context* end = group.ptanks + initial_size + count; + ptank_context* it = group.ptanks + initial_size; + while (it < end) { - break; + RpAtomic* ptank = create_ptank(group.create_flags); + it->ptank = ptank; + + if (it->ptank == NULL) + { + break; + } + + it->flags = rpPTANKDFLAGPOSITION; + it->next = *group.buckets; + *group.buckets = it; + it++; + group.size++; } - it->flags = rpPTANKDFLAGPOSITION; - it->next = *group.buckets; - *group.buckets = it; - it++; - group.size++; + return group.size - initial_size; } - return group.size - initial_size; -} - -} +} // namespace void xPTankPoolSceneEnter() { @@ -300,7 +286,7 @@ void xPTankPoolSceneEnter() { double f = it->max_size - 0.f; float scaled = float(f) * 0.25f + 0.5f; - create_ptanks(*it, (unsigned long) scaled); + create_ptanks(*it, (unsigned long)scaled); it++; } @@ -326,8 +312,8 @@ void xPTankPoolSceneExit() void xPTankPoolRender() { - RwRenderStateSet(rwRENDERSTATECULLMODE, (void *) true); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *) false); + RwRenderStateSet(rwRENDERSTATECULLMODE, (void*)true); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)false); group_data* g = groups; group_data* endg = groups + MAX_PGT; @@ -335,9 +321,9 @@ void xPTankPoolRender() { if (g->used != 0) { - qsort((void *)g->ptanks, g->size, sizeof(struct ptank_context), compare_ptanks); - - ptank_context* p = (ptank_context*) g->ptanks; + qsort((void*)g->ptanks, g->size, sizeof(struct ptank_context), compare_ptanks); + + ptank_context* p = (ptank_context*)g->ptanks; ptank_context* endp = p + g->size; while (p != endp) { @@ -348,7 +334,6 @@ void xPTankPoolRender() } else if ((p->flags & rpPTANKDFLAGCNS2DROTATE) == 0) { - RpMaterialSetTexture(p->ptank->geometry->matList.materials[0], NULL); p->flags |= rpPTANKDFLAGCNS2DROTATE; } @@ -358,7 +343,6 @@ void xPTankPoolRender() g->used = 0; sort_buckets(*g); - } g++; } @@ -376,12 +360,12 @@ void ptank_pool::grab_block(ptank_group_type type) ptank_context** it = group.buckets + 2; while (it < end) { - if (*it != NULL) { - if ( - (*it)->ptank->geometry->matList.materials[0]->texture == this->rs.texture - && (*it)->dst_blend == this->rs.dst_blend - && (*it)->src_blend == this->rs.src_blend - && !(((*it)->flags ^ this->rs.flags) & 0x1)) + if (*it != NULL) + { + if ((*it)->ptank->geometry->matList.materials[0]->texture == this->rs.texture && + (*it)->dst_blend == this->rs.dst_blend && + (*it)->src_blend == this->rs.src_blend && + !(((*it)->flags ^ this->rs.flags) & 0x1)) { this->ptank = (*it)->ptank; (*it)->flags |= rpPTANKDFLAGCNSNORMAL; @@ -393,18 +377,22 @@ void ptank_pool::grab_block(ptank_group_type type) it++; } } - + { ptank_context** it = group.buckets; while (it < end) { - if (*it != NULL) { - if ((this->rs.flags & rpPTANKDFLAGPOSITION) && !((*it)->flags & rpPTANKDFLAGPOSITION)) { + if (*it != NULL) + { + if ((this->rs.flags & rpPTANKDFLAGPOSITION) && + !((*it)->flags & rpPTANKDFLAGPOSITION)) + { destroy_ptank((*it)->ptank); (*it)->ptank = create_ptank(group.create_flags); } this->ptank = (*it)->ptank; - RpMaterialSetTexture(*this->ptank->geometry->matList.materials, this->rs.texture); + RpMaterialSetTexture(*this->ptank->geometry->matList.materials, + this->rs.texture); RPATOMICPTANKPLUGINDATA(this->ptank)->publicData.srcBlend = this->rs.src_blend; RPATOMICPTANKPLUGINDATA(this->ptank)->publicData.dstBlend = this->rs.dst_blend; RPATOMICPTANKPLUGINDATA(this->ptank)->instFlags |= rpPTANKDFLAGARRAY; @@ -425,24 +413,27 @@ void ptank_pool::grab_block(ptank_group_type type) void ptank_pool::flush() { - if (this->valid() != 0) { + if (this->valid() != 0) + { RpPTankAtomicUnlock(this->ptank); S32 oldused = RPATOMICPTANKPLUGINDATA(this->ptank)->actPCount; - S32 expand = ((S32) this->used < oldused) ? oldused - this->used : 0; + S32 expand = ((S32)this->used < oldused) ? oldused - this->used : 0; expand += 0xA; - - if ((S32) (expand + this->used) > 0x40) { + + if ((S32)(expand + this->used) > 0x40) + { expand = 0x40 - this->used; } - + S32 total = this->used + expand; - + U8* it = this->hide.data; U8* end = it + this->hide.stride * expand; - while (it != end) { + while (it != end) + { memset(it, 0, this->hide.size); - it = (U8*) it + this->hide.stride; + it = (U8*)it + this->hide.stride; } RPATOMICPTANKPLUGINDATA(this->ptank)->instFlags |= 0x800000; diff --git a/src/SB/Core/x/xPtankPool.h b/src/SB/Core/x/xPtankPool.h index a00e7d942..6c0625c1e 100644 --- a/src/SB/Core/x/xPtankPool.h +++ b/src/SB/Core/x/xPtankPool.h @@ -38,7 +38,8 @@ struct ptank_pool render_state rs; U32 used; RpAtomic* ptank; - struct { + struct + { U8* data; S32 stride; U32 size; From 3df750637e4437530a1cd613d315aedb1ebaf4f9 Mon Sep 17 00:00:00 2001 From: Velkog Date: Tue, 20 May 2025 22:37:55 -0700 Subject: [PATCH 3/5] Update hardcoded enum values --- src/SB/Core/x/xPtankPool.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/SB/Core/x/xPtankPool.cpp b/src/SB/Core/x/xPtankPool.cpp index fb71d9991..1dcd4b97b 100644 --- a/src/SB/Core/x/xPtankPool.cpp +++ b/src/SB/Core/x/xPtankPool.cpp @@ -58,7 +58,7 @@ namespace RwTexture* texture = it->ptank->geometry->matList.materials[0]->texture; if (texture == NULL) { - if ((it->flags & 0x1) != 0) + if ((it->flags & rpPTANKDFLAGPOSITION) != 0) { bucket++; } @@ -75,7 +75,7 @@ namespace { if (it->dst_blend == front->dst_blend && it->src_blend == front->src_blend && - ((it->flags ^ front->flags) & 0x1) == 0) + ((it->flags ^ front->flags) & rpPTANKDFLAGPOSITION) == 0) { break; } @@ -199,7 +199,7 @@ namespace void render_ptank(const ptank_context& context) { - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)!(context.flags & 1)); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)!(context.flags & rpPTANKDFLAGPOSITION)); RpAtomic* ptank = context.ptank; ptank->renderCallBack(ptank); } @@ -419,11 +419,11 @@ void ptank_pool::flush() S32 oldused = RPATOMICPTANKPLUGINDATA(this->ptank)->actPCount; S32 expand = ((S32)this->used < oldused) ? oldused - this->used : 0; - expand += 0xA; + expand += 10; - if ((S32)(expand + this->used) > 0x40) + if ((S32)(expand + this->used) > 64) { - expand = 0x40 - this->used; + expand = 64 - this->used; } S32 total = this->used + expand; @@ -436,7 +436,7 @@ void ptank_pool::flush() it = (U8*)it + this->hide.stride; } - RPATOMICPTANKPLUGINDATA(this->ptank)->instFlags |= 0x800000; + RPATOMICPTANKPLUGINDATA(this->ptank)->instFlags |= rpPTANKIFLAGACTNUMCHG; RPATOMICPTANKPLUGINDATA(this->ptank)->actPCount = total; this->used = 0; } From 80727b90c8e0882e4347f630ec17c52bc31aeb4e Mon Sep 17 00:00:00 2001 From: Velkog Date: Wed, 21 May 2025 21:39:14 -0700 Subject: [PATCH 4/5] Remove direct comparisons with 0 --- src/SB/Core/x/xPtankPool.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SB/Core/x/xPtankPool.cpp b/src/SB/Core/x/xPtankPool.cpp index 1dcd4b97b..d7c53c6cd 100644 --- a/src/SB/Core/x/xPtankPool.cpp +++ b/src/SB/Core/x/xPtankPool.cpp @@ -58,7 +58,7 @@ namespace RwTexture* texture = it->ptank->geometry->matList.materials[0]->texture; if (texture == NULL) { - if ((it->flags & rpPTANKDFLAGPOSITION) != 0) + if (it->flags & rpPTANKDFLAGPOSITION) { bucket++; } @@ -75,7 +75,7 @@ namespace { if (it->dst_blend == front->dst_blend && it->src_blend == front->src_blend && - ((it->flags ^ front->flags) & rpPTANKDFLAGPOSITION) == 0) + (!(it->flags ^ front->flags) & rpPTANKDFLAGPOSITION)) { break; } @@ -319,7 +319,7 @@ void xPTankPoolRender() group_data* endg = groups + MAX_PGT; while (g != endg) { - if (g->used != 0) + if (g->used) { qsort((void*)g->ptanks, g->size, sizeof(struct ptank_context), compare_ptanks); @@ -332,7 +332,7 @@ void xPTankPoolRender() render_ptank(*p); p->flags &= ~rpPTANKDFLAGCNSNORMAL; } - else if ((p->flags & rpPTANKDFLAGCNS2DROTATE) == 0) + else if (!(p->flags & rpPTANKDFLAGCNS2DROTATE)) { RpMaterialSetTexture(p->ptank->geometry->matList.materials[0], NULL); p->flags |= rpPTANKDFLAGCNS2DROTATE; @@ -413,7 +413,7 @@ void ptank_pool::grab_block(ptank_group_type type) void ptank_pool::flush() { - if (this->valid() != 0) + if (this->valid()) { RpPTankAtomicUnlock(this->ptank); From a71c881dbe97785c4989062bcd7409ecd6f29670 Mon Sep 17 00:00:00 2001 From: Velkog Date: Wed, 21 May 2025 23:23:19 -0700 Subject: [PATCH 5/5] Fix misplaced '!' --- src/SB/Core/x/xPtankPool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SB/Core/x/xPtankPool.cpp b/src/SB/Core/x/xPtankPool.cpp index d7c53c6cd..c65b0b7a5 100644 --- a/src/SB/Core/x/xPtankPool.cpp +++ b/src/SB/Core/x/xPtankPool.cpp @@ -75,7 +75,7 @@ namespace { if (it->dst_blend == front->dst_blend && it->src_blend == front->src_blend && - (!(it->flags ^ front->flags) & rpPTANKDFLAGPOSITION)) + !((it->flags ^ front->flags) & rpPTANKDFLAGPOSITION)) { break; }