Пример #1
0
/**
 * Insert the record whose contents is pointed at by recPtr into relation relNum.
 *
 * @param   relNum - Relation number
 * @param   recPtr - A pointer to a record-sized byte array whose contents
 *                   will be copied to an empty record slot in the relation.
 * @return  OK or NOTOK
 *
 * @author nithin
 *
 * GLOBAL VARIABLES MODIFIED:
 *      g_Buffer[relNum]
 *      g_CatCache[relNum]
 *
 * ERRORS REPORTED:
 *      NULL_ARGUMENT_RECEIVED
 *      DUPLICATE_TUPLE
 *
 * ALGORITHM:
 *      1. Check if the record pointed by recPtr already exists in the relation
 *          (only if the check duplicates flag is set)
 *      2. Find the first free slot in the relation by linear search
 *      3. Copy the contents into that slot
 *          (using a loop and not strcpy)
 *      4. Update the dirty bit and slotmap in Buffer
 *      5. Update the dirty bit, numRecs and numPgs in CatCache
 *
 * IMPLEMENTATION NOTES:
 *      Uses ReadPage()
 *
 *
 */
int InsertRec(const int relNum, char*recPtr) {
    if (recPtr == NULL) {
        return ErrorMsgs(NULL_ARGUMENT_RECEIVED, g_PrintFlag);
    }

    /* Checking for duplicates */
    Rid *fRid, sRid = { 0, 0 };
    char *record;
    while (GetNextRec(relNum, &sRid, &fRid, &record) == OK && g_CheckDuplicateTuples == OK) {
        if (compareRecords(record, recPtr, g_CatCache[relNum].recLength) == OK) {
            return ErrorMsgs(DUPLICATE_TUPLE, g_PrintFlag);
        }
        sRid = *fRid;
        free(fRid);
    }

    Rid startRid = { 1, 0 }, foundRid;
    /* Insert record    */
    getNextFreeSlot(relNum, startRid, &foundRid);
    ReadPage(relNum, foundRid.pid);
    unsigned int recLength = g_CatCache[relNum].recLength;
    int i, j;
    int offset = (foundRid.slotnum - 1) * recLength;
    for (i = offset, j = 0; j < recLength; ++i, j++) {
        g_Buffer[relNum].page.contents[i] = recPtr[j];
    }

    /*  Update dirty bits and slotmap*/
    g_Buffer[relNum].dirty = TRUE;
    g_Buffer[relNum].page.slotmap = (g_Buffer[relNum].page.slotmap | 1 << (32 - foundRid.slotnum));

    /*  Update numRecs in catCache*/
    g_CatCache[relNum].dirty = TRUE;
    g_CatCache[relNum].numRecs++;
    g_CatCache[relNum].numPgs =
            g_CatCache[relNum].numPgs > foundRid.pid ? g_CatCache[relNum].numPgs : foundRid.pid;

    return OK;
}
Пример #2
0
int VideoPlayer::openVideo(bool primary, const Common::String &file, Properties &properties) {
	int slot = 0;

	Video *video = 0;
	if (!primary) {
		slot = getNextFreeSlot();
		if (slot < 0) {
			warning("VideoPlayer::openVideo(): Can't open video \"%s\": No free slot", file.c_str());
			return -1;
		}

		video = &_videoSlots[slot];
	} else
		video = &_videoSlots[0];

	// Different video already in the slot => close that video
	if (!video->isEmpty() && (video->fileName.compareToIgnoreCase(file) != 0))
		video->close();

	// No video => load the requested file
	if (video->isEmpty()) {
		// Open the video
		if (!(video->decoder = openVideo(file, properties)))
			return -1;

		if (video->decoder->hasVideo() && !(properties.flags & kFlagNoVideo) &&
		    (video->decoder->isPaletted() != !_vm->isTrueColor())) {
			if (!properties.switchColorMode)
				return -1;

			_vm->setTrueColor(!video->decoder->isPaletted());

			video->decoder->colorModeChanged();
		}

		// Set the filename
		video->fileName = file;

		// WORKAROUND: In some rare cases, the cursor should still be
		// displayed while a video is playing.
		_noCursorSwitch = false;
		if (primary && (_vm->getGameType() == kGameTypeLostInTime)) {
			if (!file.compareToIgnoreCase("PORTA03") ||
			    !file.compareToIgnoreCase("PORTA03A") ||
			    !file.compareToIgnoreCase("CALE1") ||
			    !file.compareToIgnoreCase("AMIL2") ||
			    !file.compareToIgnoreCase("AMIL3B") ||
			    !file.compareToIgnoreCase("DELB"))
				_noCursorSwitch = true;
		}

		// WORKAROUND: In Woodruff, Coh Cott vanished in one video on her party.
		// This is a bug in video, so we work around it.
		_woodruffCohCottWorkaround = false;
		if (primary && (_vm->getGameType() == kGameTypeWoodruff)) {
			if (!file.compareToIgnoreCase("SQ32-03"))
				_woodruffCohCottWorkaround = true;
		}

		if (!(properties.flags & kFlagNoVideo) && (properties.sprite >= 0)) {
			bool ownSurf    = (properties.sprite != Draw::kFrontSurface) && (properties.sprite != Draw::kBackSurface);
			bool screenSize = properties.flags & kFlagScreenSurface;

			if (ownSurf) {
				_vm->_draw->_spritesArray[properties.sprite] =
					_vm->_video->initSurfDesc(screenSize ? _vm->_width  : video->decoder->getWidth(),
					                          screenSize ? _vm->_height : video->decoder->getHeight(), 0);
			}

			if (!_vm->_draw->_spritesArray[properties.sprite] &&
			    (properties.sprite != Draw::kFrontSurface) &&
			    (properties.sprite != Draw::kBackSurface)) {
				properties.sprite = -1;
				video->surface.reset();
				video->decoder->setSurfaceMemory();
				properties.x = properties.y = 0;
			} else {
				video->surface = _vm->_draw->_spritesArray[properties.sprite];
				if (properties.sprite == Draw::kFrontSurface)
					video->surface = _vm->_draw->_frontSurface;
				if (properties.sprite == Draw::kBackSurface)
					video->surface = _vm->_draw->_backSurface;

				video->decoder->setSurfaceMemory(video->surface->getData(),
						video->surface->getWidth(), video->surface->getHeight(), video->surface->getBPP());

				if (!ownSurf || (ownSurf && screenSize)) {
					if ((properties.x >= 0) || (properties.y >= 0)) {
						properties.x = (properties.x < 0) ? 0xFFFF : properties.x;
						properties.y = (properties.y < 0) ? 0xFFFF : properties.y;
					} else
						properties.x = properties.y = -1;
				} else
					properties.x = properties.y = 0;
			}

		} else {
			properties.sprite = -1;
			video->surface.reset();
			video->decoder->setSurfaceMemory();
			properties.x = properties.y = 0;
		}
	}

	video->decoder->setXY(properties.x, properties.y);

	if (primary)
		_needBlit = (properties.flags & kFlagUseBackSurfaceContent) && (properties.sprite == Draw::kFrontSurface);

	properties.hasSound = video->decoder->hasSound();

	if (!video->decoder->hasSound())
		video->decoder->setFrameRate(_vm->_util->getFrameRate());

	WRITE_VAR(7, video->decoder->getFrameCount());

	return slot;
}