forked from external/yambar
particles: name private structs and variables consistently
This commit is contained in:
parent
3135f1d36d
commit
5fc29f7bbe
4 changed files with 63 additions and 63 deletions
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
struct ramp {
|
||||
struct private {
|
||||
char *tag;
|
||||
struct particle **particles;
|
||||
size_t count;
|
||||
|
@ -15,25 +15,25 @@ struct ramp {
|
|||
static void
|
||||
particle_destroy(struct particle *particle)
|
||||
{
|
||||
struct ramp *ramp = particle->private;
|
||||
struct private *p = particle->private;
|
||||
|
||||
for (size_t i = 0; i < ramp->count; i++)
|
||||
ramp->particles[i]->destroy(ramp->particles[i]);
|
||||
for (size_t i = 0; i < p->count; i++)
|
||||
p->particles[i]->destroy(p->particles[i]);
|
||||
|
||||
free(ramp->tag);
|
||||
free(ramp->particles);
|
||||
free(ramp);
|
||||
free(p->tag);
|
||||
free(p->particles);
|
||||
free(p);
|
||||
particle_default_destroy(particle);
|
||||
}
|
||||
|
||||
static struct exposable *
|
||||
instantiate(const struct particle *particle, const struct tag_set *tags)
|
||||
{
|
||||
const struct ramp *ramp = particle->private;
|
||||
const struct tag *tag = tag_for_name(tags, ramp->tag);
|
||||
const struct private *p = particle->private;
|
||||
const struct tag *tag = tag_for_name(tags, p->tag);
|
||||
assert(tag != NULL);
|
||||
|
||||
assert(ramp->count > 0);
|
||||
assert(p->count > 0);
|
||||
|
||||
long value = tag->as_int(tag);
|
||||
long min = tag->min(tag);
|
||||
|
@ -44,18 +44,18 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
|
|||
|
||||
size_t idx = 0;
|
||||
if (max - min > 0)
|
||||
idx = ramp->count * value / (max - min);
|
||||
idx = p->count * value / (max - min);
|
||||
|
||||
if (idx == ramp->count)
|
||||
if (idx == p->count)
|
||||
idx--;
|
||||
/*
|
||||
* printf("ramp: value: %lu, min: %lu, max: %lu, progress: %f, idx: %zu\n",
|
||||
* value, min, max, progress, idx);
|
||||
*/
|
||||
assert(idx >= 0 && idx < ramp->count);
|
||||
assert(idx >= 0 && idx < p->count);
|
||||
|
||||
struct particle *p = ramp->particles[idx];
|
||||
return p->instantiate(p, tags);
|
||||
struct particle *pp = p->particles[idx];
|
||||
return pp->instantiate(pp, tags);
|
||||
}
|
||||
|
||||
struct particle *
|
||||
|
@ -70,14 +70,14 @@ particle_ramp_new(const char *tag, struct particle *particles[], size_t count,
|
|||
particle->destroy = &particle_destroy;
|
||||
particle->instantiate = &instantiate;
|
||||
|
||||
struct ramp *ramp = malloc(sizeof(*ramp));
|
||||
ramp->tag = strdup(tag);
|
||||
ramp->particles = calloc(count, sizeof(ramp->particles[0]));
|
||||
ramp->count = count;
|
||||
struct private *priv = malloc(sizeof(*priv));
|
||||
priv->tag = strdup(tag);
|
||||
priv->particles = calloc(count, sizeof(priv->particles[0]));
|
||||
priv->count = count;
|
||||
|
||||
for (size_t i = 0; i < count; i++)
|
||||
ramp->particles[i] = particles[i];
|
||||
priv->particles[i] = particles[i];
|
||||
|
||||
particle->private = ramp;
|
||||
particle->private = priv;
|
||||
return particle;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue