Log in

No account? Create an account

Previous Entry | Next Entry

Apr. 9th, 2012

- made creature part sprites (distinct from creature sprites) load on use for those creatures which use extra creature part sprites
- fixed a few bugs with load on use creature sprites

after some attempts, i realized there's no good way to make sound effects load on use without drastically changing the code (making hundreds of edits), because with the other resources, i use arrays to store their indexes, but with sound effects, i use individual named variables (which was a bad idea but that's how i did it). if GML had pointers or some way to pass variables by reference, it could be done, but GML doesn't have that functionality unfortunately

i would still like to do this if i can think of a way to do it that would not take weeks, but i'll have to put it off for now. nonetheless the changes i did make make the game load much faster: from 20 seconds average to 8 seconds average to get past the game's loading screen (this is in addition to the time it takes GM to startup the program, which i have little control over). most of that 8 seconds is loading all the sound effects in the game into memory; the graphics are now loaded prior to each area when they are needed

anyway this counts as a task now. i'll continue working on the second test dream mode level tomorrow, and with the faster game load times it won't be as annoying to keep starting up the game to test it



( 3 comments — Leave a comment )
Apr. 11th, 2012 07:54 am (UTC)
I'm interested in GML's flaws and avoiding them in the new HamsterSpeak, but pointers and references were a point of contention. Could you elaborate on what you mean "if GML had pointers or some way to pass variables by reference": how would you use them in this situation?
Apr. 11th, 2012 04:54 pm (UTC)
the way i'm doing the load on use thing takes advantage of gm's typeless variables. basically at the beginning of the game, with graphics, i set up an array of strings, each a file name

when the game attempts to draw the graphic, it first checks if that array element is a string or not. if it's a string, it takes the string (the file name) and loads it into that same array element, so that it is no longer a string, but a number (a sprite index)

since i load sounds into individual named global variables, rather than array indexes, this method can't work for them, because there are too many places that sounds are "played", and i'd need to insert the code to check if it's a string, and load it if it's not a string, just prior to every instance of the game playing a sound in code (which is, as i said, hundreds of different locations). and that couldn't even be the *same* code copied and pasted into 100s of locations, because i'd need to edit the code at each point in at least three places to take into account that individual sound variable's name

a possible workaround for that is to have the sound function that plays the sound itself check the variable and replace its value (from a string to a sound index), but that can't work because, in GML, a function cannot change the value of a variable without knowing what that variable is, and all that can be passed to a function is a variable's value, not a reference to that variable

i'm sure there's some other way to alter the code so that i can load sounds when they are first used and store their index in those variables, but i can't think of any other than my string/index system that could be added to the game without making hundreds of individual edits into the code

with graphics, the change was relatively simple, because, since what is passed are array indexes, the function to draw the graphic can change those from strings to indexes without trouble

Edited at 2012-04-11 04:56 pm (UTC)
Apr. 12th, 2012 06:20 am (UTC)
OK, thanks, nice use case. Normally this sort of thing is solved using objects (classes), but it seems that GML doesn't have user definable objects. Also, I know that I can't trust users to understand how to use objects to do such a thing when many don't understand using 'for' loops instead of copy-pasting...

If GML has efficient string-indexed maps (I see that it does have maps, but not whether they even support strings), then a simple solution would be to look up the sound effect filename in a map on every call to the function to play a sound. If it's not in the map already, load it and add it to the map. I don't know how fast this is in GML, but it would be < a hundred CPU cycles in C++.

Also, I hate to point it out, but those hundreds of substitutions would only take a minute using a text editor with a macro system, supposing it's possible to export and import GML scripts in bulk.
( 3 comments — Leave a comment )