TEST_F(ClusterTest, testListenersWhenClusterDown) {
                HazelcastServer instance(*g_srvFactory);

                std::auto_ptr<ClientConfig> clientConfig(getConfig());
                clientConfig->setAttemptPeriod(1000 * 10).setConnectionAttemptLimit(100).setLogLevel(FINEST);
                HazelcastClient hazelcastClient(*clientConfig);

                util::CountDownLatch countDownLatch(1);
                DummyListenerClusterTest listener(countDownLatch);
                IMap<std::string, std::string> m = hazelcastClient.getMap<std::string, std::string>(
                        "testListenersWhenClusterDown");
                m.addEntryListener(listener, true);
                instance.shutdown();

                util::CountDownLatch lifecycleLatch(1);
                LclForClusterTest lifecycleListener(lifecycleLatch);
                hazelcastClient.addLifecycleListener(&lifecycleListener);

                HazelcastServer instance2(*g_srvFactory);
                ASSERT_TRUE(lifecycleLatch.await(120));
                // Let enough time for the client to re-register the failed listeners
                util::sleep(1);
                m.put("sample", "entry");
                ASSERT_TRUE(countDownLatch.await(60));
                ASSERT_TRUE(hazelcastClient.removeLifecycleListener(&lifecycleListener));
            }
Exemple #2
0
TEST(MapTest, canSetCellType) {
    IMap* map = new Map(IVector2D(10, 10));

    map->setCellType(IVector2D(0, 0), CellType::FOREST);

    ASSERT_EQ(CellType::FOREST, map->getCellType(IVector2D(0, 0)));
}
Exemple #3
0
TEST(MapTest, isBadCellTypeReturnsWhenIndexIsOutOfRange) {
    IMap* map = new Map(IVector2D(10, 10));

    EXPECT_EQ(CellType::BAD_TYPE, map->getCellType(IVector2D(10, 0)));
    EXPECT_EQ(CellType::BAD_TYPE, map->getCellType(IVector2D(0, 10)));
    EXPECT_EQ(CellType::BAD_TYPE, map->getCellType(IVector2D(10, 10)));
}
Exemple #4
0
TEST(MapTest, isBadIDReturnsWhenIndexIsOutOfRange) {
    IMap* map = new Map(IVector2D(10, 10));

    EXPECT_EQ(-1, map->getIndividualID(IVector2D(10, 0)));
    EXPECT_EQ(-1, map->getIndividualID(IVector2D(0, 10)));
    EXPECT_EQ(-1, map->getIndividualID(IVector2D(10, 10)));
}
            void ClientTxnMapTest::testKeySetAndValuesWithPredicates() {
                std::string name = "testKeysetAndValuesWithPredicates";
                IMap<Employee, Employee> map = client->getMap<Employee, Employee>(name);

                Employee emp1("abc-123-xvz", 34);
                Employee emp2("abc-123-xvz", 20);

                map.put(emp1, emp1);

                TransactionContext context = client->newTransactionContext();
                context.beginTransaction();

                TransactionalMap<Employee, Employee> txMap = context.getMap<Employee, Employee>(name);
                assertNull(txMap.put(emp2, emp2).get());

                assertEqual(2, (int)txMap.size());
                assertEqual(2, (int)txMap.keySet().size());
                query::SqlPredicate predicate("a = 10");
                assertEqual(0, (int)txMap.keySet(&predicate).size());
                assertEqual(0, (int)txMap.values(&predicate).size());
                predicate.setSql("a >= 10");
                assertEqual(2, (int)txMap.keySet(&predicate).size());
                assertEqual(2, (int)txMap.values(&predicate).size());

                context.commitTransaction();

                assertEqual(2, (int)map.size());
                assertEqual(2, (int)map.values().size());


            }
Exemple #6
0
TEST(MapTest, canSetIndividualID) {
    IMap* map = new Map(IVector2D(10, 10));

    map->setIndividualID(IVector2D(0, 0), 1);

    ASSERT_EQ(1, map->getIndividualID(IVector2D(0, 0)));
}
	inline bool canStepTo(Direction direction, const IMap &map) const{
		switch(direction){
			case Left:  return x > 0;
			case Right: return x < map.numCols() - 1;
			case Up:    return y < map.numRows() - 1;
			case Down:  return y > 0;
			default:    return false;
		}
	}
void RemoveLayerCommand::undo()
{
    ITourDuMondeDocument *doc = m_docContr->document();
    IMap* map = doc->map();

    for (QPair<int, AbstractLayer*>& layer : m_layersToRestore)
    {
        map->insertLayer(layer.first, layer.second);
        m_layersToRemove.push_back(layer.second);
    }
    m_layersToRestore.clear();
    map->refresh();
}
Exemple #9
0
IResult fib(int n) {
  if (n <= 0) return 0;
  if (n <= 1) return 1;

  auto p = fibICache.find(n);

  if (p == fibICache.end()) {
    IResult res = fib(n - 2) + fib(n - 1);

    p = fibICache.insert(p, IMap::value_type(n, res));
  }

  return (*p).second;
}
 LorenzPoincareMap ( int order, interval _sigma, interval _rho, interval _beta )
   : section("var:x,y,z;fun:z;"), //  the section is z=0
     vectorField("par:b,r,s;var:x,y,z;fun:s*(y-x),(r-z)*x-y,x*y-b*z;"), // here is the vector field
     solver(vectorField,order,0.1), // 0.1 is the time step, ignored since step control is turned on by default
     // MinusPlus means that the section is crossed with 'z' changing
     // sign from minus to plus Other acceptable values are PlusMinus
     // and None. The last means both directions are acceptable. This will probably have to be changed to None. 
     pm(solver,section,poincare::MinusPlus)  
                                 
 {
   // set parameter values a and b
   vectorField.setParameter("b",_beta);
   vectorField.setParameter("r",_rho);
   vectorField.setParameter("s",_sigma);
 }
void RemoveLayerCommand::redo()
{
    ITourDuMondeDocument *doc = m_docContr->document();
    IMap* map = doc->map();

    // TODO: group layers?
    for (AbstractLayer* layer : m_layersToRemove)
    {
        const int index = map->getLayerIndex(layer);
        map->takeLayer(layer);

        m_layersToRestore.push_back(QPair<int, AbstractLayer*>(index, layer));
    }
    m_layersToRemove.clear();
    map->refresh();
}
void	sfmlGraphicManager::print(const IMap &map)
{
    int     transX;
    int     transY;
    t_pos	pos;
    char	c;

    ((sf::RenderWindow *)_Window)->Clear(sf::Color::Black);
    if (_blockSize == 0)
    {
        if (WIDTH > HEIGHT)
            _blockSize = HEIGHT / map.getSize();
        else
            _blockSize = WIDTH / map.getSize();
    }
    transY = map.getSize() / 2;
    pos.y = 0;
    while (map.getPos(pos) != -1)
    {
      pos.x = 0;
      transX = map.getSize() / 2;
      while (map.getPos(pos) != -2)
        {
	  c = map.getPos(pos);
	  sf::Shape rectangle = sf::Shape::Rectangle(sf::Vector2f((WIDTH / 2) - (transX * _blockSize), (HEIGHT / 2) - (transY * _blockSize)), sf::Vector2f((WIDTH / 2) - (transX * _blockSize) + _blockSize, (HEIGHT / 2) - (transY * _blockSize) + _blockSize), sf::Color(255,255,255));
            //rectangle.setPosition((WIDTH / 2) - (transX * _blockSize), (HEIGHT / 2) - (transY * _blockSize));
	  switch (c)
            {
            case 'P':
            case '0':
            case 'G':
            case 'x': 
	    case '2':
	    case '#':
	      rectangle.SetColor(sf::Color(0,0,0));
	      break;
            case '1':
              rectangle.SetColor(sf::Color(0,0,255));
	      break;
            }
	  ((sf::RenderWindow *)_Window)->Draw(rectangle);
	  for (std::vector<std::pair<const char, sf::Image *>>::iterator itr = _texture.begin(); itr != _texture.end(); ++itr)
	    if (c == (*itr).first)
	      {
	  	sf::Sprite sprite;
		sprite.SetImage((*(*itr).second));
		sprite.SetPosition(sf::Vector2f((WIDTH / 2) - (transX * _blockSize), (HEIGHT / 2) - (transY * _blockSize)));
		sprite.Resize(sf::Vector2f(_blockSize, _blockSize));
		((sf::RenderWindow *)_Window)->Draw(sprite);
	      }
	  pos.x += 1;
	  transX -= 1;
        }
      pos.y += 1;
      transY -= 1;
    }
    ((sf::RenderWindow *)_Window)->Display();
}
 RosslerPoincareMap (int order, interval _a, interval _b)
   : section("var:x,y,z;fun:x;"), //  the section is x=0
     vectorField("par:a,b;var:x,y,z;fun:-(y+z),x+b*y,b+z*(x-a);"), // here is the vector field
     solver(vectorField,order,0.1), // 0.1 is the time step, ignored since step control is turned on by default
     pm(solver,section,poincare::MinusPlus)  // MinusPlus means that the section is crossed with 'x' changing sign from minus to plus
                                   // Other acceptable values are PlusMinus and None. The last means both directions are acceptable.
 {
   // set parameter values a and b
   vectorField.setParameter("a",_a);
   vectorField.setParameter("b",_b);
 }
	IMap<String> *PlayerBinder::_ParseKVToMap(const char *propertiesData) {
		KeyValues *keyValues = new KeyValues("Properties");
		keyValues->LoadFromBuffer("Properties", propertiesData);

		IMap<String> *properties = new Map<String>();

		KeyValues *subKey = keyValues->GetFirstSubKey();
				
		while(subKey != NULL) {
			const char *n = subKey->GetName();
			const char *v = subKey->GetString();
				
			properties->SetValue(n, v);

			subKey = subKey->GetNextKey();
		}

		keyValues->deleteThis();

		return properties;
	}
            void ClientTxnMapTest::testKeySetValues() {
                std::string name = "testKeySetValues";
                IMap<std::string, std::string> map = client->getMap<std::string, std::string>(name);
                map.put("key1", "value1");
                map.put("key2", "value2");

                TransactionContext context = client->newTransactionContext();
                context.beginTransaction();
                TransactionalMap<std::string, std::string> txMap = context.getMap<std::string, std::string>(name);
                assertNull(txMap.put("key3", "value3").get());


                assertEqual(3, (int)txMap.size());
                assertEqual(3, (int)txMap.keySet().size());
                assertEqual(3, (int)txMap.values().size());
                context.commitTransaction();

                assertEqual(3, (int)map.size());
                assertEqual(3, (int)map.keySet().size());
                assertEqual(3, (int)map.values().size());

            }
            void ClusterTest::testListenersWhenClusterDown() {
                HazelcastServer instance(hazelcastInstanceFactory);

                std::auto_ptr<ClientConfig> clientConfig(getConfig());
                clientConfig->setAttemptPeriod(1000 * 10).setConnectionAttemptLimit(100).setLogLevel(FINEST);
                HazelcastClient hazelcastClient(*clientConfig);

                util::CountDownLatch countDownLatch(1);
                DummyListenerClusterTest listener(countDownLatch);
                IMap<std::string, std::string> m = hazelcastClient.getMap<std::string, std::string>("testListenersWhenClusterDown");
                m.addEntryListener(listener, true);
                instance.shutdown();

                util::CountDownLatch lifecycleLatch(1);
                LclForClusterTest lifecycleListener(lifecycleLatch);
                hazelcastClient.addLifecycleListener(&lifecycleListener);

                HazelcastServer instance2(hazelcastInstanceFactory);
                assertTrue(lifecycleLatch.await(120), "Lifecycle latch await timed out!");
                m.put("sample", "entry");
                assertTrue(countDownLatch.await(60), "Await timed out !");
                assertTrue(hazelcastClient.removeLifecycleListener(&lifecycleListener), "Listener could not removed");
            }
Exemple #17
0
void Renderer::renderGround() {
	IMap* map = m_world->getMap();
	for (int x = -map->getSize(); x < map->getSize(); x++) {
		for (int y = -map->getSize(); y < map->getSize(); y++) {
			MapFieldType texId = map->getTypeForPos(x, y);
			glTranslated(x, y, 0);
			switch (texId) {
				case Grass:
					setMaterial(&grass);
					break;
				case Street:
					setMaterial(&street);
					break;
				case Sand:
					setMaterial(&sand);
					break;
				case Water:
					setMaterial(&water);
					break;
				default:
					setMaterial(&black);
					break;
			}
			glBegin(GL_QUADS);
			{
				glNormal3d(0, 0, 1);
				glVertex3f(0, 0, 0);
				glVertex3f(1, 0, 0);
				glVertex3f(1, 1, 0);
				glVertex3f(0, 1, 0);
			}
			glEnd();
			glTranslated(-x, -y, 0);
		}
	}
	glColor3ub(255, 255, 255);
}
Exemple #18
0
void CMapImages::OnMapLoad()
{
	IMap *pMap = Kernel()->RequestInterface<IMap>();

	// unload all textures
	for(int i = 0; i < m_Count; i++)
	{
		Graphics()->UnloadTexture(m_aTextures[i]);
		m_aTextures[i] = -1;
	}
	m_Count = 0;

	int Start;
	pMap->GetType(MAPITEMTYPE_IMAGE, &Start, &m_Count);

	// load new textures
	for(int i = 0; i < m_Count; i++)
	{
		m_aTextures[i] = 0;

		CMapItemImage *pImg = (CMapItemImage *)pMap->GetItem(Start+i, 0, 0);
		if(pImg->m_External || (pImg->m_Version > 1 && pImg->m_Format != CImageInfo::FORMAT_RGB && pImg->m_Format != CImageInfo::FORMAT_RGBA))
		{
			char Buf[256];
			char *pName = (char *)pMap->GetData(pImg->m_ImageName);
			str_format(Buf, sizeof(Buf), "mapres/%s.png", pName);
			m_aTextures[i] = Graphics()->LoadTexture(Buf, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
		}
		else
		{
			void *pData = pMap->GetData(pImg->m_ImageData);
			m_aTextures[i] = Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, pImg->m_Version == 1 ? CImageInfo::FORMAT_RGBA : pImg->m_Format, pData, CImageInfo::FORMAT_RGBA, 0);
			pMap->UnloadData(pImg->m_ImageData);
		}
	}
}
Exemple #19
0
int main(int argc, char **argv)
{
	printf("init\n");
	if( SDL_Init(SDL_INIT_VIDEO)<0 ) {
		printf("Init error: %s",SDL_GetError());
		exit(1);
	}
	atexit(SDL_Quit);
	SDL_Surface* _screen = SDL_SetVideoMode(640,480,32,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_ASYNCBLIT);
	EntMan* _entman = new EntMan();
	CController* _control = new CController();

	CTank* tank;

	for(int i=0;i<2;i++){
		tank = new CTank(480-i*320,360,_control->getState(i),.85);
		//tank->acc(6000,0);
		_entman->addEnt((IEnt*)tank);
	} 
	
	
//	IMap* map = new CMapSlope(0.4);
	IMap* map = new CMapHeight(640,1,1);
	for(double i=0;i<640;i++) map->set(i,480-60+10*sin(i*0.03));
//	for(int i=0;i<640;i++) ((CMapHeight*)map)->set(i,40);
//	CPointMass point1(1,300,20,-50,50);
//	CPointMass point2(1,340,20,0,0);
//	CSpring spring(point1,point2,4,1);

	
	
	double dt=1./60.;
	double* pene = new double[2];
	
	Uint32 frameEnd=SDL_GetTicks()-16;
	Uint32 frameStart;
	Uint32 frameTime;
	double accum=0;
	bool go=true;
	SDL_Event ev;
	while(go) {

		while( SDL_PollEvent(&ev) ) {
			if(ev.type==SDL_QUIT) go=false;
		}
		int mx, my;
		SDL_GetMouseState(&mx,&my);
		Uint8* keyState = SDL_GetKeyState(NULL);
		
		if(keyState[SDLK_ESCAPE]) go=false;
		_control->update(keyState);
		
		
		
		frameStart = SDL_GetTicks();
		frameTime = frameStart-frameEnd;
		//frameEnd = frameStart;
		

		
		
		accum+=frameTime;
		
		int stepCount=0;
		while(accum>0&&stepCount<40) {
			
			_entman->update(dt,map);
		
			accum-=dt*1000;
			stepCount++;
		}

		map->draw(_screen);
		_entman->draw(_screen);
	

		pene = map->penetration(mx,my);
		drawLineRel(_screen,mx,my,-pene[0],-pene[1]);
		
		SDL_Flip(_screen);
		frameEnd = frameStart;
		
		SDL_Delay(dt*1000-(frameEnd-frameStart));

		SDL_FillRect(_screen,NULL,SDL_MapRGB(_screen->format,70,40,130));
	}
	delete pene;
	delete map;
	
	delete _entman;
	delete _control;
	
	return 0;
}
Exemple #20
0
TEST(MapTest, byDefaultFirstCellHasNoIndividuals) {
    IMap* map = new Map(IVector2D(10, 10));

    ASSERT_EQ(0, map->getIndividualID(IVector2D(0, 0)));
}
void dumpIMap(const IMap& V, const char* s) { V.print(g_MSGFile, s, "d",  0, 4, true); }
Exemple #22
0
TEST(MapTest, byDefaultTypeOfFirstCellIsPlains) {
    IMap* map = new Map(IVector2D(10, 10));

    ASSERT_EQ(CellType::PLAINS, map->getCellType(IVector2D(0, 0)));
}
Exemple #23
0
TEST(MapTest, canCreateMapWithNonZeroSize) {
    IMap* map = new Map(IVector2D(10, 10));

    EXPECT_EQ(IVector2D(10, 10), map->getSize());
}
Exemple #24
0
TEST(MapTest, byDefaultMapHaveZeroSize) {
    IMap* map = new Map();

    EXPECT_EQ(IVector2D(0, 0), map->getSize());
}