Exemplo n.º 1
0
SystemManager *EntityList::FindOrBootSystem(uint32 systemID) {
	system_list::iterator res;
	res = m_systems.find(systemID);
	if(res != m_systems.end())
		return(res->second);

    sLog.Log("Entity List", "Booting system %u", systemID);
/*	
    ItemData idata(
        5,
        1,
		systemID,
		flagAutoFit,
        1
	);
*/
	SystemManager *mgr = new SystemManager(systemID, *m_services);//, idata);
	if(!mgr->BootSystem()) {
		delete mgr;
		return NULL;
	}
	
	m_systems[systemID] = mgr;
	return mgr;
}
Exemplo n.º 2
0
	void EntityManager::refresh(Entity& e) {
		SystemManager * systemManager = world->getSystemManager();
		Bag<EntitySystem*> & systems = systemManager->getSystems();
    
		for (int i=0; i< systems.getCount(); i++) {
			systems.get(i)->change(e);
		}
	}
bool NodeImpl::configExit()
{
	// If this is not a master node, call dispose on the engine object. 
	// Otherwise, ConfigImpl will take care of it.
	SystemManager* sys = SystemManager::instance();
	if(!sys->isMaster())
	{
		myServer->dispose();
	}
	return Node::configExit();
}
Exemplo n.º 4
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	bool result;
	SystemManager* System; 
	System = new SystemManager; 
	if (!System) { return 0; }
	result = System->Initialize();
	if (result){ System->Run();	}	
	System->Shutdown(); 
	delete System;
	System = 0; 

	return 0;
}
NodeImpl::NodeImpl( eq::Config* parent ):
	Node(parent),
	myServer(NULL)
{
	//omsg("[EQ] NodeImpl::NodeImpl");

	SystemManager* sys = SystemManager::instance();

	ApplicationBase* app = sys->getApplication();
	if(!sys->isMaster())
	{
		// This is the not master node. Create a standard server instance.
		myServer = new Engine(app);
	}
}
Exemplo n.º 6
0
PyResult Command_spawnbelt( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args )
{
	if( !who->IsInSpace() )
		throw PyException( MakeCustomError( "You must be in space to spawn things." ) );

    const double beltradius = 100000.0;
	const double beltdistance = 25000.0;
	const double roidradius = MakeRandomFloat( 100.0, 1000.0 );
	const double beltangle = M_PI * 2.0 / 3.0;
	const uint32 pcs = 20 + MakeRandomInt( -10, 10 );   // reduced from 160 + MakeRandomInt( -10, 10 )

	const GPoint position( who->GetPosition() );

	const double R = sqrt( position.x * position.x + position.z * position.z );
	const GPoint r = position * ( R + beltdistance - beltradius ) / R;

	double phi = atan( position.x / position.z );
	if( position.z < 0 )
		phi += M_PI;

	SystemManager* sys = who->System();
	std::map<double, uint32> roidDist;
	if( !db->GetRoidDist( sys->GetSystemSecurity(), roidDist ) )
    {
        sLog.Error( "Command", "Couldn't get roid list for system security %s", sys->GetSystemSecurity() );

		throw PyException( MakeCustomError( "Couldn't get roid list for system security %s", sys->GetSystemSecurity() ) );
	}

    //double distanceToMe;
	double alpha;
    GPoint mposition;

	for( uint32 i = 0; i < pcs; ++i )
    {
		alpha = beltangle * MakeRandomFloat( -0.5, 0.5 );

		mposition.x = beltradius * sin( phi + alpha ) + roidradius * MakeRandomFloat( 0, 15 );
		mposition.z = beltradius * cos( phi + alpha ) + roidradius * MakeRandomFloat( 0, 15 );
		mposition.y = position.y - r.y + roidradius * MakeRandomFloat( 0, 15 );
        //distanceToMe = (r + mposition - position).length();
        SpawnAsteroid( who->System(), GetAsteroidType( MakeRandomFloat(), roidDist ), roidradius, r + mposition );
	}

	return new PyString( "Spawn successsfull." );
}
bool NodeImpl::configInit( const eq::uint128_t& initID )
{
	//ofmsg("[EQ] NodeImpl::configInit %1%", %initID);

	SystemManager* sys = SystemManager::instance();
	if(!sys->isMaster())
	{
		ConfigImpl* config = static_cast<ConfigImpl*>( getConfig());
		config->mapSharedData(initID);

		myServer->initialize();
		
		EqualizerDisplaySystem* eqds = (EqualizerDisplaySystem*)SystemManager::instance()->getDisplaySystem();
		eqds->finishInitialize(config, myServer);
	}

	return Node::configInit(initID);
}
Exemplo n.º 8
0
int main()
{
	Window window(0, L"asd", 800, 600);
	window.ShowAWindow();
	rendContext = new RenderingContext(&window);
	SystemManager* SM = new SystemManager();


	RenderingSystem* RS = new RenderingSystem(rendContext);
	PhysicsSystem* PS = new PhysicsSystem(90.81);

	SM->AddSystem(RS);
	SM->AddSystem(PS);

	LARGE_INTEGER StartingTime, EndingTime, ElapsedMilliseconds;
	LARGE_INTEGER Frequency;

	GameObject* obj = new GameObject("BOX_X.obj");
	GameObject* obj2 = new GameObject("pallo.obj");

	Renderable* rendComp = ComponentFactory::CreateRenderable("pallo.obj", "sample.png");
	Renderable* rendComp2 = ComponentFactory::CreateRenderable("pallo.obj", "tribaltatuointi.png");


	Physics* physz = ComponentFactory::CreatePhysicsComponent(PS);
	Physics* physz2 = ComponentFactory::CreatePhysicsComponent(PS);

	Transformable* transComp = ComponentFactory::CreateTransformable();
	Transformable* transComp2 = ComponentFactory::CreateTransformable();

	
	physz2->SetMass(5);
	physz->SetMass(2.5);
	physz->SetElasticity(0.6);
	physz->SetForces(Vector3<float>(1000000.0f, 1000000.0f, 0.0f));
	physz2->SetForces(Vector3<float>(-1000000.0f, -1000000.0f, 0.0f));
	obj->AddComponent(rendComp2);
	obj->AddComponent(transComp);

	obj2->AddComponent(rendComp);
	obj2->AddComponent(transComp2);

	obj->AddComponent(physz);
	obj2->AddComponent(physz2);


	transComp2->SetOrigin(100, 50, -200.0f);
	transComp->SetOrigin(0, 0, -200.0f);

	int x = 0;

	RS->Draw(obj);
	RS->Draw(obj2);

	while (true)
	{
		QueryPerformanceFrequency(&Frequency);
		QueryPerformanceCounter(&StartingTime);


		if (Input::isKeyPressed(Input::L))
			std::cout << "X: " << transComp->GetOrigin()[0] << " Y: " << transComp->GetOrigin()[1] << " Z: " << transComp->GetOrigin()[2] << std::endl;

		window.WindowMessageCheck();

		
		
		if (Input::isKeyPressed(Input::W))
			physz->SetForces(Vector3<float>(0.0f, 4000.0f, 0.0f));
		if (Input::isKeyPressed(Input::S))
			physz->SetForces(Vector3<float>(0.0f, -4000.0f, 0.0f));
		if (Input::isKeyPressed(Input::D))
			physz->SetForces(Vector3<float>(4000.0f, 0.0f, 0.0f));
		if (Input::isKeyPressed(Input::A))
			physz->SetForces(Vector3<float>(-4000.0f, 0.0f, 0.0f));
		if (Input::isKeyPressed(Input::Up))
			physz->SetForces(Vector3<float>(0.0f, 0.0f, -4000.0f));
		if (Input::isKeyPressed(Input::Down))
			physz->SetForces(Vector3<float>(0.0f, 0.0f, 4000.0f));


		x++;
		float al = ((transComp->GetOrigin()[0] - transComp2->GetOrigin()[0])*(transComp->GetOrigin()[0] - transComp2->GetOrigin()[0]));
		float ad = ((transComp->GetOrigin()[1] - transComp2->GetOrigin()[1])*(transComp->GetOrigin()[1] - transComp2->GetOrigin()[1]));
		if (sqrt(al + ad) < 50)
		{
			//if (x < 5)
			//	;
			//else
			physz->collision = true;
			std::cout << "Collision!"<< std::endl;
			x = 0;
		}
			
		if (Input::isKeyPressed(Input::Escape))
			break;

		

		

		if (Input::isKeyPressed(Input::Space))
			physz->collision = true;
		//kokeilua asd
		
		

		SM->UpdateSystems();

		QueryPerformanceCounter(&EndingTime);
		ElapsedMilliseconds.QuadPart = EndingTime.QuadPart - StartingTime.QuadPart;

		ElapsedMilliseconds.QuadPart *= 1000000;
		double as = ElapsedMilliseconds.QuadPart /= Frequency.QuadPart;
		PS->deltaTime = (as / 1000000);
		std::cout << " deltat: " << as/1000000 << " s"<<std::endl;
	}
	
	return 0;
}
Exemplo n.º 9
0
PyResult Command_spawnbelt( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args )
{
    if( !who->IsInSpace() )
        throw PyException( MakeCustomError( "You must be in space to spawn things." ) );

	bool makeIceBelt = false;
	bool makeRareIce = false;
	uint32 customCount = 0;
    if( args.argCount() >= 2 )
	{
        if( !args.isNumber( 1 ) )
		{
			if( args.arg( 1 ) == "ice" )
				makeIceBelt = true;
		}
		else
		{
			if( atoi(args.arg( 1 ).c_str()) > 15 )
				customCount = atoi(args.arg( 1 ).c_str());
			else
				PyException( MakeCustomError( "Argument 1 should be at least 15!" ) );
		}
	}

	if( args.argCount() >= 3 )
	{
		if( args.isNumber( 2 ) )
		{
			if( atoi(args.arg( 2 ).c_str()) > 15 )
				customCount = atoi(args.arg(2).c_str());
			else
				PyException( MakeCustomError( "Argument 2 should be at least 15!" ) );
		}
		else
			if( args.arg( 2 ) == "ice" )
				makeIceBelt = true;
			if( args.arg( 2 ) == "rareice" )
			{
				makeIceBelt = true;
				makeRareIce = true;
			}
	}

    const double beltradius = 100000.0;
    const double beltdistance = 25000.0;
    double roidradius;
    const double beltangle = M_PI * 2.0 / 3.0;
    uint32 pcs = 0;
	
	if( customCount > 15 )
		pcs = customCount + static_cast<uint32>(MakeRandomInt( -10, 10 ));
	else
		pcs = 30 + static_cast<uint32>(MakeRandomInt( -10, 10 ));

    const GPoint position( who->GetPosition() );

    const double R = sqrt( position.x * position.x + position.z * position.z );
    const GPoint r = position * ( R + beltdistance - beltradius ) / R;

    double phi = atan( position.x / position.z );
    if( position.z < 0 )
        phi += M_PI;

    SystemManager* sys = who->System();
    std::map<double, uint32> roidDist;
	if( makeIceBelt )
	{
		std::string securityStatus = sys->GetSystemSecurity();
		if( !makeRareIce )
		{
			roidDist.insert(std::pair<double,uint32>(0.60,16264));		// Blue Ice
			roidDist.insert(std::pair<double,uint32>(0.45,17975));		// Thick Blue Ice
			roidDist.insert(std::pair<double,uint32>(0.30,28627));		// Azure Ice
			roidDist.insert(std::pair<double,uint32>(0.20,16262));		// Clear Icicle
			roidDist.insert(std::pair<double,uint32>(0.10,16267));		// Dark Glitter
		}
		if( makeRareIce )
		{
			roidDist.insert(std::pair<double,uint32>(0.90,16263));		// Glacial Mass
			roidDist.insert(std::pair<double,uint32>(0.80,16265));		// White Glaze
			roidDist.insert(std::pair<double,uint32>(0.70,16266));		// Glare Crust
			roidDist.insert(std::pair<double,uint32>(0.60,16268));		// Gelidus
			roidDist.insert(std::pair<double,uint32>(0.50,16269));		// Krystallos
			roidDist.insert(std::pair<double,uint32>(0.40,17976));		// Pristine White Glaze
			roidDist.insert(std::pair<double,uint32>(0.30,17977));		// Smooth Glacial Mass
			roidDist.insert(std::pair<double,uint32>(0.20,17978));		// Enriched Clear Icicle
			roidDist.insert(std::pair<double,uint32>(0.10,28628));		// Crystalline Icicle
		}
	}
	else
	{
		if( !db->GetRoidDist( sys->GetSystemSecurity(), roidDist ) )
		{
			sLog.Error( "Command", "Couldn't get roid list for system security %s", sys->GetSystemSecurity() );

			throw PyException( MakeCustomError( "Couldn't get roid list for system security %s", sys->GetSystemSecurity() ) );
		}
	}

    double distanceToMe;
    double alpha;
    GPoint mposition;

	if( makeIceBelt )
		pcs *= 2;

    for( uint32 i = 0; i < pcs; ++i )
    {
        alpha = beltangle * MakeRandomFloat( -0.5, 0.5 );

		if( makeIceBelt )
			roidradius = MakeRandomFloat( 1000.0, 10000.0 );
		else
			roidradius = MakeRandomFloat( 100.0, 1000.0 );
        mposition.x = beltradius * sin( phi + alpha ) + roidradius * MakeRandomFloat( 0, 15 );
        mposition.z = beltradius * cos( phi + alpha ) + roidradius * MakeRandomFloat( 0, 15 );
        mposition.y = position.y - r.y + roidradius * MakeRandomFloat( 0, 15 );
        distanceToMe = (r + mposition - position).length();
        SpawnAsteroid( who->System(), GetAsteroidType( MakeRandomFloat(), roidDist ), roidradius, r + mposition );
    }

    return new PyString( "Spawn successsfull." );
}
Exemplo n.º 10
0
int main(int argc, char* argv[]) {
  SystemManager *sysMan = new SystemManager(argc, argv);
  sysMan->setDebugMode(DEBUG);
  return sysMan->run();
}
Exemplo n.º 11
0
void SpawnEntry::_DoSpawn(SystemManager &mgr, PyServiceMgr &svc) {
	_log(SPAWN__POP, "Spawning spawn entry %u with group %u", m_id, m_group.id);
	
	//pick our spawn point...
	GPoint spawn_point;
	switch(m_boundsType) {	//safe to assume `bounds` are correct.
	
	case boundsPoint: {
		spawn_point = bounds[0];
	} break;
	
	case boundsLine: {
		GVector vec(bounds[0], bounds[1]);
		double len = vec.length();
		
		spawn_point = GPoint(bounds[0] + Ga::GaFloat(MakeRandomFloat(0, len))*Ga::GaVec3(vec));
	} break;
	
	default:
		_log(SPAWN__ERROR, "Invalid bounds type %u on spawn entry %u when spawning...", m_boundsType, GetID());
		return;
	}
	_log(SPAWN__POP, "    selected point (%.1f, %.1f, %.1f)", spawn_point.x, spawn_point.y, spawn_point.z);

	std::vector<NPC *> spawned;
	
	//now see what is gunna spawn...
	std::vector<SpawnGroup::Entry>::const_iterator cur, end;
	cur = m_group.entries.begin();
	end = m_group.entries.end();
	for(; cur != end; cur++) {
		_log(SPAWN__POP, "    Evaluating spawn entry for NPC type %u in group %u", cur->npcTypeID, cur->spawnGroupID);
		int r;
		for(r = 0; r < cur->quantity; r++) {
			if(cur->probability < 1.0f) {
				if(MakeRandomFloat(0, 1.0f) > cur->probability) {
					_log(SPAWN__POP, "        [%d] not spawning, p=%.4f failed.", r, cur->probability);
					continue;
				}
				_log(SPAWN__POP, "        [%d] passed proability check of p=%.4f", r, cur->probability);
			}

			//NOTE: this is currently creating an entry in the DB...
			//which is terrible... we need to make an "in-memory only"
			// item concept.
			ItemData idata(
				cur->npcTypeID,
				cur->ownerID,	//owner
				mgr.GetID(),
				flagAutoFit
			);

			InventoryItemRef i = svc.item_factory.SpawnItem(idata);
			if( !i ) {
				_log(SPAWN__ERROR, "Failed to spawn item with type %u for group %u.", cur->npcTypeID, cur->spawnGroupID);
				continue;
			}
			
			_log(SPAWN__POP, "        [%d] spawning NPC id %u", r, i->itemID());
			
			//create them all at the same point to start with...
			//we will move them before they get added to the system
			NPC *npc = new NPC(&mgr, svc,
				i, cur->corporationID, 0, spawn_point, this);	//TODO: add allianceID
			spawned.push_back(npc);
		}
	}
	
	if(spawned.empty()) {
		int timer = MakeRandomInt(m_timerMin, m_timerMax);
		_log(SPAWN__POP, "No NPCs produced by spawn entry %u. Resetting spawn timer to %d s.", m_id, timer);
		m_timer.Start(timer*1000);
		return;
	}
	
	//TODO: apply formation..
	//hacking it for now...
	std::vector<NPC *>::iterator curn, endn;
	curn = spawned.begin();
	endn = spawned.end();
	for(; curn != endn; curn++) {
		_log(SPAWN__POP, "Moving NPC %u to (%.1f, %.1f, %.1f) due to formation.", (*curn)->GetID(), spawn_point.x, spawn_point.y, spawn_point.z);
		(*curn)->ForcedSetPosition(spawn_point);
		spawn_point.y += 1000.0f;
	}
	
	
	//now the NPCs are all set up, lets drop them into the system.
	curn = spawned.begin();
	endn = spawned.end();
	for(; curn != endn; curn++) {
		//load up any NPC attributes...
		if(!(*curn)->Load(svc.serviceDB())) {
			_log(SPAWN__POP, "Failed to load NPC data for NPC %u with type %u, depoping.", (*curn)->GetID(), (*curn)->Item()->typeID());
			delete *curn;
			continue;
		}
		
		//record this NPC as something we spawned.
		m_spawnedIDs.insert((*curn)->GetID());
		
		mgr.AddNPC(*curn);
	}
	
	//timer is disabled while the spawn is up.
	m_timer.Disable();
}
Exemplo n.º 12
0
/*
 * SQL to remove all asteroids from space in ALL systems.
 * Important, run in this order or the attributes will not be deleted!
 * 
DELETE FROM srvEntity_default_attributes WHERE attributeID > 0 and itemID in
(SELECT itemID from srvEntity where ownerID=1 AND typeID in
(SELECT typeID from invTypes where groupID in
(select groupID FROM invGroups where categoryID=25) or groupID=711));
DELETE FROM srvEntity_attributes WHERE attributeID > 0 and itemID in
(SELECT itemID from srvEntity where ownerID=1 AND typeID in
(SELECT typeID from invTypes where groupID in
(select groupID FROM invGroups where categoryID=25) or groupID=711));
DELETE FROM srvEntity WHERE itemID>=140000000 AND ownerID=1 AND typeID in
(SELECT typeID from invTypes where groupID in
(select groupID FROM invGroups where categoryID=25) or groupID=711);
 * 
 */
