Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Blog: "Tech feature: Scripting upgrade"
nemesis567 Offline
Posting Freak

Posts: 874
Threads: 65
Joined: May 2011
Reputation: 10
#11
RE: Blog: "Tech feature: Scripting upgrade"

Very nice. It's now more similar to what I'm used to script.
If I can give out some suggestions you should add:

-Directional lights(I suppose that's what you mean with sun light)
-Post Process Effects;
-Particle Emitters that emit static objects.
-Fluids(can be generated with particle emitters that emit soft bodies).
-Soft Bodies.
-In Editor animator.
-Make the use of coordinates available for the script, so functions such as SetPlayerPos(float X, float Y, float Z) or even MoveObject(X, Y, Z, Speed) where X, Y, Z is a vector, or even GetPlayerSpeed()which returns the speed vector.
-Allow the use of includes to ease up the script creation(#include ScriptAddon XXX)
-Add defines to ease up the call of some globals(#define WHATEVER "String0")
-Add a function to display an image on the player screen(DisplayFromFile("", X, Y).
-Add a function to enable FOV and to set it.
-Make it possible to create physic constraints/hinges/motors and what so on inside the editor.
-Add a lightmass system(So the shadows become more realistic without having to place 100 lights in the same level).
-Add customizable UI's Via script(Image appears in the screen via 2d coordinates, and objects such as buttons are created the same way.) CreateUIButton(string Name, float X, float, Y, float Xf, float Yf) X and Y defines the point of the first vertice of the rectangle and the others of the last.


If you think my suggestion may become usefull sometime, I can suggest a whole book in here. Otherwise I'll just suggest nothing else Tongue. Just trying to help.

Today I dreamt the life I could live forever. You only know that when you feel it for you know not what you like until you've experienced it.
05-30-2011, 02:13 PM
Find
MrBigzy Offline
Senior Member

Posts: 616
Threads: 18
Joined: Mar 2011
Reputation: 8
#12
RE: Blog: "Tech feature: Scripting upgrade"

Some of these already exist actually, like changing FOV and hinges (in the model editor).
05-31-2011, 01:54 AM
Find
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#13
RE: Blog: "Tech feature: Scripting upgrade"

I decided to expand on the discussion started with Thomas back at the blog here, 'cause the forums are more readable and support code formatting, as well because I wanted to avoid all the hassle with Bloggers spam filter (the thing is on the loose!).

OK, in summary Thomas expressed his concerns about (1) the possibility of creating a function that would act only on specific instances of a specific class, and (2), the fact that AngelScript does not allow for script-side class to be derived from a C++ class (or an exposed class even).

So, Thomas, you ended your last comment with:
Quote:Problem is that AngelScript does not let classes declared in script inherit from classes I implement in C++ code.

I know, but you're not hearing me: why do you feel the need to derive from the C++ class in the first place?
In any case, always remember that composition is a flexible alternative for inheritance.

You have several options - let's start with the straightforward one.
Say you have a C++ class that represents an entity or something else in the game, and you want to expose it to AngelScript.
Well, (1) is easily solved by making the function in question a member function of the C++ class, and exposing it as a member method of it's script counterpart. As any instance method (function), it will operate only on instance-specific data.
As for (2), as I've said - you don't actually need it. Once exposed, the script version of the class act's as an out-of-engine API to the C++ class. Every method call is delegated back to the corresponding function call on the corresponding object, so semantically it's just like using the C++ class in C++ code on it's own.
If you really need to extend the functionality of the exposed class in-script, you can use a little trick [the following is all script-side]: create a wrapper class in AngelScript, that contains the exposed C++ class as a member variable; then wrap all the methods, by simply calling the corresponding ones on the member var.
The AngelScript will not prevent you to inherit from the wrapper class.

As I've said on the blog, in order to test all this, I downloaded the AngelScript SDK, and set it up to work with a simple console app.

So here's the sample class declaration (C++):
class ClassToExpose
{
private:
    static int s_instanceCount;
    int m_refCount;
    int m_id;

public:
    ClassToExpose(void);
    virtual ~ClassToExpose(void);    
    
    // let's say that GetDescription() is the function in question.
    string GetDescription();
    void AddRef();
    void Release();
};

// Note that the factory function used by AngelScript to create the
// instance of the exposed class actually creates a C++ instance.
ClassToExpose* ObjectFactory();

Some implementation details of interest (C++):
ClassToExpose::ClassToExpose(void)
{
    m_refCount = 1;
    s_instanceCount++;  // static, keeps track of the overall number of instances created
    m_id = s_instanceCount; // the idea is to show later in script that objects are indeed different
}

//...

string ClassToExpose::GetDescription()
{
    // This just uses the m_id to identify the instance later in the script
    stringstream out;
    out << m_id;
    return string("[ I'm a class exposed from C++! (").append(out.str()).append(") ]");
}

Next step was to set it all up, along with some global helper functions (C++):
engine->RegisterGlobalFunction("void Write(const string &in)", asFUNCTION(Write), asCALL_CDECL);
    engine->RegisterGlobalFunction("void WriteLine(const string &in)", asFUNCTION(WriteLine), asCALL_CDECL);


    engine->RegisterObjectType("ScriptClass", NULL, asOBJ_REF);
    
    engine->RegisterObjectBehaviour("ScriptClass", asBEHAVE_FACTORY, "ScriptClass@ f()",
        asFUNCTION(ObjectFactory), asCALL_CDECL);
    
    engine->RegisterObjectBehaviour("ScriptClass", asBEHAVE_ADDREF, "void f()",
        asMETHOD(ClassToExpose, AddRef), asCALL_THISCALL);

    engine->RegisterObjectBehaviour("ScriptClass", asBEHAVE_RELEASE, "void f()",
        asMETHOD(ClassToExpose, Release), asCALL_THISCALL);

    engine->RegisterObjectMethod("ScriptClass", "string GetDescription()",
        asMETHOD(ClassToExpose, GetDescription), asCALL_THISCALL);

And now the fun part (AngelScript code):
void main()
{
    ScriptClass o;
    WriteLine(o.GetDescription());
    
    ScriptClass o1;
    WriteLine(o1.GetDescription());
    
    Wrapper w;
    WriteLine(w.GetDescription());
    
    DerivedWrapper dw;
    WriteLine(dw.GetDescription());
}

class Wrapper
{
    ScriptClass o;
    
    Wrapper()
    {
    }
    
    ~Wrapper()
    {
    }
    
    string GetDescription()
    {
        return "{Wrapper: " + o.GetDescription() + "}";
    }
}

class DerivedWrapper : Wrapper
{
    string GetDescription()
    {
        return "{DerivedWrapper -- " + Wrapper::GetDescription() + "}";
    }
}

The output:
[ I'm a class exposed from C++! (1) ]
[ I'm a class exposed from C++! (2) ]
{Wrapper: [ I'm a class exposed from C++! (3) ]}
{DerivedWrapper -- {Wrapper: [ I'm a class exposed from C++! (4) ]}}

Now, if your C++ class is not meant to be directly exposed to AngelScript for some reason, but you still need to use it's functions, there are two ways to go.

First, you can derive (in C++) from that class, and then expose the derived version, or you could write a C++ wrapper that would contain an instance of the original class (possibly sharing a parent/ancestor with it), and expose the wrapper.

I hope that helps.

P.S. If you spot some peculiarities about the C++ code, that's because I'm actually a C# programmer, but I think I managed to illustrate the point. And if there's something off that's important, please point it out.
(This post was last modified: 05-31-2011, 11:05 AM by TheGreatCthulhu.)
05-31-2011, 10:55 AM
Find
Thomas Offline
Frictional Games

Posts: 2,634
Threads: 184
Joined: Apr 2006
Reputation: 68
#14
RE: Blog: "Tech feature: Scripting upgrade"

TheGreatCthulhu:
Ah yeah! Of course you can just skip the whole inheritance thing and just let it the ScriptObject be a member.

Not given this a thought so thanks a bunch for the tip!

The wrapping is also a nice idea that I might use.

I am going to implement scripting today or tomorrow so can look this over and see how it works.
05-31-2011, 12:06 PM
Find
Doctorcheese Offline
Senior Member

Posts: 272
Threads: 28
Joined: Jan 2011
Reputation: 0
#15
RE: Blog: "Tech feature: Scripting upgrade"

Wish I could script... makes my head hurt though.

''Sick, twisted child... You'll burn for this!''
06-09-2011, 09:02 PM
Find
ChoskarChulian Offline
Junior Member

Posts: 32
Threads: 8
Joined: Jul 2011
Reputation: 0
#16
RE: Blog: "Tech featuScripting upgrade"

(06-09-2011, 09:02 PM)Doctorcheese Wrote: Wish I could script... makes my head hurt though.

Same here. Smile

07-08-2011, 10:20 PM
Website Find
Thomas Offline
Frictional Games

Posts: 2,634
Threads: 184
Joined: Apr 2006
Reputation: 68
#17
RE: Blog: "Tech feature: Scripting upgrade"

For got say another round of thanks for TheGreatCthulhu for the idea. If you check #2 of the script overview video you can see that a system similar to his suggestion is now in!

http://www.youtube.com/watch?v=UmQjO1C_Q90?hd=1
07-13-2011, 05:53 PM
Find
xtron Offline
Senior Member

Posts: 402
Threads: 37
Joined: May 2011
Reputation: 2
#18
RE: Blog: "Tech feature: Scripting upgrade"

And this is why I'm greatfull to be Swedish Tongue <3 Frictionalgames.

[Image: 44917299.jpg]Dubstep <3
07-14-2011, 03:16 PM
Find
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#19
RE: Blog: "Tech featuScripting upgrade"

(07-13-2011, 05:53 PM)Thomas Wrote: For got say another round of thanks for TheGreatCthulhu for the idea. If you check #2 of the script overview video you can see that a system similar to his suggestion is now in!

http://www.youtube.com/watch?v=UmQjO1C_Q90?hd=1

Smile You're welcome.

After seeing the video, I became a bit curious if there was a documentation generator for AngelScript (Idea), and I came across this post at gemedev.net, where a user said:
Quote:Thought I would update youall. NaturalDocs works splendidly with Angelscript!!!

I haven't tried it myself, so I can't warrant for quality, buy I've checked out NaturalDocs site, and it looks really decent, and seems to be pretty customizable. It uses it's own, non-invasive, readable style for it's documentation comments, but it supports Javadoc-style comments as well; it's also free - open source.

With the amount of scripting involved, I thought you'd like to check it out.
http://www.naturaldocs.org/

See you around, and keep up the good work. Big Grin
(This post was last modified: 07-14-2011, 05:13 PM by TheGreatCthulhu.)
07-14-2011, 05:10 PM
Find




Users browsing this thread: 1 Guest(s)