Esempio n. 1
0
    // Awake is called **before** any Start methods.
    // so we make sure the NoiseTag controller is ready before
    // any game objects which may want to use it!
    void Awake()
    {
        if (_instance != null && _instance != this)
        {
            Destroy(this.gameObject);
            return;
        }
        _instance = this;
        DontDestroyOnLoad(this.gameObject); // keep the controller arround...

        // Switch to 640 x 480 full-screen at 60 hz, and put
        // VSYNC on, so we a) run fast, b) are time-accurate.
        Screen.SetResolution(Screen.width, Screen.height, FullScreenMode.ExclusiveFullScreen);
        // FORCE!! Sync framerate to monitors refresh rate
        // get the current display rate, and set the vSyncCount to get as close as possible
        // for the code bits
        QualitySettings.vSyncCount = 1;
        if (FRAMESPERCODEBIT <= 0) // set framesperbit to be close to target framerate
        {
            int   refreshRate  = Screen.currentResolution.refreshRate;
            float framesperbit = refreshRate / QualitySettings.vSyncCount / targetFrameRate;
            FRAMESPERCODEBIT = (int)Math.Round(framesperbit + .1);
        }

        nt = new Noisetag(new System.IO.StringReader(codebook.text), null, null);

        // setup the event handlers when the connection is up.
        // debug message handler : prints all new messages
        nt.stopFlicker(); // reset state
        nt.addMessageHandler(newMessageHandler);
        nt.addSelectionHandler(selectionHandler);
        nt.addPredictionHandler(newPredictionHandler);
        nt.addSignalQualityHandler(signalQualityHandler);
        nt.addNewTargetHandler(newTargetHandler);
        nt.setFramesPerBit(FRAMESPERCODEBIT);

        // init the info on the set of objIDs we are managing..
        if (objIDs == null)
        {
            objIDs = new int[127];
            for (int i = 0; i < objIDs.Length; i++)
            {
                objIDs[i] = i + 1; // N.B. objid > 0
            }
        }
        if (registeredobjIDs == null)
        {
            registeredobjIDs = new NoisetagBehaviour[objIDs.Length];
        }

        nframe    = 0;
        isRunning = false;

        // magic co-routine to record accurately the time the last frame was drawn
        StartCoroutine(recordFrameTime());

        // magic co-routine to make and maintain the decoder connection
        last_connected_time = nt.getTimeStamp();
        StartCoroutine(KeepTryingToConnect());
    }
Esempio n. 2
0
    public void GoCalibration()
    {
        setActiveObject(calibrationObject);
        // make sure the flicker objects have active noisetag ids
        // N.B. this is only needed because we call startCalibration before the objects
        //      have been made visible and so get an ID themselves.
        //      If you activate the object first then this is *NOT* needed.
        NoisetagController nt = NoisetagController.Instance;

        nt.acquireObjIDs(activeObject.GetComponentsInChildren <NoisetagBehaviour>());
        // N.B. make sure the calibration objects are active before calling this
        //      otherwise can't do the cueing as don't know how many outputs there are.
        nt.startCalibration(nCalibrationTrials);
    }
Esempio n. 3
0
    public void GoCuedPrediction()
    {
        // N.B.
        setActiveObject(predictionObject);
        // set all the scene child objects active?
        // make sure the flicker objects have active noisetag ids
        // N.B. this is only needed because we call startPrediction before the objects
        //      have been made visible and so get an ID themselves.
        //      If you activate the object first then this is *NOT* needed.
        NoisetagController nt = NoisetagController.Instance;

        nt.acquireObjIDs(activeObject.GetComponentsInChildren <NoisetagBehaviour>());

        nt.startPrediction(nPredictionTrials, true);
    }
    // Awake is called **before** any Start methods.
    // so we make sure the NoiseTag controller is ready before
    // any game objects which may want to use it!
    void Awake()
    {
        if (_instance != null && _instance != this)
        {
            Destroy(this.gameObject);
            return;
        }
        _instance = this;
        DontDestroyOnLoad(this.gameObject); // keep the controller arround...

        // Switch to 640 x 480 full-screen at 60 hz, and put
        // VSYNC on, so we a) run fast, b) are time-accurate.
        Screen.SetResolution(1280, 780, FullScreenMode.ExclusiveFullScreen, 60);
        // FORCE!! Sync framerate to monitors refresh rate
        QualitySettings.vSyncCount = 1;

        nt = new Noisetag(new System.IO.StringReader(codebook.text), null, null);

        // setup the event handlers when the connection is up.
        // debug message handler : prints all new messages
        nt.addMessageHandler(newMessageHandler);
        nt.addSelectionHandler(selectionHandler);
        nt.addPredictionHandler(newPredictionHandler);
        nt.addSignalQualityHandler(signalQualityHandler);

        // init the info on the set of objIDs we are managing..
        if (objIDs == null)
        {
            objIDs = new int[127];
            for (int i = 0; i < objIDs.Length; i++)
            {
                objIDs[i] = i + 1; // N.B. objid > 0
            }
        }
        if (registeredobjIDs == null)
        {
            registeredobjIDs = new NoisetagBehaviour[objIDs.Length];
        }

        nframe    = 0;
        isRunning = false;

        // magic co-routine to record accurately the time the last frame was drawn
        StartCoroutine(recordFrameTime());

        // magic co-routine to make the initial decoder connection
        StartCoroutine(KeepTryingToConnect());
    }
Esempio n. 5
0
    // Start is called before the first frame update
    void Start()
    {
        NoisetagController nt = NoisetagController.Instance;

        nt.sequenceCompleteEvent.AddListener(GoMainMenu);
        nt.connectedEvent.AddListener(GoMainMenu);
        //nt.startPrediction(1); // test starting prediction early + button selection

        menuObject.SetActive(false);
        calibrationObject.SetActive(false);
        predictionObject.SetActive(false);
        signalQualityObject.SetActive(false);
        connectingObject.SetActive(false);
        // set the initial screen based on our connected state
        if (nt.isConnected())
        {
            GoMainMenu();
        }
        else
        {
            GoConnecting();
        }
    }