diff --git a/anaglym.cc b/anaglym.cc index 2449803..18fc24c 100644 --- a/anaglym.cc +++ b/anaglym.cc @@ -16,6 +16,7 @@ using namespace std; static void usage(); Engine * g_engine; +static string g_engine_path; SDL_Event Engine::userEvent; @@ -25,8 +26,22 @@ static void usage() exit(42); } +static void setupEnginePath(string path) +{ + size_t pos = path.find_last_of("\\/"); + if (pos != string::npos) + { + g_engine_path = string(path, 0, pos); + } + else + { + g_engine_path = "."; + } +} + int main(int argc, char * argv[]) { + setupEnginePath(argv[0]); const char * program = NULL; for (int i = 1; i < argc; i++) { @@ -164,10 +179,16 @@ string Engine::locateResource(const string & shortname) { string try_path; + /* look for the resource relative to the loaded script's directory */ try_path = m_program_path + "/" + shortname; if (fileExists(try_path)) return try_path; + /* next look for the resource in the engine's library directory */ + try_path = g_engine_path + "/lib/" + shortname; + if (fileExists(try_path)) + return try_path; + return ""; } diff --git a/tests/ballstairs.lua b/tests/ballstairs.lua index 9ce4537..1be70f3 100755 --- a/tests/ballstairs.lua +++ b/tests/ballstairs.lua @@ -10,7 +10,6 @@ end --ag.setCamera(8, -8, 15, -8, 8, 4, 0, 0, 1) arena = ag.loadStaticModel("boxarena") -arena:setVisible(false) ball = ag.loadModel("ball") ball:setPosition(-7, 7.4, 12) ball2 = ball:clone()