aboutsummaryrefslogtreecommitdiff
path: root/parex/egg.h
blob: 6830eddbf1253ab14605ff8337086e5d1f91fbb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* 
 *  EGG.H - part of the EGG system.
 *
 *  Global definitions and function prototypes.
 *
 *  By Shawn Hargreaves.
 */


#ifndef __EGG_H__
#define __EGG_H__


#ifndef TRUE 
#define TRUE         -1
#define FALSE        0
#endif

#ifndef MIN
#define MIN(x,y)     (((x) < (y)) ? (x) : (y))
#define MAX(x,y)     (((x) > (y)) ? (x) : (y))
#define MID(x,y,z)   MAX((x), MIN((y), (z)))
#endif

#ifndef ABS
#define ABS(x)       (((x) >= 0) ? (x) : (-(x)))
#endif

#ifndef ALLEGRO_H
struct BITMAP;
#endif



/* possible particle commands (ie. language keywords) */
#define EGG_COMMAND_INIT   1
#define EGG_COMMAND_SET    2
#define EGG_COMMAND_IF     3
#define EGG_COMMAND_LAY    4
#define EGG_COMMAND_DIE    5



/* each particle is controlled by a command list */
typedef struct EGG_COMMAND
{
   int type;                        /* command type */
   int line;                        /* source line number */
   char *var;                       /* variable to be set */
   char *exp;                       /* arithmetic expression */
   struct EGG_COMMAND *cmd;         /* nested, child command list (if) */
   struct EGG_COMMAND *cmd2;        /* more child commands (else) */
   struct EGG_COMMAND *next;        /* linked list pointer */
} EGG_COMMAND;



/* each type of particle is defined by one of these structures */
typedef struct EGG_TYPE
{
   char *name;                      /* type name */
   EGG_COMMAND *cmd;                /* command list */
   struct EGG_TYPE *next;           /* linked list pointer */
} EGG_TYPE;



/* particles store their state variables in these structures */
typedef struct EGG_VARIABLE
{
   char *name;                      /* variable name */
   double val;                      /* current value */
   struct EGG_VARIABLE *next;       /* linked list pointer */
} EGG_VARIABLE;



/* a specific particle instance */
typedef struct EGG_PARTICLE
{
   int num;                         /* unique ID number */
   EGG_TYPE *type;                  /* type information */
   EGG_VARIABLE *var;               /* list of variables */
   struct EGG_PARTICLE *next;       /* linked list pointer */
} EGG_PARTICLE;



/* everything you need to know about an EGG particle system */
typedef struct EGG
{
   int frame;                       /* animation frame number */
   int part_count;                  /* number of active particles */
   int part_num;                    /* particle ID counter */
   EGG_PARTICLE *part;              /* list of particle instances */
   EGG_TYPE *type;                  /* list of particle types */
   EGG_VARIABLE *var;               /* list of global variables */
} EGG;



/* script loading functions */
EGG *load_egg(char *filename, char *error);
EGG *use_egg(void *data, int length, char *error);

/* script unloading function */
void destroy_egg(EGG *egg);

/* script interpreter */
int update_egg(EGG *egg, char *error);

/* renders the current animation state into an Allegro bitmap */
void lay_egg(EGG *egg, struct BITMAP *bmp);

/* internal utility functions */
double evaluate(char *equation, int *error, double (*variable)(char *name));

int process_egg_cmd(EGG *egg, EGG_PARTICLE *part, EGG_PARTICLE *other, EGG_COMMAND *cmd, int init, int set, char *error);
void destroy_egg_cmd(EGG_COMMAND *cmd);

double get_egg_variable(EGG_PARTICLE *part, EGG_PARTICLE *other, EGG *egg, char *name);
void set_egg_variable(EGG_PARTICLE *part, EGG_PARTICLE *other, EGG *egg, char *name, double value);



#endif      /* __EGG_H__ */