Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add command options for changing mouse sensitivity in game #29

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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