-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
oliver
committed
Jul 28, 2014
1 parent
098e9f5
commit 1ca0a3f
Showing
7 changed files
with
123 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters