【NCC world管理器】
This commit is contained in:
parent
0d1d726d69
commit
01cd3adc46
|
@ -10,7 +10,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||
@EnableScheduling
|
||||
@EnableCaching
|
||||
@MapperScan(basePackages = {"club.joylink.rtss.manage.dao",
|
||||
"club.joylink.rtss.auth.mapper"})
|
||||
"club.joylink.rtss.*.mapper","club.joylink.rtss.simulation.*.mapper"})
|
||||
//@EnableRetry
|
||||
public class RtssApplication {
|
||||
|
||||
|
|
|
@ -30,5 +30,10 @@
|
|||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
package club.joylink.rtss.simulation.ncc.simulation;
|
||||
|
||||
import club.joylink.ecs.World;
|
||||
import club.joylink.ecs.WorldManage;
|
||||
import club.joylink.rtss.simulation.ncc.dto.NccMapDataDto;
|
||||
import club.joylink.rtss.simulation.ncc.module.proto.StorageProto;
|
||||
import club.joylink.rtss.simulation.ncc.repository.IRtsNccMapDataRepository;
|
||||
import club.joylink.rtss.simulation.ncc.simulation.event.NCCCreateEvent;
|
||||
import club.joylink.rtss.simulation.ncc.simulation.event.NCCDestroyEvent;
|
||||
import club.joylink.rtss.simulation.ncc.simulation.event.NCCResetEvent;
|
||||
import club.joylink.rtss.simulation.ncc.simulation.event.NCCUpdateEvent;
|
||||
import club.joylink.rtss.simulation.ncc.simulation.system.TrainStateSystem;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* Ncc world 管理服务类
|
||||
*/
|
||||
@Component
|
||||
public class NCCManagerService {
|
||||
|
||||
@Autowired
|
||||
private IRtsNccMapDataRepository rtsNccMapDataRepository;
|
||||
|
||||
/**
|
||||
* 创建world
|
||||
*/
|
||||
@EventListener
|
||||
public void createWorld(NCCCreateEvent event) {
|
||||
// NccMapDataDto nccMapData = rtsNccMapDataRepository.findById(id);
|
||||
// StorageProto.Storage storage = StorageProto.Storage.parseFrom(nccMapData.getData());
|
||||
// World world = WorldManage.create(generateWorldId(simId));
|
||||
// // 将构建信息放入world
|
||||
// world.getStorage().insertSingleton(storage);
|
||||
// // 添加系统
|
||||
// world.getTaskControl().addSystem(new TrainStateSystem());
|
||||
// world.start();
|
||||
// world.setSpeed(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新world数据
|
||||
*/
|
||||
@EventListener
|
||||
public void updateWorld(NCCUpdateEvent event) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置world数据
|
||||
*/
|
||||
@EventListener
|
||||
public void resetWorld(NCCResetEvent event) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁world
|
||||
*/
|
||||
@EventListener
|
||||
public void destroyWorld(NCCDestroyEvent event) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成world创建ID
|
||||
* @param simId 仿真ID
|
||||
* @return worldId
|
||||
*/
|
||||
private String generateWorldId(@NotNull String simId) {
|
||||
return simId.concat("-ncc");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package club.joylink.rtss.simulation.ncc.simulation.event;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* 创建事件
|
||||
*/
|
||||
public class NCCCreateEvent extends ApplicationEvent {
|
||||
|
||||
public NCCCreateEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package club.joylink.rtss.simulation.ncc.simulation.event;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* NCC销毁时间
|
||||
*/
|
||||
public class NCCDestroyEvent extends ApplicationEvent {
|
||||
|
||||
public NCCDestroyEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package club.joylink.rtss.simulation.ncc.simulation.event;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* NCC重置事件
|
||||
*/
|
||||
public class NCCResetEvent extends ApplicationEvent {
|
||||
|
||||
public NCCResetEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package club.joylink.rtss.simulation.ncc.simulation.event;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* 更新事件
|
||||
*/
|
||||
public class NCCUpdateEvent extends ApplicationEvent {
|
||||
|
||||
public NCCUpdateEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package club.joylink.rtss.simulation.ncc.sys;
|
||||
package club.joylink.rtss.simulation.ncc.simulation.system;
|
||||
|
||||
import club.joylink.ecs.api.WorldQuery;
|
||||
import club.joylink.ecs.api.WorldSystem;
|
||||
|
@ -15,12 +15,12 @@ import java.util.Optional;
|
|||
* 列车行驶位置状态更新
|
||||
*/
|
||||
@Slf4j
|
||||
public class TrainStateSystem implements WorldSystem<Tuple1<TrainStateProto.TrainState.Builder>, Tuple1<StorageProto.Storage.Builder>> {
|
||||
public class TrainStateSystem implements WorldSystem<Tuple1<TrainStateProto.TrainState.Builder>, Tuple1<StorageProto.Storage>> {
|
||||
|
||||
@Override
|
||||
public void update(WorldQuery<Tuple1<TrainStateProto.TrainState.Builder>> query, Tuple1<StorageProto.Storage.Builder> storageTuple1) {
|
||||
public void update(WorldQuery<Tuple1<TrainStateProto.TrainState.Builder>> query, Tuple1<StorageProto.Storage> storageTuple1) {
|
||||
// 所有资源
|
||||
StorageProto.Storage storage = storageTuple1.val1().get().build();
|
||||
StorageProto.Storage storage = storageTuple1.val1().get();
|
||||
// 查找需要更新的车状态信息
|
||||
query.forEach(tuple -> {
|
||||
TrainStateProto.TrainState.Builder trainState = tuple.val1().get();
|
|
@ -3,7 +3,7 @@ import club.joylink.ecs.World;
|
|||
import club.joylink.ecs.WorldManage;
|
||||
import club.joylink.ecs.api.Entity;
|
||||
import club.joylink.rtss.simulation.ncc.module.proto.*;
|
||||
import club.joylink.rtss.simulation.ncc.sys.TrainStateSystem;
|
||||
import club.joylink.rtss.simulation.ncc.simulation.system.TrainStateSystem;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Optional;
|
||||
|
@ -61,7 +61,7 @@ public class TrainStateSystemTest {
|
|||
world.getStorage().createEntity(trainBuilder.getCode(), trainBuilder, TrainStateProto.TrainState.newBuilder());
|
||||
storage.addTrain(trainBuilder);
|
||||
// 将构建信息放入world
|
||||
world.getStorage().insertSingleton(storage);
|
||||
world.getStorage().insertSingleton(storage.build());
|
||||
// 添加系统
|
||||
world.getTaskControl().addSystem(new TrainStateSystem());
|
||||
world.start();
|
||||
|
|
Loading…
Reference in New Issue