bool Paladin::get_attacked(Player& player) { get_damage(player.do_damage()); if(is_dead()) return is_dead(); player.get_damage(do_attack()); return false; }
//恢复当前协程的上下文,立即切换 void resume() { if(is_stoped() || is_dead()) { ORCHID_DEBUG("sche:%lu,coroutine:%lu,resume in coroutine,stop:%s dead:%s", sche_id(),id(),is_stoped()?"true":"false",is_dead()?"true":"false"); return; } // ORCHID_DEBUG("sche:%lu,coroutine:%lu,resume",id(),sche_id()); sche_.resume(this -> shared_from_this()); }
//恢复当前协程的上下文,但是并不是立即切换, //而是将切换的请求在调度器的IO_SERVICE里面排队,等待切换回上次运行的现场 void sche_resume() { if(is_stoped() || is_dead()) { ORCHID_DEBUG("sche:%lu,coroutine:%lu,shce_resume in coroutine,stop:%s dead:%s", sche_id(),id(),is_stoped()?"true":"false",is_dead()?"true":"false"); return; } // ORCHID_DEBUG("sche:%lu,coroutine:%lu,sche_resume",id(),sche_id()); sche_.post(boost::bind(&scheduler_type::resume,&sche_,this->shared_from_this())); }
void trace_process(pid_t pid, char launch) { int status; if (!launch && ptrace(PTRACE_ATTACH, pid, NULL, NULL) == -1) { kill(pid, SIGQUIT); perror("ptrace <PTRACE_ATTACH> failed : "); return ; } while (42) { if (wait4(pid, &status, 0, NULL) == -1) { perror("wait4 failed : "); return ; } if (get_infos_process(pid, status) || is_dead(pid, status)) return ; if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) == -1) { kill(pid, SIGQUIT); perror("ptrace <PTRACE_SINGLESTEP> failed : "); } } }
/* * This routine will turn the ship, slowing down if necessary to * facilitate the turn. (Always returns 1) */ int e_pursue(struct ship *sp, struct ship *fed, float speed) { float bear; float coursediff; bear = bearing(sp->x, fed->x, sp->y, fed->y); /* * do a quick turn if our speed is > max_warp - 2 and * (thus) we are never going to bear on the fed ship * speed = max_warp / 2 is a magic cookie. Feel free to change. */ coursediff = rectify(sp->course - bear); if (coursediff > 180.0) coursediff -= 360.0; if (speed >= sp->max_speed - 2 && fabs(coursediff) > 10) speed = (int)(sp->max_speed / 2); sp->target = fed; sp->newcourse = bear; sp->newwarp = speed; if (speed > 1 && is_dead(sp, S_WARP)) sp->newwarp = 0.99; #ifdef TRACE if (trace) { printf("*** Pursue: Newcourse = %.2f\n", sp->newcourse); printf("*** Pursue: Newwarp = %.2f\n", sp->newwarp); } #endif return 1; }
bool update_game() { int in = get_input(get_map_window()); if(in == INPUT_ACTION && get_last_action() == ACTION_QUIT) return false; else if(in == INPUT_ACTION && (get_last_action() == ACTION_SCROLL_UP || get_last_action() == ACTION_SCROLL_DOWN)) { log_scroll(get_last_action() == ACTION_SCROLL_UP); draw_log(); } else if(!dead) { update_player(); if(get_current_floor() != current_level) { set_current_map(world[get_current_floor()], current_level < get_current_floor(), current_level > get_current_floor()); current_level = get_current_floor(); } update_map(1, world[current_level]); if(is_dead()) { add_message(COLOR_HP_CRIT, "Oh dear, you've died!"); add_message(COLOR_DEFAULT, "Press q to return to the main menu"); dead = true; } if(game_won()) dead = true; draw_log(); } return true; }
int run(t_player *player) { char **map; t_target target; int ret; manage_ressources(LOCK); map = get_map(); manage_ressources(UNLOCK); while (!is_dead(player, map)) { manage_ressources(LOCK); if (player->is_lead && handle_leader(player, map, &target)) break ; else if (!player->is_lead) { if ((ret = handle_followers(player, map, &target)) == 1) break ; else if (ret == 2) continue ; } manage_ressources(UNLOCK); usleep(100000); } shmdt(*map); free(map); return 0; }
void check_spells(GameState * state) { if (state->action == GENERATE_FROST_WAVE && state->mana >= FROST_WAVE_COST && state->spells.spell_duration <= 0) { // frost wave is actief state->mana -= FROST_WAVE_COST; state->action = NONE; state->spells.spell_duration = FROST_WAVE_DURATION; state->spells.frost_wave_active = 1; } else if (state->spells.poison_gas_active || state->action == RELEASE_POISON_GAS) { register int i; if (state->action == RELEASE_POISON_GAS) { state->spells.spell_duration = POISON_GAS_DURATION; state->action = NONE; state->spells.poison_gas_active = 1; } //MAX_MANA wordt nooit bereikt tijdens een poison gas dus dit mag if (state->mana == POISON_GAS_COST) { state->mana -= POISON_GAS_COST; } //damage over time if (state->wave.spawn_counter % FPS == 0) { for (i = 0; i < state->enemies_length;i++) { if (state->enemies[i].enemy.alive) { state->enemies[i].enemy.health -= POISON_DAMAGE * state->wave.wave_number / 2; is_dead(&state->enemies[i].enemy, state); } } } } if (state->spells.spell_duration > 0) { state->spells.spell_duration--; } else { state->spells.frost_wave_active = 0; state ->spells.poison_gas_active = 0; } }
void env_universal_set( const wcstring &name, const wcstring &value, int exportv ) { message_t *msg; if( !init ) return; debug( 3, L"env_universal_set( \"%ls\", \"%ls\" )", name.c_str(), value.c_str() ); if( is_dead() ) { env_universal_common_set( name.c_str(), value.c_str(), exportv ); } else { msg = create_message( exportv?SET_EXPORT:SET, name.c_str(), value.c_str()); if( !msg ) { debug( 1, L"Could not create universal variable message" ); return; } msg->count=1; env_universal_server.unsent->push(msg); env_universal_barrier(); } }
int env_universal_remove( const wchar_t *name ) { int res; message_t *msg; if( !init ) return 1; CHECK( name, 1 ); res = !env_universal_common_get( name ); debug( 3, L"env_universal_remove( \"%ls\" )", name ); if( is_dead() ) { env_universal_common_remove( wcstring(name) ); } else { msg= create_message( ERASE, name, 0); msg->count=1; env_universal_server.unsent->push(msg); env_universal_barrier(); } return res; }
void remove_dead_agents(void) { for(agent_iter iter=agents.begin(); iter != agents.end() ; iter++) { if(is_dead(*iter)) { (*iter)->kill(0); printf("kill %s\n", (*iter)->getName().c_str()); } } int status; pid_t dead_pid; while ((dead_pid = waitpid(-1, &status, WNOHANG))>0) { agent_iter iter = find_if(agents.begin(), agents.end(), bind2nd(pid_equal<Agent*>(), dead_pid)); if(iter != agents.end()) { Agent * deadAgent = *iter; stringstream msg; msg<<deadAgent->getName(); switch(deadAgent->attr.status) { case EATEN: msg<<" has been eaten"; break; default: msg<<" has died"; break; } add_announcement(msg.str().c_str(), deadAgent->get_location(), 25); delete deadAgent; agents.erase(iter); } } }
void lemipc(int ac, char **av) { t_info *info; info = init(ac, av); print_board(info->game, 0); while (is_last(info)) ; while (42) { sem_op(info->semid, -1); print_board(info->game, 1); is_dead(info); if (is_last(info)) shmclear(&info, 1); if (info->lead) find(info); else listen_lead(info); print_board(info->game, 0); sem_op(info->semid, 1); usleep(TIMEOUT); } shmclear(&info, 2); }
int env_universal_remove(const wchar_t *name) { int res; if (!s_env_univeral_inited) return 1; CHECK(name, 1); wcstring name_str = name; res = env_universal_common_get(name_str).missing(); debug(3, L"env_universal_remove( \"%ls\" )", name); if (! synchronizes_via_fishd() || is_dead()) { env_universal_common_remove(name_str); } else { message_t *msg = create_message(ERASE, name, 0); msg->count=1; env_universal_server.unsent.push(msg); env_universal_barrier(); } return res; }
void env_universal_set(const wcstring &name, const wcstring &value, bool exportv) { if (!s_env_univeral_inited) return; debug(3, L"env_universal_set( \"%ls\", \"%ls\" )", name.c_str(), value.c_str()); if (! synchronizes_via_fishd() || is_dead()) { env_universal_common_set(name.c_str(), value.c_str(), exportv); env_universal_barrier(); } else { message_t *msg = create_message(exportv?SET_EXPORT:SET, name.c_str(), value.c_str()); if (!msg) { debug(1, L"Could not create universal variable message"); return; } msg->count=1; env_universal_server.unsent.push(msg); env_universal_barrier(); } }
void mrb_gc_mark(mrb_state *mrb, struct RBasic *obj) { if (obj == 0) return; if (!is_white(obj)) return; gc_assert(!is_dead(mrb, obj)); add_gray_list(mrb, obj); }
void mrb_field_write_barrier(mrb_state *mrb, struct RBasic *obj, struct RBasic *value) { if (!is_black(obj)) return; if (!is_white(value)) return; mrb_assert(!is_dead(mrb, value) && !is_dead(mrb, obj)); mrb_assert(is_generational(mrb) || mrb->gc_state != GC_STATE_NONE); if (is_generational(mrb) || mrb->gc_state == GC_STATE_MARK) { add_gray_list(mrb, value); } else { mrb_assert(mrb->gc_state == GC_STATE_SWEEP); paint_partial_white(mrb, obj); /* for never write barriers */ } }
void test_incremental_gc(void) { mrb_state *mrb = mrb_open(); size_t max = ~0, live = 0, total = 0, freed = 0; RVALUE *free; struct heap_page *page; puts("test_incremental_gc"); mrb_garbage_collect(mrb); gc_assert(mrb->gc_state == GC_STATE_NONE); incremental_gc(mrb, max); gc_assert(mrb->gc_state == GC_STATE_MARK); incremental_gc(mrb, max); gc_assert(mrb->gc_state == GC_STATE_MARK); incremental_gc(mrb, max); gc_assert(mrb->gc_state == GC_STATE_SWEEP); page = mrb->heaps; while (page) { RVALUE *p = page->objects; RVALUE *e = p + MRB_HEAP_PAGE_SIZE; while (p<e) { if (is_black(&p->as.basic)) { live++; } if (is_gray(&p->as.basic) && !is_dead(mrb, &p->as.basic)) { printf("%p\n", &p->as.basic); } p++; } page = page->next; total += MRB_HEAP_PAGE_SIZE; } gc_assert(mrb->gray_list == NULL); incremental_gc(mrb, max); gc_assert(mrb->gc_state == GC_STATE_SWEEP); incremental_gc(mrb, max); gc_assert(mrb->gc_state == GC_STATE_NONE); free = (RVALUE*)mrb->heaps->freelist; while (free) { freed++; free = (RVALUE*)free->as.free.next; } gc_assert(mrb->live == live); gc_assert(mrb->live == total-freed); mrb_close(mrb); }
//放弃运行,切换至调度器的上下文中 //该函数只应该在当前协程的run函数中调用 void yield() { ORCHID_DEBUG("sche:%lu,coroutine:%lu,yield",sche_id(),id()); BOOST_ASSERT(!is_dead()); boost::context::jump_fcontext(&ctx(),sche_.ctx(),0); if(is_stoped()) { //std::cout<<"throw here"<<std::endl; throw stack_unwind_exception(); } }
MRB_API void mrb_field_write_barrier(mrb_state *mrb, struct RBasic *obj, struct RBasic *value) { mrb_gc *gc = &mrb->gc; if (!is_black(obj)) return; if (!is_white(value)) return; mrb_assert(gc->state == MRB_GC_STATE_MARK || (!is_dead(gc, value) && !is_dead(gc, obj))); mrb_assert(is_generational(gc) || gc->state != MRB_GC_STATE_ROOT); if (is_generational(gc) || gc->state == MRB_GC_STATE_MARK) { add_gray_list(mrb, gc, value); } else { mrb_assert(gc->state == MRB_GC_STATE_SWEEP); paint_partial_white(gc, obj); /* for never write barriers */ } }
void mrb_write_barrier(mrb_state *mrb, struct RBasic *obj) { if (!is_black(obj)) return; mrb_assert(!is_dead(mrb, obj)); mrb_assert(is_generational(mrb) || mrb->gc_state != GC_STATE_NONE); paint_gray(obj); obj->gcnext = mrb->atomic_gray_list; mrb->atomic_gray_list = obj; }
/* * This routine has the enemy ship turn its strongest shield towards * the enemy and then accelerate to 2/3 maximum speed. (Always * returns 1) */ int e_runaway(struct ship *sp, struct ship *fed) { double bear; int strong; double strength; double temp; int sign = 1; float course = 0.0; int i; bear = bearing(sp->x, fed->x, sp->y, fed->y); /* * Find the strongest shield */ strong = 0; strength = 0.; for (i=0; i< SHIELDS; i++) { temp = sp->shields[i].eff * sp->shields[i].drain * (i == 0 ? SHIELD1 : 1.); if (temp > strength) { strong = i; strength = temp; } } switch (strong) { case 0: course = bear; sign = -1; break; case 1: course = rectify(bear - 90); sign = 1; break; case 2: course = rectify(bear + 180); sign = 1; break; case 3: course = rectify(bear + 90); sign = 1; break; } sp->target = NULL; sp->newcourse = course; sp->newwarp = 2 / 3 * sp->max_speed * sign; if (sp->newwarp > 1.0 && is_dead(sp, S_WARP)) sp->newwarp = 0.99; if (cansee(sp) && syswork(fed, S_SENSOR)) printf("%s: The %s is retreating.\n", helmsman, sp->name); #ifdef TRACE if (trace) { printf("*** Runaway: Newcourse = %.2f\n", sp->newcourse); printf("*** Runaway: Newwarp = %.2f\n", sp->newwarp); } #endif return 1; }
void mrb_write_barrier(mrb_state *mrb, struct RBasic *obj) { if (!is_black(obj)) return; gc_assert(!is_dead(mrb, obj)); gc_assert(mrb->gc_state != GC_STATE_NONE); paint_gray(obj); obj->gcnext = mrb->variable_gray_list; mrb->variable_gray_list = obj; }
bool OopMapCacheEntry::verify_mask(CellTypeState* vars, CellTypeState* stack, int max_locals, int stack_top) { // Check mask includes map VerifyClosure blk(this); iterate_oop(&blk); if (blk.failed()) return false; // Check if map is generated correctly // (Use ?: operator to make sure all 'true' & 'false' are represented exactly the same so we can use == afterwards) if (TraceOopMapGeneration && Verbose) tty->print("Locals (%d): ", max_locals); for(int i = 0; i < max_locals; i++) { bool v1 = is_oop(i) ? true : false; bool v2 = vars[i].is_reference() ? true : false; assert(v1 == v2, "locals oop mask generation error"); if (TraceOopMapGeneration && Verbose) tty->print("%d", v1 ? 1 : 0); #ifdef ENABLE_ZAP_DEAD_LOCALS bool v3 = is_dead(i) ? true : false; bool v4 = !vars[i].is_live() ? true : false; assert(v3 == v4, "locals live mask generation error"); assert(!(v1 && v3), "dead value marked as oop"); #endif } if (TraceOopMapGeneration && Verbose) { tty->cr(); tty->print("Stack (%d): ", stack_top); } for(int j = 0; j < stack_top; j++) { bool v1 = is_oop(max_locals + j) ? true : false; bool v2 = stack[j].is_reference() ? true : false; assert(v1 == v2, "stack oop mask generation error"); if (TraceOopMapGeneration && Verbose) tty->print("%d", v1 ? 1 : 0); #ifdef ENABLE_ZAP_DEAD_LOCALS bool v3 = is_dead(max_locals + j) ? true : false; bool v4 = !stack[j].is_live() ? true : false; assert(v3 == v4, "stack live mask generation error"); assert(!(v1 && v3), "dead value marked as oop"); #endif } if (TraceOopMapGeneration && Verbose) tty->cr(); return true; }
static WordSet add_or_dealloc_WordVec( WordSetU* wsu, WordVec* wv_new ) { Bool have; WordVec* wv_old; UWord ix_old = -1; tl_assert(wv_new->owner == wsu); have = VG_(lookupFM)( wsu->vec2ix, (Word*)&wv_old, (Word*)&ix_old, (Word)wv_new ); if (have) { tl_assert(wv_old != wv_new); tl_assert(wv_old); tl_assert(wv_old->owner == wsu); tl_assert(ix_old < wsu->ix2vec_used); tl_assert(wsu->ix2vec[ix_old] == wv_old); delete_WV( wv_new ); return (WordSet)ix_old; } else if (wsu->ix2vec_free) { WordSet ws; tl_assert(is_dead(wsu,(WordVec*)wsu->ix2vec_free)); ws = wsu->ix2vec_free - &(wsu->ix2vec[0]); tl_assert(wsu->ix2vec[ws] == NULL || is_dead(wsu,wsu->ix2vec[ws])); wsu->ix2vec_free = (WordVec **) wsu->ix2vec[ws]; wsu->ix2vec[ws] = wv_new; VG_(addToFM)( wsu->vec2ix, (Word)wv_new, ws ); if (HG_DEBUG) VG_(printf)("aodW %s re-use free %d %p\n", wsu->cc, (Int)ws, wv_new ); return ws; } else { ensure_ix2vec_space( wsu ); tl_assert(wsu->ix2vec); tl_assert(wsu->ix2vec_used < wsu->ix2vec_size); wsu->ix2vec[wsu->ix2vec_used] = wv_new; VG_(addToFM)( wsu->vec2ix, (Word)wv_new, (Word)wsu->ix2vec_used ); if (HG_DEBUG) VG_(printf)("aodW %s %d %p\n", wsu->cc, (Int)wsu->ix2vec_used, wv_new ); wsu->ix2vec_used++; tl_assert(wsu->ix2vec_used <= wsu->ix2vec_size); return (WordSet)(wsu->ix2vec_used - 1); } }
void TroopResult::draw_guy(int cx, int cy, int frame) { guy* myguy = NULL; if(after != NULL) myguy = after->myguy; else if(before != NULL) myguy = before; else return; if(!is_dead() && myguy != NULL) show_guy(frame, myguy, cx, cy); }
MRB_API void mrb_write_barrier(mrb_state *mrb, struct RBasic *obj) { mrb_gc *gc = &mrb->gc; if (!is_black(obj)) return; mrb_assert(!is_dead(gc, obj)); mrb_assert(is_generational(gc) || gc->state != MRB_GC_STATE_ROOT); paint_gray(obj); obj->gcnext = gc->atomic_gray_list; gc->atomic_gray_list = obj; }
static size_t incremental_sweep_phase(mrb_state *mrb, size_t limit) { struct heap_page *page = mrb->sweeps; size_t tried_sweep = 0; while (page && (tried_sweep < limit)) { RVALUE *p = page->objects; RVALUE *e = p + MRB_HEAP_PAGE_SIZE; size_t freed = 0; int dead_slot = 1; int full = (page->freelist == NULL); while (p<e) { if (is_dead(mrb, &p->as.basic)) { if (p->as.basic.tt != MRB_TT_FREE) { obj_free(mrb, &p->as.basic); p->as.free.next = page->freelist; page->freelist = (struct RBasic*)p; freed++; } } else { paint_partial_white(mrb, &p->as.basic); /* next gc target */ dead_slot = 0; } p++; } /* free dead slot */ if (dead_slot && freed < MRB_HEAP_PAGE_SIZE) { struct heap_page *next = page->next; unlink_heap_page(mrb, page); unlink_free_heap_page(mrb, page); mrb_free(mrb, page); page = next; } else { if (full && freed > 0) { link_free_heap_page(mrb, page); } page = page->next; } tried_sweep += MRB_HEAP_PAGE_SIZE; mrb->live -= freed; mrb->gc_live_after_mark -= freed; } mrb->sweeps = page; return tried_sweep; }
void InterpreterOopMap::print() { int n = number_of_entries(); tty->print("oop map for "); method()->print_value(); tty->print(" @ %d = [%d] { ", bci(), n); for (int i = 0; i < n; i++) { #ifdef ENABLE_ZAP_DEAD_LOCALS if (is_dead(i)) tty->print("%d+ ", i); else #endif if (is_oop(i)) tty->print("%d ", i); } tty->print_cr("}"); }
// |----------------------------------------------------------------------------| // | KillParticles() | // |----------------------------------------------------------------------------| void ParticleSystem::KillParticles() { DebugLog ("ParticleSystem: KillParticles() called.", DB_LOGIC, 10); // is_dead check for particles struct is_dead { bool operator() (const ParticleType& value) { return value.lifetime>value.maxLife; } }; m_particles.remove_if (is_dead()); return; }
static void os_count_object_type(mrb_state *mrb, struct RBasic *obj, void *data) { struct os_count_struct *obj_count; obj_count = (struct os_count_struct*)data; if (is_dead(mrb, obj)) { obj_count->freed++; } else { obj_count->counts[obj->tt]++; obj_count->total++; } }