示例#1
0
int main(){

		//Open logging file.
	Global_Logging_File.open("Output.txt");

		//The list of rules.
	std::vector<Rule> RuleList;

		//Add the rules.
	Rule New1("S->abS");
	Rule New2("S->bcS");
	Rule New3("S->bbS");
	Rule New4("S->a");
	Rule New5("S->cb");
		
	RuleList.push_back(New1);
	RuleList.push_back(New2);
	RuleList.push_back(New3);
	RuleList.push_back(New4);
	RuleList.push_back(New5);

	Combined Ghosts("S"); //Create a instance of the trace class.

		//Process the rule list.
	Ghosts.Process(RuleList, 0);

		//Close logging file.
	Global_Logging_File.close();

	return 0;
}
示例#2
0
void Draw::World(GLvoid)
{
	dotsRemaining = 0;
	if(levelCom)
		LoadWorld();
	glPushMatrix();
	glTranslatef(-50.0f,0.0f,-50.0f);
	for(unsigned int i = 0; i < worldLayout.size(); i++) {
		switch(worldLayout[i]) {
			case 'T':
				Top(i);
				break;
			case 'B':
				Bottom(i);
				break;
			case 'L':
				Left(i);
				break;
			case 'R':
				Right(i);
				break;
			case 'U':
			case 'D':
				Corner(i);
				break;
			case 'Z':
				Dots(i);
				break;
			case 'X':
				SpawnLoc.xp = lctn[i].x;
				SpawnLoc.zp = lctn[i].t;
				SpawnLoc.yp = 1.1f;
				break;
			case 'G':
				//GZone(i);
				break;
			case 'Y':
				//Teleport(i);
				break;
			case 'W':
				//TPWalls(i);
				break;
			case 'S':
				Start(i);
				break;
		}
	}
	if(levelStr)
		Ghosts();
	glPopMatrix();
}
示例#3
0
void PATHMANAGER::Init(std::ostream & info_output, std::ostream & error_output, bool log_paths)
{
	typedef std::vector<fs::path> Paths;

	// Set Ogre plugins dir
	{
		ogre_plugin = "";
		char *plugindir = getenv("OGRE_PLUGIN_DIR");
		if (plugindir) {
			ogre_plugin = plugindir;
		#ifndef _WIN32
		} else if (fs::exists(fs::path(OGRE_PLUGIN_DIR) / "RenderSystem_GL.so")) {
			ogre_plugin = OGRE_PLUGIN_DIR;
		#endif
		} else {
			#ifdef _WIN32
			ogre_plugin = ".";
			#else
			Paths dirs;
			#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(_M_X64)
			dirs.push_back("/usr/local/lib64");
			dirs.push_back("/usr/lib64");
			#else
			dirs.push_back("/usr/local/lib32");
			dirs.push_back("/usr/lib32");
			#endif
			dirs.push_back("/usr/local/lib");
			dirs.push_back("/usr/lib");
			// Loop through the paths and pick the first one that contain a plugin
			for (Paths::const_iterator p = dirs.begin(); p != dirs.end(); ++p) {
				if (fs::exists(*p / "OGRE/RenderSystem_GL.so")) {
					ogre_plugin = (*p / "OGRE").string();
					break;
				} else if (fs::exists(*p / "ogre/RenderSystem_GL.so")) {
					ogre_plugin = (*p / "ogre").string();
					break;
				}
			}
			#endif
		}
	}

	fs::path stuntrally = "stuntrally";
	// Figure out the user's home directory
	{
		home_dir = "";
		#ifndef _WIN32 // POSIX
			char *homedir = getenv("HOME");
			if (homedir == NULL)
			{
				home_dir = "/home/";
				homedir = getenv("USER");
				if (homedir == NULL) {
					homedir = getenv("USERNAME");
					if (homedir == NULL) {
						error_output << "Could not find user's home directory!" << std::endl;
						home_dir = "/tmp/";
					}
				}
			}
		#else // Windows
			char *homedir = getenv("USERPROFILE");
			if (homedir == NULL) homedir = "data"; // WIN 9x/Me
		#endif
		home_dir += homedir;
	}

	// Find user's config dir
	#ifndef _WIN32 // POSIX
	{
		char const* conf = getenv("XDG_CONFIG_HOME");
		if (conf) user_config = (fs::path(conf) / stuntrally).string();
		else user_config = (fs::path(home_dir) / ".config" / stuntrally).string();
	}
	#else // Windows
	{
		// Open AppData directory
		std::string str;
		ITEMIDLIST* pidl;
		char AppDir[MAX_PATH];
		HRESULT hRes = SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE , &pidl);
		if (hRes == NOERROR)
		{
			SHGetPathFromIDList(pidl, AppDir);
			int i;
			for (i = 0; AppDir[i] != '\0'; i++) {
				if (AppDir[i] == '\\') str += '/';
				else str += AppDir[i];
			}
			user_config = (fs::path(str) / stuntrally).string();
		}
	}
	#endif
	// Create user's config dir
	CreateDir(user_config, error_output);

	// Find user's data dir (for additional data)
	#ifdef _WIN32
	user_data = user_config;  // APPDATA/stuntrally
	#else
	{
		char const* xdg_data_home = getenv("XDG_DATA_HOME");
		user_data = (xdg_data_home ? xdg_data_home / stuntrally
					: fs::path(home_dir) / ".local/share/games" / stuntrally).string();
	}
	#endif

	// Create user's data dir and its children
	///--------------------------------------------------
	CreateDir(user_data, error_output);
	CreateDir(Records(), error_output);
	CreateDir(Ghosts(), error_output);
	
	CreateDir(Replays(), error_output);
	CreateDir(Screenshots(), error_output);
	CreateDir(TracksUser(), error_output);  // user tracks

	CreateDir(DataUser(), error_output);  // user data


	// Find game data dir and defaults config dir
	char *datadir = getenv("STUNTRALLY_DATA_ROOT");
	if (datadir)
		game_data = std::string(datadir);
	else
	{	fs::path shareDir = SHARED_DATA_DIR;
		Paths dirs;

		// Adding users data dir
		// TODO: Disabled for now until this is handled properly
		//dirs.push_back(user_data_dir);

		// Adding relative path for running from sources
		dirs.push_back(execname().parent_path().parent_path() / "data");
		dirs.push_back(execname().parent_path().parent_path());
		dirs.push_back(execname().parent_path() / "data");
		dirs.push_back(execname().parent_path());
		// Adding relative path from installed executable
		dirs.push_back(execname().parent_path().parent_path() / shareDir);
		#ifndef _WIN32
		// Adding XDG_DATA_DIRS
		{
			char const* xdg_data_dirs = getenv("XDG_DATA_DIRS");
			std::istringstream iss(xdg_data_dirs ? xdg_data_dirs : "/usr/local/share/:/usr/share/");
			for (std::string p; std::getline(iss, p, ':'); dirs.push_back(p / stuntrally)) {}
		}
		#endif
		// TODO: Adding path from config file

		//  Loop through the paths and pick the first one that contain some data
		for (Paths::const_iterator p = dirs.begin(); p != dirs.end(); ++p)
		{	//  Data dir
			if (fs::exists(*p / "hud"))
				game_data = p->string();
			//  Config dir
			if (fs::exists(*p / "config"))
				game_config = (*p / "config").string();
			//  Check if both are found
			if (!game_data.empty() && !game_config.empty())  break;
		}
	}


	//  Subdirs for each sim_mode
	///--------------------------------------------------
	std::list <std::string> li;
	PATHMANAGER::DirList(PATHMANAGER::CarSim(), li);
	for (std::list <std::string>::iterator i = li.begin(); i != li.end(); ++i)
	{
		CreateDir(Records()+"/"+*i, error_output);
		CreateDir(Ghosts()+"/"+*i, error_output);
	}

	// Find cache dir
	#ifdef _WIN32
	cache_dir = user_config + "/cache";  // APPDATA/stuntrally/cache
	#else
	char const* xdg_cache_home = getenv("XDG_CACHE_HOME");
	cache_dir = (xdg_cache_home ? xdg_cache_home / stuntrally
				: fs::path(home_dir) / ".cache" / stuntrally).string();
	#endif
	// Create cache dir
	CreateDir(CacheDir(), error_output);
	CreateDir(ShaderDir(), error_output);

	// Print diagnostic info
	if (log_paths)
	{
		std::stringstream out;
		out << "--- Directories: ---" << std::endl;
		out << "Ogre plugin:  " << ogre_plugin << std::endl;
		out << "Data:         " << Data() << std::endl;
		//out << "Default cfg:  " << GetGameConfigDir() << std::endl;
		//out << "Home:         " << home_dir << std::endl;
		out << "User cfg,log: " << UserConfigDir() << std::endl;
		out << "User data:    " << user_data << std::endl;
		out << "Cache:        " << CacheDir() << std::endl;
		info_output << out.str();
	}
}