Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
GameDevWeek
Sommersemester 2015
Cpp
Deth Buff Arr
Commits
b127b4ad
Commit
b127b4ad
authored
Sep 21, 2015
by
Elias Broschin
Browse files
i need some delta time
parent
9e6220db
Changes
14
Expand all
Hide whitespace changes
Inline
Side-by-side
GDWSS15.files
View file @
b127b4ad
This diff is collapsed.
Click to expand it.
GDWSS15.includes
View file @
b127b4ad
...
...
@@ -8,6 +8,7 @@ lib/sdl2_mixer/i686-w64-mingw32/include/SDL2
lib/sdl2_mixer/x86_64-w64-mingw32/include/SDL2
include/core
include/
glm/
lib/
lib/glm/glm/glm.hpp
tools/mesh_converter/lib/assimp/code
...
...
@@ -101,3 +102,8 @@ lib/glm/test/external/gli/gtx
lib/glm/glm/detail
lib/gli/external/glm-0.9.5.1/glm/gtc
include/game_state_machine
src/physics/movement
include/physics/movement
include/physics/collision
include/physics
src/physics
include/core/engine.hpp
View file @
b127b4ad
...
...
@@ -10,6 +10,7 @@ namespace gdw {
class
graphics_system
;
class
rendering_system
;
class
game_state_machine
;
class
physics_system
;
}
namespace
gdw
{
...
...
@@ -22,6 +23,7 @@ namespace gdw {
std
::
unique_ptr
<
gdw
::
graphics_system
>
graphics_system_
;
std
::
unique_ptr
<
gdw
::
rendering_system
>
rendering_system_
;
std
::
unique_ptr
<
gdw
::
game_state_machine
>
game_state_machine_
;
std
::
unique_ptr
<
gdw
::
physics_system
>
physics_system_
;
// needs to be the last one that will be destroyed
gdw
::
entity_manager
entity_manager_
;
...
...
@@ -70,6 +72,10 @@ namespace gdw {
gdw
::
game_state_machine
&
game_state_machine
()
noexcept
{
return
*
game_state_machine_
;
}
gdw
::
physics_system
&
physics_system
()
noexcept
{
return
*
physics_system_
;
}
};
}
...
...
include/game_state_machine/play_state.h
View file @
b127b4ad
...
...
@@ -5,6 +5,9 @@
namespace
gdw
{
class
entity
;
class
movement_component
;
class
play_state
:
public
game_state
{
public:
play_state
(
engine
&
engine
);
...
...
@@ -13,6 +16,9 @@ public:
void
update
(
float
dt
);
void
on_enter
();
void
on_exit
();
private:
entity
*
wcube_
;
movement_component
*
wcube_move_
;
};
}
//Namespace gdw
...
...
include/physics/movement/movement_component.h
0 → 100644
View file @
b127b4ad
#ifndef __MOVEMENT_COMPONENT__
#define __MOVEMENT_COMPONENT__
#include
<ecs/component.hpp>
#include
<util/id.hpp>
#include
<glm/glm.hpp>
#include
<vector>
namespace
gdw
{
class
engine
;
class
entity
;
class
movement_component
:
public
component
{
public:
movement_component
(
engine
&
engine
,
entity
&
owner
);
~
movement_component
();
void
update
(
float
dt
);
void
set_mass
(
float
mass
){
mass_
=
mass
;}
void
set_spring
(
float
spring
){
spring_
=
spring
;}
void
set_damping
(
float
damping
){
damping_
=
damping
;}
float
mass
()
{
return
mass_
;}
float
spring
()
{
return
spring_
;}
float
damping
()
{
return
damping_
;}
void
set_current_velocity
(
glm
::
vec3
velocity
)
{
current_velocity_
=
velocity
;}
glm
::
vec3
current_velocity
()
{
return
current_velocity_
;}
void
add_force
(
glm
::
vec3
force
)
{
forces_
.
push_back
(
force
);}
void
set_constant_force
(
glm
::
vec3
constant_force
)
{
constant_force_
=
constant_force
;}
glm
::
vec3
constant_force
()
{
return
constant_force_
;}
static
unsigned
long
long
type_id
()
{
return
gdw
::
type_id
<
gdw
::
movement_component
>
();
}
private:
float
mass_
;
float
spring_
;
float
damping_
;
glm
::
vec3
current_velocity_
;
glm
::
vec3
constant_force_
;
std
::
vector
<
glm
::
vec3
>
forces_
;
};
}
//Namespace gdw
#endif
include/physics/physics_system.h
0 → 100644
View file @
b127b4ad
#ifndef __PHYSICS_SYSTEM__
#define __PHYSICS_SYSTEM__
#include
<vector>
namespace
gdw
{
class
engine
;
class
movement_component
;
class
physics_system
{
public:
physics_system
(
engine
&
engine
);
~
physics_system
();
void
update
(
float
dt
);
private:
void
register_movement_component
(
movement_component
*
comp
);
void
unregister_movement_component
(
movement_component
*
comp
);
private:
friend
class
movement_component
;
engine
&
engine_
;
std
::
vector
<
movement_component
*>
movement_components_
;
};
}
//Namespace gdw
#endif
include/util/stacktrace.hpp
View file @
b127b4ad
#ifndef __GDW_STACKTRACE_HPP__
#define __GDW_STACKTRACE_HPP__
//
#ifndef __GDW_STACKTRACE_HPP__
//
#define __GDW_STACKTRACE_HPP__
#include
<string>
#include
<stdexcept>
//
#include <string>
//
#include <stdexcept>
namespace
gdw
{
//
namespace gdw {
extern
void
initStacktrace
(
std
::
string
exeName
);
//
extern void initStacktrace(std::string exeName);
extern
bool
isStacktraceAvailable
();
//
extern bool isStacktraceAvailable();
extern
std
::
string
genStacktrace
(
std
::
size_t
framesToSkip
=
0
);
//
extern std::string genStacktrace(std::size_t framesToSkip=0);
struct
Error
:
public
std
::
runtime_error
{
explicit
Error
(
const
std
::
string
&
msg
)
:
std
::
runtime_error
(
msg
+
"
\n
At "
+
genStacktrace
(
1
))
{}
};
//
struct Error : public std::runtime_error {
//
explicit Error(const std::string& msg)
//
: std::runtime_error(msg+"\n At "+genStacktrace(1)) {}
//
};
}
//
}
#endif //__GDW_STACKTRACE_HPP__
//
#endif //__GDW_STACKTRACE_HPP__
src/core/engine.cpp
View file @
b127b4ad
...
...
@@ -15,6 +15,7 @@
#include
<util/logger.hpp>
#include
<util/make_unique.hpp>
#include
<game_state_machine/game_state_machine.h>
#include
<physics/physics_system.h>
namespace
gdw
{
engine
::
engine
()
...
...
@@ -26,13 +27,12 @@ namespace gdw {
SDL_ClearError
();
throw
std
::
runtime_error
(
"could not initialize SDL"
+
sdl_error
);
}
physics_system_
=
make_unique
<
gdw
::
physics_system
>
(
*
this
);
audio_
=
make_unique
<
gdw
::
audio
>
(
*
this
);
graphics_system_
=
make_unique
<
gdw
::
graphics_system
>
(
*
this
);
rendering_system_
=
make_unique
<
gdw
::
rendering_system
>
(
*
this
);
game_state_machine_
=
make_unique
<
gdw
::
game_state_machine
>
(
*
this
);
auto
&
wcube
=
entity_manager_
.
emplace_back
(
glm
::
vec3
(
0.
f
),
glm
::
angleAxis
(
0.
f
,
glm
::
vec3
(
0.
f
)));
wcube
.
emplace_back
<
staticmesh_component
>
(
"mesh/cube.msh"
);
}
engine
::~
engine
()
noexcept
{
...
...
@@ -40,7 +40,9 @@ namespace gdw {
}
void
engine
::
update
(
float
delta_time
)
{
physics_system_
->
update
(
delta_time
);
game_state_machine_
->
update
(
delta_time
);
graphics_system_
->
begin
();
rendering_system_
->
update
(
delta_time
);
graphics_system_
->
end
(
delta_time
);
...
...
src/game_state_machine/game_state_machine.cpp
View file @
b127b4ad
...
...
@@ -13,6 +13,7 @@ game_state_machine::game_state_machine(engine& engine):engine_(engine), current_
//default state
current_state_
=
game_states_
[
type_id
<
play_state
>
()].
get
();
current_state_
->
on_enter
();
}
game_state_machine
::~
game_state_machine
()
{
...
...
src/game_state_machine/play_state.cpp
View file @
b127b4ad
...
...
@@ -7,6 +7,8 @@
#include
<ecs/entity.hpp>
#include
<game_state_machine/game_state_machine.h>
#include
<game_state_machine/menu_state.h>
#include
<rendering/staticmesh_component.hpp>
#include
<physics/movement/movement_component.h>
namespace
gdw
{
...
...
@@ -17,9 +19,14 @@ play_state::play_state(engine &engine):game_state(engine) {
play_state
::~
play_state
()
{}
void
play_state
::
on_enter
()
{
wcube_
=
&
engine_
.
entity_manager
().
emplace_back
(
glm
::
vec3
(
0.
f
),
glm
::
angleAxis
(
0.
f
,
glm
::
vec3
(
0.
f
)));
wcube_
->
emplace_back
<
staticmesh_component
>
(
"mesh/cube.msh"
);
wcube_move_
=
&
wcube_
->
emplace_back
<
movement_component
>
();
}
void
play_state
::
update
(
float
dt
)
{}
void
play_state
::
update
(
float
dt
)
{
wcube_move_
->
add_force
(
glm
::
vec3
(
100
,
0
,
0
));
}
void
play_state
::
on_exit
()
{
...
...
src/main.cpp
View file @
b127b4ad
...
...
@@ -8,7 +8,7 @@
int
main
(
int
argc
,
char
*
argv
[])
{
try
{
gdw
::
initStacktrace
(
argv
[
0
]);
//
gdw::initStacktrace(argv[0]);
gdw
::
engine
e
;
e
.
run
();
}
catch
(
std
::
exception
&
ex
)
{
...
...
src/physics/movement/movement_component.cpp
0 → 100644
View file @
b127b4ad
#include
<physics/movement/movement_component.h>
#include
<core/engine.hpp>
#include
<physics/physics_system.h>
#include
<ecs/entity.hpp>
#include
<iostream>
namespace
gdw
{
movement_component
::
movement_component
(
engine
&
engine
,
entity
&
owner
)
:
component
(
engine
,
owner
),
mass_
(
1.
f
),
spring_
(
1.
f
),
damping_
(
1.
f
),
constant_force_
(
glm
::
vec3
(
0.
f
)),
current_velocity_
(
glm
::
vec3
(
0.
f
))
{
//Register
engine
.
physics_system
().
register_movement_component
(
this
);
}
movement_component
::~
movement_component
()
{
//unregister
engine_
.
physics_system
().
unregister_movement_component
(
this
);
}
void
movement_component
::
update
(
float
dt
)
{
std
::
cout
<<
"updating: "
<<
owner_
.
position
().
x
<<
std
::
endl
;
glm
::
vec3
accel
(
constant_force_
);
for
(
auto
&
force
:
forces_
)
{
accel
+=
force
;}
//hack
accel
+=
glm
::
vec3
(
0.
f
)
*
(
spring_
/
mass_
);
accel
-=
current_velocity_
*
(
damping_
/
mass_
);
current_velocity_
+=
accel
*
dt
;
owner_
.
position
(
owner_
.
position
()
+
current_velocity_
*
dt
);
forces_
.
clear
();
}
}
src/physics/physics_system.cpp
0 → 100644
View file @
b127b4ad
#include
<physics/physics_system.h>
#include
<core/engine.hpp>
#include
<util/component_helper.hpp>
#include
<physics/movement/movement_component.h>
#include
<iostream>
namespace
gdw
{
physics_system
::
physics_system
(
engine
&
engine
)
:
engine_
(
engine
)
{
}
physics_system
::~
physics_system
()
{
}
void
physics_system
::
update
(
float
dt
)
{
for
(
auto
&
move
:
movement_components_
)
move
->
update
(
dt
);
}
void
physics_system
::
register_movement_component
(
movement_component
*
comp
)
{
movement_components_
.
emplace_back
(
comp
);
}
void
physics_system
::
unregister_movement_component
(
movement_component
*
comp
)
{
remove_component
(
movement_components_
,
comp
);
}
}
//namespace gdw
src/util/stacktrace.cpp
View file @
b127b4ad
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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