generate characters with sane compile time/memory

This commit is contained in:
2026-01-07 16:36:50 -05:00
parent 4bd9100954
commit b134bea670
7 changed files with 210 additions and 80039 deletions

View File

@@ -3,14 +3,17 @@ module horse/character
// Automatically generated with the horsegen tool; DO NOT EDIT
import std/core/vector
import std/core-extras
// Character identity.
pub type character
{{- range $uma := $.Characters }}
{{ kkenum $uma.Name }}
{{- end }}
// The list of all characters.
val character/all = [
// The list of all characters in order by ID, for easy iterating.
pub val character/all = [
{{- range $uma := $.Characters }}
{{ kkenum $uma.Name }},
{{- end }}
@@ -58,24 +61,32 @@ pub fun character/(==)(a: character, b: character): bool
{{- end }}
_ -> False
inline fip fun character/index(^c: character): int
match c
{{- range $uma := $.Characters }}
{{ kkenum $uma.Name }} -> {{ $uma.Index }}
{{- end }}
// Create the table of all pair affinities.
// The affinity is the value at a.index*count + b.index.
extern global/create-pair-table(): vector<int>
c inline "kk_intx_t arr[] = { {{- range $a := $.Characters }}{{ range $b := $.Characters }}{{ index $.PairMaps $a.ID $b.ID }},{{ end }}{{ end -}} };\nkk_vector_from_cintarray(arr, (kk_ssize_t){{ $.Count }}*(kk_ssize_t){{ $.Count }}, kk_context())"
js inline "[ {{- range $a := $.Characters }}{{ range $b := $.Characters }}{{ index $.PairMaps $a.ID $b.ID }},{{ end }}{{ end -}} ]"
val global/pair-table = global/create-pair-table()
// Base affinity between a pair using the global ruleset.
pub fun global/pair-affinity(a: character, b: character): int
match (a, b)
{{- range $pair := $.Pairs }}
( {{- kkenum $pair.NameA }}, {{ kkenum $pair.NameB -}} ) -> {{ $pair.Affinity }}
{{- end }}
// Reflexive cases are always 0.
{{- range $uma := $.Characters }}{{ $e := kkenum $uma.Name }}
( {{- $e }}, {{ $e -}} ) -> 0
{{- end }}
global/pair-table.at(a.index * {{ $.Count }} + b.index).default(0)
// Create the table of all trio affinities.
// The affinity is the value at a.index*count*count + b.index*count + c.index.
extern global/create-trio-table(): vector<int>
c inline "kk_intx_t arr[] = { {{- range $a := $.Characters }}{{ range $b := $.Characters }}{{ range $c := $.Characters }}{{ index $.TrioMaps $a.ID $b.ID $c.ID }},{{ end }}{{ end }}{{ end -}} };\nkk_vector_from_cintarray(arr, (kk_ssize_t){{ $.Count }}*(kk_ssize_t){{ $.Count }}*(kk_ssize_t){{ $.Count }}, kk_context())"
js inline "[ {{- range $a := $.Characters }}{{ range $b := $.Characters }}{{ range $c := $.Characters }}{{ index $.TrioMaps $a.ID $b.ID $c.ID }},{{ end }}{{ end }}{{ end -}} ]"
val global/trio-table = global/create-trio-table()
{{/* TODO: probably use a data structure instead of hoping the compilers fix this */ -}}
// Base affinity for a trio using the global ruleset.
pub fun global/trio-affinity(a: character, b: character, c: character): int
match (a, b, c)
{{- range $trio := $.Trios }}
( {{- kkenum $trio.NameA }}, {{ kkenum $trio.NameB }}, {{ kkenum $trio.NameC -}} ) -> {{ $trio.Affinity }}
{{- end }}
(_, _, _) -> 0
global/trio-table.at(a.index * {{ $.Count }} * {{ $.Count }} + b.index * {{ $.Count }} + c.index).default(0)
{{- end }}