Esempio n. 1
0
bool ResourceManager::hasResource(const Common::UString &name, FileType type) const {
	std::vector<FileType> types;

	types.push_back(type);

	return hasResource(name, types);
}
Esempio n. 2
0
void ComposerEngine::playWaveForAnim(uint16 id, uint16 priority, bool bufferingOnly) {
	if (_audioStream && _audioStream->numQueuedStreams() != 0) {
		if (_currSoundPriority < priority)
			return;
		if (_currSoundPriority > priority) {
			_mixer->stopAll();
			_audioStream = NULL;
		}
	}
	Common::SeekableReadStream *stream = NULL;
	if (!bufferingOnly && hasResource(ID_WAVE, id)) {
		stream = getResource(ID_WAVE, id);
	} else {
		for (Common::List<Pipe *>::iterator k = _pipes.begin(); k != _pipes.end(); k++) {
			Pipe *pipe = *k;
			if (!pipe->hasResource(ID_WAVE, id))
				continue;
			stream = pipe->getResource(ID_WAVE, id, true);
			break;
		}
	}
	if (!stream)
		return;
	// FIXME: non-pipe buffers have fixed wav header (data at +44, size at +40)
	byte *buffer = (byte *)malloc(stream->size());
	stream->read(buffer, stream->size());
	if (!_audioStream)
		_audioStream = Audio::makeQueuingAudioStream(22050, false);
	_audioStream->queueBuffer(buffer, stream->size(), DisposeAfterUse::YES, Audio::FLAG_UNSIGNED);
	_currSoundPriority = priority;
	delete stream;
	if (!_mixer->isSoundHandleActive(_soundHandle))
		_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, _audioStream);
}
Esempio n. 3
0
Resource *ResourceManager::upcast(Resource *res_in) 
{
	Resource *res_out;

	if (!res_in)
	{
		return NULL;
	}
	
	if (outcastBin.find(res_in) != outcastBin.end()) return outcastBin[res_in];
	
	if (upcastBin.find(res_in) != upcastBin.end())
	{
		return res_in;
	}
	
	
	if (!hasResource(res_in->getType(),res_in->getId()))
	{
		return NULL;
	}			
	
	if (upcastFunc.find(res_in->getType()) == upcastFunc.end())
	{
		if (upcastFunc.find(res_in->getSubType()) == upcastFunc.end())
		{
			return NULL;			
		}
	}
	
	(*mResources)[res_in->getType()].erase(res_in->getId());
	(*mSubResources)[res_in->getSubType()].erase(res_in->getId());
	
	ResourceCast castFunc;
	
	if (upcastFunc.find(res_in->getSubType()) != upcastFunc.end())
	{
		castFunc = upcastFunc[res_in->getSubType()];
	}
	else
	{
		castFunc = upcastFunc[res_in->getType()];
	}
	
	res_out = castFunc(this,res_in);
	
	if (!res_out) return NULL;
	
	res_in->UnLink();
	
	outcastBin[res_in] = res_out;

	addResource(*res_out);
	
	upcastBin.insert(res_out);
	
	return res_out;
}
Esempio n. 4
0
Common::SeekableReadStream *ComposerEngine::getStreamForSprite(uint16 id) {
	for (Common::List<Pipe *>::iterator k = _pipes.begin(); k != _pipes.end(); k++) {
		Pipe *pipe = *k;
		if (!pipe->hasResource(ID_BMAP, id))
			continue;
		return pipe->getResource(ID_BMAP, id, true);
	}
	if (hasResource(ID_BMAP, id))
		return getResource(ID_BMAP, id);
	return NULL;
}
Esempio n. 5
0
	/**
	 * Returns an image resource.
	 *
	 * @param fileName The filename of the image.
	 *
	 * @return The image.
	 *
	 * @throw ResourceNotLoadedExcpetion
	*/
	ImageResource* ResourceManager::image(std::string fileName) {
		std::string id = ImageResource::createID(fileName);
		if (!hasResource(id)) {
			ImageResource* res = ImageResource::open(fileName);
			insertResource(res->getName(), res);
			
			return res;
		} else {
			return static_cast<ImageResource*>(getResource(id));
		}
	}
