Commit 6fa9193a authored by Jesse Freeman's avatar Jesse Freeman

Cleanup before merging to master.

parent 7916b566
......@@ -20,7 +20,6 @@ using PixelVisionSDK.Utils;
namespace PixelVisionSDK
{
/// <summary>
/// This is the communication layer between the games
/// and the engine's chips. It's designed to provide a clean and safe API
......@@ -33,7 +32,6 @@ namespace PixelVisionSDK
/// </remarks>
public class APIBridge : IAPIBridge
{
//TODO need to make sure this is correctly sized when sprite sizes change
private static readonly int[] tmpPixelData = new int[8 * 8];
protected bool _paused;
......@@ -108,10 +106,8 @@ namespace PixelVisionSDK
public void TogglePause(bool value)
{
if (_paused != value)
{
if (chips.displayChip != null)
chips.displayChip.paused = value;
}
}
public int mouseX
......@@ -143,10 +139,7 @@ namespace PixelVisionSDK
int colorOffset = 0)
{
if (!chips.displayChip.CanDraw())
{
//Debug.Log("Out of draw calls");
return;
}
chips.spriteChip.ReadSpriteAt(id, tmpPixelData);
......@@ -207,7 +200,7 @@ namespace PixelVisionSDK
public void RebuildScreenBuffer()
{
chips.screenBufferChip.RefreshScreenBlock();
}
}
public bool ButtonDown(int button, int player = 0)
{
......@@ -417,10 +410,8 @@ namespace PixelVisionSDK
{
var total = pixelData.Length;
for (var i = 0; i < total; i++)
{
if (pixelData[i] == oldID)
pixelData[i] = newID;
}
return pixelData;
}
......@@ -436,17 +427,11 @@ namespace PixelVisionSDK
//TODO this needs to be optimized
for (var i = 0; i < total; i++)
{
for (var j = 0; j < colorTotal; j++)
{
if (pixelData[i] == oldIDs[j])
pixelData[i] = newIDs[j];
}
}
for (var j = 0; j < colorTotal; j++)
if (pixelData[i] == oldIDs[j])
pixelData[i] = newIDs[j];
return pixelData;
}
}
}
\ No newline at end of file
......@@ -18,7 +18,6 @@ using System;
namespace PixelVisionSDK.Chips
{
/// <summary>
/// The AbstractChip represents plug-in that adds new functionality to the
/// PixelVisionEngine. Simply extend this abstract class and override the
......@@ -44,7 +43,6 @@ namespace PixelVisionSDK.Chips
/// </example>
public class AbstractChip : IChip
{
protected PixelVisionEngine engine;
/// <summary>
......@@ -105,7 +103,5 @@ namespace PixelVisionSDK.Chips
public virtual void Reset()
{
}
}
}
\ No newline at end of file
......@@ -16,11 +16,9 @@
using System;
using PixelVisionSDK.Utils;
using UnityEngine;
namespace PixelVisionSDK.Chips
{
/// <summary>
/// The MusicChpip is a sequencer for playing back ISoundData. It
/// keeps track of playback time and moves through TrackData playing
......@@ -30,6 +28,7 @@ namespace PixelVisionSDK.Chips
/// </summary>
public class MusicChip : AbstractChip, IUpdate
{
protected int _totalTracks;
protected int currentSong;
public bool loopSong;
......@@ -72,13 +71,9 @@ namespace PixelVisionSDK.Chips
{
var sondData = songDataCollection[i];
if (sondData == null)
{
songDataCollection[i] = CreateNewSongData("Untitled" + i, maxTracks);
}
else
{
sondData.totalTracks = totalTracks;
}
}
}
}
......@@ -88,7 +83,8 @@ namespace PixelVisionSDK.Chips
{
get
{
return maxNoteNum;;
return maxNoteNum;
;
}
set
{
......@@ -96,36 +92,21 @@ namespace PixelVisionSDK.Chips
return;
var total = totalLoops;
for (int i = 0; i < total; i++)
{
for (var i = 0; i < total; i++)
songDataCollection[i].totalNotes = value;
}
}
}
public virtual SongData CreateNewSongData(string name, int tracks = 4)
{
return new SongData(name, tracks);
}
protected int _totalTracks = 0;
public int totalTracks
{
get
{
return _totalTracks;
}
get { return _totalTracks; }
set
{
value = Mathf.Clamp(value, 1, maxTracks);
value = value.Clamp(1, maxTracks);
var total = songDataCollection.Length;
for (var i = 0; i < total; i++)
{
songDataCollection[i].totalTracks = value;
}
_totalTracks = value;
}
......@@ -161,13 +142,16 @@ namespace PixelVisionSDK.Chips
//TODO need to make sure this still actually works after removing Time.time reference
if (songCurrentlyPlaying)
{
if (time >= nextBeatTimestamp)
{
nextBeatTimestamp = time + (sequencerBeatNumber % 2 == 1 ? noteTickSOdd : noteTickSEven);
OnBeat();
}
}
}
public virtual SongData CreateNewSongData(string name, int tracks = 4)
{
return new SongData(name, tracks);
}
/// <summary>
......@@ -275,7 +259,6 @@ namespace PixelVisionSDK.Chips
sequencerLoopNum++;
if (sequencerLoopNum >= songLoopCount)
{
if (loopSong)
{
sequencerLoopNum = 0;
......@@ -285,7 +268,6 @@ namespace PixelVisionSDK.Chips
songCurrentlyPlaying = false;
return;
}
}
sequencerBeatNumber = 0;
......@@ -303,16 +285,13 @@ namespace PixelVisionSDK.Chips
var instrument = soundChip.ReadChannel(trackNum);
if (instrument != null)
{
// now play it if possible
if ((gotANote > 0) && (gotANote < maxNoteNum) && (instrument != null))
if (gotANote > 0 && gotANote < maxNoteNum && instrument != null)
{
var frequency = noteStartFrequency[gotANote];
//$CTK midi num offset fix -1]; // -1 to account for 0 based array
instrument.Play(frequency);
}
}
}
sequencerBeatNumber++; // next beat will use array index +1
......@@ -325,14 +304,12 @@ namespace PixelVisionSDK.Chips
var channels = soundChip.totalChannels;
for (var trackNum = 0; trackNum < trackCount; trackNum++)
{
if (trackNum < channels)
{
var sfxID = song.tracks[trackNum].sfxID;
soundChip.LoadSound(sfxID, trackNum);
}
}
}
public void UpdateNoteTickLengths()
......@@ -372,23 +349,10 @@ namespace PixelVisionSDK.Chips
protected void UpdateMusicNotes()
{
for (var x = 0; x < notesPerTrack; x++)
{
// Need to make sure we only play tracks that exists
if (tracksPerLoop < activeSongData.tracks.Length)
{
for (var y = 0; y < tracksPerLoop; y++)
{
// resize invalid array from json data that's funky
if (activeSongData.tracks[y].notes.Length != notesPerTrack)
{
//Debug.LogWarning("Fixing incorrectly sized music notes array."); // feels like a hack FIXME
Array.Resize(ref activeSongData.tracks[y].notes, notesPerTrack);
}
}
}
}
}
}
}
\ No newline at end of file
......@@ -19,14 +19,12 @@ using PixelVisionSDK.Utils;
namespace PixelVisionSDK.Chips
{
/// <summary>
/// The <see cref="SoundChip" /> is responsible for playing back sound
/// effects in the engine. It's powered by SFxr.
/// </summary>
public class SoundChip : AbstractChip
{
protected int _totalSounds;
protected ISoundData[] channels = new ISoundData[0];
......@@ -56,10 +54,8 @@ namespace PixelVisionSDK.Chips
Array.Resize(ref sounds, value);
for (var i = 0; i < value; i++)
{
if (sounds[i] == null)
sounds[i] = CreateEmptySoundData("Untitled" + i.ToString("D2"));
}
}
}
......@@ -83,7 +79,7 @@ namespace PixelVisionSDK.Chips
public void ClearSound(int index)
{
// TODO need to see if there is a better way to revert a sound
sounds[index] = CreateEmptySoundData("Untitled"+index.ToString("D2"));
sounds[index] = CreateEmptySoundData("Untitled" + index.ToString("D2"));
}
/// <summary>
......@@ -193,7 +189,5 @@ namespace PixelVisionSDK.Chips
{
ReadSound(id).name = name;
}
}
}
\ No newline at end of file
......@@ -21,7 +21,6 @@ using PixelVisionSDK.Services;
namespace PixelVisionSDK.Chips
{
/// <summary>
/// The <see cref="ChipManager" /> is responsible for managing all of the
/// chips in the engine. It allows the engine to create chips from a string
......@@ -31,6 +30,7 @@ namespace PixelVisionSDK.Chips
/// </summary>
public class ChipManager : IGameLoop, IServiceLocator
{
protected Dictionary<string, IService> _services = new Dictionary<string, IService>();
protected Dictionary<string, AbstractChip> chips = new Dictionary<string, AbstractChip>();
protected List<IDraw> drawChips = new List<IDraw>();
......@@ -63,9 +63,7 @@ namespace PixelVisionSDK.Chips
var chipNames = chips.Keys.ToList();
foreach (var chipName in chipNames)
{
chips[chipName].Init();
}
// foreach (var chip in chips)
// {
// chip.Value.Init();
......@@ -80,9 +78,7 @@ namespace PixelVisionSDK.Chips
public void Update(float timeDelta)
{
foreach (var chip in updateChips)
{
chip.Update(timeDelta);
}
}
/// <summary>
......@@ -92,9 +88,7 @@ namespace PixelVisionSDK.Chips
public void Draw()
{
foreach (var chip in drawChips)
{
chip.Draw();
}
}
/// <summary>
......@@ -103,9 +97,36 @@ namespace PixelVisionSDK.Chips
public void Reset()
{
foreach (var chip in chips)
{
chip.Value.Reset();
}
}
public Dictionary<string, IService> services
{
get { return _services; }
}
/// <summary>
/// </summary>
/// <param name="id"></param>
/// <param name="service"></param>
public void AddService(string id, IService service)
{
// Add the service to the managed list
if (services.ContainsKey(id))
services[id] = service;
else
services.Add(id, service);
// Add a reference of the service locator
service.RegisterService(this);
}
public IService GetService(string id)
{
if (services.ContainsKey(id))
return services[id];
throw new ApplicationException("The requested service '" + id + "' is not registered");
}
/// <summary>
......@@ -169,7 +190,7 @@ namespace PixelVisionSDK.Chips
}
catch (Exception)
{
throw new Exception("Chip '"+id+"' could not be created.");
throw new Exception("Chip '" + id + "' could not be created.");
}
return chipInstance;
......@@ -197,7 +218,6 @@ namespace PixelVisionSDK.Chips
return;
chip.Activate(engine);
}
/// <summary>
......@@ -208,9 +228,7 @@ namespace PixelVisionSDK.Chips
public void DeactivateChips()
{
foreach (var item in chips)
{
DeactivateChip(item.Key, item.Value);
}
}
/// <summary>
......@@ -248,7 +266,7 @@ namespace PixelVisionSDK.Chips
drawChips.Add(chip as IDraw);
}
if(autoActivate)
if (autoActivate)
chip.Activate(engine);
}
......@@ -276,51 +294,7 @@ namespace PixelVisionSDK.Chips
public void RemoveInactiveChips()
{
foreach (var item in chips.Where(c => c.Value.active == false).ToArray())
{
chips.Remove(item.Key);
}
}
protected Dictionary<string, IService> _services = new Dictionary<string, IService>();
public Dictionary<string, IService> services
{
get { return _services; }
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="service"></param>
public void AddService(string id, IService service)
{
// Add the service to the managed list
if (services.ContainsKey(id))
{
// If the service exists, overwrite it
services[id] = service;
}
else
{
// If the service doesn't exist, create a new reference to it
services.Add(id, service);
}
// Add a reference of the service locator
service.RegisterService(this);
}
public IService GetService(string id)
{
if (services.ContainsKey(id))
return services[id];
throw new ApplicationException("The requested service '" + id + "' is not registered");
}
}
}
\ No newline at end of file
......@@ -22,7 +22,6 @@ using PixelVisionSDK.Utils;
namespace PixelVisionSDK.Chips
{
/// <summary>
/// The <see cref="GameChip" /> represents the foundation of a game class
/// with all the logic it needs to work correctly in the PixelVisionEngine.
......@@ -32,7 +31,6 @@ namespace PixelVisionSDK.Chips
/// </summary>
public class GameChip : AbstractChip, IGame, IUpdate, IDraw
{
private string _name = "Untitle_Game";
protected int _saveSlots;
......@@ -184,9 +182,5 @@ namespace PixelVisionSDK.Chips
base.Deactivate();
engine.currentGame = null;
}
}
}
\ No newline at end of file
......@@ -14,18 +14,14 @@
// Shawn Rakowski - @shwany
//
using System.Collections.Generic;
namespace PixelVisionSDK.Chips
{
/// <summary>
/// The <see cref="IGame" /> internal contains the API
/// calls for a game in the PixelVisionEngine.
/// </summary>
public interface IGame
{
/// <summary>
/// Name of the game.
/// </summary>
......@@ -126,7 +122,5 @@ namespace PixelVisionSDK.Chips
/// float if it is not.
/// </returns>
float GetData(string key, float defaultValue);
}
}
\ No newline at end of file
......@@ -16,12 +16,10 @@
namespace PixelVisionSDK.Chips
{
/// <summary>
/// </summary>
public interface IGameLoop : IUpdate, IDraw
{
/// <summary>
/// The Init() method for the game's live-cycle. This is the first
/// method called on a game when it is run.
......@@ -34,7 +32,5 @@ namespace PixelVisionSDK.Chips
/// you want to execute when a game is started/restarted.
/// </summary>
void Reset();
}
}
\ No newline at end of file
......@@ -19,7 +19,6 @@ using PixelVisionSDK.Utils;
namespace PixelVisionSDK.Chips
{
/// <summary>
/// The <see cref="ColorChip" /> represents the system colors of the engine.
/// It allows the engine to work in color indexes that the display can map
......@@ -27,7 +26,6 @@ namespace PixelVisionSDK.Chips
/// </summary>
public class ColorChip : AbstractChip, IColorChip
{
protected string[] _colors =
{
"#000000",
......@@ -55,18 +53,6 @@ namespace PixelVisionSDK.Chips
private bool invalid;
protected Vector pageSize = new Vector(8, 8);
public string[] hexColors
{
get
{
var colors = new string[total];
Array.Copy(_colors, colors, total);
return colors;
}
}
/// <summary>
/// Defines the total number of colors per virtual page.
......@@ -96,12 +82,8 @@ namespace PixelVisionSDK.Chips
Array.Resize(ref _colors, total);
if (oldTotal < total)
{
for (var i = oldTotal; i < total; i++)
{
_colors[i] = transparent;
}
}
}
}
......@@ -125,17 +107,16 @@ namespace PixelVisionSDK.Chips
/// <value>Int</value>
public int supportedColors { get; protected set; }
public void RecalculateSupportedColors()
public string[] hexColors
{
var count = 0;
var total = _colors.Length;
for (var i = 0; i < total; i++)
get
{
if (_colors[i] != transparent)
count ++;
}
var colors = new string[total];
supportedColors = count;
Array.Copy(_colors, colors, total);
return colors;
}
}
/// <summary>
......@@ -163,13 +144,8 @@ namespace PixelVisionSDK.Chips
colorCache = new ColorData[t];
for (var i = 0; i < t; i++)
{
colorCache[i] = new ColorData(_colors[i]);
//color.HexToColor(_colors[i]);
//colorCache[i] = color;
}
invalid = false;
}
......@@ -191,9 +167,7 @@ namespace PixelVisionSDK.Chips
{
var t = _colors.Length;
for (var i = 0; i < t; i++)
{
UpdateColorAt(i, transparent);
}
}
public void UpdateColorAt(int index, string color)
......@@ -205,13 +179,22 @@ namespace PixelVisionSDK.Chips
color = color.ToUpper();
if (ColorData.ValidateColor(color))
{
_colors[index] = color;
}
invalid = true;
}
public void RecalculateSupportedColors()
{
var count = 0;
var total = _colors.Length;
for (var i = 0; i < total; i++)
if (_colors[i] != transparent)
count++;
supportedColors = count;
}
/// <summary>
/// This method configures the chip. It registers itself with the
......@@ -241,7 +224,5 @@ namespace PixelVisionSDK.Chips
{
pages = MathUtil.CeilToInt(total / colorsPerPage);
}
}
}
\ No newline at end of file
......@@ -18,7 +18,6 @@ using System;
namespace PixelVisionSDK.Chips
{
/// <summary>
/// The color map chip is used to help import sprites and tile maps into the
/// engine if their colors don't match the system colors. When loading
......@@ -27,7 +26,6 @@ namespace PixelVisionSDK.Chips
/// </summary>
public class ColorMapChip : AbstractChip, IColorChip
{
protected string[] _colors = new string[256];
protected string transparent = "#ff00ff";
......@@ -40,15 +38,14 @@ namespace PixelVisionSDK.Chips
var colorCache = new ColorData[t];
for (var i = 0; i < t; i++)
{
colorCache[i] = new ColorData(_colors[i]);
}
return colorCache;
}
}
public string[] hexColors {
public string[] hexColors
{
get
{
var colors = new string[total];
......@@ -73,9 +70,7 @@ namespace PixelVisionSDK.Chips
{
var t = _colors.Length;
for (var i = 0; i < t; i++)
{
UpdateColorAt(i, transparent);
}
}
public string ReadColorAt(int index)
......@@ -94,9 +89,7 @@ namespace PixelVisionSDK.Chips
return;
if (ColorData.ValidateColor(color))
{
_colors[index] = color;
}
}
/// <summary>
......@@ -116,7 +109,5 @@ namespace PixelVisionSDK.Chips
base.Deactivate();
engine.colorMapChip = null;