Changeset 28093
- Timestamp:
- May 22, 2024, 5:52:12 PM (2 months ago)
- Location:
- ps/trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/binaries/data/mods/public/maps/random/rmgen/RandomMap.js
r28036 r28093 480 480 }; 481 481 482 RandomMap.prototype. ExportMap= function()482 RandomMap.prototype. = function() 483 483 { 484 484 if (g_Environment.Water.WaterBody.Height === undefined) … … 487 487 this.logger.close(); 488 488 489 Engine.ExportMap({489 { 490 490 "entities": this.exportEntityList(), 491 491 "height": this.exportHeightData(), … … 496 496 "Camera": g_Camera, 497 497 "Environment": g_Environment 498 }); 499 }; 498 }; 499 }; 500 501 RandomMap.prototype.ExportMap = function() 502 { 503 Engine.ExportMap(this.MakeExportable()); 504 }; -
ps/trunk/binaries/data/tests/test_setup.js
r23460 r28093 31 31 if (x !== y) 32 32 fail("Expected equal, got " + uneval(x) + " !== " + uneval(y)); 33 34 35 36 37 38 33 39 }; 34 40 -
ps/trunk/source/graphics/MapGenerator.cpp
r27973 r28093 1 /* Copyright (C) 202 3Wildfire Games.1 /* Copyright (C) 202 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 48 48 namespace 49 49 { 50 51 50 52 bool MapGenerationInterruptCallback(JSContext* UNUSED(cx)) 51 53 { … … 424 426 } 425 427 426 return mapData; 428 LOGMESSAGE("Run RMS generator"); 429 bool hasGenerator; 430 JS::RootedObject globalAsObject{rq.cx, &JS::HandleValue{global}.toObject()}; 431 if (!JS_HasProperty(rq.cx, globalAsObject, GENERATOR_NAME, &hasGenerator)) 432 { 433 LOGERROR("RunMapGenerationScript: failed to search `%s`.", GENERATOR_NAME); 434 return nullptr; 435 } 436 437 if (mapData != nullptr) 438 { 439 LOGWARNING("The map generation script called `Engine.ExportMap` that's deprecated. The " 440 "generator based interface should be used."); 441 if (hasGenerator) 442 LOGWARNING("The map generation script contains a `%s` but `Engine.ExportMap` was already " 443 "called. `%s` isn't called, preserving the old behavior.", GENERATOR_NAME, 444 GENERATOR_NAME); 445 return mapData; 446 } 447 448 try 449 { 450 JS::RootedValue map{rq.cx, ScriptFunction::RunGenerator(rq, global, GENERATOR_NAME, settingsVal, 451 [&](const JS::HandleValue value) 452 { 453 int tempProgress; 454 if (!Script::FromJSVal(rq, value, tempProgress)) 455 throw std::runtime_error{"Failed to convert the yielded value to an " 456 "integer."}; 457 progress.store(tempProgress); 458 })}; 459 460 JS::RootedValue exportedMap{rq.cx}; 461 const bool exportSuccess{ScriptFunction::Call(rq, map, "MakeExportable", &exportedMap)}; 462 return Script::WriteStructuredClone(rq, exportSuccess ? exportedMap : map); 463 } 464 catch(const std::exception& e) 465 { 466 LOGERROR("%s", e.what()); 467 return nullptr; 468 } 469 catch(...) 470 { 471 return nullptr; 472 } 427 473 } -
ps/trunk/source/graphics/tests/test_MapGenerator.h
r27965 r28093 1 /* Copyright (C) 202 3Wildfire Games.1 /* Copyright (C) 202 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 52 52 for (const VfsPath& path : paths) 53 53 { 54 54 55 ScriptInterface scriptInterface("Engine", "MapGenerator", g_ScriptContext); 55 56 ScriptTestSetup(scriptInterface); 56 57 57 // It's never read in the test so it doesn't matter to what value it's initialized. For58 // good practice it's initialized to 1.59 58 std::atomic<int> progress{1}; 60 59 … … 62 61 path, "{\"Seed\": 0}", JSPROP_ENUMERATE | JSPROP_PERMANENT)}; 63 62 64 // The test scripts don't call `ExportMap` so `RunMapGenerationScript` allways returns 65 // `nullptr`. 66 TS_ASSERT_EQUALS(result, nullptr); 63 if (path == "maps/random/tests/test_Generator.js" || 64 path == "maps/random/tests/test_RecoverableError.js") 65 { 66 TS_ASSERT_EQUALS(progress.load(), 50); 67 TS_ASSERT_DIFFERS(result, nullptr); 68 } 69 else 70 { 71 // The test scripts don't call `ExportMap` so `RunMapGenerationScript` allways 72 // returns `nullptr`. 73 TS_ASSERT_EQUALS(result, nullptr); 74 // Because the test scripts don't call `ExportMap`, `GenerateMap` is searched, which 75 // doesn't exist. 76 TS_ASSERT_STR_CONTAINS(logger.GetOutput(), 77 "Failed to call the generator `GenerateMap`."); 78 } 67 79 } 68 80 } -
ps/trunk/source/scriptinterface/FunctionWrapper.h
r27965 r28093 1 /* Copyright (C) 202 3Wildfire Games.1 /* Copyright (C) 202 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 23 23 #include "ScriptRequest.h" 24 24 25 25 26 #include <tuple> 26 27 #include <type_traits> 28 27 29 #include <utility> 28 30 … … 81 83 struct args_info<R(C::*)(Types ...) const> : public args_info<R(C::*)(Types ...)> {}; 82 84 85 86 87 88 89 90 91 92 93 94 95 83 96 /////////////////////////////////////////////////////////////////////////// 84 97 /////////////////////////////////////////////////////////////////////////// … … 348 361 349 362 /** 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 350 416 * Return a function spec from a C++ function. 351 417 */
Note:
See TracChangeset
for help on using the changeset viewer.