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

Extract StoresResources from Harvester #20761

Merged
merged 1 commit into from Sep 23, 2023

Conversation

PunkPun
Copy link
Member

@PunkPun PunkPun commented Mar 22, 2023

This is the first PR of the resource refactor.

  • Renamed StoresResources -> StoresPlayerResources
  • Extracted StoresResources from Harvester (StoresResources diff is messed up)
  • Renamed WithHarvesterPipsDecoration -> WithStoresResourcesPipsDecoration

This was an easy first step that could be done before docking refactor or the massive systematic changes to player resources.

With this PR harvesters will be able to have multiple storage containers, although the pips will be shown for only the one (consistent with most of our UI traits). We may want to create a way of tying those traits together somehow in the future.

We may also want to consider adding per-resource conditions so enable features such as TS harvester exploding when containing blue tib. I can add this feature in this PR if requested.

@PunkPun PunkPun force-pushed the resource-preparation branch 2 times, most recently from 9846d0d to cdee855 Compare April 15, 2023 17:55
anvilvapre
anvilvapre previously approved these changes May 1, 2023
Copy link
Contributor

@anvilvapre anvilvapre left a comment

Choose a reason for hiding this comment

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

untested.

StoresPlayerResourceAmount, seems better than StoresPlayerResources.

Or PlayerResourceConsumer.


/// <summary>Stored resources.</summary>
/// <remarks>Dictionary key refers to resourceType, value refers to resource amount.</remarks>
IReadOnlyDictionary<string, int> Contents { get; }
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand you want to keep resource type a string.

On the other hand I assume this is a hot path. Seems somewhat wastefull to do constant string hash calculations and hash map lookups to get and set an integer value.

HarvesterInfo.Resources is readonly. You could assign integer indexes. So that you can get rid of of both the string and map and use an array of length Resources.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think the extra complexity is worth it. (At least unless we have some numbers on that this makes a significant impact.)

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not a cold path, but also it's not very hot, so such optimisations shouldn't have very noticeable impact. It may make sense to do an optimisation pass after the whole refactor is finished, but atm it would just make the code much harder to read.

Copy link
Contributor

Choose a reason for hiding this comment

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

8 haversters times 8 players times any resource update.

OpenRA.Mods.Common/Traits/Harvester.cs Outdated Show resolved Hide resolved
OpenRA.Mods.Common/Traits/Harvester.cs Outdated Show resolved Hide resolved
OpenRA.Mods.Common/Traits/Harvester.cs Show resolved Hide resolved
OpenRA.Mods.Common/Traits/Harvester.cs Show resolved Hide resolved
OpenRA.Mods.Common/Traits/StoresPlayerResources.cs Outdated Show resolved Hide resolved
OpenRA.Mods.Common/Traits/StoresResources.cs Outdated Show resolved Hide resolved
}
}

public int ContentsSum { get; private set; } = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Expensive sync.

Copy link
Member Author

Choose a reason for hiding this comment

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

There's no sync here?

Copy link
Contributor

Choose a reason for hiding this comment

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

The line above. Is it really worth while to sync the value of each harvester contineously. And you do this by looping over the contents. I guess there are only a few types of content.

OpenRA.Mods.Common/Traits/StoresResources.cs Show resolved Hide resolved
OpenRA.Game/Traits/TraitsInterfaces.cs Show resolved Hide resolved
string[] ResourceTypes { get; }
}

public interface IStoresResources
Copy link
Member

Choose a reason for hiding this comment

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

This should also be explicitly implemented.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why? It would just force nasty code in other implementations

Copy link
Member

Choose a reason for hiding this comment

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

All our interfaces should be explicit. Why would this force nasty code?

Copy link
Member Author

Choose a reason for hiding this comment

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

because if the interface is explicit, you can't reference members within the class

OpenRA.Mods.Common/Traits/Harvester.cs Outdated Show resolved Hide resolved
@Mailaender

This comment was marked as resolved.

@Mailaender Mailaender merged commit d427072 into OpenRA:bleed Sep 23, 2023
3 checks passed
@PunkPun PunkPun deleted the resource-preparation branch September 23, 2023 17:06
@Mailaender
Copy link
Member

Changelog

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.

None yet

4 participants