Skip to content

Commit

Permalink
Merge pull request #1 from Interrupt/features/3d-fnt-playground
Browse files Browse the repository at this point in the history
Per-glyph version of NeoText
  • Loading branch information
evrimoztamur authored Sep 26, 2020
2 parents cc939d3 + c4bfdd3 commit 5b5246f
Show file tree
Hide file tree
Showing 44 changed files with 1,420 additions and 212 deletions.
111 changes: 43 additions & 68 deletions DelvEdit/src/com/interrupt/dungeoneer/editor/EditorApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
Expand Down Expand Up @@ -409,18 +408,25 @@ public void init(){
pickedWallTextureAtlas = pickedWallBottomTextureAtlas = pickedFloorTextureAtlas = pickedCeilingTextureAtlas =
TextureAtlas.cachedRepeatingAtlases.firstKey();

level = new Level(17,17);
Tile t = new Tile();
t.floorHeight = -0.5f;
t.ceilHeight = 0.5f;
level.setTile(7, 7, t);
createEmptyLevel(17, 17);
}

public void createEmptyLevel(int width, int height) {
level = new Level(width, height);
refresh();

history = new EditorHistory();
file = new EditorFile();

Tile t = new Tile();
t.floorHeight = -0.5f;
t.ceilHeight = 0.5f;
level.setTile(width / 2, height / 2, t);

history = new EditorHistory();
file = new EditorFile();
history.saveState(Editor.app.level);
file.markClean();
history.saveState(level);
file.markClean();

gridMesh = genGrid(level.width,level.height);
cameraController.setDefaultPositionAndRotation();
}

@Override
Expand Down Expand Up @@ -495,7 +501,7 @@ public void render() {
float z = Game.instance.player.z + Game.instance.player.eyeHeight;
float y = Game.instance.player.y;

float rotationX = Game.instance.player.rot + 3.14159265f;
float rotationX = Game.instance.player.rot;
float rotationY = -Game.instance.player.yrot;

cameraController.setPosition(x, y, z);
Expand Down Expand Up @@ -525,6 +531,7 @@ public void render() {
if(stage != null) {
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();

}
}

Expand Down Expand Up @@ -726,6 +733,8 @@ else if(e == Editor.selection.hovered) {
shouldDrawBox = false;
}

shouldDrawBox = ui.isShowingModal() ? false : shouldDrawBox;

if(Editor.selection.picked == null && Editor.selection.hovered == null || tileDragging) {
if(!selected || (!(pickedControlPoint != null || movingControlPoint) &&
editorInput.isButtonPressed(Input.Buttons.LEFT) && Gdx.input.justTouched())) {
Expand Down Expand Up @@ -824,17 +833,11 @@ else if(pickedSurface.tileSurface == TileSurface.Ceiling) {

Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE);

if(Editor.selection.picked instanceof ProjectedDecal) {
renderProjection(((ProjectedDecal) Editor.selection.picked).perspective);
}
else if(Editor.selection.picked instanceof Mover) {
if(Editor.selection.picked instanceof Mover) {
renderMoverVizualization((Mover) Editor.selection.picked);
}
for(Entity selectedEntity : Editor.selection.selected) {
if(selectedEntity instanceof ProjectedDecal) {
renderProjection(((ProjectedDecal)selectedEntity).perspective);
}
else if(selectedEntity instanceof Mover) {
if(selectedEntity instanceof Mover) {
renderMoverVizualization((Mover)selectedEntity);
}
}
Expand Down Expand Up @@ -1319,15 +1322,14 @@ else if(Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)) {
Editor.selection.picked.z = dragStart.z;
}
if(dragMode == DragMode.Y) {
Editor.selection.picked.z = dragStart.z;
Editor.selection.picked.y = dragStart.y;
Editor.selection.picked.x = dragStart.x;
}
else if(dragMode == DragMode.Z) {
Editor.selection.picked.x = dragStart.x;
Editor.selection.picked.y = dragStart.y;
}
else if(dragMode == DragMode.X) {
Editor.selection.picked.x = dragStart.x;
Editor.selection.picked.y = dragStart.y;
}

if(Gdx.input.isKeyPressed(Keys.CONTROL_LEFT)) {
Expand Down Expand Up @@ -1400,23 +1402,23 @@ else if(dragMode == DragMode.Y) {
this.drawLine(startLine, endLine, 2, EditorColors.Z_AXIS);
}
else if(dragMode == DragMode.X) {
Vector3 startLine = tempVec3.set(Editor.selection.picked.x, Editor.selection.picked.z - 0.5f, Editor.selection.picked.y - 10f);
Vector3 endLine = tempVec4.set(Editor.selection.picked.x, Editor.selection.picked.z - 0.5f, Editor.selection.picked.y + 10f);
Vector3 startLine = tempVec3.set(Editor.selection.picked.x - 10f, Editor.selection.picked.z - 0.5f, Editor.selection.picked.y);
Vector3 endLine = tempVec4.set(Editor.selection.picked.x + 10f, Editor.selection.picked.z - 0.5f, Editor.selection.picked.y);
this.drawLine(startLine, endLine, 2, EditorColors.X_AXIS);
}
else if(dragMode == DragMode.Y) {
Vector3 startLine = tempVec3.set(Editor.selection.picked.x - 10f, Editor.selection.picked.z - 0.5f, Editor.selection.picked.y);
Vector3 endLine = tempVec4.set(Editor.selection.picked.x + 10f, Editor.selection.picked.z - 0.5f, Editor.selection.picked.y);
Vector3 startLine = tempVec3.set(Editor.selection.picked.x, Editor.selection.picked.z - 0.5f, Editor.selection.picked.y -10f);
Vector3 endLine = tempVec4.set(Editor.selection.picked.x, Editor.selection.picked.z - 0.5f, Editor.selection.picked.y + 10f);
this.drawLine(startLine, endLine, 2, EditorColors.Y_AXIS);
}
else if(dragMode == DragMode.XY || (!movingEntity && Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT))) {
Vector3 startLine = tempVec3.set(Editor.selection.picked.x, Editor.selection.picked.z - 0.5f, Editor.selection.picked.y - 10f);
Vector3 endLine = tempVec4.set(Editor.selection.picked.x, Editor.selection.picked.z - 0.5f, Editor.selection.picked.y + 10f);
this.drawLine(startLine, endLine, 2, EditorColors.X_AXIS);
this.drawLine(startLine, endLine, 2, EditorColors.Y_AXIS);

startLine = tempVec3.set(Editor.selection.picked.x - 10f, Editor.selection.picked.z - 0.5f, Editor.selection.picked.y);
endLine = tempVec4.set(Editor.selection.picked.x + 10f, Editor.selection.picked.z - 0.5f, Editor.selection.picked.y);
this.drawLine(startLine, endLine, 2, EditorColors.Y_AXIS);
this.drawLine(startLine, endLine, 2, EditorColors.X_AXIS);
}
}
}
Expand Down Expand Up @@ -1462,8 +1464,8 @@ else if(dragMode == DragMode.XY || (!movingEntity && Gdx.input.isKeyPressed(Inpu

if(player == null) {
lineRenderer.begin(ShapeType.Line);
drawLine(xGridStart, xGridEnd, 2f, EditorColors.Y_AXIS_DARK);
drawLine(yGridStart, yGridEnd, 2f, EditorColors.X_AXIS_DARK);
drawLine(xGridStart, xGridEnd, 2f, EditorColors.X_AXIS_DARK);
drawLine(yGridStart, yGridEnd, 2f, EditorColors.Y_AXIS_DARK);
lineRenderer.end();
}

Expand Down Expand Up @@ -1588,6 +1590,7 @@ protected void refreshEntity(Entity theEntity) {
}
else if(theEntity instanceof ProjectedDecal) {
((ProjectedDecal)theEntity).refresh();
((ProjectedDecal)theEntity).updateDrawable();
}
else if(theEntity instanceof Model) {
Model m = (Model)theEntity;
Expand Down Expand Up @@ -1677,36 +1680,6 @@ public void renderCollisionBox(Entity e) {
lineRenderer.line(e.x + e.collision.x, zStart, e.y - e.collision.y, e.x + e.collision.x, zEnd, e.y - e.collision.y);
}

public void renderProjection(Camera perspective) {
if(perspective == null) return;

for(int i = 0; i < 4; i++) {
Vector3 startPoint = perspective.frustum.planePoints[i];
Vector3 endPoint = i != 3 ? perspective.frustum.planePoints[i + 1] : perspective.frustum.planePoints[0];

lineRenderer.line(startPoint.x, startPoint.y, startPoint.z, endPoint.x, endPoint.y, endPoint.z);
}

for(int i = 0; i < 4; i++) {
Vector3 startPoint = perspective.frustum.planePoints[i];
Vector3 endPoint = perspective.frustum.planePoints[i + 4];

lineRenderer.line(startPoint.x, startPoint.y, startPoint.z, endPoint.x, endPoint.y, endPoint.z);
}

for(int i = 4; i < 8; i++) {
Vector3 startPoint = perspective.frustum.planePoints[i];
Vector3 endPoint = i != 7 ? perspective.frustum.planePoints[i + 1] : perspective.frustum.planePoints[4];

lineRenderer.line(startPoint.x, startPoint.y, startPoint.z, endPoint.x, endPoint.y, endPoint.z);
}

Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
Gdx.gl.glLineWidth(1f);
lineRenderer.setColor(Color.CYAN);
lineRenderer.flush();
}

public void renderMoverVizualization(Mover e) {
float zStart = e.z - 0.5f;
float zEnd = zStart + e.collision.z;
Expand Down Expand Up @@ -2159,7 +2132,7 @@ public void testLevel() {
Game.instance.player.x = cameraPosition.x;
Game.instance.player.y = cameraPosition.y - Game.instance.player.eyeHeight;
Game.instance.player.z = cameraPosition.z;
Game.instance.player.rot = cameraRotation.x - 3.14159265f;
Game.instance.player.rot = cameraRotation.x;
Game.instance.player.yrot = -cameraRotation.y;
Game.isDebugMode = true;
}
Expand Down Expand Up @@ -2478,7 +2451,7 @@ public void drawZCircle(float startX, float startY, float startZ, float radius,
}
}

public void drawYCircle(float startX, float startY, float startZ, float radius, Color color) {
public void drawXCircle(float startX, float startY, float startZ, float radius, Color color) {
lineRenderer.setColor(color);

float tau = (float)Math.PI * 2;
Expand All @@ -2496,7 +2469,7 @@ public void drawYCircle(float startX, float startY, float startZ, float radius,
}
}

public void drawXCircle(float startX, float startY, float startZ, float radius, Color color) {
public void drawYCircle(float startX, float startY, float startZ, float radius, Color color) {
lineRenderer.setColor(color);

float tau = (float)Math.PI * 2;
Expand Down Expand Up @@ -2662,10 +2635,12 @@ public void clearSelectedMarkers() {
}

public void refresh() {
gridMesh.dispose();
gridMesh = null;
if (gridMesh != null) {
gridMesh.dispose();
gridMesh = null;
}

gridMesh = genGrid(level.width,level.height);
gridMesh = genGrid(level.width, level.height);

refreshLights();
}
Expand Down Expand Up @@ -2968,7 +2943,7 @@ public void paste() {

Tile copyAt = level.getTileOrNull(cursorTileX, cursorTileY);
if(copyAt != null) {
copy.z += copyAt.getFloorHeight(0.5f, 0.5f);
copy.z = copyAt.getFloorHeight(copy.x, copy.y) + 0.5f;
}

addEntity(copy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,20 @@ public void moveTo(Vector3 destination) {
InterpolationHelper.InterpolationMode.exp10Out
);
}

public void setDefaultPositionAndRotation() {
Level level = Editor.app.level;
int width = level.width;
int height = level.height;

float altitude = 6f;
float distance = 10f;

float lookAngle = (float)Math.asin((float)altitude/distance);
float projectedDistance = distance * (float)Math.cos((float)lookAngle);
float position = projectedDistance / 1.4142f;

setPosition(position + width / 2, position + height / 2, altitude);
setRotation((float)Math.PI + (float)Math.PI / 4f, lookAngle);
}
}
2 changes: 2 additions & 0 deletions DelvEdit/src/com/interrupt/dungeoneer/editor/EditorInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public boolean touchDown(int x, int y, int pointer, int button) {
buttonsDown[button] = true;
if(!buttonEvents.contains(button)) buttonEvents.add(button);

Editor.app.ui.touchDown(x, y, pointer, button);

for (InputProcessor listener : listeners) {
boolean results = listener.touchDown(x, y, pointer, button);
if (results) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,21 +349,7 @@ public void onDontSave() {
}

private void createInternal(int width, int height) {
Editor.app.history = new EditorHistory();
Editor.app.file = new EditorFile();

Editor.app.level = new Level(width,height);
Editor.app.refresh();

Editor.app.history.saveState(Editor.app.level);
Editor.app.file.markClean();

Editor.app.cameraController.setPosition(
Editor.app.level.width / 2f,
Editor.app.level.height / 2f,
4.5f
);
Editor.app.viewSelected();
Editor.app.createEmptyLevel(width, height);
}

public long getMillisSinceLastSave() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.interrupt.dungeoneer.editor.gizmos;

import com.badlogic.gdx.math.Frustum;
import com.interrupt.dungeoneer.editor.ui.Handles;
import com.interrupt.dungeoneer.entities.Camera;
import com.interrupt.dungeoneer.entities.Entity;

@GizmoFor(target = Camera.class)
public class CameraGizmo extends EntityGizmo {
@Override
public void draw(Entity entity) {
super.draw(entity);
Camera camera = (Camera) entity;
Frustum frustum = camera.getCamera().frustum;
Handles.drawWireFrustum(frustum);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.interrupt.dungeoneer.editor.gizmos;

import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.math.Frustum;
import com.interrupt.dungeoneer.editor.ui.Handles;
import com.interrupt.dungeoneer.entities.Entity;
import com.interrupt.dungeoneer.entities.ProjectedDecal;

@GizmoFor(target = ProjectedDecal.class)
public class ProjectedDecalGizmo extends EntityGizmo {
@Override
public void draw(Entity entity) {
super.draw(entity);

ProjectedDecal decal = (ProjectedDecal) entity;
Camera camera = decal.perspective;

if (camera == null) {
return;
}

Frustum frustum = camera.frustum;
Handles.drawWireFrustum(frustum);
}
}
6 changes: 6 additions & 0 deletions DelvEdit/src/com/interrupt/dungeoneer/editor/ui/EditorUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -611,4 +611,10 @@ public void touchUp(int x, int y, int pointer, int button) {
}
}
}

public void touchDown(int x, int y, int pointer, int button) {
if (button == Input.Buttons.RIGHT) {
hideContextMenu();
}
}
}
Loading

0 comments on commit 5b5246f

Please sign in to comment.