[Plugin] [REL] Math Plugin
#21

Quote:
Originally Posted by JernejL
Посмотреть сообщение
Famalamalam: plugin is already working, if you want to test it before release just let me know.
Sure, that'd be great! Just pop me a PM or something with the details
Reply
#22

Quote:
Originally Posted by whitetigerswt
Посмотреть сообщение
Is this more accurate than the other ways of detecting who is being aimed at? Can this be used as a viable option to detect damage each player has dealt to other players?
It might work for that if ran fast.. say in onplayerupdate callback, but it would run on server simulation and it might not be what happens on the client in every case. I don't think that function is also very optimized to run in each player update - but we'll have to test once plugin is released.
Reply
#23

I added link to svn repository.

http://code.******.com/p/samp-mp/
Reply
#24

i would love some functions which care for Euler Angles / Quaternions. iam scripting on my object editor for ages yet, and i failed 3 times at including the GetVehicleRotationQuat for calculating some rotations.
there are so many sources on how to code matrices for converting/manipulating rotation quats, but the effort would freeze the server, and its a bit too hard to imagine 4 dimensional things >-<
anyways, by providing a rotation in that quat format makes it possible to interpolate between 2 totally different facing angles by using ONE quaternion-set...
why do i tell/ask/spam that?
imagine a race track editor, using all new street objects, which fit exactly together...
now imagine a 40 meter long road. then a ramp up, then a slight turn to the left.... aw screw it. brb, taking some vids now...
and here it is:

anyways, prepare for a challenge in maths if you dare to ^^
****** Quaternions/euler angles, this will link you to pure brain madness!
thank you for taking time to read through all this...
edit: oops. the axis got swapped. the "less important" axis is indeed the Z axis. i can rotate an even screwed map on the Z axis. that one which points up the sky
its a total mess to think about all that..
Reply
#25

Quote:
Originally Posted by JernejL
Посмотреть сообщение
I'm sure everyone will appreciate the benefits of running this in native C code for greater speed.
If you made this to increase the speed; then this plugin is kinda useless becasue in total speed won't increase or even would DECREASE.
You could simply do all of those as a 'Include' which is more useful for this purposes.

Maybe take a look more deeper what are plugins used for.
Reply
#26

Quote:
Originally Posted by ******
Посмотреть сообщение
WHAT? I think YOU need to look at what plugins are for and understand the difference between C++ and PAWN (and, more importantly, which is faster).
well sadly as much as my wording there failed - i meant plugin being FASTER, it is faster only when it comes to pure math functions.

pawn versions

Код:
	stock GetVehicleDriver(vehicleid) {
		
		for (new i; i<500; i++) {
			if (!IsPlayerConnected(i))
				continue;
			
			if (GetPlayerState(i) != PLAYER_STATE_DRIVER)
				continue;
			
			if (GetPlayerVehicleID(i) == vehicleid) {
				return i;
			}
		}
		return -1;
	}
c++ version:

Код:
int GetVehicleDriver(int vehicleid) {

    if ((vehicleid == 0) || (vehicleid == INVALID_VEHICLE_ID) || (vehicleid > MAX_VEHICLES))
        return INVALID_PLAYER_ID;

    int i;

    for (i = 0; i < max_players; i++) {

        if (invoke->callNative(&PAWN::IsPlayerConnected, i) == false) // no connected player in slot?
            continue;

            if (invoke->callNative(&PAWN::GetPlayerState, i) != PLAYER_STATE_DRIVER) continue; // not a driver of any vehicle?

            int thisplayervehid;
            thisplayervehid = invoke->callNative(&PAWN::GetPlayerVehicleID, i);

            // todo: maybe use IsPlayerInVehicle instead.

            if (thisplayervehid == vehicleid) // found a connected driver in this car.
                return i;

    }

    return INVALID_PLAYER_ID; // found no driver.

}
i'm using incognito's invoke, and for some reason in a benchmark my c++ version is 7x slower:

Код:
		#define MAXTEST 500
	 	
		new test1;
		test1 = GetTickCount();
		
		for(new a; a < 500; ++a) {
			MPGetVehicleDriver(1);
			//returnit(a);
		}
		
		printf("# MPGetVehicleDriver %d", GetTickCount() - test1);
	 	
		new test2;
		test2 = GetTickCount();
		
		for(new a; a < 500; ++a) {
			GetVehicleDriver(1);
		}
		
		printf("# GetVehicleDriver %d", GetTickCount() - test2);
Thanks to eXtreme for the tests and benchmark.

****** and other experts - any idea why the c++ version is slower? i managed to track down to invoke->callNative function.. so whenever i call sa-mp natives via invoke that's significantly slower than doing it in pawn (pure math functions work faster tho), so this is unacceptable to me.. if calling samp natives via invoke makes the whole thing slower than in pawn, i should just stop this project - there is no other option.

Also, full source: http://code.******.com/p/samp-mp/sou...e/#svn%2Ftrunk
Reply
#27

I think High Level languages tends to be slower than lowers.

Great plugin.
Reply
#28

You can try implenting MapAndreas into Aim functions. That way you could aim to a person through a building.
Reply
#29

Quote:
Originally Posted by JernejL
Посмотреть сообщение
****** and other experts - any idea why the c++ version is slower? i managed to track down to invoke->callNative function.. so whenever i call sa-mp natives via invoke that's significantly slower than doing it in pawn (pure math functions work faster tho), so this is unacceptable to me.. if calling samp natives via invoke makes the whole thing slower than in pawn, i should just stop this project - there is no other option.
I won't make any guesses as to why exactly that bit of code is so much slower than a PAWN implemenation. There are probably any number of reasons since the function does so many things each time it's called. It uses variadic macros, allocates and deallocates memory, loops through arrays, performs lookups in containers, and much more. I've always known that it's not the most optimal solution in terms of speed, but it is faster than simply calling the native from a public function inside the plugin.

Anyway, I've done some profiling and Zeex's gamemode SDK is clearly the winner here.

Код:
void methodOne()
{
	boost::chrono::high_resolution_clock::time_point begin = boost::chrono::high_resolution_clock::now();
	for (int i = 0; i < 1000000; ++i)
	{
		invoke->callNative(&PAWN::GetPlayerPos, playerid, &x, &y, &z);
	}
	boost::chrono::duration<double, boost::milli> end = boost::chrono::high_resolution_clock::now() - begin;
	logprintf("methodOne(): %g", end.count());
}
Код:
void methodTwo()
{
	boost::chrono::high_resolution_clock::time_point begin = boost::chrono::high_resolution_clock::now();
	for (int i = 0; i < 1000000; ++i)
	{
		samp::GetPlayerPos(playerid, x, y, z);
	}
	boost::chrono::duration<double, boost::milli> end = boost::chrono::high_resolution_clock::now() - begin;
	logprintf("methodTwo(): %g", end.count());
}
Код:
[07:20:48] methodOne(): 305.934
[07:20:48] methodTwo(): 22.3173
I will be using this in the next version of the streamer plugin.

Edit: I also don't mean to say that callNative is incredibly slow. In the test above, each call took about 300 nanoseconds (or 300 billionths of a second) to complete. That's still pretty fast, even if a PAWN implementation is a bit faster.
Reply
#30

Quote:
Originally Posted by ******
Посмотреть сообщение
WHAT? I think YOU need to look at what plugins are for and understand the difference between C++ and PAWN (and, more importantly, which is faster).
Thanks to JernejL for his quick answer :


Quote:
Originally Posted by JernejL
Посмотреть сообщение
so whenever i call sa-mp natives via invoke that's significantly slower than doing it in pawn (pure math functions work faster tho), so this is unacceptable to me.. if calling samp natives via invoke makes the whole thing slower than in pawn, i should just stop this project - there is no other option.
And you *****, Please when you don't know something don't discuss about it. In my option a spam is worth than giving out wrong informations.
Thanks
Reply
#31

Matttth Plugin, I will download this and keep it. Let the Magnet Turtles be with this Plugin!
Reply
#32

Been waiting for this for 2+ years
Reply
#33

Anyone else having the paths break when converting the project over to vc++ 2010?
Reply
#34

Is it safe to use the compiled Linux version?
Reply
#35

Quote:
Originally Posted by linuxthefish
Посмотреть сообщение
Is it safe to use the compiled Linux version?
Yes.
Reply
#36

Unfortunately, I'm not the greatest with math and can hardly understand how to properly use half of these functions. I was curious, as you PMed me awhile ago telling me you had a function that could do so, if one of these functions could be manipulated to allow correct vehicle offsets when placing objects on certain areas of the map like slopes. For example, if I wanted to place a trash bin on the side of a trash truck, while it's going uphill, using the default offsets wouldn't work.

Would you mind showing me a short example of how to make that work with one of these functions (of course if it's not already added that would be a possible suggestion)?

Thanks.
Reply
#37

Quote:
Originally Posted by Bakr
Посмотреть сообщение
Unfortunately, I'm not the greatest with math and can hardly understand how to properly use half of these functions. I was curious, as you PMed me awhile ago telling me you had a function that could do so, if one of these functions could be manipulated to allow correct vehicle offsets when placing objects on certain areas of the map like slopes. For example, if I wanted to place a trash bin on the side of a trash truck, while it's going uphill, using the default offsets wouldn't work.

Would you mind showing me a short example of how to make that work with one of these functions (of course if it's not already added that would be a possible suggestion)?

Thanks.
Ok, here's a small example:

pawn Код:
public OnPlayerKeyStateChange(PlayerID, NewKeys, OldKeys) {
   
    // pressing fire key
    if ((NewKeys & KEY_FIRE) && !(OldKeys & KEY_FIRE)) {
       
        if (IsPlayerInAnyVehicle(PlayerID)) {
           
            new vehtype;
            vehtype = GetVehicleModel(GetPlayerVehicleID(PlayerID));
           
            if (vehtype == 564) {// while in RC tiger
               
                new time;
                time = GetPVarInt(PlayerID, "LastTigerShot");
               
                if (time + 500 < TickCount()) {
                   
                    new Float:turretstart[3];
                    new Float:inp[3];
                   
                    inp[0] = 0.000; inp[1] = -1.2559; inp[2] = 0.3384;
                    MPProjectPointOnVehicle(GetPlayerVehicleID(PlayerID), inp[0], inp[1], inp[2], turretstart[0], turretstart[1], turretstart[2], 1);
                    CreateObject( 921, turretstart[0], turretstart[1], turretstart[2], 0.0, 0.0, 0.0);
                   
                    SetPVarInt(PlayerID, "LastTigerShot", TickCount()); // shot time
                }
            }
        }
    }
}
This is a bit modified code from what i use on partyserver.

When you hit fire key while inside a RC tiger, this will take the turret end point coordinates, and project them thru car's rotations to get exit coordinates in game world space, then create a small light object at those points.

An alternative would be, to extend the exit turret coordinates further, and create a explosion instead, this would make the RC tank able to fire / explode things properly.

Screenshot - notice that objects are placed correctly taking the rc tank's pitch / roll / yaw into account:



You can use this, and get trash van's specific coordinates to place trash cans behind it, it's easy to get coordinates on vehicles - place a car in my map editor at exact 0,0,0 coordinates with no rotation, then click on the vehicle and status bar will show you vehicle-based coordinates.
Reply
#38

Great! Thank you very much for the example, I got one of my desired projects working as I intended. Amazing how I spent hours upon hours trying to get the correct code to manipulate the coordinates like so (not including the time doing research), and it can all be done with a simple function now.

Very nice work on this plugin and your Map Editor.
Reply
#39

Some questions:

1) Could you please make a MPDistance2D?
2) Is MPDistance faster than PointToPoint3D in the PointToPoint plugin?
3) How is MPFDistance less accurate? :S Can you please give me examples of what MPDistance and MPFDistance will return using the same coordinates?
4) Does MPGetTrailerTowingVehicle loop through all vehicles to find the towing vehicle or do you keep track of trailers using OnPlayerUpdate and OnUnoccupiedVehicleUpdate?

Thanks
Reply
#40

I am sorry for my stupidity, but where do I get the .inc file?
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)