コード例 #1
0
EntityPtr EntityFactory::createAnimatedEntity(const string& path, float width, float height) {
	EntitySystemPtr entitySystem = makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY));
	EntityPtr entity(GCC_NEW Entity());
	entitySystem->addEntity(entity);

	PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS));
	BodyPtr blockBody(GCC_NEW Body(0.0f, 0.0f, width, height));
	physicsSystem->registerBody(entity->id, blockBody);
	PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody));

	GraphicsSystemPtr graphicsSystem = makeShared(mSystemManager->getSystemByType<GraphicsSystem>(SystemType::GRAPHICS));
	TexturePtr texture(GCC_NEW Texture(""));
	shared_ptr<TextureDrawable> textureDrawable(GCC_NEW TextureDrawable(texture));
	graphicsSystem->registerDrawable(entity->id, textureDrawable);
	DrawableComponentPtr drawableComponent(GCC_NEW DrawableComponent(entity->id, textureDrawable));

	AnimationSystemPtr animationSystem = makeShared(mSystemManager->getSystemByType<AnimationSystem>(SystemType::ANIMATION));
	AnimationSetPtr animationSet = animationSystem->createAnimationSet(path);
	AnimationHandlerPtr animationHandler(GCC_NEW AnimationHandler(textureDrawable, animationSet, animationSet->fps));
	animationSystem->registerAnimation(entity->id, animationHandler);
	AnimationComponentPtr animationComponent(GCC_NEW AnimationComponent(entity->id, animationHandler));

	InputSystemPtr inputSystem(makeShared(mSystemManager->getSystemByType<InputSystem>(SystemType::INPUT)));
	InputListenerPtr inputListener(GCC_NEW InputListener(entity->id));
	inputSystem->registerEventListener(inputListener);
	InputComponentPtr inputComponent(GCC_NEW InputComponent(entity->id, inputListener));

	entity->addComponent(ComponentPtr(physicsComponent));
	entity->addComponent(ComponentPtr(drawableComponent));
	entity->addComponent(ComponentPtr(animationComponent));
	entity->addComponent(ComponentPtr(inputComponent));

	return entity;
}
コード例 #2
0
EntityPtr EntityFactory::createTexturedEntity(const string& assetTag, float tx, float ty, float w, float h) {
	EntitySystemPtr entitySystem = makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY));
	EntityPtr entity(GCC_NEW Entity());
	entitySystem->addEntity(entity);

	PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS));
	BodyPtr blockBody(GCC_NEW Body(0.0f, 0.0f, w, h));
	physicsSystem->registerBody(entity->id, blockBody);
	PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody));

	GraphicsSystemPtr graphicsSystem = makeShared(mSystemManager->getSystemByType<GraphicsSystem>(SystemType::GRAPHICS));
	TexturePtr texture(GCC_NEW Texture(assetTag, tx, ty, w, h));
	DrawablePtr textureDrawable(GCC_NEW TextureDrawable(texture));
	graphicsSystem->registerDrawable(entity->id, textureDrawable);
	DrawableComponentPtr drawableComponent(GCC_NEW DrawableComponent(entity->id, textureDrawable));

	InputSystemPtr inputSystem = makeShared(mSystemManager->getSystemByType<InputSystem>(SystemType::INPUT));
	InputListenerPtr inputListener(GCC_NEW InputListener(entity->id));
	inputSystem->registerEventListener(inputListener);
	InputComponentPtr inputComponent(GCC_NEW InputComponent(entity->id, inputListener));

	entity->addComponent(ComponentPtr(physicsComponent));
	entity->addComponent(ComponentPtr(drawableComponent));
	entity->addComponent(ComponentPtr(inputComponent));

	return entity;
}
コード例 #3
0
EntityPtr EntityFactory::createDefault() {
	EntitySystemPtr entitySystem = makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY));
	EntityPtr entity(GCC_NEW Entity());
	entitySystem->addEntity(entity);

	PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS));
	BodyPtr blockBody(GCC_NEW Body(0, 0, 16, 16));
	physicsSystem->registerBody(entity->id, blockBody);
	PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody));
	physicsComponent->setCollider(GCC_NEW Collider(0, 0, 16, 16));

	GraphicsSystemPtr graphicsSystem = makeShared(mSystemManager->getSystemByType<GraphicsSystem>(SystemType::GRAPHICS));
	DrawablePtr blockDrawable(GCC_NEW BlockDrawable(16, 16, 255, 0, 0, 255));
	graphicsSystem->registerDrawable(entity->id, blockDrawable);
	DrawableComponentPtr drawableComponent(GCC_NEW DrawableComponent(entity->id, blockDrawable));

	InputSystemPtr inputSystem = makeShared(mSystemManager->getSystemByType<InputSystem>(SystemType::INPUT));
	InputListenerPtr inputListener(GCC_NEW InputListener(entity->id));
	inputSystem->registerEventListener(inputListener);
	InputComponentPtr inputComponent(GCC_NEW InputComponent(entity->id, inputListener));

	entity->addComponent(ComponentPtr(physicsComponent));
	entity->addComponent(ComponentPtr(drawableComponent));
	entity->addComponent(ComponentPtr(inputComponent));

	return entity;
}
コード例 #4
0
ファイル: Entity.cpp プロジェクト: katik/naali
ComponentPtr Entity::Component(u32 typeId, const QString& name) const
{
    for (ComponentMap::const_iterator i = components_.begin(); i != components_.end(); ++i)
        if (i->second->TypeId() == typeId && i->second->Name() == name)
            return i->second;

    return ComponentPtr();
}
コード例 #5
0
ファイル: Entity.cpp プロジェクト: katik/naali
ComponentPtr Entity::Component(u32 typeId) const
{
    for (ComponentMap::const_iterator i = components_.begin(); i != components_.end(); ++i)
        if (i->second->TypeId() == typeId)
            return i->second;

    return ComponentPtr();
}
コード例 #6
0
ファイル: Entity.cpp プロジェクト: A-K/naali
    ComponentPtr Entity::GetComponent(uint type_hash) const
    {
        for (size_t i=0 ; i<components_.size() ; ++i)
            if (components_[i]->TypeNameHash() == type_hash)
                return components_[i];

        return ComponentPtr();
    }
