Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
xzzy
Mar 5, 2009

sevenflow posted:

The only issue with this is that you won't be able to really project before hand, you'll have to test on every frame. Which is fine, it's a really cheap operation.

Wouldn't that be a preferred design anyway? It saves a lot of re-writing if the game ever has to test for collisions against objects that are moving.

Adbot
ADBOT LOVES YOU

sevenflow
Jun 28, 2003
just watch it for a second
Yeah, I think it is in most cases. He wasn't entirely clear as to how he was using it, though, so I was just wondering if maybe he was doing pathfinding or something similar and wanted to pre-check if the path was feasible before the player ever moved. For a platformer or the like it's ideal.

You could also go with something like Box2D for collision detection, even if you're not using it for physics simulation. It has a lot of nice functionality built in for testing these types of things (eg. it'll let you project the path of an object and let you know all the objects it will collide with on the way.)

Yakattak
Dec 17, 2009

I am Grumpypuss
>:3

Bob Morales posted:

Is there any reason not to do stuff like puzzle games in just plain UIKit?

Not really. UIKit is fine for a simple puzzle game. I think goon made Scoops was made with UIKit mostly.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

Bob Morales posted:

Is there any reason not to do stuff like puzzle games in just plain UIKit?

Nope, if CoreAnimation is good enough then you can feel free. UIKit draws with OpenGL under the hood anyway.

LP0 ON FIRE
Jan 25, 2006

beep boop

sevenflow posted:

The only issue with this is that you won't be able to really project before hand, you'll have to test on every frame. Which is fine, it's a really cheap operation.

I don't understand why I'd need to test every frame? Can't I just use a for loop before the player starts moving? I'd much rather use timers in a lot of cases, but yeah I didn't know how much that would slow down things.

Here I do a test of where the rects would be by overriding the draw method in cocos2D:



There, they are 32 pixels apart from their centers, but I may want to do as little as 8 to get rid of those hard edges and make it more accurate. I might figure out a way to avoid redundant checking. But yes, this has all been very daunting and I think I'd just like to check per frame. This also means that anything else that needs to check for collision (such as enemies hitting walls) would need to check every frame.

xzzy posted:

Wouldn't that be a preferred design anyway? It saves a lot of re-writing if the game ever has to test for collisions against objects that are moving.

Exactly. Again the only thing I've been afraid of is retaining speed.

sevenflow posted:

You could also go with something like Box2D for collision detection, even if you're not using it for physics simulation. It has a lot of nice functionality built in for testing these types of things (eg. it'll let you project the path of an object and let you know all the objects it will collide with on the way.)

That's nice to know, but how much would it slow it down compared to checking per frame?

So I guess what I'd really like to get peoples opinions on is what should I use:

