combining palettes for bulk manipulation
This commit is contained in:
parent
d3ef6a5160
commit
ceb2be7214
|
@ -2,7 +2,7 @@ SET(CMAKE_C_COMPILER arm-none-eabi-gcc)
|
||||||
SET(CMAKE_CXX_COMPILER arm-none-eabi-g++)
|
SET(CMAKE_CXX_COMPILER arm-none-eabi-g++)
|
||||||
|
|
||||||
set_property(SOURCE engine/gba/sin_lut.s PROPERTY LANGUAGE C)
|
set_property(SOURCE engine/gba/sin_lut.s PROPERTY LANGUAGE C)
|
||||||
add_executable(${PROJECT_NAME}.elf main.cpp engine/sprites/sprite_manager.cpp engine/sprites/sprite_manager.h engine/gba/tonc_memmap.h engine/gba/tonc_core.h engine/gba/tonc_memdef.h engine/gba/tonc_types.h engine/sprites/sprite.cpp engine/sprites/sprite.h kul.h engine/palette_manager.cpp engine/palette_manager.h engine/allocator.cpp engine/allocator.h engine/gba/tonc_oam.h engine/gba/tonc_math.h engine/gba/sin_lut.s engine/Scene.cpp engine/Scene.h engine/sprites/sprite_builder.cpp engine/sprites/sprite_builder.h engine/sprites/affine_sprite.cpp engine/sprites/affine_sprite.h flying_stuff_scene.cpp flying_stuff_scene.h engine/gba_engine.cpp engine/gba_engine.h engine/background/text_stream.cpp engine/background/text_stream.h engine/background/background.cpp engine/background/background.h engine/background/text.h sample_start_scene.cpp sample_start_scene.h engine/sprites/animated_sprite.cpp engine/sprites/animated_sprite.h engine/effects/fade_out_scene.cpp engine/effects/fade_out_scene.h engine/gba/tonc_core_stub.h engine/effects/scene_effect.h)
|
add_executable(${PROJECT_NAME}.elf main.cpp engine/sprites/sprite_manager.cpp engine/sprites/sprite_manager.h engine/gba/tonc_memmap.h engine/gba/tonc_core.h engine/gba/tonc_memdef.h engine/gba/tonc_types.h engine/sprites/sprite.cpp engine/sprites/sprite.h kul.h engine/palette/palette_manager.cpp engine/palette/palette_manager.h engine/palette/combined_palette.cpp engine/palette/combined_palette.h engine/allocator.cpp engine/allocator.h engine/gba/tonc_oam.h engine/gba/tonc_math.h engine/gba/sin_lut.s engine/Scene.cpp engine/Scene.h engine/sprites/sprite_builder.cpp engine/sprites/sprite_builder.h engine/sprites/affine_sprite.cpp engine/sprites/affine_sprite.h flying_stuff_scene.cpp flying_stuff_scene.h engine/gba_engine.cpp engine/gba_engine.h engine/background/text_stream.cpp engine/background/text_stream.h engine/background/background.cpp engine/background/background.h engine/background/text.h sample_start_scene.cpp sample_start_scene.h engine/sprites/animated_sprite.cpp engine/sprites/animated_sprite.h engine/effects/fade_out_scene.cpp engine/effects/fade_out_scene.h engine/gba/tonc_core_stub.h engine/effects/scene_effect.h)
|
||||||
|
|
||||||
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
|
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
|
||||||
COMMAND ${CMAKE_OBJCOPY} -v -O binary ${PROJECT_NAME}.elf ${PROJECT_NAME}.gba
|
COMMAND ${CMAKE_OBJCOPY} -v -O binary ${PROJECT_NAME}.elf ${PROJECT_NAME}.gba
|
||||||
|
|
|
@ -6,6 +6,6 @@
|
||||||
|
|
||||||
#include <engine/gba_engine.h>
|
#include <engine/gba_engine.h>
|
||||||
|
|
||||||
void Scene::setEngineForSceneSwitching(GBAEngine *engine) {
|
void Scene::setEngineForSceneSwitching(std::shared_ptr<GBAEngine> engine) {
|
||||||
this->engine = engine;
|
this->engine = engine;
|
||||||
}
|
}
|
|
@ -9,7 +9,7 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <engine/background/background.h>
|
#include <engine/background/background.h>
|
||||||
#include "engine/sprites/sprite.h"
|
#include "engine/sprites/sprite.h"
|
||||||
#include "palette_manager.h"
|
#include "engine/palette/palette_manager.h"
|
||||||
|
|
||||||
class GBAEngine;
|
class GBAEngine;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ class Scene {
|
||||||
protected:
|
protected:
|
||||||
std::unique_ptr<ForegroundPaletteManager> foregroundPalette;
|
std::unique_ptr<ForegroundPaletteManager> foregroundPalette;
|
||||||
std::unique_ptr<BackgroundPaletteManager> backgroundPalette;
|
std::unique_ptr<BackgroundPaletteManager> backgroundPalette;
|
||||||
GBAEngine* engine;
|
std::shared_ptr<GBAEngine> engine;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ForegroundPaletteManager* getForegroundPalette() { return foregroundPalette.get(); }
|
ForegroundPaletteManager* getForegroundPalette() { return foregroundPalette.get(); }
|
||||||
|
@ -28,7 +28,7 @@ public:
|
||||||
virtual void load() = 0;
|
virtual void load() = 0;
|
||||||
virtual void tick(u16 i) = 0;
|
virtual void tick(u16 i) = 0;
|
||||||
|
|
||||||
void setEngineForSceneSwitching(GBAEngine* engine);
|
void setEngineForSceneSwitching(std::shared_ptr<GBAEngine> engine);
|
||||||
|
|
||||||
Scene() { }
|
Scene() { }
|
||||||
~Scene() {
|
~Scene() {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <engine/gba/tonc_memmap.h>
|
#include <engine/gba/tonc_memmap.h>
|
||||||
#include <engine/palette_manager.h>
|
#include <engine/palette/palette_manager.h>
|
||||||
#include "text_stream.h"
|
#include "text_stream.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <engine/palette_manager.h>
|
#include <engine/palette/palette_manager.h>
|
||||||
|
|
||||||
#define CHAR_OFFSET_INDEX 32
|
#define CHAR_OFFSET_INDEX 32
|
||||||
#define TILE_WIDTH 32
|
#define TILE_WIDTH 32
|
||||||
|
|
|
@ -4,16 +4,22 @@
|
||||||
|
|
||||||
#include "fade_out_scene.h"
|
#include "fade_out_scene.h"
|
||||||
|
|
||||||
|
FadeOutScene::FadeOutScene(int speed) : timesUpdated(0), speed(speed) {
|
||||||
|
}
|
||||||
|
|
||||||
void FadeOutScene::update() {
|
void FadeOutScene::update() {
|
||||||
sceneToAffect->getForegroundPalette()->increaseBrightness(speed);
|
if(!this->palette.get()) {
|
||||||
|
auto bgPalette = sceneToAffect->getBackgroundPalette();
|
||||||
|
if(!bgPalette) {
|
||||||
|
BackgroundPaletteManager defaultBg({});
|
||||||
|
bgPalette = &defaultBg;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto combined = (*sceneToAffect->getForegroundPalette() + *bgPalette);
|
||||||
|
this->palette = std::unique_ptr<CombinedPalette>(combined);
|
||||||
|
|
||||||
auto bgPalette = sceneToAffect->getBackgroundPalette();
|
|
||||||
if(bgPalette) {
|
|
||||||
bgPalette->increaseBrightness(speed);
|
|
||||||
} else {
|
|
||||||
BackgroundPaletteManager defaultBg({});
|
|
||||||
defaultBg.increaseBrightness(speed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->palette.get()->increaseBrightness(speed);
|
||||||
timesUpdated++;
|
timesUpdated++;
|
||||||
}
|
}
|
|
@ -13,9 +13,10 @@ class FadeOutScene : public SceneEffect {
|
||||||
private:
|
private:
|
||||||
int timesUpdated;
|
int timesUpdated;
|
||||||
int speed;
|
int speed;
|
||||||
|
std::unique_ptr<CombinedPalette> palette;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FadeOutScene(int speed) : timesUpdated(0), speed(speed) {}
|
FadeOutScene(int speed);
|
||||||
void update() override;
|
void update() override;
|
||||||
bool isDone() override { return timesUpdated >= (32 / speed); }
|
bool isDone() override { return timesUpdated >= (32 / speed); }
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
//
|
||||||
|
// Created by Wouter Groeneveld on 05/08/18.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#include <engine/background/text_stream.h>
|
||||||
|
#include "palette_manager.h"
|
||||||
|
|
||||||
|
void CombinedPalette::increaseBrightness(PaletteManager& palette, int bank, int index, u32 intensity) {
|
||||||
|
auto current = palette.get(bank, index);
|
||||||
|
auto next = PaletteManager::modify(current, intensity);
|
||||||
|
|
||||||
|
palette.change(bank, index, next);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CombinedPalette::increaseBrightness(u32 intensity) {
|
||||||
|
if(intensity > 31) {
|
||||||
|
failure(Brightness_Intensity_Too_High);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int bank = 0; bank < PALETTE_BANK_SIZE; bank++) {
|
||||||
|
for(int index = 0; index < PALETTE_BANK_SIZE; index++) {
|
||||||
|
increaseBrightness(palette1, bank, index, intensity);
|
||||||
|
increaseBrightness(palette2, bank, index, intensity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
//
|
||||||
|
// Created by Wouter Groeneveld on 05/08/18.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef GBA_SPRITE_ENGINE_COMBINED_PALETTE_H
|
||||||
|
#define GBA_SPRITE_ENGINE_COMBINED_PALETTE_H
|
||||||
|
|
||||||
|
class PaletteManager;
|
||||||
|
|
||||||
|
class CombinedPalette {
|
||||||
|
private:
|
||||||
|
// WHY use references here? lifetimes not bound, not owned by CombinedPalette
|
||||||
|
PaletteManager& palette1;
|
||||||
|
PaletteManager& palette2;
|
||||||
|
|
||||||
|
void increaseBrightness(PaletteManager& palette, int bank, int index, u32 intensity);
|
||||||
|
public:
|
||||||
|
CombinedPalette(PaletteManager& one, PaletteManager& two) : palette1(one), palette2(two) {}
|
||||||
|
CombinedPalette(const CombinedPalette& other) = delete;
|
||||||
|
|
||||||
|
void increaseBrightness(u32 intensity);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //GBA_SPRITE_ENGINE_COMBINED_PALETTE_H
|
|
@ -14,6 +14,10 @@ int getBits(int number, int k, int p) {
|
||||||
return (((1 << k) - 1) & (number >> p));
|
return (((1 << k) - 1) & (number >> p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CombinedPalette* PaletteManager::operator+(const PaletteManager &other) {
|
||||||
|
return new CombinedPalette(*this, const_cast<PaletteManager&>(other));
|
||||||
|
}
|
||||||
|
|
||||||
void PaletteManager::persist() {
|
void PaletteManager::persist() {
|
||||||
dma3_cpy(this->paletteAddress(), this->data, this->size);
|
dma3_cpy(this->paletteAddress(), this->data, this->size);
|
||||||
}
|
}
|
||||||
|
@ -44,6 +48,11 @@ u32 PaletteManager::blue(COLOR r) {
|
||||||
return getBits(r, 5, 10);
|
return getBits(r, 5, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
COLOR PaletteManager::modify(COLOR color, u32 intensity) {
|
||||||
|
return PaletteManager::color(PaletteManager::red(color) + intensity,
|
||||||
|
PaletteManager::green(color) + intensity, PaletteManager::blue(color) + intensity);
|
||||||
|
}
|
||||||
|
|
||||||
void PaletteManager::increaseBrightness(u32 intensity) {
|
void PaletteManager::increaseBrightness(u32 intensity) {
|
||||||
if(intensity > 31) {
|
if(intensity > 31) {
|
||||||
failure(Brightness_Intensity_Too_High);
|
failure(Brightness_Intensity_Too_High);
|
||||||
|
@ -53,9 +62,8 @@ void PaletteManager::increaseBrightness(u32 intensity) {
|
||||||
auto palBank = this->paletteBank();
|
auto palBank = this->paletteBank();
|
||||||
for(int bank = 0; bank < PALETTE_BANK_SIZE; bank++) {
|
for(int bank = 0; bank < PALETTE_BANK_SIZE; bank++) {
|
||||||
for(int index = 0; index < PALETTE_BANK_SIZE; index++) {
|
for(int index = 0; index < PALETTE_BANK_SIZE; index++) {
|
||||||
auto current = palBank[bank][index];
|
auto current = get(bank, index);
|
||||||
auto next = PaletteManager::color(PaletteManager::red(current) + intensity,
|
auto next = PaletteManager::modify(current, intensity);
|
||||||
PaletteManager::green(current) + intensity, PaletteManager::blue(current) + intensity);
|
|
||||||
|
|
||||||
change(bank, index, next);
|
change(bank, index, next);
|
||||||
}
|
}
|
|
@ -7,12 +7,15 @@
|
||||||
|
|
||||||
#include <engine/gba/tonc_memmap.h>
|
#include <engine/gba/tonc_memmap.h>
|
||||||
#include <engine/gba/tonc_types.h>
|
#include <engine/gba/tonc_types.h>
|
||||||
|
#include "combined_palette.h"
|
||||||
|
|
||||||
#define PALETTE_BANK_SIZE 16
|
#define PALETTE_BANK_SIZE 16
|
||||||
#define PALETTE_MAX_SIZE 256
|
#define PALETTE_MAX_SIZE 256
|
||||||
|
|
||||||
int getBits(int number, int k, int p);
|
int getBits(int number, int k, int p);
|
||||||
|
|
||||||
|
class CombinedPalette;
|
||||||
|
|
||||||
class PaletteManager {
|
class PaletteManager {
|
||||||
protected:
|
protected:
|
||||||
const u16 *data;
|
const u16 *data;
|
||||||
|
@ -24,11 +27,15 @@ public:
|
||||||
PaletteManager(const u16 paletteData[]) : data(paletteData), size(PALETTE_MAX_SIZE) {}
|
PaletteManager(const u16 paletteData[]) : data(paletteData), size(PALETTE_MAX_SIZE) {}
|
||||||
PaletteManager(const u16 paletteData[], int size) : data(paletteData), size(size) {}
|
PaletteManager(const u16 paletteData[], int size) : data(paletteData), size(size) {}
|
||||||
|
|
||||||
|
CombinedPalette* operator+(const PaletteManager& other);
|
||||||
|
|
||||||
void persist();
|
void persist();
|
||||||
void persistToBank(int bank);
|
void persistToBank(int bank);
|
||||||
COLOR change(int bank, int index, COLOR newColor);
|
COLOR change(int bank, int index, COLOR newColor);
|
||||||
|
COLOR get(int bank, int index) { return paletteBank()[bank][index]; }
|
||||||
void increaseBrightness(u32 intensity);
|
void increaseBrightness(u32 intensity);
|
||||||
|
|
||||||
|
static COLOR modify(COLOR color, u32 intensity);
|
||||||
static COLOR color(u32 r, u32 g, u32 b);
|
static COLOR color(u32 r, u32 g, u32 b);
|
||||||
static u32 red(COLOR r);
|
static u32 red(COLOR r);
|
||||||
static u32 green(COLOR r);
|
static u32 green(COLOR r);
|
|
@ -2,7 +2,7 @@
|
||||||
#include <engine/gba_engine.h>
|
#include <engine/gba_engine.h>
|
||||||
#include <engine/background/text.h>
|
#include <engine/background/text.h>
|
||||||
#include <engine/background/text_stream.h>
|
#include <engine/background/text_stream.h>
|
||||||
#include <engine/palette_manager.h>
|
#include <engine/palette/palette_manager.h>
|
||||||
#include <engine/allocator.h>
|
#include <engine/allocator.h>
|
||||||
|
|
||||||
#include "kul.h"
|
#include "kul.h"
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
* assumes 8bpp sprites
|
* assumes 8bpp sprites
|
||||||
*/
|
*/
|
||||||
int main() {
|
int main() {
|
||||||
GBAEngine* engine = new GBAEngine();
|
std::shared_ptr<GBAEngine> engine(new GBAEngine());
|
||||||
|
|
||||||
SampleStartScene* startScene = new SampleStartScene();
|
SampleStartScene* startScene = new SampleStartScene();
|
||||||
startScene->setEngineForSceneSwitching(engine);
|
startScene->setEngineForSceneSwitching(engine);
|
||||||
|
|
|
@ -11,5 +11,5 @@ add_definitions(-DCODE_COMPILED_AS_PART_OF_TEST)
|
||||||
|
|
||||||
include_directories(${GTEST_LIBRARY}/include)
|
include_directories(${GTEST_LIBRARY}/include)
|
||||||
|
|
||||||
add_executable(unittest maintest.cpp gbatest.cpp spritetest.cpp ../src/engine/background/background.cpp ../src/engine/background/text_stream.cpp ../src/engine/palette_manager.cpp ../src/engine/sprites/sprite.cpp ../src/engine/allocator.cpp scenetest.cpp allocatortest.cpp palettetest.cpp)
|
add_executable(unittest maintest.cpp gbatest.cpp spritetest.cpp ../src/engine/background/background.cpp ../src/engine/background/text_stream.cpp ../src/engine/palette/palette_manager.cpp ../src/engine/sprites/sprite.cpp ../src/engine/allocator.cpp scenetest.cpp allocatortest.cpp palettetest.cpp ../src/engine/palette/combined_palette.cpp ../src/engine/palette/combined_palette.h)
|
||||||
target_link_libraries(unittest ${GTEST_LIBRARY}/build/libgtest.a ${GTEST_LIBRARY}/build/libgtest_main.a)
|
target_link_libraries(unittest ${GTEST_LIBRARY}/build/libgtest.a ${GTEST_LIBRARY}/build/libgtest_main.a)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Created by Wouter Groeneveld on 04/08/18.
|
// Created by Wouter Groeneveld on 04/08/18.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <engine/palette_manager.h>
|
#include <engine/palette/palette_manager.h>
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
class SomePaletteManager : public PaletteManager {
|
class SomePaletteManager : public PaletteManager {
|
||||||
|
|
Loading…
Reference in New Issue