From 0bab9368ba9fa3852352be137bf89558784e0cda Mon Sep 17 00:00:00 2001 From: wgroeneveld Date: Fri, 30 Nov 2018 13:48:43 +0100 Subject: [PATCH] conway game of life naive implementation --- CMakeLists.txt | 3 +- demos/demo4-conway/CMakeLists.txt | 11 ++ demos/demo4-conway/conway.h | 58 ++++++++++ demos/demo4-conway/conway.png | Bin 0 -> 96 bytes demos/demo4-conway/src/ConwayScene.cpp | 99 ++++++++++++++++++ demos/demo4-conway/src/ConwayScene.h | 41 ++++++++ demos/demo4-conway/src/ConwaySeeder.cpp | 55 ++++++++++ demos/demo4-conway/src/ConwaySeeder.h | 31 ++++++ demos/demo4-conway/src/bg.h | 66 ++++++++++++ demos/demo4-conway/src/main.cpp | 19 ++++ .../background/background.h | 1 + engine/src/background/background.cpp | 5 + engine/src/gba_engine.cpp | 6 +- 13 files changed, 391 insertions(+), 4 deletions(-) create mode 100644 demos/demo4-conway/CMakeLists.txt create mode 100644 demos/demo4-conway/conway.h create mode 100644 demos/demo4-conway/conway.png create mode 100644 demos/demo4-conway/src/ConwayScene.cpp create mode 100644 demos/demo4-conway/src/ConwayScene.h create mode 100644 demos/demo4-conway/src/ConwaySeeder.cpp create mode 100644 demos/demo4-conway/src/ConwaySeeder.h create mode 100644 demos/demo4-conway/src/bg.h create mode 100644 demos/demo4-conway/src/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a0b6092..e0d2e77 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,4 +30,5 @@ add_subdirectory(test) add_subdirectory(demos/demo1-basicfeatures) add_subdirectory(demos/demo2-arkanoid) -add_subdirectory(demos/demo3-foodthrowing) \ No newline at end of file +add_subdirectory(demos/demo3-foodthrowing) +add_subdirectory(demos/demo4-conway) \ No newline at end of file diff --git a/demos/demo4-conway/CMakeLists.txt b/demos/demo4-conway/CMakeLists.txt new file mode 100644 index 0000000..d539476 --- /dev/null +++ b/demos/demo4-conway/CMakeLists.txt @@ -0,0 +1,11 @@ +project(conway) + +add_executable(${PROJECT_NAME}.elf + src/main.cpp + src/ConwayScene.cpp src/ConwayScene.h src/bg.h src/ConwaySeeder.cpp src/ConwaySeeder.h) + +target_link_libraries(${PROJECT_NAME}.elf gba-sprite-engine) + +add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -v -O binary ${PROJECT_NAME}.elf ${PROJECT_NAME}.gba + ) diff --git a/demos/demo4-conway/conway.h b/demos/demo4-conway/conway.h new file mode 100644 index 0000000..a5b905d --- /dev/null +++ b/demos/demo4-conway/conway.h @@ -0,0 +1,58 @@ +/* conway.h + * generated by png2gba program */ + +#define conway_width 24 +#define conway_height 8 + +const unsigned char conway_data [] = { + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + +}; + +const unsigned short conway_palette [] = { + 0x7c1f, 0x0c7e, 0x0fd0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000 +}; + diff --git a/demos/demo4-conway/conway.png b/demos/demo4-conway/conway.png new file mode 100644 index 0000000000000000000000000000000000000000..440757ff8921b56c22dd4beac42b6aa6409b059f GIT binary patch literal 96 zcmeAS@N?(olHy`uVBq!ia0vp^5FVdQ&MBdZfdK#nv>1N? literal 0 HcmV?d00001 diff --git a/demos/demo4-conway/src/ConwayScene.cpp b/demos/demo4-conway/src/ConwayScene.cpp new file mode 100644 index 0000000..02476b7 --- /dev/null +++ b/demos/demo4-conway/src/ConwayScene.cpp @@ -0,0 +1,99 @@ +// +// Created by Wouter Groeneveld on 30/11/18. +// + +#include +#include +#include +#include +#include "ConwayScene.h" +#include "bg.h" + +// See http://www.coranac.com/tonc/text/gfx.htm#cd-qran +int __qran_seed= 42; // Seed / rnd holder + +ConwayScene::ConwayScene(const std::shared_ptr &engine, u8 percentageSeed) : Scene(engine), percentageSeed(percentageSeed) { +} + +std::vector ConwayScene::sprites() { + return {}; +} + +std::vector ConwayScene::backgrounds() { + return { bg.get() }; +} + +int ConwayScene::countAmountOfNeighbouringCellsAlive(int x, int y) { + int amountOfNeightbouringCellsAlive = 0; + int pos = y * MAP_WIDTH + x; + + for(int x_i = x - 1; x_i <= x + 1; x_i++) { + for(int y_j = y - 1; y_j <= y + 1; y_j++) { + int toCheckPos = y_j * MAP_WIDTH + x_i; + if(toCheckPos >= 0 && toCheckPos < MAP_SIZE - 1 && pos != toCheckPos && map[toCheckPos] == ALIVE) { + amountOfNeightbouringCellsAlive++; + } + } + } + + return amountOfNeightbouringCellsAlive; +} + +u16 ConwayScene::getNextState(int x, int y) { + int pos = y * MAP_WIDTH + x; + int amountAlive = countAmountOfNeighbouringCellsAlive(x, y); + + int currentState = map[pos]; + + if(currentState == DEAD) { + if(amountAlive == 3) { + return ALIVE; + } + return DEAD; + } else { + if (amountAlive < 2 || amountAlive > 3) { + return DEAD; + } + return ALIVE; + } +} + +void ConwayScene::seedRandomMap(int seedcount) { + for(int i = 0; i < MAP_SIZE; i++) { + map[i] = DEAD; + } + + for(int i = 0; i < seedcount; i++) { + int x = qran_range(0, MAP_WIDTH); + int y = qran_range(0, MAP_HEIGHT); + map[y * MAP_WIDTH + x] = ALIVE; + } +} + +void ConwayScene::load() { + backgroundPalette = std::unique_ptr(new BackgroundPaletteManager(conway_palette, sizeof(conway_palette))); + + seedRandomMap(((MAP_WIDTH * MAP_HEIGHT) / 100) * percentageSeed); + + bg = std::unique_ptr(new Background(1, conway_data, sizeof(conway_data), map, sizeof(map))); + bg.get()->useMapScreenBlock(16); +} + +void ConwayScene::tick(u16 keys) { + generation++; + int totalAmountAlive = 0; + dma3_cpy(buffer, map, sizeof(buffer)); + + for(int w = 0; w < MAP_WIDTH; w++) { + for(int h = 0; h < MAP_HEIGHT; h++) { + u16 state = getNextState(w, h); + if(state == ALIVE) totalAmountAlive++; + buffer[h * MAP_WIDTH + w] = state; + } + } + + TextStream::instance().setText(std::string("amount alive: ") + std::to_string(totalAmountAlive) + std::string(" of ") + std::to_string(MAP_SIZE), 1, 1); + TextStream::instance().setText(std::string("generation: ") + std::to_string(generation), 2, 1); + dma3_cpy(map, buffer, sizeof(map)); + bg.get()->updateMap(buffer); +} diff --git a/demos/demo4-conway/src/ConwayScene.h b/demos/demo4-conway/src/ConwayScene.h new file mode 100644 index 0000000..0f1c6e7 --- /dev/null +++ b/demos/demo4-conway/src/ConwayScene.h @@ -0,0 +1,41 @@ +// +// Created by Wouter Groeneveld on 30/11/18. +// + +#ifndef GBA_SPRITE_ENGINE_PROJECT_CONWAYSCENE_H +#define GBA_SPRITE_ENGINE_PROJECT_CONWAYSCENE_H + +#define MAP_WIDTH 64 +#define MAP_HEIGHT 64 +#define MAP_SIZE 64 * 64 + +#define ALIVE 0x0001 +#define DEAD 0x0002 + +#include + +class ConwayScene : public Scene { +private: + u8 percentageSeed; + u16 generation; + std::unique_ptr bg; + u16 map[MAP_SIZE], buffer[MAP_SIZE]; + + int countAmountOfNeighbouringCellsAlive(int x, int y); + void seedRandomMap(int seedcount); + u16 getNextState(int x, int y); + +public: + ConwayScene(const std::shared_ptr &engine, u8 percentageSeed); + + std::vector sprites() override; + + std::vector backgrounds() override; + + void load() override; + + void tick(u16 keys) override; +}; + + +#endif //GBA_SPRITE_ENGINE_PROJECT_CONWAYSCENE_H diff --git a/demos/demo4-conway/src/ConwaySeeder.cpp b/demos/demo4-conway/src/ConwaySeeder.cpp new file mode 100644 index 0000000..253bab2 --- /dev/null +++ b/demos/demo4-conway/src/ConwaySeeder.cpp @@ -0,0 +1,55 @@ +// +// Created by Wouter Groeneveld on 30/11/18. +// + +#include +#include +#include +#include +#include "ConwaySeeder.h" +#include "bg.h" +#include "ConwayScene.h" + +ConwaySeeder::ConwaySeeder(const std::shared_ptr &engine) : Scene(engine), percentage(30), delta(0) {} + +std::vector ConwaySeeder::backgrounds() { + return {}; +} + +std::vector ConwaySeeder::sprites() { + return { + conwaySprite.get() + }; +} + +void ConwaySeeder::load() { + foregroundPalette = std::unique_ptr(new ForegroundPaletteManager(conway_palette, sizeof(conway_palette))); + + SpriteBuilder builder; + conwaySprite = builder + .withData(conway_data, sizeof(conway_data)) + .withSize(SIZE_32_8) + .withLocation(GBA_SCREEN_WIDTH - 40, 8) + .buildPtr(); + + TextStream::instance().setText(std::string("Conways Game of Life"), 1, 1); + TextStream::instance().setText(std::string("Up/Down to adjust"), 10, 1); + TextStream::instance().setText(std::string("Start to render"), 11, 1); +} + +void ConwaySeeder::tick(u16 keys) { + TextStream::instance().setText(std::string("Seed percentage: ") + std::to_string(percentage), 5, 1); + + if(keys & KEY_START) { + engine.get()->setScene(new ConwayScene(engine, percentage)); + } else if(keys & KEY_UP && percentage < 90) { + delta = 1; + } else if(keys & KEY_DOWN && percentage > 10) { + delta = -1; + } else { + if(delta != 0) { + percentage += 10 * delta; + delta = 0; + } + } +} \ No newline at end of file diff --git a/demos/demo4-conway/src/ConwaySeeder.h b/demos/demo4-conway/src/ConwaySeeder.h new file mode 100644 index 0000000..433b82d --- /dev/null +++ b/demos/demo4-conway/src/ConwaySeeder.h @@ -0,0 +1,31 @@ +// +// Created by Wouter Groeneveld on 30/11/18. +// + +#ifndef GBA_SPRITE_ENGINE_PROJECT_CONWAYSEEDER_H +#define GBA_SPRITE_ENGINE_PROJECT_CONWAYSEEDER_H + + +#include + +class ConwaySeeder : public Scene { +private: + int delta; + int percentage; + std::unique_ptr conwaySprite; + +public: + ConwaySeeder(const std::shared_ptr &engine); + + std::vector sprites() override; + + std::vector backgrounds() override; + + void load() override; + + void tick(u16 keys) override; + +}; + + +#endif //GBA_SPRITE_ENGINE_PROJECT_CONWAYSEEDER_H diff --git a/demos/demo4-conway/src/bg.h b/demos/demo4-conway/src/bg.h new file mode 100644 index 0000000..fd12b7e --- /dev/null +++ b/demos/demo4-conway/src/bg.h @@ -0,0 +1,66 @@ +// +// Created by Wouter Groeneveld on 30/11/18. +// + +#ifndef GBA_SPRITE_ENGINE_PROJECT_BG_H +#define GBA_SPRITE_ENGINE_PROJECT_BG_H +/* conway.h + * generated by png2gba program */ + +#define conway_width 24 +#define conway_height 8 + +const unsigned char conway_data [] = { + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + +}; + +const unsigned short conway_palette [] = { + 0x7c1f, 0x0c7e, 0x0fd0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000 +}; + + +#endif //GBA_SPRITE_ENGINE_PROJECT_BG_H diff --git a/demos/demo4-conway/src/main.cpp b/demos/demo4-conway/src/main.cpp new file mode 100644 index 0000000..af47674 --- /dev/null +++ b/demos/demo4-conway/src/main.cpp @@ -0,0 +1,19 @@ +// +// Created by Wouter Groeneveld on 30/11/18. +// + +#include "ConwaySeeder.h" +#include + +int main() { + std::shared_ptr engine(new GBAEngine()); + + ConwaySeeder* startScene = new ConwaySeeder(engine); + engine->setScene(startScene); + + while (true) { + engine->update(); + } + + return 0; +} \ No newline at end of file diff --git a/engine/include/libgba-sprite-engine/background/background.h b/engine/include/libgba-sprite-engine/background/background.h index 6e0b883..f55ae01 100644 --- a/engine/include/libgba-sprite-engine/background/background.h +++ b/engine/include/libgba-sprite-engine/background/background.h @@ -29,6 +29,7 @@ public: 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) {} virtual void persist(); + void updateMap(const void* map); void clearMap(); void clearData(); }; diff --git a/engine/src/background/background.cpp b/engine/src/background/background.cpp index 70c9d55..f5121c5 100644 --- a/engine/src/background/background.cpp +++ b/engine/src/background/background.cpp @@ -26,6 +26,11 @@ void* char_block(unsigned long block) { return (void*) (0x6000000 + (block * 0x4000)); } +void Background::updateMap(const void *map) { + this->map = map; + dma3_cpy(screen_block(screenBlockIndex), this->map, this->mapSize); +} + void Background::persist() { dma3_cpy(char_block(bgIndex), this->data, this->size); diff --git a/engine/src/gba_engine.cpp b/engine/src/gba_engine.cpp index d41dea1..0dadb70 100644 --- a/engine/src/gba_engine.cpp +++ b/engine/src/gba_engine.cpp @@ -145,11 +145,11 @@ void GBAEngine::setScene(Scene* scene) { dequeueAllSounds(); if(this->currentScene) { cleanupPreviousScene(); + if(!this->disableTextBg) { + TextStream::instance().clear(); + } } scene->load(); - if(!this->disableTextBg) { - TextStream::instance().clear(); - } auto fgPalette = scene->getForegroundPalette(); if(!fgPalette) {