GithubHelp home page GithubHelp logo

johnbuffer / antsimulator Goto Github PK

View Code? Open in Web Editor NEW
2.2K 56.0 280.0 890 KB

Simple Ants simulator

License: MIT License

CMake 0.55% C++ 98.58% Shell 0.19% Dockerfile 0.68%
cpp simulation realtime 2d sfml

antsimulator's Introduction

AntSimulator

Very simple ants simulator.

Installation

Prerequisites

In order to compile this project you will need to:

  • have SFML installed on your system. If you don't know how to do it see this link.
  • have CMake installed

Compilation

Detailed explanation here

On Linux with install.sh

  • Go in the repo folder

cd the/repo/location

  • Execute install.sh script

./install.sh

On Ubuntu from Docker
  • Install Docker (see this)
  • Execute install_from_docker.sh script
docker build -t myimages/ant-simulator:latest .
docker create -it --name dummy myimages/ant-simulator:latest bash
docker cp dummy:/AntSimulator/build/AntSimulator .
rm -rf build/
mkdir build/
mv AntSimulator build/
cp -r res/ build/
docker rm -f dummy

Executable files will be located in the build folder.

On Windows with CMake GUI and Visual Studio

  • Install the right SFML version or compile it (see this)
  • Run CMake
  • Select the repo location

Cmake 1

  • Click on Configure, if you have installed the x64 version of SFML, in the pop up window select x64 in the Optionnal platform for generator drop down

Cmake 2

  • Click on Finish
  • Click on Generate

Cmake 3

  • You can now open the generated project and build it.

Commands

Command Action
P Pause/Unpause the simulation
M Toggle markers drawing
A Toggle ants drawing
S Toggle max speed mode
W Toggle Wall mode
E Toggle Wall erase mode
Right click Add food
Left click Move view
Wheel Zoom

antsimulator's People

Contributors

a1eaiactaest avatar auburus avatar christhrasher avatar crimsoncrow avatar crubier avatar ivanorfanidi avatar johnbuffer avatar maidamai0 avatar michaelgrigoryan25 avatar riscygeek avatar stevenjackerman avatar typicalhog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

antsimulator's Issues

Build Fail

Hello, apologies for not building this on Linux but I currently don't have a proper setup for it. However when building in Windows, and after setting it up in CMake with SFML installed, I cannot build it fully in vs19. It says the "ALL_BUILD" folder does not exist and when trying to just run the application it crashes immediately. After debugging it, I come up with the error code 0xc0000005 which is an access violation even when ran as admin. I cant tell if it just isn't building the full game or if the directory might be messed up. If it were the former I would assume its known already but I just wanted to play around with some ants.

Game Crash When 3 Colonies

I have 2 ant colonies and i add one but the game stops for a second and then the game crashes, I don't know what just happen it just crashes.

square textures

Base Profile Screenshot 2021 05 26 - 15 29 53 50
how can i properly see the ants textures instead of squares?

How to place stuff

When I try to place something such as a wall, it only moves the black space. If I click and drag, it moves the black space, and if I only click, nothing happens. Running on Windows (ASUS laptop) and using the touchpad.

Speed up time?

Is there a way to speed up the simulation? Nothing happens when I press the "Full Speed" button in the Time control box.

keeps saying "file not found"

every time I try to run it it says "VCRUNTIME140_1.dll not found" and the program wont run. I've tried reinstalling it and it still happens.

Scaling for the editor GUI?

I have a MacBook Air 13.3" (2560 x 1600 @ 227ppi) and it is kinda unusable:

Screenshot 2021-12-11 at 08 38 08

How can I change the scaling (within the code if there's currently no other solution)?

Install instructions for not experienced people

Hello,

i just saw you're video on youtube and wanted to make my son play with you're animation.

Do you think it is hard if i ask you to make a more detailed instructions file ?

Or maybe a guide on how to put it online so i can share to others you're work.

Thank you.

Set up instructions do not work/incomplete for windows

Sorry, I'm not a c++ person!

Anyway, the instructions for setting up SFML do not work for this project. If I git clone this project into a folder and open that folder in Visual Studio 2019, there is no project settings option in the project menu. The SFML set up instructions rely upon changing these settings. There is a cmake setting menu option but the install instructions in this project do not explain how to apply SFML to this project.

Without this set up, trying to run a build gives this:

image

I have located SFMLConfig.cmake and set SFML_DIR to hold that file's parent directory. However the same error continues to occur.

image

image

Also, the SFML_DIR variable keeps reseting. Am I not saving it properly? I'm using ctrl-s. But say I click on'edit JSON' and then come back then SFML-DIR reverts to SFML_DIR-NOTFOUND

I have also redone the cmake instructions in the readme and added SFML-DIR directly there. It's kind of strange that the isntructions show an error.

Also, what does the last step mean:

"You can now open the generated project and build it."

There is no play button, and f5 does not do anything.

CMake fail for Linux related to SFML

Hello, I am getting the error
`By not providing "FindSFML.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SFML", but
CMake did not find one.

Could not find a package configuration file provided by "SFML" (requested
version 2) with any of the following names:

SFMLConfig.cmake
sfml-config.cmake

Add the installation prefix of "SFML" to CMAKE_PREFIX_PATH or set
"SFML_DIR" to a directory containing one of the above files. If "SFML"
provides a separate development package or SDK, be sure it has been
installed.`
How would I fix this?

(feature/improvement) building for gpu.

Hey! very cool simulation, have you considered building this as a shader for execution on a gpu? It would likely allow you to have millions of ants in a single simulation this way and could allow for more complex behaviors without slowing down the simulation!

Adding multi-threading?

Hey I'm kinda new to c++ stuff and I've been trying to use multi-threading, because I just have watched a video about it :)..

I want to ask you, why this approach doesn't work?
it seems to have no effect on the CPU usage.

this is the original code for one of the most time-consuming tasks:

for (Colony& colony : colonies)
{
    colony.update(dt, world);
}

and this is what I done:

for_each(std::execution::par,colonies.begin(), colonies.end(),
        [&dt, this](Colony& colony){
             colony.update(dt, world);
         });

May I have your opinion?

Compiling with docker fails (ubuntu 23.10)

when running the install_from_docker.sh file (using sudo) I get this output and the build fails.
note: i had to use patebin because github screws with the formatting
https://pastebin.com/REEd4yMC

system info:
OS: Ubuntu 23.10 x86_64
Kernel: 6.5.0-27-generic
cmake version 3.27.4
Docker version 24.0.5, build ced0996

Crash in grid.hpp - vector subscript is out of range

Running latest release, conf.txt file attached, using release map.png

conf.txt

AntSimulator Crash call stack

Cells vector subscript is out of range in this function:

const T& getCst(sf::Vector2i cell_coord) const
{
	return cells[getIndexFromCoords(cell_coord)];
}

cell_coord.x = 207, cell_coord.y = 270, cells.size = 129600

In the called function, width = 480:

uint64_t getIndexFromCoords(const sf::Vector2i& cell_coords) const
{
	return cell_coords.x + cell_coords.y * width;
}

So this returns 207 + (270 * 480) = 129807 which is out of range.

Build failed on latest master

I executed ./install.sh to build the project and got a long compilation error.

Stack trace:

-- Configuring done
-- Generating done
-- Build files have been written to: /home/kv/AntSimulator/build
[ 25%] Building CXX object CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o
In file included from /home/kv/AntSimulator/include/world_grid.hpp:6:0,
                 from /home/kv/AntSimulator/include/world.hpp:6,
                 from /home/kv/AntSimulator/include/display_manager.hpp:4,
                 from /home/kv/AntSimulator/src/display_manager.cpp:1:
/home/kv/AntSimulator/include/grid.hpp: In constructor ‘GridOfNumber<T>::GridOfNumber(int32_t, int32_t, uint32_t)’:
/home/kv/AntSimulator/include/grid.hpp:81:5: error: class ‘GridOfNumber<T>’ does not have any field named ‘Grid’
   : Grid(width_, height_, cell_size_)
     ^~~~
/home/kv/AntSimulator/include/grid.hpp: In constructor ‘GridOfList<T>::GridOfList(int32_t, int32_t, uint32_t)’:
/home/kv/AntSimulator/include/grid.hpp:112:5: error: class ‘GridOfList<T>’ does not have any field named ‘Grid’
   : Grid(width_, height_, cell_size_)
     ^~~~
/home/kv/AntSimulator/include/grid.hpp: In member function ‘T* GridOfList<T>::emplaceAtPosition(sf::Vector2i)’:
/home/kv/AntSimulator/include/grid.hpp:118:7: error: there are no arguments to ‘checkCell’ that depend on a template parameter, so a declaration of ‘checkCell’ must be available [-fpermissive]
   if (checkCell(pos)) {
       ^~~~~~~~~
/home/kv/AntSimulator/include/grid.hpp:118:7: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
/home/kv/AntSimulator/include/grid.hpp:119:25: error: there are no arguments to ‘get’ that depend on a template parameter, so a declaration of ‘get’ must be available [-fpermissive]
    GridListCell<T>& c = get(pos);
                         ^~~
/home/kv/AntSimulator/include/grid.hpp: In member function ‘T* GridOfList<T>::emplaceAtPosition(sf::Vector2f)’:
/home/kv/AntSimulator/include/grid.hpp:128:28: error: there are no arguments to ‘getCellCoords’ that depend on a template parameter, so a declaration of ‘getCellCoords’ must be available [-fpermissive]
   return emplaceAtPosition(getCellCoords(pos));
                            ^~~~~~~~~~~~~
/home/kv/AntSimulator/include/grid.hpp: In member function ‘void GridOfList<T>::clearAt(sf::Vector2f)’:
/home/kv/AntSimulator/include/grid.hpp:138:22: error: there are no arguments to ‘getCellCoords’ that depend on a template parameter, so a declaration of ‘getCellCoords’ must be available [-fpermissive]
   auto cell_coords = getCellCoords(position);
                      ^~~~~~~~~~~~~
/home/kv/AntSimulator/include/grid.hpp:139:3: error: ‘cells’ was not declared in this scope
   cells[getIndexFromCoords(cell_coords)].data.clear();
   ^~~~~
/home/kv/AntSimulator/include/grid.hpp:139:3: note: suggested alternative: ‘ceill’
   cells[getIndexFromCoords(cell_coords)].data.clear();
   ^~~~~
   ceill
/home/kv/AntSimulator/include/grid.hpp: In member function ‘T* GridOfList<T>::add(const Vector2i&, const T&)’:
/home/kv/AntSimulator/include/grid.hpp:144:7: error: there are no arguments to ‘checkCell’ that depend on a template parameter, so a declaration of ‘checkCell’ must be available [-fpermissive]
   if (checkCell(cell_coords)) {
       ^~~~~~~~~
/home/kv/AntSimulator/include/grid.hpp:145:28: error: ‘cells’ was not declared in this scope
    GridListCell<T>& cell = cells[getIndexFromCoords(cell_coords)];
                            ^~~~~
/home/kv/AntSimulator/include/grid.hpp:145:28: note: suggested alternative: ‘cell’
    GridListCell<T>& cell = cells[getIndexFromCoords(cell_coords)];
                            ^~~~~
                            cell
/home/kv/AntSimulator/include/grid.hpp:145:34: error: there are no arguments to ‘getIndexFromCoords’ that depend on a template parameter, so a declaration of ‘getIndexFromCoords’ must be available [-fpermissive]
    GridListCell<T>& cell = cells[getIndexFromCoords(cell_coords)];
                                  ^~~~~~~~~~~~~~~~~~
/home/kv/AntSimulator/include/grid.hpp: In member function ‘std::__cxx11::list<T*> GridOfList<T>::getAllAt(const Vector2f&)’:
/home/kv/AntSimulator/include/grid.hpp:155:36: error: there are no arguments to ‘getCellCoords’ that depend on a template parameter, so a declaration of ‘getCellCoords’ must be available [-fpermissive]
   const sf::Vector2i cell_coords = getCellCoords(position);
                                    ^~~~~~~~~~~~~
/home/kv/AntSimulator/include/grid.hpp:160:9: error: there are no arguments to ‘checkCell’ that depend on a template parameter, so a declaration of ‘checkCell’ must be available [-fpermissive]
     if (checkCell(coords)) {
         ^~~~~~~~~
/home/kv/AntSimulator/include/grid.hpp:161:27: error: there are no arguments to ‘get’ that depend on a template parameter, so a declaration of ‘get’ must be available [-fpermissive]
      GridListCell<T>& c = get(coords);
                           ^~~
/home/kv/AntSimulator/include/grid.hpp: In member function ‘GridListCell<T>* GridOfList<T>::getAt(const Vector2f&)’:
/home/kv/AntSimulator/include/grid.hpp:174:36: error: there are no arguments to ‘getCellCoords’ that depend on a template parameter, so a declaration of ‘getCellCoords’ must be available [-fpermissive]
   const sf::Vector2i cell_coords = getCellCoords(position);
                                    ^~~~~~~~~~~~~
/home/kv/AntSimulator/include/grid.hpp:176:7: error: there are no arguments to ‘checkCell’ that depend on a template parameter, so a declaration of ‘checkCell’ must be available [-fpermissive]
   if (checkCell(cell_coords)) {
       ^~~~~~~~~
/home/kv/AntSimulator/include/grid.hpp:177:12: error: ‘cells’ was not declared in this scope
    return &cells[getIndexFromCoords(cell_coords)];
            ^~~~~
/home/kv/AntSimulator/include/grid.hpp:177:12: note: suggested alternative: ‘ceillreturn &cells[getIndexFromCoords(cell_coords)];
            ^~~~~
            ceill
/home/kv/AntSimulator/include/grid.hpp:177:18: error: there are no arguments to ‘getIndexFromCoords’ that depend on a template parameter, so a declaration of ‘getIndexFromCoords’ must be available [-fpermissive]
    return &cells[getIndexFromCoords(cell_coords)];
                  ^~~~~~~~~~~~~~~~~~
/home/kv/AntSimulator/include/grid.hpp: In member function ‘bool GridOfList<T>::isEmpty(const Vector2f&) const’:
/home/kv/AntSimulator/include/grid.hpp:185:36: error: there are no arguments to ‘getCellCoords’ that depend on a template parameter, so a declaration of ‘getCellCoords’ must be available [-fpermissive]
   const sf::Vector2i cell_coords = getCellCoords(position);
                                    ^~~~~~~~~~~~~
/home/kv/AntSimulator/include/grid.hpp:187:7: error: there are no arguments to ‘checkCell’ that depend on a template parameter, so a declaration of ‘checkCell’ must be available [-fpermissive]
   if (checkCell(cell_coords)) {
       ^~~~~~~~~
/home/kv/AntSimulator/include/grid.hpp:188:11: error: there are no arguments to ‘getCst’ that depend on a template parameter, so a declaration of ‘getCst’ must be available [-fpermissive]
    return getCst(cell_coords).data.empty();
           ^~~~~~
CMakeFiles/AntSimulator.dir/build.make:62: recipe for target 'CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o' failed
make[2]: *** [CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/AntSimulator.dir/all' failed
make[1]: *** [CMakeFiles/AntSimulator.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Can't figure out controls on latest 3.1

I had played this on early versions where there was like an explosion from the center and ants scattered, was around march or april so whatever that version was current at the time. And I was able to play with the controls on readme, put food, place walls, etc.

Version 3.1, simulation plays red vs blue, but I am not able to interact at all other than pause, is this a bug or is the game now entirely automated?

Include vcpkg manifest file and readme

I've included the following file to the repo:

vcpkg.json

{
    "name": "antsimulator",
    "version": "1.0",
    "dependencies": [
        "sfml"
    ]
}

If the toolchain file is set for CMake (e.g. in VSCode) there is no need to install sfml independently. If the toolchain file is not set, then the manifest file is ignored.

I've tested this and worked. I would like to create a pull request for this, but don't see how to include in the readme file. Does anyone have an idea?

[Feature Request] Simulating the 'danger' and 'death' pheromones.

As the title states, I want to propose the simulation of the following:

  • Danger pheromone.
  • Death pheromone.

Danger: When ants sense a threat, they emit the so called 'danger' pheromone which let its colony know that there is a danger present; Could be an intruder, flood or similar.

Death: When ants die (Or sense that they are dying), they leave a pheromone that signals the colony one or more of its colony is dying/has died and may cause fellow ants to investigate and 'bury the fallen'.

Crashing ("Debug assertion failed! Expression: vector subscript out of range") when removing colony with population of 0.

Edit: Confirmed when using the callback that you wrote for removing a colony (hitting "remove" in GUI), it will sometimes crash if trying to remove a colony with a population of 0.

In the update() function in Simulation, I have a check to see if any colonies have a population of 0 ants. If there are 0 ants, removeColony() is called and the colony is removed from the world, as well as being removed under the hood, from the colonies vectors in Simulation, world, and renderer.

Strangely, it also only appears to happen when using colonies with somewhat large starting populations (>50?). If you try testing with small colony sizes, it may not occur. Additionally, I believe I have only one instance of crashing when using the actual "remove" button in the GUI (compared to crashes happening every single time otherwise).

It seems like it is either a problem with the index_vector.hpp class, or maybe the target field in Ant ...? I have been investigating this problem all day with no luck. I'll make a comment below that goes into greater detail.

Placing food and blocks

Hey! Is it possible to put food and walls in blocks at once (like some templates), instead of 1 point? Maybe it can be done programmatically?

Fails to load assets

Any thing in res folder fails to load. Here is the terminal:

Configuration file couldn't be found.
Failed to load image "res/ant.png". Reason: Unable to open file
Failed to load image "res/marker.png". Reason: Unable to open file
Failed to load font "res/font.ttf" (failed to create the font face)

Display number of Soldier Ants

I was interested in knowing the number of soldiers in the ant population. So I played with the following changes:

Added the following to the bottom of colony.hpp:

uint32_t soldiersCount()
{
	return std::count_if(ants.begin(), ants.end(), [](Ant& a) { return a.type == Ant::Type::Soldier; });
}

Changes to colony_renderer.hpp:

Added a soldiersCount variable:

uint32_t ants_count = 0;
uint32_t soldiers_count = 0;

Changed updateData( ) to retrieve the soldiersCount:

	ants_count = to<int32_t>(colony.ants.size());
	soldiers_count = to<int32_t>(colony.soldiersCount());

And then changed the render( ) to show the soldiersCount and right-justify the pop_diff:

	text.setCharacterSize(20);
	text.setFillColor(sf::Color::White);
	text.setPosition(position.x + padding, position.y);
	text.setString("Population " + toStr(soldiers_count) + "/" + toStr(ants_count));
	target.draw(text);

	text.setCharacterSize(14);
	text.setFillColor(pop_diff >= 0 ? sf::Color::Green : sf::Color::Red);
	const std::string sign = (pop_diff >= 0 ? "+" : "");
	text.setString("(" + sign + toStr(pop_diff) + " Ants over last 60s)");
	// right justify
	sf::FloatRect bounds = text.getLocalBounds();
	text.setPosition((position.x + population.width + padding) - bounds.width, position.y + 0.5f * padding);

	target.draw(text);

Kudos for writing this simulation - everybody who has seen it work has been fascinated.

Commands

the commands dont work or im doing something wrong or what?

Can't run executable

I'm in a Ubuntu Windows Subsystem for Linux environment, I've installed the latest SFML and CMake libraries, and I ran ./install.sh...

When I went into the build folder to run AntSimulator I got the following error output

Configuration file couldn't be found.
Failed to open X11 display; make sure the DISPLAY environment variable is set correctly
Aborted

I'm familiar with C++ projects in a windows environment with visual studio, but I feel I may be a bit out of my depth on getting this project running.

Can't configure

I was trying to configure it and when i looked into the crashreport it sas that 2 files can't be coppied and those files doesn't exist i tried re downloading pls help

Erasing the outer walls crashes the simulator

Pretty much what the title says :)

Idk why i had so much fun dropping some food and building some obstacles and seeing these little virtual ants building an ameisenstraße (looks to me like there is no term for this phenomenon in english).
Nice work 👍

Program crashes when maximum ants per colony is set under 1000

Setting the max. ants per colony to under 1000, the default minimum number of ants, in the conf.txt file, as soon as you try to place a colony, the program crashes. Allowing us to change the minimum number of ants as well as the maximum would both fix this issue as well as allow for more flexibility with scenarios.

issues building on Linux

Hi,

I'm having a few issues building on Linux.

[1/4] Building CXX object CMakeFiles/AntSimulator.dir/src/utils.cpp.o
FAILED: CMakeFiles/AntSimulator.dir/src/utils.cpp.o 
/usr/bin/c++  -I../include -I../lib  -MD -MT CMakeFiles/AntSimulator.dir/src/utils.cpp.o -MF CMakeFiles/AntSimulator.dir/src/utils.cpp.o.d -o CMakeFiles/AntSimulator.dir/src/utils.cpp.o -c ../src/utils.cpp
In file included from ../src/utils.cpp:1:
../include/utils.hpp: In instantiation of ‘float getLength(const sf::Vector2<T>&) [with T = float]’:
../src/utils.cpp:22:40:   required from here
../include/utils.hpp:17:13: error: ‘sqrt’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
   17 |  return sqrt(v.x * v.x + v.y * v.y);
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/features.h:473,
                 from /usr/include/c++/10.2.0/x86_64-pc-linux-gnu/bits/os_defines.h:39,
                 from /usr/include/c++/10.2.0/x86_64-pc-linux-gnu/bits/c++config.h:518,
                 from /usr/include/c++/10.2.0/iosfwd:38,
                 from /usr/include/c++/10.2.0/ios:38,
                 from /usr/include/c++/10.2.0/ostream:38,
                 from /usr/include/SFML/System/Err.hpp:32,
                 from /usr/include/SFML/System.hpp:34,
                 from /usr/include/SFML/Window.hpp:32,
                 from /usr/include/SFML/Graphics.hpp:32,
                 from ../include/utils.hpp:2,
                 from ../src/utils.cpp:1:
/usr/include/bits/mathcalls.h:143:1: note: ‘double sqrt(double)’ declared here, later in the translation unit
  143 | __MATHCALL (sqrt,, (_Mdouble_ __x));
      | ^~~~~~~~~~
[2/4] Building CXX object CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o
FAILED: CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o 
/usr/bin/c++  -I../include -I../lib  -MD -MT CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o -MF CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o.d -o CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o -c ../src/display_manager.cpp
In file included from ../include/marker.hpp:2,
                 from ../include/world.hpp:6,
                 from ../include/display_manager.hpp:4,
                 from ../src/display_manager.cpp:1:
../include/config.hpp:44:17: error: specializing member ‘Conf<>::FOOD_COLOR’ requires ‘template<>’ syntax
   44 | const sf::Color Conf<>::FOOD_COLOR = sf::Color(29, 129, 18);
      |                 ^~~~~~
../include/config.hpp:45:17: error: specializing member ‘Conf<>::TO_FOOD_COLOR’ requires ‘template<>’ syntax
   45 | const sf::Color Conf<>::TO_FOOD_COLOR = sf::Color(119, 211, 109);
      |                 ^~~~~~
../include/config.hpp:46:17: error: specializing member ‘Conf<>::TO_HOME_COLOR’ requires ‘template<>’ syntax
   46 | const sf::Color Conf<>::TO_HOME_COLOR = sf::Color(122, 105, 199);
      |                 ^~~~~~
../include/config.hpp:47:17: error: specializing member ‘Conf<>::COLONY_COLOR’ requires ‘template<>’ syntax
   47 | const sf::Color Conf<>::COLONY_COLOR = sf::Color(67, 46, 163);
      |                 ^~~~~~
../include/config.hpp:49:30: error: specializing member ‘Conf<>::ANT_TEXTURE’ requires ‘template<>’ syntax
   49 | std::shared_ptr<sf::Texture> Conf<>::ANT_TEXTURE;
      |                              ^~~~~~
../include/config.hpp:50:30: error: specializing member ‘Conf<>::MARKER_TEXTURE’ requires ‘template<>’ syntax
   50 | std::shared_ptr<sf::Texture> Conf<>::MARKER_TEXTURE;
      |                              ^~~~~~
In file included from ../include/ant.hpp:9,
                 from ../include/colony.hpp:5,
                 from ../include/display_manager.hpp:5,
                 from ../src/display_manager.cpp:1:
../include/direction.hpp: In member function ‘void Direction::updateVec()’:
../include/direction.hpp:62:13: error: ‘cos’ was not declared in this scope
   62 |   m_vec.x = cos(m_angle);
      |             ^~~
../include/direction.hpp:63:13: error: ‘sin’ was not declared in this scope; did you mean ‘sign’?
   63 |   m_vec.y = sin(m_angle);
      |             ^~~
      |             sign
../include/direction.hpp: In member function ‘void Direction::updateTargetVec()’:
../include/direction.hpp:68:20: error: ‘cos’ was not declared in this scope
   68 |   m_target_vec.x = cos(m_target_angle);
      |                    ^~~
../include/direction.hpp:69:20: error: ‘sin’ was not declared in this scope; did you mean ‘sign’?
   69 |   m_target_vec.y = sin(m_target_angle);
      |                    ^~~
      |                    sign
In file included from ../include/world.hpp:8,
                 from ../include/display_manager.hpp:4,
                 from ../src/display_manager.cpp:1:
../include/utils.hpp: In instantiation of ‘float getLength(const sf::Vector2<T>&) [with T = float]’:
../include/ant.hpp:65:41:   required from here
../include/utils.hpp:17:13: error: ‘sqrt’ was not declared in this scope
   17 |  return sqrt(v.x * v.x + v.y * v.y);
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~
[3/4] Building CXX object CMakeFiles/AntSimulator.dir/src/main.cpp.o
FAILED: CMakeFiles/AntSimulator.dir/src/main.cpp.o 
/usr/bin/c++  -I../include -I../lib  -MD -MT CMakeFiles/AntSimulator.dir/src/main.cpp.o -MF CMakeFiles/AntSimulator.dir/src/main.cpp.o.d -o CMakeFiles/AntSimulator.dir/src/main.cpp.o -c ../src/main.cpp
In file included from ../include/marker.hpp:2,
                 from ../include/ant.hpp:4,
                 from ../include/colony.hpp:5,
                 from ../src/main.cpp:4:
../include/config.hpp:44:17: error: specializing member ‘Conf<>::FOOD_COLOR’ requires ‘template<>’ syntax
   44 | const sf::Color Conf<>::FOOD_COLOR = sf::Color(29, 129, 18);
      |                 ^~~~~~
../include/config.hpp:45:17: error: specializing member ‘Conf<>::TO_FOOD_COLOR’ requires ‘template<>’ syntax
   45 | const sf::Color Conf<>::TO_FOOD_COLOR = sf::Color(119, 211, 109);
      |                 ^~~~~~
../include/config.hpp:46:17: error: specializing member ‘Conf<>::TO_HOME_COLOR’ requires ‘template<>’ syntax
   46 | const sf::Color Conf<>::TO_HOME_COLOR = sf::Color(122, 105, 199);
      |                 ^~~~~~
../include/config.hpp:47:17: error: specializing member ‘Conf<>::COLONY_COLOR’ requires ‘template<>’ syntax
   47 | const sf::Color Conf<>::COLONY_COLOR = sf::Color(67, 46, 163);
      |                 ^~~~~~
../include/config.hpp:49:30: error: specializing member ‘Conf<>::ANT_TEXTURE’ requires ‘template<>’ syntax
   49 | std::shared_ptr<sf::Texture> Conf<>::ANT_TEXTURE;
      |                              ^~~~~~
../include/config.hpp:50:30: error: specializing member ‘Conf<>::MARKER_TEXTURE’ requires ‘template<>’ syntax
   50 | std::shared_ptr<sf::Texture> Conf<>::MARKER_TEXTURE;
      |                              ^~~~~~
In file included from ../include/ant.hpp:9,
                 from ../include/colony.hpp:5,
                 from ../src/main.cpp:4:
../include/direction.hpp: In member function ‘void Direction::updateVec()’:
../include/direction.hpp:62:13: error: ‘cos’ was not declared in this scope
   62 |   m_vec.x = cos(m_angle);
      |             ^~~
../include/direction.hpp:63:13: error: ‘sin’ was not declared in this scope; did you mean ‘sign’?
   63 |   m_vec.y = sin(m_angle);
      |             ^~~
      |             sign
../include/direction.hpp: In member function ‘void Direction::updateTargetVec()’:
../include/direction.hpp:68:20: error: ‘cos’ was not declared in this scope
   68 |   m_target_vec.x = cos(m_target_angle);
      |                    ^~~
../include/direction.hpp:69:20: error: ‘sin’ was not declared in this scope; did you mean ‘sign’?
   69 |   m_target_vec.y = sin(m_target_angle);
      |                    ^~~
      |                    sign
In file included from ../include/world.hpp:8,
                 from ../include/ant.hpp:6,
                 from ../include/colony.hpp:5,
                 from ../src/main.cpp:4:
../include/utils.hpp: In instantiation of ‘float getLength(const sf::Vector2<T>&) [with T = float]’:
../include/ant.hpp:65:41:   required from here
../include/utils.hpp:17:13: error: ‘sqrt’ was not declared in this scope
   17 |  return sqrt(v.x * v.x + v.y * v.y);
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~

Missing include <cmath> was added to include/utils.hpp which fixed the sqrt/cos/sin errors. I've also added the missing template<> syntax to include/config.hpp but now I get a linker error:

[3/3] Linking CXX executable AntSimulator
FAILED: AntSimulator 
: && /usr/bin/c++   CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o CMakeFiles/AntSimulator.dir/src/main.cpp.o CMakeFiles/AntSimulator.dir/src/utils.cpp.o -o AntSimulator  /usr/lib/libsfml-graphics.so.2.5.1  -lpthread  /usr/lib/libsfml-window.so.2.5.1  /usr/lib/libsfml-system.so.2.5.1 && :
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/main.cpp.o:(.bss+0x0): multiple definition of `Conf<int>::ANT_COLOR'; CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o:(.bss+0x0): first defined here
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/main.cpp.o:(.bss+0x4): multiple definition of `Conf<int>::FOOD_COLOR'; CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o:(.bss+0x4): first defined here
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/main.cpp.o:(.bss+0x8): multiple definition of `Conf<int>::TO_FOOD_COLOR'; CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o:(.bss+0x8): first defined here
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/main.cpp.o:(.bss+0xc): multiple definition of `Conf<int>::TO_HOME_COLOR'; CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o:(.bss+0xc): first defined here
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/main.cpp.o:(.bss+0x10): multiple definition of `Conf<int>::COLONY_COLOR'; CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o:(.bss+0x10): first defined here
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/main.cpp.o: warning: relocation against `_ZN4ConfIiE11ANT_TEXTUREE' in read-only section `.text._ZN4ConfIiE12freeTexturesEv[_ZN4ConfIiE12freeTexturesEv]'
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o: in function `World::render(sf::RenderTarget&, sf::RenderStates const&, bool) const':
display_manager.cpp:(.text._ZNK5World6renderERN2sf12RenderTargetERKNS0_12RenderStatesEb[_ZNK5World6renderERN2sf12RenderTargetERKNS0_12RenderStatesEb]+0xfb): undefined reference to `Conf<int>::MARKER_TEXTURE'
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o: in function `Colony::render(sf::RenderTarget&, sf::RenderStates const&) const':
display_manager.cpp:(.text._ZNK6Colony6renderERN2sf12RenderTargetERKNS0_12RenderStatesE[_ZNK6Colony6renderERN2sf12RenderTargetERKNS0_12RenderStatesE]+0x229): undefined reference to `Conf<int>::ANT_TEXTURE'
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/main.cpp.o: in function `Conf<int>::loadTextures()':
main.cpp:(.text._ZN4ConfIiE12loadTexturesEv[_ZN4ConfIiE12loadTexturesEv]+0x2e): undefined reference to `Conf<int>::ANT_TEXTURE'
/usr/bin/ld: main.cpp:(.text._ZN4ConfIiE12loadTexturesEv[_ZN4ConfIiE12loadTexturesEv]+0x46): undefined reference to `Conf<int>::ANT_TEXTURE'
/usr/bin/ld: main.cpp:(.text._ZN4ConfIiE12loadTexturesEv[_ZN4ConfIiE12loadTexturesEv]+0xaf): undefined reference to `Conf<int>::ANT_TEXTURE'
/usr/bin/ld: main.cpp:(.text._ZN4ConfIiE12loadTexturesEv[_ZN4ConfIiE12loadTexturesEv]+0xdb): undefined reference to `Conf<int>::MARKER_TEXTURE'
/usr/bin/ld: main.cpp:(.text._ZN4ConfIiE12loadTexturesEv[_ZN4ConfIiE12loadTexturesEv]+0xf3): undefined reference to `Conf<int>::MARKER_TEXTURE'
/usr/bin/ld: main.cpp:(.text._ZN4ConfIiE12loadTexturesEv[_ZN4ConfIiE12loadTexturesEv]+0x15c): undefined reference to `Conf<int>::MARKER_TEXTURE'
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/main.cpp.o: in function `Conf<int>::freeTextures()':
main.cpp:(.text._ZN4ConfIiE12freeTexturesEv[_ZN4ConfIiE12freeTexturesEv]+0x32): undefined reference to `Conf<int>::ANT_TEXTURE'
/usr/bin/ld: main.cpp:(.text._ZN4ConfIiE12freeTexturesEv[_ZN4ConfIiE12freeTexturesEv]+0x62): undefined reference to `Conf<int>::MARKER_TEXTURE'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Any ideas?

CMake fail

Did follow the instructions (they're fairly simple) but CMake doesn't seem to recognize the files.

image

What the terminal says:
"Configuring incomplete, errors occurred!
See also "C:/Games/AntSimulator-master/build/CMakeFiles/CMakeOutput.log"."

What CMakeOutput.log says:
"The system is: Windows - 10.0.19042 - AMD64"

I can't even begin to guess what's happening. Not very familiar with this program.

Can't compile on Arch Linux

I have:

  1. Cloned the repo
  2. Installed sfml with pacman -S sfml (cmake was already there)
  3. Ran ./install.sh in the repo folder

And got the following:

[victor@vicm AntSimulator]$ ./install.sh 
-- The CXX compiler identification is GNU 11.1.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found SFML 2.5.1 in /usr/lib64/cmake/SFML
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/victor/Desktop/AntSimulator/build
[ 25%] Building CXX object CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o
In file included from /home/victor/Desktop/AntSimulator/include/world_renderer.hpp:4,
                 from /home/victor/Desktop/AntSimulator/include/world.hpp:11,
                 from /home/victor/Desktop/AntSimulator/include/display_manager.hpp:4,
                 from /home/victor/Desktop/AntSimulator/src/display_manager.cpp:1:
/home/victor/Desktop/AntSimulator/include/config.hpp:71:69: error: 'Conf' was not declared in this scope
   71 | sf::Vector2f DefaultConf<T>::COLONY_POSITION = sf::Vector2f(500.0f, Conf::WIN_HEIGHT * 0.5f);
      |                                                                     ^~~~
In file included from /home/victor/Desktop/AntSimulator/include/colony_base.hpp:3,
                 from /home/victor/Desktop/AntSimulator/include/ant.hpp:10,
                 from /home/victor/Desktop/AntSimulator/include/colony.hpp:5,
                 from /home/victor/Desktop/AntSimulator/include/display_manager.hpp:5,
                 from /home/victor/Desktop/AntSimulator/src/display_manager.cpp:1:
/home/victor/Desktop/AntSimulator/include/racc.hpp: In member function 'T RDiff<T>::get() const':
/home/victor/Desktop/AntSimulator/include/racc.hpp:90:16: error: 'values' was not declared in this scope
   90 |         return values[getIndex(-1)] - values[getIndex()];
      |                ^~~~~~
/home/victor/Desktop/AntSimulator/include/racc.hpp:90:23: error: there are no arguments to 'getIndex' that depend on a template parameter, so a declaration of 'getIndex' must be available [-fpermissive]
   90 |         return values[getIndex(-1)] - values[getIndex()];
      |                       ^~~~~~~~
/home/victor/Desktop/AntSimulator/include/racc.hpp:90:23: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
/home/victor/Desktop/AntSimulator/include/racc.hpp:90:46: error: there are no arguments to 'getIndex' that depend on a template parameter, so a declaration of 'getIndex' must be available [-fpermissive]
   90 |         return values[getIndex(-1)] - values[getIndex()];
      |                                              ^~~~~~~~
make[2]: *** [CMakeFiles/AntSimulator.dir/build.make:76: CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/AntSimulator.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Am I missing something? Last commit the branch master has at time of cloning: 245f8c4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.