|
From: Charles L. <cn...@us...> - 2005-12-18 07:56:29
|
Update of /cvsroot/hgengine/Mercury/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8238 Modified Files: MercuryFiles.cpp MercuryFiles.h MercuryMilkshapeModel.cpp MercuryModel.cpp MercuryModel.h MercuryTexture.cpp Log Message: Move everything to the new file system. Index: MercuryFiles.cpp =================================================================== RCS file: /cvsroot/hgengine/Mercury/src/MercuryFiles.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MercuryFiles.cpp 18 Dec 2005 07:24:08 -0000 1.2 --- MercuryFiles.cpp 18 Dec 2005 07:56:18 -0000 1.3 *************** *** 21,24 **** --- 21,47 ---- } + bool MercuryFile::ReadLine( CString & data ) + { + data = ""; + char b1[1]; + bool Success; + while ( Success = ( Read( b1, 1 ) > 0 ) ) + { + if ( ( b1[0] == '\r' ) || ( b1[0] == '\n' ) ) + break; + data += b1[0]; + } + + //We're using windows, check to make sure we don't have an extra \n. + if ( b1[0] == '\r' ) + { + unsigned long loc = Tell(); + Read( b1, 1 ); + if ( b1[0] != '\n' ) + Seek(loc); + } + + return Success; + } MercuryFileObjectDirect::MercuryFileObjectDirect( ): Index: MercuryMilkshapeModel.cpp =================================================================== RCS file: /cvsroot/hgengine/Mercury/src/MercuryMilkshapeModel.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MercuryMilkshapeModel.cpp 30 Nov 2005 02:56:59 -0000 1.7 --- MercuryMilkshapeModel.cpp 18 Dec 2005 07:56:18 -0000 1.8 *************** *** 17,21 **** void MercuryMilkshapeModel::LoadModel() { ! if (!m_file.is_open()) { LOG.Warn("File not opened."); --- 17,21 ---- void MercuryMilkshapeModel::LoadModel() { ! if (m_file==NULL) { LOG.Warn("File not opened."); *************** *** 23,29 **** } ! while (!m_file.eof()) { ! getline(m_file, m_line); FrameLoader(); --- 23,29 ---- } ! while (!m_file->Eof()) { ! m_file->ReadLine( m_line ); FrameLoader(); *************** *** 34,38 **** } ! m_file.close(); // m_model = NULL; } --- 34,38 ---- } ! SAFE_DELETE( m_file ); // m_model = NULL; } *************** *** 66,71 **** for (m_iMesh = 0; m_iMesh < numMeshes; m_iMesh++) { ! if(!m_file.eof()) ! getline(m_file, m_line); else throw; --- 66,71 ---- for (m_iMesh = 0; m_iMesh < numMeshes; m_iMesh++) { ! if(!m_file->Eof()) ! m_file->ReadLine( m_line ); else throw; *************** *** 112,117 **** float uv[2]; ! if(!m_file.eof()) ! getline(m_file, m_line); else throw; --- 112,117 ---- float uv[2]; ! if(!m_file->Eof()) ! m_file->ReadLine( m_line ); else throw; *************** *** 123,128 **** for (unsigned int i = 0; i < m_numVerts; i++) { ! if(!m_file.eof()) ! getline(m_file, m_line); else throw; --- 123,128 ---- for (unsigned int i = 0; i < m_numVerts; i++) { ! if(!m_file->Eof()) ! m_file->ReadLine( m_line ); else throw; *************** *** 148,153 **** float x,y,z; ! if(!m_file.eof()) ! getline(m_file, m_line); else throw; --- 148,153 ---- float x,y,z; ! if(!m_file->Eof()) ! m_file->ReadLine(m_line); else throw; *************** *** 165,170 **** for (unsigned int i = 0; i < nNumNormals; i++) { ! if(!m_file.eof()) ! getline(m_file, m_line); else throw; --- 165,170 ---- for (unsigned int i = 0; i < nNumNormals; i++) { ! if(!m_file->Eof()) ! m_file->ReadLine(m_line); else throw; *************** *** 190,195 **** int flag, index; ! if(!m_file.eof()) ! getline(m_file, m_line); else throw; --- 190,195 ---- int flag, index; ! if(!m_file->Eof()) ! m_file->ReadLine(m_line); else throw; *************** *** 200,205 **** for (unsigned int i = 0; i < numTri; i++) { ! if(!m_file.eof()) ! getline(m_file, m_line); else throw; --- 200,205 ---- for (unsigned int i = 0; i < numTri; i++) { ! if(!m_file->Eof()) ! m_file->ReadLine(m_line); else throw; *************** *** 252,261 **** material = new MercuryMaterial; { ! getline(m_file, m_line); material->m_name = m_line.substr(1,m_line.find("\"", 1)-1); if (material->m_name.size() <= 0) throw CString("Texture has no name"); ! std::getline(m_file, m_line); if (sscanf (m_line, "%f %f %f %f", &r, &g, &b, &a) != 4) throw CString(m_line); --- 252,261 ---- material = new MercuryMaterial; { ! m_file->ReadLine(m_line); material->m_name = m_line.substr(1,m_line.find("\"", 1)-1); if (material->m_name.size() <= 0) throw CString("Texture has no name"); ! m_file->ReadLine(m_line); if (sscanf (m_line, "%f %f %f %f", &r, &g, &b, &a) != 4) throw CString(m_line); *************** *** 266,270 **** material->m_ambient.SetA(a); ! std::getline(m_file, m_line); if (sscanf (m_line, "%f %f %f %f", &r, &g, &b, &a) != 4) throw CString(m_line); --- 266,270 ---- material->m_ambient.SetA(a); ! m_file->ReadLine(m_line); if (sscanf (m_line, "%f %f %f %f", &r, &g, &b, &a) != 4) throw CString(m_line); *************** *** 275,279 **** material->m_diffuse.SetA(a); ! std::getline(m_file, m_line); if (sscanf (m_line, "%f %f %f %f", &r, &g, &b, &a) != 4) throw CString(m_line); --- 275,279 ---- material->m_diffuse.SetA(a); ! m_file->ReadLine(m_line); if (sscanf (m_line, "%f %f %f %f", &r, &g, &b, &a) != 4) throw CString(m_line); *************** *** 284,288 **** material->m_specular.SetA(a); ! std::getline(m_file, m_line); if (sscanf (m_line, "%f %f %f %f", &r, &g, &b, &a) != 4) throw CString(m_line); --- 284,288 ---- material->m_specular.SetA(a); ! m_file->ReadLine(m_line); if (sscanf (m_line, "%f %f %f %f", &r, &g, &b, &a) != 4) throw CString(m_line); *************** *** 293,311 **** material->m_emissive.SetA(a); ! std::getline(m_file, m_line); if (sscanf (m_line, "%f", &material->m_shininess) != 1) throw CString(m_line); ! std::getline(m_file, m_line); if (sscanf (m_line, "%f", &material->m_alpha) != 1) throw CString(m_line); //The two images ! std::getline(m_file, m_line); material->m_difftext = m_path.c_str() + m_line.substr(1,m_line.find("\"", 1)-1); if (m_line.substr(1,m_line.find("\"", 1)-1).length() > 0) material->m_diffuse_texture.LoadBMP(material->m_difftext); ! std::getline(m_file, m_line); material->m_alphatext = m_path.c_str() + m_line.substr(1,m_line.find("\"", 1)-1); if (m_line.substr(1,m_line.find("\"", 1)-1).length() > 0) --- 293,311 ---- material->m_emissive.SetA(a); ! m_file->ReadLine(m_line); if (sscanf (m_line, "%f", &material->m_shininess) != 1) throw CString(m_line); ! m_file->ReadLine(m_line); if (sscanf (m_line, "%f", &material->m_alpha) != 1) throw CString(m_line); //The two images ! m_file->ReadLine(m_line); material->m_difftext = m_path.c_str() + m_line.substr(1,m_line.find("\"", 1)-1); if (m_line.substr(1,m_line.find("\"", 1)-1).length() > 0) material->m_diffuse_texture.LoadBMP(material->m_difftext); ! m_file->ReadLine(m_line); material->m_alphatext = m_path.c_str() + m_line.substr(1,m_line.find("\"", 1)-1); if (m_line.substr(1,m_line.find("\"", 1)-1).length() > 0) Index: MercuryTexture.cpp =================================================================== RCS file: /cvsroot/hgengine/Mercury/src/MercuryTexture.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** MercuryTexture.cpp 18 Dec 2005 07:24:08 -0000 1.23 --- MercuryTexture.cpp 18 Dec 2005 07:56:18 -0000 1.24 *************** *** 50,56 **** m_path = path; ! ifstream file; ! file.open(path.c_str(), ios::binary); ! if (!file.is_open()) { LOG.Warn("Could not open BMP \"" + path + "\""); --- 50,55 ---- m_path = path; ! MercuryFile * file = FILEMAN.Open( path ); ! if (file==NULL) { LOG.Warn("Could not open BMP \"" + path + "\""); *************** *** 61,65 **** //Get the type of file and test memset(tmp, 0, 4); ! file.read(tmp, sizeof(char)*2); CString type(tmp); --- 60,64 ---- //Get the type of file and test memset(tmp, 0, 4); ! file->Read(tmp, sizeof(char)*2); CString type(tmp); *************** *** 71,89 **** } //Offset of bitmap data. ! file.seekg(10); ! file.read(tmp, 4); memcpy(&offset, tmp, 4); //width & width ! file.seekg(18); ! file.read(tmp, sizeof(int)); memcpy(&m_width, tmp, sizeof(int)); ! file.read(tmp, sizeof(int)); memcpy(&m_height, tmp, sizeof(int)); //bits per pixel memset(tmp, 0, sizeof(int)); ! file.seekg(28); ! file.read(tmp, sizeof(int)); memcpy(&bitsapix, tmp, sizeof(int)); --- 70,88 ---- } //Offset of bitmap data. ! file->Seek(10); ! file->Read(tmp, 4); memcpy(&offset, tmp, 4); //width & width ! file->Seek(18); ! file->Read(tmp, sizeof(int)); memcpy(&m_width, tmp, sizeof(int)); ! file->Read(tmp, sizeof(int)); memcpy(&m_height, tmp, sizeof(int)); //bits per pixel memset(tmp, 0, sizeof(int)); ! file->Seek(28); ! file->Read(tmp, sizeof(int)); memcpy(&bitsapix, tmp, sizeof(int)); *************** *** 96,101 **** //compression ! file.seekg(30); ! file.read(tmp, sizeof(int)); memcpy(&compression, tmp, sizeof(int)); --- 95,100 ---- //compression ! file->Seek(30); ! file->Read(tmp, sizeof(int)); memcpy(&compression, tmp, sizeof(int)); *************** *** 109,120 **** //pix/m X memset(tmp, 0, sizeof(int)); ! file.seekg(38); ! file.read(tmp, sizeof(int)); memcpy(&res_x, tmp, sizeof(int)); //pix/m Y memset(tmp, 0, sizeof(int)); ! file.seekg(42); ! file.read(tmp, sizeof(int)); memcpy(&res_y, tmp, sizeof(int)); --- 108,119 ---- //pix/m X memset(tmp, 0, sizeof(int)); ! file->Seek(38); ! file->Read(tmp, sizeof(int)); memcpy(&res_x, tmp, sizeof(int)); //pix/m Y memset(tmp, 0, sizeof(int)); ! file->Seek(42); ! file->Read(tmp, sizeof(int)); memcpy(&res_y, tmp, sizeof(int)); *************** *** 130,135 **** //Get the file length ! file.seekg(0, ios::end); ! length = file.tellg(); rawlength = (length) - (offset-1); //Remember to subtract 1 from the offset. --- 129,133 ---- //Get the file length ! length = file->Length(); rawlength = (length) - (offset-1); //Remember to subtract 1 from the offset. *************** *** 139,147 **** //Get raw data and convert BGR->RGB ! file.seekg(offset); ! for (unsigned int x = 0; !file.eof(); x += 3) { memset(b, 0, sizeof(unsigned char)*3); ! file.read((char*)&b, sizeof(unsigned char)*3); m_data[x] = b[2]; --- 137,145 ---- //Get raw data and convert BGR->RGB ! file->Seek(offset); ! for (unsigned int x = 0; !file->Eof(); x += 3) { memset(b, 0, sizeof(unsigned char)*3); ! file->Read((char*)&b, sizeof(unsigned char)*3); m_data[x] = b[2]; *************** *** 149,153 **** m_data[x+2] = b[0]; } ! file.close(); m_alpha = false; --- 147,151 ---- m_data[x+2] = b[0]; } ! file->Close(); m_alpha = false; Index: MercuryModel.h =================================================================== RCS file: /cvsroot/hgengine/Mercury/src/MercuryModel.h,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** MercuryModel.h 30 Nov 2005 02:38:45 -0000 1.25 --- MercuryModel.h 18 Dec 2005 07:56:18 -0000 1.26 *************** *** 8,11 **** --- 8,12 ---- #include "MercuryMaterial.h" #include "MercuryTypes.h" + #include "MercuryFiles.h" #if defined(_MSC_VER) && (_MSC_VER > 1100) *************** *** 76,82 **** protected: void OpenFile(const CString path); ! void CloseFile() { m_file.close(); } virtual void LoadModel() = 0; ! ifstream m_file; CString m_path; --- 77,83 ---- protected: void OpenFile(const CString path); ! void CloseFile() { SAFE_DELETE( m_file ); } virtual void LoadModel() = 0; ! MercuryFile * m_file; CString m_path; Index: MercuryFiles.h =================================================================== RCS file: /cvsroot/hgengine/Mercury/src/MercuryFiles.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MercuryFiles.h 18 Dec 2005 07:24:08 -0000 1.2 --- MercuryFiles.h 18 Dec 2005 07:56:18 -0000 1.3 *************** *** 32,35 **** --- 32,37 ---- /** Returns the number of bytes read */ virtual unsigned long Read( void * data, unsigned long length ) = 0; + /** Reads one line from the file. */ + virtual bool ReadLine( CString & data ); /** Returns non-zero value if there's an error */ virtual bool Check() = 0; Index: MercuryModel.cpp =================================================================== RCS file: /cvsroot/hgengine/Mercury/src/MercuryModel.cpp,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** MercuryModel.cpp 17 Dec 2005 22:58:07 -0000 1.32 --- MercuryModel.cpp 18 Dec 2005 07:56:18 -0000 1.33 *************** *** 13,16 **** --- 13,17 ---- { m_polys = 0; + m_file = NULL; } *************** *** 70,76 **** void MercuryModel::OpenFile(const CString path) { ! m_file.open(path.c_str()); ! if (!m_file.is_open()) { LOG.Warn("File not oppened:" + path); --- 71,78 ---- void MercuryModel::OpenFile(const CString path) { ! SAFE_DELETE(m_file); ! m_file = FILEMAN.Open(path); ! if (m_file==NULL) { LOG.Warn("File not oppened:" + path); |