C++ on the iPhone: Djinn Engine

EDIT: I would like to point out that below, when mentioning “Mike” … I forgot to plug his website.. whoops! In any rate, he has a few great tutorials (in video form) located: http://www.71squared.co.uk/ … HIGHLY recommend you check them out if you’re using Obj-C on the iPhone.

Hello everyone! I have been reading through your emails and appreciate all the letters. One question I kept asking myself with this project was “Do I want to make the engine open source?” My decision came apparent when I realized that this engine, although it will be used for my iPhone games, was first and foremost a learning experience for me and a tool that I used in order to become a better programmer.

So here I am, with a working copy of the Djinn Engine, and I have decided to make the project ‘open source.’ Before I upload the source to a SVN however, I want to ask the communities opinion on what they want to see?

The engine works, but it is crude. Currently in the engine is the following:

TestGame – I’ve been using this as a static unit testing for the engine

Actor System – Handles any actors in the game. Started by using the Angel Engine as template

Animation System – Animation Manager used for stopping, starting, and updating various animation playlists.

Game Screen Management – A C++ version of the Screen Controller tutorial from below.

Serializable objects – All objects (Characters, particle effects, etc) will be serialized in .dat files for dynamic loading. This way they do not need to be hard coded into the engine.

Input management (single touch only) – A C++ version of the input manager tutorial below.

Particle System – Using Mike’s tutorial as a starting point, dynamic particle system that includes a controller, effect, and various emitters for every particle effect. The one i currently have been using is “fire”

OpenAL Sound Support (have not put in OGG support yet, plan to) – Also using Mike’s tutorials as a staging point, this is an OpenAL sound engine that currently only works with sound effects… I want to add OGG support in the future.

File Management – pass in the asset name of a file, and a pointer to the object you wish to unserialize, and the file manager will take care of the rest.

Random Number Generation – … does just what it says it will do :)

Modified version of Apples Texture2D for C++ (will need to revamp this)

Math Utilities class (IE: Clamp, Min / Max, Abs, Lerp, etc etc)

and a couple of other things. Keep in mind, this is a 2D engine! So… iPhone community… We have a few choices before this thing goes Open Source. I will continue working on it, adding things that will meet my needs (keeping in mind, this will be the engine I am using for my iPhone Game) and I figure if I need a feature, maybe the community could use it as well. Should I just release it “as is” right now and continue working on it while you all can get your hands on it and modify it depending on what you need? Should I clean it up a bit, so its easier to understand when you’re reading through the code? or should I wait til the engine is pretty much done and release it then?

Let me know either via comment or email what you wish, and we’ll make it happen. I’ll have to work on some documentation, especially for the crude object serialization haha.. but that shouldn’t be too hard to do. Let me know what you think, and for the few of us who actually enjoy C++ on the iPhone, lets make it happen!


