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

📄 level.cpp

📁 3D游戏场景编辑器
💻 CPP
📖 第 1 页 / 共 3 页
字号:


geBoolean Level_FaceFixupCallback (Brush *pBrush, void *lParam)
{
	int i;
	Level *pLevel;

	pLevel = (Level *)lParam;
	// set up the dib ids in the brush faces...
	for (i = 0;i < Brush_GetNumFaces(pBrush); i++)
	{
		Face	*f;

		f	=Brush_GetFace(pBrush, i);
		Face_SetTextureDibId(f, Level_GetDibId(pLevel, Face_GetTextureName(f)));
	}
	return GE_TRUE;
}

static void Level_BrushListToTexels(Level *pLevel)
{
	int				i;
	Brush			*cb;
	BrushIterator	bi;
	Face			*f;
	geFloat			uscale, vscale;

	cb = BrushList_GetFirst (pLevel->Brushes, &bi);
	while (cb != NULL)
	{
		for(i=0;i < Brush_GetNumFaces(cb);i++)
		{
			f	=Brush_GetFace(cb, i);
			Face_GetTextureScale(f, &uscale, &vscale);
			Face_SetTextureScale(f, CENTIMETERS_TO_ENGINE(uscale), CENTIMETERS_TO_ENGINE(vscale));
		}
		cb = BrushList_GetNext (&bi);
	}
}

#pragma warning (disable:4100)
static geBoolean Level_LoadSky 
	(
	  Level *pLevel,
	  Parse3dt *Parser, 
	  int VersionMajor, 
	  int VersionMinor, 
	  const char **Expected
	)
{
	int i;
	char BigString[SCANNER_MAXDATA];
	int Apply;
		
	if (!Parse3dt_ScanExpectingText (Parser, (*Expected = "Sky"))) return GE_FALSE;

	for (i = 0; i < 6; ++i)
	{
		*Expected = "Integer";
		if (!Parse3dt_GetInt (Parser, NULL, &Apply)) return GE_FALSE;
		pLevel->SkyFaces[i].Apply = (Apply) ? GE_TRUE : GE_FALSE;

		*Expected = "String";
		if ((VersionMajor == 1) && (VersionMinor < 14))
		{
			// first character of the string is x
			if (!Parse3dt_GetIdentifier (Parser, NULL, BigString)) return GE_FALSE;
			pLevel->SkyFaces[i].TextureName = Util_Strdup (&BigString[1]);
		}
		else
		{
			if (!Parse3dt_GetLiteral (Parser, NULL, BigString)) return GE_FALSE;
			pLevel->SkyFaces[i].TextureName = Util_Strdup (BigString);
		}
	}
	if ((VersionMajor > 1) || ((VersionMajor == 1) && (VersionMinor >= 26)))
	{
		if (!Parse3dt_GetVec3d (Parser, "Axis", &pLevel->SkyRotationAxis)) return GE_FALSE;
		if (!Parse3dt_GetFloat (Parser, "Speed", &pLevel->SkyRotationSpeed)) return GE_FALSE;
	}
	if ((VersionMajor > 1) || ((VersionMajor == 1) && (VersionMinor >= 28)))
	{
		if (!Parse3dt_GetFloat (Parser, "Scale", &pLevel->SkyTextureScale)) return GE_FALSE;
	}
	return GE_TRUE;
}
#pragma warning (default:4100)

#pragma warning (disable:4100)
static geBoolean Level_LoadCompileInfo
	(
	  Level *pLevel,
	  Parse3dt *Parser, 
	  int VersionMajor, 
	  int VersionMinor, 
	  const char **Expected
	)
{
	CompileParamsType *pParms;
	LightParms *pLight;
	VisParms *pVis;
	BspParms *pBsp;

	pParms = &(pLevel->CompileParams);
	if (!Parse3dt_ScanExpectingText (Parser, (*Expected = "CompileInfo"))) return GE_FALSE;
	if (!Parse3dt_GetLiteral (Parser, (*Expected = "Filename"), pParms->Filename)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "Vis"), &pParms->DoVis)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "Light"), &pParms->DoLight)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "Bsp"), &pParms->RunBsp)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "Preview"), &pParms->RunPreview)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "MinLight"), &pParms->UseMinLight)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "SuppressHidden"), &pParms->SuppressHidden)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "EntitiesOnly"), &pParms->EntitiesOnly)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "VisDetail"), &pParms->VisDetailBrushes)) return GE_FALSE;

	// light params
	pLight = &(pParms->Light);
	if (!Parse3dt_GetInt (Parser, (*Expected = "Verbose"), &pLight->Verbose)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "ExtraSamples"), &pLight->ExtraSamples)) return GE_FALSE;
	if (!Parse3dt_GetFloat (Parser, (*Expected = "LightScale"), &pLight->LightScale)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "Radiosity"), &pLight->Radiosity)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "NumBounce"), &pLight->NumBounce)) return GE_FALSE;
	if (!Parse3dt_GetFloat (Parser, (*Expected = "PatchSize"), &pLight->PatchSize)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "FastPatch"), &pLight->FastPatch)) return GE_FALSE;
	if (!Parse3dt_GetFloat (Parser, (*Expected = "ReflectScale"), &pLight->ReflectiveScale)) return GE_FALSE;
	if (!Parse3dt_GetVec3d (Parser, (*Expected = "MinLight"), &pLight->MinLight)) return GE_FALSE;

	// vis params
	pVis = &(pParms->Vis);
	if (!Parse3dt_GetInt (Parser, (*Expected = "VisVerbose"), &pVis->Verbose)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "FullVis"), &pVis->FullVis)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "SortPortals"), &pVis->SortPortals)) return GE_FALSE;

	// Bsp Params
	pBsp = &(pParms->Bsp);
	if (!Parse3dt_GetInt (Parser, (*Expected = "BspVerbose"), &pBsp->Verbose)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "EntityVerbose"), &pBsp->EntityVerbose)) return GE_FALSE;

	return GE_TRUE;
}
#pragma warning (default:4100)

#pragma warning (disable:4100)
static geBoolean Level_LoadGridInfo
	(
	  Level *pLevel,
	  Parse3dt *Parser, 
	  int VersionMajor, 
	  int VersionMinor, 
	  const char **Expected
	)
{
	GridInfo *pGridInfo = &pLevel->GridSettings;

	if (!Parse3dt_GetInt (Parser, (*Expected = "Grid"), &pGridInfo->UseGrid)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "Type"), &pGridInfo->GridType)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "Snap"), &pGridInfo->SnapType)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "Metric"), &pGridInfo->MetricSnapSize)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "Texel"), &pGridInfo->TexelSnapSize)) return GE_FALSE;
	if (!Parse3dt_GetInt (Parser, (*Expected = "Rotation"), &pGridInfo->RotationSnap)) return GE_FALSE;

	// force texel grid and snap
	pGridInfo->GridType = GridTexel;
	pGridInfo->SnapType = GridTexel;

    return GE_TRUE;
}
#pragma warning (default:4100)

static char *ViewNames[NUM_VIEWS] = {"TexturedView", "TopView", "FrontView", "SideView"};

#pragma warning (disable:4100)
static geBoolean Level_LoadOneView
	(
	  ViewStateInfo *pViewInfo,
	  const char *ViewName,
	  Parse3dt *Parser, 
	  int VersionMajor, 
	  int VersionMinor, 
	  const char **Expected
	)
{
	if (!Parse3dt_GetInt (Parser, (*Expected = ViewName), &pViewInfo->IsValid)) return GE_FALSE;
	if (!Parse3dt_GetFloat (Parser, (*Expected = "Zoom"), &pViewInfo->ZoomFactor)) return GE_FALSE;
	if (!Parse3dt_GetVec3d (Parser, (*Expected = "PitchRollYaw"), &pViewInfo->PitchRollYaw)) return GE_FALSE;
	if (!Parse3dt_GetVec3d (Parser, (*Expected = "CamPos"), &pViewInfo->CameraPos)) return GE_FALSE;
	return GE_TRUE;
}
#pragma warning (default:4100)

