Skip to content

Commit

Permalink
Merge branch 'develop' into squid-docs-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
realSquidCoder authored Jan 19, 2025
2 parents 0797342 + 6870494 commit c6a79fb
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 75 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/watch-df-steam.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ jobs:
structures_ref: adv-beta
dfhack_ref: adv-beta
steam_branch: adventure-beta
- df_steam_branch: testing
structures_ref: testing
dfhack_ref: testing
steps:
- name: Fetch state
uses: actions/cache/restore@v4
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cmake_policy(SET CMP0074 NEW)

# set up versioning.
set(DF_VERSION "50.15")
set(DFHACK_RELEASE "r1.2")
set(DFHACK_RELEASE "r2")
set(DFHACK_PRERELEASE FALSE)

set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}")
Expand Down
23 changes: 20 additions & 3 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,25 @@ Template for new versions:

## New Tools

## New Features

## Fixes

## Misc Improvements

## Documentation

## API

## Lua

## Removed

# 50.15-r2

## New Features
- `stockpiles`: add simple import/export dialogs to stockpile overlay panel
- `orders`: add overlays to the manager orders screen that allow right clicks to cancel edit of quantities or condition details instead of exiting to the main screen
- `orders`: add transparent overlays to the manager orders screen that allow right clicks to cancel edit of quantities or condition details instead of exiting to the main screen

## Fixes
- `preserve-rooms`: don't erroneously release reservations for units that have returned from their missions but have not yet entered the fort map
Expand All @@ -67,7 +83,7 @@ Template for new versions:

## Misc Improvements
- `strangemood`: add ability to choose Stone Cutting and Stone Carving as the mood skill
- `suspendmanager`: add more specific messages for submerged jobsites and those managed by `buildingplan`
- `suspendmanager`: add more specific messages for submerged job sites and those managed by `buildingplan`
- `dig-now`: handle digging in pool and river tiles

## Documentation
Expand All @@ -77,15 +93,16 @@ Template for new versions:
- ``Units::isUnitInBox``, ``Units::getUnitsInBox``: add versions accepting pos arguments
- ``Units::getVisibleName``: when acting on a unit without an impersonated identity, returns the unit's name structure instead of the associated histfig's name structure
- ``Translation::generateName``: generates in-game names, mirroring DF's internal logic
- ``Persistence::getUnsavedSeconds``: returns the number of seconds since last save or load

## Lua
- ``dfhack.units.isUnitInBox``, ``dfhack.units.getUnitsInBox``: add versions accepting pos arguments
- ``widgets.FilteredList``: search keys for list items can now be functions that return a string
- ``dfhack.translation.generateName``: Lua API for ``Translation::generateName``
- ``dfhack.persistent.getUnsavedSeconds``: Lua API for ``Persistence::getUnsavedSeconds``

## Removed
- ``dfhack.TranslateName`` has been renamed to ``dfhack.translation.translateName``
- ``Translation::TranslateName`` has been renamed to ``Translation::translateName``

## Internals
- Plugin command callbacks are now called with the core suspended by default so DF memory is always safe to access without extra steps
Expand Down
4 changes: 4 additions & 0 deletions docs/dev/Lua API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,10 @@ arbitrary Lua tables.
Same semantics as for the ``Site`` functions, but will associated the data
with the global world context.

* ``dfhack.persistent.getUnsavedSeconds()``

Returns the number of seconds since last save or load of a save.

The data is kept in memory, so no I/O occurs when getting or saving keys. It is
all written to a json file in the game save directory when the game is saved.

Expand Down
33 changes: 19 additions & 14 deletions library/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,30 +799,35 @@ command_result Core::runCommand(color_ostream &con, const std::string &first_, s
all = true;
}
}
auto ret = CR_OK;
if (all)
{
if (load)
plug_mgr->loadAll();
else if (unload)
plug_mgr->unloadAll();
else
plug_mgr->reloadAll();
return CR_OK;
if (load && !plug_mgr->loadAll())
ret = CR_FAILURE;
else if (unload && !plug_mgr->unloadAll())
ret = CR_FAILURE;
else if (!plug_mgr->reloadAll())
ret = CR_FAILURE;
}
for (auto p = parts.begin(); p != parts.end(); p++)
{
if (!p->size() || (*p)[0] == '-')
continue;
if (load)
plug_mgr->load(*p);
else if (unload)
plug_mgr->unload(*p);
else
plug_mgr->reload(*p);
if (load && !plug_mgr->load(*p))
ret = CR_FAILURE;
else if (unload && !plug_mgr->unload(*p))
ret = CR_FAILURE;
else if (!plug_mgr->reload(*p))
ret = CR_FAILURE;
}
if (ret != CR_OK)
con.printerr("%s failed\n", first.c_str());
return ret;
}
else
else {
con.printerr("%s: no arguments\n", first.c_str());
return CR_FAILURE;
}
}
else if( first == "enable" || first == "disable" )
{
Expand Down
6 changes: 6 additions & 0 deletions library/LuaApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,19 @@ static int dfhack_persistent_delete_world_data(lua_State *L) {
return delete_site_data(L, get_world_data);
}

static int dfhack_persistent_get_unsaved_seconds(lua_State *L) {
lua_pushinteger(L, Persistence::getUnsavedSeconds());
return 1;
}

static const luaL_Reg dfhack_persistent_funcs[] = {
{ "getSiteDataString", dfhack_persistent_get_site_data_string },
{ "saveSiteDataString", dfhack_persistent_save_site_data_string },
{ "deleteSiteData", dfhack_persistent_delete_site_data },
{ "getWorldDataString", dfhack_persistent_get_world_data_string },
{ "saveWorldDataString", dfhack_persistent_save_world_data_string },
{ "deleteWorldData", dfhack_persistent_delete_world_data },
{ "getUnsavedSeconds", dfhack_persistent_get_unsaved_seconds },
{ NULL, NULL }
};

Expand Down
33 changes: 0 additions & 33 deletions library/include/modules/Buildings.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,46 +58,13 @@ class color_ostream;

namespace Buildings
{
/**
* Structure for holding a read DF building object
* \ingroup grp_buildings
*/
struct t_building
{
uint32_t x1;
uint32_t y1;
uint32_t x2;
uint32_t y2;
uint32_t z;
t_matglossPair material;
df::building_type type;
union
{
int16_t subtype;
df::civzone_type civzone_type;
df::furnace_type furnace_type;
df::workshop_type workshop_type;
df::construction_type construction_type;
df::shop_type shop_type;
df::siegeengine_type siegeengine_type;
df::trap_type trap_type;
};
int32_t custom_type;
df::building * origin;
};

/**
* The Buildings module - allows reading DF buildings
* \ingroup grp_modules
* \ingroup grp_buildings
*/
DFHACK_EXPORT uint32_t getNumBuildings ();

/**
* read building by index
*/
DFHACK_EXPORT bool Read (const uint32_t index, t_building & building);

/**
* read mapping from custom_type value to building RAW name
* custom_type of -1 implies ordinary building
Expand Down
2 changes: 2 additions & 0 deletions library/include/modules/Persistence.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,7 @@ namespace DFHack
// Fills the vector with references to each persistent item with a key that is
// equal to the given key.
DFHACK_EXPORT void getAllByKey(std::vector<PersistentDataItem> &vec, int entity_id, const std::string &key);
// Returns the number of seconds since the current savegame was saved or loaded.
DFHACK_EXPORT uint32_t getUnsavedSeconds();
}
}
18 changes: 0 additions & 18 deletions library/modules/Buildings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,24 +278,6 @@ uint32_t Buildings::getNumBuildings()
return world->buildings.all.size();
}

bool Buildings::Read (const uint32_t index, t_building & building)
{
df::building *bld = world->buildings.all[index];

building.x1 = bld->x1;
building.x2 = bld->x2;
building.y1 = bld->y1;
building.y2 = bld->y2;
building.z = bld->z;
building.material.index = bld->mat_index;
building.material.type = bld->mat_type;
building.type = bld->getType();
building.subtype = bld->getSubtype();
building.custom_type = bld->getCustomType();
building.origin = bld;
return true;
}

bool Buildings::ReadCustomWorkshopTypes(map <uint32_t, string> & btypes)
{
vector <building_def *> & bld_def = world->raws.buildings.all;
Expand Down
16 changes: 16 additions & 0 deletions library/modules/Persistence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ using namespace DFHack;
static std::unordered_map<int, std::multimap<std::string, std::shared_ptr<Persistence::DataEntry>>> store;
static std::unordered_map<size_t, std::shared_ptr<Persistence::DataEntry>> entry_cache;

static uint32_t lastLoadSaveTickCount = 0;

size_t next_entry_id = 0; // goes more positive
int next_fake_df_id = -101; // goes more negative

Expand Down Expand Up @@ -189,13 +191,20 @@ static std::string getSaveFilePath(const std::string &world, const std::string &
return getSavePath(world) + "/dfhack-" + filterSaveFileName(name) + ".dat";
}

struct LastLoadSaveTickCountUpdater {
~LastLoadSaveTickCountUpdater() {
lastLoadSaveTickCount = Core::getInstance().p->getTickCount();
}
};

void Persistence::Internal::save(color_ostream& out) {
Core &core = Core::getInstance();

if (!core.isWorldLoaded())
return;

CoreSuspender suspend;
LastLoadSaveTickCountUpdater tickCountUpdater;

// write status
{
Expand Down Expand Up @@ -237,6 +246,7 @@ void Persistence::Internal::save(color_ostream& out) {
color_ostream_wrapper wrapper(file);
Lua::CallLuaModuleFunction(wrapper, "script-manager", "print_timers");
}

}

static bool get_entity_id(const std::string & fname, int & entity_id) {
Expand Down Expand Up @@ -283,6 +293,7 @@ static bool load_file(const std::string & path, int entity_id) {

void Persistence::Internal::load(color_ostream& out) {
CoreSuspender suspend;
LastLoadSaveTickCountUpdater tickCountUpdater;

clear(out);

Expand Down Expand Up @@ -417,3 +428,8 @@ void Persistence::getAllByKey(std::vector<PersistentDataItem> &vec, int entity_i
for (auto it = range.first; it != range.second; ++it)
vec.emplace_back(it->second);
}

uint32_t Persistence::getUnsavedSeconds() {
uint32_t durMS = Core::getInstance().p->getTickCount() - lastLoadSaveTickCount;
return durMS / 1000;
}
2 changes: 1 addition & 1 deletion library/xml
Submodule xml updated 1 files
+5 −0 changelog.txt
2 changes: 1 addition & 1 deletion scripts

0 comments on commit c6a79fb

Please sign in to comment.