st_dir = home + "/." + package_symbol_name;
/* Remove .supertux config-file from old SuperTux versions */
- if(FileSystem::faccessible(st_dir))
- {
- remove(st_dir.c_str());
- }
+ if(FileSystem::faccessible(st_dir)) {
+ remove(st_dir.c_str());
+ }
st_save_dir = st_dir + "/save";
// try current directory as datadir
if(datadir.empty()) {
if(FileSystem::faccessible("./data/intro.txt"))
- datadir = "./data";
+ datadir = "./data/";
}
// User has not that a datadir, so we try some magic
{
std::string exedir = std::string(dirname(exe_file)) + "/";
- datadir = exedir + "../data"; // SuperTux run from source dir
+ datadir = exedir + "../data/"; // SuperTux run from source dir
if (access(datadir.c_str(), F_OK) != 0)
{
- datadir = exedir + "../../data"; //SuperTux run from source dir (with libtool script)
+ datadir = exedir + "../../data/"; //SuperTux run from source dir (with libtool script)
if (access(datadir.c_str(), F_OK) != 0)
{
- datadir = exedir + "../share/" + package_symbol_name; // SuperTux run from PATH
+ datadir = exedir + "../share/" + package_symbol_name + "/"; // SuperTux run from PATH
if (access(datadir.c_str(), F_OK) != 0)
{ // If all fails, fall back to compiled path
- datadir = DATA_PREFIX;
+ datadir = DATA_PREFIX;
+ datadir += "/";
}
}
}
}
#else
- datadir = DATA_PREFIX;
+ datadir = DATA_PREFIX;
+ datadir += "/";
#endif
}
printf("Datadir: %s\n", datadir.c_str());
return false;
}
-GameSession::GameSession(const std::string& levelname_, int mode,
+GameSession::GameSession(const std::string& levelfile_, int mode,
bool flip_level_, Statistics* statistics)
: level(0), currentsector(0), st_gl_mode(mode),
- end_sequence(NO_ENDSEQUENCE), levelname(levelname_), flip_level(flip_level_),
- best_level_statistics(statistics)
+ end_sequence(NO_ENDSEQUENCE), levelfile(levelfile_),
+ flip_level(flip_level_), best_level_statistics(statistics)
{
current_ = this;
currentsector = 0;
level = new Level;
- level->load(levelname);
+ level->load(levelfile);
if(flip_level)
level->do_vertical_flip();
while (exit_status == ES_NONE) {
Uint32 ticks = SDL_GetTicks();
float elapsed_time = float(ticks - lastticks) / 1000.;
- global_time += elapsed_time;
+ if(!game_pause)
+ global_time += elapsed_time;
lastticks = ticks;
// 40fps is minimum
bool game_pause;
- std::string levelname;
+ std::string levelfile;
bool flip_level;
// the sector and spawnpoint we shoudl spawn after this frame
DrawingContext* context;
Timer2 time_left;
- GameSession(const std::string& level, int mode, bool flip_level_ = false, Statistics* statistics = NULL);
+ GameSession(const std::string& levelfile, int mode, bool flip_level_ = false,
+ Statistics* statistics = 0);
~GameSession();
/** Enter the busy loop */
}
void
-Level::load(const std::string& filename)
+Level::load(const std::string& filepath)
{
- std::string filepath;
- filepath = st_dir + "/levels/" + filename;
- if (access(filepath.c_str(), R_OK) != 0)
- {
- filepath = datadir + "/levels/" + filename;
- if (access(filepath.c_str(), R_OK) != 0)
- {
- std::cerr << "Error: Level: couldn't find level: " << filename << std::endl;
- return;
- }
- }
-
LispReader* level = LispReader::load(filepath, "supertux-level");
int version = 1;
Level();
~Level();
+ // loads a levelfile
void load(const std::string& filename);
void save(const std::string& filename);
static void create(const std::string& filename);
#include <config.h>
+#include <sstream>
+#include <stdexcept>
#include <assert.h>
#include <unistd.h>
#include "app/setup.h"
#include "level.h"
+#include "resources.h"
#include "app/globals.h"
#include "video/surface.h"
#include "level_subset.h"
// Check in which directory our subset is located (ie. ~/.supertux/
// or SUPERTUX_DATADIR)
- std::string filename;
- filename = st_dir + "/levels/" + subset + "/info";
- if (access(filename.c_str(), R_OK) != 0)
- {
- filename = datadir + "/levels/" + subset + "/info";
- if (access(filename.c_str(), R_OK) != 0)
- std::cout << "Error: LevelSubset: couldn't find subset: " << subset << std::endl;
- }
+ std::string filename = get_resource_filename(
+ std::string("levels/") + subset + "/info");
+ if(filename == "") {
+ std::stringstream msg;
+ msg << "Couldn't find level subset '" << subset << "'.";
+ throw new std::runtime_error(msg.str());
+ }
read_info_file(filename);
for(std::set<std::string>::iterator i = files.begin(); i != files.end(); ++i)
{
if (has_suffix(*i, ".stl"))
- levels.push_back(subset+ "/" + *i);
+ levels.push_back(get_resource_filename(
+ std::string("levels/" + subset+ "/" + *i)));
}
}
}
{
return levels.size();
}
-
-/* EOF */
sprite_manager = 0;
}
+std::string get_resource_filename(const std::string& resource)
+{
+ std::string filepath = st_dir + resource;
+ if(access(filepath.c_str(), R_OK) == 0)
+ return filepath;
+
+ filepath = datadir + resource;
+ if(access(filepath.c_str(), R_OK) == 0)
+ return filepath;
+
+ std::cerr << "Couldn't find resource: '" << resource << "'." << std::endl;
+ return "";
+}
extern Font* white_big_text;
extern Font* yellow_nums;
+// maps a virtual resource path to a real path (ie. levels/bla is mapped to
+// $DATADIR/levels/bla or $HOME/.supertux/levels/bla)
+std::string get_resource_filename(const std::string& resource);
+
void loadshared();
void unloadshared();
Ticks::pause_init();
- titlesession = new GameSession("misc/menu.stl", ST_GL_DEMO_GAME);
+ titlesession = new GameSession(get_resource_filename("levels/misc/menu.stl"),
+ ST_GL_DEMO_GAME);
/* Load images: */
bkg_title = new Surface(datadir + "/images/background/arctis.jpg", false);
delete img_choose_subset;
}
-
-// EOF //
-
// do a shriking fade to the level
shrink_fade(Vector((level->pos.x*32 + 16 + offset.x),(level->pos.y*32 + 16
+ offset.y)), 500);
- GameSession session(level->name,
+ GameSession session(
+ get_resource_filename(std::string("levels/" + level->name)),
ST_GL_LOAD_LEVEL_FILE, level->vertical_flip,
&level->statistics);