From: Thomas Thurman Date: Wed, 27 May 2009 05:09:53 +0000 (-0400) Subject: Initial checkin X-Git-Url: http://git.maemo.org/git/?p=sandcastle;a=commitdiff_plain;h=69d13fdd214a86665f86cbea23fe598dc8bdf1e5 Initial checkin --- diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..508198e --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +all: sandcastle + +sandcastle: sand.c + gcc -g -O3 `pkg-config --cflags --libs gtk+-2.0 gdk-pixbuf-2.0 hildon-1 dbus-glib-1` sand.c -o sandcastle + +clean: + rm sandcastle + +install: sandcastle sandcastle.xpm sandcastle.desktop + install -d ${DESTDIR}/usr/bin + install sandcastle ${DESTDIR}/usr/bin + install -d ${DESTDIR}/usr/share/applications/hildon + install sandcastle.desktop ${DESTDIR}/usr/share/applications/hildon + install -d ${DESTDIR}/usr/share/pixmaps + install sandcastle.xpm ${DESTDIR}/usr/share/pixmaps + install -d ${DESTDIR}/usr/share/sandcastle + install sandcastle.png ${DESTDIR}/usr/share/sandcastle + diff --git a/debian/README.Debian b/debian/README.Debian new file mode 100644 index 0000000..bf64b94 --- /dev/null +++ b/debian/README.Debian @@ -0,0 +1,8 @@ +rfk for Debian +-------------- + + + + -- + + <> Thu, 19 Mar 2009 21:33:32 -0400 diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..19b18d1 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,6 @@ +sandcastle (0.01-1) unstable; urgency=low + + * Initial release + + -- Thomas Thurman Thu, 19 Mar 2009 21:33:32 -0400 + diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..c5d8678 --- /dev/null +++ b/debian/control @@ -0,0 +1,13 @@ +Source: sandcastle +Section: unknown +Priority: extra +Maintainer: Thomas Thurman +Build-Depends: debhelper (>= 5) +Standards-Version: 3.7.2 + +Package: sandcastle +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: A world full of sand + Sandcastle animates a world full of sand for Maemo. + diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..210831a --- /dev/null +++ b/debian/copyright @@ -0,0 +1,39 @@ +This package was debianized by + + <> on +Thu, 19 Mar 2009 21:33:32 -0400. + +It was downloaded from + +Upstream Author: + +Copyright: + +License: + + This package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this package; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +On Debian systems, the complete text of the GNU General +Public License can be found in `/usr/share/common-licenses/GPL'. + +The Debian packaging is (C) 2009, + + <> and +is licensed under the GPL, see above. + + +# Please also look if there are files or directories which have a +# different copyright/license attached and list them here. diff --git a/debian/dirs b/debian/dirs new file mode 100644 index 0000000..ca882bb --- /dev/null +++ b/debian/dirs @@ -0,0 +1,2 @@ +usr/bin +usr/sbin diff --git a/debian/files b/debian/files new file mode 100644 index 0000000..97eebcd --- /dev/null +++ b/debian/files @@ -0,0 +1 @@ +sandcastle_0.01-1_armel.deb unknown extra diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..1987312 --- /dev/null +++ b/debian/rules @@ -0,0 +1,98 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + + + + +CFLAGS = -Wall -g + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else + CFLAGS += -O2 +endif + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + + touch configure-stamp + + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + $(MAKE) + #docbook-to-man debian/sandcastle.sgml > rfk.1 + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + -$(MAKE) clean + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/sandcastle. + $(MAKE) DESTDIR=$(CURDIR)/debian/sandcastle install + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples +# dh_install +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman + dh_link + dh_strip + dh_compress + dh_fixperms +# dh_perl +# dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/debian/sandcastle.substvars b/debian/sandcastle.substvars new file mode 100644 index 0000000..69c5948 --- /dev/null +++ b/debian/sandcastle.substvars @@ -0,0 +1 @@ +shlibs:Depends=libatk1.0-0 (>= 1.24.0), libc6 (>= 2.5.0-1), libcairo2, libdbus-1-3 (>= 1.1.4), libdbus-glib-1-2 (>= 0.76), libglib2.0-0 (>= 2.14.6-1osso1), libgtk2.0-0 (>= 2:2.12.9-0osso1), libhildon1, libpango1.0-0 diff --git a/sand.c b/sand.c new file mode 100644 index 0000000..e671d10 --- /dev/null +++ b/sand.c @@ -0,0 +1,345 @@ +/** + * Sandcastle - Falling sand game for Maemo 5 + * Copyright (c) 2009 Thomas Thurman + * This is a demonstration of the accelerometer. + * It's only a few hours' work and could stand to be improved in + * several ways: + * - use a sorted list of grains to speed up sand processing + * - add different colours of sand? + * - add various other stuff like plants, water, explosives... + * (as in the web game "Hell of Sand") + * + * I also haven't tracked down why it crashes sometimes when + * you run it from the launcher. Run it from a terminal as + * /usr/bin/sandcastle to get around this. + */ + +/** + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include +#include +#include +#include +#include +#include + +GdkPixbuf *pixbuf; +GtkWidget *window, *area; +int width, height, rowstride; +int minx, maxx, miny, maxy; +DBusGProxy *dbus_proxy = NULL; +DBusGProxyCall *dbus_call = NULL; +guint32 *pixels = NULL; +GList *grains = NULL; + +const guint32 SAND = 0xff00ffff; +const guint32 WALL = 0xffffffff; +const guint32 EMPTY = 0xff000000; + +enum { + UP = 0, + UP_RIGHT = 1, + RIGHT = 2, + DOWN_RIGHT = 3, + DOWN = 4, + DOWN_LEFT = 5, + LEFT = 6, + UP_LEFT = 7 +}; + +int gravity = DOWN; +int there_is_gravity = TRUE; + +static inline guint32* +translate_pointer_by_direction(guint32 *src, int direction, int x, int y) +{ + static guint32 edge = WALL; + + switch (direction%8) { + case UP: + if (y<=0) return &edge; + return src-rowstride; + case UP_RIGHT: + if (y<=0 || x>=width) return &edge; + return (src-rowstride)+1; + case RIGHT: + if (x>=width) return &edge; + return src+1; + case DOWN_RIGHT: + if (x>=width || y>=height) return &edge; + return (src+rowstride)+1; + case DOWN: + if (y>=height) return &edge; + return src+rowstride; + case DOWN_LEFT: + if (x<=0 || y>=height) return &edge; + return (src+rowstride)-1; + case LEFT: + if (x<=0) return &edge; + return src-1; + case UP_LEFT: + if (x<=0 || y<=0) return &edge; + return (src-rowstride)-1; + } +} + +static gint +expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer data) +{ + gdk_draw_pixbuf (GDK_DRAWABLE(widget->window), + widget->style->fg_gc[GTK_WIDGET_STATE (widget)], + pixbuf, event->area.x, event->area.y, + event->area.x, event->area.y, + event->area.width, event->area.height, + GDK_RGB_DITHER_NONE, 0, 0); + return TRUE; +} + +static gboolean +tap_event (GtkWidget *widget, + GdkEventMotion *event, + gpointer user_data) +{ + int rx, ry; + + for (rx=-5; rx<=5; rx++) + for (ry=-5; ry<=5; ry++) + { + guint32 *p = pixels + (ry+(int)event->y)*rowstride + (rx+(int)event->x); + + if (*p==EMPTY) *p=SAND; + } + + gtk_widget_queue_draw_area (area, ((int)event->x)-5, ((int)event->y)-5, 10, 10); + minx=miny=0; + maxx=width; maxy=height; +} + +static void +orientation_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *data) +{ + gchar *s1, *s2, *s3; + gint x, y, z; + gchar facing = 0; + + if (dbus_g_proxy_end_call (proxy, call, NULL, + G_TYPE_STRING, &s1, + G_TYPE_STRING, &s2, + G_TYPE_STRING, &s3, + G_TYPE_INT, &x, + G_TYPE_INT, &y, + G_TYPE_INT, &z, + G_TYPE_INVALID)) { + + if (x<=-500) facing |= 0x10; + else if (x<=0) facing |= 0x20; + else if (x<=500) facing |= 0x30; + else facing |= 0x40; + + if (y<=-500) facing |= 0x1; + else if (y<=0) facing |= 0x2; + else if (y<=500) facing |= 0x3; + else facing |= 0x4; + + g_free(s1); g_free(s2); g_free(s3); + + there_is_gravity = TRUE; + + switch (facing) { + case 0x34: case 0x36: case 0x24: gravity=UP; break; + case 0x13: case 0x14: gravity=UP_RIGHT; break; + case 0x12: gravity=RIGHT; break; + case 0x11: gravity=DOWN_RIGHT; break; + case 0x21: case 0x31: gravity=DOWN; break; + case 0x41: gravity=DOWN_LEFT; break; + case 0x42: case 0x43: gravity=LEFT; break; + case 0x44: gravity=UP_LEFT; break; + default: + there_is_gravity=FALSE; + } + + } else { + g_warning ("Couldn't end the call!\n"); + } + dbus_call = NULL; +} + +gint +sand_sort (gpointer sand1, gpointer sand2) +{ + if (sand1newmaxx) newmaxx=x; + if (ynewmaxy) newmaxy=y; + } + p += xdelta; + } + } + + minx=newminx; if (minx>2) minx--; else minx=0; + maxx=newmaxx; if (maxx2) miny--; else miny=0; + maxy=newmaxy; if (maxySandcastle + +

Sandcastle

+

A Falling Sand Game for Maemo

+ +

This is still being written. For now, you can visit +the garage page for sandcastle, +browse the source code, +or play a similar game in Java. +

+