Skip to content

Commit 19ff846

Browse files
committed
Draw walls and created wall class
1 parent aff0c7c commit 19ff846

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed

include/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
add_library(include Actor.cpp)
1+
add_library(include Actor.cpp Room.cpp)

include/Room.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "Room.hpp"
2+
#include <iostream>
3+
#include <vector>
4+
#include <array>
5+
6+
Room::Room(std::vector<std::array<float, 4>> pWalls, std::vector<std::array<float, 2>> pDestinations) {
7+
walls = pWalls;
8+
destinations = pDestinations;
9+
}
10+
11+
std::vector<std::array<float, 4>> Room::getWalls() {
12+
return walls;
13+
}
14+
15+
std::vector<std::array<float, 2>> Room::getDestinations() {
16+
return destinations;
17+
}

include/Room.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef Room_hpp
2+
#define Room_hpp
3+
4+
#include<iostream>
5+
#include <vector>
6+
#include <array>
7+
8+
class Room {
9+
private:
10+
std::vector<std::array<float, 4>> walls;
11+
std::vector<std::array<float, 2>> destinations;
12+
public:
13+
Room(std::vector<std::array<float, 4>> pWalls, std::vector<std::array<float, 2>> pDestinations);
14+
15+
std::vector<std::array<float, 4>> getWalls();
16+
std::vector<std::array<float, 2>> getDestinations();
17+
};
18+
19+
#endif

src/main.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#include <CL/sycl.hpp>
22
#include <SDL2/SDL.h>
3-
#include "Actor.hpp"
43
#include <iostream>
54

5+
#include "Actor.hpp"
6+
#include "Room.hpp"
7+
68
const int WIDTH = 8; // metres
79
const int HEIGHT = 6; // metres
810
const int SCALE = 100;
@@ -13,7 +15,7 @@ void init(SDL_Window* &win, SDL_Renderer* &render, std::vector<Actor> &actors) {
1315
win = SDL_CreateWindow("SYCL Crowd Simulation", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH * SCALE, HEIGHT * SCALE, SDL_WINDOW_SHOWN);
1416
render = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
1517

16-
actors.push_back(Actor{{1, 2}, {0.01, 0}, {0.02, 0.02}, 50, 0.05});
18+
actors.push_back(Actor{{1, 2}, {0.01, 0.01}, {0.02, 0.02}, 50, 0.05});
1719
}
1820

1921
void drawCircle(SDL_Renderer* &render, SDL_Point center, int radius, SDL_Color color) {
@@ -36,7 +38,7 @@ void update(std::vector<Actor> &actors) {
3638
}
3739
}
3840

39-
void draw(SDL_Renderer* &render, std::vector<Actor> actors) {
41+
void draw(SDL_Renderer* &render, std::vector<Actor> actors, Room room) {
4042
SDL_SetRenderDrawColor(render, 255, 255, 255, 255);
4143
SDL_RenderClear(render);
4244

@@ -46,6 +48,11 @@ void draw(SDL_Renderer* &render, std::vector<Actor> actors) {
4648
drawCircle(render, pos, actor.getRadius() * SCALE, red);
4749
}
4850

51+
SDL_SetRenderDrawColor(render, 0, 0, 0, 255);
52+
for (std::array<float, 4> wall : room.getWalls()) {
53+
SDL_RenderDrawLine(render, wall[0] * SCALE, wall[1] * SCALE, wall[2] * SCALE, wall[3] * SCALE);
54+
}
55+
4956
SDL_RenderPresent(render);
5057
}
5158

@@ -60,10 +67,11 @@ int main() {
6067
SDL_Renderer* render = NULL;
6168

6269
std::vector<Actor> actors;
70+
Room room = Room({{0.5, 0.5, 0.5, 1.5}, {0.5, 2.5, 0.5, 5.5}, {0.5, 5.5, 7.5, 5.5}, {7.5, 5.5, 7.5, 0.5}, {7.5, 0.5, 0.5, 0.5}}, {});
6371

6472
init(win, render, actors);
6573

66-
draw(render, actors);
74+
draw(render, actors, room);
6775

6876
int delayCounter = 0;
6977
bool isQuit = false;
@@ -78,7 +86,7 @@ int main() {
7886
if (delayCounter >= DELAY) {
7987
delayCounter = 0;
8088
update(actors);
81-
draw(render, actors);
89+
draw(render, actors, room);
8290
}
8391
else {
8492
delayCounter++;

0 commit comments

Comments
 (0)