~ubuntu-branches/ubuntu/raring/powermanga/raring

« back to all changes in this revision

Viewing changes to src/playanim.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Gonéri Le Bouder, Cyril Brulebois, Barry deFreese
  • Date: 2008-03-19 21:32:41 UTC
  • mfrom: (1.2.4 upstream) (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080319213241-sn6w3z75uppm22eq
Tags: 0.90-dfsg-1
[ Gonéri Le Bouder ]
* add desktop file, thanks Adrien Cunin (Closes: #402168)
 - powermanga.xpm moved in /usr/share/pixmaps
* call dh_desktop to run update-desktop-database

[ Cyril Brulebois ]
* Added XS-Vcs-Svn and XS-Vcs-Browser fields in the control file.

[ Barry deFreese ]
* Bump debhelper build-dep version to match compat
* Fix substvar source:Version
* Make distclean not ignore errors
* Add watch file
* Add Homepage field in control
* Remove XS- from VCS fields in control
* New Upstream Release (Closes: #447415)
  + Should now be dfsg free
  + Adds joystick support (Closes: #442322)
  + STILL NOT SURE ABOUT tlk.fnt
* Revert patches except fixing scoredir path and copyright for manpage
* Remove deprecated Encoding tag from desktop file
* Remove file extension from icon tag in desktop file
* Replace evil 'pwd' with $(CURDIR)
* Removing config.log config.status in clean target
* Convert copyright to UTF-8.
* Remove order/ dir from upstream tarball.
* Remove empty dirs from powermanga package.
* Bump Standards Version to 3.7.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//*****************************************************************************
2
 
// copyright (c) 1998-2003 TLK Games all rights reserved
3
 
//-----------------------------------------------------------------------------
4
 
// file         : "playanim.cpp"
5
 
// created      : ?
6
 
// updates      : 2003-07-20
7
 
//-----------------------------------------------------------------------------
8
 
// functions    : int            joueAnimation()
9
 
//                int            InitAnim(char *)
10
 
//                void           ReleaseAnim()
11
 
//                int            init(char*);
12
 
//                unsigned char* PlayAnim(int);
13
 
//                unsigned char* decompress(unsigned char*, unsigned char*,unsigned char*);
14
 
//-----------------------------------------------------------------------------
15
 
// descriptions         : play animation / 
16
 
//-----------------------------------------------------------------------------
17
 
// This program is free software; you can redistribute it and/or modify it under
18
 
// the terms of the GNU General Public License as published by the Free Software
19
 
// Foundation; either version 2 of the License, or (at your option) any later
20
 
// version.
21
 
// 
22
 
// This program is distributed in the hope that it will be useful, but WITHOUT
23
 
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
24
 
// FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
25
 
// details.
26
 
//
27
 
// You should have received a copy of the GNU General Public License along with
28
 
// this program; if not, write to the Free Software Foundation, Inc., 59 Temple
29
 
// Place - Suite 330, Boston, MA  02111-1307, USA.
30
 
//
31
 
//*****************************************************************************
32
 
#include "powermanga.hpp"
33
 
//..............................................................................
34
 
unsigned char          *image1 = 0;
35
 
static unsigned char   *image2 = 0;
36
 
static unsigned char   *icmpr = 0;
37
 
static unsigned char   *smage1 = 0;
38
 
static unsigned char   *smage2 = 0;
39
 
static unsigned char   *scmpr = 0;
40
 
static unsigned char   *pFichier = 0;                          //pointer to the file in memory
41
 
 
42
 
//..............................................................................
43
 
static unsigned char   *pcxpal = 0;                            //pointer to the colormap in the file
44
 
static int              ic = 0;
45
 
static int              images = 0;
46
 
 
47
 
//..............................................................................
48
 
extern unsigned int     iOctetsParPixel;                       //bytes per pixel "xwindow.cpp"
49
 
extern unsigned int     iCodeTouche;                           //key code pressed)
50
 
extern unsigned int     iJoueIntro;                            //(1=intro / 2=congratulation)
51
 
extern unsigned short  *pal16PlayAnim;                         //16 bits colormap (2 bytes par color)
52
 
extern unsigned int    *pal32PlayAnim;                         //32 bits colormap (4 bytes par color)
53
 
 
54
 
//locals functions .............................................................
55
 
int                     InitAnim(char *);
56
 
void                    ReleaseAnim();
57
 
int                     ainit(char *);
58
 
unsigned char          *PlayAnim(int);
59
 
unsigned char          *decompress(unsigned char *, unsigned char *, unsigned char *);
60
 
 
61
 
//------------------------------------------------------------------------------
62
 
// play animation compressed 
63
 
//------------------------------------------------------------------------------
64
 
int joueAnimation()
65
 
{
66
 
  switch (iJoueIntro)
67
 
  { //introduction animation
68
 
    case 1: 
69
 
      if(InitAnim("graphics/deb.gca"))
70
 
        iJoueIntro = 5;
71
 
      else
72
 
      { iJoueIntro = 0;
73
 
        afficheErreur("InitAnim(\"graphics/deb.gca\")", "playanim.cpp/joueAnimation()");
74
 
        return 0;
75
 
      }
76
 
      break;
77
 
    //congratulation animation
78
 
    case 2:
79
 
      if(InitAnim("graphics/fin.gca"))
80
 
        iJoueIntro = 5;
81
 
      else
82
 
      { iJoueIntro = 0;
83
 
        afficheErreur("InitAnim(\"graphics/fin.gca\")", "playanim.cpp/joueAnimation()");
84
 
        return 0;
85
 
      }
86
 
      break;
87
 
    //play animation compressed 
88
 
    case 5: 
89
 
    { unsigned char *_pScreen = PlayAnim(0);
90
 
      if(_pScreen != NULL && iCodeTouche == 0)
91
 
      {
92
 
      }
93
 
      else
94
 
      { ReleaseAnim();
95
 
        iJoueIntro = 0;
96
 
      }
97
 
    }
98
 
      break;
99
 
  }
100
 
  return 1;
101
 
}
102
 
 
103
 
//------------------------------------------------------------------------------
104
 
// initialize animation
105
 
// input => _pFileName : filename
106
 
//------------------------------------------------------------------------------
107
 
int InitAnim(char *_pFileName)
108
 
{
109
 
  int i = 0;
110
 
  smage1 = smage2 = scmpr = 0;
111
 
  smage1 = ((unsigned char *)reserveMemoire(64000));
112
 
  if(!smage1)
113
 
  { afficheErreur("'smage1' out of memory", "playanim.cpp/InitAnim()");
114
 
    return 0;
115
 
  }
116
 
  smage2 = ((unsigned char *)reserveMemoire(64000));
117
 
  if(!smage1)
118
 
  { afficheErreur("'smage2' out of memory", "playanim.cpp/InitAnim()");
119
 
    return 0;
120
 
  }
121
 
  pFichier = ((unsigned char *)reserveMemoire((1024 * 1024 * 4)));
122
 
  if(!pFichier)
123
 
  { afficheErreur("'pFichier' out of memory", "playanim.cpp/InitAnim");
124
 
    return 0;
125
 
  }
126
 
  for(i = 0; i < 64000; i++)
127
 
  { smage1[i] = 0;
128
 
    smage2[i] = 0;
129
 
  }
130
 
  if(!ainit(_pFileName))
131
 
  { afficheErreur("ainit() failed !", "playanim.cpp/InitAnim()");
132
 
    return 0;
133
 
  }
134
 
  image1 = smage1;
135
 
  image2 = smage2;
136
 
  icmpr = scmpr;
137
 
  ic = 0;
138
 
  if(!reserve_ecranPlayanim())
139
 
  {afficheErreur("reserve_ecranPlayanim() failed !", "playanim.cpp/InitAnim()");
140
 
    return 0;
141
 
  }
142
 
  return 1;
143
 
}
144
 
 
145
 
//------------------------------------------------------------------------------
146
 
// initialize animation
147
 
// input => _pFileName : filename
148
 
//------------------------------------------------------------------------------
149
 
int ainit(char *_pFileName)
150
 
{
151
 
  int *_p32;
152
 
  unsigned char *_p8;
153
 
 
154
 
  if(!chargeFichier(_pFileName, (char *)pFichier))
155
 
    return 0;
156
 
  _p32 = (int *)pFichier;
157
 
  images = litMot32bits(_p32++);
158
 
  _p8 = (unsigned char *)_p32;
159
 
  pcxpal = _p8;
160
 
  scmpr = _p8 + 768;
161
 
  if(iOctetsParPixel == 2)
162
 
  {
163
 
    if(!pal16PlayAnim)
164
 
      pal16PlayAnim = (unsigned short *)reserveMemoire(256 * 2);
165
 
    if(!pal16PlayAnim)
166
 
    {
167
 
      afficheErreur("'pal16PlayAnim' out of memory", "playanim.cpp/InitAnim()");
168
 
      return 0;
169
 
    }
170
 
    convertitPalette24_16(pcxpal, pal16PlayAnim);  //"assembler.S"
171
 
  }
172
 
  if(iOctetsParPixel > 2)
173
 
  {
174
 
    if(!pal32PlayAnim)
175
 
      pal32PlayAnim = (unsigned int *)reserveMemoire(256 * 4);
176
 
    if(!pal32PlayAnim)
177
 
    {
178
 
      afficheErreur("'pal32PlayAnim' out of memory", "playanim.cpp/InitAnim()");
179
 
      return 0;
180
 
    }
181
 
    unsigned char *_p = (unsigned char *)pal32PlayAnim;
182
 
    unsigned char *_pPal = pcxpal;
183
 
    for(int _iIndex = 0; _iIndex < 256; _iIndex++)
184
 
    {
185
 
#if __BYTE_ORDER == __BIG_ENDIAN
186
 
#ifdef SDL_TLK
187
 
      _p[2] = _pPal[2];
188
 
      _p[1] = _pPal[1];
189
 
      _p[0] = _pPal[0];
190
 
      _p[3] = 0;
191
 
#else     
192
 
      _p[3] = _pPal[2];
193
 
      _p[2] = _pPal[1];
194
 
      _p[1] = _pPal[0];
195
 
      _p[0] = 0;
196
 
#endif      
197
 
#else
198
 
#ifdef SDL_TLK
199
 
      _p[2] = _pPal[2];
200
 
      _p[1] = _pPal[1];
201
 
      _p[0] = _pPal[0];
202
 
      _p[3] = 0;
203
 
#else      
204
 
      _p[0] = _pPal[2];
205
 
      _p[1] = _pPal[1];
206
 
      _p[2] = _pPal[0];
207
 
      _p[3] = 0;
208
 
#endif      
209
 
#endif
210
 
      _p += 4;
211
 
      _pPal += 3;
212
 
    }
213
 
  }
214
 
  return 1;
215
 
}
216
 
 
217
 
//------------------------------------------------------------------------------
218
 
// playanim : free memory
219
 
//------------------------------------------------------------------------------
220
 
void ReleaseAnim()
221
 
{
222
 
  if(smage1)
223
 
  { libereMemoire((char *)smage1);
224
 
    smage1 = 0;
225
 
  }
226
 
  if(smage2)
227
 
  { libereMemoire((char *)smage2);
228
 
    smage2 = 0;
229
 
  }
230
 
  if(pal16PlayAnim)
231
 
  { libereMemoire((char *)pal16PlayAnim);
232
 
    pal16PlayAnim = 0;
233
 
  }
234
 
  kill_ecranPlayanim(); // "xwindow.cpp" free XImage
235
 
}
236
 
 
237
 
//------------------------------------------------------------------------------
238
 
// playanim : run-time
239
 
//------------------------------------------------------------------------------
240
 
unsigned char *PlayAnim(int bcl)
241
 
{
242
 
  int i;
243
 
  unsigned char *tmp; //images=64+16+2+1+1 ;
244
 
  ic++;
245
 
  if(ic == images - 1)
246
 
    if(bcl == 0)
247
 
      return 0;
248
 
    else
249
 
    { ic = 0;
250
 
      icmpr = scmpr;
251
 
      for(i = 0; i < 64000; i++)
252
 
      { smage1[i] = 0;
253
 
        smage2[i] = 0;
254
 
      }
255
 
    }
256
 
  icmpr = decompress(icmpr, image1, image2);
257
 
  tmp = image1;
258
 
  image1 = image2;
259
 
  image2 = tmp;
260
 
  return image1;
261
 
}
262
 
 
263
 
//------------------------------------------------------------------------------
264
 
// playanim : decompress 
265
 
//------------------------------------------------------------------------------
266
 
unsigned char *decompress(unsigned char *wsc, unsigned char *im1, unsigned char *im2)
267
 
{
268
 
  int i, j;
269
 
  unsigned char *idec;
270
 
  unsigned char *wdec;
271
 
  unsigned char c;
272
 
  unsigned char color;
273
 
  int longueur = 0;
274
 
  int retour = 0;
275
 
  int position = 0;
276
 
  i = 0;
277
 
  idec = im2;
278
 
  while (i < 64000)
279
 
  { int mode = 0;
280
 
    c = *wsc++; //read a byte
281
 
    if(c == 255)
282
 
    { color = *wsc++;
283
 
      *idec++ = color;
284
 
      i++;
285
 
      mode = 0;
286
 
    }
287
 
    else if((c & 0xc0) == 0)
288
 
    { unsigned int wr = 0;
289
 
      wr = c << 16;
290
 
      wr += (*wsc++) << 8;
291
 
      wr += *wsc++;
292
 
      longueur = wr & 63;
293
 
      position = (wr >> 6) & 65535;
294
 
      mode = 1;
295
 
    }
296
 
    else if((c & 0xc0) == 0x40)
297
 
    { unsigned int wr = 0;
298
 
      wr = c << 24;
299
 
      wr += (*wsc++) << 16;
300
 
      wr += (*wsc++) << 8;
301
 
      wr += *wsc++;
302
 
      longueur = wr & 16383;
303
 
      position = (wr >> 14) & 65535;
304
 
      mode = 1;
305
 
    }
306
 
    else if((c & 0xe0) == 0x80)
307
 
    { unsigned int wr = 0;
308
 
      wr = c << 8;
309
 
      wr += *wsc++;
310
 
      longueur = wr & 63;
311
 
      retour = (wr >> 6) & 255;
312
 
      mode = 2;
313
 
    }
314
 
    else if((c & 0xe0) == 0xa0)
315
 
    { unsigned int wr = 0;
316
 
      wr = c << 16;
317
 
      wr += (*wsc++) << 8;
318
 
      wr += *wsc++;
319
 
      longueur = wr & 255;
320
 
      retour = (wr >> 8) & 8191;
321
 
      mode = 2;
322
 
    }
323
 
    else if((c & 0xe0) == 0xc0)
324
 
    { unsigned int wr = 0;
325
 
      wr = c << 24;
326
 
      wr += (*wsc++) << 16;
327
 
      wr += (*wsc++) << 8;
328
 
      wr += *wsc++;
329
 
      longueur = wr & 8191;
330
 
      position = (wr >> 13) & 65535;
331
 
      mode = 3;
332
 
    }
333
 
    if(i + longueur > 64000)
334
 
    { longueur = 64000 - i;
335
 
    }
336
 
    if(mode == 1)
337
 
    { for(j = 0; j < longueur; j++)
338
 
        *idec++ = im1[position + j];
339
 
      i += longueur;
340
 
    }
341
 
    else if(mode == 2)
342
 
    { wdec = idec - retour;
343
 
      for(j = 0; j < longueur; j++)
344
 
        *idec++ = *wdec++;
345
 
      i += longueur;
346
 
    }
347
 
    else if(mode == 3)
348
 
    { for(j = 0; j < longueur; j++)
349
 
        *idec++ = im2[position + j];
350
 
      i += longueur;
351
 
    }
352
 
  }
353
 
  return wsc;
354
 
}