Skip to content

Commit

Permalink
Merge branch 'master' into csibbitt-guiadvancedscrolltext-performance…
Browse files Browse the repository at this point in the history
…-tweak
  • Loading branch information
csibbitt committed Oct 11, 2023
2 parents d1b61a5 + f0b22f2 commit 8af02c8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
11 changes: 9 additions & 2 deletions src/gui/gui2_advancedscrolltext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ GuiAdvancedScrollText::GuiAdvancedScrollText(GuiContainer* owner, string id)
scrollbar->setPosition(0, 0, sp::Alignment::TopRight)->setSize(50, GuiElement::GuiSizeMax);
}

GuiAdvancedScrollText* GuiAdvancedScrollText::addEntry(string prefix, string text, glm::u8vec4 color)
GuiAdvancedScrollText* GuiAdvancedScrollText::addEntry(string prefix, string text, glm::u8vec4 color, unsigned int seq)
{
Entry& entry = entries.emplace_back();
entry.prefix = prefix;
entry.text = text;
entry.color = color;
entry.seq = seq;
prepEntry(entry);

return this;
}

Expand All @@ -39,6 +39,13 @@ GuiAdvancedScrollText::Entry GuiAdvancedScrollText::prepEntry(GuiAdvancedScrollT
return e;
}

unsigned int GuiAdvancedScrollText::getEntrySeq(int index) const
{
if (index < 0 || index >= static_cast<int>(getEntryCount()))
return 0;
return entries[index].seq;
}

GuiAdvancedScrollText* GuiAdvancedScrollText::removeEntry(int index)
{
if (index < 0 || index >= static_cast<int>(getEntryCount()))
Expand Down
4 changes: 3 additions & 1 deletion src/gui/gui2_advancedscrolltext.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class GuiAdvancedScrollText : public GuiElement
string text;
sp::Font::PreparedFontString prepared_text;
glm::u8vec4 color;
unsigned int seq;
};

std::vector<Entry> entries;
Expand All @@ -32,11 +33,12 @@ class GuiAdvancedScrollText : public GuiElement
GuiAdvancedScrollText* enableAutoScrollDown() { auto_scroll_down = true; return this; }
GuiAdvancedScrollText* disableAutoScrollDown() { auto_scroll_down = false; return this; }

GuiAdvancedScrollText* addEntry(string prefix, string text, glm::u8vec4 color);
GuiAdvancedScrollText* addEntry(string prefix, string text, glm::u8vec4 color, unsigned int seq);
GuiAdvancedScrollText* setTextSize(float text_size) { this->text_size = text_size; return this; }

unsigned int getEntryCount() const;
string getEntryText(int index) const;
unsigned int getEntrySeq(int index) const;
GuiAdvancedScrollText* removeEntry(int index);
GuiAdvancedScrollText* clearEntries();

Expand Down
8 changes: 4 additions & 4 deletions src/screenComponents/shipsLogControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ void ShipsLog::onDraw(sp::RenderTarget& renderer)
log_text->removeEntry(0);
}

if (log_text->getEntryCount() > 0 && logs.size() > 0 && log_text->getEntryText(0) != logs[0].text)
if (log_text->getEntryCount() > 0 && logs.size() > 0 && log_text->getEntrySeq(0) != logs[0].seq)
{
bool updated = false;
for(unsigned int n=1; n<log_text->getEntryCount(); n++)
{
if (log_text->getEntryText(n) == logs[0].text)
if (log_text->getEntrySeq(n) == logs[0].seq)
{
for(unsigned int m=0; m<n; m++)
log_text->removeEntry(0);
Expand All @@ -59,7 +59,7 @@ void ShipsLog::onDraw(sp::RenderTarget& renderer)
while(log_text->getEntryCount() < logs.size())
{
int n = log_text->getEntryCount();
log_text->addEntry(logs[n].prefix, logs[n].text, logs[n].color);
log_text->addEntry(logs[n].prefix, logs[n].text, logs[n].color, logs[n].seq);
}
}else{
if (log_text->getEntryCount() > 0 && logs.size() == 0)
Expand All @@ -70,7 +70,7 @@ void ShipsLog::onDraw(sp::RenderTarget& renderer)
log_text->clearEntries();
}
if (log_text->getEntryCount() == 0 && logs.size() > 0)
log_text->addEntry(logs.back().prefix, logs.back().text, logs.back().color);
log_text->addEntry(logs.back().prefix, logs.back().text, logs.back().color, logs.back().seq);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/screens/extra/shipLogScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ void ShipLogScreen::onDraw(sp::RenderTarget& renderer)
log_text->removeEntry(0);
}

if (log_text->getEntryCount() > 0 && logs.size() > 0 && log_text->getEntryText(0) != logs[0].text)
if (log_text->getEntryCount() > 0 && logs.size() > 0 && log_text->getEntrySeq(0) != logs[0].seq)
{
bool updated = false;
for(unsigned int n=1; n<log_text->getEntryCount(); n++)
{
if (log_text->getEntryText(n) == logs[0].text)
if (log_text->getEntrySeq(n) == logs[0].seq)
{
for(unsigned int m=0; m<n; m++)
log_text->removeEntry(0);
Expand All @@ -60,7 +60,7 @@ void ShipLogScreen::onDraw(sp::RenderTarget& renderer)
while(log_text->getEntryCount() < logs.size())
{
int n = log_text->getEntryCount();
log_text->addEntry(logs[n].prefix, logs[n].text, logs[n].color);
log_text->addEntry(logs[n].prefix, logs[n].text, logs[n].color, logs[n].seq);
}
}
}
6 changes: 3 additions & 3 deletions src/spaceObjects/playerSpaceship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ string alertLevelToLocaleString(EAlertLevel level)
}

// Configure ship's log packets.
static inline sp::io::DataBuffer& operator << (sp::io::DataBuffer& packet, const PlayerSpaceship::ShipLogEntry& e) { return packet << e.prefix << e.text << e.color.r << e.color.g << e.color.b << e.color.a; }
static inline sp::io::DataBuffer& operator >> (sp::io::DataBuffer& packet, PlayerSpaceship::ShipLogEntry& e) { packet >> e.prefix >> e.text >> e.color.r >> e.color.g >> e.color.b >> e.color.a; return packet; }
static inline sp::io::DataBuffer& operator << (sp::io::DataBuffer& packet, const PlayerSpaceship::ShipLogEntry& e) { return packet << e.prefix << e.text << e.color.r << e.color.g << e.color.b << e.color.a << e.seq; }
static inline sp::io::DataBuffer& operator >> (sp::io::DataBuffer& packet, PlayerSpaceship::ShipLogEntry& e) { packet >> e.prefix >> e.text >> e.color.r >> e.color.g >> e.color.b >> e.color.a >> e.seq; return packet; }

REGISTER_MULTIPLAYER_CLASS(PlayerSpaceship, "PlayerSpaceship");
PlayerSpaceship::PlayerSpaceship()
Expand Down Expand Up @@ -1123,7 +1123,7 @@ void PlayerSpaceship::addToShipLog(string message, glm::u8vec4 color)
ships_log.erase(ships_log.begin());

// Timestamp a log entry, color it, and add it to the end of the log.
ships_log.emplace_back(gameGlobalInfo->getMissionTime() + string(": "), message, color);
ships_log.emplace_back(gameGlobalInfo->getMissionTime() + string(": "), message, color, last_log_seq++);
}

void PlayerSpaceship::addToShipLogBy(string message, P<SpaceObject> target)
Expand Down
6 changes: 4 additions & 2 deletions src/spaceObjects/playerSpaceship.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ class PlayerSpaceship : public SpaceShip
string prefix;
string text;
glm::u8vec4 color;
unsigned int seq;

ShipLogEntry() {}
ShipLogEntry(string prefix, string text, glm::u8vec4 color)
: prefix(prefix), text(text), color(color) {}
ShipLogEntry(string prefix, string text, glm::u8vec4 color, unsigned int seq)
: prefix(prefix), text(text), color(color), seq(seq) {}

bool operator!=(const ShipLogEntry& e) { return prefix != e.prefix || text != e.text || color != e.color; }
};
Expand Down Expand Up @@ -114,6 +115,7 @@ class PlayerSpaceship : public SpaceShip
std::vector<ShipLogEntry> ships_log;
float energy_shield_use_per_second = default_energy_shield_use_per_second;
float energy_warp_per_second = default_energy_warp_per_second;
unsigned int last_log_seq = 0;
public:
std::vector<CustomShipFunction> custom_functions;

Expand Down

0 comments on commit 8af02c8

Please sign in to comment.