Merge pull request #4722 from fluffyfreak/optimise-sector-view

Optimise sector view and docked face generation
master
Andrew Copland 2019-10-18 09:50:44 +01:00 committed by GitHub
commit 8fe817d1ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 7 deletions

View File

@ -38,7 +38,8 @@ widgetSizes.buttonFullRefuelSize = Vector2(widgetSizes.buttonSizeBase.x*2 + widg
widgetSizes.buttonLaunchSize = Vector2(widgetSizes.buttonSizeBase.x*5, widgetSizes.buttonSizeBase.y)
widgetSizes.iconSize = Vector2(0, widgetSizes.buttonSizeBase.y)
local face;
local face = nil
local stationSeed = 0
local shipDef
local winPos = Vector2(0,0)
@ -291,9 +292,12 @@ StationView:registerView({
refresh = function()
local station = Game.player:GetDockedWith()
shipDef = ShipDef[Game.player.shipId]
if(station) then
local rand = Rand.New(station.seed)
face = InfoFace.New(Character.New({ title = l.STATION_MANAGER }, rand), {windowPadding = widgetSizes.windowPadding, itemSpacing = widgetSizes.itemSpacing})
if (station) then
if (stationSeed ~= station.seed) then
stationSeed = station.seed
local rand = Rand.New(station.seed)
face = InfoFace.New(Character.New({ title = l.STATION_MANAGER }, rand), {windowPadding = widgetSizes.windowPadding, itemSpacing = widgetSizes.itemSpacing})
end
hyperdrive = table.unpack(Game.player:GetEquip("engine")) or nil
hyperdrive_fuel = hyperdrive and hyperdrive.fuel or Equipment.cargo.hydrogen
hyperdriveIcon = PiImage.New("icons/goods/" .. hyperdrive_fuel.icon_name .. ".png")

View File

@ -19,6 +19,10 @@ LuaManager::LuaManager() :
pi_lua_open_standard_base(m_lua);
lua_atpanic(m_lua, pi_lua_panic);
// this will print nothing currently because there's no stack yet, but it means that the function is included
// in the codebase and thus available via the "immediate" window in the MSVC debugger for us in any C++ lua function
pi_lua_stacktrace(m_lua);
instantiated = true;
}

View File

@ -1072,3 +1072,18 @@ int secure_trampoline(lua_State *l)
lua_CFunction fn = lua_tocfunction(l, lua_upvalueindex(1));
return fn(l);
}
// https://zeux.io/2010/11/07/lua-callstack-with-c-debugger/
void pi_lua_stacktrace(lua_State *l)
{
lua_Debug entry;
int depth = 0;
while (lua_getstack(l, depth, &entry)) {
int status = lua_getinfo(l, "Sln", &entry);
assert(status);
Output("%s(%d): %s\n", entry.short_src, entry.currentline, entry.name ? entry.name : "?");
depth++;
}
}

View File

@ -83,6 +83,8 @@ bool pi_lua_split_table_path(lua_State *l, const std::string &path);
int secure_trampoline(lua_State *l);
void pi_lua_stacktrace(lua_State *l);
#ifdef DEBUG
#define LUA_DEBUG_START(luaptr) const int __luaStartStackDepth = lua_gettop(luaptr)
#define LUA_DEBUG_END(luaptr, expectedStackDiff) \

View File

@ -370,6 +370,7 @@ void SectorView::OnClickSystem(const SystemPath &path)
void SectorView::PutSystemLabels(RefCountedPtr<Sector> sec, const vector3f &origin, int drawRadius)
{
PROFILE_SCOPED()
Uint32 sysIdx = 0;
for (std::vector<Sector::System>::iterator sys = sec->m_systems.begin(); sys != sec->m_systems.end(); ++sys, ++sysIdx) {
// skip the system if it doesn't fall within the sphere we're viewing.
@ -378,14 +379,20 @@ void SectorView::PutSystemLabels(RefCountedPtr<Sector> sec, const vector3f &orig
// if the system is the current system or target we can't skip it
bool can_skip = !sys->IsSameSystem(m_selected) && !sys->IsSameSystem(m_hyperspaceTarget) && !sys->IsSameSystem(m_current);
// skip if we have no population and won't drawn uninhabited systems
if (can_skip && (sys->GetPopulation() <= 0 && !m_drawUninhabitedLabels)) continue;
// skip the system if it belongs to a Faction we've toggled off and we can skip it
if (m_hiddenFactions.find(sys->GetFaction()) != m_hiddenFactions.end() && can_skip) continue;
if (can_skip && m_hiddenFactions.find(sys->GetFaction()) != m_hiddenFactions.end()) continue;
// determine if system in hyperjump range or not
RefCountedPtr<const Sector> playerSec = GetCached(m_current);
float dist = Sector::DistanceBetween(sec, sysIdx, playerSec, m_current.systemIndex);
bool inRange = dist <= m_playerHyperspaceRange;
// skip if we're out of rangen and won't draw out of range systems systems
if (can_skip && (!inRange && !m_drawOutRangeLabels)) continue;
// place the label
vector3d systemPos = vector3d((*sys).GetFullPosition() - origin);
vector3d screenPos;
@ -426,7 +433,6 @@ void SectorView::PutFactionLabels(const vector3f &origin)
for (auto it = m_visibleFactions.begin(); it != m_visibleFactions.end(); ++it) {
if ((*it)->hasHomeworld && m_hiddenFactions.find((*it)) == m_hiddenFactions.end()) {
Sector::System sys = GetCached((*it)->homeworld)->m_systems[(*it)->homeworld.systemIndex];
if ((m_pos * Sector::SIZE - sys.GetFullPosition()).Length() > (m_zoomClamped / FAR_THRESHOLD) * OUTER_RADIUS) continue;
@ -800,7 +806,7 @@ void SectorView::DrawNearSector(const int sx, const int sy, const int sz, const
// if the system belongs to a faction we've chosen to temporarily hide
// then skip it if we can
m_visibleFactions.insert(i->GetFaction());
if (m_hiddenFactions.find(i->GetFaction()) != m_hiddenFactions.end() && can_skip) continue;
if (can_skip && m_hiddenFactions.find(i->GetFaction()) != m_hiddenFactions.end()) continue;
// determine if system in hyperjump range or not
RefCountedPtr<const Sector> playerSec = GetCached(m_current);