przemoo83 Posted June 23, 2015 Share Posted June 23, 2015 HiI'm making an HTML5 game where I declare a global variablevar 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. Quote Link to comment Share on other sites More sharing options...
Kozie Posted June 23, 2015 Share Posted June 23, 2015 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 Quote Link to comment Share on other sites More sharing options...
przemoo83 Posted June 23, 2015 Author Share Posted June 23, 2015 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. Quote Link to comment Share on other sites More sharing options...
b10b Posted June 24, 2015 Share Posted June 24, 2015 Using some run-length compression on the coordinates (one string for x, another for y) may result in some memory savings.And / or storing the mouse movement delta (rather than the actual coordinate) may reduce further. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.