Open main menu

Difference between revisions of "HOWTO-Tips And Tricks"

m
Add point about passing objects by reference
(Engine development tips & tricks document)
 
m (Add point about passing objects by reference)
Line 36: Line 36:


* Any loop that waits for user input should include a check to break out if the shouldQuit() method of the engine returns true. This is because the user could close the ScummVM window, or some other system specific method to close the application, at any time, and the game shouldn't stall just because it's stuck in an arbitrary loop awaiting input. Likewise, any delay method should comprise of a loop doing smaller delay amounts, interspersed with pollEvents calls. This will allow the application to remain responsive, and exit quickly on a close without having to wait for the delay to end.
* Any loop that waits for user input should include a check to break out if the shouldQuit() method of the engine returns true. This is because the user could close the ScummVM window, or some other system specific method to close the application, at any time, and the game shouldn't stall just because it's stuck in an arbitrary loop awaiting input. Likewise, any delay method should comprise of a loop doing smaller delay amounts, interspersed with pollEvents calls. This will allow the application to remain responsive, and exit quickly on a close without having to wait for the delay to end.
* Remember that specifying an object, such as a Common::String, as a method parameter will cause a copy of the object to be made every time the method is called. This can lead to lots of inefficiencies, and should be avoided where possible in favor of passing by reference. Additionally, it's good practice to use the 'const' prefix as well if the method isn't meant to change the passed object, since it can help prevent accidental changes. That's why in the engines, you'll see methods defined like:
**void ClassName::writeString(const Common::String &str);
272

edits