From d5b909fd8dd3d0ebc6d1bd107abb5383e2cbeca1 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Fri, 26 Aug 2016 08:15:37 +0200 Subject: [PATCH] Refreshed the code to compile without warning. --- Makefile | 4 ++-- hit_shape.cc | 2 +- manipulator.cc | 2 +- misc.h | 3 ++- move_square.cc | 4 ++-- simple_window.cc | 19 +++++++++++++------ simple_window.h | 1 + xfig_tracer.h | 2 +- 8 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 1331d46..3a41714 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ else CXXFLAGS = -fPIC -Wall -g -O3 endif -LDFLAGS = -L/usr/X11R6/lib/ +LDFLAGS = -L/usr/X11R6/lib/ -lz -ldl TASK_SRC = dummy.cc move_square.cc hit_shape.cc TASK_OBJ = $(TASK_SRC:.cc=.task) @@ -44,7 +44,7 @@ main: main.o misc.o \ manipulator.o \ approximer.o \ intelligence.o - $(CXX) -lX11 $(CXXFLAGS) -o $@ $^ $(LDFLAGS) + $(CXX) $(CXXFLAGS) $(LDFLAGS) -lX11 -o $@ $^ %.task: %.cc misc.o universe.o polygon.o xfig_tracer.o map.o task.o manipulator.o $(CXX) $(CXXFLAGS) -shared -Wl,-soname,$@ -o $@ $^ diff --git a/hit_shape.cc b/hit_shape.cc index 189cadc..1663064 100644 --- a/hit_shape.cc +++ b/hit_shape.cc @@ -8,7 +8,7 @@ class MoveSquare : public Task { - int _square_size; + scalar_t _square_size; int _nb_shapes; Polygon **_shapes; bool *_targets; diff --git a/manipulator.cc b/manipulator.cc index ca6a144..d42dfb7 100644 --- a/manipulator.cc +++ b/manipulator.cc @@ -117,7 +117,7 @@ void Manipulator::update(scalar_t dt, Universe *universe) { scalar_t f = sqrt(sq(_force_x) + sq(_force_y)); if(f >= force_break) { - _current_polygon = false; + _current_polygon = 0; _force_x = 0; _force_y = 0; } else { diff --git a/misc.h b/misc.h index add2acd..f3a21f0 100644 --- a/misc.h +++ b/misc.h @@ -14,7 +14,8 @@ #define ASSERT(x, s) #endif -typedef float scalar_t; +// typedef float scalar_t; +typedef double scalar_t; inline scalar_t sq(scalar_t x) { return x*x; } diff --git a/move_square.cc b/move_square.cc index 5aed572..cf32bfb 100644 --- a/move_square.cc +++ b/move_square.cc @@ -29,8 +29,8 @@ public: else if(degree == 1) _square_size = 150; else if(degree == 2) _square_size = 100; else _square_size = 50; - scalar_t x[] = { -_square_size/2, _square_size/2, _square_size/2, -_square_size/2 }; - scalar_t y[] = { -_square_size/2, -_square_size/2, _square_size/2, _square_size/2 }; + scalar_t x[] = { -_square_size/2.0, _square_size/2.0, _square_size/2.0, -_square_size/2.0 }; + scalar_t y[] = { -_square_size/2.0, -_square_size/2.0, _square_size/2.0, _square_size/2.0 }; _target = new Polygon(0.5, 1.0, 1.0, 0.0, x, y, 4); _target->set_position(_square_size/2, _square_size/2 + (world_height - _square_size) * drand48(), 0); _target->set_speed(0, 0, 0); diff --git a/simple_window.cc b/simple_window.cc index f0905df..7fee9c2 100644 --- a/simple_window.cc +++ b/simple_window.cc @@ -186,17 +186,24 @@ SimpleEvent SimpleWindow::event() { break; case KeyPress: + KeySym mykey; + mykey = XkbKeycodeToKeysym(_display, + event.xkey.keycode, 0, + event.xkey.state & ShiftMask ? 1 : 0); + se.type = SimpleEvent::KEY_PRESS; - strncpy(se.key, - XKeysymToString(XKeycodeToKeysym(_display, event.xkey.keycode, 0)), - (sizeof(se.key)/sizeof(char) - 1)); + strncpy(se.key, XKeysymToString(mykey), (sizeof(se.key)/sizeof(char) - 1)); + break; case KeyRelease: + KeySym mykey; + mykey = XkbKeycodeToKeysym(_display, + event.xkey.keycode, 0, + event.xkey.state & ShiftMask ? 1 : 0); + se.type = SimpleEvent::KEY_RELEASE; - strncpy(se.key, - XKeysymToString(XKeycodeToKeysym(_display, event.xkey.keycode, 0)), - (sizeof(se.key)/sizeof(char) - 1)); + strncpy(se.key, XKeysymToString(mykey), (sizeof(se.key)/sizeof(char) - 1)); break; default: diff --git a/simple_window.h b/simple_window.h index 37218eb..81c3116 100644 --- a/simple_window.h +++ b/simple_window.h @@ -12,6 +12,7 @@ using namespace std; #include #include +#include class SimpleEvent { public: diff --git a/xfig_tracer.h b/xfig_tracer.h index 77a24c0..1a2ef65 100644 --- a/xfig_tracer.h +++ b/xfig_tracer.h @@ -24,7 +24,7 @@ class XFigTracer { static const int max_nb_user_colors = 100; int _palette_red[max_nb_user_colors]; int _palette_green[max_nb_user_colors]; - int _palette_blue[max_nb_user_colors],; + int _palette_blue[max_nb_user_colors]; int user_color(int red, int green, int blue); public: XFigTracer(const char *name); -- 2.39.5