25 comments so far

  1. Moski Doski on

    This actually looks very promissing , i’ve been using ur game project template for while now. cant wait to try this ;)

  2. nexus6 on

    I think you should release it as is and let people play with it. Maybe that way more ideas will evolve from people actually using it.

  3. Eskema on

    I think the same as others, release it and let people play with it, It may take ages to wait for the “complete” engine, because we (the programmers) are always changing things, so we never finish the engine ;)

  4. nexus6 on

    Is the engine going to be 3.0 compatible?

  5. Craig on

    I actually don’t have a copy of the 3.0 SDK… but there is nothing really that I’m doing (or methods that i’m calling) that would have been taken out of the 3.0 sdk… Unless they changed how you find a file from within the bundle :)

    I’m just finishing commenting on a few things, and I’ll have it released shortly. It still needs a lot of work, but at least it will give a good toy for programmers to play around with.

  6. nexus6 on

    Can’t wait to try your engine out.

  7. Craig on

    .. might be a few days, i just found a MAJOR bug that I’m not sure whats going on.. ironically its because i didn’t fully understand the OpenGL as I was writing it (and part of the problem is Apples Texture2D class)

    So i gotta do some OpenGL research.

  8. nexus6 on

    Yep, openGl ES can be a pain. I’ve noticed it doesn’t take much to get things messed up. One wrong variable and you end up spending a day just trying to figure what the heck went wrong.

    Did you try using the texture2D class from Mike’s Tutorials at 71squared? Just a suggestion.

  9. Craig on

    I really like what mike did with his (for those who are reading this and not knowing who ‘mike ‘ is… visit: http://www.71squared.co.uk/

    I may end up using that one, but right now I’m reading a few chapters in the OpenGL red book to figure out just what OpenGL is doing and maybe I can figure something out. Its funny, in my engine I even have comments and #warning’s saying i want to re-write the texture2d class tthat apple provided… guess this is a perfect opportunity eh? :D

    I may just give the SVN link to the code database even though its bugged to hell.. saying “use at your own risk” or something. I mean i’ll be updating it pretty much every day but at least that way people can play with it. If i can’t figure out the problem by tomorrow, i’ll log it in the issues and just release the source.

    Also keep in mind, even if i did use Mike’s version, i would have to convert it to C++ (which isn’t too hard, since OpenGL is C anyway)

  10. nexus6 on

    Is there a specific reason your doing it in C++

  11. nexus6 on
  12. Craig on

    I’m doing it in C++ because its the language I was learning how to program in, and I understand it at a fundamental level thats more in depth to what Obj-C is. For example, I have been learning not only the syntax but also where things are stored in memory, how they are accessed, when things are passed by value or reference, how they are initialized, how polymorphism is being implemented through base class pointers and virtual-tables, etc etc..

    I just really enjoy the language of C, C++ , and C#.

  13. nexus6 on

    I know what you mean, I’m just learning Obj-C it sure is a lot different than C, or Perl. I’ve done a little C++.
    I know Obj-C can be very slow, C structures are so much easier than doing the obj-C stuff but I figure I better stick with what apple is using at least for now.

    Hope you figure out the bug or put up the code so maybe someone else will find it.


  14. nexus6 on

    I forgot to mention that I’ve run across openGL code that works fine in 2.2.1 but gives blank screen or crashes in 3.0.
    You would think 2.2.1 would be close enough but it isn’t. They already have 3.1 beta up, I’m not touching that for awhile.

  15. Craig on

    I’ve got it narrowed down… its strange. The way I have the thing working is I have a character created that uses a Texture2D object as its texture (apples version) … if I let that draw before the particle engine runs, everything works beautifully…

    If however, I comment out the code that lets the Character draw (IE: Apples Texture2D is not being called anymore) it gives me the error. It ALWAYS craps out at the line glDrawArrays(GL_POINTS, 0, particleIndex); in the particle emitter.

    Also, if you disable Point Sprite (IE: comment out the following line: glEnableClientState( GL_POINT_SIZE_ARRAY_OES ); ) obviously you wont see any sprites from the particle emitter, but the code doesn’t crash.

    I don’t know what OpenGL is doing and thats why its frustrating.. which is why i’m looking into re-writing the texture classes so I can kinda understand what OpenGL is doing behind the scenes.

    Having said that, as long as you know the error is there, i guess there is no real problem in giving out the URL… i’ll just do it tomorrow and make sure everyone understands there are a lot of bugs in it.

  16. nexus6 on

    Sounds good, who knows maybe someone will spot whats going on. especially if someone has seen this type of problem before. I know I’ll give it a go.

  17. nexus6 on

    do you call glEnable(GL_TEXTURE_2D) at the beginning of the particle render

  18. nexus6 on

    If you put it up today I’ll make sure I download it and see if I can find out what’s going on also. Sometimes it’s easier when you haven’t been staring at the same code all day.

  19. Craig on

    repository is at: http://code.google.com/p/djinnengine/
    I’ll make the blog post about it tomorrow… I wont commit what I’ve been working on until then either. Been attempting to make a TextureController and kinda re-write the Texture2D object.. but its not ready so I’ll just hold off on that for now :)

    Everything should be fairly well commented though, so you shouldn’t have much problem figuring out what the thought process was for anything.. although the details on how they work is kinda wicked i’m sure.

  20. Craig on

    ugh… bad news. After switching everything over to the texture controller, i still get the error at the same location.. I have a feeling its something with the emitter’s OpenGL calls or possibly even my setup view in the screen controller. I’ll have to dig around and find it.

    I’ll commit my changes when I get them cleaned up a bit, should be tonight though.

  21. nexus6 on

    Hi Craig
    Just some info, the engine doesn’t compile in 3.0, has 15 hard errors and 13 warnings. Here’s one of the Hard errors

    error: extra qualification ‘ActorController::’ on member ‘loadActor’ which is line # 54 in the ActorController.h

    • Craig on

      That is a shame… quite possibly because of the call to Files->unSerialize( [ASSETNAME], [ACTOROBJECT] )

      I will download the 3.0 SDK and start developing using that, and see if i can plug some of hte issues. At least with only 15 errors, it seems like it might be the same thing (FileUtil.mm) that is spitting htem out.

      Also with the warnings… a LOT of those are me typing “#warning TODO:: Fix this code” or something :D

  22. nexus6 on

    Yep, I noticed that… :-)

  23. Craig on

    Committing the changes now, it compiles in 3.0. Starting on Revision 7

  24. Craig on

    Found the issue with the particle emitter, and fixed it. Its been committed to the code.google.com/p/djinnengine database, so you can check it out there…

    basically though, and I’m not sure if Mike did this as well (it could be an error in his too) the Texture2D did some stuff with texCoords that I never did with the emitters.. so if they never got set with Texture2D’s->draw function, OpenGL would blow up.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: