[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    Re: playground/games/kapman
From:       "Thomas Gallinari" <tg8187 () yahoo ! fr>
Date:       2008-08-19 19:50:57
Message-ID: op.uf5f27zxmlbwfu () kubuntu
[Download RAW message or body]

Latency problems seem to be recurrent with Phonon for games since sounds  
are played very close.
Actually there is a debate about using Phonon on the KDE-Games  
mailing-list.

Le Tue, 19 Aug 2008 21:40:15 +0200, Alexis Ménard <menard@kde.org> a écrit:

> Perhaps you can ask to Mathias kretz for your latency problem : *kretz*@*
> kde.org
> *
> On Tue, Aug 19, 2008 at 9:34 PM, Thomas Gallinari <tg8187@yahoo.fr>  
> wrote:
>
>> SVN commit 849579 by gallinari:
>>
>> Adding sounds to the game with Phonon... Latency problems, maybe use
>> several MediaObject ?
>>
>>  M  +10 -1     CMakeLists.txt
>>  M  +19 -10    game.cpp
>>  M  +10 -0     game.h
>>  A             sounds (directory)
>>  AM            sounds/bonus.ogg
>>  AM            sounds/energizer.ogg
>>  AM            sounds/gameover.ogg
>>  AM            sounds/ghost.ogg
>>  AM            sounds/levelup.ogg
>>  AM            sounds/pill.ogg
>>
>>
>> --- trunk/playground/games/kapman/CMakeLists.txt #849578:849579
>> @@ -42,6 +42,14 @@
>>        themes/matches.desktop
>>        themes/matches_preview.png
>>  )
>> +set(kapmanSounds
>> +       sounds/pill.ogg
>> +       sounds/energizer.ogg
>> +       sounds/ghost.ogg
>> +       sounds/bonus.ogg
>> +       sounds/levelup.ogg
>> +       sounds/gameover.ogg
>> +)
>>
>>  kde4_add_kcfg_files(kapmanSources settings.kcfgc)
>>
>> @@ -52,7 +60,8 @@
>>  target_link_libraries(kapman ${KDE4_KDEUI_LIBS}         
>> ${KDE4_PHONON_LIBS}
>> ${KDEGAMES_LIBRARY})
>>
>>  install(TARGETS kapman ${INSTALL_TARGETS_DEFAULT_ARGS})
>> +install(FILES kapman.desktop DESTINATION  
>> ${XDG_APPS_INSTALL_DIR}/kapman)
>>  install(FILES ${kapmanData} DESTINATION ${DATA_INSTALL_DIR}/kapman)
>> -install(FILES kapman.desktop DESTINATION  
>> ${XDG_APPS_INSTALL_DIR}/kapman)
>>  install(FILES ${kapmanThemes} DESTINATION
>> ${DATA_INSTALL_DIR}/kapman/themes)
>> +install(FILES ${kapmanSounds} DESTINATION ${SOUND_INSTALL_DIR}/kapman)
>>
>> --- trunk/playground/games/kapman/game.cpp #849578:849579
>> @@ -25,7 +25,8 @@
>>  const int Game::FPS = 40;
>>
>>  Game::Game(KGameDifficulty::standardLevel p_difficulty) :
>> m_isCheater(false), m_lives(3), m_points(0), m_level(1),  
>> m_nbEatenGhosts(0)
>> {
>> -
>> +       // Create the MediaObject
>> +       m_media = createPlayer(Phonon::GameCategory);
>>        // Tells the KGameDifficulty singleton that the game is not  
>> running
>>        KGameDifficulty::setRunning(false);
>>        // Initialize the characters speed considering the difficulty  
>> level
>> @@ -81,6 +82,7 @@
>>  }
>>
>>  Game::~Game() {
>> +       delete m_media;
>>        delete m_timer;
>>        delete m_bonusTimer;
>>        delete m_maze;
>> @@ -209,6 +211,13 @@
>>        }
>>  }
>>
>> +void Game::playSound(const QString& p_sound) {
>> +       if (m_media->currentSource().fileName() != p_sound) {
>> +               m_media->setCurrentSource(p_sound);
>> +       }
>> +       m_media->play();
>> +}
>> +
>>  void Game::keyPressEvent(QKeyEvent* p_event) {
>>        // At the beginning or when paused, we start the timer when an  
>> arrow
>> key is pressed
>>        if ((p_event->key() == Qt::Key_Up || p_event->key() ==  
>> Qt::Key_Down
>> || p_event->key() ==  Qt::Key_Left || p_event->key() == Qt::Key_Right)  
>> &&
>> !m_timer->isActive()) {
>> @@ -280,6 +289,7 @@
>>  }
>>
>>  void Game::kapmanDeath() {
>> +       playSound(KStandardDirs::locate("sound",  
>> "kapman/gameover.ogg"));
>>        m_lives--;
>>        m_kapman->die();
>>        emit(dataChanged(LivesInfo));
>> @@ -316,15 +326,13 @@
>>
>>        // If the eaten element is a ghost, win 200 * number of eaten  
>> ghosts
>> since the energizer was eaten
>>        if (p_element->getType() == Element::GHOST) {
>> +               playSound(KStandardDirs::locate("sound",
>> "kapman/ghost.ogg"));
>>                // Get the position of the ghost
>> -               // A TESTER (le ghost a peut-être déjà bougé)
>>                qreal xPos = p_element->getX();
>>                qreal yPos = p_element->getY();
>> -
>>                // Add points to the score
>>                wonPoints = p_element->getPoints() * m_nbEatenGhosts;
>> -
>> -               // Sends to the scene the number of points to display  
>> and
>> its position
>> +               // Send to the scene the number of points to display and
>> its position
>>                emit(pointsToDisplay(wonPoints, xPos, yPos));
>>        }
>>        // Else you just win the value of the element
>> @@ -342,6 +350,7 @@
>>        }
>>        // If the eaten element is an energyzer we change the ghosts  
>> state
>>        if (p_element->getType() == Element::ENERGYZER) {
>> +               playSound(KStandardDirs::locate("sound",
>> "kapman/energizer.ogg"));
>>                for (int i = 0; i < m_ghosts.size(); i++) {
>>                        if(m_ghosts[i]->getState() != Ghost::EATEN) {
>>                                m_ghosts[i]->setState(Ghost::PREY);
>> @@ -350,13 +359,12 @@
>>                // Reset the number of eaten ghosts
>>                m_nbEatenGhosts = 0;
>>                emit(elementEaten(p_element->getX(), p_element->getY()));
>> -       }
>> -       else if (p_element->getType() == Element::PILL) {
>> +       } else if (p_element->getType() == Element::PILL) {
>> +               playSound(KStandardDirs::locate("sound",
>> "kapman/pill.ogg"));
>>                emit(elementEaten(p_element->getX(), p_element->getY()));
>> -       }
>> -       else if (p_element->getType() == Element::BONUS) {
>> +       } else if (p_element->getType() == Element::BONUS) {
>> +               playSound(KStandardDirs::locate("sound",
>> "kapman/bonus.ogg"));
>>                // Get the position of the Bonus
>> -               // A TESTER (le ghost a peut-être déjà bougé)
>>                qreal xPos = p_element->getX();
>>                qreal yPos = p_element->getY();
>>
>> @@ -375,6 +383,7 @@
>>  }
>>
>>  void Game::nextLevel() {
>> +       playSound(KStandardDirs::locate("sound", "kapman/levelup.ogg"));
>>        // Increment the level
>>        m_level++;
>>        // Initialize the maze items
>> --- trunk/playground/games/kapman/game.h #849578:849579
>> @@ -28,6 +28,7 @@
>>  #include <QTimer>
>>  #include <QKeyEvent>
>>  #include <KGameDifficulty>
>> +#include <Phonon/MediaObject>
>>
>>  /**
>>  * @brief This class manages the game main loop : it regularly checks  
>> the
>> key press events, computes the character moves and updates their
>> coordinates.
>> @@ -85,6 +86,9 @@
>>
>>                /** The number of eaten ghosts since the beginning of the
>> current level */
>>                int m_nbEatenGhosts;
>> +
>> +               /** A MediaObject to play sounds */
>> +               Phonon::MediaObject* m_media;
>>
>>        public:
>>
>> @@ -218,6 +222,12 @@
>>                 */
>>                void initCharactersPosition();
>>
>> +               /**
>> +                * Plays the given sound.
>> +                * @param p_sound the path to the sound to play
>> +                */
>> +               void playSound(const QString& p_sound);
>> +
>>        public slots:
>>
>>                /**
>> ** trunk/playground/games/kapman/sounds/bonus.ogg #property  
>> svn:mime-type
>>   + application/octet-stream
>> ** trunk/playground/games/kapman/sounds/energizer.ogg #property
>> svn:mime-type
>>   + application/octet-stream
>> ** trunk/playground/games/kapman/sounds/gameover.ogg #property
>> svn:mime-type
>>   + application/octet-stream
>> ** trunk/playground/games/kapman/sounds/ghost.ogg #property  
>> svn:mime-type
>>   + application/octet-stream
>> ** trunk/playground/games/kapman/sounds/levelup.ogg #property  
>> svn:mime-type
>>   + application/octet-stream
>> ** trunk/playground/games/kapman/sounds/pill.ogg #property svn:mime-type
>>   + application/octet-stream
>>



-- 
Thomas Gallinari

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic