Closed r0man1337 closed 3 months ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
eternum | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jun 20, 2024 8:51am |
⏱️ Estimated effort to review [1-5] | 4 |
🧪 Relevant tests | No |
🔒 Security concerns | No |
⚡ Key issues to review |
Performance Concern: The use of instanced meshes and the manipulation of matrix transformations in InstancedBanks and InstancedCastles are performance-critical areas. Reviewers should ensure that these operations are optimized and do not introduce memory leaks or excessive re-computation. |
Code Duplication: There is a noticeable amount of duplicated logic between InstancedBanks and InstancedCastles , particularly in how instances are created and transformed. Consider abstracting common functionality into a shared utility or base component. | |
Hardcoded Values: Several hardcoded values (e.g., matrix transformations, geometry manipulations) are used in the new components. It's advisable to define these as constants or retrieve them from a configuration to enhance maintainability and flexibility. |
Category | Suggestion | Score |
Best practice |
Add cleanup for hitBoxMeshes to prevent memory leaks___ **To ensure that the hitBoxMeshes are correctly cleaned up to prevent memory leaks, consideradding a cleanup function in the useEffect where hitBoxInstances are set.**
[client/src/ui/components/worldmap/Flags.jsx [197]](https://github.com/BibliothecaDAO/eternum/pull/961/files#diff-363ae1ff924f5e9c661aafb937b8548d4f7f0b0a563a5bbaa209c010cf5ffbe9R197-R197)
```diff
-setHitBoxInstances(hitBoxMeshes);
+useEffect(() => {
+ setHitBoxInstances(hitBoxMeshes);
+ return () => hitBoxMeshes.forEach(mesh => mesh.dispose());
+}, [hitBoxMeshes]);
```
Suggestion importance[1-10]: 10Why: Adding a cleanup function in the useEffect hook is crucial for preventing memory leaks, ensuring that hitBoxMeshes are correctly disposed of when the component unmounts. | 10 |
Improve type safety by specifying a more accurate type than
___
**Consider using a more specific type for the | 7 | |
Performance |
Improve performance and maintainability by managing graphics settings through state or context___ **Instead of directly checkinglocalStorage in the render method, use a state or context to manage the graphics settings. This approach avoids potential performance issues and ensures better reactivity and encapsulation.** [client/src/ui/modules/scenes/MainScene.tsx [130]](https://github.com/BibliothecaDAO/eternum/pull/961/files#diff-fc21828fcac93c01c5fc8d97c5f4206af9199daaf1230bc6a1b1a24d20bd50c8R130-R130) ```diff -{!localStorage.getItem("LOW_GRAPHICS_FLAG") && ( +{!isLowGraphics && ( ``` Suggestion importance[1-10]: 9Why: Using state or context to manage graphics settings instead of directly checking `localStorage` in the render method improves performance and ensures better reactivity and encapsulation. | 9 |
Improve performance by using useMemo for initializing hitBoxInstances___ **Consider initializinghitBoxInstances with a useMemo hook to ensure that the instances are only recalculated when ordersRealms changes, which is more efficient than recalculating on every render.** [client/src/ui/components/worldmap/Flags.jsx [57]](https://github.com/BibliothecaDAO/eternum/pull/961/files#diff-363ae1ff924f5e9c661aafb937b8548d4f7f0b0a563a5bbaa209c010cf5ffbe9R57-R57) ```diff -const [hitBoxInstances, setHitBoxInstances] = useState([]); +const hitBoxInstances = useMemo(() => ordersRealms.map(orderRealm => new THREE.InstancedMesh(hitBoxGeometry, hitBoxMaterial, orderRealm.length)), [ordersRealms]); ``` Suggestion importance[1-10]: 9Why: Using useMemo for initializing hitBoxInstances ensures that the instances are only recalculated when ordersRealms changes, which improves performance by avoiding unnecessary recalculations on every render. | 9 | |
Optimize resource usage and performance by memoizing the
___
**To prevent potential memory leaks or unnecessary re-renders, consider wrapping the | 8 | |
Enhancement |
Enhance user experience and application responsiveness by using state management for graphics settings___ **Use a more reactive approach to handle changes in graphics settings by using statemanagement instead of directly manipulating localStorage and reloading the page.**
[client/src/ui/modules/settings/Settings.tsx [86-87]](https://github.com/BibliothecaDAO/eternum/pull/961/files#diff-7fa22706f986ed33da69c4d0952bac0d4f9404336cbe235f93c09014a75a0cddR86-R87)
```diff
-localStorage.setItem("LOW_GRAPHICS_FLAG", "true");
-window.location.reload();
+setGraphicsSetting("low"); // Assume setGraphicsSetting is a function that updates the state and is properly handled in the application.
```
Suggestion importance[1-10]: 9Why: Using state management for graphics settings instead of directly manipulating `localStorage` and reloading the page provides a more reactive and user-friendly approach, enhancing the overall user experience. | 9 |
Possible bug |
Add error handling for undefined instanceId to avoid runtime errors___ **It's recommended to add error handling forinstanceId retrieval to avoid potential runtime errors if instanceId is undefined.**
[client/src/ui/components/worldmap/Flags.jsx [227]](https://github.com/BibliothecaDAO/eternum/pull/961/files#diff-363ae1ff924f5e9c661aafb937b8548d4f7f0b0a563a5bbaa209c010cf5ffbe9R227-R227)
```diff
-const instanceId = e.instanceId;
+const instanceId = e.instanceId || 0; // Default to 0 or handle appropriately if undefined
```
Suggestion importance[1-10]: 8Why: Adding error handling for instanceId retrieval helps avoid potential runtime errors if instanceId is undefined, improving the robustness of the code. | 8 |
Maintainability |
Extract repeated JSX groups into a separate React component for better maintainability___ **To improve the readability and maintainability of the JSX structure, consider extractingthe repeated group component into a separate React component.** [client/src/ui/components/worldmap/Flags.jsx [250-262]](https://github.com/BibliothecaDAO/eternum/pull/961/files#diff-363ae1ff924f5e9c661aafb937b8548d4f7f0b0a563a5bbaa209c010cf5ffbe9R250-R262) ```diff -<> - Suggestion importance[1-10]: 7Why: Extracting the repeated JSX groups into a separate React component improves the readability and maintainability of the code, making it easier to manage and understand. | 7 |
User description
PR Type
Enhancement, Bug fix
Description
InstancedBanks
andInstancedCastles
components for optimized rendering of banks and castles using instanced meshes.SelectedUnit
component toUnitHighlight
and updated relevant references.LOW_GRAPHICS_FLAG
.WorldMapScene
.Changes walkthrough 📝
8 files
InstancedBanks.tsx
Add `InstancedBanks` component for optimized bank rendering.
client/src/ui/components/models/buildings/worldmap/InstancedBanks.tsx
InstancedBanks
for rendering banks using instancedmeshes.
useGLTF
for loading bank models.InstancedCastles.tsx
Add `InstancedCastles` component for optimized castle rendering.
client/src/ui/components/models/buildings/worldmap/InstancedCastles.tsx
InstancedCastles
for rendering castles usinginstanced meshes.
useGLTF
for loading castle models.Structures.tsx
Integrate instanced components and refactor structure rendering.
client/src/ui/components/models/buildings/worldmap/Structures.tsx
InstancedCastles
andInstancedBanks
components.ArmyInfoLabel.tsx
Add distance factor to army info label.
client/src/ui/components/worldmap/armies/ArmyInfoLabel.tsx - Added `distanceFactor` property to `BaseThreeTooltip`.
WorldHexagon.tsx
Remove unused `ShardsMines` import.
client/src/ui/components/worldmap/hexagon/WorldHexagon.tsx - Removed `ShardsMines` import.
MainScene.tsx
Add support for low graphics settings.
client/src/ui/modules/scenes/MainScene.tsx
LOW_GRAPHICS_FLAG
.Settings.tsx
Add UI for graphics settings toggle.
client/src/ui/modules/settings/Settings.tsx - Added UI for toggling low and high graphics settings.
Flags.jsx
Add hitbox instances and improve tooltip rendering.
client/src/ui/components/worldmap/Flags.jsx
5 files
Army.tsx
Rename `SelectedUnit` to `UnitHighlight`.
client/src/ui/components/worldmap/armies/Army.tsx - Renamed `SelectedUnit` component to `UnitHighlight`.
UnitHighlight.tsx
Rename `SelectedUnit` component and props.
client/src/ui/components/worldmap/hexagon/UnitHighlight.tsx
SelectedUnitProps
toUnitHighlightProps
.SelectedUnit
component toUnitHighlight
.LeftNavigationModule.tsx
Remove auto-close functionality from left navigation.
client/src/ui/modules/navigation/LeftNavigationModule.tsx - Removed auto-close functionality for left navigation.
RightNavigationModule.tsx
Remove auto-close functionality from right navigation.
client/src/ui/modules/navigation/RightNavigationModule.tsx - Removed auto-close functionality for right navigation.
WorldMapScene.tsx
Fix shadow camera bounds for directional light.
client/src/ui/modules/scenes/WorldMapScene.tsx - Fixed shadow camera bounds for directional light.