mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-17 01:32:21 +02:00
Fix time handling
This commit is contained in:
@ -26,7 +26,6 @@ void InputSourceGameController::gameControllerDeleter(SDL_GameController * gameC
|
|||||||
}
|
}
|
||||||
|
|
||||||
InputSourceGameController::InputSourceGameController():
|
InputSourceGameController::InputSourceGameController():
|
||||||
lastCheckTime(0),
|
|
||||||
cursorAxisValueX(0),
|
cursorAxisValueX(0),
|
||||||
cursorAxisValueY(0),
|
cursorAxisValueY(0),
|
||||||
cursorPlanDisX(0.0),
|
cursorPlanDisX(0.0),
|
||||||
@ -236,31 +235,31 @@ int InputSourceGameController::getMoveDis(float planDis)
|
|||||||
|
|
||||||
void InputSourceGameController::handleUpdate()
|
void InputSourceGameController::handleUpdate()
|
||||||
{
|
{
|
||||||
auto now = std::chrono::high_resolution_clock::now();
|
std::chrono::steady_clock::time_point nowMs = std::chrono::steady_clock::now();
|
||||||
auto nowMs = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
|
|
||||||
if(lastCheckTime == 0)
|
if(lastCheckTime == std::chrono::steady_clock::time_point())
|
||||||
{
|
{
|
||||||
lastCheckTime = nowMs;
|
lastCheckTime = nowMs;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long long deltaTime = nowMs - lastCheckTime;
|
int32_t deltaTime = std::chrono::duration_cast<std::chrono::seconds>(nowMs - lastCheckTime).count();
|
||||||
handleCursorUpdate(deltaTime);
|
handleCursorUpdate(deltaTime);
|
||||||
handleScrollUpdate(deltaTime);
|
handleScrollUpdate(deltaTime);
|
||||||
lastCheckTime = nowMs;
|
lastCheckTime = nowMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputSourceGameController::handleCursorUpdate(long long deltaTime)
|
void InputSourceGameController::handleCursorUpdate(int32_t deltaTimeMs)
|
||||||
{
|
{
|
||||||
if(cursorAxisValueX == 0)
|
if(cursorAxisValueX == 0)
|
||||||
cursorPlanDisX = 0;
|
cursorPlanDisX = 0;
|
||||||
else
|
else
|
||||||
cursorPlanDisX += ((float)deltaTime / 1000) * ((float)cursorAxisValueX / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
cursorPlanDisX += ((float)deltaTimeMs / 1000) * ((float)cursorAxisValueX / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
||||||
|
|
||||||
if(cursorAxisValueY == 0)
|
if(cursorAxisValueY == 0)
|
||||||
cursorPlanDisY = 0;
|
cursorPlanDisY = 0;
|
||||||
else
|
else
|
||||||
cursorPlanDisY += ((float)deltaTime / 1000) * ((float)cursorAxisValueY / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
cursorPlanDisY += ((float)deltaTimeMs / 1000) * ((float)cursorAxisValueY / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
||||||
|
|
||||||
int moveDisX = getMoveDis(cursorPlanDisX);
|
int moveDisX = getMoveDis(cursorPlanDisX);
|
||||||
int moveDisY = getMoveDis(cursorPlanDisY);
|
int moveDisY = getMoveDis(cursorPlanDisY);
|
||||||
@ -269,7 +268,7 @@ void InputSourceGameController::handleCursorUpdate(long long deltaTime)
|
|||||||
doCursorMove(moveDisX, moveDisY);
|
doCursorMove(moveDisX, moveDisY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputSourceGameController::handleScrollUpdate(long long deltaTime)
|
void InputSourceGameController::handleScrollUpdate(int32_t deltaTimeMs)
|
||||||
{
|
{
|
||||||
if(!scrollAxisMoved && isScrollAxisReleased())
|
if(!scrollAxisMoved && isScrollAxisReleased())
|
||||||
{
|
{
|
||||||
@ -288,8 +287,8 @@ void InputSourceGameController::handleScrollUpdate(long long deltaTime)
|
|||||||
scrollPlanDisX = scrollPlanDisY = 0;
|
scrollPlanDisX = scrollPlanDisY = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
scrollPlanDisX += ((float)deltaTime / 1000) * ((float)scrollAxisValueX / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
scrollPlanDisX += ((float)deltaTimeMs / 1000) * ((float)scrollAxisValueX / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
||||||
scrollPlanDisY += ((float)deltaTime / 1000) * ((float)scrollAxisValueY / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
scrollPlanDisY += ((float)deltaTimeMs / 1000) * ((float)scrollAxisValueY / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
||||||
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)
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
constexpr int AXIS_DEAD_ZOOM = 6000;
|
constexpr int AXIS_DEAD_ZOOM = 6000;
|
||||||
constexpr int AXIS_MAX_ZOOM = 32000;
|
constexpr int AXIS_MAX_ZOOM = 32000;
|
||||||
constexpr int AXIS_MOVE_SPEED = 500;
|
constexpr int AXIS_MOVE_SPEED = 500;
|
||||||
constexpr int AXIS_CURSOR_MOVE_INTERVAL = 1000;
|
|
||||||
constexpr int TRIGGER_PRESS_THRESHOLD = 8000;
|
constexpr int TRIGGER_PRESS_THRESHOLD = 8000;
|
||||||
|
|
||||||
enum class AxisType
|
enum class AxisType
|
||||||
@ -38,7 +37,7 @@ class InputSourceGameController
|
|||||||
std::map<int, GameControllerPtr> gameControllerMap;
|
std::map<int, GameControllerPtr> gameControllerMap;
|
||||||
std::set<SDL_GameControllerAxis> pressedAxes;
|
std::set<SDL_GameControllerAxis> pressedAxes;
|
||||||
|
|
||||||
long long lastCheckTime;
|
std::chrono::steady_clock::time_point lastCheckTime;
|
||||||
int cursorAxisValueX;
|
int cursorAxisValueX;
|
||||||
int cursorAxisValueY;
|
int cursorAxisValueY;
|
||||||
float cursorPlanDisX;
|
float cursorPlanDisX;
|
||||||
@ -59,8 +58,8 @@ class InputSourceGameController
|
|||||||
void tryToConvertCursor();
|
void tryToConvertCursor();
|
||||||
void doCursorMove(int deltaX, int deltaY);
|
void doCursorMove(int deltaX, int deltaY);
|
||||||
int getMoveDis(float planDis);
|
int getMoveDis(float planDis);
|
||||||
void handleCursorUpdate(long long deltaTime);
|
void handleCursorUpdate(int32_t deltaTimeMs);
|
||||||
void handleScrollUpdate(long long deltaTime);
|
void handleScrollUpdate(int32_t deltaTimeMs);
|
||||||
bool isScrollAxisReleased();
|
bool isScrollAxisReleased();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -23,7 +23,6 @@ class CursorHardware : public ICursor
|
|||||||
std::shared_ptr<IImage> cursorImage;
|
std::shared_ptr<IImage> cursorImage;
|
||||||
|
|
||||||
SDL_Cursor * cursor;
|
SDL_Cursor * cursor;
|
||||||
Point pos;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CursorHardware();
|
CursorHardware();
|
||||||
|
Reference in New Issue
Block a user