Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a filter for religions #13016

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SeventhM
Copy link
Collaborator

@SeventhM SeventhM commented Mar 2, 2025

And you get a filter, and you get a filter. Everything gets a multifilter

I mostly thought of this to allow for moving uniques for unlocking religious buildings off of the beliefs themselves and onto the buildings, but almost surely some other modder will find use for it

I really, really, really, really want to find some way to integrate this into city filter (as I believe there is actually a niche case use for that), but I can't figure out how I would go about doing that or if it's just the unique in question needs better alternatives

}

private fun matchesSingleFilter(filter: String, state: StateForConditionals = StateForConditionals.IgnoreConditionals, civ: Civilization? = null): Boolean {
if (filter == "any") return true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For performance, turn this into a switch with all static cases, and have "else" contain the dynamic cases (name, hasMatchingUnique)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... even if you then duplicate the getFounder() call (because it will nevertheless be called at most once - it will even be called "less" if you get to the else). Don't forget that when(filter) { name -> true... works1, and afterwards it may be simple enough to warrant fun(): T { return x } => fun() = x, which often reads better2. Though I admit both hints do have negative precedents in our code - all the matchesSingleFilter I see don't follow them.

Also - aren't the two last if lines absolutely identical?

Footnotes

  1. In some other programming languages a switch/case only accepts compile-time constants as branches - e.g. C and C++, but C# could do it via var pattern...

  2. Not always - e.g. when the return type is not immediately obvious

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevertheless be called at most once - it will even be called "less" if you get to the else). Don't forget that when(filter) { name -> true... works

Java is one such language where switch statements requires a compile-time here if I understand correctly. So that also would compile to an if chain if I understand correctly rather than an actual jvm switch

Also - aren't the two last if lines absolutely identical?

Goddammit

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context

Wow. Not really surprising given what 7th just said about Java, but a bit disappointing the compiler won't resolve that itself...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes me associate - what was up with interning for Strings in Kotlin? If all strings involved here were interned and coalesced, it wouldn't even need a call to equals(), comparing GC id's or pointers or whatever would be enough, and for the constants part it could precompile a vtable-type thingy. Someone must have determined that all the extra indexing work upsert's overshadows select performance...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all JVM languages, interning is not default behavior because it's essentially a hashmap getOrPut which is not cheap
I did consider doing it for RAM purposes but didn't see it made a difference

@SeventhM
Copy link
Collaborator Author

SeventhM commented Mar 2, 2025

Actually, question: should this accept a civFilter as well? E.g. in cities following a [England] religion. I didn't originally plan on that, and I'm not sure if it's worthwhile to add or not

@yairm210
Copy link
Owner

yairm210 commented Mar 2, 2025

I think we can forgo that for now, if no one is asking for it it sounds kind of 'out there'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants