vrheights

annotate src/game.cc @ 9:df3a70664a7d

falling
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 03 Oct 2014 20:36:24 +0300
parents 3f221bdc9bab
children 3e6757655fe2
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@9 141 if(cam_pos.y < floor_pos.y) {
nuclear@9 142 cam_pos.y = floor_pos.y;
nuclear@9 143 }
nuclear@9 144 }
nuclear@2 145 }
nuclear@2 146
nuclear@2 147 void game_display()
nuclear@2 148 {
nuclear@2 149 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
nuclear@2 150 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
nuclear@2 151
nuclear@2 152 for(int i=0; i<2; i++) {
nuclear@2 153 glViewport(i == 0 ? 0 : fb_xsz / 2, 0, fb_xsz / 2, fb_ysz);
nuclear@2 154 vr_begin(i);
nuclear@2 155
nuclear@2 156 float proj[16];
nuclear@2 157 if(vr_proj_matrix(i, 0.5, 500.0, proj)) {
nuclear@2 158 glMatrixMode(GL_PROJECTION);
nuclear@2 159 glLoadMatrixf(proj);
nuclear@2 160 }
nuclear@2 161
nuclear@2 162 glMatrixMode(GL_MODELVIEW);
nuclear@2 163
nuclear@2 164 float view[16];
nuclear@2 165 vr_view_matrix(i, view);
nuclear@2 166 glLoadMatrixf(view);
nuclear@4 167 glRotatef(cam_phi, 1, 0, 0);
nuclear@4 168 glRotatef(cam_theta, 0, 1, 0);
nuclear@2 169 /* move the camera to the eye level of the user */
nuclear@2 170 glTranslatef(0, -vr_getf_def(VR_EYE_HEIGHT, 1.65), 0);
nuclear@4 171 glTranslatef(-cam_pos.x, -cam_pos.y, -cam_pos.z);
nuclear@2 172
nuclear@2 173 draw_scene();
nuclear@5 174 con.draw();
nuclear@2 175
nuclear@2 176 vr_end();
nuclear@2 177 }
nuclear@2 178
nuclear@2 179 glBindFramebuffer(GL_FRAMEBUFFER, 0);
nuclear@2 180 glViewport(0, 0, win_width, win_height);
nuclear@2 181
nuclear@2 182 vr_swap_buffers();
nuclear@2 183 assert(glGetError() == GL_NO_ERROR);
nuclear@2 184 }
nuclear@2 185
nuclear@2 186 void game_reshape(int x, int y)
nuclear@2 187 {
nuclear@2 188 win_width = x;
nuclear@2 189 win_height = y;
nuclear@2 190
nuclear@5 191 create_rtarg(vr_geti_def(VR_RENDER_XRES, x * 2), vr_geti_def(VR_RENDER_YRES, y));
nuclear@2 192 vr_output_texture(fb_tex, 0, 0, (float)fb_xsz / (float)fb_tex_xsz, (float)fb_ysz / (float)fb_tex_ysz);
nuclear@2 193
nuclear@2 194 /* these might be overriden in VR mode (see game_display) */
nuclear@2 195 glViewport(0, 0, x, y);
nuclear@2 196 glMatrixMode(GL_PROJECTION);
nuclear@2 197 glLoadIdentity();
nuclear@2 198 gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0);
nuclear@2 199 }
nuclear@2 200
nuclear@2 201 void game_keyboard(int key, bool pressed)
nuclear@2 202 {
nuclear@2 203 if(pressed) {
nuclear@5 204 if(con.is_visible()) {
nuclear@5 205 if(key == 27 || key == '`') {
nuclear@5 206 con.hide();
nuclear@5 207 } else {
nuclear@5 208 con.input_key(key);
nuclear@5 209 }
nuclear@5 210 } else {
nuclear@5 211 switch(key) {
nuclear@5 212 case 27:
nuclear@5 213 exit_game();
nuclear@5 214 break;
nuclear@2 215
nuclear@5 216 case 'f':
nuclear@5 217 toggle_hmd_fullscr();
nuclear@5 218 break;
nuclear@2 219
nuclear@5 220 case 'r':
nuclear@5 221 vr_recenter();
nuclear@5 222 break;
nuclear@2 223
nuclear@5 224 case '`':
nuclear@5 225 con.show();
nuclear@5 226 break;
nuclear@5 227
nuclear@5 228 default:
nuclear@5 229 break;
nuclear@5 230 }
nuclear@2 231 }
nuclear@2 232 }
nuclear@4 233
nuclear@4 234 if(key < 256) {
nuclear@4 235 keystate[key] = pressed;
nuclear@4 236 }
nuclear@2 237 }
nuclear@2 238
nuclear@4 239
nuclear@4 240 static int prev_x, prev_y;
nuclear@4 241 static bool bnstate[32];
nuclear@4 242
nuclear@2 243 void game_mouse_button(int bn, bool state, int x, int y)
nuclear@2 244 {
nuclear@4 245 bnstate[bn] = state;
nuclear@4 246 prev_x = x;
nuclear@4 247 prev_y = y;
nuclear@2 248 }
nuclear@2 249
nuclear@2 250 void game_mouse_motion(int x, int y)
nuclear@2 251 {
nuclear@4 252 int dx = x - prev_x;
nuclear@4 253 int dy = y - prev_y;
nuclear@4 254 prev_x = x;
nuclear@4 255 prev_y = y;
nuclear@2 256
nuclear@4 257 if(!dx && !dy) {
nuclear@4 258 return;
nuclear@4 259 }
nuclear@4 260 if(bnstate[0]) {
nuclear@4 261 cam_theta += dx * 0.5;
nuclear@4 262 cam_phi += dy * 0.5;
nuclear@3 263
nuclear@4 264 if(cam_phi < -90) cam_phi = -90;
nuclear@4 265 if(cam_phi > 90) cam_phi = 90;
nuclear@4 266 }
nuclear@3 267 }
nuclear@3 268
nuclear@8 269 MeshFace dbg_walk_face;
nuclear@8 270
nuclear@2 271 static void draw_scene()
nuclear@2 272 {
nuclear@3 273 float lpos[][4] = {
nuclear@3 274 {-0.7, 0.7, 1, 0},
nuclear@3 275 {1, 0, 1, 0}
nuclear@3 276 };
nuclear@3 277 float lcol[][4] = {
nuclear@3 278 {0.9, 0.7, 0.6, 1},
nuclear@3 279 {0.3, 0.4, 0.75, 1}
nuclear@3 280 };
nuclear@3 281 for(int i=0; i<2; i++) {
nuclear@3 282 glEnable(GL_LIGHT0 + i);
nuclear@3 283 glLightfv(GL_LIGHT0 + i, GL_POSITION, lpos[i]);
nuclear@3 284 glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, lcol[i]);
nuclear@3 285 glLightfv(GL_LIGHT0 + i, GL_SPECULAR, lcol[i]);
nuclear@3 286 }
nuclear@3 287
nuclear@3 288 glMatrixMode(GL_MODELVIEW);
nuclear@3 289
nuclear@8 290 /*
nuclear@5 291 glBindTexture(GL_TEXTURE_2D, chess_tex);
nuclear@5 292 glEnable(GL_TEXTURE_2D);
nuclear@3 293 material(1, 1, 1, 1);
nuclear@3 294 glBegin(GL_QUADS);
nuclear@3 295 glNormal3f(0, 1, 0);
nuclear@5 296 glTexCoord2f(0, 0); glVertex3f(-10, 0, 10);
nuclear@5 297 glTexCoord2f(1, 0); glVertex3f(10, 0, 10);
nuclear@5 298 glTexCoord2f(1, 1); glVertex3f(10, 0, -10);
nuclear@5 299 glTexCoord2f(0, 1); glVertex3f(-10, 0, -10);
nuclear@3 300 glEnd();
nuclear@5 301 glDisable(GL_TEXTURE_2D);
nuclear@8 302 */
nuclear@3 303
nuclear@8 304 /*material(1, 1, 1, 0.4);
nuclear@3 305 glPushMatrix();
nuclear@3 306 glTranslatef(0, 1.3, -10);
nuclear@3 307 glFrontFace(GL_CW);
nuclear@3 308 bezier_teapot(2.0);
nuclear@3 309 glFrontFace(GL_CCW);
nuclear@8 310 glPopMatrix();*/
nuclear@8 311
nuclear@8 312 for(size_t i=0; i<scn.obj.size(); i++) {
nuclear@8 313 scn.obj[i]->draw();
nuclear@8 314 }
nuclear@8 315
nuclear@8 316 glPushAttrib(GL_ENABLE_BIT);
nuclear@8 317 glDisable(GL_DEPTH_TEST);
nuclear@8 318 glDisable(GL_LIGHTING);
nuclear@8 319
nuclear@8 320 glBegin(GL_TRIANGLES);
nuclear@8 321 glColor3f(0, 1, 0);
nuclear@8 322 glVertex3fv(&dbg_walk_face.v[0].x);
nuclear@8 323 glVertex3fv(&dbg_walk_face.v[1].x);
nuclear@8 324 glVertex3fv(&dbg_walk_face.v[2].x);
nuclear@8 325 glColor3f(1, 1, 1);
nuclear@8 326 glEnd();
nuclear@8 327
nuclear@8 328 glPopAttrib();
nuclear@2 329 }
nuclear@2 330
nuclear@4 331 static void material(float r, float g, float b, float roughness)
nuclear@4 332 {
nuclear@4 333 float gloss = 1.0 - roughness;
nuclear@4 334 float diffuse[] = {r * roughness, g * roughness, b * roughness, 1.0};
nuclear@4 335 float specular[] = {gloss, gloss, gloss, 1.0};
nuclear@4 336 float shin = gloss * 128.0;
nuclear@4 337
nuclear@4 338 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, diffuse);
nuclear@4 339 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
nuclear@4 340 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shin);
nuclear@4 341 }
nuclear@4 342
nuclear@4 343
nuclear@2 344 static void toggle_hmd_fullscr()
nuclear@2 345 {
nuclear@2 346 static bool fullscr;
nuclear@2 347 static int prev_x, prev_y;
nuclear@2 348 //static int prev_xsz, prev_ysz;
nuclear@2 349
nuclear@2 350 fullscr = !fullscr;
nuclear@2 351 if(fullscr) {
nuclear@2 352 /* entering fullscreen on the HMD */
nuclear@2 353 int xoffs = vr_geti_def(VR_WIN_XOFFS, -1);
nuclear@2 354 int yoffs = vr_geti_def(VR_WIN_YOFFS, -1);
nuclear@2 355 if(xoffs != -1) {
nuclear@2 356 get_window_pos(&prev_x, &prev_y);
nuclear@2 357 move_window(xoffs, yoffs);
nuclear@2 358 }
nuclear@2 359
nuclear@2 360 int xsz = vr_geti_def(VR_DISPLAY_WIDTH, -1);
nuclear@2 361 int ysz = vr_geti_def(VR_DISPLAY_HEIGHT, -1);
nuclear@2 362 if(xsz != -1) {
nuclear@2 363 //prev_xsz = win_width;
nuclear@2 364 //prev_ysz = win_height;
nuclear@2 365 resize_window(xsz, ysz);
nuclear@2 366 }
nuclear@2 367 enter_fullscreen();
nuclear@2 368
nuclear@2 369 } else {
nuclear@2 370 /* leaving fullscreen */
nuclear@2 371 leave_fullscreen();
nuclear@2 372 /*move_window(prev_x, prev_y);
nuclear@2 373 resize_window(prev_xsz, prev_ysz);*/
nuclear@2 374 }
nuclear@2 375 }
nuclear@2 376
nuclear@2 377 static void create_rtarg(int x, int y)
nuclear@2 378 {
nuclear@2 379 if(x == fb_xsz && y == fb_ysz) {
nuclear@2 380 return; // nothing changed
nuclear@2 381 }
nuclear@2 382
nuclear@2 383 fb_xsz = x;
nuclear@2 384 fb_ysz = y;
nuclear@2 385 fb_tex_xsz = next_pow2(fb_xsz);
nuclear@2 386 fb_tex_ysz = next_pow2(fb_ysz);
nuclear@2 387
nuclear@5 388 printf("creating %dx%d render target (tex size: %dx%d)\n", fb_xsz, fb_ysz, fb_tex_xsz, fb_tex_ysz);
nuclear@5 389
nuclear@2 390 if(!fbo) {
nuclear@2 391 glGenFramebuffers(1, &fbo);
nuclear@2 392
nuclear@2 393 glGenTextures(1, &fb_tex);
nuclear@2 394 glBindTexture(GL_TEXTURE_2D, fb_tex);
nuclear@2 395 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
nuclear@2 396 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
nuclear@2 397
nuclear@2 398 glGenRenderbuffers(1, &fb_depth);
nuclear@2 399 }
nuclear@2 400
nuclear@2 401 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
nuclear@2 402
nuclear@2 403 glBindTexture(GL_TEXTURE_2D, fb_tex);
nuclear@2 404 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, fb_tex_xsz, fb_tex_ysz, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
nuclear@2 405 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fb_tex, 0);
nuclear@2 406
nuclear@2 407 glBindRenderbuffer(GL_RENDERBUFFER, fb_depth);
nuclear@2 408 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, fb_tex_xsz, fb_tex_ysz);
nuclear@2 409 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fb_depth);
nuclear@2 410
nuclear@2 411 assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
nuclear@2 412 glBindFramebuffer(GL_FRAMEBUFFER, 0);
nuclear@2 413 }
nuclear@2 414
nuclear@2 415 static int next_pow2(int x)
nuclear@2 416 {
nuclear@2 417 x -= 1;
nuclear@2 418 x |= x >> 1;
nuclear@2 419 x |= x >> 2;
nuclear@2 420 x |= x >> 4;
nuclear@2 421 x |= x >> 8;
nuclear@2 422 x |= x >> 16;
nuclear@2 423 return x + 1;
nuclear@2 424 }
nuclear@6 425
nuclear@6 426 static const char *strip_spaces(const char *str)
nuclear@6 427 {
nuclear@6 428 while(*str && isspace(*str)) str++;
nuclear@6 429 return str;
nuclear@6 430 }
nuclear@6 431
nuclear@7 432 struct Variable {
nuclear@7 433 const char *var;
nuclear@7 434 enum { BOOL, NUM } type;
nuclear@7 435 bool bool_val;
nuclear@7 436 float num_val;
nuclear@7 437 };
nuclear@7 438
nuclear@6 439 static void con_handle(const char *cmd)
nuclear@6 440 {
nuclear@8 441 /* set debug values */
nuclear@8 442 set_gvar_num("cam-pos-x", cam_pos[0]);
nuclear@8 443 set_gvar_num("cam-pos-y", cam_pos[1]);
nuclear@8 444 set_gvar_num("cam-pos-z", cam_pos[2]);
nuclear@8 445
nuclear@6 446 std::vector<char*> argv;
nuclear@6 447 cmd = strip_spaces(cmd);
nuclear@6 448
nuclear@6 449 if(!*cmd || *cmd == '#') {
nuclear@6 450 return;
nuclear@6 451 }
nuclear@6 452
nuclear@6 453 char *line = (char*)alloca(strlen(cmd) + 1);
nuclear@6 454 strcpy(line, cmd);
nuclear@6 455
nuclear@6 456 char *tok = 0;
nuclear@6 457 while((tok = strtok(tok ? 0 : line, " \t\v\n\r"))) {
nuclear@6 458 argv.push_back(tok);
nuclear@6 459 }
nuclear@6 460
nuclear@6 461 if(strcmp(argv[0], "set") == 0) {
nuclear@6 462 if(argv.size() < 3) {
nuclear@7 463 con.printf("set must be followed by 2 arguments\n");
nuclear@6 464 return;
nuclear@6 465 }
nuclear@7 466 if(have_gvar(argv[1])) {
nuclear@7 467 GameVariable &gv = get_gvar(argv[1]);
nuclear@7 468 con.printf("%s->%s (prev: %s)\n", argv[1], argv[2], gv.to_str().c_str());
nuclear@6 469 } else {
nuclear@7 470 con.printf("%s->%s\n", argv[1], argv[2]);
nuclear@6 471 }
nuclear@7 472 set_gvar_parse(argv[1], argv[2]);
nuclear@7 473
nuclear@7 474 } else if(strcmp(argv[0], "get") == 0) {
nuclear@7 475 if(argv.size() < 2) {
nuclear@7 476 con.printf("get must be followed by the variable name\n");
nuclear@7 477 return;
nuclear@7 478 }
nuclear@7 479 if(have_gvar(argv[1])) {
nuclear@7 480 GameVariable &gv = get_gvar(argv[1]);
nuclear@7 481 con.printf("%s: %s\n", argv[1], gv.to_str().c_str());
nuclear@7 482 }
nuclear@7 483
nuclear@7 484 } else if(strcmp(argv[0], "vars") == 0) {
nuclear@7 485 std::list<std::string> vars = get_gvar_list();
nuclear@7 486 std::list<std::string>::const_iterator it = vars.begin();
nuclear@7 487 while(it != vars.end()) {
nuclear@7 488 con.printf(" %s\n", it++->c_str());
nuclear@7 489 }
nuclear@7 490
nuclear@6 491 } else if(strcmp(argv[0], "exit") == 0 || strcmp(argv[0], "quit") == 0) {
nuclear@6 492 exit_game();
nuclear@7 493
nuclear@7 494 } else if(strcmp(argv[0], "help") == 0) {
nuclear@7 495 con.printf("available commands:\n");
nuclear@7 496 con.printf(" set <var> <val> set value to a variable\n");
nuclear@7 497 con.printf(" get <var> print the value of a variable\n");
nuclear@7 498 con.printf(" vars print a list of all variables\n");
nuclear@7 499 con.printf(" help print this help screen\n");
nuclear@7 500 con.printf(" exit or quit quit the program\n");
nuclear@7 501
nuclear@6 502 } else {
nuclear@6 503 con.printf("invalid command: %s\n", argv[0]);
nuclear@6 504 }
nuclear@6 505 }