allow bigger tilemaps and custom charblocks in BGs
This commit is contained in:
parent
ec18d62171
commit
a4fb01b87a
|
@ -123,6 +123,8 @@ Creating a background:
|
|||
|
||||
Backgrounds work a bit different in VRAM compared to sprites. There are only 4 backgrounds available, and background #4 is taken by the font. Parameter 1 identifies your background used for prioritizing. Remember to use a screen block different than your map data.
|
||||
|
||||
If you want to create bigger maps than 32x32, use `MAPLAYOUT_64x64` or similar in the second constructor.
|
||||
|
||||
#### Sprites
|
||||
|
||||
Conjuring sprites on the screen is a matter of exposing them to the sprites vector in your scene. Create them in your load and set them as a `std::unique_ptr` member variable in your scene so they get cleaned up automatically.
|
||||
|
|
|
@ -8,6 +8,11 @@
|
|||
|
||||
#include <libgba-sprite-engine/gba/tonc_types.h>
|
||||
|
||||
#define MAPLAYOUT_32X32 0
|
||||
#define MAPLAYOUT_32X64 1
|
||||
#define MAPLAYOUT_64X32 2
|
||||
#define MAPLAYOUT_64X64 3
|
||||
|
||||
class Background {
|
||||
private:
|
||||
void buildRegister();
|
||||
|
@ -17,7 +22,7 @@ protected:
|
|||
const void *data;
|
||||
const void *map;
|
||||
int size, bgIndex;
|
||||
int mapSize;
|
||||
int mapSize, mapLayout;
|
||||
int screenBlockIndex, charBlockIndex;
|
||||
|
||||
public:
|
||||
|
@ -27,8 +32,15 @@ public:
|
|||
void scroll(int x, int y);
|
||||
void scrollSpeed(int dx, int dy);
|
||||
|
||||
Background(int bgIndex, const void *data, int size, const void* map, int mapSize) : data(data), bgIndex(bgIndex), size(size), map(map),
|
||||
screenBlockIndex(0), charBlockIndex(0), mapSize(mapSize) {}
|
||||
Background(int bgIndex, const void *data, int size, const void* map, int mapSize, int screenBlockIndex, int charBlockIndex, int mapLayout)
|
||||
: Background(bgIndex, data, size, map, mapSize) {
|
||||
this->screenBlockIndex = screenBlockIndex;
|
||||
this->charBlockIndex = charBlockIndex;
|
||||
this->mapLayout = mapLayout;
|
||||
}
|
||||
|
||||
Background(int bgIndex, const void *data, int size, const void* map, int mapSize) : data(data), bgIndex(bgIndex), size(size), map(map), mapLayout(MAPLAYOUT_32X32),
|
||||
screenBlockIndex(0), charBlockIndex(bgIndex), mapSize(mapSize) {}
|
||||
virtual void persist();
|
||||
void updateMap(const void* map);
|
||||
void clearMap();
|
||||
|
|
|
@ -32,7 +32,7 @@ void Background::updateMap(const void *map) {
|
|||
}
|
||||
|
||||
void Background::persist() {
|
||||
dma3_cpy(char_block(bgIndex), this->data, this->size);
|
||||
dma3_cpy(char_block(charBlockIndex), this->data, this->size);
|
||||
|
||||
if(this->map) {
|
||||
dma3_cpy(screen_block(screenBlockIndex), this->map, this->mapSize);
|
||||
|
@ -44,7 +44,7 @@ void Background::persist() {
|
|||
void Background::clearData() {
|
||||
this->clearMap();
|
||||
int empty[this->size];
|
||||
dma3_cpy(char_block(bgIndex), empty, this->size);
|
||||
dma3_cpy(char_block(charBlockIndex), empty, this->size);
|
||||
}
|
||||
|
||||
void Background::clearMap() {
|
||||
|
@ -67,12 +67,12 @@ u32 Background::getBgControlRegisterIndex() {
|
|||
void Background::buildRegister() {
|
||||
*(vu16*)(REG_BASE+getBgControlRegisterIndex()) =
|
||||
bgIndex | /* priority, 0 is highest, 3 is lowest */
|
||||
(bgIndex << 2) | /* the char block the image data is stored in */
|
||||
(charBlockIndex << 2) | /* the char block the image data is stored in */
|
||||
(0 << 6) | /* the mosaic flag */
|
||||
(1 << 7) | /* color mode, 0 is 16 colors, 1 is 256 colors */
|
||||
(screenBlockIndex << 8) | /* the screen block the tile data is stored in */
|
||||
(1 << 13) | /* wrapping flag */
|
||||
(0 << 14);
|
||||
(mapLayout << 14);
|
||||
}
|
||||
|
||||
void Background::scroll(int x, int y) {
|
||||
|
|
|
@ -37,6 +37,6 @@ add_executable(unittest
|
|||
../engine/src/palette/combined_palette.cpp
|
||||
../engine/src/timer.cpp
|
||||
../engine/src/gbavector.cpp
|
||||
timertest.cpp gbavectortest.cpp)
|
||||
timertest.cpp gbavectortest.cpp backgroundtest.cpp)
|
||||
|
||||
target_link_libraries(unittest ${GTEST_LIBRARY}/build/libgtest.a ${GTEST_LIBRARY}/build/libgtest_main.a)
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
//
|
||||
// Created by Wouter Groeneveld on 12/12/19.
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <libgba-sprite-engine/background/background.h>
|
||||
|
||||
class BGTestSuite : public ::testing::Test {
|
||||
protected:
|
||||
virtual void TearDown() {
|
||||
}
|
||||
|
||||
virtual void SetUp() {
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(BGTestSuite, Create_Background_Can_Set_Custom_ScreenAndMapAndLayout) {
|
||||
Background bg(1, NULL, 100, NULL, 200, 15, 16, MAPLAYOUT_64X64);
|
||||
|
||||
ASSERT_EQ(16, bg.getCharBlock());
|
||||
ASSERT_EQ(15, bg.getScreenBlock());
|
||||
}
|
||||
|
||||
TEST_F(BGTestSuite, Create_Background_CharBlockIsBgIndex_ByDefault) {
|
||||
Background bg(1, NULL, 100, NULL, 200);
|
||||
|
||||
ASSERT_EQ(1, bg.getCharBlock());
|
||||
ASSERT_EQ(0, bg.getScreenBlock());
|
||||
}
|
Loading…
Reference in New Issue