Skip to content

Instantly share code, notes, and snippets.

@kevinmoran
Created January 21, 2021 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinmoran/8a831dfbb21106a922ce38f0c169124a to your computer and use it in GitHub Desktop.
Save kevinmoran/8a831dfbb21106a922ce38f0c169124a to your computer and use it in GitHub Desktop.
Stretchy bitflags - Nifty code snippet from Ryan Fleury shared on Handmade Network discord
enum EntityProperty
{
EntityProperty_IsActive,
EntityProperty_RenderModel,
EntityProperty_Hostile,
EntityProperty_OnFire,
EntityProperty_SomethingElse,
EntityProperty_Count
};
// In Entity:
u64 properties[(EntityProperty_Count+63)/64];
b32 EntityHasProperty(Entity *entity, EntityProperty property)
{
return !!(entity->properties[property/64] & (1ull << (property%64)));
}
void SetEntityProperty(Entity *entity, EntityProperty property)
{
entity->properties[property/64] |= (1ull << (property%64));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment