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)
// break;
// }
cin >> input;
input = game->PopInput();
if (input == 'q')
{
......
#include "GameEngine.h"
#include "GameState.h"
#include <iostream>
#include <stdio.h>
void CGameEngine::Init()
{
......@@ -74,7 +75,7 @@ void CGameEngine::PopState()
}
}
// Primary Loop
// Send game engine to the state to handle events
void CGameEngine::HandleEvents()
{
......@@ -90,5 +91,19 @@ void CGameEngine::Update()
// Send game engine to draw to the console
void CGameEngine::Draw()
{
system("stty cooked");
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 @@
#define GAMEENGINE_H
#include <vector>
#include <queue>
using namespace std;
class CGameState;
......@@ -27,9 +28,13 @@ class CGameEngine
bool isRunning() { return m_running; }
void Quit() { m_running = false; }
void PushInput(char input);
char PopInput();
private:
// Gamestate Stack
vector<CGameState*> states;
queue<char> inputQueue;
// Currently running bool (false will initiate cleanup)
bool m_running;
......
#include "GameEngine.h"
#include "TestState1.h"
#include "../Testings/Nelson's YEET/ReadInput.h"
#include <thread>
// Primary Loop to be threaded
void MainLoop(CGameEngine game);
int main()
{
......@@ -9,14 +14,38 @@ int main()
game.ChangeState(CTestState1::Instance());
while (game.isRunning())
{
game.HandleEvents();
game.Update();
game.Draw();
}
// while (game.isRunning())
// {
// game.HandleEvents();
// game.Update();
// game.Draw();
// }
thread gameloop(MainLoop, game);
gameloop.join();
game.Cleanup();
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