[WIP] Bindings to the AngelScript language.
[CLOSED] Hybrid GM (Dev-Log) »

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,801
[WIP] Bindings to the AngelScript language.
« on November 11th, 2014, 09:34 PM »Last edited on February 3rd, 2015, 07:08 AM
In the last few days I tried to write some more core in Squirrel but I noticed it's becoming quite annoying. Two main reasons are:
  • Dynamically Typed: Which means that almost half of my code is nothing but making sure I'm working with the correct type.
  • Hard to Debug: Most of the bugs and errors show at run-time and testing for each run-time possibility can get quite annoying.

So I decided to write my own scripting plugin. AngelScript was the first and best choice to do it. It had everything I need and more.

The implementation enforces an object oriented approach. You have a client interface and a server interface. And you must implement those in the script in order to receive events. There's only one instance of the class which implements the server interface and an instance of the class which implements the client interface for each player on the server.

This allows you to get a better encapsulation and stop worrying about global arrays of players and whatever you used to do in Squirrel.

To give you an example of what I mean here's a quick snippet (currently functional) of how this looks:

Code: [Select]
Moved to PastedBin to preserve indentation: http://pastebin.com/acYWb6qe

The current implementation is just experimental and a lot of the functionality is missing. This is just what I've done in the last 2-3 days. Currently the code above works. However even the slightest mistake crashes the server since there are no security measures.

There are a lot of bugs and mistakes in the code but keep in mind that this is just a prototype. I'm not familiar with the internal stuff of the VC:MP server/client. Therefore I always have to test before implementing anything.

The repository can be found here and some example binaries will be available soon (probably tonight).

I've used Code::Blocks dev-builds and MinGW-w64 GCC 4.9.1 rev3 x32 as my compilation tools.

EDIT 1:

Windows x32 binaries are available here. (extract the archive in your VC:MP server directory. make sure you backup before)

EDIT 2:

Windows x32 binaries are available here. (extract the archive in your VC:MP server directory. make sure you backup before)

EDIT 3:

Windows x32 binaries are available here. (extract the archive in your VC:MP server directory. make sure you backup before)

EDIT 4:

Windows x32 binaries are available here. (extract the archive in your VC:MP server directory. make sure you backup before)







.

Stormeus

  • VC:MP Developer
  • oh god how did i get here im not good w computer
  • Posts: 1,088
[WIP] Re: Bindings to the AngelScript language.
« Reply #1, on November 12th, 2014, 01:40 AM »
Neat.

If you want to make pull requests to the plugins so they'll be compatible as well, I'm cool with it.

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,801
[WIP] Re: Bindings to the AngelScript language.
« Reply #2, on November 13th, 2014, 01:21 AM »Last edited on November 13th, 2014, 03:03 AM
I've finally implemented the string and the stream  data types. The string data type implements all the standard operations found in C++ std::string and a few supplemental features. As for the stream data type I've used an approach similar to the one found in C++ iostream. Using the left shif operator <<. The stream data type is powered by the CPPFormat library. Without the CPPFormat library it wouldn't have been that easy to implement.

I'm a bit busy this month and I'll resume work as soon as possible. Next time I plan to implement the player interaction with weapons and vehicles. And probably start to look for bugs. I know there's plenty of them. I'll keep posting the progress here if there's any.

Example:
Code: [Select]
// Create a stream
fmt::stream s;
// Test a format specifier
s << fmt::pad("test", 8, '-');
// Use the format function
s.write(" {0:f} ", 1234.3245f);
// 15 arguments is the limit
s.write("-{0:d}-{1:f}-{2:d}-{3:f}-{4:d}-{5:f}-{6:d}-{7:f}-{8:d}-{9:f}-{10:d}-{11:f}-{12:d}-{13:f}-{14:d}",
0, 1.0f, 2, 3.0f, 4, 5.0f, 6, 7.0f, 8, 9.0f, 10, 11.0f, 12, 13.0f, 14);
// Print it's contents
print(s.str);

Output:
Code: [Select]
test---- 1234.324463 -0-1.000000-2-3.000000-4-5.000000-6-7.000000-8-9.000000-10-11.000000-12-13.000000-14
Quote from stormeus on November 12th, 2014, 01:40 AM
Neat.

If you want to make pull requests to the plugins so they'll be compatible as well, I'm cool with it.
Unfortunately AngelScript doesn't have support for modules. It's using native calling conventions and registering functions from another DLL wouldn't be possible (AFAIK). I plan to have all the "modules" built in the plugin.

EDIT:

The permissions for downloading the binaries have been fixed.
.

Gudio

  • Full Member
  • Gudio.eu
  • Posts: 125

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,801
[WIP] Re: Bindings to the AngelScript language.
« Reply #5, on November 13th, 2014, 09:29 PM »Last edited on November 13th, 2014, 09:33 PM
A lot of updates, fixes, improvements and restructuring in the existing code. Overall syntax improved thanks to the new stream data type. The server no longer crashes on script mistakes. Now the errors are properly reported to the console output.

Updated binaries are available in the first post.

