work towards showing multiple units simultaneously

This commit is contained in:
Adam Jensen 2023-02-28 01:23:45 +00:00
parent af63ebd886
commit b44e773d23
3 changed files with 58 additions and 14 deletions

View File

@ -38,6 +38,8 @@ struct Level { // UnitBlob
}
struct StreamUnit {
uint32_t StreamUnitID; // 0
uint8_t used; // 8
cdc::Level *level; // C
uint8_t name[128]; // 10
cdc::ResolveObject *resolveObject_streamGroup; // 90

View File

@ -1,4 +1,5 @@
#include <cstdio>
#include <iterator>
#include "config.h"
#include "SceneLayer.h" // for StreamingCallback
#include "stream.h"
@ -77,12 +78,32 @@ void STREAM_Init() { // 582
}
StreamUnit *STREAM_GetStreamUnitWithID(int32_t id) { // 1170
// HACK
return &StreamTracker[0];
for (auto &unit : StreamTracker)
if ((unit.used == 1 || unit.used == 2) && unit.StreamUnitID == id)
return &unit;
return nullptr;
}
StreamUnit *STREAM_GetAndInitStreamUnitWithID(int32_t id) { // couldn't confirm real name
auto *unit = STREAM_GetStreamUnitWithID(id);
StreamUnit *STREAM_GetAndInitStreamUnitWithID(const char *name, int32_t id) { // couldn't confirm real name
StreamUnit *unit = StreamTracker;
while (unit < std::end(StreamTracker) && unit->used)
unit++;
if (unit == std::end(StreamTracker))
return nullptr;
unit->used = 1;
strcpy((char*)unit->name, name);
unit->StreamUnitID = id;
// unit->wordA = 0;
// unit->word240 = 0;
// unit->dword4 = 0;
// unit->dwordB4 = 0;
// unit->byte9 = 0;
// unit->dword9C = 0;
unit->coreUnit = nullptr;
unit->resolveObject_streamGroup = nullptr;
// unit->byte94 = 0;
// TODO
return unit;
}
@ -117,7 +138,7 @@ void STREAM_LoadLevel(const char *baseAreaName, StreamUnitPortal *streamPortal,
int32_t i = -1;
if (streamPortal)
i = streamPortal->word84;
StreamUnit *unit = STREAM_GetAndInitStreamUnitWithID(i);
StreamUnit *unit = STREAM_GetAndInitStreamUnitWithID(baseAreaName, i);
if (unit) {
char filename[256];
GameShell::LOAD_UnitFileName(filename, baseAreaName);

View File

@ -626,7 +626,13 @@ int spinnyCube(HWND window,
///////////////////////////////////////////////////////////////////////////////////////////
if (cdc::Level *level = STREAM_GetStreamUnitWithID(0)->level) {
for (auto &unit : StreamTracker) {
if (!unit.used)
continue;
cdc::Level *level = unit.level;
if (!level)
continue;
cdc::CellGroupData *cellGroupData = level->sub50;
uint32_t numCells = cellGroupData->header->numTotalCells;
for (uint32_t i=0; i < numCells; i++) {
@ -671,8 +677,8 @@ int spinnyCube(HWND window,
// float lightAccumulation[4] = {0.9f, 0.9f, 0.9f, 1.0f};
float lightAccumulation[4] = {0.0f, 0.0f, 0.0f, 1.0f};
StreamUnit *unit = STREAM_GetStreamUnitWithID(0);
cdc::Level *level = unit->level;
StreamUnit *unit = &StreamTracker[0];
cdc::Level *level = unit ? unit->level : nullptr;
uint32_t numIntros = level ? level->admdData->numObjects : 0;
dtp::Intro *intros = level ? level->admdData->objects : nullptr;
uint32_t numIMFRefs = level ? level->admdData->numIMFRefs : 0;
@ -758,7 +764,13 @@ int spinnyCube(HWND window,
g_scene->Draw();
// draw cells
if (cdc::Level *level = STREAM_GetStreamUnitWithID(0)->level) {
for (auto& unit : StreamTracker) {
if (!unit.used)
continue;
cdc::Level *level = unit.level;
if (!level)
continue;
cdc::CellGroupData *cellGroupData = level->sub50;
uint32_t numCells = cellGroupData->header->numTotalCells;
for (uint32_t i=0; i < numCells; i++) {
@ -881,14 +893,21 @@ int spinnyCube(HWND window,
}
if (showLoadedUnitsWindow) {
ImGui::Begin("Loaded units", &showLoadedUnitsWindow);
StreamUnit *unit = STREAM_GetStreamUnitWithID(0);
cdc::Level *level = unit->level;
ImGui::DragInt2("visible intros", introShowRange);
ImGui::DragInt2("visible IMFs", imfShowRange);
if (!level) {
ImGui::Text("not loaded");
} else {
bool anyLoaded = false;
for (auto &unit : StreamTracker) {
if (!unit.used)
continue;
anyLoaded = true;
cdc::Level *level = unit.level;
ImGui::Text("level %p", level);
if (!level) {
ImGui::Text("not loaded");
continue;
}
cdc::CellGroupData *cellGroupData = level->sub50;
uint32_t numCells = cellGroupData->header->numTotalCells;
@ -927,6 +946,8 @@ int spinnyCube(HWND window,
ImGui::PopID();
}
}
if (!anyLoaded)
ImGui::Text("no units");
ImGui::End();
}
if (showStringsWindow) {