Ejemplo n.º 1
0
BaseComponent* ComponentList::AddComponent(COMPONENT_ID ID,
                                           engine::Transform &t,
                                           game::GameObject &g)
{
  assert(ID >= 0 && ID < COMPONENT_ID_LIST_SIZE && "Not a valid componentID");
  //assert(ID >= 0 && ID < COMPONENT_ID_LIST_SIZE, "banana");
  if(m_components[ID] != nullptr)
    RemoveComponent(ID);
  return (m_components[ID] = component_factory::CreateComponent(ID, t, g));
}
Ejemplo n.º 2
0
void Entity::RemoveComponentRaw(QObject* comp)
{
    LogWarning("Entity::RemoveComponentRaw: This function is deprecated and will be removed. Use RemoveComponent or RemoveComponentById instead.");
    IComponent* compPtr = dynamic_cast<IComponent*>(comp);
    if (compPtr)
    {
        ComponentPtr ptr = Component(compPtr->TypeName(), compPtr->Name()); //the shared_ptr to this component
        RemoveComponent(ptr);
    }
}
Ejemplo n.º 3
0
void Node::RemoveAllComponents()
{
    if (components_.Empty())
        return;
    
    while (components_.Size())
        RemoveComponent(--components_.End());
    
    // Mark node dirty in all replication states
    MarkReplicationDirty();
}
Ejemplo n.º 4
0
	inline GameObject::~GameObject(void) {
		
		for (auto it = m_components.begin(); it != m_components.end(); ++it) {
			RemoveComponent(it->second);
			delete it->second;
		}
		
		if (m_scene != NULL) {
			m_scene->RemoveGameObject(this);
		}
	}
Ejemplo n.º 5
0
void TagsView::NotifyTagsChanged(TagsModel * sender)
{
	for(int i = 0; i < tags.size(); i++)
	{
		RemoveComponent(tags[i]);
		delete tags[i];
	}
	tags.clear();


	class DeleteTagAction : public ui::ButtonAction
	{
		TagsView * v;
		std::string tag;
	public:
		DeleteTagAction(TagsView * _v, std::string tag) { v = _v; this->tag = tag; }
		void ActionCallback(ui::Button * sender)
		{
			try
			{
				v->c->RemoveTag(tag);
			}
			catch(TagsModelException & ex)
			{
				new ErrorMessage("Could not remove tag", ex.what());
			}
		}
	};

	if(sender->GetSave())
	{
		for(int i = 0; i < sender->GetSave()->GetTags().size(); i++)
		{
			ui::Label * tempLabel = new ui::Label(ui::Point(35, 35+(16*i)), ui::Point(120, 16), sender->GetSave()->GetTags()[i]);
			tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;			tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
			tags.push_back(tempLabel);
			AddComponent(tempLabel);

			if(sender->GetSave()->GetUserName() == Client::Ref().GetAuthUser().Username || Client::Ref().GetAuthUser().UserElevation == User::ElevationAdmin || Client::Ref().GetAuthUser().UserElevation == User::ElevationModerator)
			{
				ui::Button * tempButton = new ui::Button(ui::Point(15, 37+(16*i)), ui::Point(11, 12));
				tempButton->Appearance.icon = IconDelete;
				tempButton->Appearance.Border = ui::Border(0);
				tempButton->Appearance.Margin.Top += 2;
				tempButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;	
				tempButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
				tempButton->SetActionCallback(new DeleteTagAction(this, sender->GetSave()->GetTags()[i]));
				tags.push_back(tempButton);
				AddComponent(tempButton);
			}
		}
	}
}
Ejemplo n.º 6
0
	virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override
	{
		TArray<UWidgetComponent*, TInlineAllocator<1>> DeadComponents;

		for ( TWeakObjectPtr<UWidgetComponent> Component : Components )
		{
			if ( UWidgetComponent* WidgetComponent = Component.Get() )
			{
				if ( ULocalPlayer* LocalPlayer = WidgetComponent->GetOwnerPlayer() )
				{
					if ( APlayerController* PlayerController = LocalPlayer->PlayerController )
					{
						FVector WorldLocation = WidgetComponent->GetComponentLocation();

						FVector ScreenPosition;
						const bool bProjected = UWidgetLayoutLibrary::ProjectWorldLocationToWidgetPositionWithDistance(PlayerController, WorldLocation, ScreenPosition);

						if ( bProjected )
						{
							WidgetComponent->GetUserWidgetObject()->SetVisibility(ESlateVisibility::SelfHitTestInvisible);

							if ( SConstraintCanvas::FSlot* CanvasSlot = ComponentToSlot.FindRef(WidgetComponent) )
							{
								FVector2D DrawSize = WidgetComponent->GetDrawSize();
								FVector2D Pivot = WidgetComponent->GetPivot();

								CanvasSlot->AutoSize(DrawSize.IsZero());
								CanvasSlot->Offset(FMargin(ScreenPosition.X, ScreenPosition.Y, DrawSize.X, DrawSize.Y));
								CanvasSlot->Anchors(FAnchors(0, 0, 0, 0));
								CanvasSlot->Alignment(Pivot);
								CanvasSlot->ZOrder(-ScreenPosition.Z);
							}
						}
						else
						{
							WidgetComponent->GetUserWidgetObject()->SetVisibility(ESlateVisibility::Hidden);
						}
					}
				}
			}
			else
			{
				DeadComponents.Add(WidgetComponent);
			}
		}

		// Normally components should be removed by someone calling remove component, but just in case it was 
		// deleted in a way where they didn't happen, this is our backup solution to enure we remove stale widgets.
		for ( int32 Index = 0; Index < DeadComponents.Num(); Index++ )
		{
			RemoveComponent(DeadComponents[Index]);
		}
	}
Ejemplo n.º 7
0
void Node::Deinitialize() {
    OnDeinitialize();

    // clear all children
    while(mChildren.size() > 0) {
        RemoveChildNode(mChildren.begin()->first);
    }

    // clear all components
    while(mComponents.size() > 0) {
        RemoveComponent(mComponents.begin()->second->GetName());
    }
}
Ejemplo n.º 8
0
			void Storage::RemoveRepo (int repoId)
			{
				QStringList components = GetComponents (repoId);
				Q_FOREACH (const QString& component, components)
					RemoveComponent (repoId, component);

				QueryRemoveRepo_.bindValue (":repo_id", repoId);
				if (!QueryRemoveRepo_.exec ())
				{
					Util::DBLock::DumpError (QueryRemoveRepo_);
					throw std::runtime_error ("Query execution failed");
				}
			}
Ejemplo n.º 9
0
void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender)
{
	if(addCommentBox)
	{
		RemoveComponent(addCommentBox);
		delete addCommentBox;
		addCommentBox = NULL;
	}
	if(submitCommentButton)
	{
		RemoveComponent(submitCommentButton);
		delete submitCommentButton;
		submitCommentButton = NULL;
	}
	if(sender->GetCommentBoxEnabled())
	{
		commentBoxPositionX = (XRES/2)+4;
		commentBoxPositionY = Size.Y-19;
		commentBoxSizeX = Size.X-(XRES/2)-48;
		commentBoxSizeY = 17;

		addCommentBox = new ui::Textbox(ui::Point((XRES/2)+4, Size.Y-19), ui::Point(Size.X-(XRES/2)-48, 17), "", "Add Comment");
		addCommentBox->SetActionCallback(new AutoCommentSizeAction(this));
		addCommentBox->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
		addCommentBox->SetMultiline(true);
		AddComponent(addCommentBox);
		submitCommentButton = new ui::Button(ui::Point(Size.X-40, Size.Y-19), ui::Point(40, 19), "Submit");
		submitCommentButton->SetActionCallback(new SubmitCommentAction(this));
		//submitCommentButton->Enabled = false;
		AddComponent(submitCommentButton);
	}
	else
	{
		submitCommentButton = new ui::Button(ui::Point(XRES/2, Size.Y-19), ui::Point(Size.X-(XRES/2), 19), "Login to comment");
		submitCommentButton->SetActionCallback(new LoginAction(this));
		AddComponent(submitCommentButton);
	}
}
Ejemplo n.º 10
0
void Node::RemoveComponent(ShortStringHash type)
{
    for (Vector<SharedPtr<Component> >::Iterator i = components_.Begin(); i != components_.End(); ++i)
    {
        if ((*i)->GetType() == type)
        {
            RemoveComponent(i);
            
            // Mark node dirty in all replication states
            MarkReplicationDirty();
            return;
        }
    }
}
Ejemplo n.º 11
0
void Node::RemoveComponent(Component* component)
{
    for (Vector<SharedPtr<Component> >::Iterator i = components_.Begin(); i != components_.End(); ++i)
    {
        if (*i == component)
        {
            RemoveComponent(i);
            
            // Mark node dirty in all replication states
            MarkReplicationDirty();
            return;
        }
    }
}
Ejemplo n.º 12
0
void Entity::RemoveComponent(const ComponentPtr &component, AttributeChange::Type change)
{
    if (component)
    {
        for(ComponentMap::Iterator it = components_.Begin(); it != components_.End(); ++it)
            if (it->second_ == component)
            {
                RemoveComponent(it, change);
                return;
            }

        LogWarning("Entity::RemoveComponent: Failed to find " + component->TypeName() + " \"" + component->Name() + "\" from " + ToString() + ".");
    }
}
Ejemplo n.º 13
0
void RPG_DestructibleEntity::SetDestroyed()
{
  m_isDestroyed = true;

  // remove the attackable component
  RPG_AttackableComponent* attackableComponent = static_cast<RPG_AttackableComponent*>(Components().GetComponentOfType(V_RUNTIME_CLASS(RPG_AttackableComponent)));
  if (attackableComponent)
  {
    RemoveComponent(attackableComponent);
  }

  vHavokRigidBody* rigidBodyComponent = static_cast<vHavokRigidBody*>(Components().GetComponentOfType(V_RUNTIME_CLASS(vHavokRigidBody)));
  if (rigidBodyComponent)
  {
    RemoveComponent(rigidBodyComponent);
  }

  // stop the ambient effect
  StopEffect(DEFX_Ambient);
  CreateEffect(DEFX_Destroy, GetPosition(), GetOrientation());

  // remove collision if so instructed
  //if (m_removeCollisionAfterDestruction)
  {
    RemoveObstacle();
  }

  if(!m_postDestructionMeshFilename.IsEmpty())
  {
    // swap the mesh
    SetMesh(m_postDestructionMeshFilename);
  }
  else
  {
    DisposeObject();
  }
}
Ejemplo n.º 14
0
void Entity::RemoveComponent(const ComponentPtr &component, AttributeChange::Type change)
{
    if (component)
    {
        ComponentMap::iterator iter = components_.find(component->Id());
        if (iter != components_.end())
        {
            RemoveComponent(iter, change);
        }
        else
        {
            LogWarning("Failed to remove component: " + component->TypeName() + " from entity: " + QString::number(Id()));
        }
    }
}
void ComponentManager::RemoveComponentWithGameObj(GameObject * l_objects)
{
	comp_vector components_to_remove;

	for (comp_vector_const_itr itr = this->m_components.begin();
	itr != this->m_components.end(); itr++) {
		if ((*itr)->m_gameObject->m_guid == l_objects->m_guid) {
			components_to_remove.push_back((*itr));
		}
	}

	for (comp_vector_const_itr itr = components_to_remove.begin();
	itr != components_to_remove.end(); itr++) {
		RemoveComponent(itr);
	}
}
Ejemplo n.º 16
0
ComponentViewItem::ComponentViewItem(AbstractComponentView* p_item, QWidget* p_parent /*= 0*/ ) : QWidget(p_parent), m_item(p_item)
{
	m_header = new ComponentViewHeader(p_item->GetComponentName(), this);
	m_layout = new QVBoxLayout(this);
	m_layout->setContentsMargins(0, 0, 0, 0);
	m_layout->addWidget(m_header);
	m_layout->addWidget(p_item);
	m_layout->setSizeConstraint(QLayout::SetNoConstraint);
	setLayout(m_layout);

	m_header->SetArrowShape(p_item->m_shown ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow);

	connect(m_header, SIGNAL(showView()),	this, SLOT(ShowComponentView()));
	connect(m_header, SIGNAL(hideView()),	this, SLOT(HideComponentView()));
	connect(m_header, SIGNAL(remove()),		this, SLOT(RemoveComponent()));
}
Ejemplo n.º 17
0
LoginView::~LoginView() {
	RemoveComponent(titleLabel);
	RemoveComponent(loginButton);
	RemoveComponent(cancelButton);
	RemoveComponent(usernameField);
	RemoveComponent(passwordField);
	RemoveComponent(infoLabel);
	delete cancelButton;
	delete loginButton;
	delete titleLabel;
	delete usernameField;
	delete passwordField;
	delete infoLabel;
}
Ejemplo n.º 18
0
BaseComponent* ComponentList::AddComponent(BaseComponent* c)
{
  if(m_components[c->GetID()] != nullptr)
    RemoveComponent(c->GetID());
  return (m_components[c->GetID()] = c);
}
Ejemplo n.º 19
0
void Entity::ReplaceComponent(IComponent* pComponent)
{
	RemoveComponent(pComponent->GetComponentID());
	AddComponent(pComponent);
}
void ElementSearchActivity::searchTools(std::string query)
{
	firstResult = NULL;
	for(std::vector<ToolButton*>::iterator iter = toolButtons.begin(), end = toolButtons.end(); iter != end; ++iter) {
		delete *iter;
		RemoveComponent(*iter);
	}
	toolButtons.clear();

	ui::Point viewPosition = searchField->Position + ui::Point(2+0, searchField->Size.Y+2+8);
	ui::Point current = ui::Point(0, 0);

	std::string queryLower = std::string(query);
	std::transform(queryLower.begin(), queryLower.end(), queryLower.begin(), ::tolower);

	std::vector<Tool *> matches;
	std::vector<Tool *> frontmatches;
	std::vector<Tool *> exactmatches;

	for(std::vector<Tool*>::const_iterator iter = tools.begin(), end = tools.end(); iter != end; ++iter)
	{
		std::string nameLower = std::string((*iter)->GetName());
		std::transform(nameLower.begin(), nameLower.end(), nameLower.begin(), ::tolower);
		if(!strcmp(nameLower.c_str(), queryLower.c_str()))
			exactmatches.push_back(*iter);
		else if(!strncmp(nameLower.c_str(), queryLower.c_str(), queryLower.length()))
			frontmatches.push_back(*iter);
		else if(strstr(nameLower.c_str(), queryLower.c_str()))
			matches.push_back(*iter);
	}

	matches.insert(matches.begin(), frontmatches.begin(), frontmatches.end());
	matches.insert(matches.begin(), exactmatches.begin(), exactmatches.end());

	for(std::vector<Tool*>::const_iterator iter = matches.begin(), end = matches.end(); iter != end; ++iter)
	{
		Tool * tool = *iter;

		if(!firstResult)
			firstResult = tool;

		VideoBuffer * tempTexture = tool->GetTexture(26, 14);
		ToolButton * tempButton;

		if(tempTexture)
			tempButton = new ToolButton(current+viewPosition, ui::Point(30, 18), "", tool->GetIdentifier(), tool->GetDescription());
		else
			tempButton = new ToolButton(current+viewPosition, ui::Point(30, 18), tool->GetName(), tool->GetIdentifier(), tool->GetDescription());

		tempButton->Appearance.SetTexture(tempTexture);
		tempButton->Appearance.BackgroundInactive = ui::Colour(tool->colRed, tool->colGreen, tool->colBlue);
		tempButton->SetActionCallback(new ToolAction(this, tool));

		if(gameController->GetActiveTool(0) == tool)
		{
			tempButton->SetSelectionState(0);	//Primary
		}
		else if(gameController->GetActiveTool(1) == tool)
		{
			tempButton->SetSelectionState(1);	//Secondary
		}
		else if(gameController->GetActiveTool(2) == tool)
		{
			tempButton->SetSelectionState(2);	//Tertiary
		}

		toolButtons.push_back(tempButton);
		AddComponent(tempButton);

		current.X += 31;

		if(current.X + 30 > searchField->Size.X) {
			current.X = 0;
			current.Y += 19;
		}

		if(current.Y + viewPosition.Y + 18 > Size.Y-23)
			break;
	}
}
Ejemplo n.º 21
0
void SearchView::NotifyTagListChanged(SearchModel * sender)
{
	int i = 0;
	int buttonWidth, buttonHeight, saveX = 0, saveY = 0, savesX = 5, savesY = 4, buttonPadding = 1;
	int buttonAreaWidth, buttonAreaHeight, buttonXOffset, buttonYOffset;

	int tagWidth, tagHeight, tagX = 0, tagY = 0, tagsX = 6, tagsY = 4, tagPadding = 1;
	int tagAreaWidth, tagAreaHeight, tagXOffset, tagYOffset;

	vector<pair<string, int> > tags = sender->GetTagList();

	RemoveComponent(motdLabel);
	motdLabel->SetParentWindow(NULL);

	RemoveComponent(tagsLabel);
	tagsLabel->SetParentWindow(NULL);

	for(i = 0; i < tagButtons.size(); i++)
	{
		RemoveComponent(tagButtons[i]);
		delete tagButtons[i];
	}
	tagButtons.clear();

	buttonYOffset = 28;
	buttonXOffset = buttonPadding;
	buttonAreaWidth = Size.X;
	buttonAreaHeight = Size.Y - buttonYOffset - 18;

	if(sender->GetShowTags())
	{
		buttonYOffset += (buttonAreaHeight/savesY) - buttonPadding*2;
		buttonAreaHeight = Size.Y - buttonYOffset - 18;
		savesY--;

		tagXOffset = tagPadding;
		tagYOffset = 60;
		tagAreaWidth = Size.X;
		tagAreaHeight = ((buttonAreaHeight/savesY) - buttonPadding*2)-(tagYOffset-28)-5;
		tagWidth = (tagAreaWidth/tagsX) - tagPadding*2;
		tagHeight = (tagAreaHeight/tagsY) - tagPadding*2;

		AddComponent(tagsLabel);
		tagsLabel->Position.Y = tagYOffset-16;

		AddComponent(motdLabel);
		motdLabel->Position.Y = tagYOffset-30;
	}

	class TagAction: public ui::ButtonAction
	{
		SearchView * v;
		std::string tag;
	public:
		TagAction(SearchView * v, std::string tag) : v(v), tag(tag) {}
		virtual void ActionCallback(ui::Button * sender)
		{
			v->Search(tag);
		}
	};
	if(sender->GetShowTags())
	{
		for(i = 0; i < tags.size(); i++)
		{
			int maxTagVotes = tags[0].second;

			pair<string, int> tag = tags[i];
			
			if(tagX == tagsX)
			{
				if(tagY == tagsY-1)
					break;
				tagX = 0;
				tagY++;
			}

			int tagAlpha = 192;
			if (maxTagVotes)
				tagAlpha = 127+(128*tag.second)/maxTagVotes;

			ui::Button * tagButton;
			tagButton = new ui::Button(
				ui::Point(
						tagXOffset + tagPadding + tagX*(tagWidth+tagPadding*2),
						tagYOffset + tagPadding + tagY*(tagHeight+tagPadding*2)
					),
				ui::Point(tagWidth, tagHeight),
				tag.first
				);
			tagButton->SetActionCallback(new TagAction(this, tag.first));
			tagButton->Appearance.BorderInactive = ui::Colour(0, 0, 0);
			tagButton->Appearance.BorderHover = ui::Colour(0, 0, 0);
			tagButton->Appearance.BorderActive = ui::Colour(0, 0, 0);
			tagButton->Appearance.BackgroundHover = ui::Colour(0, 0, 0);

			tagButton->Appearance.TextInactive = ui::Colour(tagAlpha, tagAlpha, tagAlpha);
			tagButton->Appearance.TextHover = ui::Colour((tagAlpha*5)/6, (tagAlpha*5)/6, tagAlpha);
			AddComponent(tagButton);
			tagButtons.push_back(tagButton);
			tagX++;

		}
	}
}
Ejemplo n.º 22
0
void Entity::RemoveComponentById(component_id_t id, AttributeChange::Type change)
{
    ComponentPtr comp = ComponentById(id);
    if (comp)
        RemoveComponent(comp, change);
}
template<> void Pocket::GameObject::RemoveComponent<Position>() { RemoveComponent(0); }
Ejemplo n.º 24
0
void VRendererNodeCommon::InitializePostProcessors()
{
  VASSERT_MSG(IsInitialized(), "The renderer node must be initialized before initializing the post processors.");

  ANALYSIS_IGNORE_WARNING_BLOCK_START(6385);
  ANALYSIS_IGNORE_WARNING_BLOCK_START(6211);

  // Increment the update counter to enable modifying the post processors without recursing
  m_iPostProcessorUpdateCounter++;

  VType* pCopyPostProcessorType = GetDefaultCopyPostprocessorType();

  bool bInvalidPostProcessorActive = false;
  do
  {
    bInvalidPostProcessorActive = false;
    DeInitializePostProcessors();

    VPostProcessingBaseComponent* pSimpleCopy = NULL;

    // Collect post processor components
    VMemoryTempBuffer<256> tempBuffer((Components().Count() + 1) * sizeof(VPostProcessingBaseComponent*));
    VPostProcessingBaseComponent** postProcessors = reinterpret_cast<VPostProcessingBaseComponent**>(tempBuffer.GetBuffer());
    int iPostProcessorIndex = 0;
    for(int iComponentIndex = 0; iComponentIndex < Components().Count(); iComponentIndex++)
    {
      if(VPostProcessingBaseComponent* pPostProcessor = vdynamic_cast<VPostProcessingBaseComponent*>(Components().GetAt(iComponentIndex)))
      {
        // Don't take the auto added copy PP into consideration, we'll handle that separately
        if(pCopyPostProcessorType != NULL && pPostProcessor->IsOfType(pCopyPostProcessorType))
        {
          pSimpleCopy = pPostProcessor;
          continue;
        }

        // HS#10443: Skip post-processors which do nothing - needs testing whether this works cleanly when the identity state changes
        if(!pPostProcessor->IsActive() /*!pPostProcessor->IsIdentity()*/)
        {
          continue;
        }

        postProcessors[iPostProcessorIndex] = pPostProcessor;
        iPostProcessorIndex++;
      }
    }

    int iNumPostProcessors = iPostProcessorIndex;

    qsort(postProcessors, iNumPostProcessors, sizeof(VPostProcessingBaseComponent*), ComparePostProcessorsByPriority);

    int iCopyPPIndex = iNumPostProcessors;

    // Scan backwards through post processors to find one which can take over the responsibility
    // of copying the scene to the final target context
    //
    //  This post processor must:
    //    - come after the MSAA resolve step
    //    - render an opaque full screen quad
    //    - not have any postprocessor afterwards that reads the accumulation buffer
    bool bUsesOffscreenRenderTarget = !m_bUsesDirectRenderToFinalTargetContext;
    for(int i = iNumPostProcessors - 1; i >= 0; i--)
    {
      if(postProcessors[i]->GetPriority() < VIS_RENDERCONTEXTPRIORITY_POSTPROCESSOR_RESOLVED)
      {
        bUsesOffscreenRenderTarget = true;
        break;
      }

      const unsigned int flags = postProcessors[i]->GetBufferUsageFlags();

      // Post processors that use their own render target can't be used for copying to the back buffer
      if((flags & VPostProcessingBaseComponent::USES_CUSTOM_RENDERTARGET) != 0)
      {
        bUsesOffscreenRenderTarget = true;
        break;
      }

      // Check first if the post processors draws an opaque full screen quad, because
      // a PP that draws a full screen quad AND samples the accumulation buffer
      // is still suitable for copying the accumulation buffer into the final target context (such as tonemapping).
      if((flags & VPostProcessingBaseComponent::DRAWS_FULLSCREEN_QUAD) != 0 && (flags & VPostProcessingBaseComponent::USES_BLENDING) == 0)
      {
        iCopyPPIndex = i;
        break;
      }

      if(flags & VPostProcessingBaseComponent::SAMPLES_ACCUMULATION_BUFFER)
      {
        bUsesOffscreenRenderTarget = true;
        break;
      }
    }

    VASSERT_MSG(bUsesOffscreenRenderTarget != m_bUsesDirectRenderToFinalTargetContext, "Renderer node indicated that it renders directly to the renderer node's final target context, but post-processors require an offscreen render target!");

    // If no suitable post processor was found, we need to make sure the scene is copied
    bool bNeedsManualCopyToTarget = (iCopyPPIndex == iNumPostProcessors) && bUsesOffscreenRenderTarget;

    // If we don't use an offscreen RT, we don't have a copy PP
    if (!bUsesOffscreenRenderTarget)
      iCopyPPIndex = -1;

    if(bNeedsManualCopyToTarget)
    {
      if (pCopyPostProcessorType != NULL)
      {
        if(pSimpleCopy == NULL)
        {
          pSimpleCopy = (VPostProcessingBaseComponent*)pCopyPostProcessorType->CreateInstance();
          VASSERT(pSimpleCopy != NULL);
          AddComponent(pSimpleCopy);
        }

        postProcessors[iNumPostProcessors] = pSimpleCopy;
        iNumPostProcessors++;
      }
    }
    else if(pSimpleCopy != NULL)
    {
      // Remove existing copy PP if not needed
      RemoveComponent(pSimpleCopy);
    }

    m_assignedContexts.EnsureCapacity(iNumPostProcessors);

    // Create a target context for each post processor
    for(iPostProcessorIndex = 0; iPostProcessorIndex < iNumPostProcessors; iPostProcessorIndex++)
    {
      VPostProcessingBaseComponent* pPostProcessor = postProcessors[iPostProcessorIndex];

      pPostProcessor->m_iTargetIndex = iPostProcessorIndex;

      const VisRenderContext_cl* pFinalTargetContext = GetFinalTargetContext();

      bool bRenderIntoFinalTargetContext = (iPostProcessorIndex >= iCopyPPIndex);

      int iPosX, iPosY, iWidth, iHeight;
      float zMin, zMax;
      if(bRenderIntoFinalTargetContext)
      {
        pFinalTargetContext->GetViewport(iPosX, iPosY, iWidth, iHeight, zMin, zMax);
      }
      else
      {
        GetReferenceContext()->GetViewport(iPosX, iPosY, iWidth, iHeight, zMin, zMax);
      }

      VisRenderContext_cl* pContext = new VisRenderContext_cl(pFinalTargetContext->GetCamera(), 90.0f, 90.0f, iWidth, iHeight, 0.0f, 0.0f, pFinalTargetContext->GetRenderFlags());
      pContext->SetRenderFilterMask(pFinalTargetContext->GetRenderFilterMask());
      pContext->SetViewport(iPosX, iPosY, iWidth, iHeight, zMin, zMax);
      pContext->SetViewProperties(pFinalTargetContext->GetViewProperties());

      pContext->SetName(pPostProcessor->GetTypeId()->m_lpszClassName);

      pContext->SetVisibilityCollector(pFinalTargetContext->GetVisibilityCollector(), false);
      pContext->SetPriority(pPostProcessor->GetPriority());
      pContext->SetUserData(pPostProcessor);
      pContext->SetRenderLoop(new PostProcessRenderLoop_cl(pPostProcessor));

      if(bRenderIntoFinalTargetContext)
      {
        pContext->SetRenderAndDepthStencilTargets(pFinalTargetContext);

        if (bUsesOffscreenRenderTarget)
        {
          // If possible, try to give the post processors that render directly into the final target context a useful depth-stencil target.
          // This is only possible if the final target context has MSAA disabled.
          bool bCanReplaceDST = false;

          if(pFinalTargetContext->RendersIntoBackBuffer())
          {
            #if !defined(_VISION_ANDROID) && !defined(_VISION_TIZEN) && !defined(_VISION_NACL)
              // On Android, the back buffer context uses a fixed FBO, so we can't replace the DST.
              bCanReplaceDST = Vision::Video.GetCurrentConfig()->m_eMultiSample == VVIDEO_MULTISAMPLE_OFF;
            #endif
          }
          else if(pFinalTargetContext->GetRenderTarget(0) != NULL)
          {
            bCanReplaceDST = static_cast<VisRenderableTexture_cl*>(pFinalTargetContext->GetRenderTarget(0))->GetConfig()->m_iMultiSampling <= 1;
          }

          int iRefWidth, iRefHeight, iFinalWidth, iFinalHeight;
          pFinalTargetContext->GetSize(iFinalWidth, iFinalHeight);
          GetReferenceContext()->GetSize(iRefWidth, iRefHeight);

          if(iRefWidth != iFinalWidth || iRefHeight != iFinalHeight)
          {
            bCanReplaceDST = false;
          }

          if(bCanReplaceDST)
          {
            pContext->SetDepthStencilTarget(static_cast<VisRenderableTexture_cl*>(GetPostProcessDepthStencilTarget(VRTV_RESOLVED)));
          }
          else
          {
            hkvLog::Warning("Could not attach a depth-stencil target to the context of the \"%s\" post processor - depth testing will not work correctly.", pPostProcessor->GetTypeId()->m_lpszClassName);
          }
        }
      }
      else
      {
        VRenderTargetVersion_e targetVersion = (pPostProcessor->GetPriority() <= VIS_RENDERCONTEXTPRIORITY_POSTPROCESSOR_RESOLVED) ? VRTV_MSAA : VRTV_RESOLVED;

        if((pPostProcessor->GetBufferUsageFlags() & VPostProcessingBaseComponent::USES_CUSTOM_RENDERTARGET) == 0)
        {
          pContext->SetRenderTarget(0, static_cast<VisRenderableTexture_cl*>(GetPostProcessColorTarget(targetVersion)));
          pContext->SetDepthStencilTarget(static_cast<VisRenderableTexture_cl*>(GetPostProcessDepthStencilTarget(targetVersion)));
        }
      }

      m_assignedContexts.Add(pContext);

      pPostProcessor->InitializePostProcessor();

      // Validity can only be determined after initialization, so deactivate the invalid postprocessor and retry the entire context setup
      if(!pPostProcessor->IsValid())
      {
        // the post-processor will have deactivated itself by now
        pPostProcessor->SetActive(false);
        bInvalidPostProcessorActive = true;
      }
    }
  }
  while ( bInvalidPostProcessorActive );

  m_bPostProcessorAssignmentDirty = false;
  m_iPostProcessorUpdateCounter--;

  VisRenderContext_cl::ElementManagerDeleteAllUnRef();

  ANALYSIS_IGNORE_WARNING_BLOCK_END;
  ANALYSIS_IGNORE_WARNING_BLOCK_END;
}
Ejemplo n.º 25
0
void SearchView::NotifySaveListChanged(SearchModel * sender)
{
	int i = 0;
	int buttonWidth, buttonHeight, saveX = 0, saveY = 0, savesX = 5, savesY = 4, buttonPadding = 1;
	int buttonAreaWidth, buttonAreaHeight, buttonXOffset, buttonYOffset;

	int tagWidth, tagHeight, tagX = 0, tagY = 0, tagsX = 6, tagsY = 4, tagPadding = 1;
	int tagAreaWidth, tagAreaHeight, tagXOffset, tagYOffset;

	vector<SaveInfo*> saves = sender->GetSaveList();
	//string messageOfTheDay = sender->GetMessageOfTheDay();

	if(sender->GetShowFavourite())
		favouriteSelected->SetText("Unfavourite");
	else
		favouriteSelected->SetText("Favourite");

	Client::Ref().ClearThumbnailRequests();
	for(i = 0; i < saveButtons.size(); i++)
	{
		RemoveComponent(saveButtons[i]);
	}
	if(!sender->GetSavesLoaded())
	{
		nextButton->Enabled = false;
		previousButton->Enabled = false;
		favButton->Enabled = false;
	}
	else
	{
		nextButton->Enabled = true;
		previousButton->Enabled = true;
		if (Client::Ref().GetAuthUser().ID)
			favButton->Enabled = true;
	}
	if (!sender->GetSavesLoaded() || favButton->GetToggleState())
	{
		ownButton->Enabled = false;
		sortButton->Enabled = false;
	}
	else
	{
		if (Client::Ref().GetAuthUser().ID)
			ownButton->Enabled = true;
		sortButton->Enabled = true;
	}
	if(!saves.size())
	{
		loadingSpinner->Visible = false;
		if(!errorLabel)
		{
			errorLabel = new ui::Label(ui::Point(((XRES+BARSIZE)/2)-100, ((YRES+MENUSIZE)/2)-6), ui::Point(200, 12), "Error");
			AddComponent(errorLabel);
		}
		if(!sender->GetSavesLoaded())
		{
			errorLabel->SetText("Loading...");
			loadingSpinner->Visible = true;
		}
		else
		{
			if(sender->GetLastError().length())
				errorLabel->SetText("\bo" + sender->GetLastError());
			else
				errorLabel->SetText("\boNo saves found");
		}
	}
	else
	{
		loadingSpinner->Visible = false;
		if(errorLabel)
		{
			RemoveComponent(errorLabel);
			delete errorLabel;
			errorLabel = NULL;
		}
		for(i = 0; i < saveButtons.size(); i++)
		{
			delete saveButtons[i];
		}
		saveButtons.clear();

		buttonYOffset = 28;
		buttonXOffset = buttonPadding;
		buttonAreaWidth = Size.X;
		buttonAreaHeight = Size.Y - buttonYOffset - 18;

		if(sender->GetShowTags())
		{
			buttonYOffset += (buttonAreaHeight/savesY) - buttonPadding*2;
			buttonAreaHeight = Size.Y - buttonYOffset - 18;
			savesY--;

			tagXOffset = tagPadding;
			tagYOffset = 60;
			tagAreaWidth = Size.X;
			tagAreaHeight = ((buttonAreaHeight/savesY) - buttonPadding*2)-(tagYOffset-28)-5;
			tagWidth = (tagAreaWidth/tagsX) - tagPadding*2;
			tagHeight = (tagAreaHeight/tagsY) - tagPadding*2;
		}

		buttonWidth = (buttonAreaWidth/savesX) - buttonPadding*2;
		buttonHeight = (buttonAreaHeight/savesY) - buttonPadding*2;



		class SaveOpenAction: public ui::SaveButtonAction
		{
			SearchView * v;
		public:
			SaveOpenAction(SearchView * _v) { v = _v; }
			virtual void ActionCallback(ui::SaveButton * sender)
			{
				v->c->OpenSave(sender->GetSave()->GetID(), sender->GetSave()->GetVersion());
			}
			virtual void SelectedCallback(ui::SaveButton * sender)
			{
				v->c->Selected(sender->GetSave()->GetID(), sender->GetSelected());
			}
			virtual void AltActionCallback(ui::SaveButton * sender)
			{
				stringstream search;
				search << "history:" << sender->GetSave()->GetID();
				v->Search(search.str());
			}
			virtual void AltActionCallback2(ui::SaveButton * sender)
			{
				v->Search("user:"+sender->GetSave()->GetUserName());
			}
		};
		for(i = 0; i < saves.size(); i++)
		{
			if(saveX == savesX)
			{
				if(saveY == savesY-1)
					break;
				saveX = 0;
				saveY++;
			}
			ui::SaveButton * saveButton;
			saveButton = new ui::SaveButton(
						ui::Point(
							buttonXOffset + buttonPadding + saveX*(buttonWidth+buttonPadding*2),
							buttonYOffset + buttonPadding + saveY*(buttonHeight+buttonPadding*2)
							),
						ui::Point(buttonWidth, buttonHeight),
						saves[i]);
			saveButton->AddContextMenu(0);
			saveButton->SetActionCallback(new SaveOpenAction(this));
			if(Client::Ref().GetAuthUser().ID)
				saveButton->SetSelectable(true);
			if (saves[i]->GetUserName() == Client::Ref().GetAuthUser().Username || Client::Ref().GetAuthUser().UserElevation == User::ElevationAdmin || Client::Ref().GetAuthUser().UserElevation == User::ElevationModerator)
				saveButton->SetShowVotes(true);
			saveButtons.push_back(saveButton);
			AddComponent(saveButton);
			saveX++;
		}
	}
}
template<> void Pocket::GameObject::RemoveComponent<Velocity>() { RemoveComponent(1); }