Skip to content

Sprite support to go with the networking update and psxsplash/psxsus - #40

Merged
rixnobis merged 7 commits into
mainfrom
networking
Sep 30, 2026
Merged

rixnobis merged 7 commits into
mainfrom
networking

Conversation

@CloudMracek

Copy link
Copy Markdown
Contributor

Sprites, tilemaps

@rixnobis rixnobis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One blocker, a handful of should-fix. Every new table in PSXSceneWriter (SpriteSheet 20B, SpriteAnim 12B, Tilemap 20B, TileCell 2B, TileObject 6B, AgentV2 28B, header 144B at v23) matches the reader in #28 field for field, and v20/v21 packs still load. The one mismatch is the CLUT X unit below. Not built in Unity; this is a read-through plus a symbol check.

Blocker: sprite and tile CLUT X is divided by 16 twice. PSXSpriteExporter.cs writes ClutX = tex.ClutPackingX, which TexturePacker already stores as x / 16. On the engine side, spritesystem.cpp and tilesystem.cpp build ClutIndex(Vertex{clutX, clutY}), and psyqo's ClutIndex(Vertex v) does v.x >> 4 again. Any 4bpp/8bpp sheet whose palette isn't at VRAM x=0 samples the wrong CLUT. The UI image path uses ClutIndex(x, y) and is fine. Fix it on either side: write ClutPackingX * 16 here, or use the two-argument constructor in #28.

Should-fix:

  • PSXSpriteExporter.cs: a sheet with no PackedTexture is skipped with a warning, but anims (Sheet = (byte)i) and the tilemap (sheetList.IndexOf) still index the unfiltered list, so everything after the gap points at the wrong sheet. Throw, or index into sheetData.
  • PSXTexture2D.cs: cutout only affects the paletted path. A 16bpp sheet only gets transparency where the texel happens to pack to 0x0000, and alphaIsTransparency = true makes that rarer.
  • TexturePacker.cs: the dedup key is (instanceID, BitDepth) without cutout, so a texture shared between a sprite sheet and a mesh/UI image gets whichever quantization ran first.
  • PSXSceneWriter.cs: an agent whose object isn't exported gets 0xFFFF, and gameObjectIndex + 1 in scenemanager.cpp wraps that to actor 0. A PSXAgent on a skinned object hits this, because its PSXObjectExporter is skipped in favour of the skinned proxy.
  • Utils.SetTextureImporterFormat now forces no-mip/point/uncompressed/alphaIsTransparency on every texture it touches, including mesh textures, which rewrites project import settings without saying so.
  • Editor/PSXUIMenuItems.cs has using UnityEngine.UI;, but the Editor asmdef doesn't reference uGUI and nothing in the file uses it. Probably a compile error; delete the line.

Nits: waypoint Y isn't negated like object Y is; the ASCII pass left "(cycle)" in a 22px button, "yes Path is set and valid" and "Autov"; a Debug.Log fires per sheet on every export; there are // Added: comments in PSXSceneExporterEditor.cs; hash ^= (byte)c drops the high byte of non-ASCII scene ids.

Scope: besides sprites and tilemaps this carries agents, nav settings, the network scene hash, audio silence trimming, UI budget/layout/menus, the screen preview and a repo-wide Unicode-to-ASCII pass. I'm fine reviewing it as one since #28 depends on all of it, but the ASCII pass especially makes the diff harder to read than it needs to be.

…ng it

Anims and the tilemap index sheets by their position in the unfiltered
list, so a skipped sheet pointed everything after it at the wrong one.
Also drop the per-sheet Debug.Log.
Only the paletted path applied it, so a 16bpp sheet was transparent only
where a texel happened to pack to 0x0000.
A texture used both by a sprite sheet (cutout) and by a mesh or UI image
was packed once, with whichever quantization ran first.
…t otherwise

