Ejemplo n.º 1
0
BOOL Package::Load(const void *data, ResourceManager *res, IMemoryPool *pool)
{
	UNUSED(res);
	UNUSED(pool);

	this->pPool = pool;
	this->pRes = res;

	//BOOL result = FALSE;
	const u8 *ptr = static_cast<const u8 *>(data);

	stFile.SetData(data);
	ObjectHeader *block = NULL;
	READ_STRUCT(block, ObjectHeader, ptr);

	SECURITY_CHECK(seed_validate_block(&stFile, block, PACKAGE_OBJECT_MAGIC, PACKAGE_OBJECT_VERSION), "Invalid block header for font.");
	READ_U32(iFilesAmount, ptr);

	if (!iFilesAmount)
	{
		Log(TAG "Package %s is empty.", stFile.GetName());
		pFileSystem->Close(&stFile);
		bLoaded = FALSE;
	}
	else
	{
		bLoaded = TRUE;
	}

	return bLoaded;
}
Ejemplo n.º 2
0
Archivo: Font.cpp Proyecto: doorxp/seed
BOOL Font::Load(const char *filename, ResourceManager *res, IMemoryPool *pool)
{
	ASSERT_NULL(filename);
	ASSERT_NULL(res);
	ASSERT_NULL(pool);

	if (this->Unload())
	{
		this->pFilename = filename;
		this->pRes = res;
		this->pPool = pool;

		stFile.Close();
		SECURITY_CHECK(pFileSystem->Open(filename, &stFile, pool), "Could not open font file.");
		const u8 *ptr = static_cast<const u8 *>(stFile.GetData());
		ObjectHeader *block = NULL;
		READ_STRUCT(block, ObjectHeader, ptr);
		SECURITY_CHECK(seed_validate_block(&stFile, block, FONT_OBJECT_MAGIC, FONT_OBJECT_VERSION), "Invalid block header for font.");

		READ_F32(this->fTracking, ptr);
		READ_F32(this->fSpacing, ptr);
		READ_F32(this->fSpaceWidth, ptr);

	/*
		const char *file = NULL;
		READ_STR(file, ptr);
		ASSERT_NULL(file);

		const char *ext = NULL;
		READ_STR(ext, ptr);
	*/
		u32 file = 0;
		READ_U32(file, ptr);

		u32 ext = 0;
		READ_U32(ext, ptr);

		if (ext != SEED_INVALID_ID /*&& pSystem->GetLanguage() != Seed::en_US*/)
		{
			File extf;
			if (pFileSystem->Open(_F(ext), &extf, pool))
			{
				extf.Close();
				this->mFontExt.Load(_F(ext), res, pool);
				this->pGlyphs = pDictionary->GetGlyphTable(&this->iTotalGlyphs);
			}
		}

		this->mFont.Load(_F(file), res, pool);
		this->fHeight	= mFont.GetHeight();
		this->fWidth	= mFont.GetWidth();

		this->bLoaded	= TRUE;
	}

	return bLoaded;
}
Ejemplo n.º 3
0
void SoundSource::Load(const char *filename, ResourceManager *res, IMemoryPool *pool)
{
	ASSERT_NULL(filename);
	ASSERT_NULL(pool);
	ASSERT_NULL(res);

	if (pSoundSystem->IsInitialized())
	{
		this->Unload();

		/* Open file .sound */
		SECURITY_CHECK(pFileSystem->Open(filename, &stFile, pool), "Sound object couldn't be opened");

		const u8 *ptr = static_cast<const u8 *>(stFile.GetData());
		ObjectHeader *block = NULL;
		READ_STRUCT(block, ObjectHeader, ptr);
		SECURITY_CHECK(seed_validate_block(&stFile, block, SOUND_OBJECT_MAGIC, SOUND_OBJECT_VERSION), "Invalid block header for sound.");

		u32 volume = 0;
		READ_U32(volume, ptr);
		this->fVolume  = volume / 100.0f;

		u32 flags = 0;
		READ_U32(flags, ptr);
		this->bLoop = ((flags & 0x01) == 0x01); // FIXME

		const char *fname = NULL;
		READ_STR(fname, ptr);
		ASSERT_NULL(fname);

		/* Get the resource */
		pSound = static_cast<Sound *>(res->Get(fname, Seed::ObjectSound, pool));

		if (iSource)
			alDeleteSources(1, &iSource);
		ALenum err = alGetError();

		alGenSources(1, &iSource);
		err = alGetError();
		if (err != AL_NO_ERROR)
			Info(TAG "Could not create OpenAL Source: %4x", err);

		const ALint *buffer = static_cast<const ALint *>(pSound->GetData());

		alSourcef(iSource, AL_PITCH, 1.0f);
		alSource3f(iSource, AL_POSITION, cPosition.x, cPosition.y, cPosition.z);
		alSource3f(iSource, AL_VELOCITY, cVelocity.x, cVelocity.y, cVelocity.z);
		alSourcei(iSource, AL_LOOPING, this->bLoop);
		alSourcei(iSource, AL_BUFFER, *buffer);
		this->SetVolume(this->fVolume);
	}
}
Ejemplo n.º 4
0
INLINE void Dictionary::SetLanguage(Seed::eLanguage lang, IMemoryPool *pool)
{
	// REQUIREMENT:
	/*
	The first file from filelist MUST BE strings.dict.
	This is because strings.dict is unique for each language, and we must know it's ID because
	currently we can only open "localized" files BY ID.

	A possible fix for this is that Dictionary can have an array of possible filenames to try and then open.
	*/
	this->Reset();
	this->pPool = pool;

	const char *file = _F(0);
	if (!file || !pFileSystem->Open(file, &stFile, pool))
	{
		Info(TAG, "strings.dict not found, skipping dictionary.");
		return;
	}

	const u8 *ptr = static_cast<const u8 *>(stFile.GetData());
	ObjectHeader *block = NULL;
	READ_STRUCT(block, ObjectHeader, ptr);
	SECURITY_CHECK(seed_validate_block(&stFile, block, DICT_OBJECT_MAGIC, DICT_OBJECT_VERSION), "Invalid block header for dictionary.");

	u32 code = 0;
	READ_U32(code, ptr);
	ASSERT_MSG(static_cast<u32>(lang) == code, "Dictionary has an invalid language code.");
	this->iLang = lang;

	READ_U32(this->iTotalGlyphs, ptr);
	READ_U32(this->iTotalStrings, ptr);

	if (this->iTotalGlyphs)
		this->pGlyphs = reinterpret_cast<const u16 *>(ptr);

	if (this->iTotalStrings)
		this->pStrings = reinterpret_cast<const u16 *>(ptr + iTotalGlyphs + iTotalGlyphs);

	// we can alloc a table for strings using a structure {u32, u16 *}
	// and map them on load too but I will not do it. Or, I can do
	// this table inside the file and update the pointers (take care
	// of 32bit-64bit portability) on load.
}
Ejemplo n.º 5
0
void IFileSystem::BuildFileTable()
{
	if (!pFile)
	{
		pFile = New(File(FILESYSTEM_TABLE_FILE));
		//ASSERT_NULL(pFile->pData);
		if (pFile->pData)
		{
			const u8 *ptr = static_cast<const u8 *>(pFile->pData);
			ObjectHeader *block = NULL;
			READ_STRUCT(block, ObjectHeader, ptr);

			SECURITY_CHECK(seed_validate_block(pFile, block, FST_OBJECT_MAGIC, FST_OBJECT_VERSION), "Invalid block header for filelist.");
			READ_U32(iLangCount, ptr);
			READ_U32(iFileCount, ptr);

			pFileTable = (StringFile *)pMemoryManager->Alloc(iLangCount * iFileCount * sizeof(const char *));
			for (u32 l = 0; l < iLangCount; l++)
			{
				u32 lang = 0;
				READ_U32(lang, ptr);
				pLangTable[lang] = &pFileTable[l * iFileCount];

				for (u32 s = 0; s < iFileCount; s++)
				{
					char *str = NULL;
					READ_STR(str, ptr);
					pFileTable[(l*iFileCount)+s] = str;
				}
			}

			pOldTable = pCurrentTable = pLangTable[pSystem->GetLanguage()];
			pSystem->AddListener(this);
		}
		else
		{
			Info(TAG "Could not find %s, not using localization file table and file by id feature.", FILESYSTEM_TABLE_FILE);
		}
	}
}
Ejemplo n.º 6
0
BOOL Button::Load(const char *filename, ResourceManager *res, IMemoryPool *pool)
{
	ASSERT_NULL(filename);
	ASSERT_NULL(res);
	ASSERT_NULL(pool);

	if (this->Unload())
	{
		pRes = res;
		pPool = pool;
		pFilename = filename;

		/* Isso deveria ser um objeto como SpriteObject -> ButtonObject, para que o .button seja reaproveitado. */
		SECURITY_CHECK(pFileSystem->Open(filename, &stFile, pool), "Could not open button file.");

		const u8 *ptr = static_cast<const u8 *>(stFile.GetData());
		ObjectHeader *block = NULL;
		READ_STRUCT(block, ObjectHeader, ptr);
		SECURITY_CHECK(seed_validate_block(&stFile, block, BUTTON_OBJECT_MAGIC, BUTTON_OBJECT_VERSION), "Invalid block header for button.");

		/*
		We check if any property is already set so we WON'T change it. This will allow the user to do Set* things befora doing the Load.
		If the user want that the object properties are loaded it will need call Reset before Load.
		*/
		if (!iId)
			READ_U32(iId, ptr);

		if (!iPriority)
			READ_U32(iPriority, ptr);

		f32 x = 0;
		f32 y = 0;

		READ_F32(x, ptr);
		READ_F32(y, ptr);

		if (!this->GetX())
			this->SetX(x);

		if (!this->GetY())
			this->SetY(y);

		u32 masktype = 0;
		READ_U32(masktype, ptr);

		u32 labelid = 0;
		READ_U32(labelid, ptr);

		//const char *sprite = NULL;
		//READ_STR(sprite, ptr);
		u32 sprFileId = 0;
		READ_U32(sprFileId, ptr);
		if (sprFileId != SEED_INVALID_ID)
			this->SetSprite(_F(sprFileId), res, pool);

		u32 mask = 0;
		if (masktype == 1)
		{
			READ_U32(mask, ptr);
			if (mask != SEED_INVALID_ID && eButtonCollision == CollisionNone)
				this->SetMask(_F(mask), res, pool);
		}

		bLoaded = TRUE;
	}

	return bLoaded;
}