Is it possible to check if a method exists, and if not, create a fallback one?

I have a namespace with methods with which I would like to have an implicit fallback to a different method if the aforementioned method doesn't exist. As an example, here's how I made my states.

#pragma once
#include "godot_cpp/classes/character_body2d.hpp"
#include "statemachine/base/state_base.h"

namespace GameLogic::States::ColorState
{
	constexpr double MAX_TIMER { 3.0 };
	struct ColorStateData
	{
		STATESTRUCT();
		godot::Ref<godot::StateMachine> state_machine;
		CharacterBody2D* entity;
		double timer {0.0};
	};
	void setup_state(ColorStateData& data);
	void enter_state(ColorStateData& data);
	void physics_update_state(ColorStateData& data, double delta);
	void update_state(ColorStateData& data, double delta);
	void exit_state(ColorStateData& data);
	STATESPACE(ColorStateData, GameLogic::States::ColorState)
}

It would be nice if I didn't have to specify 5 methods each time. Can I build this check into STATESPACE? In C++ 17 by the way.

reddit.com
u/Predret — 3 days ago

Problem making X macros from X macros

What I am doing:
Hello, I am working on something in C++ for Godot, but this is more of a C++ question than a Godot question. I have a singular X macro to register a struct into a system I made, but the logic is in many places, and considering I am updating this macro and adding variables, it'd be easier to have a specific macro that doesn't change.

Problem:
When I make an X macro from an X macro, it doesn't properly expand. As an example this file:

#pragma once
#include "statemachine/registry/state_registry_register.h"

#define X_GENERATE_KIND(DataType, NS) k##DataType,
enum class StateKind : std::uint8_t
{
    EACH_STATE_REGISTER(X_GENERATE_KIND)
    kUnknown
};
#undef X_GENERATE_KIND

has the macro on line 7 expand to X(something1, something2) instead of k##something1, or, in my case:

X(WalkStateData, GameLogic ::States ::WalkState) X(WalkBackStateData, GameLogic ::States ::WalkBackState);

I defined EACH_STATE_REGISTER like this:

#define REGISTER_TO_ESR(DataType, NS, fields) X(DataType, NS)

#define EACH_STATE_REGISTER(X) \
REGISTER_EACH_STATE(REGISTER_TO_ESR);

and the REGISTER_EACH_STATE as

#define REGISTER\_EACH\_STATE(State) \
State(WalkStateData, GameLogic::States::WalkState, NO_STATE_FIELDS) \
State(WalkBackStateData, GameLogic::States::WalkBackState, NO_STATE_FIELDS)

Can anyone tell me why this happens, and if this is even fixable? (c++ 17)

reddit.com
u/Predret — 9 days ago

Cursor hovering issue

My version is 0.55.4, running this in a hyper-v VM (standard session).

Am having issues with cursor hovering. Apps don't properly recognize where my cursor is. Only when I click (specifically the mouse down, holding does not move it) or when my cursor first hovers over an application. Hyprland itself finds my cursor just find, as it finds what app my cursor hovers over, and finds it well. How can I fix this?

reddit.com
u/Predret — 2 months ago

I made a rust project! (How bad did I do, coming from a different language)

https://github.com/Predret/FirstRustProject-todo-list
This is a to-do list that doesn't save anything. I never intended for it to save, as this was just going to be the project that gets me into rust. I WILL say, I DID use SOME AI on things like understanding the names of existing functions, but I did the architecture myself. How bad is it?

u/Predret — 2 months ago