Skip to content

Instantly share code, notes, and snippets.

View Hexlord's full-sized avatar

Alexander Knorre Hexlord

View GitHub Profile
#include "flecs.h"
#include "inttypes.h"
#include <cstdio>
#include <ctime>
auto nanos() {
timespec Time;
clock_gettime(CLOCK_MONOTONIC, &Time);
return Time.tv_sec * int64_t{1000000000} + (int64_t)Time.tv_nsec;
}
#include <flecs.h>
#include <stdio.h>
#include <stdlib.h>
#define MILLION (1000 * 1000)
#define ENTITY_COUNT (100)
#define SAMPLE_COUNT (1000)
struct Comp1 {
#include <ctime>
#include <cstdio>
#include "flecs.h"
#include "inttypes.h"
auto nanos() {
timespec Time;
clock_gettime(CLOCK_MONOTONIC, &Time);
return Time.tv_sec * int64_t{1000000000} + (int64_t)Time.tv_nsec;
}
struct FUpdateHierarchyStaticState{
static constexpr uint32 MaxSize = 100;
FUpdateHierarchyStaticState() {
Entities.Resize(MaxSize);
Views.Resize(MaxSize);
Positions.Resize(MaxSize);
Alignments.Resize(MaxSize, {0.5f, 0.0f});
Colors.Resize(MaxSize, {Color::ToFloatColor(0xbfbfbfff)});
Fonts.Resize(MaxSize, {EFont::Small});
#pragma once
#include "Allocator.inl"
namespace SE {
template<bool SingleFrame>
void *TDynamicAllocator<SingleFrame>::AlignPointer(void *Pointer, uint32 Extra, uint32 Alignment) {
byte *Address = (byte *)Pointer + Extra; // Space for header.
uintptr_t Aligned = Math::AlignUp((uintptr_t)Address, (uintptr_t)Alignment);
return (void *)Aligned;
#pragma once
#include "HashMapIterators.h"
namespace SE {
template<typename TKey, typename TValue, template<typename> typename THasherTemplate>
class THashMap {
private:
using FEntry = Impl::THashMapEntry<TKey, TValue>;
if constexpr (TermCount == 1) {
auto Builder = ECS.observer();
ConstructObserver<TArgs...>(Builder).event(Event);
if constexpr (FuncArgCount > 0) {
if constexpr (FuncArgCount == 1) {
// Callback only receives one parameter: entity / iter &
if constexpr (Meta::IsSame<Meta::TParameterPackFirstType<TFuncParams>, entity>) {
auto Trigger = Builder.iter([TermComponentIds, Callback = Meta::Forward<TFunc>(Func)](iter &Iter) {
Mutations.BeginIter(EIterationType::Observer, View(TermComponentIds));
for (auto Index : Iter) {
void TestPrefabPerformance(ecs &ECS) {
constexpr uint32 Count = 100000;
TStackArray<entity_view, Count> Entities;
struct CComp1 {
uint64 Field1;
uint64 Field2;
uint64 Field3;
uint64 Field4;
uint64 Field5;
char Field6;
@Hexlord
Hexlord / flecs.cpp
Created January 6, 2022 03:38
modules be like
Import<MCoreComponents>(ECS);
Import<MGameStateComponents>(ECS);
Import<MLifespanComponents>(ECS);
Import<MPlayerControllerComponents>(ECS);
Import<MTilesComponents>(ECS);
Import<MEditorTilesComponents>(ECS);
Import<MRenderTilesComponents>(ECS);
Import<MInputComponents>(ECS);
Import<MMouseControlsComponents>(ECS);
Import<MPhysicsComponents>(ECS);
@Hexlord
Hexlord / Core.cpp
Created December 6, 2021 03:08
Flecs wrappers (needs lots of testing)
#include "Core.h"
#include "CoreReflection.h"
#include "Engine/Engine.h"
#include "Engine/SDL/SDL.h"
namespace SE {
namespace Impl {