# HG changeset patch # User John Tsiombikas # Date 1412092640 -10800 # Node ID 608e03b688f88dfbb4eafbf1bfdebae4cd9b49b3 # Parent 053a52f0cb646557bbe3c880254d2ea2617f6dcb foo diff -r 053a52f0cb64 -r 608e03b688f8 src/game.cc --- a/src/game.cc Fri Sep 26 18:40:15 2014 +0300 +++ b/src/game.cc Tue Sep 30 18:57:20 2014 +0300 @@ -1,5 +1,6 @@ #include #include +#include #include #include #include "opengl.h" @@ -14,6 +15,7 @@ static void toggle_hmd_fullscr(); static void create_rtarg(int x, int y); static int next_pow2(int x); +static void con_handle(const char *cmd); bool opt_separate_walk_look; @@ -58,9 +60,10 @@ fprintf(stderr, "failed to open console font\n"); return false; } - con.set_size(6, 40); con.set_font(con_font, 14); + con.set_size(7, 40); con.set_position(0, 0, Console::CENTER); + con.set_command_func(con_handle); return true; } @@ -103,6 +106,11 @@ cam_pos.z += dir.x * sin_theta + dir.z * cos_theta; if(!opt_separate_walk_look) { + float rot[4]; + vr_view_rotation(0, rot); + Quaternion q(rot[3], rot[0], rot[1], rot[2]); + + cam_pos.transform(q); } } @@ -362,3 +370,47 @@ x |= x >> 16; return x + 1; } + +static const char *strip_spaces(const char *str) +{ + while(*str && isspace(*str)) str++; + return str; +} + +static void con_handle(const char *cmd) +{ + std::vector argv; + cmd = strip_spaces(cmd); + + if(!*cmd || *cmd == '#') { + return; + } + + char *line = (char*)alloca(strlen(cmd) + 1); + strcpy(line, cmd); + + char *tok = 0; + while((tok = strtok(tok ? 0 : line, " \t\v\n\r"))) { + argv.push_back(tok); + } + + if(strcmp(argv[0], "set") == 0) { + if(argv.size() < 3) { + fprintf(stderr, "set must be followed by 2 arguments\n"); + return; + } + if(strcmp(argv[1], "separate-walk") == 0) { + if(strcmp(argv[2], "true") == 0) { + opt_separate_walk_look = true; + } else if(strcmp(argv[2], "false") == 0) { + opt_separate_walk_look = false; + } + } else { + con.printf("unknown option: %s\n", argv[1]); + } + } else if(strcmp(argv[0], "exit") == 0 || strcmp(argv[0], "quit") == 0) { + exit_game(); + } else { + con.printf("invalid command: %s\n", argv[0]); + } +}