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

Commit

Permalink
Splitting up logic between full and lite versions of PixelVision8's r…
Browse files Browse the repository at this point in the history
…unner code.
  • Loading branch information
jessefreeman committed Oct 21, 2020
1 parent f8f3775 commit a1cf44b
Show file tree
Hide file tree
Showing 31 changed files with 1,304 additions and 1,200 deletions.
1 change: 0 additions & 1 deletion PixelVision8Lite.CoreDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
<Compile Include="SDK/Engine/Chips/Audio/SoundChannel.cs" />
<Compile Include="SDK/Engine/Chips/Audio/ISoundChip.cs" />
<Compile Include="SDK/Engine/Chips/AbstractChip.cs" />
<Compile Include="SDK/Engine/Chips/Graphics/IDisplay.cs" />
<Compile Include="SDK/Engine/Chips/Graphics/SpriteChip.cs" />
<Compile Include="SDK/Engine/Chips/Graphics/TilemapChip.cs" />
<Compile Include="SDK/Engine/Chips/Graphics/ColorChip.cs" />
Expand Down
2 changes: 1 addition & 1 deletion ProgramLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public override void Draw()

// Draw the x,y position of each sprite
DrawText("(" + MathUtil.FloorToInt(nextPos) + ",8)", pos.X + 32, 8, DrawMode.Sprite, "large", 15);
DrawText("(36," + MathUtil.FloorToInt(nextPos) + ")", 66, pos.Y + 12, DrawMode.Sprite, "large", 15, 0, false);
DrawText("(36," + MathUtil.FloorToInt(nextPos) + ")", 66, pos.Y + 12, DrawMode.Sprite, "large", 15);



Expand Down
2 changes: 1 addition & 1 deletion SDK/Editor/Audio/SfxrMusicGeneratorChip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public void ConfigureGenerator(int tracks)
//workspace.InvalidateSave();
}

public void GenerateSong(IEngine chips)
public void GenerateSong(PixelVisionEngine chips)
{
float noteChangeBoost; // more likely to play a note on beat one of each bar
var restHere = true; // if true, silence
Expand Down
2 changes: 1 addition & 1 deletion SDK/Editor/Editors/GameEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ public bool RunBackgroundScript(string scriptName, string[] args = null)
{
exportService.Restart();

exportService.AddExporter(new BackgroundScriptRunner(scriptName, serviceManager.GetService(typeof(LuaService).FullName) as LuaServicePlus, args));
exportService.AddExporter(new BackgroundScriptRunner(scriptName, serviceManager.GetService(typeof(LuaService).FullName) as LuaService, args));
//
exportService.StartExport();

Expand Down
2 changes: 1 addition & 1 deletion SDK/Editor/Exporters/BackgroundScriptRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Script LuaScript
}
}

public BackgroundScriptRunner(string scriptName, LuaServicePlus luaService, string[] args = null) : base(null)
public BackgroundScriptRunner(string scriptName, LuaService luaService, string[] args = null) : base(null)
{

LuaScript.DoFile(scriptName);
Expand Down
44 changes: 39 additions & 5 deletions SDK/Editor/Exporters/MetaDataExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ public class MetadataExporter : AbstractExporter
{
private readonly IEngine engine;
private StringBuilder sb;

private GameChip gameChip;

public MetadataExporter(string fileName, IEngine engine) : base(fileName)
{
this.engine = engine;
gameChip = this.engine.GameChip as GameChip;

//
// CalculateSteps();
}
Expand All @@ -45,7 +48,7 @@ public override void CalculateSteps()
steps.Add(CreateStringBuilder);

// Serialize Game
if (engine.GameChip != null) steps.Add(delegate { SerializeGameChip(); });
if (engine.GameChip != null) steps.Add(delegate { SerializeGameChip(gameChip); });

// Save the final string builder
steps.Add(CloseStringBuilder);
Expand All @@ -72,11 +75,42 @@ private void CloseStringBuilder()
currentStep++;
}

private void SerializeGameChip()
private void SerializeGameChip(GameChip gameChip)
{

// Name
// sb.Append("\"gameName\":");
// sb.Append("\"");
// sb.Append(gameChip.name);
// sb.Append("\"");
// sb.Append(",");
// JsonUtil.GetLineBreak(sb, 1);
//
// // Description
// sb.Append("\"gameDescription\":");
// sb.Append("\"");
// sb.Append(gameChip.description);
// sb.Append("\"");
// sb.Append(",");
// JsonUtil.GetLineBreak(sb, 1);
//
// // Version
// sb.Append("\"gameVersion\":");
// sb.Append("\"");
// sb.Append(gameChip.version);
// sb.Append("\"");
// sb.Append(",");
// JsonUtil.GetLineBreak(sb, 1);
//
// // ext
// sb.Append("\"gameExt\":");
// sb.Append("\"");
// sb.Append(gameChip.ext);
// sb.Append("\"");
// sb.Append(",");
// JsonUtil.GetLineBreak(sb, 1);

// Loop through all the meta data and save it
var metaData = engine.MetaData;
var metaData = ((PixelVisionEngine)engine).MetaData;

foreach (var data in metaData)
{
Expand Down
2 changes: 1 addition & 1 deletion SDK/Editor/Exporters/MusicExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override void CalculateSteps()

private void SaveGameData()
{
var musicChip = targetEngine.MusicChip;
var musicChip = ((PixelVisionEngine)targetEngine).MusicChip;
sb.Append("\"version\":\"v2\",");
JsonUtil.GetLineBreak(sb, 1);

Expand Down
143 changes: 143 additions & 0 deletions SDK/Editor/Exporters/SfxrSoundExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
//
// 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.Text;
using PixelVision8.Engine;
using PixelVision8.Engine.Chips;
using PixelVision8.Runner.Utils;

namespace PixelVision8.Runner.Exporters
{
public class SfxrSoundExporter : AbstractExporter
{
private readonly IEngine targetEngine;
private StringBuilder sb;
private SfxrSoundChip _sfxrSoundChip;

public SfxrSoundExporter(string fileName, IEngine targetEngine) : base(fileName)
{
this.targetEngine = targetEngine;

_sfxrSoundChip = targetEngine.SoundChip as SfxrSoundChip;

// CalculateSteps();
}

public override void CalculateSteps()
{
base.CalculateSteps();

// Create a new string builder
steps.Add(CreateStringBuilder);


steps.Add(SaveGameData);

// Save the final string builder
steps.Add(CloseStringBuilder);
}

private void SaveGameData()
{
var soundChip = targetEngine.SoundChip;

sb.Append("\"version\":\"v2\",");
JsonUtil.GetLineBreak(sb, 1);

JsonUtil.indentLevel++;
sb.Append("\"sounds\": [");

var total = soundChip.TotalSounds;
for (var i = 0; i < total; i++)
{
var sound = _sfxrSoundChip.ReadSound(i);
// if (sound != null)
// {
JsonUtil.indentLevel++;


// {
// "name":"Melody",
// "settings":"0,.5,,.2,,.2,.3,.1266,,,,,,,,,,,,,,,,,,1,,,,,,"
// },


sb.Append("{");
JsonUtil.GetLineBreak(sb, 1);

sb.Append("\"name\":\"");
sb.Append(sound.name);
sb.Append("\",");
JsonUtil.GetLineBreak(sb, 1);
sb.Append("\"settings\":");
sb.Append("\"" + sound.param + "\"");
JsonUtil.GetLineBreak(sb, 1);
sb.Append("}");

// sb.Append(sound.ReadSettings());
if (i < total - 1) sb.Append(",");

JsonUtil.GetLineBreak(sb, 1);
JsonUtil.indentLevel--;
// }
}

JsonUtil.indentLevel--;
JsonUtil.GetLineBreak(sb, 1);
sb.Append("]");

currentStep++;
}

private void CreateStringBuilder()
{
sb = new StringBuilder();

sb.Append("{");
JsonUtil.indentLevel++;

JsonUtil.GetLineBreak(sb);
sb.Append("\"SoundChip\":");

JsonUtil.GetLineBreak(sb);
sb.Append("{");
JsonUtil.GetLineBreak(sb, 1);

// JsonUtil.indentLevel++;

currentStep++;
}

private void CloseStringBuilder()
{
JsonUtil.indentLevel--;
JsonUtil.GetLineBreak(sb);
sb.Append("}");

JsonUtil.indentLevel--;
JsonUtil.GetLineBreak(sb, 1);
sb.Append("}");

bytes = Encoding.UTF8.GetBytes(sb.ToString());

currentStep++;
}
}
}
14 changes: 7 additions & 7 deletions SDK/Editor/Exporters/SongExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ public class SongExporter : AbstractExporter
public float mixdownTrackVolume = 0.6f;
public float note_tick_s = 15.0f / 120.0f; // (15.0f/120.0f) = 120BPM sixteenth notes
public float note_tick_s_odd;
private RawAudioData result;
private SfxrSynthChannel result;


public float swing_rhythm_factor = 1.0f; //0.7f;//0.66666f; // how much "shuffle" - turnaround on the offbeat triplet

private RawAudioData[] trackresult;
private SfxrSynthChannel[] trackresult;

// int songdataCurrentPos = 0;

public SongExporter(string path, MusicChip musicChip, SoundChip soundChip, int[] patterns) : base(path)
public SongExporter(string path, MusicChip musicChip, ISoundChip soundChip, int[] patterns) : base(path)
{
// Rebuild the path by adding the active song name and wav extension
fileName = path;
Expand Down Expand Up @@ -104,10 +104,10 @@ public void ExportSong()
if (trackresult == null)
{
// all the tracks we need - an array of audioclips that will be merged into result
trackresult = new RawAudioData[tcount];
trackresult = new SfxrSynthChannel[tcount];

for (var i = 0; i < tcount; i++)
trackresult[i] = new RawAudioData(0, 1,
trackresult[i] = new SfxrSynthChannel(0, 1,
preRenderBitrate);
}

Expand Down Expand Up @@ -209,7 +209,7 @@ private void CreateSongByteData()
}

// pre-rendered waveforms - OPTIMIZATION - SLOW SLOW SLOW - FIXME
public RawAudioData MixdownAudioClips(params RawAudioData[] clips)
public SfxrSynthChannel MixdownAudioClips(params SfxrSynthChannel[] clips)
{
if (clips == null || clips.Length == 0) return null;

Expand Down Expand Up @@ -253,7 +253,7 @@ public RawAudioData MixdownAudioClips(params RawAudioData[] clips)
// stereo
//AudioClip result = AudioClip.Create("MixdownSTEREO", length / 2, 2, preRenderBitrate, false);
// mono
var result = new RawAudioData(length / 2, 1, preRenderBitrate);
var result = new SfxrSynthChannel(length / 2, 1, preRenderBitrate);
result.SetData(data); // TODO: we can get a warning here: data too large to fit: discarded x samples
// the truncation can happen with a large sustain of a note that could go on after the song is over
// one solution is to pad the end with 4sec of 0000s then maybe search and TRIM
Expand Down

0 comments on commit a1cf44b

Please sign in to comment.