Deji Posted March 2, 2013 Share Posted March 2, 2013 (edited) Download Please avoid "wotzit" questions, as the readme (available on the download page) explains just about everything. There are demo scripts provided with the download. SuperVars is heavily used in The Black Market Mod, which is why I'm releasing it now. I've had SuperVars for about a year now, so it's heavily tested, I just kept it to myself for a while... Selfish. And, here is a bonus: https://pastebin.com/46ayUR24 I call this Objective-SCM (difficulty: Brainf*ck). Wotzit? It's a relatively low-level objective-oriented implementation for CLEO 4 (though it would only take replacing ALLOCATE_MEMORY to make it CLEO 3-friendly). Once you understand the example scripts given with SuperVars, this isn't too much to handle when using it but concentrate on the low-level source and your eyes may burn a bit. The source is pretty well commented, though. It's not included as part of the SuperVars example scripts as I consider it worthy of a bit more light, however this is a great example of SuperVars' power for this topic (its just best to see the example scripts with the download first). Objective-SCM allows you to create your own virtual 'types' and create C++-like objects with them. For example: CONSTCAnimal__SizeOf = 12CHuman__SizeOf = 4CDog__SizeOf = 0CCat__Sizeof = 0END:CAnimal // type()RET 3 @CAnimal_ctor 0 CAnimal__SizeOf:CHuman // (inherits CAnimal)0A8E: [email protected] = CAnimal__SizeOf + CHumanSizeOfRET 3 @CHuman_ctor 0 [email protected]:CDog // (inherits CAnimal)0A8E: [email protected] = CAnimal__SizeOf + CDogSizeOfRET 3 @CDog_ctor 0 [email protected]:CCat // (inherits CAnimal)0A8E: [email protected] = CAnimal__SizeOf + CCatSizeOfRET 3 @CCat_ctor 0 [email protected] @CCat, for example, can now be passed to @new (just like the C++ new, see the Objective-SCM :new source for more info) which initialises a 12 byte structure, or an array of 12 byte structures: CALL @new @CCat 1 [email protected] @CCat_ctor is a constructor (0 is the destructor param, use 0 to not use a constructor/destructor), which will be automatically called by @new after allocation, or in the case of an array, will call the constructor for every object in the array after allocation: CONSTthis = [email protected]_Type = [email protected]_NumLegs = [email protected]_HasTail = [email protected]_NumArms = [email protected]_TYPE_UNSPECIFIED = -1ANIMAL_TYPE_HUMAN = 0ANIMAL_TYPE_DOG = 1ANIMAL_TYPE_CAT = 2SuperVar = stringENDVARthis: array 4 of SuperVarEND:CAnimal_ctor{\__(obj*)__}0006: this[this] = @CAnimal_VTBL // default VTBL for abstract class0006: this[this] = ANIMAL_TYPE_UNSPECIFIEDRET 0:CHuman_ctor{\__(obj*)__}CALL @CAnimal_ctor 1 this0006: this[CAnimal_Type] = ANIMAL_TYPE_HUMAN0006: this[CAnimal_NumLegs] = 20006: this[CAnimal_HasTail] = FALSE0006: this[CHuman_NumArms] = 2RET 0:CDog_ctor{\__(obj*)__}CALL @CAnimal_ctor 1 this0006: this[this] = @CDog_VTBL0006: this[CAnimal_Type] = ANIMAL_TYPE_DOG0006: this[CAnimal_NumLegs] = 40006: this[CAnimal_HasTail] = TRUERET 0:CCat_ctor{\__(obj*)__}CALL @CAnimal_ctor 1 this0006: this[this] = @CCat_VTBL0006: this[CAnimal_Type] = ANIMAL_TYPE_CAT0006: this[CAnimal_NumLegs] = 40006: this[CAnimal_HasTail] = TRUERET 0 Here we have a constructor setting the default (initial) values of a 'CDog', 'CCat' or 'CAnimal'. It also sets a 'virtual table', so lets have a look at them... :[email protected][email protected][email protected]_SpeakEND:[email protected][email protected][email protected]_SpeakEND:[email protected][email protected][email protected]_SpeakEND Note that the first field of the VTBL must be a pointer to the object base VTBL. Actually, you could also have the first field point to another virtual table, and have that point to the object base VTBL, and so on... :CAnimal_SpeakPRINTSTRING "Hello"RET 0:CCat_SpeakPRINTSTRING "Miaow"RET 0:CDog_SpeakPRINTSTRING "Woof"RET 0:CAnimal_GetNumLegsRET 1 this[CAnimal_NumLegs] So calling GetNumLegs with a cat would return 4, for a dog it would also return 4, but for a human it would return 2. But for 'Speak', different animal classes have to use different methods, as they all speak differently. If we knew our object type was definitely a CDog, we could just do: CALL @CDog_Speak 1 [email protected] // [email protected] was returned from @new However, the idea of a virtual table is that we could also have a different VTBL for a similar object, but we could still call the same method: CONSTCAnimal_Speak = [email protected] // index of the Speak method for each CAnimal object's VTBLENDCALL [email protected](CAnimal_Speak,4s) [email protected] If [email protected] is a CCat, it will print "Miaow", if it's a CDog, it will print "Woof" and the default method is "Hello", which will cover a CHuman and any other CAnimal-based type which is created without it's own unique VTBL. Don't worry, lots of confusion and questions are expected, unless you are both a CLEO and C++ pro, so fire away. Cheerio. Download Edited March 2, 2013 by Deji BrownRecluse 1 Link to comment Share on other sites More sharing options...
ThirteenAG Posted March 2, 2013 Share Posted March 2, 2013 Wow, that is something. Widescreen Fixes Pack || Project2DFX || SaveLoader || WindowedMode || CLEO Scripts Link to comment Share on other sites More sharing options...
Wesser Posted March 2, 2013 Share Posted March 2, 2013 (edited) Awesome work, Deji. I was planning something similar as a feature of a new SCR compiler. Basically, you enhanced your CLEO's technique for adding new local variables and took advantage of it to make a C-like class, by passing negative local variables as array index. A tricky and cleaver method. Again, great job. Edited March 2, 2013 by Wesser 012 345 678 9A BCD EFG HIJK LMN OPQR STUV WX YZ Link to comment Share on other sites More sharing options...
fastman92 Posted March 2, 2013 Share Posted March 2, 2013 You did it well. Unsigned 32768 to 65536 index wouldn't be used in regular scripts, while it may be used in old local additional variable access method, which will still work, if flag of SuperVars is disabled. Link to comment Share on other sites More sharing options...
Deji Posted March 2, 2013 Author Share Posted March 2, 2013 (edited) Thanks, I was planning on taking over the 'v' string array vars, too (they're a bit more commonly used, but SuperVars will still work with naturally with em) but I'm really wondering what the most important new ability would be. Call-time pass by pointer would be kinda nice, but CLEO 4's GET_VAR_POINTER handles that fine... But more important would have to be the ability to read the number of bytes specified as the array size paramter (which would be great since the array size parameter is never even used by the game). That way we'd have full access of SA object classes using SuperVars as well as being able to make less space consuming classes with Objective-SCM. Having to rethink the offset according to the size you want to read may be a little annoying though... Another tip, for SCM functions, I like to store my important SuperVar indexes to a label of script memory and make a GOSUB which will read it, accessible by any SCM function. Saves having to pass the SuperVar as the first param for every SCM func, you just gotta make sure you store any params passed before reading the SuperVar index (if the SuperVar variable is [email protected]): :Push{\__(Val)__}0085: [email protected] = [email protected] @GetGlobalVarIndex0085: [email protected] = gStackPointer0085: [email protected]([email protected],4s) = [email protected]: gStackPointer += 4RET 0:Pop{\__[Val]__}GOSUB @GetGlobalVarIndex000E: gStackPointer -= 40085: [email protected] = gStackPointerRET 1 [email protected]([email protected],4s):GetGlobalVarIndexSET_BIT_L [email protected] 8SVar = @GLOBAL_VARIABLES_INDEX0085: SVar = SVar(SVar,4s)RETURN:GLOBAL_VARIABLES_INDEXHEX00000000END p.s. thank Silent for the idea of SuperVars installation checking and Objective-SCM name Edited March 2, 2013 by Deji Link to comment Share on other sites More sharing options...
Seemann Posted March 10, 2013 Share Posted March 10, 2013 I like this kind of projects and happy that SA modding is still alive because of you, guys! Keep it up Sanny Builder 3 • SA Memory Handling • OpenIV • gtamodding.com CLEO.li - The CLEO Library - Official site Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now