Skip to content

Commit

Permalink
Ghoul lumber harvest, blighted pathing build requirements, Walk Fast …
Browse files Browse the repository at this point in the history
…animation, shift select
  • Loading branch information
Retera committed Aug 20, 2021
1 parent 7db2e00 commit ba2eb05
Show file tree
Hide file tree
Showing 41 changed files with 652 additions and 306 deletions.
5 changes: 2 additions & 3 deletions core/src/com/etheller/warsmash/WarsmashGdxMapScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public void show() {
Gdx.gl30.glEnable(GL30.GL_SCISSOR_TEST);

final Scene portraitScene = this.viewer.addSimpleScene();
portraitScene.alpha = true;
this.uiScene = this.viewer.addSimpleScene();
this.uiScene.alpha = true;
if (ENABLE_AUDIO) {
Expand Down Expand Up @@ -335,8 +334,8 @@ public void resize(final int width, final int height) {
private Rectangle setupWorldFrameViewport(final int width, final int height) {
this.tempRect.x = 0;
this.tempRect.width = width;
final float topHeight = 0;// 0.02666f * height;
final float bottomHeight = 0;// 0.21333f * height;
final float topHeight = 0.02666f * height;
final float bottomHeight = 0.21333f * height;
this.tempRect.y = (int) bottomHeight;
this.tempRect.height = height - (int) (topHeight + bottomHeight);
return this.tempRect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ public void render(final MdxComplexInstance instance, final Matrix4 mvp) {
shader.setUniform2fv("u_uvRot", uvAnim, 2, 2);
shader.setUniform1fv("u_uvScale", uvAnim, 4, 1);

if (instance.vertexColor[3] < 1.0f) {
if (instance.additiveOverrideMeshMode) {
layer.bindBlended(shader);
gl.glBlendFunc(FilterMode.ADDITIVE_ALPHA[0], FilterMode.ADDITIVE_ALPHA[1]);
}
else if (instance.vertexColor[3] < 1.0f) {
layer.bindBlended(shader);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class FilterMode {
private static final int[] ERROR_DEFAULT = new int[] { 0, 0 };
private static final int[] MODULATE_2X = new int[] { GL20.GL_DST_COLOR, GL20.GL_SRC_COLOR };
private static final int[] MODULATE = new int[] { GL20.GL_ZERO, GL20.GL_SRC_COLOR };
private static final int[] ADDITIVE_ALPHA = new int[] { GL20.GL_SRC_ALPHA, GL20.GL_ONE };
public static final int[] ADDITIVE_ALPHA = new int[] { GL20.GL_SRC_ALPHA, GL20.GL_ONE };
private static final int[] BLEND = new int[] { GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA };

public static int[] layerFilterMode(final MdlxLayer.FilterMode filterMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class MdxComplexInstance extends ModelInstance {
private float animationSpeed = 1.0f;
private float blendTime;
private float blendTimeRemaining;
public boolean additiveOverrideMeshMode = false;

public MdxComplexInstance(final MdxModel model) {
super(model);
Expand Down Expand Up @@ -511,8 +512,10 @@ public void updateBoneTexture() {
public void renderOpaque(final Matrix4 mvp) {
final MdxModel model = (MdxModel) this.model;

for (final GenericGroup group : model.opaqueGroups) {
group.render(this, mvp);
if (!this.additiveOverrideMeshMode) {
for (final GenericGroup group : model.opaqueGroups) {
group.render(this, mvp);
}
}

final int glGetError = Gdx.gl.glGetError();
Expand All @@ -528,6 +531,9 @@ public void renderTranslucent() {
}
final MdxModel model = (MdxModel) this.model;

for (final GenericGroup group : model.opaqueGroups) {
group.render(this, this.scene.camera.viewProjectionMatrix);
}
for (final GenericGroup group : model.translucentGroups) {
group.render(this, this.scene.camera.viewProjectionMatrix);

Expand Down Expand Up @@ -555,6 +561,10 @@ public void updateAnimations(final float dt) {
final int integerFrameTime = this.frame - lastIntegerFrame;
this.counter += integerFrameTime;
this.allowParticleSpawn = true;
if (this.additiveOverrideMeshMode) {
this.vertexColor[3] = Math.max(0,
this.vertexColor[3] - (integerFrameTime / (float) (interval[1] - interval[0])));
}

final long animEnd = interval[1] - 1;
if (this.floatingFrame >= animEnd) {
Expand Down Expand Up @@ -667,6 +677,12 @@ public MdxComplexInstance setVertexColor(final float[] color) {
return this;
}

public MdxComplexInstance setVertexAlpha(final float alpha) {
this.vertexColor[3] = alpha;

return this;
}

/**
* Set the sequence of this instance.
*/
Expand All @@ -686,11 +702,13 @@ public MdxComplexInstance setSequence(final int id) {
this.allowParticleSpawn = false;
}
else {
if ((this.blendTime > 0) && (lastSequence != this.sequence) && (lastSequence != -1)) {
this.blendTimeRemaining = this.blendTime;
for (int i = 0, l = this.sortedNodes.length; i < l; i++) {
final SkeletalNode node = this.sortedNodes[i];
node.beginBlending();
if ((this.blendTime > 0) && (lastSequence != -1)) {
if ((this.blendTimeRemaining <= 0) && (this.counter > 0)) {
this.blendTimeRemaining = this.blendTime;
for (int i = 0, l = this.sortedNodes.length; i < l; i++) {
final SkeletalNode node = this.sortedNodes[i];
node.beginBlending();
}
}
}

Expand Down
104 changes: 49 additions & 55 deletions core/src/com/etheller/warsmash/viewer5/handlers/w3x/War3MapViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.nio.channels.SeekableByteChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -150,6 +149,9 @@ public class War3MapViewer extends AbstractMdxModelViewer {
private static final War3ID ALLOW_CUSTOM_TEAM_COLOR = War3ID.fromString("utcc");
private static final War3ID TEAM_COLOR = War3ID.fromString("utco");
private static final War3ID MAX_ROLL = War3ID.fromString("umxr");
private static final War3ID ANIMATION_RUN_SPEED = War3ID.fromString("urun");
private static final War3ID ANIMATION_WALK_SPEED = War3ID.fromString("uwal");
private static final War3ID MODEL_SCALE = War3ID.fromString("usca");
private static final War3ID sloc = War3ID.fromString("sloc");
private static final LoadGenericCallback stringDataCallback = new StringDataCallbackImplementation();
private static final float[] rayHeap = new float[6];
Expand Down Expand Up @@ -191,7 +193,6 @@ public class War3MapViewer extends AbstractMdxModelViewer {
public int renderPathing = 0;
public int renderLighting = 1;

public List<SplatModel> selModels = new ArrayList<>();
private final Set<String> selectedSplatModelKeys = new HashSet<>();
public List<RenderWidget> selected = new ArrayList<>();
private final Set<String> mouseHighlightSplatModelKeys = new HashSet<>();
Expand Down Expand Up @@ -732,6 +733,8 @@ public void spawnGainLevelEffect(final CUnit source) {
public void heroRevived(final CUnit source) {
final AbilityUI reviveUI = War3MapViewer.this.abilityDataUI.getUI(ABILITY_REVIVE_RAWCODE);
final RenderUnit renderUnit = War3MapViewer.this.unitToRenderPeer.get(source);
renderUnit.instance.additiveOverrideMeshMode = false;
renderUnit.instance.setVertexAlpha(1.0f);
final CPlayer player = War3MapViewer.this.simulation.getPlayer(source.getPlayerIndex());
final String heroReviveArt = reviveUI.getTargetArt(player.getRace().ordinal());
spawnFxOnOrigin(renderUnit, heroReviveArt);
Expand All @@ -758,6 +761,12 @@ public void heroRevived(final CUnit source) {
}
}

@Override
public void heroDeathEvent(final CUnit source) {
final RenderUnit renderUnit = War3MapViewer.this.unitToRenderPeer.get(source);
renderUnit.instance.additiveOverrideMeshMode = true;
}

@Override
public void spawnEffectOnUnit(final CUnit unit, final String effectPath) {
final RenderUnit renderUnit = War3MapViewer.this.unitToRenderPeer.get(unit);
Expand Down Expand Up @@ -1380,7 +1389,8 @@ private CUnit createNewUnit(final Warcraft3MapObjectData modifications, final Wa
}
final RenderUnit renderUnit = new RenderUnit(this, model, row, unitX, unitY, unitZ, customTeamColor,
soundset, portraitModel, simulationUnit, typeData, specialArtModel, buildingShadowInstance,
this.selectionCircleScaleFactor);
this.selectionCircleScaleFactor, typeData.getAnimationWalkSpeed(),
typeData.getAnimationRunSpeed(), typeData.getScalingValue());
this.unitToRenderPeer.put(simulationUnit, renderUnit);
this.widgets.add(renderUnit);
this.units.add(renderUnit);
Expand Down Expand Up @@ -1488,7 +1498,8 @@ public RenderUnitTypeData getUnitTypeData(final War3ID key, final MutableGameObj
if (unitTypeData == null) {
unitTypeData = new RenderUnitTypeData(row.getFieldAsFloat(MAX_PITCH, 0), row.getFieldAsFloat(MAX_ROLL, 0),
row.getFieldAsFloat(ELEVATION_SAMPLE_RADIUS, 0), row.getFieldAsBoolean(ALLOW_CUSTOM_TEAM_COLOR, 0),
row.getFieldAsInteger(TEAM_COLOR, 0));
row.getFieldAsInteger(TEAM_COLOR, 0), row.getFieldAsFloat(ANIMATION_RUN_SPEED, 0),
row.getFieldAsFloat(ANIMATION_WALK_SPEED, 0), row.getFieldAsFloat(MODEL_SCALE, 0));
this.unitIdToTypeData.put(key, unitTypeData);
}
return unitTypeData;
Expand Down Expand Up @@ -1616,15 +1627,13 @@ public void render() {
}

public void deselect() {
if (!this.selModels.isEmpty()) {
for (final String key : this.selectedSplatModelKeys) {
this.terrain.removeSplatBatchModel(key);
}
this.selModels.clear();
for (final RenderWidget unit : this.selected) {
unit.unassignSelectionCircle();
}
for (final String key : this.selectedSplatModelKeys) {
this.terrain.removeSplatBatchModel(key);
}
for (final RenderWidget unit : this.selected) {
unit.unassignSelectionCircle();
}
this.selectedSplatModelKeys.clear();
this.selected.clear();
}

Expand Down Expand Up @@ -1667,27 +1676,39 @@ else if (localPlayer.hasAlliance(selectedUnitPlayerIndex, CAllianceType.HELP_REQ
}
}
path = allyKey + path;
if (!splats.containsKey(path)) {
splats.put(path, new Splat());
final SplatModel splatModel = this.terrain.getSplatModel("selection:" + path);
if (splatModel != null) {
final float x = unit.getX();
final float y = unit.getY();
final SplatMover splatInstance = splatModel.add(x - (selectionSize / 2), y - (selectionSize / 2),
x + (selectionSize / 2), y + (selectionSize / 2), 5, this.terrain.centerOffset);
unit.assignSelectionCircle(splatInstance);
if (unit.getInstance().hidden()) {
splatInstance.hide();
}
}
final float x = unit.getX();
final float y = unit.getY();
System.out.println("Selecting a unit at " + x + "," + y);
splats.get(path).locations.add(new float[] { x - (selectionSize / 2), y - (selectionSize / 2),
x + (selectionSize / 2), y + (selectionSize / 2), 5 });
splats.get(path).unitMapping.add(new Consumer<SplatModel.SplatMover>() {
@Override
public void accept(final SplatMover t) {
unit.assignSelectionCircle(t);
if (unit.getInstance().hidden()) {
t.hide();
}
else {
if (!splats.containsKey(path)) {
splats.put(path, new Splat());
}
});
final float x = unit.getX();
final float y = unit.getY();
System.out.println("Selecting a unit at " + x + "," + y);
splats.get(path).locations.add(new float[] { x - (selectionSize / 2), y - (selectionSize / 2),
x + (selectionSize / 2), y + (selectionSize / 2), 5 });
splats.get(path).unitMapping.add(new Consumer<SplatModel.SplatMover>() {
@Override
public void accept(final SplatMover t) {
unit.assignSelectionCircle(t);
if (unit.getInstance().hidden()) {
t.hide();
}
}
});
}
}
this.selected.add(unit);
}
this.selModels.clear();
for (final Map.Entry<String, Terrain.Splat> entry : splats.entrySet()) {
final String path = entry.getKey();
final String filePath = path.substring(2);
Expand Down Expand Up @@ -1715,7 +1736,6 @@ public void accept(final SplatMover t) {
model.color[3] = this.selectionCircleColorNeutral.a;
break;
}
this.selModels.add(model);
this.terrain.addSplatBatchModel("selection:" + path, model);
this.selectedSplatModelKeys.add("selection:" + path);
}
Expand Down Expand Up @@ -1857,32 +1877,6 @@ public void showConfirmation(final Vector3 position, final float red, final floa
this.confirmationInstance.vertexColor[2] = blue;
}

public List<RenderWidget> selectUnit(final float x, final float y, final boolean toggle) {
System.out.println("world: " + x + "," + y);
final RenderWidget entity = rayPickUnit(x, y, CWidgetFilterFunction.ACCEPT_ALL_LIVING);
List<RenderWidget> sel;
if (entity != null) {
if (toggle) {
sel = new ArrayList<>(this.selected);
final int idx = sel.indexOf(entity);
if (idx >= 0) {
sel.remove(idx);
}
else {
sel.add(entity);
}
}
else {
sel = Arrays.asList(entity);
}
this.doSelectUnit(sel);
}
else {
sel = Collections.emptyList();
}
return sel;
}

public RenderWidget rayPickUnit(final float x, final float y) {
return rayPickUnit(x, y, CWidgetFilterFunction.ACCEPT_ALL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,32 +138,26 @@ public boolean checkPathingTexture(final float positionX, final float positionY,
final float offsetY = ((pathingTextureTga.getHeight() % 2) == 1) ? 16f : 0f;
final Rectangle pathingMapRectangle = new Rectangle((positionX - (width / 2)) + offsetX,
(positionY - (height / 2)) + offsetY, width, height);
short anyPathingTypeWithUnit = 0;
if (cWorldCollision.intersectsAnythingOtherThan(pathingMapRectangle, unitToExcludeFromCollisionChecks,
MovementType.AMPHIBIOUS)) {
System.out.println("intersects amph unit");
anyPathingTypesInRegion |= PathingFlags.UNBUILDABLE | PathingFlags.UNWALKABLE | PathingFlags.UNSWIMABLE;
anyPathingTypeWithUnit |= PathingFlags.UNBUILDABLE | PathingFlags.UNWALKABLE | PathingFlags.UNSWIMABLE;
}
if (cWorldCollision.intersectsAnythingOtherThan(pathingMapRectangle, unitToExcludeFromCollisionChecks,
MovementType.FLOAT)) {
System.out.println("intersects float unit");
anyPathingTypesInRegion |= PathingFlags.UNSWIMABLE;
anyPathingTypeWithUnit |= PathingFlags.UNSWIMABLE;
}
if (cWorldCollision.intersectsAnythingOtherThan(pathingMapRectangle, unitToExcludeFromCollisionChecks,
MovementType.FLY)) {
System.out.println("intersects fly unit");
anyPathingTypesInRegion |= PathingFlags.UNFLYABLE;
anyPathingTypeWithUnit |= PathingFlags.UNFLYABLE;
}
if (cWorldCollision.intersectsAnythingOtherThan(pathingMapRectangle, unitToExcludeFromCollisionChecks,
MovementType.FOOT)) {
System.out.println("intersects foot unit");
anyPathingTypesInRegion |= PathingFlags.UNBUILDABLE | PathingFlags.UNWALKABLE;
anyPathingTypeWithUnit |= PathingFlags.UNBUILDABLE | PathingFlags.UNWALKABLE;
}
pathingTypesFillingRegion &= anyPathingTypeWithUnit;
for (final CBuildingPathingType pathingType : preventPathingTypes) {
if (PathingFlags.isPathingFlag(anyPathingTypesInRegion, pathingType)) {
return false;
Expand Down Expand Up @@ -328,7 +322,9 @@ public static final class PathingFlags {
public static int UNWALKABLE = 0x2;
public static int UNFLYABLE = 0x4;
public static int UNBUILDABLE = 0x8;
public static int BLIGHTED = 0x20;
public static int UNSWIMABLE = 0x40; // PROBABLY, didn't confirm this flag value is accurate
public static int BOUDNARY = 0xF0;

public static boolean isPathingFlag(final short pathingValue, final int flag) {
return (pathingValue & flag) != 0;
Expand All @@ -337,7 +333,7 @@ public static boolean isPathingFlag(final short pathingValue, final int flag) {
public static boolean isPathingFlag(final short pathingValue, final CBuildingPathingType pathingType) {
switch (pathingType) {
case BLIGHTED:
throw new IllegalArgumentException("Blight pathing check system is Not Yet Implemented");
return PathingFlags.isPathingFlag(pathingValue, PathingFlags.BLIGHTED);
case UNAMPH:
return PathingFlags.isPathingFlag(pathingValue, PathingFlags.UNWALKABLE)
&& PathingFlags.isPathingFlag(pathingValue, PathingFlags.UNSWIMABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import com.etheller.warsmash.viewer5.handlers.w3x.War3MapViewer;

public class Terrain {
public static final float CELL_SIZE = 128f;
private static final String[] colorTags = { "R", "G", "B", "A" };
private static final float[] sizeHeap = new float[2];
private static final Vector3 normalHeap1 = new Vector3();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ public static final String vert() {
" float hU = texelFetch(height_texture, height_pos + off.zy, 0).r;\r\n" + //
" vec3 normal = normalize(vec3(hL - hR, hD - hU, 2.0));\r\n" + //
"\r\n" + //
// " UV = vec2(vPosition.x, 1 - vPosition.y);\r\n" + //
" UV = vec2(vPosition.x==0?0.01:0.99, vPosition.y==0?0.99:0.01);\r\n" + //
" UV = vec2(vPosition.x, 1 - vPosition.y);\r\n" + //
// " UV = vec2(vPosition.x==0?0.01:0.99, vPosition.y==0?0.99:0.01);\r\n" + //
" texture_indices = texelFetch(terrain_texture_list, pos, 0);\r\n" + //
" pathing_map_uv = (vPosition + pos) * 4; \r\n" + //
"\r\n" + //
Expand Down
Loading

0 comments on commit ba2eb05

Please sign in to comment.