Jump to content
naught

Object Oriented SQF Scripting and Compiling

Recommended Posts

:// so, how can we set a position private variable ?

MEMBER("position", [0,0,0]);

if i understand, if BIS add somes preprocessor features more elaborated we can do better thing ?

Share this post


Link to post
Share on other sites
:// so, how can we set a position private variable ?

MEMBER("position", [0,0,0]);

if i understand, if BIS add somes preprocessor features more elaborated we can do better thing ?

/* You can use either this: */

private ["_var"];
_var = [0,0,0];
MEMBER("position",_var);

/* Or this: */

#define VAR [0,0,0]
MEMBER("position",VAR);

And yes, if local paths are fixed (ie. "../") then it would be easier to include files within a mission and make it feasible to include a header in each file, but the array-comma issue in macros is a problem that would just slow the preprocessor down for close to no benefit since other alternatives are available.

Share this post


Link to post
Share on other sites

mmm, i did another try

#include "oop.h"

CLASS("INSTANCE")
	PRIVATE VARIABLE("array","position");
	PUBLIC FUNCTION("object","constructor") {
		private ["_position"];
		_position = [0,0,0];
		MEMBER("position", _position);
	};
	PUBLIC FUNCTION("array","getPosition") FUNC_GETVAR("position");
	PUBLIC FUNCTION("array","setPosition") {
		MEMBER("position",_this);
	};
	PUBLIC FUNCTION("string","deconstructor") {
		DELETE_VARIABLE("position");
	};
ENDCLASS;

_instance = ["new"] call INSTANCE;
["setPosition", position player] call _instance;
_position = "getPosition" call _instance;

hint format["%1", _position];

it seems _position is undefined now, it s a bit complex to fix it :(

Share this post


Link to post
Share on other sites
mmm, i did another try

#include "oop.h"

CLASS("INSTANCE")
	PRIVATE VARIABLE("array","position");
	PUBLIC FUNCTION("object","constructor") {
		private ["_position"];
		_position = [0,0,0];
		MEMBER("position", _position);
	};
	PUBLIC FUNCTION("array","getPosition") FUNC_GETVAR("position");
	PUBLIC FUNCTION("array","setPosition") {
		MEMBER("position",_this);
	};
	PUBLIC FUNCTION("string","deconstructor") {
		DELETE_VARIABLE("position");
	};
ENDCLASS;

_instance = ["new"] call INSTANCE;
["setPosition", position player] call _instance;
_position = "getPosition" call _instance;

hint format["%1", _position];

it seems _position is undefined now, it s a bit complex to fix it :(

When you call getPosition, you're passing a nil parameter to the object, but since your getPosition object member actually expects an array (look below), it won't find an available member and return nil.

So this:

PUBLIC FUNCTION("array","getPosition") FUNC_GETVAR("position");

Should be this:

PUBLIC FUNCTION("","getPosition") FUNC_GETVAR("position");

Share this post


Link to post
Share on other sites
When you call getPosition, you're passing a nil parameter to the object, but since your getPosition object member actually expects an array (look below), it won't find an available member and return nil.

I understand that an array is expected as argument, but i don't understand how the search/eval is done.

If i well understand we can have 2 functions with the same name but different arguments expected ?

example:

PUBLIC FUNCTION("","getPosition") FUNC_GETVAR("position");
PUBLIC FUNCTION("string","getPosition") {
hint _this;
};

Edited by code34

Share this post


Link to post
Share on other sites
I understand that an array is expected as argument, but i don't understand how the search/eval is done.

If i well understand we can have 2 functions with the same name but different arguments expected ?

example:

PUBLIC FUNCTION("","getPosition") FUNC_GETVAR("position");
PUBLIC FUNCTION("string","getPosition") {
hint _this;
};

Yes, you can, it searches top-down for any function which both its name and parameters (note: return value is NOT specified) match. If none match, it looks for any parents classes (or any classes which it extends) and runs the search there, and this will end and return null when the search is inconclusive and no more parents are found.

Share this post


Link to post
Share on other sites

mmm, ok interresting :) do you make some benchmark test to compare thoses objects vs other build in object like memory or cpu test ?

Share this post


Link to post
Share on other sites
mmm, ok interresting :) do you make some benchmark test to compare thoses objects vs other build in object like memory or cpu test ?

I'm assuming you mean comparing the objects that this OOP header creates and those that are built-in to the engine (like units, groups, etc.), and without benchmarking I can tell you that the built-in objects are going to be much faster since they're in native code and don't need to be interpreted like SQF - although when it comes to objects built in SQF, this is as fast as you can get since it uses high-speed switch statements for completely linear performance, and each case for the main switch statement implements lazy evaluation for minimal checking.

Share this post


Link to post
Share on other sites
I'm assuming you mean comparing the objects that this OOP header creates and those that are built-in to the engine (like units, groups, etc.), and without benchmarking I can tell you that the built-in objects are going to be much faster since they're in native code and don't need to be interpreted like SQF - although when it comes to objects built in SQF, this is as fast as you can get since it uses high-speed switch statements for completely linear performance, and each case for the main switch statement implements lazy evaluation for minimal checking.

i think it s not it depends of the usecase. I made some bench, in my case, i compare buildin logic object with "INSTANCE" code (above), cause i use logic as variable container and as object with a position on map.

I made the bench with more than 5000 objects.

Create "INSTANCE" and set its position is 70% faster than createvehicle a logic at a position.

When i use the access methods, the performance are a bit slower for "INSTANCE" but logic have a nasty effect on FPS and ... OO give a lot of more possibilities so its very interesting ;)

Edited by code34

Share this post


Link to post
Share on other sites

then Guy, i did some OO tests this week end.

This is so Nice ! I just start to introduce some objects in my mission.

How many time do you spend to make this magic oop.h ? :)

Share this post


Link to post
Share on other sites
then Guy, i did some OO tests this week end.

This is so Nice ! I just start to introduce some objects in my mission.

How many time do you spend to make this magic oop.h ? :)

It too about 3 hours for the first iteration, and it took about 2 more hours of further testing and upgrading to reach its current point.

I'm glad you're interested in OOP, it really increases throughput of coding time when you're working on large projects or in teams since you can settle down and focus on one object and its behaviors instead of having to worry about the entire project and how it'll fit together.

Share this post


Link to post
Share on other sites
It too about 3 hours for the first iteration, and it took about 2 more hours of further testing and upgrading to reach its current point.

Do you have already do this work on other langage ? I don't understand why BIS hadn't already do it before.

I already see the benefit, i developped a simple class this week end that i can t develop with procedural development without hundred and hundred lines ;)

Share this post


Link to post
Share on other sites

Hi Naught, great work. thanks

I am very interested in this approach to scripting.

And in the future, I want to wrap up your work as a module that would oop.h file was available from any folder / subfolder in the mission.

Where can I get the complete documentation describing the methods that I use in class and in the context of an object from the "code"?

Edited by Aloe
My error

Share this post


Link to post
Share on other sites

Hi Aloe

Informations are directly in the oop.h file or on the first page of this thread :)

Share this post


Link to post
Share on other sites

Sadly, all links to the oop.h file are down for me?!?

If it's not just me, could anyone send me the file that already downloaded it?

thanks

Edited by Lappihuan

Share this post


Link to post
Share on other sites

Yes, but I was wondering if I can use macros, see "Group: Internal Macros", without unforeseen consequences:

ENSURE_INDEX, CHECK_THIS, CHECK_ACCESS, CHECK_TYPE, CHECK_NIL, CHECK_MEMBER, CHECK_VAR, GETVAR, GETSVAR, GETCLASS, CALLCLASS, MOD_VAR, INC_VAR, DEC_VAR, PUSH_ARR, REM_ARR, GET_AUTO_INC?

Some of these macros are used in first post, I would like to know the full set of available macros

Share this post


Link to post
Share on other sites

i think there is no problem if you don't insert macro with already reserved keys (look #define lines) or with enclosed bracket or enclosed chars, that can break the oop.h macros :)

Share this post


Link to post
Share on other sites

code34, I'm afraid you have not understood correctly, this is all the difficulties of translation. I have not (yet) going to expand macros. While only want to know which macros can use and which are not

Share this post


Link to post
Share on other sites

yes : )) but we try !

Into the internal group you can normaly use thoses macro. Others are really oriented for the internal working of the oop.h itself

#define GETVAR(var) (_classID + "_" + var)
#define INC_VAR(varName) MOD_VAR(varName,1)
#define DEC_VAR(varName) MOD_VAR(varName,-1)
#define PUSH_ARR(varName,array) MOD_VAR(varName,array)
#define REM_ARR(varName,array) MOD_VAR(varName,array)

---------- Post added at 21:35 ---------- Previous post was at 21:22 ----------

Sadly, all links to the oop.h file are down for me?!?

If it's not just me, could anyone send me the file that already downloaded it?

thanks

No news from Naught since a long while, it seems he deleted most of his Arma work :(

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×