[Bug 62109] Redrawing is very slow over network connection

Mauricio Piacentini mauricio at tabuleiro.com
Fri Oct 27 03:12:28 UTC 2006


------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
         
http://bugs.kde.org/show_bug.cgi?id=62109         
mauricio tabuleiro com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From mauricio tabuleiro com  2006-10-27 05:12 -------
SVN commit 599425 by piacentini:

After a lot of preparation, finally removed full redraw at every tile 
addition and removal. There is still some room for optimization, but at 
800x600 play area the game is now using less than 1% of a 2GHz cpu, 
with minimal redrawings. 
Unfortunately, this change is for KDE4 only and  can not be backported 
to 3.5.x series.
BUG: 62109
CCBUG: 62109


 M  +52 -19    boardwidget.cpp  
 M  +2 -1      boardwidget.h  


--- trunk/KDE/kdegames/kmahjongg/boardwidget.cpp #599424:599425
 @ -161,8 +161,7  @
   resize(width() , height());
 }
 
-
-void BoardWidget::updateSpriteMap() {
+void BoardWidget::populateSpriteMap() {
     QPixmap  *back;
 
     int xx = rect().left();
 @ -175,11 +174,9  @
 
     spriteMap.clear();
 
-    //if (!backsprite) {
-      back = theBackground.getBackground();
-      backsprite = new KGameCanvasPixmap(*back, this);
-      backsprite->show();
-    //}
+    back = theBackground.getBackground();
+    backsprite = new KGameCanvasPixmap(*back, this);
+    backsprite->show();
 
     // initial offset on the screen of tile 0,0
     int xOffset = theTiles.width()/2;
 @ -210,25 +207,53  @
 				Game->BoardData(z,y,x)-TILE_OFFSET);
                 }
 
-		//if (!spriteMap.contains(QString("X%1Y%2Z%3").arg(x).arg(y).arg(z)))
-		//{
 		  KGameCanvasPixmap * thissprite = new KGameCanvasPixmap(*t, this);
 
-		  //if (Game->tilePresent(z, y-1, x-2)) {
-		    //qDebug() << "overlap at " << y << x;
-		  //}
 		  thissprite->moveTo(sx, sy);
 		  thissprite->show();
-		  //spriteMap.insert(QString("X%1Y%2Z%3").arg(x).arg(y).arg(z), thissprite);
 		  spriteMap.insert(TileCoord(x,y,z), thissprite);
-		//}
             }
         }
         xOffset +=theTiles.levelOffset();
         yOffset -=theTiles.levelOffset();
     }
 
+    updateSpriteMap();
+}
+
+
+void BoardWidget::updateSpriteMap() {
+    // initial offset on the screen of tile 0,0
+    int xOffset = theTiles.width()/2;
+    int yOffset = theTiles.height()/2;
+    //short tile = 0;
+
+    // we iterate over the depth stacking order. Each successive level is
+    // drawn one indent up and to the right. The indent is the width
+    // of the 3d relief on the tile left (tile shadow width)
     for (int z=0; z<Game->m_depth; z++) {
+        // we draw down the board so the tile below over rights our border
+        for (int y = 0; y < Game->m_height; y++) {
+            // drawing right to left to prevent border overwrite
+            for (int x=Game->m_width-1; x>=0; x--) {
+                int sx = x*(theTiles.qWidth()  )+xOffset;
+                int sy = y*(theTiles.qHeight()  )+yOffset;
+
+		// skip if no tile to display
+		if (!Game->tilePresent(z,y,x))
+			continue;
+
+		  KGameCanvasPixmap * thissprite =spriteMap.value(TileCoord(x,y,z));
+
+		  if (thissprite) thissprite->moveTo(sx, sy);
+		  if (thissprite) thissprite->show();
+            }
+        }
+        xOffset +=theTiles.levelOffset();
+        yOffset -=theTiles.levelOffset();
+    }
+
+    for (int z=0; z<Game->m_depth; z++) {
         // start drawing in diagonal for correct layering. For this we double the board, 
 	//actually starting outside of it, in the bottom right corner, so our first diagonal ends
 	// at the actual top right corner of the board
 @ -250,7 +275,6  @
     //qDebug() << items()->size();
     //qDebug() << spriteMap.size();
     update();
-
 }
 
 // for a given cell x y calc how that cell is shadowed
 @ -773,9 +797,7  @
 void BoardWidget::drawBoard(bool )
 {
    updateBackBuffer=true;
-  // updateSpriteMap();
-  // update(); 
-   updateSpriteMap();
+   populateSpriteMap();
    drawTileNumber();
 }
 
 @ -789,6 +811,14  @
 	// we ensure that any tile we put on has highlighting off
     Game->putTile( E, Y, X, Pos.f );
     Game->setHighlightData(E,Y,X,0);
+
+    QPixmap *t;
+    t= theTiles.unselectedPixmaps(Game->BoardData(E,Y,X)-TILE_OFFSET);
+    KGameCanvasPixmap * thissprite = new KGameCanvasPixmap(*t, this);
+    //thissprite->moveTo(sx, sy);
+    thissprite->show();
+     spriteMap.insert(TileCoord(X,Y,E), thissprite);
+
     if (doRepaint) {
 	updateBackBuffer=true;
 	update(); 
 @ -808,12 +838,15  @
     Game->TileNum--;                    // Eine Figur weniger
     Game->setMoveListData(Game->TileNum,Pos); // Position ins Protokoll eintragen
 
+    KGameCanvasPixmap * thissprite =spriteMap.value(TileCoord(X,Y,E));
+    if (thissprite) delete thissprite;
+    spriteMap.remove(TileCoord(X,Y,E));
     // remove tile from game board
     Game->putTile( E, Y, X, 0 );
     if (doRepaint) {
         updateBackBuffer=true;
 	update(); 
-	updateSpriteMap();
+//	updateSpriteMap();
     }
 }
 
--- trunk/KDE/kdegames/kmahjongg/boardwidget.h #599424:599425
 @ -86,7 +86,8  @
         bool loadBoard      ( );
         void updateScaleMode ();
         void drawBoard(bool deferUpdate = true);
-	void updateSpriteMap(); 
+	void updateSpriteMap();
+	void populateSpriteMap();
         bool loadBackground ( const QString&, bool bShowError = true );
     signals:
         void statusTextChanged ( const QString&, long );


------- Additional Comments From mauricio tabuleiro com  2006-10-27 05:12 -------
SVN commit 599425 by piacentini:

After a lot of preparation, finally removed full redraw at every tile 
addition and removal. There is still some room for optimization, but at 
800x600 play area the game is now using less than 1% of a 2GHz cpu, 
with minimal redrawings. 
Unfortunately, this change is for KDE4 only and  can not be backported 
to 3.5.x series.
BUG: 62109
CCBUG: 62109


 M  +52 -19    boardwidget.cpp  
 M  +2 -1      boardwidget.h  


--- trunk/KDE/kdegames/kmahjongg/boardwidget.cpp #599424:599425
 @ -161,8 +161,7  @
   resize(width() , height());
 }
 
-
-void BoardWidget::updateSpriteMap() {
+void BoardWidget::populateSpriteMap() {
     QPixmap  *back;
 
     int xx = rect().left();
 @ -175,11 +174,9  @
 
     spriteMap.clear();
 
-    //if (!backsprite) {
-      back = theBackground.getBackground();
-      backsprite = new KGameCanvasPixmap(*back, this);
-      backsprite->show();
-    //}
+    back = theBackground.getBackground();
+    backsprite = new KGameCanvasPixmap(*back, this);
+    backsprite->show();
 
     // initial offset on the screen of tile 0,0
     int xOffset = theTiles.width()/2;
 @ -210,25 +207,53  @
 				Game->BoardData(z,y,x)-TILE_OFFSET);
                 }
 
-		//if (!spriteMap.contains(QString("X%1Y%2Z%3").arg(x).arg(y).arg(z)))
-		//{
 		  KGameCanvasPixmap * thissprite = new KGameCanvasPixmap(*t, this);
 
-		  //if (Game->tilePresent(z, y-1, x-2)) {
-		    //qDebug() << "overlap at " << y << x;
-		  //}
 		  thissprite->moveTo(sx, sy);
 		  thissprite->show();
-		  //spriteMap.insert(QString("X%1Y%2Z%3").arg(x).arg(y).arg(z), thissprite);
 		  spriteMap.insert(TileCoord(x,y,z), thissprite);
-		//}
             }
         }
         xOffset +=theTiles.levelOffset();
         yOffset -=theTiles.levelOffset();
     }
 
+    updateSpriteMap();
+}
+
+
+void BoardWidget::updateSpriteMap() {
+    // initial offset on the screen of tile 0,0
+    int xOffset = theTiles.width()/2;
+    int yOffset = theTiles.height()/2;
+    //short tile = 0;
+
+    // we iterate over the depth stacking order. Each successive level is
+    // drawn one indent up and to the right. The indent is the width
+    // of the 3d relief on the tile left (tile shadow width)
     for (int z=0; z<Game->m_depth; z++) {
+        // we draw down the board so the tile below over rights our border
+        for (int y = 0; y < Game->m_height; y++) {
+            // drawing right to left to prevent border overwrite
+            for (int x=Game->m_width-1; x>=0; x--) {
+                int sx = x*(theTiles.qWidth()  )+xOffset;
+                int sy = y*(theTiles.qHeight()  )+yOffset;
+
+		// skip if no tile to display
+		if (!Game->tilePresent(z,y,x))
+			continue;
+
+		  KGameCanvasPixmap * thissprite =spriteMap.value(TileCoord(x,y,z));
+
+		  if (thissprite) thissprite->moveTo(sx, sy);
+		  if (thissprite) thissprite->show();
+            }
+        }
+        xOffset +=theTiles.levelOffset();
+        yOffset -=theTiles.levelOffset();
+    }
+
+    for (int z=0; z<Game->m_depth; z++) {
         // start drawing in diagonal for correct layering. For this we double the board, 
 	//actually starting outside of it, in the bottom right corner, so our first diagonal ends
 	// at the actual top right corner of the board
 @ -250,7 +275,6  @
     //qDebug() << items()->size();
     //qDebug() << spriteMap.size();
     update();
-
 }
 
 // for a given cell x y calc how that cell is shadowed
 @ -773,9 +797,7  @
 void BoardWidget::drawBoard(bool )
 {
    updateBackBuffer=true;
-  // updateSpriteMap();
-  // update(); 
-   updateSpriteMap();
+   populateSpriteMap();
    drawTileNumber();
 }
 
 @ -789,6 +811,14  @
 	// we ensure that any tile we put on has highlighting off
     Game->putTile( E, Y, X, Pos.f );
     Game->setHighlightData(E,Y,X,0);
+
+    QPixmap *t;
+    t= theTiles.unselectedPixmaps(Game->BoardData(E,Y,X)-TILE_OFFSET);
+    KGameCanvasPixmap * thissprite = new KGameCanvasPixmap(*t, this);
+    //thissprite->moveTo(sx, sy);
+    thissprite->show();
+     spriteMap.insert(TileCoord(X,Y,E), thissprite);
+
     if (doRepaint) {
 	updateBackBuffer=true;
 	update(); 
 @ -808,12 +838,15  @
     Game->TileNum--;                    // Eine Figur weniger
     Game->setMoveListData(Game->TileNum,Pos); // Position ins Protokoll eintragen
 
+    KGameCanvasPixmap * thissprite =spriteMap.value(TileCoord(X,Y,E));
+    if (thissprite) delete thissprite;
+    spriteMap.remove(TileCoord(X,Y,E));
     // remove tile from game board
     Game->putTile( E, Y, X, 0 );
     if (doRepaint) {
         updateBackBuffer=true;
 	update(); 
-	updateSpriteMap();
+//	updateSpriteMap();
     }
 }
 
--- trunk/KDE/kdegames/kmahjongg/boardwidget.h #599424:599425
 @ -86,7 +86,8  @
         bool loadBoard      ( );
         void updateScaleMode ();
         void drawBoard(bool deferUpdate = true);
-	void updateSpriteMap(); 
+	void updateSpriteMap();
+	void populateSpriteMap();
         bool loadBackground ( const QString&, bool bShowError = true );
     signals:
         void statusTextChanged ( const QString&, long );



More information about the pkg-kde-bugs-fwd mailing list