⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 brush.cpp

📁 3D游戏场景编辑器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	assert(b != NULL);
	assert (newname != NULL);

	//empty names ok?  should I check?  Should I assert?
	if (b->Name != NULL)
	{
		geRam_Free (b->Name);
	}

	b->Name	=Util_Strdup(newname);
	if (b->BList != NULL)
	{
		geRam_Free 	(b->BList->First->Name);
		geRam_Free 	(b->BList->Last->Name);

		//	these additions are necessary so that GetCursorInfo will display
		//	the correct brush name on the status bar.
		b->BList->First->Name = Util_Strdup(newname);	//	post 0.5 release
		b->BList->Last->Name = Util_Strdup(newname);	//	post 0.5 release
	}

}

geBoolean	Brush_IsSolid(const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsSolid", MB_OK);	//	post 0.55

	assert(b != NULL);
	
	return	(b->Flags & BRUSH_SOLID)?	GE_TRUE : GE_FALSE;
}

geBoolean	Brush_IsWindow(const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsWindow", MB_OK);	//	post 0.55

	assert(b != NULL);
	
	return	(b->Flags & BRUSH_WINDOW)?	GE_TRUE : GE_FALSE;
}

geBoolean	Brush_IsWavy(const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsWavy", MB_OK);	//	post 0.55

	assert(b != NULL);
	
	return	(b->Flags & BRUSH_WAVY)?	GE_TRUE : GE_FALSE;
}

geBoolean	Brush_IsDetail(const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsDetail", MB_OK);	//	post 0.55

	assert(b != NULL);
	
	return	(b->Flags & BRUSH_DETAIL)?	GE_TRUE : GE_FALSE;
}

geBoolean	Brush_IsSubtract(const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsSubtract", MB_OK);	//	post 0.55

	assert(b != NULL);
	
	return	(b->Flags & BRUSH_SUBTRACT)?	GE_TRUE : GE_FALSE;
}

geBoolean	Brush_IsClip(const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsClip", MB_OK);	//	post 0.55

	assert(b != NULL);
	
	return	(b->Flags & BRUSH_CLIP)?	GE_TRUE : GE_FALSE;
}

geBoolean	Brush_IsHollow(const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsHollow", MB_OK);	//	post 0.55

	assert(b != NULL);

	return	(b->Flags & BRUSH_HOLLOW)?	GE_TRUE : GE_FALSE;
}

geBoolean	Brush_IsHollowCut(const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsHollowCut", MB_OK);	//	post 0.55

	assert(b != NULL);

	return	(b->Flags & BRUSH_HOLLOWCUT)?	GE_TRUE : GE_FALSE;
}

geBoolean	Brush_IsEmpty(const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsEmpty", MB_OK);	//	post 0.55

	assert(b != NULL);
	
	return	(b->Flags & BRUSH_EMPTY)?	GE_TRUE : GE_FALSE;
}

//this one is ! value of flag
geBoolean	Brush_IsVisible(const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsVisible", MB_OK);	//	post 0.55

	assert(b != NULL);
	
	return	(b->Flags & BRUSH_HIDDEN)?	GE_FALSE : GE_TRUE;
}

geBoolean	Brush_IsLocked(const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsLocked", MB_OK);	//	post 0.55

	assert(b != NULL);
	
	return	(b->Flags & BRUSH_LOCKED)?	GE_TRUE : GE_FALSE;
}

geBoolean	Brush_IsHint(const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsHint", MB_OK);	//	post 0.55

	assert(b != NULL);
	
	return	(b->Flags & BRUSH_HINT)?	GE_TRUE : GE_FALSE;
}

geBoolean	Brush_IsArea(const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsArea", MB_OK);	//	post 0.55

	assert(b != NULL);
	
	return	(b->Flags & BRUSH_AREA)?	GE_TRUE : GE_FALSE;
}

geBoolean	Brush_IsTranslucent(const Brush *b)
{

	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsTranslucent", MB_OK);	//	post 0.55

	assert (b != NULL);

	return (b->Flags & BRUSH_TRANSLUCENT) ? GE_TRUE : GE_FALSE;
}

geBoolean	Brush_IsMulti(const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsMulti", MB_OK);	//	post 0.55

	assert (b != NULL);

	return (b->Type == BRUSH_MULTI) ? GE_TRUE : GE_FALSE;
}

