// Copyright (C) 2002-2012 Nikolaus Gebhardt // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h // // This file was originally written by Salvatore Russo. // I (Nikolaus Gebhardt) did some minor modifications changes to it and integrated // it into Irrlicht: // - removed STL dependency // - removed log file and replaced it with irrlicht logging // - adapted code formatting a bit to Irrlicht style // - removed memory leaks // Thanks a lot to Salvatore for his work on this and that he gave me // his permission to add it into Irrlicht. // This support library has been made by Salvatore Russo and is released under GNU public license for general uses. // For uses in Irrlicht core and only for Irrlicht related uses I release this library under zlib license. #ifndef __DMF_SUPPORT_H_INCLUDED__ #define __DMF_SUPPORT_H_INCLUDED__ #include "irrString.h" #include "fast_atof.h" namespace irr { namespace scene { namespace { /** A structure representing some DeleD infos. This structure contains data about DeleD level file like: version, ambient color, number of objects etc...*/ struct dmfHeader { //main file header core::stringc dmfName; //! tileNum;//! StringList; //Loads a stringlist from a file //note that each String added to StringList //is separated by a \\n character and it's present //at the end of line. /** Loads a StringList from a file. This function loads a StringList from a file where each string is divided by a \\n char.*/ void LoadFromFile(io::IReadFile* file, StringList& strlist) { const long sz = file->getSize(); char* buf = new char[sz+1]; file->read(buf, sz); buf[sz] = 0; char* p = buf; char* start = p; while(*p) { if (*p == '\n') { core::stringc str(start, (u32)(p - start - 1)); str.trim(); strlist.push_back(str); start = p+1; } ++p; } if (p - start > 1) { core::stringc str(start, (u32)(p - start - 1)); str.trim(); strlist.push_back(str); } delete [] buf; }; //This function subdivides a string in a list of strings /** This function subdivides strings divided by divider in a list of strings. \return A StringList made of all strings divided by divider.*/ StringList SubdivideString(const core::stringc& str, const core::stringc& divider) { StringList strings; //returned StringList strings.clear(); //clear returned stringlist int c=0; int l=str.size(); //process entire string while(c& materials, int num_material) { // offset for already handled lines const int offs=4; StringList temp; StringList temp1; // The number of materials is predetermined materials.reallocate(num_material); for(int i=0; i=9) { temp1=SubdivideString(temp[temp.size() - 1],","); materials[i].lightmapFlag=atoi(temp1[0].c_str()); materials[i].lightmapName=temp1[1]; materials[i].lightmapName.replace('\\','/'); materials[i].lightmapBlend = atoi(temp1[2].c_str()); } else { materials[i].lightmapFlag=1; materials[i].lightmapName=""; } } return true; } /**This function extract an array of dmfVert and dmfFace from a DMF file. You must give in input a StringList representing a DMF file loaded with LoadFromFile and two arrays long enough. Please use GetDMFHeader() before this function to know number of vertices and faces. \return true if function succeed or false on fail.*/ bool GetDMFVerticesFaces(const StringList& RawFile/** pos; const u32 posCount = core::strtoul10(RawFile[offs].c_str()); ++offs; pos.reallocate(posCount); for (u32 i=0; i& materials/**= 0.91 temp=SubdivideString(RawFile[0],";");//file info if ( temp[0] != "DeleD Map File" ) return false;//not a deled file temp.clear(); temp=SubdivideString(RawFile[1]," ");//get version temp1=SubdivideString(temp[1],";"); if (atof(temp1[0].c_str()) < 0.91) return false;//not correct version //end checking temp.clear(); temp1.clear(); for(int i=0;i= 0.91 temp=SubdivideString(RawFile[0],";");//file info if ( temp[0] != "DeleD Map File" ) return false;//not a deled file temp.clear(); temp=SubdivideString(RawFile[1]," ");//get version temp1=SubdivideString(temp[1],";"); if (atof(temp1[0].c_str()) < 0.91) return false;//not correct version //end checking temp.clear(); temp1.clear(); offs=offs + atoi(RawFile[offs].c_str()); offs++; s32 objs = atoi(RawFile[offs].c_str()); s32 lit=0; s32 d_lit=0; offs++; //let's get position of lights in file int i; for(i=0;i= 0.91 temp=SubdivideString(RawFile[0],";");//file info if ( temp[0] != "DeleD Map File" ) return false;//not a deled file temp.clear(); temp=SubdivideString(RawFile[1]," ");//get version temp1=SubdivideString(temp[1],";"); if (atof(temp1[0].c_str()) < 0.91) return false;//not correct version //end checking temp.clear(); temp1.clear(); offs=offs+atoi(RawFile[offs].c_str()); offs++; s32 objs=atoi(RawFile[offs].c_str()); s32 fac=0,vert=0,tmp_sz=0,vert_cnt=0,face_cnt=0,wat_id=0; core::dimension2d tilenum(40,40); f32 waveheight=3.0f; f32 wavespeed=300.0f; f32 wavelength=80.0f; offs++; for(int i=0;i