Browse Source

Removed some SDL access from non-SDL code

Ivan Savenko 2 years ago
parent
commit
b1821d4442

+ 2 - 8
client/CServerHandler.cpp

@@ -60,8 +60,6 @@
 #include <windows.h>
 #endif
 
-#include <SDL_events.h>
-
 template<typename T> class CApplyOnLobby;
 
 const std::string CServerHandler::localhostAddress{"127.0.0.1"};
@@ -655,14 +653,10 @@ void CServerHandler::endGameplay(bool closeConnection, bool restart)
 
 void CServerHandler::startCampaignScenario(std::shared_ptr<CCampaignState> cs)
 {
-	SDL_Event event;
-	event.type = SDL_USEREVENT;
-	event.user.code = static_cast<int32_t>(EUserEvent::CAMPAIGN_START_SCENARIO);
 	if(cs)
-		event.user.data1 = CMemorySerializer::deepCopy(*cs.get()).release();
+		GH.pushUserEvent(EUserEvent::CAMPAIGN_START_SCENARIO, CMemorySerializer::deepCopy(*cs.get()).release());
 	else
-		event.user.data1 = CMemorySerializer::deepCopy(*si->campState.get()).release();
-	SDL_PushEvent(&event);
+		GH.pushUserEvent(EUserEvent::CAMPAIGN_START_SCENARIO, CMemorySerializer::deepCopy(*si->campState.get()).release());
 }
 
 void CServerHandler::showServerError(std::string txt)

+ 6 - 0
client/gui/CGuiHandler.cpp

@@ -826,10 +826,16 @@ bool CGuiHandler::amIGuiThread()
 }
 
 void CGuiHandler::pushUserEvent(EUserEvent usercode)
+{
+	pushUserEvent(usercode, nullptr);
+}
+
+void CGuiHandler::pushUserEvent(EUserEvent usercode, void * userdata)
 {
 	SDL_Event event;
 	event.type = SDL_USEREVENT;
 	event.user.code = static_cast<int32_t>(usercode);
+	event.user.data1 = userdata;
 	SDL_PushEvent(&event);
 }
 

+ 1 - 0
client/gui/CGuiHandler.h

@@ -177,6 +177,7 @@ public:
 	static bool isArrowKey(SDL_Keycode key);
 	static bool amIGuiThread();
 	static void pushUserEvent(EUserEvent usercode);
+	static void pushUserEvent(EUserEvent usercode, void * userdata);
 
 	CondSh<bool> * terminate_cond; // confirm termination
 };

+ 0 - 19
client/gui/CursorHandler.cpp

@@ -21,13 +21,6 @@
 
 #include "../../lib/CConfigHandler.h"
 
-#include <SDL_render.h>
-#include <SDL_events.h>
-
-#ifdef VCMI_APPLE
-#include <dispatch/dispatch.h>
-#endif
-
 std::unique_ptr<ICursor> CursorHandler::createCursor()
 {
 	if (settings["video"]["cursor"].String() == "auto")
@@ -254,18 +247,6 @@ std::shared_ptr<IImage> CursorHandler::getCurrentImage()
 	return cursors[static_cast<size_t>(type)]->getImage(frame);
 }
 
-void CursorHandler::centerCursor()
-{
-	Point screenSize {screen->w, screen->h};
-	pos = screenSize / 2 - getPivotOffset();
-
-	SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
-	GH.moveCursorToPosition(pos);
-	SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
-
-	cursor->setCursorPosition(pos);
-}
-
 void CursorHandler::updateSpellcastCursor()
 {
 	static const float frameDisplayDuration = 0.1f; // H3 uses 100 ms per frame

+ 0 - 3
client/gui/CursorHandler.h

@@ -178,7 +178,4 @@ public:
 
 	/// change cursor's positions to (x, y)
 	void cursorMove(const int & x, const int & y);
-	/// Move cursor to screen center
-	void centerCursor();
-
 };