Parsing from a string to something faster?
I have a nice little class that loads in all .pngs files named 'arbitrary_name_<n>.png' in my art directory (where <n> is a value).
It stores them in a dictionary so that I can do things like this:
All is well and good... ish.
But this dictionary lookup seems a bit... well... high level and expensive. I'm loathe to replicate data if I can avoid it, so I don't want to hand-create a bunch of enums which map one-to-one against my files.
I've been considering using my graphical processing script (in python) to spit out a nice enums.h file in C format.
Anyone else doing anything cleverer?
It stores them in a dictionary so that I can do things like this:
Code:
- (void) drawSpriteToBuffer: (GLfloat *) buffer WithSpriteName: (NSString *) graphic_name;
[self drawSpriteToBuffer: buffer WithSpriteName: @"mr_flibble"];All is well and good... ish.
But this dictionary lookup seems a bit... well... high level and expensive. I'm loathe to replicate data if I can avoid it, so I don't want to hand-create a bunch of enums which map one-to-one against my files.
I've been considering using my graphical processing script (in python) to spit out a nice enums.h file in C format.
Anyone else doing anything cleverer?
Dictionary lookups ought to be pretty quick. Have you profiled with Shark and had it show you that this is a hot spot in your code?
ThemsAllTook Wrote:Dictionary lookups ought to be pretty quick. Have you profiled with Shark and had it show you that this is a hot spot in your code?
Not sharked this yet; the root of all this is something I chose not to explain as I thought it might make my initial question far too confusing. It seems like getting a text file to result in code-readable information would be quite useful. Perhaps I'm getting ahead of myself and optimising too early... it's been known to happen.
Madrayken Wrote:Not sharked this yet; the root of all this is something I chose not to explain as I thought it might make my initial question far too confusing. It seems like getting a text file to result in code-readable information would be quite useful. Perhaps I'm getting ahead of myself and optimising too early... it's been known to happen.
Definitely profile it before you worry about how fast a dictionary lookup is - you may be surprised. And don't worry about optimizing at all until all major features are in place - there is no point at all in hand-tightening code that you may throw away in a month or a week. That's time wasted!
-- Available Now: Dead Panic, a casual zombie shooter!
-- Development Blog: How to make a game under $1k
-- Twitter: xsmasher
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| formatting value in a string | sefiroths | 3 | 3,525 |
Dec 12, 2011 02:41 AM Last Post: sefiroths |
|
| Getting a value from a String | Megamac04 | 5 | 3,321 |
Jan 31, 2010 04:23 PM Last Post: smasher |
|
| Is -fconstant-string-class broken under the XCode/Next runtime | Justin Brimm | 17 | 6,699 |
Jun 12, 2008 01:04 PM Last Post: Justin Brimm |
|
| string to interger comparison? | dareuhl | 8 | 3,864 |
May 22, 2008 05:44 PM Last Post: OneSadCookie |
|
| OH GAWD! Text parsing in cocoa?!?!? | hypnotx | 6 | 3,924 |
Jul 5, 2007 12:57 PM Last Post: SethWillits |
|

