Skip to content

Commit

Permalink
Merge branch 'v3.x' into v4.x-cross
Browse files Browse the repository at this point in the history
# Conflicts:
#	desktop/src/cn/harryh/arkpets/controllers/RootModule.java
  • Loading branch information
isHarryh committed Feb 17, 2025
2 parents 1c452ca + 344713c commit c83888d
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 58 deletions.
58 changes: 8 additions & 50 deletions assets/shaders/OutlineFragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ uniform vec4 u_shadowColor; // Required
uniform ivec2 u_textureSize; // Required
uniform float u_alpha; // Required

const float c_alphaLv0 = 0.1;
const float c_alphaLv1 = 0.4;
const float c_alphaLv2 = 0.9;
const float c_alphaLow = 0.1;
const float c_alphaHigh = 0.9;
const float c_seamCoef = 0.6;
const float c_outlineOverstate = 10.0;
const float c_shadowOffset = 2.0;
Expand All @@ -30,21 +29,6 @@ const float gaussianNeighborKernel[25] = float[25] (
0.0035434, 0.0158805, 0.0261825, 0.0158805, 0.0035434
);

vec4[24] getSimpleNeighbors(vec2 unitLength) {
vec4 neighbors[24];
int i = 0;
for (int y = -2; y <= 2; y++) {
for (int x = -2; x <= 2; x++) {
if (!(y == 0 && x == 0)) {
vec2 offset = vec2(x, y) * unitLength;
neighbors[i] = texture2D(u_texture, v_texCoords + offset);
i++;
}
}
}
return neighbors;
}

vec4[24] getGaussianNeighbors(vec2 unitLength) {
vec4 neighbors[24];
int ni = 0;
Expand Down Expand Up @@ -76,35 +60,14 @@ vec4 getOutlined() {
if (u_outlineColor.a > 0.0 && u_outlineWidth > 0.0 && u_outlineAlpha > 0.0) {
vec2 relOutlineWidth = vec2(1.0) / u_textureSize * u_outlineWidth;
vec4 neighbor = getGaussianNeighborsSum(relOutlineWidth) * c_outlineOverstate;
if (neighbor.a > c_alphaLv0) {
if (neighbor.a > c_alphaLow) {
texColor.rgb = u_outlineColor.rgb;
texColor.a = min(1.0, neighbor.a) * u_outlineColor.a * u_outlineAlpha;
}
}
return texColor;
}

vec4 getSeamed() {
vec4 texColor = texture2D(u_texture, v_texCoords);
vec2 relPixelSize = vec2(1.0) / u_textureSize;
vec4[24] neighbors = getSimpleNeighbors(relPixelSize);
vec4 sampleColor = vec4(0.0);
int sampleSize = 0;
for (int i = 0; i < neighbors.length(); i++) {
if (neighbors[i].a > c_alphaLv2) {
sampleColor += neighbors[i];
sampleSize++;
}
}
if (sampleSize > 0) {
texColor.rgb = mix(sampleColor.rgb / sampleSize, texColor.rgb, c_seamCoef);
texColor.a = min(1.0, texColor.a * 2.0);
} else {
texColor.a = c_alphaLv2;
}
return texColor;
}

vec4 getBoxShadow() {
if (u_shadowColor.a <= 0.0) {
return vec4(0.0);
Expand All @@ -117,20 +80,15 @@ vec4 getBoxShadow() {
void main() {
vec4 texColor = texture2D(u_texture, v_texCoords);

if (texColor.a < c_alphaLv2) {
if (texColor.a < c_alphaLv0) {
// Outline effect apply on transparent areas
if (texColor.a < c_alphaHigh) {
if (texColor.a < c_alphaLow) {
// Outline effect
texColor = getOutlined();
} else if (texColor.a < c_alphaLv1) {
// No effect apply on these areas
} else {
// Seaming apply on gap areas
texColor = getSeamed();
}
// Box shadow
// Box shadow effect
texColor = mix(getBoxShadow(), texColor, texColor.a);
} else {
// No effect apply on other areas
// No effect
}

// Ultimate composing
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ allprojects {
apply plugin: "java-library"
apply plugin: "org.openjfx.javafxplugin"

version = "3.6.0"
version = "3.7.0"
ext {
// App Metadata
appName = "ArkPets"
Expand Down
5 changes: 2 additions & 3 deletions core/src/cn/harryh/arkpets/ArkChar.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ public ArkChar(ArkConfig config, float scale) {
camera.setMinInsert(canvasReserveLength - canvasMaxSize);
batch = new TwoColorPolygonBatch();
renderer = new SkeletonRenderer();
/* Pre-multiplied alpha shouldn't be applied to models released in Arknights 2.1.41 or later,
otherwise you may get a corrupted rendering result. */
renderer.setPremultipliedAlpha(false);
renderer.setPremultipliedAlpha(true);
/* Shader pedantic should be disabled to avoid uniform not-found error. */
ShaderProgram.pedantic = false;
shader1 = getShader(pass1VShader, pass1FShader);
Expand Down Expand Up @@ -256,6 +254,7 @@ protected void renderToBatch() {
batch.setShader(shader2);
ScreenUtils.clear(0, 0, 0, 0, true);
batch.begin();
batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
batch.draw(bgTexture, 0, 0);
batch.draw(passedTexture,
0, 0, 0, 0, camera.getWidth(), camera.getHeight(),
Expand Down
2 changes: 1 addition & 1 deletion core/src/cn/harryh/arkpets/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public final class Const {
// App version
public static final Version appVersion = new Version(3, 6, 0);
public static final Version appVersion = new Version(3, 7, 0);
public static final Version datasetLowestVersion = new Version(2, 2, 0);

// App name
Expand Down
19 changes: 17 additions & 2 deletions desktop/src/cn/harryh/arkpets/controllers/RootModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import cn.harryh.arkpets.concurrent.ProcessPool;
import cn.harryh.arkpets.guitasks.CheckAppUpdateTask;
import cn.harryh.arkpets.guitasks.CheckEnvironmentTask;
import cn.harryh.arkpets.guitasks.DeleteTempFilesTask;
import cn.harryh.arkpets.guitasks.GuiTask;
import cn.harryh.arkpets.envchecker.EnvCheckTask;
import cn.harryh.arkpets.utils.ArgPending;
Expand Down Expand Up @@ -182,12 +183,26 @@ public void syncRemoteMetaInfo() {
new CheckAppUpdateTask(app.body, GuiTask.GuiTaskStyle.HIDDEN, "auto").start();
}

/** Plays the exit animation and then invokes {@link Platform#exit()}.
/** Plays the exit animation, deletes temp files, then invokes {@link Platform#exit()}.
*/
public void exit() {
popSplashScreen(e -> {
Logger.info("Launcher", "User close request");
GuiPrefabs.fadeOutWindow(app.stage, durationNormal, ev -> Platform.exit());
GuiPrefabs.fadeOutWindow(
app.stage,
durationNormal,
ev -> new DeleteTempFilesTask(app.body, GuiTask.GuiTaskStyle.HIDDEN, ".+", 24 * 3600000) {
@Override
protected void onFailed(Throwable e) {
Platform.exit();
}

@Override
protected void onSucceeded(boolean result) {
Platform.exit();
}
}.start()
);
}, durationFast, durationNormal);
}

Expand Down
73 changes: 73 additions & 0 deletions desktop/src/cn/harryh/arkpets/guitasks/DeleteTempFilesTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/** Copyright (c) 2022-2025, Harry Huang
* At GPL-3.0 License
*/
package cn.harryh.arkpets.guitasks;

import cn.harryh.arkpets.Const.PathConfig;
import cn.harryh.arkpets.utils.IOUtils.FileUtil;
import javafx.concurrent.Task;
import javafx.scene.layout.StackPane;

import java.io.File;
import java.nio.file.*;
import java.util.List;
import java.util.stream.Stream;
import java.util.regex.Pattern;


public abstract class DeleteTempFilesTask extends GuiTask {
protected final Pattern regex;
protected final long timestamp;

public DeleteTempFilesTask(StackPane parent, GuiTaskStyle style, String matchRegex, long beforeMillis) {
super(parent, style);
this.regex = Pattern.compile(matchRegex);
this.timestamp = System.currentTimeMillis() - beforeMillis;
}

@Override
protected Task<Boolean> getTask() {
return new Task<>() {
@Override
protected Boolean call() throws Exception {
File temp = new File(PathConfig.tempDirPath);
if (!temp.isDirectory()) {
return true;
}

List<Path> filesToDelete;
try (Stream<Path> pathStream = Files.walk(temp.toPath())) {
filesToDelete = pathStream
.filter(path -> {
File file = path.toFile();
return file.isFile()
&& regex.matcher(file.getName()).matches()
&& file.lastModified() < timestamp;
})
.toList();
}

int total = filesToDelete.size();
if (total == 0) {
return true;
}

this.updateProgress(0, total);
for (int i = 0; i < filesToDelete.size(); i++) {
if (isCancelled()) {
break;
}
FileUtil.delete(filesToDelete.get(i), true);
updateProgress(i + 1, total);
}

return !isCancelled();
}
};
}

@Override
protected String getHeader() {
return "正在清理临时文件...";
}
}
2 changes: 1 addition & 1 deletion docs/scripts/ExePacking.iss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
; Download Inno Setup: https://jrsoftware.org/isdl.php

#define MyAppName "ArkPets"
#define MyAppVersion "3.6.0"
#define MyAppVersion "3.7.0"
#define MyAppPublisher "Harry Huang"
#define MyAppURL "https://arkpets.harryh.cn/"

Expand Down

0 comments on commit c83888d

Please sign in to comment.