fixed bug in reading/writing compressed WML data (CVS internal)
This commit is contained in:
parent
565603f5de
commit
96d6d04bf7
6 changed files with 66 additions and 47 deletions
|
@ -787,11 +787,6 @@ std::string config::write() const
|
|||
// it is mapped to the first available character. Any attribute found is always followed
|
||||
// by a nul-delimited string which is the value for the attribute.
|
||||
//
|
||||
// once the number of words in the schema exceeds 'compress_extended_word', the schema
|
||||
// will begin using two-byte word codes. Any word code which has a character above
|
||||
// 'compress_extended_word' is assumed to be part of a two-byte word code, and the second
|
||||
// byte will be read as part of that word code
|
||||
//
|
||||
// the schema objects are designed to be persisted. That is, in a network game, both peers
|
||||
// can store their schema objects, and so rather than sending schema data each time, the peers
|
||||
// use and build their schemas as the game progresses, adding a new word to the schema anytime
|
||||
|
@ -799,10 +794,8 @@ std::string config::write() const
|
|||
namespace {
|
||||
const unsigned int compress_open_element = 0, compress_close_element = 1,
|
||||
compress_schema_item = 2, compress_literal_word = 3,
|
||||
compress_first_word = 4, compress_extended_word = 250,
|
||||
compress_end_words = 256;
|
||||
const size_t compress_max_basewords = compress_extended_word - compress_first_word;
|
||||
const size_t compress_max_words = compress_max_basewords + (compress_end_words - compress_extended_word)*compress_end_words;
|
||||
compress_first_word = 4, compress_end_words = 256;
|
||||
const size_t compress_max_words = compress_end_words - compress_first_word;
|
||||
|
||||
void compress_output_literal_word(const std::string& word, std::vector<char>& output)
|
||||
{
|
||||
|
@ -814,9 +807,6 @@ namespace {
|
|||
compression_schema::word_char_map::const_iterator add_word_to_schema(const std::string& word, compression_schema& schema)
|
||||
{
|
||||
unsigned int c = compress_first_word + schema.word_to_char.size();
|
||||
if(c >= compress_extended_word) {
|
||||
c = ((compress_extended_word - 1 + c/compress_extended_word) << 8) + (c%compress_extended_word);
|
||||
}
|
||||
|
||||
schema.char_to_word.insert(std::pair<unsigned int,std::string>(c,word));
|
||||
return schema.word_to_char.insert(std::pair<std::string,unsigned int>(word,c)).first;
|
||||
|
@ -849,12 +839,7 @@ namespace {
|
|||
const compression_schema::word_char_map::const_iterator w = get_word_in_schema(word,schema,res);
|
||||
if(w != schema.word_to_char.end()) {
|
||||
//the word is in the schema, all we have to do is output the compression code for it.
|
||||
if(w->second >= compress_extended_word) {
|
||||
res.push_back(w->second >> 8);
|
||||
res.push_back(w->second & 8);
|
||||
} else {
|
||||
res.push_back(w->second);
|
||||
}
|
||||
res.push_back(w->second);
|
||||
} else {
|
||||
//the word is not in the schema. Output it as a literal word
|
||||
res.push_back(char(compress_literal_word));
|
||||
|
@ -936,12 +921,6 @@ std::string::const_iterator config::read_compressed_internal(std::string::const_
|
|||
} else {
|
||||
const unsigned char c = *i1;
|
||||
unsigned int code = c;
|
||||
if(code >= compress_extended_word) {
|
||||
++i1;
|
||||
const unsigned char c = *i1;
|
||||
code <<= 8;
|
||||
code += c;
|
||||
}
|
||||
|
||||
const compression_schema::char_word_map::const_iterator itor = schema.char_to_word.find(code);
|
||||
if(itor == schema.char_to_word.end()) {
|
||||
|
|
|
@ -113,12 +113,13 @@ hotkey_item::hotkey_item(const config& cfg) : lastres(false)
|
|||
alt = (cfg["alt"] == "yes");
|
||||
ctrl = (cfg["ctrl"] == "yes");
|
||||
shift = (cfg["shift"] == "yes");
|
||||
command = (cfg["cmd"] == "yes");
|
||||
}
|
||||
|
||||
bool operator==(const hotkey_item& a, const hotkey_item& b)
|
||||
{
|
||||
return a.keycode == b.keycode && a.alt == b.alt &&
|
||||
a.ctrl == b.ctrl && a.shift == b.shift;
|
||||
a.ctrl == b.ctrl && a.shift == b.shift && a.command == b.command;
|
||||
}
|
||||
|
||||
bool operator!=(const hotkey_item& a, const hotkey_item& b)
|
||||
|
@ -140,18 +141,19 @@ struct hotkey_pressed {
|
|||
|
||||
private:
|
||||
int keycode_;
|
||||
bool shift_, ctrl_, alt_;
|
||||
bool shift_, ctrl_, alt_, command_;
|
||||
};
|
||||
|
||||
hotkey_pressed::hotkey_pressed(const SDL_KeyboardEvent& event)
|
||||
: keycode_(event.keysym.sym), shift_(event.keysym.mod&KMOD_SHIFT),
|
||||
ctrl_(event.keysym.mod&KMOD_CTRL), alt_(event.keysym.mod&KMOD_ALT)
|
||||
ctrl_(event.keysym.mod&KMOD_CTRL), alt_(event.keysym.mod&KMOD_ALT),
|
||||
command_(event.keysym.mod&KMOD_LMETA)
|
||||
{}
|
||||
|
||||
bool hotkey_pressed::operator()(const hotkey::hotkey_item& hk) const
|
||||
{
|
||||
return hk.keycode == keycode_ && shift_ == hk.shift &&
|
||||
ctrl_ == hk.ctrl && alt_ == hk.alt;
|
||||
ctrl_ == hk.ctrl && alt_ == hk.alt && command_ == hk.command;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@ -216,6 +218,7 @@ void save_hotkeys(config& cfg)
|
|||
(*item)["alt"] = (i->alt) ? "yes" : "no";
|
||||
(*item)["ctrl"] = (i->ctrl) ? "yes" : "no";
|
||||
(*item)["shift"] = (i->shift) ? "yes" : "no";
|
||||
(*item)["cmd"] = (i->command) ? "yes" : "no";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ struct hotkey_item {
|
|||
|
||||
HOTKEY_COMMAND action;
|
||||
int keycode;
|
||||
bool alt, ctrl, shift;
|
||||
bool alt, ctrl, shift, command;
|
||||
mutable bool lastres;
|
||||
};
|
||||
|
||||
|
|
|
@ -241,8 +241,10 @@ bool show_intro_part(display& screen, const config& part,
|
|||
|
||||
void show_map_scene(display& screen, config& data)
|
||||
{
|
||||
std::cerr << "showing map scene...\n";
|
||||
//stop the screen being resized while we're in this function
|
||||
const events::resize_lock stop_resizing;
|
||||
const events::event_context context;
|
||||
|
||||
//clear the screen
|
||||
gui::draw_solid_tinted_rectangle(0,0,screen.x()-1,screen.y()-1,0,0,0,1.0,
|
||||
|
@ -251,6 +253,7 @@ void show_map_scene(display& screen, config& data)
|
|||
|
||||
const config* const cfg_item = data.child("bigmap");
|
||||
if(cfg_item == NULL) {
|
||||
std::cerr << "no map scene...\n";
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -326,6 +329,7 @@ void show_map_scene(display& screen, config& data)
|
|||
|
||||
for(int i = 0; i != 50; ++i) {
|
||||
if(key[SDLK_ESCAPE]) {
|
||||
std::cerr << "escape pressed..\n";
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -336,6 +340,7 @@ void show_map_scene(display& screen, config& data)
|
|||
int a, b;
|
||||
const int mouse_flags = SDL_GetMouseState(&a,&b);
|
||||
if(key[SDLK_RETURN] || key[SDLK_SPACE] || mouse_flags) {
|
||||
std::cerr << "key pressed..\n";
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -343,6 +348,7 @@ void show_map_scene(display& screen, config& data)
|
|||
}
|
||||
|
||||
if(key[SDLK_ESCAPE]) {
|
||||
std::cerr << "escape pressed..\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -370,8 +376,10 @@ void show_map_scene(display& screen, config& data)
|
|||
const bool new_state = mouse_flags || key[SDLK_ESCAPE] ||
|
||||
key[SDLK_RETURN] || key[SDLK_SPACE];
|
||||
|
||||
if(new_state && !last_state)
|
||||
if(new_state && !last_state) {
|
||||
std::cerr << "key pressed..\n";
|
||||
break;
|
||||
}
|
||||
|
||||
last_state = new_state;
|
||||
|
||||
|
|
|
@ -398,15 +398,43 @@ void turn_info::mouse_motion(const SDL_MouseMotionEvent& event)
|
|||
last_hex_ = new_hex;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
bool command_active()
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
return (SDL_GetModState()&KMOD_LMETA) != 0;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool is_left_click(const SDL_MouseButtonEvent& event)
|
||||
{
|
||||
return event.button == SDL_BUTTON_LEFT && !command_active();
|
||||
}
|
||||
|
||||
bool is_middle_click(const SDL_MouseButtonEvent& event)
|
||||
{
|
||||
return event.button == SDL_BUTTON_MIDDLE;
|
||||
}
|
||||
|
||||
bool is_right_click(const SDL_MouseButtonEvent& event)
|
||||
{
|
||||
return event.button == SDL_BUTTON_RIGHT || event.button == SDL_BUTTON_LEFT && command_active();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void turn_info::mouse_press(const SDL_MouseButtonEvent& event)
|
||||
{
|
||||
if(event.button == SDL_BUTTON_LEFT && event.state == SDL_RELEASED) {
|
||||
if(is_left_click(event) && event.state == SDL_RELEASED) {
|
||||
minimap_scrolling_ = false;
|
||||
} else if(event.button == SDL_BUTTON_MIDDLE && event.state == SDL_RELEASED) {
|
||||
} else if(is_middle_click(event) && event.state == SDL_RELEASED) {
|
||||
minimap_scrolling_ = false;
|
||||
} else if(event.button == SDL_BUTTON_LEFT && event.state == SDL_PRESSED) {
|
||||
} else if(is_left_click(event) && event.state == SDL_PRESSED) {
|
||||
left_click(event);
|
||||
} else if(event.button == SDL_BUTTON_RIGHT && event.state == SDL_PRESSED) {
|
||||
} else if(is_right_click(event) && event.state == SDL_PRESSED) {
|
||||
if(!current_paths_.routes.empty()) {
|
||||
selected_hex_ = gamemap::location();
|
||||
gui_.select_hex(gamemap::location());
|
||||
|
@ -425,7 +453,7 @@ void turn_info::mouse_press(const SDL_MouseButtonEvent& event)
|
|||
std::cerr << "no context menu found...\n";
|
||||
}
|
||||
}
|
||||
} else if(event.button == SDL_BUTTON_MIDDLE && event.state == SDL_PRESSED) {
|
||||
} else if(is_middle_click(event) && event.state == SDL_PRESSED) {
|
||||
// clicked on a hex on the minimap? then initiate minimap scrolling
|
||||
const gamemap::location& loc = gui_.minimap_location_on(event.x,event.y);
|
||||
minimap_scrolling_ = false;
|
||||
|
|
|
@ -842,20 +842,21 @@ void show_hotkeys_dialog (display & disp)
|
|||
for (std::vector < hotkey::hotkey_item >::iterator i =
|
||||
hotkeys.begin (); i != hotkeys.end (); i++)
|
||||
{
|
||||
if ((i->keycode==key)
|
||||
&& (i->alt==((mod&KMOD_ALT)!=0))
|
||||
&& (i->ctrl==((mod&KMOD_CTRL)!=0))
|
||||
&& (i->shift==((mod&KMOD_SHIFT)!=0)))
|
||||
used = true;
|
||||
if((i->keycode == key)
|
||||
&& (i->alt == ((mod&KMOD_ALT) != 0))
|
||||
&& (i->ctrl == ((mod&KMOD_CTRL) != 0))
|
||||
&& (i->shift == ((mod&KMOD_SHIFT) != 0))
|
||||
&& (i->command == ((mod&KMOD_LMETA) != 0))) {
|
||||
used = true;
|
||||
}
|
||||
}
|
||||
if (used)
|
||||
if(used) {
|
||||
gui::show_dialog(disp,NULL,"",string_table["hotkey_already_used"],gui::MESSAGE);
|
||||
else {
|
||||
hotkeys[menu_.selection()].alt =
|
||||
((mod&KMOD_ALT)!=0);
|
||||
hotkeys[menu_.selection()].ctrl =
|
||||
((mod&KMOD_CTRL)!=0);
|
||||
hotkeys[menu_.selection()].shift = ((mod&KMOD_SHIFT)!=0);
|
||||
} else {
|
||||
hotkeys[menu_.selection()].alt = ((mod&KMOD_ALT) != 0);
|
||||
hotkeys[menu_.selection()].ctrl = ((mod&KMOD_CTRL) != 0);
|
||||
hotkeys[menu_.selection()].shift = ((mod&KMOD_SHIFT) != 0);
|
||||
hotkeys[menu_.selection()].command = ((mod&KMOD_LMETA) != 0);
|
||||
hotkeys[menu_.selection()].keycode = key;
|
||||
hotkey::change_hotkey(hotkeys[menu_.selection()]);
|
||||
menu_.change_item(menu_.selection(),2,
|
||||
|
|
Loading…
Add table
Reference in a new issue