Skip to content

Commit

Permalink
Stop-gap solution - change the way queue is handled so that assets ar…
Browse files Browse the repository at this point in the history
…e fetched properly again
  • Loading branch information
xezno committed Mar 9, 2023
1 parent b3b20fb commit 2f97edc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 65 deletions.
13 changes: 2 additions & 11 deletions code/BridgeImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Stop()
listener.EndServer();
}

public async Task ImportFrom( Progress.ProgressBar progressBar, BridgeAsset quixelAsset )
public async Task ImportFrom( BridgeAsset quixelAsset )
{
if ( ExportAsset( quixelAsset, out string path ) )
{
Expand All @@ -30,9 +30,6 @@ public async Task ImportFrom( Progress.ProgressBar progressBar, BridgeAsset quix
Mesh mesh = quixelAsset.Meshes[i];
var mdlPath = Path.Join( relativePath, $"{quixelAsset.Name.ToSourceName()}_{quixelAsset.Id}.vmdl" );

progressBar.SetSubtitle( "Compiling... (2/2)" );
progressBar.SetValues( 0.66f, 1.0f );

// Locate imported s&box asset
var engineAsset = AssetSystem.All.FirstOrDefault( x => x.Path.NormalizeFilename() == mdlPath.NormalizeFilename() );

Expand All @@ -45,14 +42,8 @@ public async Task ImportFrom( Progress.ProgressBar progressBar, BridgeAsset quix
// Force a full compile
engineAsset.Compile( true );

Log.Trace( $"Exported to: {engineAsset}" );

// Highlight in asset browser
MainAssetBrowser.Instance.FocusOnAsset( engineAsset );
Log.Info( $"Exported to: {engineAsset}" );
}

progressBar.SetSubtitle( "Done." );
progressBar.SetValues( 1.0f, 1.0f );
}
}
else
Expand Down
87 changes: 34 additions & 53 deletions code/BridgeServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,9 @@ public void EndServer()
tcpListener.Stop();
}

//
// Shit way of running things on the main thread
// (we should probably just re-write the tcp listener
// code to work better in a single-thread context)
//
[Event.Client.Frame]
public static void OnFrame()
public static void Import()
{
Log.Trace( "Frame" );
if ( !queueDirty )
return;

Expand All @@ -55,57 +50,41 @@ public static void OnFrame()
queueDirty = false;
importQueue.Clear();

var asyncTask = async () =>
{
using var progress = Progress.Start( "Importing from Quixel Bridge..." );
var progressList = new List<Progress.ProgressBar>();

var queueItem = importQueueCopy[0];
var quixelAssets = JsonSerializer.Deserialize<BridgeAsset[]>( queueItem );

//
// Add to progress window
//
for ( int i = 0; i < quixelAssets.Length; i++ )
{
var quixelAsset = quixelAssets[i];
var progressBar = Progress.Bar( $"Import '{quixelAsset.Name}'" );
progressList.Add( progressBar );
progressBar.SetSubtitle( "Waiting..." );
progressBar.SetValues( 0.0f, 1.0f );
}
var queueItem = importQueueCopy[0];
var quixelAssets = JsonSerializer.Deserialize<BridgeAsset[]>( queueItem );

//
// Start compiling
//
for ( int i = 0; i < quixelAssets.Length; i++ )
{
var quixelAsset = quixelAssets[i];
var progressBar = progressList[i];
progressBar.SetSubtitle( "Importing... (1/2)" );
progressBar.SetValues( 0.33f, 1.0f );
await Task.Delay( 50 );

await BridgeImporter.Instance.ImportFrom( progressBar, quixelAsset );
}
//
// Add to progress window
//
for ( int i = 0; i < quixelAssets.Length; i++ )
{
var quixelAsset = quixelAssets[i];
Log.Info( $"Importing '{quixelAsset.Name}'..." );
}

//
// Play a "success" chime if the queue has more than 1 item in it and the
// user has the chime enabled
//
if ( quixelAssets.Length > 1 && BridgeSettings.Instance.EnableAudio )
{
var handle = Audio.Play( "quixel_import_success" );
handle.Position = Vector3.Zero;
handle.ListenLocal = true;
}
//
// Start compiling
//
for ( int i = 0; i < quixelAssets.Length; i++ )
{
var quixelAsset = quixelAssets[i];
Log.Info( $"Compiling '{quixelAsset.Name}'..." );

await Task.Delay( 1000 ); // Give the user an extra second to see that we completed
_ = BridgeImporter.Instance.ImportFrom( quixelAsset );

progressList.ForEach( x => x.Dispose() );
};
Log.Info( $"Completed import for '{quixelAsset.Name}'!" );
}

_ = asyncTask();
//
// Play a "success" chime if the queue has more than 1 item in it and the
// user has the chime enabled
//
if ( quixelAssets.Length > 1 && BridgeSettings.Instance.EnableAudio )
{
var handle = Audio.Play( "quixel_import_success" );
handle.Position = Vector3.Zero;
handle.ListenLocal = true;
}
}

private void ListenThread()
Expand Down Expand Up @@ -135,6 +114,8 @@ private void ListenThread()

importQueue.Add( clientMessage );
queueDirty = true;

Import();
}
catch ( Exception )
{
Expand Down
2 changes: 1 addition & 1 deletion code/Progress/Progress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static class Progress
static ProgressWindow currentWindow;
static int Popups;

class ProgressSection : IDisposable
public class ProgressSection : IDisposable
{
bool disposed;
string oldTitle;
Expand Down

0 comments on commit 2f97edc

Please sign in to comment.