コード例 #1
0
int TextureManager::init(SDL_Renderer* renderer) {
  if (renderer == nullptr) {
    return 0;
  }

  _renderer = renderer;

  int image_flags = IMG_Init(IMG_INIT_PNG);

  if (!image_flags & IMG_INIT_PNG) {
    return 0;
  }

  if (TTF_Init() == -1) {
    return 0;
  }

  // Build the path to the font
  std::string fullpath = SDL_GetBasePath();
  fullpath.append("assets/fonts/UbuntuMono-R.ttf");

  _font = TTF_OpenFont(fullpath.c_str(), 28);

  if (_font == nullptr) {
    std::cerr << TTF_GetError() << std::endl;

    return 0;
  }

  return 1;
}
コード例 #2
0
ファイル: setup.cpp プロジェクト: Cyphre117/p53_prototype
std::vector<std::string> getImageNames()
{
    std::vector<std::string> imageNames;
    std::string projectPath;
    
    char* charPath = SDL_GetBasePath();    
    projectPath = charPath;    
    SDL_free(charPath);

    std::ifstream file(projectPath + "images.txt");

    std::cout << "images.txt contains:" << std::endl;
    while( file )
    {
        std::string name;

        // whitespace seperated filenames
        file >> name;
        
        // ignore if string is empty
        if( name.empty() ) continue;

        std::cout << "\t" << name << std::endl;

        imageNames.push_back( name );
    }

    return imageNames;
}
コード例 #3
0
ファイル: configuration.c プロジェクト: MEGA65/xemu
static int get_path_info ( void )
{
	FILE *f;
	char buffer[PATH_MAX + 1];
	app_pref_path = NULL;	// to signal that it's not got yet
	/* Get base path (where executable is */
#ifdef __EMSCRIPTEN__
	app_base_path = strdup("/files/");
#else
	app_base_path = SDL_GetBasePath();
	if (!app_base_path) {
		ERROR_WINDOW("Cannot query base directory: %s", ERRSTR());
		return 1;
	}
#endif
	/* Check for pref dir override file in the same directory where executable is (base path) */
	snprintf(buffer, sizeof buffer, "%s%cxep128.dir", app_base_path, DIRSEP[0]);
	f = fopen(buffer, "r");
	if (f) {
		char *p = fgets(buffer, sizeof buffer, f);
		fclose(f);
		if (p) {
			p = strchr(buffer, 13);
			if (p)
				*p = 0;
			p = strchr(buffer, 10);
			if (p)
				*p = 0;
			if (*buffer == '.')
				app_pref_path = strdup(app_base_path);
			else if (*buffer)
				app_pref_path = strdup(buffer);
		}
	}
	/* Pref dir stuff */
	if (app_pref_path) {
		printf("CONFIG: Overriding pref path to: %s" NL, app_pref_path);
	} else {
#ifdef __EMSCRIPTEN__
		app_pref_path = strdup("/files/");
#else
		app_pref_path = SDL_GetPrefPath("nemesys.lgb", "xep128");
		if (!app_pref_path) {
			ERROR_WINDOW("Cannot query preferences directory: %s", ERRSTR());
			return 1;
		}
#endif
	}
	/* Get current directory */
#ifdef __EMSCRIPTEN__
	mkdir("/files", 0777);
	chdir("/files");
#endif
	if (getcwd(current_directory, sizeof current_directory) == NULL) {
		ERROR_WINDOW("Cannot query current directory: %s", ERRSTR());
		return 1;
	}
	strcat(current_directory, DIRSEP);
	return 0;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: iOSAppList/supertux
  void find_datadir()
  {
    std::string datadir;
    if (m_forced_datadir)
    {
      datadir = *m_forced_datadir;
    }
    else if (const char* env_datadir = getenv("SUPERTUX2_DATA_DIR"))
    {
      datadir = env_datadir;
    }
    else
    {
      // check if we run from source dir
      char* basepath_c = SDL_GetBasePath();
      std::string basepath = basepath_c;
      SDL_free(basepath_c);

      datadir = FileSystem::join(basepath, "data");
      std::string testfname = FileSystem::join(datadir, "credits.txt");
      if (!FileSystem::exists(testfname))
      {
        // if the game is not run from the source directory, try to find
        // the global install location
        datadir = datadir.substr(0, datadir.rfind(INSTALL_SUBDIR_BIN));
        datadir = FileSystem::join(datadir, INSTALL_SUBDIR_SHARE);
      }
    }

    if (!PHYSFS_addToSearchPath(datadir.c_str(), 1))
    {
      log_warning << "Couldn't add '" << datadir << "' to physfs searchpath: " << PHYSFS_getLastError() << std::endl;
    }
  }
コード例 #5
0
std::string SDLManager::getResourcePath(std::string path)
{
	#ifdef _WIN32
		const char PATH_SEP = '\\';
	#else
		const char PATH_SEP = '/';
	#endif
	
	static std::string baseRes;
	if (baseRes.empty())
	{
		char *basePath = SDL_GetBasePath();
		if (basePath)
		{
			baseRes = basePath;
			SDL_free(basePath);
		} else {
			std::cout << "Error getting resource path: " << SDL_GetError() << std::endl;
			return "";
		}
		size_t pos = baseRes.rfind("bin");
		baseRes = baseRes.substr(0, pos) + "res" + PATH_SEP;
	}
	
	if (path.empty())
	{
		return baseRes;
	} else if (PATH_SEP == '\\') {
		std::replace(path.begin(), path.end(), '/', PATH_SEP);
	}
	return baseRes+path;
}
コード例 #6
0
std::string util::getResourcePath()
{
    const char PATH_SEP = '/';

    //This will hold the base resource path: Lessons/res/
    //We give it static lifetime so that we'll only need to call
    //SDL_GetBasePath once to get the executable path
    static std::string baseRes;
    if (baseRes.empty())
    {
        //SDL_GetBasePath will return NULL if something went wrong in retrieving the path
        char *basePath = SDL_GetBasePath();
        if (basePath)
        {
            baseRes = basePath;
            SDL_free(basePath);
        }
        else
        {
            std::cerr << "Error getting resource path: " << SDL_GetError() << std::endl;
            return "";
        }
//        //We replace the last bin/ with res/ to get the the resource path
        size_t pos = baseRes.rfind("build");
        baseRes = baseRes.substr(0, pos) + "data" + PATH_SEP;
    }
    //If we want a specific subdirectory path in the resource directory
    //append it to the base path. This would be something like Lessons/res/Lesson0
//    return subDir.empty() ? baseRes : baseRes + subDir + PATH_SEP;
    return baseRes;
}
コード例 #7
0
ファイル: FWApplication.cpp プロジェクト: AntoineKoeman/AI
std::string FWApplication::GetRelativePath(const std::string & path) const
{
	std::string basePath = SDL_GetBasePath();
	return basePath + ".." + PATH_SEP + path; //  + PATH_SEP
	//size_t pos = basePath.rfind("Debug");
	//return basePath.substr(0, basePath.rfind("Debug")) + path + PATH_SEP; //  + "resources" + PATH_SEP
}
コード例 #8
0
Fireball::Fireball(float x, float y, b2World& World, Render* renderer, float d)
{
    world = &World;

    initX = x;
    initY = y;

    dir = d;

    std::string basepath(SDL_GetBasePath());

    std::string imagePath;

    if (dir == 2)
    {
        imagePath = basepath + "spearL.bmp";
    }
    else
    {
        imagePath = basepath + "spearR.bmp";
    }
    sprite = SDL_LoadBMP(imagePath.c_str());

    if (spriteRect == NULL)
    {
        spriteRect = renderer->AddSurfaceToRenderer(sprite, initX, initY, 0.5f);
    }

    else
    {

    }

    CreateBody();
}
コード例 #9
0
ファイル: Engine.cpp プロジェクト: peacefulwarrior/gitTest2
std::string Engine::getResourcePath(const std::string &subDir = ""){
	//We need to choose the path separator properly based on which
	//platform we're running on, since Windows uses a different
	//separator than most systems
#ifdef _WIN32
	const char PATH_SEP = '\\';
#else
	const char PATH_SEP = '/';
#endif
	//This will hold the base resource path: Lessons/res/
	//We give it static lifetime so that we'll only need to call
	//SDL_GetBasePath once to get the executable path
	static std::string baseRes;
	if (baseRes.empty()){
		//SDL_GetBasePath will return NULL if something went wrong in retrieving the path
		char *basePath = SDL_GetBasePath();
		if (basePath){
			baseRes = basePath;
			SDL_free(basePath);
		}
		else {
			std::cerr << "Error getting resource path: " << SDL_GetError() << std::endl;
			return "";
		}
		//We replace the last bin/ with res/ to get the the resource path
		size_t pos = baseRes.rfind("bin");
		baseRes = baseRes.substr(0, pos) + "res" + PATH_SEP;
	}
	//If we want a specific subdirectory path in the resource directory
	//append it to the base path. This would be something like Lessons/res/Lesson0
	return subDir.empty() ? baseRes : baseRes + subDir + PATH_SEP;
}
コード例 #10
0
ファイル: Bullet.cpp プロジェクト: Deagor/Galway_Project
//load the texture
void Bullet::LoadAssets(float x, float y)
{
	std::string basepath(SDL_GetBasePath());
	std::string imagePath;
	if (bulletForPlayer1 == true)
		imagePath = basepath + "../Sprites/player1Bullet.bmp";
	else imagePath = basepath + "../Sprites/player2Bullet.bmp";
	sprite = SDL_LoadBMP(imagePath.c_str());
	spriteRect = Render::GetInstance()->AddSurfaceToRenderer(sprite, x, y);
}
コード例 #11
0
ファイル: AppBaseSDL.cpp プロジェクト: CodeDocs/KTX
bool
AppBaseSDL::initialize(int argc, char* argv[])
{
    const char* basePath = SDL_GetBasePath();
    if (basePath == NULL)
        basePath = SDL_strdup("./");
    sBasePath = basePath;
    SDL_free((void *)basePath);
    return true;
}
コード例 #12
0
ファイル: xsdl.cpp プロジェクト: bossjones/burro-engine
static void initialize_data_path()
{
    char *base_path = SDL_GetBasePath();
    if (base_path)
    {
        data_path = SDL_strdup(base_path);
        SDL_free(base_path);
    } 
    else 
        data_path = SDL_strdup("./");
}
コード例 #13
0
ファイル: j1FileSystem.cpp プロジェクト: Pau5erra/XML
j1FileSystem::j1FileSystem(const char* game_path) : j1Module()
{
	name.create("file_system");

	// need to be created before Awake so other modules can use it
	char* base_path = SDL_GetBasePath();
	PHYSFS_init(base_path);
	SDL_free(base_path);

	AddPath(".");
	AddPath(game_path);
}
コード例 #14
0
ファイル: setup_generic.c プロジェクト: laochailan/taisei
static char* get_default_res_path(void) {
	char *res;

#ifdef TAISEI_BUILDCONF_RELATIVE_DATA_PATH
	res = SDL_GetBasePath();
	strappend(&res, TAISEI_BUILDCONF_DATA_PATH);
#else
	res = strdup(TAISEI_BUILDCONF_DATA_PATH);
#endif

	return res;
}
コード例 #15
0
ファイル: utils.cpp プロジェクト: thiphariel/rpg-sdl
Mix_Music *Game::load_music(std::string name)
{
    Mix_Music *music = NULL;

    std::string path = SDL_GetBasePath() + name;
    music = Mix_LoadMUS(path.c_str());
    if (music == NULL) {
        std::cerr << "An error occured while loading background music";
    }

    return music;
}
コード例 #16
0
ファイル: utils.cpp プロジェクト: thiphariel/rpg-sdl
/**
 * Load font
 */
TTF_Font *Game::load_font(std::string name, int size)
{
    TTF_Font *font = NULL;

    std::string path = SDL_GetBasePath() + name;
    font = TTF_OpenFont(path.c_str(), size);
    if (font == NULL) {
        std::cerr << "An error occured while loading font";
    }

    return font;
}
コード例 #17
0
j1FileSystem::j1FileSystem() : j1Module()
{
	name.create("file_system");

	// need to be created before Awake so other modules can use it
	char* base_path = SDL_GetBasePath();
	PHYSFS_init(base_path);
	SDL_free(base_path);

	// By default we include executable's own directory
	// without this we won't be able to find config.xml :-(
	AddPath(".");
}
コード例 #18
0
ファイル: Loader.cpp プロジェクト: milleniumbug/pr_projekt
	string GetDirectory()
	{
		string toRet = "";
		char* basePath = SDL_GetBasePath();
		if (basePath)
		{
			toRet = basePath;
			SDL_free(basePath);
		}
		else
			toRet = "error";
		return toRet;
	}
コード例 #19
0
FileSystem::FileSystem()
{
	name.assign("file_system");

	// PHYSFS must be initialized before other modules awake,
	// because it will be used by them.
	if (PHYSFS_isInit() == 0)
	{
		char *base_path = SDL_GetBasePath();
		PHYSFS_init(base_path);
		SDL_free(base_path);

		addSearchPath(".");
	}	
}
コード例 #20
0
ファイル: main.cpp プロジェクト: leyyin/supertux
  void find_datadir()
  {
    std::string datadir;
    if (m_forced_datadir)
    {
      datadir = *m_forced_datadir;
    }
    else if (const char* env_datadir = getenv("SUPERTUX2_DATA_DIR"))
    {
      datadir = env_datadir;
    }
    else
    {
      // check if we run from source dir
      char* basepath_c = SDL_GetBasePath();
      std::string basepath = basepath_c;
      SDL_free(basepath_c);

      // If we are on windows, the data directory is one directory above the binary
#ifdef WIN32
      const std::array<std::string, 2> subdirs = { "data", "../data" };
#else
      const std::array<std::string, 1> subdirs = { "data" };
#endif
      bool found = false;
      for (const std::string &subdir : subdirs)
      {
        datadir = FileSystem::join(basepath, subdir);
        if (FileSystem::exists(FileSystem::join(datadir, "credits.txt")))
        {
          found = true;
          break;
        }
      }
      if (!found)
      {
        // if the game is not run from the source directory, try to find
        // the global install location
        datadir = datadir.substr(0, datadir.rfind(INSTALL_SUBDIR_BIN));
        datadir = FileSystem::join(datadir, INSTALL_SUBDIR_SHARE);
      }
    }

    if (!PHYSFS_addToSearchPath(datadir.c_str(), 1))
    {
      log_warning << "Couldn't add '" << datadir << "' to physfs searchpath: " << PHYSFS_getLastError() << std::endl;
    }
  }
コード例 #21
0
ファイル: LoadTests.cpp プロジェクト: CodeDocs/KTX
bool
LoadTests::initialize(int argc, char* argv[])
{
	if (!GLAppSDL::initialize(argc, argv))
		return false;
    
    szBasePath = SDL_GetBasePath();
    if (szBasePath == NULL)
        szBasePath = SDL_strdup("./");
    
    // Not getting an initialize resize event, at least on Mac OS X.
    // Therefore use invokeSample which calls the sample's resize func.
    invokeSample(iCurSampleNum);
    
    return AppBaseSDL::initialize(argc, argv);
}
コード例 #22
0
Door::Door(float x, float y, Render* renderer)
{
	initX = x;
	initY = y;
	initX1 = 100000;
	initY1 = 100000;

	std::string basepath(SDL_GetBasePath());
	std::string imagePath = basepath + "door2.bmp";
	sprite = SDL_LoadBMP(imagePath.c_str());
	spriteRect = renderer->AddSurfaceToRenderer(sprite, -1000, -1000, 0.5f);

	std::string imagePath1 = basepath + "door1.bmp";
	sprite1 = SDL_LoadBMP(imagePath1.c_str());
	spriteRect1 = renderer->AddSurfaceToRenderer(sprite1, -1000, -1000, 0.5f);
}
コード例 #23
0
std::string getResourcePath( const std::string &subDir ){
#ifdef _WIN32
	const char PATH_SEP = '\\';
#else
	const char PATH_SEP = '/';
#endif
	static std::string baseRes;
	if( baseRes.empty() ){
		char *basePath = SDL_GetBasePath();
		baseRes = basePath;
		SDL_free( basePath );

		size_t pos = baseRes.rfind( "build" );
		baseRes = baseRes.substr( 0, pos ) + "res" + PATH_SEP;
	}
	return subDir.empty() ? baseRes : baseRes + subDir + PATH_SEP;
}
コード例 #24
0
int
main(int argc, char *argv[])
{
    /* Enable standard application logging */
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

    if (SDL_Init(0) == -1) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
        return 1;
    }

    SDL_Log("base path: '%s'\n", SDL_GetBasePath());
    SDL_Log("pref path: '%s'\n", SDL_GetPrefPath("libsdl", "testfilesystem"));

    SDL_Quit();
    return 0;
}
コード例 #25
0
ファイル: system.c プロジェクト: ptitSeb/allegro51-pandora
/* al_get_standard_path() does not work before the system driver is
 * initialised.  Before that, we need to call the underlying functions
 * directly.
 */
