mirror of
https://github.com/SFML/SFML.git
synced 2024-11-24 20:31:05 +08:00
Reduce compile-time impact of 'windows.h'
This commit is contained in:
parent
ae3a38345d
commit
3c7fba0f96
@ -3,6 +3,9 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics.hpp>
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <cmath>
|
||||
|
||||
|
@ -40,6 +40,9 @@
|
||||
|
||||
// The Visual C++ version of gl.h uses WINGDIAPI and APIENTRY but doesn't define them
|
||||
#ifdef _MSC_VER
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
@ -67,7 +70,7 @@
|
||||
|
||||
#include <GLES/gl.h>
|
||||
#include <GLES/glext.h>
|
||||
|
||||
|
||||
// We're not using OpenGL ES 2+ yet, but we can use the sRGB extension
|
||||
#include <GLES2/gl2platform.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
@ -39,7 +39,8 @@
|
||||
|
||||
#ifdef SFML_SYSTEM_WINDOWS
|
||||
|
||||
#include <windows.h>
|
||||
#include <SFML/System/Win32/WindowsHeader.hpp>
|
||||
#include <cstdlib> // for `__argc` and `__argv`
|
||||
|
||||
extern int main(int argc, char* argv[]);
|
||||
|
||||
|
@ -28,15 +28,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#ifdef _WIN32_WINDOWS
|
||||
#undef _WIN32_WINDOWS
|
||||
#endif
|
||||
#ifdef _WIN32_WINNT
|
||||
#undef _WIN32_WINNT
|
||||
#endif
|
||||
#define _WIN32_WINDOWS 0x0501
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#include <SFML/Network/Socket.hpp>
|
||||
#include <SFML/System/Win32/WindowsHeader.hpp>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
|
50
src/SFML/System/Win32/WindowsHeader.hpp
Normal file
50
src/SFML/System/Win32/WindowsHeader.hpp
Normal file
@ -0,0 +1,50 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2021 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_WINDOWSHEADER_HPP
|
||||
#define SFML_WINDOWSHEADER_HPP
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WINDOWS
|
||||
#define _WIN32_WINDOWS 0x0501
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#endif
|
||||
|
||||
#ifndef WINVER
|
||||
#define WINVER 0x0501
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#endif // SFML_WINDOWSHEADER_HPP
|
@ -26,9 +26,9 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/Win32/ClipboardImpl.hpp>
|
||||
#include <SFML/System/Win32/WindowsHeader.hpp>
|
||||
#include <SFML/System/String.hpp>
|
||||
#include <iostream>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
@ -26,9 +26,11 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/Win32/CursorImpl.hpp>
|
||||
#include <SFML/System/Win32/WindowsHeader.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
@ -188,7 +190,7 @@ bool CursorImpl::loadFromSystem(Cursor::Type type)
|
||||
void CursorImpl::release()
|
||||
{
|
||||
if (m_cursor && !m_systemCursor) {
|
||||
DestroyCursor(m_cursor);
|
||||
DestroyCursor(static_cast<HCURSOR>(m_cursor));
|
||||
m_cursor = nullptr;
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,6 @@
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
namespace sf
|
||||
{
|
||||
|
||||
@ -92,8 +90,8 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
HCURSOR m_cursor;
|
||||
bool m_systemCursor;
|
||||
void* m_cursor; // Type erasure via `void*` is used here to avoid depending on `windows.h`
|
||||
bool m_systemCursor;
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
@ -25,17 +25,9 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#ifdef _WIN32_WINDOWS
|
||||
#undef _WIN32_WINDOWS
|
||||
#endif
|
||||
#ifdef _WIN32_WINNT
|
||||
#undef _WIN32_WINNT
|
||||
#endif
|
||||
#define _WIN32_WINDOWS 0x0501
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#include <SFML/Window/Window.hpp>
|
||||
#include <SFML/Window/Win32/InputImpl.hpp>
|
||||
#include <windows.h>
|
||||
#include <SFML/System/Win32/WindowsHeader.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
@ -26,9 +26,9 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/JoystickImpl.hpp>
|
||||
#include <SFML/System/Win32/WindowsHeader.hpp>
|
||||
#include <SFML/System/Clock.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <regstr.h>
|
||||
#include <algorithm>
|
||||
|
@ -28,18 +28,9 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#ifdef _WIN32_WINDOWS
|
||||
#undef _WIN32_WINDOWS
|
||||
#endif
|
||||
#ifdef _WIN32_WINNT
|
||||
#undef _WIN32_WINNT
|
||||
#endif
|
||||
#define _WIN32_WINDOWS 0x0501
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#define DIRECTINPUT_VERSION 0x0800
|
||||
#include <SFML/Window/Joystick.hpp>
|
||||
#include <SFML/Window/JoystickImpl.hpp>
|
||||
#include <windows.h>
|
||||
#include <SFML/System/Win32/WindowsHeader.hpp>
|
||||
#include <mmsystem.h>
|
||||
#include <dinput.h>
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/VideoModeImpl.hpp>
|
||||
#include <windows.h>
|
||||
#include <SFML/System/Win32/WindowsHeader.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
|
@ -26,10 +26,7 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/Win32/VulkanImplWin32.hpp>
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <SFML/System/Win32/WindowsHeader.hpp>
|
||||
#define VK_USE_PLATFORM_WIN32_KHR
|
||||
#define VK_NO_PROTOTYPES
|
||||
#include <vulkan.h>
|
||||
|
@ -25,20 +25,9 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#ifdef _WIN32_WINDOWS
|
||||
#undef _WIN32_WINDOWS
|
||||
#endif
|
||||
#ifdef _WIN32_WINNT
|
||||
#undef _WIN32_WINNT
|
||||
#endif
|
||||
#ifdef WINVER
|
||||
#undef WINVER
|
||||
#endif
|
||||
#define _WIN32_WINDOWS 0x0501
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#define WINVER 0x0501
|
||||
#include <SFML/Window/Win32/WindowImplWin32.hpp>
|
||||
#include <SFML/Window/WindowStyle.hpp>
|
||||
#include <SFML/Window/JoystickImpl.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <SFML/System/Utf.hpp>
|
||||
// dbt.h is lowercase here, as a cross-compile on linux with mingw-w64
|
||||
@ -417,7 +406,7 @@ void WindowImplWin32::setMouseCursorGrabbed(bool grabbed)
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplWin32::setMouseCursor(const CursorImpl& cursor)
|
||||
{
|
||||
m_lastCursor = cursor.m_cursor;
|
||||
m_lastCursor = static_cast<HCURSOR>(cursor.m_cursor);
|
||||
SetCursor(m_cursorVisible ? m_lastCursor : nullptr);
|
||||
}
|
||||
|
||||
|
@ -30,8 +30,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/Event.hpp>
|
||||
#include <SFML/Window/WindowImpl.hpp>
|
||||
#include <SFML/System/Win32/WindowsHeader.hpp>
|
||||
#include <SFML/System/String.hpp>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
@ -27,6 +27,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/WindowImpl.hpp>
|
||||
#include <SFML/Window/Event.hpp>
|
||||
#include <SFML/Window/JoystickImpl.hpp>
|
||||
#include <SFML/Window/JoystickManager.hpp>
|
||||
#include <SFML/Window/SensorManager.hpp>
|
||||
#include <SFML/System/Sleep.hpp>
|
||||
@ -77,6 +78,12 @@ namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
struct WindowImpl::JoystickStatesImpl
|
||||
{
|
||||
JoystickState m_states[Joystick::Count]; //!< Previous state of the joysticks
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImpl* WindowImpl::create(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings)
|
||||
{
|
||||
@ -93,13 +100,14 @@ WindowImpl* WindowImpl::create(WindowHandle handle)
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImpl::WindowImpl() :
|
||||
m_joystickStatesImpl(new JoystickStatesImpl),
|
||||
m_joystickThreshold(0.1f)
|
||||
{
|
||||
// Get the initial joystick states
|
||||
JoystickManager::getInstance().update();
|
||||
for (unsigned int i = 0; i < Joystick::Count; ++i)
|
||||
{
|
||||
m_joystickStates[i] = JoystickManager::getInstance().getState(i);
|
||||
m_joystickStatesImpl->m_states[i] = JoystickManager::getInstance().getState(i);
|
||||
std::fill_n(m_previousAxes[i], static_cast<std::size_t>(Joystick::AxisCount), 0.f);
|
||||
}
|
||||
|
||||
@ -112,7 +120,7 @@ m_joystickThreshold(0.1f)
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImpl::~WindowImpl()
|
||||
{
|
||||
// Nothing to do
|
||||
delete m_joystickStatesImpl;
|
||||
}
|
||||
|
||||
|
||||
@ -179,11 +187,11 @@ void WindowImpl::processJoystickEvents()
|
||||
for (unsigned int i = 0; i < Joystick::Count; ++i)
|
||||
{
|
||||
// Copy the previous state of the joystick and get the new one
|
||||
JoystickState previousState = m_joystickStates[i];
|
||||
m_joystickStates[i] = JoystickManager::getInstance().getState(i);
|
||||
JoystickState previousState = m_joystickStatesImpl->m_states[i];
|
||||
m_joystickStatesImpl->m_states[i] = JoystickManager::getInstance().getState(i);
|
||||
|
||||
// Connection state
|
||||
bool connected = m_joystickStates[i].connected;
|
||||
bool connected = m_joystickStatesImpl->m_states[i].connected;
|
||||
if (previousState.connected ^ connected)
|
||||
{
|
||||
Event event;
|
||||
@ -207,7 +215,7 @@ void WindowImpl::processJoystickEvents()
|
||||
{
|
||||
auto axis = static_cast<Joystick::Axis>(j);
|
||||
float prevPos = m_previousAxes[i][axis];
|
||||
float currPos = m_joystickStates[i].axes[axis];
|
||||
float currPos = m_joystickStatesImpl->m_states[i].axes[axis];
|
||||
if (std::abs(currPos - prevPos) >= m_joystickThreshold)
|
||||
{
|
||||
Event event;
|
||||
@ -226,7 +234,7 @@ void WindowImpl::processJoystickEvents()
|
||||
for (unsigned int j = 0; j < caps.buttonCount; ++j)
|
||||
{
|
||||
bool prevPressed = previousState.buttons[j];
|
||||
bool currPressed = m_joystickStates[i].buttons[j];
|
||||
bool currPressed = m_joystickStatesImpl->m_states[i].buttons[j];
|
||||
|
||||
if (prevPressed ^ currPressed)
|
||||
{
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include <SFML/Window/CursorImpl.hpp>
|
||||
#include <SFML/Window/Event.hpp>
|
||||
#include <SFML/Window/Joystick.hpp>
|
||||
#include <SFML/Window/JoystickImpl.hpp>
|
||||
#include <SFML/Window/Sensor.hpp>
|
||||
#include <SFML/Window/SensorImpl.hpp>
|
||||
#include <SFML/Window/VideoMode.hpp>
|
||||
@ -266,6 +265,7 @@ protected:
|
||||
virtual void processEvents() = 0;
|
||||
|
||||
private:
|
||||
struct JoystickStatesImpl;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Read the joysticks state and generate the appropriate events
|
||||
@ -282,11 +282,11 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
std::queue<Event> m_events; //!< Queue of available events
|
||||
JoystickState m_joystickStates[Joystick::Count]; //!< Previous state of the joysticks
|
||||
Vector3f m_sensorValue[Sensor::Count]; //!< Previous value of the sensors
|
||||
float m_joystickThreshold; //!< Joystick threshold (minimum motion for "move" event to be generated)
|
||||
float m_previousAxes[Joystick::Count][Joystick::AxisCount]; //!< Position of each axis last time a move event triggered, in range [-100, 100]
|
||||
std::queue<Event> m_events; //!< Queue of available events
|
||||
JoystickStatesImpl* m_joystickStatesImpl; //!< Previous state of the joysticks (PImpl)
|
||||
Vector3f m_sensorValue[Sensor::Count]; //!< Previous value of the sensors
|
||||
float m_joystickThreshold; //!< Joystick threshold (minimum motion for "move" event to be generated)
|
||||
float m_previousAxes[Joystick::Count][Joystick::AxisCount]; //!< Position of each axis last time a move event triggered, in range [-100, 100]
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
Loading…
Reference in New Issue
Block a user