qmlfrontend/engine_instance.cpp
changeset 14373 4409344db447
parent 14372 b6824a53d4b1
child 14713 cc6ab1e3f7d5
equal deleted inserted replaced
14372:b6824a53d4b1 14373:4409344db447
    25           hwlib.resolve("hedgewars_engine_protocol_version"));
    25           hwlib.resolve("hedgewars_engine_protocol_version"));
    26   start_engine =
    26   start_engine =
    27       reinterpret_cast<Engine::start_engine_t*>(hwlib.resolve("start_engine"));
    27       reinterpret_cast<Engine::start_engine_t*>(hwlib.resolve("start_engine"));
    28   generate_preview = reinterpret_cast<Engine::generate_preview_t*>(
    28   generate_preview = reinterpret_cast<Engine::generate_preview_t*>(
    29       hwlib.resolve("generate_preview"));
    29       hwlib.resolve("generate_preview"));
       
    30   dispose_preview = reinterpret_cast<Engine::dispose_preview_t*>(
       
    31       hwlib.resolve("dispose_preview"));
    30   cleanup = reinterpret_cast<Engine::cleanup_t*>(hwlib.resolve("cleanup"));
    32   cleanup = reinterpret_cast<Engine::cleanup_t*>(hwlib.resolve("cleanup"));
    31 
    33 
    32   send_ipc = reinterpret_cast<Engine::send_ipc_t*>(hwlib.resolve("send_ipc"));
    34   send_ipc = reinterpret_cast<Engine::send_ipc_t*>(hwlib.resolve("send_ipc"));
    33   read_ipc = reinterpret_cast<Engine::read_ipc_t*>(hwlib.resolve("read_ipc"));
    35   read_ipc = reinterpret_cast<Engine::read_ipc_t*>(hwlib.resolve("read_ipc"));
    34 
    36 
    39       reinterpret_cast<Engine::render_frame_t*>(hwlib.resolve("render_frame"));
    41       reinterpret_cast<Engine::render_frame_t*>(hwlib.resolve("render_frame"));
    40   advance_simulation = reinterpret_cast<Engine::advance_simulation_t*>(
    42   advance_simulation = reinterpret_cast<Engine::advance_simulation_t*>(
    41       hwlib.resolve("advance_simulation"));
    43       hwlib.resolve("advance_simulation"));
    42 
    44 
    43   m_isValid = hedgewars_engine_protocol_version && start_engine &&
    45   m_isValid = hedgewars_engine_protocol_version && start_engine &&
    44               generate_preview && cleanup && send_ipc && read_ipc &&
    46               generate_preview && dispose_preview && cleanup && send_ipc &&
    45               setup_current_gl_context && render_frame && advance_simulation;
    47               read_ipc && setup_current_gl_context && render_frame &&
       
    48               advance_simulation;
    46   emit isValidChanged(m_isValid);
    49   emit isValidChanged(m_isValid);
    47 
    50 
    48   if (isValid()) {
    51   if (isValid()) {
    49     qDebug() << "Loaded engine library with protocol version"
    52     qDebug() << "Loaded engine library with protocol version"
    50              << hedgewars_engine_protocol_version();
    53              << hedgewars_engine_protocol_version();
    77   setup_current_gl_context(m_instance, static_cast<quint16>(size.width()),
    80   setup_current_gl_context(m_instance, static_cast<quint16>(size.width()),
    78                            static_cast<quint16>(size.height()),
    81                            static_cast<quint16>(size.height()),
    79                            &getProcAddress);
    82                            &getProcAddress);
    80 }
    83 }
    81 
    84 
    82 Engine::PreviewInfo EngineInstance::generatePreview() {
    85 QImage EngineInstance::generatePreview() {
    83   Engine::PreviewInfo pinfo;
    86   Engine::PreviewInfo pinfo;
    84 
    87 
    85   generate_preview(m_instance, &pinfo);
    88   generate_preview(m_instance, &pinfo);
    86 
    89 
    87   return pinfo;
    90   QVector<QRgb> colorTable;
       
    91   colorTable.resize(256);
       
    92   for (int i = 0; i < 256; ++i) colorTable[i] = qRgba(255, 255, 0, i);
       
    93 
       
    94   QImage previewImage(pinfo.land, static_cast<int>(pinfo.width),
       
    95                       static_cast<int>(pinfo.height), QImage::Format_Indexed8);
       
    96   previewImage.setColorTable(colorTable);
       
    97 
       
    98   // Cannot use it here, since QImage refers to original bytes
       
    99   // dispose_preview(m_instance);
       
   100 
       
   101   return previewImage;
    88 }
   102 }
    89 
   103 
    90 bool EngineInstance::isValid() const { return m_isValid; }
   104 bool EngineInstance::isValid() const { return m_isValid; }