using namespace tecplot::___3933; namespace tecplot { namespace teciompi { DataSetWriterMPI::DataSetWriterMPI( ___37* ___36, ___3501 vars, ___3501 ___4671, ___1844 const& maxIJKSubzoneSize, ___2090::ItemOffset_t maxFESubzoneSize, MPI_Comm communicator, int mainProcess, int localProcess, bool flushToDisk ) : DataSetWriter(___36, vars, ___4671, maxIJKSubzoneSize, maxFESubzoneSize, flushToDisk) , m_communicator(communicator) , m_mainProcess(mainProcess) , m_localProcess(localProcess) {} DataSetWriterMPI::~DataSetWriterMPI() {} ___372 DataSetWriterMPI::writeDataSet( FileWriterInterface& szpltFile, ___1392& szpltZoneHeaderFileLocs) { REQUIRE(szpltFile.___2041()); if (!___2337->___896()) return ___4226; ___372 ___2039 = ___4226; #if defined _WIN32 && _MSC_FULL_VER < 190022816 unsigned int oldOutputFormat = _set_output_format(_TWO_DIGIT_EXPONENT); #endif try { ZoneWriterFactoryMPI ___4710(___2680, *___2337, m_communicator, m_mainProcess); boost::unordered_map<___4636, boost::shared_ptr<___4709> > zoneWriterMap; boost::unordered_map<___4636, ___1393> zoneFileLocMap; if (m_localProcess == m_mainProcess) { ___1393 fileLoc = szpltFile.fileLoc(); MPICommunicator communicator(m_communicator); m_zoneIter->reset(); ___4636 const ___341 = m_zoneIter->baseItem(); while (___2039 && m_zoneIter->hasNext()) { ___4636 const ___904 = m_zoneIter->next(); ___4636 const fileZone = ___904 - ___341; if (!___2337->___4638(___904 + 1)) continue; uint64_t zoneFileSize; if (___2337->zoneIsPartitioned(___904 + 1) || ___2337->zoneGetOwnerProcess(___904 + 1) == m_localProcess) { zoneFileLocMap[fileZone] = fileLoc; std::vector<___372> ___4564; ___372 ___4499; getZoneSharing(___4564, ___4499, ___904, ___341, szpltFile.___844()); zoneWriterMap[fileZone] = ___4710.___4708(*m_varIter, ___904, ___341, ___4564, ___4499); zoneFileSize = zoneWriterMap[fileZone]->zoneFileSize(szpltFile.___2002() == ___4226); } else { int zoneOwner = ___2337->zoneGetOwnerProcess(___904 + 1); communicator.sendScalar(fileLoc, zoneOwner, TecioMPI::ZONE_FILE_LOC); communicator.receiveScalar(zoneFileSize, zoneOwner, TecioMPI::ZONE_FILE_SIZE); } fileLoc += zoneFileSize; } } else { MPINonBlockingCommunicationCollection communicationCollection(m_communicator); m_zoneIter->reset(); ___4636 const ___341 = m_zoneIter->baseItem(); while (___2039 && m_zoneIter->hasNext()) { ___4636 const ___904 = m_zoneIter->next(); ___4636 const fileZone = ___904 - ___341; if (!___2337->___4638(___904 + 1)) continue; if (___2337->zoneIsPartitioned(___904 + 1) || ___2337->zoneGetOwnerProcess(___904 + 1) == m_localProcess) { std::vector<___372> ___4564; ___372 ___4499; getZoneSharing(___4564, ___4499, ___904, ___341, szpltFile.___844()); zoneWriterMap[fileZone] = ___4710.___4708(*m_varIter, ___904, ___341, ___4564, ___4499); uint64_t zoneSize = zoneWriterMap[fileZone]->zoneFileSize(szpltFile.___2002() == ___4226); if (!___2337->zoneIsPartitioned(___904 + 1)) { communicationCollection.sendScalarCopy(zoneSize, m_mainProcess, TecioMPI::ZONE_FILE_SIZE); communicationCollection.receiveScalar(zoneFileLocMap[fileZone], m_mainProcess, TecioMPI::ZONE_FILE_LOC); } } } communicationCollection.___4446(); } m_zoneIter->reset(); ___4636 const ___341 = m_zoneIter->baseItem(); while (___2039 && m_zoneIter->hasNext()) { ___4636 const ___904 = m_zoneIter->next(); ___4636 const fileZone = ___904 - ___341; if (!___2337->___4638(___904 + 1)) continue; if (___2337->zoneIsPartitioned(___904 + 1) || ___2337->zoneGetOwnerProcess(___904 + 1) == m_localProcess) { ___2039 = zoneWriterMap[fileZone]->writeZone(szpltFile, zoneFileLocMap[fileZone]); if (m_localProcess == m_mainProcess) { szpltZoneHeaderFileLocs[fileZone] = zoneWriterMap[fileZone]->getZoneHeaderFilePosition(); m_varIter->reset(); ___4352 const baseVar = m_varIter->baseItem(); while (m_varIter->hasNext()) { ___4352 const datasetVar = m_varIter->next(); ___4352 const fileVar = datasetVar - baseVar; m_zoneVarMetadata->m_vzMinMaxes[fileVar][fileZone] = zoneWriterMap[fileZone]->varMinMax(datasetVar); } } else if (!___2337->zoneIsPartitioned(___904 + 1)) { MPINonBlockingCommunicationCollection communicationCollection(m_communicator); ___1393 headerFileLoc = zoneWriterMap[fileZone]->getZoneHeaderFilePosition(); communicationCollection.sendScalarCopy(headerFileLoc, m_mainProcess, TecioMPI::HEADER_FILE_LOC); std::vector<double> minValues; std::vector<double> maxValues; m_varIter->reset(); while (m_varIter->hasNext()) { ___4352 const ___4336 = m_varIter->next(); ___2479 varMinMax = zoneWriterMap[fileZone]->varMinMax(___4336); minValues.push_back(varMinMax.minValue()); maxValues.push_back(varMinMax.maxValue()); } communicationCollection.sendVectorCopy(minValues, m_mainProcess, TecioMPI::VAR_MIN_VALUES_SIZE, TecioMPI::VAR_MIN_VALUES_VEC); communicationCollection.sendVectorCopy(maxValues, m_mainProcess, TecioMPI::VAR_MAX_VALUES_SIZE, TecioMPI::VAR_MAX_VALUES_VEC); communicationCollection.___4446(); } } else if (m_localProcess == m_mainProcess) { int zoneOwner = ___2337->zoneGetOwnerProcess(___904 + 1); MPICommunicator communicator(m_communicator); communicator.receiveScalar(szpltZoneHeaderFileLocs[fileZone], zoneOwner, TecioMPI::HEADER_FILE_LOC); SimpleVector<double> minValues; SimpleVector<double> maxValues; communicator.receiveVector(minValues, zoneOwner, TecioMPI::VAR_MIN_VALUES_SIZE, TecioMPI::VAR_MIN_VALUES_VEC); communicator.receiveVector(maxValues, zoneOwner, TecioMPI::VAR_MAX_VALUES_SIZE, TecioMPI::VAR_MAX_VALUES_VEC); ___478(minValues.size() == m_varIter->___2812()); ___478(maxValues.size() == m_varIter->___2812()); m_varIter->reset(); ___4352 const baseVar = m_varIter->baseItem(); while (m_varIter->hasNext()) { ___4352 const fileVar = m_varIter->next() - baseVar; m_zoneVarMetadata->m_vzMinMaxes[fileVar][fileZone] = ___2479(minValues[fileVar], maxValues[fileVar]); } } if (szpltFile.___844() == ___845) ___2680.remove(___904); } if (!___2039) { ___2680.clear(); } } catch(std::exception const& e) { ___2039 = ___1186(e.what()); } #if defined _WIN32 _set_output_format(oldOutputFormat); #endif return ___2039; } }}
const char *TranslationManager::translate( char *inTranslationKey ) { char *translatedString = NULL; SimpleVector<char *> *keys = mStaticMembers.mTranslationKeys; SimpleVector<char *> *naturalLanguageStrings = mStaticMembers.mNaturalLanguageStrings; if( keys != NULL ) { int numKeys = keys->size(); for( int i=0; i<numKeys && translatedString == NULL; i++ ) { if( strcmp( inTranslationKey, *( keys->getElement( i ) ) ) == 0 ) { // keys match translatedString = *( naturalLanguageStrings->getElement( i ) ); } } } if( translatedString == NULL ) { translatedString = inTranslationKey; } return translatedString; }
void LocalAddressReceiver::removeReceiveAddress( char *inAddress ) { mReceiveAddressLock->lock(); int index = findAddressIndex( inAddress ); if( index != -1 ) { delete [] *( mAddressVector->getElement( index ) ); mAddressVector->deleteElement( index ); SimpleVector<char *> *currentMessageQueue = *( mMessageQueueVector->getElement( index ) ); SimpleVector<char *> *currentFromAddressQueue = *( mFromAddressQueueVector->getElement( index ) ); int numInQueue = currentMessageQueue->size(); for( int j=0; j<numInQueue; j++ ) { delete [] *( currentMessageQueue->getElement( j ) ); delete [] *( currentFromAddressQueue->getElement( j ) ); } delete currentMessageQueue; delete currentFromAddressQueue; mMessageQueueVector->deleteElement( index ); mFromAddressQueueVector->deleteElement( index ); } mReceiveAddressLock->unlock(); }
void markEmotionsLive() { for( int i=0; i<emotions.size(); i++ ) { Emotion *e = emotions.getElement( i ); if( e->eyeEmot > 0 ) { addBaseObjectToLiveObjectSet( e->eyeEmot ); } if( e->mouthEmot > 0 ) { addBaseObjectToLiveObjectSet( e->mouthEmot ); } if( e->otherEmot > 0 ) { addBaseObjectToLiveObjectSet( e->otherEmot ); } if( e->faceEmot > 0 ) { addBaseObjectToLiveObjectSet( e->faceEmot ); } if( e->bodyEmot > 0 ) { addBaseObjectToLiveObjectSet( e->bodyEmot ); } if( e->headEmot > 0 ) { addBaseObjectToLiveObjectSet( e->headEmot ); } } }
LocalAddressReceiver::~LocalAddressReceiver() { mReceiveAddressLock->lock(); int numAddresses = mAddressVector->size(); int i; for( i=0; i<numAddresses; i++ ) { delete [] *( mAddressVector->getElement( i ) ); SimpleVector<char *> *currentMessageQueue = *( mMessageQueueVector->getElement( i ) ); SimpleVector<char *> *currentFromAddressQueue = *( mFromAddressQueueVector->getElement( i ) ); int numInQueue = currentMessageQueue->size(); for( int j=0; j<numInQueue; j++ ) { delete [] *( currentMessageQueue->getElement( j ) ); delete [] *( currentFromAddressQueue->getElement( j ) ); } delete currentMessageQueue; delete currentFromAddressQueue; } delete mAddressVector; delete mMessageQueueVector; delete mFromAddressQueueVector; mReceiveAddressLock->unlock(); if (!mHandlerLock->tryLockForWrite(2000)) { //FIXME : if no lock obtaine after 2 seconds : what to do ? printf("strange, lock for write in ~LocalAddressReceiver not obtained!!!\n"); } int numHandlers = mMessageHandlerVector->size(); for( i=0; i<numHandlers; i++ ) { MessageHandlerWrapper *wrapper = *( mMessageHandlerVector->getElement( i ) ); delete wrapper; } delete mMessageHandlerVector; numHandlers = mGlobalMessageHandlerVector->size(); for( i=0; i<numHandlers; i++ ) { MessageHandlerWrapper *wrapper = *( mGlobalMessageHandlerVector->getElement( i ) ); delete wrapper; } delete mGlobalMessageHandlerVector; mHandlerLock->unlock(); delete mHandlerLock; delete mReceiveAddressLock; }
int getToolID( const char *inName ) { for( int i=0; i<tools.size(); i++ ) { toolRecord *r = tools.getElement( i ); if( strcmp( r->name, inName ) == 0 ) { return r->id; } } return -1; }
unsigned int LocalAddressReceiver::getReceivedMessages( char *inAddress, unsigned int inNumMessages, char ***outMessages, char ***outFromAddresses ) { mReceiveAddressLock->lock(); int index = findAddressIndex( inAddress ); int returnValue; char **messages; char **fromAddresses; if( index != -1 ) { SimpleVector<char *> *currentMessageQueue = *( mMessageQueueVector->getElement( index ) ); SimpleVector<char *> *currentFromAddressQueue = *( mFromAddressQueueVector->getElement( index) ); int numToGet = inNumMessages; int numAvailable = currentMessageQueue->size(); if( numToGet > numAvailable ) { numToGet = numAvailable; } messages = new char*[numToGet]; fromAddresses = new char*[numToGet]; for( int i=0; i<numToGet; i++ ) { messages[i] = *( currentMessageQueue->getElement(0) ); fromAddresses[i] = *( currentFromAddressQueue->getElement(0) ); currentMessageQueue->deleteElement( 0 ); currentFromAddressQueue->deleteElement( 0 ); } returnValue = numToGet; } else { returnValue = 0; messages = new char*[0]; fromAddresses = new char*[0]; } *outMessages = messages; *outFromAddresses = fromAddresses; mReceiveAddressLock->unlock(); return returnValue; }
Shadow *prm_findShadow(const char *id) { int i; for (i=0; i<g_shadowTable.size(); i++) { if (strcmp(g_shadowTable[i].id, id)==0) return &g_shadowTable[i]; } return NULL; }
SoundUsage scanSoundUsage( char *inString ) { SimpleVector<int> idVector; SimpleVector<double> volVector; int numParts = 0; char **parts = split( inString, "#", &numParts ); for( int i=0; i<numParts; i++ ) { int id = -1; double vol = 1.0; sscanf( parts[i], "%d:%lf", &id, &vol ); if( id != -1 && vol >=0 && vol <= 1.0 ) { idVector.push_back( id ); volVector.push_back( vol ); } delete [] parts[i]; } delete [] parts; if( idVector.size() > 0 ) { if( idVector.size() == 1 && idVector.getElementDirect( 0 ) == -1 ) { return blankSoundUsage; } SoundUsage u = { idVector.size(), idVector.getElementArray(), volVector.getElementArray() }; return u; } else { return blankSoundUsage; } }
int *getFullToolIDList( int *outNumIDs ) { *outNumIDs = tools.size(); int *returnList = new int[ *outNumIDs ]; for( int i=0; i<*outNumIDs; i++ ) { toolRecord *r = tools.getElement( i ); returnList[i] = r->id; } return returnList; }
void initCategoryBankFinish() { freeFolderCache( cache ); mapSize = maxID + 1; idMap = new CategoryRecord*[ mapSize ]; for( int i=0; i<mapSize; i++ ) { idMap[i] = NULL; } reverseMapSize = maxObjectID + 1; reverseMap = new ReverseCategoryRecord*[reverseMapSize]; for( int i=0; i<reverseMapSize; i++ ) { reverseMap[i] = NULL; } int numRecords = records.size(); for( int i=0; i<numRecords; i++ ) { CategoryRecord *r = records.getElementDirect(i); idMap[ r->parentID ] = r; for( int j=0; j<r->objectIDSet.size(); j++ ) { int objID = r->objectIDSet.getElementDirect( j ); ReverseCategoryRecord *rr = reverseMap[ objID ]; if( rr == NULL ) { rr = new ReverseCategoryRecord; rr->childID = objID; reverseMap[ objID ] = rr; } rr->categoryIDSet.push_back( r->parentID ); } } printf( "Loaded %d categories from categories folder\n", numRecords ); }
// -1 if no emotion triggered int getEmotionIndex( const char *inSpeech ) { char *upperSpeech = stringToUpperCase( inSpeech ); for( int i=0; i<emotions.size(); i++ ) { if( strstr( upperSpeech, emotions.getElement(i)->triggerWord ) == upperSpeech ) { // starts with trigger delete [] upperSpeech; return i; } } delete [] upperSpeech; return -1; }
char *readStreamUpToTagAndGetToken( InputStream *inInputStream, char *inTag, int inMaxCharsToRead, int inTokenNumber ) { // read the string char *readString = readStreamUpToTag( inInputStream, inTag, inMaxCharsToRead ); if( readString == NULL ) { return NULL; } SimpleVector<char *> *readTokens = tokenizeString( readString ); delete [] readString; // second token should be their key char *selectedToken = NULL; int numTokens = readTokens->size(); if( numTokens > inTokenNumber ) { selectedToken = stringDuplicate( *( readTokens->getElement( inTokenNumber ) ) ); } else { char *message = autoSprintf( "Looking for token %d, but only %d tokens available\n", inTokenNumber, numTokens ); AppLog::error( "readStreamUpToTagAndGetToken", message ); } for( int i=0; i<numTokens; i++ ) { delete [] *( readTokens->getElement( i ) ); } delete readTokens; // will be NULL if not enough tokens read return selectedToken; }
char OutboundChannel::sendMessage( char * inMessage, int inPriority ) { mLock->lock(); char sent; if( !mConnectionBroken ) { // add it to the queue SimpleVector<char *> *queueToUse; if( inPriority <=0 ) { queueToUse = mMessageQueue; } else { queueToUse = mHighPriorityMessageQueue; } queueToUse->push_back( stringDuplicate( inMessage ) ); sent = true; if( queueToUse->size() > mMaxQueueSize ) { // the queue is over-full // drop the oldest message char *message = *( queueToUse->getElement( 0 ) ); queueToUse->deleteElement( 0 ); delete [] message; mDroppedMessageCount++; } } else { // channel no longer working sent = false; } mLock->unlock(); if( sent ) { mMessageReadySemaphore->signal(); } return sent; }
int32_t prm_resetShadows() { int i, n; for (i=0, n=0; i<g_shadowTable.size(); i++) { if (g_shadowTable[i].data) { free(g_shadowTable[i].data); g_shadowTable[i].data = NULL; g_shadowTable[i].len = 0; n++; } } if (n>0) g_dirty = true; // force a reloading of parameters return n; }
unsigned int LocalAddressReceiver::getWaitingMessageCount( char *inAddress ) { mReceiveAddressLock->lock(); int index = findAddressIndex( inAddress ); unsigned int returnValue; if( index != -1 ) { SimpleVector<char *> *currentMessageQueue = *( mMessageQueueVector->getElement( index ) ); returnValue = currentMessageQueue->size(); } else { returnValue = 0; } mReceiveAddressLock->unlock(); return returnValue; }
char *WebClient::receiveData( SocketStream *inSocketStream, int *outContentLength ) { SimpleVector<char> *receivedVector = new SimpleVector<char>(); char connectionBroken = false; long bufferLength = 5000; unsigned char *buffer = new unsigned char[ bufferLength ]; while( !connectionBroken ) { int numRead = inSocketStream->read( buffer, bufferLength ); if( numRead != bufferLength ) { connectionBroken = true; } if( numRead > 0 ) { for( int i=0; i<numRead; i++ ) { receivedVector->push_back( buffer[i] ); } } } delete [] buffer; // copy our vector into an array int receivedSize = receivedVector->size(); char *received = new char[ receivedSize + 1 ]; for( int i=0; i<receivedSize; i++ ) { received[i] = *( receivedVector->getElement( i ) ); } received[ receivedSize ] = '\0'; delete receivedVector; *outContentLength = receivedSize; return received; }
void freeTools() { for( int i=0; i<tools.size(); i++ ) { toolRecord r = *( tools.getElement( i ) ); delete [] r.name; delete [] r.description; delete [] r.descriptionPlural; freeSprite( r.sprite ); } tools.deleteAll(); if( idToIndexMap != NULL ) { delete [] idToIndexMap; idToIndexMap = NULL; } }
void freeLineageLog() { if( lineageServerURL != NULL ) { delete [] lineageServerURL; lineageServerURL = NULL; } if( serverID != NULL ) { delete [] serverID; serverID = NULL; } for( int i=0; i<records.size(); i++ ) { delete records.getElement(i)->request; delete [] records.getElement(i)->email; delete [] records.getElement(i)->name; delete [] records.getElement(i)->lastSay; } records.deleteAll(); }
char *SettingsManager::getStringSetting( const char *inSettingName ) { char *value = NULL; SimpleVector<char *> *settingsVector = getSetting( inSettingName ); int numStrings = settingsVector->size(); if( numStrings >= 1 ) { char *firstString = *( settingsVector->getElement( 0 ) ); value = stringDuplicate( firstString ); } for( int i=0; i<numStrings; i++ ) { char *nextString = *( settingsVector->getElement( i ) ); delete [] nextString; } delete settingsVector; return value; }
void parsePlayerUpdateMessage( Client *inC, char *inMessageLine ) { SimpleVector<char*> *tokens = tokenizeString( inMessageLine ); //printf( "\n\nParsing PU line: %s\n\n", inMessageLine ); if( tokens->size() > 16 ) { int id = -1; sscanf( tokens->getElementDirect(0), "%d", &( id ) ); if( inC->id == -1 ) { inC->id = id; } if( inC->id == id ) { // update pos if( inC->moving ) { //printf( "Client %d done moving\n", inC->i ); } if( strcmp( tokens->getElementDirect(14), "X" ) == 0 ) { // dead inC->dead = true; printf( "Client %d died with PU message: %s\n", inC->i, inMessageLine ); } else { sscanf( tokens->getElementDirect(14), "%d", &( inC->x ) ); sscanf( tokens->getElementDirect(15), "%d", &( inC->y ) ); inC->moving = false; } } } tokens->deallocateStringElements(); delete tokens; }
void initTools() { File elementsDir( NULL, "gameElements" ); if( !elementsDir.exists() || !elementsDir.isDirectory() ) { return; } File *toolsDir = elementsDir.getChildFile( "tools" ); if( toolsDir == NULL ) { return; } else if( !toolsDir->exists() || !toolsDir->isDirectory() ) { delete toolsDir; return; } int numTools; File **toolNameDirs = toolsDir->getChildFiles( &numTools ); delete toolsDir; if( toolNameDirs == NULL ) { return; } for( int i=0; i<numTools; i++ ) { File *f = toolNameDirs[i]; if( f->exists() && f->isDirectory() ) { char completeRecord = true; toolRecord r; r.name = f->getFileName(); r.description = NULL; r.descriptionPlural = NULL; r.sprite = NULL; File *infoFile = f->getChildFile( "info.txt" ); completeRecord = readInfoFile( infoFile, &( r.id ), &( r.description ) ); delete infoFile; if( completeRecord ) { File *pluralFile = f->getChildFile( "plural.txt" ); completeRecord = readPluralFile( pluralFile, &( r.descriptionPlural ) ); delete pluralFile; } if( completeRecord ) { // read reach, if present (if not, default to 1) r.reach = 1; File *reachFile = f->getChildFile( "reach.txt" ); if( reachFile->exists() ) { char *reach = reachFile->readFileContents(); sscanf( reach, "%d", &( r.reach ) ); delete [] reach; } delete reachFile; File *reachSigFile = f->getChildFile( "reachSignature.txt" ); char *reachSigContents = NULL; if( reachSigFile->exists() ) { reachSigContents = reachSigFile->readFileContents(); } delete reachSigFile; char reachSigOK = true; if( regenerateReachSignatures ) { // ignore reachSignature.txt and generate a new one char *newSig = computeReachSignature( &r ); File *childFile = f->getChildFile( "reachSignature.txt" ); if( childFile != NULL ) { childFile->writeToFile( newSig ); delete childFile; } delete [] newSig; } else if( reachSigContents == NULL ) { reachSigOK = false; } else { // else check it char *sig = trimWhitespace( reachSigContents ); char *trueSig = computeReachSignature( &r ); if( strcmp( trueSig, sig ) != 0 ) { reachSigOK = false; } delete [] sig; delete [] trueSig; } if( reachSigContents != NULL ) { delete [] reachSigContents; } if( !reachSigOK ) { char *dirName = f->getFullFileName(); char *message = autoSprintf( "%s\n%s", translate( "badReachSignature" ), dirName ); delete [] dirName; loadingFailed( message ); delete [] message; } // look for sprite TGA int numChildFiles; File **childFiles = f->getChildFiles( &numChildFiles ); char *tgaPath = NULL; char *shadeMapTgaPath = NULL; for( int j=0; j<numChildFiles; j++ ) { File *f = childFiles[j]; char *name = f->getFileName(); if( strstr( name, "_shadeMap.tga" ) != NULL ) { if( shadeMapTgaPath != NULL ) { delete [] shadeMapTgaPath; } shadeMapTgaPath = f->getFullFileName(); } else if( strstr( name, ".tga" ) != NULL ) { if( tgaPath != NULL ) { delete [] tgaPath; } tgaPath = f->getFullFileName(); } delete [] name; delete childFiles[j]; } delete [] childFiles; if( tgaPath != NULL ) { // assume only one orientation here // discard extras SpriteHandle readSprites[ MAX_ORIENTATIONS ]; int numOrientations = readShadeMappedSprites( tgaPath, shadeMapTgaPath, readSprites ); if( numOrientations == 0 ) { completeRecord = false; } else { r.sprite = readSprites[0]; for( int o=1; o<numOrientations; o++ ) { freeSprite( readSprites[o] ); } } } else { if( shadeMapTgaPath != NULL ) { delete [] shadeMapTgaPath; } completeRecord = false; } } if( completeRecord ) { if( r.id >= idSpaceSize ) { idSpaceSize = r.id + 1; } tools.push_back( r ); } else { delete [] r.name; if( r.description != NULL ) { delete [] r.description; } if( r.descriptionPlural != NULL ) { delete [] r.descriptionPlural; } if( r.sprite != NULL ) { freeSprite( r.sprite ); } } } delete f; } delete [] toolNameDirs; // build map idToIndexMap = new int[idSpaceSize]; for( int i=0; i<idSpaceSize; i++ ) { idToIndexMap[i] = -1; } for( int i=0; i<tools.size(); i++ ) { toolRecord r = *( tools.getElement( i ) ); idToIndexMap[r.id] = i; } }
void freeEmotion() { for( int i=0; i<emotions.size(); i++ ) { delete [] emotions.getElementDirect(i).triggerWord; } emotions.deleteAll(); }
void initEmotion() { char *cont = SettingsManager::getSettingContents( "emotionWords", "" ); if( strcmp( cont, "" ) == 0 ) { delete [] cont; return; } int numParts; char **parts = split( cont, "\n", &numParts ); delete [] cont; for( int i=0; i<numParts; i++ ) { if( strcmp( parts[i], "" ) != 0 ) { Emotion e = { stringToUpperCase( parts[i] ), 0, 0, 0 }; emotions.push_back( e ); } delete [] parts[i]; } delete [] parts; // now read emotion objects cont = SettingsManager::getSettingContents( "emotionObjects", "" ); if( strcmp( cont, "" ) == 0 ) { delete [] cont; return; } parts = split( cont, "\n", &numParts ); delete [] cont; for( int i=0; i<numParts; i++ ) { if( strcmp( parts[i], "" ) != 0 ) { Emotion *e; if( i < emotions.size() ) { e = emotions.getElement( i ); } else { // the list extends beyond emotion words // put dummy trigger in place for these // * is a character that the end user cannot type Emotion eNew = { stringDuplicate( "DUMMY*TRIGGER" ), 0, 0, 0 }; emotions.push_back( eNew ); e = emotions.getElement( emotions.size() - 1 ); } e->eyeEmot = 0; e->mouthEmot = 0; e->otherEmot = 0; e->faceEmot = 0; e->bodyEmot = 0; e->headEmot = 0; sscanf( parts[i], "%d %d %d %d %d %d", &( e->eyeEmot ), &( e->mouthEmot ), &( e->otherEmot ), &( e->faceEmot ), &( e->bodyEmot ), &( e->headEmot ) ); } delete [] parts[i]; } delete [] parts; }
void testSimpleVectorSize() { SimpleVector v = createSimpleVector(5); BOOST_CHECK( v.size() == 5 ); }
// returns NULL if index out of range Emotion *getEmotion( int inIndex ) { if( inIndex < 0 || inIndex >= emotions.size() ) { return NULL; } return emotions.getElement( inIndex ); }
MusicNoteWaveTable::MusicNoteWaveTable( unsigned long inSamplesPerSecond ){ // read frequencies and lengths from files SimpleVector<double> *frequencyVector = new SimpleVector<double>(); SimpleVector<double> *lengthVector = new SimpleVector<double>(); FILE *musicNotePitchesFILE = NULL; FILE *musicNoteLengthsFILE = NULL; if( musicNotePitchesFILE != NULL ) { double readValue; int numRead = 1; while( numRead == 1 ) { numRead = fscanf( musicNotePitchesFILE, "%lf", &readValue ); if( numRead == 1 ) { frequencyVector->push_back( readValue ); } } fclose( musicNotePitchesFILE ); } else { // default pitches // Note N,, means N two octaves down // N'' means two octaves up /* // This one sounds pretty good // but not enough notes, too bland // A,, frequencyVector->push_back( 110 ); // D, frequencyVector->push_back( 146.832 ); // A, frequencyVector->push_back( 220 ); // D frequencyVector->push_back( 293.665 ); // G frequencyVector->push_back( 391.995 ); // C' frequencyVector->push_back( 523.251 ); // E' frequencyVector->push_back( 659.255 ); // G' frequencyVector->push_back( 783.991 ); */ // Instead, use entire two-octaves from c-major scale // Problem: there can be some discords. // However: much more interesting sounding than the two-chord version // above // base note: C, double baseNote = 130.8127827; int majorScaleSteps[7] = {2,2,1,2,2,2,1}; int scaleIndex = 0; int notePower = 0; // two octaves while( notePower < 25 ) { frequencyVector->push_back( baseNote * pow( 2, notePower / 12.0 ) ); notePower += majorScaleSteps[ scaleIndex ]; scaleIndex ++; if( scaleIndex >= 7 ) { // wrap around scaleIndex = 0; } } /* // These are the notes from Transcend level 001 frequencyVector->push_back( 220 ); frequencyVector->push_back( 277.183 ); frequencyVector->push_back( 329.628 ); frequencyVector->push_back( 440 ); frequencyVector->push_back( 554.365 ); frequencyVector->push_back( 659.255 ); */ } if( musicNoteLengthsFILE != NULL ) { double readValue; int numRead = 1; while( numRead == 1 ) { numRead = fscanf( musicNoteLengthsFILE, "%lf", &readValue ); if( numRead == 1 ) { lengthVector->push_back( readValue ); } } fclose( musicNoteLengthsFILE ); } else { // default lengths lengthVector->push_back( globalLongestNoteLength ); lengthVector->push_back( globalShortestNoteLength ); } mFrequencyCount = frequencyVector->size(); mLengthCount = lengthVector->size(); double *frequencies = frequencyVector->getElementArray(); mLengthsInSeconds = lengthVector->getElementArray(); delete frequencyVector; delete lengthVector; mSampleTable = new float**[ mFrequencyCount ]; mSampleCounts = new unsigned long[ mLengthCount ]; for( int F=0; F<mFrequencyCount; F++ ) { mSampleTable[F] = new float*[ mLengthCount ]; for( int L=0; L<mLengthCount; L++ ) { // construct a sample table for this freqency/length pair unsigned long lengthInSamples = (unsigned long)( mLengthsInSeconds[L] * inSamplesPerSecond ); mSampleTable[F][L] = new float[ lengthInSamples ]; // setting this inside a double-loop will set the same // value repeatedly with the same value, but this makes the code // cleaner (other options: a separate loop to set this value, or // an if statement to ensure that it is set only once) mSampleCounts[L] = lengthInSamples; // populate the sample table with a linearly decaying sine wave double frequencyInCyclesPerSecond = frequencies[F]; double frequencyInCyclesPerSample = frequencyInCyclesPerSecond / inSamplesPerSecond; // sine function cycles every 2*pi // adjust so that it cycles according to our desired frequency double adjustedFrequency = frequencyInCyclesPerSample * ( 2 * M_PI ); // try to fade in for 100 samples to avoid a click // at the start of the note unsigned long numFadeInSamples = 100; if( numFadeInSamples > lengthInSamples ) { numFadeInSamples = lengthInSamples / 2; } // optimizations (found with profiler) // pull these out of inner loop float lengthInSamplesMinusOne = (float)lengthInSamples - 1.0f; float inv_lengthInSamplesMinusOne = 1.0f / lengthInSamplesMinusOne; float *theseSamples = mSampleTable[F][L]; for( unsigned long i=0; i<lengthInSamples; i++ ) { // decay loudness linearly float loudness = ( lengthInSamplesMinusOne - i ) * inv_lengthInSamplesMinusOne; // fade in for the first 100 samples to avoid // a click if( i < numFadeInSamples ) { float fadeInFactor = (float)( i ) / (float)( numFadeInSamples - 1 ); // optimization: // only do this extra multiplication for notes that // are fading in loudness *= fadeInFactor; } theseSamples[i] = loudness * (float)sin( i * adjustedFrequency ); } } } delete [] frequencies; }
char pathFind( int inMapH, int inMapW, char *inBlockedMap, GridPos inStart, GridPos inGoal, int *outFullPathLength, GridPos **outFullPath ) { // watch for degen case where start and goal are equal if( equal( inStart, inGoal ) ) { if( outFullPathLength != NULL ) { *outFullPathLength = 0; } if( outFullPath != NULL ) { *outFullPath = NULL; } return true; } // insertion-sorted queue of records waiting to be searched pathSearchQueue recordsToSearch; // keep records here, even after we're done with them, // to ensure they get deleted SimpleVector<pathSearchRecord*> searchQueueRecords; SimpleVector<pathSearchRecord> doneQueue; int numFloorSquares = inMapH * inMapW; // quick lookup of touched but not done squares // indexed by floor square index number char *openMap = new char[ numFloorSquares ]; memset( openMap, false, numFloorSquares ); char *doneMap = new char[ numFloorSquares ]; memset( doneMap, false, numFloorSquares ); pathSearchRecord startRecord = { inStart, inStart.y * inMapW + inStart.x, 0, getGridDistance( inStart, inGoal ), getGridDistance( inStart, inGoal ), -1, NULL }; // can't keep pointers in a SimpleVector // (change as vector expands itself) // push heap pointers into vector instead pathSearchRecord *heapRecord = new pathSearchRecord( startRecord ); searchQueueRecords.push_back( heapRecord ); recordsToSearch.head = heapRecord; openMap[ startRecord.squareIndex ] = true; char done = false; //while( searchQueueRecords.size() > 0 && !done ) { while( recordsToSearch.head != NULL && !done ) { // head of queue is best pathSearchRecord bestRecord = *( recordsToSearch.head ); recordsToSearch.head = recordsToSearch.head->nextSearchRecord; if( false ) printf( "Best record found: " "(%d,%d), cost %d, total %f, " "pred %d, this index %d\n", bestRecord.pos.x, bestRecord.pos.y, bestRecord.cost, bestRecord.total, bestRecord.predIndex, doneQueue.size() ); doneMap[ bestRecord.squareIndex ] = true; openMap[ bestRecord.squareIndex ] = false; doneQueue.push_back( bestRecord ); int predIndex = doneQueue.size() - 1; if( equal( bestRecord.pos, inGoal ) ) { // goal record has lowest total score in queue done = true; } else { // add neighbors GridPos neighbors[4]; GridPos bestPos = bestRecord.pos; neighbors[0].x = bestPos.x; neighbors[0].y = bestPos.y - 1; neighbors[1].x = bestPos.x; neighbors[1].y = bestPos.y + 1; neighbors[2].x = bestPos.x - 1; neighbors[2].y = bestPos.y; neighbors[3].x = bestPos.x + 1; neighbors[3].y = bestPos.y; // one step to neighbors from best record int cost = bestRecord.cost + 1; for( int n=0; n<4; n++ ) { int neighborSquareIndex = neighbors[n].y * inMapW + neighbors[n].x; if( ! inBlockedMap[ neighborSquareIndex ] ) { // floor char alreadyOpen = openMap[ neighborSquareIndex ]; char alreadyDone = doneMap[ neighborSquareIndex ]; if( !alreadyOpen && !alreadyDone ) { // for testing, color touched nodes // mGridColors[ neighborSquareIndex ].r = 1; // add this neighbor double dist = getGridDistance( neighbors[n], inGoal ); // track how we got here (pred) pathSearchRecord nRecord = { neighbors[n], neighborSquareIndex, cost, dist, dist + cost, predIndex, NULL }; pathSearchRecord *heapRecord = new pathSearchRecord( nRecord ); searchQueueRecords.push_back( heapRecord ); insertSearchRecord( &recordsToSearch, heapRecord ); openMap[ neighborSquareIndex ] = true; } else if( alreadyOpen ) { pathSearchRecord *heapRecord = pullSearchRecord( &recordsToSearch, neighborSquareIndex ); // did we reach this node through a shorter path // than before? if( cost < heapRecord->cost ) { // update it! heapRecord->cost = cost; heapRecord->total = heapRecord->estimate + cost; // found a new predecessor for this node heapRecord->predIndex = predIndex; } // reinsert insertSearchRecord( &recordsToSearch, heapRecord ); } } } } } char failed = false; if( ! done ) { failed = true; } delete [] openMap; delete [] doneMap; for( int i=0; i<searchQueueRecords.size(); i++ ) { delete *( searchQueueRecords.getElement( i ) ); } if( failed ) { return false; } // follow index to reconstruct path // last in done queue is best-reached goal node int currentIndex = doneQueue.size() - 1; pathSearchRecord *currentRecord = doneQueue.getElement( currentIndex ); pathSearchRecord *predRecord = doneQueue.getElement( currentRecord->predIndex ); done = false; SimpleVector<GridPos> finalPath; finalPath.push_back( currentRecord->pos ); while( ! equal( predRecord->pos, inStart ) ) { currentRecord = predRecord; finalPath.push_back( currentRecord->pos ); predRecord = doneQueue.getElement( currentRecord->predIndex ); } // finally, add start finalPath.push_back( predRecord->pos ); SimpleVector<GridPos> finalPathReversed; int numSteps = finalPath.size(); for( int i=numSteps-1; i>=0; i-- ) { finalPathReversed.push_back( *( finalPath.getElement( i ) ) ); } if( outFullPathLength != NULL ) { *outFullPathLength = finalPath.size(); } if( outFullPath != NULL ) { *outFullPath = finalPathReversed.getElementArray(); } return true; }
void BuyAuctionPage::step() { if( mWebRequest != -1 ) { int stepResult = stepWebRequestSerial( mWebRequest ); if( stepResult != 0 ) { setWaiting( false ); } switch( stepResult ) { case 0: break; case -1: mStatusError = true; mStatusMessageKey = "err_webRequest"; clearWebRequestSerial( mWebRequest ); mWebRequest = -1; mHomeButton.setVisible( true ); break; case 1: { char *result = getWebResultSerial( mWebRequest ); clearWebRequestSerial( mWebRequest ); mWebRequest = -1; printf( "Web result = %s\n", result ); if( strstr( result, "DENIED" ) != NULL ) { mStatusError = true; mStatusMessageKey = "auctionBuyFailed"; mHomeButton.setVisible( true ); } else { // auction successful SimpleVector<char *> *tokens = tokenizeString( result ); if( tokens->size() != 2 || strcmp( *( tokens->getElement( 1 ) ), "OK" ) != 0 ) { mStatusError = true; mStatusMessageKey = "err_badServerResponse"; } else { int price; sscanf( *( tokens->getElement( 0 ) ), "%d", &price ); mBoughtSlot.setObject( mObjectID ); mBoughtSlot.setVisible( true ); mLootValue -= price; if( strcmp( mGalleryContents, "#" ) == 0 ) { // was empty, just the one new item now delete [] mGalleryContents; mGalleryContents = autoSprintf( "%d", mObjectID ); } else { // prepend char *old = mGalleryContents; mGalleryContents = autoSprintf( "%d#%s", mObjectID, mGalleryContents ); delete [] old; } const char *objectDescription = getGalleryObjectDescription( mObjectID ); char *quotedDescription = autoSprintf( "\"%s\"", objectDescription ); char *statusString = autoSprintf( translate( "auctionBuySucceed" ), quotedDescription, price ); delete [] quotedDescription; setStatusDirect( statusString, false ); delete [] statusString; } mHomeButton.setVisible( true ); for( int i=0; i<tokens->size(); i++ ) { delete [] *( tokens->getElement( i ) ); } delete tokens; } delete [] result; } break; } } }
void stepLineageLog() { if( ! useLineageServer ) { return; } for( int i=0; i<records.size(); i++ ) { LineageRecord *r = records.getElement( i ); int result = r->request->step(); char recordDone = false; if( result == -1 ) { AppLog::info( "Request to lineage server failed." ); recordDone = true; } else if( result == 1 ) { // done, have result char *webResult = r->request->getResult(); if( r->sequenceNumber == -1 ) { // still waiting for sequence number response int numRead = sscanf( webResult, "%d", &( r->sequenceNumber ) ); if( numRead != 1 ) { AppLog::info( "Failed to read sequence number " "from lineage server response." ); recordDone = true; } else { delete r->request; // start lineage-posting request char *seqString = autoSprintf( "%d", r->sequenceNumber ); char *lineageServerSharedSecret = SettingsManager::getStringSetting( "lineageServerSharedSecret", "secret_phrase" ); char *hash = hmac_sha1( lineageServerSharedSecret, seqString ); delete [] lineageServerSharedSecret; delete [] seqString; char *encodedEmail = URLUtils::urlEncode( r->email ); char *encodedName = URLUtils::urlEncode( r->name ); char *encodedLastSay = URLUtils::urlEncode( r->lastSay ); int maleInt = 0; if( r->male ) { maleInt = 1; } char *url = autoSprintf( "%s?action=log_life" "&server=%s" "&email=%s" "&age=%f" "&player_id=%d" "&parent_id=%d" "&display_id=%d" "&killer_id=%d" "&name=%s" "&last_words=%s" "&male=%d" "&sequence_number=%d" "&hash_value=%s", lineageServerURL, serverID, encodedEmail, r->age, r->playerID, r->parentID, r->displayID, r->killerID, encodedName, encodedLastSay, maleInt, r->sequenceNumber, hash ); delete [] encodedEmail; delete [] encodedName; delete [] encodedLastSay; delete [] hash; r->request = new WebRequest( "GET", url, NULL ); printf( "Starting new web request for %s\n", url ); delete [] url; } } else { if( strstr( webResult, "DENIED" ) != NULL ) { AppLog::info( "Server log_life request rejected by lineage server" ); } recordDone = true; } delete [] webResult; } if( recordDone ) { delete r->request; delete [] r->email; delete [] r->name; delete [] r->lastSay; records.deleteElement( i ); i--; } } }