示例#1
0
SoundPtr ALSubsystem::stream2D(String filename, bool startPaused)
{
  SoundPtr out;

  String ext = filename.substr(filename.find_last_of(".") + 1);

  if(mAudioLoaders.find(ext) != mAudioLoaders.end())
  {	
    try
    {
      AudioStream* stream = mAudioLoaders[ext]->streamSound(filename);
      out.bind(new StreamedSound(stream, getSource()));
      mActiveSounds.push_back(out);
      if(!startPaused)
        out->play();
    }
    catch(Exception e)
    {
      std::cout<<"Could not stream sound.\n";
    }
  }
  else
  {
    std::cout<<"Could not stream sound, no loader found.\n";
  }	

  return out;
}
示例#2
0
void play(const char* name, bool stream=false)
{
  // Only load streams if the backend supports it
  if(stream && !mg.canLoadStream)
    return;

  cout << "Playing " << name;
  if(stream) cout << " (from stream)";
  cout << "\n";

  SoundPtr snd;

  try
    {
      if(stream)
        snd = mg.load(StreamPtr(new FileStream(name)));
      else
        snd = mg.load(name);

      snd->play();

      while(snd->isPlaying())
        {
          usleep(10000);
          if(mg.needsUpdate) mg.update();
        }
    }
  catch(exception &e)
    {
      cout << "  ERROR: " << e.what() << "\n";
    }
}
示例#3
0
SoundPtr ALSubsystem::play2D(String name, bool startPaused)
{
  SoundPtr out;

  if(mAudioBuffers.find(name) == mAudioBuffers.end())
  {
    loadSound(name);

    if(mAudioBuffers.find(name) == mAudioBuffers.end())
    {
      std::cout<<"Could not play sound, could not find or load audio.\n";
      return out;
    }
  }

  if(!hasSources())
  {
    std::cout<<"Could not play sound, no available sound sources.\n";
  }
  else
  {
    out.bind(new BufferedSound(getSource(), mAudioBuffers[name], mAudioData[name]));
    mActiveSounds.push_back(out);
    if(!startPaused)
      out->play();
  }

  return out;
}
示例#4
0
SoundPtr ALSubsystem::play2D(String name, bool startPaused)
{
    SoundPtr out;

    if(mAudioBuffers.find(name) == mAudioBuffers.end())
    {
        loadSound(name);

        if(mAudioBuffers.find(name) == mAudioBuffers.end())
        {
            Logger::getPtr()->logMessage("Could not play sound, could not find or load audio.");
            return out;
        }
    }

    if(!hasSources())
    {
        Logger::getPtr()->logMessage("Could not play sound, no available sound sources.");
    }
    else
    {
        out.bind(new BufferedSound(getSource(), mAudioBuffers[name]));
        mActiveSounds.push_back(out);
        out->setGain(0.f, 1.f, 1.f);
        if(!startPaused)
            out->play();
    }

    return out;
}
示例#5
0
SoundManager::SoundPtr SoundManager::Load(const std::string& locator) {
    std::string file;
    file = "content/sounds/" + locator;
    SoundPtr sound = SoundPtr(new sf::SoundBuffer());
    if(!sound->LoadFromFile(file))
        return SoundPtr();
    return sound;
}
示例#6
0
 void SoundManager::stopSound(const std::string& soundId)
 {
     IDMap::iterator it = mLoopedSounds.find(soundId);
     if(it != mLoopedSounds.end())
     {
         SoundPtr snd = it->second.lock();
         if(snd) snd->stop();
         mLoopedSounds.erase(it);
     }
 }
 TutorialCollisionListener(Path SoundFilePath)
 {
     _CollisionSound = SoundManager::the()->createSound();
     beginEditCP(_CollisionSound, Sound::FileFieldMask | Sound::VolumeFieldMask | Sound::StreamingFieldMask | Sound::LoopingFieldMask);
         _CollisionSound->setFile(SoundFilePath);
         _CollisionSound->setVolume(1.0);
         _CollisionSound->setStreaming(false);
         _CollisionSound->setLooping(0);
     endEditCP(_CollisionSound, Sound::FileFieldMask | Sound::VolumeFieldMask | Sound::StreamingFieldMask | Sound::LoopingFieldMask);
 }