The syntax looks much cleaner now. But I still have a lot more work to do before it can be used.

Code: [Select]
// Moved over to PasteBin to preserver the indentation: http://pastebin.com/acYWb6qe
[WIP] Re: Bindings to the AngelScript language.
« Reply #6, on November 14th, 2014, 02:16 AM »Last edited on November 14th, 2014, 09:38 AM
I finally got around and implemented the player and vehicle interaction. You have both functions and operators to do this. Some of the changes aren't committed to the repository because it hasn't been completely tested.

The syntax is quite easy to use and should work with anyone's style of coding:
Code: [Select]
// Get a vehicle model to obtain information about that vehicle
as::vehicle_model my_model(VEHICLE_ID::SABRETURBO);
as::vehicle_model my_model(206);
as::vehicle_model my_model("Sabre Turbo");

// You can also extract the vehicle model from another vehicle
as::vehicle_model my_model(my_veh);

// Use that vehicle module as a blueprint to create one or more vehicles with the same model
vc::[email protected] my_veh = my_model.vehicle(my_player.world, my_player.position + as::vector3(-10, 0, 0), 0, as::rgb(), as::rgb());

// Create a vehicle using any of the overloaded constructors

// Using the vehicle model we created above
vc::[email protected] my_veh(my_model, my_player.world, my_player.position + as::vector3(-10, 0, 0), 0, as::rgb(), as::rgb());

// Pass the vehicle model ID directly
vc::[email protected] my_veh(VEHICLE_ID::SABRETURBO, my_player.world, my_player.position + as::vector3(-10, 0, 0), 0, as::rgb(), as::rgb());
vc::[email protected] my_veh(206, my_player.world, my_player.position + as::vector3(-10, 0, 0), 0, as::rgb(), as::rgb());

// Pass the vehicle model name directly
vc::[email protected] my_veh("Sabre Turbo", my_player.world, my_player.position + as::vector3(-10, 0, 0), 0, as::rgb(), as::rgb());

// Using another vehicle to extract the model, world, color etc. except the position
vc::[email protected] my_veh(another_veh, my_player.world, my_player.position + as::vector3(-10, 0, 0), 0, as::rgb(), as::rgb());

// ALL OF THE ABOVE CODE ACHIEVE THE SAME THING

// When the arrows point from the player instance to the vehicle instance
// then the player embarks in that vehicle

// Get in the vehicle
my_veh << my_player;
// Get in the vehicle
my_player >> my_veh;

// When the arrows point from the vehicle instance to the player instance
// then the player disembarks from that vehicle

// Get out the vehicle
my_veh >> my_player;
// Get out the vehicle
my_player << my_veh;

// Direct functions are also available also on both player and vehicle

my_veh.embark(my_player);

my_player.embark(my_veh);

// They all have multiple overloads to allow you to customize the result

// Extra arguments are: int slot, bool make_room, bool warp
my_veh.embark(my_player, 0, true, true);
// Extra arguments are: int slot, bool make_room, bool warp
my_player.embark(my_veh, 0, true, true);

my_player.disembark();

Snippet is also available on PasteBin: http://pastebin.com/ZYakLV4H
[WIP] Re: Bindings to the AngelScript language.
« Reply #7, on November 16th, 2014, 01:33 PM »
Development is postponed until I get some free time. The current prototype is almost done and quite functional. And since the prototype is finished and works I'll start a private repository to begin working on the real deal (when I get the time of course). Now that I've seen the flaws in the current implementation it's time to take different approach on things. The binaries to the last commit are available for testing but there is no documentation at the moment.
.

MrMADRYAN

  • Newbie
  • Posts: 3
[WIP] Re: Bindings to the AngelScript language.
« Reply #8, on August 15th, 2016, 09:13 PM »
Hi everybody!
I am building a new server and I use 64Bit server executables, so could you provide 64Bit version of modules?

Thijn

  • VC:MP Beta Tester
  • Posts: 1,689
[WIP] Re: Bindings to the AngelScript language.
« Reply #9, on August 15th, 2016, 09:30 PM »
The last post was 21 months ago. There's been no updates or progress, so I suggest you start with the Squirrel language using the official plugins.

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,801
[WIP] Re: Bindings to the AngelScript language.
« Reply #10, on August 15th, 2016, 09:35 PM »Last edited on August 15th, 2016, 09:42 PM
This project was aborted because it was too complex for the average VCMP user. Also, I had a personal issue with the standard library that the language comes with. Which was that it doesn't provide any. Because it has no standard library except a very generic one as an example. The language has no idea about strings, arrays, hash-maps etc. It expects the user to implement them and currently it does not provide an efficient way to do so. Which is why it was discontinued. The language is still superior to squirrel in every way possible. But it needs some time to mature.

Like the @Thijn said. The project was abandoned for the time being. My mistake for not closing it. I did not expect someone to actually wake it up from it's deep sleep.

If you are looking for an alternative to the official squirrel plugin then you may consider this. However, that project might soon follow in the footsteps of this one. Simply because I lost interest in vcmp.
.