예제 #1
0
void CSoundAnimation::save()
{
	// File stream
	COFile file;
	vector<NLMISC::CSheetId>	sounds;

	// Open the file
	if (!file.open(_Filename.c_str()))
	{
		throw NLMISC::Exception("Can't open the file for writing");
	}

	// Create the XML stream
	COXml output;

	// Init
	if (output.init (&file, "1.0"))
	{
		xmlDocPtr xmlDoc = output.getDocument();

		// Create the first node
		xmlNodePtr root = xmlNewDocNode (xmlDoc, NULL, (const xmlChar*)"SOUNDANIMATION", NULL);
		xmlDocSetRootElement (xmlDoc, root);

		vector<CSoundAnimMarker*>::iterator iter;
		for (iter = _Markers.begin(); iter != _Markers.end(); iter++)
		{
			CSoundAnimMarker* marker = (*iter);

			set<string>::iterator iter;

			char s[64];
			smprintf(s, 64, "%f", marker->getTime());

			xmlNodePtr markerNode = xmlNewChild (root, NULL, (const xmlChar*)"MARKER", NULL);
			xmlSetProp (markerNode, (const xmlChar*) "time", (const xmlChar*) s);

			marker->getSounds(sounds);

			vector<NLMISC::CSheetId>::iterator iter2;
			for (iter2 = sounds.begin(); iter2 != sounds.end(); iter2++)
			{
				xmlNodePtr soundNode = xmlNewChild ( markerNode, NULL, (const xmlChar*)"SOUND", NULL );
				xmlSetProp (soundNode, (const xmlChar*)"name", (const xmlChar*)iter2->toString().c_str() /*CStringMapper::unmap(*iter2).c_str()*/);
			}

			sounds.clear();
		}

		// Flush the stream, write all the output file
		output.flush ();
	}

	// Close the file
	file.close ();

	_Dirty = false;
}
예제 #2
0
// ---------------------------------------------------------------------------
void CGeorgesImpl::createInstanceFile (const std::string &_sxFullnameWithoutExt, const std::string &_dfnname)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	CFormLoader formLoader;
	CFormDfn *dfn = formLoader.loadFormDfn (_dfnname.c_str(), false);
	if (!dfn)
	{
		char msg[512];
		smprintf (msg, 512, "Can't load DFN '%s'", _dfnname);
		theApp.outputError (msg);
		return;
	}

	NLMISC::CSmartPtr<NLGEORGES::UForm> Form = new CForm;

	std::string fullName;
	fullName = _sxFullnameWithoutExt + ".";

	int i = 0;
	if (_dfnname[i] == '.') ++i;
	for (; i < (int)_dfnname.size(); ++i)
	{
		if (_dfnname[i] == '.') break;
		fullName += _dfnname[i];
	}

	((CFormElmStruct*)&Form->getRootNode ())->build (dfn);
	COFile f;
	COXml ox;
	if (f.open (fullName))
	{
		ox.init(&f);
		((NLGEORGES::CForm*)((UForm*)Form))->write (ox.getDocument(), _sxFullnameWithoutExt.c_str ());
		ox.flush();
		f.close();
	}
	else
	{
		char msg[512];
		smprintf (msg, 512, "Can't write '%s'", fullName);
		theApp.outputError (msg);
		return;
	}
}
예제 #3
0
//-----------------------------------------------
// setDebugOutput :
// Set an output file to log debugs.
//-----------------------------------------------
void setDebugOutput(const std::string &filename)
{
	// Remove output
	if(filename.empty())
	{
		DebugFile.close();
		IsDebugFile = false;
		return;
	}

	// Open The Item Association File
	if(!DebugFile.open(filename, false, true))
	{
		nlwarning("setDebugOutput: Cannot Open the '%s'.", filename.c_str());
		IsDebugFile = false;
	}
	else
		IsDebugFile = true;
}// setDebugOutput //
예제 #4
0
//-----------------------------------------------
// load :
// Load all sheets.
//-----------------------------------------------
void CSheetManager::load(NLMISC::IProgressCallback &callBack, bool updatePackedSheet, bool needComputeVS, bool dumpVSIndex)
{
	// Open The Item Association File
	if(!fItemAssoc.open("item_association.dbg", false, true))
		nlwarning("CSheetManager::load: Cannot Open the 'item_association.txt'.");
	else
		ItemAssocFileOpen = true;

	// Initialize the Sheet DB.
	loadAllSheet(callBack, updatePackedSheet, needComputeVS, dumpVSIndex);

	// Close the Item Association File.
	fItemAssoc.close();
	ItemAssocFileOpen = false;

	// Optimize memory taken by all strings of all sheets
	ClientSheetsStrings.memoryCompress();

	return;
}// load //
예제 #5
0
/*
 * Save the ranges into a data file
 */
void				CRangeMirrorManager::saveRanges()
{
	try
	{
		COFile file;
		if ( file.open( RANGE_MANAGER_BACKUP_FILE ) )
		{
			COXml output;
			if ( output.init( &file, "1.0" ) )
			{
				output.serialCont( _RangeListByDataSet );
				output.flush();
			}
			file.close();
		}
		else
			throw EFileNotOpened( RANGE_MANAGER_BACKUP_FILE );
	}
	catch ( Exception& e )
	{
		nlwarning( "Can't save ranges: %s", e.what() );
	}
}
// ***************************************************************************
int main(int argc, char* argv[])
{
	// Filter addSearchPath
	NLMISC::createDebug();
	InfoLog->addNegativeFilter ("adding the path");

	// Register 3d
	registerSerial3d ();

	// Good number of args ?
	if (argc<4)
	{
		// Help message
		printf ("ig_lighter [directoryIn] [pathOut] [parameter_file] \n");
	}
	else
	{
		try
		{
			string	directoryIn= argv[1];
			string	pathOut= argv[2];
			string	paramFile= argv[3];
			CInstanceLighter::CLightDesc	lighterDesc;
			string	grFile, rbankFile;

			// Verify directoryIn.
			directoryIn= CPath::standardizePath(directoryIn);
			if( !CFile::isDirectory(directoryIn) )
			{
				printf("DirectoryIn %s is not a directory", directoryIn.c_str());
				return -1;
			}
			// Verify pathOut.
			pathOut= CPath::standardizePath(pathOut);
			if( !CFile::isDirectory(pathOut) )
			{
				printf("PathOut %s is not a directory", pathOut.c_str());
				return -1;
			}

			// Load and setup configFile.
			//=================
			CConfigFile parameter;
			// Load and parse the param file
			parameter.load (paramFile);

			// Get the search pathes
			CConfigFile::CVar &search_pathes = parameter.getVar ("search_pathes");
			uint path;
			for (path = 0; path < (uint)search_pathes.size(); path++)
			{
				// Add to search path
				CPath::addSearchPath (search_pathes.asString(path));
			}

			// Light direction
			CConfigFile::CVar &sun_direction = parameter.getVar ("sun_direction");
			lighterDesc.LightDirection.x=sun_direction.asFloat(0);
			lighterDesc.LightDirection.y=sun_direction.asFloat(1);
			lighterDesc.LightDirection.z=sun_direction.asFloat(2);
			lighterDesc.LightDirection.normalize ();

			// Grid size
			CConfigFile::CVar &quad_grid_size = parameter.getVar ("quad_grid_size");
			lighterDesc.GridSize=quad_grid_size.asInt();

			// Grid size
			CConfigFile::CVar &quad_grid_cell_size = parameter.getVar ("quad_grid_cell_size");
			lighterDesc.GridCellSize=quad_grid_cell_size.asFloat();

			// Shadows enabled ?
			CConfigFile::CVar &shadow = parameter.getVar ("shadow");
			lighterDesc.Shadow=shadow.asInt ()!=0;

			// OverSampling
				CConfigFile::CVar &ig_oversampling = parameter.getVar ("ig_oversampling");
				lighterDesc.OverSampling= ig_oversampling.asInt ();
			// validate value: 0, 2, 4, 8, 16
			lighterDesc.OverSampling= raiseToNextPowerOf2(lighterDesc.OverSampling);
			clamp(lighterDesc.OverSampling, 0U, 16U);
			if(lighterDesc.OverSampling<2)
				lighterDesc.OverSampling= 0;

			// gr
			CConfigFile::CVar &grbank = parameter.getVar ("grbank");
			grFile= grbank.asString ();

			// rbank
			CConfigFile::CVar &rbank = parameter.getVar ("rbank");
			rbankFile= rbank.asString ();

			// CellSurfaceLightSize;
			CConfigFile::CVar &cell_surface_light_size = parameter.getVar ("cell_surface_light_size");
			float cellSurfaceLightSize= cell_surface_light_size.asFloat ();
			if(cellSurfaceLightSize<=0)
				throw Exception("cell_surface_light_size must be > 0");

			// CellRaytraceDeltaZ
			CConfigFile::CVar &cell_raytrace_delta_z = parameter.getVar ("cell_raytrace_delta_z");
			float cellRaytraceDeltaZ= cell_raytrace_delta_z.asFloat ();


			// colIdentifierPrefix
			CConfigFile::CVar &col_identifier_prefix = parameter.getVar ("col_identifier_prefix");
			string colIdentifierPrefix= col_identifier_prefix.asString ();

			// colIdentifierSuffix
			CConfigFile::CVar &col_identifier_suffix = parameter.getVar ("col_identifier_suffix");
			string colIdentifierSuffix= col_identifier_suffix.asString ();

			// colIdentifierSuffix
			CConfigFile::CVar &build_debug_surface_shape = parameter.getVar ("build_debug_surface_shape");
			bool	buildDebugSurfaceShape= build_debug_surface_shape.asInt()!=0;
			

			// try to open gr and rbank
			CRetrieverBank		*retrieverBank= NULL;
			CGlobalRetriever	*globalRetriever= NULL;
			uint32		grFileDate= 0;
			uint32		rbankFileDate= 0;
			if( grFile!="" && rbankFile!="" )
			{
				CIFile	fin;
				// serial the retrieverBank. Exception if not found.
				fin.open(CPath::lookup(rbankFile));
				retrieverBank= new CRetrieverBank;
				retrieverBank->setNamePrefix(CFile::getFilenameWithoutExtension(rbankFile).c_str ());

				// Add the search path for LR files
				CPath::addSearchPath (CFile::getPath(rbankFile));

				fin.serial(*retrieverBank);
				fin.close();

				// serial the globalRetriever. Exception if not found.
				fin.open(CPath::lookup(grFile));
				globalRetriever= new CGlobalRetriever;

				// set the RetrieverBank before loading
				globalRetriever->setRetrieverBank(retrieverBank);
				fin.serial(*globalRetriever);
				fin.close();

				// Get File Dates
				rbankFileDate= CFile::getFileModificationDate(CPath::lookup(rbankFile));
				grFileDate= CFile::getFileModificationDate(CPath::lookup(grFile));

				// And init them.
				globalRetriever->initAll();
			}


			// Scan and load all files .ig in directories
			//=================
			vector<string>				listFile;
			vector<CInstanceGroup*>		listIg;
			vector<string>				listIgFileName;
			vector<string>				listIgPathName;
			CPath::getPathContent(directoryIn, false, false, true, listFile);
			for(uint iFile=0; iFile<listFile.size(); iFile++)
			{
				string	&igFile= listFile[iFile];
				// verify it is a .ig.
				if( CFile::getExtension(igFile) == "ig" )
				{
					// Read the InstanceGroup.
					CInstanceGroup	*ig= new CInstanceGroup;
					CIFile	fin;
					fin.open(CPath::lookup(igFile));
					fin.serial(*ig);

					// add to list.
					listIg.push_back(ig);
					listIgPathName.push_back(igFile);
					listIgFileName.push_back(CFile::getFilename(igFile));
				}
			}


			// For all ig, light them, and save.
			//=================
			for(uint iIg= 0; iIg<listIg.size(); iIg++)
			{
				string	fileNameIn= listIgFileName[iIg];
				string	fileNameOut= pathOut + fileNameIn;

				// If File Out exist 
				if(CFile::fileExists(fileNameOut))
				{
					// If newer than file In (and also newer than retrieverInfos), skip
					uint32		fileOutDate= CFile::getFileModificationDate(fileNameOut);
					if(	fileOutDate > CFile::getFileModificationDate(listIgPathName[iIg]) &&
						fileOutDate > rbankFileDate && 
						fileOutDate > grFileDate 
						)
					{
						printf("Skiping %s\n", fileNameIn.c_str());
						continue;
					}
				}

				// progress
				printf("Processing %s\n", fileNameIn.c_str());

				CInstanceGroup	igOut;

				// Export a debugSun Name.
				string	debugSunName;
				debugSunName= pathOut + "/" + CFile::getFilenameWithoutExtension(fileNameIn) + "_debug_sun_.shape";
				string	debugPLName;
				debugPLName= pathOut + "/" + CFile::getFilenameWithoutExtension(fileNameIn) + "_debug_pl_.shape";

				// light the ig.
				CIgLighterLib::CSurfaceLightingInfo	slInfo;
				slInfo.CellSurfaceLightSize= cellSurfaceLightSize;
				slInfo.CellRaytraceDeltaZ= cellRaytraceDeltaZ;
				slInfo.RetrieverBank= retrieverBank;
				slInfo.GlobalRetriever= globalRetriever;
				slInfo.IgFileName= CFile::getFilenameWithoutExtension(fileNameIn);
				slInfo.ColIdentifierPrefix= colIdentifierPrefix;
				slInfo.ColIdentifierSuffix= colIdentifierSuffix;
				slInfo.BuildDebugSurfaceShape= buildDebugSurfaceShape;
				slInfo.DebugSunName= debugSunName;
				slInfo.DebugPLName= debugPLName;
				lightIg(*listIg[iIg], igOut, lighterDesc, slInfo, fileNameIn.c_str ());

				// Save this ig.
				COFile	fout;
				fout.open(fileNameOut);
				fout.serial(igOut);
				fout.close();

				// skip a line
				printf("\n");
			}

		}
		catch (Exception& except)
		{
			// Error message
			nlwarning ("ERROR %s\n", except.what());
		}
	}


	// Landscape is not deleted, nor the instanceGroups, for faster quit.
	// Must disalbe BlockMemory checks (for pointLights).
	NL3D_BlockMemoryAssertOnPurge= false;


	// exit.
	return 0;
}
예제 #7
0
파일: misc.cpp 프로젝트: AzyxWare/ryzom
//-----------------------------------------------
// dump :
// Create a file with information to debug.
//-----------------------------------------------
void dump(const std::string &name)
{
	// Write information to start as the version
	COFile fStart;
	if(fStart.open(name + "_start.rec", false, false))
	{
		CVectorD currentPos = UserEntity->pos();
		fStart.serialVersion(RecordVersion);
		fStart.serial(currentPos);
		// Close the File.
		fStart.close();
	}
	else
		nlwarning("dump: cannot open/create the file '%s_start.rec'.", name.c_str());

	// Write the DB
	IngameDbMngr.write(name + "_db.rec");
	// Open the file.
	COFile f;
	if(f.open(name + ".rec", false, false))
	{
		// Dump entities.
		EntitiesMngr.dump(f);

		// Dump Client CFG.
		ClientCfg.serial(f);

		// Close the File.
		f.close();
	}
	else
		nlwarning("dump: cannot open/create the file '%s.rec'.", name.c_str());


	// Open the file.
	if(f.open(name + ".xml", false, true))
	{
		// Create the XML stream
		COXml output;
		// Init
		if(output.init (&f, "1.0"))
		{
			// Open the XML Dump.
			output.xmlPush("XML");

			// Dump Client CFG.
			ClientCfg.serial(output);

			// Dump entities.
			EntitiesMngr.dumpXML(output);

			// Close the XML Dump.
			output.xmlPop();

			// Flush the stream, write all the output file
			output.flush();
		}
		else
			nlwarning("dump: cannot initialize '%s.xml'.", name.c_str());
		// Close the File.
		f.close();
	}
	else
		nlwarning("dump: cannot open/create the file '%s.xml'.", name.c_str());
}// dump //
// ***************************************************************************
int		main(int argc, char *argv[])
{
	// Filter addSearchPath
	NLMISC::createDebug();
	NLMISC::InfoLog->addNegativeFilter ("adding the path");

	if (argc != 3)
	{
		nlwarning("usage : %s hlsinfo_dir output_name ", argv[0]);
		exit(-1);
	}

	// get all .hlsinfo file in directory.
	vector<string>		files;
	vector<string>		hlsInfofiles;
	NLMISC::CPath::getPathContent(argv[1], false, false, true, files);
	hlsInfofiles.reserve(files.size());
	uint	k;
	for (k = 0;  k < files.size(); ++k)
	{
		std::string fileExt = NLMISC::strupr(NLMISC::CFile::getExtension(files[k]));						
		if(fileExt=="HLSINFO")
			hlsInfofiles.push_back(files[k]);
	}

	//  If none, quit.
	if(hlsInfofiles.empty())
		exit(-1);

	// Concat all hlsinfo in a Bank
	CHLSTextureBank		textBank;
	for (k = 0;  k < hlsInfofiles.size(); ++k)
	{
		printf("HLSBank Process [%2d]\r", (uint)(100*k/hlsInfofiles.size()));
		try
		{
			CIFile	f(hlsInfofiles[k]);
			CHLSBankTextureInfo	textInfo;
			f.serial(textInfo);
			addTextToBank(textInfo, textBank);
		}
		catch(Exception &e)
		{
			nlwarning("ERROR: Unable to process %s. Reason: %s. Processing next", hlsInfofiles[k].c_str(), e.what());
		}
	}

	// compile it
	textBank.compile();

	// save the bank.
	COFile	fOut;
	try
	{
		if(!fOut.open(argv[2]))
			throw int(0);
		fOut.serial(textBank);
		fOut.close();
	}
	catch(Exception &e)
	{
		nlwarning("ERROR: Unable to write HLS Bank %s: %s", argv[2], e.what());
		exit(-1);
	}
	catch(...)
	{
		nlwarning("ERROR: Unable to write HLS Bank %s.", argv[2]);
		exit(-1);
	}

	return 0;
}
// ***************************************************************************
int main(int argc, char* argv[])
{
	// Register 3d
	registerSerial3d ();

	// Avoid some stupids warnings.
	NLMISC::createDebug();
	skipLog("variable \"RootConfigFilename\"");
	skipLog("variable \"anim_low_precision_tracks\"");
	skipLog("variable \"anim_sample_rate\"");
	InfoLog->addNegativeFilter("FEHTIMER>");
	InfoLog->addNegativeFilter("adding the path");


	// Good number of args ?
	if (argc<4)
	{
		// Help message
		printf ("anim_builder [directoryIn] [pathOut] [parameter_file] \n");
	}
	else
	{
		try
		{
			string	directoryIn= argv[1];
			string	pathOut= argv[2];
			string	paramFile= argv[3];

			// Verify directoryIn.
			directoryIn= CPath::standardizePath(directoryIn);
			if( !CFile::isDirectory(directoryIn) )
			{
				printf("DirectoryIn %s is not a directory", directoryIn.c_str());
				return -1;
			}
			// Verify pathOut.
			pathOut= CPath::standardizePath(pathOut);
			if( !CFile::isDirectory(pathOut) )
			{
				printf("PathOut %s is not a directory", pathOut.c_str());
				return -1;
			}

			// Our Animation optimizer.
			//=================
			CAnimationOptimizer		animationOptimizer;
			// Leave thresholds as default.
			animationOptimizer.clearLowPrecisionTracks();


			// Load and setup configFile.
			//=================
			CConfigFile parameter;
			// Load and parse the param file
			parameter.load (paramFile);

			// Get the Low Precision Track Key Names
			try
			{
				CConfigFile::CVar &anim_low_precision_tracks = parameter.getVar ("anim_low_precision_tracks");
				uint lpt;
				for (lpt = 0; lpt < (uint)anim_low_precision_tracks.size(); lpt++)
				{
					animationOptimizer.addLowPrecisionTrack(anim_low_precision_tracks.asString(lpt));
				}
			}
			catch(EUnknownVar &)
			{
				nlwarning("\"anim_low_precision_tracks\" not found in the parameter file. Add \"Finger\" and \"Ponytail\" by default");
				animationOptimizer.addLowPrecisionTrack("Finger");
				animationOptimizer.addLowPrecisionTrack("Ponytail");
			}

			// Sample Rate.
			try
			{
				CConfigFile::CVar &anim_sample_rate = parameter.getVar ("anim_sample_rate");
				float	sr= anim_sample_rate.asFloat(0);
				// Consider values > 1000 as error values.
				if(sr<=0 || sr>1000)
				{
					nlwarning("Bad \"anim_sample_rate\" value. Use Default of 30 fps.");
					animationOptimizer.setSampleFrameRate(30);
				}
				else
				{
					animationOptimizer.setSampleFrameRate(sr);
				}
			}
			catch(EUnknownVar &)
			{
				nlwarning("\"anim_sample_rate\" not found in the parameter file. Use Default of 30 fps.");
				animationOptimizer.setSampleFrameRate(30);
			}


			// Scan and load all files .ig in directories
			//=================
			uint		numSkipped= 0;
			uint		numBuilded= 0;
			vector<string>				listFile;
			CPath::getPathContent(directoryIn, false, false, true, listFile);
			for(uint iFile=0; iFile<listFile.size(); iFile++)
			{
				string	&igFile= listFile[iFile];
				// verify it is a .anim.
				if( CFile::getExtension(igFile) == "anim" )
				{
					string	fileNameIn= CFile::getFilename(igFile);
					string	fileNameOut= pathOut + fileNameIn;

					// skip the file?
					bool	mustSkip= false;

					// If File Out exist 
					if(CFile::fileExists(fileNameOut))
					{
						// If newer than file In, skip
						uint32		fileOutDate= CFile::getFileModificationDate(fileNameOut);
						if(	fileOutDate > CFile::getFileModificationDate(igFile) )
						{
							mustSkip= true;
						}
					}

					// If must process the file.
					if(!mustSkip)
					{
						// Read the animation.
						CAnimation	animIn;
						CIFile	fin;
						fin.open(CPath::lookup(igFile));
						fin.serial(animIn);

						// process.
						CAnimation	animOut;
						animationOptimizer.optimize(animIn, animOut);

						// Save this animation.
						COFile	fout;
						fout.open(fileNameOut);
						fout.serial(animOut);
						fout.close();

						numBuilded++;
					}
					else
					{
						numSkipped++;
					}

					// progress
					printf("Anim builded: %4d. Anim Skipped: %4d\r", numBuilded, numSkipped);
				}
			}

			// Add some info in the log.
			nlinfo("Anim builded: %4d", numBuilded);
			nlinfo("Anim skipped: %4d", numSkipped);

		}
		catch (Exception& except)
		{
			// Error message
			nlwarning ("ERROR %s\n", except.what());
		}
	}

	// exit.
	return 0;
}