void SceneSyncState::AddPendingEntity(entity_id_t id)
{
    if (!isServer_)
        return;

    if (scene_.expired())
        return;
    ScenePtr scenePtr = scene_.lock();
    if (!scenePtr.get())
    {
        LogError("SceneSyncState::FillPendingComponents(id): Scene is null!");
        return;
    }

    EntityPtr entityPtr = scenePtr->GetEntity(id);
    if (!entityPtr.get())
    {
        LogError("SceneSyncState::FillPendingComponents(id): Entity is null, cannot fill components!");
        return;
    }
    if (entityPtr->Components().empty())
        return;
        
    if (!HasPendingEntity(id))
        pendingEntities_.push_back(id);
}
Beispiel #2
0
 void Test::Update(float dt)
 {
   switch (DemoToUse)
   {
   case(Demo::Pretzel) :
     PretzelDemo(dt);
     break;
   case(Demo::FireBall) :
     FireBallDemo(dt);
     break;
   case Demo::Explosion:
     ExplosionDemo(200);
     break;
   default:
     break;
   }
   
   // This is wrapped in a try catch block because it's possible the entity acquired by name doesn't have the necessary components.
   // If that is the case, the try block will encounter and exception, that gets handled by just ignoring the operation and moving on.
   try
   {
     EntityPtr mouse = ENGINE->GetActiveSpace()->GetEntityByName("Mouse");
     mouse->GET_COMPONENT(Transform)->position = GETSYS(WindowSDL)->GetMousePosition();
     mouse->GET_COMPONENT(Transform)->scale = { 10.f, 10.f };
   }
   catch (...)
   {
     
   }
 }
vector<EntityPtr> WorldEntityManager::FindEntitiesInRange(unsigned long componentMask, Vector3 center, float range)
{
	SyncRegions(center, m_entityRegionWidth);
	vector<EntityPtr> results;
	Rectangle searchArea = Rectangle(center.x - range, center.z - range, range * 2, range * 2);
	// Filter by position
	for (auto & entityID : m_quadTree.Find(searchArea)) {
		EntityPtr entity;
		if (Find(entityID, entity)) {
			// Filter by mask
			if (entity->HasComponents(componentMask)) {
				results.push_back(entity);
			}
		}
	}
	return results;
	/*auto entities = FindEntities(componentMask | ComponentMask("Position"));
	vector<EntityPtr> finalSet;
	for (auto & entity : entities) {
		if (Vector3::Distance(entity->GetComponent<Components::Position>("Position")->Pos, center) <= range) {
			finalSet.push_back(entity);
		}
	}
	return finalSet;*/
}
Beispiel #4
0
    void Test::SendMsg(EntityPtr e1, EntityPtr e2, Message::Message message)
    {
      EntityPtr camera = ENGINE->GetSpace("Particle Demo")->GetCamera();
      switch (message)
      {
      case(Message::MV_Up) :
        camera->GET_COMPONENT(Transform)->position.y += 1000.f * ENGINE->Getdt();
        break;
      case(Message::MV_Down) :
        camera->GET_COMPONENT(Transform)->position.y -= 1000.f * ENGINE->Getdt();
        break;
      case(Message::MV_Left) :
        camera->GET_COMPONENT(Transform)->position.x -= 1000.f * ENGINE->Getdt();
        break;
      case(Message::MV_Right) :
        camera->GET_COMPONENT(Transform)->position.x += 1000.f * ENGINE->Getdt();
        break;

      case(Message::MV_BackButton) :
        ENGINE->PushGamestate(PauseMenuPtr(new PauseMenu()));
        break;

      case(Message::MV_PopGamestate) :
        ENGINE->PopGamestate();
        break;

      default:
        break;
      }
    }
Beispiel #5
0
void EntityPalette::Destroy( EntityPtr entity )
{
	entity->Remove();
	EntityMap::iterator it = mEntites.find(entity->GetName());
	if (it != mEntites.end())
		mEntites.erase(it);
}
Beispiel #6
0
void	Move::OnUpdate(float elapsedTime)
{
    EntityPtr e = GetEntity();

    float ds = 1.0f;

    Vector2 v(cos(mAngle) * mSpeed * ds , sin(mAngle) * mSpeed * ds);

    b2Body* body = ((Box2DBody*)e->GetBody())->GetBox2DBody();

    //body->SetLinearVelocity(v);

    v.x *= body->GetMass() * 10;
    v.y *= body->GetMass() * 10;
    body->ApplyForce(v, e->GetPosition());

    Vector2 cv = body->GetLinearVelocity();
    float fv = abs(cv.Length());
    if (fv > abs(mSpeed) && fv > 0.00001)
    {
        cv.x *= abs(mSpeed) / fv;
        cv.y *= abs(mSpeed) / fv;
        body->SetLinearVelocity(cv);
    }
}
Beispiel #7
0
void EntityManager::HandlePacket(Packets::Inbound::SpawnGlobalEntityPacket* packet) {
    EntityId eid = packet->GetEntityId();
    EntityPtr entity = std::make_shared<Entity>(eid);

    m_Entities[eid] = entity;
    entity->SetPosition(packet->GetPosition());
}
Beispiel #8
0
EntityListWidgetItem *ECEditorWindow::AddEntity(entity_id_t entity_id, bool udpate_ui)
{
    EntityListWidgetItem *item = 0;
    PROFILE(ECEditorWindow_AddEntity);
    if (entityList)
    {
        entityList->blockSignals(true);
        //If entity don't have EC_Name then entity_name is same as it's id.
        QString entity_name = QString::number(entity_id);
        EntityPtr entity = framework->Scene()->MainCameraScene()->GetEntity(entity_id);
        if (entity && entity->GetComponent<EC_Name>())
            entity_name.append(" " + entity->Name());

        int row = AddUniqueListItem(entity, entityList, entity_name);
        item = dynamic_cast<EntityListWidgetItem *>(entityList->item(row));
        assert(item);

        entityList->blockSignals(false);
    }

    if (udpate_ui)
        RefreshPropertyBrowser();

    return item;
}
Beispiel #9
0
AssetClassPtr MeshAssetFactory::Create( const Helium::Path& path )
{
    Helium::Path assetPath = path;
    assetPath.ReplaceExtension( TXT( "entity.nrb" ) );

    if ( assetPath.Exists() )
    {
        return AssetClass::LoadAssetClass( assetPath );
    }

    EntityPtr entity = new Entity();
    entity->SetPath( path.Filename() ); // we're dropping this guy relative to the data file

    MeshProcessingComponentPtr meshProcessingComponent = new MeshProcessingComponent();
    entity->SetComponent( meshProcessingComponent );

    try
    {
        Reflect::Archive::ToFile( entity, assetPath );
        entity->SetSerializationPath( assetPath );
    }
    catch( Helium::Exception& )
    {
        delete entity;
        return NULL;
    }

    return entity;
}
Beispiel #10
0
/// Create an entity within this slice and store it in the entity list.
///
/// @param[in] pType                 Type of entity to create.
/// @param[in] rPosition             EntityDefinition position.
/// @param[in] rRotation             EntityDefinition rotation.
/// @param[in] rScale                EntityDefinition scale.
/// @param[in] pTemplate             Template from which to create the entity.
/// @param[in] name                  Object name to assign to the entity, or a null name to automatically generate a
///                                  name based on the entity type.
/// @param[in] bAssignInstanceIndex  True to assign an instance index to the entity, false to not include an
///                                  instance index.
///
/// @return  Pointer to the entity instance if created successfully, null if not.
///
/// @see DestroyEntity()
Entity* Slice::CreateEntity(EntityDefinition *pEntityDefinition, ParameterSet *pParameterSet)
{
    HELIUM_ASSERT( pEntityDefinition );
    if( !pEntityDefinition )
    {
        HELIUM_TRACE( TraceLevels::Error, TXT( "Slice::CreateEntity(): EntityDefinition is NULL.\n" ) );
        return NULL;
    }

    EntityPtr entity = pEntityDefinition->CreateEntity();
    HELIUM_ASSERT( entity.Get() );
    if (!entity)
    {
        HELIUM_TRACE( TraceLevels::Error, TXT( "Slice::CreateEntity(): Call to EntityDefinition::CreateEntity failed.\n" ) );
        return NULL;
    }
    
    size_t sliceIndex = m_entities.Push( entity );
    HELIUM_ASSERT( IsValid( sliceIndex ) );
    entity->SetSliceInfo( this, sliceIndex );

    pEntityDefinition->FinalizeEntity(entity, pParameterSet);

    return entity.Get();
}
bool SceneSyncState::FillRequest(entity_id_t id)
{
    changeRequest_.Reset(id);

    if (scene_.expired())
        return false;
    ScenePtr scenePtr = scene_.lock();
    if (!scenePtr.get())
    {
        LogError("SceneSyncState::FillRequest(id): Scene is null!");
        return false;
    }

    EntityPtr entityPtr = scenePtr->GetEntity(id);
    if (!entityPtr.get())
        return false;

    // We trust the SyncManager mechanisms to stop local entities from ever getting here.
    // Print anyways if something starts to leak so at least we notice it here.
    if (!entityPtr->IsReplicated())
        LogError("SceneSyncState::FillRequest(id): Entity " + QString::number(id) + " should not be replicated!");
    changeRequest_.SetEntity(entityPtr.get());

    return true;
}
static duk_ret_t EntityReference_LookupParent_Entity(duk_context* ctx)
{
    EntityReference* thisObj = GetThisValueObject<EntityReference>(ctx, EntityReference_ID);
    Entity* entity = GetWeakObject<Entity>(ctx, 0);
    EntityPtr ret = thisObj->LookupParent(entity);
    PushWeakObject(ctx, ret.Get());
    return 1;
}
Beispiel #13
0
EntityPtr Entity::clone() const
{
    EntityPtr cloned = this->createCloneInstance();
    cloned->copyComponents(this);
    cloned->copyProperties(this);

    return cloned;
}
static duk_ret_t EntityReference_Lookup_Scene(duk_context* ctx)
{
    EntityReference* thisObj = GetThisValueObject<EntityReference>(ctx, EntityReference_ID);
    Scene* scene = GetWeakObject<Scene>(ctx, 0);
    EntityPtr ret = thisObj->Lookup(scene);
    PushWeakObject(ctx, ret.Get());
    return 1;
}
Beispiel #15
0
void EntityManager::HandlePacket(Packets::Inbound::SpawnMobPacket* packet) {
    EntityId eid = packet->GetEntityId();
    EntityPtr entity = std::make_shared<Entity>(eid);

    m_Entities[eid] = entity;
    entity->SetPosition(Vector3d(packet->GetX(), packet->GetY(), packet->GetZ()));

    NotifyListeners(&EntityListener::OnEntitySpawn, entity);
}
EntityItem::EntityItem(const EntityPtr &entity, EntityGroupItem *parentItem) :
    QTreeWidgetItem(parentItem),
    ptr(entity),
    id(entity->Id())
{
    if (parentItem)
        parentItem->AddEntityItem(this);

    SetText(entity.get());
}
Beispiel #17
0
EntityItem::EntityItem(const EntityPtr &entity, EntityGroupItem *parent) :
    ptr(entity), id(entity->Id()), parentItem(parent)
{
    if (parentItem)
    {
        parentItem->numberOfEntities++;
        parentItem->UpdateText();
    }

    SetText(entity.get());
}
Beispiel #18
0
void TagManager::remove(EntityPtr e)
{
    std::map<EntityId, TagId>::iterator enti =
        tag_by_entity_.find(e->get_id());

    if( enti != tag_by_entity_.end() )
    {
        tag_by_entity_.erase(e->get_id());
        entity_by_tag_.erase(enti->second);
    }
}
Beispiel #19
0
void EntityManager::HandlePacket(Packets::Inbound::SpawnObjectPacket* packet) {
    EntityId eid = packet->GetEntityId();
    EntityPtr entity = std::make_shared<Entity>(eid);

    m_Entities[eid] = entity;
    entity->SetPosition(ToVector3d(packet->GetPosition()));
    entity->SetYaw(packet->GetYaw() / 256.0f * TAU);
    entity->SetPitch(packet->GetPitch() / 256.0f * TAU);

    NotifyListeners(&EntityListener::OnObjectSpawn, entity);
}
Beispiel #20
0
void	Move::OnDone()
{
    if (mChannel)
        Engine::GetSingleton()->GetSoundSystem()->StopChannel(mChannel);

    EntityPtr e = GetEntity();
    Vector2 v(0.0f, 0.0f);

    if (e != 0)
        e->GetBody()->SetLinearVelocity(v);
}
void Entity::Render( float ticks ) throw(std::exception)
{
    DoUpdate(ticks);
    glPushMatrix();
    glMultMatrixf( GetRenderState()->GetMatrix() );

    uint32_t flags = GetRenderState()->GetFlags();

    int gl_blend_src(0), gl_blend_dst(0);
    int alpha_enabled;
    glGetIntegerv(GL_ALPHA_TEST, &alpha_enabled);
    if (!alpha_enabled && (flags & RenderState::ALPHA_F) )
    {
        glGetIntegerv(GL_BLEND_SRC, &gl_blend_src);
        glGetIntegerv(GL_BLEND_DST, &gl_blend_dst);
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_ALPHA_TEST);
    }
    else if (alpha_enabled && (flags & RenderState::ALPHA_F) == 0 )
    {
        glDisable(GL_ALPHA_TEST);
    }
    int blend_enabled;
    glGetIntegerv(GL_BLEND, &blend_enabled);
    if (!blend_enabled && (flags & RenderState::BLEND_F) )
    {
        glEnable(GL_BLEND);
    }
    else if ( blend_enabled && (flags & RenderState::BLEND_F) == 0 )
    {
        glDisable(GL_BLEND);
    }

    for( auto it = m_RenderList.begin(); it != m_RenderList.end(); ) {
        EntityPtr entity = *it;
        if ( entity->AreFlagsSet( Entity::F_ENABLE ) ) {
            entity->Render( ticks );
        }
        if ( entity->AreFlagsSet( Entity::F_DELETE ) ) {
            it = m_RenderList.erase( it );
            continue;
        }
        ++it;
    }
    DoRender();

    if (!alpha_enabled && (flags & RenderState::ALPHA_F) )
    {
        glBlendFunc( gl_blend_src, gl_blend_dst);
    }
    glPopMatrix();
}
	Rocket::Core::DecoratorDataHandle DynamicEntityDecorator::GenerateElementData(Rocket::Core::Element* element)
	{
		std::string entityName = std::string(element->GetAttribute("entity_name", Rocket::Core::String()).CString());

		EntityPtr entity = m_EntityManager->GetEntity(entityName);
		if (entity)
		{
			m_UsedEntities.insert(entity);
			return (Rocket::Core::DecoratorDataHandle)entity.get();
		}

		return 0;
	}
Beispiel #23
0
void Entity::Render( int pass ) throw(std::exception)
{
    glPushMatrix();
    glMultMatrixf( GetRenderState()->GetMatrix() );

    uint32_t flags = GetRenderState()->GetFlags();

    int glBlendSrc(0), glBlendDst(0);
    int alphaEnabled;
    glGetIntegerv(GL_ALPHA_TEST, &alphaEnabled);
    if (!alphaEnabled && (flags & RenderState::ALPHA_F) )
    {
        glGetIntegerv(GL_BLEND_SRC, &glBlendSrc);
        glGetIntegerv(GL_BLEND_DST, &glBlendDst);
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_ALPHA_TEST);
    }
    else if (alphaEnabled && (flags & RenderState::ALPHA_F) == 0 )
    {
        glDisable(GL_ALPHA_TEST);
    }
    int blendEnabled;
    glGetIntegerv(GL_BLEND, &blendEnabled);
    if (!blendEnabled && (flags & RenderState::BLEND_F) )
    {
        glEnable(GL_BLEND);
    }
    else if ( blendEnabled && (flags & RenderState::BLEND_F) == 0 )
    {
        glDisable(GL_BLEND);
    }

    // render all children
    for( auto it = m_RenderList.begin(); it != m_RenderList.end(); ) {
        EntityPtr entity = *it;
        if ( entity->IsFlagSet( Entity::F_ENABLE|Entity::F_VISIBLE ) &&
            !entity->IsFlagSet( Entity::F_DELETE ) )
        {
            // don't bother rendering if we are marked for deletion
            entity->Render( pass );
        }
        ++it;
    }
    DoRender( pass );

    if (!alphaEnabled && (flags & RenderState::ALPHA_F) )
    {
        glBlendFunc( glBlendSrc, glBlendDst);
    }
    glPopMatrix();
}
Beispiel #24
0
void Entity::CheckDestroy( ) throw(std::exception)
{
    for( auto it = m_RenderList.begin(); it != m_RenderList.end(); ) {
        EntityPtr entity = *it;
        // Process children first
        entity->CheckDestroy();
        // removed from list
        if ( entity->IsFlagSet( Entity::F_DELETE ) ) {
            it = m_RenderList.erase( it );
            continue;
        }
        ++it;
    }
}
Beispiel #25
0
Light::Light(const EntityPtr &owner, const RenderSystemPtr &render_system, const std::string &name)
: Component(owner, name)
, render_system(render_system)
{
	world_matrix_property = owner->add(GM_PROPERTY_WORLD_MATRIX, glm::mat4(1));
	radius_property = owner->add(GM_PROPERTY_RADIUS, 0.0f);
	material_color_diffuse_property = owner->add(GM_PROPERTY_MATERIAL_COLOR_DIFFUSE, glm::vec3(1));
	material_color_specular_property = owner->add(GM_PROPERTY_MATERIAL_COLOR_SPECULAR, glm::vec3(1));
	material_color_ambient_property = owner->add(GM_PROPERTY_MATERIAL_COLOR_AMBIENT, glm::vec3(1));
	activated_property = owner->add<bool>(GM_PROPERTY_ACTIVATED, true);
	shadow_caster_property = owner->add<bool>(GM_PROPERTY_SHADOW_CASTER, false);

	render_system->add_light(this);
}
void Buffered::Render( float ticks )
{
    // backup viewport
    GLint vp[4];
    glGetIntegerv( GL_VIEWPORT, vp );
    GLfloat depth[2];
    glGetFloatv( GL_DEPTH_RANGE, depth );

    // backup projection matrix for internal storage
    Matrix modelview;
    glGetFloatv( GL_MODELVIEW_MATRIX, (float*)modelview );
    Matrix projection;
    glGetFloatv( GL_PROJECTION_MATRIX, (float*)projection );

    m_FrameBuffer.Enable();

    // background color
    glClearColor( 1,1,1,1 );
    // clear buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    for( auto it = m_RenderList.begin(); it != m_RenderList.end(); ) {
        EntityPtr entity = *it;
        if ( entity->AreFlagsSet( Entity::F_ENABLE ) ) {
            entity->Render(ticks);
        }
        if ( entity->AreFlagsSet( Entity::F_DELETE ) ) {
            it = m_RenderList.erase( it );
            continue;
        }
        ++it;
    }
    m_FrameBuffer.Disable();

    // restore view port
    glViewport( vp[0], vp[1], vp[2], vp[3]);
    glMatrixMode(GL_PROJECTION);
    glLoadMatrixf( projection );
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixf( modelview );

    DoUpdate( ticks );

    // render local list into texture
    glPushMatrix();
    glMultMatrixf(GetRenderState()->GetMatrix());
    Cube::DoRender();
    glPopMatrix();
}
Beispiel #27
0
void EntityManager::RegisterEntity(EntityPtr _entity)
{
    _entity->SetID(m_id_count);
    m_entities.push_back(_entity);
    
    m_id_count++;
}
Beispiel #28
0
bool frts::HarvestJob::checkSpecialRequirements(const EntityPtr& entity, const SharedManagerPtr& shared) const
{
    assert(entity != nullptr);
    assert(shared != nullptr);

    // Is the entity movable?
    if (!entity->hasComponent(shared->makeId(ComponentIds::movable())))
    {
        return false;
    }

    // Does a free neighbor exist?
    auto rm = getDataValue<RegionManager>(shared, ModelIds::regionManager());
    auto pos = rm->getPos(toHarvest, shared);

    // Null means that toHarvest is already removed. This is handled in the execution so let's just
    // go there.
    if (pos != nullptr)
    {
        auto blockedBy = getComponent<BlockedBy>(shared->makeId(ComponentIds::blockedBy()), entity);
        if(rm->findFreeNeighbors(pos, blockedBy, true, shared).empty())
        {
            return false;
        }
    }

    // Nope everything ok.
    return true;
}
Beispiel #29
0
void World::addEntity(EntityPtr entity) {
    assert(entity != nullptr);
    assert(entity->getWorld() == nullptr);
    assert(std::find(newEntityList.begin(), newEntityList.end(), entity) == newEntityList.end() && "This entity is being added (queued)!");
    assert(std::find(activeEntityList.begin(), activeEntityList.end(), entity) == activeEntityList.end() && "This entity has already been added!");
    
    newEntityList.push_back(entity);
}
Beispiel #30
0
void World::removeEntity(EntityPtr entity) {
    assert(entity != nullptr);
    assert(entity->getWorld() == shared_from_this());
    assert(std::find(deadEntityList.begin(), deadEntityList.end(), entity) == deadEntityList.end() && "This entity is being removed (queued)!");
    assert(std::find(activeEntityList.begin(), activeEntityList.end(), entity) != activeEntityList.end() && "This entity doesn't exist in this world!");
    
    deadEntityList.push_back(entity);
}