Esempio n. 6
0
	/**
	 * Opens a music file.
	 *
	 * @param name The name of the music file.
	 *
	 * @return The music file.
	*/
	MusicResource* ResourceManager::music(std::string name) {
		std::string id = "music_" + name;
		if (!hasResource(id)) {
			MusicResource* music = MusicResource::open(name);
			insertResource(id, music);
			
			return music;
		} else {
			return static_cast<MusicResource*>(getResource(id));
		}
	}
Esempio n. 7
0
	/**
	 * Opens a small audio file.
	 *
	 * @param name The name of the audio file.
	 *
	 * @return The Audio file.
	*/
	SoundResource* ResourceManager::sound(std::string name) {
		std::string id = "audio_" + name;
		if (!hasResource(id)) {
			SoundResource* sound = SoundResource::open(name);
			insertResource(id, sound);
			
			return sound;
		} else {
			return static_cast<SoundResource*>(getResource(id));
		}
	}
Esempio n. 8
0
	/**
	 * Opens a font.
	 *
	 * @param name The name of the font.
	 * @param ptSize The size of the font in points.
	 *
	 * @return The Font.
	 *
	 * @throw ResourceNotLoadedExcpetion
	*/
	FontResource* ResourceManager::font(std::string name, int ptSize) {
		std::string fontID = FontResource::getID(name, ptSize);
		if (!hasResource(fontID)) {
			FontResource* font = FontResource::open(name, ptSize);
			insertResource(fontID, font);
			
			return font;
		} else {
			return static_cast<FontResource*>(getResource(fontID));
		}
	}
