[IGfxWorld] My terrible attempt at sorting gfxsurfaces

This commit is contained in:
TheApadayo 2017-03-27 00:56:08 -04:00
parent 9e2fab7f54
commit c02eede3f4
2 changed files with 34 additions and 1 deletions

View File

@ -18,6 +18,8 @@ namespace Assets
asset->smodelInsts = reader->readArray<Game::GfxStaticModelInst>(asset->smodelCount);
}
std::vector<Game::GfxSurface*> surfs;
if (asset->surfaces)
{
asset->surfaces = reader->readArray<Game::GfxSurface>(world->surfaceCount);
@ -25,6 +27,7 @@ namespace Assets
for (unsigned int i = 0; i < world->surfaceCount; ++i)
{
Game::GfxSurface* surface = &asset->surfaces[i];
surfs.push_back(&asset->surfaces[i]);
if (surface->material)
{
@ -33,6 +36,23 @@ namespace Assets
}
}
std::sort(surfs.begin(), surfs.end(), [](Game::GfxSurface* a, Game::GfxSurface* b)
{
if (a->material->name == nullptr && b->material->name == nullptr) return false;
if (a->material->name == nullptr && b->material->name != nullptr) return true;
if (a->material->name != nullptr && b->material->name == nullptr) return false;
return strcmp(a->material->name, b->material->name) == 0;
});
Game::GfxSurface* tmpBuffer = builder->getAllocator()->allocateArray<Game::GfxSurface>(world->surfaceCount);
for (unsigned int i = 0; i < world->surfaceCount; ++i)
{
std::memcpy(&tmpBuffer[i], surfs[i], sizeof(Game::GfxSurface));
}
asset->surfaces = tmpBuffer;
if (asset->surfacesBounds)
{
asset->surfacesBounds = reader->readArray<Game::GfxSurfaceBounds>(world->surfaceCount);

View File

@ -545,7 +545,17 @@ namespace Game
struct GfxDrawSurfFields
{
__int64 _bf0;
unsigned __int64 objectId : 16;
unsigned __int64 reflectionProbeIndex : 8;
unsigned __int64 hasGfxEntIndex : 1;
unsigned __int64 customIndex : 5;
unsigned __int64 materialSortedIndex : 12;
unsigned __int64 prepass : 2;
unsigned __int64 useHeroLighting : 1;
unsigned __int64 sceneLightIndex : 8;
unsigned __int64 surfType : 4;
unsigned __int64 primarySortKey : 6;
unsigned __int64 unused : 1;
};
union GfxDrawSurf
@ -559,6 +569,7 @@ namespace Game
unsigned int loadBits[2];
};
#pragma pack(push, 4)
struct Material
{
@ -3052,6 +3063,8 @@ namespace Game
float scale;
};
struct GfxStaticModelDrawInst
{
GfxPackedPlacement placement;