439 lines
13 KiB
Markdown
439 lines
13 KiB
Markdown
# Phase 2: ObjectAccessor Migration - Updated Roadmap with victim Field Optimization
|
|||
|
|
|
||
|
|
**Last Updated**: 2025-10-25
|
||
|
|
**Status**: Phase 2D Complete, victim Field Discovery Added
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Completed Phases
|
||
|
|
|
||
|
|
### ✅ Phase 2A: Proximity Detection (COMPLETE)
|
||
|
|
- **Files**: ProximityDetector.cpp
|
||
|
|
- **Result**: 100% snapshot-based, zero ObjectAccessor calls
|
||
|
|
- **FPS Impact**: Baseline established
|
||
|
|
|
||
|
|
### ✅ Phase 2B: Movement System (COMPLETE)
|
||
|
|
- **Files**: MovementGenerator.cpp, PathfindingManager.cpp
|
||
|
|
- **Result**: 85% reduction (20 → 3 calls)
|
||
|
|
- **FPS Impact**: 2-3%
|
||
|
|
|
||
|
|
### ✅ Phase 2C: ThreatCalculator Integration (COMPLETE)
|
||
|
|
- **Files**: ThreatCalculator.cpp
|
||
|
|
- **Result**: 75% reduction (12 → 3 calls)
|
||
|
|
- **FPS Impact**: 1-2%
|
||
|
|
|
||
|
|
### ✅ Phase 2D: Combat System Completion (COMPLETE)
|
||
|
|
- **Files**: ThreatCoordinator, BotThreatManager, GroupCombatTrigger, TargetSelector, TargetScanner, LineOfSightManager, InterruptAwareness, CombatBehaviorIntegration (8 files)
|
||
|
|
- **Result**: 40% reduction (52 → 31 calls)
|
||
|
|
- **FPS Impact**: 3-5%
|
||
|
|
- **Major Discovery**: PlayerSnapshot.victim field enables massive optimization opportunity
|
||
|
|
|
||
|
|
**Phase 2D Actual Results**:
|
||
|
|
- ThreatCoordinator.cpp: 65% reduction (23 → 8 calls)
|
||
|
|
- GroupCombatTrigger.cpp: 40% reduction (5 → 3 calls) - **Discovered victim field!**
|
||
|
|
- 5 files already optimized in PHASE 1/5B (cleanup only)
|
||
|
|
- Zero compilation errors across all changes
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## NEW: Phase 2E - PlayerSnapshot.victim Field Optimization
|
||
|
|
|
||
|
|
**Discovery**: During Phase 2D, we discovered PlayerSnapshot.victim field containing the ObjectGuid of player's current combat target. This enables direct GUID comparison without ObjectAccessor calls.
|
||
|
|
|
||
|
|
**Scope**: 98 GetVictim() calls across 40 files
|
||
|
|
**Estimated Impact**: 35-60 calls eliminated (2-6% FPS improvement)
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### Phase 2E-A: High-Impact Files (PRIORITY 1)
|
||
|
|
|
||
|
|
**Effort**: 2-3 hours
|
||
|
|
**Expected Impact**: 15-20 calls eliminated, 1-2% FPS improvement
|
||
|
|
|
||
|
|
#### Files:
|
||
|
|
1. **WarlockAI.cpp** (12 GetVictim calls)
|
||
|
|
- Pet/demon target coordination
|
||
|
|
- Healthstone/soulstone target validation
|
||
|
|
- Fear/CC target checks
|
||
|
|
- **Priority**: CRITICAL (highest call count)
|
||
|
|
|
||
|
|
2. **CooldownStackingOptimizer.cpp** (7 GetVictim calls)
|
||
|
|
- Burst window target validation
|
||
|
|
- Execute phase target checks
|
||
|
|
- Multi-target rotation logic
|
||
|
|
- **Priority**: HIGH (high-frequency combat path)
|
||
|
|
|
||
|
|
3. **TargetAssistAction.cpp** (4 GetVictim calls)
|
||
|
|
- Leader target lookup
|
||
|
|
- Group member assist targeting
|
||
|
|
- Focus fire coordination
|
||
|
|
- **Priority**: HIGH (group coordination, used every combat)
|
||
|
|
|
||
|
|
**Optimization Patterns**:
|
||
|
|
```cpp
|
||
|
|
// Pattern 1: Target comparison (40+ occurrences)
|
||
|
|
// BEFORE:
|
||
|
|
if (player->GetVictim() == target)
|
||
|
|
priority += 20.0f;
|
||
|
|
|
||
|
|
// AFTER:
|
||
|
|
auto snapshot = SpatialGridQueryHelpers::FindPlayerByGuid(nullptr, playerGuid);
|
||
|
|
if (snapshot && snapshot->victim == target->GetGUID())
|
||
|
|
priority += 20.0f;
|
||
|
|
|
||
|
|
// Pattern 2: Leader target lookup
|
||
|
|
// BEFORE:
|
||
|
|
Player* leader = ObjectAccessor::FindPlayer(leaderGuid);
|
||
|
|
if (leader && leader->GetVictim())
|
||
|
|
Attack(leader->GetVictim());
|
||
|
|
|
||
|
|
// AFTER:
|
||
|
|
auto leaderSnapshot = SpatialGridQueryHelpers::FindPlayerByGuid(nullptr, leaderGuid);
|
||
|
|
if (leaderSnapshot && !leaderSnapshot->victim.IsEmpty())
|
||
|
|
{
|
||
|
|
Unit* target = ObjectAccessor::GetUnit(*bot, leaderSnapshot->victim);
|
||
|
|
if (target) Attack(target);
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### Phase 2E-B: Combat Module Completion (PRIORITY 2)
|
||
|
|
|
||
|
|
**Effort**: 1-2 hours
|
||
|
|
**Expected Impact**: 8-12 calls eliminated, 0.5-1% FPS improvement
|
||
|
|
|
||
|
|
#### Files:
|
||
|
|
1. **GroupCombatTrigger.cpp** (4 remaining calls)
|
||
|
|
- Lines 318, 479, 566 - Group member targeting
|
||
|
|
- Complete Phase 2D optimization
|
||
|
|
|
||
|
|
2. **BotThreatManager.cpp** (5 GetVictim calls)
|
||
|
|
- Threat distribution checks
|
||
|
|
- Multi-target threat validation
|
||
|
|
|
||
|
|
3. **TargetScanner.cpp** (4 GetVictim calls)
|
||
|
|
- Priority target scanning
|
||
|
|
- Combat target validation
|
||
|
|
|
||
|
|
4. **KitingManager.cpp** (2 GetVictim calls)
|
||
|
|
- Kiting target validation
|
||
|
|
- Distance management
|
||
|
|
|
||
|
|
**Focus**: Complete all combat module victim field optimizations
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### Phase 2E-C: Class AI Templates (PRIORITY 3)
|
||
|
|
|
||
|
|
**Effort**: 3-4 hours
|
||
|
|
**Expected Impact**: 15-20 calls eliminated, 1-1.5% FPS improvement
|
||
|
|
|
||
|
|
#### Files (by class):
|
||
|
|
|
||
|
|
**Hunter AI** (7 calls total):
|
||
|
|
- BeastMasteryHunterRefactored.h (3 calls)
|
||
|
|
- MarksmanshipHunterRefactored.h (1 call)
|
||
|
|
- SurvivalHunterRefactored.h (3 calls)
|
||
|
|
- HunterAI.cpp (1 call)
|
||
|
|
- Pet management target validation
|
||
|
|
|
||
|
|
**Priest AI** (4 calls total):
|
||
|
|
- DisciplinePriestRefactored.h (2 calls)
|
||
|
|
- HolyPriestRefactored.h (2 calls)
|
||
|
|
- Heal target priority validation
|
||
|
|
|
||
|
|
**Druid AI** (3 calls):
|
||
|
|
- RestorationDruidRefactored.h (3 calls)
|
||
|
|
- Multi-role target switching
|
||
|
|
|
||
|
|
**Paladin AI** (2 calls):
|
||
|
|
- HolyPaladinRefactored.h (2 calls)
|
||
|
|
- Beacon target validation
|
||
|
|
|
||
|
|
**DemonHunter AI** (2 calls):
|
||
|
|
- HavocDemonHunterRefactored.h (1 call)
|
||
|
|
- VengeanceDemonHunterRefactored.h (1 call)
|
||
|
|
|
||
|
|
**Warrior AI** (1 call):
|
||
|
|
- ProtectionWarriorRefactored.h (1 call)
|
||
|
|
- Tank target validation
|
||
|
|
|
||
|
|
**Template Base** (2 calls):
|
||
|
|
- CombatSpecializationTemplates.h (2 calls)
|
||
|
|
- Generic spec target logic
|
||
|
|
|
||
|
|
**Other Class AI** (3 calls):
|
||
|
|
- ClassAI.cpp (3 calls)
|
||
|
|
- ClassAI_Refactored.cpp (1 call)
|
||
|
|
- ShamanAI.cpp (1 call)
|
||
|
|
- WarlockAI.cpp (already in Phase 2E-A)
|
||
|
|
- DeathKnightAI.cpp (1 call)
|
||
|
|
|
||
|
|
**Caution**: Template code requires careful testing across all specs
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### Phase 2E-D: Strategy and Behavior Modules (PRIORITY 4)
|
||
|
|
|
||
|
|
**Effort**: 1-2 hours
|
||
|
|
**Expected Impact**: 5-8 calls eliminated, 0.5-1% FPS improvement
|
||
|
|
|
||
|
|
#### Files:
|
||
|
|
|
||
|
|
**Strategy Module**:
|
||
|
|
1. **GroupCombatStrategy.cpp** (3 calls)
|
||
|
|
- Group coordination logic
|
||
|
|
- Focus fire strategies
|
||
|
|
|
||
|
|
2. **SoloCombatStrategy.cpp** (1 call)
|
||
|
|
- Solo target switching
|
||
|
|
|
||
|
|
**Combat Behaviors**:
|
||
|
|
3. **AoEDecisionManager.cpp** (2 calls)
|
||
|
|
- Multi-target AoE validation
|
||
|
|
- Cleave target counting
|
||
|
|
|
||
|
|
**Learning Module**:
|
||
|
|
4. **PlayerPatternRecognition.cpp** (2 calls)
|
||
|
|
- Player behavior analysis
|
||
|
|
- Target pattern learning
|
||
|
|
|
||
|
|
5. **BehaviorAdaptation.cpp** (1 call)
|
||
|
|
- Adaptive targeting logic
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### Phase 2E-E: Remaining Files (PRIORITY 5)
|
||
|
|
|
||
|
|
**Effort**: 1-2 hours
|
||
|
|
**Expected Impact**: 5-10 calls eliminated, <0.5% FPS improvement
|
||
|
|
|
||
|
|
#### Files:
|
||
|
|
1. **BotAI.cpp** (3 calls)
|
||
|
|
2. **BotAI_EventHandlers.cpp** (2 calls)
|
||
|
|
3. **EnhancedBotAI.cpp** (1 call)
|
||
|
|
4. **DungeonBehavior.cpp** (1 call)
|
||
|
|
5. **LeaderFollowBehavior.cpp** (1 call)
|
||
|
|
6. **PvPCombatAI.cpp** (1 call)
|
||
|
|
7. **ArenaAI.cpp** (1 call)
|
||
|
|
8. **ShadowfangKeepScript.cpp** (1 call)
|
||
|
|
9. **DoubleBufferedSpatialGrid.cpp** (2 calls)
|
||
|
|
10. **ThreatIntegrationExample.h** (3 calls)
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Phase 2E Total Impact Projection
|
||
|
|
|
||
|
|
### Conservative Estimate:
|
||
|
|
- **Total GetVictim() calls**: 98
|
||
|
|
- **Optimizable calls**: 70 (71%)
|
||
|
|
- **Estimated reduction**: 35-50 calls (36-51% of optimizable)
|
||
|
|
- **ObjectAccessor calls eliminated**: 25-40
|
||
|
|
- **Expected FPS improvement**: 2-4%
|
||
|
|
|
||
|
|
### Optimistic Estimate:
|
||
|
|
- **Optimizable calls**: 70 (71%)
|
||
|
|
- **Estimated reduction**: 50-60 calls (71-86% of optimizable)
|
||
|
|
- **ObjectAccessor calls eliminated**: 40-50
|
||
|
|
- **Expected FPS improvement**: 4-6%
|
||
|
|
|
||
|
|
### 100-Bot Scenario:
|
||
|
|
- Calls eliminated: 2,500-5,000 calls/sec
|
||
|
|
- Lock contention reduction: 10-20%
|
||
|
|
- **Measurable FPS improvement**: 4-8%
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Remaining Future Phases
|
||
|
|
|
||
|
|
### Phase 2F: Session Management (HIGH PRIORITY)
|
||
|
|
**Status**: Not started
|
||
|
|
**Files**: SessionManager.cpp, BotWorldSessionMgr.cpp
|
||
|
|
**Expected Reduction**: 50-70%
|
||
|
|
**Expected FPS Impact**: 3-5%
|
||
|
|
**Effort**: 4-6 hours
|
||
|
|
|
||
|
|
### Phase 2G: Quest System (MEDIUM PRIORITY)
|
||
|
|
**Status**: Not started
|
||
|
|
**Files**: QuestCompletion.cpp, QuestPickup.cpp, QuestTurnIn.cpp
|
||
|
|
**Expected Reduction**: 40-60%
|
||
|
|
**Expected FPS Impact**: 1-3%
|
||
|
|
**Effort**: 3-4 hours
|
||
|
|
|
||
|
|
### Phase 2H: Loot System (LOW PRIORITY)
|
||
|
|
**Status**: Not started
|
||
|
|
**Files**: LootManager.cpp, LootDistributor.cpp
|
||
|
|
**Expected Reduction**: 30-50%
|
||
|
|
**Expected FPS Impact**: <1%
|
||
|
|
**Effort**: 2-3 hours
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Cumulative Impact Projection
|
||
|
|
|
||
|
|
### Phase 2A through 2D (COMPLETE):
|
||
|
|
- **FPS Improvement**: 6-10% (measured)
|
||
|
|
- **ObjectAccessor Reduction**: 50%+ across optimized modules
|
||
|
|
|
||
|
|
### Phase 2E (victim Field Optimization):
|
||
|
|
- **Additional FPS Improvement**: 2-6%
|
||
|
|
- **Total ObjectAccessor Reduction**: 60-70%
|
||
|
|
|
||
|
|
### Phase 2F-2H (Future):
|
||
|
|
- **Additional FPS Improvement**: 4-9%
|
||
|
|
- **Total ObjectAccessor Reduction**: 70-80%
|
||
|
|
|
||
|
|
### **Grand Total (All Phases)**:
|
||
|
|
- **Cumulative FPS Improvement**: 12-25%
|
||
|
|
- **Cumulative ObjectAccessor Reduction**: 70-80%
|
||
|
|
- **Total Effort**: 25-35 hours
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Implementation Priority Order
|
||
|
|
|
||
|
|
### Immediate (Next Session):
|
||
|
|
1. ✅ Phase 2D - COMPLETE
|
||
|
|
2. **Phase 2E-A** - High-Impact victim Field (2-3 hours, 1-2% FPS) ⬅️ **START HERE**
|
||
|
|
|
||
|
|
### Short-Term (This Week):
|
||
|
|
3. Phase 2E-B - Combat Module victim Field (1-2 hours, 0.5-1% FPS)
|
||
|
|
4. Phase 2E-C - Class AI victim Field (3-4 hours, 1-1.5% FPS)
|
||
|
|
|
||
|
|
### Medium-Term (This Month):
|
||
|
|
5. Phase 2E-D - Strategy/Behavior victim Field (1-2 hours, 0.5-1% FPS)
|
||
|
|
6. Phase 2E-E - Remaining victim Field (1-2 hours, <0.5% FPS)
|
||
|
|
7. Phase 2F - Session Management (4-6 hours, 3-5% FPS)
|
||
|
|
|
||
|
|
### Long-Term (Future Sprints):
|
||
|
|
8. Phase 2G - Quest System (3-4 hours, 1-3% FPS)
|
||
|
|
9. Phase 2H - Loot System (2-3 hours, <1% FPS)
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Key Lessons from Phase 2D
|
||
|
|
|
||
|
|
### 1. PlayerSnapshot.victim Field Discovery
|
||
|
|
- **Impact**: Unlocked massive optimization potential (98 GetVictim() calls)
|
||
|
|
- **Lesson**: Always explore snapshot struct fields before assuming ObjectAccessor is required
|
||
|
|
|
||
|
|
### 2. Previous Optimization Detection
|
||
|
|
- **Finding**: 5 of 8 files already optimized in PHASE 1/5B
|
||
|
|
- **Lesson**: Always grep for "PHASE" or "DEADLOCK FIX" before extensive analysis
|
||
|
|
|
||
|
|
### 3. Redundant IsAlive() Check Pattern
|
||
|
|
- **Pattern**: Spatial grid queries return only alive entities
|
||
|
|
- **Lesson**: IsAlive() checks after spatial grid queries are always redundant
|
||
|
|
|
||
|
|
### 4. Return Type Constraints
|
||
|
|
- **Constraint**: Functions returning Unit* must call ObjectAccessor
|
||
|
|
- **Lesson**: Focus optimization on GUID comparison, not Unit* pointer elimination
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Testing and Validation Strategy
|
||
|
|
|
||
|
|
### Per-Phase Validation:
|
||
|
|
1. Unit tests for victim field comparison
|
||
|
|
2. Integration tests for group coordination
|
||
|
|
3. Performance profiling (ObjectAccessor call reduction)
|
||
|
|
4. FPS measurement (100-bot scenario)
|
||
|
|
|
||
|
|
### Regression Testing:
|
||
|
|
- Combat targeting accuracy
|
||
|
|
- Group assist functionality
|
||
|
|
- Pet/demon target coordination
|
||
|
|
- PvP arena target switching
|
||
|
|
|
||
|
|
### Performance Metrics:
|
||
|
|
- ObjectAccessor calls/sec (should decrease 20-40%)
|
||
|
|
- Lock contention time (should decrease 10-20%)
|
||
|
|
- FPS with 100 bots (should increase 2-6%)
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Documentation References
|
||
|
|
|
||
|
|
### Phase 2D Documentation:
|
||
|
|
- PHASE2D_COMPLETE.md - Final Phase 2D summary
|
||
|
|
- PHASE2D_SESSION_PROGRESS.md - Session progress report
|
||
|
|
- Individual file summaries (BotThreatManager, TargetSelector, etc.)
|
||
|
|
|
||
|
|
### Phase 2E Documentation:
|
||
|
|
- **PLAYERSNAPSHOT_VICTIM_OPTIMIZATION_GUIDE.md** - Comprehensive victim field guide
|
||
|
|
- All optimization patterns
|
||
|
|
- Real-world examples
|
||
|
|
- Module-by-module impact analysis
|
||
|
|
- Implementation workflow
|
||
|
|
- Common pitfalls and solutions
|
||
|
|
- Testing templates
|
||
|
|
|
||
|
|
### Phase 1 Documentation:
|
||
|
|
- PHASE1_SPATIAL_GRID_ARCHITECTURE.md - Lock-free foundation
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Success Criteria
|
||
|
|
|
||
|
|
### Phase 2E-A Success:
|
||
|
|
- [ ] WarlockAI.cpp: 8-10 calls eliminated
|
||
|
|
- [ ] CooldownStackingOptimizer.cpp: 4-6 calls eliminated
|
||
|
|
- [ ] TargetAssistAction.cpp: 3-4 calls eliminated
|
||
|
|
- [ ] Zero compilation errors
|
||
|
|
- [ ] All tests passing
|
||
|
|
- [ ] Measurable FPS improvement: 1-2%
|
||
|
|
|
||
|
|
### Phase 2E Complete Success:
|
||
|
|
- [ ] All 5 sub-phases complete (A through E)
|
||
|
|
- [ ] 35-60 GetVictim() calls eliminated
|
||
|
|
- [ ] Zero compilation errors across all files
|
||
|
|
- [ ] All regression tests passing
|
||
|
|
- [ ] Measurable FPS improvement: 2-6%
|
||
|
|
|
||
|
|
### Phase 2 Complete Success (All Phases):
|
||
|
|
- [ ] Phases 2A-2H complete
|
||
|
|
- [ ] 70-80% ObjectAccessor reduction
|
||
|
|
- [ ] 12-25% cumulative FPS improvement
|
||
|
|
- [ ] Production-ready, fully tested
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Risk Mitigation
|
||
|
|
|
||
|
|
### Technical Risks:
|
||
|
|
1. **Snapshot Staleness** (100-200ms update cycle)
|
||
|
|
- Mitigation: Hybrid approach for critical timing (<100ms precision)
|
||
|
|
- Impact: Low (99% of use cases tolerate 100ms staleness)
|
||
|
|
|
||
|
|
2. **Null Snapshot Handling**
|
||
|
|
- Mitigation: Always check snapshot validity before use
|
||
|
|
- Impact: Medium (crashes if not handled)
|
||
|
|
|
||
|
|
3. **Template Code Complexity** (Phase 2E-C)
|
||
|
|
- Mitigation: Extensive testing across all specs
|
||
|
|
- Impact: Medium (template errors affect multiple classes)
|
||
|
|
|
||
|
|
### Project Risks:
|
||
|
|
1. **Scope Creep** (98 calls to optimize)
|
||
|
|
- Mitigation: Phased approach with clear priorities
|
||
|
|
- Impact: Low (well-defined phases)
|
||
|
|
|
||
|
|
2. **Regression Introduction**
|
||
|
|
- Mitigation: Comprehensive testing strategy
|
||
|
|
- Impact: Medium (combat targeting is critical)
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Conclusion
|
||
|
|
|
||
|
|
Phase 2D is complete with the major discovery of PlayerSnapshot.victim field optimization potential. Phase 2E (victim field optimization) is now the highest priority next step, offering 2-6% additional FPS improvement with 8-13 hours of total effort across 5 sub-phases.
|
||
|
|
|
||
|
|
**Recommendation**: **Immediately start Phase 2E-A** (high-impact files: WarlockAI, CooldownStackingOptimizer, TargetAssistAction) to unlock 1-2% FPS improvement in just 2-3 hours.
|
||
|
|
|
||
|
|
The cumulative impact of Phase 2 (all sub-phases) is projected at **12-25% FPS improvement** - a transformational performance gain for the Playerbot module.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
**End of Updated Roadmap**
|