horsegen: spam vectors to try to limit type check time
This commit is contained in:
@@ -3,68 +3,55 @@ module horse/{{ $.Region }}/character
|
||||
|
||||
// Automatically generated with horsegen; DO NOT EDIT
|
||||
|
||||
import std/core/delayed
|
||||
import std/core/vector
|
||||
import std/core-extras
|
||||
import std/data/rb-map
|
||||
import horse/game-id
|
||||
pub import horse/character
|
||||
|
||||
// Enumeration of all characters for type-safe programming.
|
||||
pub type character
|
||||
{{- range $uma := $.Characters }}
|
||||
{{ kkenum $uma.Name }}
|
||||
{{- end }}
|
||||
extern create-id-table(): vector<int>
|
||||
c inline "int32_t arr[] = { {{- range $chara := $.Characters }}{{ $chara.ID }},{{ end -}} };\nkk_vector_from_cint32array(arr, (kk_ssize_t){{ $.CharaCount }}, kk_context())"
|
||||
js inline "[{{ range $chara := $.Characters }}{{ $chara.ID }},{{ end }}]"
|
||||
// Vector of all character ID values in order for easy iterating.
|
||||
pub val all = once(create-id-table)
|
||||
|
||||
// Get the character ID for a character.
|
||||
pub fun character-id(c: character): character-id
|
||||
match c
|
||||
{{- range $uma := $.Characters }}
|
||||
{{ kkenum $uma.Name }} -> Character-id({{ $uma.ID }})
|
||||
{{- end }}
|
||||
|
||||
// List of all characters in ID order for easy iterating.
|
||||
pub val all = [
|
||||
{{- range $uma := $.Characters }}
|
||||
{{ kkenum $uma.Name }},
|
||||
{{- end }}
|
||||
]
|
||||
|
||||
val name2id: rbmap<string, character-id> = rb-map/empty()
|
||||
{{- range $uma := $.Characters }}
|
||||
.set({{ printf "%q" $uma.Name }}, Character-id({{ $uma.ID}}))
|
||||
{{- end }}
|
||||
val name2id = once()
|
||||
var m: rbmap<string, int> := empty()
|
||||
all().foreach() fn(id) m := m.set(Character-id(id).show, id)
|
||||
m
|
||||
|
||||
// Get the character ID that has the given exact name.
|
||||
// If no character matches the name, the result is an invalid ID.
|
||||
pub fun from-name(name: string): character-id
|
||||
name2id.lookup(name).default(Character-id(0))
|
||||
Character-id(name2id().rb-map/lookup(name).default(0))
|
||||
|
||||
// Get the name for a character.
|
||||
// If no character matches the ID, the result is the numeric ID.
|
||||
pub fun show(c: character-id): string
|
||||
match c.game-id
|
||||
{{- range $uma := $.Characters }}
|
||||
{{ $uma.ID }} -> {{ printf "%q" $uma.Name }}
|
||||
{{- range $chara := $.Characters }}
|
||||
{{ $chara.ID }} -> {{ printf "%q" $chara.Name }}
|
||||
{{- end }}
|
||||
x -> "character " ++ x.show
|
||||
|
||||
fun character/index(c: character-id): int
|
||||
match c.game-id
|
||||
{{- range $uma := $.Characters }}
|
||||
{{ $uma.ID }} -> {{ $uma.Index }}
|
||||
{{- range $chara := $.Characters }}
|
||||
{{ $chara.ID }} -> {{ $chara.Index }}
|
||||
{{- end }}
|
||||
_ -> -99999999
|
||||
|
||||
// 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[] = {
|
||||
c inline "int32_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())"
|
||||
};\nkk_vector_from_cint32array(arr, (kk_ssize_t){{ $.CharaCount }} * (kk_ssize_t){{ $.CharaCount }}, kk_context())"
|
||||
js inline "[
|
||||
{{- range $a := $.Characters }}
|
||||
{{- range $b := $.Characters }}
|
||||
@@ -76,12 +63,12 @@ val global/pair-table = global/create-pair-table()
|
||||
|
||||
// Base affinity between a pair using the global ruleset.
|
||||
pub fun global/pair-affinity(a: character-id, b: character-id): int
|
||||
global/pair-table.at(a.index * {{ $.Count }} + b.index).default(0)
|
||||
global/pair-table.at(a.index * {{ $.CharaCount }} + 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[] = {
|
||||
c inline "int32_t arr[] = {
|
||||
{{- range $a := $.Characters }}
|
||||
{{- range $b := $.Characters }}
|
||||
{{- range $c := $.Characters }}
|
||||
@@ -89,7 +76,7 @@ extern global/create-trio-table(): vector<int>
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end -}}
|
||||
};\nkk_vector_from_cintarray(arr, (kk_ssize_t){{ $.Count }} * (kk_ssize_t){{ $.Count }} * (kk_ssize_t){{ $.Count }}, kk_context())"
|
||||
};\nkk_vector_from_cint32array(arr, (kk_ssize_t){{ $.CharaCount }} * (kk_ssize_t){{ $.CharaCount }} * (kk_ssize_t){{ $.CharaCount }}, kk_context())"
|
||||
js inline "[
|
||||
{{- range $a := $.Characters }}
|
||||
{{- range $b := $.Characters }}
|
||||
@@ -103,6 +90,6 @@ val global/trio-table = global/create-trio-table()
|
||||
|
||||
// Base affinity for a trio using the global ruleset.
|
||||
pub fun global/trio-affinity(a: character-id, b: character-id, c: character-id): int
|
||||
global/trio-table.at(a.index * {{ $.Count }} * {{ $.Count }} + b.index * {{ $.Count }} + c.index).default(0)
|
||||
global/trio-table.at(a.index * {{ $.CharaCount }} * {{ $.CharaCount }} + b.index * {{ $.CharaCount }} + c.index).default(0)
|
||||
|
||||
{{- end }}
|
||||
|
||||
Reference in New Issue
Block a user