コード例 #1
0
void ConfigManager::setConfig (const ICommand::Args& args)
{
	if (args.size() != 2) {
		Log::error(LOG_CONFIG, "parameters: the config key");
		return;
	}

	Log::info(LOG_CONFIG, "set %s to %s", args[0].c_str(), args[1].c_str());

	ConfigVarPtr p = getConfigVar(args[0]);
	p->setValue(args[1]);
}
コード例 #2
0
void ConfigManager::setLogLevel (const ICommand::Args& args)
{
	if (args.size() != 1)
		return;
	const int max = static_cast<int>(LogLevel::LEVEL_MAX);
	for (int i = 0; i < max; ++i) {
		if (args[0] == LogLevels[i].logLevelStr) {
			Log::info(LOG_CONFIG, "Changing log level to %s", args[0].c_str());
			_logLevel = LogLevels[i].logLevel;
			return;
		}
	}
	Log::error(LOG_CONFIG, "Failed to change the level to %s", args[0].c_str());
}
コード例 #3
0
void ConfigManager::setLogLevel (const ICommand::Args& args)
{
	if (args.size() != 1)
		return;
	const int max = static_cast<int>(LogLevel::LEVEL_MAX);
	for (int i = 0; i < max; ++i) {
		if (args[0] == LogLevels[i].logLevelStr) {
			SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, LogLevels[i].sdlLevel);
			_logLevel = LogLevels[i].logLevel;
			Log::info(LOG_COMMON, "Changing log level to %s", args[0].c_str());
			return;
		}
	}
	Log::error(LOG_COMMON, "Failed to change the level to %s", args[0].c_str());
}
コード例 #4
0
void ConfigManager::listConfigVariables (const ICommand::Args& args)
{
	if (!args.empty()) {
		const String tmp(args[0] + "*");
		for (ConfigVarsMapConstIter i = _configVars.begin(); i != _configVars.end(); ++i) {
			if (!tmp.matches(i->first))
				continue;
			const ConfigVarPtr& c = i->second;
			Log::info(LOG_CONFIG, "%s %s", c->getName().c_str(), c->getValue().c_str());
		}
	} else {
		for (ConfigVarsMapConstIter i = _configVars.begin(); i != _configVars.end(); ++i) {
			const ConfigVarPtr& c = i->second;
			Log::info(LOG_CONFIG, "%s %s", c->getName().c_str(), c->getValue().c_str());
		}
	}
}
コード例 #5
0
void ConfigManager::init (IBindingSpaceListener *bindingSpaceListener, int argc, char **argv)
{
	_persister = new ConfigPersisterSQL(System.getDatabaseDirectory() + Singleton<Application>::getInstance().getName() + ".sqlite");
	Log::info(LOG_COMMON, "init configmanager");

	_persister->init();

	_bindingSpaceListener = bindingSpaceListener;

	LUA lua;

	Log::info(LOG_COMMON, "load config lua file");
	const bool success = lua.load("config.lua");
	if (!success) {
		Log::error(LOG_COMMON, "could not load config");
	}

	if (success) {
		Log::info(LOG_COMMON, "load config values");
		getKeyValueMap(lua, _configVarMap, "settings");
		Log::info(LOG_COMMON, "load keybindings");
		getBindingMap(lua, _keybindings, KEY_CONFIG_KEYBINDINGS, KEYBOARD);
		Log::info(LOG_COMMON, "load controller bindings");
		getBindingMap(lua, _controllerBindings, KEY_CONFIG_CONTROLLERBINDINGS, CONTROLLER);
	}
	_language = getConfigValue(_configVarMap, "language", System.getLanguage());
	_gameController = getConfigValue(_configVarMap, "gamecontroller");
	_gameControllerTriggerAxis = getConfigValue(_configVarMap, "gamecontrollertriggeraxis");
	_showFPS = getConfigValue(_configVarMap, "showfps");
	_width = getConfigValue(_configVarMap, "width", "-1");
	_height = getConfigValue(_configVarMap, "height", "-1");
	_fullscreen = getConfigValue(_configVarMap, "fullscreen", "true");
	_soundEnabled = getConfigValue(_configVarMap, "sound");
	_port = getConfigValue(_configVarMap, "port", "4567");
	_debug = getConfigValue(_configVarMap, "debug", "false");
#ifdef NONETWORK
	_network = getConfigValue(_configVarMap, "network", "false");
#else
	_network = getConfigValue(_configVarMap, "network", "true");
#endif
	_vsync = getConfigValue(_configVarMap, "vsync", "true");
	_textureSize = getConfigValue(_configVarMap, "texturesize", "auto");
	_grabMouse = getConfigValue(_configVarMap, "grabmouse", "true");
	_soundEngine = getConfigValue(_configVarMap, "soundengine", "sdl");
	_particles = getConfigValue(_configVarMap, "particles", "0");
	_renderToTexture = getConfigValue(_configVarMap, "rendertotexture", "1");
	getConfigValue(_configVarMap, "red", "8");
	getConfigValue(_configVarMap, "green", "8");
	getConfigValue(_configVarMap, "blue", "8");
	_serverName = getConfigVar("servername", System.getCurrentUser());
	_name = getConfigVar("name", System.getCurrentUser());
	_debugui = getConfigVar("debugui", "false");
	_debugEntity = getConfigVar("debugentity", "false", true);
	getConfigVar("alreadyrated", "false", true);
	_mode = getConfigValue(_configVarMap, "mode", "");

#if 0
	// disabled because the vars must be created on access - to set the flags properly
	for (KeyValueMap::iterator i = _configVarMap.begin(); i != _configVarMap.end(); ++i) {
		getConfigVar(i->first, i->second, true);
	}

	std::vector<std::string> vars;
	_persister->getVars(vars);
	for (std::vector<std::string>::const_iterator i = vars.begin(); i != vars.end(); ++i) {
		getConfigVar(*i);
	}
	for (auto entry : _configVars) {
		Log::info(LOG_COMMON, "'%s' with value '%s'", entry.first.c_str(), entry.second->getValue().c_str());
	}
#endif

	memset(&_debugRendererData, 0, sizeof(_debugRendererData));

	Log::info(LOG_COMMON, "mouse grab enabled: %s", _grabMouse->getValue().c_str());
	Log::info(LOG_COMMON, "controller enabled: %s", _gameController->getValue().c_str());
	Log::info(LOG_COMMON, "     sound enabled: %s", _soundEnabled->getValue().c_str());
	Log::info(LOG_COMMON, "     debug enabled: %s", _debug->getValue().c_str());

	Commands.registerCommand("loglevel", bindFunction(ConfigManager::setLogLevel));
	CommandPtr cmd = Commands.registerCommand(CMD_SETVAR, bindFunction(ConfigManager::setConfig));
	cmd->setCompleter([&] (const std::string& input, std::vector<std::string>& matches) {
		for (auto entry : _configVars) {
			if (!string::startsWith(entry.first, input))
				continue;
			matches.push_back(entry.first);
		}
	});

	Commands.registerCommand(CMD_LISTVARS, bindFunction(ConfigManager::listConfigVariables));

	for (int i = 0; i < argc; i++) {
		if (argv[i][0] != '-')
			continue;
		const std::string command = &argv[i][1];
		if (command == CMD_SETVAR) {
			if (i + 2 >= argc)
				continue;
			const std::string var = argv[i + 1];
			const std::string val = argv[i + 2];
			ConfigVarPtr p = getConfigVar(var);
			p->setValue(val);
			*argv[i] = *argv[i + 1] = *argv[i + 2] = '\0';
			i += 2;
		} else if (command == "loglevel") {
			if (i + 1 >= argc)
				continue;
			ICommand::Args a;
			a.push_back(argv[i + 1]);
			setLogLevel(a);
			*argv[i] = *argv[i + 1] = '\0';
			i += 1;
		}
	}
	increaseCounter("launchcount");
	_persister->save(_configVars);
}