# HG changeset patch # User John Tsiombikas # Date 1349142779 -10800 # Node ID 7f52d6310317e6d81ed01c9b838d67f03bca099b # Parent f71381c9e245d0f05c7ed3072df316cf076bc5e8 fixed design issue with datafile_path diff -r f71381c9e245 -r 7f52d6310317 prototype/src/cmdcon.cc --- a/prototype/src/cmdcon.cc Tue Sep 25 06:59:11 2012 +0300 +++ b/prototype/src/cmdcon.cc Tue Oct 02 04:52:59 2012 +0300 @@ -19,15 +19,15 @@ bool init_cmdcon() { - const char *path = datafile_path(FONT_FILENAME); - if(!path) { + std::string path = datafile_path(FONT_FILENAME); + if(path.empty()) { fprintf(stderr, "failed to locate font file: %s\n", FONT_FILENAME); return false; } - printf("loading font: %s\n", path); - if(!(font = dtx_open_font(path, 14))) { - fprintf(stderr, "failed to open font file: %s\n", path); + printf("loading font: %s\n", path.c_str()); + if(!(font = dtx_open_font(path.c_str(), 14))) { + fprintf(stderr, "failed to open font file: %s\n", path.c_str()); return false; } dtx_use_font(font, 14); diff -r f71381c9e245 -r 7f52d6310317 prototype/src/datapath.cc --- a/prototype/src/datapath.cc Tue Sep 25 06:59:11 2012 +0300 +++ b/prototype/src/datapath.cc Tue Oct 02 04:52:59 2012 +0300 @@ -10,12 +10,11 @@ pathlist.push_back(path); } -const char *datafile_path(const char *fname) +std::string datafile_path(const char *fname) { - static std::string res; - + std::string res; if(!fname) { - return 0; + return res; } for(auto path : pathlist) { @@ -23,8 +22,8 @@ FILE *fp = fopen(res.c_str(), "r"); if(fp) { fclose(fp); - return res.c_str(); + return res; } } - return 0; + return std::string(fname); } diff -r f71381c9e245 -r 7f52d6310317 prototype/src/datapath.h --- a/prototype/src/datapath.h Tue Sep 25 06:59:11 2012 +0300 +++ b/prototype/src/datapath.h Tue Oct 02 04:52:59 2012 +0300 @@ -1,8 +1,10 @@ #ifndef DATAPATH_H_ #define DATAPATH_H_ +#include + void add_data_path(const char *path); -const char *datafile_path(const char *fname); +std::string datafile_path(const char *fname); #endif // DATAPATH_H_ diff -r f71381c9e245 -r 7f52d6310317 prototype/src/dataset.h --- a/prototype/src/dataset.h Tue Sep 25 06:59:11 2012 +0300 +++ b/prototype/src/dataset.h Tue Oct 02 04:52:59 2012 +0300 @@ -53,7 +53,7 @@ } else { path = name; } - if(!(path = datafile_path(path))) { + if(!(path = datafile_path(path).c_str()) || !*path) { fprintf(stderr, "can't find data file: %s\n", name); return 0; } diff -r f71381c9e245 -r 7f52d6310317 prototype/src/main.cc --- a/prototype/src/main.cc Tue Sep 25 06:59:11 2012 +0300 +++ b/prototype/src/main.cc Tue Oct 02 04:52:59 2012 +0300 @@ -109,7 +109,7 @@ move_sound->set_volume(0.4); music = new OggVorbisStream; - if(music->open(datafile_path("bgtrack.ogg"))) { + if(music->open(datafile_path("bgtrack.ogg").c_str())) { music->set_volume(0.6); music->play(PlayMode::loop); } else { @@ -175,14 +175,14 @@ // load a tileset tileset = new TileSet; printf("loading tileset: %s\n", cfg.tileset_file); - if(!tileset->load(datafile_path(cfg.tileset_file))) { + if(!tileset->load(datafile_path(cfg.tileset_file).c_str())) { return false; } set_active_tileset(tileset); level = new Level; printf("loading level: %s\n", cfg.level_file); - if(!level->load(datafile_path(cfg.level_file))) { + if(!level->load(datafile_path(cfg.level_file).c_str())) { return false; } diff -r f71381c9e245 -r 7f52d6310317 prototype/src/renderer.cc --- a/prototype/src/renderer.cc Tue Sep 25 06:59:11 2012 +0300 +++ b/prototype/src/renderer.cc Tue Oct 02 04:52:59 2012 +0300 @@ -114,22 +114,16 @@ static unsigned int load_sdr(const char *vfname, const char *pfname) { - char vsfile[PATH_MAX], psfile[PATH_MAX]; - const char *fname; unsigned int prog; - if((fname = datafile_path(vfname))) { - strcpy(vsfile, fname); - } else { - vsfile[0] = 0; - } - if((fname = datafile_path(pfname))) { - strcpy(psfile, fname); - } else { - psfile[0] = 0; - } - if(!(prog = create_program_load(vsfile, psfile))) { - fprintf(stderr, "failed to load shader program (%s, %s)\n", vsfile, psfile); + std::string vsfile = datafile_path(vfname); + std::string psfile = datafile_path(pfname); + + const char *vs = vsfile.empty() ? 0 : vsfile.c_str(); + const char *ps = psfile.empty() ? 0 : psfile.c_str(); + + if(!(prog = create_program_load(vs, ps))) { + fprintf(stderr, "failed to load shader program (%s, %s)\n", vs, ps); return 0; } return prog; diff -r f71381c9e245 -r 7f52d6310317 prototype/src/renderer_deferred.cc --- a/prototype/src/renderer_deferred.cc Tue Sep 25 06:59:11 2012 +0300 +++ b/prototype/src/renderer_deferred.cc Tue Oct 02 04:52:59 2012 +0300 @@ -255,22 +255,16 @@ static unsigned int load_sdr(const char *vfname, const char *pfname) { - char vsfile[PATH_MAX], psfile[PATH_MAX]; - const char *fname; unsigned int prog; - if((fname = datafile_path(vfname))) { - strcpy(vsfile, fname); - } else { - vsfile[0] = 0; - } - if((fname = datafile_path(pfname))) { - strcpy(psfile, fname); - } else { - psfile[0] = 0; - } - if(!(prog = create_program_load(vsfile, psfile))) { - fprintf(stderr, "failed to load shader program (%s, %s)\n", vsfile, psfile); + std::string vsfile = datafile_path(vfname); + std::string psfile = datafile_path(pfname); + + const char *vs = vsfile.empty() ? 0 : vsfile.c_str(); + const char *ps = psfile.empty() ? 0 : psfile.c_str(); + + if(!(prog = create_program_load(vs, ps))) { + fprintf(stderr, "failed to load shader program (%s, %s)\n", vs, ps); return 0; } return prog; diff -r f71381c9e245 -r 7f52d6310317 prototype/src/renderer_multipass.cc --- a/prototype/src/renderer_multipass.cc Tue Sep 25 06:59:11 2012 +0300 +++ b/prototype/src/renderer_multipass.cc Tue Oct 02 04:52:59 2012 +0300 @@ -102,22 +102,16 @@ static unsigned int load_sdr(const char *vfname, const char *pfname) { - char vsfile[PATH_MAX], psfile[PATH_MAX]; - const char *fname; unsigned int prog; - if((fname = datafile_path(vfname))) { - strcpy(vsfile, fname); - } else { - vsfile[0] = 0; - } - if((fname = datafile_path(pfname))) { - strcpy(psfile, fname); - } else { - psfile[0] = 0; - } - if(!(prog = create_program_load(vsfile, psfile))) { - fprintf(stderr, "failed to load shader program (%s, %s)\n", vsfile, psfile); + std::string vsfile = datafile_path(vfname); + std::string psfile = datafile_path(pfname); + + const char *vs = vsfile.empty() ? 0 : vsfile.c_str(); + const char *ps = psfile.empty() ? 0 : psfile.c_str(); + + if(!(prog = create_program_load(vs, ps))) { + fprintf(stderr, "failed to load shader program (%s, %s)\n", vs, ps); return 0; } return prog; diff -r f71381c9e245 -r 7f52d6310317 prototype/src/tile.cc --- a/prototype/src/tile.cc Tue Sep 25 06:59:11 2012 +0300 +++ b/prototype/src/tile.cc Tue Oct 02 04:52:59 2012 +0300 @@ -155,7 +155,7 @@ { for(size_t i=0; idraw(); } } @@ -273,7 +273,7 @@ // ... ALSO add a fire particle system :) save me jebus struct psys_emitter *ps = psys_create(); - if(ps && psys_load_attr(&ps->attr, datafile_path("fire.psys")) == 0) { + if(ps && psys_load_attr(&ps->attr, datafile_path("fire.psys").c_str()) == 0) { Vector3 lpos = lt->get_position(); psys_set_pos(ps, v3_cons(lpos.x, lpos.y + 0.01, lpos.z), 0); psys_global.push_back(ps); diff -r f71381c9e245 -r 7f52d6310317 prototype/src/tileset.cc --- a/prototype/src/tileset.cc Tue Sep 25 06:59:11 2012 +0300 +++ b/prototype/src/tileset.cc Tue Oct 02 04:52:59 2012 +0300 @@ -1,4 +1,9 @@ #include +#ifndef _MSC_VER +#include +#else +#include +#endif #include "tileset.h" #include "datapath.h" @@ -26,6 +31,9 @@ fprintf(stderr, "failed to open tileset: %s\n", fname); return false; } + char *tmp = (char*)alloca(strlen(fname) + 1); + strcpy(tmp, fname); + fname = tmp; int linenum = 0; char buf[512]; @@ -48,7 +56,7 @@ printf("Tileset %s, loading tile \"%s\" -> %s\n", fname, line, tilefile); Tile *tile = new Tile(this); - if(!tile->load(datafile_path(tilefile))) { + if(!tile->load(datafile_path(tilefile).c_str())) { fprintf(stderr, "failed to load tile: %s\n", tilefile); delete tile; continue;