2020-07-08 09:05:02 +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/gba/tonc_memmap.h>
|
2020-07-09 13:29:02 +02:00
|
|
|
#include <libgba-sprite-engine/gba/tonc_memmap.h>
|
|
|
|
#include <libgba-sprite-engine/vectorfx.h>
|
2020-07-10 14:41:32 +02:00
|
|
|
#include <libgba-sprite-engine/vectorpx.h>
|
2020-07-09 13:29:02 +02:00
|
|
|
#include <libgba-sprite-engine/matrixfx.h>
|
2020-07-08 09:05:02 +02:00
|
|
|
#include "scene.h"
|
|
|
|
#include "sound_control.h"
|
|
|
|
#include "timer.h"
|
|
|
|
|
2020-07-08 18:12:38 +02:00
|
|
|
|
|
|
|
const unsigned int black[VRAM_PAGE_SIZE] = {};
|
2020-07-08 09:05:02 +02:00
|
|
|
|
|
|
|
class GBAEngine {
|
|
|
|
private:
|
|
|
|
// WHY raw pointers? the engine does the transition and cleanup work itself
|
|
|
|
Scene* currentScene;
|
2020-07-09 13:29:02 +02:00
|
|
|
Camera currentCamera;
|
2020-07-08 09:05:02 +02:00
|
|
|
Scene* sceneToTransitionTo;
|
|
|
|
|
2020-07-09 15:48:03 +02:00
|
|
|
MatrixFx projectionMatrix;
|
2020-07-08 18:12:38 +02:00
|
|
|
|
2020-07-08 09:05:02 +02:00
|
|
|
static std::unique_ptr<Timer> timer;
|
|
|
|
static std::unique_ptr<SoundControl> activeChannelA;
|
|
|
|
static std::unique_ptr<SoundControl> activeChannelB;
|
|
|
|
|
|
|
|
void vsync();
|
|
|
|
void cleanupPreviousScene();
|
|
|
|
void enqueueSound(const s8 *data, int totalSamples, int sampleRate, SoundChannel channel);
|
|
|
|
|
|
|
|
void enableTimer0AndVBlank();
|
|
|
|
void disableTimer0AndVBlank();
|
|
|
|
static void startOnVBlank() { REG_IME = 1; }
|
|
|
|
static void stopOnVBlank() { REG_IME = 0; }
|
|
|
|
static void onVBlank();
|
|
|
|
|
2020-07-08 18:12:38 +02:00
|
|
|
void render();
|
|
|
|
void renderClear();
|
2020-07-10 14:41:32 +02:00
|
|
|
inline VectorPx project(const VectorFx &coord, const MatrixFx &transMat);
|
2020-07-08 18:12:38 +02:00
|
|
|
void flipPage();
|
|
|
|
|
2020-07-08 09:05:02 +02:00
|
|
|
public:
|
|
|
|
GBAEngine();
|
|
|
|
|
|
|
|
Timer* getTimer();
|
|
|
|
void setScene(Scene* scene);
|
|
|
|
|
|
|
|
void dequeueAllSounds();
|
|
|
|
void enqueueMusic(const s8 *data, int totalSamples, int sampleRate = 16000) {
|
|
|
|
enqueueSound(data, totalSamples, sampleRate, ChannelA);
|
|
|
|
}
|
|
|
|
void enqueueSound(const s8 *data, int totalSamples, int sampleRate = 16000) {
|
|
|
|
enqueueSound(data, totalSamples, sampleRate, ChannelB);
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 readKeys();
|
|
|
|
void update();
|
2020-07-10 14:41:32 +02:00
|
|
|
inline void delay(int times) {
|
2020-07-08 09:05:02 +02:00
|
|
|
for(int i = 0; i < times; i++){}
|
|
|
|
}
|
2020-07-10 14:41:32 +02:00
|
|
|
|
2020-07-10 20:14:47 +02:00
|
|
|
inline void plotPixel(int x, int y, u8 clrId);
|
2020-07-10 14:41:32 +02:00
|
|
|
inline void plotPixel(const VectorPx &pixel, u8 clrId);
|
|
|
|
inline void plotLine(const VectorPx &point0, const VectorPx &point1, u8 clrId);
|
2020-07-08 09:05:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //GBA_SPRITE_ENGINE_GBAENGINE_H
|