示例#8
0
void PlayerBehavior::update( ) {
	//何もしなかったら待機
	_player_state = PLAYER_STATE_WAIT;
	
	CONTROLL controll = makeControll( );

	walk( controll );
	attack( controll );
	AppPtr app = App::getTask( );

	if ( _parent->getStatus( ).hp <= 0 ) {
		_player_state = PLAYER_STATE_DEAD;
		SoundPtr sound = Sound::getTask( );
		sound->playSE( Sound::SE_GAME_OVER );
		ClientPtr client = Client::getTask( );
		SERVERDATA data;
		data.command = COMMAND_STATUS_POS;
		data.value[ 0 ] = _player_id;
		data.value[ 1 ] = 0;
		data.value[ 2 ] = 0;
		client->send( data );

		if ( _controll ) {
			app->setState( App::STATE_DEAD );
		}
	} else {
		PlayerPtr player = std::dynamic_pointer_cast< Player >( _parent );
		player->addSP( 1 );
	}
	_before_state = _player_state;
	PlayerPtr player = std::dynamic_pointer_cast< Player >( _parent );
	int sp = player->getSP( );
	//AdventurePtr adventure = app->getAdventure( );
	if ( ( !_is_tutorial_sence ) && ( sp == Player::FULL_SP_NUM ) && _controll ) {
		//adventure->set( Adventure::TYPE_COMMON_TUTORIAL_3 );
		_is_tutorial_sence = true;
	}
	for ( int i = PLAYER_ETUDE_RED; i <= PLAYER_ETUDE_BLUE; i++ ) {
		Vector pos = _parent->getPos( ) - app->getPlayer( i )->getPos( );
		if ( !_is_conntact_minotaur && 
			( _player_id < PLAYER_ETUDE_RED ) && 
			( pos.getLength( ) < CONNTACT_MINOTAUR_LENGTH ) &&
			_controll ) {
			//adventure->set( Adventure::TYPE_COMMON_CYCLOPS_CONTACT );
			//adventure->set( Adventure::TYPE_COMMON_AFTER_MINOTAUR_ENTRY );
			_is_conntact_minotaur = true;
		}
	}
	_keep_pos = _parent->getPos( );
}
示例#9
0
 void SoundManager::playSound (const std::string& soundId, float volume, float pitch)
 {
   if(!mData) return;
   // Play and forget
   float min, max;
   const std::string &file = mData->lookup(soundId, volume, min, max);
   if(file != "")
     {
       SoundPtr snd = mData->mgr->load(file);
       snd->setVolume(volume);
       snd->setRange(min,max);
       snd->setPitch(pitch);
       snd->play();
     }
 }
示例#10
0
/** 
 * Initializes the bee's attributes 
 * 
 * 
 * @return bool
 */
