Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
GameDevWeek
Sommersemester 2019
Cpp
PhaseShifter
Commits
b1e84d34
Commit
b1e84d34
authored
Sep 17, 2019
by
Georg Schäfer
Browse files
Merge branch 'develop' into feature/19-level-datastructure
parents
dcf5cafe
306b27cd
Pipeline
#3235
passed with stage
in 2 minutes and 7 seconds
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
assets/game_assets/blueprints/camera.json
View file @
b1e84d34
...
...
@@ -4,5 +4,16 @@
"fov"
:
50.0
,
"near"
:
0.05
,
"far"
:
80.0
},
"Viewtarget"
:
{
"offset"
:
{
"x"
:
0.0
,
"y"
:
10.0
,
"z"
:
1.0
}
},
"Spring"
:
{
"spring_constant"
:
20.0
,
"mass"
:
1.0
}
}
src/gameplay/beat_system.cpp
View file @
b1e84d34
...
...
@@ -17,7 +17,7 @@ namespace phase_shifter::gameplay {
_acc
=
0
;
}
_state
=
{
beat
,
_acc
,
beat_time
-
_acc
};
_state
=
{
beat
,
_acc
,
beat_time
-
_acc
,
beat_time
};
}
}
// namespace phase_shifter::gameplay
src/gameplay/camera_system.cpp
0 → 100644
View file @
b1e84d34
#include
"camera_system.hpp"
#include
<mirrage/ecs/components/transform_comp.hpp>
namespace
phase_shifter
::
gameplay
{
Camera_system
::
Camera_system
(
mirrage
::
ecs
::
Entity_manager
&
entity_manager
)
:
_entity_manager
(
entity_manager
)
{
_entity_manager
.
register_component_type
<
Viewtarget_comp
>
();
_entity_manager
.
register_component_type
<
Spring_comp
>
();
}
void
Camera_system
::
update
(
mirrage
::
util
::
Time
dt
)
{
for
(
auto
&&
[
viewtarget
,
spring
,
transform
]
:
_entity_manager
.
list
<
Viewtarget_comp
,
Spring_comp
,
mirrage
::
ecs
::
components
::
Transform_comp
>
())
{
auto
target_facet
=
_entity_manager
.
get
(
viewtarget
.
target
);
if
(
target_facet
.
is_some
())
{
auto
target_transform
=
target_facet
.
get_or_throw
().
get
<
mirrage
::
ecs
::
components
::
Transform_comp
>
();
if
(
target_transform
.
is_some
())
{
auto
&
target_position
=
target_transform
.
get_or_throw
().
position
;
glm
::
vec3
offset
=
viewtarget
.
offset
;
glm
::
vec3
dest_pos
=
{
target_position
.
x
+
offset
.
x
,
target_position
.
y
+
offset
.
y
,
target_position
.
z
+
offset
.
z
};
float
damping_constant
=
2
*
sqrtf
(
spring
.
spring_constant
);
glm
::
vec3
damping_force
=
-
damping_constant
*
spring
.
velocity
;
glm
::
vec3
spring_force
=
spring
.
spring_constant
*
(
dest_pos
-
transform
.
position
);
glm
::
vec3
acceleration
=
(
spring_force
+
damping_force
)
/
spring
.
mass
;
spring
.
velocity
+=
dt
.
value
()
*
acceleration
;
transform
.
position
+=
dt
.
value
()
*
spring
.
velocity
;
transform
.
direction
(
-
offset
);
}
}
}
}
}
// namespace phase_shifter::gameplay
src/gameplay/camera_system.hpp
0 → 100644
View file @
b1e84d34
#pragma once
#include
<mirrage/utils/units.hpp>
#include
<mirrage/ecs/entity_manager.hpp>
#include
"viewtarget_comp.hpp"
#include
"spring_comp.hpp"
namespace
phase_shifter
::
gameplay
{
class
Camera_system
{
public:
Camera_system
(
mirrage
::
ecs
::
Entity_manager
&
entity_manager
);
void
update
(
mirrage
::
util
::
Time
dt
);
private:
mirrage
::
ecs
::
Entity_manager
&
_entity_manager
;
};
}
\ No newline at end of file
src/gameplay/spring_comp.hpp
0 → 100644
View file @
b1e84d34
#pragma once
#include
<mirrage/ecs/ecs.hpp>
#include
<mirrage/utils/sf2_glm.hpp>
namespace
phase_shifter
::
gameplay
{
struct
Spring_comp
:
public
mirrage
::
ecs
::
Component
<
Spring_comp
>
{
static
constexpr
const
char
*
name
()
{
return
"Spring"
;
}
using
Component
::
Component
;
glm
::
vec3
velocity
=
{
0.
f
,
0.
f
,
0.
f
};
float
spring_constant
=
1.
f
;
float
mass
=
1.
f
;
};
sf2_structDef
(
Spring_comp
,
spring_constant
);
}
\ No newline at end of file
src/gameplay/viewtarget_comp.hpp
0 → 100644
View file @
b1e84d34
#pragma once
#include
<mirrage/ecs/ecs.hpp>
#include
<mirrage/utils/sf2_glm.hpp>
namespace
phase_shifter
::
gameplay
{
struct
Viewtarget_comp
:
public
mirrage
::
ecs
::
Component
<
Viewtarget_comp
>
{
static
constexpr
const
char
*
name
()
{
return
"Viewtarget"
;
}
using
Component
::
Component
;
mirrage
::
ecs
::
Entity_handle
target
;
glm
::
vec3
offset
=
{
0.
f
,
10.
f
,
1.
f
};
};
sf2_structDef
(
Viewtarget_comp
,
offset
);
}
\ No newline at end of file
src/meta_system.cpp
View file @
b1e84d34
...
...
@@ -3,6 +3,7 @@
#include
"audio/audio_asset.hpp"
#include
"game_engine.hpp"
#include
"gameplay/beat_system.hpp"
#include
"gameplay/camera_system.hpp"
#include
"gameplay/movement_system.hpp"
#include
"helper/attachment_system.hpp"
#include
"input/input_system.hpp"
...
...
@@ -31,8 +32,9 @@ namespace phase_shifter {
,
_movement_system
(
std
::
make_unique
<
gameplay
::
Movement_system
>
(
_entities
,
*
_beat_system
))
,
_input_system
(
std
::
make_unique
<
input
::
Input_system
>
(
engine
.
bus
(),
_entities
))
,
_attachment_system
(
std
::
make_unique
<
helper
::
Attachment_system
>
(
_entities
))
,
_hud_system
(
std
::
make_unique
<
ui
::
Hud_system
>
(
engine
.
gui
(),
_entities
))
,
_hud_system
(
std
::
make_unique
<
ui
::
Hud_system
>
(
engine
.
gui
(),
_entities
,
*
_beat_system
))
,
_level_system
(
std
::
make_unique
<
level
::
Level_system
>
(
_entities
,
engine
.
assets
()))
,
_camera_system
(
std
::
make_unique
<
gameplay
::
Camera_system
>
(
_entities
))
{
_entities
.
register_component_type
<
ecs
::
components
::
Transform_comp
>
();
...
...
@@ -81,17 +83,6 @@ namespace phase_shifter {
auto
cam_azimuth
=
0.0
f
;
auto
cam_dir
=
glm
::
quat
(
glm
::
vec3
(
(
cam_elevation
-
2.
f
)
*
glm
::
pi
<
float
>
()
/
2.
f
,
glm
::
pi
<
float
>
()
*
cam_azimuth
,
0.
f
));
entities
()
.
entity_builder
(
"camera"
)
.
rotation
(
cam_dir
)
.
position
(
glm
::
rotate
(
cam_dir
,
glm
::
vec3
(
0
,
0
,
-
1
))
*
8.
f
)
.
post_create
([
=
](
ecs
::
Entity_facet
entity
)
{
entity
.
process
<
Transform_comp
>
([
&
](
auto
&
transform
)
{
transform
.
position
=
transform
.
direction
()
*
-
10.
f
;
transform
.
look_at
({
0
,
0
,
0
});
});
})
.
create
();
auto
sun_elevation
=
0.05
f
*
glm
::
pi
<
float
>
();
auto
sun_azimuth
=
0.7
f
;
...
...
@@ -103,7 +94,21 @@ namespace phase_shifter {
.
position
(
glm
::
rotate
(
sun_dir
,
glm
::
vec3
(
0
,
0
,
1
))
*
40.
f
)
.
create
();
entities
().
entity_builder
(
"player"
).
position
({
0
,
1
,
0
}).
create
();
mirrage
::
ecs
::
Entity_facet
player
=
entities
().
entity_builder
(
"player"
).
position
({
0
,
1
,
0
}).
create
();
auto
playerhandle
=
player
.
handle
();
entities
()
.
entity_builder
(
"camera"
)
.
rotation
(
cam_dir
)
.
position
(
glm
::
rotate
(
cam_dir
,
glm
::
vec3
(
0
,
0
,
-
1
))
*
8.
f
)
.
post_create
([
=
](
ecs
::
Entity_facet
entity
)
{
entity
.
process
<
Transform_comp
>
([
&
](
auto
&
transform
)
{
transform
.
position
=
transform
.
direction
()
*
-
10.
f
;
transform
.
look_at
({
0
,
0
,
0
});
});
entity
.
process
(
[
=
](
gameplay
::
Viewtarget_comp
&
viewtarget
)
{
viewtarget
.
target
=
playerhandle
;
});
})
.
create
();
}
Meta_system
::~
Meta_system
()
...
...
@@ -119,6 +124,7 @@ namespace phase_shifter {
_beat_system
->
update
(
dt
);
_input_system
->
update
(
dt
);
_movement_system
->
update
(
dt
);
_camera_system
->
update
(
dt
);
_attachment_system
->
update
(
dt
);
...
...
src/meta_system.hpp
View file @
b1e84d34
...
...
@@ -22,6 +22,7 @@ namespace phase_shifter {
namespace
gameplay
{
class
Beat_system
;
class
Movement_system
;
class
Camera_system
;
}
// namespace gameplay
namespace
helper
{
class
Attachment_system
;
...
...
@@ -65,6 +66,7 @@ namespace phase_shifter {
std
::
unique_ptr
<
helper
::
Attachment_system
>
_attachment_system
;
std
::
unique_ptr
<
ui
::
Hud_system
>
_hud_system
;
std
::
unique_ptr
<
level
::
Level_system
>
_level_system
;
std
::
unique_ptr
<
gameplay
::
Camera_system
>
_camera_system
;
// TODO: add systems here
mirrage
::
util
::
Console_command_container
_commands
;
...
...
src/ui/hud_system.cpp
View file @
b1e84d34
...
...
@@ -13,16 +13,28 @@ namespace phase_shifter::ui {
namespace
{
constexpr
auto
hud_height
=
100
;
}
constexpr
auto
count_down
=
300
;
constexpr
auto
bar_speed
=
100
;
}
// namespace
Hud_system
::
Hud_system
(
mirrage
::
gui
::
Gui
&
gui
,
mirrage
::
ecs
::
Entity_manager
&
ecs
)
:
_gui
(
gui
)
,
_ecs
(
ecs
)
Hud_system
::
Hud_system
(
mirrage
::
gui
::
Gui
&
gui
,
mirrage
::
ecs
::
Entity_manager
&
ecs
,
const
phase_shifter
::
gameplay
::
Beat_system
&
beat_system
)
:
_gui
(
gui
),
_ecs
(
ecs
),
_timeLeft
(
count_down
),
_beat_system
(
beat_system
)
{
//_circle_texture = _gui.load_texture("tex:circle"_aid);
_max_distance
=
gui
.
viewport
().
z
/
2
;
}
void
Hud_system
::
update
(
mirrage
::
util
::
Time
dt
)
{
_timeLeft
-=
dt
;
auto
state
=
_beat_system
.
beat_state
();
int
max_bars
=
static_cast
<
int
>
(
_max_distance
/
(
bar_speed
*
state
.
avg_beat_time
)
+
1
);
if
(
state
.
beat
&&
_beats
<
max_bars
)
{
_beats
++
;
}
_offset
=
state
.
time_to_beat
*
bar_speed
;
}
void
Hud_system
::
draw
()
...
...
@@ -33,20 +45,56 @@ namespace phase_shifter::ui {
if
(
font
.
is_some
())
ImGui
::
PushFont
(
font
.
get_or_throw
());
ImGui
::
PushStyleColor
(
ImGuiCol_WindowBg
,
"#333333FF"
_imcolor
.
Value
);
ImGui
::
PositionNextWindow
(
glm
::
vec2
(
viewport
.
z
,
hud_height
),
ImGui
::
WindowPosition_X
::
center
,
ImGui
::
WindowPosition_Y
::
bot
to
m
);
ImGui
::
WindowPosition_X
::
left
,
ImGui
::
WindowPosition_Y
::
to
p
);
if
(
ImGui
::
Begin
(
"hud"
,
nullptr
,
ImGuiWindowFlags_NoTitleBar
|
ImGuiWindowFlags_NoMove
|
ImGuiWindowFlags_NoResize
))
{
ImGui
::
Text
(
"TODO"
);
nullptr
,
ImGuiWindowFlags_NoTitleBar
|
ImGuiWindowFlags_NoMove
|
ImGuiWindowFlags_NoResize
|
ImGuiWindowFlags_NoBackground
))
{
ImGui
::
Text
(
"%.2f"
,
_timeLeft
.
value
());
ImGui
::
End
();
}
ImGui
::
PositionNextWindow
(
glm
::
vec2
(
viewport
.
z
,
150
),
ImGui
::
WindowPosition_X
::
center
,
ImGui
::
WindowPosition_Y
::
bottom
);
if
(
ImGui
::
Begin
(
"beat"
,
nullptr
,
ImGuiWindowFlags_NoTitleBar
|
ImGuiWindowFlags_NoMove
|
ImGuiWindowFlags_NoResize
|
ImGuiWindowFlags_NoBackground
))
{
ImGui
::
PushStyleColor
(
ImGuiCol_Border
,
"#00000000"
_imcolor
.
Value
);
// Hide Border
ImVec2
cursor
=
ImGui
::
GetCursorScreenPos
();
auto
beat_state
=
_beat_system
.
beat_state
();
int
max_bars
=
static_cast
<
int
>
(
_max_distance
/
(
bar_speed
*
beat_state
.
avg_beat_time
)
+
1
);
auto
line_offset
=
bar_speed
*
beat_state
.
avg_beat_time
;
auto
start_offset
=
(
max_bars
-
_beats
)
*
line_offset
;
ImGui
::
BeginChild
(
"Line"
,
{
viewport
.
z
,
90
},
true
);
ImDrawList
*
drawList
=
ImGui
::
GetWindowDrawList
();
for
(
int
i
=
0
;
i
<
_beats
;
i
++
)
{
ImVec2
p
(
cursor
.
x
+
_max_distance
-
_offset
-
start_offset
-
i
*
line_offset
,
cursor
.
y
+
10
);
drawList
->
AddLine
(
p
,
{
p
.
x
,
p
.
y
+
50
},
0xFFFFFFFF
,
1
);
}
for
(
int
i
=
0
;
i
<
_beats
;
i
++
)
{
ImVec2
p
(
cursor
.
x
+
viewport
.
z
/
2
+
_offset
+
start_offset
+
i
*
line_offset
,
cursor
.
y
+
10
);
drawList
->
AddLine
(
p
,
{
p
.
x
,
p
.
y
+
50
},
0xFFFFFFFF
,
1
);
}
ImVec2
middle
(
cursor
.
x
+
viewport
.
z
/
2
,
cursor
.
y
);
drawList
->
AddLine
(
middle
,
{
middle
.
x
,
middle
.
y
+
70
},
0xFFFF0000
,
3
);
ImGui
::
EndChild
();
ImGui
::
PopStyleColor
();
ImGui
::
End
();
if
(
beat_state
.
beat
||
beat_state
.
avg_beat_time
-
beat_state
.
time_since_beat
<
0.1
f
||
beat_state
.
time_to_beat
<
0.1
f
)
{
//TODO: Flash image to beat
//ImGui::Image(_circle_texture.get(), {10, 10});
}
}
ImGui
::
PopStyleColor
();
if
(
font
.
is_some
())
ImGui
::
PopFont
();
...
...
src/ui/hud_system.hpp
View file @
b1e84d34
...
...
@@ -6,13 +6,16 @@
#include
<unordered_map>
#include
<memory>
#include
"../gameplay/beat_system.hpp"
namespace
phase_shifter
::
ui
{
class
Hud_system
{
public:
Hud_system
(
mirrage
::
gui
::
Gui
&
gui
,
mirrage
::
ecs
::
Entity_manager
&
ecs
);
Hud_system
(
mirrage
::
gui
::
Gui
&
gui
,
mirrage
::
ecs
::
Entity_manager
&
ecs
,
const
phase_shifter
::
gameplay
::
Beat_system
&
beat_system
);
void
update
(
mirrage
::
util
::
Time
dt
);
void
draw
();
...
...
@@ -20,6 +23,11 @@ namespace phase_shifter::ui {
private:
mirrage
::
gui
::
Gui
&
_gui
;
mirrage
::
ecs
::
Entity_manager
&
_ecs
;
mirrage
::
util
::
Time
_timeLeft
;
int
_beats
=
0
;
float
_offset
=
0
;
float
_max_distance
;
const
phase_shifter
::
gameplay
::
Beat_system
&
_beat_system
;
};
}
// namespace phase_shifter::ui
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment