Merge remote-tracking branch 'origin/master' into water

Conflicts:
	include/Core/Engine.h
	include/Physics/PhysicsSystem.h
	include/Sound/SoundSystem.h
	src/game/Physics/PhysicsSystem.cpp
	src/game/Sound/SoundSystem.cpp
PS:min teori i förra commiten var sann
This commit is contained in:
Stiffly
2015-10-07 18:34:36 +02:00
75 changed files with 9561 additions and 2755 deletions
+1
View File
@@ -3,3 +3,4 @@
/lib/ /lib/
# CLion # CLion
.idea/ .idea/
.orig
+10 -4
View File
@@ -15,11 +15,11 @@ else()
endif() endif()
if(CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fpermissive")
if(UNIX) if(UNIX)
# Needed to link with debug version of bgfx on linux # Needed to link with debug version of bgfx on linux
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -ldl") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -ldl")
endif() endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
endif() endif()
set(BUILD_SHARED_LIBS FALSE) set(BUILD_SHARED_LIBS FALSE)
@@ -31,7 +31,7 @@ include_directories(${PROJECT_SOURCE_DIR}/include)
#set(GLFW_INCLUDE_DIR ${daydream_SOURCE_DIR}/libs/glfw-3.0.4/include) #set(GLFW_INCLUDE_DIR ${daydream_SOURCE_DIR}/libs/glfw-3.0.4/include)
#set(GLFW_LIBRARY ${daydream_SOURCE_DIR}/libs/glfw-3.0.4/lib/Release/glfw3dll.lib) #set(GLFW_LIBRARY ${daydream_SOURCE_DIR}/libs/glfw-3.0.4/lib/Release/glfw3dll.lib)
set(Boost_DEBUG ON) #set(Boost_DEBUG ON)
set(Boost_USE_STATIC_LIBS on) set(Boost_USE_STATIC_LIBS on)
add_definitions(-DBOOST_ALL_NO_LIB) add_definitions(-DBOOST_ALL_NO_LIB)
#set(BOOST_INCLUDEDIR ${BOOST_ROOT}/boost) #set(BOOST_INCLUDEDIR ${BOOST_ROOT}/boost)
@@ -40,9 +40,15 @@ set(BOOST_LIBRARYDIR $ENV{BOOST_ROOT}/lib64-msvc-12.0)
#add_definitions(-DGLEW_MX) #add_definitions(-DGLEW_MX)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} )
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} )
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} )
endforeach(OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES)
add_subdirectory(src/game) add_subdirectory(src/game)
add_subdirectory(src/tests) add_subdirectory(src/tests)
+12
View File
@@ -0,0 +1,12 @@
# Blender MTL File: 'Bricks.blend'
# Material Count: 1
newmtl Material.002
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd IceBrick_Diffuse.png
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

+12
View File
@@ -0,0 +1,12 @@
# Blender MTL File: 'Bricks.blend'
# Material Count: 1
newmtl Material.004
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd turquoise.png
+513
View File
@@ -0,0 +1,513 @@
# Blender v2.75 (sub 0) OBJ File: 'Bricks.blend'
# www.blender.org
mtllib TurquoiseBrick.mtl
o OriginalBrick_Cube.002
v 0.416882 0.151013 0.189181
v 0.383459 0.157800 0.197587
v 0.427922 0.161606 0.161784
v 0.383459 0.180000 0.161784
v 0.432779 0.125616 0.202365
v 0.383459 0.126000 0.215784
v 0.450000 0.126000 0.161784
v -0.416882 0.151013 0.189181
v 0.000000 0.157800 0.197587
v -0.383459 0.157800 0.197587
v -0.427922 0.161606 0.161784
v 0.000000 0.180000 0.161784
v -0.383459 0.180000 0.161784
v -0.432779 0.125616 0.202365
v 0.000000 0.126000 0.215784
v -0.383459 0.126000 0.215784
v -0.450000 0.126000 0.161784
v 0.427922 0.161606 0.000000
v 0.416882 0.151013 -0.189181
v 0.383459 0.180000 0.000000
v 0.383459 0.157800 -0.197587
v 0.427922 0.161606 -0.161784
v 0.383459 0.180000 -0.161784
v 0.450000 0.126000 0.000000
v 0.432779 0.125616 -0.202365
v 0.383459 0.126000 -0.215784
v 0.450000 0.126000 -0.161784
v 0.000000 0.180000 0.000000
v -0.427922 0.161606 0.000000
v -0.416882 0.151013 -0.189181
v 0.000000 0.157800 -0.197587
v -0.383459 0.180000 0.000000
v -0.383459 0.157800 -0.197587
v -0.427922 0.161606 -0.161784
v 0.000000 0.180000 -0.161784
v -0.383459 0.180000 -0.161784
v -0.450000 0.126000 0.000000
v -0.432779 0.125616 -0.202365
v 0.000000 0.126000 -0.215784
v -0.383459 0.126000 -0.215784
v -0.450000 0.126000 -0.161784
v 0.416882 -0.151013 0.189181
v 0.383459 -0.157800 0.197587
v 0.427922 -0.161606 0.161784
v 0.383459 -0.180000 0.161784
v 0.432779 -0.125616 0.202365
v 0.383459 -0.126000 0.215784
v 0.450000 -0.126000 0.161784
v 0.432723 0.000000 0.202132
v 0.383459 0.000000 0.215784
v 0.450000 0.000000 0.161784
v -0.416882 -0.151013 0.189181
v 0.000000 -0.157800 0.197587
v -0.383459 -0.157800 0.197587
v -0.427922 -0.161606 0.161784
v 0.000000 -0.180000 0.161784
v -0.383459 -0.180000 0.161784
v -0.432779 -0.125616 0.202365
v 0.000000 -0.126000 0.215784
v -0.383459 -0.126000 0.215784
v -0.450000 -0.126000 0.161784
v -0.432723 0.000000 0.202132
v 0.000000 0.000000 0.215784
v -0.383459 0.000000 0.215784
v -0.450000 0.000000 0.161784
v 0.427922 -0.161606 0.000000
v 0.416882 -0.151013 -0.189181
v 0.383459 -0.180000 0.000000
v 0.383459 -0.157800 -0.197587
v 0.427922 -0.161606 -0.161784
v 0.383459 -0.180000 -0.161784
v 0.450000 -0.126000 0.000000
v 0.432779 -0.125616 -0.202365
v 0.383459 -0.126000 -0.215784
v 0.450000 -0.126000 -0.161784
v 0.450000 0.000000 0.000000
v 0.432723 0.000000 -0.202132
v 0.383459 0.000000 -0.215784
v 0.450000 0.000000 -0.161784
v 0.000000 -0.180000 0.000000
v -0.427922 -0.161606 0.000000
v -0.416882 -0.151013 -0.189181
v 0.000000 -0.157800 -0.197587
v -0.383459 -0.180000 0.000000
v -0.383459 -0.157800 -0.197587
v -0.427922 -0.161606 -0.161784
v 0.000000 -0.180000 -0.161784
v -0.383459 -0.180000 -0.161784
v -0.450000 -0.126000 0.000000
v -0.432779 -0.125616 -0.202365
v 0.000000 -0.126000 -0.215784
v -0.383459 -0.126000 -0.215784
v -0.450000 -0.126000 -0.161784
v -0.450000 0.000000 0.000000
v -0.432723 0.000000 -0.202132
v 0.000000 0.000000 -0.215784
v -0.383459 0.000000 -0.215784
v -0.450000 0.000000 -0.161784
vt 0.732824 0.651596
vt 0.497063 0.656145
vt 0.498352 0.561696
vt 0.835737 0.544092
vt 0.832410 0.574334
vt 0.728776 0.549797
vt 0.733409 0.516110
vt 0.747921 0.523504
vt 0.498691 0.536867
vt 0.754013 0.503366
vt 0.838288 0.518944
vt 0.716137 0.523643
vt 0.711494 0.504530
vt 0.498984 0.515399
vt 0.734485 0.500579
vt 0.734742 0.443967
vt 0.756687 0.444264
vt 0.500002 0.440769
vt 0.708811 0.443615
vt 0.842574 0.445423
vt 0.261516 0.645162
vt 0.268342 0.543511
vt 0.164088 0.565217
vt 0.161584 0.534899
vt 0.264629 0.509713
vt 0.281689 0.517713
vt 0.159717 0.509691
vt 0.244381 0.496413
vt 0.249922 0.516708
vt 0.263977 0.494158
vt 0.286851 0.498734
vt 0.243317 0.437260
vt 0.265263 0.437561
vt 0.291193 0.437916
vt 0.157430 0.436083
vt 0.495722 0.754363
vt 0.939579 0.572784
vt 0.950008 0.538976
vt 0.966270 0.556108
vt 0.495366 0.780443
vt 0.733578 0.753608
vt 0.929866 0.518425
vt 0.931317 0.541897
vt 0.953950 0.520177
vt 0.983612 0.534778
vt 0.733699 0.802691
vt 0.495056 0.803167
vt 0.935351 0.446668
vt 0.962999 0.447038
vt 0.733787 0.881463
vt 0.493987 0.881463
vt 0.999906 0.447531
vt 0.057009 0.560761
vt 0.047501 0.526686
vt 0.066106 0.530111
vt 0.257977 0.747114
vt 0.068193 0.506688
vt 0.030782 0.543370
vt 0.014024 0.521580
vt 0.256516 0.796175
vt 0.044070 0.507787
vt 0.037002 0.434429
vt 0.064650 0.434809
vt 0.254277 0.874915
vt 0.000094 0.433923
vt 0.501652 0.319843
vt 0.502941 0.225399
vt 0.738475 0.236380
vt 0.731650 0.338024
vt 0.835884 0.316299
vt 0.838396 0.346613
vt 0.735366 0.371817
vt 0.718307 0.363820
vt 0.501313 0.344671
vt 0.840268 0.371818
vt 0.755614 0.385114
vt 0.750071 0.364821
vt 0.736021 0.387371
vt 0.713148 0.382798
vt 0.501020 0.366139
vt 0.267194 0.229946
vt 0.164293 0.337419
vt 0.167628 0.307183
vt 0.271241 0.331739
vt 0.266605 0.365420
vt 0.252095 0.358025
vt 0.246001 0.378160
vt 0.161736 0.362565
vt 0.283877 0.357890
vt 0.288517 0.377003
vt 0.265527 0.380951
vt 0.504282 0.127186
vt 0.942953 0.320724
vt 0.952471 0.354792
vt 0.933866 0.351373
vt 0.742013 0.134433
vt 0.504638 0.101108
vt 0.931787 0.374794
vt 0.969182 0.338104
vt 0.985946 0.359886
vt 0.504948 0.078385
vt 0.743473 0.085376
vt 0.955907 0.373688
vt 0.506017 0.000095
vt 0.745712 0.006641
vt 0.060470 0.308697
vt 0.050030 0.342497
vt 0.033776 0.325361
vt 0.266441 0.127940
vt 0.070165 0.363055
vt 0.068721 0.339584
vt 0.046081 0.361294
vt 0.016425 0.346681
vt 0.266320 0.078861
vt 0.266232 0.000094
vt 0.733646 0.779865
vt 0.257192 0.773359
vt 0.742798 0.108190
vt 0.266373 0.101685
vn 0.194900 0.980800 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 0.961700 0.273900
vn 0.647300 0.762200 0.000000
vn 0.178700 0.949500 0.257800
vn 0.457300 0.661600 0.594300
vn 0.631200 0.737600 0.239800
vn 0.000000 0.694500 0.719500
vn 0.939500 0.276000 0.202600
vn 0.961700 0.274000 0.000000
vn 0.151600 0.685100 0.712500
vn 0.135500 0.258500 0.956400
vn 0.000000 0.256900 0.966400
vn 0.632300 0.305000 0.712100
vn 0.658300 0.000000 0.752800
vn 0.979700 0.000000 0.200600
vn 0.000000 0.000000 1.000000
vn 0.134200 0.000000 0.990900
vn 1.000000 0.000000 0.000000
vn -0.194900 0.980800 0.000000
vn -0.178700 0.949500 0.257800
vn -0.647300 0.762200 0.000000
vn -0.457300 0.661600 0.594300
vn -0.151600 0.685100 0.712500
vn -0.961700 0.274000 0.000000
vn -0.939500 0.276000 0.202600
vn -0.631200 0.737600 0.239800
vn -0.632300 0.305000 0.712100
vn -0.135500 0.258500 0.956400
vn -0.979700 0.000000 0.200600
vn -0.658300 0.000000 0.752800
vn -0.134200 0.000000 0.990900
vn -1.000000 0.000000 0.000000
vn 0.000000 0.961700 -0.273900
vn 0.178700 0.949500 -0.257800
vn 0.457300 0.661600 -0.594300
vn 0.151600 0.685100 -0.712500
vn 0.000000 0.694500 -0.719500
vn 0.939500 0.276000 -0.202600
vn 0.631200 0.737600 -0.239800
vn 0.632300 0.305000 -0.712100
vn 0.135500 0.258500 -0.956400
vn 0.000000 0.256900 -0.966400
vn 0.979700 0.000000 -0.200600
vn 0.658300 0.000000 -0.752800
vn 0.134200 0.000000 -0.990900
vn 0.000000 0.000000 -1.000000
vn -0.178700 0.949500 -0.257800
vn -0.457300 0.661600 -0.594300
vn -0.631200 0.737600 -0.239800
vn -0.939500 0.276000 -0.202600
vn -0.151600 0.685100 -0.712500
vn -0.135500 0.258500 -0.956400
vn -0.632300 0.305000 -0.712100
vn -0.658300 0.000000 -0.752800
vn -0.979700 0.000000 -0.200600
vn -0.134200 0.000000 -0.990900
vn 0.000000 -0.961700 0.273900
vn 0.000000 -1.000000 0.000000
vn 0.194900 -0.980800 0.000000
vn 0.178700 -0.949500 0.257800
vn 0.647300 -0.762200 0.000000
vn 0.457300 -0.661600 0.594300
vn 0.151600 -0.685100 0.712500
vn 0.000000 -0.694500 0.719500
vn 0.961700 -0.274000 0.000000
vn 0.939500 -0.276000 0.202600
vn 0.631200 -0.737600 0.239800
vn 0.632300 -0.305000 0.712100
vn 0.135500 -0.258500 0.956400
vn 0.000000 -0.256900 0.966400
vn -0.194900 -0.980800 0.000000
vn -0.647300 -0.762200 0.000000
vn -0.178700 -0.949500 0.257800
vn -0.457300 -0.661600 0.594300
vn -0.631200 -0.737600 0.239800
vn -0.939500 -0.276000 0.202600
vn -0.961700 -0.274000 0.000000
vn -0.151600 -0.685100 0.712500
vn -0.135500 -0.258500 0.956400
vn -0.632300 -0.305000 0.712100
vn 0.000000 -0.961700 -0.273900
vn 0.178700 -0.949500 -0.257800
vn 0.457300 -0.661600 -0.594300
vn 0.631200 -0.737600 -0.239800
vn 0.000000 -0.694500 -0.719500
vn 0.939500 -0.276000 -0.202600
vn 0.151600 -0.685100 -0.712500
vn 0.135500 -0.258500 -0.956400
vn 0.000000 -0.256900 -0.966400
vn 0.632300 -0.305000 -0.712100
vn -0.178700 -0.949500 -0.257800
vn -0.457300 -0.661600 -0.594300
vn -0.151600 -0.685100 -0.712500
vn -0.939500 -0.276000 -0.202600
vn -0.631200 -0.737600 -0.239800
vn -0.632300 -0.305000 -0.712100
vn -0.135500 -0.258500 -0.956400
usemtl Material.004
s 1
f 20/1/1 28/2/2 12/3/3
f 18/4/4 20/5/1 4/6/5
f 1/7/6 3/8/7 4/6/5
f 4/6/5 12/3/3 9/9/8
f 3/8/7 7/10/9 24/11/10
f 1/7/6 2/12/11 6/13/12
f 9/9/8 15/14/13 6/13/12
f 1/7/6 5/15/14 7/10/9
f 5/15/14 49/16/15 51/17/16
f 15/14/13 63/18/17 50/19/18
f 5/15/14 6/13/12 50/19/18
f 7/10/9 51/17/16 76/20/19
f 12/3/3 28/2/2 32/21/20
f 13/22/21 32/23/20 29/24/22
f 8/25/23 10/26/24 13/22/21
f 9/9/8 12/3/3 13/22/21
f 37/27/25 17/28/26 11/29/27
f 8/25/23 14/30/28 16/31/29
f 16/31/29 15/14/13 9/9/8
f 17/28/26 14/30/28 8/25/23
f 65/32/30 62/33/31 14/30/28
f 64/34/32 63/18/17 15/14/13
f 14/30/28 62/33/31 64/34/32
f 94/35/33 65/32/30 17/28/26
f 35/36/34 28/2/2 20/1/1
f 23/37/35 20/5/1 18/4/4
f 19/38/36 21/39/37 23/37/35
f 31/40/38 35/36/34 23/41/35
f 24/11/10 27/42/39 22/43/40
f 19/38/36 25/44/41 26/45/42
f 26/46/42 39/47/43 31/40/38
f 27/42/39 25/44/41 19/38/36
f 79/48/44 77/49/45 25/44/41
f 78/50/46 96/51/47 39/47/43
f 25/44/41 77/49/45 78/52/46
f 76/20/19 79/48/44 27/42/39
f 32/21/20 28/2/2 35/36/34
f 29/24/22 32/23/20 36/53/48
f 30/54/49 34/55/50 36/53/48
f 36/56/48 35/36/34 31/40/38
f 34/55/50 41/57/51 37/27/25
f 30/54/49 33/58/52 40/59/53
f 31/40/38 39/47/43 40/60/53
f 30/54/49 38/61/54 41/57/51
f 38/61/54 95/62/55 98/63/56
f 39/47/43 96/51/47 97/64/57
f 38/61/54 40/59/53 97/65/57
f 41/57/51 98/63/56 94/35/33
f 56/66/58 80/67/59 68/68/60
f 45/69/61 68/70/60 66/71/62
f 42/72/63 43/73/64 45/69/61
f 53/74/65 56/66/58 45/69/61
f 72/75/66 48/76/67 44/77/68
f 42/72/63 46/78/69 47/79/70
f 47/79/70 59/80/71 53/74/65
f 48/76/67 46/78/69 42/72/63
f 51/17/16 49/16/15 46/78/69
f 50/19/18 63/18/17 59/80/71
f 46/78/69 49/16/15 50/19/18
f 76/20/19 51/17/16 48/76/67
f 84/81/72 80/67/59 56/66/58
f 81/82/73 84/83/72 57/84/74
f 52/85/75 55/86/76 57/84/74
f 57/84/74 56/66/58 53/74/65
f 55/86/76 61/87/77 89/88/78
f 52/85/75 54/89/79 60/90/80
f 53/74/65 59/80/71 60/90/80
f 52/85/75 58/91/81 61/87/77
f 58/91/81 62/33/31 65/32/30
f 59/80/71 63/18/17 64/34/32
f 58/91/81 60/90/80 64/34/32
f 61/87/77 65/32/30 94/35/33
f 68/68/60 80/67/59 87/92/82
f 66/71/62 68/70/60 71/93/83
f 67/94/84 70/95/85 71/93/83
f 71/96/83 87/92/82 83/97/86
f 70/95/85 75/98/87 72/75/66
f 67/94/84 69/99/88 74/100/89
f 83/97/86 91/101/90 74/102/89
f 67/94/84 73/103/91 75/98/87
f 73/103/91 77/49/45 79/48/44
f 91/101/90 96/104/47 78/105/46
f 73/103/91 74/100/89 78/52/46
f 75/98/87 79/48/44 76/20/19
f 87/92/82 80/67/59 84/81/72
f 88/106/92 84/83/72 81/82/73
f 82/107/93 85/108/94 88/106/92
f 83/97/86 87/92/82 88/109/92
f 89/88/78 93/110/95 86/111/96
f 82/107/93 90/112/97 92/113/98
f 92/114/98 91/101/90 83/97/86
f 93/110/95 90/112/97 82/107/93
f 98/63/56 95/62/55 90/112/97
f 97/115/57 96/104/47 91/101/90
f 90/112/97 95/62/55 97/65/57
f 94/35/33 98/63/56 93/110/95
f 4/6/5 20/1/1 12/3/3
f 3/8/7 18/4/4 4/6/5
f 2/12/11 1/7/6 4/6/5
f 2/12/11 4/6/5 9/9/8
f 18/4/4 3/8/7 24/11/10
f 5/15/14 1/7/6 6/13/12
f 2/12/11 9/9/8 6/13/12
f 3/8/7 1/7/6 7/10/9
f 7/10/9 5/15/14 51/17/16
f 6/13/12 15/14/13 50/19/18
f 49/16/15 5/15/14 50/19/18
f 24/11/10 7/10/9 76/20/19
f 13/22/21 12/3/3 32/21/20
f 11/29/27 13/22/21 29/24/22
f 11/29/27 8/25/23 13/22/21
f 10/26/24 9/9/8 13/22/21
f 29/24/22 37/27/25 11/29/27
f 10/26/24 8/25/23 16/31/29
f 10/26/24 16/31/29 9/9/8
f 11/29/27 17/28/26 8/25/23
f 17/28/26 65/32/30 14/30/28
f 16/31/29 64/34/32 15/14/13
f 16/31/29 14/30/28 64/34/32
f 37/27/25 94/35/33 17/28/26
f 23/41/35 35/36/34 20/1/1
f 22/43/40 23/37/35 18/4/4
f 22/43/40 19/38/36 23/37/35
f 21/116/37 31/40/38 23/41/35
f 18/4/4 24/11/10 22/43/40
f 21/39/37 19/38/36 26/45/42
f 21/116/37 26/46/42 31/40/38
f 22/43/40 27/42/39 19/38/36
f 27/42/39 79/48/44 25/44/41
f 26/46/42 78/50/46 39/47/43
f 26/45/42 25/44/41 78/52/46
f 24/11/10 76/20/19 27/42/39
f 36/56/48 32/21/20 35/36/34
f 34/55/50 29/24/22 36/53/48
f 33/58/52 30/54/49 36/53/48
f 33/117/52 36/56/48 31/40/38
f 29/24/22 34/55/50 37/27/25
f 38/61/54 30/54/49 40/59/53
f 33/117/52 31/40/38 40/60/53
f 34/55/50 30/54/49 41/57/51
f 41/57/51 38/61/54 98/63/56
f 40/60/53 39/47/43 97/64/57
f 95/62/55 38/61/54 97/65/57
f 37/27/25 41/57/51 94/35/33
f 45/69/61 56/66/58 68/68/60
f 44/77/68 45/69/61 66/71/62
f 44/77/68 42/72/63 45/69/61
f 43/73/64 53/74/65 45/69/61
f 66/71/62 72/75/66 44/77/68
f 43/73/64 42/72/63 47/79/70
f 43/73/64 47/79/70 53/74/65
f 44/77/68 48/76/67 42/72/63
f 48/76/67 51/17/16 46/78/69
f 47/79/70 50/19/18 59/80/71
f 47/79/70 46/78/69 50/19/18
f 72/75/66 76/20/19 48/76/67
f 57/84/74 84/81/72 56/66/58
f 55/86/76 81/82/73 57/84/74
f 54/89/79 52/85/75 57/84/74
f 54/89/79 57/84/74 53/74/65
f 81/82/73 55/86/76 89/88/78
f 58/91/81 52/85/75 60/90/80
f 54/89/79 53/74/65 60/90/80
f 55/86/76 52/85/75 61/87/77
f 61/87/77 58/91/81 65/32/30
f 60/90/80 59/80/71 64/34/32
f 62/33/31 58/91/81 64/34/32
f 89/88/78 61/87/77 94/35/33
f 71/96/83 68/68/60 87/92/82
f 70/95/85 66/71/62 71/93/83
f 69/99/88 67/94/84 71/93/83
f 69/118/88 71/96/83 83/97/86
f 66/71/62 70/95/85 72/75/66
f 73/103/91 67/94/84 74/100/89
f 69/118/88 83/97/86 74/102/89
f 70/95/85 67/94/84 75/98/87
f 75/98/87 73/103/91 79/48/44
f 74/102/89 91/101/90 78/105/46
f 77/49/45 73/103/91 78/52/46
f 72/75/66 75/98/87 76/20/19
f 88/109/92 87/92/82 84/81/72
f 86/111/96 88/106/92 81/82/73
f 86/111/96 82/107/93 88/106/92
f 85/119/94 83/97/86 88/109/92
f 81/82/73 89/88/78 86/111/96
f 85/108/94 82/107/93 92/113/98
f 85/119/94 92/114/98 83/97/86
f 86/111/96 93/110/95 82/107/93
f 93/110/95 98/63/56 90/112/97
f 92/114/98 97/115/57 91/101/90
f 92/113/98 90/112/97 97/65/57
f 89/88/78 94/35/33 93/110/95
Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

@@ -1,6 +1,6 @@
# Blender v2.75 (sub 0) OBJ File: 'submarine.blend' # Blender v2.75 (sub 0) OBJ File: 'submarine.blend'
# www.blender.org # www.blender.org
mtllib submarine2.mtl mtllib Submarine2.mtl
o Cube o Cube
v -0.378953 -0.002680 -0.065172 v -0.378953 -0.002680 -0.065172
v 0.212611 0.044805 -0.044067 v 0.212611 0.044805 -0.044067
+21
View File
@@ -0,0 +1,21 @@
# Blender MTL File: 'Sid.blend'
# Material Count: 2
newmtl Derp
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd SquidTexture.png
newmtl None
Ns 0
Ka 0.000000 0.000000 0.000000
Kd 0.8 0.8 0.8
Ks 0.8 0.8 0.8
d 1
illum 2
map_Kd SquidTexture.png
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+187
View File
@@ -0,0 +1,187 @@
EXPORTS
alAuxiliaryEffectSlotf
alAuxiliaryEffectSlotfv
alAuxiliaryEffectSloti
alAuxiliaryEffectSlotiv
alBuffer3f
alBuffer3i
alBufferData
alBufferSamplesSOFT
alBufferSubDataSOFT
alBufferSubSamplesSOFT
alBufferf
alBufferfv
alBufferi
alBufferiv
alDeferUpdatesSOFT
alDeleteAuxiliaryEffectSlots
alDeleteBuffers
alDeleteEffects
alDeleteFilters
alDeleteFontsoundsSOFT
alDeletePresetsSOFT
alDeleteSoundfontsSOFT
alDeleteSources
alDisable
alDistanceModel
alDopplerFactor
alDopplerVelocity
alEffectf
alEffectfv
alEffecti
alEffectiv
alEnable
alFilterf
alFilterfv
alFilteri
alFilteriv
alFontsound2iSOFT
alFontsoundModulatoriSOFT
alFontsoundiSOFT
alFontsoundivSOFT
alGenAuxiliaryEffectSlots
alGenBuffers
alGenEffects
alGenFilters
alGenFontsoundsSOFT
alGenPresetsSOFT
alGenSoundfontsSOFT
alGenSources
alGetAuxiliaryEffectSlotf
alGetAuxiliaryEffectSlotfv
alGetAuxiliaryEffectSloti
alGetAuxiliaryEffectSlotiv
alGetBoolean
alGetBooleanv
alGetBuffer3f
alGetBuffer3i
alGetBufferSamplesSOFT
alGetBufferf
alGetBufferfv
alGetBufferi
alGetBufferiv
alGetDouble
alGetDoublev
alGetEffectf
alGetEffectfv
alGetEffecti
alGetEffectiv
alGetEnumValue
alGetError
alGetFilterf
alGetFilterfv
alGetFilteri
alGetFilteriv
alGetFloat
alGetFloatv
alGetFontsoundModulatorivSOFT
alGetFontsoundivSOFT
alGetInteger
alGetInteger64SOFT
alGetInteger64vSOFT
alGetIntegerv
alGetListener3f
alGetListener3i
alGetListenerf
alGetListenerfv
alGetListeneri
alGetListeneriv
alGetPresetivSOFT
alGetProcAddress
alGetSoundfontivSOFT
alGetSource3dSOFT
alGetSource3f
alGetSource3i
alGetSource3i64SOFT
alGetSourcedSOFT
alGetSourcedvSOFT
alGetSourcef
alGetSourcefv
alGetSourcei
alGetSourcei64SOFT
alGetSourcei64vSOFT
alGetSourceiv
alGetString
alIsAuxiliaryEffectSlot
alIsBuffer
alIsBufferFormatSupportedSOFT
alIsEffect
alIsEnabled
alIsExtensionPresent
alIsFilter
alIsFontsoundSOFT
alIsPresetSOFT
alIsSoundfontSOFT
alIsSource
alListener3f
alListener3i
alListenerf
alListenerfv
alListeneri
alListeneriv
alLoadSoundfontSOFT
alMidiEventSOFT
alMidiGainSOFT
alMidiPauseSOFT
alMidiPlaySOFT
alMidiResetSOFT
alMidiSoundfontSOFT
alMidiSoundfontvSOFT
alMidiStopSOFT
alMidiSysExSOFT
alPresetFontsoundsSOFT
alPresetiSOFT
alPresetivSOFT
alProcessUpdatesSOFT
alSoundfontPresetsSOFT
alSource3dSOFT
alSource3f
alSource3i
alSource3i64SOFT
alSourcePause
alSourcePausev
alSourcePlay
alSourcePlayv
alSourceQueueBuffers
alSourceRewind
alSourceRewindv
alSourceStop
alSourceStopv
alSourceUnqueueBuffers
alSourcedSOFT
alSourcedvSOFT
alSourcef
alSourcefv
alSourcei
alSourcei64SOFT
alSourcei64vSOFT
alSourceiv
alSpeedOfSound
alcCaptureCloseDevice
alcCaptureOpenDevice
alcCaptureSamples
alcCaptureStart
alcCaptureStop
alcCloseDevice
alcCreateContext
alcDestroyContext
alcDevicePauseSOFT
alcDeviceResumeSOFT
alcGetContextsDevice
alcGetCurrentContext
alcGetEnumValue
alcGetError
alcGetInteger64vSOFT
alcGetIntegerv
alcGetProcAddress
alcGetString
alcGetThreadContext
alcIsExtensionPresent
alcIsRenderFormatSupportedSOFT
alcLoopbackOpenDeviceSOFT
alcMakeContextCurrent
alcOpenDevice
alcProcessContext
alcRenderSamplesSOFT
alcSetThreadContext
alcSuspendContext
Binary file not shown.
Binary file not shown.
Binary file not shown.
+41 -110
View File
@@ -45,6 +45,7 @@
#include "Game/CPad.h" #include "Game/CPad.h"
#include "Game/CBrick.h" #include "Game/CBrick.h"
#include "Game/BallSystem.h" #include "Game/BallSystem.h"
#include "Game/HitLagSystem.h"
#include "Game/Bricks/CPowerUpBrick.h" #include "Game/Bricks/CPowerUpBrick.h"
#include "Physics/PhysicsSystem.h" #include "Physics/PhysicsSystem.h"
@@ -113,10 +114,6 @@ public:
m_World->ComponentFactory.Register<Components::PowerUp>(); m_World->ComponentFactory.Register<Components::PowerUp>();
m_World->ComponentFactory.Register<Components::PowerUpBrick>(); m_World->ComponentFactory.Register<Components::PowerUpBrick>();
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::PhysicsSystem>();
m_World->SystemFactory.Register<Systems::LevelSystem>( m_World->SystemFactory.Register<Systems::LevelSystem>(
[this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); }); [this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::LevelSystem>(); m_World->AddSystem<Systems::LevelSystem>();
@@ -126,6 +123,12 @@ public:
m_World->SystemFactory.Register<Systems::BallSystem>( m_World->SystemFactory.Register<Systems::BallSystem>(
[this]() { return new Systems::BallSystem(m_World.get(), m_EventBroker); }); [this]() { return new Systems::BallSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::BallSystem>(); m_World->AddSystem<Systems::BallSystem>();
m_World->SystemFactory.Register<Systems::HitLagSystem>(
[this]() { return new Systems::HitLagSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::HitLagSystem>();
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::PhysicsSystem>();
m_World->ComponentFactory.Register<Components::Model>(); m_World->ComponentFactory.Register<Components::Model>();
m_World->ComponentFactory.Register<Components::Template>(); m_World->ComponentFactory.Register<Components::Template>();
@@ -135,31 +138,6 @@ public:
m_World->ComponentFactory.Register<Components::ParticleEmitter>(); m_World->ComponentFactory.Register<Components::ParticleEmitter>();
m_World->Initialize(); m_World->Initialize();
//OctoBall
{
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(-0.f, 0.26f, -9.f);
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
transform->Velocity = glm::vec3(0.0f, -10.f, 0.f);
auto model = m_World->AddComponent<Components::Model>(ent);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
ball->Speed = 5.f;
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;
physics->Category = CollisionLayer::Type::Ball;
physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall;
physics->Calculate = true;
auto plight = m_World->AddComponent<Components::PointLight>(ent);
plight->Radius = 2.f;
m_World->CommitEntity(ent);
}
//PointLightTest //PointLightTest
{ {
auto t_Light = m_World->CreateEntity(); auto t_Light = m_World->CreateEntity();
@@ -207,6 +185,7 @@ public:
m_World->CommitEntity(background); m_World->CommitEntity(background);
} }
// auto particleEmitter= m_World->AddComponent<Components::Emitter>(Pe);
//Water test //Water test
{ {
auto t_waterBody = m_World->CreateEntity(); auto t_waterBody = m_World->CreateEntity();
@@ -271,64 +250,35 @@ public:
//TODO: Why does the ball not collide with these bricks? //TODO: Why does the ball not collide with these bricks?
//BottomBox //BottomBox
{ {
auto topWall = m_World->CreateEntity(); auto BottomWall = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(topWall); auto transform = m_World->AddComponent<Components::Transform>(BottomWall);
transform->Position = glm::vec3(0.f, -7.f, -9.9f); transform->Position = glm::vec3(0.f, -6.f, -10.f);
transform->Scale = glm::vec3(10.f, 0.5f, 1.f); transform->Scale = glm::vec3(20.f, 0.5f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall); std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(BottomWall);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>( std::shared_ptr<Components::RectangleShape> rectangleShape = m_World->AddComponent<Components::RectangleShape>(BottomWall);
topWall); rectangleShape->Dimensions = glm::vec2(20.f, 0.5f);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall); std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(BottomWall);
physics->Static = true; physics->CollisionType = CollisionType::Type::Static;
m_World->CommitEntity(topWall); m_World->CommitEntity(BottomWall);
} }
//SideBox
// {
// auto topWall = m_World->CreateEntity();
// std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
// transform->Position = glm::vec3(3.f, -3.0f, -9.9f);
// transform->Scale = glm::vec3(0.5f, 3.f, 1.f);
// std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
// sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
// std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
// topWall);
// std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
// physics->Static = true;
// m_World->CommitEntity(topWall);
// }
// //OtherSideBox
// {
// auto topWall = m_World->CreateEntity();
// std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
// transform->Position = glm::vec3(-4.f, -3.0f, -9.9f);
// transform->Scale = glm::vec3(0.5f, 3.0f, 1.f);
// std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
// sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
// std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
// topWall);
// std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
// physics->Static = true;
// m_World->CommitEntity(topWall);
// }
{ {
auto topWall = m_World->CreateEntity(); auto topWall = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>( std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
topWall);
transform->Position = glm::vec3(0.f, 6.f, -10.f); transform->Position = glm::vec3(0.f, 6.f, -10.f);
transform->Scale = glm::vec3(20.f, 0.5f, 1.f); transform->Scale = glm::vec3(20.f, 0.5f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall); std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>( std::shared_ptr<Components::RectangleShape> rectangleShape = m_World->AddComponent<Components::RectangleShape>(topWall);
topWall); rectangleShape->Dimensions = glm::vec2(20.f, 0.5f);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall); std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
physics->Static = true; physics->CollisionType = CollisionType::Type::Static;
physics->Category = CollisionLayer::Type::Wall; physics->Category = CollisionLayer::Wall;
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick; physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Ball | CollisionLayer::Brick);
m_World->CommitEntity(topWall); m_World->CommitEntity(topWall);
} }
@@ -343,13 +293,13 @@ public:
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(leftWall); std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(leftWall);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>( std::shared_ptr<Components::RectangleShape> rectangleShape = m_World->AddComponent<Components::RectangleShape>(leftWall);
leftWall); rectangleShape->Dimensions = glm::vec2(0.5f, 20.f);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(leftWall); std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(leftWall);
physics->Static = true; physics->CollisionType = CollisionType::Type::Static;
physics->Category = CollisionLayer::Type::Wall; physics->Category = CollisionLayer::Wall;
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick; physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Ball | CollisionLayer::Brick);
m_World->CommitEntity(leftWall); m_World->CommitEntity(leftWall);
} }
@@ -364,37 +314,16 @@ public:
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(rightWall); std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(rightWall);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>( std::shared_ptr<Components::RectangleShape> rectangleShape = m_World->AddComponent<Components::RectangleShape>(rightWall);
rightWall); rectangleShape->Dimensions = glm::vec2(0.5f, 20.f);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(rightWall); std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(rightWall);
physics->Static = true; physics->CollisionType = CollisionType::Type::Static;
physics->Category = CollisionLayer::Type::Wall; physics->Category = CollisionLayer::Wall;
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick; physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Ball | CollisionLayer::Brick);
m_World->CommitEntity(rightWall); m_World->CommitEntity(rightWall);
} }
{
auto ent = m_World->CreateEntity();
m_World->SetProperty(ent, "Name", "Pad");
auto ctransform = m_World->AddComponent<Components::Transform>(ent);
ctransform->Position = glm::vec3(0.f, -3.5f, -10.f);
ctransform->Scale = glm::vec3(1.0f, 1.0f, 1.f);
auto rectangle = m_World->AddComponent<Components::RectangleShape>(ent);
auto physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;
physics->Category = CollisionLayer::Type::Pad;
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::PowerUp;
physics->Calculate = true;
auto cModel = m_World->AddComponent<Components::Model>(ent);
cModel->ModelFile = "Models/Submarine2.obj";
auto pad = m_World->AddComponent<Components::Pad>(ent);
m_World->CommitEntity(ent);
}
//EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &Engine::OnGameStart); //EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &Engine::OnGameStart);
m_EGameStart = decltype(m_EGameStart)(std::bind(&Engine::OnGameStart, this, std::placeholders::_1)); m_EGameStart = decltype(m_EGameStart)(std::bind(&Engine::OnGameStart, this, std::placeholders::_1));
m_EventBroker->Subscribe(m_EGameStart); m_EventBroker->Subscribe(m_EGameStart);
@@ -605,17 +534,19 @@ private:
//Todo: Move this //Todo: Move this
{ {
dd::Events::PlaySound e; dd::Events::PlaySound e;
e.path = "Sounds/BGM/under-the-sea-instrumental.wav"; e.FilePath = "Sounds/BGM/under-the-sea-instrumental.wav";
e.isAmbient = true; e.IsAmbient = true;
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
} }
{ {
dd::Events::PlaySound e; dd::Events::PlaySound e;
e.path = "Sounds/BGM/water-flowing.wav"; e.FilePath = "Sounds/BGM/water-flowing.wav";
e.volume = 0.3f; e.Gain = 0.3f;
e.isAmbient = true; e.IsAmbient = true;
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
} }
return true;
}; };
double m_LastTime; double m_LastTime;
}; };
-562
View File
@@ -1,562 +0,0 @@
/*
This file is part of Daydream Engine.
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
Daydream Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Daydream Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string>
#include <sstream>
#include <Sound/CCollisionSound.h>
#include "ResourceManager.h"
#include "OBJ.h"
#include "Model.h"
#include "Texture.h"
#include "EventBroker.h"
#include "RenderQueue.h"
#include "Renderer.h"
#include "InputManager.h"
//TODO: Remove includes that are only here for the temporary draw solution.
#include "World.h"
#include "CTransform.h"
#include "Core/EventBroker.h"
#include "Rendering/CModel.h"
#include "Rendering/CSprite.h"
#include "CTemplate.h"
#include "Rendering/CPointLight.h"
#include "Transform/TransformSystem.h"
#include "Sound/SoundSystem.h"
#include "Sound/CCollisionSound.h"
#include "Game/LevelSystem.h"
#include "Game/PadSystem.h"
#include "Game/CBall.h"
#include "Game/CPad.h"
#include "Game/CBrick.h"
#include "Game/BallSystem.h"
#include "Game/Bricks/CPowerUpBrick.h"
#include "Physics/PhysicsSystem.h"
#include "Physics/CPhysics.h"
#include "Physics/CRectangleShape.h"
#include "Physics/ESetImpulse.h"
#include "Physics/CWaterVolume.h"
#include "Game/EGameStart.h"
#include "Sound/EPlaySound.h"
#include "GUI/Frame.h"
#include "GUI/Button.h"
#include "Game/MainMenu.h"
#include "Game/HUD.h"
namespace dd
{
class Engine
{
public:
Engine(int argc, char* argv[]) {
m_EventBroker = std::make_shared<EventBroker>();
m_Renderer = std::make_shared<Renderer>();
m_Renderer->SetFullscreen(false);
//m_Renderer->SetResolution(Rectangle(0, 0, 1920, 1080));
m_Renderer->SetResolution(Rectangle(0, 0, 675, 1080));
m_Renderer->Initialize();
m_FrameStack = new GUI::Frame(m_EventBroker.get());
m_FrameStack->Width = 675;
m_FrameStack->Height = 1080;
auto hud = new GUI::HUD(m_FrameStack, "HUD");
auto menu = new GUI::MainMenu(m_FrameStack, "MainMenu");
m_InputManager = std::make_shared<InputManager>(m_Renderer->Window(), m_EventBroker);
m_World = std::make_shared<World>(m_EventBroker);
//TODO: Move this out of engine.h
m_World->ComponentFactory.Register<Components::Transform>();
m_World->SystemFactory.Register<Systems::TransformSystem>(
[this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::TransformSystem>();
m_World->ComponentFactory.Register<Components::Model>();
m_World->ComponentFactory.Register<Components::Template>();
m_World->ComponentFactory.Register<Components::CollisionSound>();
m_World->SystemFactory.Register<Systems::SoundSystem>(
[this]() { return new Systems::SoundSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::SoundSystem>();
m_World->ComponentFactory.Register<Components::Sprite>();
m_World->ComponentFactory.Register<Components::RectangleShape>();
m_World->ComponentFactory.Register<Components::Physics>();
m_World->ComponentFactory.Register<Components::Ball>();
m_World->ComponentFactory.Register<Components::Brick>();
m_World->ComponentFactory.Register<Components::Pad>();
m_World->ComponentFactory.Register<Components::Life>();
m_World->ComponentFactory.Register<Components::PowerUp>();
m_World->ComponentFactory.Register<Components::PowerUpBrick>();
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::PhysicsSystem>();
m_World->SystemFactory.Register<Systems::LevelSystem>(
[this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::LevelSystem>();
m_World->SystemFactory.Register<Systems::PadSystem>(
[this]() { return new Systems::PadSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::PadSystem>();
m_World->SystemFactory.Register<Systems::BallSystem>(
[this]() { return new Systems::BallSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::BallSystem>();
m_World->ComponentFactory.Register<Components::Model>();
m_World->ComponentFactory.Register<Components::Template>();
m_World->ComponentFactory.Register<Components::PointLight>();
m_World->ComponentFactory.Register<Components::WaterVolume>();
m_World->Initialize();
//OctoBall
{
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(-0.f, 0.26f, -9.f);
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
transform->Velocity = glm::vec3(0.0f, -10.f, 0.f);
auto model = m_World->AddComponent<Components::Model>(ent);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
ball->Speed = 5.f;
<<<<<<< HEAD
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;
physics->Category = CollisionLayer::Type::Ball;
physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall;
physics->Calculate = true;
=======
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;
>>>>>>> origin/master
auto plight = m_World->AddComponent<Components::PointLight>(ent);
plight->Radius = 2.f;
m_World->CommitEntity(ent);
}
//PointLightTest
{
auto t_Light = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_Light);
transform->Position = glm::vec3(2.f, 1.5f, -9.f);
auto pl = m_World->AddComponent<Components::PointLight>(t_Light);
pl->Radius = 8.f;
m_World->CommitEntity(t_Light);
}
//Halfpipe background test model.
{
auto t_halfPipe = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_halfPipe);
transform->Position = glm::vec3(0.f, 0.f, -15.f);
transform->Scale = glm::vec3(15.f);
auto model = m_World->AddComponent<Components::Model>(t_halfPipe);
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
model->Color = glm::vec4(1.f, 1.f, 1.f, 0.3f);
m_World->CommitEntity(t_halfPipe);
}
//Background
{
auto background = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(background);
transform->Position = glm::vec3(0.f, 0.f, -30.f);
transform->Scale = glm::vec3(2681.f / 50.f, 1080.f / 50.f, 1.f);
auto sprite = m_World->AddComponent<Components::Sprite>(background);
sprite->SpriteFile = "Textures/Background.png";
m_World->CommitEntity(background);
}
//Water test
{
auto t_waterBody = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_waterBody);
transform->Position = glm::vec3(0.f, -4.5f, -10.f);
transform->Scale = glm::vec3(7.f, 1.5f, 1.f);
auto water = m_World->AddComponent<Components::WaterVolume>(t_waterBody);
auto body = m_World->AddComponent<Components::RectangleShape>(t_waterBody);
m_World->CommitEntity(t_waterBody);
}
//TODO: Why does the ball not collide with these bricks?
//BottomBox
{
auto topWall = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(topWall);
transform->Position = glm::vec3(0.f, -6.f, -9.9f);
transform->Scale = glm::vec3(10.f, 0.5f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
topWall);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
physics->Static = true;
m_World->CommitEntity(topWall);
}
//SideBox
// {
// auto topWall = m_World->CreateEntity();
// std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
// transform->Position = glm::vec3(3.f, -3.0f, -9.9f);
// transform->Scale = glm::vec3(0.5f, 3.f, 1.f);
// std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
// sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
// std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
// topWall);
// std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
// physics->Static = true;
// m_World->CommitEntity(topWall);
// }
// //OtherSideBox
// {
// auto topWall = m_World->CreateEntity();
// std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
// transform->Position = glm::vec3(-4.f, -3.0f, -9.9f);
// transform->Scale = glm::vec3(0.5f, 3.0f, 1.f);
// std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
// sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
// std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
// topWall);
// std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
// physics->Static = true;
// m_World->CommitEntity(topWall);
// }
{
auto topWall = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(
topWall);
transform->Position = glm::vec3(0.f, 6.f, -10.f);
transform->Scale = glm::vec3(20.f, 0.5f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
topWall);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
physics->Static = true;
physics->Category = CollisionLayer::Type::Wall;
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
m_World->CommitEntity(topWall);
}
{
auto leftWall = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(
leftWall);
transform->Position = glm::vec3(-4.f, 1.f, -10.f);
transform->Scale = glm::vec3(0.5f, 20.f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(leftWall);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
leftWall);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(leftWall);
physics->Static = true;
physics->Category = CollisionLayer::Type::Wall;
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
m_World->CommitEntity(leftWall);
}
{
auto rightWall = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(
rightWall);
transform->Position = glm::vec3(4.f, 1.f, -10.f);
transform->Scale = glm::vec3(0.5f, 20.f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(rightWall);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
rightWall);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(rightWall);
physics->Static = true;
physics->Category = CollisionLayer::Type::Wall;
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
m_World->CommitEntity(rightWall);
}
{
auto ent = m_World->CreateEntity();
m_World->SetProperty(ent, "Name", "Pad");
auto ctransform = m_World->AddComponent<Components::Transform>(ent);
ctransform->Position = glm::vec3(0.f, -5.f, -10.f);
ctransform->Scale = glm::vec3(1.0f, 1.0f, 1.f);
auto rectangle = m_World->AddComponent<Components::RectangleShape>(ent);
auto physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;
physics->Category = CollisionLayer::Type::Pad;
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::PowerUp;
physics->Calculate = true;
auto cModel = m_World->AddComponent<Components::Model>(ent);
cModel->ModelFile = "Models/Submarine2.obj";
auto pad = m_World->AddComponent<Components::Pad>(ent);
m_World->CommitEntity(ent);
}
//EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &Engine::OnGameStart);
m_EGameStart = decltype(m_EGameStart)(std::bind(&Engine::OnGameStart, this, std::placeholders::_1));
m_EventBroker->Subscribe(m_EGameStart);
m_LastTime = glfwGetTime();
}
bool Running() const { return !glfwWindowShouldClose(m_Renderer->Window()); }
void Tick()
{
double currentTime = glfwGetTime();
double dt = currentTime - m_LastTime;
m_LastTime = currentTime;
// Update input
m_InputManager->Update(dt);
// Swap event queues to get fresh input data in the read queue
//m_EventBroker->Swap();
ResourceManager::Update();
if (m_GameIsRunning) {
m_World->Update(dt);
}
m_EventBroker->Process<GUI::Frame>();
m_FrameStack->UpdateLayered(dt);
m_RendererQueue.Clear();
m_FrameStack->DrawLayered(m_RendererQueue);
//TODO Fill up the renderQueue with models (Temp fix)
if (m_GameIsRunning) {
TEMPAddToRenderQueue();
}
// Render scene
//TODO send renderqueue to draw.
m_Renderer->Draw(m_RendererQueue);
m_EventBroker->Process<Engine>();
// Swap event queues
m_EventBroker->Swap();
glfwPollEvents();
}
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
std::shared_ptr<Systems::LevelSystem> m_LevelSystem;
//TODO: Get this out of engine.h
void TEMPAddToRenderQueue()
{
if (!m_TransformSystem)
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
for (auto &pair : *m_World->GetEntities())
{
EntityID entity = pair.first;
auto templateComponent = m_World->GetComponent<Components::Template>(entity);
if (templateComponent)
continue;
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (!transform)
continue;
auto modelComponent = m_World->GetComponent<Components::Model>(entity);
if (modelComponent)
{
Model* modelAsset = nullptr;
modelAsset = ResourceManager::Load<Model>(modelComponent->ModelFile);
if (modelAsset)
{
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
glm::mat4 modelMatrix = glm::translate(glm::mat4(), absoluteTransform.Position)
* glm::toMat4(absoluteTransform.Orientation)
* glm::scale(absoluteTransform.Scale);
EnqueueModel(modelAsset, modelMatrix, modelComponent->Transparent, modelComponent->Color, modelComponent->ModelFile);
}
}
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity);
if (pointLightComponent)
{
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
EnqueuePointLight(absoluteTransform.Position,
pointLightComponent->Diffuse,
pointLightComponent->Specular,
pointLightComponent->Radius);
}
auto parent = m_World->GetEntityParent(entity);
if(parent != 0) {
auto waterParticleComponent = m_World->GetComponent<Components::WaterVolume>(parent);
if (waterParticleComponent) {
//TODO: Remove hardcoded color.
//TODO: Do i even need modelMatrix?
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position)
* glm::scale(absoluteTransform.Scale);
EnqueueWaterParticles(absoluteTransform.Position, glm::vec4(1.f, 1.f, 1.f, 1.f), modelMatrix, absoluteTransform.Position.z);
}
}
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
if (spriteComponent)
{
std::string normal = spriteComponent->NormalTexture;
std::string spec = spriteComponent->SpecularTexture;
if (normal.empty()) {
normal = "Textures/Core/NeutralNormalMap.png";
}
if (spec.empty()) {
spec = "Textures/Core/NeutralSpecularMap.png";
}
auto texturediff = ResourceManager::Load<Texture>(spriteComponent->SpriteFile);
auto texturenorm = ResourceManager::Load<Texture>(normal);
auto texturespec = ResourceManager::Load<Texture>(spec);
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform.Orientation).z, glm::vec3(0, 0, -1));
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position)
* glm::toMat4(orientation2D)
* glm::scale(absoluteTransform.Scale);
EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color, absoluteTransform.Position.z);
}
}
}
//TODO: Get this out of engine.h
void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent, glm::vec4 color, std::string fileName)
{
for (auto texGroup : model->TextureGroups)
{
ModelJob job;
job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0;
job.DiffuseTexture = (texGroup.Texture) ? *texGroup.Texture : 0;
job.NormalTexture = (texGroup.NormalMap) ? *texGroup.NormalMap : 0;
job.SpecularTexture = (texGroup.SpecularMap) ? *texGroup.SpecularMap : 0;
job.VAO = model->VAO;
job.ElementBuffer = model->ElementBuffer;
job.StartIndex = texGroup.StartIndex;
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = modelMatrix;
job.Color = color;
m_RendererQueue.Deferred.Add(job);
}
}
// TODO: Get this out of engine.h
void EnqueueSprite(Texture* texture, Texture* normalTexture, Texture* specularTexture, glm::mat4 modelMatrix, glm::vec4 color, float depth)
{
SpriteJob job;
job.TextureID = texture->ResourceID;
job.DiffuseTexture = *texture;
job.NormalTexture = *normalTexture;
job.SpecularTexture = *specularTexture;
job.ModelMatrix = modelMatrix;
job.Color = color;
job.Depth = depth;
m_RendererQueue.Forward.Add(job);
}
void EnqueuePointLight(glm::vec3 position, glm::vec3 diffuseColor, glm::vec3 specularColor, float radius)
{
PointLightJob job;
job.Position = position;
job.DiffuseColor = diffuseColor;
job.SpecularColor = specularColor;
job.Radius = radius;
m_RendererQueue.Lights.Add(job);
}
void EnqueueWaterParticles(glm::vec3 position, glm::vec4 color, glm::mat4 modelMatrix, float depth)
{
WaterParticleJob job;
job.Position = position;
job.Color = color;
job.ModelMatrix = modelMatrix;
job.Depth = depth;
m_RendererQueue.Forward.Add(job);
}
private:
std::shared_ptr<EventBroker> m_EventBroker;
GUI::Frame* m_FrameStack = nullptr;
std::shared_ptr<Renderer> m_Renderer;
RenderQueueCollection m_RendererQueue;
std::shared_ptr<InputManager> m_InputManager;
std::shared_ptr<World> m_World;
//TODO: Redo
bool m_GameIsRunning = false;
dd::EventRelay<Engine, dd::Events::GameStart> m_EGameStart;
bool OnGameStart(const dd::Events::GameStart &event)
{
m_GameIsRunning = true;
//Todo: Move this
{
dd::Events::PlaySound e;
e.path = "Sounds/BGM/under-the-sea-instrumental.wav";
e.isAmbient = true;
m_EventBroker->Publish(e);
}
{
dd::Events::PlaySound e;
e.path = "Sounds/BGM/water-flowing.wav";
e.volume = 0.3f;
e.isAmbient = true;
m_EventBroker->Publish(e);
}
};
double m_LastTime;
};
}
+8
View File
@@ -24,6 +24,7 @@
#include <map> #include <map>
#include <unordered_map> #include <unordered_map>
#include <list> #include <list>
#include <tuple>
#define EVENT_SUBSCRIBE_MEMBER(relay, handler) \ #define EVENT_SUBSCRIBE_MEMBER(relay, handler) \
relay = decltype(relay)(std::bind(handler, this, std::placeholders::_1)); \ relay = decltype(relay)(std::bind(handler, this, std::placeholders::_1)); \
@@ -123,16 +124,23 @@ public:
void Unsubscribe(BaseEventRelay &relay); void Unsubscribe(BaseEventRelay &relay);
private: private:
bool m_IsProcessing = false;
typedef std::string ContextTypeName_t; // typeid(ContextType).name() typedef std::string ContextTypeName_t; // typeid(ContextType).name()
typedef std::string EventTypeName_t; // typeid(EventType).name() typedef std::string EventTypeName_t; // typeid(EventType).name()
typedef std::unordered_multimap<EventTypeName_t, BaseEventRelay*> EventRelays_t; typedef std::unordered_multimap<EventTypeName_t, BaseEventRelay*> EventRelays_t;
typedef std::unordered_map<ContextTypeName_t, EventRelays_t> ContextRelays_t; typedef std::unordered_map<ContextTypeName_t, EventRelays_t> ContextRelays_t;
ContextRelays_t m_ContextRelays; ContextRelays_t m_ContextRelays;
std::vector<BaseEventRelay*> m_RelaysToSubscribe;
std::vector<BaseEventRelay*> m_RelaysToUnsubscribe;
typedef std::list<std::pair<EventTypeName_t, std::shared_ptr<Event>>> EventQueue_t; typedef std::list<std::pair<EventTypeName_t, std::shared_ptr<Event>>> EventQueue_t;
std::shared_ptr<EventQueue_t> m_EventQueueRead; std::shared_ptr<EventQueue_t> m_EventQueueRead;
std::shared_ptr<EventQueue_t> m_EventQueueWrite; std::shared_ptr<EventQueue_t> m_EventQueueWrite;
void subscribeImmediate(BaseEventRelay& relay);
void unsubscribeImmediate(BaseEventRelay& relay);
}; };
template <typename EventType> template <typename EventType>
+1 -1
View File
@@ -194,7 +194,7 @@ public:
// Triggers commit events in systems // Triggers commit events in systems
// TODO: Replace completely by EComponentCreated? // TODO: Replace completely by EComponentCreated?
int CommitEntity(EntityID entity); void CommitEntity(EntityID entity);
/** Get all components of a specific type. /** Get all components of a specific type.
+14
View File
@@ -60,6 +60,10 @@ protected:
virtual bool OnMouseMove(const Events::MouseMove& event) virtual bool OnMouseMove(const Events::MouseMove& event)
{ {
if (Hidden()) {
return false;
}
bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1)); bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1));
if (isOver && !m_MouseIsOver) { // Enter if (isOver && !m_MouseIsOver) { // Enter
if (!m_IsDown) { if (!m_IsDown) {
@@ -88,6 +92,11 @@ protected:
} }
virtual bool OnMousePress(const Events::MousePress& event) virtual bool OnMousePress(const Events::MousePress& event)
{ {
if (Hidden()) {
LOG_DEBUG("Pressed hidden button");
return false;
}
if (!Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1))) { if (!Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1))) {
return false; return false;
} }
@@ -107,6 +116,11 @@ protected:
} }
virtual bool OnMouseRelease(const Events::MouseRelease& event) virtual bool OnMouseRelease(const Events::MouseRelease& event)
{ {
if (Hidden()) {
LOG_DEBUG("Released hidden button");
return false;
}
bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1)); bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1));
if (!isOver && !m_IsDown) { if (!isOver && !m_IsDown) {
return false; return false;
+42 -57
View File
@@ -1,6 +1,8 @@
#ifndef GUI_NUMBERFRAME_H__ #ifndef GUI_NUMBERFRAME_H__
#define GUI_NUMBERFRAME_H__ #define GUI_NUMBERFRAME_H__
#include <unordered_map>
#include "GUI/TextureFrame.h" #include "GUI/TextureFrame.h"
namespace dd namespace dd
@@ -14,32 +16,16 @@ public:
NumberFrame(Frame* parent, std::string name) NumberFrame(Frame* parent, std::string name)
: Frame(parent, name) : Frame(parent, name)
{ {
m_NumberTextures[0] = "Textures/GUI/Numbers/N0.png"; m_CharacterTextures['0'] = "Textures/GUI/Numbers/N0.png";
m_NumberTextures[1] = "Textures/GUI/Numbers/N1.png"; m_CharacterTextures['1'] = "Textures/GUI/Numbers/N1.png";
m_NumberTextures[2] = "Textures/GUI/Numbers/N2.png"; m_CharacterTextures['2'] = "Textures/GUI/Numbers/N2.png";
m_NumberTextures[3] = "Textures/GUI/Numbers/N3.png"; m_CharacterTextures['3'] = "Textures/GUI/Numbers/N3.png";
m_NumberTextures[4] = "Textures/GUI/Numbers/N4.png"; m_CharacterTextures['4'] = "Textures/GUI/Numbers/N4.png";
m_NumberTextures[5] = "Textures/GUI/Numbers/N5.png"; m_CharacterTextures['5'] = "Textures/GUI/Numbers/N5.png";
m_NumberTextures[6] = "Textures/GUI/Numbers/N6.png"; m_CharacterTextures['6'] = "Textures/GUI/Numbers/N6.png";
m_NumberTextures[7] = "Textures/GUI/Numbers/N7.png"; m_CharacterTextures['7'] = "Textures/GUI/Numbers/N7.png";
m_NumberTextures[8] = "Textures/GUI/Numbers/N8.png"; m_CharacterTextures['8'] = "Textures/GUI/Numbers/N8.png";
m_NumberTextures[9] = "Textures/GUI/Numbers/N9.png"; m_CharacterTextures['9'] = "Textures/GUI/Numbers/N9.png";
// Create number frame if missing
for (int i = 0; i < 10; i++) {
auto frame = new GUI::TextureFrame(this, "NumberFrameDigit");
frame->SetTexture(m_NumberTextures[0]);
frame->DisableScissor();
// Position frame based on alignment
if (i > 0) {
frame->X = i * 20;
}
Width += frame->Width;
if (Height < frame->Height) {
Height = frame->Height;
}
m_NumberFrames.push_front(frame);
}
SetNumber(0); SetNumber(0);
} }
@@ -50,41 +36,40 @@ public:
m_Number = number; m_Number = number;
// Clear number textures // Clear number textures
//for (auto& frame : m_NumberFrames) { for (auto& frame : m_NumberFrames) {
// frame->SetTexture(""); frame->SetTexture("");
//} }
//Width = 0; Width = 0;
//Height = 0; Height = 0;
int n = 0; std::string digits = std::to_string(number);
do {
// // Create number frame if missing int i = 0;
// if (m_NumberFrames.size() <= n) { for (char& c : digits) {
// auto frame = new GUI::TextureFrame(this, "NumberFrameDigit"); // Create number frame if missing
// frame->DisableScissor(); if (i >= m_NumberFrames.size()) {
// m_NumberFrames.push_front(frame); auto frame = new GUI::TextureFrame(this, "NumberFrameDigit");
// } if (i > 0) {
frame->SetLeft(m_NumberFrames[i - 1]->Right());
}
frame->DisableScissor();
m_NumberFrames.push_back(frame);
}
// Update value // Update value
int digit = number % 10; std::string texture = "Textures/Core/ErrorTexture.png";
m_NumberFrames[n]->SetTexture(m_NumberTextures[digit]); if (m_CharacterTextures.find(c) != m_CharacterTextures.end()) {
//Width += m_NumberFrames[n]->Width; texture = m_CharacterTextures.at(c);
//if (Height < m_NumberFrames[n]->Height) { }
// Height = m_NumberFrames[n]->Height; m_NumberFrames[i]->SetTexture(m_CharacterTextures.at(c));
//} Width += m_NumberFrames[i]->Width;
// // Position frame based on alignment if (Height < m_NumberFrames[i]->Height) {
// if (n > 0) { Height = m_NumberFrames[i]->Height;
// if (!m_LeftAligned) { }
// m_NumberFrames[n]->SetLeft(m_NumberFrames[n - 1]->Right());
// } else {
// m_NumberFrames[n]->SetRight(m_NumberFrames[n - 1]->Left());
// }
// }
number /= 10; i++;
n++; }
} while (number > 0);
} }
void SetLeftAlign() { m_LeftAligned = true; } void SetLeftAlign() { m_LeftAligned = true; }
@@ -99,7 +84,7 @@ private:
int m_Number = 0; int m_Number = 0;
bool m_LeftAligned = true; bool m_LeftAligned = true;
std::string m_NumberTextures[10]; std::unordered_map<char, std::string> m_CharacterTextures;
std::deque<TextureFrame*> m_NumberFrames; std::deque<TextureFrame*> m_NumberFrames;
}; };
+78 -6
View File
@@ -5,23 +5,42 @@
#include "Core/World.h" #include "Core/World.h"
#include "Core/EventBroker.h" #include "Core/EventBroker.h"
#include "Core/CTransform.h" #include "Core/CTransform.h"
#include "Core/CTemplate.h"
#include "Physics/CPhysics.h"
#include "Physics/CCircleShape.h"
#include "Physics/CRectangleShape.h"
#include "Physics/EContact.h" #include "Physics/EContact.h"
#include "Rendering/CModel.h"
#include "Rendering/CPointLight.h"
#include "Game/CBall.h" #include "Game/CBall.h"
#include "Game/CPowerUp.h" #include "Game/CPowerUp.h"
#include "Game/CLife.h"
#include "Game/CBrick.h"
#include "Game/ELifeLost.h"
#include "Game/EComboEvent.h"
#include "Game/EResetBall.h"
#include "Game/EMultiBall.h"
#include "Game/EMultiBallLost.h"
#include "Game/EGameOver.h"
#include "Game/EPause.h"
#include "Game/EHitPad.h"
#include "Game/EHitLag.h"
namespace dd { namespace dd
{
namespace Systems { namespace Systems
{
class BallSystem : public System { class BallSystem : public System
{
public: public:
BallSystem(World *world, std::shared_ptr<dd::EventBroker> eventBroker) BallSystem(World *world, std::shared_ptr<dd::EventBroker> eventBroker)
: System(world, eventBroker) { } : System(world, eventBroker) { }
~BallSystem(); ~BallSystem();
EventRelay<BallSystem, Events::Contact> m_Contact;
bool Contact(const Events::Contact &event);
void RegisterComponents(ComponentFactory *cf) override; void RegisterComponents(ComponentFactory *cf) override;
@@ -39,11 +58,64 @@ public:
// Called when an entity is removed // Called when an entity is removed
void OnEntityRemoved(EntityID entity) override; void OnEntityRemoved(EntityID entity) override;
private: EntityID CreateBall();
void CreateLife(int);
EntityID Ball() { return m_Ball; };
void SetBall(const EntityID& ball) { m_Ball = ball; }
float& XMovementMultiplier() { return m_XMovementMultiplier; }
void SetXMovementMultiplier(const float& xMovementMultiplier) { m_XMovementMultiplier = xMovementMultiplier; }
float& EdgeX() { return m_EdgeX; }
void SetEdgeX(const float& edgeX) { m_EdgeX = edgeX; }
float& EdgeY() { return m_EdgeY; }
void SetEdgeY(const float& edgeY) { m_EdgeY = edgeY; }
int& MultiBalls() { return m_MultiBalls; }
void SetMultiBalls(const int& multiBalls) { m_MultiBalls = multiBalls; }
int& Lives() { return m_Lives; }
void SetLives(const int& lives) { m_Lives = lives; }
int& PastLives() { return m_PastLives; }
void SetPastLives(const int& pastLives) { m_PastLives = pastLives; }
bool ReplaceBall() const { return m_ReplaceBall; }
void SetReplaceBall(const bool& replaceBall) { m_ReplaceBall = replaceBall; }
bool IsPaused() const { return m_Pause; }
void SetPause(const bool& pause) { m_Pause = pause; }
private:
float m_XMovementMultiplier = 2.f;
float m_EdgeX = 3.2f;
float m_EdgeY = 5.2f;
int m_MultiBalls = 0;
int m_Lives = 3;
int m_PastLives = 3;
bool m_ReplaceBall = false;
bool m_Pause = false;
EntityID m_LastCollision = 999999;
glm::vec3 m_SavedSpeed;
bool m_InitializePause = false;
EntityID m_Ball;
std::unordered_map<EntityID, std::list<glm::vec2>> m_Contacts;
void ResolveContacts();
dd::EventRelay<BallSystem, dd::Events::LifeLost> m_ELifeLost;
dd::EventRelay<BallSystem, dd::Events::MultiBallLost> m_EMultiBallLost;
dd::EventRelay<BallSystem, dd::Events::ResetBall> m_EResetBall;
dd::EventRelay<BallSystem, dd::Events::MultiBall> m_EMultiBall;
dd::EventRelay<BallSystem, dd::Events::Pause> m_EPause;
EventRelay<BallSystem, Events::Contact> m_Contact;
bool Contact(const Events::Contact &event);
bool OnLifeLost(const dd::Events::LifeLost &event);
bool OnMultiBallLost(const dd::Events::MultiBallLost &event);
bool OnResetBall(const dd::Events::ResetBall &event);
bool OnMultiBall(const dd::Events::MultiBall &event);
bool OnPause(const dd::Events::Pause &event);
}; };
} }
} }
#endif #endif
+3
View File
@@ -17,6 +17,9 @@ struct Ball : Component
{ {
int Number = 0; int Number = 0;
float Speed = 5.f; float Speed = 5.f;
int Combo = 0;
bool Paused = false;
glm::vec3 SavedSpeed = glm::vec3(0, 0, 0);
}; };
} }
+1 -2
View File
@@ -15,9 +15,8 @@ namespace Components
struct Brick : Component struct Brick : Component
{ {
int Points = 10;
int Hits = 1;
int Score = 50; int Score = 50;
int Type = 0;
bool Removed = false; bool Removed = false;
}; };
+1 -4
View File
@@ -17,12 +17,9 @@ namespace Components
struct Pad : Component struct Pad : Component
{ {
int Lives;
int Points;
float SlowdownModifier = 5.f; float SlowdownModifier = 5.f;
float AccelerationSpeed = 40.f; float AccelerationSpeed = 40.f;
float MaxSpeed = 20.f; float MaxSpeed = 5.f;
}; };
} }
+27
View File
@@ -0,0 +1,27 @@
//
// Created by Adniklastrator on 2015-09-29.
//
#ifndef DAYDREAM_ECOMBOEVENT_H
#define DAYDREAM_ECOMBOEVENT_H
#include "Core/Entity.h"
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct ComboEvent : Event
{
EntityID Ball;
int Combo;
};
}
}
#endif //DAYDREAM_ECOMBOEVENT_H
+26
View File
@@ -0,0 +1,26 @@
//
// Created by Administrator on 2015-09-30.
//
#ifndef DAYDREAM_EHITLAG_H
#define DAYDREAM_EHITLAG_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct HitLag : Event
{
float Time;
std::string Type;
};
}
}
#endif //DAYDREAM_EHITLAG_H
+21
View File
@@ -0,0 +1,21 @@
//
// Created by Administrator on 2015-10-05.
//
#ifndef DAYDREAM_EHITPAD_H
#define DAYDREAM_EHITPAD_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct HitPad : Event
{
};
}
}
#endif //DAYDREAM_EHITPAD_H
+26
View File
@@ -0,0 +1,26 @@
//
// Created by Adniklastrator on 2015-09-28.
//
#ifndef DAYDREAM_EMULTIBALLLOST_H
#define DAYDREAM_EMULTIBALLLOST_H
#include "Core/EventBroker.h"
#include "Core/Entity.h"
namespace dd
{
namespace Events
{
struct MultiBallLost : Event
{
};
}
}
#endif //DAYDREAM_EMULTIBALLLOST_H
+25
View File
@@ -0,0 +1,25 @@
//
// Created by Adniklastrator on 2015-09-30.
//
#ifndef DAYDREAM_EPAUSE_H
#define DAYDREAM_EPAUSE_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct Pause : Event
{
std::string Type;
};
}
}
#endif //DAYDREAM_EPAUSE_H
+45
View File
@@ -0,0 +1,45 @@
#ifndef GUI_FPSCOUNTER_H__
#define GUI_FPSCOUNTER_H__
#include <numeric>
#include "GUI/Frame.h"
#include "GUI/NumberFrame.h"
namespace dd
{
namespace GUI
{
class FPSCounter : public Frame
{
public:
FPSCounter(Frame* parent, std::string name)
: Frame(parent, name)
{
m_FrameTimes.resize(m_MaxSamples);
m_Numbers = new GUI::NumberFrame(this, "FPSCounterNumberFrame");
}
virtual void Update(double dt)
{
m_FrameTimes[m_CurrentFrame % m_MaxSamples] = dt;
double sum = std::accumulate(m_FrameTimes.begin(), m_FrameTimes.end(), 0.0);
sum /= std::min(m_CurrentFrame, m_MaxSamples);
m_Numbers->SetNumber(std::round(1.0 / sum));
m_CurrentFrame++;
}
private:
NumberFrame* m_Numbers = nullptr;
int m_MaxSamples = 100;
int m_CurrentFrame = 0;
std::vector<double> m_FrameTimes;
};
}
}
#endif
+16
View File
@@ -6,6 +6,7 @@
#include "GUI/NumberFrame.h" #include "GUI/NumberFrame.h"
#include "Core/EKeyUp.h" #include "Core/EKeyUp.h"
#include "Game/EScoreEvent.h" #include "Game/EScoreEvent.h"
#include "Game/FPSCounter.h"
namespace dd namespace dd
{ {
@@ -24,6 +25,15 @@ public:
m_LevelIndicator = new GUI::TextureFrame(this, "HUDLevelIndicator"); m_LevelIndicator = new GUI::TextureFrame(this, "HUDLevelIndicator");
m_LevelIndicator->SetTexture("Textures/GUI/HUD/LevelIndicatorBG.png"); m_LevelIndicator->SetTexture("Textures/GUI/HUD/LevelIndicatorBG.png");
m_AreaNumberFrame = new GUI::NumberFrame(m_LevelIndicator, "HUDScoreNumberFrameawdawdwa");
m_AreaNumberFrame->X = 132;
m_AreaNumberFrame->Y = 19;
m_AreaNumberFrame->SetNumber(6);
m_StageNumberFrame = new GUI::NumberFrame(m_LevelIndicator, "HUDScoreNumberFrameawdawdwa");
m_StageNumberFrame->X = 165;
m_StageNumberFrame->Y = 19;
m_StageNumberFrame->SetNumber(5);
m_ScoreIndicator = new GUI::TextureFrame(this, "HUDScoreIndicator"); m_ScoreIndicator = new GUI::TextureFrame(this, "HUDScoreIndicator");
m_ScoreIndicator->SetTexture("Textures/GUI/HUD/ScoreIndicatorBG.png"); m_ScoreIndicator->SetTexture("Textures/GUI/HUD/ScoreIndicatorBG.png");
m_ScoreIndicator->SetRight(Right()); m_ScoreIndicator->SetRight(Right());
@@ -31,19 +41,25 @@ public:
m_ScoreNumberFrame->X = 15; m_ScoreNumberFrame->X = 15;
m_ScoreNumberFrame->Y = 21; m_ScoreNumberFrame->Y = 21;
m_FPSCounter = new GUI::FPSCounter(this, "FPSCounter");
EVENT_SUBSCRIBE_MEMBER(m_EScore, &HUD::OnScore); EVENT_SUBSCRIBE_MEMBER(m_EScore, &HUD::OnScore);
} }
private: private:
TextureFrame* m_LevelIndicator = nullptr; TextureFrame* m_LevelIndicator = nullptr;
TextureFrame* m_ScoreIndicator = nullptr; TextureFrame* m_ScoreIndicator = nullptr;
NumberFrame* m_AreaNumberFrame = nullptr;
NumberFrame* m_StageNumberFrame = nullptr;
NumberFrame* m_ScoreNumberFrame = nullptr; NumberFrame* m_ScoreNumberFrame = nullptr;
FPSCounter* m_FPSCounter = nullptr;
EventRelay<Frame, Events::ScoreEvent> m_EScore; EventRelay<Frame, Events::ScoreEvent> m_EScore;
bool OnScore(const Events::ScoreEvent& event) bool OnScore(const Events::ScoreEvent& event)
{ {
m_ScoreNumberFrame->SetNumber(m_ScoreNumberFrame->Number() + event.Score); m_ScoreNumberFrame->SetNumber(m_ScoreNumberFrame->Number() + event.Score);
return true;
} }
}; };
+91
View File
@@ -0,0 +1,91 @@
//
// Created by Adniklastrator on 2015-09-30.
//
#ifndef DAYDREAM_HITLAGSYSTEM_H
#define DAYDREAM_HITLAGSYSTEM_H
#include "Core/System.h"
#include "Core/CTransform.h"
#include "Core/CTemplate.h"
#include "Core/EventBroker.h"
#include "Core/World.h"
#include "Rendering/CSprite.h"
#include "Rendering/CModel.h"
#include "Game/CBrick.h"
#include "Game/CBall.h"
#include "Game/CLife.h"
#include "Game/CPowerUp.h"
#include "Game/EStageCleared.h"
#include "Game/ELifeLost.h"
#include "Game/EResetBall.h"
#include "Game/EScoreEvent.h"
#include "Game/EComboEvent.h"
#include "Game/EMultiBall.h"
#include "Game/EMultiBallLost.h"
#include "Game/EPause.h"
#include "Game/EHitLag.h"
#include "Game/EGameOver.h"
#include "Game/ECreatePowerUp.h"
#include "Game/EPowerUpTaken.h"
#include "Game/Bricks/CPowerUpBrick.h"
#include "Physics/CPhysics.h"
#include "Physics/CCircleShape.h"
#include "Physics/CRectangleShape.h"
#include "Physics/ESetImpulse.h"
#include "Physics/EContact.h"
#include "Sound/CCollisionSound.h"
#include "Game/PadSystem.h"
#include <fstream>
#include <iostream>
namespace dd
{
namespace Systems
{
class HitLagSystem : public System
{
public:
HitLagSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
: System(world, eventBroker)
{ }
void Initialize() override;
void Update(double dt) override;
void FlipPause();
bool IsPaused() const { return m_Pause; }
void SetPause(const bool& pause) { m_Pause = pause; }
bool HitLag() const { return m_HitLag; }
void SetHitLag(const bool& hitLag) { m_HitLag = hitLag; }
float& HitLagDuration() { return m_HitLagDuration; }
void SetHitLagDuration(const float& hitLagDuration) { m_HitLagDuration = hitLagDuration; }
float& HitLagTimer() { return m_HitLagTimer; }
void SetHitLagTimer(const float& hitLagTimer) { m_HitLagTimer = hitLagTimer; }
std::string& CurrentType() { return m_CurrentType; }
void SetCurrentType(const std::string& currentType) { m_CurrentType = currentType; }
private:
bool m_Pause;
bool m_HitLag;
float m_HitLagDuration;
float m_HitLagTimer;
std::string m_CurrentType;
dd::EventRelay<HitLagSystem, dd::Events::Pause> m_EPause;
dd::EventRelay<HitLagSystem, dd::Events::HitLag> m_EHitLag;
bool OnPause(const dd::Events::Pause &event);
bool OnHitLag(const dd::Events::HitLag &event);
};
}
}
#endif //DAYDREAM_HITLAGSYSTEM_H
+41 -28
View File
@@ -7,6 +7,7 @@
#include "Core/System.h" #include "Core/System.h"
#include "Core/CTransform.h" #include "Core/CTransform.h"
#include "Core/CTemplate.h"
#include "Core/EventBroker.h" #include "Core/EventBroker.h"
#include "Core/World.h" #include "Core/World.h"
#include "Rendering/CSprite.h" #include "Rendering/CSprite.h"
@@ -19,21 +20,24 @@
#include "Game/ELifeLost.h" #include "Game/ELifeLost.h"
#include "Game/EResetBall.h" #include "Game/EResetBall.h"
#include "Game/EScoreEvent.h" #include "Game/EScoreEvent.h"
#include "Physics/CRectangleShape.h" #include "Game/EComboEvent.h"
#include "Game/EHitPad.h"
#include "Game/EMultiBall.h" #include "Game/EMultiBall.h"
#include "Game/EMultiBallLost.h"
#include "Game/EPause.h"
#include "Game/EGameOver.h" #include "Game/EGameOver.h"
#include "Game/ECreatePowerUp.h" #include "Game/ECreatePowerUp.h"
#include "Game/EPowerUpTaken.h" #include "Game/EPowerUpTaken.h"
#include "Game/Bricks/CPowerUpBrick.h" #include "Game/Bricks/CPowerUpBrick.h"
#include "Physics/CPhysics.h" #include "Physics/CPhysics.h"
#include "Physics/CCircleShape.h" #include "Physics/CCircleShape.h"
#include "Physics/CRectangleShape.h"
#include "Physics/ESetImpulse.h" #include "Physics/ESetImpulse.h"
#include "Physics/EContact.h" #include "Physics/EContact.h"
#include "Sound/CCollisionSound.h" #include "Sound/CCollisionSound.h"
#include "Game/PadSystem.h" #include "Game/PadSystem.h"
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <intrin.h>
namespace dd namespace dd
{ {
@@ -42,15 +46,15 @@ namespace Systems
{ {
// Me trying things out. // Me trying things out.
class Level /*class Level
{ {
public: public:
int levelRows; int levelRows = 6;
int levelLines; int levelLines = 7;
int levelSpaceBetweenBricks; glm::vec2 levelSpaceBetweenBricks = glm::vec2(1, 0.4);
int levelSpaceToEdge; float levelSpaceToEdge = 0.25f;
int bricks[]; std::array<int, 42> bricks;
}; };*/
class LevelSystem : public System class LevelSystem : public System
{ {
@@ -62,11 +66,8 @@ public:
void Initialize() override; void Initialize() override;
void CreateBasicLevel(int, int, glm::vec2, float); void CreateBasicLevel(int, int, glm::vec2, float);
void CreateLife(int); void CreateLevel();
void SaveLevel(int, int, glm::vec2, int); // Shouldn't be here, but I'm experimenting. void CreateBrick(int, int, glm::vec2, float, int, int);
void LoadLevel(char[20]);
void CreateBrick(int, int, glm::vec2, float, int);
void ProcessCollision();
void OnEntityRemoved(EntityID entity); void OnEntityRemoved(EntityID entity);
@@ -79,10 +80,8 @@ public:
void SetRestarting(const bool& restarting) { m_Restarting = restarting; } void SetRestarting(const bool& restarting) { m_Restarting = restarting; }
bool Initialized() const { return m_Initialized; } bool Initialized() const { return m_Initialized; }
void SetInitialized(const bool& initialized) { m_Initialized = initialized; } void SetInitialized(const bool& initialized) { m_Initialized = initialized; }
int& Lives() { return m_Lives; } bool IsPaused() const { return m_Pause; }
void SetLives(const int& lives) { m_Lives = lives; } void SetPause(const bool& pause) { m_Pause = pause; }
int& PastLives() { return m_PastLives; }
void SetPastLives(const int& pastLives) { m_PastLives = pastLives; }
int& MultiBalls() { return m_MultiBalls; } int& MultiBalls() { return m_MultiBalls; }
void SetMultiBalls(const int& multiBalls) { m_MultiBalls = multiBalls; } void SetMultiBalls(const int& multiBalls) { m_MultiBalls = multiBalls; }
int& PowerUps() { return m_PowerUps; } int& PowerUps() { return m_PowerUps; }
@@ -100,16 +99,17 @@ public:
glm::vec2& SpaceBetweenBricks() { return m_SpaceBetweenBricks; } glm::vec2& SpaceBetweenBricks() { return m_SpaceBetweenBricks; }
void SetSpaceBetweenBricks(const glm::vec2& spaceBetweenBricks) { m_SpaceBetweenBricks = spaceBetweenBricks; } void SetSpaceBetweenBricks(const glm::vec2& spaceBetweenBricks) { m_SpaceBetweenBricks = spaceBetweenBricks; }
float& EdgeX() { return m_EdgeX; } float& NotResettingTheStage() { return m_NotResettingTheStage; }
void SetEdgeX(const float& edgeX) { m_EdgeX = edgeX; } void SetNotResettingTheStage(const float& notResettingTheStage) { m_NotResettingTheStage = notResettingTheStage; }
float& EdgeY() { return m_EdgeY; }
void SetEdgeY(const float& edgeY) { m_EdgeY = edgeY; }
private: private:
bool m_Cleared = false;
bool m_Restarting = false; bool m_Restarting = false;
bool m_Initialized = false; bool m_Initialized = false;
int m_Lives = 3; bool m_Pause = false;
int m_PastLives = 3; int m_LooseBricks = 0;
int m_CurrentCluster = 2;
int m_CurrentLevel = 1;
int m_MultiBalls = 0; int m_MultiBalls = 0;
int m_PowerUps = 0; int m_PowerUps = 0;
int m_Score = 0; int m_Score = 0;
@@ -118,24 +118,37 @@ private:
int m_Lines = 7; int m_Lines = 7;
float m_SpaceToEdge = 0.25f; float m_SpaceToEdge = 0.25f;
glm::vec2 m_SpaceBetweenBricks = glm::vec2(1, 0.4); glm::vec2 m_SpaceBetweenBricks = glm::vec2(1, 0.4);
float m_EdgeX = 3.2f; float m_NotResettingTheStage = 5.f;
float m_EdgeY = 5.2f;
const int EmptyBrickSpace = 0;
const int StandardBrick = 1;
const int MultiBallBrick = 2;
EntityID m_BrickTemplate;
std::array<int, 42> m_Bricks;
dd::EventRelay<LevelSystem, dd::Events::Contact> m_EContact; dd::EventRelay<LevelSystem, dd::Events::Contact> m_EContact;
dd::EventRelay<LevelSystem, dd::Events::LifeLost> m_ELifeLost;
dd::EventRelay<LevelSystem, dd::Events::ScoreEvent> m_EScoreEvent; dd::EventRelay<LevelSystem, dd::Events::ScoreEvent> m_EScoreEvent;
dd::EventRelay<LevelSystem, dd::Events::MultiBall> m_EMultiBall; dd::EventRelay<LevelSystem, dd::Events::MultiBall> m_EMultiBall;
dd::EventRelay<LevelSystem, dd::Events::MultiBallLost> m_EMultiBallLost;
dd::EventRelay<LevelSystem, dd::Events::CreatePowerUp> m_ECreatePowerUp; dd::EventRelay<LevelSystem, dd::Events::CreatePowerUp> m_ECreatePowerUp;
dd::EventRelay<LevelSystem, dd::Events::PowerUpTaken> m_EPowerUpTaken; dd::EventRelay<LevelSystem, dd::Events::PowerUpTaken> m_EPowerUpTaken;
dd::EventRelay<LevelSystem, dd::Events::StageCleared> m_EStageCleared; dd::EventRelay<LevelSystem, dd::Events::StageCleared> m_EStageCleared;
dd::EventRelay<LevelSystem, dd::Events::Pause> m_EPause;
dd::EventRelay<LevelSystem, dd::Events::HitPad> m_EHitPad;
bool OnContact(const dd::Events::Contact &event); bool OnContact(const dd::Events::Contact &event);
bool OnLifeLost(const dd::Events::LifeLost &event);
bool OnScoreEvent(const dd::Events::ScoreEvent &event); bool OnScoreEvent(const dd::Events::ScoreEvent &event);
bool OnMultiBall(const dd::Events::MultiBall &event); bool OnMultiBall(const dd::Events::MultiBall &event);
bool OnMultiBallLost(const dd::Events::MultiBallLost &event);
bool OnCreatePowerUp(const dd::Events::CreatePowerUp &event); bool OnCreatePowerUp(const dd::Events::CreatePowerUp &event);
bool OnPowerUpTaken(const dd::Events::PowerUpTaken &event); bool OnPowerUpTaken(const dd::Events::PowerUpTaken &event);
bool OnStageCleared(const dd::Events::StageCleared &event); bool OnStageCleared(const dd::Events::StageCleared &event);
bool OnPause(const dd::Events::Pause &event);
bool OnHitPad(const dd::Events::HitPad &event);
void GetNextLevel();
}; };
} }
+4 -4
View File
@@ -61,15 +61,15 @@ private:
{ {
if (event.Slider == m_SFXSlider) { if (event.Slider == m_SFXSlider) {
Events::MasterVolume e; Events::MasterVolume e;
e.isAmbient = false; e.IsAmbient = false;
e.gain = event.Percentage; e.Gain = event.Percentage;
EventBroker->Publish(e); EventBroker->Publish(e);
} }
if (event.Slider == m_BGMSlider) { if (event.Slider == m_BGMSlider) {
Events::MasterVolume e; Events::MasterVolume e;
e.isAmbient = true; e.IsAmbient = true;
e.gain = event.Percentage; e.Gain = event.Percentage;
EventBroker->Publish(e); EventBroker->Publish(e);
} }
+19 -14
View File
@@ -9,6 +9,7 @@
#include "Core/System.h" #include "Core/System.h"
#include "Core/Component.h" #include "Core/Component.h"
#include "Core/CTransform.h" #include "Core/CTransform.h"
#include "Core/CTemplate.h"
#include "Core/EventBroker.h" #include "Core/EventBroker.h"
#include "Core/EKeyDown.h" #include "Core/EKeyDown.h"
#include "Core/EKeyUp.h" #include "Core/EKeyUp.h"
@@ -27,6 +28,8 @@
#include "Game/EMultiBall.h" #include "Game/EMultiBall.h"
#include "Game/EPowerUpTaken.h" #include "Game/EPowerUpTaken.h"
#include "Game/EStageCleared.h" #include "Game/EStageCleared.h"
#include "Game/EPause.h"
#include "Game/EHitLag.h"
namespace dd namespace dd
@@ -45,8 +48,6 @@ public:
void Update(double dt) override; void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override; void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
EntityID CreateBall();
EntityID& Entity() { return m_Entity; } EntityID& Entity() { return m_Entity; }
void SetEntity(const EntityID& ent) { m_Entity = ent; } void SetEntity(const EntityID& ent) { m_Entity = ent; }
glm::vec3 Acceleration() const { return m_Acceleration; } glm::vec3 Acceleration() const { return m_Acceleration; }
@@ -56,39 +57,43 @@ public:
void SetLeft(const bool& left) { m_Left = left; } void SetLeft(const bool& left) { m_Left = left; }
bool Right() const { return m_Right; } bool Right() const { return m_Right; }
void SetRight(const bool& right) { m_Right = right; } void SetRight(const bool& right) { m_Right = right; }
bool ReplaceBall() const { return m_ReplaceBall; } float Edge() const { return m_Edge; }
void SetReplaceBall(const bool& replaceBall) { m_ReplaceBall = replaceBall; } void SetEdge(const float& edge) { m_Edge = edge; }
bool MultiBall() const { return m_MultiBall; }
void SetMultiBall(const bool& multiBall) { m_MultiBall = multiBall; }
Components::Transform* Transform() const { return m_Transform; } Components::Transform* Transform() const { return m_Transform; }
void SetTransform(Components::Transform* transform) { m_Transform = transform; } void SetTransform(Components::Transform* transform) { m_Transform = transform; }
Components::Pad* Pad() const { return m_Pad; } Components::Pad* Pad() const { return m_Pad; }
void SetPad(Components::Pad* pad) { m_Pad = pad; } void SetPad(Components::Pad* pad) { m_Pad = pad; }
bool IsPaused() const { return m_Pause; }
void SetPause(const bool& pause) { m_Pause = pause; }
private: private:
EntityID m_Entity = 0; EntityID m_Entity = 0;
glm::vec3 m_Acceleration = glm::vec3(0.f, 0.f, 0.f); glm::vec3 m_Acceleration = glm::vec3(0.f, 0.f, 0.f);
bool m_Left = false, m_Right = false, m_ReplaceBall = false, m_MultiBall = false; bool m_Left = false;
Components::Transform* m_Transform; bool m_Right = false;
Components::Pad* m_Pad; bool m_ReplaceBall = false;
bool m_MultiBall = false;
float m_Edge = 2.8f;
Components::Transform* m_Transform = nullptr;
Components::Pad* m_Pad = nullptr;
bool m_Pause = false;
dd::EventRelay<PadSystem, dd::Events::KeyDown> m_EKeyDown; dd::EventRelay<PadSystem, dd::Events::KeyDown> m_EKeyDown;
dd::EventRelay<PadSystem, dd::Events::KeyUp> m_EKeyUp; dd::EventRelay<PadSystem, dd::Events::KeyUp> m_EKeyUp;
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContact; dd::EventRelay<PadSystem, dd::Events::Contact> m_EContact;
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContactPowerUp; dd::EventRelay<PadSystem, dd::Events::Contact> m_EContactPowerUp;
dd::EventRelay<PadSystem, dd::Events::ResetBall> m_EResetBall;
dd::EventRelay<PadSystem, dd::Events::MultiBall> m_EMultiBall;
dd::EventRelay<PadSystem, dd::Events::StageCleared> m_EStageCleared; dd::EventRelay<PadSystem, dd::Events::StageCleared> m_EStageCleared;
dd::EventRelay<PadSystem, dd::Events::Pause> m_EPause;
bool OnKeyDown(const dd::Events::KeyDown &event); bool OnKeyDown(const dd::Events::KeyDown &event);
bool OnKeyUp(const dd::Events::KeyUp &event); bool OnKeyUp(const dd::Events::KeyUp &event);
bool OnContact(const dd::Events::Contact &event); bool OnContact(const dd::Events::Contact &event);
bool OnContactPowerUp(const dd::Events::Contact &event); bool OnContactPowerUp(const dd::Events::Contact &event);
bool OnResetBall(const dd::Events::ResetBall &event);
bool OnMultiBall(const dd::Events::MultiBall &event);
bool OnStageCleared(const dd::Events::StageCleared &event); bool OnStageCleared(const dd::Events::StageCleared &event);
bool OnPause(const dd::Events::Pause &event);
class PadSteeringInputController; class PadSteeringInputController;
std::array<std::shared_ptr<PadSteeringInputController>, 4> m_PadInputControllers; std::array<std::shared_ptr<PadSteeringInputController>, 4> m_PadInputControllers;
+1 -1
View File
@@ -10,7 +10,7 @@ namespace Components
struct CircleShape : public Component struct CircleShape : public Component
{ {
// Circles are circles float Radius = 1.f;
}; };
} }
+38 -38
View File
@@ -7,24 +7,24 @@ namespace dd {
namespace ParticleFlags { namespace ParticleFlags {
enum Type { enum Type {
waterParticle = 0, Water = 0,
zombieParticle = 1 << 1, Zombie = 1 << 1,
wallParticle = 1 << 2, Wall = 1 << 2,
springParticle = 1 << 3, Spring = 1 << 3,
elasticParticle = 1 << 4, Elastic = 1 << 4,
viscousParticle = 1 << 5, Viscous = 1 << 5,
powderParticle = 1 << 6, Powder = 1 << 6,
tensileParticle = 1 << 7, Tensile = 1 << 7,
colorMixingParticle = 1 << 8, ColorMixing = 1 << 8,
destructionListenerParticle = 1 << 9, DestructionListener = 1 << 9,
barrierParticle = 1 << 10, Barrier = 1 << 10,
staticPressureParticle = 1 << 11, StaticPressure = 1 << 11,
reactiveParticle = 1 << 12, Reactive = 1 << 12,
repulsiveParticle = 1 << 13, Repulsive = 1 << 13,
fixtureContactListenerParticle = 1 << 14, FixtureContactListener = 1 << 14,
particleContactListenerParticle = 1 << 15, ParticleContactListener = 1 << 15,
fixtureContactFilterParticle = 1 << 16, FixtureContactFilter = 1 << 16,
particleContactFilterParticle = 1 << 17 ParticleContactFilter = 1 << 17
}; };
} }
@@ -36,26 +36,26 @@ struct Particle : public Component
float Radius = 0.5f; float Radius = 0.5f;
float LifeTime = 5.0f; float LifeTime = 5.0f;
ParticleFlags::Type Flags = ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>(
ParticleFlags::Type::waterParticle | ParticleFlags::Water
ParticleFlags::Type::zombieParticle | | ParticleFlags::Zombie
ParticleFlags::Type::wallParticle | | ParticleFlags::Wall
ParticleFlags::Type::springParticle | | ParticleFlags::Spring
ParticleFlags::Type::elasticParticle | | ParticleFlags::Elastic
ParticleFlags::Type::viscousParticle | | ParticleFlags::Viscous
ParticleFlags::Type::powderParticle | | ParticleFlags::Powder
ParticleFlags::Type::tensileParticle | | ParticleFlags::Tensile
ParticleFlags::Type::colorMixingParticle | | ParticleFlags::ColorMixing
ParticleFlags::Type::destructionListenerParticle | | ParticleFlags::DestructionListener
ParticleFlags::Type::barrierParticle | | ParticleFlags::Barrier
ParticleFlags::Type::staticPressureParticle | | ParticleFlags::StaticPressure
ParticleFlags::Type::reactiveParticle | | ParticleFlags::Reactive
ParticleFlags::Type::repulsiveParticle | | ParticleFlags::Repulsive
ParticleFlags::Type::fixtureContactListenerParticle | | ParticleFlags::FixtureContactListener
ParticleFlags::Type::particleContactListenerParticle | | ParticleFlags::ParticleContactListener
ParticleFlags::Type::fixtureContactFilterParticle | | ParticleFlags::FixtureContactFilter
ParticleFlags::Type::particleContactFilterParticle; | ParticleFlags::ParticleContactFilter
);
}; };
} }
+1 -1
View File
@@ -20,7 +20,7 @@ struct ParticleEmitter : public Component
float Speed = 2.f; float Speed = 2.f;
double LifeTime = 100; double LifeTime = 100;
//ParticleSystem variables //System variables
float GravityScale = 1.0f; float GravityScale = 1.0f;
}; };
+25 -9
View File
@@ -18,23 +18,39 @@ enum Type
Wall = 1 << 6 Wall = 1 << 6
}; };
} }
namespace CollisionType
{
enum Type
{
Static = 0,
Kinematic = 1,
Dynamic = 2,
};
}
namespace Components namespace Components
{ {
struct Physics: public Component struct Physics: public Component
{ {
bool Static = true; CollisionType::Type CollisionType = CollisionType::Type::Static;
bool Calculate = false; bool Calculate = false;
float GravityScale = 0.f; float GravityScale = 0.f;
CollisionLayer::Type Category = CollisionLayer::Type::Other; CollisionLayer::Type Category = CollisionLayer::Type::Other;
CollisionLayer::Type Mask = CollisionLayer::Type Mask = static_cast<CollisionLayer::Type>(
CollisionLayer::Type::Pad | CollisionLayer::Pad
CollisionLayer::Type::Ball | | CollisionLayer::Ball
CollisionLayer::Type::Brick | | CollisionLayer::Brick
CollisionLayer::Type::Water | | CollisionLayer::Water
CollisionLayer::Type::PowerUp | | CollisionLayer::PowerUp
CollisionLayer::Type::Wall | | CollisionLayer::Wall
CollisionLayer::Type::Other; | CollisionLayer::Other
);
}; };
} }
+1 -1
View File
@@ -10,7 +10,7 @@ namespace Components
struct RectangleShape : public Component struct RectangleShape : public Component
{ {
glm::vec2 Dimensions = glm::vec2(1.f, 1.f);
}; };
} }
+1 -1
View File
@@ -26,7 +26,7 @@ struct CreateParticleSequence : public Event
//Particle //Particle
std::string SpriteFile = "Texures/Core/ErrorTexture.png"; std::string SpriteFile = "Texures/Core/ErrorTexture.png";
double ParticleLifeTime = 3.f; double ParticleLifeTime = 3.f;
ParticleFlags::Type Flags = ParticleFlags::Type::powderParticle | ParticleFlags::Type::particleContactFilterParticle | ParticleFlags::Type::fixtureContactFilterParticle; ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>(ParticleFlags::Powder | ParticleFlags::ParticleContactFilter | ParticleFlags::FixtureContactFilter);
float Radius = 1.f; float Radius = 1.f;
}; };
+74 -100
View File
@@ -2,30 +2,35 @@
#define DAYDREAM_PHYSICSSYSTEM_H #define DAYDREAM_PHYSICSSYSTEM_H
#include <unordered_map> #include <unordered_map>
#include <random>
#include <glm/gtc/quaternion.hpp> #include <Box2D/Box2D.h>
#include "Core/System.h" #include "Core/System.h"
#include "Core/World.h" #include "Core/World.h"
#include "CRectangleShape.h"
#include "Physics/CPhysics.h"
#include <Box2D/Box2D.h>
#include "Core/CTransform.h"
#include "Transform/TransformSystem.h"
#include "Physics/EContact.h"
#include "Physics/ESetImpulse.h"
#include "Physics/ECreateParticleSequence.h"
#include "Physics/CCircleShape.h"
#include "Core/EventBroker.h" #include "Core/EventBroker.h"
#include "Game/CPad.h"
#include "Physics/CWaterVolume.h"
#include "Game/CBall.h"
#include "Rendering/CSprite.h"
#include "Physics/CParticle.h"
#include "Physics/CParticleEmitter.h"
#include "Core/CTemplate.h" #include "Core/CTemplate.h"
#include "Physics/CRectangleShape.h"
#include "Physics/CCircleShape.h"
#include "Physics/CPhysics.h"
#include "Physics/CWaterVolume.h"
#include "Core/CTransform.h"
#include "Transform/TransformSystem.h"
#include "CRectangleShape.h"
#include "Physics/CPhysics.h"
#include "Physics/EContact.h"
#include "Physics/ESetImpulse.h"
#include "Physics/CParticle.h"
#include "Physics/ECreateParticleSequence.h"
#include "Physics/CCircleShape.h"
#include "Physics/CParticleEmitter.h"
#include "Game/CPad.h"
#include "Game/CPad.h"
#include "Game/CBall.h"
#include "Transform/TransformSystem.h"
#include "Rendering/CSprite.h"
#include "Core/CTemplate.h"
#include "Game/EPause.h"
namespace dd namespace dd
{ {
@@ -33,7 +38,6 @@ namespace dd
namespace Systems namespace Systems
{ {
class PhysicsSystem : public System class PhysicsSystem : public System
{ {
friend class ContractListener; friend class ContractListener;
@@ -45,58 +49,64 @@ public:
~PhysicsSystem(); ~PhysicsSystem();
EventRelay<PhysicsSystem, Events::SetImpulse> m_SetImpulse;
bool SetImpulse(const Events::SetImpulse &event);
EventRelay<PhysicsSystem, Events::CreateParticleSequence> m_ECreateParticleSequence; EventRelay<PhysicsSystem, Events::CreateParticleSequence> m_ECreateParticleSequence;
bool CreateParticleSequence(const Events::CreateParticleSequence &event); bool CreateParticleSequence(const Events::CreateParticleSequence &event);
void RegisterComponents(ComponentFactory* cf) override; void RegisterComponents(ComponentFactory* cf) override;
void Initialize() override; void Initialize() override;
// Called once per system every tick
void Update(double dt) override; void Update(double dt) override;
// Called once for every entity in the world every tick
void UpdateEntity(double dt, EntityID entity, EntityID parent) override; void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
// Called when components are committed to an entity
void OnEntityCommit(EntityID entity) override; void OnEntityCommit(EntityID entity) override;
// Called when an entity is removed
void OnEntityRemoved(EntityID entity) override; void OnEntityRemoved(EntityID entity) override;
private: private:
b2Vec2 m_Gravity; struct Impulse
b2World* m_PhysicsWorld; {
float m_TimeStep; b2Body* Body;
float m_Accumulator; b2Vec2 Vector;
b2Vec2 Point;
int m_VelocityIterations, m_PositionIterations; };
bool m_Pause = false;
std::mt19937 gen; std::mt19937 gen;
std::unordered_map<EntityID, b2Body*> m_EntitiesToBodies;
std::unordered_map<b2Body*, EntityID> m_BodiesToEntities;
void CreateBody(EntityID entity); b2Vec2 m_Gravity = b2Vec2(0.f, -9.82f);
b2World* m_PhysicsWorld = nullptr;
float m_TimeStep = 1.f/60.f;
float m_Accumulator = 0.f;
int m_VelocityIterations = 6;
int m_PositionIterations = 2;
b2ParticleSystem* m_WaterParticleSystem; b2ParticleSystem* m_WaterParticleSystem;
std::vector<b2ParticleGroup*> t_ParticleGroup; std::vector<b2ParticleGroup*> t_ParticleGroup;
std::unordered_map<EntityID, const b2ParticleHandle*> m_EntitiesToWaterParticleHandle;
std::unordered_map<const b2ParticleHandle*, EntityID> m_WaterParticleHandleToEntities; std::unordered_map<const b2ParticleHandle*, EntityID> m_WaterParticleHandleToEntities;
std::unordered_map<EntityID, const b2ParticleHandle*> m_EntitiesToWaterParticleHandle;
std::vector<std::unordered_map<EntityID, const b2ParticleHandle*>> m_EntitiesToParticleHandle; std::vector<std::unordered_map<EntityID, const b2ParticleHandle*>> m_EntitiesToParticleHandle;
std::vector<std::unordered_map<const b2ParticleHandle*, EntityID>> m_ParticleHandleToEntities; std::vector<std::unordered_map<const b2ParticleHandle*, EntityID>> m_ParticleHandleToEntities;
std::unordered_map<EntityID, b2Body*> m_EntitiesToBodies;
std::unordered_map<b2Body*, EntityID> m_BodiesToEntities;
b2ParticleSystem* CreateParticleSystem(float radius, float gravityScale, int maxCount);
void CreateBody(EntityID entity);
void SyncEntitiesWithBodies();
void SyncBodiesWithEntities();
void InitializeWater(); void InitializeWater();
void CreateParticleGroup(EntityID entity); void CreateParticleGroup(EntityID entity);
b2ParticleSystem* CreateParticleSystem(float radius, float gravityScale, int maxCount);
void CreateParticleEmitter(EntityID entity); void CreateParticleEmitter(EntityID entity);
void UpdateParticleEmitters(double dt); //TODO: Remove them and particles if needed. void UpdateParticleEmitters(double dt); //TODO: Remove them and particles if needed.
EventRelay<PhysicsSystem, Events::SetImpulse> m_SetImpulse;
bool SetImpulse(const Events::SetImpulse &event);
dd::EventRelay<PhysicsSystem, dd::Events::Pause> m_EPause;
bool OnPause(const dd::Events::Pause &event);
//TODO: Fill struct with info needed. //TODO: Fill struct with info needed.
struct ParticleEmitter struct ParticleEmitter //TODO CHANGE NAMES
{ {
std::vector<b2ParticleSystem*> ParticleSystem; std::vector<b2ParticleSystem*> ParticleSystem;
std::vector<EntityID> ParticleEmitter; std::vector<EntityID> ParticleEmitter;
@@ -104,15 +114,9 @@ private:
}; };
ParticleEmitter m_ParticleEmitters; ParticleEmitter m_ParticleEmitters;
//TODO: Struct med listor är bättre än en lista med structs
struct Impulse
{
b2Body* Body;
b2Vec2 Impulse;
b2Vec2 Point;
};
std::list<Impulse> m_Impulses; std::list<Impulse> m_Impulses;
class DestructionListener : public b2DestructionListener class DestructionListener : public b2DestructionListener
{ {
public: public:
@@ -127,7 +131,7 @@ private:
LOG_INFO("Particle ded"); LOG_INFO("Particle ded");
b2ParticleHandle* handle = particleSystem->GetParticleHandleFromIndex(index); const b2ParticleHandle* handle = particleSystem->GetParticleHandleFromIndex(index);
for (int i = 0; i < m_PhysicsSystem->m_ParticleEmitters.ParticleSystem.size(); i++) { for (int i = 0; i < m_PhysicsSystem->m_ParticleEmitters.ParticleSystem.size(); i++) {
if(m_PhysicsSystem->m_ParticleEmitters.ParticleSystem[i] == particleSystem) { if(m_PhysicsSystem->m_ParticleEmitters.ParticleSystem[i] == particleSystem) {
std::unordered_map<const b2ParticleHandle*, EntityID>::iterator it = m_PhysicsSystem->m_ParticleHandleToEntities[i].find(handle); std::unordered_map<const b2ParticleHandle*, EntityID>::iterator it = m_PhysicsSystem->m_ParticleHandleToEntities[i].find(handle);
@@ -144,56 +148,6 @@ private:
PhysicsSystem* m_PhysicsSystem; PhysicsSystem* m_PhysicsSystem;
}; };
class ContactListener : public b2ContactListener
{
public:
ContactListener(PhysicsSystem* physicsSystem)
: m_PhysicsSystem(physicsSystem) { }
void BeginContact(b2Contact* contact)
{
b2WorldManifold worldManifold;
contact->GetWorldManifold(&worldManifold);
Events::Contact e;
e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
e.Normal = glm::normalize(glm::vec2(contact->GetManifold()->localNormal.x, contact->GetManifold()->localNormal.y));
e.SignificantNormal = glm::normalize((glm::abs(e.Normal.x) > glm::abs(e.Normal.y)) ? glm::vec2(e.Normal.x, 0) : glm::vec2(0, e.Normal.y));
m_PhysicsSystem->EventBroker->Publish(e);
}
void EndContact(b2Contact* contact)
{
}
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
{
EntityID entityA = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
EntityID entityB = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
auto physicsComponentA = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityA);
auto physicsComponentB = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityB);
if (physicsComponentA != nullptr && physicsComponentB != nullptr) {
if (physicsComponentA->Calculate || physicsComponentB->Calculate) {
// Turn of collisions
contact->SetEnabled(false);
}
}
}
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
{
}
private:
PhysicsSystem* m_PhysicsSystem;
};
class ParticleContactDisabler : public b2ContactFilter class ParticleContactDisabler : public b2ContactFilter
{ {
public: public:
@@ -211,12 +165,32 @@ private:
}; };
class ContactListener : public b2ContactListener
{
public:
ContactListener(PhysicsSystem* physicsSystem)
: m_PhysicsSystem(physicsSystem) { }
void BeginContact(b2Contact* contact);
void EndContact(b2Contact* contact);
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
private:
PhysicsSystem* m_PhysicsSystem;
};
DestructionListener* m_DestructionListener; DestructionListener* m_DestructionListener;
ParticleContactDisabler m_ParticleContactDisabler; ParticleContactDisabler m_ParticleContactDisabler;
ContactListener* m_ContactListener; ContactListener* m_ContactListener;
}; };
} }
} }
#endif //DAYDREAM_PHYSICSSYSTEM_H #endif
-149
View File
@@ -1,149 +0,0 @@
#ifndef DAYDREAM_PHYSICSSYSTEM_H
#define DAYDREAM_PHYSICSSYSTEM_H
#include <unordered_map>
#include "Core/System.h"
#include "Core/World.h"
#include "CRectangleShape.h"
#include "Physics/CPhysics.h"
#include <Box2D/Box2D.h>
#include "Core/CTransform.h"
#include "Transform/TransformSystem.h"
#include "Physics/EContact.h"
#include "Physics/ESetImpulse.h"
#include "Physics/CCircleShape.h"
#include "Core/EventBroker.h"
#include "Game/CPad.h"
<<<<<<< HEAD
#include "Game/CBall.h"
=======
#include "Physics/CWaterVolume.h"
#include "Rendering/CSprite.h"
>>>>>>> origin/master
namespace dd
{
namespace Systems
{
class PhysicsSystem : public System
{
friend class ContractListener;
public:
PhysicsSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
: System(world, eventBroker) {}
~PhysicsSystem();
EventRelay<PhysicsSystem, Events::SetImpulse> m_SetImpulse;
bool SetImpulse(const Events::SetImpulse &event);
void RegisterComponents(ComponentFactory* cf) override;
void Initialize() override;
// Called once per system every tick
void Update(double dt) override;
// Called once for every entity in the world every tick
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
// Called when components are committed to an entity
void OnEntityCommit(EntityID entity) override;
// Called when an entity is removed
void OnEntityRemoved(EntityID entity) override;
private:
b2Vec2 m_Gravity;
b2World* m_PhysicsWorld;
float m_TimeStep;
float m_Accumulator;
int m_VelocityIterations, m_PositionIterations;
std::unordered_map<EntityID, b2Body*> m_EntitiesToBodies;
std::unordered_map<b2Body*, EntityID> m_BodiesToEntities;
void CreateBody(EntityID entity);
b2ParticleSystem *m_ParticleSystem;
b2ParticleGroup* t_watergroup;
std::unordered_map<EntityID, const b2ParticleHandle*> m_EntitiesToParticleHandle;
std::unordered_map<const b2ParticleHandle*, EntityID> m_ParticleHandleToEntities;
void InitializeWater();
void SyncWater(); //TODO: Probably remove this
void CreateParticleGroup(EntityID entity);
struct Impulse
{
b2Body* Body;
b2Vec2 Impulse;
b2Vec2 Point;
};
std::list<Impulse> m_Impulses;
class ContactListener : public b2ContactListener
{
public:
ContactListener(PhysicsSystem* physicsSystem)
: m_PhysicsSystem(physicsSystem) { }
void BeginContact(b2Contact* contact)
{
b2WorldManifold worldManifold;
contact->GetWorldManifold(&worldManifold);
Events::Contact e;
e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
e.Normal = glm::normalize(glm::vec2(contact->GetManifold()->localNormal.x, contact->GetManifold()->localNormal.y));
e.SignificantNormal = glm::normalize((glm::abs(e.Normal.x) > glm::abs(e.Normal.y)) ? glm::vec2(e.Normal.x, 0) : glm::vec2(0, e.Normal.y));
m_PhysicsSystem->EventBroker->Publish(e);
}
void EndContact(b2Contact* contact)
{
}
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
{
EntityID entityA = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
EntityID entityB = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
auto physicsComponentA = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityA);
auto physicsComponentB = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityB);
if (physicsComponentA != nullptr && physicsComponentB != nullptr) {
if (physicsComponentA->Calculate || physicsComponentB->Calculate) {
// Turn of collisions
contact->SetEnabled(false);
}
}
}
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
{
}
private:
PhysicsSystem* m_PhysicsSystem;
};
ContactListener* m_ContactListener;
};
}
}
#endif //DAYDREAM_PHYSICSSYSTEM_H
+1 -7
View File
@@ -1,7 +1,3 @@
//
// Created by Adam on 2015-09-17.
//
#ifndef COMPONENTS_CCOLLISIONSOUND_H__ #ifndef COMPONENTS_CCOLLISIONSOUND_H__
#define COMPONENTS_CCOLLISIONSOUND_H__ #define COMPONENTS_CCOLLISIONSOUND_H__
@@ -9,17 +5,15 @@
namespace dd namespace dd
{ {
namespace Components namespace Components
{ {
struct CollisionSound : public Component struct CollisionSound : public Component
{ {
std::string filePath; std::string FilePath;
}; };
} }
} }
#endif #endif
+2 -8
View File
@@ -1,7 +1,3 @@
//
// Created by Adam on 2015-09-24.
//
#ifndef EVENTS_EMASTERVOLUME_H__ #ifndef EVENTS_EMASTERVOLUME_H__
#define EVENTS_EMASTERVOLUME_H__ #define EVENTS_EMASTERVOLUME_H__
@@ -9,19 +5,17 @@
namespace dd namespace dd
{ {
namespace Events namespace Events
{ {
struct MasterVolume : public Event struct MasterVolume : public Event
{ {
float gain = 1; float Gain = 1;
//To determine what channel group to apply the change to. //To determine what channel group to apply the change to.
bool isAmbient = false; bool IsAmbient = false;
}; };
} }
} }
#endif #endif
+6 -8
View File
@@ -1,24 +1,22 @@
#ifndef Events_PlaySFX_h__ #ifndef EVENTS_PLAYSFX_H__
#define Events_PlaySFX_h__ #define EVENTS_PLAYSFX_H__
#include "Core/EventBroker.h" #include "Core/EventBroker.h"
namespace dd namespace dd
{ {
namespace Events namespace Events
{ {
struct PlaySound : Event struct PlaySound : Event
{ {
std::string path; std::string FilePath;
float volume = 1.f; float Gain = 1.f;
float pitch = 1.f; float Pitch = 1.f;
bool isAmbient = false; bool IsAmbient = false;
}; };
} }
} }
#endif #endif
+1 -5
View File
@@ -8,16 +8,12 @@ namespace dd
namespace Events namespace Events
{ {
struct StopSound : public Event struct StopSound : public Event
{ {
std::string path; std::string FilePath;
}; };
} }
} }
#endif #endif
+9 -5
View File
@@ -12,27 +12,31 @@ namespace dd
class Sound : public Resource class Sound : public Resource
{ {
friend class ResourceManager; friend class ResourceManager;
public: public:
ALuint Buffer() { return m_Buffer; }; ALuint Buffer() { return m_Buffer; };
std::string Path() { return m_Path; }; std::string Path() { return m_Path; };
float Gain() { return m_Gain; };
void SetGain(const float Gain) { m_Gain = Gain; };
private: private:
Sound(std::string path); Sound(std::string path);
float m_Gain = 1;
ALuint m_Buffer;
std::string m_Path;
//File-info //File-info
char m_Type[4]; char m_Type[4];
unsigned long m_Size, m_ChunkSize; unsigned long m_Size, m_ChunkSize;
short m_FormatType, m_Channels; short m_FormatType, m_Channels;
unsigned long m_SampleRate, m_AvgBytesPerSec; unsigned long m_SampleRate, m_AvgBytesPerSec;
short m_BytesPerSample, m_BitsPerSample; short m_BytesPerSample, m_BitsPerSample;
unsigned long m_DataSize; unsigned int m_DataSize;
std::map<std::string, ALuint> m_BufferCache; std::map<std::string, ALuint> m_BufferCache;
ALuint LoadFile(std::string path); ALuint LoadFile(std::string path);
ALuint m_Buffer;
std::string m_Path;
}; };
} }
#endif #endif
+20 -22
View File
@@ -1,63 +1,61 @@
#ifndef DAYDREAM_SOUND_H #ifndef SYSTEMS_SOUNDSYSTEM_H__
#define DAYDREAM_SOUND_H #define SYSTEMS_SOUNDSYSTEM_H__
#include "AL/al.h" #include "AL/al.h"
#include "AL/alc.h" #include "AL/alc.h"
#include "Core/System.h" #include "Core/System.h"
#include "Core/World.h" #include "Core/World.h"
#include "Core/EventBroker.h" #include "Core/EventBroker.h"
#include "Core/ResourceManager.h"
#include "Sound.h" #include "Sound.h"
#include "Sound/EPlaySound.h" #include "Sound/EPlaySound.h"
#include "Sound/EStopSound.h" #include "Sound/EStopSound.h"
#include "Sound/EMasterVolume.h" #include "Sound/EMasterVolume.h"
#include "Sound/CCollisionSound.h"
#include "Physics/EContact.h" #include "Physics/EContact.h"
#include "Game/CBall.h" #include "Game/CBall.h"
#include "Game/CBrick.h" #include "Game/CBrick.h"
#include "Game/CPad.h" #include "Game/CPad.h"
#include "Sound/CCollisionSound.h"
#include "Core/ResourceManager.h"
#include "Physics/ECreateParticleSequence.h" #include "Physics/ECreateParticleSequence.h"
namespace dd namespace dd
{ {
namespace Systems namespace Systems
{ {
class SoundSystem : public System { class SoundSystem : public System {
public: public:
SoundSystem(World *world, std::shared_ptr<dd::EventBroker> eventBroker) SoundSystem(World *world, std::shared_ptr<dd::EventBroker> eventBroker)
: System(world, eventBroker) { } : System(world, eventBroker) { }
~SoundSystem(); ~SoundSystem();
void Initialize() override; void Initialize() override;
void Update(double dt) override; void Update(double dt) override;
private: private:
float m_BGMMasterVolume = 1.f;
float m_SFXMasterVolume = 1.f;
std::map<ALuint, Sound*> m_BGMSourcesToBuffers;
std::map<ALuint, Sound*> m_SFXSourcesToBuffers;
ALCdevice* m_Device = nullptr;
//Events //Events
dd::EventRelay<SoundSystem, dd::Events::PlaySound> m_EPlaySFX; dd::EventRelay<SoundSystem, dd::Events::PlaySound> m_EPlaySFX;
dd::EventRelay<SoundSystem, dd::Events::Contact> m_EContact;
dd::EventRelay<SoundSystem, dd::Events::StopSound> m_EStopSound;
dd::EventRelay<SoundSystem, dd::Events::MasterVolume> m_EMasterVolume;
bool OnPlaySound(const dd::Events::PlaySound &event); bool OnPlaySound(const dd::Events::PlaySound &event);
//On contact: play the sound given in the CCOllisionSound.
dd::EventRelay<SoundSystem, dd::Events::Contact> m_EContact;
bool OnContact(const dd::Events::Contact &event); bool OnContact(const dd::Events::Contact &event);
dd::EventRelay<SoundSystem, dd::Events::StopSound> m_EStopSound;
bool OnStopSound(const dd::Events::StopSound &event); bool OnStopSound(const dd::Events::StopSound &event);
dd::EventRelay<SoundSystem, dd::Events::MasterVolume> m_EMasterVolume;
bool OnMasterVolume(const dd::Events::MasterVolume &event); bool OnMasterVolume(const dd::Events::MasterVolume &event);
ALuint CreateSource(); ALuint CreateSource();
std::map<ALuint, Sound*> m_BGMSourcesToBuffers;
std::map<ALuint, Sound*> m_SFXSourcesToBuffers;
ALCdevice* m_Device;
float m_BGMMasterVolume, m_SFXMasterVolume;
}; };
} }
} }
#endif //DAYDREAM_SOUND_H #endif
+1 -6
View File
@@ -7,7 +7,6 @@ find_package(Boost REQUIRED COMPONENTS system filesystem thread chrono)
find_package(assimp REQUIRED) find_package(assimp REQUIRED)
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)
find_package(PNG REQUIRED) find_package(PNG REQUIRED)
find_package(BGFX REQUIRED)
find_package(liquidfun REQUIRED) find_package(liquidfun REQUIRED)
# Because FindOpenAL is retarded # Because FindOpenAL is retarded
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${CMAKE_SOURCE_DIR}/deps/include/AL") set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${CMAKE_SOURCE_DIR}/deps/include/AL")
@@ -28,7 +27,6 @@ include_directories(
${assimp_INCLUDE_DIRS} ${assimp_INCLUDE_DIRS}
${PNG_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS}
${X11_INCLUDE_DIRS} ${X11_INCLUDE_DIRS}
${BGFX_INCLUDE_DIRS}
${OPENAL_INCLUDE_DIR} ${OPENAL_INCLUDE_DIR}
${liquidfun_INCLUDE_DIRS} ${liquidfun_INCLUDE_DIRS}
) )
@@ -94,8 +92,7 @@ set(SOURCE_FILES
${SOURCE_FILES_Physics} ${SOURCE_FILES_Physics}
${SOURCE_FILES_Game} ${SOURCE_FILES_Game}
${SOURCE_FILES_Sound} ${SOURCE_FILES_Sound}
${SOURCE_FILES_GUI} ${SOURCE_FILES_GUI})
)
if(CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
@@ -112,7 +109,6 @@ target_link_libraries(game
${assimp_LIBRARIES} ${assimp_LIBRARIES}
${PNG_LIBRARIES} ${PNG_LIBRARIES}
${X11_LIBRARIES} ${X11_LIBRARIES}
${BGFX_LIBRARIES}
${OPENAL_LIBRARY} ${OPENAL_LIBRARY}
${liquidfun_LIBRARIES} ${liquidfun_LIBRARIES}
) )
@@ -129,7 +125,6 @@ target_link_libraries(breakout
${assimp_LIBRARIES} ${assimp_LIBRARIES}
${PNG_LIBRARIES} ${PNG_LIBRARIES}
${X11_LIBRARIES} ${X11_LIBRARIES}
${BGFX_LIBRARIES}
${OPENAL_LIBRARY} ${OPENAL_LIBRARY}
${liquidfun_LIBRARIES} ${liquidfun_LIBRARIES}
) )
+53 -19
View File
@@ -29,32 +29,26 @@ dd::BaseEventRelay::~BaseEventRelay()
void dd::EventBroker::Unsubscribe(BaseEventRelay &relay) // ? void dd::EventBroker::Unsubscribe(BaseEventRelay &relay) // ?
{ {
auto contextIt = m_ContextRelays.find(relay.m_ContextTypeName); if (m_IsProcessing) {
if (contextIt == m_ContextRelays.end()) m_RelaysToUnsubscribe.push_back(&relay);
return; } else {
unsubscribeImmediate(relay);
auto eventRelays = contextIt->second;
auto itpair = eventRelays.equal_range(relay.m_EventTypeName);
for (auto it = itpair.first; it != itpair.second; ++it)
{
if (it->second == &relay)
{
relay.m_Broker = nullptr;
eventRelays.erase(it);
break;
}
} }
} }
void dd::EventBroker::Subscribe(BaseEventRelay &relay) void dd::EventBroker::Subscribe(BaseEventRelay &relay)
{ {
relay.m_Broker = this; if (m_IsProcessing) {
m_ContextRelays[relay.m_ContextTypeName].insert(std::make_pair(relay.m_EventTypeName, &relay)); m_RelaysToSubscribe.push_back(&relay);
} else {
subscribeImmediate(relay);
}
} }
int dd::EventBroker::Process(std::string contextTypeName) int dd::EventBroker::Process(std::string contextTypeName)
{ {
m_IsProcessing = true;
auto it = m_ContextRelays.find(contextTypeName); auto it = m_ContextRelays.find(contextTypeName);
if (it == m_ContextRelays.end()) if (it == m_ContextRelays.end())
return 0; return 0;
@@ -68,14 +62,29 @@ int dd::EventBroker::Process(std::string contextTypeName)
std::shared_ptr<Event> event = pair.second; std::shared_ptr<Event> event = pair.second;
auto itpair = relays.equal_range(eventTypeName); auto itpair = relays.equal_range(eventTypeName);
for (auto it2 = itpair.first; it2 != itpair.second; ++it2) for (auto it2 = itpair.first; it2 != itpair.second; it2++)
{ {
auto relay = it2->second; std::string name = it2->first;
BaseEventRelay* relay = it2->second;
relay->Receive(event); relay->Receive(event);
eventsProcessed++; eventsProcessed++;
} }
} }
m_IsProcessing = false;
// Process pending subscriptions
for (auto& r : m_RelaysToSubscribe) {
subscribeImmediate(*r);
}
m_RelaysToSubscribe.clear();
// Process pending unsubscriptions
for (auto& r : m_RelaysToUnsubscribe) {
unsubscribeImmediate(*r);
}
m_RelaysToUnsubscribe.clear();
return eventsProcessed; return eventsProcessed;
} }
@@ -83,4 +92,29 @@ void dd::EventBroker::Swap()
{ {
std::swap(m_EventQueueRead, m_EventQueueWrite); std::swap(m_EventQueueRead, m_EventQueueWrite);
m_EventQueueWrite->clear(); m_EventQueueWrite->clear();
}
void dd::EventBroker::subscribeImmediate(dd::BaseEventRelay& relay)
{
relay.m_Broker = this;
m_ContextRelays[relay.m_ContextTypeName].insert(std::make_pair(relay.m_EventTypeName, &relay));
}
void dd::EventBroker::unsubscribeImmediate(dd::BaseEventRelay& relay)
{
auto contextIt = m_ContextRelays.find(relay.m_ContextTypeName);
if (contextIt == m_ContextRelays.end()) {
return;
}
auto eventRelays = contextIt->second;
auto itpair = eventRelays.equal_range(relay.m_EventTypeName);
for (auto it = itpair.first; it != itpair.second; ++it) {
if (it->second == &relay) {
relay.m_Broker = nullptr;
eventRelays.erase(it);
break;
}
}
} }
+3 -3
View File
@@ -263,7 +263,7 @@ void dd::OBJ::ParseMaterial()
ParseColorMap(currentLine, ss, prefix, arg, colorMap); ParseColorMap(currentLine, ss, prefix, arg, colorMap);
} }
// HACK: Should we really have to specify the full path here? // HACK: Should we really have to specify the full FilePath here?
colorMap.FileName = (m_MaterialPath.branch_path() / colorMap.FileName).string(); colorMap.FileName = (m_MaterialPath.branch_path() / colorMap.FileName).string();
currentMaterial->DiffuseTexture = colorMap; currentMaterial->DiffuseTexture = colorMap;
continue; continue;
@@ -280,7 +280,7 @@ void dd::OBJ::ParseMaterial()
ParseColorMap(currentLine, ss, prefix, arg, colorMap); ParseColorMap(currentLine, ss, prefix, arg, colorMap);
} }
// HACK: Should we really have to specify the full path here? // HACK: Should we really have to specify the full FilePath here?
colorMap.FileName = (m_MaterialPath.branch_path() / colorMap.FileName).string(); colorMap.FileName = (m_MaterialPath.branch_path() / colorMap.FileName).string();
currentMaterial->SpecularMap = colorMap; currentMaterial->SpecularMap = colorMap;
continue; continue;
@@ -297,7 +297,7 @@ void dd::OBJ::ParseMaterial()
ParseBumpMap(currentLine, ss, prefix, arg, bumpMap); ParseBumpMap(currentLine, ss, prefix, arg, bumpMap);
} }
// HACK: Should we really have to specify the full path here? // HACK: Should we really have to specify the full FilePath here?
bumpMap.FileName = (m_MaterialPath.branch_path() / bumpMap.FileName).string(); bumpMap.FileName = (m_MaterialPath.branch_path() / bumpMap.FileName).string();
currentMaterial->NormalMap = bumpMap; currentMaterial->NormalMap = bumpMap;
continue; continue;
+1 -1
View File
@@ -163,7 +163,7 @@ void dd::World::Initialize()
} }
} }
int dd::World::CommitEntity(EntityID entity) void dd::World::CommitEntity(EntityID entity)
{ {
for (auto pair : m_Systems) for (auto pair : m_Systems)
{ {
+292 -5
View File
@@ -13,17 +13,151 @@ void dd::Systems::BallSystem::RegisterComponents(ComponentFactory *cf)
void dd::Systems::BallSystem::Initialize() void dd::Systems::BallSystem::Initialize()
{ {
EVENT_SUBSCRIBE_MEMBER(m_Contact, BallSystem::Contact); EVENT_SUBSCRIBE_MEMBER(m_Contact, &BallSystem::Contact);
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, &BallSystem::OnLifeLost);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBallLost, &BallSystem::OnMultiBallLost);
EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &BallSystem::OnResetBall);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &BallSystem::OnMultiBall);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &BallSystem::OnPause);
//OctoBall
{
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(-0.f, 50.26f, -10.f);
transform->Scale = glm::vec3(0.3f, 0.3f, 0.3f);
transform->Velocity = glm::vec3(0.f, 0.f, 0.f);
auto model = m_World->AddComponent<Components::Model>(ent);
model->ModelFile = "Models/Test/Ball/Sid.obj";
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
circleShape->Radius = 0.4f;
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
ball->Speed = 5.f;
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
std::shared_ptr<Components::Template> ballTemplate = m_World->AddComponent<Components::Template>(ent);
physics->CollisionType = CollisionType::Type::Dynamic;
physics->Category = CollisionLayer::Type::Ball;
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall);
physics->Calculate = true;
//auto plight = m_World->AddComponent<Components::PointLight>(ent);
//plight->Radius = 2.f;
m_World->CommitEntity(ent);
SetBall(ent);
auto ent2 = CreateBall();
auto transform2 = m_World->GetComponent<Components::Transform>(ent2);
transform2->Position = glm::vec3(-0.f, 0.26f, -10.f);
transform2->Velocity = glm::vec3(0.0f, -10.f, 0.f);
}
for (int i = 0; i < Lives(); i++) {
CreateLife(i);
}
} }
void dd::Systems::BallSystem::Update(double dt) void dd::Systems::BallSystem::Update(double dt)
{ {
if (Lives() < 0)
{
SetLives(3);
Events::GameOver e;
EventBroker->Publish(e);
}
ResolveContacts();
} }
void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{ {
//TODO: When the ball collides with 2 bricks on the same frame it is reflected and then reflected again, make it reflect only once like a list or something?
auto ballComponent = m_World->GetComponent<Components::Ball>(entity); auto ballComponent = m_World->GetComponent<Components::Ball>(entity);
if (IsPaused()) {
if (ballComponent != nullptr) {
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (!ballComponent->Paused) {
ballComponent->Paused = true;
ballComponent->SavedSpeed = transform->Velocity;
transform->Velocity = glm::vec3(0, 0, 0);
}
}
return;
} else {
if (ballComponent != nullptr) {
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (ballComponent->Paused) {
transform->Velocity = ballComponent->SavedSpeed;
ballComponent->Paused = false;
}
}
}
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
if (templateCheck != nullptr){ return; }
if (ballComponent != nullptr) {
if (ReplaceBall()) {
SetReplaceBall(false);
auto transform = m_World->GetComponent<Components::Transform>(entity);
transform->Position = glm::vec3(0.0f, 0.26f, -10.f);
transform->Velocity = glm::vec3(0.0f, -ballComponent->Speed, 0.f);
}
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
if (glm::abs(transformBall->Velocity.y) < 2) {
if (transformBall->Velocity.y > 0) {
transformBall->Velocity.y = 2;
} else {
transformBall->Velocity.y = -2;
}
}
if (transformBall->Position.y < -EdgeY() - 4) {
if (MultiBalls() != 0) {
m_World->RemoveEntity(entity);
Events::MultiBallLost e;
EventBroker->Publish(e);
} else if (Lives() == PastLives()) {
Events::ResetBall be;
EventBroker->Publish(be);
Events::LifeLost e;
e.Entity = entity;
EventBroker->Publish(e);
return;
}
} //Removing this made the wall collisions work again
/*else if (transformBall->Position.x > EdgeX()) {
if (transformBall->Velocity.x > 0) {
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(1, 0));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
} else if (transformBall->Position.x < -EdgeX()) {
if (transformBall->Velocity.x < 0) {
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(-1, 0));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
} else if (transformBall->Position.y > EdgeY()) {
if (transformBall->Velocity.y > 0) {
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(0, 1));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
}*/
}
if (Lives() != PastLives()) {
auto life = m_World->GetComponent<Components::Life>(entity);
if (life != nullptr) {
if (life->Number + 1 == PastLives()) {
m_World->RemoveEntity(entity);
SetPastLives(Lives());
}
}
}
if (ballComponent != nullptr) { if (ballComponent != nullptr) {
auto transform = m_World->GetComponent<Components::Transform>(entity); auto transform = m_World->GetComponent<Components::Transform>(entity);
glm::vec2 dir = glm::normalize(glm::vec2(transform->Velocity.x, transform->Velocity.y)); glm::vec2 dir = glm::normalize(glm::vec2(transform->Velocity.x, transform->Velocity.y));
@@ -33,6 +167,20 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
} }
} }
bool dd::Systems::BallSystem::OnPause(const dd::Events::Pause &event)
{
if (event.Type != "BallSystem" && event.Type != "All") {
return false;
}
if (IsPaused()) {
SetPause(false);
} else {
SetPause(true);
}
return true;
}
void dd::Systems::BallSystem::OnEntityCommit(EntityID entity) void dd::Systems::BallSystem::OnEntityCommit(EntityID entity)
{ {
@@ -79,23 +227,162 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
//TODO: Add support for power-up collisions //TODO: Add support for power-up collisions
} }
auto brick = m_World->GetComponent<Components::Brick>(otherEntitiy);
if (brick != nullptr) {
auto transform = m_World->GetComponent<Components::Transform>(otherEntitiy);
auto physics = m_World->GetComponent<Components::Physics>(otherEntitiy);
auto rectangle = m_World->GetComponent<Components::RectangleShape>(otherEntitiy);
int hey = 5;
}
//if this is a brick thats dead do not collide :) //if this is a brick thats dead do not collide :)
auto ballTransform = m_World->GetComponent<Components::Transform>(ballEntity); auto ballTransform = m_World->GetComponent<Components::Transform>(ballEntity);
glm::vec2 ballVelocity = glm::vec2(ballTransform->Velocity.x, ballTransform->Velocity.y); glm::vec2 ballVelocity = glm::vec2(ballTransform->Velocity.x, ballTransform->Velocity.y);
if (m_World->GetProperty<std::string>(otherEntitiy, "Name") == "Pad"){ if (m_World->GetProperty<std::string>(otherEntitiy, "Name") == "Pad"){
Events::HitPad e;
EventBroker->Publish(e);
// Events::HitLag el;
// el.Time = 0.1f;
//el.Type = "All";
// EventBroker->Publish(el);
auto padTransform = m_World->GetComponent<Components::Transform>(otherEntitiy); auto padTransform = m_World->GetComponent<Components::Transform>(otherEntitiy);
float x = ballTransform->Position.x - padTransform->Position.x; float x = (ballTransform->Position.x - padTransform->Position.x) * XMovementMultiplier();
float y = glm::cos((abs(x) / (1.6f)) * glm::pi<float>() / 2.f) + 1.f; float y = glm::cos((abs(x) / (1.6f)) * glm::pi<float>() / 2.f) + 1.f;
ballTransform->Velocity = glm::normalize(glm::vec3(x, y ,0.f)) * ballComponent->Speed; ballTransform->Velocity = glm::normalize(glm::vec3(x, y ,0.f)) * ballComponent->Speed;
ballComponent->Combo = 0;
Events::ComboEvent ec;
ec.Combo = ballComponent->Combo;
ec.Ball = ballEntity;
EventBroker->Publish(ec);
//std::cout << "Combo: " << ballComponent->Combo << std::endl;
} }
else { else {
glm::vec2 reflectedVelocity = glm::reflect(ballVelocity, event.Normal); auto it = m_Contacts.find(ballEntity);
ballTransform->Velocity = glm::vec3(reflectedVelocity, 0.f); if (it == m_Contacts.end()) {
std::list<glm::vec2> normalList;
normalList.push_back(event.Normal);
m_Contacts[ballEntity] = normalList;
} else {
std::list<glm::vec2> normalList = it->second;
normalList.push_back(event.Normal);
m_Contacts[ballEntity] = normalList;
}
//glm::vec2 reflectedVelocity = glm::reflect(ballVelocity, event.Normal);
//ballTransform->Velocity = glm::vec3(reflectedVelocity, 0.f);
} }
return true; return true;
} }
void dd::Systems::BallSystem::ResolveContacts()
{
for (auto c : m_Contacts) {
int count = 0;
EntityID entity = c.first;
std::list<glm::vec2> contactNormals = c.second;
glm::vec2 finalNormal = glm::vec2(0.f);
for (auto it = contactNormals.begin(); it != contactNormals.end(); it++) {
finalNormal = finalNormal + (*it);
count++;
}
finalNormal = glm::normalize(finalNormal);
if (count > 1) {
LOG_INFO("MultiCollision %i", count);
}
auto transform = m_World->GetComponent<Components::Transform>(entity);
glm::vec2 velocity = glm::vec2(transform->Velocity.x, transform->Velocity.y);
glm::vec2 reflectedVelocity = glm::reflect(velocity, finalNormal);
transform->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
m_Contacts.clear();
}
EntityID dd::Systems::BallSystem::CreateBall()
{
auto ent = m_World->CloneEntity(Ball());
m_World->RemoveComponent<Components::Template>(ent);
return ent;
}
void dd::Systems::BallSystem::CreateLife(int number)
{
auto life = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(life);
transform->Position = glm::vec3(-1.5f + number * 0.15f, -2.f, -5.f);
transform->Scale = glm::vec3(0.1f, 0.1f, 0.1f);
std::shared_ptr<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
lifeNr->Number = number;
auto model = m_World->AddComponent<Components::Model>(life);
model->ModelFile = "Models/Test/Ball/Sid.obj";
m_World->CommitEntity(life);
}
bool dd::Systems::BallSystem::OnLifeLost(const dd::Events::LifeLost &event)
{
SetLives(Lives() - 1);
return true;
}
bool dd::Systems::BallSystem::OnMultiBallLost(const dd::Events::MultiBallLost &event)
{
SetMultiBalls(MultiBalls() - 1);
//std::cout << MultiBalls() << std::endl;
if (MultiBalls() < 0) {
auto ent = CreateBall();
SetMultiBalls(0);
}
return true;
}
bool dd::Systems::BallSystem::OnResetBall(const dd::Events::ResetBall &event)
{
SetReplaceBall(true);
return true;
}
bool dd::Systems::BallSystem::OnMultiBall(const dd::Events::MultiBall &event)
{
auto ent1 = CreateBall();
auto ent2 = CreateBall();
auto transform1 = m_World->GetComponent<Components::Transform>(ent1);
auto transform2 = m_World->GetComponent<Components::Transform>(ent2);
auto ball1 = m_World->GetComponent<Components::Ball>(ent1);
auto ball2 = m_World->GetComponent<Components::Ball>(ent2);
auto padTransform = event.padTransform;
float x1 = padTransform->Position.x - 2, x2 = padTransform->Position.x + 2;
if (x1 < -m_EdgeX) {
x1 = m_EdgeX - 0.2;
}
if (x2 > m_EdgeX) {
x2 = -m_EdgeX + 0.2;
}
transform1->Position = glm::vec3(x1, -5.5, -10);
transform2->Position = glm::vec3(x2, -5.5, -10);
transform1->Velocity = glm::normalize(glm::vec3(5, 5 ,0.f)) * ball1->Speed;
transform2->Velocity = glm::normalize(glm::vec3(-5, 5 ,0.f)) * ball2->Speed;
SetMultiBalls(MultiBalls() + 2);
//std::cout << MultiBalls() << std::endl;
return true;
}
+57
View File
@@ -0,0 +1,57 @@
//
// Created by Adniklastrator on 2015-09-30.
//
#include "PrecompiledHeader.h"
#include "Game/HitLagSystem.h"
void dd::Systems::HitLagSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EPause, &HitLagSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EHitLag, &HitLagSystem::OnHitLag);
}
void dd::Systems::HitLagSystem::Update(double dt)
{
if (IsPaused()) {
if (HitLag()) {
SetHitLagTimer(HitLagTimer() += dt);
//std::cout << HitLagTimer() << std::endl;
if (HitLagDuration() < HitLagTimer()) {
SetHitLagTimer(0);
SetHitLag(false);
FlipPause();
}
}
return;
}
}
void dd::Systems::HitLagSystem::FlipPause()
{
Events::Pause e;
e.Type = CurrentType();
EventBroker->Publish(e);
}
bool dd::Systems::HitLagSystem::OnPause(const dd::Events::Pause &event)
{
if (IsPaused()) {
SetPause(false);
} else {
SetPause(true);
}
return true;
}
bool dd::Systems::HitLagSystem::OnHitLag(const dd::Events::HitLag &event)
{
if (HitLag()) {
FlipPause();
}
SetHitLag(true);
SetCurrentType(event.Type);
FlipPause();
SetHitLagDuration(event.Time);
return true;
}
+255 -177
View File
@@ -9,156 +9,126 @@
void dd::Systems::LevelSystem::Initialize() void dd::Systems::LevelSystem::Initialize()
{ {
EVENT_SUBSCRIBE_MEMBER(m_EContact, LevelSystem::OnContact); EVENT_SUBSCRIBE_MEMBER(m_EContact, &LevelSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, LevelSystem::OnLifeLost); EVENT_SUBSCRIBE_MEMBER(m_EScoreEvent, &LevelSystem::OnScoreEvent);
EVENT_SUBSCRIBE_MEMBER(m_EScoreEvent, LevelSystem::OnScoreEvent); EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &LevelSystem::OnMultiBall);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, LevelSystem::OnMultiBall); EVENT_SUBSCRIBE_MEMBER(m_ECreatePowerUp, &LevelSystem::OnCreatePowerUp);
EVENT_SUBSCRIBE_MEMBER(m_ECreatePowerUp, LevelSystem::OnCreatePowerUp); EVENT_SUBSCRIBE_MEMBER(m_EMultiBallLost, &LevelSystem::OnMultiBallLost);
EVENT_SUBSCRIBE_MEMBER(m_EPowerUpTaken, LevelSystem::OnPowerUpTaken); EVENT_SUBSCRIBE_MEMBER(m_EPowerUpTaken, &LevelSystem::OnPowerUpTaken);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, LevelSystem::OnStageCleared); EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &LevelSystem::OnStageCleared);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &LevelSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EHitPad, &LevelSystem::OnHitPad);
for (int i = 0; i < Lives(); i++) { m_BrickTemplate = m_World->CreateEntity();
CreateLife(i); std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(m_BrickTemplate);
} auto model = m_World->AddComponent<Components::Model>(m_BrickTemplate);
std::shared_ptr<Components::Brick> cBrick = m_World->AddComponent<Components::Brick>(m_BrickTemplate);
std::shared_ptr<Components::RectangleShape> cRec = m_World->AddComponent<Components::RectangleShape>(m_BrickTemplate);
cRec->Dimensions = glm::vec2(0.9f, 0.35f);
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(m_BrickTemplate);
std::shared_ptr<Components::Template> cTemplate = m_World->AddComponent<Components::Template>(m_BrickTemplate);
cPhys->CollisionType = CollisionType::Type::Dynamic;
cPhys->GravityScale = 0.f;
cPhys->Category = CollisionLayer::Type::Brick;
cPhys->Mask = CollisionLayer::Type::Ball;
model->ModelFile = "Models/Brick/TurquoiseBrick.obj";
transform->Position = glm::vec3(50, 50, -10);
//sound
auto collisionSound = m_World->AddComponent<Components::CollisionSound>(m_BrickTemplate);
collisionSound->FilePath = "Sounds/Brick/shortbrickbreak.wav";
m_World->CommitEntity(m_BrickTemplate);
return; return;
} }
void dd::Systems::LevelSystem::CreateLife(int number)
{
auto life = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(life);
transform->Position = glm::vec3(-1.5f + number * 0.15f, -2.f, -5.f);
transform->Scale = glm::vec3(0.1f, 0.1f, 0.1f);
std::shared_ptr<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
lifeNr->Number = number;
auto model = m_World->AddComponent<Components::Model>(life);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
m_World->CommitEntity(life);
}
void dd::Systems::LevelSystem::Update(double dt) void dd::Systems::LevelSystem::Update(double dt)
{ {
if (!m_Initialized) { if (!m_Initialized) {
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge()); GetNextLevel();
CreateLevel();
m_Initialized = true; m_Initialized = true;
} }
if (Lives() < 0)
{
SetLives(3);
Events::GameOver e;
EventBroker->Publish(e);
}
} }
void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{ {
auto ball = m_World->GetComponent<Components::Ball>(entity); if (IsPaused()) {
if (ball != nullptr) {
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
if (glm::abs(transformBall->Velocity.y) < 2) {
if (transformBall->Velocity.y > 0) {
transformBall->Velocity.y = 2;
} else {
transformBall->Velocity.y = -2;
}
}
if (transformBall->Position.y < -EdgeY() - 4) {
if (MultiBalls() != 0) {
SetMultiBalls(MultiBalls() - 1);
// m_World->RemoveComponent<Components::Ball>(entity);
// m_World->RemoveComponent<Components::Transform>(entity);
// m_World->RemoveComponent<Components::CircleShape>(entity);
// m_World->RemoveComponent<Components::Physics>(entity);
m_World->RemoveEntity(entity);
} else if (Lives() == PastLives()) {
Events::ResetBall be;
EventBroker->Publish(be);
Events::LifeLost e;
e.Entity = entity;
EventBroker->Publish(e);
return; return;
} }
} else if (transformBall->Position.x > EdgeX()) { auto templateCheck = m_World->GetComponent<Components::Template>(entity);
if (transformBall->Velocity.x > 0) { if (templateCheck != nullptr){ return; }
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(1, 0));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f); auto brick = m_World->GetComponent<Components::Brick>(entity);
} if (brick != nullptr) {
} else if (transformBall->Position.x < -EdgeX()) { auto transform = m_World->GetComponent<Components::Transform>(entity);
if (transformBall->Velocity.x < 0) { //Removes bricks that falls out of the stage.
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(-1, 0)); if (transform->Position.y < -10) {
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f); if (brick->Type == MultiBallBrick) {
} Events::MultiBall e;
} else if (transformBall->Position.y > EdgeY()) { e.padTransform = transform;
if (transformBall->Velocity.y > 0) { EventBroker->Publish(e);
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(0, 1));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
} }
m_LooseBricks--;
m_World->RemoveEntity(entity);
} }
} }
if (Lives() != PastLives()) { auto ball = m_World->GetComponent<Components::Ball>(entity);
auto life = m_World->GetComponent<Components::Life>(entity);
if (life != nullptr) { if (NumberOfBricks() <= 0 && m_LooseBricks <= 0 && !Restarting()) {
if (life->Number + 1 == PastLives()) {
// m_World->RemoveComponent<Components::Life>(entity);
// m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveEntity(entity);
SetPastLives(Lives());
}
}
}
if (NumberOfBricks() <= 0) {
/*SetRestarting(true);
if (MultiBalls() <= 0 && PowerUps() <= 0) { if (MultiBalls() <= 0 && PowerUps() <= 0) {
Events::ResetBall e;
EventBroker->Publish(e);
Events::ScoreEvent es;
es.Score = 500;
EventBroker->Publish(es);
Events::StageCleared ec; Events::StageCleared ec;
EventBroker->Publish(ec); EventBroker->Publish(ec);
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
} else { } else {
if (ball != nullptr && MultiBalls() > 0) { if (ball != nullptr && MultiBalls() > 0) {
SetMultiBalls(MultiBalls() - 1); Events::MultiBallLost e;
m_World->RemoveComponent<Components::Ball>(entity); EventBroker->Publish(e);
m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveComponent<Components::CircleShape>(entity);
m_World->RemoveComponent<Components::Physics>(entity);
m_World->RemoveEntity(entity); m_World->RemoveEntity(entity);
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
} else { } else {
auto powerUp = m_World->GetComponent<Components::PowerUp>(entity); auto powerUp = m_World->GetComponent<Components::PowerUp>(entity);
if (powerUp != nullptr) { if (powerUp != nullptr) {
SetPowerUps(PowerUps() - 1); SetPowerUps(PowerUps() - 1);
m_World->RemoveComponent<Components::PowerUp>(entity); m_World->RemoveEntity(entity);
m_World->RemoveComponent<Components::Transform>(entity); } else {
if (brick != nullptr) {
m_LooseBricks--;
m_World->RemoveEntity(entity); m_World->RemoveEntity(entity);
} }
} }
}*/
} }
} }
}
}
bool dd::Systems::LevelSystem::OnPause(const dd::Events::Pause &event)
{
if (event.Type != "LevelSystem" && event.Type != "All") {
return false;
}
if (IsPaused()) {
SetPause(false);
} else {
SetPause(true);
}
return true;
}
void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 spacesBetweenBricks, float spaceToEdge) void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 spacesBetweenBricks, float spaceToEdge)
{ {
SetNumberOfBricks(rows * lines); SetNumberOfBricks(rows * lines);
std::cout << "You're only doing this once, right?" << std::endl; //std::cout << "You're only doing this once, right?" << std::endl;
int num = 0; int num = Lines();
for (int i = 0; i < rows; i++) { for (int i = 0; i < rows; i++) {
num++; num--;
for (int j = 0; j < Lines(); j++) { for (int j = 0; j < Lines(); j++) {
CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, num); CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, num, 1);
} }
if (num == 7) if (num == 1)
num = 0; num = Lines();
} }
SetNumberOfBricks(rows * lines); SetNumberOfBricks(rows * lines);
@@ -166,60 +136,55 @@ void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 s
return; return;
} }
void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBetweenBricks, float spaceToEdge, int num) void dd::Systems::LevelSystem::CreateLevel()
{ {
auto brick = m_World->CreateEntity(); std::cout << "Loading level: " << m_CurrentLevel << std::endl;
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(brick); SetNumberOfBricks(Rows() * Lines());
auto model = m_World->AddComponent<Components::Model>(brick); int num = Lines();
std::shared_ptr<Components::Brick> cBrick = m_World->AddComponent<Components::Brick>(brick); int getter = 0;
std::shared_ptr<Components::RectangleShape> cRec = m_World->AddComponent<Components::RectangleShape>(brick);
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(brick);
cPhys->Static = false;
cPhys->GravityScale = 0.f;
cPhys->Category = CollisionLayer::Type::Brick;
cPhys->Mask = CollisionLayer::Type::Ball;
std::string fileName = "Textures/Bricks/"; for (int i = 0; i < Rows(); i++) {
fileName.append(std::to_string(num)); num--;
fileName.append(".png"); for (int j = 0; j < Lines(); j++) {
//sprite->SpriteFile = fileName; CreateBrick(i, j, SpaceBetweenBricks(), SpaceToEdge(), num, m_Bricks[getter]);
model->ModelFile = "Models/Test/Brick/Brick.obj"; getter++;
if ((line == 1 && row == 4) || (line == 3 && row == 2) || (line == 6 && row == 6)) { }
if (num == 1) {
num = Lines();
}
}
m_LooseBricks = NumberOfBricks();
SetRestarting(false);
}
void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBetweenBricks, float spaceToEdge, int num, int typeInt)
{
if (typeInt == EmptyBrickSpace) {
SetNumberOfBricks(NumberOfBricks() - 1);
return;
}
auto brick = m_World->CloneEntity(m_BrickTemplate);
m_World->RemoveComponent<Components::Template>(brick);
auto transform = m_World->GetComponent<Components::Transform>(brick);
auto cBrick = m_World->GetComponent<Components::Brick>(brick);
if (typeInt == StandardBrick) {
} else if (typeInt == MultiBallBrick) {
cBrick->Type = MultiBallBrick;
std::shared_ptr<Components::PowerUpBrick> cPow = m_World->AddComponent<Components::PowerUpBrick>(brick); std::shared_ptr<Components::PowerUpBrick> cPow = m_World->AddComponent<Components::PowerUpBrick>(brick);
auto model = m_World->GetComponent<Components::Model>(brick);
model->ModelFile = "Models/Brick/IceBrick.obj";
} }
float x = line * spacesBetweenBricks.x; float x = line * spacesBetweenBricks.x;
float y = row * spacesBetweenBricks.y; float y = row * spacesBetweenBricks.y;
transform->Scale = glm::vec3(0.8, 0.2, 0.2);
transform->Position = glm::vec3(x - 3, 5 - spaceToEdge - y , -10.f); transform->Position = glm::vec3(x - 3, 5 - spaceToEdge - y , -10.f);
cBrick->Score = 10 * num; cBrick->Score = 10 * num;
//sound
auto collisionSound = m_World->AddComponent<Components::CollisionSound>(brick);
collisionSound->filePath = "Sounds/Brick/shortbrickbreak.wav";
m_World->CommitEntity(brick);
return;
}
void dd::Systems::LevelSystem::ProcessCollision()
{
// Like, go into brick component and check what it does upon collision. Maybe not done here?
return; return;
} }
void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity) void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity)
{ {
auto brick = m_World->GetComponent<Components::Brick>(entity);
if (brick != nullptr) {
SetNumberOfBricks(NumberOfBricks() - 1);
Events::ScoreEvent es;
es.Score = brick->Score;
EventBroker->Publish(es);
/*if (numberOfBricks < 1) {
EndLevel();
}*/
}
return;
} }
bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event) bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
@@ -254,26 +219,28 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
return false; return false;
} }
auto power = m_World->GetComponent<Components::PowerUpBrick>(entityBrick); /*auto power = m_World->GetComponent<Components::PowerUpBrick>(entityBrick);
if (power != nullptr) { if (power != nullptr && NumberOfBricks() > 1) {
Events::CreatePowerUp e; Events::CreatePowerUp e;
auto transform = m_World->GetComponent<Components::Transform>(entityBrick); auto transform = m_World->GetComponent<Components::Transform>(entityBrick);
e.Position = transform->Position; e.Position = transform->Position;
EventBroker->Publish(e); EventBroker->Publish(e);
} }*/
if (!Restarting() && !brick->Removed) {
brick->Removed = true;
// Hit brick with ball code.
ball->Combo += 1;
Events::ComboEvent ec;
ec.Combo = ball->Combo;
ec.Ball = entityBall;
EventBroker->Publish(ec);
if (ball != nullptr && Restarting() == false) {
auto ballTransform = m_World->GetComponent<Components::Transform>(entityBall); auto ballTransform = m_World->GetComponent<Components::Transform>(entityBall);
// m_World->RemoveComponent<Components::Brick>(entityBrick);
// m_World->RemoveComponent<Components::Transform>(entityBrick);
// m_World->RemoveComponent<Components::RectangleShape>(entityBrick);
// m_World->RemoveComponent<Components::Physics>(entityBrick);
// m_World->RemoveEntity(entityBrick);
auto physicsComponent = m_World->GetComponent<Components::Physics>(entityBrick); auto physicsComponent = m_World->GetComponent<Components::Physics>(entityBrick);
physicsComponent->GravityScale = 1.f; physicsComponent->GravityScale = 1.f;
physicsComponent->Mask = CollisionLayer::Type::Water | CollisionLayer::Type::Wall; physicsComponent->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Water | CollisionLayer::Wall);
auto transformComponentBrick = m_World->GetComponent<Components::Transform>(entityBrick); auto transformComponentBrick = m_World->GetComponent<Components::Transform>(entityBrick);
auto transformComponentBall = m_World->GetComponent<Components::Transform>(entityBall); auto transformComponentBall = m_World->GetComponent<Components::Transform>(entityBall);
@@ -289,28 +256,21 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
EventBroker->Publish(e); EventBroker->Publish(e);
//TODO: Bricks dont collide with walls D= //TODO: Bricks dont collide with walls D=
SetNumberOfBricks(NumberOfBricks() - 1); SetNumberOfBricks(NumberOfBricks() - 1);
if (NumberOfBricks() <= 0) {
SetMultiBalls(MultiBalls() + 1);
}
Events::ScoreEvent es; Events::ScoreEvent es;
es.Score = brick->Score; es.Score = brick->Score * ball->Combo;
EventBroker->Publish(es); EventBroker->Publish(es);
//std::cout << "Combo: " << ball->Combo << std::endl;
//std::cout << NumberOfBricks() << std::endl; //std::cout << NumberOfBricks() << std::endl;
//std::cout << "Brick Score: " << brick->Score << std::endl;
//std::cout << "Score: " << Score() << std::endl; //std::cout << "Score: " << Score() << std::endl;
} }
return true; return true;
} }
bool dd::Systems::LevelSystem::OnLifeLost(const dd::Events::LifeLost &event)
{
SetLives(Lives() - 1);
return true;
}
bool dd::Systems::LevelSystem::OnScoreEvent(const dd::Events::ScoreEvent &event) bool dd::Systems::LevelSystem::OnScoreEvent(const dd::Events::ScoreEvent &event)
{ {
SetScore(Score() += event.Score); SetScore(Score() += event.Score);
@@ -321,6 +281,16 @@ bool dd::Systems::LevelSystem::OnScoreEvent(const dd::Events::ScoreEvent &event)
bool dd::Systems::LevelSystem::OnMultiBall(const dd::Events::MultiBall &event) bool dd::Systems::LevelSystem::OnMultiBall(const dd::Events::MultiBall &event)
{ {
SetMultiBalls(MultiBalls()+2); SetMultiBalls(MultiBalls()+2);
return true;
}
bool dd::Systems::LevelSystem::OnMultiBallLost(const dd::Events::MultiBallLost &event)
{
SetMultiBalls(MultiBalls()-1);
if (MultiBalls() < 0) {
SetMultiBalls(0);
}
return true;
} }
bool dd::Systems::LevelSystem::OnCreatePowerUp(const dd::Events::CreatePowerUp &event) bool dd::Systems::LevelSystem::OnCreatePowerUp(const dd::Events::CreatePowerUp &event)
@@ -331,13 +301,12 @@ bool dd::Systems::LevelSystem::OnCreatePowerUp(const dd::Events::CreatePowerUp &
auto model = m_World->AddComponent<Components::Model>(powerUp); auto model = m_World->AddComponent<Components::Model>(powerUp);
std::shared_ptr<Components::CircleShape> cRec = m_World->AddComponent<Components::CircleShape>(powerUp); std::shared_ptr<Components::CircleShape> cRec = m_World->AddComponent<Components::CircleShape>(powerUp);
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(powerUp); std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(powerUp);
cPhys->Static = false; cPhys->CollisionType = CollisionType::Type::Dynamic;
cPhys->Category = CollisionLayer::Type::PowerUp; cPhys->Category = CollisionLayer::Type::PowerUp;
cPhys->Mask = CollisionLayer::Type::Pad; cPhys->Mask = CollisionLayer::Type::Pad;
std::shared_ptr<Components::PowerUp> cPow = m_World->AddComponent<Components::PowerUp>(powerUp); std::shared_ptr<Components::PowerUp> cPow = m_World->AddComponent<Components::PowerUp>(powerUp);
transform->Position = event.Position; transform->Position = event.Position;
transform->Scale = glm::vec3(0.2, 0.2, 0.2); transform->Scale = glm::vec3(0.2, 0.2, 0.2);
transform->Velocity = glm::vec3(0, -4, 0); transform->Velocity = glm::vec3(0, -4, 0);
@@ -357,13 +326,122 @@ bool dd::Systems::LevelSystem::OnPowerUpTaken(const dd::Events::PowerUpTaken &ev
bool dd::Systems::LevelSystem::OnStageCleared(const dd::Events::StageCleared &event) bool dd::Systems::LevelSystem::OnStageCleared(const dd::Events::StageCleared &event)
{ {
if (!m_Cleared) {
m_Cleared = true;
SetRestarting(true);
Events::ResetBall e;
EventBroker->Publish(e);
Events::ScoreEvent es;
es.Score = 500;
EventBroker->Publish(es);
m_CurrentLevel++;
if (m_CurrentLevel < 6) {
GetNextLevel();
CreateLevel();
}
}
return true; return true;
} }
void dd::Systems::LevelSystem::EndLevel() void dd::Systems::LevelSystem::GetNextLevel()
{ {
Events::StageCleared e; std::array<int, 42> level;
EventBroker->Publish(e); // 0 is empty space.
return; // 1 is standard brick.
// 2 is multiball brick.
if (m_CurrentCluster == 1) {
if (m_CurrentLevel == 1) {
level =
{0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0};
} else if (m_CurrentLevel == 2) {
level =
{1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0};
} else if (m_CurrentLevel == 3) {
level =
{0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0};
} else if (m_CurrentLevel == 4) {
level =
{0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0};
} else if (m_CurrentLevel == 5) {
level =
{0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1};
}
} else if (m_CurrentCluster == 2) {
if (m_CurrentLevel == 1) {
level =
{1, 1, 0, 1, 0, 1, 1,
1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1,
1, 2, 1, 2, 1, 2, 1,
1, 1, 0, 1, 0, 1, 1,
1, 0, 0, 1, 0, 0, 1};
} else if (m_CurrentLevel == 2) {
level =
{1, 0, 0, 0, 0, 0, 1,
0, 1, 0, 0, 0, 1, 0,
0, 0, 2, 2, 2, 0, 0,
0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0};
} else if (m_CurrentLevel == 3) {
level =
{2, 0, 0, 0, 0, 0, 2,
0, 1, 0, 0, 0, 1, 0,
1, 2, 1, 1, 1, 2, 1,
1, 0, 1, 1, 1, 0, 1,
1, 0, 1, 1, 1, 0, 1,
1, 0, 1, 1, 1, 0, 1};
} else if (m_CurrentLevel == 4) {
level =
{1, 2, 1, 1, 1, 2, 1,
1, 0, 1, 1, 1, 0, 1,
1, 2, 1, 1, 1, 2, 1,
1, 0, 1, 1, 1, 0, 1,
1, 0, 0, 0, 0, 0, 1,
0, 1, 1, 0, 1, 1, 0};
} else if (m_CurrentLevel == 5) {
level =
{1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0,
2, 0, 1, 0, 1, 0, 2,
0, 1, 0, 2, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0};
}
} else if (m_CurrentCluster == 3) {
} }
std::copy(std::begin(level), std::end(level), std::begin(m_Bricks));
}
bool dd::Systems::LevelSystem::OnHitPad(const dd::Events::HitPad &event)
{
m_Cleared = false;
return true;
}
-372
View File
@@ -1,372 +0,0 @@
//
// Created by Adniklastrator on 2015-09-09.
//
#include "PrecompiledHeader.h"
#include "Game/LevelSystem.h"
void dd::Systems::LevelSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EContact, LevelSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, LevelSystem::OnLifeLost);
EVENT_SUBSCRIBE_MEMBER(m_EScoreEvent, LevelSystem::OnScoreEvent);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, LevelSystem::OnMultiBall);
EVENT_SUBSCRIBE_MEMBER(m_ECreatePowerUp, LevelSystem::OnCreatePowerUp);
EVENT_SUBSCRIBE_MEMBER(m_EPowerUpTaken, LevelSystem::OnPowerUpTaken);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, LevelSystem::OnStageCleared);
for (int i = 0; i < Lives(); i++) {
CreateLife(i);
}
return;
}
void dd::Systems::LevelSystem::CreateLife(int number)
{
auto life = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(life);
transform->Position = glm::vec3(-1.5f + number * 0.15f, -2.f, -5.f);
transform->Scale = glm::vec3(0.1f, 0.1f, 0.1f);
std::shared_ptr<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
lifeNr->Number = number;
auto model = m_World->AddComponent<Components::Model>(life);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
m_World->CommitEntity(life);
}
void dd::Systems::LevelSystem::Update(double dt)
{
if (!m_Initialized) {
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
m_Initialized = true;
}
if (Lives() < 0)
{
SetLives(3);
Events::GameOver e;
EventBroker->Publish(e);
}
}
void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto ball = m_World->GetComponent<Components::Ball>(entity);
if (ball != nullptr) {
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
if (glm::abs(transformBall->Velocity.y) < 2) {
if (transformBall->Velocity.y > 0) {
transformBall->Velocity.y = 2;
} else {
transformBall->Velocity.y = -2;
}
}
if (transformBall->Position.y < -EdgeY() - 4) {
if (MultiBalls() != 0) {
SetMultiBalls(MultiBalls() - 1);
// m_World->RemoveComponent<Components::Ball>(entity);
// m_World->RemoveComponent<Components::Transform>(entity);
// m_World->RemoveComponent<Components::CircleShape>(entity);
// m_World->RemoveComponent<Components::Physics>(entity);
m_World->RemoveEntity(entity);
} else if (Lives() == PastLives()) {
Events::ResetBall be;
EventBroker->Publish(be);
Events::LifeLost e;
e.Entity = entity;
EventBroker->Publish(e);
return;
}
} else if (transformBall->Position.x > EdgeX()) {
if (transformBall->Velocity.x > 0) {
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(1, 0));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
} else if (transformBall->Position.x < -EdgeX()) {
if (transformBall->Velocity.x < 0) {
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(-1, 0));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
} else if (transformBall->Position.y > EdgeY()) {
if (transformBall->Velocity.y > 0) {
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(0, 1));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
}
}
if (Lives() != PastLives()) {
auto life = m_World->GetComponent<Components::Life>(entity);
if (life != nullptr) {
if (life->Number + 1 == PastLives()) {
// m_World->RemoveComponent<Components::Life>(entity);
// m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveEntity(entity);
SetPastLives(Lives());
}
}
}
if (NumberOfBricks() <= 0) {
/*SetRestarting(true);
if (MultiBalls() <= 0 && PowerUps() <= 0) {
Events::ResetBall e;
EventBroker->Publish(e);
Events::ScoreEvent es;
es.Score = 500;
EventBroker->Publish(es);
Events::StageCleared ec;
EventBroker->Publish(ec);
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
} else {
if (ball != nullptr && MultiBalls() > 0) {
SetMultiBalls(MultiBalls() - 1);
m_World->RemoveComponent<Components::Ball>(entity);
m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveComponent<Components::CircleShape>(entity);
m_World->RemoveComponent<Components::Physics>(entity);
m_World->RemoveEntity(entity);
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
} else {
auto powerUp = m_World->GetComponent<Components::PowerUp>(entity);
if (powerUp != nullptr) {
SetPowerUps(PowerUps() - 1);
m_World->RemoveComponent<Components::PowerUp>(entity);
m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveEntity(entity);
}
}
}*/
}
}
void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 spacesBetweenBricks, float spaceToEdge)
{
SetNumberOfBricks(rows * lines);
std::cout << "You're only doing this once, right?" << std::endl;
int num = 0;
for (int i = 0; i < rows; i++) {
num++;
for (int j = 0; j < Lines(); j++) {
CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, num);
}
if (num == 7)
num = 0;
}
SetNumberOfBricks(rows * lines);
SetRestarting(false);
return;
}
void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBetweenBricks, float spaceToEdge, int num)
{
auto brick = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(brick);
auto model = m_World->AddComponent<Components::Model>(brick);
std::shared_ptr<Components::Brick> cBrick = m_World->AddComponent<Components::Brick>(brick);
std::shared_ptr<Components::RectangleShape> cRec = m_World->AddComponent<Components::RectangleShape>(brick);
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(brick);
cPhys->Static = false;
cPhys->GravityScale = 0.f;
cPhys->Category = CollisionLayer::Type::Brick;
cPhys->Mask = CollisionLayer::Type::Ball;
std::string fileName = "Textures/Bricks/";
fileName.append(std::to_string(num));
fileName.append(".png");
//sprite->SpriteFile = fileName;
model->ModelFile = "Models/Test/Brick/Brick.obj";
if ((line == 1 && row == 4) || (line == 3 && row == 2) || (line == 6 && row == 6)) {
std::shared_ptr<Components::PowerUpBrick> cPow = m_World->AddComponent<Components::PowerUpBrick>(brick);
}
float x = line * spacesBetweenBricks.x;
float y = row * spacesBetweenBricks.y;
transform->Scale = glm::vec3(0.8, 0.2, 0.2);
transform->Position = glm::vec3(x - 3, 5 - spaceToEdge - y , -10.f);
cBrick->Score = 10 * num;
//sound
auto collisionSound = m_World->AddComponent<Components::CollisionSound>(brick);
collisionSound->filePath = "Sounds/Brick/shortbrickbreak.wav";
m_World->CommitEntity(brick);
return;
}
void dd::Systems::LevelSystem::ProcessCollision()
{
// Like, go into brick component and check what it does upon collision. Maybe not done here?
return;
}
void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity)
{
auto brick = m_World->GetComponent<Components::Brick>(entity);
if (brick != nullptr) {
SetNumberOfBricks(NumberOfBricks() - 1);
Events::ScoreEvent es;
es.Score = brick->Score;
EventBroker->Publish(es);
/*if (numberOfBricks < 1) {
EndLevel();
}*/
}
return;
}
bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
{
EntityID entityBrick;
EntityID entityBall;
auto ball = m_World->GetComponent<Components::Ball>(event.Entity2);
auto brick = m_World->GetComponent<Components::Brick>(event.Entity1);
if (brick != nullptr) {
entityBrick = event.Entity1;
} else {
brick = m_World->GetComponent<Components::Brick>(event.Entity2);
if (brick != nullptr) {
entityBrick = event.Entity2;
} else {
return false;
}
}
if (ball != nullptr) {
entityBall = event.Entity2;
} else {
ball = m_World->GetComponent<Components::Ball>(event.Entity1);
if (ball != nullptr) {
entityBall = event.Entity1;
} else {
return false;
}
}
brick = m_World->GetComponent<Components::Brick>(entityBrick);
if (brick == nullptr) {
return false;
}
auto power = m_World->GetComponent<Components::PowerUpBrick>(entityBrick);
if (power != nullptr) {
Events::CreatePowerUp e;
auto transform = m_World->GetComponent<Components::Transform>(entityBrick);
e.Position = transform->Position;
EventBroker->Publish(e);
}
if (ball != nullptr && Restarting() == false) {
auto ballTransform = m_World->GetComponent<Components::Transform>(entityBall);
// m_World->RemoveComponent<Components::Brick>(entityBrick);
// m_World->RemoveComponent<Components::Transform>(entityBrick);
// m_World->RemoveComponent<Components::RectangleShape>(entityBrick);
// m_World->RemoveComponent<Components::Physics>(entityBrick);
// m_World->RemoveEntity(entityBrick);
auto physicsComponent = m_World->GetComponent<Components::Physics>(entityBrick);
physicsComponent->GravityScale = 1.f;
physicsComponent->Mask = CollisionLayer::Type::Water | CollisionLayer::Type::Wall;
auto transformComponentBrick = m_World->GetComponent<Components::Transform>(entityBrick);
auto transformComponentBall = m_World->GetComponent<Components::Transform>(entityBall);
Events::SetImpulse e;
e.Entity = entityBrick;
glm::vec2 point = glm::vec2(transformComponentBrick->Position.x + ((transformComponentBrick->Position.x - transformComponentBall->Position.x)/4), transformComponentBrick->Position.y + ((transformComponentBrick->Position.y - transformComponentBall->Position.y )/4));
e.Impulse = glm::normalize(point)/2.f;
e.Point = point;
EventBroker->Publish(e);
//TODO: Bricks dont collide with walls D=
SetNumberOfBricks(NumberOfBricks() - 1);
if (NumberOfBricks() <= 0) {
SetMultiBalls(MultiBalls() + 1);
}
Events::ScoreEvent es;
es.Score = brick->Score;
EventBroker->Publish(es);
<<<<<<< HEAD
// std::cout << NumberOfBricks() << std::endl;
=======
//std::cout << NumberOfBricks() << std::endl;
>>>>>>> origin/master
//std::cout << "Score: " << Score() << std::endl;
}
return true;
}
bool dd::Systems::LevelSystem::OnLifeLost(const dd::Events::LifeLost &event)
{
SetLives(Lives() - 1);
return true;
}
bool dd::Systems::LevelSystem::OnScoreEvent(const dd::Events::ScoreEvent &event)
{
SetScore(Score() += event.Score);
return true;
}
bool dd::Systems::LevelSystem::OnMultiBall(const dd::Events::MultiBall &event)
{
SetMultiBalls(MultiBalls()+2);
}
bool dd::Systems::LevelSystem::OnCreatePowerUp(const dd::Events::CreatePowerUp &event)
{
SetPowerUps(PowerUps() + 1);
auto powerUp = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(powerUp);
auto model = m_World->AddComponent<Components::Model>(powerUp);
std::shared_ptr<Components::CircleShape> cRec = m_World->AddComponent<Components::CircleShape>(powerUp);
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(powerUp);
cPhys->Static = false;
cPhys->Category = CollisionLayer::Type::PowerUp;
cPhys->Mask = CollisionLayer::Type::Pad;
std::shared_ptr<Components::PowerUp> cPow = m_World->AddComponent<Components::PowerUp>(powerUp);
transform->Position = event.Position;
transform->Scale = glm::vec3(0.2, 0.2, 0.2);
transform->Velocity = glm::vec3(0, -4, 0);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
m_World->CommitEntity(powerUp);
return true;
}
bool dd::Systems::LevelSystem::OnPowerUpTaken(const dd::Events::PowerUpTaken &event)
{
SetPowerUps(PowerUps() - 1);
return true;
}
bool dd::Systems::LevelSystem::OnStageCleared(const dd::Events::StageCleared &event)
{
return true;
}
void dd::Systems::LevelSystem::EndLevel()
{
Events::StageCleared e;
EventBroker->Publish(e);
return;
}
+63 -80
View File
@@ -26,27 +26,42 @@ void dd::Systems::PadSystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &PadSystem::OnKeyUp); EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &PadSystem::OnKeyUp);
EVENT_SUBSCRIBE_MEMBER(m_EContact, &PadSystem::OnContact); EVENT_SUBSCRIBE_MEMBER(m_EContact, &PadSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_EContactPowerUp, &PadSystem::OnContactPowerUp); EVENT_SUBSCRIBE_MEMBER(m_EContactPowerUp, &PadSystem::OnContactPowerUp);
EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &PadSystem::OnResetBall);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &PadSystem::OnMultiBall);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PadSystem::OnStageCleared); EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PadSystem::OnStageCleared);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &PadSystem::OnPause);
{
auto ent = m_World->CreateEntity();
m_World->SetProperty(ent, "Name", "Pad");
auto ctransform = m_World->AddComponent<Components::Transform>(ent);
ctransform->Position = glm::vec3(0.f, -3.5f, -10.f);
auto rectangleShape = m_World->AddComponent<Components::RectangleShape>(ent);
rectangleShape->Dimensions = glm::vec2(1.f, 0.5f);
auto physics = m_World->AddComponent<Components::Physics>(ent);
physics->CollisionType = CollisionType::Type::Dynamic;
physics->Category = CollisionLayer::Type::Pad;
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Ball | CollisionLayer::PowerUp);
physics->Calculate = true;
auto cModel = m_World->AddComponent<Components::Model>(ent);
cModel->ModelFile = "Models/Submarine2.obj";
auto pad = m_World->AddComponent<Components::Pad>(ent);
m_World->CommitEntity(ent);
SetEdge(3.2 - (ctransform->Scale.x / 2));
}
} }
void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{ {
auto ball = m_World->GetComponent<Components::Ball>(entity); auto templateCheck = m_World->GetComponent<Components::Template>(entity);
if (ball != nullptr) { if (templateCheck != nullptr){ return; }
if (ReplaceBall() == true) {
SetReplaceBall(false);
auto transform = m_World->GetComponent<Components::Transform>(entity);
transform->Position = glm::vec3(0.0f, 0.26f, -10.f);
transform->Velocity = glm::vec3(0.0f, -ball->Speed, 0.f);
}
}
} }
void dd::Systems::PadSystem::Update(double dt) void dd::Systems::PadSystem::Update(double dt)
{ {
if (IsPaused()) {
return;
}
if (Entity() == 0) { if (Entity() == 0) {
for (auto it = m_World->GetEntities()->begin(); it != m_World->GetEntities()->end(); it++) { for (auto it = m_World->GetEntities()->begin(); it != m_World->GetEntities()->end(); it++) {
if (m_World->GetProperty<std::string>(it->first, "Name") == "Pad") { if (m_World->GetProperty<std::string>(it->first, "Name") == "Pad") {
@@ -69,9 +84,15 @@ void dd::Systems::PadSystem::Update(double dt)
transform->Velocity.x = pad->MaxSpeed; transform->Velocity.x = pad->MaxSpeed;
} }
transform->Position += transform->Velocity * (float)dt; transform->Position += transform->Velocity * (float)dt;
if (transform->Position.x > Edge()) {
transform->Position.x = Edge();
} else if (transform->Position.x < -Edge()) {
transform->Position.x = -Edge();
}
transform->Velocity += acceleration * (float)dt; transform->Velocity += acceleration * (float)dt;
if (glm::abs(transform->Velocity.x) > 1 || (!Left() && !Right())) {
transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float) dt; transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float) dt;
}
if (Left()) { if (Left()) {
acceleration.x = -pad->AccelerationSpeed; acceleration.x = -pad->AccelerationSpeed;
@@ -85,38 +106,21 @@ void dd::Systems::PadSystem::Update(double dt)
SetPad(pad); SetPad(pad);
SetAcceleration(acceleration); SetAcceleration(acceleration);
if (MultiBall() == true) {
SetMultiBall(false);
Events::MultiBall e;
e.padTransform = transform;
EventBroker->Publish(e);
}
return; return;
} }
EntityID dd::Systems::PadSystem::CreateBall() bool dd::Systems::PadSystem::OnPause(const dd::Events::Pause &event)
{ {
auto ent = m_World->CreateEntity(); if (event.Type != "PadSystem" && event.Type != "All") {
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent); return false;
transform->Position = glm::vec3(0.5f, 0.26f, -10.f); }
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
auto model = m_World->AddComponent<Components::Model>(ent);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
//auto pointlight = m_World->AddComponent<Components::PointLight>(ent);
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
std::shared_ptr<Components::Ball> cball = m_World->AddComponent<Components::Ball>(ent);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;
physics->Category = CollisionLayer::Type::Ball;
physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall;
physics->Calculate = true;
cball->Speed = 5.f;
m_World->CommitEntity(ent); if (IsPaused()) {
SetPause(false);
return ent; } else {
SetPause(true);
}
return true;
} }
bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event) bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
@@ -135,9 +139,21 @@ bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
//acceleration.x = 0.01f; //acceleration.x = 0.01f;
SetRight(true); SetRight(true);
} else if (val == GLFW_KEY_R) { } else if (val == GLFW_KEY_R) {
SetReplaceBall(true); Events::ResetBall e;
EventBroker->Publish(e);
} else if (val == GLFW_KEY_M) { } else if (val == GLFW_KEY_M) {
SetMultiBall(true); Events::MultiBall e;
e.padTransform = Transform();
EventBroker->Publish(e);
} else if (val == GLFW_KEY_P) {
Events::Pause e;
e.Type = "All";
EventBroker->Publish(e);
} else if (val == GLFW_KEY_H) {
Events::HitLag e;
e.Time = 0.2;
e.Type = "All";
EventBroker->Publish(e);
} else if (val == GLFW_KEY_D) { } else if (val == GLFW_KEY_D) {
return false; return false;
} }
@@ -202,12 +218,13 @@ bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
//transform->Velocity = glm::vec3(movementX, movementY, 0.f); //transform->Velocity = glm::vec3(movementX, movementY, 0.f);
*/ */
return false;
} }
bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event) bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
{ {
EntityID entityPower; EntityID entityPower = 0;
EntityID entityPad; EntityID entityPad = 0;
auto powerUp = m_World->GetComponent<Components::PowerUp>(event.Entity1); auto powerUp = m_World->GetComponent<Components::PowerUp>(event.Entity1);
auto pad = m_World->GetComponent<Components::Pad>(event.Entity2); auto pad = m_World->GetComponent<Components::Pad>(event.Entity2);
if (powerUp != nullptr) { if (powerUp != nullptr) {
@@ -227,7 +244,7 @@ bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
} }
} }
if (entityPower == NULL || entityPad == NULL) { if (entityPower == 0 || entityPad == 0) {
return false; return false;
} }
@@ -236,9 +253,6 @@ bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
return false; return false;
} }
// m_World->RemoveComponent<Components::PowerUp>(entityPower);
// m_World->RemoveComponent<Components::CircleShape>(entityPower);
// m_World->RemoveComponent<Components::Physics>(entityPower);
m_World->RemoveEntity(entityPower); m_World->RemoveEntity(entityPower);
Events::PowerUpTaken ep; Events::PowerUpTaken ep;
ep.Name = "Something"; ep.Name = "Something";
@@ -251,40 +265,9 @@ bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
return true; return true;
} }
bool dd::Systems::PadSystem::OnResetBall(const dd::Events::ResetBall &event)
{
SetReplaceBall(true);
return true;
}
bool dd::Systems::PadSystem::OnMultiBall(const dd::Events::MultiBall &event)
{
auto ent1 = CreateBall();
auto ent2 = CreateBall();
auto transform1 = m_World->GetComponent<Components::Transform>(ent1);
auto transform2 = m_World->GetComponent<Components::Transform>(ent2);
auto ball1 = m_World->GetComponent<Components::Ball>(ent1);
auto ball2 = m_World->GetComponent<Components::Ball>(ent2);
auto padTransform = event.padTransform;
float x1 = padTransform->Position.x - 2, x2 = padTransform->Position.x + 2;
if (x1 < -3.1) {
x1 = 3;
}
if (x2 > 3.1) {
x2 = -3;
}
transform1->Position = glm::vec3(x1, -5.5, -10);
transform2->Position = glm::vec3(x2, -5.5, -10);
transform1->Velocity = glm::normalize(glm::vec3(5, 5 ,0.f)) * ball1->Speed;
transform2->Velocity = glm::normalize(glm::vec3(-5, 5 ,0.f)) * ball2->Speed;
return true;
}
bool dd::Systems::PadSystem::OnStageCleared(const dd::Events::StageCleared &event) bool dd::Systems::PadSystem::OnStageCleared(const dd::Events::StageCleared &event)
{ {
auto entity = CreateBall(); //auto entity = CreateBall();
return true; return true;
} }
-313
View File
@@ -1,313 +0,0 @@
//
// Created by Adniklastrator on 2015-09-10.
//
#include "PrecompiledHeader.h"
#include "Game/PadSystem.h"
#include "Core/World.h"
#include <iostream>
#include <Game/CPad.h>
#include <Rendering/CPointLight.h>
void dd::Systems::PadSystem::Initialize()
{
Events::BindKey r;
r.KeyCode = GLFW_KEY_RIGHT;
r.Command = "right";
EventBroker->Publish(r);
Events::BindKey l;
l.KeyCode = GLFW_KEY_LEFT;
l.Command = "left";
EventBroker->Publish(l);
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &PadSystem::OnKeyDown);
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &PadSystem::OnKeyUp);
EVENT_SUBSCRIBE_MEMBER(m_EContact, &PadSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_EContactPowerUp, &PadSystem::OnContactPowerUp);
EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &PadSystem::OnResetBall);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &PadSystem::OnMultiBall);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PadSystem::OnStageCleared);
}
void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto ball = m_World->GetComponent<Components::Ball>(entity);
if (ball != nullptr) {
if (ReplaceBall() == true) {
SetReplaceBall(false);
auto transform = m_World->GetComponent<Components::Transform>(entity);
transform->Position = glm::vec3(0.0f, 0.26f, -10.f);
transform->Velocity = glm::vec3(0.0f, -ball->Speed, 0.f);
}
}
}
void dd::Systems::PadSystem::Update(double dt)
{
if (Entity() == 0) {
for (auto it = m_World->GetEntities()->begin(); it != m_World->GetEntities()->end(); it++) {
if (m_World->GetProperty<std::string>(it->first, "Name") == "Pad") {
SetEntity(it->first);
SetTransform(m_World->GetComponent<Components::Transform>(Entity()));
SetPad(m_World->GetComponent<Components::Pad>(Entity()));
break;
}
}
}
auto transform = Transform();
auto pad = Pad();
auto acceleration = Acceleration();
if (transform->Velocity.x < -pad->MaxSpeed) {
transform->Velocity.x = -pad->MaxSpeed;
}
else if (transform->Velocity.x > pad->MaxSpeed) {
transform->Velocity.x = pad->MaxSpeed;
}
transform->Position += transform->Velocity * (float)dt;
transform->Velocity += acceleration * (float)dt;
transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float)dt;
if (Left()) {
acceleration.x = -pad->AccelerationSpeed;
<<<<<<< HEAD
}
else if (Right()) {
=======
} else if (Right()) {
>>>>>>> 72413dc0a93bd3a2f6ab9fa7e19bbc3b846232db
acceleration.x = pad->AccelerationSpeed;
} else {
acceleration.x = 0.f;
}
SetTransform(transform);
SetPad(pad);
SetAcceleration(acceleration);
if (MultiBall() == true) {
SetMultiBall(false);
Events::MultiBall e;
e.padTransform = transform;
EventBroker->Publish(e);
}
return;
}
EntityID dd::Systems::PadSystem::CreateBall()
{
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(0.5f, 0.26f, -10.f);
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
auto model = m_World->AddComponent<Components::Model>(ent);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
//auto pointlight = m_World->AddComponent<Components::PointLight>(ent);
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
std::shared_ptr<Components::Ball> cball = m_World->AddComponent<Components::Ball>(ent);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;
cball->Speed = 10;
m_World->CommitEntity(ent);
return ent;
}
bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
{
int val = event.KeyCode;
if (val == GLFW_KEY_UP) {
//std::cout << "Up!" << std::endl;
} else if (val == GLFW_KEY_DOWN) {
//std::cout << "Down!" << std::endl;
} else if (val == GLFW_KEY_LEFT) {
//std::cout << "Left!" << std::endl;
//acceleration.x = -0.01f;
SetLeft(true);
} else if (val == GLFW_KEY_RIGHT) {
//std::cout << "Right!" << std::endl;
//acceleration.x = 0.01f;
SetRight(true);
} else if (val == GLFW_KEY_R) {
SetReplaceBall(true);
} else if (val == GLFW_KEY_M) {
SetMultiBall(true);
} else if (val == GLFW_KEY_D) {
return false;
}
return true;
}
bool dd::Systems::PadSystem::OnKeyUp(const dd::Events::KeyUp &event)
{
int val = event.KeyCode;
if (val == GLFW_KEY_UP) {
} else if (val == GLFW_KEY_DOWN) {
} else if (val == GLFW_KEY_LEFT) {
SetLeft(false);
} else if (val == GLFW_KEY_RIGHT) {
SetRight(false);
}
return true;
}
bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
{
/*
EntityID entityBall = event.Entity2;
auto ball = m_World->GetComponent<Components::Ball>(entityBall);
if (ball == NULL) {
return false;
}
EntityID entityPad = event.Entity1;
auto pad = m_World->GetComponent<Components::Pad>(entityPad);
if (pad == NULL) {
return false;
}
auto transformBall = m_World->GetComponent<Components::Transform>(entityBall);
auto transformPad = m_World->GetComponent<Components::Transform>(entityPad);
float movementMultiplier = 0.5f;
//float movementX = (event.ContactPoint.x - transformPad->Position.x) * movementMultiplier;
//float movementY = glm::cos((abs(movementX) / (3.2f * movementMultiplier)) * 3.14159265359f / 2) * 2.f;
if (whatX > 0) {
movementX = movementMultiplier * whatX;
//std::cout << "Right!" << std::endl;
} else {
movementX = movementMultiplier * whatX;
//std::cout << "Left!" << std::endl;
}
// std::cout << movementX << " " << movementY << std::endl;
//float movementX = (event.ContactPoint.x - transformPad->Position.x) * movementMultiplier;
<<<<<<< HEAD
float movementY = glm::cos((abs(movementX) / ((1.6f) * movementMultiplier)) * 3.14159265359f / 2) + 1;
=======
float movementY = glm::cos((abs(movementX) / ((1.6f) * movementMultiplier)) * 3.14159265359f / 2)+ 0.2;
>>>>>>> 72413dc0a93bd3a2f6ab9fa7e19bbc3b846232db
//std::cout << movementX << " " << movementY << std::endl;
float len = glm::length<float>(transformBall->Velocity);
//auto pointlight = m_World->AddComponent<Components::PointLight>(ent);
transformBall->Velocity += glm::vec3(transformPad->Velocity.x, 0, 0);
transformBall->Velocity = glm::normalize(transformBall->Velocity) * len;
//transform->Velocity = glm::vec3(movementX, movementY, 0.f);
*/
}
bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
{
EntityID entityPower;
EntityID entityPad;
auto powerUp = m_World->GetComponent<Components::PowerUp>(event.Entity1);
auto pad = m_World->GetComponent<Components::Pad>(event.Entity2);
if (powerUp != nullptr) {
entityPower = event.Entity1;
} else {
powerUp = m_World->GetComponent<Components::PowerUp>(event.Entity2);
if (powerUp != nullptr) {
entityPower = event.Entity2;
}
}
if (pad != nullptr) {
entityPad = event.Entity2;
} else {
pad = m_World->GetComponent<Components::Pad>(event.Entity1);
if (pad != nullptr) {
entityPad = event.Entity1;
}
}
if (entityPower == NULL || entityPad == NULL) {
return false;
}
pad = m_World->GetComponent<Components::Pad>(entityPad);
if (pad == nullptr) {
return false;
}
m_World->RemoveComponent<Components::PowerUp>(entityPower);
m_World->RemoveComponent<Components::CircleShape>(entityPower);
m_World->RemoveComponent<Components::Physics>(entityPower);
m_World->RemoveEntity(entityPower);
Events::PowerUpTaken ep;
ep.Name = "Something";
EventBroker->Publish(ep);
Events::MultiBall e;
auto transform = m_World->GetComponent<Components::Transform>(entityPad);
e.padTransform = transform;
EventBroker->Publish(e);
return true;
}
bool dd::Systems::PadSystem::OnResetBall(const dd::Events::ResetBall &event)
{
SetReplaceBall(true);
return true;
}
bool dd::Systems::PadSystem::OnMultiBall(const dd::Events::MultiBall &event)
{
auto ent1 = CreateBall();
auto ent2 = CreateBall();
auto transform1 = m_World->GetComponent<Components::Transform>(ent1);
auto transform2 = m_World->GetComponent<Components::Transform>(ent2);
auto ball1 = m_World->GetComponent<Components::Ball>(ent1);
auto ball2 = m_World->GetComponent<Components::Ball>(ent2);
auto padTransform = event.padTransform;
float x1 = padTransform->Position.x - 2, x2 = padTransform->Position.x + 2;
if (x1 < -3.1) {
x1 = 3;
}
if (x2 > 3.1) {
x2 = -3;
}
transform1->Position = glm::vec3(x1, -5.5, -10);
transform2->Position = glm::vec3(x2, -5.5, -10);
transform1->Velocity = glm::normalize(glm::vec3(5, 5 ,0.f)) * ball1->Speed;
transform2->Velocity = glm::normalize(glm::vec3(-5, 5 ,0.f)) * ball2->Speed;
return true;
}
bool dd::Systems::PadSystem::OnStageCleared(const dd::Events::StageCleared &event)
{
auto entity = CreateBall();
return true;
}
bool dd::Systems::PadSystem::PadSteeringInputController::OnCommand(const Events::InputCommand &event)
{
std::string command = event.Command;
std::cout << "Command!" << std::endl;
if (command == "right") {
std::cout << "Right!" << std::endl;
} else if (command == "left") {
std::cout << "Left!" << std::endl;
}
return true;
}
+47
View File
@@ -0,0 +1,47 @@
#include "PrecompiledHeader.h"
#include "Physics/PhysicsSystem.h"
void dd::Systems::PhysicsSystem::ContactListener::BeginContact(b2Contact* contact)
{
b2WorldManifold worldManifold;
contact->GetWorldManifold(&worldManifold);
Events::Contact e;
e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
e.Normal = glm::normalize(glm::vec2(contact->GetManifold()->localNormal.x, contact->GetManifold()->localNormal.y));
e.SignificantNormal = glm::normalize((glm::abs(e.Normal.x) > glm::abs(e.Normal.y)) ? glm::vec2(e.Normal.x, 0) : glm::vec2(0, e.Normal.y));
m_PhysicsSystem->EventBroker->Publish(e);
}
void dd::Systems::PhysicsSystem::ContactListener::EndContact(b2Contact* contact)
{
}
void dd::Systems::PhysicsSystem::ContactListener::PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
{
EntityID entityA = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
EntityID entityB = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
auto physicsComponentA = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityA);
auto physicsComponentB = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityB);
if (physicsComponentA != nullptr && physicsComponentB != nullptr) {
if (physicsComponentA->Calculate || physicsComponentB->Calculate) {
// Turn of collisions
contact->SetEnabled(false);
}
}
}
void dd::Systems::PhysicsSystem::ContactListener::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
{
}
+135 -82
View File
@@ -2,37 +2,26 @@
#include "Physics/PhysicsSystem.h" #include "Physics/PhysicsSystem.h"
void dd::Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf) void dd::Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
{ {
cf->Register<Components::CircleShape>(); cf->Register<Components::CircleShape>();
//TODO: REGISTER PHYSICS COMPONENTS HERE
} }
void dd::Systems::PhysicsSystem::Initialize() void dd::Systems::PhysicsSystem::Initialize()
{ {
std::random_device rd; std::random_device rd;
gen = std::mt19937(rd()); gen = std::mt19937(rd());
m_DestructionListener = new DestructionListener(this); m_DestructionListener = new DestructionListener(this);
m_ContactListener = new ContactListener(this); m_ContactListener = new ContactListener(this);
m_Gravity = b2Vec2(0.f, -9.82f);
m_PhysicsWorld = new b2World(m_Gravity); m_PhysicsWorld = new b2World(m_Gravity);
m_TimeStep = 1.f/60.f;
m_VelocityIterations = 6;
m_PositionIterations = 2;
m_Accumulator = 0.f;
m_PhysicsWorld->SetContactListener(m_ContactListener); m_PhysicsWorld->SetContactListener(m_ContactListener);
m_PhysicsWorld->SetContactFilter(&m_ParticleContactDisabler); m_PhysicsWorld->SetContactFilter(&m_ParticleContactDisabler);
m_PhysicsWorld->SetDestructionListener(m_DestructionListener); m_PhysicsWorld->SetDestructionListener(m_DestructionListener);
InitializeWater(); InitializeWater();
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, &PhysicsSystem::SetImpulse);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &PhysicsSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, PhysicsSystem::SetImpulse);
EVENT_SUBSCRIBE_MEMBER(m_ECreateParticleSequence, &PhysicsSystem::CreateParticleSequence); EVENT_SUBSCRIBE_MEMBER(m_ECreateParticleSequence, &PhysicsSystem::CreateParticleSequence);
} }
@@ -53,7 +42,11 @@ void dd::Systems::PhysicsSystem::InitializeWater()
bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event) bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event)
{ {
b2Body* body = m_EntitiesToBodies[event.Entity]; auto it = m_EntitiesToBodies.find(event.Entity);
if(it == m_EntitiesToBodies.end()) {
LOG_ERROR("Entity: %i, Tried to set an impulse on a body that does not exsist", event.Entity);
return false;
}
b2Vec2 impulse; b2Vec2 impulse;
impulse.x = event.Impulse.x; impulse.x = event.Impulse.x;
@@ -63,41 +56,40 @@ bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event)
point.x = event.Point.x; point.x = event.Point.x;
point.y = event.Point.y; point.y = event.Point.y;
Impulse i; Impulse i;
i.Body = body; i.Body = it->second;
i.Impulse = impulse; i.Vector = impulse;
i.Point = point; i.Point = point;
m_Impulses.push_back(i); m_Impulses.push_back(i);
return true; return true;
} }
void dd::Systems::PhysicsSystem::Update(double dt) { void dd::Systems::PhysicsSystem::SyncEntitiesWithBodies()
{
m_Accumulator += dt;
while (m_Accumulator >= m_TimeStep) {
for (auto i : m_EntitiesToBodies) { for (auto i : m_EntitiesToBodies) {
EntityID entity = i.first; EntityID entity = i.first;
b2Body* body = i.second; b2Body* body = i.second;
if (body == nullptr) {
LOG_ERROR("This body should not exist, please fix this");
continue;
}
auto transformComponent = m_World->GetComponent<Components::Transform>(entity); auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (! transformComponent) { if (! transformComponent) {
continue; continue;
LOG_ERROR("RigidBody with no TransformComponent"); LOG_ERROR("RigidBody with no TransformComponent");
} }
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity); auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
if (! physicsComponent) { if (! physicsComponent) {
continue; continue;
LOG_ERROR("RigidBody with no PhysicsComponent"); LOG_ERROR("RigidBody with no PhysicsComponent");
} }
if (body == nullptr) {
LOG_ERROR("This body should not exist");
continue;
}
if (m_World->GetEntityParent(entity) == 0) { //TODO: Make this work with childs too if (m_World->GetEntityParent(entity) == 0) { //TODO: Make this work with childs too
b2Vec2 position; b2Vec2 position;
@@ -114,40 +106,39 @@ void dd::Systems::PhysicsSystem::Update(double dt) {
body->GetFixtureList()->SetFilterData(filter); body->GetFixtureList()->SetFilterData(filter);
} }
} }
UpdateParticleEmitters(dt);
for (auto i : m_Impulses) {
i.Body->ApplyLinearImpulse(i.Impulse, i.Point, true);
} }
m_Impulses.clear();
m_PhysicsWorld->Step(m_TimeStep, m_VelocityIterations, m_PositionIterations); void dd::Systems::PhysicsSystem::SyncBodiesWithEntities()
{
for (auto i : m_BodiesToEntities) {
for (auto i : m_EntitiesToBodies) { b2Body* body = i.first;
EntityID entity = i.first; EntityID entity = i.second;
b2Body *body = i.second;
if (body == nullptr) { if (body == nullptr) {
LOG_ERROR("This body should not exist"); LOG_ERROR("This body should not exist, please fix this");
continue; continue;
} }
auto transformComponent = m_World->GetComponent<Components::Transform>(entity); auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (!transformComponent) if (! transformComponent) {
continue; continue;
auto parent = m_World->GetEntityParent(entity); LOG_ERROR("RigidBody with no TransformComponent");
if (parent == 0) { }
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity); auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
if (physicsComponent->Calculate) { //TODO: REPLACE THIS WITH PARTICLE COLLISION FILTERS if (! physicsComponent) {
transformComponent->Position.x = continue;
transformComponent->Position.x + (transformComponent->Velocity.x * m_TimeStep); LOG_ERROR("RigidBody with no PhysicsComponent");
transformComponent->Position.y =
transformComponent->Position.y + (transformComponent->Velocity.y * m_TimeStep);
} }
else {
auto parent = m_World->GetEntityParent(entity);
if (parent == 0) {
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
if (physicsComponent->Calculate) { //TODO: REPLACE THIS WITH PARTICLE COLLISION FILTERS
transformComponent->Position.x = transformComponent->Position.x + (transformComponent->Velocity.x * m_TimeStep);
transformComponent->Position.y = transformComponent->Position.y + (transformComponent->Velocity.y * m_TimeStep);
} else {
b2Vec2 position = body->GetPosition(); b2Vec2 position = body->GetPosition();
transformComponent->Position.x = position.x; transformComponent->Position.x = position.x;
transformComponent->Position.y = position.y; transformComponent->Position.y = position.y;
@@ -161,14 +152,40 @@ void dd::Systems::PhysicsSystem::Update(double dt) {
} }
} }
} }
}
void dd::Systems::PhysicsSystem::Update(double dt)
{
if (m_Pause) {
return;
}
m_Accumulator += dt;
while(m_Accumulator >= m_TimeStep)
{
UpdateParticleEmitters(dt);
SyncEntitiesWithBodies();
//Apply Impulses Must be done after SyncEntitiesWithBodies
for (auto i : m_Impulses) {
i.Body->ApplyLinearImpulse(i.Vector, i.Point, true);
}
m_Impulses.clear();
//Update the PhysicsWorld
m_PhysicsWorld->Step(m_TimeStep, m_VelocityIterations, m_PositionIterations);
SyncBodiesWithEntities();
//water //water
b2Vec2 *positionBuffer = m_WaterParticleSystem->GetPositionBuffer(); b2Vec2 *positionBuffer = m_WaterParticleSystem->GetPositionBuffer();
for (auto i : m_EntitiesToWaterParticleHandle){ for (auto i : m_EntitiesToWaterParticleHandle){
EntityID entity = i.first; EntityID entity = i.first;
b2ParticleHandle *particleH = i.second; const b2ParticleHandle *particleH = i.second;
b2Vec2 positionB2 = positionBuffer[particleH->GetIndex()]; b2Vec2 positionB2 = positionBuffer[particleH->GetIndex()];
@@ -182,7 +199,7 @@ void dd::Systems::PhysicsSystem::Update(double dt) {
} }
auto transform = m_World->GetComponent<Components::Transform>(entity); auto transform = m_World->GetComponent<Components::Transform>(entity);
transform->Position = glm::vec3(position.x, position.y, -10); transform->Position = glm::vec3(position.x, position.y, -10.f);
} }
//Normal particles //Normal particles
@@ -193,7 +210,7 @@ void dd::Systems::PhysicsSystem::Update(double dt) {
} }
for (auto i : m_EntitiesToParticleHandle[e]){ for (auto i : m_EntitiesToParticleHandle[e]){
EntityID entity = i.first; EntityID entity = i.first;
b2ParticleHandle *particleH = i.second; const b2ParticleHandle *particleH = i.second;
b2Vec2 positionB2 = positionBuffer[particleH->GetIndex()]; b2Vec2 positionB2 = positionBuffer[particleH->GetIndex()];
glm::vec2 position = glm::vec2(positionB2.x, positionB2.y); glm::vec2 position = glm::vec2(positionB2.x, positionB2.y);
@@ -214,7 +231,6 @@ void dd::Systems::PhysicsSystem::Update(double dt) {
} }
} }
void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{ {
auto particle = m_World->GetComponent<Components::Particle>(entity); auto particle = m_World->GetComponent<Components::Particle>(entity);
@@ -223,7 +239,7 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
particle->LifeTime -= dt; particle->LifeTime -= dt;
if (particle->LifeTime <= 0) { if (particle->LifeTime <= 0) {
for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++) { for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++) {
b2ParticleHandle* handle = m_EntitiesToParticleHandle[i][entity]; const b2ParticleHandle* handle = m_EntitiesToParticleHandle[i][entity];
std::unordered_map<EntityID, const b2ParticleHandle*>::iterator iter1; std::unordered_map<EntityID, const b2ParticleHandle*>::iterator iter1;
std::unordered_map<const b2ParticleHandle*,EntityID>::iterator iter2; std::unordered_map<const b2ParticleHandle*,EntityID>::iterator iter2;
iter1 = m_EntitiesToParticleHandle[i].find(entity); iter1 = m_EntitiesToParticleHandle[i].find(entity);
@@ -241,6 +257,20 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
} }
} }
bool dd::Systems::PhysicsSystem::OnPause(const dd::Events::Pause &event)
{
if (event.Type != "PhysicsSystem" && event.Type != "All") {
return false;
}
if (m_Pause) {
m_Pause = false;
} else {
m_Pause = true;
}
return true;
}
void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity) void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity)
{ {
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity); auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
@@ -257,7 +287,12 @@ void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity)
} }
if (physicsComponent) { if (physicsComponent) {
auto it = m_EntitiesToBodies.find(entity);
if(it == m_EntitiesToBodies.end()) {
CreateBody(entity); CreateBody(entity);
} else {
LOG_ERROR("Tried to commit a body that already exists");
}
} else if (waterComponent) { } else if (waterComponent) {
CreateParticleGroup(entity); CreateParticleGroup(entity);
} else if (particleEmitterComponent) { } else if (particleEmitterComponent) {
@@ -268,21 +303,25 @@ void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity)
void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity) void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
{ {
auto physics = m_World->GetComponent<Components::Physics>(entity); /* auto physics = m_World->GetComponent<Components::Physics>(entity);
if (physics == nullptr) { if (physics == nullptr) {
return; return;
}*/
auto it = m_EntitiesToBodies.find(entity);
if(it == m_EntitiesToBodies.end()) {
LOG_ERROR("Trying to remove non-exsisting body, Entity: %i", entity);
return;
} }
b2Body* body = m_EntitiesToBodies[entity]; //It told me I was removing a lot of objects, and I didn't need that information, so I commented it out.
//LOG_INFO("Removing entity %i", entity);
if (body != nullptr) { it->second->GetWorld()->DestroyBody(it->second);
m_BodiesToEntities.erase(it->second);
m_EntitiesToBodies.erase(entity); m_EntitiesToBodies.erase(entity);
m_BodiesToEntities.erase(body); //delete body;
m_PhysicsWorld->DestroyBody(body);
} }
}
void dd::Systems::PhysicsSystem::CreateBody(EntityID entity) void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
{ {
@@ -292,7 +331,6 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
return; return;
} }
auto transformComponent = m_World->GetComponent<Components::Transform>(entity); auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if(!transformComponent) { if(!transformComponent) {
LOG_ERROR("No TransformComponent in CreateBody"); LOG_ERROR("No TransformComponent in CreateBody");
@@ -305,34 +343,28 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
bodyDef.position.Set(absoluteTransform.Position.x, absoluteTransform.Position.y); bodyDef.position.Set(absoluteTransform.Position.x, absoluteTransform.Position.y);
bodyDef.angle = -glm::eulerAngles(absoluteTransform.Orientation).z; bodyDef.angle = -glm::eulerAngles(absoluteTransform.Orientation).z;
if (physicsComponent->Static) { if (physicsComponent->CollisionType == CollisionType::Type::Static) {
bodyDef.type = b2_staticBody; bodyDef.type = b2_staticBody;
} else { } else if (physicsComponent->CollisionType == CollisionType::Type::Dynamic) {
bodyDef.type = b2_dynamicBody;
} else if (physicsComponent->CollisionType == CollisionType::Type::Kinematic) {
bodyDef.type = b2_dynamicBody; bodyDef.type = b2_dynamicBody;
} }
b2Body* body = m_PhysicsWorld->CreateBody(&bodyDef); b2Body* body = m_PhysicsWorld->CreateBody(&bodyDef);
b2Shape* pShape; b2Shape* pShape;
auto boxComponent = m_World->GetComponent<Components::RectangleShape>(entity); auto rectangleComponent = m_World->GetComponent<Components::RectangleShape>(entity);
if (boxComponent) { if (rectangleComponent) {
b2PolygonShape* bShape = new b2PolygonShape(); b2PolygonShape* bShape = new b2PolygonShape();
bShape->SetAsBox(absoluteTransform.Scale.x/2, absoluteTransform.Scale.y/2); bShape->SetAsBox(rectangleComponent->Dimensions.x/2.f, rectangleComponent->Dimensions.y/2.f);
pShape = bShape; pShape = bShape;
} else { } else {
auto circleComponent = m_World->GetComponent<Components::CircleShape>(entity); auto circleComponent = m_World->GetComponent<Components::CircleShape>(entity);
if (circleComponent) { if (circleComponent) {
pShape = new b2CircleShape(); pShape = new b2CircleShape();
pShape->m_radius = absoluteTransform.Scale.x; pShape->m_radius = circleComponent->Radius;
if (absoluteTransform.Scale.x != absoluteTransform.Scale.y && absoluteTransform.Scale.y != absoluteTransform.Scale.z) {
LOG_WARNING("Circles has to be of uniform scale.");
}
pShape->m_radius = absoluteTransform.Scale.x/2;
} }
} }
@@ -342,26 +374,28 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
fixtureDef.filter.maskBits = physicsComponent->Mask; fixtureDef.filter.maskBits = physicsComponent->Mask;
if(physicsComponent->Static) {
body->CreateFixture(&fixtureDef); //Density kanske ska vara 0 p statiska kroppar
}
else {
fixtureDef.shape = pShape; fixtureDef.shape = pShape;
fixtureDef.density = 10.f; fixtureDef.density = 10.f;
fixtureDef.restitution = 1.0f; fixtureDef.restitution = 1.0f;
fixtureDef.friction = 0.0f; fixtureDef.friction = 0.0f;
body->CreateFixture(&fixtureDef); body->CreateFixture(&fixtureDef);
}
delete pShape; delete pShape;
/* if(physicsComponent->Static) {
body->SetType(b2BodyType::b2_staticBody);
} else if (! physicsComponent->Static) {
body->SetType(b2BodyType::b2_dynamicBody);
}*/
body->SetGravityScale(physicsComponent->GravityScale); body->SetGravityScale(physicsComponent->GravityScale);
m_EntitiesToBodies.insert(std::make_pair(entity, body)); m_EntitiesToBodies.insert(std::make_pair(entity, body));
m_BodiesToEntities.insert(std::make_pair(body, entity)); m_BodiesToEntities.insert(std::make_pair(body, entity));
} }
void dd::Systems::PhysicsSystem::CreateParticleGroup(EntityID e) void dd::Systems::PhysicsSystem::CreateParticleGroup(EntityID e)
{ {
auto transform = m_World->GetComponent<Components::Transform>(e); auto transform = m_World->GetComponent<Components::Transform>(e);
@@ -397,6 +431,7 @@ void dd::Systems::PhysicsSystem::CreateParticleGroup(EntityID e)
} }
} }
void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt) void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
{ {
std::vector<EntityID> emittersToDelete; std::vector<EntityID> emittersToDelete;
@@ -584,10 +619,28 @@ b2ParticleSystem* dd::Systems::PhysicsSystem::CreateParticleSystem(float radius,
return m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef); return m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef);
} }
dd::Systems::PhysicsSystem::~PhysicsSystem() dd::Systems::PhysicsSystem::~PhysicsSystem()
{ {
for (auto i = m_BodiesToEntities.begin(); i != m_BodiesToEntities.end(); i++) {
b2Body* body = i->first;
body->GetWorld()->DestroyBody(body);
//delete body;
}
m_BodiesToEntities.clear();
m_EntitiesToBodies.clear();
m_Impulses.clear();
//TODO:REMOVE PARTICLE SYSTEMS
if (m_ContactListener != nullptr) { if (m_ContactListener != nullptr) {
delete m_ContactListener; delete m_ContactListener;
m_ContactListener = nullptr; m_ContactListener = nullptr;
} }
if (m_PhysicsWorld != nullptr) {
delete m_PhysicsWorld;
m_PhysicsWorld = nullptr;
}
} }
-363
View File
@@ -1,363 +0,0 @@
#include "PrecompiledHeader.h"
#include "Physics/PhysicsSystem.h"
void dd::Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
{
cf->Register<Components::CircleShape>();
}
void dd::Systems::PhysicsSystem::Initialize()
{
m_ContactListener = new ContactListener(this);
m_Gravity = b2Vec2(0.f, -9.82f);
m_PhysicsWorld = new b2World(m_Gravity);
m_TimeStep = 1.f/60.f;
m_VelocityIterations = 6;
m_PositionIterations = 2;
m_Accumulator = 0.f;
m_PhysicsWorld->SetContactListener(m_ContactListener);
InitializeWater();
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, PhysicsSystem::SetImpulse);
}
void dd::Systems::PhysicsSystem::InitializeWater()
{
b2ParticleSystemDef m_ParticleSystemDef;
m_ParticleSystemDef.radius = 0.13f;
m_ParticleSystem = m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef);
}
bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event)
{
b2Body* body = m_EntitiesToBodies[event.Entity];
b2Vec2 impulse;
impulse.x = event.Impulse.x;
impulse.y = event.Impulse.y;
b2Vec2 point;
point.x = event.Point.x;
point.y = event.Point.y;
Impulse i;
i.Body = body;
i.Impulse = impulse;
i.Point = point;
m_Impulses.push_back(i);
return true;
}
void dd::Systems::PhysicsSystem::Update(double dt)
{
m_Accumulator += dt;
while(m_Accumulator >= m_TimeStep)
{
for (auto i : m_EntitiesToBodies) {
EntityID entity = i.first;
b2Body* body = i.second;
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (! transformComponent) {
continue;
LOG_ERROR("RigidBody with no TransformComponent");
}
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
if (! physicsComponent) {
continue;
LOG_ERROR("RigidBody with no PhysicsComponent");
}
if (body == nullptr) {
LOG_ERROR("This body should not exist");
continue;
}
if (m_World->GetEntityParent(entity) == 0) { //TODO: Make this work with childs too
b2Vec2 position;
position.x = transformComponent->Position.x;
position.y = transformComponent->Position.y;
float angle = -glm::eulerAngles(transformComponent->Orientation).z;
body->SetTransform(position, angle);
body->SetLinearVelocity(b2Vec2(transformComponent->Velocity.x, transformComponent->Velocity.y));
body->SetGravityScale(physicsComponent->GravityScale);
<<<<<<< HEAD
b2Filter filter;
filter.categoryBits = physicsComponent->Category;
filter.maskBits = physicsComponent->Mask;
body->GetFixtureList()->SetFilterData(filter);
}
}
for (auto i : m_Impulses) {
i.Body->ApplyLinearImpulse(i.Impulse, i.Point, true);
=======
>>>>>>> origin/master
}
m_Impulses.clear();
<<<<<<< HEAD
=======
for (auto i : m_Impulses) {
i.Body->ApplyLinearImpulse(i.Impulse, i.Point, true);
}
m_Impulses.clear();
m_Accumulator += dt;
while(m_Accumulator >= m_TimeStep)
{
>>>>>>> origin/master
m_PhysicsWorld->Step(m_TimeStep, m_VelocityIterations, m_PositionIterations);
m_Accumulator -= dt;
<<<<<<< HEAD
=======
for (auto i : m_EntitiesToBodies) {
EntityID entity = i.first;
b2Body* body = i.second;
>>>>>>> origin/master
for (auto i : m_EntitiesToBodies) {
EntityID entity = i.first;
b2Body* body = i.second;
if (body == nullptr) {
LOG_ERROR("This body should not exist");
continue;
}
<<<<<<< HEAD
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (! transformComponent)
continue;
if (m_World->GetEntityParent(entity) == 0) {
b2Vec2 position = body->GetPosition();
transformComponent->Position.x = position.x;
transformComponent->Position.y = position.y;
=======
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (! transformComponent)
continue;
auto parent = m_World->GetEntityParent(entity);
if (parent == 0) {
b2Vec2 position = body->GetPosition();
transformComponent->Position.x = position.x;
transformComponent->Position.y = position.y;
>>>>>>> origin/master
float angle = body->GetAngle();
transformComponent->Orientation = glm::quat(glm::vec3(0, 0, -angle));
<<<<<<< HEAD
b2Vec2 velocity = body->GetLinearVelocity();
transformComponent->Velocity.x = velocity.x;
transformComponent->Velocity.y = velocity.y;
}
=======
>>>>>>> origin/master
}
}
b2Vec2* positionBuffer = m_ParticleSystem->GetPositionBuffer();
for (auto i : m_EntitiesToParticleHandle) {
EntityID entity = i.first;
b2ParticleHandle* particleH = i.second;
b2Vec2 positionB2 = positionBuffer[particleH->GetIndex()];
glm::vec2 position = glm::vec2(positionB2.x, positionB2.y);
EntityID entityParent = m_World->GetEntityParent(entity);
auto transform = m_World->GetComponent<Components::Transform>(entity);
auto transformParent = m_World->GetComponent<Components::Transform>(entityParent);
transform->Position = glm::vec3(position.x, position.y, -10) - transformParent->Position;
}
}
void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
}
void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity)
{
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
auto waterComponent = m_World->GetComponent<Components::WaterVolume>(entity);
if (physicsComponent && waterComponent) {
LOG_ERROR("Entity has both water and physics component, this is illegal. The police has been alerted.");
return;
}
if (physicsComponent) {
CreateBody(entity);
} else if (waterComponent) {
CreateParticleGroup(entity);
}
}
void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
{
auto physics = m_World->GetComponent<Components::Physics>(entity);
if (physics == nullptr) {
return;
}
b2Body* body = m_EntitiesToBodies[entity];
if (body != nullptr) {
m_EntitiesToBodies.erase(entity);
m_BodiesToEntities.erase(body);
m_PhysicsWorld->DestroyBody(body);
}
}
void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
{
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
if(!physicsComponent){
LOG_ERROR("No PhysicsComponent in CreateBody");
return;
}
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if(!transformComponent) {
LOG_ERROR("No TransformComponent in CreateBody");
return;
}
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
b2BodyDef bodyDef;
bodyDef.position.Set(absoluteTransform.Position.x, absoluteTransform.Position.y);
bodyDef.angle = -glm::eulerAngles(absoluteTransform.Orientation).z;
if (physicsComponent->Static) {
bodyDef.type = b2_staticBody;
} else {
bodyDef.type = b2_dynamicBody;
}
b2Body* body = m_PhysicsWorld->CreateBody(&bodyDef);
b2Shape* pShape;
auto boxComponent = m_World->GetComponent<Components::RectangleShape>(entity);
if (boxComponent) {
b2PolygonShape* bShape = new b2PolygonShape();
bShape->SetAsBox(absoluteTransform.Scale.x/2, absoluteTransform.Scale.y/2);
pShape = bShape;
} else {
auto circleComponent = m_World->GetComponent<Components::CircleShape>(entity);
if (circleComponent) {
pShape = new b2CircleShape();
pShape->m_radius = absoluteTransform.Scale.x;
if (absoluteTransform.Scale.x != absoluteTransform.Scale.y && absoluteTransform.Scale.y != absoluteTransform.Scale.z) {
LOG_WARNING("Circles has to be of uniform scale.");
}
pShape->m_radius = absoluteTransform.Scale.x/2;
}
}
b2FixtureDef fixtureDef;
fixtureDef.shape = pShape;
fixtureDef.filter.categoryBits = physicsComponent->Category;
fixtureDef.filter.maskBits = physicsComponent->Mask;
if(physicsComponent->Static) {
body->CreateFixture(&fixtureDef); //Density kanske ska vara 0 på statiska kroppar
}
else {
fixtureDef.shape = pShape;
fixtureDef.density = 1.f;
fixtureDef.restitution = 1.0f;
fixtureDef.friction = 0.0f;
body->CreateFixture(&fixtureDef);
}
delete pShape;
body->SetGravityScale(physicsComponent->GravityScale);
m_EntitiesToBodies.insert(std::make_pair(entity, body));
m_BodiesToEntities.insert(std::make_pair(body, entity));
}
void dd::Systems::PhysicsSystem::CreateParticleGroup(EntityID e)
{
//TODO: Lägg alla pd i en lista
auto transform = m_World->GetComponent<Components::Transform>(e);
if (!transform) {
LOG_ERROR("No Transform component in CreateParticleGroup");
return;
}
b2ParticleGroupDef pd;
b2PolygonShape shape;
shape.SetAsBox(transform->Scale.x/2.f, transform->Scale.y/2.f);
pd.shape = &shape;
pd.flags = b2_tensileParticle;
pd.position.Set(transform->Position.x, transform->Position.y);
//TODO: PUT IN LIST
t_watergroup = m_ParticleSystem->CreateParticleGroup(pd);
b2Vec2* t_ParticlePositions = m_ParticleSystem->GetPositionBuffer();
for(int i = 0; i < m_ParticleSystem->GetParticleCount(); i++){
{
auto t_waterparticle = m_World->CreateEntity(e);
auto transformChild = m_World->AddComponent<Components::Transform>(t_waterparticle);
//auto sprite = m_World->AddComponent<Components::Sprite>(t_waterparticle);
transformChild->Position = glm::vec3(t_ParticlePositions[i].x - transform->Position.x, t_ParticlePositions[i].y - transform->Position.y, -9.5f);
transformChild->Scale = glm::vec3(m_ParticleSystem->GetRadius())/transform->Scale;
//sprite->SpriteFile = "Textures/Ball.png";
m_World->CommitEntity(t_waterparticle);
m_EntitiesToParticleHandle.insert(std::make_pair(t_waterparticle, m_ParticleSystem->GetParticleHandleFromIndex(i)));
m_ParticleHandleToEntities.insert(std::make_pair( m_ParticleSystem->GetParticleHandleFromIndex(i), t_waterparticle));
}
}
LOG_INFO("ParticleCount: %i", m_ParticleSystem->GetParticleCount());
}
dd::Systems::PhysicsSystem::~PhysicsSystem()
{
if (m_ContactListener != nullptr) {
delete m_ContactListener;
m_ContactListener = nullptr;
}
}
+10 -10
View File
@@ -26,7 +26,7 @@ ALuint dd::Sound::LoadFile(std::string path)
return 0; return 0;
} }
fread(&m_Size, sizeof(unsigned long), 1, fp); fread(&m_Size, 4*sizeof(char), 1, fp);
fread(m_Type, sizeof(char), 4, fp); fread(m_Type, sizeof(char), 4, fp);
if (m_Type[0] != 'W' || m_Type[1] != 'A' || m_Type[2] != 'V' || m_Type[3]!= 'E') { if (m_Type[0] != 'W' || m_Type[1] != 'A' || m_Type[2] != 'V' || m_Type[3]!= 'E') {
LOG_ERROR("ERROR: Not WAVE-file"); LOG_ERROR("ERROR: Not WAVE-file");
@@ -40,13 +40,13 @@ ALuint dd::Sound::LoadFile(std::string path)
} }
//READ THE DATA FROM WAVE-FILE //READ THE DATA FROM WAVE-FILE
fread(&m_ChunkSize, sizeof(unsigned long), 1, fp); fread(&m_ChunkSize, 4*sizeof(char), 1, fp);
fread(&m_FormatType, sizeof(short), 1, fp); fread(&m_FormatType, 2*sizeof(char), 1, fp);
fread(&m_Channels, sizeof(short), 1, fp); fread(&m_Channels, 2*sizeof(char), 1, fp);
fread(&m_SampleRate, sizeof(unsigned long), 1, fp); fread(&m_SampleRate, 4*sizeof(char), 1, fp);
fread(&m_AvgBytesPerSec, sizeof(unsigned long), 1, fp); fread(&m_AvgBytesPerSec, 4*sizeof(char), 1, fp);
fread(&m_BytesPerSample, sizeof(short), 1, fp); fread(&m_BytesPerSample, 2*sizeof(char), 1, fp);
fread(&m_BitsPerSample, sizeof(short), 1, fp); fread(&m_BitsPerSample, 2*sizeof(char), 1, fp);
fread(m_Type, sizeof(char), 4, fp); fread(m_Type, sizeof(char), 4, fp);
if (m_Type[0] !='d' || m_Type[1] != 'a' || m_Type[2] != 't' || m_Type[3] != 'a') { if (m_Type[0] !='d' || m_Type[1] != 'a' || m_Type[2] != 't' || m_Type[3] != 'a') {
@@ -54,10 +54,10 @@ ALuint dd::Sound::LoadFile(std::string path)
return 0; return 0;
} }
fread(&m_DataSize, sizeof(unsigned long), 1, fp); fread(&m_DataSize, 4*sizeof(char), 1, fp);
unsigned char* buf = new unsigned char[m_DataSize]; unsigned char* buf = new unsigned char[m_DataSize];
fread(buf, sizeof(unsigned char), m_DataSize, fp); fread(buf, sizeof(char), m_DataSize, fp);
fclose(fp); fclose(fp);
// Create buffer // Create buffer
+45 -41
View File
@@ -19,22 +19,28 @@ void dd::Systems::SoundSystem::Initialize()
else { else {
LOG_ERROR("OpenAL failed to initialize."); LOG_ERROR("OpenAL failed to initialize.");
} }
alGetError(); alGetError();
//Probably unnecessary. vec3(0) probably default.
const ALfloat pos[3] = {0, 0, 0};
//alListenerfv(AL_POSITION, pos);
m_SFXMasterVolume = 1.f;
m_BGMMasterVolume = 1.f;
//Subscribe to events //Subscribe to events
EVENT_SUBSCRIBE_MEMBER(m_EContact, &SoundSystem::OnContact); EVENT_SUBSCRIBE_MEMBER(m_EContact, &SoundSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::OnPlaySound); EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::OnPlaySound);
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound); EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound);
EVENT_SUBSCRIBE_MEMBER(m_EMasterVolume, &SoundSystem::OnMasterVolume); EVENT_SUBSCRIBE_MEMBER(m_EMasterVolume, &SoundSystem::OnMasterVolume);
//Todo: Move this
{
dd::Events::PlaySound e;
e.FilePath = "Sounds/BGM/under-the-sea-instrumental.wav";
e.IsAmbient = true;
EventBroker->Publish(e);
}
{
dd::Events::PlaySound e;
e.FilePath = "Sounds/BGM/water-flowing.wav";
e.Gain = 0.3f;
e.IsAmbient = true;
EventBroker->Publish(e);
}
} }
@@ -44,7 +50,7 @@ void dd::Systems::SoundSystem::Update(double dt)
//Clean up none-active sources //Clean up none-active sources
//Only used for SFX's. BGM's are handled on stop sound. //Only used for SFX's. BGM's are handled on stop sound.
std::vector<ALuint> deleteList; std::vector<ALuint> deleteList;
for (auto item : m_SFXSourcesToBuffers) { for (auto& item : m_SFXSourcesToBuffers) {
ALint sourceState; ALint sourceState;
alGetSourcei(item.first, AL_SOURCE_STATE, &sourceState); alGetSourcei(item.first, AL_SOURCE_STATE, &sourceState);
if (sourceState == AL_STOPPED) { if (sourceState == AL_STOPPED) {
@@ -70,32 +76,32 @@ ALuint dd::Systems::SoundSystem::CreateSource()
bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event) bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event)
{ {
//Loading and binding sound buffer to source //Loading and binding sound buffer to source
Sound *sound = ResourceManager::Load<Sound>(event.path); Sound *sound = ResourceManager::Load<Sound>(event.FilePath);
if (sound == nullptr) { if (sound == nullptr) {
return false; return false;
} }
ALuint source = CreateSource(); ALuint source = CreateSource();
ALuint buffer = sound->Buffer(); ALuint buffer = sound->Buffer();
alSourcei(source, AL_BUFFER, buffer); alSourcei(source, AL_BUFFER, buffer);
sound->SetGain(event.Gain);
//Sound settings //Sound settings
float relativeVolume = 1.f; float relativeVolume = 1.f;
if (event.isAmbient) { if (event.IsAmbient) {
alSourcei(source, AL_LOOPING, AL_TRUE); alSourcei(source, AL_LOOPING, AL_TRUE);
relativeVolume = m_BGMMasterVolume; relativeVolume = m_BGMMasterVolume;
m_BGMSourcesToBuffers[source] = sound; m_BGMSourcesToBuffers[source] = sound;
} }
else if (!event.isAmbient) else if (!event.IsAmbient)
{ {
m_SFXSourcesToBuffers[source] = sound; m_SFXSourcesToBuffers[source] = sound;
alSourcei(source, AL_LOOPING, AL_FALSE); alSourcei(source, AL_LOOPING, AL_FALSE);
relativeVolume = m_SFXMasterVolume; relativeVolume = m_SFXMasterVolume;
} }
alSourcef(source, AL_GAIN, (event.volume * relativeVolume)); alSourcef(source, AL_GAIN, (sound->Gain() * relativeVolume));
alSourcef(source, AL_PITCH, event.pitch); alSourcef(source, AL_PITCH, event.Pitch);
//Play //Play
alSourcePlay(source); alSourcePlay(source);
@@ -104,53 +110,50 @@ bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event)
bool dd::Systems::SoundSystem::OnStopSound(const dd::Events::StopSound &event) bool dd::Systems::SoundSystem::OnStopSound(const dd::Events::StopSound &event)
{ {
ALuint itemToDeleted;
//TODO: Delete sources for bgms for (auto& item : m_BGMSourcesToBuffers)
ALuint itemToDelete;
for (auto item : m_BGMSourcesToBuffers)
{ {
if (item.second->Path() == event.path) { if (item.second->Path() == event.FilePath) {
itemToDelete = item.first; itemToDeleted = item.first;
break; break;
} }
} }
alSourceStop(itemToDelete); alSourceStop(itemToDeleted);
alDeleteSources(1, &itemToDelete); alDeleteSources(1, &itemToDeleted);
m_BGMSourcesToBuffers.erase(itemToDelete); m_BGMSourcesToBuffers.erase(itemToDeleted);
//Should not because SFX's should be very short. //Should not happen because SFX's should be very short.
for (auto item : m_SFXSourcesToBuffers) for (auto item : m_SFXSourcesToBuffers)
{ {
if (item.second->Path() == event.path) { if (item.second->Path() == event.FilePath) {
alSourceStop(item.first); alSourceStop(item.first);
return true; return true;
} }
} }
return false; return false;
} }
bool dd::Systems::SoundSystem::OnMasterVolume(const dd::Events::MasterVolume &event) bool dd::Systems::SoundSystem::OnMasterVolume(const dd::Events::MasterVolume &event)
{ {
//TODO: Make the volume depend on the value given when stored. if (event.IsAmbient) {
//TODO: .. now it ONLY uses the master volume m_BGMMasterVolume = event.Gain;
if (event.isAmbient) { for (auto& item : m_BGMSourcesToBuffers)
m_BGMMasterVolume = event.gain;
for (auto item : m_BGMSourcesToBuffers)
{ {
alSourcef(item.first, AL_GAIN, event.gain); alSourcef(item.first, AL_GAIN, (item.second->Gain() * m_BGMMasterVolume));
} }
return true;
} }
else if (!event.isAmbient) { else if (!event.IsAmbient) {
m_SFXMasterVolume = event.gain; m_SFXMasterVolume = event.Gain;
for (auto item : m_SFXSourcesToBuffers) for (auto& item : m_SFXSourcesToBuffers)
{ {
alSourcef(item.first, AL_GAIN, event.gain); alSourcef(item.first, AL_GAIN, (item.second->Gain() * m_SFXMasterVolume));
} }
return true;
} }
return false;
} }
//On contact: play the sound given in the CCOllisionSound.
bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event) bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
{ {
//Check which entity has the collisionSound component. //Check which entity has the collisionSound component.
@@ -167,8 +170,8 @@ bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
{ {
dd::Events::PlaySound e; dd::Events::PlaySound e;
e.path = collisionSound->filePath; e.FilePath = collisionSound->FilePath;
e.isAmbient = false; e.IsAmbient = false;
EventBroker->Publish(e); EventBroker->Publish(e);
} }
@@ -187,7 +190,8 @@ bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
e.ParticleLifeTime = 3.f; e.ParticleLifeTime = 3.f;
EventBroker->Publish(e); EventBroker->Publish(e);
} }
//return true; return true;
} }
+5 -6
View File
@@ -1,18 +1,17 @@
project(tests) project(tests)
find_package(PNG REQUIRED)
find_package(Boost REQUIRED COMPONENTS chrono thread unit_test_framework) find_package(Boost REQUIRED COMPONENTS chrono thread unit_test_framework)
include_directories( include_directories(
${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/include
${PNG_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
) )
set(SOURCE_FILES
main.cpp file(GLOB SOURCE_FILES
FileWatcherTest.cpp "*.cpp"
EventTest.cpp
ComponentCopyTest.cpp
EntityCloneTest.cpp
) )
if(CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_COMPILER_IS_GNUCXX)
+2 -2
View File
@@ -10,7 +10,7 @@ struct EventFixture
EventFixture() EventFixture()
{ {
this->EventBroker = new dd::EventBroker(); this->EventBroker = new dd::EventBroker();
m_EEventType = decltype(m_EEventType)(std::bind(&OnEvent, this, std::placeholders::_1)); m_EEventType = decltype(m_EEventType)(std::bind(&EventFixture::OnEvent, this, std::placeholders::_1));
this->EventBroker->Subscribe(m_EEventType); this->EventBroker->Subscribe(m_EEventType);
Run(); Run();
Check(); Check();
@@ -40,7 +40,7 @@ struct EventFixture
// Publish the event // Publish the event
this->EventBroker->Publish(Before); this->EventBroker->Publish(Before);
// Clear to swap buffers // Clear to swap buffers
this->EventBroker->Clear(); this->EventBroker->Swap();
// Process the event // Process the event
this->EventBroker->template Process<EventFixture>(); this->EventBroker->template Process<EventFixture>();
} }
+41
View File
@@ -0,0 +1,41 @@
#include <boost/test/unit_test.hpp>
#include "PrecompiledHeader.h"
#include "Core/EventBroker.h"
#include "GUI/Frame.h"
using namespace dd;
BOOST_AUTO_TEST_CASE(FrameTest)
{
EventBroker eb;
GUI::Frame baseFrame(&eb);
baseFrame.X = 100;
baseFrame.Y = 100;
// Create a frame with a relative position to baseFrame
GUI::Frame f1(&baseFrame, "f1");
f1.X = 50;
f1.Y = 50;
f1.Width = 50;
f1.Height = 50;
BOOST_CHECK(f1.Left() == 150); BOOST_CHECK(baseFrame.X + f1.X == 150);
BOOST_CHECK(f1.Top() == 150); BOOST_CHECK(baseFrame.Y + f1.Y == 150);
BOOST_CHECK(f1.Right() == 200); BOOST_CHECK(baseFrame.X + f1.X + f1.Width == 200);
BOOST_CHECK(f1.Bottom() == 200); BOOST_CHECK(baseFrame.Y + f1.Y + f1.Height == 200);
// Create a frame to the right of f1
GUI::Frame f2(&baseFrame, "f2");
f2.SetLeft(f1.Right());
f2.SetTop(f1.Bottom());
f2.Width = 50;
f2.Height = 50;
BOOST_CHECK(f2.X == 100); BOOST_CHECK(f2.X == f1.X + f1.Width);
BOOST_CHECK(f2.Left() == 200); BOOST_CHECK(f2.Left() == f1.Right());
BOOST_CHECK(f2.Y == 100); BOOST_CHECK(f2.Y == f1.Y + f1.Height);
BOOST_CHECK(f2.Top() == 200); BOOST_CHECK(f2.Top() == f1.Bottom());
BOOST_CHECK(f2.Right() == 250); BOOST_CHECK(f2.Right() == f1.Right() + f2.Width);
BOOST_CHECK(f2.Bottom() == 250); BOOST_CHECK(f2.Bottom() == f1.Bottom() + f2.Height);
}
+6
View File
@@ -1,6 +1,12 @@
#ifndef NAMESPACE_FILENAME_H__ #ifndef NAMESPACE_FILENAME_H__
#define NAMESPACE_FILENAME_H__ #define NAMESPACE_FILENAME_H__
#include <standard_library>
#include <external_dependency>
#include "Internal/Header.h"
namespace dd namespace dd
{ {