コード例 #1
0
ファイル: markdown_viewer.cpp プロジェクト: jingqi/organic
void MarkdownViewer::init_actions()
{
    assert(NULL == _action_reload);
    _action_reload = new QAction(QIcon(":/markdown-viewer/refresh"), tr("重新加载(&R)"), this);
    _action_reload->setStatusTip(tr("重新加载页面"));
    _action_reload->setToolTip(tr("重新加载页面"));
    _action_reload->setShortcut(QKeySequence::Refresh);
    _action_reload->setPriority(QAction::LowPriority);
    connect(_action_reload, SIGNAL(triggered()),
           this, SLOT(reload()));

    assert(NULL == _action_zoom_in);
    _action_zoom_in = new QAction(QIcon(":/markdown-viewer/zoom-in"), tr("放大(&I)"), this);
    _action_zoom_in->setStatusTip(tr("放大"));
    _action_zoom_in->setToolTip(tr("放大"));
    _action_zoom_in->setShortcut(QKeySequence::ZoomIn);
    _action_zoom_in->setPriority(QAction::LowPriority);
    connect(_action_zoom_in, SIGNAL(triggered()),
            this, SLOT(zoom_in()));

    assert(NULL == _action_zoom_out);
    _action_zoom_out = new QAction(QIcon(":/markdown-viewer/zoom-out"), tr("缩小(&O)"), this);
    _action_zoom_out->setStatusTip(tr("缩小"));
    _action_zoom_out->setToolTip(tr("缩小"));
    _action_zoom_out->setShortcut(QKeySequence::ZoomOut);
    _action_zoom_out->setPriority(QAction::LowPriority);
    connect(_action_zoom_out, SIGNAL(triggered()),
            this, SLOT(zoom_out()));

    assert(NULL == _action_reset_zoom);
    _action_reset_zoom = new QAction(QIcon(":/markdown-viewer/reset-zoom"), tr("重置缩放(&Z)"), this);
    _action_reset_zoom->setStatusTip(tr("重置缩放"));
    _action_reset_zoom->setToolTip(tr("重置缩放"));
    _action_reset_zoom->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Z));
    _action_reset_zoom->setPriority(QAction::LowPriority);
    connect(_action_reset_zoom, SIGNAL(triggered()),
            this, SLOT(reset_zoom()));
}
コード例 #2
0
void
update_and_render(Memory *memory, GameState *game_state, FrameBuffer *frame_buffer, Keys *keys, Mouse *mouse, u64 time_us, u32 last_frame_dt, u32 fps , u32 argc, char *argv[])
{
    if (!game_state->init)
    {
        init_render_segments(memory, game_state, frame_buffer);
        init_game(memory, game_state, keys, time_us, argc, argv);
        load_maze(memory, game_state, argc, argv);
        reset_zoom(game_state);
    }

    update_inputs(keys, &game_state->inputs, time_us);

    if (game_state->inputs.maps[SAVE].active)
    {
        serialize_maze(&game_state->maze, &game_state->functions, game_state->filename);
    }

    if (game_state->inputs.maps[RELOAD].active)
    {
        strcpy(game_state->persistent_str, "Reload!");
        load_maze(memory, game_state, argc, argv);
    }

    if (game_state->inputs.maps[RESET].active)
    {
        strcpy(game_state->persistent_str, "Reset!");
        reset_zoom(game_state);
    }

    if (game_state->inputs.maps[RESTART].active)
    {
        strcpy(game_state->persistent_str, "Restart!");
        delete_all_cars(&game_state->cars);
        reset_car_inputs(&game_state->ui);
        game_state->finish_sim_step_move = false;
        game_state->last_sim_tick = 0;
        game_state->sim_steps = 0;
    }

    if (game_state->inputs.maps[STEP_MODE_TOGGLE].active)
    {
        game_state->single_step = !game_state->single_step;
        log(L_GameLoop, "Changing stepping mode");
    }

    //
    // UPDATE VIEW
    //

    update_pan_and_zoom(game_state, mouse);

    RenderBasis render_basis;
    render_basis.world_per_pixel = game_state->world_per_pixel;
    render_basis.scale = squared(game_state->zoom / 30.0f);
    render_basis.scale_focus = game_state->scale_focus;
    render_basis.origin = game_state->maze_pos * game_state->world_per_pixel;
    render_basis.clip_region = game_state->world_render_region * game_state->world_per_pixel;

    RenderBasis orthographic_basis;
    get_orthographic_basis(&orthographic_basis, game_state->screen_render_region);

    //
    // UPDATE WORLD
    //

    ui_consume_mouse_clicks(game_state, &orthographic_basis, &game_state->ui, mouse, time_us);

    if (game_state->inputs.maps[SIM_TICKS_INC].active)
    {
        game_state->sim_ticks_per_s += .5f;
    }
    if (game_state->inputs.maps[SIM_TICKS_DEC].active)
    {
        game_state->sim_ticks_per_s -= .5f;
    }
    game_state->sim_ticks_per_s = clamp(.5, game_state->sim_ticks_per_s, 20);

    update_cells_ui_state(game_state, &render_basis, mouse, time_us);

    b32 sim = sim_tick(game_state, time_us);

    if (sim && game_state->ui.car_inputs == 0 && !game_state->finish_sim_step_move)
    {
        perform_cells_sim_tick(memory, game_state, &(game_state->maze.tree), time_us);
        perform_cars_sim_tick(memory, game_state, time_us);
    }

    if (sim && game_state->ui.car_inputs == 0)
    {
        move_cars(game_state);

        game_state->finish_sim_step_move = false;
        ++game_state->sim_steps;
    }

    annimate_cars(game_state, last_frame_dt);
    step_particles(&(game_state->particles), time_us);

    update_ui(game_state, &orthographic_basis, &game_state->ui, mouse, &game_state->inputs, time_us);

    //
    // RENDER
    //

    // Add render operations to queue

    game_state->render_operations.next_free = 0;

    add_fast_box_to_render_list(&game_state->render_operations, &orthographic_basis, (Rectangle) {
        (V2) {0,0},size(game_state->screen_render_region)
    }, (PixelColor) {
        255, 255, 255
    });

    draw_cells(game_state, &game_state->render_operations, &render_basis, &(game_state->maze.tree), time_us);
    draw_cars(game_state, &game_state->render_operations, &render_basis, &(game_state->cars), time_us);
    // render_particles(&(game_state->particles), &game_state->render_operations, &render_basis);

    r32 text_scale = 0.3;
    draw_string(&game_state->render_operations, &orthographic_basis, &game_state->bitmaps.font, size(game_state->screen_render_region) - CHAR_SIZE*text_scale*(V2) {
        strlen(game_state->persistent_str), 1
    }, game_state->persistent_str, text_scale, (V4) {
        1, 0, 0, 0
    });

    draw_ui(&game_state->render_operations, &orthographic_basis, &render_basis, &game_state->bitmaps.font, &game_state->cell_bitmaps, &game_state->ui, time_us);

    char str[4];
    fmted_str(str, 4, "%d", fps);
    draw_string(&game_state->render_operations, &orthographic_basis, &game_state->bitmaps.font, (V2) {
        0, 0
    }, str, 0.3, (V4) {
        1, 0, 0, 0
    });

    // Add render segments to render queue

    V2 ns = game_state->render_segs.n_segments;
    V2 s;
    for (s.y = 0; s.y < ns.y; ++s.y)
    {
        for (s.x = 0; s.x < ns.x; ++s.x)
        {
            RenderQueueData render_data;

            Rectangle *segment = game_state->render_segs.segments + (u32)s.y + (u32)ns.y*(u32)s.x;
            render_data.clip_region = *segment;

            render_data.frame_buffer = frame_buffer;
            render_data.render_operations = &game_state->render_operations;

#ifdef THREADED_RENDERING
            pthread_mutex_lock(&game_state->render_queue.mut);

            while (game_state->render_queue.full)
            {
                log(L_RenderQueue, "producer: queue FULL.");
                pthread_cond_wait(&game_state->render_queue.not_full, &game_state->render_queue.mut);
            }

            log(L_RenderQueue, "producer: Adding.");
            queue_add(&game_state->render_queue, render_data);

            pthread_mutex_unlock(&game_state->render_queue.mut);
            pthread_cond_signal(&game_state->render_queue.not_empty);
#else
            consume_render_operations(render_data.frame_buffer, render_data.render_operations, render_data.clip_region);
#endif
        }
    }

    // TODO: Wait for frame rendering to finish

    // TODO: Get rid of this
    game_state->last_render_basis = render_basis;
}