Пример #1
0
void Gource::draw(float t, float dt) {

    display.mode2D();

    drawBackground(dt);

    if(draw_loading) {
        loadingScreen();
        draw_loading = false;
        return;
    }

    Frustum frustum(camera);

    trace_time = SDL_GetTicks();

    mousetrace(frustum,dt);

    trace_time = SDL_GetTicks() - trace_time;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    camera.focus();

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    //draw tree
    drawTree(frustum, dt);

    glColor4f(1.0, 1.0, 0.0, 1.0);
    for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
        trace_debug ? it->second->drawSimple(dt) : it->second->draw(dt);
    }

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);

    //draw bloom
    drawBloom(frustum, dt);

    root->drawNames(font,frustum);

    if(!(gGourceHideUsernames || gGourceHideUsers)) {
        for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
            it->second->drawName();
        }
    }

    //draw selected item names again so they are over the top
    if(selectedUser !=0) selectedUser->drawName();

    if(selectedFile !=0) {
        vec2f dirpos = selectedFile->getDir()->getPos();

        glPushMatrix();
            glTranslatef(dirpos.x, dirpos.y, 0.0);
            selectedFile->drawName();
        glPopMatrix();
    }

    if(debug) {
        glDisable(GL_TEXTURE_2D);
        glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

        track_users ? user_bounds.draw() : dir_bounds.draw();
    }

    if(gGourceQuadTreeDebug) {
        glDisable(GL_TEXTURE_2D);
        glColor4f(0.0f, 1.0f, 0.0f, 1.0f);

        glLineWidth(1.0);
        dirNodeTree->outline();

        glColor4f(0.0f, 1.0f, 1.0f, 1.0f);

        userTree->outline();
    }

    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

    display.mode2D();

    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glEnable(GL_TEXTURE_2D);

    vec3f campos = camera.getPos();

    if(!gGourceHideDate) {
        fontmedium.draw(display.width/2 - date_x_offset, 20, displaydate);
    }

    if(splash>0.0f) {
        int logowidth = fontlarge.getWidth("Gource");
        int logoheight = 100;
        int cwidth    = font.getWidth("Software Version Control Visualization");
        int awidth    = font.getWidth("(C) 2009 Andrew Caudwell");

        vec2f corner(display.width/2 - logowidth/2 - 30.0f, display.height/2 - 40);

        glDisable(GL_TEXTURE_2D);
        glColor4f(0.0f, 0.5f, 1.0f, splash * 0.015f);
        glBegin(GL_QUADS);
            glVertex2f(0.0f,                 corner.y);
            glVertex2f(0.0f,                 corner.y + logoheight);
            glVertex2f(display.width, corner.y + logoheight);
            glVertex2f(display.width, corner.y);
        glEnd();

        glEnable(GL_TEXTURE_2D);

        glColor4f(1.0,1.0,1.0,1.0);
        fontlarge.draw(display.width/2 - logowidth/2,display.height/2 - 30, "Gource");
        font.draw(display.width/2 - cwidth/2,display.height/2 + 10, "Software Version Control Visualization");
        font.draw(display.width/2 - awidth/2,display.height/2 + 30, "(C) 2009 Andrew Caudwell");
    }

    if(debug) {
        font.print(0,20, "FPS: %.2f", fps);
        font.print(0,40,"Time Scale: %.2f", time_scale);
        font.print(0,60,"Users: %d", users.size());
        font.print(0,80,"Files: %d", files.size());
        font.print(0,100,"Dirs: %d",  gGourceDirMap.size());

        font.print(0,120,"Log Position: %.2f", commitlog->getPercent());
        font.print(0,140,"Camera: (%.2f, %.2f, %.2f)", campos.x, campos.y, campos.z);
        font.print(0,160,"Gravity: %.2f", gGourceForceGravity);
        font.print(0,180,"Update Tree: %u ms", update_dir_tree_time);
        font.print(0,200,"Draw Tree: %u ms", draw_tree_time);
        font.print(0,220,"Mouse Trace: %u ms", trace_time);
        font.print(0,240,"Logic Time: %u ms", logic_time);
        font.print(0,260,"Draw Time: %u ms", SDL_GetTicks() - draw_time);
        font.print(0,280,"File Inner Loops: %d", gGourceFileInnerLoops);
        font.print(0,300,"User Inner Loops: %d", gGourceUserInnerLoops);
        font.print(0,320,"Dir Inner Loops: %d (QTree items = %d, nodes = %d)", gGourceDirNodeInnerLoops,
            dirNodeTree->item_count, dirNodeTree->node_count);

        if(selectedUser != 0) {

        }

        if(selectedFile != 0) {
            font.print(0,360,"%s: %d files (%d visible)", selectedFile->getDir()->getPath().c_str(),
                    selectedFile->getDir()->fileCount(), selectedFile->getDir()->visibleFileCount());
        }

    }

    glDisable(GL_TEXTURE_2D);

    if(canSeek()) slider.draw(dt);

    mousemoved=false;
    mouseclicked=false;
}
Пример #2
0
//Displays the actual game with car handling
void Application::gameStart(std::fstream& fileToRead, int& choosenCar)
{
    if (gWindow != NULL)
    {
        if (!loadMedia(choosenCar))
        {
            printf("Failed to load media!\n");
        }
    }
    //Main loop flag
    bool quit = false;

    //Event handler
    SDL_Event e;
    SDL_Color textColor = { 0xFF, 0xFF, 0xFF, 0xFF };
    LTexture timeTexture;
    int timeTemp = gameData.getTime();
    const int mapFinishX = 870;
    const int mapFinishY = 620;
    bool firstRun = true;

    switch (choosenCar)
    {
    case CAR_ONE:
        gCarTexture = gFirstCarTexture;
        break;
    case CAR_TWO:
        gCarTexture = gSecondCarTexture;
        break;
    case CAR_THREE:
        gCarTexture = gThirdCarTexture;
        break;
    }

    //The car that will be moving around on the screen
    Car car(choosenCar, gCarTexture.getWidth(), gCarTexture.getHeight(), startingAngle, map.getDifficulty());
    SDL_Rect* wall = map.getObstacles();
    gameData.setStartGame(obj.getCurrentTime(obj.getCurrentDateTime()));
    if (isMusicOn)
    {
        car.loadSounds();
    }

    //While application is running
    while (!quit)
    {
        //Handle events on queue
        while (SDL_PollEvent(&e) != 0)
        {
            //Handle input for the car
            car.handleEvent(e);

            if (onMusicButton->handleEvent(&e))
            {
                checkMusicInGame(car, e);
            }
        }
        if (firstRun)
        {
            loadingScreen(gRenderer, timeTexture, textColor, car);
            firstRun = false;
        }
        //Clear screen
        SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
        SDL_RenderClear(gRenderer);

        gBackgroundTexture.render(*gRenderer, 0, 0);
        timeTexture.render(*gRenderer, 620, 10);
        renderMusicButton();

        if (SDL_GetTicks() - startTimeTemp >= ONE_SECOND)
        {
            if (!timeTexture.loadFromRenderedText(timer(timeTemp), textColor, *gRenderer))
            {
                printf("Unable to render time texture!\n");
            }
            timer(timeTemp--);
            startTimeTemp = SDL_GetTicks();
        }

        //test the obstacles
        //drawObstaclesHelper(*gRenderer, wall, map.getObstaclesNumber());

        //Move the car and check collision
        car.move(wall, map.getObstaclesNumber(), SCREEN_HEIGHT, SCREEN_WIDTH);

        if (timeTemp < 0)
        {
            //YOU LOSE
            caseYouLose(fileToRead);
            return;
        }
        else if (car.getCarX() >= mapFinishX && car.getCarY() >= mapFinishY)
        {
            //YOU WIN
            caseYouWin(fileToRead);
            return;
        }
        //Render car
        car.render(gCarTexture, gSpeedMeter, gSpeedMeterClips, *gRenderer);

        //UPDATE SCREEN
        SDL_RenderPresent(gRenderer);
    }
}
Пример #3
0
void Gource::draw(float t, float dt) {
    dt = std::min<float>(dt, gGourceMaxDelta * time_scale);

    display.setClearColour(background_colour);
    display.clear();

    if(draw_loading) {
        loadingScreen();
        draw_loading = false;
        return;
    }

    //camera tracking
    if(track_users && (selectedFile !=0 || selectedUser !=0)) {
        Bounds2D focusbounds;

        vec3f camerapos = camera.getPos();

        if(selectedUser !=0) focusbounds.update(selectedUser->getPos());
        if(selectedFile !=0) focusbounds.update(selectedFile->getAbsolutePos());

        camera.adjust(focusbounds);
    } else {
        if(track_users && idle_time==0) camera.adjust(user_bounds);
        else camera.adjust(dir_bounds);
    }

    camera.logic(dt);

    Frustum frustum(camera);

    trace_time = SDL_GetTicks();

    mousetrace(frustum,dt);

    trace_time = SDL_GetTicks() - trace_time;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    camera.focus();

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    draw_tree_time = SDL_GetTicks();

    root->calcEdges();

    //switch to 2d
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, display.width, display.height, 0, -1.0, 1.0);

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glEnable(GL_TEXTURE_2D);

    //draw edges
    root->drawEdgeShadows(dt);
    root->drawEdges(dt);

    //switch back
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);

    //draw shadows

    if(!gGourceHideUsers) {
        for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
            it->second->drawShadow(dt);
        }
    }

    root->drawShadows(frustum, dt);

    //draw actions
    for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
        it->second->drawActions(dt);
    }

    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glColor4f(0.0, 1.0, 0.0, 1.0);
    trace_debug ? root->drawSimple(frustum,dt) : root->drawFiles(frustum,dt);

    draw_tree_time = SDL_GetTicks() - draw_tree_time;

    glColor4f(1.0, 1.0, 0.0, 1.0);
    for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
        trace_debug ? it->second->drawSimple(dt) : it->second->draw(dt);
    }


    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);

    root->drawNames(font,frustum);

    if(!gGourceHideUsernames) {
        for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
            it->second->drawName();
        }
    }

    //draw selected item names again so they are over the top
    if(selectedUser !=0) selectedUser->drawName();

    if(selectedFile !=0) {
        vec2f dirpos = selectedFile->getDir()->getPos();

        glPushMatrix();
            glTranslatef(dirpos.x, dirpos.y, 0.0);
            selectedFile->drawName();
        glPopMatrix();
    }

    if(debug) {
        glDisable(GL_TEXTURE_2D);
        glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

        track_users ? user_bounds.draw() : dir_bounds.draw();
    }

    if(gGourceQuadTreeDebug) {
        glDisable(GL_TEXTURE_2D);
        glColor4f(0.0f, 1.0f, 0.0f, 1.0f);

        glLineWidth(1.0);
        dirNodeTree->outline();

        glColor4f(0.0f, 1.0f, 1.0f, 1.0f);

        userTree->outline();
    }

    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

    display.mode2D();

    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glEnable(GL_TEXTURE_2D);

    vec3f campos = camera.getPos();

	float width = static_cast<float>(display.width);
	float height = static_cast<float>(display.height);
	float half_width = width/2.0f;
	float half_height = height/2.0f;

    if(!gGourceHideDate) {
        fontmedium.draw(half_width - date_x_offset, 20.0f, displaydate);
    }

    if(splash>0.0f) {
        float logowidth = fontlarge.getWidth("Gource");
        float logoheight = 100.0f;
        float cwidth    = font.getWidth("Software Version Control Visualization");
        float awidth    = font.getWidth("(C) 2009 Andrew Caudwell");

        vec2f corner(half_width - logowidth/2.0f - 30.0f, half_height - 40.0f);

        glDisable(GL_TEXTURE_2D);
        glColor4f(0.0f, 0.5f, 1.0f, splash * 0.015f);
        glBegin(GL_QUADS);
            glVertex2f(0.0f,                 corner.y);
            glVertex2f(0.0f,                 corner.y + logoheight);
            glVertex2f(width, corner.y + logoheight);
            glVertex2f(width, corner.y);
        glEnd();

        glEnable(GL_TEXTURE_2D);

        glColor4f(1.0f,1.0f,1.0f,1.0f);
        fontlarge.draw(half_width - logowidth/2.0f,half_height - 30.0f, "Gource");
        font.draw(half_width - cwidth/2.0f,half_height + 10.0f, "Software Version Control Visualization");
        font.draw(half_width - awidth/2.0f,half_height + 30.0f, "(C) 2009 Andrew Caudwell");
    }

    if(debug) {
        font.print(0,20, "FPS: %.2f", fps);
        font.print(0,60,"Users: %d", users.size());
        font.print(0,80,"Files: %d", files.size());
        font.print(0,100,"Dirs: %d",  gGourceDirMap.size());

        font.print(0,120,"Log Position: %.2f", commitlog->getPercent());
        font.print(0,140,"Camera: (%.2f, %.2f, %.2f)", campos.x, campos.y, campos.z);
        font.print(0,160,"Gravity: %.2f", gGourceForceGravity);
        font.print(0,180,"Update Tree: %u ms", update_dir_tree_time);
        font.print(0,200,"Draw Tree: %u ms", draw_tree_time);
        font.print(0,220,"Mouse Trace: %u ms", trace_time);
        font.print(0,240,"Logic Time: %u ms", logic_time);
        font.print(0,260,"Draw Time: %u ms", SDL_GetTicks() - draw_time);
        font.print(0,280,"File Inner Loops: %d", gGourceFileInnerLoops);
        font.print(0,300,"User Inner Loops: %d", gGourceUserInnerLoops);
        font.print(0,320,"Dir Inner Loops: %d (QTree items = %d, nodes = %d)", gGourceDirNodeInnerLoops,
            dirNodeTree->item_count, dirNodeTree->node_count);

        if(selectedUser != 0) {

        }

        if(selectedFile != 0) {
            font.print(0.0f,360.0f,"%s: %d files (%d visible)", selectedFile->getDir()->getPath().c_str(),
                    selectedFile->getDir()->fileCount(), selectedFile->getDir()->visibleFileCount());
        }

    }

    glDisable(GL_TEXTURE_2D);

    if(canSeek()) slider.draw(dt);

    mousemoved=false;
    mouseclicked=false;
}
Пример #4
0
void Gource::draw(float t, float dt) {

    display.mode2D();

    drawBackground(dt);

    if(draw_loading) {
        loadingScreen();
        draw_loading = false;
        return;
    }

    Frustum frustum(camera);

    trace_time = SDL_GetTicks();

    if(!gGourceSettings.hide_mouse && cursor.isVisible()) {
        mousetrace(frustum,dt);
    }

    trace_time = SDL_GetTicks() - trace_time;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    camera.focus();

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    //draw tree
    drawTree(frustum, dt);

    glColor4f(1.0, 1.0, 0.0, 1.0);
    for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
        trace_debug ? it->second->drawSimple(dt) : it->second->draw(dt);
    }

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);

    //draw bloom
    drawBloom(frustum, dt);

    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    name_calc_time = SDL_GetTicks();

    root->calcScreenPos();

    name_calc_time = SDL_GetTicks() - name_calc_time;


    name_draw_time = SDL_GetTicks();

    //switch to 2D, preserve current state
    display.push2D();

    root->drawNames(font,frustum);

    //switch back
    display.pop2D();

    name_draw_time = SDL_GetTicks() - name_draw_time;

    if(!(gGourceSettings.hide_usernames || gGourceSettings.hide_users)) {
        for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
            it->second->drawName();
        }
    }

    //draw selected item names again so they are over the top
    if(selectedUser !=0) selectedUser->drawName();

    if(selectedFile !=0) {
        display.push2D();
            selectedFile->drawName();
        display.pop2D();
    }

    if(debug) {
        glDisable(GL_TEXTURE_2D);
        glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

        track_users ? user_bounds.draw() : dir_bounds.draw();
    }

    if(gGourceQuadTreeDebug) {
        glDisable(GL_TEXTURE_2D);
        glColor4f(0.0f, 1.0f, 0.0f, 1.0f);

        glLineWidth(1.0);
        dirNodeTree->outline();

        glColor4f(0.0f, 1.0f, 1.0f, 1.0f);

        userTree->outline();
    }

    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

    display.mode2D();

    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glEnable(GL_TEXTURE_2D);

    vec3f campos = camera.getPos();

    if(logotex!=0) {
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_BLEND);
        glEnable(GL_TEXTURE_2D);

        glColor4f(1.0, 1.0, 1.0, 1.0);

        glBindTexture(GL_TEXTURE_2D, logotex->textureid);

        vec2f logopos = vec2f(display.width, display.height) - vec2f(logotex->w, logotex->h) - gGourceSettings.logo_offset;

        glPushMatrix();

            glTranslatef(logopos.x, logopos.y, 0.0);

            glBegin(GL_QUADS);
                glTexCoord2f(0.0f,0.0f);
                glVertex2i(0, 0);

                glTexCoord2f(1.0f,0.0f);
                glVertex2i(logotex->w, 0);

                glTexCoord2f(1.0f,1.0f);
                glVertex2i(logotex->w, logotex->h);

                glTexCoord2f(0.0f,1.0f);
                glVertex2i(0, logotex->h);
            glEnd();

        glPopMatrix();
    }

    if(splash>0.0f) {
        int logowidth = fontlarge.getWidth("Gource");
        int logoheight = 100;
        int cwidth    = font.getWidth("Software Version Control Visualization");
        int awidth    = font.getWidth("(C) 2009 Andrew Caudwell");

        vec2f corner(display.width/2 - logowidth/2 - 30.0f, display.height/2 - 40);

        glDisable(GL_TEXTURE_2D);
        glColor4f(0.0f, 0.5f, 1.0f, splash * 0.015f);
        glBegin(GL_QUADS);
            glVertex2f(0.0f,                 corner.y);
            glVertex2f(0.0f,                 corner.y + logoheight);
            glVertex2f(display.width, corner.y + logoheight);
            glVertex2f(display.width, corner.y);
        glEnd();

        glEnable(GL_TEXTURE_2D);

        glColor4f(1.0,1.0,1.0,1.0);
        fontlarge.draw(display.width/2 - logowidth/2,display.height/2 - 30, "Gource");
        font.draw(display.width/2 - cwidth/2,display.height/2 + 10, "Software Version Control Visualization");
        font.draw(display.width/2 - awidth/2,display.height/2 + 30, "(C) 2009 Andrew Caudwell");
    }

    // text using the specified font goes here

    glColor4f(gGourceSettings.font_colour.x, gGourceSettings.font_colour.y, gGourceSettings.font_colour.z, 1.0f);

    if(!gGourceSettings.hide_date) {
        fontmedium.draw(display.width/2 - date_x_offset, 20, displaydate);
    }

    if(gGourceSettings.title.size()>0) {
        fontmedium.alignTop(false);
        fontmedium.draw(10, display.height - 10, gGourceSettings.title);
        fontmedium.alignTop(true);
    }

    if(message_timer>0.0f) {
         fontmedium.draw(1, 3, message);
    }

    // end text

    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

    if(debug) {
        font.print(1,20, "FPS: %.2f", fps);
        font.print(1,40,"Days Per Second: %.2f",
            gGourceSettings.days_per_second);
        font.print(1,60,"Time Scale: %.2f", time_scale);
        font.print(1,80,"Users: %d", users.size());
        font.print(1,100,"Files: %d", files.size());
        font.print(1,120,"Dirs: %d",  gGourceDirMap.size());

        font.print(1,140,"Log Position: %.4f", commitlog->getPercent());
        font.print(1,160,"Camera: (%.2f, %.2f, %.2f)", campos.x, campos.y, campos.z);
        font.print(1,180,"Gravity: %.2f", gGourceForceGravity);
        font.print(1,200,"Update Tree: %u ms", update_dir_tree_time);
        font.print(1,220,"Draw Tree: %u ms", draw_tree_time);
        font.print(1,240,"Mouse Trace: %u ms", trace_time);
        font.print(1,260,"Logic Time: %u ms", logic_time);
        font.print(1,280,"Draw Time: %u ms (Names: Calc Time = %u ms, Draw Time = %u ms)", SDL_GetTicks() - draw_time, name_calc_time, name_draw_time);
        font.print(1,300,"File Inner Loops: %d", gGourceFileInnerLoops);
        font.print(1,320,"User Inner Loops: %d", gGourceUserInnerLoops);
        font.print(1,340,"Dir Inner Loops: %d (QTree items = %d, nodes = %d)", gGourceDirNodeInnerLoops,
            dirNodeTree->item_count, dirNodeTree->node_count);

        if(selectedUser != 0) {

        }

        if(selectedFile != 0) {
            font.print(1,360,"%s: %d files (%d visible)", selectedFile->getDir()->getPath().c_str(),
                    selectedFile->getDir()->fileCount(), selectedFile->getDir()->visibleFileCount());
        }

    }

    glDisable(GL_TEXTURE_2D);

    if(canSeek()) slider.draw(dt);

    mousemoved=false;
    mouseclicked=false;
}
Пример #5
0
void loop() {
	// Calculate the position of the map that we are redrawing behind the old cursor
	map_redraw.x = cursor.position.x - cursor.r;
	map_redraw.y = cursor.position.y - cursor.r;
	
	// Calculate the source tile of the map that we are palcing
	map_tile.x = map_redraw.x + m_map.x;
	map_tile.y = map_redraw.y + m_map.y;
	
	// Ini redraw parameter, will be used to indicate that a redraw is required
	bool redraw = 0;
	
	// Analog read into joystick parameters
	JoyStick.x = analogRead(HORZJOY);
	JoyStick.y = analogRead(VERTJOY);
	
	// If there is a deviation from the initial readings, this indicates that there might be some redrawing required
	if(iniJoy.x != JoyStick.x || iniJoy.y != JoyStick.y)
	{
		moveJoystick(&JoyStick, &cursor, &tft, &redraw);
		moveCursorOff(&map_image, &tft, &cursor, &m_map, &redraw);
	}
	
	if(state)
	{
		// Determine the location of the cursor on the image file
		cursor_map.x = m_map.x + cursor.position.x;
		cursor_map.y = m_map.y + cursor.position.y;
		
		#if DEBUG
		Serial.print("Mapped (X,Y) Coord> (");
		Serial.print(cursor_map.x);
		Serial.print(",");
		Serial.print(cursor_map.y);
		Serial.println(")");
		
		Serial.print("Mapped (LON,LAT) Coord> (");
		Serial.print(x_to_lon(cursor_map.x));
		Serial.print(",");
		Serial.print(y_to_lat(cursor_map.y));
		Serial.println(")");
		#endif
		
		// Sets our page number to be zero
		uint16_t page = 1;
		
		// Prints loading screen to tft while loading and sorting get processed
		loadingScreen(&card, &tft);
		
		// Define RestDist structure for holding the distances from the different rest's
		// NOTE: As rest is an array, it does not need to be dereferenced
		RestDist rest[TOTAL_REST];
		
		// Load the restraunts from the SD card into the restdist array
		loadRest(&card, rest, &cursor_map, TOTAL_REST);
		
		// Use the comb sort algorithm to sort the list of restraunts
		comb_sort(rest, TOTAL_REST);
		
		// Print page 1 of the sorted list
		printRest(&card, &tft, rest, page);
		
		while(state)
		{
			// Reads the current position of the joystick
			JoyStick.y = analogRead(VERTJOY);
			
			/*
			* Checks whether the joystick has moved (selecting other restraunts from list) and prints the restraunt according the page passed, with added support for checking that you do not go over the amount of restraunts that were loaded.
			*/
			if(JoyStick.y > 800 && page != 1)
			{
				printRest(&card, &tft, rest, --page);
			}
			else if(JoyStick.y < 250 && (page - 1)*PAGESIZE + PAGESIZE < TOTAL_REST)
			{
				printRest(&card, &tft, rest, ++page);
			}
		}
		
		// Redraw the map
		lcd_image_draw(&map_image, &tft, &m_map, &c_zero, tft.width(), tft.height());
		
		// Redraw the cursor in its old position
		drawCursor(&tft, &cursor);
		
		// Set the redraw parameter to be zero
		redraw = 0;
	}
	
	/*
	*	This will redraw the map over the old cursor, and redraw the cursor in the new position if the cursor has been indicated as moved.
	*/
	
	if(redraw == 1)
	{
		// Included for DEBUG purposes
		#if DEBUG
		// Determine the location of the cursor on the image file
		cursor_map.x = m_map.x + cursor.position.x;
		cursor_map.y = m_map.y + cursor.position.y;
		
		Serial.print("Mapped (X,Y) Coord> (");
		Serial.print(cursor_map.x);
		Serial.print(",");
		Serial.print(cursor_map.y);
		Serial.println(")");
		
		Serial.print("Mapped (LON,LAT) Coord> (");
		Serial.print(x_to_lon(cursor_map.x));
		Serial.print(",");
		Serial.print(y_to_lat(cursor_map.y));
		Serial.println(")");
		#endif
		
		
		// Redraw the map in front of the old cursor
		lcd_image_draw(&map_image, &tft, &map_tile, &map_redraw, cursor.r*2+1, cursor.r*2+1);
		
		// Draw the new cursor at the new position
		drawCursor(&tft, &cursor);
	}
}