Merge pull request #57 from aaronfranke/win

Add Windows support to C++ demos
This commit is contained in:
Aaron Franke
2021-07-10 20:51:06 -07:00
committed by GitHub
24 changed files with 117 additions and 139 deletions

View File

@@ -8,6 +8,8 @@ Dependencies:
this is now a Git submodule of this repo.
* `clang`, `gcc`, or any decent C compiler that's C11 compatible.
* You need to have GLFW and its headers installed.
* On Ubuntu Linux: `sudo apt install libglfw3 libglfw3-dev`
* On macOS: `brew install glfw`
## Compile with SCons (cross platform)
You can use SCons to compile the library if you have it installed:

View File

@@ -40,27 +40,22 @@ if env["platform"] == "":
platform = env["platform"]
# Process other arguments.
if True or env["use_llvm"]: # TODO: GCC doesn't work for some reason.
env["CC"] = "clang"
env["CXX"] = "clang++"
# Check our platform specifics
if env["platform"] == "macos":
# Check our platform specifics.
if platform == "macos":
if not env["use_llvm"]:
env["use_llvm"] = "yes"
if env["target"] in ("debug", "d"):
env.Append(CCFLAGS=["-g", "-O2", "-arch", "x86_64"])
env.Append(LINKFLAGS=["-arch", "x86_64"])
else:
env.Append(CCFLAGS=["-g", "-O3", "-arch", "x86_64"])
env.Append(LINKFLAGS=["-arch", "x86_64"])
elif env["platform"] == "linuxbsd":
elif platform == "linuxbsd":
if env["target"] in ("debug", "d"):
env.Append(CCFLAGS=["-fPIC", "-g3", "-Og"])
else:
env.Append(CCFLAGS=["-fPIC", "-g", "-O3"])
elif env["platform"] == "windows":
elif platform == "windows":
# This makes sure to keep the session environment variables
# on Windows, so that you can run scons in a VS 2017 prompt
# and it will find all the required tools.
@@ -73,6 +68,10 @@ elif env["platform"] == "windows":
else:
env.Append(CCFLAGS=["-O2", "-EHsc", "-DNDEBUG", "-MD"])
if env["use_llvm"] == "yes":
env["CC"] = "clang"
env["CXX"] = "clang++"
# Make sure our library includes the Godot headers.
env.Append(CPPPATH=[".", godot_headers_path])

View File

@@ -27,3 +27,5 @@ multithread/thread_rid_pool_prealloc=60
[rendering]
quality/driver/driver_name="GLES2"
vram_compression/import_etc=true
vram_compression/import_etc2=false

View File

@@ -40,27 +40,22 @@ if env["platform"] == "":
platform = env["platform"]
# Process other arguments.
if env["use_llvm"]:
env["CC"] = "clang"
env["CXX"] = "clang++"
# Check our platform specifics
if env["platform"] == "macos":
# Check our platform specifics.
if platform == "macos":
if not env["use_llvm"]:
env["use_llvm"] = "yes"
if env["target"] in ("debug", "d"):
env.Append(CCFLAGS=["-g", "-O2", "-arch", "x86_64"])
env.Append(LINKFLAGS=["-arch", "x86_64"])
else:
env.Append(CCFLAGS=["-g", "-O3", "-arch", "x86_64"])
env.Append(LINKFLAGS=["-arch", "x86_64"])
elif env["platform"] == "linuxbsd":
elif platform == "linuxbsd":
if env["target"] in ("debug", "d"):
env.Append(CCFLAGS=["-fPIC", "-g3", "-Og"])
else:
env.Append(CCFLAGS=["-fPIC", "-g", "-O3"])
elif env["platform"] == "windows":
elif platform == "windows":
# This makes sure to keep the session environment variables
# on Windows, so that you can run scons in a VS 2017 prompt
# and it will find all the required tools.
@@ -73,6 +68,10 @@ elif env["platform"] == "windows":
else:
env.Append(CCFLAGS=["-O2", "-EHsc", "-DNDEBUG", "-MD"])
if env["use_llvm"] == "yes":
env["CC"] = "clang"
env["CXX"] = "clang++"
# Make sure our library includes the Godot headers.
env.Append(CPPPATH=[".", godot_headers_path])

View File

@@ -31,3 +31,5 @@ multithread/thread_rid_pool_prealloc=60
[rendering]
quality/driver/driver_name="GLES2"
vram_compression/import_etc=true
vram_compression/import_etc2=false

View File

@@ -40,27 +40,22 @@ if env["platform"] == "":
platform = env["platform"]
# Process other arguments.
if env["use_llvm"]:
env["CC"] = "clang"
env["CXX"] = "clang++"
# Check our platform specifics
if env["platform"] == "macos":
# Check our platform specifics.
if platform == "macos":
if not env["use_llvm"]:
env["use_llvm"] = "yes"
if env["target"] in ("debug", "d"):
env.Append(CCFLAGS=["-g", "-O2", "-arch", "x86_64"])
env.Append(LINKFLAGS=["-arch", "x86_64"])
else:
env.Append(CCFLAGS=["-g", "-O3", "-arch", "x86_64"])
env.Append(LINKFLAGS=["-arch", "x86_64"])
elif env["platform"] == "linuxbsd":
elif platform == "linuxbsd":
if env["target"] in ("debug", "d"):
env.Append(CCFLAGS=["-fPIC", "-g3", "-Og"])
else:
env.Append(CCFLAGS=["-fPIC", "-g", "-O3"])
elif env["platform"] == "windows":
elif platform == "windows":
# This makes sure to keep the session environment variables
# on Windows, so that you can run scons in a VS 2017 prompt
# and it will find all the required tools.
@@ -73,6 +68,10 @@ elif env["platform"] == "windows":
else:
env.Append(CCFLAGS=["-O2", "-EHsc", "-DNDEBUG", "-MD"])
if env["use_llvm"] == "yes":
env["CC"] = "clang"
env["CXX"] = "clang++"
# Make sure our library includes the Godot headers.
env.Append(CPPPATH=[".", godot_headers_path])

View File

@@ -10,7 +10,6 @@ config_version=4
_global_script_classes=[ ]
_global_script_class_icons={
}
[application]
@@ -27,3 +26,9 @@ singletons=[ ]
[memory]
multithread/thread_rid_pool_prealloc=60
[rendering]
quality/driver/driver_name="GLES2"
vram_compression/import_etc=true
vram_compression/import_etc2=false

View File

@@ -3,12 +3,13 @@ import os
opts = Variables([], ARGUMENTS)
# Gets the standard flags CC, CCX, etc.
env = DefaultEnvironment()
# Define the relative path to the Godot headers.
godot_headers_path = "godot-cpp/godot-headers"
godot_bindings_path = "godot-cpp"
# Gets the standard flags CC, CCX, etc.
env = DefaultEnvironment()
# Define our options. Use future-proofed names for platforms.
platform_array = ["", "windows", "linuxbsd", "macos", "x11", "linux", "osx"]
opts.Add(EnumVariable("target", "Compilation target", "debug", ["d", "debug", "r", "release"]))
@@ -38,28 +39,22 @@ if env["platform"] == "":
platform = env["platform"]
# Process other arguments.
if env["platform"] == "osx" and not env["use_llvm"]:
env["use_llvm"] = "yes"
if env["use_llvm"] == "yes":
env["CC"] = "clang"
env["CXX"] = "clang++"
# put stuff that is the same for all first, saves duplication
if env["platform"] == "osx":
# Check our platform specifics.
if platform == "osx":
if not env["use_llvm"]:
env["use_llvm"] = "yes"
if env["target"] in ("debug", "d"):
env.Append(CCFLAGS=["-g", "-O2", "-arch", "x86_64", "-std=c++14"])
env.Append(LINKFLAGS=["-arch", "x86_64"])
else:
env.Append(CCFLAGS=["-g", "-O3", "-arch", "x86_64", "-std=c++14"])
env.Append(LINKFLAGS=["-arch", "x86_64"])
elif env["platform"] == "linux":
elif platform == "linux":
if env["target"] in ("debug", "d"):
env.Append(CCFLAGS=["-fPIC", "-g3", "-Og"])
else:
env.Append(CCFLAGS=["-fPIC", "-g", "-O3"])
elif env["platform"] == "windows":
elif platform == "windows":
# This makes sure to keep the session environment variables
# on Windows, so that you can run scons in a VS 2017 prompt
# and it will find all the required tools.
@@ -72,6 +67,10 @@ elif env["platform"] == "windows":
else:
env.Append(CCFLAGS=["-O2", "-EHsc", "-DNDEBUG", "-MD"])
if env["use_llvm"] == "yes":
env["CC"] = "clang"
env["CXX"] = "clang++"
SConscript("godot-cpp/SConstruct")
@@ -92,11 +91,7 @@ env.Append(
env.Append(
LIBS=[
env.File(
os.path.join(
"godot-cpp/bin", "libgodot-cpp.%s.%s.64%s" % (env["platform"], env["target"], env["LIBSUFFIX"])
)
)
env.File(os.path.join("godot-cpp/bin", "libgodot-cpp.%s.%s.64%s" % (platform, env["target"], env["LIBSUFFIX"])))
]
)
@@ -105,7 +100,5 @@ env.Append(LIBPATH=[godot_bindings_path + "/bin/"])
sources = []
add_sources(sources, "src")
library = env.SharedLibrary(
target=env["target_path"] + "/" + env["platform"] + "/" + env["target_name"], source=sources
)
library = env.SharedLibrary(target=env["target_path"] + "/" + platform + "/" + env["target_name"], source=sources)
Default(library)

View File

@@ -23,7 +23,7 @@ void HUD::show_game_over() {
_start_message_timer->start();
}
void HUD::update_score(int p_score) {
void HUD::update_score(const int p_score) {
_score_label->set_text(godot::Variant(p_score));
}
@@ -51,5 +51,5 @@ void HUD::_register_methods() {
godot::register_method("_on_StartButton_pressed", &HUD::_on_StartButton_pressed);
godot::register_method("_on_StartMessageTimer_timeout", &HUD::_on_StartMessageTimer_timeout);
godot::register_method("_on_GetReadyMessageTimer_timeout", &HUD::_on_GetReadyMessageTimer_timeout);
godot::register_signal<HUD>("start_game");
godot::register_signal<HUD>("start_game", godot::Dictionary());
}

View File

@@ -22,7 +22,7 @@ public:
void _ready();
void show_get_ready();
void show_game_over();
void update_score(int score);
void update_score(const int score);
void _on_StartButton_pressed();
void _on_StartMessageTimer_timeout();
void _on_GetReadyMessageTimer_timeout();

View File

@@ -38,20 +38,20 @@ void Main::new_game() {
void Main::_on_MobTimer_timeout() {
// Choose a random location on Path2D.
_mob_spawn_location->set_offset(_random->randi());
_mob_spawn_location->set_offset((real_t)_random->randi());
// Create a Mob instance and add it to the scene.
godot::Node *mob = mob_scene->instance();
add_child(mob);
// Set the mob's direction perpendicular to the path direction.
real_t direction = _mob_spawn_location->get_rotation() + Math_PI / 2;
real_t direction = _mob_spawn_location->get_rotation() + (real_t)Math_PI / 2;
// Set the mob's position to a random location.
mob->set("position", _mob_spawn_location->get_position());
// Add some randomness to the direction.
direction += _random->randf_range(-Math_PI / 4, Math_PI / 4);
direction += _random->randf_range((real_t)-Math_PI / 4, (real_t)Math_PI / 4);
mob->set("rotation", direction);
// Choose the velocity for the mob.

View File

@@ -16,12 +16,7 @@ void Mob::_on_VisibilityNotifier2D_screen_exited() {
queue_free();
}
void Mob::_on_start_game() {
queue_free();
}
void Mob::_register_methods() {
godot::register_method("_ready", &Mob::_ready);
godot::register_method("_on_VisibilityNotifier2D_screen_exited", &Mob::_on_VisibilityNotifier2D_screen_exited);
godot::register_method("_on_start_game", &Mob::_on_start_game);
}

View File

@@ -11,13 +11,9 @@ class Mob : public godot::RigidBody2D {
godot::AnimatedSprite *_animated_sprite;
public:
int min_speed = 150;
int max_speed = 250;
void _init() {}
void _ready();
void _on_VisibilityNotifier2D_screen_exited();
void _on_start_game();
static void _register_methods();
};

View File

@@ -9,7 +9,7 @@ void Player::_ready() {
hide();
}
void Player::_process(double p_delta) {
void Player::_process(const double p_delta) {
godot::Input *input = godot::Input::get_singleton();
godot::Vector2 velocity(0, 0);
@@ -24,7 +24,7 @@ void Player::_process(double p_delta) {
}
godot::Vector2 position = get_position();
position += velocity * p_delta;
position += velocity * (real_t)p_delta;
position.x = godot::Math::clamp(position.x, (real_t)0.0, _screen_size.x);
position.y = godot::Math::clamp(position.y, (real_t)0.0, _screen_size.y);
set_position(position);
@@ -39,7 +39,7 @@ void Player::_process(double p_delta) {
}
}
void Player::start(godot::Vector2 p_position) {
void Player::start(const godot::Vector2 p_position) {
set_position(p_position);
show();
_collision_shape->set_disabled(false);
@@ -57,6 +57,6 @@ void Player::_register_methods() {
godot::register_method("_process", &Player::_process);
godot::register_method("start", &Player::start);
godot::register_method("_on_Player_body_entered", &Player::_on_Player_body_entered);
godot::register_property("speed", &Player::speed, 400);
godot::register_signal<Player>("hit");
godot::register_property("speed", &Player::speed, (real_t)400.0);
godot::register_signal<Player>("hit", godot::Dictionary());
}

View File

@@ -14,12 +14,12 @@ class Player : public godot::Area2D {
godot::Vector2 _screen_size; // Size of the game window.
public:
int speed = 400; // How fast the player will move (pixels/sec).
real_t speed = 400; // How fast the player will move (pixels/sec).
void _init() {}
void _ready();
void _process(double p_delta);
void start(godot::Vector2 p_position);
void _process(const double p_delta);
void start(const godot::Vector2 p_position);
void _on_Player_body_entered(godot::Node2D *_body);
static void _register_methods();

View File

@@ -3,12 +3,13 @@ import os
opts = Variables([], ARGUMENTS)
# Gets the standard flags CC, CCX, etc.
env = DefaultEnvironment()
# Define the relative path to the Godot headers.
godot_headers_path = "godot-cpp/godot-headers"
godot_bindings_path = "godot-cpp"
# Gets the standard flags CC, CCX, etc.
env = DefaultEnvironment()
# Define our options. Use future-proofed names for platforms.
platform_array = ["", "windows", "linuxbsd", "macos", "x11", "linux", "osx"]
opts.Add(EnumVariable("target", "Compilation target", "debug", ["d", "debug", "r", "release"]))
@@ -38,28 +39,22 @@ if env["platform"] == "":
platform = env["platform"]
# Process other arguments.
if env["platform"] == "osx" and not env["use_llvm"]:
env["use_llvm"] = "yes"
if env["use_llvm"] == "yes":
env["CC"] = "clang"
env["CXX"] = "clang++"
# put stuff that is the same for all first, saves duplication
if env["platform"] == "osx":
# Check our platform specifics.
if platform == "osx":
if not env["use_llvm"]:
env["use_llvm"] = "yes"
if env["target"] in ("debug", "d"):
env.Append(CCFLAGS=["-g", "-O2", "-arch", "x86_64", "-std=c++14"])
env.Append(LINKFLAGS=["-arch", "x86_64"])
else:
env.Append(CCFLAGS=["-g", "-O3", "-arch", "x86_64", "-std=c++14"])
env.Append(LINKFLAGS=["-arch", "x86_64"])
elif env["platform"] == "linux":
elif platform == "linux":
if env["target"] in ("debug", "d"):
env.Append(CCFLAGS=["-fPIC", "-g3", "-Og"])
else:
env.Append(CCFLAGS=["-fPIC", "-g", "-O3"])
elif env["platform"] == "windows":
elif platform == "windows":
# This makes sure to keep the session environment variables
# on Windows, so that you can run scons in a VS 2017 prompt
# and it will find all the required tools.
@@ -72,6 +67,10 @@ elif env["platform"] == "windows":
else:
env.Append(CCFLAGS=["-O2", "-EHsc", "-DNDEBUG", "-MD"])
if env["use_llvm"] == "yes":
env["CC"] = "clang"
env["CXX"] = "clang++"
SConscript("godot-cpp/SConstruct")
@@ -92,11 +91,7 @@ env.Append(
env.Append(
LIBS=[
env.File(
os.path.join(
"godot-cpp/bin", "libgodot-cpp.%s.%s.64%s" % (env["platform"], env["target"], env["LIBSUFFIX"])
)
)
env.File(os.path.join("godot-cpp/bin", "libgodot-cpp.%s.%s.64%s" % (platform, env["target"], env["LIBSUFFIX"])))
]
)
@@ -105,7 +100,5 @@ env.Append(LIBPATH=[godot_bindings_path + "/bin/"])
sources = []
add_sources(sources, "src")
library = env.SharedLibrary(
target=env["target_path"] + "/" + env["platform"] + "/" + env["target_name"], source=sources
)
library = env.SharedLibrary(target=env["target_path"] + "/" + platform + "/" + env["target_name"], source=sources)
Default(library)

View File

@@ -4,10 +4,10 @@ void Ball::_ready() {
_initial_pos = get_position();
}
void Ball::_process(double p_delta) {
_speed += p_delta * 2;
void Ball::_process(const double p_delta) {
_speed += (real_t)p_delta * 2;
godot::Vector2 position = get_position();
position += _speed * p_delta * direction;
position += _speed * (real_t)p_delta * direction;
set_position(position);
}

View File

@@ -7,7 +7,7 @@
class Ball : public godot::Area2D {
GODOT_CLASS(Ball, godot::Area2D)
const int DEFAULT_SPEED = 100;
const real_t DEFAULT_SPEED = 100;
real_t _speed = DEFAULT_SPEED;
godot::Vector2 _initial_pos;
@@ -16,7 +16,7 @@ public:
void _init() {}
void _ready();
void _process(double p_delta);
void _process(const double p_delta);
void reset();
static void _register_methods();

View File

@@ -2,7 +2,7 @@
void CeilingFloor::_on_area_entered(Ball *p_ball) {
if (p_ball->get_name() == "Ball") {
p_ball->direction = (p_ball->direction + godot::Vector2(0, bounce_direction)).normalized();
p_ball->direction = (p_ball->direction + godot::Vector2(0, (real_t)bounce_direction)).normalized();
}
}

View File

@@ -15,12 +15,12 @@ void Paddle::_ready() {
}
}
void Paddle::_process(double delta) {
void Paddle::_process(const double delta) {
godot::Input *input = godot::Input::get_singleton();
// Move up and down based on input.
real_t keyboard_input = input->get_action_strength(_down) - input->get_action_strength(_up);
godot::Vector2 position = get_position();
position.y = godot::Math::clamp(position.y + keyboard_input * MOVE_SPEED * delta, 16.0, _screen_size_y - 16.0);
position.y = (real_t)godot::Math::clamp(position.y + keyboard_input * MOVE_SPEED * delta, 16.0, _screen_size_y - 16.0);
set_position(position);
}
@@ -29,7 +29,7 @@ void Paddle::_on_area_entered(Ball *p_ball) {
godot::Ref<godot::RandomNumberGenerator> random = godot::RandomNumberGenerator::_new();
random->randomize();
// Assign new direction.
p_ball->direction = godot::Vector2(_ball_dir, random->randf() * 2 - 1).normalized();
p_ball->direction = godot::Vector2((real_t)_ball_dir, random->randf() * 2 - 1).normalized();
}
}

View File

@@ -20,7 +20,7 @@ class Paddle : public godot::Area2D {
public:
void _init() {}
void _ready();
void _process(double p_delta);
void _process(const double p_delta);
void _on_area_entered(Ball *p_area);
static void _register_methods();

View File

@@ -3,12 +3,13 @@ import os
opts = Variables([], ARGUMENTS)
# Gets the standard flags CC, CCX, etc.
env = DefaultEnvironment()
# Define the relative path to the Godot headers.
godot_headers_path = "godot-cpp/godot-headers"
godot_bindings_path = "godot-cpp"
# Gets the standard flags CC, CCX, etc.
env = DefaultEnvironment()
# Define our options. Use future-proofed names for platforms.
platform_array = ["", "windows", "linuxbsd", "macos", "x11", "linux", "osx"]
opts.Add(EnumVariable("target", "Compilation target", "debug", ["d", "debug", "r", "release"]))
@@ -38,28 +39,22 @@ if env["platform"] == "":
platform = env["platform"]
# Process other arguments.
if env["platform"] == "osx" and not env["use_llvm"]:
env["use_llvm"] = "yes"
if env["use_llvm"] == "yes":
env["CC"] = "clang"
env["CXX"] = "clang++"
# put stuff that is the same for all first, saves duplication
if env["platform"] == "osx":
# Check our platform specifics.
if platform == "osx":
if not env["use_llvm"]:
env["use_llvm"] = "yes"
if env["target"] in ("debug", "d"):
env.Append(CCFLAGS=["-g", "-O2", "-arch", "x86_64", "-std=c++14"])
env.Append(LINKFLAGS=["-arch", "x86_64"])
else:
env.Append(CCFLAGS=["-g", "-O3", "-arch", "x86_64", "-std=c++14"])
env.Append(LINKFLAGS=["-arch", "x86_64"])
elif env["platform"] == "linux":
elif platform == "linux":
if env["target"] in ("debug", "d"):
env.Append(CCFLAGS=["-fPIC", "-g3", "-Og"])
else:
env.Append(CCFLAGS=["-fPIC", "-g", "-O3"])
elif env["platform"] == "windows":
elif platform == "windows":
# This makes sure to keep the session environment variables
# on Windows, so that you can run scons in a VS 2017 prompt
# and it will find all the required tools.
@@ -72,6 +67,10 @@ elif env["platform"] == "windows":
else:
env.Append(CCFLAGS=["-O2", "-EHsc", "-DNDEBUG", "-MD"])
if env["use_llvm"] == "yes":
env["CC"] = "clang"
env["CXX"] = "clang++"
SConscript("godot-cpp/SConstruct")
@@ -92,11 +91,7 @@ env.Append(
env.Append(
LIBS=[
env.File(
os.path.join(
"godot-cpp/bin", "libgodot-cpp.%s.%s.64%s" % (env["platform"], env["target"], env["LIBSUFFIX"])
)
)
env.File(os.path.join("godot-cpp/bin", "libgodot-cpp.%s.%s.64%s" % (platform, env["target"], env["LIBSUFFIX"])))
]
)
@@ -105,7 +100,5 @@ env.Append(LIBPATH=[godot_bindings_path + "/bin/"])
sources = []
add_sources(sources, "src")
library = env.SharedLibrary(
target=env["target_path"] + "/" + env["platform"] + "/" + env["target_name"], source=sources
)
library = env.SharedLibrary(target=env["target_path"] + "/" + platform + "/" + env["target_name"], source=sources)
Default(library)

View File

@@ -24,12 +24,12 @@ void SimpleSprite::_init() {
godot::Godot::print("A SimpleSprite was initialized in GDNative!");
}
void SimpleSprite::_process(double p_delta) {
void SimpleSprite::_process(const double p_delta) {
godot::Input *input = godot::Input::get_singleton();
godot::Vector2 input_dir(0, 0);
input_dir.x = input->get_action_strength("ui_right") - input->get_action_strength("ui_left");
input_dir.y = input->get_action_strength("ui_down") - input->get_action_strength("ui_up");
set_position(get_position() + input_dir.normalized() * p_delta * 300);
set_position(get_position() + input_dir.normalized() * (real_t)p_delta * 300);
}

View File

@@ -27,7 +27,7 @@ public:
void _init();
void _process(double p_delta);
void _process(const double p_delta);
};
#endif // SIMPLE_H