コード例 #1
0
ファイル: r_data.c プロジェクト: jeffdoggett/Doom
//
// R_InitTextures
// Initializes the texture list
//  with the textures from the world map.
//
static void R_InitTextures (void)
{
    int i;

    textures = NULL;
    textureheight = NULL;
    numtextures = 0;

    R_MergeTextures ();

    textures = Z_Realloc (textures, numtextures * sizeof(*textures), PU_STATIC, 0);
    textureheight = Z_Realloc (textureheight, numtextures * sizeof(*textureheight), PU_STATIC, 0);

    // Create translation table for global animation.
    // killough 4/9/98: make column offsets 32-bit;
    // clean up malloc-ing to use sizeof
    texturetranslation = Z_Malloc((numtextures + 1) * sizeof(*texturetranslation), PU_STATIC, 0);

    for (i = 0; i < numtextures; ++i)
	texturetranslation[i] = i;

    while (--i >= 0)
    {
	int j;

	j = W_LumpNameHash(textures[i]->name) % (unsigned int)numtextures;
	textures[i]->next = textures[j]->index; // Prepend to chain
	textures[j]->index = i;
    }
#if 0
    // [BH] Initialize partially fullbright textures.
    texturefullbright = Z_Malloc(numtextures * sizeof(*texturefullbright), PU_STATIC, 0);

    memset(texturefullbright, 0, numtextures * sizeof(*texturefullbright));
    if (r_brightmaps)
    {
	i = 0;
	while (fullbright[i].colormask)
	{
	    if (fullbright[i].texture)
	    {
		int num = R_CheckTextureNumForName(fullbright[i].texture);

		if (num != -1)
		    texturefullbright[num] = fullbright[i].colormask;
		i++;
	    }
	}
    }
#endif
}
コード例 #2
0
static materialterraintype_t* getMaterialTerrainType(Material* mat, uint idx)
{
#define BATCH_SIZE       8

    materialterraintype_t* mtt;

    // If we've already assigned this material to a terrain type, override
    // the previous assignation.
    if((mtt = findMaterialTerrainType(mat)))
    {
        mtt->terrainNum = idx;
        return mtt;
    }

    // Its a new material.
    // Only allocate memory when it's needed.
    if(++numMaterialTTypes > maxMaterialTTypes)
    {
        uint newMax = maxMaterialTTypes + BATCH_SIZE;

        materialTTypes = Z_Realloc(materialTTypes, sizeof(*materialTTypes) * newMax, PU_GAMESTATIC);
        memset(materialTTypes+maxMaterialTTypes, 0, sizeof(*materialTTypes) * (newMax - maxMaterialTTypes));
        maxMaterialTTypes = newMax;
    }

    mtt = &materialTTypes[numMaterialTTypes-1];
    mtt->material = mat;
    mtt->terrainNum = idx - 1;
    return mtt;

#undef BATCH_SIZE
}
コード例 #3
0
ファイル: script.c プロジェクト: m4son/q2pro
static void add_string(menuSpinControl_t *s, const char *tok)
{
    if (s->numItems < MAX_MENU_ITEMS) {
        s->itemnames = Z_Realloc(s->itemnames, ALIGN(s->numItems + 2, MIN_MENU_ITEMS) * sizeof(char *));
        s->itemnames[s->numItems++] = UI_CopyString(tok);
    }
}
コード例 #4
0
ファイル: stable.c プロジェクト: postfix/quake2vr
qboolean Q_STShrink(stable_t *st, size_t newSize) {
    assert(st->st != NULL);
    
    // make sure that this is a valid resize
    if (newSize > MIN_SIZE && newSize < st->size) {
        // pack the string table into the smallest possible footprint
        int32_t size = nfst_pack((struct nfst_StringTable *)st->st);
        
        // if the string table can fit into
        if (size <= newSize) {
            void *new_one = NULL;
            if ((new_one = Z_Realloc(st->st, newSize)) != NULL) {
                st->st = new_one;
                st->size = newSize;
                nfst_grow((struct nfst_StringTable *)st->st, st->size);
                return true;
            }
        }
        
        // if it got here the allocation didn't change
        // either it's not small enough, or realloc failed
        // either way, expand the string table back to fit the allocation
        nfst_grow((struct nfst_StringTable *)st->st, st->size);
    }
    return false;
}
コード例 #5
0
ファイル: http.c プロジェクト: jayschwa/q2pro
// libcurl callback for filelists.
static size_t recv_func(void *ptr, size_t size, size_t nmemb, void *stream)
{
    dlhandle_t *dl = (dlhandle_t *)stream;
    size_t new_size, bytes;

    if (!nmemb)
        return 0;

    if (size > SIZE_MAX / nmemb)
        goto oversize;

    if (dl->position > MAX_DLSIZE)
        goto oversize;

    bytes = size * nmemb;
    if (bytes >= MAX_DLSIZE - dl->position)
        goto oversize;

    // grow buffer in MIN_DLSIZE chunks. +1 for NUL.
    new_size = (dl->position + bytes + MIN_DLSIZE) & ~(MIN_DLSIZE - 1);
    if (new_size > dl->size) {
        dl->size = new_size;
        dl->buffer = Z_Realloc(dl->buffer, new_size);
    }

    memcpy(dl->buffer + dl->position, ptr, bytes);
    dl->position += bytes;
    dl->buffer[dl->position] = 0;

    return bytes;

oversize:
    Com_DPrintf("[HTTP] Oversize file while trying to download '%s'\n", dl->url);
    return 0;
}
コード例 #6
0
ファイル: r_drawlist.c プロジェクト: MP2E/kexplus
vtxlist_t *DL_AddVertexList(drawlist_t * dl)
{
	vtxlist_t *list;

	list = &dl->list[dl->index];

	if (list == &dl->list[dl->max - 1]) {
		// add a new list to the array
		dl->max++;

		// allocate array
		dl->list =
		    (vtxlist_t *) Z_Realloc(dl->list,
					    dl->max * sizeof(vtxlist_t),
					    PU_LEVEL, NULL);

		dmemset(&dl->list[dl->max - 1], 0, sizeof(vtxlist_t));

		list = &dl->list[dl->index];
	}

	list->flags = 0;
	list->texid = 0;
	list->params = 0;

	return &dl->list[dl->index++];
}
コード例 #7
0
ファイル: t_prepro.c プロジェクト: dorienh/smmu
void parse_include(char *lumpname)
{
  int lumpnum;
  char *lump, *end;
  char *saved_rover;
  
  if(-1 == (lumpnum = W_GetNumForName(lumpname)) )
    {
      script_error("include lump '%s' not found!\n", lumpname);
      return;
    }
  
  lump = W_CacheLumpNum(lumpnum, PU_STATIC);
  
  // realloc bigger for NULL at end
  lump = Z_Realloc(lump, W_LumpLength(lumpnum)+10, PU_STATIC, NULL);
  
  saved_rover = rover;    // save rover during include
  rover = lump; end = lump+W_LumpLength(lumpnum);
  *end = 0;
  
  // preprocess the include
  // we assume that it does not include sections or labels or 
  // other nasty things
  process_find_char(lump, 0);
  
  // now parse the lump
  parse_data(lump, end);
  
  // restore rover
  rover = saved_rover;
  
  // free the lump
  Z_Free(lump);
}
コード例 #8
0
ファイル: lua_script.c プロジェクト: HipsterLion/SRB2
// Lua asks for memory using this.
static void *LUA_Alloc(void *ud, void *ptr, size_t osize, size_t nsize)
{
	(void)ud;
	if (nsize == 0) {
		if (osize != 0)
			Z_Free(ptr);
		return NULL;
	} else
		return Z_Realloc(ptr, nsize, PU_LUA, NULL);
}
コード例 #9
0
ファイル: fi_main.cpp プロジェクト: cmbruns/Doomsday-Engine
finale_t* P_CreateFinale(void)
{
    finale_t* f;
    finales = (finale_t *) Z_Realloc(finales, sizeof(*finales) * ++finalesSize, PU_APPSTATIC);
    f = &finales[finalesSize-1];
    f->id = finalesUniqueId();
    f->_interpreter = P_CreateFinaleInterpreter();
    f->_interpreter->_id = f->id;
    f->active = true;
    return f;
}
コード例 #10
0
ファイル: stable.c プロジェクト: Nephatrine/nephq2
int32_t Q_STPack(stable_t *st) {
    int32_t size = nfst_pack((struct nfst_StringTable *)st->st);
    if (st->heap && size > MIN_SIZE && size <= st->size/2) {
        void *new_one = NULL;
        if ((new_one = Z_Realloc(st->st, size)) != NULL) {
            st->st = new_one;
            st->size = size;
        }
    }
    return size;
}
コード例 #11
0
ファイル: net_encode.c プロジェクト: Reedych/xash3d
void Delta_ParseTable( char **delta_script, delta_info_t *dt, const char *encodeDll, const char *encodeFunc )
{
	string		token;
	delta_t		*pField;
	const delta_field_t	*pInfo;

	// allocate the delta-structures
	if( !dt->pFields ) dt->pFields = (delta_t *)Z_Malloc( dt->maxFields * sizeof( delta_t ));

	pField = dt->pFields;
	pInfo = dt->pInfo;
	dt->numFields = 0;

	// assume we have handled '{'
	while(( *delta_script = COM_ParseFile( *delta_script, token )) != NULL )
	{
		ASSERT( dt->numFields <= dt->maxFields );

		if( !Q_strcmp( token, "DEFINE_DELTA" ))
		{
			if( Delta_ParseField( delta_script, pInfo, &pField[dt->numFields], false ))
				dt->numFields++;
		}
		else if( !Q_strcmp( token, "DEFINE_DELTA_POST" ))
		{
			if( Delta_ParseField( delta_script, pInfo, &pField[dt->numFields], true ))
				dt->numFields++;
		}
		else if( token[0] == '}' )
		{
			// end of the section
			break;
		}
	}

	// copy function name
	Q_strncpy( dt->funcName, encodeFunc, sizeof( dt->funcName ));

	if( !Q_stricmp( encodeDll, "none" ))
		dt->customEncode = CUSTOM_NONE;
	else if( !Q_stricmp( encodeDll, "gamedll" ))
		dt->customEncode = CUSTOM_SERVER_ENCODE;
	else if( !Q_stricmp( encodeDll, "clientdll" ))
		dt->customEncode = CUSTOM_CLIENT_ENCODE;

	// adjust to fit memory size
	if( dt->numFields < dt->maxFields )
	{
		dt->pFields = Z_Realloc( dt->pFields, dt->numFields * sizeof( delta_t ));
	}

	dt->bInitialized = true; // table is ok
}
コード例 #12
0
ファイル: sset.c プロジェクト: postfix/quake2vr
qboolean Q_SSetGrow(sset_t *ss, uint32_t newSize) {
    assert(ss != NULL);
    
    if (newSize > ss->maxSize) {
        int32_t *newTokens = Z_Realloc(ss->tokens, newSize * sizeof(int32_t));
        if (newTokens) {
            ss->tokens = newTokens;
            ss->maxSize = newSize;
            return true;
        }
    }
    return false;
}
コード例 #13
0
ファイル: d_client.c プロジェクト: Doom-Utils/dsdoom
static void CheckQueuedPackets(void)
{

  int i;
  for (i=0; (unsigned)i<numqueuedpackets; i++)
    if (doom_ntohl(queuedpacket[i]->tic) <= gametic)
      switch (queuedpacket[i]->type) {
      case PKT_QUIT: // Player quit the game
  {
    int pn = *(byte*)(queuedpacket[i]+1);
    playeringame[pn] = false;
    doom_printf("Player %d left the game\n", pn);
  }
  break;
      case PKT_EXTRA:
  {
    int *p = (int*)(queuedpacket[i]+1);
    size_t len = LONG(*(p+2));
    switch (LONG(*p)) {
    case nm_plcolour:
      G_ChangedPlayerColour(LONG(*(p+1)), LONG(*(p+3)));
      break;
    case nm_savegamename:
      if (len < SAVEDESCLEN) {
        memcpy(savedescription, p+3, len);
        // Force terminating 0 in case
        savedescription[len] = 0;
      }
      break;
    }
  }
  break;
      default: // Should not be queued
  break;
      }

  { // Requeue remaining packets
    int newnum = 0;
    packet_header_t **newqueue = NULL;

    for (i=0; (unsigned)i<numqueuedpackets; i++)
      if (doom_ntohl(queuedpacket[i]->tic) > gametic) {
  newqueue = Z_Realloc(newqueue, ++newnum * sizeof *newqueue,
           PU_STATIC, NULL);
  newqueue[newnum-1] = queuedpacket[i];
      } else Z_Free(queuedpacket[i]);

    Z_Free(queuedpacket);
    numqueuedpackets = newnum; queuedpacket = newqueue;
  }
}
コード例 #14
0
ファイル: net_encode.c プロジェクト: Reedych/xash3d
qboolean Delta_AddField( const char *pStructName, const char *pName, int flags, int bits, float mul, float post_mul )
{
	delta_info_t	*dt;
	delta_field_t	*pFieldInfo;
	delta_t		*pField;
	int		i;

	// get the delta struct
	dt = Delta_FindStruct( pStructName );
	ASSERT( dt != NULL );

	// check for coexisting field
	for( i = 0, pField = dt->pFields; i < dt->numFields; i++, pField++ )
	{
		if( !Q_strcmp( pField->name, pName ))
		{
			MsgDev( D_NOTE, "Delta_Add: %s->%s already existing\n", pStructName, pName );
			return false; // field already exist		
		}
	}

	// find field description
	pFieldInfo = Delta_FindFieldInfo( dt->pInfo, pName );
	if( !pFieldInfo )
	{
		MsgDev( D_ERROR, "Delta_Add: couldn't find description for %s->%s\n", pStructName, pName );
		return false;
	}

	if( dt->numFields + 1 > dt->maxFields )
	{
		MsgDev( D_WARN, "Delta_Add: can't add %s->%s encoder list is full\n", pStructName, pName );
		return false; // too many fields specified (duplicated ?)
	}

	// allocate a new one
	dt->pFields = Z_Realloc( dt->pFields, (dt->numFields + 1) * sizeof( delta_t ));	
	for( i = 0, pField = dt->pFields; i < dt->numFields; i++, pField++ );

	// copy info to new field
	pField->name = pFieldInfo->name;
	pField->offset = pFieldInfo->offset;
	pField->size = pFieldInfo->size;
	pField->flags = flags;
	pField->bits = bits;
	pField->multiplier = mul;
	pField->post_multiplier = post_mul;
	dt->numFields++;

	return true;
}
コード例 #15
0
ファイル: midifile.c プロジェクト: Manuel-K/doomretro
static dboolean ReadTrack(midi_track_t *track, FILE *stream)
{
    midi_event_t        *new_events = NULL;
    unsigned int        last_event_type;

    track->num_events = 0;
    track->events = NULL;
    track->num_event_mem = 0;   // NSM

    // Read the header:
    if (!ReadTrackHeader(track, stream))
        return false;

    // Then the events:
    last_event_type = 0;

    for (;;)
    {
        midi_event_t    *event;

        // Resize the track slightly larger to hold another event:
        if (track->num_events == track->num_event_mem)
        {
            // depending on the state of the heap and the malloc implementation, realloc()
            // one more event at a time can be VERY slow. 10sec+ in MSVC
            track->num_event_mem += 100;
            new_events = Z_Realloc(track->events, sizeof(midi_event_t) * track->num_event_mem);
        }

        if (!new_events)
            return false;

        track->events = new_events;

        // Read the next event:
        event = &track->events[track->num_events];
        if (!ReadEvent(event, &last_event_type, stream))
            return false;

        ++track->num_events;

        // End of track?
        if (event->event_type == MIDI_EVENT_META
            && event->data.meta.type == MIDI_META_END_OF_TRACK)
            break;
    }

    return true;
}
コード例 #16
0
ファイル: stable.c プロジェクト: postfix/quake2vr
int32_t Q_STAutoPack(stable_t *st) {
	int32_t size;
    assert(st->st != NULL);
    size = nfst_pack((struct nfst_StringTable *)st->st);
    if (size <= st->size) {
        void *new_one = NULL;
		if ((new_one = Z_Realloc(st->st, size)) != NULL) {
			st->st = new_one;
            st->size = size;
            return size;
        }
    }
    // if the reallocation failed, expand the string table again
    nfst_grow((struct nfst_StringTable *)st->st, st->size);
    return st->size;
}
コード例 #17
0
ファイル: mn_misc.c プロジェクト: dorienh/smmu
static void WriteCentredText(char *message)
{
  static char *tempbuf = NULL;
  static int allocedsize=0;
  char *rover, *addrover;
  int x, y;

  // rather than reallocate memory every time we draw it,
  // use one buffer and increase the size as neccesary
  if(strlen(message) > allocedsize)
    {
      if(tempbuf)
	tempbuf = Z_Realloc(tempbuf, strlen(message)+3, PU_STATIC, 0);
      else
	tempbuf = Z_Malloc(strlen(message)+3, PU_STATIC, 0);

      allocedsize = strlen(message);
    }

  y = (SCREENHEIGHT - V_StringHeight(popup_message)) / 2;
  addrover = tempbuf;
  rover = message;

  while(*rover)
    {
      if(*rover == '\n')
	{
	  *addrover = '\0';  // end string
	  x = (SCREENWIDTH - V_StringWidth(tempbuf)) / 2;
	  V_WriteText(tempbuf, x, y);
	  addrover = tempbuf;  // reset addrover
	  y += 7; // next line
	}
      else      // add next char
	{
	  *addrover = *rover;
	  addrover++;
	}
      rover++;
    }

  // dont forget the last line.. prob. not \n terminated

  *addrover = '\0';
  x = (SCREENWIDTH - V_StringWidth(tempbuf)) / 2;
  V_WriteText(tempbuf, x, y);
}
コード例 #18
0
ファイル: p_switch.c プロジェクト: ryan-sg/doomretro
//
// P_InitSwitchList()
//
// Only called at game initialization in order to list the set of switches
// and buttons known to the engine. This enables their texture to change
// when activated, and in the case of buttons, change back after a timeout.
//
// This routine modified to read its data from a predefined lump or
// PWAD lump called SWITCHES rather than a static table in this module to
// allow wad designers to insert or modify switches.
//
// Lump format is an array of byte packed switchlist_t structures, terminated
// by a structure with episode == -0. 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.
//
// Rewritten by Lee Killough to remove limit 2/8/98
//
void P_InitSwitchList(void)
{
    int                 i;
    int                 index = 0;
    int                 episode = (gamemode == registered || gamemode == retail ? 2 :
                            (gamemode == commercial ? 3 : 1));
    switchlist_t        *alphSwitchList;                // jff 3/23/98 pointer to switch table
    int                 lump = W_GetNumForName2("SWITCHES");    // cph - new wad lump handling

    // jff 3/23/98 read the switch table from a predefined lump
    alphSwitchList = (switchlist_t *)W_CacheLumpNum(lump, PU_STATIC);

    for (i = 0;; ++i)
    {
        if (index + 1 >= max_numswitches)
            switchlist = Z_Realloc(switchlist, sizeof(*switchlist)
                * (max_numswitches = max_numswitches ? max_numswitches * 2 : 8));
        if (SHORT(alphSwitchList[i].episode) <= episode)        // jff 5/11/98 endianess
        {
            int texture1;
            int texture2;

            if (!SHORT(alphSwitchList[i].episode))
                break;

            // Ignore switches referencing unknown texture names, instead of exiting.
            // Warn if either one is missing, but only add if both are valid.
            texture1 = R_CheckTextureNumForName(alphSwitchList[i].name1);
            if (texture1 == -1)
                C_Warning("Switch %i in SWITCHES lump has an unknown texture of %s.", i,
                    alphSwitchList[i].name1);
            texture2 = R_CheckTextureNumForName(alphSwitchList[i].name2);
            if (texture2 == -1)
                C_Warning("Switch %i in SWITCHES lump has an unknown texture of %s.", i,
                    alphSwitchList[i].name2);
            if (texture1 != -1 && texture2 != -1)
            {
                switchlist[index++] = texture1;
                switchlist[index++] = texture2;
            }
        }
    }

    numswitches = index / 2;
    switchlist[index] = -1;
    W_ReleaseLumpNum(lump);
}
コード例 #19
0
ファイル: stable.c プロジェクト: postfix/quake2vr
qboolean Q_STGrow(stable_t *st, size_t newSize) {
    assert(st->st != NULL);
    
    // check to see if it's a valid size
    if (newSize > st->size && newSize > MIN_SIZE) {
        void *new_one = NULL;
        // try to reallocate it into the larger size
        if ((new_one = Z_Realloc(st->st, newSize)) != NULL) {
            // if that succeeds, save the size and grow the string table
            st->st = new_one;
            st->size = newSize;
            nfst_grow((struct nfst_StringTable *)st->st, newSize);
            return true;
        }
    }
    // leave everything untouched
    return false;
}
コード例 #20
0
ファイル: cbuffer.cpp プロジェクト: cmbruns/Doomsday-Engine
static void bufferFlush(CBuffer* cb)
{
    uint len;
    cbline_t* line;

    assert(cb);

    // Is there anything to flush?
    if(cb->wbc < 1)
        return;

    line = bufferNewLine(cb);

    //
    // Flush the write buffer.
    //
    len = cb->wbc;
    if(line->text)
    {
        if(line->len <= len)
        {
            line->len = len + 1;
            line->text = (char*)Z_Realloc(line->text, line->len, PU_APPSTATIC);
            if(!line->text) Con_Error("CBuffer::flush: Failed on reallocation of %lu bytes for text line.", (unsigned long) line->len);
        }
    }
    else
    {
        line->len = len + 1;
        line->text = (char*)Z_Malloc(line->len, PU_APPSTATIC, 0);
        if(!line->text) Con_Error("CBuffer::flush: Failed on allocation of %lu bytes for text line.", (unsigned long) line->len);
    }

    memcpy(line->text, cb->writebuf, len);
    line->text[len] = 0;

    line->flags = cb->wbFlags;

    // Clear the write buffer.
    memset(cb->writebuf, 0, cb->maxLineLen);
    cb->wbc = 0;
    cb->wbFlags = 0;
}
コード例 #21
0
ファイル: stable.c プロジェクト: Nephatrine/nephq2
int32_t Q_STRegister(stable_t *st, const char *string) {
    int result = nfst_to_symbol((struct nfst_StringTable *)st->st, string);
    if (result == NFST_STRING_TABLE_FULL && st->heap) {
        void *new_one = NULL;
        int newsize = st->size * 2;
        if ((new_one = Z_Realloc(st->st, newsize)) != NULL) {
            st->st = new_one;
            st->size = newsize;
            nfst_grow((struct nfst_StringTable *)st->st, newsize);
            result = nfst_to_symbol((struct nfst_StringTable *)st->st, string);
        }
    
    }
    if (result == NFST_STRING_TABLE_FULL) {
        Com_Printf(S_COLOR_RED"Error: could not register string: %s\n",string);
    }
    
    return result;
}
コード例 #22
0
ファイル: fi_lib.c プロジェクト: cmbruns/Doomsday-Engine
static fi_state_t* stackPush(finaleid_t finaleId, finale_mode_t mode, gamestate_t prevGamestate,
                             const char* defId)
{
    fi_state_t* s;
    finaleStack = Z_Realloc(finaleStack, sizeof(*finaleStack) * ++finaleStackSize, PU_GAMESTATIC);
    s = &finaleStack[finaleStackSize-1];
    s->finaleId = finaleId;
    s->mode = mode;
    s->initialGamestate = prevGamestate;
    if(defId)
    {
        (void) strncpy(s->defId, defId, sizeof(s->defId) - 1);
        s->defId[sizeof(s->defId) - 1] = 0; // terminate
    }
    else
    {
        // Source ID not provided.
        memset(s->defId, 0, sizeof(s->defId));
    }
    initStateConditions(s);
    return s;
}
コード例 #23
0
ファイル: fi_main.cpp プロジェクト: cmbruns/Doomsday-Engine
void P_DestroyFinale(finale_t* f)
{
    assert(f);
    {uint i;
    for(i = 0; i < finalesSize; ++i)
    {
        if(&finales[i] != f)
            continue;

        if(i != finalesSize-1)
            memmove(&finales[i], &finales[i+1], sizeof(*finales) * (finalesSize-i));

        if(finalesSize > 1)
        {
            finales = (finale_t *) Z_Realloc(finales, sizeof(*finales) * --finalesSize, PU_APPSTATIC);
        }
        else
        {
            Z_Free(finales); finales = 0;
            finalesSize = 0;
        }
        break;
    }}
}
コード例 #24
0
ファイル: p_plats.c プロジェクト: Lord-Ptolemy/strife-ve
//
// P_AddActivePlat
//
void P_AddActivePlat(plat_t* plat)
{
    int i;

    for(i = 0; i < numactiveplats; i++)
    {
        if(activeplats[i] == NULL)
        {
            activeplats[i] = plat;
            return;
        }    
    }
    
    // haleyjd 20140816: [SVE] remove activeplats limit
    if(numactiveplats == numactiveplatsalloc)
    {
        numactiveplatsalloc = 
            numactiveplatsalloc ? 2*numactiveplatsalloc : MAXPLATS;
        activeplats = Z_Realloc(activeplats, 
                                numactiveplatsalloc * sizeof(plat_t *),
                                PU_STATIC, NULL);
    }
    activeplats[numactiveplats++] = plat;
}
コード例 #25
0
ファイル: lua_maplib.c プロジェクト: HipsterLion/SRB2
// help function for P_LoadSectors, find a flat in the active wad files,
// allocate an id for it, and set the levelflat (to speedup search)
//
static INT32 P_AddLevelFlatRuntime(const char *flatname)
{
	size_t i;
	levelflat_t *levelflat = levelflats;

	//
	//  first scan through the already found flats
	//
	for (i = 0; i < numlevelflats; i++, levelflat++)
		if (strnicmp(levelflat->name,flatname,8)==0)
			break;

	// that flat was already found in the level, return the id
	if (i == numlevelflats)
	{
		// allocate new flat memory
		levelflats = Z_Realloc(levelflats, (numlevelflats + 1) * sizeof(*levelflats), PU_LEVEL, NULL);
		levelflat = levelflats+i;

		// store the name
		strlcpy(levelflat->name, flatname, sizeof (levelflat->name));
		strupr(levelflat->name);

		// store the flat lump number
		levelflat->lumpnum = R_GetFlatNumForName(flatname);

#ifndef ZDEBUG
		CONS_Debug(DBG_SETUP, "flat #%03d: %s\n", atoi(sizeu1(numlevelflats)), levelflat->name);
#endif

		numlevelflats++;
	}

	// level flat id
	return (INT32)i;
}
コード例 #26
0
ファイル: d_client.c プロジェクト: RobLoach/libretro-prboom
void NetUpdate(void)
{
  static int lastmadetic;
  if (isExtraDDisplay)
    return;
  if (server) { // Receive network packets
    size_t recvlen;
    packet_header_t *packet = Z_Malloc(10000, PU_STATIC, NULL);
    while ((recvlen = I_GetPacket(packet, 10000))) {
      switch(packet->type) {
      case PKT_TICS:
  {
    uint8_t *p = (void*)(packet+1);
    int tics = *p++;
    unsigned long ptic = doom_ntohl(packet->tic);
    if (ptic > (unsigned)remotetic) { // Missed some
      packet_set(packet, PKT_RETRANS, remotetic);
      *(uint8_t*)(packet+1) = consoleplayer;
      I_SendPacket(packet, sizeof(*packet)+1);
    } else {
      if (ptic + tics <= (unsigned)remotetic) break; // Will not improve things
      remotetic = ptic;
      while (tics--) {
        int players = *p++;
        while (players--) {
            int n = *p++;
            RawToTic(&netcmds[n][remotetic%BACKUPTICS], p);
            p += sizeof(ticcmd_t);
        }
        remotetic++;
      }
    }
  }
  break;
      case PKT_RETRANS: // Resend request
          remotesend = doom_ntohl(packet->tic);
          break;
      case PKT_DOWN: // Server downed
  {
    int j;
    for (j=0; j<MAXPLAYERS; j++)
      if (j != consoleplayer) playeringame[j] = FALSE;
    server = FALSE;
    doom_printf("Server is down\nAll other players are no longer in the game\n");
  }
  break;
      case PKT_EXTRA: // Misc stuff
      case PKT_QUIT: // Player quit
  // Queue packet to be processed when its tic time is reached
  queuedpacket = Z_Realloc(queuedpacket, ++numqueuedpackets * sizeof *queuedpacket,
         PU_STATIC, NULL);
  queuedpacket[numqueuedpackets-1] = Z_Malloc(recvlen, PU_STATIC, NULL);
  memcpy(queuedpacket[numqueuedpackets-1], packet, recvlen);
  break;
      case PKT_BACKOFF:
        /* cph 2003-09-18 -
	 * The server sends this when we have got ahead of the other clients. We should
	 * stall the input side on this client, to allow other clients to catch up.
	 */
        lastmadetic++;
	break;
      default: // Other packet, unrecognised or redundant
  break;
      }
    }
    Z_Free(packet);
  }
  { // Build new ticcmds
    int newtics = I_GetTime() - lastmadetic;
    newtics = (newtics > 0 ? newtics : 0);
    lastmadetic += newtics;
    if (ffmap) newtics++;
    while (newtics--) {
      I_StartTic();
      if (maketic - gametic > BACKUPTICS/2) break;
      G_BuildTiccmd(&localcmds[maketic%BACKUPTICS]);
      maketic++;
    }
    if (server && maketic > remotesend) { // Send the tics to the server
      int sendtics;
      remotesend -= xtratics;
      if (remotesend < 0) remotesend = 0;
      sendtics = maketic - remotesend;
      {
  size_t pkt_size = sizeof(packet_header_t) + 2 + sendtics * sizeof(ticcmd_t);
  packet_header_t *packet = Z_Malloc(pkt_size, PU_STATIC, NULL);

  packet_set(packet, PKT_TICC, maketic - sendtics);
  *(uint8_t*)(packet+1) = sendtics;
  *(((uint8_t*)(packet+1))+1) = consoleplayer;
  {
    void *tic = ((uint8_t*)(packet+1)) +2;
    while (sendtics--) {
      TicToRaw(tic, &localcmds[remotesend++%BACKUPTICS]);
      tic = (uint8_t *)tic + sizeof(ticcmd_t);
    }
  }
  I_SendPacket(packet, pkt_size);
  Z_Free(packet);
      }
    }
  }
}
コード例 #27
0
ファイル: w_wad.c プロジェクト: mdgunn/doomretro
//
// W_AddFile
// All files are optional, but at least one file must be
//  found (PWAD, if all required lumps are present).
// Files with a .wad extension are wadlink files
//  with multiple lumps.
// Other files are single lumps with the base filename
//  for the lump name.
wad_file_t *W_AddFile(char *filename, dboolean automatic)
{
    wadinfo_t   header;
    lumpindex_t i;
    int         startlump;
    filelump_t  *fileinfo;
    filelump_t  *filerover;
    lumpinfo_t  *filelumps;
    int         numfilelumps;

    // open the file and add to directory
    wad_file_t  *wad_file = W_OpenFile(filename);

    if (!wad_file)
        return NULL;

    M_StringCopy(wad_file->path, filename, sizeof(wad_file->path));

    wad_file->freedoom = IsFreedoom(filename);

    if (!M_StringCompare(filename + strlen(filename) - 3, "wad"))
    {
        // single lump file

        // fraggle: Swap the filepos and size here. The WAD directory
        // parsing code expects a little-endian directory, so will swap
        // them back. Effectively we're constructing a "fake WAD directory"
        // here, as it would appear on disk.
        fileinfo = Z_Malloc(sizeof(filelump_t), PU_STATIC, NULL);
        fileinfo->filepos = LONG(0);
        fileinfo->size = LONG(wad_file->length);

        // Name the lump after the base of the filename (without the
        // extension).
        ExtractFileBase(filename, fileinfo->name);
        numfilelumps = 1;
    }
    else
    {
        int     length;

        // WAD file
        W_Read(wad_file, 0, &header, sizeof(header));

        // Homebrew levels?
        if (strncmp(header.identification, "IWAD", 4)
            && strncmp(header.identification, "PWAD", 4))
            I_Error("Wad file %s doesn't have IWAD or PWAD id\n", filename);

        wad_file->type = (!strncmp(header.identification, "IWAD", 4) ? IWAD : PWAD);

        header.numlumps = LONG(header.numlumps);
        header.infotableofs = LONG(header.infotableofs);
        length = header.numlumps * sizeof(filelump_t);
        fileinfo = Z_Malloc(length, PU_STATIC, NULL);

        W_Read(wad_file, header.infotableofs, fileinfo, length);
        numfilelumps = header.numlumps;
    }

    // Increase size of numlumps array to accommodate the new file.
    filelumps = calloc(numfilelumps, sizeof(lumpinfo_t));
    if (!filelumps)
        I_Error("Failed to allocate array for lumps from new file.");

    startlump = numlumps;
    numlumps += numfilelumps;
    lumpinfo = Z_Realloc(lumpinfo, numlumps * sizeof(lumpinfo_t *));
    if (!lumpinfo)
        I_Error("Failed to increase lumpinfo[] array size.");

    filerover = fileinfo;

    for (i = startlump; i < numlumps; ++i)
    {
        lumpinfo_t      *lump_p = &filelumps[i - startlump];

        lump_p->wad_file = wad_file;
        lump_p->position = LONG(filerover->filepos);
        lump_p->size = LONG(filerover->size);
        lump_p->cache = NULL;
        strncpy(lump_p->name, filerover->name, 8);
        lumpinfo[i] = lump_p;

        ++filerover;
    }

    Z_Free(fileinfo);

    if (lumphash)
    {
        Z_Free(lumphash);
        lumphash = NULL;
    }

    C_Output("%s %s lump%s from %.4s file %s.", (automatic ? "Automatically added" : "Added"),
        commify(numlumps - startlump), (numlumps - startlump == 1 ? "" : "s"),
        header.identification, uppercase(filename));

    return wad_file;
}
コード例 #28
0
ファイル: r_data.c プロジェクト: jeffdoggett/Doom
static void R_ReadTextures (int names_lump, int maptex_lump_1, int maptex_lump_2)
{
    const maptexture_t	*mtexture;
    texture_t		*texture;
    int			i, j;
    const int		*maptex1;
    const int		*maptex2;
    const char		*names; // cph -
    const char		*name_p;// const*'s
    int			*patchlookup;
    int			texbase;
    int			numtex;
    int			nummappatches;
    int			maxoff, maxoff2;
    int			numtextures1, numtextures2;
    const int		*directory;
    char		name[9];

    // Load the patch names from pnames.lmp.
    name[8] = '\0';
    names = W_CacheLumpNum(names_lump, PU_STATIC);
    nummappatches = LONG(*((const int *)names));
    name_p = names + 4;
    patchlookup = malloc(nummappatches * sizeof(*patchlookup));   // killough

    for (i = 0; i < nummappatches; i++)
    {
	strncpy(name, name_p + i * 8, 8);
	patchlookup[i] = W_CheckNumForName(name);
    }
    W_ReleaseLumpNum(names_lump);       // cph - release the lump

    // Load the map texture definitions from textures.lmp.
    // The data is contained in one or two lumps,
    //  TEXTURE1 for shareware, plus TEXTURE2 for commercial.
    maptex1 = W_CacheLumpNum(maptex_lump_1, PU_STATIC);
    numtextures1 = LONG(*maptex1);
    maxoff = W_LumpLength(maptex_lump_1);
    directory = maptex1 + 1;

    if (maptex_lump_2 != -1)
    {
	maptex2 = W_CacheLumpNum(maptex_lump_2, PU_STATIC);
	numtextures2 = LONG(*maptex2);
	maxoff2 = W_LumpLength(maptex_lump_2);
    }
    else
    {
	maptex2 = NULL;
	numtextures2 = 0;
	maxoff2 = 0;
    }

    texbase = numtextures;
    numtex = numtextures1 + numtextures2;
    numtextures += numtex;

    // killough 4/9/98: make column offsets 32-bit;
    // clean up malloc-ing to use sizeof
    textures = Z_Realloc (textures, numtextures * sizeof(*textures), PU_STATIC, 0);
    textureheight = Z_Realloc (textureheight, numtextures * sizeof(*textureheight), PU_STATIC, 0);

    for (i = 0; i < numtex; ++directory)
    {
	const mappatch_t *mpatch;
	texpatch_t	*patch;
	int		offset;

	if (i == numtextures1)
	{
	    // Start looking in second texture file.
	    maptex1 = maptex2;
	    maxoff = maxoff2;
	    directory = maptex1 + 1;
	}

	if ((((byte *) directory) >= ((byte *)maptex1+maxoff))
	 || ((offset=LONG(*directory)) >= maxoff))
	{
	  printf ("R_InitTextures: bad texture directory %X/%X %d/%d\n",
		(uintptr_t)directory,((uintptr_t)maptex1+maxoff), offset, maxoff);
	  break;
	}

	mtexture = (const maptexture_t *)((const byte *)maptex1 + offset);

	if ((texbase)
	 && (R_DuplicateTexture (mtexture->name, texbase)))
	{
	  numtex--;
	  numtextures--;
	  numtextures1--;
	  continue;
	}

	texture = textures[texbase+i] = Z_Malloc(sizeof(texture_t) + sizeof(texpatch_t)
	    * (SHORT(mtexture->patchcount) - 1), PU_STATIC, 0);

	texture->width = SHORT(mtexture->width);
	texture->height = SHORT(mtexture->height);
	texture->patchcount = SHORT(mtexture->patchcount);
	// killough 1/31/98: Initialize texture hash table
	texture->index = -1;

	{
	    size_t      j;

	    for (j = 0; j < sizeof(texture->name); ++j)
		texture->name[j] = mtexture->name[j];
	}

#ifdef PADDED_STRUCTS
	mpatch = (mappatch_t *) ((char *) mtexture + 22);
#else
	mpatch = &mtexture->patches[0];
#endif
	patch = texture->patches;

	for (j = 0; j < texture->patchcount; ++j, ++patch)
	{
	    patch->originx = SHORT(mpatch->originx);
	    patch->originy = SHORT(mpatch->originy);
	    patch->patch = patchlookup[SHORT(mpatch->patch)];
	    if (patch->patch == -1)
		printf("Missing patch %d in texture %.8s.", SHORT(mpatch->patch),
		    texture->name);     // killough 4/17/98
#ifdef PADDED_STRUCTS
	    mpatch = (mappatch_t *)   ((unsigned char *) mpatch + 10);
#else
	    mpatch++;
#endif
	}

	for (j = 1; j * 2 <= texture->width; j <<= 1);
	texture->widthmask = j - 1;
	textureheight[texbase+i] = texture->height << FRACBITS;

	i++;	// Done here so that 'continue' misses it out...
    }

    free(patchlookup);	  // killough

    // cph - release the TEXTUREx lumps
    W_ReleaseLumpNum (maptex_lump_1);
    if (maptex_lump_2 != -1)
      W_ReleaseLumpNum (maptex_lump_2);
}
コード例 #29
0
ファイル: pr_edict.c プロジェクト: ProfessorKaos64/vkQuake
static void PR_AllocStringSlots (void)
{
	pr_maxknownstrings += PR_STRING_ALLOCSLOTS;
	Con_DPrintf2("PR_AllocStringSlots: realloc'ing for %d slots\n", pr_maxknownstrings);
	pr_knownstrings = (const char **) Z_Realloc ((void *)pr_knownstrings, pr_maxknownstrings * sizeof(char *));
}
コード例 #30
0
ファイル: fi_lib.c プロジェクト: cmbruns/Doomsday-Engine
int Hook_FinaleScriptStop(int hookType, int finaleId, void* parameters)
{
    gamestate_t initialGamestate;
    finale_mode_t mode;
    fi_state_t* s = stateForFinaleId(finaleId);

    DENG_UNUSED(hookType);
    DENG_UNUSED(parameters);

    if(IS_CLIENT && s == &remoteFinaleState)
    {
#ifdef _DEBUG
        Con_Message("Hook_FinaleScriptStop: Clientside script stopped, clearing remote state.");
        memset(&remoteFinaleState, 0, sizeof(remoteFinaleState));
#endif
        return true;
    }

    if(!s)
    {
        // Finale was not initiated by us...
        return true;
    }
    initialGamestate = s->initialGamestate;
    mode = s->mode;

    // Should we go back to NULL?
    if(finaleStackSize > 1)
    {   // Resume the next script on the stack.
        finaleStack = Z_Realloc(finaleStack, sizeof(*finaleStack) * --finaleStackSize, PU_GAMESTATIC);
        FI_ScriptResume(stackTop()->finaleId);
        return true;
    }

    /**
     * No more scripts are left.
     */
    Z_Free(finaleStack); finaleStack = 0;
    finaleStackSize = 0;

    // Return to the previous game state?
    if(FI_ScriptFlags(finaleId) & FF_LOCAL)
    {
        G_ChangeGameState(initialGamestate);
        return true;
    }

    // Go to the next game mode?
    if(mode == FIMODE_AFTER) // A map has been completed.
    {
        if(IS_CLIENT) return true;

        G_SetGameAction(GA_ENDDEBRIEFING);
    }
    else if(mode == FIMODE_BEFORE) // A briefing has ended.
    {
        // Its time to start the map; que music and begin!
        S_MapMusic(gameEpisode, gameMap);
        HU_WakeWidgets(-1 /* all players */);
        G_BeginMap();
        Pause_End(); // skip forced period
    }
    return true;
}