improve usability of ExampleBrowser

store command-line arguments in bulletDemo.txt
save/load of configuration, save demo name instead of index
add setBackgroundColor as example (background_color_red) and
mouse move/wheel speed config (mouse_wheel_multiplier and mouse_move_multiplier)
(saved after changing the demo)
default btIDebugDraw colors can be changed
b3CommandLineArgs::GetCmdLineArgument returns bool, and b3CommandLineArgs::addArgs added
fix copy/paste
This commit is contained in:
erwincoumans
2015-08-04 18:24:30 -07:00
parent 9d7d5caa8b
commit b316f30040
14 changed files with 400 additions and 115 deletions

View File

@@ -19,6 +19,11 @@ public:
// Constructor
b3CommandLineArgs(int argc, char **argv)
{
addArgs(argc,argv);
}
void addArgs(int argc, char**argv)
{
using namespace std;
@@ -39,7 +44,12 @@ public:
key = string(arg, 2, pos - 2);
val = string(arg, pos + 1, arg.length() - 1);
}
pairs[key] = val;
//only add new keys, don't replace existing
if(pairs.find(key) == pairs.end())
{
pairs[key] = val;
}
}
}
@@ -54,7 +64,7 @@ public:
}
template <typename T>
void GetCmdLineArgument(const char *arg_name, T &val);
bool GetCmdLineArgument(const char *arg_name, T &val);
int ParsedArgc()
{
@@ -63,18 +73,20 @@ public:
};
template <typename T>
inline void b3CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val)
inline bool b3CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val)
{
using namespace std;
map<string, string>::iterator itr;
if ((itr = pairs.find(arg_name)) != pairs.end()) {
istringstream strstream(itr->second);
strstream >> val;
return true;
}
return false;
}
template <>
inline void b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, char* &val)
inline bool b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, char* &val)
{
using namespace std;
map<string, string>::iterator itr;
@@ -83,10 +95,11 @@ inline void b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, c
string s = itr->second;
val = (char*) malloc(sizeof(char) * (s.length() + 1));
std::strcpy(val, s.c_str());
return true;
} else {
val = NULL;
}
return false;
}