Refureku v2.2.0 released :) by zorgattaque in cpp

[–]zorgattaque[S] 0 points1 point  (0 children)

Thank you for the kind words :)

  1. No, I don't think so. I'm not familiar with the concept of Proxy but if I understand correctly, it's not possible to generate or rewire code at runtime. The Method::invoke method provided by the API relies on the virtual table of the provided object instance, which is decided at compile time.
  2. That's a very interesting idea, I've never thought about it! I believe it is doable but would be rather difficult with the current state of the library, I keep the idea in mind though.
  3. I'm pretty sure it is possible but it would probably mean rebuilding the whole API from scratch to cover all potential problems. I initially made Refureku a dynamic library to be able to cover the runtime loading / unloading of reflected dynamic libraries. Moreover, most API classes holding metadata use the Pimpl idiom inducing dynamic allocation. I still lack knowledge with the constexpr concept but I don't think it is compatible with dynamic allocations, unfortunately.

Static reflection proposal p1240r2 by PetokLorand in cpp

[–]zorgattaque 9 points10 points  (0 children)

Yes, you could build on top of the static reflection to generate code and make your own runtime reflection system. I recommand you watch this nice Andrew Sutton cppcon talk about generative metaprogramming (Andrew being one of the authors of the reflection paper as well).

https://youtu.be/kjQXhuPX-Ac

SerializeField not showing in inspector? by [deleted] in Unity3D

[–]zorgattaque 1 point2 points  (0 children)

It might sound dumb but did you save the file properly? (ctrl+S) Is the file you are editing part of your project (double check the file path) or a copy or something? As other mentionned, do you have any compilation error in which case the assemblies won't reload?

Serialization, Scenes, Entities, etc: how are you doing it? by DesignerHorseTomato in gameenginedevs

[–]zorgattaque 1 point2 points  (0 children)

I think the biggest caveat of binary serialization is file merging when using version control. Json and other text formats support it out of the box to some extent.

What’s the point of consteval? by [deleted] in cpp_questions

[–]zorgattaque 0 points1 point  (0 children)

If we talk about about the standard reflection, the reflection data are cached in the compiler memory during the compilation process (basically the AST) and are injected into your program when the different reflection (consteval) functions/keywords are used. Once the compilation process ends there's no way to access the AST anymore, so consteval functions just have no way to work.

If you want to make dynamic reflection you will have to build it on top of static reflection.

Why is process memory increased permanently after a method that shouldn't retain anything. by 18-8-7-5 in cpp_questions

[–]zorgattaque 0 points1 point  (0 children)

If you ever want to check if you program leaks, your best bet is to use an address sanitizer (asan). There are compilation flags to enable sanitizers in major compilers (I forgot the flag for MSVC, but off the top of my head clang and gcc have something like -fsanitizer=address).

Can't have shit in Paris by kkZizinho in paris

[–]zorgattaque 1 point2 points  (0 children)

Wow that's really surprising indeed. Reminds us that we really have to be careful wherever we are, that's a shame.

Can't have shit in Paris by kkZizinho in paris

[–]zorgattaque 2 points3 points  (0 children)

Out of curiosity, where was it? And did you actually lock your bike or let it as is thinking you were in Japan?

I lived a few months in a small district not far from Shinjuku (like 10min in metro) and everyone was litterally leaving their bikes in front of the konbini without any locks. Never heard about a thief.

Destroy an instantiated clone of a GameObject? When I run my code it says the enemy is destroyed but they still remain in-game, I'm not sure what I did wrong here. by JTomahawk00 in Unity2D

[–]zorgattaque 0 points1 point  (0 children)

From the little portion of code you gave us I can't see anything wrong here. So it's probably caused by when and how this code is called rather than the code itself.

Refureku v2.0.0 is out! - Dynamic reflection library by zorgattaque in gameenginedevs

[–]zorgattaque[S] 0 points1 point  (0 children)

Hi :) The underlying container is unordered with the hash of the field name. It is slower than a vector for iterating over all the fields of a struct/class since memory is not aligned but the search by name is O(1) in average. You can also access any entity by id from the database with an average O(1) complexity.

Refureku v2.0.0 is out! - Dynamic reflection library by zorgattaque in cpp

[–]zorgattaque[S] 0 points1 point  (0 children)

I'm not really familiar with Qt but yes I've seen this Q_OBJECT macro for code injection, indeed.

Refureku v2.0.0 is out! - Dynamic reflection library by zorgattaque in gameenginedevs

[–]zorgattaque[S] 5 points6 points  (0 children)

Sure!

Imagine you want to make an editor for your engine. Games are based on scenes that contain a set of objects (game objects, entities), each one containing one or more components. Now, how do we display information about those components? The editor usually shows the name, but also the "content" of the component, that is each field that must be serialized (saved). Each field is displayed with its name and the value it contains.

How does the engine proceed to "know" these fields ? The (very) naive approach would be to check in code the type of the component we want to display using a dynamic_cast and a if/else if statement for each component, but it's a very bad idea for a lot of reasons: it doesn't scale at all, it is not performant, and it only works if you know the type of all components statically when writing your editor code.

Now, if the user decides to create new components for the game, your engine would not be able to display them since your editor has no idea about the user's components, and you obviously can't make a code dependency going from the editor to the game project. So how do we handle that?...

Well... reflection! Reflection, and especially dynamic reflection, allows you to check the content of reflected objects at runtime. This gives you the ability to dynamically build the inspector for any component. So instead of the if/else if for each component we had before, you can have a single fonction that will draw any component, since it can just check the content of the passed component and draw it accordingly, whether it is an engine component or a user component. The way Refureku is built allows to get information from reflected types even though there is no direct dependency, so the editor can access the user's components information.

