reworked for new wfobj interface

git-svn-id: svn://anubis/dwscr/trunk@122 5bef9df8-b654-44bb-925b-0ff18baa8f8c
This commit is contained in:
josh 2010-10-26 20:08:39 +00:00
parent e2e552e338
commit 580597f389
6 changed files with 82 additions and 52 deletions

View File

@ -1,13 +1,7 @@
#include <map>
#include <string>
#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));
FileLoader::Buffer LoadFile::load(const FileLoader::Path & path)
{
map<string, fileref_t *>::iterator it = m_filemap.find(path.shortPath);
if (it == LoadFileMap->end())
return NULL;
if (it == m_filemap.end())
return Buffer(0);
*length = it->second->length;
return it->second->data;
return Buffer((char *) it->second->data, it->second->length);
}
int LoadFile::getSize(const FileLoader::Path & path)
{
map<string, fileref_t *>::iterator it = m_filemap.find(path.shortPath);
if (it == m_filemap.end())
return 0;
return it->second->length;
}

View File

@ -1,2 +1,25 @@
void * LoadFile(const char * filename, unsigned int * length);
#ifndef LOADFILE_H
#define LOADFILE_H
#include <map>
#include <string>
#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

View File

@ -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

View File

@ -11,7 +11,7 @@
#ifndef WITHOUT_ODE
#include <ode/ode.h>
#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();

View File

@ -27,7 +27,7 @@ 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];

View File

@ -9,6 +9,7 @@
#include <SDL.h>
#include <GL/gl.h>
#include <ode/ode.h>
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;