geBoolean Brush_IsFlocking (const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsFlocking", MB_OK);	//	post 0.55

	assert (b != NULL);

	return (b->Flags & BRUSH_FLOCKING) ? GE_TRUE : GE_FALSE;
}

geBoolean Brush_IsSheet (const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_IsSheet", MB_OK);	//	post 0.55

	assert (b != NULL);

	return (b->Flags & BRUSH_SHEET) ? GE_TRUE : GE_FALSE;
}

static void Brush_SetExclusiveState (Brush *b, int Mask, geBoolean bState)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetExclusiveState", MB_OK);	//	post 0.55

	if (bState)
	{
		b->Flags &= ~(BRUSH_SOLID | BRUSH_CLIP | BRUSH_WINDOW | BRUSH_HINT | BRUSH_SUBTRACT | BRUSH_EMPTY);
		b->Flags |= Mask;
	}
	else
	{
		b->Flags &= ~Mask;
	}
}

void	Brush_SetSolid(Brush *b, const geBoolean bState)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetSolid", MB_OK);	//	post 0.55

	assert(b != NULL);

	if(b->Type==BRUSH_MULTI)
	{
		BrushList_SetFlag(b->BList, bState, Brush_SetSolid);
	}

	Brush_SetExclusiveState (b, BRUSH_SOLID, bState);
}

void	Brush_SetWindow(Brush *b, const geBoolean bState)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetWindow", MB_OK);	//	post 0.55

	assert(b != NULL);
		
	if(b->Type==BRUSH_MULTI)
	{
		BrushList_SetFlag(b->BList, bState, Brush_SetWindow);
	}

	Brush_SetExclusiveState (b, BRUSH_WINDOW, bState);
}

void	Brush_SetWavy(Brush *b, const geBoolean bState)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetWavy", MB_OK);	//	post 0.55

	assert(b != NULL);
		
	if(b->Type==BRUSH_MULTI)
	{
		BrushList_SetFlag(b->BList, bState, Brush_SetWavy);
	}

	b->Flags	=(bState)? b->Flags|BRUSH_WAVY : b->Flags&~BRUSH_WAVY;
}

void	Brush_SetDetail(Brush *b, const geBoolean bState)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetDetail", MB_OK);	//	post 0.55

	assert(b != NULL);
		
	if(b->Type==BRUSH_MULTI)
	{
		BrushList_SetFlag(b->BList, bState, Brush_SetDetail);
	}

	b->Flags	=(bState)? b->Flags|BRUSH_DETAIL : b->Flags&~BRUSH_DETAIL;
}

void	Brush_SetSubtract(Brush *b, const geBoolean bState)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetSubtract", MB_OK);	//	post 0.55

	assert(b != NULL);

	if(b->Type==BRUSH_MULTI)
	{
		BrushList_SetFlag(b->BList, bState, Brush_SetSubtract);
	}

	if(b->Flags & BRUSH_HOLLOWCUT)
	{
		return;	//can't reset these
	}
	
	Brush_SetExclusiveState (b, BRUSH_SUBTRACT, bState);
}

void	Brush_SetClip(Brush *b, const geBoolean bState)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetClip", MB_OK);	//	post 0.55

	assert(b != NULL);

	if(b->Type==BRUSH_MULTI)
	{
		BrushList_SetFlag(b->BList, bState, Brush_SetClip);
	}
		
	Brush_SetExclusiveState (b, BRUSH_CLIP, bState);
}

void	Brush_SetHollow(Brush *b, const geBoolean bState)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetHollow", MB_OK);	//	post 0.55

	assert(b != NULL);
		
	if(b->Type==BRUSH_MULTI)
	{
		BrushList_SetFlag(b->BList, bState, Brush_SetHollow);
	}
	if(b->Flags & BRUSH_HOLLOWCUT)
	{
		return;	//can't reset these
	}

	b->Flags	=(bState)? b->Flags|BRUSH_HOLLOW : b->Flags&~BRUSH_HOLLOW;
}

void	Brush_SetHollowCut(Brush *b, const geBoolean bState)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetHollowCut", MB_OK);	//	post 0.55

	assert(b != NULL);
	assert(b->Type != BRUSH_MULTI);

	//should set both here... HOLLOWCUT is just a dialog helper		
	b->Flags	=(bState)? b->Flags|BRUSH_HOLLOWCUT : b->Flags&~BRUSH_HOLLOWCUT;
	b->Flags	=(bState)? b->Flags|BRUSH_SUBTRACT : b->Flags&~BRUSH_SUBTRACT;
}

void	Brush_SetFlocking (Brush *b, const geBoolean bState)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetFlocking", MB_OK);	//	post 0.55

	assert (b != NULL);

	b->Flags = (bState) ? b->Flags | BRUSH_FLOCKING : b->Flags & ~BRUSH_FLOCKING;
}

void	Brush_SetSheet (Brush *b, const geBoolean bState)
{
	int		i;
	Face	*f;

	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetSheet", MB_OK);	//	post 0.55

	assert (b != NULL);
	if(b->Type != BRUSH_MULTI)
	{
		b->Flags = (bState) ? b->Flags | BRUSH_SHEET : b->Flags & ~BRUSH_SHEET;

		f	=FaceList_GetFace(b->Faces, 0);
		Face_SetSheet(f, bState);

		for(i=1;i < FaceList_GetNumFaces(b->Faces);i++)
		{
			f	=FaceList_GetFace(b->Faces, i);
			Face_SetVisible(f, !bState);
		}
	}
}

void		Brush_SetUserFlags (Brush *b, unsigned long UserFlags)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetUserFlags", MB_OK);	//	post 0.55

	assert (b != NULL);

	// mask off the lower bits so they don't get modified
	b->Flags = (b->Flags & SYSTEM_FLAGS_MASK) | (UserFlags & USER_FLAGS_MASK);
}

unsigned long Brush_GetUserFlags (const Brush *b)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_GetUserFlags", MB_OK);	//	post 0.55

	assert (b != NULL);

	return (b->Flags & USER_FLAGS_MASK);
}

void	Brush_SetEmpty(Brush *b, const geBoolean bState)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetEmpty", MB_OK);	//	post 0.55

	assert(b != NULL);
		
	if(b->Type==BRUSH_MULTI)
	{
		BrushList_SetFlag(b->BList, bState, Brush_SetEmpty);
	}

	Brush_SetExclusiveState (b, BRUSH_EMPTY, bState);
}

void	Brush_SetHint(Brush *b, const geBoolean bState)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetHint", MB_OK);	//	post 0.55

	assert(b != NULL);
		
	if(b->Type==BRUSH_MULTI)
	{
		BrushList_SetFlag(b->BList, bState, Brush_SetHint);
	}

	Brush_SetExclusiveState (b, BRUSH_HINT, bState);
}

//opposite flag value here... should this affect children?
void	Brush_SetVisible(Brush *b, const geBoolean bState)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetVisible", MB_OK);	//	post 0.55

	assert(b != NULL);
		
	b->Flags	=(bState)? b->Flags&~BRUSH_HIDDEN : b->Flags|BRUSH_HIDDEN;
}

//should this affect child brushes?
void	Brush_SetLocked(Brush *b, const geBoolean bState)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetLocked", MB_OK);	//	post 0.55

	assert(b != NULL);
		
	b->Flags	=(bState)? b->Flags|BRUSH_LOCKED : b->Flags&~BRUSH_LOCKED;
}

void	Brush_SetArea(Brush *b, const geBoolean bState)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetArea", MB_OK);	//	post 0.55

	assert(b != NULL);
		
	if(b->Type==BRUSH_MULTI)
	{
		BrushList_SetFlag(b->BList, bState, Brush_SetArea);
	}

	b->Flags	=(bState)? b->Flags|BRUSH_AREA : b->Flags&~BRUSH_AREA;
}

void	Brush_SetTranslucent(Brush *b, const geBoolean bState)
{
	if (b == NULL)
		MessageBox(NULL, "Brush == NULL", "Brush_SetTranslucent", MB_OK);	//	post 0.55

	assert(b != NULL);
	
	if(b->Type==BRUSH_MULTI)
	{
		BrushList_SetFlag(b->BList, bState, Brush_SetTranslucent);
	}

	b->Flags	=(bState)? b->Flags|BRUSH_TRANSLUCENT : b->Flags&~BRUSH_TRANSLUCENT;
}

