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

Commit

Permalink
Changing parsers to load data on first step.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Feb 5, 2020
1 parent 2aed7b5 commit c060f36
Show file tree
Hide file tree
Showing 18 changed files with 308 additions and 153 deletions.
2 changes: 1 addition & 1 deletion Runners/CSharpRunner/CSharpRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ where fileExtensions.Any(val => p.EndsWith(val))
tmpEngine.ActivateChip("GameChip", new EmptyTemplateDemoChip());

// Process the files
ProcessFiles(tmpEngine, gameFiles.ToArray(), false, Path.DirectorySeparatorChar);
ProcessFiles(tmpEngine, gameFiles.ToArray());

}

Expand Down
19 changes: 9 additions & 10 deletions Runners/PixelVision8/Runner/Editors/GameEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,10 +1004,9 @@ public void OptimizeSprites()

var tmpPixelData = new int[8 * 8];
var nextSpriteID = 0;
var i = 0;


// Copy the sprites to the temp chip
for (i = 0; i < total; i++)
for (var i = 0; i < total; i++)
{
spriteChip.ReadSpriteAt(i, tmpPixelData);

Expand All @@ -1023,7 +1022,7 @@ public void OptimizeSprites()

total = tmpSpriteChip.spritesInRam;

for (i = 0; i < total; i++)
for (var i = 0; i < total; i++)
{
tmpSpriteChip.ReadSpriteAt(i, tmpPixelData);
spriteChip.UpdateSpriteAt(i, tmpPixelData);
Expand Down Expand Up @@ -1441,7 +1440,7 @@ public void ReindexSprites()
/// </summary>
public void ResizeToolColorMemory()
{
runner.activeEngine.ColorChip.total = 512;
runner.ActiveEngine.ColorChip.total = 512;
}

/// <summary>
Expand Down Expand Up @@ -2048,7 +2047,7 @@ public int[] ReadGameSpriteData(int id, int scaleX = 1, int scaleY = 1, bool fli
/// <returns></returns>
public int[] ReadToolSpriteData(int id, int scaleX = 1, int scaleY = 1, bool flipH = false, bool flipV = false)
{
return ReadSpriteData(runner.activeEngine.SpriteChip, id, scaleX, scaleY, flipH, flipV);
return ReadSpriteData(runner.ActiveEngine.SpriteChip, id, scaleX, scaleY, flipH, flipV);
}

private int[] ReadSpriteData(SpriteChip spriteChip, int id, int scaleX = 1, int scaleY = 1, bool flipH = false,
Expand Down Expand Up @@ -2285,7 +2284,7 @@ public void CopyRenderToDisplay(int x, int y, int width, int height, int colorOf
// }

// Copy to the active game's tilemap layer
runner.activeEngine.GameChip.DrawPixels(tmpPixelData, x, y, width, height, false, false,
runner.ActiveEngine.GameChip.DrawPixels(tmpPixelData, x, y, width, height, false, false,
DrawMode.TilemapCache, colorOffset);
}

Expand Down Expand Up @@ -2330,7 +2329,7 @@ public void CopyRenderToDisplay(int x, int y, int width, int height, int colorOf
// }

// Copy to the active game's tilemap layer
runner.activeEngine.GameChip.DrawPixels(tmpPixelData, x, y, width, height, false, false,
runner.ActiveEngine.GameChip.DrawPixels(tmpPixelData, x, y, width, height, false, false,
DrawMode.TilemapCache, colorOffset);
}

Expand All @@ -2347,7 +2346,7 @@ public void CopyRenderToDisplay(int x, int y, int width, int height, int colorOf
/// <returns></returns>
public string[] ToolColors()
{
return runner.activeEngine.ColorChip.hexColors;
return runner.ActiveEngine.ColorChip.hexColors;
}

/// <summary>
Expand All @@ -2356,7 +2355,7 @@ public string[] ToolColors()
/// <param name="total"></param>
public void ToolRebuildColorPages(int total)
{
runner.activeEngine.ColorChip.total = total;
runner.ActiveEngine.ColorChip.total = total;
}

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions Runners/PixelVision8/Runner/PixelVision8Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public void QuitCurrentTool(Dictionary<string, string> metaData, string tool = n

protected override void Update(GameTime gameTime)
{
if (activeEngine == null || shutdown) return;
if (ActiveEngine == null || shutdown) return;

// TODO make sure this order is correct or maybe it can be cleaned up
if (screenShotActive)
Expand Down Expand Up @@ -379,7 +379,7 @@ protected override void Update(GameTime gameTime)
if (!screenShotActive)
// Console.WriteLine("Take Picture");

screenShotActive = screenshotService.TakeScreenshot(activeEngine);
screenShotActive = screenshotService.TakeScreenshot(ActiveEngine);
}
else if (controllerChip.GetKeyUp(actionKeys[ActionKeys.RecordKey]))
{
Expand Down Expand Up @@ -445,7 +445,7 @@ protected override void Draw(GameTime gameTime)
{
base.Draw(gameTime);

if (Recording) gifEncoder.AddFrame(activeEngine.DisplayChip);
if (Recording) gifEncoder.AddFrame(ActiveEngine.DisplayChip);
}
}
catch (Exception e)
Expand Down Expand Up @@ -746,7 +746,7 @@ public override void ResetGame()
var metaData = lastGameRef.Value;

// Merge values from the active game
foreach (var entry in activeEngine.MetaData)
foreach (var entry in ActiveEngine.MetaData)
if (metaData.ContainsKey(entry.Key))
metaData[entry.Key] = entry.Value;
else
Expand Down Expand Up @@ -863,7 +863,7 @@ public void StartRecording()
gifEncoder = new AnimatedGifEncoder();
gifEncoder.SetDelay(1000 / 60);

gifEncoder.CreatePalette(activeEngine.DisplayChip, activeEngine.ColorChip);
gifEncoder.CreatePalette(ActiveEngine.DisplayChip, ActiveEngine.ColorChip);

Window.Title = windowTitle + " (REC)";
}
Expand Down
118 changes: 61 additions & 57 deletions Runners/PixelVision8/Runner/Services/LoadServicePlus.cs
Original file line number Diff line number Diff line change
@@ -1,57 +1,61 @@
//
// Copyright (c) Jesse Freeman, Pixel Vision 8. All rights reserved.
//
// Licensed under the Microsoft Public License (MS-PL) except for a few
// portions of the code. See LICENSE file in the project root for full
// license information. Third-party libraries used by Pixel Vision 8 are
// under their own licenses. Please refer to those libraries for details
// on the license they use.
//
// Contributors
// --------------------------------------------------------
// This is the official list of Pixel Vision 8 contributors:
//
// Jesse Freeman - @JesseFreeman
// Christina-Antoinette Neofotistou @CastPixel
// Christer Kaitila - @McFunkypants
// Pedro Medeiros - @saint11
// Shawn Rakowski - @shwany
//

using System.IO;
using PixelVision8.Runner.Workspace;

namespace PixelVision8.Runner.Services
{
public class LoadServicePlus : LoadService
{
protected WorkspaceService WorkspaceService;

public LoadServicePlus(WorkspaceService workspaceService)
{
WorkspaceService = workspaceService;
}

public override byte[] ReadAllBytes(string file)
{

var path = WorkspacePath.Parse(file);

using (var memoryStream = new MemoryStream())
{
using (var fileStream = WorkspaceService.OpenFile(path, FileAccess.Read))
{
fileStream.CopyTo(memoryStream);
fileStream.Close();
}

// Console.WriteLine("Add File " + file.Path.Substring(1));

return memoryStream.ToArray();
// files.Add(file.Path.Substring(1), file.Path);//memoryStream.ToArray());
}

// return base.ReadAllBytes(file);
}
}
}
// //
// // Copyright (c) Jesse Freeman, Pixel Vision 8. All rights reserved.
// //
// // Licensed under the Microsoft Public License (MS-PL) except for a few
// // portions of the code. See LICENSE file in the project root for full
// // license information. Third-party libraries used by Pixel Vision 8 are
// // under their own licenses. Please refer to those libraries for details
// // on the license they use.
// //
// // Contributors
// // --------------------------------------------------------
// // This is the official list of Pixel Vision 8 contributors:
// //
// // Jesse Freeman - @JesseFreeman
// // Christina-Antoinette Neofotistou @CastPixel
// // Christer Kaitila - @McFunkypants
// // Pedro Medeiros - @saint11
// // Shawn Rakowski - @shwany
// //
//
// using System.IO;
// using PixelVision8.Runner.Workspace;
//
// namespace PixelVision8.Runner.Services
// {
// public class LoadServicePlus : LoadService
// {
// protected WorkspaceService WorkspaceService;
//
// public LoadServicePlus(WorkspaceService workspaceService)
// {
// WorkspaceService = workspaceService;
// }
//
// public override string GetFileName(string path)
// {
// return WorkspacePath.Parse(path).EntityName;
// }
// public override byte[] ReadAllBytes(string file)
// {
//
// var path = WorkspacePath.Parse(file);
//
// using (var memoryStream = new MemoryStream())
// {
// using (var fileStream = WorkspaceService.OpenFile(path, FileAccess.Read))
// {
// fileStream.CopyTo(memoryStream);
// fileStream.Close();
// }
//
// // Console.WriteLine("Add File " + file.Path.Substring(1));
//
// return memoryStream.ToArray();
// // files.Add(file.Path.Substring(1), file.Path);//memoryStream.ToArray());
// }
//
// // return base.ReadAllBytes(file);
// }
// }
// }
1 change: 1 addition & 0 deletions SDK/PixelVision8.SDK.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Runner\Utils\AnimatedGifEncoder\GifEncoder\AnimatedGifEncoder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Runner\Utils\AnimatedGifEncoder\GifEncoder\LZWEncoder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Runner\Utils\AnimatedGifEncoder\GifEncoder\NeuQuant.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Runner\Utils\FileLoadHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Runner\Utils\JsonUtil.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Runner\Utils\MiniJSON.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Runner\Utils\PNGUtils.cs" />
Expand Down
1 change: 1 addition & 0 deletions SDK/PixelVision8.Workspace.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Runner\Utils\ScriptLoaderUtil.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Runner\Services\BiosService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Runner\Services\WorkspaceService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Runner\Utils\WorkspaceFileLoadHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Runner\Workspace\Collections\EnumerableCollection.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Runner\Workspace\Collections\InverseComparer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Runner\Workspace\FileSystemExtensions.cs" />
Expand Down
12 changes: 6 additions & 6 deletions SDK/Runner/DesktopRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public DesktopRunner()
/// The base runner contains a list of the core chips. Here you'll want to add the game chip to the list so it can run.
/// This is called when a new game is created by the runner.
/// </summary>
public override List<string> defaultChips
public override List<string> DefaultChips
{
get
{
// Get the list of default chips
var chips = base.defaultChips;
var chips = base.DefaultChips;

// Add the custom C# game chip
chips.Add(typeof(LuaGameChip).FullName);
Expand Down Expand Up @@ -126,7 +126,7 @@ protected override void ConfigureRunner()
public override void CreateLoadService()
{

loadService = new LoadServicePlus(workspaceService);
loadService = new LoadService(new WorkspaceFileLoadHelper(workspaceService));

Script.DefaultOptions.ScriptLoader = new ScriptLoaderUtil(workspaceService);
}
Expand Down Expand Up @@ -668,14 +668,14 @@ public virtual void ShutdownSystem()
public override void ShutdownActiveEngine()
{
// Look to see if there is an active engine
if (activeEngine == null) return;
if (ActiveEngine == null) return;

base.ShutdownActiveEngine();

if (activeEngine.GameChip.SaveSlots > 0)
if (ActiveEngine.GameChip.SaveSlots > 0)
//Print("Active Engine To Save", activeEngine.name);

SaveGameData("/Game/", activeEngine, SaveFlags.SaveData,
SaveGameData("/Game/", ActiveEngine, SaveFlags.SaveData,
false);

// Save the active disk
Expand Down

0 comments on commit c060f36

Please sign in to comment.