calref / cboe

Classic Blades of Exile
http://spiderwebforums.ipbhost.com/index.php?/forum/12-blades-of-exile/
Other
173 stars 42 forks source link

Feature Request: Console feedback on Successful Save #204

Open clort81 opened 4 years ago

clort81 commented 4 years ago

Hitting the Save icon outdoors (linux, aarch64) I see savefile updated, but no console confirmation.

In game/boe.actions.cpp do_save, i added a message incase (saved) not true, but that yields no console text either.

        if(saved)
                add_string_to_buf("Save: Game saved");
        else
                add_string_to_buf("Save: Error saving game!");

Exploring this now.

retropipes commented 4 years ago

Common culprits for this sort of thing: Writing to the wrong buffer; writing to the right buffer but on a thread that can't access it directly; writing to the right buffer on the right thread, but forgetting to check if it's full and gets cleared before your message ever shows up. Interested in this all the same.

clort81 commented 4 years ago

added to game/boe.actions.cpp

                        case 5:
                                if(overall_mode == MODE_OUTDOORS) {
                                        fs::path file = univ.file;
                                        bool saved = false;
                                        if(!file.empty()) {
                                                univ.file = file;
                                                saved = save_party(univ.file, univ); // Clort FIXME add error check to save_party
                                        }
                                        if(saved)
                                                add_string_to_buf("Save: Game saved");
                                        else
                                                add_string_to_buf("Save: Error saving game!");
                                        need_redraw = true;
                                        current_switch = 6;
                                        break;
                                } else if(overall_mode == MODE_TOWN) {
                                        add_string_to_buf("Use: Select a space or item.");
                                        add_string_to_buf("  (Hit button again to cancel.)");
                                        need_reprint = true;
                                        overall_mode = MODE_USE_TOWN;
                                } else if(overall_mode == MODE_USE_TOWN) {
                                        overall_mode = MODE_TOWN;
                                        need_reprint = true;
                                        add_string_to_buf("  Cancelled.");
                                } else if(overall_mode == MODE_COMBAT) {
                                        need_reprint = true;
                                        need_redraw = true;
                                        pc_delayed = true;
                                }

                                break;

That is complete case 5: sorry I don't know how to do the github contributing to project yet. I get console message for successful save now.

Unfortunately if i set savefile dir to unwriteable, savefile doesn't get created, but I still get "Game saved" because save_party() in fileio/fileio_party.cpp returns true no matter what.

some more reading shows we can catch an error after C++ open()

#include <iostream>
#include <fstream>

void log_message(const string& msg)
{
    std::ofstream out_file("data.log", 
             std::ios::out|std::ios::app|std::ios::ate);
    if (out_file.bad(  ))  
       // do something (what?) if we can't write
}

The actual open() is found in src/fileio/gzstream/gzstream.h

thanks wrldwzrd89! I hope i'm not wasting people's time!

CelticMinstrel commented 4 years ago

Note that gzstream is an external library, so we shouldn't be changing it.

Probably the reason your first version didn't work was a missing need_reprint = true, as the in-game console won't be redrawn unless that is true.

Also, there already is notification on successful save, though not on error...

clort81 commented 4 years ago

With current master git, i do not get a save game notification in game console.

CelticMinstrel commented 4 years ago

Hm, you're saving via the Save button while outdoors, right? I guess I can test that method, maybe there's something different about it…