annotate src/rovascope/misc.c @ 760:6ed8d477ba89 trunk

[svn] - add tuple building for ADTS/Shoutcast streams
author nenolod
date Wed, 28 Feb 2007 19:48:28 -0800
parents 290588854a9d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
186
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
1 #ifdef HAVE_CONFIG_H
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
2 # include <config.h>
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
3 #endif
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
4
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
5 #include <stdlib.h>
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
6 #include <stdio.h>
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
7
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
8 #include <glib.h>
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
9
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
10 #include "paranormal.h"
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
11 #include "actuators.h"
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
12 #include "pn_utils.h"
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
13
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
14 /* ******************** misc_floater ******************** */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
15 static struct pn_actuator_option_desc misc_floater_opts[] =
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
16 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
17 { "value", "The colour value for the floater.",
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
18 OPT_TYPE_INT, { ival: 255 } },
188
0d826917c56f [svn] - 64-bit safety (pass 1 of 2)
nenolod
parents: 186
diff changeset
19 { NULL }
186
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
20 };
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
21
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
22 typedef enum
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
23 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
24 float_up = 0x1,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
25 float_down = 0x2,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
26 float_left = 0x4,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
27 float_right = 0x8,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
28 } FloaterDirection;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
29
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
30 struct floater_state_data
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
31 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
32 FloaterDirection dir;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
33 gint x;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
34 gint y;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
35 };
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
36
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
37 static void
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
38 misc_floater_init(gpointer *data)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
39 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
40 struct floater_state_data *opaque_data = g_new0(struct floater_state_data, 1);
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
41 *data = opaque_data;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
42 opaque_data->x = rand() % pn_image_data->width;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
43 opaque_data->y = rand() % pn_image_data->height;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
44 opaque_data->dir = (FloaterDirection) rand() % 15; /* sum of all dir values */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
45 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
46
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
47 static void
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
48 misc_floater_cleanup(gpointer data)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
49 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
50 g_free(data);
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
51 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
52
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
53 /*
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
54 * This implementation isn't very great.
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
55 * Anyone want to improve it? :(
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
56 */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
57 static void
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
58 misc_floater_exec(const struct pn_actuator_option *opts, gpointer data)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
59 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
60 struct floater_state_data *opaque_data = (struct floater_state_data *) data;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
61 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
62
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
63 /* determine the root coordinate first */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
64 if (opaque_data->dir & float_up)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
65 opaque_data->y -= 1;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
66 if (opaque_data->dir & float_down)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
67 opaque_data->y += 1;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
68
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
69 if (opaque_data->dir & float_left)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
70 opaque_data->x -= 1;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
71 if (opaque_data->dir & float_right)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
72 opaque_data->x += 1;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
73
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
74 /* make sure we're within surface boundaries. segfaults suck, afterall. */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
75 if (opaque_data->x + 1 <= pn_image_data->width &&
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
76 opaque_data->x - 1 >= 0 &&
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
77 opaque_data->y + 1 <= pn_image_data->height &&
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
78 opaque_data->y - 1 >= 0)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
79 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
80 /* 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
81 * so i don't think i will at this time. -nenolod
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
82 */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
83 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x, opaque_data->y)] = value;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
84 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
85 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
86 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
87 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
88 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
89
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
90 /* check if we need to change direction yet, and if so, do so. */
302
b185ed2f8fa2 [svn] - improve beat detection
nenolod
parents: 188
diff changeset
91 if (pn_new_beat == TRUE)
186
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
92 opaque_data->dir = (FloaterDirection) rand() % 15; /* sum of all dir values */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
93
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
94 /* now adjust the direction so we stay in boundary */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
95 if (opaque_data->x - 1 <= 0 && opaque_data->dir & float_left)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
96 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
97 opaque_data->dir &= ~float_left;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
98 opaque_data->dir |= float_right;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
99 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
100
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
101 if (opaque_data->x + 1 >= pn_image_data->width && opaque_data->dir & float_right)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
102 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
103 opaque_data->dir &= ~float_right;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
104 opaque_data->dir |= float_left;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
105 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
106
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
107 if (opaque_data->y - 1 <= 0 && opaque_data->dir & float_up)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
108 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
109 opaque_data->dir &= ~float_up;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
110 opaque_data->dir |= float_down;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
111 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
112
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
113 if (opaque_data->y + 1 >= pn_image_data->height && opaque_data->dir & float_down)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
114 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
115 opaque_data->dir &= ~float_down;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
116 opaque_data->dir |= float_up;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
117 }
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 struct pn_actuator_desc builtin_misc_floater =
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
121 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
122 "misc_floater",
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
123 "Floating Particle",
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
124 "A floating particle.",
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
125 0, misc_floater_opts,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
126 misc_floater_init, misc_floater_cleanup, misc_floater_exec
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
127 };
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
128