void CFilesPackage::PutFile(const CMemoryBuffer &buf , const nstring & name, const nstring & ext, const nstring &grs)
{
	TFileHeader fheader;
	memset(&fheader, 0, sizeof(TFileHeader));

	strcpy(fheader.file_name, name.c_str());
	strcpy(fheader.ext, ext.c_str());
	strcpy(fheader.resource_group, grs.c_str());

	if(!mIsOpened)
		throw NOVA_EXP("CFilesPackage::PutFile: package not opened, open package file first!", BAD_OPERATION);
	if(!mWritePackage)
		throw NOVA_EXP("CFilesPackage::PutFile: package opened for reading!", BAD_OPERATION);	

	if(InFileList(name))
		throw NOVA_EXP("CFilesPackage::PutFile: package already contains this name!", BAD_OPERATION);	

	fheader.pos = mFile->Tell() + sizeof(TFileHeader);
	fheader.number = mPackageMap.size() + 1;
	fheader.size = buf.GetBufferSize();

	mFile->Write(&fheader, sizeof(TFileHeader));
	mFile->Write(buf);

	std::pair<nstring, TFileHeader> pf;
	pf.first = name;
	pf.second = fheader;
	mPackageMap.insert(pf);

	mFile->Flush();
}
Пример #2
0
void CDevILCodec::CodeToFile(const nstring & filename, const CImage &image)
{
	ILuint imageid;
	CDevILFormats informat;
	informat.SetExFormat(image.GetPixelFormat());
	// Generate the main image name to use.
	ilGenImages(1, &imageid);

	// Bind this image name.
	ilBindImage(imageid);

	ilTexImage(image.GetWidth(), image.GetHeight(), image.GetDepth(), informat.GetInternalChannels(),
		informat.GetFormat(), IL_UNSIGNED_BYTE, image.GetBitsPtr());

	ilSaveImage(filename.c_str());

	ilDeleteImages(1, &imageid);

	ILenum Error = 0;
	if((Error = ilGetError()) != NULL)
	{
		nstring str("CDevILCodec::CodeToFile: ");
		str.append(iluErrorString(Error));
		throw NOVA_EXP(str.c_str(), BAD_OPERATION);
	}
}
Пример #3
0
void CDevILCodec::DecodeFromFile(const nstring & filename, CImage *image,
		CImageFormats::NovaPixelFormats format)
{
	ILuint image_id;
	// Generate the main image name to use.
	ilGenImages(1, &image_id);

	// Bind this image name.
	ilBindImage(image_id);

	if(!ilLoadImage(filename.c_str()))
	{
		ILenum Error = 0;
		if((Error = ilGetError()) != NULL)
		{
			nstring str("CDevILCodec::DecodeFromFile(): Can not load image file - ");
			str.append(iluErrorString(Error));
			throw NOVA_EXP(str.c_str(), BAD_OPERATION);
		}
	}

	image->GetImageSource().mHeight = ilGetInteger(IL_IMAGE_HEIGHT);
	image->GetImageSource().mWidth = ilGetInteger(IL_IMAGE_WIDTH);
	image->GetImageSource().mDepth = ilGetInteger(IL_IMAGE_DEPTH);

	//if (ilGetInteger(IL_IMAGE_ORIGIN) == IL_ORIGIN_LOWER_LEFT)
	//	iluFlipImage();

//	this->size = ilGetInteger(IL_IMAGE_SIZE_OF_DATA);
	if(format == CImageFormats::NF_DEFAULT)
	{
		CDevILFormats inf;
		inf.SetFormat(ilGetInteger(IL_IMAGE_FORMAT));
		format = inf.GetExFormat();
	}

	CDevILFormats informat;
	informat.SetExFormat(format);
	image->GetImageSource().mPixelFormat = format;

	size_t _size = image->GetWidth() * image->GetHeight() * image->GetDepth() * ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
	image->GetBits().FreeBuffer();
	image->GetBits().AllocBuffer(_size);

	ilCopyPixels(0, 0, 0, image->GetWidth(), image->GetHeight(), 
		image->GetDepth(), informat.GetFormat(), IL_UNSIGNED_BYTE, image->GetBits().GetBegin());

	ilDeleteImages(1, &image_id);

	ILenum Error = 0;
	if((Error = ilGetError()) != NULL)
	{
		nstring str("CDevILCodec::DecodeFromFile(): Can not load image file ");
		str.append(filename);
		str.append(", reason: ");
		str.append(iluErrorString(Error));
		throw NOVA_EXP(str.c_str(), BAD_OPERATION);
	}
}
Пример #4
0
nstring CStringUtils::ToLowerCase(const nstring &str)
{
	nova::nstringstream lower;
	for(nova::nUInt32 i = 0; i < str.size(); ++i)
		lower << (char)tolower(str[i]);

	return lower.str();
}
Пример #5
0
nstring CStringUtils::ToUpperCase(const nstring &str)
{
	nova::nstringstream upper;
	for(nova::nUInt32 i = 0; i < str.size(); ++i)
		upper << (char)toupper(str[i]);

	return upper.str();
}
Пример #6
0
CParser::values CParser::ParseString(nstring input)
{
	CParser::values result;
	while(true)
	{
		found = input.find("  ");
		if(found == nstring::npos)
			break;
		input.replace(found, 2, " ");
	}

	while(input[0] == ' ') 
		input.erase(input.begin());
	while(input[input.length() - 1] == ' ') 
		input.erase(input.end()-1);

	while(true)
	{
		found = input.find(' ');
		parstr.clear();
		memset(value, 0, LINE_LENGTH);
		if(found != nstring::npos)
		{
			input.copy(value, found);
			input.erase(0, found+1);
			parstr.append(value);
			result.push_back(parstr);
		}
		else if(found == nstring::npos)
		{
			result.push_back(input);
			break;
		}
	}


	return result;
}
void CResource::SerializeToXmlFile(const nstring &file)
{
    xmlTextWriterPtr writer = NULL;

    /* Create a new XmlWriter for uri, with no compression. */
    if((writer = xmlNewTextWriterFilename(file.c_str(), 0)) == NULL)
		NOVA_EXP("CResource::SerializeToXmlFile: Error creating the xml writer", BAD_OPERATION);

	// automatic indentation for readability
	xmlTextWriterSetIndent(writer, 1);

	if(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL) < 0)
		NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterStartDocument fail", BAD_OPERATION);

	if(xmlTextWriterStartElement(writer, BAD_CAST "NovaResource") < 0)
		NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterStartElement fail", BAD_OPERATION);

    if(xmlTextWriterWriteComment(writer, BAD_CAST "Common resource header") < 0)
		NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterWriteComment fail", BAD_OPERATION);

	if(xmlTextWriterStartElement(writer, BAD_CAST "ResourceHeader") < 0)
		NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterStartElement fail", BAD_OPERATION);

	if(xmlTextWriterWriteElement(writer, BAD_CAST "ResourceName", BAD_CAST mName.c_str()) < 0)
		NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterWriteElement fail", BAD_OPERATION);

	if(xmlTextWriterWriteElement(writer, BAD_CAST "ResourceGroup", BAD_CAST mGroup.c_str()) < 0)
		NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterWriteElement fail", BAD_OPERATION);

	if(xmlTextWriterStartElement(writer, BAD_CAST "ResourceData") < 0)
		NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterStartElement fail", BAD_OPERATION);

// Resource manager attribute
	if(xmlTextWriterWriteAttribute(writer, BAD_CAST "ResourceFactory", BAD_CAST GetCreator()->GetResourceFactoryName().c_str()) < 0)
		NOVA_EXP("CImage::SerializeToXmlFileImpl: xmlTextWriterWriteAttribute fail", BAD_OPERATION);

	SerializeToXmlFileImpl(writer);

    xmlTextWriterEndDocument(writer);
	xmlFreeTextWriter(writer);
}
Пример #8
0
void CSDLWorkspace::SaveContents(nstring & file)
{
	if(!mReady)
		return;

	SDL_Surface * dib = NULL;
	Uint32 rmask, gmask, bmask, amask;

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    rmask = 0xff000000;
    gmask = 0x00ff0000;
    bmask = 0x0000ff00;
    amask = 0x000000ff;
#else
    rmask = 0x000000ff;
    gmask = 0x0000ff00;
    bmask = 0x00ff0000;
    amask = 0xff000000;
#endif

	if((dib = SDL_CreateRGBSurface(SDL_SWSURFACE, mMetrics.width, mMetrics.height, 
		mVideo->vfmt->BitsPerPixel, rmask, gmask, bmask, amask)) == NULL)
		throw NOVA_EXP((nstring("CSDLWorkspace::SaveContents - Couldn't allocate dib surface: ")+
			nstring(SDL_GetError())).c_str(), BAD_OPERATION);

	SDL_Rect dsrect, screct;
	SDL_GetClipRect(dib, &dsrect);
	screct.x =  screct.y = 0;
	screct.w = mMetrics.width;
	screct.h = mMetrics.height;

	SDL_BlitSurface(mScreen, &screct, dib, &dsrect);
	SDL_SaveBMP(dib, file.c_str());
	SDL_FreeSurface(dib);

	dib = NULL;
}
Пример #9
0
double CStringUtils::StringToDouble(const nstring & str)
{
	return StringToDouble(str.c_str());
}
Пример #10
0
float CStringUtils::StringToFloat(const nstring & str)
{
	return StringToFloat(str.c_str());
}
Пример #11
0
nInt32 CStringUtils::StringToInt(const nstring & str)
{
	return StringToInt(str.c_str());
}
Пример #12
0
void CConsole::WriteLen(const nstring & message)
{
	WriteLen(message.c_str());
}
Пример #13
0
void CConsole::WriteLen(const nstring & message, const CColorRGB & pc)
{
	WriteLen(message.c_str(), pc);
}
Пример #14
0
nInt32 CParser::ParseStringRecurse(nstring input, CParser::values & result)
{
	if(input.empty())
		return 0;

	while(input[0] == ' ') {
		input.erase(input.begin());
		if(input.empty())
			return 0;
	}
	while(input[input.length() - 1] == ' ') {
		input.erase(input.end()-1);
		if(input.empty())
			return 0;
	}

	found = input.find(' ');
	parstr.clear();
	memset(value, 0, LINE_LENGTH);
	if(found != nstring::npos)
	{
		input.copy(value, found);
		input.erase(0, found+1);
		parstr.append(value);
		result.push_back(parstr);
	}
	else if(found == nstring::npos)
	{
		result.push_back(input);
		input.clear();
	}

	if(!input.empty())
		return ParseStringRecurse(input, result);

	return E_SUCCESS;
}
Пример #15
0
nInt32 CScene::LoadSceneForce(const nstring &pckFile, bool withResorces)
{
	xmlDocPtr doc = NULL;
	doc = xmlParseFile(pckFile.c_str());

	if(doc == NULL)
		throw NOVA_EXP("CScene::LoadSceneForce - Parse error of xml file from file", BAD_OPERATION);

	xmlNodePtr cur = xmlDocGetRootElement(doc);
	if(cur == NULL)
	{
		xmlFreeDoc(doc);
		throw NOVA_EXP("CScene::LoadSceneForce - Parse error xml root element.", BAD_OPERATION);
	}

	const xmlChar * caption = cur->name;
	if(xmlStrcmp(caption, (xmlChar *)"NovaScene"))
	{
		xmlFreeDoc(doc);
		throw NOVA_EXP("CScene::LoadSceneForce - this xml file is not a nova scene file.", BAD_OPERATION);
	}

	cur = cur->children;
	xmlNodePtr data = NULL;
	while(cur != NULL)
	{
		if(xmlIsBlankNode(cur))
		{
			cur = cur->next;
			continue;
		}

		if(withResorces)
		{
			if(!xmlStrcmp(cur->name, (xmlChar *)"SceneResources"))
			{
				data = cur->children;
				
				while(data != NULL)
				{
					if(xmlIsBlankNode(cur))
					{
						data = data->next;
						continue;
					}

					if(!xmlStrcmp(data->name, (xmlChar *) "ResourceFile"))
					{
						nova::CResourceManager::LoadResourceFromXml(reinterpret_cast<char *>(data->children->content));
					}

					data = data->next;
				}
			}
		}

		if(!xmlStrcmp(cur->name, (xmlChar *)"SceneContent"))
		{
			xmlChar * managerName = xmlGetProp(cur, (xmlChar *) "SceneManager");
			nova::CSmartPtr<CSceneManager> scenePtr = FindScene(reinterpret_cast<char *>(managerName));

			if(!scenePtr.IsNull())
			{
				scenePtr->DeSerializeSceneFromXml(cur->children);
				scenePtr->PrepareScene();
			}
			else
			{
				xmlFreeDoc(doc);
				throw NOVA_EXP(nstring("CScene::LoadSceneForce - can not find scene manager ") + reinterpret_cast<char *>(managerName), BAD_OPERATION);
			}
		}

		cur = cur->next;
	}

	xmlFreeDoc(doc);
	return 0;
}