Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory/Cpu improvement #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ARKit Example/Classes/ARKit/ARKitEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ - (CGPoint)pointInView:(UIView *)realityView forCoordinate:(ARGeoCoordinate *)co
}

- (void)updateLocations:(NSTimer *)timer {
[radar updatePoints:centerCoordinate];
[radar updatePoints:centerCoordinate reloadData:NO];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is never invoked with YES then, I'd remove the new argument.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reloaddata wont be called here, but if you want to call it manually you could call it somewhere else from superview on data changes without reallocating everything.


if (!ar_coordinateViews || ar_coordinateViews.count == 0) {
return;
Expand Down
2 changes: 1 addition & 1 deletion ARKit Example/Classes/ARKit/View/RadarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

- (id)initAtPoint:(CGPoint)middlePoint;

- (void) updatePoints:(ARGeoCoordinate *)centerCoord;
- (void)updatePoints:(ARGeoCoordinate *)centerCoord reloadData:(BOOL)reloadData;

@end
76 changes: 49 additions & 27 deletions ARKit Example/Classes/ARKit/View/RadarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,55 @@ - (id)initAtPoint:(CGPoint)middlePoint {
return self;
}

- (void) updatePoints:(ARGeoCoordinate *)centerCoord {
double centerAzimuth = centerCoord.azimuth + M_PI / 2;
if (centerAzimuth < 0.0) {
centerAzimuth = 2 * M_PI + centerAzimuth;
}

UIImage *dot = [UIImage imageNamed:@"radar_dot.png"];

for (UIView *sub in dotsView.subviews) {
[sub removeFromSuperview];
}

for (ARGeoCoordinate *coord in points) {
double coordAzimuth = coord.azimuth - centerAzimuth;
if (coordAzimuth < 0.0) {
coordAzimuth = 2 * M_PI + coordAzimuth;
}
CGPoint pt;

pt.x = dotsView.center.x + cos(coordAzimuth) * coord.radialDistance * self.frame.size.width / (2 * farthest);
pt.y = dotsView.center.y + sin(coordAzimuth) * coord.radialDistance * self.frame.size.height / (2 * farthest);

UIImageView *point = [[UIImageView alloc] initWithImage:dot];
point.center = pt;

[dotsView addSubview:point];
}
- (void)updatePoints:(ARGeoCoordinate *)centerCoord reloadData:(BOOL)reloadData {

double centerAzimuth = centerCoord.azimuth + M_PI / 2;

if (centerAzimuth < 0.0f) {
centerAzimuth = 2 * M_PI + centerAzimuth;
}

// Only remove subviews if reloading the data with new points
if (reloadData) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data will never be reloaded so remove this bit. Instead I'd check somehow that if this is the first call (i.e., no dots in the dotsView), then dot views have to be created.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point was for compatibility if you want to invoke reloaddata from superview without reallocating the entire radarview from beginning, for example you change positions and want to change the number of points.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is needed at some point then it will be added. For now I'd rather keep it the simplest. :)

for (UIView *sub in dotsView.subviews) {
[sub removeFromSuperview];
}
}

// Keep correct count on object index in loop
NSInteger count = 0;

for (ARGeoCoordinate *coord in points) {

double coordAzimuth = coord.azimuth - centerAzimuth;

if (coordAzimuth < 0.0f) {
coordAzimuth = 2 * M_PI + coordAzimuth;
}

CGPoint pt;

pt.x = dotsView.center.x + cos(coordAzimuth) * coord.radialDistance * self.frame.size.width / (2 * farthest);
pt.y = dotsView.center.y + sin(coordAzimuth) * coord.radialDistance * self.frame.size.height / (2 * farthest);

UIImageView *point;

// Only create new imageviews if reloaddata or initial load
if (points.count != dotsView.subviews.count) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All dot views will already be created (from line 40), so we just need to point = [dotsView.subviews objectAtIndex:count]; here.


point = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"radar_dot.png"]];
[dotsView addSubview:point];
}
// Otherwise just change position on current loaded imageviews
else {
point = [dotsView.subviews objectAtIndex:count];
}

point.tintColor = [UIColor redColor];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why red?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to clean that part , it was more of an indicator if you want to change the standard color of the image.

point.center = pt;

count += 1;
}
}

@end