Skip to content

Commit

Permalink
Merge branch 'master' into gui-rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
cam72cam committed Oct 4, 2023
2 parents 9b74712 + 2db0d35 commit 4f10519
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 68 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Immersive Railroading Build Pipeline

on:
push:
branches-ignore:
- 'master'

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
branch: [1.12.2-forge, 1.16.5-forge]
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: keyscan
run: mkdir -p ~/.ssh/ && ssh-keyscan -t rsa teamopenindustry.cc >> ~/.ssh/known_hosts
- name: Install deps
run: sudo apt install -y pngquant findutils xvfb
- name: Setup Universal Mod Core (and helpers)
env:
BRANCH: ${{ matrix.branch }}
run: java -jar UMCSetup.jar ${BRANCH} https
- name: Gradle compile
run: ./gradlew classes
- name: Process images
run: find src/main/resources/assets/immersiverailroading/ | grep png | xargs -I foo pngquant -s1 -f --ext .png foo
- name: Run Data (optionalish)
run: xvfb-run --auto-servernum ./gradlew runData || xvfb-run --auto-servernum ./gradlew runData || true
- name: Gradle build
run: ./gradlew build
- name: Gradle publish
env:
MAVENCI_PASS: ${{ secrets.MAVENCI_PASS }}
run: ./gradlew publish
- uses: actions/upload-artifact@v2
with:
name: Immersive Railroading ${{matrix.branch}}
path: build/libs/ImmersiveRailroading-${{matrix.branch}}-*
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Immersive Railroading Build Pipeline

on: [push]
on:
push:
branches:
- 'master'

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,23 @@ public final void setCoupledUUID(CouplerType coupler, UUID id) {
.sendToObserving(this);
}

EntityCoupleableRollingStock coupled = id != null ? findByUUID(id) : null;

switch (coupler) {
case FRONT:
coupledFront = id;
if (coupledFront == null) {
lastKnownFront = null;
} else if (coupled != null){
lastKnownFront = new Vec3i(coupled.getPosition());
}
break;
case BACK:
coupledBack = id;
if (coupledBack == null) {
lastKnownRear = null;
} else if (coupled != null){
lastKnownFront = new Vec3i(coupled.getPosition());
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ public static Map<UUID, SimulationState> iterate(Map<UUID, SimulationState> stat
// Propagate dirty flag
boolean canBeUnloaded = consist.stream().allMatch(p -> p.state.velocity == 0 && state.forcesNewtons() < state.frictionNewtons());
consist.forEach(p -> p.state.canBeUnloaded = canBeUnloaded);
List<UUID> ids = consist.stream().map(x -> x.state.config.id).collect(Collectors.toList());
consist.forEach(p -> p.state.consist = ids);

boolean dirty = consist.stream().anyMatch(p -> p.state.dirty);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,73 +74,16 @@ public static void simulate(World world) {
state.update(entity);
stateMaps.get(i).put(entity.getUUID(), state);
if (state.dirty) {
dirty.add(entity.getUUID());
dirty.addAll(state.consist);
}
}
}
if (i < 40) {
stateMaps.get(i).get(entity.getUUID()).dirty = true;
dirty.addAll(stateMaps.get(i).get(entity.getUUID()).consist);
}
}
}

// This finds the full list of dirty stock that needs to be recomputed.
// It is *highly* optimized to run in under 0.5ms per 100 pieces of stock.
// It could be tuned further, but I suspect this is good enough for now
for (int i = 0; i < allStock.size(); i++) {
int lastSize = dirty.size();

for (UUID uuid : stateMaps.get(0).keySet()) {
boolean isDirty = dirty.contains(uuid);

// This makes an assumption that stock only has a single value for a coupler in 40 ticks
// Worst case is the potential for a missed dirty flag which will interact with the Mismatch check
UUID front = null;
UUID rear = null;

for (Map<UUID, SimulationState> stateMap : stateMaps) {
if (front != null && rear != null) {
break;
}

SimulationState state = stateMap.get(uuid);
if (state != null) {
if (front == null && state.interactingFront != null) {
front = state.interactingFront;
}
if (rear == null && state.interactingRear != null) {
rear = state.interactingRear;
}
}
}

if (!isDirty) {
if (front != null && dirty.contains(front)) {
dirty.add(uuid);
isDirty = true;
}
}
if (!isDirty) {
if (rear != null && dirty.contains(rear)) {
dirty.add(uuid);
isDirty = true;
}
}

if (isDirty) {
if (front != null && !dirty.contains(front)) {
dirty.add(front);
}
if (rear != null && !dirty.contains(rear)) {
dirty.add(rear);
}
}
}
if (lastSize == dirty.size()) {
break;
}
}

for (UUID uuid : dirty) {
SimulationState state = stateMaps.get(0).get(uuid);
if (state != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class SimulationState {
public boolean frontPulling;
public boolean rearPushing;
public boolean rearPulling;
public List<UUID> consist;

public static class Configuration {
public UUID id;
Expand Down Expand Up @@ -199,6 +200,8 @@ public SimulationState(EntityCoupleableRollingStock stock) {

calculateBlockCollisions(Collections.emptyList());
blocksToBreak = Collections.emptyList();

consist = Collections.singletonList(config.id);
}

private SimulationState(SimulationState prev) {
Expand Down Expand Up @@ -229,6 +232,8 @@ private SimulationState(SimulationState prev) {
interferingResistance = prev.interferingResistance;
blocksToBreak = Collections.emptyList();
directResistance = prev.directResistance;

consist = prev.consist;
}

public void calculateCouplerPositions() {
Expand Down Expand Up @@ -348,14 +353,6 @@ private void moveAlongTrack(double distance) {
}
}

// Fix bogeys pointing in opposite directions
if (DegreeFuncs.delta(yawFront, yaw) > 90) {
yawFront = yaw;
}
if (DegreeFuncs.delta(yawRear, yaw) > 90) {
yawRear = yaw;
}

boolean isReversed = distance < 0;
if (isReversed) {
distance = -distance;
Expand Down Expand Up @@ -391,6 +388,12 @@ private void moveAlongTrack(double distance) {
yawFront = yaw;
yawRear = yaw;
}

// Fix bogeys pointing in opposite directions
if (DegreeFuncs.delta(yawFront, yaw) > 90 || DegreeFuncs.delta(yawFront, yawRear) > 90) {
yawFront = yaw;
yawRear = yaw;
}
}

public double forcesNewtons() {
Expand Down

0 comments on commit 4f10519

Please sign in to comment.