Skip to content

Commit

Permalink
Bump default sensitivity to 50 on windows to compensate for raw mouse…
Browse files Browse the repository at this point in the history
… changes
  • Loading branch information
UnknownShadow200 committed May 17, 2019
1 parent 4ac9498 commit 065a32a
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 27 deletions.
4 changes: 4 additions & 0 deletions src/Camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ void Camera_Init(void) {
Event_RegisterMouseMove(&MouseEvents.RawMoved, NULL, Camera_RawMouseMovedHandler);
Event_RegisterVoid(&UserEvents.HackPermissionsChanged, NULL, Camera_CheckThirdPerson);

#ifdef CC_BUILD_WIN
Camera.Sensitivity = Options_GetInt(OPT_SENSITIVITY, 1, 100, 50);
#else
Camera.Sensitivity = Options_GetInt(OPT_SENSITIVITY, 1, 100, 30);
#endif
Camera.Clipping = Options_GetBool(OPT_CAMERA_CLIPPING, true);
Camera.Invert = Options_GetBool(OPT_INVERT_MOUSE, false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Formats.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ static ReturnCode Nbt_ReadString(struct Stream* stream, String* str) {
if (len > Array_Elems(buffer)) return CW_ERR_STRING_LEN;
if ((res = Stream_Read(stream, buffer, len))) return res;

Convert_DecodeUtf8(str, buffer, len);
String_AppendUtf8(str, buffer, len);
return 0;
}

Expand Down
7 changes: 2 additions & 5 deletions src/LScreens.c
Original file line number Diff line number Diff line change
Expand Up @@ -1429,11 +1429,8 @@ CC_NOINLINE static void UpdatesScreen_FormatTime(String* str, char* type, int de
String_Append(str, ' ');
String_AppendConst(str, type);

if (delta > 1) {
String_AppendConst(str, "s ago");
} else {
String_AppendConst(str, " ago");
}
if (delta > 1) String_Append(str, 's');
String_AppendConst(str, " ago");
}

static void UpdatesScreen_Format(struct LLabel* lbl, const char* prefix, TimeMS time) {
Expand Down
4 changes: 4 additions & 0 deletions src/Menus.c
Original file line number Diff line number Diff line change
Expand Up @@ -2804,7 +2804,11 @@ struct Screen* MiscOptionsScreen_MakeInstance(void) {
validators[2] = MenuInputValidator_Int(0, 100);
defaultValues[2] = "0";
validators[7] = MenuInputValidator_Int(1, 200);
#ifdef CC_BUILD_WIN
defaultValues[7] = "50";
#else
defaultValues[7] = "30";
#endif

return MenuOptionsScreen_MakeInstance(widgets, Array_Elems(widgets), buttons,
MiscOptionsScreen_ContextRecreated, validators, defaultValues, NULL, 0);
Expand Down
46 changes: 36 additions & 10 deletions src/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#endif

#ifdef UNICODE
#define Platform_DecodeString(dst, src, len) Convert_DecodeUtf16(dst, src, (len) * 2)
#define Platform_DecodeString(dst, src, len) String_AppendUtf16(dst, src, (len) * 2)
#else
#define Platform_DecodeString(dst, src, len) Convert_DecodeAscii(dst, src, len)
#endif
Expand Down Expand Up @@ -525,7 +525,7 @@ ReturnCode Directory_Enum(const String* dirPath, void* obj, Directory_EnumCallba
if (src[0] == '.' && src[1] == '.' && src[2] == '\0') continue;

len = String_CalcLen(src, UInt16_MaxValue);
Convert_DecodeUtf8(&path, src, len);
String_AppendUtf8(&path, src, len);

/* TODO: fallback to stat when this fails */
if (entry->d_type == DT_DIR) {
Expand Down Expand Up @@ -1623,7 +1623,7 @@ ReturnCode Process_GetExePath(String* path) {
if (_NSGetExecutablePath(str, &len)) return ERR_INVALID_ARGUMENT;

len = String_CalcLen(str, 600);
Convert_DecodeUtf8(path, str, len);
String_AppendUtf8(path, str, len);
return 0;
}
#elif defined CC_BUILD_UNIX
Expand All @@ -1638,7 +1638,7 @@ ReturnCode Process_GetExePath(String* path) {
int len = readlink("/proc/self/exe", str, 600);
if (len == -1) return errno;

Convert_DecodeUtf8(path, str, len);
String_AppendUtf8(path, str, len);
return 0;
}
#elif defined CC_BUILD_FREEBSD
Expand All @@ -1649,7 +1649,7 @@ ReturnCode Process_GetExePath(String* path) {
if (sysctl(mib, 4, str, &size, NULL, 0) == -1) return errno;

size = String_CalcLen(str, 600);
Convert_DecodeUtf8(path, str, size);
String_AppendUtf8(path, str, size);
return 0;
}
#elif defined CC_BUILD_OPENBSD
Expand All @@ -1675,7 +1675,7 @@ ReturnCode Process_GetExePath(String* path) {
}

size = String_CalcLen(str, 600);
Convert_DecodeUtf8(path, str, size);
String_AppendUtf8(path, str, size);
return 0;
}
#elif defined CC_BUILD_NETBSD
Expand All @@ -1686,7 +1686,7 @@ ReturnCode Process_GetExePath(String* path) {
if (sysctl(mib, 4, str, &size, NULL, 0) == -1) return errno;

size = String_CalcLen(str, 600);
Convert_DecodeUtf8(path, str, size);
String_AppendUtf8(path, str, size);
return 0;
}
#elif defined CC_BUILD_SOLARIS
Expand All @@ -1695,7 +1695,7 @@ ReturnCode Process_GetExePath(String* path) {
int len = readlink("/proc/self/path/a.out", str, 600);
if (len == -1) return errno;

Convert_DecodeUtf8(path, str, len);
String_AppendUtf8(path, str, len);
return 0;
}
#endif
Expand Down Expand Up @@ -1726,12 +1726,22 @@ int Platform_ConvertString(void* data, const String* src) {
if (src->length > FILENAME_SIZE) Logger_Abort("String too long to expand");

for (i = 0; i < src->length; i++) {
*dst = Convert_CP437ToUnicode(src->buffer[i]); dst++;
*dst++ = Convert_CP437ToUnicode(src->buffer[i]);
}
*dst = '\0';
return src->length * 2;
}

int Platform_ConvertUniString(void* data, const UniString* src) {
TCHAR* dst = data;
int i;
if (src->length > FILENAME_SIZE) Logger_Abort("String too long to expand");

for (i = 0; i < src->length; i++) { *dst++ = src->buffer[i]; }
*dst = '\0';
return src->length * 2;
}

static void Platform_InitStopwatch(void) {
LARGE_INTEGER freq;
sw_highRes = QueryPerformanceFrequency(&freq);
Expand Down Expand Up @@ -1870,6 +1880,22 @@ int Platform_ConvertString(void* data, const String* src) {
return len;
}

int Platform_ConvertUniString(void* data, const UniString* src) {
uint8_t* dst = data;
uint8_t* cur;

int i, len = 0;
if (src->length > FILENAME_SIZE) Logger_Abort("String too long to expand");

for (i = 0; i < src->length; i++) {
cur = dst + len;
len += Convert_UnicodeToUtf8(src->buffer[i], cur);
}
dst[len] = '\0';
return len;
}


static void Platform_InitCommon(void) {
signal(SIGCHLD, SIG_IGN);
/* So writing to closed socket doesn't raise SIGPIPE */
Expand Down Expand Up @@ -1919,7 +1945,7 @@ bool Platform_DescribeError(ReturnCode res, String* dst) {
if (len == -1) return false;

len = String_CalcLen(chars, 600);
Convert_DecodeUtf8(dst, chars, len);
String_AppendUtf8(dst, chars, len);
return true;
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions src/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ extern const ReturnCode ReturnCode_SocketWouldBlock;
/* NOTE: Only useful for platform specific function calls - do NOT try to interpret the data. */
/* Returns the number of bytes written, excluding trailing NULL terminator. */
CC_API int Platform_ConvertString(void* data, const String* src);
/* Encodes a unicode string in platform specific format. (e.g. unicode on windows, UTF8 on linux) */
/* NOTE: Only useful for platform specific function calls - do NOT try to interpret the data. */
/* Returns the number of bytes written, excluding trailing NULL terminator. */
CC_API int Platform_ConvertUniString(void* data, const UniString* src);

/* Initalises the platform specific state. */
void Platform_Init(void);
/* Frees the platform specific state. */
Expand Down
26 changes: 24 additions & 2 deletions src/String.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,25 @@ void String_AppendColorless(String* str, const String* src) {
}


void UniString_Append(UniString* str, Codepoint c) {
if (str->length == str->capacity) return;
str->buffer[str->length++] = c;
}

void UniString_AppendConst(UniString* str, const char* src) {
for (; *src; src++) {
UniString_Append(str, Convert_CP437ToUnicode(*src));
}
}

void UniString_AppendString(UniString* str, const String* src) {
int i;
for (i = 0; i < src->length; i++) {
UniString_Append(str, Convert_CP437ToUnicode(src->buffer[i]));
}
}


int String_IndexOfAt(const String* str, int offset, char c) {
int i;
for (i = offset; i < str->length; i++) {
Expand Down Expand Up @@ -572,15 +591,15 @@ int Convert_UnicodeToUtf8(Codepoint cp, uint8_t* data) {
}
}

void Convert_DecodeUtf16(String* value, const Codepoint* chars, int numBytes) {
void String_AppendUtf16(String* value, const Codepoint* chars, int numBytes) {
int i; char c;

for (i = 0; i < (numBytes >> 1); i++) {
if (Convert_TryUnicodeToCP437(chars[i], &c)) String_Append(value, c);
}
}

void Convert_DecodeUtf8(String* value, const uint8_t* chars, int numBytes) {
void String_AppendUtf8(String* value, const uint8_t* chars, int numBytes) {
int len; Codepoint cp; char c;

for (; numBytes > 0; numBytes -= len) {
Expand All @@ -592,6 +611,9 @@ void Convert_DecodeUtf8(String* value, const uint8_t* chars, int numBytes) {
}
}

// TODO: String_AppendUtf8
// TODO: Remove DecodeAscii, it's a lie
// TODO: Typedef uint8_t Key; typedef uint8_T MouseButton;
void Convert_DecodeAscii(String* value, const uint8_t* chars, int numBytes) {
int i; char c;

Expand Down
19 changes: 16 additions & 3 deletions src/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ typedef struct String_ {
uint16_t capacity; /* Max number of characters */
} String;

typedef struct UniString_ {
Codepoint* buffer;
uint16_t length, capacity;
} UniString;

/* Constant string that points to NULL and has 0 length. */
/* NOTE: Do NOT modify the contents of this string! */
extern const String String_Empty;
Expand Down Expand Up @@ -85,7 +90,7 @@ CC_API int String_MakeUInt32(uint32_t num, char* digits);

/* Attempts to append a character. */
/* Does nothing if str->length == str->capcity. */
void String_Append(String* str, char c);
CC_API void String_Append(String* str, char c);
/* Attempts to append "true" if value is non-zero, "false" otherwise. */
CC_API void String_AppendBool(String* str, bool value);
/* Attempts to append the digits of an integer (and -sign if negative). */
Expand All @@ -111,6 +116,14 @@ CC_API void String_AppendColorless(String* str, const String* src);
/* Attempts to append the two hex digits of a byte. */
CC_API void String_AppendHex(String* str, uint8_t value);

/* Attempts to append a character. */
/* Does nothing if str->length == str->capcity. */
CC_API void UniString_Append(UniString* str, Codepoint c);
/* Attempts to append characters. src MUST be null-terminated. */
CC_API void UniString_AppendConst(UniString* str, const char* src);
/* Attempts to append characters of a string. */
CC_API void UniString_AppendString(UniString* str, const String* src);

/* Returns first index of the given character in the given string, -1 if not found. */
#define String_IndexOf(str, c) String_IndexOfAt(str, 0, c)
/* Returns first index of the given character in the given string, -1 if not found. */
Expand Down Expand Up @@ -174,10 +187,10 @@ int Convert_UnicodeToUtf8(Codepoint cp, uint8_t* data);

/* Attempts to append all characters from UTF16 encoded data to the given string. */
/* Characters not in code page 437 are omitted. */
void Convert_DecodeUtf16(String* str, const Codepoint* chars, int numBytes);
void String_AppendUtf16(String* str, const Codepoint* chars, int numBytes);
/* Attempts to append all characters from UTF8 encoded data to the given string. */
/* Characters not in code page 437 are omitted. */
void Convert_DecodeUtf8(String* str, const uint8_t* chars, int numBytes);
void String_AppendUtf8(String* str, const uint8_t* chars, int numBytes);
/* Attempts to append all characters from ASCII encoded data to the given string. */
/* Characters not in code page 437 are omitted. */
void Convert_DecodeAscii(String* str, const uint8_t* chars, int numBytes);
Expand Down
12 changes: 6 additions & 6 deletions src/Window.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ void Window_GetClipboardText(String* value) {
/* ignore trailing NULL at end */
/* TODO: Verify it's always there */
if (isUnicode) {
Convert_DecodeUtf16(value, (Codepoint*)src, size - 2);
String_AppendUtf16(value, (Codepoint*)src, size - 2);
} else {
Convert_DecodeAscii(value, (uint8_t*)src, size - 1);
}
Expand Down Expand Up @@ -1298,7 +1298,7 @@ void Window_ProcessEvents(void) {

if (data && items && prop_type == xa_utf8_string) {
clipboard_paste_text.length = 0;
Convert_DecodeUtf8(&clipboard_paste_text, data, items);
String_AppendUtf8(&clipboard_paste_text, data, items);
}
if (data) XFree(data);
}
Expand Down Expand Up @@ -2020,11 +2020,11 @@ void Window_GetClipboardText(String* value) {
if (!(err = PasteboardCopyItemFlavorData(pbRef, itemID, FMT_UTF16, &outData))) {
ptr = CFDataGetBytePtr(outData);
len = CFDataGetLength(outData);
if (ptr) Convert_DecodeUtf16(value, (Codepoint*)ptr, len);
if (ptr) String_AppendUtf16(value, (Codepoint*)ptr, len);
} else if (!(err = PasteboardCopyItemFlavorData(pbRef, itemID, FMT_UTF8, &outData))) {
ptr = CFDataGetBytePtr(outData);
len = CFDataGetLength(outData);
if (ptr) Convert_DecodeUtf8(value, (uint8_t*)ptr, len);
if (ptr) String_AppendUtf8(value, (uint8_t*)ptr, len);
}
}

Expand Down Expand Up @@ -2317,7 +2317,7 @@ void Window_GetClipboardText(String* value) {
if (!ptr) return;

int len = String_CalcLen(ptr, UInt16_MaxValue);
Convert_DecodeUtf8(value, ptr, len);
String_AppendUtf8(value, ptr, len);
SDL_free(ptr);
}

Expand Down Expand Up @@ -2471,7 +2471,7 @@ static void Window_HandleTextEvent(const SDL_Event* e) {

String_InitArray(str, buffer);
len = String_CalcLen(e->text.text, SDL_TEXTINPUTEVENT_TEXT_SIZE);
Convert_DecodeUtf8(&str, e->text.text, len);
String_AppendUtf8(&str, e->text.text, len);

for (i = 0; i < str.length; i++) {
Event_RaiseInt(&KeyEvents.Press, str.buffer[i]);
Expand Down

0 comments on commit 065a32a

Please sign in to comment.