mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-17 01:32:21 +02:00
Apply SonarCloud suggestions
This commit is contained in:
@ -58,7 +58,7 @@ void InputSourceGameController::openGameController(int index)
|
|||||||
logGlobal->error("Fail to open game controller %d!", index);
|
logGlobal->error("Fail to open game controller %d!", index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GameControllerPtr controllerPtr(controller, gameControllerDeleter);
|
GameControllerPtr controllerPtr(controller, &gameControllerDeleter);
|
||||||
|
|
||||||
// Need to save joystick index for event. Joystick index may not be equal to index sometimes.
|
// Need to save joystick index for event. Joystick index may not be equal to index sometimes.
|
||||||
int joystickIndex = getJoystickIndex(controllerPtr.get());
|
int joystickIndex = getJoystickIndex(controllerPtr.get());
|
||||||
@ -74,7 +74,7 @@ void InputSourceGameController::openGameController(int index)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gameControllerMap.emplace(joystickIndex, std::move(controllerPtr));
|
gameControllerMap.try_emplace(joystickIndex, std::move(controllerPtr));
|
||||||
}
|
}
|
||||||
|
|
||||||
int InputSourceGameController::getJoystickIndex(SDL_GameController * controller)
|
int InputSourceGameController::getJoystickIndex(SDL_GameController * controller)
|
||||||
@ -86,7 +86,7 @@ int InputSourceGameController::getJoystickIndex(SDL_GameController * controller)
|
|||||||
SDL_JoystickID instanceID = SDL_JoystickInstanceID(joystick);
|
SDL_JoystickID instanceID = SDL_JoystickInstanceID(joystick);
|
||||||
if(instanceID < 0)
|
if(instanceID < 0)
|
||||||
return -1;
|
return -1;
|
||||||
return (int)instanceID;
|
return instanceID;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputSourceGameController::handleEventDeviceAdded(const SDL_ControllerDeviceEvent & device)
|
void InputSourceGameController::handleEventDeviceAdded(const SDL_ControllerDeviceEvent & device)
|
||||||
@ -191,7 +191,7 @@ void InputSourceGameController::tryToConvertCursor()
|
|||||||
if(CCS->curh->getShowType() == Cursor::ShowType::HARDWARE)
|
if(CCS->curh->getShowType() == Cursor::ShowType::HARDWARE)
|
||||||
{
|
{
|
||||||
const Point & cursorPosition = GH.getCursorPosition();
|
const Point & cursorPosition = GH.getCursorPosition();
|
||||||
CCS->curh->ChangeCursor(Cursor::ShowType::SOFTWARE);
|
CCS->curh->changeCursor(Cursor::ShowType::SOFTWARE);
|
||||||
CCS->curh->cursorMove(cursorPosition.x, cursorPosition.y);
|
CCS->curh->cursorMove(cursorPosition.x, cursorPosition.y);
|
||||||
GH.input().setCursorPosition(cursorPosition);
|
GH.input().setCursorPosition(cursorPosition);
|
||||||
}
|
}
|
||||||
@ -243,7 +243,7 @@ void InputSourceGameController::handleUpdate()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t deltaTime = std::chrono::duration_cast<std::chrono::seconds>(nowMs - lastCheckTime).count();
|
int32_t deltaTime = std::chrono::duration_cast<std::chrono::milliseconds>(nowMs - lastCheckTime).count();
|
||||||
handleCursorUpdate(deltaTime);
|
handleCursorUpdate(deltaTime);
|
||||||
handleScrollUpdate(deltaTime);
|
handleScrollUpdate(deltaTime);
|
||||||
lastCheckTime = nowMs;
|
lastCheckTime = nowMs;
|
||||||
@ -251,15 +251,17 @@ void InputSourceGameController::handleUpdate()
|
|||||||
|
|
||||||
void InputSourceGameController::handleCursorUpdate(int32_t deltaTimeMs)
|
void InputSourceGameController::handleCursorUpdate(int32_t deltaTimeMs)
|
||||||
{
|
{
|
||||||
|
float deltaTimeSeconds = static_cast<float>(deltaTimeMs) / 1000;
|
||||||
|
|
||||||
if(cursorAxisValueX == 0)
|
if(cursorAxisValueX == 0)
|
||||||
cursorPlanDisX = 0;
|
cursorPlanDisX = 0;
|
||||||
else
|
else
|
||||||
cursorPlanDisX += ((float)deltaTimeMs / 1000) * ((float)cursorAxisValueX / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
cursorPlanDisX += deltaTimeSeconds * AXIS_MOVE_SPEED * cursorAxisValueX / AXIS_MAX_ZOOM;
|
||||||
|
|
||||||
if(cursorAxisValueY == 0)
|
if(cursorAxisValueY == 0)
|
||||||
cursorPlanDisY = 0;
|
cursorPlanDisY = 0;
|
||||||
else
|
else
|
||||||
cursorPlanDisY += ((float)deltaTimeMs / 1000) * ((float)cursorAxisValueY / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
cursorPlanDisY += deltaTimeSeconds * AXIS_MOVE_SPEED * cursorAxisValueY / AXIS_MAX_ZOOM;
|
||||||
|
|
||||||
int moveDisX = getMoveDis(cursorPlanDisX);
|
int moveDisX = getMoveDis(cursorPlanDisX);
|
||||||
int moveDisY = getMoveDis(cursorPlanDisY);
|
int moveDisY = getMoveDis(cursorPlanDisY);
|
||||||
@ -287,8 +289,9 @@ void InputSourceGameController::handleScrollUpdate(int32_t deltaTimeMs)
|
|||||||
scrollPlanDisX = scrollPlanDisY = 0;
|
scrollPlanDisX = scrollPlanDisY = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
scrollPlanDisX += ((float)deltaTimeMs / 1000) * ((float)scrollAxisValueX / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
float deltaTimeSeconds = static_cast<float>(deltaTimeMs) / 1000;
|
||||||
scrollPlanDisY += ((float)deltaTimeMs / 1000) * ((float)scrollAxisValueY / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
scrollPlanDisX += deltaTimeSeconds * AXIS_MOVE_SPEED * scrollAxisValueX / AXIS_MAX_ZOOM;
|
||||||
|
scrollPlanDisY += deltaTimeSeconds * AXIS_MOVE_SPEED * scrollAxisValueY / AXIS_MAX_ZOOM;
|
||||||
int moveDisX = getMoveDis(scrollPlanDisX);
|
int moveDisX = getMoveDis(scrollPlanDisX);
|
||||||
int moveDisY = getMoveDis(scrollPlanDisY);
|
int moveDisY = getMoveDis(scrollPlanDisY);
|
||||||
if(moveDisX != 0 || moveDisY != 0)
|
if(moveDisX != 0 || moveDisY != 0)
|
||||||
|
@ -291,17 +291,17 @@ void CursorHandler::show()
|
|||||||
cursor->setVisible(true);
|
cursor->setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Cursor::ShowType CursorHandler::getShowType()
|
Cursor::ShowType CursorHandler::getShowType() const
|
||||||
{
|
{
|
||||||
return showType;
|
return showType;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CursorHandler::ChangeCursor(Cursor::ShowType showType)
|
void CursorHandler::changeCursor(Cursor::ShowType newShowType)
|
||||||
{
|
{
|
||||||
if(this->showType == showType)
|
if(newShowType == showType)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch(showType)
|
switch(newShowType)
|
||||||
{
|
{
|
||||||
case Cursor::ShowType::SOFTWARE:
|
case Cursor::ShowType::SOFTWARE:
|
||||||
cursor.reset(new CursorSoftware());
|
cursor.reset(new CursorSoftware());
|
||||||
|
@ -186,6 +186,6 @@ public:
|
|||||||
/// change cursor's positions to (x, y)
|
/// change cursor's positions to (x, y)
|
||||||
void cursorMove(const int & x, const int & y);
|
void cursorMove(const int & x, const int & y);
|
||||||
|
|
||||||
Cursor::ShowType getShowType();
|
Cursor::ShowType getShowType() const;
|
||||||
void ChangeCursor(Cursor::ShowType showType);
|
void changeCursor(Cursor::ShowType showType);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user