Skip to content

Commit

Permalink
images: make images array variable
Browse files Browse the repository at this point in the history
We can now have as many images as memory permits.

Also updated N.fnp:

- green 1 toggles between pac man and ghost (as before)
- green 2 toggles between pac man pleiades
- green 8 toggles between ghost and pac man (as before)
  • Loading branch information
wpwrak committed Feb 16, 2012
1 parent efcfe22 commit 44ad1f6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
6 changes: 4 additions & 2 deletions experimental/N.fnp
@@ -1,4 +1,4 @@
imagefiles=pacman.jpg, ghost.jpg
imagefiles=pacman.jpg, ghost.jpg, pleiades.jpg
decay=0.6
image1_a=0.6
image2_a=0.6
Expand All @@ -8,6 +8,7 @@ midi "Faderfox LV3" {
fad8 = fader(8, 7);

green1 = button(1, 16);
green2 = button(2, 16);
green8 = button(8, 16);

joy1x = pot(9, 1);
Expand All @@ -20,6 +21,7 @@ fad1 = range(fad1);
fad8 = range(fad8);

green1 = button(green1);
green2 = button(green2);
green8 = button(green8);

joy1x = range(joy1x);
Expand All @@ -30,7 +32,7 @@ joy2y = range(joy2y);
per_frame:
image1_zoom = fad1*5+0.1;
image2_zoom = fad8*6+0.1;
image1_index = green1;
image1_index = green1+2*green2;
image2_index = !green8;

sx = 1.06;
Expand Down
42 changes: 26 additions & 16 deletions src/compiler/compiler.c
Expand Up @@ -411,11 +411,18 @@ static const char *assign_image_name(struct parser_comm *comm,
struct compiler_sc *sc = comm->u.sc;
char *totalname;
struct image *img;
#endif

if(number > IMAGE_COUNT)
return strdup("image number out of bounds");
#ifndef STANDALONE
if(number > sc->p->n_images) {
int i;

sc->p->images = realloc(sc->p->images,
number*sizeof(struct image));
for(i = sc->p->n_images; i != number; i++) {
sc->p->images[i].pixbuf = NULL;
sc->p->images[i].filename = NULL;
}
sc->p->n_images = number;
}
number--;

if(*name == '/')
Expand Down Expand Up @@ -472,7 +479,6 @@ struct patch *patch_compile(const char *basedir, const char *patch_code,
{
struct compiler_sc *sc;
struct patch *p;
int i;

sc = malloc(sizeof(struct compiler_sc));
if(sc == NULL) {
Expand All @@ -485,10 +491,8 @@ struct patch *patch_compile(const char *basedir, const char *patch_code,
free(sc);
return NULL;
}
for(i=0;i<IMAGE_COUNT;i++) {
sc->p->images[i].pixbuf = NULL;
sc->p->images[i].filename = NULL;
}
sc->p->images = NULL;
sc->p->n_images = 0;
sc->p->ref = 1;
sc->p->require = 0;
sc->p->original = NULL;
Expand Down Expand Up @@ -561,18 +565,23 @@ struct patch *patch_copy(struct patch *p)
{
struct patch *new_patch;
struct image *img;
int i;

new_patch = malloc(sizeof(struct patch));
assert(new_patch != NULL);
memcpy(new_patch, p, sizeof(struct patch));
new_patch->ref = 1;
new_patch->original = p;
new_patch->next = NULL;
for(img = new_patch->images;
img != new_patch->images+IMAGE_COUNT; img++) {
if(img->filename)
img->filename = strdup(img->filename);
pixbuf_inc_ref(img->pixbuf);
if(p->images) {
new_patch->images = malloc(p->n_images*sizeof(struct image));
for(i = 0; i != p->n_images; i++) {
img = new_patch->images+i;
*img = p->images[i];
if(img->filename)
img->filename = strdup(img->filename);
pixbuf_inc_ref(img->pixbuf);
}
}
new_patch->stim = stim_get(p->stim);
if(p->stim)
Expand All @@ -587,10 +596,11 @@ void patch_free(struct patch *p)
assert(p->ref);
if(--p->ref);
return;
for(img = p->images; img != p->images+IMAGE_COUNT; img++) {
for(img = p->images; img != p->images+p->n_images; img++) {
pixbuf_dec_ref(img->pixbuf);
free((void *) img->filename);
}
free(p->images);
stim_put(p->stim);
free(p);
}
Expand All @@ -600,7 +610,7 @@ struct patch *patch_refresh(struct patch *p)
struct image *img;
struct pixbuf *pixbuf;

for(img = p->images; img != p->images+IMAGE_COUNT; img++) {
for(img = p->images; img != p->images+p->n_images; img++) {
if(!img->pixbuf)
continue;
pixbuf = pixbuf_update(img->pixbuf);
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/compiler.h
Expand Up @@ -230,7 +230,8 @@ struct image {

struct patch {
/* per-frame */
struct image images[IMAGE_COUNT]; /* images used in this patch */
struct image *images; /* images used in this patch */
int n_images; /* number of images */
float pfv_initial[COMP_PFV_COUNT]; /* patch initial conditions */
int pfv_allocation[COMP_PFV_COUNT]; /* where per-frame variables
are mapped in PFPU regf,
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/eval.c
Expand Up @@ -317,7 +317,7 @@ static rtems_task eval_task(rtems_task_argument argument)
for(i=0;i<IMAGE_COUNT;i++) {
int n = frd->image_index[i];

frd->images[i] = n >= 0 && n < IMAGE_COUNT ?
frd->images[i] = n >= 0 && n < p->n_images ?
p->images[n].pixbuf : NULL;
}

Expand Down

0 comments on commit 44ad1f6

Please sign in to comment.