global character_registry *Global_CharacterRegistry = 0;

////////////////////////////////
//~ sixten: Character Registry Functions
static void CR_SetState(character_registry *State)
{
    Global_CharacterRegistry = State;
}

static character_registry *CR_GetState(void)
{
    return(Global_CharacterRegistry);
}

static character_list CR_GetCharacters(void)
{
    character_registry *Registry = CR_GetState();
    character_list List = Registry->Characters;
    return(List);
}

static void CR_Init(character_registry *State)
{
    CR_SetState(State);
    
    State->Arena = ArenaAllocate(Megabytes(32));
}

static character_entry *CR_EntryFromName(string Name)
{
    character_entry *Entry = 0;
    
    character_registry *Registry = CR_GetState();
    for(character_entry *Iter = Registry->Characters.First; Iter != 0; Iter = Iter->Next)
    {
        if(AreEqual(Name, Iter->Name))
        {
            Entry = Iter;
            break;
        }
    }
    
    if(!Entry)
    {
        Entry = PushStruct(Registry->Arena, character_entry);
        Entry->Name = PushString(Registry->Arena, Name);
        DLLInsertLast(Registry->Characters.First, Registry->Characters.Last, Entry);
    }
    
    return(Entry);
}