📄 level.cpp
字号:
if (SkyFaces[i].TextureName != NULL)
{
StringToQuote = SkyFaces[i].TextureName;
}
Util_QuoteString (StringToQuote, QuotedValue);
if (fprintf (ArFile, "%d %s\n", SkyFaces[i].Apply, QuotedValue) < 0) return GE_FALSE;
}
// Write rotation axis and speed
if (fprintf (ArFile, "Axis %f %f %f\n", Axis->X, Axis->Y, Axis->Z) < 0) return GE_FALSE;
if (fprintf (ArFile, "Speed %f\n", Speed) < 0) return GE_FALSE;
if (fprintf (ArFile, "Scale %f\n", Scale) < 0) return GE_FALSE;
return GE_TRUE;
}
static geBoolean Level_WriteCompileInfo
(
const CompileParamsType *pParms,
FILE *ArFile
)
{
char QuotedString[MAX_PATH];
const LightParms *pLight;
const VisParms *pVis;
const BspParms *pBsp;
if (fprintf (ArFile, "%s\n", "CompileInfo") < 0) return GE_FALSE;
Util_QuoteString (pParms->Filename, QuotedString);
if (fprintf (ArFile, "Filename %s\n", QuotedString) < 0) return GE_FALSE;
if (fprintf (ArFile, "Vis %d\n", pParms->DoVis) < 0) return GE_FALSE;
if (fprintf (ArFile, "Light %d\n", pParms->DoLight) < 0) return GE_FALSE;
if (fprintf (ArFile, "Bsp %d\n", pParms->RunBsp) < 0) return GE_FALSE;
if (fprintf (ArFile, "Preview %d\n", pParms->RunPreview) < 0) return GE_FALSE;
if (fprintf (ArFile, "MinLight %d\n", pParms->UseMinLight) < 0) return GE_FALSE;
if (fprintf (ArFile, "SuppressHidden %d\n", pParms->SuppressHidden) < 0) return GE_FALSE;
if (fprintf (ArFile, "EntitiesOnly %d\n", pParms->EntitiesOnly) < 0) return GE_FALSE;
if (fprintf (ArFile, "VisDetail %d\n", pParms->VisDetailBrushes) < 0) return GE_FALSE;
// light params
pLight = &(pParms->Light);
if (fprintf (ArFile, "Verbose %d\n", pLight->Verbose) < 0) return GE_FALSE;
if (fprintf (ArFile, "ExtraSamples %d\n", pLight->ExtraSamples) < 0) return GE_FALSE;
if (fprintf (ArFile, "LightScale %f\n", pLight->LightScale) < 0) return GE_FALSE;
if (fprintf (ArFile, "Radiosity %d\n", pLight->Radiosity) < 0) return GE_FALSE;
if (fprintf (ArFile, "NumBounce %d\n", pLight->NumBounce) < 0) return GE_FALSE;
if (fprintf (ArFile, "PatchSize %f\n", pLight->PatchSize) < 0) return GE_FALSE;
if (fprintf (ArFile, "FastPatch %d\n", pLight->FastPatch) < 0) return GE_FALSE;
if (fprintf (ArFile, "ReflectScale %f\n", pLight->ReflectiveScale) < 0) return GE_FALSE;
if (fprintf (ArFile, "MinLight %f %f %f\n", pLight->MinLight.X, pLight->MinLight.Y, pLight->MinLight.Z) < 0) return GE_FALSE;
// vis params
pVis = &(pParms->Vis);
if (fprintf (ArFile, "VisVerbose %d\n", pVis->Verbose) < 0) return GE_FALSE;
if (fprintf (ArFile, "FullVis %d\n", pVis->FullVis) < 0) return GE_FALSE;
if (fprintf (ArFile, "SortPortals %d\n", pVis->SortPortals) < 0) return GE_FALSE;
// Bsp Params
pBsp = &(pParms->Bsp);
if (fprintf (ArFile, "BspVerbose %d\n", pBsp->Verbose) < 0) return GE_FALSE;
if (fprintf (ArFile, "EntityVerbose %d\n", pBsp->EntityVerbose) < 0) return GE_FALSE;
return GE_TRUE;
}
static geBoolean Level_WriteGridInfo
(
const GridInfo *pGridInfo,
FILE *ArFile
)
{
if (fprintf (ArFile, "Grid %d\n", pGridInfo->UseGrid) < 0) return GE_FALSE;
if (fprintf (ArFile, "Type %d\n", pGridInfo->GridType) < 0) return GE_FALSE;
if (fprintf (ArFile, "Snap %d\n", pGridInfo->SnapType) < 0) return GE_FALSE;
if (fprintf (ArFile, "Metric %d\n", pGridInfo->MetricSnapSize) < 0) return GE_FALSE;
if (fprintf (ArFile, "Texel %d\n", pGridInfo->TexelSnapSize) < 0) return GE_FALSE;
if (fprintf (ArFile, "Rotation %d\n", pGridInfo->RotationSnap) < 0) return GE_FALSE;
return GE_TRUE;
}
static geBoolean Level_WriteOneView
(
const ViewStateInfo *pViewInfo,
const char *ViewName,
FILE *f
)
{
if (fprintf (f, "%s %d\n", ViewName, pViewInfo->IsValid) < 0) return GE_FALSE;
if (fprintf (f, "Zoom %f\n", pViewInfo->ZoomFactor) < 0) return GE_FALSE;
if (fprintf (f, "PitchRollYaw %f %f %f\n", pViewInfo->PitchRollYaw.X, pViewInfo->PitchRollYaw.Y, pViewInfo->PitchRollYaw.Z) < 0) return GE_FALSE;
if (fprintf (f, "CamPos %f %f %f\n", pViewInfo->CameraPos.X, pViewInfo->CameraPos.Y, pViewInfo->CameraPos.Z) < 0) return GE_FALSE;
return GE_TRUE;
}
static geBoolean Level_WriteViewInfo
(
const ViewStateInfo pViewInfo[],
FILE *ArFile
)
{
int iView;
for (iView = 0; iView < NUM_VIEWS; iView++)
{
if (!Level_WriteOneView (&pViewInfo[iView], ViewNames[iView], ArFile)) return GE_FALSE;
}
return GE_TRUE;
}
static geBoolean Level_WriteBrushTemplates
(
const Level *pLevel,
FILE *f
)
{
if (BrushTemplate_WriteArch (&pLevel->ArchTemplate, f) == GE_FALSE) return GE_FALSE;
if (BrushTemplate_WriteBox (&pLevel->BoxTemplate, f) == GE_FALSE) return GE_FALSE;
if (BrushTemplate_WriteCone (&pLevel->ConeTemplate, f) == GE_FALSE) return GE_FALSE;
if (BrushTemplate_WriteCylinder (&pLevel->CylinderTemplate, f) == GE_FALSE) return GE_FALSE;
if (BrushTemplate_WriteSpheroid (&pLevel->SpheroidTemplate, f) == GE_FALSE) return GE_FALSE;
if (BrushTemplate_WriteStaircase (&pLevel->StaircaseTemplate, f) == GE_FALSE) return GE_FALSE;
return GE_TRUE;
}
geBoolean Level_WriteToFile (Level *pLevel, const char *Filename)
{
FILE *ArFile;
char QuotedString[MAX_PATH];
geBoolean WriteRslt;
assert (pLevel != NULL);
assert (Filename != NULL);
// error checking required!
ArFile = fopen(Filename, "wt");
if (ArFile == NULL)
{
return GE_FALSE;
}
WriteRslt = GE_FALSE;
if (fprintf(ArFile, "3dtVersion %d.%d\n", LEVEL_VERSION_MAJOR, LEVEL_VERSION_MINOR) < 0) goto WriteDone;
Util_QuoteString (pLevel->WadPath, QuotedString);
if (fprintf(ArFile, "TextureLib %s\n", QuotedString) < 0) goto WriteDone;
Util_QuoteString (pLevel->HeadersDir, QuotedString);
if (fprintf (ArFile, "HeadersDir %s\n", QuotedString) < 0) goto WriteDone;
if (fprintf(ArFile, "NumEntities %d\n", pLevel->Entities->GetSize ()) < 0) goto WriteDone;
if (fprintf(ArFile, "NumModels %d\n", ModelList_GetCount (pLevel->ModelInfo.Models)) < 0) goto WriteDone;
if (fprintf(ArFile, "NumGroups %d\n", Group_GetCount (pLevel->Groups)) < 0) goto WriteDone;
if (BrushList_Write (pLevel->Brushes, ArFile) == GE_FALSE) goto WriteDone;
if (Level_SaveEntities (pLevel->Entities, ArFile) == GE_FALSE) goto WriteDone;
if (ModelList_Write (pLevel->ModelInfo.Models, ArFile) == GE_FALSE) goto WriteDone;
if (Group_WriteList (pLevel->Groups, ArFile) == GE_FALSE) goto WriteDone;
if (Level_WriteSky (pLevel->SkyFaces, &pLevel->SkyRotationAxis, pLevel->SkyRotationSpeed, pLevel->SkyTextureScale, ArFile) == GE_FALSE) goto WriteDone;
if (Level_WriteCompileInfo (&pLevel->CompileParams, ArFile) == GE_FALSE) goto WriteDone;
if (fprintf (ArFile, "ShowGroups %d\n", pLevel->GroupVisSetting) < 0) goto WriteDone;
if (EntityViewList_WriteToFile (pLevel->pEntityView, ArFile) == GE_FALSE) goto WriteDone;
if (Level_WriteGridInfo (&pLevel->GridSettings, ArFile) == GE_FALSE) goto WriteDone;
if (fprintf (ArFile, "BspRebuild %d\n", pLevel->BspRebuildFlag) < 0) goto WriteDone;
if (Level_WriteViewInfo (pLevel->ViewInfo, ArFile) == GE_FALSE) goto WriteDone;
if (Level_WriteBrushTemplates (pLevel, ArFile) == GE_FALSE) goto WriteDone;
if (fprintf (ArFile, "TemplatePos %f %f %f\n", pLevel->TemplatePos.X, pLevel->TemplatePos.Y, pLevel->TemplatePos.Z) < 0) goto WriteDone;
// level options
if (fprintf (ArFile, "DrawScale %f\n", pLevel->DrawScale) < 0) goto WriteDone;
if (fprintf (ArFile, "LightmapScale %f\n", pLevel->LightmapScale) < 0) goto WriteDone;
WriteRslt = GE_TRUE;
WriteDone:
if (fclose(ArFile) != 0) return GE_FALSE;
return GE_TRUE ;
}
CEntityArray *Level_GetEntities (Level *pLevel)
{
return pLevel->Entities;
}
BrushList *Level_GetBrushes (Level *pLevel)
{
return pLevel->Brushes;
}
SkyFaceTexture *Level_GetSkyInfo (Level *pLevel, geVec3d *Axis, geFloat *Speed, geFloat *Scale)
{
*Axis = pLevel->SkyRotationAxis;
*Speed = pLevel->SkyRotationSpeed;
*Scale = pLevel->SkyTextureScale;
return pLevel->SkyFaces;
}
void Level_SetSkyRotationAxis (Level *pLevel, const geVec3d *Axis)
{
pLevel->SkyRotationAxis = *Axis;
}
void Level_SetSkyRotationSpeed (Level *pLevel, const geFloat Speed)
{
pLevel->SkyRotationSpeed = Speed;
}
void Level_SetSkyTextureScale (Level *pLevel, const geFloat Scale)
{
pLevel->SkyTextureScale = Scale;
}
ModelInfo_Type *Level_GetModelInfo (Level *pLevel)
{
assert (pLevel != NULL);
return &(pLevel->ModelInfo);
}
Model *Level_GetModel (Level *pLevel, int ModelId)
{
return ModelList_FindById (pLevel->ModelInfo.Models, ModelId);
}
void Level_AddModel (Level *pLevel, Model *pModel)
{
ModelList_AddModel (pLevel->ModelInfo.Models, pModel);
}
GroupListType *Level_GetGroups (Level *pLevel)
{
assert (pLevel != NULL);
return pLevel->Groups;
}
Group *Level_GetGroup (Level *pLevel, int GroupId)
{
assert (pLevel != NULL);
return GroupList_GetFromId (pLevel->Groups, GroupId);
}
void Level_AddGroup (Level *pLevel, Group *pGroup)
{
GroupList_Add (pLevel->Groups, pGroup);
}
const char *Level_GetWadPath (const Level *pLevel)
{
assert (pLevel != NULL);
return (pLevel->WadPath);
}
void Level_SetWadPath (Level *pLevel, const char *NewWad)
{
if (pLevel->WadPath != NULL)
{
geRam_Free (pLevel->WadPath);
}
pLevel->WadPath = Util_Strdup (NewWad);
}
SizeInfo *Level_GetWadSizeInfos (Level *pLevel)
{
assert (pLevel != NULL);
return pLevel->WadSizeInfos;
}
CWadFile *Level_GetWadFile (Level *pLevel)
{
return pLevel->WadFile;
}
int Level_AddEntity (Level *pLevel, CEntity &Entity)
{
assert (pLevel != NULL);
Level_AssignEntityName (pLevel, &Entity);
return pLevel->Entities->Add (Entity);
}
void Level_AppendBrush (Level *pLevel, Brush *pBrush)
{
assert (pLevel != NULL);
assert (pBrush != NULL);
BrushList_Append (pLevel->Brushes, pBrush);
}
void Level_RemoveBrush (Level *pLevel, Brush *pBrush)
{
assert (pLevel != NULL);
assert (pBrush != NULL);
BrushList_Remove (pLevel->Brushes, pBrush);
}
int Level_EnumEntities (Level *pLevel, void *lParam, EntityList_CB Callback)
{
assert (pLevel != NULL);
return EntityList_Enum (*(pLevel->Entities), lParam, Callback);
}
int Level_EnumBrushes (Level *pLevel, void *lParam, BrushList_CB Callback)
{
return BrushList_Enum (pLevel->Brushes, lParam, Callback);
}
int Level_EnumAllBrushes (Level *pLevel, void *lParam, BrushList_CB Callback)
{
return BrushList_EnumAll (pLevel->Brushes, lParam, Callback);
}
int Level_EnumLeafBrushes (Level *pLevel, void *lParam, BrushList_CB Callback)
{
return BrushList_EnumLeafBrushes (pLevel->Brushes, lParam, Callback);
}
void Level_TranslateAll (Level *pLevel, const geVec3d *VecXlate)
{
int i;
CEntityArray *Entities;
assert (pLevel != NULL);
// move all brushes
BrushList_Move (pLevel->Brushes, VecXlate);
// and entities
Entities = pLevel->Entities;
for (i = 0; i < Entities->GetSize (); ++i)
{
(*Entities)[i].Move (VecXlate);
}
// update the models' origins
{
Model *pModel;
ModelIterator mi;
pModel = ModelList_GetFirst (pLevel->ModelInfo.Models, &mi);
while (pModel != NULL)
{
Model_UpdateOrigin (pModel, BRUSH_MOVE, VecXlate);
pModel = ModelList_GetNext (pLevel->ModelInfo.Models, &mi);
}
}
}
void Level_CollapseGroups (Level *pLevel, int StartingGroup)
{
assert (pLevel != NULL);
GroupList_Collapse (pLevel->Groups, StartingGroup, pLevel->Brushes, pLevel->Entities);
}
void Level_CollapseModels (Level *pLevel, int StartingModel)
{
assert (pLevel != NULL);
ModelList_Collapse (pLevel->ModelInfo.Models, StartingModel, pLevel->Brushes);
}
float Level_GetGridSnapSize (const Level *pLevel)
{
const GridInfo *pGridInfo = &pLevel->GridSettings;
switch (pGridInfo->SnapType)
{
case GridMetric :
return CENTIMETERS_TO_ENGINE (pGridInfo->MetricSnapSize);
break;
default :
assert (0);
case GridTexel :
return (float)pGridInfo->TexelSnapSize;
break;
}
}
int Level_GetRotationSnap (const Level *pLevel)
{
return pLevel->GridSettings.RotationSnap;
}
int Level_GetGridType (const Level *pLevel)
{
return pLevel->GridSettings.GridType;
}
geBoolean Level_UseGrid (const Level *pLevel)
{
return pLevel->GridSettings.UseGrid;
}
GridInfo *Level_GetGridInfo (Level *pLevel)
{
return &pLevel->GridSettings;
}
geBoolean Level_RebuildBspAlways (const Level *pLevel)
{
return pLevel->BspRebuildFlag;
}
void Level_SetBspRebuild (Level *pLevel, geBoolean RebuildFlag)
{
pLevel->BspRebuildFlag = RebuildFlag;
}
ViewStateInfo *Level_GetViewStateInfo (Level *pLevel, int iView)
{
assert (iView >= 0);
assert (iView < 4);
return &pLevel->ViewInfo[iView];
}
BrushTemplate_Arch *Level_GetArchTemplate (Level *pLevel)
{
return &pLevel->ArchTemplate;
}
BrushTemplate_Box *Level_GetBoxTemplate (Level *pLevel)
{
return &pLevel->BoxTemplate;
}
BrushTemplate_Cone *Level_GetConeTemplate (Level *pLevel)
{
return &pLevel->ConeTemplate;
}
BrushTemplate_Cylinder *Level_GetCylinderTemplate (Level *pLevel)
{
return &pLevel->CylinderTemplate;
}
BrushTemplate_Spheroid *Level_GetSpheroidTemplate (Level *pLevel)
{
return &pLevel->SpheroidTemplate;
}
BrushTemplate_Staircase *Level_GetStaircaseTemplate (Level *pLevel)
{
return &pLevel->StaircaseTemplate;
}
geVec3d *Level_GetTemplatePos (Level *pLevel)
{
return &pLevel->TemplatePos;
}
float Level_GetDrawScale (const Level *pLevel)
{
return pLevel->DrawScale;
}
float Level_GetLightmapScale (const Level *pLevel)
{
return pLevel->LightmapScale;
}
void Level_SetDrawScale (Level *pLevel, float Scale)
{
pLevel->DrawScale = Scale;
}
void Level_SetLightmapScale (Level *pLevel, float Scale)
{
pLevel->LightmapScale = Scale;
}
const char *Level_GetHeadersDirectory (const Level *pLevel)
{
return pLevel->HeadersDir;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -