gnome-games r8648 - trunk/gnometris



Author: jclinton
Date: Tue Feb  3 18:55:58 2009
New Revision: 8648
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8648&view=rev

Log:
Make renderer render cells and cache instead of the whole field.

This set of changes does away with the concept of the renderer as a
slave that draws the entire field by itteration through field block
data. Instead, the renderer has been paired down to knowledge of only
how to draw an individual cell in anticipation of renderer handling its
own cache of the seven block colors and providing textures to blockops
on demand when requested.

Also, this commit splits blockops out in to to pieces so that Actor
movement logic can be kept in blockops.

Added:
   trunk/gnometris/blockops-noclutter.cpp
      - copied, changed from r8647, /trunk/gnometris/blockops.cpp
   trunk/gnometris/blockops-noclutter.h
      - copied, changed from r8647, /trunk/gnometris/blockops.h
Removed:
   trunk/gnometris/block-cache.cpp
   trunk/gnometris/block-cache.h
Modified:
   trunk/gnometris/Makefile.am
   trunk/gnometris/blockops.cpp
   trunk/gnometris/blockops.h
   trunk/gnometris/field.cpp
   trunk/gnometris/field.h
   trunk/gnometris/renderer.cpp
   trunk/gnometris/renderer.h
   trunk/gnometris/tetris.cpp

Modified: trunk/gnometris/Makefile.am
==============================================================================
--- trunk/gnometris/Makefile.am	(original)
+++ trunk/gnometris/Makefile.am	Tue Feb  3 18:55:58 2009
@@ -6,8 +6,6 @@
 	main.cpp \
 	blocks.cpp \
 	blocks.h \
-	blockops.cpp \
-	blockops.h \
 	highscores.cpp \
 	highscores.h \
 	scoreframe.cpp \
@@ -21,16 +19,18 @@
 	field.h \
 	preview.cpp \
 	preview.h \
+	blockops.cpp \
+	blockops.h \
 	renderer.cpp \
-	renderer.h \
-	block-cache.cpp \
-	block-cache.h
+	renderer.h
 else
 gnometris_SOURCES += \
 	field-noclutter.cpp \
 	field-noclutter.h \
 	preview-noclutter.cpp \
 	preview-noclutter.h \
+	blockops-noclutter.cpp \
+	blockops-noclutter.h \
 	renderer-noclutter.cpp \
 	renderer-noclutter.h
 endif
@@ -72,8 +72,8 @@
 #	blocks.h \
 #	preview-noclutter.cpp \
 #	preview-noclutter.h \
-#	blockops.cpp \
-#	blockops.h \
+#	blockops-noclutter.cpp \
+#	blockops-noclutter.h \
 #	field-noclutter.cpp \
 #	field-noclutter.h \
 #	highscores.cpp \

Copied: trunk/gnometris/blockops-noclutter.cpp (from r8647, /trunk/gnometris/blockops.cpp)
==============================================================================
--- /trunk/gnometris/blockops.cpp	(original)
+++ trunk/gnometris/blockops-noclutter.cpp	Tue Feb  3 18:55:58 2009
@@ -20,22 +20,16 @@
  */
 
 #include <config.h>
-#include "blockops.h"
+#include "blockops-noclutter.h"
 #include "blocks.h"
 
-#ifdef HAVE_CLUTTER
-#include "field.h"
-#else
-#include "field-noclutter.h"
-#endif
+// #include "field-noclutter.h"
 
 #define NCOLOURS 7
 
 
 BlockOps::BlockOps() :
-#ifndef HAVE_CLUTTER
 	useTarget (false),
-#endif
 	blocknr (0),
 	rot (0),
 	color (0)
@@ -185,7 +179,6 @@
 	return fallen;
 }
 
-#ifndef HAVE_CLUTTER
 void
 BlockOps::clearTarget ()
 {
@@ -225,7 +218,6 @@
 	if (!useTarget)
 		clearTarget ();
 }
-#endif
 
 int
 BlockOps::dropBlock()
@@ -367,11 +359,9 @@
 				int i = bx - 2 + x;
 				int j = y + by;
 
-#ifndef HAVE_CLUTTER
 				if ((fill == TARGET) &&
 				    (field[i][j].what != EMPTY))
 					return;
