1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-06-11 17:29:29 +00:00

Tweak visualizer interface

Report visualization generation errors through an explicit
IApplication interface, instead of pulling messages out of the
DebugLog stream.

Declare that GetVisGenDescrs() is only called when the plugin is in
the "prepared" state, so that plugins can taylor the set based on
the contents of the file.  (This could be used to set min/max on
the "offset" entries, but I want special handling for offsets, so
we might as well set it later.)
This commit is contained in:
Andy McFadden 2019-12-05 10:21:07 -08:00
parent 4ef1d7e7c7
commit 4bf1ab2799
6 changed files with 48 additions and 22 deletions

View File

@ -140,7 +140,9 @@ namespace PluginCommon {
public interface IPlugin_Visualizer {
/// <summary>
/// Retrieves a list of descriptors for visualization generators implemented by this
/// plugin. The caller must not modify the contents.
/// plugin. The items in the set may have values based on the file data.
///
/// The caller must not modify the contents.
/// </summary>
VisDescr[] GetVisGenDescrs();
@ -150,7 +152,8 @@ namespace PluginCommon {
/// <param name="descr">VisGen identifier.</param>
/// <param name="parms">Parameter set.</param>
/// <returns>2D visualization object reference, or null if something went
/// wrong (unknown ident, bad parameters, etc).</returns>
/// wrong (unknown ident, bad parameters, etc). By convention, an error
/// message is reported through the IApplication ReportError interface.</returns>
IVisualization2d Generate2d(VisDescr descr, ReadOnlyDictionary<string, object> parms);
}
@ -306,6 +309,12 @@ namespace PluginCommon {
/// is passed to the plugin as an argument to Prepare().
/// </summary>
public interface IApplication {
/// <summary>
/// Reports an error message to the application. Used by visualizers.
/// </summary>
/// <param name="msg"></param>
void ReportError(string msg);
/// <summary>
/// Sends a debug message to the application. This can be useful when debugging scripts.
/// (For example, DEBUG > Show Analyzer Output shows output generated while performing

View File

@ -20,7 +20,7 @@ using System.Text;
namespace PluginCommon {
/// <summary>
/// Bitmap with 8-bit palette indices, for use with plugin visualizers.
/// Bitmap with 8-bit palette indices, for use with visualization generators.
/// </summary>
[Serializable]
public class VisBitmap8 : IVisualization2d {

View File

@ -76,6 +76,10 @@ namespace SourceGen {
mOuter = null;
}
public void ReportError(string msg) {
DebugLog(msg);
}
public void DebugLog(string msg) {
mOuter.mDebugLog.LogI("PLUGIN: " + msg);
}

View File

@ -107,6 +107,11 @@ namespace RuntimeData.Apple {
// IPlugin_Visualizer
public VisDescr[] GetVisGenDescrs() {
// We're using a static set, but it could be generated based on file contents.
// Confirm that we're prepared.
if (mFileData == null) {
return null;
}
return mDescriptors;
}
@ -121,7 +126,7 @@ namespace RuntimeData.Apple {
case VIS_GEN_HR_SCREEN:
return GenerateScreen(parms);
default:
mAppRef.DebugLog("Unknown ident " + descr.Ident);
mAppRef.ReportError("Unknown ident " + descr.Ident);
return null;
}
}
@ -147,21 +152,21 @@ namespace RuntimeData.Apple {
byteWidth <= 0 || byteWidth > MAX_DIM ||
height <= 0 || height > MAX_DIM) {
// the UI should flag these based on range (and ideally wouldn't have called us)
mAppRef.DebugLog("Invalid parameter");
mAppRef.ReportError("Invalid parameter");
return null;
}
if (colStride <= 0 || colStride > MAX_DIM) {
mAppRef.DebugLog("Invalid column stride");
mAppRef.ReportError("Invalid column stride");
return null;
}
if (rowStride < byteWidth * colStride - (colStride - 1) || rowStride > MAX_DIM) {
mAppRef.DebugLog("Invalid row stride");
mAppRef.ReportError("Invalid row stride");
return null;
}
int lastOffset = offset + rowStride * height - (colStride - 1) - 1;
if (lastOffset >= mFileData.Length) {
mAppRef.DebugLog("Bitmap runs off end of file (last offset +" +
mAppRef.ReportError("Bitmap runs off end of file (last offset +" +
lastOffset.ToString("x6") + ")");
return null;
}
@ -185,13 +190,13 @@ namespace RuntimeData.Apple {
itemByteWidth <= 0 || itemByteWidth > MAX_DIM ||
itemHeight <= 0 || itemHeight > MAX_DIM) {
// should be caught by editor
mAppRef.DebugLog("Invalid parameter");
mAppRef.ReportError("Invalid parameter");
return null;
}
int lastOffset = offset + itemByteWidth * itemHeight - 1;
if (lastOffset >= mFileData.Length) {
mAppRef.DebugLog("Bitmap runs off end of file (last offset +" +
mAppRef.ReportError("Bitmap runs off end of file (last offset +" +
lastOffset.ToString("x6") + ")");
return null;
}
@ -248,13 +253,13 @@ namespace RuntimeData.Apple {
if (offset < 0 || offset >= mFileData.Length) {
// should be caught by editor
mAppRef.DebugLog("Invalid parameter");
mAppRef.ReportError("Invalid parameter");
return null;
}
int lastOffset = offset + RAW_IMAGE_SIZE - 1;
if (lastOffset >= mFileData.Length) {
mAppRef.DebugLog("Bitmap runs off end of file (last offset +" +
mAppRef.ReportError("Bitmap runs off end of file (last offset +" +
lastOffset.ToString("x6") + ")");
return null;
}
@ -523,7 +528,7 @@ namespace RuntimeData.Apple {
break;
default:
// just leave the bitmap empty
mAppRef.DebugLog("Unknown ColorMode " + colorMode);
mAppRef.ReportError("Unknown ColorMode " + colorMode);
break;
}
}

View File

@ -91,6 +91,10 @@ namespace SourceGen {
private class ScriptSupport : MarshalByRefObject, PluginCommon.IApplication {
public ScriptSupport() { }
public void ReportError(string msg) {
DebugLog(msg);
}
public void DebugLog(string msg) {
Debug.WriteLine("Vis plugin: " + msg);
}
@ -130,22 +134,22 @@ namespace SourceGen {
}
Debug.WriteLine("Vis needs refresh: " + vis.Tag);
if (iapp == null) {
// Prep the plugins on first need.
iapp = new ScriptSupport();
project.PrepareScripts(iapp);
}
if (plugins == null) {
plugins = project.GetActivePlugins();
}
IPlugin_Visualizer vplug = FindPluginByVisGenIdent(plugins,
vis.VisGenIdent, out VisDescr visDescr);
if (vplug == null) {
Debug.WriteLine("Unable to referesh " + vis.Tag + ": plugin not found");
Debug.WriteLine("Unable to refresh " + vis.Tag + ": plugin not found");
continue;
}
if (iapp == null) {
// Prep the plugins on first need.
iapp = new ScriptSupport();
project.PrepareScripts(iapp);
}
IVisualization2d vis2d;
try {
vis2d = vplug.Generate2d(visDescr,

View File

@ -125,9 +125,13 @@ namespace SourceGen.WpfGui {
mOuter = outer;
}
public void ReportError(string msg) {
mOuter.LastPluginMessage = msg;
DebugLog(msg);
}
public void DebugLog(string msg) {
Debug.WriteLine("Vis plugin: " + msg);
mOuter.LastPluginMessage = msg;
}
public bool SetOperandFormat(int offset, DataSubType subType, string label) {
@ -165,6 +169,7 @@ namespace SourceGen.WpfGui {
mOrigVis = vis;
mScriptSupport = new ScriptSupport(this);
mProject.PrepareScripts(mScriptSupport);
if (vis != null) {
TagString = vis.Tag;
@ -191,7 +196,6 @@ namespace SourceGen.WpfGui {
// Set the selection. This should cause the sel change event to fire.
visComboBox.SelectedIndex = visSelection;
mProject.PrepareScripts(mScriptSupport);
}
/// <summary>