Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver committed Jul 28, 2014
1 parent 098e9f5 commit 1ca0a3f
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 123 deletions.
2 changes: 1 addition & 1 deletion src/FieldModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void FieldModel::init(){
delete [] x;
}
MPI_Barrier(MPI_COMM_WORLD);
printf("task %d hat %d Boids\n", tID, (int)swarm.size());
// printf("task %d hat %d Boids\n", tID, (int)swarm.size());
}


Expand Down
6 changes: 3 additions & 3 deletions src/Float2.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "Float2.h"

#include <sstream>
//#include "lib/fixed_point.h"
//#define float fpml::fixed_point<int, 8>
#include "lib/fixed_point.h"
#define float fpml::fixed_point<int, 8>

static Float2* tmp_e = new Float2(0, 0);

Expand Down Expand Up @@ -90,4 +90,4 @@ std::ostream& operator<<(std::ostream& os, Float2 const& obj){
return os << "(" << obj.getX() << ", " << obj.getY() << ")";
}

//#undef float
#undef float
6 changes: 3 additions & 3 deletions src/Float2.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define FLOAT2_H

#include <string>
//#include "lib/fixed_point.h"
//#define float fpml::fixed_point<int, 8>
#include "lib/fixed_point.h"
#define float fpml::fixed_point<int, 8>

class Float2
{
Expand Down Expand Up @@ -43,5 +43,5 @@ const Float2 operator-(Float2 const& lhs, Float2 const& rhs);
//inline const Float2 operator*(Float2 const& lhs, Fgloat2 const& rhs);
const Float2 operator*(Float2 const& lhs, float const& rhs);

//#undef float
#undef float
#endif // FLOAT2_H
178 changes: 89 additions & 89 deletions src/boidview.cpp
Original file line number Diff line number Diff line change
@@ -1,89 +1,89 @@
#include "boidview.h"
#include "SDL/SDL.h"
#include "Float2.h"
#include <stdio.h>
#include <time.h>
#include "test.h"
//#include <mpi/mpi.h>
#include <mpi.h>
#include <vector>
#include <cmath>
#include <assert.h>

extern field myField;
extern int tID;
extern int dimX;
extern int dimY;

BoidView::BoidView(FieldModel* model) : model(model)
{
timer = clock();
}


void BoidView::init(){
// if(tID != 0) return;
SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode(myField.width*3/dimX, myField.height*3/dimY, 32, SDL_SWSURFACE);
// screen = SDL_SetVideoMode(myField.width*3, myField.height*3, 32, SDL_SWSURFACE);

SDL_FillRect(screen, &screen->clip_rect, 0x00ffffff);
SDL_Flip(screen);
}

void BoidView::update(){
// if(tID != 0) return;

double d = ((double)clock()-timer) / ((double)CLOCKS_PER_SEC);
if(d < 30){
SDL_Delay((30 - d));
}
timer = clock();


Uint32 pixel = 0x00000000;
Uint32 *pixels = (Uint32 *)screen->pixels;
SDL_FillRect(screen, &screen->clip_rect, 0x00ffffff);
// printf("hi... %d", model->getSwarmSize());

for ( auto itr = model->swarm.begin(), end = model->swarm.end(); itr != end; itr++ ){
int x = (int)floorf(itr->getPosX());
int y = (int)floorf(itr->getPosY());
if(x < 0 || y < 0) continue;
x -= myField.width/dimX * tID%dimX;
y -= myField.height/dimY * (tID/dimX);
if(x < 0 || y < 0) continue;


//assert(x >= 0); assert(y >= 0);



x *= 3; y *= 3;
for(int _x = 0; _x < 3; _x++){
for(int _y = 0; _y < 3; _y++){
int r = (x+_x)+(y+_y)*screen->w;
if(r >= 0 && r <= screen->w*screen->h)
pixels[r] = pixel;
}
}//*/
}

SDL_Flip(screen);

}

void BoidView::close(bool &quit){
if(tID != 0)
return;

SDL_Event event;
while(SDL_PollEvent(&event)){
if(event.type == SDL_QUIT){
quit = true;
}
}
if(quit){
SDL_Quit();
}
}
//#include "boidview.h"
//#include "SDL/SDL.h"
//#include "Float2.h"
//#include <stdio.h>
//#include <time.h>
//#include "test.h"
////#include <mpi/mpi.h>
//#include <mpi.h>
//#include <vector>
//#include <cmath>
//#include <assert.h>
//
//extern field myField;
//extern int tID;
//extern int dimX;
//extern int dimY;
//
//BoidView::BoidView(FieldModel* model) : model(model)
//{
// timer = clock();
//}
//
//
//void BoidView::init(){
//// if(tID != 0) return;
// SDL_Init(SDL_INIT_EVERYTHING);
// screen = SDL_SetVideoMode(myField.width*3/dimX, myField.height*3/dimY, 32, SDL_SWSURFACE);
//// screen = SDL_SetVideoMode(myField.width*3, myField.height*3, 32, SDL_SWSURFACE);
//
// SDL_FillRect(screen, &screen->clip_rect, 0x00ffffff);
// SDL_Flip(screen);
//}
//
//void BoidView::update(){
//// if(tID != 0) return;
//
// double d = ((double)clock()-timer) / ((double)CLOCKS_PER_SEC);
// if(d < 30){
// SDL_Delay((30 - d));
// }
// timer = clock();
//
//
// Uint32 pixel = 0x00000000;
// Uint32 *pixels = (Uint32 *)screen->pixels;
// SDL_FillRect(screen, &screen->clip_rect, 0x00ffffff);
//// printf("hi... %d", model->getSwarmSize());
//
// for ( auto itr = model->swarm.begin(), end = model->swarm.end(); itr != end; itr++ ){
// int x = (int)floorf(itr->getPosX());
// int y = (int)floorf(itr->getPosY());
// if(x < 0 || y < 0) continue;
// x -= myField.width/dimX * tID%dimX;
// y -= myField.height/dimY * (tID/dimX);
// if(x < 0 || y < 0) continue;
//
//
// //assert(x >= 0); assert(y >= 0);
//
//
//
// x *= 3; y *= 3;
// for(int _x = 0; _x < 3; _x++){
// for(int _y = 0; _y < 3; _y++){
// int r = (x+_x)+(y+_y)*screen->w;
// if(r >= 0 && r <= screen->w*screen->h)
// pixels[r] = pixel;
// }
// }//*/
// }
//
// SDL_Flip(screen);
//
//}
//
//void BoidView::close(bool &quit){
// if(tID != 0)
// return;
//
// SDL_Event event;
// while(SDL_PollEvent(&event)){
// if(event.type == SDL_QUIT){
// quit = true;
// }
// }
// if(quit){
// SDL_Quit();
// }
//}
46 changes: 23 additions & 23 deletions src/boidview.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#ifndef BOIDVIEW_H
#define BOIDVIEW_H

#include "FieldModel.h"
#include "BoidModel.h"
#include "SDL/SDL.h"
#include <time.h>

class BoidView
{
public:
BoidView(FieldModel* model);

void init();
void update();
void close(bool &quit);
private:
FieldModel* model;
SDL_Surface* screen = NULL;
clock_t timer;
};

#endif // BOIDVIEW_H
//#ifndef BOIDVIEW_H
//#define BOIDVIEW_H
//
//#include "FieldModel.h"
//#include "BoidModel.h"
//#include "SDL/SDL.h"
//#include <time.h>
//
//class BoidView
//{
//public:
// BoidView(FieldModel* model);
//
// void init();
// void update();
// void close(bool &quit);
//private:
// FieldModel* model;
// SDL_Surface* screen = NULL;
// clock_t timer;
//};
//
//#endif // BOIDVIEW_H
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "IModel.h"
#include "BoidModel.h"
#include "FieldModel.h"
#include "boidview.h"
//#include "boidview.h"
#include "test.h"

//BoidView* view;
Expand Down Expand Up @@ -99,7 +99,7 @@ int main(int argc, char** argv)
if(i == 1) quit = true;
}
// model->print(); // DEBUG
printf("%d: quit now\n", tID);
if(tID == 0) printf("quit now\n", tID);
// delete model; model = NULL; → throws segmentation fault, but does not matter cause program ends now

MPI_Finalize();
Expand Down
4 changes: 2 additions & 2 deletions src/rulereturnhome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ void RuleReturnHome::followRule(Boid &b, std::vector<Boid> *swarm){
// tmpv.setX(b.getPosX()-(int)b.getPosX());
// tmpv.setY(b.getPosY()-(int)b.getPosY());

tmpv.setX(((int)round(b.getPosX()) + myField.width) %myField.width );
tmpv.setY(((int)round(b.getPosY()) + myField.height)%myField.height );
tmpv.setX(((int)round(b.getPosX()) + myField.width )%myField.width );
tmpv.setY(((int)round(b.getPosY()) + myField.height)%myField.height);

// if(tmpv.getX() < 0) printf("%2.f, %d → %.2f", b.getPosX(), sizeof(b.getPosX()), tmpv.getX());

Expand Down

0 comments on commit 1ca0a3f

Please sign in to comment.