Skip to content

Add template availablility for untyped component constants and bits#1558

Merged
SanderMertens merged 16 commits intoSanderMertens:masterfrom
Reddy-dev:patch-3
Feb 11, 2025
Merged

Add template availablility for untyped component constants and bits#1558
SanderMertens merged 16 commits intoSanderMertens:masterfrom
Reddy-dev:patch-3

Conversation

@Reddy-dev
Copy link
Copy Markdown
Contributor

No description provided.

@Reddy-dev
Copy link
Copy Markdown
Contributor Author

Will add tests

@Reddy-dev
Copy link
Copy Markdown
Contributor Author

Reddy-dev commented Feb 9, 2025

Note: needed it for this usecase

ScriptEnumComponent = World.component(StringCast<char>(*ScriptEnum->GetName()).Get());
			solid_check(ScriptEnumComponent.is_valid());
			ScriptEnumComponent.set_symbol(StringCast<char>(*ScriptEnum->GetName()).Get());
			ScriptEnumComponent.set<flecs::Component>(
				{ .size = sizeof(uint8), .alignment = alignof(uint8) });
			ScriptEnumComponent.set<flecs::Enum>(flecs::Enum{
				.underlying_type = flecs::U8 });

			const int32 EnumCount = ScriptEnum->NumEnums();
			
			for (int32 EnumIndex = 0; EnumIndex < EnumCount; ++EnumIndex)
			{
				const FString EnumName = ScriptEnum->GetNameStringByIndex(EnumIndex);
				const int32 EnumValue = ScriptEnum->GetValueByIndex(EnumIndex);
				
				ScriptEnumComponent.constant<uint8>(StringCast<char>(*EnumName).Get(), EnumValue, flecs::U8);
			}

@Reddy-dev
Copy link
Copy Markdown
Contributor Author

This also retains backwards compatability

@Reddy-dev
Copy link
Copy Markdown
Contributor Author

As I needed to be able to make Runtime Enum types with a certain integer underlying type

const char *name,
int32_t value)
T value,
flecs::entity_t TId = flecs::I32)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you passing in this parameter vs. using flecs::_::type<T>::id(world)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oop didnt think of that, can change that now

@SanderMertens
Copy link
Copy Markdown
Owner

Looks good overall! Just one small comment about the type id parameter.

@Reddy-dev
Copy link
Copy Markdown
Contributor Author

Should be fixed now

@SanderMertens
Copy link
Copy Markdown
Owner

LGTM!

@SanderMertens SanderMertens merged commit 8e15d0e into SanderMertens:master Feb 11, 2025
70 checks passed
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