|
|
@ -2312,59 +2312,61 @@ void frame(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
assert(!(it->exists && it->generation == 0));
|
|
|
|
assert(!(it->exists && it->generation == 0));
|
|
|
|
#ifdef WEB
|
|
|
|
#ifdef WEB
|
|
|
|
if(it->gen_request_id != 0)
|
|
|
|
if(it->is_npc)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
assert(it->gen_request_id > 0);
|
|
|
|
if(it->gen_request_id != 0)
|
|
|
|
int status = EM_ASM_INT({
|
|
|
|
|
|
|
|
return get_generation_request_status($0);
|
|
|
|
|
|
|
|
}, it->gen_request_id);
|
|
|
|
|
|
|
|
if(status == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// simply not done yet
|
|
|
|
assert(it->gen_request_id > 0);
|
|
|
|
}
|
|
|
|
int status = EM_ASM_INT({
|
|
|
|
else
|
|
|
|
return get_generation_request_status($0);
|
|
|
|
{
|
|
|
|
}, it->gen_request_id);
|
|
|
|
if(status == 1)
|
|
|
|
if(status == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// simply not done yet
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// done! we can get the string
|
|
|
|
if(status == 1)
|
|
|
|
char sentence_str[MAX_SENTENCE_LENGTH] = {0};
|
|
|
|
{
|
|
|
|
EM_ASM({
|
|
|
|
// done! we can get the string
|
|
|
|
let generation = get_generation_request_content($0);
|
|
|
|
char sentence_str[MAX_SENTENCE_LENGTH] = {0};
|
|
|
|
stringToUTF8(generation, $1, $2);
|
|
|
|
EM_ASM({
|
|
|
|
}, it->gen_request_id, sentence_str, ARRLEN(sentence_str));
|
|
|
|
let generation = get_generation_request_content($0);
|
|
|
|
|
|
|
|
stringToUTF8(generation, $1, $2);
|
|
|
|
|
|
|
|
}, it->gen_request_id, sentence_str, ARRLEN(sentence_str));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// parse out from the sentence NPC action and dialog
|
|
|
|
// parse out from the sentence NPC action and dialog
|
|
|
|
Perception out = {0};
|
|
|
|
Perception out = {0};
|
|
|
|
bool text_was_well_formatted = parse_ai_response(it, sentence_str, &out);
|
|
|
|
bool text_was_well_formatted = parse_ai_response(it, sentence_str, &out);
|
|
|
|
|
|
|
|
|
|
|
|
if(text_was_well_formatted)
|
|
|
|
if(text_was_well_formatted)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
process_perception(it, out);
|
|
|
|
process_perception(it, out);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
it->perceptions_dirty = true; // on poorly formatted AI, just retry request.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EM_ASM({
|
|
|
|
|
|
|
|
done_with_generation_request($0);
|
|
|
|
|
|
|
|
}, it->gen_request_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else if(status == 2)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
it->perceptions_dirty = true; // on poorly formatted AI, just retry request.
|
|
|
|
Log("Failed to generate dialog! Fuck!");
|
|
|
|
|
|
|
|
// need somethin better here. Maybe each sentence has to know if it's player or NPC, that way I can remove the player's dialog
|
|
|
|
|
|
|
|
process_perception(it, (Perception){.type = NPCDialog, .npc_action_type = ACT_none, .npc_dialog = SENTENCE_CONST("I'm not sure...")});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
it->gen_request_id = 0;
|
|
|
|
EM_ASM({
|
|
|
|
|
|
|
|
done_with_generation_request($0);
|
|
|
|
|
|
|
|
}, it->gen_request_id);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(status == 2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Log("Failed to generate dialog! Fuck!");
|
|
|
|
|
|
|
|
// need somethin better here. Maybe each sentence has to know if it's player or NPC, that way I can remove the player's dialog
|
|
|
|
|
|
|
|
process_perception(it, (Perception){.type = NPCDialog, .npc_action_type = ACT_none, .npc_dialog = SENTENCE_CONST("I'm not sure...")});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
it->gen_request_id = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
if(fabsf(it->vel.x) > 0.01f)
|
|
|
|
if(fabsf(it->vel.x) > 0.01f)
|
|
|
|
it->facing_left = it->vel.x < 0.0f;
|
|
|
|
it->facing_left = it->vel.x < 0.0f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(it->dead)
|
|
|
|
if(it->dead)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
it->dead_time += dt;
|
|
|
|
it->dead_time += dt;
|
|
|
|