void AGOSEngine::resetVerbs() { if (getGameType() == GType_ELVIRA1 || getGameType() == GType_ELVIRA2) return; uint id; HitArea *ha; if (getGameType() == GType_SIMON2) { id = 2; if (!getBitFlag(79)) id = (_mouse.y >= 136) ? 102 : 101; } else { id = (_mouse.y >= 136) ? 102 : 101; } _defaultVerb = id; ha = findBox(id); if (ha == NULL) return; if (ha->flags & kBFBoxDead) { _defaultVerb = 999; _currentVerbBox = NULL; } else { _verbHitArea = ha->verb; setVerb(ha); } }
void AGOSEngine::undefineBox(uint hitarea) { HitArea *ha = findBox(hitarea); if (ha != NULL) { ha->flags = 0; if (ha == _lastNameOn) clearName(); _needHitAreaRecalc++; } }
double InterpolateCubic::get_fdf( const std::vector<double>& pos ){ plumed_dbg_assert( pos.size()==1 ); unsigned mybox=findBox( pos ); double d1=ub[0] - lb[0]; double b=( pos[0] - lb[0] ) / d1, a=( ub[0] - pos[0] ) / d1; double *cbase=&clist[(mybox*4)+3], *c3=cbase-1, *c2=c3-1, *c1=c2-1; double f=a*(*c1) + b*(*c2) + (a*a*a-a)*(*c3) + (b*b*b-b)*(*cbase); return f; }
void AGOSEngine::disableBox(uint hitarea) { HitArea *ha = findBox(hitarea); if (ha != NULL) { ha->flags |= kBFBoxDead; ha->flags &= ~kBFBoxSelected; if ((getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) && hitarea == 102) { resetVerbs(); } } }
void AGOSEngine::moveBox(uint hitarea, int x, int y) { HitArea *ha = findBox(hitarea); if (ha != NULL) { if (getGameType() == GType_FF || getGameType() == GType_PP) { ha->x += x; ha->y += y; } else { ha->x = x; ha->y = y; } } }
void AGOSEngine_Simon1::clearName() { HitArea *ha; if (_currentVerbBox == _lastVerbOn) return; resetNameWindow(); _lastVerbOn = _currentVerbBox; if (_currentVerbBox != NULL && (ha = findBox(200)) && (ha->flags & kBFBoxDead) && !(_currentVerbBox->flags & kBFBoxDead)) printVerbOf(_currentVerbBox->id); }
void testPolyhOut() { struct polyhedron *ph; AllocVar(ph); ph->id = nextId(); ph->names[0] = cloneString("Jim"); ph->names[1] = cloneString("Kent"); ph->polygonCount = 2; slAddTail(&ph->polygons, makeTriangle(0, 0, 0)); slAddTail(&ph->polygons, makeTriangle(0, 0, 100)); findBox(ph); polyhedronCommaOut(ph, stdout); printf("\n"); polyhedronFree(&ph); }
double InterpolateBicubic::get_fdf( const std::vector<double>& pos ){ plumed_dbg_assert( pos.size()==2 ); unsigned mybox=findBox( pos ); double d1 = ub[0] - lb[0], d2 = ub[1] - lb[1]; double t = (pos[0] - lb[0]) / d1, u = (pos[1] - lb[1]) / d2; //faster access by pointer arithmetic (dirty dirty dirty) double *cbase=&clist[(mybox+1)*16-1], *c3, *c2, *c1, *c0; double f=0.; for (int i=3; i>=0; i--) { // Note to self - this has to be an int as unsigned cannot be less than zero - duh!! c3=cbase; c2=c3-1; c1=c2-1; c0=c1-1; cbase=c0-1; f= t*f + ( ( (*c3)*u + (*c2) )*u + (*c1) )*u + (*c0); } delete cbase; delete c3; delete c2; delete c1; delete c0; return f; }
void AGOSEngine::displayName(HitArea *ha) { if (getGameType() == GType_ELVIRA1 || getGameType() == GType_ELVIRA2 || getGameType() == GType_PP) return; bool result; int x = 0, y = 0; if (getGameType() == GType_FF) { if (ha->flags & kBFHyperBox) { _lastNameOn = ha; return; } if (findBox(50)) return; if (getBitFlag(99)) _animatePointer = ((ha->flags & kBFTextBox) == 0); else _animatePointer = true; if (!getBitFlag(73)) return; y = ha->y; if (getBitFlag(99) && y > 288) y = 288; y -= 17; if (y < 0) y = 0; y += 2; x = ha->width / 2 + ha->x; } else { resetNameWindow(); } if (ha->flags & kBFTextBox) { result = printTextOf(ha->flags / 256, x, y); } else { result = printNameOf(ha->itemPtr, x, y); } if (result) _lastNameOn = ha; }
// Elvira 2 and Waxworks specific void AGOSEngine::doMenuStrip(uint menuNum) { uint i; const uint var = (getGameType() == GType_WW) ? 11 : 1; for (i = 111; i != 115; i++) disableBox(i); for (i = var; i != (var + 5); i++) _variableArray[i] = 0; byte *srcPtr = _menuBase; while (menuNum--) { while (READ_BE_UINT16(srcPtr) != 0) srcPtr += 2; srcPtr += 2; } uint id = 111; uint v = var; while (READ_BE_UINT16(srcPtr) != 0) { uint verb = READ_BE_UINT16(srcPtr); _variableArray[v] = verb; HitArea *ha = findBox(id); if (ha != NULL) { ha->flags &= ~kBFBoxDead; ha->verb = verb; } id++; srcPtr += 2; v++; } _variableArray[var + 4] = id - 111; if (getGameType() == GType_WW) { setWindowImageEx(2, 102); } else { setWindowImageEx(2, 103); } }
void AGOSEngine::lightMenuBox(uint hitarea) { HitArea *ha = findBox(hitarea); byte *src; int w, h, i; mouseOff(); Graphics::Surface *screen = _system->lockScreen(); src = (byte *)screen->pixels + ha->y * screen->pitch + ha->x; w = ha->width; h = ha->height; do { for (i = 0; i != w; ++i) { if (src[i] == 14) src[i] = 15; } src += screen->pitch; } while (--h); _system->unlockScreen(); mouseOn(); }
void AGOSEngine::boxController(uint x, uint y, uint mode) { HitArea *best_ha; HitArea *ha = _hitAreas; uint count = ARRAYSIZE(_hitAreas); uint16 priority = 0; best_ha = NULL; do { if (ha->flags & kBFBoxInUse) { if (!(ha->flags & kBFBoxDead)) { if (x >= ha->x && y >= ha->y && x - ha->x < ha->width && y - ha->y < ha->height && priority <= ha->priority) { priority = ha->priority; best_ha = ha; } else { if (ha->flags & kBFBoxSelected) { hitarea_leave(ha , true); ha->flags &= ~kBFBoxSelected; } } } else { ha->flags &= ~kBFBoxSelected; } } } while (ha++, --count); _currentBoxNum = 0; _currentBox = best_ha; if (best_ha == NULL) return; _currentBoxNum = best_ha->id; if (mode != 0) { if (mode == 3) { if (best_ha->verb & 0x4000) { if (getGameType() == GType_ELVIRA1 && _variableArray[500] == 0) { _variableArray[500] = best_ha->verb & 0xBFFF; } if (_clickOnly && best_ha->id < 8) { uint id = best_ha->id; if (id >= 4) id -= 4; invertBox(findBox(id), 0, 0, 0, 0); _clickOnly = false; return; } } if (best_ha->flags & kBFDragBox) _lastClickRem = best_ha; } else { _lastHitArea = best_ha; } } if (_clickOnly) return; if (best_ha->flags & kBFInvertTouch) { if (!(best_ha->flags & kBFBoxSelected)) { hitarea_leave(best_ha, false); best_ha->flags |= kBFBoxSelected; } } else { if (mode == 0) return; if (!(best_ha->flags & kBFInvertSelect)) return; if (best_ha->flags & kBFToggleBox) { hitarea_leave(best_ha, false); best_ha->flags ^= kBFInvertSelect; } else if (!(best_ha->flags & kBFBoxSelected)) { hitarea_leave(best_ha, false); best_ha->flags |= kBFBoxSelected; } } }
void AGOSEngine::leaveHitAreaById(uint hitarea_id) { HitArea *ha = findBox(hitarea_id); if (ha) hitarea_leave(ha); }
bool AGOSEngine::isBoxDead(uint hitarea) { HitArea *ha = findBox(hitarea); if (ha == NULL) return false; return (ha->flags & kBFBoxDead) == 0; }
void AGOSEngine::enableBox(uint hitarea) { HitArea *ha = findBox(hitarea); if (ha != NULL) ha->flags &= ~kBFBoxDead; }
bool KNMusicTagM4a::writeTag(const KNMusicAnalysisItem &analysisItem) { //Get the detail info. const KNMusicDetailInfo &detailInfo=analysisItem.detailInfo; //Prepare and get the music file. QFile musicFile(detailInfo.filePath); //Open the file as read only mode. if(!musicFile.open(QIODevice::ReadOnly)) { //Failed to open the source. return false; } //Generate a temporary file, write the new data to the temporary file. QTemporaryFile updatedTagFile; //Open the temporary file, if we cannot open the temporary file it will be //failed to write the tag. if(!updatedTagFile.open()) { //Close the opened music file. musicFile.close(); return false; } //Generate a data stream for music file. QDataStream musicDataStream(&musicFile); //Read and copy the fytp box. If the first box isn't fytp box, then ignore //the file. M4ABox ftypBox; if(!getBox(musicDataStream, ftypBox) || ftypBox.name!="ftyp") { //Close both file. musicFile.close(); updatedTagFile.close(); //Failed to find a m4a file, return false. return false; } //Write ftyp data to the temporary file. writeBox(ftypBox, updatedTagFile); //We have to keep reading until we find out the moov box. //Output all the other data to updated tag file. M4ABox moovBox; for(;;) { //If we can get a new box. if(getBox(musicDataStream, moovBox)) { //Check out the name. if(moovBox.name=="moov") { break; } else { //Copy the data. writeBox(moovBox, updatedTagFile); } } else { //If we cannot find a box, means there's no "moov" box, failed to //write data. //Close both file. musicFile.close(); updatedTagFile.close(); //Failed to find a m4a file, return false. return false; } } //When we comes to here, we should find the "moov" box, expand the box to //find out the "udta" box. QList<M4ABox> moovExpandList; extractBox(moovBox, moovExpandList); //Generate a empty box for "udta" box. M4ABox udtaBox; //Check the expand list. if(moovExpandList.isEmpty() || !findBox("udta", udtaBox, moovExpandList)) { //If the name of the udta box is still empty, means there's no udta box //in the moov box, then we are faild to parse. //Close both file. musicFile.close(); updatedTagFile.close(); //Failed to find a m4a file, return false. return false; } //Expand the "udta" box, and find "meta" box. QList<M4ABox> udtaExpandList; extractBox(udtaBox, udtaExpandList); //Generate a empty box for "meta" box. M4ABox metaBox; //Check the expand list and find box. if(udtaExpandList.isEmpty() || !findBox("meta", metaBox, udtaExpandList)) { //If the name of the meta box is still empty, means we cannot find meta //box in the meta box, then we are finished to parse. //Close both file. musicFile.close(); updatedTagFile.close(); //Failed to find a m4a file, return false. return false; } //Okay, now we can parse the meta box. //Generate a box for ilst. M4ABox ilstBox; QList<M4ABox> metaExpandList; //Extract the meta box. extractMetaBox(metaBox, metaExpandList); //Find all box of the expand list. if(metaExpandList.isEmpty() || !findBox("ilst", ilstBox, metaExpandList)) { //We cannot find ilst box in the meta box. //Close both file. musicFile.close(); updatedTagFile.close(); //Failed to find a m4a file, return false. return false; } //Prepare the ilst expand list. QList<M4ABox> ilstExpandList; //Expand the ilst box. extractBox(ilstBox, ilstExpandList); //Now we have to write data to ilst expand list. for(int i=0; i<MusicDataCount; ++i) { //Get the atom name of current data. QString atomName=m_indexAtomMap.value(i, QString()); //Check if the atom name is empty, then go to the next. if(atomName.isEmpty()) { continue; } //Remove the exist data inside the ilst expand list. for(int j=ilstExpandList.size()-1; j>-1; --j) { //Check the name of the item. if(ilstExpandList.at(j).name==atomName) { //Remove it. ilstExpandList.removeAt(j); } } //Generate the raw data. QByteArray rawData; //Write the data to raw data. switch(i) { case TrackNumber: //Append three 0x00 first. rawData.append((char)0x00); rawData.append((char)0x00); rawData.append((char)0x00); //Append the track index. rawData.append((char)detailInfo.textLists[TrackNumber].toString() .toInt()); //Append splitter 0x00. rawData.append((char)0x00); //Append the track count. rawData.append((char)detailInfo.textLists[TrackCount].toString() .toInt()); //Append two 0x00 after. rawData.append((char)0x00); rawData.append((char)0x00); break; case DiscNumber: //Append three 0x00 first. rawData.append((char)0x00); rawData.append((char)0x00); rawData.append((char)0x00); //Append the disc index. rawData.append((char)detailInfo.textLists[DiscNumber].toString() .toInt()); //Append splitter 0x00. rawData.append((char)0x00); //Append the disc count. rawData.append((char)detailInfo.textLists[DiscCount].toString() .toInt()); //Append two 0x00 after. rawData.append((char)0x00); rawData.append((char)0x00); break; case Rating: //Append the rating to bytes. rawData.append((char)detailInfo.textLists[Rating].toString() .toInt()); break; default: //Translate the text data to UTF-8, without BOM. rawData=detailInfo.textLists[i].toString().toUtf8(); } //Generate the box. ilstExpandList.append(generateItemBox(i, atomName, rawData)); } //Remove all the album art atom. for(int j=ilstExpandList.size()-1; j>-1; --j) { //Check the name of the item. if(ilstExpandList.at(j).name=="covr") { //Remove it. ilstExpandList.removeAt(j); } } //Check album art. if(!analysisItem.coverImage.isNull()) { //Generate the raw data for the image. //Add the png raw data to image data. QByteArray imageData; QBuffer imageBuffer(&imageData); //Open the image buffer. imageBuffer.open(QIODevice::WriteOnly); //Save the data to image data. analysisItem.coverImage.save(&imageBuffer, "PNG"); //Close the image buffer. imageBuffer.close(); //Check the image data, if the data is not empty, then insert data. if(imageData.isEmpty()) { //Generate the flag data. char covrFlag[5]; covrFlag[0]=0x00; covrFlag[1]=0x00; covrFlag[2]=0x00; covrFlag[3]=14; //Generate item box, insert to list. ilstExpandList.append(generateItemBox(covrFlag, "covr", imageData)); } } //Combine the ilst data together. M4ABox updatedIlstBox=zipBox("ilst", ilstExpandList); //Clear the list and original ilst box. ilstExpandList.clear(); clearBox(ilstBox); //Replace the original ilst box. for(int i=metaExpandList.size()-1; i>-1; --i) { //Check the name. if(metaExpandList.at(i).name=="ilst") { //Replace the item. metaExpandList.replace(i, updatedIlstBox); //Stop searching. break; } } //Combine the meta expand list data. QByteArray metaRawData=combineBoxList(metaExpandList); //Clear up the meta expand list. metaExpandList.clear(); //Append the first four bytes raw data to the meta box raw data. metaRawData.prepend(metaBox.data, 4); //Clear up the no use meta box. clearBox(metaBox); clearBox(updatedIlstBox); //Set the data to new meta box. metaBox.name="meta"; metaBox.independence=true; metaBox.size=metaRawData.size(); metaBox.data=new char[metaBox.size]; memcpy(metaBox.data, metaRawData.data(), metaBox.size); //Replace the original meta box. for(int i=udtaExpandList.size()-1; i>-1; --i) { //Check the name. if(udtaExpandList.at(i).name=="meta") { //Replace the item. udtaExpandList.replace(i, metaBox); //Stop Searching. break; } } //Combine the udta data together. M4ABox updatedUdtaBox=zipBox("udta", udtaExpandList); //Clear the list and original udta box. udtaExpandList.clear(); clearBox(udtaBox); //Replace the original udta box. for(int i=moovExpandList.size()-1; i>-1; --i) { //Check the name. if(moovExpandList.at(i).name=="udta") { //Replace the item moovExpandList.replace(i, updatedUdtaBox); //Stop searching. break; } } //Combine the moov data together. M4ABox updatedMoovBox=zipBox("moov", moovExpandList); //Clear the list and original moov box. moovExpandList.clear(); clearBox(moovBox); //Write the new moov box to the updated tag file. writeBox(updatedMoovBox, updatedTagFile); //Clear up the updated moov box. clearBox(updatedMoovBox); //Copy the left data to the updated tag file. //Generate the music data cache. char *turboCache=new char[DataCacheSize]; //Copy the music data from the original music file, copy the //MusicDataCacheSize bytes once, until there's no bytes to copy. int bytesRead=musicFile.read(turboCache, DataCacheSize); while(bytesRead>0) { //Write the cache to temporary file. updatedTagFile.write(turboCache, bytesRead); //Read new data from the original file to cache. bytesRead=musicFile.read(turboCache, DataCacheSize); } //Close the music file. musicFile.close(); //Reset the temporary file. updatedTagFile.reset(); //Reopen the music file as write only mode, write all the udpated tag file //data to the music file. if(!musicFile.open(QIODevice::WriteOnly)) { //Close the updated tag file. updatedTagFile.close(); //Failed to write data. return false; } //Copy data from temporary file to music file. bytesRead=updatedTagFile.read(turboCache, DataCacheSize); while(bytesRead>0) { //Write the cache to music file. musicFile.write(turboCache, bytesRead); //Read new data from cache to the original file. bytesRead=updatedTagFile.read(turboCache, DataCacheSize); } //Close the music file and temporary file. musicFile.close(); updatedTagFile.close(); //Clear up the turbo memory. delete[] turboCache; //The tag rewrite is finished. return true; }