SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Plugin Development (https://forum.sa-mp.com/forumdisplay.php?f=18)
-   -   Gamemode SDK for C/C++ (GDK) (https://forum.sa-mp.com/showthread.php?t=421090)

xeeZ 08/03/2013 07:08 AM

Gamemode SDK for C/C++ (GDK)
 
NEW: Setting up GDK with CMake

Gamemode SDK for C/C++ (GDK)

The GDK (Gamemode Development Kit) allows you to write SA-MP gamemodes in C/C++. It provides most the functions you would find in Pawn, except those that overlap with the C standard library, like file I/O or string functions, or could be easily implemented on top of it. Callbacks are supported as well.

Example

Here's a "Hello, World!" gamemode:

pawn Code:
#include <stdio.h>
#include <string.h>

#include <sampgdk/a_players.h>
#include <sampgdk/a_samp.h>
#include <sampgdk/core.h>
#include <sampgdk/sdk.h>

using sampgdk::logprintf;

void SAMPGDK_CALL PrintTickCountTimer(int timerid, void *params) {
  logprintf("Tick count: %d", GetTickCount());
}

PLUGIN_EXPORT bool PLUGIN_CALL OnGameModeInit() {
  SetGameModeText("Hello, World!");
  AddPlayerClass(0, 1958.3783f, 1343.1572f, 15.3746f, 269.1425f, 0, 0, 0, 0, 0, 0);
  SetTimer(1000, true, PrintTickCountTimer, 0);
  return true;
}

PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerConnect(int playerid) {
  SendClientMessage(playerid, 0xFFFFFFFF, "Welcome to the HelloWorld server!");
  return true;
}

PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerRequestClass(int playerid, int classid) {
  SetPlayerPos(playerid, 1958.3783f, 1343.1572f, 15.3746f);
  SetPlayerCameraPos(playerid, 1958.3783f, 1343.1572f, 15.3746f);
  SetPlayerCameraLookAt(playerid, 1958.3783f, 1343.1572f, 15.3746f, CAMERA_CUT);
  return true;
}

PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerCommandText(int playerid, const char *cmdtext) {
  if (strcmp(cmdtext, "/hello") == 0) {
    char name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    char message[MAX_CLIENT_MESSAGE];
    sprintf(message, "Hello, %s!", name);
    SendClientMessage(playerid, 0x00FF00FF, message);
    return true;
  }
  return false;
}

PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() {
  return sampgdk::Supports() | SUPPORTS_PROCESS_TICK;
}

PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) {
  return sampgdk::Load(ppData);
}

PLUGIN_EXPORT void PLUGIN_CALL Unload() {
  sampgdk::Unload();
}

PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() {
  sampgdk::ProcessTick();
}

Full code

Download

To download binary packages for Windows and Linux please visit this page.

Source code

The source code is hosted on GitHub.

Hoda 08/03/2013 07:20 AM

Re: Gamemode SDK for C/C++ (GDK)
 
The most useful plugin for SA-MP !
Is this integrated to 0.3x with all functions ?
Offtopic :
By the way are you really the Zeex ?!!1??

RajatPawar 08/03/2013 07:22 AM

Re: Gamemode SDK for C/C++ (GDK)
 
I know C++ and so I can certainly code in this, but may I know the advantages of this?

Hoda 08/03/2013 07:31 AM

Re: Gamemode SDK for C/C++ (GDK)
 
Do you mean you know C++ syntax by 'I know C++' !?
This is not enough.

Advantages :
OOP
CLR (.NET) useful classes.
Speed improvement in calculations.

And every single advantage which I have mentioned worth to whole SA-MP project !

RajatPawar 08/03/2013 07:34 AM

Re: Gamemode SDK for C/C++ (GDK)
 
Nah, I know C++ as in the better way, not the syntax way. Well, not that great, but oKay.
1st advantage and the 3rd makes sense to me!

GWMPT 08/03/2013 08:23 AM

Re: Gamemode SDK for C/C++ (GDK)
 
Quote:

Originally Posted by Rajat_Pawar (Post 2417466)
I know C++ and so I can certainly code in this, but may I know the advantages of this?

Advantages:
  • Possiblity to do OOP
  • Possiblity to use namespaces
  • You can implement other c/++ code on the server, for example, mysql , sockets, and so on.
  • Possiblity of have dynamic arrays
  • Possiblity of using the multithreading system
  • Etc

Disadvantages:
  • The processing speed on the server is slower than using pawn.

Hoda 08/03/2013 08:49 AM

Re: Gamemode SDK for C/C++ (GDK)
 
Quote:

Originally Posted by klklt0 (Post 2417532)
Advantages:
  • Possiblity to do OOP
  • Possiblity to use namespaces
  • You can implement other c/++ code on the server, for example, mysql , sockets, and so on.
  • Possiblity of have dynamic arrays
  • Possiblity of using the multithreading system
  • Etc

Disadvantages:
  • The processing speed on the server is slower than using pawn.

Off topic :
Are you trying to increase your post count or what ?
No one of your advantages are more than what I have already wrote.

On Topic :
However your named disadvantage is completely false. The C++ or any compiled native CPU opcode processing is much much faster than a scripting language which depends on it's run-times.

The only speed decrease is for calling pawn native functions which in no way this count as processing speed !

Also for you knowledge, so next time you wont make false responses. When total speed is increased you can't count this as disadvantage; no matter if it's in processing field or anything else; it is NOT counted as disadvantage.


More :
Most of scripting for SA-MP is calculations and rarely script calls native pawn functions [only SA-MP includes]
It's usually called when processing is finished.
So to everybody who is going to use this plugin except speed increasing and not decreasing in total.

GWMPT 08/03/2013 08:59 AM

Re: Gamemode SDK for C/C++ (GDK)
 
Quote:

Originally Posted by Hoda (Post 2417555)
Off topic :
Are you trying to increase your post count or what ?
No one of your advantages are more than what I have already wrote.

Then just look for the posts you've done, because you just have 5 posts, and you're still spamming like hell.

Quote:

Originally Posted by Hoda (Post 2417555)
However your named disadvantage is completely false. The C++ or any compiled native CPU opcode processing is much much faster than a scripting language which depends on it's run-times.

The only speed decrease is for calling pawn native functions which in no way this count as processing speed !

Also for you knowledge, so next time you wont make false responses. When total speed is increased you can't count this as disadvantage; no matter if it's in processing field or anything else; it is NOT counted as disadvantage.

Lol? SA-MP main script is PAWN, so every script called in PAWN will automatically get performed.
PLUGINS will get processed when the SCRIPT call him or whatsoever, so AUTOMATICALLY the processing SPEED is SLOWER.
Sa-mp pawn script calls the plugin
Sa-mp server will proccess the call.
Plugin will receive the call from the sa-mp server
plugin will proccess the call AWAY from the SA-MP server.
then plugin will return the reply for the server
which the server will return for the value defined to return on the function.


Isn't it more slower than pawn?:
Sa-mp script calls the function
SA-MP server process the call
SA-MP server returns the value defined to return on the function.

So SA-MP plugins takes more time to be proccessed, and not the sa-mp functions for pawn.
So it's a disadvantage.

And once again, THIS IS A FORUM, remember that.

Hoda 08/03/2013 09:10 AM

Re: Gamemode SDK for C/C++ (GDK)
 
You even didn't try this plugin.. no game-mode or any pawn code call this plugin functions.

I leave this to experienced guys and those who are going to benchmark this because of your lacking of knowledge will just take away my time.

GWMPT 08/03/2013 09:33 AM

Re: Gamemode SDK for C/C++ (GDK)
 
Quote:

Originally Posted by Hoda (Post 2417567)
You even didn't try this plugin.. no game-mode or any pawn code call this plugin functions.

I leave this to experienced guys and those who are going to benchmark this because of your lacking of knowledge will just take away my time.

Lack of knowledge?
Cmon, you should be joking with me

Just a noob don't know that having a gamemode based on a plugin it is still going to be on the same speed.
C/++ is a Impressive language, YES IT IS!, c++ is used here to give more functionality to pawn, not to write full gamemodes on it!
And you still say a Lack of knowledge?

A plugin to be executed will use more ram than the server function and script himself-
You still say a lack of knowledge?

This plugin can be runned without the .pwn script being created, but it still get's called BY THE SERVER to be executed, so it will be always more slower than the pawn script!
And you still say a lack of knowledge?

I am on a programming course for more than 1 year now, but since 4 years ago i script in c/++ based languages[php, java, javascript, c#, squirrel] as well on non c++ based languages[lua, python, delphin, pascal]
And you still say a lack of knowledge?

Just look for you, most likely you can't even declare a function in c/++ with OOP and Namespace.
And you still say a lack of knowledge?


All times are GMT. The time now is 02:36 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.