From a70bb43daefa7e05aa94aa4f796dcda8b6d3c9f5 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 3 Jun 2021 19:07:34 +0300 Subject: [PATCH] Rewrote 'check unneeded tech prerequisites' that was causing ANRs and lowered time from 714ms to 1ms on my computer (!) for RekMOD check. Also removed it from being blocking, since some important older mods (e.g. DeCiv) are unplayable because of this. --- buildSrc/src/main/kotlin/BuildConfig.kt | 4 ++-- core/src/com/unciv/models/ruleset/Ruleset.kt | 21 ++++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/buildSrc/src/main/kotlin/BuildConfig.kt b/buildSrc/src/main/kotlin/BuildConfig.kt index 1512ea1a54..730e8194cb 100644 --- a/buildSrc/src/main/kotlin/BuildConfig.kt +++ b/buildSrc/src/main/kotlin/BuildConfig.kt @@ -3,8 +3,8 @@ package com.unciv.build object BuildConfig { const val kotlinVersion = "1.4.30" const val appName = "Unciv" - const val appCodeNumber = 572 - const val appVersion = "3.14.13" + const val appCodeNumber = 573 + const val appVersion = "3.14.13-patch1" const val gdxVersion = "1.10.0" const val roboVMVersion = "2.3.1" diff --git a/core/src/com/unciv/models/ruleset/Ruleset.kt b/core/src/com/unciv/models/ruleset/Ruleset.kt index ec14fad2cc..5256571d92 100644 --- a/core/src/com/unciv/models/ruleset/Ruleset.kt +++ b/core/src/com/unciv/models/ruleset/Ruleset.kt @@ -317,22 +317,31 @@ class Ruleset { lines += "${terrain.name} occurs on terrain $baseTerrain which does not exist!" } + val prereqsHashMap = HashMap>() for (tech in technologies.values) { for (prereq in tech.prerequisites) { if (!technologies.containsKey(prereq)) lines += "${tech.name} requires tech $prereq which does not exist!" - fun getPrereqTree(technologyName: String): Sequence { + fun getPrereqTree(technologyName: String): Set { + if (prereqsHashMap.containsKey(technologyName)) return prereqsHashMap[technologyName]!! val technology = technologies[technologyName] - if (technology == null) return sequenceOf() - return technology.prerequisites.asSequence() + technology.prerequisites.asSequence().flatMap { getPrereqTree(it) } + if (technology == null) return emptySet() + val techHashSet = HashSet() + techHashSet += technology.prerequisites + for (prereq in technology.prerequisites) + techHashSet += getPrereqTree(prereq) + prereqsHashMap[technologyName] = techHashSet + return techHashSet } - val allOtherPrereqs = tech.prerequisites.asSequence().filterNot { it == prereq }.flatMap { getPrereqTree(it) } - if (allOtherPrereqs.contains(prereq)) - lines += "No need to add $prereq as a prerequisite of ${tech.name} - it is already implicit from the other prerequisites!" + if (tech.prerequisites.asSequence().filterNot { it == prereq } + .any { getPrereqTree(it).contains(prereq) }) + println("No need to add $prereq as a prerequisite of ${tech.name} - it is already implicit from the other prerequisites!") } } + + return lines.joinToString("\n") } }