moved model constructor always behind factory

This commit is contained in:
Will
2013-12-05 21:28:20 +01:00
29 changed files with 173 additions and 152 deletions

View File

@@ -33,7 +33,7 @@ public:
virtual TextRenderer3D *newTextRenderer3D() {return new TextRenderer3DGl();}
virtual ModelRenderer *newModelRenderer() {return new ModelRendererGl();}
virtual Context *newContext() {return new ContextGl();}
virtual Model *newModel() {return new ModelGl();}
virtual Model *newModel(const string &path,TextureManager* textureManager,bool deletePixMapAfterLoad,std::map<string,vector<pair<string, string> > > *loadedFileList, string *sourceLoader) { return new ModelGl(path,textureManager,deletePixMapAfterLoad,loadedFileList,sourceLoader); }
virtual Texture2D *newTexture2D() {return new Texture2DGl();}
virtual Font2D *newFont2D() {return new Font2DGl();}
virtual Font3D *newFont3D() {return new Font3DGl();}

View File

@@ -47,7 +47,7 @@ public:
//models
virtual ModelManager *newModelManager() {return new ModelManager();}
virtual ModelRenderer *newModelRenderer() {return new ModelRendererGl();}
virtual Model *newModel() {return new ModelGl();}
virtual Model *newModel(const string &path,TextureManager* textureManager,bool deletePixMapAfterLoad,std::map<string,vector<pair<string, string> > > *loadedFileList, string *sourceLoader) { return new ModelGl(path,textureManager,deletePixMapAfterLoad,loadedFileList,sourceLoader); }
//text
virtual FontManager *newFontManager() {return new FontManager();}

View File

