Beispiel #1
0
int NetworkConstraints::getNetworkConstraints(string resFile)
{
	try
    {
        sae::io::MappedGraph* g = sae::io::MappedGraph::Open(graphFile.c_str());
        for (auto e = g->Edges(); e->Alive(); e->Next()) 
        {
            EData ed = sae::serialization::convert_from_string<EData>(e->Data());
            ed.value = 0;
            for(auto es = e->Source()->OutEdges(); es->Alive(); es->Next())
            {
                for(auto ee = es->Target()->OutEdges(); ee->Alive(); ee->Next())
                {
                    if (ee->Target()->GlobalId() == e->Target()->GlobalId())
                    {
                        ed.value += sae::serialization::convert_from_string<EData>(es->Data()).attribute[0] * 
                        sae::serialization::convert_from_string<EData>(ee->Data()).attribute[0];
                        break;
                    }
                }
            }
            e->Data() = sae::serialization::convert_to_string<EData>(ed);     
        }
        ofstream outfile(resFile);
        for (auto v = g->Vertices(); v->Alive(); v->Next()) 
        {
            double value = 0;
            VData vd = sae::serialization::convert_from_string<VData>(v->Data());
            for(auto e = v->OutEdges(); e->Alive(); e->Next())
            {
                value += sae::serialization::convert_from_string<EData>(e->Data()).value;
            }
            if(v->OutEdgeCount() > 0)
            {
                outfile << vd.name << "\t" << value / v->OutEdgeCount() <<"\n";
            }
            else
            {
                outfile << vd.name << "\t" << 0 <<"\n";
            }
        }
        cout<<"compute Network Constraints done."<<endl;
    }
    catch(...)
    {
        cout << "Network Constraints parameter error" << endl;
        return -1;
    }
    return 0;
}
Beispiel #2
0
///knock player back. used in collisions
void Player::KnockBack()
{
    if (Alive())
    {
        SetXY(_lastX, _lastY);
    }
}
Beispiel #3
0
///knocks bad guy back. used for collisions.
void BadGuy::KnockBack()
{
    if (Alive())
    {
        SetXY(_lastX, _lastY);
    }

}
Beispiel #4
0
void Player::ClearDamage()
{
    if (Alive())
    {
        Hurt = false;
        _damagedSpriteSet = false;
        SetSprite(PLAYERSPRITE_FILENAME.c_str(), X, Y);
    }
}
Beispiel #5
0
void Player::Damage(int damage)
{
    if (Alive())
    {
        Health -= damage;
        Hurt = true;

        if (!_damagedSpriteSet)
            _damagedSpriteSet = SetSprite(PLAYERHURTSPRITE_FILENAME.c_str(), X, Y);
    }
}
Beispiel #6
0
void CHangingLamp::UpdateCL	()
{
	inherited::UpdateCL		();

	if(m_pPhysicsShell)
		m_pPhysicsShell->InterpolateGlobalTransform(&XFORM());

	if (Alive() && light_render->get_active()){
		if(Visual())	PKinematics(Visual())->CalculateBones();

		// update T&R from light (main) bone
		Fmatrix xf;
		if (light_bone!=BI_NONE){
			Fmatrix& M = smart_cast<CKinematics*>(Visual())->LL_GetTransform(light_bone);
			xf.mul		(XFORM(),M);
			VERIFY(!fis_zero(DET(xf)));
		}else{
			xf.set		(XFORM());
		}
		light_render->set_rotation	(xf.k,xf.i);
		light_render->set_position	(xf.c);
		if (glow_render)glow_render->set_position	(xf.c);

		// update T&R from ambient bone
		if (light_ambient){	
			if (ambient_bone!=light_bone){
				if (ambient_bone!=BI_NONE){
					Fmatrix& M = smart_cast<CKinematics*>(Visual())->LL_GetTransform(ambient_bone);
					xf.mul		(XFORM(),M);
					VERIFY(!fis_zero(DET(xf)));
				}else{
					xf.set		(XFORM());
				}
			}
			light_ambient->set_rotation	(xf.k,xf.i);
			light_ambient->set_position	(xf.c);
		}
		
		if (lanim){
			int frame;
			u32 clr					= lanim->CalculateBGR(Device.fTimeGlobal,frame); // возвращает в формате BGR
			Fcolor					fclr;
			fclr.set				((float)color_get_B(clr),(float)color_get_G(clr),(float)color_get_R(clr),1.f);
			fclr.mul_rgb			(fBrightness/255.f);
			light_render->set_color	(fclr);
			if (glow_render)		glow_render->set_color	(fclr);
			if (light_ambient) {
				fclr.mul_rgb		(ambient_power);
				light_ambient->set_color(fclr);
			}
		}
	}
}
    void SynchronousEngine<algorithm_t>::executeGathers (){
        // todo, how to get list of vertex ids to iterate?
        context_type context(*this, graph_);
        for (lvid_type vid = 0; vid < graph_.num_local_vertices(); vid++) {
            if (!active_superstep_[vid]) {
                continue;
            }
            auto &vprog = vertex_programs_[vid];
            vertex_type vertex(graph_.vertex(vid));
            auto gather_dir = vprog.gather_edges(context, vertex);

            bool accum_is_set = false;
            gather_type accum = gather_type();
            if (gather_dir == IN_EDGES || gather_dir == ALL_EDGES){
                for (auto ep = vertex.in_edges(); ep->Alive(); ep->Next()) {
                    edge_type edge(ep->Clone());
                    if(accum_is_set) {
                        accum += vprog.gather(context, vertex, edge);
                    } else {
                        accum = vprog.gather(context, vertex, edge);
                        accum_is_set = true;
                    }
                }
            }

            if (gather_dir == OUT_EDGES || gather_dir == ALL_EDGES){
                for (auto ep = vertex.out_edges(); ep->Alive(); ep->Next()) {
                    edge_type edge(ep->Clone());
                    if(accum_is_set) {
                        accum += vprog.gather(context, vertex, edge);
                    } else {
                        accum = vprog.gather(context, vertex, edge);
                        accum_is_set = true;
                    }
                }
            }
            gather_accum_[vid] = accum;
        }
    }
Beispiel #8
0
///returns true if the player was healed.
bool Player::Heal(int health){

    bool healed = false;

    if (Alive() && Health < _maxHealth){
        healed = true;
        Health += health;
        if (Health > _maxHealth)
            Health = _maxHealth;
    }

    return healed;
}
Beispiel #9
0
	size_t GoLWorld::Alive() const 
	{
		size_t alive = 0;
		for(size_t y=0; y<Height(); ++y)
		{
			for(size_t x=0; x<Width(); ++x)
			{
				if(Alive(x, y))
					++alive;
			}
		}
		return alive;
	}
Beispiel #10
0
///Moves bad guy towards it's target
void BadGuy::Move(int targetX, int targetY)
{
    if (Alive())
    {
        _lastX = X;
        _lastY = Y;

        int deltaX = 0, deltaY = 0;

        if (rand() % 50 == 0)
        {
            if (rand() % 2 == 0){
                deltaX += rand() % _stepDistance + 5;
                deltaY += rand() % _stepDistance + 5;
            } else {
                deltaX -= rand() % _stepDistance + 5;
                deltaY -= rand() % _stepDistance + 5;
            }
        }
        else
        {
            if (targetX < X)
            {
                deltaX -= _stepDistance;
                Direction = LEFT;
            }
            if (targetX > X)
            {
                deltaX += _stepDistance;
                Direction = RIGHT;
            }
            if (targetY < Y)
            {
                deltaY -= _stepDistance;
                Direction = UP;
            }
            if (targetY > Y)
            {
                deltaY += _stepDistance;
                Direction = DOWN;
            }
        }



        SetXY(X + deltaX, Y + deltaY);

    }
}
    virtual void Render() {
        GG::Clr base_color = Alive() ? m_wound_color : m_dead_color;

        // Always draw the red background, health will cover it
        GG::FlatRectangle(ClientUpperLeft(), ClientLowerRight(), base_color, m_hovered ? GG::CLR_WHITE : GG::CLR_BLACK, 1);

        if ( m_sizer.Get( TOGGLE_BAR_HEALTH_SMOOTH ) ) {
            // Use a smooth colour change based health display.
            if (Alive()) {
                double health_percentage = 1.0 * m_participant.current_health / m_participant.max_health;

                GG::Clr mixed_color(interpolate(health_percentage, m_health_color.r, m_wound_color.r),
                                    interpolate(health_percentage, m_health_color.g, m_wound_color.g),
                                    interpolate(health_percentage, m_health_color.b, m_wound_color.b),
                                    interpolate(health_percentage, m_health_color.a, m_wound_color.a));
                GG::FlatRectangle(ClientUpperLeft(), ClientLowerRight(), mixed_color, GG::CLR_ZERO, 1);
            }
        } else {
            if (Alive()) {
                GG::Y health_height( (m_participant.current_health / m_participant.max_health) * Value(ClientHeight()) );
                GG::FlatRectangle(GG::Pt(ClientUpperLeft().x, ClientLowerRight().y - health_height), ClientLowerRight(), m_health_color, GG::CLR_ZERO, 1);
            }
        }
    }
Beispiel #12
0
    virtual std::vector<sae::io::vid_t> get_targets(indexing::QueryItem support) {
        std::vector<sae::io::vid_t> targets;

        auto& g = data.g;
        auto vi = g->Vertices();
        vi->MoveTo(support.docId);
        auto publish_type = g->EdgeTypeIdOf("UserWeibo");
        for (auto edgeIt = vi->InEdges(); edgeIt->Alive(); edgeIt->Next()) {
            if (edgeIt->TypeId() == publish_type) {
                int gid = edgeIt->SourceId();
                targets.push_back(gid);
            }
        }

        return targets;
    }
Beispiel #13
0
void Player::Update()
{
	actual_time = GetTickCount();

	switch (actual_state)
	{
	case ALIVE:
	{
		Alive();
		break;
	}
	default:
	{
		break;
	}
	}
}
Beispiel #14
0
void Player::MoveToScreen(Directions direction)
{
    if (Alive())
    {
        //set direction
        Direction = direction;

        //set player movement
        int newX = 0, newY = 0;
        if (direction == RIGHT)
        {
            printf("moving player screen right\n");
            MapXLocation++;
            newX = _stepDistance * 2;
            newY = Y;
        }
        else if (direction == LEFT)
        {
            printf("moving player screen left\n");
            MapXLocation--;
            newX = PLAYFIELD_WIDTH - _stepDistance * 2;
            newY = Y;
        }
        else if (direction == DOWN)
        {
            printf("moving player screen down\n");
            MapYLocation++;
            newX = X;
            newY = _stepDistance * 2;
        }
        else if (direction == UP)
        {
            printf("moving player screen up\n");
            MapYLocation--;
            newX = X;
            newY = PLAYFIELD_HEIGHT - _stepDistance * 2;
        }
        _lastX = newX;
        _lastY = newY;

        //move player
        SetXY(newX, newY);
    }
}
void main() {
    // Set OSC to 64 MHz
    OSCCON = 0xF4;
    OSCCON2 = 0x80;
    OSCTUNE = 0xFF;

    // Setup output pins
    ANSELC = 0;
    TRISB = 0x00;
    TRISD = 0x00;
    LATB = 0x00;


    SetDefaults();
    InitDriverI2C();
    InitUART();
    Alive();

    Delay_us(1000);

    // Reset the Drivers
    TLC59116_ResetAll();
    TLC59116_Setup();

    // Run Idle Pattern before allowing input
    IdlePattern();

    // Enable all interrupts
    INTCON.GIE = 1;
    INTCON.PEIE = 1;


    while(1) {
        Refresh();
        auto_idle_counter++;

        if((auto_idle_counter > auto_idle_timeout) && auto_idle_enable && auto_idle_flag) {
            IdlePattern();
            auto_idle_counter = 0;
            auto_idle_flag = 0;
        }
    }
}
Beispiel #16
0
void Player::Move(Directions direction)
{
    if (Alive())
    {
        _lastX = X;
        _lastY = Y;

        //set direction
        Direction = direction;

        //set player movement
        int deltaX = 0, deltaY = 0;
        if (direction == RIGHT) deltaX += _stepDistance;
        else if (direction == LEFT) deltaX -= _stepDistance;
        else if (direction == DOWN) deltaY += _stepDistance;
        else if (direction == UP) deltaY -= _stepDistance;

        //move player
        SetXY(X + deltaX, Y + deltaY);
    }
}
Beispiel #17
0
char creature::CanWalk(void) {
    if(!Alive())
        return 0;

    int legok = 2;

    if(Wound[BODYPART_LEG_RIGHT].IsGone())
        legok--;

    if(Wound[BODYPART_LEG_LEFT].IsGone())
        legok--;

    if(SpecialWound[SPECIALWOUND_NECK] != 1 ||
            SpecialWound[SPECIALWOUND_UPPERSPINE] != 1 ||
            SpecialWound[SPECIALWOUND_LOWERSPINE] != 1)
        return 0;

    if(legok == 0)
        return 0;

    return 1;
}
Beispiel #18
0
int AverageSSSP::getAverageSSSP()
{
	try
    {
        double** dist;
        double MAX = 10000000;
        int paircount = 0;
        double distance = 0;
        sae::io::MappedGraph* g = sae::io::MappedGraph::Open(graphFile.c_str());
        dist = new double*[g->VertexCount()];
        for(int i = 0; i < g->VertexCount(); i++)
        {
            dist[i] = new double[g -> VertexCount()];
            for(int j = 0; j < g->VertexCount(); j++)
            {
                dist[i][j] = MAX;
            }            
        }
        for (auto v = g->Vertices(); v->Alive(); v->Next()) 
        {
            for(auto e = v->OutEdges(); e->Alive(); e->Next())
            {
                dist[v->GlobalId()][e->Source()->GlobalId()] = sae::serialization::convert_from_string<EData>(e->Data()).attribute[0];                
            }
        }
        int maxIter = g->VertexCount() / 1000;
        int lastIter = -10;
        for(int k = 0; k < g->VertexCount() / 1000; k++)
        {
            if (k * 100 / maxIter >= lastIter + 10)
            {
                lastIter = k * 100 / maxIter;
                printf("Processing %d%%...\n", lastIter);
            }
            for(int i = 0; i < g->VertexCount(); i++)
            {
                for(int j = 0; j < g->VertexCount(); j++)
                {
                    if(dist[i][j] > dist[i][k] + dist[k][j])
                    {
                        dist[i][j] = dist[i][k] + dist[k][j];
                    }
                }
            }
        }
        for(int i = 0; i < g->VertexCount(); i++)
        {
            for(int j = 0; j < g->VertexCount(); j++)
            {
                if(dist[i][j] < MAX)
                {
                    paircount ++;
                    distance += dist[i][j];
                }
            }
        }
        if(paircount > 0)
        {            
            cout<<"Average SSSP: " << distance / paircount << endl;
        }
        else
        {
            cout<<"Average SSSP: " << 0 << endl;
        }
    }
    catch(...)
    {
        cout<<"AverageSSSP parameter error"<<endl;
        return -1;
    }
    return 0;
}
Beispiel #19
0
/*-----------------------------------------------------------------------------
  Background thread for managing the state of the agent
-----------------------------------------------------------------------------*/
void CurlBlastDlg::ThreadProc(void)
{
    LoadSettings();

    // configure the desktop resolution
    WaitForSingleObject(testingMutex, INFINITE);
    SetupScreen();
    ReleaseMutex(testingMutex);

    // wait for the statup delay
    SetStatus(_T("Starting up..."));
    DWORD ms = startupDelay;
    while( ms > 0 && WaitForSingleObject(hMustExit,0) == WAIT_TIMEOUT) {
        Sleep(500);
        ms -= 500;
    }

    // launch the watchdog
    TCHAR path[MAX_PATH];
    GetModuleFileName(NULL, path, MAX_PATH);
    lstrcpy(PathFindFileName(path), _T("wptwatchdog.exe"));
    CString watchdog;
    watchdog.Format(_T("\"%s\" %d"), path, GetCurrentProcessId());
    HANDLE process = NULL;
    LaunchProcess(watchdog, &process);
    if (process)
        CloseHandle(process);

    if (WaitForSingleObject(hMustExit,0) == WAIT_TIMEOUT) {
        DoStartup();
    }

    // handle the periodic cleanup until it is time to exit
    Alive();
    DWORD msCleanup = 500;
    DWORD msTemp = 20000;
    while(WaitForSingleObject(hMustExit,0) == WAIT_TIMEOUT) {
        if (!msCleanup) {
            CloseDialogs();
            KillProcs();
            msCleanup = 500;
        } else
            msCleanup -= 500;

        if (!msTemp) {
            if (WaitForSingleObject(testingMutex, 0) != WAIT_TIMEOUT) {
                ClearTemp();
                msTemp = 20000;
                ReleaseMutex(testingMutex);
            }
        } else
            msTemp -= 500;

        CheckAlive();
        Sleep(500);
    }

    // signal and wait for all of the workers to finish
    KillWorker();

    // shut down the url manager
    urlManager.Stop();
}
Beispiel #20
0
BOOL CHangingLamp::net_Spawn(CSE_Abstract* DC)
{
	CSE_Abstract			*e		= (CSE_Abstract*)(DC);
	CSE_ALifeObjectHangingLamp	*lamp	= smart_cast<CSE_ALifeObjectHangingLamp*>(e);
	R_ASSERT				(lamp);
	inherited::net_Spawn	(DC);
	Fcolor					clr;

	// set bone id
//	CInifile* pUserData		= K->LL_UserData(); 
//	R_ASSERT3				(pUserData,"Empty HangingLamp user data!",lamp->get_visual());
	xr_delete(collidable.model);
	if (Visual()){
		CKinematics* K		= smart_cast<CKinematics*>(Visual());
		R_ASSERT			(Visual()&&smart_cast<CKinematics*>(Visual()));
		light_bone			= K->LL_BoneID	(*lamp->light_main_bone);	VERIFY(light_bone!=BI_NONE);
		ambient_bone		= K->LL_BoneID	(*lamp->light_ambient_bone);VERIFY(ambient_bone!=BI_NONE);
		collidable.model	= xr_new<CCF_Skeleton>				(this);
		// alpet: загрузка иммунитетов из спавн-конфига
		CInifile* ini=K->LL_UserData();
		if(ini && ini->section_exist("immunities"))		CHitImmunity::LoadImmunities("immunities",ini);
	}
	fBrightness				= lamp->brightness;
	clr.set					(lamp->color);						clr.a = 1.f;
	clr.mul_rgb				(fBrightness);

	light_render			= ::Render->light_create();
	light_render->set_shadow(!!lamp->flags.is(CSE_ALifeObjectHangingLamp::flCastShadow));
	light_render->set_type	(lamp->flags.is(CSE_ALifeObjectHangingLamp::flTypeSpot)?IRender_Light::SPOT:IRender_Light::POINT);
	light_render->set_range	(lamp->range);
	light_render->set_color	(clr);
	light_render->set_cone	(lamp->spot_cone_angle);
	light_render->set_texture(*lamp->light_texture);
	light_render->set_virtual_size(lamp->m_virtual_size);

	if (lamp->glow_texture.size())	{
		glow_render				= ::Render->glow_create();
		glow_render->set_texture(*lamp->glow_texture);
		glow_render->set_color	(clr);
		glow_render->set_radius	(lamp->glow_radius);
	}

	if (lamp->flags.is(CSE_ALifeObjectHangingLamp::flPointAmbient)){
		ambient_power			= lamp->m_ambient_power;
		light_ambient			= ::Render->light_create();
		light_ambient->set_type	(IRender_Light::POINT);
		light_ambient->set_shadow(false);
		clr.mul_rgb				(ambient_power);
		light_ambient->set_range(lamp->m_ambient_radius);
		light_ambient->set_color(clr);
		light_ambient->set_texture(*lamp->m_ambient_texture);
		light_ambient->set_virtual_size(lamp->m_virtual_size);
	}

	fHealth					= lamp->m_health;

	lanim					= LALib.FindItem(*lamp->color_animator);

	CPHSkeleton::Spawn(e);
	if (smart_cast<CKinematicsAnimated*>(Visual()))	smart_cast<CKinematicsAnimated*>	(Visual())->PlayCycle("idle");
	if (smart_cast<CKinematics*>(Visual())){
		smart_cast<CKinematics*>			(Visual())->CalculateBones_Invalidate	();
		smart_cast<CKinematics*>			(Visual())->CalculateBones();
		//.intepolate_pos
	}
	if (lamp->flags.is(CSE_ALifeObjectHangingLamp::flPhysic)&&!Visual())
		Msg("! WARNING: lamp, obj name [%s],flag physics set, but has no visual",*cName());
//.	if (lamp->flags.is(CSE_ALifeObjectHangingLamp::flPhysic)&&Visual()&&!guid_physic_bone)	fHealth=0.f;
	if (Alive())			TurnOn	();
	else{
		processing_activate		();	// temporal enable
		TurnOff					();	// -> and here is disable :)
	}
	
	setVisible					((BOOL)!!Visual());
	setEnabled					((BOOL)!!collidable.model);

	return						(TRUE);
}