Compare commits
808 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d95ab97a7 | |||
| d7309091a1 | |||
| 3e859eed32 | |||
| 4f5b87d0f7 | |||
| b844f35e95 | |||
| 9c9f30790e | |||
| 55abdfc7d0 | |||
| e8ad19f267 | |||
| 44b9bb2cd1 | |||
| 377bb36ce2 | |||
| b95f08f62e | |||
| 6a4399934c | |||
| 3a2d28022b | |||
| d3be16ab38 | |||
| 19ccd823ef | |||
| 81aa469595 | |||
| 9ea52db3d5 | |||
| 398ccd5b3f | |||
| c48389d97f | |||
| c553d79439 | |||
| 5c144c2099 | |||
| dae5b667a8 | |||
| 4161dbfaf2 | |||
| 55d0b2b361 | |||
| 61a7a991a8 | |||
| ed5bcc9706 | |||
| b51c4b4f30 | |||
| e1bea5e571 | |||
| ec7908b010 | |||
| afa869f4e6 | |||
| 3ddb63700c | |||
| a9ba4bb759 | |||
| a2f5e367b2 | |||
| 1826baa48d | |||
| baf9492026 | |||
| 131b0b433a | |||
| 00b7f27829 | |||
| dd63efb355 | |||
| 0b631e006c | |||
| 64833f86da | |||
| 518ea93adc | |||
| 07218418a2 | |||
| 6d8d7963a1 | |||
| 69a13c5ed6 | |||
| 011f71ea61 | |||
| 4894daa273 | |||
| 9a1dcc2f53 | |||
| 8d2fc45d7d | |||
| 867a86fd79 | |||
| 7ccea0d1c0 | |||
| 7c6468c1dd | |||
| 5285397101 | |||
| ba295099f3 | |||
| 754fb71850 | |||
| dd25f068af | |||
| bf273db9c2 | |||
| 5d3d82bf3f | |||
| 36ba3fa132 | |||
| 3002afa1e9 | |||
| f9936f6107 | |||
| 905af46731 | |||
| 8b0bc76a9f | |||
| fb2d49f1e0 | |||
| cc6981e35f | |||
| f9a5f60969 | |||
| b74a5aabcd | |||
| 7c88392cf3 | |||
| 20b121766a | |||
| f32b8a9b4f | |||
| ccb7adbd10 | |||
| 8e7af9ce88 | |||
| 752f8f82f9 | |||
| 1f2d0b8e76 | |||
| ec409c8177 | |||
| 82d5a5c181 | |||
| 420d39d467 | |||
| e2e2e243d4 | |||
| 5d0f9e1bb8 | |||
| d3f855c69b | |||
| 8749d1fd93 | |||
| 7205d6692c | |||
| 7b9c016082 | |||
| 235f3b57e0 | |||
| f23b929f8a | |||
| 48b9a9b264 | |||
| d7196df760 | |||
| 957458d489 | |||
| 3b24aae422 | |||
| a751531e18 | |||
| 4794965166 | |||
| a532d33579 | |||
| 8778bfdc4b | |||
| 42b37be6f5 | |||
| cbf8538c24 | |||
| 4ced27a905 | |||
| 57f92a8b2e | |||
| a8bbbeabb7 | |||
| e2f5494380 | |||
| 9a1714a881 | |||
| 18f119224a | |||
| ba384c182a | |||
| 3b90465afd | |||
| 284009baa7 | |||
| be4ec0349b | |||
| 1ed4f85d62 | |||
| 12f86f22de | |||
| 30aa11c083 | |||
| b89f6f2ece | |||
| 5f0cf826d4 | |||
| c2197d5e71 | |||
| 13e67746b4 | |||
| a86a41ad46 | |||
| fd11f4e0e6 | |||
| 19792f8aec | |||
| 0666c69680 | |||
| 16f7f043fc | |||
| bd9d969f8e | |||
| 41626328c9 | |||
| bbd468af1a | |||
| 49b15f4710 | |||
| ff67b62792 | |||
| 3a23ba93af | |||
| 15cd3648a3 | |||
| fe7bbbbb3d | |||
| e6e2421ba0 | |||
| f2119f77a9 | |||
| 50f3a9e74e | |||
| 3eafb57403 | |||
| 47d464ed3a | |||
| f83f5f76c7 | |||
| fd98749995 | |||
| 4b4814e89a | |||
| c0bbadb0bf | |||
| c6bc8c24fb | |||
| e7d3205a96 | |||
| ffe5c80117 | |||
| a083cce5da | |||
| 37fadc6567 | |||
| 188a6805bf | |||
| 626435974e | |||
| b6c9361876 | |||
| 45f67476b8 | |||
| 0c1232ae3b | |||
| dfa8683c47 | |||
| c36c5210ab | |||
| 57a4fc8380 | |||
| 540f646209 | |||
| caf6403a76 | |||
| f585b8adda | |||
| 3e42371e02 | |||
| 93a955caf9 | |||
| 563a217237 | |||
| 41d601ab06 | |||
| 2dd2aead13 | |||
| 915660da0e | |||
| 3d6509b5a5 | |||
| 03e643a17a | |||
| dc5b09a9b4 | |||
| 345980af5e | |||
| 371ca4a22c | |||
| 6bcaf460b9 | |||
| 00fe2263d5 | |||
| 68eddcfcbb | |||
| f2ee1e8b24 | |||
| dd50287bdd | |||
| b33fb66d2a | |||
| 2f86511254 | |||
| e8347cb9fb | |||
| 8c3f7913f6 | |||
| a7ce7a0e9b | |||
| a4d3a356c3 | |||
| fedc420c19 | |||
| b10572ccaf | |||
| ca67bf3bdd | |||
| f0ab1dfef8 | |||
| 8838fcd14e | |||
| 0150dbb929 | |||
| aa9081d9cf | |||
| 48f5512e1a | |||
| d2e75e02c5 | |||
| 4ced681c76 | |||
| e08e34b677 | |||
| af17bd2800 | |||
| 24eb730c72 | |||
| f82b0a8843 | |||
| 210bccbe0d | |||
| 68429806d1 | |||
| a8cf0a6947 | |||
| 822d0636cc | |||
| 164a3e18d9 | |||
| 3498b5d154 | |||
| 96c10da527 | |||
| 3856b3cdd2 | |||
| 661f6db82c | |||
| 99b35483f8 | |||
| 102ba18b7b | |||
| 07faf1b96b | |||
| 1d70e271b6 | |||
| 0bf5ccee4d | |||
| 35e7d0cf61 | |||
| 27fd810cfd | |||
| 8903b1e28d | |||
| c1ace69e19 | |||
| 5c404c572e | |||
| 878d502b8b | |||
| 2a1ee4acbf | |||
| 0e149acc62 | |||
| 63e4394583 | |||
| 7aeabf0d14 | |||
| 9d5a668045 | |||
| 0efb541074 | |||
| 4ae58550b5 | |||
| d82e3a8b79 | |||
| 954213f1ff | |||
| d2bb3575fc | |||
| ca6afb72ad | |||
| 670ab22e96 | |||
| 4d71d4cc40 | |||
| 81b3769188 | |||
| c3c6d42a80 | |||
| 3d8ee25ae7 | |||
| decc77e21c | |||
| 501b1e9814 | |||
| 01502372c9 | |||
| a8c309ec9d | |||
| 41d6314beb | |||
| 74ed93ddc7 | |||
| 18a7143926 | |||
| bd68af5875 | |||
| b8806cc209 | |||
| edcb6f05ce | |||
| cb63c9b07c | |||
| a00ddb3142 | |||
| 3431d323e5 | |||
| 84c4dd0497 | |||
| 3e6a05307e | |||
| c45bda645b | |||
| 1210d2d24f | |||
| 894b53e760 | |||
| 4630b7e403 | |||
| 067bf40be7 | |||
| d8045ae339 | |||
| eff23352aa | |||
| 46df0f17b7 | |||
| ddedc06e47 | |||
| 6a999a8a72 | |||
| 8a97cb8c2c | |||
| e011e6bdc5 | |||
| a106134dd1 | |||
| a538cf73d5 | |||
| b273b4c04a | |||
| 248d142c2b | |||
| 2cc7260552 | |||
| fa4ccb6596 | |||
| 87af4f1a1e | |||
| 18b144fa46 | |||
| e71d0b3a09 | |||
| 9710acad6f | |||
| ca2d4c9217 | |||
| bad6cc2fab | |||
| 95e3ce9a69 | |||
| 5583ba4323 | |||
| a18577665a | |||
| 0bdafe7e15 | |||
| 38f6ced633 | |||
| 65f23bbd1a | |||
| 453a211343 | |||
| 1e8f91a871 | |||
| 2a86a09693 | |||
| bd878e20ce | |||
| 92a02c7f0c | |||
| dacb8df674 | |||
| 7356e8ae77 | |||
| 9b2e78a68e | |||
| be90694234 | |||
| e2757a7628 | |||
| 42662c3f61 | |||
| e752dd7b0f | |||
| 44e24b667e | |||
| de6eb38516 | |||
| 74bf70c44d | |||
| cd06ccc1a5 | |||
| dc40ee64cf | |||
| de1cd8d6a8 | |||
| 1923f90329 | |||
| eeac329c49 | |||
| f13e8479e4 | |||
| cf1008f0d9 | |||
| dfae33cbd1 | |||
| 9f3721247d | |||
| d0b2f8e12f | |||
| 051ed0f14c | |||
| 8ea667a0b5 | |||
| b391dde089 | |||
| be67906218 | |||
| 70d4233a15 | |||
| 31fc5a8fa5 | |||
| 1973cfd061 | |||
| 3322783d95 | |||
| 9895e27d5a | |||
| 877c0f59d3 | |||
| 92eb75af7e | |||
| d815f17442 | |||
| 0344fe0d6d | |||
| a10636e067 | |||
| 4b8f9b4330 | |||
| eb897c81e8 | |||
| 963aca218a | |||
| c6981e6216 | |||
| 8b8ef088d9 | |||
| 6704944105 | |||
| 8e50be24d4 | |||
| f9c19a630d | |||
| 78c04718e0 | |||
| bb592b2436 | |||
| 4b5011a579 | |||
| f3fb5017b3 | |||
| 3a9fdd511b | |||
| 57c6f45c21 | |||
| 8d204dc3c4 | |||
| 9413adcf4a | |||
| 99af76c5b5 | |||
| cc6458daa7 | |||
| 8708cfbee0 | |||
| b67e85e87b | |||
| 33c3143de9 | |||
| ce16fc6969 | |||
| f6e90d7e39 | |||
| ee0b7884a8 | |||
| 7e5a7f8183 | |||
| f2d517df9d | |||
| 6c11aa0927 | |||
| 398f1c8bfd | |||
| 3e2d1a5a56 | |||
| f52eafdf55 | |||
| dff04b5b69 | |||
| 900f623f3b | |||
| 44a1edac30 | |||
| 2ae2c48819 | |||
| 07af05712b | |||
| 15ea360b8a | |||
| 0d9dfad4a5 | |||
| 7962692641 | |||
| 4d1bb17382 | |||
| 015631a73d | |||
| 3399053e64 | |||
| ae046977f0 | |||
| 72f641bf63 | |||
| dbd1289ced | |||
| de4e539449 | |||
| 61f462a882 | |||
| 5607f76ce7 | |||
| 0e666d3203 | |||
| f50406d69f | |||
| cc167180f6 | |||
| c89f94b681 | |||
| 822ff5827e | |||
| 8579d7e0d6 | |||
| 06eb1f2e9e | |||
| b59cd0fe87 | |||
| bac8bc2b41 | |||
| e5abd51f76 | |||
| 584b6ea303 | |||
| 01461deaa5 | |||
| fa0d232727 | |||
| 6485839dcf | |||
| 81a3a92603 | |||
| 9ba76c8987 | |||
| 5eeda8235d | |||
| 20d40d5b81 | |||
| 5e11077c7a | |||
| 5deb6a9d8e | |||
| ba81bcba69 | |||
| 9329274866 | |||
| ace87b438b | |||
| 1f3c1f32f4 | |||
| cacd3dcd6d | |||
| 97b7945191 | |||
| a01d75549f | |||
| ecd0b43abe | |||
| d35ab24e15 | |||
| 100c4f6522 | |||
| a1c20959fe | |||
| 3b9df46510 | |||
| f7ba34dcec | |||
| 3192524922 | |||
| 74234684af | |||
| 06e027710f | |||
| 73d9095604 | |||
| f2d79225a3 | |||
| daa38413f3 | |||
| a4ed23f6c7 | |||
| cfdc61c357 | |||
| 77b47b4634 | |||
| 0f139562c3 | |||
| fc2bc06992 | |||
| 8eefdd71b5 | |||
| 966443be3d | |||
| 5327d91917 | |||
| 6399efc227 | |||
| 7da5de619b | |||
| 0735037f10 | |||
| 8c78a5d26c | |||
| f584dd140b | |||
| 4434900afc | |||
| 2a7a2889c6 | |||
| e488b15acc | |||
| 387e86de63 | |||
| 0e3a042fbb | |||
| de7167e830 | |||
| 40c76b4285 | |||
| 12cc970bf1 | |||
| bd2fd4ee97 | |||
| c3041d2a74 | |||
| 974effd95e | |||
| f3073efa39 | |||
| 1761134839 | |||
| 7c4762852b | |||
| 8dcd02aba3 | |||
| 4d6186021f | |||
| b7847d6260 | |||
| 869780589f | |||
| 254b97aa80 | |||
| 5a42a7e36c | |||
| 76206a1146 | |||
| 1f099a07dc | |||
| 356d83caf6 | |||
| be9ce33637 | |||
| 9b43b4641f | |||
| 6589a1a06d | |||
| db40f198be | |||
| 87ef03d512 | |||
| 8e97de6979 | |||
| d4740df996 | |||
| 926871d5fe | |||
| c010c0da0a | |||
| 8dc41886ef | |||
| e452f2ecfc | |||
| bfcf9a1d37 | |||
| 59e3518dd8 | |||
| 58bb70d1c5 | |||
| 9367bd802f | |||
| 411687b41c | |||
| ad2c65dc67 | |||
| 712d94d3b2 | |||
| 17b9eb7ad4 | |||
| 2c06232264 | |||
| 4c882682ed | |||
| f581c3238f | |||
| ceb6fe73f5 | |||
| 246a5ee541 | |||
| 79c7e48139 | |||
| 06922dc820 | |||
| 5577387d61 | |||
| d50cf5b91e | |||
| 6ca62db16d | |||
| 5536bf366d | |||
| 094efad728 | |||
| f77aec6dd7 | |||
| 6f4334f84d | |||
| 4ed512e0e2 | |||
| d0cc5521da | |||
| af8e7b70a0 | |||
| 8bc1326fef | |||
| dfe8c108de | |||
| 61337e29f6 | |||
| 5dea53ad50 | |||
| f52a022e64 | |||
| 0fdaa90a83 | |||
| e7ba097e6a | |||
| 3b409a8608 | |||
| ce97245131 | |||
| 59c9ba698f | |||
| 52ab9f0087 | |||
| 4ea1f8b016 | |||
| f1080151e3 | |||
| 5af0a7999c | |||
| 1e9ac9815b | |||
| 98ffcb8cd3 | |||
| 1b041d7771 | |||
| 6d98bab000 | |||
| b6c70cbc0d | |||
| e56a3d121c | |||
| 1776583e01 | |||
| 74f809a801 | |||
| 182101b592 | |||
| 07885cca1b | |||
| 956e920b7a | |||
| 908f91d674 | |||
| fd320767c5 | |||
| c830fa0537 | |||
| 10c89970cc | |||
| 0b512305a9 | |||
| 555abf9c95 | |||
| 2b3ea5eb80 | |||
| 66815016ba | |||
| 46f02dcfdd | |||
| 414a0896c9 | |||
| 0077d501ac | |||
| e946a0741d | |||
| 839c2af940 | |||
| f70241cc57 | |||
| 36d30ce39b | |||
| 28d083cba4 | |||
| 4dd4b37fc0 | |||
| 82b1b589dc | |||
| bac493c96b | |||
| d5520e83c6 | |||
| 93480be685 | |||
| 8ed308e89a | |||
| 8df1ecd804 | |||
| 8c9d071c7a | |||
| ac1098fa86 | |||
| deba324449 | |||
| 95362286f8 | |||
| f5c58bf5ad | |||
| 316db43b0a | |||
| 46ed196bf4 | |||
| 64baa63d12 | |||
| e19b6fbc23 | |||
| a64411a567 | |||
| 3662a97475 | |||
| 97aaacbc23 | |||
| 8afd0e7c8a | |||
| 82c776df83 | |||
| 924ebc2ee9 | |||
| d3bf099a98 | |||
| a6de5f9e69 | |||
| 618666de43 | |||
| 5c74ecdd72 | |||
| 61848db65b | |||
| dfc464ddd6 | |||
| bd5e57401e | |||
| a23fbbfb38 | |||
| c021032512 | |||
| d4be22a6eb | |||
| c210b99a5f | |||
| 01eb934fad | |||
| 52e6b144c1 | |||
| b418ad713d | |||
| 1bc51fe035 | |||
| 793737e1ed | |||
| e57b047343 | |||
| a11867126c | |||
| bf4a7561ed | |||
| 13332bf3fc | |||
| 955aed2224 | |||
| ee79231de0 | |||
| 5128d17759 | |||
| a07e7418a6 | |||
| 1ef5eb7a0f | |||
| 135e650ec8 | |||
| b7c12ba106 | |||
| 2d27399fd1 | |||
| ba83fac29f | |||
| 3bd4f1bb1d | |||
| b269ce5fb9 | |||
| f034c32c38 | |||
| 5175a4e40d | |||
| ee2ac0b7a9 | |||
| 63be0ee70d | |||
| cac273da5e | |||
| 170096b5db | |||
| 10e857ecd1 | |||
| 5c8572d811 | |||
| 973a2be16b | |||
| 9b9f6700af | |||
| 7fb458ddc1 | |||
| 310f701b0d | |||
| 6664f8a8bc | |||
| 2c9b0fc3e7 | |||
| 5966d7b51a | |||
| 46dff9b97b | |||
| 23364b2810 | |||
| da60fa8f94 | |||
| fbac14e188 | |||
| 0a03535ecb | |||
| 2bebfdfb97 | |||
| fb6fba9564 | |||
| d2f03b98dc | |||
| 4acd350219 | |||
| 9d83abbd38 | |||
| 1cfb814ee4 | |||
| 2e8a474792 | |||
| 93c41bb19c | |||
| bf922ec598 | |||
| de902d2d3d | |||
| 7b3bf24e5d | |||
| de7da81102 | |||
| 6428b02d85 | |||
| 519b8a1e36 | |||
| 967f0653a1 | |||
| b86d393571 | |||
| 6b38501c27 | |||
| 5893342ad8 | |||
| ac4a264f12 | |||
| 43895a462a | |||
| 1bde0ed3f7 | |||
| d903c0df30 | |||
| 9620826d65 | |||
| 0a71f43ef3 | |||
| a47e76845f | |||
| c2eb08bd5e | |||
| 7b76e07231 | |||
| 1dd8042d3d | |||
| c575ee9ce1 | |||
| 1befc76b70 | |||
| 6a6e7f7125 | |||
| bb6e248583 | |||
| f7df4fba6c | |||
| e7403be508 | |||
| 873715b28c | |||
| b1d6e5a314 | |||
| f0453375c4 | |||
| e5a98efd7d | |||
| 14b330009b | |||
| 288b62d3f8 | |||
| c5e8f1b3af | |||
| 980717f9fd | |||
| 68475eee0f | |||
| eeb2400e79 | |||
| 01244005e9 | |||
| c5005b9b07 | |||
| 80a26341b1 | |||
| b7877962f1 | |||
| 688d064085 | |||
| 1c4d53e3ef | |||
| a53a134163 | |||
| 4d12788c53 | |||
| 1beb7cbd5d | |||
| 8358d72a98 | |||
| 4ebff4a25a | |||
| 0ff787abda | |||
| 9b5b48a8ab | |||
| 5dd0fb9e23 | |||
| 7c210e04a5 | |||
| 9236e02101 | |||
| 8f4ebf20da | |||
| 910e51f637 | |||
| 92fc9b4e25 | |||
| 2b8e7241c9 | |||
| 124cb3ad13 | |||
| 6d3400d948 | |||
| 5031352fe3 | |||
| 624369f147 | |||
| 9a7f7b8684 | |||
| fa9487c2f2 | |||
| 9ec1ddab99 | |||
| 6f1c2d0555 | |||
| 01b50d5590 | |||
| 9c673928e6 | |||
| d55dfb90e4 | |||
| 235a05d006 | |||
| dabb7b3b2e | |||
| e756289c2b | |||
| c534158c2e | |||
| b47191a0c1 | |||
| 6c6a025f2a | |||
| 60edc97ea5 | |||
| a5b209d9e0 | |||
| fd673a415f | |||
| 4270765146 | |||
| f56cb58dfb | |||
| f315f4bf35 | |||
| 69765de433 | |||
| 35d463d4ba | |||
| 894b46c5db | |||
| eb0b18af6f | |||
| fba183fa27 | |||
| c5a627004a | |||
| ac27fb0ca7 | |||
| be4a8311d5 | |||
| 6d32d44fa3 | |||
| 9bacfb1424 | |||
| c3464be589 | |||
| 7fe71c60d0 | |||
| 0c6537fb36 | |||
| 854dc0eb45 | |||
| e90afb7e4a | |||
| 0453f6becf | |||
| c8a58ab515 | |||
| 553f8dbfa5 | |||
| 2bacdcdab7 | |||
| 99aecbfdbb | |||
| 27bda5dc28 | |||
| 962f3f5dd0 | |||
| 41077b43b3 | |||
| 4410ab892f | |||
| 60000cb0cf | |||
| 66b00255d5 | |||
| a5b68cf1fd | |||
| 4cff57fe71 | |||
| 38b603fc8f | |||
| 47684380a9 | |||
| e4bfbfb906 | |||
| 9db86c19f6 | |||
| d5b551cec3 | |||
| 7e500027e3 | |||
| dd786ba579 | |||
| 5a57888305 | |||
| 706aa5e1d7 | |||
| 19c1b1197d | |||
| 5cf62f5517 | |||
| 56d02ad8d4 | |||
| 006a72174f | |||
| 0cbc9dd9db | |||
| 60c31ff56d | |||
| 6a204643f6 | |||
| 59285d1630 | |||
| a850d6b1af | |||
| f17fa0f345 | |||
| 756d4e770d | |||
| 7bb5e8ce0d | |||
| 975533afba | |||
| 19749f7c87 | |||
| 7703c4b0ad | |||
| dc8f594eec | |||
| 4629b7302b | |||
| 02d83d1f16 | |||
| 91c9cef56d | |||
| f7d4912942 | |||
| eb8674b84f | |||
| ff44e4d916 | |||
| e66540f114 | |||
| 639c0c70e3 | |||
| 37b02352e2 | |||
| 31c8bd7fd2 | |||
| 808fe570a3 | |||
| e706cc9d13 | |||
| eb02cc4b6a | |||
| 31cca61d1c | |||
| 071e0d9021 | |||
| a494bfbb38 | |||
| baadf554cd | |||
| 9df16fede0 | |||
| dd0ad31ac6 | |||
| be26c9d103 | |||
| a448c8fb68 | |||
| de1a6a050f | |||
| 49c9abe91b | |||
| 3b05476689 | |||
| 1c032bfc47 | |||
| 1a7457f650 | |||
| e640eda771 | |||
| fc2b67608f | |||
| a3a990cc01 | |||
| f6a4674a2f | |||
| 865620b4a8 | |||
| 1e0ed350fc | |||
| 6ccc874583 | |||
| ca86dc5fb8 | |||
| e3605e4dc5 | |||
| cb9aef95ec | |||
| 09f97de0e6 | |||
| f5466b9982 | |||
| e176a60d28 | |||
| dc24d1b059 | |||
| fa3fc18ddf | |||
| c2941cd3e8 | |||
| bf15a5d957 | |||
| f01463bab3 | |||
| 54cd26b76f | |||
| 2bd8adaf69 | |||
| 26eba2def6 | |||
| 43852ce755 | |||
| 81fab06e3b | |||
| 77a90f9c0c | |||
| bc32f2a2f0 | |||
| 76bfecd466 | |||
| d4eb1e7b8d | |||
| 2ec307510d | |||
| 0b4e6003d6 | |||
| 7e603ffa89 | |||
| 6fc8570cf4 | |||
| 0bfd916df4 | |||
| 88aee0f4f5 | |||
| 0d3c3243a0 | |||
| 871b1136c2 | |||
| f64c935ffe | |||
| 600ec6789b | |||
| 65a3937592 | |||
| 719c8f49a6 | |||
| 29928c0b92 | |||
| a88a1f7cf7 | |||
| 46efbfbe9a | |||
| 26ff8dcc8f | |||
| 9c91e9d5fd | |||
| 3628d3c1fd | |||
| 6c9406147a | |||
| aae244de39 | |||
| d5b14c2679 | |||
| a54fbfb9e9 | |||
| 9cbbfe77b7 | |||
| 9b64c67068 | |||
| de0227a1cf | |||
| 1dfeabf195 | |||
| 6c5197f3f2 | |||
| 09453cc24e | |||
| 4b62310158 | |||
| 43f2190c3e | |||
| 3225da6b13 | |||
| 0c233b8764 | |||
| 027d0125ef | |||
| e4884c3e18 | |||
| b675f516e7 | |||
| d5f7363c33 | |||
| 7458962ad4 | |||
| 0a0b61287e |
+24
@@ -0,0 +1,24 @@
|
|||||||
|
#Editor generated files
|
||||||
|
*.sln
|
||||||
|
*.vcproj
|
||||||
|
*.suo
|
||||||
|
*.ncb
|
||||||
|
*.user
|
||||||
|
|
||||||
|
#Directories
|
||||||
|
Release/
|
||||||
|
Debug/
|
||||||
|
Out/
|
||||||
|
release/
|
||||||
|
debug/
|
||||||
|
out/
|
||||||
|
|
||||||
|
#Project generated files
|
||||||
|
*.db
|
||||||
|
*.o
|
||||||
|
*.a
|
||||||
|
*.exe
|
||||||
|
|
||||||
|
#Shell files
|
||||||
|
*.bat
|
||||||
|
*.sh
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
[submodule "bin"]
|
||||||
|
path = bin
|
||||||
|
url = https://github.com/krgamestudios/bin.git
|
||||||
|
[submodule "TurtleGUI"]
|
||||||
|
path = TurtleGUI
|
||||||
|
url = https://github.com/krgamestudios/TurtleGUI.git
|
||||||
|
[submodule "TurtleMap"]
|
||||||
|
path = TurtleMap
|
||||||
|
url = https://github.com/krgamestudios/TurtleMap.git
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
## Outline
|
||||||
|
|
||||||
|
Tortuga is a 2D MMORPG featuring permadeath, with an emphasis on multiplayer cooperation, exploration and customization. The game runs on customizable public and private servers.
|
||||||
|
|
||||||
|
This game is inspired by classic 2D RPGs (Final Fantasy, The Legend of Zelda), as well as more modern sandboxes and MMOs (Minecraft, EVE Online). This project is currently independently created and funded, with the goal of creating a game that will engage the players and inspire a large community.
|
||||||
|
|
||||||
|
## Releases
|
||||||
|
|
||||||
|
* The most recent stable build for Windows can be found [here](https://www.dropbox.com/s/zm9hg11ywol7yyz/Tortuga-win.rar?dl=1).
|
||||||
|
* The most recent stable build for Linux can be found [here](https://www.dropbox.com/s/5z6ag9r88ovr5bb/Tortuga-linux.tar?dl=1).
|
||||||
|
|
||||||
|
## Patreon
|
||||||
|
|
||||||
|
If you would like to support the development of Tortuga, please consider becoming a patron below.
|
||||||
|
|
||||||
|
* [My Patreon Page](https://patreon.com/user?u=2811779)
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
* [Tortuga Wiki](https://github.com/Ratstail91/Tortuga/wiki) - Full documentation (incomplete)
|
||||||
|
* [Tortuga Bug Tracker](https://github.com/Ratstail91/Tortuga/issues) - A list of all known bugs and issues
|
||||||
|
|
||||||
|
## External Dependencies
|
||||||
|
|
||||||
|
* [SDL 2.0](http://www.libsdl.org/) - Simple DirectMedia Layer API
|
||||||
|
* [SDL_image 2.0](https://www.libsdl.org/projects/SDL_image/) - An SDL Extension for loading multiple image file formats
|
||||||
|
* [SDL_net 2.0](http://www.libsdl.org/projects/SDL_net/) - SDL's networking extension
|
||||||
|
* [SDL_ttf 2.0](https://www.libsdl.org/projects/SDL_ttf/) - An SDL extention for rendering fonts
|
||||||
|
* [lua 5.2](http://www.lua.org/) - The lua programming language
|
||||||
|
* [SQLite3](http://www.sqlite.org/) - A lightweight SQL database engine
|
||||||
|
|
||||||
|
## Tools
|
||||||
|
|
||||||
|
* [WinRAR](http://www.rarlab.com/) - A free archive tool; needed for Windows distribution
|
||||||
|
* [tar](http://www.gnu.org/software/tar/manual/) - The GNU archive tool; needed for Linux distribution
|
||||||
|
* [Dropbox](https://www.dropbox.com/) - For hosting and distribution
|
||||||
|
|
||||||
|
## Using and Including
|
||||||
|
|
||||||
|
* [Coolvetica Typeface](http://typodermicfonts.com/coolvetica/)
|
||||||
|
|
||||||
|
## Copyright
|
||||||
|
|
||||||
|
(Future versions (to be determined) may be released under a modified version of the [Uplink Developer's License](http://www.introversion.co.uk/uplink/developer/license.html).)
|
||||||
|
|
||||||
|
The current version of Tortuga is released under the [zlib license](http://en.wikipedia.org/wiki/Zlib_License).
|
||||||
|
|
||||||
|
Copyright (c) 2013-2016 Kayne Ruse
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
### Items not made by me
|
||||||
|
|
||||||
|
* [Coolvetica Font](http://typodermicfonts.com/coolvetica/)
|
||||||
|
* Creative Commons Artwork from [Artsader](http://www.moosader.com/artsader/)
|
||||||
Binary file not shown.
Submodule
+1
Submodule TurtleGUI added at 13e810df0a
Submodule
+1
Submodule TurtleMap added at d6672e59d0
@@ -1,57 +0,0 @@
|
|||||||
--TODO: each function needs to check it's parameter count
|
|
||||||
--TODO: Set metatables
|
|
||||||
|
|
||||||
--RoomManager interface
|
|
||||||
RoomMgr.GetRoom(index)
|
|
||||||
RoomMgr.CreateRoom([{params}])
|
|
||||||
RoomMgr.UnloadRoom(index)
|
|
||||||
|
|
||||||
|
|
||||||
--RoomData interface
|
|
||||||
Room.GetPager()
|
|
||||||
Room.GetGenerator()
|
|
||||||
Room.OnCreate([{params}])
|
|
||||||
Room.OnUnload()
|
|
||||||
|
|
||||||
Room.Get{params}()
|
|
||||||
|
|
||||||
|
|
||||||
--RegionPager interface
|
|
||||||
RegionPager.SetTile(x, y, z, v)
|
|
||||||
RegionPager.GetTile(x, y, z)
|
|
||||||
RegionPager.SetSolid(x, y, b)
|
|
||||||
RegionPager.GetSolid(x, y)
|
|
||||||
RegionPager.GetRegion(x, y)
|
|
||||||
RegionPager.SetDirectory(directory)
|
|
||||||
RegionPager.GetDirectory()
|
|
||||||
RegionPager.LoadRegion(x, y)
|
|
||||||
RegionPager.SaveRegion(x, y)
|
|
||||||
RegionPager.CreateRegion(x, y[, {params}])
|
|
||||||
RegionPager.UnloadRegion(x, y)
|
|
||||||
|
|
||||||
|
|
||||||
--Region interface
|
|
||||||
Region.SetTile(x, y, z, v)
|
|
||||||
Region.GetTile(x, y, z)
|
|
||||||
Region.SetSolid(x, y, b)
|
|
||||||
Region.GetSolid(x, y)
|
|
||||||
Region.GetX()
|
|
||||||
Region.GetY()
|
|
||||||
Region.GetWidth()
|
|
||||||
Region.GetHeight()
|
|
||||||
Region.GetDepth()
|
|
||||||
Region.OnLoad(directory)
|
|
||||||
Region.OnSave(directory)
|
|
||||||
Region.OnCreate([{params}])
|
|
||||||
Region.OnUnload([directory])
|
|
||||||
|
|
||||||
|
|
||||||
--*Generator interface
|
|
||||||
Generator.GetMapType()
|
|
||||||
Generator.GetChunk(x, y)
|
|
||||||
Generator.GetMapWidth()
|
|
||||||
Generator.GetMapHeight()
|
|
||||||
|
|
||||||
|
|
||||||
--Chunk interface
|
|
||||||
??
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
My game Tortuga will have permadeath; it's actually one of the first design decisions I made. How to implement it, however, is another decision all together.
|
|
||||||
|
|
||||||
A while ago, before the implementation of hardcore mode, I was playing on a Minecraft server that boasted something close to permadeath: your account would be banned for 15 days, so long that it's almost unavoidable that you'd lose all of your hidden items. This was a brutal server; the further you went from spawn, the more dangerous it became, not less. If the natural hazards didn't kill you, another player would.
|
|
||||||
|
|
||||||
I loved it.
|
|
||||||
|
|
||||||
Although I haven't been back to that server since I died for the last time, the experience will stay with me forever. I'd played and died on that server a few times, each time I had to wait for my ban to clear. I never really lost much, since I never survived for very long. Even today, in a single player world, I'm likely to die on the first night.
|
|
||||||
|
|
||||||
After playing for a while, I began to understand the mentality needed to survive there. Always fear other people, never take risks, and never hoard valuable items if they could be better spent keeping you alive. One day, the last day I played, I found a hole in the ground that someone was obviously using as a "hidden" base. I tried to get in, always careful not to trigger any traps. However, while I was trying to get in, the owner came home.
|
|
||||||
|
|
||||||
I was suddenly attacked from behind, I barely had enough sense to dig down, since they were wearing enchanted diamond armour. I had no chance against them. I thought I was safe, digging 10, 20, 30 meters down, but no, they poured lava down the hole and plugged it up. I was a gonner, and I knew it. I was futilely digging and thrashing around in what was now my tomb, about to lose my life. I'd survived for so long, only to lose it all by not keeping a lookout.
|
|
||||||
|
|
||||||
When the game over screen flashed up, I screamed. I screamed, and screamed, and screamed. For 5 minutes, my mind was blank, nothing but hatred and pain and loss. I'm sure you've seen the video of the angry German kid who died in WoW, but have you ever actually experienced that pain? Have you ever worked so hard, and lost it all?
|
|
||||||
|
|
||||||
For days afterwards, that loss was all I could think about. Even now, that experience stays with me. What about that game, that server, invoked so much pain that I almost lost consciousness from screaming? Me of all people, who thought he was invincible?
|
|
||||||
|
|
||||||
I've played games that have moved me, terrified me, made me fall in love and fight for the people that I care about. But never have I played a game that has made me feel pain and loss like that. I died that day. Me.
|
|
||||||
|
|
||||||
Pain and loss are part of life, but not games. Permadeath seems like the obvious choice for creating a sense of loss for the player, but there are so few games with permadeath, and even fewer multiplayer games. Pain and loss can be conveyed in other ways, I'm sure anybody who's played Final Fantasy 7 knows that, and some games are especially well suited to delivering that message. However, for a player to feel like they are the one who's died, that is a challenge.
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
Abstract:
|
|
||||||
|
|
||||||
The goal of this pseudocode is to create a collision system that brings several
|
|
||||||
colliding bodies to a near-contact state (no space between the bodies, but not
|
|
||||||
overlapping), while preserving the motion of said bodies. For simplicity, I've
|
|
||||||
decided to use a square box (BoundingBox, or BBox for short) for the collidable
|
|
||||||
bodies.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
My current game has a tiled-map, where the tiles are arranged on a 2D grid. The
|
|
||||||
tiles each have a flag indicating if they are solid (i.e. collidable) or not. I
|
|
||||||
also have characters walking around on these tile maps, that must not intersect
|
|
||||||
with solid tiles. For stylistic reasons, I want characters moving at an angle
|
|
||||||
to "slide" along these walls, and continue along with their original velocity
|
|
||||||
when they've circumvented the obstacles.
|
|
||||||
|
|
||||||
I'd also like to keep the possibility of non-grid collisions using this logic
|
|
||||||
open (for objects like trees, etc.) if the code allows it.
|
|
||||||
|
|
||||||
Obviously, there are many in depth issues that I will need to take into
|
|
||||||
account when writing this logic, that have been glossed over or omitted in this
|
|
||||||
article.
|
|
||||||
|
|
||||||
-------------------------
|
|
||||||
|
|
||||||
```
|
|
||||||
velocity = motion + speed
|
|
||||||
if (collision(position + velocity)) then
|
|
||||||
if (collision(position + {velocity.x, 0})) then
|
|
||||||
velocity.x = 0
|
|
||||||
end
|
|
||||||
if (collision(position + {0, velocity.y})) then
|
|
||||||
velocity.y = 0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
position = position + velocity
|
|
||||||
```
|
|
||||||
|
|
||||||
This code is a basic outline for a collision system that preserves the object's
|
|
||||||
motion, but it still leaves several pixels of space between the bounding boxes.
|
|
||||||
Notably, it also treats "collision" as an abstract concept, rather than as an
|
|
||||||
event that could happen multiple times per frame.
|
|
||||||
|
|
||||||
-------------------------
|
|
||||||
|
|
||||||
```
|
|
||||||
velocity = motion + speed
|
|
||||||
if (collisionSimple(BOXSET, position + velocity)) then
|
|
||||||
velocity.x = collisionX(BOXSET, velocity.x)
|
|
||||||
velocity.y = collisionY(BOXSET, velocity.y)
|
|
||||||
end
|
|
||||||
position = position + velocity
|
|
||||||
```
|
|
||||||
|
|
||||||
Here, collisions are still abstract, but "BOXSET" is defined externally
|
|
||||||
(probably as a set of solid boxes, and their positions). This does require more
|
|
||||||
in depth calculations, as well as three specialized utility functions, but the
|
|
||||||
results might be what I'm looking for.
|
|
||||||
|
|
||||||
If there are any collisions between the player object and the given box set,
|
|
||||||
then collisionX() and collisionY() are called to calculate the new distance
|
|
||||||
that the character will move.
|
|
||||||
|
|
||||||
-------------------------
|
|
||||||
|
|
||||||
```
|
|
||||||
bool collisionSimple(BOXSET, newPos):
|
|
||||||
for_each box in BOXSET do
|
|
||||||
if (box.overlap(PLAYER.box + newPos)) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
collisionSimple() first runs through the BOXSET, checking if any of the given
|
|
||||||
bounding boxes would collide with the player object's new position (just
|
|
||||||
pretend PLAYER is accessible). In this case, non-tile bounding boxes can be
|
|
||||||
included as part of BOXSET; they're treated just the same. The optimal outcome
|
|
||||||
is that there are no collisions.
|
|
||||||
|
|
||||||
A possible, but flawed, optimization that could be preformed here is to remove
|
|
||||||
any elements from BOXSET that do not collide with newPos, and let the other
|
|
||||||
utility functions operate only on what remains. However, if there are any
|
|
||||||
collisions, than newPos is not the algorithm's final result, therefore any
|
|
||||||
final result that the algorithm would calculate based on the remaining elements
|
|
||||||
would not have been checked against the removed elements.
|
|
||||||
|
|
||||||
Just something to note.
|
|
||||||
|
|
||||||
-------------------------
|
|
||||||
|
|
||||||
```
|
|
||||||
var collisionX(BOXSET, velocityX):
|
|
||||||
var ret = velocityX
|
|
||||||
|
|
||||||
for_each box in BOXSET do
|
|
||||||
if (box.overlap(PLAYER.box + PLAYER.position + {velocityX,0})) then
|
|
||||||
if (velocityX > 0) then
|
|
||||||
ret = min(ret, box.west - PLAYER.position.x)
|
|
||||||
else
|
|
||||||
ret = max(ret, box.east - PLAYER.position.x)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
Two things: 1. collisionX() and collisionY() should be identical except for the
|
|
||||||
axis of operation and 2. if a player object is "sliding" along a wall (or
|
|
||||||
stuck), then these functions will be called every frame.
|
|
||||||
|
|
||||||
collisionX() and collisionY() check the sides of the elements in BOXSET, and if
|
|
||||||
there's a box that the player would collide with, given the current distance to
|
|
||||||
move, than the distance is reduced, based on if the character is moving left or
|
|
||||||
right (or up or down).
|
|
||||||
|
|
||||||
An unfortunate bug I can already see is that this logic doesn't check corners;
|
|
||||||
it might be possible to get stuck on a corner of a wall, but if this becomes an
|
|
||||||
issue in my implementation I will update this article with that information,
|
|
||||||
and you can promptly ignore it.
|
|
||||||
Submodule
+1
Submodule bin added at 08e1382e66
@@ -0,0 +1,109 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
|
SDL_Renderer* BaseScene::rendererHandle = nullptr;
|
||||||
|
|
||||||
|
BaseScene::BaseScene() {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseScene::~BaseScene() {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseScene::RenderFrame(SDL_Renderer* renderer) {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseScene::SetRenderer(SDL_Renderer* r) {
|
||||||
|
rendererHandle = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Renderer* BaseScene::GetRenderer() {
|
||||||
|
return rendererHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseScene::SetSceneSignal(SceneSignal signal) {
|
||||||
|
sceneSignal = signal;
|
||||||
|
}
|
||||||
|
|
||||||
|
SceneSignal BaseScene::GetSceneSignal() {
|
||||||
|
return sceneSignal;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//frame phases
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void BaseScene::FrameStart() {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseScene::Update() {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseScene::FrameEnd() {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//input events
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void BaseScene::QuitEvent() {
|
||||||
|
sceneSignal = SceneSignal::QUIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseScene::MouseMotion(SDL_MouseMotionEvent const& event) {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseScene::MouseButtonDown(SDL_MouseButtonEvent const& event) {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseScene::MouseButtonUp(SDL_MouseButtonEvent const& event) {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseScene::MouseWheel(SDL_MouseWheelEvent const& event) {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseScene::KeyDown(SDL_KeyboardEvent const& event) {
|
||||||
|
//preference as a default
|
||||||
|
switch(event.keysym.sym) {
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
QuitEvent();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseScene::KeyUp(SDL_KeyboardEvent const& event) {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseScene::TextInput(SDL_TextInputEvent const& event) {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "scene_signal.hpp"
|
||||||
|
|
||||||
|
#include "SDL2/SDL.h"
|
||||||
|
|
||||||
|
class BaseScene {
|
||||||
|
public:
|
||||||
|
BaseScene();
|
||||||
|
virtual ~BaseScene();
|
||||||
|
|
||||||
|
virtual void RenderFrame(SDL_Renderer*);
|
||||||
|
static void SetRenderer(SDL_Renderer*);
|
||||||
|
SceneSignal GetSceneSignal();
|
||||||
|
|
||||||
|
//frame phases
|
||||||
|
virtual void FrameStart();
|
||||||
|
virtual void Update();
|
||||||
|
virtual void FrameEnd();
|
||||||
|
|
||||||
|
//input events
|
||||||
|
virtual void QuitEvent();
|
||||||
|
virtual void MouseMotion(SDL_MouseMotionEvent const& event);
|
||||||
|
virtual void MouseButtonDown(SDL_MouseButtonEvent const& event);
|
||||||
|
virtual void MouseButtonUp(SDL_MouseButtonEvent const& event);
|
||||||
|
virtual void MouseWheel(SDL_MouseWheelEvent const& event);
|
||||||
|
virtual void KeyDown(SDL_KeyboardEvent const& event);
|
||||||
|
virtual void KeyUp(SDL_KeyboardEvent const& event);
|
||||||
|
virtual void TextInput(SDL_TextInputEvent const& event);
|
||||||
|
|
||||||
|
//TODO: joystick and controller events
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//control
|
||||||
|
static SDL_Renderer* GetRenderer();
|
||||||
|
void SetSceneSignal(SceneSignal);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static SDL_Renderer* rendererHandle;
|
||||||
|
SceneSignal sceneSignal = SceneSignal::CONTINUE;
|
||||||
|
};
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
enum Channels {
|
||||||
|
SERVER = 0
|
||||||
|
};
|
||||||
@@ -0,0 +1,372 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "client_application.hpp"
|
||||||
|
|
||||||
|
#include "serial_packet.hpp"
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
|
//for handling platforms
|
||||||
|
#include "SDL2/SDL_syswm.h"
|
||||||
|
#include "SDL2/SDL_version.h"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Public access members
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void ClientApplication::Init(int argc, char* argv[]) {
|
||||||
|
std::cout << "Beginning " << argv[0] << std::endl;
|
||||||
|
|
||||||
|
//load the prerequisites
|
||||||
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
config.Load("rsc/config.cfg", false, argc, argv);
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Initialize SDL
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
if (SDL_Init(0)) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to initialize SDL: " << SDL_GetError();
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//create and check the window
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
//get the config values
|
||||||
|
int w = config.Int("client.screen.w");
|
||||||
|
int h = config.Int("client.screen.h");
|
||||||
|
int f = config.Boolean("client.screen.f") ? SDL_WINDOW_FULLSCREEN : 0;
|
||||||
|
|
||||||
|
//BUG: fullscreen is disabled
|
||||||
|
f = 0;
|
||||||
|
|
||||||
|
//default sizes
|
||||||
|
w = w ? w : 800;
|
||||||
|
h = h ? h : 600;
|
||||||
|
|
||||||
|
window = SDL_CreateWindow(argv[0], SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, f);
|
||||||
|
|
||||||
|
if (!window) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to create the window: " << SDL_GetError();
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Initialized the window" << std::endl;
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//DEBUG: detecting platforms, versions & appropriate fonts
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
SDL_SysWMinfo windowInfo;
|
||||||
|
SDL_VERSION(&windowInfo.version);
|
||||||
|
if (SDL_GetWindowWMInfo(window, &windowInfo)) {
|
||||||
|
//
|
||||||
|
std::string platform;
|
||||||
|
std::string fontPath;
|
||||||
|
|
||||||
|
//get the info
|
||||||
|
switch(windowInfo.subsystem) {
|
||||||
|
case SDL_SYSWM_WINDOWS:
|
||||||
|
platform = "Microsoft Windows";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_SYSWM_X11:
|
||||||
|
platform = "X Window System";
|
||||||
|
break;
|
||||||
|
|
||||||
|
//NOTE: OS X is currently unsupported, but it could be
|
||||||
|
case SDL_SYSWM_COCOA:
|
||||||
|
platform = "Apple OS X";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
platform = "an unsupported platform";
|
||||||
|
}
|
||||||
|
|
||||||
|
//final output
|
||||||
|
std::cout << "SDL Version ";
|
||||||
|
std::cout << (int)windowInfo.version.major << ".";
|
||||||
|
std::cout << (int)windowInfo.version.minor << ".";
|
||||||
|
std::cout << (int)windowInfo.version.patch << " on ";
|
||||||
|
std::cout << platform << std::endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to retrieve window info: " << SDL_GetError();
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//create and check the renderer
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||||
|
|
||||||
|
if (!renderer) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to create the renderer: " << SDL_GetError();
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//screen scaling
|
||||||
|
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best");
|
||||||
|
SDL_RenderSetLogicalSize(renderer, w, h);
|
||||||
|
|
||||||
|
//set the hook for the renderer
|
||||||
|
BaseScene::SetRenderer(renderer);
|
||||||
|
|
||||||
|
std::cout << "Initialized the renderer" << std::endl;
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Initialize the APIs
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
//initialize SDL_net
|
||||||
|
if (SDLNet_Init()) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to initialize SDL_net 2.0: " << SDL_GetError();
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
UDPNetworkUtility::GetSingleton().Open(0);
|
||||||
|
|
||||||
|
std::cout << "Initialized SDL_net 2.0" << std::endl;
|
||||||
|
|
||||||
|
//setting up SDL2_ttf
|
||||||
|
if (TTF_Init()) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to initialize SDL_ttf 2.0: " << SDL_GetError();
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Initialized SDL_ttf 2.0" << std::endl;
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//debug output
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
#define DEBUG_INTERNAL_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl;
|
||||||
|
|
||||||
|
std::cout << "Internal sizes:" << std::endl;
|
||||||
|
|
||||||
|
DEBUG_INTERNAL_VAR(NETWORK_VERSION);
|
||||||
|
DEBUG_INTERNAL_VAR(sizeof(Region::type_t));
|
||||||
|
DEBUG_INTERNAL_VAR(sizeof(Region));
|
||||||
|
DEBUG_INTERNAL_VAR(REGION_WIDTH);
|
||||||
|
DEBUG_INTERNAL_VAR(REGION_HEIGHT);
|
||||||
|
DEBUG_INTERNAL_VAR(REGION_DEPTH);
|
||||||
|
DEBUG_INTERNAL_VAR(REGION_TILE_FOOTPRINT);
|
||||||
|
DEBUG_INTERNAL_VAR(REGION_SOLID_FOOTPRINT);
|
||||||
|
DEBUG_INTERNAL_VAR(PACKET_STRING_SIZE);
|
||||||
|
DEBUG_INTERNAL_VAR(PACKET_BUFFER_SIZE);
|
||||||
|
DEBUG_INTERNAL_VAR(MAX_PACKET_SIZE);
|
||||||
|
DEBUG_INTERNAL_VAR(static_cast<int>(SerialPacketType::LAST));
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//BUGFIX
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
SDL_StopTextInput();
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//finalize the startup
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
std::cout << "Startup completed successfully" << std::endl;
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//debugging
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
//...
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClientApplication::Proc() {
|
||||||
|
//load the first scene
|
||||||
|
ProcessSceneSignal(SceneSignal::FIRST);
|
||||||
|
|
||||||
|
//fixed frame rate
|
||||||
|
typedef std::chrono::steady_clock Clock;
|
||||||
|
|
||||||
|
Clock::time_point simTime = Clock::now();
|
||||||
|
Clock::time_point realTime;
|
||||||
|
constexpr std::chrono::duration<int, std::milli> frameDelay(16); //~60FPS
|
||||||
|
|
||||||
|
//the game loop continues until the scenes signal QUIT
|
||||||
|
while(activeScene->GetSceneSignal() != SceneSignal::QUIT) {
|
||||||
|
//switch scenes if necessary
|
||||||
|
if(activeScene->GetSceneSignal() != SceneSignal::CONTINUE) {
|
||||||
|
ProcessSceneSignal(activeScene->GetSceneSignal());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//update the current time
|
||||||
|
realTime = Clock::now();
|
||||||
|
|
||||||
|
//simulate the game or give the machine a break
|
||||||
|
if (simTime < realTime) {
|
||||||
|
while(simTime < realTime) {
|
||||||
|
//call the user defined functions
|
||||||
|
activeScene->FrameStart();
|
||||||
|
ProcessEvents();
|
||||||
|
activeScene->Update();
|
||||||
|
activeScene->FrameEnd();
|
||||||
|
|
||||||
|
//step to the next frame
|
||||||
|
simTime += frameDelay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SDL_Delay(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
activeScene->RenderFrame(renderer);
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
//cleanup
|
||||||
|
ClearScene();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClientApplication::Quit() {
|
||||||
|
//clean up after the program
|
||||||
|
std::cout << "Shutting down" << std::endl;
|
||||||
|
UDPNetworkUtility::GetSingleton().Close();
|
||||||
|
TTF_Quit();
|
||||||
|
SDLNet_Quit();
|
||||||
|
BaseScene::SetRenderer(nullptr);
|
||||||
|
SDL_DestroyRenderer(renderer);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Quit();
|
||||||
|
std::cout << "Clean exit" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Scene management
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void ClientApplication::ProcessEvents() {
|
||||||
|
SDL_Event event;
|
||||||
|
while(SDL_PollEvent(&event)) {
|
||||||
|
switch(event.type) {
|
||||||
|
case SDL_QUIT:
|
||||||
|
activeScene->QuitEvent();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_MOUSEMOTION:
|
||||||
|
activeScene->MouseMotion(event.motion);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
|
activeScene->MouseButtonDown(event.button);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_MOUSEBUTTONUP:
|
||||||
|
activeScene->MouseButtonUp(event.button);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_MOUSEWHEEL:
|
||||||
|
activeScene->MouseWheel(event.wheel);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
activeScene->KeyDown(event.key);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_KEYUP:
|
||||||
|
activeScene->KeyUp(event.key);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_TEXTINPUT:
|
||||||
|
activeScene->TextInput(event.text);
|
||||||
|
break;
|
||||||
|
|
||||||
|
//TODO: (9) joystick and controller events
|
||||||
|
|
||||||
|
//window events are handled internally
|
||||||
|
case SDL_WINDOWEVENT:
|
||||||
|
switch(event.window.event) {
|
||||||
|
case SDL_WINDOWEVENT_RESIZED:
|
||||||
|
SDL_RenderSetLogicalSize(renderer, event.window.data1, event.window.data2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Add the custom scene headers here
|
||||||
|
#include "splash_screen.hpp"
|
||||||
|
#include "main_menu.hpp"
|
||||||
|
#include "options_menu.hpp"
|
||||||
|
#include "lobby_menu.hpp"
|
||||||
|
#include "world.hpp"
|
||||||
|
#include "combat.hpp"
|
||||||
|
#include "disconnected_screen.hpp"
|
||||||
|
|
||||||
|
void ClientApplication::ProcessSceneSignal(SceneSignal signal) {
|
||||||
|
//BUG: #16 Resources are being reloaded between scenes
|
||||||
|
ClearScene();
|
||||||
|
switch(signal) {
|
||||||
|
//add scene creation calls here
|
||||||
|
case SceneSignal::FIRST:
|
||||||
|
case SceneSignal::SPLASHSCREEN:
|
||||||
|
activeScene = new SplashScreen(window);
|
||||||
|
break;
|
||||||
|
case SceneSignal::MAINMENU:
|
||||||
|
activeScene = new MainMenu();
|
||||||
|
break;
|
||||||
|
case SceneSignal::OPTIONSMENU:
|
||||||
|
activeScene = new OptionsMenu();
|
||||||
|
break;
|
||||||
|
case SceneSignal::LOBBYMENU:
|
||||||
|
activeScene = new LobbyMenu(&clientIndex, &accountIndex);
|
||||||
|
break;
|
||||||
|
case SceneSignal::WORLD:
|
||||||
|
activeScene = new World(&clientIndex, &accountIndex);
|
||||||
|
break;
|
||||||
|
case SceneSignal::COMBAT:
|
||||||
|
activeScene = new Combat(&clientIndex, &accountIndex);
|
||||||
|
break;
|
||||||
|
case SceneSignal::DISCONNECTEDSCREEN:
|
||||||
|
activeScene = new DisconnectedScreen();
|
||||||
|
break;
|
||||||
|
default: {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to recognize the scene signal: " << signal;
|
||||||
|
throw(std::logic_error(msg.str()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClientApplication::ClearScene() {
|
||||||
|
delete activeScene;
|
||||||
|
activeScene = nullptr;
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
#include "scene_signal.hpp"
|
||||||
|
#include "singleton.hpp"
|
||||||
|
#include "udp_network_utility.hpp"
|
||||||
|
|
||||||
|
#include "SDL2/SDL.h"
|
||||||
|
#include "SDL2/SDL_net.h"
|
||||||
|
#include "SDL2/SDL_ttf.h"
|
||||||
|
|
||||||
|
class ClientApplication: public Singleton<ClientApplication> {
|
||||||
|
public:
|
||||||
|
void Init(int argc, char* argv[]);
|
||||||
|
void Proc();
|
||||||
|
void Quit();
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend Singleton<ClientApplication>;
|
||||||
|
|
||||||
|
ClientApplication() = default;
|
||||||
|
~ClientApplication() = default;
|
||||||
|
|
||||||
|
//scene management
|
||||||
|
void ProcessEvents();
|
||||||
|
void ProcessSceneSignal(SceneSignal);
|
||||||
|
void ClearScene();
|
||||||
|
|
||||||
|
BaseScene* activeScene = nullptr;
|
||||||
|
|
||||||
|
//TODO: (9) build a "window" class?
|
||||||
|
SDL_Window* window = nullptr;
|
||||||
|
SDL_Renderer* renderer = nullptr;
|
||||||
|
|
||||||
|
//global scene parameters
|
||||||
|
int clientIndex = -1;
|
||||||
|
int accountIndex = -1;
|
||||||
|
};
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "image.hpp"
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
template<typename T = class Image>
|
||||||
|
class CompositeImage {
|
||||||
|
public:
|
||||||
|
CompositeImage() = default;
|
||||||
|
~CompositeImage() = default;
|
||||||
|
|
||||||
|
void Load(SDL_Renderer* const, std::string spriteDir, std::list<std::string> nameList);
|
||||||
|
void SetTextures(std::map<std::string, Image>& templateImages);
|
||||||
|
void Free();
|
||||||
|
|
||||||
|
void DrawTo(SDL_Renderer* const, Sint16 x, Sint16 y, double scaleX = 1.0, double scaleY = 1.0);
|
||||||
|
|
||||||
|
//accessors & mutators
|
||||||
|
T* Find(std::string name);
|
||||||
|
|
||||||
|
bool Enable(std::string name);
|
||||||
|
bool Disable(std::string name);
|
||||||
|
void EnableAll();
|
||||||
|
void DisableAll();
|
||||||
|
|
||||||
|
std::map<std::string, std::pair<bool, T>>* GetTemplateImages();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<std::string, std::pair<bool, T>> imageMap;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void CompositeImage<T>::Load(SDL_Renderer* const renderer, std::string spriteDir, std::list<std::string> nameList) {
|
||||||
|
for (auto& it : nameList) {
|
||||||
|
imageMap[it].first = true;
|
||||||
|
imageMap[it].second.Load(renderer, spriteDir + it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void CompositeImage<T>::SetTextures(std::map<std::string, Image>& templateImages) {
|
||||||
|
for (auto& it : templateImages) {
|
||||||
|
imageMap[it.first].first = true;
|
||||||
|
imageMap[it.first].second.SetTexture(it.second.GetTexture());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void CompositeImage<T>::Free() {
|
||||||
|
imageMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void CompositeImage<T>::DrawTo(SDL_Renderer* const dest, Sint16 x, Sint16 y, double scaleX, double scaleY) {
|
||||||
|
//draw all members, regardless of internal ordering
|
||||||
|
for (auto& it : imageMap) {
|
||||||
|
if (it.second.first) {
|
||||||
|
it.second.second.DrawTo(dest, x, y, scaleX, scaleY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//accessors & mutators
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T* CompositeImage<T>::Find(std::string name) {
|
||||||
|
auto it = imageMap.find(name);
|
||||||
|
if (it == imageMap.end()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return &it->second.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool CompositeImage<T>::Enable(std::string name) {
|
||||||
|
auto it = imageMap.find(name);
|
||||||
|
if (it == imageMap.end()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
imageMap[name].first = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool CompositeImage<T>::Disable(std::string name) {
|
||||||
|
auto it = imageMap.find(name);
|
||||||
|
if (it == imageMap.end()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
imageMap[name].first = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void CompositeImage<T>::EnableAll() {
|
||||||
|
for (auto& it : imageMap) {
|
||||||
|
it.second.first = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void CompositeImage<T>::DisableAll() {
|
||||||
|
for (auto& it : imageMap) {
|
||||||
|
it.second.first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::map<std::string, std::pair<bool, T>>* CompositeImage<T>::GetTemplateImages() {
|
||||||
|
return &imageMap;
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "barrier_manager.hpp"
|
||||||
|
|
||||||
|
void BarrierManager::DrawTo(SDL_Renderer* const dest, Sint16 x, Sint16 y, double scaleX, double scaleY) {
|
||||||
|
for (auto& it : elementMap) {
|
||||||
|
it.second.DrawTo(dest, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarrierManager::LoadBaseImage(SDL_Renderer* renderer, std::string fname) {
|
||||||
|
baseImage.Load(renderer, fname);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarrierManager::UnloadBaseImage() {
|
||||||
|
baseImage.Free();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarrierManager::LoadTemplateImages(SDL_Renderer* renderer, std::string spriteDir, std::list<std::string> names) {
|
||||||
|
//sprite names are file names only
|
||||||
|
for (auto& it : names) {
|
||||||
|
templateImages.emplace(it, Image(renderer, spriteDir + it));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarrierManager::UnloadTemplateImages() {
|
||||||
|
templateImages.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseBarrier* BarrierManager::Create(int index) {
|
||||||
|
elementMap.emplace(index, BaseBarrier(baseImage, templateImages));
|
||||||
|
return &elementMap[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarrierManager::Unload(int i) {
|
||||||
|
elementMap.erase(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarrierManager::UnloadAll() {
|
||||||
|
elementMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarrierManager::UnloadIf(std::function<bool(std::pair<const int, BaseBarrier const&>)> fn) {
|
||||||
|
std::map<int, BaseBarrier>::iterator it = elementMap.begin();
|
||||||
|
while (it != elementMap.end()) {
|
||||||
|
if (fn(*it)) {
|
||||||
|
it = elementMap.erase(it);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int BarrierManager::Size() {
|
||||||
|
return elementMap.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseBarrier* BarrierManager::Find(int i) {
|
||||||
|
std::map<int, BaseBarrier>::iterator it = elementMap.find(i);
|
||||||
|
|
||||||
|
if (it == elementMap.end()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<int, BaseBarrier>* BarrierManager::GetContainer() {
|
||||||
|
return &elementMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, Image>* BarrierManager::GetTemplateContainer() {
|
||||||
|
return &templateImages;
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "base_barrier.hpp"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class BarrierManager {
|
||||||
|
public:
|
||||||
|
BarrierManager() = default;
|
||||||
|
~BarrierManager() = default;
|
||||||
|
|
||||||
|
void DrawTo(SDL_Renderer* const, Sint16 x, Sint16 y, double scaleX = 1.0, double scaleY = 1.0);
|
||||||
|
|
||||||
|
//NOTE: don't use these while you have barriers loaded
|
||||||
|
void LoadBaseImage(SDL_Renderer* renderer, std::string fname);
|
||||||
|
void UnloadBaseImage();
|
||||||
|
void LoadTemplateImages(SDL_Renderer* renderer, std::string spriteDir, std::list<std::string> names);
|
||||||
|
void UnloadTemplateImages();
|
||||||
|
|
||||||
|
BaseBarrier* Create(int index);
|
||||||
|
void Unload(int i);
|
||||||
|
void UnloadAll();
|
||||||
|
void UnloadIf(std::function<bool(std::pair<const int, BaseBarrier const&>)> fn);
|
||||||
|
|
||||||
|
int Size();
|
||||||
|
|
||||||
|
BaseBarrier* Find(int i);
|
||||||
|
std::map<int, BaseBarrier>* GetContainer();
|
||||||
|
std::map<std::string, Image>* GetTemplateContainer();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Image baseImage;
|
||||||
|
std::map<std::string, Image> templateImages;
|
||||||
|
std::map<int, BaseBarrier> elementMap;
|
||||||
|
};
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "base_barrier.hpp"
|
||||||
|
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
BaseBarrier::BaseBarrier(Image& argBaseImage, std::map<std::string, Image>& templateImages) {
|
||||||
|
baseImage.SetTexture(argBaseImage.GetTexture());
|
||||||
|
composite.SetTextures(templateImages);
|
||||||
|
memset(status, 0, sizeof(int) * 8);
|
||||||
|
CorrectSprite();
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseBarrier::~BaseBarrier() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseBarrier::CorrectSprite() {
|
||||||
|
//TODO: link status to sprite
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
//setup the name
|
||||||
|
std::ostringstream os;
|
||||||
|
os << "slot " << i+1;
|
||||||
|
|
||||||
|
switch(status[i]) {
|
||||||
|
case 0:
|
||||||
|
composite.Disable(os.str() + " green.png");
|
||||||
|
composite.Disable(os.str() + " red.png");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
composite.Enable(os.str() + " green.png");
|
||||||
|
composite.Disable(os.str() + " red.png");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
composite.Disable(os.str() + " green.png");
|
||||||
|
composite.Enable(os.str() + " red.png");
|
||||||
|
break;
|
||||||
|
default: {
|
||||||
|
std::ostringstream os;
|
||||||
|
os << "index " << i << ", value " << status[i] << std::endl;
|
||||||
|
throw(std::runtime_error("Unknown graphical status in barrier; " + os.str()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseBarrier::Update() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseBarrier::DrawTo(SDL_Renderer* const dest, int camX, int camY) {
|
||||||
|
//ignore the default sprite for now
|
||||||
|
baseImage.DrawTo(dest, origin.x - camX, origin.y - camY);
|
||||||
|
composite.DrawTo(dest, origin.x - camX, origin.y - camY);
|
||||||
|
}
|
||||||
|
|
||||||
|
int BaseBarrier::SetStatus(int k, int v) {
|
||||||
|
if (k >= 8 || k < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return status[k] = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BaseBarrier::FindStatus(int k) {
|
||||||
|
if (k >= 8 || k < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return status[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
int* BaseBarrier::SetStatusArray(int* ptr) {
|
||||||
|
memcpy(status, ptr, sizeof(int) * 8);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
int* BaseBarrier::GetStatusArray() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
CompositeImage<>* BaseBarrier::GetComposite() {
|
||||||
|
return &composite;
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "entity.hpp"
|
||||||
|
|
||||||
|
#include "composite_image.hpp"
|
||||||
|
|
||||||
|
class BaseBarrier: public Entity {
|
||||||
|
public:
|
||||||
|
BaseBarrier() = default;
|
||||||
|
BaseBarrier(Image& baseImage, std::map<std::string, Image>& templateImages);
|
||||||
|
virtual ~BaseBarrier();
|
||||||
|
|
||||||
|
void CorrectSprite();
|
||||||
|
void Update();
|
||||||
|
void DrawTo(SDL_Renderer* const, int camX, int camY);
|
||||||
|
|
||||||
|
int SetStatus(int, int);
|
||||||
|
int FindStatus(int);
|
||||||
|
|
||||||
|
int* SetStatusArray(int*);
|
||||||
|
int* GetStatusArray();
|
||||||
|
|
||||||
|
CompositeImage<>* GetComposite();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//metadata
|
||||||
|
int status[8];
|
||||||
|
|
||||||
|
Image baseImage;
|
||||||
|
CompositeImage<> composite;
|
||||||
|
};
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "base_character.hpp"
|
||||||
|
|
||||||
|
//TODO: (3) remove this
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//graphics
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void BaseCharacter::CorrectSprite() {
|
||||||
|
//NOTE: These must correspond to the sprite sheet in use
|
||||||
|
if (motion.y > 0) {
|
||||||
|
sprite.SetIndexY(0);
|
||||||
|
}
|
||||||
|
else if (motion.y < 0) {
|
||||||
|
sprite.SetIndexY(1);
|
||||||
|
}
|
||||||
|
else if (motion.x > 0) {
|
||||||
|
sprite.SetIndexY(3);
|
||||||
|
}
|
||||||
|
else if (motion.x < 0) {
|
||||||
|
sprite.SetIndexY(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
//animation
|
||||||
|
if (motion != 0) {
|
||||||
|
sprite.SetDelay(0.1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sprite.SetDelay(0);
|
||||||
|
sprite.SetIndexX(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//metadata
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
int BaseCharacter::SetOwner(int i) {
|
||||||
|
return owner = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BaseCharacter::GetOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BaseCharacter::SetHandle(std::string s) {
|
||||||
|
return handle = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BaseCharacter::GetHandle() const {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BaseCharacter::SetAvatar(SDL_Renderer* const renderer, std::string s) {
|
||||||
|
avatar = s;
|
||||||
|
sprite.Load(renderer, ConfigUtility::GetSingleton()["dir.sprites"] + avatar, CHARACTER_CELLS_X, CHARACTER_CELLS_Y);
|
||||||
|
return avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BaseCharacter::GetAvatar() const {
|
||||||
|
return avatar;
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//components
|
||||||
|
#include "character_defines.hpp"
|
||||||
|
#include "entity.hpp"
|
||||||
|
|
||||||
|
//std namespace
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class BaseCharacter: public Entity {
|
||||||
|
public:
|
||||||
|
BaseCharacter() = default;
|
||||||
|
virtual ~BaseCharacter() = default;
|
||||||
|
|
||||||
|
//graphics
|
||||||
|
void CorrectSprite();
|
||||||
|
|
||||||
|
//metadata
|
||||||
|
int SetOwner(int i);
|
||||||
|
int GetOwner();
|
||||||
|
std::string SetHandle(std::string s);
|
||||||
|
std::string GetHandle() const;
|
||||||
|
std::string SetAvatar(SDL_Renderer* const, std::string s);
|
||||||
|
std::string GetAvatar() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//metadata
|
||||||
|
int owner;
|
||||||
|
std::string handle;
|
||||||
|
std::string avatar;
|
||||||
|
};
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "base_creature.hpp"
|
||||||
|
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
|
void BaseCreature::CorrectSprite() {
|
||||||
|
//TODO: (9) BaseCreature::CorrectSprite()
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BaseCreature::SetHandle(std::string s) {
|
||||||
|
return handle = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BaseCreature::GetHandle() const {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BaseCreature::SetAvatar(SDL_Renderer* const renderer, std::string s) {
|
||||||
|
avatar = s;
|
||||||
|
sprite.Load(renderer, ConfigUtility::GetSingleton()["dir.sprites"] + avatar, 4, 4);
|
||||||
|
return avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BaseCreature::GetAvatar() const {
|
||||||
|
return avatar;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "entity.hpp"
|
||||||
|
|
||||||
|
class BaseCreature: public Entity {
|
||||||
|
public:
|
||||||
|
BaseCreature() = default;
|
||||||
|
virtual ~BaseCreature() = default;
|
||||||
|
|
||||||
|
void CorrectSprite();
|
||||||
|
|
||||||
|
std::string SetHandle(std::string s);
|
||||||
|
std::string GetHandle() const;
|
||||||
|
std::string SetAvatar(SDL_Renderer* const, std::string s);
|
||||||
|
std::string GetAvatar() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//metadata
|
||||||
|
std::string handle;
|
||||||
|
std::string avatar;
|
||||||
|
};
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "entity.hpp"
|
||||||
|
|
||||||
|
void Entity::Update() {
|
||||||
|
origin += motion;
|
||||||
|
sprite.Update(0.016);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Entity::DrawTo(SDL_Renderer* const renderer, int camX, int camY) {
|
||||||
|
sprite.DrawTo(renderer, origin.x - camX, origin.y - camY);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpriteSheet* Entity::GetSprite() {
|
||||||
|
return &sprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//accessors & mutators
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
Vector2 Entity::SetOrigin(Vector2 v) {
|
||||||
|
return origin = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 Entity::SetMotion(Vector2 v) {
|
||||||
|
return motion = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
BoundingBox Entity::SetBounds(BoundingBox b) {
|
||||||
|
return bounds = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 Entity::GetOrigin() const {
|
||||||
|
return origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 Entity::GetMotion() const {
|
||||||
|
return motion;
|
||||||
|
}
|
||||||
|
|
||||||
|
BoundingBox Entity::GetBounds() const {
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "bounding_box.hpp"
|
||||||
|
#include "sprite_sheet.hpp"
|
||||||
|
#include "vector2.hpp"
|
||||||
|
|
||||||
|
//The base class for all objects in the world
|
||||||
|
//TODO: (9) write a better hierarchy
|
||||||
|
class Entity {
|
||||||
|
public:
|
||||||
|
virtual void Update();
|
||||||
|
virtual void DrawTo(SDL_Renderer* const, int camX, int camY);
|
||||||
|
|
||||||
|
SpriteSheet* GetSprite();
|
||||||
|
|
||||||
|
//accessors & mutators
|
||||||
|
Vector2 SetOrigin(Vector2 v);
|
||||||
|
Vector2 SetMotion(Vector2 v);
|
||||||
|
BoundingBox SetBounds(BoundingBox b);
|
||||||
|
|
||||||
|
Vector2 GetOrigin() const;
|
||||||
|
Vector2 GetMotion() const;
|
||||||
|
BoundingBox GetBounds() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Entity() = default;
|
||||||
|
virtual ~Entity() = default;
|
||||||
|
|
||||||
|
SpriteSheet sprite;
|
||||||
|
Vector2 origin;
|
||||||
|
Vector2 motion;
|
||||||
|
BoundingBox bounds;
|
||||||
|
};
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "local_character.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
bool LocalCharacter::ProcessCollisionGrid(std::list<BoundingBox> boxList) {
|
||||||
|
for(auto& box : boxList) {
|
||||||
|
if (box.CheckOverlap(origin + bounds)) {
|
||||||
|
//TODO: (9) write a better collision system
|
||||||
|
origin -= motion;
|
||||||
|
motion = {0, 0};
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "base_character.hpp"
|
||||||
|
#include "bounding_box.hpp"
|
||||||
|
#include "vector2.hpp"
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
class LocalCharacter: public BaseCharacter {
|
||||||
|
public:
|
||||||
|
LocalCharacter() = default;
|
||||||
|
virtual ~LocalCharacter() = default;
|
||||||
|
|
||||||
|
bool ProcessCollisionGrid(std::list<BoundingBox>);
|
||||||
|
|
||||||
|
private:
|
||||||
|
//NOTE: NO MEMBERS
|
||||||
|
};
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#config
|
||||||
|
INCLUDES+=. .. ../../common/global_defines ../../common/utilities ../../TurtleGUI
|
||||||
|
LIBS+=
|
||||||
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#output
|
||||||
|
OUTDIR=..
|
||||||
|
OUT=$(addprefix $(OUTDIR)/,client.a)
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
ar -crs $(OUT) $(OBJ)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "fatal_error.hpp"
|
||||||
|
|
||||||
|
//DOCS: This empty file is used to force an object file
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class fatal_error: public std::runtime_error {
|
||||||
|
public:
|
||||||
|
explicit fatal_error(const std::string& str): runtime_error(str) {}
|
||||||
|
explicit fatal_error(const char* cstr): runtime_error(cstr) {}
|
||||||
|
};
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "heartbeat_utility.hpp"
|
||||||
|
|
||||||
|
#include "channels.hpp"
|
||||||
|
#include "ip_operators.hpp"
|
||||||
|
|
||||||
|
//heartbeat system
|
||||||
|
void HeartbeatUtility::hPing(ServerPacket* const argPacket) {
|
||||||
|
ServerPacket newPacket;
|
||||||
|
newPacket.type = SerialPacketType::PONG;
|
||||||
|
network.SendTo(argPacket->srcAddress, &newPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HeartbeatUtility::hPong(ServerPacket* const argPacket) {
|
||||||
|
if (*network.GetIPAddress(Channels::SERVER) != argPacket->srcAddress) {
|
||||||
|
throw(std::runtime_error("Heartbeat message received from an unknown source"));
|
||||||
|
}
|
||||||
|
attemptedBeats = 0;
|
||||||
|
lastBeat = Clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
int HeartbeatUtility::CheckHeartBeat() {
|
||||||
|
//check the connection (heartbeat)
|
||||||
|
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
|
||||||
|
if (attemptedBeats > 2) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ServerPacket newPacket;
|
||||||
|
newPacket.type = SerialPacketType::PING;
|
||||||
|
network.SendTo(Channels::SERVER, &newPacket);
|
||||||
|
|
||||||
|
attemptedBeats++;
|
||||||
|
lastBeat = Clock::now();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "server_packet.hpp"
|
||||||
|
#include "udp_network_utility.hpp"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
class HeartbeatUtility {
|
||||||
|
public:
|
||||||
|
//heartbeat system
|
||||||
|
void hPing(ServerPacket* const);
|
||||||
|
void hPong(ServerPacket* const);
|
||||||
|
|
||||||
|
int CheckHeartBeat();
|
||||||
|
|
||||||
|
private:
|
||||||
|
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
|
||||||
|
typedef std::chrono::steady_clock Clock;
|
||||||
|
Clock::time_point lastBeat = Clock::now();
|
||||||
|
int attemptedBeats = 0;
|
||||||
|
};
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "client_application.hpp"
|
||||||
|
|
||||||
|
//singletons
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
#include "udp_network_utility.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
try {
|
||||||
|
//create the singletons
|
||||||
|
ConfigUtility::CreateSingleton();
|
||||||
|
UDPNetworkUtility::CreateSingleton();
|
||||||
|
|
||||||
|
//call the client's routines
|
||||||
|
ClientApplication::CreateSingleton();
|
||||||
|
ClientApplication& app = ClientApplication::GetSingleton();
|
||||||
|
|
||||||
|
app.Init(argc, argv);
|
||||||
|
app.Proc();
|
||||||
|
app.Quit();
|
||||||
|
|
||||||
|
//control the position of the app's destructor
|
||||||
|
ClientApplication::DeleteSingleton();
|
||||||
|
|
||||||
|
//delete the singletons
|
||||||
|
ConfigUtility::DeleteSingleton();
|
||||||
|
UDPNetworkUtility::DeleteSingleton();
|
||||||
|
}
|
||||||
|
catch(exception& e) {
|
||||||
|
cerr << "Fatal exception thrown: " << e.what() << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
#include directories
|
||||||
|
INCLUDES+=. entities scenes ../common/debugging ../common/global_defines ../common/network ../common/network/packet_types ../common/utilities ../TurtleGUI ../TurtleMap
|
||||||
|
|
||||||
|
#libraries
|
||||||
|
#the order of the $(LIBS) is important, at least for MinGW
|
||||||
|
LIBS+=client.a ../libcommon.a ../libturtlegui.a ../libturtlemap.a -lSDL2_net
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
|
LIBS+=-lwsock32 -liphlpapi -lmingw32
|
||||||
|
endif
|
||||||
|
LIBS+=-lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf
|
||||||
|
|
||||||
|
#flags
|
||||||
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
ifeq ($(shell uname), Linux)
|
||||||
|
#read data about the current install
|
||||||
|
CXXFLAGS+=$(shell sdl-config --cflags --static-libs)
|
||||||
|
endif
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#output
|
||||||
|
OUTDIR=../out
|
||||||
|
OUT=$(addprefix $(OUTDIR)/,client)
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
$(MAKE) -C entities
|
||||||
|
$(MAKE) -C scenes
|
||||||
|
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
|
$(RM) *.o *.a *.exe
|
||||||
|
else ifeq ($(shell uname), Linux)
|
||||||
|
find . -type f -name *.o -exec rm -f -r -v {} \;
|
||||||
|
find . -type f -name *.a -exec rm -f -r -v {} \;
|
||||||
|
rm -f -v out/client out/server
|
||||||
|
endif
|
||||||
|
|
||||||
|
rebuild: clean all
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
enum SceneSignal {
|
||||||
|
//reserved members for internal use
|
||||||
|
QUIT = -1,
|
||||||
|
CONTINUE = 0,
|
||||||
|
FIRST = 1,
|
||||||
|
|
||||||
|
//custom scenes
|
||||||
|
SPLASHSCREEN,
|
||||||
|
MAINMENU,
|
||||||
|
OPTIONSMENU,
|
||||||
|
LOBBYMENU,
|
||||||
|
WORLD,
|
||||||
|
COMBAT,
|
||||||
|
DISCONNECTEDSCREEN,
|
||||||
|
};
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "combat.hpp"
|
||||||
|
|
||||||
|
//Public access members
|
||||||
|
Combat::Combat(int* const argClientIndex, int* const argAccountIndex) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
Combat::~Combat() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Combat::RenderFrame(SDL_Renderer* renderer) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//frame phases
|
||||||
|
void Combat::FrameStart() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Combat::Update() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Combat::FrameEnd() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//input events
|
||||||
|
void Combat::QuitEvent() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Combat::MouseMotion(SDL_MouseMotionEvent const& event) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Combat::MouseButtonDown(SDL_MouseButtonEvent const& event) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Combat::MouseButtonUp(SDL_MouseButtonEvent const& event) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Combat::MouseWheel(SDL_MouseWheelEvent const& event) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Combat::KeyDown(SDL_KeyboardEvent const& event) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Combat::KeyUp(SDL_KeyboardEvent const& event) {
|
||||||
|
//
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
|
class Combat: public BaseScene {
|
||||||
|
public:
|
||||||
|
//Public access members
|
||||||
|
Combat(int* const argClientIndex, int* const argAccountIndex);
|
||||||
|
~Combat();
|
||||||
|
|
||||||
|
void RenderFrame(SDL_Renderer* renderer) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
//frame phases
|
||||||
|
void FrameStart() override;
|
||||||
|
void Update() override;
|
||||||
|
void FrameEnd() override;
|
||||||
|
|
||||||
|
//input events
|
||||||
|
void QuitEvent();
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const& event) override;
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseWheel(SDL_MouseWheelEvent const& event) override;
|
||||||
|
void KeyDown(SDL_KeyboardEvent const& event) override;
|
||||||
|
void KeyUp(SDL_KeyboardEvent const& event) override;
|
||||||
|
};
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "disconnected_screen.hpp"
|
||||||
|
|
||||||
|
#include "channels.hpp"
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
#include "udp_network_utility.hpp"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
constexpr SDL_Color WHITE = {255, 255, 255, 255};
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Public access members
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
DisconnectedScreen::DisconnectedScreen() {
|
||||||
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
|
||||||
|
//setup the utility objects
|
||||||
|
//TODO: (1) resource tool, to prevent reloading like this
|
||||||
|
image.Load(GetRenderer(), config["dir.interface"] + "button_blue.png");
|
||||||
|
font = TTF_OpenFont(config["client.font"].c_str(), 12);
|
||||||
|
|
||||||
|
//check that the font loaded
|
||||||
|
if (!font) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to load a font file; " << SDL_GetError();
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//setup the button
|
||||||
|
backButton.SetBackgroundTexture(GetRenderer(), image.GetTexture());
|
||||||
|
backButton.SetText(GetRenderer(), font, WHITE, "Back");
|
||||||
|
|
||||||
|
//set the button positions
|
||||||
|
backButton.SetX(50);
|
||||||
|
backButton.SetY(50);
|
||||||
|
|
||||||
|
//set the disconnection message text
|
||||||
|
textLine.SetX(50);
|
||||||
|
textLine.SetY(30);
|
||||||
|
textLine.SetText(GetRenderer(), font, WHITE, config["client.disconnectMessage"]);
|
||||||
|
|
||||||
|
//full reset
|
||||||
|
UDPNetworkUtility::GetSingleton().Unbind(Channels::SERVER);
|
||||||
|
|
||||||
|
//auto return
|
||||||
|
startTick = std::chrono::steady_clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
DisconnectedScreen::~DisconnectedScreen() {
|
||||||
|
TTF_CloseFont(font);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Frame loop
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void DisconnectedScreen::FrameStart() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisconnectedScreen::Update() {
|
||||||
|
if (std::chrono::steady_clock::now() - startTick > std::chrono::duration<int>(10)) {
|
||||||
|
SetSceneSignal(SceneSignal::MAINMENU);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Eat incoming packets
|
||||||
|
while(UDPNetworkUtility::GetSingleton().Receive());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisconnectedScreen::FrameEnd() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisconnectedScreen::RenderFrame(SDL_Renderer* renderer) {
|
||||||
|
backButton.DrawTo(renderer);
|
||||||
|
textLine.DrawTo(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Event handlers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void DisconnectedScreen::MouseMotion(SDL_MouseMotionEvent const& event) {
|
||||||
|
backButton.MouseMotion(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisconnectedScreen::MouseButtonDown(SDL_MouseButtonEvent const& event) {
|
||||||
|
backButton.MouseButtonDown(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisconnectedScreen::MouseButtonUp(SDL_MouseButtonEvent const& event) {
|
||||||
|
if (backButton.MouseButtonUp(event) == Button::State::RELEASED) {
|
||||||
|
SetSceneSignal(SceneSignal::MAINMENU);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisconnectedScreen::MouseWheel(SDL_MouseWheelEvent const& event) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisconnectedScreen::KeyDown(SDL_KeyboardEvent const& event) {
|
||||||
|
switch(event.keysym.sym) {
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
SetSceneSignal(SceneSignal::MAINMENU);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisconnectedScreen::KeyUp(SDL_KeyboardEvent const& event) {
|
||||||
|
//
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
#include "button.hpp"
|
||||||
|
#include "image.hpp"
|
||||||
|
#include "text_line.hpp"
|
||||||
|
|
||||||
|
#include "SDL2/SDL_ttf.h"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
class DisconnectedScreen : public BaseScene {
|
||||||
|
public:
|
||||||
|
//Public access members
|
||||||
|
DisconnectedScreen();
|
||||||
|
~DisconnectedScreen();
|
||||||
|
|
||||||
|
void RenderFrame(SDL_Renderer* renderer) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//frame phases
|
||||||
|
void FrameStart() override;
|
||||||
|
void Update() override;
|
||||||
|
void FrameEnd() override;
|
||||||
|
|
||||||
|
//input events
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const& event) override;
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseWheel(SDL_MouseWheelEvent const& event) override;
|
||||||
|
void KeyDown(SDL_KeyboardEvent const& event) override;
|
||||||
|
void KeyUp(SDL_KeyboardEvent const& event) override;
|
||||||
|
|
||||||
|
//graphics
|
||||||
|
Image image;
|
||||||
|
TTF_Font* font = nullptr;
|
||||||
|
Button backButton;
|
||||||
|
TextLine textLine;
|
||||||
|
|
||||||
|
//auto return
|
||||||
|
std::chrono::steady_clock::time_point startTick;
|
||||||
|
};
|
||||||
@@ -0,0 +1,424 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "lobby_menu.hpp"
|
||||||
|
|
||||||
|
#include "channels.hpp"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
constexpr SDL_Color WHITE = {255, 255, 255, 255};
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Public access members
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
LobbyMenu::LobbyMenu(int* const argClientIndex, int* const argAccountIndex):
|
||||||
|
clientIndex(*argClientIndex),
|
||||||
|
accountIndex(*argAccountIndex)
|
||||||
|
{
|
||||||
|
//preemptive reset
|
||||||
|
clientIndex = -1;
|
||||||
|
accountIndex = -1;
|
||||||
|
|
||||||
|
//setup the utility objects
|
||||||
|
buttonImage.Load(GetRenderer(), config["dir.interface"] + "button_blue.png");
|
||||||
|
font = TTF_OpenFont(config["client.font"].c_str(), 12);
|
||||||
|
|
||||||
|
//check that the font loaded
|
||||||
|
if (!font) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to load a font file; " << SDL_GetError();
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//setup the buttons
|
||||||
|
searchButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
||||||
|
searchButton.SetText(GetRenderer(), font, WHITE, "Search");
|
||||||
|
joinButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
||||||
|
joinButton.SetText(GetRenderer(), font, WHITE, "Join");
|
||||||
|
backButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
||||||
|
backButton.SetText(GetRenderer(), font, WHITE, "Back");
|
||||||
|
|
||||||
|
//set the button positions (assumed)
|
||||||
|
searchButton.SetX(50);
|
||||||
|
searchButton.SetY(50);
|
||||||
|
joinButton.SetX(50);
|
||||||
|
joinButton.SetY(70);
|
||||||
|
backButton.SetX(50);
|
||||||
|
backButton.SetY(90);
|
||||||
|
|
||||||
|
//setup the text fields
|
||||||
|
username.SetText(GetRenderer(), font, WHITE, config["client.username"]);
|
||||||
|
password.SetText(GetRenderer(), font, WHITE, config["client.password"]);
|
||||||
|
handle.SetText(GetRenderer(), font, WHITE, config["client.handle"]);
|
||||||
|
avatar.SetText(GetRenderer(), font, WHITE, config["client.avatar"]);
|
||||||
|
|
||||||
|
username.SetBounds(BoundingBox{0, 0, 300, 20});
|
||||||
|
password.SetBounds(BoundingBox{0, 0, 300, 20});
|
||||||
|
handle.SetBounds(BoundingBox{0, 0, 300, 20});
|
||||||
|
avatar.SetBounds(BoundingBox{0, 0, 300, 20});
|
||||||
|
|
||||||
|
username.SetX(50);
|
||||||
|
username.SetY(110);
|
||||||
|
password.SetX(50);
|
||||||
|
password.SetY(130);
|
||||||
|
handle.SetX(50);
|
||||||
|
handle.SetY(150);
|
||||||
|
avatar.SetX(50);
|
||||||
|
avatar.SetY(170);
|
||||||
|
|
||||||
|
//pseudo-list selection
|
||||||
|
//TODO: move this into the UI library?
|
||||||
|
boundingBox = {300, 50, 200, 12};
|
||||||
|
|
||||||
|
//hacked together a highlight box
|
||||||
|
highlightImage.Create(GetRenderer(), 300, 12, {49, 150, 5, 255});
|
||||||
|
|
||||||
|
//Eat incoming packets
|
||||||
|
while(network.Receive());
|
||||||
|
|
||||||
|
//Initial broadcast
|
||||||
|
SendBroadcastRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
LobbyMenu::~LobbyMenu() {
|
||||||
|
TTF_CloseFont(font);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Frame loop
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void LobbyMenu::FrameStart() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::Update() {
|
||||||
|
//suck in and process all waiting packets
|
||||||
|
SerialPacket* packetBuffer = reinterpret_cast<SerialPacket*>(new char[MAX_PACKET_SIZE]);
|
||||||
|
while(network.Receive(packetBuffer)) {
|
||||||
|
HandlePacket(packetBuffer);
|
||||||
|
}
|
||||||
|
delete reinterpret_cast<char*>(packetBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::FrameEnd() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::RenderFrame(SDL_Renderer* renderer) {
|
||||||
|
//TODO: (2) I need a proper UI system for the entire client and the editor
|
||||||
|
|
||||||
|
//UI
|
||||||
|
searchButton.DrawTo(renderer);
|
||||||
|
joinButton.DrawTo(renderer);
|
||||||
|
backButton.DrawTo(renderer);
|
||||||
|
|
||||||
|
username.DrawTo(renderer);
|
||||||
|
password.DrawTo(renderer);
|
||||||
|
handle.DrawTo(renderer);
|
||||||
|
avatar.DrawTo(renderer);
|
||||||
|
|
||||||
|
//TODO: (3) draw headers for the server list
|
||||||
|
//TODO: (3) ping/delay displayed in the server list
|
||||||
|
for (int i = 0; i < serverVector.size(); i++) {
|
||||||
|
//draw the selected server's highlight
|
||||||
|
if (selection == &serverVector[i]) {
|
||||||
|
highlightImage.DrawTo(renderer, boundingBox.x, boundingBox.y + boundingBox.h * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
//draw the server's info
|
||||||
|
serverVector[i].nameImage.SetX(boundingBox.x);
|
||||||
|
serverVector[i].nameImage.SetY(boundingBox.y + boundingBox.h * i);
|
||||||
|
serverVector[i].nameImage.DrawTo(renderer);
|
||||||
|
|
||||||
|
serverVector[i].playerCountImage.SetX(boundingBox.x+276);
|
||||||
|
serverVector[i].playerCountImage.SetY(boundingBox.y + boundingBox.h * i);
|
||||||
|
serverVector[i].playerCountImage.DrawTo(renderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Event handlers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void LobbyMenu::MouseMotion(SDL_MouseMotionEvent const& event) {
|
||||||
|
searchButton.MouseMotion(event);
|
||||||
|
joinButton.MouseMotion(event);
|
||||||
|
backButton.MouseMotion(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::MouseButtonDown(SDL_MouseButtonEvent const& event) {
|
||||||
|
searchButton.MouseButtonDown(event);
|
||||||
|
joinButton.MouseButtonDown(event);
|
||||||
|
backButton.MouseButtonDown(event);
|
||||||
|
|
||||||
|
if (username.MouseButtonDown(event)) {
|
||||||
|
//GUI trick
|
||||||
|
if (!username.GetText().compare(config["client.username"])) {
|
||||||
|
username.SetText(GetRenderer(), font, WHITE, "");
|
||||||
|
}
|
||||||
|
SDL_StartTextInput();
|
||||||
|
}
|
||||||
|
if (password.MouseButtonDown(event)) {
|
||||||
|
//GUI trick
|
||||||
|
if (!password.GetText().compare(config["client.password"])) {
|
||||||
|
password.SetText(GetRenderer(), font, WHITE, "");
|
||||||
|
}
|
||||||
|
SDL_StartTextInput();
|
||||||
|
}
|
||||||
|
if (handle.MouseButtonDown(event)) {
|
||||||
|
//GUI trick
|
||||||
|
if (!handle.GetText().compare(config["client.handle"])) {
|
||||||
|
handle.SetText(GetRenderer(), font, WHITE, "");
|
||||||
|
}
|
||||||
|
SDL_StartTextInput();
|
||||||
|
}
|
||||||
|
if (avatar.MouseButtonDown(event)) {
|
||||||
|
//GUI trick
|
||||||
|
if (!avatar.GetText().compare(config["client.avatar"])) {
|
||||||
|
avatar.SetText(GetRenderer(), font, WHITE, "");
|
||||||
|
}
|
||||||
|
SDL_StartTextInput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& event) {
|
||||||
|
if (searchButton.MouseButtonUp(event) == Button::State::RELEASED) {
|
||||||
|
SendBroadcastRequest();
|
||||||
|
}
|
||||||
|
if (joinButton.MouseButtonUp(event) == Button::State::RELEASED && selection && selection->compatible) {
|
||||||
|
SendJoinRequest();
|
||||||
|
}
|
||||||
|
if (backButton.MouseButtonUp(event) == Button::State::RELEASED) {
|
||||||
|
SetSceneSignal(SceneSignal::MAINMENU);
|
||||||
|
}
|
||||||
|
|
||||||
|
//has the user selected a server on the list?
|
||||||
|
BoundingBox tmpBox = boundingBox;
|
||||||
|
tmpBox.h *= serverVector.size(); //within the list bounds
|
||||||
|
if (tmpBox.CheckOverlap({event.x, event.y})) {
|
||||||
|
//NOTE: this memory trick requires a vector
|
||||||
|
selection = &serverVector[(event.y - boundingBox.y)/boundingBox.h];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
selection = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::MouseWheel(SDL_MouseWheelEvent const& event) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::KeyDown(SDL_KeyboardEvent const& event) {
|
||||||
|
switch(event.keysym.sym) {
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
SetSceneSignal(SceneSignal::MAINMENU);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDLK_BACKSPACE:
|
||||||
|
//easier than mucking about with SDL_TextEditEvent
|
||||||
|
if (username.GetFocus()) {
|
||||||
|
username.PopChars(GetRenderer(), font, WHITE, 1);
|
||||||
|
}
|
||||||
|
if (password.GetFocus()) {
|
||||||
|
password.PopChars(GetRenderer(), font, WHITE, 1);
|
||||||
|
}
|
||||||
|
if (handle.GetFocus()) {
|
||||||
|
handle.PopChars(GetRenderer(), font, WHITE, 1);
|
||||||
|
}
|
||||||
|
if (avatar.GetFocus()) {
|
||||||
|
avatar.PopChars(GetRenderer(), font, WHITE, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::KeyUp(SDL_KeyboardEvent const& event) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::TextInput(SDL_TextInputEvent const& event) {
|
||||||
|
if (username.GetFocus()) {
|
||||||
|
username.PushText(GetRenderer(), font, WHITE, std::string(event.text));
|
||||||
|
}
|
||||||
|
if (password.GetFocus()) {
|
||||||
|
password.PushText(GetRenderer(), font, WHITE, std::string(event.text));
|
||||||
|
}
|
||||||
|
if (handle.GetFocus()) {
|
||||||
|
handle.PushText(GetRenderer(), font, WHITE, std::string(event.text));
|
||||||
|
}
|
||||||
|
if (avatar.GetFocus()) {
|
||||||
|
avatar.PushText(GetRenderer(), font, WHITE, std::string(event.text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Network handlers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void LobbyMenu::HandlePacket(SerialPacket* const argPacket) {
|
||||||
|
switch(argPacket->type) {
|
||||||
|
//responses
|
||||||
|
case SerialPacketType::BROADCAST_RESPONSE:
|
||||||
|
HandleBroadcastResponse(static_cast<ServerPacket*>(argPacket));
|
||||||
|
break;
|
||||||
|
case SerialPacketType::JOIN_RESPONSE:
|
||||||
|
HandleJoinResponse(static_cast<ClientPacket*>(argPacket));
|
||||||
|
break;
|
||||||
|
case SerialPacketType::LOGIN_RESPONSE:
|
||||||
|
HandleLoginResponse(static_cast<ClientPacket*>(argPacket));
|
||||||
|
break;
|
||||||
|
|
||||||
|
//rejections
|
||||||
|
case SerialPacketType::JOIN_REJECTION:
|
||||||
|
HandleJoinRejection(static_cast<TextPacket*>(argPacket));
|
||||||
|
break;
|
||||||
|
case SerialPacketType::LOGIN_REJECTION:
|
||||||
|
HandleLoginRejection(static_cast<TextPacket*>(argPacket));
|
||||||
|
break;
|
||||||
|
|
||||||
|
//handle errors
|
||||||
|
default: {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Unknown SerialPacketType encountered in LobbyMenu: " << static_cast<int>(argPacket->type);
|
||||||
|
throw(std::runtime_error( msg.str() ));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
|
||||||
|
//extract the data
|
||||||
|
ServerInfo newServer;
|
||||||
|
|
||||||
|
newServer.address = argPacket->srcAddress;
|
||||||
|
newServer.name = argPacket->name;
|
||||||
|
newServer.playerCount = argPacket->playerCount;
|
||||||
|
newServer.version = argPacket->version;
|
||||||
|
newServer.compatible = newServer.version == NETWORK_VERSION;
|
||||||
|
|
||||||
|
//push
|
||||||
|
serverVector.push_back(newServer);
|
||||||
|
|
||||||
|
//BUGFIX: since TextLine lacks the memory management of Image, I'll wait until after the line is in the vector to handle these
|
||||||
|
|
||||||
|
//fancy colors
|
||||||
|
SDL_Color color;
|
||||||
|
if (newServer.compatible) {
|
||||||
|
color = {255, 255, 255, 255};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
color = {255, 0, 0, 255};
|
||||||
|
}
|
||||||
|
|
||||||
|
//fancy itoa
|
||||||
|
auto itoa_base10 = [](int i) -> std::string {
|
||||||
|
char str[20];
|
||||||
|
sprintf(str, "%d", i);
|
||||||
|
return std::string(str);
|
||||||
|
};
|
||||||
|
|
||||||
|
//text graphics
|
||||||
|
serverVector.back().nameImage.SetText(GetRenderer(), font, color, newServer.name);
|
||||||
|
serverVector.back().playerCountImage.SetText(GetRenderer(), font, color, itoa_base10(newServer.playerCount));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
|
||||||
|
//save the server's data
|
||||||
|
clientIndex = argPacket->clientIndex;
|
||||||
|
network.Bind(argPacket->srcAddress, Channels::SERVER);
|
||||||
|
|
||||||
|
//request login data
|
||||||
|
SendLoginRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::HandleLoginResponse(ClientPacket* const argPacket) {
|
||||||
|
if (argPacket->clientIndex != clientIndex) {
|
||||||
|
throw(std::runtime_error("Client index invalid during login"));
|
||||||
|
}
|
||||||
|
accountIndex = argPacket->accountIndex;
|
||||||
|
SetSceneSignal(SceneSignal::WORLD);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::HandleJoinRejection(TextPacket* const argPacket) {
|
||||||
|
//NOTE: NEVER HAPPENS
|
||||||
|
throw(std::runtime_error("HandleJoinRejection"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::HandleLoginRejection(TextPacket* const argPacket) {
|
||||||
|
config["client.disconnectMessage"] = std::string() + "Join request rejected: " + argPacket->text;
|
||||||
|
SetSceneSignal(SceneSignal::DISCONNECTEDSCREEN);
|
||||||
|
|
||||||
|
//avoid crashes from the heartbeat system
|
||||||
|
ClientPacket newPacket;
|
||||||
|
newPacket.type = SerialPacketType::DISCONNECT_REQUEST;
|
||||||
|
newPacket.clientIndex = clientIndex;
|
||||||
|
network.SendTo(argPacket->srcAddress, &newPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//server control
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void LobbyMenu::SendBroadcastRequest() {
|
||||||
|
//broadcast to the home server, and to the LAN
|
||||||
|
ClientPacket packet;
|
||||||
|
|
||||||
|
packet.type = SerialPacketType::BROADCAST_REQUEST;
|
||||||
|
network.SendTo(config["server.home"].c_str(), config.Int("server.port"), &packet);
|
||||||
|
network.SendTo(config["server.host"].c_str(), config.Int("server.port"), &packet);
|
||||||
|
|
||||||
|
//reset the server list
|
||||||
|
serverVector.clear();
|
||||||
|
selection = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::SendJoinRequest() {
|
||||||
|
//BUG: 101 received in LobbyMenu on failed join
|
||||||
|
//pack the packet
|
||||||
|
ClientPacket packet;
|
||||||
|
packet.type = SerialPacketType::JOIN_REQUEST;
|
||||||
|
|
||||||
|
//join the selected server
|
||||||
|
network.SendTo(selection->address, &packet);
|
||||||
|
selection = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::SendLoginRequest() {
|
||||||
|
//NOTE: high cohesion
|
||||||
|
//TODO: (9) have a separate login screen
|
||||||
|
ClientPacket packet;
|
||||||
|
packet.type = SerialPacketType::LOGIN_REQUEST;
|
||||||
|
packet.clientIndex = clientIndex;
|
||||||
|
strncpy(packet.username, username.GetText().c_str(), PACKET_STRING_SIZE+1);
|
||||||
|
|
||||||
|
network.SendTo(Channels::SERVER, &packet);
|
||||||
|
|
||||||
|
//TODO: remove
|
||||||
|
config["client.username"] = username.GetText();
|
||||||
|
config["client.password"] = password.GetText();
|
||||||
|
config["client.handle"] = handle.GetText();
|
||||||
|
config["client.avatar"] = avatar.GetText();
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//graphics & ui
|
||||||
|
#include "image.hpp"
|
||||||
|
#include "button.hpp"
|
||||||
|
#include "bounding_box.hpp"
|
||||||
|
#include "text_field.hpp"
|
||||||
|
#include "text_line.hpp"
|
||||||
|
|
||||||
|
#include "SDL2/SDL_ttf.h"
|
||||||
|
|
||||||
|
//utilities
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
#include "udp_network_utility.hpp"
|
||||||
|
#include "serial_packet.hpp"
|
||||||
|
|
||||||
|
//client
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
|
//STL
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class LobbyMenu : public BaseScene {
|
||||||
|
public:
|
||||||
|
//Public access members
|
||||||
|
LobbyMenu(int* const argClientIndex, int* const argAccountIndex);
|
||||||
|
~LobbyMenu();
|
||||||
|
|
||||||
|
void RenderFrame(SDL_Renderer* renderer) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//frame phases
|
||||||
|
void FrameStart() override;
|
||||||
|
void Update() override;
|
||||||
|
void FrameEnd() override;
|
||||||
|
|
||||||
|
//input events
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const& event) override;
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseWheel(SDL_MouseWheelEvent const& event) override;
|
||||||
|
void KeyDown(SDL_KeyboardEvent const& event) override;
|
||||||
|
void KeyUp(SDL_KeyboardEvent const& event) override;
|
||||||
|
void TextInput(SDL_TextInputEvent const& event) override;
|
||||||
|
|
||||||
|
//Network handlers
|
||||||
|
void HandlePacket(SerialPacket* const);
|
||||||
|
void HandleBroadcastResponse(ServerPacket* const);
|
||||||
|
void HandleJoinResponse(ClientPacket* const);
|
||||||
|
void HandleLoginResponse(ClientPacket* const);
|
||||||
|
void HandleJoinRejection(TextPacket* const);
|
||||||
|
void HandleLoginRejection(TextPacket* const);
|
||||||
|
|
||||||
|
//server control
|
||||||
|
void SendBroadcastRequest();
|
||||||
|
void SendJoinRequest();
|
||||||
|
void SendLoginRequest();
|
||||||
|
|
||||||
|
//shared parameters
|
||||||
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
|
||||||
|
int& clientIndex;
|
||||||
|
int& accountIndex;
|
||||||
|
|
||||||
|
//define the list object
|
||||||
|
struct ServerInfo {
|
||||||
|
//graphics
|
||||||
|
TextLine nameImage;
|
||||||
|
TextLine playerCountImage;
|
||||||
|
|
||||||
|
//networking
|
||||||
|
IPaddress address;
|
||||||
|
std::string name;
|
||||||
|
int playerCount;
|
||||||
|
int version;
|
||||||
|
bool compatible;
|
||||||
|
};
|
||||||
|
|
||||||
|
//members
|
||||||
|
Image buttonImage;
|
||||||
|
Image highlightImage;
|
||||||
|
TTF_Font* font = nullptr;
|
||||||
|
Button searchButton;
|
||||||
|
Button joinButton;
|
||||||
|
Button backButton;
|
||||||
|
TextField username;
|
||||||
|
TextField password;
|
||||||
|
TextField handle;
|
||||||
|
TextField avatar;
|
||||||
|
|
||||||
|
std::vector<ServerInfo> serverVector;
|
||||||
|
ServerInfo* selection = nullptr;
|
||||||
|
|
||||||
|
BoundingBox boundingBox;
|
||||||
|
};
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "main_menu.hpp"
|
||||||
|
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
constexpr SDL_Color WHITE = {255, 255, 255, 255};
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Public access members
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
MainMenu::MainMenu() {
|
||||||
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
|
||||||
|
//setup the utility objects
|
||||||
|
buttonImage.Load(GetRenderer(), config["dir.interface"] + "button_blue.png");
|
||||||
|
font = TTF_OpenFont(config["client.font"].c_str(), 12);
|
||||||
|
|
||||||
|
//check that the font loaded
|
||||||
|
if (!font) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to load a font file; " << SDL_GetError();
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//setup the buttons
|
||||||
|
startButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
||||||
|
startButton.SetText(GetRenderer(), font, WHITE, "Start");
|
||||||
|
optionsButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
||||||
|
optionsButton.SetText(GetRenderer(), font, WHITE, "Options");
|
||||||
|
quitButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
||||||
|
quitButton.SetText(GetRenderer(), font, WHITE, "Quit");
|
||||||
|
|
||||||
|
//set the button positions
|
||||||
|
startButton.SetX(50);
|
||||||
|
startButton.SetY(50 + 20 * 0);
|
||||||
|
optionsButton.SetX(50);
|
||||||
|
optionsButton.SetY(50 + 20 * 1);
|
||||||
|
quitButton.SetX(50);
|
||||||
|
quitButton.SetY(50 + 20 * 2);
|
||||||
|
|
||||||
|
//text box
|
||||||
|
int h = -1;
|
||||||
|
SDL_RenderGetLogicalSize(GetRenderer(), nullptr, &h);
|
||||||
|
|
||||||
|
textBox.SetX(50);
|
||||||
|
textBox.SetY(h-100);
|
||||||
|
|
||||||
|
textBox.PushLine(GetRenderer(), font, WHITE, "Thanks for playing!");
|
||||||
|
textBox.PushLine(GetRenderer(), font, WHITE, "You can get the latest version at: ");
|
||||||
|
textBox.PushLine(GetRenderer(), font, WHITE, "krgamestudios.com"); //TODO: (9) click to open the website/update
|
||||||
|
|
||||||
|
//debug
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
MainMenu::~MainMenu() {
|
||||||
|
TTF_CloseFont(font);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Frame loop
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void MainMenu::FrameStart() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::Update() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::FrameEnd() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::RenderFrame(SDL_Renderer* renderer) {
|
||||||
|
startButton.DrawTo(renderer);
|
||||||
|
optionsButton.DrawTo(renderer);
|
||||||
|
quitButton.DrawTo(renderer);
|
||||||
|
textBox.DrawTo(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Event handlers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void MainMenu::MouseMotion(SDL_MouseMotionEvent const& event) {
|
||||||
|
startButton.MouseMotion(event);
|
||||||
|
optionsButton.MouseMotion(event);
|
||||||
|
quitButton.MouseMotion(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& event) {
|
||||||
|
startButton.MouseButtonDown(event);
|
||||||
|
optionsButton.MouseButtonDown(event);
|
||||||
|
quitButton.MouseButtonDown(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& event) {
|
||||||
|
//TODO: (2) Buttons should only register as "selected" when the left button is used
|
||||||
|
if (startButton.MouseButtonUp(event) == Button::State::RELEASED) {
|
||||||
|
SetSceneSignal(SceneSignal::LOBBYMENU);
|
||||||
|
}
|
||||||
|
if (optionsButton.MouseButtonUp(event) == Button::State::RELEASED) {
|
||||||
|
SetSceneSignal(SceneSignal::OPTIONSMENU);
|
||||||
|
}
|
||||||
|
if (quitButton.MouseButtonUp(event) == Button::State::RELEASED) {
|
||||||
|
QuitEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::MouseWheel(SDL_MouseWheelEvent const& event) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::KeyDown(SDL_KeyboardEvent const& event) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::KeyUp(SDL_KeyboardEvent const& event) {
|
||||||
|
switch(event.keysym.sym) {
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
QuitEvent();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
#include "button.hpp"
|
||||||
|
#include "image.hpp"
|
||||||
|
#include "text_box.hpp"
|
||||||
|
|
||||||
|
#include "SDL2/SDL_ttf.h"
|
||||||
|
|
||||||
|
class MainMenu : public BaseScene {
|
||||||
|
public:
|
||||||
|
//Public access members
|
||||||
|
MainMenu();
|
||||||
|
~MainMenu();
|
||||||
|
|
||||||
|
void RenderFrame(SDL_Renderer* renderer) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//frame phases
|
||||||
|
void FrameStart() override;
|
||||||
|
void Update() override;
|
||||||
|
void FrameEnd() override;
|
||||||
|
|
||||||
|
//input events
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const& event) override;
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseWheel(SDL_MouseWheelEvent const& event) override;
|
||||||
|
void KeyDown(SDL_KeyboardEvent const& event) override;
|
||||||
|
void KeyUp(SDL_KeyboardEvent const& event) override;
|
||||||
|
|
||||||
|
//members
|
||||||
|
Image buttonImage;
|
||||||
|
TTF_Font* font = nullptr;
|
||||||
|
Button startButton;
|
||||||
|
Button optionsButton;
|
||||||
|
Button quitButton;
|
||||||
|
TextBox textBox;
|
||||||
|
};
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#config
|
||||||
|
INCLUDES+=. .. ../entities ../../common/debugging ../../common/global_defines ../../common/network ../../common/network/packet_types ../../common/utilities ../../TurtleGUI ../../TurtleMap
|
||||||
|
LIBS+=
|
||||||
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#output
|
||||||
|
OUTDIR=..
|
||||||
|
OUT=$(addprefix $(OUTDIR)/,client.a)
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
ar -crs $(OUT) $(OBJ)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "options_menu.hpp"
|
||||||
|
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
constexpr SDL_Color WHITE = {255, 255, 255, 255};
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Public access members
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
OptionsMenu::OptionsMenu() {
|
||||||
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
|
||||||
|
//setup the utility objects
|
||||||
|
buttonImage.Load(GetRenderer(), config["dir.interface"] + "button_blue.png");
|
||||||
|
font = TTF_OpenFont(config["client.font"].c_str(), 12);
|
||||||
|
|
||||||
|
//check that the font loaded
|
||||||
|
if (!font) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to load a font file; " << SDL_GetError();
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//setup the button
|
||||||
|
backButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
||||||
|
backButton.SetText(GetRenderer(), font, WHITE, "Back");
|
||||||
|
|
||||||
|
//set the button positions
|
||||||
|
backButton.SetX(50);
|
||||||
|
backButton.SetY(50);
|
||||||
|
|
||||||
|
//text line
|
||||||
|
textLine.SetX(50);
|
||||||
|
textLine.SetY(30);
|
||||||
|
textLine.SetText(GetRenderer(), font, WHITE, "Am I making any progress?");
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionsMenu::~OptionsMenu() {
|
||||||
|
TTF_CloseFont(font);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Frame loop
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void OptionsMenu::FrameStart() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsMenu::Update() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsMenu::FrameEnd() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsMenu::RenderFrame(SDL_Renderer* renderer) {
|
||||||
|
backButton.DrawTo(renderer);
|
||||||
|
textLine.DrawTo(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Event handlers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void OptionsMenu::MouseMotion(SDL_MouseMotionEvent const& event) {
|
||||||
|
backButton.MouseMotion(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsMenu::MouseButtonDown(SDL_MouseButtonEvent const& event) {
|
||||||
|
backButton.MouseButtonDown(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsMenu::MouseButtonUp(SDL_MouseButtonEvent const& event) {
|
||||||
|
if (backButton.MouseButtonUp(event) == Button::State::RELEASED) {
|
||||||
|
SetSceneSignal(SceneSignal::MAINMENU);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsMenu::MouseWheel(SDL_MouseWheelEvent const& event) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsMenu::KeyDown(SDL_KeyboardEvent const& event) {
|
||||||
|
switch(event.keysym.sym) {
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
SetSceneSignal(SceneSignal::MAINMENU);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsMenu::KeyUp(SDL_KeyboardEvent const& event) {
|
||||||
|
//
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "button.hpp"
|
||||||
|
#include "image.hpp"
|
||||||
|
#include "text_line.hpp"
|
||||||
|
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
|
//NOTE: The options screen needs to be USED
|
||||||
|
class OptionsMenu : public BaseScene {
|
||||||
|
public:
|
||||||
|
//Public access members
|
||||||
|
OptionsMenu();
|
||||||
|
~OptionsMenu();
|
||||||
|
|
||||||
|
void RenderFrame(SDL_Renderer* renderer) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
//frame phases
|
||||||
|
void FrameStart() override;
|
||||||
|
void Update() override;
|
||||||
|
void FrameEnd() override;
|
||||||
|
|
||||||
|
//input events
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const& event) override;
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseWheel(SDL_MouseWheelEvent const& event) override;
|
||||||
|
void KeyDown(SDL_KeyboardEvent const& event) override;
|
||||||
|
void KeyUp(SDL_KeyboardEvent const& event) override;
|
||||||
|
|
||||||
|
//members
|
||||||
|
Image buttonImage;
|
||||||
|
TTF_Font* font = nullptr;
|
||||||
|
Button backButton;
|
||||||
|
TextLine textLine;
|
||||||
|
};
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "splash_screen.hpp"
|
||||||
|
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Public access members
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
SplashScreen::SplashScreen(SDL_Window* w) {
|
||||||
|
//fit the screen to the logo
|
||||||
|
//NOTE: not using this window trick
|
||||||
|
window = w;
|
||||||
|
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
|
||||||
|
|
||||||
|
logo.Load(GetRenderer(), ConfigUtility::GetSingleton()["dir.logos"] + "krstudios.png");
|
||||||
|
|
||||||
|
startTick = std::chrono::steady_clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
SplashScreen::~SplashScreen() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Frame loop
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void SplashScreen::FrameStart() {
|
||||||
|
//TODO: (0) config flag to change the delay
|
||||||
|
if (std::chrono::steady_clock::now() - startTick > std::chrono::duration<int>(3)) {
|
||||||
|
SetSceneSignal(SceneSignal::MAINMENU);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreen::RenderFrame(SDL_Renderer* renderer) {
|
||||||
|
//TODO: version information
|
||||||
|
int w = 0, h = 0;
|
||||||
|
SDL_RenderGetLogicalSize(renderer, &w, &h);
|
||||||
|
logo.DrawTo(renderer, (w - logo.GetClipW()) / 2, (h - logo.GetClipH()) / 2);
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
#include "image.hpp"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
class SplashScreen : public BaseScene {
|
||||||
|
public:
|
||||||
|
//Public access members
|
||||||
|
SplashScreen(SDL_Window*);
|
||||||
|
~SplashScreen();
|
||||||
|
|
||||||
|
void RenderFrame(SDL_Renderer* renderer) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
//Frame loop
|
||||||
|
void FrameStart() override;
|
||||||
|
|
||||||
|
//members
|
||||||
|
std::chrono::steady_clock::time_point startTick;
|
||||||
|
Image logo;
|
||||||
|
|
||||||
|
//screws with the window
|
||||||
|
SDL_Window* window = nullptr;
|
||||||
|
int windowWidth, windowHeight;
|
||||||
|
};
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,171 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//maps
|
||||||
|
#include "region_pager_base.hpp"
|
||||||
|
|
||||||
|
//utilities
|
||||||
|
#include "udp_network_utility.hpp"
|
||||||
|
#include "serial_packet.hpp"
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
|
//graphics
|
||||||
|
#include "image.hpp"
|
||||||
|
#include "button.hpp"
|
||||||
|
#include "tile_sheet.hpp"
|
||||||
|
#include "text_line.hpp"
|
||||||
|
|
||||||
|
//common
|
||||||
|
#include "frame_rate.hpp"
|
||||||
|
|
||||||
|
//client
|
||||||
|
#include "barrier_manager.hpp"
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
#include "base_barrier.hpp"
|
||||||
|
#include "base_creature.hpp"
|
||||||
|
#include "heartbeat_utility.hpp"
|
||||||
|
#include "local_character.hpp"
|
||||||
|
|
||||||
|
#include "SDL2/SDL.h"
|
||||||
|
#include "SDL2/SDL_net.h"
|
||||||
|
#include "SDL2/SDL_ttf.h"
|
||||||
|
|
||||||
|
//STL
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
class World: public BaseScene {
|
||||||
|
public:
|
||||||
|
//Public access members
|
||||||
|
World(int* const argClientIndex, int* const argAccountIndex);
|
||||||
|
~World();
|
||||||
|
|
||||||
|
void RenderFrame(SDL_Renderer* renderer) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
//frame phases
|
||||||
|
void FrameStart() override;
|
||||||
|
void Update() override;
|
||||||
|
void FrameEnd() override;
|
||||||
|
|
||||||
|
//input events
|
||||||
|
void QuitEvent();
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const& event) override;
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseWheel(SDL_MouseWheelEvent const& event) override;
|
||||||
|
void KeyDown(SDL_KeyboardEvent const& event) override;
|
||||||
|
void KeyUp(SDL_KeyboardEvent const& event) override;
|
||||||
|
|
||||||
|
//handle incoming traffic
|
||||||
|
void HandlePacket(SerialPacket* const);
|
||||||
|
|
||||||
|
//basic connections
|
||||||
|
void SendLogoutRequest();
|
||||||
|
void SendDisconnectRequest();
|
||||||
|
void SendAdminDisconnectForced();
|
||||||
|
void SendAdminShutdownRequest();
|
||||||
|
|
||||||
|
void hLogoutResponse(ClientPacket* const);
|
||||||
|
void hDisconnectResponse(ClientPacket* const);
|
||||||
|
void hAdminDisconnectForced(ClientPacket* const);
|
||||||
|
|
||||||
|
//map management
|
||||||
|
void SendRegionRequest(int roomIndex, int x, int y);
|
||||||
|
void hRegionContent(RegionPacket* const);
|
||||||
|
void UpdateMap();
|
||||||
|
|
||||||
|
//character management
|
||||||
|
void hCharacterUpdate(CharacterPacket* const);
|
||||||
|
void hCharacterCreate(CharacterPacket* const);
|
||||||
|
void hCharacterUnload(CharacterPacket* const);
|
||||||
|
void hQueryCharacterExists(CharacterPacket* const);
|
||||||
|
void hCharacterMovement(CharacterPacket* const);
|
||||||
|
void hCharacterRejection(TextPacket* const);
|
||||||
|
|
||||||
|
//creature management
|
||||||
|
void hCreatureUpdate(CreaturePacket* const);
|
||||||
|
void hCreatureCreate(CreaturePacket* const);
|
||||||
|
void hCreatureUnload(CreaturePacket* const);
|
||||||
|
void hQueryCreatureExists(CreaturePacket* const);
|
||||||
|
void hCreatureMovement(CreaturePacket* const);
|
||||||
|
|
||||||
|
//barrier management
|
||||||
|
void hBarrierUpdate(BarrierPacket* const);
|
||||||
|
void hBarrierCreate(BarrierPacket* const);
|
||||||
|
void hBarrierUnload(BarrierPacket* const);
|
||||||
|
void hQueryBarrierExists(BarrierPacket* const);
|
||||||
|
|
||||||
|
//chat
|
||||||
|
//TODO: ui chat engine
|
||||||
|
void hTextBroadcast(TextPacket* const);
|
||||||
|
void hTextSpeech(TextPacket* const);
|
||||||
|
void hTextWhisper(TextPacket* const);
|
||||||
|
|
||||||
|
//general gameplay
|
||||||
|
void SendLocalCharacterMovement();
|
||||||
|
std::list<BoundingBox> GenerateCollisionGrid(Entity*, int tileWidth, int tileHeight);
|
||||||
|
|
||||||
|
//indexes
|
||||||
|
int& clientIndex;
|
||||||
|
int& accountIndex;
|
||||||
|
int characterIndex = -1;
|
||||||
|
int roomIndex = -1;
|
||||||
|
|
||||||
|
//graphics
|
||||||
|
TileSheet tileSheet;
|
||||||
|
|
||||||
|
//map
|
||||||
|
RegionPagerBase regionPager;
|
||||||
|
|
||||||
|
//UI
|
||||||
|
Image buttonImage;
|
||||||
|
TTF_Font* font = nullptr;
|
||||||
|
Button disconnectButton;
|
||||||
|
Button shutdownButton;
|
||||||
|
FrameRate fps;
|
||||||
|
TextLine fpsTextLine;
|
||||||
|
|
||||||
|
//the camera structure
|
||||||
|
struct {
|
||||||
|
int x = 0, y = 0;
|
||||||
|
int width = 0, height = 0;
|
||||||
|
int marginX = 0, marginY = 0;
|
||||||
|
} camera;
|
||||||
|
|
||||||
|
//entities
|
||||||
|
BarrierManager barrierMgr;
|
||||||
|
std::map<int, BaseCharacter> characterMap;
|
||||||
|
std::map<int, BaseCreature> creatureMap;
|
||||||
|
LocalCharacter* localCharacter = nullptr;
|
||||||
|
|
||||||
|
//heartbeat
|
||||||
|
HeartbeatUtility heartbeatUtility;
|
||||||
|
typedef std::chrono::steady_clock Clock;
|
||||||
|
Clock::time_point queryTime = Clock::now() - std::chrono::seconds(4); //back 4 seconds to trigger automatically
|
||||||
|
|
||||||
|
//ugly references; I hate this
|
||||||
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
|
||||||
|
};
|
||||||
@@ -0,0 +1,186 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "sprite_sheet.hpp"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
SpriteSheet& SpriteSheet::operator=(SpriteSheet const& rhs) {
|
||||||
|
//don't screw yourself
|
||||||
|
if (this == &rhs) {
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Free();
|
||||||
|
|
||||||
|
//Copy the other SpriteSheet's stuff
|
||||||
|
texture = rhs.texture;
|
||||||
|
clip = rhs.clip;
|
||||||
|
local = false;
|
||||||
|
countX = rhs.countX;
|
||||||
|
countY = rhs.countY;
|
||||||
|
indexX = rhs.indexX;
|
||||||
|
indexY = rhs.indexY;
|
||||||
|
delay = rhs.delay;
|
||||||
|
tick = rhs.tick;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpriteSheet& SpriteSheet::operator=(SpriteSheet&& rhs) {
|
||||||
|
//don't screw yourself
|
||||||
|
if (this == &rhs) {
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Free();
|
||||||
|
|
||||||
|
//Steal the other SpriteSheet's stuff
|
||||||
|
texture = rhs.texture;
|
||||||
|
clip = rhs.clip;
|
||||||
|
local = rhs.local;
|
||||||
|
countX = rhs.countX;
|
||||||
|
countY = rhs.countY;
|
||||||
|
indexX = rhs.indexX;
|
||||||
|
indexY = rhs.indexY;
|
||||||
|
delay = rhs.delay;
|
||||||
|
tick = rhs.tick;
|
||||||
|
|
||||||
|
rhs.texture = nullptr;
|
||||||
|
rhs.clip = {0, 0, 0, 0};
|
||||||
|
rhs.local = false;
|
||||||
|
rhs.countX = 0;
|
||||||
|
rhs.countY = 0;
|
||||||
|
rhs.indexX = 0;
|
||||||
|
rhs.indexY = 0;
|
||||||
|
rhs.delay = 0.0;
|
||||||
|
rhs.tick = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpriteSheet::Update(double delta) {
|
||||||
|
//if the delay has passed
|
||||||
|
if (delay && (tick += delta) >= delay) {
|
||||||
|
//if the index is out of bounds
|
||||||
|
if (++indexX >= countX) {
|
||||||
|
indexX = 0;
|
||||||
|
}
|
||||||
|
tick = 0;
|
||||||
|
}
|
||||||
|
//modify area drawn
|
||||||
|
clip.x = indexX * clip.w;
|
||||||
|
clip.y = indexY * clip.h;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Texture* SpriteSheet::Load(SDL_Renderer* r, std::string fname, Uint16 cx, Uint16 cy) {
|
||||||
|
//call the base function
|
||||||
|
Image::Load(r, fname);
|
||||||
|
|
||||||
|
//set the metadata
|
||||||
|
countX = cx;
|
||||||
|
countY = cy;
|
||||||
|
|
||||||
|
//assume clip.x and clip.y were set to the size of the texture
|
||||||
|
//reduce the w & h to the size of one cell
|
||||||
|
clip.w = clip.w / countX;
|
||||||
|
clip.h = clip.h / countY;
|
||||||
|
|
||||||
|
indexX = indexY = 0;
|
||||||
|
delay = tick = 0.0;
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Texture* SpriteSheet::Create(SDL_Renderer* r, Uint16 w, Uint16 h, Uint16 cx, Uint16 cy) {
|
||||||
|
//call the base function
|
||||||
|
Image::Create(r, w, h);
|
||||||
|
|
||||||
|
//set the metadata
|
||||||
|
countX = cx;
|
||||||
|
countY = cy;
|
||||||
|
|
||||||
|
//assume clip.x and clip.y were set to the size of the texture
|
||||||
|
//reduce the w & h to the size of one cell
|
||||||
|
clip.w = clip.w / countX;
|
||||||
|
clip.h = clip.h / countY;
|
||||||
|
|
||||||
|
indexX = indexY = 0;
|
||||||
|
delay = tick = 0.0;
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Texture* SpriteSheet::SetTexture(SDL_Texture* ptr, Uint16 cx, Uint16 cy) {
|
||||||
|
//call the base function
|
||||||
|
Image::SetTexture(ptr);
|
||||||
|
|
||||||
|
//set the metadata
|
||||||
|
countX = cx;
|
||||||
|
countY = cy;
|
||||||
|
|
||||||
|
//assume clip.x and clip.y were set to the size of the texture
|
||||||
|
//reduce the w & h to the size of one cell
|
||||||
|
clip.w = clip.w / countX;
|
||||||
|
clip.h = clip.h / countY;
|
||||||
|
|
||||||
|
indexX = indexY = 0;
|
||||||
|
delay = tick = 0.0;
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpriteSheet::Free() {
|
||||||
|
Image::Free();
|
||||||
|
countX = countY = 0;
|
||||||
|
indexX = indexY = 0;
|
||||||
|
delay = tick = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint16 SpriteSheet::SetCountX(Uint16 i) {
|
||||||
|
indexX = 0;
|
||||||
|
return countX = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint16 SpriteSheet::SetCountY(Uint16 i) {
|
||||||
|
indexY = 0;
|
||||||
|
return countY = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint16 SpriteSheet::SetIndexX(Uint16 i) {
|
||||||
|
if (i > countX) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Cannot set index 'x' to " << i;
|
||||||
|
throw(std::out_of_range(msg.str()));
|
||||||
|
}
|
||||||
|
return indexX = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint16 SpriteSheet::SetIndexY(Uint16 i) {
|
||||||
|
if (i > countY) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Cannot set index 'y' to " << i;
|
||||||
|
throw(std::invalid_argument(msg.str()));
|
||||||
|
}
|
||||||
|
return indexY = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SpriteSheet::SetDelay(double d) {
|
||||||
|
tick = 0;
|
||||||
|
return delay = d;
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "image.hpp"
|
||||||
|
|
||||||
|
class SpriteSheet : public Image {
|
||||||
|
public:
|
||||||
|
SpriteSheet() = default;
|
||||||
|
SpriteSheet(SpriteSheet const& rhs) { *this = rhs; }
|
||||||
|
SpriteSheet(SpriteSheet&& rhs) { *this = std::move(rhs); }
|
||||||
|
SpriteSheet(SDL_Renderer* r, std::string fname, Uint16 cx, Uint16 cy)
|
||||||
|
{ Load(r, fname, cx, cy); }
|
||||||
|
SpriteSheet(SDL_Renderer* r, Uint16 w, Uint16 h, Uint16 cx, Uint16 cy)
|
||||||
|
{ Create(r, w, h, cx, cy); }
|
||||||
|
SpriteSheet(SDL_Texture* p, Uint16 cx, Uint16 cy)
|
||||||
|
{ SetTexture(p, cx, cy); }
|
||||||
|
~SpriteSheet() = default;
|
||||||
|
|
||||||
|
SpriteSheet& operator=(SpriteSheet const&);
|
||||||
|
SpriteSheet& operator=(SpriteSheet&&);
|
||||||
|
|
||||||
|
void Update(double delta);
|
||||||
|
|
||||||
|
SDL_Texture* Load(SDL_Renderer*, std::string fname, Uint16 cx, Uint16 cy);
|
||||||
|
SDL_Texture* Create(SDL_Renderer*, Uint16 w, Uint16 h, Uint16 cx, Uint16 cy);
|
||||||
|
SDL_Texture* SetTexture(SDL_Texture*, Uint16 cx, Uint16 cy);
|
||||||
|
void Free() override;
|
||||||
|
|
||||||
|
Uint16 SetCountX(Uint16);
|
||||||
|
Uint16 SetCountY(Uint16);
|
||||||
|
Uint16 SetIndexX(Uint16);
|
||||||
|
Uint16 SetIndexY(Uint16);
|
||||||
|
|
||||||
|
Uint16 GetCountX() const { return countX; }
|
||||||
|
Uint16 GetCountY() const { return countY; }
|
||||||
|
Uint16 GetIndexX() const { return indexX; }
|
||||||
|
Uint16 GetIndexY() const { return indexY; }
|
||||||
|
|
||||||
|
double SetDelay(double d);
|
||||||
|
double GetDelay() const { return delay; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Uint16 countX = 0, countY = 0, indexX = 0, indexY = 0;
|
||||||
|
double delay = 0.0, tick = 0.0;
|
||||||
|
|
||||||
|
//disable access
|
||||||
|
using Image::Load;
|
||||||
|
using Image::Create;
|
||||||
|
using Image::SetTexture;
|
||||||
|
};
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
class FrameRate {
|
||||||
|
public:
|
||||||
|
typedef std::chrono::high_resolution_clock Clock;
|
||||||
|
|
||||||
|
FrameRate() = default;
|
||||||
|
|
||||||
|
//DOCS: for usage purposes, this returns -1 unless a new framerate value is set
|
||||||
|
int Calculate() {
|
||||||
|
frameCount++;
|
||||||
|
if (Clock::now() - tick >= std::chrono::duration<int>(1)) {
|
||||||
|
lastFrameRate = frameCount;
|
||||||
|
frameCount = 0;
|
||||||
|
tick = Clock::now();
|
||||||
|
return lastFrameRate;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetFrameRate() { return lastFrameRate; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int frameCount = 0;
|
||||||
|
int lastFrameRate = 0;
|
||||||
|
Clock::time_point tick = Clock::now();
|
||||||
|
};
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#config
|
||||||
|
INCLUDES+=.
|
||||||
|
LIBS+=
|
||||||
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
ar -crs $(OUT) $(OBJ)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "timer.hpp"
|
||||||
|
|
||||||
|
Timer::Timer(): start(Timer::Clock::now()) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer::Timer(std::string s): name(s), start(Timer::Clock::now()) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Timer::Start() {
|
||||||
|
start = Clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Timer::Stop() {
|
||||||
|
timeSpan = Clock::now() - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, Timer& t) {
|
||||||
|
os << t.GetName() << ": ";
|
||||||
|
os << std::chrono::duration_cast<std::chrono::microseconds>(t.GetTime()).count();
|
||||||
|
os << "us";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <string>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
class Timer {
|
||||||
|
public:
|
||||||
|
typedef std::chrono::high_resolution_clock Clock;
|
||||||
|
|
||||||
|
Timer();
|
||||||
|
Timer(std::string s);
|
||||||
|
~Timer() = default;
|
||||||
|
|
||||||
|
void Start();
|
||||||
|
void Stop();
|
||||||
|
|
||||||
|
//accessors and mutators
|
||||||
|
Clock::duration GetTime() { return timeSpan; }
|
||||||
|
|
||||||
|
std::string SetName(std::string s) { return name = s; }
|
||||||
|
std::string GetName() { return name; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string name;
|
||||||
|
Clock::time_point start;
|
||||||
|
Clock::duration timeSpan;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, Timer& t);
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//the bounds for the objects, mapped to the default sprites
|
||||||
|
constexpr int BARRIER_BOUNDS_X = 0;
|
||||||
|
constexpr int BARRIER_BOUNDS_Y = 0;
|
||||||
|
constexpr int BARRIER_BOUNDS_WIDTH = 96;
|
||||||
|
constexpr int BARRIER_BOUNDS_HEIGHT = 96;
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
//the speeds that the characters move
|
||||||
|
constexpr double CHARACTER_WALKING_SPEED = 2.24;
|
||||||
|
constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0);
|
||||||
|
constexpr double CHARACTER_WALKING_NEGATIVE_MOD = 1.0 - CHARACTER_WALKING_MOD;
|
||||||
|
|
||||||
|
//the bounds for the character objects, mapped to the default sprites
|
||||||
|
constexpr int CHARACTER_BOUNDS_X = 0;
|
||||||
|
constexpr int CHARACTER_BOUNDS_Y = 16;
|
||||||
|
constexpr int CHARACTER_BOUNDS_WIDTH = 32;
|
||||||
|
constexpr int CHARACTER_BOUNDS_HEIGHT = 32;
|
||||||
|
|
||||||
|
//the character's sprite format
|
||||||
|
constexpr int CHARACTER_CELLS_X = 4;
|
||||||
|
constexpr int CHARACTER_CELLS_Y = 4;
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
//the speeds that the characters move
|
||||||
|
constexpr double CREATURE_WALKING_SPEED = 1.0;
|
||||||
|
constexpr double CREATURE_WALKING_MOD = 1.0/sqrt(2.0);
|
||||||
|
constexpr double CREATURE_WALKING_NEGATIVE_MOD = 1.0 - CREATURE_WALKING_MOD;
|
||||||
|
|
||||||
|
//the bounds for the character objects, mapped to the default sprites
|
||||||
|
constexpr int CREATURE_BOUNDS_X = 0;
|
||||||
|
constexpr int CREATURE_BOUNDS_Y = 0;
|
||||||
|
constexpr int CREATURE_BOUNDS_WIDTH = 32;
|
||||||
|
constexpr int CREATURE_BOUNDS_HEIGHT = 32;
|
||||||
|
|
||||||
|
//the character's sprite format
|
||||||
|
constexpr int CREATURE_CELLS_X = 4;
|
||||||
|
constexpr int CREATURE_CELLS_Y = 4;
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
constexpr int INFLUENCE_RADIUS = 1000;
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
enum ItemType {
|
||||||
|
//basics
|
||||||
|
POTION = 101,
|
||||||
|
|
||||||
|
//weapons
|
||||||
|
SWORD = 201,
|
||||||
|
DAGGER = 202,
|
||||||
|
STAFF = 203
|
||||||
|
};
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#config
|
||||||
|
INCLUDES+=.
|
||||||
|
LIBS+=
|
||||||
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
ar -crs $(OUT) $(OBJ)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#output
|
||||||
|
export OUTDIR=../..
|
||||||
|
export OUT=$(addprefix $(OUTDIR)/,libcommon.a)
|
||||||
|
|
||||||
|
all: $(OUTDIR)
|
||||||
|
$(MAKE) -C debugging
|
||||||
|
$(MAKE) -C global_defines
|
||||||
|
$(MAKE) -C network
|
||||||
|
$(MAKE) -C utilities
|
||||||
|
|
||||||
|
debug: export CXXFLAGS+=-g
|
||||||
|
debug: clean all
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
|
$(RM) *.o *.a *.exe
|
||||||
|
else ifeq ($(shell uname), Linux)
|
||||||
|
find . -type f -name *.o -exec rm -f -r -v {} \;
|
||||||
|
find . -type f -name *.a -exec rm -f -r -v {} \;
|
||||||
|
rm -f -v out/client out/server
|
||||||
|
endif
|
||||||
|
|
||||||
|
rebuild: clean all
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#config
|
||||||
|
INCLUDES+=. packet_types ../global_defines ../utilities ../../TurtleGUI ../../TurtleMap
|
||||||
|
LIBS+=
|
||||||
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
ar -crs $(OUT) $(OBJ)
|
||||||
|
$(MAKE) -C packet_types
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "barrier_packet.hpp"
|
||||||
|
|
||||||
|
#include "serial_utility.hpp"
|
||||||
|
|
||||||
|
void serializeBarrier(void* buffer, BarrierPacket* packet) {
|
||||||
|
serialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
//identify the barrier
|
||||||
|
serialCopy(&buffer, &packet->barrierIndex, sizeof(int));
|
||||||
|
|
||||||
|
//bounds
|
||||||
|
serialCopy(&buffer, &packet->bounds.x, sizeof(int));
|
||||||
|
serialCopy(&buffer, &packet->bounds.y, sizeof(int));
|
||||||
|
serialCopy(&buffer, &packet->bounds.w, sizeof(int));
|
||||||
|
serialCopy(&buffer, &packet->bounds.h, sizeof(int));
|
||||||
|
|
||||||
|
|
||||||
|
//location
|
||||||
|
serialCopy(&buffer, &packet->roomIndex, sizeof(int));
|
||||||
|
serialCopy(&buffer, &packet->origin.x, sizeof(double));
|
||||||
|
serialCopy(&buffer, &packet->origin.y, sizeof(double));
|
||||||
|
serialCopy(&buffer, &packet->motion.x, sizeof(double));
|
||||||
|
serialCopy(&buffer, &packet->motion.y, sizeof(double));
|
||||||
|
|
||||||
|
//graphical data
|
||||||
|
serialCopy(&buffer, packet->status, sizeof(int) * 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
void deserializeBarrier(void* buffer, BarrierPacket* packet) {
|
||||||
|
deserialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
//identify the barrier
|
||||||
|
deserialCopy(&buffer, &packet->barrierIndex, sizeof(int));
|
||||||
|
|
||||||
|
//bounds
|
||||||
|
deserialCopy(&buffer, &packet->bounds.x, sizeof(int));
|
||||||
|
deserialCopy(&buffer, &packet->bounds.y, sizeof(int));
|
||||||
|
deserialCopy(&buffer, &packet->bounds.w, sizeof(int));
|
||||||
|
deserialCopy(&buffer, &packet->bounds.h, sizeof(int));
|
||||||
|
|
||||||
|
|
||||||
|
//location
|
||||||
|
deserialCopy(&buffer, &packet->roomIndex, sizeof(int));
|
||||||
|
deserialCopy(&buffer, &packet->origin.x, sizeof(double));
|
||||||
|
deserialCopy(&buffer, &packet->origin.y, sizeof(double));
|
||||||
|
deserialCopy(&buffer, &packet->motion.x, sizeof(double));
|
||||||
|
deserialCopy(&buffer, &packet->motion.y, sizeof(double));
|
||||||
|
|
||||||
|
//graphical data
|
||||||
|
deserialCopy(&buffer, packet->status, sizeof(int) * 8);
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "serial_packet_base.hpp"
|
||||||
|
|
||||||
|
#include "bounding_box.hpp"
|
||||||
|
#include "vector2.hpp"
|
||||||
|
|
||||||
|
struct BarrierPacket : SerialPacketBase {
|
||||||
|
//identify the barrier
|
||||||
|
int barrierIndex;
|
||||||
|
BoundingBox bounds;
|
||||||
|
|
||||||
|
//location
|
||||||
|
int roomIndex;
|
||||||
|
Vector2 origin;
|
||||||
|
Vector2 motion;
|
||||||
|
|
||||||
|
//graphical data: 0 blank, 1 green, 2 red
|
||||||
|
int status[8];
|
||||||
|
};
|
||||||
|
|
||||||
|
void serializeBarrier(void* buffer, BarrierPacket* packet);
|
||||||
|
void deserializeBarrier(void* buffer, BarrierPacket* packet);
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "character_packet.hpp"
|
||||||
|
|
||||||
|
#include "serial_utility.hpp"
|
||||||
|
|
||||||
|
void serializeCharacter(void* buffer, CharacterPacket* packet) {
|
||||||
|
serialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
//identify the character
|
||||||
|
serialCopy(&buffer, &packet->characterIndex, sizeof(int));
|
||||||
|
serialCopy(&buffer, packet->handle, PACKET_STRING_SIZE);
|
||||||
|
serialCopy(&buffer, packet->avatar, PACKET_STRING_SIZE);
|
||||||
|
|
||||||
|
//the owner
|
||||||
|
serialCopy(&buffer, &packet->accountIndex, sizeof(int));
|
||||||
|
|
||||||
|
//location
|
||||||
|
serialCopy(&buffer, &packet->roomIndex, sizeof(int));
|
||||||
|
|
||||||
|
serialCopy(&buffer, &packet->origin.x, sizeof(double));
|
||||||
|
serialCopy(&buffer, &packet->origin.y, sizeof(double));
|
||||||
|
|
||||||
|
serialCopy(&buffer, &packet->motion.x, sizeof(double));
|
||||||
|
serialCopy(&buffer, &packet->motion.y, sizeof(double));
|
||||||
|
|
||||||
|
serialCopy(&buffer, &packet->bounds.x, sizeof(int));
|
||||||
|
serialCopy(&buffer, &packet->bounds.y, sizeof(int));
|
||||||
|
serialCopy(&buffer, &packet->bounds.w, sizeof(int));
|
||||||
|
serialCopy(&buffer, &packet->bounds.h, sizeof(int));
|
||||||
|
|
||||||
|
//gameplay components: equipment, items, buffs, debuffs...
|
||||||
|
}
|
||||||
|
|
||||||
|
void deserializeCharacter(void* buffer, CharacterPacket* packet) {
|
||||||
|
deserialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
//identify the character
|
||||||
|
deserialCopy(&buffer, &packet->characterIndex, sizeof(int));
|
||||||
|
deserialCopy(&buffer, packet->handle, PACKET_STRING_SIZE);
|
||||||
|
deserialCopy(&buffer, packet->avatar, PACKET_STRING_SIZE);
|
||||||
|
|
||||||
|
//the owner
|
||||||
|
deserialCopy(&buffer, &packet->accountIndex, sizeof(int));
|
||||||
|
|
||||||
|
//location
|
||||||
|
deserialCopy(&buffer, &packet->roomIndex, sizeof(int));
|
||||||
|
|
||||||
|
deserialCopy(&buffer, &packet->origin.x, sizeof(double));
|
||||||
|
deserialCopy(&buffer, &packet->origin.y, sizeof(double));
|
||||||
|
|
||||||
|
deserialCopy(&buffer, &packet->motion.x, sizeof(double));
|
||||||
|
deserialCopy(&buffer, &packet->motion.y, sizeof(double));
|
||||||
|
|
||||||
|
deserialCopy(&buffer, &packet->bounds.x, sizeof(int));
|
||||||
|
deserialCopy(&buffer, &packet->bounds.y, sizeof(int));
|
||||||
|
deserialCopy(&buffer, &packet->bounds.w, sizeof(int));
|
||||||
|
deserialCopy(&buffer, &packet->bounds.h, sizeof(int));
|
||||||
|
|
||||||
|
//gameplay components: equipment, items, buffs, debuffs...
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "serial_packet_base.hpp"
|
||||||
|
|
||||||
|
#include "bounding_box.hpp"
|
||||||
|
#include "vector2.hpp"
|
||||||
|
|
||||||
|
struct CharacterPacket : SerialPacketBase {
|
||||||
|
//identify the character
|
||||||
|
int characterIndex;
|
||||||
|
char handle[PACKET_STRING_SIZE];
|
||||||
|
char avatar[PACKET_STRING_SIZE];
|
||||||
|
|
||||||
|
//the owner
|
||||||
|
int accountIndex;
|
||||||
|
|
||||||
|
//location
|
||||||
|
int roomIndex;
|
||||||
|
Vector2 origin;
|
||||||
|
Vector2 motion;
|
||||||
|
BoundingBox bounds;
|
||||||
|
};
|
||||||
|
|
||||||
|
void serializeCharacter(void* buffer, CharacterPacket* packet);
|
||||||
|
void deserializeCharacter(void* buffer, CharacterPacket* packet);
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "client_packet.hpp"
|
||||||
|
|
||||||
|
#include "serial_utility.hpp"
|
||||||
|
|
||||||
|
void serializeClient(void* buffer, ClientPacket* packet) {
|
||||||
|
serialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
serialCopy(&buffer, &packet->clientIndex, sizeof(int));
|
||||||
|
serialCopy(&buffer, &packet->accountIndex, sizeof(int));
|
||||||
|
serialCopy(&buffer, packet->username, PACKET_STRING_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void deserializeClient(void* buffer, ClientPacket* packet) {
|
||||||
|
deserialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
deserialCopy(&buffer, &packet->clientIndex, sizeof(int));
|
||||||
|
deserialCopy(&buffer, &packet->accountIndex, sizeof(int));
|
||||||
|
deserialCopy(&buffer, packet->username, PACKET_STRING_SIZE);
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "serial_packet_base.hpp"
|
||||||
|
|
||||||
|
struct ClientPacket : SerialPacketBase {
|
||||||
|
int clientIndex;
|
||||||
|
int accountIndex;
|
||||||
|
char username[PACKET_STRING_SIZE];
|
||||||
|
//TODO: (3) password, auth token
|
||||||
|
};
|
||||||
|
|
||||||
|
void serializeClient(void* buffer, ClientPacket* packet);
|
||||||
|
void deserializeClient(void* buffer, ClientPacket* packet);
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "creature_packet.hpp"
|
||||||
|
|
||||||
|
#include "serial_utility.hpp"
|
||||||
|
|
||||||
|
void serializeCreature(void* buffer, CreaturePacket* packet) {
|
||||||
|
serialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
//identify the creature
|
||||||
|
serialCopy(&buffer, &packet->creatureIndex, sizeof(int));
|
||||||
|
serialCopy(&buffer, packet->handle, PACKET_STRING_SIZE);
|
||||||
|
serialCopy(&buffer, packet->avatar, PACKET_STRING_SIZE);
|
||||||
|
|
||||||
|
//bounds
|
||||||
|
serialCopy(&buffer, &packet->bounds.x, sizeof(int));
|
||||||
|
serialCopy(&buffer, &packet->bounds.y, sizeof(int));
|
||||||
|
serialCopy(&buffer, &packet->bounds.w, sizeof(int));
|
||||||
|
serialCopy(&buffer, &packet->bounds.h, sizeof(int));
|
||||||
|
|
||||||
|
|
||||||
|
//location
|
||||||
|
serialCopy(&buffer, &packet->roomIndex, sizeof(int));
|
||||||
|
serialCopy(&buffer, &packet->origin.x, sizeof(double));
|
||||||
|
serialCopy(&buffer, &packet->origin.y, sizeof(double));
|
||||||
|
serialCopy(&buffer, &packet->motion.x, sizeof(double));
|
||||||
|
serialCopy(&buffer, &packet->motion.y, sizeof(double));
|
||||||
|
}
|
||||||
|
|
||||||
|
void deserializeCreature(void* buffer, CreaturePacket* packet) {
|
||||||
|
deserialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
//identify the creature
|
||||||
|
deserialCopy(&buffer, &packet->creatureIndex, sizeof(int));
|
||||||
|
deserialCopy(&buffer, packet->handle, PACKET_STRING_SIZE);
|
||||||
|
deserialCopy(&buffer, packet->avatar, PACKET_STRING_SIZE);
|
||||||
|
|
||||||
|
//bounds
|
||||||
|
deserialCopy(&buffer, &packet->bounds.x, sizeof(int));
|
||||||
|
deserialCopy(&buffer, &packet->bounds.y, sizeof(int));
|
||||||
|
deserialCopy(&buffer, &packet->bounds.w, sizeof(int));
|
||||||
|
deserialCopy(&buffer, &packet->bounds.h, sizeof(int));
|
||||||
|
|
||||||
|
|
||||||
|
//location
|
||||||
|
deserialCopy(&buffer, &packet->roomIndex, sizeof(int));
|
||||||
|
deserialCopy(&buffer, &packet->origin.x, sizeof(double));
|
||||||
|
deserialCopy(&buffer, &packet->origin.y, sizeof(double));
|
||||||
|
deserialCopy(&buffer, &packet->motion.x, sizeof(double));
|
||||||
|
deserialCopy(&buffer, &packet->motion.y, sizeof(double));
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "serial_packet_base.hpp"
|
||||||
|
|
||||||
|
#include "bounding_box.hpp"
|
||||||
|
#include "vector2.hpp"
|
||||||
|
|
||||||
|
struct CreaturePacket : SerialPacketBase {
|
||||||
|
//identify the creature
|
||||||
|
int creatureIndex;
|
||||||
|
char handle[PACKET_STRING_SIZE];
|
||||||
|
char avatar[PACKET_STRING_SIZE];
|
||||||
|
BoundingBox bounds;
|
||||||
|
|
||||||
|
//location
|
||||||
|
int roomIndex;
|
||||||
|
Vector2 origin;
|
||||||
|
Vector2 motion;
|
||||||
|
};
|
||||||
|
|
||||||
|
void serializeCreature(void* buffer, CreaturePacket* packet);
|
||||||
|
void deserializeCreature(void* buffer, CreaturePacket* packet);
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#config
|
||||||
|
INCLUDES+=. .. ../../global_defines ../../utilities ../../../TurtleGUI ../../../TurtleMap
|
||||||
|
LIBS+=
|
||||||
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
ar -crs ../$(OUT) $(OBJ)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "region_packet.hpp"
|
||||||
|
|
||||||
|
#include "serial_utility.hpp"
|
||||||
|
|
||||||
|
void serializeRegion(void* buffer, RegionPacket* packet) {
|
||||||
|
serialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
//format
|
||||||
|
serialCopy(&buffer, &packet->roomIndex, sizeof(int));
|
||||||
|
serialCopy(&buffer, &packet->x, sizeof(int));
|
||||||
|
serialCopy(&buffer, &packet->y, sizeof(int));
|
||||||
|
|
||||||
|
if (packet->type != SerialPacketType::REGION_CONTENT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//tiles
|
||||||
|
for (int i = 0; i < REGION_WIDTH; i++) {
|
||||||
|
for (int j = 0; j < REGION_HEIGHT; j++) {
|
||||||
|
for (int k = 0; k < REGION_DEPTH; k++) {
|
||||||
|
*reinterpret_cast<Region::type_t*>(buffer) = packet->region->GetTile(i, j, k);
|
||||||
|
buffer = reinterpret_cast<char*>(buffer) + sizeof(Region::type_t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//solids
|
||||||
|
serialCopy(&buffer, packet->region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void deserializeRegion(void* buffer, RegionPacket* packet) {
|
||||||
|
deserialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
//format
|
||||||
|
deserialCopy(&buffer, &packet->roomIndex, sizeof(int));
|
||||||
|
deserialCopy(&buffer, &packet->x, sizeof(int));
|
||||||
|
deserialCopy(&buffer, &packet->y, sizeof(int));
|
||||||
|
|
||||||
|
if (packet->type != SerialPacketType::REGION_CONTENT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//an object to work on
|
||||||
|
packet->region = new Region(packet->x, packet->y);
|
||||||
|
|
||||||
|
//tiles
|
||||||
|
for (int i = 0; i < REGION_WIDTH; i++) {
|
||||||
|
for (int j = 0; j < REGION_HEIGHT; j++) {
|
||||||
|
for (int k = 0; k < REGION_DEPTH; k++) {
|
||||||
|
packet->region->SetTile(i, j, k, *reinterpret_cast<Region::type_t*>(buffer));
|
||||||
|
buffer = reinterpret_cast<char*>(buffer) + sizeof(Region::type_t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//solids
|
||||||
|
deserialCopy(&buffer, packet->region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "serial_packet_base.hpp"
|
||||||
|
|
||||||
|
#include "region.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
//define the memory footprint for the region's members
|
||||||
|
constexpr int REGION_TILE_FOOTPRINT = sizeof(Region::type_t) * REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH;
|
||||||
|
constexpr int REGION_SOLID_FOOTPRINT = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0);
|
||||||
|
constexpr int REGION_METADATA_FOOTPRINT = sizeof(int) * 3;
|
||||||
|
|
||||||
|
struct RegionPacket : SerialPacketBase {
|
||||||
|
//location/identify the region
|
||||||
|
int roomIndex;
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
//the data
|
||||||
|
Region* region;
|
||||||
|
};
|
||||||
|
|
||||||
|
void serializeRegion(void* buffer, RegionPacket* packet);
|
||||||
|
void deserializeRegion(void* buffer, RegionPacket* packet);
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "serial_packet_base.hpp"
|
||||||
|
|
||||||
|
//sanity check
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "serial_packet_type.hpp"
|
||||||
|
|
||||||
|
#include "SDL2/SDL_net.h"
|
||||||
|
|
||||||
|
constexpr int PACKET_STRING_SIZE = 100;
|
||||||
|
|
||||||
|
struct SerialPacketBase {
|
||||||
|
//members
|
||||||
|
SerialPacketType type;
|
||||||
|
IPaddress srcAddress;
|
||||||
|
|
||||||
|
virtual ~SerialPacketBase() {};
|
||||||
|
};
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "server_packet.hpp"
|
||||||
|
|
||||||
|
#include "serial_utility.hpp"
|
||||||
|
|
||||||
|
void serializeServer(void* buffer, ServerPacket* packet) {
|
||||||
|
serialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
//identify the server
|
||||||
|
serialCopy(&buffer, &packet->version, sizeof(int));
|
||||||
|
serialCopy(&buffer, packet->name, PACKET_STRING_SIZE);
|
||||||
|
serialCopy(&buffer, &packet->playerCount, sizeof(int));
|
||||||
|
}
|
||||||
|
|
||||||
|
void deserializeServer(void* buffer, ServerPacket* packet) {
|
||||||
|
deserialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
//identify the server
|
||||||
|
deserialCopy(&buffer, &packet->version, sizeof(int));
|
||||||
|
deserialCopy(&buffer, packet->name, PACKET_STRING_SIZE);
|
||||||
|
deserialCopy(&buffer, &packet->playerCount, sizeof(int));
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "serial_packet_base.hpp"
|
||||||
|
|
||||||
|
struct ServerPacket : SerialPacketBase {
|
||||||
|
//identify the server
|
||||||
|
char name[PACKET_STRING_SIZE];
|
||||||
|
int playerCount;
|
||||||
|
int version;
|
||||||
|
};
|
||||||
|
|
||||||
|
void serializeServer(void* buffer, ServerPacket* packet);
|
||||||
|
void deserializeServer(void* buffer, ServerPacket* packet);
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "text_packet.hpp"
|
||||||
|
|
||||||
|
#include "serial_utility.hpp"
|
||||||
|
|
||||||
|
void serializeText(void* buffer, TextPacket* packet) {
|
||||||
|
serialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
//content
|
||||||
|
serialCopy(&buffer, packet->name, PACKET_STRING_SIZE);
|
||||||
|
serialCopy(&buffer, packet->text, PACKET_STRING_SIZE);
|
||||||
|
|
||||||
|
//location
|
||||||
|
serialCopy(&buffer, &packet->roomIndex, sizeof(int));
|
||||||
|
serialCopy(&buffer, &packet->origin.x, sizeof(double));
|
||||||
|
serialCopy(&buffer, &packet->origin.y, sizeof(double));
|
||||||
|
serialCopy(&buffer, &packet->range, sizeof(int));
|
||||||
|
}
|
||||||
|
|
||||||
|
void deserializeText(void* buffer, TextPacket* packet) {
|
||||||
|
deserialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
//content
|
||||||
|
deserialCopy(&buffer, packet->name, PACKET_STRING_SIZE);
|
||||||
|
deserialCopy(&buffer, packet->text, PACKET_STRING_SIZE);
|
||||||
|
|
||||||
|
//location
|
||||||
|
deserialCopy(&buffer, &packet->roomIndex, sizeof(int));
|
||||||
|
deserialCopy(&buffer, &packet->origin.x, sizeof(double));
|
||||||
|
deserialCopy(&buffer, &packet->origin.y, sizeof(double));
|
||||||
|
deserialCopy(&buffer, &packet->range, sizeof(int));
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "serial_packet_base.hpp"
|
||||||
|
|
||||||
|
#include "vector2.hpp"
|
||||||
|
|
||||||
|
struct TextPacket : SerialPacketBase {
|
||||||
|
char name[PACKET_STRING_SIZE];
|
||||||
|
char text[PACKET_STRING_SIZE];
|
||||||
|
int roomIndex;
|
||||||
|
Vector2 origin;
|
||||||
|
int range;
|
||||||
|
};
|
||||||
|
|
||||||
|
void serializeText(void* buffer, TextPacket* packet);
|
||||||
|
void deserializeText(void* buffer, TextPacket* packet);
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "serial_packet_base.hpp"
|
||||||
|
#include "barrier_packet.hpp"
|
||||||
|
#include "character_packet.hpp"
|
||||||
|
#include "client_packet.hpp"
|
||||||
|
#include "creature_packet.hpp"
|
||||||
|
#include "region_packet.hpp"
|
||||||
|
#include "server_packet.hpp"
|
||||||
|
#include "text_packet.hpp"
|
||||||
|
|
||||||
|
//SerialPacketBase is defined in serial_packet_base.hpp
|
||||||
|
typedef SerialPacketBase SerialPacket;
|
||||||
|
|
||||||
|
//DOCS: NETWORK_VERSION is used to discern compatible servers and clients
|
||||||
|
constexpr int NETWORK_VERSION = 20161209;
|
||||||
|
|
||||||
|
union MaxPacket {
|
||||||
|
BarrierPacket a;
|
||||||
|
CharacterPacket b;
|
||||||
|
ClientPacket c;
|
||||||
|
CreaturePacket d;
|
||||||
|
RegionPacket e;
|
||||||
|
ServerPacket f;
|
||||||
|
TextPacket g;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket);
|
||||||
|
|
||||||
|
/* DOCS: PACKET_BUFFER_SIZE is the memory required to store serialized data
|
||||||
|
* DOCS: SerialPacketType::REGION_CONTENT is currently the largest packet type
|
||||||
|
* Serialized RegionPacket structure:
|
||||||
|
* SerialPacketType
|
||||||
|
* room index (int)
|
||||||
|
* X & Y position (int)
|
||||||
|
* tile data (3 layers)
|
||||||
|
* solid data (bitset)
|
||||||
|
*/
|
||||||
|
|
||||||
|
constexpr int PACKET_BUFFER_SIZE =
|
||||||
|
sizeof(SerialPacketType) +
|
||||||
|
REGION_METADATA_FOOTPRINT +
|
||||||
|
REGION_TILE_FOOTPRINT +
|
||||||
|
REGION_SOLID_FOOTPRINT;
|
||||||
@@ -0,0 +1,195 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
/* DOCS: The headers indicate what packet type is used for each message
|
||||||
|
* different messages under the same header will carry different amounts of
|
||||||
|
* valid data, but it will still be carried in that packet's format.
|
||||||
|
* FORMAT_* is for internal use, deviding the different format bounds.
|
||||||
|
*/
|
||||||
|
|
||||||
|
enum class SerialPacketType {
|
||||||
|
//default: there is something wrong
|
||||||
|
NONE = 0,
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//ServerPacket
|
||||||
|
// name, player count, version
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
FORMAT_SERVER = 100,
|
||||||
|
|
||||||
|
//heartbeat
|
||||||
|
PING = 101,
|
||||||
|
PONG = 102,
|
||||||
|
|
||||||
|
//Used for finding available servers
|
||||||
|
BROADCAST_REQUEST = 103,
|
||||||
|
BROADCAST_RESPONSE = 104,
|
||||||
|
|
||||||
|
FORMAT_END_SERVER = 199,
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//ClientPacket
|
||||||
|
// client index, account index, username
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
FORMAT_CLIENT = 200,
|
||||||
|
|
||||||
|
//Connecting to a server as a client
|
||||||
|
JOIN_REQUEST = 201,
|
||||||
|
JOIN_RESPONSE = 202,
|
||||||
|
|
||||||
|
//disconnect from the server
|
||||||
|
DISCONNECT_REQUEST = 203,
|
||||||
|
DISCONNECT_RESPONSE = 204,
|
||||||
|
ADMIN_DISCONNECT_FORCED = 205,
|
||||||
|
|
||||||
|
//load the account
|
||||||
|
LOGIN_REQUEST = 206,
|
||||||
|
LOGIN_RESPONSE = 207,
|
||||||
|
|
||||||
|
//unload the account
|
||||||
|
LOGOUT_REQUEST = 208,
|
||||||
|
LOGOUT_RESPONSE = 209,
|
||||||
|
|
||||||
|
//shut down the server
|
||||||
|
ADMIN_SHUTDOWN_REQUEST = 210,
|
||||||
|
|
||||||
|
FORMAT_END_CLIENT = 299,
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//RegionPacket
|
||||||
|
// room index, x, y, raw data
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
FORMAT_REGION = 300,
|
||||||
|
|
||||||
|
//map data
|
||||||
|
REGION_REQUEST = 301,
|
||||||
|
REGION_CONTENT = 302,
|
||||||
|
|
||||||
|
FORMAT_END_REGION = 399,
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//CharacterPacket
|
||||||
|
// character index,
|
||||||
|
// handle, avatar,
|
||||||
|
// account index (owner),
|
||||||
|
// room index, origin, motion
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
FORMAT_CHARACTER = 400,
|
||||||
|
|
||||||
|
//full data update
|
||||||
|
CHARACTER_UPDATE = 401,
|
||||||
|
|
||||||
|
//character management
|
||||||
|
CHARACTER_CREATE = 402,
|
||||||
|
CHARACTER_DELETE = 403,
|
||||||
|
CHARACTER_LOAD = 404,
|
||||||
|
CHARACTER_UNLOAD = 405,
|
||||||
|
|
||||||
|
//find out info from the server
|
||||||
|
QUERY_CHARACTER_EXISTS = 406,
|
||||||
|
|
||||||
|
//actions taken
|
||||||
|
CHARACTER_MOVEMENT = 407,
|
||||||
|
|
||||||
|
FORMAT_END_CHARACTER = 499,
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//CreaturePacket
|
||||||
|
// creature index,
|
||||||
|
// handle, avatar
|
||||||
|
// bounds
|
||||||
|
// room index, origin, motion
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
FORMAT_CREATURE = 500,
|
||||||
|
|
||||||
|
//full data update
|
||||||
|
CREATURE_UPDATE = 501,
|
||||||
|
|
||||||
|
//character management
|
||||||
|
CREATURE_CREATE = 502,
|
||||||
|
CREATURE_UNLOAD = 503,
|
||||||
|
|
||||||
|
//find out info from the server
|
||||||
|
QUERY_CREATURE_EXISTS = 504,
|
||||||
|
|
||||||
|
//actions taken
|
||||||
|
CREATURE_MOVEMENT = 505,
|
||||||
|
|
||||||
|
FORMAT_END_CREATURE = 599,
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//TextPacket
|
||||||
|
// name, text
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
FORMAT_TEXT = 600,
|
||||||
|
|
||||||
|
//general speech
|
||||||
|
TEXT_BROADCAST = 601,
|
||||||
|
TEXT_SPEECH = 602,
|
||||||
|
TEXT_WHISPER = 603,
|
||||||
|
|
||||||
|
//rejection/error messages
|
||||||
|
JOIN_REJECTION = 604,
|
||||||
|
LOGIN_REJECTION = 605,
|
||||||
|
REGION_REJECTION = 606,
|
||||||
|
CHARACTER_REJECTION = 607,
|
||||||
|
CREATURE_REJECTION = 608,
|
||||||
|
SHUTDOWN_REJECTION = 609,
|
||||||
|
QUERY_REJECTION = 610,
|
||||||
|
|
||||||
|
FORMAT_END_TEXT = 699,
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//BarrierPacket
|
||||||
|
// barrier index,
|
||||||
|
// bounds,
|
||||||
|
// roomIndex, origin, motion
|
||||||
|
// status
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
FORMAT_BARRIER = 700,
|
||||||
|
|
||||||
|
BARRIER_UPDATE = 701,
|
||||||
|
|
||||||
|
BARRIER_CREATE = 702,
|
||||||
|
BARRIER_UNLOAD = 703,
|
||||||
|
|
||||||
|
QUERY_BARRIER_EXISTS = 704,
|
||||||
|
|
||||||
|
BARRIER_ENTRY = 705,
|
||||||
|
BARRIER_EXIT = 706,
|
||||||
|
|
||||||
|
FORMAT_END_BARRIER = 799,
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//not used
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
LAST = 800
|
||||||
|
};
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "serial_utility.hpp"
|
||||||
|
|
||||||
|
//packet types
|
||||||
|
#include "barrier_packet.hpp"
|
||||||
|
#include "character_packet.hpp"
|
||||||
|
#include "client_packet.hpp"
|
||||||
|
#include "creature_packet.hpp"
|
||||||
|
#include "region_packet.hpp"
|
||||||
|
#include "server_packet.hpp"
|
||||||
|
#include "text_packet.hpp"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
//macros
|
||||||
|
#define BOUNDS(type, lower, upper) ((type) > (lower) && (type) < (upper))
|
||||||
|
|
||||||
|
//raw memory copy
|
||||||
|
void serialCopy(void** buffer, void* data, int size) {
|
||||||
|
memcpy(*buffer, data, size);
|
||||||
|
*buffer = reinterpret_cast<char*>(*buffer) + size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void deserialCopy(void** buffer, void* data, int size) {
|
||||||
|
memcpy(data, *buffer, size);
|
||||||
|
*buffer = reinterpret_cast<char*>(*buffer) + size;
|
||||||
|
}
|
||||||
|
|
||||||
|
//DOCS: The server and client MUST use the correct packet types
|
||||||
|
|
||||||
|
//main switch functions
|
||||||
|
void serializePacket(void* buffer, SerialPacketBase* packet) {
|
||||||
|
if (BOUNDS(packet->type, SerialPacketType::FORMAT_SERVER, SerialPacketType::FORMAT_END_SERVER)) {
|
||||||
|
serializeServer(buffer, static_cast<ServerPacket*>(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BOUNDS(packet->type, SerialPacketType::FORMAT_CLIENT, SerialPacketType::FORMAT_END_CLIENT)) {
|
||||||
|
serializeClient(buffer, static_cast<ClientPacket*>(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BOUNDS(packet->type, SerialPacketType::FORMAT_REGION, SerialPacketType::FORMAT_END_REGION)) {
|
||||||
|
serializeRegion(buffer, static_cast<RegionPacket*>(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BOUNDS(packet->type, SerialPacketType::FORMAT_CHARACTER, SerialPacketType::FORMAT_END_CHARACTER)) {
|
||||||
|
serializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BOUNDS(packet->type, SerialPacketType::FORMAT_CREATURE, SerialPacketType::FORMAT_END_CREATURE)) {
|
||||||
|
serializeCreature(buffer, static_cast<CreaturePacket*>(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BOUNDS(packet->type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) {
|
||||||
|
serializeText(buffer, static_cast<TextPacket*>(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BOUNDS(packet->type, SerialPacketType::FORMAT_BARRIER, SerialPacketType::FORMAT_END_BARRIER)) {
|
||||||
|
serializeBarrier(buffer, static_cast<BarrierPacket*>(packet));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void deserializePacket(void* buffer, SerialPacketBase* packet) {
|
||||||
|
//find the type, so that you can actually deserialize the packet!
|
||||||
|
SerialPacketType type;
|
||||||
|
memcpy(&type, buffer, sizeof(SerialPacketType));
|
||||||
|
|
||||||
|
if (BOUNDS(type, SerialPacketType::FORMAT_SERVER, SerialPacketType::FORMAT_END_SERVER)) {
|
||||||
|
deserializeServer(buffer, static_cast<ServerPacket*>(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BOUNDS(type, SerialPacketType::FORMAT_CLIENT, SerialPacketType::FORMAT_END_CLIENT)) {
|
||||||
|
deserializeClient(buffer, static_cast<ClientPacket*>(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BOUNDS(type, SerialPacketType::FORMAT_REGION, SerialPacketType::FORMAT_END_REGION)) {
|
||||||
|
deserializeRegion(buffer, static_cast<RegionPacket*>(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BOUNDS(type, SerialPacketType::FORMAT_CHARACTER, SerialPacketType::FORMAT_END_CHARACTER)) {
|
||||||
|
deserializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BOUNDS(type, SerialPacketType::FORMAT_CREATURE, SerialPacketType::FORMAT_END_CREATURE)) {
|
||||||
|
deserializeCreature(buffer, static_cast<CreaturePacket*>(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BOUNDS(type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) {
|
||||||
|
deserializeText(buffer, static_cast<TextPacket*>(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BOUNDS(type, SerialPacketType::FORMAT_BARRIER, SerialPacketType::FORMAT_END_BARRIER)) {
|
||||||
|
deserializeBarrier(buffer, static_cast<BarrierPacket*>(packet));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "serial_packet_base.hpp"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
//raw memory copy
|
||||||
|
void serialCopy(void** buffer, void* data, int size);
|
||||||
|
void deserialCopy(void** buffer, void* data, int size);
|
||||||
|
|
||||||
|
//primary functions
|
||||||
|
void serializePacket(void* buffer, SerialPacketBase* packet);
|
||||||
|
void deserializePacket(void* buffer, SerialPacketBase* packet);
|
||||||
@@ -0,0 +1,224 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "udp_network_utility.hpp"
|
||||||
|
|
||||||
|
#include "serial_packet.hpp"
|
||||||
|
#include "serial_utility.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
//DOCS: memset() is used before sending a packet to remove old data; you don't want to send sensitive data over the network
|
||||||
|
//NOTE: don't confuse SerialPacketBase with UDPpacket
|
||||||
|
|
||||||
|
void UDPNetworkUtility::Open(int port) {
|
||||||
|
socket = SDLNet_UDP_Open(port);
|
||||||
|
packet = SDLNet_AllocPacket(PACKET_BUFFER_SIZE);
|
||||||
|
if (!socket || !packet) {
|
||||||
|
Close();
|
||||||
|
throw(std::runtime_error("Failed to open UDPNetworkUtility"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UDPNetworkUtility::Close() {
|
||||||
|
SDLNet_UDP_Close(socket);
|
||||||
|
SDLNet_FreePacket(packet);
|
||||||
|
socket = nullptr;
|
||||||
|
packet = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//bind to a channel
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
int UDPNetworkUtility::Bind(const char* ip, int port, int channel) {
|
||||||
|
IPaddress add;
|
||||||
|
if (SDLNet_ResolveHost(&add, ip, port) == -1) {
|
||||||
|
throw(std::runtime_error("Failed to resolve a host"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Bind(add, channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
int UDPNetworkUtility::Bind(IPaddress add, int channel) {
|
||||||
|
int ret = SDLNet_UDP_Bind(socket, channel, &add);
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
throw(std::runtime_error("Failed to bind to a channel"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UDPNetworkUtility::Unbind(int channel) {
|
||||||
|
SDLNet_UDP_Unbind(socket, channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//send a buffer
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
int UDPNetworkUtility::SendTo(const char* ip, int port, void* data, int len) {
|
||||||
|
IPaddress add;
|
||||||
|
if (SDLNet_ResolveHost(&add, ip, port) == -1) {
|
||||||
|
throw(std::runtime_error("Failed to resolve a host"));
|
||||||
|
}
|
||||||
|
|
||||||
|
SendTo(add, data, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
int UDPNetworkUtility::SendTo(IPaddress add, void* data, int len) {
|
||||||
|
if (len > packet->maxlen) {
|
||||||
|
throw(std::runtime_error("The buffer is to large for the UDPpacket"));
|
||||||
|
}
|
||||||
|
memset(packet->data, 0, packet->maxlen);
|
||||||
|
memcpy(packet->data, data, len);
|
||||||
|
packet->len = len;
|
||||||
|
packet->address = add;
|
||||||
|
|
||||||
|
int ret = SDLNet_UDP_Send(socket, -1, packet);
|
||||||
|
|
||||||
|
if (ret <= 0) {
|
||||||
|
throw(std::runtime_error("Failed to send a packet"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UDPNetworkUtility::SendTo(int channel, void* data, int len) {
|
||||||
|
if (len > packet->maxlen) {
|
||||||
|
throw(std::runtime_error("The buffer is to large for the UDPpacket"));
|
||||||
|
}
|
||||||
|
memset(packet->data, 0, packet->maxlen);
|
||||||
|
memcpy(packet->data, data, len);
|
||||||
|
packet->len = len;
|
||||||
|
|
||||||
|
int ret = SDLNet_UDP_Send(socket, channel, packet);
|
||||||
|
|
||||||
|
if (ret <= 0) {
|
||||||
|
throw(std::runtime_error("Failed to send a packet"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UDPNetworkUtility::SendToAllChannels(void* data, int len) {
|
||||||
|
if (len > packet->maxlen) {
|
||||||
|
throw(std::runtime_error("The buffer is to large for the UDPpacket"));
|
||||||
|
}
|
||||||
|
memset(packet->data, 0, packet->maxlen);
|
||||||
|
memcpy(packet->data, data, len);
|
||||||
|
packet->len = len;
|
||||||
|
|
||||||
|
int sent = 0;
|
||||||
|
|
||||||
|
//send to all bound channels
|
||||||
|
for (int i = 0; i < SDLNET_MAX_UDPCHANNELS; i++) {
|
||||||
|
if (SDLNet_UDP_GetPeerAddress(socket, i)) {
|
||||||
|
sent += SDLNet_UDP_Send(socket, i, packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sent;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UDPNetworkUtility::Receive() {
|
||||||
|
memset(packet->data, 0, packet->maxlen);
|
||||||
|
int ret = SDLNet_UDP_Recv(socket, packet);
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
throw(std::runtime_error("Unknown network error occured"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//send a SerialPacketBase
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
int UDPNetworkUtility::SendTo(const char* ip, int port, SerialPacketBase* serialPacket) {
|
||||||
|
IPaddress add;
|
||||||
|
if (SDLNet_ResolveHost(&add, ip, port) == -1) {
|
||||||
|
throw(std::runtime_error("Failed to resolve a host"));
|
||||||
|
}
|
||||||
|
|
||||||
|
SendTo(add, serialPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
int UDPNetworkUtility::SendTo(IPaddress add, SerialPacketBase* serialPacket) {
|
||||||
|
memset(packet->data, 0, packet->maxlen);
|
||||||
|
serializePacket(packet->data, serialPacket);
|
||||||
|
packet->len = PACKET_BUFFER_SIZE;
|
||||||
|
packet->address = add;
|
||||||
|
|
||||||
|
int ret = SDLNet_UDP_Send(socket, -1, packet);
|
||||||
|
|
||||||
|
if (ret <= 0) {
|
||||||
|
throw(std::runtime_error("Failed to send a packet"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UDPNetworkUtility::SendTo(int channel, SerialPacketBase* serialPacket) {
|
||||||
|
memset(packet->data, 0, packet->maxlen);
|
||||||
|
serializePacket(packet->data, serialPacket);
|
||||||
|
packet->len = PACKET_BUFFER_SIZE;
|
||||||
|
|
||||||
|
int ret = SDLNet_UDP_Send(socket, channel, packet);
|
||||||
|
|
||||||
|
if (ret <= 0) {
|
||||||
|
throw(std::runtime_error("Failed to send a packet"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UDPNetworkUtility::SendToAllChannels(SerialPacketBase* serialPacket) {
|
||||||
|
memset(packet->data, 0, packet->maxlen);
|
||||||
|
serializePacket(packet->data, serialPacket);
|
||||||
|
packet->len = PACKET_BUFFER_SIZE;
|
||||||
|
|
||||||
|
int sent = 0;
|
||||||
|
|
||||||
|
//send to all bound channels
|
||||||
|
for (int i = 0; i < SDLNET_MAX_UDPCHANNELS; i++) {
|
||||||
|
if (SDLNet_UDP_GetPeerAddress(socket, i)) {
|
||||||
|
sent += SDLNet_UDP_Send(socket, i, packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sent;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UDPNetworkUtility::Receive(SerialPacketBase* serialPacket) {
|
||||||
|
memset(packet->data, 0, packet->maxlen);
|
||||||
|
int ret = SDLNet_UDP_Recv(socket, packet);
|
||||||
|
deserializePacket(packet->data, serialPacket);
|
||||||
|
serialPacket->srcAddress = packet->address;
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
throw(std::runtime_error("Unknown network error occured"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//common
|
||||||
|
#include "serial_packet_base.hpp"
|
||||||
|
#include "singleton.hpp"
|
||||||
|
|
||||||
|
//APIs
|
||||||
|
#include "SDL2/SDL_net.h"
|
||||||
|
|
||||||
|
class UDPNetworkUtility : public Singleton<UDPNetworkUtility> {
|
||||||
|
public:
|
||||||
|
void Open(int port);
|
||||||
|
void Close();
|
||||||
|
|
||||||
|
//bind to a channel
|
||||||
|
int Bind(const char* ip, int port, int channel = -1);
|
||||||
|
int Bind(IPaddress add, int channel = -1);
|
||||||
|
void Unbind(int channel);
|
||||||
|
|
||||||
|
IPaddress* GetIPAddress(int channel) {
|
||||||
|
return SDLNet_UDP_GetPeerAddress(socket, channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
//send a buffer
|
||||||
|
int SendTo(const char* ip, int port, void* data, int len);
|
||||||
|
int SendTo(IPaddress add, void* data, int len);
|
||||||
|
int SendTo(int channel, void* data, int len);
|
||||||
|
int SendToAllChannels(void* data, int len);
|
||||||
|
int Receive();
|
||||||
|
|
||||||
|
//send a SerialPacketBase
|
||||||
|
int SendTo(const char* ip, int port, SerialPacketBase* serialPacket);
|
||||||
|
int SendTo(IPaddress add, SerialPacketBase* serialPacket);
|
||||||
|
int SendTo(int channel, SerialPacketBase* serialPacket);
|
||||||
|
int SendToAllChannels(SerialPacketBase* serialPacket);
|
||||||
|
int Receive(SerialPacketBase* serialPacket);
|
||||||
|
|
||||||
|
//accessors
|
||||||
|
UDPpacket* GetPacket() const {
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
UDPsocket GetSocket() const {
|
||||||
|
return socket;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
friend Singleton<UDPNetworkUtility>;
|
||||||
|
|
||||||
|
UDPNetworkUtility() = default;
|
||||||
|
~UDPNetworkUtility() = default;
|
||||||
|
|
||||||
|
UDPsocket socket = nullptr;
|
||||||
|
UDPpacket* packet = nullptr;
|
||||||
|
};
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
void ConfigUtility::Load(std::string fname, bool skipMissingFile, int argc, char* argv[]) {
|
||||||
|
//clear the stored configuration
|
||||||
|
configMap.clear();
|
||||||
|
|
||||||
|
//use the default file
|
||||||
|
if (argc < 2) {
|
||||||
|
configMap = Read(fname, skipMissingFile);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//some variables to use
|
||||||
|
table_t redirectedFile;
|
||||||
|
table_t cmdLineParams;
|
||||||
|
char key[256], val[256];
|
||||||
|
bool redirectUsed = false;
|
||||||
|
|
||||||
|
//reading from the command line
|
||||||
|
for (int i = 1; i < argc; ++i) {
|
||||||
|
//read from a specified config file
|
||||||
|
if (!strncmp(argv[i], "-config=", 8)) {
|
||||||
|
//older specified files take precedence
|
||||||
|
table_t tmp = Read(argv[i] + 8, skipMissingFile);
|
||||||
|
redirectedFile.insert(tmp.begin(), tmp.end());
|
||||||
|
redirectUsed = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//set some specific values
|
||||||
|
if (!strncmp(argv[i], "-", 1)) {
|
||||||
|
//wipe the variables
|
||||||
|
memset(key, 0, 256);
|
||||||
|
memset(key, 0, 256);
|
||||||
|
|
||||||
|
//read the key-value pair
|
||||||
|
if (sscanf(argv[i], "-%[^=]=%[^\\0]", key, val) != 2) {
|
||||||
|
std::ostringstream os;
|
||||||
|
os << "Failed to read a command line config argument (expected -%s=%s):" << std::endl;
|
||||||
|
os << "\targv[" << i << "]: " << argv[i] << std::endl;
|
||||||
|
os << "\tkey: " << key << std::endl;
|
||||||
|
os << "\tval: " << val << std::endl;
|
||||||
|
throw(std::runtime_error( os.str() ));
|
||||||
|
}
|
||||||
|
cmdLineParams[key] = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//finally, construct the final config table
|
||||||
|
if (!redirectUsed) {
|
||||||
|
redirectedFile = Read(fname, skipMissingFile);
|
||||||
|
}
|
||||||
|
configMap.insert(cmdLineParams.begin(), cmdLineParams.end());
|
||||||
|
configMap.insert(redirectedFile.begin(), redirectedFile.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigUtility::table_t ConfigUtility::Read(std::string fname, bool skipMissingFile) {
|
||||||
|
//read in and return this file's data
|
||||||
|
table_t retTable;
|
||||||
|
std::ifstream is(fname);
|
||||||
|
|
||||||
|
if (!is.is_open()) {
|
||||||
|
if (skipMissingFile) {
|
||||||
|
return {}; //empty table
|
||||||
|
}
|
||||||
|
std::ostringstream os;
|
||||||
|
os << "Failed to open a config file: " << fname;
|
||||||
|
throw(std::runtime_error( os.str() ));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string key, val;
|
||||||
|
|
||||||
|
while(true) { //forever
|
||||||
|
//eat whitespace
|
||||||
|
while(isspace(is.peek())) {
|
||||||
|
is.ignore();
|
||||||
|
}
|
||||||
|
|
||||||
|
//end of file
|
||||||
|
if (is.eof()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//skip comment lines
|
||||||
|
if (is.peek() == '#') {
|
||||||
|
while(is.peek() != '\n' && !is.eof()) {
|
||||||
|
is.ignore();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//read in the pair
|
||||||
|
getline(is, key,'=');
|
||||||
|
getline(is, val);
|
||||||
|
|
||||||
|
//eat the whitespace at the start & end
|
||||||
|
while(key.size() && isspace( *key.begin() )) {
|
||||||
|
key.erase(0, 1);
|
||||||
|
}
|
||||||
|
while(val.size() && isspace( *val.begin() )) {
|
||||||
|
val.erase(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
while(key.size() && isspace( *(key.end()-1) )) {
|
||||||
|
key.erase(key.end() - 1);
|
||||||
|
}
|
||||||
|
while(val.size() && isspace( *(val.end()-1) )) {
|
||||||
|
val.erase(val.end() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//disallow empty/wiped pairs
|
||||||
|
if (key.size() == 0 || val.size() == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//save the pair
|
||||||
|
retTable[key] = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
is.close();
|
||||||
|
|
||||||
|
//load in any subordinate config files
|
||||||
|
if (retTable.find("config.next") != retTable.end()) {
|
||||||
|
table_t subTable = Read(retTable["config.next"], skipMissingFile);
|
||||||
|
retTable.insert(subTable.begin(), subTable.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
return retTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Convert to a type
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
std::string& ConfigUtility::String(std::string s) {
|
||||||
|
return configMap[s];
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConfigUtility::Integer(std::string s) {
|
||||||
|
table_t::iterator it = configMap.find(s);
|
||||||
|
if (it == configMap.end()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return atoi(it->second.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
double ConfigUtility::Double(std::string s) {
|
||||||
|
table_t::iterator it = configMap.find(s);
|
||||||
|
if (it == configMap.end()) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
return atof(it->second.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ConfigUtility::Boolean(std::string s) {
|
||||||
|
table_t::iterator it = configMap.find(s);
|
||||||
|
if (it == configMap.end()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return it->second == "true";
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "singleton.hpp"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class ConfigUtility: public Singleton<ConfigUtility> {
|
||||||
|
public:
|
||||||
|
void Load(std::string fname, bool skipMissingFile = false, int argc = 0, char* argv[] = nullptr);
|
||||||
|
|
||||||
|
//convert to a type
|
||||||
|
std::string& String(std::string);
|
||||||
|
int Integer(std::string);
|
||||||
|
double Double(std::string);
|
||||||
|
bool Boolean(std::string);
|
||||||
|
|
||||||
|
//shorthand
|
||||||
|
inline std::string& operator[](std::string s) { return configMap[s]; }
|
||||||
|
inline int Int(std::string s) { return Integer(s); }
|
||||||
|
inline bool Bool(std::string s) { return Boolean(s); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef std::map<std::string, std::string> table_t;
|
||||||
|
|
||||||
|
friend Singleton<ConfigUtility>;
|
||||||
|
|
||||||
|
table_t Read(std::string fname, bool skipMissingFile);
|
||||||
|
|
||||||
|
table_t configMap;
|
||||||
|
};
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2015
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//DOCS: this is a generic CSV reading tool
|
||||||
|
//DOCS: empty lines and comment lines begining with '#' are ignored
|
||||||
|
//DOCS: whitespace characters are valid field values
|
||||||
|
//DOCS: if the file is invalid, then the behavior is undefined
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cstring>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
//define the container types
|
||||||
|
template<int N>
|
||||||
|
using CSVElement = std::array<std::string, N>;
|
||||||
|
|
||||||
|
template<int N>
|
||||||
|
using CSVObject = std::vector<CSVElement<N>>;
|
||||||
|
|
||||||
|
//read a file into an object
|
||||||
|
template<int N>
|
||||||
|
CSVObject<N> readCSV(std::string fname, char delim = ',') {
|
||||||
|
//open the file
|
||||||
|
std::ifstream is(fname);
|
||||||
|
|
||||||
|
if (!is.is_open()) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to open file: " << fname;
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//build the scanf format
|
||||||
|
std::ostringstream format;
|
||||||
|
format << "%[^\0" << delim << "]";
|
||||||
|
|
||||||
|
//read and store each record (one per line)
|
||||||
|
CSVObject<N> object;
|
||||||
|
while(!is.eof()) {
|
||||||
|
//get a line
|
||||||
|
std::string tmpLine;
|
||||||
|
getline(is, tmpLine);
|
||||||
|
|
||||||
|
//skip blank and comment lines
|
||||||
|
if (tmpLine.size() == 0 || tmpLine[0] == '#') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//read and store each field
|
||||||
|
CSVElement<N> record;
|
||||||
|
for (int i = 0; i < N; ++i) {
|
||||||
|
//get a field
|
||||||
|
char tmpField[256];
|
||||||
|
memset(tmpField, 0, 256);
|
||||||
|
|
||||||
|
sscanf(tmpLine.c_str(), format.str().c_str(), tmpField);
|
||||||
|
|
||||||
|
//prune the input
|
||||||
|
int len = std::min(strlen(tmpField)+1, tmpLine.size());
|
||||||
|
tmpLine = tmpLine.substr(len);
|
||||||
|
|
||||||
|
//store the field
|
||||||
|
record[i] = tmpField;
|
||||||
|
}
|
||||||
|
|
||||||
|
object.push_back(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
//finally, close the file
|
||||||
|
is.close();
|
||||||
|
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<int N>
|
||||||
|
void writeCSV(std::string fname, CSVObject<N> const& object, char delim = ',') {
|
||||||
|
//open the file
|
||||||
|
std::ofstream os(fname);
|
||||||
|
|
||||||
|
if (!os.is_open()) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to open file: " << fname;
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//write each record, one at a time
|
||||||
|
for(auto& record : object) {
|
||||||
|
//write each field, one at a time
|
||||||
|
for (int i = 0; i < N; i++) {
|
||||||
|
os << record[i];
|
||||||
|
|
||||||
|
//print delimiter
|
||||||
|
if (i != N -1) {
|
||||||
|
os << delim;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
//finish
|
||||||
|
os.close();
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "file_hash.hpp"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
//hash a byte array into a 32-bit integer
|
||||||
|
unsigned fnv_hash_1a_32(void *key, int len) {
|
||||||
|
unsigned char *p = static_cast<unsigned char*>(key);
|
||||||
|
unsigned h = 0x811c9dc5;
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
h = ( h ^ p[i] ) * 0x01000193;
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getFileHash(std::string fname) {
|
||||||
|
std::ifstream is(fname, std::ios::in | std::ios::binary);
|
||||||
|
|
||||||
|
//if the file doesn't exist, return a hash of -1
|
||||||
|
if (!is.is_open()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//get the file size
|
||||||
|
is.seekg(0, std::ios_base::end);
|
||||||
|
int size = is.tellg();
|
||||||
|
is.seekg(0);
|
||||||
|
|
||||||
|
//create a buffer of that size
|
||||||
|
char buffer[size];
|
||||||
|
|
||||||
|
//load the data
|
||||||
|
is.read(buffer, size);
|
||||||
|
|
||||||
|
//cleanup
|
||||||
|
is.close();
|
||||||
|
|
||||||
|
//finally, return the hash value
|
||||||
|
return fnv_hash_1a_32(buffer, size);
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
int getFileHash(std::string fname);
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "ip_operators.hpp"
|
||||||
|
|
||||||
|
bool operator==(IPaddress lhs, IPaddress rhs) {
|
||||||
|
return lhs.host == rhs.host && lhs.port == rhs.port;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(IPaddress lhs, IPaddress rhs) {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "SDL2/SDL_net.h"
|
||||||
|
|
||||||
|
//these should've come standard
|
||||||
|
bool operator==(IPaddress lhs, IPaddress rhs);
|
||||||
|
bool operator!=(IPaddress lhs, IPaddress rhs);
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#config
|
||||||
|
INCLUDES+=.
|
||||||
|
LIBS+=
|
||||||
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
ar -crs $(OUT) $(OBJ)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class Singleton {
|
||||||
|
public:
|
||||||
|
static T& GetSingleton() {
|
||||||
|
if (!ptr) {
|
||||||
|
throw(std::logic_error("This singleton has not been created"));
|
||||||
|
}
|
||||||
|
return *ptr;
|
||||||
|
}
|
||||||
|
static void CreateSingleton() {
|
||||||
|
if (ptr) {
|
||||||
|
throw(std::logic_error("This singleton has already been created"));
|
||||||
|
}
|
||||||
|
ptr = new T();
|
||||||
|
}
|
||||||
|
static void DeleteSingleton() {
|
||||||
|
if (!ptr) {
|
||||||
|
throw(std::logic_error("A non-existant singleton cannot be deleted"));
|
||||||
|
}
|
||||||
|
delete ptr;
|
||||||
|
ptr = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Singleton() = default;
|
||||||
|
Singleton(Singleton const&) = default;
|
||||||
|
Singleton(Singleton&&) = default;
|
||||||
|
~Singleton() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static T* ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T* Singleton<T>::ptr = nullptr;
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
Future versions (to be determined) may be released under a modified version of the Uplink Developer's License.
|
||||||
|
|
||||||
|
The current version of Tortuga is released under the zlib license.
|
||||||
|
|
||||||
|
Copyright (c) 2013-2015 Kayne Ruse
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
The Game Map
|
|
||||||
|
|
||||||
This section outlines the game’s map system. This system utilizes pagination to create a theoretically infinite game map, as well as supporting multiple tilesets in the same map. The goal of this design is to create a system with as much flexibility as possible, and simply enforcing a more rigid approach higher in the tool chain.
|
|
||||||
|
|
||||||
Tile
|
|
||||||
|
|
||||||
The Tile class is the basic unit of the map system, and is explicitly a POD (plain old data) structure. A tile has these members:
|
|
||||||
|
|
||||||
X Position
|
|
||||||
Y Position
|
|
||||||
Depth
|
|
||||||
Width
|
|
||||||
Height
|
|
||||||
Tile Index
|
|
||||||
|
|
||||||
The tile’s X and Y positions are relative to their container region’s location. A tile’s depth allows multiple tiles to be drawn at the same location, and in the correct order; tiles with lower depths (including below zero) are drawn first. If a new tile has the same X position, Y position and depth as an existing tile, the old tile is overwritten.
|
|
||||||
|
|
||||||
The width and height members indicate the graphical size of the tile (not actually used when drawing), while the tile index is the specific tile for the sheet manager to draw. A negative value here is considered an error message.
|
|
||||||
|
|
||||||
Region
|
|
||||||
|
|
||||||
The region class has these members:
|
|
||||||
|
|
||||||
X Position
|
|
||||||
Y Position
|
|
||||||
Width
|
|
||||||
Height
|
|
||||||
Tile Container
|
|
||||||
|
|
||||||
Each region in a certain map must have the same width and height, and it’s X and Y positions must be multiples of those width and height values, respectfully. The outcome of this restriction is a theoretically infinite grid of region objects.
|
|
||||||
|
|
||||||
Each region holds a set of tiles corresponding to the region’s bounds. The tiles’ X and Y positions are relative to the regions’, so moving the region will move the tiles as well. A region object is created or loaded when a tile is place in it’s bounds; similarly, if a region has no tiles it should be deleted or removed from memory.
|
|
||||||
|
|
||||||
The exact width and height of a region has no significant impact, other than loading or transmission costs. The width and height of a map can be adjusted as needed.
|
|
||||||
|
|
||||||
Region Pager
|
|
||||||
|
|
||||||
The region pager class has these members:
|
|
||||||
|
|
||||||
Region Width
|
|
||||||
Region Height
|
|
||||||
On New Callback
|
|
||||||
On Delete Callback
|
|
||||||
Region Container
|
|
||||||
|
|
||||||
The Region Pager class holds a series of region objects, as well as creating and deleting them as needed. Every region theoretically exists at any time, so if a non-existent region object is requested, it is created and then returned. This class also has the Prune() method, which removes all regions out of bounds from memory, and the DrawTo method, which takes (among other things) the sheet manager for the map.
|
|
||||||
|
|
||||||
The width and height members must be set before the pager is used, and must not be changed while it still has regions loaded. These are used to create region objects as needed.
|
|
||||||
|
|
||||||
Each pager can also have two different callbacks set: “on new” and “on delete”. If either of these are set (that is, not null) then each region object’s address is passed to these after it is created or before it is destroyed, respectfully. The callbacks are intended to be used for domain specific processes, such as loading or saving data, or even requesting data from a remote server.
|
|
||||||
|
|
||||||
Tile Sheet
|
|
||||||
|
|
||||||
A tileset is a series of tile graphics stored in a single file. The tile sheet class loads a tile set into memory, and provides utilities for drawing them to the screen. The tile sheet class has these members:
|
|
||||||
|
|
||||||
Image
|
|
||||||
X Count
|
|
||||||
Y Count
|
|
||||||
Total Count
|
|
||||||
Begin
|
|
||||||
End
|
|
||||||
|
|
||||||
The Image class is utilized heavily here by storing the graphical data and the tile size. Any file loaded into a sheet object must have all tile images arranged in a grid pattern, and they must all have the same width and height. The width and height must be provided when the file is loaded.
|
|
||||||
|
|
||||||
The X and Y counts are the number of tiles along the X and Y axis of the sheet’s image, and the total count is the number of tiles in the whole sheet (which is equal to the product of the X and Y counts).
|
|
||||||
|
|
||||||
Begin is the index of the first tile on the sheet (default is zero), and end is the index after the last tile (defaults to the value of total count). These indicate the range of the tiles, and are mostly used by the sheet manager. They are also used by the InRange() method, which checks to see if a certain tile is in that sheet.
|
|
||||||
|
|
||||||
Tile Sheet Manager
|
|
||||||
|
|
||||||
This class has these members:
|
|
||||||
|
|
||||||
Tile Sheet Container
|
|
||||||
Range End
|
|
||||||
|
|
||||||
This class is a wrapper around a key-value container, using strings as the keys. Given a specific tile index, this class will draw the correct tile from the loaded sheets, or it throws an error.
|
|
||||||
|
|
||||||
Also, this class keeps track of the end of the sheet’s ranges.
|
|
||||||
|
|
||||||
TODO
|
|
||||||
|
|
||||||
Map File Format
|
|
||||||
|
|
||||||
TODO
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
This particular refactoring stage was absolute hell, mostly because I was wrestling with a severe bout of depression too. So, I've added the diffs, and a scary screenshot of the git console.
|
|
||||||
|
|
||||||
There are three diff files because server/server_application.cpp was split into two files: server/server_internals.cpp and server/server_connections.cpp, each with it's own diff.
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user