From bddbf61f5f6f10c93d4c2a99acb7422430d1e156 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 12 Oct 2009 17:44:30 +0000 Subject: [PATCH] added lib directory for standard Anaglym library of models, textures, scripts, etc... git-svn-id: svn://anubis/anaglym/trunk@69 99a6e188-d820-4881-8870-2d33a10e2619 --- anaglym.cc | 21 +++++++++++++++++++++ tests/ballstairs.lua | 1 - 2 files changed, 21 insertions(+), 1 deletion(-) 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()