Beispiel #1
0
void main() {
    blicketCubes.mark(blicket1);
    blicketCubes.mark(blicket2);
    nonBlicketCubes.mark(nonBlicket1);
    nonBlicketCubes.mark(nonBlicket2);

    // Initialize asset configuration and loader
    config.append(gMainSlot, BootstrapAssets);
    loader.init();

    // Subscribe to events (See pubsub design pattern)
    Events::cubeConnect.set(onCubeConnect);
    Events::cubeDisconnect.set(onCubeDisconnect);
    Events::cubeRefresh.set(onCubeRefresh);
    Events::neighborAdd.set(onNeighborAdd);
    Events::neighborRemove.set(onNeighborRemove);
    // Events::cubeTouch.set(onCubeTouch);
    Events::cubeTouch.set(onTouch);

    // Initialize cubes
    for(CubeID cid : CubeSet::connected()) {
        vbuf[cid].attach(cid);
        activateCube(cid);
    }

    // Run loop
    for(;;) {
        paintWrapper();
    }
}
Beispiel #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);
}
Beispiel #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);
}
Beispiel #4
0
static void activateCube(CubeID cid) {
    // mark cube as active and render its canvas
    activeCubes.mark(cid);
   
    String<128> str;
    if (inRunMode) {
		str << "I am cube #" << cid << "\n";
    	drawText(cid, str, 1, 1);
    }
    else {
    	str << "In set mode...\n";
    	drawText(cid, str, 1, 1);
    }
}
Beispiel #5
0
static void activateCube(CubeID cid, int task) {
    // mark cube as active and render its canvas
    activeCubes.mark(cid);
    vbuf[cid].initMode(BG0_SPR_BG1);

    //this is where the starting image is set (after a task is set and we exit the menu) 
    vbuf[cid].bg0.image(vec(0,0), TaskReds, task);

    auto neighbors = vbuf[cid].physicalNeighbors();
    for(int side=0; side<4; ++side) {
        if (neighbors.hasNeighborAt(Side(side))) {
            //showSideBar(cid, Side(side));
        } else {
            hideSideBar(cid, Side(side));
        }
    }
}
Beispiel #6
0
static void activateCube(CubeID cid) {
    // mark cube as active and render its canvas
    activeCubes.mark(cid);
    
    vbuf[cid].initMode(BG0_SPR_BG1);
    vbuf[cid].bg0.image(vec(0,0), Backgrounds, currentBackgrounds[(int)cid]);
    
    //Old sidebar code
    //auto neighbors = vbuf[cid].physicalNeighbors();
    // for(int side=0; side<4; ++side) {
    //     if (neighbors.hasNeighborAt(Side(side))) {
    //         showSideBar(cid, Side(side));
    //     } else {
    //         hideSideBar(cid, Side(side));
    //     }
    // }
}
Beispiel #7
0
static void activateCube(CubeID cid) {
    // Mark cube as active and render its canvas
    //
    activeCubes.mark(cid);
    vbuf[cid].initMode(BG0_SPR_BG1);
    if (cid == 0) {
        vbuf[cid].bg0.image(vec(0,0), Backgrounds, 0);
    } else {
        vbuf[cid].bg0.image(vec(0,0), cond.get_condition(), cid - 1);
    }
    auto neighbors = vbuf[cid].physicalNeighbors();
    for(int side=0; side<4; ++side) {
        if (neighbors.hasNeighborAt(Side(side))) {
            showSideBar(cid, Side(side));
        } else {
            hideSideBar(cid, Side(side));
        }
    }
}
Beispiel #8
0
static void onCubeRefresh(void* ctxt, unsigned cid) {
    // mark this cube for a future repaint
    dirtyCubes.mark(cid);
}
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();
}
Beispiel #10
0
void main() {

    // subscribe to events
    Events::neighborAdd.set(onNeighborAdd);
    Events::neighborRemove.set(onNeighborRemove);
    
    Events::cubeTouch.set(onTouch);
    Events::cubeAccelChange.set(onAccelChange);
      
    for(CubeID cid : CubeSet::connected()) {
       	vbuf[cid].attach(cid);
       	motion[cid].attach(cid);
        activateCube(cid);
    }
    
    AudioTracker::setVolume(0.2f * AudioChannel::MAX_VOLUME);
    
    //if (inRunMode) LOG("run mode\n");
    //else LOG("set mode\n");
    
    // run loop
    while(1) {
        System::paint();
               
        if (count > 1800 /*&& countDown*/) {
        	LOG("in count conditional \n");
        	SystemTime curTime = SystemTime::now();
        	TimeDelta timePast = curTime - startTime;
        	if (timePast > totalTime) {
    			if (!musicInitialized) {
    				musicInitialized = true;
    				AudioTracker::play(Music);
    				alarm = true;
    				//countDown = false;
    			}
        	}
        	convertedSec = timePast.seconds();
        	convertedMin = convertedSec / 60;
        	displayHour = convertedMin / 60;
        	displayMin = (int)convertedMin % (int)60;
        	displaySec = convertedSec - (convertedMin * 60);
        	count = 0;
        }
        //LOG_FLOAT(displaySec);
        count++;
        
        //if (inRunMode) LOG("run mode\n");
    	//else LOG("set mode\n");
        
        for(CubeID cid : CubeSet::connected()) {
        	activeCubes.mark(cid);
        	String<128> str;
    		if (inRunMode) {
    			if (alarm) {
    				if (cid == 0) str << "0:\n";
    				else if (cid == 1) str << ":00\n";
    				drawText(cid, str, 1, 1);
    			}
    			else {
    				if (cid == 0) str << Fixed(hours-displayHour, 3) << ":\n";
					else if (cid == 1) str << ":" << Fixed(minutes-displayMin, 3) << "\n";
					drawText(cid, str, 1, 1) ;
    			}
    		}
    		else {
				if (cid == 0) str << "Hours: " << Fixed(hours, 3) << "\n";
				else if (cid == 1) str << "Minutes: " << Fixed(minutes, 3) << "\n";
				drawText(cid, str, 1, 1) ;
    		}
    	}
        
    }
}