Skip to content

Commit

Permalink
Don't create replays without commands in case of running non-visual r…
Browse files Browse the repository at this point in the history
…eplay or an atlas simulation.

Remove trailing whitespace.


git-svn-id: http://svn.wildfiregames.com/public/ps/trunk@17689 3db68df2-c116-0410-a063-a993310a9797
  • Loading branch information
elexis committed Jan 23, 2016
1 parent a3e1211 commit 6799c39
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
10 changes: 5 additions & 5 deletions source/ps/Replay.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down
14 changes: 7 additions & 7 deletions source/simulation2/Simulation2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class CSimulation2Impl
{
JSContext* cxOld = oldScript.GetContext();
JSAutoRequest rqOld(cxOld);

std::vector<SimulationCommand> newCommands;
newCommands.reserve(commands.size());
for (const SimulationCommand& command : commands)
Expand Down Expand Up @@ -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));
Expand All @@ -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")
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions source/simulation2/Simulation2.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -82,7 +82,7 @@ class CSimulation2
* Loads the map settings script (called after map is loaded)
*/
void LoadMapSettings();

/**
* Set a startup script, which will get executed before the first turn.
*/
Expand Down
42 changes: 21 additions & 21 deletions source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -148,15 +148,15 @@ QUERYHANDLER(GenerateMap)
MESSAGEHANDLER(LoadMap)
{
InitGame();

ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);

// 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"));
Expand All @@ -168,30 +168,30 @@ 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)
{
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
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -274,7 +274,7 @@ BEGIN_COMMAND(SetMapSettings)
{
m_OldSettings = g_Game->GetSimulation2()->GetMapSettingsString();
m_NewSettings = *msg->settings;

SetSettings(m_NewSettings);
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6799c39

Please sign in to comment.