void kai_fu_act_obj::build_rank_award_info(const int delay, const int mail_id, ilist<kai_fu_act_cfg_obj *> *lp, ilist<int> &char_list) { ilist<give_award_info *> *give_award_list = new ilist<give_award_info *>(); for (ilist_node<kai_fu_act_cfg_obj *> *k_itor = lp->head(); k_itor != NULL; k_itor = k_itor->next_) { ilist_node<int> *c_itor = char_list.head(); for (int n = 1; c_itor != NULL; c_itor = c_itor->next_, ++n) { if (k_itor->value_->open_ && k_itor->value_->param_ == n) { give_award_info *gai = new give_award_info(); give_award_list->push_back(gai); gai->idx_ = n; gai->char_id_ = c_itor->value_; for (ilist_node<item_amount_bind_t> *i_itor = k_itor->value_->award_list_.head(); i_itor != NULL; i_itor = i_itor->next_) gai->award_list_.push_back(i_itor->value_); } } } kai_fu_award_timer *kp = new kai_fu_award_timer(mail_id, give_award_list); sys::r->schedule_timer(kp, time_value(0, delay*1000), time_value(0, 500*1000)); }
virtual int handle_close(const int , reactor_mask m) { if (m == ev_handler::write_mask) { if (this->sock_status_ != _SOCK_SEND_ERROR) return 0; } e_log->rinfo("handle db proxy close h=%d m=%d %s:%d![%s]", this->get_handle(), m, this->host_, this->port_, g_sock_status[this->sock_status_]); this->shutdown_i(); this->recv_buff_->reset(); while (!this->buff_list_.empty()) { mblock *h = this->buff_list_.pop_front(); mblock_pool::instance()->release(h); } this->be_connecting_ = false; this->sock_status_ = _SOCK_INIT; if (this->get_reactor()->schedule_timer(this, time_value(2, 0), time_value(DB_PROXY_HEART_BEAT, 0)) == -1) { e_log->error("schedule timer failed! %s:%d", __FILE__, __LINE__); } return 0; }
void init(reactor *r) { this->connector_.open(r); int ret = r->schedule_timer(this, time_value(0, 600*1000), time_value(0, 600*1000)); assert(ret != -1); }
time_value time_value::operator - (double interval) { if (as_double() >= interval) { return time_value(as_double() - interval); } else { return time_value(); } }
int player::lua_schedule_timer() { if (this->get_reactor()->schedule_timer(this, time_value(0, 0), time_value(0, 33*1000)) == -1) return -1; return 0; }
int open(db_handler *dh, const int port, const char *host) { this->port_ = port; this->dh_ = dh; ::strncpy(this->host_, host, sizeof(this->host_) - 1); s_connector.open(this->get_reactor()); return this->get_reactor()->schedule_timer(this, time_value(0, 0), time_value(DB_PROXY_HEART_BEAT, 0)) == -1 ? -1 : 0; }
time_value& time_value::operator -= (double interval) { if (as_double() >= interval) { *this = time_value(as_double() - interval); } else { *this = time_value(); } return *this; }
virtual int open(void *p) { if (super::open(p) != 0) return -1; this->get_reactor()->register_handler(this, ev_handler::read_mask); this->conn_ok_ = true; int r = rand() % 100; int ret = this->get_reactor()->schedule_timer(this, time_value(0, (300 + r)*1000), time_value(0, (300 + r)*1000)); assert(ret != -1); return this->send_req(); }
player::player(const char *ac, const char *name) : client(8192, "world svc"), scene_player(0, 0), lvl_(0), scene_cid_(0), last_heart_beat_time_(0), att_target_id_(0), last_use_skill_cid_(0), search_att_target_area_radius_(1), diamond_(0), b_diamond_(0), coin_(0), exp_(0), ai_(NULL), social_relation_(NULL), team_info_(NULL) { ::strncpy(this->account_, ac, sizeof(this->account_) - 1); ::strncpy(this->name_, name, sizeof(this->name_) - 1); ++g_curr_payload; this->ai_ = new ai_struct[R_END](); time_value dt = time_value::gettimeofday() + \ time_value(rand() % 10, rand() % 1000 * 1000); for (int i = 0; i < R_END; ++i) { this->ai_[i].param_ = 0; this->ai_[i].done_cnt_ = 0; this->ai_[i].do_time_ = dt; } this->next_patrol_time_ = time_value::gettimeofday(); social_module::init(this); team_module::init(this); }
time_value time_value::get_current_time() { timeval tv; gettimeofday(&tv, NULL); return time_value(tv); }
int player::handle_start_game_result(const char *msg, const int len, const int res) { if (res != 0) { e_log->rinfo("%s:%d start game failed! %d", this->account_, this->id_, res); return -1; } int zhu_wu_cid = 0; int fu_wu_cid = 0; in_stream is(msg, len); stream_istr name_si(this->name_, sizeof(this->name_)); is >> name_si >> this->career_ >> this->lvl_ >> this->exp_ >> this->scene_cid_ >> this->dir_ >> this->x_ >> this->y_ >> zhu_wu_cid >> fu_wu_cid; s_log->rinfo("%s:%d start game ok!%d %d.%d", this->account_, this->id_, this->scene_cid_, this->x_, this->y_); if (this->get_reactor()->schedule_timer(this, time_value(0, 0), time_value(0, 33*1000)) == -1) return -1; this->last_heart_beat_time_ = time_util::now; return this->do_enter_game(); }
time_value progress_timer::elapsed() { time_value curr_time = time_value::get_current_time(); if (begin_ > curr_time) { return time_value(); } time_value retval(curr_time.distance(begin_)); return retval; }
void CDemo::initialize( IDingusAppContext& appContext ) { CONS << "Initializing..." << endl; gAppContext = &appContext; gProbablyInitSettings(); CSharedTextureBundle& stb = CSharedTextureBundle::getInstance(); CSharedSurfaceBundle& ssb = CSharedSurfaceBundle::getInstance(); CD3DDevice& dx = CD3DDevice::getInstance(); CONS << "Video memory seems to be: " << dx.getCaps().getVideoMemoryMB() << endl; G_INPUTCTX->addListener( *this ); // -------------------------------- // shared resources CIndexBufferBundle::getInstance().registerIB( RID_IB_QUADS, 8000*6, D3DFMT_INDEX16, *(new CIBFillerQuads()) ); // -------------------------------- // common params gGlobalCullMode = D3DCULL_CW; G_RENDERCTX->getGlobalParams().addIntRef( "iCull", &gGlobalCullMode ); G_RENDERCTX->getGlobalParams().addFloatRef( "fTime", &gTimeParam ); G_RENDERCTX->getGlobalParams().addVector4Ref( "vFog", gFogParam ); G_RENDERCTX->getGlobalParams().addVector4Ref( "vFogColor", gFogColorParam ); gDebugRenderer = new CDebugRenderer( *G_RENDERCTX, *RGET_FX("debug") ); // -------------------------------- // game CGameInfo::initialize( gServerName, gServerPort, mHwnd ); // GUI gUIDlg = new CUIDialog(); //gUIDlg->enableKeyboardInput( true ); gUIDlg->setCallback( gUICallback ); gUIDlg->setFont( 0, "Tahoma", 12, FW_NORMAL ); gUIDlg->setFont( 1, "Arial", 22, FW_NORMAL ); gUIDlg->setFont( 2, "Tahoma", 12, FW_BOLD ); gUISettingsDlg = new CDemoSettingsDialog( appContext.getD3DEnumeration(), appContext.getD3DSettings() ); gSettingsDlgWasActive = false; gUIHelpDlg = new CDemoHelpDialog(); gHelpDlgWasActive = false; gLastGameUpdateTime = time_value(); CONS << "Starting..." << endl; }
void char_obj::do_update_all_buff(const time_value &now) { if (this->buff_obj_list_.empty()) return ; if (now < this->next_update_buff_time_) return ; this->next_update_buff_time_ = now + time_value(0, 300*1000); int size = this->buff_obj_list_.size(); for (int i = 0; i < size; ++i) { buff_obj *bo = this->buff_obj_list_.pop_front(); if (bo->run(now) != 0) { this->on_remove_buff(bo); this->buff_effect_cnt_[bo->effect_] -= 1; bo->remove(); } else this->buff_obj_list_.push_back(bo); } }
int main (int argc, char *argv[]) { #ifdef FOR_ONEROBOT if (argc != 3) { fprintf(stderr, "%s 192.168.1.221 4001!\n", argv[0]); return -1; } #else if (argc != 5) { fprintf(stderr, "%s 192.168.1.221 4001 payload begin_idx!\n", argv[0]); return -1; } #endif signal(SIGPIPE ,SIG_IGN); signal(SIGINT ,SIG_IGN); set_max_fds(1024); reactor r; if (r.open(10000, 2192) != 0) { fprintf(stderr, "open failed![%s]\n", strerror(errno)); return -1; } if (init_log() != 0) { fprintf(stderr, "init log err.\n"); return -1; } host = argv[1]; port = ::atoi(argv[2]); #ifndef FOR_ONEROBOT g_total_payload = ::atoi(argv[3]); begin_id = ::atoi(argv[4]); #endif srand(time_value::start_time.sec()); time_util::init(); robot_connector.open(&r); #ifndef FOR_ONEROBOT r.schedule_timer(new timer(begin_id), time_value(0, 800*1000), time_value(0, 800*1000)); #endif if (global_param_cfg::instance()->load_config("../config") != 0) { fprintf(stderr, "Error: config - load global_param_cfg config failed!\n"); return -1; } if (scene_config::instance()->load_config("../config") != 0) { fprintf(stderr, "Error: config - load scene config failed!\n"); return -1; } if (buff_config::instance()->load_config("../config") != 0) { fprintf(stderr, "Error: config - load buff config failed!\n"); return -1; } if (skill_config::instance()->load_config("../config") != 0) { fprintf(stderr, "Error: config - load skill config failed!\n"); return -1; } if (item_config::instance()->load_config("../config") != 0) { fprintf(stderr, "Error: config - load item config failed!\n"); return -1; } L = luaL_newstate(); luaL_openlibs(L); #ifdef FOR_LUA tolua_player_open(L); tolua_lua_istream_open(L); if (luaL_loadfile(L, "src/ai_func.lua") || lua_pcall(L, 0, 0, 0)) { fprintf(stderr, "load ai_func lua file failed!\n"); return -1; } if (luaL_loadfile(L, "src/dispatch_msg.lua") || lua_pcall(L, 0, 0, 0)) { fprintf(stderr, "load dispatch_msg lua file failed!\n"); return -1; } #endif s_log->rinfo("=============================begin================="); e_log->rinfo("=============================begin================="); #ifdef FOR_ONEROBOT ::signal(SIGABRT, svc_core_signal); //::signal(SIGSEGV, svc_core_signal); inet_address remote_addr(port, host); time_value tv(30, 0); char ac_bf[32] = {0}; login_ncurses::input_account(ac_bf); if (robot_connector.connect(new player(ac_bf, ""), remote_addr, &tv) != 0) { e_log->rinfo("connect world failed!"); return 0; } #endif r.run_reactor_event_loop(); #ifdef FOR_ONEROBOT director::instance()->exit(); #endif lua_close(L); return 0; }
time_value& time_value::operator += (double interval) { *this = time_value(as_double() + interval); return *this; }
time_value time_value::operator + (double interval) { return time_value(as_double() + interval); }
void time_value::reset() { *this = time_value(); }
bool time_value::empty() const { return (*this == time_value()); }
pwr_tUInt32 bck_WaitBackup ( void *context, pwr_tBoolean timeout) { pwr_tUInt32 sts; pwr_tObjid objid; pwr_tInt32 c; pwr_tTime t; pwr_tVaxTime tmo; pwr_tVaxTime tmptime; pwr_sClass_Backup_Conf *backup_confp; /* Backup_Conf object pointer */ $DESCRIPTOR (timeunitdsc, "0 0:0:0.1"); /* 0.1 second units */ int cycletime; #ifdef OS_ELN pwr_tInt32 res; pwr_tVaxTime *tmop; #endif #ifdef OS_VMS $DESCRIPTOR (efcname, BCK_EFC_NAME); #endif /* * Initialize */ #ifdef OS_ELN if (!areas_mapped) { BCK_MAP_AREAS; areas_mapped = TRUE; } #endif /* * Find the local Backup_Conf object */ sts = gdh_GetClassList (pwr_cClass_Backup_Conf, &objid); while (ODD (sts)) { sts = gdh_ObjidToPointer (objid, (pwr_tAddress *)&backup_confp); if (ODD (sts)) break; sts = gdh_GetNextObject (objid, &objid); } if (EVEN (sts)) return sts; /* Something wrong, quit */ /* * Pick up argument information */ if (context == NULL) time_GetTime(&t); else { t = *(pwr_tTime *)context; free (context); } #ifdef OS_ELN tmop = NULL; #else timed_out = FALSE; sts = sys$ascefc (BCK_EFC, &efcname, 0, 0); if (EVEN (sts)) lib$signal (sts); /* BUG */ #endif if (timeout) { cycletime = backup_confp->CycleSlow * 2; if (cycletime == 0) cycletime = BCK_DEFAULT_SLOW * 2; #ifdef OS_ELN tmo = eln$time_value (&timeunitdsc); #else sts = sys$bintim (&timeunitdsc, &tmo); if (EVEN (sts)) lib$signal (sts); /* BUG, should not happen */ #endif lib$mult_delta_time ( &cycletime, /* multiplier */ &tmo); /* delta_time (modified) */ sys$gettim (&tmptime); lib$add_times (&tmo, &tmptime, &tmo); /* Make absolute time */ #ifdef OS_ELN tmop = &tmo; #else sts = sys$setimr (BCK_WRITE_DONE, &tmo, &astrtn, 4711, 0); if (EVEN (sts)) lib$signal (sts); /* BUG */ #endif } /* * Loop, and wait for things to happen */ while (TRUE) { #ifdef OS_ELN ker$clear_event (NULL, bck_write_done); ker$wait_any (NULL, &res, tmop, bck_write_done); /* Check for timeout */ if (res == 0) return SS$_TIMEOUT; #else sts = sys$clref (BCK_WRITE_DONE); if (EVEN (sts)) lib$signal (sts); /* BUG */ sts = sys$waitfr (BCK_WRITE_DONE); if (EVEN (sts)) lib$signal (sts); /* BUG */ /* Check for timeout */ if (timed_out) return SS$_TIMEOUT; #endif /* Check if both cycles done */ if (time_Acomp(&backup_confp->ObjTimeSlow, &t) < 0) continue; if (time_Acomp(&backup_confp->ObjTimeFast, &t) < 0) continue; break; } /* Loop */ #ifdef OS_VMS sys$cantim (4711, 0); #endif return 1; /* Done. */ } /* bck_WaitBackup */