APPLE sucks and their libc libraries are old as fuck so c++23 things are not available like linux. Added MAC support so i can develop
This commit is contained in:
@@ -20,6 +20,27 @@ FetchContent_Declare(SFML
|
||||
EXCLUDE_FROM_ALL
|
||||
SYSTEM)
|
||||
FetchContent_MakeAvailable(SFML)
|
||||
# Detect macOS
|
||||
if(APPLE)
|
||||
message(STATUS "Detected macOS — using range-v3 for cartesian_product")
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
range-v3
|
||||
GIT_REPOSITORY https://github.com/ericniebler/range-v3.git
|
||||
GIT_TAG 0.12.0
|
||||
GIT_SHALLOW ON
|
||||
)
|
||||
FetchContent_MakeAvailable(range-v3)
|
||||
|
||||
# Add include directory globally or per target
|
||||
include_directories(${range-v3_SOURCE_DIR}/include)
|
||||
|
||||
# Optional: expose a macro so you can #ifdef it in code
|
||||
add_compile_definitions(USE_RANGE_V3)
|
||||
else()
|
||||
message(STATUS "Non-macOS system — assuming std::views::cartesian_product is available")
|
||||
endif()
|
||||
|
||||
add_executable(SFML_game_engine ${SOURCES})
|
||||
target_link_libraries(SFML_game_engine
|
||||
|
||||
+34
-21
@@ -4,7 +4,12 @@
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/Window/Keyboard.hpp>
|
||||
#ifdef __APPLE__
|
||||
#include <range/v3/view/iota.hpp>
|
||||
#include <range/v3/view/cartesian_product.hpp>
|
||||
#else
|
||||
#include <ranges>
|
||||
#endif
|
||||
|
||||
Entity::Entity(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f velocity, float border_thickness, sf::Color inside_color, sf::Color border_color) {
|
||||
rect.setSize(size);
|
||||
@@ -106,7 +111,11 @@ void Player::vertical_no_out_of_bounds(Entity &base) {
|
||||
}
|
||||
|
||||
bool Player::get_horizontal_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
||||
#ifdef __APPLE__
|
||||
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
#else
|
||||
for(auto [i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) {
|
||||
#endif
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
auto collision = wall_list[i][j]->find_intersection(*this);
|
||||
if(collision == CollisionDir::None) continue;
|
||||
@@ -121,33 +130,37 @@ bool Player::get_horizontal_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
||||
}
|
||||
|
||||
bool Player::get_vertical_top_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
||||
for(int i : std::views::iota(0, MAX_ROWS)) {
|
||||
for(int j : std::views::iota(0, MAX_COLS)) {
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
auto collision = find_intersection(*wall_list[i][j]);
|
||||
if(collision == CollisionDir::None) continue;
|
||||
if(collision == CollisionDir::Top) {
|
||||
rect.setPosition({ rect.getPosition().x, wall_list[i][j]->rect.getSize().y + wall_list[i][j]->rect.getPosition().y + rect.getOutlineThickness()});
|
||||
set_velocity_y(0);
|
||||
return true;
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
#else
|
||||
for(auto [i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) {
|
||||
#endif
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
auto collision = find_intersection(*wall_list[i][j]);
|
||||
if(collision == CollisionDir::None) continue;
|
||||
if(collision == CollisionDir::Top) {
|
||||
rect.setPosition({ rect.getPosition().x, wall_list[i][j]->rect.getSize().y + wall_list[i][j]->rect.getPosition().y + rect.getOutlineThickness()});
|
||||
set_velocity_y(0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Player::get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
||||
for(int i : std::views::iota(0, MAX_ROWS)) {
|
||||
for(int j : std::views::iota(0, MAX_COLS)) {
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
auto collision = find_intersection(*wall_list[i][j]);
|
||||
if(collision == CollisionDir::None) continue;
|
||||
if(collision == CollisionDir::Bottom && get_velocity().y > 0) {
|
||||
rect.setPosition({ rect.getPosition().x, wall_list[i][j]->rect.getPosition().y - rect.getSize().y });
|
||||
m_jumping = false;
|
||||
set_velocity_y(0);
|
||||
return true;
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
#else
|
||||
for(auto [i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) {
|
||||
#endif
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
auto collision = find_intersection(*wall_list[i][j]);
|
||||
if(collision == CollisionDir::None) continue;
|
||||
if(collision == CollisionDir::Bottom && get_velocity().y > 0) {
|
||||
rect.setPosition({ rect.getPosition().x, wall_list[i][j]->rect.getPosition().y - rect.getSize().y });
|
||||
m_jumping = false;
|
||||
set_velocity_y(0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
+32
-3
@@ -12,8 +12,12 @@
|
||||
#include <SFML/Window/Keyboard.hpp>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#ifdef __APPLE__
|
||||
#include <range/v3/view/iota.hpp>
|
||||
#include <range/v3/view/cartesian_product.hpp>
|
||||
#else
|
||||
#include <ranges>
|
||||
#include <iostream>
|
||||
#endif
|
||||
#include "globals.hpp"
|
||||
#include "elements.hpp"
|
||||
#include "maps.hpp"
|
||||
@@ -50,6 +54,17 @@ int main() {
|
||||
float border_size { -1.0f };
|
||||
} simulated_data;
|
||||
|
||||
#ifdef __APPLE__
|
||||
for(auto[i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
if(map_data[i][j] != 1) continue;
|
||||
wall_list[i][j] = new Entity { tile_data.size, tile_data.pos, tile_data.velocity, tile_data.border_size, sf::Color::Black };
|
||||
}
|
||||
|
||||
for(auto[i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
wall_list[i][j]->rect.setPosition({ (j * tile_data.size.x), (i * tile_data.size.y) });
|
||||
}
|
||||
#else
|
||||
for(auto[i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) {
|
||||
if(map_data[i][j] != 1) continue;
|
||||
wall_list[i][j] = new Entity { tile_data.size, tile_data.pos, tile_data.velocity, tile_data.border_size, sf::Color::Black };
|
||||
@@ -59,6 +74,7 @@ int main() {
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
wall_list[i][j]->rect.setPosition({ (j * tile_data.size.x), (i * tile_data.size.y) });
|
||||
}
|
||||
#endif
|
||||
|
||||
Player player {
|
||||
player_data.size, player_data.pos, player_data.velocity,
|
||||
@@ -73,8 +89,7 @@ int main() {
|
||||
|
||||
#ifdef __APPLE__
|
||||
sf::Font font("/Users/andrewhaynes/personal/Projects/CPP/SFML_game_engine/assets/pixel.ttf");
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
#else
|
||||
sf::Font font("/home/andrew/personal/Projects/CPP/SFML_game_engine/assets/pixel.ttf");
|
||||
#endif
|
||||
|
||||
@@ -108,16 +123,30 @@ int main() {
|
||||
player.vertical_no_out_of_bounds(line);
|
||||
|
||||
// Drawing Everything to window
|
||||
#ifdef __APPLE__
|
||||
for(auto[i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
window.draw(wall_list[i][j]->rect);
|
||||
}
|
||||
#else
|
||||
|
||||
for(auto[i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) {
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
window.draw(wall_list[i][j]->rect);
|
||||
}
|
||||
#endif
|
||||
window.draw(player.rect);
|
||||
window.draw(line.rect);
|
||||
window.draw(text);
|
||||
window.display();
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
for(auto[i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
delete wall_list[i][j];
|
||||
}
|
||||
#else
|
||||
for(auto[i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) {
|
||||
delete wall_list[i][j];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user