Skip to content

Lev instances#16

Draft
TheUbMunster wants to merge 15 commits intomateusfavarin:mainfrom
TheUbMunster:lev-instances
Draft

Lev instances#16
TheUbMunster wants to merge 15 commits intomateusfavarin:mainfrom
TheUbMunster:lev-instances

Conversation

@TheUbMunster
Copy link
Contributor

WIP

src/levelui.cpp Outdated
if (ImGui::MenuItem("Renderer")) { Windows::w_renderer = !Windows::w_renderer; }
if (ImGui::MenuItem("Ghosts")) { Windows::w_ghost = !Windows::w_ghost; }
if (ImGui::MenuItem("Python")) { Windows::w_python = !Windows::w_python; }
if (ImGui::MenuItem("Model Importer")) { m_showModelImporterWindow = !m_showModelImporterWindow; }
Copy link
Owner

Choose a reason for hiding this comment

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

Save the variable in Windows:: data structure, as well as save its state to the settings file

Copy link
Contributor Author

@TheUbMunster TheUbMunster Feb 18, 2026

Choose a reason for hiding this comment

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

I see what you mean by the first suggestion (addressed), but I'm not sure what you mean by "as well as save its state to the settings file".

Copy link
Owner

Choose a reason for hiding this comment

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

Sorry, I wrote this message 4 days ago and the Windows:: structure doesn't exist anymore, so lets update this topic:

There's now a global Settings struct. As you can imagine, this is always loaded by the editor. ImGui saves its state globally as well. So, for window states, I'd like to always save the "latest" windows the user left open, so turning this bool into Settings::w_modelImporter and saving in the global settings file would be prefered.

std::unordered_map<std::string, std::vector<uint8_t>> m_importedModels;

// Model textures placed in VRAM (filled by UpdateVRM, used by SaveLEV)
std::vector<ModelTextureForVRM> m_modelTexturesInVRAM;
Copy link
Owner

Choose a reason for hiding this comment

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

Wouldn't it be better to unify these 3 structures to represent an instance? So the instance would be a name, its model texture and its definition (call it a class Instance). And then this cless has a serialize function and other helpers as needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if this is as simple as you think it is,

  • m_modelInstances : m_modelInstanceNames — 1:1 (parallel arrays, same index) - m_modelInstanceNames → m_importedModels — many:1 (multiple instances can reference the same model by name)
  • m_importedModels → m_modelTexturesInVRAM — 1:many (each model can have multiple textures; each ModelTextureForVRM stores a modelName back-reference)
  • m_modelInstances ↔ m_modelTexturesInVRAM — no direct relationship (both independently reference a model in m_importedModels)

Copy link
Owner

Choose a reason for hiding this comment

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

We'll need to call to discuss this further

std::string m_log;
};

namespace SH
Copy link
Owner

Choose a reason for hiding this comment

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

SH? What does this name mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shared helpers. I didn't really care what it was called, I just wanted a short namespace so I could distinctly keep these separate from anything in psx_types


// Extract raw PSX texture data (pixel indices + palette) without converting to RGBA
static void ExtractRawPSXTexture(const LevDataExtractor::VramBuffer& vram,
int pageX, int pageY, int palX, int palY,
Copy link
Owner

Choose a reason for hiding this comment

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

Avoid this many function arguments. When you need too many arguments, it's a hint they should be a structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see what you mean, but I disagree in this case. The parameters of this function are

  1. Vram
  2. Page coordinate.
  3. texture metadata.
  4. a set of uv coords
  5. raw texture data (out)

It just so happens to be that describing some of these params (number 2, number 3, and number 4) are "verbose" and those parameters are "more than one parameter". I think making the args of this function a monolithic "argument structure" is silly and would have limited usage and would be more clutter than its worth. If you feel strongly about this I'll do it though.

Copy link
Owner

Choose a reason for hiding this comment

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

I agree that VRAM and textura data are clearly its own independent entities. Putting them together in a struct would suck as the function would be hard to re-use. As for addressing where a texture is in VRAM, you always need the texpage number, the palette, the bpp, the coordinates, so those can likely go in a struct (and there's likely many places in the editor that could use this struct). We might want to refactor some parts of the editor to use a common struct to refer to the texture in VRAM.

src/texture.h Outdated
// Model texture data for VRAM placement (from .ctrmodel)
struct ModelTextureForVRM
{
std::vector<uint8_t> pixelData; // Raw PSX format pixels
Copy link
Owner

Choose a reason for hiding this comment

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

Thid structure seems to be repeated in the extractor file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to deduplicate the structs a bit, lmk what you think.

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