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(), axis.y.ToInt()); //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; } }
void RegionLoad::DefineActors() { //Creates a list with actors that intercept the region regionActors.Clear(); KrVector2T< GlFixed > screen, axis; Axis *pAxis = GameControl::Get()->GetAxis(); //Get region bounds (Solve the bug "Game behavior differ based on editor grid position when uses regions", ALPHA_1_1_4.ged) getImage()->CalcTransform(); KrRect rectRegion = getImage()->Bounds(); rectRegion.Translate(-rectRegion.xmin, -rectRegion.ymin); //To axis coordinate (Solve the bug "Game behavior differ based on editor grid position when uses regions", ALPHA_1_1_4.ged) getImage()->ObjectToScreen(0, 0, &screen); pAxis->getImage()->ScreenToObject( screen.x.ToInt(), screen.y.ToInt(), &axis ); rectRegion.Translate(axis.x.ToInt(), axis.y.ToInt()); MapActorIterator it(mapActors); for(it.Begin(); !it.Done(); it.Next()) { ListActor *listActor = it.Value(); for(int il = 0; il < listActor->Count(); il++) { Actor *actor = (*listActor)[il]; if( actor->EditMode() && !actor->isRegion() && !actor->isView() && actor != pAxis ) { //Get actor bounds (Solve the bug "Game behavior differ based on editor grid position when uses regions", ALPHA_1_1_4.ged, abuse2.ged) actor->getImage()->CalcCompositeTransform(); KrRect rectActor = actor->Bounds(); if(actor->getTextActor() && !rectActor.IsValid()) { //Solve the bug "Text actors aren't load after use the LoadGame function without Activation Regions" engine->Tree()->Walk(actor->getImage(), true, true); rectActor = actor->Bounds(); } if(actor->getTile() && !rectActor.IsValid()) { //Solve the bug "Text actors aren't load after use the LoadGame function without Activation Regions" engine->Tree()->Walk(actor->getImage(), true, true); rectActor = actor->Bounds(); } rectActor.Translate(-rectActor.xmin, -rectActor.ymin); //To axis coordinate (Solve the bug "Game behavior differ based on editor grid position when uses regions", ALPHA_1_1_4.ged, abuse2.ged) actor->getImage()->ObjectToScreen(0, 0, &screen); pAxis->getImage()->ScreenToObject( screen.x.ToInt(), screen.y.ToInt(), &axis ); rectActor.Translate(axis.x.ToInt(), axis.y.ToInt()); if(rectActor.IsValid() && rectRegion.Intersect(rectActor)) { regionActors.Add(actor->getCloneName(), 1); } } } } viewPosAnt.Set(-123, 456, 0, 0); bRegionInView = false; }