Jump to content

Thoughts and help on my game engine core


spleen387
 Share

Recommended Posts

So I'm putting together some code for the low level of my next game and so far I have a constructor for constructing game object constructors (createGameObjectConstructor)

and it's child: Clock, which will be used to set up the main loop and such. (two others Monster and Vec3 but they're just test cases)

 

everything, to my knowledge right now, is working just fine but I was wondering if you guys could have a look over it  to see if theres anything I could do a better way,

particularly in createGameObjectConstructor theres an Object (outerProto) that gets created everytime createGameObjectConstructor is called but I cant seem to find a way around that..

 

thanks! :)

 

http://jsfiddle.net/hv7Xx/1/

or

https://gist.github.com/spleen387/9713289

Link to comment
Share on other sites

Please correct me if I'm wrong about your code cause I'm just having a quick-read and didn't test it.

 

I think it is quite complex but also you are specializing the object creator (as game object constructor). It is best that object creation is generic, as everything may have the same trouble as they are "object". If it is only one level of inheritance and doesn't need namespace, it doesn't need any object creation pattern at all (just use function A() {}). 

 

About the performance, even though the process won't be seen by the gameplay developer, I see that ret() function is invoked everytime an object has to be created, and inside that you call a lot of stuff that is expensive such as .apply, recentArray = [] (Careful you're creating a new array instance here!), and attaching a new property, for the sake of pooling if I see it (recycling the instance). These may causes an overhead when allocating a new object.

 

If you want to do an object creation, maybe try to trim the code not to have anything attached to the instance (the countDescriptor I guess). More properties attached to an instance means more performance degradation in JavaScript. Google has suggested not to have more than 30 properties, or keep is as minimum as possible (Unless the properties are class members, which means that the class is always only one.)

 

I suggest that as far as you go, try to trim everything down to compilation mode. For example, make sure whatever you do before the runtime (calling the main/onload), all those codes have been supplied to each object (in your case, gameobject), and when it is needed to be used, it will be used natively (var car = new Car()). This will save the performance during run time, as it uses the native "new". Also with that, the object is easily available for generic or specialized object pooling outside your recycler.

 

You might want to think about some of these issues if you're talking about these low level things; namespaces, circular dependencies (A has B, B has A), and object comparison (a instanceof A? a === A?).
And if you want to test it the performance, simply do a 100K - 1M loop test of yours against the native "new".

 

If performance is not an issue, then your code is fine as long as you make it generic (I guess it's probably just the naming convention). But looking that you're using a recycler like that, I assume you want better performance.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...