mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
perf(ship): share per-team accent material instead of allocating per ship
_apply_team_color() allocated a fresh StandardMaterial3D on every call, and ran at least twice per ship (once from _ready at the default team, once from the team setter when the game mode assigns the real team). Cache one StandardMaterial3D per team in a static dict on Ship and reuse it across every ship on that team.
This commit is contained in:
+21
-8
@@ -38,6 +38,26 @@ var team: int = 0:
|
||||
team = value
|
||||
_apply_team_color()
|
||||
|
||||
# Shared per-team accent material, built once per team and reused by every
|
||||
# ship — avoids allocating a fresh StandardMaterial3D from both _ready and
|
||||
# the team setter (previously ran at least twice per ship).
|
||||
static var _team_materials: Dictionary = {} # team:int -> StandardMaterial3D
|
||||
|
||||
|
||||
static func _get_team_material(team: int) -> StandardMaterial3D:
|
||||
if _team_materials.has(team):
|
||||
return _team_materials[team]
|
||||
var color: Color = TEAM_COLORS.get(team, TEAM_COLORS[0])
|
||||
var accent := StandardMaterial3D.new()
|
||||
accent.albedo_color = color
|
||||
accent.metallic = 0.3
|
||||
accent.roughness = 0.5
|
||||
accent.emission_enabled = true
|
||||
accent.emission = color
|
||||
accent.emission_energy_multiplier = 0.35
|
||||
_team_materials[team] = accent
|
||||
return accent
|
||||
|
||||
var controller: ShipController
|
||||
var _current_action: ShipAction = ShipAction.new()
|
||||
var _boundary: ArenaBoundary
|
||||
@@ -93,14 +113,7 @@ func _ready():
|
||||
func _apply_team_color() -> void:
|
||||
if not is_inside_tree():
|
||||
return
|
||||
var color: Color = TEAM_COLORS.get(team, TEAM_COLORS[0])
|
||||
var accent := StandardMaterial3D.new()
|
||||
accent.albedo_color = color
|
||||
accent.metallic = 0.3
|
||||
accent.roughness = 0.5
|
||||
accent.emission_enabled = true
|
||||
accent.emission = color
|
||||
accent.emission_energy_multiplier = 0.35
|
||||
var accent := _get_team_material(team)
|
||||
for mesh_name in ["Nose", "TailFin"]:
|
||||
var mesh := get_node_or_null(mesh_name) as MeshInstance3D
|
||||
if mesh:
|
||||
|
||||
@@ -25,7 +25,6 @@ Bugs found in an adversarial review. None are gameplay- or physics-affecting, so
|
||||
|
||||
## Performance
|
||||
|
||||
- [ ] Shared per-team materials instead of `Ship._apply_team_color()` allocating a fresh `StandardMaterial3D` and assigning it as `material_override` (and running at least twice per ship — once from `_ready`, once from the `team` setter). Removes the allocation and lets same-team ships batch.
|
||||
- [ ] Merge the four non-tinted ship meshes (Hull/Canopy/EngineGlowL/R) into one — 6 draw calls per ship down to 3. Irrelevant at 1v1; 36 calls before VFX at 3v3.
|
||||
- [ ] Name collision layers in `project.godot` and assign them — nothing configures `collision_layer`/`collision_mask` today, so every body tests against every other.
|
||||
- [ ] Measure `nebula_dust.gdshader`'s per-fragment depth-texture sample across 500 large soft billboards before adding more particle work.
|
||||
|
||||
Reference in New Issue
Block a user