Open main menu

Difference between revisions of "HOWTO-Tips And Tricks"

m
Added entry about not having lots of constant data
m (Add point about passing objects by reference)
m (Added entry about not having lots of constant data)
 
Line 39: Line 39:
* 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:
* 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);
**void ClassName::writeString(const Common::String &str);
* Avoid using large amounts of constant data in your engine. This is because it not only bloats the compiled ScummVM executable, it will also get loaded into memory when ScummVM starts, irrespective of whether your game is played or not. This is why many of the game engines come with a data file containing extra needed data, as well as a developer tool to create that data file, usually by extracting it from the original game's executable. There are no rules for how these data files need to be structured, so can come up with your own format, and then load it into memory when your game is started.
265

edits