Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Czarniecki

Pages: [1]
1
General / Re: Using boost-test with SFML and cmake
« on: February 08, 2022, 05:53:29 pm »
As your code to be tested depends on SFML, you also need to link your test project against SFML, otherwise it won't know what to do with these includes and symbols.
You're right, thank you.

2
General / Using boost-test with SFML and cmake
« on: February 08, 2022, 04:43:59 pm »
I'm writing a simple game in C++ with use of SFML. I want to use boost tests, but when i try to i get undefined reference in every place i use SFML features (the game itself works fine, it's just the test that don't). Sample test:
#include <boost/test/unit_test.hpp>
#include "Sentry.h"

BOOST_AUTO_TEST_SUITE(BasicModelTestSuite)

BOOST_AUTO_TEST_CASE(testLamp_10BulbsWithPower10_ExpectedPower)
    {
        sf::Texture projectileTexture;
        sf::Texture sentryTexture;
        std::vector<std::shared_ptr<Sentry>> foes;
        sentryTexture.loadFromFile("../GameResources/sentry_image.png");
        projectileTexture.loadFromFile("../GameResources/projectile_animation.png");
        foes.push_back(std::make_shared<Sentry>(Sentry(&sentryTexture, sf::Vector2u(1,2), 0.2f, sf::Vector2f(140,200), projectileTexture, true)));
        foes.push_back(std::make_shared<Sentry>(Sentry(&sentryTexture, sf::Vector2u(1,2), 0.2f, sf::Vector2f(200,200), projectileTexture, false)));
        BOOST_REQUIRE_EQUAL(foes.size(), 2);
    }

BOOST_AUTO_TEST_SUITE_END()

And the test portion of cmakelist.txt:
Quote
find_package(Boost 1.65 COMPONENTS "unit_test_framework" REQUIRED)

include_directories(
        ${CMAKE_CURRENT_SOURCE_DIR}/include
        ${Boost_INCLUDE_DIRS}
)

set(SOURCE_TEST_FILES
        test/master.cpp test/master.cpp test/baseTest.cpp
        main.cpp src/Level.cpp include/Level.h src/Game.cpp include/Game.h src/Platform.cpp include/Platform.h src/Item.cpp include/Item.h src/Life.cpp include/Life.h src/Coin.cpp include/Coin.h src/Collider.cpp include/Collider.h src/Enemy.cpp include/Enemy.h src/MrStrawberry.cpp include/MrStrawberry.h src/Animation.cpp include/Animation.h src/MrBerry.cpp include/MrBerry.h src/Projectile.cpp include/Projectile.h src/Sentry.cpp include/Sentry.h)

add_executable(TestProject ${SOURCE_TEST_FILES})

target_include_directories(TestProject PUBLIC include)

target_link_libraries(TestProject
        ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})

enable_testing()

add_test(NAME Test COMMAND TestProject
        --report_level=detailed
        --log_level=all
        --color_output=yes)

add_custom_target(check ${CMAKE_COMMAND} -E env CTEST_OUTPUT_ON_FAILURE=1 BOOST_TEST_LOG_LEVEL=all
        ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> --verbose
        WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

I have no clue why it throws undefined reference to everything, like this:
Quote
/usr/bin/ld: /home/student/CLionProjects/oop21_ww2_14/BerryGame/src/Projectile.cpp:8: undefined reference to `sf::RectangleShape::setSize(sf::Vector2<float> const&)'
/usr/bin/ld: /home/student/CLionProjects/oop21_ww2_14/BerryGame/src/Projectile.cpp:9: undefined reference to `sf::Shape::setTexture(sf::Texture const*, bool)'

3
General / Re: Installing SFML on linux
« on: February 08, 2022, 02:49:24 pm »
The problem was that in one file ("Animation.h") SFML/Graphics.hpp was included with backslash, instead of forward slash (apparently debian doesn't allow that, opposite to windows).

4
General / Re: Installing SFML on linux
« on: February 08, 2022, 01:24:57 pm »
Don't request static libraries.
The Linux eco system is built on shared libraries, thus you'll also only get shared libraries from the package managers

I have my cmakelist like this:
Quote
cmake_minimum_required(VERSION 3.20)
project(BerryGame)

set(CMAKE_CXX_STANDARD 14)

add_executable(BerryGame main.cpp src/Level.cpp include/Level.h src/Game.cpp include/Game.h src/Platform.cpp include/Platform.h src/Item.cpp include/Item.h src/Life.cpp include/Life.h src/Coin.cpp include/Coin.h src/Collider.cpp include/Collider.h src/Enemy.cpp include/Enemy.h src/MrStrawberry.cpp include/MrStrawberry.h src/Animation.cpp include/Animation.h src/MrBerry.cpp include/MrBerry.h src/Projectile.cpp include/Projectile.h src/Sentry.cpp include/Sentry.h)




target_include_directories(BerryGame PUBLIC include)
find_package(SFML 2.4 COMPONENTS graphics window system REQUIRED)


target_link_libraries(BerryGame sfml-system sfml-window sfml-graphics sfml-audio)
And the same fatal error occurs. Funnily enough, when i use this exact cmakelist (with changed executables of course) in this examplary program:
#include <SFML/Graphics.hpp>

int main() {

    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        window.clear();
        window.draw(shape);
        window.display();
    }
    return 0;
}
It works perfectly fine.

5
General / Re: Installing SFML on linux
« on: February 08, 2022, 12:26:45 pm »
Don't request static libraries.
The Linux eco system is built on shared libraries, thus you'll also only get shared libraries from the package managers
What should i do then?
When i set it to:
Quote
set(SFML_STATIC_LIBRARIES FALSE)
i get:
Quote
In file included from /home/student/CLionProjects/oop21_ww2_14/BerryGame/include/Enemy.h:5,
                 from /home/student/CLionProjects/oop21_ww2_14/BerryGame/include/MrStrawberry.h:4,
                 from /home/student/CLionProjects/oop21_ww2_14/BerryGame/main.cpp:2:
/home/student/CLionProjects/oop21_ww2_14/BerryGame/include/Animation.h:4:10: fatal error: SFML\Graphics.hpp: No such file or directory
    4 | #include <SFML\Graphics.hpp>

6
General / Installing SFML on linux
« on: February 08, 2022, 11:54:16 am »
I've been developing my game in SFML on windows, but wanted to move to linux. I installed SFML like so:
Quote
sudo apt-get install libsfml-dev
Quote
But when i want to build my program i get:
CMake Error at /usr/lib/x86_64-linux-gnu/cmake/SFML/SFMLConfig.cmake:139 (message):
  Requested SFML configuration (Static) was not found
Call Stack (most recent call first):
  CMakeLists.txt:11 (find_package)


CMake Error at CMakeLists.txt:11 (find_package):
  Found package configuration file:

    /usr/lib/x86_64-linux-gnu/cmake/SFML/SFMLConfig.cmake

  but it set SFML_FOUND to FALSE so package "SFML" is considered to be NOT
  FOUND.
I am using clion and cmake.

7
General / Enemy patrolling
« on: January 01, 2022, 05:25:24 pm »
I'm currently making a game, and trying to create an enemy class, that is patrolling within a certain range from it's origin. My code:
huh = body.getPosition().x
body.move(-(sf::Vector2f(body.getPosition().x, -velocity.y) - sf::Vector2f(huh,body.getPosition().y))* deltaTime);
 

The code above is moving in one direction, and it does the job just fine, but as the object moves, it continuously slows down, until it stops completely, and i'd rather have it walk all the way with the same speed. Any tips on how to do this?

Pages: [1]
anything