Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
1
142GameCenter
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nelson Phillips
142GameCenter
Commits
6ee43644
Commit
6ee43644
authored
Mar 04, 2019
by
Konrad McClure
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
quick commit
parent
19e0fbe5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
8 deletions
+57
-8
GameEngine/2048GameState.cpp
GameEngine/2048GameState.cpp
+1
-1
GameEngine/GameEngine.cpp
GameEngine/GameEngine.cpp
+16
-1
GameEngine/GameEngine.h
GameEngine/GameEngine.h
+5
-0
GameEngine/enginetest.cpp
GameEngine/enginetest.cpp
+35
-6
No files found.
GameEngine/2048GameState.cpp
View file @
6ee43644
...
...
@@ -61,7 +61,7 @@ void C2048GameState::HandleEvents(CGameEngine* game)
// break;
// }
cin
>>
input
;
input
=
game
->
PopInput
()
;
if
(
input
==
'q'
)
{
...
...
GameEngine/GameEngine.cpp
View file @
6ee43644
#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
GameEngine/GameEngine.h
View file @
6ee43644
...
...
@@ -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
;
...
...
GameEngine/enginetest.cpp
View file @
6ee43644
#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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment