mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-11-08 10:29:00 +00:00
Reduce usage of entityObj in SharedScript
The information where a unit is and which resource it provides wasn't available on joining clients. Now the `resourceMap` is reset when a resource is destroide. It would be performance intensive when the `resourceMap` would be reset when any unit would be destroied. To prevent this the `SharedScript` remembers which entities are resourcesources.
This commit is contained in:
1 file changed
+9
-3
@@ -126,6 +126,8 @@ SharedScript.prototype.init = function(state, deserialization)
|
|||||||
this.normalizationFactor = { "abundant": 50, "sparse": 90 };
|
this.normalizationFactor = { "abundant": 50, "sparse": 90 };
|
||||||
this.influenceRadius = { "abundant": 36, "sparse": 48 };
|
this.influenceRadius = { "abundant": 36, "sparse": 48 };
|
||||||
this.ccInfluenceRadius = { "abundant": 60, "sparse": 120 };
|
this.ccInfluenceRadius = { "abundant": 60, "sparse": 120 };
|
||||||
|
|
||||||
|
this.resources = []; // Contains entityIds of all resources in the maps.
|
||||||
this.resourceMaps = {}; // Contains maps showing the density of resources
|
this.resourceMaps = {}; // Contains maps showing the density of resources
|
||||||
this.ccResourceMaps = {}; // Contains maps showing the density of resources, optimized for CC placement.
|
this.ccResourceMaps = {}; // Contains maps showing the density of resources, optimized for CC placement.
|
||||||
this.createResourceMaps();
|
this.createResourceMaps();
|
||||||
@@ -410,9 +412,12 @@ SharedScript.prototype.createResourceMaps = function()
|
|||||||
*/
|
*/
|
||||||
SharedScript.prototype.updateResourceMaps = function(events)
|
SharedScript.prototype.updateResourceMaps = function(events)
|
||||||
{
|
{
|
||||||
for (const e of events.Destroy)
|
if (events.Destroy.some(e => this.resources.includes(e.entity)))
|
||||||
if (e.entityObj)
|
{
|
||||||
this.removeEntityFromResourceMap(e.entityObj);
|
this.resources = [];
|
||||||
|
this.resourceMaps = {};
|
||||||
|
this.createResourceMaps();
|
||||||
|
}
|
||||||
|
|
||||||
for (const e of events.Create)
|
for (const e of events.Create)
|
||||||
if (e.entity && this._entities.has(e.entity))
|
if (e.entity && this._entities.has(e.entity))
|
||||||
@@ -425,6 +430,7 @@ SharedScript.prototype.updateResourceMaps = function(events)
|
|||||||
SharedScript.prototype.addEntityToResourceMap = function(entity)
|
SharedScript.prototype.addEntityToResourceMap = function(entity)
|
||||||
{
|
{
|
||||||
this.changeEntityInResourceMapHelper(entity, 1);
|
this.changeEntityInResourceMapHelper(entity, 1);
|
||||||
|
this.resources.push(entity.id());
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user