gba-sprite-engine/engine/include/libgba-sprite-engine/gba_engine.h

73 lines
2.1 KiB
C
Raw Permalink Normal View History

2018-08-01 16:03:16 +02:00
//
// Created by Wouter Groeneveld on 28/07/18.
//
#ifndef GBA_SPRITE_ENGINE_GBAENGINE_H
#define GBA_SPRITE_ENGINE_GBAENGINE_H
#include <libgba-sprite-engine/sprites/sprite_manager.h>
#include <libgba-sprite-engine/gba/tonc_memmap.h>
#include <libgba-sprite-engine/gba/tonc_memdef.h>
#include <libgba-sprite-engine/effects/scene_effect.h>
#include "scene.h"
#include "sound_control.h"
2018-12-06 21:53:53 +01:00
#include "timer.h"
2018-08-07 09:23:00 +02:00
2018-08-08 14:43:34 +02:00
#define GBA_SCREEN_WIDTH 240
#define GBA_SCREEN_HEIGHT 160
2018-08-01 16:03:16 +02:00
class GBAEngine {
private:
2018-08-05 13:47:37 +02:00
// WHY raw pointers? the engine does the transition and cleanup work itself
2018-08-08 14:43:34 +02:00
Scene* currentScene;
Scene* sceneToTransitionTo;
2018-08-04 10:43:27 +02:00
SceneEffect* currentEffectForTransition;
2018-11-29 16:06:59 +01:00
bool disableTextBg;
2018-08-05 13:47:37 +02:00
SpriteManager spriteManager;
2018-12-06 21:53:53 +01:00
static std::unique_ptr<Timer> timer;
static std::unique_ptr<SoundControl> activeChannelA;
static std::unique_ptr<SoundControl> activeChannelB;
2018-08-07 09:23:00 +02:00
2018-08-07 14:32:20 +02:00
void vsync();
2018-08-05 13:47:37 +02:00
void cleanupPreviousScene();
2018-08-07 14:32:20 +02:00
void enqueueSound(const s8 *data, int totalSamples, int sampleRate, SoundChannel channel);
void enableTimer0AndVBlank();
void disableTimer0AndVBlank();
2018-08-07 14:32:20 +02:00
static void startOnVBlank() { REG_IME = 1; }
static void stopOnVBlank() { REG_IME = 0; }
2018-08-07 09:35:53 +02:00
static void onVBlank();
2018-08-01 16:03:16 +02:00
public:
GBAEngine();
2018-12-06 21:53:53 +01:00
Timer* getTimer();
2018-08-08 14:43:34 +02:00
void setScene(Scene* scene);
void dynamicallyAddSprite(Sprite* s) { spriteManager.add(s); }
2018-08-08 14:43:34 +02:00
void transitionIntoScene(Scene* scene, SceneEffect* effect);
bool isTransitioning() { return currentEffectForTransition != nullptr; }
2018-11-29 16:06:59 +01:00
void disableText() { this->disableTextBg = true; }
void enableText() { this->disableTextBg = false; }
2018-08-04 10:43:27 +02:00
2018-08-07 14:32:20 +02:00
void dequeueAllSounds();
2018-08-08 14:43:34 +02:00
void enqueueMusic(const s8 *data, int totalSamples, int sampleRate = 16000) {
enqueueSound(data, totalSamples, sampleRate, ChannelA);
2018-08-07 09:23:00 +02:00
}
2018-08-08 14:43:34 +02:00
void enqueueSound(const s8 *data, int totalSamples, int sampleRate = 16000) {
enqueueSound(data, totalSamples, sampleRate, ChannelB);
2018-08-07 09:23:00 +02:00
}
u16 readKeys();
void update();
void updateSpritesInScene();
2018-08-01 16:03:16 +02:00
void delay(int times) {
for(int i = 0; i < times; i++){}
}
};
#endif //GBA_SPRITE_ENGINE_GBAENGINE_H