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