-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move video redraw out of FastTimer and instead to a dedicated thread …
…synced with VDP via REG_SCANLINE from #3
- Loading branch information
Showing
16 changed files
with
334 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
v9t9/v9t9-java/v9t9-common/src/v9t9/common/video/VideoThread.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* | ||
*/ | ||
package v9t9.common.video; | ||
|
||
import java.io.PrintWriter; | ||
|
||
import ejs.base.properties.IProperty; | ||
import ejs.base.settings.Logging; | ||
import v9t9.common.client.ISettingsHandler; | ||
import v9t9.common.client.IVideoRenderer; | ||
import v9t9.common.cpu.ICpu; | ||
import v9t9.common.hardware.IVdpChip; | ||
|
||
/** | ||
* @author ejs | ||
* | ||
*/ | ||
public class VideoThread extends Thread { | ||
|
||
private IVideoRenderer videoRenderer; | ||
private Object sync; | ||
private IProperty dumpVdpAccess; | ||
private IProperty dumpFullInstructions; | ||
|
||
public VideoThread(IVideoRenderer videoRenderer) { | ||
setName("Video Thread"); | ||
this.videoRenderer = videoRenderer; | ||
sync = new Object(); | ||
|
||
ISettingsHandler settings = videoRenderer.getVdpHandler().getMachine().getSettings(); | ||
dumpVdpAccess = settings.get(IVdpChip.settingDumpVdpAccess); | ||
dumpFullInstructions = settings.get(ICpu.settingDumpFullInstructions); | ||
} | ||
|
||
/** | ||
* Invoke Object#notifyAll() on this object to trigger | ||
* a redraw. | ||
* @return | ||
*/ | ||
public Object getSync() { | ||
return sync; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
synchronized (sync) { | ||
while (!isInterrupted()) { | ||
try { | ||
// attempt update at least once a second even if the | ||
// CPU and/or video threads are somehow frozen | ||
sync.wait(1000); | ||
|
||
// got notify | ||
synchronized (videoRenderer.getVdpHandler()) { | ||
synchronized (videoRenderer) { | ||
synchronized (videoRenderer.getCanvasHandler()) { | ||
synchronized (videoRenderer.getCanvas()) { | ||
updateVideo(); | ||
} | ||
} | ||
} | ||
} | ||
} catch (InterruptedException e) { | ||
break; | ||
} | ||
} | ||
|
||
} | ||
|
||
System.out.println("Exiting video thread"); | ||
} | ||
|
||
private void log(String msg) { | ||
if (dumpVdpAccess.getBoolean()) { | ||
PrintWriter pw = Logging.getLog(dumpFullInstructions); | ||
if (pw != null) | ||
pw.println("[VideoThread] " + msg); | ||
} | ||
} | ||
|
||
public void updateVideo() { | ||
if (videoRenderer.isIdle() && videoRenderer.isVisible()) { | ||
log("updating VDP canvas"); | ||
videoRenderer.getCanvasHandler().update(); | ||
videoRenderer.queueRedraw(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.