Exemplo n.º 1
0
ICCItem *CMission::GetProperty (const CString &sName)

//	GetProperty
//
//	Returns a property

{
    CCodeChain &CC = g_pUniverse->GetCC();

    if (strEquals(sName, PROPERTY_IS_ACTIVE))
        return CC.CreateBool(IsActive());

    else if (strEquals(sName, PROPERTY_IS_COMPLETED))
        return CC.CreateBool(IsCompleted());

    else if (strEquals(sName, PROPERTY_IS_DEBRIEFED))
        return CC.CreateBool(m_fDebriefed);

    else if (strEquals(sName, PROPERTY_IS_DECLINED))
        return CC.CreateBool(m_fDeclined);

    else if (strEquals(sName, PROPERTY_IS_FAILURE))
        return CC.CreateBool(IsFailure());

    else if (strEquals(sName, PROPERTY_IS_INTRO_SHOWN))
        return CC.CreateBool(m_fIntroShown);

    else if (strEquals(sName, PROPERTY_IS_OPEN))
        return CC.CreateBool(m_iStatus == statusOpen);

    else if (strEquals(sName, PROPERTY_IS_RECORDED))
        return CC.CreateBool(IsRecorded());

    else if (strEquals(sName, PROPERTY_IS_SUCCESS))
        return CC.CreateBool(IsSuccess());

    else if (strEquals(sName, PROPERTY_IS_UNAVAILABLE))
        return CC.CreateBool(IsUnavailable());

    else if (strEquals(sName, PROPERTY_NODE_ID))
        return (m_sNodeID.IsBlank() ? CC.CreateNil() : CC.CreateString(m_sNodeID));

    else if (strEquals(sName, PROPERTY_OWNER_ID))
    {
        if (m_pOwner.GetID() == OBJID_NULL)
            return CC.CreateNil();
        else
            return CC.CreateInteger(m_pOwner.GetID());
    }

    else if (strEquals(sName, PROPERTY_UNID))
        return CC.CreateInteger(m_pType->GetUNID());

    else
        return CSpaceObject::GetProperty(sName);
}
Exemplo n.º 2
0
    TEST_F(GlobalAllocatorTest, RequestBlock)
	{
		auto instance = gcix::GlobalAllocator::Instance;
		ASSERT_NE(nullptr, instance);

		// Check internals
		ASSERT_EQ(0, instance->Chunks.Count());

		// Request a memory block
		auto blockData0 = instance->RequestBlock(false);
		ASSERT_EQ(1, instance->Chunks.Count());

		// Gets the chunk
		auto chunk0 = instance->Chunks[0];
		ASSERT_NE(nullptr, chunk0);

		// Check that a chunk has the same address as the first block data
		EXPECT_EQ((void*)chunk0, (void*)blockData0);

        EXPECT_TRUE(chunk0->IsFree());
        EXPECT_TRUE(chunk0->HasFreeBlocks());
        EXPECT_FALSE(chunk0->HasRecyclableBlocks());

		// Check block count per chunk
		EXPECT_EQ(Constants::BlockCountPerChunk, chunk0->GetBlockCount());

		// Check allocated blocks
		for (int i = 0; i < chunk0->GetBlockCount(); i++)
		{
			auto block = chunk0->GetBlock(i);

			if (i == 0)
			{
				EXPECT_EQ(block, blockData0);
			}

			EXPECT_TRUE(block->IsFree());
			EXPECT_FALSE(block->IsRecyclable());
			EXPECT_FALSE(block->IsUnavailable());

			// Check that all block data are aligned on a block size
			EXPECT_EQ(0, (intptr_t)block & Constants::BlockSizeInBytesMask);

            // Check line flags are empty
            for (uint32_t lineIndex = Constants::HeaderLineCount; lineIndex < Constants::LineCount; lineIndex++)
            {
                EXPECT_EQ(LineFlags::Empty, block->Header.LineFlags[lineIndex]);

                // Check line datas are empty
                for (uint32_t columnIndex = 0; columnIndex < Constants::LineSizeInBytes; columnIndex++)
                {
                    EXPECT_EQ(0, block->Lines[lineIndex][columnIndex]);
                }
            }
		}

		// Check Bump cursor in BlockData, must be equal to the header size
		EXPECT_EQ(Constants::HeaderSizeInBytes, blockData0->Header.Info.BumpCursor);

		// Check BumpCursorLimit = 0
		EXPECT_EQ(0, blockData0->Header.Info.BumpCursorLimit);

		// Check Chunk min/max memory
		auto minChunkAddress = chunk0;
		auto maxChunkAddress = (Chunk*)((intptr_t)chunk0 + Constants::BlockSizeInBytes * Constants::BlockCountPerChunk);

		// Check pointers inside the chunk
		EXPECT_TRUE(instance->Chunks.Contains(chunk0));
		EXPECT_TRUE(instance->Chunks.Contains((Chunk*)((intptr_t)maxChunkAddress - 1)));

		// Check pointers outside the chunk
		EXPECT_FALSE(instance->Chunks.Contains((Chunk*)((intptr_t)chunk0 - 1)));
		EXPECT_FALSE(instance->Chunks.Contains(maxChunkAddress));

		// Allocate remaining blocks into the chunk
		for (int i = 1; i < chunk0->GetBlockCount(); i++)
		{
			auto nextBlock = instance->RequestBlock(false);
			EXPECT_TRUE(instance->Chunks.Contains((Chunk*)nextBlock));
		}

		// Reallocate a new block from a new chunk
		auto nextBlockOfNextChunj = instance->RequestBlock(false);
		auto nextChunk = (Chunk*)nextBlockOfNextChunj;
		EXPECT_TRUE(nextChunk < minChunkAddress || nextChunk > maxChunkAddress);

		// Recycle freshly allocated block, as they have not been marked, the nextChunk must be freed by the recycle
		// while the firstChunk must be kept for future allocation.
		instance->Recycle();
		EXPECT_EQ(1, instance->Chunks.Count());

		// TODO Add tests after recycle

	}
Exemplo n.º 3
0
bool CMission::MatchesCriteria (CSpaceObject *pSource, const SCriteria &Criteria)

//	MatchesCriteria
//
//	Returns TRUE if the given mission matches the criteria

{
    int i;

    //	By status

    if (Criteria.bIncludeActive && !IsActive())
        return false;

    if (Criteria.bIncludeOpen && m_iStatus != statusOpen)
        return false;

    if (Criteria.bIncludeRecorded && !IsRecorded())
        return false;

    if (Criteria.bIncludeUnavailable && !IsUnavailable())
        return false;

    //	Owned by source

    if (Criteria.bOnlySourceOwner)
    {
        if (pSource)
        {
            if (pSource->GetID() != m_pOwner.GetID())
                return false;
        }
        else
        {
            if (m_pOwner.GetID() != OBJID_NULL)
                return false;
        }
    }

    //	Check required attributes

    for (i = 0; i < Criteria.AttribsRequired.GetCount(); i++)
        if (!HasAttribute(Criteria.AttribsRequired[i]))
            return false;

    //	Check attributes not allowed

    for (i = 0; i < Criteria.AttribsNotAllowed.GetCount(); i++)
        if (HasAttribute(Criteria.AttribsNotAllowed[i]))
            return false;

    //	Check special attribs required

    for (i = 0; i < Criteria.SpecialRequired.GetCount(); i++)
        if (!HasSpecialAttribute(Criteria.SpecialRequired[i]))
            return false;

    //	Check special attribs not allowed

    for (i = 0; i < Criteria.SpecialNotAllowed.GetCount(); i++)
        if (HasSpecialAttribute(Criteria.SpecialNotAllowed[i]))
            return false;

    //	Match

    return true;
}
Exemplo n.º 4
0
ICCItem *CMission::GetProperty (CCodeChainCtx &Ctx, const CString &sName)

//	GetProperty
//
//	Returns a property

	{
	CCodeChain &CC = g_pUniverse->GetCC();

	if (strEquals(sName, PROPERTY_ACCEPTED_ON))
		return (m_fAcceptedByPlayer ? CC.CreateInteger(m_dwAcceptedOn) : CC.CreateNil());

	else if (strEquals(sName, PROPERTY_CAN_BE_DELETED))
		return CC.CreateBool(m_pType->CanBeDeleted());

	else if (strEquals(sName, PROPERTY_DEBRIEFER_ID))
		{
		if (m_pDebriefer.GetID() != OBJID_NULL)
			return CC.CreateInteger(m_pDebriefer.GetID());
		else if (m_pOwner.GetID() != OBJID_NULL)
			return CC.CreateInteger(m_pOwner.GetID());
		else
			return CC.CreateNil();
		}

	else if (strEquals(sName, PROPERTY_FORCE_UNDOCK_AFTER_DEBRIEF))
		return CC.CreateBool(m_pType->ForceUndockAfterDebrief());

	else if (strEquals(sName, PROPERTY_IS_ACTIVE))
		return CC.CreateBool(IsActive());

	else if (strEquals(sName, PROPERTY_IS_COMPLETED))
		return CC.CreateBool(IsCompleted());

	else if (strEquals(sName, PROPERTY_IS_DEBRIEFED))
		return CC.CreateBool(m_fDebriefed);

	else if (strEquals(sName, PROPERTY_IS_DECLINED))
		return CC.CreateBool(m_fDeclined);

	else if (strEquals(sName, PROPERTY_IS_FAILURE))
		return CC.CreateBool(IsFailure());

	else if (strEquals(sName, PROPERTY_IS_INTRO_SHOWN))
		return CC.CreateBool(m_fIntroShown);

	else if (strEquals(sName, PROPERTY_IS_OPEN))
		return CC.CreateBool(m_iStatus == statusOpen);

	else if (strEquals(sName, PROPERTY_IS_RECORDED))
		return CC.CreateBool(IsRecorded());

	else if (strEquals(sName, PROPERTY_IS_SUCCESS))
		return CC.CreateBool(IsSuccess());

	else if (strEquals(sName, PROPERTY_IS_UNAVAILABLE))
		return CC.CreateBool(IsUnavailable());

	else if (strEquals(sName, PROPERTY_NAME))
		return CC.CreateString(m_sTitle);

	else if (strEquals(sName, PROPERTY_NODE_ID))
		return (m_sNodeID.IsBlank() ? CC.CreateNil() : CC.CreateString(m_sNodeID));

	else if (strEquals(sName, PROPERTY_OWNER_ID))
		{
		if (m_pOwner.GetID() == OBJID_NULL)
			return CC.CreateNil();
		else
			return CC.CreateInteger(m_pOwner.GetID());
		}

	else if (strEquals(sName, PROPERTY_SUMMARY))
		return CC.CreateString(m_sInstructions);

	else if (strEquals(sName, PROPERTY_UNID))
		return CC.CreateInteger(m_pType->GetUNID());

	else
		return CSpaceObject::GetProperty(Ctx, sName);
	}