示例#1
0
 public static void sol_load_swch(IntPtr fin, s_swch xp)
 {
     Binary.get_array(fin, xp.m_p, 3);
     Binary.get_float(fin, ref xp.m_r);
     Binary.get_index(fin, ref xp.m_pi);
     Binary.get_float(fin, ref xp.m_t0);
     Binary.get_float(fin, ref xp.m_t);
     Binary.get_index(fin, ref xp.m_f0);
     Binary.get_index(fin, ref xp.m_f);
     Binary.get_index(fin, ref xp.m_i);
 }
示例#2
0
        /*
         * Compute the states of all switches after DT seconds have passed.
         */
        public static void sol_swch_step(s_file fp, float dt)
        {
            int xi;

            for (xi = 0; xi < fp.m_xc; xi++)
            {
                s_swch xp = fp.m_xv[xi];

                //volatile
                float t = xp.m_t;

                if (t < xp.m_t0)
                {
                    xp.m_t = (t += dt);

                    if (t >= xp.m_t0)
                    {
                        int pi = xp.m_pi;
                        int pj = xp.m_pi;

                        do  /* Tortoise and hare cycle traverser. */
                        {
                            fp.m_pv[pi].m_f = xp.m_f0;
                            fp.m_pv[pj].m_f = xp.m_f0;

                            cmd.type        = cmd_type.CMD_PATH_FLAG;
                            cmd.pathflag.pi = pi;
                            cmd.pathflag.f  = fp.m_pv[pi].m_f;
                            sol_cmd_enq(cmd);

                            pi = fp.m_pv[pi].m_pi;
                            pj = fp.m_pv[pj].m_pi;
                            pj = fp.m_pv[pj].m_pi;
                        }while (pi != pj);

                        xp.m_f = xp.m_f0;

                        cmd.type          = cmd_type.CMD_SWCH_TOGGLE;
                        cmd.swchtoggle.xi = xi;
                        sol_cmd_enq(cmd);
                    }
                }
            }
        }
示例#3
0
        /*
         * Test and process the event the ball UI enters a switch. Return 1 if
         * a visible  switch is  activated, return 0  otherwise (no  switch is
         * activated or only invisible switches).
         */
        public static int sol_swch_test(s_file fp, int ui)
        {
            float[] ball_p = fp.m_uv[ui].m_p;
            float   ball_r = fp.m_uv[ui].m_r;
            int     xi;
            int     res = 0;

            for (xi = 0; xi < fp.m_xc; xi++)
            {
                s_swch xp = fp.m_xv[xi];

                /* FIXME enter/exit events don't work for timed switches */

                if (xp.m_t0 == 0 || xp.m_f == xp.m_f0)
                {
                    float   l;
                    float[] r = new float[3];

                    r[0] = ball_p[0] - xp.m_p[0];
                    r[1] = ball_p[2] - xp.m_p[2];
                    r[2] = 0;

                    l = Vec3.v_len(r) - xp.m_r;

                    if (l < ball_r &&
                        ball_p[1] > xp.m_p[1] &&
                        ball_p[1] < xp.m_p[1] + Config.SWCH_HEIGHT / 2)
                    {
                        if (xp.m_e == 0 &&
                            l < -ball_r)
                        {
                            int pi = xp.m_pi;
                            int pj = xp.m_pi;

                            /* The ball enters. */

                            if (xp.m_t0 == 0)
                            {
                                xp.m_e = 1;

                                cmd.type         = cmd_type.CMD_SWCH_ENTER;
                                cmd.swchenter.xi = xi;
                                sol_cmd_enq(cmd);
                            }

                            /* Toggle the state, update the path. */

                            xp.m_f = xp.m_f != 0 ? 0 : 1;

                            cmd.type          = cmd_type.CMD_SWCH_TOGGLE;
                            cmd.swchtoggle.xi = xi;
                            sol_cmd_enq(cmd);

                            do  /* Tortoise and hare cycle traverser. */
                            {
                                fp.m_pv[pi].m_f = xp.m_f;
                                fp.m_pv[pj].m_f = xp.m_f;

                                cmd.type        = cmd_type.CMD_PATH_FLAG;
                                cmd.pathflag.pi = pi;
                                cmd.pathflag.f  = fp.m_pv[pi].m_f;
                                sol_cmd_enq(cmd);

                                pi = fp.m_pv[pi].m_pi;
                                pj = fp.m_pv[pj].m_pi;
                                pj = fp.m_pv[pj].m_pi;
                            }while (pi != pj);

                            /* It toggled to non-default state, start the timer. */

                            if (xp.m_f != xp.m_f0)
                            {
                                xp.m_t = 0.0f;
                            }

                            /* If visible, set the result. */

                            if (xp.m_i == 0)
                            {
                                res = 1;
                            }
                        }
                    }

                    /* The ball exits. */

                    else if (xp.m_e != 0)
                    {
                        xp.m_e = 0;

                        cmd.type        = cmd_type.CMD_SWCH_EXIT;
                        cmd.swchexit.xi = xi;
                        sol_cmd_enq(cmd);
                    }
                }
            }
            return(res);
        }