Raised This Month: $32 Target: $400
 8% 

Save Entity Index with BitSum


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
XSlayer
Member
Join Date: Dec 2021
Old 07-26-2022 , 18:33   Save Entity Index with BitSum
Reply With Quote #1

Hi i wanted to know, how can i save an index for a client, with bitsums

PHP Code:
new __int_Entity[33];

public 
CreateEntityClient )
{
      
__int_Entity[Client] = create_entity"env_sprite" );
}
public 
RemoveEntityClient )
{
     if(
is_valid_ent(__int_Entity[Client]))
     {
         
entity_set_int__int_Entity[Client], EV_INT_flagsentity_get_int__int_Entity[Client], EV_INT_flags ) | FL_KILLME );        
     }
     
__int_Entity[Client]  = 0;


Last edited by XSlayer; 07-26-2022 at 18:35.
XSlayer is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-26-2022 , 18:43   Re: Save Entity Index with BitSum
Reply With Quote #2

May be more work than it's worth, what are you trying to accomplish?
__________________
Bugsy is offline
XSlayer
Member
Join Date: Dec 2021
Old 07-26-2022 , 19:15   Re: Save Entity Index with BitSum
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
May be more work than it's worth, what are you trying to accomplish?
try to save all 33 cells and bytes, like

PHP Code:
new __int_Variable[33];

public 
TestClient )
{
       if(!
__int_Variable[Client])) // if is false
       
{
              
__int_Variable[Client] = 1;
       } 
       else 
// if is true
       
{
             
__int_Variable[Client] = 0;
       }

to

PHP Code:

#define SetPlayerBit(%1,%2)      (%1 |= (1<<(%2&31)))
#define ClearPlayerBit(%1,%2)    (%1 &= ~(1 <<(%2&31)))
#define CheckPlayerBit(%1,%2)    (%1 & (1<<(%2&31)))

new __int_Variable;

public 
TestClient )
{
       if(!
CheckPlayerBit__int_VariableClient )) 
       {
             
SetPlayerBit(__int_VariableClient);
       } 
       else 
       {
             
ClearPlayerBit(__int_VariableClient);
       }

but in this case for saving and index

Last edited by XSlayer; 07-26-2022 at 19:18.
XSlayer is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-26-2022 , 19:28   Re: Save Entity Index with BitSum
Reply With Quote #4

Take a look at the Manipulating bits outside of the bit-range of a memory cell section here https://forums.alliedmods.net/showthread.php?t=139916

I assume you are looking to store index's larger than 1 to 32, so you need to use an array which will give you increments of 32 for each cell used.
__________________
Bugsy is offline
XSlayer
Member
Join Date: Dec 2021
Old 07-26-2022 , 19:32   Re: Save Entity Index with BitSum
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
Take a look at the Manipulating bits outside of the bit-range of a memory cell section here https://forums.alliedmods.net/showthread.php?t=139916

I assume you are looking to store index's larger than 1 to 32, so you need to use an array which will give you increments of 32 for each cell used.
yes I read it, but I don't fully understand that part, I understand about setting the bits to players, but not what continues, that's why the post
XSlayer is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-26-2022 , 19:52   Re: Save Entity Index with BitSum
Reply With Quote #6

Ok, I'll try to give you a quick visual

Lets use a 3-cell array

Cell 1 - 4 bytes/32 bits - 32 bits total
A single cell is perfect for player booleans since player ID's range from 1 to 32.
[ 0000 0000 ][ 0000 0000 ][ 0000 0000 ][ 0000 0000 ]

Cell 2 - 4 bytes/32 bits - 64 bits total
[ 0000 0000 ][ 0000 0000 ][ 0000 0000 ][ 0000 0000 ]

Cell 3 - 4 bytes/32 bits - 96 bits total
[ 0000 0000 ][ 0000 0000 ][ 0000 0000 ][ 0000 0000 ]

When you want to set bits beyond 32, you need to use an array, cell 2 holds bits 33 to 64, cell 3 holds 65-96, etc. Those macros do the work for you to set the appropriate bit.
__________________

Last edited by Bugsy; 07-26-2022 at 19:53.
Bugsy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-27-2022 , 02:07   Re: Save Entity Index with BitSum
Reply With Quote #7

Please don't do this in practice. There is absolutely no reason for it.
__________________
HamletEagle is offline
XSlayer
Member
Join Date: Dec 2021
Old 07-27-2022 , 02:11   Re: Save Entity Index with BitSum
Reply With Quote #8

Quote:
Originally Posted by HamletEagle View Post
Please don't do this in practice. There is absolutely no reason for it.
and because??...

Last edited by XSlayer; 07-27-2022 at 02:12.
XSlayer is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-27-2022 , 07:59   Re: Save Entity Index with BitSum
Reply With Quote #9

This is why I asked for your use-case. It's not beneficial to use bit-wise operators/logic if you need to jump through hoops to accomplish it. There is likely a much simpler and economical way to do what are attempting
__________________
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-28-2022 , 00:42   Re: Save Entity Index with BitSum
Reply With Quote #10

Quote:
Originally Posted by XSlayer View Post
and because??...
You're using a modern computer for an ancient game engine, there won't be any issues with performance by using arrays.

Also, I have no idea what you're actually requesting. What does it even mean to "save an index"? Didn't you literally just write the code you needed in post #3? I think you'd need to provide context for what you are ACTUALLY trying to do so we can give you the best advice.
__________________
fysiks 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 04:01.


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