//brushes written to gbsplib should be convex
void Brush_WriteToMap(Brush const *b, FILE *ofile, geBoolean VisDetail)
{
	uint32 OutputFlags;

	assert(b != NULL);
	assert(b->Faces != NULL);
	assert(ofile);
	assert(!(b->Flags & BRUSH_HOLLOW));	//only send convex
	assert(!(b->Flags & BRUSH_SUBTRACT));	//only send convex

	// write flags

	// convert flags to output flags expected by GBSPLIB
	OutputFlags = 0;
	if (b->Flags & BRUSH_SOLID)			OutputFlags |= bfSolid;
	if (b->Flags & BRUSH_WINDOW)		OutputFlags |= bfWindow;
	if (b->Flags & BRUSH_WAVY)			OutputFlags |= bfWavy;
	if (b->Flags & BRUSH_DETAIL)		OutputFlags |= bfDetail;
	if (b->Flags & BRUSH_CLIP)			OutputFlags |= bfClip;
	if (b->Flags & BRUSH_HINT)			OutputFlags |= bfHint;
	if (b->Flags & BRUSH_AREA)			OutputFlags |= bfArea;
	if (b->Flags & BRUSH_FLOCKING)		OutputFlags |= bfFlocking;
//	if (b->Flags & BRUSH_TRANSLUCENT)	OutputFlags |= bfTranslucent;
	if (b->Flags & BRUSH_EMPTY)			OutputFlags |= bfEmpty;
	if (b->Flags & BRUSH_SHEET)			OutputFlags |= bfSheet;

	// and do the user flags
	OutputFlags |= (b->Flags & USER_FLAGS_MASK);

	if (VisDetail)
	{
		OutputFlags &= ~bfDetail;
	}

	TypeIO_WriteInt(ofile, OutputFlags);
	FaceList_WriteToMap(b->Faces, ofile);
}

geBoolean Brush_Write(const Brush *b, FILE *ofile)
{
	assert(ofile);
	assert(b);

	if (b->Type == BRUSH_CSG)
	{
		// CSG brushes aren't saved
		return GE_TRUE;
	}

	{
		// make sure we don't output a blank name
		char *Name;
		char QuotedValue[SCANNER_MAXDATA];

		Name = ((b->Name == NULL) || (*b->Name == '\0')) ? "NoName" : b->Name;
		// quote the brush name string...
		Util_QuoteString (Name, QuotedValue);
		if (fprintf (ofile, "Brush %s\n", QuotedValue) < 0) return GE_FALSE;
	}

	if (fprintf(ofile, "\tFlags %d\n",	b->Flags) < 0) return GE_FALSE;
	if (fprintf(ofile, "\tModelId %d\n",b->ModelId) < 0) return GE_FALSE;
	if (fprintf(ofile, "\tGroupId %d\n", b->GroupId) < 0) return GE_FALSE;
	{
		if (b->HullSize < 1.0f)
		{
			((Brush *)b)->HullSize = 1.0f;
		}
		if (fprintf(ofile, "\tHullSize %f\n", b->HullSize) < 0) return GE_FALSE;
	}
	if (fprintf(ofile, "\tType %d\n", b->Type) < 0) return GE_FALSE;

	switch (b->Type)
	{
		case	BRUSH_MULTI:
			return BrushList_Write (b->BList, ofile);

		case	BRUSH_LEAF:
			return FaceList_Write (b->Faces, ofile);

		default :
			assert (0);		// invalid brush type
			break;
	}
	return GE_TRUE;
}

Brush	*Brush_CreateFromFile
	(
	  Parse3dt *Parser, 
	  int VersionMajor, 
	  int VersionMinor, 
	  const char **Expected
	)
{
	FaceList	*fl;
	Brush		*b;
	int			tmpFlags, tmpModelId, tmpGroupId, tmpType, tmpTranslucency;
	geFloat		tmpHullSize;
	BrushList	*blist;
	char		szTemp[_MAX_PATH];

	assert (Parser != NULL);

	b	=NULL;

	if((VersionMajor > 1) || ((VersionMajor == 1) && (VersionMinor >= 24)))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -