Coding

 Reply to this postStart new topic

[CLEO 3] 0AB1 + 0AB2 discussion

Siggi
post Jul 23 2010, 10:33 AM
Post #1


User banned by request due to personal reasons. - SV

Posts: 24
From: 0xFFFFFFFF
Joined: 14-March 10



Hi all,

I've got a question about the CLEO 3 opcodes
SANNY
0AB1: call_scm_func @GetSQR 1  10 $result

and
SANNY
0AB2: ret 1 0@


(0x0AB1):
QUOTE (SannyBuilder Help)
This opcode calls a SCM function, passes the parameters to it and stores the result to a variable(s). The passed parameters values are copied to the local variables in series, then the thread execution is transferred to the label, it executes code there and returns after the opcode 0AB2.
Parameters:
1 – label (SCM function beginning)
2 – number of parameters to pass


Well actually i can see 4 paramters:
a label, a flag, a (int) parameter and the var that will be returned by 0x0AB2

well the flag always seems to be 1, but the point I don't realy get is the (int) parameter (10 in this case)
(it seems to be the second parameter explained by SB Help)

Well what the hell does it?
I mean how can $result return 10 values unsure.gif ???
and because I'm a huge fan of functions in other languages (especially in C++) I use gosubs very often for this purposes and I don't realy see a good reason for having 0AB1
(yes, you got it, I'm provocing here laugh.gif )


because:
SANNY

gosub @GetPosition

...

:GetPosition
Actor.StorePos(_PActor, _PX, _PY, _PZ)
_PTempX = _PX
_PTempY = _PY
_PTempX -= _PRadius
_PTempY -= _PRadius
_PX += _PRadius
_PY += _PRadius
_PX = Random(_PTempX, _PX)
_PY = Random(_PTempY, _PY)

02CE: _PZ@ = ground_z_at _PX _PY _PZ


works well and although its a void function (concerning the syntax) I can now use the coords (replaced with _P... consts here)

I mean why would I create the example code for
SANNY
0@ = 5
0AB1: call_scm_func @GetSQR 1  10 $result
end_thread

…..

: GetSQR
006A: 0@ *= 0@
0AB2: ret 1 0@


when its more high-performative ( wacko.gif ) to use:
SANNY

gosub @GetSQR
...
:GetSQR
0@ *= 0@
return


if there is any real need of these two opcodes I doubt on, please help me to destroy this doubt laugh.gif

cheers


This post has been edited by Siggi: Jul 23 2010, 10:35 AM


--------------------


User banned by request due to personal reasons. - SV
Go to the top of the page
 
+Quote Post
Silent
post Jul 23 2010, 12:08 PM
Post #2


The master of cut retort

Group Icon

Posts: 239
From: Warsaw, PL
Joined: 21-July 10



Hm, maybe it's a bit hard to explain.

SCM function works like temporary new 'sub-thread', that passes set values to thread, that called that thread (a bit confusing ;D).

So

QUOTE
Well actually i can see 4 paramters:
a label, a flag, a (int) parameter and the var that will be returned by 0x0AB2

well the flag always seems to be 1, but the point I don't realy get is the (int) parameter (10 in this case)
(it seems to be the second parameter explained by SB Help)


Second value isn't a flag. It's number of parameters, that will be passed to 'sub-thread'. So @GetSQR label will have 0@ = 10 (in this case). IT'S IMPORTANT, that 0@ in your main thread WILL BE UNTOUCHED (it's main rule why SCM function is better than gosub in some cases). After calling SCM it's working normally and when gets to 0AB2, function returns to main thread and sets $Result variable to value of 0@ from that function.

So if you see SCM function opcode like that:

SANNY
0AB1: call_scm_func @DoSomeAction 5  53 63 79 95 5@ 9@ 10@


We have 5 parameters, but wait - there is 7 values after that digit!
That's because 0AB1 calls @DoSomeAction label and now 0@ = 53, 1@ = 63, 2@ = 79, 3@ = 95, 4@ = 5@ (remember that locals from main thread won't be affected). That label does some actions and then return:

SANNY
0AB2: ret 2 0@ 2@


Now that function sets 9@ from main thread to value 0@ from func, and 10@ to 2@ (note that number of values from 0AB2 must be equal to number of values subtracted from second parameter of SCM - in this case 7 values - 5 = 2).

Confusing, but simple biggrin.gif
Go to the top of the page
 
+Quote Post
Siggi
post Jul 23 2010, 02:49 PM
Post #3


User banned by request due to personal reasons. - SV

Posts: 24
From: 0xFFFFFFFF
Joined: 14-March 10



Ah, I'm getting closer to understand, this seems to be comapreable with real locals in a block (general programming)

So I can give it any parameters and the sub_thread extends uses its own locals which I can return?
that makes it even more comfortable as using gosubs as voids cool.gif

please correct me if I'm wrong

cheers


--------------------


User banned by request due to personal reasons. - SV
Go to the top of the page
 
+Quote Post
Silent
post Jul 23 2010, 05:10 PM
Post #4


The master of cut retort

Group Icon

Posts: 239
From: Warsaw, PL
Joined: 21-July 10



QUOTE (Siggi @ Jul 23 2010, 04:49 PM) *
Ah, I'm getting closer to understand, this seems to be comapreable with real locals in a block (general programming)

So I can give it any parameters and the sub_thread extends uses its own locals which I can return?
that makes it even more comfortable as using gosubs as voids cool.gif

please correct me if I'm wrong

cheers


Yes, by default scm function has all locals set to 0 (like a new thread), but you can define them while calling that func (like a new thread too, but regular thread can't pass some of its parameters to other thread when it's completed).


Maybe it will be easier to understand using sample & simple script:

SANNY
0@ = 10
1@ = 5
2@ = 0
0AB1: call_scm_func @SomeCalculations 1 1@ 2@ // passes value of 1@ to 0@ of that scm func, 2@ will receive value from function
// Value of 0@ now = 10
// Value of 1@ now = 5
// Value of 2@ now = 10
end_thread

:SomeCalculations
// 2+2+2+2+2 and so on ;D
// Value of 0@ now = 5
// Value of 1@ now = 0
// Value of 2@ now = 0
2@ += 10
// Value of 2@ now = 10
0AB2: ret 1 2@ // Passes value of 2@ to 2@ of main thread


Now it's better to understand?

This post has been edited by Silent: Jul 23 2010, 05:15 PM
Go to the top of the page
 
+Quote Post
Deji
post Jul 23 2010, 11:16 PM
Post #5


Coding like a Rockstar!

Group Icon

Posts: 1,468
From: ???
Joined: 28-May 09



0AB1 is a good way to perform calculations like a gosub without using extra variables.

Since all variables in a SCM Function start as 0 (unless parameters are passed to them), you can easily check which parameters were passed, like so:

SANNY
0AB1: call_scm_func @GetCoords 0 $X $Y $Z    // 00A0 will run, returning just the player position.
0AB1: call_scm_func @GetCoords 1 4.0 $X $Y $Z    // The X offset will be 4.0, the rest 0 (0.0).
0AB1: call_scm_func @GetCoords 3 -4.0 2.1 3.5 $X $Y $Z
end_thread

:GetCoords
if or
    8039:   not 0@ == 0   // first param passed.
    8039:   not 1@ == 0   // second param passed.
    8039:   not 2@ == 0   // third.
then
    // if an offset was passed...
    04C4: store_coords_to 3@ 4@ 5@ from_actor $PLAYER_ACTOR with_offset 0@ 1@ 2@
else
    // if no offsets were passed or they all equal 0.0
    00A0: store_actor $PLAYER_ACTOR position_to 3@ 4@ 5@
end
0AB2: ret 3 3@ 4@ 5@


Probably not the best example, but here we have a SCM Function that tests which opcode to use based on whether the required parameters have been passed.

So you don't have to pass all the parameters... Just remember that anything not passed will equal 0.


--------------------
Go to the top of the page
 
+Quote Post
Reply to this postStart new topic

5 User(s) are reading this topic (5 Guests and 0 Anonymous Users)
0 Members: