Skip to content

Instantly share code, notes, and snippets.

@asherkin
Created September 16, 2018 11:39
Show Gist options
  • Save asherkin/536ed5465a45c9bc5a94f587dcf5f92b to your computer and use it in GitHub Desktop.
Save asherkin/536ed5465a45c9bc5a94f587dcf5f92b to your computer and use it in GitHub Desktop.
#include <sourcemod>
#pragma semicolon 1
#pragma newdecls required
public Plugin myinfo = {
name = "",
author = "",
description = "",
version = "0.0.0",
url = ""
};
// SourcePawn plugin defines, these are <<1 more than the native engine flags.
#define PARTITION_SOLID_EDICTS (1 << 1) // every edict_t that isn't SOLID_TRIGGER or SOLID_NOT (and static props)
#define PARTITION_TRIGGER_EDICTS (1 << 2) // every edict_t that IS SOLID_TRIGGER
#define PARTITION_NON_STATIC_EDICTS (1 << 5) // everything in solid & trigger except the static props, includes SOLID_NOTs
#define PARTITION_STATIC_PROPS (1 << 7)
// Engine flags, not defined in SourcePawn, here for example
#define PARTITION_ENGINE_SOLID_EDICTS (1 << 0)
#define PARTITION_ENGINE_TRIGGER_EDICTS (1 << 1)
#define PARTITION_ENGINE_NON_STATIC_EDICTS (1 << 4)
#define PARTITION_ENGINE_STATIC_PROPS (1 << 6)
// This would live on the native side.
int TranslatePartitionFlags(int input)
{
if (input == 0) {
return PARTITION_ENGINE_SOLID_EDICTS;
} else if (input == 1) {
return PARTITION_ENGINE_SOLID_EDICTS | PARTITION_ENGINE_TRIGGER_EDICTS;
} else {
return input >> 1;
}
}
// For debugging.
void PrintNativePartitionFlags(int flags)
{
flags = TranslatePartitionFlags(flags);
char buffer[1024];
for (int i = 0; i < 32; ++i) {
if ((flags & (1 << i)) == 0) {
continue;
}
if (buffer[0]) {
StrCat(buffer, sizeof(buffer), " | ");
}
switch (i) {
case 0:
StrCat(buffer, sizeof(buffer), "PARTITION_ENGINE_SOLID_EDICTS");
case 1:
StrCat(buffer, sizeof(buffer), "PARTITION_ENGINE_TRIGGER_EDICTS");
case 4:
StrCat(buffer, sizeof(buffer), "PARTITION_ENGINE_NON_STATIC_EDICTS");
case 6:
StrCat(buffer, sizeof(buffer), "PARTITION_ENGINE_STATIC_PROPS");
default:
Format(buffer, sizeof(buffer), "%sUNKNOWN_FLAG_%d", buffer, i);
}
}
PrintToServer("%s", buffer);
}
public void OnPluginStart()
{
PrintNativePartitionFlags(false); // PARTITION_ENGINE_SOLID_EDICTS
PrintNativePartitionFlags(true); // PARTITION_ENGINE_SOLID_EDICTS | PARTITION_ENGINE_TRIGGER_EDICTS
PrintNativePartitionFlags(PARTITION_SOLID_EDICTS); // PARTITION_ENGINE_SOLID_EDICTS
PrintNativePartitionFlags(PARTITION_TRIGGER_EDICTS); // PARTITION_ENGINE_TRIGGER_EDICTS
PrintNativePartitionFlags(PARTITION_NON_STATIC_EDICTS); // PARTITION_ENGINE_NON_STATIC_EDICTS
PrintNativePartitionFlags(PARTITION_STATIC_PROPS); // PARTITION_ENGINE_STATIC_PROPS
PrintNativePartitionFlags(PARTITION_SOLID_EDICTS | PARTITION_TRIGGER_EDICTS); // PARTITION_ENGINE_SOLID_EDICTS | PARTITION_ENGINE_TRIGGER_EDICTS
PrintNativePartitionFlags(PARTITION_NON_STATIC_EDICTS | PARTITION_STATIC_PROPS); // PARTITION_ENGINE_NON_STATIC_EDICTS | PARTITION_ENGINE_STATIC_PROPS
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment