Compare commits
560 Commits
8c0debed40
...
as
| Author | SHA1 | Date | |
|---|---|---|---|
| e81340f6ce | |||
|
|
fc01a95bc4 | ||
|
|
4b72d7c174 | ||
|
|
be66e61285 | ||
|
|
924ab6e6fa | ||
|
|
f83403eed7 | ||
| 957ddaad4d | |||
| 429829e847 | |||
| 347f8705de | |||
| 33f76e6a89 | |||
| 872d9d7bc3 | |||
| d689db9388 | |||
| 7a31c754ee | |||
| e7e2f355b0 | |||
| 5a0b2ecd13 | |||
| 3836c35723 | |||
| a4111d0622 | |||
| f975cebeb5 | |||
| 4a1deea89e | |||
| e3da82c0ac | |||
| 8d97cda751 | |||
| c2985a6bb1 | |||
| b5d5009f61 | |||
| 5d8d5849ee | |||
| a364f21a07 | |||
| 56759639ae | |||
| 64f1f87c0a | |||
| eed9440200 | |||
| 53e30c70da | |||
| e71c6e863c | |||
| e995c2c687 | |||
| ea161290eb | |||
| 89c8290045 | |||
| c877952365 | |||
| 88743161e2 | |||
| 2fa813069e | |||
|
|
622399a45c | ||
| a7edb3116f | |||
|
|
047d74eaec | ||
| 5a3e94dacd | |||
| b3bd516643 | |||
| ed6b107f3e | |||
| ea9b8acf55 | |||
| 8f0896da38 | |||
| c7e74f6ec5 | |||
| b54c087e18 | |||
| e1a6b4b609 | |||
| f19fe48f5f | |||
| d3c4e95d83 | |||
| 6ed98d0790 | |||
|
|
7a0352e012 | ||
| ca99d2b34b | |||
| b157375522 | |||
|
|
3153eb1ac6 | ||
| ac52f99e14 | |||
| 794abef83a | |||
| f97c163ea5 | |||
| a9ba7445fa | |||
| 21bda9afbe | |||
| 170e3bf567 | |||
| b5dcc5646d | |||
| 5c168d342b | |||
| 8ee0aa6ec9 | |||
|
|
ee1002da3a | ||
|
|
085f2fba27 | ||
| 5ee833c315 | |||
| 999db35a85 | |||
|
|
7adca12c8f | ||
| db5fa9ca21 | |||
| 17e078f743 | |||
| dde86bb8b1 | |||
| 59f4d769b6 | |||
| ce02c8dc2a | |||
| ffd1d57cba | |||
| c24e5e6fdd | |||
| b484b742bc | |||
| b7fdb4edc2 | |||
| ad63c5d2c5 | |||
| a267c9d3a0 | |||
| c90e20b288 | |||
| 2b40543425 | |||
| 756c2e98fe | |||
| d347b1b74f | |||
| dc3faff91d | |||
| 8d93ed6f64 | |||
| 5a6816e70e | |||
| d94bf97a47 | |||
| ed9c124286 | |||
| 652ee90fc1 | |||
| 04bfc1a8a2 | |||
| b68415be42 | |||
| f182c84c93 | |||
| bd221ceb02 | |||
|
|
fd092d3a2d | ||
|
|
9dcff14b68 | ||
| accdee9549 | |||
| 97ca39457d | |||
| 49e7e8053a | |||
|
|
c68de9caa6 | ||
|
|
caca8bcf79 | ||
|
|
dc746ae82a | ||
|
|
a15cdccb78 | ||
| 061e60b839 | |||
| 06109c7fd3 | |||
| 0a66799c47 | |||
| 3b4f29f53f | |||
| 5b25027e51 | |||
| d85b340398 | |||
| b35ae45ae7 | |||
|
|
67baab5035 | ||
| 32555c9152 | |||
| c303640a02 | |||
| 94e8982bd5 | |||
| 658854a3e4 | |||
| 5cfea89ea0 | |||
|
|
44d1891196 | ||
|
|
87522ca98f | ||
| 0989660683 | |||
| 7cff518260 | |||
| 08c702e00e | |||
|
|
75ca41bdfc | ||
|
|
3b27fcb883 | ||
| 05bc32769e | |||
| 1cfb024d04 | |||
| 95b1821636 | |||
| c9a6b88826 | |||
| 77ded46961 | |||
| 5646d1a5e4 | |||
| ea46b48eee | |||
| 4a6e086c0e | |||
| f8dec1dba5 | |||
| 618c39c634 | |||
| 051507142b | |||
| a062534659 | |||
| e1063449ae | |||
| a368898f1a | |||
| de9c82b1a3 | |||
| ea74396d6f | |||
| f467d53cc2 | |||
| a684f42e0d | |||
| 4d607336cd | |||
| f808d2e9c6 | |||
| 35cf8eb56d | |||
| 768f4d7839 | |||
| 914959df3f | |||
| 2a32df773d | |||
| 15e4d5327c | |||
| dc5b19323f | |||
| fd8668c0e7 | |||
| af460a1630 | |||
|
|
33d5146be8 | ||
| a4d0864980 | |||
| 027cd225a0 | |||
| df55220895 | |||
| 32a53cc6fd | |||
| cfdc59d5bd | |||
| 8467fcc584 | |||
| 3735e77e03 | |||
| d097e346b2 | |||
| 7fef75d8c7 | |||
| b1ddd2db79 | |||
| 5d49b048fd | |||
| 318dd45b19 | |||
| 16ff9a88bb | |||
| 25b206dca8 | |||
| 4ddbfe61e3 | |||
| ffc912a4d4 | |||
| bd7f9cdfb9 | |||
| 11fc12bfd9 | |||
| 87eebfb4f6 | |||
| dc67a81f9f | |||
| f382367980 | |||
| 645edf5a25 | |||
| c552012831 | |||
| de264be3e3 | |||
| 85ebcfa38e | |||
| 503db418d3 | |||
| b20e6c7fab | |||
| a07662e544 | |||
| beec158508 | |||
| 56c58694d2 | |||
| 5fda30b1e1 | |||
| 612a31d2d8 | |||
| 00fb3131c7 | |||
| 539016b1be | |||
| 71def4e124 | |||
|
|
cc5ae2d620 | ||
| e830bf2654 | |||
| 50241f957e | |||
| cf7b56167b | |||
| 7fea96083d | |||
| f409eb7233 | |||
| 75a7e0bf92 | |||
| 896165efe2 | |||
| eb7767fa08 | |||
| 84706809e0 | |||
| 69a85ca620 | |||
| c163b6a04e | |||
| 519a28ca5c | |||
| f7fdf74f83 | |||
| 846721f16c | |||
| 747af0662c | |||
| c7bf78fd3e | |||
| e9d7a3268b | |||
| 1ea341e8a8 | |||
| 3e98876ab1 | |||
| 6f92ddd034 | |||
| 67f90e6428 | |||
| ca8d02b0f6 | |||
| a2a6d71323 | |||
| a528e45f2d | |||
| c085310285 | |||
| e8ea69616b | |||
| a39f36fadb | |||
| 9663247904 | |||
| 66d933f2f5 | |||
| 19bc297a62 | |||
| 3e03918764 | |||
| 917f45188a | |||
| d25b6de1b5 | |||
| c73b363a7f | |||
| 7d26a14787 | |||
| 49922e4a18 | |||
| c7a8b8b46c | |||
| a24cf97588 | |||
| 62c85aeb66 | |||
| 23a7a9fd40 | |||
| 4bc94527df | |||
| 91d41633a7 | |||
| 3dc4459a98 | |||
| 3e1ce01a72 | |||
| 63205f18de | |||
| 7068f16a34 | |||
| c12997a9cb | |||
| a24ef3953e | |||
| 0c50e55f74 | |||
| 5d705cfef5 | |||
| 9fd53d1d0b | |||
| 5e03acbc95 | |||
| 2b8c81822f | |||
| 5fe978c494 | |||
| d9d5421299 | |||
| 5b76ee51fe | |||
| 289ec70653 | |||
| 9de148271b | |||
| d11664f067 | |||
| 544c29e8b9 | |||
| 28b6de3d8c | |||
| 673fdff7ae | |||
| fc48b9967c | |||
| 128c87049c | |||
| 6525d38603 | |||
| 71bc558859 | |||
| fc174d4b76 | |||
| 2191b589aa | |||
| e21869a3bf | |||
| a7f17add73 | |||
| 361d328a98 | |||
| 80d84a362e | |||
| e20620fedf | |||
| 3d9dc19049 | |||
| a79612885b | |||
| b6c252318e | |||
| f7df6376f6 | |||
| 59b881302b | |||
| 97e4fdaf58 | |||
| 39122a6e51 | |||
| 469280c7c8 | |||
| d669fb430b | |||
| 86b9d49a52 | |||
| 9651c88ffe | |||
| f6ace83729 | |||
| c19ef32505 | |||
| 7b6ac65d6a | |||
| 84d93d21ea | |||
| cfa99d24a0 | |||
| a8f5068f1b | |||
| 21554417d1 | |||
| b02d83e72d | |||
| b90c6cb333 | |||
| c370481954 | |||
| 4e6db00df8 | |||
| 2d9adc6cef | |||
| fb87244bd8 | |||
| eca141be99 | |||
|
|
10d14cb8dc | ||
| 072333387f | |||
| 24c3fe5e62 | |||
| 55d6514e56 | |||
| 2877a0576d | |||
| e7cd381587 | |||
| 9cfb36fd80 | |||
| 850d22b5b1 | |||
| 475e44bcc5 | |||
| af0f8ecf3d | |||
| cc5d883482 | |||
| e9bb4470a2 | |||
| c4d9df60d9 | |||
| ce4f65782f | |||
| 87e1a9aee0 | |||
| 2a85327a8e | |||
| 5aaf24d8a7 | |||
| b880279b42 | |||
| 4c1d479dfe | |||
| 7045b5a6ed | |||
| 9eaf5a2f54 | |||
| 0e29610808 | |||
| 1299adbc68 | |||
| 31a6007f05 | |||
| 61383029dc | |||
| 1b1ae5cc3c | |||
| 62fda5cc08 | |||
| fe49c0ad1d | |||
| 756a34128d | |||
| 64db8d670b | |||
| 9833f2d757 | |||
| f961018850 | |||
| 40a7372df9 | |||
| 5d6d48ebda | |||
| 323d97d6fd | |||
| 5546775e55 | |||
| 4d18d10c74 | |||
| 92a6d7c48f | |||
| 2d00e6f19f | |||
| ae5b12bdd8 | |||
| 4be4f10c0c | |||
| 8e929f44af | |||
| aa0557b1d8 | |||
| acb5b9fb16 | |||
| 0c64b08712 | |||
| 29d8bf474a | |||
| e9e05d5ed1 | |||
| e32ad97790 | |||
| 57e518e3b2 | |||
| 7c8202d182 | |||
| baef716db1 | |||
| 7011bdc05f | |||
| 16ed87afbb | |||
| 0e6ebad2ba | |||
| 8ec5777a7c | |||
| f83bcbb194 | |||
| 44a71dc477 | |||
| 2d76c42c9c | |||
| f303b17c41 | |||
| 24488e4495 | |||
| bfdb82a741 | |||
| 07e79fd1ac | |||
| 6500ffd1d9 | |||
| aa3c35ed1a | |||
| 7986f9ac73 | |||
| 285e83246e | |||
| bb4a967290 | |||
| 11f7f7ff1a | |||
| 63ee210e40 | |||
| 8972f2f1f5 | |||
| 8a5052ecc6 | |||
| 73e4868ce8 | |||
| a556d6468a | |||
| 6f3b5a6884 | |||
| 9928fd4f1f | |||
| b45732c05d | |||
| d2ac9f8013 | |||
| 0b341cdda1 | |||
| e0c70ae7e7 | |||
| d759e70a1d | |||
| 9a6c875398 | |||
| efd3959b5b | |||
| eb15f62f83 | |||
| ecf6f7137f | |||
| 32218b00dc | |||
| 9ceede5bbb | |||
| f166a85e69 | |||
| f825d1fe53 | |||
| a5972e4e1a | |||
| fff349c71a | |||
| 6d9b05c927 | |||
| 33b0d44fc9 | |||
| 27b0d205dd | |||
| 0639e6bbec | |||
| bd1af5419e | |||
| 74f1103618 | |||
| 4da8dd00ff | |||
| 7e6cb8f9b1 | |||
| 85f5039c81 | |||
| 3c973eb28d | |||
| 20d8236701 | |||
| 2c421c37ff | |||
| 758cc39c19 | |||
| 55c24686f1 | |||
| f7dd288908 | |||
| b5a79753ea | |||
| c4b7444b7a | |||
| eaf2765c96 | |||
| 3cb4f9a54b | |||
| 16f2ef8e02 | |||
| 2ceb1ea26c | |||
| f9f3ee58ff | |||
| 9ca021133b | |||
| 23b3700a42 | |||
| adea97280e | |||
| d43890e4cf | |||
| e89406f8f2 | |||
| 7aaa095fbc | |||
| af18839fe6 | |||
| 3d5bd4ebff | |||
| 6278183960 | |||
| 7d254ab0e5 | |||
| b22b7411eb | |||
| de21aa399e | |||
| 47b2dca56f | |||
| 3171e3f958 | |||
| d9b7d02e4d | |||
| b43b69a749 | |||
| 4b4ea9e4ff | |||
| 42b1c2aeb8 | |||
| eb7bb26804 | |||
| 4166103b68 | |||
| 854143a980 | |||
| 905019db00 | |||
| c7017f5508 | |||
| 3b1f9ae9c5 | |||
| 93c00706fc | |||
| 69a2f2e14b | |||
| c7fe733cd6 | |||
| c029a909a6 | |||
| bb0df38b70 | |||
| c638acc117 | |||
|
|
7e54de7c9d | ||
|
|
cebf698aa5 | ||
| 5916f293c3 | |||
| 8110767654 | |||
| 407e6ef039 | |||
| e47215d71e | |||
| 1be9c270a1 | |||
| 2d6d0b189b | |||
| de4f8a11fe | |||
|
|
2952ff378f | ||
|
|
27c7917338 | ||
| b8456634ae | |||
| f732a6a343 | |||
| 0e6eac2829 | |||
| d093a0105e | |||
| df9a6efbf3 | |||
| e339c234c0 | |||
| bc914d7398 | |||
| 1f9dc57e11 | |||
| c45ee1b6ed | |||
| a88262463f | |||
| 1ca49626d5 | |||
| 22ccf33e4a | |||
| 80b0dcd51d | |||
| 10f6d9bebb | |||
| 410a883f12 | |||
| df77a4b847 | |||
| 07c3a1dad1 | |||
| 2716bbf9d1 | |||
| 4f7a1f4443 | |||
|
|
c5d60527a0 | ||
| 771d624c4e | |||
| b0a931657a | |||
| f6eaa5ff8e | |||
| 351353ce63 | |||
|
|
1861ef16eb | ||
|
|
940eb961cd | ||
|
|
8434f0f11e | ||
| 4ff099de99 | |||
|
|
44a92ea288 | ||
| 59f8d4ab08 | |||
| 86d6aba1f6 | |||
| f08e090c65 | |||
| 897b1c937b | |||
| 9d360fe9ed | |||
| b06e98eadb | |||
| f45d54abe5 | |||
| 2660bffe3e | |||
| 755ca93a4e | |||
| e4cf4d4948 | |||
| ed72cd0a5a | |||
| efaa8c86d6 | |||
| 98a60b507c | |||
| b369c925dc | |||
| fe71cef42f | |||
| 19f050a2d0 | |||
| 137c5d6464 | |||
| c4614944aa | |||
| e4716d47d1 | |||
| 3525ecac71 | |||
| c4bdf73ca9 | |||
| 0cb42976d8 | |||
| bc0717b189 | |||
| c549e4cae9 | |||
| 4ac64797e4 | |||
| 7603da2bd2 | |||
| e3c11e064f | |||
| 1ef6bc560e | |||
| 966fe26e10 | |||
| 4ebd63f9ea | |||
| 50c5238219 | |||
| c1afe4de62 | |||
| c9615dfc2b | |||
| 0561ed005a | |||
| 7b633a6a63 | |||
| 0f4eae6eaf | |||
| abc414046f | |||
| 2523a91dfd | |||
| 6dd8b27ae1 | |||
| 3f31762859 | |||
| fa6f50eb84 | |||
| 7d8fec8aff | |||
| 248e314644 | |||
| e33445b4e2 | |||
| 0b521a3a63 | |||
| cb648b2e20 | |||
| a08a18424a | |||
| b05e22b110 | |||
| 4314254c04 | |||
| 9ffb3c116a | |||
| b8a0410d25 | |||
| 6dc659a4e2 | |||
| b1dc69ed28 | |||
| 09667f9441 | |||
| 86fa716f03 | |||
| 4bf4e22383 | |||
| acc07bcbbb | |||
| 69561e0a7f | |||
| 9962ac9dea | |||
| 1d881a3f76 | |||
| 7913f50d4c | |||
| ec35c6e941 | |||
| d06d7c3eef | |||
| c1109cb72c | |||
| a4d748f2dd | |||
| 415c5779fe | |||
| c19f96f9ac | |||
| aa0cfd59e2 | |||
| 342738ff0f | |||
| fc926692d6 | |||
|
|
14099d85d5 | ||
| de1b6e44ac | |||
| 4bd1062db9 | |||
| afabbfc20f | |||
| 89978fa5ed | |||
| ddce87c047 | |||
| d4b31299e6 | |||
| b2b114c94d | |||
| 7b25295b8c | |||
| 9a5f82aeac | |||
| d874ff7708 | |||
|
|
eee1571fa4 | ||
| 6117fcd47b | |||
| 2243e3d6ba | |||
|
|
ec40e313e4 | ||
| 6ddfb19ed4 | |||
|
|
25947288f7 | ||
| 3e06438f7a | |||
| 828fe646ce | |||
| c3690acd5d | |||
| d7c84b70e8 | |||
| f78f452d26 | |||
| 515db93d07 |
80
.gitignore
vendored
@@ -1,47 +1,53 @@
|
||||
#
|
||||
# Common
|
||||
#
|
||||
|
||||
.vscode
|
||||
|
||||
*.temp
|
||||
|
||||
open-builder/
|
||||
|
||||
*.srctrlprj
|
||||
*.srctrldb
|
||||
*.srctrlbm
|
||||
|
||||
#
|
||||
# Linux
|
||||
#
|
||||
|
||||
bin/
|
||||
|
||||
#
|
||||
# Windows
|
||||
#
|
||||
|
||||
*.dll
|
||||
CMakeFiles/
|
||||
CMakeCache.txt
|
||||
*.exe
|
||||
|
||||
# Visual Studio
|
||||
.vscode
|
||||
*.sln
|
||||
*.vcxproj
|
||||
*.filters
|
||||
*.user
|
||||
*.vs
|
||||
|
||||
# CMake
|
||||
CMakeFiles/
|
||||
CMakeCache.txt
|
||||
cmake_install.cmake
|
||||
|
||||
# Make
|
||||
Makefile
|
||||
mk/make/Makefile.config
|
||||
|
||||
# Ninja
|
||||
.ninja_deps
|
||||
.ninja_log
|
||||
build.ninja
|
||||
|
||||
# Generated headers
|
||||
config.hpp
|
||||
|
||||
# ImGui
|
||||
imgui.ini
|
||||
|
||||
# Binary files
|
||||
*.exe
|
||||
*.dll
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# User provided folders
|
||||
external/
|
||||
|
||||
# Generic build folders
|
||||
Debug/
|
||||
Release/
|
||||
UnitTests/
|
||||
open-builder-unit-tests/
|
||||
build/
|
||||
|
||||
libenet.a
|
||||
libglad.a
|
||||
font.ttf
|
||||
Makefile
|
||||
polygun
|
||||
cmake_install.cmake
|
||||
# Media files
|
||||
*.png
|
||||
*.ogg
|
||||
*.ttf
|
||||
|
||||
# Python
|
||||
__pycache__
|
||||
|
||||
# demos
|
||||
!/demos/**/*.png
|
||||
*.blend1
|
||||
448
CMakeLists.txt
@@ -1,21 +1,443 @@
|
||||
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
|
||||
# PolyGun
|
||||
|
||||
# Copyright (c) 2023 kacperks https://kacperks.cubesoftware.xyz
|
||||
# 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
cmake_minimum_required(VERSION 3.19 FATAL_ERROR)
|
||||
|
||||
project(polygun)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
if(SERENITYOS)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
else()
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
endif()
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED true)
|
||||
|
||||
include_directories(deps)
|
||||
include_directories(src/common)
|
||||
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/mk/cmake")
|
||||
|
||||
file(GLOB_RECURSE Sources "src/**.cpp" "src/**.h")
|
||||
|
||||
add_executable(${PROJECT_NAME} ${Sources})
|
||||
|
||||
if(UNIX AND NOT APPLE) # linux
|
||||
target_link_libraries(${PROJECT_NAME} GL GLEW glfw)
|
||||
if(NOT BUILD_FLAG_SUPPRESS_WARNING_MODE AND NOT MSVC)
|
||||
# Compile with highest warning mode by default
|
||||
set(DEFAULT_COMPILE_OPTIONS -Wall -Wpedantic -Werror)
|
||||
endif()
|
||||
|
||||
if (WIN32) # windows
|
||||
target_link_libraries(${PROJECT_NAME} opengl32 glew32 glfw3)
|
||||
endif(WIN32)
|
||||
include_directories("${CMAKE_SOURCE_DIR}/src")
|
||||
include_directories("${CMAKE_BINARY_DIR}")
|
||||
|
||||
option(BUILD_CLIENT "Build client" ON)
|
||||
option(BUILD_SERVER "Build server" ON)
|
||||
option(BUILD_TOOLS "Build tools" OFF)
|
||||
if(APPLE OR SERENITYOS)
|
||||
set(RENDERER_GL_DEFAULT OFF)
|
||||
else()
|
||||
set(RENDERER_GL_DEFAULT ON)
|
||||
endif()
|
||||
option(RENDERER_GL "Enable OpenGL renderer" ${RENDERER_GL_DEFAULT})
|
||||
if(SERENITYOS)
|
||||
set(RENDERER_LEGACY_GL_DEFAULT ON)
|
||||
else()
|
||||
set(RENDERER_LEGACY_GL_DEFAULT OFF)
|
||||
endif()
|
||||
# Please note that LEGACY_GL renderer should be only used on hardware/operating systems that do not support OpenGL 2.0+
|
||||
option(RENDERER_LEGACY_GL "Enable legacy OpenGL renderer" ${RENDERER_LEGACY_GL_DEFAULT})
|
||||
if(NOT BUILD_CLIENT)
|
||||
set(RENDERER_GL OFF)
|
||||
set(RENDERER_LEGACY_GL OFF)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
set(WINDOW_WIN32_DEFAULT ON)
|
||||
else()
|
||||
set(WINDOW_WIN32_DEFAULT OFF)
|
||||
endif()
|
||||
option(WINDOW_WIN32 "Enable Win32 window creation (Windows only)" ${WINDOW_WIN32_DEFAULT})
|
||||
if(UNIX AND NOT APPLE AND NOT SERENITYOS)
|
||||
if(X11_INCLUDE_DIRS AND X11_LIBRARIES)
|
||||
set(WINDOW_X11_DEFAULT ON)
|
||||
else()
|
||||
find_package(X11 QUIET)
|
||||
if(X11_FOUND)
|
||||
set(WINDOW_X11_DEFAULT ON)
|
||||
else()
|
||||
set(WINDOW_X11_DEFAULT OFF)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
option(WINDOW_X11 "Enable X11 window creation" ${WINDOW_X11_DEFAULT})
|
||||
if(UNIX AND NOT APPLE AND NOT SERENITYOS)
|
||||
if(WaylandClient_INCLUDE_DIR AND WaylandClient_LIBRARY)
|
||||
set(WINDOW_WAYLAND_DEFAULT ON)
|
||||
else()
|
||||
find_package(WaylandClient QUIET)
|
||||
if(WaylandClient_FOUND)
|
||||
set(WINDOW_WAYLAND_DEFAULT ON)
|
||||
else()
|
||||
set(WINDOW_WAYLAND_DEFAULT OFF)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
option(WINDOW_WAYLAND "Enable Wayland window creation" ${WINDOW_WAYLAND_DEFAULT})
|
||||
if(SERENITYOS)
|
||||
set(WINDOW_SERENITYOS_DEFAULT ON)
|
||||
execute_process(COMMAND patch INPUT_FILE mk/fixes/serenityos/01_angelscript_no_malloc_h.diff)
|
||||
add_definitions("-D__serenityos__")
|
||||
endif()
|
||||
option(WINDOW_SERENITYOS "Enable SerenityOS window creation" ${WINDOW_SERENITYOS_DEFAULT})
|
||||
if(HAIKU)
|
||||
set(WINDOW_HAIKU_DEFAULT ON)
|
||||
else()
|
||||
set(WINDOW_HAIKU_DEFAULT OFF)
|
||||
endif()
|
||||
option(WINDOW_HAIKU "Enable Haiku window creation" ${WINDOW_HAIKU_DEFAULT})
|
||||
|
||||
option(ENABLE_BACKTRACE_PRINTING "Enable backtrace printing" OFF)
|
||||
if(ENABLE_BACKTRACE_PRINTING)
|
||||
if(MSVC)
|
||||
|
||||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BUILD_CLIENT)
|
||||
set(CLIENT_SOURCES
|
||||
src/game/audio/audio.cpp
|
||||
src/game/audio/buffer.cpp
|
||||
src/game/audio/oggvorbis_decoder.cpp
|
||||
src/game/audio/source.cpp
|
||||
src/game/audio/streaming_source.cpp
|
||||
src/game/control/keyboard_controller.cpp
|
||||
src/game/control/mouse_camera_controller.cpp
|
||||
src/game/engine/content_registry.cpp
|
||||
src/game/engine/engine.cpp
|
||||
src/game/engine/game_config.cpp
|
||||
src/game/engine/greedy_meshing.cpp
|
||||
src/game/engine/ingame_music.cpp
|
||||
src/game/engine/node_side.cpp
|
||||
src/game/engine/normal_meshing.cpp
|
||||
src/game/engine/ray.cpp
|
||||
src/game/engine/redirect_manager.cpp
|
||||
src/game/engine/resource_manager.cpp
|
||||
src/game/engine/screen_manager.cpp
|
||||
src/game/engine/sync_manager.cpp
|
||||
src/game/engine/texture_atlas.cpp
|
||||
src/game/engine/thread_helper.cpp
|
||||
src/game/gui/box.cpp
|
||||
src/game/gui/button.cpp
|
||||
src/game/gui/chat.cpp
|
||||
src/game/gui/combo_box.cpp
|
||||
src/game/gui/component.cpp
|
||||
src/game/gui/constraint.cpp
|
||||
src/game/gui/container.cpp
|
||||
src/game/gui/gui_master.cpp
|
||||
src/game/gui/image.cpp
|
||||
src/game/gui/item_gallery.cpp
|
||||
src/game/gui/label.cpp
|
||||
src/game/gui/layout.cpp
|
||||
src/game/gui/line_edit.cpp
|
||||
src/game/gui/message_box.cpp
|
||||
src/game/gui/slider.cpp
|
||||
src/game/gui/style_change_listener.cpp
|
||||
src/game/gui/style.cpp
|
||||
src/game/gui/tab_view.cpp
|
||||
src/game/gui/text_edit.cpp
|
||||
src/game/hud/editmode_hud.cpp
|
||||
src/game/hud/hud.cpp
|
||||
src/game/hud/normal_hud.cpp
|
||||
src/game/renderer/font.cpp
|
||||
src/game/renderer/gui_renderer.cpp
|
||||
src/game/renderer/master_renderer.cpp
|
||||
src/game/renderer/mesh_renderer.cpp
|
||||
src/game/renderer/ortho_camera.cpp
|
||||
src/game/renderer/surface.cpp
|
||||
src/game/renderer/texture.cpp
|
||||
src/game/screens/game_session_screen.cpp
|
||||
src/game/screens/main_menu_screen.cpp
|
||||
src/game/screens/options_screen.cpp
|
||||
src/game/window/keyboard.cpp
|
||||
src/game/window/mouse.cpp
|
||||
src/game/window/window.cpp
|
||||
src/game/world/chunk_manager.cpp
|
||||
src/game/world/client_chunk.cpp
|
||||
src/game/world/local_player.cpp
|
||||
src/game/world/physic_manager.cpp
|
||||
src/game/world/player_manager.cpp
|
||||
src/game/world/skybox.cpp
|
||||
)
|
||||
if(RENDERER_GL)
|
||||
list(APPEND CLIENT_SOURCES
|
||||
src/game/renderer/gl/gl_context.cpp
|
||||
src/game/renderer/gl/gl_gui_renderer.cpp
|
||||
src/game/renderer/gl/gl_master_renderer.cpp
|
||||
src/game/renderer/gl/gl_mesh.cpp
|
||||
src/game/renderer/gl/gl_mesh_renderer.cpp
|
||||
src/game/renderer/gl/gl_shader.cpp
|
||||
src/game/renderer/gl/gl_texture.cpp
|
||||
src/game/renderer/gl/opengl.cpp
|
||||
)
|
||||
endif()
|
||||
if(RENDERER_LEGACY_GL)
|
||||
list(APPEND CLIENT_SOURCES
|
||||
src/game/renderer/gl/gl_context.cpp
|
||||
src/game/renderer/gl/gl_texture.cpp
|
||||
src/game/renderer/gl/opengl.cpp
|
||||
src/game/renderer/legacy_gl/legacy_gl_gui_renderer.cpp
|
||||
src/game/renderer/legacy_gl/legacy_gl_master_renderer.cpp
|
||||
src/game/renderer/legacy_gl/legacy_gl_mesh.cpp
|
||||
src/game/renderer/legacy_gl/legacy_gl_mesh_renderer.cpp
|
||||
)
|
||||
endif()
|
||||
if(WINDOW_WIN32)
|
||||
list(APPEND CLIENT_SOURCES
|
||||
src/game/window/win32/win32_window.cpp
|
||||
)
|
||||
if(RENDERER_GL OR RENDERER_LEGACY_GL)
|
||||
list(APPEND CLIENT_SOURCES
|
||||
src/game/renderer/gl/win32_gl_context.cpp
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
if(WINDOW_X11)
|
||||
list(APPEND CLIENT_SOURCES
|
||||
src/game/window/x11/dynamic_x11.cpp
|
||||
src/game/window/x11/x11_window.cpp
|
||||
)
|
||||
if(RENDERER_GL OR RENDERER_LEGACY_GL)
|
||||
list(APPEND CLIENT_SOURCES
|
||||
src/game/renderer/gl/x11_gl_context.cpp
|
||||
src/game/window/x11/dynamic_glx.cpp
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
if(WINDOW_WAYLAND)
|
||||
list(APPEND CLIENT_SOURCES
|
||||
src/game/window/wayland_window.cpp
|
||||
)
|
||||
if(RENDERER_GL OR RENDERER_LEGACY_GL)
|
||||
list(APPEND CLIENT_SOURCES
|
||||
src/game/renderer/gl/egl_gl_context.cpp
|
||||
)
|
||||
endif()
|
||||
execute_process(COMMAND wayland-scanner client-header INPUT_FILE ${CMAKE_SOURCE_DIR}/mk/wayland/relative-pointer-unstable-v1.xml OUTPUT_FILE ${CMAKE_BINARY_DIR}/wayland-relative-pointer-unstable-v1.h)
|
||||
execute_process(COMMAND wayland-scanner private-code INPUT_FILE ${CMAKE_SOURCE_DIR}/mk/wayland/relative-pointer-unstable-v1.xml OUTPUT_FILE ${CMAKE_BINARY_DIR}/wayland-relative-pointer-unstable-v1.c)
|
||||
execute_process(COMMAND wayland-scanner client-header INPUT_FILE ${CMAKE_SOURCE_DIR}/mk/wayland/pointer-constraints-unstable-v1.xml OUTPUT_FILE ${CMAKE_BINARY_DIR}/wayland-pointer-constraints-unstable-v1.h)
|
||||
execute_process(COMMAND wayland-scanner private-code INPUT_FILE ${CMAKE_SOURCE_DIR}/mk/wayland/pointer-constraints-unstable-v1.xml OUTPUT_FILE ${CMAKE_BINARY_DIR}/wayland-pointer-constraints-unstable-v1.c)
|
||||
list(APPEND CLIENT_SOURCES
|
||||
${CMAKE_BINARY_DIR}/wayland-relative-pointer-unstable-v1.c
|
||||
${CMAKE_BINARY_DIR}/wayland-pointer-constraints-unstable-v1.c
|
||||
)
|
||||
endif()
|
||||
if(WINDOW_SERENITYOS)
|
||||
list(APPEND CLIENT_SOURCES
|
||||
src/game/window/serenityos_window.cpp
|
||||
)
|
||||
if(RENDERER_LEGACY_GL)
|
||||
list(APPEND CLIENT_SOURCES
|
||||
src/game/renderer/gl/serenityos_gl_context.cpp
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
if(WINDOW_HAIKU)
|
||||
list(APPEND CLIENT_SOURCES
|
||||
src/game/window/haiku_window.cpp
|
||||
)
|
||||
if(RENDERER_GL OR RENDERER_LEGACY_GL)
|
||||
list(APPEND CLIENT_SOURCES
|
||||
src/game/renderer/gl/haiku_gl_context.cpp
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
if(BUILD_SERVER)
|
||||
file(GLOB_RECURSE SERVER_SOURCES "src/server/**.cpp")
|
||||
|
||||
include(CheckCXXSourceCompiles)
|
||||
check_cxx_source_compiles(
|
||||
"
|
||||
#include <csignal>
|
||||
#include <cstring>
|
||||
int main(){
|
||||
const char* sig = strsignal(SIGINT);
|
||||
return 0;
|
||||
}
|
||||
"
|
||||
HAVE_STRSIGNAL_CHECK
|
||||
)
|
||||
if(HAVE_STRSIGNAL_CHECK)
|
||||
option(HAVE_STRSIGNAL "STRSIGNAL" ON)
|
||||
endif()
|
||||
endif()
|
||||
configure_file("config.hpp.in" "config.hpp")
|
||||
|
||||
if(BUILD_TOOLS)
|
||||
add_executable("extract_strings"
|
||||
tools/extract_strings.cpp
|
||||
src/common/xml/xml_node.cpp
|
||||
src/common/xml/lexer.cpp
|
||||
src/common/xml/parser.cpp
|
||||
src/common/logger.cpp
|
||||
)
|
||||
target_compile_options(extract_strings PRIVATE ${DEFAULT_COMPILE_OPTIONS})
|
||||
|
||||
add_executable("t3d_to_polymap"
|
||||
tools/t3d_to_polymap.cpp
|
||||
src/common/binary_utils.cpp
|
||||
)
|
||||
target_compile_options(t3d_to_polymap PRIVATE ${DEFAULT_COMPILE_OPTIONS})
|
||||
endif()
|
||||
file(GLOB_RECURSE COMMON_SOURCES "src/common/**.cpp")
|
||||
if(NOT ENABLE_BACKTRACE_PRINTING)
|
||||
list(REMOVE_ITEM COMMON_SOURCES ${CMAKE_SOURCE_DIR}/src/common/backtrace_handler.cpp)
|
||||
endif()
|
||||
|
||||
if(BUILD_SERVER AND NOT BUILD_CLIENT)
|
||||
set(PROJECT_NAME "polygun_server")
|
||||
endif()
|
||||
|
||||
if(NOT BUILD_CLIENT AND NOT BUILD_SERVER)
|
||||
message(FATAL_ERROR "You need to select at least one configuration (BUILD_CLIENT and/or BUILD_SERVER)")
|
||||
endif()
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
${CLIENT_SOURCES}
|
||||
${SERVER_SOURCES}
|
||||
${COMMON_SOURCES}
|
||||
src/main.cpp
|
||||
)
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE ${DEFAULT_COMPILE_OPTIONS})
|
||||
|
||||
if(BUILD_CLIENT)
|
||||
if(RENDERER_GL OR RENDERER_LEGACY_GL)
|
||||
set(RENDERER_GL_LIBRARIES OpenGL::GL)
|
||||
if(SERENITYOS)
|
||||
set(OPENGL_INCLUDE_DIR "/usr/include/LibGL")
|
||||
set(RENDERER_GL_LIBRARIES "gl;gfx")
|
||||
set(OPENGL_LIBRARIES "gl")
|
||||
elseif(UNIX AND NOT HAIKU)
|
||||
set(RENDERER_GL_LIBRARIES "libOpenGL.so")
|
||||
endif()
|
||||
if(NOT OPENGL_INCLUDE_DIR OR NOT OPENGL_LIBRARIES)
|
||||
set(RENDERER_GL_COMPONENTS OpenGL)
|
||||
if(WINDOW_WAYLAND)
|
||||
list(APPEND RENDERER_GL_COMPONENTS ";EGL")
|
||||
list(APPEND RENDERER_GL_LIBRARIES ";OpenGL::EGL")
|
||||
if(NOT WaylandEGL_INCLUDE_DIR OR NOT WaylandEGL_LIBRARY)
|
||||
find_package(WaylandEGL REQUIRED)
|
||||
endif()
|
||||
include_directories(${WaylandEGL_INCLUDE_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} ${WaylandEGL_LIBRARY})
|
||||
endif()
|
||||
find_package(OpenGL REQUIRED COMPONENTS ${RENDERER_GL_COMPONENTS})
|
||||
endif()
|
||||
include_directories(${OPENGL_INCLUDE_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} ${RENDERER_GL_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(WINDOW_X11)
|
||||
if(NOT X11_INCLUDE_DIRS OR NOT X11_LIBRARIES)
|
||||
find_package(X11 REQUIRED)
|
||||
endif()
|
||||
include_directories(${X11_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
if(WINDOW_WAYLAND)
|
||||
if(NOT WaylandClient_INCLUDE_DIR OR NOT WaylandClient_LIBRARY)
|
||||
find_package(WaylandClient REQUIRED)
|
||||
endif()
|
||||
include_directories(${WaylandClient_INCLUDE_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} ${WaylandClient_LIBRARY})
|
||||
if(NOT WaylandCursor_INCLUDE_DIR OR NOT WaylandCursor_LIBRARY)
|
||||
find_package(WaylandCursor REQUIRED)
|
||||
endif()
|
||||
include_directories(${WaylandCursor_INCLUDE_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} ${WaylandCursor_LIBRARY})
|
||||
if(NOT Libdecor_INCLUDE_DIR OR NOT Libdecor_LIBRARY)
|
||||
find_package(Libdecor REQUIRED)
|
||||
endif()
|
||||
include_directories(${Libdecor_INCLUDE_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} ${Libdecor_LIBRARY})
|
||||
if(NOT XKBCommon_INCLUDE_DIR OR NOT XKBCommon_LIBRARY)
|
||||
find_package(XKBCommon REQUIRED)
|
||||
endif()
|
||||
include_directories(${XKBCommon_INCLUDE_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} ${XKBCommon_LIBRARY})
|
||||
endif()
|
||||
|
||||
if(WINDOW_HAIKU)
|
||||
target_link_libraries(${PROJECT_NAME} "be" "game")
|
||||
endif()
|
||||
|
||||
if(NOT OPENAL_INCLUDE_DIR OR NOT OPENAL_LIBRARY)
|
||||
find_package(OpenAL REQUIRED)
|
||||
endif()
|
||||
include_directories("${OPENAL_INCLUDE_DIR}")
|
||||
target_link_libraries(${PROJECT_NAME} "${OPENAL_LIBRARY}")
|
||||
|
||||
if(NOT OGG_INCLUDE_DIR OR NOT OGG_LIBRARY OR NOT VORBIS_INCLUDE_DIR OR NOT VORBIS_LIBRARY)
|
||||
find_package(OggVorbis REQUIRED)
|
||||
endif()
|
||||
include_directories("${OGG_INCLUDE_DIR}")
|
||||
include_directories("${VORBIS_INCLUDE_DIR}")
|
||||
target_link_libraries(${PROJECT_NAME} "${VORBIS_LIBRARY}")
|
||||
target_link_libraries(${PROJECT_NAME} "${OGG_LIBRARY}")
|
||||
|
||||
if(NOT PNG_INCLUDE_DIRS OR NOT PNG_LIBRARIES)
|
||||
find_package(PNG REQUIRED)
|
||||
endif()
|
||||
include_directories("${PNG_INCLUDE_DIRS}")
|
||||
target_link_libraries(${PROJECT_NAME} "${PNG_LIBRARIES}")
|
||||
|
||||
if(NOT ZLIB_INCLUDE_DIRS OR NOT ZLIB_LIBRARIES)
|
||||
find_package(ZLIB REQUIRED)
|
||||
endif()
|
||||
include_directories("${ZLIB_INCLUDE_DIRS}")
|
||||
target_link_libraries(${PROJECT_NAME} "${ZLIB_LIBRARIES}")
|
||||
|
||||
if(UNIX AND NOT HAIKU)
|
||||
target_link_libraries(${PROJECT_NAME} "dl")
|
||||
endif()
|
||||
endif()
|
||||
if(BUILD_SERVER)
|
||||
add_subdirectory("${CMAKE_SOURCE_DIR}/external/angelscript/angelscript/projects/cmake")
|
||||
include_directories("${CMAKE_SOURCE_DIR}/external/angelscript/angelscript/include")
|
||||
include_directories("${CMAKE_SOURCE_DIR}/external/angelscript/add_on")
|
||||
target_link_libraries(${PROJECT_NAME} "angelscript")
|
||||
add_library("angelscript_addons" STATIC
|
||||
external/angelscript/add_on/scriptstdstring/scriptstdstring.cpp
|
||||
external/angelscript/add_on/scriptstdstring/scriptstdstring_utils.cpp
|
||||
)
|
||||
target_link_libraries(${PROJECT_NAME} "angelscript_addons")
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(${PROJECT_NAME} "ws2_32")
|
||||
endif()
|
||||
if(SERENITYOS)
|
||||
target_link_libraries(${PROJECT_NAME} "gcc_s" "gui" "threading" "core")
|
||||
endif()
|
||||
if(HAIKU)
|
||||
target_link_libraries(${PROJECT_NAME} "network")
|
||||
endif()
|
||||
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(${PROJECT_NAME} "${CMAKE_THREAD_LIBS_INIT}")
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 kacperks, Looki2000, Solindek, mrkubax10
|
||||
Copyright (c) 2021-2023 Migdyn
|
||||
|
||||
|
||||
40
config.hpp.in
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#cmakedefine BUILD_CLIENT
|
||||
#cmakedefine BUILD_SERVER
|
||||
|
||||
#cmakedefine RENDERER_GL
|
||||
#cmakedefine RENDERER_LEGACY_GL
|
||||
|
||||
#cmakedefine WINDOW_WIN32
|
||||
#cmakedefine WINDOW_X11
|
||||
#cmakedefine WINDOW_WAYLAND
|
||||
#cmakedefine WINDOW_SERENITYOS
|
||||
#cmakedefine WINDOW_HAIKU
|
||||
|
||||
#cmakedefine ENABLE_BACKTRACE_PRINTING
|
||||
|
||||
#cmakedefine HAVE_STRSIGNAL
|
||||
#define POLYGUN_VERSION "git"
|
||||
81
demos/DDA light test/light.py
Normal file
@@ -0,0 +1,81 @@
|
||||
import numpy as np
|
||||
import numba
|
||||
from ray_casting import light_cast
|
||||
|
||||
# left, top, right, bottom
|
||||
offsets = np.array([[0.0, 0.5], [0.5, 0.0], [1.0, 0.5], [0.5, 1.0]])
|
||||
normals = np.array([[-1, 0], [0, -1], [1, 0], [0, 1]], dtype=np.float64)
|
||||
|
||||
@numba.njit
|
||||
def inverse_square_law(distance):
|
||||
return 1 / ((distance + 1) ** 2)
|
||||
|
||||
@numba.njit
|
||||
def process_light(map_arr, emissive_positions):
|
||||
light_arr = np.zeros(map_arr.shape, dtype=np.float32)
|
||||
|
||||
# for each map block
|
||||
for y in range(map_arr.shape[1]):
|
||||
for x in range(map_arr.shape[0]):
|
||||
# skip if block is not air
|
||||
if map_arr[y, x] != 0:
|
||||
continue
|
||||
|
||||
#print("===============")
|
||||
#print(emissive_positions)
|
||||
#print("===============")
|
||||
|
||||
# for each emissive block
|
||||
for emissive_pos in emissive_positions:
|
||||
|
||||
#temp_emissive_pos = np.array(emissive_pos)
|
||||
|
||||
#print("===============")
|
||||
# for each wall of emissive block
|
||||
for i in range(4):
|
||||
# calculate source position, normal axis and normal sign
|
||||
#source = temp_emissive_pos + offsets[i]
|
||||
source = emissive_pos + offsets[i]
|
||||
#print(source)
|
||||
|
||||
# normal axis is alternating: x, y, x, y
|
||||
source_normal_axis = i % 2
|
||||
|
||||
# normal sign is switching in the middle: -1, -1, 1, 1
|
||||
source_normal_sign = -1 if i < 2 else 1
|
||||
|
||||
target = np.array([x + 0.5, y + 0.5])
|
||||
|
||||
# cast light
|
||||
hit, dir, dir_3d = light_cast(map_arr, source, target, source_normal_axis, source_normal_sign)
|
||||
#print(hit, dir)
|
||||
|
||||
# skip if hit (light was blocked by some wall)
|
||||
if hit:
|
||||
continue
|
||||
|
||||
# calculate distance
|
||||
distance = np.linalg.norm(source - target)
|
||||
|
||||
|
||||
## calculate light intensity
|
||||
|
||||
# area depending on distance
|
||||
intensity = inverse_square_law(distance)
|
||||
|
||||
|
||||
#intensity = distance
|
||||
# multiply by dot product of normal and direction
|
||||
#print(normals[i].dtype, dir.dtype)
|
||||
|
||||
# area depending on direction the emissive face is seen by the target
|
||||
intensity *= np.dot(normals[i], dir)
|
||||
|
||||
# and the other way around (we assume target normal is always facing up in 3D in this scenario)
|
||||
intensity *= np.dot(np.array([0, 0, -1], dtype=np.float64), dir_3d)
|
||||
|
||||
# add intensity to light array
|
||||
light_arr[y, x] += intensity
|
||||
|
||||
|
||||
return light_arr
|
||||
187
demos/DDA light test/main.py
Normal file
@@ -0,0 +1,187 @@
|
||||
import pygame
|
||||
import pygame.freetype
|
||||
import numpy as np
|
||||
from light import process_light
|
||||
|
||||
|
||||
|
||||
""" KEYBOARD CONTROLS
|
||||
|
||||
left mouse button - remove
|
||||
middle mouse button - draw wall
|
||||
right mouse button - draw emissive block (becomes very slow very quickly)
|
||||
up and down arrow keys - change exposure
|
||||
|
||||
"""
|
||||
|
||||
|
||||
##### CONFIG #####
|
||||
|
||||
# works best when its multiple of map_size
|
||||
window_size = (768,) * 2
|
||||
|
||||
# additionaly limited by monitor refresh rate (vsync)
|
||||
fps_limit = 240
|
||||
|
||||
|
||||
map_size = (64, ) * 2
|
||||
|
||||
|
||||
# colors
|
||||
wall = (8, 16, 32)
|
||||
emissive = (255, 255, 100)
|
||||
grid_lines = (32,) * 3
|
||||
|
||||
##################
|
||||
|
||||
|
||||
# pygame init
|
||||
pygame.init()
|
||||
window = pygame.display.set_mode(window_size, flags=pygame.SCALED, vsync=1)
|
||||
clock = pygame.time.Clock()
|
||||
font = pygame.freetype.SysFont("Arial", 16)
|
||||
|
||||
|
||||
# 0 - air
|
||||
# 1 - wall
|
||||
# 2 - emissive block
|
||||
map_arr = np.zeros(map_size, dtype=np.uint8)
|
||||
light_arr = np.zeros(map_size, dtype=np.uint16)
|
||||
|
||||
#emissive_positions = [None]
|
||||
emissive_positions = np.zeros((0, 2), dtype=np.uint16)
|
||||
|
||||
block_size = window_size[1] / map_size[1]
|
||||
|
||||
|
||||
class HDRToPixel:
|
||||
def __init__(self):
|
||||
self.exposure = 1.0
|
||||
self.gamma = 2.2
|
||||
self.gamma_power_factor = self._gamma_power_factor(self.gamma)
|
||||
|
||||
def __call__(self, hdr_value):
|
||||
return (np.clip(np.power(hdr_value * self.exposure, self.gamma_power_factor), 0, 1) * 255).astype(np.uint8)
|
||||
|
||||
def _gamma_power_factor(self, gamma):
|
||||
return 1 / gamma
|
||||
|
||||
def set_exposure(self, exposure):
|
||||
self.exposure = exposure
|
||||
|
||||
def set_gamma(self, gamma):
|
||||
self.gamma = gamma
|
||||
self.gamma_power_factor = self._gamma_power_factor(gamma)
|
||||
|
||||
hdr_to_pixel = HDRToPixel()
|
||||
|
||||
|
||||
|
||||
#d_time = 1 / fps_limit
|
||||
|
||||
block_updated = True
|
||||
|
||||
|
||||
font.render_to(window, (10, 10), "Numba is compiling... Please wait...", (255, 255, 255), size=32)
|
||||
pygame.display.update()
|
||||
|
||||
# main loop
|
||||
while True:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
pygame.quit()
|
||||
quit()
|
||||
|
||||
# mouse input
|
||||
mouse_pos = np.array(pygame.mouse.get_pos())
|
||||
mouse_pos = (mouse_pos / block_size).astype(np.uint8)
|
||||
mouse_buttons = pygame.mouse.get_pressed()
|
||||
|
||||
# wall placement with middle mouse button
|
||||
if mouse_buttons[1]:
|
||||
#if map_arr[mouse_pos[1], mouse_pos[0]] == 2:
|
||||
#emissive_positions.remove((mouse_pos[0], mouse_pos[1]))
|
||||
|
||||
# if do exist in the array, remove it
|
||||
if np.any(np.all(emissive_positions == mouse_pos, axis=1)):
|
||||
emissive_positions = np.delete(emissive_positions, np.where(np.all(emissive_positions == mouse_pos, axis=1))[0][0], axis=0)
|
||||
|
||||
|
||||
map_arr[mouse_pos[1], mouse_pos[0]] = 1
|
||||
block_updated = True
|
||||
|
||||
# emissive block placement with right mouse button
|
||||
elif mouse_buttons[2]:
|
||||
map_arr[mouse_pos[1], mouse_pos[0]] = 2
|
||||
# if does not exist in the list, add it
|
||||
#if (mouse_pos[0], mouse_pos[1]) not in emissive_positions:
|
||||
#emissive_positions.append((mouse_pos[0], mouse_pos[1]))
|
||||
|
||||
# if does not exist in the list, add it
|
||||
if not np.any(np.all(emissive_positions == mouse_pos, axis=1)):
|
||||
emissive_positions = np.append(emissive_positions, np.array([[mouse_pos[0], mouse_pos[1]]]), axis=0)
|
||||
|
||||
block_updated = True
|
||||
|
||||
# block removal with left mouse button
|
||||
elif mouse_buttons[0]:
|
||||
#if map_arr[mouse_pos[1], mouse_pos[0]] == 2:
|
||||
#emissive_positions.remove((mouse_pos[0], mouse_pos[1]))
|
||||
|
||||
# if do exist in the array, remove it
|
||||
if np.any(np.all(emissive_positions == mouse_pos, axis=1)):
|
||||
emissive_positions = np.delete(emissive_positions, np.where(np.all(emissive_positions == mouse_pos, axis=1))[0][0], axis=0)
|
||||
|
||||
map_arr[mouse_pos[1], mouse_pos[0]] = 0
|
||||
block_updated = True
|
||||
|
||||
|
||||
# keyboard input
|
||||
keys = pygame.key.get_pressed()
|
||||
|
||||
# exposure change on up and down arrow keys
|
||||
if keys[pygame.K_UP]:
|
||||
hdr_to_pixel.set_exposure(hdr_to_pixel.exposure * 1.1)
|
||||
if keys[pygame.K_DOWN]:
|
||||
hdr_to_pixel.set_exposure(hdr_to_pixel.exposure / 1.1)
|
||||
|
||||
|
||||
window.fill((0, 0, 0))
|
||||
|
||||
# calculate light
|
||||
if block_updated:
|
||||
light_arr = process_light(map_arr, emissive_positions)
|
||||
block_updated = False
|
||||
|
||||
|
||||
|
||||
# draw map blocks
|
||||
for y in range(map_size[1]):
|
||||
for x in range(map_size[0]):
|
||||
match map_arr[y, x]:
|
||||
case 0:
|
||||
|
||||
# calculate pixel value
|
||||
color = (hdr_to_pixel(light_arr[y, x]),) * 3
|
||||
pygame.draw.rect(window, color, (x * block_size, y * block_size, block_size, block_size))
|
||||
|
||||
# draw light power value text
|
||||
#font.render_to(window, (x * block_size + 2, y * block_size + 2), f"{light_arr[y, x]:.2f}", (255, 100, 100))
|
||||
case 1:
|
||||
pygame.draw.rect(window, wall, (x * block_size, y * block_size, block_size, block_size))
|
||||
case 2:
|
||||
pygame.draw.rect(window, emissive, (x * block_size, y * block_size, block_size, block_size))
|
||||
|
||||
## draw grid
|
||||
#for i in range(map_size[0] + 1):
|
||||
# pygame.draw.line(window, grid_lines, (i * block_size, 0), (i * block_size, window_size[1]))
|
||||
#for i in range(map_size[1] + 1):
|
||||
# pygame.draw.line(window, grid_lines, (0, i * block_size), (block_size * map_size[0], i * block_size))
|
||||
|
||||
|
||||
|
||||
#font.render_to(window, (10, 10), f"FPS: {clock.get_fps():.2f}", (255, 255, 255), size=16)
|
||||
|
||||
pygame.display.update()
|
||||
clock.tick(fps_limit)
|
||||
#d_time = clock.tick(fps_limit) / 1000
|
||||
107
demos/DDA light test/ray_casting.py
Normal file
@@ -0,0 +1,107 @@
|
||||
import numpy as np
|
||||
import numba
|
||||
|
||||
|
||||
# modified light_cast function from PolyGun
|
||||
"""
|
||||
target is NOT normalized position
|
||||
light_cast ray should be cast from the center of the face of a node
|
||||
source_normal_sign should be 1 if the normal is pointing towards positive direction, -1 otherwise
|
||||
"""
|
||||
@numba.njit
|
||||
def light_cast(map_arr, source, target, source_normal_axis, source_normal_sign):
|
||||
# floor
|
||||
hit_node = np.floor(source).astype(np.int32)
|
||||
|
||||
# if front of the face is NOT visible
|
||||
if (target[source_normal_axis] - source[source_normal_axis]) * source_normal_sign <= 0:
|
||||
#hit = True
|
||||
# if normal is positive, move hit_node backwards
|
||||
#if source_normal_sign > 0:
|
||||
# hit_node[source_normal_axis] -= 1
|
||||
return True, None, None
|
||||
|
||||
|
||||
# check for collision in starting place if normal is positive
|
||||
if source_normal_sign > 0:
|
||||
if map_arr[hit_node[1]][hit_node[0]] > 0:
|
||||
#hit = True
|
||||
return True, None, None
|
||||
# and for next node if normal is negative
|
||||
else:
|
||||
temp_hit_node = hit_node.copy()
|
||||
temp_hit_node[source_normal_axis] -= 1
|
||||
|
||||
if map_arr[temp_hit_node[1]][temp_hit_node[0]] > 0:
|
||||
#hit = True
|
||||
#hit_node = temp_hit_node
|
||||
return True, None, None
|
||||
|
||||
|
||||
# calculate direction
|
||||
direction = (target - source) / np.linalg.norm(target - source)
|
||||
|
||||
ray_length = np.zeros(2).astype(np.float32)
|
||||
unit_step_size = np.zeros(2).astype(np.float32)
|
||||
step = np.zeros(2).astype(np.int32)
|
||||
|
||||
|
||||
# calculate how long does the ray need to travel to go from the one to the other side of the node on each axis
|
||||
#unit_step_size = np.sqrt(np.array([
|
||||
# 1 + (direction[1] / direction[0]) ** 2,
|
||||
# 1 + (direction[0] / direction[1]) ** 2
|
||||
#]))
|
||||
unit_step_size = np.sqrt(np.array([
|
||||
np.inf if direction[0] == 0 else 1 + (direction[1] / direction[0]) ** 2,
|
||||
np.inf if direction[1] == 0 else 1 + (direction[0] / direction[1]) ** 2
|
||||
]))
|
||||
|
||||
# perform first step from current position to the node boundary
|
||||
for i in range(2):
|
||||
if direction[i] < 0:
|
||||
step[i] = -1
|
||||
#print("===============")
|
||||
#print(ray_length)
|
||||
ray_length[i] = (source[i] - hit_node[i]) * unit_step_size[i]
|
||||
#print(ray_length)
|
||||
else:
|
||||
step[i] = 1
|
||||
#print("===============")
|
||||
#print(ray_length)
|
||||
ray_length[i] = (hit_node[i] + 1 - source[i]) * unit_step_size[i]
|
||||
#print(ray_length)
|
||||
|
||||
# floor
|
||||
target_node = np.floor(target).astype(np.int32)
|
||||
|
||||
shortest_axis = 0
|
||||
#hit = False
|
||||
|
||||
# perform next steps until there is a hit or the hit_node is the target_node
|
||||
#while not hit and not np.array_equal(hit_node, target_node):
|
||||
while not np.array_equal(hit_node, target_node):
|
||||
# select axis with the shortest travel distance
|
||||
shortest_axis = 0
|
||||
shortest_dist = ray_length[0]
|
||||
|
||||
if ray_length[1] < shortest_dist:
|
||||
shortest_dist = ray_length[1]
|
||||
shortest_axis = 1
|
||||
|
||||
# move to the next node
|
||||
hit_node[shortest_axis] += step[shortest_axis]
|
||||
ray_length[shortest_axis] += unit_step_size[shortest_axis]
|
||||
|
||||
if map_arr[hit_node[1]][hit_node[0]] > 0:
|
||||
#hit = True
|
||||
return True, None, None
|
||||
|
||||
|
||||
|
||||
# calculate direction in 3D assuming source is always 0.5 of the ground
|
||||
target_3d = np.append(target, 0.0)
|
||||
source_3d = np.append(source, 0.5)
|
||||
direction_3d = (target_3d - source_3d) / np.linalg.norm(target_3d - source_3d)
|
||||
|
||||
|
||||
return False, direction, direction_3d
|
||||
62
demos/beer_lambert_law_light_absorption.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import numpy as np
|
||||
import tkinter as tk
|
||||
|
||||
|
||||
#### CONFIG ####
|
||||
|
||||
rgb_color = (0.96, 0.0, 0.0)
|
||||
initial_rgb_power = (10, 10, 200)
|
||||
distance = 1
|
||||
density = 3
|
||||
|
||||
################
|
||||
|
||||
|
||||
def absorb(in_rgb_power, rgb_color, density, distance):
|
||||
in_rgb_power = np.array(in_rgb_power)
|
||||
rgb_color = np.array(rgb_color)
|
||||
|
||||
# Beer-Lambert Law
|
||||
coefficients = (rgb_color - 1) * density
|
||||
return in_rgb_power * np.exp(coefficients * distance)
|
||||
|
||||
final_rgb_power = absorb(initial_rgb_power, rgb_color, density, distance)
|
||||
|
||||
print("final rgb power (not gamma corrected): ", np.round(final_rgb_power, 4))
|
||||
|
||||
|
||||
## show final color
|
||||
|
||||
# gamma correction
|
||||
final_rgb_power = np.clip(final_rgb_power, 0, 255)
|
||||
final_rgb_power = final_rgb_power / 255.0
|
||||
final_rgb_power = np.power(final_rgb_power, 1.0 / 2.2)
|
||||
final_rgb_power = np.round(final_rgb_power * 255).astype(int)
|
||||
|
||||
initial_rgb_power = np.array(initial_rgb_power, dtype=np.float32) / 255.0
|
||||
initial_rgb_power = np.power(initial_rgb_power, 1.0 / 2.2)
|
||||
initial_rgb_power = np.round(initial_rgb_power * 255).astype(int)
|
||||
|
||||
rgb_color = np.power(rgb_color, 1.0 / 2.2)
|
||||
rgb_color = np.round(rgb_color * 255).astype(int)
|
||||
|
||||
#print(final_rgb_power)
|
||||
|
||||
root = tk.Tk()
|
||||
|
||||
canvas = tk.Canvas(root, width=500, height=500)
|
||||
canvas.pack()
|
||||
|
||||
# add rectangles
|
||||
canvas.create_rectangle(0, 0, 250, 250, fill='#%02x%02x%02x' % (*initial_rgb_power,))
|
||||
canvas.create_rectangle(250, 0, 500, 250, fill='#%02x%02x%02x' % (*rgb_color,))
|
||||
canvas.create_rectangle(0, 250, 500, 500, fill='#%02x%02x%02x' % (*final_rgb_power,))
|
||||
|
||||
# add text
|
||||
canvas.create_text(20, 20, text='source color', fill='white' if np.any(initial_rgb_power < 127) else 'black', anchor='w')
|
||||
canvas.create_text(270, 20, text='absorption color', fill='white' if np.any(rgb_color < 127) else 'black', anchor='w')
|
||||
canvas.create_text(20, 270, text='final color', fill='white' if np.any(final_rgb_power < 127) else 'black', anchor='w')
|
||||
|
||||
|
||||
|
||||
root.mainloop()
|
||||
BIN
demos/sky shader/cubemap.png
Normal file
|
After Width: | Height: | Size: 961 KiB |
4
demos/sky shader/info.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
Blender version: 4.1.1
|
||||
|
||||
cubemap.png generated on: https://tools.wwwtyro.net/space-3d/index.html
|
||||
seed: retertert
|
||||
BIN
demos/sky shader/sky shader v2.blend
Normal file
BIN
demos/sky shader/sky shader.blend
Normal file
136
docs/GUI.MD
Normal file
@@ -0,0 +1,136 @@
|
||||
|
||||
|
||||
GUI system concept
|
||||
==================
|
||||
|
||||
Objects
|
||||
-------
|
||||
|
||||
**div** - generic container with the following attributes, can act like a button:
|
||||
- `width`, `height`
|
||||
- `margin`
|
||||
- `padding`
|
||||
- `color`
|
||||
- `font_color`
|
||||
- `bordered`
|
||||
- `center_outside`
|
||||
- `center_inside`
|
||||
- `grid_horizontal_elems`
|
||||
- `on_tab`
|
||||
- `clickable_surface`
|
||||
- `z_extrusion`
|
||||
|
||||
**text** - generic text element with the following attributes:
|
||||
- `font_size`
|
||||
- `font_color`
|
||||
- `margin`
|
||||
- `center_outside`
|
||||
|
||||
**text_field** - just a text field with the following attributes:
|
||||
- `default_text`
|
||||
- `on_enter`
|
||||
- `on_tab`
|
||||
- `width`, `height`
|
||||
- `margin`
|
||||
- `padding`
|
||||
- `color`
|
||||
- `font_color`
|
||||
- `border`
|
||||
- `center_outside`
|
||||
- `center_inside`
|
||||
- `grid_horizontal_elems`
|
||||
- `z_extrusion`
|
||||
|
||||
**img** - image
|
||||
- `width`, `height`
|
||||
- `asset_name`
|
||||
- `margin`
|
||||
- `padding`
|
||||
- `font_color`
|
||||
- `border`
|
||||
- `center_outside`
|
||||
- `center_inside`
|
||||
- `color`
|
||||
- `grid_horizontal_elems`
|
||||
- `z_extrusion`
|
||||
|
||||
**dropdown** - dropdown menu with selectable elements
|
||||
- `text_objects`
|
||||
- `width`, `height`
|
||||
- `on_tab`
|
||||
- `margin`
|
||||
- `padding`
|
||||
- `color`
|
||||
- `font_color`
|
||||
- `font_size`
|
||||
- `border`
|
||||
- `center_outside`
|
||||
- `center_inside`
|
||||
- `z_extrusion`
|
||||
|
||||
**checkbox** - just a checkbox
|
||||
- `checkbox_size`
|
||||
- `on_tab`
|
||||
- `margin`
|
||||
- `color`
|
||||
- `check_color`
|
||||
- `border`
|
||||
- `center_outside`
|
||||
- `z_extrusion`
|
||||
|
||||
Attributes and Their Parameters
|
||||
-------------------------------
|
||||
|
||||
- `width`, `height`
|
||||
- % value relative to the parent element / auto
|
||||
|
||||
- `padding`, `margin`
|
||||
- % value relative to the parent element
|
||||
|
||||
- `default_text`
|
||||
- self-explanatory
|
||||
|
||||
- `color`, `font_color`
|
||||
- rgb / rgba / hex rgb / hex alpha + rgb color value
|
||||
- (alpha / hex alpha value for img exclusively)
|
||||
- sets the background color of the current element
|
||||
|
||||
- `border`
|
||||
- false / int (0 is interpreted as false)
|
||||
- disabled / border thickness value in pixels
|
||||
- final value = value * OS screen scaling
|
||||
|
||||
- `center_inside`
|
||||
- true / false
|
||||
- centers all child elements in a container
|
||||
|
||||
- `center_outside`
|
||||
- true / false
|
||||
- centers the element relative to the parent
|
||||
- acts like `center_inside` applied to the parent but only affecting the current element
|
||||
|
||||
- `grid_horizontal_elems`
|
||||
- int
|
||||
- defines how many elements can be horizontally in a grid before it forms a new row
|
||||
|
||||
- `font_size`
|
||||
- (unit unknown, depends on truetype)
|
||||
|
||||
- `on_enter`, `on_tab`
|
||||
- function
|
||||
- target action on specific key press when the element is active
|
||||
|
||||
- `clickable_surface`
|
||||
- true / false
|
||||
- makes the entire surface clickable instead of only the child elements' surfaces
|
||||
|
||||
- `text_objects`
|
||||
- list of text objects
|
||||
|
||||
- `z_extrusion`
|
||||
- "down" or "d" / "up" or "u" / false
|
||||
- creates a 3D extrusion effect in the desired direction if the element border is non-zero, like from Microsoft Windows 95/98 or Valve Source Engine GUI
|
||||
|
||||
- `checkbox_size`
|
||||
- int
|
||||
- size of the checkbox in pixels (gets multiplied by OS screen scaling)
|
||||
212
docs/INSTALL.MD
Normal file
@@ -0,0 +1,212 @@
|
||||
# Building PolyGun
|
||||
## `CMakeLists.txt` documentation
|
||||
`CMakeLists.txt` has following variables which can be customized to your needs
|
||||
(however if your configuration is pretty standard then everything should be detected automatically and nothing has to be set):
|
||||
- `BUILD_FLAG_SUPPRESS_WARNING_MODE`, if true compiling with highest warning mode will be omitted.
|
||||
- `BUILD_CLIENT`, if true client will be added to resulting executable.
|
||||
Please note that this will require all libraries which client depends on to be installed.
|
||||
- `BUILD_SERVER`, if true server will be added to resulting executable.
|
||||
If building multi-configuration executable (i.e. client and server) then server can be
|
||||
started from command line using `server` argument, example: `./polygun server`.
|
||||
If `BUILD_SERVER` is only configuration enabled then executable name will be changed to `polygun_server`.
|
||||
- `RENDERER_GL`, if true rendering with OpenGL support. This option is only valid if `BUILD_CLIENT` is enabled.
|
||||
By default enabled on every platform except Apple operating systems (i.e. macOS and iOS) and SerenityOS.
|
||||
- `RENDERER_LEGACY_GL`, if true rendering with OpenGL 1.x will be enabled. Only valid if `BUILD_CLIENT` is enabled.
|
||||
By default only enabled on SerenityOS. If your hardware/operating system supports OpenGL 2.0+ then use RENDERER_GL instead.
|
||||
- `WINDOW_WIN32`, if true window creation using Win32 API will be enabled. It's Windows only and enabled there by default.
|
||||
- `WINDOW_X11`, if true window creation using X11 will be enabled. It's only valid on Unix-like systems and is detected there automatically.
|
||||
- `WINDOW_WAYLAND`, if true window creation using Wayland will be enabled. It's only valid on Linux and is detected there automatically.
|
||||
- `WINDOW_SERENITYOS` if true window creation on SerenityOS will be supported.
|
||||
- `ENABLE_BACKTRACE_PRINTING` if true PolyGun will print backtrace after crash. It should be only used when building release executable, while developing use proper tools (GDB, AddressSanitizer etc).
|
||||
- `HAVE_STRSIGNAL`, if true `strsignal` from C library will be used, otherwise PolyGun will provide it's own
|
||||
implementation. Note that you shouldn't have to set this manually because it's automatically detected.
|
||||
- `X11_INCLUDE_DIR`, only valid if `WINDOW_X11` was set to `TRUE`, it's path to X11 headers. It should point to folder with `X11` directory.
|
||||
- `WaylandClient_INCLUDE_DIR`, only valid if `WINDOW_WAYLAND` was set to `TRUE`, it's path to libwayland-client headers.
|
||||
- `WaylandClient_LIBRARY`, only valid if `WINDOW_WAYLAND` was set to `TRUE`, it's path to libwayland-client library.
|
||||
- `WaylandEGL_INCLUDE_DIR`, only valid if `WINDOW_WAYLAND` and `RENDERER_GL` were set to `TRUE`, it's path to libwayland-egl headers.
|
||||
- `WaylandEGL_LIBRARY`, only valid if `WINDOW_WAYLAND` and `RENDERER_GL` were set to `TRUE`, it's path to libwayland-egl library.
|
||||
- `WaylandCursor_INCLUDE_DIR`, only valid if `WINDOW_WAYLAND` was set to `TRUE`, it's path to libwayland-cursor headers.
|
||||
- `WaylandCursor_LIBRARY`, only valid if `WINDOW_WAYLAND` was set to `TRUE`, it's path to libwayland-cursor library.
|
||||
- `Libdecor_INCLUDE_DIR`, only valid if `WINDOW_WAYLAND` was set to `TRUE`, it's path to libdecor headers.
|
||||
- `Libdecor_LIBRARY`, only valid if `WINDOW_WAYLAND` was set to `TRUE`, it's path to libdecor library.
|
||||
- `XKBCommon_INCLUDE_DIR`, path to XKBCommon headers. It should point to directory with `xkbcommon` folder.
|
||||
- `XKBCommon_LIBRARY`, path to XKBCommon library.
|
||||
- `OPENGL_INCLUDE_DIR`, path to OpenGL headers. It should point to folder which contains `GL` directory. You shouldn't have to set this because
|
||||
usually OpenGL is provided with C++ compiler.
|
||||
- `OPENGL_LIBRARIES`, path to OpenGL libraries separated by `;`. Similar to OpenGL headers you shouldn't have to set this manually.
|
||||
- `OPENAL_INCLUDE_DIR`, path to OpenAL headers. This should point to `AL` folder.
|
||||
- `OPENAL_LIBRARY`, path to OpenAL library, either static or shared.
|
||||
- `OGG_INCLUDE_DIR`, path to libogg headers. This should point to folder with `ogg` directory.
|
||||
- `OGG_LIBRARY`, path to libogg library, either static or shared.
|
||||
- `VORBIS_INCLUDE_DIR`, path to libvorbis headers. This should point to folder with `vorbis` directory.
|
||||
- `VORBIS_LIBRARY`, path to libvorbis library, either static or shared.
|
||||
- `PNG_INCLUDE_DIRS`, path to libpng headers. This should point to folder with `png.h` file.
|
||||
- `PNG_LIBRARIES`, path to libpng library, either static or shared.
|
||||
- `ZLIB_INCLUDE_DIRS`, path to zlib headers. This should point to folder with `deflate.h` file.
|
||||
- `ZLIB_LIBRARIES`, path to zlib library, either static or shared.
|
||||
|
||||
## Required libraries
|
||||
For `BUILD_CLIENT`:
|
||||
| Library | Description | Required for | Custom CMake variables |
|
||||
|----------------------------------------------------------------------------|--------------------------------|----------------------------------|------------------------------------------------------------|
|
||||
| OpenGL | Rendering via OpenGL api | `RENDERER_{LEGACY}_GL` | - `OPENGL_INCLUDE_DIR`<br>- `OPENGL_LIBRARIES` |
|
||||
| [Xlib](https://www.x.org/wiki) | Window creation using X11 | `WINDOW_X11` | - `X11_INCLUDE_DIR`<br>- `X11_LIBRARIES` |
|
||||
| [libwayland-client](https://wayland.freedesktop.org) | Window creation using Wayland | `WINDOW_WAYLAND` | - `WaylandClient_INCLUDE_DIR`<br>- `WaylandClient_LIBRARY` |
|
||||
| [libwayland-egl](https://wayland.freedesktop.org) | Using EGL with Wayland | `WINDOW_WAYLAND` + `RENDERER_GL` | - `WaylandEGL_INCLUDE_DIR`<br>- `WaylandClient_LIBRARY` |
|
||||
| [libwayland-cursor](https://wayland.freedesktop.org) | Cursor management for Wayland | `WINDOW_WAYLAND` | - `WaylandCursor_INCLUDE_DIR`<br>- `WaylandCursor_LIBRARY` |
|
||||
| [libdecor](https://gitlab.freedesktop.org/libdecor/libdecor) | Window management for Wayland | `WINDOW_WAYLAND` | - `Libdecor_INCLUDE_DIR`<br>- `Libdecor_LIBRARY` |
|
||||
| [XKBCommon](https://xkbcommon.org) | Text input handling | `WINDOW_WAYLAND` | - `XKBCommon_INCLUDE_DIR`<br>- `XKBCommon_LIBRARY` |
|
||||
| [OpenAL](https://www.openal.org) or [OpenAL Soft](https://openal-soft.org) | Playing sounds | *always* | - `OPENAL_INCLUDE_DIR`<br>- `OPENAL_LIBRARY` |
|
||||
| [libogg](https://www.xiph.org/ogg) | Loading Ogg files | *always* | - `OGG_INCLUDE_DIR`<br>- `OGG_LIBRARY` |
|
||||
| [libvorbis](https://www.xiph.org/vorbis) | Decoding Vorbis encoded audio | *always* | - `VORBIS_INCLUDE_DIR`<br>- `VORBIS_LIBRARY` |
|
||||
| [libpng](http://www.libpng.org/pub/png/libpng.html) | Loading PNG images | *always* | - `PNG_INCLUDE_DIRS`<br>- `PNG_LIBRARIES` |
|
||||
| [zlib](https://www.zlib.net) | libpng dependency | *always* | - `ZLIB_INCLUDE_DIRS`<br>- `ZLIB_LIBRARIES` |
|
||||
|
||||
For `BUILD_SERVER`:
|
||||
| Library | Description | Required for | Custom CMake variables |
|
||||
|------------------------------------------------------|-----------------------|-----------------------|------------------------|
|
||||
| [AngelScript](https://www.angelcode.com/angelscript) | server side scripting | *always* | *none* |
|
||||
|
||||
If we forgot to mention some library then please create issue.
|
||||
|
||||
## Building
|
||||
### GNU/Linux, Alpine Linux
|
||||
1. Install required tools if you don't have them (you can use Clang instead of g++ or Ninja instead of GNU Make if you like):
|
||||
- for Debian based distributions use: `sudo apt install g++ make cmake git` or `sudo apt install clang ninja-build cmake git`.
|
||||
- for Fedora use: `sudo dnf install gcc-c++ make cmake git` or `sudo dnf install clang ninja-build cmake git`.
|
||||
- for openSUSE use: `sudo zypper install --no-recommends g++ make cmake git` or `sudo zypper install --no-recommends clang ninja cmake git`.
|
||||
- for Alpine Linux use: `sudo apk add g++ make cmake git` or `sudo apk add clang ninja-build cmake git`.
|
||||
2. Clone repository with following command: `git clone https://git.cubesoftware.xyz/PolyGun/PolyGun.git`. You can add `--depth=1` argument
|
||||
to reduce used disk space via not downloading entire git history.
|
||||
3. Enter directory with downloaded PolyGun repository using `cd PolyGun`.
|
||||
4. Install required libraries. Libraries may vary depending on what build configuration you will use. This tutorial assumes full build with X11 windowing.
|
||||
- for Debian based distributions use: `sudo apt install libx11-dev libopenal-dev libvorbis-dev libpng-dev`. `libogg-dev` and `libzlib-dev` will be
|
||||
installed automatically because they are dependencies of `libvorbis-dev` and `libpng-dev` respectively.
|
||||
- for Fedora use: `sudo dnf install libX11-devel openal-soft-devel libogg-devel libvorbis-devel libpng-devel`. `libz-devel` will be installed automatically
|
||||
because it's dependency of `libpng-devel`.
|
||||
- for openSUSE use: `sudo zypper install libx11-dev libopenal-dev libogg libvorbis libpng`. `zlib` will be installed automatically because it's
|
||||
dependency of `libpng`
|
||||
- for Alpine Linux use: `sudo apk add libx11-dev openal-soft-dev libvorbis-dev libpng-dev`. `libogg-dev` and `zlib-dev` will be installed automatically
|
||||
because they are dependencies of `libvorbis-dev` and `libpng-dev` respectively.
|
||||
- (distribution agnositic) download and extract latest AngelScript source package to `external/angelscript` inside of repository root.
|
||||
5. Make build directory using `mkdir build`.
|
||||
6. Enter build directory using `cd build`.
|
||||
7. Generate build files using `cmake ..` or `cmake .. -G Ninja` if you are using Ninja build system. You may want to add additional arguments to CMake, see *`CMakeLists.txt` documentation* section.
|
||||
8. Build project using `make -j$(nproc)` or `ninja` depending on your selected build system.
|
||||
|
||||
### Windows with MSYS2
|
||||
1. Install all the required libs through pacman. (see MSYS2 dependencies below)
|
||||
2. Download and extract latest AngelScript source package to `external/angelscript` inside of repository root.
|
||||
3. Clone master and go into the root dir.
|
||||
4. Open MSYS2 MinGW64 terminal.
|
||||
5. Create build folder: `mkdir build` and enter it.
|
||||
6. Run `cmake .. -G"MSYS Makefiles"`
|
||||
7. Run `make -j[how many processors]`
|
||||
8. Make sure to add `C:\msys64\mingw64\bin` (or wherever your MSYS2 is installed) to PATH if you're getting missing dll errors.
|
||||
|
||||
### MSYS2 dependencies install commands
|
||||
```
|
||||
pacman -S mingw-w64-x86_64-openal
|
||||
pacman -S mingw-w64-x86_64-libogg
|
||||
pacman -S mingw-w64-x86_64-libvorbis
|
||||
pacman -S mingw-w64-x86_64-libpng
|
||||
pacman -S mingw-w64-x86_64-zlib
|
||||
```
|
||||
If we forgot to mention some library then please create issue.
|
||||
|
||||
### Windows with vcpkg and Visual Studio
|
||||
1. Install all the required libs through vcpkg. (see vcpkg dependencies below),
|
||||
2. Download and extract the latest AngelScript source package to external/angelscript inside of the repository root,
|
||||
3. Clone master and enter the root directory,
|
||||
4. Create a folder called 'build' in the root directory,
|
||||
5. Open CMakeLists.txt and add the following commands (see the commands below),
|
||||
6. Open CMake(cmake-gui) and enter valid paths for the building process,
|
||||
7. Enter the build folder and find a .sln file,
|
||||
8. Open the solution file and select the appropriate architecture,
|
||||
9. Starting compiling the Visual Studio project.
|
||||
|
||||
In case of any missing .dll files or unexpected errors while trying to open the .exe file:
|
||||
- Make sure you have all of the required .dll files in the same folder as the .exe,
|
||||
- Make sure the .dll files are the same architecture as the project was built in.
|
||||
|
||||
### CMakeLists.txt commands
|
||||
```
|
||||
SET(OPENAL_INCLUDE_DIR "your openAL include dir")
|
||||
SET(OPENAL_LIBRARY "your openAL .lib file dir")
|
||||
SET(OGG_INCLUDE_DIR "your ogg include dir (from libvorbis)")
|
||||
SET(VORBIS_INCLUDE_DIR "your vorbis include dir")
|
||||
SET(OGG_LIBRARY "your ogg .lib file dir")
|
||||
SET(VORBIS_LIBRARY "your vorbis .lib file dir")
|
||||
SET(PNG_PNG_INCLUDE_DIR "your libpng include dir")
|
||||
SET(PNG_LIBRARY "your libpng .lib file dir")
|
||||
SET(ZLIB_INCLUDE_DIR "your zlib.h file dir")
|
||||
SET(ZLIB_LIBRARY "your zlib.lib file dir")
|
||||
SET(BUILD_FLAG_SUPPRESS_WARNING_MODE ON CACHE BOOL "NO WARNINGS")
|
||||
```
|
||||
|
||||
### Vcpkg dependencies install commands
|
||||
```
|
||||
vcpkg install openal-soft
|
||||
vcpkg install libvorbis
|
||||
vcpkg install libpng
|
||||
vcpkg install zlib
|
||||
```
|
||||
### Specifying architecture
|
||||
```
|
||||
vcpkg install [package-name]:[your-architecture]-windows
|
||||
```
|
||||
|
||||
Inside of the square brackets provide the appropiarate information
|
||||
|
||||
### Windows with Cygwin
|
||||
1. Download Cygwin installer from [here](https://www.cygwin.com) and run it.
|
||||
2. Follow installation util package selection screen
|
||||
3. Select following programs (these are for 64-bit Windows, however you use any other architecture):
|
||||
`cmake`, `make`, `git`, `mingw64-x86_64-gcc-core`, `mingw64-x86_64-gcc-g++`
|
||||
4. Select following libraries (same as above, these are for 64-bit Windows):
|
||||
`mingw64-x86_64-libogg`, `mingw64-x86_64-libvorbis`, `mingw64-x86_64-libpng`,
|
||||
`mingw64-x86_64-openal`
|
||||
5. Open Cygwin terminal and change into desired directory
|
||||
6. Clone repository with following command: `git clone https://git.cubesoftware.xyz/PolyGun/PolyGun.git`. You can add `--depth=1` argument
|
||||
to reduce used disk space via not downloading entire git history.
|
||||
7. Download and extract latest AngelScript source package to `external/angelscript` inside of repository root.
|
||||
8. Enter directory with downloaded PolyGun repository using `cd PolyGun`.
|
||||
9. Make build directory using `mkdir build`.
|
||||
10. Enter build directory using `cd build`.
|
||||
11. Generate build files using `cmake ..`. You may want to add additional arguments to CMake, see *`CMakeLists.txt` documentation* section.
|
||||
12. Build project using `make -j$(nproc)`.
|
||||
|
||||
### FreeBSD
|
||||
1. Install required tools (you can use Ninja instead of GNU Make if you like): `sudo pkg install cmake gmake` or `sudo pkg install cmake ninja`.
|
||||
2. Clone repository with following command: `git clone https://git.cubesoftware.xyz/PolyGun/PolyGun.git`. You can add `--depth=1` argument
|
||||
to reduce used disk space via not downloading entire git history.
|
||||
3. Install required libraries. Libraries may vary depending on what build configuration you will use. This tutorial assumes full build.
|
||||
`sudo pkg install xorg-minimal openal-soft vorbis png`. `ogg` and `zlib` will be installed automatically because they
|
||||
are dependencies of `vorbis` and `png`
|
||||
4. Make build directory using `mkdir build`.
|
||||
5. Enter build directory using `cd build`.
|
||||
6. Generate build files using `cmake ..` or `cmake .. -G Ninja` if you are using Ninja build system. You may want to add additional arguments to CMake, see *`CMakeLists.txt` documentation* section.
|
||||
7. Build project using `gmake -j$(nproc)` or `ninja` depending on your selected build system.
|
||||
|
||||
### SerenityOS
|
||||
This documentation assumes full build (client and server).
|
||||
1. Install following ports: `gcc` (alternatively `clang`), `cmake`, `libopenal`, `libvorbis`, `libpng`, `git`.
|
||||
2. Clone repository with following command: `git clone http://git.cubesoftware.xyz:20524/PolyGun/PolyGun.git`. You can add `--depth=1` argument
|
||||
to reduce used disk space via not downloading entire git history.
|
||||
3. Enter directory with downloaded PolyGun repository using `cd PolyGun`.
|
||||
4. Download and extract latest AngelScript source package to `external/angelscript` inside of repository root.
|
||||
5. Make build directory using `mkdir build`.
|
||||
6. Enter build directory using `cd build`.
|
||||
7. Generate build files using `cmake ..`. You may want to add additional arguments to CMake, see *`CMakeLists.txt` documentation* section.
|
||||
8. Build project using `make -j$(nproc)`.
|
||||
|
||||
### Haiku
|
||||
1. Install required tools: `pkgman install cmake`.
|
||||
2. Clone repository with following command: `git clone https://git.cubesoftware.xyz/PolyGun/PolyGun.git`. You can add `--depth=1` argument
|
||||
to reduce used disk space via not downloading entire git history.
|
||||
3. Install required libraries. Libraries may vary depending on what build configuration you will use. This tutorial assumes full build.
|
||||
`pkgman install openal_devel vorbis_devel png_devel`. `ogg_devel` and `zlib_devel` will be installed automatically.
|
||||
4. Make build directory using `mkdir build`.
|
||||
5. Enter build directory using `cd build`.
|
||||
6. Generate build files using `cmake ..`.
|
||||
7. Build project using `make -j$(nproc)`.
|
||||
51
docs/MAP_FILE_FORMAT.MD
Normal file
@@ -0,0 +1,51 @@
|
||||
# Map file format
|
||||
## Overview
|
||||
Format is little endian. It has following structure:
|
||||
|Section |
|
||||
|-------------|
|
||||
|Header |
|
||||
|Chunks data |
|
||||
|Chunk headers|
|
||||
|
||||
Information about data types used in format:
|
||||
|Name |Description |
|
||||
|------------|-----------------------------------------------------|
|
||||
|char string |Unterminated non-prefixed static size array of bytes |
|
||||
|uint16 |Unsigned 16-bit integer |
|
||||
|uint32 |Unsigned 32-bit integer |
|
||||
|uint64 |Unsigned 64-bit integer |
|
||||
|
||||
## Header
|
||||
File header consists of following fields:
|
||||
|Name |Size (bytes) |Type |Offset |Remarks |
|
||||
|---------------------------|-------------|------------|----------|-------------------------------------------------------|
|
||||
|File magic |7 |char string |0 |It always has value `polymap` |
|
||||
|Format version number |2 |uint16 |7 |For development version `0xFFFF` number should be used |
|
||||
|Chunk count |4 |uint32 |9 | |
|
||||
|Chunk headers array offset |8 |uint64 |13 |Offset from beginning of file |
|
||||
|
||||
## Single chunk data entry
|
||||
Immediately after header chunk data array is located. Each entry has following structure:
|
||||
|Name |Size (bytes) |Type |Offset |Remarks |
|
||||
|------------------|----------------------|------------|----------|-----------------------------------------------|
|
||||
|Data |varying |uint8 array |0 |Compressed chunk data of size specified earlier|
|
||||
|
||||
## Single chunk header
|
||||
|Name |Size (bytes) |Type |Offset |Remarks |
|
||||
|------------------|---------------|------------|------------------|--------------------------------------------------|
|
||||
|Chunk X position |4 |int32 |0 | |
|
||||
|Chunk Y position |4 |int32 |4 | |
|
||||
|Chunk Z position |4 |int32 |8 | |
|
||||
|Compression mode |1 |uint8 |12 |See *Compression modes* for possible values |
|
||||
|Data size |2 |uint16 |13 |Size of compressed chunk data |
|
||||
|Data offset |8 |uint64 |15 |Offset of chunk data in *Chunk data* file section |
|
||||
|
||||
### Compression modes
|
||||
- `0`: No compression. Every node is stored using it's 16-bit ID
|
||||
- `1`: Efficient Huffman coding. Node count is stored first then node ID, however following encoding is used to
|
||||
decrease size: node count is stored in first 7 bits in byte. Last bit is used to denote if count spans to next byte,
|
||||
if this is a case then that bit is high (`1`), else it's low (`0`). Because there are only 7 bits available maximum
|
||||
value that can be stored is `127`. Situation repeats for next bytes if last bit was `1`. Same applies to node ID.
|
||||
- `2`: Fill. If chunk is filled with just one node type then the only thing that is stored is node ID as regular uint16.
|
||||
|
||||
Compression mode will be selected depending on which mode gives best result in particular case.
|
||||
203
docs/NETWORK_PROTOCOL.MD
Normal file
@@ -0,0 +1,203 @@
|
||||
# Network protocol
|
||||
PolyGun uses own UDP-based binary protocol with reliablity features. Usually port 1337 is used, obviously
|
||||
you can use any other.
|
||||
|
||||
## Data types
|
||||
| Name | Size in bytes | Description |
|
||||
|-----------|----------------------------|----------------------------------------|
|
||||
| uint8 | 1 | Unsigned 8-bit number |
|
||||
| uint16 | 2 | Unsigned 16-bit number |
|
||||
| uint32 | 4 | Unsigned 32-bit number |
|
||||
| float | 4 | Single precision floating point number |
|
||||
| string | varying (at least 2 bytes) | Prefixed (uint16 length) UTF-8 string |
|
||||
| vec3 | 12 | Vector with 3 float components |
|
||||
|
||||
## Packet flags
|
||||
Each packet may have none, one or more of these flags:
|
||||
| Name | Bitmask | Description |
|
||||
|-----------------|--------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `FLAG_RELIABLE` | `0b10000000` | It must be ensured that packet with this flag will be delivered and will arrive in correct order.<br>It's identified by unique 32-bit packet number. Receiving side must acknowledge sender that it was received via *ACK control packet* |
|
||||
|
||||
## Packet structure
|
||||
Packet structure may vary depending on *Packet flags* used.
|
||||
- Structure of packet without any flags:
|
||||
| Name | Type | Offset | Description |
|
||||
|--------------|-----------|--------|----------------------------------------|
|
||||
| Flags | uint8 | 0 | Must be zero |
|
||||
| Packet type | uint8 | 1 | See *Packet types* for possible values |
|
||||
| Data | *unknown* | 2 | Depends of Packet type |
|
||||
|
||||
- Structure of packet with `FLAG_RELIABLE`:
|
||||
| Name | Type | Offset | Description |
|
||||
|--------------|-----------|--------|--------------------------------------------------------------|
|
||||
| Flags | uint8 | 0 | Packet flag |
|
||||
| Packet num | uint32 | 1 | Unique ID of packet used to identifying and ordering packets |
|
||||
| Packet type | uint8 | 5 | See *Packet types* for possible values |
|
||||
| Data | *unknown* | 6 | Depends of Packet type |
|
||||
|
||||
## Packet types
|
||||
- `PACKET_HANDSHAKE` (to server), first packet that should be sent by client to server. Start connection initialization.
|
||||
| Name | Type | Offset | Description |
|
||||
|--------------|-----------|--------|--------------------------|
|
||||
| Nick | string | 0 | Nick specified by player |
|
||||
|
||||
- `PACKET_HANDSHAKE` (to client), server's response to handshake packet sent by client. Finalizes connection initialization.
|
||||
| Name | Type | Offset | Description |
|
||||
|--------------|-----------|--------|-----------------------------------|
|
||||
| UUID | uint32 | 0 | Player's UUID generated by server |
|
||||
| Node count | uint16 | 4 | Registered node count on server |
|
||||
| Player mode | uint8 | 6 | Mode that client should set |
|
||||
| Day time | uint16 | 7 | Current day time |
|
||||
|
||||
- `PACKET_TO_CLIENT_PLAYER_JOIN`, informs client that new player joined.
|
||||
| Name | Type | Offset | Description |
|
||||
|--------------|-----------|--------|-------------------|
|
||||
| UUID | uint32 | 0 | New player's UUID |
|
||||
| Nick | string | 4 | New player's nick |
|
||||
|
||||
- `PACKET_TO_CLIENT_PLAYER_INFO`, informs client about other players that are already on server. Sent immediately to new player by server after `PACKET_HANDSHAKE`.
|
||||
| Name | Type | Offset | Description |
|
||||
|----------------|-----------|--------|------------------------------------------------------|
|
||||
| Player count | uint8 | 0 | Player count on server excluding target client |
|
||||
| *Player* array | array | 1 | Array of *Player* objects with length *Player count* |
|
||||
|
||||
Player object
|
||||
| Name | Type | Offset | Description |
|
||||
|----------------|-----------|------------|--------------------------|
|
||||
| UUID | uint32 | 0 | Player's UUID |
|
||||
| Nick | string | 4 | Player's nick |
|
||||
| Position | vec3 | after Nick | Player's position |
|
||||
|
||||
- `PACKET_POSITION` (unreliable) (to server), sent by client to inform about player's position.
|
||||
| Name | Type | Offset | Description |
|
||||
|----------------|-----------|------------|--------------------------|
|
||||
| Position | vec3 | 0 | Player's position |
|
||||
|
||||
- `PACKET_POSITION (unreliable) (to client), sent by server to inform client about other player's new position.
|
||||
| Name | Type | Offset | Description |
|
||||
|----------------|-----------|------------|--------------------------|
|
||||
| UUID | uint32 | 0 | Player's UUID |
|
||||
| Position | vec3 | 4 | Player's position |
|
||||
|
||||
- `PACKET_ROTATE` (unreliable) (to server), sent by client to inform about player's rotation.
|
||||
| Name | Type | Offset | Description |
|
||||
|----------------|-----------|------------|--------------------------|
|
||||
| Rotation | float | 0 | Player's yaw |
|
||||
|
||||
- `PACKET_ROTATE (unreliable) (to client), sent by server to inform client about other player's new rotation.
|
||||
| Name | Type | Offset | Description |
|
||||
|----------------|-----------|------------|--------------------------|
|
||||
| UUID | uint32 | 0 | Player's UUID |
|
||||
| Rotation | float | 4 | Player's yaw |
|
||||
|
||||
- `PACKET_MESSAGE` (to server), sent by client when new chat message is entered.
|
||||
| Name | Type | Offset | Description |
|
||||
|----------------|-----------|------------|---------------------------|
|
||||
| Message | string | 0 | Message entered by player |
|
||||
|
||||
- `PACKET_MESSAGE` (to client), sent by server to propagate player's chat message.
|
||||
| Name | Type | Offset | Description |
|
||||
|----------------|-----------|--------------------------|--------------------------------------------------|
|
||||
| Type | uint8 | 0 | `0` - regular message<br>`1` - server message |
|
||||
| Sender name | string | 1 | Omitted if type is `1`. |
|
||||
| Message | string | 1 or after *Sender name* | Message entered by player/Message sent by server |
|
||||
|
||||
- `PACKET_CHUNK` (to server), sent by client to request chunk data.
|
||||
| Name | Type | Offset |
|
||||
|------------------|-----------|------------|
|
||||
| Chunk X position | int32 | 0 |
|
||||
| Chunk Y position | int32 | 4 |
|
||||
| Chunk Z position | int32 | 8 |
|
||||
|
||||
- `PACKET_CHUNK` (to client), response to `PACKET_CHUNK` (to server).
|
||||
| Name | Type | Offset | Description |
|
||||
|----------------------------|-----------|------------|----------------------------------------------------------------------------------------------|
|
||||
| Chunk X position | int32 | 0 | |
|
||||
| Chunk Y position | int32 | 4 | |
|
||||
| Chunk Z position | int32 | 8 | |
|
||||
| Chunk compression mode | uint8 | 13 | See *Compression modes* in [docs/MAP_FILE_FORMAT.MD](MAP_FILE_FORMAT.MD) for possible values |
|
||||
| Compressed chunk data size | uint32 | 14 | |
|
||||
| Compressed chunk data | array | 18 | Array of *uint8* with size *Compressed chunk data size* |
|
||||
|
||||
- `PACKET_TO_CLIENT_INVALIDATE_MAP`, sent by server to inform client about map change.
|
||||
*empty*
|
||||
|
||||
- `PACKET_NODE_CHANGE` (same for client and server), sent when player changes node.
|
||||
| Name | Type | Offset | Description |
|
||||
|------------------|-----------|------------|------------------|
|
||||
| Position | vec3 | 0 | Node position |
|
||||
| Node ID | uint16 | 12 | New node ID |
|
||||
|
||||
- `PACKET_NODE_FILL` (same for client and server), sent when player fills area with node.
|
||||
| Name | Type | Offset | Description |
|
||||
|------------------|-----------|------------|------------------|
|
||||
| From | vec3 | 0 | Starting point |
|
||||
| To | vec3 | 12 | Ending point |
|
||||
| Node ID | uint16 | 24 | Filled node ID |
|
||||
|
||||
- `PACKET_SYNC` (to server), sent by clients in order to synchronize game state.
|
||||
*empty*
|
||||
|
||||
- `PACKET_SYNC` (to client), response to `PACKET_SYNC` (to server).
|
||||
| Name | Type | Offset | Description |
|
||||
|------------------|-----------|------------|------------------|
|
||||
| Day time | uint16 | 0 | Current day time |
|
||||
|
||||
- `PACKET_TO_CLIENT_PLAYER_MODE`, sent when server changes player's mode.
|
||||
| Name | Type | Offset | Description |
|
||||
|------------------|-----------|------------|--------------------------------|
|
||||
| UUID | uint32 | 0 | Player's UUID |
|
||||
| Mode | uint8 | 4 | `0` - normal<br>`1` - editmode |
|
||||
|
||||
- `PACKET_NODE_DEFINITION` (to server), sent by client to request node definition.
|
||||
| Name | Type | Offset | Description |
|
||||
|----------------|-----------|------------|--------------------------|
|
||||
| Node ID | uint16 | 0 | Numerical node ID |
|
||||
|
||||
- `PACKET_NODE_DEFINITION` (to client), response to `PACKET_NODE_DEFINITION` (to server).
|
||||
| Name | Type | Offset | Description |
|
||||
|------------------------|-----------|------------|--------------------------------------------------------------------------------|
|
||||
| Node ID | uint16 | 0 | Numerical node ID |
|
||||
| Node string ID | string | 2 | Node string ID in form of `namespace:name` |
|
||||
| Node texture | string | +0 | Texture ID to render on all faces in form of `<modname>/texture/<texturename>` |
|
||||
| Node display icon | string | +0 | ID of texture which will be displayed in GUI |
|
||||
| Node top texture ID | string | +0 | Texture ID to render on top face |
|
||||
| Node bottom texture ID | string | +0 | Texture ID to render on bottom face |
|
||||
| Node left texture ID | string | +0 | Texture ID to render on left face |
|
||||
| Node right texture ID | string | +0 | Texture ID to render on right face |
|
||||
| Node front texture ID | string | +0 | Texture ID to render on front face |
|
||||
| Node back texture ID | string | +0 | Texture ID to render on back face |
|
||||
|
||||
- `PACKET_RESOURCE` (to server), sent by client to request resource data.
|
||||
| Name | Type | Offset | Description |
|
||||
|----------------|-----------|------------|-----------------------------------------------------------------|
|
||||
| Resource ID | string | 0 | String resource ID in form of `<modname>/texture/<texturename>` |
|
||||
|
||||
- `PACKET_RESOURCE` (to client), response to `PACKET_RESOURCE` (to server).
|
||||
| Name | Type | Offset | Description |
|
||||
|--------------------|-----------|------------|-------------------------------------------------|
|
||||
| Resource ID | string | 0 | String resource ID |
|
||||
| Resource data size | uint32 | +0 | |
|
||||
| Resource data | array | +4 | Array of *uint8* with size *Resource data size* |
|
||||
|
||||
- `PACKET_EXIT` (to server), sent by client while exiting server.
|
||||
**no additional data**
|
||||
|
||||
- `PACKET_EXIT` (to client), sent by server to inform that other player left.
|
||||
| Name | Type | Offset | Description |
|
||||
|----------------|-----------|------------|-------------------------------------------------------------|
|
||||
| Player UUID | uint32 | 0 | Other player's UUID |
|
||||
| Reason | uint8 | 4 | Leave reason ID. For possible values see *Leave reason IDs* |
|
||||
Leave reason IDs:
|
||||
- `0`: Player disconnected
|
||||
- `1`: Timeout
|
||||
|
||||
- `PACKET_ACK`, sent either by client or server to inform that reliable packet with certain number was received.
|
||||
Please note that `PACKET_ACK` must be sent without any packet flags.
|
||||
| Name | Type | Offset | Description |
|
||||
|----------------|-----------|------------|-------------------------------------|
|
||||
| Packet number | uint32 | 0 | Number of packet which was received |
|
||||
|
||||
- `PACKET_ACTIVITY`, sent by client and server to inform each side that connection wasn't interrupted.
|
||||
Please note that `PACKET_ACTIVITY` must be sent without any packet flags.
|
||||
**no additional data**
|
||||
153
locale/pl.xml
Normal file
@@ -0,0 +1,153 @@
|
||||
<!--
|
||||
Polygun locale
|
||||
Language: PL
|
||||
Last translator: mrkubax10 <mrkubax10@onet.pl>
|
||||
-->
|
||||
|
||||
<locale>
|
||||
<!-- src/game/screens/game_session_screen.cpp:284 -->
|
||||
<tr>
|
||||
<msgid>Place Block</msgid>
|
||||
<msgstr>Postaw blok</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:216 -->
|
||||
<tr>
|
||||
<msgid>Joining server</msgid>
|
||||
<msgstr>Dołączanie do serwera</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:217 -->
|
||||
<tr>
|
||||
<msgid>Joining server @ polygun://%s:%d...</msgid>
|
||||
<msgstr>Dołączanie do serwera polygun://%s:%d...</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:225 -->
|
||||
<tr>
|
||||
<msgid>Connect to server</msgid>
|
||||
<msgstr>Łączenie z serwerem</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:225 -->
|
||||
<tr>
|
||||
<msgid>Failed to connect to polygun://</msgid>
|
||||
<msgstr>Nie można połączyć się z polygun://</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:228 -->
|
||||
<tr>
|
||||
<msgid>Connection timed out</msgid>
|
||||
<msgstr>Upłynął czas połączenia</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:228 -->
|
||||
<tr>
|
||||
<msgid>Lost connection with polygun://</msgid>
|
||||
<msgstr>Utracono połączenie z polygun://</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:260 -->
|
||||
<tr>
|
||||
<msgid>Debug</msgid>
|
||||
<msgstr>Debugowanie</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:269 -->
|
||||
<tr>
|
||||
<msgid>Framerate</msgid>
|
||||
<msgstr>Czas klatek</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:271 -->
|
||||
<tr>
|
||||
<msgid>Averaging at %.3f ms/frame (%.1f FPS)</msgid>
|
||||
<msgstr>Średnia aplikacji %.3f ms/klatkę (%.1f klatek na sekundę)</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:273 -->
|
||||
<tr>
|
||||
<msgid>Player position: %.3f, %.3f, %.3f</msgid>
|
||||
<msgstr>Pozycja gracza: %.3f, %.3f, %.3f</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp: 275 -->
|
||||
<tr>
|
||||
<msgid>Player rotation: %.3f, %.3f, %.3f</msgid>
|
||||
<msgstr>Obrót gracza: %.3f, %.3f, %.3f</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:276 -->
|
||||
<tr>
|
||||
<msgid>ID</msgid>
|
||||
<msgstr>Identyfikator</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:277 -->
|
||||
<tr>
|
||||
<msgid>X</msgid>
|
||||
<msgstr>X</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:278 -->
|
||||
<tr>
|
||||
<msgid>Y</msgid>
|
||||
<msgstr>Y</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:279 -->
|
||||
<tr>
|
||||
<msgid>Z</msgid>
|
||||
<msgstr>Z</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:282 -->
|
||||
<tr>
|
||||
<msgid>FoV</msgid>
|
||||
<msgstr>Pole widzenia</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:289 -->
|
||||
<tr>
|
||||
<msgid>Quit game</msgid>
|
||||
<msgstr>Wyjdź z gry</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:308 -->
|
||||
<tr>
|
||||
<msgid>Clear color</msgid>
|
||||
<msgstr>Kolor czyszczenia</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/game_session_screen.cpp:483 -->
|
||||
<tr>
|
||||
<msgid>OK</msgid>
|
||||
<msgstr>OK</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/main_menu_screen.cpp:56 -->
|
||||
<tr>
|
||||
<msgid>Temporary main menu</msgid>
|
||||
<msgstr>Tymczasowe menu główne</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/main_menu_screen.cpp:62 -->
|
||||
<tr>
|
||||
<msgid>Nickname</msgid>
|
||||
<msgstr>Pseudonim</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/main_menu_screen.cpp:65 -->
|
||||
<tr>
|
||||
<msgid>Multi-player mode</msgid>
|
||||
<msgstr>Tryb wieloosobowy</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/main_menu_screen.cpp:66 -->
|
||||
<tr>
|
||||
<msgid>Server address</msgid>
|
||||
<msgstr>Adres serwera</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/main_menu_screen.cpp:67 -->
|
||||
<tr>
|
||||
<msgid>Server port</msgid>
|
||||
<msgstr>Port serwera</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/main_menu_screen.cpp:68 -->
|
||||
<tr>
|
||||
<msgid>Connect</msgid>
|
||||
<msgstr>Połącz</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/main_menu_screen.cpp:75 -->
|
||||
<tr>
|
||||
<msgid>Host game</msgid>
|
||||
<msgstr>Hostuj grę</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/main_menu_screen.cpp:78 -->
|
||||
<tr>
|
||||
<msgid>Host</msgid>
|
||||
<msgstr>Hostuj</msgstr>
|
||||
</tr>
|
||||
<!-- src/game/screens/main_menu_screen.cpp:85 -->
|
||||
<tr>
|
||||
<msgid>Cannot host (server not built)</msgid>
|
||||
<msgstr>Nie mozna uruchomic serwera (serwer nie zbudowany)</msgstr>
|
||||
</tr>
|
||||
</locale>
|
||||
31
mk/cmake/FindLibdecor.cmake
Normal file
@@ -0,0 +1,31 @@
|
||||
find_path(
|
||||
Libdecor_INCLUDE_DIR
|
||||
NAMES libdecor.h libdecor-0/libdecor.h
|
||||
)
|
||||
|
||||
find_library(
|
||||
Libdecor_LIBRARY
|
||||
NAMES libdecor libdecor-0 decor-0 decor
|
||||
)
|
||||
|
||||
if(Libdecor_INCLUDE_DIR AND Libdecor_LIBRARY)
|
||||
add_library(libdecor UNKNOWN IMPORTED)
|
||||
|
||||
set_target_properties(
|
||||
libdecor PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${Libdecor_INCLUDE_DIR}"
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${Libdecor_LIBRARY}"
|
||||
)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(
|
||||
Libdecor
|
||||
REQUIRED_VARS Libdecor_LIBRARY Libdecor_INCLUDE_DIR
|
||||
)
|
||||
|
||||
mark_as_advanced(
|
||||
Libdecor_INCLUDE_DIR
|
||||
Libdecor_LIBRARY
|
||||
)
|
||||
186
mk/cmake/FindOggVorbis.cmake
Normal file
@@ -0,0 +1,186 @@
|
||||
# Taken from https://github.com/sidch/CMake/blob/main/Modules/FindOggVorbis.cmake
|
||||
# - Try to find the OggVorbis libraries
|
||||
# Once done this will define
|
||||
#
|
||||
# OGGVORBIS_FOUND - system has OggVorbis (i.e. it has the Ogg and Vorbis headers, as well as libogg and libvorbis)
|
||||
# OGGVORBIS_VERSION - set either to 1 or 2
|
||||
# OGGVORBIS_INCLUDE_DIRS - the Ogg and Vorbis include directories
|
||||
# OGG_INCLUDE_DIR - the Ogg include directory
|
||||
# VORBIS_INCLUDE_DIR - the Vorbis include directory
|
||||
# OGGVORBIS_LIBRARIES - The libraries needed to use OggVorbis
|
||||
# OGG_LIBRARY - The Ogg library
|
||||
# VORBIS_LIBRARY - The Vorbis library
|
||||
# VORBISFILE_LIBRARY - The VorbisFile library (optional)
|
||||
# VORBISENC_LIBRARY - The VorbisEnc library (optional)
|
||||
#
|
||||
# To specify an additional directory to search for Ogg, set Ogg_ROOT.
|
||||
# To specify an additional directory to search for Vorbis, set Vorbis_ROOT.
|
||||
#
|
||||
# Copyright (c) 2006, Richard Laerkaeng, <richard@goteborg.utfors.se>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
#
|
||||
# (Copied and slightly modified from the KDE project)
|
||||
#
|
||||
|
||||
INCLUDE(CheckLibraryExists)
|
||||
|
||||
FIND_PATH(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h PATHS ${Vorbis_ROOT} ${Vorbis_ROOT}/include NO_DEFAULT_PATH)
|
||||
IF(NOT VORBIS_INCLUDE_DIR)
|
||||
FIND_PATH(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h)
|
||||
ENDIF(NOT VORBIS_INCLUDE_DIR)
|
||||
|
||||
FIND_PATH(OGG_INCLUDE_DIR ogg/ogg.h PATHS ${Ogg_ROOT} ${Ogg_ROOT}/include NO_DEFAULT_PATH)
|
||||
IF(NOT OGG_INCLUDE_DIR)
|
||||
FIND_PATH(OGG_INCLUDE_DIR ogg/ogg.h)
|
||||
ENDIF(NOT OGG_INCLUDE_DIR)
|
||||
|
||||
# Debug libraries
|
||||
FIND_LIBRARY(OGG_DEBUG_LIBRARY NAMES oggd ogg_d liboggd libogg_d PATH_SUFFIXES "" Debug
|
||||
PATHS ${Ogg_ROOT} ${Ogg_ROOT}/lib NO_DEFAULT_PATH)
|
||||
IF(NOT OGG_DEBUG_LIBRARY) # now look in system locations
|
||||
FIND_LIBRARY(OGG_DEBUG_LIBRARY NAMES oggd ogg_d liboggd libogg_d PATH_SUFFIXES "" Debug)
|
||||
ENDIF(NOT OGG_DEBUG_LIBRARY)
|
||||
|
||||
FIND_LIBRARY(VORBIS_DEBUG_LIBRARY NAMES vorbisd vorbis_d libvorbisd libvorbis_d PATH_SUFFIXES "" Debug
|
||||
PATHS ${Vorbis_ROOT} ${Vorbis_ROOT}/lib NO_DEFAULT_PATH)
|
||||
IF(NOT VORBIS_DEBUG_LIBRARY) # now look in system locations
|
||||
FIND_LIBRARY(VORBIS_DEBUG_LIBRARY NAMES vorbisd vorbis_d libvorbisd libvorbis_d PATH_SUFFIXES "" Debug)
|
||||
ENDIF(NOT VORBIS_DEBUG_LIBRARY)
|
||||
|
||||
FIND_LIBRARY(VORBISFILE_DEBUG_LIBRARY NAMES vorbisfiled vorbisfile_d libvorbisfiled libvorbisfile_d PATH_SUFFIXES "" Debug
|
||||
PATHS ${Vorbis_ROOT} ${Vorbis_ROOT}/lib NO_DEFAULT_PATH)
|
||||
IF(NOT VORBISFILE_DEBUG_LIBRARY) # now look in system locations
|
||||
FIND_LIBRARY(VORBISFILE_DEBUG_LIBRARY NAMES vorbisfiled vorbisfile_d libvorbisfiled libvorbisfile_d PATH_SUFFIXES "" Debug)
|
||||
ENDIF(NOT VORBISFILE_DEBUG_LIBRARY)
|
||||
|
||||
FIND_LIBRARY(VORBISENC_DEBUG_LIBRARY NAMES vorbisencd vorbisenc_d libvorbisencd libvorbisenc_d PATH_SUFFIXES "" Debug
|
||||
PATHS ${Vorbis_ROOT} ${Vorbis_ROOT}/lib NO_DEFAULT_PATH)
|
||||
IF(NOT VORBISENC_DEBUG_LIBRARY) # now look in system locations
|
||||
FIND_LIBRARY(VORBISENC_DEBUG_LIBRARY NAMES vorbisencd vorbisenc_d libvorbisencd libvorbisenc_d PATH_SUFFIXES "" Debug)
|
||||
ENDIF(NOT VORBISENC_DEBUG_LIBRARY)
|
||||
|
||||
|
||||
# Release libraries
|
||||
FIND_LIBRARY(OGG_RELEASE_LIBRARY NAMES ogg libogg PATH_SUFFIXES "" Release
|
||||
PATHS ${Ogg_ROOT} ${Ogg_ROOT}/lib NO_DEFAULT_PATH)
|
||||
IF(NOT OGG_RELEASE_LIBRARY) # now look in system locations
|
||||
FIND_LIBRARY(OGG_RELEASE_LIBRARY NAMES ogg libogg PATH_SUFFIXES "" Release)
|
||||
ENDIF(NOT OGG_RELEASE_LIBRARY)
|
||||
|
||||
FIND_LIBRARY(VORBIS_RELEASE_LIBRARY NAMES vorbis libvorbis PATH_SUFFIXES "" Release
|
||||
PATHS ${Vorbis_ROOT} ${Vorbis_ROOT}/lib NO_DEFAULT_PATH)
|
||||
IF(NOT VORBIS_RELEASE_LIBRARY) # now look in system locations
|
||||
FIND_LIBRARY(VORBIS_RELEASE_LIBRARY NAMES vorbis libvorbis PATH_SUFFIXES "" Release)
|
||||
ENDIF(NOT VORBIS_RELEASE_LIBRARY)
|
||||
|
||||
FIND_LIBRARY(VORBISFILE_RELEASE_LIBRARY NAMES vorbisfile libvorbisfile PATH_SUFFIXES "" Release
|
||||
PATHS ${Vorbis_ROOT} ${Vorbis_ROOT}/lib NO_DEFAULT_PATH)
|
||||
IF(NOT VORBISFILE_RELEASE_LIBRARY) # now look in system locations
|
||||
FIND_LIBRARY(VORBISFILE_RELEASE_LIBRARY NAMES vorbisfile libvorbisfile PATH_SUFFIXES "" Release)
|
||||
ENDIF(NOT VORBISFILE_RELEASE_LIBRARY)
|
||||
|
||||
FIND_LIBRARY(VORBISENC_RELEASE_LIBRARY NAMES vorbisenc libvorbisenc PATH_SUFFIXES "" Release
|
||||
PATHS ${Vorbis_ROOT} ${Vorbis_ROOT}/lib NO_DEFAULT_PATH)
|
||||
IF(NOT VORBISENC_RELEASE_LIBRARY) # now look in system locations
|
||||
FIND_LIBRARY(VORBISENC_RELEASE_LIBRARY NAMES vorbisenc libvorbisenc PATH_SUFFIXES "" Release)
|
||||
ENDIF(NOT VORBISENC_RELEASE_LIBRARY)
|
||||
|
||||
|
||||
SET(OGG_LIBRARY)
|
||||
IF(OGG_DEBUG_LIBRARY AND OGG_RELEASE_LIBRARY)
|
||||
SET(OGG_LIBRARY debug ${OGG_DEBUG_LIBRARY} optimized ${OGG_RELEASE_LIBRARY})
|
||||
ELSEIF(OGG_DEBUG_LIBRARY)
|
||||
SET(OGG_LIBRARY ${OGG_DEBUG_LIBRARY})
|
||||
ELSEIF(OGG_RELEASE_LIBRARY)
|
||||
SET(OGG_LIBRARY ${OGG_RELEASE_LIBRARY})
|
||||
ENDIF(OGG_DEBUG_LIBRARY AND OGG_RELEASE_LIBRARY)
|
||||
|
||||
SET(VORBIS_LIBRARY)
|
||||
IF(VORBIS_DEBUG_LIBRARY AND VORBIS_RELEASE_LIBRARY)
|
||||
SET(VORBIS_LIBRARY debug ${VORBIS_DEBUG_LIBRARY} optimized ${VORBIS_RELEASE_LIBRARY})
|
||||
ELSEIF(VORBIS_DEBUG_LIBRARY)
|
||||
SET(VORBIS_LIBRARY ${VORBIS_DEBUG_LIBRARY})
|
||||
ELSEIF(VORBIS_RELEASE_LIBRARY)
|
||||
SET(VORBIS_LIBRARY ${VORBIS_RELEASE_LIBRARY})
|
||||
ENDIF(VORBIS_DEBUG_LIBRARY AND VORBIS_RELEASE_LIBRARY)
|
||||
|
||||
SET(VORBISFILE_LIBRARY)
|
||||
IF(VORBISFILE_DEBUG_LIBRARY AND VORBISFILE_RELEASE_LIBRARY)
|
||||
SET(VORBISFILE_LIBRARY debug ${VORBISFILE_DEBUG_LIBRARY} optimized ${VORBISFILE_RELEASE_LIBRARY})
|
||||
ELSEIF(VORBISFILE_DEBUG_LIBRARY)
|
||||
SET(VORBISFILE_LIBRARY ${VORBISFILE_DEBUG_LIBRARY})
|
||||
ELSEIF(VORBISFILE_RELEASE_LIBRARY)
|
||||
SET(VORBISFILE_LIBRARY ${VORBISFILE_RELEASE_LIBRARY})
|
||||
ENDIF(VORBISFILE_DEBUG_LIBRARY AND VORBISFILE_RELEASE_LIBRARY)
|
||||
|
||||
SET(VORBISENC_LIBRARY)
|
||||
IF(VORBISENC_DEBUG_LIBRARY AND VORBISENC_RELEASE_LIBRARY)
|
||||
SET(VORBISENC_LIBRARY debug ${VORBISENC_DEBUG_LIBRARY} optimized ${VORBISENC_RELEASE_LIBRARY})
|
||||
ELSEIF(VORBISENC_DEBUG_LIBRARY)
|
||||
SET(VORBISENC_LIBRARY ${VORBISENC_DEBUG_LIBRARY})
|
||||
ELSEIF(VORBISENC_RELEASE_LIBRARY)
|
||||
SET(VORBISENC_LIBRARY ${VORBISENC_RELEASE_LIBRARY})
|
||||
ENDIF(VORBISENC_DEBUG_LIBRARY AND VORBISENC_RELEASE_LIBRARY)
|
||||
|
||||
# Should the check also test for the OGG... variables?
|
||||
IF(OGG_INCLUDE_DIR AND VORBIS_INCLUDE_DIR AND OGG_LIBRARY AND VORBIS_LIBRARY)
|
||||
SET(OGGVORBIS_FOUND TRUE)
|
||||
|
||||
SET(OGGVORBIS_INCLUDE_DIRS ${OGG_INCLUDE_DIR} ${VORBIS_INCLUDE_DIR})
|
||||
SET(OGGVORBIS_LIBRARIES ${OGG_LIBRARY} ${VORBIS_LIBRARY} ${VORBISFILE_LIBRARY} ${VORBISENC_LIBRARY})
|
||||
|
||||
IF(NOT WIN32) # not quite sure what to do on Windows yet
|
||||
SET(_CMAKE_REQUIRED_LIBRARIES_TMP ${CMAKE_REQUIRED_LIBRARIES})
|
||||
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${OGGVORBIS_LIBRARIES})
|
||||
CHECK_LIBRARY_EXISTS(vorbis vorbis_bitrate_addblock "" HAVE_LIBVORBISENC2)
|
||||
SET(CMAKE_REQUIRED_LIBRARIES ${_CMAKE_REQUIRED_LIBRARIES_TMP})
|
||||
|
||||
IF(HAVE_LIBVORBISENC2)
|
||||
SET(OGGVORBIS_VERSION 2)
|
||||
ELSE(HAVE_LIBVORBISENC2)
|
||||
SET(OGGVORBIS_VERSION 1)
|
||||
ENDIF(HAVE_LIBVORBISENC2)
|
||||
ENDIF(NOT WIN32)
|
||||
|
||||
ELSE(OGG_INCLUDE_DIR AND VORBIS_INCLUDE_DIR AND OGG_LIBRARY AND VORBIS_LIBRARY)
|
||||
SET(OGGVORBIS_VERSION)
|
||||
SET(OGGVORBIS_FOUND FALSE)
|
||||
ENDIF(OGG_INCLUDE_DIR AND VORBIS_INCLUDE_DIR AND OGG_LIBRARY AND VORBIS_LIBRARY)
|
||||
|
||||
|
||||
IF(OGGVORBIS_FOUND)
|
||||
IF(NOT OggVorbis_FIND_QUIETLY)
|
||||
MESSAGE(STATUS "Found OggVorbis: ${OGGVORBIS_LIBRARIES}")
|
||||
ENDIF(NOT OggVorbis_FIND_QUIETLY)
|
||||
ELSE(OGGVORBIS_FOUND)
|
||||
IF(OggVorbis_FIND_REQUIRED)
|
||||
MESSAGE(FATAL_ERROR "Could not find OggVorbis libraries")
|
||||
ENDIF(OggVorbis_FIND_REQUIRED)
|
||||
IF(NOT OggVorbis_FIND_QUITELY)
|
||||
MESSAGE(STATUS "Could not find OggVorbis libraries")
|
||||
ENDIF(NOT OggVorbis_FIND_QUITELY)
|
||||
ENDIF(OGGVORBIS_FOUND)
|
||||
|
||||
#CHECK_INCLUDE_FILES(vorbis/vorbisfile.h HAVE_VORBISFILE_H)
|
||||
#CHECK_LIBRARY_EXISTS(ogg ogg_page_version "" HAVE_LIBOGG)
|
||||
#CHECK_LIBRARY_EXISTS(vorbis vorbis_info_init "" HAVE_LIBVORBIS)
|
||||
#CHECK_LIBRARY_EXISTS(vorbisfile ov_open "" HAVE_LIBVORBISFILE)
|
||||
#CHECK_LIBRARY_EXISTS(vorbisenc vorbis_info_clear "" HAVE_LIBVORBISENC)
|
||||
#CHECK_LIBRARY_EXISTS(vorbis vorbis_bitrate_addblock "" HAVE_LIBVORBISENC2)
|
||||
|
||||
#IF(HAVE_LIBOGG AND HAVE_VORBISFILE_H AND HAVE_LIBVORBIS AND HAVE_LIBVORBISFILE AND HAVE_LIBVORBISENC)
|
||||
# MESSAGE(STATUS "Ogg/Vorbis found")
|
||||
# SET(VORBIS_LIBS "-lvorbis -logg")
|
||||
# SET(VORBISFILE_LIBS "-lvorbisfile")
|
||||
# SET(VORBISENC_LIBS "-lvorbisenc")
|
||||
# SET(OGGVORBIS_FOUND TRUE)
|
||||
# IF(HAVE_LIBVORBISENC2)
|
||||
# SET(HAVE_VORBIS 2)
|
||||
# ELSE(HAVE_LIBVORBISENC2)
|
||||
# SET(HAVE_VORBIS 1)
|
||||
# ENDIF(HAVE_LIBVORBISENC2)
|
||||
#ELSE(HAVE_LIBOGG AND HAVE_VORBISFILE_H AND HAVE_LIBVORBIS AND HAVE_LIBVORBISFILE AND HAVE_LIBVORBISENC)
|
||||
# MESSAGE(STATUS "Ogg/Vorbis not found")
|
||||
#ENDIF(HAVE_LIBOGG AND HAVE_VORBISFILE_H AND HAVE_LIBVORBIS AND HAVE_LIBVORBISFILE AND HAVE_LIBVORBISENC)
|
||||
35
mk/cmake/FindWaylandClient.cmake
Normal file
@@ -0,0 +1,35 @@
|
||||
find_path(
|
||||
WaylandClient_INCLUDE_DIR
|
||||
NAMES wayland-client.h
|
||||
)
|
||||
|
||||
find_library(
|
||||
WaylandClient_LIBRARY
|
||||
NAMES wayland-client libwayland-client
|
||||
)
|
||||
|
||||
if(WaylandClient_INCLUDE_DIR AND WaylandClient_LIBRARY)
|
||||
add_library(wayland::client UNKNOWN IMPORTED)
|
||||
|
||||
set_target_properties(
|
||||
wayland::client PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${WaylandClient_INCLUDE_DIR}"
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${WaylandClient_LIBRARY}"
|
||||
)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(
|
||||
WaylandClient
|
||||
REQUIRED_VARS WaylandClient_LIBRARY WaylandClient_INCLUDE_DIR
|
||||
)
|
||||
|
||||
mark_as_advanced(
|
||||
WaylandClient_INCLUDE_DIR
|
||||
WaylandClient_LIBRARY
|
||||
)
|
||||
|
||||
if(WaylandClient_FOUND)
|
||||
message(STATUS "Found WaylandClient: ${WaylandClient_LIBRARY}")
|
||||
endif()
|
||||
31
mk/cmake/FindWaylandCursor.cmake
Normal file
@@ -0,0 +1,31 @@
|
||||
find_path(
|
||||
WaylandCursor_INCLUDE_DIR
|
||||
NAMES wayland-cursor.h
|
||||
)
|
||||
|
||||
find_library(
|
||||
WaylandCursor_LIBRARY
|
||||
NAMES wayland-cursor libwayland-cursor
|
||||
)
|
||||
|
||||
if(WaylandCursor_INCLUDE_DIR AND WaylandCursor_LIBRARY)
|
||||
add_library(wayland::cursor UNKNOWN IMPORTED)
|
||||
|
||||
set_target_properties(
|
||||
wayland::cursor PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${WaylandCursor_INCLUDE_DIR}"
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${WaylandCursor_LIBRARY}"
|
||||
)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(
|
||||
WaylandCursor
|
||||
REQUIRED_VARS WaylandCursor_LIBRARY WaylandCursor_INCLUDE_DIR
|
||||
)
|
||||
|
||||
mark_as_advanced(
|
||||
WaylandCursor_INCLUDE_DIR
|
||||
WaylandCursor_LIBRARY
|
||||
)
|
||||
35
mk/cmake/FindWaylandEGL.cmake
Normal file
@@ -0,0 +1,35 @@
|
||||
find_path(
|
||||
WaylandEGL_INCLUDE_DIR
|
||||
NAMES wayland-egl.h
|
||||
)
|
||||
|
||||
find_library(
|
||||
WaylandEGL_LIBRARY
|
||||
NAMES wayland-egl libwayland-egl
|
||||
)
|
||||
|
||||
if(WaylandEGL_INCLUDE_DIR AND WaylandEGL_LIBRARY)
|
||||
add_library(wayland::egl UNKNOWN IMPORTED)
|
||||
|
||||
set_target_properties(
|
||||
wayland::egl PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${WaylandEGL_INCLUDE_DIR}"
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${WaylandEGL_LIBRARY}"
|
||||
)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(
|
||||
WaylandEGL
|
||||
REQUIRED_VARS WaylandEGL_LIBRARY WaylandEGL_INCLUDE_DIR
|
||||
)
|
||||
|
||||
mark_as_advanced(
|
||||
WaylandEGL_INCLUDE_DIR
|
||||
WaylandEGL_LIBRARY
|
||||
)
|
||||
|
||||
if(WaylandEGL_FOUND)
|
||||
message(STATUS "Found WaylandEGL: ${WaylandEGL_LIBRARY}")
|
||||
endif()
|
||||
31
mk/cmake/FindXKBCommon.cmake
Normal file
@@ -0,0 +1,31 @@
|
||||
find_path(
|
||||
XKBCommon_INCLUDE_DIR
|
||||
NAMES xkbcommon/xkbcommon.h
|
||||
)
|
||||
|
||||
find_library(
|
||||
XKBCommon_LIBRARY
|
||||
NAMES xkbcommon
|
||||
)
|
||||
|
||||
if(WaylandClient_INCLUDE_DIR AND WaylandClient_LIBRARY)
|
||||
add_library(xkbcommon UNKNOWN IMPORTED)
|
||||
|
||||
set_target_properties(
|
||||
xkbcommon PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${XKBCommon_INCLUDE_DIR}"
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${XKBCommon_LIBRARY}"
|
||||
)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(
|
||||
XKBCommon
|
||||
REQUIRED_VARS XKBCommon_LIBRARY XKBCommon_INCLUDE_DIR
|
||||
)
|
||||
|
||||
mark_as_advanced(
|
||||
XKBCommon_INCLUDE_DIR
|
||||
XKBCommon_LIBRARY
|
||||
)
|
||||
13
mk/fixes/serenityos/01_angelscript_no_malloc_h.diff
Normal file
@@ -0,0 +1,13 @@
|
||||
--- external/angelscript/angelscript/source/as_memory.cpp
|
||||
+++ external/angelscript/angelscript/source/as_memory-1.cpp
|
||||
@@ -38,10 +38,6 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
-#if !defined(__APPLE__) && !defined(__SNC__) && !defined(__ghs__) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__)
|
||||
-#include <malloc.h>
|
||||
-#endif
|
||||
-
|
||||
#include "as_config.h"
|
||||
#include "as_memory.h"
|
||||
#include "as_scriptnode.h"
|
||||
283
mk/make/Makefile
Normal file
@@ -0,0 +1,283 @@
|
||||
# PolyGun
|
||||
# Simple Makefile for usage on systems where setting up CMake is too complicated/long.
|
||||
|
||||
# Copyright (c) 2024 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
include mk/make/Makefile.config
|
||||
|
||||
ifeq ($(BUILD_SERVER),1)
|
||||
# AngelScript
|
||||
AS_SOURCES=external/angelscript/angelscript/source/as_atomic.cpp \
|
||||
external/angelscript/angelscript/source/as_builder.cpp \
|
||||
external/angelscript/angelscript/source/as_bytecode.cpp \
|
||||
external/angelscript/angelscript/source/as_callfunc.cpp \
|
||||
external/angelscript/angelscript/source/as_compiler.cpp \
|
||||
external/angelscript/angelscript/source/as_configgroup.cpp \
|
||||
external/angelscript/angelscript/source/as_context.cpp \
|
||||
external/angelscript/angelscript/source/as_datatype.cpp \
|
||||
external/angelscript/angelscript/source/as_gc.cpp \
|
||||
external/angelscript/angelscript/source/as_generic.cpp \
|
||||
external/angelscript/angelscript/source/as_globalproperty.cpp \
|
||||
external/angelscript/angelscript/source/as_memory.cpp \
|
||||
external/angelscript/angelscript/source/as_module.cpp \
|
||||
external/angelscript/angelscript/source/as_objecttype.cpp \
|
||||
external/angelscript/angelscript/source/as_outputbuffer.cpp \
|
||||
external/angelscript/angelscript/source/as_parser.cpp \
|
||||
external/angelscript/angelscript/source/as_restore.cpp \
|
||||
external/angelscript/angelscript/source/as_scriptcode.cpp \
|
||||
external/angelscript/angelscript/source/as_scriptengine.cpp \
|
||||
external/angelscript/angelscript/source/as_scriptfunction.cpp \
|
||||
external/angelscript/angelscript/source/as_scriptnode.cpp \
|
||||
external/angelscript/angelscript/source/as_scriptobject.cpp \
|
||||
external/angelscript/angelscript/source/as_string.cpp \
|
||||
external/angelscript/angelscript/source/as_string_util.cpp \
|
||||
external/angelscript/angelscript/source/as_thread.cpp \
|
||||
external/angelscript/angelscript/source/as_tokenizer.cpp \
|
||||
external/angelscript/angelscript/source/as_typeinfo.cpp \
|
||||
external/angelscript/angelscript/source/as_variablescope.cpp \
|
||||
$(AS_CALLCONV_IMPL) \
|
||||
external/angelscript/add_on/scriptarray/scriptarray.cpp \
|
||||
external/angelscript/add_on/scriptstdstring/scriptstdstring.cpp \
|
||||
external/angelscript/add_on/scriptstdstring/scriptstdstring_utils.cpp
|
||||
|
||||
AS_OBJECTS=$(patsubst %.cpp,%.o,$(addprefix build/,$(AS_SOURCES)))
|
||||
|
||||
build/external/angelscript/%.o: external/angelscript/%.cpp
|
||||
@echo CXX $<
|
||||
@mkdir -p $(dir $@)
|
||||
@$(CXX) $< -c -o $@ $(CXXFLAGS) -Iexternal/angelscript/angelscript/include
|
||||
endif # BUILD_SERVER
|
||||
|
||||
# PolyGun
|
||||
ifeq ($(RENDERER_GL),1)
|
||||
RENDERER_GENERIC_GL=1
|
||||
endif
|
||||
ifeq ($(RENDERER_LEGACY_GL),1)
|
||||
RENDERER_GENERIC_GL=1
|
||||
endif
|
||||
|
||||
SOURCES=src/common/binary_utils.cpp \
|
||||
src/common/command_arguments_parser.cpp \
|
||||
src/common/fs.cpp \
|
||||
src/common/logger.cpp \
|
||||
src/common/resource_id_parser.cpp \
|
||||
src/common/str.cpp \
|
||||
src/common/type_enum.cpp \
|
||||
src/common/as/ast.cpp \
|
||||
src/common/as/lexer.cpp \
|
||||
src/common/as/parser.cpp \
|
||||
src/common/as/value.cpp \
|
||||
src/common/as/vm.cpp \
|
||||
src/common/control/controller.cpp \
|
||||
src/common/locale/dictionary.cpp \
|
||||
src/common/locale/translation_manager.cpp \
|
||||
src/common/math/matrix4.cpp \
|
||||
src/common/math/rect3d.cpp \
|
||||
src/common/math/rect.cpp \
|
||||
src/common/network/network_manager.cpp \
|
||||
src/common/network/network_packet.cpp \
|
||||
src/common/network/tcp_socket.cpp \
|
||||
src/common/network/udp_socket.cpp \
|
||||
src/common/world/chunk.cpp \
|
||||
src/common/world/chunk_manager_base.cpp \
|
||||
src/common/world/entity_def.cpp \
|
||||
src/common/world/node_def.cpp \
|
||||
src/common/world/physic_manager_base.cpp \
|
||||
src/common/world/player.cpp \
|
||||
src/common/world/player_mode.cpp \
|
||||
src/common/xml/lexer.cpp \
|
||||
src/common/xml/parser.cpp \
|
||||
src/common/xml/reader.cpp \
|
||||
src/common/xml/writer.cpp \
|
||||
src/common/xml/xml_node.cpp \
|
||||
src/main.cpp
|
||||
|
||||
ifeq ($(BUILD_CLIENT),1)
|
||||
SOURCES+=src/game/audio/audio.cpp \
|
||||
src/game/audio/buffer.cpp \
|
||||
src/game/audio/oggvorbis_decoder.cpp \
|
||||
src/game/audio/source.cpp \
|
||||
src/game/audio/streaming_source.cpp \
|
||||
src/game/control/keyboard_controller.cpp \
|
||||
src/game/control/mouse_camera_controller.cpp \
|
||||
src/game/engine/content_registry.cpp \
|
||||
src/game/engine/engine.cpp \
|
||||
src/game/engine/game_config.cpp \
|
||||
src/game/engine/greedy_meshing.cpp \
|
||||
src/game/engine/ingame_music.cpp \
|
||||
src/game/engine/node_side.cpp \
|
||||
src/game/engine/normal_meshing.cpp \
|
||||
src/game/engine/ray.cpp \
|
||||
src/game/engine/redirect_manager.cpp \
|
||||
src/game/engine/resource_manager.cpp \
|
||||
src/game/engine/screen_manager.cpp \
|
||||
src/game/engine/sync_manager.cpp \
|
||||
src/game/engine/texture_atlas.cpp \
|
||||
src/game/engine/thread_helper.cpp \
|
||||
src/game/gui/box.cpp \
|
||||
src/game/gui/button.cpp \
|
||||
src/game/gui/chat.cpp \
|
||||
src/game/gui/combo_box.cpp \
|
||||
src/game/gui/component.cpp \
|
||||
src/game/gui/constraint.cpp \
|
||||
src/game/gui/container.cpp \
|
||||
src/game/gui/gui_master.cpp \
|
||||
src/game/gui/image.cpp \
|
||||
src/game/gui/item_gallery.cpp \
|
||||
src/game/gui/label.cpp \
|
||||
src/game/gui/layout.cpp \
|
||||
src/game/gui/line_edit.cpp \
|
||||
src/game/gui/message_box.cpp \
|
||||
src/game/gui/slider.cpp \
|
||||
src/game/gui/style_change_listener.cpp \
|
||||
src/game/gui/style.cpp \
|
||||
src/game/gui/tab_view.cpp \
|
||||
src/game/gui/text_edit.cpp \
|
||||
src/game/hud/editmode_hud.cpp \
|
||||
src/game/hud/hud.cpp \
|
||||
src/game/hud/normal_hud.cpp \
|
||||
src/game/renderer/font.cpp \
|
||||
src/game/renderer/gui_renderer.cpp \
|
||||
src/game/renderer/master_renderer.cpp \
|
||||
src/game/renderer/mesh_renderer.cpp \
|
||||
src/game/renderer/ortho_camera.cpp \
|
||||
src/game/renderer/surface.cpp \
|
||||
src/game/renderer/texture.cpp \
|
||||
src/game/screens/game_session_screen.cpp \
|
||||
src/game/screens/intro_screen.cpp \
|
||||
src/game/screens/main_menu_screen.cpp \
|
||||
src/game/screens/options_screen.cpp \
|
||||
src/game/window/keyboard.cpp \
|
||||
src/game/window/mouse.cpp \
|
||||
src/game/window/window.cpp \
|
||||
src/game/world/chunk_manager.cpp \
|
||||
src/game/world/client_chunk.cpp \
|
||||
src/game/world/local_player.cpp \
|
||||
src/game/world/physic_manager.cpp \
|
||||
src/game/world/player_manager.cpp \
|
||||
src/game/world/skybox.cpp
|
||||
|
||||
ifeq ($(RENDERER_GL),1)
|
||||
SOURCES+=src/game/renderer/gl/gl_gui_renderer.cpp \
|
||||
src/game/renderer/gl/gl_master_renderer.cpp \
|
||||
src/game/renderer/gl/gl_mesh.cpp \
|
||||
src/game/renderer/gl/gl_mesh_renderer.cpp \
|
||||
src/game/renderer/gl/gl_shader.cpp
|
||||
CXXFLAGS+=-DRENDERER_GL
|
||||
endif
|
||||
|
||||
ifeq ($(RENDERER_LEGACY_GL),1)
|
||||
SOURCES+=src/game/renderer/legacy_gl/legacy_gl_gui_renderer.cpp \
|
||||
src/game/renderer/legacy_gl/legacy_gl_master_renderer.cpp \
|
||||
src/game/renderer/legacy_gl/legacy_gl_mesh.cpp \
|
||||
src/game/renderer/legacy_gl/legacy_gl_mesh_renderer.cpp
|
||||
CXXFLAGS+=-DRENDERER_LEGACY_GL
|
||||
endif
|
||||
|
||||
ifeq ($(RENDERER_GENERIC_GL),1)
|
||||
SOURCES+=src/game/renderer/gl/gl_context.cpp \
|
||||
src/game/renderer/gl/gl_texture.cpp \
|
||||
src/game/renderer/gl/opengl.cpp
|
||||
endif
|
||||
|
||||
ifeq ($(WINDOW_WIN32),1)
|
||||
SOURCES+=src/game/window/win32_window.cpp
|
||||
ifeq ($(RENDERER_GENERIC_GL),1)
|
||||
SOURCES+=src/game/renderer/gl/win32_gl_context.cpp
|
||||
endif # RENDERER_GENERIC_GL
|
||||
CXXFLAGS+=-DWINDOW_WIN32
|
||||
endif # WINDOW_WIN32
|
||||
|
||||
ifeq ($(WINDOW_X11),1)
|
||||
SOURCES+=src/game/window/x11/dynamic_x11.cpp \
|
||||
src/game/window/x11/x11_window.cpp
|
||||
ifeq ($(RENDERER_GENERIC_GL),1)
|
||||
SOURCES+=src/game/window/x11/dynamic_glx.cpp \
|
||||
src/game/renderer/gl/x11_gl_context.cpp
|
||||
endif # RENDERER_GENERIC_GL
|
||||
CXXFLAGS+=-DWINDOW_X11
|
||||
endif # WINDOW_X11
|
||||
|
||||
ifeq ($(WINDOW_WAYLAND),1)
|
||||
SOURCES+=src/game/window/wayland_window.cpp
|
||||
ifeq ($(RENDERER_GENERIC_GL),1)
|
||||
SOURCES+=src/game/renderer/gl/egl_gl_context.cpp
|
||||
endif # RENDERER_GENERIC_GL
|
||||
CXXFLAGS+=-DWINDOW_WAYLAND
|
||||
endif # WINDOW_WAYLAND
|
||||
|
||||
ifeq ($(WINDOW_SERENITYOS),1)
|
||||
SOURCES+=src/game/window/serenityos_window.cpp
|
||||
ifeq ($(RENDERER_GENERIC_GL),1)
|
||||
SOURCES+=src/game/renderer/gl/serenityos_gl_context.cpp
|
||||
endif # RENDERER_GENERIC_GL
|
||||
CXXFLAGS+=-DWINDOW_SERENITYOS
|
||||
endif # WINDOW_SERENITYOS
|
||||
|
||||
ifeq ($(WINDOW_HAIKU),1)
|
||||
SOURCES+=src/game/window/haiku_window.cpp
|
||||
ifeq ($(RENDERER_GENERIC_GL),1)
|
||||
SOURCES+=src/game/renderer/gl/haiku_gl_context.cpp
|
||||
endif
|
||||
CXXFLAGS+=-DWINDOW_HAIKU
|
||||
endif # WINDOW_HAIKU
|
||||
|
||||
CXXFLAGS+=-DBUILD_CLIENT
|
||||
|
||||
endif # BUILD_CLIENT
|
||||
|
||||
ifeq ($(BUILD_SERVER),1)
|
||||
SOURCES+=src/server/chunk_manager.cpp \
|
||||
src/server/client.cpp \
|
||||
src/server/command_parser.cpp \
|
||||
src/server/mod.cpp \
|
||||
src/server/mod_api.cpp \
|
||||
src/server/mod_manager.cpp \
|
||||
src/server/player_storage.cpp \
|
||||
src/server/server.cpp \
|
||||
src/server/server_config.cpp
|
||||
CXXFLAGS+=-DBUILD_SERVER -Iexternal/angelscript/angelscript/include -Iexternal/angelscript/add_on
|
||||
endif # BUILD_SERVER
|
||||
|
||||
ifeq ($(ENABLE_BACKTRACE_PRINTING),1)
|
||||
SOURCES+=src/common/backtrace_handler.cpp
|
||||
CXXFLAGS+=-DENABLE_BACKTRACE_PRINTING
|
||||
endif # ENABLE_BACKTRACE_PRINTING
|
||||
|
||||
ifeq ($(HAVE_STRSIGNAL),1)
|
||||
CXXFLAGS+=-DHAVE_STRSIGNAL
|
||||
endif # HAVE_STRSIGNAL
|
||||
|
||||
OBJECTS=$(patsubst %.cpp,%.o,$(addprefix build/,$(SOURCES)))
|
||||
.PHONY: polygun clean
|
||||
|
||||
polygun: $(AS_OBJECTS) $(OBJECTS)
|
||||
@echo CXXLD build/polygun
|
||||
@$(LD) $(AS_OBJECTS) $(OBJECTS) $(LDFLAGS) -o build/polygun
|
||||
|
||||
clean:
|
||||
-@rm $(AS_OBJECTS) $(OBJECTS) &> /dev/null
|
||||
|
||||
build/src/%.o: src/%.cpp
|
||||
@echo CXX $<
|
||||
@mkdir -p $(dir $@)
|
||||
@$(CXX) $< -c -o $@ $(CXXFLAGS) -Isrc -Imk/make -DPOLYGUN_VERSION=\"$(POLYGUN_VERSION)\"
|
||||
68
mk/make/Makefile.config
Normal file
@@ -0,0 +1,68 @@
|
||||
# PolyGun
|
||||
|
||||
# Copyright (c) 2024 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
# Adjust these variables to your requirements
|
||||
|
||||
CXX=g++
|
||||
LD=$(CXX)
|
||||
|
||||
CXXFLAGS=
|
||||
|
||||
LDFLAGS=
|
||||
|
||||
# Select one from following
|
||||
# AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_arm.cpp
|
||||
# AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_arm64.cpp
|
||||
# AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_arm64_gcc.S
|
||||
# AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_arm64_msvc.asm
|
||||
# AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_arm_gcc.S
|
||||
# AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_arm_msvc.asm
|
||||
# AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_arm_vita.S
|
||||
# AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_arm_xcode.S
|
||||
# AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_mips.cpp
|
||||
# AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_ppc.cpp
|
||||
# AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_ppc_64.cpp
|
||||
# AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_sh4.cpp
|
||||
#AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_x64_gcc.cpp
|
||||
# AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_x64_mingw.cpp
|
||||
# AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_x64_msvc.cpp \
|
||||
# external/angelscript/angelscript/source/as_callfunc_x64_msvc_asm.asm
|
||||
# AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_x86.cpp
|
||||
# AS_CALLCONV_IMPL=external/angelscript/angelscript/source/as_callfunc_xenon.cpp
|
||||
|
||||
BUILD_CLIENT=0
|
||||
BUILD_SERVER=0
|
||||
|
||||
RENDERER_GL=0
|
||||
RENDERER_LEGACY_GL=0
|
||||
|
||||
WINDOW_WIN32=0
|
||||
WINDOW_X11=0
|
||||
WINDOW_WAYLAND=0
|
||||
WINDOW_SERENITYOS=0
|
||||
WINDOW_HAIKU=0
|
||||
|
||||
ENABLE_BACKTRACE_PRINTING=0
|
||||
|
||||
HAVE_STRSIGNAL=0
|
||||
POLYGUN_VERSION=git
|
||||
339
mk/wayland/pointer-constraints-unstable-v1.xml
Normal file
@@ -0,0 +1,339 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="pointer_constraints_unstable_v1">
|
||||
|
||||
<copyright>
|
||||
Copyright © 2014 Jonas Ådahl
|
||||
Copyright © 2015 Red Hat Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
</copyright>
|
||||
|
||||
<description summary="protocol for constraining pointer motions">
|
||||
This protocol specifies a set of interfaces used for adding constraints to
|
||||
the motion of a pointer. Possible constraints include confining pointer
|
||||
motions to a given region, or locking it to its current position.
|
||||
|
||||
In order to constrain the pointer, a client must first bind the global
|
||||
interface "wp_pointer_constraints" which, if a compositor supports pointer
|
||||
constraints, is exposed by the registry. Using the bound global object, the
|
||||
client uses the request that corresponds to the type of constraint it wants
|
||||
to make. See wp_pointer_constraints for more details.
|
||||
|
||||
Warning! The protocol described in this file is experimental and backward
|
||||
incompatible changes may be made. Backward compatible changes may be added
|
||||
together with the corresponding interface version bump. Backward
|
||||
incompatible changes are done by bumping the version number in the protocol
|
||||
and interface names and resetting the interface version. Once the protocol
|
||||
is to be declared stable, the 'z' prefix and the version number in the
|
||||
protocol and interface names are removed and the interface version number is
|
||||
reset.
|
||||
</description>
|
||||
|
||||
<interface name="zwp_pointer_constraints_v1" version="1">
|
||||
<description summary="constrain the movement of a pointer">
|
||||
The global interface exposing pointer constraining functionality. It
|
||||
exposes two requests: lock_pointer for locking the pointer to its
|
||||
position, and confine_pointer for locking the pointer to a region.
|
||||
|
||||
The lock_pointer and confine_pointer requests create the objects
|
||||
wp_locked_pointer and wp_confined_pointer respectively, and the client can
|
||||
use these objects to interact with the lock.
|
||||
|
||||
For any surface, only one lock or confinement may be active across all
|
||||
wl_pointer objects of the same seat. If a lock or confinement is requested
|
||||
when another lock or confinement is active or requested on the same surface
|
||||
and with any of the wl_pointer objects of the same seat, an
|
||||
'already_constrained' error will be raised.
|
||||
</description>
|
||||
|
||||
<enum name="error">
|
||||
<description summary="wp_pointer_constraints error values">
|
||||
These errors can be emitted in response to wp_pointer_constraints
|
||||
requests.
|
||||
</description>
|
||||
<entry name="already_constrained" value="1"
|
||||
summary="pointer constraint already requested on that surface"/>
|
||||
</enum>
|
||||
|
||||
<enum name="lifetime">
|
||||
<description summary="constraint lifetime">
|
||||
These values represent different lifetime semantics. They are passed
|
||||
as arguments to the factory requests to specify how the constraint
|
||||
lifetimes should be managed.
|
||||
</description>
|
||||
<entry name="oneshot" value="1">
|
||||
<description summary="the pointer constraint is defunct once deactivated">
|
||||
A oneshot pointer constraint will never reactivate once it has been
|
||||
deactivated. See the corresponding deactivation event
|
||||
(wp_locked_pointer.unlocked and wp_confined_pointer.unconfined) for
|
||||
details.
|
||||
</description>
|
||||
</entry>
|
||||
<entry name="persistent" value="2">
|
||||
<description summary="the pointer constraint may reactivate">
|
||||
A persistent pointer constraint may again reactivate once it has
|
||||
been deactivated. See the corresponding deactivation event
|
||||
(wp_locked_pointer.unlocked and wp_confined_pointer.unconfined) for
|
||||
details.
|
||||
</description>
|
||||
</entry>
|
||||
</enum>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="destroy the pointer constraints manager object">
|
||||
Used by the client to notify the server that it will no longer use this
|
||||
pointer constraints object.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<request name="lock_pointer">
|
||||
<description summary="lock pointer to a position">
|
||||
The lock_pointer request lets the client request to disable movements of
|
||||
the virtual pointer (i.e. the cursor), effectively locking the pointer
|
||||
to a position. This request may not take effect immediately; in the
|
||||
future, when the compositor deems implementation-specific constraints
|
||||
are satisfied, the pointer lock will be activated and the compositor
|
||||
sends a locked event.
|
||||
|
||||
The protocol provides no guarantee that the constraints are ever
|
||||
satisfied, and does not require the compositor to send an error if the
|
||||
constraints cannot ever be satisfied. It is thus possible to request a
|
||||
lock that will never activate.
|
||||
|
||||
There may not be another pointer constraint of any kind requested or
|
||||
active on the surface for any of the wl_pointer objects of the seat of
|
||||
the passed pointer when requesting a lock. If there is, an error will be
|
||||
raised. See general pointer lock documentation for more details.
|
||||
|
||||
The intersection of the region passed with this request and the input
|
||||
region of the surface is used to determine where the pointer must be
|
||||
in order for the lock to activate. It is up to the compositor whether to
|
||||
warp the pointer or require some kind of user interaction for the lock
|
||||
to activate. If the region is null the surface input region is used.
|
||||
|
||||
A surface may receive pointer focus without the lock being activated.
|
||||
|
||||
The request creates a new object wp_locked_pointer which is used to
|
||||
interact with the lock as well as receive updates about its state. See
|
||||
the the description of wp_locked_pointer for further information.
|
||||
|
||||
Note that while a pointer is locked, the wl_pointer objects of the
|
||||
corresponding seat will not emit any wl_pointer.motion events, but
|
||||
relative motion events will still be emitted via wp_relative_pointer
|
||||
objects of the same seat. wl_pointer.axis and wl_pointer.button events
|
||||
are unaffected.
|
||||
</description>
|
||||
<arg name="id" type="new_id" interface="zwp_locked_pointer_v1"/>
|
||||
<arg name="surface" type="object" interface="wl_surface"
|
||||
summary="surface to lock pointer to"/>
|
||||
<arg name="pointer" type="object" interface="wl_pointer"
|
||||
summary="the pointer that should be locked"/>
|
||||
<arg name="region" type="object" interface="wl_region" allow-null="true"
|
||||
summary="region of surface"/>
|
||||
<arg name="lifetime" type="uint" enum="lifetime" summary="lock lifetime"/>
|
||||
</request>
|
||||
|
||||
<request name="confine_pointer">
|
||||
<description summary="confine pointer to a region">
|
||||
The confine_pointer request lets the client request to confine the
|
||||
pointer cursor to a given region. This request may not take effect
|
||||
immediately; in the future, when the compositor deems implementation-
|
||||
specific constraints are satisfied, the pointer confinement will be
|
||||
activated and the compositor sends a confined event.
|
||||
|
||||
The intersection of the region passed with this request and the input
|
||||
region of the surface is used to determine where the pointer must be
|
||||
in order for the confinement to activate. It is up to the compositor
|
||||
whether to warp the pointer or require some kind of user interaction for
|
||||
the confinement to activate. If the region is null the surface input
|
||||
region is used.
|
||||
|
||||
The request will create a new object wp_confined_pointer which is used
|
||||
to interact with the confinement as well as receive updates about its
|
||||
state. See the the description of wp_confined_pointer for further
|
||||
information.
|
||||
</description>
|
||||
<arg name="id" type="new_id" interface="zwp_confined_pointer_v1"/>
|
||||
<arg name="surface" type="object" interface="wl_surface"
|
||||
summary="surface to lock pointer to"/>
|
||||
<arg name="pointer" type="object" interface="wl_pointer"
|
||||
summary="the pointer that should be confined"/>
|
||||
<arg name="region" type="object" interface="wl_region" allow-null="true"
|
||||
summary="region of surface"/>
|
||||
<arg name="lifetime" type="uint" enum="lifetime" summary="confinement lifetime"/>
|
||||
</request>
|
||||
</interface>
|
||||
|
||||
<interface name="zwp_locked_pointer_v1" version="1">
|
||||
<description summary="receive relative pointer motion events">
|
||||
The wp_locked_pointer interface represents a locked pointer state.
|
||||
|
||||
While the lock of this object is active, the wl_pointer objects of the
|
||||
associated seat will not emit any wl_pointer.motion events.
|
||||
|
||||
This object will send the event 'locked' when the lock is activated.
|
||||
Whenever the lock is activated, it is guaranteed that the locked surface
|
||||
will already have received pointer focus and that the pointer will be
|
||||
within the region passed to the request creating this object.
|
||||
|
||||
To unlock the pointer, send the destroy request. This will also destroy
|
||||
the wp_locked_pointer object.
|
||||
|
||||
If the compositor decides to unlock the pointer the unlocked event is
|
||||
sent. See wp_locked_pointer.unlock for details.
|
||||
|
||||
When unlocking, the compositor may warp the cursor position to the set
|
||||
cursor position hint. If it does, it will not result in any relative
|
||||
motion events emitted via wp_relative_pointer.
|
||||
|
||||
If the surface the lock was requested on is destroyed and the lock is not
|
||||
yet activated, the wp_locked_pointer object is now defunct and must be
|
||||
destroyed.
|
||||
</description>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="destroy the locked pointer object">
|
||||
Destroy the locked pointer object. If applicable, the compositor will
|
||||
unlock the pointer.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<request name="set_cursor_position_hint">
|
||||
<description summary="set the pointer cursor position hint">
|
||||
Set the cursor position hint relative to the top left corner of the
|
||||
surface.
|
||||
|
||||
If the client is drawing its own cursor, it should update the position
|
||||
hint to the position of its own cursor. A compositor may use this
|
||||
information to warp the pointer upon unlock in order to avoid pointer
|
||||
jumps.
|
||||
|
||||
The cursor position hint is double buffered. The new hint will only take
|
||||
effect when the associated surface gets it pending state applied. See
|
||||
wl_surface.commit for details.
|
||||
</description>
|
||||
<arg name="surface_x" type="fixed"
|
||||
summary="surface-local x coordinate"/>
|
||||
<arg name="surface_y" type="fixed"
|
||||
summary="surface-local y coordinate"/>
|
||||
</request>
|
||||
|
||||
<request name="set_region">
|
||||
<description summary="set a new lock region">
|
||||
Set a new region used to lock the pointer.
|
||||
|
||||
The new lock region is double-buffered. The new lock region will
|
||||
only take effect when the associated surface gets its pending state
|
||||
applied. See wl_surface.commit for details.
|
||||
|
||||
For details about the lock region, see wp_locked_pointer.
|
||||
</description>
|
||||
<arg name="region" type="object" interface="wl_region" allow-null="true"
|
||||
summary="region of surface"/>
|
||||
</request>
|
||||
|
||||
<event name="locked">
|
||||
<description summary="lock activation event">
|
||||
Notification that the pointer lock of the seat's pointer is activated.
|
||||
</description>
|
||||
</event>
|
||||
|
||||
<event name="unlocked">
|
||||
<description summary="lock deactivation event">
|
||||
Notification that the pointer lock of the seat's pointer is no longer
|
||||
active. If this is a oneshot pointer lock (see
|
||||
wp_pointer_constraints.lifetime) this object is now defunct and should
|
||||
be destroyed. If this is a persistent pointer lock (see
|
||||
wp_pointer_constraints.lifetime) this pointer lock may again
|
||||
reactivate in the future.
|
||||
</description>
|
||||
</event>
|
||||
</interface>
|
||||
|
||||
<interface name="zwp_confined_pointer_v1" version="1">
|
||||
<description summary="confined pointer object">
|
||||
The wp_confined_pointer interface represents a confined pointer state.
|
||||
|
||||
This object will send the event 'confined' when the confinement is
|
||||
activated. Whenever the confinement is activated, it is guaranteed that
|
||||
the surface the pointer is confined to will already have received pointer
|
||||
focus and that the pointer will be within the region passed to the request
|
||||
creating this object. It is up to the compositor to decide whether this
|
||||
requires some user interaction and if the pointer will warp to within the
|
||||
passed region if outside.
|
||||
|
||||
To unconfine the pointer, send the destroy request. This will also destroy
|
||||
the wp_confined_pointer object.
|
||||
|
||||
If the compositor decides to unconfine the pointer the unconfined event is
|
||||
sent. The wp_confined_pointer object is at this point defunct and should
|
||||
be destroyed.
|
||||
</description>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="destroy the confined pointer object">
|
||||
Destroy the confined pointer object. If applicable, the compositor will
|
||||
unconfine the pointer.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<request name="set_region">
|
||||
<description summary="set a new confine region">
|
||||
Set a new region used to confine the pointer.
|
||||
|
||||
The new confine region is double-buffered. The new confine region will
|
||||
only take effect when the associated surface gets its pending state
|
||||
applied. See wl_surface.commit for details.
|
||||
|
||||
If the confinement is active when the new confinement region is applied
|
||||
and the pointer ends up outside of newly applied region, the pointer may
|
||||
warped to a position within the new confinement region. If warped, a
|
||||
wl_pointer.motion event will be emitted, but no
|
||||
wp_relative_pointer.relative_motion event.
|
||||
|
||||
The compositor may also, instead of using the new region, unconfine the
|
||||
pointer.
|
||||
|
||||
For details about the confine region, see wp_confined_pointer.
|
||||
</description>
|
||||
<arg name="region" type="object" interface="wl_region" allow-null="true"
|
||||
summary="region of surface"/>
|
||||
</request>
|
||||
|
||||
<event name="confined">
|
||||
<description summary="pointer confined">
|
||||
Notification that the pointer confinement of the seat's pointer is
|
||||
activated.
|
||||
</description>
|
||||
</event>
|
||||
|
||||
<event name="unconfined">
|
||||
<description summary="pointer unconfined">
|
||||
Notification that the pointer confinement of the seat's pointer is no
|
||||
longer active. If this is a oneshot pointer confinement (see
|
||||
wp_pointer_constraints.lifetime) this object is now defunct and should
|
||||
be destroyed. If this is a persistent pointer confinement (see
|
||||
wp_pointer_constraints.lifetime) this pointer confinement may again
|
||||
reactivate in the future.
|
||||
</description>
|
||||
</event>
|
||||
</interface>
|
||||
|
||||
</protocol>
|
||||
136
mk/wayland/relative-pointer-unstable-v1.xml
Normal file
@@ -0,0 +1,136 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="relative_pointer_unstable_v1">
|
||||
|
||||
<copyright>
|
||||
Copyright © 2014 Jonas Ådahl
|
||||
Copyright © 2015 Red Hat Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
</copyright>
|
||||
|
||||
<description summary="protocol for relative pointer motion events">
|
||||
This protocol specifies a set of interfaces used for making clients able to
|
||||
receive relative pointer events not obstructed by barriers (such as the
|
||||
monitor edge or other pointer barriers).
|
||||
|
||||
To start receiving relative pointer events, a client must first bind the
|
||||
global interface "wp_relative_pointer_manager" which, if a compositor
|
||||
supports relative pointer motion events, is exposed by the registry. After
|
||||
having created the relative pointer manager proxy object, the client uses
|
||||
it to create the actual relative pointer object using the
|
||||
"get_relative_pointer" request given a wl_pointer. The relative pointer
|
||||
motion events will then, when applicable, be transmitted via the proxy of
|
||||
the newly created relative pointer object. See the documentation of the
|
||||
relative pointer interface for more details.
|
||||
|
||||
Warning! The protocol described in this file is experimental and backward
|
||||
incompatible changes may be made. Backward compatible changes may be added
|
||||
together with the corresponding interface version bump. Backward
|
||||
incompatible changes are done by bumping the version number in the protocol
|
||||
and interface names and resetting the interface version. Once the protocol
|
||||
is to be declared stable, the 'z' prefix and the version number in the
|
||||
protocol and interface names are removed and the interface version number is
|
||||
reset.
|
||||
</description>
|
||||
|
||||
<interface name="zwp_relative_pointer_manager_v1" version="1">
|
||||
<description summary="get relative pointer objects">
|
||||
A global interface used for getting the relative pointer object for a
|
||||
given pointer.
|
||||
</description>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="destroy the relative pointer manager object">
|
||||
Used by the client to notify the server that it will no longer use this
|
||||
relative pointer manager object.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<request name="get_relative_pointer">
|
||||
<description summary="get a relative pointer object">
|
||||
Create a relative pointer interface given a wl_pointer object. See the
|
||||
wp_relative_pointer interface for more details.
|
||||
</description>
|
||||
<arg name="id" type="new_id" interface="zwp_relative_pointer_v1"/>
|
||||
<arg name="pointer" type="object" interface="wl_pointer"/>
|
||||
</request>
|
||||
</interface>
|
||||
|
||||
<interface name="zwp_relative_pointer_v1" version="1">
|
||||
<description summary="relative pointer object">
|
||||
A wp_relative_pointer object is an extension to the wl_pointer interface
|
||||
used for emitting relative pointer events. It shares the same focus as
|
||||
wl_pointer objects of the same seat and will only emit events when it has
|
||||
focus.
|
||||
</description>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="release the relative pointer object"/>
|
||||
</request>
|
||||
|
||||
<event name="relative_motion">
|
||||
<description summary="relative pointer motion">
|
||||
Relative x/y pointer motion from the pointer of the seat associated with
|
||||
this object.
|
||||
|
||||
A relative motion is in the same dimension as regular wl_pointer motion
|
||||
events, except they do not represent an absolute position. For example,
|
||||
moving a pointer from (x, y) to (x', y') would have the equivalent
|
||||
relative motion (x' - x, y' - y). If a pointer motion caused the
|
||||
absolute pointer position to be clipped by for example the edge of the
|
||||
monitor, the relative motion is unaffected by the clipping and will
|
||||
represent the unclipped motion.
|
||||
|
||||
This event also contains non-accelerated motion deltas. The
|
||||
non-accelerated delta is, when applicable, the regular pointer motion
|
||||
delta as it was before having applied motion acceleration and other
|
||||
transformations such as normalization.
|
||||
|
||||
Note that the non-accelerated delta does not represent 'raw' events as
|
||||
they were read from some device. Pointer motion acceleration is device-
|
||||
and configuration-specific and non-accelerated deltas and accelerated
|
||||
deltas may have the same value on some devices.
|
||||
|
||||
Relative motions are not coupled to wl_pointer.motion events, and can be
|
||||
sent in combination with such events, but also independently. There may
|
||||
also be scenarios where wl_pointer.motion is sent, but there is no
|
||||
relative motion. The order of an absolute and relative motion event
|
||||
originating from the same physical motion is not guaranteed.
|
||||
|
||||
If the client needs button events or focus state, it can receive them
|
||||
from a wl_pointer object of the same seat that the wp_relative_pointer
|
||||
object is associated with.
|
||||
</description>
|
||||
<arg name="utime_hi" type="uint"
|
||||
summary="high 32 bits of a 64 bit timestamp with microsecond granularity"/>
|
||||
<arg name="utime_lo" type="uint"
|
||||
summary="low 32 bits of a 64 bit timestamp with microsecond granularity"/>
|
||||
<arg name="dx" type="fixed"
|
||||
summary="the x component of the motion vector"/>
|
||||
<arg name="dy" type="fixed"
|
||||
summary="the y component of the motion vector"/>
|
||||
<arg name="dx_unaccel" type="fixed"
|
||||
summary="the x component of the unaccelerated motion vector"/>
|
||||
<arg name="dy_unaccel" type="fixed"
|
||||
summary="the y component of the unaccelerated motion vector"/>
|
||||
</event>
|
||||
</interface>
|
||||
|
||||
</protocol>
|
||||
48
mods/defaultblocks/main.as
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
PolyGun - example server mod that adds few default nodes
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
void main() {
|
||||
polygun::log_info("Hello");
|
||||
polygun::register_node("defaultblocks:dirt", DirtNode());
|
||||
polygun::register_node("defaultblocks:grass", GrassNode());
|
||||
polygun::register_node("defaultblocks:sand", SandNode());
|
||||
polygun::register_node("defaultblocks:bricks", BricksNode());
|
||||
polygun::register_node("defaultblocks:bricks_blue", BlueBricksNode());
|
||||
polygun::register_node("defaultblocks:bricks_green", GreenBricksNode());
|
||||
polygun::register_node("defaultblocks:bricks_yellow", YellowBricksNode());
|
||||
polygun::register_node("defaultblocks:bricks_purple", PurpleBricksNode());
|
||||
polygun::register_node("defaultblocks:bricks_black", BlackBricksNode());
|
||||
polygun::register_node("defaultblocks:gold", GoldNode());
|
||||
polygun::register_node("defaultblocks:iron", IronNode());
|
||||
polygun::register_node("defaultblocks:stone", StoneNode());
|
||||
polygun::register_node("defaultblocks:wood", WoodNode());
|
||||
polygun::register_node("defaultblocks:coal_ore", CoalOreNode());
|
||||
polygun::register_node("defaultblocks:gold_ore", GoldOreNode());
|
||||
polygun::register_node("defaultblocks:planks", PlanksNode());
|
||||
polygun::register_node("defaultblocks:thinplanks", ThinPlanksNode());
|
||||
polygun::register_node("defaultblocks:leaves", LeavesNode());
|
||||
polygun::register_node("defaultblocks:red", RedNode());
|
||||
polygun::register_node("defaultblocks:tire", TireNode());
|
||||
polygun::register_node("defaultblocks:crt", TubeNode());
|
||||
}
|
||||
33
mods/defaultblocks/mod.xml
Normal file
@@ -0,0 +1,33 @@
|
||||
<!--
|
||||
PolyGun - example server mod that adds few default nodes
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
-->
|
||||
|
||||
<mod>
|
||||
<name>Default Nodes</name>
|
||||
<description>Example server mod that adds few default nodes</description>
|
||||
<author>PolyGun Developers</author>
|
||||
<scripts>
|
||||
<script>main.as</script>
|
||||
<script>nodes.as</script>
|
||||
</scripts>
|
||||
</mod>
|
||||
154
mods/defaultblocks/nodes.as
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
PolyGun - example server mod that adds few default nodes
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
class DirtNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/dirt";
|
||||
}
|
||||
}
|
||||
|
||||
class GrassNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/grass";
|
||||
}
|
||||
}
|
||||
|
||||
class SandNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/sand";
|
||||
}
|
||||
}
|
||||
|
||||
class BricksNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/bricks_red";
|
||||
}
|
||||
}
|
||||
|
||||
class BlueBricksNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/bricks_blue";
|
||||
}
|
||||
}
|
||||
|
||||
class GreenBricksNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/bricks_green";
|
||||
}
|
||||
}
|
||||
|
||||
class YellowBricksNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/bricks_yellow";
|
||||
}
|
||||
}
|
||||
|
||||
class PurpleBricksNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/bricks_purple";
|
||||
}
|
||||
}
|
||||
|
||||
class BlackBricksNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/bricks_black";
|
||||
}
|
||||
}
|
||||
|
||||
class GoldNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/gold";
|
||||
}
|
||||
}
|
||||
|
||||
class IronNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/iron";
|
||||
}
|
||||
}
|
||||
|
||||
class StoneNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/stone";
|
||||
}
|
||||
}
|
||||
|
||||
class WoodNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/wood";
|
||||
}
|
||||
}
|
||||
|
||||
class CoalOreNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/coal_ore";
|
||||
}
|
||||
}
|
||||
|
||||
class GoldOreNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/gold_ore";
|
||||
}
|
||||
}
|
||||
|
||||
class PlanksNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/planks";
|
||||
}
|
||||
}
|
||||
|
||||
class ThinPlanksNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/thinplanks";
|
||||
}
|
||||
}
|
||||
|
||||
class LeavesNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/leaves";
|
||||
}
|
||||
}
|
||||
|
||||
class RedNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/red";
|
||||
}
|
||||
}
|
||||
|
||||
class TireNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/tire";
|
||||
}
|
||||
}
|
||||
|
||||
class TubeNode : polygun::Node {
|
||||
string get_texture_filename() {
|
||||
return "defaultblocks/texture/crt";
|
||||
}
|
||||
|
||||
uint8 get_light_emission() {
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
82
mods/interface.as
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
PolyGun - scripting interface
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
// Registering nodes
|
||||
namespace polygun {
|
||||
shared abstract class Node {
|
||||
private polygun::cNode@ m_proxy;
|
||||
|
||||
Node() {
|
||||
@m_proxy = polygun::cNode();
|
||||
}
|
||||
|
||||
string get_texture_filename() {
|
||||
return "";
|
||||
}
|
||||
|
||||
string get_display_icon() {
|
||||
return "";
|
||||
}
|
||||
|
||||
string get_top_texture_filename() {
|
||||
return "";
|
||||
}
|
||||
|
||||
string get_bottom_texture_filename() {
|
||||
return "";
|
||||
}
|
||||
|
||||
string get_left_texture_filename() {
|
||||
return "";
|
||||
}
|
||||
|
||||
string get_right_texture_filename() {
|
||||
return "";
|
||||
}
|
||||
|
||||
string get_front_texture_filename() {
|
||||
return "";
|
||||
}
|
||||
|
||||
string get_back_texture_filename() {
|
||||
return "";
|
||||
}
|
||||
|
||||
bool is_invisible() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool is_transparent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8 get_light_emission() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
polygun::cNode @opImplCast() {
|
||||
return m_proxy;
|
||||
}
|
||||
}
|
||||
}
|
||||
34
readme.md
@@ -1,14 +1,32 @@
|
||||
```
|
||||
PPPPP OOOOOO LL YY YY GGGGGGG UU UU NN NN
|
||||
PP PP OOOOOO LL YY YY GG UU UU NNNN NN
|
||||
PPPPP OO OO LL YYYY GG GGGG UU UU NNNNN NN
|
||||
PP OO OO LL YY GG G GG UU UU NN NNN NN
|
||||
PP OO OO LLLLL YY GG GG UUUUUU NN NNNNN
|
||||
PP OOOOOO LLLLL YY GGGGGGG UUUUUU NN NNNN
|
||||
___________________________________________________
|
||||
| ____ ___ _ __ __ ____ __ __ ____ |
|
||||
| | \ / \ | T | T T / || T T| \ |
|
||||
| | o )| || | | | || __|| | || _ | |
|
||||
| | _/ | O || |___ | || | || | || | | |
|
||||
| | | | || ||___, || |_ || | || | | |
|
||||
| | | | !| || || || || | | |
|
||||
| |__| \___/ |_____||____/ |_____| \____||__|__| |
|
||||
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
||||
```
|
||||
## PolyGun
|
||||
PolyGun is a voxel-based multiplayer first person shooter game/engine.
|
||||
|
||||
# PolyGun is a multi-player voxel first person shooter
|
||||
## Licensing
|
||||
PolyGun is free software licensed under the permissive Expat ("MIT") license. See [LICENSE.TXT](LICENSE.TXT) for the full end-user license agreement.
|
||||
|
||||
PolyGun comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.
|
||||
|
||||
## Supported platforms/operating systems
|
||||
- GNU/Linux, Alpine Linux (X11 and Wayland windowing systems)
|
||||
- Microsoft Windows (2000/ME or later, may work on older but untested. Also good luck getting
|
||||
a C++ 17 compiler on there)
|
||||
- FreeBSD (X11 and Wayland windowing systems)
|
||||
- SerenityOS
|
||||
- Haiku
|
||||
|
||||
## Contributing
|
||||
### See [docs/CODING_STYLE.MD](docs/CODING_STYLE.MD)
|
||||
|
||||
### See `CODING_STYLE.txt`
|
||||
## Building
|
||||
### See [docs/INSTALL.MD](docs/INSTALL.MD)
|
||||
|
||||
27
res/gui/editmode_toolbox/default.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<!--
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
-->
|
||||
|
||||
<gui>
|
||||
<button id="button_generate_platform" width="50%" height="25" tr_text="Generate platform" />
|
||||
</gui>
|
||||
31
res/gui/editmode_toolbox/selection.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<!--
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2024 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
-->
|
||||
|
||||
<gui>
|
||||
<label width="100%" height="25" tr_text="Fill with probability" />
|
||||
<container width="100%" height="25" layout="horizontal">
|
||||
<text_edit width="45%" height="100%" id="text_edit_fill" numbers_only="true" />
|
||||
<button width="45%" height="100%" left_margin="4" id="button_fill" tr_text="Fill" />
|
||||
</container>
|
||||
</gui>
|
||||
47
res/gui/game_session.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<!--
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2024 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
-->
|
||||
|
||||
<gui>
|
||||
<!-- Only visible in editmode -->
|
||||
<container width="100%" height="100%" id="container_editmode_hud" hidden="true">
|
||||
<item_gallery x="0" y="10" width="100%" height="128" id="item_gallery_nodes" />
|
||||
<label x="0" y="0" tr_text="Editmode enabled" />
|
||||
<label x="0" y="20" id="label_position" />
|
||||
<label x="0" y="40" id="label_target" />
|
||||
<label x="0" y="60" id="label_selection_info" />
|
||||
<label x="right" y="0" id="label_node_name" />
|
||||
</container>
|
||||
|
||||
<!-- Only visible when paused -->
|
||||
<box x="right" y="bottom" width="250" height="200" id="box_pause" hidden="true" right_margin="8" bottom_margin="8" tr_text="Pause" layout="fixed">
|
||||
<container x="center" y="1%" width="75%" height="99%" layout="vertical">
|
||||
<button width="100%" height="30" id="button_return" tr_text="Return" />
|
||||
<button width="100%" height="30" id="button_exit" tr_text="Exit" />
|
||||
</container>
|
||||
</box>
|
||||
|
||||
<!-- Always visible -->
|
||||
<image x="center" y="center" path="res/gui/crosschair.png" />
|
||||
<chat x="0" y="bottom" width="50%" height="40%" id="chat" />
|
||||
</gui>
|
||||
43
res/gui/main_menu.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<!--
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
-->
|
||||
|
||||
<gui>
|
||||
<image x="5" y="5" scale_x="2" scale_y="2" path="res/gui/polygun_header.png" />
|
||||
<box x="right" y="bottom" width="250" height="240" right_margin="8" bottom_margin="8" tr_text="Main Menu" layout="horizontal">
|
||||
<container width="50%" height="100%" layout="vertical">
|
||||
<label width="100%" height="25" tr_text="Nickname" />
|
||||
<label width="100%" height="25" tr_text="Server" />
|
||||
<label width="100%" height="25" tr_text="Port" />
|
||||
<button width="50%" height="30" id="button_join" tr_text="Join" />
|
||||
<!-- Note: Caption of button_host is set in code -->
|
||||
<button width="50%" height="30" id="button_host" />
|
||||
<button width="50%" height="30" id="button_options" tr_text="Options" />
|
||||
</container>
|
||||
<container width="45%" height="100%" layout="vertical">
|
||||
<text_edit width="97%" height="25" id="text_edit_nickname" />
|
||||
<text_edit width="97%" height="25" id="text_edit_server" />
|
||||
<text_edit width="97%" height="25" id="text_edit_port" numbers_only="true" text="1337" />
|
||||
</container>
|
||||
</box>
|
||||
</gui>
|
||||
45
res/gui/options.xml
Normal file
@@ -0,0 +1,45 @@
|
||||
<!--
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
-->
|
||||
|
||||
<gui>
|
||||
<box x="right" y="bottom" width="250" height="240" right_margin="8" bottom_margin="8" tr_text="Options" layout="vertical">
|
||||
<tab_view width="100%" height="170">
|
||||
<tab text="Video" layout="vertical">
|
||||
<container width="100%" height="35" layout="fixed">
|
||||
<label x="0" y="center" width="50%" height="100%" tr_text="Renderer (restart required)" text_size="14" />
|
||||
<combo_box x="right" y="0" width="48%" height="100%" right_margin="8" id="combo_box_renderer" />
|
||||
</container>
|
||||
<container width="100%" height="35" layout="fixed">
|
||||
<label x="0" y="center" width="50%" height="100%" tr_text="Meshing mode" text_size="14" />
|
||||
<combo_box x="right" y="0" width="48%" height="100%" right_margin="8" id="combo_box_meshing_mode" />
|
||||
</container>
|
||||
</tab>
|
||||
<tab text="Audio" layout="vertical">
|
||||
<label tr_text="Music volume" />
|
||||
<slider width="100%" height="30" id="slider_music_volume" />
|
||||
</tab>
|
||||
</tab_view>
|
||||
<button width="70" height="30" id="button_back" tr_text="Back" />
|
||||
</box>
|
||||
</gui>
|
||||
32
res/gui/styles/blue.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<!--
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
-->
|
||||
|
||||
<style>
|
||||
<text>
|
||||
<normal>255;255;255;255</normal>
|
||||
<inactive>36;56;54;255</inactive>
|
||||
</text>
|
||||
<font>res/fonts/PolyFont</font>
|
||||
<debug>false</debug>
|
||||
</style>
|
||||
|
Before Width: | Height: | Size: 682 B |
|
Before Width: | Height: | Size: 376 B |
|
Before Width: | Height: | Size: 196 B |
|
Before Width: | Height: | Size: 401 B |
|
Before Width: | Height: | Size: 423 B |
|
Before Width: | Height: | Size: 857 B |
|
Before Width: | Height: | Size: 289 B |
|
Before Width: | Height: | Size: 685 B |
|
Before Width: | Height: | Size: 692 B |
@@ -1,11 +0,0 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoord;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = texture(texture1, TexCoord);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec2 aTexCoord;
|
||||
|
||||
out vec2 TexCoord;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0f);
|
||||
TexCoord = vec2(aTexCoord.x, aTexCoord.y);
|
||||
}
|
||||
19
shaders/gl/chunk_fragment.glsl
Normal file
@@ -0,0 +1,19 @@
|
||||
#version 330 core
|
||||
|
||||
out vec4 out_frag_color;
|
||||
|
||||
in vec2 out_uv;
|
||||
in vec3 out_normal;
|
||||
in vec4 out_color;
|
||||
|
||||
uniform sampler2D uniform_texture_num;
|
||||
uniform float uniform_opacity;
|
||||
uniform float uniform_sunlight_intensity;
|
||||
uniform vec3 uniform_sky_light_color;
|
||||
|
||||
void main() {
|
||||
vec3 sunlight_layer = out_color.xyz * uniform_sunlight_intensity * (out_normal.y * 0.8 + 0.2);
|
||||
vec3 sky_light_layer = uniform_sky_light_color * (out_normal.y * 0.25 + 0.75);
|
||||
|
||||
out_frag_color = texture(uniform_texture_num, out_uv) * vec4(sunlight_layer + sky_light_layer, 1.0) * vec4(1, 1, 1, uniform_opacity);
|
||||
}
|
||||
20
shaders/gl/chunk_vertex.glsl
Normal file
@@ -0,0 +1,20 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 in_pos;
|
||||
layout (location = 1) in vec2 in_uv;
|
||||
layout (location = 2) in vec3 in_normal;
|
||||
layout (location = 3) in vec4 in_color;
|
||||
|
||||
out vec2 out_uv;
|
||||
out vec3 out_normal;
|
||||
out vec4 out_color;
|
||||
|
||||
uniform mat4 uniform_model;
|
||||
uniform mat4 uniform_view;
|
||||
uniform mat4 uniform_projection;
|
||||
|
||||
void main() {
|
||||
gl_Position = uniform_projection * uniform_view * uniform_model * vec4(in_pos/vec3(4.0), 1.0f);
|
||||
out_uv = in_uv;
|
||||
out_color = in_color;
|
||||
out_normal = in_normal;
|
||||
}
|
||||
16
shaders/gl/greedy_chunk_fragment.glsl
Normal file
@@ -0,0 +1,16 @@
|
||||
#version 330 core
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
flat in float out_node_id;
|
||||
in vec3 out_pixel_pos;
|
||||
|
||||
uniform sampler2D uniform_texture_num;
|
||||
uniform float uniform_texture_size;
|
||||
|
||||
void main() {
|
||||
vec2 uv;
|
||||
uv.x = (out_node_id-1)*uniform_texture_size+mod(out_pixel_pos.x+out_pixel_pos.z, 1)*uniform_texture_size;
|
||||
uv.y = 1-mod(out_pixel_pos.y, 1);
|
||||
FragColor = texture(uniform_texture_num, uv);
|
||||
}
|
||||
16
shaders/gl/greedy_chunk_vertex.glsl
Normal file
@@ -0,0 +1,16 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 in_pos;
|
||||
layout (location = 1) in float in_node_id;
|
||||
|
||||
flat out float out_node_id;
|
||||
out vec3 out_pixel_pos;
|
||||
|
||||
uniform mat4 uniform_model;
|
||||
uniform mat4 uniform_view;
|
||||
uniform mat4 uniform_projection;
|
||||
|
||||
void main() {
|
||||
gl_Position = uniform_projection * uniform_view * uniform_model * vec4(in_pos, 1.0f);
|
||||
out_pixel_pos = in_pos;
|
||||
out_node_id = in_node_id;
|
||||
}
|
||||
9
shaders/gl/gui_solid_fragment.glsl
Normal file
@@ -0,0 +1,9 @@
|
||||
#version 330 core
|
||||
|
||||
uniform vec4 uniform_color;
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
void main() {
|
||||
out_color = uniform_color;
|
||||
}
|
||||
10
shaders/gl/gui_solid_vertex.glsl
Normal file
@@ -0,0 +1,10 @@
|
||||
#version 330 core
|
||||
layout(location = 0) in vec3 in_pos;
|
||||
|
||||
uniform mat4 uniform_model;
|
||||
uniform mat4 uniform_view;
|
||||
uniform mat4 uniform_projection;
|
||||
|
||||
void main() {
|
||||
gl_Position = uniform_projection * uniform_view * uniform_model * vec4(in_pos, 1.0);
|
||||
}
|
||||
12
shaders/gl/gui_textured_fragment.glsl
Normal file
@@ -0,0 +1,12 @@
|
||||
#version 330 core
|
||||
|
||||
in vec2 out_uv;
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
uniform sampler2D uniform_texture_num;
|
||||
uniform vec4 uniform_color_mod;
|
||||
|
||||
void main() {
|
||||
out_color = texture(uniform_texture_num, out_uv) * uniform_color_mod;
|
||||
}
|
||||
15
shaders/gl/gui_textured_vertex.glsl
Normal file
@@ -0,0 +1,15 @@
|
||||
#version 330 core
|
||||
|
||||
layout(location = 0) in vec3 in_pos;
|
||||
layout(location = 1) in vec2 in_uv;
|
||||
|
||||
out vec2 out_uv;
|
||||
|
||||
uniform mat4 uniform_projection;
|
||||
uniform mat4 uniform_view;
|
||||
uniform mat4 uniform_model;
|
||||
|
||||
void main() {
|
||||
gl_Position = uniform_projection * uniform_view * uniform_model * vec4(in_pos, 1.0);
|
||||
out_uv = in_uv;
|
||||
}
|
||||
9
shaders/gl/node_preview_fragment.glsl
Normal file
@@ -0,0 +1,9 @@
|
||||
#version 330 core
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
uniform vec4 uniform_color;
|
||||
|
||||
void main() {
|
||||
out_color = uniform_color;
|
||||
}
|
||||
12
shaders/gl/node_preview_vertex.glsl
Normal file
@@ -0,0 +1,12 @@
|
||||
#version 330 core
|
||||
|
||||
layout(location = 0) in vec3 in_pos;
|
||||
|
||||
uniform mat4 uniform_projection;
|
||||
uniform mat4 uniform_view;
|
||||
uniform mat4 uniform_model;
|
||||
|
||||
void main() {
|
||||
gl_Position = uniform_projection * uniform_view * uniform_model * vec4(in_pos, 1.0);
|
||||
}
|
||||
|
||||
11
shaders/gl/object_fragment.glsl
Normal file
@@ -0,0 +1,11 @@
|
||||
#version 330 core
|
||||
|
||||
out vec4 out_frag_color;
|
||||
|
||||
in vec2 out_uv;
|
||||
|
||||
uniform sampler2D uniform_texture_num;
|
||||
|
||||
void main() {
|
||||
out_frag_color = texture(uniform_texture_num, out_uv);
|
||||
}
|
||||
14
shaders/gl/object_vertex.glsl
Normal file
@@ -0,0 +1,14 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 in_pos;
|
||||
layout (location = 1) in vec2 in_uv;
|
||||
|
||||
out vec2 out_uv;
|
||||
|
||||
uniform mat4 uniform_model;
|
||||
uniform mat4 uniform_view;
|
||||
uniform mat4 uniform_projection;
|
||||
|
||||
void main() {
|
||||
gl_Position = uniform_projection * uniform_view * uniform_model * vec4(in_pos, 1.0f);
|
||||
out_uv = in_uv;
|
||||
}
|
||||
54
shaders/gl/skybox_fragment.glsl
Normal file
@@ -0,0 +1,54 @@
|
||||
#version 330 core
|
||||
|
||||
out vec4 out_frag_color;
|
||||
|
||||
in vec3 out_pos;
|
||||
|
||||
#define glow_height (0.6)
|
||||
#define glow_blur (0.5)
|
||||
|
||||
uniform vec3 uniform_glow_color;
|
||||
uniform vec3 uniform_sun_vector;
|
||||
uniform float uniform_glow_intensity;
|
||||
uniform vec3 uniform_sky_color;
|
||||
uniform float uniform_stars_intensity;
|
||||
|
||||
|
||||
float map_range_clamped(float x, float in_min, float in_max, float out_min, float out_max) {
|
||||
return clamp((x - in_min) / (in_max - in_min), 0.0, 1.0) * (out_max - out_min) + out_min;
|
||||
}
|
||||
|
||||
float smoothstep_map_range(float x, float in_min, float in_max, float out_min, float out_max) {
|
||||
// scale to input range and clamp
|
||||
x = clamp((x - in_min) / (in_max - in_min), 0.0, 1.0);
|
||||
|
||||
// smoothstep
|
||||
x = x * x * (3.0 - 2.0 * x);
|
||||
|
||||
// scale to output range
|
||||
return x * (out_max - out_min) + out_min;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec3 sphere_pos = normalize(out_pos);
|
||||
|
||||
// golden glow
|
||||
float glow_displacement = dot(uniform_sun_vector, sphere_pos);
|
||||
glow_displacement = map_range_clamped(glow_displacement, 1.0, -1.0, -glow_height, 0.0) + sphere_pos.y;
|
||||
|
||||
float glow_center = map_range_clamped(uniform_glow_intensity, 0.0, 1.0, -1.0, -0.5);
|
||||
|
||||
float glow = smoothstep_map_range(glow_displacement, glow_center + glow_blur, glow_center - glow_blur, 0.0, 1.0) * uniform_glow_intensity;
|
||||
|
||||
|
||||
// sky fill gradient
|
||||
vec3 sky_gradient = smoothstep_map_range(sphere_pos.y, 1.0, -1.0, 0.33333, 3.0) * uniform_sky_color;
|
||||
|
||||
// stars
|
||||
float stars = 0.0 * uniform_stars_intensity; // not implemented
|
||||
|
||||
// final color
|
||||
vec3 final_color = mix(sky_gradient, uniform_glow_color, glow) + stars;
|
||||
|
||||
out_frag_color = vec4(final_color, 1.0);
|
||||
}
|
||||
17
shaders/gl/skybox_vertex.glsl
Normal file
@@ -0,0 +1,17 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 in_pos;
|
||||
|
||||
out vec3 out_pos;
|
||||
|
||||
uniform mat4 uniform_view;
|
||||
uniform mat4 uniform_projection;
|
||||
|
||||
void main() {
|
||||
mat4 view_copy = uniform_view;
|
||||
view_copy[3] = vec4(0, 0, 0, 1);
|
||||
view_copy[0][3] = 0;
|
||||
view_copy[1][3] = 0;
|
||||
view_copy[2][3] = 0;
|
||||
gl_Position = uniform_projection * view_copy * vec4(in_pos, 1.0f);
|
||||
out_pos = in_pos;
|
||||
}
|
||||
22
shaders/gl2/chunk_fragment.glsl
Normal file
@@ -0,0 +1,22 @@
|
||||
#version 110
|
||||
|
||||
varying vec2 out_uv;
|
||||
varying vec3 out_normal;
|
||||
varying vec4 out_color;
|
||||
|
||||
uniform sampler2D uniform_texture_num;
|
||||
uniform float uniform_opacity;
|
||||
uniform float uniform_sunlight_intensity;
|
||||
uniform vec3 uniform_sky_light_color;
|
||||
|
||||
void main() {
|
||||
vec3 sunlight_layer = out_color.xyz * uniform_sunlight_intensity * (out_normal.y * 0.8 + 0.2);
|
||||
vec3 sky_light_layer = uniform_sky_light_color * (out_normal.y * 0.25 + 0.75);
|
||||
|
||||
vec4 final_color = texture2D(uniform_texture_num, out_uv) * vec4(sunlight_layer + sky_light_layer, 1.0) * vec4(1, 1, 1, uniform_opacity);
|
||||
|
||||
// temporary gamma correction
|
||||
final_color = pow(final_color, vec4(1.0 / 2.4));
|
||||
|
||||
gl_FragColor = final_color;
|
||||
}
|
||||
20
shaders/gl2/chunk_vertex.glsl
Normal file
@@ -0,0 +1,20 @@
|
||||
#version 110
|
||||
attribute vec3 in_pos;
|
||||
attribute vec2 in_uv;
|
||||
attribute vec3 in_normal;
|
||||
attribute vec4 in_color;
|
||||
|
||||
varying vec2 out_uv;
|
||||
varying vec3 out_normal;
|
||||
varying vec4 out_color;
|
||||
|
||||
uniform mat4 uniform_projection;
|
||||
uniform mat4 uniform_view;
|
||||
uniform mat4 uniform_model;
|
||||
|
||||
void main() {
|
||||
gl_Position = uniform_projection * uniform_view * uniform_model * vec4(in_pos/vec3(4.0), 1.0);
|
||||
out_uv = in_uv;
|
||||
out_color = in_color;
|
||||
out_normal = in_normal;
|
||||
}
|
||||
14
shaders/gl2/greedy_chunk_fragment.glsl
Normal file
@@ -0,0 +1,14 @@
|
||||
#version 110
|
||||
|
||||
varying float out_node_id;
|
||||
varying vec3 out_pixel_pos;
|
||||
|
||||
uniform sampler2D uniform_texture_num;
|
||||
uniform float uniform_texture_size;
|
||||
|
||||
void main() {
|
||||
vec2 uv;
|
||||
uv.x = (out_node_id-1.0)*uniform_texture_size+mod(out_pixel_pos.x+out_pixel_pos.z, 1.0)*uniform_texture_size;
|
||||
uv.y = 1.0-mod(out_pixel_pos.y, 1.0);
|
||||
gl_FragColor = texture2D(uniform_texture_num, uv);
|
||||
}
|
||||
16
shaders/gl2/greedy_chunk_vertex.glsl
Normal file
@@ -0,0 +1,16 @@
|
||||
#version 110
|
||||
attribute vec3 in_pos;
|
||||
attribute float in_0;
|
||||
|
||||
varying float out_node_id;
|
||||
varying vec3 out_pixel_pos;
|
||||
|
||||
uniform mat4 uniform_model;
|
||||
uniform mat4 uniform_view;
|
||||
uniform mat4 uniform_projection;
|
||||
|
||||
void main() {
|
||||
gl_Position = uniform_projection * uniform_view * uniform_model * vec4(in_pos, 1.0);
|
||||
out_node_id = in_0;
|
||||
out_pixel_pos = in_pos;
|
||||
}
|
||||
7
shaders/gl2/gui_solid_fragment.glsl
Normal file
@@ -0,0 +1,7 @@
|
||||
#version 110
|
||||
|
||||
uniform vec4 uniform_color;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = uniform_color;
|
||||
}
|
||||
10
shaders/gl2/gui_solid_vertex.glsl
Normal file
@@ -0,0 +1,10 @@
|
||||
#version 110
|
||||
attribute vec3 in_pos;
|
||||
|
||||
uniform mat4 uniform_model;
|
||||
uniform mat4 uniform_view;
|
||||
uniform mat4 uniform_projection;
|
||||
|
||||
void main() {
|
||||
gl_Position = uniform_projection * uniform_view * uniform_model * vec4(in_pos, 1.0);
|
||||
}
|
||||
10
shaders/gl2/gui_textured_fragment.glsl
Normal file
@@ -0,0 +1,10 @@
|
||||
#version 110
|
||||
|
||||
varying vec2 out_uv;
|
||||
|
||||
uniform sampler2D uniform_texture_num;
|
||||
uniform vec4 uniform_color_mod;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = texture2D(uniform_texture_num, out_uv) * uniform_color_mod;
|
||||
}
|
||||
14
shaders/gl2/gui_textured_vertex.glsl
Normal file
@@ -0,0 +1,14 @@
|
||||
#version 110
|
||||
attribute vec3 in_pos;
|
||||
attribute vec2 in_uv;
|
||||
|
||||
varying vec2 out_uv;
|
||||
|
||||
uniform mat4 uniform_projection;
|
||||
uniform mat4 uniform_view;
|
||||
uniform mat4 uniform_model;
|
||||
|
||||
void main() {
|
||||
gl_Position = uniform_projection * uniform_view * uniform_model * vec4(in_pos, 1.0);
|
||||
out_uv = in_uv;
|
||||
}
|
||||
7
shaders/gl2/node_preview_fragment.glsl
Normal file
@@ -0,0 +1,7 @@
|
||||
#version 110
|
||||
|
||||
uniform vec4 uniform_color;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = uniform_color;
|
||||
}
|
||||
10
shaders/gl2/node_preview_vertex.glsl
Normal file
@@ -0,0 +1,10 @@
|
||||
#version 110
|
||||
attribute vec3 in_pos;
|
||||
|
||||
uniform mat4 uniform_projection;
|
||||
uniform mat4 uniform_view;
|
||||
uniform mat4 uniform_model;
|
||||
|
||||
void main() {
|
||||
gl_Position = uniform_projection * uniform_view * uniform_model * vec4(in_pos, 1.0);
|
||||
}
|
||||
9
shaders/gl2/object_fragment.glsl
Normal file
@@ -0,0 +1,9 @@
|
||||
#version 110
|
||||
|
||||
varying vec2 out_uv;
|
||||
|
||||
uniform sampler2D uniform_texture_num;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = texture2D(uniform_texture_num, out_uv);
|
||||
}
|
||||
14
shaders/gl2/object_vertex.glsl
Normal file
@@ -0,0 +1,14 @@
|
||||
#version 110
|
||||
attribute vec3 in_pos;
|
||||
attribute vec2 in_uv;
|
||||
|
||||
varying vec2 out_uv;
|
||||
|
||||
uniform mat4 uniform_projection;
|
||||
uniform mat4 uniform_view;
|
||||
uniform mat4 uniform_model;
|
||||
|
||||
void main() {
|
||||
gl_Position = uniform_projection * uniform_view * uniform_model * vec4(in_pos, 1.0);
|
||||
out_uv = in_uv;
|
||||
}
|
||||
55
shaders/gl2/skybox_fragment.glsl
Normal file
@@ -0,0 +1,55 @@
|
||||
#version 110
|
||||
|
||||
varying vec3 out_pos;
|
||||
|
||||
#define glow_height (0.6)
|
||||
#define glow_blur (0.5)
|
||||
|
||||
uniform vec3 uniform_glow_color;
|
||||
uniform vec3 uniform_sun_vector;
|
||||
uniform float uniform_glow_intensity;
|
||||
uniform vec3 uniform_sky_color;
|
||||
uniform float uniform_stars_intensity;
|
||||
|
||||
|
||||
float map_range_clamped(float x, float in_min, float in_max, float out_min, float out_max) {
|
||||
return clamp((x - in_min) / (in_max - in_min), 0.0, 1.0) * (out_max - out_min) + out_min;
|
||||
}
|
||||
|
||||
float smoothstep_map_range(float x, float in_min, float in_max, float out_min, float out_max) {
|
||||
// scale to input range and clamp
|
||||
x = clamp((x - in_min) / (in_max - in_min), 0.0, 1.0);
|
||||
|
||||
// smoothstep
|
||||
x = x * x * (3.0 - 2.0 * x);
|
||||
|
||||
// scale to output range
|
||||
return x * (out_max - out_min) + out_min;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec3 sphere_pos = normalize(out_pos);
|
||||
|
||||
// golden glow
|
||||
float glow_displacement = dot(uniform_sun_vector, sphere_pos);
|
||||
glow_displacement = map_range_clamped(glow_displacement, 1.0, -1.0, -glow_height, 0.0) + sphere_pos.y;
|
||||
|
||||
float glow_center = map_range_clamped(uniform_glow_intensity, 0.0, 1.0, -1.0, -0.5);
|
||||
|
||||
float glow = smoothstep_map_range(glow_displacement, glow_center + glow_blur, glow_center - glow_blur, 0.0, 1.0) * uniform_glow_intensity;
|
||||
|
||||
|
||||
// sky fill gradient
|
||||
vec3 sky_gradient = smoothstep_map_range(sphere_pos.y, 1.0, -1.0, 0.33333, 3.0) * uniform_sky_color;
|
||||
|
||||
// stars
|
||||
float stars = 0.0 * uniform_stars_intensity; // not implemented
|
||||
|
||||
// final color
|
||||
vec3 final_color = mix(sky_gradient, uniform_glow_color, glow) + stars;
|
||||
|
||||
// gamma correction (temporary solution)
|
||||
final_color = pow(final_color, vec3(1.0 / 2.4));
|
||||
|
||||
gl_FragColor = vec4(final_color, 1.0);
|
||||
}
|
||||
17
shaders/gl2/skybox_vertex.glsl
Normal file
@@ -0,0 +1,17 @@
|
||||
#version 110
|
||||
attribute vec3 in_pos;
|
||||
|
||||
varying vec3 out_pos;
|
||||
|
||||
uniform mat4 uniform_view;
|
||||
uniform mat4 uniform_projection;
|
||||
|
||||
void main() {
|
||||
mat4 view_copy = uniform_view;
|
||||
view_copy[3] = vec4(0, 0, 0, 1);
|
||||
view_copy[0][3] = 0.0;
|
||||
view_copy[1][3] = 0.0;
|
||||
view_copy[2][3] = 0.0;
|
||||
gl_Position = uniform_projection * view_copy * vec4(in_pos, 1.0);
|
||||
out_pos = in_pos;
|
||||
}
|
||||
182
src/common/as/ast.cpp
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2024 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "common/as/ast.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "common/as/vm.hpp"
|
||||
|
||||
using namespace polygun::as;
|
||||
|
||||
Expression::Expression(ValueType result_type) :
|
||||
m_result_type(result_type)
|
||||
{}
|
||||
|
||||
LiteralExpression::LiteralExpression(const Value& value, ValueType type) :
|
||||
Expression(type),
|
||||
m_value(value)
|
||||
{}
|
||||
|
||||
BinaryExpression::BinaryExpression(BinaryExpression::Operation op, std::unique_ptr<Expression> lhs, std::unique_ptr<Expression> rhs) :
|
||||
Expression(get_wider_type(lhs->get_result_type(), rhs->get_result_type())),
|
||||
m_op(op),
|
||||
m_lhs(std::move(lhs)),
|
||||
m_rhs(std::move(rhs))
|
||||
{}
|
||||
|
||||
Value BinaryExpression::eval(VM& vm) {
|
||||
Value result;
|
||||
const Value lhs_value = m_lhs->eval(vm);
|
||||
const Value rhs_value = m_rhs->eval(vm);
|
||||
const double lhs_result = value_as<double>(lhs_value, m_lhs->get_result_type());
|
||||
const double rhs_result = value_as<double>(rhs_value, m_rhs->get_result_type());
|
||||
|
||||
switch(m_op) {
|
||||
case Operation::OPERATION_ADD:
|
||||
to_value<double>(lhs_result+rhs_result, m_result_type, result);
|
||||
break;
|
||||
case Operation::OPERATION_SUB:
|
||||
to_value<double>(lhs_result-rhs_result, m_result_type, result);
|
||||
break;
|
||||
case Operation::OPERATION_MUL:
|
||||
to_value<double>(lhs_result*rhs_result, m_result_type, result);
|
||||
break;
|
||||
case Operation::OPERATION_DIV:
|
||||
to_value<double>(lhs_result/rhs_result, m_result_type, result);
|
||||
break;
|
||||
case Operation::OPERATION_MOD:
|
||||
// % can't be performed on fractional numbers so use int here
|
||||
to_value<int>(value_as<int>(lhs_value, m_lhs->get_result_type())%value_as<int>(rhs_value, m_rhs->get_result_type()), m_result_type, result);
|
||||
break;
|
||||
case Operation::OPERATION_EXP:
|
||||
to_value<double>(std::pow(lhs_result, rhs_result), m_result_type, result);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
StatementBlock::StatementBlock() :
|
||||
Expression(ValueType::VALUE_TYPE_VOID),
|
||||
m_exprs()
|
||||
{}
|
||||
|
||||
void StatementBlock::add_expression(std::unique_ptr<Expression> expr) {
|
||||
m_exprs.push_back(std::move(expr));
|
||||
}
|
||||
|
||||
Value StatementBlock::eval(VM& vm) {
|
||||
for(std::unique_ptr<Expression>& expr : m_exprs)
|
||||
expr->eval(vm);
|
||||
return Value{};
|
||||
}
|
||||
|
||||
FunctionDefinition::FunctionDefinition(VarType result_type, const std::vector<VarType>& argument_types, std::unique_ptr<StatementBlock> body) :
|
||||
m_result_type(result_type),
|
||||
m_argument_types(argument_types),
|
||||
m_body(std::move(body))
|
||||
{}
|
||||
|
||||
Value FunctionDefinition::eval(VM& vm) {
|
||||
m_body->eval(vm);
|
||||
return vm.get_return_value();
|
||||
}
|
||||
|
||||
VariableAssignment::VariableAssignment(VarType type, Location location, unsigned offset, std::unique_ptr<Expression> rhs) :
|
||||
Expression(var_type_to_value_type(type)),
|
||||
m_var_type(type),
|
||||
m_location(location),
|
||||
m_offset(offset),
|
||||
m_rhs(std::move(rhs))
|
||||
{}
|
||||
|
||||
Value VariableAssignment::eval(VM& vm) {
|
||||
const Value rhs_value = m_rhs->eval(vm);
|
||||
unsigned addr;
|
||||
switch(m_location) {
|
||||
case Location::LOCATION_STACK:
|
||||
addr = vm.get_stack_ptr()-m_offset;
|
||||
break;
|
||||
case Location::LOCATION_STATIC:
|
||||
addr = m_offset;
|
||||
break;
|
||||
}
|
||||
vm.set_value_at(m_location, addr, rhs_value, m_var_type);
|
||||
return rhs_value;
|
||||
}
|
||||
|
||||
FunctionCall::FunctionCall(VM& vm, FunctionType func_type, unsigned address, std::vector<std::unique_ptr<Expression>> arguments) :
|
||||
Expression(ValueType::VALUE_TYPE_VOID),
|
||||
m_func_type(func_type),
|
||||
m_address(address),
|
||||
m_arguments(std::move(arguments))
|
||||
{
|
||||
switch(func_type) {
|
||||
case FunctionType::FUNCTION_NORMAL:
|
||||
// TODO
|
||||
break;
|
||||
case FunctionType::FUNCTION_NATIVE:
|
||||
m_result_type = var_type_to_value_type(vm.get_native_function_by_address(address).m_result_type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Value FunctionCall::eval(VM& vm) {
|
||||
std::vector<Value> argument_values;
|
||||
argument_values.reserve(m_arguments.size());
|
||||
for(std::unique_ptr<Expression>& arg : m_arguments)
|
||||
argument_values.push_back(arg->eval(vm));
|
||||
|
||||
switch(m_func_type) {
|
||||
case FunctionType::FUNCTION_NORMAL:
|
||||
// TODO
|
||||
break;
|
||||
case FunctionType::FUNCTION_NATIVE:
|
||||
return vm.get_native_function_by_address(m_address).m_func(vm, argument_values);
|
||||
}
|
||||
return Value{};
|
||||
}
|
||||
|
||||
VariableExpression::VariableExpression(VarType type, Location location, unsigned offset) :
|
||||
Expression(var_type_to_value_type(type)),
|
||||
m_var_type(type),
|
||||
m_location(location),
|
||||
m_offset(offset)
|
||||
{}
|
||||
|
||||
Value VariableExpression::eval(VM& vm) {
|
||||
Value value;
|
||||
unsigned addr;
|
||||
switch(m_location) {
|
||||
case Location::LOCATION_STACK:
|
||||
addr = vm.get_stack_ptr()-m_offset;
|
||||
break;
|
||||
case Location::LOCATION_STATIC:
|
||||
addr = m_offset;
|
||||
break;
|
||||
}
|
||||
vm.get_value_at(m_location, addr, m_var_type, value);
|
||||
return value;
|
||||
}
|
||||
142
src/common/as/ast.hpp
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2024 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef POLYGUN_AS_AST_HPP
|
||||
#define POLYGUN_AS_AST_HPP
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "common/as/value.hpp"
|
||||
|
||||
namespace polygun::as {
|
||||
class VM;
|
||||
class Expression {
|
||||
public:
|
||||
Expression(ValueType result_type);
|
||||
virtual ~Expression() = default;
|
||||
|
||||
ValueType get_result_type() const { return m_result_type; }
|
||||
|
||||
virtual Value eval(VM& vm) = 0;
|
||||
|
||||
protected:
|
||||
ValueType m_result_type;
|
||||
};
|
||||
|
||||
class LiteralExpression final : public Expression {
|
||||
public:
|
||||
LiteralExpression(const Value& value, ValueType type);
|
||||
|
||||
virtual Value eval(VM& vm) override { return m_value; }
|
||||
|
||||
private:
|
||||
Value m_value;
|
||||
};
|
||||
|
||||
class BinaryExpression final : public Expression {
|
||||
public:
|
||||
enum Operation {
|
||||
OPERATION_ADD,
|
||||
OPERATION_SUB,
|
||||
OPERATION_MUL,
|
||||
OPERATION_DIV,
|
||||
OPERATION_MOD,
|
||||
OPERATION_EXP
|
||||
};
|
||||
|
||||
public:
|
||||
BinaryExpression(Operation op, std::unique_ptr<Expression> lhs, std::unique_ptr<Expression> rhs);
|
||||
|
||||
virtual Value eval(VM& vm) override;
|
||||
|
||||
private:
|
||||
Operation m_op;
|
||||
std::unique_ptr<Expression> m_lhs;
|
||||
std::unique_ptr<Expression> m_rhs;
|
||||
};
|
||||
|
||||
class StatementBlock final : public Expression {
|
||||
public:
|
||||
StatementBlock();
|
||||
~StatementBlock() = default;
|
||||
|
||||
void add_expression(std::unique_ptr<Expression> expr);
|
||||
|
||||
virtual Value eval(VM& vm) override;
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<Expression>> m_exprs;
|
||||
};
|
||||
|
||||
class FunctionDefinition final {
|
||||
public:
|
||||
FunctionDefinition(VarType result_type, const std::vector<VarType>& argument_types, std::unique_ptr<StatementBlock> body);
|
||||
Value eval(VM& vm);
|
||||
|
||||
private:
|
||||
VarType m_result_type;
|
||||
std::vector<VarType> m_argument_types;
|
||||
std::unique_ptr<StatementBlock> m_body;
|
||||
};
|
||||
|
||||
class VariableAssignment final : public Expression {
|
||||
public:
|
||||
VariableAssignment(VarType type, Location location, unsigned offset, std::unique_ptr<Expression> rhs);
|
||||
|
||||
virtual Value eval(VM& vm) override;
|
||||
|
||||
private:
|
||||
VarType m_var_type;
|
||||
Location m_location;
|
||||
unsigned m_offset;
|
||||
std::unique_ptr<Expression> m_rhs;
|
||||
};
|
||||
|
||||
class FunctionCall final : public Expression {
|
||||
public:
|
||||
FunctionCall(VM& vm, FunctionType func_type, unsigned address, std::vector<std::unique_ptr<Expression>> arguments);
|
||||
|
||||
virtual Value eval(VM& vm) override;
|
||||
|
||||
private:
|
||||
FunctionType m_func_type;
|
||||
unsigned m_address;
|
||||
std::vector<std::unique_ptr<Expression>> m_arguments;
|
||||
};
|
||||
|
||||
class VariableExpression final : public Expression {
|
||||
public:
|
||||
VariableExpression(VarType type, Location location, unsigned offset);
|
||||
|
||||
virtual Value eval(VM& vm) override;
|
||||
|
||||
private:
|
||||
VarType m_var_type;
|
||||
Location m_location;
|
||||
unsigned m_offset;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // POLYGUN_AS_AST_HPP
|
||||
330
src/common/as/lexer.cpp
Normal file
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2024 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "common/as/lexer.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
using namespace polygun::as;
|
||||
|
||||
static const std::map<char, TokenType> g_simple_token_mapping = {
|
||||
{'(', TokenType::TOKEN_LBRACKET},
|
||||
{')', TokenType::TOKEN_RBRACKET},
|
||||
{'[', TokenType::TOKEN_SQUARE_LBRACKET},
|
||||
{']', TokenType::TOKEN_SQUARE_RBRACKET},
|
||||
{'{', TokenType::TOKEN_SCOPE_LBRACKET},
|
||||
{'}', TokenType::TOKEN_SCOPE_RBRACKET},
|
||||
{',', TokenType::TOKEN_COMMA},
|
||||
{';', TokenType::TOKEN_SEMICOLON},
|
||||
{'!', TokenType::TOKEN_NOT},
|
||||
{'@', TokenType::TOKEN_HANDLE}
|
||||
};
|
||||
|
||||
static const std::string g_token_names[] = {
|
||||
"EMPTY",
|
||||
"IDENTIFIER",
|
||||
"LBRACKET",
|
||||
"RBRACKET",
|
||||
"SQUARE_LBRACKET",
|
||||
"SQUARE_RBRACKET",
|
||||
"SCOPE_LBRACKET",
|
||||
"SCOPE_RBRACKET",
|
||||
"COMMA",
|
||||
"SEMICOLON",
|
||||
"COLON",
|
||||
"SCOPE",
|
||||
"EQUALS",
|
||||
"PLUS",
|
||||
"MINUS",
|
||||
"MULTIPLY",
|
||||
"DIVIDE",
|
||||
"MOD",
|
||||
"EXP",
|
||||
"BITWISE_COMP",
|
||||
"BITWISE_AND",
|
||||
"BITWISE_OR",
|
||||
"BITWISE_XOR",
|
||||
"BITWISE_LEFT_SHIFT",
|
||||
"BITWISE_RIGHT_SHIFT",
|
||||
"ARITHMETIC_RIGHT_SHIFT",
|
||||
"EQUALS_PLUS",
|
||||
"EQUALS_MINUS",
|
||||
"EQUALS_MULTIPLY",
|
||||
"EQUALS_DIVIDE",
|
||||
"EQUALS_MOD",
|
||||
"EQUALS_EXP",
|
||||
"EQUALS_BITWISE_COMP",
|
||||
"EQUALS_BITWISE_AND",
|
||||
"EQUALS_BITWISE_OR",
|
||||
"EQUALS_BITWISE_XOR",
|
||||
"EQUALS_BITWISE_LEFT_SHIFT",
|
||||
"EQUALS_BITWISE_RIGHT_SHIFT",
|
||||
"EQUALS_ARITHMETIC_RIGHT_SHIFT",
|
||||
"INCREMENT",
|
||||
"DECREMENT",
|
||||
"CONDITIONAL",
|
||||
"NOT",
|
||||
"AND",
|
||||
"OR",
|
||||
"XOR",
|
||||
"EQUAL",
|
||||
"NOT_EQUAL",
|
||||
"LESS",
|
||||
"GREATER",
|
||||
"LESS_OR_EQUAL",
|
||||
"GREATER_OR_EQUAL",
|
||||
"STRING",
|
||||
"INTEGER",
|
||||
"FRACTIONAL",
|
||||
"HANDLE"
|
||||
};
|
||||
|
||||
Lexer::Lexer(std::istream& input) :
|
||||
m_input(input),
|
||||
m_line(1),
|
||||
m_line_start(0),
|
||||
m_identifier()
|
||||
{
|
||||
memset(m_identifier, 0, sizeof(m_identifier));
|
||||
}
|
||||
|
||||
Token Lexer::consume_token(unsigned offset) {
|
||||
Token result;
|
||||
for(unsigned i = 0; i<offset; i++)
|
||||
result = next_token();
|
||||
return result;
|
||||
}
|
||||
|
||||
Token Lexer::peek_token(unsigned offset) {
|
||||
const std::streampos prev_pos = m_input.tellg();
|
||||
Token result;
|
||||
for(unsigned i = 0; i<offset; i++)
|
||||
result = next_token();
|
||||
m_input.seekg(prev_pos);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Lexer::has_next_token() {
|
||||
consume_whitespace();
|
||||
return !m_input.eof();
|
||||
}
|
||||
|
||||
void Lexer::consume_whitespace() {
|
||||
char ch;
|
||||
while(!m_input.eof() && isspace(ch = m_input.peek())) {
|
||||
handle_newline();
|
||||
m_input.ignore();
|
||||
}
|
||||
}
|
||||
|
||||
bool Lexer::handle_newline() {
|
||||
if(m_input.peek()=='\n') {
|
||||
m_line++;
|
||||
m_line_start = m_input.tellg()+1L;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Token Lexer::next_token() {
|
||||
consume_whitespace();
|
||||
|
||||
char ch;
|
||||
Token result;
|
||||
result.m_type = TokenType::TOKEN_EMPTY;
|
||||
while(!m_input.eof()) {
|
||||
ch = m_input.get();
|
||||
if(g_simple_token_mapping.count(ch)) {
|
||||
result.m_type = g_simple_token_mapping.at(ch);
|
||||
result.m_line = m_line;
|
||||
result.m_line_offset = static_cast<unsigned>(m_input.tellg())-m_line_start+1;
|
||||
return result;
|
||||
}
|
||||
switch(ch) {
|
||||
case ':':
|
||||
result.m_type = resolve_similar(ch, TokenType::TOKEN_COLON, TokenType::TOKEN_SCOPE);
|
||||
break;
|
||||
case '=':
|
||||
result.m_type = resolve_similar(ch, TokenType::TOKEN_EQUALS, TokenType::TOKEN_EQUAL);
|
||||
break;
|
||||
case '+':
|
||||
result.m_type = resolve_starting_similar({
|
||||
{'+', TokenType::TOKEN_INCREMENT},
|
||||
{'=', TokenType::TOKEN_EQUALS_PLUS}
|
||||
}, TokenType::TOKEN_PLUS);
|
||||
break;
|
||||
case '-':
|
||||
result.m_type = resolve_starting_similar({
|
||||
{'-', TokenType::TOKEN_DECREMENT},
|
||||
{'=', TokenType::TOKEN_EQUALS_MINUS}
|
||||
}, TokenType::TOKEN_MINUS);
|
||||
break;
|
||||
case '*':
|
||||
result.m_type = resolve_starting_similar({
|
||||
{'*', TokenType::TOKEN_EXP},
|
||||
{'=', TokenType::TOKEN_EQUALS_MULTIPLY}
|
||||
}, TokenType::TOKEN_MULTIPLY);
|
||||
break;
|
||||
case '/':
|
||||
// TODO: Multiline comments
|
||||
switch(m_input.peek()) {
|
||||
case '/':
|
||||
while(!handle_newline())
|
||||
m_input.ignore();
|
||||
m_input.ignore();
|
||||
consume_whitespace();
|
||||
continue;
|
||||
case '=':
|
||||
m_input.ignore();
|
||||
result.m_type = TokenType::TOKEN_EQUALS_DIVIDE;
|
||||
break;
|
||||
default:
|
||||
result.m_type = TokenType::TOKEN_DIVIDE;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '%':
|
||||
result.m_type = resolve_starting_similar({
|
||||
{'=', TokenType::TOKEN_EQUALS_MOD}
|
||||
}, TokenType::TOKEN_MOD);
|
||||
break;
|
||||
case '~':
|
||||
result.m_type = resolve_starting_similar({
|
||||
{'=', TokenType::TOKEN_EQUALS_BITWISE_COMP},
|
||||
}, TokenType::TOKEN_BITWISE_COMP);
|
||||
break;
|
||||
case '&':
|
||||
result.m_type = resolve_starting_similar({
|
||||
{'&', TokenType::TOKEN_AND},
|
||||
{'=', TokenType::TOKEN_EQUALS_BITWISE_AND}
|
||||
}, TokenType::TOKEN_MULTIPLY);
|
||||
break;
|
||||
case '|':
|
||||
result.m_type = resolve_starting_similar({
|
||||
{'|', TokenType::TOKEN_OR},
|
||||
{'=', TokenType::TOKEN_EQUALS_BITWISE_OR}
|
||||
}, TokenType::TOKEN_BITWISE_OR);
|
||||
break;
|
||||
case '^':
|
||||
result.m_type = resolve_starting_similar({
|
||||
{'^', TokenType::TOKEN_XOR},
|
||||
{'=', TokenType::TOKEN_EQUALS_BITWISE_XOR}
|
||||
}, TokenType::TOKEN_BITWISE_XOR);
|
||||
break;
|
||||
case '<':
|
||||
switch(m_input.peek()) {
|
||||
case '<':
|
||||
m_input.ignore();
|
||||
if(m_input.peek()=='=') {
|
||||
m_input.ignore();
|
||||
result.m_type = TokenType::TOKEN_EQUALS_BITWISE_LEFT_SHIFT;
|
||||
}
|
||||
else
|
||||
result.m_type = TokenType::TOKEN_BITWISE_LEFT_SHIFT;
|
||||
break;
|
||||
case '=':
|
||||
m_input.ignore();
|
||||
result.m_type = TokenType::TOKEN_LESS_OR_EQUAL;
|
||||
break;
|
||||
default:
|
||||
result.m_type = TokenType::TOKEN_LESS;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '>':
|
||||
switch(m_input.peek()) {
|
||||
case '>':
|
||||
m_input.ignore();
|
||||
switch(m_input.peek()) {
|
||||
case '>':
|
||||
m_input.ignore();
|
||||
result.m_type = TokenType::TOKEN_ARITHMETIC_RIGHT_SHIFT;
|
||||
break;
|
||||
case '=':
|
||||
m_input.ignore();
|
||||
result.m_type = TokenType::TOKEN_EQUALS_BITWISE_RIGHT_SHIFT;
|
||||
break;
|
||||
default:
|
||||
result.m_type = TokenType::TOKEN_BITWISE_RIGHT_SHIFT;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '=':
|
||||
m_input.ignore();
|
||||
result.m_type = TokenType::TOKEN_GREATER_OR_EQUAL;
|
||||
break;
|
||||
default:
|
||||
result.m_type = TokenType::TOKEN_GREATER;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(result.m_type==TokenType::TOKEN_EMPTY) {
|
||||
// Check if character is a valid identifier start
|
||||
if(isalpha(ch) || ch=='_') {
|
||||
unsigned offset = 0;
|
||||
while(isalnum(ch) || ch=='_') {
|
||||
m_identifier[offset++] = ch;
|
||||
ch = m_input.get();
|
||||
}
|
||||
m_input.unget();
|
||||
m_identifier[offset] = 0;
|
||||
result.m_type = TokenType::TOKEN_IDENTIFIER;
|
||||
result.m_data = m_identifier;
|
||||
}
|
||||
}
|
||||
result.m_line = m_line;
|
||||
result.m_line_offset = static_cast<unsigned>(m_input.tellg())-m_line_start+1;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
TokenType Lexer::resolve_similar(char ch, TokenType first, TokenType second) {
|
||||
if(m_input.peek()==ch) {
|
||||
m_input.ignore();
|
||||
return second;
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
TokenType Lexer::resolve_starting_similar(const std::map<char, TokenType>& endings, TokenType def) {
|
||||
const char next_ch = m_input.peek();
|
||||
if(endings.count(next_ch)) {
|
||||
m_input.ignore();
|
||||
return endings.at(next_ch);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
const std::string& polygun::as::get_token_name(TokenType type) {
|
||||
return g_token_names[type];
|
||||
}
|
||||
|
||||
void polygun::as::dump_token(const Token& token) {
|
||||
std::cout<<g_token_names[token.m_type]<<std::endl;
|
||||
if(token.m_type==TokenType::TOKEN_IDENTIFIER)
|
||||
std::cout<<" "<<token.m_data<<std::endl;
|
||||
}
|
||||
127
src/common/as/lexer.hpp
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2024 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef POLYGUN_AS_LEXER_HPP
|
||||
#define POLYGUN_AS_LEXER_HPP
|
||||
|
||||
#include <istream>
|
||||
#include <map>
|
||||
|
||||
namespace polygun::as {
|
||||
enum TokenType {
|
||||
TOKEN_EMPTY,
|
||||
TOKEN_IDENTIFIER,
|
||||
TOKEN_LBRACKET,
|
||||
TOKEN_RBRACKET,
|
||||
TOKEN_SQUARE_LBRACKET,
|
||||
TOKEN_SQUARE_RBRACKET,
|
||||
TOKEN_SCOPE_LBRACKET,
|
||||
TOKEN_SCOPE_RBRACKET,
|
||||
TOKEN_COMMA,
|
||||
TOKEN_SEMICOLON,
|
||||
TOKEN_COLON,
|
||||
TOKEN_SCOPE,
|
||||
TOKEN_EQUALS,
|
||||
TOKEN_PLUS,
|
||||
TOKEN_MINUS,
|
||||
TOKEN_MULTIPLY,
|
||||
TOKEN_DIVIDE,
|
||||
TOKEN_MOD,
|
||||
TOKEN_EXP,
|
||||
TOKEN_BITWISE_COMP,
|
||||
TOKEN_BITWISE_AND,
|
||||
TOKEN_BITWISE_OR,
|
||||
TOKEN_BITWISE_XOR,
|
||||
TOKEN_BITWISE_LEFT_SHIFT,
|
||||
TOKEN_BITWISE_RIGHT_SHIFT,
|
||||
TOKEN_ARITHMETIC_RIGHT_SHIFT,
|
||||
TOKEN_EQUALS_PLUS,
|
||||
TOKEN_EQUALS_MINUS,
|
||||
TOKEN_EQUALS_MULTIPLY,
|
||||
TOKEN_EQUALS_DIVIDE,
|
||||
TOKEN_EQUALS_MOD,
|
||||
TOKEN_EQUALS_EXP,
|
||||
TOKEN_EQUALS_BITWISE_COMP,
|
||||
TOKEN_EQUALS_BITWISE_AND,
|
||||
TOKEN_EQUALS_BITWISE_OR,
|
||||
TOKEN_EQUALS_BITWISE_XOR,
|
||||
TOKEN_EQUALS_BITWISE_LEFT_SHIFT,
|
||||
TOKEN_EQUALS_BITWISE_RIGHT_SHIFT,
|
||||
TOKEN_EQUALS_ARITHMETIC_RIGHT_SHIFT,
|
||||
TOKEN_INCREMENT,
|
||||
TOKEN_DECREMENT,
|
||||
TOKEN_CONDITIONAL,
|
||||
TOKEN_NOT,
|
||||
TOKEN_AND,
|
||||
TOKEN_OR,
|
||||
TOKEN_XOR,
|
||||
TOKEN_EQUAL,
|
||||
TOKEN_NOT_EQUAL,
|
||||
TOKEN_LESS,
|
||||
TOKEN_GREATER,
|
||||
TOKEN_LESS_OR_EQUAL,
|
||||
TOKEN_GREATER_OR_EQUAL,
|
||||
TOKEN_STRING,
|
||||
TOKEN_INTEGER,
|
||||
TOKEN_FRACTIONAL,
|
||||
TOKEN_HANDLE
|
||||
};
|
||||
|
||||
struct Token {
|
||||
TokenType m_type;
|
||||
const char* m_data;
|
||||
unsigned m_line;
|
||||
unsigned m_line_offset;
|
||||
};
|
||||
|
||||
class Lexer final {
|
||||
public:
|
||||
Lexer(std::istream& input);
|
||||
|
||||
Token consume_token(unsigned offset = 1);
|
||||
Token peek_token(unsigned offset = 1);
|
||||
Token expect_consume_token(TokenType type, unsigned offset = 1);
|
||||
Token expect_peek_token(TokenType type, unsigned offset = 1);
|
||||
bool has_next_token();
|
||||
|
||||
private:
|
||||
std::istream& m_input;
|
||||
unsigned m_line;
|
||||
unsigned m_line_start;
|
||||
char m_identifier[1024];
|
||||
|
||||
private:
|
||||
void consume_whitespace();
|
||||
bool handle_newline();
|
||||
Token next_token();
|
||||
// Resolves tokens starting with the same character, for example == and =
|
||||
TokenType resolve_similar(char ch, TokenType first, TokenType second);
|
||||
TokenType resolve_starting_similar(const std::map<char, TokenType>& endings, TokenType def);
|
||||
};
|
||||
|
||||
const std::string& get_token_name(TokenType type);
|
||||
void dump_token(const Token& token);
|
||||
}
|
||||
|
||||
#endif // POLYGUN_AS_LEXER_HPP
|
||||
39
src/common/as/parser.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2024 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "common/as/parser.hpp"
|
||||
|
||||
#include "common/as/vm.hpp"
|
||||
|
||||
using namespace polygun::as;
|
||||
|
||||
Parser::Parser(VM& vm) :
|
||||
m_vm(vm)
|
||||
{}
|
||||
|
||||
void Parser::parse(std::istream& input) {
|
||||
while(!input.eof()) {
|
||||
|
||||
}
|
||||
}
|
||||
44
src/common/as/parser.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2024 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef POLYGUN_AS_PARSER_HPP
|
||||
#define POLYGUN_AS_PARSER_HPP
|
||||
|
||||
#include <istream>
|
||||
|
||||
namespace polygun::as {
|
||||
class VM;
|
||||
class Parser final {
|
||||
public:
|
||||
Parser(VM& vm);
|
||||
~Parser() = default;
|
||||
|
||||
void parse(std::istream& input);
|
||||
|
||||
private:
|
||||
VM& m_vm;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // POLYGUN_AS_PARSER_HPP
|
||||
41
src/common/as/value.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2024 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "common/as/value.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
polygun::as::ValueType polygun::as::get_wider_type(polygun::as::ValueType first, polygun::as::ValueType second) {
|
||||
return static_cast<ValueType>(std::max(first, second));
|
||||
}
|
||||
|
||||
polygun::as::ValueType polygun::as::var_type_to_value_type(polygun::as::VarType var_type) {
|
||||
if(var_type<=VarType::VAR_TYPE_BOOL)
|
||||
return static_cast<ValueType>(var_type);
|
||||
if(var_type<=VarType::VAR_TYPE_UINT64)
|
||||
return ValueType::VALUE_TYPE_UINT;
|
||||
if(var_type<=VarType::VAR_TYPE_INT64)
|
||||
return ValueType::VALUE_TYPE_INT;
|
||||
return ValueType::VALUE_TYPE_DOUBLE;
|
||||
}
|
||||
115
src/common/as/value.hpp
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2024 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef POLYGUN_AS_VALUE_HPP
|
||||
#define POLYGUN_AS_VALUE_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace polygun::as {
|
||||
union Value {
|
||||
bool b;
|
||||
uint64_t u;
|
||||
int64_t i;
|
||||
double d;
|
||||
struct {
|
||||
void* m_ptr;
|
||||
// Index in VM custom type table
|
||||
unsigned m_type_index;
|
||||
} p;
|
||||
};
|
||||
|
||||
enum ValueType {
|
||||
VALUE_TYPE_VOID,
|
||||
VALUE_TYPE_BOOL,
|
||||
VALUE_TYPE_UINT,
|
||||
VALUE_TYPE_INT,
|
||||
VALUE_TYPE_DOUBLE,
|
||||
VALUE_TYPE_PTR
|
||||
};
|
||||
|
||||
enum VarType {
|
||||
VAR_TYPE_VOID,
|
||||
VAR_TYPE_BOOL,
|
||||
VAR_TYPE_UINT8,
|
||||
VAR_TYPE_UINT16,
|
||||
VAR_TYPE_UINT32,
|
||||
VAR_TYPE_UINT64,
|
||||
VAR_TYPE_INT8,
|
||||
VAR_TYPE_INT16,
|
||||
VAR_TYPE_INT32,
|
||||
VAR_TYPE_INT64,
|
||||
VAR_TYPE_FLOAT,
|
||||
VAR_TYPE_DOUBLE,
|
||||
VAR_TYPE_PTR
|
||||
};
|
||||
|
||||
enum FunctionType {
|
||||
FUNCTION_NORMAL,
|
||||
FUNCTION_NATIVE
|
||||
};
|
||||
|
||||
enum Location {
|
||||
LOCATION_STACK,
|
||||
LOCATION_STATIC
|
||||
};
|
||||
|
||||
ValueType get_wider_type(ValueType first, ValueType second);
|
||||
ValueType var_type_to_value_type(VarType var_type);
|
||||
template<typename T>
|
||||
T value_as(const Value& value, ValueType type) {
|
||||
switch(type) {
|
||||
case ValueType::VALUE_TYPE_BOOL:
|
||||
return value.b;
|
||||
case ValueType::VALUE_TYPE_UINT:
|
||||
return value.u;
|
||||
case ValueType::VALUE_TYPE_INT:
|
||||
return value.i;
|
||||
case ValueType::VALUE_TYPE_DOUBLE:
|
||||
return value.d;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
template<typename T>
|
||||
void to_value(T input, ValueType type, Value& value) {
|
||||
switch(type) {
|
||||
case ValueType::VALUE_TYPE_BOOL:
|
||||
value.b = input;
|
||||
break;
|
||||
case ValueType::VALUE_TYPE_UINT:
|
||||
value.u = input;
|
||||
break;
|
||||
case ValueType::VALUE_TYPE_INT:
|
||||
value.i = input;
|
||||
break;
|
||||
case ValueType::VALUE_TYPE_DOUBLE:
|
||||
value.d = input;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // POLYGUN_AS_VALUE_HPP
|
||||
175
src/common/as/vm.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2024 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "common/as/vm.hpp"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
using namespace polygun::as;
|
||||
|
||||
VM::VM(unsigned storage_size) :
|
||||
m_storage_size(storage_size),
|
||||
m_stack(new uint8_t[storage_size]),
|
||||
m_stack_ptr(0),
|
||||
m_return_value(),
|
||||
m_parser(*this),
|
||||
m_native_functions(),
|
||||
m_native_function_addresses()
|
||||
{}
|
||||
|
||||
VM::~VM() {
|
||||
delete[] m_stack;
|
||||
}
|
||||
|
||||
void VM::load_script_from_file(const std::string& path) {
|
||||
std::ifstream file;
|
||||
file.exceptions(std::ios::badbit);
|
||||
file.open(path);
|
||||
m_parser.parse(file);
|
||||
file.close();
|
||||
}
|
||||
|
||||
void VM::register_function(const std::string& name, VarType result_type, const std::vector<VarType>& argument_types, Value(*func)(VM&, const std::vector<Value>&)) {
|
||||
m_native_function_addresses[name] = m_native_functions.size();
|
||||
const NativeFunction native_function {
|
||||
result_type,
|
||||
argument_types,
|
||||
func
|
||||
};
|
||||
m_native_functions.push_back(native_function);
|
||||
}
|
||||
|
||||
void VM::set_value_at(Location location, unsigned addr, const Value& value, VarType type) {
|
||||
assert(addr<m_storage_size);
|
||||
uint8_t* mem;
|
||||
switch(location) {
|
||||
case Location::LOCATION_STACK:
|
||||
mem = m_stack;
|
||||
break;
|
||||
case Location::LOCATION_STATIC:
|
||||
// TODO
|
||||
break;
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case VarType::VAR_TYPE_VOID:
|
||||
break;
|
||||
case VarType::VAR_TYPE_BOOL:
|
||||
mem[addr] = value.b;
|
||||
break;
|
||||
case VarType::VAR_TYPE_UINT8:
|
||||
mem[addr] = value.u;
|
||||
break;
|
||||
case VarType::VAR_TYPE_UINT16:
|
||||
*reinterpret_cast<uint16_t*>(&mem[addr]) = value.u;
|
||||
break;
|
||||
case VarType::VAR_TYPE_UINT32:
|
||||
*reinterpret_cast<uint32_t*>(&mem[addr]) = value.u;
|
||||
break;
|
||||
case VarType::VAR_TYPE_UINT64:
|
||||
*reinterpret_cast<uint64_t*>(&mem[addr]) = value.u;
|
||||
break;
|
||||
case VarType::VAR_TYPE_INT8:
|
||||
mem[addr] = value.i;
|
||||
break;
|
||||
case VarType::VAR_TYPE_INT16:
|
||||
*reinterpret_cast<int16_t*>(&mem[addr]) = value.i;
|
||||
break;
|
||||
case VarType::VAR_TYPE_INT32:
|
||||
*reinterpret_cast<int32_t*>(&mem[addr]) = value.i;
|
||||
break;
|
||||
case VarType::VAR_TYPE_INT64:
|
||||
*reinterpret_cast<int64_t*>(&mem[addr]) = value.i;
|
||||
break;
|
||||
case VarType::VAR_TYPE_FLOAT:
|
||||
*reinterpret_cast<float*>(&mem[addr]) = value.d;
|
||||
break;
|
||||
case VarType::VAR_TYPE_DOUBLE:
|
||||
*reinterpret_cast<double*>(&mem[addr]) = value.d;
|
||||
break;
|
||||
case VarType::VAR_TYPE_PTR:
|
||||
*reinterpret_cast<void**>(&mem[addr]) = value.p.m_ptr;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void VM::get_value_at(Location location, unsigned addr, VarType type, Value& value) {
|
||||
assert(addr<m_storage_size);
|
||||
uint8_t* mem;
|
||||
switch(location) {
|
||||
case Location::LOCATION_STACK:
|
||||
mem = m_stack;
|
||||
break;
|
||||
case Location::LOCATION_STATIC:
|
||||
// TODO
|
||||
break;
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case VarType::VAR_TYPE_VOID:
|
||||
break;
|
||||
case VarType::VAR_TYPE_BOOL:
|
||||
value.b = mem[addr];
|
||||
break;
|
||||
case VarType::VAR_TYPE_UINT8:
|
||||
value.u = mem[addr];
|
||||
break;
|
||||
case VarType::VAR_TYPE_UINT16:
|
||||
value.u = *reinterpret_cast<uint16_t*>(&mem[addr]);
|
||||
break;
|
||||
case VarType::VAR_TYPE_UINT32:
|
||||
value.u = *reinterpret_cast<uint32_t*>(&mem[addr]);
|
||||
break;
|
||||
case VarType::VAR_TYPE_UINT64:
|
||||
value.u = *reinterpret_cast<uint64_t*>(&mem[addr]);
|
||||
break;
|
||||
case VarType::VAR_TYPE_INT8:
|
||||
value.i = mem[addr];
|
||||
break;
|
||||
case VarType::VAR_TYPE_INT16:
|
||||
value.i = *reinterpret_cast<int16_t*>(&mem[addr]);
|
||||
break;
|
||||
case VarType::VAR_TYPE_INT32:
|
||||
value.i = *reinterpret_cast<int32_t*>(&mem[addr]);
|
||||
break;
|
||||
case VarType::VAR_TYPE_INT64:
|
||||
value.i = *reinterpret_cast<int64_t*>(&mem[addr]);
|
||||
break;
|
||||
case VarType::VAR_TYPE_FLOAT:
|
||||
value.d = *reinterpret_cast<float*>(&mem[addr]);
|
||||
break;
|
||||
case VarType::VAR_TYPE_DOUBLE:
|
||||
value.d = *reinterpret_cast<double*>(&mem[addr]);
|
||||
break;
|
||||
case VarType::VAR_TYPE_PTR:
|
||||
*reinterpret_cast<void**>(&mem[addr]) = value.p.m_ptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const VM::NativeFunction& VM::get_native_function_by_address(unsigned address) {
|
||||
assert(address<m_native_functions.size());
|
||||
return m_native_functions[address];
|
||||
}
|
||||
72
src/common/as/vm.hpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2024 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef POLYGUN_AS_VM_HPP
|
||||
#define POLYGUN_AS_VM_HPP
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "common/as/parser.hpp"
|
||||
#include "common/as/value.hpp"
|
||||
|
||||
namespace polygun::as {
|
||||
class VM final {
|
||||
public:
|
||||
struct NativeFunction {
|
||||
VarType m_result_type;
|
||||
std::vector<VarType> m_argument_types;
|
||||
Value(*m_func)(VM&, const std::vector<Value>&);
|
||||
};
|
||||
|
||||
public:
|
||||
VM(unsigned storage_size);
|
||||
~VM();
|
||||
|
||||
void load_script_from_file(const std::string& path);
|
||||
void register_function(const std::string& name, VarType result_type, const std::vector<VarType>& argument_types, Value(*func)(VM&, const std::vector<Value>&));
|
||||
|
||||
void set_value_at(Location location, unsigned addr, const Value& value, VarType type);
|
||||
void set_return_value(const Value& value) { m_return_value = value; }
|
||||
void get_value_at(Location location, unsigned addr, VarType type, Value& value);
|
||||
unsigned get_stack_ptr() const { return m_stack_ptr; }
|
||||
const Value& get_return_value() const { return m_return_value; }
|
||||
const NativeFunction& get_native_function_by_address(unsigned address);
|
||||
|
||||
private:
|
||||
unsigned m_storage_size;
|
||||
uint8_t* m_stack;
|
||||
unsigned m_stack_ptr;
|
||||
Value m_return_value;
|
||||
Parser m_parser;
|
||||
std::vector<NativeFunction> m_native_functions;
|
||||
// Maps function name to index in std::vector above
|
||||
std::map<std::string, unsigned> m_native_function_addresses;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // POLYGUN_AS_VM_HPP
|
||||
49
src/common/backtrace_handler.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "common/backtrace_handler.hpp"
|
||||
|
||||
#include <csignal>
|
||||
#include <iostream>
|
||||
#if defined(__GNUC__)
|
||||
#include <execinfo.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
void polygun::utils::backtrace_handler::initialize() {
|
||||
signal(SIGSEGV, handler);
|
||||
signal(SIGILL, handler);
|
||||
signal(SIGFPE, handler);
|
||||
}
|
||||
|
||||
void polygun::utils::backtrace_handler::handler(int signal) {
|
||||
std::cout<<"PolyGun has crashed :/"<<std::endl;
|
||||
std::cout<<"Backtrace: "<<std::endl;
|
||||
#if defined(__GNUC__)
|
||||
void* backtrace_symbols[1024];
|
||||
size_t size = backtrace(backtrace_symbols, 1024);
|
||||
backtrace_symbols_fd(backtrace_symbols, size, STDOUT_FILENO);
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
33
src/common/backtrace_handler.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef POLYGUN_UTILS_BACKTRACE_HANDLER_HPP
|
||||
#define POLYGUN_UTILS_BACKTRACE_HANDLER_HPP
|
||||
|
||||
namespace polygun::utils::backtrace_handler {
|
||||
void initialize();
|
||||
void handler(int signal);
|
||||
}
|
||||
|
||||
#endif // POLYGUN_UTILS_BACKTRACE_HANDLER_HPP
|
||||
199
src/common/binary_utils.cpp
Normal file
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "common/binary_utils.hpp"
|
||||
|
||||
bool polygun::utils::is_little_endian(){
|
||||
unsigned x=0x76543210;
|
||||
char* c=(char*)&x;
|
||||
return *c==0x10;
|
||||
}
|
||||
|
||||
uint16_t polygun::utils::bytes_to_uint16(const char* data){
|
||||
uint16_t output;
|
||||
if(is_little_endian()){
|
||||
((char*)&output)[0]=data[0];
|
||||
((char*)&output)[1]=data[1];
|
||||
}
|
||||
else{
|
||||
((char*)&output)[1]=data[0];
|
||||
((char*)&output)[0]=data[1];
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
void polygun::utils::uint16_to_bytes(uint16_t data,char* output){
|
||||
if(is_little_endian()){
|
||||
output[0]=((char*)&data)[0];
|
||||
output[1]=((char*)&data)[1];
|
||||
}
|
||||
else{
|
||||
output[1]=((char*)&data)[0];
|
||||
output[0]=((char*)&data)[1];
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t polygun::utils::bytes_to_uint32(const char* data){
|
||||
uint32_t output;
|
||||
if(is_little_endian()){
|
||||
((char*)&output)[0]=data[0];
|
||||
((char*)&output)[1]=data[1];
|
||||
((char*)&output)[2]=data[2];
|
||||
((char*)&output)[3]=data[3];
|
||||
}
|
||||
else{
|
||||
((char*)&output)[3]=data[0];
|
||||
((char*)&output)[2]=data[1];
|
||||
((char*)&output)[1]=data[2];
|
||||
((char*)&output)[0]=data[3];
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
void polygun::utils::uint32_to_bytes(uint32_t data,char* output){
|
||||
if(is_little_endian()){
|
||||
output[0]=((char*)&data)[0];
|
||||
output[1]=((char*)&data)[1];
|
||||
output[2]=((char*)&data)[2];
|
||||
output[3]=((char*)&data)[3];
|
||||
}
|
||||
else{
|
||||
output[3]=((char*)&data)[0];
|
||||
output[2]=((char*)&data)[1];
|
||||
output[1]=((char*)&data)[2];
|
||||
output[0]=((char*)&data)[3];
|
||||
}
|
||||
}
|
||||
|
||||
int32_t polygun::utils::bytes_to_int32(const char* data){
|
||||
int32_t output;
|
||||
if(is_little_endian()){
|
||||
((char*)&output)[0]=data[0];
|
||||
((char*)&output)[1]=data[1];
|
||||
((char*)&output)[2]=data[2];
|
||||
((char*)&output)[3]=data[3];
|
||||
}
|
||||
else{
|
||||
((char*)&output)[3]=data[0];
|
||||
((char*)&output)[2]=data[1];
|
||||
((char*)&output)[1]=data[2];
|
||||
((char*)&output)[0]=data[3];
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
void polygun::utils::int32_to_bytes(int32_t data,char* output){
|
||||
if(is_little_endian()){
|
||||
output[0]=((char*)&data)[0];
|
||||
output[1]=((char*)&data)[1];
|
||||
output[2]=((char*)&data)[2];
|
||||
output[3]=((char*)&data)[3];
|
||||
}
|
||||
else{
|
||||
output[3]=((char*)&data)[0];
|
||||
output[2]=((char*)&data)[1];
|
||||
output[1]=((char*)&data)[2];
|
||||
output[0]=((char*)&data)[3];
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t polygun::utils::bytes_to_uint64(const char* data){
|
||||
uint64_t output;
|
||||
if(is_little_endian()){
|
||||
((char*)&output)[0]=data[0];
|
||||
((char*)&output)[1]=data[1];
|
||||
((char*)&output)[2]=data[2];
|
||||
((char*)&output)[3]=data[3];
|
||||
((char*)&output)[4]=data[4];
|
||||
((char*)&output)[5]=data[5];
|
||||
((char*)&output)[6]=data[6];
|
||||
((char*)&output)[7]=data[7];
|
||||
}
|
||||
else{
|
||||
((char*)&output)[7]=data[0];
|
||||
((char*)&output)[6]=data[1];
|
||||
((char*)&output)[5]=data[2];
|
||||
((char*)&output)[4]=data[3];
|
||||
((char*)&output)[3]=data[4];
|
||||
((char*)&output)[2]=data[5];
|
||||
((char*)&output)[1]=data[6];
|
||||
((char*)&output)[0]=data[7];
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
void polygun::utils::uint64_to_bytes(uint64_t data,char* output){
|
||||
if(is_little_endian()){
|
||||
output[0]=((char*)&data)[0];
|
||||
output[1]=((char*)&data)[1];
|
||||
output[2]=((char*)&data)[2];
|
||||
output[3]=((char*)&data)[3];
|
||||
output[4]=((char*)&data)[4];
|
||||
output[5]=((char*)&data)[5];
|
||||
output[6]=((char*)&data)[6];
|
||||
output[7]=((char*)&data)[7];
|
||||
}
|
||||
else{
|
||||
output[7]=((char*)&data)[0];
|
||||
output[6]=((char*)&data)[1];
|
||||
output[5]=((char*)&data)[2];
|
||||
output[4]=((char*)&data)[3];
|
||||
output[3]=((char*)&data)[4];
|
||||
output[2]=((char*)&data)[5];
|
||||
output[1]=((char*)&data)[6];
|
||||
output[0]=((char*)&data)[7];
|
||||
}
|
||||
}
|
||||
|
||||
float polygun::utils::bytes_to_float(const char* data) {
|
||||
float output;
|
||||
if(is_little_endian()){
|
||||
((char*)&output)[0]=data[0];
|
||||
((char*)&output)[1]=data[1];
|
||||
((char*)&output)[2]=data[2];
|
||||
((char*)&output)[3]=data[3];
|
||||
}
|
||||
else{
|
||||
((char*)&output)[3]=data[0];
|
||||
((char*)&output)[2]=data[1];
|
||||
((char*)&output)[1]=data[2];
|
||||
((char*)&output)[0]=data[3];
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
void polygun::utils::float_to_bytes(float data, char* output) {
|
||||
if(is_little_endian()){
|
||||
output[0]=((char*)&data)[0];
|
||||
output[1]=((char*)&data)[1];
|
||||
output[2]=((char*)&data)[2];
|
||||
output[3]=((char*)&data)[3];
|
||||
}
|
||||
else{
|
||||
output[3]=((char*)&data)[0];
|
||||
output[2]=((char*)&data)[1];
|
||||
output[1]=((char*)&data)[2];
|
||||
output[0]=((char*)&data)[3];
|
||||
}
|
||||
}
|
||||
44
src/common/binary_utils.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef POLYGUN_UTILS_BINARY_UTILS_HPP
|
||||
#define POLYGUN_UTILS_BINARY_UTILS_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace polygun::utils {
|
||||
bool is_little_endian();
|
||||
uint16_t bytes_to_uint16(const char* data);
|
||||
void uint16_to_bytes(uint16_t data, char* output);
|
||||
uint32_t bytes_to_uint32(const char* data);
|
||||
void uint32_to_bytes(uint32_t data, char* output);
|
||||
int32_t bytes_to_int32(const char* data);
|
||||
void int32_to_bytes(int32_t data, char* output);
|
||||
uint64_t bytes_to_uint64(const char* data);
|
||||
void uint64_to_bytes(uint64_t data, char* output);
|
||||
float bytes_to_float(const char* data);
|
||||
void float_to_bytes(float data, char* output);
|
||||
}
|
||||
|
||||
#endif
|
||||
123
src/common/command_arguments_parser.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "common/command_arguments_parser.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
#include "common/logger.hpp"
|
||||
|
||||
using namespace polygun::utils;
|
||||
|
||||
CommandArgumentsParser::CommandArgumentsParser(int argc, char** argv) :
|
||||
#if defined(BUILD_SERVER)
|
||||
#if defined(BUILD_CLIENT)
|
||||
m_start_server(false),
|
||||
m_host_server_nickname(),
|
||||
m_host_server(false),
|
||||
#else
|
||||
m_start_server(true),
|
||||
#endif
|
||||
#endif
|
||||
#if defined(BUILD_CLIENT)
|
||||
m_connect_nickname(),
|
||||
m_connect_ip(),
|
||||
m_connect_port(0),
|
||||
#endif
|
||||
m_argc(argc),
|
||||
m_argv(argv)
|
||||
{}
|
||||
|
||||
void CommandArgumentsParser::parse() {
|
||||
for(int i = 1; i<m_argc; i++) {
|
||||
if(strcmp(m_argv[i], "server")==0) {
|
||||
#if defined(BUILD_CLIENT)
|
||||
if(!m_connect_ip.empty())
|
||||
LOG_FATAL("Server could not be started: --connect argument is present");
|
||||
#endif
|
||||
#if defined(BUILD_SERVER)
|
||||
m_start_server = true;
|
||||
continue;
|
||||
#else
|
||||
LOG_FATAL("Failed to start server: not compiled in");
|
||||
#endif
|
||||
}
|
||||
#if defined(BUILD_SERVER)
|
||||
if(!m_start_server) {
|
||||
#endif
|
||||
if(strcmp(m_argv[i], "help")==0) {
|
||||
show_help();
|
||||
exit(0);
|
||||
}
|
||||
else if(strcmp(m_argv[i], "version")==0) {
|
||||
std::cout<<"PolyGun "<<POLYGUN_VERSION<<std::endl;
|
||||
exit(0);
|
||||
}
|
||||
#if defined(BUILD_CLIENT)
|
||||
else if(strcmp(m_argv[i], "--host")==0) {
|
||||
#if defined(BUILD_SERVER)
|
||||
if(++i>=m_argc)
|
||||
LOG_FATAL("Nickname is required for --host");
|
||||
m_host_server_nickname = m_argv[i];
|
||||
m_host_server = true;
|
||||
#else
|
||||
LOG_FATAL("Failed to host server: server not compiled in");
|
||||
#endif
|
||||
}
|
||||
else if(strcmp(m_argv[i], "--connect")==0) {
|
||||
if(++i>=m_argc)
|
||||
LOG_FATAL("Server IP is required for --connect");
|
||||
m_connect_ip = m_argv[i];
|
||||
if(++i>=m_argc)
|
||||
LOG_FATAL("Server port is required for --connect");
|
||||
m_connect_port = atoi(m_argv[i]);
|
||||
if(++i>=m_argc)
|
||||
LOG_FATAL("Nickname is required for --connect");
|
||||
m_connect_nickname = m_argv[i];
|
||||
}
|
||||
#endif
|
||||
else
|
||||
LOG_FATAL("Unknown command '%s'", m_argv[i]);
|
||||
#if defined(BUILD_SERVER)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void CommandArgumentsParser::show_help() {
|
||||
std::cout<<"PolyGun - Voxel multiplayer FPS game with Raytracing"<<std::endl;
|
||||
std::cout<<"Available subcommands:"<<std::endl;
|
||||
std::cout<<" help - shows this message"<<std::endl;
|
||||
std::cout<<" version - shows version number"<<std::endl;
|
||||
#if defined(BUILD_SERVER)
|
||||
std::cout<<" server - starts server"<<std::endl;
|
||||
#endif
|
||||
std::cout<<"Available client arguments:"<<std::endl;
|
||||
#if defined(BUILD_CLIENT)
|
||||
std::cout<<" --host <nickname> - host local server and join it with <nickname>"<<std::endl;
|
||||
std::cout<<" --connect <IP> <port> <nickname> - connect to server with <address> and <port> using <nickname>"<<std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
74
src/common/command_arguments_parser.hpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef POLYGUN_UTILS_COMMAND_ARGUMENT_PARSER_HPP
|
||||
#define POLYGUN_UTILS_COMMAND_ARGUMENT_PARSER_HPP
|
||||
|
||||
#include <config.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace polygun::utils {
|
||||
class CommandArgumentsParser final {
|
||||
public:
|
||||
CommandArgumentsParser(int argc, char** argv);
|
||||
~CommandArgumentsParser() = default;
|
||||
|
||||
void parse();
|
||||
|
||||
#if defined(BUILD_SERVER)
|
||||
bool start_server() const { return m_start_server; }
|
||||
#if defined(BUILD_CLIENT)
|
||||
const std::string& get_host_server_nickname() const { return m_host_server_nickname; }
|
||||
bool host_server() const { return m_host_server; }
|
||||
#endif
|
||||
#endif
|
||||
#if defined(BUILD_CLIENT)
|
||||
bool connect_to() const { return !m_connect_ip.empty(); }
|
||||
const std::string& get_connect_nickname() const { return m_connect_nickname; }
|
||||
const std::string& get_connect_ip() const { return m_connect_ip; }
|
||||
unsigned short get_connect_port() const { return m_connect_port; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
#if defined(BUILD_SERVER)
|
||||
bool m_start_server;
|
||||
#if defined(BUILD_CLIENT)
|
||||
std::string m_host_server_nickname;
|
||||
bool m_host_server;
|
||||
#endif
|
||||
#endif
|
||||
#if defined(BUILD_CLIENT)
|
||||
std::string m_connect_nickname;
|
||||
std::string m_connect_ip;
|
||||
unsigned short m_connect_port;
|
||||
#endif
|
||||
int m_argc;
|
||||
char** m_argv;
|
||||
|
||||
private:
|
||||
void show_help();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // POLYGUN_UTILS_COMMAND_ARGUMENT_PARSER_HPP
|
||||
48
src/common/control/controller.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "common/control/controller.hpp"
|
||||
|
||||
using namespace polygun::control;
|
||||
|
||||
Controller::Controller() :
|
||||
m_pressed_controls(),
|
||||
m_prev_pressed_controls()
|
||||
{}
|
||||
|
||||
void Controller::update() {
|
||||
m_prev_pressed_controls = m_pressed_controls;
|
||||
}
|
||||
|
||||
bool Controller::is_control_pressed(Control control) {
|
||||
return !m_prev_pressed_controls[control] && m_pressed_controls[control];
|
||||
}
|
||||
|
||||
bool Controller::is_control_released(Control control) {
|
||||
return m_prev_pressed_controls[control] && !m_pressed_controls[control];
|
||||
}
|
||||
|
||||
bool Controller::is_control_held(Control control) {
|
||||
return m_pressed_controls[control];
|
||||
}
|
||||
64
src/common/control/controller.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef POLYGUN_CONTROL_CONTROLLER_HPP
|
||||
#define POLYGUN_CONTROL_CONTROLLER_HPP
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace polygun::control {
|
||||
enum Control {
|
||||
CONTROL_UP,
|
||||
CONTROL_DOWN,
|
||||
CONTROL_LEFT,
|
||||
CONTROL_RIGHT,
|
||||
CONTROL_JUMP,
|
||||
CONTROL_CROUCH,
|
||||
CONTROL_AIM,
|
||||
CONTROL_SHOOT,
|
||||
CONTROL_OPEN_CHAT,
|
||||
CONTROL_PAUSE,
|
||||
CONTROL_OPEN_EDITMODE_TOOLBOX,
|
||||
CONTROL_EDITMODE_SELECT,
|
||||
CONTROL_COUNT
|
||||
};
|
||||
|
||||
class Controller {
|
||||
public:
|
||||
Controller();
|
||||
virtual ~Controller() = default;
|
||||
|
||||
virtual void update();
|
||||
|
||||
bool is_control_pressed(Control control);
|
||||
bool is_control_released(Control control);
|
||||
bool is_control_held(Control control);
|
||||
|
||||
protected:
|
||||
std::map<Control, bool> m_pressed_controls;
|
||||
std::map<Control, bool> m_prev_pressed_controls;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // POLYGUN_CONTROL_CONTROLLER_HPP
|
||||
64
src/common/fs.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "common/fs.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
#include "common/logger.hpp"
|
||||
|
||||
std::string polygun::utils::get_user_dir() {
|
||||
#if defined(__APPLE__)
|
||||
// TODO
|
||||
#elif defined(__unix__) || defined(__HAIKU__) // Linux etc
|
||||
char* c_data_home = getenv("XDG_DATA_HOME");
|
||||
std::string data_home;
|
||||
if(c_data_home) {
|
||||
data_home = std::string(c_data_home)+"/polygun";
|
||||
if(!std::filesystem::exists(data_home))
|
||||
std::filesystem::create_directories(data_home);
|
||||
return data_home;
|
||||
}
|
||||
c_data_home = getenv("HOME");
|
||||
if(!c_data_home)
|
||||
LOG_FATAL("Failed to determine folder for writing user data (HOME or XDG_DATA_HOME not set)");
|
||||
data_home = std::string(c_data_home)+"/.polygun";
|
||||
if(!std::filesystem::exists(data_home))
|
||||
std::filesystem::create_directories(data_home);
|
||||
return data_home;
|
||||
#elif defined(_WIN32)
|
||||
char* c_appdata = getenv("appdata");
|
||||
std::string appdata;
|
||||
if(!c_appdata)
|
||||
LOG_FATAL("Failed to determine folder for writing user data (appdata not set)");
|
||||
appdata = std::string(c_appdata)+"/polygun";
|
||||
if(!std::filesystem::exists(appdata))
|
||||
std::filesystem::create_directories(appdata);
|
||||
return appdata;
|
||||
#else
|
||||
LOG_FATAL("polygun::utils::get_user_dir is not implemented for your platform");
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
34
src/common/fs.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef POLYGUN_UTILS_FS_HPP
|
||||
#define POLYGUN_UTILS_FS_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace polygun::utils {
|
||||
std::string get_user_dir();
|
||||
}
|
||||
|
||||
#endif // POLYGUN_UTILS_FS_HPP
|
||||
75
src/common/locale/dictionary.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "common/locale/dictionary.hpp"
|
||||
|
||||
#include "common/xml/parser.hpp"
|
||||
#include "common/xml/xml_node.hpp"
|
||||
#include "common/logger.hpp"
|
||||
|
||||
using namespace polygun::locale;
|
||||
|
||||
Dictionary::Dictionary() :
|
||||
m_data()
|
||||
{}
|
||||
|
||||
void Dictionary::load_from_file(const std::string& path) {
|
||||
xml::XMLNode* root_node;
|
||||
if(!xml::parse_file(path, root_node)) {
|
||||
LOG_ERROR("Failed to load translation '%s'", path.c_str());
|
||||
delete root_node;
|
||||
return;
|
||||
}
|
||||
|
||||
if(root_node->get_name()!="locale") {
|
||||
LOG_ERROR("Failed to load translation '%s': not a locale file", path.c_str());
|
||||
delete root_node;
|
||||
return;
|
||||
}
|
||||
|
||||
m_data.clear();
|
||||
for(xml::XMLNode* node = root_node->next_node(); node; node = root_node->next_node()) {
|
||||
if(node->get_name()!="tr") {
|
||||
LOG_ERROR("Invalid tag '%s' in locale file '%s'", node->get_name().c_str(), path.c_str());
|
||||
delete root_node;
|
||||
return;
|
||||
}
|
||||
xml::XMLNode* msgid = node->next_node("msgid");
|
||||
xml::XMLNode* msgstr = node->next_node("msgstr");
|
||||
if(!msgid || !msgstr) {
|
||||
LOG_ERROR("Invalid locale entry in locale file '%s'", path.c_str());
|
||||
delete root_node;
|
||||
return;
|
||||
}
|
||||
m_data[msgid->get_text()] = msgstr->get_text();
|
||||
}
|
||||
|
||||
delete root_node;
|
||||
}
|
||||
|
||||
const std::string& Dictionary::get(const std::string& msgid) {
|
||||
if(!m_data.count(msgid))
|
||||
return msgid;
|
||||
return m_data[msgid];
|
||||
}
|
||||