source: abuse/trunk/src/smoosh.cpp @ 129

Last change on this file since 129 was 129, checked in by Sam Hocevar, 12 years ago
  • Get rid of jmalloc and replace it with standard malloc. Modern operating systems certainly perform a lot better than this custom implementation, and we have superior tools (eg. valgrind) to debug and profile memory usage without interfering with the code itself.
File size: 1.5 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *
5 *  This software was released into the Public Domain. As with most public
6 *  domain software, no warranty is made or implied by Crack dot Com or
7 *  Jonathan Clark.
8 */
9
10#include "config.h"
11
12#define PARTICLE_SIZE 2            // 2x2 block of pixels
13
14class particle
15{
16public :
17  unsigned char *pict;
18  int x,y;
19  particle *left,*right,*up,*down;
20  particle(int X, int Y, int size);
21  ~particle() { free(pict); }
22} ;
23
24particle::particle(int X, int Y, image *im, int size);
25{
26  x=X; y=Y;
27  left=right=up=down=NULL;
28  pict=(unsigned char *)malloc(size*size);
29}
30
31class particle_image
32{
33  int particles;
34  particle *top;
35  int size;
36public :
37  particle_image(image *im, int particle_size);       // im will be erased!
38} ;
39
40
41particle_image::particle_image(image *im, int particle_size)
42{
43  int x,y,py,p;
44  unsigned char *sl,*sl2;
45  top=NULL;
46  size=particle_size;
47
48  int matw=(im->width()+size-1)/size,math=(im->height()+size-1)/size;
49  particle *matrix[matw*math];
50
51
52  // break the image up into particles and store in a big matrix
53  for (y=0;y<im->height();y++)
54  {
55    sl=im->scan_line(y);
56    py=y/size;
57    for (x=0;x<im->width();x++,sl+=px)
58    {
59      px=x/size;
60      sl2=matrix[py*matw+px]->pict+(y%size)*size;      // address of particle image memory
61
62      int copy_size;
63
64      memset(sl2,0,size);
65
66      if (*sl)
67      {
68    px=x/size;
69    py=y/size;
70      }
71
72  }
73  if (px<0)       // couldn't find any non-blank pixels
74    particles=0;
75  else
76    add_particle_line(px,py,im);
77}
Note: See TracBrowser for help on using the repository browser.