vrheights

annotate src/game.cc @ 11:537db3079134

- setting a variable from the console now sets the same variable in libgoatvr too - set_gvar_parse now returns the inferred type
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 03 Oct 2014 23:11:23 +0300
parents 3e6757655fe2
children 0168104ec568
rev   line source
nuclear@2 1 #include <stdio.h>
nuclear@2 2 #include <assert.h>
nuclear@6 3 #include <vector>
nuclear@2 4 #include <algorithm>
nuclear@4 5 #include <vmath/vmath.h>
nuclear@2 6 #include "opengl.h"
nuclear@2 7 #include "game.h"
nuclear@2 8 #include "goatvr.h"
nuclear@3 9 #include "teapot.h"
nuclear@5 10 #include "console.h"
nuclear@5 11 #include "drawtext.h"
nuclear@7 12 #include "game_var.h"
nuclear@8 13 #include "scenefile.h"
nuclear@2 14
nuclear@2 15 static void draw_scene();
nuclear@4 16 static void material(float r, float g, float b, float roughness);
nuclear@2 17 static void toggle_hmd_fullscr();
nuclear@2 18 static void create_rtarg(int x, int y);
nuclear@2 19 static int next_pow2(int x);
nuclear@6 20 static void con_handle(const char *cmd);
nuclear@2 21
nuclear@2 22 static int win_width, win_height;
nuclear@2 23 static unsigned int fb_tex;
nuclear@2 24 static unsigned int fbo, fb_depth;
nuclear@2 25 static int fb_xsz, fb_ysz;
nuclear@2 26 static int fb_tex_xsz, fb_tex_ysz;
nuclear@2 27
nuclear@5 28 static unsigned int chess_tex;
nuclear@5 29
nuclear@8 30 static float cam_theta = -90, cam_phi;
nuclear@9 31 static Vector3 cam_pos = Vector3(15.4, 0, 0);
nuclear@4 32 static bool keystate[256];
nuclear@4 33
nuclear@9 34 static float cam_vvel;
nuclear@9 35 static const float grav = -9.8;
nuclear@9 36
nuclear@5 37 static Console con;
nuclear@5 38 static dtx_font *con_font;
nuclear@5 39
nuclear@8 40 static SceneFile scn;
nuclear@8 41
nuclear@8 42 #define GVAR_LOOK_WALK "look-walk"
nuclear@8 43 #define GVAR_MAX_STEP "max-step"
nuclear@7 44
nuclear@2 45 bool game_init()
nuclear@2 46 {
nuclear@2 47 init_opengl();
nuclear@2 48
nuclear@8 49 if(!(con_font = dtx_open_font_glyphmap("data/mono14.glyphmap"))) {
nuclear@8 50 fprintf(stderr, "failed to open console font\n");
nuclear@8 51 return false;
nuclear@8 52 }
nuclear@8 53 con.set_font(con_font, 14);
nuclear@8 54 con.set_size(7, 52);
nuclear@8 55 con.set_position(0, 0, Console::CENTER);
nuclear@8 56 con.set_command_func(con_handle);
nuclear@8 57 con.set_echo(false);
nuclear@8 58
nuclear@8 59
nuclear@2 60 if(vr_init() == -1) {
nuclear@2 61 return false;
nuclear@2 62 }
nuclear@2 63
nuclear@2 64 glEnable(GL_DEPTH_TEST);
nuclear@2 65 glEnable(GL_CULL_FACE);
nuclear@3 66 glEnable(GL_LIGHTING);
nuclear@2 67
nuclear@5 68 unsigned char chess_pixels[] = {
nuclear@5 69 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0xff,
nuclear@5 70 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0xff
nuclear@5 71 };
nuclear@5 72 glGenTextures(1, &chess_tex);
nuclear@5 73 glBindTexture(GL_TEXTURE_2D, chess_tex);
nuclear@5 74 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
nuclear@5 75 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
nuclear@5 76 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, chess_pixels);
nuclear@5 77
nuclear@8 78 if(!scn.load("data/sibenik.goatsce")) {
nuclear@8 79 fprintf(stderr, "failed to load scene file\n");
nuclear@5 80 return false;
nuclear@5 81 }
nuclear@7 82
nuclear@7 83 /* initialize all option variables */
nuclear@8 84 set_gvar_bool(GVAR_LOOK_WALK, true);
nuclear@8 85 set_gvar_num(GVAR_MAX_STEP, 0.5);
nuclear@5 86
nuclear@2 87 return true;
nuclear@2 88 }
nuclear@2 89
nuclear@2 90 void game_cleanup()
nuclear@2 91 {
nuclear@2 92 vr_shutdown();
nuclear@2 93 }
nuclear@2 94
nuclear@2 95 void game_update(long tm)
nuclear@2 96 {
nuclear@4 97 static long prev_upd;
nuclear@4 98 float dt = (tm - prev_upd) / 1000.0;
nuclear@4 99 prev_upd = tm;
nuclear@4 100
nuclear@5 101 if(con.is_visible()) {
nuclear@5 102 con.update();
nuclear@5 103 return;
nuclear@5 104 }
nuclear@5 105
nuclear@5 106 float offs = dt * 5.0;
nuclear@4 107 Vector3 dir;
nuclear@4 108
nuclear@4 109 if(keystate['d'] || keystate['D']) {
nuclear@4 110 dir += Vector3(offs, 0, 0);
nuclear@4 111 }
nuclear@4 112 if(keystate['a'] || keystate['A']) {
nuclear@4 113 dir += Vector3(-offs, 0, 0);
nuclear@4 114 }
nuclear@4 115 if(keystate['w'] || keystate['W']) {
nuclear@4 116 dir += Vector3(0, 0, -offs);
nuclear@4 117 }
nuclear@4 118 if(keystate['s'] || keystate['S']) {
nuclear@4 119 dir += Vector3(0, 0, offs);
nuclear@4 120 }
nuclear@4 121
nuclear@8 122 if(get_gvar_bool(GVAR_LOOK_WALK)) {
nuclear@7 123 float rot[4];
nuclear@7 124 vr_view_rotation(0, rot);
nuclear@7 125 Quaternion q(rot[3], rot[0], rot[1], rot[2]);
nuclear@7 126
nuclear@7 127 dir.transform(q);
nuclear@7 128 }
nuclear@7 129
nuclear@5 130 float cos_theta = cos(DEG_TO_RAD(cam_theta));
nuclear@5 131 float sin_theta = sin(DEG_TO_RAD(cam_theta));
nuclear@5 132 cam_pos.x += dir.x * cos_theta - dir.z * sin_theta;
nuclear@5 133 cam_pos.z += dir.x * sin_theta + dir.z * cos_theta;
nuclear@5 134
nuclear@8 135 float max_step = get_gvar_num(GVAR_MAX_STEP);
nuclear@9 136 Vector3 floor_pos = scn.find_walk_pos(cam_pos + Vector3(0, max_step, 0));
nuclear@9 137
nuclear@9 138 if(floor_pos.y < cam_pos.y) {
nuclear@9 139 cam_vvel += grav * dt;
nuclear@9 140 cam_pos.y += cam_vvel * dt;
nuclear@10 141 if(cam_pos.y <= floor_pos.y) {
nuclear@9 142 cam_pos.y = floor_pos.y;
nuclear@10 143 cam_vvel = 0;
nuclear@9 144 }
nuclear@10 145 } else {
nuclear@10 146 cam_pos.y = floor_pos.y;
nuclear@10 147 cam_vvel = 0;
nuclear@9 148 }
nuclear@2 149 }
nuclear@2 150
nuclear@2 151 void game_display()
nuclear@2 152 {
nuclear@2 153 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
nuclear@2 154 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
nuclear@2 155
nuclear@2 156 for(int i=0; i<2; i++) {
nuclear@2 157 glViewport(i == 0 ? 0 : fb_xsz / 2, 0, fb_xsz / 2, fb_ysz);
nuclear@2 158 vr_begin(i);
nuclear@2 159
nuclear@2 160 float proj[16];
nuclear@2 161 if(vr_proj_matrix(i, 0.5, 500.0, proj)) {
nuclear@2 162 glMatrixMode(GL_PROJECTION);
nuclear@2 163 glLoadMatrixf(proj);
nuclear@2 164 }
nuclear@2 165
nuclear@2 166 glMatrixMode(GL_MODELVIEW);
nuclear@2 167
nuclear@2 168 float view[16];
nuclear@2 169 vr_view_matrix(i, view);
nuclear@2 170 glLoadMatrixf(view);
nuclear@4 171 glRotatef(cam_phi, 1, 0, 0);
nuclear@4 172 glRotatef(cam_theta, 0, 1, 0);
nuclear@2 173 /* move the camera to the eye level of the user */
nuclear@2 174 glTranslatef(0, -vr_getf_def(VR_EYE_HEIGHT, 1.65), 0);
nuclear@4 175 glTranslatef(-cam_pos.x, -cam_pos.y, -cam_pos.z);
nuclear@2 176
nuclear@2 177 draw_scene();
nuclear@5 178 con.draw();
nuclear@2 179
nuclear@2 180 vr_end();
nuclear@2 181 }
nuclear@2 182
nuclear@2 183 glBindFramebuffer(GL_FRAMEBUFFER, 0);
nuclear@2 184 glViewport(0, 0, win_width, win_height);
nuclear@2 185
nuclear@2 186 vr_swap_buffers();
nuclear@2 187 assert(glGetError() == GL_NO_ERROR);
nuclear@2 188 }
nuclear@2 189
nuclear@2 190 void game_reshape(int x, int y)
nuclear@2 191 {
nuclear@2 192 win_width = x;
nuclear@2 193 win_height = y;
nuclear@2 194
nuclear@5 195 create_rtarg(vr_geti_def(VR_RENDER_XRES, x * 2), vr_geti_def(VR_RENDER_YRES, y));
nuclear@2 196 vr_output_texture(fb_tex, 0, 0, (float)fb_xsz / (float)fb_tex_xsz, (float)fb_ysz / (float)fb_tex_ysz);
nuclear@2 197
nuclear@2 198 /* these might be overriden in VR mode (see game_display) */
nuclear@2 199 glViewport(0, 0, x, y);
nuclear@2 200 glMatrixMode(GL_PROJECTION);
nuclear@2 201 glLoadIdentity();
nuclear@2 202 gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0);
nuclear@2 203 }
nuclear@2 204
nuclear@2 205 void game_keyboard(int key, bool pressed)
nuclear@2 206 {
nuclear@2 207 if(pressed) {
nuclear@5 208 if(con.is_visible()) {
nuclear@5 209 if(key == 27 || key == '`') {
nuclear@5 210 con.hide();
nuclear@5 211 } else {
nuclear@5 212 con.input_key(key);
nuclear@5 213 }
nuclear@5 214 } else {
nuclear@5 215 switch(key) {
nuclear@5 216 case 27:
nuclear@5 217 exit_game();
nuclear@5 218 break;
nuclear@2 219
nuclear@5 220 case 'f':
nuclear@5 221 toggle_hmd_fullscr();
nuclear@5 222 break;
nuclear@2 223
nuclear@5 224 case 'r':
nuclear@5 225 vr_recenter();
nuclear@5 226 break;
nuclear@2 227
nuclear@5 228 case '`':
nuclear@5 229 con.show();
nuclear@5 230 break;
nuclear@5 231
nuclear@5 232 default:
nuclear@5 233 break;
nuclear@5 234 }
nuclear@2 235 }
nuclear@2 236 }
nuclear@4 237
nuclear@4 238 if(key < 256) {
nuclear@4 239 keystate[key] = pressed;
nuclear@4 240 }
nuclear@2 241 }
nuclear@2 242
nuclear@4 243
nuclear@4 244 static int prev_x, prev_y;
nuclear@4 245 static bool bnstate[32];
nuclear@4 246
nuclear@2 247 void game_mouse_button(int bn, bool state, int x, int y)
nuclear@2 248 {
nuclear@4 249 bnstate[bn] = state;
nuclear@4 250 prev_x = x;
nuclear@4 251 prev_y = y;
nuclear@2 252 }
nuclear@2 253
nuclear@2 254 void game_mouse_motion(int x, int y)
nuclear@2 255 {
nuclear@4 256 int dx = x - prev_x;
nuclear@4 257 int dy = y - prev_y;
nuclear@4 258 prev_x = x;
nuclear@4 259 prev_y = y;
nuclear@2 260
nuclear@4 261 if(!dx && !dy) {
nuclear@4 262 return;
nuclear@4 263 }
nuclear@4 264 if(bnstate[0]) {
nuclear@4 265 cam_theta += dx * 0.5;
nuclear@4 266 cam_phi += dy * 0.5;
nuclear@3 267
nuclear@4 268 if(cam_phi < -90) cam_phi = -90;
nuclear@4 269 if(cam_phi > 90) cam_phi = 90;
nuclear@4 270 }
nuclear@3 271 }
nuclear@3 272
nuclear@8 273 MeshFace dbg_walk_face;
nuclear@8 274
nuclear@2 275 static void draw_scene()
nuclear@2 276 {
nuclear@3 277 float lpos[][4] = {
nuclear@3 278 {-0.7, 0.7, 1, 0},
nuclear@3 279 {1, 0, 1, 0}
nuclear@3 280 };
nuclear@3 281 float lcol[][4] = {
nuclear@3 282 {0.9, 0.7, 0.6, 1},
nuclear@3 283 {0.3, 0.4, 0.75, 1}
nuclear@3 284 };
nuclear@3 285 for(int i=0; i<2; i++) {
nuclear@3 286 glEnable(GL_LIGHT0 + i);
nuclear@3 287 glLightfv(GL_LIGHT0 + i, GL_POSITION, lpos[i]);
nuclear@3 288 glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, lcol[i]);
nuclear@3 289 glLightfv(GL_LIGHT0 + i, GL_SPECULAR, lcol[i]);
nuclear@3 290 }
nuclear@3 291
nuclear@3 292 glMatrixMode(GL_MODELVIEW);
nuclear@3 293
nuclear@8 294 /*
nuclear@5 295 glBindTexture(GL_TEXTURE_2D, chess_tex);
nuclear@5 296 glEnable(GL_TEXTURE_2D);
nuclear@3 297 material(1, 1, 1, 1);
nuclear@3 298 glBegin(GL_QUADS);
nuclear@3 299 glNormal3f(0, 1, 0);
nuclear@5 300 glTexCoord2f(0, 0); glVertex3f(-10, 0, 10);
nuclear@5 301 glTexCoord2f(1, 0); glVertex3f(10, 0, 10);
nuclear@5 302 glTexCoord2f(1, 1); glVertex3f(10, 0, -10);
nuclear@5 303 glTexCoord2f(0, 1); glVertex3f(-10, 0, -10);
nuclear@3 304 glEnd();
nuclear@5 305 glDisable(GL_TEXTURE_2D);
nuclear@8 306 */
nuclear@3 307
nuclear@8 308 /*material(1, 1, 1, 0.4);
nuclear@3 309 glPushMatrix();
nuclear@3 310 glTranslatef(0, 1.3, -10);
nuclear@3 311 glFrontFace(GL_CW);
nuclear@3 312 bezier_teapot(2.0);
nuclear@3 313 glFrontFace(GL_CCW);
nuclear@8 314 glPopMatrix();*/
nuclear@8 315
nuclear@8 316 for(size_t i=0; i<scn.obj.size(); i++) {
nuclear@8 317 scn.obj[i]->draw();
nuclear@8 318 }
nuclear@8 319
nuclear@10 320 /*glPushAttrib(GL_ENABLE_BIT);
nuclear@8 321 glDisable(GL_DEPTH_TEST);
nuclear@8 322 glDisable(GL_LIGHTING);
nuclear@8 323
nuclear@8 324 glBegin(GL_TRIANGLES);
nuclear@8 325 glColor3f(0, 1, 0);
nuclear@8 326 glVertex3fv(&dbg_walk_face.v[0].x);
nuclear@8 327 glVertex3fv(&dbg_walk_face.v[1].x);
nuclear@8 328 glVertex3fv(&dbg_walk_face.v[2].x);
nuclear@8 329 glColor3f(1, 1, 1);
nuclear@8 330 glEnd();
nuclear@8 331
nuclear@10 332 glPopAttrib();*/
nuclear@2 333 }
nuclear@2 334
nuclear@4 335 static void material(float r, float g, float b, float roughness)
nuclear@4 336 {
nuclear@4 337 float gloss = 1.0 - roughness;
nuclear@4 338 float diffuse[] = {r * roughness, g * roughness, b * roughness, 1.0};
nuclear@4 339 float specular[] = {gloss, gloss, gloss, 1.0};
nuclear@4 340 float shin = gloss * 128.0;
nuclear@4 341
nuclear@4 342 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, diffuse);
nuclear@4 343 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
nuclear@4 344 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shin);
nuclear@4 345 }
nuclear@4 346
nuclear@4 347
nuclear@2 348 static void toggle_hmd_fullscr()
nuclear@2 349 {
nuclear@2 350 static bool fullscr;
nuclear@2 351 static int prev_x, prev_y;
nuclear@2 352 //static int prev_xsz, prev_ysz;
nuclear@2 353
nuclear@2 354 fullscr = !fullscr;
nuclear@2 355 if(fullscr) {
nuclear@2 356 /* entering fullscreen on the HMD */
nuclear@2 357 int xoffs = vr_geti_def(VR_WIN_XOFFS, -1);
nuclear@2 358 int yoffs = vr_geti_def(VR_WIN_YOFFS, -1);
nuclear@2 359 if(xoffs != -1) {
nuclear@2 360 get_window_pos(&prev_x, &prev_y);
nuclear@2 361 move_window(xoffs, yoffs);
nuclear@2 362 }
nuclear@2 363
nuclear@2 364 int xsz = vr_geti_def(VR_DISPLAY_WIDTH, -1);
nuclear@2 365 int ysz = vr_geti_def(VR_DISPLAY_HEIGHT, -1);
nuclear@2 366 if(xsz != -1) {
nuclear@2 367 //prev_xsz = win_width;
nuclear@2 368 //prev_ysz = win_height;
nuclear@2 369 resize_window(xsz, ysz);
nuclear@2 370 }
nuclear@2 371 enter_fullscreen();
nuclear@2 372
nuclear@2 373 } else {
nuclear@2 374 /* leaving fullscreen */
nuclear@2 375 leave_fullscreen();
nuclear@2 376 /*move_window(prev_x, prev_y);
nuclear@2 377 resize_window(prev_xsz, prev_ysz);*/
nuclear@2 378 }
nuclear@2 379 }
nuclear@2 380
nuclear@2 381 static void create_rtarg(int x, int y)
nuclear@2 382 {
nuclear@2 383 if(x == fb_xsz && y == fb_ysz) {
nuclear@2 384 return; // nothing changed
nuclear@2 385 }
nuclear@2 386
nuclear@2 387 fb_xsz = x;
nuclear@2 388 fb_ysz = y;
nuclear@2 389 fb_tex_xsz = next_pow2(fb_xsz);
nuclear@2 390 fb_tex_ysz = next_pow2(fb_ysz);
nuclear@2 391
nuclear@5 392 printf("creating %dx%d render target (tex size: %dx%d)\n", fb_xsz, fb_ysz, fb_tex_xsz, fb_tex_ysz);
nuclear@5 393
nuclear@2 394 if(!fbo) {
nuclear@2 395 glGenFramebuffers(1, &fbo);
nuclear@2 396
nuclear@2 397 glGenTextures(1, &fb_tex);
nuclear@2 398 glBindTexture(GL_TEXTURE_2D, fb_tex);
nuclear@2 399 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
nuclear@2 400 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
nuclear@2 401
nuclear@2 402 glGenRenderbuffers(1, &fb_depth);
nuclear@2 403 }
nuclear@2 404
nuclear@2 405 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
nuclear@2 406
nuclear@2 407 glBindTexture(GL_TEXTURE_2D, fb_tex);
nuclear@2 408 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, fb_tex_xsz, fb_tex_ysz, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
nuclear@2 409 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fb_tex, 0);
nuclear@2 410
nuclear@2 411 glBindRenderbuffer(GL_RENDERBUFFER, fb_depth);
nuclear@2 412 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, fb_tex_xsz, fb_tex_ysz);
nuclear@2 413 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fb_depth);
nuclear@2 414
nuclear@2 415 assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
nuclear@2 416 glBindFramebuffer(GL_FRAMEBUFFER, 0);
nuclear@2 417 }
nuclear@2 418
nuclear@2 419 static int next_pow2(int x)
nuclear@2 420 {
nuclear@2 421 x -= 1;
nuclear@2 422 x |= x >> 1;
nuclear@2 423 x |= x >> 2;
nuclear@2 424 x |= x >> 4;
nuclear@2 425 x |= x >> 8;
nuclear@2 426 x |= x >> 16;
nuclear@2 427 return x + 1;
nuclear@2 428 }
nuclear@6 429
nuclear@6 430 static const char *strip_spaces(const char *str)
nuclear@6 431 {
nuclear@6 432 while(*str && isspace(*str)) str++;
nuclear@6 433 return str;
nuclear@6 434 }
nuclear@6 435
nuclear@7 436 struct Variable {
nuclear@7 437 const char *var;
nuclear@7 438 enum { BOOL, NUM } type;
nuclear@7 439 bool bool_val;
nuclear@7 440 float num_val;
nuclear@7 441 };
nuclear@7 442
nuclear@6 443 static void con_handle(const char *cmd)
nuclear@6 444 {
nuclear@8 445 /* set debug values */
nuclear@8 446 set_gvar_num("cam-pos-x", cam_pos[0]);
nuclear@8 447 set_gvar_num("cam-pos-y", cam_pos[1]);
nuclear@8 448 set_gvar_num("cam-pos-z", cam_pos[2]);
nuclear@8 449
nuclear@6 450 std::vector<char*> argv;
nuclear@6 451 cmd = strip_spaces(cmd);
nuclear@6 452
nuclear@6 453 if(!*cmd || *cmd == '#') {
nuclear@6 454 return;
nuclear@6 455 }
nuclear@6 456
nuclear@6 457 char *line = (char*)alloca(strlen(cmd) + 1);
nuclear@6 458 strcpy(line, cmd);
nuclear@6 459
nuclear@6 460 char *tok = 0;
nuclear@6 461 while((tok = strtok(tok ? 0 : line, " \t\v\n\r"))) {
nuclear@6 462 argv.push_back(tok);
nuclear@6 463 }
nuclear@6 464
nuclear@6 465 if(strcmp(argv[0], "set") == 0) {
nuclear@6 466 if(argv.size() < 3) {
nuclear@7 467 con.printf("set must be followed by 2 arguments\n");
nuclear@6 468 return;
nuclear@6 469 }
nuclear@7 470 if(have_gvar(argv[1])) {
nuclear@7 471 GameVariable &gv = get_gvar(argv[1]);
nuclear@7 472 con.printf("%s->%s (prev: %s)\n", argv[1], argv[2], gv.to_str().c_str());
nuclear@6 473 } else {
nuclear@7 474 con.printf("%s->%s\n", argv[1], argv[2]);
nuclear@6 475 }
nuclear@11 476
nuclear@11 477 int type = set_gvar_parse(argv[1], argv[2]);
nuclear@11 478 if(type == GameVariable::NUMBER) {
nuclear@11 479 vr_setf(argv[1], atof(argv[2]));
nuclear@11 480 } else if(type == GameVariable::BOOL) {
nuclear@11 481 vr_seti(argv[1], get_gvar_bool(argv[1]) ? 1 : 0);
nuclear@11 482 }
nuclear@11 483
nuclear@11 484 // update state vars
nuclear@11 485 cam_pos[0] = get_gvar_num("cam-pos-x");
nuclear@11 486 cam_pos[1] = get_gvar_num("cam-pos-y");
nuclear@11 487 cam_pos[2] = get_gvar_num("cam-pos-z");
nuclear@7 488
nuclear@7 489 } else if(strcmp(argv[0], "get") == 0) {
nuclear@7 490 if(argv.size() < 2) {
nuclear@7 491 con.printf("get must be followed by the variable name\n");
nuclear@7 492 return;
nuclear@7 493 }
nuclear@7 494 if(have_gvar(argv[1])) {
nuclear@7 495 GameVariable &gv = get_gvar(argv[1]);
nuclear@7 496 con.printf("%s: %s\n", argv[1], gv.to_str().c_str());
nuclear@7 497 }
nuclear@7 498
nuclear@7 499 } else if(strcmp(argv[0], "vars") == 0) {
nuclear@7 500 std::list<std::string> vars = get_gvar_list();
nuclear@7 501 std::list<std::string>::const_iterator it = vars.begin();
nuclear@7 502 while(it != vars.end()) {
nuclear@7 503 con.printf(" %s\n", it++->c_str());
nuclear@7 504 }
nuclear@7 505
nuclear@6 506 } else if(strcmp(argv[0], "exit") == 0 || strcmp(argv[0], "quit") == 0) {
nuclear@6 507 exit_game();
nuclear@7 508
nuclear@7 509 } else if(strcmp(argv[0], "help") == 0) {
nuclear@7 510 con.printf("available commands:\n");
nuclear@7 511 con.printf(" set <var> <val> set value to a variable\n");
nuclear@7 512 con.printf(" get <var> print the value of a variable\n");
nuclear@7 513 con.printf(" vars print a list of all variables\n");
nuclear@7 514 con.printf(" help print this help screen\n");
nuclear@7 515 con.printf(" exit or quit quit the program\n");
nuclear@7 516
nuclear@6 517 } else {
nuclear@6 518 con.printf("invalid command: %s\n", argv[0]);
nuclear@6 519 }
nuclear@6 520 }