From 2278c5d0c7d0d97ddb52a5a9e8728f19088ec39d Mon Sep 17 00:00:00 2001 From: tzdwindows 7 <3076584115@qq.com> Date: Wed, 22 Oct 2025 22:33:15 +0800 Subject: [PATCH] =?UTF-8?q?chore(build):=20=E6=9B=B4=E6=96=B0=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E8=84=9A=E6=9C=AC=E5=B9=B6=E4=BC=98=E5=8C=96=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E5=8E=86=E5=8F=B2=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 runClient任务组和描述信息 - 添加多个 2D 模型测试任务 (test2DModelLayerPanel, testModelRenderLightingTest 等) - 替换 System.out.println 日志为 SLF4J Logger 实现 - 移除冗余的日志打印和注释代码 - 统一使用占位符方式记录日志信息 - 注册和注销操作类型时增加日志跟踪 - 完善操作监听器添加与移除的日志提示 -优化异常处理中的错误日志输出 --- build.gradle | 44 ++++- .../awt/util/OperationHistoryGlobal.java | 150 ++++-------------- .../vivid2D/test/ModelLayerPanelTest.java | 10 +- 3 files changed, 74 insertions(+), 130 deletions(-) diff --git a/build.gradle b/build.gradle index 8de67fc..0cbe446 100644 --- a/build.gradle +++ b/build.gradle @@ -191,8 +191,8 @@ application { } task runClient(type: JavaExec) { - group = "application" - description = "运行 com.axis.innovators.box.Main" + group = "run-toolboxProgram" + description = "执行工具箱程序" classpath = sourceSets.main.runtimeClasspath mainClass = "com.axis.innovators.box.Main" jvmArgs = [ @@ -200,3 +200,43 @@ task runClient(type: JavaExec) { "-Djava.system.class.loader=com.axis.innovators.box.plugins.BoxClassLoader" ] } + +task test2DModelLayerPanel(type: JavaExec) { + group = "test-model" + description = "运行 2D Model Layer Panel 测试" + classpath = sourceSets.main.runtimeClasspath + mainClass = "com.chuangzhou.vivid2D.test.ModelLayerPanelTest" + jvmArgs = [ + "-Dfile.encoding=UTF-8" + ] +} + +task testModelRenderLightingTest(type: JavaExec) { + group = "test-model" + description = "运行 2D Model 高亮灯光测试" + classpath = sourceSets.main.runtimeClasspath + mainClass = "com.chuangzhou.vivid2D.test.ModelRenderLightingTest" + jvmArgs = [ + "-Dfile.encoding=UTF-8" + ] +} + +task testModelTest(type: JavaExec) { + group = "test-model" + description = "运行 2D Model 保存和完整性测试" + classpath = sourceSets.main.runtimeClasspath + mainClass = "com.chuangzhou.vivid2D.test.ModelTest" + jvmArgs = [ + "-Dfile.encoding=UTF-8" + ] +} + +task testModelTest2(type: JavaExec) { + group = "test-model" + description = "运行 2D Model 物理基准测试" + classpath = sourceSets.main.runtimeClasspath + mainClass = "com.chuangzhou.vivid2D.test.ModelTest2" + jvmArgs = [ + "-Dfile.encoding=UTF-8" + ] +} \ No newline at end of file diff --git a/src/main/java/com/chuangzhou/vivid2D/render/awt/util/OperationHistoryGlobal.java b/src/main/java/com/chuangzhou/vivid2D/render/awt/util/OperationHistoryGlobal.java index fec31f4..1dc57f3 100644 --- a/src/main/java/com/chuangzhou/vivid2D/render/awt/util/OperationHistoryGlobal.java +++ b/src/main/java/com/chuangzhou/vivid2D/render/awt/util/OperationHistoryGlobal.java @@ -3,6 +3,8 @@ package com.chuangzhou.vivid2D.render.awt.util; import com.chuangzhou.vivid2D.render.model.ModelPart; import com.chuangzhou.vivid2D.render.model.util.Mesh2D; import org.joml.Vector2f; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; @@ -15,6 +17,8 @@ import java.util.concurrent.CopyOnWriteArrayList; */ public class OperationHistoryGlobal { + private static final Logger LOGGER = LoggerFactory.getLogger(OperationHistoryGlobal.class); + // 单例实例 private static final OperationHistoryGlobal INSTANCE = new OperationHistoryGlobal(); @@ -58,7 +62,7 @@ public class OperationHistoryGlobal { * 初始化基础操作记录器 */ private void initializeBasicRecorders() { - System.out.println("开始初始化基础操作记录器..."); + LOGGER.debug("开始初始化基础操作记录器..."); // 基础变换操作 registerOperationRecorder("SET_POSITION", new OperationRecorder() { @@ -442,7 +446,7 @@ public class OperationHistoryGlobal { } }); - System.out.println("基础操作记录器初始化完成,共注册 " + registeredOperations.size() + " 个操作类型"); + LOGGER.info("基础操作记录器初始化完成,共注册 {} 个操作类型", registeredOperations.size()); } /** @@ -484,12 +488,6 @@ public class OperationHistoryGlobal { // 标记已处理的操作类型 handledOperations.add(operationType); - - // 输出调试信息 - if (isDebugEnabled()) { - System.out.printf("默认监听器处理: %s - %s (参数数: %d)%n", - operationType, action, params != null ? params.length : 0); - } } private void handleRecordEvent(String operationType, Object... params) { @@ -550,7 +548,7 @@ public class OperationHistoryGlobal { handleBatchTransformRecord(params); break; default: - System.out.println("记录操作: " + operationType); + LOGGER.debug("记录操作: {}", operationType); break; } } @@ -592,7 +590,7 @@ public class OperationHistoryGlobal { executeBatchTransform(params); break; default: - System.out.println("执行操作: " + operationType); + LOGGER.debug("执行操作: {}", operationType); break; } } @@ -646,8 +644,6 @@ public class OperationHistoryGlobal { ModelPart part = (ModelPart) params[0]; Object[] oldValues = (Object[]) params[1]; Object[] newValues = (Object[]) params[2]; - - System.out.printf("记录批量变换: %s (位置、旋转、缩放、中心点)%n", part.getName()); } } @@ -669,7 +665,7 @@ public class OperationHistoryGlobal { part.setPivot(newPivot.x, newPivot.y); } - System.out.println("重做批量变换: " + part.getName()); + LOGGER.debug("重做批量变换: {}", part.getName()); } } @@ -691,7 +687,7 @@ public class OperationHistoryGlobal { part.setPivot(oldPivot.x, oldPivot.y); } - System.out.println("撤回批量变换: " + part.getName()); + LOGGER.debug("撤回批量变换: {}", part.getName()); } } @@ -705,11 +701,11 @@ public class OperationHistoryGlobal { operationCounts.clear(); handledOperations.clear(); operationContext.clear(); - System.out.println("操作历史已清空"); + LOGGER.debug("操作历史已清空"); } private void handleUnknownEvent(String operationType, String action, Object... params) { - System.out.println("未知操作事件: " + operationType + " - " + action); + LOGGER.debug("未知操作事件: {} - {}", operationType, action); } // ============ 新增的拖拽结束操作方法 ============ @@ -733,45 +729,19 @@ public class OperationHistoryGlobal { if (params.length >= 2) { List parts = (List) params[0]; Map startScales = (Map) params[1]; - - System.out.printf("记录调整大小结束: %d 个部件从起始缩放调整%n", parts.size()); for (ModelPart part : parts) { Vector2f startScale = startScales.get(part); Vector2f currentScale = part.getScale(); - System.out.printf(" 部件 %s: (%.2f,%.2f) -> (%.2f,%.2f)%n", + LOGGER.debug(" 部件 %s: (%.2f,%.2f) -> (%.2f,%.2f)%n", part.getName(), startScale.x, startScale.y, currentScale.x, currentScale.y); } } } private void handleRotatePartEndRecord(Object... params) { - if (params.length >= 2) { - List parts = (List) params[0]; - Map startRotations = (Map) params[1]; - - System.out.printf("记录旋转结束: %d 个部件从起始旋转角度调整%n", parts.size()); - for (ModelPart part : parts) { - float startRotation = startRotations.get(part); - float currentRotation = part.getRotation(); - System.out.printf(" 部件 %s: %.1f° -> %.1f°%n", - part.getName(), Math.toDegrees(startRotation), Math.toDegrees(currentRotation)); - } - } } private void handleMovePivotEndRecord(Object... params) { - if (params.length >= 2) { - List parts = (List) params[0]; - Map startPivots = (Map) params[1]; - - System.out.printf("记录移动中心点结束: %d 个部件从起始中心点移动%n", parts.size()); - for (ModelPart part : parts) { - Vector2f startPivot = startPivots.get(part); - Vector2f currentPivot = part.getPivot(); - System.out.printf(" 部件 %s: (%.1f,%.1f) -> (%.1f,%.1f)%n", - part.getName(), startPivot.x, startPivot.y, currentPivot.x, currentPivot.y); - } - } } private void executeDragPartEnd(Object... params) { @@ -786,7 +756,7 @@ public class OperationHistoryGlobal { paramIndex++; } } - System.out.println("重做拖拽结束操作"); + LOGGER.debug("重做拖拽结束操作"); } } @@ -802,7 +772,7 @@ public class OperationHistoryGlobal { paramIndex++; } } - System.out.println("重做调整大小结束操作"); + LOGGER.debug("重做调整大小结束操作"); } } @@ -818,7 +788,7 @@ public class OperationHistoryGlobal { paramIndex++; } } - System.out.println("重做旋转结束操作"); + LOGGER.debug("重做旋转结束操作"); } } @@ -834,7 +804,7 @@ public class OperationHistoryGlobal { paramIndex++; } } - System.out.println("重做移动中心点结束操作"); + LOGGER.debug("重做移动中心点结束操作"); } } @@ -864,7 +834,7 @@ public class OperationHistoryGlobal { part.setScale(startScale.x, startScale.y); } } - System.out.println("撤回调整大小结束操作"); + LOGGER.debug("撤回调整大小结束操作"); } } @@ -879,7 +849,7 @@ public class OperationHistoryGlobal { part.setRotation(startRotation); } } - System.out.println("撤回旋转结束操作"); + LOGGER.debug("撤回旋转结束操作"); } } @@ -894,7 +864,7 @@ public class OperationHistoryGlobal { part.setPivot(startPivot.x, startPivot.y); } } - System.out.println("撤回移动中心点结束操作"); + LOGGER.debug("撤回移动中心点结束操作"); } } @@ -910,9 +880,6 @@ public class OperationHistoryGlobal { // 保存撤回信息 String key = "position_undo_" + part.getName(); operationContext.put(key, oldPosition); - - System.out.printf("记录位置变化: %s (%.1f,%.1f) -> (%.1f,%.1f)%n", - part.getName(), oldPosition.x, oldPosition.y, newPosition.x, newPosition.y); } } @@ -921,7 +888,6 @@ public class OperationHistoryGlobal { ModelPart part = (ModelPart) params[0]; Vector2f newPosition = (Vector2f) params[2]; part.setPosition(newPosition.x, newPosition.y); - System.out.println("重做位置变化: " + part.getName()); } } @@ -930,7 +896,6 @@ public class OperationHistoryGlobal { ModelPart part = (ModelPart) params[0]; Vector2f oldPosition = (Vector2f) params[1]; part.setPosition(oldPosition.x, oldPosition.y); - System.out.println("撤回位置变化: " + part.getName()); } } @@ -942,9 +907,6 @@ public class OperationHistoryGlobal { String key = "rotation_undo_" + part.getName(); operationContext.put(key, oldRotation); - - System.out.printf("记录旋转变化: %s %.1f° -> %.1f°%n", - part.getName(), Math.toDegrees(oldRotation), Math.toDegrees(newRotation)); } } @@ -953,7 +915,6 @@ public class OperationHistoryGlobal { ModelPart part = (ModelPart) params[0]; float newRotation = (Float) params[2]; part.setRotation(newRotation); - System.out.println("重做旋转变化: " + part.getName()); } } @@ -962,7 +923,6 @@ public class OperationHistoryGlobal { ModelPart part = (ModelPart) params[0]; float oldRotation = (Float) params[1]; part.setRotation(oldRotation); - System.out.println("撤回旋转变化: " + part.getName()); } } @@ -974,9 +934,6 @@ public class OperationHistoryGlobal { String key = "scale_undo_" + part.getName(); operationContext.put(key, oldScale); - - System.out.printf("记录缩放变化: %s (%.2f,%.2f) -> (%.2f,%.2f)%n", - part.getName(), oldScale.x, oldScale.y, newScale.x, newScale.y); } } @@ -985,7 +942,6 @@ public class OperationHistoryGlobal { ModelPart part = (ModelPart) params[0]; Vector2f newScale = (Vector2f) params[2]; part.setScale(newScale.x, newScale.y); - System.out.println("重做缩放变化: " + part.getName()); } } @@ -994,7 +950,6 @@ public class OperationHistoryGlobal { ModelPart part = (ModelPart) params[0]; Vector2f oldScale = (Vector2f) params[1]; part.setScale(oldScale.x, oldScale.y); - System.out.println("撤回缩放变化: " + part.getName()); } } @@ -1006,9 +961,6 @@ public class OperationHistoryGlobal { String key = "opacity_undo_" + part.getName(); operationContext.put(key, oldOpacity); - - System.out.printf("记录不透明度变化: %s %.1f -> %.1f%n", - part.getName(), oldOpacity, newOpacity); } } @@ -1017,7 +969,6 @@ public class OperationHistoryGlobal { ModelPart part = (ModelPart) params[0]; float newOpacity = (Float) params[2]; part.setOpacity(newOpacity); - System.out.println("重做不透明度变化: " + part.getName()); } } @@ -1026,7 +977,6 @@ public class OperationHistoryGlobal { ModelPart part = (ModelPart) params[0]; float oldOpacity = (Float) params[1]; part.setOpacity(oldOpacity); - System.out.println("撤回不透明度变化: " + part.getName()); } } @@ -1038,9 +988,6 @@ public class OperationHistoryGlobal { String key = "visible_undo_" + part.getName(); operationContext.put(key, oldVisible); - - System.out.printf("记录可见性变化: %s %s -> %s%n", - part.getName(), oldVisible ? "显示" : "隐藏", newVisible ? "显示" : "隐藏"); } } @@ -1049,7 +996,6 @@ public class OperationHistoryGlobal { ModelPart part = (ModelPart) params[0]; boolean newVisible = (Boolean) params[2]; part.setVisible(newVisible); - System.out.println("重做可见性变化: " + part.getName()); } } @@ -1058,7 +1004,6 @@ public class OperationHistoryGlobal { ModelPart part = (ModelPart) params[0]; boolean oldVisible = (Boolean) params[1]; part.setVisible(oldVisible); - System.out.println("撤回可见性变化: " + part.getName()); } } @@ -1070,9 +1015,6 @@ public class OperationHistoryGlobal { String key = "pivot_undo_" + part.getName(); operationContext.put(key, oldPivot); - - System.out.printf("记录中心点变化: %s (%.1f,%.1f) -> (%.1f,%.1f)%n", - part.getName(), oldPivot.x, oldPivot.y, newPivot.x, newPivot.y); } } @@ -1081,7 +1023,6 @@ public class OperationHistoryGlobal { ModelPart part = (ModelPart) params[0]; Vector2f newPivot = (Vector2f) params[2]; part.setPivot(newPivot.x, newPivot.y); - System.out.println("重做中心点变化: " + part.getName()); } } @@ -1090,63 +1031,28 @@ public class OperationHistoryGlobal { ModelPart part = (ModelPart) params[0]; Vector2f oldPivot = (Vector2f) params[1]; part.setPivot(oldPivot.x, oldPivot.y); - System.out.println("撤回中心点变化: " + part.getName()); } } private void handleAddPartRecord(Object... params) { - if (params.length >= 1 && params[0] instanceof ModelPart) { - ModelPart part = (ModelPart) params[0]; - System.out.println("记录添加图层: " + part.getName()); - } } private void handleRemovePartRecord(Object... params) { - if (params.length >= 1 && params[0] instanceof MeshState) { - MeshState state = (MeshState) params[0]; - System.out.println("记录删除图层: " + state.name); - } } private void handleRenamePartRecord(Object... params) { - if (params.length >= 3 && params[0] instanceof ModelPart) { - ModelPart part = (ModelPart) params[0]; - String oldName = (String) params[1]; - String newName = (String) params[2]; - System.out.printf("记录重命名: %s -> %s%n", oldName, newName); - } } private void handleDragPartRecord(Object... params) { - if (params.length >= 3 && params[0] instanceof ModelPart) { - ModelPart part = (ModelPart) params[0]; - Vector2f startPos = (Vector2f) params[1]; - Vector2f endPos = (Vector2f) params[2]; - System.out.printf("记录拖拽: %s (%.1f,%.1f) -> (%.1f,%.1f)%n", - part.getName(), startPos.x, startPos.y, endPos.x, endPos.y); - } } private void handleAddMeshRecord(Object... params) { - if (params.length >= 1 && params[0] instanceof Mesh2D) { - Mesh2D mesh = (Mesh2D) params[0]; - System.out.println("记录添加网格: " + mesh.getName()); - } } private void handleRemoveMeshRecord(Object... params) { - if (params.length >= 1 && params[0] instanceof MeshState) { - MeshState state = (MeshState) params[0]; - System.out.println("记录删除网格: " + state.name); - } } private void handleBindTextureRecord(Object... params) { - System.out.println("记录绑定纹理操作"); - } - - private boolean isDebugEnabled() { - return Boolean.getBoolean("operation.history.debug"); } /** @@ -1252,7 +1158,7 @@ public class OperationHistoryGlobal { historyManager.registerRecorder(operationType, recorder); } - System.out.println("已注册操作类型: " + operationType); + LOGGER.debug("已注册操作类型: {}", operationType); } /** @@ -1262,9 +1168,7 @@ public class OperationHistoryGlobal { if (operationType != null) { registeredOperations.remove(operationType); recorderMap.remove(operationType); - - // 注意:这里不从历史管理器中移除,因为历史管理器可能需要处理已有的操作记录 - System.out.println("已注销操作类型: " + operationType); + LOGGER.debug("已注销操作类型: {}", operationType); } } @@ -1273,7 +1177,7 @@ public class OperationHistoryGlobal { */ public void recordOperation(String operationType, Object... params) { if (!isOperationRegistered(operationType)) { - System.err.println("未注册的操作类型: " + operationType); + LOGGER.warn("未注册的操作类型: {}", operationType); return; } @@ -1308,7 +1212,7 @@ public class OperationHistoryGlobal { if (success) { String description = historyManager.getRedoDescription(); notifyListeners("SYSTEM", "redo", description); - System.out.println("重做操作: " + description); + LOGGER.debug("重做操作: {}", description); } return success; } @@ -1321,7 +1225,7 @@ public class OperationHistoryGlobal { public void addOperationListener(OperationListener listener) { if (listener != null && !listeners.contains(listener)) { listeners.add(listener); - System.out.println("已添加操作监听器: " + listener.getClass().getSimpleName()); + LOGGER.debug("已添加操作监听器: {}", listener.getClass().getSimpleName()); } } @@ -1330,7 +1234,7 @@ public class OperationHistoryGlobal { */ public void removeOperationListener(OperationListener listener) { if (listeners.remove(listener)) { - System.out.println("已移除操作监听器: " + listener.getClass().getSimpleName()); + LOGGER.debug("已移除操作监听器: {}", listener.getClass().getSimpleName()); } } @@ -1349,7 +1253,7 @@ public class OperationHistoryGlobal { try { listener.onOperationEvent(operationType, action, params); } catch (Exception e) { - System.err.println("操作监听器执行失败: " + e.getMessage()); + LOGGER.error("操作监听器执行失败: {}", e.getMessage()); e.printStackTrace(); } } diff --git a/src/main/java/com/chuangzhou/vivid2D/test/ModelLayerPanelTest.java b/src/main/java/com/chuangzhou/vivid2D/test/ModelLayerPanelTest.java index f3f55fc..ea4e212 100644 --- a/src/main/java/com/chuangzhou/vivid2D/test/ModelLayerPanelTest.java +++ b/src/main/java/com/chuangzhou/vivid2D/test/ModelLayerPanelTest.java @@ -126,11 +126,11 @@ public class ModelLayerPanelTest { @Override public void windowClosing(java.awt.event.WindowEvent e) { // 先释放渲染面板相关 GL 资源与线程 - try { - renderPanel.dispose(); - } catch (Throwable t) { - t.printStackTrace(); - } + //try { + // renderPanel.dispose(); + //} catch (Throwable t) { + // t.printStackTrace(); + //} } @Override