Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Editor/Core/SplashControlPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ private void DrawToolchainSection()
GUILayout.FlexibleSpace();
if (_hasPsxavenc)
{
PSXEditorStyles.DrawStatusBadge("Installed", PSXEditorStyles.Success);
PSXEditorStyles.DrawStatusBadge("Ready", PSXEditorStyles.Success);
}
else if (!_hasPsxavencDeps && Application.platform == RuntimePlatform.OSXEditor)
{
Expand Down Expand Up @@ -581,7 +581,7 @@ private void DrawToolchainSection()
}
else
{
PSXEditorStyles.DrawStatusBadge("Installed", PSXEditorStyles.Success);
PSXEditorStyles.DrawStatusBadge("Ready", PSXEditorStyles.Success);
}
EditorGUILayout.EndHorizontal();

Expand Down Expand Up @@ -2656,7 +2656,7 @@ private void RefreshToolchainStatus()

string reduxBin = SplashSettings.PCSXReduxPath;
_hasRedux = !string.IsNullOrEmpty(reduxBin) && File.Exists(reduxBin);
_reduxVersion = _hasRedux ? "Installed" : "";
_reduxVersion = _hasRedux ? "Ready" : "";

_hasPsxavenc = PSXAudioConverter.IsInstalled();

Expand Down
44 changes: 43 additions & 1 deletion Editor/PSXTilemapPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,18 @@ private class Entry
public Mesh Mesh;
public int Hash;
public Texture2D Texture;

#if UNITY_6000_4_OR_NEWER
public EntityId TilesetEntityId;
#endif

}

#if UNITY_6000_4_OR_NEWER
private static readonly Dictionary<EntityId, Entry> s_cache = new Dictionary<EntityId, Entry>();
#else
private static readonly Dictionary<int, Entry> s_cache = new Dictionary<int, Entry>();
#endif
private static Material s_material;

/// <summary>Throw away every cached mesh (the painter calls this).</summary>
Expand Down Expand Up @@ -80,7 +89,40 @@ private static Material PreviewMaterial()
s_material = new Material(shader) { hideFlags = HideFlags.HideAndDontSave };
return s_material;
}
#if UNITY_6000_4_OR_NEWER
private static int ContentHash(PSXTilemap map)
{
unchecked
{
int h = 17;
h = h * 31 + map.Width;
h = h * 31 + map.Height;
h = h * 31 + (map.Tileset != null ? map.Tileset.CellWidth * 397 + map.Tileset.CellHeight : 0);
foreach (var b in map.Brushes) h = h * 31 + b.tilesetCell * 7 + (b.walkable ? 1 : 0);
for (int y = 0; y < map.Height; y++)
for (int x = 0; x < map.Width; x++)
h = h * 31 + map.GetCell(x, y);
return h;
}
}

/// <summary>The cached world-space mesh for a map, rebuilt when it changes.</summary>
public static Mesh MeshFor(PSXTilemap map)
{
if (map == null || map.Tileset == null || map.Tileset.SourceTexture == null) return null;

EntityId key = map.GetEntityId();
EntityId tilesetEntityId = map.Tileset.GetEntityId();
int hash = ContentHash(map);
if (s_cache.TryGetValue(key, out Entry e) && e.Mesh != null && e.Hash == hash && e.TilesetEntityId == tilesetEntityId)
return e.Mesh;

if (e != null && e.Mesh != null) Object.DestroyImmediate(e.Mesh);
e = new Entry { Hash = hash, Texture = map.Tileset.SourceTexture, Mesh = BuildMesh(map), TilesetEntityId = tilesetEntityId };
s_cache[key] = e;
return e.Mesh;
}
#else
private static int ContentHash(PSXTilemap map)
{
unchecked
Expand Down Expand Up @@ -113,7 +155,7 @@ public static Mesh MeshFor(PSXTilemap map)
s_cache[key] = e;
return e.Mesh;
}

#endif
private static Mesh BuildMesh(PSXTilemap map)
{
PSXSpriteSheet set = map.Tileset;
Expand Down
14 changes: 14 additions & 0 deletions Editor/Timeline/PSXTimelineWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ public static void Open(ScriptableObject clip)
window.Focus();
}

#if UNITY_6000_4_OR_NEWER
[OnOpenAsset]
public static bool OnOpenAsset(EntityId instanceID, int line)
{
var obj = EditorUtility.EntityIdToObject(instanceID);
if (obj is PSXAnimationClip || obj is PSXCutsceneClip)
{
Open((ScriptableObject)obj);
return true;
}
return false;
}
#else
[OnOpenAsset]
public static bool OnOpenAsset(int instanceID, int line)
{
Expand All @@ -52,6 +65,7 @@ public static bool OnOpenAsset(int instanceID, int line)
}
return false;
}
#endif

private void OnEnable()
{
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ See the [installation guide](https://psxsplash.github.io/docs/getting-started/in

## Contributing

This has been a one-person project and it has grown over my head. Pull requests are very welcome. See the [contributing guide](https://psxsplash.github.io/docs/reference/contributing/) for areas where help is needed.
This has been a one-person project and it has grown over my head. Pull requests are very welcome. See the [contributing guide](https://psxsplash.github.io/docs/latest/reference/contributing/) for areas where help is needed.

If you build something with SplashEdit, please share it on [PSX.Dev](https://psx.dev) or the Bandwidth Discord server!

Expand Down
7 changes: 0 additions & 7 deletions RFC.md.meta

This file was deleted.

14 changes: 13 additions & 1 deletion Runtime/PSXObjectExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class PSXObjectExporter : MonoBehaviour, IPSXExportable
public LuaFile LuaFile => luaFile;

[FormerlySerializedAs("IsActive")]
[SerializeField] private bool isActive = true;
[SerializeField] private bool isActive = true;
public bool IsActive => isActive;

public List<PSXTexture2D> Textures { get; set; } = new List<PSXTexture2D>();
Expand Down Expand Up @@ -58,7 +58,11 @@ public class PSXObjectExporter : MonoBehaviour, IPSXExportable
public bool IsPlatform => isPlatform;
public int UVOffsetMaterial => uvOffsetMaterial;

#if UNITY_6000_4_OR_NEWER
private readonly Dictionary<(EntityId, PSXBPP), PSXTexture2D> cache = new();
#else
private readonly Dictionary<(int, PSXBPP), PSXTexture2D> cache = new();
#endif

public void CreatePSXTextures2D()
{
Expand All @@ -78,15 +82,23 @@ public void CreatePSXTextures2D()

if (tex2D == null) continue;

#if UNITY_6000_4_OR_NEWER
if (cache.TryGetValue((tex2D.GetEntityId(), bitDepth), out var cached))
#else
if (cache.TryGetValue((tex2D.GetInstanceID(), bitDepth), out var cached))
#endif
{
Textures.Add(cached);
}
else
{
var tex = PSXTexture2D.CreateFromTexture2D(tex2D, bitDepth);
tex.OriginalTexture = tex2D;
#if UNITY_6000_4_OR_NEWER
cache.Add((tex2D.GetEntityId(), bitDepth), tex);
#else
cache.Add((tex2D.GetInstanceID(), bitDepth), tex);
#endif
Textures.Add(tex);
}
}
Expand Down
13 changes: 12 additions & 1 deletion Runtime/TexturePacker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ public VRAMPacker(List<Rect> framebuffers, List<ProhibitedArea> reservedAreas)
List<PSXTexture2D> uniqueTextures = new List<PSXTexture2D>();
// Cutout is part of the key: the same source quantized with and without it
// gives different pixels, so the two must not be merged.
#if UNITY_6000_4_OR_NEWER
Dictionary<(EntityId, PSXBPP, bool), int> textureToIndexMap = new Dictionary<(EntityId, PSXBPP, bool), int>();
#else
Dictionary<(int, PSXBPP, bool), int> textureToIndexMap = new Dictionary<(int, PSXBPP, bool), int>();
#endif
// Track duplicates so we can propagate packing data after placement
List<(PSXTexture2D duplicate, int uniqueIndex)> duplicates = new List<(PSXTexture2D, int)>();

Expand Down Expand Up @@ -115,8 +119,11 @@ public VRAMPacker(List<Rect> framebuffers, List<ProhibitedArea> reservedAreas)
// Process each texture in descending order of area.
foreach (var texture in group.OrderByDescending(tex => tex.QuantizedWidth * tex.Height))
{
#if UNITY_6000_4_OR_NEWER
var textureKey = (texture.OriginalTexture.GetEntityId(), texture.BitDepth, texture.Cutout);
#else
var textureKey = (texture.OriginalTexture.GetInstanceID(), texture.BitDepth, texture.Cutout);

#endif
// Check if we've already processed this texture
if (textureToIndexMap.TryGetValue(textureKey, out int existingIndex))
{
Expand Down Expand Up @@ -154,7 +161,11 @@ public VRAMPacker(List<Rect> framebuffers, List<ProhibitedArea> reservedAreas)

for (int i = 0; i < obj.Textures.Count; i++)
{
#if UNITY_6000_4_OR_NEWER
var textureKey = (obj.Textures[i].OriginalTexture.GetEntityId(), obj.Textures[i].BitDepth, obj.Textures[i].Cutout);
#else
var textureKey = (obj.Textures[i].OriginalTexture.GetInstanceID(), obj.Textures[i].BitDepth, obj.Textures[i].Cutout);
#endif
if (textureToIndexMap.TryGetValue(textureKey, out int newIndex))
{
oldToNewIndexMap[i] = newIndex;
Expand Down