Files
Bubberstation/code/modules/buildmode
LemonInTheDark 5d9488cd2a Macro Optimizes Map Saving (100x) DO NOT CHURN STRINGS Edition (#80845)
## About The Pull Request

Yello!
This one is reasonably quick, tho I did some fixes too

This is the big one, fixes the buildmode tool sometimes locking disabled
for the whole round.
We do this by replacing the static var on buildmode with global var and
a global proc
This keeps a harddel on the buildmode datum from permalocking is_running
to TRUE

Also makes flipping the var BACK if something breaks significantly
easier for admins, so that's nice

Alright, smaller things now

Fixes lists of numbers failing to encoded improperly This was fixed on
shiptest, we failed to actually port their most recent revision
Fixes the shuttle flag not actually working because it used istype
instead of ispath
Changes obj_blacklist to a typecache for optimization's sake
Renames/moves some vars around to prevent weird double typing things
Removes a checktick in key gen, it's just costing more time then it
would save in overtime
Properly handles lists. We were only doing var encoding one layer deep,
need to do it alll the way down

Alright, now the optimizations

This proc is fucking HOT, and it's for really dumb reasons

This is a text gen proc, and it makes the mistake of generating text and
concatinating it with MORE text.
This is HORRIFICALLY EXPENSIVE because byond caches strings (can only be
one of each) and string churn fucks up that caching system something
fierce
Moving from strings to lists of strings we join at the end takes us from
like idk 100 seconds to save bare metastation to like 1.5
This is applied basically everywhere for obvious reasons

While I'm here, storing keys in a flat list and then using find to find
them, then using that index to lookup into another flat list is a bit
silly. Let's just make it an assoc list. Faster lookup, cleaner.

Oh also rather then iterating over all the vars on an object, let's
iterate over just the ones we care about yeah?

Let's see... no sense genning a key we'll never use, and having suffixes
be often non existent is silly just embrace the slight mess.

That's it I think, this takes us from 100 seconds to save metastation to
2.5 seconds to save ALL of metastation (I removed the vars limiter so I
could make sure var saving didn't fuck me up)

## Why It's Good For The Game

Cleans up some issues that we failed to port the fixes for, MASSIVELY
optimizes this (so it can finish in like 5/10 seconds and not 300!) and
ensures admins can always use the thing and don't risk dropping their
pet buildastation to the void.

Worth noting, this tool really should not be used for station mapping
outside an event context. It produces sorta buggy var edits, and WILL
fail to pull over context for shit. Please don't use it as such

Profiles (csv files I promise)

[Before](https://github.com/tgstation/tgstation/files/13853313/profiler.json)

[After](https://github.com/tgstation/tgstation/files/13853271/profiler.json)

I'd include my line by lines but I don't know how much you'd get out of
them. Here's an image tho


![image](https://github.com/tgstation/tgstation/assets/58055496/3f3148c5-8b1e-4bda-aa65-3983f9944a91)

## Changelog
🆑
fix: The map saving tool will no longer lock up and prevent all further
action at random
fix: Map saving now takes on the order of seconds, not minutes
fix: Fixes an issue with lists that caused strongdmm to report saved
maps as broken
/🆑
2024-01-20 10:14:45 +00:00
..

Buildmode

Code layout

Buildmode

Manager for buildmode modes. Contains logic to manage switching between each mode, and presenting a suitable user interface.

Effects

Special graphics used by buildmode modes for user interface purposes.

Buildmode Mode

Implementer of buildmode behaviors.

Existing varieties:

  • Basic

    Description:

    Allows creation of simple structures consisting of floors, walls, windows, and airlocks.

    Controls:

    • Left click a turf:

      "Upgrades" the turf based on the following rules below:

      • Space -> Tiled floor
      • Simulated floor -> Regular wall
      • Wall -> Reinforced wall
    • Right click a turf:

      "Downgrades" the turf based on the following rules below:

      • Reinforced wall -> Regular wall
      • Wall -> Tiled floor
      • Simulated floor -> Space
    • Right click an object:

      Deletes the clicked object.

    • Alt+Left click a location:

      Places an airlock at the clicked location.

    • Ctrl+Left click a location:

      Places a window at the clicked location.

  • Advanced

    Description:

    Creates an instance of a configurable atom path where you click.

    Controls:

    • Right click on the mode selector:

      Choose a path to spawn.

    • Left click a location (requires chosen path):

      Place an instance of the chosen path at the location.

    • Right click an object:

      Delete the object.

  • Fill

    Description:

    Creates an instance of an atom path on every tile in a chosen region.

    With a special control input, instead deletes everything within the region.

    Controls:

    • Right click on the mode selector:

      Choose a path to spawn.

    • Left click on a region (requires chosen path):

      Fill the region with the chosen path.

    • Alt+Left click on a region:

      Deletes everything within the region.

    • Right click during region selection:

      Cancel region selection.

  • Copy

    Description:

    Take an existing object in the world, and place duplicates with identical attributes where you click.

    May not always work nicely - "deep" variables such as lists or datums may malfunction.

    Controls:

    • Right click an existing object:

      Select the clicked object as a template.

    • Left click a location (Requires a selected object as template):

      Place a duplicate of the template at the clicked location.

  • Area Edit

    Description:

    Modifies and creates areas.

    The active area will be highlighted in yellow.

    Controls:

    • Right click the mode selector:

      Create a new area, and make it active.

    • Right click an existing area:

      Make the clicked area active.

    • Left click a turf:

      When an area is active, adds the turf to the active area.

  • Var Edit

    Description:

    Allows for setting and resetting variables of objects with a click.

    If the object does not have the var, will do nothing and print a warning message.

    Controls:

    • Right click the mode selector:

      Choose which variable to set, and what to set it to.

    • Left click an atom:

      Change the clicked atom's variables as configured.

    • Right click an atom:

      Reset the targeted variable to its original value in the code.

  • Map Generator

    Description:

    Fills rectangular regions with algorithmically generated content. Right click during region selection to cancel.

    See the procedural_mapping module for the generators themselves.

    Controls:

    • Right-click on the mode selector:

      Select a map generator from all the generators present in the codebase.

    • Left click two corners of an area:

      Use the generator to populate the region.

    • Right click during region selection:

      Cancel region selection.

  • Throwing

    Description:

    Select an object with left click, and right click to throw it towards where you clicked.

    Controls:

    • Left click on a movable atom:

      Select the atom for throwing.

    • Right click on a location:

      Throw the selected atom towards that location.

  • Boom

    Description:

    Make explosions where you click.

    Controls:

    • Right click the mode selector:

      Configure the explosion size.

    • Left click a location:

      Cause an explosion where you clicked.