コード例 #7
0
ファイル: Entity.cpp プロジェクト: A-K/naali
 ComponentPtr Entity::GetComponent(const IComponent *component) const
 {
     for (size_t i = 0; i < components_.size(); i++)
         if(component->TypeName() == components_[i]->TypeName() &&
            component->Name() == components_[i]->Name())
            return components_[i];
     return ComponentPtr();
 }
コード例 #8
0
ファイル: Entity.cpp プロジェクト: A-K/naali
    ComponentPtr Entity::GetComponent(const QString &type_name) const
    {
        for (size_t i=0 ; i<components_.size() ; ++i)
            if (components_[i]->TypeName() == type_name)
                return components_[i];

        return ComponentPtr();
    }
コード例 #9
0
ファイル: Entity.cpp プロジェクト: realXtend/tundra-urho3d
ComponentPtr Entity::Component(u32 typeId, const String& name) const
{
    for (ComponentMap::ConstIterator i = components_.Begin(); i != components_.End(); ++i)
        if (i->second_->TypeId() == typeId && i->second_->Name() == name)
            return i->second_;

    return ComponentPtr();
}
コード例 #10
0
ファイル: Entity.cpp プロジェクト: realXtend/tundra-urho3d
ComponentPtr Entity::Component(u32 typeId) const
{
    for (ComponentMap::ConstIterator i = components_.Begin(); i != components_.End(); ++i)
        if (i->second_->TypeId() == typeId)
            return i->second_;

    return ComponentPtr();
}
コード例 #11
0
ファイル: Entity.cpp プロジェクト: A-K/naali
    ComponentPtr Entity::GetComponent(uint type_hash, const QString& name) const
    {
        for (size_t i=0 ; i<components_.size() ; ++i)
            if ((components_[i]->TypeNameHash() == type_hash) && (components_[i]->Name() == name))
                return components_[i];

        return ComponentPtr();
    }
