Skip to content

Commit

Permalink
indent
Browse files Browse the repository at this point in the history
  • Loading branch information
jbmouret committed Apr 15, 2016
1 parent 5b74413 commit 0628524
Show file tree
Hide file tree
Showing 22 changed files with 1,048 additions and 1,014 deletions.
539 changes: 257 additions & 282 deletions display.cpp

Large diffs are not rendered by default.

95 changes: 46 additions & 49 deletions display.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
** Login : <[email protected]>
** Started on Mon Jan 14 16:42:14 2008 Jean-Baptiste MOURET
** $Id$
**
**
** Copyright (C) 2008 Jean-Baptiste MOURET
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Expand All @@ -39,95 +39,92 @@
#include "robot.hpp"
#include <boost/shared_ptr.hpp>

namespace fastsim
{
class Display
{
namespace fastsim {
class Display {

public:
public:
#ifdef USE_SDL
Display(const boost::shared_ptr<Map>& m, const Robot& r);
~Display()
{
~Display() {
SDL_FreeSurface(_map_bmp);
SDL_FreeSurface(_screen);
SDL_Quit();
}
}
void update();
void update_map()
{
void update_map() {
_blit_map();
}
#else
Display(const boost::shared_ptr<Map>& m, const Robot& r) : _map(m), _robot(r) {}
~Display() {}
void update(){}
void update_map(){}
void update() {}
void update_map() {}
#endif
protected:
protected:
const boost::shared_ptr<Map>& _map;
const Robot& _robot;
#ifdef USE_SDL
void _events();
void _bb_to_sdl(const Robot::BoundingBox& bb,
SDL_Rect *r)
{
SDL_Rect *r) {
r->x = (Sint16) _map->real_to_pixel(bb.x);
r->y = (Sint16) _map->real_to_pixel(bb.y);
r->w = (Sint16) _map->real_to_pixel(bb.w);
r->h = (Sint16) _map->real_to_pixel(bb.h);
}

void _quit()
{
void _quit() {
SDL_Quit();
exit(0);
}
void _put_pixel(SDL_Surface* surf,
Uint32 color, unsigned x, unsigned y)
{
Uint32 color, unsigned x, unsigned y) {
if (x >= surf->w || x < 0 || y >= surf->h || y < 0)
return;
return;
Uint32 *bufp = (Uint32*)surf->pixels + y * surf->pitch / 4 + x;
*bufp = color;
}
void _put_pixel(SDL_Surface* surf,
unsigned x, unsigned y,
Uint8 r, Uint8 g, Uint8 b)
{ _put_pixel(surf, SDL_MapRGB(surf->format, r, g, b), x, y); }

unsigned x, unsigned y,
Uint8 r, Uint8 g, Uint8 b) {
_put_pixel(surf, SDL_MapRGB(surf->format, r, g, b), x, y);
}

void _blit_map();

// used by _circle
void _circle_points(SDL_Surface* surf,
int cx, int cy, int x, int y, Uint32 color);
int cx, int cy, int x, int y, Uint32 color);
void _circle(SDL_Surface* surf,
int x_center, int y_center, int radius,
Uint8 r, Uint8 g, Uint8 b)
{ _circle(surf, x_center, y_center, radius, SDL_MapRGB(surf->format, r, g, b)); }
int x_center, int y_center, int radius,
Uint8 r, Uint8 g, Uint8 b) {
_circle(surf, x_center, y_center, radius, SDL_MapRGB(surf->format, r, g, b));
}
void _circle(SDL_Surface* surf,
int x_center, int y_center, int radius,
Uint32 color);
int x_center, int y_center, int radius,
Uint32 color);
//
void _disc(SDL_Surface* surf,
int x_center, int y_center, int radius,
Uint8 r, Uint8 g, Uint8 b)
{ _disc(surf, x_center, y_center, radius, SDL_MapRGB(surf->format, r, g, b)); }
int x_center, int y_center, int radius,
Uint8 r, Uint8 g, Uint8 b) {
_disc(surf, x_center, y_center, radius, SDL_MapRGB(surf->format, r, g, b));
}
void _disc(SDL_Surface* surf,
int x_center, int y_center, int radius,
Uint32 color);
int x_center, int y_center, int radius,
Uint32 color);
//
void _line(SDL_Surface* surf, int x0, int y0, int x1, int y1,
Uint8 r, Uint8 g, Uint8 b)
{ _line(surf, x0, y0, x1, y1, SDL_MapRGB(surf->format, r, g, b)); }
void _line(SDL_Surface* surf, int x0, int y0, int x1, int y1,
Uint32 color);

void _line(SDL_Surface* surf, int x0, int y0, int x1, int y1,
Uint8 r, Uint8 g, Uint8 b) {
_line(surf, x0, y0, x1, y1, SDL_MapRGB(surf->format, r, g, b));
}
void _line(SDL_Surface* surf, int x0, int y0, int x1, int y1,
Uint32 color);

void _try_pixel(bool& res,
SDL_Surface* surf,
Uint32 color,
int x, int y);
SDL_Surface* surf,
Uint32 color,
int x, int y);

//
Uint32 _color_from_id(SDL_Surface* surf, int id);
// disp sensor values
Expand All @@ -139,7 +136,7 @@ namespace fastsim
void _disp_lasers();
void _disp_light_sensors();
void _disp_camera();
//
//
int _w, _h;
SDL_Surface* _screen, *_map_bmp;
SDL_Rect _prev_bb;
Expand Down
39 changes: 18 additions & 21 deletions fastsim_keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
#include "simu_fastsim.hpp"

using namespace sferes;
struct Params
{
struct simu
{
struct Params {
struct simu {
SFERES_STRING(map_name, "modules/fastsim/cuisine.pbm");
SFERES_CONST float dt = 0.01;
};
};



int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
using namespace fastsim;
typedef simu::Fastsim<Params> simu_t;
simu_t s;
Expand All @@ -37,21 +35,20 @@ int main(int argc, char *argv[])
s.init_view();

int numkey;
while(true)
{
SDL_PumpEvents();
Uint8* keys = SDL_GetKeyState(&numkey);
if (keys[SDLK_UP])
s.move_robot(1.0, 1.0);
if (keys[SDLK_DOWN])
s.move_robot(-1.0, -1.0);
if (keys[SDLK_LEFT])
s.move_robot(1.0, -1.0);
if (keys[SDLK_RIGHT])
s.move_robot(-1.0, 1.0);
s.refresh();
s.refresh_view();
}
while(true) {
SDL_PumpEvents();
Uint8* keys = SDL_GetKeyState(&numkey);
if (keys[SDLK_UP])
s.move_robot(1.0, 1.0);
if (keys[SDLK_DOWN])
s.move_robot(-1.0, -1.0);
if (keys[SDLK_LEFT])
s.move_robot(1.0, -1.0);
if (keys[SDLK_RIGHT])
s.move_robot(-1.0, 1.0);
s.refresh();
s.refresh_view();
}

return 0;
}
28 changes: 17 additions & 11 deletions goal.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
#ifndef FASTSIM_GOAL_HPP_
#define FASTSIM_GOAL_HPP_

namespace fastsim
{
class Goal
{
public:
namespace fastsim {
class Goal {
public:
Goal(float x, float y, float diam, int color) :
_x(x), _y(y), _diam(diam), _color(color) {}
float get_x() const { return _x; }
float get_y() const { return _y; }
float get_diam() const { return _diam; }
int get_color() const { return _color; }
private:
float get_x() const {
return _x;
}
float get_y() const {
return _y;
}
float get_diam() const {
return _diam;
}
int get_color() const {
return _color;
}
private:
float _x, _y;
float _diam;
int _color;
int _color;
};
}

Expand Down
Loading

0 comments on commit 0628524

Please sign in to comment.