patternMinor
My iPod is slower than my iPad
Viewed 0 times
ipadthanipodslower
Problem
Many of the variables in my 2D mining game were declared as constants like so:
DWConstants.h
This was all well and good for initial testing, but I soon found out that there were quite a few variables that I wanted to be able to adjust based on what device the game was running on. I thought about a couple approaches to this, and I decided on this one. The values of the variables are set based on the memory of the device. I would love to know what you think.
DWMemoryConstants.h
DWMemoryConstants.m
As always, I am open to any sort of feedback about the code.
DWConstants.h
static const int kBlockSpriteWidth = 64;
static const float kBufferFactor = 2.5;
static const int kMaxBlockDamage = 3;This was all well and good for initial testing, but I soon found out that there were quite a few variables that I wanted to be able to adjust based on what device the game was running on. I thought about a couple approaches to this, and I decided on this one. The values of the variables are set based on the memory of the device. I would love to know what you think.
DWMemoryConstants.h
#import
@interface DWMemoryConstants : NSObject
@property int startingChunks;
@property int chunkSize;
@property int chunksToGenerate;
@property float maxZoom;
@endDWMemoryConstants.m
#import "DWMemoryConstants.h"
@implementation DWMemoryConstants
-(instancetype) init {
self = [super init];
if (self) {
unsigned long long memorySize = [NSProcessInfo processInfo].physicalMemory;
unsigned long long memSize = memorySize/1000/1000;
if (memSize = 256 && memSize = 800 && memSize = 1800 && memSize = 2800) {
_startingChunks = 12;
_chunkSize = 30;
_chunksToGenerate = 10;
_maxZoom = 0.04;
}
}
return self;
}
@endAs always, I am open to any sort of feedback about the code.
Solution
I think using memory size is an interesting idea. You may want to define the values with an expression (e.g.
Old:
With my changes:
startingChunks = round(memSize / 600) * 2 + 8), rather than an else-if chain, tho if you want to target specific devices, an if-else chain is acceptable.Old:
if (memSize = 256 && memSize < 800) {
//ipod 5 is in this range
_startingChunks = 8;
_chunkSize = 16;
_chunksToGenerate = 4;
_maxZoom = 0.45;
}- Underscores are annoying, is there any reason you use them in those variable names? If it's supposed to denote constants, doesn't the name work well enough? It shouldn't be doubted that
chunkSize, for instance, won't change if you know how the app works. And if in a future update you want it to change, you could change it without renaming.
if (memSize = 256. So there's really no need to add that to theelse if.
With my changes:
if (memSize < 256) {
startingChunks = 0;
chunkSize = 0;
chunksToGenerate = 0;
maxZoom = 0.00;
} else if (memSize < 800) {
//ipod 5 is in this range
startingChunks = 8;
chunkSize = 16;
chunksToGenerate = 4;
maxZoom = 0.45;
}Code Snippets
if (memSize < 256) {
_startingChunks = 0;
_chunkSize = 0;
_chunksToGenerate = 0;
_maxZoom = 0.00;
} else if (memSize >= 256 && memSize < 800) {
//ipod 5 is in this range
_startingChunks = 8;
_chunkSize = 16;
_chunksToGenerate = 4;
_maxZoom = 0.45;
}if (memSize < 256) {
startingChunks = 0;
chunkSize = 0;
chunksToGenerate = 0;
maxZoom = 0.00;
} else if (memSize < 800) {
//ipod 5 is in this range
startingChunks = 8;
chunkSize = 16;
chunksToGenerate = 4;
maxZoom = 0.45;
}Context
StackExchange Code Review Q#67056, answer score: 3
Revisions (0)
No revisions yet.