Exemple #1
0
//
// TextureManager::cacheRawTexture
//
// Converts a linear 320x200 block of pixels into a Texture 
//
void TextureManager::cacheRawTexture(texhandle_t handle)
{
	const int width = 320;
	const int height = 200;

	Texture* texture = createTexture(handle, width, height);

	if (clientside)
	{
		unsigned int lumpnum = (handle & ~RAW_HANDLE_MASK);
		unsigned int lumplen = W_LumpLength(lumpnum);

		byte *lumpdata = new byte[lumplen];
		W_ReadLump(lumpnum, lumpdata);

		// convert the row-major flat lump to into column-major
		byte* dest = texture->mData;

		for (int x = 0; x < width; x++)
		{
			const byte* source = lumpdata + x;
			
			for (int y = 0; y < height; y++)
			{
				*dest = *source;
				source += width;
				dest++;
			}
		}
		
		delete [] lumpdata;
	}
}
Exemple #2
0
void P_LoadVertexes (int lump)
{
#ifdef MARS
	numvertexes = W_LumpLength (lump) / sizeof(vertex_t);
	vertexes = (vertex_t *)(wadfileptr+BIGLONG(lumpinfo[lump].filepos));
#else
	byte		*data;
	int			i;
	mapvertex_t	*ml;
	vertex_t	*li;
	
	numvertexes = W_LumpLength (lump) / sizeof(mapvertex_t);
	vertexes = Z_Malloc (numvertexes*sizeof(vertex_t),PU_LEVEL,0);	
	data = I_TempBuffer ();	
	W_ReadLump (lump,data);
	
	
	ml = (mapvertex_t *)data;
	li = vertexes;
	for (i=0 ; i<numvertexes ; i++, li++, ml++)
	{
		li->x = LITTLESHORT(ml->x)<<FRACBITS;
		li->y = LITTLESHORT(ml->y)<<FRACBITS;
	}
#endif
}
Exemple #3
0
void   *W_CacheLumpNum(int lump, int tag)
{
	byte   *ptr;

	if((unsigned) lump >= (unsigned) numlumps)
	{
		Con_Error("W_CacheLumpNum: %i >= numlumps", lump);
	}
	// Return the name instead of data?
	if(tag == PU_GETNAME)
	{
		strncpy(retname, lumpinfo[lump].name, 8);
		retname[8] = 0;
		return retname;
	}
	if(!lumpcache[lump])
	{							// Need to read the lump in
		ptr = Z_Malloc(W_LumpLength(lump), tag, &lumpcache[lump]);
		W_ReadLump(lump, lumpcache[lump]);
	}
	else
	{
		Z_ChangeTag(lumpcache[lump], tag);
	}
	return lumpcache[lump];
}
static char *GetFinaleText(int sequence)
{
	char *msgLumpName;
	int msgSize;
	int msgLump;
	static char *winMsgLumpNames[] =
	{
		"win1msg",
		"win2msg",
		"win3msg"
	};

	msgLumpName = winMsgLumpNames[sequence];
	msgLump = W_CheckNumForName(msgLumpName);
	if (msgLump<0) {
	 strcpy(ClusterMessage,"CONGRADULATIONS!");
	 return ClusterMessage;
	}
	msgSize = W_LumpLength(msgLump);
	if(msgSize >= MAX_INTRMSN_MESSAGE_SIZE)
	{
		I_Error("Finale message too long (%s)", msgLumpName);
	}
	W_ReadLump(msgLump, ClusterMessage);
	ClusterMessage[msgSize] = 0; // Append terminator
	return ClusterMessage;
}
Exemple #5
0
//
// W_CacheLumpNum
//
// Load a lump into memory and return a pointer to a buffer containing
// the lump data.
//
// 'tag' is the type of zone memory buffer to allocate for the lump
// (usually PU_STATIC or PU_CACHE). If the lump is loaded as
// PU_STATIC, it should be released back using W_ReleaseLumpNum
// when no longer needed (do not use Z_ChangeTag).
//
void *W_CacheLumpNum(lumpindex_t lumpnum, int tag)
{
    byte        *result;
    lumpinfo_t  *lump;

    if (lumpnum >= numlumps)
        I_Error("W_CacheLumpNum: %i >= numlumps", lumpnum);

    lump = lumpinfo[lumpnum];

    // Get the pointer to return. If the lump is in a memory-mapped
    // file, we can just return a pointer to within the memory-mapped
    // region. If the lump is in an ordinary file, we may already
    // have it cached; otherwise, load it into memory.
    if (lump->wad_file->mapped)
    {
        // Memory mapped file, return from the mmapped region.
        result = lump->wad_file->mapped + lump->position;
    }
    else if (lump->cache)
    {
        // Already cached, so just switch the zone tag.
        result = (byte *)lump->cache;
        Z_ChangeTag(lump->cache, tag);
    }
    else
    {
        // Not yet loaded, so load it now
        lump->cache = Z_Malloc(W_LumpLength(lumpnum), tag, &lump->cache);
        W_ReadLump(lumpnum, lump->cache);
        result = (byte *)lump->cache;
    }

    return result;
}
Exemple #6
0
//
// W_CacheLumpNum
//
void*
W_CacheLumpNum
( int		lump,
  int		tag )
{
    byte*	ptr;

    if ((unsigned)lump >= numlumps)
	I_Error ("W_CacheLumpNum: %i >= numlumps",lump);
		
    if (!lumpcache[lump])
    {
	// read the lump in
	
	//printf ("cache miss on lump %i\n",lump);
	ptr = Z_Malloc (W_LumpLength (lump), tag, &lumpcache[lump]);
	W_ReadLump (lump, lumpcache[lump]);
    }
    else
    {
	//printf ("cache hit on lump %i\n",lump);
	Z_ChangeTag (lumpcache[lump],tag);
    }
	
    return lumpcache[lump];
}
Exemple #7
0
//
// TextureManger::cachePatch
//
void TextureManager::cachePatch(texhandle_t handle)
{
	unsigned int lumpnum = handle & ~(PATCH_HANDLE_MASK | SPRITE_HANDLE_MASK);

	unsigned int lumplen = W_LumpLength(lumpnum);
	byte* lumpdata = new byte[lumplen];
	W_ReadLump(lumpnum, lumpdata);

	int width = LESHORT(*(short*)(lumpdata + 0));
	int height = LESHORT(*(short*)(lumpdata + 2));
	int offsetx = LESHORT(*(short*)(lumpdata + 4));
	int offsety = LESHORT(*(short*)(lumpdata + 6));

	Texture* texture = createTexture(handle, width, height);
	texture->mOffsetX = offsetx;
	texture->mOffsetY = offsety;

	if (clientside)
	{
		// TODO: remove this once proper masking is in place
		memset(texture->mData, 0, width * height);

		// initialize the mask to entirely transparent 
		memset(texture->mMask, 0, width * height);

		R_DrawPatchIntoTexture(texture, lumpdata, 0, 0);
		texture->mHasMask = (memchr(texture->mMask, 0, width * height) != NULL);
	}

	delete [] lumpdata;

}
Exemple #8
0
void P_LoadBlockMap(int lump)
{
    int i, count;
    int lumplen;

    lumplen = W_LumpLength(lump);

    blockmaplump = Z_Malloc(lumplen, PU_LEVEL, NULL);
    W_ReadLump(lump, blockmaplump);
    blockmap = blockmaplump + 4;

    // Swap all short integers to native byte ordering:

    count = lumplen / 2;

    for (i = 0; i < count; i++)
        blockmaplump[i] = SHORT(blockmaplump[i]);

    bmaporgx = blockmaplump[0] << FRACBITS;
    bmaporgy = blockmaplump[1] << FRACBITS;
    bmapwidth = blockmaplump[2];
    bmapheight = blockmaplump[3];

    // clear out mobj chains

    count = sizeof(*blocklinks) * bmapwidth * bmapheight;
    blocklinks = Z_Malloc(count, PU_LEVEL, 0);
    memset(blocklinks, 0, count);
}
Exemple #9
0
void P_LoadSideDefs(int lump)
{
    byte *data;
    int   i;
    mapsidedef_t *msd;
    side_t       *sd;

    for(i = 0; i < numtextures; i++)
        textures[i].usecount = 0;

    numsides = W_LumpLength(lump) / sizeof(mapsidedef_t);
    sides    = Z_Malloc(numsides * sizeof(side_t), PU_LEVEL, 0);
    D_memset(sides, 0, numsides * sizeof(side_t));
    data     = I_TempBuffer();
    W_ReadLump(lump, data);

    msd = (mapsidedef_t *)data;
    sd  = sides;
    for(i = 0; i < numsides; i++, msd++, sd++)
    {
        sd->textureoffset = LITTLESHORT(msd->textureoffset) << FRACBITS;
        sd->rowoffset     = LITTLESHORT(msd->rowoffset) << FRACBITS;
        sd->toptexture    = R_TextureNumForName(msd->toptexture);
        sd->bottomtexture = R_TextureNumForName(msd->bottomtexture);
        sd->midtexture    = R_TextureNumForName(msd->midtexture);
        sd->sector        = &sectors[LITTLESHORT(msd->sector)];

        textures[sd->toptexture].usecount++;
        textures[sd->bottomtexture].usecount++;
        textures[sd->midtexture].usecount++;
    }
}
Exemple #10
0
void P_LoadNodes(int lump)
{
    byte *data;
    int   i, j, k;
    mapnode_t *mn;
    node_t    *no;

    numnodes = W_LumpLength(lump) / sizeof(mapnode_t);
    nodes    = Z_Malloc(numnodes * sizeof(node_t), PU_LEVEL, 0);
    data     = I_TempBuffer();
    W_ReadLump(lump, data);

    mn = (mapnode_t *)data;
    no = nodes;
    for(i = 0; i < numnodes; i++, no++, mn++)
    {
        no->x  = LITTLESHORT(mn->x ) << FRACBITS;
        no->y  = LITTLESHORT(mn->y ) << FRACBITS;
        no->dx = LITTLESHORT(mn->dx) << FRACBITS;
        no->dy = LITTLESHORT(mn->dy) << FRACBITS;

        for(j = 0; j < 2; j++)
        {
            no->children[j] = (unsigned short)LITTLESHORT(mn->children[j]);
            for(k = 0; k < 4; k++)
                no->bbox[j][k] = LITTLESHORT(mn->bbox[j][k]) << FRACBITS;
        }
    }
}
Exemple #11
0
void P_LoadSectors(int lump)
{
    byte *data;
    int   i;
    mapsector_t *ms;
    sector_t    *ss;

    numsectors = W_LumpLength(lump) / sizeof(mapsector_t);
    sectors    = Z_Malloc(numsectors * sizeof(sector_t), PU_LEVEL, 0);
    D_memset(sectors, 0, numsectors * sizeof(sector_t));
    data = I_TempBuffer();
    W_ReadLump(lump, data);

    ms = (mapsector_t *)data;
    ss = sectors;
    for(i = 0; i < numsectors; i++, ss++, ms++)
    {
        ss->floorheight   = LITTLESHORT(ms->floorheight) << FRACBITS;
        ss->ceilingheight = LITTLESHORT(ms->ceilingheight) << FRACBITS;
        ss->floorpic      = R_FlatNumForName(ms->floorpic);

        if(!D_strncasecmp(ms->ceilingpic,"F_SKY1", 6))
            ss->ceilingpic = -1;
        else
        {
            ss->ceilingpic = R_FlatNumForName(ms->ceilingpic);
        }

        ss->lightlevel = LITTLESHORT(ms->lightlevel);
        ss->special    = LITTLESHORT(ms->special);
        ss->tag        = LITTLESHORT(ms->tag);
        ss->thinglist  = NULL;
    }
}
Exemple #12
0
const void *W_CacheLumpNum(int lump)
{
  const int locks = 1;
#ifdef RANGECHECK
  if ((unsigned)lump >= (unsigned)numlumps)
    I_Error ("W_CacheLumpNum: %i >= numlumps",lump);
#endif

  if (!cachelump[lump].cache)      // read the lump in
    W_ReadLump(lump, Z_Malloc(W_LumpLength(lump), PU_CACHE, &cachelump[lump].cache));

  /* cph - if wasn't locked but now is, tell z_zone to hold it */
  if (!cachelump[lump].locks && locks) {
    Z_ChangeTag(cachelump[lump].cache,PU_STATIC);
#ifdef TIMEDIAG
    cachelump[lump].locktic = gametic;
#endif
  }
  cachelump[lump].locks += locks;

#ifdef SIMPLECHECKS
  if (!((cachelump[lump].locks+1) & 0xf))
    lprintf(LO_DEBUG, "W_CacheLumpNum: High lock on %8s (%d)\n",
	    lumpinfo[lump].name, cachelump[lump].locks);
#endif

  return cachelump[lump].cache;
}
Exemple #13
0
//
// TextureManager::readPNamesDirectory
//
void TextureManager::readPNamesDirectory()
{
	int lumpnum = W_GetNumForName("PNAMES");
	size_t lumplen = W_LumpLength(lumpnum);

	byte* lumpdata = new byte[lumplen];
	W_ReadLump(lumpnum, lumpdata);

	int num_pname_mappings = LELONG(*((int*)(lumpdata + 0)));
	mPNameLookup = new int[num_pname_mappings];

	for (int i = 0; i < num_pname_mappings; i++)
	{
		const char* lumpname = (const char*)(lumpdata + 4 + 8 * i);
		mPNameLookup[i] = W_CheckNumForName(lumpname);

		// killough 4/17/98:
		// Some wads use sprites as wall patches, so repeat check and
		// look for sprites this time, but only if there were no wall
		// patches found. This is the same as allowing for both, except
		// that wall patches always win over sprites, even when they
		// appear first in a wad. This is a kludgy solution to the wad
		// lump namespace problem.

		if (mPNameLookup[i] == -1)
			mPNameLookup[i] = W_CheckNumForName(lumpname, ns_sprites);
	}

	delete [] lumpdata;
}
Exemple #14
0
//
// R_InitColormaps
//
void R_InitColormaps (int lump)
{
  int length;

  if (lump == 0)
  {
    lump = W_GetNumForName("COLORMAP");
    firstcollump = W_CheckNumForName ("C_START");
    lastcollump = W_CheckNumForName ("C_END");
  }

  if ((lump != prevcollump) || (colourmap_size == 0))
  {
    prevcollump = lump;

    length = W_LumpLength (lump) + 255;
    if (length > colourmap_size)
    {
      colourmap_size = length + 0x200;

      if (colourmaps_a)
	Z_Free (colourmaps_a);

      // Load in the light tables,
      colourmaps_a = Z_Malloc (colourmap_size, PU_STATIC, 0);
      // 256 byte align tables.
      colormaps = (byte *)( ((uintptr_t)colourmaps_a + 255)&~0xff);
    }
    W_ReadLump (lump,colormaps);
  }
}
Exemple #15
0
//
// TextureManager::readAnimatedLump
//
// Reads animation definitions from the ANIMATED lump.
//
// Load the table of animation definitions, checking for existence of
// the start and end of each frame. If the start doesn't exist the sequence
// is skipped, if the last doesn't exist, BOOM exits.
//
// Wall/Flat animation sequences, defined by name of first and last frame,
// The full animation sequence is given using all lumps between the start
// and end entry, in the order found in the WAD file.
//
// This routine modified to read its data from a predefined lump or
// PWAD lump called ANIMATED rather than a static table in this module to
// allow wad designers to insert or modify animation sequences.
//
// Lump format is an array of byte packed animdef_t structures, terminated
// by a structure with istexture == -1. The lump can be generated from a
// text source file using SWANTBLS.EXE, distributed with the BOOM utils.
// The standard list of switches and animations is contained in the example
// source text file DEFSWANI.DAT also in the BOOM util distribution.
//
// [RH] Rewritten to support BOOM ANIMATED lump but also make absolutely
// no assumptions about how the compiler packs the animdefs array.
//
void TextureManager::readAnimatedLump()
{
	int lumpnum = W_CheckNumForName("ANIMATED");
	if (lumpnum == -1)
		return;

	size_t lumplen = W_LumpLength(lumpnum);
	if (lumplen == 0)
		return;

	byte* lumpdata = new byte[lumplen];
	W_ReadLump(lumpnum, lumpdata);

	for (byte* ptr = lumpdata; *ptr != 255; ptr += 23)
	{
		anim_t anim;

		Texture::TextureSourceType texture_type = *(ptr + 0) == 1 ?
					Texture::TEX_WALLTEXTURE : Texture::TEX_FLAT;

		const char* startname = (const char*)(ptr + 10);
		const char* endname = (const char*)(ptr + 1);

		texhandle_t start_texhandle =
				texturemanager.getHandle(startname, texture_type);
		texhandle_t end_texhandle =
				texturemanager.getHandle(endname, texture_type);

		if (start_texhandle == TextureManager::NOT_FOUND_TEXTURE_HANDLE ||
			start_texhandle == TextureManager::NO_TEXTURE_HANDLE ||
			end_texhandle == TextureManager::NOT_FOUND_TEXTURE_HANDLE ||
			end_texhandle == TextureManager::NO_TEXTURE_HANDLE)
			continue;

		anim.basepic = start_texhandle;
		anim.numframes = end_texhandle - start_texhandle + 1;

		if (anim.numframes <= 0)
			continue;
		anim.curframe = 0;
			
		int speed = LELONG(*(int*)(ptr + 19));
		anim.countdown = speed - 1;

		for (int i = 0; i < anim.numframes; i++)
		{
			anim.framepic[i] = anim.basepic + i;
			anim.speedmin[i] = anim.speedmax[i] = speed;
		}

		mAnimDefs.push_back(anim);
	}

	delete [] lumpdata;
}
Exemple #16
0
byte *ST_LoadScreen(void)
{
    int length, lump;
    byte *buffer;

    lump = W_GetNumForName("STARTUP");
    length = W_LumpLength(lump);
    buffer = (byte *) Z_Malloc(length, PU_STATIC, NULL);
    W_ReadLump(lump, buffer);
    return (buffer);
}
Exemple #17
0
int W_MergeDump (const char *file)
{
    FILE *fp = NULL;
    char *lump_p = NULL;
    uint32_t i, dir_p;

    // WAD directory structure
    typedef struct {
	uint32_t pos;
	uint32_t size;
	char name[8];
    } directory_t;
    directory_t *dir = NULL;

    // open file for writing
    if (!(fp = fopen(file, "wb")))
	I_Error("Failed writing to file %s!", file);

    // prepare directory
    if (!(dir = malloc(numlumps * sizeof(*dir))))
	I_Error("Failed allocating memory!");
    memset(dir, 0, numlumps * sizeof(*dir));

    // write lumps to file, starting at offset 12
    fseek(fp, 12, SEEK_SET);
    for (i = 0; i < numlumps; i++)
    {
	dir[i].pos = ftell(fp);
	dir[i].size = lumpinfo[i]->size;
	memcpy(dir[i].name, lumpinfo[i]->name, 8);

	// avoid flooding Doom's Zone Memory
	lump_p = realloc(lump_p, lumpinfo[i]->size);
	W_ReadLump(i, lump_p);
	fwrite(lump_p, 1, lumpinfo[i]->size, fp);
    }
    free(lump_p);

    // write directory
    dir_p = ftell(fp);
    fwrite(dir, sizeof(*dir), numlumps, fp);
    free(dir);

    // write WAD header
    fseek(fp, 0, SEEK_SET);
    fwrite("IWAD", 1, 4, fp);
    fwrite(&i, 4, 1, fp);
    fwrite(&dir_p, 4, 1, fp);

    fclose(fp);

    return (i);
}
Exemple #18
0
//
// R_InitColormaps
//
void R_InitColormaps (void)
{
    int	lump, length;
    
    // Load in the light tables, 
    //  256 byte align tables.
    lump = W_GetNumForName("COLORMAP"); 
    length = W_LumpLength (lump) + 255; 
    colormaps = Z_Malloc (length, PU_STATIC, 0); 
    colormaps = (byte *)( ((int)colormaps + 255)&~0xff); 
    W_ReadLump (lump,colormaps); 
}
Exemple #19
0
//
// W_CachePatch
//
// [SL] Reads and caches a patch from disk. This takes care of converting the
// patch from the standard Doom format of posts with 1-byte lengths and offsets
// to a new format for posts that uses 2-byte lengths and offsets.
//
patch_t* W_CachePatch(unsigned lumpnum, int tag)
{
	if (lumpnum >= numlumps)
		I_Error ("W_CachePatch: %u >= numlumps", lumpnum);

	if (!lumpcache[lumpnum])
	{
		// temporary storage of the raw patch in the old format
		byte *rawlumpdata = new byte[W_LumpLength(lumpnum)];

		W_ReadLump(lumpnum, rawlumpdata);
		patch_t *rawpatch = (patch_t*)(rawlumpdata);

		size_t newlumplen = R_CalculateNewPatchSize(rawpatch, W_LumpLength(lumpnum));

		if (newlumplen > 0)
		{
			// valid patch
			byte *ptr = (byte *)Z_Malloc(newlumplen + 1, tag, &lumpcache[lumpnum]);
			patch_t *newpatch = (patch_t*)lumpcache[lumpnum];

			R_ConvertPatch(newpatch, rawpatch);
			ptr[newlumplen] = 0;
		}
		else
		{
			// invalid patch - just create a header with width = 0, height = 0
			Z_Malloc(sizeof(patch_t) + 1, tag, &lumpcache[lumpnum]);
			memset(lumpcache[lumpnum], 0, sizeof(patch_t) + 1);
		}

		delete [] rawlumpdata;
	}
	else
	{
		Z_ChangeTag(lumpcache[lumpnum], tag);
	}

	// denis - todo - would be good to check whether the patch violates W_LumpLength here
	// denis - todo - would be good to check for width/height == 0 here, and maybe replace those with a valid patch

	return (patch_t*)lumpcache[lumpnum];
}
Exemple #20
0
//
// TextureManager::cacheFlat
//
// Loads a flat with the specified handle from the WAD file and composes
// a Texture object.
//
void TextureManager::cacheFlat(texhandle_t handle)
{
	// should we check that the handle is valid for a flat?

	unsigned int lumpnum = (handle & ~FLAT_HANDLE_MASK) + mFirstFlatLumpNum;
	unsigned int lumplen = W_LumpLength(lumpnum);

	int width, height;	

	if (lumplen == 64 * 64)
		width = height = 64;
	else if (lumplen == 128 * 128)
		width = height = 128;
	else if (lumplen == 256 * 256)
		width = height = 256;
	else
		width = height = Log2(sqrt(lumplen));	// probably not pretty... 

	Texture* texture = createTexture(handle, width, height);

	if (clientside)
	{
		byte *lumpdata = new byte[lumplen];
		W_ReadLump(lumpnum, lumpdata);

		// convert the row-major flat lump to into column-major
		byte* dest = texture->mData;

		for (int x = 0; x < width; x++)
		{
			const byte* source = lumpdata + x;
			
			for (int y = 0; y < height; y++)
			{
				*dest = *source;
				source += width;
				dest++;
			}
		}
		
		delete [] lumpdata;
	}
}
Exemple #21
0
//
// TextureManager::cacheWallTexture
//
// Composes a wall texture from a set of patches loaded from the WAD file.
//
void TextureManager::cacheWallTexture(texhandle_t handle)
{
	// should we check that the handle is valid for a wall texture?

	texdef_t* texdef = mTextureDefinitions[handle & ~WALLTEXTURE_HANDLE_MASK];

	int width = texdef->width;
	int height = texdef->height;

	Texture* texture = createTexture(handle, width, height);
	if (texdef->scalex)
		texture->mScaleX = texdef->scalex << (FRACBITS - 3);
	if (texdef->scaley)
		texture->mScaleY = texdef->scaley << (FRACBITS - 3);

	if (clientside)
	{
		// TODO: remove this once proper masking is in place
		memset(texture->mData, 0, width * height);

		// initialize the mask to entirely transparent 
		memset(texture->mMask, 0, width * height);

		// compose the texture out of a set of patches
		for (int i = 0; i < texdef->patchcount; i++)
		{
			texdefpatch_t* texdefpatch = &texdef->patches[i];
			
			if (texdefpatch->patch == -1)		// not found ?
				continue;

			unsigned int lumplen = W_LumpLength(texdefpatch->patch);
			byte* lumpdata = new byte[lumplen];
			W_ReadLump(texdefpatch->patch, lumpdata);
			R_DrawPatchIntoTexture(texture, lumpdata, texdefpatch->originx, texdefpatch->originy);

			delete [] lumpdata;
		}

		texture->mHasMask = (memchr(texture->mMask, 0, width * height) != NULL);
	}
}
Exemple #22
0
void P_LoadVertexes(int lump)
{
    byte        *data;
    int          i;
    mapvertex_t *ml;
    vertex_t    *li;

    numvertexes = W_LumpLength(lump) / sizeof(mapvertex_t);
    vertexes    = Z_Malloc(numvertexes * sizeof(vertex_t), PU_LEVEL, 0);
    data = I_TempBuffer();
    W_ReadLump(lump, data);

    ml = (mapvertex_t *)data;
    li = vertexes;
    for(i = 0; i < numvertexes; i++, li++, ml++)
    {
        li->x = LITTLESHORT(ml->x) << FRACBITS;
        li->y = LITTLESHORT(ml->y) << FRACBITS;
    }
}
Exemple #23
0
//
// W_CacheLumpNum
//
void*
W_CacheLumpNum
( int		lump,
  int		tag )
{
#ifdef RANGECHECK
	if (lump >= numlumps)
	I_Error ("W_CacheLumpNum: %i >= numlumps",lump);
#endif

	if (!lumpcache[lump])
	{
		byte*	ptr;
		// read the lump in
		//I_Printf ("cache miss on lump %i\n",lump);
		ptr = (byte*)DoomLib::Z_Malloc(W_LumpLength (lump), tag, &lumpcache[lump]);
		W_ReadLump (lump, lumpcache[lump]);
	}

	return lumpcache[lump];
}
Exemple #24
0
void P_LoadSubsectors(int lump)
{
    byte *data;
    int   i;
    mapsubsector_t *ms;
    subsector_t    *ss;

    numsubsectors = W_LumpLength(lump) / sizeof(mapsubsector_t);
    subsectors    = Z_Malloc(numsubsectors * sizeof(subsector_t), PU_LEVEL, 0);
    data = I_TempBuffer();
    W_ReadLump(lump, data);

    ms = (mapsubsector_t *)data;
    D_memset (subsectors,0, numsubsectors * sizeof(subsector_t));
    ss = subsectors;
    for(i = 0; i < numsubsectors; i++, ss++, ms++)
    {
        ss->numlines  = LITTLESHORT(ms->numsegs);
        ss->firstline = LITTLESHORT(ms->firstseg);
    }
}
Exemple #25
0
#endif //rww end
void R_InitColormaps (void)
{
	int	lump, length;
//
// load in the light tables
// 256 byte align tables
//
	lump = W_GetNumForName("COLORMAP");
	length = W_LumpLength (lump) + 255;
#if 0//def _HEXENDS //rww begin - put colormaps at the end of dtcm
	if ((((int)&__dtcm_end)+4+0x1200+length) > 0x8040000) {
		I_Error("DTCM region would overflow from colormap allocation!\n");
	}
	colormaps = (byte *)((&__dtcm_end)+4);
	colormaps = (byte *)( ((int)colormaps + 255)&~0xff);
#else //rww end
	colormaps = Z_Malloc (length, PU_STATIC, 0);
	colormaps = (byte *)( ((int)colormaps + 255)&~0xff);
#endif
	W_ReadLump (lump,colormaps);
Exemple #26
0
void P_LoadSegs(int lump)
{
    byte     *data;
    int       i;
    mapseg_t *ml;
    seg_t    *li;
    line_t   *ldef;
    int       linedef, side;

    numsegs = W_LumpLength(lump) / sizeof(mapseg_t);
    segs    = Z_Malloc(numsegs * sizeof(seg_t), PU_LEVEL, 0);
    D_memset(segs, 0, numsegs * sizeof(seg_t));
    data = I_TempBuffer();
    W_ReadLump(lump, data);

    ml = (mapseg_t *)data;
    li = segs;
    for(i = 0; i < numsegs; i++, li++, ml++)
    {
        li->v1 = &vertexes[LITTLESHORT(ml->v1)];
        li->v2 = &vertexes[LITTLESHORT(ml->v2)];

        li->angle = (LITTLESHORT(ml->angle)) << 16;
        li->offset = (LITTLESHORT(ml->offset)) << 16;
        linedef = LITTLESHORT(ml->linedef);
        ldef = &lines[linedef];
        li->linedef = ldef;
        side = LITTLESHORT(ml->side);
        li->sidedef = &sides[ldef->sidenum[side]];
        li->frontsector = sides[ldef->sidenum[side]].sector;

        if(ldef-> flags & ML_TWOSIDED)
            li->backsector = sides[ldef->sidenum[side ^ 1]].sector;
        else
            li->backsector = 0;

        if(ldef->v1 == li->v1)
            ldef->fineangle = li->angle >> ANGLETOFINESHIFT;
    }
}
Exemple #27
0
void P_LoadThings(int lump)
{
    byte *data;
    int   i;
    mapthing_t *mt;
    int numthings;

    data = I_TempBuffer();
    W_ReadLump(lump, data);
    numthings = W_LumpLength(lump) / sizeof(mapthing_t);

    mt = (mapthing_t *)data;
    for(i = 0; i < numthings; i++, mt++)
    {
        mt->x       = LITTLESHORT(mt->x);
        mt->y       = LITTLESHORT(mt->y);
        mt->angle   = LITTLESHORT(mt->angle);
        mt->type    = LITTLESHORT(mt->type);
        mt->options = LITTLESHORT(mt->options);
        P_SpawnMapThing(mt);
    }
}
Exemple #28
0
static char *ReadDMXConfig(void)
{
    int lumpnum;
    unsigned int len;
    char *data;

    // TODO: This should be chosen based on gamemode == commercial:

    lumpnum = W_CheckNumForName("DMXGUS");

    if (lumpnum < 0)
    {
        lumpnum = W_GetNumForName("DMXGUSC");
    }

    len = W_LumpLength(lumpnum);
    data = Z_Malloc(len + 1, PU_STATIC, NULL);
    W_ReadLump(lumpnum, data);

    data[len] = '\0';
    return data;
}
Exemple #29
0
void P_SetupLevel(int episode, int map, int playermask, skill_t skill)
{
    int i;
    int parm;
    char lumpname[9];
    int lumpnum;
    mobj_t *mobj;

    for (i = 0; i < MAXPLAYERS; i++)
    {
        players[i].killcount = players[i].secretcount
            = players[i].itemcount = 0;
    }
    players[consoleplayer].viewz = 1;   // will be set by player think

    // Waiting-for-level-load song; not played if playing music from CD
    // (the seek time will be so long it will just make loading take
    // longer)
    if (!cdmusic)
    {
        S_StartSongName("chess", true);
    }

    Z_FreeTags(PU_LEVEL, PU_PURGELEVEL - 1);

    P_InitThinkers();
    leveltime = 0;

    sprintf(lumpname, "MAP%02d", map);
    lumpnum = W_GetNumForName(lumpname);
    //
    // Begin processing map lumps
    // Note: most of this ordering is important
    //
    P_LoadBlockMap(lumpnum + ML_BLOCKMAP);
    P_LoadVertexes(lumpnum + ML_VERTEXES);
    P_LoadSectors(lumpnum + ML_SECTORS);
    P_LoadSideDefs(lumpnum + ML_SIDEDEFS);
    P_LoadLineDefs(lumpnum + ML_LINEDEFS);
    P_LoadSubsectors(lumpnum + ML_SSECTORS);
    P_LoadNodes(lumpnum + ML_NODES);
    P_LoadSegs(lumpnum + ML_SEGS);
    rejectmatrix = W_CacheLumpNum(lumpnum + ML_REJECT, PU_LEVEL);
    P_GroupLines();
    bodyqueslot = 0;
    po_NumPolyobjs = 0;
    deathmatch_p = deathmatchstarts;
    P_LoadThings(lumpnum + ML_THINGS);
    PO_Init(lumpnum + ML_THINGS);       // Initialize the polyobjs
    P_LoadACScripts(lumpnum + ML_BEHAVIOR);     // ACS object code
    //
    // End of map lump processing
    //

    // If deathmatch, randomly spawn the active players
    TimerGame = 0;
    if (deathmatch)
    {
        for (i = 0; i < MAXPLAYERS; i++)
        {
            if (playeringame[i])
            {                   // must give a player spot before deathmatchspawn
                mobj = P_SpawnMobj(playerstarts[0][i].x << 16,
                                   playerstarts[0][i].y << 16, 0,
                                   MT_PLAYER_FIGHTER);
                players[i].mo = mobj;
                G_DeathMatchSpawnPlayer(i);
                P_RemoveMobj(mobj);
            }
        }

        //!
        // @arg <n>
        // @category net
        // @vanilla
        //
        // For multiplayer games: exit each level after n minutes.
        //

        parm = M_CheckParmWithArgs("-timer", 1);
        if (parm)
        {
            TimerGame = atoi(myargv[parm + 1]) * 35 * 60;
        }
    }

// set up world state
    P_SpawnSpecials();

// build subsector connect matrix
//      P_ConnectSubsectors ();

// Load colormap and set the fullbright flag
    i = P_GetMapFadeTable(gamemap);
    W_ReadLump(i, colormaps);
    if (i == W_GetNumForName("COLORMAP"))
    {
        LevelUseFullBright = true;
    }
    else
    {                           // Probably fog ... don't use fullbright sprites
        LevelUseFullBright = false;
    }

// preload graphics
    if (precache)
        R_PrecacheLevel();

    // Check if the level is a lightning level
    P_InitLightning();

    S_StopAllSound();
    SN_StopAllSequences();
    S_StartSong(gamemap, true);

//printf ("free memory: 0x%x\n", Z_FreeMemory());

}
Exemple #30
0
static void InitStats(void)
{
    int i;
    int j;
    int oldCluster;
    signed int slaughterfrags;
    int posnum;
    int slaughtercount;
    int playercount;
    char *msgLumpName;
    int msgSize;
    int msgLump;

    extern int LeaveMap;

    if (!deathmatch)
    {
        gametype = SINGLE;
        HubCount = 0;
        oldCluster = P_GetMapCluster(gamemap);
        if (oldCluster != P_GetMapCluster(LeaveMap))
        {
            if (oldCluster >= 1 && oldCluster <= 5)
            {
                msgLumpName = ClusMsgLumpNames[oldCluster - 1];
                msgLump = W_GetNumForName(msgLumpName);
                msgSize = W_LumpLength(msgLump);
                if (msgSize >= MAX_INTRMSN_MESSAGE_SIZE)
                {
                    I_Error("Cluster message too long (%s)", msgLumpName);
                }
                W_ReadLump(msgLump, ClusterMessage);
                ClusterMessage[msgSize] = 0;    // Append terminator
                HubText = ClusterMessage;
                HubCount = strlen(HubText) * TEXTSPEED + TEXTWAIT;
                S_StartSongName("hub", true);
            }
        }
    }
    else
    {
        gametype = DEATHMATCH;
        slaughterboy = 0;
        slaughterfrags = -9999;
        posnum = 0;
        playercount = 0;
        slaughtercount = 0;
        for (i = 0; i < MAXPLAYERS; i++)
        {
            totalFrags[i] = 0;
            if (playeringame[i])
            {
                playercount++;
                for (j = 0; j < MAXPLAYERS; j++)
                {
                    if (playeringame[j])
                    {
                        totalFrags[i] += players[i].frags[j];
                    }
                }
                posnum++;
            }
            if (totalFrags[i] > slaughterfrags)
            {
                slaughterboy = 1 << i;
                slaughterfrags = totalFrags[i];
                slaughtercount = 1;
            }
            else if (totalFrags[i] == slaughterfrags)
            {
                slaughterboy |= 1 << i;
                slaughtercount++;
            }
        }
        if (playercount == slaughtercount)
        {                       // don't do the slaughter stuff if everyone is equal
            slaughterboy = 0;
        }
        S_StartSongName("hub", true);
    }
}