# HG changeset patch # User John Tsiombikas # Date 1412367083 -10800 # Node ID 537db30791344d28c6b02d54691dc68507a427c8 # Parent 3e6757655fe208530550fde6bfc96ca4b1ff6809 - setting a variable from the console now sets the same variable in libgoatvr too - set_gvar_parse now returns the inferred type diff -r 3e6757655fe2 -r 537db3079134 src/game.cc --- a/src/game.cc Fri Oct 03 21:27:58 2014 +0300 +++ b/src/game.cc Fri Oct 03 23:11:23 2014 +0300 @@ -473,7 +473,18 @@ } else { con.printf("%s->%s\n", argv[1], argv[2]); } - set_gvar_parse(argv[1], argv[2]); + + int type = set_gvar_parse(argv[1], argv[2]); + if(type == GameVariable::NUMBER) { + vr_setf(argv[1], atof(argv[2])); + } else if(type == GameVariable::BOOL) { + vr_seti(argv[1], get_gvar_bool(argv[1]) ? 1 : 0); + } + + // update state vars + cam_pos[0] = get_gvar_num("cam-pos-x"); + cam_pos[1] = get_gvar_num("cam-pos-y"); + cam_pos[2] = get_gvar_num("cam-pos-z"); } else if(strcmp(argv[0], "get") == 0) { if(argv.size() < 2) { diff -r 3e6757655fe2 -r 537db3079134 src/game_var.cc --- a/src/game_var.cc Fri Oct 03 21:27:58 2014 +0300 +++ b/src/game_var.cc Fri Oct 03 23:11:23 2014 +0300 @@ -82,7 +82,7 @@ return *a == 0 ? -1 : 1; } -void set_gvar_parse(const char *name, const char *val) +int set_gvar_parse(const char *name, const char *val) { char *endp, *valstr = (char*)alloca(strlen(val) + 1); strcpy(valstr, val); @@ -91,18 +91,19 @@ float fval = strtod(valstr, &endp); if(endp != valstr && *endp == 0) { set_gvar_num(name, fval); - return; + return GameVariable::NUMBER; } if(strccmp(valstr, "true") == 0 || strccmp(valstr, "yes") == 0) { set_gvar_bool(name, true); - return; + return GameVariable::BOOL; } if(strccmp(valstr, "false") == 0 || strccmp(valstr, "no") == 0) { set_gvar_bool(name, false); - return; + return GameVariable::BOOL; } - return set_gvar_str(name, val); + set_gvar_str(name, val); + return GameVariable::STR; } GameVariable &get_gvar(const char *name) diff -r 3e6757655fe2 -r 537db3079134 src/game_var.h --- a/src/game_var.h Fri Oct 03 21:27:58 2014 +0300 +++ b/src/game_var.h Fri Oct 03 23:11:23 2014 +0300 @@ -18,7 +18,7 @@ void set_gvar_str(const char *name, const char *val); void set_gvar_num(const char *name, float val); void set_gvar_bool(const char *name, bool val); -void set_gvar_parse(const char *name, const char *val); +int set_gvar_parse(const char *name, const char *val); GameVariable &get_gvar(const char *name); const char *get_gvar_str(const char *name); @@ -29,4 +29,4 @@ std::list get_gvar_list(); -#endif // GAME_VAR_H_ \ No newline at end of file +#endif // GAME_VAR_H_