source: abuse/trunk/src/seq.cpp @ 503

Last change on this file since 503 was 503, checked in by Sam Hocevar, 11 years ago

cache: fix a crash caused by empty SFX objects being reused for other
purposes but still being deleted later on.

File size: 2.3 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com or
8 *  Jonathan Clark.
9 */
10
11#include "config.h"
12
13#include "seq.h"
14#include "macs.h"
15#include "lisp.h"
16
17int sequence::size()
18{
19  int t=0;
20  for (int i=0; i<total; i++)
21  {
22    if (cache.loaded(seq[i]))
23      t+=cache.fig(seq[i])->size();
24  }
25  return t;
26}
27
28int sequence::cache_in()
29{
30  int i;
31  for (i=0; i<total; i++)
32  {
33    cache.note_need(seq[i]);
34  }
35  return 1;
36}
37
38sequence::sequence(char *filename, void *pict_list, void *advance_list)
39{
40  if (item_type(pict_list)==L_STRING)
41    total=1;
42  else
43    total = ((LList *)pict_list)->GetLength();
44
45  seq=(int *) malloc(sizeof(int)*total);
46  if (item_type(pict_list)==L_STRING)
47    seq[0]=cache.reg_object(filename,(LObject *)pict_list,SPEC_CHARACTER2,1);
48  else
49  {
50    int i;
51    for (i=0; i<total; i++)
52    {
53      seq[i]=cache.reg_object(filename,lcar(pict_list),SPEC_CHARACTER2,1);
54      pict_list=lcdr(pict_list);
55    }
56  }
57}
58
59sequence::~sequence()
60{
61  free(seq);
62}
63
64/*sequence::sequence(char *filename, char *picts)
65{
66  char t[100],*s=picts,imname[100];
67  int i,j;
68  total=0;
69
70  // first count the images
71  while (token_type(s)!=sRIGHT_PAREN)
72  {
73    if (token_type(s)==sLEFT_PAREN)
74    {
75      get_token(s,t);    // left paren
76      get_token(s,t);    // seq
77      get_token(s,t);    // name
78      i=get_number(s);
79      total+=get_number(s)-i+1;
80      get_token(s,t);    // right paren
81    }
82    else
83    { get_token(s,t);
84      total++;
85    }
86  }
87
88
89  s=picts;
90  seq=(int *) malloc(sizeof(int)*total);
91
92  for (i=0; i<total; )
93  {
94    if (get_token(s,t)==sLEFT_PAREN)
95    {
96      get_token(s,t);      // left paren
97      if (strcmp(t,"seq"))
98      {
99    printf("Expected seq at %s\n",s);
100    exit(0);
101      }
102      get_token(s,t);
103      int start,end;
104      start=get_number(s);
105      end=get_number(s);
106      for (j=start; j<=end; j++)
107      {
108    sprintf(imname,"%s%04d.pcx",t,j);
109    seq[i++]=cache.reg(filename,imname,SPEC_CHARACTER,1);
110      }
111      get_token(s,t);      // right paren
112    }
113    else
114      seq[i++]=cache.reg(filename,t,SPEC_CHARACTER,1);
115  }
116}*/
117
118
119
120
121
Note: See TracBrowser for help on using the repository browser.