Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Commit fd52b4a

Browse files
committed
refactor: optimize color assignment logic for brick spawning
Refactor the color assignment process by replacing the loop with System.arraycopy for improved performance. Clear world properties before setting new values to ensure a clean state.
1 parent 97981a8 commit fd52b4a

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

src/main/java/com/github/codestorm/bounceverse/systems/init/GameSystem.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ public void onSave(@NotNull DataFile dataFile) {
6262
final int level = properties.getInt("level");
6363
final int seed = properties.getInt("seed");
6464

65-
// TODO: Save map
66-
6765
final var bundle = new Bundle("game");
6866
bundle.put("lives", lives.getValue());
6967
bundle.put("score", score);
@@ -83,6 +81,7 @@ public void onLoad(@NotNull DataFile dataFile) {
8381
final int seed = bundle.get("seed");
8482

8583
final var vars = FXGL.getWorldProperties();
84+
vars.clear();
8685
vars.setValue("lives", lives);
8786
vars.setValue("score", score);
8887
vars.setValue("level", level);
@@ -119,6 +118,7 @@ public static void hookDeathSubscene() {
119118
FXGL.getSceneService().popSubScene();
120119
FXGL.getGameController().resumeEngine();
121120
});
121+
122122
FXGL.getSceneService().pushSubScene(deathSubscene);
123123
FXGL.getGameController().pauseEngine();
124124
});
@@ -221,9 +221,7 @@ record Cell(int gx, int gy, double x, double y, float n) {}
221221
var colorAssignments = new Color[target];
222222

223223
// Bước 1: Gán mỗi màu cho ít nhất một brick
224-
for (var i = 0; i < Math.min(colors.length, target); i++) {
225-
colorAssignments[i] = colors[i];
226-
}
224+
System.arraycopy(colors, 0, colorAssignments, 0, Math.min(colors.length, target));
227225

228226
// Bước 2: Phân phối các brick còn lại dựa trên noise
229227
for (var i = colors.length; i < target; i++) {
@@ -346,7 +344,6 @@ public void addAll() {
346344
if (isInitialized) {
347345
return;
348346
}
349-
// TODO: issue sau khi reset màn chơi thì không thêm lại UI
350347

351348
addScoreDisplay();
352349
addHeartsDisplay();

0 commit comments

Comments
 (0)