Hi Oleg,

I will try and answer your questions. Please bear in mind, though, that my
knowledge is from BfW 1.8. If things have changed since then, I might be
wrong on something I tell here.

1)
Yes, save_index was created due to performance reasons. The main difficulty
is presenting the load_game dialog. 

For that, you don't only have to know all the filenames: You also need to
investigate about all the things that are presented when a game is selected
in the list, namely map, turns, hero-icon etc.

To get those, you would have to (fully) parse every savefile which would
take very long.

The save_index stores all that information for every save. It's actually not
that much WML, but as said before, it is tedious to evaluate otherwise.


2)
Save_index is controlled by a class with the same name, that consists only
of static members. It is meant to represent globally available functionality
and you are not supposed to create instances of this class.

This class has a static member save_index_cfg, which gets filled by calling
save_index::load(), which in turn is done in save_index::save_summary as
well as save_index::write_save_index.
This config is meant to hold all the game information that needs to be
presented in the load_game dialog.

So by writing the save_index, updated information is put into
save_index_cfg.

You might also be right, that this information is not used anymore. When I
refactored the savegame functionality together with euschn, I also created a
new load_game dialog that uses the Gui2-framework of mordante. The new
dialog was optional and back then could be used by starting Wesnoth with the
command line parameter --new_widgets. 

The old dialog still relied on save_index, if I remember correctly. So if
--new_widgets is no longer there or the load_game dialog does not rely on it
anymore and/or the old load_game dialog doesn't exist anymore: Then yes,
save_index is no longer used.

3)
Probably correct, yes.

4)
Because the save_index_cfg is updated every time write_save_index gets
called, I don't think you will run into problems 1,2 or 3 (but you might
want to check that out).

Therefore from my perspective and knowledge, replacing direct file reading
in tgame_load with save_index information should be sufficient. There
shouldn't be any need for an update-function.
I hope it wasn't for unwanted dependencies that we decided not to use
save_index within the new dialog. But I can't remember right now. If you
have to introduce new dependencies it would be nice to check back on me
about that.



Hope that helps you along.

Greetings, Joerg Hinrichs (YogiHH)





-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im
Auftrag von Oleg Tsarev
Gesendet: Samstag, 4. Februar 2012 17:07
An: [email protected]
Betreff: [Wesnoth-dev] save_index file - purposes and current state

Hello guys,

I investigated "save_index" and confused by several things. General
questions:

1) Which the reason create save_index file?
If I right understood, only two purposes:
 a) decrease time of open "Load" dialog
 b) decrease time of render clicked save - show preview, game
description, company name, etc.

Perfomance reason, other words. Please approve/disapprove my understanding.

2) Unfortunatelly, right now "save_index" does not used by anywhere in game.

I see just single call of save_index: write_save_index() (I skipped
definition of class and definition of methods):

src/savegame.hpp:       /** Update the save_index */
src/dialogs.cpp:                config& cfg =
savegame::save_index::save_summary(i->name);
src/dialogs.cpp:        savegame::save_index::write_save_index();

You can check this by "find ./src -exec grep save_index". From this
point of view, right now save_index nobody used.
I also checked it by stacktraces *(see end of letter)

In typical game usage nowhere is used :(

3) I supposed - save_index used before, but right now code with usage
removed. I investigated revision history by git bisect and can't
confirm this -

commit fd497d4601f40acb0bc16c5c2ec3353767b94e92
Author: Sirp <Sirp@75b3775d-3801-0410-9e12-e2e43121521d>
Date:   Thu Jun 10 00:35:45 2004 +0000

    added new 'load' dialog. changed behavior of pressing 'space' to
end a unit's turn

    git-svn-id: svn+ssh://svn.gna.org/svn/wesnoth/trunk@2265
75b3775d-3801-0410-9e12-e2e43121521d

4) Current code directly read the dir with saves and parse every file
separatelly. You can see this in src/gui/dialogs/game_load.cpp:
tgame_load::display_savegame

So, I want to change this situation, and full support of the
"save_index" in soure code.
I need this at least for:
http://forums.wesnoth.org/viewtopic.php?f=10&t=36034&p=519985#p519985
- for group the saves by game I should parse all saves.
This is required a lot of time.

Suppose we avoid directly read the directory, and use "save_index"
instead of direct read.
Which problem we will meet?

1) SHORT: missed save_index
PROBLEM: User doesn't have "save_index" file, but have saves (for
example, he move saves from another folder). As result "save_index"
will no loaded, and user didn't see any saves.
SOLUTION: rebuild save_index by directly read saves files while game is
starting

2) SHORT: save_index file too old
PROBLEM: User add some new save files, not listed in save_index
SOLUTION: as in (1) - rebuild save_index directly from saves files
(probably read & parse just new files, not listed in save_index).

3) SHORT: user added save file while play to game and wants open it.
PROBLEM: added saves will not listed in "open" dialog without game restart.

SOLUTION (simple): on open "Load"  dialog read the filename and
modify_time from directory (this is right now happendessin tgame_load)
and compare their with information from save_index.

SOLUTION (hard): use inotify/similar things for get updates about new
files. Unreasonably complex solution.

So, right now I wants to do SOLUTION(3)(simple). I would like again
repeat what I will change:
1) replay direct file read in tgame_load by information from save_index
2) implement function "update" for save_index - function list all
files from save_directory, and update information in save_index file
3) call "update" function on every open of game load dialog.

How this plan for you?

Best regards, Oleg

savegame::save_index::load
savegame::save_index::save_summary
dialogs::load_game_dialog
savegame::loadgame::show_dialog
savegame::loadgame::load_game
game_controller::load_game
do_gameloop
main

savegame::save_index::load
savegame::save_index::write_save_index
dialogs::load_game_dialog
savegame::loadgame::show_dialog
savegame::loadgame::load_game
game_controller::load_game
do_gameloop
main

_______________________________________________
Wesnoth-dev mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-dev


_______________________________________________
Wesnoth-dev mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-dev

Reply via email to