Commit 6ee43644 authored by Konrad McClure's avatar Konrad McClure
Browse files

quick commit

parent 19e0fbe5
...@@ -61,7 +61,7 @@ void C2048GameState::HandleEvents(CGameEngine* game) ...@@ -61,7 +61,7 @@ void C2048GameState::HandleEvents(CGameEngine* game)
// break; // break;
// } // }
cin >> input; input = game->PopInput();
if (input == 'q') if (input == 'q')
{ {
......
#include "GameEngine.h" #include "GameEngine.h"
#include "GameState.h" #include "GameState.h"
#include <iostream> #include <iostream>
#include <stdio.h>
void CGameEngine::Init() void CGameEngine::Init()
{ {
...@@ -74,7 +75,7 @@ void CGameEngine::PopState() ...@@ -74,7 +75,7 @@ void CGameEngine::PopState()
} }
} }
// Primary Loop
// Send game engine to the state to handle events // Send game engine to the state to handle events
void CGameEngine::HandleEvents() void CGameEngine::HandleEvents()
{ {
...@@ -90,5 +91,19 @@ void CGameEngine::Update() ...@@ -90,5 +91,19 @@ void CGameEngine::Update()
// Send game engine to draw to the console // Send game engine to draw to the console
void CGameEngine::Draw() void CGameEngine::Draw()
{ {
system("stty cooked");
states.back()->Draw(this); states.back()->Draw(this);
system("stty raw");
}
void CGameEngine::PushInput(char input)
{
inputQueue.push(input);
}
char CGameEngine::PopInput()
{
char input = inputQueue.front();
inputQueue.pop();
return input;
} }
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define GAMEENGINE_H #define GAMEENGINE_H
#include <vector> #include <vector>
#include <queue>
using namespace std; using namespace std;
class CGameState; class CGameState;
...@@ -27,9 +28,13 @@ class CGameEngine ...@@ -27,9 +28,13 @@ class CGameEngine
bool isRunning() { return m_running; } bool isRunning() { return m_running; }
void Quit() { m_running = false; } void Quit() { m_running = false; }
void PushInput(char input);
char PopInput();
private: private:
// Gamestate Stack // Gamestate Stack
vector<CGameState*> states; vector<CGameState*> states;
queue<char> inputQueue;
// Currently running bool (false will initiate cleanup) // Currently running bool (false will initiate cleanup)
bool m_running; bool m_running;
......
#include "GameEngine.h" #include "GameEngine.h"
#include "TestState1.h" #include "TestState1.h"
#include "../Testings/Nelson's YEET/ReadInput.h"
#include <thread>
// Primary Loop to be threaded
void MainLoop(CGameEngine game);
int main() int main()
{ {
...@@ -9,14 +14,38 @@ int main() ...@@ -9,14 +14,38 @@ int main()
game.ChangeState(CTestState1::Instance()); game.ChangeState(CTestState1::Instance());
while (game.isRunning()) // while (game.isRunning())
{ // {
game.HandleEvents(); // game.HandleEvents();
game.Update(); // game.Update();
game.Draw(); // game.Draw();
} // }
thread gameloop(MainLoop, game);
gameloop.join();
game.Cleanup(); game.Cleanup();
return 0; return 0;
}
// Primary Loop to be threaded
void MainLoop(CGameEngine game)
{
while (game.isRunning())
{
game.HandleEvents();
game.Update();
game.Draw();
}
}
void MainInput(CGameEngine game)
{
ReadInput reader;
while (game.isRunning())
{
game.PushInput(reader.collectInput());
}
} }
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment