Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/main/java/com/terminalvelocitycabbage/editor/Editor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.terminalvelocitycabbage.editor;

import com.terminalvelocitycabbage.editor.registry.*;
import com.terminalvelocitycabbage.engine.client.ClientBase;
import com.terminalvelocitycabbage.engine.client.window.WindowProperties;
import com.terminalvelocitycabbage.engine.event.EventDispatcher;
import com.terminalvelocitycabbage.engine.filesystem.resources.ResourceSource;
import com.terminalvelocitycabbage.engine.filesystem.sources.MainSource;
import com.terminalvelocitycabbage.engine.registry.Identifier;
import com.terminalvelocitycabbage.templates.events.*;

public abstract class Editor<T extends ClientBase> extends ClientBase {

public static Identifier ENGINE_RESOURCE_SOURCE;

public static Identifier EDITOR_SCENE;

protected T gameClient;

public static final String ID = "editor";

public Editor(T gameClient) {
super(ID, 20);
this.gameClient = gameClient;
}

@Override
public void registerEventListeners(EventDispatcher dispatcher) {
gameClient.registerEventListeners(dispatcher);

dispatcher.listenToEvent(ResourceCategoryRegistrationEvent.EVENT, event -> EditorResources.registerResourceCategories((ResourceCategoryRegistrationEvent) event));
dispatcher.listenToEvent(ResourceSourceRegistrationEvent.EVENT, event -> {
ResourceSource mainSource = new MainSource(getInstance(), getNamespace());
mainSource.registerDefaultSources(getNamespace());
ENGINE_RESOURCE_SOURCE = ((ResourceSourceRegistrationEvent) event).registerResourceSource(getNamespace(), "editor", mainSource);
});
dispatcher.listenToEvent(EntityComponentRegistrationEvent.EVENT, event -> EditorEntities.registerComponents((EntityComponentRegistrationEvent) event));
dispatcher.listenToEvent(EntitySystemRegistrationEvent.EVENT, event -> EditorEntities.createSystems((EntitySystemRegistrationEvent) event));
dispatcher.listenToEvent(RoutineRegistrationEvent.EVENT, event -> EditorRoutines.init((RoutineRegistrationEvent) event));
dispatcher.listenToEvent(RendererRegistrationEvent.EVENT, event -> EditorRenderers.init((RendererRegistrationEvent) event));
dispatcher.listenToEvent(SceneRegistrationEvent.EVENT, event -> {
EditorScenes.init((SceneRegistrationEvent) event);
EDITOR_SCENE = EditorScenes.EDITOR_SCENE;
});
dispatcher.listenToEvent(LocalizedTextKeyRegistrationEvent.EVENT, event -> EditorLocalizedTexts.registerLocalizedTextKeys((LocalizedTextKeyRegistrationEvent) event));
dispatcher.listenToEvent(MeshRegistrationEvent.EVENT, event -> EditorMeshes.init((MeshRegistrationEvent) event));
dispatcher.listenToEvent(AnimationConfigurationEvent.EVENT, event -> EditorModels.initAnimations((AnimationConfigurationEvent) event));
dispatcher.listenToEvent(ModelConfigRegistrationEvent.EVENT, event -> EditorModels.init((ModelConfigRegistrationEvent) event));

EditorFonts.init(dispatcher);
EditorInput.init(dispatcher);
EditorTextures.init(dispatcher);
EditorStates.init(dispatcher);
}

@Override
public void init() {
super.init();
WindowProperties properties = new WindowProperties(1800, 900, "Terminal Velocity Engine", EDITOR_SCENE);
long window = getWindowManager().createNewWindow(properties);
getWindowManager().focusWindow(window);
}

public T getGameClient() {
return gameClient;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.terminalvelocitycabbage.editor.data;

import com.terminalvelocitycabbage.engine.client.renderer.elements.VertexAttribute;
import com.terminalvelocitycabbage.engine.client.renderer.elements.VertexFormat;

public class EditorMeshData {

public static final VertexFormat MESH_FORMAT = VertexFormat.builder()
.addElement(VertexAttribute.XYZ_POSITION)
.addElement(VertexAttribute.XYZ_NORMAL)
.addElement(VertexAttribute.RGB_COLOR)
.addElement(VertexAttribute.UV)
.build();

public static final VertexFormat ANIMATED_MESH_FORMAT = VertexFormat.builder()
.addElement(VertexAttribute.XYZ_POSITION)
.addElement(VertexAttribute.XYZ_NORMAL)
.addElement(VertexAttribute.RGB_COLOR)
.addElement(VertexAttribute.UV)
.addElement(VertexAttribute.BONE_INDEX)
.build();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.terminalvelocitycabbage.editor.ecs.components;

import com.terminalvelocitycabbage.editor.hints.EditorHint;
import com.terminalvelocitycabbage.engine.client.renderer.Projection;
import com.terminalvelocitycabbage.templates.ecs.components.CameraComponent;
import com.terminalvelocitycabbage.engine.util.Transformation;
import org.joml.Matrix4f;

@EditorHint.ComponentName(name = "Editor Camera")
public class EditorCameraComponent extends CameraComponent {

public EditorCameraComponent() {
super(new Projection(Projection.Type.PERSPECTIVE, 70, 0.1f, 1000f));
}

@Override
public void updateProjectionMatrix(int width, int height) {
getProjection().updateProjectionMatrix(width, height);
}

@Override
public Matrix4f getViewMatrix(Transformation transformation) {
var pos = transformation.getPosition();
return viewMatrix.identity()
.rotate(transformation.getRotation().invert(new org.joml.Quaternionf()))
.translate(-pos.x, -pos.y, -pos.z);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.terminalvelocitycabbage.editor.hints;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public class EditorHint {

@Retention(RetentionPolicy.RUNTIME)
public @interface ComponentName {
String name();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.terminalvelocitycabbage.editor.registry;

import com.terminalvelocitycabbage.editor.ecs.components.EditorCameraComponent;
import com.terminalvelocitycabbage.templates.ecs.components.CameraComponent;
import com.terminalvelocitycabbage.templates.ecs.components.DirectionalLightComponent;
import com.terminalvelocitycabbage.templates.ecs.components.NameComponent;
import com.terminalvelocitycabbage.templates.events.EntityComponentRegistrationEvent;
import com.terminalvelocitycabbage.templates.events.EntitySystemRegistrationEvent;

public class EditorEntities {

public static void registerComponents(EntityComponentRegistrationEvent event) {
event.registerComponent(NameComponent.class);
event.registerComponent(CameraComponent.class);
event.registerComponent(EditorCameraComponent.class);
event.registerComponent(DirectionalLightComponent.class);
}

public static void createSystems(EntitySystemRegistrationEvent event) {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.terminalvelocitycabbage.editor.registry;

import com.terminalvelocitycabbage.editor.Editor;
import com.terminalvelocitycabbage.engine.event.EventDispatcher;
import com.terminalvelocitycabbage.engine.registry.Identifier;
import com.terminalvelocitycabbage.templates.events.FontRegistrationEvent;

import static com.terminalvelocitycabbage.engine.filesystem.resources.ResourceCategory.FONT;

public class EditorFonts {

public static final Identifier THIN = FONT.identifierOf(Editor.ID, "outfit_thin");
public static final Identifier EXTRA_LIGHT = FONT.identifierOf(Editor.ID, "outfit_extralight");
public static final Identifier LIGHT = FONT.identifierOf(Editor.ID, "outfit_light");
public static final Identifier REGULAR = FONT.identifierOf(Editor.ID, "outfit_regular");
public static final Identifier MEDIUM = FONT.identifierOf(Editor.ID, "outfit_medium");
public static final Identifier SEMI_BOLD = FONT.identifierOf(Editor.ID, "outfit_semibold");
public static final Identifier BOLD = FONT.identifierOf(Editor.ID, "outfit_bold");
public static final Identifier EXTRA_BOLD = FONT.identifierOf(Editor.ID, "outfit_extrabold");
public static final Identifier BLACK = FONT.identifierOf(Editor.ID, "outfit_black");

public static void init(EventDispatcher eventDispatcher) {
registerFont(eventDispatcher, THIN);
registerFont(eventDispatcher, EXTRA_LIGHT);
registerFont(eventDispatcher, LIGHT);
registerFont(eventDispatcher, REGULAR);
registerFont(eventDispatcher, MEDIUM);
registerFont(eventDispatcher, SEMI_BOLD);
registerFont(eventDispatcher, BOLD);
registerFont(eventDispatcher, EXTRA_BOLD);
registerFont(eventDispatcher, BLACK);
}

public static void registerFont(EventDispatcher eventDispatcher, Identifier name) {
eventDispatcher.listenToEvent(FontRegistrationEvent.EVENT, e -> ((FontRegistrationEvent) e).registerFont(name));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.terminalvelocitycabbage.editor.registry;

import com.terminalvelocitycabbage.editor.Editor;
import com.terminalvelocitycabbage.engine.client.input.control.Control;
import com.terminalvelocitycabbage.engine.client.input.control.MouseButtonControl;
import com.terminalvelocitycabbage.engine.client.input.control.MouseScrollControl;
import com.terminalvelocitycabbage.engine.client.input.controller.ControlGroup;
import com.terminalvelocitycabbage.engine.client.input.types.MouseInput;
import com.terminalvelocitycabbage.engine.event.EventDispatcher;
import com.terminalvelocitycabbage.engine.registry.Identifier;
import com.terminalvelocitycabbage.templates.events.InputHandlerRegistrationEvent;
import com.terminalvelocitycabbage.templates.inputcontrollers.UIClickController;
import com.terminalvelocitycabbage.templates.inputcontrollers.UIScrollController;

public class EditorInput {

public static Identifier UI_CLICK;
public static Identifier UI_SCROLL;

public static void init(EventDispatcher eventDispatcher) {

eventDispatcher.listenToEvent(InputHandlerRegistrationEvent.EVENT, e -> {
InputHandlerRegistrationEvent event = (InputHandlerRegistrationEvent) e;

var inputHandler = event.getInputHandler();

Control leftClickControl = inputHandler.registerControlListener(new MouseButtonControl(MouseInput.Button.LEFT_CLICK));
Control mouseScrollUpControl = inputHandler.registerControlListener(new MouseScrollControl(MouseInput.ScrollDirection.UP, 1f));
Control mouseScrollDownControl = inputHandler.registerControlListener(new MouseScrollControl(MouseInput.ScrollDirection.DOWN, 1f));

UI_CLICK = inputHandler.registerController(Editor.getInstance().getNamespace(), "ui_click", new UIClickController(MouseInput.Button.LEFT_CLICK, leftClickControl));
UI_SCROLL = inputHandler.registerController(Editor.getInstance().getNamespace(), "scroll", new UIScrollController(
new ControlGroup(mouseScrollUpControl),
new ControlGroup(mouseScrollDownControl)
));
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.terminalvelocitycabbage.editor.registry;

import com.terminalvelocitycabbage.templates.events.LocalizedTextKeyRegistrationEvent;

public class EditorLocalizedTexts {

public static void registerLocalizedTextKeys(LocalizedTextKeyRegistrationEvent event) {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.terminalvelocitycabbage.editor.registry;

import com.terminalvelocitycabbage.templates.events.MeshRegistrationEvent;

public class EditorMeshes {

public static void init(MeshRegistrationEvent event) {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.terminalvelocitycabbage.editor.registry;

import com.terminalvelocitycabbage.templates.events.AnimationConfigurationEvent;
import com.terminalvelocitycabbage.templates.events.ModelConfigRegistrationEvent;

public class EditorModels {

public static void init(ModelConfigRegistrationEvent event) {

}

public static void initAnimations(AnimationConfigurationEvent event) {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.terminalvelocitycabbage.editor.registry;

import com.terminalvelocitycabbage.editor.Editor;
import com.terminalvelocitycabbage.editor.rendernodes.DrawEditorUIRenderNode;
import com.terminalvelocitycabbage.editor.rendernodes.EditorDrawSceneRenderNode;
import com.terminalvelocitycabbage.engine.client.renderer.RenderGraph;
import com.terminalvelocitycabbage.engine.client.renderer.shader.ShaderProgramConfig;
import com.terminalvelocitycabbage.engine.registry.Identifier;
import com.terminalvelocitycabbage.templates.events.RendererRegistrationEvent;

public class EditorRenderers {

public static Identifier DRAW_SCENE_RENDER_NODE;
public static Identifier DRAW_EDITOR_UI_RENDER_NODE;

public static Identifier EDITOR_RENDER_GRAPH;

public static void init(RendererRegistrationEvent event) {

DRAW_SCENE_RENDER_NODE = event.registerNode(Editor.ID, "draw_scene");
DRAW_EDITOR_UI_RENDER_NODE = event.registerNode(Editor.ID, "draw_editor_ui");

EDITOR_RENDER_GRAPH = event.registerGraph(Editor.ID, "draw_scene",
new RenderGraph(RenderGraph.RenderPath.builder()
.addRenderNode(DRAW_SCENE_RENDER_NODE, EditorDrawSceneRenderNode.class, EditorShaders.MESH_SHADER_PROGRAM_CONFIG)
.addRenderNode(DRAW_EDITOR_UI_RENDER_NODE, DrawEditorUIRenderNode.class, ShaderProgramConfig.EMPTY)
)
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.terminalvelocitycabbage.editor.registry;

import com.terminalvelocitycabbage.editor.Editor;
import com.terminalvelocitycabbage.engine.filesystem.resources.ResourceCategory;
import com.terminalvelocitycabbage.templates.events.ResourceCategoryRegistrationEvent;

public class EditorResources {

public static void registerResourceCategories(ResourceCategoryRegistrationEvent event) {
ResourceCategory.registerEngineDefaults(event.getRegistry(), Editor.ID);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.terminalvelocitycabbage.editor.registry;

import com.terminalvelocitycabbage.editor.Editor;
import com.terminalvelocitycabbage.templates.events.RoutineRegistrationEvent;

public class EditorRoutines {

public static void init(RoutineRegistrationEvent event) {
event.registerRoutineFromFile(Editor.ID, "editor_default");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.terminalvelocitycabbage.editor.registry;

import com.terminalvelocitycabbage.editor.Editor;
import com.terminalvelocitycabbage.engine.registry.Identifier;
import com.terminalvelocitycabbage.templates.events.SceneRegistrationEvent;

public class EditorScenes {

public static Identifier EDITOR_SCENE;

public static void init(SceneRegistrationEvent event) {
EDITOR_SCENE = event.registerSceneFromFile(Editor.ID, "editor");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.terminalvelocitycabbage.editor.registry;

import com.terminalvelocitycabbage.editor.Editor;
import com.terminalvelocitycabbage.engine.client.renderer.shader.Shader;
import com.terminalvelocitycabbage.engine.client.renderer.shader.ShaderProgramConfig;
import com.terminalvelocitycabbage.engine.client.renderer.shader.Uniform;
import com.terminalvelocitycabbage.engine.registry.Identifier;

import static com.terminalvelocitycabbage.editor.data.EditorMeshData.ANIMATED_MESH_FORMAT;
import static com.terminalvelocitycabbage.editor.data.EditorMeshData.MESH_FORMAT;
import static com.terminalvelocitycabbage.engine.filesystem.resources.ResourceCategory.SHADER;

public class EditorShaders {

public static final Identifier TEST_VERTEX_SHADER = SHADER.identifierOf(Editor.ID, "default_vertex");
public static final Identifier ANIMATED_VERTEX_SHADER = SHADER.identifierOf(Editor.ID, "animated_vertex");
public static final Identifier TEST_FRAGMENT_SHADER = SHADER.identifierOf(Editor.ID, "default_fragment");
public static final ShaderProgramConfig MESH_SHADER_PROGRAM_CONFIG = ShaderProgramConfig.builder()
.vertexFormat(MESH_FORMAT)
.addShader(Shader.Type.VERTEX, EditorShaders.TEST_VERTEX_SHADER)
.addShader(Shader.Type.FRAGMENT, EditorShaders.TEST_FRAGMENT_SHADER)
.addUniform(new Uniform("textureSampler"))
.addUniform(new Uniform("projectionMatrix"))
.addUniform(new Uniform("viewMatrix"))
.addUniform(new Uniform("modelMatrix"))
.addUniform(new Uniform("directionalLight"))
.build();

public static final ShaderProgramConfig ANIMATED_MESH_SHADER_PROGRAM_CONFIG = ShaderProgramConfig.builder()
.vertexFormat(ANIMATED_MESH_FORMAT)
.addShader(Shader.Type.VERTEX, EditorShaders.ANIMATED_VERTEX_SHADER)
.addShader(Shader.Type.FRAGMENT, EditorShaders.TEST_FRAGMENT_SHADER)
.addUniform(new Uniform("textureSampler"))
.addUniform(new Uniform("projectionMatrix"))
.addUniform(new Uniform("viewMatrix"))
.addUniform(new Uniform("modelMatrix"))
.addUniform(new Uniform("boneMatrices"))
.addUniform(new Uniform("directionalLight"))
.build();

}
Loading