void zz::bot::move( ) { _moved = false; #ifdef DEBUG_BOT fprintf( stderr, "(%d,%d) vs (%d,%d) calculating move:\n", _map.player_one().x(), _map.player_one().y(), _map.player_two().x(), _map.player_two().y() ); #endif // determins the basic strategy of minimax vs solomax if( _players_are_connected ) { _players_are_connected = _map.locations_are_connected( _map.player_one( ), _map.player_two( ) ); if( !_players_are_connected ) _depth = 3; // we are gonna switch from minimax to solomax, solomax can't alpha-beta prune, so we need to start low again } set_depth(); // find the best possible hueristic solution to the board using _depth clock_t timer = clock( ); minimax( _depth ); timer = clock( ) - timer; #ifdef DEBUG_BOT fprintf( stderr, " %move: [" ); for( int i = 0; i < _count_moves; ++i ) { fprintf( stderr, "%d", _moves[i] ); if( i != _count_moves - 1) fprintf( stderr, ", " ); } fprintf( stderr, "]\n" ); #endif if( !_moved ) { choose_by_walls(); } }
Sun::Sun(Vector2 opos, SpaceSprite *sprite, int index) : SpaceObject(NULL, opos, 0.0, sprite) { STACKTRACE; layer = LAYER_SHOTS; set_depth(LAYER_EXPLOSIONS); // collide_flag_sameship = 0; // collide_flag_sameship = ALL_LAYERS; // layer = LAYER_CBODIES; // id |= ID_PLANET; id=SUN_ID; // mass = 9999999.0; damage_factor=6; //use remote .ini file game->log_file ("server.ini"); sprite_index = index; gravity_mindist = scale_range(get_config_float("Sun", "GravityMinDist", 0)); gravity_range = scale_range(get_config_float("Sun", "GravityRange", 0)); gravity_power = get_config_float("Sun", "GravityPower", 0); gravity_force = scale_acceleration(get_config_float("Sun", "GravityForce", 0), 0); gravity_whip = get_config_float("Sun", "GravityWhip", 0); }
UmgahCone::UmgahCone(double odist, int odamage, UmgahDrone *oship, SpaceSprite *osprite) : SpaceObject(oship, oship->normal_pos(), 0.0, osprite), dist(odist) { STACKTRACE; layer = LAYER_SHOTS; set_depth(DEPTH_SHIPS - 0.1); id = SPACE_SHOT; damage_factor = 1; damage_type = oship->damage_type; damage = (odamage/1000.0); residual_damage = 1e-5; pos = ship->normal_pos() + (unit_vector(ship->get_angle()) * dist); angle = ship->get_angle(); sprite_index = get_index(angle); collide_flag_sameship = 0; isblockingweapons = false; umgahship = oship; }
EarthlingCruiserMk3Beam::EarthlingCruiserMk3Beam(SpaceLocation *creator, Vector2 rpos, double lrange, double ldamage, double sdamage, int lfcount, SpaceObject *tgt) : SpaceLine(creator, creator->normal_pos(), 0, lrange, 0), frame(0), frame_count(lfcount), lpos(creator), rel_pos(rpos), damage_shots(sdamage) { STACKTRACE; set_depth(DEPTH_EXPLOSIONS); target = tgt; base_length = length; rel_pos.x *= -1; pos = normalize(pos + rotate(rel_pos, -PI/2+lpos->get_angle())); vel = lpos->get_vel(); id |= SPACE_LASER; damage_factor = ldamage; angle = trajectory_angle(target); if (!target->canCollide(this) || !canCollide(target)) state = 0; if (!(lpos && lpos->exists())) { lpos = 0; state = 0; } color = tw_makecol(100+tw_random()%105,100+tw_random()%105,255); got_spark = false; switch_counter = 0; }
KaboMine::KaboMine (Vector2 opos, double oangle, double ov, double oturnrate, double orange, double oarmour, double olifetime, double ohostiletime, double orangeacc, double obasepower, SpaceLocation *ocreator, SpaceSprite *osprite) : SpaceObject(ocreator, ocreator->pos+rotate(opos,oangle-PI/2), oangle, osprite), lifetime(olifetime), hostiletime(ohostiletime), Haze_basepower(obasepower) { layer = LAYER_SPECIAL; set_depth(DEPTH_SPECIAL); spriteindextime = 0; velocity = ov; turn_rate = oturnrate; existtime = 0; collide_flag_anyone = ALL_LAYERS; collide_flag_sameteam = ALL_LAYERS; collide_flag_sameship = 0; isblockingweapons = false; attributes &= ~ATTRIB_STANDARD_INDEX; }
ChmmrZapSat::ChmmrZapSat(double oangle, double orange, int odamage, int oframes, int orechargerate, int ocolor, int oarmour, Ship *oship, SpaceSprite *osprite) : SpaceObject(oship, Vector2(0.0, 0.0), 0.0, osprite), lRange(orange), lDamage(odamage), lFrames(oframes), lRechargeRate(orechargerate), lRecharge(0), lColor(ocolor), armour(oarmour) { STACKTRACE; layer = LAYER_SPECIAL; set_depth(DEPTH_SPECIAL); collide_flag_anyone = ALL_LAYERS &~ bit(LAYER_CBODIES); id |= CHMMR_SPEC; angle = oangle; // x = ship->normal_x() + cos(angle) * 100.0; // y = ship->normal_y() + sin(angle) * 100.0; pos = ship->normal_pos() + unit_vector(angle) * 100.0; if (!(ship && ship->exists())) { ship = 0; state = 0; } isblockingweapons = false; }
MultiDBoWMatcher::WindowVisitor::WindowVisitor (AdjacencyWindow &win, const ReferenceFrameId& init_node, double max_dist, unsigned int max_depth) : m_win(win), m_max_dist(max_dist) { set_root_id(init_node); set_depth(max_depth); set_has_visit(true); set_has_explore_node(true); }
ZRadar::ZRadar(BITMAP *BlankSlate, Presence *target, double Size) { STACKTRACE; Blank=BlankSlate; Painted = create_bitmap_ex(bitmap_color_depth(screen),Blank->w,Blank->h); t=target; size=Size; active=TRUE; set_depth(DEPTH_STARS + 0.1); }
CrossObj(Game *game) : GameObject(game) { type = OBJ_CROSS; set_depth(-2); // Make the spinning crosses Animation *my_animation = new Animation(game->get_resource_manager()); my_animation->generate_from_id(ANIM_CROSS_SPIN); this->set_animation(my_animation); this->set_position(0, 128); }
/* * The command-line arguments to ucblinks are: * * -r specify a root relative to which ./devices and ./dev * are used to create links. * * -e the awk-based ucblinks had a default rule-base and * allowed alternate rule-bases with -e. If the user * specifies a rule-base we run the awk-based ucblinks * and pass all the args to it. * * -d undocumented debug option (like the awk-based version); * print what would be created, fixed, or is already correct. */ int main(int argc, char **argv) { int c; int err = 0; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); progname = argv[0]; /* save program name for error messages */ while ((c = getopt(argc, argv, "r:e:d")) != EOF) { switch (c) { case 'r': rootdir = optarg; break; case 'e': exec_script(argv); /* exec_script doesn't return */ break; case 'd': debug = 1; break; case '?': default: err = 1; break; } } if (err || (optind != argc)) { (void) fprintf(stderr, gettext("usage: %s [ -r rootdir ] " "[ -e rulebase ]\n"), progname); exit(1); } get_major_nums(); set_depth(); get_devices(); get_dev_links(); call_device_rules(); return (0); }
MelnormeDisable::MelnormeDisable(Ship *creator, Ship *oship, SpaceSprite *osprite, int ofcount, int ofsize, int disableFrames) : SpaceObject(creator, oship->normal_pos(), 0.0, osprite), ship(oship), disableframe(0), disableframe_count(disableFrames), frame_step(0), frame_size(ofsize), frame_count(ofcount) { STACKTRACE; collide_flag_anyone = 0; set_depth(DEPTH_EXPLOSIONS); }
// traverse downwards from r setting the depth value of each visited node // depends on all nodes having assigned adjacent->descendent_count values // to know which nodes to visit static void set_depth( Region *r, short depth ) { int i; short child_depth = (short)(depth + 1); r->depth = depth; if( r->adjacent_region_count != 1 ){ // if not a leaf for( i=0; i < r->adjacent_region_count; ++i ){ Region *adjacent = r->adjacent_regions[i]; if( adjacent->descendent_count < r->descendent_count ) set_depth( adjacent, child_depth ); } } }
MultiDBoWMatcher::LandmarkVisitor::LandmarkVisitor( const std::vector<Landmark>& landmarks, const ReferenceFrameId& frame, const Sophus::SE3t& T_wc) : m_landmarks(landmarks), m_T_wc(T_wc) { set_depth(100); set_has_visit(true); set_root_id(frame); m_points.resize(landmarks.size()); size_t idx = 0; for(auto lit = landmarks.begin(); lit != landmarks.end(); ++lit, ++idx) m_open[lit->id().ref_frame_id].push_back(idx); }
TeronDrone::TeronDrone( TeronBuilder *creator, Vector2 opos, double shipAngle, SpaceSprite *osprite ): Ship( creator, opos, shipAngle, osprite ), just_docked( false ), resource( 0 ), docked( NULL ), goal( dock ) { STACKTRACE; set_depth( (double)LAYER_SHIPS + 0.01 ); layer = LAYER_SHIPS; asteroid_value = creator->drone_asteroid_value; crew = creator->drone_crew_max; crew_max = creator->drone_crew_max; batt = creator->drone_batt_max; batt_max = creator->drone_batt_max; recharge_amount = creator->drone_recharge_amount; recharge_rate = creator->drone_recharge_rate; recharge_step = recharge_rate; weapon_drain = creator->drone_weapon_drain; weapon_rate = creator->drone_weapon_rate; weapon_sample = 0; weapon_recharge = 0; weapon_low = FALSE; special_drain = creator->drone_special_drain; special_rate = creator->drone_special_rate; special_sample = 0; special_recharge = 0; special_low = FALSE; hotspot_rate = creator->drone_hotspot_rate; hotspot_frame = 0; turn_rate = creator->drone_turn_rate; turn_step = 0.0; speed_max = creator->drone_speed_max; accel_rate = creator->drone_accel_rate; mass = creator->drone_mass; orig_mass = mass; weaponRange = creator->droneWeaponRange; control = new TeronDroneController( "Teron Drone", Game::channel_none ); control->load( "scp.ini", "Config0" ); game->add( control ); control->temporary = true; control->select_ship( this, "terbi" ); ((ControlWussie*)control)->option_velocity[0][0] = scale_velocity( 999 ); ((ControlWussie*)control)->option_range[0][0] = weaponRange; }
TeronTurret::TeronTurret( TeronBuilder *creator, Vector2 opos, double shipAngle, SpaceSprite *osprite ): Ship( creator, opos, shipAngle, osprite ), dock_counter( 0 ) { STACKTRACE; set_depth( (double)LAYER_SHIPS + 0.01 ); crew = creator->turret_crew_max; crew_max = creator->turret_crew_max; batt = creator->turret_batt_max; batt_max = creator->turret_batt_max; recharge_amount = creator->turret_recharge_amount; recharge_rate = creator->turret_recharge_rate; recharge_step = recharge_rate; weapon_drain = creator->turret_weapon_drain; weapon_rate = creator->turret_weapon_rate; weapon_sample = 0; weapon_recharge = 0; weapon_low = FALSE; special_drain = creator->turret_special_drain; special_rate = creator->turret_special_rate; special_sample = 0; special_recharge = 0; special_low = FALSE; turn_rate = creator->turret_turn_rate; turn_step = 0.0; mass = creator->turret_mass; speed_max = 0.0; weaponRange = creator->turretWeaponRange; weaponVelocity = creator->turretWeaponVelocity; weaponDamage = creator->turretWeaponDamage; weaponArmour = creator->turretWeaponArmour; control = new TeronShipController( "Teron Turret", Game::channel_none ); control->load( "scp.ini", "Config0" ); game->add( control ); control->temporary = true; control->select_ship( this, "terbi" ); ((ControlWussie*)control)->option_velocity[0][0] = weaponVelocity; ((ControlWussie*)control)->option_range[0][0] = weaponRange; docked = 0; }
BasiliskAreaHurt::BasiliskAreaHurt(Vector2 opos, double ov, int onum, int olife, int ocolor) : Presence(), num(onum), lifetime(olife), life_counter(0), color(ocolor) { STACKTRACE; if (onum <= 0) { state = 0; return; } set_depth(DEPTH_EXPLOSIONS); xp = new Vector2[num]; xv = new Vector2[num]; int i; for (i=0; i<num; i++) { xp[i] = opos; xv[i] = ov * (0.5+sqrt(sqrt((random()%1000000001)/1000000000.0))) * unit_vector(PI2 * (random()%1000000)/1000000.0); } }
Hook2::Hook2(SefyNautilus2 *creator, Vector2 orelpos, SpaceSprite *osprite, bool bHit) : SpaceObject(creator, creator->pos+orelpos, creator->angle, osprite) { STACKTRACE; // double specialRange, specialDelay // ; sprite_index = get_index(angle); // velocity of the ejected hook (0.5). ejvel = creator->specialRelVelocity; // this is in ms vel = ship->vel + ejvel * unit_vector(ship->angle); armour = creator->specialArmour; Nnodes = 0; roll_time = 0; exist_time = 0; life_time = creator->specialLifeTime; oscperiod = creator->specialOscFreq; ropestart = 20.0; // minimum pixels length of a rope segment, approx. ropeseglen = creator->specialSegLength; hooktarget = 0; hooklocked = 0; bHitAsteroids = bHit; springconst = creator->specialSprConst; hooksize = 9; // from center to the eye for the rope. layer = LAYER_SHOTS; set_depth(DEPTH_SHOTS); collide_flag_anyone = ALL_LAYERS; collide_flag_sameteam = ALL_LAYERS; collide_flag_sameship = ALL_LAYERS; isblockingweapons = false; }
ShipPart2::ShipPart2(Ship *creator, SpaceSprite *osprite, double oangle, Vector2 orelpos, Vector2 opivot, double omass) : SpaceObject(creator, creator->pos, oangle, osprite), mother(creator) { STACKTRACE; layer = LAYER_SHIPS; set_depth(DEPTH_SHOTS); // angle relative to the mother ship (sprite angle = mother angle + rel. angle) offset_angle = oangle; // the point relative to center of this sprite, rotation is around this point // The pi/2 rotation is needed, since the vectors are declared along y as if angle=0 there, // instead angle=0 along x. pivot_point = rotate(opivot, PI/2); // position of the pivot point relative to mothership central position offset_pos = rotate(orelpos, PI/2); // just here so that you can override this, if needed. ship_rotations = 64; // mass, should be non-zero to allow for collisions; the bigger the mass, the less // it'll "move" out of position due to collisions // mass = omass; mass = ship->mass; // might be better ? // ok, override earlier settings now calc_angle(); calc_pos(mother->pos); collide_flag_anyone = mother->collide_flag_anyone; //collide_flag_anyone = ALL_LAYERS; //collide_flag_anyone = 1<<LAYER_SHIPS - 1<<LAYER_SHOTS; //collide_flag_sameteam = mother->collide_flag_sameteam; collide_flag_sameteam = 0; collide_flag_sameship = 0; hascollided = 0; change_pos = 0; change_vel = 0; }
// Reserve as many buffers as possible for count bytes. size_t pni_write_pipeline_reserve(write_pipeline_t *pl, size_t count) { if (pl->primary->in_use) return 0; // I.e. io->wouldblock if (!pl->depth) set_depth(pl); if (pl->depth == 1) { // always use the primary pl->reserved_count = 1; pl->next_primary_index = 0; return 1; } iocp_t *iocp = pl->iocpd->iocp; confirm_as_writer(pl); size_t wanted = (count / IOCP_WBUFSIZE); if (count % IOCP_WBUFSIZE) wanted++; size_t pending = pl->pending_count; assert(pending < pl->depth); size_t bufs = pn_min(wanted, pl->depth - pending); // Can draw from shared pool or the primary... but share with others. size_t writers = iocp->writer_count; size_t shared_count = (iocp->shared_available_count + writers - 1) / writers; bufs = pn_min(bufs, shared_count + 1); pl->reserved_count = pending + bufs; if (bufs == wanted && pl->reserved_count < (pl->depth / 2) && iocp->shared_available_count > (2 * writers + bufs)) { // No shortage: keep the primary as spare for future use pl->next_primary_index = pl->reserved_count; } else if (bufs == 1) { pl->next_primary_index = pending; } else { // let approx 1/3 drain before replenishing pl->next_primary_index = ((pl->reserved_count + 2) / 3) - 1; if (pl->next_primary_index < pending) pl->next_primary_index = pending; } return bufs; }
strategy iterative_deepening(strategy const & S, unsigned init, unsigned inc, unsigned max) { return [=]() { // NOLINT state s = curr_state(); unsigned ncs = get_num_choice_points(); unsigned d = init; while (true) { flet<unsigned> set_depth(get_config().m_max_depth, d); if (auto r = S()) return r; d += inc; if (d > max) { if (get_config().m_show_failure) display_curr_state(); return none_expr(); } curr_state() = s; shrink_choice_points(ncs); }; }; }
MelnormeShot::MelnormeShot(Vector2 opos, double oangle, double ov, int odamage, double orange, double rangeup, int oarmour, Ship *oship, SpaceSprite *osprite, int ofcount, int ofsize) : Shot(oship, opos, oangle, ov, odamage, orange, oarmour, oship, osprite), v(ov), frame(0), frame_step(0), frame_size(ofsize), frame_count(ofcount), charge_frame(0), charge_phase(0), released(FALSE), RangeUp(rangeup) { STACKTRACE; // vx = ship->get_vx(); // vy = ship->get_vy(); vel = ship->get_vel(); set_depth(DEPTH_SHIPS+0.5); }
ChmmrBeam::ChmmrBeam(Ship *oship, int oframes) : SpaceObject(oship, oship->normal_pos(), oship->get_angle(), meleedata.sparkSprite), frame(0), frame_count(oframes), ship(oship), target(oship->target) { STACKTRACE; set_depth(DEPTH_HOTSPOTS); collide_flag_anyone = 0; if (!(ship && ship->exists())) { state = 0; return; } target = ship->target; if (!(target && target->exists()) || (target->isInvisible())) { state = 0; return; } }
TauDaggerBeam::TauDaggerBeam(SpaceLocation *creator, Vector2 rpos, double lrange, double ldamage, int lfcount, double oangle) : SpaceLine(creator, creator->normal_pos(), oangle, lrange, 0), frame(0), frame_count(lfcount), lpos(creator), rel_pos(rpos) { STACKTRACE; if (ldamage <= 0) collide_flag_anyone = 0; set_depth(DEPTH_SHOTS); base_length = length; rel_pos.x *= -1; pos = normalize(pos + rotate(rel_pos, -PI/2+lpos->get_angle())); vel = lpos->get_vel(); id |= SPACE_LASER; damage_factor = ldamage; int rrr = tw_random()%85; color = tw_makecol(100+rrr,100+rrr+tw_random()%55,205+tw_random()%51); relative_angle = angle - lpos->get_angle(); got_spark = false; }
void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue) { //this function is called when there is a debugger break (bug on script) //or when execution is paused from editor if (!tcp_client->is_connected_to_host()) { ERR_EXPLAIN("Script Debugger failed to connect, but being used anyway."); ERR_FAIL(); } packet_peer_stream->put_var("debug_enter"); packet_peer_stream->put_var(2); packet_peer_stream->put_var(p_can_continue); packet_peer_stream->put_var(p_script->debug_get_error()); skip_profile_frame = true; // to avoid super long frame time for the frame Input::MouseMode mouse_mode = Input::get_singleton()->get_mouse_mode(); if (mouse_mode != Input::MOUSE_MODE_VISIBLE) Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); while (true) { _get_output(); if (packet_peer_stream->get_available_packet_count() > 0) { Variant var; Error err = packet_peer_stream->get_var(var); ERR_CONTINUE(err != OK); ERR_CONTINUE(var.get_type() != Variant::ARRAY); Array cmd = var; ERR_CONTINUE(cmd.size() == 0); ERR_CONTINUE(cmd[0].get_type() != Variant::STRING); String command = cmd[0]; if (command == "get_stack_dump") { packet_peer_stream->put_var("stack_dump"); int slc = p_script->debug_get_stack_level_count(); packet_peer_stream->put_var(slc); for (int i = 0; i < slc; i++) { Dictionary d; d["file"] = p_script->debug_get_stack_level_source(i); d["line"] = p_script->debug_get_stack_level_line(i); d["function"] = p_script->debug_get_stack_level_function(i); //d["id"]=p_script->debug_get_stack_level_ d["id"] = 0; packet_peer_stream->put_var(d); } } else if (command == "get_stack_frame_vars") { cmd.remove(0); ERR_CONTINUE(cmd.size() != 1); int lv = cmd[0]; List<String> members; List<Variant> member_vals; p_script->debug_get_stack_level_members(lv, &members, &member_vals); ERR_CONTINUE(members.size() != member_vals.size()); List<String> locals; List<Variant> local_vals; p_script->debug_get_stack_level_locals(lv, &locals, &local_vals); ERR_CONTINUE(locals.size() != local_vals.size()); packet_peer_stream->put_var("stack_frame_vars"); packet_peer_stream->put_var(2 + locals.size() * 2 + members.size() * 2); { //members packet_peer_stream->put_var(members.size()); List<String>::Element *E = members.front(); List<Variant>::Element *F = member_vals.front(); while (E) { _put_variable(E->get(), F->get()); E = E->next(); F = F->next(); } } { //locals packet_peer_stream->put_var(locals.size()); List<String>::Element *E = locals.front(); List<Variant>::Element *F = local_vals.front(); while (E) { _put_variable(E->get(), F->get()); E = E->next(); F = F->next(); } } } else if (command == "step") { set_depth(-1); set_lines_left(1); break; } else if (command == "next") { set_depth(0); set_lines_left(1); break; } else if (command == "continue") { set_depth(-1); set_lines_left(-1); OS::get_singleton()->move_window_to_foreground(); break; } else if (command == "break") { ERR_PRINT("Got break when already broke!"); break; } else if (command == "request_scene_tree") { if (request_scene_tree) request_scene_tree(request_scene_tree_ud); } else if (command == "request_video_mem") { _send_video_memory(); } else if (command == "inspect_object") { ObjectID id = cmd[1]; _send_object_id(id); } else if (command == "set_object_property") { _set_object_property(cmd[1], cmd[2], cmd[3]); } else if (command == "reload_scripts") { reload_all_scripts = true; } else if (command == "breakpoint") { bool set = cmd[3]; if (set) insert_breakpoint(cmd[2], cmd[1]); else remove_breakpoint(cmd[2], cmd[1]); } else { _parse_live_edit(cmd); } } else { OS::get_singleton()->delay_usec(10000); } } packet_peer_stream->put_var("debug_exit"); packet_peer_stream->put_var(0); if (mouse_mode != Input::MOUSE_MODE_VISIBLE) Input::get_singleton()->set_mouse_mode(mouse_mode); }
static void et_splay (struct et_occ *occ) { struct et_occ *f, *gf, *ggf; int occ_depth, f_depth, gf_depth; #ifdef DEBUG_ET record_path_before (occ); et_check_tree_sanity (occ); #endif while (occ->parent) { occ_depth = occ->depth; f = occ->parent; f_depth = f->depth; gf = f->parent; if (!gf) { set_depth_add (occ, f_depth); occ->min_occ = f->min_occ; occ->min = f->min; if (f->prev == occ) { /* zig */ set_prev (f, occ->next); set_next (occ, f); set_depth_add (f->prev, occ_depth); } else { /* zag */ set_next (f, occ->prev); set_prev (occ, f); set_depth_add (f->next, occ_depth); } set_depth (f, -occ_depth); occ->parent = NULL; et_recomp_min (f); #ifdef DEBUG_ET et_check_tree_sanity (occ); check_path_after (occ); #endif return; } gf_depth = gf->depth; set_depth_add (occ, f_depth + gf_depth); occ->min_occ = gf->min_occ; occ->min = gf->min; ggf = gf->parent; if (gf->prev == f) { if (f->prev == occ) { /* zig zig */ set_prev (gf, f->next); set_prev (f, occ->next); set_next (occ, f); set_next (f, gf); set_depth (f, -occ_depth); set_depth_add (f->prev, occ_depth); set_depth (gf, -f_depth); set_depth_add (gf->prev, f_depth); } else { /* zag zig */ set_prev (gf, occ->next); set_next (f, occ->prev); set_prev (occ, f); set_next (occ, gf); set_depth (f, -occ_depth); set_depth_add (f->next, occ_depth); set_depth (gf, -occ_depth - f_depth); set_depth_add (gf->prev, occ_depth + f_depth); } } else { if (f->prev == occ) { /* zig zag */ set_next (gf, occ->prev); set_prev (f, occ->next); set_prev (occ, gf); set_next (occ, f); set_depth (f, -occ_depth); set_depth_add (f->prev, occ_depth); set_depth (gf, -occ_depth - f_depth); set_depth_add (gf->next, occ_depth + f_depth); } else { /* zag zag */ set_next (gf, f->prev); set_next (f, occ->prev); set_prev (occ, f); set_prev (f, gf); set_depth (f, -occ_depth); set_depth_add (f->next, occ_depth); set_depth (gf, -f_depth); set_depth_add (gf->next, f_depth); } } occ->parent = ggf; if (ggf) { if (ggf->prev == gf) ggf->prev = occ; else ggf->next = occ; } et_recomp_min (gf); et_recomp_min (f); #ifdef DEBUG_ET et_check_tree_sanity (occ); #endif } #ifdef DEBUG_ET et_check_sanity (occ); check_path_after (occ); #endif }
KaboHaze::KaboHaze(SpaceLocation *creator, Ship *ohost, double obasepower) : SpaceLocation(creator, Vector2(0.0, 0.0), 0.0) { STACKTRACE; prev = 0; next = 0; // update the list (insert at the start) if (KaboHazeFirst) KaboHazeFirst->prev = this; next = KaboHazeFirst; prev = 0; KaboHazeFirst = this; //mother = omother; host = ohost; basepower = obasepower; power = basepower; // decay_time = odecaytime; // in milliseconds newcrew = iround(host->getCrew()); oldcrew = newcrew; // this "haze" is passive, of course: collide_flag_anyone = 0; collide_flag_sameteam = 0; collide_flag_sameship = 0; // I'll make 64 rotated versions in total, if needed, which I'll store // in memory: for ( int i = 0; i < 64; ++i ) { shield_bmp[i] = 0; } sprite_index = 0; // no rotation. shield_sprite_index = 0; // this item cannot collide collide_flag_anyone = 0; // this is probably important ... otherwise a thing like a flipping wedge indicator // can avoid a shield from being drawn ?!?! layer = LAYER_SHIPS; set_depth(DEPTH_SHIPS + 0.1); // The +0.1 places this presence at a higher level, so that this routine is // always done after the ship was drawn! Thnx Orz, for telling. // Graphics init stuff for the shield ! // copy the ship sprite (yes, a COPY because we need to do some operations on it !) SpaceSprite *ship_spr; ship_spr = host->get_sprite(); if (!ship_spr) { state = 0; return; } //BITMAP *ship_bmp; int wship = ship_spr->width(); int hship = ship_spr->height(); BITMAP *ship_bmp = create_bitmap(wship, hship); clear_to_color(ship_bmp, 0); // important otherwise it contains artefacts int index = 0; ship_spr->draw(Vector2(0, 0), Vector2(wship, hship), index, ship_bmp); // this does a (masked?) blit // create a blurred image from this: int R = 3; blit_blur(ship_bmp, R); // a complex and costly funtion ! Inefficiently programmed as well of course (by me). // now, create a masked shield - only the area that covers the // blurred image of the ship: shield_bmp[sprite_index] = create_bitmap(wship, hship); // important otherwise it contains artefacts clear_to_color(shield_bmp[sprite_index], 0); // scale/draw a shield: /* // the raw shield image BITMAP *raw_bmp = this->sprite->get_bitmap_readonly(0); int wraw = raw_bmp->w; int hraw = raw_bmp->h; stretch_blit(raw_bmp, shield_bmp[sprite_index], 0, 0, wraw, hraw, 0, 0, wship, hship ); */ // a uniform green glow clear_to_color(shield_bmp[sprite_index], tw_makecol(0,255,0)); // mask out the areas outside the ship, so that the shield only covers // the ship. blit_singlecolor(ship_bmp, shield_bmp[sprite_index], tw_makecol(0,0,0)); destroy_bitmap(ship_bmp); // ok ! this is what we need - only things left are // resize // rotate // trans-draw. // which we've to do repeatedly. // we may also cache the rotated images ! // flashes can occur within the edges of the shield ... check where the // edges are !! (assuming here, it's a closed shape). edge_left = new int [hship]; edge_right = new int [hship]; for ( int j = 0; j < hship; ++j ) { edge_left[j] = -1; edge_right[j] = -1; for ( int i = 0; i < wship; ++i ) { int color = getpixel(shield_bmp[0], i, j); if ( color != 0 ) { if ( edge_left[j] == -1 ) edge_left[j] = i; edge_right[j] = i; } } } attributes &= ~ATTRIB_STANDARD_INDEX; }
void pop(){g_assert(_depth>0);set_depth(get_depth()-1);}
static void compute_fiducial_statistics( FidtrackerX *ft, FiducialX *f, Region *r, int width, int height ) { double all_x = 0.; double all_y = 0.; double black_x = 0.; double black_y = 0.; double all_x_warped = 0.; double all_y_warped = 0.; double black_x_warped = 0.; double black_y_warped = 0.; char *depth_string; ft->black_x_sum = 0.; ft->black_y_sum = 0.; ft->black_leaf_count = 0.; ft->white_x_sum = 0.; ft->white_y_sum = 0.; ft->white_leaf_count = 0.; ft->black_x_sum_warped = 0.; ft->black_y_sum_warped = 0.; ft->black_leaf_count_warped = 0.; ft->white_x_sum_warped = 0.; ft->white_y_sum_warped = 0.; ft->white_leaf_count_warped = 0.; ft->total_leaf_count = 0; ft->total_leaf_size = 0.; ft->average_leaf_size = 0.; // ft->min_leaf_width_or_height = 0x7FFFFFFF; set_depth( r, 0 ); sum_leaf_centers( ft, r, width, height ); if(ft->total_leaf_count<1 || ft->black_leaf_count<1 || ft->white_leaf_count<1) { //fprintf(stderr, "did not find any leafs (%d)!", ft->total_leaf_count); r->flags |= LOST_SYMBOL_FLAG; f->id = INVALID_FIDUCIAL_ID; return; } ft->average_leaf_size = ft->total_leaf_size / (double)(ft->total_leaf_count); all_x = (double)(ft->black_x_sum + ft->white_x_sum) / (double)(ft->black_leaf_count + ft->white_leaf_count); all_y = (double)(ft->black_y_sum + ft->white_y_sum) / (double)(ft->black_leaf_count + ft->white_leaf_count); black_x = (double)ft->black_x_sum / (double)ft->black_leaf_count; black_y = (double)ft->black_y_sum / (double)ft->black_leaf_count; if (ft->pixelwarp) { if (ft->total_leaf_count>(ft->black_leaf_count_warped+ft->white_leaf_count_warped)) { int pixel = width*(int)all_y+(int)all_x; if ((pixel>=0) && (pixel<width*height)) { all_x_warped = ft->pixelwarp[pixel].x; all_y_warped = ft->pixelwarp[pixel].y; if ((all_x_warped>0) || (all_y_warped>0)) { pixel = (int)black_y*width+(int)black_x; if ((pixel>=0) && (pixel<width*height)) { black_x_warped = ft->pixelwarp[pixel].x; black_y_warped = ft->pixelwarp[pixel].y; if ((black_x_warped>0) || (black_y_warped>0)) { f->angle = calculate_angle( all_x_warped - black_x_warped, all_y_warped - black_y_warped ); } else f->angle = 0.0f; } else f->angle = 0.0f; f->x = all_x_warped; f->y = all_y_warped; } else { f->x = 0.0f; f->y = 0.0f; f->angle = 0.0f; r->flags |= LOST_SYMBOL_FLAG; } } else r->flags |= LOST_SYMBOL_FLAG; } else { all_x_warped = (double)(ft->black_x_sum_warped + ft->white_x_sum_warped) / (double)(ft->black_leaf_count_warped + ft->white_leaf_count_warped); all_y_warped = (double)(ft->black_y_sum_warped + ft->white_y_sum_warped) / (double)(ft->black_leaf_count_warped + ft->white_leaf_count_warped); black_x_warped = (double)ft->black_x_sum_warped / (double)ft->black_leaf_count_warped; black_y_warped = (double)ft->black_y_sum_warped / (double)ft->black_leaf_count_warped; f->x = all_x_warped; f->y = all_y_warped; f->angle = calculate_angle( all_x_warped - black_x_warped, all_y_warped - black_y_warped ); } } else { f->x = all_x; f->y = all_y; f->angle = calculate_angle( all_x - black_x, all_y - black_y ); } //f->a = black_x; //f->b = black_y; f->leaf_size = (float)(ft->average_leaf_size); f->root_size = r->right-r->left; if ((r->bottom-r->top)>f->root_size) f->root_size = r->bottom-r->top; f->root_colour=r->colour; f->node_count=r->descendent_count; /* print_unordered_depth_string( r ); printf( "\n" ); fflush( stdout ); */ /* // can differ due to fuzzy fiducial tracking assert( r->depth == 0 ); assert( r->descendent_count >= ft->min_target_root_descendent_count ); assert( r->descendent_count <= ft->max_target_root_descendent_count ); */ if (r->flags & LOST_SYMBOL_FLAG) f->id = INVALID_FIDUCIAL_ID; else { ft->next_depth_string = 0; depth_string = build_left_heavy_depth_string( ft, r ); ft->temp_coloured_depth_string[0] = (char)( r->colour ? 'w' : 'b' ); ft->temp_coloured_depth_string[1] = '\0'; strcat( ft->temp_coloured_depth_string, depth_string ); f->id = treestring_to_id( ft->treeidmap, ft->temp_coloured_depth_string ); /*if (f->id != INVALID_FIDUCIAL_ID) { if (!(check_leaf_variation(ft, r, width, height))) { f->id = INVALID_FIDUCIAL_ID; printf("filtered %f\n",ft->average_leaf_size); } }*/ } }
static void compute_fiducial_statistics( FidtrackerX *ft, FiducialX *f, Region *r, int width, int height ) { double all_x, all_y; double black_x, black_y; char *depth_string; ft->black_x_sum = 0.; ft->black_y_sum = 0.; ft->black_leaf_count = 0.; ft->white_x_sum = 0.; ft->white_y_sum = 0.; ft->white_leaf_count = 0.; ft->total_leaf_count = 0; ft->total_leaf_size = 0.; ft->average_leaf_size = 0.; // ft->min_leaf_width_or_height = 0x7FFFFFFF; set_depth( r, 0 ); sum_leaf_centers( ft, r, width, height ); ft->average_leaf_size = ft->total_leaf_size / (double)(ft->total_leaf_count); all_x = (double)(ft->black_x_sum + ft->white_x_sum) / (double)(ft->black_leaf_count + ft->white_leaf_count); all_y = (double)(ft->black_y_sum + ft->white_y_sum) / (double)(ft->black_leaf_count + ft->white_leaf_count); black_x = (double)ft->black_x_sum / (double)ft->black_leaf_count; black_y = (double)ft->black_y_sum / (double)ft->black_leaf_count; f->x = all_x; f->y = all_y; f->angle = (M_PI * 2) - calculate_angle( all_x - black_x, all_y - black_y ); f->leaf_size = (float)(ft->average_leaf_size); f->root_size = ((r->right-r->left)+(r->bottom-r->top))/2; /* print_unordered_depth_string( r ); printf( "\n" ); fflush( stdout ); */ /* // can differ due to fuzzy fiducial tracking assert( r->depth == 0 ); assert( r->descendent_count >= ft->min_target_root_descendent_count ); assert( r->descendent_count <= ft->max_target_root_descendent_count ); */ if(r->flags & LOST_SYMBOL_FLAG) f->id = INVALID_FIDUCIAL_ID; else { ft->next_depth_string = 0; depth_string = build_left_heavy_depth_string( ft, r ); ft->temp_coloured_depth_string[0] = (char)( r->colour ? 'w' : 'b' ); ft->temp_coloured_depth_string[1] = '\0'; strcat( ft->temp_coloured_depth_string, depth_string ); f->id = treestring_to_id( ft->treeidmap, ft->temp_coloured_depth_string ); /*if (f->id != INVALID_FIDUCIAL_ID) { if (!(check_leaf_variation(ft, r, width, height))) { f->id = INVALID_FIDUCIAL_ID; printf("filtered %f\n",ft->average_leaf_size); } }*/ } }
void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue) { print_line("Debugger Break, Reason: '" + p_script->debug_get_error() + "'"); print_line("*Frame " + itos(0) + " - " + p_script->debug_get_stack_level_source(0) + ":" + itos(p_script->debug_get_stack_level_line(0)) + " in function '" + p_script->debug_get_stack_level_function(0) + "'"); print_line("Enter \"help\" for assistance."); int current_frame = 0; int total_frames = p_script->debug_get_stack_level_count(); while (true) { OS::get_singleton()->print("debug> "); String line = OS::get_singleton()->get_stdin_string().strip_edges(); if (line == "") { print_line("Debugger Break, Reason: '" + p_script->debug_get_error() + "'"); print_line("*Frame " + itos(current_frame) + " - " + p_script->debug_get_stack_level_source(current_frame) + ":" + itos(p_script->debug_get_stack_level_line(current_frame)) + " in function '" + p_script->debug_get_stack_level_function(current_frame) + "'"); print_line("Enter \"help\" for assistance."); } else if (line == "c" || line == "continue") break; else if (line == "bt" || line == "breakpoint") { for (int i = 0; i < total_frames; i++) { String cfi = (current_frame == i) ? "*" : " "; //current frame indicator print_line(cfi + "Frame " + itos(i) + " - " + p_script->debug_get_stack_level_source(i) + ":" + itos(p_script->debug_get_stack_level_line(i)) + " in function '" + p_script->debug_get_stack_level_function(i) + "'"); } } else if (line.begins_with("fr") || line.begins_with("frame")) { if (line.get_slice_count(" ") == 1) { print_line("*Frame " + itos(current_frame) + " - " + p_script->debug_get_stack_level_source(current_frame) + ":" + itos(p_script->debug_get_stack_level_line(current_frame)) + " in function '" + p_script->debug_get_stack_level_function(current_frame) + "'"); } else { int frame = line.get_slicec(' ', 1).to_int(); if (frame < 0 || frame >= total_frames) { print_line("Error: Invalid frame."); } else { current_frame = frame; print_line("*Frame " + itos(frame) + " - " + p_script->debug_get_stack_level_source(frame) + ":" + itos(p_script->debug_get_stack_level_line(frame)) + " in function '" + p_script->debug_get_stack_level_function(frame) + "'"); } } } else if (line == "lv" || line == "locals") { List<String> locals; List<Variant> values; p_script->debug_get_stack_level_locals(current_frame, &locals, &values); List<Variant>::Element *V = values.front(); for (List<String>::Element *E = locals.front(); E; E = E->next()) { print_line(E->get() + ": " + String(V->get())); V = V->next(); } } else if (line == "gv" || line == "globals") { List<String> locals; List<Variant> values; p_script->debug_get_globals(&locals, &values); List<Variant>::Element *V = values.front(); for (List<String>::Element *E = locals.front(); E; E = E->next()) { print_line(E->get() + ": " + String(V->get())); V = V->next(); } } else if (line == "mv" || line == "members") { List<String> locals; List<Variant> values; p_script->debug_get_stack_level_members(current_frame, &locals, &values); List<Variant>::Element *V = values.front(); for (List<String>::Element *E = locals.front(); E; E = E->next()) { print_line(E->get() + ": " + String(V->get())); V = V->next(); } } else if (line.begins_with("p") || line.begins_with("print")) { if (line.get_slice_count(" ") <= 1) { print_line("Usage: print <expre>"); } else { String expr = line.get_slicec(' ', 2); String res = p_script->debug_parse_stack_level_expression(current_frame, expr); print_line(res); } } else if (line == "s" || line == "step") { set_depth(-1); set_lines_left(1); break; } else if (line.begins_with("n") || line.begins_with("next")) { set_depth(0); set_lines_left(1); break; } else if (line.begins_with("br") || line.begins_with("break")) { if (line.get_slice_count(" ") <= 1) { //show breakpoints } else { String bppos = line.get_slicec(' ', 1); String source = bppos.get_slicec(':', 0).strip_edges(); int line = bppos.get_slicec(':', 1).strip_edges().to_int(); source = breakpoint_find_source(source); insert_breakpoint(line, source); print_line("BreakPoint at " + source + ":" + itos(line)); } } else if (line.begins_with("delete")) { if (line.get_slice_count(" ") <= 1) { clear_breakpoints(); } else { String bppos = line.get_slicec(' ', 1); String source = bppos.get_slicec(':', 0).strip_edges(); int line = bppos.get_slicec(':', 1).strip_edges().to_int(); source = breakpoint_find_source(source); remove_breakpoint(line, source); print_line("Removed BreakPoint at " + source + ":" + itos(line)); } } else if (line == "h" || line == "help") { print_line("Built-In Debugger command list:\n"); print_line("\tc,continue :\t\t Continue execution."); print_line("\tbt,backtrace :\t\t Show stack trace (frames)."); print_line("\tfr,frame <frame>:\t Change current frame."); print_line("\tlv,locals :\t\t Show local variables for current frame."); print_line("\tmv,members :\t\t Show member variables for \"this\" in frame."); print_line("\tgv,globals :\t\t Show global variables."); print_line("\tp,print <expr> :\t Execute and print variable in expression."); print_line("\ts,step :\t\t Step to next line."); print_line("\tn,next :\t\t Next line."); print_line("\tbr,break source:line :\t Place a breakpoint."); print_line("\tdelete [source:line]:\t\t Delete one/all breakpoints."); } else { print_line("Error: Invalid command, enter \"help\" for assistance."); } } }