Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Simplifying SpriteChip resizing.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Oct 8, 2020
1 parent f9186ae commit d91cb4d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 38 deletions.
6 changes: 3 additions & 3 deletions Disks/PixelVisionOS/System/Tools/WorkspaceTool/saves.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"GameChip":
{
"savedData":{
"sessionID": "202010081508429024",
"sessionID": "202010081519151162",
"scrollPos": "0",
"selection": "0",
"lastPath": "/Workspace/"
"selection": "6",
"lastPath": "/Workspace/Demos/MicroPlatformerDemo/"
}
}
}
8 changes: 4 additions & 4 deletions SDK/Editor/Editors/GameEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,10 @@ public void ClearColors(string color = null)
colorChip.Clear(color);
}

public void ClearSprites()
{
spriteChip.Clear();
}
// public void ClearSprites()
// {
// // spriteChip.Clear();
// }

/// <summary>
/// Get the TotalDisks colors or change the limit for how many colors the color chip can store.
Expand Down
4 changes: 2 additions & 2 deletions SDK/Engine/Chips/Graphics/FontChip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public override void Configure()
pages = 2;
colorsPerSprite = 2;
unique = true;
Resize(pageWidth, pageHeight * pages);
// Resize(pageWidth, pageHeight * pages);


Clear();
// Clear();
}

public override void Deactivate()
Expand Down
61 changes: 34 additions & 27 deletions SDK/Engine/Chips/Graphics/SpriteChip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class SpriteChip : AbstractChip
protected readonly int[] emptySpriteData = Enumerable.Repeat(-1, 64).ToArray();

protected int _colorsPerSprite = 8;
protected int _pages = 4;
protected int _pages;

private Image spriteMemory = new Image(128, 128);

Expand All @@ -53,7 +53,7 @@ public class SpriteChip : AbstractChip

protected int tmpX;
protected int tmpY;
protected int totalSprites1;
// protected int totalSprites1;
public bool unique = false;
protected int w;
protected int width1;
Expand Down Expand Up @@ -124,7 +124,14 @@ public int pages
if (_pages == value) return;

_pages = MathHelper.Clamp(value, 1, 8);
Resize(pageWidth, pageHeight * pages);

spriteMemory.Resize(
(int) Math.Ceiling((float) pageWidth / width) * width,
(int) Math.Ceiling((float) pageHeight * pages / height)* height
);

cache = new string[spriteMemory.TotalSprites];

}
}

Expand Down Expand Up @@ -194,12 +201,13 @@ public override void Configure()
{
engine.SpriteChip = this;

pages = 4;
// _texture.wrapMode = false;
// width = 8;
// height = 8;


Clear();
// Clear();
}

public override void Deactivate()
Expand All @@ -221,22 +229,22 @@ public override void Deactivate()
/// New <see cref="height" /> for the internal
/// TextureData.
/// </param>
public void Resize(int w, int h)
{

w = Math.Max((int) Math.Ceiling((float) w / width) * width, width);
h = Math.Max((int) Math.Ceiling((float) h / height) * height, height);

if (textureWidth != w || textureHeight != h)
{
spriteMemory.Resize(w, h);
}

//TODO this needs to be double checked at different size sprites
var cols = MathUtil.FloorToInt(textureWidth / width);
var rows = MathUtil.FloorToInt(textureHeight / height);
totalSprites1 = cols * rows;
}
// public void Resize(int w, int h)
// {
//
// w = Math.Max((int) Math.Ceiling((float) w / width) * width, width);
// h = Math.Max((int) Math.Ceiling((float) h / height) * height, height);
//
// // if (textureWidth != w || textureHeight != h)
// // {
// spriteMemory.Resize(w, h);
// // }
//
// //TODO this needs to be double checked at different size sprites
// var cols = MathUtil.FloorToInt(textureWidth / width);
// var rows = MathUtil.FloorToInt(textureHeight / height);
// totalSprites1 = cols * rows;
// }

/// <summary>
/// This caches a sprite for easier look up and duplicate detection.
Expand Down Expand Up @@ -268,12 +276,11 @@ protected void CacheSprite(int index, int[] data)
/// Clears the Image to a default color index of -1
/// and also resets the cache. This removes all sprites from the chip.
/// </summary>
public void Clear()
{
cache = new string[TotalSprites];
spriteMemory.Clear();

}
// public void Clear()
// {
//
// spriteMemory.Clear();
// }

/// <summary>
/// Returns an array of ints that represent a sprite. Each
Expand Down Expand Up @@ -344,7 +351,7 @@ public void UpdateSpriteAt(int index, int[] pixels)
// var totalSprites2 = SpriteChipUtil.CalculateTotalSprites(width2, height2, spriteWidth, spriteHeight);

// Make sure we stay in bounds
index = MathHelper.Clamp(index, 0, totalSprites1 - 1);
index = MathHelper.Clamp(index, 0, spriteMemory.TotalSprites - 1);

var w1 = spriteMemory.Width / width;

Expand Down
4 changes: 2 additions & 2 deletions SDK/Runner/Parsers/SystemParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void ConfigureFontChip(Dictionary<string, object> data)

if (data.ContainsKey("unique")) fontChip.unique = Convert.ToBoolean(data["unique"]);

fontChip.Resize(fontChip.pageWidth, fontChip.pageHeight * fontChip.pages);
// fontChip.Resize(fontChip.pageWidth, fontChip.pageHeight * fontChip.pages);
}

public void ConfigureGameChip(Dictionary<string, object> data)
Expand Down Expand Up @@ -562,7 +562,7 @@ public void ConfigureSpriteChip(Dictionary<string, object> data)

if (data.ContainsKey("unique")) spriteChip.unique = Convert.ToBoolean(data["unique"]);

spriteChip.Resize(spriteChip.pageWidth, spriteChip.pageHeight * spriteChip.pages);
// spriteChip.Resize(spriteChip.pageWidth, spriteChip.pageHeight * spriteChip.pages);
}

public void ConfigureTilemapChip(Dictionary<string, object> data)
Expand Down

0 comments on commit d91cb4d

Please sign in to comment.