Esempio n. 1
0
 protected virtual void ResetLight()
 {
     lightCmdQ.Clear();
     lightSenarioCmdQ.Clear();
     currLightCmd        = default;
     currLightSenarioCmd = default;
 }
Esempio n. 2
0
        protected void LightScheduler(float t)
        {
            // ----- Simulate Lag -----
            while (lightCmdQ.Count > 0 && t > lightCmdQ.Peek().tRecv)
            {
                currLightCmd = lightCmdQ.Dequeue();
            }
            while (lightSenarioCmdQ.Count > 0 && t > lightSenarioCmdQ.Peek().tRecv)
            {
                currLightSenarioCmd = lightSenarioCmdQ.Dequeue();
            }

            // ----- Excute Order -----
            if (currLightCmd.tRecv >= currLightSenarioCmd.tRecv)    // light cmd
            {
                float elipsed = t - currLightCmd.tRecv;
                if (currLightCmd.duration == 0 || elipsed < currLightCmd.duration / 1000f)
                {
                    cube._SetLight(currLightCmd.r, currLightCmd.g, currLightCmd.b);
                }
                else
                {
                    cube._StopLight();
                }
            }
            else    // light senario cmd
            {
                float elipsed = t - currLightSenarioCmd.tRecv;
                if (currLightSenarioCmd.period == 0 ||
                    currLightSenarioCmd.repeat > 0 && currLightSenarioCmd.period * currLightSenarioCmd.repeat <= elipsed)
                {
                    cube._StopLight();
                }
                else
                {
                    // Index of current operation
                    float sum = 0; int index = 0; var lights = currLightSenarioCmd.lights;
                    for (int i = 0; i < lights.Length; ++i)
                    {
                        sum += lights[i].durationMs / 1000f;
                        if (elipsed % currLightSenarioCmd.period < sum)
                        {
                            index = i;
                            break;
                        }
                    }
                    cube._SetLight(lights[index].red, lights[index].green, lights[index].blue);
                }
            }
        }
Esempio n. 3
0
        public override void SetLights(int repeatCount, Cube.LightOperation[] operations)
        {
            if (operations.Length == 0)
            {
                return;
            }
            operations = operations.Take(29).ToArray();

            LightSenarioCmd cmd = new LightSenarioCmd();

            cmd.lights = operations;
            cmd.repeat = (byte)Mathf.Clamp(repeatCount, 0, 255);
            // calc. period
            cmd.period = 0;
            for (int i = 0; i < cmd.lights.Length; ++i)
            {
                cmd.period += cmd.lights[i].durationMs / 1000f;
            }
            cmd.tRecv = Time.time;
            lightSenarioCmdQ.Enqueue(cmd);
        }
 protected virtual void ResetLight()
 {
     lightCmd        = default;
     lightSenarioCmd = default;
     lightCmdType    = LightCmdType.None;
 }