CoreData, Vectors, and relationships

Nibbie
Posts: 3
Joined: 2008.11
Post: #1
Hi all,

I'm having some issues in my on-again off-again project I'm hoping someone here can help me with.

The basic gist is that I've got an OpenGL project that uses a gameObject class to create enemies & NPCs. The class has a number of functions, as well as properties such as name, health, and position (which is an instance of a custom glVector class).

Right now I'm parsing this data from an XML file, but I haven't even looked into writing the data back into the file, and as I've done very little actual game logic programming yet (mostly been focusing on getting the camera working), I've decided to take the leap and re-implement the thing using CoreData.

I've also decided, because I hate myself and also because every tutorial I've found uses IB2.0, to code it programmatically.

You can probably guess that I've run into a few problems.

Basically: what's the best way to re-implement a vector class using CoreData? Right now I've got a craftEntity object, which contains the unit's name and health, and my idea is to create a vectorEntity object with three NSNumbers for the axes, and create a relationship so that craftEntity's position can be handled using a vectorEntity. I haven't been able to find any resources on declaring a relationship programmatically, however, or any suggestion if it's the right / best thing to do.

I'm at work right now, so I don't have my laptop handy for code samples or error reports, but if anyone has any general advice / suggestions I'd really appreciate them.

Thanks!
Quote this message in a reply
Member
Posts: 24
Joined: 2008.02
Post: #2
What are you trying to do by writing information back into a file? If it's for saving a game, you could put the player's data into a dictionary and save it as a plist. If not, then I need to research core data some more, as I have not done anything more than basic stuff with it.
Quote this message in a reply
Member
Posts: 283
Joined: 2006.05
Post: #3
I've never tried to set up a Core Data Managed Object Model programatically. You create them in Xcode, not Interface Builder, and it has hardly changed since Core Data's introduction, so any tutorials you find will still be valid. The only thing IB is used for is when you drag a managed object into a view to create a test interface, and that hasn't changed either.

It's true that you could probably use plists, but Core Data is really stable, more forgiving and has features like undo management in case you want that sort of thing. Definitely worth trying out.

As for your actual question, I don't know. The documentation has a section called "Non-Standard Persistent Attributes" which describes one way to go. Your idea of having a vector entity would also work but you'd have to use one-way relationships which aren't recommended in the docs. I'd be tempted to just give your craftEntity three extra NSNumber attributes.
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2008.11
Post: #4
Quote:You create them in Xcode, not Interface Builder, and it has hardly changed since Core Data's introduction, so any tutorials you find will still be valid.
You're right - I'm not sure what I was thinking there. The problem I'm facing is that all the guides I've found are about starting a coredata project from scratch, whereas I'm trying to shoehorn it into an application. Are there any resources as far as that would go?

Quote: I'd be tempted to just give your craftEntity three extra NSNumber attributes.
Yeah, I'm sorely tempted to do just that, but it's a last resort option at this point - I'd rather fix this problem or work out a more correct way to go about it, first.
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2008.11
Post: #5
Okay, so after playing around with the game a bit after work, I've decided to settle for creating three additional NSNumber variables. I've also added an instance of the GLvector class in the managedObject, and only access the NSNumber instances through that – basically getting the same functionality as before, with a bit more overhead.

It'll do for now.

Thanks for the help!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Finding Rotational Vectors and Angles Nick 9 4,682 Mar 25, 2005 12:14 AM
Last Post: tigakub
  Vectors vs linked lists KidTsunami 5 3,186 Jun 29, 2003 04:27 AM
Last Post: lpetrich