mirror of https://github.com/trudnai/Steve2.git
Rendering running independently on the main thread
This commit is contained in:
parent
4c006f5323
commit
8c7fcc437a
|
@ -405,6 +405,7 @@ class ViewController: NSViewController {
|
||||||
// return
|
// return
|
||||||
|
|
||||||
frameCnt += 1
|
frameCnt += 1
|
||||||
|
|
||||||
if ( frameCnt == fps / 2 ) {
|
if ( frameCnt == fps / 2 ) {
|
||||||
// flashingSpace = blockChar
|
// flashingSpace = blockChar
|
||||||
ViewController.charConvTbl = ViewController.charConvTblFlashOn
|
ViewController.charConvTbl = ViewController.charConvTblFlashOn
|
||||||
|
@ -415,65 +416,68 @@ class ViewController: NSViewController {
|
||||||
frameCnt = 0
|
frameCnt = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var txt : String = ""
|
// Rendering is happening in the main thread, which has two implications:
|
||||||
|
// 1. We can update UI elements
|
||||||
var fromLines = 0
|
// 2. it is independent of the simulation, de that is running in the background thread while we are busy with rendering...
|
||||||
var toLines = textLines
|
DispatchQueue.main.async {
|
||||||
|
|
||||||
|
var txt : String = ""
|
||||||
|
|
||||||
|
var fromLines = 0
|
||||||
|
var toLines = self.textLines
|
||||||
|
|
||||||
if videoMode.text == 0 {
|
if videoMode.text == 0 {
|
||||||
if videoMode.mixed == 1 {
|
if videoMode.mixed == 1 {
|
||||||
fromLines = toLines - 4
|
fromLines = toLines - 4
|
||||||
}
|
|
||||||
else {
|
|
||||||
toLines = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
txtArr = txtClear
|
|
||||||
|
|
||||||
|
|
||||||
// render an empty space to eiminate displaying text portion of the screen covered by graphics
|
|
||||||
for y in 0 ..< fromLines {
|
|
||||||
if videoMode.col80 == 0 {
|
|
||||||
txtArr[ y * (textCols + lineEndChars) + textCols ] = "\n"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
txtArr[ y * (textCols * 2 + lineEndChars) + textCols * 2] = "\n"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// render the rest of the text screen
|
|
||||||
for y in fromLines ..< toLines {
|
|
||||||
for x in 0 ..< textCols {
|
|
||||||
let byte = textBufferPointer[ textLineOfs[y] + x ]
|
|
||||||
let idx = Int(byte);
|
|
||||||
let chr = ViewController.charConvTbl[idx]
|
|
||||||
|
|
||||||
if videoMode.col80 == 0 {
|
|
||||||
txtArr[ y * (textCols + lineEndChars) + x ] = chr
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
txtArr[ y * (textCols * 2 + lineEndChars) + x * 2 + 1] = chr
|
toLines = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let byte = textAuxBufferPointer[ textLineOfs[y] + x ]
|
self.txtArr = self.txtClear
|
||||||
|
|
||||||
|
// render an empty space to eiminate displaying text portion of the screen covered by graphics
|
||||||
|
for y in 0 ..< fromLines {
|
||||||
|
if videoMode.col80 == 0 {
|
||||||
|
self.txtArr[ y * (self.textCols + self.lineEndChars) + self.textCols ] = "\n"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.txtArr[ y * (self.textCols * 2 + self.lineEndChars) + self.textCols * 2] = "\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// render the rest of the text screen
|
||||||
|
for y in fromLines ..< toLines {
|
||||||
|
for x in 0 ..< self.textCols {
|
||||||
|
let byte = self.textBufferPointer[ self.textLineOfs[y] + x ]
|
||||||
let idx = Int(byte);
|
let idx = Int(byte);
|
||||||
let chr = ViewController.charConvTbl[idx]
|
let chr = ViewController.charConvTbl[idx]
|
||||||
|
|
||||||
txtArr[ y * (textCols * 2 + lineEndChars) + x * 2] = chr
|
if videoMode.col80 == 0 {
|
||||||
|
self.txtArr[ y * (self.textCols + self.lineEndChars) + x ] = chr
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.txtArr[ y * (self.textCols * 2 + self.lineEndChars) + x * 2 + 1] = chr
|
||||||
|
|
||||||
|
let byte = self.textAuxBufferPointer[ self.textLineOfs[y] + x ]
|
||||||
|
let idx = Int(byte);
|
||||||
|
let chr = ViewController.charConvTbl[idx]
|
||||||
|
|
||||||
|
self.txtArr[ y * (self.textCols * 2 + self.lineEndChars) + x * 2] = chr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if videoMode.col80 == 0 {
|
||||||
|
self.txtArr[ y * (self.textCols + self.lineEndChars) + self.textCols ] = "\n"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.txtArr[ y * (self.textCols * 2 + self.lineEndChars) + self.textCols * 2] = "\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if videoMode.col80 == 0 {
|
|
||||||
txtArr[ y * (textCols + lineEndChars) + textCols ] = "\n"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
txtArr[ y * (textCols * 2 + lineEndChars) + textCols * 2] = "\n"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
txt = String(txtArr)
|
txt = String(self.txtArr)
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
if videoMode.col80 != self.currentVideoMode.col80 {
|
if videoMode.col80 != self.currentVideoMode.col80 {
|
||||||
self.currentVideoMode.col80 = videoMode.col80
|
self.currentVideoMode.col80 = videoMode.col80
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue