Add Russian translation provided by Валерий Крувялис <valkru@mail.ru>
[xiph-mirror.git] / planarity / gameboard_logic_fade.c
blobdedd30146dfadc37d3d30eddb5d985e3263c2400
1 /*
3 * gPlanarity:
4 * The geeky little puzzle game with a big noodly crunch!
5 *
6 * gPlanarity copyright (C) 2005 Monty <monty@xiph.org>
7 * Original Flash game by John Tantalo <john.tantalo@case.edu>
8 * Original game concept by Mary Radcliffe
10 * gPlanarity is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
15 * gPlanarity is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Postfish; see the file COPYING. If not, write to the
22 * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <stdlib.h>
28 #include "graph.h"
29 #include "gameboard.h"
31 static fade_list *pool=0;
33 #define CHUNK 32
34 static void fade_add_vertex(fade_state *f,vertex *v){
35 fade_list *ret;
37 if(pool==0){
38 int i;
39 pool = calloc(CHUNK,sizeof(*pool));
40 for(i=0;i<CHUNK-1;i++) /* last addition's next points to nothing */
41 pool[i].next=pool+i+1;
44 ret=pool;
45 pool=ret->next;
47 ret->v=v;
48 v->fading=1;
50 ret->next = f->head;
51 f->head = ret;
54 static gint animate_fade(gpointer ptr){
55 Gameboard *g = (Gameboard *)ptr;
56 fade_state *f = &g->fade;
58 f->count--;
59 if(f->count>0){
60 fade_list *l = f->head;
62 while(l){
63 invalidate_vertex(g,l->v);
64 l=l->next;
67 return 1;
70 fade_cancel(g);
71 return 0;
74 void fade_cancel(Gameboard *g){
75 fade_state *f = &g->fade;
76 fade_list *l = f->head;
78 while(l){
79 fade_list *n = l->next;
81 /* unflag vertex */
82 l->v->fading=0;
84 /* invalidate the vertex */
85 invalidate_vertex(g,l->v);
87 l->next=pool;
88 pool=l;
89 l=n;
91 f->head = 0;
92 f->count = 0;
94 if(f->fade_timer)
95 g_source_remove(f->fade_timer);
96 f->fade_timer=0;
99 void fade_attached(Gameboard *g,vertex *v){
100 fade_state *f = &g->fade;
101 edge_list *el=v->edges;
103 /* If a fade is already in progress, cancel it */
104 fade_cancel(g);
106 while(el){
107 edge *e=el->edge;
109 if(v == e->A){
110 fade_add_vertex(f,e->B);
111 }else{
112 fade_add_vertex(f,e->A);
114 el=el->next;
117 f->count = FADE_FRAMES;
119 f->fade_timer = g_timeout_add(FADE_ANIM_INTERVAL, animate_fade, (gpointer)g);
122 void fade_grabbed(Gameboard *g){
123 fade_state *f = &g->fade;
124 vertex *v = g->g.verticies;
126 /* If a fade is already in progress, cancel it */
127 fade_cancel(g);
129 while(v){
130 if(v->grabbed){
131 edge_list *el=v->edges;
134 while(el){
135 edge *e=el->edge;
137 if(v == e->A){
138 if(!e->B->grabbed)
139 fade_add_vertex(f,e->B);
140 }else{
141 if(!e->A->grabbed)
142 fade_add_vertex(f,e->A);
144 el=el->next;
147 v=v->next;
150 f->count = FADE_FRAMES;
152 f->fade_timer = g_timeout_add(FADE_ANIM_INTERVAL, animate_fade, (gpointer)g);
155 void fade_marked(Gameboard *g){
156 fade_state *f = &g->fade;
157 vertex *v = g->g.verticies;
159 /* If a fade is already in progress, cancel it */
160 fade_cancel(g);
162 while(v){
163 if(v->grabbed)
164 fade_add_vertex(f,v);
165 v=v->next;
168 f->count = FADE_FRAMES;
170 f->fade_timer = g_timeout_add(FADE_ANIM_INTERVAL, animate_fade, (gpointer)g);