Exemplo n.º 1
0
void Sample::InitResource()
{
	DeviceCreated();
	SkyBoxPtr = std::make_shared<SkyBox>();
	SkyBoxPtr->InitResource();
	gameObject.InitResource(GEOMETRY_TYPE_GRID);
	gameObject.SetTexture("Data\\Texture\\metal001.dds");
	gameSphereObject.InitResource(GEOMETRY_TYPE_SPHERE);
	gameSphereObject.SetTexture("Data\\Texture\\ice.dds");
	g_objSprite.ResetSize(mClientWidth, mClientHeight);
	CreateScrene();

	RolePtr = std::make_shared<Role>();
	RolePtr->Init(scene_);
}
void EC_MeshmoonWater::OnParentEntitySet()
{
    if (!framework || framework->IsHeadless())
        return;

    OgreRendererPtr renderer = Renderer();
    if (!renderer)
    {
        // Try to resolve the renderer now. Might have not been done in ctor if constructed as unparented!
        OgreRenderingModule* renderingModule = framework->Module<OgreRenderingModule>();
        if (!renderingModule)
            return;
        renderer_ = renderingModule->Renderer();
        if (renderer_.expired())
            return;
        renderer = renderer_.lock();
    }
        
    if (world_.expired() && ParentScene())
        world_ = ParentScene()->GetWorld<OgreWorld>();

    connect(renderer.get(), SIGNAL(DeviceCreated()), this, SLOT(RecreateOcean()), Qt::UniqueConnection);
    connect(renderer.get(), SIGNAL(MainCameraChanged(Entity *)), this, SLOT(OnActiveCameraChanged(Entity *)), Qt::UniqueConnection);
    connect(framework->Frame(), SIGNAL(Updated(float)), this, SLOT(OnUpdate(float)), Qt::UniqueConnection);

    OnActiveCameraChanged(renderer->MainCamera());

    // Detect sky components if already in scene, otherwise will be detected via ComponentAdded signal
    EntityList ents = ParentScene()->EntitiesWithComponent(EC_MeshmoonSky::TypeIdStatic());
    for (EntityList::iterator iter = ents.begin(); iter != ents.end(); ++iter)
    {
        IComponent *comp = (*iter)->Component(EC_MeshmoonSky::TypeIdStatic()).get();
        if (comp) OnComponentAdded(0, comp, AttributeChange::LocalOnly);
    }
    ents = (windConditionsComp_.expired() ? ParentScene()->EntitiesWithComponent(EC_SkyX::TypeIdStatic()) : EntityList());
    for (EntityList::iterator iter = ents.begin(); iter != ents.end(); ++iter)
    {
        IComponent *comp = (*iter)->Component(EC_SkyX::TypeIdStatic()).get();
        if (comp) OnComponentAdded(0, comp, AttributeChange::LocalOnly);
    }

    connect(ParentScene(), SIGNAL(ComponentAdded(Entity*, IComponent*, AttributeChange::Type)), 
        this, SLOT(OnComponentAdded(Entity*, IComponent*, AttributeChange::Type)), Qt::UniqueConnection);
    connect(ParentScene(), SIGNAL(ComponentRemoved(Entity*, IComponent*, AttributeChange::Type)), 
        this, SLOT(OnComponentRemoved(Entity*, IComponent*, AttributeChange::Type)), Qt::UniqueConnection);

    CreateOcean();
}