Пример #1
0
static FDoubleProd *NewDoubleProd (double val)
{
	FDoubleProd *prod = (FDoubleProd *)M_Malloc (sizeof(FDoubleProd));
	prod->Type = PROD_Double;
	prod->Value = val;
	return prod;
}
Пример #2
0
// This is used by DECORATE to assign ActorInfos to internal classes
void PClass::InitializeActorInfo ()
{
	Symbols.SetParentTable (&ParentClass->Symbols);
	Defaults = (BYTE *)M_Malloc(Size);
	if (ParentClass->Defaults != NULL) 
	{
		memcpy (Defaults, ParentClass->Defaults, ParentClass->Size);
		if (Size > ParentClass->Size)
		{
			memset (Defaults + ParentClass->Size, 0, Size - ParentClass->Size);
		}
	}
	else
	{
		memset (Defaults, 0, Size);
	}

	FActorInfo *info = ActorInfo = new FActorInfo;
	info->Class = this;
	info->GameFilter = GAME_Any;
	info->SpawnID = 0;
	info->DoomEdNum = -1;
	info->OwnedStates = NULL;
	info->NumOwnedStates = 0;
	info->Replacement = NULL;
	info->Replacee = NULL;
	info->StateList = NULL;
	info->DamageFactors = NULL;
	info->PainChances = NULL;
	info->PainFlashes = NULL;
	info->ColorSets = NULL;
	info->ScoreOnDeath = 0;
	m_RuntimeActors.Push (this);
}
Пример #3
0
static FStateLabels * CreateStateLabelList(TArray<FStateDefine> & statelist)
{
	// First delete all empty labels from the list
	for (int i=statelist.Size()-1;i>=0;i--)
	{
		if (statelist[i].Label == NAME_None || (statelist[i].State == NULL && statelist[i].Children.Size() == 0))
		{
			statelist.Delete(i);
		}
	}

	int count=statelist.Size();

	if (count == 0) return NULL;

	FStateLabels * list = (FStateLabels*)M_Malloc(sizeof(FStateLabels)+(count-1)*sizeof(FStateLabel));
	list->NumLabels = count;

	for (int i=0;i<count;i++)
	{
		list->Labels[i].Label = statelist[i].Label;
		list->Labels[i].State = statelist[i].State;
		list->Labels[i].Children = CreateStateLabelList(statelist[i].Children);
	}
	qsort(list->Labels, count, sizeof(FStateLabel), labelcmp);
	return list;
}
Пример #4
0
void FStringTable::SetString (const char *name, const char *newString)
{
	StringEntry **pentry, *oentry;
	FindString (name, pentry, oentry);

	size_t newlen = strlen (newString);
	size_t namelen = strlen (name);

	// Create a new string entry
	StringEntry *entry = (StringEntry *)M_Malloc (sizeof(*entry) + newlen + namelen);
	strcpy (entry->String, newString);
	strcpy (entry->Name = entry->String + newlen + 1, name);
	entry->PassNum = 0;

	// If this is a new string, insert it. Otherwise, replace the old one.
	if (oentry == NULL)
	{
		entry->Next = *pentry;
		*pentry = entry;
	}
	else
	{
		*pentry = entry;
		entry->Next = oentry->Next;
		M_Free (oentry);
	}
}
Пример #5
0
static FStringProd *NewStringProd (const char *str)
{
	FStringProd *prod = (FStringProd *)M_Malloc (sizeof(FStringProd)+strlen(str));
	prod->Type = PROD_String;
	strcpy (prod->Value, str);
	return prod;
}
Пример #6
0
ddstring_t *Str_Prepend(ddstring_t *str, char const *prepend)
{
    char *copied;
    size_t incoming;

    DENG_ASSERT(str);
    DENG_ASSERT(prepend);

    if(!str || !prepend) return str;

    incoming = strlen(prepend);
    if(incoming == 0)
        return str;

    copied = M_Malloc(incoming);
    memcpy(copied, prepend, incoming);

    allocateString(str, str->length + incoming, true);
    memmove(str->str + incoming, str->str, str->length + 1);
    memcpy(str->str, copied, incoming);
    str->length += incoming;

    M_Free(copied);
    return str;
}
Пример #7
0
static FStringProd *NewStringProd (size_t len)
{
	FStringProd *prod = (FStringProd *)M_Malloc (sizeof(FStringProd)+len);
	prod->Type = PROD_String;
	prod->Value[0] = 0;
	return prod;
}
Пример #8
0
Rect *Rect_New(void)
{
    Rect *r = M_Malloc(sizeof *r);
    r->origin = Point2_New();
    r->size = Size2_New();
    return r;
}
Пример #9
0
//----初始化标准输入模块-------------------------------------------------------
//功能: 初始化标准输入模块,执行初始化后,可以创建输入设备。
//参数: 无
//返回: true = 成功,false= 失败.
//-----------------------------------------------------------------------------
bool_t ModuleInstall_Stddev(ptu32_t para)
{
    static struct  tagStdinDeviceRsc root;

    tg_pStdinInputMsgQ = Stddev_CreatInputMsgQ(10,"StdInDev");
    if(tg_pStdinInputMsgQ == NULL)
        return false;
    g_ptStdinDevice = M_Malloc(gc_u32CfgStdinDeviceLimit
                                * sizeof(struct  tagStdinDeviceRsc),0);
    if(g_ptStdinDevice == NULL)
    {
        Stddev_DeleteInputMsgQ(tg_pStdinInputMsgQ);
        return false;
    }
    s_ptStdinDeviceRscTree = (struct  tagStdinDeviceRsc *)
                        Rsc_AddTree(&root.stdin_device_node,
                        sizeof(struct  tagStdinDeviceRsc),RSC_STDIN_OUT,"stdin input device");
    //初始化泛设备控制块内存池
    g_ptStdinDevicePool = Mb_CreatePool((void*)g_ptStdinDevice,
                                    gc_u32CfgStdinDeviceLimit,
                                    sizeof(struct  tagStdinDeviceRsc),
                                    2,10,
                                    "输入设备控制块内存池");
    Stddev_SetFocusDefault(tg_pStdinInputMsgQ);
    return true;
}
Пример #10
0
FMemArena::Block *FMemArena::AddBlock(size_t size)
{
	Block *mem, **last;
	size += sizeof(Block);		// Account for header size

	// Search for a free block to use
	for (last = &FreeBlocks, mem = FreeBlocks; mem != NULL; last = &mem->NextBlock, mem = mem->NextBlock)
	{
		if ((BYTE *)mem->Limit - (BYTE *)mem >= (ptrdiff_t)size)
		{
			*last = mem->NextBlock;
			break;
		}
	}
	if (mem == NULL)
	{
		// Allocate a new block
		if (size < BlockSize)
		{
			size = BlockSize;
		}
		else
		{ // Stick some free space at the end so we can use this block for
		  // other things.
			size += BlockSize/2;
		}
		mem = (Block *)M_Malloc(size);
		mem->Limit = (BYTE *)mem + size;
	}
	mem->Reset();
	mem->NextBlock = TopBlock;
	TopBlock = mem;
	return mem;
}
Пример #11
0
ddstring_t *Str_PartAppend(ddstring_t *str, char const *append, int start, int count)
{
    int partLen;
    char *copied;

    DENG_ASSERT(str);
    DENG_ASSERT(append);

    if(!str || !append) return str;
    if(start < 0 || count <= 0) return str;

    copied = M_Malloc(count + 1);
    copied[0] = 0; // empty string

    strncat(copied, append + start, count);
    partLen = strlen(copied);

    allocateString(str, str->length + partLen + 1, true);
    memcpy(str->str + str->length, copied, partLen);
    str->length += partLen;

    // Terminate the appended part.
    str->str[str->length] = 0;

    M_Free(copied);
    return str;
}
Пример #12
0
void FRemapTable::Alloc(int count)
{
	Remap = (BYTE *)M_Malloc(count*sizeof(*Remap) + count*sizeof(*Palette));
	assert (Remap != NULL);
	Palette = (PalEntry *)(Remap + count*(sizeof(*Remap)));
	Native = NULL;
	NumEntries = count;
}
Пример #13
0
size_t Zip::readLump(int lumpIdx, uint8_t* buffer, size_t startOffset,
                     size_t length, bool tryCache)
{
    LOG_AS("Zip::readLump");
    ZipFile const& file = reinterpret_cast<ZipFile&>(lump(lumpIdx));

    LOG_TRACE("\"%s:%s\" (%u bytes%s) [%u +%u]")
            << de::NativePath(composePath()).pretty()
            << de::NativePath(file.composePath()).pretty()
            << (unsigned long) file.size()
            << (file.isCompressed()? ", compressed" : "")
            << startOffset
            << length;

    // Try to avoid a file system read by checking for a cached copy.
    if(tryCache)
    {
        uint8_t const* data = d->lumpCache? d->lumpCache->data(lumpIdx) : 0;
        LOG_TRACE("Cache %s on #%i") << (data? "hit" : "miss") << lumpIdx;
        if(data)
        {
            size_t readBytes = MIN_OF(file.size(), length);
            memcpy(buffer, data + startOffset, readBytes);
            return readBytes;
        }
    }

    size_t readBytes;
    if(!startOffset && length == file.size())
    {
        // Read it straight to the caller's data buffer.
        readBytes = d->bufferLump(file, buffer);
    }
    else
    {
        // Allocate a temporary buffer and read the whole lump into it(!).
        uint8_t* lumpData = (uint8_t*) M_Malloc(file.size());
        if(!lumpData) throw Error("Zip::readLumpSection", QString("Failed on allocation of %1 bytes for work buffer").arg(file.size()));

        if(d->bufferLump(file, lumpData))
        {
            readBytes = MIN_OF(file.size(), length);
            memcpy(buffer, lumpData + startOffset, readBytes);
        }
        else
        {
            readBytes = 0;
        }
        M_Free(lumpData);
    }

    /// @todo Do not check the read length here.
    if(readBytes < MIN_OF(file.size(), length))
        throw Error("Zip::readLumpSection", QString("Only read %1 of %2 bytes of lump #%3").arg(readBytes).arg(length).arg(lumpIdx));

    return readBytes;
}
Пример #14
0
SaveInfo *SaveInfo_New(void)
{
    SaveInfo *info = (SaveInfo *)M_Malloc(sizeof *info);

    Str_Init(&info->name);
    info->gameId = 0;
    memset(&info->header, 0, sizeof(info->header));

    return info;
}
Пример #15
0
// =============================================================================
// 功能:新增SPI总线结点到SPI总线类型结点,并初始化tagSPI_CB控制块结构体
// 参数:NewSPIParam,新增总线参数,参数说明详细请参照tagSPI_Param结构体
// 返回:返回建立的资源结点指针,失败时返回NULL
// =============================================================================
struct tagSPI_CB *SPI_BusAdd(struct tagSPI_Param *NewSPIParam)
{
    struct tagSPI_CB *NewSPI;
    if(NULL == NewSPIParam)
        goto exit_from_param;

    //避免重复建立同名的SPI总线
    if(NULL != Rsc_SearchSon(&s_SPIBusType,NewSPIParam->BusName))
        goto exit_from_readd;

    NewSPI = (struct tagSPI_CB *)M_Malloc(sizeof(struct tagSPI_CB),0);
    if(NewSPI == NULL)
        goto exit_from_malloc;

    //将总线结点挂接到总线类型结点的子结点
    Rsc_AddSon(&s_SPIBusType,&NewSPI->SPI_BusNode,
                sizeof(struct tagSPI_CB),RSC_SPIBUS,NewSPIParam->BusName);
    if(&NewSPI->SPI_BusNode == NULL)
        goto exit_from_add_node;

    //创建总线信号量和阻塞信号量
    NewSPI->SPI_BusSemp= Lock_SempCreate(1,1,CN_SEMP_BLOCK_FIFO,"spi bus semp");
    if(NewSPI->SPI_BusSemp== NULL)
        goto exit_from_spi_bus_semp;
    NewSPI->SPI_BlockSemp = Lock_SempCreate(1,0,CN_SEMP_BLOCK_FIFO,"spi block semp");
    if(NewSPI->SPI_BlockSemp== NULL)
        goto exit_from_spi_buf_semp;

    //tagSPI_CB控制块初始化
    NewSPI->SpecificFlag      = NewSPIParam->SpecificFlag;
    NewSPI->pTransferTxRx     = NewSPIParam->pTransferTxRx;
    NewSPI->pCsActive         = NewSPIParam->pCsActive;
    NewSPI->pCsInActive       = NewSPIParam->pCsInActive;
    NewSPI->pBusCtrl          = NewSPIParam->pBusCtrl;
    NewSPI->pTransferPoll     = NewSPIParam->pTransferPoll;

    //缓冲区初始化
    NewSPI->SPI_Buf.pBuf     = NewSPIParam->SPIBuf;
    NewSPI->SPI_Buf.MaxLen   = NewSPIParam->SPIBufLen;
    NewSPI->SPI_Buf.Offset   = 0;

    printk("%s Added Succeeded!\r\n",NewSPIParam->BusName);
    return NewSPI;

exit_from_spi_buf_semp:
    Lock_SempDelete(NewSPI->SPI_BusSemp);
exit_from_spi_bus_semp:
    Rsc_DelNode(&NewSPI->SPI_BusNode);
exit_from_add_node:
    free(NewSPI);
exit_from_malloc:
exit_from_readd:
exit_from_param:
    return NULL;
}
Пример #16
0
void FTextureManager::AddComplexAnim (FTextureID picnum, const TArray<FAnimDef::FAnimFrame> &frames)
{
	FAnimDef *anim = (FAnimDef *)M_Malloc (sizeof(FAnimDef) + (frames.Size()-1) * sizeof(frames[0]));
	anim->BasePic = picnum;
	anim->NumFrames = frames.Size();
	anim->CurFrame = 0;
	anim->AnimType = FAnimDef::ANIM_DiscreteFrames;
	anim->SwitchTime = 0;
	memcpy (&anim->Frames[0], &frames[0], frames.Size() * sizeof(frames[0]));
	AddAnim (anim);
}
Пример #17
0
//
// R_ClearDrawSegs
//
void R_ClearDrawSegs (void)
{
	if (drawsegs == NULL)
	{
		MaxDrawSegs = 256;		// [RH] Default. Increased as needed.
		firstdrawseg = drawsegs = (drawseg_t *)M_Malloc (MaxDrawSegs * sizeof(drawseg_t));
	}
	FirstInterestingDrawseg = 0;
	InterestingDrawsegs.Clear ();
	ds_p = drawsegs;
}
Пример #18
0
void FTextureManager::InitSwitchList ()
{
	const BITFIELD texflags = TEXMAN_Overridable | TEXMAN_TryAny;
	int lump = Wads.CheckNumForName ("SWITCHES");

	if (lump != -1)
	{
		FMemLump lumpdata = Wads.ReadLump (lump);
		const char *alphSwitchList = (const char *)lumpdata.GetMem();
		const char *list_p;
		FSwitchDef *def1, *def2;

		for (list_p = alphSwitchList; list_p[18] || list_p[19]; list_p += 20)
		{
			// [RH] Check for switches that aren't really switches
			if (stricmp (list_p, list_p+9) == 0)
			{
				Printf ("Switch %s in SWITCHES has the same 'on' state\n", list_p);
				continue;
			}
			// [RH] Skip this switch if its textures can't be found.
			if (CheckForTexture (list_p /* .name1 */, FTexture::TEX_Wall, texflags).Exists() &&
				CheckForTexture (list_p + 9 /* .name2 */, FTexture::TEX_Wall, texflags).Exists())
			{
				def1 = (FSwitchDef *)M_Malloc (sizeof(FSwitchDef));
				def2 = (FSwitchDef *)M_Malloc (sizeof(FSwitchDef));
				def1->PreTexture = def2->frames[0].Texture = CheckForTexture (list_p /* .name1 */, FTexture::TEX_Wall, texflags);
				def2->PreTexture = def1->frames[0].Texture = CheckForTexture (list_p + 9, FTexture::TEX_Wall, texflags);
				def1->Sound = def2->Sound = 0;
				def1->NumFrames = def2->NumFrames = 1;
				def1->frames[0].TimeMin = def2->frames[0].TimeMin = 0;
				def1->frames[0].TimeRnd = def2->frames[0].TimeRnd = 0;
				AddSwitchPair(def1, def2);
			}
		}
	}

	mSwitchDefs.ShrinkToFit ();
	qsort (&mSwitchDefs[0], mSwitchDefs.Size(), sizeof(FSwitchDef *), SortSwitchDefs);
}
Пример #19
0
// =============================================================================
// 功能:在SPI总线结点上增加器件,即总线上挂接的器件,并初始化器件所对应的参数配置寄
//       存器,该器件属于总线结点的子结点
// 参数:BusName,新增子器件挂接的总线名称
//       DevName,器件名称
//       cs,该器件所属的片选序号
//       charlen,器件的字符长度,比特位数
//       mode,配置从器件模式,CHPA和CPOL组合成成的模式
//       freq,SPI总线的时钟频率,单位Hz
//       autocs,新增加设备是否自动片选
// 返回:控制块结点指针,添加失败时返回NULL
// =============================================================================
struct tagSPI_Device *SPI_DevAdd(char *BusName ,char *DevName,u8 cs,u8 charlen,
                                u8 mode,u8 shiftdir,u32 freq,u8 autocs)
{
    struct tagSPI_CB      *SPI;
    struct tagSPI_Device *NewDev;
    tagSpiConfig spicfg;

    //查询是否该总线存在
    SPI = SPI_BusFind(BusName);
    if(NULL == SPI)
        return NULL;

    //避免建立同名的SPI器件
    if(NULL != Rsc_SearchSon(&SPI->SPI_BusNode,DevName))
        return NULL;

    //为新的器件结点动态分配内存
    NewDev = (struct tagSPI_Device *)M_Malloc(sizeof(struct tagSPI_Device),0);
    if(NULL == NewDev)
        return NULL;

    //为新结点初始化
    NewDev->Cs  = cs;
    Rsc_AddSon(&SPI->SPI_BusNode,&NewDev->DevNode,
                sizeof(struct tagSPI_Device),RSC_SPI_DEVICE,DevName);
    if(NULL == &NewDev->DevNode)
    {
        free(NewDev);
        return NULL;
    }

    NewDev->CharLen    = charlen;
    NewDev->Cs         = cs;
    NewDev->AutoCs     = autocs;
    NewDev->Mode       = mode;
    NewDev->Freq       = freq;
    NewDev->ShiftDir   = shiftdir;

    spicfg.CharLen = charlen;
    spicfg.Mode    = mode;
    spicfg.Freq    = freq;
    spicfg.ShiftDir= shiftdir;

    //如果SPI控制器有多套CS寄存器,则配置它,否则不作配置
    if(true == SPI->MultiCsReg)
    {
        SPI_BusCtrl(NewDev,CN_SPI_CS_CONFIG,(ptu32_t)cs,(ptu32_t)&spicfg);
    }

    printk("SPI Device %s Added Succeeded!\r\n",DevName);
    return NewDev;
}
Пример #20
0
void R_3D_AddHeight(secplane_t *add, sector_t *sec)
{
	HeightLevel *near;
	HeightLevel *curr;

	double height = add->ZatPoint(ViewPos);
	if(height >= sec->CenterCeiling()) return;
	if(height <= sec->CenterFloor()) return;

	fakeActive = 1;

	if(height_max >= 0) {
		near = height_top;
		while(near && near->height < height) near = near->next;
		if(near) {
			if(near->height == height) return;
			curr = (HeightLevel*)M_Malloc(sizeof(HeightLevel));
			curr->height = height;
			curr->prev = near->prev;
			curr->next = near;
			if(near->prev) near->prev->next = curr;
			else height_top = curr;
			near->prev = curr;
		} else {
			curr = (HeightLevel*)M_Malloc(sizeof(HeightLevel));
			curr->height = height;
			curr->prev = height_cur;
			curr->next = NULL;
			height_cur->next = curr;
			height_cur = curr;
		}
	} else {
		height_top = height_cur = (HeightLevel*)M_Malloc(sizeof(HeightLevel));
		height_top->height = height;
		height_top->prev = NULL;
		height_top->next = NULL;
	}
	height_max++;
}
Пример #21
0
// Fix for certain special patches on single-patch textures.
void FPatchTexture::HackHack (int newheight)
{
	BYTE *out;
	int x;

	Unload ();
	if (Spans != NULL)
	{
		FreeSpans (Spans);
	}

	{
		FMemLump lump = Wads.ReadLump (SourceLump);
		const patch_t *patch = (const patch_t *)lump.GetMem();

		Width = LittleShort(patch->width);
		Height = newheight;
		LeftOffset = 0;
		TopOffset = 0;

		Pixels = new BYTE[Width * Height];

		// Draw the image to the buffer
		for (x = 0, out = Pixels; x < Width; ++x)
		{
			const BYTE *in = (const BYTE *)patch + LittleLong(patch->columnofs[x]) + 3;

			for (int y = newheight; y > 0; --y)
			{
				*out = *in != 255 ? *in : Near255;
				out++, in++;
			}
			out += newheight;
		}
	}

	// Create the spans
	Spans = (Span **)M_Malloc (sizeof(Span *)*Width + sizeof(Span)*Width*2);

	Span *span = (Span *)&Spans[Width];

	for (x = 0; x < Width; ++x)
	{
		Spans[x] = span;
		span[0].Length = newheight;
		span[0].TopOffset = 0;
		span[1].Length = 0;
		span[1].TopOffset = 0;
		span += 2;
	}
}
Пример #22
0
// =============================================================================
// 函数功能:看门狗模块的初始化
// 输入参数:
// 输出参数:
// 返回值  :1成功  0失败
// 说明    :创建看门狗硬件对应的软看门狗。注册看门狗异常信息解析器
// =============================================================================
ptu32_t ModuleInstall_Wdt(ptu32_t para)
{
    bool_t  result_bool;
    u16     evttid;

    g_ptWdtPool = M_Malloc(gc_u32CfgWdtLimit * sizeof(tagWdt),0);
    if(g_ptWdtPool == NULL)
        return 0;
    ptWdtPool = Mb_CreatePool(g_ptWdtPool,gc_u32CfgWdtLimit,sizeof(tagWdt),0,0,"wdt pool");
    //init the queue
    ptWdtHead = NULL;
    ptWdtTail = NULL;
    ptWdtHard = NULL;

    //create the msg box for the api to snd msg to the wdt service task
    ptWdtMsgBox = MsgQ_Create(CN_WDTMSG_LIMIT,sizeof(tagWdtMsg),CN_MSGQ_TYPE_FIFO);

    //create the main service
    evttid = Djy_EvttRegist(EN_CORRELATIVE,CN_PRIO_WDT,0,0,Wdt_Service,
                                NULL,0x1000,"wdt service");
    if(evttid == CN_EVTT_ID_INVALID)
        return 0;
    if( Djy_EventPop(evttid,NULL,0,0,0,0) == CN_EVENT_ID_INVALID)
    {
        printk("WDT MODULE:POP SERVICE FAILED!\n\r");
        Djy_EvttUnregist(evttid);
        return 0;
    }

    //create the soft wdt match the hard wdt
    struct tagWdtHalChipInfo hardpara;
    result_bool = WdtHal_GetChipPara(&hardpara);
    if(true == result_bool)//存在硬件看门狗,则创建硬件看门狗
    {
        fnWdtHardFeed = hardpara.wdtchip_feed;
        ptWdtHard = Wdt_Create(hardpara.wdtchip_name,\
                               hardpara.wdtchip_cycle,\
                               __Wdt_HardWdtYipHook,\
                               EN_EXP_DEAL_IGNORE, NULL);
    }
//todo:此处有警告
    extern bool_t Exp_RegisterThrowinfoDecoder(fnExp_ThrowinfoDecoderModule decoder,const char *name);
    if(false ==Exp_RegisterThrowinfoDecoder(__Wdt_WdtExpInfoDecoder,\
                                            CN_WDT_EXPDECODERNAME))
    {
        printk("WDT MODULE: Register Wdt Exp Decoder Failed!\n\r");
    }

    printk("WDT MODULE:Init end ...\n\r");
    return 1;
}
Пример #23
0
/**
 * Create a new memory volume.  The new volume is added to the list of
 * memory volumes.
 */
static memvolume_t *createVolume(size_t volumeSize)
{
    memblock_t     *block;
    memvolume_t    *vol = M_Calloc(sizeof(memvolume_t));

    lockZone();

    // Append to the end of the volume list.
    if (volumeLast)
        volumeLast->next = vol;
    volumeLast = vol;
    vol->next = 0;
    if (!volumeRoot)
        volumeRoot = vol;

    // Allocate memory for the zone volume.
    vol->size = volumeSize;
    vol->zone = M_Malloc(vol->size);
    vol->allocatedBytes = 0;

    // Clear the start of the zone.
    memset(vol->zone, 0, sizeof(memzone_t) + sizeof(memblock_t));
    vol->zone->size = vol->size;

    // Set the entire zone to one free block.
    vol->zone->blockList.next
        = vol->zone->blockList.prev
        = block
        = (memblock_t *) ((byte *) vol->zone + sizeof(memzone_t));

    vol->zone->blockList.user = (void *) vol->zone;
    vol->zone->blockList.volume = vol;
    vol->zone->blockList.tag = PU_APPSTATIC;
    vol->zone->rover = vol->zone->staticRover = block;

    block->prev = block->next = &vol->zone->blockList;
    block->user = NULL;         // free block
    block->seqFirst = block->seqLast = NULL;
    block->size = vol->zone->size - sizeof(memzone_t);

    unlockZone();

    App_Log(DE2_LOG_MESSAGE,
            "Created a new %.1f MB memory volume.", vol->size / 1024.0 / 1024.0);

    Z_CheckHeap();

    return vol;
}
Пример #24
0
FName::NameManager::NameBlock *FName::NameManager::AddBlock (size_t len)
{
	NameBlock *block;

	len += sizeof(NameBlock);
	if (len < BLOCK_SIZE)
	{
		len = BLOCK_SIZE;
	}
	block = (NameBlock *)M_Malloc (len);
	block->NextAlloc = sizeof(NameBlock);
	block->NextBlock = Blocks;
	Blocks = block;
	return block;
}
Пример #25
0
// Create a new object that this class represents
DObject *PClass::CreateNew () const
{
	BYTE *mem = (BYTE *)M_Malloc (Size);
	assert (mem != NULL);

	// Set this object's defaults before constructing it.
	if (Defaults != NULL)
		memcpy (mem, Defaults, Size);
	else
		memset (mem, 0, Size);

	ConstructNative (mem);
	((DObject *)mem)->SetClass (const_cast<PClass *>(this));
	return (DObject *)mem;
}
Пример #26
0
void FTextureManager::AddSimpleAnim (FTextureID picnum, int animcount, int animtype, DWORD speedmin, DWORD speedrange)
{
	if (AreTexturesCompatible(picnum, picnum + (animcount - 1)))
	{
		FAnimDef *anim = (FAnimDef *)M_Malloc (sizeof(FAnimDef));
		anim->CurFrame = 0;
		anim->BasePic = picnum;
		anim->NumFrames = animcount;
		anim->AnimType = animtype;
		anim->SwitchTime = 0;
		anim->Frames[0].SpeedMin = speedmin;
		anim->Frames[0].SpeedRange = speedrange;
		anim->Frames[0].FramePic = anim->BasePic;
		AddAnim (anim);
	}
}
Пример #27
0
ddstring_t *Str_Set(ddstring_t *str, char const *text)
{
    DENG_ASSERT(str);
    if(!str) return 0;

    {
    size_t incoming = strlen(text);
    char *copied = M_Malloc(incoming + 1); // take a copy in case text points to (a part of) str->str
    strcpy(copied, text);
    allocateString(str, incoming, false);
    strcpy(str->str, copied);
    str->length = incoming;
    M_Free(copied);
    return str;
    }
}
Пример #28
0
// =============================================================================
// 功能:在DjyBus总线树结点上增加新的总线类型结点,新增总线类型结点是DjyBus的子结点,
//       使用内存池分配的方式分配内存
// 参数:NewBusTypeName,总线类型名称
// 返回:返回建立的资源结点指针,失败时返回NULL
// =============================================================================
struct tagRscNode * DjyBus_BusTypeAdd (char* NewBusTypeName)
{
    struct tagRscNode * NewBusType;

    NewBusType = (struct tagRscNode *)M_Malloc(sizeof(struct tagRscNode),0);
    if(NewBusType == NULL)
        return NULL;

    //避免重复创建同名的总线类型
    if(NULL != Rsc_SearchSon(&tg_djybus_root,NewBusTypeName))
        return NULL;

    Rsc_AddSon(&tg_djybus_root,NewBusType,
                sizeof(struct tagRscNode),RSC_RSCNODE,NewBusTypeName);

    return NewBusType;
}
Пример #29
0
void PClassActor::InitializeNativeDefaults()
{
	Symbols.SetParentTable(&ParentClass->Symbols);
	assert(Defaults == NULL);
	Defaults = (BYTE *)M_Malloc(Size);
	if (ParentClass->Defaults != NULL) 
	{
		memcpy(Defaults, ParentClass->Defaults, ParentClass->Size);
		if (Size > ParentClass->Size)
		{
			memset(Defaults + ParentClass->Size, 0, Size - ParentClass->Size);
		}
	}
	else
	{
		memset (Defaults, 0, Size);
	}
}
Пример #30
0
FAnimDef *FTextureManager::AddSimpleAnim (FTextureID picnum, int animcount, DWORD speedmin, DWORD speedrange)
{
	if (AreTexturesCompatible(picnum, picnum + (animcount - 1)))
	{
		FAnimDef *anim = (FAnimDef *)M_Malloc (sizeof(FAnimDef));
		anim->CurFrame = 0;
		anim->BasePic = picnum;
		anim->NumFrames = animcount;
		anim->AnimType = FAnimDef::ANIM_Forward;
		anim->bDiscrete = false;
		anim->SwitchTime = 0;
		anim->Frames[0].SpeedMin = speedmin;
		anim->Frames[0].SpeedRange = speedrange;
		anim->Frames[0].FramePic = anim->BasePic;
		return AddAnim (anim);
	}
	return NULL;
}