The writer fell back to 0xFFFF, which the runtime's gameObjectIndex + 1
wraps to actor 0, the player. A PSXAgent on a skinned object always hit
this, because its PSXObjectExporter is skipped for the skinned proxy.
The Editor asmdef does not reference uGUI and nothing in the file uses it.
The refresh button, the path-OK label and the console's auto-scroll
toggle read "(cycle)", "yes Path..." and "Autov".
@rixnobis

Copy link
Copy Markdown
Contributor

Pushed six commits onto this branch for the review above: a sprite sheet with no PackedTexture now fails the export, since anims and the tilemap index the unfiltered list (the per-sheet Debug.Log is gone too); cutout applies on the 16bpp path; the VRAM dedup key includes cutout; an agent on a skinned object resolves to its proxy, and an agent on no exported object fails the export (it used to write 0xFFFF, which becomes actor 0); using UnityEngine.UI; is gone from PSXUIMenuItems.cs; the refresh button, path label and auto-scroll toggle have readable ASCII labels again. The CLUT X double divide is fixed on the engine side in #37, so ClutX here is unchanged. Not built in Unity; the symbols the fixes use (TextureQuantizer.CutoutAlphaThreshold, PSXSkinnedObjectExporter.ProxyExporter, VRAMPixel's default) exist on this branch.

Left for @CloudMracek: Utils.SetTextureImporterFormat now forces no-mip, point, uncompressed and alphaIsTransparency on every texture it touches, mesh textures included. Keep that, or limit it to sprite sheets?

@rixnobis rixnobis added the rfc Request for comments: API or format change, 7-day comment window label Sep 29, 2026
@github-actions

Copy link
Copy Markdown

This is now an RFC: it cannot merge before 2026-10-06 09:40 UTC, so anyone who depends on what it changes has a week to comment. See RFC.md.

@github-actions github-actions Bot mentioned this pull request Sep 29, 2026

@rixnobis rixnobis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Labeled rfc: the new components (PSXSprite, PSXSpriteSheet, PSXTilemap, PSXAgent, PSXUISprite) and the v22/v23 writer are contracts, and this pairs with #37.

I compared the writer on this head with the reader on #37 field by field. The 144-byte v23 header lines up with SPLASHPACKFileHeader in order and width, sceneLuaFileIndex written as -1 reads back as the reader's 0xFFFF, and the agent records (28 bytes), sprite sheets (20), sprite anims (12), tilemap header (20), cells (2) and tile objects (6) match the engine's structs. The sprite and tilemap offsets are backfilled into the header slots the engine reads.

What nobody has done yet is build this in Unity: the fixes pushed here were only checked against the symbols on the branch. @CloudMracek, once you've exported a scene with sprites and a tilemap from this head and run it, that plus the SetTextureImporterFormat question above is what's left before I approve.

@CloudMracek

Copy link
Copy Markdown
Contributor Author

Pushed six commits onto this branch for the review above: a sprite sheet with no PackedTexture now fails the export, since anims and the tilemap index the unfiltered list (the per-sheet Debug.Log is gone too); cutout applies on the 16bpp path; the VRAM dedup key includes cutout; an agent on a skinned object resolves to its proxy, and an agent on no exported object fails the export (it used to write 0xFFFF, which becomes actor 0); using UnityEngine.UI; is gone from PSXUIMenuItems.cs; the refresh button, path label and auto-scroll toggle have readable ASCII labels again. The CLUT X double divide is fixed on the engine side in #37, so ClutX here is unchanged. Not built in Unity; the symbols the fixes use (TextureQuantizer.CutoutAlphaThreshold, PSXSkinnedObjectExporter.ProxyExporter, VRAMPixel's default) exist on this branch.

Left for @CloudMracek: Utils.SetTextureImporterFormat now forces no-mip, point, uncompressed and alphaIsTransparency on every texture it touches, mesh textures included. Keep that, or limit it to sprite sheets?

Yes that is the correct approach.

@rixnobis rixnobis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fine by me. With the import settings intended, nothing I raised is open.

@rixnobis
rixnobis merged commit 9d9d270 into main Sep 30, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rfc Request for comments: API or format change, 7-day comment window

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants