From 0dfade56adbe3ee4cc99f80accca78a03c7abbc1 Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Tue, 26 Sep 2023 14:00:40 +0800 Subject: [PATCH] =?UTF-8?q?spks=E7=94=B5=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system/spks_system.go | 70 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/system/spks_system.go b/system/spks_system.go index fb05a5b..6b174ad 100644 --- a/system/spks_system.go +++ b/system/spks_system.go @@ -13,6 +13,10 @@ type SpksCircuitState struct { SPKSS2JA bool //ture-按钮开关接通常开点 SPKSS4JA bool + //ture-按钮开关接通常开点 + SPKSXPLA bool + //ture-按钮开关接通常开点 + SPKSSPLA bool //true-灯亮 SPKSX1D bool //true-灯亮 @@ -41,13 +45,77 @@ type SpksCircuitState struct { SPKSSPLAJ bool } type SpksCircuitSystem struct { + query *ecs.Query } var ( SpksCircuitStateComponent = ecs.NewComponentType[SpksCircuitState]() ) +func NewSpksCircuitState() *SpksCircuitState { + return &SpksCircuitState{ + SPKSX1JA: true, + SPKSX3JA: true, + SPKSS2JA: true, + SPKSS4JA: true, + SPKSXPLA: false, + SPKSSPLA: false, + SPKSX1D: false, + SPKSX3D: false, + SPKSS2D: false, + SPKSS4D: false, + SPKSXPLAD: false, + SPKSSPLAD: false, + SDA: false, + SPKSX1J: true, + SPKSX3J: true, + SPKSS2J: true, + SPKSS4J: true, + SPKSXPLAJ: false, + SPKSSPLAJ: false, + } +} + // Update world 执行 func (me *SpksCircuitSystem) Update(w ecs.World) { - + me.query.Each(w, func(e *ecs.Entry) { + state := SpksCircuitStateComponent.Get(e) + _state := &(*state) + // + me.calculateSpksD(state) + me.calculateSPKSXJ(state) + me.calculateSPKSSJ(state) + me.calculateSPKSPLAJ(state) + me.calculateChange(state, _state) + }) +} + +// 亮灯运算 +func (me *SpksCircuitSystem) calculateSpksD(state *SpksCircuitState) { + state.SPKSX1D = state.SDA || !state.SPKSX1J + state.SPKSX3D = state.SDA || !state.SPKSX3J + state.SPKSS2D = state.SDA || !state.SPKSS2J + state.SPKSS4D = state.SDA || !state.SPKSS4J + state.SPKSXPLAD = state.SDA || state.SPKSXPLAJ + state.SPKSSPLAD = state.SDA || state.SPKSSPLAJ +} + +func (me *SpksCircuitSystem) calculateSPKSXJ(state *SpksCircuitState) { + state.SPKSX1J = state.SPKSX1JA || state.SPKSXPLAJ + state.SPKSX3J = state.SPKSX3JA || state.SPKSXPLAJ +} +func (me *SpksCircuitSystem) calculateSPKSSJ(state *SpksCircuitState) { + state.SPKSS2J = state.SPKSS2JA || state.SPKSSPLAJ + state.SPKSS4J = state.SPKSS4JA || state.SPKSSPLAJ +} +func (me *SpksCircuitSystem) calculateSPKSPLAJ(state *SpksCircuitState) { + state.SPKSXPLAJ = state.SPKSXPLA + state.SPKSSPLAJ = state.SPKSSPLA +} + +// 状态改变运算,通过pre与cur比较,如果某个状态改变则发送对应事件 +func (me *SpksCircuitSystem) calculateChange(curState *SpksCircuitState, preState *SpksCircuitState) { + if curState.SPKSX1J != preState.SPKSX1J { + //继电器状态需要改变 + } }