Heaps

Post your coolest Hexcasting creations here.

New topics are NOT for chatting or asking help, put those in the comments of a post or in a different forum.
User avatar
[object Object]
Posts: 70
Joined: Fri Dec 02, 2022 12:37 am

Heaps

Post by [object Object] »

Heaps

This is a set of macros that can be used to implement "heap memory" in Hex Casting - a system that allows random access to integer memory addresses within a cube of in-world focuses. Requires Hex Gloop, or any other mod that allows you to fit one focus per block (ie. not item frames).

Memory addresses start at 0 and fill up each focus before moving to the next. Focus coordinates iterate x, then z, then y. Each focus can store up to 1000 iotas (technically 1022 is possible, but then we'd have to deal with Shame). For example, with a 3x3 heap centered at (0, 0, 0), this would be the focus position corresponding to each chunk of the address space:
  • 0-999: (-1, -1, -1)
  • 1000-1999: (0, -1, -1)
  • 2000-2999: (1, -1, -1)
  • 3000-3999: (-1, -1, 0)
  • ...
  • 9000-9999: (-1, 0, -1)
  • ...
  • 26000-26999: (1, 1, 1)
Note: all of the read/write macros require the heap start position (ie. the position of the 0-999 focus), not the center of the focus. A convenience macro is provided to calculate the start position of a heap centered on the player's sentinel given the size of the heap (eg. 3x3x3 cube = size 3).

These macros are also available on GitHub: object-Object/hex-hexes/macros/Heaps.hexpattern

Image

Encyclopedist's Exaltation
address (int), heap size (int), heap location (vec)any
Reads a value from an address in the heap.
aqqqqqeqaqqqqq
Patterns
qqqeeqaqqqqqdqqqqqaqeewawqwqwqwqwqwaawdddeeedeee

Code: Select all

{
    Encyclopedist's Assistant
    Chronicler's Purification
    Jester's Gambit
    Selection Distillation
}
Encyclopedist's Gambit
value (any), address (int), heap size (int), heap location (vec)
Writes a value to an address in the heap. Preventing serde errors with nested lists is left as an exercise for the hexcaster.
deeeeeqqaqqqqq
Patterns
qqqeeqaqqqqqdqqqqqaqeeddqaawawqwqwqwqwqwaadadaawaqaeaqwddwaadaaNumerical Reflection: 0eeqqqBookkeeper's Gambit: Drop 1qeewdweddwddqddNumerical Reflection: 1waawaadaaeqqwawqaawdaawddaadaadaaqeewdweddwewdqdweqaeaqaawddeqqwawqaaweeeaaqwqaaawdddeaqqaawddNumerical Reflection: 4ddadwqaeaqwwdweweweweweweee

Code: Select all

#define Encyclopedist's Gambit (EAST deeeeeqqaqqqqq) = any, int, int, vec ->
// value, address, heap size, heap location ->
// writes a value to an address in the heap
// preventing serde errors with nested lists is left as an exercise for the hexcaster
{
    Encyclopedist's Assistant
    Undertaker's Gambit
    Chronicler's Purification

    // if the index is out of range, insert nulls to cover the difference
    Dioscuri Gambit
    Abacus Purification
    Subtractive Distillation
    Gemini Decomposition
    Numerical Reflection: 0
    Maximus Distillation II
    {
        // if false
        Bookkeeper's Gambit: v
        
        // if true
        Muninn's Reflection
        Rotation Gambit II
        
        Numerical Reflection: 1
        Additive Distillation
        Gemini Decomposition
        Huginn's Gambit
        
        Nullary Reflection
        Jester's Gambit
        Gemini Gambit
        Muninn's Reflection
        Flock's Gambit
        Combination Distillation
        
        Jester's Gambit
        Huginn's Gambit
    }
    Speaker's Decomposition
    Augur's Exaltation
    Hermes' Gambit

    // write new value
    Jester's Gambit
    Numerical Reflection: 4
    Fisherman's Gambit
    Surgeon's Exaltation

    Chronicler's Gambit
}
Encyclopedist's Gambit II
value (any), address (int), heap size (int), heap location (vec)
Writes a value to an address in the heap. UNSAFE - will mishap if writing to an orphaned index (ie. no adjacent iotas).
deeeeeaeeeeedq
Patterns
qqqeeqaqqqqqdqqqqqaqeeddqaawawqwqwqwqwqwaawddNumerical Reflection: 4ddadwqaeaqwwdweweweweweweee

Code: Select all

#define Encyclopedist's Gambit II (EAST deeeeeaeeeeedq) = any, int, int, vec ->
// value, address, heap size, heap location ->
// writes a value to an address in the heap
// UNSAFE - will mishap if writing to an orphaned index (no adjacent iotas)
{
    Encyclopedist's Assistant
    Undertaker's Gambit
    Chronicler's Purification

    Jester's Gambit
    Numerical Reflection: 4
    Fisherman's Gambit
    Surgeon's Exaltation

    Chronicler's Gambit
}
Locate Heap
heap size (int)heap location (vec)
Returns the position of a heap centered on the player's sentinel.
qaqqqqqewdedqde
Patterns
qqqwaeawaedeaawddNumerical Reflection: 2wdedwewqwddweee

Code: Select all

#define Locate Heap (SOUTH_EAST qaqqqqqewdedqde) = int -> vec
// heap size -> heap position
// returns the position of a heap centered on the player's sentinel
{
    Locate Sentinel
    Jester's Gambit
    Numerical Reflection: 2
    Division Distillation
    Floor Purification
    Subtractive Distillation
}
Encyclopedist's Assistant
address (int), heap size (int), heap location (vec)list index (int), focus (entity)
eeqaqqqqqdqqqqqaqee
Patterns
qqqaawddaaeaaNumerical Reflection: 1000aadadaawaddwaadddqddddqaawdedwewqaawddaddwaadaaeaaqaqqqqqdeeeaaeaawaawqqqqqdaqaeee

Code: Select all

#define Encyclopedist's Assistant (NORTH_EAST eeqaqqqqqdqqqqqaqee) = int, int, vec -> int, entity
// address, heap size, heap location -> index, focus
// internal helper macro
{
    // index in focus
    Jester's Gambit
    Rotation Gambit
    // max size of a focus
    // technically each focus could store up to 1022 iotas
    // but we don't have to deal with Shame if we use 1000
    Numerical Reflection: 1000
    Dioscuri Gambit
    Modulus Distillation
    Rotation Gambit II
    
    // index in heap
    Undertaker's Gambit
    Division Distillation
    Floor Purification
    Jester's Gambit
    Modulus Distillation

    // focus entity
    Rotation Gambit
    Cubic Index Distillation
    Rotation Gambit
    Additive Distillation
    Entity Purification
}
Cubic Index Distillation
index (int), size (int)offset (vec)
Converts a 1D index to a position in a 3D cube. Iterates x+, then z+, then y+, starting from the origin.
qaqqqqqdeee
Patterns
qqqaadadaawaddwaadddqddaadadaawddqaawdedwewqaawddaddwaadddqddaadaawaqawwdedwewqaawddeqqqqqeee

Code: Select all

#define Cubic Index Distillation (EAST qaqqqqqdeee) = int, int -> vec
// index, size -> coord
// iterates x+, then z+, then y+
{
    // x
    Dioscuri Gambit
    Modulus Distillation
    Rotation Gambit II
    
    // z
    Dioscuri Gambit
    Undertaker's Gambit
    Division Distillation
    Floor Purification
    Jester's Gambit
    Modulus Distillation
    Rotation Gambit II
    
    // y
    Gemini Decomposition
    Multiplicative Distillation
    Division Distillation
    Floor Purification

    Jester's Gambit
    Vector Exaltation
}