当前位置: 首页>>代码示例>>C++>>正文


C++ Synchronised类代码示例

本文整理汇总了C++中Synchronised的典型用法代码示例。如果您正苦于以下问题:C++ Synchronised类的具体用法?C++ Synchronised怎么用?C++ Synchronised使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Synchronised类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Message


//.........这里部分代码省略.........
        int y = height - int(1.5f * dim.Height);
        g_area = irr::core::recti(x, y, x + dim.Width, y + dim.Height);
        m_text->setRelativePosition(g_area);
        m_text->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
        m_text->grab();
        m_text->remove();
    }
    // ------------------------------------------------------------------------
    /** Draw the message. */
    void draw()
    {
        assert(m_text != NULL);
        m_text->draw();
    }

};   // class Message

// ============================================================================
/** A function class to compare messages, required for priority_queue. */
class CompareMessages
{
public:
    /** Used to sort messages by priority in the priority queue. Achievement
     * messages (1) need to have a higher priority than friend messages
     * (value 0), and errors (3) the highest priority. */
    bool operator() (const Message *a, const Message *b) const
    {
        return a->getMessageType() < b->getMessageType();
    }   // operator ()
};   // operator()

// ============================================================================
/** List of all messages. */
Synchronised<std::priority_queue<Message*, std::vector<Message*>,
                   CompareMessages> > g_all_messages;

/** How long the current message has been displayed. The special value
 *  -1 indicates that a new message was added when the queue was empty. */
float        g_current_display_time = -1.0f;

/** How long the current message should be displaed. */
float        g_max_display_time     = 5.0f;

/** The label widget used to show the current message. */
SkinWidgetContainer *g_container    = NULL;

// ============================================================================

void createLabel(Message *message)
{
    if(!g_container)
        g_container = new SkinWidgetContainer();

    g_current_display_time = 0.0f;
    // Maybe make this time dependent on message length as well?
    g_max_display_time     = 5.0f;
    message->init();
}   // createLabel

// ----------------------------------------------------------------------------
/** Called when the screen resolution is changed to compute the new
 *  position of the message. */
void updatePosition()
{
    g_all_messages.lock();
    bool empty = g_all_messages.getData().empty();
开发者ID:nado,项目名称:stk-code,代码行数:67,代码来源:message_queue.cpp

示例2: update

/** Update function called from the GUIEngine to handle displaying of the
 *  messages. It will make sure that each message is shown for a certain
 *  amount of time, before it is discarded and the next message (if any)
 *  is displayed.
 *  \param dt Time step size.
 */
void update(float dt)
{
    g_all_messages.lock();
    bool empty = g_all_messages.getData().empty();
    g_all_messages.unlock();
    if (empty) return;

    g_all_messages.lock();
    g_current_display_time += dt;
    if (g_current_display_time > g_max_display_time)
    {
        Message *last = g_all_messages.getData().top();
        g_all_messages.getData().pop();
        delete last;
        if (g_all_messages.getData().empty())
        {
            g_all_messages.unlock();
            return;
        }
        g_current_display_time = -1.0f;
    }

    Message *current = g_all_messages.getData().top();
    // Create new data for the display.
    if (g_current_display_time < 0)
    {
        createLabel(current);
    }
    g_all_messages.unlock();

    GUIEngine::getSkin()->drawMessage(g_container, g_area,
                                      current->getRenderType());
    current->draw();

}   // update
开发者ID:nado,项目名称:stk-code,代码行数:41,代码来源:message_queue.cpp

示例3: getMyAddress

 /** Returns the IP address of this host. We need to return a copy
  *  to make sure the address is thread safe (otherwise it could happen
  *  that e.g. data is taken when the IP address was written, but not
  *  yet the port). */
 const TransportAddress getMyAddress() const
 {
     TransportAddress a;
     m_my_address.lock();
     a.copy(m_my_address.getData());
     m_my_address.unlock();
     return a;
 }   // getMyAddress
开发者ID:Elderme,项目名称:stk-code,代码行数:12,代码来源:network_config.hpp

示例4: add

/** Adds a message to the message queue.
 *  \param mt The MessageType of the message.
 *  \param message The actual message.
 */
void add(MessageType mt, const irr::core::stringw &message)
{
    Message *m = new Message(mt, message);
    g_all_messages.lock();
    if (g_all_messages.getData().empty())
    {
        // Indicate that there is a new message, which should
        // which needs a new label etc. to be computed.
        g_current_display_time =-1.0f;
    }
    g_all_messages.getData().push(m);
    g_all_messages.unlock();
}   // add
开发者ID:nado,项目名称:stk-code,代码行数:17,代码来源:message_queue.cpp

示例5: updatePosition

/** Called when the screen resolution is changed to compute the new
 *  position of the message. */
void updatePosition()
{
    g_all_messages.lock();
    bool empty = g_all_messages.getData().empty();
    if (empty)
    {
        g_all_messages.unlock();
        return;
    }
    Message *last = g_all_messages.getData().top();
    createLabel(last);
    g_all_messages.unlock();
}   // updatePosition
开发者ID:nado,项目名称:stk-code,代码行数:15,代码来源:message_queue.cpp

示例6: clearErrorMessage

 /** Clears the error message. */
 void          clearErrorMessage() {m_error_message.setAtomic(""); }
开发者ID:qwertychouskie,项目名称:stk-code,代码行数:2,代码来源:news_manager.hpp

示例7: setErrorMessage

 /** Sets an error message that is displayed instead of any news message. */
 void          setErrorMessage(const core::stringw &s)
 {
     m_error_message.setAtomic(s);
 }   // setErrorMessage
开发者ID:qwertychouskie,项目名称:stk-code,代码行数:5,代码来源:news_manager.hpp

示例8: getAddon

 /** Returns the i-th addons. */
 const Addon& getAddon(unsigned int i) { return m_addons_list.getData()[i];}
开发者ID:langresser,项目名称:stk,代码行数:2,代码来源:addons_manager.hpp

示例9: getNumAddons

 /** Returns the list of addons (installed and uninstalled). */
 unsigned int getNumAddons() const { return m_addons_list.getData().size();}
开发者ID:langresser,项目名称:stk,代码行数:2,代码来源:addons_manager.hpp

示例10: setErrorState

 /** Marks addon as not being available. */
 void         setErrorState() { m_state.setAtomic(STATE_ERROR); }
开发者ID:langresser,项目名称:stk,代码行数:2,代码来源:addons_manager.hpp

示例11: isLoading

 // ------------------------------------------------------------------------
 bool         isLoading()   const { return m_state.getAtomic()==STATE_INIT; }
开发者ID:langresser,项目名称:stk,代码行数:2,代码来源:addons_manager.hpp

示例12: wasError

 // ------------------------------------------------------------------------
 bool         wasError()    const { return m_state.getAtomic()==STATE_ERROR;}
开发者ID:langresser,项目名称:stk,代码行数:2,代码来源:addons_manager.hpp

示例13: onlineReady

 /** Returns true if the list of online addons has been downloaded. This is 
  *  used to grey out the 'addons' entry till a network connections could be
  *  established. */
 bool         onlineReady() const {return m_state.getAtomic()==STATE_READY; }
开发者ID:langresser,项目名称:stk,代码行数:4,代码来源:addons_manager.hpp

示例14: getAbort

 bool getAbort() { return m_abort.getAtomic(); }
开发者ID:Charence,项目名称:stk-code,代码行数:1,代码来源:request_manager.hpp


注:本文中的Synchronised类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。