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

Commit

Permalink
Cleaning up API.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Dec 10, 2019
1 parent 36cba9e commit 0690bbe
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 41 deletions.
3 changes: 2 additions & 1 deletion Disks/PixelVision8System/code.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
a new game. Simply delete the following code and implement your own Init(),
Update() and Draw() logic.
Learn more about making Pixel Vision 8 games at https://www.gitbook.com/@pixelvision8
Learn more about making Pixel Vision 8 games at
https://www.pixelvision8.com/getting-started
]]--

-- This this is an empty game, we will the following text. We combined two sets of fonts into
Expand Down
3 changes: 3 additions & 0 deletions Disks/RunnerTools/BootTool/code.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ end

function Update(timeDelta)

-- Convert timeDelta to a float
timeDelta = timeDelta / 1000

-- Track time of animation
time = time + timeDelta

Expand Down
3 changes: 3 additions & 0 deletions Disks/RunnerTools/ErrorTool/code.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ end

function Update(timeDelta)

-- Convert timeDelta to a float
timeDelta = timeDelta / 1000

animTime = animTime + timeDelta
if(animTime > animDelay) then
animTime = 0
Expand Down
3 changes: 3 additions & 0 deletions Disks/RunnerTools/LoadTool/code.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ end

function Update(timeDelta)

-- Convert timeDelta to a float
timeDelta = timeDelta / 1000

-- Calculate start delay
delayTime = delayTime + timeDelta

Expand Down
2 changes: 1 addition & 1 deletion Runners/PixelVision8/Runner/Editors/GameEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ public Point OctaveRange(int? min, int? max)
/// Manually update the sequencer
/// </summary>
/// <param name="timeDelta"></param>
public void UpdateSequencer(float timeDelta)
public void UpdateSequencer(int timeDelta)
{
musicChip.Update(timeDelta);
}
Expand Down
5 changes: 3 additions & 2 deletions SDK/Engine/Chips/Audio/MusicChip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,10 @@ public TrackerData ActiveTrackerData
/// move the play head to the next beat and play that note.
/// </summary>
/// <param name="timeDelta"></param>
public void Update(float timeDelta)
public void Update(int timeDelta)
{
time += timeDelta;
// Need to conver the time to a float
time += timeDelta / 1000f;

songData["playing"] = Convert.ToInt32(songCurrentlyPlaying);

Expand Down
20 changes: 2 additions & 18 deletions SDK/Engine/Chips/Game/GameChip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class GameChip : AbstractChip, IUpdate, IDraw
//
public int fps;
public Dictionary<string, string> savedData = new Dictionary<string, string>();
public Dictionary<string, string> textFiles = new Dictionary<string, string>();

private int[] tmpFontData = new int[0];

private int[] tmpSpriteData = new int[0];
Expand All @@ -87,22 +87,6 @@ public class GameChip : AbstractChip, IUpdate, IDraw

public int CurrentSprites { get; set; }

/// <summary>
/// This allows you to add your Lua scripts at runtime to a game from a string. This could be useful for
/// dynamically generating code such as level data or other custom Lua objects in memory. Simply give the
/// script a name and pass in a string with valid Lua code. If a script with the same name exists, this will
/// override it. Make sure to call LoadScript() after to parse it.
/// </summary>
/// <param name="name">Name of the script. This should contain the .lua extension.</param>
/// <param name="file">The string text representing the Lua script data.</param>
public void AddTextFile(string name, string file)
{
if (textFiles.ContainsKey(name))
textFiles[name] = file;
else
textFiles.Add(name, file);
}

#region GameChip Properties

/// <summary>
Expand Down Expand Up @@ -169,7 +153,7 @@ public override void Configure()
/// Runner
/// </label>
/// <param name="timeDelta">A float value representing the time in milliseconds since the last Draw() call was completed.</param>
public virtual void Update(float timeDelta)
public virtual void Update(int timeDelta)
{
// Overwrite this method and add your own draw logic.
}
Expand Down
5 changes: 3 additions & 2 deletions SDK/Engine/Chips/Game/LuaGameChip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace PixelVision8.Engine.Chips
public class LuaGameChip : GameChip
{
protected Script _luaScript;

public Dictionary<string, string> textFiles = new Dictionary<string, string>();
public Script luaScript
{
get
Expand All @@ -58,7 +58,7 @@ public override void Init()
luaScript.Call(luaScript.Globals["Init"]);
}

public override void Update(float timeDelta)
public override void Update(int timeDelta)
{
base.Update(timeDelta);

Expand Down Expand Up @@ -140,6 +140,7 @@ public override void Reset()

#region File IO APIs

luaScript.Globals["AddScript"] = new Action<string, string>(AddScript);
luaScript.Globals["LoadScript"] = new Action<string>(LoadScript);
luaScript.Globals["ReadSaveData"] = new Func<string, string, string>(ReadSaveData);
luaScript.Globals["WriteSaveData"] = new Action<string, string>(WriteSaveData);
Expand Down
2 changes: 1 addition & 1 deletion SDK/Engine/Chips/IUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public interface IUpdate
/// input.
/// </summary>
/// <param name="timeDelta"></param>
void Update(float timeDelta);
void Update(int timeDelta);
}
}
2 changes: 1 addition & 1 deletion SDK/Engine/Chips/Input/ControllerChip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class ControllerChip : AbstractChip, IControllerChip

private Keys? repChar;

public void Update(float timeDelta)
public void Update(int timeDelta)
{
// Save the one and only (if available) keyboardstate
previousKeyboardState = currentKeyboardState;
Expand Down
6 changes: 1 addition & 5 deletions SDK/Engine/PixelVisionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,8 @@ public virtual void RunGame()
/// </summary>
/// <param name="timeDelta"></param>
/// <tocexclude />
public virtual void Update(float timeDelta)
public virtual void Update(int timeDelta)
{
// int delta = (int)(timeDelta * 1000);
//
// Console.WriteLine(timeDelta + " " + delta + " " + delta/1000);

// Reset the sprite counter on each frame
gameChip.CurrentSprites = 0;

Expand Down
2 changes: 1 addition & 1 deletion SDK/Runner/Data/DisplayTarget.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
 //
// Copyright (c) Jesse Freeman, Pixel Vision 8. All rights reserved.
//
// Licensed under the Microsoft Public License (MS-PL) except for a few
Expand Down
8 changes: 2 additions & 6 deletions SDK/Runner/GameRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public enum RunnerMode
protected IServiceLocator serviceManager;

// protected bool stretchScreen;
protected float timeDelta;
protected int timeDelta;
protected IEngine tmpEngine;

public GameRunner()
Expand Down Expand Up @@ -383,7 +383,7 @@ protected override void Update(GameTime gameTime)
return;


timeDelta = (float) gameTime.ElapsedGameTime.TotalSeconds;
timeDelta = (int)(gameTime.ElapsedGameTime.TotalSeconds * 1000);

elapsedTime += gameTime.ElapsedGameTime;

Expand All @@ -394,15 +394,11 @@ protected override void Update(GameTime gameTime)
// Make sure the game chip has the current fps value
activeEngine.gameChip.fps = frameCounter;

// Save this to the runner
// frameRate = frameCounter;

frameCounter = 0;
}

// Before trying to update the PixelVisionEngine instance, we need to make sure it exists. The guard clause protects us from throwing an
// error when the Runner loads up and starts before we've had a chance to instantiate the new engine instance.

activeEngine.Update(timeDelta);

// It's important that we pass in the Time.deltaTime to the PixelVisionEngine. It is passed along to any Chip that registers itself with
Expand Down
6 changes: 3 additions & 3 deletions SDK/Runner/Parsers/ScriptParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public class ScriptParser : AbstractParser
{
private readonly string name;
private readonly string script;
private readonly GameChip target;
private readonly LuaGameChip target;

public ScriptParser(string name, string script, GameChip target)
{
this.name = name;
this.script = script;
this.target = target;
this.target = target as LuaGameChip;
}

public override void CalculateSteps()
Expand All @@ -44,7 +44,7 @@ public override void CalculateSteps()

protected void LoadScript()
{
target.AddTextFile(name, script);
target?.AddScript(name, script);
currentStep++;
}
}
Expand Down

0 comments on commit 0690bbe

Please sign in to comment.