fix timer usage without sound enabling, performance measure food demo
This commit is contained in:
parent
be37416bcf
commit
0351deb3d4
|
@ -46,6 +46,15 @@ VECTOR FoodScene::rotateAround(VECTOR center, VECTOR point) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FoodScene::tick(u16 keys) {
|
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);
|
avatar->animateToFrame(0);
|
||||||
bool allowedToShoot = false;
|
bool allowedToShoot = false;
|
||||||
int oldBulletSize = bullets.size();
|
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
|
// 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};
|
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 i = 0; i < 10; i++) {
|
||||||
for(int j = 0; j < 4; j++) {
|
for(int j = 0; j < 4; j++) {
|
||||||
bullets.push_back(createBullet());
|
bullets.push_back(createBullet());
|
||||||
|
@ -135,6 +143,7 @@ void FoodScene::load() {
|
||||||
b->getSprite()->moveTo(10 + (i * 20), 100 + (j * 20));
|
b->getSprite()->moveTo(10 + (i * 20), 100 + (j * 20));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
*/
|
|
||||||
|
engine->getTimer()->start();
|
||||||
}
|
}
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
class FoodScene : public Scene {
|
class FoodScene : public Scene {
|
||||||
private:
|
private:
|
||||||
|
int counter = 0;
|
||||||
std::unique_ptr<AffineSprite> avatar;
|
std::unique_ptr<AffineSprite> avatar;
|
||||||
std::unique_ptr<Sprite> someBulletSprite;
|
std::unique_ptr<Sprite> someBulletSprite;
|
||||||
std::vector<std::unique_ptr<Bullet>> bullets;
|
std::vector<std::unique_ptr<Bullet>> bullets;
|
||||||
|
|
|
@ -35,6 +35,8 @@ private:
|
||||||
void cleanupPreviousScene();
|
void cleanupPreviousScene();
|
||||||
void enqueueSound(const s8 *data, int totalSamples, int sampleRate, SoundChannel channel);
|
void enqueueSound(const s8 *data, int totalSamples, int sampleRate, SoundChannel channel);
|
||||||
|
|
||||||
|
void enableTimer0AndVBlank();
|
||||||
|
void disableTimer0AndVBlank();
|
||||||
static void startOnVBlank() { REG_IME = 1; }
|
static void startOnVBlank() { REG_IME = 1; }
|
||||||
static void stopOnVBlank() { REG_IME = 0; }
|
static void stopOnVBlank() { REG_IME = 0; }
|
||||||
static void onVBlank();
|
static void onVBlank();
|
||||||
|
|
|
@ -30,6 +30,7 @@ public:
|
||||||
|
|
||||||
std::string to_string();
|
std::string to_string();
|
||||||
|
|
||||||
|
int getTotalMsecs();
|
||||||
int getMsecs() { return msecs; }
|
int getMsecs() { return msecs; }
|
||||||
int getSecs() { return secs; }
|
int getSecs() { return secs; }
|
||||||
int getMinutes() { return minutes; }
|
int getMinutes() { return minutes; }
|
||||||
|
|
|
@ -56,9 +56,6 @@ u16 GBAEngine::readKeys() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBAEngine::dequeueAllSounds() {
|
void GBAEngine::dequeueAllSounds() {
|
||||||
stopOnVBlank();
|
|
||||||
vsync();
|
|
||||||
|
|
||||||
if(GBAEngine::activeChannelA) {
|
if(GBAEngine::activeChannelA) {
|
||||||
GBAEngine::activeChannelA->disable();
|
GBAEngine::activeChannelA->disable();
|
||||||
} if(GBAEngine::activeChannelB) {
|
} if(GBAEngine::activeChannelB) {
|
||||||
|
@ -81,8 +78,7 @@ void GBAEngine::enqueueSound(const s8 *data, int totalSamples, int sampleRate, S
|
||||||
control = GBAEngine::activeChannelB.get();
|
control = GBAEngine::activeChannelB.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
stopOnVBlank();
|
disableTimer0AndVBlank();
|
||||||
REG_TM0CNT = 0;
|
|
||||||
control->disable();
|
control->disable();
|
||||||
|
|
||||||
REG_SNDDSCNT |= control->getControlFlags(); // output to both sides, reset fifo
|
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)
|
u16 ticksPerSample = CLOCK / sampleRate; // divide the clock (ticks/second) by the sample rate (samples/second)
|
||||||
|
|
||||||
control->accept(data, totalSamples, ticksPerSample);
|
control->accept(data, totalSamples, ticksPerSample);
|
||||||
startOnVBlank();
|
|
||||||
control->enable();
|
control->enable();
|
||||||
|
|
||||||
REG_TM0D = OVERFLOW_16_BIT_VALUE - ticksPerSample;
|
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
|
REG_TM0CNT = TM_ENABLE | TM_FREQ_1; // enable timer - dma auto-syncs to this thanks to DMA_SYNC_TO_TIMER
|
||||||
|
startOnVBlank();
|
||||||
}
|
}
|
||||||
|
|
||||||
GBAEngine::GBAEngine() {
|
GBAEngine::GBAEngine() {
|
||||||
|
@ -107,6 +113,8 @@ GBAEngine::GBAEngine() {
|
||||||
REG_IE |= INTERRUPT_VBLANK;
|
REG_IE |= INTERRUPT_VBLANK;
|
||||||
*IRQ_CALLBACK = (u32) &GBAEngine::onVBlank;
|
*IRQ_CALLBACK = (u32) &GBAEngine::onVBlank;
|
||||||
|
|
||||||
|
enableTimer0AndVBlank();
|
||||||
|
|
||||||
REG_SNDDSCNT = 0;
|
REG_SNDDSCNT = 0;
|
||||||
disableTextBg = false;
|
disableTextBg = false;
|
||||||
Allocator::free();
|
Allocator::free();
|
||||||
|
@ -156,6 +164,7 @@ void GBAEngine::cleanupPreviousScene() {
|
||||||
|
|
||||||
void GBAEngine::setScene(Scene* scene) {
|
void GBAEngine::setScene(Scene* scene) {
|
||||||
dequeueAllSounds();
|
dequeueAllSounds();
|
||||||
|
|
||||||
if(this->currentScene) {
|
if(this->currentScene) {
|
||||||
cleanupPreviousScene();
|
cleanupPreviousScene();
|
||||||
if(!this->disableTextBg) {
|
if(!this->disableTextBg) {
|
||||||
|
|
|
@ -67,6 +67,8 @@ void Sprite::syncOam() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::updateVelocity() {
|
void Sprite::updateVelocity() {
|
||||||
|
if(dx == 0 && dy == 0) return;
|
||||||
|
|
||||||
this->x += this->dx;
|
this->x += this->dx;
|
||||||
this->y += this->dy;
|
this->y += this->dy;
|
||||||
|
|
||||||
|
|
|
@ -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::string Timer::to_string() {
|
||||||
std::ostringstream stringStream;
|
std::ostringstream stringStream;
|
||||||
stringStream << *this;
|
stringStream << *this;
|
||||||
|
|
Loading…
Reference in New Issue