From 580597f3896acc10062968c8ed64adb5dce10c44 Mon Sep 17 00:00:00 2001 From: josh Date: Tue, 26 Oct 2010 20:08:39 +0000 Subject: [PATCH] reworked for new wfobj interface git-svn-id: svn://anubis/dwscr/trunk@122 5bef9df8-b654-44bb-925b-0ff18baa8f8c --- LoadFile/LoadFile.cc | 53 ++++++++++++++++++++++---------------------- LoadFile/LoadFile.h | 25 ++++++++++++++++++++- Makefile | 6 +++++ ss/LogoBox.cpp | 7 +++--- ss/SSMode.cc | 40 ++++++++++++++++----------------- ss/SSMode.h | 3 ++- 6 files changed, 82 insertions(+), 52 deletions(-) diff --git a/LoadFile/LoadFile.cc b/LoadFile/LoadFile.cc index d3112f9..373acf3 100644 --- a/LoadFile/LoadFile.cc +++ b/LoadFile/LoadFile.cc @@ -1,13 +1,7 @@ -#include -#include #include "LoadFile.h" -typedef struct { - const char * filename; - unsigned char * data; - int length; -} fileref_t; +using namespace std; /* The data section is generated by a perl script. The contents of the * included file are part of this logical program unit, which is why it @@ -15,28 +9,33 @@ typedef struct { */ #include "LoadFile-gen.inc" -const static int numFiles = sizeof(LoadFileData)/sizeof(fileref_t); - -static std::map< std::string, fileref_t * > * LoadFileMap = NULL; - -void * LoadFile(const char * filename, unsigned int * length) +LoadFile::LoadFile() { - if (LoadFileMap == NULL) + for (unsigned int i = 0; + i < sizeof(LoadFileData)/sizeof(LoadFileData[0]); + i++) { - LoadFileMap = new std::map< std::string, fileref_t * >(); - for (int i = 0; i < numFiles; i++) - { - (*LoadFileMap)[std::string(LoadFileData[i].filename)] = &LoadFileData[i]; - } + m_filemap[LoadFileData[i].filename] = &LoadFileData[i]; } - - std::map< std::string, fileref_t * >::iterator it = - LoadFileMap->find(std::string(filename)); - - if (it == LoadFileMap->end()) - return NULL; - - *length = it->second->length; - return it->second->data; +} + +FileLoader::Buffer LoadFile::load(const FileLoader::Path & path) +{ + map::iterator it = m_filemap.find(path.shortPath); + + if (it == m_filemap.end()) + return Buffer(0); + + return Buffer((char *) it->second->data, it->second->length); +} + +int LoadFile::getSize(const FileLoader::Path & path) +{ + map::iterator it = m_filemap.find(path.shortPath); + + if (it == m_filemap.end()) + return 0; + + return it->second->length; } diff --git a/LoadFile/LoadFile.h b/LoadFile/LoadFile.h index 7261b72..bda2792 100644 --- a/LoadFile/LoadFile.h +++ b/LoadFile/LoadFile.h @@ -1,2 +1,25 @@ -void * LoadFile(const char * filename, unsigned int * length); +#ifndef LOADFILE_H +#define LOADFILE_H + +#include +#include +#include "FileLoader/FileLoader.h" + +typedef struct { + const char * filename; + unsigned char * data; + int length; +} fileref_t; + +class LoadFile : public FileLoader +{ + public: + LoadFile(); + int getSize(const Path & path); + Buffer load(const Path & path); + protected: + std::map< std::string, fileref_t * > m_filemap; +}; + +#endif diff --git a/Makefile b/Makefile index 61ad341..9ae3bd6 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,12 @@ else WINDOWS := 1 endif +ifeq ($(WINDOWS),1) +export CPPFLAGS += -I"$(shell cd)" +else +export CPPFLAGS += -I"$(shell pwd)" +endif + OBJS = dwscr.o wfobj/WFObj.o LoadFile/LoadFile.o ss/ss.a TARGET = dwscr export CXXFLAGS := -O2 -Wall diff --git a/ss/LogoBox.cpp b/ss/LogoBox.cpp index 8817516..5746039 100644 --- a/ss/LogoBox.cpp +++ b/ss/LogoBox.cpp @@ -11,7 +11,7 @@ #ifndef WITHOUT_ODE #include #endif -#include "../wfobj/WFObj.hh" +#include "../wfobj/WFObj.h" #include "LogoBox.h" #include "../LoadFile/LoadFile.h" @@ -21,6 +21,7 @@ using namespace std; static GLuint _logoList = 0; static float _logoAABB[6]; static GLuint _drawList; +static LoadFile loadFile; /* construct a LogoBox object * The first time the constructor is called it loads the @@ -38,8 +39,8 @@ LogoBox::LogoBox() { if (_logoList == 0) { - WFObj obj; - if (obj.load("dwlogo.obj", NULL, &LoadFile)) + WFObj obj(loadFile); + if (obj.load(FileLoader::Path("", "dwlogo.obj"))) { _logoList = obj.render(false); const float * aabb = obj.getAABB(); diff --git a/ss/SSMode.cc b/ss/SSMode.cc index 8f85ada..f2ddb41 100644 --- a/ss/SSMode.cc +++ b/ss/SSMode.cc @@ -27,25 +27,25 @@ void SSMode::update() /* push an OpenGL matrix onto the matrix stack for a given * ODE body position and rotation */ -void SSMode::pushTransform(const float pos[3], const float R[12]) +void SSMode::pushTransform(const dReal pos[3], const dReal R[12]) { - GLfloat matrix[16]; - matrix[0] = R[0]; - matrix[1] = R[4]; - matrix[2] = R[8]; - matrix[3] = 0; - matrix[4] = R[1]; - matrix[5] = R[5]; - matrix[6] = R[9]; - matrix[7] = 0; - matrix[8] = R[2]; - matrix[9] = R[6]; - matrix[10] = R[10]; - matrix[11] = 0; - matrix[12] = pos[0]; - matrix[13] = pos[1]; - matrix[14] = pos[2]; - matrix[15] = 1; - glPushMatrix(); - glMultMatrixf(matrix); + GLfloat matrix[16]; + matrix[0] = R[0]; + matrix[1] = R[4]; + matrix[2] = R[8]; + matrix[3] = 0; + matrix[4] = R[1]; + matrix[5] = R[5]; + matrix[6] = R[9]; + matrix[7] = 0; + matrix[8] = R[2]; + matrix[9] = R[6]; + matrix[10] = R[10]; + matrix[11] = 0; + matrix[12] = pos[0]; + matrix[13] = pos[1]; + matrix[14] = pos[2]; + matrix[15] = 1; + glPushMatrix(); + glMultMatrixf(matrix); } diff --git a/ss/SSMode.h b/ss/SSMode.h index e525fc8..c85ef78 100644 --- a/ss/SSMode.h +++ b/ss/SSMode.h @@ -9,6 +9,7 @@ #include #include +#include class SSMain; @@ -20,7 +21,7 @@ public: SSMode(SSMain * _SSMain); virtual ~SSMode(); virtual void update(); - void pushTransform(const float pos[3], const float R[12]); + void pushTransform(const dReal pos[3], const dReal R[12]); protected: SSMain * m_SSMain;