comparison src/paranormal/containers.c @ 164:0393aae79318 trunk

[svn] - clean up about box - add on-beat branch-change evaluation
author nenolod
date Tue, 31 Oct 2006 21:28:30 -0800
parents adf9f4b26039
children a118245b88c7
comparison
equal deleted inserted replaced
163:46e074b915eb 164:0393aae79318
5 #include <stdio.h> 5 #include <stdio.h>
6 6
7 #include <glib.h> 7 #include <glib.h>
8 8
9 #include "actuators.h" 9 #include "actuators.h"
10 #include "paranormal.h"
10 11
11 /* **************** all containers **************** */ 12 /* **************** all containers **************** */
12 13
13 /* Add a actuator to a container (end of list) */ 14 /* Add a actuator to a container (end of list) */
14 void 15 void
141 /* **************** container_cycle ***************** */ 142 /* **************** container_cycle ***************** */
142 static struct pn_actuator_option_desc container_cycle_opts[] = 143 static struct pn_actuator_option_desc container_cycle_opts[] =
143 { 144 {
144 { "change_interval", "The number of seconds between changing the " 145 { "change_interval", "The number of seconds between changing the "
145 "child to be executed", OPT_TYPE_INT, { ival: 20 } }, 146 "child to be executed", OPT_TYPE_INT, { ival: 20 } },
146 { "random", "Whether or not the change should be random", 147 { "beat", "Whether or not the change should only occur on a beat",
147 OPT_TYPE_BOOLEAN, { bval: TRUE } }, 148 OPT_TYPE_BOOLEAN, { bval: TRUE } },
148 { 0 } 149 { 0 }
149 }; 150 };
150 151
151 struct container_cycle_data 152 struct container_cycle_data
152 { 153 {
153 GSList *children; 154 GSList *children;
154 GSList *current; 155 GSList *current;
155 int last_change; 156 int last_change;
157 int last_beat;
156 }; 158 };
157 159
158 static void 160 static void
159 container_cycle_init (gpointer *data) 161 container_cycle_init (gpointer *data)
160 { 162 {
172 container_cycle_exec (const struct pn_actuator_option *opts, 174 container_cycle_exec (const struct pn_actuator_option *opts,
173 gpointer data) 175 gpointer data)
174 { 176 {
175 struct container_cycle_data *cdata = (struct container_cycle_data*)data; 177 struct container_cycle_data *cdata = (struct container_cycle_data*)data;
176 int now; 178 int now;
177 179 int new_beat = ((pn_sound_data->pcm_data[0][0]+pn_sound_data->pcm_data[1][0]) >> 7) >= 80 ? 1 : 0;
178 now = SDL_GetTicks (); 180
179 181 /*
180 if (now - cdata->last_change 182 * Change branch if all of the requirements are met for the branch to change.
181 > opts[0].val.ival * 1000) 183 */
184 if ((opts[1].val.bval == TRUE && new_beat != cdata->last_beat) || opts[1].val.bval == FALSE)
182 { 185 {
183 cdata->last_change = now; 186 now = SDL_GetTicks();
184 187
185 /* FIXME: add randomization support */ 188 if (now - cdata->last_change
186 if (cdata->current) 189 > opts[0].val.ival * 1000)
187 cdata->current = cdata->current->next; 190 {
191 cdata->last_change = now;
192
193 /* FIXME: add randomization support */
194 if (cdata->current)
195 cdata->current = cdata->current->next;
196 }
188 } 197 }
198
199 /* reset the tracking for on-beat branch changing. */
200 cdata->last_beat = new_beat;
189 201
190 if (! cdata->current) 202 if (! cdata->current)
191 cdata->current = cdata->children; 203 cdata->current = cdata->children;
192 204
193 if (cdata->current) 205 if (cdata->current)
197 struct pn_actuator_desc builtin_container_cycle = 209 struct pn_actuator_desc builtin_container_cycle =
198 { 210 {
199 "container_cycle", 211 "container_cycle",
200 "Branched-execution Container", 212 "Branched-execution Container",
201 "A container that alternates which of its children is executed; it " 213 "A container that alternates which of its children is executed; it "
202 "can either change children randomly or go in order.", 214 "can either change on an interval, or only on a beat.",
203 ACTUATOR_FLAG_CONTAINER, container_cycle_opts, 215 ACTUATOR_FLAG_CONTAINER, container_cycle_opts,
204 container_cycle_init, container_cycle_cleanup, container_cycle_exec 216 container_cycle_init, container_cycle_cleanup, container_cycle_exec
205 }; 217 };