File indexing completed on 2024-05-12 04:06:03

0001 /*
0002     SPDX-FileCopyrightText: 2010 Stefan Majewsky <majewsky@gmx.net>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #ifndef KGAMEOPENALRUNTIME_P_H
0008 #define KGAMEOPENALRUNTIME_P_H
0009 
0010 // Qt
0011 #include <QHash>
0012 #include <QPointF>
0013 // OpenAL includes (without "AL/" include directory; see FindOpenAL.cmake)
0014 #include <al.h>
0015 #include <alc.h>
0016 
0017 class KGameSound;
0018 
0019 /// @internal
0020 class KGamePlaybackEvent
0021 {
0022 public:
0023     // Creates and starts the playback. Also registers with the OpenALRuntime.
0024     KGamePlaybackEvent(KGameSound *sound, QPointF pos);
0025     // Stops playback if it is still running.
0026     ~KGamePlaybackEvent();
0027 
0028     // Is playback still running?
0029     bool isRunning() const;
0030     bool replay(QPointF pos) const;
0031 
0032 private:
0033     ALuint m_source;
0034     bool m_valid;
0035 };
0036 
0037 typedef QList<KGamePlaybackEvent *> KGamePlaybackEventList;
0038 
0039 /// @internal
0040 class KGameOpenALRuntime
0041 {
0042 public:
0043     KGameOpenALRuntime();
0044     ~KGameOpenALRuntime();
0045 
0046     static KGameOpenALRuntime *instance();
0047 
0048     void configureListener();
0049     void cleanupUnusedSources();
0050 
0051     // global properties
0052     QPointF m_listenerPos;
0053     qreal m_volume;
0054     bool m_error;
0055     // active sound and playback instances
0056     QHash<KGameSound *, KGamePlaybackEventList> m_soundsEvents;
0057 
0058 private:
0059     ALCcontext *m_context;
0060     ALCdevice *m_device;
0061 };
0062 
0063 #endif // KGAMEOPENALRUNTIME_P_H