netpanzer-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netPanzer-CVS] netpanzer/src/Editor TemplateCreator.cpp TileSe...


From: Matthias Braun
Subject: [netPanzer-CVS] netpanzer/src/Editor TemplateCreator.cpp TileSe...
Date: Wed, 19 Nov 2003 12:25:08 -0500

CVSROOT:        /cvsroot/netpanzer
Module name:    netpanzer
Branch:         
Changes by:     Matthias Braun <address@hidden> 03/11/19 12:25:08

Modified files:
        src/Editor     : TemplateCreator.cpp TileSet.cpp 
                         TileSetEditor.cpp TileSetEditor.hpp 

Log message:
        several robustness fixes to editor tileset handling code along with 
some small UI improvements

Patches:
Index: netpanzer/src/Editor/TemplateCreator.cpp
diff -u netpanzer/src/Editor/TemplateCreator.cpp:1.1 
netpanzer/src/Editor/TemplateCreator.cpp:1.2
--- netpanzer/src/Editor/TemplateCreator.cpp:1.1        Sun Nov 16 17:40:59 2003
+++ netpanzer/src/Editor/TemplateCreator.cpp    Wed Nov 19 12:25:07 2003
@@ -49,8 +49,11 @@
 {
     try {
         TileTemplate* tiletemplate = selectwidget->createTemplate(tileset);
+
         (void) tiletemplate;
-        // XXX TODO blabla...
+        // XXX TODO
+
+        Close();
     } catch(std::exception& e) {
         wxMessageDialog(this, e.what(), "Error", wxOK | 
wxICON_ERROR).ShowModal();    
     }
Index: netpanzer/src/Editor/TileSet.cpp
diff -u netpanzer/src/Editor/TileSet.cpp:1.1 
netpanzer/src/Editor/TileSet.cpp:1.2
--- netpanzer/src/Editor/TileSet.cpp:1.1        Sun Nov 16 17:40:59 2003
+++ netpanzer/src/Editor/TileSet.cpp    Wed Nov 19 12:25:07 2003
@@ -1,5 +1,6 @@
 #include <config.h>
 
+#include <iostream>
 #include <stdint.h>
 #include <memory>
 
@@ -32,7 +33,7 @@
 
 TileSetHeader::TileSetHeader()
     : fileformatversion(FILEFORMATVERSION), tilewidth(32), tileheight(32),
-      tilebitsperpixel(32), tilecount(0)
+      tilebitsperpixel(24), tilecount(0)
 {
     strncpy(magic, MAGICSTRING, 4);
     for(size_t i=0;i<sizeof(reserved)/sizeof(uint32_t); i++)
@@ -107,13 +108,14 @@
     header = fileheader.release();
     
     delete[] tiledata;
+    tilebuffersize = 0;
+    tiledata = 0;
+    
     tilesize = header->tilewidth * header->tileheight * 
(header->tilebitsperpixel / 8);
-    if(tiledata > 0) {
+    if(header->tilecount > 0) {
         resizeBuffer(tilesize * header->tilecount);
         if(file.read(tiledata, tilesize, header->tilecount) != 
header->tilecount)
             throw Exception("Tileset file is too short.");
-    } else {
-        tiledata = 0;
     }
 }
 
@@ -163,12 +165,12 @@
         }
     }
 
-    if(rect->x + rect->w >= surface->w ||
-       rect->y + rect->h >= surface->h)
+    if(rect->x + rect->w > surface->w ||
+       rect->y + rect->h > surface->h)
         throw Exception("Invalid source rectangle, can't add tile");
 
-    if(tilesize * header->tilecount > tilebuffersize)
-        resizeBuffer(tilebuffersize * 2);
+    if(tilesize * (header->tilecount+1) > tilebuffersize)
+        resizeBuffer(tilebuffersize * 2 + tilesize);
 
     int bpp = surface->format->BytesPerPixel;
     char* sptr = ((char*) surface->pixels) +
@@ -211,5 +213,6 @@
 
     delete[] tiledata;
     tiledata = newbuffer.release();
+    tilebuffersize = newbuffersize;
 }
 
Index: netpanzer/src/Editor/TileSetEditor.cpp
diff -u netpanzer/src/Editor/TileSetEditor.cpp:1.1 
netpanzer/src/Editor/TileSetEditor.cpp:1.2
--- netpanzer/src/Editor/TileSetEditor.cpp:1.1  Sun Nov 16 17:40:59 2003
+++ netpanzer/src/Editor/TileSetEditor.cpp      Wed Nov 19 12:25:07 2003
@@ -25,6 +25,7 @@
 
 TileSetEditor::~TileSetEditor()
 {
+    saveTileSet();
     delete currenttileset;
 }
 
@@ -33,15 +34,38 @@
     switchTileSet((const char*) evt.GetText());
 }
 
+void TileSetEditor::saveTileSet()
+{
+    try {
+        if(currenttileset) {
+            std::auto_ptr<WriteFile>
+                file(FileSystem::openWrite(filename.c_str()));        
+            currenttileset->save(*(file.get()));
+        }                                                                 
+    } catch(std::exception& e) {
+        std::string errormsg = "Couldn't save Tileset to '";
+        errormsg += filename ;
+        errormsg += "' : ";
+        errormsg += e.what();
+        wxMessageDialog(this, errormsg.c_str(),
+                "Error", wxOK | wxICON_ERROR).ShowModal();
+    }
+}
+
 bool TileSetEditor::switchTileSet(const std::string& newtileset)
 {
+    saveTileSet();
+
+    delete currenttileset;
+    currenttileset = 0;
+    tilesetview->setTileSet(0);    
+    
     try {
-        std::string filename = "/tileset/";
+        filename = "/tileset/";
         filename += newtileset;
         filename += "/tiles.dat";
         std::auto_ptr<ReadFile> file (FileSystem::openRead(filename.c_str()));
 
-        delete currenttileset; currenttileset = 0;
         currenttileset = new TileSet();
         currenttileset->load(*(file.get()));
 
Index: netpanzer/src/Editor/TileSetEditor.hpp
diff -u netpanzer/src/Editor/TileSetEditor.hpp:1.1 
netpanzer/src/Editor/TileSetEditor.hpp:1.2
--- netpanzer/src/Editor/TileSetEditor.hpp:1.1  Sun Nov 16 17:40:59 2003
+++ netpanzer/src/Editor/TileSetEditor.hpp      Wed Nov 19 12:25:07 2003
@@ -19,10 +19,13 @@
 private:
     void OnItemSelected(wxListEvent& event);
     bool switchTileSet(const std::string& tileset);
+
+    void saveTileSet();
     
     TileSetList* tilesetlist;
     TileSetView* tilesetview;
 
+    std::string filename;
     TileSet* currenttileset;
 
     DECLARE_EVENT_TABLE()




reply via email to

[Prev in Thread] Current Thread [Next in Thread]