[WIP] Bindings to the AngelScript language.

Started by ., Nov 11, 2014, 09:34 PM

Previous topic - Next topic

.

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:

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

Neat.

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

.

#2
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:
// 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:
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 Nov 12, 2014, 01:40 AMNeat.

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.
.


.

Quote from: Gudio on Nov 13, 2014, 07:49 PMhttp://forum.vc-mp.org/?board=13.0 ??

I haven't seen that at first and I assumed it's disabled for some reason. Anyway, let's wait for a moderator/admin to move it or something.
.

.

#5
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.

// Moved over to PasteBin to preserver the indentation: http://pastebin.com/acYWb6qe
.

.

#6
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:
// 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::vehicle@ 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::vehicle@ 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::vehicle@ my_veh(VEHICLE_ID::SABRETURBO, my_player.world, my_player.position + as::vector3(-10, 0, 0), 0, as::rgb(), as::rgb());
vc::vehicle@ 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::vehicle@ 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::vehicle@ 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
.

.

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

Hi everybody!
I am building a new server and I use 64Bit server executables, so could you provide 64Bit version of modules?
Skype: MrMADRYAN-GREIS

Thijn

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.

.

#10
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.
.