tryout splash image in demo2

This commit is contained in:
wgroeneveld 2018-11-29 16:06:59 +01:00
parent 730d44ebee
commit be655e9efe
22 changed files with 25874 additions and 6 deletions

View File

@ -154,10 +154,20 @@ The paddle auto-stays within bounds.
Each sprite has own raw data, so there's no shared sprite image (for the better). The palette of course is shared, so think about that when exporting with a tool like [grit](https://www.coranac.com/man/grit/html/grit.htm) or [png2gba](https://github.com/IanFinlayson/png2gba). Grit has flags to export a shared palette:
> ./../grit pic1.png pic2.png kul.png -ftc -pS -gB8 -O shared.c
> grit pic1.png pic2.png kul.png -ftc -pS -gB8 -O shared.c
Consult the [Grit list of cmdline options](https://www.coranac.com/man/grit/html/grit.htm) for more information.
Extracting a tilemap from a big image to create a splash-like intro screen can be done using these options:
> grit splashimage.png -gt -gB8 -mRtpf -mLs -ftc
It will export:
1. A tileset. Your data, to be injected into background VRAM char blocks.
2. A tilemap. Your metadata, to be injected into the next free background VRAM screen block.
3. A palette. Your one and only background palette.
#### Sound
The engine supports **sounds** and **background music** using GBA's Active Sound channel A and B. It's a simple implementation meaning no mixing in either channels (but A and B are mixed).

View File

@ -4,7 +4,7 @@ add_executable(${PROJECT_NAME}.elf
src/main.cpp
src/pats.h
src/arkanoid_game_scene.cpp
src/arkanoid_game_scene.h src/spritedata.h src/dead.h)
src/arkanoid_game_scene.h src/spritedata.h src/dead.h src/SplashScreen.cpp src/SplashScreen.h src/splashimage.h)
target_link_libraries(${PROJECT_NAME}.elf gba-sprite-engine)

View File

Before

Width:  |  Height:  |  Size: 118 B

After

Width:  |  Height:  |  Size: 118 B

View File

Before

Width:  |  Height:  |  Size: 98 B

After

Width:  |  Height:  |  Size: 98 B

View File

Before

Width:  |  Height:  |  Size: 98 B

After

Width:  |  Height:  |  Size: 98 B

View File

Before

Width:  |  Height:  |  Size: 151 B

After

Width:  |  Height:  |  Size: 151 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,49 @@
//
// Created by Wouter Groeneveld on 29/11/18.
//
#include <libgba-sprite-engine/gba/tonc_memdef.h>
#include <libgba-sprite-engine/effects/fade_out_scene.h>
#include "SplashScreen.h"
#include "arkanoid_game_scene.h"
#include "splashimage.h"
#include "omnom.h"
SplashScreen::SplashScreen(const std::shared_ptr<GBAEngine> &engine) : Scene(engine) {}
std::vector<Sprite *> SplashScreen::sprites() {
return {};
}
std::vector<Background *> SplashScreen::backgrounds() {
return {
bg.get()
};
}
void SplashScreen::tick(u16 keys) {
if(keys & KEY_ANY) {
engine->setScene(new ArkanoidGameScene(engine));
}
}
void SplashScreen::load() {
// we need to disable the text background because the splash screen is too big and fills up al char blocks (including map)
// remember, we have background char blocks 0, 1, 2, 3, each consisting of 8 screen blocks, from 0x6000000 to 0x6000f800 (last screen block, 31)
engine.get()->disableText();
backgroundPalette = std::unique_ptr<BackgroundPaletteManager>(new BackgroundPaletteManager(splashimagePal, sizeof(splashimagePal)));
// use background number 0, as the text bg is disabled, to start dumping into VRAM from 0x6000000
// data exported from grit using: "grit splashimage.png -gt -gB8 -mRtpf -mLs -ftc", see https://www.coranac.com/man/grit/html/grit.htm or https://github.com/devkitPro/grit/blob/master/grit-readme.txt
// do NOT use "-Mw" or "-Mh", regular map needed, no metamap.
// the photograph was first edited in GIMP to contain max. 255 colors using image -> mode -> indexed colors.
bg = std::unique_ptr<Background>(new Background(0, splashimageTiles, sizeof(splashimageTiles), splashimageMap, sizeof(splashimageMap)));
// the last char block (3) starts at screen block 24, is still available to dump the tilemap in.
bg.get()->useMapScreenBlock(24);
engine.get()->enqueueSound(omnom, omnom_bytes, 44200);
}

View File

@ -0,0 +1,28 @@
//
// Created by Wouter Groeneveld on 29/11/18.
//
#ifndef GBA_SPRITE_ENGINE_PROJECT_SPLASHSCREEN_H
#define GBA_SPRITE_ENGINE_PROJECT_SPLASHSCREEN_H
#include <libgba-sprite-engine/scene.h>
class SplashScreen : public Scene {
private:
std::unique_ptr<Background> bg;
public:
SplashScreen(const std::shared_ptr<GBAEngine> &engine);
std::vector<Sprite *> sprites() override;
std::vector<Background *> backgrounds() override;
void load() override;
void tick(u16 keys) override;
};
#endif //GBA_SPRITE_ENGINE_PROJECT_SPLASHSCREEN_H

View File

@ -78,6 +78,7 @@ void ArkanoidGameScene::tick(u16 keys) {
}
void ArkanoidGameScene::load() {
engine.get()->enableText();
foregroundPalette = std::unique_ptr<ForegroundPaletteManager>(new ForegroundPaletteManager(paletteSharedPal, sizeof(paletteSharedPal)));
SpriteBuilder<Sprite> builder;

View File

@ -6,11 +6,12 @@
#include <libgba-sprite-engine/gba_engine.h>
#include "arkanoid_game_scene.h"
#include "SplashScreen.h"
int main() {
std::shared_ptr<GBAEngine> engine(new GBAEngine());
auto scene = new ArkanoidGameScene(engine);
auto scene = new SplashScreen(engine);
engine->setScene(scene);
while (true) {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -30,6 +30,7 @@ public:
screenBlockIndex(0), charBlockIndex(0), mapSize(mapSize) {}
virtual void persist();
void clearMap();
void clearData();
};

View File

@ -23,6 +23,7 @@ private:
Scene* sceneToTransitionTo;
SceneEffect* currentEffectForTransition;
bool disableTextBg;
SpriteManager spriteManager;
static std::unique_ptr<SoundControl> activeChannelA;
@ -43,6 +44,8 @@ public:
void dynamicallyAddSprite(Sprite* s) { spriteManager.add(s); }
void transitionIntoScene(Scene* scene, SceneEffect* effect);
bool isTransitioning() { return currentEffectForTransition != nullptr; }
void disableText() { this->disableTextBg = true; }
void enableText() { this->disableTextBg = false; }
void dequeueAllSounds();
void enqueueMusic(const s8 *data, int totalSamples, int sampleRate = 16000) {

View File

@ -30,7 +30,7 @@ public:
virtual std::vector<Background*> backgrounds() = 0;
virtual void load() = 0;
virtual void tick(u16 i) = 0;
virtual void tick(u16 keys) = 0;
Scene(std::shared_ptr<GBAEngine> engine) :
engine(engine),

View File

@ -36,6 +36,12 @@ void Background::persist() {
buildRegister();
}
void Background::clearData() {
this->clearMap();
int empty[this->size];
dma3_cpy(char_block(bgIndex), empty, this->size);
}
void Background::clearMap() {
volatile auto ptr = &se_mem[screenBlockIndex][0];
for (int i = 0; i < this->mapSize; i++) {

View File

@ -100,6 +100,7 @@ GBAEngine::GBAEngine() {
*IRQ_CALLBACK = (u32) &GBAEngine::onVBlank;
REG_SNDDSCNT = 0;
disableTextBg = false;
Allocator::free();
}
@ -131,6 +132,10 @@ void GBAEngine::transitionIntoScene(Scene* scene, SceneEffect* effect) {
}
void GBAEngine::cleanupPreviousScene() {
for(auto bg : currentScene->backgrounds()) {
bg->clearData();
}
delete currentScene;
sceneToTransitionTo = nullptr;
delete currentEffectForTransition;
@ -140,9 +145,11 @@ void GBAEngine::setScene(Scene* scene) {
dequeueAllSounds();
if(this->currentScene) {
cleanupPreviousScene();
TextStream::instance().clear();
}
scene->load();
if(!this->disableTextBg) {
TextStream::instance().clear();
}
auto fgPalette = scene->getForegroundPalette();
if(!fgPalette) {
@ -155,7 +162,9 @@ void GBAEngine::setScene(Scene* scene) {
}
bgPalette->persist();
TextStream::instance().persist();
if(!this->disableTextBg) {
TextStream::instance().persist();
}
for(const auto bg : scene->backgrounds()) {
bg->persist();