Example #1
0
static void paintWrapper() {
    // clear the palette
    newCubes.clear();
    lostCubes.clear();
    reconnectedCubes.clear();
    dirtyCubes.clear();

    // fire events
    System::paint();

    // dynamically load assets just-in-time
    if (!(newCubes | reconnectedCubes).empty()) {
        loader.start(config);
        while(!loader.isComplete()) {
            for(CubeID cid : (newCubes | reconnectedCubes)) {
                vbuf[cid].bg0rom.hBargraph(
                    vec(0, 4), loader.cubeProgress(cid, 128), BG0ROMDrawable::ORANGE, 8
                );
            }
            // fire events while we wait
            System::paint();
        }
        loader.finish();
    }

    // repaint cubes
    for(CubeID cid : dirtyCubes) {
        activateCube(cid, taskCubes[cid].task);
    }
    
    // also, handle lost cubes, if you so desire :)
}
Example #2
0
static void onCubeDisconnect(void* ctxt, unsigned cid) {
    // mark as lost and clear from other cube sets
    lostCubes.mark(cid);
    newCubes.clear(cid);
    reconnectedCubes.clear(cid);
    dirtyCubes.clear(cid);
    activeCubes.clear(cid);
}
Example #3
0
static void onCubeConnect(void* ctxt, unsigned cid) {
    // this cube is either new or reconnected
    if (lostCubes.test(cid)) {
        // this is a reconnected cube since it was already lost this paint()
        lostCubes.clear(cid);
        reconnectedCubes.mark(cid);
    } else {
        // this is a brand-spanking new cube
        newCubes.mark(cid);
    }
    // begin showing some loading art (have to use BG0ROM since we don't have assets)
    dirtyCubes.mark(cid);
    auto& g = vbuf[cid];
    g.attach(cid);
    g.initMode(BG0_ROM);
    g.bg0rom.fill(vec(0,0), vec(16,16), BG0ROMDrawable::SOLID_BG);
    g.bg0rom.text(vec(1,1), "Hold on!", BG0ROMDrawable::BLUE);
    g.bg0rom.text(vec(1,14), "Adding Cube...", BG0ROMDrawable::BLUE);
}
Example #4
0
void MainMenu::updateConnecting()
{
    /*
     * Cubes are in the 'connectingCubes' set between when they first connect
     * and when they become usable for the menu. They go through three states:
     *
     *   1. Displaying the Sifteo logo. This starts in cubeConnect(), and runs on a timer.
     *
     *   2. Loading assets. We start the load itself in cubeConnect(). After the logo
     *      finishes, we switch to displaying a progress animation.
     *
     *   3. When loading finishes, we draw an idle screen on the cube and remove it
     *      form connectingCubes.
     */

    SystemTime now = SystemTime::now();

    /*
     * Look for state transitions from (1) to (2)
     */

    CubeSet beginLoadingAnim;
    beginLoadingAnim.clear();

    for (CubeID cube : connectingCubes & ~loadingCubes) {
        if ((now - Shared::connectTime[cube]).milliseconds() >= kDisplayBlueLogoTimeMS) {
            loadingCubes.mark(cube);
            beginLoadingAnim.mark(cube);
        }
    }

    if (!beginLoadingAnim.empty()) {
        loadingAnimation.begin(beginLoadingAnim);
    }

    /*
     * Let cubes participate in the loading animation until the whole load is done
     */
    if (loadingCubes.empty()) {
        // nothing to do
        return;
    }

    if (!loader.isComplete()) {
        // Still loading, update progress
        loadingAnimation.paint(loadingCubes, loader.averageProgress(100));
        return;
    }

    // Loading is done!
    loadingAnimation.end(loadingCubes);

    // Draw an idle screen on each cube, and remove it from connectingCubes
    for (CubeID cube : loadingCubes) {
        auto& vid = Shared::video[cube];
        vid.initMode(BG0);
        vid.bg0.erase(Menu_StripeTile);
        vid.bg0.image(vec(0,0), Menu_IdleCube);

        connectingCubes.clear(cube);

        // Dispatch connected event to current applet now that the cube is ready
        if (itemIndexCurrent >= 0) {
            ASSERT(itemIndexCurrent < items.count());
            MainMenuItem *item = items[itemIndexCurrent];
            item->onCubeConnect(cube);

            // If a game was waiting on a cube to launch, try again.
            if (cubeRangeSavedIcon && areEnoughCubesConnected(itemIndexCurrent)) {
                itemIndexChoice = itemIndexCurrent;
                toggleCubeRangeAlert(); // remove the warning asking for more cubes
            }
        }

        updateCubeRangeAlert();
    }

    loadingCubes.clear();
}
Example #5
0
static void paintWrapper() {
    // clear the palette
    newCubes.clear();
    lostCubes.clear();
    reconnectedCubes.clear();
    dirtyCubes.clear();

        if(previousLearningTask != currentLearningTask){
        previousLearningTask++;
        }


    // fire events
    System::paint();

    // dynamically load assets just-in-time
    if (!(newCubes | reconnectedCubes).empty()) {
        AudioTracker::pause();
        playSfx(SfxConnect);
        loader.start(config);
        while(!loader.isComplete()) {
            for(CubeID cid : (newCubes | reconnectedCubes)) {
                vbuf[cid].bg0rom.hBargraph(
                    vec(0, 4), loader.cubeProgress(cid, 128), BG0ROMDrawable::ORANGE, 8
                );
            }
            // fire events while we wait
            System::paint();
        }
        loader.finish();
        AudioTracker::resume();
    }


    // // repaint cubes (will this paint right? If not, try repainting all of them)
    // for(CubeID cid : dirtyCubes) {
    //     activateCube(cid);
    // }

    //If the shaken timer flag is too old, turn it off again here.
    if(distractTime.isValid() && (currentLearningTask==2)) {

        TimeDelta timeSinceShook = SystemTime::now() - distractTime;
        double duration = timeSinceShook.milliseconds() / 1000;
        if((duration > 11) && isDistracted) {
            currentBackgrounds[2] = 3;
            currentBackgrounds[1] = 1;
            isDistracted = false;
        }
    }

    //update art to new task

    int j = 0;
    for(CubeID cid : CubeSet::connected()) {
        vbuf[cid].attach(cid);
        activateCube(cid);
        cbs [j] = cid;
        j++;
    }


    // also, handle lost cubes, if you so desire :)
}