blob: d707124331f5528bf69391fd3a8d4e1d0aa7437c [file] [log] [blame]
Don Turner0db81a42018-03-29 17:48:12 +01001/*
2 * Copyright 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef RHYTHMGAME_GAME_H
18#define RHYTHMGAME_GAME_H
19
20#include <android/asset_manager.h>
21#include <oboe/Oboe.h>
Don Turnerf7923ae2018-04-03 22:43:27 +010022
23#include "audio/Mixer.h"
24#include "audio/SoundRecording.h"
25#include "ui/OpenGLFunctions.h"
26#include "utils/LockFreeQueue.h"
27#include "utils/UtilityFunctions.h"
Don Turnerbbdefad2018-04-26 12:58:44 +010028#include "GameConstants.h"
Don Turner0db81a42018-03-29 17:48:12 +010029
30using namespace oboe;
31
32class Game : public AudioStreamCallback {
33public:
Don Turnerf7923ae2018-04-03 22:43:27 +010034 explicit Game(AAssetManager *assetManager);
Don Turner0db81a42018-03-29 17:48:12 +010035
36 void start();
37 void onSurfaceCreated();
38 void onSurfaceDestroyed();
39 void onSurfaceChanged(int widthInPixels, int heightInPixels);
40 void tick();
41 void tap(int64_t eventTimeAsUptime);
42
Don Turnerf7923ae2018-04-03 22:43:27 +010043 // Inherited from oboe::AudioStreamCallback
Don Turner0db81a42018-03-29 17:48:12 +010044 DataCallbackResult
45 onAudioReady(AudioStream *oboeStream, void *audioData, int32_t numFrames) override;
46
47private:
Don Turner35d45432018-05-07 10:46:05 -070048 AAssetManager *mAssetManager{nullptr};
Don Turner254dc862018-05-07 10:50:01 -070049 AudioStream *mAudioStream{nullptr};
50 SoundRecording *mClap{nullptr};
51 SoundRecording *mBackingTrack{nullptr};
Don Turner0db81a42018-03-29 17:48:12 +010052 Mixer mMixer;
53
Don Turnerf7923ae2018-04-03 22:43:27 +010054 LockFreeQueue<int64_t, kMaxQueueItems> mClapEvents;
Don Turnerbbdefad2018-04-26 12:58:44 +010055 std::atomic<int64_t> mCurrentFrame { 0 };
Don Turnerf7923ae2018-04-03 22:43:27 +010056 LockFreeQueue<int64_t, kMaxQueueItems> mClapWindows;
57 LockFreeQueue<TapResult, kMaxQueueItems> mUiEvents;
Don Turner0db81a42018-03-29 17:48:12 +010058 std::atomic<int64_t> mLastUpdateTime { 0 };
59};
60
61
62#endif //RHYTHMGAME_GAME_H