Posts: 352
Threads: 37
Joined: Jun 2012
Quote:
Originally Posted by ******
“stop bad practices”
- Linear search.
- Rectangular zones with multiple IDs for the same zone, instead of polygons.
- IsPlayerConnected and IsValidVehicle instead of GetXPos return values.
- Multiple copies of the same string literals.
- No backwards-compatibility with the default compiler.
- No const data.
- No brackets on macro replacements.
- Memes in the release topic.
I’m wondering which bad practices you DID stop?
Also, I’m not quite sure how you managed to miss the good solutions that have existed for a decade already…
|
Quote:
Originally Posted by ******
Actually constructive critisism:
- Put the locations and names in separate arrays, that way you avoid the massive duplication of strings, and their index will match the zone ID. I know people seem to prefer enums over multiple arrays (I’ve repeatedly seen comments to the effect of “use enums not two arrays”) but there are actually advantages to using multiple arrays instead.
- Could be a good idea (since the IDs are now constants) to provide defines, then you can do things like:
if (GetPlayerZone(playerid) == ZONE_GROVE_STREET)
- Searching rectangles is, admittedly, vastly simpler than searching polygons, but this can be solved with stored zone IDs, so your array data looks like:
{ZONE_OCEAN_FLATS, -2994.489990, 277.411010, -0.000091, -2867.850097, 458.411010, 200.000000},
{ZONE_OCEAN_FLATS, -2994.489990, -222.589004, -0.000106, -2593.439941, 277.411010, 200.000000},
{ZONE_OCEAN_FLATS, -2994.489990, -430.276000, -0.000122, -2831.889892, -222.589004, 200.000000},
Then you return the stored ID, not the array index, and multiple zones end up the same. For boxy shapes like this this is probably the best method TBH, even better than polygons if you could support them.
- Much harder is getting rid of the linear search, but it can be done with careful arrangements of the data. Zones can be sorted in the x- and y- axes, making finding the zone given a co-ordinate almost O(1).
|
Thanks for the criticism and ideas. I've already taken care of the minor stuff, I'll release a new version in the near future, restructuring the data will take some time though. I'll also try to include sound IDs for the zone names, but the SFX files are a lot harder to parse than everything else I've parsed so far, so I might have to do that manually.
I've already addressed this in the Discord, but just in case I'll mention this here as well that I considered using polygons instead of rectangles for this (I should even have the required code in one of my older repos), but since some of the areas with same names have different Z-coordinates, it doesn't suit for this usecase since I'd like to keep the data the same as it was in the game files.