-
-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make our custom noises inherit Godot Noise.
Depends on godotengine/godot#100443
- Loading branch information
Showing
13 changed files
with
465 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "noise.h" | ||
#include "../../io/log.h" | ||
|
||
namespace zylann { | ||
|
||
#if defined(ZN_GODOT) | ||
|
||
real_t ZN_Noise::get_noise_1d(real_t p_x) const { | ||
return _zn_get_noise_1d(p_x); | ||
} | ||
|
||
real_t ZN_Noise::get_noise_2dv(Vector2 p_v) const { | ||
return _zn_get_noise_2d(p_v); | ||
} | ||
|
||
real_t ZN_Noise::get_noise_2d(real_t p_x, real_t p_y) const { | ||
return _zn_get_noise_2d(Vector2(p_x, p_y)); | ||
} | ||
|
||
real_t ZN_Noise::get_noise_3dv(Vector3 p_v) const { | ||
return _zn_get_noise_3d(p_v); | ||
} | ||
|
||
real_t ZN_Noise::get_noise_3d(real_t p_x, real_t p_y, real_t p_z) const { | ||
return _zn_get_noise_3d(Vector3(p_x, p_y, p_z)); | ||
} | ||
|
||
#elif defined(ZN_GODOT_EXTENSION) && (GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MINOR >= 4) | ||
|
||
real_t ZN_Noise::_get_noise_1d(real_t p_x) const { | ||
return _zn_get_noise_1d(p_x); | ||
} | ||
|
||
real_t ZN_Noise::_get_noise_2d(Vector2 p_v) const { | ||
return _zn_get_noise_2d(p_v); | ||
} | ||
|
||
real_t ZN_Noise::_get_noise_3d(Vector3 p_v) const { | ||
return _zn_get_noise_3d(p_v); | ||
} | ||
|
||
#endif | ||
|
||
real_t ZN_Noise::_zn_get_noise_1d(real_t p_x) const { | ||
// Should be implemented in derived classes | ||
ZN_PRINT_ERROR_ONCE("Not implemented"); | ||
return 0.0; | ||
} | ||
|
||
real_t ZN_Noise::_zn_get_noise_2d(Vector2 p_v) const { | ||
// Should be implemented in derived classes | ||
ZN_PRINT_ERROR_ONCE("Not implemented"); | ||
return 0.0; | ||
} | ||
|
||
real_t ZN_Noise::_zn_get_noise_3d(Vector3 p_v) const { | ||
// Should be implemented in derived classes | ||
ZN_PRINT_ERROR_ONCE("Not implemented"); | ||
return 0.0; | ||
} | ||
|
||
// #if defined(ZN_GODOT_EXTENSION) && (GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MINOR <= 3) | ||
// void real_t ZN_Noise::_b_get_noise_2dv(real_t p_x, real_t p_y) const { | ||
// return _zn_get_noise_2d(Vector2(p_x, p_y)); | ||
// } | ||
|
||
// void real_t ZN_Noise::_b_get_noise_3dv(real_t p_x, real_t p_y, real_t p_z) const { | ||
// return _zn_get_noise_3d(Vector3(p_x, p_y, p_z)); | ||
// } | ||
// #endif | ||
|
||
void ZN_Noise::_bind_methods() { | ||
// #if defined(ZN_GODOT_EXTENSION) && (GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MINOR <= 3) | ||
// ClassDB::bind_method(D_METHOD("get_noise_2d", "x", "y"), &ZN_FastNoiseLite::_zn_get_noise_2dc); | ||
// ClassDB::bind_method(D_METHOD("get_noise_3d", "x", "y", "z"), &ZN_FastNoiseLite::_zn_get_noise_2dc); | ||
|
||
// ClassDB::bind_method(D_METHOD("get_noise_2dv", "position"), &ZN_FastNoiseLite::_zn_get_noise_2d); | ||
// ClassDB::bind_method(D_METHOD("get_noise_3dv", "position"), &ZN_FastNoiseLite::_zn_get_noise_3d); | ||
// #endif | ||
} | ||
|
||
} // namespace zylann |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,52 @@ | ||
#ifndef ZN_GODOT_NOISE_H | ||
#define ZN_GODOT_NOISE_H | ||
|
||
#include "../core/version.h" | ||
|
||
#if defined(ZN_GODOT) | ||
#include <modules/noise/noise.h> | ||
#elif defined(ZN_GODOT_EXTENSION) | ||
#include <godot_cpp/classes/noise.hpp> | ||
using namespace godot; | ||
#endif | ||
|
||
namespace zylann { | ||
|
||
#if defined(ZN_GODOT) || (GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MINOR >= 4) | ||
class ZN_Noise : public Noise { | ||
GDCLASS(ZN_Noise, Noise) | ||
#else | ||
// Noise is abstract in the extension API and cannot be inherited | ||
class ZN_Noise : public Resource { | ||
GDCLASS(ZN_Noise, Resource) | ||
#endif | ||
public: | ||
#if defined(ZN_GODOT) | ||
real_t get_noise_1d(real_t p_x) const override; | ||
real_t get_noise_2dv(Vector2 p_v) const override; | ||
real_t get_noise_2d(real_t p_x, real_t p_y) const override; | ||
real_t get_noise_3dv(Vector3 p_v) const override; | ||
real_t get_noise_3d(real_t p_x, real_t p_y, real_t p_z) const override; | ||
#elif defined(ZN_GODOT_EXTENSION) && (GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MINOR >= 4) | ||
real_t _get_noise_1d(real_t p_x) const override; | ||
real_t _get_noise_2d(Vector2 p_v) const override; | ||
real_t _get_noise_3d(Vector3 p_v) const override; | ||
#endif | ||
|
||
protected: | ||
virtual real_t _zn_get_noise_1d(real_t p_x) const; | ||
virtual real_t _zn_get_noise_2d(Vector2 p_v) const; | ||
virtual real_t _zn_get_noise_3d(Vector3 p_v) const; | ||
|
||
// #if defined(ZN_GODOT_EXTENSION) && (GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MINOR <= 3) | ||
// void real_t _b_get_noise_2dc(real_t p_x, real_t p_y) const; | ||
// void real_t _b_get_noise_3dc(real_t p_x, real_t p_y, real_t p_z) const; | ||
// #endif | ||
|
||
private: | ||
static void _bind_methods(); | ||
}; | ||
|
||
} // namespace zylann | ||
|
||
#endif // ZN_GODOT_NOISE_H |
Oops, something went wrong.