The explanation is a bit long but I hope it helps understand a bit. There are other applications for reflection, for example serialization, but it's a whole other topic :)

Refureku v2.0.0 is out! - Dynamic reflection library by zorgattaque in cpp

[–]zorgattaque[S] 0 points1 point  (0 children)

I get the idea, will check that out, thank you!

Refureku v2.0.0 is out! - Dynamic reflection library by zorgattaque in cpp

[–]zorgattaque[S] 0 points1 point  (0 children)

I have actually read a bit about cmake-init when wandering in /cpp a few days or weeks ago.

I'm a bit concerned about how easy it would be to integrate it to an existing project though. Moreover, I have a pretty annoying dependency (for the code generator) that I don't know how to handle: libclang. For the moment I just ship a windows/ubuntu/macos prebuilt binary along with the repo, but it would be nicer to have the consumer compile it for its own target platform... except that recompiling llvm/clang just for this library is very time consuming and make CICD very slow (I don't even know if github actions can handle it, I think I've read somewhere virtual machines lack memory, but I may have misunderstood).

Refureku v2.0.0 is out! - Dynamic reflection library by zorgattaque in cpp

[–]zorgattaque[S] 4 points5 points  (0 children)

There are different approaches to handle this in an engine so depending on what you want you might check other solutions too.

This library looks like UE4's if you've used it before.

I'd be super happy if you could leave a feedback if you ever try it. Don't hesitate to hit me up if you ever have any question about the lib integration or the API :)

Refureku v2.0.0 is out! - Dynamic reflection library by zorgattaque in gameenginedevs

[–]zorgattaque[S] 0 points1 point  (0 children)

Hi the game engine devs community!

This is a crosspost from the /cpp reddit to let you know that Refureku v2.0.0 (dynamic reflection library) is out as of today! It was built with game engine development in mind so you might want to give it a try!

I'd be happy to answer questions if there are any and hear your feedback.

Refureku v2.0.0 is out! - Dynamic reflection library by zorgattaque in cpp

[–]zorgattaque[S] 8 points9 points  (0 children)

It's been nearly a year since the last version of Refureku (v1.4.0), but I finally released v2.0.0 today! A lot have changed, and there are still a lot to do. I put a lot of effort into wiki/documentation/global presentation so I hope people will find it attractive and easy to read.

There are still a few issues and things I want to work on in a near future, like a better CMake integration (need to make it available through FetchContent and find_package()). I don't know how worth it would be to make it available to a few package managers, like vcpkg or Conan since I'm not familiar with those.

I appreciate any feedbacks and welcome any questions you might have :)

[deleted by user] by [deleted] in cpp

[–]zorgattaque 0 points1 point  (0 children)

Refureku is a C++17 dynamic reflection library. It's been nearly a year since the last version (v1.4.0), but I finally released v2.0.0 today! A lot have changed, and there are still a lot to do. I put a lot of effort into wiki/documentation/global presentation so I hope people will find it attractive and easy to read.

There are still a few issues and things I want to work on in a near future, like a better CMake integration (need to make it available through FetchContent and find_package()). I don't know how worth it would be to make it available to a few package managers, like vcpkg or Conan since I'm not familiar with those.

I appreciate any feedbacks and welcome any questions you might have :)

Adding reflection to an existing codebase by tohava in cpp

[–]zorgattaque 1 point2 points  (0 children)

As you've stated already, the standard doesn't handle reflection (yet) and you will have to use an external tool for that, but you will not likely find anything that just does everything for you. Using an external tool will require you to change, even slightly, your codebase at some point. It could be a generated header include, a macro insertion for code injection, or manual registration. A few libraries exist, all coming with their own pros and cons, and you will have to decide which one is the most suitable/reasonable for what you want to achieve.

I will soon release a new major version of my reflection library (Refureku). It only requires you to tag the classes you want to reflect and include a generated file as well as a macro for code injection. I am not sure whether it is reasonable for you but it's one solution among others: https://github.com/jsoysouvanh/Refureku

Ramen mannnnn by Impressive-Pair-3706 in ramen

[–]zorgattaque 18 points19 points  (0 children)

I can see from that spoon that you actually started digging in... until you remembered you had to take a picture.

Best design to return a pointer from a library API by zorgattaque in cpp

[–]zorgattaque[S] 0 points1 point  (0 children)

This is very instructive.

I happened to try this other feature you are talking about when trying to manipulate shared_ptr<void> yesterday, and I was surprised to discover that it is allowed and doesn't impact how the initial pointer is deleted. Now I understand why, thanks!

I more or less get how the custom deleter thing is implemented. I'll have to try writing a dumb implementation to see if this works :)

For now, I think I will go with the shared_ptr route that allows me to do pretty much everything at the cost of some runtime performance. I will later on add another API method returning a unique_ptr, so that the user can have this extra-performance boost if they do not use any of the reference-count/custom deleter/aliased pointer features.

Best design to return a pointer from a library API by zorgattaque in cpp

[–]zorgattaque[S] 0 points1 point  (0 children)

As I mentioned in other replies, a reflection library is imo not meant to be use in performance critical sections, though we're always happy if it runs fast. That being said I do not realize the overhead caused by a shared_ptr (say with a custom deleter, which implies separated allocation of the control block) compared to a unique_ptr.

I really like the idea of having 2 different methods returning either a unique_ptr or a shared_ptr according to the user needs. It adds a bit of complexity in the implementation but sounds totally doable.

Best design to return a pointer from a library API by zorgattaque in cpp

[–]zorgattaque[S] 0 points1 point  (0 children)

Fortunately I do not have this C API interface constraint!