Skip to content

Commit

Permalink
Refactoring more in the editor to support editing big levels
Browse files Browse the repository at this point in the history
  • Loading branch information
Interrupt committed Jan 4, 2019
1 parent fc3f507 commit ca1b79f
Showing 1 changed file with 7 additions and 171 deletions.
178 changes: 7 additions & 171 deletions DelvEdit/src/com/interrupt/dungeoneer/editor/EditorFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.badlogic.gdx.graphics.g3d.decals.Decal;
import com.badlogic.gdx.graphics.g3d.decals.DecalBatch;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.*;
Expand Down Expand Up @@ -51,7 +50,10 @@
import com.interrupt.dungeoneer.game.Level.Source;
import com.interrupt.dungeoneer.generator.DungeonGenerator;
import com.interrupt.dungeoneer.generator.GenInfo.Markers;
import com.interrupt.dungeoneer.gfx.*;
import com.interrupt.dungeoneer.gfx.GlRenderer;
import com.interrupt.dungeoneer.gfx.SpriteGroupStrategy;
import com.interrupt.dungeoneer.gfx.TextureAtlas;
import com.interrupt.dungeoneer.gfx.WorldChunk;
import com.interrupt.dungeoneer.gfx.drawables.DrawableMesh;
import com.interrupt.dungeoneer.gfx.drawables.DrawableSprite;
import com.interrupt.dungeoneer.interfaces.Directional;
Expand Down Expand Up @@ -205,8 +207,6 @@ public boolean isWestFloor() {
}
}

private JFrame window = null;

private GameInput input;
public EditorInput editorInput;
private InputMultiplexer inputMultiplexer;
Expand Down Expand Up @@ -241,13 +241,11 @@ public boolean isWestFloor() {
double rotya = 0;
float rotYClamp = 1.571f;

double walkVel = 0.05;
double walkSpeed = 0.15;
double rotSpeed = 0.009;
double maxRot = 0.8;

boolean readFloorMove, readCeilMove, readRotate;
private int readFloorMoveCount, readCeilMoveCount;
boolean readRotate;

Mesh cubeMesh;
Mesh gridMesh;
Expand Down Expand Up @@ -329,11 +327,8 @@ protected Decal newObject () {
Color selectedColor = new Color(1f, 0.5f, 0.5f, 1f);

Vector3 intersection = new Vector3();
Vector3 testPos = new Vector3();
Vector3 tempVector1 = new Vector3();

Color tempColor = new Color();

DrawableSprite unknownEntityMarker = new DrawableSprite();

Array<ControlPoint> controlPoints = new Array<ControlPoint>();
Expand All @@ -356,15 +351,12 @@ protected Decal newObject () {

Vector3 rayOutVector = new Vector3();

private boolean isOnWindows = System.getProperty("os.name").startsWith("Windows");

public Editor editor;

/**
* @wbp.parser.entryPoint
*/
public EditorFrame(JFrame window, Editor editor) {
this.window = window;
this.editor = editor;
}

Expand Down Expand Up @@ -1986,8 +1978,6 @@ public void tick() {
// get picked entity
Ray ray = camera.getPickRay(Gdx.input.getX(), Gdx.input.getY());

float worldHitDistance = 10000000f;

// get plane intersection
if(intpos != null) {
if (!Gdx.input.isTouched()) {
Expand All @@ -2002,7 +1992,6 @@ public void tick() {
if (Collidor.intersectRayForwardFacingTriangles(camera.getPickRay(Gdx.input.getX(), Gdx.input.getY()), camera, GlRenderer.triangleSpatialHash.getAllTriangles(), intpos, intersectNormal)) {
intersectTemp.set(intpos).sub(camera.position).nor();
intpos.add(intersectTemp.x * -0.05f, 0.0001f, intersectTemp.z * -0.05f);
worldHitDistance = intersectTemp.set(intpos).sub(camera.position).len();
}

if(tileDragging) {
Expand Down Expand Up @@ -2570,7 +2559,7 @@ public Mesh genGrid (int height, int width) {
indices[i++] = (short)(i - 1);
}

Mesh mesh = new Mesh(true, vertices.length, indices.length, new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.ColorUnpacked, 4, "a_color"));
Mesh mesh = new Mesh(false, vertices.length, indices.length, new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.ColorUnpacked, 4, "a_color"));
mesh.setVertices(vertices);
mesh.setIndices(indices);

Expand Down Expand Up @@ -3310,7 +3299,7 @@ public void paste() {
level.setTile(x + selX, y + selY, t);
}

markWorldAsDirty(x, y, 1);
markWorldAsDirty(x + selX, y + selY, 1);
}
}

Expand Down Expand Up @@ -3802,159 +3791,6 @@ public TextureRegion[] loadAtlas(String texture, int spritesHorizontal, boolean
return region;
}

public Color GetLightmapAt(float posx, float posy, float posz) {
Color t = level.GetLightmapAt(posx, posz, posz);

if(t == null) {
return Color.BLACK;
}

return level.GetLightmapAt(posx, posy, posz);
}

Array<Vector3> t_collisionTriangles = new Array<Vector3>();
VertexAttributes t_staticMeshVertexAttributes = new VertexAttributes(new VertexAttribute(VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE),
new VertexAttribute(VertexAttributes.Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE),
new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));

public Array<Mesh> mergeStaticMeshes(Level level, Array<Entity> entities) {
short indexOffset = 0;
int vertexCount = 0;

ShortArray indices = new ShortArray(500);
FloatArray vertices = new FloatArray(500);

Array<Mesh> created = new Array<Mesh>();

for(Entity e : entities) {
if(e.drawable != null && e.drawable instanceof DrawableMesh) {
DrawableMesh drbl = (DrawableMesh)e.drawable;

if(drbl.loadedMesh != null && drbl.isStaticMesh) {

// may need to chunk up the meshes
if(drbl.loadedMesh.getNumIndices() + indexOffset >= 32000 && vertexCount > 0) {

Mesh m = EditorCachePools.getStaticMesh(t_staticMeshVertexAttributes, vertexCount, indices.size, true);

// pack the array
indices.shrink();
vertices.shrink();

m.setIndices(indices.toArray());
m.setVertices(vertices.toArray());

indices = new ShortArray(500);
vertices = new FloatArray(500);

vertexCount = 0;
indexOffset = 0;

created.add(m);
}

VertexAttributes attributes = drbl.loadedMesh.getVertexAttributes();

int positionOffset = 0;
int uvOffset = 0;
int attSize = 0;

for(int i = 0; i < attributes.size(); i++) {
VertexAttribute attrib = attributes.get(i);

if(attrib.usage == VertexAttribute.Position().usage) {
positionOffset = attSize;
}
else if(attrib.usage == VertexAttribute.TexCoords(0).usage) {
uvOffset = attSize;
}

attSize += attrib.numComponents;
}

short[] ind = new short[drbl.loadedMesh.getNumIndices()];
float[] verts = new float[drbl.loadedMesh.getNumVertices() * attSize];

if(ind.length > 0)
drbl.loadedMesh.getIndices(ind);
else {
ind = new short[drbl.loadedMesh.getNumVertices()];

for(int i = 0; i < drbl.loadedMesh.getNumVertices(); i++) {
ind[i] = (short)i;
}
}

drbl.loadedMesh.getVertices(verts);

Matrix4 matrix = new Matrix4().setToTranslation(e.x, e.z - 0.5f, e.y);
matrix.scale(drbl.scale, drbl.scale, drbl.scale);
matrix.mul(new Matrix4().setToRotation(Vector3.X, drbl.dir.y * -90f));

matrix.rotate(Vector3.Y, drbl.rotZ);
matrix.rotate(Vector3.X, drbl.rotX);
matrix.rotate(Vector3.Z, drbl.rotY);

// translate the vertices by the model matrix
Matrix4.mulVec(matrix.val, verts, 0, drbl.loadedMesh.getNumVertices(), attSize);

if(ind != null && verts != null) {
for(int i = 0; i < ind.length; i++) {
indices.add((short)(ind[i] + indexOffset));
}
indexOffset += ind.length;

for(int i = 0; i < drbl.loadedMesh.getNumVertices() * attSize; i+= attSize) {

vertices.add(verts[i + positionOffset]);
vertices.add(verts[i + positionOffset + 1]);
vertices.add(verts[i + positionOffset + 2]);

if (e.isSolid) {
t_collisionTriangles.add(EditorCachePools.getCollisionVector(verts[i + positionOffset], verts[i + positionOffset + 1], verts[i + positionOffset + 2]));
}

float c = Color.WHITE.toFloatBits();
if(!e.fullbrite && showLights) {
c = level.getLightColorAt(verts[i + positionOffset], verts[i + positionOffset + 2], verts[i + positionOffset + 1], null, new Color()).toFloatBits();
}

vertices.add(c);
vertices.add(verts[i + uvOffset]);
vertices.add(verts[i + uvOffset + 1]);

vertexCount++;
}
}
}
}
}

if(vertexCount == 0) return null;

for (int i = 0; i < t_collisionTriangles.size; i += 3) {
Triangle triangle = EditorCachePools.getTriangle();
triangle.v1.set(t_collisionTriangles.get(i + 2));
triangle.v2.set(t_collisionTriangles.get(i + 1));
triangle.v3.set(t_collisionTriangles.get(i));

staticMeshCollisionTriangles.add(triangle);
}
t_collisionTriangles.clear();

Mesh m = EditorCachePools.getStaticMesh(t_staticMeshVertexAttributes, vertexCount, indices.size, true);

// pack the array
indices.shrink();
vertices.shrink();

m.setIndices(indices.toArray());
m.setVertices(vertices.toArray());

created.add(m);
return created;
}

public void doCarve() {
if(pickedEntity != null) return;

Expand Down

0 comments on commit ca1b79f

Please sign in to comment.