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)

*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

Encyclopedist's Exaltation

**address (int), heap size (int), heap location (vec) → any**

Reads a value from an address in the heap.

## Patterns

Code: Select all

```
{
Encyclopedist's Assistant
Chronicler's Purification
Jester's Gambit
Selection Distillation
}
```

**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.

## Patterns

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
}
```

**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).

## Patterns

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
}
```

**heap size (int) → heap location (vec)**

Returns the position of a heap centered on the player's sentinel.

## Patterns

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
}
```

**address (int), heap size (int), heap location (vec) → list index (int), focus (entity)**

## Patterns

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
}
```

**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.

## Patterns

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
}
```