static u64 S2_CallFunctionIndexFromString(string String) { u64 Result = 0; for(u64 Index = 0; Index < ArrayCount(S2_CallNameLookup); Index += 1) { if(AreEqual(String, S2_CallNameLookup[Index])) { Result = Index; break; } } return(Result); } static scene2_call_function *S2_CallFunctionFromString(string String) { scene2_call_function *Result = S2_Call_Stub; for(u64 Index = 0; Index < ArrayCount(S2_CallNameLookup); Index += 1) { if(AreEqual(String, S2_CallNameLookup[Index])) { Result = S2_CallBindingLookup[Index]; break; } } return(Result); } static S2_CALL_FUNCTION(S2_Call_StackSanity) { scene2_object Value = S2_StackPop(Runtime); Assert(Value.Kind == S2_ObjectKind_Number && Runtime->StackPointer == (u64)Value.As.Number); } static S2_CALL_FUNCTION(S2_Call_TextClear) { scene_view *SceneView = (scene_view *)Runtime->Data; SceneView->TextboxUsed = 0; SceneView->TextboxRevealed = 0; } static S2_CALL_FUNCTION(S2_Call_NewLine) { scene_view *SceneView = (scene_view *)Runtime->Data; if(SceneView->TextboxUsed < ArrayCount(SceneView->TextboxData)) { SceneView->TextboxData[SceneView->TextboxUsed++] = '\n'; } } static S2_CALL_FUNCTION(S2_Call_TextAppend) { scene_view *SceneView = (scene_view *)Runtime->Data; temp Scratch = GetScratch(); string Addend = S2_StringFromObject(Scratch.Arena, S2_StackPop(Runtime)); Addend.Count = Min(Addend.Count, ArrayCount(SceneView->TextboxData)-SceneView->TextboxUsed); Copy(SceneView->TextboxData+SceneView->TextboxUsed, Addend.Data, Addend.Count); SceneView->TextboxUsed += Addend.Count; ReleaseScratch(Scratch); } static S2_CALL_FUNCTION(S2_Call_ProcSet) { temp Scratch = GetScratch(); S2_SetCurrentProc(Runtime, S2_ProcFromName(Compiled, S2_StringFromObject(Scratch.Arena, S2_StackPop(Runtime)))); ReleaseScratch(Scratch); } static S2_CALL_FUNCTION(S2_Call_CharacterSet) { scene_view *SceneView = (scene_view *)Runtime->Data; scene2_object IDObject = S2_StackPop(Runtime); scene2_object TargetObject = S2_StackPop(Runtime); // sixten(TODO): this should fail gracefully Assert(IDObject.Kind == S2_ObjectKind_Number || IDObject.Kind == S2_ObjectKind_Nil); Assert(TargetObject.Kind == S2_ObjectKind_String); string Target = TargetObject.As.String; asset_id ID = IDObject.Kind == S2_ObjectKind_Number ? (asset_id)IDObject.As.Number : AssetID_None; scene_view_character_data *CharacterBegin = SceneView->Characters; scene_view_character_data *CharacterUsedEnd = SceneView->Characters+SceneView->CharactersUsed; scene_view_character_data *CharacterEnd = SceneView->Characters+ArrayCount(SceneView->Characters); scene_view_character_data *Character = CharacterBegin; for(;Character < CharacterEnd; Character += 1) { // sixten: check if the character doesn't exist if(Character == CharacterUsedEnd) { // sixten: "create" new character ZeroStruct(Character); Character->Name = PushString(SceneView->SceneArena, Target); SceneView->CharactersUsed += 1; Character->PctP = ((r32)SceneView->CharactersUsed / (r32)(SceneView->CharactersUsed+1)); break; } // sixten: check if character exists if(AreEqual(Character->Name, Target)) { break; } } if(Character != CharacterEnd) { Character->Active = true; if(ID != AssetID_None) { Character->Info.Texture = A_TextureFromAssetID(ID); Character->Info.Scale = A_ScaleFromAssetID(ID); } } else { // sixten: we've run out of characters } } static S2_CALL_FUNCTION(S2_Call_CharacterRemove) { scene_view *SceneView = (scene_view *)Runtime->Data; scene2_object TargetObject = S2_StackPop(Runtime); // sixten(TODO): this should fail gracefully Assert(TargetObject.Kind == S2_ObjectKind_String); string Target = TargetObject.As.String; scene_view_character_data *CharacterBegin = SceneView->Characters; scene_view_character_data *CharacterEnd = SceneView->Characters+SceneView->CharactersUsed; scene_view_character_data *Character = CharacterBegin; // sixten: check if the character exists for(;Character < CharacterEnd; Character += 1) { if(AreEqual(Character->Name, Target)) { break; } } // sixten: if the character exists, request its deletion if(Character != CharacterEnd) { Character->Active = false; Character->Talking = false; } } static S2_CALL_FUNCTION(S2_Call_CharacterSetTalking) { scene_view *SceneView = (scene_view *)Runtime->Data; scene2_object TargetObject = S2_StackPop(Runtime); // sixten(TODO): this should fail gracefully Assert(TargetObject.Kind == S2_ObjectKind_String); string Target = TargetObject.As.String; scene_view_character_data *CharacterBegin = SceneView->Characters; scene_view_character_data *CharacterEnd = SceneView->Characters+SceneView->CharactersUsed; scene_view_character_data *Character = CharacterBegin; // sixten: check if the character exists for(;Character < CharacterEnd; Character += 1) { if(AreEqual(Character->Name, Target)) { break; } } // sixten: if the character exists, request its deletion if(Character != CharacterEnd) { Character->Talking = true; } } static S2_CALL_FUNCTION(S2_Call_CharacterUnsetAllTalking) { scene_view *SceneView = (scene_view *)Runtime->Data; scene_view_character_data *CharacterBegin = SceneView->Characters; scene_view_character_data *CharacterEnd = SceneView->Characters+SceneView->CharactersUsed; scene_view_character_data *Character = CharacterBegin; for(;Character < CharacterEnd; Character += 1) { Character->Talking = false; } }