Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[buildingplan] only consider building materials that can be accessed by citizens/residents #4897

Merged
merged 3 commits into from
Sep 3, 2024

Conversation

chdoc
Copy link
Member

@chdoc chdoc commented Sep 1, 2024

No description provided.


// ensure that we update at most once per tick
auto frame_counter = df::global::world->frame_counter;
if (frame_counter == update_timestamp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will give incorrect results if a world is loaded, exited, and then a different world is loaded (since frame_counter is reset to 0 on world load). It would be safer if the update_timestamp were declared outside of this function, referenced as an extern in buildingplan.h (or buildingplan.cpp) and reset in plugin_load_site_data (where cycle_timestamp is reset)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean when you load a world, never unpause (or at least not long enough to reach a cycle), and then load a different world, you have one tick where there is stale data? Nice catch, I certainly didn't test that.

plugins/buildingplan/buildingplan_cycle.cpp Show resolved Hide resolved
@chdoc
Copy link
Member Author

chdoc commented Sep 1, 2024

I noticed that scanAvailableItems is not being called on every tick, even if the panel showing the currently available building materials is open. Where does this rate limiting come from, and are the various Lua functions that indirectly call this "synchronized" to do this on the same tick?

@myk002
Copy link
Member

myk002 commented Sep 1, 2024

I believe the rate limiting is coming from here:

function ItemLine:reset()
    self.desc = nil
    self.available = nil
end

...

function ItemLine:get_item_line_text()
    local idx = self.idx
    local filter = get_cur_filters()[idx]
    local quantity = get_quantity(filter, self.is_hollow_fn())

    local buildingplan = require('plugins.buildingplan')
    self.desc = self.desc or buildingplan.get_desc(filter)

    self.available = self.available or buildingplan.countAvailableItems(
        uibs.building_type, uibs.building_subtype, uibs.custom_type, idx - 1)
    if self.available >= quantity then
        self.note_pen = COLOR_GREEN
        self.note = (' %d available now'):format(self.available)
    elseif self.available >= 0 then
        self.note_pen = COLOR_BROWN
        self.note = (' Will link next (need to make %d)'):format(quantity - self.available)
    else
        self.note_pen = COLOR_BROWN
        self.note = (' Will link later (need to make %d)'):format(-self.available + quantity)
    end
    self.note = string.char(192) .. self.note -- character 192 is "└"

    return ('%d %s%s'):format(quantity, self.desc, quantity == 1 and '' or 's')
end

so buildingplan.countAvailableItems() is only being called when self.available is reset (which happens once a cycle or when other UI actions trigger it)

@myk002 myk002 merged commit 3ae8713 into DFHack:develop Sep 3, 2024
14 checks passed
@chdoc chdoc deleted the buildingplan-walkable branch September 3, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants