angered-ghandi / OpenAOE

An open source reimplementation of Age of Empires (1997)
Other
64 stars 5 forks source link

Possible unnecesary allocations #59

Closed phrohdoh closed 8 years ago

phrohdoh commented 8 years ago

Is there any reasons all of these systems must consume the EmpiresDbRef? Does the Arc<> prevent actual copying of the data (instead just copies the pointer)?

fn attach_systems(planner: &mut WorldPlanner,
                  empires: &EmpiresDbRef,
                  shape_metadata: &ShapeMetadataStoreRef) {

    system!(planner, VelocitySystem, 1000);
    system!(planner, CameraInputSystem, 1000);
    system!(planner, CameraPositionSystem, 1000);
    system!(planner, CameraPositionSystem, 1000);
    system!(planner, GridSystem, 1000);
    system!(planner,
            DecalSystem,
            DecalSystem::new(shape_metadata.clone()),
            1000);
    system!(planner,
            AnimationSystem,
            AnimationSystem::new(empires.clone(), shape_metadata.clone()),
            1000);
    system!(planner, UnitActionSystem, UnitActionSystem::new(), 1000);
    system!(planner,
            UnitSelectionSystem,
            UnitSelectionSystem::new(empires.clone()),
            1000);
    system!(planner,
            MoveToPositionActionSystem,
            MoveToPositionActionSystem::new(empires.clone()),
            1000);
    system!(planner,
            OccupiedTileSystem,
            OccupiedTileSystem::new(empires.clone()),
            1000);
}

fn attach_render_systems(planner: &mut WorldPlanner, empires: &EmpiresDbRef) {
    render_system!(planner,
                   TerrainRenderSystem,
                   TerrainRenderSystem::new(empires.clone()),
                   1000);
    render_system!(planner, DecalRenderSystem, 1000);
    render_system!(planner,
                   GraphicRenderSystem,
                   GraphicRenderSystem::new(empires.clone()),
                   1000);
    render_system!(planner,
                   UnitSelectionRenderSystem,
                   UnitSelectionRenderSystem::new(empires.clone()),
                   1000);
    render_system!(planner, TileDebugRenderSystem, 1000);
}
phrohdoh commented 8 years ago

I should have done just a bit more reading before opening this.

Cloning an Arc<> just increments the ref-count and clones the pointer.