bool ONScripter::clickWait( char *out_text ) { flush( REFRESH_NONE_MODE ); skip_mode &= ~SKIP_TO_EOL; if (script_h.checkClickstr(script_h.getStringBuffer() + string_buffer_offset) != 1) string_buffer_offset++; string_buffer_offset++; if ( (skip_mode & (SKIP_NORMAL | SKIP_TO_EOP) || ctrl_pressed_status) && !textgosub_label ){ clickstr_state = CLICK_NONE; if ( out_text ){ drawChar( out_text, &sentence_font, false, true, accumulation_surface, &text_info ); } else{ // called on '@' flush(refreshMode()); } num_chars_in_sentence = 0; event_mode = IDLE_EVENT_MODE; if ( waitEvent(0) ) return false; } else{ if ( out_text ){ drawChar( out_text, &sentence_font, true, true, accumulation_surface, &text_info ); num_chars_in_sentence++; } while( (!(script_h.getEndStatus() & ScriptHandler::END_1BYTE_CHAR) && script_h.getStringBuffer()[ string_buffer_offset ] == ' ') || script_h.getStringBuffer()[ string_buffer_offset ] == '\t' ) string_buffer_offset ++; if ( textgosub_label ){ saveon_flag = false; textgosub_clickstr_state = CLICK_WAIT; if (script_h.getStringBuffer()[string_buffer_offset] == 0x0) textgosub_clickstr_state |= CLICK_EOL; gosubReal( textgosub_label, script_h.getNext(), true ); event_mode = IDLE_EVENT_MODE; waitEvent(0); return false; } // if this is the end of the line, pretext becomes enabled if (script_h.getStringBuffer()[string_buffer_offset] == 0x0) line_enter_status = 0; clickstr_state = CLICK_WAIT; if (doClickEnd()) return false; clickstr_state = CLICK_NONE; if (pagetag_flag) processEOT(); page_enter_status = 0; } return true; }
bool ONScripter::doClickEnd() { bool ret = false; draw_cursor_flag = true; if ( automode_flag ){ event_mode = WAIT_TEXT_MODE | WAIT_INPUT_MODE | WAIT_VOICE_MODE | WAIT_TIMER_MODE; if ( automode_time < 0 ) ret = waitEvent( -automode_time * num_chars_in_sentence ); else ret = waitEvent( automode_time ); } else if ( autoclick_time > 0 ){ event_mode = WAIT_TIMER_MODE; ret = waitEvent( autoclick_time ); } else{ event_mode = WAIT_TEXT_MODE | WAIT_INPUT_MODE | WAIT_TIMER_MODE; ret = waitEvent(-1); } num_chars_in_sentence = 0; draw_cursor_flag = false; return ret; }
u32 Connection::Receive(NetworkPacket* pkt, int timeout) { for(;;){ ConnectionEvent e = waitEvent(timeout); if(e.type != CONNEVENT_NONE) dout_con<<getDesc()<<": Receive: got event: " <<e.describe()<<std::endl; switch(e.type){ case CONNEVENT_NONE: //throw NoIncomingDataException("No incoming data"); return 0; case CONNEVENT_DATA_RECEIVED: if (e.data.getSize() < 2) { continue; } pkt->putRawPacket(*e.data, e.data.getSize(), e.peer_id); return e.data.getSize(); case CONNEVENT_PEER_ADDED: { if(m_bc_peerhandler) m_bc_peerhandler->peerAdded(e.peer_id); continue; } case CONNEVENT_PEER_REMOVED: { if(m_bc_peerhandler) m_bc_peerhandler->deletingPeer(e.peer_id, e.timeout); continue; } case CONNEVENT_BIND_FAILED: throw ConnectionBindFailed("Failed to bind socket " "(port already in use?)"); case CONNEVENT_CONNECT_FAILED: throw ConnectionException("Failed to connect"); } } return 0; //throw NoIncomingDataException("No incoming data"); }
HRESULT RunOnUIThread(CODE &&code, const ComPtr<ICoreDispatcher> &dispatcher) { ComPtr<IAsyncAction> asyncAction; HRESULT result = S_OK; boolean hasThreadAccess; result = dispatcher->get_HasThreadAccess(&hasThreadAccess); if (FAILED(result)) { return result; } if (hasThreadAccess) { return code(); } else { Event waitEvent( CreateEventEx(nullptr, nullptr, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS)); if (!waitEvent.IsValid()) { return E_FAIL; } HRESULT codeResult = E_FAIL; auto handler = Callback<AddFtmBase<IDispatchedHandler>::Type>([&codeResult, &code, &waitEvent] { codeResult = code(); SetEvent(waitEvent.Get()); return S_OK; }); result = dispatcher->RunAsync(CoreDispatcherPriority_Normal, handler.Get(), asyncAction.GetAddressOf()); if (FAILED(result)) { return result; } auto waitResult = WaitForSingleObjectEx(waitEvent.Get(), 10 * 1000, true); if (waitResult != WAIT_OBJECT_0) { // Wait 10 seconds before giving up. At this point, the application is in an // unrecoverable state (probably deadlocked). We therefore terminate the application // entirely. This also prevents stack corruption if the async operation is eventually // run. ERR() << "Timeout waiting for async action on UI thread. The UI thread might be blocked."; std::terminate(); return E_FAIL; } return codeResult; } }
bool Socket::WaitForSendReady(int msecs) { #ifdef WIN32 fd_set writeSet; FD_ZERO(&writeSet); FD_SET(connectSocket, &writeSet); TIMEVAL tv = { msecs / 1000, (msecs % 1000) * 1000 }; int ret = select(0, NULL, &writeSet, NULL, &tv); return ret != KNET_SOCKET_ERROR && ret != 0; #else Event waitEvent(connectSocket, EventWaitWrite); return waitEvent.Wait(msecs); #endif }
void MinerManager::eventLoop() { size_t blocksMined = 0; for (;;) { m_logger(Logging::DEBUGGING) << "waiting for event"; MinerEvent event = waitEvent(); switch (event.type) { case MinerEventType::BLOCK_MINED: { m_logger(Logging::DEBUGGING) << "got BLOCK_MINED event"; stopBlockchainMonitoring(); if (submitBlock(m_minedBlock, m_config.daemonHost, m_config.daemonPort)) { m_lastBlockTimestamp = m_minedBlock.timestamp; if (m_config.blocksLimit != 0 && ++blocksMined == m_config.blocksLimit) { m_logger(Logging::INFO) << "Miner mined requested " << m_config.blocksLimit << " blocks. Quitting"; return; } } BlockMiningParameters params = requestMiningParameters(m_dispatcher, m_config.daemonHost, m_config.daemonPort, m_config.miningAddress); adjustBlockTemplate(params.blockTemplate); startBlockchainMonitoring(); startMining(params); break; } case MinerEventType::BLOCKCHAIN_UPDATED: { m_logger(Logging::DEBUGGING) << "got BLOCKCHAIN_UPDATED event"; stopMining(); stopBlockchainMonitoring(); BlockMiningParameters params = requestMiningParameters(m_dispatcher, m_config.daemonHost, m_config.daemonPort, m_config.miningAddress); adjustBlockTemplate(params.blockTemplate); startBlockchainMonitoring(); startMining(params); break; } default: assert(false); return; } } }
static int32 simonThread(void* cookie) { ObjectView* objectView = reinterpret_cast<ObjectView*>(cookie); int noPause = 0; while (acquire_sem_etc(objectView->quittingSem, 1, B_TIMEOUT, 0) == B_NO_ERROR) { if (objectView->SpinIt()) { objectView->DrawFrame(noPause); release_sem(objectView->quittingSem); noPause = 1; } else { release_sem(objectView->quittingSem); noPause = 0; waitEvent(objectView->drawEvent); } } return 0; }
status_t Dispatcher::WaitInternal(int dispatcherCount, Dispatcher *dispatchers[], WaitFlags flags, bigtime_t timeout, WaitTag tags[]) { status_t result = E_NO_ERROR; ThreadWaitEvent waitEvent(Thread::GetRunningThread(), flags); for (int dispatcherIndex = 0; dispatcherIndex < dispatcherCount; dispatcherIndex++) { tags[dispatcherIndex].fEvent = &waitEvent; dispatchers[dispatcherIndex]->fTags.Enqueue(&tags[dispatcherIndex]); tags[dispatcherIndex].fEventNext = waitEvent.fTags; tags[dispatcherIndex].fDispatcher = dispatchers[dispatcherIndex]; waitEvent.fTags = &tags[dispatcherIndex]; } if (timeout != INFINITE_TIMEOUT) waitEvent.SetTimeout(SystemTime() + timeout, kOneShotTimer); waitEvent.fThread->SetState(kThreadWaiting); gScheduler.Reschedule(); result = waitEvent.fWakeError; return result; }
bool Pipe::_cmdFrameStart( co::ICommand& cmd ) { LB_TS_THREAD( _pipeThread ); co::ObjectICommand command( cmd ); const uint128_t version = command.get< uint128_t >(); const uint128_t frameID = command.get< uint128_t >(); const uint32_t frameNumber = command.get< uint32_t >(); LBVERB << "handle pipe frame start " << command << " frame " << frameNumber << " id " << frameID << std::endl; LBLOG( LOG_TASKS ) << "---- TASK start frame ---- frame " << frameNumber << " id " << frameID << std::endl; sync( version ); const int64_t lastFrameTime = _impl->frameTime; _impl->frameTimeMutex.set(); LBASSERT( !_impl->frameTimes.empty( )); _impl->frameTime = _impl->frameTimes.front(); _impl->frameTimes.pop_front(); _impl->frameTimeMutex.unset(); if( lastFrameTime > 0 ) { PipeStatistics waitEvent( Statistic::PIPE_IDLE, this ); waitEvent.event.statistic.idleTime = _impl->thread ? _impl->thread->getWorkerQueue()->resetWaitTime() :0; waitEvent.event.statistic.totalTime = LB_MAX( _impl->frameTime - lastFrameTime, 1 ); // avoid SIGFPE } LBASSERTINFO( _impl->currentFrame + 1 == frameNumber, "current " <<_impl->currentFrame << " start " << frameNumber); frameStart( frameID, frameNumber ); return true; }
/*! In case of attached mode, the current context must be reset to context for client \param [in] event Event sent to server */ void CContextClient::sendEvent(CEventClient& event) { list<int> ranks = event.getRanks(); if (!event.isEmpty()) { list<int> sizes = event.getSizes(); // We force the getBuffers call to be non-blocking on the servers list<CBufferOut*> buffList; bool couldBuffer = getBuffers(ranks, sizes, buffList, !CXios::isClient); if (couldBuffer) { event.send(timeLine, sizes, buffList); checkBuffers(ranks); if (isAttachedModeEnabled()) // couldBuffer is always true in attached mode { waitEvent(ranks); CContext::setCurrent(context->getId()); } } else { tmpBufferedEvent.ranks = ranks; tmpBufferedEvent.sizes = sizes; for (list<int>::const_iterator it = sizes.begin(); it != sizes.end(); it++) tmpBufferedEvent.buffers.push_back(new CBufferOut(*it)); event.send(timeLine, tmpBufferedEvent.sizes, tmpBufferedEvent.buffers); } } timeLine++; }
int myRead(int epfd, int pipefd0, struct epoll_event *e) { int ret, i; if((ret = waitEvent(epfd, e)) < 0){ myLog(logFetal, NULL, "epoll_wait error: %s", strerror(errno)); return -1; } if(ret > 0){ LogConfig conf; conf.logfile = "test.log"; conf.syslog_enabled = 1; for(i = 0; i< ret; i++){ char rBuf[1024]; memset(rBuf, 0x0, 1024); read(pipefd0, rBuf, 1024); myLog(logInfo, NULL, "child -> %s\n", rBuf); } } return ret; }
bool ONScripterLabel::doEffect( EffectLink *effect, bool clear_dirty_region ) { bool first_time = (effect_counter == 0); effect_start_time = SDL_GetTicks(); effect_timer_resolution = effect_start_time - effect_start_time_old; effect_start_time_old = effect_start_time; int effect_no = effect->effect; if (first_time) { if ( (effect_cut_flag && ( ctrl_pressed_status || skip_mode & SKIP_NORMAL )) || (effectspeed == EFFECTSPEED_INSTANT) ) effect_no = 1; } skip_effect = false; int i, amp; int width, width2; int height, height2; SDL_Rect src_rect={0, 0, screen_width, screen_height}; SDL_Rect dst_rect={0, 0, screen_width, screen_height}; SDL_Rect quake_rect={0, 0, screen_width, screen_height}; /* ---------------------------------------- */ /* Execute effect */ if (debug_level > 0 && first_time) printf("Effect number %d, %d ms\n", effect_no, effect_duration ); bool not_implemented = false; switch ( effect_no ){ case 0: // Instant display case 1: // Instant display //drawEffect( &src_rect, &src_rect, effect_dst_surface ); break; case 2: // Left shutter width = EFFECT_STRIPE_WIDTH * effect_counter / effect_duration; for ( i=0 ; i<screen_width/EFFECT_STRIPE_WIDTH ; i++ ){ src_rect.x = i * EFFECT_STRIPE_WIDTH; src_rect.y = 0; src_rect.w = width; src_rect.h = screen_height; drawEffect(&src_rect, &src_rect, effect_dst_surface); } break; case 3: // Right shutter width = EFFECT_STRIPE_WIDTH * effect_counter / effect_duration; for ( i=1 ; i<=screen_width/EFFECT_STRIPE_WIDTH ; i++ ){ src_rect.x = i * EFFECT_STRIPE_WIDTH - width - 1; src_rect.y = 0; src_rect.w = width; src_rect.h = screen_height; drawEffect(&src_rect, &src_rect, effect_dst_surface); } break; case 4: // Top shutter height = EFFECT_STRIPE_WIDTH * effect_counter / effect_duration; for ( i=0 ; i<screen_height/EFFECT_STRIPE_WIDTH ; i++ ){ src_rect.x = 0; src_rect.y = i * EFFECT_STRIPE_WIDTH; src_rect.w = screen_width; src_rect.h = height; drawEffect(&src_rect, &src_rect, effect_dst_surface); } break; case 5: // Bottom shutter height = EFFECT_STRIPE_WIDTH * effect_counter / effect_duration; for ( i=1 ; i<=screen_height/EFFECT_STRIPE_WIDTH ; i++ ){ src_rect.x = 0; src_rect.y = i * EFFECT_STRIPE_WIDTH - height - 1; src_rect.w = screen_width; src_rect.h = height; drawEffect(&src_rect, &src_rect, effect_dst_surface); } break; case 6: // Left curtain width = EFFECT_STRIPE_CURTAIN_WIDTH * effect_counter * 2 / effect_duration; for ( i=0 ; i<=screen_width/EFFECT_STRIPE_CURTAIN_WIDTH ; i++ ){ width2 = width - EFFECT_STRIPE_CURTAIN_WIDTH * EFFECT_STRIPE_CURTAIN_WIDTH * i / screen_width; if ( width2 >= 0 ){ src_rect.x = i * EFFECT_STRIPE_CURTAIN_WIDTH; src_rect.y = 0; src_rect.w = width2; src_rect.h = screen_height; drawEffect(&src_rect, &src_rect, effect_dst_surface); } } break; case 7: // Right curtain width = EFFECT_STRIPE_CURTAIN_WIDTH * effect_counter * 2 / effect_duration; for ( i=0 ; i<=screen_width/EFFECT_STRIPE_CURTAIN_WIDTH ; i++ ){ width2 = width - EFFECT_STRIPE_CURTAIN_WIDTH * EFFECT_STRIPE_CURTAIN_WIDTH * i / screen_width; if ( width2 >= 0 ){ if ( width2 > EFFECT_STRIPE_CURTAIN_WIDTH ) width2 = EFFECT_STRIPE_CURTAIN_WIDTH; src_rect.x = screen_width - i * EFFECT_STRIPE_CURTAIN_WIDTH - width2; src_rect.y = 0; src_rect.w = width2; src_rect.h = screen_height; drawEffect(&src_rect, &src_rect, effect_dst_surface); } } break; case 8: // Top curtain height = EFFECT_STRIPE_CURTAIN_WIDTH * effect_counter * 2 / effect_duration; for ( i=0 ; i<=screen_height/EFFECT_STRIPE_CURTAIN_WIDTH ; i++ ){ height2 = height - EFFECT_STRIPE_CURTAIN_WIDTH * EFFECT_STRIPE_CURTAIN_WIDTH * i / screen_height; if ( height2 >= 0 ){ src_rect.x = 0; src_rect.y = i * EFFECT_STRIPE_CURTAIN_WIDTH; src_rect.w = screen_width; src_rect.h = height2; drawEffect(&src_rect, &src_rect, effect_dst_surface); } } break; case 9: // Bottom curtain height = EFFECT_STRIPE_CURTAIN_WIDTH * effect_counter * 2 / effect_duration; for ( i=0 ; i<=screen_height/EFFECT_STRIPE_CURTAIN_WIDTH ; i++ ){ height2 = height - EFFECT_STRIPE_CURTAIN_WIDTH * EFFECT_STRIPE_CURTAIN_WIDTH * i / screen_height; if ( height2 >= 0 ){ src_rect.x = 0; src_rect.y = screen_height - i * EFFECT_STRIPE_CURTAIN_WIDTH - height2; src_rect.w = screen_width; src_rect.h = height2; drawEffect(&src_rect, &src_rect, effect_dst_surface); } } break; default: not_implemented = true; if (first_time) { snprintf(script_h.errbuf, MAX_ERRBUF_LEN, "effect No. %d not implemented; substituting crossfade", effect_no); errorAndCont(script_h.errbuf); } case 10: // Cross fade height = 256 * effect_counter / effect_duration; effectBlend( NULL, ALPHA_BLEND_CONST, height, &dirty_rect.bounding_box ); break; case 11: // Left scroll width = screen_width * effect_counter / effect_duration; src_rect.x = 0; dst_rect.x = width; src_rect.y = dst_rect.y = 0; src_rect.w = dst_rect.w = screen_width - width; src_rect.h = dst_rect.h = screen_height; drawEffect(&dst_rect, &src_rect, effect_src_surface); src_rect.x = screen_width - width - 1; dst_rect.x = 0; src_rect.y = dst_rect.y = 0; src_rect.w = dst_rect.w = width; src_rect.h = dst_rect.h = screen_height; drawEffect(&dst_rect, &src_rect, effect_dst_surface); break; case 12: // Right scroll width = screen_width * effect_counter / effect_duration; src_rect.x = width; dst_rect.x = 0; src_rect.y = dst_rect.y = 0; src_rect.w = dst_rect.w = screen_width - width; src_rect.h = dst_rect.h = screen_height; drawEffect(&dst_rect, &src_rect, effect_src_surface); src_rect.x = 0; dst_rect.x = screen_width - width - 1; src_rect.y = dst_rect.y = 0; src_rect.w = dst_rect.w = width; src_rect.h = dst_rect.h = screen_height; drawEffect(&dst_rect, &src_rect, effect_dst_surface); break; case 13: // Top scroll width = screen_height * effect_counter / effect_duration; src_rect.x = dst_rect.x = 0; src_rect.y = 0; dst_rect.y = width; src_rect.w = dst_rect.w = screen_width; src_rect.h = dst_rect.h = screen_height - width; drawEffect(&dst_rect, &src_rect, effect_src_surface); src_rect.x = dst_rect.x = 0; src_rect.y = screen_height - width - 1; dst_rect.y = 0; src_rect.w = dst_rect.w = screen_width; src_rect.h = dst_rect.h = width; drawEffect(&dst_rect, &src_rect, effect_dst_surface); break; case 14: // Bottom scroll width = screen_height * effect_counter / effect_duration; src_rect.x = dst_rect.x = 0; src_rect.y = width; dst_rect.y = 0; src_rect.w = dst_rect.w = screen_width; src_rect.h = dst_rect.h = screen_height - width; drawEffect(&dst_rect, &src_rect, effect_src_surface); src_rect.x = dst_rect.x = 0; src_rect.y = 0; dst_rect.y = screen_height - width - 1; src_rect.w = dst_rect.w = screen_width; src_rect.h = dst_rect.h = width; drawEffect(&dst_rect, &src_rect, effect_dst_surface); break; case 15: // Fade with mask effectBlend( effect->anim.image_surface, ALPHA_BLEND_FADE_MASK, 256 * effect_counter / effect_duration, &dirty_rect.bounding_box ); break; case 16: // Mosaic out generateMosaic( effect_src_surface, 5 - 6 * effect_counter / effect_duration ); break; case 17: // Mosaic in generateMosaic( effect_dst_surface, 6 * effect_counter / effect_duration ); break; case 18: // Cross fade with mask effectBlend( effect->anim.image_surface, ALPHA_BLEND_CROSSFADE_MASK, 256 * effect_counter * 2 / effect_duration, &dirty_rect.bounding_box ); break; case (MAX_EFFECT_NUM + 0): // quakey if ( effect_timer_resolution > effect_duration / 4 / effect->no ) effect_timer_resolution = effect_duration / 4 / effect->no; amp = (Sint16)(sin(M_PI * 2.0 * effect->no * effect_counter / effect_duration) * EFFECT_QUAKE_AMP * effect->no * (effect_duration - effect_counter) / effect_duration); dst_rect.x = 0; dst_rect.y = amp; drawEffect(&dst_rect, &src_rect, effect_dst_surface); if (amp >= 0){ quake_rect.y = 0; quake_rect.h = amp; } else{ quake_rect.y = screen_height + amp; quake_rect.h = -amp; } SDL_FillRect( accumulation_surface, &quake_rect, SDL_MapRGBA( accumulation_surface->format, 0, 0, 0, 0xff ) ); break; case (MAX_EFFECT_NUM + 1): // quakex if ( effect_timer_resolution > effect_duration / 4 / effect->no ) effect_timer_resolution = effect_duration / 4 / effect->no; amp = (Sint16)(sin(M_PI * 2.0 * effect->no * effect_counter / effect_duration) * EFFECT_QUAKE_AMP * effect->no * (effect_duration - effect_counter) / effect_duration); dst_rect.x = amp; dst_rect.y = 0; drawEffect(&dst_rect, &src_rect, effect_dst_surface); if (amp >= 0){ quake_rect.x = 0; quake_rect.w = amp; } else{ quake_rect.x = screen_width + amp; quake_rect.w = -amp; } SDL_FillRect( accumulation_surface, &quake_rect, SDL_MapRGBA( accumulation_surface->format, 0, 0, 0, 0xff ) ); break; case (MAX_EFFECT_NUM + 2 ): // quake dst_rect.x = effect->no*((int)(3.0*rand()/(RAND_MAX+1.0)) - 1) * 2; dst_rect.y = effect->no*((int)(3.0*rand()/(RAND_MAX+1.0)) - 1) * 2; SDL_FillRect( accumulation_surface, NULL, SDL_MapRGBA( accumulation_surface->format, 0, 0, 0, 0xff ) ); drawEffect(&dst_rect, &src_rect, effect_dst_surface); break; case (MAX_EFFECT_NUM + 3 ): // flushout if (effect_counter > 0){ width = 30 * effect_counter / effect_duration; height = 30 * (effect_counter + effect_timer_resolution) / effect_duration; if (height > width){ doFlushout(height); effectBlend( NULL, ALPHA_BLEND_CONST, effect_counter * 256 / effect_duration, &dirty_rect.bounding_box, effect_tmp_surface ); } } break; case 99: // dll-based if (dll != NULL) { if (!strncmp(dll, "cascade.dll", 11)) { effectCascade(params, effect_duration); } else if (!strncmp(dll, "whirl.dll", 9)) { effectWhirl(params, effect_duration); } else if (!strncmp(dll, "trvswave.dll", 12)) { effectTrvswave(params, effect_duration); } else if (!strncmp(dll, "breakup.dll", 11)) { effectBreakup(params, effect_duration); } else { not_implemented = true; if (first_time) { snprintf(script_h.errbuf, MAX_ERRBUF_LEN, "dll effect '%s' (%d) not implemented; substituting crossfade", dll, effect_no); errorAndCont(script_h.errbuf); } } } else { //just in case no dll is given not_implemented = true; if (first_time) { snprintf(script_h.errbuf, MAX_ERRBUF_LEN, "no dll provided for effect %d; substituting crossfade", effect_no); errorAndCont(script_h.errbuf); } } if (not_implemented) { // do crossfade height = 256 * effect_counter / effect_duration; effectBlend( NULL, ALPHA_BLEND_CONST, height, &dirty_rect.bounding_box ); } break; } if (debug_level > 1) printf("\teffect count %d / dur %d\n", effect_counter, effect_duration); effect_counter += effect_timer_resolution; //check for events before drawing event_mode = IDLE_EVENT_MODE; event_mode |= WAIT_NO_ANIM_MODE; if (effectskip_flag) { event_mode |= WAIT_INPUT_MODE; } waitEvent(0); event_mode &= ~(WAIT_NO_ANIM_MODE | WAIT_INPUT_MODE); if ( effect_counter < effect_duration && effect_no != 1 ){ if ( effect_no != 0 ) flush( REFRESH_NONE_MODE, NULL, false ); if (effectskip_flag && skip_effect) effect_counter = effect_duration; return true; } else { //last call SDL_BlitSurface(effect_dst_surface, &dirty_rect.bounding_box, accumulation_surface, &dirty_rect.bounding_box); if (effect_no != 0) flush(REFRESH_NONE_MODE, NULL, clear_dirty_region); if (effect_no == 1) effect_counter = 0; else if ((effect_no == 99) && (dll != NULL)){ dll = params = NULL; } display_mode &= ~DISPLAY_MODE_UPDATED; if (effect_blank != 0 && effect_counter != 0) { event_mode = WAIT_TIMER_MODE; if ( ctrl_pressed_status || (skip_mode & SKIP_TO_WAIT) ) waitEvent(1); //allow a moment to detect ctrl unpress, if any else waitEvent(effect_blank); } event_mode = IDLE_EVENT_MODE; return false; } }
bool EventObjWrapper::waitEventWrapper(unsigned int timeout_ms) { return waitEvent(*eventObj, timeout_ms); }
bool ONScripter::processText() { //printf("textCommand %c %d %d %d\n", script_h.getStringBuffer()[ string_buffer_offset ], string_buffer_offset, event_mode, line_enter_status); char out_text[3]= {'\0', '\0', '\0'}; //printf("*** textCommand %d (%d,%d)\n", string_buffer_offset, sentence_font.xy[0], sentence_font.xy[1]); while( (!(script_h.getEndStatus() & ScriptHandler::END_1BYTE_CHAR) && script_h.getStringBuffer()[ string_buffer_offset ] == ' ') || script_h.getStringBuffer()[ string_buffer_offset ] == '\t' ) string_buffer_offset ++; if (script_h.getStringBuffer()[string_buffer_offset] == 0x00){ processEOT(); return false; } new_line_skip_flag = false; char ch = script_h.getStringBuffer()[string_buffer_offset]; if ( IS_TWO_BYTE(ch) ){ // Shift jis /* ---------------------------------------- */ /* Kinsoku process */ if ( checkLineBreak( script_h.getStringBuffer() + string_buffer_offset, &sentence_font ) ){ sentence_font.newLine(); current_page->add(0x0a); for (int i=0 ; i<indent_offset ; i++){ current_page->add(0x81); current_page->add(0x40); sentence_font.advanceCharInHankaku(2); } } out_text[0] = script_h.getStringBuffer()[string_buffer_offset]; out_text[1] = script_h.getStringBuffer()[string_buffer_offset+1]; if (script_h.checkClickstr(&script_h.getStringBuffer()[string_buffer_offset]) > 0){ if (sentence_font.getRemainingLine() <= clickstr_line) return clickNewPage( out_text ); else return clickWait( out_text ); } else{ clickstr_state = CLICK_NONE; } if ( skip_mode || ctrl_pressed_status ){ drawChar( out_text, &sentence_font, false, true, accumulation_surface, &text_info ); } else{ drawChar( out_text, &sentence_font, true, true, accumulation_surface, &text_info ); event_mode = WAIT_TIMER_MODE | WAIT_INPUT_MODE; if ( sentence_font.wait_time == -1 ) waitEvent( default_text_speed[text_speed_no] ); else waitEvent( sentence_font.wait_time ); } num_chars_in_sentence++; string_buffer_offset += 2; return true; } else if ( ch == '@' ){ // wait for click return clickWait( NULL ); } else if ( ch == '\\' ){ // new page return clickNewPage( NULL ); } else if ( ch == '_' ){ // Ignore an immediate click wait string_buffer_offset++; int matched_len = script_h.checkClickstr(script_h.getStringBuffer() + string_buffer_offset, true); if (matched_len > 0){ out_text[0] = script_h.getStringBuffer()[string_buffer_offset]; if (out_text[0] != '@' && out_text[0] != '\\'){ if (matched_len == 2) out_text[1] = script_h.getStringBuffer()[string_buffer_offset+1]; bool flush_flag = true; if ( skip_mode || ctrl_pressed_status ) flush_flag = false; drawChar( out_text, &sentence_font, flush_flag, true, accumulation_surface, &text_info ); } string_buffer_offset += matched_len; } return true; } else if ( ch == '!' && !(script_h.getEndStatus() & ScriptHandler::END_1BYTE_CHAR) ){ string_buffer_offset++; if ( script_h.getStringBuffer()[ string_buffer_offset ] == 's' ){ string_buffer_offset++; if ( script_h.getStringBuffer()[ string_buffer_offset ] == 'd' ){ sentence_font.wait_time = -1; string_buffer_offset++; } else{ int t = 0; while( script_h.getStringBuffer()[ string_buffer_offset ] >= '0' && script_h.getStringBuffer()[ string_buffer_offset ] <= '9' ){ t = t*10 + script_h.getStringBuffer()[ string_buffer_offset ] - '0'; string_buffer_offset++; } sentence_font.wait_time = t; while (script_h.getStringBuffer()[ string_buffer_offset ] == ' ' || script_h.getStringBuffer()[ string_buffer_offset ] == '\t') string_buffer_offset++; } } else if ( script_h.getStringBuffer()[ string_buffer_offset ] == 'w' || script_h.getStringBuffer()[ string_buffer_offset ] == 'd' ){ bool flag = false; if ( script_h.getStringBuffer()[ string_buffer_offset ] == 'd' ) flag = true; string_buffer_offset++; int t = 0; while( script_h.getStringBuffer()[ string_buffer_offset ] >= '0' && script_h.getStringBuffer()[ string_buffer_offset ] <= '9' ){ t = t*10 + script_h.getStringBuffer()[ string_buffer_offset ] - '0'; string_buffer_offset++; } while (script_h.getStringBuffer()[ string_buffer_offset ] == ' ' || script_h.getStringBuffer()[ string_buffer_offset ] == '\t') string_buffer_offset++; if (!skip_mode && !ctrl_pressed_status){ event_mode = WAIT_TIMER_MODE; if (flag) event_mode |= WAIT_INPUT_MODE; waitEvent(t); } } return true; } else if ( ch == '#' && !(script_h.getEndStatus() & ScriptHandler::END_1BYTE_CHAR) ){ readColor( &sentence_font.color, script_h.getStringBuffer() + string_buffer_offset ); readColor( &ruby_font.color, script_h.getStringBuffer() + string_buffer_offset ); string_buffer_offset += 7; return true; } else if ( ch == '(' && (!english_mode || !(script_h.getEndStatus() & ScriptHandler::END_1BYTE_CHAR)) ){ current_page->add('('); startRuby( script_h.getStringBuffer() + string_buffer_offset + 1, sentence_font ); string_buffer_offset++; return true; } else if ( ch == '/' && !(script_h.getEndStatus() & ScriptHandler::END_1BYTE_CHAR) ){ if ( ruby_struct.stage == RubyStruct::BODY ){ current_page->add('/'); sentence_font.addLineOffset(ruby_struct.margin); string_buffer_offset = ruby_struct.ruby_end - script_h.getStringBuffer(); if (*ruby_struct.ruby_end == ')'){ if ( skip_mode || ctrl_pressed_status ) endRuby(false, true, accumulation_surface, &text_info); else endRuby(true, true, accumulation_surface, &text_info); current_page->add(')'); string_buffer_offset++; } return true; } else{ // skip new line new_line_skip_flag = true; string_buffer_offset++; if (script_h.getStringBuffer()[string_buffer_offset] != 0x00) errorAndExit( "'new line' must follow '/'." ); return true; // skip the following eol } } else if ( ch == ')' && !(script_h.getEndStatus() & ScriptHandler::END_1BYTE_CHAR) && ruby_struct.stage == RubyStruct::BODY ){ current_page->add(')'); string_buffer_offset++; ruby_struct.stage = RubyStruct::NONE; return true; } else if ( ch == '<' && (!english_mode || !(script_h.getEndStatus() & ScriptHandler::END_1BYTE_CHAR)) ){ current_page->add('<'); string_buffer_offset++; int no = 0; while(script_h.getStringBuffer()[string_buffer_offset]>='0' && script_h.getStringBuffer()[string_buffer_offset]<='9'){ current_page->add(script_h.getStringBuffer()[string_buffer_offset]); no=no*10+script_h.getStringBuffer()[string_buffer_offset++]-'0'; } in_textbtn_flag = true; return true; } else if ( ch == '>' && in_textbtn_flag && (!english_mode || !(script_h.getEndStatus() & ScriptHandler::END_1BYTE_CHAR)) ){ current_page->add('>'); string_buffer_offset++; in_textbtn_flag = false; return true; } else{ out_text[0] = ch; int matched_len = script_h.checkClickstr(script_h.getStringBuffer() + string_buffer_offset); if (matched_len > 0){ if (matched_len == 2) out_text[1] = script_h.getStringBuffer()[ string_buffer_offset + 1 ]; if (sentence_font.getRemainingLine() <= clickstr_line) return clickNewPage( out_text ); else return clickWait( out_text ); } else if (script_h.getStringBuffer()[ string_buffer_offset + 1 ] && script_h.checkClickstr(&script_h.getStringBuffer()[string_buffer_offset+1]) == 1 && script_h.getEndStatus() & ScriptHandler::END_1BYTE_CHAR){ if ( script_h.getStringBuffer()[ string_buffer_offset + 2 ] && script_h.checkClickstr(&script_h.getStringBuffer()[string_buffer_offset+2]) > 0){ clickstr_state = CLICK_NONE; } else if (script_h.getStringBuffer()[ string_buffer_offset + 1 ] == '@'){ return clickWait( out_text ); } else if (script_h.getStringBuffer()[ string_buffer_offset + 1 ] == '\\'){ return clickNewPage( out_text ); } else{ out_text[1] = script_h.getStringBuffer()[ string_buffer_offset + 1 ]; if (sentence_font.getRemainingLine() <= clickstr_line) return clickNewPage( out_text ); else return clickWait( out_text ); } } else{ clickstr_state = CLICK_NONE; } bool flush_flag = true; if ( skip_mode || ctrl_pressed_status ) flush_flag = false; if ( script_h.getStringBuffer()[ string_buffer_offset + 1 ] && !(script_h.getEndStatus() & ScriptHandler::END_1BYTE_CHAR)){ out_text[1] = script_h.getStringBuffer()[ string_buffer_offset + 1 ]; drawChar( out_text, &sentence_font, flush_flag, true, accumulation_surface, &text_info ); num_chars_in_sentence++; } else if (script_h.getEndStatus() & ScriptHandler::END_1BYTE_CHAR){ drawChar( out_text, &sentence_font, flush_flag, true, accumulation_surface, &text_info ); num_chars_in_sentence++; } if (!skip_mode && !ctrl_pressed_status){ event_mode = WAIT_TIMER_MODE | WAIT_INPUT_MODE; if ( sentence_font.wait_time == -1 ) waitEvent( default_text_speed[text_speed_no] ); else waitEvent( sentence_font.wait_time ); } if ( script_h.getStringBuffer()[ string_buffer_offset + 1 ] && !(script_h.getEndStatus() & ScriptHandler::END_1BYTE_CHAR)) string_buffer_offset++; string_buffer_offset++; return true; } return false; }
void* launch_graphic(void * client_void){ //Main de test (Bruno) Client* client = (Client*) client_void; Process* process = client->process; pthread_t threadDisplay; ScreenInfo* screenInfo = malloc(sizeof(ScreenInfo)); bool quit = false; if(SDL_Init(SDL_INIT_VIDEO) == -1){ fprintf(stderr, "Erreur initialisation de la vidéo : %s\n", SDL_GetError()); exit(EXIT_FAILURE);// } else{ SDL_Window* window = NULL; //Création d'une fenêtre en pleine écran à la résolution de l'ordinateur window = SDL_CreateWindow("Network Of Swag", SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,WIDTH,HEIGHT, SDL_WINDOW_SHOWN|SDL_WINDOW_RESIZABLE); if(window){ int selectedItem = 0; SDL_Event event; loadBmp(); /*if(client->logo){ //POUR LE TROLL SDL_Surface* yogurt = SDL_LoadBMP("./client/src/graphic/image/projet_reseau_logo.bmp"); SDL_Rect logo = {310, 195, 375, 413}; SDL_BlitSurface(yogurt,NULL,SDL_GetWindowSurface(window), &logo); SDL_UpdateWindowSurface(window); sleep(2); }*/ Player* player = process->player; //Player temporaire pour les test /*block stone, iron; stone.type = STONE; iron.type = IRON; addBlockToInv(player,iron); //Ajout de bloc pour tester la barre d'inventaire addBlockToInv(player,stone); printMap(window,map,27,37,selectedItem,player); //Print de test printPlayer(window, 550, 51); //Only for test SDL_UpdateWindowSurface(window); //Only for test*/ screenInfo->win = window; screenInfo->process = process; screenInfo->selectedItem = &selectedItem; screenInfo->isClosed = &(client->isClosed); pthread_create(&threadDisplay, NULL, displayOnScreen, screenInfo); while(client->isClosed == false){ //Boucle principale quit = waitEvent(event,window,&selectedItem,player,process->map,client->cn); // Gére les évenements if(quit){ client->isClosed = true; } } pthread_join(threadDisplay, NULL); freeBmp(); SDL_DestroyWindow(window); } else{ fprintf(stderr, "Erreur création de la fenêtre : %s\n", SDL_GetError()); exit(-1); } } SDL_Quit(); #ifdef DEBUG printf("Close Graphic\n"); #endif pthread_exit(NULL); }
void demo(MGLDC *dc) { int numpages,aPage,vPage; int sizex,sizey,bits; rect_t fullView,oldView; pixel_format_t pf; palette_t pal[256]; MGLDC *memdc; /* The first way to do simple page flipping is using two display * pages for 'double' buffering. The MGL has functions to set the * system into double buffered modes and flip pages for you, so * this method is very easy. We use MGL_doubleBuffer() to change * to double buffered mode and MGL_swapBuffers() to change display * pages. */ if (!MGL_doubleBuffer(dc)) MGL_fatalError("Double buffereing not available!"); mainWindow(dc,"Page Flip Demo"); statusLine("Method 1: Double buffering with two pages"); MGL_swapBuffers(dc,true); /* Draw to the hidden page */ mainWindow(dc,"Page Flip Demo"); statusLine("Method 1: Double buffering with two pages"); initAnimation(); do { /* Clear the entire display device before drawing the next frame */ MGL_clearViewport(); /* Draw the clock at the current location and move it */ drawClock(); moveClock(); /* Swap the display buffers */ MGL_swapBuffers(dc,true); } while (!checkEvent()); waitEvent(); /* Return to single buffered mode */ MGL_singleBuffer(dc); /* The second way to use page flipping is with multiple display * pages (3+) to do multi-buffering. Because we are using multiple * display pages, we can turn off the wait for retrace flag when we * swap visual pages. In order for triple buffering to work properly, * we need to be doing a complete re-paint of the screen each frame * without doing a screen clear (otherwise you will see flicker). * Games like Quake and Duke3D repaint the entire frame from top to * bottom without any overdraw, which allows them to use triple * buffering techniques like this. We simulate this here by rendering * to a system buffer and blitting to the screen constantly to achieve * a similar effect for this sample program. * * Note that VBE/Core 3.0 and VBE/AF 2.0 include full support for * hardware triple buffering that can be used to eliminate this problem. * When these standards are ratified, the MGL will be updated to support * this and you will be able to do 'real' triple buffering without * any flicker on the screen. */ numpages = MGL_maxPage(dc)+1; if (numpages < 3) return; /* Get the display device size, color depth and pixel format so that we * can create a compatible memory device context. Note that we also * need to copy the palette from the display DC to the memory DC. */ sizex = MGL_sizex(dc); sizey = MGL_sizey(dc); bits = MGL_getBitsPerPixel(dc); MGL_getPixelFormat(dc,&pf); if ((memdc = MGL_createMemoryDC(sizex+1,sizey+1,bits,&pf)) == NULL) MGL_fatalError(MGL_errorMsg(MGL_result())); if (bits == 8) { MGL_getPalette(dc,pal,256,0); MGL_setPalette(memdc,pal,256,0); MGL_realizePalette(memdc,256,0,true); } MGL_makeCurrentDC(memdc); /* Make the fullViewport for the display DC the full screen, as the * above code has changed it to a smaller value. */ fullView.left = 0; fullView.top = 0; fullView.right = sizex+1; fullView.bottom = sizey+1; MGL_setViewportDC(dc,fullView); /* Draw the main window display on the memory buffer */ mainWindow(memdc,"Page Flip Demo"); statusLine("Method 2: Multi-buffering with 3+ pages"); initAnimation(); MGL_setActivePage(dc,aPage = 1); MGL_setVisualPage(dc,vPage = 0,false); MGL_getViewport(&oldView); do { /* Clear the fullViewport before drawing the next frame */ MGL_clearViewport(); /* Draw the clock at the current location and move it */ drawClock(); moveClock(); /* Copy the memory device to the display device */ MGL_setViewport(fullView); MGL_bitBlt(dc,memdc,fullView,0,0,MGL_REPLACE_MODE); MGL_setViewport(oldView); /* Swap the hardware display buffers */ aPage = (aPage+1) % numpages; vPage = (vPage+1) % numpages; MGL_setActivePage(dc,aPage); MGL_setVisualPage(dc,vPage,false); } while (!checkEvent()); waitEvent(); }
bool ONScripter::doEffect( EffectLink *effect, bool clear_dirty_region ) { effect_start_time = SDL_GetTicks(); if ( effect_counter == 0 ) effect_start_time_old = effect_start_time - 1; //printf("effect_counter %d timer between %d %d\n",effect_counter,effect_start_time,effect_start_time_old); effect_timer_resolution = effect_start_time - effect_start_time_old; effect_start_time_old = effect_start_time; int effect_no = effect->effect; if (effect_cut_flag && (skip_mode & SKIP_NORMAL || ctrl_pressed_status)) effect_no = 1; int i, amp; int width, width2; int height, height2; SDL_Rect src_rect = screen_rect, dst_rect = screen_rect; SDL_Rect quake_rect = screen_rect; /* ---------------------------------------- */ /* Execute effect */ //printf("Effect number %d %d\n", effect_no, effect_duration ); bool not_implemented = false; switch ( effect_no ){ case 0: // Instant display case 1: // Instant display //drawEffect( &src_rect, &src_rect, effect_dst_surface ); break; case 2: // Left shutter width = EFFECT_STRIPE_WIDTH * effect_counter / effect_duration; for ( i=0 ; i<screen_width/EFFECT_STRIPE_WIDTH ; i++ ){ src_rect.x = i * EFFECT_STRIPE_WIDTH; src_rect.y = 0; src_rect.w = width; src_rect.h = screen_height; drawEffect(&src_rect, &src_rect, effect_dst_surface); } break; case 3: // Right shutter width = EFFECT_STRIPE_WIDTH * effect_counter / effect_duration; for ( i=1 ; i<=screen_width/EFFECT_STRIPE_WIDTH ; i++ ){ src_rect.x = i * EFFECT_STRIPE_WIDTH - width - 1; src_rect.y = 0; src_rect.w = width; src_rect.h = screen_height; drawEffect(&src_rect, &src_rect, effect_dst_surface); } break; case 4: // Top shutter height = EFFECT_STRIPE_WIDTH * effect_counter / effect_duration; for ( i=0 ; i<screen_height/EFFECT_STRIPE_WIDTH ; i++ ){ src_rect.x = 0; src_rect.y = i * EFFECT_STRIPE_WIDTH; src_rect.w = screen_width; src_rect.h = height; drawEffect(&src_rect, &src_rect, effect_dst_surface); } break; case 5: // Bottom shutter height = EFFECT_STRIPE_WIDTH * effect_counter / effect_duration; for ( i=1 ; i<=screen_height/EFFECT_STRIPE_WIDTH ; i++ ){ src_rect.x = 0; src_rect.y = i * EFFECT_STRIPE_WIDTH - height - 1; src_rect.w = screen_width; src_rect.h = height; drawEffect(&src_rect, &src_rect, effect_dst_surface); } break; case 6: // Left curtain width = EFFECT_STRIPE_CURTAIN_WIDTH * effect_counter * 2 / effect_duration; for ( i=0 ; i<=screen_width/EFFECT_STRIPE_CURTAIN_WIDTH ; i++ ){ width2 = width - EFFECT_STRIPE_CURTAIN_WIDTH * EFFECT_STRIPE_CURTAIN_WIDTH * i / screen_width; if ( width2 >= 0 ){ src_rect.x = i * EFFECT_STRIPE_CURTAIN_WIDTH; src_rect.y = 0; src_rect.w = width2; src_rect.h = screen_height; drawEffect(&src_rect, &src_rect, effect_dst_surface); } } break; case 7: // Right curtain width = EFFECT_STRIPE_CURTAIN_WIDTH * effect_counter * 2 / effect_duration; for ( i=0 ; i<=screen_width/EFFECT_STRIPE_CURTAIN_WIDTH ; i++ ){ width2 = width - EFFECT_STRIPE_CURTAIN_WIDTH * EFFECT_STRIPE_CURTAIN_WIDTH * i / screen_width; if ( width2 >= 0 ){ if ( width2 > EFFECT_STRIPE_CURTAIN_WIDTH ) width2 = EFFECT_STRIPE_CURTAIN_WIDTH; src_rect.x = screen_width - i * EFFECT_STRIPE_CURTAIN_WIDTH - width2; src_rect.y = 0; src_rect.w = width2; src_rect.h = screen_height; drawEffect(&src_rect, &src_rect, effect_dst_surface); } } break; case 8: // Top curtain height = EFFECT_STRIPE_CURTAIN_WIDTH * effect_counter * 2 / effect_duration; for ( i=0 ; i<=screen_height/EFFECT_STRIPE_CURTAIN_WIDTH ; i++ ){ height2 = height - EFFECT_STRIPE_CURTAIN_WIDTH * EFFECT_STRIPE_CURTAIN_WIDTH * i / screen_height; if ( height2 >= 0 ){ src_rect.x = 0; src_rect.y = i * EFFECT_STRIPE_CURTAIN_WIDTH; src_rect.w = screen_width; src_rect.h = height2; drawEffect(&src_rect, &src_rect, effect_dst_surface); } } break; case 9: // Bottom curtain height = EFFECT_STRIPE_CURTAIN_WIDTH * effect_counter * 2 / effect_duration; for ( i=0 ; i<=screen_height/EFFECT_STRIPE_CURTAIN_WIDTH ; i++ ){ height2 = height - EFFECT_STRIPE_CURTAIN_WIDTH * EFFECT_STRIPE_CURTAIN_WIDTH * i / screen_height; if ( height2 >= 0 ){ src_rect.x = 0; src_rect.y = screen_height - i * EFFECT_STRIPE_CURTAIN_WIDTH - height2; src_rect.w = screen_width; src_rect.h = height2; drawEffect(&src_rect, &src_rect, effect_dst_surface); } } break; default: not_implemented = true; case 10: // Cross fade height = 256 * effect_counter / effect_duration; alphaBlend( NULL, ALPHA_BLEND_CONST, height, &dirty_rect.bounding_box ); break; case 11: // Left scroll width = screen_width * effect_counter / effect_duration; src_rect.x = 0; dst_rect.x = width; src_rect.y = dst_rect.y = 0; src_rect.w = dst_rect.w = screen_width - width; src_rect.h = dst_rect.h = screen_height; drawEffect(&dst_rect, &src_rect, effect_src_surface); src_rect.x = screen_width - width - 1; dst_rect.x = 0; src_rect.y = dst_rect.y = 0; src_rect.w = dst_rect.w = width; src_rect.h = dst_rect.h = screen_height; drawEffect(&dst_rect, &src_rect, effect_dst_surface); break; case 12: // Right scroll width = screen_width * effect_counter / effect_duration; src_rect.x = width; dst_rect.x = 0; src_rect.y = dst_rect.y = 0; src_rect.w = dst_rect.w = screen_width - width; src_rect.h = dst_rect.h = screen_height; drawEffect(&dst_rect, &src_rect, effect_src_surface); src_rect.x = 0; dst_rect.x = screen_width - width - 1; src_rect.y = dst_rect.y = 0; src_rect.w = dst_rect.w = width; src_rect.h = dst_rect.h = screen_height; drawEffect(&dst_rect, &src_rect, effect_dst_surface); break; case 13: // Top scroll width = screen_height * effect_counter / effect_duration; src_rect.x = dst_rect.x = 0; src_rect.y = 0; dst_rect.y = width; src_rect.w = dst_rect.w = screen_width; src_rect.h = dst_rect.h = screen_height - width; drawEffect(&dst_rect, &src_rect, effect_src_surface); src_rect.x = dst_rect.x = 0; src_rect.y = screen_height - width - 1; dst_rect.y = 0; src_rect.w = dst_rect.w = screen_width; src_rect.h = dst_rect.h = width; drawEffect(&dst_rect, &src_rect, effect_dst_surface); break; case 14: // Bottom scroll width = screen_height * effect_counter / effect_duration; src_rect.x = dst_rect.x = 0; src_rect.y = width; dst_rect.y = 0; src_rect.w = dst_rect.w = screen_width; src_rect.h = dst_rect.h = screen_height - width; drawEffect(&dst_rect, &src_rect, effect_src_surface); src_rect.x = dst_rect.x = 0; src_rect.y = 0; dst_rect.y = screen_height - width - 1; src_rect.w = dst_rect.w = screen_width; src_rect.h = dst_rect.h = width; drawEffect(&dst_rect, &src_rect, effect_dst_surface); break; case 15: // Fade with mask alphaBlend( effect->anim.image_surface, ALPHA_BLEND_FADE_MASK, 256 * effect_counter / effect_duration, &dirty_rect.bounding_box ); break; case 16: // Mosaic out generateMosaic( effect_src_surface, 5 - 6 * effect_counter / effect_duration ); break; case 17: // Mosaic in generateMosaic( effect_dst_surface, 6 * effect_counter / effect_duration ); break; case 18: // Cross fade with mask alphaBlend( effect->anim.image_surface, ALPHA_BLEND_CROSSFADE_MASK, 256 * effect_counter * 2 / effect_duration, &dirty_rect.bounding_box ); break; case (MAX_EFFECT_NUM + 0): // quakey if ( effect_timer_resolution > effect_duration / 4 / effect->no ) effect_timer_resolution = effect_duration / 4 / effect->no; amp = (Sint16)(sin(M_PI * 2.0 * effect->no * effect_counter / effect_duration) * EFFECT_QUAKE_AMP * effect->no * (effect_duration - effect_counter) / effect_duration); dst_rect.x = 0; dst_rect.y = amp; drawEffect(&dst_rect, &src_rect, effect_dst_surface); if (amp >= 0){ quake_rect.y = 0; quake_rect.h = amp; } else{ quake_rect.y = screen_height + amp; quake_rect.h = -amp; } SDL_FillRect( accumulation_surface, &quake_rect, SDL_MapRGBA( accumulation_surface->format, 0, 0, 0, 0xff ) ); break; case (MAX_EFFECT_NUM + 1): // quakex if ( effect_timer_resolution > effect_duration / 4 / effect->no ) effect_timer_resolution = effect_duration / 4 / effect->no; amp = (Sint16)(sin(M_PI * 2.0 * effect->no * effect_counter / effect_duration) * EFFECT_QUAKE_AMP * effect->no * (effect_duration - effect_counter) / effect_duration); dst_rect.x = amp; dst_rect.y = 0; drawEffect(&dst_rect, &src_rect, effect_dst_surface); if (amp >= 0){ quake_rect.x = 0; quake_rect.w = amp; } else{ quake_rect.x = screen_width + amp; quake_rect.w = -amp; } SDL_FillRect( accumulation_surface, &quake_rect, SDL_MapRGBA( accumulation_surface->format, 0, 0, 0, 0xff ) ); break; case (MAX_EFFECT_NUM + 2): // quake dst_rect.x = effect->no*((int)(3.0*rand()/(RAND_MAX+1.0)) - 1) * 2; dst_rect.y = effect->no*((int)(3.0*rand()/(RAND_MAX+1.0)) - 1) * 2; SDL_FillRect( accumulation_surface, NULL, SDL_MapRGBA( accumulation_surface->format, 0, 0, 0, 0xff ) ); drawEffect(&dst_rect, &src_rect, effect_dst_surface); break; case 99: // dll-based if (effect->anim.image_name != NULL){ if (!strncmp(effect->anim.image_name, "breakup.dll", 11)){ effectBreakup(effect->anim.image_name, effect_duration); } else { // do crossfade height = 256 * effect_counter / effect_duration; alphaBlend( NULL, ALPHA_BLEND_CONST, height, &dirty_rect.bounding_box ); not_implemented = true; } } else { //just in case no dll is given // do crossfade height = 256 * effect_counter / effect_duration; alphaBlend( NULL, ALPHA_BLEND_CONST, height, &dirty_rect.bounding_box ); not_implemented = true; } break; } if (effect_counter == 0 && not_implemented) logw(stderr, "effect No. %d not implemented; substituting crossfade\n", effect_no); //printf("effect conut %d / dur %d\n", effect_counter, effect_duration); effect_counter += effect_timer_resolution; event_mode = WAIT_INPUT_MODE; waitEvent(0); if ( !((automode_flag || autoclick_time > 0) || (usewheel_flag && current_button_state.button == -5) || (!usewheel_flag && current_button_state.button == -2)) ){ effect_counter = effect_duration; // interrupted } if ( effect_counter < effect_duration && effect_no != 1 ){ if ( effect_no != 0 ) flush( REFRESH_NONE_MODE, NULL, false ); return true; } else{ SDL_BlitSurface( effect_dst_surface, &dirty_rect.bounding_box, accumulation_surface, &dirty_rect.bounding_box ); if ( effect_no != 0 ) flush(REFRESH_NONE_MODE, NULL, clear_dirty_region); if ( effect_no == 1 ) effect_counter = 0; skip_mode &= ~SKIP_TO_EOL; event_mode = IDLE_EVENT_MODE; if (effect_blank != 0 && effect_counter != 0) waitEvent(effect_blank); return false; } }
void AsyncCopier::copyHtoD(void* dest, const void* src, size_t size) { VLOG(1) << "copyHtoD " << size; auto pdest = static_cast<uint8_t*>(dest); auto psrc = static_cast<const uint8_t*>(src); unsigned int flags; auto err = cudaHostGetFlags(&flags, const_cast<void*>(src)); if (err == cudaSuccess) { // Page-locked using cudaHostAlloc / cudaHostRegister, copy directly. checkCudaError(cudaMemcpyAsync(dest, src, size, cudaMemcpyHostToDevice), "cudaMemcpyAsync"); return; } else if (err != cudaErrorInvalidValue) { checkCudaError(err, "invalid return code from cudaMemcpyAsync"); } cudaGetLastError(); // reset last error // This is dicey -- what if another kernel has completed with an error? // But there's nothing else we can do, as any cuda function may return an // error from a previous kernel launch. if (size > bufferSize_) { // Copy synchronously. checkCudaError(cudaMemcpy(dest, src, size, cudaMemcpyHostToDevice), "cudaMemcpy"); return; } Event* eventToWait = nullptr; auto copyRange = [this, &size, &pdest, &psrc] (AllocatedBlock& range) { size_t n = std::min(size, range.length); range.length = n; VLOG(1) << "Copy " << range.start << " + " << n; auto bufPtr = buffer_.get() + range.start; memcpy(bufPtr, psrc, n); checkCudaError(cudaMemcpyAsync(pdest, bufPtr, n, cudaMemcpyHostToDevice), "cudaMemcpyAsync"); pdest += n; psrc += n; size -= n; checkCudaError(cudaEventRecord(*range.event->event), "cudaEventRecord"); allocated_.push_back(range); }; for (;;) { { std::lock_guard<std::mutex> lock(mutex_); if (eventToWait) { releaseEventLocked(eventToWait); eventToWait = nullptr; } // Always reap while (!allocated_.empty() && pollEvent(allocated_.front().event)) { releaseEventLocked(allocated_.front().event); allocated_.pop_front(); } auto ranges = getRangesLocked(); if (!ranges.empty()) { auto ev = getEventLocked(); for (auto it = ranges.begin(); size != 0 && it != ranges.end(); ++it) { auto& range = *it; ++ev->refCount; range.event = ev; copyRange(range); } releaseEventLocked(ev); if (size == 0) { break; } } // Sigh, we have to wait. eventToWait = allocated_.front().event; ++eventToWait->refCount; } DCHECK(eventToWait); VLOG(1) << "Waiting, remaining " << size; waitEvent(eventToWait); } VLOG(1) << "End copyHtoD"; DCHECK(!eventToWait); }
void editEvent(SDL_Surface *screen) { BinaryTree *tree = NULL; BinaryTree *tabTree[128] = {0}; int i = 0, j=0; int menuChoice = 0, option = 0; Bool endWhile = FALSE; int val[] = {1,2,3,4,5,6,7,8,9,10}; int tabSize = sizeof(val) / sizeof(int); do { menuChoice = displayMenu(); switch (menuChoice) { case 1: endWhile = FALSE; while (!endWhile) { printf("\nValeur du noeud : "); scanf("%d", &option); if(option < 0) endWhile = TRUE; else { tree = insertNode(option, tree); tabTree[i++] = copyTree(tree); tree = transformBTree(tree); tabTree[i++] = copyTree(tree); } clearScreen(screen); drawTree(screen,tabTree[i - 1],0,height(tree),0,0,1,0); SDL_Flip(screen); } break; case 2: printf("\nValeur du noeud : "); scanf("%d", &option); tree = deleteNode(option, tree); tabTree[i++] = copyTree(tree); tree = transformBTree(tree); tabTree[i++] = copyTree(tree); clearScreen(screen); drawTree(screen,tabTree[i - 1],0,height(tree),0,0,1,0); SDL_Flip(screen); break; case 3: waitEvent(screen, tabTree); break; case 5: i = 0; for(j = 0; j < tabSize; j++) { tree = insertNode(val[j], tree); tabTree[i++] = copyTree(tree); tree = transformBTree(tree); tabTree[i++] = copyTree(tree); } waitEvent(screen, tabTree); break; } } while (menuChoice != 0); }