4b825dc642cb6eb9a060e54bf8d69288fbee4904ebd360ec63ec976c05699f3180e866b3f69e5472
 
 
1
#include "system.h"
 
 
2
#include "stratdef.h"
 
 
3
#include "particle.h"
 
 
4
#include "sfx.h"
 
 
5
#include "corpse.h"
 
 
6
#include "lighting.h"
 
 
7
#include <stdio.h>
 
 
8
#include <assert.h>
 
 
9
 
 
 
10
static SFXBLOCK SfxBlockStorage[MAX_NO_OF_SFX_BLOCKS];
 
 
11
static int NumFreeSfxBlocks;
 
 
12
static SFXBLOCK *FreeSfxBlockList[MAX_NO_OF_SFX_BLOCKS];
 
 
13
static SFXBLOCK **FreeSfxBlockListPtr;
 
 
14
 
 
 
15
void InitialiseSfxBlocks()
 
 
16
{
 
 
17
    SFXBLOCK *freeBlockPtr = SfxBlockStorage;
 
 
18
    int blk = 0;
 
 
19
 
 
 
20
    for(; blk < MAX_NO_OF_SFX_BLOCKS; blk++) 
 
 
21
        FreeSfxBlockList[blk] = freeBlockPtr++;
 
 
22
 
 
 
23
    FreeSfxBlockListPtr = &FreeSfxBlockList[MAX_NO_OF_SFX_BLOCKS-1];
 
 
24
    NumFreeSfxBlocks = MAX_NO_OF_SFX_BLOCKS;
 
 
25
}
 
 
26
 
 
 
27
SFXBLOCK* AllocateSfxBlock()
 
 
28
{
 
 
29
    SFXBLOCK *sfxPtr;
 
 
30
 
 
 
31
    if (NumFreeSfxBlocks) 
 
 
32
    {
 
 
33
        sfxPtr = *FreeSfxBlockListPtr--;
 
 
34
        NumFreeSfxBlocks--;
 
 
35
    }
 
 
36
    else
 
 
37
    {
 
 
38
        /* unable to allocate a sfxamics block I'm afraid; MAX_NO_OF_SFX_BLOCKS is too low */
 
 
39
        printf("No Free SFX blocks!\n");
 
 
40
        sfxPtr = NULL;
 
 
41
    }
 
 
42
 
 
 
43
return sfxPtr;
 
 
44
}
 
 
45
 
 
 
46
void DeallocateSfxBlock(SFXBLOCK *sfxPtr)
 
 
47
{
 
 
48
    *(++FreeSfxBlockListPtr) = sfxPtr;
 
 
49
    NumFreeSfxBlocks++;
 
 
50
}
 
 
51
 
 
 
52
DISPLAYBLOCK *CreateSFXObject(enum SFX_ID sfxID)
 
 
53
{
 
 
54
    DISPLAYBLOCK *dispPtr = CreateActiveObject();
 
 
55
 
 
 
56
    if (dispPtr)
 
 
57
    {
 
 
58
        SFXBLOCK *sfxPtr = AllocateSfxBlock();
 
 
59
 
 
 
60
        if (sfxPtr)
 
 
61
        {
 
 
62
            dispPtr->SfxPtr = sfxPtr;
 
 
63
            sfxPtr->SfxID = sfxID;
 
 
64
        }
 
 
65
        else
 
 
66
        {
 
 
67
            /* damn, we've got a DISPLAYBLOCK, but were unable to get a SFXBLOCK;
 
 
68
               this means we must dealloc the DISPLAYBLOCK and return NULL to indicate 
 
 
69
               failure.
 
 
70
            */
 
 
71
            DestroyActiveObject(&dispPtr);
 
 
72
        }
 
 
73
    }
 
 
74
 
 
 
75
return dispPtr;
 
 
76
}