Isometric World Editor download - new version with more enhancements!

Started by
19 comments, last by the_moo 18 years, 9 months ago
right you are syranide! (most of it anyways)
the .iwd files are the tile map files that contain all relevant information that is needed by the map.
it completely slipped my mind that someone might actually want to test loading/drawing a map they made from it so i didnt put the loading code up yet.
thats the part where you're wrong syranide [wink]! ive completely finished the loader in both pascal and c++ (how else would the editor load the map then [smile]) for the current version of the editor.
obviously what api/method you use of drawing the map is up to you but here's the loading code for all you interested:
  typedef struct _ForeStat {    int X, Y, Z, ImageNum, CellNum, RowNum;    bool Drawn;  }ForeStat;  typedef struct _Sizes {    int X, Y;  }Sizes;  typedef struct _World {    std::string Name;    int SizeX, SizeY, SizeZ, TileX, TileY, TileH;    std::string *BackImages, *ForeImages, *Music;    Sizes *ForeImSize;    int *ObjectCount;    int ImageCount, ObImCount, MusicCount;    bool Loaded;    Stat ***Background; /*stat is a struct that contains the tile info -                          int ImageNum, CellNum, RowNum, StoreCell, StoreRow;                          bool Exsists, Draw;*/    ForeStat **Foreground;  }World;bool ReadLineTo(char to, bool atstart, std::string line,                  std::string &data)   {     data = "";     if (atstart == TRUE)     {       i = 0;       while (line != ' ')       { ++i; }     }     ++i;     while (line != to)     { data = data+line;       ++i; }   }     bool SearchString(const std::string& my_string,                    const std::string& substring)   {    std::string::size_type position = my_string.find(substring);    bool string_found = (position != std::string::npos);    return (string_found);   }  //note that this loader is for use with direct3d 8 so any textures or images//will be loaded in different ways depending on the api  World MapData;  bool LoadMap(LPDIRECT3DDEVICE8 &lpdd, char *filename)   {    std::ifstream mapfile(filename);    std::string linedata, temp;        while (std::getline(mapfile,linedata))    {     if (linedata[0] == '#')     {      if (SearchString(linedata,"NAME: "))      { ReadLineTo(';',TRUE,linedata,temp);        MapData.Name = temp;         name = temp.c_str();         }      if (SearchString(linedata,"SIZEX: "))      { ReadLineTo(';',TRUE,linedata,temp);        MapData.SizeX = atoi(temp.c_str());         }      if (SearchString(linedata,"SIZEZ: "))      { ReadLineTo(';',TRUE,linedata,temp);        MapData.SizeZ = atoi(temp.c_str());         }      if (SearchString(linedata,"SIZEY: "))      { ReadLineTo(';',TRUE,linedata,temp);        MapData.SizeY = atoi(temp.c_str());        }      if (SearchString(linedata,"TILEX: "))      { ReadLineTo(';',TRUE,linedata,temp);        MapData.TileX = atoi(temp.c_str());         }      if (SearchString(linedata,"TILEY: "))      { ReadLineTo(';',TRUE,linedata,temp);        MapData.TileY = atoi(temp.c_str());         }      if (SearchString(linedata,"TILEH: "))      { ReadLineTo(';',TRUE,linedata,temp);        MapData.TileH = atoi(temp.c_str());         }      if (SearchString(linedata,"IMAGECOUNT: "))      { ReadLineTo(';',TRUE,linedata,temp);        MapData.ImageCount = atoi(temp.c_str());         }      if (SearchString(linedata,"OBJECTIMCOUNT: "))      { ReadLineTo(';',TRUE,linedata,temp);        MapData.ObImCount = atoi(temp.c_str());         }      if (SearchString(linedata,"OBJECTCOUNT: "))      { i = 0; n = 0;        while (linedata != ' ') { ++i; }        MapData.ObjectCount = new int[MapData.SizeY];        if (MapData.SizeY > 1)         { while (linedata != ';')           {            if (n < MapData.SizeY-1)            { ReadLineTo(',',FALSE,linedata,temp); }            else { ReadLineTo(';',FALSE,linedata,temp); }            MapData.ObjectCount[n] = atoi(temp.c_str());            ++n;           }         }        else if (MapData.SizeY == 1)        { ReadLineTo(';',FALSE,linedata,temp);          MapData.ObjectCount[n] = atoi(temp.c_str()); }      }      if (SearchString(linedata,"MUSICCOUNT: "))      { ReadLineTo(';',TRUE,linedata,temp);        MapData.MusicCount = atoi(temp.c_str());      }      if (SearchString(linedata,"MUSIC: "))      {        if (MapData.MusicCount > 0)       {        i = 0; n = 0;        while (linedata != ' ') { ++i; }        MapData.Music = new std::string[MapData.MusicCount];        if (MapData.MusicCount > 1)         {          while (linedata != ';')           {            if (n < MapData.MusicCount-1)             { ReadLineTo(',',FALSE,linedata,temp);               ++i; }            else { ReadLineTo(';',FALSE,linedata,temp); }            MapData.Music[n] = temp;            ++n;           }         }         else          { if (MapData.MusicCount == 1)           { ReadLineTo(';',FALSE,linedata,temp);             MapData.Music[n] = temp; }         }       }      }      if (SearchString(linedata,"BACKIMAGES: "))       {        int s;        i = 0; n = 0;        while (linedata != ' ') { ++i; }        MapData.BackImages = new std::string[MapData.ImageCount];        Images = new D3DImage[MapData.ImageCount];        if (MapData.ImageCount > 0)         {          while (linedata != ';')           {            ReadLineTo('[',FALSE,linedata,temp);            MapData.BackImages[n] = temp;            ReadLineTo(',',FALSE,linedata,temp);            Images[n].texcolcount = atoi(temp.c_str());            ReadLineTo('(',FALSE,linedata,temp);            Images[n].texrowcount = atoi(temp.c_str());            ReadLineTo(')',FALSE,linedata,temp);            ReadLineTo(']',FALSE,linedata,temp);            ++i;            ++n;           }        }       }       if (SearchString(linedata,"BACKGROUND: "))       {        int in1, in2, in3, imnum, cellnum, rownum;        i = 0;        while (linedata != ' ') { ++i; }        ++i;        MapData.Background = new Stat**[MapData.SizeX];        for (int x = 0; x < MapData.SizeX; ++x)        { MapData.Background[x] = new Stat*[MapData.SizeZ];          for (int z = 0; z < MapData.SizeZ; ++z)            MapData.Background[x][z] = new Stat[MapData.SizeY]; }        for (int x = 0; x < MapData.SizeX; ++x)         for (int z = 0; z < MapData.SizeZ; ++z)          for (int y = 0; y < MapData.SizeY; ++y)          {            MapData.Background[x][z][y].Exsists = FALSE;            MapData.Background[x][z][y].Draw = FALSE;            MapData.Background[x][z][y].ImageNum = -1;            MapData.Background[x][z][y].CellNum = -1;            MapData.Background[x][z][y].RowNum = -1;            MapData.Background[x][z][y].StoreCell = -1;            MapData.Background[x][z][y].StoreRow = -1;          }        while (linedata != ';')         {          if (linedata == '[')           {            ReadLineTo(',',FALSE,linedata,temp);            in1 = atoi(temp.c_str());            ReadLineTo(',',FALSE,linedata,temp);            in2 = atoi(temp.c_str());            ReadLineTo('=',FALSE,linedata,temp);            in3 = atoi(temp.c_str());            ReadLineTo(',',FALSE,linedata,temp);            imnum = atoi(temp.c_str());            ReadLineTo(',',FALSE,linedata,temp);            cellnum = atoi(temp.c_str());            ReadLineTo(']',FALSE,linedata,temp);            rownum = atoi(temp.c_str());            MapData.Background[in1][in2][in3].ImageNum = imnum;            MapData.Background[in1][in2][in3].CellNum = cellnum;            MapData.Background[in1][in2][in3].RowNum = rownum;            MapData.Background[in1][in2][in3].StoreCell = cellnum;            MapData.Background[in1][in2][in3].StoreRow = rownum;            MapData.Background[in1][in2][in3].Exsists = TRUE;            MapData.Background[in1][in2][in3].Draw = TRUE;          }          ++i;        }        for (int x = 0; x < MapData.SizeX; ++x)         for (int z = 0; z < MapData.SizeZ; ++z)          for (int y = 0; y < MapData.SizeY; ++y)            if (y < MapData.SizeY-1 &&                MapData.Background[x][z][y+1].Exsists)            { MapData.Background[x][z][y].Exsists = FALSE;              MapData.Background[x][z][y].Draw = FALSE; }       }       if (SearchString(linedata,"FOREIMAGES: "))       {        i = 0; n = 0;        if (MapData.ObImCount > 0)        {         while (linedata != ' ') { ++i; }         MapData.ForeImages = new std::string[MapData.ObImCount];         MapData.ForeImSize = new Sizes[MapData.ObImCount];         ForeImages = new D3DImage[MapData.ObImCount];         while (linedata != ';')           {            ReadLineTo('[',FALSE,linedata,temp);            MapData.ForeImages[n] = temp;            ReadLineTo('=',FALSE,linedata,temp);            ReadLineTo(',',FALSE,linedata,temp);            ReadLineTo('-',FALSE,linedata,temp);            ReadLineTo(',',FALSE,linedata,temp);            MapData.ForeImSize[n].X = atoi(temp.c_str());            ReadLineTo(']',FALSE,linedata,temp);            MapData.ForeImSize[n].Y = atoi(temp.c_str());            ++i; ++n;           }        }       }       if (SearchString(linedata,"FOREGROUND: "))       {        int i1,i2,i3,t,n;        i = 0;        while (linedata != ' ') { ++i; }        ++i;        MapData.Foreground = new ForeStat*[MapData.SizeY];        for (int c = 0; c < MapData.SizeY-1; ++c)        { if (MapData.ObjectCount[c] > 0)          MapData.Foreground[c] =             new ForeStat[MapData.ObjectCount[c]]; }        for (int n = 0; n < MapData.SizeY; ++n)         {t = 0;          for (int c = 0; c < MapData.ObjectCount[n]; ++c)          {           if (linedata == '(')           {            ReadLineTo(',',FALSE,linedata,temp);            i1 = atoi(temp.c_str());            ReadLineTo(',',FALSE,linedata,temp);            i2 = atoi(temp.c_str());            ReadLineTo('=',FALSE,linedata,temp);            i3 = atoi(temp.c_str());            MapData.Foreground[i3][t].X = i1;            MapData.Foreground[i3][t].Z = i2;            MapData.Foreground[i3][t].Y = i3;            ReadLineTo(',',FALSE,linedata,temp);            MapData.Foreground[i3][t].ImageNum = atoi(temp.c_str());            ReadLineTo(',',FALSE,linedata,temp);            MapData.Foreground[i3][t].CellNum = atoi(temp.c_str());            ReadLineTo(')',FALSE,linedata,temp);            MapData.Foreground[i3][t].RowNum = atoi(temp.c_str());           }          ++i; ++t;          }         }       }     }    }    if (MapData.ImageCount > 0)    { for (int c = 0; c < MapData.ImageCount; ++c)      {        //load the image data for the current tileset image (c) however      }    }    if (MapData.ObImCount > 0)    { for (int c = 0; c < MapData.ObImCount; ++c)      {       //load the image data for the current object image (c) however you like      }    }             MapData.Loaded = TRUE;   }

ok there we go!
i know its not great code but it gets the job done with no errors so i figure thats good enough for the moment.
if anything needs to be explained here just ask and ill see what i can do, but basically it all just initialises sizes of arrays and loads the map data into the World struct.
also, please dont comment on my use of "typedef" - for some reason i have never been able to compile a project without it (yes i use c++) in dev c++. if you dont normally use it, just get rid of it [wink].
lastly, sorry about the lack of comments (ie. almost none), but i didnt plan on this being used by anyone but me so i didnt put any in cause i understand the process and what each if does and i know the file format.

anywho, hope someone can make use of this then and if anyone does, i hope you find it useful (let us all know [smile]).

[edit] oh by the way, thanks for the support Daniel Miller and Syranide, its good to hear that people like it. [/edit]
the_moo

This topic is closed to new replies.

Advertisement