[Kde-games-devel] Review Request 127284: KBlocks: Port sound to KgSound
Julian Helfferich
julian.helfferich at googlemail.com
Sun Mar 6 20:51:01 UTC 2016
> On March 6, 2016, 9:37 a.m., Frederik Schwarzer wrote:
> > Do you have any reason to move the enum outside of the class?
> > I am using C++ for some years now but have only started serious reading about it a few months ago. Meaning, my knowledge is pretty limited and I would like to understand, if there is a reason for that.
> >
> > Same goes for "virtual". I have not advanced to the "virtual" chapter of the book I am reading. So ... well, at least I cannot comment on that change. :D
> >
> > Otherwise I would say: "Ship it!", but you may want to wait a few days for others to comment.
Before I learned about enum classes, I always put enums in a namespace or inside a class to protect their scope. Thankfully, with enum classes this is no longer necessary.
If I had left the enum inside the class, it would be necessary to call
```cpp
KBlocksSound mSnd;
mSnd->playSound(KBlocksSound::Sound::BlockMove);
```
which I find redundant. If the enum is outside the class you can call
```cpp
mSnd->playSound(Sound::BlockMove);
```
which I find much nicer.
Virtual destructors are necessary if there are child classes. When you have
```cpp
BaseClass *pointer = new ChildClass();
delete pointer;
```
will the ChildClass destructor be called? If you have a virtual destructor in BaseClass the answer is yes. If you don't have a virtual destructor then nobody knows.
In this case, KBlocksSound is not designed to be inherited from. I have seen people declaring all destructors virtual. I do not have a strong opinion on this, but I prefer to omit unnecessary keywords.
> On March 6, 2016, 9:37 a.m., Frederik Schwarzer wrote:
> > KBlocksSound.cpp, lines 87-92
> > <https://git.reviewboard.kde.org/r/127284/diff/2/?file=448053#file448053line87>
> >
> > I think it's considered good practice to always have a default: label in every switch-case.
> > There you can have some debug output saying that a sound was requested that does not exist yet.
> >
> > I mean, if you add a sound to the enum and then forget to add in to the switch-case.
This is a very good point. Thank you for bringing this up.
- Julian
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://git.reviewboard.kde.org/r/127284/#review93222
-----------------------------------------------------------
On March 6, 2016, 8:35 p.m., Julian Helfferich wrote:
>
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://git.reviewboard.kde.org/r/127284/
> -----------------------------------------------------------
>
> (Updated March 6, 2016, 8:35 p.m.)
>
>
> Review request for KDE Games.
>
>
> Repository: kblocks
>
>
> Description
> -------
>
> Port sound in KBlocksSound from Phonon to KgSound. Note that neither before nor after this port sounds are played (the KBlocksSound::playSound() function is not called). I have also re-enabled the sound and will post the patch here once the port to KgSound is approved and pushed.
>
> The new KBlocksSound uses the sounds from the sounds/ directory. Previously it was intended (at least it seams so to me) that the sound is part of the theme. However, there are only two of three sounds in the themes/ directory (default theme). Thus, unless there are any themed sounds, I suggest to simply use the sounds from the sounds/ directory.
>
>
> Diffs
> -----
>
> CMakeLists.txt 38fdfd3
> KBlocksScene.cpp 07cd457
> KBlocksSound.h dc02775
> KBlocksSound.cpp 1346bc6
> sounds/CMakeLists.txt PRE-CREATION
>
> Diff: https://git.reviewboard.kde.org/r/127284/diff/
>
>
> Testing
> -------
>
> The testing were done for this patch plus the next patch enabling the sounds.
>
> * Played single game -> Sounds play correctly.
> * Played Human vs AI -> Sounds play only for human player (as intended).
> * Turned off/on sounds -> Sounds off/on correctly.
>
>
> Thanks,
>
> Julian Helfferich
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-games-devel/attachments/20160306/d8c8331e/attachment-0001.html>
More information about the kde-games-devel
mailing list