예제 #1
0
void EventManager::HandleEvent(string name, msgEvent* msg)
{
    if(!P_VALID(msg))
        return;
    
    DWORD dwId = UtilTool::Crc32((LPBYTE)name.data(), name.length());
    if(!GT_VALID(dwId))
        return;
    
    EventMapItor itor = mEventMap.find(dwId);
    if(itor == mEventMap.end())
        return;
    
    EventList& events = itor->second;
    if(events.size() == 0)
        return;
    EventListItor iList = events.begin();
    EventListItor iListEnd = events.end();
    for(; iList != iListEnd; ++iList)
    {
        EventData* data = (EventData*)(*iList);
        if(!data->target)
            continue;
        
        (data->target->*(data->callback))(msg);
        //CCLOG("HandleEvent %s\n", name.c_str());
    }
}
예제 #2
0
void FrameManager::RegisterFrame(string name, FrameCreateCallBack creater)
{
    DWORD dwId = Util::Crc32((LPBYTE)name.data(), name.length());
    if(!GT_VALID(dwId))
        return;
    
    mFrameCretateMap.insert(make_pair(dwId, creater));
}
예제 #3
0
void EventManager::HandleCmd(string name, PROTOBUF_MESSAGE* cmd)
{
    DWORD dwId = UtilTool::hasCode((LPBYTE)name.c_str(), name.length());
    if(!GT_VALID(dwId))
        return;
    
    HandleCmd(dwId, cmd);
}
예제 #4
0
void NetManager::RegisterCmd(string name, TWrap<concrete_class> cmd)
{
    DWORD dwId = Util::Crc32((LPBYTE)name.data(), name.length());
    if(!GT_VALID(dwId))
        return;
    
    mMsgFactory.Register(cmd, dwId);
}
예제 #5
0
void NetManager::ParseCmd(LPBYTE pMsg)
{
    Json::Value root(Json::objectValue);
    Json::Reader jReader;
    jReader.parse((char*)pMsg , root);
    
    string name = root["cmd"].asString();
    //test
    //name = "userFacade.getServers";
    DWORD dwId = Util::Crc32((LPBYTE)name.data(), name.length());
    if(!GT_VALID(dwId))
        return;
    
    msgCmd* cmd = mMsgFactory.Create(dwId);
    if(!P_VALID(cmd))
        return;
    
    cmd->Parse(root);
    EventManager::Shared()->HandleCmd(name, cmd);
    delete cmd;
}
예제 #6
0
GameFrame* FrameManager::CreateFrame(string name)
{
    DWORD dwId = Util::Crc32((LPBYTE)name.data(), name.length());
    if(!GT_VALID(dwId))
        return NULL;
    
    FrameCreateMapItor itor = mFrameCretateMap.find(dwId);
    if(itor == mFrameCretateMap.end())
    {
        return NULL;
    }
    
    FrameCreateCallBack create =  itor->second;
    
    GameFrame* node = create();
    if(!P_VALID(node))
    {
        return NULL;
    }
    
    return node;
}
예제 #7
0
bool EventManager::RegisterGameEvent(string name, Ref* target, EventCallBack callback)
{
    DWORD dwId = UtilTool::Crc32((LPBYTE)name.data(), name.length());
    if(!GT_VALID(dwId))
        return false;
    
    EventMapItor itor = mEventMap.find(dwId);
    if(itor == mEventMap.end())
    {
        EventList events;
        mEventMap.insert(make_pair(dwId, events));
    }
    
    itor = mEventMap.find(dwId);
    EventList& events = itor->second;
    EventData* data = new EventData;
    data->dwId = dwId;
    data->target = target;
    target->retain();
    data->callback = callback;
    events.push_back(data);
    return true;
}
예제 #8
0
GameFrame* GameFrame::AddChildFrame(string className, string name)
{
    DWORD dwId = GT_INVALID;
    if(name == "")
        dwId = UtilTool::Crc32((LPBYTE)className.data(), className.length());
    else
        dwId = UtilTool::Crc32((LPBYTE)name.data(), name.length());
    
    if(!GT_VALID(dwId))
        return nullptr;
    
    FrameMapItor itor = mFrames.find(dwId);
    if(itor != mFrames.end())
        return nullptr;
    
    GameFrame* frame = FrameManager::Shared()->CreateFrame(className);
    if(!P_VALID(frame))
    {
        return nullptr;
    }
    
    if(!frame->LoadUI())
    {
        return nullptr;
    }
    frame->RegisterEvent();
    if(dwId == FrameManager::Shared()->GetMsgBoxID())
    {
        //todo
        this->addChild(frame, 9999999);
    }
    else
        this->addChild(frame);
    mFrames[dwId] = frame;
    frame->retain();
    return frame;
}