diff --git a/GameEngine/resources/GameEngineTest.model b/GameEngine/resources/GameEngineTest.model new file mode 100644 index 0000000..4b5a525 --- /dev/null +++ b/GameEngine/resources/GameEngineTest.model @@ -0,0 +1,39 @@ +channel KeyEvent { + out state(curState:Int,keyEvent(nextState)) = nextState +} +channel SceneUpdateEvent { + out time(time:Long,updateEvent(dt:Long)) = (time+dt) +} +channel TimerEvent { + out count(count:Long,tick()) = (count+1) +} +channel EntitySpriteUpdate { + in mesh(curMesh:Json,updateSprite(spritePath:Str)) = {"sprite": spritePath, "type": "sprite"} +} +channel EntityScaleUpdate { + in scale(curScale:Json,updateScale(nextScale.{x},nextScale.{y},nextScale.{z})) = nextScale +} +channel EntityPositionUpdate { + in position(curPos:Json,updatePosition(nextPos.{x},nextPos.{y},nextPos.{z})) = nextPos +} +channel CameraProjectionUpdate { + in projection(curProj:Json,updateProjection(curProj,nextProj)) = nextProj +} +channel TimersUpdated { + in timers(curTimers:Map,update(curTimers,nextTimers)) = nextTimers +} +channel CameraPositionUpdate { + in position(curPos:Json,updatePosition(nextPos.{x},nextPos.{y},nextPos.{z})) = nextPos +} +channel SceneUpdate { + in scene(curSc:Json,update(curSc,nextSc)) = nextSc +} +channel CameraScaleUpdate { + in scale(curScale:Json,updateScale(nextScale.{x},nextScale.{y},nextScale.{z})) = nextScale +} +channel EntityRotationUpdate { + in rotation(curRot:Json,updateRotation(nextRot.{x},nextRot.{y},nextRot.{z})) = nextRot +} +channel CameraRotationUpdate { + in rotation(curRot:Json,updateRotation(nextRot.{x},nextRot.{y},nextRot.{z})) = nextRot +} diff --git a/GameEngine/src/main/java/Main.java b/GameEngine/src/main/java/Main.java deleted file mode 100644 index 2c9c264..0000000 --- a/GameEngine/src/main/java/Main.java +++ /dev/null @@ -1,8 +0,0 @@ -import gameEngine.views.Window; - -public class Main { - public static void main(String[] args) { - Window window = Window.get(); - window.runFromEditor(); - } -} \ No newline at end of file diff --git a/GameEngine/src/main/java/gameEngine/GameEditor.java b/GameEngine/src/main/java/gameEngine/GameEditor.java index 4447641..512ddcc 100644 --- a/GameEngine/src/main/java/gameEngine/GameEditor.java +++ b/GameEngine/src/main/java/gameEngine/GameEditor.java @@ -157,7 +157,7 @@ dtramButton.clearListeners(); GameEngineModelFileGenerator modelFileGenerator = new GameEngineModelFileGenerator(); - dtramButton.addListener(modelFileGenerator.generate()); + dtramButton.addListener(modelFileGenerator::generate); createMeshComponentViewButton.clearListeners(); createMeshComponentViewButton.addListener(scene::addNewMeshComponent); diff --git a/GameEngine/src/main/java/gameEngine/GameEngineModelFileGenerator.java b/GameEngine/src/main/java/gameEngine/GameEngineModelFileGenerator.java index 4362c1a..69e47c5 100644 --- a/GameEngine/src/main/java/gameEngine/GameEngineModelFileGenerator.java +++ b/GameEngine/src/main/java/gameEngine/GameEngineModelFileGenerator.java @@ -1,6 +1,5 @@ package gameEngine; -import algorithms.TypeInference; import models.algebra.Expression; import models.algebra.Variable; import models.dataConstraintModel.ChannelMember; @@ -13,13 +12,18 @@ import parser.exceptions.ExpectedDoubleQuotation; import parser.exceptions.ExpectedRightBracket; import parser.exceptions.WrongJsonExpression; -import simulator.Simulator; -import simulator.SystemState; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; public class GameEngineModelFileGenerator { DataTransferModel model; + private final String modelFilePath = "GameEngine/resources/"; - public Runnable generate(){ + public void generate(){ try { Parser.TokenStream stream = new Parser.TokenStream(); Parser parser = new Parser(stream); @@ -51,33 +55,61 @@ ResourcePath timer_count = new ResourcePath(timer, "count"); //"timer.{tid}.count model.addResourcePath(scene_time); + model.addResourcePath(scene_camera); + model.addResourcePath(scene_camera_transform); model.addResourcePath(scene_camera_transform_position); model.addResourcePath(scene_camera_transform_rotation); model.addResourcePath(scene_camera_transform_scale); model.addResourcePath(scene_camera_projection); + model.addResourcePath(entity_transform); model.addResourcePath(entity_transform_position); model.addResourcePath(entity_transform_rotation); model.addResourcePath(entity_transform_scale); model.addResourcePath(entity_mesh); model.addResourcePath(key_state); + model.addResourcePath(timers); model.addResourcePath(timer_count); - addNativeOutputChannel(stream, parser, scene_time, "SceneUpdateEvent", "time: Long", "updateEvent(dt: Long)", "time + dt"); + addNativeInputChannel(stream, parser, scene_time, new DataTransferChannel("SceneUpdateEvent"), "time: Long", "updateEvent(dt: Long)", "time + dt"); + addNativeOutputChannel(stream, parser, scene,new DataTransferChannel("SceneUpdate"), "curSc: Json", "update(curSc, nextSc)", "nextSc"); + addNativeOutputChannel(stream, parser, scene_camera_transform_position,new DataTransferChannel("CameraPositionUpdate"),"curPos: Json","updatePosition(nextPos.x, nextPos.y, nextPos.z)","nextPos"); + addNativeOutputChannel(stream, parser, scene_camera_transform_rotation,new DataTransferChannel("CameraRotationUpdate"),"curRot: Json","updateRotation(nextRot.x, nextRot.y, nextRot.z)","nextRot"); + addNativeOutputChannel(stream, parser, scene_camera_transform_scale,new DataTransferChannel("CameraScaleUpdate"),"curScale: Json","updateScale(nextScale.x, nextScale.y, nextScale.z)","nextScale"); + addNativeOutputChannel(stream, parser, scene_camera_projection,new DataTransferChannel("CameraProjectionUpdate"),"curProj: Json","updateProjection(curProj, nextProj)","nextProj"); + addNativeOutputChannel(stream, parser, entity_transform_position, new DataTransferChannel("EntityPositionUpdate", new Variable("eid")),"curPos: Json","updatePosition(nextPos.x, nextPos.y, nextPos.z)","nextPos"); + addNativeOutputChannel(stream, parser, entity_transform_rotation,new DataTransferChannel("EntityRotationUpdate", new Variable("eid")),"curRot: Json","updateRotation(nextRot.x, nextRot.y, nextRot.z)","nextRot"); + addNativeOutputChannel(stream, parser, entity_transform_scale,new DataTransferChannel("EntityScaleUpdate", new Variable("eid")),"curScale: Json","updateScale(nextScale.x, nextScale.y, nextScale.z)","nextScale"); + addNativeOutputChannel (stream, parser, entity_mesh,new DataTransferChannel("EntitySpriteUpdate", new Variable("eid")),"curMesh: Json","updateSprite(spritePath: Str)","{\"type\": \"sprite\", \"sprite\": spritePath}"); + addNativeInputChannel(stream, parser, key_state,new DataTransferChannel("KeyEvent", new Variable("kno")),"curState: Int","keyEvent(nextState)","nextState"); + addNativeOutputChannel(stream, parser, timers ,new DataTransferChannel("TimersUpdated"),"curTimers: Map","update(curTimers, nextTimers)","nextTimers"); + addNativeInputChannel(stream, parser, timer_count,new DataTransferChannel("TimerEvent" , new Variable("tid")),"count: Long","tick()","count + 1"); - TypeInference.infer(model); - Simulator simulator = new Simulator(model); - simulator.init(); - SystemState s = simulator.getCurState(); } catch (Exception e) { e.printStackTrace(); } - return null; + save(); + + } + + public void save() { + String outputFileName = modelFilePath + File.separator + "GameEngineTest.model"; + + try { + File file = new File(outputFileName); + FileWriter fileWriter = new FileWriter(file); + fileWriter.write(model.getSourceText()); + fileWriter.close(); + + System.out.println("Model file saved as: " + outputFileName); + } catch (IOException e) { + e.printStackTrace(); + } } private void addNativeOutputChannel(TokenStream stream, Parser parser, ResourcePath path, - String channelName, String curStateName, String messageName, String nextStateName) throws ExpectedRightBracket, WrongJsonExpression, ExpectedColon, ExpectedDoubleQuotation { - DataTransferChannel outputChannel = new DataTransferChannel(channelName); + DataTransferChannel dataTransferChannel, String curStateName, String messageName, String nextStateName) throws ExpectedRightBracket, WrongJsonExpression, ExpectedColon, ExpectedDoubleQuotation { + DataTransferChannel outputChannel = dataTransferChannel; outputChannel.setNative(true); ChannelMember out = new ChannelMember(path); stream.addLine(curStateName); @@ -94,8 +126,8 @@ } private void addNativeInputChannel(TokenStream stream, Parser parser, ResourcePath path, - String channelName, String curStateName, String messageName, String nextStateName) throws ExpectedRightBracket, WrongJsonExpression, ExpectedColon, ExpectedDoubleQuotation { - DataTransferChannel inputChannel = new DataTransferChannel(channelName); + DataTransferChannel dataTransferChannel, String curStateName, String messageName, String nextStateName) throws ExpectedRightBracket, WrongJsonExpression, ExpectedColon, ExpectedDoubleQuotation { + DataTransferChannel inputChannel = dataTransferChannel; inputChannel.setNative(true); ChannelMember in = new ChannelMember(path); stream.addLine(curStateName); @@ -109,6 +141,7 @@ in.getStateTransition().setNextStateExpression(nextState); inputChannel.addChannelMemberAsOutput(in); model.addInputChannel(inputChannel); + } } diff --git a/GameEngine/src/main/java/main/Main.java b/GameEngine/src/main/java/main/Main.java new file mode 100644 index 0000000..5059548 --- /dev/null +++ b/GameEngine/src/main/java/main/Main.java @@ -0,0 +1,10 @@ +package main; + +import gameEngine.views.Window; + +public class Main { + public static void main(String[] args) { + Window window = Window.get(); + window.runFromEditor(); + } +} \ No newline at end of file