[IGfxWorld] More work, some possible fixes

This commit is contained in:
TheApadayo 2017-03-27 21:25:58 -04:00
parent 38080b7d73
commit 0b1f28bdae
4 changed files with 132 additions and 16 deletions

View File

@ -18,8 +18,6 @@ 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);
@ -27,7 +25,6 @@ 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)
{
@ -434,17 +431,6 @@ namespace Assets
{
asset->heroOnlyLights = reader.readArray<Game::GfxHeroOnlyLight>(asset->heroOnlyLightCount);
}
// We need to temporarily allocate a runtime buffer
// It's not accessed during the building process,
// but as we're interacting with the runtime, we have to
// allocate a valid buffer for the time we're using it.
if (asset->dpvs.surfaceMaterials)
{
asset->dpvs.surfaceMaterials = builder->getAllocator()->allocateArray<Game::GfxDrawSurf>(asset->surfaceCount);
}
Game::SortWorldSurfaces(asset);
}
}

View File

@ -597,7 +597,6 @@ namespace Components
}
if (pass->argumentDef)
{
buffer->align(Utils::Stream::ALIGN_4);
@ -645,6 +644,98 @@ namespace Components
}
});
static Game::GfxWorld* storedWorld = nullptr;
AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader asset, std::string name, bool* /*restrict*/)
{
if (type == Game::XAssetType::ASSET_TYPE_GFXWORLD)
{
Game::GfxWorld* world = asset.gfxWorld;
Utils::Stream* buffer = new Utils::Stream(0x1000);
for (unsigned int i = 0; i < world->dpvs.staticSurfaceCount; ++i)
{
buffer->saveString(Utils::String::VA("%s\n", world->dpvs.surfaces[world->dpvs.sortedSurfIndex[i]].material->name));
}
Utils::IO::WriteFile("userraw/logs/matlog.txt", buffer->toBuffer());
storedWorld = asset.gfxWorld;
}
});
Dvar::OnInit([]()
{
Dvar::Register<bool>("r_drawAabbTrees", false, Game::DVAR_FLAG_USERCREATED, "draw aabb trees");
});
Renderer::OnFrame([]()
{
if (!Game::CL_IsCgameInitialized() || !Dvar::Var("r_drawAabbTrees").get<bool>()) return;
float cyan[4] = { 0.0f, 0.5f, 0.5f, 1.0f };
Game::GfxWorld** gameWorld = reinterpret_cast<Game::GfxWorld**>(0x66DEE94);
for (int i = 0; i < (*gameWorld)->dpvsPlanes.cellCount; ++i)
{
for (int j = 0; j < (*gameWorld)->aabbTreeCounts[i].aabbTreeCount; ++j)
{
Game::vec3_t v1, v2, v3, v4, v5, v6, v7, v8;
float* center = (*gameWorld)->aabbTrees[i].aabbTree[j].bounds.midPoint;
float* halfSize = (*gameWorld)->aabbTrees[i].aabbTree[j].bounds.halfSize;
v1[0] = center[0] - halfSize[0];
v1[1] = center[1] - halfSize[1];
v1[2] = center[2] - halfSize[2];
v2[0] = center[0] + halfSize[0];
v2[1] = center[1] - halfSize[1];
v2[2] = center[2] - halfSize[2];
v3[0] = center[0] - halfSize[0];
v3[1] = center[1] + halfSize[1];
v3[2] = center[2] - halfSize[2];
v4[0] = center[0] + halfSize[0];
v4[1] = center[1] + halfSize[1];
v4[2] = center[2] - halfSize[2];
v5[0] = center[0] - halfSize[0];
v5[1] = center[1] - halfSize[1];
v5[2] = center[2] + halfSize[2];
v6[0] = center[0] + halfSize[0];
v6[1] = center[1] - halfSize[1];
v6[2] = center[2] + halfSize[2];
v7[0] = center[0] - halfSize[0];
v7[1] = center[1] + halfSize[1];
v7[2] = center[2] + halfSize[2];
v8[0] = center[0] + halfSize[0];
v8[1] = center[1] + halfSize[1];
v8[2] = center[2] + halfSize[2];
// bottom
Game::R_AddDebugLine(cyan, v1, v2);
Game::R_AddDebugLine(cyan, v2, v4);
Game::R_AddDebugLine(cyan, v4, v3);
Game::R_AddDebugLine(cyan, v3, v1);
// top
Game::R_AddDebugLine(cyan, v5, v6);
Game::R_AddDebugLine(cyan, v6, v8);
Game::R_AddDebugLine(cyan, v8, v7);
Game::R_AddDebugLine(cyan, v7, v5);
// verticals
Game::R_AddDebugLine(cyan, v1, v5);
Game::R_AddDebugLine(cyan, v2, v6);
Game::R_AddDebugLine(cyan, v3, v7);
Game::R_AddDebugLine(cyan, v4, v8);
}
}
});
// Dvars
Dvar::Register<bool>("ui_streamFriendly", false, Game::DVAR_FLAG_SAVED, "Stream friendly UI");

View File

@ -754,4 +754,41 @@ namespace Game
*specular1 = saveSpecular1;
*specular2 = saveSpecular2;
}
void R_AddDebugLine(float* color, float* v1, float* v2)
{
void* debugglobals = reinterpret_cast<void*> (Utils::Hook::Get<int>(0x66DAD78) + 268772);
void* func = reinterpret_cast<void*> (0x51CEB0);
__asm
{
mov eax, v2
push eax
mov eax, v1
push eax
mov esi, debugglobals
mov edi, color
call func
add esp, 8
}
}
void R_AddDebugString(float *color, float *pos, float scale, char *string)
{
void* debugglobals = reinterpret_cast<void*> (Utils::Hook::Get<int>(0x66DAD78) + 268772);
void* func = reinterpret_cast<void*> (0x51D0A0);
__asm
{
mov eax, string
push eax
mov eax, scale
push eax
mov eax, color
push eax
mov eax, pos
push eax
mov edi, debugglobals
call func
add esp, 16
}
}
}

View File

@ -772,4 +772,6 @@ namespace Game
int CL_GetMaxXP();
void SortWorldSurfaces(GfxWorld* world);
void R_AddDebugLine(float* color, float* v1, float* v2);
void R_AddDebugString(float *color, float *pos, float scale, char *str);
}