Skip to content

Commit

Permalink
#16 Working console
Browse files Browse the repository at this point in the history
  • Loading branch information
KocproZ committed Jul 14, 2018
1 parent d244507 commit df4bdd3
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 45 deletions.
15 changes: 15 additions & 0 deletions console/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
group 'net.warpgame'
version '0.1.2'

apply plugin: 'java'

repositories {
jcenter()
mavenCentral()
}

dependencies {
compile project(':core')
compile project(':net')

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.warpgame.content;
package net.warpgame.engine.console;

import net.warpgame.engine.core.context.service.Service;
import net.warpgame.engine.core.serialization.Deserializer;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.warpgame.engine.console;

import net.warpgame.engine.core.component.Component;
import net.warpgame.engine.core.event.Event;
import net.warpgame.engine.core.event.Listener;
import org.apache.log4j.Logger;

/**
* @author KocproZ
* Created 2018-07-14 at 13:12
*/
public class ConsoleInputEventListener extends Listener<ConsoleInputEvent> {

public ConsoleInputEventListener(Component owner) {
super(owner, Event.getTypeId(ConsoleInputEvent.class));
}

@Override
public void handle(ConsoleInputEvent event) {
Logger.getLogger(ConsoleInputEventListener.class).info(event.getInput());
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package net.warpgame.test.console;
package net.warpgame.engine.console;

import net.warpgame.engine.console.command.Command;
import net.warpgame.engine.console.command.CommandVariable;
import net.warpgame.engine.console.command.SimpleCommand;
import net.warpgame.engine.core.component.SceneComponent;
import net.warpgame.engine.core.component.SceneHolder;
import net.warpgame.engine.core.context.Context;
import net.warpgame.engine.core.context.service.Service;
import org.apache.commons.lang3.ArrayUtils;

Expand All @@ -21,10 +25,12 @@ public class ConsoleService {
private Map<String, CommandVariable> variables = new HashMap<>();
private PrintStream output;
private SceneHolder sceneHolder;
private Context context;
private SceneComponent consoleComponent;

public ConsoleService(SceneHolder holder) {
sceneHolder = holder;
public ConsoleService(SceneHolder holder, Context context) {
this.sceneHolder = holder;
this.context = context;
output = System.out;
}

Expand All @@ -36,8 +42,10 @@ public void printToConsole(String text) {
* Registers basic commands
*/
public void initConsole() {
consoleComponent = new SceneComponent(sceneHolder.getScene());
SimpleCommand help = new SimpleCommand("help", Side.CLIENT,
sceneHolder.getScene().addListener(new ConsoleInputEventListener(sceneHolder.getScene()));
// consoleComponent = new SceneComponent(sceneHolder.getScene());
consoleComponent = sceneHolder.getScene();
SimpleCommand help = new SimpleCommand("help", Command.Side.CLIENT,
"Get help", "help [command]");
help.setExecutor((args) -> {
if (args.length > 0) {
Expand All @@ -51,7 +59,7 @@ public void initConsole() {
}
});

SimpleCommand list = new SimpleCommand("list", Side.CLIENT,
SimpleCommand list = new SimpleCommand("list", Command.Side.CLIENT,
"lists all commands", "list");
list.setExecutor((args) -> {
output.println("Available commands:");
Expand All @@ -60,14 +68,14 @@ public void initConsole() {
}
});

SimpleCommand print = new SimpleCommand("print", Side.CLIENT,
SimpleCommand print = new SimpleCommand("print", Command.Side.CLIENT,
"prints variables to console", "print $variable1 [...]");
print.setExecutor((args) -> {
for (String s : args)
output.printf("%s\n", s);
});

SimpleCommand variables = new SimpleCommand("variables", Side.CLIENT,
SimpleCommand variables = new SimpleCommand("variables", Command.Side.CLIENT,
"Lists all variables", "variables");
variables.setExecutor((args) -> {
output.println("Variables:");
Expand Down Expand Up @@ -117,11 +125,16 @@ void parseAndExecute(String line) {
return;
}

if (command.getSide() == Side.CLIENT) {
if (command.getSide() == Command.Side.LOCAL) {
command.execute(args);
} else {
// consoleComponent.triggerEvent();
//TODO send command to server
} else if (context.isProfileEnabled("client") && command.getSide() == Command.Side.CLIENT) {
command.execute(args);
} else if (context.isProfileEnabled("server") && command.getSide() == Command.Side.SERVER) {
command.execute(args);
} else if (context.isProfileEnabled("client") && command.getSide() == Command.Side.SERVER) {
consoleComponent.triggerEvent(new ConsoleInputEvent(line));
} else if (context.isProfileEnabled("server") && command.getSide() == Command.Side.CLIENT) {
consoleComponent.triggerEvent(new ConsoleInputEvent(line));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.warpgame.test.console;
package net.warpgame.engine.console;

import net.warpgame.engine.core.context.service.Service;
import net.warpgame.engine.core.context.task.RegisterTask;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.warpgame.test.console;
package net.warpgame.engine.console;

import net.warpgame.engine.core.context.executor.RegisterExecutor;
import net.warpgame.engine.core.context.service.Service;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.warpgame.test.console;
package net.warpgame.engine.console.command;

/**
* @author KocproZ
Expand Down Expand Up @@ -35,4 +35,10 @@ public Side getSide() {
return side;
}

public enum Side {
CLIENT, //Executed on client
SERVER, //Executed on server
LOCAL //Executed on side where it was run
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.warpgame.test.console;
package net.warpgame.engine.console.command;

/**
* @author KocproZ
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.warpgame.test.console;
package net.warpgame.engine.console.command;

import java.util.function.Consumer;

Expand Down
1 change: 1 addition & 0 deletions gamecontent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repositories {
dependencies {
compile project(':core')
compile project(':net')
compile project(':console')

compile 'org.slf4j:slf4j-api:1.7.12'
compile 'org.joml:joml:1.8.0'
Expand Down
2 changes: 2 additions & 0 deletions servertest/src/main/java/net/warpgame/servertest/Test.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.warpgame.servertest;

import net.warpgame.engine.console.ConsoleService;
import net.warpgame.engine.core.component.Component;
import net.warpgame.engine.core.component.SceneComponent;
import net.warpgame.engine.core.context.EngineContext;
Expand All @@ -18,6 +19,7 @@ public class Test {
public static void start(EngineRuntime engineRuntime) {
EngineContext engineContext = new EngineContext("dev", "fullPhysics", "server");
engineContext.getLoadedContext().addService(engineRuntime.getIdRegistry());
engineContext.getLoadedContext().findOne(ConsoleService.class).get().initConsole();

// Component root = new SceneComponent(engineContext);
engineContext.getScene().addListener(new ConnectedListener(
Expand Down
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ include 'client'
include 'net'
include 'servertest'
include 'gamecontent'
include 'postbuild'
include 'postbuild'
include 'console'
8 changes: 4 additions & 4 deletions test/src/main/java/net/warpgame/test/MultiplayerTest.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package net.warpgame.test;

import net.warpgame.engine.core.property.TransformProperty;
import net.warpgame.engine.core.property.Transforms;
import net.warpgame.engine.core.component.Component;
import net.warpgame.engine.core.component.Scene;
import net.warpgame.engine.core.component.SceneComponent;
import net.warpgame.engine.core.component.SceneHolder;
import net.warpgame.engine.core.context.EngineContext;
import net.warpgame.engine.core.property.TransformProperty;
import net.warpgame.engine.core.property.Transforms;
import net.warpgame.engine.core.runtime.EngineRuntime;
import net.warpgame.engine.graphics.GraphicsThread;
import net.warpgame.engine.graphics.camera.CameraHolder;
import net.warpgame.engine.graphics.material.Material;
import net.warpgame.engine.graphics.material.MaterialProperty;
import net.warpgame.engine.graphics.mesh.shapes.SphereBuilder;
import net.warpgame.engine.graphics.mesh.MeshProperty;
import net.warpgame.engine.graphics.mesh.StaticMesh;
import net.warpgame.engine.graphics.mesh.shapes.SphereBuilder;
import net.warpgame.engine.graphics.rendering.screenspace.cubemap.CubemapProperty;
import net.warpgame.engine.graphics.rendering.screenspace.light.LightSource;
import net.warpgame.engine.graphics.rendering.screenspace.light.LightSourceProperty;
Expand All @@ -40,7 +40,7 @@ public class MultiplayerTest {

public static void start(EngineRuntime engineRuntime) {
System.out.println();
EngineContext engineContext = new EngineContext("dev", "fullPhysics");
EngineContext engineContext = new EngineContext("dev", "fullPhysics", "client");
engineContext.getLoadedContext().addService(engineRuntime.getIdRegistry());
GraphicsThread thread = engineContext.getLoadedContext()
.findOne(GraphicsThread.class)
Expand Down
23 changes: 13 additions & 10 deletions test/src/main/java/net/warpgame/test/Test1.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package net.warpgame.test;

import net.warpgame.engine.audio.*;
import net.warpgame.engine.core.property.Property;
import net.warpgame.engine.core.property.TransformProperty;
import net.warpgame.engine.core.property.Transforms;
import net.warpgame.engine.audio.AudioClip;
import net.warpgame.engine.audio.AudioListenerProperty;
import net.warpgame.engine.audio.AudioSourceProperty;
import net.warpgame.engine.console.ConsoleService;
import net.warpgame.engine.console.command.Command;
import net.warpgame.engine.console.command.CommandVariable;
import net.warpgame.engine.console.command.SimpleCommand;
import net.warpgame.engine.core.component.*;
import net.warpgame.engine.core.context.Context;
import net.warpgame.engine.core.context.EngineContext;
import net.warpgame.engine.core.execution.EngineThread;
import net.warpgame.engine.core.property.Property;
import net.warpgame.engine.core.property.TransformProperty;
import net.warpgame.engine.core.property.Transforms;
import net.warpgame.engine.core.runtime.EngineRuntime;
import net.warpgame.engine.core.script.Script;
import net.warpgame.engine.core.script.annotation.OwnerProperty;
Expand Down Expand Up @@ -43,13 +49,10 @@
import net.warpgame.engine.graphics.texture.Texture2D;
import net.warpgame.engine.graphics.utility.projection.PerspectiveMatrix;
import net.warpgame.engine.graphics.window.Display;
import net.warpgame.test.console.*;
import net.warpgame.test.console.MoveCameraCommand;
import org.joml.Vector3f;
import org.lwjgl.openal.AL10;
import org.lwjgl.openal.AL11;
import org.lwjgl.opengl.GL11;

import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
Expand All @@ -69,7 +72,7 @@ public class Test1 {

public static void start(EngineRuntime engineRuntime) {
System.out.println();
EngineContext engineContext = new EngineContext("dev", "client");
EngineContext engineContext = new EngineContext("dev", "client", "server");
engineContext.getLoadedContext().addService(engineRuntime.getIdRegistry());
GraphicsThread thread = engineContext.getLoadedContext()
.findOne(GraphicsThread.class)
Expand Down Expand Up @@ -213,7 +216,7 @@ private static void genJointNameToJointIds(Joint joint, Map<String, Integer> nam
private static void registerCommandsAndVariables(Context context) {
consoleService.initConsole();
SimpleCommand exit = new SimpleCommand("quit",
Side.CLIENT,
Command.Side.CLIENT,
"Stops the engine and quits",
"quit");
exit.setExecutor((args) -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package net.warpgame.test.console;

import net.warpgame.engine.core.property.TransformProperty;
import net.warpgame.engine.console.ConsoleService;
import net.warpgame.engine.console.command.Command;
import net.warpgame.engine.console.command.CommandVariable;
import net.warpgame.engine.core.property.Property;
import net.warpgame.engine.core.property.TransformProperty;
import net.warpgame.engine.graphics.camera.CameraHolder;
import org.joml.Vector3f;

Expand All @@ -11,7 +14,7 @@
*/
public class MoveCameraCommand extends Command {

private CameraHolder cameraHolder; //TODO make output available
private CameraHolder cameraHolder;
private ConsoleService consoleService;

public MoveCameraCommand(CameraHolder holder, ConsoleService consoleService) {
Expand Down
9 changes: 0 additions & 9 deletions test/src/main/java/net/warpgame/test/console/Side.java

This file was deleted.

2 changes: 1 addition & 1 deletion test/src/main/resources/warp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ graphics:
smaa:
preset: !!net.warpgame.engine.graphics.rendering.antialiasing.smaa.SMAAPreset MEDIUM
multiplayer:
ip: 10.48.1.1
ip: 127.0.0.1
port: 6688
script.ups: 40

0 comments on commit df4bdd3

Please sign in to comment.