Skip to content

simple shadow :)#746

Open
spongeis5 wants to merge 3 commits into
bfbbdecomp:mainfrom
spongeis5:main
Open

simple shadow :)#746
spongeis5 wants to merge 3 commits into
bfbbdecomp:mainfrom
spongeis5:main

Conversation

@spongeis5

Copy link
Copy Markdown

PLEASE oh PLEASE review my code i dont wanna screw anything up 😔

@SquareMan SquareMan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this and welcome to the project! I haven't fully reviewed the function code yet as there are some major structural issues introduced by these struct edits you've made. Feel free to ask for more help in the discord if you need it but once this PR passes CI one of us will give it a more thorough review.

Comment thread src/SB/Core/x/xGlobals.h Outdated
Comment thread src/SB/Core/x/xShadowSimple.h Outdated
Comment thread src/SB/Core/x/xShadowSimple.cpp Outdated
@spongeis5

Copy link
Copy Markdown
Author

thank you so much for the feedback !!

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

main/SB/Core/x/xShadowSimple

Section From To Bytes
.bss 99.69% 100.00% +44
.rodata 14.29% 100.00% +13
📈 .sdata2 50.00% 77.27% +13
📈 .text 14.98% 96.07% +4093
Function From To Bytes
📈 shadowRayEntCB(xEnt*, void*) 0.00% 94.18% +794
📈 xShadowSimple_SceneCollide(xShadowSimpleCache*, xVec3*, float) 0.00% 97.70% +484
📈 xShadowSimple_CalcCorners(xShadowSimpleCache*, xEnt*, float, float) 0.00% 98.35% +476
📈 xShadowSimple_AddVerts(xShadowSimpleCache*) 0.00% 89.67% +326
📈 xShadowSimple_Init() 40.35% 92.94% +172
📈 xShadowSimple_CacheInit(xShadowSimpleCache*, xEnt*, unsigned char) 56.84% 98.75% +147
📈 xShadowSimple_Add(xShadowSimpleCache*, xEnt*, float, float) 0.00% 94.52% +1111
xShadowSimpleQueue::operator=(const xShadowSimpleQueue&) 0.00% 100.00% +44
xShadowSimple_Render() 0.00% 100.00% +536

Comment thread src/SB/Core/x/xScene.h
Comment on lines +45 to +48
union {
xEnv* env;
xClumpCollBSPTree* scenecoll;
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok so this is pretty sus. We're gonna focus on figuring out what's really going on

Comment on lines +23 to +26
struct shadowRayEntData {
xShadowSimpleCache* cache;
const RwLine* line;
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you tell me where this struct came from?

Comment on lines +28 to +31
class xNPCBasic : public xEnt {
public:
u32 SelfType() const;
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this before. xNPCBasic is decarled in xNPCBasic.h, you should remove this and include that header instead.

norm = (xVec3*)&tri->normal;
}

if (dist >= *testdist || (norm->y < 0.0871557f))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you try using DEG2RAD(5) here instead of 0.0871557?

Comment on lines +202 to +206
if (*(RpAtomic**)((char*)clump + 0x10)) {
xClumpColl_ForAllIntersections(*(xClumpCollBSPTree**)((char*)*(RpAtomic**)((char*)clump + 0x10) + 0x10), &isx, shadowRayCB, cache);
} else {
RpCollisionWorldForAllIntersections(*(RpWorld**)clump, &isx, shadowRayCB, cache);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a mess and needs to be cleaned. In doing so I think we can solve our scenecoll mystery with xScene. It's not unheard of to see crazy pointer math like this with Renderware, but usually it's handled by a macro from one of the rw headers if necessary.

Comment on lines +385 to +388
#pragma push
#pragma optimization_level 1
#pragma optimize_for_size on

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably not accurate. I'd rather it be removed at the cost of a lower match percentage but others might disagree.

Comment on lines +454 to 500
U32 flags = 0;
U32 var_r20 = 0;

S32 count = xSTAssetCountByType('SHDW');
for (i = 0; i < count; i++)
{
sst = (zSimpleShadowTableHeader*)xSTFindAssetByType('SHDW', i, &size);
var_r24 = 0;
for (j = 0; j < (U32)sst->num; j += 1)
for (j = 0; j < (U32)sst->num; j++)
{
if ((U32)ent->model->modelID == 0)
U32 offset = j * sizeof(zSimpleShadowTableEntry);

U32 entry_modelID = *(U32*)((char*)sst + 4 + offset);

if ((U32)ent->model->modelID == entry_modelID)
{
if (xSTFindAsset(sst->num, NULL) != NULL)
U32 entry_assetID = *(U32*)((char*)sst + 8 + offset);
RwTexture* tex = (RwTexture*)xSTFindAsset(entry_assetID, NULL);
if (tex != NULL)
{
flags = (U32)xSTFindAsset(sst->num, NULL);
var_r20 = sst->num;
flags = (U32)tex->raster;
var_r20 = *(U32*)((char*)sst + 12 + offset);
}
else
{
flags = 0xDEADBEEFU;
flags = 0xDEADBEEF;
}
}

if (flags != 0)
{
break;
}
}
if (flags != 0)
{
break;
}
}
if ((flags == 0U) || ((U32)(flags + 0x21530000) == -0x4111U))

if ((flags == 0) || (flags == 0xDEADBEEF))
{
flags = sShadRaster->width;
flags = (U32)sShadRaster;
}
cache->corner[1].x = flags;
cache->flags |= (S16)var_r20;

cache->raster = flags;
cache->flags |= (U16)var_r20;
ent->model->shadowID = flags;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should give this one another go. The last three lines here are a big tell. Looks like the current flags var is actually raster, var_r20 is flags. Not sure about the last line since it seems to match but it's odd too.

Comment on lines +58 to +63
struct zSimpleShadowTableEntry {
U32 modelID;
U32 assetID;
U32 flags;
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also curious about this struct, since it's not in DWARF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants