GithubHelp home page GithubHelp logo

jyanar / boids Goto Github PK

View Code? Open in Web Editor NEW
32.0 32.0 13.0 5.13 MB

An implementation of the Boids program using C++ and the SFML library.

License: MIT License

C++ 97.20% Makefile 2.80%
boids cpp hacktoberfest sfml simulation

boids's People

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

Watchers

 avatar  avatar  avatar  avatar  avatar

boids's Issues

Doesn't build

Unfortunately it doesn't seem to build :(

$ git rev-parse master
81d098d9b51fb0bb383cecad0af2b6ece945f671
$ make
g++ -c -g Boid.cpp
g++ -c -g Flock.cpp
In file included from Flock.cpp:2:
Flock.h:22:11: error: ‘Boid& Flock::getBoid(int)’ cannot be overloaded with ‘Boid Flock::getBoid(int)’
   22 |     Boid &getBoid(int i);
      |           ^~~~~~~
Flock.h:21:10: note: previous declaration ‘Boid Flock::getBoid(int)’
   21 |     Boid getBoid(int i);
      |          ^~~~~~~
Flock.cpp:20:7: error: no declaration matches ‘Boid& Flock::getBoid(int)’
   20 | Boid &Flock::getBoid(int i)
      |       ^~~~~
Flock.cpp:14:6: note: candidate is: ‘Boid Flock::getBoid(int)’
   14 | Boid Flock::getBoid(int i)
      |      ^~~~~
In file included from Flock.cpp:2:
Flock.h:14:7: note: ‘class Flock’ defined here
   14 | class Flock {
      |       ^~~~~
make: *** [makefile:21: Flock.o] Error 1

Performance issue

With increasing number of boids the performance of this program drops significantly. Although FPS is not the perfect way to measure performance, here are some of my observations.

Release mode

Number of boids: 250
Avg FPS: 650
Memory usage: 30 MB
CPU usage: 29.9%

Number of boids: 1000
Avg FPS: 50
Memory usage: 31 MB
CPU usage: 23.7%

Now there are two problems here:

  1. With less number of boids the FPS shoots up too high. We should try to limit FPS to 60 or 30.
  2. CPU usage also seems high, even for 250 boids.

Note: These reading were taken on i5 9th gen + GTX1650 + 8 GB Ram

Boid getBoid(int i) should return a reference not a copy.

Boid getBoid(int i); returns a copy of the boid which makes it impossible change. If this was intended maybe adding a getter for both read only and read/write would be good.

should be:

Boid &getBoid(int i);

with the definition being:

Boid &Flock::getBoid(int i)
{
    return flock[i];
}

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.