So far things seem relatively easy enough. The function would look something like this:
Code: Select all
function Atomic(n){
if(n > GSController.GetOpsTillSuspend () + A){GSController.Sleep(B);}
}
1: How high do A and B need to be to get the intended behaviour from the function?
Now in order to actually get the operations cost, I would need to create a profiling function.
Code: Select all
function Profile(fnc, ...){
local lvalue;
local maxops = GSGameSettings.GetValue("script.ops_till_suspend");
local start_tick = GSController.GetTick();
local current_op = GSController.GetOpsTillSuspend();
switch(vargc){
case(0): lvalue = fnc(); break;
case(1): lvalue =fnc(vargv[0]); break;
case(2): lvalue =fnc(vargv[0], vargv[1]); break;
// etcetera etcetera.
}
local tick = GSController.GetTick();
local op = GSController.GetOpsTillSuspend();
local total_ops = ( tick - start_tick ) * maxops + (op - current_op) + C // (2)
Log.Info("Profile of" + fnc.tostring() + ": " + total_ops.tostring() + " OPS", Log.LVL_INFO);
return lvalue;
}
2a: What is the correct value of C?
2b: Does C depend on vargc in some way? E.g. inner workings of switch statement.
3: is there a less convoluted way of passing thru variable argument lists? I've been looking at squirrel documentation and this is the best I managed to concoct so far.
Like most concurrency issues, this is a rather messy affair. I would love to have a better way of profiling accurately, so if there are better ideas, please don't hesitate to suggest.