foxygit / fake-08-xbox360 Log in
commit 01f7f7a545469d515e446f6496bc013d0db74ad7
Author:     jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Sun Nov 22 21:38:45 2020 -0700
Commit:     jtothebell <j.to.the.bell@gmail.com>
CommitDate: Sun Nov 22 21:38:45 2020 -0700

    move gameloop into Vm class
---
 source/main.cpp | 31 +------------------------------
 source/vm.cpp   | 31 +++++++++++++++++++++++++++++++
 source/vm.h     |  2 ++
 3 files changed, 34 insertions(+), 30 deletions(-)

diff --git a/source/main.cpp b/source/main.cpp
index 4a9e948..d914a20 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -33,36 +33,7 @@ int main(int argc, char* argv[])
 	// Main loop
 	Logger::Write("Starting main loop\n");

-	while (host->shouldRunMainLoop())
-	{
-		int targetFps = vm->GetTargetFps();
-		//shouldn't need to set this every frame
-		host->setTargetFps(targetFps);
-
-		//is this better at the end of the loop?
-		host->waitForTargetFps();
-
-		if (host->shouldQuit()) break; // break in order to return to hbmenu
-		//this should probably be handled just in the host class
-		host->changeStretch();
-
-		//update buttons needs to be callable from the cart, and also flip
-		//it should update call the pico part of scanInput and set the values in memory
-		//then we don't need to pass them in here
-		vm->UpdateAndDraw();
-
-		uint8_t* picoFb = vm->GetPicoInteralFb();
-		uint8_t* screenPaletteMap = vm->GetScreenPaletteMap();
-
-		host->drawFrame(picoFb, screenPaletteMap);
-
-		if (host->shouldFillAudioBuff()) {
-			vm->FillAudioBuffer(host->getAudioBufferPointer(), 0, host->getAudioBufferSize());
-
-			host->playFilledAudioBuffer();
-		}
-	}
-
+	vm->GameLoop();

 	Logger::Write("Turning off vm and exiting logger\n");
 	vm->CloseCart();
diff --git a/source/vm.cpp b/source/vm.cpp
index ebacfe5..91a557d 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -413,6 +413,37 @@ string Vm::GetBiosError() {
     return _cartLoadError;
 }

+void Vm::GameLoop() {
+    while (_host->shouldRunMainLoop())
+	{
+		//shouldn't need to set this every frame
+		_host->setTargetFps(_targetFps);
+
+		//is this better at the end of the loop?
+		_host->waitForTargetFps();
+
+		if (_host->shouldQuit()) break; // break in order to return to hbmenu
+		//this should probably be handled just in the host class
+		_host->changeStretch();
+
+		//update buttons needs to be callable from the cart, and also flip
+		//it should update call the pico part of scanInput and set the values in memory
+		//then we don't need to pass them in here
+		UpdateAndDraw();
+
+		uint8_t* picoFb = GetPicoInteralFb();
+		uint8_t* screenPaletteMap = GetScreenPaletteMap();
+
+		_host->drawFrame(picoFb, screenPaletteMap);
+
+		if (_host->shouldFillAudioBuff()) {
+			FillAudioBuffer(_host->getAudioBufferPointer(), 0, _host->getAudioBufferSize());
+
+			_host->playFilledAudioBuffer();
+		}
+	}
+}
+
 bool Vm::ExecuteLua(string luaString, string callbackFunction){
     int success = luaL_dostring(_luaState, luaString.c_str());

diff --git a/source/vm.h b/source/vm.h
index c56c628..1b1cbc8 100644
--- a/source/vm.h
+++ b/source/vm.h
@@ -78,6 +78,8 @@ class Vm {

     int GetFrameCount();

+    void GameLoop();
+
     void SetCartList(vector<string> cartList);
     vector<string> GetCartList();
     string GetBiosError();