[Include] od_batch_operation.inc
#1

PHP код:
#if defined _INC_od_batch_operation
    #endinput
#endif
#define _INC_od_batch_operation
#include <indirection\indirection>
#if !defined FIX_const
    
native CST_SetSVarInt(const varname[], int_value) = SetSVarInt;
    
native CST_GetSVarType(const varname[]) = GetSVarType;
    
native CST_DeleteSVar(const varname[]) = DeleteSVar;
    
native CST_SetPVarInt(playerid, const varname[], int_value) = SetPVarInt;
    
native CST_GetPVarType(playerid, const varname[]) = GetPVarType;
    
native CST_DeletePVar(playerid, const varname[]) = DeletePVar;
    
native CST_SetTimerEx(const funcname[], intervalrepeating, const format[], {Float,_}:...) = SetTimerEx;
#else
    #if !FIX_const
        
native CST_SetSVarInt(const varname[], int_value) = SetSVarInt;
        
native CST_GetSVarType(const varname[]) = GetSVarType;
        
native CST_DeleteSVar(const varname[]) = DeleteSVar;
        
native CST_SetPVarInt(playerid, const varname[], int_value) = SetPVarInt;
        
native CST_GetPVarType(playerid, const varname[]) = GetPVarType;
        
native CST_DeletePVar(playerid, const varname[]) = DeletePVar;
        
native CST_SetTimerEx(const funcname[], intervalrepeating, const format[], {Float,_}:...) = SetTimerEx;
    
#endif
#endif
forward Batch_SVar(Func:func<>, const name[]);
public 
Batch_SVar(Func:func<>, const name[]) {
    
CST_DeleteSVar(name);
    @.
func();
    
Indirect_Release(func);
}
forward Batch_PVar(playeridFunc:func<i>, const name[]);
public 
Batch_PVar(playeridFunc:func<i>, const name[]) {
    
CST_DeletePVar(playeridname);
    @.
func(playerid);
    
Indirect_Release(func);
}
stock BATCH({F@_@, F@_@i}:func F@_@:0playerid INVALID_PLAYER_ID, const name[]) {
    if (
func == F@_@:0) {
        
func F@_@:GetPublicAddressFromName(name);
    }
    if (
playerid == INVALID_PLAYER_ID) {
        if (
CST_GetSVarType(name) == SERVER_VARTYPE_NONE) {
            
Indirect_Claim(func);
            
CST_SetSVarInt(nameCST_SetTimerEx("Batch_SVar"00"is"_:funcname));
        }
    } else if (
IsPlayerConnected(playerid)) {
        if (
CST_GetPVarType(playeridname) == SERVER_VARTYPE_NONE) {
            
Indirect_Claim(func);
            
CST_SetPVarInt(playeridnameCST_SetTimerEx("Batch_PVar"00"iis"playerid_:funcname));
        }
    }
}
#define BATCH(&%1) (_:BATCH_2:BATCH(addressof(%1<>),.name=#%1))
#define BATCH_2:BATCH(addressof(%1,%2<>)%3)) BATCH(addressof(%1<i>),%2,#%1)) 
It can make a function called many times called only once.

example:

PHP код:
UpdateHUD(playerid)
{
    
// Update HUD
}
new 
PLAYER_MONEY[MAX_PLAYERS];
new 
PLAYER_CLAN[MAX_PLAYERS][20];
new 
PLAYER_LEVEL[MAX_PLAYERS];
AddToMoneyStat(playeridamount) {
    
PLAYER_MONEY[playerid] += amount;
    
BATCH(&UpdateHUDplayerid);
}
SetClanStat(playerid, const clan[]) {
    
format(PLAYER_CLAN[playerid], 20"%s"clan);
    
BATCH(&UpdateHUDplayerid);
}
SetLevelStat(playeridlevel) {
    
PLAYER_LEVEL[playerid] = level;
    
BATCH(&UpdateHUDplayerid);
}
public 
OnPlayerConnect(playerid) {
    
AddToMoneyStat(playerid500);
    
SetClanStat(playerid"LVPD");
    
SetLevelStat(playerid0);

The UpdateHUD will called only once to save time instead of a lot of times without need.

It can be made in many ways. Global or per-player:

PHP код:
BATCH(&Func);
BATCH(&Funcplayerid);
BATCH(.name "Func");
BATCH(using inline Func);
BATCH(using public Funcplayerid); 
Reply
#2

Awesome, I will try it later.
Reply
#3

Looks nice, i will test this.
Reply
#4

so is this really good for reducing resources used?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)