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