bool Bee::DoExtraInits()
{
	if (!GameCharacter::DoExtraInits())
	{
		return false;
	}

	// add a health attribute
	HealthAttributePtr health = NiNew HealthAttribute(this);
	m_fMaxHealth = ConfigurationManager::Get()->bee_initialHealth;
	health->Reset(m_fMaxHealth);
	AddAttribute(GameCharacter::ATTR_HEALTH, (CharacterAttribute*)health);
	// add an armor attribute
	AddAttribute(GameCharacter::ATTR_ARMOR, NiNew ArmorAttribute(this));
	// add a damage attribute
	DamageAttribute* dmg = NiNew DamageAttribute(this);
	dmg->Reset(ConfigurationManager::Get()->bee_damage);
	AddAttribute(GameCharacter::ATTR_DAMAGE, dmg);
	// add an FSMBeeAIControl
	AddAttribute(GameCharacter::ATTR_CONTROLLER, NiNew FSMBeeAIControl(this));
	// set initial position
	m_pActor->setGlobalPosition(GameManager::Get()->
		GetQueen()->GetActor()->getGlobalPosition() - NxVec3(50.0, 0.0, 0.0));

	SoundPtr sound = ResourceManager::Get()->GetSound(
		ResourceManager::RES_SOUND_BEE, this);
	if (sound)
	{
		AddAttribute(GameCharacter::ATTR_SOUND_DEFAULT, (CharacterAttribute*)sound);
		sound->Play();
	}

	AddAttribute(GameCharacter::ATTR_SOUND_1, (CharacterAttribute*) ResourceManager::Get()->GetSound(
		ResourceManager::RES_SOUND_BEE_AWAITING, this));

	AddAttribute(GameCharacter::ATTR_SOUND_2, (CharacterAttribute*) ResourceManager::Get()->GetSound(
		ResourceManager::RES_SOUND_BEE_DYING, this));

	// set dampings
	m_pActor->setLinearDamping(8.0f);
	m_pActor->setAngularDamping(8.0f);

	
	

	return true;
}
示例#11
0
  void SoundManager::playSound(const std::string& soundId, float volume, float pitch, bool loop)
  {
    float min, max;
    const std::string &file = lookup(soundId, volume, min, max);
    if (file != "")
    {
        SoundPtr snd = mgr->load(file);
        snd->setRepeat(loop);
        snd->setVolume(volume);
        snd->setRange(min,max);
        snd->setPitch(pitch);
        snd->setRelative(true);
        snd->play();

        if (loop)
        {
            // Only add the looping sound once
            IDMap::iterator it = mLoopedSounds.find(soundId);
            if(it == mLoopedSounds.end())
            {
                mLoopedSounds[soundId] = WSoundPtr(snd);
            }
        }
    }
  }
示例#12
0
void Audio::playSFX(const std::string &filename, bool relative, const cml::vector2f &pos, float attenuation, float min_dist)
{
    if(sounds.empty())
        for(int i = 0; i < 32; i++)
        {
            SoundPtr s(new sf::Sound());
            s->SetVolume(60.0f);
            sounds.push_back(s);
        }


    SoundPtr s;

    for(unsigned int i = 0; i < sounds.size(); i++)
        if(sounds[i]->GetStatus() == sf::Sound::Stopped)
            s = sounds[i];

    if(!s)
    {
        warning("too many sounds");
        return;
    }

    SoundBufferPtr sb = getSoundBuffer(filename);
    s->SetRelativeToListener(relative);
    s->SetPosition(pos[0], pos[1], 0.0f);
    s->SetAttenuation(attenuation);
    s->SetMinDistance(min_dist);
    s->SetBuffer(*(sb.get()));
    s->Play();
}
示例#13
0
    // Clears all the sub-elements of a given iterator, and then
    // removes it from 'sounds'.
    void clearAll(PtrMap::iterator it)
    {
      IDMap::iterator sit = it->second.begin();

      while(sit != it->second.end())
        {
          // Get sound pointer, if any
          SoundPtr snd = sit->second.lock();

          // Stop the sound
          if(snd) snd->stop();

          sit++;
        }

      // Remove the ptr reference
      sounds.erase(it);
    }
