Put the CMapGeneratorWorker completely inside the task

The return-slot provided by the `Future` is used for synchronisation.

Refs: #5874

Comments By: @Stan, @vladislavbelov, @wraitii
Differential Revision: https://code.wildfiregames.com/D5001
This was SVN commit r27944.
This commit is contained in:
phosit
2023-11-19 19:19:32 +00:00
parent 56f15f0869
commit e33aafc4e2
8 changed files with 480 additions and 627 deletions
+13 -4
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games.
/* Copyright (C) 2023 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -19,6 +19,8 @@
#include "ps/Filesystem.h"
#include "simulation2/system/ComponentTest.h"
#include <atomic>
class TestMapGenerator : public CxxTest::TestSuite
{
public:
@@ -52,9 +54,16 @@ public:
ScriptInterface scriptInterface("Engine", "MapGenerator", g_ScriptContext);
ScriptTestSetup(scriptInterface);
CMapGeneratorWorker worker(&scriptInterface);
worker.InitScriptInterface(0);
scriptInterface.LoadGlobalScriptFile(path);
// It's never read in the test so it doesn't matter to what value it's initialized. For
// good practice it's initialized to 1.
std::atomic<int> progress{1};
const Script::StructuredClone result{RunMapGenerationScript(progress, scriptInterface,
path, "{\"Seed\": 0}", JSPROP_ENUMERATE | JSPROP_PERMANENT)};
// The test scripts don't call `ExportMap` so `RunMapGenerationScript` allways returns
// `nullptr`.
TS_ASSERT_EQUALS(result, nullptr);
}
}
};