Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Game Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Onuralp SEZER
Game Library
Commits
1ff0a577
Commit
1ff0a577
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
explicily pass delta time for util functions
parent
fd114acb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
demo/demo/rollball.cpp
+64
-47
64 additions, 47 deletions
demo/demo/rollball.cpp
demo/include/rollball.hpp
+1
-1
1 addition, 1 deletion
demo/include/rollball.hpp
include/fggl/debug/impl/logging_std20.hpp
+1
-1
1 addition, 1 deletion
include/fggl/debug/impl/logging_std20.hpp
with
66 additions
and
49 deletions
demo/demo/rollball.cpp
+
64
−
47
View file @
1ff0a577
...
...
@@ -80,35 +80,35 @@ static void setup_camera(fggl::ecs3::World& world) {
world
.
add
<
fggl
::
gfx
::
Camera
>
(
prototype
);
}
static
fggl
::
ecs3
::
entity_t
setup_environment
(
fggl
::
ecs3
::
World
&
world
,
fggl
::
math
::
vec2
&
size
,
demo
::
RollState
&
state
)
{
static
fggl
::
ecs3
::
entity_t
setup_environment
(
fggl
::
ecs3
::
World
&
world
,
const
fggl
::
math
::
vec2
&
size
,
demo
::
RollState
&
state
)
{
{
auto
northWall
=
world
.
createFromPrototype
(
"wallX"
);
auto
*
transform
=
world
.
get
<
fggl
::
math
::
Transform
>
(
northWall
);
transform
->
origin
({
size
.
x
/
2
,
0.0
f
,
0.0
f
});
transform
->
origin
({
size
.
x
/
2
,
0.0
F
,
0.0
F
});
}
{
auto
southWall
=
world
.
createFromPrototype
(
"wallX"
);
auto
*
transform
=
world
.
get
<
fggl
::
math
::
Transform
>
(
southWall
);
transform
->
origin
({
-
size
.
x
/
2
,
0.0
f
,
0.0
f
});
transform
->
origin
({
-
size
.
x
/
2
,
0.0
F
,
0.0
F
});
}
{
auto
westWall
=
world
.
createFromPrototype
(
"wallZ"
);
auto
*
transform
=
world
.
get
<
fggl
::
math
::
Transform
>
(
westWall
);
transform
->
origin
({
0.0
f
,
0.0
f
,
-
size
.
y
/
2
});
transform
->
origin
({
0.0
F
,
0.0
F
,
-
size
.
y
/
2
});
}
{
auto
eastWall
=
world
.
createFromPrototype
(
"wallZ"
);
auto
*
transform
=
world
.
get
<
fggl
::
math
::
Transform
>
(
eastWall
);
transform
->
origin
({
0.0
f
,
0.0
f
,
size
.
y
/
2
});
transform
->
origin
({
0.0
F
,
0.0
F
,
size
.
y
/
2
});
}
{
auto
floor
=
world
.
createFromPrototype
(
"floor"
);
auto
*
transform
=
world
.
get
<
fggl
::
math
::
Transform
>
(
floor
);
transform
->
origin
({
0.0
f
,
-
2.5
f
,
0.0
f
});
transform
->
origin
({
0.0
F
,
-
2.5
F
,
0.0
F
});
}
{
...
...
@@ -135,12 +135,22 @@ static fggl::ecs3::entity_t setup_environment(fggl::ecs3::World& world, fggl::ma
}
}
// ensure the state is clean
state
.
closestPickup
=
fggl
::
ecs
::
NULL_ENTITY
;
state
.
mode
=
demo
::
DebugMode
::
NORMAL
;
state
.
time
=
0.0
F
;
return
state
.
player
;
}
namespace
demo
{
constexpr
fggl
::
math
::
vec2
WORLD_SIZE
{
40.0
F
,
40.0
F
};
constexpr
fggl
::
math
::
vec3
COLOUR_WHITE
{
1.0
F
,
1.0
F
,
1.0
F
};
constexpr
fggl
::
math
::
vec3
COLOUR_BLUE
{
0.0
F
,
0.0
F
,
1.0
F
};
constexpr
float
MOVE_FORCE
{
3.0
F
};
RollBall
::
RollBall
(
fggl
::
App
&
app
)
:
Game
(
app
)
{
}
...
...
@@ -152,9 +162,13 @@ namespace demo {
// collectable callbacks
auto
*
collectableCallbacks
=
world
().
get
<
fggl
::
phys
::
CollisionCallbacks
>
(
prefabs
.
collectable
);
collectableCallbacks
->
onEnter
=
[
this
](
auto
ourID
,
auto
theirID
)
{
if
(
theirID
==
state
.
player
)
{
this
->
world
().
destroy
(
ourID
);
collectableCallbacks
->
onEnter
=
[
this
](
auto
ourEntity
,
auto
theirEntity
)
{
if
(
theirEntity
==
state
.
player
)
{
//if ( ourEntity == state.closestPickup ) {
// // we're the closest pickup and we're about to get killed, so need to not be.
// state.closestPickup = fggl::ecs::NULL_ENTITY;
//}
this
->
world
().
destroy
(
ourEntity
);
}
};
...
...
@@ -162,55 +176,57 @@ namespace demo {
setup_camera
(
world
());
// create a 20x20 grid
fggl
::
math
::
vec2
size
{
40.0
f
,
40.0
f
};
setup_environment
(
world
(),
size
,
state
);
setup_environment
(
world
(),
WORLD_SIZE
,
state
);
}
fggl
::
math
::
vec3
calc_move_vector
(
const
fggl
::
input
::
Input
&
input
)
{
constexpr
fggl
::
math
::
vec3
forward
=
fggl
::
math
::
FORWARD
;
constexpr
fggl
::
math
::
vec3
right
=
fggl
::
math
::
RIGHT
;
fggl
::
math
::
vec3
force
=
fggl
::
math
::
VEC3_ZERO
;
if
(
input
.
keyboard
.
down
(
glfwGetKeyScancode
(
GLFW_KEY_W
)))
{
force
+=
forward
;
}
if
(
input
.
keyboard
.
down
(
glfwGetKeyScancode
(
GLFW_KEY_S
)))
{
force
-=
forward
;
}
if
(
input
.
keyboard
.
down
(
glfwGetKeyScancode
(
GLFW_KEY_A
)))
{
force
-=
right
;
}
if
(
input
.
keyboard
.
down
(
glfwGetKeyScancode
(
GLFW_KEY_D
)))
{
force
+=
right
;
}
return
force
;
}
void
RollBall
::
update
()
{
Game
::
update
();
const
float
deltaTime
=
1
/
60.0
F
;
auto
&
input
=
this
->
input
();
if
(
state
.
player
!=
fggl
::
ecs3
::
NULL_ENTITY
)
{
auto
&
world
=
this
->
world
();
const
fggl
::
math
::
vec3
forward
=
fggl
::
math
::
FORWARD
;
const
fggl
::
math
::
vec3
right
=
fggl
::
math
::
RIGHT
;
fggl
::
math
::
vec3
force
=
fggl
::
math
::
VEC3_ZERO
;
bool
moved
=
false
;
if
(
input
.
keyboard
.
down
(
glfwGetKeyScancode
(
GLFW_KEY_W
)))
{
force
+=
forward
;
moved
=
true
;
}
if
(
input
.
keyboard
.
down
(
glfwGetKeyScancode
(
GLFW_KEY_S
)))
{
force
-=
forward
;
moved
=
true
;
}
if
(
input
.
keyboard
.
down
(
glfwGetKeyScancode
(
GLFW_KEY_A
)))
{
force
-=
right
;
moved
=
true
;
}
if
(
input
.
keyboard
.
down
(
glfwGetKeyScancode
(
GLFW_KEY_D
)))
{
force
+=
right
;
moved
=
true
;
}
// mode selection
if
(
input
.
keyboard
.
pressed
(
glfwGetKeyScancode
(
GLFW_KEY_SPACE
)))
{
state
.
mode
=
(
DebugMode
)(
((
int
)
state
.
mode
+
1
)
%
3
);
}
// setup dynamic force
if
(
moved
)
{
float
forceFactor
=
3.0
F
;
force
=
glm
::
normalize
(
force
)
*
forceFactor
;
auto
force
=
calc_move_vector
(
input
);
if
(
force
!=
fggl
::
math
::
VEC3_ZERO
)
{
force
=
glm
::
normalize
(
force
)
*
MOVE_FORCE
;
auto
*
dynamics
=
world
.
get
<
fggl
::
phys
::
Dynamics
>
(
state
.
player
);
dynamics
->
force
+=
force
;
}
// track player position with camera
{
auto
cameras
=
world
.
findMatching
<
fggl
::
gfx
::
Camera
>
();
fggl
::
ecs3
::
entity_t
cam
=
cameras
[
0
];
...
...
@@ -229,7 +245,7 @@ namespace demo {
if
(
world
.
alive
(
state
.
closestPickup
)
){
auto
*
renderer
=
world
.
tryGet
<
fggl
::
gfx
::
PhongMaterial
>
(
state
.
closestPickup
);
if
(
renderer
!=
nullptr
)
{
renderer
->
diffuse
=
{
1.0
f
,
1.0
f
,
1.0
f
}
;
renderer
->
diffuse
=
COLOUR_WHITE
;
}
}
...
...
@@ -237,8 +253,9 @@ namespace demo {
}
}
spinCubes
(
world
);
state
.
time
+=
(
60.0
f
/
1000
);
// make the cubes spin
spinCubes
(
world
,
deltaTime
);
state
.
time
+=
deltaTime
;
}
}
...
...
@@ -261,11 +278,11 @@ namespace demo {
}
if
(
state
.
closestPickup
!=
closestEntity
)
{
if
(
state
.
closestPickup
!=
fggl
::
ecs
::
NULL_ENTITY
){
if
(
world
.
alive
(
state
.
closestPickup
)
){
// deal with the previous closest pickup
auto
*
renderer
=
world
.
tryGet
<
fggl
::
gfx
::
PhongMaterial
>
(
state
.
closestPickup
);
if
(
renderer
!=
nullptr
)
{
renderer
->
diffuse
=
{
1.0
f
,
1.0
f
,
1.0
f
}
;
renderer
->
diffuse
=
COLOUR_WHITE
;
}
}
...
...
@@ -274,7 +291,7 @@ namespace demo {
if
(
closestEntity
!=
fggl
::
ecs
::
NULL_ENTITY
)
{
auto
*
renderer
=
world
.
tryGet
<
fggl
::
gfx
::
PhongMaterial
>
(
state
.
closestPickup
);
if
(
renderer
!=
nullptr
)
{
renderer
->
diffuse
=
{
0.0
f
,
0.0
f
,
1.0
f
}
;
renderer
->
diffuse
=
COLOUR_BLUE
;
}
}
}
...
...
@@ -291,7 +308,7 @@ namespace demo {
}
void
RollBall
::
spinCubes
(
fggl
::
ecs3
::
World
&
world
)
{
void
RollBall
::
spinCubes
(
fggl
::
ecs3
::
World
&
world
,
float
deltaTime
)
{
// rotation
for
(
const
auto
&
entity
:
state
.
collectables
)
{
if
(
!
world
.
alive
(
entity
)
||
entity
==
state
.
closestPickup
)
{
...
...
@@ -302,7 +319,7 @@ namespace demo {
// rotate the cubes
fggl
::
math
::
vec3
angles
{
15
,
30
,
45
};
transform
->
rotateEuler
(
angles
*
(
60.0
F
/
1000
)
);
transform
->
rotateEuler
(
angles
*
deltaTime
);
//auto* renderer = world.get<fggl::data::StaticMesh>( entity );
...
...
This diff is collapsed.
Click to expand it.
demo/include/rollball.hpp
+
1
−
1
View file @
1ff0a577
...
...
@@ -64,7 +64,7 @@ namespace demo {
fggl
::
math
::
vec3
cameraOffset
=
{
-
15.0
F
,
15.0
F
,
0.0
F
};
void
closestPickup
(
fggl
::
ecs3
::
World
&
world
);
void
spinCubes
(
fggl
::
ecs3
::
World
&
world
);
void
spinCubes
(
fggl
::
ecs3
::
World
&
world
,
float
dt
);
};
}
...
...
This diff is collapsed.
Click to expand it.
include/fggl/debug/impl/logging_std20.hpp
+
1
−
1
View file @
1ff0a577
...
...
@@ -51,7 +51,7 @@ namespace fggl::debug {
constexpr
std
::
string_view
level_to_string
(
Level
level
)
{
switch
(
level
)
{
case
Level
::
critical
:
return
"CRITI
T
AL"
;
return
"CRITI
C
AL"
;
case
Level
::
error
:
return
"ERROR"
;
case
Level
::
warning
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment