DataHeader *DataFile::getHeader(FileOffset offset) { AutoPtr<DataHeader> header; try { // Header ref's the datafile. header = new DataHeader(this); } catch (...) { throw GenericException(__FILE__, __LINE__, "Cannot allocate DataHeader"); } try { header->read(offset); return header.release(); } catch (GenericException &e) { throw GenericException(__FILE__, __LINE__, "Datafile::getHeader:\n%s", e.what()); } }
void operator()(std::ostream& out, const VertexOrEdge& v) const { if (type[v] == FROM_STATE) { out << "[color=\"black\"]"; } else if (type[v] == BAD_STATE) { out << "[color=\"red\"]"; } else if (type[v] == GOOD_STATE) { out << "[color=\"green\"]"; } else { std::ostringstream oss; oss << "Unknown edge type for edge " << name[v]; throw GenericException(oss.str()); } }
void operator()(std::ostream& out, const VertexOrEdge& v) const { if (type[v] == STATE) { out << "[shape=oval,rank=source,label=\"" << id[v] << ": " << name[v] << "\"]"; } else if (type[v] == CONDITION) { out << "[shape=box,rank=min,label=\"" << id[v] << ": " << name[v] << "\"]"; } else if (type[v] == STARTSTATE) { out << "[shape=hexagon,rank=max,label=\"" << id[v] << ": " << name[v] << "\"]"; } else { std::ostringstream oss; oss << "Unknown vertex type for vertex " << name[v]; throw GenericException(oss.str()); } }
void GString::Insert( int nIndex, char ch ) { // subscript out of range if (nIndex > _len) throw GenericException("String", 1); if (_len + 2 >= _max) resize(); _len++; memmove(&_str[nIndex + 1], &_str[nIndex], _len - nIndex); _str[nIndex] = ch; _str[_len] = 0; }
MsgLogger::MsgLogger(const char *filename) : prev_logger(TheMsgLogger), f(0) { if (filename && filename[0] != '\0') { f.set(fopen(filename, "a")); if (! f) throw GenericException(__FILE__, __LINE__, "Cannot open '%s' for writing", filename); } // Make this logger the current one. TheMsgLogger = this; }
// Call instead of delete: void DataFile::release() { if (ref_count <= 0) throw GenericException(__FILE__, __LINE__, "DataFile(%s): over-released", filename.c_str()); --ref_count; // You might expect // delete this; // in here, but we keep the files open // and cache them until close_all() is called. #ifdef LOG_DATAFILE LOG_MSG("DataFile %s released, %d references\n", filename.c_str(), ref_count); #endif }
SRow *MAPITableIterator::GetNext() { HRESULT hr = S_OK; if (0 == m_totalRows) return NULL; if (m_currRow >= m_pRows->cRows) { if (m_rowsVisited >= m_totalRows) return NULL; FreeProws(m_pRows); m_pRows = NULL; if (m_totalRows - m_rowsVisited < m_batchSize) { hr = m_pTable->QueryRows((m_totalRows - m_rowsVisited), 0, &m_pRows); if (m_pRows && (m_pRows->cRows < (m_totalRows - m_rowsVisited))) { // "**Warning**: %d Table Rows Requested, Got just %d, hr = %d"), _totalRows - _rowsVisited, _pRows->cRows, hr m_rowsVisited = m_totalRows - m_pRows->cRows; } } else { hr = m_pTable->QueryRows(m_batchSize, 0, &m_pRows); if (m_pRows && (m_pRows->cRows < m_batchSize)) { // "**Warning**: %d Table Rows Requested, Got just %d, hr = %d"), _batchSize, _pRows->cRows, hr m_rowsVisited += m_batchSize - m_pRows->cRows; } } if (FAILED(hr)) { throw GenericException(hr, L"MAPITableIterator::GetNext():QueryRows Failed.",ERR_GET_NEXT, __LINE__, __FILE__); } m_currRow = 0; } if (!m_pRows->cRows) return NULL; SRow *pRow = &(m_pRows->aRow[m_currRow]); m_currRow++; m_rowsVisited++; return pRow; }
void FileAllocator::remove_node(FileOffset head_offset, list_node *head, FileOffset node_offset, const list_node *node) { list_node tmp; FileOffset tmp_offset; if (head->next == node_offset) { // first node; make head skip it head->bytes -= node->bytes; head->next = node->next; if (head->next == 0) // list now empty? head->prev = 0; else { // correct 'prev' ptr of what's now the first node read_node(head->next, &tmp); tmp.prev = 0; write_node(head->next, &tmp); } write_node(head_offset, head); } else { // locate a node that's not the first tmp_offset = head->next; read_node(tmp_offset, &tmp); while (tmp.next != node_offset) { tmp_offset = tmp.next; if (!tmp_offset) throw GenericException(__FILE__, __LINE__, "node not found"); read_node(tmp_offset, &tmp); } // tmp/tmp_offset == node before the one to be removed tmp.next = node->next; write_node(tmp_offset, &tmp); if (node->next) { // adjust prev pointer of node->next read_node(node->next, &tmp); tmp.prev = tmp_offset; write_node(node->next, &tmp); } head->bytes -= node->bytes; if (head->prev == node_offset) head->prev = node->prev; write_node(head_offset, head); } }
/************************************************************************* constructor *************************************************************************/ FontManager::FontManager(void) { d_implData = new FontManagerImplData; if (FT_Init_FreeType(&d_implData->d_ftlib)) { throw GenericException((utf8*)"FontManager::FontManager - Failed to initialise the FreeType library."); } Logger::getSingleton().logEvent((utf8*)"CEGUI::FontManager singleton created."); d_timeOld = 0.0f; d_totalLife = 0.8f; //blink one cycle need 0.8 sec. d_minAlpha = 0.35f; //alpha smallest value. d_curBlinkAlpha = 1.0f; }
Item* ItemFactory::GetItem(Item::ItemType type, int itemId) { Item* retval = new Item(itemId, type); LoadItem(type, itemId, retval); switch(itemId) { //TODO: Init Item with Id itemId default: std::string msg("Invalid ItemId "); msg.append(std::to_string(itemId)); msg.append(" given in GetItem."); throw GenericException(msg); } return retval; }
//Create a polygonal shape void PhysicsManager::CreatePolygonShape(b2PolygonDef* definition, const std::string& bodyname) { if(definition->vertexCount > b2_maxPolygonVertices) throw GenericException("Encountered a polygon definition with too many vertexs",GenericException::INVALIDPARAMS); //TODO: BE SURE IT IS A CONVEX POLYGON OR TRANSFORM IT! PhysBodiesMapIterator itr = mBodiesMap.find(bodyname); if(itr != mBodiesMap.end()) { //Add shape to body (*itr).second->CreateShape(definition); } else SingletonLogMgr::Instance()->AddNewLine("PhysicsManager::CreatePolygonShape","Error: intent to create shape to non-existent body: " + bodyname,LOGEXCEPTION); }
PxGeometry& Camera::getPixelFrustum(FDreal pixelXSize, FDreal pixelYSize) { if (pixelFrustum.isValid()) { return pixelFrustum; } Vector3 proj1(-pixelXSize / 2, -pixelYSize / 2, 1); Vector3 proj2(-pixelXSize / 2, pixelYSize / 2, 1); Vector3 proj3(pixelXSize / 2, -pixelYSize / 2, 1); Vector3 proj4(pixelXSize / 2, pixelYSize / 2, 1); fdmath::Matrix44 projInverse; fdmath::gluInvertMatrix44(projection, projInverse); FDreal len = -100.0f; Vector3 view1 = projInverse.transform(proj1).getNormalized() * len; Vector3 view2 = projInverse.transform(proj2).getNormalized() * len; Vector3 view3 = projInverse.transform(proj3).getNormalized() * len; Vector3 view4 = projInverse.transform(proj4).getNormalized() * len; static const PxVec3 convexVerts[] = {PxVec3(0,0,0), view1, view2, view3, view4}; PhysicsSystem* physics = FreeThread__getWorld(). getSystem<PhysicsSystem>(); PxConvexMeshDesc convexDesc; convexDesc.points.count = 5; convexDesc.points.stride = sizeof(PxVec3); convexDesc.points.data = convexVerts; convexDesc.flags = PxConvexFlag::eCOMPUTE_CONVEX; convexDesc.vertexLimit = 256; PxDefaultMemoryOutputStream buf; if (!physics->cooking->cookConvexMesh(convexDesc, buf)) { FD_THROW(GenericException("Unable to cook convex pixel mesh!")); } PxDefaultMemoryInputData input(buf.getData(), buf.getSize()); PxConvexMesh* convexMesh = physics->physics->createConvexMesh(input); pixelFrustum = PxConvexMeshGeometry(convexMesh); return pixelFrustum; }
Mesh* ConvexHull::newMesh(Array<Vector3> points, VertexDescriptor& descriptor, GraphicsSystem& graphicsSystem, PhysicsSystem& physicsSystem) { GraphicsAPI& graphicsAPI = graphicsSystem.getAPI(); PxConvexMesh* pxMesh = compute(points, physicsSystem); FDUint vertexCount = pxMesh->getNbVertices(); FDUint byteSize = vertexCount * descriptor.getVertexSize(); FDUint polygonCount = pxMesh->getNbPolygons(); GeometryAuthor author(descriptor, graphicsAPI.getDynamicAllocator()); const PxU8* indices = pxMesh->getIndexBuffer(); for (FDUint i = 0; i < polygonCount; i++) { PxHullPolygon polygon; FDbool success = pxMesh->getPolygonData(i, polygon); if (!success) { FD_THROW(GenericException("Failed to get polygon data.\n")); } FDUint firstIndex = 0; for (FDUint j = 0; j < polygon.mNbVerts; j++) { PxU8 cIndex = *(indices + polygon.mIndexBase + j); FDUint myIndex = author.newPoint(pxMesh->getVertices()[cIndex]); if (j == 0) { firstIndex = myIndex; } } for (FDUint j = 2; j < polygon.mNbVerts; j++) { FDUint i1 = firstIndex; FDUint i2 = firstIndex + j - 1; FDUint i3 = firstIndex + j; author.newTriangle(i1, i2, i3); } } author.postProcess(); Mesh* mesh = graphicsSystem.getAPI().newMesh(author); return mesh; }
PxConvexMesh* ConvexHull::compute(fdcore::Array<fdmath::Vector3> points, PhysicsSystem& physicsSystem) { PxConvexMeshDesc convexDesc; convexDesc.points.count = points.length; convexDesc.points.stride = sizeof(PxVec3); convexDesc.points.data = points.elements; convexDesc.flags = PxConvexFlag::eCOMPUTE_CONVEX; convexDesc.vertexLimit = 256; PxDefaultMemoryOutputStream buf; if (!physicsSystem.cooking->cookConvexMesh(convexDesc, buf)) { FD_THROW(GenericException("Unable to cook convex pixel mesh!")); } PxDefaultMemoryInputData input(buf.getData(), buf.getSize()); PxConvexMesh* convexMesh = physicsSystem.physics->createConvexMesh(input); return convexMesh; }
/************************************************************************* If possible, execute script code contained in the given CEGUI::String object. *************************************************************************/ void System::executeScriptString(const String& str) const { if (d_scriptModule) { try { d_scriptModule->executeString(str); } catch(...) { throw GenericException("System::executeScriptString - An exception was thrown during execution of the script code."); } } else { Logger::getSingleton().logEvent("System::executeScriptString - the script code could not be executed as no ScriptModule is available.", Errors); } }
/************************************************************************* Execute a script file if possible. *************************************************************************/ void System::executeScriptFile(const String& filename, const String& resourceGroup) const { if (d_scriptModule) { try { d_scriptModule->executeScriptFile(filename, resourceGroup); } catch(...) { throw GenericException("System::executeScriptFile - An exception was thrown during the execution of the script file."); } } else { Logger::getSingleton().logEvent("System::executeScriptFile - the script named '" + filename +"' could not be executed as no ScriptModule is available.", Errors); } }
void ThreadList::remove(const OrderedMutex *lock) { // Remove lock from the list of locks for this thread. stdList<const OrderedMutex *>::iterator i; for (i = locks.begin(); i != locks.end(); ++i) { if (*i == lock) { locks.erase(i); return; } } if (getenv("ABORT_ON_ERRORS")) { LOG_MSG("ThreadList: Unknown lock '%s'\n", lock->getName().c_str()); abort(); } throw GenericException(__FILE__, __LINE__, "Unknown lock '%s'", lock->getName().c_str()); }
String XercesParser::transcodeXmlCharToString(const XMLCh* const xmlch_str, unsigned int inputLength) { XERCES_CPP_NAMESPACE_USE; XMLTransService::Codes res; XMLTranscoder* transcoder = XMLPlatformUtils::fgTransService->makeNewTranscoderFor(XMLRecognizer::UTF_8, res, 4096, XMLPlatformUtils::fgMemoryManager ); if (res == XMLTransService::Ok) { String out; #if _XERCES_VERSION >= 30000 XMLByte outBuff[128]; XMLSize_t outputLength; XMLSize_t eaten = 0; XMLSize_t offset = 0; #else /* _XERCES_VERSION >= 30000 */ utf8 outBuff[128]; unsigned int outputLength; unsigned int eaten = 0; unsigned int offset = 0; #endif /* _XERCES_VERSION >= 30000 */ // unsigned int inputLength = XMLString::stringLen(xmlch_str); // dalfy caracters node need to transcode but give the size while (inputLength) { outputLength = transcoder->transcodeTo(xmlch_str + offset, inputLength, outBuff, 128, eaten, XMLTranscoder::UnRep_RepChar); out.append(outBuff, outputLength); offset += eaten; inputLength -= eaten; } delete transcoder; return out; } else { throw GenericException("XercesParser::transcodeXmlCharToString - Internal Error: Could not create UTF-8 string transcoder."); } }
/************************************************************************* Execute a scripted global function if possible. The function should not take any parameters and should return an integer. *************************************************************************/ int System::executeScriptGlobal(const String& function_name) const { if (d_scriptModule) { try { return d_scriptModule->executeScriptGlobal(function_name); } catch(...) { throw GenericException("System::executeScriptGlobal - An exception was thrown during execution of the scripted function."); } } else { Logger::getSingleton().logEvent("System::executeScriptGlobal - the global script function named '" + function_name +"' could not be executed as no ScriptModule is available.", Errors); } return 0; }
void ItemFactory::LoadItem(Item::ItemType type, int id, Item* item) { if(item->GetItemType() == Item::ItemTypeEquipment) { Equipment* equipment = (Equipment*)item; LoadEquipment(equipment->GetEquipmentPosition(), id, equipment); } else { switch(id) { //TODO: Init Item with Id itemId default: std::string msg("Invalid ItemId "); msg.append(std::to_string(id)); msg.append(" given in LoadItem."); throw GenericException(msg); } } }
//----------------------------------------------------------------------------// void DefaultResourceProvider::loadRawDataContainer(const String& filename, RawDataContainer& output, const String& resourceGroup) { if (filename.empty()) CEGUI_THROW(InvalidRequestException("DefaultResourceProvider::load: " "Filename supplied for data loading must be valid")); const String final_filename(getFinalFilename(filename, resourceGroup)); #if defined(__WIN32__) || defined(_WIN32) FILE* file = _wfopen(Utf8ToUtf16(final_filename.c_str()).c_str(), L"rb"); #else FILE* file = fopen(final_filename.c_str(), "rb"); #endif if (file == 0) CEGUI_THROW(InvalidRequestException("DefaultResourceProvider::load: " + final_filename + " does not exist")); fseek(file, 0, SEEK_END); const long size = ftell(file); fseek(file, 0, SEEK_SET); unsigned char* const buffer = new unsigned char[size]; const size_t size_read = fread(buffer, sizeof(char), size, file); fclose(file); if (size_read != size) { delete[] buffer; CEGUI_THROW(GenericException( "DefaultResourceProvider::loadRawDataContainer: " "A problem occurred while reading file: " + final_filename)); } output.setData(buffer); output.setSize(size); }
/************************************************************************* SAX2 Handler methods *************************************************************************/ void Animate_xmlHandler::elementStart(const String& element, const XMLAttributes& attributes) { // handle an Animate element (extract all element attributes and use data to define an Animate) if(element == AnimateManagerElement) { } else if(element == AnimateElement) { String name(attributes.getValueAsString(AnimateNameAttribute)); bool loop = attributes.getValueAsBool(AnimatePlayLoop); int id = attributes.getValueAsInteger(AnimateID, -1); int totalTime = attributes.getValueAsInteger(AnimateTime, -1); bool alpha = attributes.getValueAsBool( AnimateAlphaMode ); int loopType = attributes.getValueAsInteger(AnimateAlphaType, 1 ); d_animate = AnimateManager::getSingleton().createAnimate(name, id, loop, totalTime, alpha, loopType ); } else if (element == AniamteItemElement ) { if(d_animate == 0) { throw GenericException("Aniamte::xmlHandler::startElement - Invalid file struct."); } const Image* pImage = PropertyHelper::stringToImage(attributes.getValueAsString(AniamteImage)); if(pImage) { d_animate->defineAnimateKey(pImage); AnimateManager::getSingleton().addAnimateImageset(pImage->getImagesetName()); } } else { throw FileIOException("Aniamte::xmlHandler::startElement - Unexpected data was found while parsing the animatefile: '" + element + "' is unknown."); } }
//Adds a camera to IndieLib and sets it as current Camera2DPointer IndieLibManager::RegisterCamera(const std::string& name, float zoomfactor, const Vector2& position, int layer) { //Check if camera exists CamerasListIterator itr; bool found = false; //LOOP - Find camera for(itr = mCamerasList.begin(); itr != mCamerasList.end(); itr++) { //IF - Camera found if((*itr)->GetName() == name) { found = true; break; }//IF }//LOOP END //IF - Camera not found (OK) if(!found) { //Creation of camera float windowheight = static_cast<float>(Window->GetHeight()); float windowwidth = static_cast<float>(Window->GetWidth()); Camera2DPointer newcamera (new IndieCamera2D(position,zoomfactor,mGlobalScale,layer,windowwidth,windowheight,name,mMaxAABB,mMinAABB)); //Add to container mCamerasList.push_back(newcamera); //Sort cameras by layer CamerasCompareClass comparefunc; mCamerasList.sort(comparefunc); return(newcamera); } else { //Throw exception (incoherence in cameras is not tolerant fault) throw GenericException("Cameras creation incoherence. Program bug or bad files config! Camera '" + name + "' was registered twice!",GenericException::INVALIDPARAMS); } //NO RETURN BECAUSE OF EXCEPTION ;) }
void GString::resize() { // double the size of the buffer _max <<= 1; char *nstr = new char[_max]; // not enough memory for resize if (!nstr) throw GenericException("String", 0); nstr[0] = 0; if (_str) { memcpy(nstr, _str, _len); if (_strIsOnHeap) delete [] _str; } _str = nstr; _strIsOnHeap = 1; _initialbuf[0] = 0; }
RTree *IndexFile::getTree(const stdString &channel, stdString &directory) { stdString tree_filename; FileOffset tree_anchor; if (!names.find(channel, tree_filename, tree_anchor)) return 0; // All OK, but channel not found. // Using AutoPtr in case e.g. tree->reattach throws exception. AutoPtr<RTree> tree; try { tree = new RTree(fa, tree_anchor); } catch (...) { tree.release(); throw GenericException(__FILE__, __LINE__, "Cannot allocate RTree for channel '%s'", channel.c_str()); } tree->reattach(); directory = dirname; return tree.release(); }
void LockMonitor::remove(epicsThreadId thread, OrderedMutex &lock) { epicsMutexGuard guard(mutex); // Remove lock from the list of locks for that thread. stdList<ThreadList>::iterator i; for (i = threads.begin(); i != threads.end(); ++i) { if (i->getThread() == thread) { i->remove(&lock); if (i->isEmpty()) threads.erase(i); return; } } if (getenv("ABORT_ON_ERRORS")) { LOG_MSG("LockMonitor: Unknown thread\n"); dump(guard); abort(); } throw GenericException(__FILE__, __LINE__, "Unknown thread"); }
// NOTE Can i make this process faster? // NOTE Why should i have a seperate class for dynamic and static models StaticModel::StaticModel(const Model3D* const model, const glm::mat4& world) : m_model(model), m_world(world), m_sampler(std::make_unique<Sampler>()) { if(model == nullptr) { throw GenericException("Null param passed to StaticModel constructor"); } m_meshCount = m_model->getMeshCount(); for(unsigned int i = 0; i < m_meshCount; i++) { auto mesh = m_model->getMesh(i); GLuint vbo, vao, ibo; glGenVertexArrays(1, &vao); glBindVertexArray(vao); m_VAO.push_back(vao); glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(Model3D::Vertex) * mesh->getVertices().size(), mesh->getVertices().data(), GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Model3D::Vertex), 0); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Model3D::Vertex), (GLvoid*)sizeof(glm::vec3)); glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Model3D::Vertex), (GLvoid*)(sizeof(glm::vec3) + sizeof(glm::vec3))); m_VBO.push_back(vbo); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glGenBuffers(1, &ibo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * mesh->getIndices().size(), mesh->getIndices().data(), GL_STATIC_DRAW); m_indexCount.push_back(mesh->getIndices().size()); m_IBO.push_back(ibo); } }
// List channel names, maybe with start/end info. void list_channels(Index &index, stdVector<stdString> names, bool info) { epicsTime start, end; stdString s, e; AutoPtr<RTree> tree; size_t i; for (i=0; i<names.size(); ++i) { if (info) { stdString directory; tree = index.getTree(names[i], directory); if (!tree) throw GenericException(__FILE__, __LINE__, "Cannot locate channel '%s'", names[i].c_str()); tree->getInterval(start, end); printf("%s\t%s\t%s\n", names[i].c_str(), epicsTimeTxt(start, s), epicsTimeTxt(end, e)); } else printf("%s\n", names[i].c_str()); } }
DynamicModule::DynamicModule(const String& name) : d_moduleName(name) { //If nothing is passed, don't load anything... if(name.empty()) { d_handle = 0; return; } // if(name.empty()) #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__HAIKU__) #if defined(CEGUI_HAS_VERSION_SUFFIX) || defined(CEGUI_HAS_BUILD_SUFFIX) // check if we are being asked to open a CEGUI .so, if so postfix the // name with our package version if (d_moduleName.substr(0, 5) == "CEGUI" || d_moduleName.substr(0, 8) == "libCEGUI") { // strip .so extension before postfixing, will get added again below if (d_moduleName.substr(d_moduleName.length() - 3, 3) == ".so") d_moduleName = d_moduleName.substr(0, d_moduleName.length() - 3); #ifdef CEGUI_HAS_BUILD_SUFFIX // append a suffix (like _d for debug builds, etc) d_moduleName += CEGUI_BUILD_SUFFIX; #endif #ifdef CEGUI_HAS_VERSION_SUFFIX d_moduleName += "-"; d_moduleName += CEGUI_VERSION_SUFFIX; #endif } #endif // dlopen() does not add .so to the filename, like windows does for .dll if (d_moduleName.substr(d_moduleName.length() - 3, 3) != ".so") d_moduleName += ".so"; #endif // Optionally add a _d to the module name for the debug config on Win32 #if defined(__WIN32__) || defined(_WIN32) // if name has .dll extension, assume it's complete and do not touch it. if (d_moduleName.substr(d_moduleName.length() - 4, 4) != ".dll") { #ifdef CEGUI_HAS_BUILD_SUFFIX // append a suffix (like _d for debug builds, etc) d_moduleName += CEGUI_BUILD_SUFFIX; #endif #ifdef CEGUI_HAS_VERSION_SUFFIX d_moduleName += "-"; d_moduleName += CEGUI_VERSION_SUFFIX; #endif } #endif d_handle = DYNLIB_LOAD(d_moduleName.c_str()); #if defined(__linux__) || defined(__MINGW32__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__HAIKU__) if (!d_handle) { // see if we need to add the leading 'lib' if (d_moduleName.substr(0, 3) != "lib") { d_moduleName.insert(0, "lib"); d_handle = DYNLIB_LOAD(d_moduleName.c_str()); } } #endif // check for library load failure if (!d_handle) CEGUI_THROW(GenericException( "DynamicModule::DynamicModule - Failed to load module '" + d_moduleName + "': " + getFailureString())); }
//Read a part of xml info void PlayerBuilder::ReadPlayerParams(const ticpp::Element* xmlelement) { /*PLAYER ELEMENT Element: PLAYER Atts: MoveSpeed(number) CollidedSpeed(number) ShootForce(number) ProjectileCollGroupIndex (number) ProjectileCollMaskBits(number) ProjectileCollCategoryBits(number) ProjectileImageName(number) ProjectileHeight(number) ProjectileWidth(number) ProjectileDensity(number) ProjectileLifeTime(number) Elements: Body Sprite SpawnAIDef */ //-------Get attributes from entity--------- float movespeed, collidedspeed, shootforce; std::string projectileimgname; float projh,projw,projdensity, lifetime; xmlelement->GetAttribute("MoveSpeed",&movespeed); xmlelement->GetAttribute("CollidedSpeed",&collidedspeed); xmlelement->GetAttribute("ShootForce",&shootforce); projectileimgname = xmlelement->GetAttribute("ProjectileImageName"); xmlelement->GetAttribute("ProjectileCollGroupIndex",&mParams.projectilefilterdef.groupIndex); xmlelement->GetAttribute("ProjectileCollCategoryBits",&mParams.projectilefilterdef.categoryBits); xmlelement->GetAttribute("ProjectileCollMaskBits",&mParams.projectilefilterdef.maskBits); xmlelement->GetAttribute("ProjectileDensity",&projdensity); xmlelement->GetAttribute("ProjectileHeight",&projh); xmlelement->GetAttribute("ProjectileWidth",&projw); xmlelement->GetAttribute("ProjectileLifeTime",&lifetime); //Check correctness of parameters if(movespeed <= 0.0f || collidedspeed <= 0.0f || shootforce < 0.0f || projdensity <= 0.0f || projh <= 0.0f || projw <= 0.0f || lifetime <= 0.0f) throw GenericException("Player Element, bad attributes detected! - Out of bounds values",GenericException::FILE_CONFIG_INCORRECT); if(!SingletonResourceMgr::Instance()->GetSurfaceResource(projectileimgname)) throw GenericException("Player Element, bad attributes detected! - Projectile image resource '" + projectileimgname+ "' not loaded!",GenericException::FILE_CONFIG_INCORRECT); //Store params mParams.movespeed = movespeed; mParams.collidedspeed = collidedspeed; mParams.shootforce = shootforce; mParams.projectilegfxresource = projectileimgname; mParams.projectiledensity = projdensity; mParams.projh = projh; mParams.projw = projw; mParams.projectilelifetime = lifetime * 1000.0f; //In ms //------Get elements associated to entity------- ticpp::Element* childelement; //A BODY ELEMENT childelement = xmlelement->FirstChildElement("Body"); mBodyBuilder.ReadBodyParams(childelement); //A SPRITE ELEMENT childelement = xmlelement->FirstChildElement("Sprite"); mSpriteBuilder.ReadSpriteParams(childelement); //A SPAWNAIDEF ELEMENT childelement = xmlelement->FirstChildElement("SpawnAIDef"); { mParams.spawnaibuilderptr = AIAgentBuilderPointer (new AIAgentBuilder()); mParams.spawnaibuilderptr->ReadAIParams(childelement); } mParamsLoaded = true; }