Cleanup before trying to make the tile rendering faster by pre-loading the sprites needed, or caching as they're requested.

This commit is contained in:
Zed A. Shaw 2024-10-18 20:53:19 -04:00
parent 08d71f9bdc
commit 31c86fa2b3
2 changed files with 16 additions and 25 deletions

36
gui.cpp
View file

@ -67,11 +67,6 @@ GUI::GUI() : $game_map(GAME_MAP_X, GAME_MAP_Y),
$ui_text.setCharacterSize(UI_FONT_SIZE);
$ui_text.setFillColor(color(Value::LIGHT_LIGHT));
$map_text.setFont($font);
$map_text.setPosition(GAME_MAP_POS,0);
$map_text.setCharacterSize(MAP_FONT_SIZE);
$map_text.setFillColor(color(Value::MID));
$game_map.generate();
}
@ -135,18 +130,6 @@ void GUI::run_systems() {
System::combat($world, player);
}
void GUI::burn() {
for(int i = 0; i < 20; ++i) {
$map_text.setFillColor(color(i % VALUES.size()));
int x = Random::uniform<int>(-10,10);
int y = Random::uniform<int>(-10,10);
draw_screen(false, x, y);
std::this_thread::sleep_for(2ms);
}
$map_text.setFillColor(color(Value::MID));
}
void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) {
if(clear) $window.clear();
std::string screenout = $screen.ToString();
@ -156,17 +139,19 @@ void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) {
$window.draw($ui_text);
std::wstring map_screen_utf8 = $converter.from_bytes(map_screenout);
$map_text.setString(map_screen_utf8);
sf::Texture ftext = $font.getTexture(MAP_FONT_SIZE);
float y = 0.0f;
float x = GAME_MAP_POS;
const float line_spacing = $font.getLineSpacing(MAP_FONT_SIZE);
for(size_t i = 0; i < map_screen_utf8.size(); i++) {
wchar_t tile = map_screen_utf8[i];
sf::Glyph glyph = $font.getGlyph(tile, MAP_FONT_SIZE, false);
sf::Sprite sprite(ftext);
sprite.setTextureRect(glyph.textureRect);
auto pos = $map_text.findCharacterPos(i);
sprite.setPosition(pos);
sprite.setPosition({x, y});
if(tile == L'') {
sprite.setColor(sf::Color(100,100,100));
} else if(tile == L'') {
@ -175,14 +160,19 @@ void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) {
sprite.setColor(sf::Color::Red);
} else if(tile == L'·') {
sprite.setColor(color(Value::DARK_MID));
} else if(tile == L'\n' || tile == L'\r') {
// skip newlines
} else if(tile == L'\r') {
continue; // skip these, just windows junk
} else if(tile == L'\n') {
// newline
y += line_spacing;
x = GAME_MAP_POS;
continue;
} else {
sprite.setColor(color(Value::MID));
}
$window.draw(sprite);
x += glyph.advance;
}
$window.display();