JelleGraaf / PowerSpel2

PowerSpel, but six years of experience later
GNU General Public License v3.0
2 stars 1 forks source link

Drawing optimization #2

Open SteveL-MSFT opened 5 months ago

SteveL-MSFT commented 5 months ago

Saw your community demo on this. Thought it was great. However, I did notice that the drawing aspect was not fast. Looking at your code, I think one optimization you should make is instead of writing each cell with Write-Host, write it to a string and then render it to the console all at once. Would suggest using a StringBuilder to construct the output and then a single Write-Host at the end. The only "challenge" I see is color output which you rely on with Write-Host. Instead, you'd have to use VT escape sequences. The easiest way is to use $PSStyle, but if you need it to work on Windows PowerShell 5.1, you could use $PSStyle on PowerShell 7 just to get the VT escape sequence to use with Windows PowerShell 5.1.

JelleGraaf commented 5 months ago

Hi Steve. Thanks for your feedback! I will certainly have a look at your suggestions. The colors are a must-have though, so it's probably going to take some creative thinking to keep those in there. Will let you know if/when I get it working. Thanks again.

HCRitter commented 5 months ago

my idea to optimize the rendering would be to make use of an index array for the game board, instead of re-drawing all. like I've done it in: https://github.com/HCRitter/PSFunctions/blob/main/Start-MultiJob.ps1

for example:

$host.UI.RawUI.CursorPosition = @{ X = 0; Y = $Changingline }
$ChangingLine= $Changeingline.replace('X','Y')
Write-Host  $changingline
JelleGraaf commented 4 months ago

Interesting, never even considered that. Back to the drawing board!