Skip to content

Commit f9694fe

Browse files
committed
Got input working
1 parent 3183d42 commit f9694fe

File tree

16 files changed

+88
-165
lines changed

16 files changed

+88
-165
lines changed

docs/Doxyfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ IDL_PROPERTY_SUPPORT = YES
382382
# all members of a group must be documented explicitly.
383383
# The default value is: NO.
384384

385-
DISTRIBUTE_GROUP_DOC = NO
385+
DISTRIBUTE_GROUP_DOC = YES
386386

387387
# If one adds a struct or class to a group and this option is enabled, then also
388388
# any nested class or struct is added to the same group. By default this option
@@ -2230,7 +2230,7 @@ ALLEXTERNALS = NO
22302230
# listed.
22312231
# The default value is: YES.
22322232

2233-
EXTERNAL_GROUPS = YES
2233+
EXTERNAL_GROUPS = NO
22342234

22352235
# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in
22362236
# the related pages index. If set to NO, only the current project's pages will

docs/source/api/input.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
Input
22
=====
3+
4+
.. doxygennamespace:: igneous::input
5+
:members:

igneous/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ set(INCLUDES
3232
include/igneous/core/input.hpp
3333
include/igneous/core/log.hpp
3434
include/igneous/core/version.hpp
35-
include/igneous/ecs/components/modelComponent.hpp
3635
include/igneous/ecs/components/transformationComponent.hpp
3736
include/igneous/ecs/systems/captureSystem.hpp
3837
include/igneous/ecs/systems/rendererSystem.hpp

igneous/include/igneous/core/igneous.hpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ class Application
5252
);
5353

5454
void reset(uint32_t flags = 0);
55-
uint32_t getWidth() const;
56-
uint32_t getHeight() const;
5755
void setSize(int width, int height);
5856
const char* getTitle() const;
5957
void setTitle(const char* title);
@@ -63,7 +61,7 @@ class Application
6361
virtual void render() {};
6462
virtual int shutdown() { return 0; };
6563

66-
virtual void onReset() {};
64+
virtual void onReset();
6765
virtual void onKey(int key, int scancode, int action, int mods) {}
6866
virtual void onChar(unsigned int codepoint) {}
6967
virtual void onCharMods(int codepoint, unsigned int mods) {}
@@ -75,15 +73,8 @@ class Application
7573
virtual void onWindowSize(int width, int height) {}
7674
protected:
7775
GLFWwindow* mWindow;
78-
Allocator mAllocator;
79-
bool mKeyDown[GLFW_KEY_LAST + 1] = { 0 };
80-
bool mMouseButtonDown[GLFW_MOUSE_BUTTON_LAST + 1] = { 0 };
81-
float mMouseWheelH;
82-
float mMouseWheel;
8376
private:
8477
uint32_t mReset;
85-
uint32_t mWidth;
86-
uint32_t mHeight;
8778
const char* mTitle;
8879
};
8980
} // end namespace igneous

igneous/include/igneous/core/input.hpp

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,15 @@
66
#include "igneous/console/console.hpp"
77

88
namespace igneous {
9-
#define IN_KEY_SINK(callback) Input::keySignal.sink().connect<callback>()
10-
#define IN_MOUSE_SINK(callback) Input::mouseSignal.sink().connect<callback>()
11-
#define IN_SCROLL_SINK(callback) Input::scrollSignal.sink().connect<callback>()
12-
#define IN_CURSOR_POS_SINK(callback) Input::cursorPosSignal.sink().connect<callback>()
13-
#define IN_CURSOR_ENTER_SINK(callback) Input::cursorEnterSignal.sink().connect<callback>()
14-
15-
namespace Input
9+
namespace input
1610
{
17-
void Init(GLFWwindow* window);
11+
/*! @private */
12+
void init(GLFWwindow* window);
1813

19-
void cursorVisibleCallback(float oldValue, float newValue);
20-
void onKey(int key, int scancode, int action, int mods);
21-
void onMouseButton(int button, int action, int mods);
22-
void onScroll(double xoffset, double yoffset);
23-
void onCursorPos(double xpos, double ypos);
24-
void onCursorEnter(int entered);
25-
void setCursorPos(GLFWwindow* window, double xpos, double ypos);
26-
void setCursorVisible(GLFWwindow* window, bool visible);
27-
void quitCallback(const std::string& name, const arg_list& args);
14+
/*! Sets the mouse cursor visibility
15+
* \param visible `true` for visible. `false` for hidden.
16+
*/
17+
void setCursorVisible(bool visible);
2818

2919
extern bool keys[GLFW_KEY_LAST + 1];
3020
extern bool mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1];
@@ -33,12 +23,6 @@ namespace Input
3323
extern int width;
3424
extern int height;
3525
extern GLFWwindow* window;
36-
37-
extern entt::sigh<void(int, int, int, int)> keySignal;
38-
extern entt::sigh<void(int, int, int)> mouseSignal;
39-
extern entt::sigh<void(double, double)> scrollSignal;
40-
extern entt::sigh<void(double, double)> cursorPosSignal;
41-
extern entt::sigh<void(int)> cursorEnterSignal;
4226
}
4327

