~and471/ubuntu/maverick/frozen-bubble/fix-599809

« back to all changes in this revision

Viewing changes to c_stuff/fb_c_stuff.xs

  • Committer: Bazaar Package Importer
  • Author(s): Josselin Mouette
  • Date: 2004-07-08 17:22:16 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040708172216-4e9erxuhsq7djmnd
Tags: 1.0.0-6
c_stuff/lib/FBLE.pm: fix to deal with new SDL_perl (closes: #257749).

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include "XSUB.h"
23
23
 
24
24
#include <SDL/SDL.h>
25
 
#include <../SDL_mixer_patched/SDL_mixer.h>
 
25
#include <SDL/SDL_mixer.h>
26
26
 
27
27
const int XRES = 640;
28
28
const int YRES = 480;
34
34
int ANIM_SPEED = 20;
35
35
Uint32 ticks;
36
36
Uint32 to_wait;
 
37
void myLockSurface(SDL_Surface * s)
 
38
{
 
39
        while (SDL_MUSTLOCK(s) == 1 && SDL_LockSurface(s) < 0)
 
40
                SDL_Delay(10);
 
41
}
 
42
void myUnlockSurface(SDL_Surface * s)
 
43
{
 
44
        if (SDL_MUSTLOCK(s))
 
45
                SDL_UnlockSurface(s);
 
46
}
37
47
void synchro_before(SDL_Surface * s)
38
48
{
39
49
        ticks = SDL_GetTicks(); 
40
 
        SDL_LockSurface(s);
 
50
        myLockSurface(s);
41
51
}
42
52
void synchro_after(SDL_Surface * s)
43
53
{
44
 
        SDL_UnlockSurface(s);
 
54
        myUnlockSurface(s);
45
55
        SDL_Flip(s);
46
56
        to_wait = SDL_GetTicks() - ticks;
47
57
        if (to_wait < ANIM_SPEED) {
49
59
        }
50
60
//      else { printf("slow (%d)", ANIM_SPEED - to_wait); }
51
61
}
52
 
 
 
62
void fb__out_of_memory(void)
 
63
{
 
64
        fprintf(stderr, "**ERROR** Out of memory\n");
 
65
        abort();
 
66
}
53
67
 
54
68
int rand_(double val) { return 1+(int) (val*rand()/(RAND_MAX+1.0)); }
55
69
 
196
210
        int sqr(int v) { return v*v; }
197
211
 
198
212
        circle_steps = malloc(XRES * YRES * sizeof(int));
 
213
        if (!circle_steps)
 
214
                fb__out_of_memory();
199
215
 
200
216
        for (y=0; y<YRES; y++)
201
217
                for (x=0; x<XRES; x++) {
236
252
        char mypath[] = "/data/plasma.raw";
237
253
        FILE * f;
238
254
        finalpath = malloc(strlen(datapath) + sizeof(mypath) + 1);
 
255
        if (!finalpath)
 
256
                fb__out_of_memory();
239
257
        sprintf(finalpath, "%s%s", datapath, mypath);
240
258
        f = fopen(finalpath, "rb");
241
259
        free(finalpath);
246
264
        }
247
265
 
248
266
        plasma = malloc(XRES * YRES);
 
267
        if (!plasma)
 
268
                fb__out_of_memory();
249
269
        if (fread(plasma, 1, XRES * YRES, f) != XRES * YRES) {
250
270
                fprintf(stderr, "Ouch, could not read %d bytes from plasma file\n", XRES * YRES);
251
271
                exit(1);
263
283
 
264
284
 
265
285
        plasma2 = malloc(XRES * YRES);
 
286
        if (!plasma2)
 
287
                fb__out_of_memory();
266
288
        for (i=0; i<XRES*YRES; i++)
267
289
                plasma2[i] = rand_(256) - 1;
268
290
 
330
352
        int rh = orig_rect->h / factor;
331
353
        xpos -= rx;
332
354
        ypos -= ry;
333
 
        SDL_LockSurface(dest);
 
355
        myLockSurface(orig);
 
356
        myLockSurface(dest);
334
357
        for (x=rx; x<rx+rw; x++) {
335
358
                for (y=ry; y<ry+rh; y++) {
336
359
                        if (!dest->format->palette) {
359
382
                        }
360
383
                }
361
384
        }
362
 
        SDL_UnlockSurface(dest);
 
385
        myUnlockSurface(orig);
 
386
        myUnlockSurface(dest);
363
387
}
364
388
 
365
389