Difference between revisions of "Managing Resources"
(3 intermediate revisions by the same user not shown) | |||
Line 8: | Line 8: | ||
[[AGI|AGI]] is a game engine which imposes significant memory and resource constraints on the game developer. Among these constraints are: | [[AGI|AGI]] is a game engine which imposes significant memory and resource constraints on the game developer. Among these constraints are: | ||
− | * A limit of 255 [[Logic Resource|logic]], [[Picture Resource|picture]], [[View Resource|view]], and [[ | + | * A limit of 255 [[AGI Logic Resource|logic]], [[AGI Picture Resource|picture]], [[AGI View Resource|view]], and [[AGI Sound Resource|sound]] resources in a game. |
− | * A limit of 255 [[Variable|variables]] and [[Flag|flags]]. | + | * A limit of 255 [[AGI Variable|variables]] and [[AGI Flag|flags]]. |
* A limit of roughly 64 kilobytes for memory. | * A limit of roughly 64 kilobytes for memory. | ||
Line 25: | Line 25: | ||
=== Discard unused resources === | === Discard unused resources === | ||
− | If you don't need that [[View Resource|view]] of [[Ego|ego]] falling into the dumpster any more (because ego has already fallen in), [[Discard.view | + | If you don't need that [[AGI View Resource|view]] of [[AGI Ego|ego]] falling into the dumpster any more (because ego has already fallen in), [[Discard.view|discard]] it! If you leave it in memory, it is occupying valuable space that could be used by something else. Be careful, though. Discarding resources that are being used by other [[AGI Animated Object|objects]] can crash the game, and there are even more subtle bugs that can arise if you don't discard your resource in the exact reverse order that you loaded them. See [[AGI Memory and Script|Memory and Script]] for more details on that issue. |
| | ||
=== Be Mindful of View Sizes === | === Be Mindful of View Sizes === | ||
− | When you [[Load.view | + | When you [[Load.view|load a view resource]], the ''entire'' resource gets loaded into memory. It doesn't matter if you are using only one [[Loop|loop]] or even just one [[Cel|cel]]<nowiki>! If you find you are exhausting your memory, check for views that are being loaded in the </nowiki>[[AGI Room|room]] that have unused loops or cels in them. If you can move those parts out of that view, you can save ''a lot'' of memory. |
| | ||
=== Be concise === | === Be concise === | ||
− | When you are [[Print|printing]] a [[Message|message]] to the screen, ''every single letter'' adds a byte to the total amount of memory that the [[Logic Resource|logic resource]] is using. This means you can't write like a student who's been assigned a 5-page paper and only has 3 pages of content. You must cut the fat. | + | When you are [[AGI Print|printing]] a [[AGI Message|message]] to the screen, ''every single letter'' adds a byte to the total amount of memory that the [[AGI Logic Resource|logic resource]] is using. This means you can't write like a student who's been assigned a 5-page paper and only has 3 pages of content. You must cut the fat. |
<div class="CodeBlockHeader">Code:</div> | <div class="CodeBlockHeader">Code:</div> | ||
Line 65: | Line 65: | ||
[[Category:Tutorials]] | [[Category:Tutorials]] | ||
+ | [[Category:AGI Tutorials]] | ||
[[Category:References]] | [[Category:References]] | ||
+ | [[Category:AGI References]] | ||
[[Category:Resources]] | [[Category:Resources]] | ||
+ | [[Category:AGI Resources]] |
Latest revision as of 14:22, 24 March 2019
Tutorials and Guides Table of Contents
By unknown
AGI is a game engine which imposes significant memory and resource constraints on the game developer. Among these constraints are:
- A limit of 255 logic, picture, view, and sound resources in a game.
- A limit of 255 variables and flags.
- A limit of roughly 64 kilobytes for memory.
This article discusses ways of managing your resources to make the most of them, including tips for avoiding the dreaded out of memory error. As you might imagine, some of the tips in this article might contradict each other. When this happens, you will have to decide which of the two provides you with more advantages. This is called a "trade-off."
Managing memory
No one wants to see their game spit out an out of memory error, but when it happens, all is not necessarily lost. Very often, games are not making careful use of their resources. The good news is that you can often overcome memory exhaustion and get your game up and running again. The bad news is that this requires thought and work. The really bad news is that there are sometimes traps for the unwary that can cause a game to crash or otherwise misbehave. With the advice presented here (and perhaps some help from the message board, you should be able to overcome the challenges and get your game working the way you want it to.
There are no guarantees, of course. Some projects are simply too ambitious for AGI, but with that said, here are some tips for avoiding memory exhaustion.
Discard unused resources
If you don't need that view of ego falling into the dumpster any more (because ego has already fallen in), discard it! If you leave it in memory, it is occupying valuable space that could be used by something else. Be careful, though. Discarding resources that are being used by other objects can crash the game, and there are even more subtle bugs that can arise if you don't discard your resource in the exact reverse order that you loaded them. See Memory and Script for more details on that issue.
Be Mindful of View Sizes
When you load a view resource, the entire resource gets loaded into memory. It doesn't matter if you are using only one loop or even just one cel! If you find you are exhausting your memory, check for views that are being loaded in the room that have unused loops or cels in them. If you can move those parts out of that view, you can save a lot of memory.
Be concise
When you are printing a message to the screen, every single letter adds a byte to the total amount of memory that the logic resource is using. This means you can't write like a student who's been assigned a 5-page paper and only has 3 pages of content. You must cut the fat.
<syntaxhighlight lang="agi"> print("I do not know whether or not he will come."); print("I didn't actually do that in reality."); </syntaxhighlight>
The above two print commands are wasting memory! They use far too many characters to say what they're trying to say. Compare to these far better versions:
<syntaxhighlight lang="agi"> print("I don't know whether he'll come."); print("I didn't do that."); // OR print("I didn't really do that."); </syntaxhighlight>
The sentence I don't know whether he'll come. is 10 bytes less memory than I do not know whether or not he will come. and it says the same thing. Similarly, I didn't do that. is 20 bytes less memory than I didn't actually do that in reality.
The last sentence I didn't really do that. brings up an important point: it only saves 13 bytes of memory over I didn't actually do that in reality.; however, the meaning of the sentence is slightly different than the meaning of I didn't do that. If you can avoid it, you shouldn't sacrifice saying what you mean to say for the sake of saving a few bytes. However, you should also avoid using verbose sentences to say something simple.
So, yes, good writing skills can help you avoid an out of memory error. Go figure.
Tutorials and Guides Table of Contents