fix timer usage without sound enabling, performance measure food demo

This commit is contained in:
wgroeneveld 2018-12-18 16:23:08 +01:00
parent be37416bcf
commit 0351deb3d4
7 changed files with 38 additions and 10 deletions

View File

@ -46,6 +46,15 @@ VECTOR FoodScene::rotateAround(VECTOR center, VECTOR point) {
}
void FoodScene::tick(u16 keys) {
if(engine->getTimer()->getTotalMsecs() < 5000) {
counter++;
} else {
engine->getTimer()->stop();
}
TextStream::instance().setText(std::to_string(counter) + std::string(" frames/5sec"), 5, 1);
TextStream::instance().setText(std::string(engine->getTimer()->to_string()), 6, 1);
avatar->animateToFrame(0);
bool allowedToShoot = false;
int oldBulletSize = bullets.size();
@ -123,8 +132,7 @@ void FoodScene::load() {
// rotation of a point on a circle within the resolution means our radius should be big enough
defaultBulletTarget = { GBA_SCREEN_WIDTH / 2, GBA_SCREEN_HEIGHT + (GBA_SCREEN_WIDTH / 2) - avatar->getCenter().y + 40};
/*
/*
for(int i = 0; i < 10; i++) {
for(int j = 0; j < 4; j++) {
bullets.push_back(createBullet());
@ -135,6 +143,7 @@ void FoodScene::load() {
b->getSprite()->moveTo(10 + (i * 20), 100 + (j * 20));
}
}
}
*/
}*/
engine->getTimer()->start();
}

View File

@ -13,6 +13,7 @@
class FoodScene : public Scene {
private:
int counter = 0;
std::unique_ptr<AffineSprite> avatar;
std::unique_ptr<Sprite> someBulletSprite;
std::vector<std::unique_ptr<Bullet>> bullets;

View File

@ -35,6 +35,8 @@ private:
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();

View File

@ -30,6 +30,7 @@ public:
std::string to_string();
int getTotalMsecs();
int getMsecs() { return msecs; }
int getSecs() { return secs; }
int getMinutes() { return minutes; }

View File

@ -56,9 +56,6 @@ u16 GBAEngine::readKeys() {
}
void GBAEngine::dequeueAllSounds() {
stopOnVBlank();
vsync();
if(GBAEngine::activeChannelA) {
GBAEngine::activeChannelA->disable();
} if(GBAEngine::activeChannelB) {
@ -81,8 +78,7 @@ void GBAEngine::enqueueSound(const s8 *data, int totalSamples, int sampleRate, S
control = GBAEngine::activeChannelB.get();
}
stopOnVBlank();
REG_TM0CNT = 0;
disableTimer0AndVBlank();
control->disable();
REG_SNDDSCNT |= control->getControlFlags(); // output to both sides, reset fifo
@ -90,11 +86,21 @@ void GBAEngine::enqueueSound(const s8 *data, int totalSamples, int sampleRate, S
u16 ticksPerSample = CLOCK / sampleRate; // divide the clock (ticks/second) by the sample rate (samples/second)
control->accept(data, totalSamples, ticksPerSample);
startOnVBlank();
control->enable();
REG_TM0D = OVERFLOW_16_BIT_VALUE - ticksPerSample;
enableTimer0AndVBlank();
}
void GBAEngine::disableTimer0AndVBlank() {
stopOnVBlank();
REG_TM0CNT = 0;
}
void GBAEngine::enableTimer0AndVBlank() {
REG_TM0CNT = TM_ENABLE | TM_FREQ_1; // enable timer - dma auto-syncs to this thanks to DMA_SYNC_TO_TIMER
startOnVBlank();
}
GBAEngine::GBAEngine() {
@ -107,6 +113,8 @@ GBAEngine::GBAEngine() {
REG_IE |= INTERRUPT_VBLANK;
*IRQ_CALLBACK = (u32) &GBAEngine::onVBlank;
enableTimer0AndVBlank();
REG_SNDDSCNT = 0;
disableTextBg = false;
Allocator::free();
@ -156,6 +164,7 @@ void GBAEngine::cleanupPreviousScene() {
void GBAEngine::setScene(Scene* scene) {
dequeueAllSounds();
if(this->currentScene) {
cleanupPreviousScene();
if(!this->disableTextBg) {

View File

@ -67,6 +67,8 @@ void Sprite::syncOam() {
}
void Sprite::updateVelocity() {
if(dx == 0 && dy == 0) return;
this->x += this->dx;
this->y += this->dy;

View File

@ -33,6 +33,10 @@ void Timer::onvblank() {
}
}
int Timer::getTotalMsecs() {
return msecs + (hours * 60 * 60 + minutes * 60 + secs) * 1000;
}
std::string Timer::to_string() {
std::ostringstream stringStream;
stringStream << *this;