writing orders to the CR no longer copies them into a buffer when it can be avoided.

This commit is contained in:
Enno Rehling 2017-12-06 20:00:32 +01:00
parent 7867eb6962
commit 7b2531a8ae
4 changed files with 55 additions and 15 deletions

View File

@ -11,7 +11,7 @@ fi
cd "$ERESSEA/game-$GAME" || exit
echo "running turn $TURN, game $GAME"
"$ERESSEA/server/bin/eressea" -v3 -t "$TURN" run-turn.lua
"$ERESSEA/server/bin/eressea" -t "$TURN" run-turn.lua
mkdir -p log
ln -f eressea.log "log/eressea.log.$TURN"

View File

@ -723,18 +723,6 @@ static void cr_output_ship_compat(FILE *F, const ship *sh, const unit *u,
cr_output_ship(&strm, sh, u, fcaptain, f, r);
}
static int stream_order(stream *out, const struct order *ord, const struct locale *lang) {
const char *str;
char ebuf[1025];
char obuf[1024];
write_order(ord, lang, obuf, sizeof(obuf));
str = escape_string(obuf, ebuf, sizeof(ebuf));
if (str == ebuf) {
ebuf[1024] = 0;
}
return stream_printf(out, "\"%s\"\n", str);
}
static void cr_output_spells(stream *out, const unit * u, int maxlevel)
{
spellbook * book = unit_get_spellbook(u);
@ -925,7 +913,9 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
for (ord = u->old_orders; ord; ord = ord->next) {
/* this new order will replace the old defaults */
if (is_persistent(ord)) {
stream_order(out, ord, lang);
swrite("\"", 1, 1, out);
stream_order(out, ord, lang, true);
swrite("\"\n", 1, 2, out);
}
}
for (ord = u->orders; ord; ord = ord->next) {
@ -933,7 +923,9 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
if (u->old_orders && is_repeated(kwd))
continue; /* unit has defaults */
if (is_persistent(ord)) {
stream_order(out, ord, lang);
swrite("\"", 1, 1, out);
stream_order(out, ord, lang, true);
swrite("\"\n", 1, 2, out);
}
}

View File

@ -23,6 +23,9 @@
#include <util/language.h>
#include <util/log.h>
#include <util/parser.h>
#include <util/strings.h>
#include <stream.h>
/* libc includes */
#include <assert.h>
@ -135,6 +138,49 @@ char* get_command(const order *ord, const struct locale *lang, char *sbuffer, si
return sbuffer;
}
int stream_order(struct stream *out, const struct order *ord, const struct locale *lang, bool escape)
{
const char *str, *text;
order_data *od = NULL;
keyword_t kwd = ORD_KEYWORD(ord);
if (ord->command & CMD_QUIET) {
swrite("!", 1, 1, out);
}
if (ord->command & CMD_PERSIST) {
swrite("@", 1, 1, out);
}
if (ord->id < 0) {
skill_t sk = (skill_t)(100 + ord->id);
assert(kwd == K_STUDY && sk != SK_MAGIC && sk < MAXSKILLS);
text = skillname(sk, lang);
}
else {
od = odata_load(ord->id);
text = OD_STRING(od);
}
if (kwd != NOKEYWORD) {
str = (const char *)LOC(lang, keyword(kwd));
assert(str);
swrite(str, 1, strlen(str), out);
}
if (text) {
char obuf[1024];
swrite(" ", 1, 1, out);
if (escape) {
text = escape_string(text, obuf, sizeof(obuf));
}
swrite(text, 1, strlen(text), out);
}
if (od) {
odata_release(od);
}
return 0;
}
void free_order(order * ord)
{
if (ord != NULL) {

View File

@ -22,6 +22,7 @@ extern "C" {
#endif
struct locale;
struct stream;
/* Encapsulation of an order
*
@ -69,6 +70,7 @@ extern "C" {
char *write_order(const order * ord, const struct locale *lang,
char *buffer, size_t size);
int stream_order(struct stream *out, const struct order *ord, const struct locale *lang, bool escape);
keyword_t init_order_depr(const struct order *ord);
keyword_t init_order(const struct order *ord, const struct locale *lang);