static ALLEGRO_PATH *early_get_exename_path(void)
{
#if defined(ALLEGRO_WINDOWS)
   return _al_win_get_path(ALLEGRO_EXENAME_PATH);
#elif defined(ALLEGRO_MACOSX)
   return _al_osx_get_path(ALLEGRO_EXENAME_PATH);
#elif defined(ALLEGRO_IPHONE)
   return _al_iphone_get_path(ALLEGRO_EXENAME_PATH);
#elif defined(ALLEGRO_UNIX)
   return _al_unix_get_path(ALLEGRO_EXENAME_PATH);
#elif defined(ALLEGRO_ANDROID)
   return _al_android_get_path(ALLEGRO_EXENAME_PATH);
#elif defined(ALLEGRO_SDL)
   return al_create_path_for_directory(SDL_GetBasePath());
#else
   #error early_get_exename_path not implemented
#endif
}
コード例 #26
0
ファイル: testfilesystem.c プロジェクト: PrisimaTheFox/SRB2
int
main(int argc, char *argv[])
{
    char *base_path;
    char *pref_path;

    /* Enable standard application logging */
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

    if (SDL_Init(0) == -1) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
        return 1;
    }

    base_path = SDL_GetBasePath();
    if(base_path == NULL){
      SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find base path: %s\n",
                   SDL_GetError());
      return 1;
    }
    SDL_Log("base path: '%s'\n", base_path);
    SDL_free(base_path);

    pref_path = SDL_GetPrefPath("libsdl", "testfilesystem");
    if(pref_path == NULL){
      SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path: %s\n",
                   SDL_GetError());
      return 1;
    }
    SDL_Log("pref path: '%s'\n", pref_path); 
    SDL_free(pref_path);

    pref_path = SDL_GetPrefPath(NULL, "testfilesystem");
    if(pref_path == NULL){
      SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path without organization: %s\n",
                   SDL_GetError());
      return 1;
    }
    SDL_Log("pref path: '%s'\n", pref_path); 
    SDL_free(pref_path);

    SDL_Quit();
    return 0;
}
コード例 #27
0
ファイル: utils.cpp プロジェクト: thiphariel/rpg-sdl
/**
 * Load an image as texture
 */
