Skip to content

Commit

Permalink
Merge pull request #29 from WSUCEG-7140/8-setting-for-mouse-sensitivity
Browse files Browse the repository at this point in the history
add command options for changing mouse sensitivity in game
  • Loading branch information
TonePoems committed Jul 17, 2023
2 parents dafddf7 + f09a7f4 commit 4de782a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ python server.py [HOST [PORT]]
### Chat Commands
/mouse [f]
Set the mouse sensitivity. Default value is 0.0025. Valid range from 0.0 (exclusive) to 1.0 (inclusive).
/goto [NAME]
Teleport to another user.
Expand Down
18 changes: 14 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ typedef struct {
int scale;
int ortho;
float fov;
float mouse_sensitivity;
int suppress_char;
int mode;
int mode_changed;
Expand Down Expand Up @@ -2025,6 +2026,7 @@ void parse_command(const char *buffer, int forward) {
int server_port = DEFAULT_PORT;
char filename[MAX_PATH_LENGTH];
int radius, count, xc, yc, zc;
float sensitivity;
if (sscanf(buffer, "/identity %128s %128s", username, token) == 2) {
db_auth_set(username, token);
add_message("Successfully imported identity token!");
Expand Down Expand Up @@ -2061,6 +2063,14 @@ void parse_command(const char *buffer, int forward) {
g->mode_changed = 1;
g->mode = MODE_OFFLINE;
snprintf(g->db_path, MAX_PATH_LENGTH, "%s", DB_PATH);
}
else if (sscanf(buffer, "/mouse %f", &sensitivity) == 1) {
if (sensitivity > 0.0 && sensitivity <= 1.0) {
g->mouse_sensitivity = sensitivity;
}
else {
add_message("Mouse sensitivity must be between 0.0 and 1.0");
}
}
else if (sscanf(buffer, "/view %d", &radius) == 1) {
if (radius >= 1 && radius <= 24) {
Expand Down Expand Up @@ -2384,13 +2394,12 @@ void handle_mouse_input() {
if (exclusive && (px || py)) {
double mx, my;
glfwGetCursorPos(g->window, &mx, &my);
float m = 0.0025;
s->rx += (mx - px) * m;
s->rx += (mx - px) * g->mouse_sensitivity;
if (INVERT_MOUSE) {
s->ry += (my - py) * m;
s->ry += (my - py) * g->mouse_sensitivity;
}
else {
s->ry -= (my - py) * m;
s->ry -= (my - py) * g->mouse_sensitivity;
}
if (s->rx < 0) {
s->rx += RADIANS(360);
Expand Down Expand Up @@ -2579,6 +2588,7 @@ void reset_model() {
g->observe2 = 0;
g->flying = 0;
g->item_index = 0;
g->mouse_sensitivity = 0.0025;
memset(g->typing_buffer, 0, sizeof(char) * MAX_TEXT_LENGTH);
g->typing = 0;
memset(g->messages, 0, sizeof(char) * MAX_MESSAGES * MAX_TEXT_LENGTH);
Expand Down

0 comments on commit 4de782a

Please sign in to comment.