コード例 #1
0
int CHalfLife2::ReferenceToIndex(cell_t entRef)
{
	if ((unsigned)entRef == INVALID_EHANDLE_INDEX)
	{
		return INVALID_EHANDLE_INDEX;
	}

	if (entRef & (1<<31))
	{
		/* Proper ent reference */
		int hndlValue = entRef & ~(1<<31);
		CBaseHandle hndl(hndlValue);

		CEntInfo *pInfo = LookupEntity(hndl.GetEntryIndex());

		if (pInfo->m_SerialNumber != hndl.GetSerialNumber())
		{
			return INVALID_EHANDLE_INDEX;
		}

		return hndl.GetEntryIndex();
	}

	return entRef;
}
コード例 #2
0
cell_t CHalfLife2::ReferenceToBCompatRef(cell_t entRef)
{
	if ((unsigned)entRef == INVALID_EHANDLE_INDEX)
	{
		return INVALID_EHANDLE_INDEX;
	}

	int hndlValue = entRef & ~(1<<31);
	CBaseHandle hndl(hndlValue);

	if (hndl.GetEntryIndex() < MAX_EDICTS)
	{
		return hndl.GetEntryIndex();
	}

	return entRef;
}
コード例 #3
0
CBaseEntity *CHalfLife2::ReferenceToEntity(cell_t entRef)
{
	if ((unsigned)entRef == INVALID_EHANDLE_INDEX)
	{
		return NULL;
	}

	CEntInfo *pInfo = NULL;

	if (entRef & (1<<31))
	{
		/* Proper ent reference */
		int hndlValue = entRef & ~(1<<31);
		CBaseHandle hndl(hndlValue);

		pInfo = LookupEntity(hndl.GetEntryIndex());
		if (!pInfo || pInfo->m_SerialNumber != hndl.GetSerialNumber())
		{
			return NULL;
		}
	}
	else
	{
		/* Old style index only */
		pInfo = LookupEntity(entRef);
	}

	if (!pInfo)
	{
		return NULL;
	}

	IServerUnknown *pUnk = static_cast<IServerUnknown *>(pInfo->m_pEntity);
	if (pUnk)
	{
		return pUnk->GetBaseEntity();
	}

	return NULL;
}
コード例 #4
0
ファイル: wav.cpp プロジェクト: gnuzinho/Doomsday-Engine
void *WAV_Load(char const *filename, int *bits, int *rate, int *samples)
{
    try
    {
        // Relative paths are relative to the native working directory.
        de::String path = (de::NativePath::workPath() / de::NativePath(filename).expand()).withSeparators('/');
        QScopedPointer<de::FileHandle> hndl(&App_FileSystem().openFile(path, "rb"));

        // Read in the whole thing.
        size_t size = hndl->length();

        LOG_AS("WAV_Load");
        LOGDEV_RES_XVERBOSE("Loading from \"%s\" (size %i, fpos %i)")
                << de::NativePath(hndl->file().composePath()).pretty()
                << size
                << hndl->tell();

        uint8_t *data = (uint8_t *) M_Malloc(size);

        hndl->read(data, size);
        App_FileSystem().releaseFile(hndl->file());

        // Parse the RIFF data.
        void *sampledata = WAV_MemoryLoad((byte const *) data, size, bits, rate, samples);
        if(!sampledata)
        {
            LOG_RES_WARNING("Failed to load \"%s\"") << filename;
        }

        M_Free(data);
        return sampledata;
    }
    catch(de::FS1::NotFoundError const &)
    {} // Ignore.
    return 0;
}