Exemplo n.º 1
16
StdCopyStrBuf GetRegistryString(const char *szSubKey, const char *szValueName)
{
	HKEY ckey;

	// Open the key
	if (RegOpenKeyExW(HKEY_CURRENT_USER, GetWideChar(szSubKey), 0, KEY_READ, &ckey)!=ERROR_SUCCESS)
		return StdCopyStrBuf();

	// Get the value
	DWORD dwValSize = 128;
	BYTE *sValue = new BYTE[dwValSize];
	while(true)
	{
		DWORD valtype;
		switch(RegQueryValueExW(ckey, GetWideChar(szValueName), NULL, &valtype,
			sValue, &dwValSize))
		{
		case ERROR_SUCCESS:
			RegCloseKey(ckey);
			if (valtype == REG_SZ)
			{
				StdCopyStrBuf nrv(reinterpret_cast<wchar_t*>(sValue));
				delete[] sValue;
				return nrv;
			} else {
		default:
				delete[] sValue;
				return StdCopyStrBuf();
			}
			break;
		case ERROR_MORE_DATA:
			delete[] sValue;
			sValue = new BYTE[dwValSize];
			break;
		}
	}
}
Exemplo n.º 2
0
void C4LandscapeRenderGL::AddTextureAnim(const char *szTextureAnim)
{
	if(!szTextureAnim) return;
#ifdef DEBUG_SEPERATOR_TEXTURES
	// Save back count of textures at start
	uint32_t iStartTexCount = MaterialTextureMap.size();
#endif
	// Add all individual transitions
	const char *pFrom = szTextureAnim;
	for(;;)
	{
		// Get next phase
		const char *pTo = strchr(pFrom, '-');
		if(!pTo) pTo = szTextureAnim; else pTo++;
		// Add transition
		StdStrBuf From, To;
		From.CopyUntil(pFrom, '-');
		To.CopyUntil(pTo, '-');
		AddTextureTransition(From.getData(), To.getData());
		// Advance
		if(pTo == szTextureAnim) break;
		pFrom = pTo;
	}
#ifdef DEBUG_SEPERATOR_TEXTURES
	// Add a seperator texture, if we added any new ones
	if(MaterialTextureMap.size() > iStartTexCount)
		MaterialTextureMap.push_back(StdCopyStrBuf(SEPERATOR_TEXTURE));
#endif
}
Exemplo n.º 3
0
bool C4DefGraphics::LoadSkeleton(C4Group &hGroup, const char* szFileName, StdMeshSkeletonLoader& loader)
{
	char* buf = NULL;
	size_t size;

	try
	{
		if (!hGroup.LoadEntry(szFileName, &buf, &size, 1)) return false;

		StdCopyStrBuf filename = StdCopyStrBuf();
		StdMeshSkeletonLoader::MakeFullSkeletonPath(filename, hGroup.GetName(), szFileName);

		if (SEqualNoCase(GetExtension(szFileName), "xml"))
		{
			loader.LoadSkeletonXml(filename, buf, size);
		}
		else
		{
			loader.LoadSkeletonBinary(filename, buf, size);
		}

		delete[] buf;
	}
	catch (const std::runtime_error& ex)
	{
		DebugLogF("Failed to load skeleton in definition %s: %s", hGroup.GetName(), ex.what());
		delete[] buf;
		return false;
	}

	return true;
}
void C4RoundResults::CompileFunc(StdCompiler *pComp)
{
	bool fCompiler = pComp->isCompiler();
	if (fCompiler) Clear();
	pComp->Value(mkNamingAdapt(Goals, "Goals", C4IDList()));
	pComp->Value(mkNamingAdapt(iPlayingTime, "PlayingTime", 0u));
	pComp->Value(mkNamingAdapt(fHideSettlementScore, "HideSettlementScore", Game.C4S.Game.IsMelee()));
	pComp->Value(mkNamingAdapt(sCustomEvaluationStrings, "CustomEvaluationStrings", StdCopyStrBuf()));
	pComp->Value(mkNamingAdapt(iLeaguePerformance, "LeaguePerformance", 0));
	pComp->Value(mkNamingAdapt(Players, "PlayerInfos", C4RoundResultsPlayers()));
	pComp->Value(mkNamingAdapt(sNetResult, "NetResult", StdCopyStrBuf()));
	StdEnumEntry<NetResult> NetResultEntries[] =
	{
		{ "",            NR_None       },
		{ "LeagueOK",    NR_LeagueOK   },
		{ "LeagueError", NR_LeagueError},
		{ "NetError",    NR_NetError   },
	};
	pComp->Value(mkNamingAdapt(mkEnumAdaptT<uint8_t>(eNetResult, NetResultEntries), "NetResult", NR_None));
}
Exemplo n.º 5
0
bool C4Reloc::AddPath(const char* path, PathType pathType)
{
	if(!IsGlobalPath(path))
		return false;

	if(std::find(Paths.begin(), Paths.end(), path) != Paths.end())
		return false;

	Paths.push_back(PathInfo(StdCopyStrBuf(path), pathType));
	return true;
}
Exemplo n.º 6
0
void C4ScenarioParameters::SetValue(const char *id, int32_t value, bool only_if_larger)
{
	if (only_if_larger)
	{
		auto i = Parameters.find(StdStrBuf(id));
		if (i != Parameters.end())
			if (i->second >= value)
				// could become smaller. don't set.
				return;
	}
	// just update map
	Parameters[StdCopyStrBuf(id)] = value;
}
Exemplo n.º 7
0
void C4LandscapeRenderGL::AddTextureTransition(const char *szFrom, const char *szTo)
{
	// Empty?
	if (!szFrom || !szTo) return;
	// First try the lookup (both directions)
	if (LookupTextureTransition(szFrom, szTo) >= 0) return;
	if (LookupTextureTransition(szTo, szFrom) >= 0) return;
	// Single texture? Add it as single
	if (SEqual(szTo, szFrom))
		MaterialTextureMap.push_back(StdCopyStrBuf(szFrom));
	// Have one of the textures at the end of the list?
	else if(SEqual(MaterialTextureMap.back().getData(), szFrom))
		MaterialTextureMap.push_back(StdCopyStrBuf(szTo));
	else if(SEqual(MaterialTextureMap.back().getData(), szTo))
		MaterialTextureMap.push_back(StdCopyStrBuf(szFrom));
	else
	{
		// Otherwise add both
		MaterialTextureMap.push_back(StdCopyStrBuf(szFrom));
		MaterialTextureMap.push_back(StdCopyStrBuf(szTo));
	}
}
Exemplo n.º 8
0
void C4Team::CompileFunc(StdCompiler *pComp)
{
	if (pComp->isCompiler()) Clear();
	pComp->Value(mkNamingAdapt(iID,                  "id",             0));
	pComp->Value(mkNamingAdapt(mkStringAdaptMA(Name), "Name",          ""));
	pComp->Value(mkNamingAdapt(iPlrStartIndex,       "PlrStartIndex",  0));
	pComp->Value(mkNamingAdapt(iPlayerCount,         "PlayerCount", 0));
	if (pComp->isCompiler()) { delete [] piPlayers; piPlayers = new int32_t [iPlayerCapacity = iPlayerCount]; ZeroMem(piPlayers, sizeof(*piPlayers) * iPlayerCount); }
	pComp->Value(mkNamingAdapt(mkArrayAdapt(piPlayers, iPlayerCount, -1), "Players"));
	pComp->Value(mkNamingAdapt(dwClr,                "Color",        0u));
	pComp->Value(mkNamingAdapt(mkParAdapt(sIconSpec, StdCompiler::RCT_All),
	                                                 "IconSpec",     StdCopyStrBuf()));
	pComp->Value(mkNamingAdapt(iMaxPlayer,           "MaxPlayer",    0));
}
Exemplo n.º 9
0
void C4MusicSystem::CompileFunc(StdCompiler *comp)
{
	comp->Value(mkNamingAdapt(playlist, "PlayList", StdCopyStrBuf()));
	comp->Value(mkNamingAdapt(game_music_level, "Volume", 100));
	comp->Value(mkNamingAdapt(music_break_min, "MusicBreakMin", DefaultMusicBreak));
	comp->Value(mkNamingAdapt(music_break_max, "MusicBreakMax", DefaultMusicBreak));
	comp->Value(mkNamingAdapt(music_break_chance, "MusicBreakChance", DefaultMusicBreakChance));
	comp->Value(mkNamingAdapt(music_max_position_memory, "MusicMaxPositionMemory", DefaultMusicMaxPositionMemory));
	// Wait time is not saved - begin savegame resume with a fresh song!
	// Reflect loaded values immediately
	if (comp->isCompiler())
	{
		SetGameMusicLevel(game_music_level);
		SetPlayList(playlist.getData());
	}
}
Exemplo n.º 10
0
void C4SHead::CompileFunc(StdCompiler *pComp, bool fSection) {
  if (!fSection) {
    pComp->Value(mkNamingAdapt(Icon, "Icon", 18));
    pComp->Value(
        mkNamingAdapt(mkStringAdaptMA(Title), "Title", "Default Title"));
    pComp->Value(mkNamingAdapt(mkStringAdaptMA(Loader), "Loader", ""));
    pComp->Value(mkNamingAdapt(mkStringAdaptMA(Font), "Font", ""));
    pComp->Value(mkNamingAdapt(mkArrayAdaptDM(C4XVer, 0), "Version"));
    pComp->Value(mkNamingAdapt(Difficulty, "Difficulty", 0));
    pComp->Value(mkNamingAdapt(EnableUnregisteredAccess, "Access", FALSE));
    pComp->Value(mkNamingAdapt(MaxPlayer, "MaxPlayer", C4S_MaxPlayerDefault));
    pComp->Value(mkNamingAdapt(MaxPlayerLeague, "MaxPlayerLeague", MaxPlayer));
    pComp->Value(mkNamingAdapt(MinPlayer, "MinPlayer", 0));
    pComp->Value(mkNamingAdapt(SaveGame, "SaveGame", FALSE));
    pComp->Value(mkNamingAdapt(Replay, "Replay", FALSE));
    pComp->Value(mkNamingAdapt(Film, "Film", FALSE));
    pComp->Value(mkNamingAdapt(DisableMouse, "DisableMouse", FALSE));
    pComp->Value(mkNamingAdapt(IgnoreSyncChecks, "IgnoreSyncChecks", FALSE));
  }
  pComp->Value(mkNamingAdapt(NoInitialize, "NoInitialize", FALSE));
  pComp->Value(mkNamingAdapt(RandomSeed, "RandomSeed", 0));
  if (!fSection) {
    pComp->Value(mkNamingAdapt(mkStringAdaptMA(Engine), "Engine", ""));
    pComp->Value(
        mkNamingAdapt(mkStringAdaptMA(MissionAccess), "MissionAccess", ""));
    pComp->Value(mkNamingAdapt(NetworkGame, "NetworkGame", false));
    pComp->Value(
        mkNamingAdapt(NetworkRuntimeJoin, "NetworkRuntimeJoin", false));
    pComp->Value(mkNamingAdapt(ForcedGfxMode, "ForcedGfxMode", 0));
    pComp->Value(mkNamingAdapt(ForcedFairCrew, "ForcedNoCrew", 0));
    pComp->Value(mkNamingAdapt(FairCrewStrength, "DefCrewStrength", 0));
    pComp->Value(
        mkNamingAdapt(ForcedAutoContextMenu, "ForcedAutoContextMenu", -1));
    pComp->Value(
        mkNamingAdapt(ForcedControlStyle, "ForcedAutoStopControl", -1));
    pComp->Value(
        mkNamingAdapt(mkStrValAdapt(mkParAdapt(Origin, StdCompiler::RCT_All),
                                    C4InVal::VAL_SubPathFilename),
                      "Origin", StdCopyStrBuf()));
    // windows needs backslashes in Origin; other systems use forward slashes
    if (pComp->isCompiler())
      Origin.ReplaceChar(AltDirectorySeparator, DirectorySeparator);
  }
}
Exemplo n.º 11
0
C4GUI::ContextMenu *C4StartupMainDlg::OnPlayerSelContextAdd(
    C4GUI::Element *pBtn, int32_t iX, int32_t iY) {
  C4GUI::ContextMenu *pCtx = new C4GUI::ContextMenu();
  const char *szFn;
  StdStrBuf sSearchPath;
  sSearchPath.Format("%s%s", (const char *)Config.General.ExePath,
                     (const char *)Config.General.PlayerPath);
  for (DirectoryIterator i(sSearchPath.getData()); szFn = *i; i++) {
    szFn = Config.AtExeRelativePath(szFn);
    if (*GetFilename(szFn) == '.') continue;
    if (!WildcardMatch(C4CFN_PlayerFiles, GetFilename(szFn))) continue;
    if (!SIsModule(Config.General.Participants, szFn, NULL, false))
      pCtx->AddItem(C4Language::IconvClonk(GetFilenameOnly(szFn)).getData(),
                    "Let this player join in next game", C4GUI::Ico_Player,
                    new C4GUI::CBMenuHandlerEx<C4StartupMainDlg, StdCopyStrBuf>(
                        this, &C4StartupMainDlg::OnPlayerSelContextAddPlr,
                        StdCopyStrBuf(szFn)),
                    NULL);
  }
  return pCtx;
}
Exemplo n.º 12
0
void C4RoundResultsPlayer::CompileFunc(StdCompiler *pComp)
{
	// remember to adjust operator = and == when adding values here!
	pComp->Value(mkNamingAdapt(id,    "ID",   0));
	// pComp->Value(mkNamingAdapt(fctBigIcon,    "Icon",      C4TargetFacet())); - not possible
	pComp->Value(mkNamingAdapt(iTotalPlayingTime,  "TotalPlayingTime",    0u));
	pComp->Value(mkNamingAdapt(iScoreOld,  "SettlementScoreOld",    -1));
	pComp->Value(mkNamingAdapt(iScoreNew,  "SettlementScoreNew",    -1));
	pComp->Value(mkNamingAdapt(iLeagueScoreNew,  "Score",    -1));          // name used in league reply!
	pComp->Value(mkNamingAdapt(iLeagueScoreGain,  "GameScore",    -1));     // name used in league reply!
	pComp->Value(mkNamingAdapt(iLeagueRankNew,  "Rank",    0));             // name used in league reply!
	pComp->Value(mkNamingAdapt(iLeagueRankSymbolNew,  "RankSymbol",    0)); // name used in league reply!
	pComp->Value(mkNamingAdapt(sLeagueProgressData,  "LeagueProgressData",    StdCopyStrBuf()));
	StdEnumEntry<LeagueStatus> LeagueStatusEntries[] =
	{
		{ "",     RRPLS_Unknown },
		{ "Lost", RRPLS_Lost    },
		{ "Won",  RRPLS_Won     },
	};
	pComp->Value(mkNamingAdapt(mkEnumAdaptT<uint8_t>(eLeagueStatus, LeagueStatusEntries),  "Status",    RRPLS_Unknown));            // name used in league reply!
}
Exemplo n.º 13
0
void C4MaterialReaction::CompileFunc(StdCompiler *pComp)
{
	if (pComp->isCompiler()) pScriptFunc = NULL;
	// compile reaction func ptr
	StdStrBuf sReactionFuncName;
	int32_t i=0; while (ReactionFuncMap[i].szRFName && (ReactionFuncMap[i].pFunc != pFunc)) ++i;
	sReactionFuncName = ReactionFuncMap[i].szRFName;
	pComp->Value(mkNamingAdapt(mkParAdapt(sReactionFuncName, StdCompiler::RCT_IdtfAllowEmpty),   "Type",                     StdCopyStrBuf() ));
	i=0; while (ReactionFuncMap[i].szRFName && !SEqual(ReactionFuncMap[i].szRFName, sReactionFuncName.getData())) ++i;
	pFunc = ReactionFuncMap[i].pFunc;
	// compile the rest
	pComp->Value(mkNamingAdapt(mkParAdapt(TargetSpec, StdCompiler::RCT_All),          "TargetSpec",               StdCopyStrBuf() ));
	pComp->Value(mkNamingAdapt(mkParAdapt(ScriptFunc, StdCompiler::RCT_IdtfAllowEmpty),          "ScriptFunc",               StdCopyStrBuf() ));
	pComp->Value(mkNamingAdapt(iExecMask,           "ExecMask",                 ~0u             ));
	pComp->Value(mkNamingAdapt(fReverse,            "Reverse",                  false           ));
	pComp->Value(mkNamingAdapt(fInverseSpec,        "InverseSpec",              false           ));
	pComp->Value(mkNamingAdapt(fInsertionCheck,     "CheckSlide",               true            ));
	pComp->Value(mkNamingAdapt(iDepth,              "Depth",                    0               ));
	pComp->Value(mkNamingAdapt(mkParAdapt(sConvertMat, StdCompiler::RCT_IdtfAllowEmpty),         "ConvertMat",               StdCopyStrBuf() ));
	pComp->Value(mkNamingAdapt(iCorrosionRate,      "CorrosionRate",            100             ));
}
Exemplo n.º 14
0
StdMesh *StdMeshLoader::LoadMeshXml(const char* xml_data, size_t size, const StdMeshMatManager& manager, StdMeshSkeletonLoader& skel_loader, const char* filename)
{
	StdMeshXML xml(filename ? filename : "<unknown>", xml_data);

	std::unique_ptr<StdMesh> mesh(new StdMesh);

	TiXmlElement* mesh_elem = xml.RequireFirstChild(NULL, "mesh");

	// Load shared geometry, if any
	TiXmlElement* sharedgeometry_elem = mesh_elem->FirstChildElement("sharedgeometry");
	if(sharedgeometry_elem != NULL)
		xml.LoadGeometry(*mesh, mesh->SharedVertices, sharedgeometry_elem);

	TiXmlElement* submeshes_elem = xml.RequireFirstChild(mesh_elem, "submeshes");

	TiXmlElement* submesh_elem_base = xml.RequireFirstChild(submeshes_elem, "submesh");
	for (TiXmlElement* submesh_elem = submesh_elem_base; submesh_elem != NULL; submesh_elem = submesh_elem->NextSiblingElement("submesh"))
	{
		mesh->SubMeshes.push_back(StdSubMesh());
		StdSubMesh& submesh = mesh->SubMeshes.back();

		const char* material = xml.RequireStrAttribute(submesh_elem, "material");
		submesh.Material = manager.GetMaterial(material);
		if (!submesh.Material)
			xml.Error(FormatString("There is no such material named '%s'", material), submesh_elem);

		const char* usesharedvertices = submesh_elem->Attribute("usesharedvertices");
		const std::vector<StdMesh::Vertex>* vertices;
		if(!usesharedvertices || strcmp(usesharedvertices, "true") != 0)
		{
			TiXmlElement* geometry_elem = xml.RequireFirstChild(submesh_elem, "geometry");
			xml.LoadGeometry(*mesh, submesh.Vertices, geometry_elem);
			vertices = &submesh.Vertices;
		}
		else
		{
			if(mesh->SharedVertices.empty())
				xml.Error(StdCopyStrBuf("Submesh specifies to use shared vertices but there is no shared geometry"), submesh_elem);
			vertices = &mesh->SharedVertices;
		}

		TiXmlElement* faces_elem = xml.RequireFirstChild(submesh_elem, "faces");
		int FaceCount = xml.RequireIntAttribute(faces_elem, "count");
		submesh.Faces.resize(FaceCount);

		unsigned int i = 0;
		for (TiXmlElement* face_elem = faces_elem->FirstChildElement("face"); face_elem != NULL && i < submesh.Faces.size(); face_elem = face_elem->NextSiblingElement("face"), ++i)
		{
			int v[3];

			v[0] = xml.RequireIntAttribute(face_elem, "v1");
			v[1] = xml.RequireIntAttribute(face_elem, "v2");
			v[2] = xml.RequireIntAttribute(face_elem, "v3");

			for (unsigned int j = 0; j < 3; ++j)
			{
				if (v[j] < 0 || static_cast<unsigned int>(v[j]) >= vertices->size())
					xml.Error(FormatString("Vertex index v%u (%d) is out of range", j+1, v[j]), face_elem);
				submesh.Faces[i].Vertices[j] = v[j];
			}
		}
	}

	// We allow bounding box to be empty if it's only due to Z direction since
	// this is what goes inside the screen in Clonk.
	if(mesh->BoundingBox.x1 == mesh->BoundingBox.x2 || mesh->BoundingBox.y1 == mesh->BoundingBox.y2)
		xml.Error(StdCopyStrBuf("Bounding box is empty"), mesh_elem);

	// Read skeleton, if any
	TiXmlElement* skeletonlink_elem = mesh_elem->FirstChildElement("skeletonlink");
	if (skeletonlink_elem)
	{
		const char* name = xml.RequireStrAttribute(skeletonlink_elem, "name");
		StdCopyStrBuf xml_filename(name); xml_filename.Append(".xml");

		StdCopyStrBuf skeleton_filename;
		StdMeshSkeletonLoader::MakeFullSkeletonPath(skeleton_filename, filename, xml_filename.getData());

		mesh->Skeleton = skel_loader.GetSkeletonByName(skeleton_filename);
		if (!mesh->Skeleton) xml.Error(FormatString("Failed to load '%s'", skeleton_filename.getData()), skeletonlink_elem);

		// Vertex<->Bone assignments for shared geometry
		if (sharedgeometry_elem)
		{
			TiXmlElement* boneassignments_elem = xml.RequireFirstChild(mesh_elem, "boneassignments");
			xml.LoadBoneAssignments(*mesh, mesh->SharedVertices, boneassignments_elem);
		}

		// Vertex<->Bone assignments for all vertices (need to go through SubMeshes again...)
		unsigned int submesh_index = 0;
		for (TiXmlElement* submesh_elem = submesh_elem_base; submesh_elem != NULL; submesh_elem = submesh_elem->NextSiblingElement("submesh"), ++submesh_index)
		{
			StdSubMesh& submesh = mesh->SubMeshes[submesh_index];
			if (!submesh.Vertices.empty())
			{
				TiXmlElement* boneassignments_elem = xml.RequireFirstChild(submesh_elem, "boneassignments");
				xml.LoadBoneAssignments(*mesh, submesh.Vertices, boneassignments_elem);
			}
		}
	}
	else
	{
		// Mesh has no skeleton
		// Bone assignements do not make sense then, as the
		// actual bones are defined in the skeleton file.
		for (TiXmlElement* submesh_elem = submesh_elem_base; submesh_elem != NULL; submesh_elem = submesh_elem->NextSiblingElement("submesh"))
		{
			TiXmlElement* boneassignments_elem = submesh_elem->FirstChildElement("boneassignments");
			if (boneassignments_elem)
				xml.Error(StdStrBuf("Mesh has bone assignments, but no skeleton"), boneassignments_elem);
		}

		TiXmlElement* boneassignments_elem = mesh_elem->FirstChildElement("boneassignments");
		if (boneassignments_elem)
			xml.Error(StdStrBuf("Mesh has bone assignments, but no skeleton"), boneassignments_elem);
	}

	return mesh.release();
}
Exemplo n.º 15
0
bool C4LandscapeRenderGL::InitMaterialTexture(C4TextureMap *pTexs)
{

	// Populate our map with all needed textures
	MaterialTextureMap.push_back(StdCopyStrBuf(""));
	AddTexturesFromMap(pTexs);

	// Determine depth to use
	iMaterialTextureDepth = 2*MaterialTextureMap.size();
	int32_t iNormalDepth = iMaterialTextureDepth / 2;

	// Find the largest texture
	C4Texture *pTex; C4Surface *pRefSfc = NULL;
	for(int iTexIx = 0; (pTex = pTexs->GetTexture(pTexs->GetTexture(iTexIx))); iTexIx++)
		if(C4Surface *pSfc = pTex->Surface32)
			if (!pRefSfc || pRefSfc->Wdt < pSfc->Wdt || pRefSfc->Hgt < pSfc->Hgt)
				pRefSfc = pSfc;
	if(!pRefSfc)
		return false;

	// Get size for our textures. We might be limited by hardware
	int iTexWdt = pRefSfc->Wdt, iTexHgt = pRefSfc->Hgt;
	GLint iMaxTexSize, iMaxTexLayers;
	glGetIntegerv(GL_MAX_TEXTURE_SIZE, &iMaxTexSize);
	glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &iMaxTexLayers);
	if (iTexWdt > iMaxTexSize || iTexHgt > iMaxTexSize)
	{
		iTexWdt = std::min(iTexWdt, iMaxTexSize);
		iTexHgt = std::min(iTexHgt, iMaxTexSize);
		LogF("   gl: Material textures too large, GPU only supports %dx%d! Cropping might occur!", iMaxTexSize, iMaxTexSize);
	}
	if(iMaterialTextureDepth >= iMaxTexLayers)
	{
		LogF("   gl: Too many material textures! GPU only supports 3D texture depth of %d!", iMaxTexSize);
		return false;
	}
	iMaterialWidth = iTexWdt;
	iMaterialHeight = iTexHgt;

	// Compose together data of all textures
	const int iTexSize = iTexWdt * iTexHgt * C4Draw::COLOR_DEPTH_BYTES;
	const int iSize = iTexSize * iMaterialTextureDepth;
	BYTE *pData = new BYTE [iSize];
	for(int i = 0; i < iMaterialTextureDepth; i++)
	{
		BYTE *p = pData + i * iTexSize;
		// Get texture at position
		StdStrBuf Texture;
		bool fNormal = i >= iNormalDepth;
		if(i < int32_t(MaterialTextureMap.size()))
			Texture.Ref(MaterialTextureMap[i]);
		else if(fNormal && i < iNormalDepth + int32_t(MaterialTextureMap.size()))
			Texture.Format("%s_NRM", MaterialTextureMap[i-iNormalDepth].getData());
		// Try to find the texture
		C4Texture *pTex; C4Surface *pSurface;
		if((pTex = pTexs->GetTexture(Texture.getData())) && (pSurface = pTex->Surface32))
		{
#ifdef DEBUG_SOLID_COLOR_TEXTURES
			// Just write a solid color that depends on the texture index
			DWORD *texdata = reinterpret_cast<DWORD *>(p);
			for (int y = 0; y < iTexHgt; ++y)
				for (int x = 0; x < iTexWdt; ++x)
					*texdata++ = RGBA((iTex & 48), (iTex & 3) * 16, (i & 12) * 4, 255);
			continue;
#else
			// Size recheck. It's fine if this texture's size is a divisor
			// of the maximum texture size, because then we can just tile
			// the smaller texture.
			if(pSurface->Wdt != iTexWdt || pSurface->Hgt != iTexHgt)
				if (iTexWdt % pSurface->Wdt != 0 || iTexHgt % pSurface->Hgt != 0)
					LogF("   gl: texture %s size mismatch (%dx%d vs %dx%d)!", Texture.getData(), pSurface->Wdt, pSurface->Hgt, iTexWdt, iTexHgt);

			// Copy bytes
			DWORD *texdata = reinterpret_cast<DWORD *>(p);
			pSurface->Lock();
			for (int y = 0; y < iTexHgt; ++y)
				for (int x = 0; x < iTexWdt; ++x)
					*texdata++ = pSurface->GetPixDw(x % pSurface->Wdt, y % pSurface->Hgt, false);
			pSurface->Unlock();
			continue;
#endif
		}
		// Seperator texture?
		if(SEqual(Texture.getData(), SEPERATOR_TEXTURE))
		{
			// Make some ugly stripes
			DWORD *texdata = reinterpret_cast<DWORD *>(p);
			for (int y = 0; y < iTexHgt; ++y)
				for (int x = 0; x < iTexWdt; ++x)
					*texdata++ = ((x + y) % 32 < 16 ? RGBA(255, 0, 0, 255) : RGBA(0, 255, 255, 255));
			continue;
		}
		// If we didn't "continue" yet, we haven't written the texture yet.
		// Make color texture transparent, and normal texture flat.
		if (fNormal)
		{
			DWORD *texdata = reinterpret_cast<DWORD *>(p);
			for (int y = 0; y < iTexHgt; ++y)
				for (int x = 0; x < iTexWdt; ++x)
					*texdata++ = RGBA(127, 127, 255, 255);
		}
		else
			memset(p, 0, iTexSize);
	}

	// Clear error error(s?)
	while(glGetError()) {}
	
	// Alloc 1D matmap texture
	glGenTextures(1, &matMapTexture);

	// Alloc 2D texture array
	glGenTextures(1, &hMaterialTexture);

	// Generate textures
	int iSizeSum = 0;

	// Select texture
	glBindTexture(GL_TEXTURE_2D_ARRAY, hMaterialTexture);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	// We fully expect to tile these
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

	// Make it happen!
	glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, iTexWdt, iTexHgt, iMaterialTextureDepth, 0, GL_BGRA,
				GL_UNSIGNED_INT_8_8_8_8_REV,
				pData);

	glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
	   
	// Statistics
	iSizeSum += iTexWdt * iTexHgt * iMaterialTextureDepth * C4Draw::COLOR_DEPTH_BYTES;
	
	// Dispose of data
	delete [] pData;
	
	// Check whether we were successful
	if(int err = glGetError())
	{
		LogF("   gl: Could not load textures (error %d)", err);
		return false;
	}

	// Announce the good news
	LogF("  gl: Texturing uses %d slots at %dx%d (%d MB total)",
		static_cast<int>(MaterialTextureMap.size()),
		iMaterialWidth, iMaterialHeight,
		iSizeSum / 1000000);

	return true;
}
Exemplo n.º 16
0
void C4ScenarioParameterDef::CompileFunc(StdCompiler *pComp)
{
	if (!pComp->Name("ParameterDef")) { pComp->NameEnd(); pComp->excNotFound("ParameterDef"); }
	pComp->Value(mkNamingAdapt(mkParAdapt(Name, StdCompiler::RCT_All),          "Name",         StdCopyStrBuf()));
	pComp->Value(mkNamingAdapt(mkParAdapt(Description, StdCompiler::RCT_All),   "Description",  StdCopyStrBuf()));
	pComp->Value(mkNamingAdapt(mkParAdapt(ID, StdCompiler::RCT_Idtf),           "ID",           StdCopyStrBuf()));
	StdEnumEntry<ParameterType> ParTypeEntries[] =
	{
		{ "Enumeration", SPDT_Enum },
		{ nullptr, SPDT_Enum }
	};
	pComp->Value(mkNamingAdapt(mkEnumAdaptT<uint8_t>(Type, ParTypeEntries),         "Type",         SPDT_Enum));
	pComp->Value(mkNamingAdapt(Default,                                             "Default",      0));
	pComp->Value(mkNamingAdapt(LeagueValue,                                         "LeagueValue",  0));
	pComp->Value(mkNamingAdapt(mkParAdapt(Achievement, StdCompiler::RCT_Idtf),      "Achievement",  StdCopyStrBuf()));
	pComp->Value(mkNamingAdapt(mkSTLContainerAdapt(Options, StdCompiler::SEP_NONE), "Options"));
	pComp->NameEnd();
}
Exemplo n.º 17
0
void C4ScenarioParameterDef::Option::CompileFunc(StdCompiler *pComp)
{
	if (!pComp->Name("Option")) { pComp->NameEnd(); pComp->excNotFound("Option"); }
	pComp->Value(mkNamingAdapt(mkParAdapt(Name, StdCompiler::RCT_All),          "Name",         StdCopyStrBuf()));
	pComp->Value(mkNamingAdapt(mkParAdapt(Description, StdCompiler::RCT_All),   "Description",  StdCopyStrBuf()));
	pComp->Value(mkNamingAdapt(           Value,                                "Value",        0));
	pComp->NameEnd();
}
Exemplo n.º 18
0
void C4SGame::CompileFunc(StdCompiler *pComp, bool fSection)
{
	if (!fSection)
	{
		pComp->Value(mkNamingAdapt(Realism.ValueOverloads,            "ValueOverloads",      C4IDList()));
	}
	pComp->Value(mkNamingAdapt(mkRuntimeValueAdapt(Realism.LandscapePushPull),         "LandscapePushPull",   false));
	pComp->Value(mkNamingAdapt(mkRuntimeValueAdapt(Realism.LandscapeInsertThrust),     "LandscapeInsertThrust",true));

	pComp->Value(mkNamingAdapt(mkParAdapt(Mode, StdCompiler::RCT_IdtfAllowEmpty), "Mode",        StdCopyStrBuf()));
	pComp->Value(mkNamingAdapt(Goals,                                             "Goals",       C4IDList()));
	pComp->Value(mkNamingAdapt(Rules,                                             "Rules",       C4IDList()));
	pComp->Value(mkNamingAdapt(FoWEnabled,                                        "FoWEnabled",  true));
}
Exemplo n.º 19
0
void C4SHead::CompileFunc(StdCompiler *pComp, bool fSection)
{
	if (!fSection)
	{
		pComp->Value(mkNamingAdapt(Icon,                      "Icon",                 18));
		pComp->Value(mkNamingAdapt(mkStringAdaptMA(Title),    "Title",                "Default Title"));
		pComp->Value(mkNamingAdapt(mkStringAdaptMA(Loader),   "Loader",               ""));
		pComp->Value(mkNamingAdapt(mkStringAdaptMA(Font),     "Font",                 ""));
		pComp->Value(mkNamingAdapt(mkArrayAdaptDM(C4XVer,0),  "Version"               ));
		pComp->Value(mkNamingAdapt(Difficulty,                "Difficulty",           0));
		pComp->Value(mkNamingAdapt(MaxPlayer,                 "MaxPlayer",            C4S_MaxPlayerDefault));
		pComp->Value(mkNamingAdapt(MaxPlayerLeague,           "MaxPlayerLeague",      MaxPlayer));
		pComp->Value(mkNamingAdapt(MinPlayer,                 "MinPlayer",            0));
		pComp->Value(mkNamingAdapt(SaveGame,                  "SaveGame",             false));
		pComp->Value(mkNamingAdapt(Replay,                    "Replay",               false));
		pComp->Value(mkNamingAdapt(Film,                      "Film",                 0));
	}
	pComp->Value(mkNamingAdapt(NoInitialize,              "NoInitialize",         false));
	pComp->Value(mkNamingAdapt(RandomSeed,                "RandomSeed",           0));
	if (!fSection)
	{
		pComp->Value(mkNamingAdapt(mkStringAdaptMA(Engine),   "Engine",               ""));
		pComp->Value(mkNamingAdapt(mkStringAdaptMA(MissionAccess), "MissionAccess", ""));
		pComp->Value(mkNamingAdapt(Secret,                    "Secret",               false));
		pComp->Value(mkNamingAdapt(NetworkGame,               "NetworkGame",          false));
		pComp->Value(mkNamingAdapt(NetworkRuntimeJoin,        "NetworkRuntimeJoin",   false));
		pComp->Value(mkNamingAdapt(mkStrValAdapt(mkParAdapt(Origin, StdCompiler::RCT_All), C4InVal::VAL_SubPathFilename),  "Origin",  StdCopyStrBuf()));
		// windows needs backslashes in Origin; other systems use forward slashes
		if (pComp->isCompiler()) Origin.ReplaceChar(AltDirectorySeparator, DirectorySeparator);
	}
}
Exemplo n.º 20
0
void C4PacketLeagueRoundResults::CompileFunc(StdCompiler *pComp)
{
	pComp->Value(mkNamingAdapt(fSuccess, "Success", false));
	pComp->Value(mkNamingAdapt(sResultsString, "ResultString", StdCopyStrBuf()));
	pComp->Value(Players);
}