Skip to content

Commit d04db60

Browse files
author
phillemann
committed
Added more json functions, corrections for new input system
1 parent e00e1fb commit d04db60

40 files changed

+885
-236
lines changed

CMakeLists.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ SET(shadow_files shadow/object.cpp)
122122
SET(ghost_files ghost/instance.cpp
123123
ghost/manager.cpp)
124124
SET(events_files events/tick.cpp
125-
events/key_repeat.cpp
125+
events/mouse_axis.cpp
126+
events/mouse_button.cpp
126127
events/render.cpp
127128
events/key.cpp)
128129
SET(states_files states/camera_move.cpp
@@ -173,7 +174,9 @@ model/object.cpp
173174
model/scoped.cpp
174175
model/create_shader.cpp)
175176
SET(json_files json/parse_config.cpp
176-
json/parse_font.cpp)
177+
json/parse_font.cpp
178+
json/string_to_value.cpp)
179+
#json/merge_trees.cpp)
177180
SET(base_files media_path.cpp input_delegator.cpp create_path.cpp music_controller.cpp machine.cpp application_title.cpp sound_controller.cpp exception.cpp help_needed.cpp create_variables_map.cpp game_cli_options.cpp random_seed.cpp scoped_machine.cpp timed_output.cpp turn_timer.cpp milliseconds_to_string.cpp rigid_model.cpp arrow.cpp)
178181

179182
SET_SOURCE_FILES_PROPERTIES(

console/object.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <sge/renderer/device.hpp>
1010
#include <sge/image/multi_loader.hpp>
1111
#include <sge/image/file.hpp>
12-
#include <sge/input/key_pair.hpp>
1312
#include <sge/texture/part_ptr.hpp>
1413
#include <sge/texture/part_raw.hpp>
1514
#include <sge/config/media_path.hpp>
@@ -27,7 +26,7 @@
2726
#include <functional>
2827

2928
insula::console::object::object(
30-
sge::input::system_ptr const is,
29+
sge::input::keyboard::device_ptr const is,
3130
sge::renderer::device_ptr const rend,
3231
sge::font::system_ptr const fs,
3332
sge::image::multi_loader &il,

console/object.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "redirect_mode.hpp"
55
#include "streambuf.hpp"
6-
#include <sge/input/system_ptr.hpp>
6+
#include <sge/input/keyboard/device_ptr.hpp>
77
#include <sge/console/object.hpp>
88
#include <sge/console/gfx.hpp>
99
#include <sge/renderer/device_ptr.hpp>
@@ -32,7 +32,7 @@ class object
3232

3333
explicit
3434
object(
35-
sge::input::system_ptr,
35+
sge::input::keyboard::device_ptr,
3636
sge::renderer::device_ptr,
3737
sge::font::system_ptr,
3838
sge::image::multi_loader &,

events/key.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#include "key.hpp"
22

33
insula::events::key::key(
4-
sge::input::key_pair const &_k)
4+
sge::input::keyboard::key_event const &_k)
55
:
66
k_(
77
_k)
88
{
99
}
1010

11-
sge::input::key_pair const &
12-
insula::events::key::pair() const
11+
sge::input::keyboard::key_event const &
12+
insula::events::key::event() const
1313
{
1414
return k_;
1515
}

events/key.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef INSULA_EVENTS_KEY_HPP_INCLUDED
22
#define INSULA_EVENTS_KEY_HPP_INCLUDED
33

4-
#include <sge/input/key_pair.hpp>
4+
#include <sge/input/keyboard/key_event.hpp>
55
#include <boost/statechart/event.hpp>
66

77
namespace insula
@@ -15,12 +15,12 @@ class key
1515
public:
1616
explicit
1717
key(
18-
sge::input::key_pair const &);
18+
sge::input::keyboard::key_event const &);
1919

20-
sge::input::key_pair const &
21-
pair() const;
20+
sge::input::keyboard::key_event const &
21+
event() const;
2222
private:
23-
sge::input::key_pair k_;
23+
sge::input::keyboard::key_event k_;
2424
};
2525
}
2626
}

events/key_repeat.cpp

-15
This file was deleted.

events/key_repeat.hpp

-28
This file was deleted.

events/mouse_axis.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "mouse_axis.hpp"
2+
3+
insula::events::mouse_axis::mouse_axis(
4+
sge::input::mouse::axis_event const &_k)
5+
:
6+
k_(
7+
_k)
8+
{
9+
}
10+
11+
sge::input::mouse::axis_event const &
12+
insula::events::mouse_axis::event() const
13+
{
14+
return k_;
15+
}

events/mouse_axis.hpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef INSULA_EVENTS_MOUSE_AXIS_HPP_INCLUDED
2+
#define INSULA_EVENTS_MOUSE_AXIS_HPP_INCLUDED
3+
4+
#include <sge/input/mouse/axis_event.hpp>
5+
#include <boost/statechart/event.hpp>
6+
7+
namespace insula
8+
{
9+
namespace events
10+
{
11+
class mouse_axis
12+
:
13+
public boost::statechart::event<mouse_axis>
14+
{
15+
public:
16+
explicit
17+
mouse_axis(
18+
sge::input::mouse::axis_event const &);
19+
20+
sge::input::mouse::axis_event const &
21+
event() const;
22+
private:
23+
sge::input::mouse::axis_event k_;
24+
};
25+
}
26+
}
27+
28+
#endif

events/mouse_button.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "mouse_button.hpp"
2+
3+
insula::events::mouse_button::mouse_button(
4+
sge::input::mouse::button_event const &_k)
5+
:
6+
k_(
7+
_k)
8+
{
9+
}
10+
11+
sge::input::mouse::button_event const &
12+
insula::events::mouse_button::event() const
13+
{
14+
return k_;
15+
}

events/mouse_button.hpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef INSULA_EVENTS_MOUSE_BUTTON_HPP_INCLUDED
2+
#define INSULA_EVENTS_MOUSE_BUTTON_HPP_INCLUDED
3+
4+
#include <sge/input/mouse/button_event.hpp>
5+
#include <boost/statechart/event.hpp>
6+
7+
namespace insula
8+
{
9+
namespace events
10+
{
11+
class mouse_button
12+
:
13+
public boost::statechart::event<mouse_button>
14+
{
15+
public:
16+
explicit
17+
mouse_button(
18+
sge::input::mouse::button_event const &);
19+
20+
sge::input::mouse::button_event const &
21+
event() const;
22+
private:
23+
sge::input::mouse::button_event k_;
24+
};
25+
}
26+
}
27+
28+
#endif

graphics/camera/object.cpp

+51-33
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
#include "../mat3.hpp"
66
#include "../../input_delegator.hpp"
77
#include "parameters.hpp"
8-
#include <sge/input/key_pair.hpp>
9-
#include <sge/input/system.hpp>
8+
#include <sge/input/mouse/axis_event.hpp>
9+
#include <sge/input/mouse/axis.hpp>
10+
#include <sge/input/keyboard/key_event.hpp>
1011
#include <fcppt/math/matrix/perspective.hpp>
1112
#include <fcppt/math/matrix/translation.hpp>
1213
#include <fcppt/math/matrix/rotation_axis.hpp>
1314
#include <fcppt/math/matrix/transpose.hpp>
14-
#include <fcppt/math/almost_zero.hpp>
15-
#include <fcppt/math/compare.hpp>
16-
#include <fcppt/math/pi.hpp>
1715
#include <fcppt/io/cout.hpp>
1816
#include <fcppt/assert.hpp>
1917

@@ -23,10 +21,16 @@
2321
insula::graphics::camera::object::object(
2422
parameters const &params)
2523
:
26-
input_connection_(
27-
params.input_delegator.register_callback(
24+
key_callback_(
25+
params.input_delegator.key_callback(
2826
std::bind(
29-
&object::input_callback,
27+
&object::key_callback,
28+
this,
29+
std::placeholders::_1))),
30+
mouse_axis_callback_(
31+
params.input_delegator.mouse_axis_callback(
32+
std::bind(
33+
&object::mouse_axis_callback,
3034
this,
3135
std::placeholders::_1))),
3236
aspect_(
@@ -161,15 +165,46 @@ insula::graphics::camera::object::movement(
161165
}
162166

163167
void
164-
insula::graphics::camera::object::input_callback(
165-
sge::input::key_pair const &k)
168+
insula::graphics::camera::object::key_callback(
169+
sge::input::keyboard::key_event const &k)
170+
{
171+
switch (k.key().code())
172+
{
173+
case sge::input::keyboard::key_code::space:
174+
dirs_[1] = !k.pressed() ? 0 : 1;
175+
break;
176+
case sge::input::keyboard::key_code::lctrl:
177+
dirs_[1] = !k.pressed() ? 0 : -1;
178+
break;
179+
case sge::input::keyboard::key_code::up:
180+
dirs_[2] = !k.pressed() ? 0 : -1;
181+
break;
182+
case sge::input::keyboard::key_code::down:
183+
dirs_[2] = !k.pressed() ? 0 : 1;
184+
break;
185+
case sge::input::keyboard::key_code::left:
186+
dirs_[0] = !k.pressed() ? 0 : -1;
187+
break;
188+
case sge::input::keyboard::key_code::right:
189+
dirs_[0] = !k.pressed() ? 0 : 1;
190+
break;
191+
default:
192+
break;
193+
}
194+
}
195+
196+
void
197+
insula::graphics::camera::object::mouse_axis_callback(
198+
sge::input::mouse::axis_event const &k)
166199
{
167200
scalar const angle =
168-
static_cast<scalar>(k.value())/rotation_speed_;
201+
static_cast<scalar>(
202+
k.axis_position())
203+
/rotation_speed_;
169204

170-
switch (k.key().code())
205+
switch (k.axis())
171206
{
172-
case sge::input::kc::mouse_x_axis:
207+
case sge::input::mouse::axis::x:
173208
{
174209
using fcppt::math::matrix::rotation_axis;
175210
using fcppt::math::vector::narrow_cast;
@@ -203,7 +238,7 @@ insula::graphics::camera::object::input_callback(
203238
.right(normalize(right));
204239
}
205240
break;
206-
case sge::input::kc::mouse_y_axis:
241+
case sge::input::mouse::axis::y:
207242
{
208243
using fcppt::math::matrix::rotation_axis;
209244
using fcppt::math::vector::narrow_cast;
@@ -231,24 +266,7 @@ insula::graphics::camera::object::input_callback(
231266
.right(normalize(right));
232267
}
233268
break;
234-
case sge::input::kc::key_space:
235-
dirs_[1] = !k.value() ? 0 : 1;
236-
break;
237-
case sge::input::kc::key_lctrl:
238-
dirs_[1] = !k.value() ? 0 : -1;
239-
break;
240-
default:
241-
if (k.key().code() == sge::input::kc::key_up)
242-
dirs_[2] = !k.value() ? 0 : -1;
243-
244-
if (k.key().code() == sge::input::kc::key_down)
245-
dirs_[2] = !k.value() ? 0 : 1;
246-
247-
if (k.key().code() == sge::input::kc::key_left)
248-
dirs_[0] = !k.value() ? 0 : -1;
249-
250-
if (k.key().code() == sge::input::kc::key_right)
251-
dirs_[0] = !k.value() ? 0 : 1;
252-
break;
269+
case sge::input::mouse::axis::wheel:
270+
break;
253271
}
254272
}

graphics/camera/object.hpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#include "../vec4.hpp"
88
#include "../gizmo.hpp"
99
#include "parameters_fwd.hpp"
10-
#include <sge/input/system_ptr.hpp>
11-
#include <sge/input/key_pair_fwd.hpp>
10+
#include <sge/input/keyboard/key_event_fwd.hpp>
11+
#include <sge/input/mouse/axis_event_fwd.hpp>
1212
#include <fcppt/signal/scoped_connection.hpp>
1313

1414
#include <fcppt/io/cout.hpp>
@@ -75,16 +75,20 @@ class object
7575
movement(
7676
bool);
7777
private:
78-
fcppt::signal::scoped_connection input_connection_;
78+
fcppt::signal::scoped_connection key_callback_,mouse_axis_callback_;
7979
scalar aspect_,fov_,near_,far_;
8080
scalar movement_speed_,rotation_speed_;
8181
vec3 dirs_;
8282
insula::graphics::gizmo gizmo_;
8383
bool movement_;
8484

8585
void
86-
input_callback(
87-
sge::input::key_pair const &);
86+
key_callback(
87+
sge::input::keyboard::key_event const &);
88+
89+
void
90+
mouse_axis_callback(
91+
sge::input::mouse::axis_event const &);
8892
};
8993
}
9094
}

0 commit comments

Comments
 (0)