SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 08/03/2013, 07:08 AM   #1
xeeZ
Huge Clucker
 
Join Date: Feb 2013
Posts: 321
Reputation: 380
Default 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:

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.

Last edited by xeeZ; 25/08/2014 at 09:12 AM.
xeeZ is offline   Reply With Quote
Old 08/03/2013, 07:20 AM   #2
Hoda
Little Clucker
 
Join Date: Mar 2013
Posts: 24
Reputation: 4
Default 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??
Hoda is offline   Reply With Quote
Old 08/03/2013, 07:22 AM   #3
RajatPawar
High-roller
 
RajatPawar's Avatar
 
Join Date: Aug 2011
Location: ヽ༼ຈل͜ຈ༽ノ
Posts: 2,313
Reputation: 311
Default 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?
RajatPawar is offline   Reply With Quote
Old 08/03/2013, 07:31 AM   #4
Hoda
Little Clucker
 
Join Date: Mar 2013
Posts: 24
Reputation: 4
Default 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 !
Hoda is offline   Reply With Quote
Old 08/03/2013, 07:34 AM   #5
RajatPawar
High-roller
 
RajatPawar's Avatar
 
Join Date: Aug 2011
Location: ヽ༼ຈل͜ຈ༽ノ
Posts: 2,313
Reputation: 311
Default 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!
RajatPawar is offline   Reply With Quote
Old 08/03/2013, 08:23 AM   #6
GWMPT
High-roller
 
Join Date: Nov 2012
Location: Portugal.
Posts: 1,051
Reputation: 286
Default Re: Gamemode SDK for C/C++ (GDK)

Quote:
Originally Posted by Rajat_Pawar View Post
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.
GWMPT is offline   Reply With Quote
Old 08/03/2013, 08:49 AM   #7
Hoda
Little Clucker
 
Join Date: Mar 2013
Posts: 24
Reputation: 4
Default Re: Gamemode SDK for C/C++ (GDK)

Quote:
Originally Posted by klklt0 View Post
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.
Hoda is offline   Reply With Quote
Old 08/03/2013, 08:59 AM   #8
GWMPT
High-roller
 
Join Date: Nov 2012
Location: Portugal.
Posts: 1,051
Reputation: 286
Default Re: Gamemode SDK for C/C++ (GDK)

Quote:
Originally Posted by Hoda View Post
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 View Post
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.
GWMPT is offline   Reply With Quote
Old 08/03/2013, 09:10 AM   #9
Hoda
Little Clucker
 
Join Date: Mar 2013
Posts: 24
Reputation: 4
Default 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.
Hoda is offline   Reply With Quote
Old 08/03/2013, 09:33 AM   #10
GWMPT
High-roller
 
Join Date: Nov 2012
Location: Portugal.
Posts: 1,051
Reputation: 286
Default Re: Gamemode SDK for C/C++ (GDK)

Quote:
Originally Posted by Hoda View Post
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?
GWMPT is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gamemode is unknown. When i connect theres no gamemode. Shannon_Brown Server Support 11 09/09/2012 08:49 AM
[GameMode] Brasil Drift Show [BDS] - Primeiro GameMode vitorzero3um PortuguÍs/Portuguese 3 29/02/2012 06:48 PM
[ENG] Ideas for new GameMode [NL] Ideeen voor nieuwe Gamemode Xtreme-Nicole Everything and Nothing 10 10/07/2011 11:20 AM
[ENG] Ideas for new GameMode [NL] Ideeen voor nieuwe GameMode Xtreme-Nicole Help Archive 2 09/07/2011 11:24 AM


All times are GMT. The time now is 02:55 PM.


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