Sertica 18 Posted October 14, 2020 I'm trying to get a grasp on two matters to get a mission loop running properly. 1. What is the difference between call and spawn? According to https://community.bistudio.com/wiki/Scheduler#Scheduled_Environment I'm taking it to mean that the only difference is code running in spawn is limited to 3ms bursts. call compileFinal preprocessFile "main.sqf"; call main; main = { onEachFrame { hint "test"; // game engine loop going in parallel with this }; }; 2. Is calling only scripts compiled in init.sqf, as above, all you need to get best possible speed? Is there a way to compile all sqf files in the mission folder tree as opposed to adding all lines manually to init? What I am aiming for now as I start to gather my test missions into a real mission is having typical game loop for mission with frequency sections like this: main = { _frameCount = 1; // start on frame 1 onEachFrame { if (_frameCount > 500) then { _frameCount = 1; }; // reset after 500 frames /* High Frequency */ call highFreqMethod; // execute these every frame; ~0.02 interval /* Medium Frequency */ _remainder = _frameCount % 20; if (_remainder == 0) then { // execute these every 20 frames; ~0.4 second interval call medFreqMethod; }; /* Low Frequency */ _remainder = _frameCount % 500; if (_remainder == 0) then { // execute these every 500 frames; ~10 seconds interval call lowFreqMethod; }; _frameCount = _frameCount + 1; // }; }; A strategic decision making script would go in the low freq section for call at ~ 10 second interval. Scouts trying to spot enemies could go in medium or high depending on how much precision can be afforded with current frame rate. Share this post Link to post Share on other sites
Sertica 18 Posted October 14, 2020 Is there any serious reason to use function-as-file? https://community.bistudio.com/wiki/Function#Types_of_function I read a bit about inlining for general programming. Not sure whether there could be a problem arising from using variables instead. Then there is the question of which versions of existing ones to use. E.g., vectorDotProduct vs. BIS_fnc_dotProduct. Share this post Link to post Share on other sites
phronk 895 Posted October 14, 2020 Call is faster usually, but doesn't let you suspend time using sleep, waitUntil, while, etc. whereas code within a Spawn allows them. Too many spawned scripts/functions at one time can fill up the scheduler faster and cause code delays, as well as lower FPS depending on how heavy everything is. But that's usually in poor practice. Personally, I try to call as much as I can and keep my spawns limited and manageable. As far as initializing functions/scripts, many people prefer to initialize functions in CfgFunctions (Just create your own functions.hpp to #include under CfgFunctions in your Description.ext) because you can apply additional parameters like preInit to make them load faster. In my case, I initialize functions in a .sqf which stores each function within a global variable/missionNamespace for modularity. 2 Share this post Link to post Share on other sites
gc8 970 Posted October 14, 2020 spawn creates new thread where the execution of the spawned code is done. call doesn't create new thread. Also execVM and spawn are basically the same, just that execVM get's the code from a file 2 Share this post Link to post Share on other sites
Sertica 18 Posted October 14, 2020 9 hours ago, gc8 said: spawn creates new thread where the execution of the spawned code is done. call doesn't create new thread. Also execVM and spawn are basically the same, just that execVM get's the code from a file When I run the main code above it does not freeze the game, leading to the question of what thread it is in to begin with. It seems scripts are already running parallel to the game engine. 1 Share this post Link to post Share on other sites
phronk 895 Posted October 14, 2020 If you want code to execute as fast as possible, such as during initialization of a mission, you can do it within a loading screen (Code runs 50ms per frame instead of limited to 3ms per frame): startLoadingScreen["Please wait, LOADING!!!"]; // All muh scriptz n codez sleep 3; endLoadingScreen; 2 Share this post Link to post Share on other sites
fn_Quiksilver 1633 Posted October 15, 2020 On 10/14/2020 at 2:36 PM, Sertica said: I'm trying to get a grasp on two matters to get a mission loop running properly. 1. What is the difference between call and spawn? According to https://community.bistudio.com/wiki/Scheduler#Scheduled_Environment I'm taking it to mean that the only difference is code running in spawn is limited to 3ms bursts. call compileFinal preprocessFile "main.sqf"; call main; main = { onEachFrame { hint "test"; // game engine loop going in parallel with this }; }; 2. Is calling only scripts compiled in init.sqf, as above, all you need to get best possible speed? Is there a way to compile all sqf files in the mission folder tree as opposed to adding all lines manually to init? What I am aiming for now as I start to gather my test missions into a real mission is having typical game loop for mission with frequency sections like this: main = { _frameCount = 1; // start on frame 1 onEachFrame { if (_frameCount > 500) then { _frameCount = 1; }; // reset after 500 frames /* High Frequency */ call highFreqMethod; // execute these every frame; ~0.02 interval /* Medium Frequency */ _remainder = _frameCount % 20; if (_remainder == 0) then { // execute these every 20 frames; ~0.4 second interval call medFreqMethod; }; /* Low Frequency */ _remainder = _frameCount % 500; if (_remainder == 0) then { // execute these every 500 frames; ~10 seconds interval call lowFreqMethod; }; _frameCount = _frameCount + 1; // }; }; A strategic decision making script would go in the low freq section for call at ~ 10 second interval. Scouts trying to spot enemies could go in medium or high depending on how much precision can be afforded with current frame rate. as a general rule for optimization, call/execute/evaluate code as infrequently as possible while still accomplishing the task. very few things need to be executed each frame, examples being visual things like GUI. Things that aren't seen by the player dont need to be updated very frequently 1 Share this post Link to post Share on other sites