[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src game.cpp network.cpp campaign_serve...
From: |
Guillaume Melquiond |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src game.cpp network.cpp campaign_serve... |
Date: |
Fri, 25 Mar 2005 11:43:54 -0500 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Guillaume Melquiond <address@hidden> 05/03/25 16:43:54
Modified files:
src : game.cpp network.cpp
src/campaign_server: campaign_server.cpp
src/serialization: binary_or_text.cpp binary_wml.cpp
binary_wml.hpp
Log message:
Stream-based binary WML. No need anymore to load the whole cache into
memory before processing it.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.214&tr2=1.215&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/network.cpp.diff?tr1=1.57&tr2=1.58&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/campaign_server/campaign_server.cpp.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/binary_or_text.cpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/binary_wml.cpp.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/binary_wml.hpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
Patches:
Index: wesnoth/src/campaign_server/campaign_server.cpp
diff -u wesnoth/src/campaign_server/campaign_server.cpp:1.10
wesnoth/src/campaign_server/campaign_server.cpp:1.11
--- wesnoth/src/campaign_server/campaign_server.cpp:1.10 Sat Mar 5
10:54:25 2005
+++ wesnoth/src/campaign_server/campaign_server.cpp Fri Mar 25 16:43:54 2005
@@ -90,8 +90,9 @@
network::send_data(construct_error("Campaign not found."),sock);
} else {
config cfg;
- compression_schema schema;
- read_compressed(cfg,
read_file((*campaign)["filename"]),schema);
+ std::istream *stream =
stream_file((*campaign)["filename"]);
+ read_compressed(cfg, *stream);
+ delete stream;
network::queue_data(cfg,sock);
const int downloads =
lexical_cast_default<int>((*campaign)["downloads"],0)+1;
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.214 wesnoth/src/game.cpp:1.215
--- wesnoth/src/game.cpp:1.214 Thu Mar 24 21:56:44 2005
+++ wesnoth/src/game.cpp Fri Mar 25 16:43:54 2005
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.214 2005/03/24 21:56:44 j_daniel Exp $ */
+/* $Id: game.cpp,v 1.215 2005/03/25 16:43:54 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -272,7 +272,9 @@
compression_schema schema;
try {
- read_compressed(cfg,
read_file(fname), schema);
+ std::istream *stream =
stream_file(fname);
+ read_compressed(cfg, *stream,
schema);
+ delete stream;
return;
} catch(config::error&) {
std::cerr << "cache is corrupt.
Loading from files\n";
Index: wesnoth/src/network.cpp
diff -u wesnoth/src/network.cpp:1.57 wesnoth/src/network.cpp:1.58
--- wesnoth/src/network.cpp:1.57 Wed Mar 23 22:10:50 2005
+++ wesnoth/src/network.cpp Fri Mar 25 16:43:54 2005
@@ -520,7 +520,9 @@
const schema_map::iterator schema = schemas.find(result);
wassert(schema != schemas.end());
-
read_compressed(cfg,std::string(buf.begin(),buf.end()),schema->second.incoming);
+ std::string buffer(buf.begin(), buf.end());
+ std::istringstream stream(buffer);
+ read_compressed(cfg, stream, schema->second.incoming);
return result;
}
Index: wesnoth/src/serialization/binary_or_text.cpp
diff -u wesnoth/src/serialization/binary_or_text.cpp:1.1
wesnoth/src/serialization/binary_or_text.cpp:1.2
--- wesnoth/src/serialization/binary_or_text.cpp:1.1 Sat Mar 5 10:54:25 2005
+++ wesnoth/src/serialization/binary_or_text.cpp Fri Mar 25 16:43:54 2005
@@ -1,4 +1,4 @@
-/* $Id: binary_or_text.cpp,v 1.1 2005/03/05 10:54:25 silene Exp $ */
+/* $Id: binary_or_text.cpp,v 1.2 2005/03/25 16:43:54 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -16,11 +16,13 @@
#include "serialization/binary_wml.hpp"
#include "serialization/parser.hpp"
+#include <sstream>
+
bool detect_format_and_read(config &cfg, std::string const &data)
{
try {
- compression_schema schema;
- read_compressed(cfg, data, schema);
+ std::istringstream stream(data);
+ read_compressed(cfg, stream);
return true;
} catch (config::error &) {
}
Index: wesnoth/src/serialization/binary_wml.cpp
diff -u wesnoth/src/serialization/binary_wml.cpp:1.3
wesnoth/src/serialization/binary_wml.cpp:1.4
--- wesnoth/src/serialization/binary_wml.cpp:1.3 Thu Mar 10 20:59:20 2005
+++ wesnoth/src/serialization/binary_wml.cpp Fri Mar 25 16:43:54 2005
@@ -1,4 +1,4 @@
-/* $Id: binary_wml.cpp,v 1.3 2005/03/10 20:59:20 ydirson Exp $ */
+/* $Id: binary_wml.cpp,v 1.4 2005/03/25 16:43:54 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -19,7 +19,8 @@
#include "serialization/binary_wml.hpp"
#include <algorithm>
-#include <ostream>
+#include <iostream>
+#include <sstream>
#define ERR_CF lg::err(lg::config)
@@ -28,9 +29,9 @@
return write_compressed(cfg, schema);
}
-void read_compressed(config &cfg, std::string const &data) {
+void read_compressed(config &cfg, std::istream &in) {
compression_schema schema;
- read_compressed(cfg, data, schema);
+ read_compressed(cfg, in, schema);
}
//data compression. Compression is designed for network traffic.
@@ -122,15 +123,19 @@
}
}
-typedef std::string::const_iterator scit;
-static scit compress_read_literal_word(scit i1, scit i2, std::string &res)
+static std::string compress_read_literal_word(std::istream &in)
{
- scit const end_word = std::find(i1, i2, 0);
- if (end_word == i2)
- throw config::error("Unexpected end of data in compressed
config read\n");
-
- res = std::string(i1, end_word);
- return end_word;
+ std::stringstream stream;
+ for(;;) {
+ unsigned char c;
+ c = in.get();
+ if (in.fail())
+ throw config::error("Unexpected end of data in
compressed config read\n");
+ if (c == 0)
+ break;
+ stream << c;
+ }
+ return stream.str();
}
static void write_compressed_internal(config const &cfg, compression_schema
&schema, std::vector< char > &res, int level)
@@ -170,32 +175,31 @@
return s;
}
-static scit read_compressed_internal(config &cfg, scit i1, scit i2,
compression_schema &schema, int level)
+static void read_compressed_internal(config &cfg, std::istream &in,
compression_schema &schema, int level)
{
if (level >= max_recursion_levels)
throw config::error("Too many recursion levels in compressed
config read\n");
bool in_open_element = false;
- while (i1 != i2) {
- switch (*i1) {
+ for(;;) {
+ unsigned char const c = in.get();
+ if (in.fail())
+ return;
+ switch (c) {
case compress_open_element:
in_open_element = true;
break;
case compress_close_element:
- return i1;
- case compress_schema_item: {
- std::string word;
- i1 = compress_read_literal_word(i1 + 1, i2, word);
- add_word_to_schema(word,schema);
+ return;
+ case compress_schema_item:
+ add_word_to_schema(compress_read_literal_word(in),
schema);
break;
- }
default: {
std::string word;
- if (*i1 == compress_literal_word) {
- i1 = compress_read_literal_word(i1 + 1, i2,
word);
+ if (c == compress_literal_word) {
+ word = compress_read_literal_word(in);
} else {
- const unsigned char c = *i1;
unsigned int code = c;
const
compression_schema::char_word_map::const_iterator itor
@@ -211,27 +215,20 @@
if (in_open_element) {
in_open_element = false;
config &cfg2 = cfg.add_child(word);
- i1 = read_compressed_internal(cfg2, i1 + 1, i2,
schema, level + 1);
+ read_compressed_internal(cfg2, in, schema,
level + 1);
} else {
//we have a name/value pair, the value is
always a literal string
- std::string value;
- i1 = compress_read_literal_word(i1 + 1, i2,
value);
+ std::string value =
compress_read_literal_word(in);
cfg.values.insert(std::make_pair(word, value));
}
}
} //end switch
-
- if(i1 == i2)
- return i2;
- ++i1;
}
-
- return i1;
}
-void read_compressed(config &cfg, std::string const &data, compression_schema
&schema)
+void read_compressed(config &cfg, std::istream &in, compression_schema &schema)
{
cfg.clear();
- read_compressed_internal(cfg, data.begin(), data.end(), schema, 0);
+ read_compressed_internal(cfg, in, schema, 0);
}
Index: wesnoth/src/serialization/binary_wml.hpp
diff -u wesnoth/src/serialization/binary_wml.hpp:1.2
wesnoth/src/serialization/binary_wml.hpp:1.3
--- wesnoth/src/serialization/binary_wml.hpp:1.2 Tue Mar 8 02:25:09 2005
+++ wesnoth/src/serialization/binary_wml.hpp Fri Mar 25 16:43:54 2005
@@ -1,4 +1,4 @@
-/* $Id: binary_wml.hpp,v 1.2 2005/03/08 02:25:09 Sirp Exp $ */
+/* $Id: binary_wml.hpp,v 1.3 2005/03/25 16:43:54 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -14,6 +14,7 @@
#ifndef SERIALIZATION_BINARY_WML_HPP_INCLUDED
#define SERIALIZATION_BINARY_WML_HPP_INCLUDED
+#include <iosfwd>
#include <map>
#include <string>
@@ -35,10 +36,10 @@
//meaning that the entire schema won't have to be transmitted each time.
std::string write_compressed(config const &cfg, compression_schema &schema);
-void read_compressed(config &cfg, std::string const &data, compression_schema
&schema); //throws config::error
+void read_compressed(config &cfg, std::istream &in, compression_schema
&schema); //throws config::error
std::string write_compressed(config const &cfg);
-void read_compressed(config &cfg, std::string const &data);
+void read_compressed(config &cfg, std::istream &in);
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Wesnoth-cvs-commits] wesnoth/src game.cpp network.cpp campaign_serve...,
Guillaume Melquiond <=