physics_service_rename.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. import os
  9. import re
  10. from pathlib import Path
  11. '''
  12. Updates AZ_CRC to AZ_CRC_CE.
  13. '''
  14. def crc_update(line: str):
  15. return re.sub(r'(AZ_CRC\()(.*)(,[\s]*0x[0-9a-f]{8})',
  16. r'AZ_CRC_CE(\2',
  17. line)
  18. '''
  19. Renames services provided by PhysX components from PhysX...Service to Physics...Service.
  20. The service names were originally chosen to make a distinction from the legacy physics
  21. components, but the legacy components have been removed, and the new naming better reflects
  22. the modular design and intent to support other potential physics Gems.
  23. This function searches all folders below the O3DE root folder for .cpp, .h or .inl files, and
  24. replaces any instances of the old naming convention.
  25. '''
  26. def rename_physics_services():
  27. renamed_services = {
  28. "\"PhysXCharacterControllerService\"": "\"PhysicsCharacterControllerService\"",
  29. "\"PhysXCharacterGameplayService\"": "\"PhysicsCharacterGameplayService\"",
  30. "\"PhysXColliderService\"": "\"PhysicsColliderService\"",
  31. "\"PhysXEditorService\"": "\"PhysicsEditorService\"",
  32. "\"PhysXHeightfieldColliderService\"": "\"PhysicsHeightfieldColliderService\"",
  33. "\"PhysXJointService\"": "\"PhysicsJointService\"",
  34. "\"PhysXRagdollService\"": "\"PhysicsRagdollService\"",
  35. "\"PhysXRigidBodyService\"": "\"PhysicsRigidBodyService\"",
  36. "\"PhysXStaticRigidBodyService\"": "\"PhysicsStaticRigidBodyService\"",
  37. "\"PhysXDynamicRigidBodyService\"": "\"PhysicsDynamicRigidBodyService\"",
  38. "\"PhysXService\"": "\"PhysicsService\"",
  39. "\"PhysXShapeColliderService\"": "\"PhysicsShapeColliderService\"",
  40. "\"PhysXTriggerService\"": "\"PhysicsTriggerService\""
  41. }
  42. o3de_root = Path(__file__).parents[2]
  43. for root, dirs, files in os.walk(o3de_root):
  44. for filename in files:
  45. extension = os.path.splitext(filename)[1]
  46. if extension in [".h", ".cpp", ".inl"]:
  47. full_path = os.path.join(root, filename)
  48. file = open(full_path)
  49. lines = file.readlines()
  50. file.close()
  51. lines_changed = False
  52. for line_index in range(len(lines)):
  53. for old_service, new_service in renamed_services.items():
  54. if old_service in lines[line_index]:
  55. lines_changed = True
  56. lines[line_index] = lines[line_index].replace(old_service, new_service)
  57. lines[line_index] = crc_update(lines[line_index])
  58. if lines_changed:
  59. file = open(full_path, 'w')
  60. file.writelines(lines)
  61. file.close()
  62. if __name__ == "__main__":
  63. rename_physics_services()