4428
/*! @defgroup keys Keyboard keys
@@ -60,7 +44,6 @@ namespace Input
6044
* - For non-printable keys, custom names are used (e.g. "F4",
6145
* "BACKSPACE", etc.)
6246
*
63-
* @ingroup input
6447
* @{
6548
*/
6649

@@ -199,7 +182,6 @@ namespace Input
199182
*
200183
* See [key input](@ref input_key) for how these are used.
201184
*
202-
* @ingroup input
203185
* @{ */
204186

205187
/*! @brief If this bit is set one or more Shift keys were held down.
@@ -221,7 +203,6 @@ namespace Input
221203
*
222204
* See [mouse button input](@ref input_mouse_button) for how these are used.
223205
*
224-
* @ingroup input
225206
* @{ */
226207
#define IG_MOUSE_BUTTON_1 GLFW_MOUSE_BUTTON_1
227208
#define IG_MOUSE_BUTTON_2 GLFW_MOUSE_BUTTON_2
@@ -241,7 +222,6 @@ namespace Input
241222
*
242223
* See [joystick input](@ref joystick) for how these are used.
243224
*
244-
* @ingroup input
245225
* @{ */
246226
#define IG_JOYSTICK_1 GLFW_JOYSTICK_1
247227
#define IG_JOYSTICK_2 GLFW_JOYSTICK_2

igneous/include/igneous/ecs.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include "igneous/ecs/components/modelComponent.hpp"
43
#include "igneous/ecs/components/transformationComponent.hpp"
54
#include "igneous/ecs/systems/captureSystem.hpp"
65
#include "igneous/ecs/systems/rendererSystem.hpp"

igneous/include/igneous/gui/gui.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
namespace igneous {
77
namespace gui
88
{
9+
/*! @cond */
910
void init(GLFWwindow* window);
1011
void update(float dt);
1112
void reset(uint16_t width, uint16_t height);
1213
void render(ImDrawData* drawData);
1314
void shutdown();
15+
/*! @endcond */
1416

1517
/*! Themes to use with `setTheme(Theme theme)` */
1618
enum Theme

igneous/include/igneous/renderer/model.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ struct Mesh
1515
struct Model
1616
{
1717
std::vector<Mesh> meshes;
18+
bgfx::ProgramHandle program;
1819
};
20+
21+
typedef Model* ModelHandle;
1922
} // end namespace igneous

igneous/include/igneous/renderer/renderer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Renderer
2222
bgfx::ProgramHandle loadProgram(const char* vs, const char* fs);
2323

2424
template<typename VertexType>
25-
Model* loadModel(std::string path);
25+
Model* loadModel(std::string path, bgfx::ProgramHandle program = BGFX_INVALID_HANDLE);
2626

2727
void cleanUp();
2828

igneous/include/igneous/renderer/renderer.inl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace igneous {
1313
template<typename VertexType>
14-
Model* Renderer::loadModel(std::string path)
14+
ModelHandle Renderer::loadModel(std::string path, bgfx::ProgramHandle program)
1515
{
1616
static_assert(std::is_base_of<Vertex, VertexType>::value, "VertexType must derive from Vertex");
1717

@@ -30,7 +30,8 @@ Model* Renderer::loadModel(std::string path)
3030

3131
std::string directory = path.substr(0, path.find_last_of('/') + 1);
3232

33-
Model* model = new Model;
33+
ModelHandle model = new Model;
34+
model->program = program;
3435

3536
const auto processMesh = [&](aiMesh* mesh)
3637
{

igneous/src/console/console.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ Console::Console() : consoleVar(variable("console", 0))
2727
bind(IG_KEY_Z, "+test");
2828
bind(IG_KEY_V, "-test");
2929

30-
IN_KEY_SINK(&onKey);
31-
3230
colors[trace] = WHITE;
3331
colors[debug] = CYAN;
3432
colors[info] = GREEN;

igneous/src/core/igneous.cpp

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
namespace igneous {
2828
// Application
2929
Application::Application(const char* title, uint32_t width, uint32_t height)
30-
: mTitle(title), mWidth(width), mHeight(height)
30+
: mTitle(title), mReset(BGFX_RESET_NONE), mWindow(nullptr)
3131
{
32-
32+
input::width = width;
33+
input::height = height;
3334
}
3435

3536
// Input callbacks
@@ -41,11 +42,11 @@ void Application::keyCallback(GLFWwindow* window, int key, int scancode, int act
4142
{
4243
if (action == GLFW_PRESS)
4344
{
44-
io.KeysDown[key] = app->mKeyDown[key] = true;
45+
io.KeysDown[key] = input::keys[key] = true;
4546
}
4647
else if (action == GLFW_RELEASE)
4748
{
48-
io.KeysDown[key] = app->mKeyDown[key] = false;
49+
io.KeysDown[key] = input::keys[key] = false;
4950
}
5051
}
5152

@@ -57,6 +58,7 @@ void Application::keyCallback(GLFWwindow* window, int key, int scancode, int act
5758
if (!io.WantCaptureKeyboard)
5859
{
5960
app->onKey(key, scancode, action, mods);
61+
Console::getInstance().onKey(key, scancode, action, mods);
6062
}
6163
}
6264

@@ -94,11 +96,11 @@ void Application::mouseButtonCallback(GLFWwindow* window, int button, int action
9496
{
9597
if (action == GLFW_PRESS)
9698
{
97-
app->mMouseButtonDown[button] = true;
99+
input::mouseButtons[button] = true;
98100
}
99101
else if (action == GLFW_RELEASE)
100102
{
101-
app->mMouseButtonDown[button] = false;
103+
input::mouseButtons[button] = false;
102104
}
103105
}
104106

@@ -111,6 +113,8 @@ void Application::mouseButtonCallback(GLFWwindow* window, int button, int action
111113
void Application::cursorPosCallback(GLFWwindow* window, double xpos, double ypos)
112114
{
113115
Application* app = (Application*)glfwGetWindowUserPointer(window);
116+
input::mouseX = xpos;
117+
input::mouseY = ypos;
114118
app->onCursorPos(xpos, ypos);
115119
}
116120

@@ -126,8 +130,8 @@ void Application::scrollCallback(GLFWwindow* window, double xoffset, double yoff
126130
ImGuiIO& io = ImGui::GetIO();
127131
io.MouseWheelH += (float)xoffset;
128132
io.MouseWheel += (float)yoffset;
129-
app->mMouseWheelH += (float)xoffset;
130-
app->mMouseWheel += (float)yoffset;
133+
input::scrollX += (float)xoffset;
134+
input::scrollY += (float)yoffset;
131135
app->onScroll(xoffset, yoffset);
132136
}
133137

@@ -140,23 +144,25 @@ void Application::dropCallback(GLFWwindow* window, int count, const char** paths
140144
void Application::windowSizeCallback(GLFWwindow* window, int width, int height)
141145
{
142146
Application* app = (Application*)glfwGetWindowUserPointer(window);
143-
app->mWidth = width;
144-
app->mHeight = height;
147+
input::width = width;
148+
input::height = height;
145149
app->reset(app->mReset);
146150
app->onWindowSize(width, height);
147151
}
148152

149153
int Application::run(int argc, char** argv, bgfx::RendererType::Enum type, uint16_t vendorId, uint16_t deviceId, bgfx::CallbackI* callback, bx::AllocatorI* allocator)
150154
{
151-
// Initialize the glfw
155+
IG_CORE_INFO("Initializing Engine");
156+
IG_CORE_INFO("Initializing GLFW");
157+
// Initialize glfw
152158
if (!glfwInit())
153159
{
154160
return -1;
155161
}
156162

157163
// Create a window
158164
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
159-
mWindow = glfwCreateWindow(getWidth(), getHeight(), getTitle(), NULL, NULL);
165+
mWindow = glfwCreateWindow(input::width, input::height, mTitle, NULL, NULL);
160166
if (!mWindow)
161167
{
162168
glfwTerminate();
@@ -174,8 +180,10 @@ int Application::run(int argc, char** argv, bgfx::RendererType::Enum type, uint1
174180
glfwSetScrollCallback(mWindow, scrollCallback);
175181
glfwSetDropCallback(mWindow, dropCallback);
176182
glfwSetWindowSizeCallback(mWindow, windowSizeCallback);
183+
IG_CORE_INFO("GLFW Initializied");
177184

178185
// Setup bgfx
186+
IG_CORE_INFO("Initializing bgfx");
179187
bgfx::PlatformData platformData;
180188
memset(&platformData, 0, sizeof(platformData));
181189
#if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
@@ -196,8 +204,8 @@ int Application::run(int argc, char** argv, bgfx::RendererType::Enum type, uint1
196204
init.callback = callback;
197205
init.allocator = allocator;
198206
bgfx::init(init);
207+
IG_CORE_INFO("bgfx Initializied");
199208

200-
IG_CORE_INFO("Initializing Engine");
201209
IG_CORE_INFO("Setting window title and icon");
202210
GLFWimage images[4];
203211
images[0].pixels = stbi_load("res/icons/icon16.png", &images[0].width, &images[0].height, 0, 4);
@@ -212,11 +220,13 @@ int Application::run(int argc, char** argv, bgfx::RendererType::Enum type, uint1
212220
IG_CORE_INFO("Window title and icon set");
213221

214222
IG_CORE_INFO("Initializing Services");
223+
reset();
215224
Renderer* renderer = &Renderer::getInstance();
216225
Audio* audio = &Audio::getInstance();
217226
RendererSystem::init();
218227
gui::init(mWindow);
219228
Console* console = &Console::getInstance();
229+
input::Init(mWindow);
220230
console->runFile("startup.cmd");
221231
IG_CORE_INFO("Services Initialized");
222232

@@ -249,7 +259,7 @@ int Application::run(int argc, char** argv, bgfx::RendererType::Enum type, uint1
249259
}
250260
IG_CORE_INFO("OpenAL Extensions: {}", audio->getExtensions());
251261

252-
Input::setCursorVisible(mWindow, false);
262+
input::setCursorVisible(false);
253263

254264
IG_CONSOLE_INFO("Engine Initialized");
255265

@@ -275,6 +285,7 @@ int Application::run(int argc, char** argv, bgfx::RendererType::Enum type, uint1
275285
ImGui::NewFrame();
276286
bgfx::touch(0);
277287
render();
288+
console->render();
278289
ImGui::Render();
279290
bgfx::frame();
280291
}
@@ -290,7 +301,7 @@ int Application::run(int argc, char** argv, bgfx::RendererType::Enum type, uint1
290301
renderer->cleanUp();
291302
IG_CORE_INFO("Services Shut Down");
292303
bgfx::shutdown();
293-
Input::setCursorVisible(mWindow, true);
304+
input::setCursorVisible(true);
294305
glfwTerminate();
295306
IG_CORE_INFO("Engine Shut Down");
296307
return ret;
@@ -299,19 +310,15 @@ int Application::run(int argc, char** argv, bgfx::RendererType::Enum type, uint1
299310
void Application::reset(uint32_t flags)
300311
{
301312
mReset = flags;
302-
bgfx::reset(mWidth, mHeight, mReset);
303-
gui::reset(uint16_t(getWidth()), uint16_t(getHeight()));
313+
bgfx::reset(input::width, input::height, mReset);
314+
gui::reset(uint16_t(input::width), uint16_t(input::height));
304315
onReset();
305316
}
306317

307-
uint32_t Application::getWidth() const
308-
{
309-
return mWidth;
310-
}
311-
312-
uint32_t Application::getHeight() const
318+
void Application::onReset()
313319
{
314-
return mHeight;
320+
bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x000000ff, 1.0f, 0);
321+
bgfx::setViewRect(0, 0, 0, uint16_t(input::width), uint16_t(input::height));
315322
}
316323

317324
void Application::setSize(int width, int height)

0 commit comments

Comments
 (0)