#1

I donwloaded gamemode from internet. and i want to edit it. It is small gamemode in BaySide and i found something strange(at least for me). Dialogs are defined like this
PHP код:
enum
{
    
DIALOG_OTHER,
    
DIALOG_LOGIN,
    
DIALOG_REGISTER,
    
DIALOG_REGISTER_POL,
    
DIALOG_REGISTER_GODINE,
    
DIALOG_REGISTER_POTVRDA,
    
DIALOG_POSTAVKE,
    
DIALOG_POSTAVKE_IME,
    
DIALOG_POSTAVKE_SLOZINKA,
    
DIALOG_POSTAVKE_RCON,
    
DIALOG_POSTAVKE_SKINM,
    
DIALOG_POSTAVKE_SKINZ,
    
DIALOG_POSTAVKE_POS,
    
DIALOG_POSTAVKE_PNOVAC,
    
DIALOG_POSTAVKE_PLEVEL,
    
DIALOG_POSTAVKE_DEBUG,
    
DIALOG_CREATE,
    
DIALOG_CREATE_RENT,
    
DIALOG_EDIT,
    
DIALOG_EDIT_RENTVOZILA,
    
DIALOG_RENT,
    
DIALOG_BANK_MAIN,
    
DIALOG_CREATE_BANK,
    
DIALOG_EDIT_BANK,
    
DIALOG_EDIT_ATM,
    
DIALOG_ATM
}; 
Is it going to effect speed and preformance?? Should i leave them like that or should i
PHP код:
#define DIALOG 
?? What do you think
Reply
#2

Its fine.

I even prefer using an enum for the dialogs but its your choice.
Reply
#3

Well i had to ask because it is first time for me seeing dialogs like this so i was confused
Reply
#4

When using enumerators, your compiled script will create constants (variables) which are automatically signed with an ID.
Defines however are only applied by the pre- compiler. Before pawncc actually compiles, te pre-compiler finds every macro and changes it with it's value.
Meaning that this:
PHP код:
#define MyNumber 10
#define Add 5
main()
{
    
printf("MyNumber is %d. Add %d and we get: %d"MyNumberAddMyNumber Add);
    return 
1;

Actually compiles like this:
PHP код:
main()
{
    
printf("MyNumber is %d. Add %d and we get: %d"10510+5);
    return 
1;

Now, if you'd use a script with enumerators:
PHP код:
#include <a_samp>
enum MyEnum
{
    
MyNumber,
    
Add
};
new var[
MyEnum];
main()
{
    var[
MyNumber] = 10;
    var[
Add] = 5;
    
    
printf("MyNumber is %d. Add %d and we get: %d", var[MyNumber], var[Add], var[MyNumber] + var[Add]);
    return 
1;

This script does exactly the same, except that the compiled script will look something like this:
PHP код:
new var01var02;
main()
{
    
var01 10;
    
var02 5;
    
printf("MyNumber is %d. Add %d and we get: %d"var01var02var01 var02);
    return 
1;

This means that memory is used (every variable uses atleast 4 cells of the memory).


p.s.
The compiled file of the define version was (with a_samp included); 218 bytes
The compiled file of the enumerator version was (also with a_samp included); 246 bytes
Imagine that with a huge gamemode. You'd safe quite some memory using defines.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)