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(); }
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); } }
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); } }
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); }
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; }
double CStringUtils::StringToDouble(const nstring & str) { return StringToDouble(str.c_str()); }
float CStringUtils::StringToFloat(const nstring & str) { return StringToFloat(str.c_str()); }
nInt32 CStringUtils::StringToInt(const nstring & str) { return StringToInt(str.c_str()); }
void CConsole::WriteLen(const nstring & message) { WriteLen(message.c_str()); }
void CConsole::WriteLen(const nstring & message, const CColorRGB & pc) { WriteLen(message.c_str(), pc); }
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; }