Updating OpenBOR content on-the-fly.Tutorial by O Ilusionista. With help of Damon Caskey, thanks buddy.
Although I love the engine, there was always something about OpenBOR that bothered me a little - you had to close the game and reload to update the materials with each modification you made. This wasted a lot of time, depending on the size of the game and the amount of items.
However I found that there is a way to update the material while the engine is running (on-the-fly).
It's not perfect, but it worked for me and it might be useful for more people. And it works when using the DATA folder and not compressed in .pak, ok?
STAGES--------As Damon said some time ago, the contents of the stages (codes and images) are loaded before use and
unloaded immediately after use - that is, when the scenario ends.Then you can update the scenario files with the engine running.
Just exit, save your changes and enter the stage again. The engine will load the content again, this time updatedENTITIES--------This is a more complicated case, based on the dependencies that each character has (in other words, the models that the entity carries)
For example, I want to update the entity called
"bug". Even if I leave the scene and enter again, the entity will not be updated, as it is already in memory -
And if you told the engine to load something it already loaded, it ignores it and moves on because the engine knows what it already loaded.But here is a trick, which answers a question that I and others asked years ago - If the engine ignores when you ask to load something it has already loaded (in the default configuration), what happens if you tell the engine to load a content that is already in memory but changing the loading configuration?
Answer: ENGINE UPDATES THE LOADED MATERIAL!And how do you change the loading configuration? Using a command in the stage's .txt file:
load {name} {bi}
~ Used to load a model whose name is {name} in current level.
~ {bi} determines if model stays in memory or not after current level ends.
0 = Nothing. The model is left alone (IOW, remains loaded) and loop moves on. This is the default action.
1 = Unload model only. The model is unloaded, but the sprites are not. Pretty pointless unless the model has a lot of script attached to it.
2 = Unload sprites only. The mode remains loaded, but its sprites are removed from memory.
3 = You'll notice there there is no third option, but because bitwise logic is in play, 3 effectively means "1 and 2" - model and sprites are unloaded.
~ This command is for loading weapons models or other entities which shouldn't be loaded until this command is executed. It's useful for memory usage control.
~ Don't forget to load {name} with 'know' in models.txt!
In my case, I added:
load bug 3
After updating what I wanted, I left the stage and entered it again - and now the entity was updated.
Note: for any dependency of this entity, such as weapons, projectiles, etc. that you want to be updated as well, it is necessary to place another command in the file. For example, if the "bug" entity has a projectile (knife / bomb / etc) called "missile", you need to add one more line:
load bug 3
load missile 3
Tip: You can make a simple test scenario that you will use to test entities and use this code.