static geBoolean Level_LoadViewInfo
	(
	  Level *pLevel,
	  Parse3dt *Parser, 
	  int VersionMajor, 
	  int VersionMinor, 
	  const char **Expected
	)
{
	int iView;

	for (iView = 0; iView < NUM_VIEWS; ++iView)
	{
		if (!Level_LoadOneView (&pLevel->ViewInfo[iView], ViewNames[iView], Parser, VersionMajor, VersionMinor, Expected)) return GE_FALSE;
	}
	return GE_TRUE;
}

static geBoolean Level_LoadBrushTemplates
	(
	  Level *pLevel,
	  Parse3dt *Parser, 
	  int VersionMajor, 
	  int VersionMinor, 
	  const char **Expected
	)
{
	if (!BrushTemplate_LoadArch (&pLevel->ArchTemplate, Parser, VersionMajor, VersionMinor, Expected)) return GE_FALSE;
	if (!BrushTemplate_LoadBox (&pLevel->BoxTemplate, Parser, VersionMajor, VersionMinor, Expected)) return GE_FALSE;
	if (!BrushTemplate_LoadCone (&pLevel->ConeTemplate, Parser, VersionMajor, VersionMinor, Expected)) return GE_FALSE;
	if (!BrushTemplate_LoadCylinder (&pLevel->CylinderTemplate, Parser, VersionMajor, VersionMinor, Expected)) return GE_FALSE;
	if (!BrushTemplate_LoadSpheroid (&pLevel->SpheroidTemplate, Parser, VersionMajor, VersionMinor, Expected)) return GE_FALSE;
	if (!BrushTemplate_LoadStaircase (&pLevel->StaircaseTemplate, Parser, VersionMajor, VersionMinor, Expected)) return GE_FALSE;

	return GE_TRUE;
}


