gnome-games r8397 - trunk/gnometris



Author: jclinton
Date: Mon Jan  5 06:20:00 2009
New Revision: 8397
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8397&view=rev

Log:
Gnometris renders with Clutter in an extremely rudamentary way, as a first
milestone on the way to a fully-canvas driven game engine. Right now, it's just
two ClutterCairo surfaces, background and foreground, which are used as
compositors. These two actors will end up staying: background for--eh--the
background, and foreground for display of Pango text. An intermediate layer will
be introduced on which game pieces are actually animated, rotated and exploded.

Sadly, even this stupid way of rendering is faster than the old method.

This pre-alpha 'leaks' memory like gang-busters, also. I do not know if it is
merely a i915 driver bug or something more fundamental. It's not a 'leak' in the
traditional sense: all the textures that are 'leaked' are still reachable in the
i915 driver code. It leaks on the order of 1MB of memory per frame of animation.
This will be fixed either by doing things the Right Way or mitigating i915 leaks
by avoiding the use of texture uploads at all costs (a tile cache).

Modified:
   trunk/gnometris/field.cpp
   trunk/gnometris/renderer.cpp
   trunk/gnometris/renderer.h

Modified: trunk/gnometris/field.cpp
==============================================================================
--- trunk/gnometris/field.cpp	(original)
+++ trunk/gnometris/field.cpp	Mon Jan  5 06:20:00 2009
@@ -208,17 +208,20 @@
 	generateTarget ();
 
 	cr = clutter_cairo_create (CLUTTER_CAIRO(foreground));
+	cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+	cairo_paint(cr);
+	cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
 
 	if (rendererTheme != themeID) {
 
 		if (renderer)
 			delete renderer;
 
-		renderer = rendererFactory (themeID, cairo_get_target(cr), field,
+		renderer = rendererFactory (themeID, foreground, field,
 				     COLUMNS, LINES, width, height);
 		rendererTheme = themeID;
 	} else {
-		renderer->setTarget (cairo_get_target(cr));
+		renderer->setTarget (foreground);
 		renderer->data = field;
 		renderer->width = COLUMNS;
 		renderer->height = LINES;
@@ -234,8 +237,6 @@
 		drawMessage(cr, _("Game Over"));
 
 	cairo_destroy(cr);
-
-	draw ();
 }
 
 void

Modified: trunk/gnometris/renderer.cpp
==============================================================================
--- trunk/gnometris/renderer.cpp	(original)
+++ trunk/gnometris/renderer.cpp	Mon Jan  5 06:20:00 2009
@@ -51,7 +51,7 @@
 	return 0;
 }
 
-Renderer * rendererFactory (gint id, cairo_surface_t *dst,
+Renderer * rendererFactory (gint id, ClutterActor *dst,
 			    Block **src, int w,
 			    int h, int pxw, int pxh)
 {
@@ -82,10 +82,10 @@
    for the preview widget and possibly the theme previewer, so make no
    assumptions. */
 
-Renderer::Renderer (cairo_surface_t *dst, Block **src,
+Renderer::Renderer (ClutterActor *dst, Block **src,
 		    int w, int h, int pxw, int pxh)
 {
-	target = cairo_surface_reference (dst);
+	target = dst;
 	block_cache = new GnometrisBlockCache(5);
 	data = src;
 	width = w;
@@ -96,13 +96,12 @@
 
 Renderer::~Renderer ()
 {
-	cairo_surface_destroy (target);
+	delete block_cache;
 }
 
-void Renderer::setTarget (cairo_surface_t * dst)
+void Renderer::setTarget (ClutterActor * dst)
 {
-	cairo_surface_destroy (target);
-	target = cairo_surface_reference (dst);
+	target = dst;
 }
 
 void Renderer::drawCell (cairo_t *cr, gint x, gint y)
@@ -152,7 +151,7 @@
 {
 	cairo_t *cr;
 
-	cr = cairo_create (target);
+	cr = clutter_cairo_create (CLUTTER_CAIRO(target));
 
 	drawForeground (cr);
 
@@ -350,7 +349,7 @@
 
 /*--------------------------------------------------------*/
 
-TangoBlock::TangoBlock (cairo_surface_t * dst, Block ** src,
+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;

Modified: trunk/gnometris/renderer.h
==============================================================================
--- trunk/gnometris/renderer.h	(original)
+++ trunk/gnometris/renderer.h	Mon Jan  5 06:20:00 2009
@@ -29,6 +29,7 @@
 
 #include "block-cache.h"
 #include "blockops.h"
+#include <clutter-cairo/clutter-cairo.h>
 
 struct ThemeTableEntry {
 	const gchar *name;
@@ -39,12 +40,12 @@
 
 class Renderer {
 public:
-	Renderer (cairo_surface_t * dst, Block ** src,
+	Renderer (ClutterActor * dst, Block ** src,
 		  int w, int h, int pxw, int pxh);
 	virtual ~ Renderer ();
 	virtual void render ();
 
-	void setTarget (cairo_surface_t *target);
+	void setTarget (ClutterActor *target);
 
 	Block **data;
 	int width;
@@ -53,20 +54,20 @@
 	int pxheight;
 protected:
 	GnometrisBlockCache *block_cache;
-	cairo_surface_t *target;
+	ClutterActor *target;
 
 	virtual void drawCell (cairo_t * cr, gint x, gint y);
 	virtual void drawForeground (cairo_t * cr);
 };
 
-Renderer *rendererFactory (gint id, cairo_surface_t * dst,
+Renderer *rendererFactory (gint id, ClutterActor * dst,
 			   Block ** src, int w,
 			   int h, int pxw, int pxh);
 gint themeNameToNumber (const gchar * id);
 
 class JoinedUp:public Renderer {
 public:
-	JoinedUp (cairo_surface_t * dst, Block ** src,
+	JoinedUp (ClutterActor * dst, Block ** src,
 	int w, int h, int pxw, int pxh):Renderer (dst, src, w, h, pxw,
 						  pxh) {}
 protected:
@@ -82,7 +83,7 @@
 
 class TangoBlock:public Renderer {
 public:
-	TangoBlock (cairo_surface_t * dst, Block ** src,
+	TangoBlock (ClutterActor * dst, Block ** src,
 		    int w, int h, int pxw, int pxh, gboolean grad);
 
 protected:



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