Jump to content

JS game variable holding big data


przemoo83
 Share

Recommended Posts

Hi
I'm making an HTML5 game where I declare a global variable

var route = [];

that is used to hold mouse coordinates in form of array of objects. After couple of minutes of playing there are already thousands of objects there. I didn't notice any lags or slowing down but maybe that's because the game is very simple without complex graphics. Should I worry about that variable? What is a general rule in game design when it comes to variables that are constantly growing. I cannot clear this variable because I need all of thiese coordinates throughout a game. I wouldn't want to end up with a game that has a "bug" that makes it impossible to play after a while due to memory overload.

Link to comment
Share on other sites

It depends how precise you want the mouse data history. Perhaps there could be a greater interval between every record of mouse info so you will end up with less entries in the array.

 

You also mentioned that there are 'thousands of objects' within a couple of minutes. I'm not sure if you mean object by just an entry or object as in an instantiated object/class with more info than, perhaps, actually needed.

What i mean is if you only need some small numbers of, for example, mouse coordinate numbers, you could also use one of the TypedArrays.

It seems that you append 'route' with 'New MyClassNameWithMousePosInfo()' objects which seems a bit overkill. If you tend to keep situations like these as small and simple as possible you will probably have less problems with memory or performance issues. Even tho you don't have any of those now they may certainly be present on systems with less computing power/resources or when you project grows further.

 

Good luck tho ;)

Link to comment
Share on other sites

Thanks a lot for feedback. I need to think whether I really need all of the coordinates to be stored there. In the meantime I separated the module of this game and put it in JSfidle:

 http://jsfiddle.net/przemoo83/exenqqdo/

You can see in a console  after you uncomment the

  //console.log(route);

at the bottom how it grows rapidly after you draw some lines.

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...