Created
January 21, 2021 23:11
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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