Level *Level_CreateFromFile (const char *FileName, const char **ErrMsg, const char *DefaultHeadersDir)
{
	int NumModels;
	int VersionMajor, VersionMinor;
	int NumGroups = 0;
	int NumBrushes = 0;
	int NumEntities;
	Parse3dt *Parser;
	const char *Expected = "!*ERROR*!";
	int k;
	Level *pLevel = NULL;
	char WadPath[MAX_PATH];
	char HeadersDir[MAX_PATH];

	CGenEditDoc *pDoc = CGlobals::GetActiveDocument();

	assert (FileName != NULL);

	Parser = Parse3dt_Create (FileName);
	if (Parser == NULL)
	{
		*ErrMsg = "Can't open file";
		return NULL;
	}

	Expected = "3dtVersion";
	if (!Parse3dt_GetVersion (Parser, &VersionMajor, &VersionMinor)) goto DoneLoad;

	if(VersionMajor > LEVEL_VERSION_MAJOR)
	{
		*ErrMsg = "Version mismatch.";
		return NULL ;
	}

	if	(VersionMajor <= 1 && VersionMinor < 16)
	{
		char	PalPath[_MAX_PATH];

		if (!Parse3dt_GetPath (Parser, (Expected = "PalLoc"), PalPath)) goto DoneLoad;
	}

	// texture library path
	if ((VersionMajor <= 1) && (VersionMinor < 18))
	{
		if (!Parse3dt_GetPath (Parser, (Expected = "WadLoc"), WadPath)) goto DoneLoad;
	}
	else
	{
		if (!Parse3dt_GetLiteral (Parser, (Expected = "TextureLib"), WadPath)) goto DoneLoad;
	}

	// headers directory
	if ((VersionMajor <= 1) && (VersionMinor < 31))
	{
		strcpy (HeadersDir, DefaultHeadersDir);		//	post 0.55
	}
	else
	{
		if (!Parse3dt_GetLiteral (Parser, (Expected = "HeadersDir"), HeadersDir)) goto DoneLoad;	//	post 0.55
	}

	//	post 0.55	//	check to see if HeadersDir and WadPath actually exist on this system
	if (pDoc->m_currentTemplateName != "PreFab")	// ignore if we are adding prefab
	{
		if (!PathFileExists(WadPath))
		{
			CString	wadpath = _T("");
			
			CString	txlPathError = _T("GenEdit-Classic checks for valid *.txl files when opening new levels.\n\n");
			txlPathError += _T("This *.3dt file's specified *.txl file... ");
			txlPathError += _T(WadPath);
			txlPathError += _T("\ndoes not exist at the specified path.\n\n");
			txlPathError += _T("To avoid this message in the future, set the *.txl path for this *.3dt file\n");
			txlPathError += _T("in the Project, Level Options dialog box, then save the file.\n\n");
			txlPathError += _T("For now, please select a valid *.txl file or the application will exit.");
				
			AfxMessageBox(txlPathError);
					
				CFileDialog FileDlg (TRUE,
					"txl",
					WadPath,
					OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR,
					"Texture Library Files (*.txl)|*.txl||");
				
				FileDlg.m_ofn.lpstrTitle	="GenEdit-Classic Texture Finder";
				
				if (FileDlg.DoModal () == IDOK)
				{
					wadpath = FileDlg.GetPathName ();
					strcpy(WadPath, wadpath.GetBuffer(260));
				}
		}
		
		//	post 0.55	//	check to see if headers directory exists
		{
			CString tempHeaderDir = HeadersDir;
			// report path minus semicolon
			if (tempHeaderDir.Find(";") > 0) // post 0.57
			{
				tempHeaderDir = tempHeaderDir.Left(tempHeaderDir.Find(";"));
			}
			//	if path doesn't exist	
			if (!PathIsDirectory(tempHeaderDir))
			{
				CString	headersPathError = _T("GenEdit-Classic checks for valid header directories when opening new levels.\n\n");
				headersPathError += _T("The path to this *.3dt file's specified Headers directory does not exist on this system.\n\n");
				headersPathError += _T("Choose [OK] if you want GenEdit-Classic to set the headers path to:\n\n");
				headersPathError += _T(CGlobals::m_GlobalAppPath);
				headersPathError += _T("\n\nChoose [Cancel] if you want the headers path to stay as:\n\n");
				headersPathError += _T(HeadersDir);
				headersPathError += _T("\n\n");
				headersPathError += _T("After your new level file has opened, please adjust the true headers path(s) using the\n");
				headersPathError += _T("Project, Level Options dialog box.");
				
				if (AfxMessageBox(headersPathError, MB_OKCANCEL) == IDOK)
				{									//	set headers path to this app's path
					strcpy(HeadersDir, CGlobals::m_GlobalAppPath);
				}
			}
		}
	}		//	end post 0.55
	
	pLevel = Level_Create (WadPath, HeadersDir);
	if (pLevel == NULL)
	{
		*ErrMsg = "Error creating level.";
		return NULL;
	}


	if ((VersionMajor == 1) && (VersionMinor < 15))
	{
		if (!Parse3dt_GetInt  (Parser, (Expected = "NumBrushes"), &NumBrushes)) goto DoneLoad;
	}
	if (!Parse3dt_GetInt  (Parser, (Expected = "NumEntities"), &NumEntities)) goto DoneLoad;
	if (!Parse3dt_GetInt  (Parser, (Expected = "NumModels"), &NumModels)) goto DoneLoad;

	if ((VersionMajor > 1) || ((VersionMajor == 1) && (VersionMinor >= 3)))
	{
		if (!Parse3dt_GetInt (Parser, (Expected = "NumGroups"), &NumGroups)) goto DoneLoad;
	}


	if ((VersionMajor == 1) && (VersionMinor < 15))
	{
		for (k = 0; k < NumBrushes; k++)
		{
			Brush *pBrush;

			pBrush	=Brush_CreateFromFile(Parser, VersionMajor, VersionMinor, &Expected);
			if (pBrush == NULL) goto DoneLoad;
			BrushList_Append (pLevel->Brushes, pBrush);
		}
	}
	else
	{
		if (pLevel->Brushes != NULL)
		{
			BrushList_Destroy (&pLevel->Brushes);
		}
		pLevel->Brushes = BrushList_CreateFromFile (Parser, VersionMajor, VersionMinor, &Expected);
		if (pLevel->Brushes == NULL)
			goto DoneLoad;
	}

	if((VersionMajor > 1) || ((VersionMajor == 1) && (VersionMinor < 6)))
	{
		Level_BrushListToTexels (pLevel);
	}

	if (!Level_LoadEntities (pLevel, Parser, VersionMajor, VersionMinor, &Expected)) goto DoneLoad;

	if ((VersionMajor > 1) || ((VersionMajor == 1) && (VersionMinor >= 2)))
	{
		if (!ModelList_Read (pLevel->ModelInfo.Models, NumModels, Parser, VersionMajor, VersionMinor, &Expected))
		{
			goto DoneLoad;
		}
	}

	// collapse model list so numbers are consecutive
	Level_CollapseModels (pLevel, 1);

	if ((VersionMajor > 1) || ((VersionMajor == 1) && (VersionMinor >= 3)))
	{
		if (!Group_ReadList (pLevel->Groups, NumGroups, Parser, VersionMajor, VersionMinor, &Expected ))
		{
			goto DoneLoad;
		}
	}
	// collapse the group list so numbers are consecutive
	Level_CollapseGroups (pLevel, 1);

	// load sky information...
	if ((VersionMajor > 1) || ((VersionMajor == 1) && (VersionMinor >= 12)))
	{
		if (!Level_LoadSky (pLevel, Parser, VersionMajor, VersionMinor, &Expected)) goto DoneLoad;
	}

	// load compile information and other editing settings
	if ((VersionMajor > 1) || ((VersionMajor == 1) && (VersionMinor >= 20)))
	{
		if (!Level_LoadCompileInfo (pLevel, Parser, VersionMajor, VersionMinor, &Expected)) goto DoneLoad;
		if (!Parse3dt_GetInt (Parser, (Expected = "ShowGroups"), &pLevel->GroupVisSetting)) goto DoneLoad;
		if (!EntityViewList_LoadSettings (pLevel->pEntityView, Parser, VersionMajor, VersionMinor, &Expected)) goto DoneLoad;
		if (!Level_LoadGridInfo (pLevel, Parser, VersionMajor, VersionMinor, &Expected)) goto DoneLoad;
		if (!Parse3dt_GetInt (Parser, (Expected = "BspRebuild"), &pLevel->BspRebuildFlag)) goto DoneLoad;
		if (!Level_LoadViewInfo (pLevel, Parser, VersionMajor, VersionMinor, &Expected)) goto DoneLoad;
		if (!Level_LoadBrushTemplates (pLevel, Parser, VersionMajor, VersionMinor, &Expected)) goto DoneLoad;
		if (!Parse3dt_GetVec3d (Parser, (Expected = "TemplatePos"), &pLevel->TemplatePos)) goto DoneLoad;
	}

	// load level settings
	if ((VersionMajor > 1) || ((VersionMajor == 1) && (VersionMinor >= 22)))
	{
		if (!Parse3dt_GetFloat (Parser, (Expected = "DrawScale"), &pLevel->DrawScale)) goto DoneLoad;
		if (!Parse3dt_GetFloat (Parser, (Expected = "LightmapScale"), &pLevel->LightmapScale)) goto DoneLoad;
	}

	goto AllDone;

DoneLoad:
	*ErrMsg = Parse3dt_Error (Parser, "Expected %s", Expected);

//DoneLoad1:
	if (pLevel != NULL)
	{
		Level_Destroy (&pLevel);
	}

AllDone:
	if (Parser != NULL)
	{
		Parse3dt_Destroy (&Parser);
	}

	//fixup hollows
	if(pLevel != NULL)
	{
		BrushList_MakeHollowsMulti(pLevel->Brushes);
	}

	return pLevel;
}



static geBoolean Level_WriteSky
	(
	  SkyFaceTexture const SkyFaces[],
	  geVec3d const *Axis,
	  const float Speed,
	  const float Scale,
	  FILE *ArFile
	)
{
	int i;

	if (fprintf (ArFile, "%s\n", "Sky") < 0) return GE_FALSE;
	for (i = 0; i < 6; ++i)
	{
		char QuotedValue[SCANNER_MAXDATA];
		char const *StringToQuote;

		StringToQuote = "";

⌨️ 快捷键说明

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