Skip to content

Commit

Permalink
Minor attempts at fixes, fix some camera issues, but there is still a…
Browse files Browse the repository at this point in the history
… bug on the res loader
  • Loading branch information
Retera committed Apr 23, 2022
1 parent 84d445f commit 61faa91
Show file tree
Hide file tree
Showing 38 changed files with 1,574 additions and 1,019 deletions.
9 changes: 5 additions & 4 deletions craft3data/src/com/hiveworkshop/ReteraCASCUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hiveworkshop;

public class ReteraCASCUtils {
public static final boolean LOAD_OLD_131_FORMAT = false;

public static boolean arraysEquals(final byte[] a, final int aFromIndex, final int aToIndex, final byte[] b,
final int bFromIndex, final int bToIndex) {
Expand All @@ -14,7 +15,7 @@ public static boolean arraysEquals(final byte[] a, final int aFromIndex, final i
if (b == null) {
return false;
}
if ((aToIndex - aFromIndex) != (bToIndex - bFromIndex)) {
if (aToIndex - aFromIndex != bToIndex - bFromIndex) {
return false;
}
int j = bFromIndex;
Expand All @@ -29,10 +30,10 @@ public static boolean arraysEquals(final byte[] a, final int aFromIndex, final i
public static int arraysCompareUnsigned(final byte[] a, final int aFromIndex, final int aToIndex, final byte[] b,
final int bFromIndex, final int bToIndex) {
final int i = arraysMismatch(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex);
if ((i >= 0) && (i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))) {
if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex)) {
return byteCompareUnsigned(a[aFromIndex + i], b[bFromIndex + i]);
}
return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
return aToIndex - aFromIndex - (bToIndex - bFromIndex);
}

private static int byteCompareUnsigned(final byte b, final byte c) {
Expand All @@ -43,7 +44,7 @@ private static int arraysMismatch(final byte[] a, final int aFromIndex, final in
final int bFromIndex, final int bToIndex) {
final int aLength = aToIndex - aFromIndex;
final int bLength = bToIndex - bFromIndex;
for (int i = 0; (i < aLength) && (i < bLength); i++) {
for (int i = 0; i < aLength && i < bLength; i++) {
if (a[aFromIndex + i] != b[bFromIndex + i]) {
return i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Arrays;
import java.util.List;

import com.hiveworkshop.ReteraCASCUtils;
import com.hiveworkshop.blizzard.casc.Key;
import com.hiveworkshop.blizzard.casc.nio.MalformedCASCStructureException;

Expand Down Expand Up @@ -155,7 +156,9 @@ private StorageReference[] getFileReferences(final int fileOffset) throws Malfor
storageBuffer.get(encodingKeyDecoder);

final int physicalSize = storageBuffer.getInt();
storageBuffer.get();
if (!ReteraCASCUtils.LOAD_OLD_131_FORMAT) {
storageBuffer.get();
}
final int actualSize = storageBuffer.getInt();

final StorageReference reference = new StorageReference(offset, size, new Key(encodingKeyDecoder),
Expand All @@ -177,7 +180,7 @@ public TVFSFile loadFile(final ByteBuffer fileBuffer) throws IOException {

// check identifier

if ((localBuffer.remaining() < IDENTIFIER.remaining())
if (localBuffer.remaining() < IDENTIFIER.remaining()
|| !localBuffer.limit(IDENTIFIER.remaining()).equals(IDENTIFIER)) {
throw new MalformedCASCStructureException("missing TVFS identifier");
}
Expand All @@ -204,20 +207,20 @@ public TVFSFile loadFile(final ByteBuffer fileBuffer) throws IOException {

pathOffset = localBuffer.getInt();
pathSize = localBuffer.getInt();
if ((Integer.toUnsignedLong(pathOffset) + Integer.toUnsignedLong(pathSize)) > localBuffer.capacity()) {
if (Integer.toUnsignedLong(pathOffset) + Integer.toUnsignedLong(pathSize) > localBuffer.capacity()) {
throw new MalformedCASCStructureException("path stream extends past end of file");
}

fileReferenceOffset = localBuffer.getInt();
fileReferenceSize = localBuffer.getInt();
if ((Integer.toUnsignedLong(fileReferenceOffset) + Integer.toUnsignedLong(fileReferenceSize)) > localBuffer
if (Integer.toUnsignedLong(fileReferenceOffset) + Integer.toUnsignedLong(fileReferenceSize) > localBuffer
.capacity()) {
throw new MalformedCASCStructureException("logical data extends past end of file");
}

cascReferenceOffset = localBuffer.getInt();
cascReferenceSize = localBuffer.getInt();
if ((Integer.toUnsignedLong(cascReferenceOffset) + Integer.toUnsignedLong(cascReferenceSize)) > localBuffer
if (Integer.toUnsignedLong(cascReferenceOffset) + Integer.toUnsignedLong(cascReferenceSize) > localBuffer
.capacity()) {
throw new MalformedCASCStructureException("storage data extends past end of file");
}
Expand All @@ -227,7 +230,7 @@ public TVFSFile loadFile(final ByteBuffer fileBuffer) throws IOException {
throw new MalformedCASCStructureException("header goes out of bounds");
}

contentsOffsetSize = Math.max(1, Integer.BYTES - (Integer.numberOfLeadingZeros(cascReferenceSize) / Byte.SIZE));
contentsOffsetSize = Math.max(1, Integer.BYTES - Integer.numberOfLeadingZeros(cascReferenceSize) / Byte.SIZE);
contentsOffsetDecoder.putInt(0, 0);

localBuffer.limit(pathOffset + pathSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.awt.Component;
import java.awt.Font;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.util.HashMap;

import javax.swing.DefaultListCellRenderer;
Expand All @@ -27,9 +28,11 @@ public Component getListCellRendererComponent(final JList list, final Object val
final String name = ((Material) value).getName();
ImageIcon myIcon = map.get(value);
if (myIcon == null) {
myIcon = new ImageIcon(((Material) value).getBufferedImage(model.getWrappedDataSource())
.getScaledInstance(64, 64, Image.SCALE_SMOOTH));
map.put((Material) value, myIcon);
final BufferedImage bufferedImage = ((Material) value).getBufferedImage(model.getWrappedDataSource());
if (bufferedImage != null) {
myIcon = new ImageIcon(bufferedImage.getScaledInstance(64, 64, Image.SCALE_SMOOTH));
map.put((Material) value, myIcon);
}
}
super.getListCellRendererComponent(list, name, index, iss, chf);
setIcon(myIcon);
Expand Down
18 changes: 8 additions & 10 deletions craft3data/src/com/hiveworkshop/wc3/gui/modeledit/ModelPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ public ModelPanel(final JComponent parent, final EditableModel input, final Prog
modelView = new ModelViewManager(input);
undoManager = new UndoManagerImpl(undoHandler);
editorRenderModel = new RenderModel(input, modelView);
editorRenderModel.setSpawnParticles((prefs.getRenderParticles() == null) || prefs.getRenderParticles());
editorRenderModel.setSpawnParticles(prefs.getRenderParticles() == null || prefs.getRenderParticles());
editorRenderModel.setAllowInanimateParticles(
(prefs.getRenderStaticPoseParticles() == null) || prefs.getRenderStaticPoseParticles());
prefs.getRenderStaticPoseParticles() == null || prefs.getRenderStaticPoseParticles());
modelEditorManager = new ModelEditorManager(modelView, prefs, modeNotifier, modelEditorChangeNotifier,
viewportActivityManager, editorRenderModel, modelStructureChangeListener);
modelViewManagingTree = new ModelViewManagingTree(modelView, undoManager, modelEditorManager);
Expand Down Expand Up @@ -153,7 +153,8 @@ public void typeChanged(final SelectionItemTypes newType) {
animationController = new AnimationController(modelView, true, animationViewer,
animationViewer.getCurrentAnimation());

cameraController = new CameraManagerPanel(modelView, animationViewer);
cameraController = new CameraManagerPanel(modelView, animationViewer, modelStructureChangeListener,
modelEditorManager.getModelEditor(), undoManager);

frontArea.setControlsVisible(prefs.showVMControls());
botArea.setControlsVisible(prefs.showVMControls());
Expand Down Expand Up @@ -419,8 +420,7 @@ public boolean close(final ModelPanelCloseListener listener)// MainPanel parent)
canceled = true;
break;
}
}
else // parent.tabbedPane.remove(myIndex);
} else // parent.tabbedPane.remove(myIndex);
if (editUVPanel != null) {
editUVPanel.view.setVisible(false);
}
Expand Down Expand Up @@ -515,13 +515,11 @@ public void viewMatrices() {
}
String boneList = "";
for (int i = 0; i < boneRefs.size(); i++) {
if (i == (boneRefs.size() - 2)) {
if (i == boneRefs.size() - 2) {
boneList = boneList + boneRefs.get(i).getName() + " and ";
}
else if (i == (boneRefs.size() - 1)) {
} else if (i == boneRefs.size() - 1) {
boneList = boneList + boneRefs.get(i).getName();
}
else {
} else {
boneList = boneList + boneRefs.get(i).getName() + ", ";
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.hiveworkshop.wc3.gui.modeledit.creator.actions;

import java.util.ArrayList;
import java.util.List;

import com.hiveworkshop.wc3.gui.modeledit.UndoAction;
import com.hiveworkshop.wc3.gui.modeledit.actions.newsys.ModelStructureChangeListener;
import com.hiveworkshop.wc3.mdl.Camera;
import com.hiveworkshop.wc3.mdl.v2.ModelView;

public class DrawCameraAction implements UndoAction {
private final ModelView modelView;
private final Camera camera;
private final ModelStructureChangeListener modelStructureChangeListener;
private final List<Camera> cameraAsList;

public DrawCameraAction(final ModelView modelView, final ModelStructureChangeListener modelStructureChangeListener,
final Camera camera) {
this.modelView = modelView;
this.camera = camera;
this.modelStructureChangeListener = modelStructureChangeListener;
cameraAsList = new ArrayList<>();
cameraAsList.add(camera);
}

@Override
public void undo() {
modelView.getModel().remove(camera);
modelStructureChangeListener.camerasRemoved(cameraAsList);
}

@Override
public void redo() {
modelView.getModel().add(camera);
modelStructureChangeListener.camerasAdded(cameraAsList);
}

@Override
public String actionName() {
return "add " + camera.getName();
}

}
Loading

0 comments on commit 61faa91

Please sign in to comment.