PyResult Command_spawnbelt( Client* who, const Seperator& args )
{
    if (!who->IsInSpace())
    {
        throw PyException(MakeCustomError("You must be in space to spawn things."));
    }

	bool makeIceBelt = false;
	bool makeRareIce = false;
	uint32 customCount = 0;
    if( args.argCount() >= 2 )
	{
        if( !args.isNumber( 1 ) )
		{
			if( args.arg( 1 ) == "ice" )
				makeIceBelt = true;
		}
		else
		{
			if( atoi(args.arg( 1 ).c_str()) > 15 )
				customCount = atoi(args.arg( 1 ).c_str());
			else
				PyException( MakeCustomError( "Argument 1 should be at least 15!" ) );
		}
	}

	if( args.argCount() >= 3 )
	{
		if( args.isNumber( 2 ) )
		{
			if( atoi(args.arg( 2 ).c_str()) > 15 )
				customCount = atoi(args.arg(2).c_str());
			else
				PyException( MakeCustomError( "Argument 2 should be at least 15!" ) );
		}
		else
			if( args.arg( 2 ) == "ice" )
				makeIceBelt = true;
			if( args.arg( 2 ) == "rareice" )
			{
				makeIceBelt = true;
				makeRareIce = true;
			}
    }

    double beltradius = 25000.0; // 25 KM
    if(makeIceBelt)
    {
        beltradius = 100000.0; // 100 KM
    }
    uint32 pcs = 0;

    if (customCount > 15)
    {
        pcs = customCount + static_cast<uint32> (MakeRandomInt(-10, 10));
    }
    else
    {
        pcs = 200 + static_cast<uint32> (MakeRandomInt(-10, 10));
    }

    SystemManager* sys = who->System();
    std::map<double, uint32> roidDist;
    if (makeIceBelt)
    {
        pcs /= 8;
        std::string securityStatus = sys->GetSystemSecurity();
        if (!makeRareIce)
        {
            roidDist.insert(std::pair<double, uint32>(0.60, 16264)); // Blue Ice
            roidDist.insert(std::pair<double, uint32>(0.45, 17975)); // Thick Blue Ice
            roidDist.insert(std::pair<double, uint32>(0.30, 28627)); // Azure Ice
            roidDist.insert(std::pair<double, uint32>(0.20, 16262)); // Clear Icicle
            roidDist.insert(std::pair<double, uint32>(0.10, 16267)); // Dark Glitter
        }
        if (makeRareIce)
        {
            roidDist.insert(std::pair<double, uint32>(0.90, 16263)); // Glacial Mass
            roidDist.insert(std::pair<double, uint32>(0.80, 16265)); // White Glaze
            roidDist.insert(std::pair<double, uint32>(0.70, 16266)); // Glare Crust
            roidDist.insert(std::pair<double, uint32>(0.60, 16268)); // Gelidus
            roidDist.insert(std::pair<double, uint32>(0.50, 16269)); // Krystallos
            roidDist.insert(std::pair<double, uint32>(0.40, 17976)); // Pristine White Glaze
            roidDist.insert(std::pair<double, uint32>(0.30, 17977)); // Smooth Glacial Mass
            roidDist.insert(std::pair<double, uint32>(0.20, 17978)); // Enriched Clear Icicle
            roidDist.insert(std::pair<double, uint32>(0.10, 28628)); // Crystalline Icicle
        }
    }
    else
    {
        if (!CommandDB::GetRoidDist(sys->GetSystemSecurity(), roidDist))
        {
            SysLog::Error("Command", "Couldn't get roid list for system security %s", sys->GetSystemSecurity());

            throw PyException(MakeCustomError("Couldn't get roid list for system security %s", sys->GetSystemSecurity()));
        }
    }

    const GPoint position(who->GetPosition());
    double phi = atan(position.x / position.z);
    if (position.z == 0)
    {
        phi = M_PI / 2;
    }
    if (position.z < 0)
    {
        phi += M_PI;
    }
    GPoint beltOffset;
    if (makeIceBelt)
    {
        beltOffset.x = (beltradius * 0.75) * sin(phi);
        beltOffset.z = (beltradius * 0.75) * cos(phi);
    }
    double alpha;
    GPoint mposition;
    double beltThickness = 3000;
    double height;
    double roidradius;
    const double beltangle = M_PI * 2.0 / 3.0;
    int triesLeft = pcs * 25;
    int pcsLeft = pcs;
    std::vector<std::pair<GPoint, double>> spawned;
    while (triesLeft-- && pcsLeft)
    {
        uint32 typeID = GetAsteroidType(MakeRandomFloat(), roidDist);
        // Generate asteroid parameters.
		if( makeIceBelt)
        {
            height = MakeRandomFloat(-0.2, 1.8);
            alpha = beltangle * ((M_PI / 8) * height);
            roidradius = MakeRandomFloat(4000.0, 10000.0);
            height *= 8;
        }
        else
        {
            alpha = beltangle * MakeRandomFloat(-M_PI / 4, M_PI / 4);
			roidradius = MakeRandomFloat( 100.0, 1000.0 );
            height = MakeRandomFloat(-1, 1);
            const ItemType *type = ItemFactory::GetType(typeID);
            if (type->groupID() == EVEDB::invGroups::Veldspar)
            {
                roidradius *= 2;
            }
        }
        // Calculate new position.
        mposition.y = beltThickness * height;
        mposition.x = beltradius * sin(phi + alpha) + beltThickness * MakeRandomFloat(-1, 1);
        mposition.z = beltradius * cos(phi + alpha) + beltThickness * MakeRandomFloat(-1, 1);
        // Check for collision.
        bool collision = false;
        for (auto pair : spawned)
        {
            GPoint point = pair.first;
            double dist = (mposition - point).length();
            double radii = (roidradius + pair.second);
            if ((dist - radii) < 0)
            {
                collision = true;
                continue;
            }
        }
        if (collision)
        {
            // There was a collision, try again.
            continue;
        }
        // Were good, add the asteroid.
        pcsLeft--;
        SpawnAsteroid(who->System(), typeID, roidradius, mposition + position - beltOffset);
        // Save the location for collision checks.
        spawned.push_back(std::pair<GPoint, double>(mposition, roidradius));
    }

    return new PyString( "Spawn successsfull." );
}
Exemplo n.º 13
0
int main(int argc, char** argv)
{
  // Parameters
  std::string filename = "system.dat";
  float temperature = 1.0f;
  float epsilon = 0;
  uint64_t seed = 0;
  int phi_card = 0;

  // Get parameters
  for(int i = 1; i < argc; i++)
  {
    if(strlen(argv[i]) != 2 || argv[i][0] != '-' || i+1 == argc)
    {
      std::cout << "Invalid option " << argv[i] << std::endl;
      return EXIT_FAILURE;
    }

    switch(argv[i][1])
    {
      case 'o': // Output file
        filename = argv[i+1];
        break;
      case 't': // Temperature
        temperature = std::stof(argv[i+1]);
        break;
      case 'e': // Epsilon
        epsilon = std::stof(argv[i+1]);
        break;
      case 's': // RNG Seed
        seed = std::stoull(argv[i+1]);
        break;
      case 'p': // Numer of Phi card to use
        phi_card = std::stoi(argv[i+1]);
        break;
      default:
        std::cout << "Invalid option " << argv[i] << std::endl;
        return EXIT_FAILURE;
    }
    i++;
  }

  // Required timesteps
  std::set<uint64_t> times;
  uint64_t maxT = 10000000;
  for(uint64_t j = 1; j <= maxT/10; j*=10)
  {
    times.insert(j);
    for(uint64_t i = 1; i < maxT; i+=(i+1)/2)
      times.insert(j+i);
  }
  size_t system_size = 2*4*N*N*N;
  std::cout << "Timesteps to save: " << times.size() << std::endl;
  std::cout << "Space required: " << times.size()*system_size/1024/1024 << " MB" << std::endl;

  // Info
  float field = epsilon * temperature;
  std::cout << "Temperature: " << temperature << std::endl;
  std::cout << "Field: " << field << std::endl;
  std::cout << "Seed: " << seed << std::endl;
  std::cout << "Dimension: " << N << "^3" << std::endl;

  // Initialize
  uint32_t* systemState = (uint32_t*)_mm_malloc(system_size, 64);
  uint32_t* system0;
  #pragma offload target(mic:phi_card)       \
    in(systemState : length(2*N*N*N) ALLOC)  \
    nocopy(system0)
  {
    system0 = (uint32_t*)_mm_malloc(sizeof(uint32_t)*(N*N*N*4 + OFFSET), ALIGN);
    uint32_t* system1 = system0 + N*N*N + OFFSET/4;
    uint32_t* field0 = system1 + N*N*N + OFFSET/4;
    uint32_t* field1 = field0 + N*N*N + OFFSET/4;
    setParameters(temperature, field);
  
    randomize(system0, seed++);
    randomize(system1, seed++);
    randomize(field0, seed++);
    randomize(field1, seed++);
  }

  // Open output file
  SystemManager mgr;
  mgr.CreateFile(filename, N, 2*4);
  mgr.SetParameters(temperature, field);

  // Set precision
  std::cout.precision(2);
  std::cout << std::fixed;
  
  // Start simulation
  times.insert(0);
  auto prev = times.begin();
  uint64_t maxTime = *times.rbegin();
  double startTime = get_cputime();
  for(auto it = std::next(prev); it != times.end(); ++it)
  {
    // Necessary steps for next system
    uint64_t steps = *it - *prev;
    prev = it;
    
    // Do steps
    #pragma offload target(mic:phi_card)        \
      out(systemState : length(2*N*N*N) REUSE)  \
      nocopy(system0)
    {
      uint32_t* system1 = system0 + N*N*N + OFFSET/4;
      uint32_t* field0 = system1 + N*N*N + OFFSET/4;
      uint32_t* field1 = field0 + N*N*N + OFFSET/4;

      for(uint64_t i = 0; i < steps; ++i)
      {
        spinFlip(system0, system1, field0, seed++);
        spinFlip(system1, system0, field1, seed++);
      }
      
      // Rearrange system for output
      for(unsigned int z = 0; z < N; z++)
      for(unsigned int y = 0; y < N; y++)
      for(unsigned int x = 0; x < N; x++)
      {
        if((x+y+z)%2)
        {
          systemState[2*(z*N*N + y*N + x)]   = system0[z*N*N + y*N + x];
          systemState[2*(z*N*N + y*N + x)+1] = system1[z*N*N + y*N + x];
        }
        else
        {
          systemState[2*(z*N*N + y*N + x)]   = system1[z*N*N + y*N + x];
          systemState[2*(z*N*N + y*N + x)+1] = system0[z*N*N + y*N + x];
        }
      }
    }
    
    // Write out system
    mgr.SaveSystem(*it, reinterpret_cast<const char*>(systemState), system_size);
    
    // Statistics
    std::cout << "\r" << *it * 100.f/maxTime << "% finished" << std::flush;
  }
  
  double stopTime = get_cputime();
  double delta = stopTime-startTime;
  double timePerSpin = delta/64/N/N/N/maxTime;
  std::cout << "\r" << 100.0 << "% finished" << std::endl;
  std::cout << "Elapsed time: " << delta << std::endl;
  std::cout << "Time per spin: " << timePerSpin*1E12 << " ps" << std::endl;
  
  // Free memory
  #pragma offload target(mic:phi_card)       \
    out(systemState : length(2*N*N*N) FREE)  \
    nocopy(system0)
  {
    _mm_free(system0);
  }
}
Exemplo n.º 14
0
AbstractSystem::AbstractSystem(SystemManager & systemManager, UpdateStepEnum updateStep) : 
    _systemManager(systemManager)
{
    systemManager.RegisterSystem(this, updateStep);
}