Skip to content

CS:GO weapons update #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Dec 10, 2016
Merged

CS:GO weapons update #169

merged 18 commits into from
Dec 10, 2016

Conversation

satoon101
Copy link
Member

  • Adds item_definition_index attribute for Weapon instances for CS:GO
  • Adds item_definition_index values for weapons in csgo weapon data
  • Fixes maxammo on CS:GO which no longer uses ConVars
  • Adds weapons to csgo weapon data that use the item_definition_index to set along with the parent classname
  • Overrides created for Entity.create and Entity.find for csgo
  • Adds Weapon.get_weapon_name to return the full name. Uses the item_definition_index for CS:GO. For other games/engines, just returns the classname

…lassnames.

Added item_definition_index to all weapons in csgo weapon data to help differentiate between weapons.

Changed maxammo for all non-grenade weapons in csgo weapon data to hard code the value instead of using the ConVars.  The ConVars seem to no longer work, as changing their values does not affect the reserver ammo for the weapons.
Added the ini ConfigObj to the weapon_manager instance.
Added Weapon.get_weapon_name to the base Weapon class and CS:GO specific.
Added CEconEntity data for CS:GO.
Fixed issue with weapon_knifegg.
Implemented changes to Entity.find and Entity.create for csgo engine.
…eapons should never be given to players that have not earned/purchased them as any server doing so could be banned.
@satoon101
Copy link
Member Author

Currently, this uses get_weapon_name. I'm thinking we should change it to a getter property weapon_name, but I'm open to other suggestions for the name.

@Ayuto
Copy link
Member

Ayuto commented Dec 5, 2016

Yes, weapon_name would be great. I haven't tested the changes yet, but I'm afraid that find is now extremely slow, because it's utilizing EntityIter. This isn't really an issue of your implementation, but rather an issue with __getattr__ (and __setattr__) and maybe EntityIter. However, maybe we should use BaseEntity.get_network_property_* instead of accessing item_definition_index to speed things up.

@satoon101
Copy link
Member Author

Good point! I tested a couple different solutions, and the most recent commit (586738c) was by far the fastest.

@satoon101
Copy link
Member Author

Let me know when you have had a chance to test everything, and if it's all good, we can merge this.

@Ayuto
Copy link
Member

Ayuto commented Dec 6, 2016

Thanks for the update! Have you tried BaseEntityGenerator? It should be even faster than BaseEntityIter and it also provides the classname filter.

@Ayuto
Copy link
Member

Ayuto commented Dec 6, 2016

I just noticed that it doesn't provide the classname filter. However, this should be a lot faster:

for edict in EntityGenerator(<classname>, True):
    entity = edict.server_unknown.base_entity
    break

@satoon101
Copy link
Member Author

I tried using EntityGenerator as in your snippet, but time.time() was acting really funky and I couldn't get proper speed testing results. I did find that the newest update (75c5c2d), which utilizes your earlier suggestion of BaseEntityGenerator, does significantly improve performance. I just added the classname filter directly to the loops in Entity.find.

@Ayuto
Copy link
Member

Ayuto commented Dec 7, 2016

I usually use the timeit module to measure performance. This little snippet shows that EntityGenerator is faster than BaseEntityGenerator:

import timeit

ITERATIONS = 10000

print(timeit.Timer(
"""
for entity in BaseEntityGenerator():
    if entity.classname != 'INVALID':
        continue
    if not entity.is_networked():
        continue
        
    break
""",
"""
from filters.entities import BaseEntityGenerator
""").timeit(ITERATIONS))

print(timeit.Timer(
"""
for edict in EntityGenerator('INVALID', True):
    entity = edict.server_unknown.base_entity
    break
""",
"""
from filters.entities import EntityGenerator
""").timeit(ITERATIONS))

Result:

4.368229347527859
0.1648294557697536

I used the classname INVALID to test the worst case (iterating over all entities, because no classname matches).

@Ayuto
Copy link
Member

Ayuto commented Dec 7, 2016

Just added classname filter options to BaseEntityGenerator to speed things up:

import timeit

ITERATIONS = 10000

print(timeit.Timer(
"""
for entity in BaseEntityGenerator():
    if entity.classname != 'INVALID':
        continue
        
    break
""",
"""
from filters.entities import BaseEntityGenerator
""").timeit(ITERATIONS))

print(timeit.Timer(
"""
for entity in BaseEntityGenerator('INVALID', True):
    break
""",
"""
from filters.entities import BaseEntityGenerator
""").timeit(ITERATIONS))

Result:

3.3641884975067313
0.13046310604846667

Now, there is probably no big difference between EntityGenerator and BaseEntityGenerator.

@satoon101
Copy link
Member Author

My tests show that BaseEntityGenerator is slightly faster than EntityGenerator. We don't really need to worry about invalid classnames in our instance, because unless we accidentally add invalid classnames to our weapon data, they will always skip both the if and elif clauses.

@Ayuto Ayuto merged commit 4e22e36 into master Dec 10, 2016
@Ayuto Ayuto deleted the csgo_weapons branch December 10, 2016 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants