diff --git a/Engine.cc b/Engine.cc index f23e6f5..c7620a0 100644 --- a/Engine.cc +++ b/Engine.cc @@ -3,6 +3,7 @@ #include "anaglym.h" #include "Engine.h" #include "Video.h" +#include "PhyObj/PhyObj.h" #include "sdl_keymap.h" #include #include /* exit() */ @@ -30,7 +31,6 @@ using namespace std; #define doClearHandler(event) \ do { EVENT_PRESENT_FLAG(event) = false; } while(0) -#define WHITESPACE " \t\r\n\f" #define HOOK_TIMEOUT 10000u #define HOOK_STEPS 250000000 #define FONT_NAME "FreeSans.ttf" @@ -41,25 +41,6 @@ using namespace std; Engine * g_engine; /* static helper functions */ -static string trim(const string & orig) -{ - string result = orig; - size_t pos = result.find_first_not_of(WHITESPACE); - if (pos == string::npos) - { - result = ""; - } - else - { - if (pos > 0) - result = result.substr(pos, result.length() - pos); - pos = result.find_last_not_of(WHITESPACE); - if (pos < result.length() - 1) - result = result.substr(0, pos + 1); - } - return result; -} - static void cross_product(dVector3 result, dVector3 first, dVector3 second) { result[0] = first[1] * second[2] - first[2] * second[1]; @@ -549,7 +530,7 @@ int Engine::loadModel(const string & name, bool static_data, float scale) Engine::Object * engine_obj = getObject(id); if (engine_obj != NULL) { - engine_obj->loadPhy(phys_path); + engine_obj->loadPhy(m_fileLoader, phys_path); } return id; } @@ -1427,61 +1408,30 @@ void Engine::Object::render() checkGLError(); } -void Engine::Object::loadPhy(const FileLoader::Path & path) +void Engine::Object::loadPhy(FileLoader * fl, const FileLoader::Path & path) { - FileLoader::Buffer buff = g_engine->m_fileLoader->load(path); - if (buff.size <= 0) - return; - string str(buff.data, buff.size); - stringstream istr(str, ios_base::in); - while (!istr.eof()) + PhyObj po; + po.load(fl, path); + for (int i = 0, sz = po.getNumGeoms(); i < sz; i++) { - string line; - getline(istr, line); - line = trim(line); - if (line == "" || line[0] == '#') - continue; - size_t pos = line.find_first_of(WHITESPACE); - if (pos == string::npos) - continue; - string type = line.substr(0, pos); - pos = line.find("\"", pos); - if (pos == string::npos) - continue; - size_t pos2 = line.find("\"", pos + 1); - if (pos2 == string::npos) - continue; - string name = line.substr(pos + 1, pos2 - pos - 1); - pos = pos2 + 1; - refptr< vector > args = new vector(); - for (;;) + refptr geom = po.getGeom(i); + refptr< vector > args = geom->getArgs(); + switch (geom->getType()) { - pos = line.find_first_not_of(WHITESPACE, pos); - if (pos == string::npos) + case PhyObj::BOX: + m_ode_object->addBox(args); break; - pos2 = line.find_first_of(WHITESPACE, pos); - string n = line.substr(pos, pos2 - pos); - float f = atof(n.c_str()); - args->push_back(f); - if (pos2 == string::npos) + case PhyObj::SPHERE: + m_ode_object->addSphere(args); + break; + case PhyObj::CAPSULE: + m_ode_object->addCapsule(args); + break; + case PhyObj::PLANE: + m_ode_object->addPlane(args); + break; + default: break; - pos = pos2 + 1; - } - if (type == "cube") - { - m_ode_object->addBox(args); - } - else if (type == "sphere") - { - m_ode_object->addSphere(args); - } - else if (type == "capsule") - { - m_ode_object->addCapsule(args); - } - else if (type == "plane") - { - m_ode_object->addPlane(args); } } m_ode_object->finalize(); diff --git a/Engine.h b/Engine.h index 88274cb..3240b54 100644 --- a/Engine.h +++ b/Engine.h @@ -36,7 +36,7 @@ class Engine { m_ode_object->getPosition(x, y, z); } - void loadPhy(const FileLoader::Path & path); + void loadPhy(FileLoader * fl, const FileLoader::Path & path); void setVisible(bool visible) { m_is_visible = visible; } bool getVisible() { return m_is_visible; } void addForce(dReal fx, dReal fy, dReal fz) diff --git a/Makefile b/Makefile index 27d33ad..7e8a82e 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,7 @@ endif all: $(TARGET) -$(TARGET): $(OBJS) wfobj/WFObj.o OdeWorld/OdeWorld.o TextureCache/TextureCache.o +$(TARGET): $(OBJS) wfobj/WFObj.o OdeWorld/OdeWorld.o PhyObj/PhyObj.o TextureCache/TextureCache.o $(CXX) -o $@ $^ $(LDFLAGS) ag_lua.c: ag.lua @@ -69,6 +69,10 @@ wfobj/WFObj.o: OdeWorld/OdeWorld.o: $(MAKE) -C OdeWorld +.PHONY: PhyObj/PhyObj.o +PhyObj/PhyObj.o: + $(MAKE) -C PhyObj + .PHONY: TextureCache/TextureCache.o TextureCache/TextureCache.o: $(MAKE) -C TextureCache