From ff5e33a6001afdca490ad0e9224b7942e2f675cb Mon Sep 17 00:00:00 2001 From: Ange Yaghi Date: Wed, 24 Jun 2020 22:27:35 -0400 Subject: [PATCH] [#17] : Added feature to confine cursor to window --- engines/basic/include/delta_engine.h | 12 +- engines/basic/src/delta_engine.cpp | 18 +- include/yds_d3d10_shader_program.h | 11 +- include/yds_d3d11_shader_program.h | 11 +- include/yds_mouse.h | 32 +- include/yds_opengl_context.h | 148 ++++----- include/yds_opengl_shader_program.h | 11 +- include/yds_rendering_context.h | 8 +- include/yds_shader.h | 33 +- include/yds_shader_program.h | 13 +- include/yds_window.h | 3 + include/yds_window_event_handler.h | 16 +- include/yds_window_system.h | 12 + include/yds_window_system_object.h | 6 +- include/yds_windows_window_system.h | 8 + physics/src/collision_primitives.cpp | 8 + project/delta-core/delta-core.vcxproj.filters | 306 ++++++++++-------- src/yds_d3d10_context.cpp | 4 +- src/yds_d3d10_device.cpp | 25 +- src/yds_d3d10_shader_program.cpp | 4 +- src/yds_d3d11_context.cpp | 2 +- src/yds_d3d11_device.cpp | 24 +- src/yds_d3d11_shader_program.cpp | 4 +- src/yds_device.cpp | 4 +- src/yds_ds8_system.cpp | 2 +- src/yds_input_device.cpp | 2 +- src/yds_input_system.cpp | 8 +- src/yds_monitor.cpp | 2 +- src/yds_mouse.cpp | 14 +- src/yds_opengl_context.cpp | 2 +- src/yds_opengl_device.cpp | 8 +- src/yds_opengl_shader_program.cpp | 4 +- src/yds_opengl_windows_context.cpp | 21 +- src/yds_rendering_context.cpp | 6 +- src/yds_shader.cpp | 4 +- src/yds_shader_program.cpp | 4 +- src/yds_window.cpp | 4 +- src/yds_window_event_handler.cpp | 2 +- src/yds_window_system.cpp | 18 +- src/yds_window_system_object.cpp | 2 +- src/yds_windows_audio_wave_file.cpp | 2 +- src/yds_windows_input_device.cpp | 4 +- src/yds_windows_input_system.cpp | 34 +- src/yds_windows_monitor.cpp | 2 +- src/yds_windows_window.cpp | 4 +- src/yds_windows_window_system.cpp | 47 ++- 46 files changed, 506 insertions(+), 413 deletions(-) diff --git a/engines/basic/include/delta_engine.h b/engines/basic/include/delta_engine.h index 1785d7e8..a6793435 100644 --- a/engines/basic/include/delta_engine.h +++ b/engines/basic/include/delta_engine.h @@ -107,10 +107,16 @@ namespace dbasic { bool IsKeyDown(ysKeyboard::KEY_CODE key); bool ProcessKeyDown(ysKeyboard::KEY_CODE key); - bool IsMouseKeyDown(ysMouse::BUTTON_CODE key); + bool IsMouseKeyDown(ysMouse::Button key); int GetMouseWheel(); void GetMousePos(int *x, int *y); + void SetCursorPositionLock(bool lock) { m_cursorPositionLocked = lock; } + bool GetCursorPositionLock() { return m_cursorPositionLocked; } + + void SetCursorHidden(bool hidden) { m_cursorHidden = hidden; } + bool GetCursorHidden() const { return m_cursorHidden; } + float GetFrameLength(); float GetAverageFramerate(); @@ -221,6 +227,10 @@ namespace dbasic { // Settings float m_clearColor[4]; + // Cursor + bool m_cursorPositionLocked; + bool m_cursorHidden; + protected: // Initialization Routines ysError InitializeGeometry(); diff --git a/engines/basic/src/delta_engine.cpp b/engines/basic/src/delta_engine.cpp index d9cf0357..5344fd3e 100644 --- a/engines/basic/src/delta_engine.cpp +++ b/engines/basic/src/delta_engine.cpp @@ -97,14 +97,14 @@ ysError dbasic::DeltaEngine::CreateGameWindow(const char *title, void *instance, YDS_ERROR_DECLARE("CreateGameWindow"); // Create the window system - YDS_NESTED_ERROR_CALL(ysWindowSystem::CreateWindowSystem(&m_windowSystem, ysWindowSystemObject::Platform::WINDOWS)); + YDS_NESTED_ERROR_CALL(ysWindowSystem::CreateWindowSystem(&m_windowSystem, ysWindowSystemObject::Platform::Windows)); m_windowSystem->ConnectInstance(instance); // Find the monitor setup m_windowSystem->SurveyMonitors(); ysMonitor *mainMonitor = m_windowSystem->GetMonitor(0); - YDS_NESTED_ERROR_CALL(ysInputSystem::CreateInputSystem(&m_inputSystem, ysWindowSystemObject::Platform::WINDOWS)); + YDS_NESTED_ERROR_CALL(ysInputSystem::CreateInputSystem(&m_inputSystem, ysWindowSystemObject::Platform::Windows)); m_windowSystem->AssignInputSystem(m_inputSystem); m_inputSystem->CreateDevices(false); @@ -168,6 +168,18 @@ ysError dbasic::DeltaEngine::StartFrame() { if (IsKeyDown(ysKeyboard::KEY_B)) m_device->SetDebugFlag(0, true); else m_device->SetDebugFlag(0, false); + if (m_gameWindow->IsActive()) { + m_windowSystem->SetCursorVisible(!m_cursorHidden); + if (m_cursorPositionLocked) { + m_windowSystem->ReleaseCursor(); + m_windowSystem->ConfineCursor(m_gameWindow); + } + } + else { + m_windowSystem->SetCursorVisible(true); + m_windowSystem->ReleaseCursor(); + } + if (IsOpen()) { m_device->SetRenderTarget(m_mainRenderTarget); m_device->ClearBuffers(m_clearColor); @@ -515,7 +527,7 @@ bool dbasic::DeltaEngine::ProcessKeyDown(ysKeyboard::KEY_CODE key) { return false; } -bool dbasic::DeltaEngine::IsMouseKeyDown(ysMouse::BUTTON_CODE key) { +bool dbasic::DeltaEngine::IsMouseKeyDown(ysMouse::Button key) { if (m_mainMouse != nullptr) { ysMouse *mouse = m_mainMouse->GetAsMouse(); return mouse->GetButton(key)->IsDown(); diff --git a/include/yds_d3d10_shader_program.h b/include/yds_d3d10_shader_program.h index 10cbe05d..8b12c3de 100644 --- a/include/yds_d3d10_shader_program.h +++ b/include/yds_d3d10_shader_program.h @@ -4,20 +4,15 @@ #include "yds_shader_program.h" class ysD3D10Shader; -class ysD3D10ShaderProgram : public ysShaderProgram -{ - +class ysD3D10ShaderProgram : public ysShaderProgram { friend class ysD3D10Device; public: - ysD3D10ShaderProgram(); virtual ~ysD3D10ShaderProgram(); protected: - - ysD3D10Shader *GetShader(ysShader::SHADER_TYPE type); - + ysD3D10Shader *GetShader(ysShader::ShaderType type); }; -#endif \ No newline at end of file +#endif /* YDS_D3D10_SHADER_PROGRAM_H */ diff --git a/include/yds_d3d11_shader_program.h b/include/yds_d3d11_shader_program.h index d5082729..a1109daa 100644 --- a/include/yds_d3d11_shader_program.h +++ b/include/yds_d3d11_shader_program.h @@ -4,20 +4,15 @@ #include "yds_shader_program.h" class ysD3D11Shader; -class ysD3D11ShaderProgram : public ysShaderProgram -{ - +class ysD3D11ShaderProgram : public ysShaderProgram { friend class ysD3D11Device; public: - ysD3D11ShaderProgram(); ~ysD3D11ShaderProgram(); protected: - - ysD3D11Shader *GetShader(ysShader::SHADER_TYPE type); - + ysD3D11Shader *GetShader(ysShader::ShaderType type); }; -#endif \ No newline at end of file +#endif /* YDS_D3D11_SHADER_PROGRAM_H */ diff --git a/include/yds_mouse.h b/include/yds_mouse.h index de4bfa03..c8bc29a4 100644 --- a/include/yds_mouse.h +++ b/include/yds_mouse.h @@ -5,18 +5,18 @@ class ysMouse { public: - enum BUTTON_CODE { - BUTTON_LEFT, - BUTTON_RIGHT, - BUTTON_MIDDLE, - - BUTTON_1, - BUTTON_2, - BUTTON_3, - BUTTON_4, - BUTTON_5, - - BUTTON_COUNT + enum class Button { + Left, + Right, + Middle, + + Aux_1, + Aux_2, + Aux_3, + Aux_4, + Aux_5, + + Count }; public: @@ -26,14 +26,14 @@ class ysMouse { void Reset(); void UpdatePosition(int x, int y, bool delta = true); void UpdateWheel(int dwheel); - void UpdateButton(BUTTON_CODE button, ysKey::KEY_STATE state); + void UpdateButton(Button button, ysKey::KEY_STATE state); int GetX() const { return m_x; } int GetY() const { return m_y; } int GetWheel() const { return m_wheel; } - const ysKey *GetButton(BUTTON_CODE button) const { return &m_buttons[button]; } + const ysKey *GetButton(Button button) const { return &m_buttons[(int)button]; } - bool ProcessMouseButton(BUTTON_CODE button, ysKey::KEY_STATE state); + bool ProcessMouseButton(Button button, ysKey::KEY_STATE state); protected: int m_x; @@ -41,7 +41,7 @@ class ysMouse { int m_wheel; protected: - ysKey m_buttons[BUTTON_COUNT]; + ysKey m_buttons[(int)Button::Count]; }; #endif /* YDS_MOUSE_H */ diff --git a/include/yds_opengl_context.h b/include/yds_opengl_context.h index 429f3c77..ff433eba 100644 --- a/include/yds_opengl_context.h +++ b/include/yds_opengl_context.h @@ -38,90 +38,90 @@ class ysOpenGLVirtualContext : public ysRenderingContext { } // OpenGL Extensions - PFNGLGENBUFFERSPROC glGenBuffers; - PFNGLDELETEBUFFERSPROC glDeleteBuffers; - PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; - PFNGLBINDBUFFERPROC glBindBuffer; - PFNGLBINDBUFFERRANGEPROC glBindBufferRange; - PFNGLBUFFERDATAPROC glBufferData; - PFNGLGENVERTEXARRAYSPROC glGenVertexArrays; - PFNGLBINDVERTEXARRAYPROC glBindVertexArray; - PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray; - PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer; - PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer; - - PFNGLVERTEXATTRIB3FPROC glVertexAttrib3f; - PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f; - - PFNGLDELETEPROGRAMPROC glDeleteProgram; - PFNGLDELETESHADERPROC glDeleteShader; - - PFNGLCREATESHADERPROC glCreateShader; - PFNGLSHADERSOURCEPROC glShaderSource; - PFNGLCOMPILESHADERPROC glCompileShader; - PFNGLCREATEPROGRAMPROC glCreateProgram; - PFNGLATTACHSHADERPROC glAttachShader; - PFNGLDETACHSHADERPROC glDetachShader; - PFNGLLINKPROGRAMPROC glLinkProgram; - PFNGLUSEPROGRAMPROC glUseProgram; - PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation; - PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation; - PFNGLGETFRAGDATALOCATIONPROC glGetFragDataLocation; - PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; - PFNGLGETSHADERIVPROC glGetShaderiv; - PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; - PFNGLDRAWBUFFERSPROC glDrawBuffers; - - PFNGLUNIFORM4FPROC glUniform4f; - PFNGLUNIFORM4FVPROC glUniform4fv; - PFNGLUNIFORM3FVPROC glUniform3fv; - PFNGLUNIFORM2FVPROC glUniform2fv; - PFNGLUNIFORM3FPROC glUniform3f; - PFNGLUNIFORM2FPROC glUniform2f; - PFNGLUNIFORM1FPROC glUniform1f; - PFNGLUNIFORM1IPROC glUniform1i; - - PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv; - PFNGLUNIFORMMATRIX3FVPROC glUniformMatrix3fv; - - PFNGLMAPBUFFERPROC glMapBuffer; - PFNGLMAPBUFFERRANGEPROC glMapBufferRange; - PFNGLUNMAPBUFFERPROC glUnmapBuffer; - - PFNGLGETPROGRAMIVPROC glGetProgramiv; - PFNGLGETACTIVEUNIFORMNAMEPROC glGetActiveUniformName; - PFNGLGETACTIVEUNIFORMSIVPROC glGetActiveUniformsiv; - PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform; - - PFNGLDRAWELEMENTSBASEVERTEXPROC glDrawElementsBaseVertex; + PFNGLGENBUFFERSPROC glGenBuffers = nullptr; + PFNGLDELETEBUFFERSPROC glDeleteBuffers = nullptr; + PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays = nullptr; + PFNGLBINDBUFFERPROC glBindBuffer = nullptr; + PFNGLBINDBUFFERRANGEPROC glBindBufferRange = nullptr; + PFNGLBUFFERDATAPROC glBufferData = nullptr; + PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = nullptr; + PFNGLBINDVERTEXARRAYPROC glBindVertexArray = nullptr; + PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray = nullptr; + PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer = nullptr; + PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer = nullptr; + + PFNGLVERTEXATTRIB3FPROC glVertexAttrib3f = nullptr; + PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f = nullptr; + + PFNGLDELETEPROGRAMPROC glDeleteProgram = nullptr; + PFNGLDELETESHADERPROC glDeleteShader = nullptr; + + PFNGLCREATESHADERPROC glCreateShader = nullptr; + PFNGLSHADERSOURCEPROC glShaderSource = nullptr; + PFNGLCOMPILESHADERPROC glCompileShader = nullptr; + PFNGLCREATEPROGRAMPROC glCreateProgram = nullptr; + PFNGLATTACHSHADERPROC glAttachShader = nullptr; + PFNGLDETACHSHADERPROC glDetachShader = nullptr; + PFNGLLINKPROGRAMPROC glLinkProgram = nullptr; + PFNGLUSEPROGRAMPROC glUseProgram = nullptr; + PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation = nullptr; + PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation = nullptr; + PFNGLGETFRAGDATALOCATIONPROC glGetFragDataLocation = nullptr; + PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = nullptr; + PFNGLGETSHADERIVPROC glGetShaderiv = nullptr; + PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog = nullptr; + PFNGLDRAWBUFFERSPROC glDrawBuffers = nullptr; + + PFNGLUNIFORM4FPROC glUniform4f = nullptr; + PFNGLUNIFORM4FVPROC glUniform4fv = nullptr; + PFNGLUNIFORM3FVPROC glUniform3fv = nullptr; + PFNGLUNIFORM2FVPROC glUniform2fv = nullptr; + PFNGLUNIFORM3FPROC glUniform3f = nullptr; + PFNGLUNIFORM2FPROC glUniform2f = nullptr; + PFNGLUNIFORM1FPROC glUniform1f = nullptr; + PFNGLUNIFORM1IPROC glUniform1i = nullptr; + + PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv = nullptr; + PFNGLUNIFORMMATRIX3FVPROC glUniformMatrix3fv = nullptr; + + PFNGLMAPBUFFERPROC glMapBuffer = nullptr; + PFNGLMAPBUFFERRANGEPROC glMapBufferRange = nullptr; + PFNGLUNMAPBUFFERPROC glUnmapBuffer = nullptr; + + PFNGLGETPROGRAMIVPROC glGetProgramiv = nullptr; + PFNGLGETACTIVEUNIFORMNAMEPROC glGetActiveUniformName = nullptr; + PFNGLGETACTIVEUNIFORMSIVPROC glGetActiveUniformsiv = nullptr; + PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform = nullptr; + + PFNGLDRAWELEMENTSBASEVERTEXPROC glDrawElementsBaseVertex = nullptr; // Textures - PFNGLACTIVETEXTUREPROC glActiveTexture; - PFNGLGENERATEMIPMAPPROC glGenerateMipmap; + PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr; + PFNGLGENERATEMIPMAPPROC glGenerateMipmap = nullptr; // Buffers - PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers; - PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer; - PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage; + PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers = nullptr; + PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer = nullptr; + PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage = nullptr; - PFNGLCOPYBUFFERSUBDATAPROC glCopyBufferSubData; - PFNGLBUFFERSUBDATAPROC glBufferSubData; + PFNGLCOPYBUFFERSUBDATAPROC glCopyBufferSubData = nullptr; + PFNGLBUFFERSUBDATAPROC glBufferSubData = nullptr; - PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; - PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers; - PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; - PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; - PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer; - PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; + PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers = nullptr; + PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers = nullptr; + PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer = nullptr; + PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = nullptr; + PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer = nullptr; + PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus = nullptr; - PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer; - PFNGLBLENDEQUATIONPROC glBlendEquation; + PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer = nullptr; + PFNGLBLENDEQUATIONPROC glBlendEquation = nullptr; - PFNWGLMAKECONTEXTCURRENTARBPROC wglMakeContextCurrent; - PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB; - PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB; + PFNWGLMAKECONTEXTCURRENTARBPROC wglMakeContextCurrent = nullptr; + PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = nullptr; + PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = nullptr; bool IsRealContext() { return m_isRealContext; } diff --git a/include/yds_opengl_shader_program.h b/include/yds_opengl_shader_program.h index 452649d8..66f378e9 100644 --- a/include/yds_opengl_shader_program.h +++ b/include/yds_opengl_shader_program.h @@ -4,22 +4,17 @@ #include "yds_shader_program.h" class ysOpenGLShader; -class ysOpenGLShaderProgram : public ysShaderProgram -{ - +class ysOpenGLShaderProgram : public ysShaderProgram { friend class ysOpenGLDevice; public: - ysOpenGLShaderProgram(); ~ysOpenGLShaderProgram(); protected: - - ysOpenGLShader *GetShader(ysShader::SHADER_TYPE type); + ysOpenGLShader *GetShader(ysShader::ShaderType type); unsigned int m_handle; - }; -#endif \ No newline at end of file +#endif /* YDS_OPENGL_SHADER_PROGRAM_H */ diff --git a/include/yds_rendering_context.h b/include/yds_rendering_context.h index 1521c997..15db558f 100644 --- a/include/yds_rendering_context.h +++ b/include/yds_rendering_context.h @@ -13,10 +13,10 @@ class ysRenderingContext : public ysContextObject { friend ysDevice; public: - enum ContextMode { - WINDOWED, - FULLSCREEN, - UNDEFINED + enum class ContextMode { + Windowed, + Fullscreen, + Undefined }; public: diff --git a/include/yds_shader.h b/include/yds_shader.h index 4cf9d4e9..58a6d95d 100644 --- a/include/yds_shader.h +++ b/include/yds_shader.h @@ -3,28 +3,21 @@ #include "yds_context_object.h" -class ysShader : public ysContextObject -{ - +class ysShader : public ysContextObject { friend class ysDevice; public: + static const int MaxShaderFilenameLength = 256; + static const int MaxShaderNameLength = 64; - static const int MAX_SHADER_FILENAME_LENGTH = 256; - static const int MAX_SHADER_NAME = 64; - - enum SHADER_TYPE - { - - SHADER_TYPE_PIXEL, - SHADER_TYPE_VERTEX, - - SHADER_TYPE_NUM_TYPES + enum class ShaderType { + Pixel, + Vertex, + NumShaderTypes }; public: - ysShader(); ysShader(DEVICE_API API); virtual ~ysShader(); @@ -32,15 +25,13 @@ class ysShader : public ysContextObject const char *GetFilename() const { return m_filename; } const char *GetShaderName() const { return m_shaderName; } - SHADER_TYPE GetShaderType() const { return m_shaderType; } + ShaderType GetShaderType() const { return m_shaderType; } protected: + char m_filename[MaxShaderFilenameLength]; + char m_shaderName[MaxShaderNameLength]; - char m_filename[MAX_SHADER_FILENAME_LENGTH]; - char m_shaderName[MAX_SHADER_NAME]; - - SHADER_TYPE m_shaderType; - + ShaderType m_shaderType; }; -#endif \ No newline at end of file +#endif /* YDS_SHADER_H */ diff --git a/include/yds_shader_program.h b/include/yds_shader_program.h index 7f2f7b7d..b2451f5e 100644 --- a/include/yds_shader_program.h +++ b/include/yds_shader_program.h @@ -4,24 +4,19 @@ #include "yds_context_object.h" #include "yds_shader.h" -class ysShaderProgram : public ysContextObject -{ - +class ysShaderProgram : public ysContextObject { friend class ysDevice; public: - ysShaderProgram(); ysShaderProgram(DEVICE_API API); virtual ~ysShaderProgram(); - const ysShader *GetShader(ysShader::SHADER_TYPE type) const { return m_shaderSlots[type]; } + const ysShader *GetShader(ysShader::ShaderType type) const { return m_shaderSlots[(int)type]; } protected: - - ysShader *m_shaderSlots[ysShader::SHADER_TYPE_NUM_TYPES]; + ysShader *m_shaderSlots[(int)ysShader::ShaderType::NumShaderTypes]; bool m_isLinked; - }; -#endif \ No newline at end of file +#endif /* YDS_SHADER_PROGRAM_H */ diff --git a/include/yds_window.h b/include/yds_window.h index 58bc1777..f65d06e9 100644 --- a/include/yds_window.h +++ b/include/yds_window.h @@ -48,6 +48,9 @@ class ysWindow : public ysWindowSystemObject { WindowStyle GetStyle() const { return m_windowStyle; } ysMonitor *GetMonitor() const { return m_monitor; } + int GetPositionX() const { return m_locationx; } + int GetPositionY() const { return m_locationy; } + bool IsOpen(); virtual bool IsActive(); virtual bool IsVisible(); diff --git a/include/yds_window_event_handler.h b/include/yds_window_event_handler.h index 0a4442f4..cd1dd5ea 100644 --- a/include/yds_window_event_handler.h +++ b/include/yds_window_event_handler.h @@ -4,31 +4,25 @@ #include "yds_base.h" // Window Event Handler -class ysWindowEventHandler : public ysObject -{ - +class ysWindowEventHandler : public ysObject { friend class ysWindow; public: - ysWindowEventHandler(); virtual ~ysWindowEventHandler(); virtual void OnMoveWindow(int x, int y) { (void)x; (void)y; } virtual void OnResizeWindow(int w, int h) { (void)w; (void)h; } - virtual void OnActivate() {} - virtual void OnDeactivate() {} - virtual void OnCloseWindow() {} + virtual void OnActivate() { /* void */ } + virtual void OnDeactivate() { /* void */ } + virtual void OnCloseWindow() { /* void */ } virtual void OnKeyDown(int key) { (void)key; } protected: - inline ysWindow *GetWindow() { return m_window; } private: - ysWindow *m_window; - }; -#endif \ No newline at end of file +#endif /* YDS_WINDOW_EVENT_HANDLER_H */ diff --git a/include/yds_window_system.h b/include/yds_window_system.h index fc114c74..ea6c9450 100644 --- a/include/yds_window_system.h +++ b/include/yds_window_system.h @@ -27,6 +27,15 @@ class ysWindowSystem : public ysWindowSystemObject { void CloseWindow(ysWindow *window); void DeleteWindow(ysWindow *window); + virtual void SetCursorPosition(int x, int y) { /* void */ } + + virtual void ConfineCursor(ysWindow *window) { m_cursorConfined = true; } + virtual void ReleaseCursor() { m_cursorConfined = false; } + bool IsCursorConfined() const { return m_cursorConfined; } + + virtual void SetCursorVisible(bool visible) { m_cursorVisible = visible; } + bool IsMouseVisible() const { return m_cursorVisible; }; + // Monitor Interface virtual ysMonitor *NewMonitor() = 0; virtual void SurveyMonitors(); @@ -53,6 +62,9 @@ class ysWindowSystem : public ysWindowSystemObject { ysDynamicArray m_windowArray; ysInputSystem *m_inputSystem; + + bool m_cursorVisible; + bool m_cursorConfined; }; #endif /* YDS_WINDOW_SYSTEM_H */ diff --git a/include/yds_window_system_object.h b/include/yds_window_system_object.h index 8fafc9a5..2e4b9f5c 100644 --- a/include/yds_window_system_object.h +++ b/include/yds_window_system_object.h @@ -5,9 +5,9 @@ class ysWindowSystemObject : public ysObject { public: - enum Platform { - WINDOWS, - UNKNOWN, + enum class Platform { + Windows, + Unknown, }; public: diff --git a/include/yds_windows_window_system.h b/include/yds_windows_window_system.h index 993f1bc0..7316e9a6 100644 --- a/include/yds_windows_window_system.h +++ b/include/yds_windows_window_system.h @@ -23,8 +23,16 @@ class ysWindowsWindowSystem : public ysWindowSystem { static LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + virtual void ConfineCursor(ysWindow *window); + virtual void ReleaseCursor(); + + virtual void SetCursorPosition(int x, int y); + virtual void SetCursorVisible(bool visible); + protected: HINSTANCE m_instance; + + RECT m_oldCursorClip; }; #endif /* YDS_WINDOWS_WINDOW_SYSTEM_H */ diff --git a/physics/src/collision_primitives.cpp b/physics/src/collision_primitives.cpp index 890f823b..a35f0938 100644 --- a/physics/src/collision_primitives.cpp +++ b/physics/src/collision_primitives.cpp @@ -7,6 +7,8 @@ dphysics::Collision::Collision() : ysObject("Collision") { m_penetration = 0.0f; + m_position = ysMath::Constants::Zero; + m_relativePosition[0] = m_relativePosition[1] = ysMath::Constants::Zero; m_normal = ysMath::Constants::Zero; m_body1 = nullptr; m_body2 = nullptr; @@ -19,10 +21,14 @@ dphysics::Collision::Collision() : ysObject("Collision") { m_dynamicFriction = 0.0f; m_staticFriction = 0.0f; m_restitution = 0.0f; + m_contactVelocity = ysMath::Constants::Zero; + m_contactSpace = ysMath::LoadIdentity(); } dphysics::Collision::Collision(Collision &collision) : ysObject("Collision") { m_penetration = collision.m_penetration; + m_relativePosition[0] = collision.m_relativePosition[0]; + m_relativePosition[1] = collision.m_relativePosition[1]; m_normal = collision.m_normal; m_position = collision.m_position; @@ -42,6 +48,8 @@ dphysics::Collision::Collision(Collision &collision) : ysObject("Collision") { m_restitution = collision.m_restitution; m_initialContactVelocity = collision.m_initialContactVelocity; + m_contactVelocity = collision.m_contactVelocity; + m_contactSpace = ysMath::LoadIdentity(); } dphysics::Collision::~Collision() { diff --git a/project/delta-core/delta-core.vcxproj.filters b/project/delta-core/delta-core.vcxproj.filters index 0e08ada4..2e38309c 100644 --- a/project/delta-core/delta-core.vcxproj.filters +++ b/project/delta-core/delta-core.vcxproj.filters @@ -61,9 +61,6 @@ {18b1e4f7-e3f6-4744-817a-74a7b3f7e862} - - {fecda108-c3c0-464e-b6e6-fa90496c9a74} - {25de78db-f5fa-45c8-8f20-1080fcb41348} @@ -100,6 +97,45 @@ {f7364ee5-b1c6-4126-a9a4-dba4b225b852} + + {33a48428-875c-4469-9e00-d381f3699a7c} + + + {9c24c283-d38f-443e-a986-54812672896a} + + + {881cc602-f3ce-47d8-9727-23632e08eb14} + + + {76e2c80d-15f8-401e-b989-e885b9607181} + + + {e1a29b99-c1ae-4324-b5db-5df976331a88} + + + {1d55c780-55c5-4b3c-97c3-d550feac597a} + + + {a045bfce-4213-4c1e-b8d1-119543a000d7} + + + {ed248d0a-4171-4a27-af45-21e748bdf8cd} + + + {c0fa04da-3c5c-4e72-9175-0505337fc154} + + + {5ab3f8bb-6c4f-4932-a157-64a4ca4cb27e} + + + {db6d240a-dd2b-438f-a507-17511fe57c6d} + + + {83029188-0ed8-4b65-8c6d-8bb03789d590} + + + {b34a11c3-fb56-40b3-956c-43cb491246fa} + @@ -536,203 +572,203 @@ Source Files\api\opengl - - Source Files\Unsorted + + Source Files\object - - Source Files\Unsorted + + Source Files\assets\animation\interchange - - Source Files\Unsorted + + Source Files\assets\animation\interchange - - Source Files\Unsorted + + Source Files\assets\animation\interchange - - Source Files\Unsorted + + Source Files\assets\animation\interchange - - Source Files\Unsorted + + Source Files\audio - - Source Files\Unsorted + + Source Files\audio - - Source Files\Unsorted + + Source Files\audio - - Source Files\Unsorted + + Source Files\audio - - Source Files\Unsorted + + Source Files\audio - - Source Files\Unsorted + + Source Files\audio - - Source Files\Unsorted + + Source Files\audio\ds8 - - Source Files\Unsorted + + Source Files\audio\ds8 - - Source Files\Unsorted + + Source Files\audio\wave - - Source Files\Unsorted + + Source Files\audio - - Source Files\Unsorted + + Source Files\audio\ds8 - - Source Files\Unsorted + + Source Files\audio - - Source Files\Unsorted + + Source Files\audio\ds8 - - Source Files\Unsorted + + Source Files\color - - Source Files\Unsorted + + Source Files\window-system - - Source Files\Unsorted + + Source Files\window-system - - Source Files\Unsorted + + Source Files\window-system - - Source Files\Unsorted + + Source Files\window-system - - Source Files\Unsorted + + Source Files\window-system\windows - - Source Files\Unsorted + + Source Files\window-system\windows - - Source Files\Unsorted + + Source Files\window-system\windows - - Source Files\Unsorted + + Source Files\window-system\windows - - Source Files\Unsorted + + Source Files\input\windows - - Source Files\Unsorted + + Source Files\input\windows - - Source Files\Unsorted + + Source Files\input - - Source Files\Unsorted + + Source Files\input - - Source Files\Unsorted + + Source Files\input - - Source Files\Unsorted + + Source Files\error-handling - - Source Files\Unsorted + + Source Files\error-handling - - Source Files\Unsorted + + Source Files\memory-management - - Source Files\Unsorted + + Source Files\debugging\logging - - Source Files\Unsorted + + Source Files\debugging\logging - - Source Files\Unsorted + + Source Files\api - - Source Files\Unsorted + + Source Files\api - - Source Files\Unsorted + + Source Files\api - - Source Files\Unsorted + + Source Files\api - - Source Files\Unsorted + + Source Files\api - - Source Files\Unsorted + + Source Files\api - - Source Files\Unsorted + + Source Files\api - - Source Files\Unsorted + + Source Files\api - - Source Files\Unsorted + + Source Files\api - - Source Files\Unsorted + + Source Files\api - - Source Files\object + + Source Files\api - - Source Files\assets\animation\interchange + + Source Files\debugging\logging - - Source Files\assets\animation\interchange + + Source Files\input - - Source Files\assets\animation\interchange + + Source Files\input - - Source Files\assets\animation\interchange + + Source Files\memory-management - - Source Files\audio + + Source Files\base - - Source Files\audio + + Source Files\assets\legacy - - Source Files\audio + + Source Files\memory-management - - Source Files\audio + + Source Files\assets - - Source Files\audio + + Source Files\timing - - Source Files\audio + + Source Files\timing - - Source Files\audio\ds8 + + Source Files\assets\legacy - - Source Files\audio\ds8 + + Source Files\assets\legacy - - Source Files\audio\wave + + Source Files\math - - Source Files\audio + + Source Files\window-system - - Source Files\audio\ds8 + + Source Files\math - - Source Files\audio + + Source Files\assets\legacy - - Source Files\audio\ds8 + + Source Files\assets\legacy - - Source Files\color + + Source Files\file \ No newline at end of file diff --git a/src/yds_d3d10_context.cpp b/src/yds_d3d10_context.cpp index df31081b..13d797c2 100644 --- a/src/yds_d3d10_context.cpp +++ b/src/yds_d3d10_context.cpp @@ -3,8 +3,8 @@ #include "../include/yds_d3d10_render_target.h" #include "../include/yds_d3d10_device.h" -ysD3D10Context::ysD3D10Context() : ysRenderingContext(ysDevice::DIRECTX10, ysWindowSystemObject::Platform::WINDOWS) { - m_swapChain = NULL; +ysD3D10Context::ysD3D10Context() : ysRenderingContext(ysDevice::DIRECTX10, ysWindowSystemObject::Platform::Windows) { + m_swapChain = nullptr; } ysD3D10Context::~ysD3D10Context() { diff --git a/src/yds_d3d10_device.cpp b/src/yds_d3d10_device.cpp index cf605f8d..b0893a4b 100644 --- a/src/yds_d3d10_device.cpp +++ b/src/yds_d3d10_device.cpp @@ -33,7 +33,6 @@ ysD3D10Device::~ysD3D10Device() { ysError ysD3D10Device::InitializeDevice() { YDS_ERROR_DECLARE("InitializeDevice"); - D3D_FEATURE_LEVEL highestFeatureLevel; HRESULT result = D3D10CreateDevice(nullptr, D3D10_DRIVER_TYPE_HARDWARE, nullptr, @@ -79,7 +78,7 @@ bool ysD3D10Device::CheckSupport() { ysError ysD3D10Device::CreateRenderingContext(ysRenderingContext **context, ysWindow *window) { YDS_ERROR_DECLARE("CreateRenderingContext"); - if (window->GetPlatform() != ysWindowSystem::Platform::WINDOWS) return YDS_ERROR_RETURN(ysError::YDS_INCOMPATIBLE_PLATFORMS); + if (window->GetPlatform() != ysWindowSystem::Platform::Windows) return YDS_ERROR_RETURN(ysError::YDS_INCOMPATIBLE_PLATFORMS); if (context == nullptr) return YDS_ERROR_RETURN(ysError::YDS_INVALID_PARAMETER); if (m_device == nullptr) return YDS_ERROR_RETURN(ysError::YDS_NO_DEVICE); *context = nullptr; @@ -225,7 +224,7 @@ ysError ysD3D10Device::DestroyRenderingContext(ysRenderingContext *&context) { // END TEMP if (context) { - YDS_NESTED_ERROR_CALL( SetContextMode(context, ysRenderingContext::ContextMode::WINDOWED) ); + YDS_NESTED_ERROR_CALL( SetContextMode(context, ysRenderingContext::ContextMode::Windowed) ); ysD3D10Context *d3d10Context = static_cast(context); ULONG result; @@ -251,7 +250,7 @@ ysError ysD3D10Device::SetContextMode(ysRenderingContext *context, ysRenderingCo HRESULT result; - if (mode == ysRenderingContext::ContextMode::FULLSCREEN) { + if (mode == ysRenderingContext::ContextMode::Fullscreen) { window->SetWindowStyle(ysWindow::WindowStyle::FULLSCREEN); //d3d10Context->m_swapChain->ResizeBuffers result = d3d10Context->m_swapChain->SetFullscreenState(TRUE, nullptr); @@ -259,7 +258,7 @@ ysError ysD3D10Device::SetContextMode(ysRenderingContext *context, ysRenderingCo if (FAILED(result)) return YDS_ERROR_RETURN(ysError::YDS_COULD_NOT_ENTER_FULLSCREEN); } - else if (mode == ysRenderingContext::ContextMode::WINDOWED) { + else if (mode == ysRenderingContext::ContextMode::Windowed) { window->SetWindowStyle(ysWindow::WindowStyle::WINDOWED); result = d3d10Context->m_swapChain->SetFullscreenState(FALSE, nullptr); @@ -772,7 +771,7 @@ ysError ysD3D10Device::CreateVertexShader(ysShader **newShader, const char *shad strcpy_s(newD3D10Shader->m_filename, 256, shaderFilename); strcpy_s(newD3D10Shader->m_shaderName, 64, shaderName); - newD3D10Shader->m_shaderType = ysShader::SHADER_TYPE_VERTEX; + newD3D10Shader->m_shaderType = ysShader::ShaderType::Vertex; *newShader = static_cast(newD3D10Shader); @@ -812,7 +811,7 @@ ysError ysD3D10Device::CreatePixelShader(ysShader **newShader, const char *shade strcpy_s(newD3D10Shader->m_filename, 256, shaderFilename); strcpy_s(newD3D10Shader->m_shaderName, 64, shaderName); - newD3D10Shader->m_shaderType = ysShader::SHADER_TYPE_PIXEL; + newD3D10Shader->m_shaderType = ysShader::ShaderType::Pixel; *newShader = static_cast(newD3D10Shader); @@ -831,13 +830,13 @@ ysError ysD3D10Device::DestroyShader(ysShader *&shader) { d3d10Shader->m_shaderBlob->Release(); switch(shader->GetShaderType()) { - case ysShader::SHADER_TYPE_VERTEX: + case ysShader::ShaderType::Vertex: { if (active) GetDevice()->VSSetShader(nullptr); d3d10Shader->m_vertexShader->Release(); break; } - case ysShader::SHADER_TYPE_PIXEL: + case ysShader::ShaderType::Pixel: { if (active) GetDevice()->PSSetShader(nullptr); d3d10Shader->m_pixelShader->Release(); @@ -893,13 +892,13 @@ ysError ysD3D10Device::UseShaderProgram(ysShaderProgram *program) { ysD3D10ShaderProgram *d3d10Program = static_cast(program); ysD3D10ShaderProgram *currentProgram = static_cast(m_activeShaderProgram); - ysD3D10Shader *vertexShader = (program) ? d3d10Program->GetShader(ysShader::SHADER_TYPE_VERTEX) : nullptr; - ysD3D10Shader *fragmentShader = (program) ? d3d10Program->GetShader(ysShader::SHADER_TYPE_PIXEL) : nullptr; + ysD3D10Shader *vertexShader = (program) ? d3d10Program->GetShader(ysShader::ShaderType::Vertex) : nullptr; + ysD3D10Shader *fragmentShader = (program) ? d3d10Program->GetShader(ysShader::ShaderType::Pixel) : nullptr; if (d3d10Program == currentProgram) return YDS_ERROR_RETURN(ysError::YDS_NO_ERROR); - ysD3D10Shader *currentVertexShader = (currentProgram) ? currentProgram->GetShader(ysShader::SHADER_TYPE_VERTEX) : nullptr; - ysD3D10Shader *currentPixelShader = (currentProgram) ? currentProgram->GetShader(ysShader::SHADER_TYPE_PIXEL) : nullptr; + ysD3D10Shader *currentVertexShader = (currentProgram) ? currentProgram->GetShader(ysShader::ShaderType::Vertex) : nullptr; + ysD3D10Shader *currentPixelShader = (currentProgram) ? currentProgram->GetShader(ysShader::ShaderType::Pixel) : nullptr; if (vertexShader != currentVertexShader) { GetDevice()->VSSetShader((vertexShader) ? vertexShader->m_vertexShader : nullptr); diff --git a/src/yds_d3d10_shader_program.cpp b/src/yds_d3d10_shader_program.cpp index e345c862..9e459150 100644 --- a/src/yds_d3d10_shader_program.cpp +++ b/src/yds_d3d10_shader_program.cpp @@ -9,6 +9,6 @@ ysD3D10ShaderProgram::~ysD3D10ShaderProgram() { /* void */ } -ysD3D10Shader *ysD3D10ShaderProgram::GetShader(ysShader::SHADER_TYPE type) { - return static_cast(m_shaderSlots[type]); +ysD3D10Shader *ysD3D10ShaderProgram::GetShader(ysShader::ShaderType type) { + return static_cast(m_shaderSlots[(int)type]); } diff --git a/src/yds_d3d11_context.cpp b/src/yds_d3d11_context.cpp index 52321511..cc9f7203 100644 --- a/src/yds_d3d11_context.cpp +++ b/src/yds_d3d11_context.cpp @@ -3,7 +3,7 @@ #include "../include/yds_d3d11_render_target.h" #include "../include/yds_d3d11_device.h" -ysD3D11Context::ysD3D11Context() : ysRenderingContext(ysDevice::DIRECTX11, ysWindowSystemObject::Platform::WINDOWS) { +ysD3D11Context::ysD3D11Context() : ysRenderingContext(ysDevice::DIRECTX11, ysWindowSystemObject::Platform::Windows) { m_swapChain = nullptr; } diff --git a/src/yds_d3d11_device.cpp b/src/yds_d3d11_device.cpp index 93d40861..7a2e4cc7 100644 --- a/src/yds_d3d11_device.cpp +++ b/src/yds_d3d11_device.cpp @@ -123,7 +123,7 @@ bool ysD3D11Device::CheckSupport() { ysError ysD3D11Device::CreateRenderingContext(ysRenderingContext **context, ysWindow *window) { YDS_ERROR_DECLARE("CreateRenderingContext"); - if (window->GetPlatform() != ysWindowSystem::Platform::WINDOWS) return YDS_ERROR_RETURN(ysError::YDS_INCOMPATIBLE_PLATFORMS); + if (window->GetPlatform() != ysWindowSystem::Platform::Windows) return YDS_ERROR_RETURN(ysError::YDS_INCOMPATIBLE_PLATFORMS); if (context == nullptr) return YDS_ERROR_RETURN(ysError::YDS_INVALID_PARAMETER); if (m_device == nullptr) return YDS_ERROR_RETURN(ysError::YDS_NO_DEVICE); *context = nullptr; @@ -303,7 +303,7 @@ ysError ysD3D11Device::DestroyRenderingContext(ysRenderingContext *&context) { YDS_ERROR_DECLARE("DestroyRenderingContext"); if (context != nullptr) { - YDS_NESTED_ERROR_CALL(SetContextMode(context, ysRenderingContext::ContextMode::WINDOWED)); + YDS_NESTED_ERROR_CALL(SetContextMode(context, ysRenderingContext::ContextMode::Windowed)); ysD3D11Context *d3d11Context = static_cast(context); if (d3d11Context->m_swapChain) d3d11Context->m_swapChain->Release(); @@ -326,7 +326,7 @@ ysError ysD3D11Device::SetContextMode(ysRenderingContext *context, ysRenderingCo HRESULT result; - if (mode == ysRenderingContext::ContextMode::FULLSCREEN) { + if (mode == ysRenderingContext::ContextMode::Fullscreen) { window->SetWindowStyle(ysWindow::WindowStyle::FULLSCREEN); result = d3d11Context->m_swapChain->SetFullscreenState(TRUE, nullptr); @@ -335,7 +335,7 @@ ysError ysD3D11Device::SetContextMode(ysRenderingContext *context, ysRenderingCo } } - else if (mode == ysRenderingContext::ContextMode::WINDOWED) { + else if (mode == ysRenderingContext::ContextMode::Windowed) { window->SetWindowStyle(ysWindow::WindowStyle::WINDOWED); result = d3d11Context->m_swapChain->SetFullscreenState(FALSE, nullptr); @@ -873,7 +873,7 @@ ysError ysD3D11Device::CreateVertexShader(ysShader **newShader, const char *shad strcpy_s(newD3D11Shader->m_filename, 256, shaderFilename); strcpy_s(newD3D11Shader->m_shaderName, 64, shaderName); - newD3D11Shader->m_shaderType = ysShader::SHADER_TYPE_VERTEX; + newD3D11Shader->m_shaderType = ysShader::ShaderType::Vertex; *newShader = static_cast(newD3D11Shader); @@ -912,7 +912,7 @@ ysError ysD3D11Device::CreatePixelShader(ysShader **newShader, const char *shade strcpy_s(newD3D11Shader->m_filename, 256, shaderFilename); strcpy_s(newD3D11Shader->m_shaderName, 64, shaderName); - newD3D11Shader->m_shaderType = ysShader::SHADER_TYPE_PIXEL; + newD3D11Shader->m_shaderType = ysShader::ShaderType::Vertex; *newShader = newD3D11Shader; @@ -954,13 +954,13 @@ ysError ysD3D11Device::DestroyShader(ysShader *&shader) { d3d11Shader->m_shaderBlob->Release(); switch (shader->GetShaderType()) { - case ysShader::SHADER_TYPE_VERTEX: + case ysShader::ShaderType::Vertex: { if (active) GetImmediateContext()->VSSetShader(nullptr, nullptr, 0); d3d11Shader->m_vertexShader->Release(); break; } - case ysShader::SHADER_TYPE_PIXEL: + case ysShader::ShaderType::Pixel: { if (active) GetImmediateContext()->PSSetShader(nullptr, nullptr, 0); d3d11Shader->m_pixelShader->Release(); @@ -1016,13 +1016,13 @@ ysError ysD3D11Device::UseShaderProgram(ysShaderProgram *program) { ysD3D11ShaderProgram *d3d11Program = static_cast(program); ysD3D11ShaderProgram *currentProgram = static_cast(m_activeShaderProgram); - ysD3D11Shader *vertexShader = (d3d11Program) ? d3d11Program->GetShader(ysShader::SHADER_TYPE_VERTEX) : nullptr; - ysD3D11Shader *fragmentShader = (d3d11Program) ? d3d11Program->GetShader(ysShader::SHADER_TYPE_PIXEL) : nullptr; + ysD3D11Shader *vertexShader = (d3d11Program) ? d3d11Program->GetShader(ysShader::ShaderType::Vertex) : nullptr; + ysD3D11Shader *fragmentShader = (d3d11Program) ? d3d11Program->GetShader(ysShader::ShaderType::Pixel) : nullptr; if (d3d11Program == currentProgram) return YDS_ERROR_RETURN(ysError::YDS_NO_ERROR); - ysD3D11Shader *currentVertexShader = (currentProgram) ? currentProgram->GetShader(ysShader::SHADER_TYPE_VERTEX) : nullptr; - ysD3D11Shader *currentPixelShader = (currentProgram) ? currentProgram->GetShader(ysShader::SHADER_TYPE_PIXEL) : nullptr; + ysD3D11Shader *currentVertexShader = (currentProgram) ? currentProgram->GetShader(ysShader::ShaderType::Vertex) : nullptr; + ysD3D11Shader *currentPixelShader = (currentProgram) ? currentProgram->GetShader(ysShader::ShaderType::Pixel) : nullptr; if (vertexShader != currentVertexShader) { GetImmediateContext()->VSSetShader((vertexShader) ? vertexShader->m_vertexShader : nullptr, nullptr, 0); diff --git a/src/yds_d3d11_shader_program.cpp b/src/yds_d3d11_shader_program.cpp index 4bb16bc6..ca61d26f 100644 --- a/src/yds_d3d11_shader_program.cpp +++ b/src/yds_d3d11_shader_program.cpp @@ -9,6 +9,6 @@ ysD3D11ShaderProgram::~ysD3D11ShaderProgram() { /* void */ } -ysD3D11Shader *ysD3D11ShaderProgram::GetShader(ysShader::SHADER_TYPE type) { - return static_cast(m_shaderSlots[type]); +ysD3D11Shader *ysD3D11ShaderProgram::GetShader(ysShader::ShaderType type) { + return static_cast(m_shaderSlots[(int)type]); } diff --git a/src/yds_device.cpp b/src/yds_device.cpp index fffce8c0..1da86573 100644 --- a/src/yds_device.cpp +++ b/src/yds_device.cpp @@ -290,7 +290,7 @@ ysError ysDevice::DestroyShaderProgram(ysShaderProgram *&program, bool destroySh if (program == m_activeShaderProgram) UseShaderProgram(nullptr); if (destroyShaders) { - for(int i = 0; i < ysShader::SHADER_TYPE_NUM_TYPES; i++) { + for(int i = 0; i < (int)ysShader::ShaderType::NumShaderTypes; i++) { YDS_NESTED_ERROR_CALL( DestroyShader(program->m_shaderSlots[i]) ); } } @@ -309,7 +309,7 @@ ysError ysDevice::AttachShader(ysShaderProgram *program, ysShader *shader) { if (!CheckCompatibility(shader)) return YDS_ERROR_RETURN_MSG(ysError::YDS_INCOMPATIBLE_PLATFORMS, "SHADER"); if (program->m_isLinked) return YDS_ERROR_RETURN(ysError::YDS_PROGRAM_ALREADY_LINKED); - program->m_shaderSlots[shader->m_shaderType] = shader; + program->m_shaderSlots[(int)shader->m_shaderType] = shader; return YDS_ERROR_RETURN(ysError::YDS_NO_ERROR); } diff --git a/src/yds_ds8_system.cpp b/src/yds_ds8_system.cpp index 017dcda4..49f7eb29 100644 --- a/src/yds_ds8_system.cpp +++ b/src/yds_ds8_system.cpp @@ -33,7 +33,7 @@ void ysDS8System::ConnectDevice(ysAudioDevice *device, ysWindow *windowAssociati int breakHere=0; } - //RaiseError(windowAssociation->GetPlatform() == ysWindow::Platform::WINDOWS, "Incompatible platform for audio device window association."); + //RaiseError(windowAssociation->GetPlatform() == ysWindow::Platform::Windows, "Incompatible platform for audio device window association."); ysWindowsWindow *windowsWindow = static_cast(windowAssociation); result = ds8Device->m_device->SetCooperativeLevel(windowsWindow->GetWindowHandle(), DSSCL_PRIORITY); diff --git a/src/yds_input_device.cpp b/src/yds_input_device.cpp index b96092f6..41b83710 100644 --- a/src/yds_input_device.cpp +++ b/src/yds_input_device.cpp @@ -1,6 +1,6 @@ #include "../include/yds_input_device.h" -ysInputDevice::ysInputDevice() : ysWindowSystemObject("INPUT DEVICE", Platform::UNKNOWN) { +ysInputDevice::ysInputDevice() : ysWindowSystemObject("INPUT DEVICE", Platform::Unknown) { SetName(""); m_type = InputDeviceType::UNKNOWN; diff --git a/src/yds_input_system.cpp b/src/yds_input_system.cpp index 0ae4df75..fe6b3b83 100644 --- a/src/yds_input_system.cpp +++ b/src/yds_input_system.cpp @@ -3,7 +3,7 @@ #include "../include/yds_window_system.h" #include "../include/yds_windows_input_system.h" -ysInputSystem::ysInputSystem() : ysWindowSystemObject("INPUT_SYSTEM", Platform::UNKNOWN) { +ysInputSystem::ysInputSystem() : ysWindowSystemObject("INPUT_SYSTEM", Platform::Unknown) { m_windowSystem = nullptr; m_supportMultiple = false; } @@ -17,16 +17,16 @@ ysInputSystem::~ysInputSystem() { /* void */ } -ysError ysInputSystem::CreateInputSystem(ysInputSystem** newInputSystem, Platform platform) { +ysError ysInputSystem::CreateInputSystem(ysInputSystem **newInputSystem, Platform platform) { YDS_ERROR_DECLARE("CreateInputSystem"); if (newInputSystem == nullptr) return YDS_ERROR_RETURN_STATIC(ysError::YDS_INVALID_PARAMETER); *newInputSystem = nullptr; - if (platform == Platform::UNKNOWN) return YDS_ERROR_RETURN_STATIC(ysError::YDS_INVALID_PARAMETER); + if (platform == Platform::Unknown) return YDS_ERROR_RETURN_STATIC(ysError::YDS_INVALID_PARAMETER); switch (platform) { - case Platform::WINDOWS: + case Platform::Windows: *newInputSystem = new ysWindowsInputSystem(); break; } diff --git a/src/yds_monitor.cpp b/src/yds_monitor.cpp index c6d9fe25..ac08ce0c 100644 --- a/src/yds_monitor.cpp +++ b/src/yds_monitor.cpp @@ -1,6 +1,6 @@ #include "../include/yds_monitor.h" -ysMonitor::ysMonitor() : ysWindowSystemObject("DISPLAY_MONITOR", Platform::WINDOWS) { +ysMonitor::ysMonitor() : ysWindowSystemObject("DISPLAY_MONITOR", Platform::Windows) { m_maxDeviceNameLength = 0; m_deviceName = 0; diff --git a/src/yds_mouse.cpp b/src/yds_mouse.cpp index da67aad4..fad5c7d9 100644 --- a/src/yds_mouse.cpp +++ b/src/yds_mouse.cpp @@ -11,7 +11,7 @@ ysMouse::~ysMouse() { } void ysMouse::Reset() { - for (int i = 0; i < BUTTON_COUNT; i++) m_buttons[i].Reset(); + for (int i = 0; i < (int)Button::Count; i++) m_buttons[i].Reset(); m_x = 0; m_y = 0; @@ -33,15 +33,15 @@ void ysMouse::UpdateWheel(int dwheel) { m_wheel += dwheel; } -void ysMouse::UpdateButton(BUTTON_CODE button, ysKey::KEY_STATE state) { - m_buttons[button].m_state = state; +void ysMouse::UpdateButton(Button button, ysKey::KEY_STATE state) { + m_buttons[(int)button].m_state = state; } -bool ysMouse::ProcessMouseButton(BUTTON_CODE button, ysKey::KEY_STATE state) { - if (m_buttons[button].m_state != state) return false; +bool ysMouse::ProcessMouseButton(Button button, ysKey::KEY_STATE state) { + if (m_buttons[(int)button].m_state != state) return false; - if (m_buttons[button].m_state == ysKey::KEY_UP_TRANS) m_buttons[button].m_state = ysKey::KEY_UP; - if (m_buttons[button].m_state == ysKey::KEY_DOWN_TRANS) m_buttons[button].m_state = ysKey::KEY_DOWN; + if (m_buttons[(int)button].m_state == ysKey::KEY_UP_TRANS) m_buttons[(int)button].m_state = ysKey::KEY_UP; + if (m_buttons[(int)button].m_state == ysKey::KEY_DOWN_TRANS) m_buttons[(int)button].m_state = ysKey::KEY_DOWN; return true; } diff --git a/src/yds_opengl_context.cpp b/src/yds_opengl_context.cpp index b781186f..11794e0b 100644 --- a/src/yds_opengl_context.cpp +++ b/src/yds_opengl_context.cpp @@ -1,6 +1,6 @@ #include "../include/yds_opengl_context.h" -ysOpenGLVirtualContext::ysOpenGLVirtualContext() : ysRenderingContext(OPENGL4_0, ysWindowSystemObject::Platform::UNKNOWN) { +ysOpenGLVirtualContext::ysOpenGLVirtualContext() : ysRenderingContext(OPENGL4_0, ysWindowSystemObject::Platform::Unknown) { m_isRealContext = false; } diff --git a/src/yds_opengl_device.cpp b/src/yds_opengl_device.cpp index d5559229..40baf353 100644 --- a/src/yds_opengl_device.cpp +++ b/src/yds_opengl_device.cpp @@ -54,7 +54,7 @@ ysError ysOpenGLDevice::CreateRenderingContext(ysRenderingContext **context, ysW if (context == NULL) return YDS_ERROR_RETURN(ysError::YDS_INVALID_PARAMETER); *context = NULL; - if (window->GetPlatform() == ysWindowSystemObject::Platform::WINDOWS) { + if (window->GetPlatform() == ysWindowSystemObject::Platform::Windows) { ysOpenGLWindowsContext *newContext; newContext = m_renderingContexts.NewGeneric(); YDS_NESTED_ERROR_CALL(newContext->CreateRenderingContext(this, window, 4, 3)); @@ -618,7 +618,7 @@ ysError ysOpenGLDevice::CreateVertexShader(ysShader **newShader, const char *sha ysOpenGLShader *newOpenGLShader = m_shaders.NewGeneric(); strcpy_s(newOpenGLShader->m_shaderName, 64, shaderName); strcpy_s(newOpenGLShader->m_filename, 256, shaderFilename); - newOpenGLShader->m_shaderType = ysShader::SHADER_TYPE_VERTEX; + newOpenGLShader->m_shaderType = ysShader::ShaderType::Vertex; newOpenGLShader->m_handle = handle; *newShader = static_cast(newOpenGLShader); @@ -673,7 +673,7 @@ ysError ysOpenGLDevice::CreatePixelShader(ysShader **newShader, const char *shad ysOpenGLShader *newOpenGLShader = m_shaders.NewGeneric(); strcpy_s(newOpenGLShader->m_shaderName, 64, shaderName); strcpy_s(newOpenGLShader->m_filename, 256, shaderFilename); - newOpenGLShader->m_shaderType = ysShader::SHADER_TYPE_PIXEL; + newOpenGLShader->m_shaderType = ysShader::ShaderType::Pixel; newOpenGLShader->m_handle = shaderHandle; *newShader = static_cast(newOpenGLShader); @@ -701,7 +701,7 @@ ysError ysOpenGLDevice::DestroyShaderProgram(ysShaderProgram *&program, bool des ysOpenGLShaderProgram *openglProgram = static_cast(program); - for (int i = 0; i < ysShader::SHADER_TYPE_NUM_TYPES; i++) { + for (int i = 0; i < (int)ysShader::ShaderType::NumShaderTypes; i++) { ysOpenGLShader *openglShader = static_cast(openglProgram->m_shaderSlots[i]); m_realContext->glDetachShader(openglProgram->m_handle, openglShader->m_handle); } diff --git a/src/yds_opengl_shader_program.cpp b/src/yds_opengl_shader_program.cpp index 8f163d37..a4192ba8 100644 --- a/src/yds_opengl_shader_program.cpp +++ b/src/yds_opengl_shader_program.cpp @@ -10,6 +10,6 @@ ysOpenGLShaderProgram::~ysOpenGLShaderProgram() { /* void */ } -ysOpenGLShader *ysOpenGLShaderProgram::GetShader(ysShader::SHADER_TYPE type) { - return static_cast(m_shaderSlots[type]); +ysOpenGLShader *ysOpenGLShaderProgram::GetShader(ysShader::ShaderType type) { + return static_cast(m_shaderSlots[(int)type]); } diff --git a/src/yds_opengl_windows_context.cpp b/src/yds_opengl_windows_context.cpp index 57f69b09..3727c819 100644 --- a/src/yds_opengl_windows_context.cpp +++ b/src/yds_opengl_windows_context.cpp @@ -4,7 +4,7 @@ #include "../include/yds_windows_window.h" #include "../include/yds_windows_window_system.h" -ysOpenGLWindowsContext::ysOpenGLWindowsContext() : ysOpenGLVirtualContext(ysWindowSystem::Platform::WINDOWS) { +ysOpenGLWindowsContext::ysOpenGLWindowsContext() : ysOpenGLVirtualContext(ysWindowSystem::Platform::Windows) { m_contextHandle = nullptr; m_device = nullptr; m_deviceHandle = nullptr; @@ -17,7 +17,7 @@ ysOpenGLWindowsContext::~ysOpenGLWindowsContext() { ysError ysOpenGLWindowsContext::CreateRenderingContext(ysOpenGLDevice *device, ysWindow *window, int major, int minor) { YDS_ERROR_DECLARE("CreateRenderingContext"); - if (window->GetPlatform() != ysWindowSystemObject::Platform::WINDOWS) { + if (window->GetPlatform() != ysWindowSystemObject::Platform::Windows) { return YDS_ERROR_RETURN(ysError::YDS_INCOMPATIBLE_PLATFORMS); } @@ -149,7 +149,7 @@ ysError ysOpenGLWindowsContext::DestroyContext() { ysError ysOpenGLWindowsContext::TransferContext(ysOpenGLVirtualContext *context) { YDS_ERROR_DECLARE("TransferContext"); - if (context->GetPlatform() != ysWindowSystemObject::Platform::WINDOWS) return YDS_ERROR_RETURN(ysError::YDS_INCOMPATIBLE_PLATFORMS); + if (context->GetPlatform() != ysWindowSystemObject::Platform::Windows) return YDS_ERROR_RETURN(ysError::YDS_INCOMPATIBLE_PLATFORMS); ysOpenGLWindowsContext *windowsContext = static_cast(context); windowsContext->m_contextHandle = m_contextHandle; @@ -168,14 +168,14 @@ ysError ysOpenGLWindowsContext::SetContextMode(ContextMode mode) { ysMonitor *monitor = window->GetMonitor(); int result; - if (mode == ysRenderingContext::ContextMode::FULLSCREEN) { + if (mode == ysRenderingContext::ContextMode::Fullscreen) { window->SetWindowStyle(ysWindow::WindowStyle::FULLSCREEN); DEVMODE dmScreenSettings; memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); dmScreenSettings.dmSize = sizeof(dmScreenSettings); - dmScreenSettings.dmPelsWidth = monitor->GetWidth(); //window->GetWidth(); - dmScreenSettings.dmPelsHeight = monitor->GetHeight(); //window->GetHeight(); + dmScreenSettings.dmPelsWidth = monitor->GetWidth(); + dmScreenSettings.dmPelsHeight = monitor->GetHeight(); dmScreenSettings.dmBitsPerPel = 32; dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; @@ -183,21 +183,14 @@ ysError ysOpenGLWindowsContext::SetContextMode(ContextMode mode) { if (result != DISP_CHANGE_SUCCESSFUL) { return YDS_ERROR_RETURN(ysError::YDS_COULD_NOT_ENTER_FULLSCREEN); } - - //ChangeDisplaySettingsEx (NULL, NULL, NULL, 0, NULL); - - // TEMP - ShowCursor(TRUE); } - else if (mode == ysRenderingContext::ContextMode::WINDOWED) { + else if (mode == ysRenderingContext::ContextMode::Windowed) { window->SetWindowStyle(ysWindow::WindowStyle::WINDOWED); result = ChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL); if (result != DISP_CHANGE_SUCCESSFUL) { return YDS_ERROR_RETURN(ysError::YDS_COULD_NOT_EXIT_FULLSCREEN); } - - ShowCursor(TRUE); } return YDS_ERROR_RETURN(ysError::YDS_NO_ERROR); diff --git a/src/yds_rendering_context.cpp b/src/yds_rendering_context.cpp index f3d81e8e..d56fec44 100644 --- a/src/yds_rendering_context.cpp +++ b/src/yds_rendering_context.cpp @@ -5,16 +5,16 @@ ysRenderingContext::ysRenderingContext() : ysContextObject("RENDERING_CONTEXT", m_targetWindow = nullptr; m_attachedRenderTarget = nullptr; - m_currentMode = ContextMode::UNDEFINED; + m_currentMode = ContextMode::Undefined; - m_platform = ysWindowSystem::Platform::UNKNOWN; + m_platform = ysWindowSystem::Platform::Unknown; } ysRenderingContext::ysRenderingContext(DEVICE_API API, ysWindowSystem::Platform platform) : ysContextObject("RENDERING_CONTEXT", API) { m_targetWindow = nullptr; m_attachedRenderTarget = nullptr; - m_currentMode = ContextMode::UNDEFINED; + m_currentMode = ContextMode::Undefined; m_platform = platform; } diff --git a/src/yds_shader.cpp b/src/yds_shader.cpp index 2a1f920b..f68e9506 100644 --- a/src/yds_shader.cpp +++ b/src/yds_shader.cpp @@ -3,13 +3,13 @@ ysShader::ysShader() : ysContextObject("SHADER", API_UNKNOWN) { m_filename[0] = '\0'; m_shaderName[0] = '\0'; - m_shaderType = SHADER_TYPE::SHADER_TYPE_VERTEX; + m_shaderType = ShaderType::Vertex; } ysShader::ysShader(DEVICE_API API) : ysContextObject("SHADER", API) { m_filename[0] = '\0'; m_shaderName[0] = '\0'; - m_shaderType = SHADER_TYPE::SHADER_TYPE_VERTEX; + m_shaderType = ShaderType::Vertex; } ysShader::~ysShader() { diff --git a/src/yds_shader_program.cpp b/src/yds_shader_program.cpp index bbd3b0d8..870751de 100644 --- a/src/yds_shader_program.cpp +++ b/src/yds_shader_program.cpp @@ -1,12 +1,12 @@ #include "../include/yds_shader_program.h" ysShaderProgram::ysShaderProgram() : ysContextObject("SHADER_PROGRAM", API_UNKNOWN) { - memset(m_shaderSlots, 0, sizeof(ysShader *) * ysShader::SHADER_TYPE_NUM_TYPES); + memset(m_shaderSlots, 0, sizeof(ysShader *) * (int)ysShader::ShaderType::NumShaderTypes); m_isLinked = false; } ysShaderProgram::ysShaderProgram(DEVICE_API API) : ysContextObject("SHADER_PROGRAM", API) { - memset(m_shaderSlots, 0, sizeof(ysShader *) * ysShader::SHADER_TYPE_NUM_TYPES); + memset(m_shaderSlots, 0, sizeof(ysShader *) * (int)ysShader::ShaderType::NumShaderTypes); m_isLinked = false; } diff --git a/src/yds_window.cpp b/src/yds_window.cpp index 29b58fca..cbaabad6 100644 --- a/src/yds_window.cpp +++ b/src/yds_window.cpp @@ -3,7 +3,7 @@ #include "../include/yds_window_event_handler.h" #include "../include/yds_window_system.h" -ysWindow::ysWindow() : ysWindowSystemObject("WINDOW", Platform::UNKNOWN) { +ysWindow::ysWindow() : ysWindowSystemObject("WINDOW", Platform::Unknown) { m_title[0] = '\0'; m_monitor = nullptr; @@ -46,7 +46,7 @@ ysWindow::ysWindow(Platform platform) : ysWindowSystemObject("WINDOW", platform) m_windowState = WindowState::HIDDEN; m_parent = nullptr; - m_active = false; + m_active = true; m_eventHandler = nullptr; } diff --git a/src/yds_window_event_handler.cpp b/src/yds_window_event_handler.cpp index 078da81c..2452841e 100644 --- a/src/yds_window_event_handler.cpp +++ b/src/yds_window_event_handler.cpp @@ -1,7 +1,7 @@ #include "../include/yds_window_event_handler.h" ysWindowEventHandler::ysWindowEventHandler() : ysObject("WINDOW_EVENT_HANDLER") { - m_window = NULL; + m_window = nullptr; } ysWindowEventHandler::~ysWindowEventHandler() { diff --git a/src/yds_window_system.cpp b/src/yds_window_system.cpp index f2eada21..5c4a0d18 100644 --- a/src/yds_window_system.cpp +++ b/src/yds_window_system.cpp @@ -3,15 +3,16 @@ #include "../include/yds_input_system.h" #include "../include/yds_windows_window_system.h" -ysWindowSystem *ysWindowSystem::g_instance = NULL; +ysWindowSystem *ysWindowSystem::g_instance = nullptr; -ysWindowSystem::ysWindowSystem() : ysWindowSystemObject("WINDOW_SYSTEM", Platform::UNKNOWN) { +ysWindowSystem::ysWindowSystem() : ysWindowSystemObject("WINDOW_SYSTEM", Platform::Unknown) { YDS_ERROR_DECLARE("ysWindowSystem"); - if (g_instance) YDS_ERROR_RETURN(ysError::YDS_MULTIPLE_SYSTEMS); + if (g_instance != nullptr) YDS_ERROR_RETURN(ysError::YDS_MULTIPLE_SYSTEMS); g_instance = this; m_inputSystem = nullptr; + m_cursorVisible = true; YDS_ERROR_RETURN(ysError::YDS_NO_ERROR); } @@ -19,9 +20,10 @@ ysWindowSystem::ysWindowSystem() : ysWindowSystemObject("WINDOW_SYSTEM", Platfor ysWindowSystem::ysWindowSystem(Platform platform) : ysWindowSystemObject("WINDOW_SYSTEM", platform) { YDS_ERROR_DECLARE("ysWindowSystem"); - if (g_instance) YDS_ERROR_RETURN(ysError::YDS_MULTIPLE_SYSTEMS); + if (g_instance != nullptr) YDS_ERROR_RETURN(ysError::YDS_MULTIPLE_SYSTEMS); g_instance = this; + m_cursorVisible = true; m_inputSystem = nullptr; YDS_ERROR_RETURN(ysError::YDS_NO_ERROR); @@ -34,14 +36,14 @@ ysWindowSystem::~ysWindowSystem() { ysError ysWindowSystem::CreateWindowSystem(ysWindowSystem **newSystem, Platform platform) { YDS_ERROR_DECLARE("CreateWindowSystem"); - if (newSystem == NULL) return YDS_ERROR_RETURN_STATIC(ysError::YDS_INVALID_PARAMETER); - *newSystem = NULL; + if (newSystem == nullptr) return YDS_ERROR_RETURN_STATIC(ysError::YDS_INVALID_PARAMETER); + *newSystem = nullptr; - if (platform == Platform::UNKNOWN) return YDS_ERROR_RETURN_STATIC(ysError::YDS_INVALID_PARAMETER); + if (platform == Platform::Unknown) return YDS_ERROR_RETURN_STATIC(ysError::YDS_INVALID_PARAMETER); if (g_instance) return YDS_ERROR_RETURN_STATIC(ysError::YDS_MULTIPLE_ERROR_SYSTEMS); switch (platform) { - case Platform::WINDOWS: + case Platform::Windows: *newSystem = new ysWindowsWindowSystem(); break; default: diff --git a/src/yds_window_system_object.cpp b/src/yds_window_system_object.cpp index 8c851d70..81587f71 100644 --- a/src/yds_window_system_object.cpp +++ b/src/yds_window_system_object.cpp @@ -3,7 +3,7 @@ ysWindowSystemObject::ysWindowSystemObject() : ysObject("WINDOW_SYSTEM_OBJECT") { YDS_ERROR_DECLARE("ysWindowSystemObject"); - m_platform = Platform::UNKNOWN; + m_platform = Platform::Unknown; YDS_ERROR_RETURN(ysError::YDS_NO_PLATFORM); } diff --git a/src/yds_windows_audio_wave_file.cpp b/src/yds_windows_audio_wave_file.cpp index b5d24b90..eefb728d 100644 --- a/src/yds_windows_audio_wave_file.cpp +++ b/src/yds_windows_audio_wave_file.cpp @@ -2,7 +2,7 @@ #include -ysWindowsAudioWaveFile::ysWindowsAudioWaveFile() : ysAudioFile(Platform::WINDOWS, AudioFormat::Wave) { +ysWindowsAudioWaveFile::ysWindowsAudioWaveFile() : ysAudioFile(Platform::Windows, AudioFormat::Wave) { m_fileHandle = NULL; m_dataSegmentOffset = 0; } diff --git a/src/yds_windows_input_device.cpp b/src/yds_windows_input_device.cpp index a283d4af..ba4bfe03 100644 --- a/src/yds_windows_input_device.cpp +++ b/src/yds_windows_input_device.cpp @@ -1,12 +1,12 @@ #include "../include/yds_windows_input_device.h" -ysWindowsInputDevice::ysWindowsInputDevice() : ysInputDevice(Platform::WINDOWS, InputDeviceType::UNKNOWN) { +ysWindowsInputDevice::ysWindowsInputDevice() : ysInputDevice(Platform::Windows, InputDeviceType::UNKNOWN) { m_deviceHandle = NULL; memset(&m_info, 0, sizeof(m_info)); m_systemName[0] = 0; } -ysWindowsInputDevice::ysWindowsInputDevice(InputDeviceType inputDeviceType) : ysInputDevice(Platform::WINDOWS, inputDeviceType) { +ysWindowsInputDevice::ysWindowsInputDevice(InputDeviceType inputDeviceType) : ysInputDevice(Platform::Windows, inputDeviceType) { m_deviceHandle = NULL; memset(&m_info, 0, sizeof(m_info)); m_systemName[0] = 0; diff --git a/src/yds_windows_input_system.cpp b/src/yds_windows_input_system.cpp index f78b8b96..3ef1d207 100644 --- a/src/yds_windows_input_system.cpp +++ b/src/yds_windows_input_system.cpp @@ -6,7 +6,7 @@ #include //#include -ysWindowsInputSystem::ysWindowsInputSystem() : ysInputSystem(Platform::WINDOWS) { +ysWindowsInputSystem::ysWindowsInputSystem() : ysInputSystem(Platform::Windows) { /* void */ } @@ -272,29 +272,29 @@ int ysWindowsInputSystem::ProcessInputMessage(HRAWINPUT lparam) { if (raw->data.mouse.usButtonFlags & RI_MOUSE_WHEEL) mouse->UpdateWheel((int)((short)raw->data.mouse.usButtonData)); - if (raw->data.mouse.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN) mouse->UpdateButton(ysMouse::BUTTON_LEFT, ysKey::KEY_DOWN_TRANS); - if (raw->data.mouse.usButtonFlags & RI_MOUSE_LEFT_BUTTON_UP) mouse->UpdateButton(ysMouse::BUTTON_LEFT, ysKey::KEY_UP_TRANS); + if (raw->data.mouse.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN) mouse->UpdateButton(ysMouse::Button::Left, ysKey::KEY_DOWN_TRANS); + if (raw->data.mouse.usButtonFlags & RI_MOUSE_LEFT_BUTTON_UP) mouse->UpdateButton(ysMouse::Button::Left, ysKey::KEY_UP_TRANS); - if (raw->data.mouse.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_DOWN) mouse->UpdateButton(ysMouse::BUTTON_RIGHT, ysKey::KEY_DOWN_TRANS); - if (raw->data.mouse.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_UP) mouse->UpdateButton(ysMouse::BUTTON_RIGHT, ysKey::KEY_UP_TRANS); + if (raw->data.mouse.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_DOWN) mouse->UpdateButton(ysMouse::Button::Right, ysKey::KEY_DOWN_TRANS); + if (raw->data.mouse.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_UP) mouse->UpdateButton(ysMouse::Button::Right, ysKey::KEY_UP_TRANS); - if (raw->data.mouse.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_DOWN) mouse->UpdateButton(ysMouse::BUTTON_MIDDLE, ysKey::KEY_DOWN_TRANS); - if (raw->data.mouse.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_UP) mouse->UpdateButton(ysMouse::BUTTON_MIDDLE, ysKey::KEY_UP_TRANS); + if (raw->data.mouse.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_DOWN) mouse->UpdateButton(ysMouse::Button::Middle, ysKey::KEY_DOWN_TRANS); + if (raw->data.mouse.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_UP) mouse->UpdateButton(ysMouse::Button::Middle, ysKey::KEY_UP_TRANS); - if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_1_DOWN) mouse->UpdateButton(ysMouse::BUTTON_1, ysKey::KEY_DOWN_TRANS); - if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_1_UP) mouse->UpdateButton(ysMouse::BUTTON_1, ysKey::KEY_UP_TRANS); + if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_1_DOWN) mouse->UpdateButton(ysMouse::Button::Aux_1, ysKey::KEY_DOWN_TRANS); + if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_1_UP) mouse->UpdateButton(ysMouse::Button::Aux_1, ysKey::KEY_UP_TRANS); - if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_2_DOWN) mouse->UpdateButton(ysMouse::BUTTON_2, ysKey::KEY_DOWN_TRANS); - if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_2_UP) mouse->UpdateButton(ysMouse::BUTTON_2, ysKey::KEY_UP_TRANS); + if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_2_DOWN) mouse->UpdateButton(ysMouse::Button::Aux_2, ysKey::KEY_DOWN_TRANS); + if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_2_UP) mouse->UpdateButton(ysMouse::Button::Aux_2, ysKey::KEY_UP_TRANS); - if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_3_DOWN) mouse->UpdateButton(ysMouse::BUTTON_3, ysKey::KEY_DOWN_TRANS); - if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_3_UP) mouse->UpdateButton(ysMouse::BUTTON_3, ysKey::KEY_UP_TRANS); + if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_3_DOWN) mouse->UpdateButton(ysMouse::Button::Aux_3, ysKey::KEY_DOWN_TRANS); + if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_3_UP) mouse->UpdateButton(ysMouse::Button::Aux_3, ysKey::KEY_UP_TRANS); - if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_4_DOWN) mouse->UpdateButton(ysMouse::BUTTON_4, ysKey::KEY_DOWN_TRANS); - if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_4_UP) mouse->UpdateButton(ysMouse::BUTTON_4, ysKey::KEY_UP_TRANS); + if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_4_DOWN) mouse->UpdateButton(ysMouse::Button::Aux_4, ysKey::KEY_DOWN_TRANS); + if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_4_UP) mouse->UpdateButton(ysMouse::Button::Aux_4, ysKey::KEY_UP_TRANS); - if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_5_DOWN) mouse->UpdateButton(ysMouse::BUTTON_5, ysKey::KEY_DOWN_TRANS); - if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_5_UP) mouse->UpdateButton(ysMouse::BUTTON_5, ysKey::KEY_UP_TRANS); + if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_5_DOWN) mouse->UpdateButton(ysMouse::Button::Aux_5, ysKey::KEY_DOWN_TRANS); + if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_5_UP) mouse->UpdateButton(ysMouse::Button::Aux_5, ysKey::KEY_UP_TRANS); } } diff --git a/src/yds_windows_monitor.cpp b/src/yds_windows_monitor.cpp index 261ef7c1..df311fc4 100644 --- a/src/yds_windows_monitor.cpp +++ b/src/yds_windows_monitor.cpp @@ -2,7 +2,7 @@ #include -ysWindowsMonitor::ysWindowsMonitor() : ysMonitor(Platform::WINDOWS) { +ysWindowsMonitor::ysWindowsMonitor() : ysMonitor(Platform::Windows) { InitializeDeviceName(CCHDEVICENAME); } diff --git a/src/yds_windows_window.cpp b/src/yds_windows_window.cpp index fe693301..606d5154 100644 --- a/src/yds_windows_window.cpp +++ b/src/yds_windows_window.cpp @@ -1,7 +1,7 @@ #include "../include/yds_windows_window.h" #include "../include/yds_windows_window_system.h" -ysWindowsWindow::ysWindowsWindow() : ysWindow(Platform::WINDOWS) { +ysWindowsWindow::ysWindowsWindow() : ysWindow(Platform::Windows) { m_instance = 0; m_hwnd = 0; } @@ -204,7 +204,7 @@ void ysWindowsWindow::AL_SetSize(int width, int height) { } void ysWindowsWindow::AL_SetLocation(int x, int y) { - ysWindow::AL_SetSize(x, y); + ysWindow::AL_SetLocation(x, y); SetWindowPos(m_hwnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); } diff --git a/src/yds_windows_window_system.cpp b/src/yds_windows_window_system.cpp index cdb92ed3..12ba65cb 100644 --- a/src/yds_windows_window_system.cpp +++ b/src/yds_windows_window_system.cpp @@ -4,7 +4,7 @@ #include "../include/yds_windows_monitor.h" #include "../include/yds_windows_input_system.h" -ysWindowsWindowSystem::ysWindowsWindowSystem() : ysWindowSystem(Platform::WINDOWS) { +ysWindowsWindowSystem::ysWindowsWindowSystem() : ysWindowSystem(Platform::Windows) { m_instance = NULL; } @@ -124,3 +124,48 @@ LRESULT WINAPI ysWindowsWindowSystem::WinProc(HWND hWnd, UINT msg, WPARAM wParam return DefWindowProc(hWnd, msg, wParam, lParam); } + +void ysWindowsWindowSystem::ConfineCursor(ysWindow *window) { + if (IsCursorConfined()) return; + ysWindowSystem::ConfineCursor(window); + + GetClipCursor(&m_oldCursorClip); + ysWindowsWindow *windowsWindow = static_cast(window); + + RECT clientRect; + GetClientRect(windowsWindow->GetWindowHandle(), &clientRect); + + POINT ul, lr; + ul.x = clientRect.left; + ul.y = clientRect.top; + lr.x = clientRect.right; + lr.y = clientRect.bottom; + + MapWindowPoints(windowsWindow->GetWindowHandle(), nullptr, &ul, 1); + MapWindowPoints(windowsWindow->GetWindowHandle(), nullptr, &lr, 1); + + clientRect.left = ul.x; + clientRect.top = ul.y; + + clientRect.right = lr.x; + clientRect.bottom = lr.y; + + ClipCursor(&clientRect); +} + +void ysWindowsWindowSystem::ReleaseCursor() { + if (!IsCursorConfined()) return; + ysWindowSystem::ReleaseCursor(); + + ClipCursor(&m_oldCursorClip); +} + +void ysWindowsWindowSystem::SetCursorPosition(int x, int y) { + SetCursorPos(x, y); +} + +void ysWindowsWindowSystem::SetCursorVisible(bool visible) { + ysWindowSystem::SetCursorVisible(visible); + + ShowCursor(visible ? TRUE : FALSE); +}