Added keyboard and mouse input
This commit is contained in:
parent
95426b9205
commit
a21c24040d
@ -1,11 +1,12 @@
|
||||
#include "MainState.h"
|
||||
|
||||
void MainState::onEnter(Application* app) {
|
||||
Log("MainState update!");
|
||||
Log("MainState onEnter!");
|
||||
m_app = app;
|
||||
}
|
||||
|
||||
void MainState::onExit() {
|
||||
Log("MainState update!");
|
||||
Log("MainState onExit!");
|
||||
}
|
||||
|
||||
void MainState::update() {
|
||||
|
@ -9,5 +9,5 @@ public:
|
||||
void update() override;
|
||||
void render() override;
|
||||
private:
|
||||
|
||||
Application* m_app;
|
||||
};
|
@ -200,6 +200,7 @@
|
||||
<ClInclude Include="src\include\Config.h" />
|
||||
<ClInclude Include="src\include\IGamestate.h" />
|
||||
<ClInclude Include="src\include\IntroGamestate.h" />
|
||||
<ClInclude Include="src\include\Input.h" />
|
||||
<ClInclude Include="src\include\NothinFancy.h" />
|
||||
<ClInclude Include="src\include\Utility.h" />
|
||||
</ItemGroup>
|
||||
|
@ -44,6 +44,9 @@
|
||||
<ClInclude Include="src\include\IntroGamestate.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\Input.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Natvis Include="src\NatvisFile.natvis" />
|
||||
|
@ -103,6 +103,15 @@ namespace nf {
|
||||
return m_FPS;
|
||||
}
|
||||
|
||||
bool Application::isInput(unsigned int code) {
|
||||
if (code < 164) {
|
||||
return m_input[code];
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Application::addIntroState() {
|
||||
m_sIntro = new IntroGamestate;
|
||||
m_sIntro->onEnter(this);
|
||||
@ -191,11 +200,47 @@ namespace nf {
|
||||
app->toggleFullscreen();
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
return 0;
|
||||
}
|
||||
case WM_MENUCHAR: {
|
||||
return MNC_CLOSE << 16;
|
||||
}
|
||||
case WM_LBUTTONDOWN: {
|
||||
app->m_input[1] = true;
|
||||
return 0;
|
||||
}
|
||||
case WM_LBUTTONUP: {
|
||||
app->m_input[1] = false;
|
||||
return 0;
|
||||
}
|
||||
case WM_RBUTTONDOWN: {
|
||||
app->m_input[2] = true;
|
||||
return 0;
|
||||
}
|
||||
case WM_RBUTTONUP: {
|
||||
app->m_input[2] = false;
|
||||
return 0;
|
||||
}
|
||||
case WM_MBUTTONDOWN: {
|
||||
app->m_input[4] = true;
|
||||
return 0;
|
||||
}
|
||||
case WM_MBUTTONUP: {
|
||||
app->m_input[4] = false;
|
||||
return 0;
|
||||
}
|
||||
case WM_KEYDOWN: {
|
||||
if (wParam < 164 && !(lParam & (1 << 30))) {
|
||||
app->m_input[wParam] = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_KEYUP: {
|
||||
if (wParam < 164) {
|
||||
app->m_input[wParam] = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_CLOSE: {
|
||||
DestroyWindow(hWnd);
|
||||
return 0;
|
||||
@ -245,6 +290,7 @@ namespace nf {
|
||||
wglDeleteContext(m_hglrc);
|
||||
m_hglrc = wglCreateContextAttribsARB(m_hdc, NULL, attrib);
|
||||
wglMakeCurrent(m_hdc, m_hglrc);
|
||||
wglSwapIntervalEXT(0);
|
||||
Log("OpenGL version: " + std::string((char*)glGetString(GL_VERSION)));
|
||||
GLuint vao;
|
||||
glGenVertexArrays(1, &vao);
|
||||
|
@ -1,8 +1,9 @@
|
||||
//TODO: Debug logger
|
||||
//TODO: File IO functions
|
||||
#include <Windows.h>
|
||||
|
||||
#include "Utility.h"
|
||||
#include "Config.h"
|
||||
#include <Windows.h>
|
||||
|
||||
namespace nf {
|
||||
#ifdef _DEBUG
|
||||
|
@ -1,12 +1,13 @@
|
||||
#pragma once
|
||||
#include "Config.h"
|
||||
#include "Utility.h"
|
||||
#include "IntroGamestate.h"
|
||||
#include <Windows.h>
|
||||
#include <chrono>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "Config.h"
|
||||
#include "Utility.h"
|
||||
#include "IntroGamestate.h"
|
||||
|
||||
namespace nf {
|
||||
class Application {
|
||||
public:
|
||||
@ -23,6 +24,7 @@ namespace nf {
|
||||
void showWindow(bool show);
|
||||
const Config& getConfig() const;
|
||||
int getFPS() const;
|
||||
bool isInput(unsigned int code);
|
||||
|
||||
~Application();
|
||||
private:
|
||||
@ -63,5 +65,8 @@ namespace nf {
|
||||
IGamestate* m_DefaultState;
|
||||
bool m_defaultStateAdded = false;
|
||||
IGamestate* m_currentState;
|
||||
|
||||
//Array of booleans that represent keyboard and mouse input minus the scrollwheel
|
||||
bool m_input[164];
|
||||
};
|
||||
}
|
63
NothinFancy/src/include/Input.h
Normal file
63
NothinFancy/src/include/Input.h
Normal file
@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#define NFI_LEFTMOUSE 1
|
||||
#define NFI_RIGHTMOUSE 2
|
||||
#define NFI_MIDLEMOUSE 4
|
||||
#define NFI_TAB 9
|
||||
#define NFI_ENTER 13
|
||||
#define NFI_SHIFT 16
|
||||
#define NFI_CONTROL 17
|
||||
#define NFI_ESCAPE 27
|
||||
#define NFI_SPACE 32
|
||||
#define NFI_LEFT 37
|
||||
#define NFI_UP 38
|
||||
#define NFI_RIGHT 39
|
||||
#define NFI_DOWN 40
|
||||
#define NFI_0 48
|
||||
#define NFI_1 49
|
||||
#define NFI_2 50
|
||||
#define NFI_3 51
|
||||
#define NFI_4 52
|
||||
#define NFI_5 53
|
||||
#define NFI_6 54
|
||||
#define NFI_7 55
|
||||
#define NFI_8 56
|
||||
#define NFI_9 57
|
||||
#define NFI_A 65
|
||||
#define NFI_B 66
|
||||
#define NFI_C 67
|
||||
#define NFI_D 68
|
||||
#define NFI_E 69
|
||||
#define NFI_F 70
|
||||
#define NFI_G 71
|
||||
#define NFI_H 72
|
||||
#define NFI_I 73
|
||||
#define NFI_J 74
|
||||
#define NFI_K 75
|
||||
#define NFI_L 76
|
||||
#define NFI_M 77
|
||||
#define NFI_N 78
|
||||
#define NFI_O 79
|
||||
#define NFI_P 80
|
||||
#define NFI_Q 81
|
||||
#define NFI_R 82
|
||||
#define NFI_S 83
|
||||
#define NFI_T 84
|
||||
#define NFI_U 85
|
||||
#define NFI_V 86
|
||||
#define NFI_W 87
|
||||
#define NFI_X 88
|
||||
#define NFI_Y 89
|
||||
#define NFI_Z 90
|
||||
#define NFI_F1 112
|
||||
#define NFI_F2 113
|
||||
#define NFI_F3 114
|
||||
#define NFI_F4 115
|
||||
#define NFI_F5 116
|
||||
#define NFI_F6 117
|
||||
#define NFI_F7 118
|
||||
#define NFI_F8 119
|
||||
#define NFI_F9 120
|
||||
#define NFI_F10 121
|
||||
#define NFI_F11 122
|
||||
#define NFI_F12 123
|
@ -1,5 +1,6 @@
|
||||
//Master engine include (Is this even useful?)
|
||||
|
||||
#include "Application.h"
|
||||
#include "Input.h"
|
||||
|
||||
using namespace nf;
|
@ -6,13 +6,19 @@
|
||||
|
||||
namespace nf {
|
||||
#ifdef _DEBUG
|
||||
//Strips __FILE__ down to only the name of the file
|
||||
#define __FILENAME__ strrchr(__FILE__, '\\') + 1
|
||||
//Initializes static variables needed for debugging
|
||||
#define DEBUGINIT std::chrono::steady_clock::time_point Debug::m_initTime = std::chrono::high_resolution_clock::now();
|
||||
//Sleep for an amount of seconds
|
||||
#define SleepS(x) std::this_thread::sleep_for(std::chrono::seconds(x))
|
||||
//Sleep for an amount of milliseconds
|
||||
#define SleepMS(x) std::this_thread::sleep_for(std::chrono::milliseconds(x))
|
||||
//Prints a nicely-formatted message complete with a timestamp
|
||||
#define Log(x) nf::Debug::LogImp(x)
|
||||
//Prints error message and breaks the debugger
|
||||
#define Error(x) nf::Debug::ErrorImp(x,__FILENAME__, __LINE__);\
|
||||
DebugBreak();
|
||||
__debugbreak();
|
||||
|
||||
class Debug {
|
||||
private:
|
||||
|
Reference in New Issue
Block a user