rts-sim-module/examples/main.go
2023-12-27 09:57:56 +08:00

55 lines
1.6 KiB
Go

package main
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/fi"
"joylink.club/rtsssimulation/repository/model/proto"
"joylink.club/rtsssimulation/sys"
"time"
rtss_simulation "joylink.club/rtsssimulation"
"joylink.club/rtsssimulation/repository"
)
func main() {
protoRepo := &proto.Repository{}
protoRepo.Id = "1"
protoRepo.Version = "V1"
protoRepo.Fans = append(protoRepo.Fans, &proto.Fan{Id: "fan1", FanType: proto.Fan_CommonFan})
protoRepo.Fans = append(protoRepo.Fans, &proto.Fan{Id: "fan2", FanType: proto.Fan_FcBypassFan})
protoRepo.Fans = append(protoRepo.Fans, &proto.Fan{Id: "fan3", FanType: proto.Fan_SoftStartFan})
protoRepo.Fans = append(protoRepo.Fans, &proto.Fan{Id: "fan4", FanType: proto.Fan_HighLowSpeedFan})
//
repo, _ := repository.BuildRepository(protoRepo)
sim, _ := newIscsSimulation(repo)
sim.StartUp()
time.Sleep(2 * time.Second)
fi.MotorOperate(sim, "fan2", fi.FiMsOnForward, 60)
time.Sleep(8 * time.Second)
fi.MotorOperate(sim, "fan2", fi.FiMsOnReverse, 60)
time.Sleep(8 * time.Second)
sim.Close()
time.Sleep(2 * time.Second)
}
func newIscsSimulation(repo *repository.Repository) (ecs.World, error) {
w := ecs.NewWorld(100)
sys.BindIscsSystem(w)
//
// 初始化世界数据单例组件
entity.LoadWorldData(w, repo)
err := entity.LoadIscs(w)
return w, err
}
///////////////////////////////////////////////////////
func main1() {
sim, _ := rtss_simulation.NewSimulation(&repository.Repository{})
sim.StartUp()
sim.SetSpeed(2)
time.Sleep(1 * time.Second)
sim.Close()
time.Sleep(2 * time.Second)
}