mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 10:05:44 -04:00
Use elapsed game time instead of elapsed system time for automatic periodic block place/delete when mouse is held down
This commit is contained in:
parent
9e561e645f
commit
0355fdf863
21
src/Input.c
21
src/Input.c
@ -28,7 +28,7 @@
|
|||||||
struct _InputState Input;
|
struct _InputState Input;
|
||||||
static cc_bool input_buttonsDown[3];
|
static cc_bool input_buttonsDown[3];
|
||||||
static int input_pickingId = -1;
|
static int input_pickingId = -1;
|
||||||
static TimeMS input_lastClick;
|
static double input_lastClick;
|
||||||
static float input_fovIndex = -1.0f;
|
static float input_fovIndex = -1.0f;
|
||||||
#ifdef CC_BUILD_WEB
|
#ifdef CC_BUILD_WEB
|
||||||
static cc_bool suppressEscape;
|
static cc_bool suppressEscape;
|
||||||
@ -48,6 +48,7 @@ static struct TouchPointer {
|
|||||||
int begX, begY;
|
int begX, begY;
|
||||||
TimeMS start;
|
TimeMS start;
|
||||||
} touches[INPUT_MAX_POINTERS];
|
} touches[INPUT_MAX_POINTERS];
|
||||||
|
|
||||||
int Pointers_Count;
|
int Pointers_Count;
|
||||||
int Input_TapMode = INPUT_MODE_PLACE;
|
int Input_TapMode = INPUT_MODE_PLACE;
|
||||||
int Input_HoldMode = INPUT_MODE_DELETE;
|
int Input_HoldMode = INPUT_MODE_DELETE;
|
||||||
@ -123,7 +124,7 @@ void Input_AddTouch(long id, int x, int y) {
|
|||||||
/* Also set last click time, otherwise quickly tapping */
|
/* Also set last click time, otherwise quickly tapping */
|
||||||
/* sometimes triggers a 'delete' in InputHandler_Tick, */
|
/* sometimes triggers a 'delete' in InputHandler_Tick, */
|
||||||
/* and then another 'delete' in CheckBlockTap. */
|
/* and then another 'delete' in CheckBlockTap. */
|
||||||
input_lastClick = touches[i].start;
|
input_lastClick = Game.Time;
|
||||||
|
|
||||||
if (i == Pointers_Count) Pointers_Count++;
|
if (i == Pointers_Count) Pointers_Count++;
|
||||||
Pointer_SetPosition(i, x, y);
|
Pointer_SetPosition(i, x, y);
|
||||||
@ -624,7 +625,7 @@ static void MouseStateChanged(int button, cc_bool pressed) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void MouseStatePress(int button) {
|
static void MouseStatePress(int button) {
|
||||||
input_lastClick = DateTime_CurrentUTC_MS();
|
input_lastClick = Game.Time;
|
||||||
input_pickingId = -1;
|
input_pickingId = -1;
|
||||||
MouseStateChanged(button, true);
|
MouseStateChanged(button, true);
|
||||||
}
|
}
|
||||||
@ -635,7 +636,7 @@ static void MouseStateRelease(int button) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler_OnScreensChanged(void) {
|
void InputHandler_OnScreensChanged(void) {
|
||||||
input_lastClick = DateTime_CurrentUTC_MS();
|
input_lastClick = Game.Time;
|
||||||
input_pickingId = -1;
|
input_pickingId = -1;
|
||||||
if (!Gui.InputGrab) return;
|
if (!Gui.InputGrab) return;
|
||||||
|
|
||||||
@ -804,15 +805,17 @@ void InputHandler_PickBlock(void) {
|
|||||||
|
|
||||||
void InputHandler_Tick(void) {
|
void InputHandler_Tick(void) {
|
||||||
cc_bool left, middle, right;
|
cc_bool left, middle, right;
|
||||||
TimeMS now;
|
double now;
|
||||||
int delta;
|
int delta;
|
||||||
|
|
||||||
if (Gui.InputGrab) return;
|
if (Gui.InputGrab) return;
|
||||||
|
now = Game.Time;
|
||||||
|
delta = now - input_lastClick;
|
||||||
|
|
||||||
|
if (delta < 0.2495) return; /* 4 times per second */
|
||||||
now = DateTime_CurrentUTC_MS();
|
/* NOTE: 0.2495 is used instead of 0.25 to produce delta time */
|
||||||
delta = (int)(now - input_lastClick);
|
/* values slightly closer to the old code which measured */
|
||||||
if (delta < 250) return; /* 4 times per second */
|
/* elapsed time using DateTime_CurrentUTC_MS() instead */
|
||||||
input_lastClick = now;
|
input_lastClick = now;
|
||||||
|
|
||||||
left = KeyBind_IsPressed(KEYBIND_DELETE_BLOCK);
|
left = KeyBind_IsPressed(KEYBIND_DELETE_BLOCK);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user