本文整理汇总了C++中ModelInstance函数的典型用法代码示例。如果您正苦于以下问题:C++ ModelInstance函数的具体用法?C++ ModelInstance怎么用?C++ ModelInstance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ModelInstance函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fopen
bool StaticMapTree::InitMap(const std::string &fname, VMapManager2 *vm) {
sLog->outDebug(LOG_FILTER_MAPS,
"StaticMapTree::InitMap() : initializing StaticMapTree '%s'",
fname.c_str());
bool success = true;
std::string fullname = iBasePath + fname;
FILE *rf = fopen(fullname.c_str(), "rb");
if (!rf)
return false;
else {
char chunk[8];
//general info
if (!readChunk(rf, chunk, VMAP_MAGIC, 8))
success = false;
char tiled;
if (success && fread(&tiled, sizeof(char), 1, rf) != 1)
success = false;
iIsTiled = bool(tiled);
// Nodes
if (success && !readChunk(rf, chunk, "NODE", 4))
success = false;
if (success)
success = iTree.readFromFile(rf);
if (success) {
iNTreeValues = iTree.primCount();
iTreeValues = new ModelInstance[iNTreeValues];
}
if (success && !readChunk(rf, chunk, "GOBJ", 4))
success = false;
// global model spawns
// only non-tiled maps have them, and if so exactly one (so far at least...)
ModelSpawn spawn;
#ifdef VMAP_DEBUG
sLog->outDebug(LOG_FILTER_MAPS, "StaticMapTree::InitMap() : map isTiled: %u", static_cast<uint32>(iIsTiled));
#endif
if (!iIsTiled && ModelSpawn::readFromFile(rf, spawn)) {
WorldModel *model = vm->acquireModelInstance(iBasePath, spawn.name);
sLog->outDebug(LOG_FILTER_MAPS,
"StaticMapTree::InitMap() : loading %s",
spawn.name.c_str());
if (model) {
// assume that global model always is the first and only tree value (could be improved...)
iTreeValues[0] = ModelInstance(spawn, model);
iLoadedSpawns[0] = 1;
} else {
success = false;
sLog->outError(
"StaticMapTree::InitMap() : could not acquire WorldModel pointer for '%s'",
spawn.name.c_str());
}
}
fclose(rf);
}
return success;
}
示例2: ModelAsset
bool MeshRenderComponent::VInit(TiXmlElement* _pData)
{
Asset = WE_NEW ModelAsset();
LoadAsset();
Instance = WE_NEW ModelInstance();
Instance->asset = Asset;
return true;
}
示例3: fopen
bool StaticMapTree::init(const std::string &fname, VMapManager2 *vm)
{
std::cout << "Initializing StaticMapTree '" << fname << "'\n";
bool success=true;
std::string fullname = iBasePath + fname;
FILE *rf = fopen(fullname.c_str(), "rb");
if(!rf)
return false;
else
{
char chunk[8];
//general info
char tiled;
if (fread(&tiled, sizeof(char), 1, rf) != 1) success = false;
iIsTiled = (bool(tiled));
// Nodes
if (success && !readChunk(rf, chunk, "NODE", 4)) success = false;
if (success) success = iTree.readFromFile(rf);
if (success)
{
iNTreeValues = iTree.primCount();
iTreeValues = new ModelInstance[iNTreeValues];
}
if (success && !readChunk(rf, chunk, "GOBJ", 4)) success = false;
// global model spawns
// only non-tiled maps have them, and if so exactly one (so far at least...)
ModelSpawn spawn;
#ifdef VMAP_DEBUG
std::cout << "Map isTiled:" << bool(iIsTiled) << std::endl;
#endif
if (!iIsTiled && ModelSpawn::readFromFile(rf, spawn))
{
WorldModel *model = vm->acquireModelInstance(iBasePath, spawn.name);
std::cout << "StaticMapTree::init(): loading " << spawn.name << std::endl;
if (model)
{
// assume that global model always is the first and only tree value (could be improved...)
iTreeValues[0] = ModelInstance(spawn, model);
iLoadedSpawns[spawn.ID] = 1;
}
else
{
success = false;
std::cout << "error: could not acquire WorldModel pointer!\n";
}
}
fclose(rf);
}
return success;
}
示例4: VMAP_DEBUG_LOG
bool StaticMapTree::InitMap(const std::string &fname, VMapManager2* vm)
{
VMAP_DEBUG_LOG("maps", "StaticMapTree::InitMap() : initializing StaticMapTree '%s'", fname.c_str());
bool success = false;
std::string fullname = iBasePath + fname;
FILE* rf = fopen(fullname.c_str(), "rb");
if (!rf)
return false;
char chunk[8];
char tiled = '\0';
if (readChunk(rf, chunk, VMAP_MAGIC, 8) && fread(&tiled, sizeof(char), 1, rf) == 1 &&
readChunk(rf, chunk, "NODE", 4) && iTree.readFromFile(rf))
{
iNTreeValues = iTree.primCount();
iTreeValues = new ModelInstance[iNTreeValues];
success = readChunk(rf, chunk, "GOBJ", 4);
}
iIsTiled = tiled != '\0';
// global model spawns
// only non-tiled maps have them, and if so exactly one (so far at least...)
ModelSpawn spawn;
#ifdef VMAP_DEBUG
TC_LOG_DEBUG("maps", "StaticMapTree::InitMap() : map isTiled: %u", static_cast<uint32>(iIsTiled));
#endif
if (!iIsTiled && ModelSpawn::readFromFile(rf, spawn))
{
WorldModel* model = vm->acquireModelInstance(iBasePath, spawn.name);
VMAP_DEBUG_LOG("maps", "StaticMapTree::InitMap() : loading %s", spawn.name.c_str());
if (model)
{
// assume that global model always is the first and only tree value (could be improved...)
iTreeValues[0] = ModelInstance(spawn, model);
iLoadedSpawns[0] = 1;
}
else
{
success = false;
VMAP_ERROR_LOG("misc", "StaticMapTree::InitMap() : could not acquire WorldModel pointer for '%s'", spawn.name.c_str());
}
}
fclose(rf);
return success;
}
示例5: ERROR_LOG
bool StaticMapTree::LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm)
{
if (!iIsTiled)
{
// currently, core creates grids for all maps, whether it has terrain tiles or not
// so we need "fake" tile loads to know when we can unload map geometry
iLoadedTiles[packTileID(tileX, tileY)] = false;
return true;
}
if (!iTreeValues)
{
ERROR_LOG("StaticMapTree::LoadMapTile(): Tree has not been initialized! [%u,%u]", tileX, tileY);
return false;
}
bool result = true;
std::string tilefile = iBasePath + getTileFileName(iMapID, tileX, tileY);
FILE* tf = fopen(tilefile.c_str(), "rb");
if (tf)
{
char chunk[8];
if (!readChunk(tf, chunk, VMAP_MAGIC, 8))
{ result = false; }
uint32 numSpawns;
if (result && fread(&numSpawns, sizeof(uint32), 1, tf) != 1)
{ result = false; }
for (uint32 i = 0; i < numSpawns && result; ++i)
{
// read model spawns
ModelSpawn spawn;
result = ModelSpawn::readFromFile(tf, spawn);
if (result)
{
// acquire model instance
WorldModel* model = vm->acquireModelInstance(iBasePath, spawn.name);
if (!model)
{ ERROR_LOG("StaticMapTree::LoadMapTile() could not acquire WorldModel pointer for '%s'!", spawn.name.c_str()); }
// update tree
uint32 referencedVal;
size_t fileRead = fread(&referencedVal, sizeof(uint32), 1, tf);
if (!iLoadedSpawns.count(referencedVal) || fileRead <= 0)
{
#ifdef VMAP_DEBUG
if (referencedVal > iNTreeValues)
{
DEBUG_LOG("invalid tree element! (%u/%u)", referencedVal, iNTreeValues);
continue;
}
#endif
iTreeValues[referencedVal] = ModelInstance(spawn, model);
iLoadedSpawns[referencedVal] = 1;
}
else
{
++iLoadedSpawns[referencedVal];
#ifdef VMAP_DEBUG
if (iTreeValues[referencedVal].ID != spawn.ID)
{ DEBUG_LOG("Error: trying to load wrong spawn in node!"); }
else if (iTreeValues[referencedVal].name != spawn.name)
{ DEBUG_LOG("Error: name mismatch on GUID=%u", spawn.ID); }
#endif
}
}
}
iLoadedTiles[packTileID(tileX, tileY)] = true;
fclose(tf);
}
else
{ iLoadedTiles[packTileID(tileX, tileY)] = false; }
return result;
}
示例6: getTileFileName
bool StaticMapTree::LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm)
{
if (!iIsTiled)
{
// currently, core creates grids for all maps, whether it has terrain tiles or not
// so we need "fake" tile loads to know when we can unload map geometry
iLoadedTiles[packTileID(tileX, tileY)] = false;
return true;
}
if (!iTreeValues)
{
sLog->outError(LOG_FILTER_GENERAL, "StaticMapTree::LoadMapTile() : tree has not been initialized [%u, %u]", tileX, tileY);
return false;
}
bool result = true;
std::string tilefile = iBasePath + getTileFileName(iMapID, tileX, tileY);
FILE* tf = fopen(tilefile.c_str(), "rb");
if (tf)
{
char chunk[8];
if (!readChunk(tf, chunk, VMAP_MAGIC, 8))
result = false;
uint32 numSpawns = 0;
if (result && fread(&numSpawns, sizeof(uint32), 1, tf) != 1)
result = false;
for (uint32 i=0; i<numSpawns && result; ++i)
{
// read model spawns
ModelSpawn spawn;
result = ModelSpawn::readFromFile(tf, spawn);
if (result)
{
// acquire model instance
WorldModel* model = vm->acquireModelInstance(iBasePath, spawn.name);
if (!model)
sLog->outError(LOG_FILTER_GENERAL, "StaticMapTree::LoadMapTile() : could not acquire WorldModel pointer [%u, %u]", tileX, tileY);
// update tree
uint32 referencedVal;
if (fread(&referencedVal, sizeof(uint32), 1, tf) == 1)
{
if (!iLoadedSpawns.count(referencedVal))
{
#ifdef VMAP_DEBUG
if (referencedVal > iNTreeValues)
{
sLog->outDebug(LOG_FILTER_MAPS, "StaticMapTree::LoadMapTile() : invalid tree element (%u/%u)", referencedVal, iNTreeValues);
continue;
}
#endif
iTreeValues[referencedVal] = ModelInstance(spawn, model);
iLoadedSpawns[referencedVal] = 1;
}
else
{
++iLoadedSpawns[referencedVal];
#ifdef VMAP_DEBUG
if (iTreeValues[referencedVal].ID != spawn.ID)
sLog->outDebug(LOG_FILTER_MAPS, "StaticMapTree::LoadMapTile() : trying to load wrong spawn in node");
else if (iTreeValues[referencedVal].name != spawn.name)
sLog->outDebug(LOG_FILTER_MAPS, "StaticMapTree::LoadMapTile() : name collision on GUID=%u", spawn.ID);
#endif
}
}
else
result = false;
}
}
iLoadedTiles[packTileID(tileX, tileY)] = true;
fclose(tf);
}
else
iLoadedTiles[packTileID(tileX, tileY)] = false;
return result;
}
示例7: theFile
MapTile::MapTile(int pX, int pZ, const std::string& pFilename, bool pBigAlpha)
{
this->modelCount = 0;
this->mPositionX = pX;
this->mPositionZ = pZ;
this->changed = 0;
this->xbase = mPositionX * TILESIZE;
this->zbase = mPositionZ * TILESIZE;
this->mBigAlpha = pBigAlpha;
for (int i = 0; i < 16; ++i)
{
for (int j = 0; j < 16; j++)
{
mChunks[i][j] = NULL;
}
}
mFilename = pFilename;
MPQFile theFile(mFilename);
Log << "Opening tile " << mPositionX << ", " << mPositionZ << " (\"" << mFilename << "\") from " << (theFile.isExternal() ? "disk" : "MPQ") << "." << std::endl;
// - Parsing the file itself. --------------------------
// We store this data to load it at the end.
uint32_t lMCNKOffsets[256];
std::vector<ENTRY_MDDF> lModelInstances;
std::vector<ENTRY_MODF> lWMOInstances;
uint32_t fourcc;
uint32_t size;
MHDR Header;
// - MVER ----------------------------------------------
uint32_t version;
theFile.read(&fourcc, 4);
theFile.seekRelative(4);
theFile.read(&version, 4);
assert(fourcc == 'MVER' && version == 18);
// - MHDR ----------------------------------------------
theFile.read(&fourcc, 4);
theFile.seekRelative(4);
assert(fourcc == 'MHDR');
theFile.read(&Header, sizeof(MHDR));
mFlags = Header.flags;
// - MCIN ----------------------------------------------
theFile.seek(Header.mcin + 0x14);
theFile.read(&fourcc, 4);
theFile.seekRelative(4);
assert(fourcc == 'MCIN');
for (int i = 0; i < 256; ++i)
{
theFile.read(&lMCNKOffsets[i], 4);
theFile.seekRelative(0xC);
}
// - MTEX ----------------------------------------------
theFile.seek(Header.mtex + 0x14);
theFile.read(&fourcc, 4);
theFile.read(&size, 4);
assert(fourcc == 'MTEX');
{
char* lCurPos = reinterpret_cast<char*>(theFile.getPointer());
char* lEnd = lCurPos + size;
while (lCurPos < lEnd)
{
mTextureFilenames.push_back(std::string(lCurPos));
lCurPos += strlen(lCurPos) + 1;
}
}
// - MMDX ----------------------------------------------
theFile.seek(Header.mmdx + 0x14);
theFile.read(&fourcc, 4);
theFile.read(&size, 4);
assert(fourcc == 'MMDX');
//.........这里部分代码省略.........
示例8: getTileFileName
bool StaticMapTree::loadMap(uint32 tileX, uint32 tileY, VMapManager2 *vm)
{
if (!iIsTiled)
return true;
if (!iTreeValues)
{
std::cout << "Tree has not been initialized!\n";
return false;
}
bool result = true;
std::string tilefile = iBasePath + getTileFileName(iMapID, tileX, tileY);
FILE* tf = fopen(tilefile.c_str(), "rb");
if(tf)
{
while(result)
{
// read model spawns
ModelSpawn spawn;
result = ModelSpawn::readFromFile(tf, spawn);
if(result)
{
// acquire model instance
WorldModel *model = vm->acquireModelInstance(iBasePath, spawn.name);
if(!model) std::cout << "error: could not acquire WorldModel pointer!\n";
// update tree
uint32 nNodeVal=0, referencedVal;
fread(&nNodeVal, sizeof(uint32), 1, tf);
#ifdef VMAP_DEBUG
if(nNodeVal != 1)
std::cout << "unexpected amount of affected NodeVals! (" << nNodeVal << ")\n";
#endif
for (uint32 i=0; i<nNodeVal; ++i)
{
fread(&referencedVal, sizeof(uint32), 1, tf);
if (!iLoadedSpawns.count(spawn.ID))
{
#ifdef VMAP_DEBUG
if (referencedVal > iNTreeValues)
{
std::cout << "invalid tree element! (" << referencedVal << "/" << iNTreeValues << ")\n";
continue;
}
#endif
iTreeValues[referencedVal] = ModelInstance(spawn, model);
iLoadedSpawns[spawn.ID] = 1;
}
else
{
++iLoadedSpawns[spawn.ID];
#ifdef VMAP_DEBUG
if (iTreeValues[referencedVal].ID != spawn.ID) std::cout << "error: trying to load wrong spawn in node!\n";
else if (iTreeValues[referencedVal].name != spawn.name) std::cout << "error: name collision on GUID="<< spawn.ID << "\n";
#endif
}
}
}
}
iLoadedTiles[packTileID(tileX, tileY)] = true;
fclose(tf);
}
else
iLoadedTiles[packTileID(tileX, tileY)] = false;
return result;
}
示例9: TC_LOG_ERROR
bool StaticMapTree::LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm)
{
if (!iTreeValues)
{
TC_LOG_ERROR("misc", "StaticMapTree::LoadMapTile() : tree has not been initialized [%u, %u]", tileX, tileY);
return false;
}
bool result = true;
TileFileOpenResult fileResult = OpenMapTileFile(iBasePath, iMapID, tileX, tileY, vm);
if (fileResult.File)
{
char chunk[8];
if (!readChunk(fileResult.File, chunk, VMAP_MAGIC, 8))
result = false;
uint32 numSpawns = 0;
if (result && fread(&numSpawns, sizeof(uint32), 1, fileResult.File) != 1)
result = false;
for (uint32 i=0; i<numSpawns && result; ++i)
{
// read model spawns
ModelSpawn spawn;
result = ModelSpawn::readFromFile(fileResult.File, spawn);
if (result)
{
// acquire model instance
WorldModel* model = vm->acquireModelInstance(iBasePath, spawn.name, spawn.flags);
if (!model)
TC_LOG_ERROR("misc", "StaticMapTree::LoadMapTile() : could not acquire WorldModel pointer [%u, %u]", tileX, tileY);
// update tree
auto spawnIndex = iSpawnIndices.find(spawn.ID);
if (spawnIndex != iSpawnIndices.end())
{
uint32 referencedVal = spawnIndex->second;
if (!iLoadedSpawns.count(referencedVal))
{
if (referencedVal >= iNTreeValues)
{
TC_LOG_ERROR("maps", "StaticMapTree::LoadMapTile() : invalid tree element (%u/%u) referenced in tile %s", referencedVal, iNTreeValues, fileResult.Name.c_str());
continue;
}
iTreeValues[referencedVal] = ModelInstance(spawn, model);
iLoadedSpawns[referencedVal] = 1;
}
else
{
++iLoadedSpawns[referencedVal];
#ifdef VMAP_DEBUG
if (iTreeValues[referencedVal].ID != spawn.ID)
TC_LOG_DEBUG("maps", "StaticMapTree::LoadMapTile() : trying to load wrong spawn in node");
else if (iTreeValues[referencedVal].name != spawn.name)
TC_LOG_DEBUG("maps", "StaticMapTree::LoadMapTile() : name collision on GUID=%u", spawn.ID);
#endif
}
}
else
result = false;
}
}
iLoadedTiles[packTileID(tileX, tileY)] = true;
fclose(fileResult.File);
}
else
iLoadedTiles[packTileID(tileX, tileY)] = false;
TC_METRIC_EVENT("map_events", "LoadMapTile",
"Map: " + std::to_string(iMapID) + " TileX: " + std::to_string(tileX) + " TileY: " + std::to_string(tileY));
return result;
}