Ejemplo n.º 1
0
int main(int argc,char *argv[])
{

 FILE *bluetab;

 if(argc < 2)
 { 
   msgm();
   printf("Useage : ./bluetab <nickname>\n");
   return 0;
 } 
 else
 { 
   msgm();
   printf("bluetab.txt file created with your nickname . \n");
 }
 
 bluetab = fopen("bluetab.txt","w");
 if(!bluetab)
 {
   msgm();  
   printf("Some kind of file error!\n");
   return 0;
 }

 
 fprintf(bluetab,"%s%c%c%c",argv[1],tab1,tab2,dot1); 
 fclose(bluetab);
 return 0;
 
}
Ejemplo n.º 2
0
 set<int> get_quad_ids(FloatRect rect) {
     //array<int, 4>ret = {-1,-1,-1,-1};
     set<int> ret;
     auto depth = int(log2(1.f / max(rect.width, rect.height)));
     msgm("ids depth", depth)
     ret.insert(get_quad_id({ rect.left, rect.top }, depth));
     ret.insert(get_quad_id({ rect.left + rect.width, rect.top }, depth));
     ret.insert(get_quad_id({ rect.left, rect.top + rect.height }, depth));
     ret.insert(get_quad_id({ rect.left + rect.width, rect.top + rect.height }, depth));
     if (ret.count(-1)) ret.erase(-1);
     return ret;
 }
Ejemplo n.º 3
0
 int insert_balanced(int id, Vec2 pos){
     int quad_id = 0, depth = 0;
     while(flat_tree.count(quad_id)>=max_items_per_quad){
         ++depth;
         quad_id = get_quad_id(pos,depth);
         // msgm(
         //     "quad_id",quad_id,
         //     "count()",flat_tree.count(quad_id),
         //     );
     }
     msgm("inserting", id, "at", quad_id, "has", flat_tree.count(quad_id));
     insert(id,pos,depth);
     return quad_id;
 }
Ejemplo n.º 4
0
Archivo: main5.cpp Proyecto: jokoon/eio
    void insertquad(Vec2 from, int depth, Vec2 remainder, size_t parent,
		vector<vector<string>> &loggy)

        /*, int maxdepth*/
    {
        int side = 1;
        float subsize = pow(0.5f, depth);
        if (remainder.x > subsize) { side += 1; remainder.x -= subsize; }
        if (remainder.y > subsize) { side += 2; remainder.y -= subsize; }

        Vec2 quadpos = from + calc_dir2(depth+2, side - 1);
        float quadsize = pow(0.5f, depth + 1);
        size_t child = 4 * parent + side;
        msgm(parent, child, "from", from, "quadpos", quadpos, "remainder", remainder, "quadsize", quadsize);
        //lf.logw(to_str(parent, child, "from", from, "quadpos", quadpos, "remainder", remainder, "quadsize", quadsize));

		vector<string> logy =
		{
			strfy(parent),
			strfy(child),
			"from " + strfy(from),
			"quadpos " + strfy(quadpos),
			"remainder " + strfy(remainder),
			"quadsize " + strfy(quadsize)
		};
		//flatten(logy);
		loggy.push_back(logy);
		
        if (depth <= maxdepth)
        {
            insertquad(
                quadpos,
				depth + 1, remainder, child, loggy);
			//depth + 1, remainder, child, lf);
        }
    }
Ejemplo n.º 5
0
int main(int argc, char*argv[]) {
    // ████████ INITS 1 ████████
#ifndef COMMON_INITS1
    cfg.init("bedlab.cfg");
    ui2::init_ui();
    Vec2i windowsize;
    Vec2i screen_resolution = { int(VideoMode::getDesktopMode().width), int(VideoMode::getDesktopMode().height) };
    if (cfg.getvar<int>("auto_winsize")) {
        auto window_scale = cfg.getvar<Vec2>("window_scale");
        windowsize = Vec2i(scal(Vec2(screen_resolution), window_scale));
    }
    else {
        windowsize = cfg.getvar<Vec2i>("windowsize");
    }
    winsize = Vec2(windowsize);
    //UI.init_console(); // ALWAYS AFTER SO IT CAN GET WINDOW SIZE
    ui2::init_console(); // ALWAYS AFTER SO IT CAN GET WINDOW SIZE

    wincenter = 0.5f*Vec2(windowsize);
    Vec2i windowpos;
    VideoMode::getDesktopMode().height;
    if (cfg.getvar<int>("stick_left")) {
        windowpos = Vec2i(
            screen_resolution.x - windowsize.x - 10,
            screen_resolution.y - windowsize.y - 40
        );
    }
    else
        windowpos = (Vec2i(5, 25));

    sf::RenderWindow window(sf::VideoMode(windowsize.x, windowsize.y),
        "bedlab!", 7
        //,sf::ContextSettings(0, 0, 1)
    );
    window.setFramerateLimit(cfg.getvar<int>("fps_max"));
    frame_duration = 1.0f / cfg.getvar<int>("fps_max");

    window.setPosition(windowpos);

    vector<string> keys;
    auto choice = cfg.getstr("app");
    // show_keys(cfg.getstr("app"), keys);
#endif
// ████████ INITS2 ████████
#ifndef COMMON_INITS2

// we don't have a class/interface/struct with data, everything is local to this function, like a classic stack that all programs are anyway.
// Texture cursor_tx;
// if (!cursor_tx.loadFromFile(cfg.getstr("cursor")))
//     cout << "did not load cursor" << endl;
// Sprite cursor;
// cursor.setTexture(cursor_tx);
// cursor.setOrigin(3, 3);

    CircleShape cursor = mkcircle({ 0,0 }, Color::Transparent, 3, 1);
    Color background = cfg.getvar<Color>("background");
    window.setMouseCursorVisible(false);
    Vec2 mpos;
    bool leftclicked = false, rightclicked = false;

    // view and zoom
    View view, ui_view;
    ui_view = view = window.getDefaultView();
    float zoomlevel = 1;
    Vec2 mpos_abs;
    float frame_duration = 1.0f / cfg.getvar<int>("fps_max");
#endif // COMMON_INITS2
    // ████████ APP ACTUAL ████████
    {
        auto testarea = Vec2(winsize.y, winsize.y);
        auto offset = Vec2(-.5f*testarea);
        offset = { 0,0 };
        int many = 4;
        float cellsize = 0.5*testarea.x / many;
        map<Vec2i, RectangleShape> zone_rects;
    for (int i = 0; i < many + 1; ++i) {
        for (int j = 0; j < many + 1; ++j)
        {
            auto c = rgb_from_hue((float((i + j) % many)) / many);
            c.a = 128;
            auto r = mkrect2(
                Vec2(i*cellsize, j*cellsize)
                //+ offset
                ,
                Vec2(1, 1)*(cellsize - 10),
                Color::Transparent,
                5,
                false
            );
            r.setOutlineColor(c);
            //auto r_p = new RectangleShape();
            //*r_p = r;
            //grid[Vec2i(i, j)].insert(r_p);
            zone_rects[Vec2i(i, j)] = r;
            lf.logw(strfy(
                (float((i + j) % many)) / many) + " " + strfy(c)
            );
        }
    }
    }

    set<Vec2i> surround = {
        Vec2i(-1, -1) ,
        Vec2i(0, -1)  ,
        Vec2i(1, -1)  ,
        Vec2i(1, 0)   ,
        Vec2i(1, 1)   ,
        Vec2i(0, 1)   ,
        Vec2i(-1, 1)  ,
        Vec2i(-1, 0),
        Vec2i(0, 0)
    },
    active_chunks;
    float cell_size = 30;
    RectangleShape view_center = mkrect2({ 0,0 }, { 10,10 }, Color::Transparent, 1);
    RectangleShape world_center = mkrect2({ 0,0 }, { 6,6 }, Color::Red);
    //Vec2i reference_chunk = { 2,2 };
    Vec2i reference_chunk = {0,0};
    map<Vec2i, RectangleShape> chunks;
    
    for (int i = -5; i <= 5; ++i) {
        for (int j = -5; j <= 5; ++j) {
            chunks[Vec2i(i, j)] = mkrect2(cell_size*Vec2(i, j), { cell_size,cell_size }, Color::Transparent, 1);
        }
    }
    auto recenter_world = [&](Vec2i shift) {
        msgm("shifting", shift);
        world_center.move(Vec2(shift)*cell_size);
        for (auto&a : chunks) {
            a.second.move(Vec2(shift)*cell_size);
        }
        view.move(Vec2(shift)*cell_size);
        //world_center.setPosition(view.getCenter());
        world_center.move(-Vec2(shift)*cell_size);
        //for (auto&a : chunks) {
        //    a.second.setPosition(cell_size*Vec2(shift));
        //}

        for (auto&a : active_chunks) {
            chunks[a].setFillColor(Color::Transparent);
        }
        
        active_chunks.clear();
        // activate chunk surrounding the reference
        for (auto&a : surround) { 
            auto index = reference_chunk + a;
            active_chunks.insert(index);
            //chunks[index].setPosition(cell_size*Vec2(index));
            chunks[index].setFillColor(Color(255,0,0,128));
        }
    };
    recenter_world({ 0,0 });
    auto recenter_check = [&]() {
        view_center.setPosition(view.getCenter());
        //auto shift = Vec2i(2.f*view.getCenter() / (1.2f*cellsize));
        auto shift = -Vec2i(0.8f * view.getCenter() / cell_size);
        show(view.getCenter());
        //if (view.getCenter().x > cell_size*1.2f) reference_chunk.x -= 1;
        //if (view.getCenter().y > cell_size*1.2f) reference_chunk.y -= 1;
        //if (view.getCenter().x < -cell_size*1.2f) reference_chunk.x += 1;
        //if (view.getCenter().y < -cell_size*1.2f) reference_chunk.y += 1;

        //msg("recenter triggered!");
        //reposition_chunks();
        //reference_chunk = Vec2i();
        if (shift != Vec2i{0, 0}) recenter_world(shift);
        reference_chunk -= shift;
    };
    // ████████ callbacks ████████
    bool panning = false;
    Vec2 previous_mouse_pos;
    view.setCenter({ 0,0 });
    //view.sets
#ifndef LOOP_LAMBDAS
    draw = [&]() {
        window.setView(view);
        //////////////// OBJECTS THAT CAN ZOOMED ////////////////
        window.draw(glob_vert_single);
        for (auto&a : glob_pts)window.draw(a);
        for (auto&a : glob_rects)window.draw(a);
        for (auto&a : glob_vert)window.draw(a);
        for (auto&a : glob_texts)window.draw(a);
        //////////////// OBJECTS THAT CAN ZOOMED ////////////////
        //for (auto&a : zone_rects) window.draw(a.second);
        for (auto&a : chunks) window.draw(a.second);

        window.draw(view_center);
        window.draw(world_center);

        // UI draw, AFTER ui view and BEFORE other draw
        window.setView(ui_view);
        //////////////// OBJECTS THAT CANNOT ZOOMED, MEANING UI ////////////////
        //br.drawwithtext(window);
        ui2::draw(window);
        //UI.draw(window);
        window.draw(cursor);
    };
    update = [&]() {
        recenter_check();
    };
    treatkeyevent = [&](Keyboard::Key k) {
        switch (k)
        {
        case Keyboard::E:
            break;
        case Keyboard::I:

            break;
        case Keyboard::Q:
            break;
        case Keyboard::BackSpace:
            glob_pts.clear();
            glob_texts.clear();
            glob_rects.clear();
            glob_vert.clear();
            break;

        case Keyboard::Space:
            break;

        case Keyboard::S:
            screenshot(window);
            break;
        case Keyboard::Num1:
        case Keyboard::Num2:
        case Keyboard::Num3:
        case Keyboard::Num4:
        case Keyboard::Num5:
            break;
        }
    };
    mousemoved = [&](Vec2 pos) {
        cursor.setPosition(pos);
        if (leftclicked);
        if (panning) {
            view.move((previous_mouse_pos - pos));
        }
        previous_mouse_pos = pos;
    };
    mouseclick = [&](sf::Mouse::Button button) {
        if (button == Mouse::Button::Left) leftclicked = true;
        if (button == Mouse::Button::Right) rightclicked = true;
        if (button == Mouse::Button::Left) {
        };
        panning = leftclicked;

    };
    mouserelease = [&](sf::Mouse::Button button) {
        if (button == Mouse::Button::Left) leftclicked = false;
        if (button == Mouse::Button::Right) rightclicked = false;
        if (button == Mouse::Button::Left) {
        }
        panning = leftclicked;

    };
    loop = [&]() {
        while (window.isOpen())
        {
            sf::Event event;
            while (window.pollEvent(event))
            {
                switch (event.type)
                {
                case sf::Event::KeyPressed:
                    if (event.key.code == sf::Keyboard::Escape)
                        window.close();
                    treatkeyevent(event.key.code);
                    break;
                case sf::Event::Closed:
                    window.close();
                    break;
                case sf::Event::MouseButtonPressed:
                    mouseclick(event.mouseButton.button);
                    break;
                case sf::Event::MouseButtonReleased:
                    mouserelease(event.mouseButton.button);
                    break;
                case sf::Event::MouseMoved:
                    mpos = Vec2(event.mouseMove.x, event.mouseMove.y);
                    mpos_abs = window.mapPixelToCoords(Vec2i(mpos), view);
                    mousemoved(mpos);
                    break;
                default:
                    treatotherevent(event);
                    break;
                }
            }

            window.clear(background);
            update();
            draw();
            window.display();
        }
    };
    treatotherevent = [&](Event&e) {
        if (e.type == Event::MouseWheelMoved && e.mouseWheel.delta)
        {
            mpos_abs = window.mapPixelToCoords(Vec2i(mpos), view);

            //view = window.getView();
            if (e.mouseWheel.delta < 0)
            {
                zoomlevel *= 2.f;
                view.setSize(view.getSize()*2.f);
                view.setCenter(interp(mpos_abs, view.getCenter(), 2.f));
                //view.setCenter(interp(mpos_abs, view.getCenter(), 2.f));
            }
            if (e.mouseWheel.delta > 0)
            {
                zoomlevel *= 0.5;
                view.setSize(view.getSize()*.5f);
                view.setCenter(.5f*(view.getCenter() + mpos_abs));
                //view.setCenter(.5f*(view.getCenter() + mpos_abs));
            }
            window.setView(view);
        }
    };
#endif // LOOP_LAMBDAS

    loop();
}
Ejemplo n.º 6
0
int main(int argc, char*argv[]) {
#ifndef COMMON_INITS1
    cfg.init("bedlab.cfg");
    Vec2i windowsize;
    Vec2i screen_resolution = { int(VideoMode::getDesktopMode().width), int(VideoMode::getDesktopMode().height) };
    if (cfg.getvar<int>("auto_winsize")) {
        auto winscale_which = cfg.getstr("winscale_which");
        auto window_scale = cfg.getvar<Vec2>(winscale_which);
        windowsize = Vec2i(scal(Vec2(screen_resolution), window_scale));
    }
    else {
        windowsize = cfg.getvar<Vec2i>("windowsize");
    }
    winsize = Vec2(windowsize);
    UI.init_console(); // ALWAYS AFTER SO IT CAN GET WINDOW SIZE

    wincenter = 0.5f*Vec2(windowsize);
    Vec2i windowpos;
    VideoMode::getDesktopMode().height;
    if (cfg.getvar<int>("stick_left")) {
        windowpos = Vec2i(
            screen_resolution.x - windowsize.x - 10,
            screen_resolution.y - windowsize.y - 40
        );
    }
    else
        windowpos = (Vec2i(5, 25));

    sf::RenderWindow window(sf::VideoMode(windowsize.x, windowsize.y),
        "bedlab!", 7
        //,sf::ContextSettings(0, 0, 1)
    );
    window.setFramerateLimit(cfg.getvar<int>("fps_max"));
    frame_duration = 1.0f / cfg.getvar<int>("fps_max");

    window.setPosition(windowpos);

    vector<string> keys;
    auto choice = cfg.getstr("app");
    // show_keys(cfg.getstr("app"), keys);
#endif // COMMON_INITS1
#ifndef COMMON_INITS2
    // we don't have a class/interface/struct with data, everything is local to this function, like a classic stack that all programs are anyway.
    // Texture cursor_tx;
    // if (!cursor_tx.loadFromFile(cfg.getstr("cursor")))
    //     cout << "did not load cursor" << endl;
    // Sprite cursor;
    // cursor.setTexture(cursor_tx);
    // cursor.setOrigin(3, 3);

    CircleShape cursor = mkcircle({ 0,0 }, Color::Transparent, 3, 1);
    Color background = cfg.getvar<Color>("background");
    window.setMouseCursorVisible(false);
    Vec2 mpos;
    bool leftclicked = false, rightclicked = false;

    // view and zoom
    View view, ui_view;
    ui_view = view = window.getDefaultView();
    float zoomlevel = 1;
    Vec2 mpos_abs;
    float frame_duration = 1.0f / cfg.getvar<int>("fps_max");

    float smaller_size = 0.95*min(windowsize.y, windowsize.x);
    auto all_pt_mult = cfg.getvar<float>("all_pt_mult");
    all_pt_size = all_pt_mult * smaller_size;
    //Transform transf;
    //transf_glob.translate(smaller_size*0.1, smaller_size*0.5);
    transf_glob.translate(smaller_size*0.02, smaller_size*0.02);
    transf_glob.scale(Vec2(smaller_size, smaller_size));
    //transf_glob = transf;
    glob_vert_single = VertexArray(Lines);
#endif // COMMON_INITS2
#ifndef COMMON_INITS3
    bool point_text = cfg.getvar<int>("street_gen_point_text");

    bool alternate_font = cfg.getvar<int>("alternate_font");
    glob_vert = vector<VertexArray>(10, VertexArray(LineStrip));

    string bar_font;
    Vec2 barsize;
    auto winscale_which = cfg.getstr("winscale_which");
    if (winscale_which == "winscale_smallest" || winscale_which == "winscale_laptop") {
        bar_font = UI.small_font;;
        barsize = { 40,7 };
    }
    else if (winscale_which == "winscale_largest" || winscale_which == "winscale_large") {
        bar_font = UI.default_font;
        barsize = { 100,15 };
    }
    else {
        bar_font = UI.default_font;
        barsize = { 100,15 };
    }

    //dip_bars dbars(UI.fonts["unaligned"], UI.fontsizes[UI.default_font], { 100,15 });
    dip_bars dbars(UI.fonts[bar_font], UI.fontsizes[UI.default_font], barsize, { 1,1 });

    // tests in lambdas
    map<string, function<void(void)>> test_lambdas;
    VertexArray grid(Lines);
    auto make_grid = [&](float resolution) {
        // dummy grid
        grid.clear();
        Color col(64, 64, 64, 32);
        // glob_vert = vector<VertexArray>(10, VertexArray(Lines));
        for (int i = 0; i <= int(resolution); ++i)
            for (int j = 0; j <= int(resolution); ++j) {
                grid.append(Vertex(tr(Vec2(i / resolution, 0)), col));
                grid.append(Vertex(tr(Vec2(i / resolution, 1)), col));

                grid.append(Vertex(tr(Vec2(0, i / resolution)), col));
                grid.append(Vertex(tr(Vec2(1, i / resolution)), col));
            }
    };
    // actual tests

    diag_draw ddraw;

    function<void(void)> test_current = [&] {msg("no test configured"); };
    auto street_gen_test = cfg.getstr("street_gen_test");
    if (test_lambdas.count(street_gen_test)) {
        test_current = test_lambdas[street_gen_test];
        msgm("ok, using test", street_gen_test);
        test_current();
    }
    else {
        msg("invalid test choice string thing bing ding king ping ring sing wing wing");
    }
#endif // COMMON_INITS3
    // █████████████████████ APP ACTUAL █████████████████████



    // █████████████████████ callbacks █████████████████████

#ifndef LOOP_LAMBDAS
    draw = [&]() {
        window.setView(view);
        //////////////// OBJECTS THAT CAN ZOOMED ////////////////
        window.draw(grid);

        window.draw(glob_vert_single);
        for (auto&a : glob_pts)window.draw(a);
        for (auto&a : glob_rects)window.draw(a);
        for (auto&a : glob_vert)window.draw(a);
        if (point_text) for (auto&a : glob_texts)window.draw(a);

        ddraw.draw(window);

        // UI draw, AFTER ui view and BEFORE other draw
        window.setView(ui_view);
        //////////////// OBJECTS THAT CANNOT ZOOMED, MEANING UI ////////////////
        dbars.draw(window);
        //br.drawwithtext(window);
        UI.draw(window);
        window.draw(cursor);
    };
    update = [&]() {
    };
    treatkeyevent = [&](Keyboard::Key k) {
        switch (k)
        {
        case Keyboard::E:
            break;
        case Keyboard::T:
            point_text ^= 1;
            break;
        case Keyboard::Q:
            break;
        case Keyboard::BackSpace:
            glob_pts.clear();
            glob_texts.clear();
            glob_rects.clear();
            glob_vert.clear();
            break;
        case Keyboard::Space:
            break;
        case Keyboard::S:
            screenshot(window);
            break;
        case Keyboard::Num1:
        case Keyboard::Num2:
        case Keyboard::Num3:
        case Keyboard::Num4:
        case Keyboard::Num5:
            break;
        }
    };
    mousemoved = [&](Vec2 pos) {
        dbars.mouse_moved(mpos);
        cursor.setPosition(pos);
        if (leftclicked);
    };
    mouseclick = [&](sf::Mouse::Button button) {
        if (button == Mouse::Button::Left) leftclicked = true;
        if (button == Mouse::Button::Right) rightclicked = true;
        if (button == Mouse::Button::Left) {
            dbars.mouse_click(mpos);
            //test_search();
            //test_inter();
        }
        if (button == Mouse::Button::Right) {
            //test_inter();
        }
    };
    mouserelease = [&](sf::Mouse::Button button) {
        if (button == Mouse::Button::Left) leftclicked = false;
        if (button == Mouse::Button::Right) rightclicked = false;
        dbars.mouse_release();
        test_current();
    };
    loop = [&]() {
        while (window.isOpen())
        {
            sf::Event event;
            while (window.pollEvent(event))
            {
                switch (event.type)
                {
                case sf::Event::KeyPressed:
                    if (event.key.code == sf::Keyboard::Escape)
                        window.close();
                    treatkeyevent(event.key.code);
                    break;
                case sf::Event::Closed:
                    window.close();
                    break;
                case sf::Event::MouseButtonPressed:
                    mouseclick(event.mouseButton.button);
                    break;
                case sf::Event::MouseButtonReleased:
                    mouserelease(event.mouseButton.button);
                    break;
                case sf::Event::MouseMoved:
                    mpos = Vec2(event.mouseMove.x, event.mouseMove.y);
                    mpos_abs = window.mapPixelToCoords(Vec2i(mpos), view);
                    mousemoved(mpos);
                    break;
                default:
                    treatotherevent(event);
                    break;
                }
            }

            window.clear(background);
            update();
            draw();

            //static bool once = true;
            //if (once) {
            //    screenshot(window);
            //    once = false;
            //}

            window.display();

        }
    };
    treatotherevent = [&](Event&e) {
        if (e.type == Event::MouseWheelMoved && e.mouseWheel.delta)
        {
            mpos_abs = window.mapPixelToCoords(Vec2i(mpos), view);

            //view = window.getView();
            if (e.mouseWheel.delta < 0)
            {
                zoomlevel *= 2.f;
                view.setSize(view.getSize()*2.f);
                view.setCenter(interp(mpos_abs, view.getCenter(), 2.f));
                //view.setCenter(interp(mpos_abs, view.getCenter(), 2.f));
            }
            if (e.mouseWheel.delta > 0)
            {
                zoomlevel *= 0.5;
                view.setSize(view.getSize()*.5f);
                view.setCenter(.5f*(view.getCenter() + mpos_abs));
                //view.setCenter(.5f*(view.getCenter() + mpos_abs));
            }
            window.setView(view);
        }
    };
#endif // LOOP_LAMBDAS
    loop();
}