| 1 |
/* Emacs style mode select -*- C -*- |
| 2 |
*----------------------------------------------------------------------------- |
| 3 |
* |
| 4 |
* |
| 5 |
* PrBoom: a Doom port merged with LxDoom and LSDLDoom |
| 6 |
* based on BOOM, a modified and improved DOOM engine |
| 7 |
* Copyright (C) 1999 by |
| 8 |
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman |
| 9 |
* Copyright (C) 1999-2001 by |
| 10 |
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze |
| 11 |
* Copyright 2005, 2006 by |
| 12 |
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko |
| 13 |
* |
| 14 |
* This program is free software; you can redistribute it and/or |
| 15 |
* modify it under the terms of the GNU General Public License |
| 16 |
* as published by the Free Software Foundation; either version 2 |
| 17 |
* of the License, or (at your option) any later version. |
| 18 |
* |
| 19 |
* This program is distributed in the hope that it will be useful, |
| 20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
* GNU General Public License for more details. |
| 23 |
* |
| 24 |
* You should have received a copy of the GNU General Public License |
| 25 |
* along with this program; if not, write to the Free Software |
| 26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 27 |
* 02111-1307, USA. |
| 28 |
* |
| 29 |
* DESCRIPTION: |
| 30 |
* Handles in-memory caching of WAD lumps |
| 31 |
* |
| 32 |
*----------------------------------------------------------------------------- |
| 33 |
*/ |
| 34 |
|
| 35 |
// use config.h if autoconf made one -- josh |
| 36 |
#ifdef HAVE_CONFIG_H |
| 37 |
#include "config.h" |
| 38 |
#endif |
| 39 |
|
| 40 |
#include "doomstat.h" |
| 41 |
#include "doomtype.h" |
| 42 |
|
| 43 |
#include "w_wad.h" |
| 44 |
#include "z_zone.h" |
| 45 |
#include "lprintf.h" |
| 46 |
|
| 47 |
static void **lump_data; |
| 48 |
|
| 49 |
/* W_InitCache |
| 50 |
* |
| 51 |
* cph 2001/07/07 - split from W_Init |
| 52 |
*/ |
| 53 |
void W_InitCache(void) |
| 54 |
{ |
| 55 |
// set up caching |
| 56 |
lump_data = calloc(sizeof *lump_data, numlumps); |
| 57 |
if (!lump_data) |
| 58 |
I_Error ("W_Init: Couldn't allocate lump data"); |
| 59 |
} |
| 60 |
|
| 61 |
void W_DoneCache(void) |
| 62 |
{ |
| 63 |
} |
| 64 |
|
| 65 |
/* W_LumpByNum |
| 66 |
* killough 4/25/98: simplified |
| 67 |
* CPhipps - modified for new lump locking scheme |
| 68 |
* returns a const* |
| 69 |
*/ |
| 70 |
|
| 71 |
const void *W_LumpByNum(int lump) |
| 72 |
{ |
| 73 |
#ifdef RANGECHECK |
| 74 |
if ((unsigned)lump >= (unsigned)numlumps) |
| 75 |
I_Error ("W_LumpByNum: %i >= numlumps",lump); |
| 76 |
#endif |
| 77 |
|
| 78 |
// read the lump in |
| 79 |
if (!lump_data[lump]) { |
| 80 |
lump_data[lump] = Z_Malloc(W_LumpLength(lump)); |
| 81 |
W_ReadLump(lump, lump_data[lump]); |
| 82 |
} |
| 83 |
|
| 84 |
return lump_data[lump]; |
| 85 |
} |
| 86 |
|
| 87 |
const void *W_LockLumpNum(int lump) |
| 88 |
{ |
| 89 |
return W_LumpByNum(lump); |
| 90 |
} |
| 91 |
|
| 92 |
void *W_GetModifiableLumpData(int lump) |
| 93 |
{ |
| 94 |
return lump_data[lump]; |
| 95 |
} |