-#endif
 
 				field[i][j].what = fill;
 				if ((fill == FALLING) || (fill == LAYING))

Copied: trunk/gnometris/blockops-noclutter.h (from r8647, /trunk/gnometris/blockops.h)
==============================================================================
--- /trunk/gnometris/blockops.h	(original)
+++ trunk/gnometris/blockops-noclutter.h	Tue Feb  3 18:55:58 2009
@@ -26,9 +26,7 @@
 
 enum SlotType {
 	EMPTY,
-#ifndef HAVE_CLUTTER
 	TARGET,
-#endif
 	FALLING,
 	LAYING
 };
@@ -56,12 +54,10 @@
 	void putBlockInField (bool erase);
 	int getLinesToBottom ();
 	bool isFieldEmpty (void);
-#ifndef HAVE_CLUTTER
 	void setUseTarget (bool);
 	bool getUseTarget () {
 		return useTarget;
 	};
-#endif
 
 private:
 	void putBlockInField (int bx, int by, int blocknr, int rotation,
@@ -69,14 +65,10 @@
 	bool blockOkHere (int x, int y, int b, int r);
 	void eliminateLine (int l);
 
-#ifndef HAVE_CLUTTER
 	bool useTarget;
-#endif
 protected:
-#ifdef HAVE_CLUTTER
 	void clearTarget ();
 	void generateTarget ();
-#endif
 
 	Block **field;
 

Modified: trunk/gnometris/blockops.cpp
==============================================================================
--- trunk/gnometris/blockops.cpp	(original)
+++ trunk/gnometris/blockops.cpp	Tue Feb  3 18:55:58 2009
@@ -23,19 +23,12 @@
 #include "blockops.h"
 #include "blocks.h"
 
-#ifdef HAVE_CLUTTER
-#include "field.h"
-#else
-#include "field-noclutter.h"
-#endif
+// #include "field.h"
 
 #define NCOLOURS 7
 
 
 BlockOps::BlockOps() :
-#ifndef HAVE_CLUTTER
-	useTarget (false),
-#endif
 	blocknr (0),
 	rot (0),
 	color (0)
@@ -185,48 +178,6 @@
 	return fallen;
 }
 
-#ifndef HAVE_CLUTTER
-void
-BlockOps::clearTarget ()
-{
-	for (int x = 0; x < COLUMNS; ++x)
-		for (int y = 0; y < LINES; ++y)
-			if (field[x][y].what == TARGET)
-				field[x][y].what = EMPTY;
-}
-
-// The target is the set of blocks which the currently falling block
-// will occupy when it lands. It is an aid for beginners.
-void
-BlockOps::generateTarget ()
-{
-	if (!useTarget)
-		return;
-
-	clearTarget ();
-
-	// FIXME: Check that this is actually guaranteed
-	// to terminate (i.e. posx, posy, blocknr and rot
-	// are guaranteed to be valid).
-	int n = 0;
-	do {
-		n++;
-	} while (blockOkHere (posx, posy + n, blocknr, rot));
-	n--;
-
-	// Mark the relevant places.
-	putBlockInField (posx, posy + n, blocknr, rot, TARGET);
-}
-
-void
-BlockOps::setUseTarget (bool use)
-{
-	useTarget = use;
-	if (!useTarget)
-		clearTarget ();
-}
-#endif
-
 int
 BlockOps::dropBlock()
 {
@@ -367,12 +318,6 @@
 				int i = bx - 2 + x;
 				int j = y + by;
 
-#ifndef HAVE_CLUTTER
-				if ((fill == TARGET) &&
-				    (field[i][j].what != EMPTY))
-					return;
-#endif
-
 				field[i][j].what = fill;
 				if ((fill == FALLING) || (fill == LAYING))
 					field[i][j].color = color;

Modified: trunk/gnometris/blockops.h
==============================================================================
--- trunk/gnometris/blockops.h	(original)
+++ trunk/gnometris/blockops.h	Tue Feb  3 18:55:58 2009
@@ -26,9 +26,6 @@
 
 enum SlotType {
 	EMPTY,
-#ifndef HAVE_CLUTTER
-	TARGET,
-#endif
 	FALLING,
 	LAYING
 };
@@ -56,12 +53,6 @@
 	void putBlockInField (bool erase);
 	int getLinesToBottom ();
 	bool isFieldEmpty (void);
-#ifndef HAVE_CLUTTER
-	void setUseTarget (bool);
-	bool getUseTarget () {
-		return useTarget;
-	};
-#endif
 
 private:
 	void putBlockInField (int bx, int by, int blocknr, int rotation,
@@ -69,15 +60,7 @@
 	bool blockOkHere (int x, int y, int b, int r);
 	void eliminateLine (int l);
 
-#ifndef HAVE_CLUTTER
-	bool useTarget;
-#endif
 protected:
-#ifdef HAVE_CLUTTER
-	void clearTarget ();
-	void generateTarget ();
-#endif
-
 	Block **field;
 
 	int blocknr;

Modified: trunk/gnometris/field.cpp
==============================================================================
--- trunk/gnometris/field.cpp	(original)
+++ trunk/gnometris/field.cpp	Tue Feb  3 18:55:58 2009
@@ -49,7 +49,7 @@
 	g_signal_connect (w, "configure_event", G_CALLBACK (configure), this);
 
 	/* I don't know if this helps or not FIXME */
-	gtk_widget_set_double_buffered(w, FALSE);
+	gtk_widget_set_double_buffered (w, FALSE);
 
 	gtk_widget_set_size_request (w, COLUMNS*190/LINES, 190);
 
@@ -120,25 +120,20 @@
 		cairo_matrix_t m;
 
 		/* FIXME: This doesn't handle tiled backgrounds in the obvious way. */
-		gdk_cairo_set_source_pixbuf(bg_cr, backgroundImage, 0, 0);
+		gdk_cairo_set_source_pixbuf (bg_cr, backgroundImage, 0, 0);
 		xscale = 1.0*gdk_pixbuf_get_width (backgroundImage)/w->allocation.width;
 		yscale = 1.0*gdk_pixbuf_get_height (backgroundImage)/w->allocation.height;
 		cairo_matrix_init_scale (&m, xscale, yscale);
 		cairo_pattern_set_matrix (cairo_get_source (bg_cr), &m);
 	} else if (backgroundColor)
-		gdk_cairo_set_source_color(bg_cr, backgroundColor);
+		gdk_cairo_set_source_color (bg_cr, backgroundColor);
 	else
-		cairo_set_source_rgb(bg_cr, 0., 0., 0.);
+		cairo_set_source_rgb (bg_cr, 0., 0., 0.);
 
-	cairo_paint(bg_cr);
-
-	cairo_destroy(bg_cr);
-}
-
-void
-Field::rescaleBlockCache ()
-{
-	return;
+	cairo_paint (bg_cr);
+	cairo_destroy (bg_cr);
+	this->drawMessage ();
+	renderer->rescaleCache ();
 }
 
 gboolean
@@ -148,7 +143,6 @@
 	field->height = widget->allocation.height;
 
 	field->rescaleField ();
-	
 	return TRUE;
 }
 
@@ -177,7 +171,7 @@
 	}
 
 	// Center coordinates
-	cairo_translate(cr, width / 2, height / 2);
+	cairo_translate (cr, width / 2, height / 2);
 
 	desc = pango_font_description_from_string(FONT);
 
@@ -197,7 +191,7 @@
 	pango_layout_get_size (layout, &lw, &lh);
 	cairo_move_to (cr, -((double)lw / PANGO_SCALE) / 2, -((double)lh / PANGO_SCALE) / 2);
 	pango_cairo_layout_path (cr, layout);
-	cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
+	cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
 	cairo_fill_preserve (cr);
 	cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
 	/* A linewidth of 2 pixels at the default size. */

Modified: trunk/gnometris/field.h
==============================================================================
--- trunk/gnometris/field.h	(original)
+++ trunk/gnometris/field.h	Tue Feb  3 18:55:58 2009
@@ -65,9 +65,7 @@
 	GdkColor *backgroundColor;
 	gint themeID;
 
-	void drawMessage (cairo_t * cr, const char *msg);
 	void rescaleField ();
-	void rescaleBlockCache ();
 
 	static gboolean configure (GtkWidget * widget, GdkEventConfigure * event,
 				   Field * field);

Modified: trunk/gnometris/renderer.cpp
==============================================================================
--- trunk/gnometris/renderer.cpp	(original)
+++ trunk/gnometris/renderer.cpp	Tue Feb  3 18:55:58 2009
@@ -28,7 +28,6 @@
 #include "renderer.h"
 
 const ThemeTableEntry ThemeTable[] = {{N_("Plain"), "plain"},
-				      {N_("Joined"), "joined"},
 				      {N_("Tango Flat"), "tangoflat"},
 				      {N_("Tango Shaded"), "tangoshaded"},
 				      {NULL, NULL}};
@@ -59,12 +58,10 @@
 			    int h, int pxw, int pxh)
 {
 	switch (id) {
-	case 3:
-		return new TangoBlock (dst, src, w, h, pxw, pxh, TRUE);
 	case 2:
-		return new TangoBlock (dst, src, w, h, pxw, pxh, FALSE);
+		return new TangoBlock (dst, src, w, h, pxw, pxh, TRUE);
 	case 1:
-		return new JoinedUp (dst, src, w, h, pxw, pxh);
+		return new TangoBlock (dst, src, w, h, pxw, pxh, FALSE);
 	case 0:
 	default:
 		return new Renderer (dst, src, w, h, pxw, pxh);
@@ -89,7 +86,6 @@
 		    int w, int h, int pxw, int pxh)
 {
 	target = dst;
-	block_cache = new GnometrisBlockCache(5);
 	data = src;
 	width = w;
 	height = h;
@@ -99,17 +95,14 @@
 
 Renderer::~Renderer ()
 {
-	delete block_cache;
 }
 
-void Renderer::setTarget (ClutterActor * dst)
+void Renderer::rescaleCache ()
 {
-	target = dst;
 }
 
-void Renderer::drawCell (cairo_t *cr, gint x, gint y)
+void Renderer::drawCell (cairo_t *cr, guint color)
 {
-	int i;
 	const gdouble colours[7][3] = {{1.0, 0.0, 0.0},
 				       {0.0, 1.0, 0.0},
 				       {0.0, 0.0, 1.0},
@@ -118,31 +111,22 @@
 				       {1.0, 0.0, 1.0},
 				       {0.0, 1.0, 1.0}};
 
-	if (data[x][y].what == EMPTY)
-		return;
-
-	i = data[x][y].color;
-	i = CLAMP (i, 0, 6);
+	color = CLAMP (color, 0, 6);
 
-	cairo_set_source_rgb(cr, colours[i][0],
-				colours[i][1],
-				colours[i][2]);
-
-	cairo_rectangle(cr, x+0.05, y+0.05,
-			0.9, 0.9);
-	cairo_fill (cr);
+	cairo_set_source_rgb(cr, colours[color][0],
+				colours[color][1],
+				colours[color][2]);
+	cairo_paint (cr);
 }
 
 void Renderer::drawForeground (cairo_t *cr)
 {
-	int x, y;
+	int color;
 
 	cairo_scale(cr, 1.0 * pxwidth / width, 1.0 * pxheight / height);
 
-	for (y = 0; y<height; y++) {
-		for (x = 0; x<width; x++) {
-			drawCell (cr, x, y);
-		}
+	for (color = 0; color<7; color++) {
+		drawCell (cr, color);
 	}
 }
 
@@ -157,204 +141,15 @@
 	cairo_destroy (cr);
 }
 
-/*--------------------------------------------------------*/
-
-void JoinedUp::drawInnerCorner (cairo_t *cr)
-{
-	border = 0.2;
-	cairo_move_to (cr, 0, 0);
-	cairo_line_to (cr, border, border);
-	cairo_line_to (cr, border, 0);
-	cairo_move_to (cr, border, border);
-	cairo_line_to (cr, 0, border);
-	cairo_stroke (cr);
-}
-
-void JoinedUp::drawOuterCorner (cairo_t *cr)
-{
-	border = 0.2;
-	cairo_move_to (cr, 0, 0.5);
-	cairo_line_to (cr, 0, 0);
-	cairo_line_to (cr, 0.5, 0);
-	cairo_move_to (cr, 0, 0);
-	cairo_line_to (cr, border, border);
-	cairo_line_to (cr, 0.5, border);
-	cairo_move_to (cr, border, border);
-	cairo_line_to (cr, border, 0.5);
-	cairo_stroke (cr);
-}
-
-void JoinedUp::drawHEdge (cairo_t *cr)
-{
-	border = 0.2;
-	cairo_move_to (cr, 0, 0);
-	cairo_line_to (cr, 0.5, 0);
-	cairo_move_to (cr, 0, border);
-	cairo_line_to (cr, 0.5, border);
-	cairo_stroke (cr);
-}
-
-void JoinedUp::drawVEdge (cairo_t *cr)
-{
-	border = 0.2;
-	cairo_move_to (cr, 0, 0);
-	cairo_line_to (cr, 0, 0.5);
-	cairo_move_to (cr, border, 0);
-	cairo_line_to (cr, border, 0.5);
-	cairo_stroke (cr);
-}
-
-void JoinedUp::drawCell (cairo_t *cr, gint x, gint y)
-{
-	int i, m, n;
-	int segments[4];
-	double xofs;
-	double yofs;
-	int c;
-	int neighbours[8];
-	static const int formtable[4][8] = {{0, 7, 0, 7, 4, 9, 4, 8},
-					    {1, 4, 1, 4, 5, 10, 5, 8},
-					    {2, 6, 2, 6, 7, 11, 7, 8},
-					    {3, 5, 3, 5, 6, 12, 6, 8}};
-	static const gdouble colours[7][3] = {{1.0, 0.0, 0.0},
-					      {0.1, 0.8, 0.1},
-					      {0.1, 0.1, 0.8},
-					      {1.0, 1.0, 1.0},
-					      {1.0, 1.0, 0.0},
-					      {0.8, 0.1, 0.8},
-					      {0.0, 1.0, 1.0}};
-	static const int neighbourmap[8][2] = {{-1, -1}, {0, -1}, {+1, -1},
-					       {-1, 0}, {+1, 0},
-					       {-1, +1}, {0, +1}, {+1, +1}};
-
-	if (data[x][y].what == EMPTY)
-		return;
-
-	i = data[x][y].color;
-	i = CLAMP (i, 0, 6);
-
-	cairo_save (cr);
-	cairo_translate (cr, x, y);
-
-	cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
-	cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
-	cairo_set_line_width (cr, 0.05);
-
-	cairo_set_source_rgb (cr, colours[i][0],
-				colours[i][1],
-				colours[i][2]);
-
-	cairo_rectangle (cr, -0.025, -0.025, 1.025, 1.025);
-	cairo_fill (cr);
-	cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
-
-	// Enumerate the neighbours.
-	c = data[x][y].color;
-	for (i=0; i<8; i++) {
-		m = x + neighbourmap[i][0];
-		n = y + neighbourmap[i][1];
-		if ((m < 0) || (n < 0) || (m >= width) || (n >= height))
-			neighbours[i] = 0;
-		else
-			neighbours[i] = ((data[m][n].what != EMPTY) &&
-					 (data[m][n].color == c)) ? 1 : 0;
-	}
-
-	// Sort out which quadrant of the square is drawn in what way.
-	segments[0] = formtable [0][neighbours[3]*4 +
-				    neighbours[0]*2 +
-				    neighbours[1]];
-	segments[1] = formtable [1][neighbours[1]*4 +
-				    neighbours[2]*2 +
-				    neighbours[4]];
-	segments[2] = formtable [2][neighbours[6]*4 +
-				    neighbours[5]*2 +
-				    neighbours[3]];
-	segments[3] = formtable [3][neighbours[4]*4 +
-				    neighbours[7]*2 +
-				    neighbours[6]];
-
-	// Finally: do the actual drawing.
-	for (i=0; i<4; i++) {
-		cairo_save (cr);
-		xofs = 0.5*(i % 2);
-		yofs = 0.5*(i / 2);
-		cairo_translate (cr, xofs, yofs);
-		switch (segments[i]) {
-		case 0:
-			drawOuterCorner (cr);
-			break;
-		case 1:
-			cairo_scale (cr, -1.0, 1.0);
-			cairo_translate (cr, -0.5, 0);
-			drawOuterCorner (cr);
-			break;
-		case 2:
-			cairo_scale (cr, 1.0, -1.0);
-			cairo_translate (cr, 0, -0.5);
-			drawOuterCorner (cr);
-			break;
-		case 3:
-			cairo_scale (cr, -1.0, -1.0);
-			cairo_translate (cr, -0.5, -0.5);
-			drawOuterCorner (cr);
-			break;
-		case 4:
-			drawHEdge (cr);
-			break;
-		case 5:
-			cairo_scale (cr, -1.0, 1.0);
-			cairo_translate (cr, -0.5, 0);
-			drawVEdge (cr);
-			break;
-		case 6:
-			cairo_scale (cr, 1.0, -1.0);
-			cairo_translate (cr, 0, -0.5);
-			drawHEdge (cr);
-			break;
-		case 7:
-			drawVEdge (cr);
-			break;
-
-		case 8:
-			break;
-		case 9:
-			drawInnerCorner (cr);
-			break;
-		case 10:
-			cairo_scale (cr, -1.0, 1.0);
-			cairo_translate (cr, -0.5, 0);
-			drawInnerCorner (cr);
-			break;
-		case 11:
-			cairo_scale (cr, 1.0, -1.0);
-			cairo_translate (cr, 0, -0.5);
-			drawInnerCorner (cr);
-			break;
-		case 12:
-			cairo_scale (cr, -1.0, -1.0);
-			cairo_translate (cr, -0.5, -0.5);
-			drawInnerCorner (cr);
-			break;
-		}
-		cairo_restore (cr);
-	}
-
-	cairo_restore (cr);
-}
-
-/*--------------------------------------------------------*/
-
 TangoBlock::TangoBlock (ClutterActor * dst, Block ** src,
 	    int w, int h, int pxw, int pxh, gboolean grad) : Renderer (dst, src, w, h, pxw, pxh)
 {
 	usegrads = grad;
 }
 
-void TangoBlock::drawCell (cairo_t *cr, gint x, gint y)
+void TangoBlock::drawCell (cairo_t *cr, guint color)
 {
 
-	int i;
 	cairo_pattern_t *pat = NULL;
 	/* the following garbage is derived from the official tango style guide */
 	const gdouble colours[8][3][3] = {
@@ -391,44 +186,40 @@
 					   {0.10, 0.12, 0.13}} /* grey */
 					 };
 
-	if (data[x][y].what == EMPTY)
-		return;
-
-	i = data[x][y].color;
-	i = CLAMP (i, 0, 6);
+	color = CLAMP (color, 0, 6);
 
 	if (usegrads) {
-		 pat = cairo_pattern_create_linear (x+0.35, y, x+0.55, y+0.9);
-		 cairo_pattern_add_color_stop_rgb (pat, 0.0, colours[i][0][0],
-						   colours[i][0][1],
-						   colours[i][0][2]);
-		 cairo_pattern_add_color_stop_rgb (pat, 1.0, colours[i][1][0],
-						   colours[i][1][1],
-						   colours[i][1][2]);
+		 pat = cairo_pattern_create_linear (0.35, 0, 0.55, 0.9);
+		 cairo_pattern_add_color_stop_rgb (pat, 0.0, colours[color][0][0],
+						   colours[color][0][1],
+						   colours[color][0][2]);
+		 cairo_pattern_add_color_stop_rgb (pat, 1.0, colours[color][1][0],
+						   colours[color][1][1],
+						   colours[color][1][2]);
 		 cairo_set_source (cr, pat);
 	} else {
-		 cairo_set_source_rgb (cr, colours[i][0][0],
-				       colours[i][0][1],
-				       colours[i][0][2]);
+		 cairo_set_source_rgb (cr, colours[color][0][0],
+				       colours[color][0][1],
+				       colours[color][0][2]);
 	}
 
-	drawRoundedRectangle (cr, x+0.05, y+0.05, 0.9, 0.9, 0.2);
+	drawRoundedRectangle (cr, 0.05, 0.05, 0.9, 0.9, 0.2);
 	cairo_fill_preserve (cr);  /* fill with shaded gradient */
 
 
 	if (usegrads)
 		cairo_pattern_destroy(pat);
-	cairo_set_source_rgb(cr, colours[i][2][0],
-			     colours[i][2][1],
-			     colours[i][2][2]);
+	cairo_set_source_rgb(cr, colours[color][2][0],
+			     colours[color][2][1],
+			     colours[color][2][2]);
 
 	cairo_set_line_width (cr, 0.1);
 	cairo_stroke (cr);  /* add darker outline */
 
-	drawRoundedRectangle (cr, x+0.15, y+0.15, 0.7, 0.7, 0.08);
+	drawRoundedRectangle (cr, 0.15, 0.15, 0.7, 0.7, 0.08);
 	if (usegrads) {
-		pat = cairo_pattern_create_linear (x-0.3, y-0.3, x+0.8, y+0.8);
-		switch (i) { /* yellow and white blocks need a brighter highlight */
+		pat = cairo_pattern_create_linear (-0.3, -0.3, 0.8, 0.8);
+		switch (color) { /* yellow and white blocks need a brighter highlight */
 		case 3:
 		case 4:
 			cairo_pattern_add_color_stop_rgba (pat, 0.0, 1.0,

Modified: trunk/gnometris/renderer.h
==============================================================================
--- trunk/gnometris/renderer.h	(original)
+++ trunk/gnometris/renderer.h	Tue Feb  3 18:55:58 2009
@@ -26,10 +26,9 @@
 
 #include <cairo.h>
 #include <glib.h>
+#include <clutter-cairo/clutter-cairo.h>
 
-#include "block-cache.h"
 #include "blockops.h"
-#include <clutter-cairo/clutter-cairo.h>
 
 struct ThemeTableEntry {
 	const gchar *name;
@@ -45,7 +44,7 @@
 	virtual ~ Renderer ();
 	virtual void render ();
 
-	void setTarget (ClutterActor *target);
+	void rescaleCache ();
 
 	Block **data;
 	int width;
@@ -53,41 +52,24 @@
 	int pxwidth;
 	int pxheight;
 protected:
-	GnometrisBlockCache *block_cache;
 	ClutterActor *target;
 
-	virtual void drawCell (cairo_t * cr, gint x, gint y);
+	virtual void drawCell (cairo_t * cr, guint color);
 	virtual void drawForeground (cairo_t * cr);
 };
 
-Renderer *rendererFactory (gint id, ClutterActor * dst,
+Renderer *rendererFactory (gint id, cairo_surface_t * dst,
 			   Block ** src, int w,
 			   int h, int pxw, int pxh);
 gint themeNameToNumber (const gchar * id);
 
-class JoinedUp:public Renderer {
-public:
-	JoinedUp (ClutterActor * dst, Block ** src,
-	int w, int h, int pxw, int pxh):Renderer (dst, src, w, h, pxw,
-						  pxh) {}
-protected:
-	virtual void drawCell (cairo_t * cr, gint x, gint y);
-
-private:
-	double border;
-	void drawInnerCorner (cairo_t * cr);
-	void drawOuterCorner (cairo_t * cr);
-	void drawHEdge (cairo_t * cr);
-	void drawVEdge (cairo_t * cr);
-};
-
 class TangoBlock:public Renderer {
 public:
 	TangoBlock (ClutterActor * dst, Block ** src,
 		    int w, int h, int pxw, int pxh, gboolean grad);
 
 protected:
-	virtual void drawCell (cairo_t * cr, gint x, gint y);
+	virtual void drawCell (cairo_t * cr, guint color);
 	gboolean usegrads;
 
 private:

Modified: trunk/gnometris/tetris.cpp
==============================================================================
--- trunk/gnometris/tetris.cpp	(original)
+++ trunk/gnometris/tetris.cpp	Tue Feb  3 18:55:58 2009
@@ -39,7 +39,6 @@
 #include <libgames-support/games-stock.h>
 
 #include "tetris.h"
-#include "blockops.h"
 #include "blocks.h"
 #include "scoreframe.h"
 #include "highscores.h"
@@ -48,10 +47,12 @@
 #include "preview.h"
 #include "field.h"
 #include "renderer.h"
+#include "blockops.h"
 #else
 #include "preview-noclutter.h"
 #include "field-noclutter.h"
 #include "renderer-noclutter.h"
+#include "blockops-noclutter.h"
 #endif
 
 int LINES = 20;



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