Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
/src/test/skriptparticle/
CLAUDE.md
/.claude
/shapes-lib/build
/skript-particle/build
/shapes-lib/build/
/skript-particle/build/
/skript-particle/.gradle/
/net/minecraft/network
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
41 changes: 28 additions & 13 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven {
url 'https://repo.papermc.io/repository/maven-public/'
}
}
}

rootProject.name = 'skript-particle-root'
include 'shapes-lib', 'skript-particle'
7 changes: 7 additions & 0 deletions shapes-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ repositories {

dependencies {
api "org.joml:joml:${jomlVersion}"
compileOnly 'org.jetbrains:annotations:24.0.1'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

tasks.named('test') {
useJUnitPlatform()
}

java {
Expand Down
18 changes: 18 additions & 0 deletions shapes-lib/src/main/java/com/sovdee/shapes/modifiers/Easable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.sovdee.shapes.modifiers;

/**
* Something that has an {@link EasingFunction}.
*/
public interface Easable {

/**
* @return the easing function used to distribute rotation along the axis
*/
EasingFunction getEasing();

/**
* @param easing the easing function used to distribute rotation along the axis
*/
void setEasing(EasingFunction easing);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package com.sovdee.shapes.modifiers;

import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

/**
* Maps a normalised value {@code t ∈ [0, 1]} to a (typically) {@code [0, 1]} output, shaping
* how interpolation progresses along a modifier's input axis.
* <br>
* Built-in constants and factory methods cover the most common curves, like {@link #SINE_IN_OUT}.
* <br>
* Custom implementations must provide a stable {@link #easingHash()} so that modifier cache
* invalidation works correctly.
*/
public interface EasingFunction {

/**
* Given an input between 0 and 1, applies the easing function and returns a mapped output
* @param t Input between 0 and 1.
* @return Output value mapped by the easing function.
*/
double apply(double t);

/**
* @return Stable hash of this easing's configuration, used in modifier cache keys.
* Two easings that produce identical output for all inputs should return the same value.
*/
int easingHash();

/**
* Controls which end of the interpolation range is eased.
* <ul>
* <li>{@link #IN} — slow start, fast end (ease into motion)</li>
* <li>{@link #OUT} — fast start, slow end (ease out of motion)</li>
* <li>{@link #IN_OUT} — slow start and slow end (symmetric ease)</li>
* </ul>
*/
enum Mode {
IN,
OUT,
IN_OUT
}

/**
* Power-curve easing: {@code t^n} (in), {@code 1-(1-t)^n} (out),
* symmetric combination (in-out).
* @param exponent 1 = linear, 2 = quadratic, 3 = cubic, etc.
* @param mode Whether to have the start, end, or both be smooth.
*/
record PowerEasing(double exponent, Mode mode) implements EasingFunction {
/**
* Applies the power-curve easing to {@code t}.
* <ul>
* <li>IN: {@code t^exponent}</li>
* <li>OUT: {@code 1 - (1-t)^exponent}</li>
* <li>IN_OUT: piecewise symmetric combination of the above</li>
* </ul>
*
* @param t normalised input in {@code [0, 1]}
* @return eased output value
*/
@Override
public double apply(double t) {
return switch (mode) {
case IN -> Math.pow(t, exponent);
case OUT -> 1.0 - Math.pow(1.0 - t, exponent);
case IN_OUT -> {
if (t < 0.5)
yield Math.pow(2.0 * t, exponent) / 2.0;
yield 1.0 - Math.pow(-2.0 * t + 2.0, exponent) / 2.0;
}
};
}

/**
* @return a hash combining the exponent and mode ordinal,
* unique among all standard {@code PowerEasing} configurations
*/
@Override
public int easingHash() {
return 31 * Double.hashCode(exponent) + mode.ordinal();
}
}

/**
* Sine-based easing.
* @param mode Whether to have the start, end, or both be smooth.
*/
record SineEasing(Mode mode) implements EasingFunction {
/**
* Applies the sine-based easing to {@code t}.
* <ul>
* <li>IN: {@code 1 - cos(t * π/2)}</li>
* <li>OUT: {@code sin(t * π/2)}</li>
* <li>IN_OUT: {@code -(cos(π*t) - 1) / 2}</li>
* </ul>
*
* @param t normalised input in {@code [0, 1]}
* @return eased output value
*/
@Override
public double apply(double t) {
return switch (mode) {
case IN -> 1.0 - Math.cos(t * Math.PI / 2.0);
case OUT -> Math.sin(t * Math.PI / 2.0);
case IN_OUT -> -(Math.cos(Math.PI * t) - 1.0) / 2.0;
};
}

@Override
public int easingHash() {
return 1000 + mode.ordinal();
}
}

// -------------------------------------------------------------------------
// Named constants
// -------------------------------------------------------------------------

EasingFunction LINEAR = new PowerEasing(1.0, Mode.IN);

EasingFunction QUAD_IN = new PowerEasing(2.0, Mode.IN);
EasingFunction QUAD_OUT = new PowerEasing(2.0, Mode.OUT);
EasingFunction QUAD_IN_OUT = new PowerEasing(2.0, Mode.IN_OUT);

EasingFunction CUBIC_IN = new PowerEasing(3.0, Mode.IN);
EasingFunction CUBIC_OUT = new PowerEasing(3.0, Mode.OUT);
EasingFunction CUBIC_IN_OUT = new PowerEasing(3.0, Mode.IN_OUT);

EasingFunction SINE_IN = new SineEasing(Mode.IN);
EasingFunction SINE_OUT = new SineEasing(Mode.OUT);
EasingFunction SINE_IN_OUT = new SineEasing(Mode.IN_OUT);

// -------------------------------------------------------------------------
// Factory methods
// -------------------------------------------------------------------------

/**
* @param exponent Degree to use for the easing function
* @return A power-based easing function with a gradual start and abrupt end
*/
@Contract("_ -> new")
static @NotNull EasingFunction powerIn(double exponent) {
return new PowerEasing(exponent, Mode.IN);
}

/**
* @param exponent Degree to use for the easing function
* @return A power-based easing function with an abrupt start and gradual end
*/
@Contract("_ -> new")
static @NotNull EasingFunction powerOut(double exponent) {
return new PowerEasing(exponent, Mode.OUT);
}

/**
* @param exponent Degree to use for the easing function
* @return A power-based easing function with a gradual start and end
*/
@Contract("_ -> new")
static @NotNull EasingFunction powerInOut(double exponent) {
return new PowerEasing(exponent, Mode.IN_OUT);
}

}
17 changes: 17 additions & 0 deletions shapes-lib/src/main/java/com/sovdee/shapes/modifiers/HasInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sovdee.shapes.modifiers;

/**
* A modifier that is driven by a {@link NormalizedInput}.
*/
public interface HasInput {

/**
* @return the input that drives this modifier
*/
NormalizedInput getInput();

/**
* @param input the input to drive this modifier with
*/
void setInput(NormalizedInput input);
}
Loading
Loading