示例#1
0
void Path::Update( float dt )
{
    const float curr_time = t.GetTime();
    if( curr_time > clock_time ) {
        Charges next_charges;

        for( Objects::iterator it = objects.begin(); it != objects.end(); ++it ) {
            if( (*it)->HasOutCharge() ) {
                const Vec2i pt = (*it)->GetGridPos();
                const Vec2i face = (*it)->Facing();

                //L_ << "We're " << pt << " " << face << '\n';

                Vec2i out_pos;
                if( face == Vec2i::left ) out_pos = grid->TopLeftPos( pt );
                else if( face == Vec2i::right ) out_pos = grid->DownRightPos( pt );
                else if( face == Vec2i::up ) out_pos = grid->TopRightPos( pt );
                else if( face == Vec2i::down ) out_pos = grid->DownLeftPos( pt );

                Charge charge = (*it)->ChargeOut();
                charge.point = out_pos;
                charge.can_kill = false;
                charge.dir = face;
                //L_ << "We wanna charge: " << charge.type << '\n';

                if( Has( out_pos ) ) {
                    //L_ << "Def added in next\n";
                    AddChock( next_charges, charge  );
                }

            }
            (*it)->ClockPulse();
        }


        for( Charges::iterator it = charges.begin(); it != charges.end(); ++it ) {
            if( it->can_kill ) continue;

            const Vec2i pt = it->point;
            if( it->dir == Vec2i::zero ) {
                Chock( grid->TopLeftPos( pt ), Vec2i::left );
                Chock( grid->DownRightPos( pt ), Vec2i::right );
                Chock( grid->TopRightPos( pt ), Vec2i::up );
                Chock( grid->DownLeftPos( pt ), Vec2i::down );
            }
            else {
                const Vec2i left = grid->TopLeftPos( pt );
                const Vec2i right = grid->DownRightPos( pt );
                const Vec2i up = grid->TopRightPos( pt );
                const Vec2i down = grid->DownLeftPos( pt );

                Vec2i order[4];
                Vec2i dir[4];

                if( it->dir == Vec2i::left ) {
                    order[0] = left; dir[0] = Vec2i::left;
                    order[1] = down; dir[1] = Vec2i::down;
                    order[2] = up; dir[2] = Vec2i::up;
                    order[3] = right; dir[3] = Vec2i::right;
                }
                else if( it->dir == Vec2i::right ) {
                    order[0] = right; dir[0] = Vec2i::right;
                    order[1] = down; dir[1] = Vec2i::down;
                    order[2] = up; dir[2] = Vec2i::up;
                    order[3] = left; dir[3] = Vec2i::left;
                }
                else if( it->dir == Vec2i::up ) {
                    order[0] = up; dir[0] = Vec2i::up;
                    order[1] = left; dir[1] = Vec2i::left;
                    order[2] = right; dir[2] = Vec2i::right;
                    order[3] = down; dir[3] = Vec2i::down;
                }
                else if( it->dir == Vec2i::down ) {
                    order[0] = down; dir[0] = Vec2i::down;
                    order[1] = left; dir[1] = Vec2i::left;
                    order[2] = right; dir[2] = Vec2i::right;
                    order[3] = up; dir[3] = Vec2i::up;
                }

                if( CanChock( order[0] ) ) {
                    AddChock( next_charges, order[0], dir[0], it->type );
                }
                else {
                    if( Has( order[1] ) || Has( order[2] ) ) {
                        AddChock( next_charges, order[1], dir[1], it->type );
                        AddChock( next_charges, order[2], dir[2], it->type );
                        if( Has( order[1] ) && Has( order[2] ) ) {
                            split.Play();
                        }
                        else {
                            turn.Play();
                        }
                    }
                    else {
                        AddChock( next_charges, order[3], dir[3], it->type );
                        dead_end.Play();
                    }
                }
            }
        }
        charges = next_charges;
        if( !chocks.empty() ) {
            //charge_it.Play();
            charges.splice( charges.begin(), chocks );
        }

        // This isn't effective, bot I don't care atm
        Charges unique;

        for( Charges::iterator it = charges.begin(); it != charges.end(); ++it ) {
            const Vec2i pt = it->point;

            if( HasObj( pt ) ) {
                PathObjPtr obj = GetObj( pt );
                obj->ChargeIn( *it );
            }

            bool has = false;
            for( Charges::iterator is = unique.begin(); is != unique.end(); ++is ) {
                if( *it == *is ) {
                    has = true;
                    break;
                }
            }
            if( !has ) { unique.push_back( *it ); }
        }
        charges = unique;

        t.Restart();
    }
}
      before_each([&](){
        context = std::unique_ptr<bf::fake_context>(new bf::fake_context());
        context_stack = std::unique_ptr<bandit::detail::contextstack_t>(new bandit::detail::contextstack_t());
        context_stack->push_back(context.get());
      });
      
      describe("before_each", [&](){
        bandit::detail::voidfunc_t before_each_fn;

        before_each([&](){
          before_each_fn = [](){};
          });

        it("registers itself for the current context in the stack", [&](){
          before_each(before_each_fn, *context_stack); 
          Assert::That(context->call_log(), Has().Exactly(1).EqualTo("register_before_each"));
          });

      }); 

      describe("after_each", [&](){
          bandit::detail::voidfunc_t after_each_fn;
        
        before_each([&](){
          after_each_fn = [](){};
        });
      
        it("registers itself for the current context in the stack", [&](){
          after_each(after_each_fn, *context_stack); 
          Assert::That(context->call_log(), Has().Exactly(1).EqualTo("register_after_each"));
        });