vrheights

changeset 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 cb97ea43709b
files src/game.cc src/game_var.cc src/game_var.h
diffstat 3 files changed, 20 insertions(+), 8 deletions(-) [+]
line diff
     1.1 --- a/src/game.cc	Fri Oct 03 21:27:58 2014 +0300
     1.2 +++ b/src/game.cc	Fri Oct 03 23:11:23 2014 +0300
     1.3 @@ -473,7 +473,18 @@
     1.4  		} else {
     1.5  			con.printf("%s->%s\n", argv[1], argv[2]);
     1.6  		}
     1.7 -		set_gvar_parse(argv[1], argv[2]);
     1.8 +
     1.9 +		int type = set_gvar_parse(argv[1], argv[2]);
    1.10 +		if(type == GameVariable::NUMBER) {
    1.11 +			vr_setf(argv[1], atof(argv[2]));
    1.12 +		} else if(type == GameVariable::BOOL) {
    1.13 +			vr_seti(argv[1], get_gvar_bool(argv[1]) ? 1 : 0);
    1.14 +		}
    1.15 +
    1.16 +		// update state vars
    1.17 +		cam_pos[0] = get_gvar_num("cam-pos-x");
    1.18 +		cam_pos[1] = get_gvar_num("cam-pos-y");
    1.19 +		cam_pos[2] = get_gvar_num("cam-pos-z");
    1.20  
    1.21  	} else if(strcmp(argv[0], "get") == 0) {
    1.22  		if(argv.size() < 2) {
     2.1 --- a/src/game_var.cc	Fri Oct 03 21:27:58 2014 +0300
     2.2 +++ b/src/game_var.cc	Fri Oct 03 23:11:23 2014 +0300
     2.3 @@ -82,7 +82,7 @@
     2.4  	return *a == 0 ? -1 : 1;
     2.5  }
     2.6  
     2.7 -void set_gvar_parse(const char *name, const char *val)
     2.8 +int set_gvar_parse(const char *name, const char *val)
     2.9  {
    2.10  	char *endp, *valstr = (char*)alloca(strlen(val) + 1);
    2.11  	strcpy(valstr, val);
    2.12 @@ -91,18 +91,19 @@
    2.13  	float fval = strtod(valstr, &endp);
    2.14  	if(endp != valstr && *endp == 0) {
    2.15  		set_gvar_num(name, fval);
    2.16 -		return;
    2.17 +		return GameVariable::NUMBER;
    2.18  	}
    2.19  
    2.20  	if(strccmp(valstr, "true") == 0 || strccmp(valstr, "yes") == 0) {
    2.21  		set_gvar_bool(name, true);
    2.22 -		return;
    2.23 +		return GameVariable::BOOL;
    2.24  	}
    2.25  	if(strccmp(valstr, "false") == 0 || strccmp(valstr, "no") == 0) {
    2.26  		set_gvar_bool(name, false);
    2.27 -		return;
    2.28 +		return GameVariable::BOOL;
    2.29  	}
    2.30 -	return set_gvar_str(name, val);
    2.31 +	set_gvar_str(name, val);
    2.32 +	return GameVariable::STR;
    2.33  }
    2.34  
    2.35  GameVariable &get_gvar(const char *name)
     3.1 --- a/src/game_var.h	Fri Oct 03 21:27:58 2014 +0300
     3.2 +++ b/src/game_var.h	Fri Oct 03 23:11:23 2014 +0300
     3.3 @@ -18,7 +18,7 @@
     3.4  void set_gvar_str(const char *name, const char *val);
     3.5  void set_gvar_num(const char *name, float val);
     3.6  void set_gvar_bool(const char *name, bool val);
     3.7 -void set_gvar_parse(const char *name, const char *val);
     3.8 +int set_gvar_parse(const char *name, const char *val);
     3.9  
    3.10  GameVariable &get_gvar(const char *name);
    3.11  const char *get_gvar_str(const char *name);
    3.12 @@ -29,4 +29,4 @@
    3.13  
    3.14  std::list<std::string> get_gvar_list();
    3.15  
    3.16 -#endif	// GAME_VAR_H_
    3.17 \ No newline at end of file
    3.18 +#endif	// GAME_VAR_H_