@@ -22,6 +22,9 @@ namespace Shared{ namespace Graphics{ namespace Gl{
// =====================================================
class ModelGl: public Model{
friend class GraphicsFactoryGl;
protected:
ModelGl(const string &path,TextureManager* textureManager,bool deletePixMapAfterLoad,std::map<string,vector<pair<string, string> > > *loadedFileList, string *sourceLoader);
public:
virtual void init(){}
virtual void end(){}

View File

@@ -13,6 +13,11 @@
#define _SHARED_GRAPHICS_GRAPHICSFACTORY_H_
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
using std::string;
#include "leak_dumper.h"
namespace Shared{ namespace Graphics{
@@ -64,7 +69,7 @@ public:
//models
virtual ModelManager *newModelManager() {return NULL;}
virtual ModelRenderer *newModelRenderer() {return NULL;}
virtual Model *newModel() {return NULL;}
virtual Model *newModel(const string &path,TextureManager* textureManager,bool deletePixMapAfterLoad,std::map<string,std::vector<std::pair<string, string> > > *loadedFileList, string *sourceLoader) {return NULL;}
//text
virtual FontManager *newFontManager() {return NULL;}

View File

@@ -35,7 +35,7 @@ enum ResourceScope {
class RendererInterface {
public:
virtual Texture2D *newTexture2D(ResourceScope rs) = 0;
virtual Model *newModel(ResourceScope rs) = 0;
virtual Model *newModel(ResourceScope rs,const string &path,bool deletePixMapAfterLoad=false,std::map<string,vector<pair<string, string> > > *loadedFileList=NULL, string *sourceLoader=NULL) = 0;
virtual ~RendererInterface() {}
};

View File

@@ -221,9 +221,7 @@ public:
uint32 getVertexCount() const;
//io
void load(const string &path,bool deletePixMapAfterLoad=false,std::map<string,vector<pair<string, string> > > *loadedFileList=NULL, string *sourceLoader=NULL);
void save(const string &path, string convertTextureToFormat,bool keepsmallest);
void loadG3d(const string &path,bool deletePixMapAfterLoad=false,std::map<string,vector<pair<string, string> > > *loadedFileList=NULL, string sourceLoader="");
void saveG3d(const string &path, string convertTextureToFormat,bool keepsmallest);
void setTextureManager(TextureManager *textureManager) {this->textureManager= textureManager;}
@@ -234,6 +232,11 @@ public:
void toEndian();
void fromEndian();
protected:
void load(const string &path,bool deletePixMapAfterLoad=false,std::map<string,vector<pair<string, string> > > *loadedFileList=NULL, string *sourceLoader=NULL);
void loadG3d(const string &path,bool deletePixMapAfterLoad=false,std::map<string,vector<pair<string, string> > > *loadedFileList=NULL, string sourceLoader="");
private:
void buildInterpolationData() const;
void autoJoinMeshFrames();

View File

@@ -38,7 +38,7 @@ public:
ModelManager();
virtual ~ModelManager();
Model *newModel();
Model *newModel(const string &path,bool deletePixMapAfterLoad,std::map<string,vector<pair<string, string> > > *loadedFileList, string *sourceLoader);
void init();
void end();

View File

@@ -0,0 +1,21 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#include "model_gl.h"
namespace Shared{ namespace Graphics{ namespace Gl{
ModelGl::ModelGl(const string &path,TextureManager* textureManager,bool deletePixMapAfterLoad,std::map<string,vector<pair<string, string> > > *loadedFileList, string *sourceLoader) {
setTextureManager(textureManager);
load(path,deletePixMapAfterLoad,loadedFileList,sourceLoader);
}
}}}//end namespace

View File

@@ -512,7 +512,7 @@ void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *tex
}
fromEndianVecArray<Vec3f>(normals, frameCount*vertexCount);
if(textures[mtDiffuse] != NULL) {
if(textureFlags & (1<<mtDiffuse)) {
readBytes = fread(texCoords, sizeof(Vec2f)*vertexCount, 1, f);
if(readBytes != 1 && vertexCount != 0) {
char szBuf[8096]="";
@@ -650,7 +650,7 @@ void Mesh::loadV3(int meshIndex, const string &dir, FILE *f,
}
fromEndianVecArray<Vec3f>(normals, frameCount*vertexCount);
if(textures[mtDiffuse] != NULL) {
if(textureFlags & (1<<mtDiffuse)) {
for(unsigned int i=0; i<meshHeader.texCoordFrameCount; ++i){
readBytes = fread(texCoords, sizeof(Vec2f)*vertexCount, 1, f);
if(readBytes != 1 && vertexCount != 0) {
@@ -744,7 +744,7 @@ void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textu
bool deletePixMapAfterLoad,std::map<string,vector<pair<string, string> > > *loadedFileList,
string sourceLoader,string modelFile) {
this->textureManager = textureManager;
//read header
MeshHeader meshHeader;
size_t readBytes = fread(&meshHeader, sizeof(MeshHeader), 1, f);
@@ -788,7 +788,7 @@ void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textu
//maps
uint32 flag= 1;
for(int i = 0; i < meshTextureCount; ++i) {
if((meshHeader.textures & flag) && textureManager != NULL) {
if(meshHeader.textures & flag) {
uint8 cMapPath[mapPathSize];
readBytes = fread(cMapPath, mapPathSize, 1, f);
if(readBytes != 1 && mapPathSize != 0) {
@@ -804,13 +804,14 @@ void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textu
string mapFullPath= dir;
if(mapFullPath != "") {
endPathWithSlash(mapFullPath);
endPathWithSlash(mapFullPath);
}
mapFullPath += mapPath;
textures[i] = loadMeshTexture(meshIndex, i, textureManager, mapFullPath,
meshTextureChannelCount[i],texturesOwned[i],
deletePixMapAfterLoad, loadedFileList, sourceLoader,modelFile);
if(textureManager) {
textures[i] = loadMeshTexture(meshIndex, i, textureManager, mapFullPath,
meshTextureChannelCount[i],texturesOwned[i],
deletePixMapAfterLoad, loadedFileList, sourceLoader,modelFile);
}
}
flag *= 2;
}
@@ -1834,7 +1835,6 @@ unsigned int BaseColorPickEntity::nextColorRGB = BaseColorPickEntity::k;
//Mutex BaseColorPickEntity::mutexNextColorID;
unsigned char BaseColorPickEntity::nextColorID[COLOR_COMPONENTS] = { 1, 1, 1, 0 };
auto_ptr<PixelBufferWrapper> BaseColorPickEntity::pbo;
map<string,bool> BaseColorPickEntity::usedColorIDList;

View File

@@ -40,9 +40,8 @@ ModelManager::~ModelManager(){
end();
}
Model *ModelManager::newModel(){
Model *model= GraphicsInterface::getInstance().getFactory()->newModel();
model->setTextureManager(textureManager);
Model *ModelManager::newModel(const string &path,bool deletePixMapAfterLoad,std::map<string,vector<pair<string, string> > > *loadedFileList, string *sourceLoader){
Model *model= GraphicsInterface::getInstance().getFactory()->newModel(path,textureManager,deletePixMapAfterLoad,loadedFileList,sourceLoader);
models.push_back(model);
return model;
}

View File

@@ -74,6 +74,7 @@
#ifdef __APPLE__
#include <mach-o/dyld.h>
#include <sys/param.h>
#endif
#include "leak_dumper.h"

View File

@@ -33,6 +33,15 @@ using namespace Shared::PlatformCommon;
namespace Shared{ namespace Platform{
// Example values:
// DEFAULT_CHARSET (English) = 1
// GB2312_CHARSET (Chinese) = 134
#ifdef WIN32
DWORD PlatformContextGl::charSet = DEFAULT_CHARSET;
#else
int PlatformContextGl::charSet = 1;
#endif
// ======================================
// class PlatformContextGl
// ======================================

View File

@@ -121,55 +121,60 @@ static int getFileAndLine(char *function, void *address, char *file, size_t flen
// prepare command to be executed
// our program need to be passed after the -e parameter
#if __APPLE_CC__
snprintf(buf, 8096,"xcrun atos -v -o %s %p",PlatformExceptionHandler::application_binary.c_str(),address);
fprintf(stderr,"> %s\n",buf);
#else
snprintf(buf, 8096,"addr2line -C -e %s -f -i %p",PlatformExceptionHandler::application_binary.c_str(),address);
#endif
FILE* f = popen (buf, "r");
if (f == NULL) {
perror (buf);
return 0;
}
#if __APPLE_CC__
//### TODO Will: still working this out
int len = fread(buf,1,maxbufSize,f);
buf[len] = 0;
fprintf(stderr,"< %s",buf);
return -1;
#endif
for(;function != NULL && function[0] != '\0';) {
// get function name
char *ret = fgets (buf, maxbufSize, f);
if(ret == NULL) {
pclose(f);
return line;
}
//printf("Looking for [%s] Found [%s]\n",function,ret);
if(strstr(ret,function) != NULL) {
break;
}
// get file and line
ret = fgets (buf, maxbufSize, f);
if(ret == NULL) {
pclose(f);
return line;
}
if(function != NULL && function[0] != '\0') {
line = 0;
for(;function != NULL && function[0] != '\0';) {
// get function name
char *ret = fgets (buf, maxbufSize, f);
if(ret == NULL) {
pclose(f);
return line;
}
//printf("Looking for [%s] Found [%s]\n",function,ret);
if(strstr(ret,function) != NULL) {
break;
}
if(strlen(buf) > 0 && buf[0] != '?') {
//int l;
char *p = buf;
// file name is until ':'
while(*p != 0 && *p != ':') {
p++;
}
// get file and line
ret = fgets (buf, maxbufSize, f);
if(ret == NULL) {
pclose(f);
return line;
}
if(strlen(buf) > 0 && buf[0] != '?') {
//int l;
char *p = buf;
// file name is until ':'
while(*p != 0 && *p != ':') {
p++;
}
*p++ = 0;
// after file name follows line number
strcpy (file , buf);
sscanf (p,"%10d", &line);
}
else {
strcpy (file,"unknown");
line = 0;
}
}
}
*p++ = 0;
// after file name follows line number
strcpy (file , buf);
sscanf (p,"%10d", &line);
}
else {
strcpy (file,"unknown");
line = 0;
}
}
// get file and line
char *ret = fgets (buf, maxbufSize, f);

View File

@@ -28,14 +28,6 @@ using namespace Shared::Util;
namespace Shared { namespace Platform {
// Example values:
// DEFAULT_CHARSET (English) = 1
// GB2312_CHARSET (Chinese) = 134
#ifdef WIN32
DWORD PlatformContextGl::charSet = DEFAULT_CHARSET;
#else
int PlatformContextGl::charSet = 1;
#endif
// ======================================
// Global Fcs