changeset 192:a7c823478180 trunk

[svn] - add fast linedrawing code
author nenolod
date Thu, 02 Nov 2006 22:19:05 -0800
parents 6d5f164a8719
children 4b48e6e9b3cb
files ChangeLog src/paranormal/Makefile src/paranormal/drawing.c src/paranormal/paranormal.c
diffstat 4 files changed, 84 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Nov 02 21:44:14 2006 -0800
+++ b/ChangeLog	Thu Nov 02 22:19:05 2006 -0800
@@ -1,3 +1,11 @@
+2006-11-03 05:44:14 +0000  William Pitcock <nenolod@nenolod.net>
+  revision [382]
+  - fix warning (oops)
+  
+  trunk/src/paranormal/paranormal.c |    2 +-
+  1 file changed, 1 insertion(+), 1 deletion(-)
+
+
 2006-11-03 05:43:22 +0000  William Pitcock <nenolod@nenolod.net>
   revision [380]
   - compile with -DFULLSCREEN_HACK to get the fullscreen overlay stuff
--- a/src/paranormal/Makefile	Thu Nov 02 21:44:14 2006 -0800
+++ b/src/paranormal/Makefile	Thu Nov 02 22:19:05 2006 -0800
@@ -16,6 +16,7 @@
 	cfg.c			\
 	cmaps.c			\
 	containers.c		\
+	drawing.c		\
 	freq.c			\
 	general.c		\
 	misc.c			\
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/paranormal/drawing.c	Thu Nov 02 22:19:05 2006 -0800
@@ -0,0 +1,74 @@
+#include "paranormal.h"
+#include "actuators.h"
+#include "pn_utils.h"
+
+extern SDL_Surface *screen;
+
+void
+pn_draw_line (guint _x0, guint _y0, guint _x1, guint _y1, guchar value)
+{
+  gint x0 = _x0;
+  gint y0 = _y0;
+  gint x1 = _x1;
+  gint y1 = _y1;
+
+  gint dy = y1 - y0;
+  gint dx = x1 - x0;
+  gint stepx, stepy;
+  gint fraction;
+
+  if (dy < 0)
+    {
+      dy = -dy;
+      stepy = -(screen->pitch >> 2);
+    }
+  else
+    {
+      stepy = screen->pitch>>2;
+    }
+  if (dx < 0)
+    {
+      dx = -dx;
+      stepx = -1;
+    }
+  else
+    {
+      stepx = 1;
+    }
+  dy <<= 1;
+  dx <<= 1;
+
+  y0 *= screen->pitch>>2;
+  y1 *= screen->pitch>>2;
+  pn_image_data->surface[0][PN_IMG_INDEX(x0, y0)] = value;
+  if (dx > dy)
+    {
+      fraction = dy - (dx >> 1);
+      while (x0 != x1)
+	{
+	  if (fraction >= 0)
+	    {
+	      y0 += stepy;
+	      fraction -= dx;
+	    }
+	  x0 += stepx;
+	  fraction += dy;
+	  pn_image_data->surface[0][PN_IMG_INDEX(x0, y0)] = value;
+	}
+    }
+  else
+    {
+      fraction = dx - (dy >> 1);
+      while (y0 != y1)
+	{
+	  if (fraction >= 0)
+	    {
+	      x0 += stepx;
+	      fraction -= dy;
+	    }
+	  y0 += stepy;
+	  fraction += dx;
+	  pn_image_data->surface[0][PN_IMG_INDEX(x0, y0)] = value;
+	}
+    }
+}
--- a/src/paranormal/paranormal.c	Thu Nov 02 21:44:14 2006 -0800
+++ b/src/paranormal/paranormal.c	Thu Nov 02 22:19:05 2006 -0800
@@ -19,7 +19,7 @@
 #include "actuators.h"
 
 /* SDL stuffs */
-static SDL_Surface *screen;
+SDL_Surface *screen;
 
 /* Globals */
 struct pn_rc         *pn_rc;