コード例 #12
0
ファイル: ComponentManager.cpp プロジェクト: A-K/naali
ComponentPtr ComponentManager::CreateComponent(const QString &type_name)
{
    ComponentFactoryMap::const_iterator iter = factories_.find(type_name);
    if (iter == factories_.end())
        return ComponentPtr();

    ComponentPtr component = (*iter->second.get())();
    return component;
}
コード例 #13
0
ファイル: ComponentManager.cpp プロジェクト: A-K/naali
ComponentPtr ComponentManager::CreateComponent(uint type_hash)
{
    ComponentFactoryHashMap::const_iterator iter = factories_hash_.find(type_hash);
    if (iter == factories_hash_.end())
        return ComponentPtr();

    ComponentPtr component = (*iter->second.get())();
    return component;
}
コード例 #14
0
ファイル: Component.cpp プロジェクト: DarkMagicCK/UKN
 ComponentPtr ComponentHolder::removeComponent(const MistString& name) {
     ComponentMap::iterator it = mComponents.find(name);
     if(it != mComponents.end()) {
         ComponentPtr comp = it->second;
         mComponents.erase(it);
         return comp;
     }
     return ComponentPtr();
 }
コード例 #15
0
ファイル: Entity.cpp プロジェクト: realXtend/tundra-urho3d
ComponentPtr Entity::Component(const String &type_name, const String& name) const
{
    const String cTypeName = IComponent::EnsureTypeNameWithoutPrefix(type_name);
    for (ComponentMap::ConstIterator i = components_.Begin(); i != components_.End(); ++i)
        if (i->second_->TypeName() == cTypeName && i->second_->Name() == name)
            return i->second_;

    return ComponentPtr();
}
コード例 #16
0
ファイル: ComponentManager.cpp プロジェクト: A-K/naali
ComponentPtr ComponentManager::CloneComponent(const ComponentPtr &component)
{
    ComponentFactoryMap::const_iterator iter = factories_.find(component->TypeName());
    if (iter == factories_.end())
        return ComponentPtr();

    ComponentPtr newComponent = (*iter->second.get())(component);
    return newComponent;
}
コード例 #17
0
EntityPtr EntityFactory::createFromSerialization(const string& path) {
	std::ifstream file(path);
	std::string line;
	std::string builder;
	while (std::getline(file, line)) {
		builder.append(line);
	}
	file.close();

	rapidjson::Document doc;
	doc.Parse(builder.c_str());

	EntitySystemPtr entitySystem = static_pointer_cast<EntitySystem>(mSystemManager->systems.at(SystemType::ENTITY));
	EntityPtr entity(GCC_NEW Entity());
	entitySystem->addEntity(entity);
	const rapidjson::Value& componentContainer = doc["componentContainer"];

	GraphicsSystemPtr graphicsSystem = static_pointer_cast<GraphicsSystem>(mSystemManager->systems.at(SystemType::GRAPHICS));
	PhysicsSystemPtr physicsSystem = static_pointer_cast<PhysicsSystem>(mSystemManager->systems.at(SystemType::PHYSICS));
	for (rapidjson::SizeType index = 0; index < componentContainer.Size(); index++) {
		const rapidjson::Value& component = componentContainer[index];
		ComponentType componentId = (ComponentType) component["componentId"].GetUint();

		if (componentId == ComponentType::DRAWABLE_COMPONENT) {
			DrawableComponentPtr comp(GCC_NEW DrawableComponent(entity->id, component));
			entity->addComponent(ComponentPtr(comp));
			graphicsSystem->registerDrawable(entity->id, makeShared(comp->getDrawable()));
		}
		else if (componentId == ComponentType::PHYSICS_COMPONENT) {
			PhysicsComponentPtr comp(GCC_NEW PhysicsComponent(entity->id, component));
			entity->addComponent(ComponentPtr(comp));
			physicsSystem->registerBody(entity->id, makeShared(comp->getBody()));
		}
		else if (componentId == ComponentType::TILE_COMPONENT) {
			entity->addComponent(ComponentPtr(GCC_NEW TileComponent(entity->id, component)));
		}
		else {
			assert(false);
		}
	}

	return entity;
}
コード例 #18
0
ファイル: Entity.cpp プロジェクト: A-K/naali
    ComponentPtr Entity::CreateComponent(uint type_hash, const QString &name, AttributeChange::Type change)
    {
        ComponentPtr new_comp = framework_->GetComponentManager()->CreateComponent(type_hash, name);
        if (!new_comp)
        {
            LogError("Failed to create a component of type hash " + QString::number(type_hash) + " and name \"" + name + "\" to " + ToString());
            return ComponentPtr();
        }

        AddComponent(new_comp, change);
        return new_comp;
    }
コード例 #19
0
ファイル: Entity.cpp プロジェクト: A-K/naali
    ComponentPtr Entity::CreateComponent(const QString &type_name, const QString &name, AttributeChange::Type change, bool syncEnabled)
    {
        ComponentPtr new_comp = framework_->GetComponentManager()->CreateComponent(type_name, name);
        if (!new_comp)
        {
            LogError("Failed to create a component of type \"" + type_name + "\" and name \"" + name + "\" to " + ToString());
            return ComponentPtr();
        }

        new_comp->SetNetworkSyncEnabled(syncEnabled);
        AddComponent(new_comp, change);
        return new_comp;
    }
コード例 #20
0
EntityPtr EntityFactory::createPhysicsEntity(float x, float y, float width, float height) {
	EntitySystemPtr entitySystem(makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY)));
	EntityPtr entity(GCC_NEW Entity());
	entitySystem->addEntity(entity);

	PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS));
	BodyPtr blockBody(GCC_NEW Body(x, y, width, height));
	physicsSystem->registerBody(entity->id, blockBody);
	PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody));
	physicsComponent->setCollider(GCC_NEW Collider(x, y, width, height));

	entity->addComponent(ComponentPtr(physicsComponent));

	return entity;
}
コード例 #21
0
ファイル: Entity.cpp プロジェクト: katik/naali
ComponentPtr Entity::CreateComponent(u32 typeId, const QString &name, AttributeChange::Type change, bool replicated)
{
    ComponentPtr new_comp = framework_->Scene()->CreateComponentById(scene_, typeId, name);
    if (!new_comp)
    {
        LogError("Failed to create a component of type id " + QString::number(typeId) + " and name \"" + name + "\" to " + ToString());
        return ComponentPtr();
    }

    // If changemode is default, and new component requests to not be replicated by default, honor that
    if (change != AttributeChange::Default || new_comp->IsReplicated())
        new_comp->SetReplicated(replicated);
    
    AddComponent(new_comp, change);
    return new_comp;
}
コード例 #22
0
ファイル: Entity.cpp プロジェクト: katik/naali
ComponentPtr Entity::CreateComponentWithId(component_id_t compId, u32 typeId, const QString &name, AttributeChange::Type change)
{
    ComponentPtr new_comp = framework_->Scene()->CreateComponentById(scene_, typeId, name);
    if (!new_comp)
    {
        LogError("Failed to create a component of type id " + QString::number(typeId) + " and name \"" + name + "\" to " + ToString());
        return ComponentPtr();
    }

    // If this overload is called with id 0, it must come from SyncManager (server). In that case make sure we do not allow the component to be created as local
    if (!compId)
        new_comp->SetReplicated(true);

    AddComponent(compId, new_comp, change);
    return new_comp;
}
コード例 #23
0
ファイル: Entity.cpp プロジェクト: realXtend/tundra-urho3d
ComponentPtr Entity::ComponentById(component_id_t id) const
{
    ComponentMap::ConstIterator i = components_.Find(id);
    return (i != components_.End() ? i->second_ : ComponentPtr());
}
コード例 #24
0
ファイル: ecs.hpp プロジェクト: respu/microecs
	static ComponentPtr MakeComponentPtr(T* ptr) {
		return ComponentPtr(ptr, [](Component* p) { delete static_cast<T*>(p); });
	}
コード例 #25
0
ファイル: Entity.cpp プロジェクト: katik/naali
ComponentPtr Entity::ComponentById(component_id_t id) const
{
    ComponentMap::const_iterator i = components_.find(id);
    return (i != components_.end() ? i->second : ComponentPtr());
}