示例#14
0
// Set the position on a sound based on a Ptr.
static void setPos(SoundPtr &snd, const MWWorld::Ptr ref)
{
  // Get sound position from the reference
  const float *pos = ref.getCellRef().pos.pos;

  // Move the sound, converting from MW coordinates to Ogre
  // coordinates.
  snd->setPos(pos[0], pos[2], -pos[1]);
}
SoundPtr ResourceConfig::SafeReadSound(StringParser &theVal)
{
	theVal.SkipWhitespace();
	
	SoundDescriptor aDesc;
	std::string aName;
	if(theVal.GetChar()=='(')
	{
		theVal.IncrementPos();
		theVal.ReadString(aName); EnsureComma(theVal);
		int aFlags = 0;
		while(true)
		{
			std::string aFlagStr;
			theVal.ReadString(aFlagStr,true);
			if(aFlagStr.empty())
				break;

			if(stricmp(aFlagStr.c_str(),"Preload")==0)
				aFlags |= SoundFlag_Preload;
			else if(stricmp(aFlagStr.c_str(),"Music")==0)
				aFlags |= SoundFlag_Music;
			else if(stricmp(aFlagStr.c_str(),"Muted")==0)
				aFlags |= SoundFlag_Muted;
			else 
				throw ConfigObjectException("Unknown sound flag: " + aFlagStr);
		}

		aDesc.SetSoundFlags(aFlags,true);
		EnsureCloseParen(theVal);
	}
	else
		theVal.ReadString(aName);

	aDesc.mFilePath = ComponentConfig::GetResourceFile(aName);

	SoundPtr aSound = WindowManager::GetDefaultWindowManager()->DecodeSound(aDesc);
	if(aSound.get()==NULL)
		throw ConfigObjectException("Failed to decode sound: " + aDesc.mFilePath);

	return aSound;
}
示例#16
0
    // Add a sound to the list and play it
    void SoundManager::add(const std::string &file,
             MWWorld::Ptr ptr,
             const std::string &id,
             float volume, float pitch,
             float min, float max,
             bool loop, bool untracked)
    {
      try
        {
          SoundPtr snd = mgr->load(file);
          snd->setRepeat(loop);
          snd->setVolume(volume);
          snd->setPitch(pitch);
          snd->setRange(min,max);
          setPos(snd, ptr);
          snd->play();

          if (!untracked)
          {
            sounds[ptr][id] = WSoundPtr(snd);
          }
        }
      catch(...)
        {
          std::cout << "Error loading " << file << ", skipping.\n";
        }
    }
示例#17
0
    bool isPlaying(MWWorld::Ptr ptr, const std::string &id) const
    {
      PtrMap::const_iterator it = sounds.find(ptr);
      if(it != sounds.end())
        {
          IDMap::const_iterator it2 = it->second.find(id);
          if(it2 != it->second.end())
            {
              // Get a shared_ptr from the weak_ptr
              SoundPtr snd = it2->second.lock();;

              // Is it still alive?
              if(snd)
                {
                  // Then return its status!
                  return snd->isPlaying();
                }
            }
        }
      // Nothing found, sound is not playing
      return false;
    }
示例#18
0
 // Stop a sound and remove it from the list. If id="" then
 // remove the entire object and stop all its sounds.
 void remove(MWWorld::Ptr ptr, const std::string &id = "")
 {
   PtrMap::iterator it = sounds.find(ptr);
   if(it != sounds.end())
     {
       if(id == "")
         // Kill all references to 'ptr'
         clearAll(it);
       else
         {
           // Only find the id we're looking for
           IDMap::iterator it2 = it->second.find(id);
           if(it2 != it->second.end())
             {
               // Stop the sound and remove it from the list
               SoundPtr snd = it2->second.lock();
               if(snd) snd->stop();
               it->second.erase(it2);
             }
         }
     }
 }
示例#19
0
 virtual void actionPerformed(const ActionEventPtr e)
  {
      TutorialSound->stop(TutorialSoundChannelID);
      std::cout << "Stop Action" << std::endl;
      NodePtr s = makeTorus(.5, 2, 16, 16);
      beginEditCP(scene, Node::ChildrenFieldMask);
          while(scene->getNChildren() > 0)
          {
              scene->subChild(scene->getNChildren()-1);
          }
          scene->addChild(s);
      endEditCP(scene, Node::ChildrenFieldMask);
      
      segUpdate = 0;
  }
示例#20
0
   virtual void actionPerformed(const ActionEventPtr e)
    {
        TutorialSound->pauseToggle(TutorialSoundChannelID);
        std::cout << "Pause Action" << std::endl;

    }
示例#21
0
   virtual void actionPerformed(const ActionEventPtr e)
    {
        TutorialSoundChannelID = TutorialSound->play();
        std::cout << "Start Action" << std::endl;

    }
示例#22
0
 virtual void collision(const CollisionEventPtr e)
 {
     _CollisionSound->play();
 }
示例#23
0
SoundID ResourceManagerImpl::new_sound_from_file(const unicode& path) {
    //Load the sound
    SoundPtr snd = sound(new_sound()).lock();
    window().loader_for(path.encode())->into(*snd);
    return snd->id();
}
示例#24
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindowEventProducer = createDefaultWindowEventProducer();
    WindowPtr MainWindow = TutorialWindowEventProducer->initWindow();

    TutorialWindowEventProducer->setDisplayCallback(display);
    TutorialWindowEventProducer->setReshapeCallback(reshape);
    
    TutorialKeyListener TheKeyListener;
    TutorialWindowEventProducer->addKeyListener(&TheKeyListener);
    TutorialUpdateListener TheTutorialUpdateListener;
    TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener);

    //Create Start and stop buttons for the caption
    ButtonPtr StartButton = osg::Button::create();
    ButtonPtr StopButton = osg::Button::create();
    ButtonPtr PauseButton = osg::Button::create();

    UIFontPtr ButtonFont = osg::UIFont::create();

    beginEditCP(ButtonFont, UIFont::SizeFieldMask);
        ButtonFont->setSize(16);
    endEditCP(ButtonFont, UIFont::SizeFieldMask);
    
    beginEditCP(StartButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask |
        Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask);
            StartButton->setMinSize(Vec2f(50, 25));
            StartButton->setMaxSize(Vec2f(200, 100));
            StartButton->setPreferredSize(Vec2f(100, 50));
            StartButton->setToolTipText("This will start playing the caption!");

            StartButton->setText("START");
            StartButton->setFont(ButtonFont);
            StartButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
            StartButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0));
            StartButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
            StartButton->setAlignment(Vec2f(0.25,0.5));
    endEditCP(StartButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask |
        Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask);

    beginEditCP(StopButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask |
        Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask);
            StopButton->setMinSize(Vec2f(50, 25));
            StopButton->setMaxSize(Vec2f(200, 100));
            StopButton->setPreferredSize(Vec2f(100, 50));
            StopButton->setToolTipText("This will stop the caption and reset it!");

            StopButton->setText("STOP");
            StopButton->setFont(ButtonFont);
            StopButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
            StopButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0));
            StopButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
            StopButton->setAlignment(Vec2f(0.75,0.5));
    endEditCP(StopButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask |
        Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask);

    beginEditCP(PauseButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask |
        Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask);
            PauseButton->setMinSize(Vec2f(50, 25));
            PauseButton->setMaxSize(Vec2f(200, 100));
            PauseButton->setPreferredSize(Vec2f(100, 50));
            PauseButton->setToolTipText("This will Pause the caption!");

            PauseButton->setText("PAUSE");
            PauseButton->setFont(ButtonFont);
            PauseButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
            PauseButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0));
            PauseButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
            PauseButton->setAlignment(Vec2f(0.5,0.5));
    endEditCP(PauseButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask |
        Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask);


    StartButtonActionListener TheStartButtonActionListener;
    StartButton->addActionListener(&TheStartButtonActionListener);

    StopButtonActionListener TheStopButtonActionListener;
    StopButton->addActionListener(&TheStopButtonActionListener);

    PauseButtonActionListener ThePauseButtonActionListener;
    PauseButton->addActionListener(&ThePauseButtonActionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(MainWindow);
	
    // Make Torus Node (creates Torus in background of scene)
    NodePtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

    // Make Main Scene Node and add the Torus
    scene = osg::Node::create();
    beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask);
        scene->setCore(osg::Group::create());
        scene->addChild(TorusGeometryNode);
    endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask);


    // Create the Graphics
    GraphicsPtr TutorialGraphics = osg::Graphics2D::create();

    // Initialize the LookAndFeelManager to enable default settings
    LookAndFeelManager::the()->getLookAndFeel()->init();

    
    LayoutPtr MainInternalWindowLayout = osg::FlowLayout::create();



    PanelPtr CaptionContainer = osg::Panel::create();

    beginEditCP(CaptionContainer, Panel::PreferredSizeFieldMask | Panel::LayoutFieldMask);
        CaptionContainer->setPreferredSize(Pnt2f(250.0,30.0));
        CaptionContainer->setLayout(MainInternalWindowLayout);
    endEditCP(CaptionContainer, Panel::PreferredSizeFieldMask | Panel::LayoutFieldMask);

    //Initialize the Sound Manager
    SoundManager::the()->attachUpdateProducer(TutorialWindowEventProducer);

    TutorialSound = SoundManager::the()->createSound();
    beginEditCP(TutorialSound, Sound::FileFieldMask | Sound::VolumeFieldMask | Sound::StreamingFieldMask | Sound::LoopingFieldMask);
        TutorialSound->setFile(Path("./Data/captionSoundFile.ogg"));
        TutorialSound->setVolume(1.0);
        TutorialSound->setStreaming(true);
        TutorialSound->setLooping(0);
    endEditCP(TutorialSound, Sound::FileFieldMask | Sound::VolumeFieldMask | Sound::StreamingFieldMask | Sound::LoopingFieldMask);

    // Create the Caption
    TutorialCaption = osg::Caption::create();

    //Add the segments of text to be displayed
    TutorialCaption->captionSegment("Listeners can be used for a variety",1.7,3.4);
    TutorialCaption->captionSegment("of different applications.",3.4,4.7);
    TutorialCaption->captionSegment("In this tutorial we will",5.0,6.35);
    TutorialCaption->captionSegment("simply be changing the background though.",6.35,8.0);
    TutorialCaption->captionSegment("First we will change the",8.8,10.2);
    TutorialCaption->captionSegment("torus on screen to a sphere.",10.2,11.75);
    TutorialCaption->captionSegment("By timing things correctly we can make",12.7,14.6);
    TutorialCaption->captionSegment("the changes right as the word is spoken.",14.6,16.75);
    TutorialCaption->captionSegment("Such as changing the sphere to a cube",17.3,20.0);
    TutorialCaption->captionSegment("but personally I would prefer",20.33,21.65);
    TutorialCaption->captionSegment("the background to be blank.",21.65,22.8);
    TutorialCaption->captionSegment("Much better!",23.8,25.0);


    //Add the tutorial Caption Listener to the Caption that was set up for the tutorial
    TutorialCaptionListener TheCaptionListener;
    TutorialCaption->addCaptionListener(&TheCaptionListener);

    //Create the Caption component Generator
    TutorialCapGen = DefaultCaptionComponentGenerator::create();

    TutorialCaption->attachWindowEventProducer(TutorialWindowEventProducer);
    beginEditCP(TutorialCaption, Caption::ParentContainerFieldMask | Caption::ComponentGeneratorFieldMask | Caption::CaptionDialogSoundFieldMask);
        TutorialCaption->setParentContainer(CaptionContainer);
        TutorialCaption->setComponentGenerator(TutorialCapGen);
        TutorialCaption->setCaptionDialogSound(TutorialSound);
    endEditCP(TutorialCaption, Caption::ParentContainerFieldMask | Caption::ComponentGeneratorFieldMask | Caption::CaptionDialogSoundFieldMask);


    //Create and modify the Label prototype that will be used for the caption
    LabelPtr LabelPrototype = Label::create();
    LabelPrototype->setAlignment(Pnt2f(0.5f,0.5f));
    LabelPrototype->setPreferredSize(Pnt2f(250.0,30.0));

    //Add the prototype to the Generator for use
    beginEditCP(TutorialCapGen, DefaultCaptionComponentGenerator::CaptionSegmentPrototypeFieldMask);
        TutorialCapGen->setCaptionSegmentPrototype(LabelPrototype);
    endEditCP(TutorialCapGen, DefaultCaptionComponentGenerator::CaptionSegmentPrototypeFieldMask);
    
    // Create The Main InternalWindow
    // Create Background to be used with the Main InternalWindow
    ColorLayerPtr MainInternalWindowBackground = osg::ColorLayer::create();
    MainInternalWindow = osg::InternalWindow::create();
    beginEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask);
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
    endEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask);
	beginEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask);
       MainInternalWindow->setLayout(MainInternalWindowLayout);
       MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
	   MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
	   MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f));
	   MainInternalWindow->setDrawTitlebar(false);
	   MainInternalWindow->setResizable(false);
	   MainInternalWindow->getChildren().push_back(CaptionContainer);
	   MainInternalWindow->getChildren().push_back(StartButton);
	   MainInternalWindow->getChildren().push_back(StopButton);
       MainInternalWindow->getChildren().push_back(PauseButton);
    endEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask);

    // Create the Drawing Surface
    UIDrawingSurfacePtr TutorialDrawingSurface = UIDrawingSurface::create();
    beginEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask);
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindowEventProducer);
    endEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask);
    
	TutorialDrawingSurface->openWindow(MainInternalWindow);
	
	// Create the UI Foreground Object
    UIForegroundPtr TutorialUIForeground = osg::UIForeground::create();

    beginEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask);
        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);
    endEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask);

    mgr->setRoot(scene);

    // Add the UI Foreground Object to the Scene
    ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0);
    beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask);
        TutorialViewport->getForegrounds().push_back(TutorialUIForeground);
    beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask);

    // Show the whole Scene
    mgr->showAll();
    SoundManager::the()->setCamera(mgr->getCamera());


    Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5);
    TutorialWindowEventProducer->openWindow(WinPos,
            WinSize,
            "05Caption");

    //Enter main Loop
    TutorialWindowEventProducer->mainLoop();


    osgExit();

    return 0;
}
示例#25
0
 void SoundChannel::QueueBuffers()
 {
     // See that we do have waiting sounds and they're ready to play
     if (!pending_sounds_.size())
         return;
     if ((*pending_sounds_.begin())->GetHandle() == 0)
         return;
     
     // Create source now if did not exist already
     if (!CreateSource())
     {
         state_ = Foundation::SoundServiceInterface::Stopped;
         pending_sounds_.clear();
         return;
     }
     
     bool queued = false;
     
     // Buffer pending sounds, move them to playing vector
     while (pending_sounds_.size())
     {
         SoundPtr sound = *pending_sounds_.begin();
         ALuint buffer = sound->GetHandle();
         // If no valid handle yet, cannot play this one, break out
         if (!buffer)
             return;
         
         alGetError();
         alSourceQueueBuffers(handle_, 1, &buffer);
         ALenum error = alGetError();
         
         if (error != AL_NONE)
         {
             // If queuing fails, we may have changed sound format. Stop, flush queue & retry
             alSourceStop(handle_);
             alSourcei(handle_, AL_BUFFER, 0);
             alSourceQueueBuffers(handle_, 1, &buffer);
             ALenum error = alGetError();
             if (error != AL_NONE)
                 OpenALAudioModule::LogError("Could not queue OpenAL sound buffer: " + ToString<int>(error));
             else
             {
                 playing_sounds_.push_back(sound);
                 queued = true;
             }
         }
         else
         {
             playing_sounds_.push_back(sound);
             queued = true;
         }
         
         pending_sounds_.pop_front();
     }
     
     // If at least one sound queued, start playback if not already playing
     if (queued)
     {
         ALint playing;
         alGetSourcei(handle_, AL_SOURCE_STATE, &playing);
         if (playing != AL_PLAYING)
             alSourcePlay(handle_);
         state_ = Foundation::SoundServiceInterface::Playing;
     }
 }
示例#26
0
 // Release the lock. This may or may not delete the object. Never do
 // anything after calling unlock()!
 void unlock()
 {
   self.reset();
 }