void CBaseMenuEdit::CopyStateEdit(CBaseMenuEdit *pmTo) { CopyState(pmTo,this,IDmenuEditDirectory); CopyState(pmTo,this,IDmenuEditCell); CopyState(pmTo,this,IDmenuDisableSample); CopyState(pmTo->GetMenuItemAccept(),this->GetMenuItemAccept()); CopyState(pmTo->GetMenuItemReview(),this->GetMenuItemReview()); GetMenuAccept()->CopyState(pmTo->GetMenuAccept()); GetMenuReview()->CopyState(pmTo->GetMenuReview()); }
/* Performs a move on the board, updating the state of the board */ void PerformMove(char board[8][8], char move[12], int mlen) { int i,j,x,y,x1,y1,x2,y2; NumberToXY(move[0],&x,&y); NumberToXY(move[mlen-1],&x1,&y1); CopyState(&board[y1][x1],board[y][x]); if(y1 == 0 || y1 == 7) board[y1][x1] |= King; board[y][x] &= Clear; NumberToXY(move[1],&x2,&y2); if(abs(x2-x) == 2) { for(i=0,j=1; j<mlen; i++,j++) { if(move[i] > move[j]) { y1 = -1; if((move[i]-move[j]) == 9) x1 = -1; else x1 = 1; } else { y1 = 1; if((move[j]-move[i]) == 7) x1 = -1; else x1 = 1; } NumberToXY(move[i],&x,&y); board[y+y1][x+x1] &= Clear; } } }
void CBaseMenuEdit::CopyState(wxMenu *pmTo, wxMenu *pmFrom, int nID) { wxMenuItem *pmiTo = pmTo->FindItem(nID); if(pmiTo != NULL) { wxMenuItem *pmiFrom = pmFrom->FindItem(nID); if(pmiFrom != NULL) { CopyState(pmiTo,pmiFrom); } } }
void MLNodeBrain::SetLocationState(state_t newState) { sem_wait(&this->binSem); for (unsigned i = 0; i < ySize; i++) { for (unsigned j = 0; j < xSize; j++) { if ((newState.y == i)&&(newState.x == j)) { CopyState(newState, agentBrain[i][j]); } } } sem_post(&this->binSem); }
DRAW_CONTEXT* GetDrawContext(SWR_CONTEXT *pContext, bool isSplitDraw = false) { RDTSC_START(APIGetDrawContext); // If current draw context is null then need to obtain a new draw context to use from ring. if (pContext->pCurDrawContext == nullptr) { uint32_t dcIndex = pContext->nextDrawId % KNOB_MAX_DRAWS_IN_FLIGHT; DRAW_CONTEXT* pCurDrawContext = &pContext->dcRing[dcIndex]; pContext->pCurDrawContext = pCurDrawContext; // Update LastRetiredId UpdateLastRetiredId(pContext); // Need to wait until this draw context is available to use. while (StillDrawing(pContext, pCurDrawContext)) { // Make sure workers are working. WakeAllThreads(pContext); _mm_pause(); } // Assign next available entry in DS ring to this DC. uint32_t dsIndex = pContext->curStateId % KNOB_MAX_DRAWS_IN_FLIGHT; pCurDrawContext->pState = &pContext->dsRing[dsIndex]; Arena& stateArena = pCurDrawContext->pState->arena; // Copy previous state to current state. if (pContext->pPrevDrawContext) { DRAW_CONTEXT* pPrevDrawContext = pContext->pPrevDrawContext; // If we're splitting our draw then we can just use the same state from the previous // draw. In this case, we won't increment the DS ring index so the next non-split // draw can receive the state. if (isSplitDraw == false) { CopyState(*pCurDrawContext->pState, *pPrevDrawContext->pState); stateArena.Reset(); // Reset memory. // Copy private state to new context. if (pPrevDrawContext->pState->pPrivateState != nullptr) { pCurDrawContext->pState->pPrivateState = stateArena.AllocAligned(pContext->privateStateSize, KNOB_SIMD_WIDTH*sizeof(float)); memcpy(pCurDrawContext->pState->pPrivateState, pPrevDrawContext->pState->pPrivateState, pContext->privateStateSize); } pContext->curStateId++; // Progress state ring index forward. } else { // If its a split draw then just copy the state pointer over // since its the same draw. pCurDrawContext->pState = pPrevDrawContext->pState; } } else { stateArena.Reset(); // Reset memory. pContext->curStateId++; // Progress state ring index forward. } pCurDrawContext->dependency = 0; pCurDrawContext->arena.Reset(); pCurDrawContext->pContext = pContext; pCurDrawContext->isCompute = false; // Dispatch has to set this to true. pCurDrawContext->inUse = false; pCurDrawContext->doneCompute = false; pCurDrawContext->doneFE = false; pCurDrawContext->FeLock = 0; pCurDrawContext->pTileMgr->initialize(); // Assign unique drawId for this DC pCurDrawContext->drawId = pContext->nextDrawId++; } else { SWR_ASSERT(isSplitDraw == false, "Split draw should only be used when obtaining a new DC"); } RDTSC_STOP(APIGetDrawContext, 0, 0); return pContext->pCurDrawContext; }
Server::Server(const struct ServerState &init_state, Window *w) : LockingReciever<Window, Monitor> (w) , last_channel(nullptr) , widget(new Fl_Group(0, 0, 800, 600)) , channel_list(nullptr) , task_died(false) , network_task(new ServerTask(this, init_state.socket, &task_died)){ CopyState(state, init_state); state.socket = init_state.socket; Channel *channel = new Channel(this, "server"); channel_list.reset(Parent->GenerateChannelBrowser()); channel->Handlers.push_back(std::unique_ptr<MessageHandler>(new ChannelMessage::YourHost_Handler(channel))); channel->Handlers.push_back(std::unique_ptr<MessageHandler>(new ChannelMessage::Notice_Handler(channel))); channel->Handlers.push_back(std::unique_ptr<MessageHandler>(new ChannelMessage::TopicExtra_Handler(channel))); AddChannel(channel); w->SetChannel(channel); Thread::AddShortRunningTask(network_task); Thread::AddSocketToTaskGroup(state.socket, Thread::GetShortThreadPool()); Handlers.push_back(std::unique_ptr<MessageHandler>(new Ping_Handler(this))); // This should all be put in the call before construction IRC_Message *msg_name = IRC_CreateUser(state.name.c_str(), "falcon", "millenium", state.real.c_str()); IRC_Message *msg_nick = IRC_CreateNick(state.nick.c_str()); Handlers.push_back(std::unique_ptr<MessageHandler>(new Debug_Handler())); Handlers.push_back(std::unique_ptr<MessageHandler>(new SendMessage_Handler(this, msg_name))); Handlers.push_back(std::unique_ptr<MessageHandler>(new SendMessage_Handler(this, msg_nick))); Handlers.push_back(std::unique_ptr<MessageHandler>(new Join_Handler(this))); Handlers.push_back(std::unique_ptr<MessageHandler>(new Part_Handler(this))); Handlers.push_back(std::unique_ptr<MessageHandler>(new Topic_Handler(this))); Handlers.push_back(std::unique_ptr<MessageHandler>(new PrivateMessage_Handler(this))); Handlers.push_back(std::unique_ptr<MessageHandler>(new NumericTopic_Handler(this))); Handlers.push_back(std::unique_ptr<MessageHandler>(new NumericNoTopic_Handler(this))); Handlers.push_back(std::unique_ptr<MessageHandler>(new Namelist_Handler(this))); Handlers.push_back(std::unique_ptr<MessageHandler>(new Quit_Handler(this))); Handlers.push_back(std::unique_ptr<MessageHandler>(new Nick_Handler(this))); Handlers.push_back(std::unique_ptr<MessageHandler>(new Notice_Handler(this))); for(std::list<std::string>::const_iterator iter = state.channels.cbegin(); iter!=state.channels.cend(); iter++){ printf("Joining %s.\n", iter->c_str()); IRC_Message *msg = IRC_CreateJoin(1, iter->c_str()); SendMessage(msg); JoinChannel(iter->c_str()); Handlers.push_back(std::unique_ptr<MessageHandler>(new SendMessageOn_Handler<OnMsgType<IRC_welcome_num> >(this, msg))); } printf("Creating Server.\n"); }