Files
802d3fe01f Persistency subsystem update - Generics and history records (#22114)
# Summary

This PR is the next update to the persistency subsystem. The goal of
this PR is to provide more framework like functions to allow more types
of content to be made persistent.

Currently only volatile game objects created during a round can be (*in
a [clean](https://www.youtube.com/watch?v=rZ3ETK7-ZM8) way*) saved and
made persistent. This update attempts to provide methods to make
*everything*¹ persistent.

This introduces persistent generics and history.

## Database

The following things are going to be changed and added in the database  
(open in new tab for better visibility, PNG file includes the drawIO
code):

<img width="1692" height="1041" alt="aurora_persistency_db drawio"
src="https://github.com/user-attachments/assets/ea53f419-f9aa-4592-af8f-3a8d5edf3177"
/>

**Deviations on database implementation from diagram:**  
- Removed unique constraint on history table - Prevented adding multiple
records per round per attribute.

## Framework surface changes

- MC/VV: Moved global object track register to subsystem var space.
- MC/VV: Point of interest: Added history_cache and generic_cache to
subsystem var space.
- MC/VV: Updated subsystem stat entry message, now providing information
on cache sizes of new types.
- Added `singleton/persistent_type` defines (Type, clean-up rules,
finalization hook) and macros allowing new definitions of said types.
- Added cache structures that are also used for returns on public procs
in generics and history persistent types.
- Major new framework features: Persistent history (example: Mining
yield records) and persistent generics (example: Persistent Horizon
overmap position). See documentation for more information.

DrawIO diagram for documentation, includes source in it (open in new
tab):

<img width="200" height="200" alt="Persistence-subsystem-flowchart
drawio"
src="https://github.com/user-attachments/assets/51f28331-f999-49a2-a7cc-58278f7ae416"
/>

## Tasks

(These lists are not comprehensive.)

**General**
- [x] Update DB - Write SQL scripts.
- [x] Add subsystem modular files for generics and history.
- [x] Add type definition logic, macros.
- [x] Add type-DB init logic.
- [x] Logging.
- [x] A lot of testing. *A lot.*
- [x] Changelog.
- [x] Self-Review.
- [x] Update documentation on the persistence subsystem.

**"Persistent history"**
- [x] Add init logic.
- [x] Add finalize logic.
- [x] Add framework surface procs.
  - [x] Get last record.
  - [x] Get last X records.
  - [x] Add record.
  - [x] Add character ID related validation.
- [x] Add initial example mechanic.

**"Persistent generics"**
- [x] Add init logic.
- [x] Add finalize logic.
- [x] Add framework surface procs.
  - [x] Save.
  - [x] Load.
- [x] Add initial example mechanic.

## Changes

Too many changes to be listed here - Check changelog and actual changes.

## Warning

There are certain use/test cases that *cannot* be tested locally due to
missing preexisting data in the database. This should only affect new
data structures (new persistent types), not existing data.

¹ _Large scale persistent mapping is excluded for this version._

---------

Co-authored-by: Copilot <copilot@github.com>
2026-07-19 20:56:17 +02:00

120 lines
4.3 KiB
Plaintext

#define ZERO_WIDTH_SPACE "&#8203;" //prevents the UI elements from popping out of place when viewport gets too small
// Oxyginetion states
#define OXYGENATION_STATE_HIGH 5
#define OXYGENATION_STATE_NORMAL 4
#define OXYGENATION_STATE_LOW 3
#define OXYGENATION_STATE_VERY_LOW 2
#define OXYGENATION_STATE_NONE 1
#define OXYGENATION_STATE_UNDEFINED 0
GLOBAL_DATUM_INIT(crew_repository, /datum/repository/crew, new())
/datum/repository/crew
var/list/cache_data
/datum/repository/crew/New()
cache_data = list()
..()
/datum/repository/crew/proc/health_data(var/z_level)
var/list/crewmembers = list()
var/area_display_name
if(!z_level)
return crewmembers
var/datum/cache_entry/cache_entry = cache_data[num2text(z_level)]
if(!cache_entry)
cache_entry = new/datum/cache_entry
cache_data[num2text(z_level)] = cache_entry
if(world.time < cache_entry.timestamp)
return cache_entry.data
var/tracked = scan()
for(var/t in tracked)
var/obj/item/clothing/under/C = t
var/turf/pos = get_turf(C)
if((C) && (C.has_sensor) && (pos) && (pos.z == z_level) && (C.sensor_mode != SUIT_SENSOR_OFF) && !within_jamming_range(C))
if(istype(C.loc, /mob/living/carbon/human))
var/mob/living/carbon/human/H = C.loc
if(H.w_uniform != C)
continue
var/list/crewmemberData = list("area"=null, "x"=null, "y"=null, "z"=null, "level"=null, "ref" = "[REF(H)]")
crewmemberData["stype"] = C.sensor_mode
crewmemberData["name"] = H.get_authentification_name(if_no_id="Unknown")
crewmemberData["ass"] = H.get_assignment(if_no_id="Unknown", if_no_job="No Job")
if(C.sensor_mode >= SUIT_SENSOR_BINARY)
crewmemberData["pulse"] = "N/A"
crewmemberData["tpulse"] = -1
crewmemberData["cellCharge"] = -1
if(!H.isSynthetic())
if(H.should_have_organ(BP_HEART))
var/obj/item/organ/internal/heart/O = H.internal_organs_by_name[BP_HEART]
if (!O || !BP_IS_ROBOTIC(O)) // Don't make medical freak out over prosthetic hearts
crewmemberData["tpulse"] = H.status_flags & FAKEDEATH ? 0 : H.pulse()
crewmemberData["pulse"] = H.get_pulse(GETPULSE_TOOL)
else
if(isipc(H) && H.internal_organs_by_name[BP_IPCTAG]) // Don't make untagged IPCs obvious
var/obj/item/organ/internal/machine/power_core/cell = H.internal_organs_by_name[BP_CELL]
if(cell)
crewmemberData["cellCharge"] = cell.percent()
if(C.sensor_mode >= SUIT_SENSOR_VITAL)
crewmemberData["pressure"] = "N/A"
crewmemberData["toxyg"] = -1
crewmemberData["oxyg"] = OXYGENATION_STATE_UNDEFINED
if(!H.isSynthetic() && H.should_have_organ(BP_HEART))
crewmemberData["tpressure"] = H.get_blood_pressure_alert()
crewmemberData["pressure"] = H.get_blood_pressure()
crewmemberData["toxyg"] = H.get_blood_oxygenation()
switch (crewmemberData["toxyg"])
if(105 to INFINITY)
crewmemberData["oxyg"] = OXYGENATION_STATE_HIGH
if(BLOOD_VOLUME_SAFE to 105)
crewmemberData["oxyg"] = OXYGENATION_STATE_NORMAL
if(BLOOD_VOLUME_OKAY to BLOOD_VOLUME_SAFE)
crewmemberData["oxyg"] = OXYGENATION_STATE_LOW
if(BLOOD_VOLUME_BAD to BLOOD_VOLUME_OKAY)
crewmemberData["oxyg"] = OXYGENATION_STATE_VERY_LOW
if(-(INFINITY) to BLOOD_VOLUME_BAD)
crewmemberData["oxyg"] = OXYGENATION_STATE_NONE
crewmemberData["bodytemp"] = H.bodytemperature - T0C + (rand(-5, 5) / 10)
if(C.sensor_mode >= SUIT_SENSOR_TRACKING)
var/area/A = get_area(H)
area_display_name = get_area_display_name(A)
crewmemberData["area"] = area_display_name
crewmemberData["x"] = pos.x
crewmemberData["y"] = pos.y
crewmemberData["z"] = pos.z
crewmembers += list(crewmemberData)
crewmembers = sortByKeyText(crewmembers, "name")
cache_entry.timestamp = world.time + 5 SECONDS
cache_entry.data = crewmembers
return crewmembers
/datum/repository/crew/proc/scan()
var/list/tracked = list()
for(var/mob/living/carbon/human/H in GLOB.mob_list)
if(istype(H.w_uniform, /obj/item/clothing/under))
var/obj/item/clothing/under/C = H.w_uniform
if (C.has_sensor)
tracked |= C
return tracked
#undef ZERO_WIDTH_SPACE
#undef OXYGENATION_STATE_HIGH
#undef OXYGENATION_STATE_NORMAL
#undef OXYGENATION_STATE_LOW
#undef OXYGENATION_STATE_VERY_LOW
#undef OXYGENATION_STATE_NONE
#undef OXYGENATION_STATE_UNDEFINED