本文整理汇总了C++中CIFile类的典型用法代码示例。如果您正苦于以下问题:C++ CIFile类的具体用法?C++ CIFile怎么用?C++ CIFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CIFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: playSync
/// Play from memory.
bool CMusicChannelFMod::playSync(const std::string &filepath, bool loop)
{
CIFile ifile;
ifile.allowBNPCacheFileOnOpen(false);
ifile.setCacheFileOnOpen(false);
ifile.open(filepath);
// try to load the music in memory
uint32 fs = ifile.getFileSize();
if (!fs) {
nlwarning("NLSOUND FMod Driver: Empty music file");
return false;
}
// read Buffer
nlassert(!_MusicBuffer);
_MusicBuffer = new uint8[fs];
try {
ifile.serialBuffer(_MusicBuffer, fs);
}
catch (...)
{
nlwarning("NLSOUND FMod Driver: Error while reading music file");
delete[] _MusicBuffer;
_MusicBuffer = NULL;
return false;
}
// open FMOD stream
_MusicStream = FSOUND_Stream_Open((const char*)_MusicBuffer,
FSOUND_2D | FSOUND_LOADMEMORY | (loop ? FSOUND_LOOP_NORMAL : FSOUND_LOOP_OFF), 0, fs);
if (!_MusicStream)
{
nlwarning("NLSOUND FMod Driver: Error while creating the FMOD stream for music file");
delete[] _MusicBuffer;
_MusicBuffer = NULL;
return false;
}
if (!playStream())
{
nlwarning("NLSOUND FMod Driver: Error While trying to play sync music file");
FSOUND_Stream_Close(_MusicStream);
_MusicStream = NULL;
delete[] _MusicBuffer;
_MusicBuffer = NULL;
return false;
}
return true;
}
示例2: computeBBoxFromVillage
//=======================================================================================
// ryzom specific build bbox of a village in a zone
static void computeBBoxFromVillage(const NLGEORGES::UFormElm *villageItem,
const std::string &continentName,
uint villageIndex,
TShapeMap &shapeMap,
CLightingBBox &result
)
{
result = CLightingBBox();
const NLGEORGES::UFormElm *igNamesItem;
if (! (villageItem->getNodeByName (&igNamesItem, "IgList") && igNamesItem) )
{
nlwarning("No list of IGs was found in the continent form %s, village #%d", continentName.c_str(), villageIndex);
return;
}
// Get number of village
uint numIgs;
nlverify (igNamesItem->getArraySize (numIgs));
const NLGEORGES::UFormElm *currIg;
for(uint l = 0; l < numIgs; ++l)
{
if (!(igNamesItem->getArrayNode (&currIg, l) && currIg))
{
nlwarning("Couldn't get ig #%d in the continent form %s, in village #%d", l, continentName.c_str(), villageIndex);
continue;
}
const NLGEORGES::UFormElm *igNameItem;
currIg->getNodeByName (&igNameItem, "IgName");
std::string igName;
if (!igNameItem->getValue (igName))
{
nlwarning("Couldn't get ig name of ig #%d in the continent form %s, in village #%d", l, continentName.c_str(), villageIndex);
continue;
}
if (igName.empty())
{
nlwarning("Ig name of ig #%d in the continent form %s, in village #%d is an empty string", l, continentName.c_str(), villageIndex);
continue;
}
igName = CFile::getFilenameWithoutExtension(igName) + ".ig";
string nameLookup = CPath::lookup (igName, false, true);
if (!nameLookup.empty())
{
CIFile inputFile;
// Try to open the file
if (inputFile.open (nameLookup))
{
CInstanceGroup group;
try
{
CLightingBBox currBBox;
group.serial (inputFile);
computeIGBBox(group, currBBox, shapeMap);
result.makeUnion(currBBox);
}
catch(NLMISC::Exception &)
{
nlwarning ("Error while loading instance group %s\n", igName.c_str());
continue;
}
inputFile.close();
}
else
{
// Error
nlwarning ("Can't open instance group %s\n", igName.c_str());
}
}
}
}
示例3: computeIGBBox
/** Load and compute the bbox of the models that are contained in a given instance group
* \return true if the computed bbox is valid
*/
static void computeIGBBox(const NL3D::CInstanceGroup &ig, CLightingBBox &result, TShapeMap &shapeMap)
{
result = CLightingBBox(); // starts with void result
bool firstBBox = true;
/// now, compute the union of all bboxs
for (CInstanceGroup::TInstanceArray::const_iterator it = ig._InstancesInfos.begin(); it != ig._InstancesInfos.end(); ++it)
{
CLightingBBox currBBox;
bool validBBox = false;
/// get the bbox from file or from map
if (shapeMap.count(it->Name)) // already loaded ?
{
currBBox = shapeMap[it->Name];
validBBox = true;
}
else // must load the shape to get its bbox
{
std::string shapePathName;
std::string toLoad = it->Name;
if (getExt(toLoad).empty()) toLoad += ".shape";
shapePathName = NLMISC::CPath::lookup(toLoad, false, false);
if (shapePathName.empty())
{
nlwarning("Unable to find shape %s", it->Name.c_str());
}
else
{
CIFile shapeInputFile;
if (shapeInputFile.open (shapePathName.c_str()))
{
NL3D::CShapeStream shapeStream;
try
{
shapeStream.serial (shapeInputFile);
// NB Nico :
// Deal with water shape -> their 'Receiving' box is set to 'void'
// this prevent the case where a huge surface of water will cause the zone it is attached to (the 'Zone'
// field in the villages sheets) to load all the zones that the water surface cover. (This caused
// an 'out of memory error' in the zone lighter due to too many zone being loaded)
// FIXME : test for water case hardcoded for now
CWaterShape *ws = dynamic_cast<CWaterShape *>(shapeStream.getShapePointer());
if (ws)
{
CAABBox bbox;
shapeStream.getShapePointer()->getAABBox(bbox);
currBBox.OccludingBox = CPotentialBBox(bbox); // occluding box is used, though the water shape
// doesn't cast shadow -> the tiles flag ('above', 'intersect', 'below water')
// are updated inside the zone_lighter
currBBox.ReceivingBox.IsVoid = true; // no lighted by the zone lighter !!!
currBBox.removeVoid();
shapeMap[it->Name] = currBBox;
}
else
{
CAABBox bbox;
shapeStream.getShapePointer()->getAABBox(bbox);
currBBox.OccludingBox = CPotentialBBox(bbox);
currBBox.ReceivingBox = CPotentialBBox(bbox);
currBBox.removeVoid();
shapeMap[it->Name] = currBBox;
}
validBBox = true;
}
catch (NLMISC::Exception &e)
{
nlwarning("Error while loading shape %s. \n\t Reason : %s ", it->Name.c_str(), e.what());
}
}
else
{
nlwarning("Unable to open shape file %s to get its bbox", it->Name.c_str());
}
}
}
if (validBBox)
{
/// build the model matrix
NLMISC::CMatrix mat;
mat.scale(it->Scale);
NLMISC::CMatrix rotMat;
rotMat.setRot(it->Rot);
mat = rotMat * mat;
mat.setPos(it->Pos);
/// transform the bbox
currBBox.transform(mat);
currBBox.removeVoid();
if (firstBBox)
{
//.........这里部分代码省略.........
示例4: main
//.........这里部分代码省略.........
}
// Min z
float minZ=FLT_MAX;
// Make a quad grid
CQuadGrid<CZoneDescriptorBB> quadGrid;
quadGrid.create (256, 100);
// The dependencies list
vector< CZoneDependencies > dependencies;
dependencies.resize ((lastX-firstX+1)*(lastY-firstY+1));
// Ryzom specific: build bbox for villages
TString2LightingBBox villagesBBox;
computeIGBBoxFromContinent(properties, shapeMap, villagesBBox);
// Insert each zone in the quad tree
sint y, x;
for (y=firstY; y<=lastY; y++)
for (x=firstX; x<=lastX; x++)
{
// Progress
progress ("Build bounding boxes", (float)(x+y*lastX)/(float)(lastX*lastY));
// Make a zone file name
string zoneName;
getZoneNameByCoord (x, y, zoneName);
// Open the file
CIFile file;
if (file.open (dir+zoneName+ext))
{
// The zone
CZone zone;
try
{
// Serial the zone
file.serial (zone);
/// get bbox from the ig of this zone
CLightingBBox igBBox;
if (computeDependenciesWithIgs)
{
computeZoneIGBBox(zoneName.c_str(), igBBox, shapeMap, villagesBBox);
}
// Create a zone descriptor
NLMISC::CAABBox zoneBox;
zoneBox.setCenter(zone.getZoneBB().getCenter());
zoneBox.setHalfSize(zone.getZoneBB().getHalfSize());
CLightingBBox zoneLBox;
zoneLBox.OccludingBox = zoneLBox.ReceivingBox = zoneBox; // can't be void
zoneLBox.makeUnion(igBBox);
nlassert(!zoneLBox.ReceivingBox.IsVoid);
//
CZoneDescriptorBB zoneDesc;
zoneDesc.X=x;
zoneDesc.Y=y;
示例5: OnOpenDocument
BOOL CTexGenThumbnailDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
CIFile file;
if (file.open (lpszPathName))
{
try
{
NLTEXGEN::CTexGenDocument doc;
file.serial(doc);
CFloatBitmap bitmap;
CRenderParameter renderParameters (false, false, false);
doc.Operators[0]->eval (bitmap, renderParameters);
if ((bitmap.getWidth() != 0) && (bitmap.getHeight() != 0))
{
bitmap.resample (m_sizeDoc.cx, m_sizeDoc.cy);
_DibBitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFO);
_DibBitmapInfo.bmiHeader.biWidth = m_sizeDoc.cx;
_DibBitmapInfo.bmiHeader.biHeight = m_sizeDoc.cy;
_DibBitmapInfo.bmiHeader.biPlanes = 1;
_DibBitmapInfo.bmiHeader.biBitCount = 32;
_DibBitmapInfo.bmiHeader.biCompression = BI_RGB;
_DibBitmapInfo.bmiHeader.biSizeImage = 0;
_DibBitmapInfo.bmiHeader.biXPelsPerMeter = 0;
_DibBitmapInfo.bmiHeader.biYPelsPerMeter = 0;
_DibBitmapInfo.bmiHeader.biClrUsed = 0;
_DibBitmapInfo.bmiHeader.biClrImportant = 0;
HWND desktop = ::GetDesktopWindow();
HDC dc = ::GetDC (desktop);
nlverify(_Dib = CreateDIBSection(dc, &_DibBitmapInfo, DIB_RGB_COLORS, (void**)&_DibBits, NULL, 0));
const float *pixels = bitmap.getPixels();
if (pixels)
{
uint8 *dst = _DibBits;
const uint height = m_sizeDoc.cy;
uint y;
for (y=0; y<height; y++)
{
const uint width = m_sizeDoc.cx*4 + y*m_sizeDoc.cx*4;
uint i = y*m_sizeDoc.cx*4;
uint j = (height-y-1)*m_sizeDoc.cx*4;
for (;i<width; i+=4, j+=4)
{
/*if (alpha)
{
int r = (int)(pixels[i+0] * 255.f);
clamp (r, 0, 255);
dst[j+0] = r;
dst[j+1] = r;
dst[j+2] = r;
}
else*/
{
int r = (int)(pixels[i+0] * 255.f);
int g = (int)(pixels[i+1] * 255.f);
int b = (int)(pixels[i+2] * 255.f);
clamp (r, 0, 255);
clamp (g, 0, 255);
clamp (b, 0, 255);
dst[j+0] = b;
dst[j+1] = g;
dst[j+2] = r;
}
}
}
}
::ReleaseDC (desktop, dc);
return TRUE;
}
}
catch (Exception &)
{
}
}
return FALSE;
}
示例6: H_AUTO
void CSheetId::loadSheetId ()
{
H_AUTO(CSheetIdInit);
//nldebug("Loading sheet_id.bin");
// Open the sheet id to sheet file name association
CIFile file;
std::string path = CPath::lookup("sheet_id.bin", false, false);
if(!path.empty() && file.open(path))
{
// clear entries
_FileExtensions.clear ();
_SheetIdToName.clear ();
_SheetNameToId.clear ();
// reserve space for the vector of file extensions
_FileExtensions.resize(1 << (NL_SHEET_ID_TYPE_BITS));
// Get the map from the file
map<uint32,string> tempMap;
contReset(tempMap);
file.serialCont(tempMap);
file.close();
if (_RemoveUnknownSheet)
{
uint32 removednbfiles = 0;
uint32 nbfiles = (uint32)tempMap.size();
// now we remove all files that not available
map<uint32,string>::iterator itStr2;
for( itStr2 = tempMap.begin(); itStr2 != tempMap.end(); )
{
if (CPath::exists ((*itStr2).second))
{
++itStr2;
}
else
{
map<uint32,string>::iterator olditStr = itStr2;
//nldebug ("Removing file '%s' from CSheetId because the file not exists", (*olditStr).second.c_str ());
itStr2++;
tempMap.erase (olditStr);
removednbfiles++;
}
}
nlinfo ("SHEETID: Removed %d files on %d from CSheetId because these files doesn't exists", removednbfiles, nbfiles);
}
// Convert the map to one big string and 1 static map (id to name)
{
// Get the number and size of all strings
vector<CChar> tempVec; // Used to initialise the first map
uint32 nNb = 0;
uint32 nSize = 0;
map<uint32,string>::const_iterator it = tempMap.begin();
while (it != tempMap.end())
{
nSize += (uint32)it->second.size()+1;
nNb++;
it++;
}
// Make the big string (composed of all strings) and a vector referencing each string
tempVec.resize(nNb);
_AllStrings.Ptr = new char[nSize];
it = tempMap.begin();
nSize = 0;
nNb = 0;
while (it != tempMap.end())
{
tempVec[nNb].Ptr = _AllStrings.Ptr+nSize;
strcpy(_AllStrings.Ptr+nSize, it->second.c_str());
toLower(_AllStrings.Ptr+nSize);
nSize += (uint32)it->second.size()+1;
nNb++;
it++;
}
// Finally build the static map (id to name)
_SheetIdToName.reserve(tempVec.size());
it = tempMap.begin();
nNb = 0;
while (it != tempMap.end())
{
_SheetIdToName.add(pair<uint32, CChar>(it->first, CChar(tempVec[nNb])));
nNb++;
it++;
}
// The vector of all small string is not needed anymore we have all the info in
// the static map and with the pointer AllStrings referencing the beginning.
}
// Build the invert map (Name to Id) & file extension vector
{
uint32 nSize = (uint32)_SheetIdToName.size();
_SheetNameToId.reserve(nSize);
CStaticMap<uint32,CChar>::iterator itStr;
//.........这里部分代码省略.........
示例7: main
//.........这里部分代码省略.........
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;
示例8: main
int main(int argc, char* argv[])
{
// Filter addSearchPath
NLMISC::createDebug();
InfoLog->addNegativeFilter ("adding the path");
// Register 3d
registerSerial3d ();
// Good number of args ?
if (argc<5)
{
// Help message
printf ("%s [zonein.zonel] [igout.ig] [parameter_file] [dependancy_file]\n", argv[0]);
}
else
{
// Ok, read the zone
CIFile inputFile;
// Get extension
string ext=getExt (argv[1]);
string dir=getDir (argv[1]);
// Open it for reading
if (inputFile.open (argv[1]))
{
// Zone name
string zoneName=toLower (string ("zone_"+getName (argv[1])));
// Load the zone
try
{
// Read the config file
CConfigFile parameter;
// Load and parse the parameter file
parameter.load (argv[3]);
// **********
// *** Build the lighter descriptor
// **********
CInstanceLighter::CLightDesc lighterDesc;
// 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;
// For ig of Zones, never disable Sun contrib !!!
lighterDesc.DisableSunContribution= false;
// 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));
}
// A landscape allocated with new: it is not delete because destruction take 3 secondes more!
CLandscape *landscape=new CLandscape;
landscape->init();
// A zone lighter
CMyIgZoneLighter lighter;
lighter.init ();
// A vector of zone id
vector<uint> listZoneId;
// The zone
CZone zone;
// List of ig
//.........这里部分代码省略.........
示例9: CSheetId
void CRingAccess::init()
{
if (_Initialised ) { return; } // no double initialisation
_CustomNpcSheetId.clear();
//CSheetId::init() must be called first
_CustomNpcSheetId.insert(CSheetId("basic_matis_male.creature"));
_CustomNpcSheetId.insert(CSheetId("basic_fyros_male.creature"));
_CustomNpcSheetId.insert(CSheetId("basic_tryker_male.creature"));
_CustomNpcSheetId.insert(CSheetId("basic_zorai_male.creature"));
_CustomNpcSheetId.insert(CSheetId("basic_matis_female.creature"));
_CustomNpcSheetId.insert(CSheetId("basic_fyros_female.creature"));
_CustomNpcSheetId.insert(CSheetId("basic_tryker_female.creature"));
_CustomNpcSheetId.insert(CSheetId("basic_zorai_female.creature"));
for (uint32 i = 0 ; i <= 184 ; ++i)
{
_R2PlotItemSheetId.insert( CSheetId( NLMISC::toString("r2_plot_item_%d.sitem", i)));
}
_SheetIdToAccess.clear();//only usefull when manualy re init file
// File stream
CIFile file;
std::string pathFileName = CPath::lookup(RingAccessFilename, false, false, false);
// Open the file
if (pathFileName.empty() || !file.open(pathFileName.c_str()))
{
nlinfo("Can't open the file for reading : %s", RingAccessFilename.c_str());
return;
}
// Create the XML stream
CIXml input;
// Init
if(input.init(file))
{
xmlNodePtr entitiesAccess = input.getRootNode();
xmlNodePtr entityAccess = input.getFirstChildNode(entitiesAccess, "entityAccess");
while (entityAccess != 0)
{
// island name
CXMLAutoPtr namePtr( (const char*) xmlGetProp(entityAccess, (xmlChar*) "name") );
CXMLAutoPtr packagePtr( (const char*) xmlGetProp(entityAccess, (xmlChar*) "package") );
CXMLAutoPtr sheetClientPtr( (const char*) xmlGetProp(entityAccess, (xmlChar*) "sheetClient") );
CXMLAutoPtr sheetPtr( (const char*) xmlGetProp(entityAccess, (xmlChar*) "sheetServer") );
if (!namePtr.getDatas()|| !packagePtr.getDatas() || !sheetPtr.getDatas() || !sheetPtr.getDatas())
{
nlerror( "Syntax error in %s", pathFileName.c_str());
return;
}
std::string sheet( sheetPtr.getDatas() );
std::string package( packagePtr.getDatas() );
std::string sheetClient(sheetClientPtr.getDatas());
CSheetId sheetClientId(sheetClient);
CSheetId sheetId; // no sheet server
if (sheet.empty())
{
bool ok = _SheetIdToAccess.insert( std::make_pair(std::make_pair(sheetClientId, sheetId), package)).second;
if (!ok)
{
std::string previousPackage = _SheetIdToAccess[std::make_pair(sheetClientId, sheetId)];
// only display warning if one key has multiple package
if ( previousPackage != package )
{
nlwarning("%s: Entity %s sheet(%s) is defined more than once with different package definition. Previous definition is '%s', current definition is '%s'", RingAccessFilename.c_str(), namePtr.getDatas(), sheetClientPtr.getDatas(), previousPackage.c_str(), package.c_str());
}
}
}
else
{
sheetId = CSheetId(sheet);
if (_CustomNpcSheetId.find(sheetClientId) != _CustomNpcSheetId.end())
{
bool ok = _SheetIdToAccess.insert( std::make_pair(std::make_pair(sheetClientId, sheetId), package)).second;
if (!ok)
{
std::string previousPackage = _SheetIdToAccess[std::make_pair(sheetClientId, sheetId)];
// only display warning if one key has multiple package
if ( previousPackage != package )
{
//.........这里部分代码省略.........
示例10: main
//.........这里部分代码省略.........
}
// 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;
}
示例11: nlinfo
/*
* init()
*/
bool CPrimChecker::build(const string &primitivesPath, const string &igLandPath, const string &igVillagePath, const string &outputDirectory, bool forceRebuild)
{
if (Verbose)
nlinfo("Checking pacs.packed_prims consistency");
NLLIGO::Register();
// Init ligo
if (!LigoConfig.readPrimitiveClass ("world_editor_classes.xml", false))
{
// Should be in l:\leveldesign\world_edit_files
nlwarning ("Can't load ligo primitive config file world_editor_classes.xml");
return false;
}
uint i, j;
string outputfname = CPath::standardizePath(outputDirectory)+"pacs.packed_prims";
_Grid.clear();
vector<string> files;
CPath::getPathContent(primitivesPath, true, false, true, files);
for (i=0; i<files.size(); ++i)
{
if (CFile::getExtension(files[i]) == "primitive")
{
readFile(files[i]);
}
}
files.clear();
CPath::getPathContent(igLandPath, true, false, true, files);
CPath::getPathContent(igVillagePath, true, false, true, files);
set<string> noWaterShapes;
for (i=0; i<files.size(); ++i)
{
try
{
// load ig associated to the zone
string igname = files[i];
string ignamelookup = CPath::lookup(igname);
//nlinfo("Reading ig '%s'", ignamelookup.c_str());
CIFile igStream(ignamelookup);
CInstanceGroup ig;
igStream.serial(ig);
// search in group for water instance
for (j=0; j<ig._InstancesInfos.size(); ++j)
{
string shapeName = ig._InstancesInfos[j].Name;
if (CFile::getExtension (shapeName) == "")
shapeName += ".shape";
if (noWaterShapes.find(shapeName) != noWaterShapes.end())
continue;
string shapeNameLookup = CPath::lookup (shapeName, false, false);
if (!shapeNameLookup.empty())
{
CIFile f;
if (f.open (shapeNameLookup))
{
CShapeStream shape;
shape.serial(f);
CWaterShape *wshape = dynamic_cast<CWaterShape*>(shape.getShapePointer());
if (wshape == NULL)
{
noWaterShapes.insert(shapeName);
continue;
}
//nlinfo("Render water shape '%s'", shapeNameLookup.c_str());
CMatrix matrix;
ig.getInstanceMatrix(j, matrix);
CPolygon wpoly;
//wshape->getShapeInWorldSpace(wpoly);
CPolygon2D wpoly2d = wshape->getShape();
uint k;
for (k=0; k<wpoly2d.Vertices.size(); ++k)
{
wpoly.Vertices.push_back(matrix * wpoly2d.Vertices[k]);
}
float zwater = wpoly.Vertices[0].z - WaterThreshold;
uint16 idx = (uint16)_WaterHeight.size();
_WaterHeight.push_back(zwater);
render(wpoly, idx);
if (Verbose)
//.........这里部分代码省略.........
示例12: makeAnimByRace
// ***************************************************************************
void makeAnimByRace(const std::string &animSetFile, const std::vector<string> &animList)
{
// *** Read the animset file.
CIFile iFile;
iFile.open(animSetFile, true);
// Read all text
static vector<string> animSetText;
animSetText.clear();
while(!iFile.eof())
{
char tmp[50000];
iFile.getline(tmp, 50000);
animSetText.push_back(tmp);
}
iFile.close();
bool someChangeDone= false;
// *** For each possible anim
for(uint i=0;i<animList.size();i++)
{
// get the possible anim file name (lowered)
static vector<string> raceAnimNames;
raceAnimNames.clear();
buildRaceAnimNames(raceAnimNames, toLower(CFile::getFilename(animList[i])));
// For each line of the animSet
uint lastStructLine= 0;
bool raceRestrictionFound= false;
for(uint j=0;j<animSetText.size();)
{
string line= animSetText[j];
string lineLwr= toLower(line);
// Find <LOG> TAg? => stop
if(line.find("<LOG>")!=string::npos)
break;
// Find a STRUCT start?
if(line.find("<STRUCT>")!=string::npos)
{
lastStructLine= j;
raceRestrictionFound= false;
}
// Find a RaceRestriction?
if( line.find("Name=\"Race Restriction\"")!=string::npos )
raceRestrictionFound= true;
// Find the anim name?
uint nameIndexInLine= findAnimName(lineLwr, raceAnimNames);
if(nameIndexInLine!=-1)
{
// Find the enclosing struct
nlassert(lastStructLine!=0);
uint startBlock= lastStructLine;
uint nameLineInBlock= j-startBlock;
uint endBlock= 0;
for(uint k=j+1;k<animSetText.size();k++)
{
string line= animSetText[k];
// Find a RaceRestriction?
if( line.find("Name=\"Race Restriction\"")!=string::npos )
raceRestrictionFound= true;
// end of block?
if(line.find("</STRUCT>")!=string::npos)
{
// endBlock is exclusive
endBlock= k+1;
break;
}
}
// if not found, abort
if(endBlock==0)
break;
// if a raceRestriction has been found, no op (already done)
if(raceRestrictionFound)
{
j= endBlock;
}
else
{
// LOG
InfoLog->displayRawNL("%s: Specifying %s by race",
CFile::getFilename(animSetFile).c_str(),
CFile::getFilename(animList[i]).c_str());
// *** Start a copy paste ^^
// Copy
static vector<string> copyText;
copyText.clear();
for(uint k=startBlock;k<endBlock;k++)
{
// add an empty line before </STRUCT>, for race selection node (filled later)
//.........这里部分代码省略.........
示例13: sFile
void Browse::OnImportBorder()
{
// Select a file
CFileDialog sFile (true, NULL, NULL, OFN_ENABLESIZING,
"Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL);
if (sFile.DoModal()==IDOK)
{
// Get the border of the bank
std::vector<NLMISC::CBGRA> array(128*128);
// The bitmap
NLMISC::CBitmap bitmap;
// Read the bitmap
bool error=false;
CString pathName=sFile.GetPathName();
try
{
CIFile file;
if (file.open ((const char*)pathName))
{
// Export
bitmap.load (file);
}
else
error=true;
}
catch (Exception& e)
{
const char *toto=e.what ();
error=true;
}
// Error during import ?
if (error)
{
// Error message
char tmp[512];
sprintf (tmp, "Can't read bitmap %s", (const char*)pathName);
MessageBox (tmp, "Import border", MB_OK|MB_ICONEXCLAMATION);
}
// Get pixel
CRGBA *pPixel=(CRGBA*)&bitmap.getPixels()[0];
// Good size
if ((bitmap.getWidth()==128)&&(bitmap.getHeight()==128))
{
// Make a copy
for (int i=0; i<128*128; i++)
{
// Copy the pixel
array[i].R=pPixel->R;
array[i].G=pPixel->G;
array[i].B=pPixel->B;
array[i].A=pPixel->A;
pPixel++;
}
}
else
{
// Error message
char tmp[512];
sprintf (tmp, "The bitmap must have a size of 128x128 (%s)", (const char*)pathName);
MessageBox (tmp, "Import border", MB_OK|MB_ICONEXCLAMATION);
}
// 256 or 128 ?
CTileBorder border;
border.set (128, 128, array);
tileBank2.getTileSet (land)->setBorder (m_ctrl.Texture==1?CTile::diffuse:CTile::additive, border);
// Message
MessageBox ("The border has been changed.", "Import border", MB_OK|MB_ICONINFORMATION);
}
}
示例14: main
// ---------------------------------------------------------------------------
int main(int nNbArg, char**ppArgs)
{
if (!NLMISC::INelContext::isContextInitialised())
new CApplicationContext();
NL3D_BlockMemoryAssertOnPurge = false;
char sCurDir[MAX_PATH];
getcwd (sCurDir, MAX_PATH);
if (nNbArg != 2)
{
printf ("Use : ig_elevation configfile.cfg\n");
printf ("\nExample of config.cfg\n\n");
printf ("InputIGDir = \"ig_land_max\";\n");
printf ("OutputIGDir = \"ig_land_max_elev\";\n");
printf ("CellSize = 160.0;\n");
printf ("HeightMapFile1 = \"w:/database/landscape/ligo/jungle/big.tga\";\n");
printf ("ZFactor1 = 1.0;\n");
printf ("HeightMapFile2 = \"w:/database/landscape/ligo/jungle/noise.tga\";\n");
printf ("ZFactor2 = 0.5;\n");
printf ("LandFile = \"w:/matis.land\";\n");
return -1;
}
SExportOptions options;
if (!options.load(ppArgs[1]))
{
return -1;
}
// Get all ig files in the input directory and elevate to the z of the double heightmap
// Load the land
CZoneRegion *ZoneRegion = loadLand(options.LandFile);
CZoneLimits zl;
if (ZoneRegion)
{
zl._ZoneMinX = ZoneRegion->getMinX() < 0 ? 0 : ZoneRegion->getMinX();
zl._ZoneMaxX = ZoneRegion->getMaxX() > 255 ? 255 : ZoneRegion->getMaxX();
zl._ZoneMinY = ZoneRegion->getMinY() > 0 ? 0 : ZoneRegion->getMinY();
zl._ZoneMaxY = ZoneRegion->getMaxY() < -255 ? -255 : ZoneRegion->getMaxY();
}
else
{
nlwarning("A ligo .land file cannot be found");
zl._ZoneMinX = 0;
zl._ZoneMaxX = 255;
zl._ZoneMinY = 0;
zl._ZoneMaxY = 255;
}
// Load the 2 height maps
CBitmap *HeightMap1 = NULL;
if (!options.HeightMapFile1.empty())
{
HeightMap1 = new CBitmap;
try
{
CIFile inFile;
if (inFile.open(options.HeightMapFile1))
{
HeightMap1->load (inFile);
}
else
{
string sTmp = string("Couldn't not open ")+string(options.HeightMapFile1)
+string(" : heightmap 1 map ignored");
outString(sTmp);
delete HeightMap1;
HeightMap1 = NULL;
}
}
catch (const Exception &e)
{
string sTmp = string("Cant load height map : ") + options.HeightMapFile1 + " : " + e.what();
outString (sTmp);
delete HeightMap1;
HeightMap1 = NULL;
}
}
CBitmap *HeightMap2 = NULL;
if (!options.HeightMapFile2.empty())
{
HeightMap2 = new CBitmap;
try
{
CIFile inFile;
if (inFile.open(options.HeightMapFile2))
{
HeightMap2->load (inFile);
}
else
{
string sTmp = string("Couldn't not open ")+string(options.HeightMapFile2)
+string(" : heightmap 2 map ignored\n");
outString(sTmp);
delete HeightMap2;
//.........这里部分代码省略.........
示例15: main
int main(int argc, char **argv)
{
if (argc != 2)
{
printf("usage : %s file.ig\n", argv[0]);
return -1;
}
try
{
uint k;
CInstanceGroup ig;
CIFile inputStream;
if (!inputStream.open(string(argv[1])))
{
printf("unable to open %s\n", argv[1]);
return -1;
}
ig.serial(inputStream);
printf("Origine\n");
printf("---------\n");
CVector gpos = ig.getGlobalPos();
printf("global pos : x = %.1f, y = %.1f, z =%.1f\n", gpos.x, gpos.y, gpos.z);
printf("Instances\n");
printf("---------\n");
for(k = 0; k < ig._InstancesInfos.size(); ++k)
{
printf("instance %s : x = %.1f, y = %.1f, z = %.1f, sx = %.1f, sy = %.1f, sz = %.1f\n", ig._InstancesInfos[k].Name.c_str(), ig._InstancesInfos[k].Pos.x + gpos.x, ig._InstancesInfos[k].Pos.y + gpos.y, ig._InstancesInfos[k].Pos.z + gpos.z, ig._InstancesInfos[k].Scale.x, ig._InstancesInfos[k].Scale.y, ig._InstancesInfos[k].Scale.z);
}
printf("\n");
printf("Lights\n");
printf("---------\n");
for(k = 0; k < ig.getNumPointLights(); ++k)
{
const CPointLightNamed &pl = ig.getPointLightNamed(k);
printf("light group = %d, anim = \"%s\" x = %.1f, y = %.1f, z = %.1f\n", pl.LightGroup, pl.AnimatedLight.c_str(), pl.getPosition().x + gpos.x, pl.getPosition().y + gpos.y, pl.getPosition().z + gpos.z);
}
printf("---------\n");
printf("Realtime sun contribution = %s\n", ig.getRealTimeSunContribution() ? "on" : "off");
printf("---------\n");
// IGSurfaceLight info.
const CIGSurfaceLight::TRetrieverGridMap &rgm= ig.getIGSurfaceLight().getRetrieverGridMap();
printf("IGSurfaceLighting: CellSize: %f. NumGridRetriever: %u\n",
ig.getIGSurfaceLight().getCellSize(), (uint)rgm.size() );
uint rgmInst= 0;
uint totalCells= 0;
CIGSurfaceLight::TRetrieverGridMap::const_iterator it= rgm.begin();
for(;it!=rgm.end();it++)
{
for(uint i=0;i<it->second.Grids.size();i++)
{
printf("grid(%d, %d): %dx%d\n", rgmInst, i, it->second.Grids[i].Width, it->second.Grids[i].Height );
totalCells+= it->second.Grids[i].Cells.size();
}
rgmInst++;
}
printf("TotalCells: %d\n", totalCells);
}
catch (const std::exception &e)
{
printf("%s\n", e.what());
}
}