-A path of rects to precheck collision before movement
-Check collision per frame (I think I'd prefer this, but speed? Also could I get some idea of how this is done)
-Use Box 2D (Unnecessary?)

xzzy
Mar 5, 2009

NOG posted:

-A path of rects to precheck collision before movement
-Check collision per frame (I think I'd prefer this, but speed? Also could I get some idea of how this is done)
-Use Box 2D (Unnecessary?)

Pre-checking can get really expensive, as scene complexity rises, the check will have to spend more time testing everything. Runs the risk of getting to a point where a player clicking results in a perceptible drop in framerate before action resumes (if you've ever played Dwarf Fortress, this is one of the biggest performance hits in the game, entities picking their route before doing it).

Per frame checks are well-studied and there is a lot of discussion out there on how to optimize them. It is true that testing every single frame will increase render time, but you're spreading the workload over a span of several seconds.. which translates into a smoother performance with fewer spikes.

I don't really have an opinion on box2d, I've experimented with it and it seems able to handle a hundred or more physics objects without breaking a sweat, so I'm sure it would work, but on the other hand, you miss out on the educational aspect of doing your own collision.

LP0 ON FIRE
Jan 25, 2006

beep boop
Thanks. I'm going to see how a per-frame basis works out and how much I can push it.

Does anyone know if ccTime checks on a per frame? Even after looking it up on the Cocos2D site, I can't really find out much info about it.

Just calling this in init: [self schedule:@selector(update:)];

And this as a method

code:
- (void)update:(ccTime)dt {
	NSLog(@"test");
}

OHIO
Aug 15, 2005

touchin' algebra

NOG posted:

Thanks. I'm going to see how a per-frame basis works out and how much I can push it.

Does anyone know if ccTime checks on a per frame? Even after looking it up on the Cocos2D site, I can't really find out much info about it.

Just calling this in init: [self schedule:@selector(update:)];

And this as a method

code:

- (void)update:(ccTime)dt {
	NSLog(@"test");
}

The "dt" will be the time since the last call. So if you're updating position it should look like
code:
position = speed * dt;

LP0 ON FIRE
Jan 25, 2006

beep boop
So how can you have a method checked every frame?

edit: Also found a really extensive tutorial on box2D that I'm going to read up on.
http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone

LP0 ON FIRE fucked around with this message at 20:33 on Apr 15, 2011

OHIO
Aug 15, 2005

touchin' algebra

NOG posted:

So how can you have a method checked every frame?

edit: Also found a really extensive tutorial on box2D that I'm going to read up on.
http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone

Yeah that will be every frame, cocos2d will hook into CADisplayLink if it can.

Vizin
Sep 3, 2007

Bob Morales posted:

Is there any reason not to do stuff like puzzle games in just plain UIKit?

I made a simple puzzle game in UIKit and it performed just fine on even the original iPhone. It had an 8x9 grid of images, with objects users could move around, and basic animations. All of the objects were simple UIImageViews.

Small White Dragon
Nov 23, 2007

No relation.
Hey Clang friends:

I'm hearing about Clang LLVM 3.0, but the current version is 2.9 and I don't see any info on 3.0. Given it's an open source project, can you talk about (or point to) some info about 3.0?

AlwaysWetID34
Mar 8, 2003
*shrug*
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

AlwaysWetID34 fucked around with this message at 17:33 on Jan 18, 2019

dizzywhip
Dec 23, 2005

Try initWithFormat: instead of initWithString:. The former works like printf, which seems to be what you want, and the latter just takes in a single string argument. Check out the documentation for details:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

Small White Dragon posted:

Hey Clang friends:

I'm hearing about Clang LLVM 3.0, but the current version is 2.9 and I don't see any info on 3.0. Given it's an open source project, can you talk about (or point to) some info about 3.0?


I haven't seen anything. You can check the Clang mailing list archive but I'm not sure that they've really discussed it beyond 100% C++'0x support.

I've been curious myself about what is coming up for Objective-C but haven't heard anything.

AlwaysWetID34
Mar 8, 2003
*shrug*
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

AlwaysWetID34 fucked around with this message at 17:33 on Jan 18, 2019

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!
Using Xcode 4, is there a keyboard shortcut to switch between the main editor and the assistant editor? The "Move Focus To Editor..." command would work and be only slightly annoying for requiring two keystrokes to switch, but I have to hit a different keystroke to switch to each editor, and I have to think about it every drat time and it's starting to drive me insane.

monkey
Jan 20, 2004

by zen death robot
Yams Fan
I'm working on my first iPhone game and have come up against a bit of a showstopper. I need a scrabble dictionary in memory to do some very fast spellchecking, hopefully checking about 100 words vs 250,000+ words in a single frame.

If I hardcode the whole thing in XCode 4 as a single massive line of code like this:

wordList = [NSArray arrayWithObjects:@"aa", @"aah", @"aahed", ... @"zyzzyvas",nil];

The compiler just hangs. It doesn't crash, but it will sit there and chew on it for 30 minutes until I cancel it.

In the past, I've written the same thing, both in C and in flash's actionscript without this sort of problem, so I'm just wondering if anyone can shed some light on any practical limits of XCode, the iOS GCC compiler and iOS itself, or maybe suggest a workaround to my crappy method.

Also any suggestions on the best way to hold and process that amount of data in Objective C (and on an iPhone) would be good. I plan to just do a binary search on it for speed. But I have no idea how an NSString 'compare' will rate for speed and overhead against a simple C style string comparison like this:

if( (char*)myWord < (char*)WordList[index] )

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

monkey posted:

I need a scrabble dictionary in memory to do some very fast spellchecking, hopefully checking about 100 words vs 250,000+ words in a single frame.

First step is to use an NSSet, not an NSArray, because you don't care about order. But when you run into the same problem, check out tries, their memory-saving counterpart radix trees, and their goofy cousin dawgs. There's also plenty more where those come from, so poke around.

The idea is to use a data structure whose lookups take time proportional to the length of the word you're checking, as opposed to time proportional to the number of words in your dictionary. If filling this data structure takes too long on the device, you can do it beforehand and dump it to a file, to be loaded on the device when needed.

Comedy option: let ragel do the work for you.

NotShadowStar
Sep 20, 2000

monkey posted:

If I hardcode the whole thing in XCode 4 as a single massive line of code like this:

Errrrgh. A 250k element NSDictionary?

Try something like this instead, it explains the theory and links to other implementations, including C. By Peter Norvig, Google Wizard.

Or you could link to aspell

NotShadowStar fucked around with this message at 12:42 on Apr 17, 2011

monkey
Jan 20, 2004

by zen death robot
Yams Fan

pokeyman posted:

First step is to use an NSSet, not an NSArray, because you don't care about order. But when you run into the same problem, check out tries, their memory-saving counterpart radix trees, and their goofy cousin dawgs. There's also plenty more where those come from, so poke around.

The idea is to use a data structure whose lookups take time proportional to the length of the word you're checking, as opposed to time proportional to the number of words in your dictionary. If filling this data structure takes too long on the device, you can do it beforehand and dump it to a file, to be loaded on the device when needed.

Comedy option: let ragel do the work for you.

Thanks! Not the answer I was looking for, but very interesting. I found that a plain binary search was fast enough, it's more the reason I need the whole thing in RAM all the time. When I say "fast enough"... a prototype version written in flash and running on an android phone is able to parse 200+ words without a hitch at 30FPS. I'll implement it as a binary search first (already wrote that code years ago) and if it's not quick enough, I'll definitely look into setting up a DAWG. On the surface, my guesstimation is that DAWG may shave off about 30% of the operations, but take about 3 times the RAM. This is only because a lot of the strings I have to check will be 9 letters long.

Are you saying NSSet containsObject is faster than a binary search in an ordered array? I'm not familiar with NSSet, but that seems pretty amazing.

Anyway the answer I really needed was "Load it from an external file, you dolt"

Now I'm looking into how I'm supposed to do that. Wondering whether the convenience of arrayWithContentsOfFile is worth the XML bloat, and whether I can even use fopen and fgets on iOS.

Paradoxish
Dec 19, 2003

Will you stop going crazy in there?
Does anyone have any recommendations for a decent iOS or cross-platform vector math library to use with OpenGL? I've been rolling my own linear algebra functions, but the project I'm working on is getting larger and I'd rather use a well-tested third-party library. Most of the 3d programming I've done on PCs has been in DirectX, so I'm used to having the D3DX math functions rely on.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

monkey posted:

I'm working on my first iPhone game and have come up against a bit of a showstopper. I need a scrabble dictionary in memory to do some very fast spellchecking, hopefully checking about 100 words vs 250,000+ words in a single frame.

Stackoverflow gives a suggestion of using a form of compression (since you've only got 26 letters, no need to use a byte for each character) and cramming each of the 250k words in to a 64-bit value, ending up at 2mb.

http://stackoverflow.com/questions/2276641/way-to-store-a-large-dictionary-with-low-memory-footprint-fast-lookups-on-andr

monkey
Jan 20, 2004

by zen death robot
Yams Fan
^^ oh, that 5 bit compression is nice, I'll use that.

I got it working... The wordlist now loads as a NSString from a CSV file, the string is split into an NSArray, the NSArray converted to a NSSet. There's a hasWord method, [dict hasWord:@"TESTING"] returns true, [dict hasWord:"FKJHDSA"] returns false Everything is good.

edit: and it's fixed.

monkey fucked around with this message at 20:01 on Apr 17, 2011

Small White Dragon
Nov 23, 2007

No relation.

monkey posted:

and whether I can even use fopen and fgets on iOS.
Absolutely you can.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

monkey posted:

Are you saying NSSet containsObject is faster than a binary search in an ordered array? I'm not familiar with NSSet, but that seems pretty amazing.

I don't know if you're familiar with big-O notation, but if you are, binary search is O(log n) with n the number of words while a hash table (NSSet) is O(1) amortized.

If you're unfamiliar with big-O notation, learn it, it's useful, but the translated version of the above is binary search takes longer when you have more words, while a hash table doesn't.

edit:

Small White Dragon posted:

Absolutely you can.

http://www.youtube.com/watch?v=q73MjnazIfg#t=0m23s

pokeyman fucked around with this message at 22:23 on Apr 17, 2011

monkey
Jan 20, 2004

by zen death robot
Yams Fan

pokeyman posted:

I don't know if you're familiar with big-O notation...

Familiar enough to realise it's not O(exp n) so there's not much speed difference between 2,000 and 200,000 words. Would NSSet be practical to store nothing but long ints like in the stackoverflow link Bob Morales posted? I mean practical in terms of the memory footprint and any memory thrashing it may have, compared to just 1 static long int per word?

I'm working on the other end of the search at the moment, and NSStrings are giving me a bit of grief with their handling of individual characters. I'm coming from Actionscript where "searchString+=charArray[x][y];" is valid syntax. It may turn out that converting to long ints will be a lot faster to stitch the searched words together out of a 2D array. I'll benchmark the two search methods anyway, since they're both written now.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

monkey posted:

Familiar enough to realise it's not O(exp n) so there's not much speed difference between 2,000 and 200,000 words. Would NSSet be practical to store nothing but long ints like in the stackoverflow link Bob Morales posted? I mean practical in terms of the memory footprint and any memory thrashing it may have, compared to just 1 static long int per word?

Foundation collections are a pain to use with ints because you have to keep boxing/unboxing them. I'd probably just find/write some C hash table (or use CFSet if you're really partial to Apple libraries).

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Beginner question:

Let's say you're making a falling blocks game, using UIKit. For a 10 square by 10 square game field, would you make an array of UIImageViews, or would you just make an array of a 'block' struct/objects?
code:
UIImageView *gameGrid[10][10];
vs
code:
struct
{
int solid, int color;
} block;

block *gameGrid[10][10];
(ignore the probably incorrect C syntax)

If I used the second way, would I just use a method like drawAtPoint to draw the bitmap for the block for each cell in the gameGrid? Let's say I'd have < 20 images total, some for different colors of blocks and then maybe 'jewels' or another piece of each color.

Would I just keep the UIImageViews off screen or hidden, or what in that case?

OHIO
Aug 15, 2005

touchin' algebra

Bob Morales posted:

Beginner question:

Let's say you're making a falling blocks game, using UIKit. For a 10 square by 10 square game field, would you make an array of UIImageViews, or would you just make an array of a 'block' struct/objects?


For UIKit I'd use UIImageView, because it's so easy and you can tap into sweet UIView animations.

However if you're going to have a ton of objects on the screen moving around and you want to have accurate positional info about them you might want to use OpenGL (cocos2d is pretty great). It's more helpful for "real-time" games. (as opposed to turn-based)

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Bob Morales posted:

Let's say you're making a falling blocks game, using UIKit. For a 10 square by 10 square game field, would you make an array of UIImageViews, or would you just make an array of a 'block' struct/objects?
code:
UIImageView *gameGrid[10][10];
vs
code:
struct
{
int solid, int color;
} block;

block *gameGrid[10][10];
(ignore the probably incorrect C syntax)

The difference here is in the first case you're combining a model and a view, whereas in the second you're separating the two. I'd recommend the second; I find this separation easier to do from the start than later on, and you inevitably need to do it.

quote:

If I used the second way, would I just use a method like drawAtPoint to draw the bitmap for the block for each cell in the gameGrid? Let's say I'd have < 20 images total, some for different colors of blocks and then maybe 'jewels' or another piece of each color.

Would I just keep the UIImageViews off screen or hidden, or what in that case?

You could use a bunch of UIImageViews, or just use UIImage's -drawAtPoint: or -drawInRect:. Maybe wrap this up in a UIView subclass, so you can just tell your custom view -drawBlock:atX:y: in your view controller.

Small White Dragon
Nov 23, 2007

No relation.
Hey, how do I compile a single file with a different compiler in Xcode 4?

I have one C++ file that makes use of variable-size new[]'s, and this bombs on ARMv6 devices with Clang.

Unfortunately, most of the project makes use of Objective C features only available in Clang.

nullfox
Aug 19, 2008
I am in the process of writing a new iPhone app that will be heavily dependent on the API and will have a large number of API calls coming in and out.

How do you guys usually structure your API client libs in an iPhone app? I thought about having a base API request object and sub-classing them for each API method, but depending on the controller that would be implementing them, that would be alot of seperate delegates to tie in to each class.

Another one I saw was supplying a selector which I've seen ASIHTTPRequest use as well as ShareKit. They let you supply a "finished" selector and looks for that in the class defined as the delegate.

[delegate performSelector:finishedSelector withObject:data];

Any tips/suggestions, etc?

nullfox fucked around with this message at 20:33 on Apr 18, 2011

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

WildFoxMedia posted:

Any tips/suggestions, etc?

I'm not sure I entirely understand your question, so apologies if this is useless.

If you're targeting iOS 4.0+, have your API library take blocks as completion handlers.

code:
[self.apiHandler doSomething:hello completion:^(id response) {
  self.label.text = response;
}];
If you need multiple completion handlers for the same action (like 1 to N), consider using key-value observing or a notification center.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice
You can also just take a list of blocks. But I second the motion on blocks - it is much closer to writing "normal" code and really easy to use.

Generally you can just have your API class expose the methods that take certain parameters and run onSuccess and onError blocks depending on the situation. If you have more advanced needs you can define a protocol so that you could have different underlying APIs or a simulator. The onComplete can pass any number of objects into the block when it runs.

Personally I don't care for having a bunch of different Request/Response objects for each operation but some people do it that way. It just seems like a lot of boilerplate to wrap and unwrap the parameters.

Just don't fall into the trap of thinking that because you didn't have to write new methods or re compile that you are doing a good thing. I've known too many people that think having an ultra-flexible interface or doing stuff in SQL stored procs are great because hey - changes without a new build! Until I remind them that those are changes that receive no testing or validation before deploying to production.... So instead of catching the bugs at compile time and re-running unit tests, they decided to let customers find the bugs in the field.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Ender.uNF posted:

You can also just take a list of blocks.

Or maintain one. [thinger onSuccess:^(id result) { ... }] adds the block to the array of success handlers, all of which are called on the success event. Like an EventEmitter. That'd be handy to have for Foundation actually...

Ender.uNF posted:

Just don't fall into the trap of thinking that because you didn't have to write new methods or re compile that you are doing a good thing. I've known too many people that think having an ultra-flexible interface or doing stuff in SQL stored procs are great because hey - changes without a new build!

Sounds like a case of You Ain't Gonna Need It. Don't code anything you're not using right now. Don't extract code into its own framework/project unless you're actually using it from more than one place. Don't add features you aren't using or testing constantly.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

pokeyman posted:

Or maintain one. [thinger onSuccess:^(id result) { ... }] adds the block to the array of success handlers, all of which are called on the success event. Like an EventEmitter. That'd be handy to have for Foundation actually...

Oh coming from C#, a proper event handling system with real language support would be fantastic, but they have already moved beyond next-next gen. LINQ/PLINQ is awesome and the IObservable stuff makes composing event handlers really cool (and solves the unhook problem too). But the real magic is the async stuff that is coming next. It makes closures look positively ancient by comparison. You literally write code that looks and works just like regular old synchronous code but gets turned into async calls with completion and error handlers by the compiler.

C# is turning into the best parts of C, Java, dynamic languages like Python, and functional programming... But without the glacial pace, infighting, and 'sperging architecture astronauts that tend to dominate projects like GCC or Java 1.7


Not that I'm abandoning Objective-C by any means!

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!



^^ What's that toolbar or whatever called with the arrows on it? I don't see it in my books, I want it.

Edit: gently caress nevermind, it's just a black toolbar.

Bob Morales fucked around with this message at 03:20 on Apr 19, 2011

OHIO
Aug 15, 2005

touchin' algebra
Tapjoy's going down (maybe), if you don't know about it, it's like those "sign up for these free trial offers to get a new iPod!"

http://www.tuaw.com/2011/04/19/apple-banning-pay-per-install-apps-from-the-app-store-says-tapjo/

I'm glad I avoided that bullshit, do anyone of you have any inside info about this?

OHIO fucked around with this message at 16:47 on Apr 19, 2011

Adbot
ADBOT LOVES YOU

LP0 ON FIRE
Jan 25, 2006

beep boop
In Flash, you can normalize a velocity by using this: vel.normalize(speed). But in Objective C or Cocos2d, what is built in? I know of ccpNormalize(vel), but I don't understand how I can make it work like the Flash one. I guess if I knew more about normalization I'd just do the math, but is there anything built in?

edit: I get it now I think according to this http://www.cocos2d-iphone.org/forum/topic/759

LP0 ON FIRE fucked around with this message at 20:34 on Apr 19, 2011

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply