Raised This Month: $209 Target: $400
 52% 

Need a good array for this...


Post New Thread Reply   
 
Thread Tools Display Modes
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 12-21-2015 , 12:39   Re: Need a good array for this...
Reply With Quote #11

Quote:
Originally Posted by bally View Post
So basically, what you're saying is, there's no need to store the values on a dynamic array, I can just access the keyvalues because they are already cached?
Well the kv tree is in memory, but that doesn't mean that lookup is particularly fast or equal compared to other storage techniques.
You still haven't said what you want to do, so everything from building a menu handle and caching that, using an adt-array, or using a tree might be better or not worth the effort.
I don't want this thread to be another example for "parse through huge kv-structures in game".
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
bally
Senior Member
Join Date: Aug 2015
Old 12-21-2015 , 13:18   Re: Need a good array for this...
Reply With Quote #12

Quote:
Originally Posted by Dr. Greg House View Post
Well the kv tree is in memory, but that doesn't mean that lookup is particularly fast or equal compared to other storage techniques.
You still haven't said what you want to do, so everything from building a menu handle and caching that, using an adt-array, or using a tree might be better or not worth the effort.
I don't want this thread to be another example for "parse through huge kv-structures in game".
Let me be more specific:

PHP Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR ""
#define PLUGIN_VERSION "0.00"

#define Kv_Location "configs/loc/location.cfg"

#include <sourcemod>
#include <sdktools>
#include <cstrike> 


bool clwhitelisted[MAXPLAYERS 1];
KeyValues kv;

Handle g_adtArray;

public 
Plugin myinfo 
{
    
name ""
    
author PLUGIN_AUTHOR
    
description ""
    
version PLUGIN_VERSION
    
url ""
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_tpmenu"buildUI"builds UI");
    
CreateTimer(2.0loopremove_TIMER_REPEAT);
    
g_adtArray CreateArray(32);
}



public 
void OnMapStart()
{
    
CacheVl();
}

public 
bool CacheVl()
{
    
kv = new KeyValues("locations");

    
char buffer[256];
    
char dirLoc[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMdirLocsizeof(dirLoc), Kv_Location);
    
    
    
FileToKeyValues(kvdirLoc);
    if (!
KvGotoFirstSubKey(kv))
    {
        
CloseHandle(kv);
        return 
false;
        
// cfg is broken...
    
}
    
    do {
        
        
KvGetSectionName(kvbuffersizeof(buffer));
        
PushArrayString(g_adtArraybuffer); 
        
// get section name, store into a dynamic array
        
    
} while (KvGotoNextKey(kv));
    
    return 
true;
}

public 
int handlerUI(Menu menuMenuAction actionint parameterCLint parameterARGS)
{
    
/* If an option was selected, tell the client about the item. */
    
    
if (action == MenuAction_Select)
    {
        
char selectedName[32];
        
menu.GetItem(parameterARGSselectedNamesizeof(selectedName)); 
        
retrieveCachedData(parameterCLselectedName);
            
            
/* Know which section we talkin' bout = selectedName = Section*/
            /* Compare data with the keyValues */
            /* Retrieve Info */
            /* Teleport */
            
    
}
    
/* If the menu was cancelled, print a message to the server about it. */
    
else if (action == MenuAction_Cancel)
    {
        
PrintToServer("Client %d's menu was cancelled.  Reason: %d"parameterCLparameterARGS);
    }
    
/* If the menu has ended, destroy it */
    
else if (action == MenuAction_End)
    {
        
delete menu;
    }
}


public 
Action buildUI(int clint args)
{
    
char buffer[32];
    
Menu menu = new Menu(handlerUI);
    
menu.SetTitle("Teleport to:");
    
    for (
int i 0GetArraySize(g_adtArray); i++)
    {
        
GetArrayString(g_adtArrayibuffersizeof(buffer));
        
menu.AddItem(buffer"location");
    }
    
menu.ExitButton true;
    
menu.Display(clMENU_TIME_FOREVER);
    
    return 
Plugin_Handled;
}

public 
bool retrieveCachedData(int clchar[] section)
{
    
float temploc[3];
    
bool whitelist;
    if (!
kv.JumpToKey(section))
    {
        return 
false;
        
// no setted section ??? 
    
}
    
    
int clteam GetClientTeam(cl);
    
    switch (
clteam)
    {
        case 
CS_TEAM_CT:
        {
            
kv.GetFloat("ctlocx"temploc[0]);
            
kv.GetFloat("ctlocy"temploc[1]);
            
kv.GetFloat("ctlocz"temploc[2]);
        }
        case 
CS_TEAM_T:
        {
            
kv.GetFloat("tlocx"temploc[0]);
            
kv.GetFloat("tlocy"temploc[1]);
            
kv.GetFloat("tlocz"temploc[2]);
        }
    }
    
//whitelist = kv.GetNum("tlocy", temploc[1]);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
    
teleportcl(cltemploc);
    
delete kv;
    return 
true;
}

public 
teleportcl(int clfloat pos[3])
{
    
TeleportEntity(clposNULL_VECTORNULL_VECTOR);
}

public 
Action loopremove(Handle timer)
{
    
int ent;
    
    if (
GameRules_GetProp("m_bWarmupPeriod") == 0// it's not warm up
    
{
        for (
int i 1MaxClientsi++)
        {
            if (
IsClientInGame(i) && IsPlayerAlive(i))
            {
                for (
int wepwep 4wep++)
                {
                    if ((
ent GetPlayerWeaponSlot(iwep)) != -1)
                    {
                        
SetEntProp(entProp_Send"m_iPrimaryReserveAmmoCount"0);
                        
SetEntProp(entProp_Send"m_iClip1"0);
                    }
                }
                
            }
        }
    }

My KeyValue:
PHP Code:
"Locations"
{
    
"Arena"
      
{
               
"ammo"         "1"
               "ctlocx"     "535"
            "ctlocy"     "5290"
            "ctlocz"     "1924"
            "tlocx"     "4467"
            "tlocy"     "45361"
            "tlocz"     "375"
        
}
    
"TradeRooms"
      
{
               
"ammo"         "0"
               "ctlocx"     "535"
            "ctlocy"     "5290"
            "ctlocz"     "1924"
            "tlocx"     "4467"
            "tlocy"     "45361"
            "tlocz"     "375"
        
}
    
"Surf"
      
{
               
"ammo"         "0"
               "ctlocx"     "535"
            "ctlocy"     "5290"
            "ctlocz"     "1924"
            "tlocx"     "4467"
            "tlocy"     "45361"
            "tlocz"     "375"
        
}
    
"Bhop"
      
{
               
"ammo"         "0"
               "ctlocx"     "535"
            "ctlocy"     "5290"
            "ctlocz"     "1924"
            "tlocx"     "4467"
            "tlocy"     "45361"
            "tlocz"     "375"
        
}

This is my code & KeyValue, I want to access these values in such way that I won't stress my server, what would be the better way, keeping my KeyValue Handle open and search sections for a value each time a user inputs data, or cache all the data in an adt_array or an adt_trie?
__________________
Perhaps my lack of faith was my undoing,

Last edited by bally; 12-21-2015 at 14:07.
bally is offline
bally
Senior Member
Join Date: Aug 2015
Old 12-22-2015 , 14:19   Re: Need a good array for this...
Reply With Quote #13

hello?
__________________
Perhaps my lack of faith was my undoing,

Last edited by bally; 12-22-2015 at 14:20.
bally is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 12-22-2015 , 14:25   Re: Need a good array for this...
Reply With Quote #14

Bumping is not allowed, as the rules do suggest,
you may put a mods temper to the test.
But let me put the rules astray,
in your example, a cached menu just may,
solve what makes you all so stressed,
if to the consistency of the menus you can attest.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
bally
Senior Member
Join Date: Aug 2015
Old 12-22-2015 , 15:07   Re: Need a good array for this...
Reply With Quote #15

Quote:
Originally Posted by Dr. Greg House View Post
Bumping is not allowed, as the rules do suggest,
you may put a mods temper to the test.
But let me put the rules astray,
in your example, a cached menu just may,
solve what makes you all so stressed,
if to the consistency of the menus you can attest.
o.o, was that supposed to be a poem? xD
I'm sorry for bumping

Edit: I'm not very good with poems... could you please clarify?
__________________
Perhaps my lack of faith was my undoing,

Last edited by bally; 12-22-2015 at 15:16.
bally is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 12-22-2015 , 15:41   Re: Need a good array for this...
Reply With Quote #16

Don't worry about optimization unless is something more processing or io intese like writting to a databse. Finish the plugin first and see if it needs any optimization. If that is the case you can use a multidimensional array without leaving pawn, with static size as a gobal variable if the size is not a problem or an adt array if you need variable size. Take a look at this

Edit: Multidimensional Arrays in pawn:

new Float:g_flPositions[MAXPLAYERS+1][3];

for (new i=0; i<sizeof(g_flPositions); i++) {
g_flPositions[i][0] = -1.0;
g_flPositions[i][1] = -1.0;
g_flPositions[i][2] = -1.0;
}

Last edited by fakuivan; 12-22-2015 at 15:49.
fakuivan is offline
bally
Senior Member
Join Date: Aug 2015
Old 12-22-2015 , 16:11   Re: Need a good array for this...
Reply With Quote #17

Quote:
Originally Posted by fakuivan View Post
Don't worry about optimization unless is something more processing or io intese like writting to a databse. Finish the plugin first and see if it needs any optimization. If that is the case you can use a multidimensional array without leaving pawn, with static size as a gobal variable if the size is not a problem or an adt array if you need variable size. Take a look at this

Edit: Multidimensional Arrays in pawn:

new Float:g_flPositions[MAXPLAYERS+1][3];

for (new i=0; i<sizeof(g_flPositions); i++) {
g_flPositions[i][0] = -1.0;
g_flPositions[i][1] = -1.0;
g_flPositions[i][2] = -1.0;
}
I know how to work with multidimensional arrays in pawn, but thanks . My question is: DO I really need an array or I can use KeyValues? Like I'm doing in that code...
__________________
Perhaps my lack of faith was my undoing,

Last edited by bally; 12-22-2015 at 16:11.
bally is offline
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

Forum Jump


All times are GMT -4. The time now is 00:19.


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode