-
Notifications
You must be signed in to change notification settings - Fork 35
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = [[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]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why red? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.