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

Commit

Permalink
Cleaning up APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Dec 20, 2019
1 parent f6391e6 commit cd2e864
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 49 deletions.
5 changes: 3 additions & 2 deletions Disks/RunnerTools/BootTool/code.lua
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ function Update(timeDelta)
-- Not done with animation, go to next frame
frame = frame + 1
local sprite = bootSprites[frame]
UpdateTiles(10, 12, sprite.width, sprite.spriteIDs)
DrawSprites(sprite.spriteIDs, 10, 12, sprite.width, false, false, DrawMode.Tile)
-- UpdateTiles(, )

elseif(done == false) then

Expand Down Expand Up @@ -272,7 +273,7 @@ function FindEditors()
return {}
end

local paths =
local paths =
{
NewWorkspacePath("/PixelVisionOS/Tools/"),
}
Expand Down
16 changes: 8 additions & 8 deletions Runners/PixelVision8/Runner/Editors/GameEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,9 @@ public void RewindSong(int position = 0, int loopID = 0)
gameChip.RewindSong();
}

public Point SpriteSize(int? width, int? height)
public Point SpriteSize()
{
return gameChip.SpriteSize(width, height);
return gameChip.SpriteSize();
}

public int[] Sprite(int id, int[] data = null)
Expand All @@ -739,10 +739,10 @@ public int[] FlipPixelData(int[] data, bool flipH = false, bool flipV = false, i
return data;
}

public int[] Sprites(int[] ids, int width)
{
return gameChip.Sprites(ids, width);
}
// public int[] Sprites(int[] ids, int width)
// {
// return gameChip.Sprites(ids, width);
// }

public int TotalSprites(bool ignoreEmpty = true)
{
Expand Down Expand Up @@ -774,9 +774,9 @@ public Point TilemapSize(int? width = null, int? height = null, bool clear = fal
return gameChip.TilemapSize(width, height, clear);
}

public void UpdateTiles(int column, int row, int columns, int[] ids, int? colorOffset = null, int? flag = null)
public void UpdateTiles(int[] ids, int? colorOffset = null, int? flag = null)
{
gameChip.UpdateTiles(column, row, columns, ids, colorOffset, flag);
gameChip.UpdateTiles(ids, colorOffset, flag);
}

/// <summary>
Expand Down
47 changes: 11 additions & 36 deletions SDK/Engine/Chips/Game/GameChip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,10 @@ public Point Display(bool visible = true)
/// Returns the visible bounds of the display as a Rectangle.
/// </summary>
/// <returns></returns>
public Rectangle VisibleBounds()
{
return displayChip.visibleBounds;
}
// public Rectangle VisibleBounds()
// {
// return displayChip.visibleBounds;
// }

/// <summary>
/// This method allows you to draw raw pixel data directly to the display. Depending on which draw mode you
Expand Down Expand Up @@ -1410,12 +1410,10 @@ public void RewindSong(int position = 0, int patternID = 0)
/// <returns>
/// Returns a vector where the X and Y for the sprite's width and height.
/// </returns>
public Point SpriteSize(int? width = 8, int? height = 8)
public Point SpriteSize()
{
var size = new Point(spriteChip.width, spriteChip.height);

// TODO you can't resize sprites at runtime

return size;
}

Expand Down Expand Up @@ -1452,29 +1450,6 @@ public int[] Sprite(int id, int[] data = null)
return tmpSpriteData;
}

/// <summary>
/// This allows you to get the pixel data of multiple sprites. This is a read only method but
/// can be used to copy a collection of sprites into memory and draw them to the display in a
/// single pass.
/// </summary>
/// <param name="ids"></param>
/// <param name="width"></param>
/// <returns></returns>
public int[] Sprites(int[] ids, int width)
{
var spriteSize = SpriteSize();
var realWidth = width * spriteSize.X;
var realHeight = (int) Math.Ceiling((float) ids.Length / width) * spriteSize.Y;

var textureData = new TextureData(realWidth, realHeight);

var pixelData = new int[realWidth * realHeight];

textureData.CopyPixels(ref pixelData);

return pixelData;
}

/// <summary>
/// Returns the total number of sprites in the system. You can pass in an optional argument to
/// get a total number of sprites the Sprite Chip can store by passing in false for ignoreEmpty.
Expand All @@ -1490,9 +1465,9 @@ public int[] Sprites(int[] ids, int width)
/// This method returns the total number of sprites in the color chip based on the ignoreEmpty
/// argument's value.
/// </returns>
public int TotalSprites(bool ignoreEmpty = true)
public int TotalSprites(bool ignoreEmpty = false)
{
return ignoreEmpty ? spriteChip.totalSprites : spriteChip.spritesInRam;
return ignoreEmpty ? spriteChip.spritesInRam : spriteChip.totalSprites;
}

/// <summary>
Expand Down Expand Up @@ -1689,9 +1664,10 @@ public Point TilemapSize(int? width = null, int? height = null, bool clear = fal
/// <param name="flag">
/// An optional flag int value to be applied to each updated tile.
/// </param>
public void UpdateTiles(int column, int row, int columns, int[] ids, int? colorOffset = null, int? flag = null)
public void UpdateTiles(int[] ids, int? colorOffset = null, int? flag = null)
{
var total = ids.Length;
var width = TilemapSize().X;

int id, newX, newY;

Expand All @@ -1701,10 +1677,9 @@ public void UpdateTiles(int column, int row, int columns, int[] ids, int? colorO
{
id = ids[i];

newX = MathUtil.FloorToInt(i % columns) + column;
newY = MathUtil.FloorToInt(i / (float) columns) + row;
var pos = CalculatePosition(id, width);

Tile(newX, newY, id, colorOffset, flag);
Tile(pos.X, pos.Y, null, colorOffset, flag);
}
}

Expand Down
8 changes: 5 additions & 3 deletions SDK/Engine/Chips/Game/LuaGameChip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ public override void Reset()

#region Sound APIs

luaScript.Globals["Sound"] = new Func<int, string, string>(Sound);
luaScript.Globals["PlaySound"] = new Action<int, int>(PlaySound);
luaScript.Globals["StopSound"] = new Action<int>(StopSound);
luaScript.Globals["PlayRawSound"] = new Action<string, int, float>(soundChip.PlayRawSound);

luaScript.Globals["IsChannelPlaying"] = new Func<int, bool>(IsChannelPlaying);
Expand All @@ -188,8 +190,8 @@ public override void Reset()
#region Sprite APIs

luaScript.Globals["Sprite"] = new Func<int, int[], int[]>(Sprite);
luaScript.Globals["Sprites"] = new Func<int[], int, int[]>(Sprites);
luaScript.Globals["SpriteSize"] = new Func<int?, int?, Point>(SpriteSize);
// luaScript.Globals["Sprites"] = new Func<int[], int, int[]>(Sprites);
luaScript.Globals["SpriteSize"] = new Func<Point>(SpriteSize);
luaScript.Globals["TotalSprites"] = new Func<bool, int>(TotalSprites);
luaScript.Globals["MaxSpriteCount"] = new Func<int>(MaxSpriteCount);

Expand All @@ -201,7 +203,7 @@ public override void Reset()

luaScript.Globals["TilemapSize"] = new Func<int?, int?, bool, Point>(TilemapSize);
luaScript.Globals["Tile"] = new Func<int, int, int?, int?, int?, bool?, bool?, TileData>(Tile);
luaScript.Globals["UpdateTiles"] = new Action<int, int, int, int[], int?, int?>(UpdateTiles);
luaScript.Globals["UpdateTiles"] = new Action<int[], int?, int?>(UpdateTiles);
luaScript.Globals["Flag"] = new Func<int, int, int?, int>(Flag);


Expand Down

0 comments on commit cd2e864

Please sign in to comment.