Ticket #3359: t3359_move_engine_version_v1.patch

File t3359_move_engine_version_v1.patch, 9.3 KB (added by elexis, 9 years ago)

Moves the version and uses it for testing the savegame.

  • binaries/data/mods/public/gui/common/functions_utility_loadsave.js

     
    77{
    88    var dateTimeString = Engine.FormatMillisecondsIntoDateString(metadata.time*1000, translate("yyyy-MM-dd HH:mm:ss"));
    99    var dateString = sprintf(translate("\\[%(date)s]"), { date: dateTimeString });
    1010    if (engineInfo)
    1111    {
    12         if (!hasSameVersion(metadata, engineInfo))
     12        if (!hasSameSavegameVersion(metadata, engineInfo) || !hasSameEngineVersion(metadata, engineInfo))
    1313            dateString = "[color=\"red\"]" + dateString + "[/color]";
    1414        else if (!hasSameMods(metadata, engineInfo))
    1515            dateString = "[color=\"orange\"]" + dateString + "[/color]";
    1616    }
    1717    if (metadata.description)
     
    2121}
    2222
    2323/**
    2424 * Check the version compatibility between the saved game to be loaded and the engine
    2525 */
    26 function hasSameVersion(metadata, engineInfo)
     26function hasSameSavegameVersion(metadata, engineInfo)
    2727{
    28     return (metadata.version_major == engineInfo.version_major);
     28    return metadata.version_major == engineInfo.version_major;
     29}
     30
     31/**
     32 * Check the version compatibility between the saved game to be loaded and the engine
     33 */
     34function hasSameEngineVersion(metadata, engineInfo)
     35{
     36    return metadata.engine_version && metadata.engine_version == engineInfo.engine_version;
    2937}
    3038
    3139/**
    3240 * Check the mod compatibility between the saved game to be loaded and the engine
    3341 */
    3442function hasSameMods(metadata, engineInfo)
    3543{
    36     if (!metadata.mods)         // only here for backwards compatibility with previous saved games
    37         var gameMods = [];
    38     else
    39         var gameMods = metadata.mods;
    40 
    41     if (gameMods.length != engineInfo.mods.length)
     44    if (!metadata.mods || metadata.mods.length != engineInfo.mods.length)
    4245        return false;
    43     for (var i = 0; i < gameMods.length; ++i)
    44         if (gameMods[i] != engineInfo.mods[i])
    45             return false;
    46     return true;
     46   
     47    return metadata.mods.every((mod, index) => mod == engineInfo.mods[index]);
    4748}
  • binaries/data/mods/public/gui/savedgames/load.js

     
    3838    var gameLabel = gameSelection.list[gameSelection.selected];
    3939    var metadata = gameMetadatas[gameSelection.selected];
    4040
    4141    // check game compatibility before really loading it
    4242    var engineInfo = Engine.GetEngineInfo();
    43     if (!hasSameVersion(metadata, engineInfo) || !hasSameMods(metadata, engineInfo))
     43    var sameMods = hasSameMods(metadata, engineInfo);
     44    var sameEngineVersion = hasSameEngineVersion(metadata, engineInfo);
     45    var sameSavegameVersion = hasSameSavegameVersion(metadata, engineInfo);
     46    if (!sameEngineVersion || !sameSavegameVersion || !sameMods)
    4447    {
    4548        // version not compatible ... ask for confirmation
    4649        var btCaptions = [translate("Yes"), translate("No")];
    4750        var btCode = [function(){ reallyLoadGame(gameId); }, init];
    4851        var message = translate("This saved game may not be compatible:");
    49         if (!hasSameVersion(metadata, engineInfo))
    50             message += "\n" + sprintf(translate("It needs 0 A.D. version %(requiredVersion)s, while you are running version %(currentVersion)s."), {
     52
     53        if (!sameEngineVersion)
     54        {
     55            if (metadata.engine_version)
     56                message += "\n" + sprintf(translate("It needs 0 A.D. version %(requiredVersion)s, while you are running version %(currentVersion)s."), {
     57                    requiredVersion: metadata.engine_version,
     58                    currentVersion: engineInfo.engine_version
     59                });
     60            else
     61                message += "\n" + translate("It needs an older version of 0 A.D.");
     62        }
     63       
     64        if (!sameSavegameVersion)
     65            message += "\n" + sprintf(translate("It needs 0 A.D. savegame version %(requiredVersion)s, while you are running version %(currentVersion)s."), {
    5166                requiredVersion: metadata.version_major,
    5267                currentVersion: engineInfo.version_major
    5368            });
    5469
    55         if (!hasSameMods(metadata, engineInfo))
     70        if (!sameMods)
    5671        {
    5772            if (!metadata.mods)         // only for backwards compatibility with previous saved games
    5873                metadata.mods = [];
    5974            if (metadata.mods.length == 0)
    6075                message += "\n" + sprintf(translate("It does not need any mod while you are running with \"%(currentMod)s\"."), {
  • source/lobby/XmppClient.cpp

     
    2222#include "glooxwrapper/glooxwrapper.h"
    2323#include "i18n/L10n.h"
    2424#include "lib/utf8.h"
    2525#include "ps/CLogger.h"
    2626#include "ps/ConfigDB.h"
     27#include "ps/Pyrogenesis.h"
    2728#include "scriptinterface/ScriptInterface.h"
    2829
    2930//debug
    3031#if 1
    3132#define DbgXMPP(x)
     
    9596    const int mechs = gloox::SaslMechAll ^ gloox::SaslMechPlain;
    9697    m_client->setSASLMechanisms(mechs);
    9798
    9899    m_client->registerConnectionListener(this);
    99100    m_client->setPresence(gloox::Presence::Available, -1);
    100     m_client->disco()->setVersion("Pyrogenesis", "0.0.19");
     101    m_client->disco()->setVersion("Pyrogenesis", engine_version);
    101102    m_client->disco()->setIdentity("client", "bot");
    102103    m_client->setCompression(false);
    103104
    104105    m_client->registerStanzaExtension(new GameListQuery());
    105106    m_client->registerIqHandler(this, EXTGAMELISTQUERY);
  • source/ps/Pyrogenesis.cpp

     
    2222#include "Pyrogenesis.h"
    2323
    2424#include "lib/sysdep/sysdep.h"
    2525#include "lib/svn_revision.h"
    2626
     27const char engine_version[] = "0.0.19";
     28
    2729// convert contents of file <in_filename> from char to wchar_t and
    2830// append to <out> file.
    2931static void AppendAsciiFile(FILE* out, const OsPath& pathname)
    3032{
    3133    FILE* in = sys_OpenFile(pathname, "rb");
     
    5254
    5355// for user convenience, bundle all logs into this file:
    5456void psBundleLogs(FILE* f)
    5557{
    5658    fwprintf(f, L"SVN Revision: %ls\n\n", svn_revision);
     59    fwprintf(f, L"Engine Version: %hs\n\n", engine_version);
    5760
    5861    fwprintf(f, L"System info:\n\n");
    5962    OsPath path1 = psLogDir()/"system_info.txt";
    6063    AppendAsciiFile(f, path1);
    6164    fwprintf(f, L"\n\n====================================\n\n");
  • source/ps/Pyrogenesis.h

     
    2424#ifndef INCLUDED_PYROGENESIS
    2525#define INCLUDED_PYROGENESIS
    2626
    2727#include "lib/os_path.h"
    2828
     29extern const char engine_version[];
     30
    2931extern void psBundleLogs(FILE* f); // set during InitVfs
    3032extern void psSetLogDir(const OsPath& logDir);  // set during InitVfs
    3133extern const OsPath& psLogDir();    // used by AppHooks and engine code when reporting errors
    3234
    3335#endif
  • source/ps/SavedGame.cpp

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
    55 * it under the terms of the GNU General Public License as published by
    66 * the Free Software Foundation, either version 2 of the License, or
     
    2727#include "lib/utf8.h"
    2828#include "ps/CLogger.h"
    2929#include "ps/Filesystem.h"
    3030#include "ps/Game.h"
    3131#include "ps/Mod.h"
     32#include "ps/Pyrogenesis.h"
    3233#include "scriptinterface/ScriptInterface.h"
    3334#include "simulation2/Simulation2.h"
    3435
    3536static const int SAVED_GAME_VERSION_MAJOR = 1; // increment on incompatible changes to the format
    3637static const int SAVED_GAME_VERSION_MINOR = 0; // increment on compatible changes to the format
     
    8485    JS::RootedValue metadata(cx);
    8586    JS::RootedValue initAttributes(cx, simulation.GetInitAttributes());
    8687    simulation.GetScriptInterface().Eval("({})", &metadata);
    8788    simulation.GetScriptInterface().SetProperty(metadata, "version_major", SAVED_GAME_VERSION_MAJOR);
    8889    simulation.GetScriptInterface().SetProperty(metadata, "version_minor", SAVED_GAME_VERSION_MINOR);
     90    simulation.GetScriptInterface().SetProperty(metadata, "engine_version", CStr(engine_version));
    8991    simulation.GetScriptInterface().SetProperty(metadata, "mods", g_modsLoaded);
    9092    simulation.GetScriptInterface().SetProperty(metadata, "time", (double)now);
    9193    simulation.GetScriptInterface().SetProperty(metadata, "player", playerID);
    9294    simulation.GetScriptInterface().SetProperty(metadata, "initAttributes", initAttributes);
    9395
     
    298300   
    299301    JS::RootedValue metainfo(cx);
    300302    scriptInterface.Eval("({})", &metainfo);
    301303    scriptInterface.SetProperty(metainfo, "version_major", SAVED_GAME_VERSION_MAJOR);
    302304    scriptInterface.SetProperty(metainfo, "version_minor", SAVED_GAME_VERSION_MINOR);
    303     scriptInterface.SetProperty(metainfo, "mods"         , g_modsLoaded);
     305    scriptInterface.SetProperty(metainfo, "engine_version", CStr(engine_version));
     306    scriptInterface.SetProperty(metainfo, "mods", g_modsLoaded);
    304307    return metainfo;
    305308}