示例#1
0
void RegionLoad::UpdateRegions()
{
	//Define all regions actors

	//Reset axis (Solve the bug "Game behavior differ based on editor grid position when uses regions", ALPHA_1_1_4.ged)
	int xAxisAnt, yAxisAnt;
	double scaleAnt;
	Axis *pAxis = GameControl::Get()->GetAxis();

	scaleAnt = pAxis->getScale();	
	xAxisAnt = pAxis->getImage()->X();
	yAxisAnt = pAxis->getImage()->Y();

	pAxis->SetScale(1.0);
	pAxis->SetPos(0, 0);
	pAxis->getImage()->Invalidate();

	//Define actors
	MapRegionsIterator it(regions);
	RegionLoad *pRegion;
	for( it.Begin(); !it.Done(); it.Next() )
	{
		pRegion = *it.Key();
		pRegion->DefineActors();
	}

	SetDefaultRegionView();

	//Restore axis (Solve the bug "Game behavior differ based on editor grid position when uses regions", ALPHA_1_1_4.ged)
	pAxis->SetScale(scaleAnt);
	pAxis->SetPos(xAxisAnt, yAxisAnt);	
	pAxis->getImage()->Invalidate();
	
}
示例#2
0
void RegionLoad::UpdateView()
{
	/*
	Tests the intersection of all regions with the view (if moved) 
	Call CreateActors of the areas that began to intercept and    
	DestroyActors of the areas that are not more intercepting.
	*/
	
	//The coordinates changes solve the bug in activation-problem_view_parent.ged
	//(don't load left region)

	//Make sure view don't will shake
	KrImage *pImageView = GameControl::Get()->GetViewActor()->getImage();
	Axis *pAxis = GameControl::Get()->GetAxis();

	if(pImageView->IsInvalid(true)) 
	{
		//Solve the alpha14.ged bug
		pImageView->CalcCompositeTransform();
		engine->Tree()->Walk(pImageView, true, true);
	}
	else
	{
		pImageView->CalcTransform();
	}

	//Get view bounds
	KrRect rectView = pImageView->Bounds(), viewPos;

	//Get view in screen and axis coordinates
	KrVector2T< GlFixed > screen, axis;
	pImageView->ObjectToScreen(0, 0, &screen);
	pAxis->getImage()->ScreenToObject( screen.x.ToInt(), screen.y.ToInt(), &axis );

	//Make sure rect is (0, 0, ...)
	rectView.Translate(-rectView.xmin, -rectView.ymin);

	//Translate to correct position
	rectView.Translate(axis.x.ToInt(), axis.y.ToInt());


	//Solve the bug: "PocketPC don't load checkers.ged"
	viewPos.Set(rectView.xmin, rectView.ymin, 
				//zeroViewPos.x.ToInt(), zeroViewPos.y.ToInt(),
				0, 0);

	

	if(viewPos != viewPosAnt)
	{		
		MapRegions createdRegions, destroyedRegions;

/*#ifdef DEBUG
		GLOUTPUT( " View pos: (%ld, %ld)\n",  rectView.xmin, rectView.ymin);
#endif*/

		MapRegionsIterator it(regions);
		RegionLoad *pRegion;
		for( it.Begin(); !it.Done(); it.Next() )
		{
			pRegion = *it.Key();

			pRegion->getImage()->CalcTransform();
			KrRect rectRegion = pRegion->getImage()->Bounds();
			rectRegion.Translate(-rectRegion.xmin, -rectRegion.ymin);

			//To axis coordinate
			pRegion->getImage()->ObjectToScreen(0, 0, &screen);
			pAxis->getImage()->ScreenToObject( screen.x.ToInt(), screen.y.ToInt(), &axis );
			rectRegion.Translate(axis.x.ToInt()*pAxis->getScale(), axis.y.ToInt()*pAxis->getScale());

			//View and region in axis coordinates

			if(rectView.Intersect(rectRegion))
			{
				if(!pRegion->bRegionInView)
				{
					createdRegions.Add(pRegion, 1);
				}				
			}
			else
			{
				if(pRegion->bRegionInView)
				{
					destroyedRegions.Add(pRegion, 1);				
				}
			}
		}

		//Destroy actors from regions outside the view
		//Solve the Move to Region.ged when add the 'sad' actor to two default regions 
		//(some times)

		MapRegionsIterator it1(destroyedRegions);
		
		for(it1.Begin(); !it1.Done(); it1.Next())
		{
			pRegion = *it1.Key();
			
			pRegion->DestroyActors();
			if(defaultRegion == pRegion)
				InvalidateDefaultRegion();
		}

		//Call OnCreate after destroy old actors
		//Solve the Move to Region 2.ged actor move to a wrong position
		MapRegionsIterator it2(createdRegions);
		
		for(it2.Begin(); !it2.Done(); it2.Next())
		{
			pRegion = *it2.Key();			
			RegionLoad *pOldDefaultRegion = defaultRegion;
			SetDefaultRegion(pRegion);
			
			pRegion->CreateActors();
					
			RemoveCommonActorsFromOldDefaultRegion(pOldDefaultRegion);
		}
		
		viewPosAnt = viewPos;
	}






}