Fix fault tolerant AI queries not working

main
Cameron Murphy Reikes 2 years ago
parent a5469c95ff
commit b71688f0b0

@ -1268,7 +1268,7 @@ typedef struct TouchMemory
} TouchMemory; } TouchMemory;
TouchMemory activate(uintptr_t by) TouchMemory activate(uintptr_t by)
{ {
Log("Activating %ld\n", by); //Log("Activating %ld\n", by);
return (TouchMemory){.active = true, .identifier = by}; return (TouchMemory){.active = true, .identifier = by};
} }
// returns if deactivated // returns if deactivated
@ -1278,7 +1278,7 @@ bool maybe_deactivate(TouchMemory *memory, uintptr_t ended_identifier)
{ {
if(memory->identifier == ended_identifier) if(memory->identifier == ended_identifier)
{ {
Log("Deactivating %ld\n", memory->identifier); //Log("Deactivating %ld\n", memory->identifier);
*memory = (TouchMemory){0}; *memory = (TouchMemory){0};
return true; return true;
} }
@ -1303,7 +1303,7 @@ float thumbstick_base_size()
} }
else else
{ {
return screen_size().x * 0.14; return screen_size().x * 0.14f;
} }
} }
@ -2525,7 +2525,7 @@ void frame(void)
{ {
Log("Failed to generate dialog! Fuck!"); 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 // 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
make_space_and_append(&it->player_dialog, (DialogElement){ .s = SENTENCE_CONST("I'm not sure..."), .author = NPC }); add_new_npc_sentence(it, "I'm not sure...");
} }
it->gen_request_id = 0; it->gen_request_id = 0;
} }

@ -7,6 +7,14 @@
"expandedProjectPaths": [ "expandedProjectPaths": [
], ],
"fileStates": { "fileStates": {
"assets/new_level.json": {
"scale": 0.25,
"selectedLayer": 1,
"viewCenter": {
"x": 1378,
"y": 1072
}
}
}, },
"last.imagePath": "C:/Users/Cameron/Documents/rpgpt/assets/copyrighted", "last.imagePath": "C:/Users/Cameron/Documents/rpgpt/assets/copyrighted",
"map.height": 100, "map.height": 100,
@ -16,6 +24,7 @@
], ],
"project": "main.tiled-project", "project": "main.tiled-project",
"recentFiles": [ "recentFiles": [
"assets/new_level.json"
], ],
"tileset.lastUsedFormat": "tsx" "tileset.lastUsedFormat": "tsx"
} }

@ -163,13 +163,13 @@ function on_textarea_key(event) {
final_textarea_string += cur_textarea_string[i]; final_textarea_string += cur_textarea_string[i];
} }
document.getElementById("inputtext").value = final_textarea_string; document.getElementById("inputtext").value = final_textarea_string;
if(should_end) end_dialog(); if(event.key === "Enter") should_end = true;
if(event.key === "Enter") end_dialog();
if(event.key === "Escape") if(event.key === "Escape")
{ {
document.getElementById("inputtext").value = ""; document.getElementById("inputtext").value = "";
end_dialog(); should_end = true;
} }
if(should_end) end_dialog();
} }
const max_retries = 5; const max_retries = 5;
@ -184,6 +184,11 @@ let generation_requests = []; // array of dictionaries with structure:
*/ */
function resend_request(r) { function resend_request(r) {
r.failed = false;
r.request = new XMLHttpRequest();
r.request.onerror = function(e) {
r.failed = true;
};
r.request.open("POST", r.request_info.url, true); r.request.open("POST", r.request_info.url, true);
r.request.send(r.request_info.body); r.request.send(r.request_info.body);
} }
@ -195,8 +200,9 @@ function make_generation_request(p, api) {
let to_push = { let to_push = {
"id": cur_id, "id": cur_id,
"request": new XMLHttpRequest(), "request": new XMLHttpRequest(),
"retries_remaining": 5, "retries_remaining": max_retries,
"request_info": {"url": api, "body": p} "request_info": {"url": api, "body": p},
"failed": false,
} }
console.log("Making generation request with id " + to_push.id); console.log("Making generation request with id " + to_push.id);
generation_requests.push(to_push) generation_requests.push(to_push)
@ -209,15 +215,23 @@ function make_generation_request(p, api) {
function get_generation_request_status(id) { function get_generation_request_status(id) {
for(let i = 0; i < generation_requests.length; i++) { for(let i = 0; i < generation_requests.length; i++) {
if(generation_requests[i].id == id) { if(generation_requests[i].id == id) {
let http_status = generation_requests[i].request.status; if(generation_requests[i].failed)
if(http_status == 200) { {
return 1;
} }
else if(http_status == 0) { // not done yet else
return 0; {
let http_status = generation_requests[i].request.status;
if(http_status == 200) {
return 1;
}
else if(http_status == 0) { // not done yet
return 0;
}
} }
else { // errored
{ // errored
if(generation_requests[i].retries_remaining > 0) { if(generation_requests[i].retries_remaining > 0) {
console.log("Retrying request");
generation_requests[i].retries_remaining -= 1; generation_requests[i].retries_remaining -= 1;
resend_request(generation_requests[i]); resend_request(generation_requests[i]);
return 0; return 0;

Loading…
Cancel
Save