SDL_Texture *Game::load_image(SDL_Renderer *renderer, std::string name)
{
    SDL_Surface *image = NULL;
    SDL_Texture *texture = NULL;

    std::string path = SDL_GetBasePath() + name;
    image = IMG_Load(path.c_str());

    if (image != NULL) {
        texture = SDL_CreateTextureFromSurface(renderer, image);

        SDL_FreeSurface(image);
        image = NULL;
    } else {
        std::cout << "Image could not be loaded! SDL_Error : " << SDL_GetError();
    }

    return texture;
}
コード例 #28
0
ファイル: map.cpp プロジェクト: thiphariel/rpg-sdl
/**
 * Load all data tiles from the binary file
 */
void Map::load(std::string name)
{
    std::string path = SDL_GetBasePath() + name;
    std::fstream stream(path.c_str(), std::ios::in | std::ios::binary);
    if (!stream.is_open()) {
        std::cerr << "Error while loading map data !\n";
        exit(1);
    }

    for (int layer = 0; layer < m_layers; layer++) {
        for (int i = 0; i < m_width; i++) {
            for (int j = 0; j < m_height; j++) {
                binary_read(stream, m_tiles[layer][i][j]);
            }
        }
    }

    stream.close();
}
コード例 #29
0
ファイル: GUI_MainWin.cpp プロジェクト: siharat-th/SDL_gui
void GUI_TemplateDialog::setDirectory()
{
    
#if __ANDROID__
	strcpy( cur_wdir, "/mnt/sdcard/PhaThai/Templates" );
#else
    char *base_path = SDL_GetBasePath();
    const char *data_path;
    if (base_path) {
        data_path = base_path;
    } else {
        data_path = SDL_strdup("./");
    }
    
    
    strcpy( cur_wdir, data_path );
    strcat( cur_wdir, "data/Templates" );
#endif

    
}
コード例 #30
0
ファイル: main.cpp プロジェクト: christ2go/supertux
  void find_datadir() const
  {
    std::string datadir;
    if (m_forced_datadir)
    {
      datadir = *m_forced_datadir;
    }
    else if (const char* env_datadir = getenv("SUPERTUX2_DATA_DIR"))
    {
      datadir = env_datadir;
    }
    else
    {
      // check if we run from source dir
      char* basepath_c = SDL_GetBasePath();
      std::string basepath = basepath_c ? basepath_c : "./";
      SDL_free(basepath_c);

      if (FileSystem::exists(FileSystem::join(BUILD_DATA_DIR, "credits.stxt")))
      {
        datadir = BUILD_DATA_DIR;
        // Add config dir for supplemental files
        PHYSFS_mount(boost::filesystem::canonical(BUILD_CONFIG_DATA_DIR).string().c_str(), NULL, 1);
      }
      else
      {
        // if the game is not run from the source directory, try to find
        // the global install location
        datadir = basepath.substr(0, basepath.rfind(INSTALL_SUBDIR_BIN));
        datadir = FileSystem::join(datadir, INSTALL_SUBDIR_SHARE);
      }
    }

    if (!PHYSFS_mount(boost::filesystem::canonical(datadir).string().c_str(), NULL, 1))
    {
      log_warning << "Couldn't add '" << datadir << "' to physfs searchpath: " << PHYSFS_getLastErrorCode() << std::endl;
    }
  }