示例#1
0
int main (int argc, char* argv[]) {
    struct sigaction sa;
    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = &sig_handler;

    sigaction(SIGINT, &sa, NULL);


    IniParser* ini = new IniParser("server.ini");
    documentRoot = ini->get("document_root");
    std::string port = ini->get("port");
    delete(ini);
    
    ServerSocket* server = new ServerSocket(port);
    ClientSocket* client = NULL;

    while (!stop) {
        client = server->accept(true);
        
        if (client != NULL) {
            pthread_t tid;
            pthread_create(&tid, NULL, &clientThread, client);
            pthread_detach(tid);
        }
    }
    
    delete(server);

    std::cout << "Shutdown complete." << std::endl;
    
    return 0;
}
示例#2
0
void Game::init(const std::string& path)
{
	// Set application directory
	size_t last_dir = path.find_last_of("/\\");
	m_app_dir = path.substr(0, last_dir + 1);
	if (m_app_dir.empty())
		m_app_dir = "./";

	// Init resources search directory
	Resources::setSearchPath(m_app_dir + "/resources/");

	// Init levels
	std::cout << "* loading levels from " << WB_LEVEL_FILE << std::endl;
	LevelManager::getInstance().openFromFile(m_app_dir + WB_LEVEL_FILE);

	// Init GUI module
	gui::Theme::loadFont(m_app_dir + "/resources/images/font.png");

	SoundSystem::openMusicFromFile(m_app_dir + "/resources/musics/evolution_sphere.ogg");

	// Load configuration from settings file
	IniParser config;
	std::cout << "* loading settings from " << WB_SETTINGS_FILE << std::endl;
	if (config.load(m_app_dir + WB_SETTINGS_FILE))
	{
		config.seek_section("Wallbreaker");
		size_t app_width = config.get("app_width", APP_WIDTH * 2);
		size_t app_height = config.get("app_height", APP_HEIGHT * 2);
		setResolution(app_width, app_height);

		Settings::highscore = config.get("highscore", 0);

		SoundSystem::enableSound(config.get("sound", true));
		SoundSystem::enableMusic(config.get("music", true));
	}
	else
	{
		setResolution(APP_WIDTH * 2, APP_HEIGHT * 2);
	}

	SoundSystem::playMusic();
}
示例#3
0
void UserSettings::loadFromConfig(IniParser& config)
{
	config.seekSection("Settings");
	// language
	std::string lang = config.get("language");
	if (lang.empty() || !I18n::getInstance().loadFromCode(lang))
	{
		I18n::getInstance().loadFromLocale();
	}

	// Panel position
	panel_on_top = config.get("panel_on_top", panel_on_top);

	config.seekSection("Player");

	int level = config.get("last_unlocked_level", 1);
	LevelManager::getInstance().setLastUnlocked(level);

	level = config.get("current_level", 1);
	LevelManager::getInstance().setCurrent(level);

	s_credits = config.get("credits", 0);
	s_highscore = config.get("arcade_highscore", 0);

	s_items[Item::WEAPON] =   config.get("lvl_laser", 1);
	s_items[Item::SHIELD] =   config.get("lvl_shield", 1);
	s_items[Item::HULL] =     config.get("lvl_hull", 1);
	s_items[Item::ENGINE] =   config.get("lvl_engine", 1);
	s_items[Item::HEATSINK] = config.get("lvl_heatsink", 1);
	for (int i = 0; i < Item::_COUNT; ++i)
	{
		setItemLevel((Item::Type) i, s_items[i]);
	}

	config.seekSection("Keyboard");
	Input::setKeyBinding(config.get("move_up",    Input::getKeyBinding(Action::UP)), Action::UP);
	Input::setKeyBinding(config.get("move_down",  Input::getKeyBinding(Action::DOWN)), Action::DOWN);
	Input::setKeyBinding(config.get("move_left",  Input::getKeyBinding(Action::LEFT)), Action::LEFT);
	Input::setKeyBinding(config.get("move_right", Input::getKeyBinding(Action::RIGHT)), Action::RIGHT);
	Input::setKeyBinding(config.get("laser",      Input::getKeyBinding(Action::USE_LASER)), Action::USE_LASER);
	Input::setKeyBinding(config.get("cooler",     Input::getKeyBinding(Action::USE_COOLER)), Action::USE_COOLER);
	Input::setKeyBinding(config.get("missile",    Input::getKeyBinding(Action::USE_MISSILE)), Action::USE_MISSILE);

	config.seekSection("Joystick");
	Input::setButtonBinding(config.get("pause",   Input::getButtonBinding(Action::PAUSE)), Action::PAUSE);
	Input::setButtonBinding(config.get("laser",   Input::getButtonBinding(Action::USE_LASER)), Action::USE_LASER);
	Input::setButtonBinding(config.get("cooler",  Input::getButtonBinding(Action::USE_COOLER)), Action::USE_COOLER);
	Input::setButtonBinding(config.get("missile", Input::getButtonBinding(Action::USE_MISSILE)), Action::USE_MISSILE);
	Input::setJoystickDeadzone(config.get("sensitivity", Input::getJoystickDeadzone()));

	config.seekSection("Audio");
	SoundSystem::enableMusic(config.get("enable_music", true));
	SoundSystem::setMusicVolume(config.get("music_volume", 100));
	SoundSystem::enableSound(config.get("enable_sound", true));
	SoundSystem::setSoundVolume(config.get("sound_volume", 100));
}