Beispiel #1
0
    void
    TextRenderer::render()
    {
        if (!m_Target)
        {
            throw std::logic_error("No render target set! Use `set_target` to "
                                   "link a target surface to this renderer.");
        }

        render_points();
        render_lines();
    }
void DebugRenderer::render(sf::RenderTarget& window)
{
    fps_counter++;
    if (fps_counter > 30)
    {
        fps = fps_counter / fps_timer.restart().asSeconds();
        fps_counter = 0;
    }
    string text = "";
    if (show_fps)
        text = text + "FPS: " + string(fps) + "\n";
    
    if (show_datarate && game_server)
    {
        text = text + string(game_server->getSendDataRate() / 1000, 1) + " kb per second\n";
        text = text + string(game_server->getSendDataRatePerClient() / 1000, 1) + " kb per client\n";
    }
    if (show_timing_graph)
    {
        if (timing_graph_points.size() > window.getView().getSize().x)
            timing_graph_points.clear();
        timing_graph_points.push_back(engine->getEngineTiming());
        sf::VertexArray update_points(sf::LinesStrip, timing_graph_points.size());
        sf::VertexArray collision_points(sf::LinesStrip, timing_graph_points.size());
        sf::VertexArray render_points(sf::LinesStrip, timing_graph_points.size());
        for(unsigned int n=0; n<timing_graph_points.size(); n++)
        {
            update_points[n].position.x = float(n);
            update_points[n].position.y = window.getView().getSize().y - timing_graph_points[n].update * 10000;
            collision_points[n].position.x = float(n);
            collision_points[n].position.y = window.getView().getSize().y - (timing_graph_points[n].update + timing_graph_points[n].collision) * 10000;
            render_points[n].position.x = float(n);
            render_points[n].position.y = window.getView().getSize().y - (timing_graph_points[n].render + timing_graph_points[n].update + timing_graph_points[n].collision) * 10000;
            
            update_points[n].color = sf::Color::Red;
            collision_points[n].color = sf::Color::Cyan;
            render_points[n].color = sf::Color::Green;
        }
        window.draw(update_points);
        window.draw(collision_points);
        window.draw(render_points);
        
        sf::Text text_update("Update: " + string(timing_graph_points.back().update * 1000) + "ms", *mainFont, 18);
        sf::Text text_collision("Collision: " + string(timing_graph_points.back().collision * 1000) + "ms", *mainFont, 18);
        sf::Text text_render("Render: " + string(timing_graph_points.back().render * 1000) + "ms", *mainFont, 18);

        sf::VertexArray fps60_line(sf::LinesStrip, 2);
        fps60_line[0].position = sf::Vector2f(0, window.getView().getSize().y - 166);
        fps60_line[1].position = sf::Vector2f(window.getView().getSize().x, window.getView().getSize().y - 166);
        fps60_line[0].color = sf::Color(255, 255, 255, 128);
        fps60_line[1].color = sf::Color(255, 255, 255, 128);
        window.draw(fps60_line);
        
        text_update.setPosition(0, window.getView().getSize().y - 18 * 3 - 170);
        text_collision.setPosition(0, window.getView().getSize().y - 18 * 2 - 170);
        text_render.setPosition(0, window.getView().getSize().y - 18 - 170);
        text_update.setColor(sf::Color::Red);
        text_collision.setColor(sf::Color::Cyan);
        text_render.setColor(sf::Color::Green);
        window.draw(text_update);
        window.draw(text_collision);
        window.draw(text_render);
    }

    sf::Text textElement(text, *mainFont, 18);
    textElement.setPosition(0, 0);
    window.draw(textElement);
}
Beispiel #3
0
int main(int argc, char *argv[]) {
    QApplication a(argc, argv);

    // open file
    string filename = "input100.txt";
    ifstream input;
    input.open(filename);

    // the vector of points
    vector<Point> points;

    // read points from file
    int N;
    int x;
    int y;

    input >> N;

    for (int i = 0; i < N; ++i) {
        input >> x >> y;
        points.push_back(Point(x, y));
    }
    input.close();

    // setup graphical window
    QGraphicsView *view = new QGraphicsView();
    QGraphicsScene *scene = new QGraphicsScene(0, 0, SCENE_WIDTH, SCENE_HEIGHT);
    view->setScene(scene);
    // draw points to screen all at once
    render_points(scene, points);
    view->scale(1, -1); //screen y-axis is inverted
    view->resize(view->sizeHint());
    view->setWindowTitle("Brute Force Pattern Recognition");
    view->show();

    // sort points by natural order
    // makes finding endpoints of line segments easy
    sort(points.begin(), points.end());
    auto begin = chrono::high_resolution_clock::now();

    //for each point int points
    for (unsigned int i=0;i<points.size();i++){
        //we create a map with the slope as key and a vector of points as value
        map<double,vector<Point>> point_map;

        //for each point that is "larger" than the point we takes its slopes to the current point i
        for (unsigned int j=i+1;j<points.size();++j){
            //and adds it to the maps in the vector with all other points with the same slope
            point_map[points.at(i).slopeTo(points.at(j))].push_back(points.at(j));
        }
        //after this we iterate through each key in the map
        for (map<double,vector<Point>>::iterator it=point_map.begin(); it!=point_map.end(); ++it){
            //and check if the vector has a size of of three or more
            if (it->second.size()>=3){
                //creates a line
                render_line(scene,points.at(i),*(it->second.end()-1));
                //process the event
                a.processEvents();
            }
        }


    }


    auto end = chrono::high_resolution_clock::now();
    cout << "Computing line segments took "
         << std::chrono::duration_cast<chrono::milliseconds>(end - begin).count()
         << " milliseconds." << endl;

    return a.exec(); // start Qt event loop
}