aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2021-05-28 21:02:26 -0400
committerJon Santmyer <jon@jonsantmyer.com>2021-05-28 21:02:26 -0400
commit51682452fad8ca99d9085f46a0572dab12a6a991 (patch)
treec7567b6448dcfba0351a88e13007f3b1f3333790
parente937c2bfc72d560ce285f49e4eb8fb7036fed3dd (diff)
downloadpostmodern-51682452fad8ca99d9085f46a0572dab12a6a991.tar.gz
postmodern-51682452fad8ca99d9085f46a0572dab12a6a991.tar.bz2
postmodern-51682452fad8ca99d9085f46a0572dab12a6a991.zip
transition to boxii-based rendering
-rw-r--r--Makefile2
-rw-r--r--bin/assets/title.txt2
-rwxr-xr-xbin/libboxii.sobin90256 -> 240808 bytes
m---------boxii0
-rw-r--r--include/pausescreen.h3
-rw-r--r--include/screen.h9
-rw-r--r--src/game.cpp26
-rw-r--r--src/pausescreen.cpp16
-rw-r--r--src/screen.cpp24
-rw-r--r--src/titlescreen.cpp9
10 files changed, 33 insertions, 58 deletions
diff --git a/Makefile b/Makefile
index 88b8d2a..cf7eddd 100644
--- a/Makefile
+++ b/Makefile
@@ -63,7 +63,7 @@ $(INCDIR)/boxii:
.PHONY: $(TARGET_PREFIX)/libboxii.so
$(TARGET_PREFIX)/libboxii.so:
- $(MAKE) -C $(PWD)/boxii
+ $(MAKE) -C $(PWD)/boxii TRUECOLOR=$(TRUECOLOR) EXTCOLOR=$(EXTCOLOR) VGACOLOR=$(VGACOLOR)
mv $(PWD)/boxii/bin/libboxii.so $(TARGET_PREFIX)
# vim: set ts=4 sw=0 tw=0 noet :
diff --git a/bin/assets/title.txt b/bin/assets/title.txt
index 8d04dd1..0c50c96 100644
--- a/bin/assets/title.txt
+++ b/bin/assets/title.txt
@@ -3,4 +3,4 @@
| |_) | | | \___ \ | | | |\/| | | | | | | | _| | |_) | \| |
| __/| |_| |___) || | | | | | |_| | |_| | |___| _ <| |\ |
|_| \___/|____/ |_| |_| |_|\___/|____/|_____|_| \_\_| \_|
-Powered by Boxii!
+Powered by Boxii!
diff --git a/bin/libboxii.so b/bin/libboxii.so
index 6d20a19..981ffa3 100755
--- a/bin/libboxii.so
+++ b/bin/libboxii.so
Binary files differ
diff --git a/boxii b/boxii
-Subproject a5ef0ae876df2b767cf03c2b42a253dd1e0cf07
+Subproject b4ddbcd99dfc5d4209efa549e94827c2db1e36b
diff --git a/include/pausescreen.h b/include/pausescreen.h
index c3c1a43..586d4bf 100644
--- a/include/pausescreen.h
+++ b/include/pausescreen.h
@@ -22,6 +22,9 @@ public:
PauseScreen();
~PauseScreen();
+ void activate() override;
+ void deactivate() override;
+
void update() override;
};
diff --git a/include/screen.h b/include/screen.h
index 6896b72..c379483 100644
--- a/include/screen.h
+++ b/include/screen.h
@@ -10,20 +10,15 @@
class Screen {
private:
- bool m_redraw;
protected:
- std::unordered_map<std::string, std::shared_ptr<Boxii::Window>> m_windows;
- std::deque<std::weak_ptr<Boxii::Window>> m_order;
public:
Screen() {}
virtual ~Screen() {}
- void addWindow(const std::string &key, std::shared_ptr<Boxii::Window> value);
+ virtual void activate() {}
+ virtual void deactivate() {}
virtual void update() {}
- void render();
-
- void setRedraw() { m_redraw = true; }
};
#endif
diff --git a/src/game.cpp b/src/game.cpp
index 0177bd7..9644010 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -28,7 +28,7 @@ Game::loop()
{
while(m_running)
{
- render();
+ Boxii::refresh();
update();
}
}
@@ -50,33 +50,19 @@ Game::update()
locked->update();
}
-void
-Game::render()
-{
- for(auto it = m_order.cbegin(); it != m_order.cend(); it++){
- auto lock = it->lock();
- if(!lock) continue;
-
- if(m_dirty){
- lock->setRedraw();
- }
- lock->render();
- }
- m_dirty = false;
-}
-
void
Game::addScreen(const std::string &key, std::shared_ptr<Screen> value)
{
m_screens.emplace(key, value);
}
+
bool
Game::pushScreen(const std::string &key)
{
auto it = m_screens.find(key);
if(it != m_screens.end()){
m_order.push_back(it->second);
- m_dirty = true;
+ it->second->activate();
return true;
}
return false;
@@ -85,6 +71,9 @@ Game::pushScreen(const std::string &key)
bool
Game::popScreen()
{
+ if(auto lock = m_order.back().lock()){
+ lock->deactivate();
+ }
m_order.pop_back();
m_dirty = true;
return m_order.empty();
@@ -106,6 +95,7 @@ Game::popUpto(const std::string &key)
}
if(lock == find->second) break;
+ lock->deactivate();
m_order.pop_back();
}
m_dirty = true;
@@ -118,6 +108,8 @@ Game::popUptoIncluding(const std::string &key)
bool r = popUpto(key);
if(!r) return r;
+ auto lock = m_order.back().lock();
+ if(lock != nullptr) lock->deactivate();
m_order.pop_back();
return true;
}
diff --git a/src/pausescreen.cpp b/src/pausescreen.cpp
index 17a82d5..4bb6f4a 100644
--- a/src/pausescreen.cpp
+++ b/src/pausescreen.cpp
@@ -53,8 +53,8 @@ PauseScreen::PauseScreen() :
int menuX = (sw / 2) - (menuWidth / 2);
int menuY = (sh / 2) - (menuHeight / 2);
- m_menuWindow = std::make_shared<Boxii::TextWindow>(menuX, menuY / 2, menuWidth, menuHeight, false);
- addWindow("main", m_menuWindow);
+ m_menuWindow = Boxii::makeWindow<Boxii::TextWindow>(menuX, menuY / 2, menuWidth, menuHeight);
+ Boxii::remove(m_menuWindow);
printSelections(m_menuWindow, m_selection);
}
@@ -65,6 +65,18 @@ PauseScreen::~PauseScreen()
}
void
+PauseScreen::activate()
+{
+ Boxii::pushToFront(m_menuWindow);
+}
+
+void
+PauseScreen::deactivate()
+{
+ Boxii::remove(m_menuWindow);
+}
+
+void
PauseScreen::update()
{
int c = Boxii::Input::getch(true);
diff --git a/src/screen.cpp b/src/screen.cpp
deleted file mode 100644
index fbefc5e..0000000
--- a/src/screen.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "screen.h"
-
-#include <ncurses.h>
-
-void
-Screen::addWindow(const std::string &key, std::shared_ptr<Boxii::Window> value)
-{
- m_windows.emplace(key, value);
- m_order.push_back(std::weak_ptr<Boxii::Window>(value));
-}
-
-void
-Screen::render()
-{
- for(auto it = m_order.begin(); it != m_order.end(); it++){
- if(auto obs = it->lock()){
- if(m_redraw) obs->setRedraw();
- obs->refresh();
- }else{
- m_order.erase(it--);
- }
- }
- m_redraw = false;
-}
diff --git a/src/titlescreen.cpp b/src/titlescreen.cpp
index b2f6c02..14c97e5 100644
--- a/src/titlescreen.cpp
+++ b/src/titlescreen.cpp
@@ -79,11 +79,8 @@ TitleScreen::TitleScreen() :
int graphicHeight = (sh / 4) * 3;
int selectionHeight = (sh / 4);
- m_graphicWindow = std::make_shared<Boxii::Window>(0, 0, sw, graphicHeight + 1, false);
- m_selectionWindow = std::make_shared<Boxii::TextWindow>(0, graphicHeight + 1, sw, selectionHeight + 1, false);
-
- addWindow("graphic", m_graphicWindow);
- addWindow("selection", m_selectionWindow);
+ m_graphicWindow = Boxii::makeWindow<Boxii::Window>(0, 0, sw, graphicHeight + 1);
+ m_selectionWindow = Boxii::makeWindow<Boxii::TextWindow>(0, graphicHeight + 1, sw, selectionHeight + 1);
printTitle(m_graphicWindow);
printSelections(m_selectionWindow, m_selection);
@@ -103,7 +100,7 @@ TitleScreen::parseSelection()
void
TitleScreen::update()
{
- int c = Boxii::Input::getch(false);
+ int c = Boxii::Input::getch(true);
if(c == Boxii::KEY_ESCAPE) {
Game::pushScreen("pause");
}