Пример #1
0
unsigned int CCategoryHandler::GetCategory(std::string name)
{
	StringTrimInPlace(name);
	StringToLowerInPlace(name);

	if (name.empty())
		return 0; // the empty category

	unsigned int cat = 0;
	
	GML_STDMUTEX_LOCK(cat); // GetCategory

	if (categories.find(name) == categories.end()) {
		// this category is yet unknown
		if (firstUnused >= CCategoryHandler::GetMaxCategories()) {
			// skip this category
			LOG_L(L_WARNING, "too many unit categories (%i), skipping %s",
					firstUnused, name.c_str());
			cat = 0;
		} else {
			// create the category (bit field value)
			cat = (1 << firstUnused);
			//LOG_L(L_DEBUG, "New unit-category %s #%i", name.c_str(), firstUnused);
		}
		// if (cat == 0), this will prevent further warnings for this category
		categories[name] = cat;
		firstUnused++;
	} else {
		// this category is already known
		cat = categories[name];
	}

	return cat;
}
Пример #2
0
C3DOTextureHandler::UnitTexture* C3DOParser::GetTexture(S3DOPiece* obj, _Primitive* p, const std::vector<unsigned char>& fileBuf) const
{
	std::string texName;
	if (p->OffsetToTextureName != 0) {
		int unused;
		texName = GET_TEXT(p->OffsetToTextureName, fileBuf, unused);
		StringToLowerInPlace(texName);

		if (teamtex.find(texName) == teamtex.end()) {
			texName += "00";
		}
	} else {
		texName = "ta_color" + IntToString(p->PaletteEntry, "%i");
	}

	auto tex = texturehandler3DO->Get3DOTexture(texName);
	if (tex != nullptr)
		return tex;

	LOG_L(L_WARNING, "[%s] unknown 3DO texture \"%s\" for piece \"%s\"",
			__FUNCTION__, texName.c_str(), obj->name.c_str());

	// assign a dummy texture (the entire atlas)
	return texturehandler3DO->Get3DOTexture("___dummy___");
}
Пример #3
0
static void RegisterAssimpModelParsers(C3DModelLoader::ParserMap& parsers, CAssParser* assParser) {
	std::string extension;
	std::string extensions;
	Assimp::Importer importer;

	// get a ";" separated list of format extensions ("*.3ds;*.lwo;*.mesh.xml;...")
	importer.GetExtensionList(extensions);

	// do not ignore the last extension
	extensions += ";";

	LOG("[%s] supported Assimp model formats: %s",
			__FUNCTION__, extensions.c_str());

	size_t i = 0;
	size_t j = 0;

	// split the list, strip off the "*." extension prefixes
	while ((j = extensions.find(";", i)) != std::string::npos) {
		extension = extensions.substr(i, j - i);
		extension = extension.substr(extension.find("*.") + 2);

		StringToLowerInPlace(extension);

		if (parsers.find(extension) == parsers.end()) {
			parsers[extension] = assParser;
		}

		i = j + 1;
	}
}
Пример #4
0
void CArchiveScanner::ReadCacheData(const std::string& filename)
{
	if (!FileSystem::FileExists(filename)) {
		LOG_L(L_INFO, "Archive cache doesn't exist: %s", filename.c_str());
		return;
	}

	LuaParser p(filename, SPRING_VFS_RAW, SPRING_VFS_BASE);
	if (!p.Execute()) {
		LOG_L(L_ERROR, "Failed to parse archive cache: %s", p.GetErrorLog().c_str());
		return;
	}
	const LuaTable archiveCache = p.GetRoot();

	// Do not load old version caches
	const int ver = archiveCache.GetInt("internalVer", (INTERNAL_VER + 1));
	if (ver != INTERNAL_VER) {
		return;
	}

	const LuaTable archives = archiveCache.SubTable("archives");
	for (int i = 1; archives.KeyExists(i); ++i) {
		const LuaTable curArchive = archives.SubTable(i);
		const LuaTable archived = curArchive.SubTable("archivedata");
		std::string name = curArchive.GetString("name", "");

		ArchiveInfo& ai = archiveInfos[StringToLower(name)];
		ai.origName = name;
		ai.path     = curArchive.GetString("path", "");

		// do not use LuaTable.GetInt() for 32-bit integers, the Spring lua
		// library uses 32-bit floats to represent numbers, which can only
		// represent 2^24 consecutive integers
		ai.modified = strtoul(curArchive.GetString("modified", "0").c_str(), 0, 10);
		ai.checksum = strtoul(curArchive.GetString("checksum", "0").c_str(), 0, 10);
		ai.updated = false;

		ai.archiveData = CArchiveScanner::ArchiveData(archived, true);
		if (ai.archiveData.GetModType() == modtype::map) {
			AddDependency(ai.archiveData.GetDependencies(), "Map Helper v1");
		} else if (ai.archiveData.GetModType() == modtype::primary) {
			AddDependency(ai.archiveData.GetDependencies(), "Spring content v1");
		}
	}

	const LuaTable brokenArchives = archiveCache.SubTable("brokenArchives");
	for (int i = 1; brokenArchives.KeyExists(i); ++i) {
		const LuaTable curArchive = brokenArchives.SubTable(i);
		std::string name = curArchive.GetString("name", "");
		StringToLowerInPlace(name);

		BrokenArchive& ba = this->brokenArchives[name];
		ba.path = curArchive.GetString("path", "");
		ba.modified = strtoul(curArchive.GetString("modified", "0").c_str(), 0, 10);
		ba.updated = false;
		ba.problem = curArchive.GetString("problem", "unknown");
	}

	isDirty = false;
}
unsigned int CCategoryHandler::GetCategory(std::string name)
{
	StringToLowerInPlace(name);
	while(!name.empty() && *name.begin()==' ')
		name.erase(name.begin());
	if(name.empty())
		return 0;
	// Remove some categories that we don't think we need since we have too few of them.
	if (categories.find(name) == categories.end()) {
		if (name.find("ctrl") != std::string::npos
		 || name.find("arm") != std::string::npos
		 || name.find("core") != std::string::npos
		 || name.find("level") != std::string::npos
		 || name.find("energy") != std::string::npos
		 || name.find("storage") != std::string::npos
		 || name.find("defensive") != std::string::npos
		 || name.find("extractor") != std::string::npos
		 || name.find("metal") != std::string::npos
		 || name.find("torp") != std::string::npos)
			return 0;
		if(firstUnused > 31) {
			logOutput.Print("WARNING: too many unit categories %i missed %s", firstUnused + 1, name.c_str());
			return 0;
		}
		categories[name] = (1 << (firstUnused++));
//		logOutput.Print("New cat %s #%i",name.c_str(),firstUnused);
	}
	return categories[name];
}
Пример #6
0
void CUnitDefHandler::CreateYardMap(UnitDef* def, std::string yardmapStr)
{
	StringToLowerInPlace(yardmapStr);

	const int mw = def->xsize;
	const int mh = def->zsize;
	const int maxIdx = mw * mh;

	// create the yardmaps for each build-facing
	for (int u = 0; u < 4; u++) {
		def->yardmaps[u] = new unsigned char[maxIdx];
	}

	// Spring resolution's is double that of TA's (so 4 times as much area)
	unsigned char* originalMap = new unsigned char[maxIdx / 4];

	memset(originalMap, 255, maxIdx / 4);

	if (!yardmapStr.empty()) {
		std::string::iterator si = yardmapStr.begin();

		for (int y = 0; y < mh / 2; y++) {
			for (int x = 0; x < mw / 2; x++) {

					 if (*si == 'g') def->needGeo = true;
				else if (*si == 'c') originalMap[x + y * mw / 2] = 1; // blocking
				else if (*si == 'y') originalMap[x + y * mw / 2] = 0; // non-blocking

				// advance one non-space character (matching the column
				// <x> we have just advanced) in this row, and skip any
				// spaces
				do {
					si++;
				} while (si != yardmapStr.end() && *si == ' ');

				if (si == yardmapStr.end()) {
					// no more chars for remaining colums in this row
					break;
				}
			}

			if (si == yardmapStr.end()) {
				// no more chars for any remaining rows
 				break;
			}
 		}
 	}

	for (int y = 0; y < mh; y++) {
		for (int x = 0; x < mw; x++) {
			int orgIdx = x / 2 + y / 2 * mw / 2;
			char orgMapChar = originalMap[orgIdx];

			def->yardmaps[0][         (x + y * mw)                ] = orgMapChar;
			def->yardmaps[1][maxIdx - (mh * (x + 1) - (y + 1) + 1)] = orgMapChar;
			def->yardmaps[2][maxIdx - (x + y * mw + 1)            ] = orgMapChar;
			def->yardmaps[3][          mh * (x + 1) - (y + 1)     ] = orgMapChar;
		}
	}
}
Пример #7
0
unsigned int CCategoryHandler::GetCategory(std::string name)
{
	unsigned int cat = 0;

	StringToLowerInPlace(name);
	// remove leading spaces
	while (!name.empty() && (*name.begin() == ' ')) {
		name.erase(name.begin());
	}

	if (name.empty()) {
		// the empty category
		cat = 0;
	} else if (categories.find(name) == categories.end()) {
		// this category is yet unknown
		if (firstUnused >= CCategoryHandler::GetMaxCategories()) {
			// skip this category
			logOutput.Print("WARNING: too many unit categories (%i), skipping %s", firstUnused, name.c_str());
			cat = 0;
		} else {
			// create the category (bit field value)
			cat = (1 << firstUnused);
//			logOutput.Print("New cat %s #%i", name.c_str(), firstUnused);
		}
		// if (cat == 0), this will prevent further warnings for this category
		categories[name] = cat;
		firstUnused++;
	} else {
		// this category is already known
		cat = categories[name];
	}

	return cat;
}
int CDamageArrayHandler::GetTypeFromName(std::string name)
{
	StringToLowerInPlace(name);
	if(name2type.find(name)!=name2type.end())
		return name2type[name];
	return 0;
}
Пример #9
0
bool CglList::Filter(bool reset)
{
	std::string current = (*filteredItems)[place];
	std::vector<std::string>* destination = filteredItems == &temp1 ? &temp2 : &temp1;
	destination->clear();
	if (reset) filteredItems = &items; // reset filter
	for (std::vector<std::string>::const_iterator it = filteredItems->begin(); it != filteredItems->end(); ++it) {
		std::string lcitem(*it, 0, query.length());
		StringToLowerInPlace(lcitem);
		if (lcitem == query) {
			if (*it == current)
				place = destination->size();
			destination->push_back(*it);
		}
	}
	if (destination->empty()) {
		query = query.substr(0, query.length() - 1);
		return false;
	} else {
		filteredItems = destination;
		if(place>=(int)filteredItems->size())
			place=filteredItems->size()-1;
		if(place<0)
			place=0;
		return true;
	}
}
Пример #10
0
int CTextureAtlas::AddTexFromFile(std::string name, std::string file)
{
	StringToLowerInPlace(name);

	// if the file is already loaded, use that instead
	std::string lcFile = StringToLower(file);
	std::map<std::string, MemTex*>::iterator it = files.find(lcFile);
	if (it != files.end()) {
		MemTex* memtex = it->second;
		memtex->names.push_back(name);
		return 1;
	}


	CBitmap bitmap;
	if (!bitmap.Load(file)) {
		throw content_error("Could not load texture from file " + file);
	}

	if (bitmap.channels != 4 || bitmap.compressed) {
		// only suport RGBA for now
		throw content_error("Unsupported bitmap format in file " + file);
	}

	const int ret = AddTexFromMem(name, bitmap.xsize, bitmap.ysize, RGBA32, bitmap.mem);
	if (ret == 1) {
		files[lcFile] = memtextures.back();
	}
	return ret;
}
Пример #11
0
int CTextureAtlas::AddTexFromFile(std::string name, std::string file)
{
	StringToLowerInPlace(name);

	//if the file already loaded, use that instead
	std::string lcfile = StringToLower(file);
	std::map<std::string, MemTex*>::iterator it = files.find(lcfile);

	if(it != files.end())
	{
		MemTex *memtex = it->second;
		memtex->names.push_back(name);
		return 1;
	}

	CBitmap bitmap;

	if (!bitmap.Load(file))
		throw content_error("Could not load texture from file " + file);

	if(bitmap.type != CBitmap::BitmapTypeStandardRGBA)  //only suport rgba for now
		throw content_error("Unsupported bitmap format in file " + file);

	int ret = AddTexFromMem(name, bitmap.xsize, bitmap.ysize, RGBA32, bitmap.mem);

	if (ret == 1)
		files[lcfile] = memtextures.back();

	return ret;
}
Пример #12
0
void LuaMatUniforms::Parse(lua_State* L, const int tableIdx)
{
	auto uniformAndNames = GetUniformsAndPossibleNames();
	decltype(uniformAndNames) uniformAndNamesLower;
	for (auto& p: uniformAndNames) {
		uniformAndNamesLower[StringToLower(p.first)] = p.second;
	}

	for (lua_pushnil(L); lua_next(L, tableIdx) != 0; lua_pop(L, 1)) {
		if (!lua_israwstring(L, -2) || !lua_isnumber(L, -1))
			continue;

		// get the lua table key
		// and remove the "loc" at the end (cameraPosLoc -> camerapos)
		std::string uniformLocStr = luaL_tosstring(L, -2);
		StringToLowerInPlace(uniformLocStr);
		if (StringEndsWith(uniformLocStr, "loc")) {
			uniformLocStr.resize(uniformLocStr.size() - 3);
		}

		const auto uniformLocIt = uniformAndNamesLower.find(uniformLocStr);
		if (uniformLocIt == uniformAndNamesLower.end()) {
			LOG_L(L_WARNING, "LuaMaterial: unknown uniform \"%s\"", lua_tostring(L, -2));
			continue;
		}

		uniformLocIt->second->loc = static_cast<GLint>(lua_tonumber(L, -1));
	}
}
Пример #13
0
S3DOModel* C3DModelParser::Load3DO(string name,float scale,int side,const float3& offsets)
{
	StringToLowerInPlace(name);
	if(name.find(".s3o")!=string::npos)
		return units3oparser->LoadS3O(name,scale,side);
	else
		return unit3doparser->Load3DO(name,scale,side,offsets);
}
Пример #14
0
/**
 * Initializes variables in CGlobalUnsyncedStuff
 */
CGlobalUnsyncedStuff::CGlobalUnsyncedStuff()
{
	boost::uint64_t randnum;
	randnum = SDL_GetTicks();
	usRandSeed = randnum&0xffffffff;
	modGameTime = 0;
	gameTime = 0;
	lastFrameTime = 0;
	drawFrame = 1;
	viewSizeX = 100;
	viewSizeY = 100;
	pixelX = 0.01f;
	pixelY = 0.01f;
	aspectRatio = 1.0f;
	myPlayerNum = 0;
	myTeam = 1;
	myAllyTeam = 1;
	spectating           = false;
	spectatingFullView   = false;
	spectatingFullSelect = false;
	drawdebug = false;
	active = true;
	viewRange = MAX_VIEW_RANGE;
	timeOffset = 0;
	drawFog = true;
	teamNanospray = false;
	autoQuit = false;
	quitTime = 0;
#ifdef DIRECT_CONTROL_ALLOWED
	directControl = 0;
#endif
	compressTextures = false;
	atiHacks = false;
	supportNPOTs = GLEW_ARB_texture_non_power_of_two;
	{
		std::string vendor = std::string((char*)glGetString(GL_VENDOR));
		StringToLowerInPlace(vendor);
		bool isATi = (vendor.find("ati ") != string::npos);
		if (isATi) {
			std::string renderer = std::string((char*)glGetString(GL_RENDERER));
			StringToLowerInPlace(renderer);
			supportNPOTs = (renderer.find(" x") == string::npos && renderer.find(" 9") == string::npos); //! x-series doesn't support NPOTs
		}
	}
}
Пример #15
0
S3DOModel* C3DModelParser::Load3DModel(std::string name, float scale, int side)
{
	// TODO: abstract this
	StringToLowerInPlace(name);
	if (name.find(".s3o") != std::string::npos)
		return units3oparser->LoadS3O(name, scale, side);
	else
		return unit3doparser->Load3DO(name, scale, side);
}
Пример #16
0
C3DOTextureHandler::UnitTexture* C3DOTextureHandler::Get3DOTexture(std::string name)
{
	StringToLowerInPlace(name);
	std::map<std::string,UnitTexture*>::iterator tti;
	if((tti=textures.find(name))!=textures.end()){
		return tti->second;
	}
	LogObject() << "Unknown texture " << name.c_str() << "\n";
	return textures[" "];
}
Пример #17
0
CModel* C3DModelParser::Load3DO(string name,float scale,int side)
{
	CModel *mdl;
	StringToLowerInPlace(name);
	if(name.find(".s3o")!=string::npos)
		mdl = units3oparser->Load3DO(name,scale,side);
	else
		mdl = unit3doparser->Load3DO(name,scale,side);
	return mdl;
}
Пример #18
0
const UnitDef* CUnitDefHandler::GetUnitDefByName(std::string name)
{
	StringToLowerInPlace(name);

	std::map<std::string, int>::iterator it = unitDefIDsByName.find(name);
	if (it == unitDefIDsByName.end()) {
		return NULL;
	}

	const int defid = it->second;
	return unitDefs[defid];
}
Пример #19
0
/**
 * Get CRC of the data in the specified archive.
 * Returns 0 if file could not be opened.
 */
unsigned int CArchiveScanner::GetCRC(const std::string& arcName)
{
	CRC crc;
	CArchiveBase* ar;
	std::list<std::string> files;

	//! Try to open an archive
	ar = CArchiveFactory::OpenArchive(arcName);
	if (!ar) {
		return 0; // It wasn't an archive
	}

	//! Load ignore list.
	IFileFilter* ignore = CreateIgnoreFilter(ar);

	for (unsigned fid = 0; fid != ar->NumFiles(); ++fid) {
		std::string name;
		int size;
		ar->FileInfo(fid, name, size);

		if (ignore->Match(name)) {
			continue;
		}

		StringToLowerInPlace(name); //! case insensitive hash
		files.push_back(name);
	}

	files.sort();

	//! Add all files in sorted order
	for (std::list<std::string>::iterator i = files.begin(); i != files.end(); ++i) {
		const unsigned int nameCRC = CRC().Update(i->data(), i->size()).GetDigest();
		const unsigned fid = ar->FindFile(*i);
		const unsigned int dataCRC = ar->GetCrc32(fid);
		crc.Update(nameCRC);
		crc.Update(dataCRC);
	}

	delete ignore;
	delete ar;

	unsigned int digest = crc.GetDigest();

	//! A value of 0 is used to indicate no crc.. so never return that
	//! Shouldn't happen all that often
	if (digest == 0) {
		return 4711;
	} else {
		return digest;
	}
}
Пример #20
0
unsigned int CArchiveScanner::GetSingleArchiveChecksum(const std::string& name) const
{
	std::string lcname = filesystem.GetFilename(name);
	StringToLowerInPlace(lcname);

	std::map<std::string, ArchiveInfo>::const_iterator aii = archiveInfo.find(lcname);
	if (aii == archiveInfo.end()) {
		logOutput.Print(LOG_ARCHIVESCANNER, "%s checksum: not found (0)\n", name.c_str());
		return 0;
	}

	logOutput.Print(LOG_ARCHIVESCANNER, "%s checksum: %d/%u\n", name.c_str(), aii->second.checksum, aii->second.checksum);
	return aii->second.checksum;
}
Пример #21
0
unsigned int CArchiveScanner::GetSingleArchiveChecksum(const std::string& name) const
{
	std::string lcname = FileSystem::GetFilename(name);
	StringToLowerInPlace(lcname);

	std::map<std::string, ArchiveInfo>::const_iterator aii = archiveInfos.find(lcname);
	if (aii == archiveInfos.end()) {
		LOG_SL(LOG_SECTION_ARCHIVESCANNER, L_WARNING, "%s checksum: not found (0)", name.c_str());
		return 0;
	}

	LOG_S(LOG_SECTION_ARCHIVESCANNER,"%s checksum: %d/%u", name.c_str(), aii->second.checksum, aii->second.checksum);
	return aii->second.checksum;
}
Пример #22
0
S3DOPiece* C3DOParser::LoadPiece(S3DModel* model, int pos, S3DOPiece* parent, int* numobj, const std::vector<unsigned char>& fileBuf)
{
	(*numobj)++;

	_3DObject me;
	int curOffset = pos;
	READ_3DOBJECT(me, fileBuf, curOffset);

	std::string s = GET_TEXT(me.OffsetToObjectName, fileBuf, curOffset);
	StringToLowerInPlace(s);

	S3DOPiece* piece = new S3DOPiece();
		piece->name = s;
		piece->parent = parent;
		piece->offset.x =  me.XFromParent * SCALE_FACTOR_3DO;
		piece->offset.y =  me.YFromParent * SCALE_FACTOR_3DO;
		piece->offset.z = -me.ZFromParent * SCALE_FACTOR_3DO;
		piece->goffset = piece->offset + ((parent != NULL)? parent->goffset: ZeroVector);

	GetVertexes(&me, piece, fileBuf);
	GetPrimitives(piece, me.OffsetToPrimitiveArray, me.NumberOfPrimitives, ((pos == 0)? me.SelectionPrimitive: -1), fileBuf);
	piece->CalcNormals();
	piece->SetMinMaxExtends();

	piece->emitPos = ZeroVector;
	piece->emitDir = FwdVector;
	if (piece->vertexPos.size() >= 2) {
		piece->emitPos = piece->vertexPos[0];
		piece->emitDir = piece->vertexPos[1] - piece->vertexPos[0];
	} else 	if (piece->vertexPos.size() == 1) {
		piece->emitDir = piece->vertexPos[0];
	}

	model->mins = float3::min(piece->goffset + piece->mins, model->mins);
	model->maxs = float3::max(piece->goffset + piece->maxs, model->maxs);

	piece->SetCollisionVolume(CollisionVolume("box", piece->maxs - piece->mins, (piece->maxs + piece->mins) * 0.5f));

	if (me.OffsetToChildObject > 0) {
		piece->children.push_back(LoadPiece(model, me.OffsetToChildObject, piece, numobj, fileBuf));
	}

	if (me.OffsetToSiblingObject > 0) {
		parent->children.push_back(LoadPiece(model, me.OffsetToSiblingObject, parent, numobj, fileBuf));
	}

	return piece;
}
Пример #23
0
const UnitDef* CUnitDefHandler::GetUnitByName(std::string name)
{
	StringToLowerInPlace(name);

	std::map<std::string, int>::iterator it = unitID.find(name);
	if (it == unitID.end()) {
		return NULL;
	}

	const int id = it->second;
	if (!unitDefs[id].valid) {
		return NULL; // should not happen
	}

	return &unitDefs[id];
}
Пример #24
0
int CTextureAtlas::AddTexFromMem(std::string name, int xsize, int ysize, TextureType texType, void  *data)
{
	int gpp = GetBPP(texType);
	MemTex *memtex = SAFE_NEW MemTex;
	memtex->xsize = xsize;
	memtex->ysize = ysize;
	memtex->xpos = 0;
	memtex->ypos = 0;
	memtex->texType = texType;
	memtex->data = SAFE_NEW char[xsize*ysize*gpp/8];
	StringToLowerInPlace(name);
	memtex->names.push_back(name);
	memcpy(memtex->data, data, xsize*ysize*gpp/8);
	memtextures.push_back(memtex);

	return 1;
}
Пример #25
0
unsigned int CCategoryHandler::GetCategories(std::string names)
{
	unsigned int ret = 0;

	StringToLowerInPlace(names);

	// split on ' '
	std::stringstream namesStream(names);
	std::string name;
	while (std::getline(namesStream, name, ' ')) {
		if (!name.empty()) {
			ret |= GetCategory(name);
		}
	}

	return ret;
}
Пример #26
0
void* CTextureAtlas::AddTex(std::string name, int xsize, int ysize, TextureType texType)
{
	const int gpp = GetBPP(texType);
	const size_t data_size = xsize * ysize * gpp / 8;
	MemTex* memtex = new MemTex;
	memtex->xsize = xsize;
	memtex->ysize = ysize;
	memtex->texType = texType;
	memtex->data = new char[data_size];
	StringToLowerInPlace(name);
	memtex->names.push_back(name);
	memtextures.push_back(memtex);

	atlasAllocator->AddEntry(name, int2(xsize, ysize));

	return memtex->data;
}
Пример #27
0
CColorMap* CColorMap::LoadFromBitmapFile(std::string filename)
{
	std::string lowfilename = filename;
	StringToLowerInPlace(lowfilename);
	CColorMap *map;
	if(colorMapsMap.find(lowfilename)==colorMapsMap.end())
	{
		map = new CColorMap(filename);
		colorMapsMap[lowfilename] = map;
		colorMaps.push_back(map);
	}
	else
	{
		map = colorMapsMap.find(lowfilename)->second;
	}
	return map;
}
Пример #28
0
CArchive7Zip::CArchive7Zip(const std::string& name):
	CArchiveBuffered(name),
	curSearchHandle(1),
	isOpen(false)
{
	SZ_RESULT res;

	archiveStream.File = fopen(name.c_str(), "rb");
	if (archiveStream.File == 0)
		return;

	archiveStream.InStream.Read = SzFileReadImp;
	archiveStream.InStream.Seek = SzFileSeekImp;

	allocImp.Alloc = SzAlloc;
	allocImp.Free = SzFree;

	allocTempImp.Alloc = SzAllocTemp;
	allocTempImp.Free = SzFreeTemp;

	InitCrcTable();
	SzArDbExInit(&db);
	res = SzArchiveOpen(&archiveStream.InStream, &db, &allocImp, &allocTempImp);
	if (res != SZ_OK)
		return;

	isOpen = true;

	// Get contents of archive and store name->int mapping
	for (unsigned i = 0; i < db.Database.NumFiles; ++i) {
		CFileItem* fi = db.Database.Files + i;
		if ((fi->Size >= 0) && !fi->IsDirectory) {
			std::string name = fi->Name;
			//SetSlashesForwardToBack(name);

			FileData fd;
			fd.origName = name;
			fd.fp = i;
			fd.size = fi->Size;
			fd.crc = (fi->Size > 0) ? fi->FileCRC : 0;

			StringToLowerInPlace(name);
			fileData[name] = fd;
		}
	}
}
CTextureHandler::UnitTexture* CTextureHandler::GetTATexture(std::string name, int team, int teamTex)
{
	if(teamTex){
		char c[50];
		sprintf(c,"team%d_",team);
		name=string(c)+name;
	}

	StringToLowerInPlace(name);

	std::map<std::string,UnitTexture*>::iterator tti;
	if((tti=textures.find(name))!=textures.end()){
		return tti->second;
	}
	logOutput << "Unknown texture " << name.c_str() << "\n";
	return textures[" "];
}
Пример #30
0
size_t CTextureAtlas::AddTex(std::string name, int xsize, int ysize, TextureType texType)
{
	memTextures.emplace_back();
	MemTex& tex = memTextures.back();

	tex.xsize = xsize;
	tex.ysize = ysize;
	tex.texType = texType;
	tex.mem.resize((xsize * ysize * GetBPP(texType)) / 8, 0);

	StringToLowerInPlace(name);
	tex.names.emplace_back(std::move(name));

	atlasAllocator->AddEntry(tex.names.back(), int2(xsize, ysize));

	return (memTextures.size() - 1);
}