static inline int neo_interrupt(void) { /* static int fc; int skip_this_frame; */ pd4990a_addretrace(); // printf("neogeo_frame_counter_speed %d\n",neogeo_frame_counter_speed); if (!(irq2control & 0x8)) { if (fc >= neogeo_frame_counter_speed) { fc = 0; neogeo_frame_counter++; } fc++; } skip_this_frame = skip_next_frame; skip_next_frame = frame_skip(0); if (!skip_this_frame) { PROFILER_START(PROF_VIDEO); #ifdef DEBUG_VIDEO draw_screen_scanline(0, 256, 1); #else #ifdef FULL_GL fgl_drawscreen(); #else draw_screen(); #endif #endif PROFILER_STOP(PROF_VIDEO); } return 1; }
bool bucket_waiting_queue::send(int64_t now) { bool empty = true; tbsys::CThreadGuard guard(&mutex); map<uint64_t, packets_queue_type>::iterator it = packets_queue.begin(); for (it = packets_queue.begin(); it != packets_queue.end(); ++it) { packets_queue_type queue = it->second; if (queue.empty()) continue; empty = false; int64_t& last_time = last_send_time[it->first]; if (now - last_time < MISECONDS_BEFOR_SEND_RETRY) { continue; } request_duplicate* packet = new request_duplicate(*queue.front()); log_debug("will send packet pid = %d", packet->packet_id); PROFILER_START("do duplicate"); PROFILER_BEGIN("send duplicate packet"); if (psm->conn_mgr->sendPacket(it->first, packet, NULL, NULL, true) == false) { log_debug("send duplicate packet failed: %s", tbsys::CNetUtil::addrToString(it->first).c_str()); delete packet; } else { log_debug("duplicate packet sent: %s", tbsys::CNetUtil::addrToString(it->first).c_str()); last_time = now; } PROFILER_END(); PROFILER_DUMP(); PROFILER_STOP(); } return !empty; }
void main_frame(void) { uint m68k_overclk = 0; uint z80_overclk = 0; Uint32 cpu_68k_timeslice = (m68k_overclk == 0 ? 200000 : 200000 + (m68k_overclk * 200000 / 100.0)); Uint32 cpu_68k_timeslice_scanline = cpu_68k_timeslice / 264.0; Uint32 cpu_z80_timeslice = (z80_overclk == 0 ? 73333 : 73333 + (z80_overclk * 73333 / 100.0)); Uint32 tm_cycle = 0; Uint32 cpu_z80_timeslice_interlace = cpu_z80_timeslice / (float) nb_interlace; // run one frame { #ifndef ENABLE_940T if (conf.sound) { PROFILER_START(PROF_Z80); for (int i = 0; i < nb_interlace; i++) { cpu_z80_run(cpu_z80_timeslice_interlace); my_timer(); } //cpu_z80_run(cpu_z80_timeslice); PROFILER_STOP(PROF_Z80); } /* else my_timer();*/ #endif #ifdef ENABLE_940T if (conf.sound) { PROFILER_START(PROF_Z80); wait_busy_940(JOB940_RUN_Z80); #if 0 if (gp2x_timer) { gp2x_timer_prev=gp2x_timer; gp2x_timer=gp2x_memregl[0x0A00>>2]; shared_ctl->sample_todo=(unsigned int)(((gp2x_timer-gp2x_timer_prev)*conf.sample_rate)/7372800.0); } else { gp2x_timer=gp2x_memregl[0x0A00>>2]; shared_ctl->sample_todo=sample_len; } #endif gp2x_add_job940(JOB940_RUN_Z80); PROFILER_STOP(PROF_Z80); }
void U2FrameXmlParser::ParseShaders() { U2XmlStream newXmlStream; newXmlStream.SetFilename(m_szFullPath); if(!newXmlStream.Open(U2XmlStream::Read)) { FDebug("Failed to open : %s\n", m_szFullPath.Str()); U2ASSERT(false); } else { newXmlStream.SetToNode(_T("/Frame/Shaders")); } newXmlStream.SetToFirstChild(); do { if(newXmlStream.HasAttr(_T("name")) && newXmlStream.HasAttr(_T("file"))) { PROFILER_DECLARE(prof); PROFILER_START(prof); U2FrameShader *pNewShader = U2_NEW U2FrameShader; #ifdef UNICODE pNewShader->SetName(ToUnicode(newXmlStream.GetString("name"))); pNewShader->SetFilename(ToUnicode(newXmlStream.GetString("file"))); #else pNewShader->SetName(newXmlStream.GetString("name")); pNewShader->SetFilename(newXmlStream.GetString("file")); #endif m_pOwnerFrame->AddShader(pNewShader); //DPrintf("Parsed Shader : %s\n", newXmlStream.GetString("file")); PROFILER_STOP(prof); //FILE_LOG(logINFO) << _T("AddShader: ") << prof.GetTimeInSecs(); } else { break; } } while (newXmlStream.SetToNextChild()); }
void update_sdl_stream(void *userdata, Uint8 * stream, int len) { #ifdef ENABLE_940T static Uint32 play_buffer_pos; #endif PROFILER_START(PROF_SOUND); //streamupdate(len); #ifdef ENABLE_940T if (shared_ctl->buf_pos >= play_buffer_pos && shared_ctl->buf_pos <= play_buffer_pos + len) { //printf("SOUND WARN 1 %d %d\n",shared_ctl->buf_pos,play_buffer_pos); return; } if (shared_ctl->buf_pos + shared_ctl->sample_len >= play_buffer_pos && shared_ctl->buf_pos + shared_ctl->sample_len <= play_buffer_pos + len) { //printf("SOUND WARN 2 %d %d\n",shared_ctl->buf_pos,play_buffer_pos); return; } if ( play_buffer_pos+len>SAMPLE_BUFLEN) { unsigned int last=(SAMPLE_BUFLEN-play_buffer_pos); memcpy(stream, (Uint8 *) shared_ctl->play_buffer+ play_buffer_pos, last); memcpy(stream+last, (Uint8 *) shared_ctl->play_buffer, len-last); //printf("Case 1\n"); play_buffer_pos=len-last; } else { memcpy(stream, (Uint8 *) shared_ctl->play_buffer+play_buffer_pos, len); play_buffer_pos+=len; //printf("Case 2\n"); } #else YM2610Update_stream(len/4); memcpy(stream, (Uint8 *) play_buffer, len); #endif PROFILER_STOP(PROF_SOUND); }
static inline int neo_interrupt(void) { static int frames; pd4990a_addretrace(); // printf("neogeo_frame_counter_speed %d\n",neogeo_frame_counter_speed); if (!(memory.vid.irq2control & 0x8)) { if (fc >= neogeo_frame_counter_speed) { fc = 0; neogeo_frame_counter++; } fc++; } //skip_this_frame = skip_next_frame; //skip_next_frame = frame_skip(0); if (!skip_this_frame) { PROFILER_START(PROF_VIDEO); draw_screen(); PROFILER_STOP(PROF_VIDEO); } /* frames++; printf("FRAME %d\n",frames); if (frames==262) { FILE *f; sleep(1); f=fopen("/tmp/video.dmp","wb"); fwrite(&memory.vid.ram,0x20000,1,f); fclose(f); } */ return 1; }
bool tair_server::handlePacketQueue(tbnet::Packet *apacket, void *args) { base_packet *packet = (base_packet*)apacket; int pcode = packet->getPCode(); bool send_return = true; int ret = TAIR_RETURN_SUCCESS; const char *msg = ""; char buf[100]; sprintf(buf, "pcode is %d, ip is %u", pcode, (uint32_t)(packet->get_connection()->getServerId() & 0xffffffff)); PROFILER_START("process request"); PROFILER_BEGIN(buf); switch (pcode) { case TAIR_REQ_TTL_PACKET: { request_ttl *npacket = (request_ttl *)packet; ret = req_processor->process(npacket, send_return); break; } case TAIR_REQ_TYPE_PACKET: { request_type *npacket = (request_type *)packet; ret = req_processor->process(npacket, send_return); break; } case TAIR_REQ_EXISTS_PACKET: { request_exists *npacket = (request_exists *)packet; ret = req_processor->process(npacket, send_return); break; } case TAIR_REQ_PUT_PACKET: { request_put *npacket = (request_put *)packet; ret = req_processor->process (npacket, send_return); break; } case TAIR_REQ_PUTNX_PACKET: { request_putnx *npacket = (request_putnx *)packet; ret = req_processor->process (npacket, send_return); break; } case TAIR_REQ_GET_PACKET: { request_get *npacket = (request_get *) packet; ret = req_processor->process (npacket, send_return); send_return = false; break; } case TAIR_REQ_GETSET_PACKET: { request_getset *npacket = (request_getset *)packet; ret = req_processor->process(npacket, send_return); break; } case TAIR_REQ_REMOVE_PACKET: { request_remove *npacket = (request_remove *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end remove,prepare to send return packet"); break; } case TAIR_REQ_LINDEX_PACKET: { request_lindex *npacket = (request_lindex *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end lindex, prepare to send return packet"); break; } case TAIR_REQ_LPOP_PACKET: case TAIR_REQ_RPOP_PACKET: { request_lrpop *npacket = (request_lrpop *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end lrpop, prepare to send return packet"); break; } case TAIR_REQ_LPUSH_PACKET: case TAIR_REQ_RPUSH_PACKET: case TAIR_REQ_LPUSHX_PACKET: case TAIR_REQ_RPUSHX_PACKET: { request_lrpush *npacket = (request_lrpush *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end lrpush, prepare to send return packet"); break; } case TAIR_REQ_LPUSH_LIMIT_PACKET: case TAIR_REQ_RPUSH_LIMIT_PACKET: case TAIR_REQ_LPUSHX_LIMIT_PACKET: case TAIR_REQ_RPUSHX_LIMIT_PACKET: { request_lrpush_limit *npacket = (request_lrpush_limit *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end lrpush limit, prepare to send return packet"); break; } case TAIR_REQ_HEXISTS_PACKET: { request_hexists *npacket = (request_hexists *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end hexists, prepare to send return packet"); break; } case TAIR_REQ_HGETALL_PACKET: { request_hgetall *npacket = (request_hgetall *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end hgetall, prepare to send return packet"); break; } case TAIR_REQ_HKEYS_PACKET: { request_hkeys *npacket = (request_hkeys *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end hkeys, prepare to send return packet"); break; } case TAIR_REQ_HINCRBY_PACKET: { request_hincrby *npacket = (request_hincrby *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end hincrby, prepare to send return packet"); break; } case TAIR_REQ_HMSET_PACKET: { request_hmset *npacket = (request_hmset *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end hmset, prepare to send return packet"); break; } case TAIR_REQ_HSET_PACKET: { request_hset *npacket = (request_hset *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end hset, prepare to send return packet"); break; } case TAIR_REQ_HSETNX_PACKET: { request_hsetnx *npacket = (request_hsetnx *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end hsetnx, prepare to send return packet"); break; } case TAIR_REQ_HGET_PACKET: { request_hget *npacket = (request_hget *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end hget, prepare to send return packet"); break; } case TAIR_REQ_HMGET_PACKET: { request_hmget *npacket = (request_hmget *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end hmget, prepare to send return packet"); break; } case TAIR_REQ_HVALS_PACKET: { request_hvals *npacket = (request_hvals *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end hvals, prepare to send return packet"); break; } case TAIR_REQ_HDEL_PACKET: { request_hdel *npacket = (request_hdel *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end hdel, prepare to send return packet"); break; } case TAIR_REQ_HLEN_PACKET: { request_hlen *npacket = (request_hlen *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end llen, prepare to sen return packet"); break; } case TAIR_REQ_LTRIM_PACKET: { request_ltrim *npacket = (request_ltrim *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end ltrim, prepare to send return packet"); break; } case TAIR_REQ_LREM_PACKET: { request_lrem *npacket = (request_lrem *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end lrem, prepare to send return packet"); break; } case TAIR_REQ_LLEN_PACKET: { request_llen *npacket = (request_llen *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end llen, prepare to sen return packet"); break; } case TAIR_REQ_LRANGE_PACKET: { request_lrange *npacket = (request_lrange *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end lrange, prepare to send return packet"); break; } case TAIR_REQ_SCARD_PACKET: { request_scard *npacket = (request_scard *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end scard, prepare to send return packet"); break; } case TAIR_REQ_SMEMBERS_PACKET: { request_smembers *npacket = (request_smembers *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end smembers, prepare to send return packet"); break; } case TAIR_REQ_SADD_PACKET: { request_sadd *npacket = (request_sadd *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end sadd, prepare to send return packet"); break; } case TAIR_REQ_SREM_PACKET: { request_srem *npacket = (request_srem *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end srem, prepare to send return packet"); break; } case TAIR_REQ_SPOP_PACKET: { request_spop *npacket = (request_spop *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end lrpush, prepare to send return packet"); break; } case TAIR_REQ_SADDMULTI_PACKET: { request_sadd_multi *npacket = (request_sadd_multi *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end request sadd multi, prepare to send return packet"); break; } case TAIR_REQ_SREMMULTI_PACKET: { request_srem_multi *npacket = (request_srem_multi *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end request srem multi, prepare to send return packet"); break; } case TAIR_REQ_SMEMBERSMULTI_PACKET: { request_smembers_multi *npacket = (request_smembers_multi *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end request smembers multi, prepare to send retrun packet"); break; } case TAIR_REQ_ZSCORE_PACKET: { request_zscore *npacket = (request_zscore *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end zscore, prepare to send return packet"); break; } case TAIR_REQ_ZRANGE_PACKET: { request_zrange *npacket = (request_zrange *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end zrange, prepare to send return packet"); break; } case TAIR_REQ_ZREVRANGE_PACKET: { request_zrevrange *npacket = (request_zrevrange *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end zrevrange, prepare to send return packet"); break; } case TAIR_REQ_ZRANGEBYSCORE_PACKET: { request_zrangebyscore *npacket = (request_zrangebyscore *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end zrangebyscore, prepare to send return packet"); break; } case TAIR_REQ_GENERIC_ZRANGEBYSCORE_PACKET: { request_generic_zrangebyscore *npacket = (request_generic_zrangebyscore *)packet; ret = req_processor->process (npacket, send_return); log_debug ("end generic zrangebyscore, prepare to send return packet, send_return=%d",send_return); break; } case TAIR_REQ_ZADD_PACKET: { request_zadd *npacket = (request_zadd *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end zadd, prepare to send return packet, send_return=%d", send_return); break; } case TAIR_REQ_ZRANK_PACKET: { request_zrank *npacket = (request_zrank *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end zrank, prepare to send return packet"); break; } case TAIR_REQ_ZREVRANK_PACKET: { request_zrevrank *npacket = (request_zrevrank *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end zrevrank, prepare to send return packet, send_return=%d",send_return); break; } case TAIR_REQ_ZCOUNT_PACKET: { request_zcount *npacket = (request_zcount *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end zcount, prepare to send return packet"); break; } case TAIR_REQ_ZINCRBY_PACKET: { request_zincrby *npacket = (request_zincrby *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end zincrby, prepare to send return packet"); break; } case TAIR_REQ_ZCARD_PACKET: { request_zcard *npacket = (request_zcard *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end zcard, prepare to send return packet"); break; } case TAIR_REQ_ZREM_PACKET: { request_zrem *npacket = (request_zrem *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end zrem, prepare to send return packet"); break; } case TAIR_REQ_ZREMRANGEBYRANK_PACKET: { request_zremrangebyrank *npacket = (request_zremrangebyrank *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end zremrangebyrank, prepare to send return packet"); break; } case TAIR_REQ_ZREMRANGEBYSCORE_PACKET: { request_zremrangebyscore *npacket = (request_zremrangebyscore *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end zremrangebyscore, prepare to send return packet"); break; } case TAIR_REQ_EXPIRE_PACKET: { request_expire *npacket = (request_expire *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end expire, prepare to send return packet"); break; } case TAIR_REQ_EXPIREAT_PACKET: { request_expireat *npacket = (request_expireat *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end expireat, prepare to send return packet"); break; } case TAIR_REQ_PERSIST_PACKET: { request_persist *npacket = (request_persist *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end persist, prepare to send return packet"); break; } case TAIR_REQ_INFO_PACKET: { request_info *npacket = (request_info *) packet; ret = req_processor->process (npacket, send_return); log_debug ("end info, prepare to send return packet"); break; } case TAIR_REQ_LAZY_REMOVE_AREA_PACKET: { request_lazy_remove_area *npacket = (request_lazy_remove_area *)packet; ret = req_processor->process (npacket, send_return); log_debug ("end lazy remove area, prepare to send return packet"); break; } case TAIR_REQ_DUMP_AREA_PACKET: { request_dump_area *npacket = (request_dump_area *)packet; ret = req_processor->process (npacket, send_return); log_debug ("end dump area, prepare to send return packet"); break; } case TAIR_REQ_LOAD_AREA_PACKET: { request_load_area *npacket = (request_load_area *)packet; ret = req_processor->process (npacket, send_return); log_debug ("end dump area, prepare to send return packet"); break; } case TAIR_REQ_ADD_FILTER_PACKET: { request_addfilter *npacket = (request_addfilter *)packet; ret = req_processor->process (npacket, send_return); log_debug ("end add filter area, prepare to send return packet"); break; } case TAIR_REQ_REMOVE_FILTER_PACKET: { request_removefilter *npacket = (request_removefilter *)packet; ret = req_processor->process (npacket, send_return); log_debug ("end add filter area, prepare to send return packet"); break; } case TAIR_REQ_REMOVE_AREA_PACKET: { request_remove_area *npacket = (request_remove_area*)packet; if (npacket->get_direction() == DIRECTION_RECEIVE) { async_task_queue_thread.push(new request_remove_area(*npacket)); } else { if (tair_mgr->clear(npacket->area) == false) { ret = EXIT_FAILURE; } } break; } case TAIR_REQ_PING_PACKET: { ret = ((request_ping*)packet)->value; break; } case TAIR_REQ_DUMP_PACKET: { request_dump *npacket = (request_dump*)packet; if (npacket->get_direction() == DIRECTION_RECEIVE) { async_task_queue_thread.push(new request_dump(*npacket)); } else { tair_mgr->do_dump(npacket->info_set); } break; } case TAIR_REQ_DUMP_BUCKET_PACKET: { ret = EXIT_FAILURE; break; } case TAIR_REQ_INCDEC_PACKET: { request_inc_dec *npacket = (request_inc_dec*)packet; ret = req_processor->process(npacket, send_return); break; } case TAIR_REQ_DUPLICATE_PACKET: { request_duplicate *dpacket = (request_duplicate *)packet; ret = req_processor->process(dpacket, send_return); if (ret == TAIR_RETURN_SUCCESS) send_return = false; break; } case TAIR_REQ_MUPDATE_PACKET: { request_mupdate *mpacket = (request_mupdate *)(packet); ret = req_processor->process(mpacket, send_return); break; } default: { ret = EXIT_FAILURE; log_warn("unknow packet, pcode: %d", pcode); } } PROFILER_END(); PROFILER_DUMP(); PROFILER_STOP(); if (ret == TAIR_RETURN_PROXYED) { // request is proxyed return false; } if (send_return && packet->get_direction() == DIRECTION_RECEIVE) { log_debug("send return packet, return code: %d", ret); tair_packet_factory::set_return_packet(packet, ret, msg, heartbeat.get_client_version()); } if ((TBSYS_LOG_LEVEL_DEBUG<=TBSYS_LOGGER._level)) { int64_t now = tbsys::CTimeUtil::getTime(); if (packet->get_direction() == DIRECTION_RECEIVE && now-packet->request_time>100000LL) { log_warn("Slow, pcode: %d, %ld us", pcode, now-packet->request_time); } } return true; }
bool IMEXIntegrator::integrate(Clock& c) { PROFILER_START("Total"); const real ConvergenceThreshold = 0.0125 * r.numCPs(); const real ConvergenceTolerance = 1.25 * r.numCPs(); bool evalSuccess = false; bool newtonConverge = false; int newtonIterations = 0; while (!evalSuccess) { VecXe Fx = VecXe::Zero(r.numDOF()); VecXe FxEx = VecXe::Zero(r.numDOF()); VecXe dqdot = VecXe::Zero(r.numDOF()); VecXe sol = VecXe::Zero(r.numDOF()); Eigen::SparseMatrix<real> GradFx(r.numDOF(), r.numDOF()); std::vector<Triplet> triplets; // TODO: Figure out a thread-safe way to fill this // TODO: Query energies to figure out a good estimate std::size_t numTriplets = 9*9*r.numIntCPs(); // Calculate Fx contribution from Explicit energies // (these do not change between Newton iterations) for (RodEnergy* e : energies) { if (e->evalType() == Explicit) { evalSuccess = e->eval(&FxEx); CHECK_NAN_VEC(FxEx); if (!evalSuccess) break; } } if (!evalSuccess) continue; // Perform Newton iteration to solve IMEX equations while (!newtonConverge) { triplets.clear(); triplets.reserve(numTriplets); Fx = FxEx; // Find offset for implicit evaluation VecXe offset = c.timestep() * (r.cur().vel + dqdot); // Add up energies for (RodEnergy* e : energies) { if (e->evalType() == Implicit) { evalSuccess = e->eval(&Fx, &triplets, &offset); if (!evalSuccess) break; } } if (!evalSuccess) break; Fx *= -c.timestep(); Fx += r.getMass().sparse * dqdot; CHECK_NAN_VEC(Fx); // Test for convergence real residual = Fx.norm(); if (residual < ConvergenceThreshold) { newtonConverge = true; break; } else if (newtonIterations > 4) { std::cout << "resid: " << residual << "\n"; if (residual < ConvergenceTolerance) { newtonConverge = true; } break; } // Error too high; perform one Newton iteration to update dqdot newtonIterations++; // Create sparse Jacobian of Fx GradFx.setFromTriplets(triplets.begin(), triplets.end()); // sums up duplicates automagically GradFx *= -c.timestep() * c.timestep(); GradFx += r.getMass().sparse; CHECK_NAN_VEC(GradFx.toDense()); PROFILER_START("CG Solver"); Eigen::ConjugateGradient<Eigen::SparseMatrix<real>, Eigen::Upper, Eigen::IncompleteLUT<real>> cg; cg.compute(GradFx); assert(cg.preconditioner().info() == Eigen::ComputationInfo::Success); VecXe guess = sol; sol = cg.solveWithGuess(-Fx, guess); // H(x_n) (x_n+1 - x_n) = -F(x_n) if (cg.info() == Eigen::NoConvergence) { if (c.canDecreaseTimestep()) { PROFILER_STOP("CG Solver"); c.suggestTimestep(c.timestep()/2.0); std::cout << "No convergence in CG solver. New timestep: " << c.timestep() << "\n"; evalSuccess = false; break; } std::cerr << "No convergence!! Newton iterate: " << newtonIterations << "\n"; std::cerr << "Fx has NaN: " << Fx.hasNaN() << "\n"; std::cerr << "GradFx has NaN: " << GradFx.toDense().hasNaN() << "\n"; std::cerr << "Fx max coeff: " << Fx.maxCoeff() << "\n"; std::cerr << "GradFx max coeff: " << GradFx.toDense().maxCoeff() << "\n"; assert(false); } dqdot += sol; PROFILER_STOP("CG Solver"); } // Update rod positions if (newtonConverge) { #ifdef NEWMARK_BETA // Newmark-Beta update const real gamma = 0.5; const real beta = 0.25; r.next().dVel = dqdot; r.next().vel = r.cur().vel + (1.0-gamma) * r.cur().dVel + gamma * dqdot; r.next().pos = r.cur().pos + c.timestep() * (r.cur().vel + ((1.0-2.0*beta) / 2.0) * r.cur().dVel + beta * dqdot); #else // ifdef NEWMARK_BETA // Update changes to position and velocity r.next().vel = r.cur().vel + dqdot; r.next().pos = r.cur().pos + c.timestep() * r.next().vel; #endif // ifdef NEWMARK_BETA } } PROFILER_STOP("Total"); PROFILER_PRINT_ELAPSED(); PROFILER_RESET_ALL(); return newtonConverge; }
void profiler_stop() { PROFILER_STOP(); }
//Trigger the ODE simulation. This method should be called frequently //(call SetTime() before invoking Trigger() to update the current Time). //The method will invoke dWorldStep one or several times, depending //on the Time since the last call, and the step size of the Level. //The method will make sure that the physics simulation is triggered //using a constant step size. void CLevel::Trigger() { PROFILER_START(profFrameBefore); for (int i = 0; i < Entities.Size(); i++) Entities[i]->OnFrameBefore(); PROFILER_STOP(profFrameBefore); PROFILER_RESET(profStepBefore); PROFILER_RESET(profStepAfter); PROFILER_RESET(profCollide); PROFILER_RESET(profStep); PROFILER_RESET(profJointGroupEmpty); #ifdef __NEBULA_STATS__ statsNumNearCallbackCalled = 0; statsNumCollideCalled = 0; statsNumCollided = 0; statsNumSpaceCollideCalled = 0; statsNumSteps = 0; #endif TimeToSim += GameSrv->GetFrameTime(); while (TimeToSim > StepSize) { PROFILER_STARTACCUM(profStepBefore); for (int i = 0; i < Entities.Size(); i++) Entities[i]->OnStepBefore(); PROFILER_STOPACCUM(profStepBefore); // do collision detection PROFILER_STARTACCUM(profCollide); statsNumSpaceCollideCalled++; dSpaceCollide2((dGeomID)ODEDynamicSpaceID, (dGeomID)ODEStaticSpaceID, this, &ODENearCallback); dSpaceCollide(ODEDynamicSpaceID, this, &ODENearCallback); PROFILER_STOPACCUM(profCollide); // step physics simulation PROFILER_STARTACCUM(profStep); dWorldQuickStep(ODEWorldID, dReal(StepSize)); PROFILER_STOPACCUM(profStep); // clear Contact joints PROFILER_STARTACCUM(profJointGroupEmpty); dJointGroupEmpty(ContactJointGroup); PROFILER_STOPACCUM(profJointGroupEmpty); PROFILER_STARTACCUM(profStepAfter); for (int i = 0; i < Entities.Size(); i++) Entities[i]->OnStepAfter(); PROFILER_STOPACCUM(profStepAfter); statsNumSteps++; TimeToSim -= StepSize; } // export statistics #ifdef __NEBULA_STATS__ //nWatched watchSpaceCollideCalled("statsMangaPhysicsSpaceCollideCalled", DATA_TYPE(int)); //nWatched watchNearCallbackCalled("statsMangaPhysicsNearCallbackCalled", DATA_TYPE(int)); //nWatched watchCollideCalled("statsMangaPhysicsCollideCalled", DATA_TYPE(int)); //nWatched watchCollided("statsMangaPhysicsCollided", DATA_TYPE(int)); //nWatched watchSpaces("statsMangaPhysicsSpaces", DATA_TYPE(int)); //nWatched watchShapes("statsMangaPhysicsShapes", DATA_TYPE(int)); //nWatched watchSteps("statsMangaPhysicsSteps", DATA_TYPE(int)); //if (statsNumSteps > 0) //{ // watchSpaceCollideCalled->SetValue(statsNumSpaceCollideCalled/statsNumSteps); // watchNearCallbackCalled->SetValue(statsNumNearCallbackCalled/statsNumSteps); // watchCollideCalled->SetValue(statsNumCollideCalled/statsNumSteps); // watchCollided->SetValue(statsNumCollided/statsNumSteps); //} //watchSpaces->SetValue(statsNumSpaces); //watchShapes->SetValue(statsNumShapes); //watchSteps->SetValue(statsNumSteps); #endif // invoke the "on-frame-after" methods PROFILER_START(profFrameAfter); for (int i = 0; i < Entities.Size(); i++) Entities[i]->OnFrameAfter(); PROFILER_STOP(profFrameAfter); }
//------------------------------------------------------------------------------------------------- bool U2FrameXmlParser::Parse() { TiXmlHandle docHandle(m_pXmlDoc); TiXmlElement* pFrameElem = docHandle.FirstChildElement("Frame").Element(); U2ASSERT(pFrameElem); TiXmlElement* pChild; for(pChild = pFrameElem->FirstChildElement(); pChild; pChild = pChild->NextSiblingElement()) { #ifdef UNICODE if(ToUnicode(pChild->Value()) == U2DynString(_T("Shaders"))) { ParseShaders(); } else if(ToUnicode(pChild->Value()) == U2DynString(_T("RenderTarget"))) { ParseRenderTarget(pChild, m_pOwnerFrame); } else if(ToUnicode(pChild->Value()) == U2DynString(_T("Float"))) { ParseGlobalVariable(U2Variable::Float, pChild, m_pOwnerFrame); } else if(ToUnicode(pChild->Value()) == U2DynString(_T("Float4"))) { ParseGlobalVariable(U2Variable::Vector4, pChild, m_pOwnerFrame); } else if(ToUnicode(pChild->Value()) == U2DynString(_T("Int"))) { ParseGlobalVariable(U2Variable::Int, pChild, m_pOwnerFrame); } else if(ToUnicode(pChild->Value()) == U2DynString(_T("Texture"))) { ParseGlobalVariable(U2Variable::Object, pChild, m_pOwnerFrame); } else if(ToUnicode(pChild->Value()) == U2DynString(_T("RenderTarget"))) { ParseFrameSection(pChild, m_pOwnerFrame); } #else if(pChild->Value() == U2DynString(_T("Shaders"))) { PROFILER_DECLARE(prof); PROFILER_START(prof); ParseShaders(); PROFILER_STOP(prof); //FILE_LOG(logINFO) << _T("ParseShaders: ") << prof.GetTimeInSecs(); } else if(pChild->Value() == U2DynString(_T("RenderTarget"))) { PROFILER_DECLARE(prof); PROFILER_START(prof); ParseRenderTarget(pChild, m_pOwnerFrame); PROFILER_STOP(prof); //FILE_LOG(logINFO) << _T("ParseRenderTarget: ") << prof.GetTimeInSecs(); } else if(pChild->Value() == U2DynString(_T("Float"))) { PROFILER_DECLARE(prof); PROFILER_START(prof); ParseGlobalVariable(U2Variable::Float, pChild, m_pOwnerFrame); PROFILER_STOP(prof); //FILE_LOG(logINFO) << _T("ParseGlobalVariable Float: ") << prof.GetTimeInSecs(); } else if(pChild->Value() == U2DynString(_T("Float4"))) { PROFILER_DECLARE(prof); PROFILER_START(prof); ParseGlobalVariable(U2Variable::Vector4, pChild, m_pOwnerFrame); PROFILER_STOP(prof); //FILE_LOG(logINFO) << _T("ParseGlobalVariable Float4: ") << prof.GetTimeInSecs(); } else if(pChild->Value() == U2DynString(_T("Int"))) { PROFILER_DECLARE(prof); PROFILER_START(prof); ParseGlobalVariable(U2Variable::Int, pChild, m_pOwnerFrame); PROFILER_STOP(prof); //FILE_LOG(logINFO) << _T("ParseGlobalVariable Int: ") << prof.GetTimeInSecs(); } else if(pChild->Value() == U2DynString(_T("Texture"))) { PROFILER_DECLARE(prof); PROFILER_START(prof); ParseGlobalVariable(U2Variable::Object, pChild, m_pOwnerFrame); PROFILER_STOP(prof); //FILE_LOG(logINFO) << _T("ParseGlobalVariable Texture: ") << prof.GetTimeInSecs(); } else if(pChild->Value() == U2DynString(_T("FrameSection"))) { PROFILER_DECLARE(prof); PROFILER_START(prof); // Reset 에러... 2011/09/26 ParseFrameSection(pChild, m_pOwnerFrame); PROFILER_STOP(prof); //FILE_LOG(logINFO) << _T("ParseFrameSection: ") << prof.GetTimeInSecs(); } #endif } return true; }
void main_loop(void) { int neo_emu_done = 0; int overclk=CF_VAL(cf_get_item_by_name("overclock")); Uint32 cpu_68k_timeslice = (overclk==0?200000:200000+(overclk*200000/100.0)); Uint32 cpu_68k_timeslice_scanline = cpu_68k_timeslice/262.0; // Uint32 cpu_z80_timeslice = 100000; Uint32 cpu_z80_timeslice = 73333; Uint32 tm_cycle=0; /* Uint32 cpu_z80_timeslice=66666; // is it 4Mhz or 6Mhz ???? 4 seems to work fine.... UPDATE: it's clear now that it's 6Mhz -> kof96 presentation */ Uint32 cpu_z80_timeslice_interlace = cpu_z80_timeslice / (float) nb_interlace; char ksym_code[5]; SDL_Event event; Uint16 scancode, i, a; char input_buf[20]; Uint8 show_keysym=0; CONF_ITEM* item = cf_get_item_by_name("invertjoy"); int invert_joy = 0; if (item) invert_joy=CF_BOOL(item); reset_frame_skip(); my_timer(); //printf("Cpuspeed: %d\n",cpu_68k_timeslice); /* printf("%s\n",&memory.cpu[0x100]); printf("NGH = %04x\n",READ_WORD(&memory.cpu[0x108])); printf("SSN = %04x\n",READ_WORD(&memory.cpu[0x114])); */ while (!neo_emu_done) { if (conf.test_switch == 1) conf.test_switch = 0; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_JOYAXISMOTION: joy_axe[event.jaxis.which][event.jaxis.axis] = event.jaxis.value; if (show_keysym) { sprintf(ksym_code, "%d", event.jaxis.axis); draw_message(ksym_code); } break; case SDL_JOYHATMOTION: switch (event.jhat.value) { case SDL_HAT_CENTERED: joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 0; joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 0; break; case SDL_HAT_UP: joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = -32767; joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 0; break; case SDL_HAT_DOWN: joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 32767; joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 0; break; case SDL_HAT_LEFT: joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = -32767; joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 0; break; case SDL_HAT_RIGHT: joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 32767; joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 0; break; case SDL_HAT_RIGHTUP: joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 32767; joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = -32767; break; case SDL_HAT_RIGHTDOWN: joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 32767; joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 32767; break; case SDL_HAT_LEFTUP: joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = -32767; joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = -32767; break; case SDL_HAT_LEFTDOWN: joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = -32767; joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 32767; break; } if (show_keysym) { sprintf(ksym_code, "%d", event.jhat.hat); draw_message(ksym_code); } break; case SDL_JOYBUTTONDOWN: joy_button[event.jbutton.which][event.jbutton.button] = 1; if (show_keysym) { sprintf(ksym_code, "%d", event.jbutton.button); draw_message(ksym_code); } break; case SDL_JOYBUTTONUP: joy_button[event.jbutton.which][event.jbutton.button] = 0; break; case SDL_KEYUP: if (player) { switch(event.key.keysym.sym) { case 273: key[264] = 0; break; case 275: key[274] = 0; break; case 274: key[261] = 0; break; case 276: key[260] = 0; break; case 122: key[108] = 0; break; case 120: key[59] = 0; break; case 97: key[111] = 0; break; case 115: key[112] = 0; break; case 49: key[50] = 0; break; case 51: key[52] = 0; break; default: key[event.key.keysym.sym] = 0; break; } } else key[event.key.keysym.sym] = 0; break; case SDL_KEYDOWN: scancode = event.key.keysym.sym; if (show_keysym) { sprintf(ksym_code, "%d", scancode); draw_message(ksym_code); } if (player) { switch(scancode) { case 273: key[264] = 1; break; case 275: key[274] = 1; break; case 274: key[261] = 1; break; case 276: key[260] = 1; break; case 122: key[108] = 1; break; case 120: key[59] = 1; break; case 97: key[111] = 1; break; case 115: key[112] = 1; break; case 49: key[50] = 1; break; case 51: key[52] = 1; break; default: key[scancode] = 1; break; } } else key[scancode] = 1; switch (scancode) { case SDLK_ESCAPE: neo_emu_done = 1; #ifdef __QNXNTO__ shutdown = 1; #endif break; // ESC /* case SDLK_TAB: main_gngeo_gui(); break; */ case SDLK_F1: draw_message("Reset"); //neogeo_init(); cpu_68k_reset(); break; case SDLK_F2: take_screenshot(); draw_message("Screenshot saved"); break; case SDLK_F3: draw_message("Test Switch ON"); conf.test_switch = 1; break; case SDLK_F5: show_fps ^= SDL_TRUE; break; case SDLK_F4: show_keysym = 1 - show_keysym; if (show_keysym) draw_message("Show keysym code : ON"); else draw_message("Show keysym code : OFF"); break; case SDLK_F6: slow_motion = 1 - slow_motion; if (slow_motion) draw_message("SlowMotion : ON"); else { draw_message("SlowMotion : OFF"); reset_frame_skip(); } break; case SDLK_F7: //screen_set_effect("scanline"); if (conf.debug) { dbg_step = 1; } break; case SDLK_F8: { int val; char *endptr; text_input("Save to slot [0-999]? ",16,227,input_buf,3); val=strtol(input_buf,&endptr,10); if (input_buf != endptr) { pending_save_state=val+1; } } break; case SDLK_F9: { int val; char *endptr; text_input("Load from slot [0-999]? ",16,227,input_buf,3); val=strtol(input_buf,&endptr,10); if (input_buf != endptr) { pending_load_state=val+1; } } break; case SDLK_F10: autoframeskip ^= SDL_TRUE; if (autoframeskip) { reset_frame_skip(); draw_message("AutoFrameSkip : ON"); } else draw_message("AutoFrameSkip : OFF"); break; case SDLK_F11: sleep_idle ^= SDL_TRUE; if (sleep_idle) draw_message("Sleep idle : ON"); else draw_message("Sleep idle : OFF"); break; case SDLK_F12: screen_fullscreen(); break; #ifdef __QNXNTO__ case SDLK_F13: neo_emu_done = 1; break; case SDLK_F14: if (player) { key[52] = 0; key[50] = 0; key[112] = 0; key[111] = 0; key[59] = 0; key[108] = 0; key[260] = 0; key[261] = 0; key[274] = 0; key[264] = 0; } player = !player; break; #endif } break; case SDL_VIDEORESIZE: conf.res_x=event.resize.w; conf.res_y=event.resize.h; screen_resize(event.resize.w, event.resize.h); break; case SDL_ACTIVEEVENT: if (event.active.state & SDL_APPINPUTFOCUS) { if (!event.active.gain) { int J; SDL_PauseAudio(1); while (1) { usleep(10000); if (SDL_PollEvent(&event)) { if (event.type == SDL_ACTIVEEVENT) { if (event.active.state & SDL_APPINPUTFOCUS) { if (event.active.gain) break; } } else if (event.type == SDL_QUIT) { neo_emu_done = 1; break; } } } SDL_PauseAudio(0); reset_frame_skip(); } } break; case SDL_USEREVENT: reset_frame_skip(); break; case SDL_QUIT: neo_emu_done = 1; #ifdef __QNXNTO__ shutdown = 1; #endif break; default: break; } } /* update the internal representation of keyslot */ update_p1_key(); update_p2_key(); update_start(); update_coin(); if (slow_motion) SDL_Delay(100); if (conf.sound) { PROFILER_START(PROF_Z80); for (i = 0; i < nb_interlace; i++) { cpu_z80_run(cpu_z80_timeslice_interlace); my_timer(); } PROFILER_STOP(PROF_Z80); } /* else my_timer();*/ if (!conf.debug) { if (conf.raster) { for (i = 0; i < 261; i++) { tm_cycle=cpu_68k_run(cpu_68k_timeslice_scanline-tm_cycle); if (update_scanline()) cpu_68k_interrupt(2); } tm_cycle=cpu_68k_run(cpu_68k_timeslice_scanline-tm_cycle); state_handling(pending_save_state,pending_load_state); update_screen(); cpu_68k_interrupt(1); } else { PROFILER_START(PROF_68K); tm_cycle=cpu_68k_run(cpu_68k_timeslice-tm_cycle); PROFILER_STOP(PROF_68K); a = neo_interrupt(); /* state handling (we save/load before interrupt) */ state_handling(pending_save_state,pending_load_state); if (a) { cpu_68k_interrupt(a); } } } else { /* we arre in debug mode -> we are just here for event handling */ neo_emu_done=1; } #ifdef ENABLE_PROFILER profiler_show_stat(); #endif PROFILER_START(PROF_ALL); } }