(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
authorrubidium
Sun, 09 Sep 2007 10:13:17 +0000
changeset 7545 d44e19c5671e
parent 7544 cac538ba670a
child 7546 c4f9132d9f1e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
src/clear_cmd.cpp
src/functions.h
src/gfx.cpp
src/gfx.h
src/signs.cpp
src/station.h
src/station_cmd.cpp
src/texteff.cpp
src/town_cmd.cpp
src/vehicle.cpp
src/vehicle.h
src/viewport.cpp
src/water_cmd.cpp
src/window.h
--- a/src/clear_cmd.cpp	Sat Sep 08 22:53:10 2007 +0000
+++ b/src/clear_cmd.cpp	Sun Sep 09 10:13:17 2007 +0000
@@ -47,7 +47,14 @@
 	int modheight_count;                                         ///< amount of entries in "modheight".
 	int tile_table_count;                                        ///< amount of entries in "tile_table".
 
-	TileIndex tile_table[TERRAFORMER_TILE_TABLE_SIZE];           ///< Dirty tiles, i.e. at least one corner changed.
+	/**
+	 * Dirty tiles, i.e.\ at least one corner changed.
+	 *
+	 * This array contains the tiles which are or will be marked as dirty.
+	 *
+	 * @ingroup dirty
+	 */
+	TileIndex tile_table[TERRAFORMER_TILE_TABLE_SIZE];
 	TerraformerHeightMod modheight[TERRAFORMER_MODHEIGHT_SIZE];  ///< Height modifications.
 };
 
@@ -106,6 +113,7 @@
  *
  * @param ts TerraformerState.
  * @param tile Tile.
+ * @ingroup dirty
  */
 static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile)
 {
@@ -128,6 +136,7 @@
  *
  * @param ts TerraformerState.
  * @param tile Tile.
+ * @ingroup dirty
  */
 static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile)
 {
--- a/src/functions.h	Sat Sep 08 22:53:10 2007 +0000
+++ b/src/functions.h	Sun Sep 09 10:13:17 2007 +0000
@@ -103,7 +103,18 @@
 void ConvertNameArray();
 
 /* misc functions */
+/**
+ * Mark a tile given by its coordinate dirty for repaint.
+ *
+ * @ingroup dirty
+ */
 void MarkTileDirty(int x, int y);
+
+/**
+ * Mark a tile given by its index dirty for repaint.
+ *
+ * @ingroup dirty
+ */
 void MarkTileDirtyByTile(TileIndex tile);
 void InvalidateWindow(WindowClass cls, WindowNumber number);
 void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index);
@@ -124,6 +135,12 @@
 void DrawSprite(SpriteID img, SpriteID pal, int x, int y);
 bool EnsureNoVehicle(TileIndex tile);
 bool EnsureNoVehicleOnGround(TileIndex tile);
+
+/**
+ * Mark all viewports dirty for repaint.
+ *
+ * @ingroup dirty
+ */
 void MarkAllViewportsDirty(int left, int top, int right, int bottom);
 void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost);
 void ShowFeederIncomeAnimation(int x, int y, int z, Money cost);
--- a/src/gfx.cpp	Sat Sep 08 22:53:10 2007 +0000
+++ b/src/gfx.cpp	Sun Sep 09 10:13:17 2007 +0000
@@ -48,6 +48,14 @@
 FontSize _cur_fontsize;
 static FontSize _last_fontsize;
 static uint8 _cursor_backup[64 * 64 * 4];
+
+/**
+ * The rect for repaint.
+ *
+ * This rectangle defines the area which should be repaint by the video driver.
+ *
+ * @ingroup dirty
+ */
 static Rect _invalid_rect;
 static const byte *_color_remap_ptr;
 static byte _string_colorremap[3];
@@ -269,7 +277,8 @@
 	GfxFillRect((xl + xr - w) / 2, y + 10, (xl + xr + w) / 2, y + 10, _string_colorremap[1]);
 }
 
-/** 'Correct' a string to a maximum length. Longer strings will be cut into
+/**
+ * 'Correct' a string to a maximum length. Longer strings will be cut into
  * additional lines at whitespace characters if possible. The string parameter
  * is modified with terminating characters mid-string which are the
  * placeholders for the newlines.
@@ -284,7 +293,8 @@
  * @param maxw the maximum width the string can have on one line
  * @return return a 32bit wide number consisting of 2 packed values:
  *  0 - 15 the number of lines ADDED to the string
- * 16 - 31 the fontsize in which the length calculation was done at */
+ * 16 - 31 the fontsize in which the length calculation was done at
+ */
 uint32 FormatStringLinebreaks(char *str, int maxw)
 {
 	FontSize size = _cur_fontsize;
@@ -919,6 +929,11 @@
 	_video_driver->MakeDirty(left, top, right - left, bottom - top);
 }
 
+/*!
+ * Repaints the rectangle blocks which are marked as 'dirty'.
+ *
+ * @see SetDirtyBlocks
+ */
 void DrawDirtyBlocks()
 {
 	byte *b = _dirty_blocks;
@@ -1003,7 +1018,21 @@
 	}
 }
 
-
+/*!
+ * This function extends the internal _invalid_rect rectangle as it
+ * now contains the rectangle defined by the given parameters. Note
+ * the point (0,0) is top left.
+ *
+ * @param left The left edge of the rectangle
+ * @param top The top edge of the rectangle
+ * @param right The right edge of the rectangle
+ * @param bottom The bottm edge of the rectangle
+ * @see DrawDirtyBlocks
+ *
+ * @todo The name of the function should be called like @c AddDirtyBlock as
+ *       it neither set a dirty rect nor add several dirty rects although
+ *       the function name is in plural. (Progman)
+ */
 void SetDirtyBlocks(int left, int top, int right, int bottom)
 {
 	byte *b;
@@ -1041,6 +1070,11 @@
 	} while (--height != 0);
 }
 
+/*!
+ * This function mark the whole screen as dirty. This results in repainting
+ * the whole screen. Use this with care as this function will break the
+ * idea about marking only parts of the screen as 'dirty'.
+ */
 void MarkWholeScreenDirty()
 {
 	SetDirtyBlocks(0, 0, _screen.width, _screen.height);
--- a/src/gfx.h	Sat Sep 08 22:53:10 2007 +0000
+++ b/src/gfx.h	Sun Sep 09 10:13:17 2007 +0000
@@ -2,6 +2,36 @@
 
 /** @file gfx.h */
 
+/**
+ * @defgroup dirty Dirty
+ *
+ * Handles the repaint of some part of the screen.
+ *
+ * Some places in the code are called functions which makes something "dirty".
+ * This has nothing to do with making a Tile or Window darker or less visible.
+ * This term comes from memory caching and is used to define an object must
+ * be repaint. If some data of an object (like a Tile, Window, Vehicle, whatever)
+ * are changed which are so extensive the object must be repaint its marked
+ * as "dirty". The video driver repaint this object instead of the whole screen
+ * (this is btw. also possible if needed). This is used to avoid a
+ * flickering of the screen by the video driver constantly repainting it.
+ *
+ * This whole mechanism is controlled by an rectangle defined in #_invalid_rect. This
+ * rectangle defines the area on the screen which must be repaint. If a new object
+ * needs to be repainted this rectangle is extended to 'catch' the object on the
+ * screen. At some point (which is normaly uninteressted for patch writers) this
+ * rectangle is send to the video drivers method
+ * VideoDriver::MakeDirty and it is truncated back to an empty rectangle. At some
+ * later point (which is uninteressted, too) the video driver
+ * repaints all these saved rectangle instead of the whole screen and drop the
+ * rectangle informations. Then a new round begins by marking objects "dirty".
+ *
+ * @see VideoDriver::MakeDirty
+ * @see _invalid_rect
+ * @see _screen
+ */
+
+
 #ifndef GFX_H
 #define GFX_H
 
@@ -244,8 +274,26 @@
 void LoadStringWidthTable();
 void DrawStringMultiCenter(int x, int y, StringID str, int maxw);
 uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh = -1);
+
+/**
+ * Let the dirty blocks repainting by the video driver.
+ *
+ * @ingroup dirty
+ */
 void DrawDirtyBlocks();
+
+/**
+ * Set a new dirty block.
+ *
+ * @ingroup dirty
+ */
 void SetDirtyBlocks(int left, int top, int right, int bottom);
+
+/**
+ * Marks the whole screen as dirty.
+ *
+ * @ingroup dirty
+ */
 void MarkWholeScreenDirty();
 
 void GfxInitPalettes();
--- a/src/signs.cpp	Sat Sep 08 22:53:10 2007 +0000
+++ b/src/signs.cpp	Sun Sep 09 10:13:17 2007 +0000
@@ -60,10 +60,12 @@
 }
 
 /**
+ * Marks the region of a sign as dirty.
  *
- * Marks the region of a sign as dirty
+ * This function marks the sign in all viewports as dirty for repaint.
  *
  * @param si Pointer to the Sign
+ * @ingroup dirty
  */
 static void MarkSignDirty(Sign *si)
 {
--- a/src/station.h	Sat Sep 08 22:53:10 2007 +0000
+++ b/src/station.h	Sun Sep 09 10:13:17 2007 +0000
@@ -173,7 +173,19 @@
 	virtual ~Station();
 
 	void AddFacility(byte new_facility_bit, TileIndex facil_xy);
+
+	/**
+	 * Mark the sign of a station dirty for repaint.
+	 *
+	 * @ingroup dirty
+	 */
 	void MarkDirty() const;
+
+	/**
+	 * Marks the tiles of the station as dirty.
+	 *
+	 * @ingroup dirty
+	 */
 	void MarkTilesDirty(bool cargo_change) const;
 	bool TileBelongsToRailStation(TileIndex tile) const;
 	uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
--- a/src/station_cmd.cpp	Sat Sep 08 22:53:10 2007 +0000
+++ b/src/station_cmd.cpp	Sun Sep 09 10:13:17 2007 +0000
@@ -375,7 +375,14 @@
 	}
 }
 
-// Update the station virt coords while making the modified parts dirty.
+/**
+ * Update the station virt coords while making the modified parts dirty.
+ *
+ * This function updates the virt coords and mark the modified parts as dirty
+ *
+ * @param st The station to update the virt coords
+ * @ingroup dirty
+ */
 static void UpdateStationVirtCoordDirty(Station *st)
 {
 	st->MarkDirty();
--- a/src/texteff.cpp	Sat Sep 08 22:53:10 2007 +0000
+++ b/src/texteff.cpp	Sun Sep 09 10:13:17 2007 +0000
@@ -256,7 +256,15 @@
 	_chatmessage_dirty = false;
 }
 
-/** Text Effects */
+/* Text Effects */
+/**
+ * Mark the area of the text effect as dirty.
+ *
+ * This function marks the area of a text effect as dirty for repaint.
+ *
+ * @param te The TextEffect to mark the area dirty
+ * @ingroup dirty
+ */
 static void MarkTextEffectAreaDirty(TextEffect *te)
 {
 	/* Width and height of the text effect are doubled, so they are correct in both zoom out levels 1x and 2x. */
--- a/src/town_cmd.cpp	Sat Sep 08 22:53:10 2007 +0000
+++ b/src/town_cmd.cpp	Sun Sep 09 10:13:17 2007 +0000
@@ -256,8 +256,12 @@
 }
 
 /**
- * Marks the town sign as needing a repaint
- * @param t Town requesting repaint
+ * Marks the town sign as needing a repaint.
+ *
+ * This function marks the area of the sign of a town as dirty for repaint.
+ *
+ * @param t Town requesting town sign for repaint
+ * @ingroup dirty
  */
 static void MarkTownSignDirty(Town *t)
 {
--- a/src/vehicle.cpp	Sat Sep 08 22:53:10 2007 +0000
+++ b/src/vehicle.cpp	Sun Sep 09 10:13:17 2007 +0000
@@ -1491,7 +1491,7 @@
 		ShowVehicleGettingOld(v, STR_01A0_IS_GETTING_OLD);
 	} else if (age == 0) {
 		ShowVehicleGettingOld(v, STR_01A1_IS_GETTING_VERY_OLD);
-	} else if ((age % 366) == 0) {
+	} else if (age > 0 && (age % 366) == 0) {
 		ShowVehicleGettingOld(v, STR_01A2_IS_GETTING_VERY_OLD_AND);
 	}
 }
--- a/src/vehicle.h	Sat Sep 08 22:53:10 2007 +0000
+++ b/src/vehicle.h	Sun Sep 09 10:13:17 2007 +0000
@@ -384,6 +384,11 @@
 
 	/**
 	 * Marks the vehicles to be redrawn and updates cached variables
+	 *
+	 * This method marks the area of the vehicle on the screen as dirty.
+	 * It can be use to repaint the vehicle.
+	 *
+	 * @ingroup dirty
 	 */
 	virtual void MarkDirty() {}
 
--- a/src/viewport.cpp	Sat Sep 08 22:53:10 2007 +0000
+++ b/src/viewport.cpp	Sun Sep 09 10:13:17 2007 +0000
@@ -1440,6 +1440,14 @@
 	}
 }
 
+/**
+ * Marks a viewport as dirty for repaint.
+ *
+ * @param vp The viewport to mark as dirty
+ * @todo documents the missing parameters @c left, @c top, @c right and @c bottom
+ * @todo detailed description missing
+ * @ingroup dirty
+ */
 static void MarkViewportDirty(const ViewPort *vp, int left, int top, int right, int bottom)
 {
 	right -= vp->virtual_left;
@@ -1505,6 +1513,14 @@
 	);
 }
 
+/**
+ * Marks the selected tiles as dirty.
+ *
+ * This function marks the selected tiles as dirty for repaint
+ *
+ * @note Documentation may be wrong (Progman)
+ * @ingroup dirty
+ */
 static void SetSelectionTilesDirty()
 {
 	int y_size, x_size;
--- a/src/water_cmd.cpp	Sat Sep 08 22:53:10 2007 +0000
+++ b/src/water_cmd.cpp	Sun Sep 09 10:13:17 2007 +0000
@@ -183,6 +183,15 @@
 	return CommandCost(_price.clear_water * 2);
 }
 
+/**
+ * Marks the tiles around a tile as dirty.
+ *
+ * This functions marks the tiles around a given tile as dirty for repaint.
+ *
+ * @param tile The center of the tile where all other tiles are marked as dirty
+ * @ingroup dirty
+ * @see TerraformAddDirtyTileAround
+ */
 static void MarkTilesAroundDirty(TileIndex tile)
 {
 	MarkTileDirtyByTile(TILE_ADDXY(tile, 0, 1));
--- a/src/window.h	Sat Sep 08 22:53:10 2007 +0000
+++ b/src/window.h	Sun Sep 09 10:13:17 2007 +0000
@@ -565,6 +565,12 @@
 /* window.cpp */
 void CallWindowEventNP(Window *w, int event);
 void CallWindowTickEvent();
+
+/**
+ * Marks the window as dirty for repaint.
+ *
+ * @ingroup dirty
+ */
 void SetWindowDirty(const Window *w);
 void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam);
 void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam);