Don't create replays without commands in case of running non-visual replay or an atlas simulation.

Remove trailing whitespace.

This was SVN commit r17689.
This commit is contained in:
elexis 2016-01-23 01:02:57 +00:00
parent dd7287c1c8
commit 5747619c39
4 changed files with 35 additions and 35 deletions

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2016 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -96,7 +96,7 @@ void CReplayLogger::Turn(u32 n, u32 turnLength, std::vector<SimulationCommand>&
{
JSContext* cx = m_ScriptInterface.GetContext();
JSAutoRequest rq(cx);
*m_Stream << "turn " << n << " " << turnLength << "\n";
for (size_t i = 0; i < commands.size(); ++i)
{
@ -147,12 +147,12 @@ void CReplayPlayer::Replay(bool serializationtest, bool ooslog)
new CProfileManager;
g_ScriptStatsTable = new CScriptStatsTable;
g_ProfileViewer.AddRootTable(g_ScriptStatsTable);
const int runtimeSize = 384 * 1024 * 1024;
const int heapGrowthBytesGCTrigger = 20 * 1024 * 1024;
g_ScriptRuntime = ScriptInterface::CreateRuntime(shared_ptr<ScriptRuntime>(), runtimeSize, heapGrowthBytesGCTrigger);
g_Game = new CGame(true);
g_Game = new CGame(true, false);
if (serializationtest)
g_Game->GetSimulation2()->EnableSerializationTest();
if (ooslog)
@ -266,7 +266,7 @@ void CReplayPlayer::Replay(bool serializationtest, bool ooslog)
// Must be explicitly destructed here to avoid callbacks from the JSAPI trying to use g_Profiler2 when
// it's already destructed.
g_ScriptRuntime.reset();
// Clean up
delete &g_TexMan;

View file

@ -156,7 +156,7 @@ public:
{
JSContext* cxOld = oldScript.GetContext();
JSAutoRequest rqOld(cxOld);
std::vector<SimulationCommand> newCommands;
newCommands.reserve(commands.size());
for (const SimulationCommand& command : commands)
@ -375,7 +375,7 @@ void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationComman
{
JSContext* cx2 = secondaryComponentManager.GetScriptInterface().GetContext();
JSAutoRequest rq2(cx2);
JS::RootedValue mapSettingsCloned(cx2,
JS::RootedValue mapSettingsCloned(cx2,
secondaryComponentManager.GetScriptInterface().CloneValueFromOtherContext(
scriptInterface, m_MapSettings));
ENSURE(LoadTriggerScripts(secondaryComponentManager, mapSettingsCloned, &secondaryLoadedScripts));
@ -385,7 +385,7 @@ void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationComman
LDR_BeginRegistering();
CMapReader* mapReader = new CMapReader; // automatically deletes itself
std::string mapType;
scriptInterface.GetProperty(m_InitAttributes, "mapType", mapType);
if (mapType == "random")
@ -763,9 +763,9 @@ void CSimulation2::LoadMapSettings()
{
JSContext* cx = GetScriptInterface().GetContext();
JSAutoRequest rq(cx);
JS::RootedValue global(cx, GetScriptInterface().GetGlobalObject());
// Initialize here instead of in Update()
GetScriptInterface().CallFunctionVoid(global, "LoadMapSettings", m->m_MapSettings);
@ -893,11 +893,11 @@ std::string CSimulation2::GetAIData()
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
JS::RootedValue aiData(cx, ICmpAIManager::GetAIs(scriptInterface));
// Build single JSON string with array of AI data
JS::RootedValue ais(cx);
if (!scriptInterface.Eval("({})", &ais) || !scriptInterface.SetProperty(ais, "AIData", aiData))
return std::string();
return scriptInterface.StringifyJSON(&ais);
}

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2014 Wildfire Games.
/* Copyright (C) 2016 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -82,7 +82,7 @@ public:
* Loads the map settings script (called after map is loaded)
*/
void LoadMapSettings();
/**
* Set a startup script, which will get executed before the first turn.
*/

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2013 Wildfire Games.
/* Copyright (C) 2016 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -56,7 +56,7 @@ namespace
g_Game = NULL;
}
g_Game = new CGame();
g_Game = new CGame(false, false);
// Default to player 1 for playtesting
g_Game->SetPlayerID(1);
@ -92,7 +92,7 @@ QUERYHANDLER(GenerateMap)
ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
JS::RootedValue settings(cx);
scriptInterface.ParseJSON(*msg->settings, &settings);
scriptInterface.SetProperty(settings, "mapType", std::string("random"));
@ -148,7 +148,7 @@ QUERYHANDLER(GenerateMap)
MESSAGEHANDLER(LoadMap)
{
InitGame();
ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
@ -156,7 +156,7 @@ MESSAGEHANDLER(LoadMap)
// Scenario
CStrW map = *msg->filename;
CStrW mapBase = map.BeforeLast(L".pmp"); // strip the file extension, if any
JS::RootedValue attrs(cx);
scriptInterface.Eval("({})", &attrs);
scriptInterface.SetProperty(attrs, "mapType", std::string("scenario"));
@ -168,10 +168,10 @@ MESSAGEHANDLER(LoadMap)
MESSAGEHANDLER(ImportHeightmap)
{
CStrW src = *msg->filename;
size_t fileSize;
shared_ptr<u8> fileData;
// read in image file
File file;
if (file.Open(src, O_RDONLY) < 0)
@ -179,19 +179,19 @@ MESSAGEHANDLER(ImportHeightmap)
LOGERROR("Failed to load heightmap.");
return;
}
fileSize = lseek(file.Descriptor(), 0, SEEK_END);
lseek(file.Descriptor(), 0, SEEK_SET);
fileData = shared_ptr<u8>(new u8[fileSize]);
if (read(file.Descriptor(), fileData.get(), fileSize) < 0)
{
LOGERROR("Failed to read heightmap image.");
file.Close();
return;
}
file.Close();
// decode to a raw pixel format
@ -212,32 +212,32 @@ MESSAGEHANDLER(ImportHeightmap)
// pick smallest side of texture; truncate if not divisible by PATCH_SIZE
ssize_t terrainSize = std::min(tex.m_Width, tex.m_Height);
terrainSize -= terrainSize % PATCH_SIZE;
// resize terrain to heightmap size
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
terrain->Resize(terrainSize / PATCH_SIZE);
// copy heightmap data into map
u16* heightmap = g_Game->GetWorld()->GetTerrain()->GetHeightMap();
ssize_t hmSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide();
u8* mapdata = tex.get_data();
ssize_t bytesPP = tex.m_Bpp / 8;
ssize_t mapLineSkip = tex.m_Width * bytesPP;
for (ssize_t y = 0; y < terrainSize; ++y)
{
for (ssize_t x = 0; x < terrainSize; ++x)
{
int offset = y * mapLineSkip + x * bytesPP;
// pick color channel with highest value
u16 value = std::max(mapdata[offset+bytesPP*2], std::max(mapdata[offset], mapdata[offset+bytesPP]));
heightmap[(terrainSize-y-1) * hmSize + x] = clamp(value * 256, 0, 65535);
}
}
// update simulation
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
if (cmpTerrain) cmpTerrain->ReloadTerrain();
@ -264,7 +264,7 @@ QUERYHANDLER(GetMapSettings)
BEGIN_COMMAND(SetMapSettings)
{
std::string m_OldSettings, m_NewSettings;
void SetSettings(const std::string& settings)
{
g_Game->GetSimulation2()->SetMapSettings(settings);
@ -274,7 +274,7 @@ BEGIN_COMMAND(SetMapSettings)
{
m_OldSettings = g_Game->GetSimulation2()->GetMapSettingsString();
m_NewSettings = *msg->settings;
SetSettings(m_NewSettings);
}
@ -385,7 +385,7 @@ QUERYHANDLER(GetMapList)
std::vector<std::wstring> scenarioFilenames;
vfs::ForEachFile(g_VFS, L"maps/scenarios/", AddToFilenames, (uintptr_t)&scenarioFilenames, L"*.xml", vfs::DIR_RECURSIVE);
msg->scenarioFilenames = scenarioFilenames;
std::vector<std::wstring> skirmishFilenames;
vfs::ForEachFile(g_VFS, L"maps/skirmishes/", AddToFilenames, (uintptr_t)&skirmishFilenames, L"*.xml", vfs::DIR_RECURSIVE);
msg->skirmishFilenames = skirmishFilenames;