示例#1
0
void Hero::showHint()
{
    ObjectWeakPtrs objs;
    Simulator::get().findObjectsAround(getX(), getY(), getZ(), 5, &objs);

    ObjectSharedPtr objectWithHint;
    for (auto i = objs.begin(); i != objs.end(); ++i)
    {
        ObjectSharedPtr obj = (*i).lock();
        if (obj && obj->hasHint())
        {
            objectWithHint = obj;
            break;
        }
    }

    if (!objectWithHint)
    {
        return;
    }

    WindowSharedPtr w(m_hintPopup.expired() ?
                      WindowSharedPtr(new Window()) : m_hintPopup.lock());
    m_hintPopup = w;

    w->setHorizontalAlign(Window::HorizontalAlign::CENTER);
    w->setVerticalAlign(Window::VerticalAlign::BOTTOM);
    //w->setBorderWidth(1, 0);
    w->clear();

    objectWithHint->printHint(w.get());

    WindowManager::get().popup(w, 5);
}
示例#2
0
void Hero::takeAll()
{
    ObjectWeakPtrs objects;
    if (Simulator::get().listObjectsAt(
            getX(),
            getY(),
            getZ(),
            &objects))
    {
        ItemSharedPtrs items;
        std::for_each(
            objects.begin(), objects.end(), [&items](const ObjectWeakPtr& o)
            {
                ObjectSharedPtr object = o.lock();
                if (object->getObjectType() & OBJECT_TYPE_CHARACTER)
                {
                    Character* target = (Character*)object.get();
                    if (target->getHp() == 0)
                    {
                        items.reserve(items.size() + target->getItems().size());
                        items.insert(items.end(), target->getItems().begin(), target->getItems().end());
                        target->removeAllItems();
                    }
                }
                else if (object->getObjectType() & OBJECT_TYPE_CHEST)
                {
                    Chest* target = (Chest*)object.get();
                    items.reserve(items.size() + target->getItems().size());
                    items.insert(items.end(), target->getItems().begin(), target->getItems().end());
                    target->removeAllItems();
                }
            });

        if (!items.empty())
        {
            WindowSharedPtr w(new Window());
            w->setHorizontalAlign(Window::HorizontalAlign::CENTER);
            w->setVerticalAlign(Window::VerticalAlign::BOTTOM);
            w->setTitle("Added To Inventory");
            w->setMaxWidth(50);

            bool first = true;
            for_each(items.begin(), items.end(),
                     [w, &first] (const ItemSharedPtr& item)
                     {
                         if (!first)
                         {
                             w->printEndLine();
                         }
                         first = false;
                         w->print(Colors::WHITE(), item->getName());
                     });

            WindowManager::get().popup(w, 5);

            addItems(items);
        }
    }
}
	RenderObjectData::RenderObjectData(const ObjectSharedPtr &object,
		const BitSet64 visibility_mask): m_object(object),
		m_visibility_mask(visibility_mask), m_transparency(0.0f),
		m_distance(0.0f),
		m_occlusion_culling(std::numeric_limits<Uint32>::max()),
		m_lod(0), m_blend(bt_alpha_transparency_source_value)
	{
		m_transparency = object->get_transparency();
		m_blend = object->get_blend();
		m_blend_mask = object->get_blend_mask();
	}
示例#4
0
      bool Group::isEquivalent( ObjectSharedPtr const& object, bool ignoreNames, bool deepCompare ) const
      {
        if ( object.get() == this )
        {
          return( true );
        }

        bool equi = std::dynamic_pointer_cast<Group>(object) && Node::isEquivalent( object, ignoreNames, deepCompare );
        if ( equi )
        {
          GroupSharedPtr const& g = std::static_pointer_cast<Group>(object);
          equi =   ( m_children.size()   == g->m_children.size() )
                && ( m_clipPlanes.size() == g->m_clipPlanes.size() );
          if ( deepCompare )
          {
            for ( ChildrenContainer::const_iterator lhsit = m_children.begin() ; equi && lhsit != m_children.end() ; ++lhsit )
            {
              bool found = false;
              for ( ChildrenContainer::const_iterator rhsit = g->m_children.begin() ; !found && rhsit != g->m_children.end() ; ++rhsit )
              {
                found = (*lhsit)->isEquivalent( *rhsit, ignoreNames, true );
              }
              equi = found;
            }
            for ( ClipPlaneContainer::const_iterator lhsit = m_clipPlanes.begin() ; equi && lhsit != m_clipPlanes.end() ; ++lhsit )
            {
              bool found = false;
              for ( ClipPlaneContainer::const_iterator rhsit = g->m_clipPlanes.begin() ; !found && rhsit != g->m_clipPlanes.end() ; ++rhsit )
              {
                found = (*lhsit)->isEquivalent( *rhsit, ignoreNames, true );
              }
              equi = found;
            }
          }
          else
          {
            for ( ChildrenContainer::const_iterator lhsit = m_children.begin() ; equi && lhsit != m_children.end() ; ++lhsit )
            {
              bool found = false;
              for ( ChildrenContainer::const_iterator rhsit = g->m_children.begin() ; !found && rhsit != g->m_children.end() ; ++rhsit )
              {
                found = ( *lhsit == *rhsit );
              }
              equi = found;
            }
            for ( ClipPlaneContainer::const_iterator lhsit = m_clipPlanes.begin() ; equi && lhsit != m_clipPlanes.end() ; ++lhsit )
            {
              bool found = false;
              for ( ClipPlaneContainer::const_iterator rhsit = g->m_clipPlanes.begin() ; !found && rhsit != g->m_clipPlanes.end() ; ++rhsit )
              {
                found = ( *lhsit == *rhsit );
              }
              equi = found;
            }
          }
        }
        return( equi );
      }
示例#5
0
void Weapon::use(Direction dir)
{
    if (getOwner() && getOwner()->getObjectType() & Object::OBJECT_TYPE_CHARACTER)
    {
        Character* owner = (Character*)getOwner();

        m_dir = dir;
        show();

        float dx, dy;
        getDeltas(dx, dy);

        ObjectWeakPtrs objects;
        if (Simulator::get().listObjectsAt(
                    owner->getX() + dx,
                    owner->getY() + dy,
                    owner->getZ(),
                    &objects))
        {
            std::for_each(
                objects.begin(), objects.end(),
                [this, owner](const ObjectWeakPtr& o)
            {
                ObjectSharedPtr object = o.lock();
                if (object->getObjectType() & Object::OBJECT_TYPE_CHARACTER)
                {
                    int damage = Math::ceilRandom(m_damage);

                    Character* target = (Character*)object.get();

                    Math::clamp(damage, 0, target->getHp());
                    target->onReceiveHit(owner, damage);
                    owner->onGiveHit(target, damage);
                }
            });
        }
    }
}
示例#6
0
      bool Billboard::isEquivalent( ObjectSharedPtr const& object, bool ignoreNames, bool deepCompare ) const
      {
        if ( object.get() == this )
        {
          return( true );
        }

        bool equi = std::dynamic_pointer_cast<Billboard>(object) && Group::isEquivalent( object, ignoreNames, deepCompare );
        if ( equi )
        {
          BillboardSharedPtr const& b = std::static_pointer_cast<Billboard>(object);
          equi = ( m_alignment == b->m_alignment )
              && ( ( m_alignment != Alignment::AXIS ) || ( m_rotationAxis == b->m_rotationAxis ) );
        }
        return( equi );
      }
示例#7
0
      bool VertexAttributeSet::isEquivalent( ObjectSharedPtr const& object, bool ignoreNames, bool deepCompare ) const
      {
        if ( object.get() == this )
        {
          return( true );
        }

        bool equi = std::dynamic_pointer_cast<VertexAttributeSet>(object) && Object::isEquivalent( object, ignoreNames, deepCompare );
        if ( equi )
        {
          VertexAttributeSetSharedPtr vas = std::static_pointer_cast<VertexAttributeSet>(object);

          equi = ( m_vattribs.size() == vas->m_vattribs.size() );
          for ( AttributeContainer::const_iterator thisit = m_vattribs.begin(), thatit = vas->m_vattribs.begin()
              ; equi && ( thisit != m_vattribs.end() ) && ( thatit != vas->m_vattribs.end() )
              ; ++thisit, ++thatit )
          {
            equi = (thisit->first == thatit->first)
                && (thisit->second.getVertexDataBytes() == thatit->second.getVertexDataBytes())
                && (thisit->second.getVertexDataCount() == thatit->second.getVertexDataCount())
                && (thisit->second.getVertexDataOffsetInBytes() == thatit->second.getVertexDataOffsetInBytes())
                && (thisit->second.getVertexDataSize() == thatit->second.getVertexDataSize())
                && (thisit->second.getVertexDataStrideInBytes() == thatit->second.getVertexDataStrideInBytes())
                && (thisit->second.getVertexDataType() == thatit->second.getVertexDataType());
          }
          if ( equi )
          {
            for ( AttributeContainer::const_iterator thisit = m_vattribs.begin(), thatit = vas->m_vattribs.begin()
                ; equi && thisit != m_vattribs.end() && thatit != vas->m_vattribs.end()
                ; ++thisit, ++thatit )
            {
              equi = (thisit->second.getBuffer() == thatit->second.getBuffer())
                || (deepCompare && thisit->second.getBuffer()->isEquivalent(thatit->second.getBuffer(), ignoreNames, deepCompare));
            }
          }
        }
        return( equi );
      }
示例#8
0
bool CommandReplaceItem::doReplace( SceneTreeItem * oldChild, SceneTreeItem * newChild )
{
  switch( m_parent->getObject()->getObjectCode() )
  {
    case ObjectCode::GEO_NODE :
      DP_ASSERT(std::static_pointer_cast<GeoNode>(m_parent->getObject())->getMaterialPipeline() == std::static_pointer_cast<dp::sg::core::PipelineData>(oldChild->getObject()));
      if ( std::dynamic_pointer_cast<dp::sg::core::PipelineData>(newChild->getObject()) )
      {
        std::static_pointer_cast<GeoNode>(m_parent->getObject())->setMaterialPipeline(std::static_pointer_cast<dp::sg::core::PipelineData>(newChild->getObject()));
      }
      else
      {
        DP_ASSERT( std::dynamic_pointer_cast<Primitive>(m_newChild->getObject()) );
        std::static_pointer_cast<GeoNode>(m_parent->getObject())->setPrimitive(std::static_pointer_cast<Primitive>(newChild->getObject()));
      }
      break;
    case ObjectCode::GROUP :
    case ObjectCode::LOD :
    case ObjectCode::SWITCH :
    case ObjectCode::TRANSFORM :
    case ObjectCode::BILLBOARD :
      {
        GroupSharedPtr g = std::static_pointer_cast<Group>(m_parent->getObject());
        if ( std::dynamic_pointer_cast<Node>(newChild->getObject()) )
        {
          DP_ASSERT(g->findChild(g->beginChildren(), std::static_pointer_cast<Node>(oldChild->getObject())) != g->endChildren());
          g->replaceChild(std::static_pointer_cast<Node>(newChild->getObject()), std::static_pointer_cast<Node>(oldChild->getObject()));
        }
        else
        {
          DP_ASSERT( std::dynamic_pointer_cast<ClipPlane>(newChild->getObject()) );
          DP_ASSERT( g->findClipPlane( std::static_pointer_cast<ClipPlane>(oldChild->getObject()) ) != g->endClipPlanes() );
          g->removeClipPlane(std::static_pointer_cast<ClipPlane>(oldChild->getObject()));
          g->addClipPlane(std::static_pointer_cast<ClipPlane>(newChild->getObject()));
        }
      }
      break;
    case ObjectCode::PRIMITIVE :
      if ( std::dynamic_pointer_cast<IndexSet>(newChild->getObject()) )
      {
        std::static_pointer_cast<Primitive>(m_parent->getObject())->setIndexSet(std::static_pointer_cast<IndexSet>(newChild->getObject()));
      }
      else
      {
        DP_ASSERT( std::dynamic_pointer_cast<VertexAttributeSet>(newChild->getObject()) );
        std::static_pointer_cast<Primitive>(m_parent->getObject())->setVertexAttributeSet(std::static_pointer_cast<VertexAttributeSet>(newChild->getObject()));
      }
      break;
    case ObjectCode::PARAMETER_GROUP_DATA :
      DP_ASSERT( newChild->getObject()->getObjectCode() == ObjectCode::SAMPLER );
      {
        ParameterGroupDataSharedPtr pgd = std::static_pointer_cast<ParameterGroupData>(m_parent->getObject());
        const dp::fx::ParameterGroupSpecSharedPtr & pgs = pgd->getParameterGroupSpec();
        dp::fx::ParameterGroupSpec::iterator it = pgs->findParameterSpec(std::static_pointer_cast<Sampler>(newChild->getObject())->getName());
        DP_ASSERT( it != pgs->endParameterSpecs() );
        DP_ASSERT(pgs->findParameterSpec(std::static_pointer_cast<Sampler>(oldChild->getObject())->getName()) == it);
        pgd->setParameter(it, std::static_pointer_cast<Sampler>(newChild->getObject()));
      }
      break;
    case ObjectCode::PARALLEL_CAMERA :
    case ObjectCode::PERSPECTIVE_CAMERA :
    case ObjectCode::MATRIX_CAMERA :
      DP_ASSERT( m_newChild->getObject()->getObjectCode() == ObjectCode::LIGHT_SOURCE );
      std::static_pointer_cast<Camera>(m_parent->getObject())->replaceHeadLight(std::static_pointer_cast<LightSource>(newChild->getObject()), std::static_pointer_cast<LightSource>(oldChild->getObject()));
      break;
    case ObjectCode::PIPELINE_DATA :
      DP_ASSERT( std::dynamic_pointer_cast<ParameterGroupData>(newChild->getObject()) );
      DP_ASSERT(std::static_pointer_cast<ParameterGroupData>(newChild->getObject())->getParameterGroupSpec() == std::static_pointer_cast<ParameterGroupData>(oldChild->getObject())->getParameterGroupSpec());
      std::static_pointer_cast<dp::sg::core::PipelineData>(m_parent->getObject())->setParameterGroupData(std::static_pointer_cast<ParameterGroupData>(newChild->getObject()));
      break;
    case ObjectCode::SCENE :
      if ( std::dynamic_pointer_cast<Camera>(m_newChild->getObject()) )
      {
        SceneSharedPtr s = std::static_pointer_cast<Scene>(m_parent->getObject());
        s->removeCamera(std::static_pointer_cast<Camera>(oldChild->getObject()));
        s->addCamera(std::static_pointer_cast<Camera>(newChild->getObject()));
      }
      else
      {
        DP_ASSERT( std::dynamic_pointer_cast<Node>(newChild->getObject()) );
        std::static_pointer_cast<Scene>(m_parent->getObject())->setRootNode(std::static_pointer_cast<Node>(newChild->getObject()));
      }
      break;
    default :
      DP_ASSERT( false );
      break;
  }

  if ( m_parent->isExpanded() )
  {
    int index = m_parent->indexOfChild( oldChild );
    DP_ASSERT( 0 <= index );
    m_parent->takeChild( index );
    m_parent->insertChild( index, newChild );
    m_holdsOldChild = !m_holdsOldChild;
  }
  m_parent->setChildIndicatorPolicy();
  GetApp()->outputStatistics();

  ObjectSharedPtr s = std::static_pointer_cast<Object>(oldChild->getObject());
  if ( s->isAttached( m_observer ) )
  {
    s->detach( m_observer );
    std::static_pointer_cast<Object>(newChild->getObject())->attach(m_observer);
  }

  return true;
}
      bool TriangulateTraverser::optimizationAllowed( ObjectSharedPtr const& obj )
      {
        DP_ASSERT( obj != NULL );

        return (obj->getHints( Object::DP_SG_HINT_DYNAMIC ) == 0);
      }