Esempio n. 9
0
bool ResourceManager::hasCast(string typeId, string idName)
{
	if (!hasResource(typeId,idName)) return false;
	
	if (upcastBin.find((*mResources)[typeId][idName]) == upcastBin.end())
	{
		return false;
	}
	
	return true;
}
Esempio n. 10
0
void ComposerEngine::loadAnimation(Animation *&anim, uint16 animId, int16 x, int16 y, int16 eventParam, int32 size) {
	Common::SeekableReadStream *stream = NULL;
	Pipe *newPipe = NULL;

	// First, check the existing pipes.
	for (Common::List<Pipe *>::iterator j = _pipes.begin(); j != _pipes.end(); j++) {
		Pipe *pipe = *j;
		if (!pipe->hasResource(ID_ANIM, animId))
			continue;

		stream = pipe->getResource(ID_ANIM, animId, false);

		// When loading from savegame, make sure we have the correct stream
		if ((!size) || (stream->size() >= size))
			break;
		stream = NULL;
	}

	// If we didn't find it, try the libraries.
	if (!stream) {
		if (!hasResource(ID_ANIM, animId)) {
			warning("ignoring attempt to play invalid anim %d", animId);
			return;
		}
		Common::List<Library>::iterator j;
		for (j = _libraries.begin(); j != _libraries.end(); j++) {
			if (!j->_archive->hasResource(ID_ANIM, animId))
				continue;

			stream = j->_archive->getResource(ID_ANIM, animId);

			// When loading from savegame, make sure we have the correct stream
			if ((!size) || (stream->size() >= size))
				break;
			stream = NULL;
		}

		uint32 type = j->_archive->getResourceFlags(ID_ANIM, animId);

		// If the resource is a pipe itself, then load the pipe
		// and then fish the requested animation out of it.
		if (type != 1) {
			_pipeStreams.push_back(stream);
			newPipe = new Pipe(stream, animId);
			_pipes.push_front(newPipe);
			newPipe->nextFrame();
			stream = newPipe->getResource(ID_ANIM, animId, false);
		}
	}

	anim = new Animation(stream, animId, Common::Point(x, y), eventParam);
	if (newPipe)
		newPipe->_anim = anim;
}
Esempio n. 11
0
void ComposerEngine::playAnimation(uint16 animId, int16 x, int16 y, int16 eventParam) {
	// First, we check if this animation is already playing,
	// and if it is, we sabotage that running one first.
	for (Common::List<Animation *>::iterator i = _anims.begin(); i != _anims.end(); i++) {
		Animation *anim = *i;
		if (anim->_id != animId)
			continue;

		stopAnimation(*i);
	}

	Common::SeekableReadStream *stream = NULL;
	Pipe *newPipe = NULL;

	// First, check the existing pipes.
	for (Common::List<Pipe *>::iterator j = _pipes.begin(); j != _pipes.end(); j++) {
		Pipe *pipe = *j;
		if (!pipe->hasResource(ID_ANIM, animId))
			continue;
		stream = pipe->getResource(ID_ANIM, animId, false);
		break;
	}

	// If we didn't find it, try the libraries.
	if (!stream) {
		if (!hasResource(ID_ANIM, animId)) {
			warning("ignoring attempt to play invalid anim %d", animId);
			return;
		}
		stream = getResource(ID_ANIM, animId);

		uint32 type = 0;
		for (Common::List<Library>::iterator i = _libraries.begin(); i != _libraries.end(); i++)
			if (i->_archive->hasResource(ID_ANIM, animId)) {
				type = i->_archive->getResourceFlags(ID_ANIM, animId);
				break;
			}

		// If the resource is a pipe itself, then load the pipe
		// and then fish the requested animation out of it.
		if (type != 1) {
			newPipe = new Pipe(stream);
			_pipes.push_front(newPipe);
			stream = newPipe->getResource(ID_ANIM, animId, false);
		}
	}

	Animation *anim = new Animation(stream, animId, Common::Point(x, y), eventParam);
	_anims.push_back(anim);
	runEvent(kEventAnimStarted, animId, eventParam, 0);
	if (newPipe)
		newPipe->_anim = anim;
}
Esempio n. 12
0
	/**
	 * Returns an image resource. The image will be scaled and rotated.
	 *
	 * @param fileName The filename of the image.
	 * @param width The width of the image.
	 * @param height The height of the image.
	 * @param keepRatio True if to keep the aspect ratio of the original image.
	 *        It is possible that the width or height of the image will be less than the given values.
	 * @param angle The angle of the rotation (in degrees).
	 *
	 * @return The image.
	 *
	 * @throw ResourceNotLoadedExcpetion
	*/
	ImageResource* ResourceManager::image(std::string fileName, int width,
	                                      int height, bool keepRatio, int angle) {
		std::string id = ImageResource::createID(fileName, width, height, keepRatio, angle);
		if (!hasResource(id)) {
			ImageResource* res = image(fileName);
			ImageResource* scaled = res->scaleAndRotate(width, height, keepRatio, angle);
			free(res);
			insertResource(scaled->getName(), scaled);
			
			return scaled;
		} else {
			return static_cast<ImageResource*>(getResource(id));
		}
	}
Esempio n. 13
0
void ComposerEngine::playPipe(uint16 id) {
	stopPipes();

	if (!hasResource(ID_PIPE, id)) {
		error("couldn't find pipe %d", id);
	}

	Common::SeekableReadStream *stream = getResource(ID_PIPE, id);
	OldPipe *pipe = new OldPipe(stream, id);
	_pipes.push_front(pipe);
	//pipe->nextFrame();

	const Common::Array<uint16> *scripts = pipe->getScripts();
	if (scripts && !scripts->empty())
		runScript((*scripts)[0], 1, 0, 0);
}
Esempio n. 14
0
void ResourceManager::setResource(const std::string &resource, int priority, int caps, int show, const std::string &status) {
	if (resource.empty())
		return;
	if (!hasResource(resource)) {
		m_resources[resource].caps = 0;
		m_resources[resource].priority = 0;
		m_resources[resource].show = -1;
	}
	if (priority != -256)
		m_resources[resource].priority = priority;
	if (caps != -1)
		m_resources[resource].caps = caps;
	m_resources[resource].status = status;
	m_resources[resource].name = resource;

	setActiveResource();
}
Esempio n. 15
0
 //------------------------------------------------------------------------------
 void ResourceVisitor::addResource( Resource& resource )
 {
     osg::ref_ptr<Resource> tmpResource = &resource;
     if( !hasResource(resource) )
         _collectedResources.insert( &resource );
 }
Esempio n. 16
0
void ComposerEngine::loadLibrary(uint id) {
	if (getGameType() == GType_ComposerV1 && !_libraries.empty()) {
		// kill the previous page, starting with any scripts running on it

		for (Common::List<OldScript *>::iterator i = _oldScripts.begin(); i != _oldScripts.end(); i++)
			delete *i;
		_oldScripts.clear();

		Library *library = &_libraries.front();
		unloadLibrary(library->_id);
	}

	Common::String filename;

	if (getGameType() == GType_ComposerV1) {
		if (!id || _bookGroup.empty())
			filename = getStringFromConfig("Common", "StartPage");
		else
			filename = getStringFromConfig(_bookGroup, Common::String::format("%d", id));
		filename = mangleFilename(filename);

		// bookGroup is the basename of the path.
		// TODO: tidy this up.
		_bookGroup.clear();
		for (uint i = 0; i < filename.size(); i++) {
			if (filename[i] == '~' || filename[i] == '/' || filename[i] == ':')
				continue;
			for (uint j = 0; j < filename.size(); j++) {
				if (filename[j] == '/') {
					_bookGroup.clear();
					continue;
				}
				if (filename[j] == '.')
					break;
				_bookGroup += filename[j];
			}
			break;
		}
	} else {
		if (!id)
			id = atoi(getStringFromConfig("Common", "StartUp").c_str());
		filename = getFilename("Libs", id);
	}

	Library library;

	library._id = id;
	library._archive = new ComposerArchive();
	if (!library._archive->openFile(filename))
		error("failed to open '%s'", filename.c_str());
	_libraries.push_front(library);

	Library &newLib = _libraries.front();

	Common::Array<uint16> buttonResources = library._archive->getResourceIDList(ID_BUTN);
	for (uint i = 0; i < buttonResources.size(); i++) {
		uint16 buttonId = buttonResources[i];
		Common::SeekableReadStream *stream = library._archive->getResource(ID_BUTN, buttonId);
		Button button(stream, buttonId, getGameType());

		bool inserted = false;
		for (Common::List<Button>::iterator b = newLib._buttons.begin(); b != newLib._buttons.end(); b++) {
			if (button._zorder < b->_zorder)
				continue;
			newLib._buttons.insert(b, button);
			inserted = true;
			break;
		}
		if (!inserted)
			newLib._buttons.push_back(button);
	}

	Common::Array<uint16> ambientResources = library._archive->getResourceIDList(ID_AMBI);
	for (uint i = 0; i < ambientResources.size(); i++) {
		Common::SeekableReadStream *stream = library._archive->getResource(ID_AMBI, ambientResources[i]);
		Button button(stream);
		newLib._buttons.insert(newLib._buttons.begin(), button);
	}

	Common::Array<uint16> accelResources = library._archive->getResourceIDList(ID_ACEL);
	for (uint i = 0; i < accelResources.size(); i++) {
		Common::SeekableReadStream *stream = library._archive->getResource(ID_ACEL, accelResources[i]);
		KeyboardHandler handler;
		handler.keyId = stream->readUint16LE();
		handler.modifierId = stream->readUint16LE();
		handler.scriptId = stream->readUint16LE();
		newLib._keyboardHandlers.push_back(handler);
	}

	Common::Array<uint16> randResources = library._archive->getResourceIDList(ID_RAND);
	for (uint i = 0; i < randResources.size(); i++) {
		Common::SeekableReadStream *stream = library._archive->getResource(ID_RAND, randResources[i]);
		Common::Array<RandomEvent> &events = _randomEvents[randResources[i]];
		uint16 count = stream->readUint16LE();
		for (uint j = 0; j < count; j++) {
			RandomEvent random;
			random.scriptId = stream->readUint16LE();
			random.weight = stream->readUint16LE();
			events.push_back(random);
		}
		delete stream;
	}

	// add background sprite, if it exists
	if (hasResource(ID_BMAP, 1000))
		setBackground(1000);

	// TODO: better CTBL logic
	loadCTBL(1000, 100);

	// Run the startup script.
	runScript(1000, 0, 0, 0);

	_mouseEnabled = true;
	onMouseMove(_lastMousePos);

	runEvent(kEventLoad, id, 0, 0);
}
int KoDocumentResourceManager::grabSensitivity() const
{
    if (hasResource(GrabSensitivity))
        return intResource(GrabSensitivity);
    return 3; // default value
}
int KoDocumentResourceManager::handleRadius() const
{
    if (hasResource(HandleRadius))
        return intResource(HandleRadius);
    return 3; // default value.
}
Esempio n. 19
0
TRIGGER( targetobj )(obj user, obj usedon)
{
  cleanup();
  if(Q4BL(user, "The blacksmith skill", 0x00))
  {
    return(0x00);
  }
  if(!Q4ZM(user))
  {
    return(0x00);
  }
  if(isWeapon(usedon) && hasResource(usedon, resourceTypeToId("metal")))
  {
    if(isInContainer(usedon))
    {
      obj container = getTopmostContainer(usedon);
      if(isMobile(container))
      {
        if(container != user)
        {
          systemMessage(user, "You can't work on that item.");
          return(0x00);
        }
      }
    }
    int Q4G6 = getWeaponCurHP(usedon);
    int Q56H = getWeaponMaxHP(usedon);
    if((Q56H == 0x00) || (Q4G6 >= Q56H))
    {
      systemMessage(user, "That is already in full repair.");
      return(0x00);
    }
    int Q5MK = (Q56H - Q4G6) * 0x04E2 / Q56H - 0xFA;
    int Q4Q1;
    int success = testAndLearnSkill(user, 0x07, Q5MK, 0x32);
    Q56H --;
    Q4G6 --;
    if(Q4G6 < 0x01)
    {
      systemMessage(user, "You destroyed the item.");
      deleteObject(usedon);
    }
    else
    {
      if(success > 0x00)
      {
        Q4G6 = Q56H;
        systemMessage(user, "You repair the item.");
      }
      Q4Q1 = setWeaponMaxHP(usedon, Q56H);
      Q4Q1 = setWeaponCurHP(usedon, Q4G6);
    }
    if(Q46J(user, this))
    {
      deleteObject(this);
    }
    return(0x00);
  }
  systemMessage(user, "You can't repair that.");
  return(0x00);
}
KoImageCollection *KoDocumentResourceManager::imageCollection() const
{
    if (!hasResource(ImageCollection))
        return 0;
    return static_cast<KoImageCollection*>(resource(ImageCollection).value<void*>());
}
KoOdfDocument *KoDocumentResourceManager::odfDocument() const
{
    if (!hasResource(OdfDocument))
        return 0;
    return static_cast<KoOdfDocument*>(resource(OdfDocument).value<void*>());
}
KUndo2Stack *KoDocumentResourceManager::undoStack() const
{
    if (!hasResource(UndoStack))
        return 0;
    return static_cast<KUndo2Stack*>(resource(UndoStack).value<void*>());
}
Esempio n. 23
0
bool ResourceManager::hasFeature(int feature, const std::string &resource) {
	std::string res = resource.empty() ? m_resource : resource;
	if (hasResource(res))
		return getResource(res).caps & feature;
	return false;
}
Esempio n. 24
0
Resource & ResourceManager::getResource(const std::string &r) {
	std::string resource = r.empty() ? m_resource : r;
	if (resource.empty() || !hasResource(resource))
		return DummyResource;
	return m_resources[resource];
}
Esempio n. 25
0
bool ResourceManager::hasResource(const Common::UString &name) const {
	return hasResource(TypeMan.setFileType(name, kFileTypeNone), TypeMan.getFileType(name));
}