annotate src/paranormal/misc.c @ 1892:3b034150d31e

Add GPL2 boilerplate text.
author William Pitcock <nenolod@atheme.org>
date Wed, 26 Sep 2007 11:51:08 -0500
parents b185ed2f8fa2
children 56bb18dd3fdd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1892
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
1 /*
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
2 * paranormal: iterated pipeline-driven visualization plugin
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
3 * Copyright (c) 2006, 2007 William Pitcock <nenolod@dereferenced.org>
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
4 * Portions copyright (c) 2001 Jamie Gennis <jgennis@mindspring.com>
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
5 *
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
6 * This program is free software; you can redistribute it and/or modify
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
7 * it under the terms of the GNU General Public License as published by
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
8 * the Free Software Foundation; under version 2 of the License.
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
9 *
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
10 * This program is distributed in the hope that it will be useful,
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
13 * GNU General Public License for more details.
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
14 *
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
15 * You should have received a copy of the GNU General Public License
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
16 * along with this program; if not, write to the Free Software
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
18 */
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
19
186
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
20 #ifdef HAVE_CONFIG_H
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
21 # include <config.h>
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
22 #endif
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
23
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
24 #include <stdlib.h>
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
25 #include <stdio.h>
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
26
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
27 #include <glib.h>
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
28
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
29 #include "paranormal.h"
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
30 #include "actuators.h"
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
31 #include "pn_utils.h"
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
32
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
33 /* ******************** misc_floater ******************** */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
34 static struct pn_actuator_option_desc misc_floater_opts[] =
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
35 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
36 { "value", "The colour value for the floater.",
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
37 OPT_TYPE_INT, { ival: 255 } },
188
0d826917c56f [svn] - 64-bit safety (pass 1 of 2)
nenolod
parents: 186
diff changeset
38 { NULL }
186
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
39 };
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
40
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
41 typedef enum
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
42 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
43 float_up = 0x1,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
44 float_down = 0x2,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
45 float_left = 0x4,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
46 float_right = 0x8,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
47 } FloaterDirection;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
48
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
49 struct floater_state_data
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
50 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
51 FloaterDirection dir;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
52 gint x;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
53 gint y;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
54 };
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
55
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
56 static void
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
57 misc_floater_init(gpointer *data)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
58 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
59 struct floater_state_data *opaque_data = g_new0(struct floater_state_data, 1);
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
60 *data = opaque_data;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
61 opaque_data->x = rand() % pn_image_data->width;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
62 opaque_data->y = rand() % pn_image_data->height;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
63 opaque_data->dir = (FloaterDirection) rand() % 15; /* sum of all dir values */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
64 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
65
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
66 static void
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
67 misc_floater_cleanup(gpointer data)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
68 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
69 g_free(data);
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
70 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
71
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
72 /*
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
73 * This implementation isn't very great.
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
74 * Anyone want to improve it? :(
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
75 */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
76 static void
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
77 misc_floater_exec(const struct pn_actuator_option *opts, gpointer data)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
78 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
79 struct floater_state_data *opaque_data = (struct floater_state_data *) data;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
80 guchar value = (opts[0].val.ival < 0 || opts[0].val.ival > 255) ? 255 : opts[0].val.ival;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
81
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
82 /* determine the root coordinate first */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
83 if (opaque_data->dir & float_up)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
84 opaque_data->y -= 1;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
85 if (opaque_data->dir & float_down)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
86 opaque_data->y += 1;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
87
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
88 if (opaque_data->dir & float_left)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
89 opaque_data->x -= 1;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
90 if (opaque_data->dir & float_right)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
91 opaque_data->x += 1;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
92
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
93 /* make sure we're within surface boundaries. segfaults suck, afterall. */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
94 if (opaque_data->x + 1 <= pn_image_data->width &&
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
95 opaque_data->x - 1 >= 0 &&
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
96 opaque_data->y + 1 <= pn_image_data->height &&
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
97 opaque_data->y - 1 >= 0)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
98 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
99 /* draw it. i could use a loop here, but i don't see much reason in it,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
100 * so i don't think i will at this time. -nenolod
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
101 */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
102 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x, opaque_data->y)] = value;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
103 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x + 1, opaque_data->y)] = value;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
104 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x - 1, opaque_data->y)] = value;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
105 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x, opaque_data->y + 1)] = value;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
106 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x, opaque_data->y - 1)] = value;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
107 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
108
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
109 /* check if we need to change direction yet, and if so, do so. */
302
b185ed2f8fa2 [svn] - improve beat detection
nenolod
parents: 188
diff changeset
110 if (pn_new_beat == TRUE)
186
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
111 opaque_data->dir = (FloaterDirection) rand() % 15; /* sum of all dir values */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
112
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
113 /* now adjust the direction so we stay in boundary */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
114 if (opaque_data->x - 1 <= 0 && opaque_data->dir & float_left)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
115 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
116 opaque_data->dir &= ~float_left;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
117 opaque_data->dir |= float_right;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
118 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
119
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
120 if (opaque_data->x + 1 >= pn_image_data->width && opaque_data->dir & float_right)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
121 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
122 opaque_data->dir &= ~float_right;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
123 opaque_data->dir |= float_left;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
124 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
125
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
126 if (opaque_data->y - 1 <= 0 && opaque_data->dir & float_up)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
127 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
128 opaque_data->dir &= ~float_up;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
129 opaque_data->dir |= float_down;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
130 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
131
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
132 if (opaque_data->y + 1 >= pn_image_data->height && opaque_data->dir & float_down)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
133 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
134 opaque_data->dir &= ~float_down;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
135 opaque_data->dir |= float_up;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
136 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
137 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
138
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
139 struct pn_actuator_desc builtin_misc_floater =
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
140 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
141 "misc_floater",
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
142 "Floating Particle",
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
143 "A floating particle.",
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
144 0, misc_floater_opts,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
145 misc_floater_init, misc_floater_cleanup, misc_floater_exec
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
146 };
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
147