コード例 #1
0
ファイル: Scope.cpp プロジェクト: sakuradavik/GameEngine
Scope& Scope::AppendScope(const std::string& key)
{
	Datum* datum = Find(key);
	//TODO: Push Back when removing from Vector
	//Found key, check if type is table
	if (datum)
	{
		if (datum->IsExternal() || (datum->GetType() != Datum::DatumType::Table))
		{
			throw std::exception("This Datum is not of the right type");
		}
		Scope* newScope = new Scope();
		newScope->mParent = this;
		datum->Set(newScope, datum->Size());
		return *datum->GetScope(datum->Size() - 1);
	}
	else
	{
		//key not found
		Datum& d = Append(key, Datum::DatumType::Table);
		Scope* newScope = new Scope();
		newScope->mParent = this;
		d.Set(newScope, 0);
		return *d.GetScope(0);
	}
}
コード例 #2
0
ファイル: Scope.cpp プロジェクト: sakuradavik/GameEngine
void Scope::Adopt(Scope& childToAdopt, const std::string& key, const std::uint32_t index)
{
	if (childToAdopt.GetParent())
		childToAdopt.Orphan();

	Datum * foundDatum = Find(key);
	if (foundDatum)
	{
		if ((foundDatum->GetType() != Datum::DatumType::Table) || foundDatum->IsExternal())
			throw std::exception("You are trying to adopt into a invalid scope");

		if ((foundDatum->GetType() == Datum::DatumType::Table))
		{
			if (index >= foundDatum->Size())
			{
				foundDatum->Set(&childToAdopt, index);
				foundDatum->GetScope(index)->mParent = this;
			}
			else
			{
				Scope* temp = foundDatum->GetScope(index);
				foundDatum->Set(&childToAdopt, index);
				foundDatum->GetScope(index)->mParent = this;
				for (std::uint32_t i = index + 1; i < foundDatum->Size(); ++i)
				{
					Scope* temp2 = foundDatum->GetScope(i);
					foundDatum->Set(temp, i);
					temp = temp2;
				}
				foundDatum->Set(temp, foundDatum->Size());
			}
		}
	}
	else
	{
		Datum& d = Append(key, Datum::DatumType::Table);
		d.Set(&childToAdopt);
		d.GetScope()->mParent = this;
	}
}
コード例 #3
0
ファイル: Scope.cpp プロジェクト: Poltergust/FieaGameEngine
void Scope::Adopt(Scope& child, const std::string& key, std::uint32_t index)
{
    if (key == std::string())
        throw std::exception("Key cannot be an empty string.");

    child.Orphan();
    child.mParent = this;

    // try to find entry first in this scope
    Datum* d = Find(key);
    if (d != nullptr)
    {
        if (d->GetType() != Datum::Table)
            throw std::exception("Found entry is not a table!");
        if (d->IsExternal())
            throw std::exception("Table is external. Cannot modify data owned by something else.");

        std::uint32_t originalDatumSize = d->Size();

        // if a scope is empty or not pointing to anything at the given index, we can just have it point to something else
        if (originalDatumSize <= index || d->GetTable(index) == nullptr || d->GetTable(index)->mOrder.Size() == 0)
            d->Set(&child, index);

        // otherwise, we add in the child scope and rearrange the datum array if necessary
        else
        {
            if (index < originalDatumSize)
            {
                d->SetSize(originalDatumSize + 1);
                for (std::uint32_t i = originalDatumSize; i > index; --i)
                {
                    d->Set(d->GetTable(i - 1), i);
                }
            }
            else if (index > originalDatumSize)
            {
                index = originalDatumSize;
            }
            d->Set(&child, index);
        }
    }
    else
    {
        Datum scopeDatum;
        scopeDatum = &child;

        std::pair<std::string, Datum> pair(key, scopeDatum);
        HashMap<std::string, Datum>::Iterator iterator = mTable.Insert(pair);
        mOrder.PushBack(&(*iterator));
    }
}
コード例 #4
0
ファイル: Scope.cpp プロジェクト: Poltergust/FieaGameEngine
Scope& Scope::AppendScope(const std::string& key)
{
    if (key == std::string())
        throw std::exception("Key cannot be an empty string.");

    Scope* newScope = new Scope();
    newScope->mParent = this;

    // try to find entry first in this scope
    Datum* d = Find(key);
    if (d != nullptr)
    {
        if (d->GetType() != Datum::Table && d->GetType() != Datum::Unknown)
        {
            delete newScope;
            throw std::exception("Found entry is not a table!");
        }
        if (d->IsExternal())
        {
            delete newScope;
            throw std::exception("Table entry is external. Cannot modify data owned by something else.");
        }

        // a new scope gets added into this table datum
        std::uint32_t datumSize = d->Size();
        d->Set(newScope, datumSize);
        return *d->GetTable(datumSize);
    }

    // if no entry is found, create new datum with this scope
    Datum scopeDatum;
    scopeDatum = newScope;
    std::pair<std::string, Datum> pair(key, scopeDatum);
    HashMap<std::string, Datum>::Iterator iterator = mTable.Insert(pair);
    mOrder.PushBack(&(*iterator));
    return *(iterator->second.GetTable());
}
コード例 #5
0
ファイル: ActionAdopt.cpp プロジェクト: CalWLee/FIEATetris
	/**
	The update function of ActionAdopt calls the setSector method of
	the entity that contains this action on the provided target sector.
	This should produce the behavior of orphaning the entity and moving it
	into a new sector

	@param curState the current worldstate to reference during update
	*/
	void ActionAdopt::Update(const WorldState& curState)
	{
		//Double check to ensure that our target sector isn't the one
		//that our containing entity already exists in
		std::string targetName = Find("Target")->Get<std::string>();
		Sector* curSector = curState.GetSector();
		if (targetName == curSector->Name())
		{
			return;
		}

		//Grab the entity that contains us
		Entity* curEntity = curState.GetEntity();
		
		//Grab the world
		World* curWorld = curState.GetWorld();

		//Set up the sector
		Datum* targetDatum = curWorld->Sectors()->Find(targetName);
		if (targetDatum == nullptr || targetDatum->GetType() != Datum::TABLE)
		{
			throw std::exception("Sector could not be found");
		}
		else		
		{
			Sector* targetSector = targetDatum->Get<Scope*>()->As<Sector>();
			if (targetSector == nullptr)
			{
				throw std::exception("Malformed sector");
			}
			else
			{
				curEntity->SetSector(targetSector);
				return;
			}
		}
	}