Compare commits

...

560 Commits

Author SHA1 Message Date
e81340f6ce Some fixes of warnings showed by newer GCC 2025-12-07 18:37:27 +01:00
Looki2000
fc01a95bc4 simplify collision_amount_axis code 2025-12-07 18:37:27 +01:00
Looki2000
4b72d7c174 improve player collision along y axis 2025-12-07 18:37:27 +01:00
Looki2000
be66e61285 improved player physics 2025-12-07 18:37:27 +01:00
Looki2000
924ab6e6fa fix typo 2025-12-07 18:37:27 +01:00
Looki2000
f83403eed7 implement ray-bbox intersection (ray casting) 2025-12-07 18:37:27 +01:00
957ddaad4d Add AngelScript implementation source files to Makefile 2025-08-16 22:51:28 +02:00
429829e847 Move AngelScript implementation to common 2025-08-16 22:45:51 +02:00
347f8705de Implement as::Lexer::has_next_token and as::Lexer::peek_token 2024-11-17 22:29:06 +01:00
33f76e6a89 Implement identifier lexing 2024-08-26 13:15:01 +02:00
872d9d7bc3 Implement token dumping 2024-08-26 13:14:08 +02:00
d689db9388 Fix lexing tokens starting with '|' and '^' 2024-08-25 22:27:08 +02:00
7a31c754ee Fix lexing tokens starting with '<' and '>' 2024-08-25 22:22:13 +02:00
e7e2f355b0 Some work on lexer 2024-08-25 21:51:08 +02:00
5a0b2ecd13 Implement VariableExpression 2024-08-25 21:51:08 +02:00
3836c35723 Introduce VariableAssignment 2024-08-25 21:51:08 +02:00
a4111d0622 Rename NumericExpression to LiteralExpression and add pointer to Value 2024-08-25 21:51:08 +02:00
f975cebeb5 Introduce FunctionCall and way to register native functions 2024-08-25 21:51:08 +02:00
4a1deea89e Introduce FunctionDefinition 2024-08-25 21:51:06 +02:00
e3da82c0ac Introduce FunctionDefinition 2024-08-16 19:22:52 +02:00
8d97cda751 Add simple VM with stack storage 2024-08-05 21:58:53 +02:00
c2985a6bb1 Introduce StatementBlock 2024-08-05 21:58:06 +02:00
b5d5009f61 Introduce NumericExpression and BinaryExpression 2024-08-05 13:29:22 +02:00
5d8d5849ee Introduce Value for storing AST result values 2024-08-05 13:19:01 +02:00
a364f21a07 Forgot to clear player information in RedirectManager 2024-08-03 12:11:05 +02:00
56759639ae Implement ability for server to redirect player to another server 2024-08-03 12:08:37 +02:00
64f1f87c0a Clean up parent setting code in GUI 2024-08-01 21:59:02 +02:00
eed9440200 Fix camera view not getting updated when game is paused 2024-08-01 13:39:21 +02:00
53e30c70da Implement TabView GUI component
It will be useful in options
2024-07-20 21:20:21 +02:00
e71c6e863c Allow for sending large resource data 2024-07-01 13:42:31 +02:00
e995c2c687 Implement packet fragmentation to allow sending larger packets 2024-07-01 12:17:26 +02:00
ea161290eb Some improvements in NetworkPacket 2024-07-01 12:15:44 +02:00
89c8290045 Some GLMeshRenderer fixes 2024-06-28 11:52:04 +02:00
c877952365 Change node resolution from 7 to 4 in normal meshing 2024-06-28 10:35:08 +02:00
88743161e2 Send chunk vertices as uint8 fixed-point to GPU 2024-06-23 21:56:18 +02:00
2fa813069e Only resend first non ACK-ed packet 2024-06-22 13:36:03 +02:00
Looki2000
622399a45c implement GUI layout debug mode 2024-06-20 20:24:03 +02:00
a7edb3116f Use sRGB framebuffer mode when available 2024-06-20 12:52:15 +02:00
Looki2000
047d74eaec add normals, improve slider, shading 2024-06-19 18:03:57 +02:00
5a3e94dacd Implement fill with probability 2024-06-19 12:15:13 +02:00
b3bd516643 Implement node area selection for editmode 2024-06-17 15:10:55 +02:00
ed6b107f3e Implement support for different textures per node side 2024-06-16 14:23:02 +02:00
ea9b8acf55 Change sunlight intensity depending on day time 2024-06-16 10:54:08 +02:00
8f0896da38 Fix node place and dig buffering 2024-06-15 11:46:14 +02:00
c7e74f6ec5 Use normal meshing by default 2024-06-15 11:34:13 +02:00
b54c087e18 Introduce way to change music volume 2024-06-14 16:16:14 +02:00
e1a6b4b609 Add on change callback to slider 2024-06-14 16:15:27 +02:00
f19fe48f5f Implement slider GUI component 2024-06-14 15:22:50 +02:00
d3c4e95d83 Remove unused simple text option 2024-06-14 09:33:05 +02:00
6ed98d0790 Fix some issues introduced earlier 2024-06-13 20:33:36 +02:00
Looki2000
7a0352e012 add new skybox 2024-06-13 20:33:36 +02:00
ca99d2b34b Synchronize day time with server 2024-06-13 20:33:34 +02:00
b157375522 Change skybox color depending on day time 2024-06-13 20:31:11 +02:00
Looki2000
3153eb1ac6 add skybox shader demos 2024-06-13 20:28:30 +02:00
ac52f99e14 Begin implementing simple skybox 2024-06-13 20:28:30 +02:00
794abef83a Fix few random issues 2024-06-13 17:39:59 +02:00
f97c163ea5 Fix player nick written incorrectly in message packet 2024-06-12 21:10:21 +02:00
a9ba7445fa Make sure that decoded sample never exceed range from -1 to 1 2024-06-12 20:58:30 +02:00
21bda9afbe Implement ingame music playing 2024-06-12 12:56:29 +02:00
170e3bf567 Rename MasterRenderer::supports_greedy_meshing to MasterRenderer::supports_shaders 2024-06-04 12:13:42 +02:00
b5dcc5646d Update GNU make build script 2024-06-03 11:53:53 +02:00
5c168d342b Merge branch 'sunlight' 2024-06-03 11:25:52 +02:00
8ee0aa6ec9 Some fixes with chunk meshes not updating properly 2024-06-03 11:23:03 +02:00
Looki2000
ee1002da3a improve demos 2024-06-02 15:39:10 +02:00
Looki2000
085f2fba27 add development test demos for different features 2024-06-02 15:20:04 +02:00
5ee833c315 Only update node column after changing node 2024-06-01 21:56:00 +02:00
999db35a85 Make client ChunkManager thread safe 2024-06-01 21:47:44 +02:00
Looki2000
7adca12c8f fix set_perspective so the near plane works properly and look_at which turned out to be wrong AGAIN after fixing projection LOL 2024-05-30 01:10:23 +02:00
db5fa9ca21 Generate chunk mesh and sun lightmap on separate thread 2024-05-29 13:26:47 +02:00
17e078f743 Initial and naive sun lightmap generation 2024-05-28 20:17:59 +02:00
dde86bb8b1 Win32Window: Only register raw mouse move event when mouse is actually grabbed
Mouse grab on Windows also happens when window is moved with mouse. This
caused dragged window to move in unexpected way.
2024-05-27 13:32:46 +02:00
59f4d769b6 Show message box when local server fails to start 2024-05-27 11:51:14 +02:00
ce02c8dc2a Store chunk sun lightmap as RGBColor per node 2024-05-25 13:25:11 +02:00
ffd1d57cba Store neighbours in ClientChunk 2024-05-23 22:13:14 +02:00
c24e5e6fdd Extract client specific Chunk code to ClientChunk 2024-05-22 19:24:55 +02:00
b484b742bc Add NodeSide enum 2024-05-21 20:54:26 +02:00
b7fdb4edc2 Only define NOMINMAX when it's needed on Windows 2024-05-20 20:11:43 +02:00
ad63c5d2c5 Fix variable naming in Matrix4::set_perspective 2024-05-19 14:15:28 +02:00
a267c9d3a0 Update docs/NETWORK_PROTOCOL.MD 2024-05-17 21:53:40 +02:00
c90e20b288 Update docs/MAP_FILE_FORMAT.MD 2024-05-17 20:51:07 +02:00
2b40543425 Implement fake lightning so terrain looks a little bit better 2024-05-17 12:51:30 +02:00
756c2e98fe Reset R/W mode during map file operations in server ChunkManager 2024-05-17 11:33:11 +02:00
d347b1b74f Some minor fixes 2024-05-16 19:57:04 +02:00
dc3faff91d Fix missing #include <cstring> in normal_meshing.cpp
Thanks MSVC
2024-05-16 14:32:57 +02:00
8d93ed6f64 Use NodeDef to check if node is transparent while generating chunk mesh 2024-05-16 10:42:39 +02:00
5a6816e70e Introduce base for lightning implementation 2024-05-15 22:14:47 +02:00
d94bf97a47 Make OpenGL headers include order correct depending on compiler 2024-05-15 16:31:10 +02:00
ed9c124286 Implement changing map during gameplay 2024-05-15 14:17:09 +02:00
652ee90fc1 Make it possible to change default map on server 2024-05-15 13:49:16 +02:00
04bfc1a8a2 Win32Window: Implement raw mouse input 2024-05-15 13:35:15 +02:00
b68415be42 Fix compilation with MSVC 2024-05-15 10:55:10 +02:00
f182c84c93 Don't push chunk without mesh to m_unloaded_chunks 2024-05-09 20:52:26 +02:00
bd221ceb02 Show PolyGun ASCII art at the start of program 2024-05-09 15:54:05 +02:00
Looki2000
fd092d3a2d major changes to light_cast 2024-05-07 14:09:24 +02:00
Looki2000
9dcff14b68 reduced ray casting code duplication 2024-05-06 23:57:35 +02:00
accdee9549 Use std::recursive_mutex as guard in ThreadSafe 2024-05-06 17:10:31 +02:00
97ca39457d Fix compilation with Clang 2024-05-06 17:02:22 +02:00
49e7e8053a Remove accidentally added "media" submodule 2024-05-05 20:12:59 +02:00
Looki2000
c68de9caa6 added shortening of path printed by logger 2024-05-05 17:44:18 +02:00
Looki2000
caca8bcf79 added angelscript download and unpack tool 2024-05-05 16:47:20 +02:00
Looki2000
dc746ae82a Merge branch 'master' of https://git.cubesoftware.xyz/PolyGun/PolyGun 2024-05-05 15:13:56 +02:00
Looki2000
a15cdccb78 fixed and simplified look_at, added ray casting with target position for lighting 2024-05-05 15:13:48 +02:00
061e60b839 Fix array out of bounds access in ChunkManager 2024-05-04 22:35:12 +02:00
06109c7fd3 Only update one chunk per frame 2024-05-04 11:42:10 +02:00
0a66799c47 Implement animated chunk loading and unloading 2024-05-04 11:07:33 +02:00
3b4f29f53f Improve random Chunk lookup in client 2024-05-03 16:38:57 +02:00
5b25027e51 Change anchor point of Rect3D 2024-05-03 14:31:42 +02:00
d85b340398 Remove LoadedChunk and move it's members to Chunk 2024-05-02 10:46:43 +02:00
b35ae45ae7 Some patches in NetworkManager 2024-04-30 11:16:12 +02:00
Looki2000
67baab5035 fixed missing include in item_gallery.hpp 2024-04-28 21:59:37 +02:00
32555c9152 Speed up NodeDef lookup in ContentRegistry via using regular array 2024-04-28 14:23:56 +02:00
c303640a02 Add colors attribute to Mesh 2024-04-28 11:42:49 +02:00
94e8982bd5 Display correct node string ID in editmode HUD 2024-04-26 22:22:00 +02:00
658854a3e4 X11Window: Implement raw mouse input through Xinput2 2024-04-26 22:03:59 +02:00
5cfea89ea0 Rename ImageGallery to ItemGallery and make it more generic
In future ItemGallery will be used for implementing inventory
2024-04-26 16:17:32 +02:00
Looki2000
44d1891196 Merge branch 'master' of https://git.cubesoftware.xyz/PolyGun/PolyGun 2024-04-24 00:59:51 +02:00
Looki2000
87522ca98f better ray casting using DDA algorithm 2024-04-24 00:58:13 +02:00
0989660683 Fix mouse click hiding chat in game (found by Looki2000) 2024-04-23 20:07:07 +02:00
7cff518260 t3d_to_polymap: Remove unused code that I accidentally added while copying 2024-04-23 16:08:53 +02:00
08c702e00e Implement ThreadHelper and use it to fix crashes with rendering player nicks 2024-04-23 11:37:45 +02:00
Kacper Kostka
75ca41bdfc Merge branch 'master' of https://git.cubesoftware.xyz/PolyGun/PolyGun 2024-04-22 20:38:53 +02:00
Kacper Kostka
3b27fcb883 deleted ingame music 2024-04-22 20:38:43 +02:00
05bc32769e Temporarily don't check incoming packet retries 2024-04-22 19:55:31 +02:00
1cfb024d04 added entitydef class 2024-04-22 13:12:57 +02:00
95b1821636 added "}" at the end of matrix.cpp file 2024-04-22 12:53:30 +02:00
c9a6b88826 Temporary fix for Matrix4::look_at 2024-04-22 12:38:16 +02:00
77ded46961 Remove Mesh::load_from_memory to make loading mesh data more flexible 2024-04-21 16:24:48 +02:00
5646d1a5e4 t3d_to_polymap: Update defaultblocks leaves ID mapping 2024-04-21 15:39:18 +02:00
ea46b48eee Properly wait while resource is pending in ResourceManager 2024-04-21 14:39:49 +02:00
4a6e086c0e Added new nodes and code for playing ingame music 2024-04-19 19:23:39 -04:00
f8dec1dba5 Temporarily comment out packet retry limit 2024-04-19 20:50:49 +02:00
618c39c634 t3d_to_polymap: Implement converting 2024-04-19 20:48:31 +02:00
051507142b t3d_to_polymap: Write polymap header 2024-04-18 22:20:21 +02:00
a062534659 Begin implementing Terrarium 3D to Polymap converter 2024-04-18 21:34:28 +02:00
e1063449ae Fix player rotation 2024-04-18 18:30:07 +02:00
a368898f1a Show player nick above player model 2024-04-18 18:07:16 +02:00
de9c82b1a3 Handle all incoming packets in one network thread step 2024-04-16 14:02:46 +02:00
ea74396d6f Make CommandParser aware of command argument data types and allow command overloading 2024-04-16 13:02:15 +02:00
f467d53cc2 Introduce op and deop commands 2024-04-14 14:14:05 +02:00
a684f42e0d Implement player storage system
It will allow storing persistent per player data
2024-04-14 13:59:26 +02:00
4d607336cd Add a way to send server commands from client 2024-04-13 12:10:57 +02:00
f808d2e9c6 Don't duplicate node selection every HUD switch 2024-04-11 21:57:50 +02:00
35cf8eb56d Replace TrueType font with simpler bitmap font
Since we wanted to use low resolution font and imitating it
with TrueType font would be a total overcomplication implementing
bitmap font text renderer seemed like a correct way.
2024-04-10 20:59:17 +02:00
768f4d7839 Add Surface::blit_surface_cropped and Surface color keying 2024-04-10 20:31:55 +02:00
914959df3f Win32Window: Make sure to only grab or ungrab mouse when state is different
This prevents calling ShowCursor multiple times, which buffers
subsequent calls with the same argument.
2024-02-27 19:36:38 +01:00
2a32df773d Gravity deceleration is no longer CPU speed dependent 2024-02-26 16:52:04 +01:00
15e4d5327c Fix collision with blocks breaking on negative coordinates 2024-02-23 16:15:49 +01:00
dc5b19323f Replace std::fstream with FILE* in server ChunkManager 2024-02-23 10:23:41 +01:00
fd8668c0e7 Merge branch 'physic' 2024-02-21 20:09:08 +01:00
af460a1630 Implement gravity and collisions with some issues 2024-02-21 20:08:18 +01:00
Looki2000
33d5146be8 added missing includes to oggvorbis_decoder.hpp 2024-02-21 18:33:41 +01:00
a4d0864980 Begin implementing simple physic system 2024-02-19 20:23:13 +01:00
027cd225a0 Add alternative build script for GNU make
It can be used on systems where setting up CMake is not possible or too complicated
2024-02-18 14:37:07 +01:00
df55220895 Remove X11_LIBRARIES description from docs/INSTALL.MD 2024-02-16 08:13:06 +01:00
32a53cc6fd Use std::ios::binary for Ogg input file stream 2024-02-12 17:13:29 +01:00
cfdc59d5bd Win32Window: Adapt to changes introduced in d097e34 2024-02-12 16:25:21 +01:00
8467fcc584 HaikuWindow: Adapt to changes introduced in d097e34 2024-02-11 17:52:10 +01:00
3735e77e03 WaylandWindow: Adapt to changes introduced in previous commit 2024-02-11 11:22:02 +01:00
d097e346b2 Make Window manage GLContext 2024-02-10 22:35:09 +01:00
7fef75d8c7 Dynamically load GLX 2024-02-10 11:50:28 +01:00
b1ddd2db79 Dynamically load Xlib
This will allow building universal executable that will work on both X11 and Wayland systems
without hard dependency on any of these dynamic libraries.
2024-02-09 22:06:45 +01:00
5d49b048fd Adapt NetworkManager retry interval to current reliable packet RTT
This will make sure to not drop packets when connection is slower.
2024-02-09 12:17:17 +01:00
318dd45b19 Fix rotation of Players 2024-02-08 18:50:09 +01:00
16ff9a88bb Inform players about server status 2024-02-04 20:38:51 +01:00
25b206dca8 Fix wrong raycast result node with negative coordinates 2024-02-04 13:59:40 +01:00
4ddbfe61e3 Don't call proxy object in cNode to prevent calling loop on Haiku 2024-02-03 20:41:58 +01:00
ffc912a4d4 Write player join and leave messages on chat 2024-02-03 11:37:56 +01:00
bd7f9cdfb9 Some quality fixes 2024-02-02 20:26:37 +01:00
11fc12bfd9 HaikuWindow: Fix crash when closing game while using OpenGL renderer 2024-02-01 22:38:08 +01:00
87eebfb4f6 Implement simple (but working!) Chat 2024-02-01 11:32:49 +01:00
dc67a81f9f LineEdit improvements and fixes 2024-01-30 18:09:34 +01:00
f382367980 Factor out text editing component from TextEdit into LineEdit 2024-01-30 14:09:23 +01:00
645edf5a25 Don't reload game session GUI after player mode change 2024-01-29 19:26:13 +01:00
c552012831 Implement hidden attribute for GUI components 2024-01-29 18:46:41 +01:00
de264be3e3 Renderer: Support mesh usage hints 2024-01-28 18:56:38 +01:00
85ebcfa38e X11Window: Use modern way of creating OpenGL context if available 2024-01-28 18:55:11 +01:00
503db418d3 Some code quality changes in udp_socket.cpp 2024-01-25 21:07:13 +01:00
b20e6c7fab Play music in entire main menu 2024-01-25 13:29:47 +01:00
a07662e544 Properly clean up OpenAL buffers in StreamingSource 2024-01-25 13:18:27 +01:00
beec158508 Implement StreamingSource for streaming music Ogg files. 2024-01-25 12:43:11 +01:00
56c58694d2 Implement OggVorbisDecoder class which exposes more control over audio decoding process 2023-12-29 13:19:47 +01:00
5fda30b1e1 Implement basic music playing support 2023-12-25 22:12:01 +01:00
612a31d2d8 Add write and read for math::Vector3i to NetworkPacket 2023-12-13 14:39:23 +01:00
00fb3131c7 Add basic editmode toolbox operation for filling 100x100 platform 2023-12-13 14:26:17 +01:00
539016b1be Deduplicate ChunkManager code 2023-12-12 20:23:50 +01:00
71def4e124 Begin implementing editmode context toolbox 2023-12-08 12:00:01 +01:00
Kacper Kostka
cc5ae2d620 MSYS2 Build fixed 2023-11-13 10:56:55 +01:00
e830bf2654 Properly render chunks while using normal meshing 2023-11-10 10:44:28 +01:00
50241f957e Implement writing and loading map to/from files 2023-11-09 22:05:40 +01:00
cf7b56167b Node editing improvements 2023-11-06 18:05:56 +01:00
7fea96083d Partial fix for node editing at negative coordinates 2023-11-05 16:15:43 +01:00
f409eb7233 update switch for haiku 2023-11-04 20:11:00 +01:00
75a7e0bf92 Implement moving in Y axis while in editmode 2023-11-03 10:43:33 +01:00
896165efe2 Optimize and fix chunk fill check 2023-11-02 20:44:57 +01:00
eb7767fa08 Write Haiku build instruction 2023-11-02 10:26:36 +01:00
84706809e0 HaikuGLContext: Implement get_proc_address 2023-11-01 15:48:51 +01:00
69a85ca620 HaikuWindow: Implement grab_mouse 2023-11-01 15:16:45 +01:00
c163b6a04e Remove GLM from INSTALL.MD 2023-10-31 19:24:30 +01:00
519a28ca5c Remove unneeded file 2023-10-31 19:24:09 +01:00
f7fdf74f83 Don't require GLM in CMakeLists.txt 2023-10-31 19:20:55 +01:00
846721f16c Final mathlib fixes 2023-10-31 19:19:07 +01:00
747af0662c change spaces 2 tabs 2023-10-31 16:09:12 +01:00
c7bf78fd3e add lookat function 2023-10-31 16:06:39 +01:00
e9d7a3268b Properly initialize math::Vector2f in ImageGallery 2023-10-31 11:16:33 +01:00
1ea341e8a8 Matrix4 calculations fixes
Fixes oversight in Matrix4::operator* and transformation order in MeshRenderer
2023-10-31 11:15:57 +01:00
3e98876ab1 Use our own math classes instead of GLM 2023-10-28 18:46:57 +02:00
6f92ddd034 Some additions and fixed to Vector and Matrix4 2023-10-28 18:35:18 +02:00
67f90e6428 Fix formatting in src/common/math/matrix4.*pp 2023-10-25 16:55:28 +02:00
ca8d02b0f6 matrix4 class 2023-10-25 16:36:15 +02:00
a2a6d71323 typedefs added 2023-10-25 16:36:15 +02:00
a528e45f2d Vector class added 2023-10-25 16:36:15 +02:00
c085310285 HaikuWindow: Text enter event 2023-10-24 15:29:10 +02:00
e8ea69616b HaikuWindow: Window resize event 2023-10-24 10:40:52 +02:00
a39f36fadb Change way of sending player position through network 2023-10-23 21:44:16 +02:00
9663247904 Fix typos in INSTALL.MD 2023-10-23 19:59:49 +02:00
66d933f2f5 Try to fix NetworkManager desynchronization 2023-10-23 15:42:39 +02:00
19bc297a62 Win32Window: Make sure to not propagate unprintable characters in text enter event 2023-10-23 14:27:02 +02:00
3e03918764 Increase packet retry interval in NetworkManager 2023-10-23 14:13:01 +02:00
917f45188a HaikuWindow: Keyboard and mouse input events 2023-10-22 14:46:30 +02:00
d25b6de1b5 Create window on Haiku 2023-10-22 11:47:13 +02:00
c73b363a7f Begin Haiku port 2023-10-20 18:46:00 +02:00
7d26a14787 REMOVE FILE CREATED BY SOME IDIOT AHHHHgit status 2023-10-20 11:34:21 +02:00
49922e4a18 Implement floating MessageBox 2023-10-20 11:28:22 +02:00
c7a8b8b46c Normal meshing fixes 2023-10-17 22:10:46 +02:00
a24cf97588 Implement normal meshing for older usage with LegacyGL 2023-10-16 21:35:01 +02:00
62c85aeb66 Make sure that modules were loaded before acknowledging that server is running 2023-10-15 11:37:48 +02:00
23a7a9fd40 Add crosschair image to editmode GameSessionScreen GUI 2023-10-14 19:35:12 +02:00
4bc94527df Add Image GUI component 2023-10-14 19:13:39 +02:00
91d41633a7 Use glyph separate cache for different font sizes 2023-10-13 19:54:09 +02:00
3dc4459a98 LegacyGL fixes
Changes in this commit make sure that textures are power of 2 on older hardware
2023-10-13 18:50:22 +02:00
3e1ce01a72 Optimize text rendering 2023-10-13 10:52:40 +02:00
63205f18de Only send grabbed mouse move event when offset is not 0 2023-10-10 19:10:24 +02:00
7068f16a34 Add position and target node displaying to EditmodeHUD 2023-10-09 22:32:05 +02:00
c12997a9cb Remove unused lambda capture 2023-10-08 20:26:13 +02:00
a24ef3953e Implement initial node placing 2023-10-08 19:37:03 +02:00
0c50e55f74 Add default_player_mode option to ServerConfig 2023-10-05 10:54:59 +02:00
5d705cfef5 Implement requesting chunk data from server 2023-10-04 22:20:26 +02:00
9fd53d1d0b Calculate player's position on server 2023-10-01 16:09:25 +02:00
5e03acbc95 WaylandWindow: Populate relative mouse coordinates when in grab mode 2023-09-26 10:29:43 +02:00
2b8c81822f Implement server player mode handling
Now it's possible to change player's mode (normal, editmode) via using server-side command 'mode'
2023-09-25 21:22:48 +02:00
5fe978c494 Save and restore renderer type in OptionsScreen 2023-09-22 11:04:40 +02:00
d9d5421299 Win32Window: Don't mouse move push event if relative offset is 0 2023-09-22 10:45:14 +02:00
5b76ee51fe Add some options to OptionsScreen 2023-09-19 19:54:11 +02:00
289ec70653 Start implementing OptionsMenu and add ComboBox 2023-09-18 21:29:35 +02:00
9de148271b Win32Window: Implement relative mouse position 2023-09-12 13:57:37 +02:00
d11664f067 Window: Add relative_x and relative_y to mouse move event 2023-09-11 18:41:45 +02:00
544c29e8b9 Add pause menu in GameSessionScreen 2023-09-09 22:13:04 +02:00
28b6de3d8c Fix some race condition issues via adding appriopriate guards 2023-09-08 18:51:06 +02:00
673fdff7ae Fix building on compilers other than GCC 2023-09-08 11:27:46 +02:00
fc48b9967c Very basic and naive player movement 2023-09-02 22:30:11 +02:00
128c87049c Make NetworkManager thread safe 2023-09-01 18:06:55 +02:00
6525d38603 Node texturing for GLSL 1.1 shaders 2023-09-01 13:22:23 +02:00
71bc558859 More work on node texturing 2023-08-31 18:32:04 +02:00
fc174d4b76 Implement crash handler 2023-08-30 21:31:57 +02:00
2191b589aa Moved Git to another location 2023-08-30 17:11:10 +02:00
e21869a3bf Some initial work on greedy texturing code 2023-08-30 17:10:37 +02:00
a7f17add73 Render other players 2023-08-28 22:10:05 +02:00
361d328a98 Fix crash in GUIMaster caused by not cleaning up highlighted component 2023-08-28 15:03:21 +02:00
80d84a362e Add Logger::fixme
It should be used for marking behaviour as intended for future revision
2023-08-26 20:59:28 +02:00
e20620fedf Implement XMLWriter 2023-08-25 22:26:45 +02:00
3d9dc19049 Proper detecting if userdir exists 2023-08-25 17:59:50 +02:00
a79612885b Support for simple text rendering 2023-08-24 20:24:51 +02:00
b6c252318e Add network protocol documentation 2023-08-24 19:00:38 +02:00
f7df6376f6 Fix oversights introduced in 97e4fda 2023-08-23 11:27:26 +02:00
59b881302b Implement GameConfig 2023-08-22 21:33:07 +02:00
97e4fdaf58 Fixes on FreeBSD 2023-08-22 13:58:50 +02:00
39122a6e51 Fix oversight introduced in previous commit 2023-08-21 12:30:55 +02:00
469280c7c8 Inform other players about new player on server 2023-08-21 11:13:29 +02:00
d669fb430b Implement Player and PlayerManager 2023-08-19 12:25:28 +02:00
86b9d49a52 Introduce Controller system 2023-08-18 10:18:25 +02:00
9651c88ffe Fix some random issues 2023-08-16 21:35:42 +02:00
f6ace83729 Add default text and numbers only support to TextEdit 2023-08-16 13:45:27 +02:00
c19ef32505 Add better node selector 2023-08-15 19:11:26 +02:00
7b6ac65d6a XMLParser: Implement support for short tag endings 2023-08-14 21:51:14 +02:00
84d93d21ea Server: Implement support for chunk requests 2023-08-14 11:56:21 +02:00
cfa99d24a0 Implement unfinished server side ChunkManager 2023-08-13 21:42:08 +02:00
a8f5068f1b Move Rect to common 2023-08-13 20:16:45 +02:00
21554417d1 Implement chunk compression and decompression methods 2023-08-12 22:24:23 +02:00
b02d83e72d Convert docs/MAP_FILE_FORMAT.MD to LF and add some updates 2023-08-12 22:24:23 +02:00
b90c6cb333 revert c370481954 at mrkubax10's request 2023-08-12 12:09:15 +02:00
c370481954 New header 2023-08-12 11:13:17 +02:00
4e6db00df8 improve transl'ns and locale PART 1 2023-08-12 10:11:38 +02:00
2d9adc6cef readme corrections + warranty disclaimer 2023-08-12 09:46:54 +02:00
fb87244bd8 remove unnec files part 2 2023-08-12 09:42:15 +02:00
eca141be99 remove unnec files part 1 2023-08-12 09:34:41 +02:00
kacperks
10d14cb8dc #include fixes 2023-08-12 09:28:29 +02:00
072333387f fixed networking build error on Windows 2023-08-11 22:03:14 +02:00
24c3fe5e62 Windows and Clang build fixes 2023-08-11 17:47:43 +02:00
55d6514e56 Add GLSL 1.1 shaders 2023-08-02 11:41:33 +02:00
2877a0576d Delete some unused code 2023-08-02 11:01:41 +02:00
e7cd381587 Fix some glyphs getting cropped while rendering text 2023-08-02 10:57:25 +02:00
9cfb36fd80 MasterRenderer code cleanup 2023-08-01 20:04:52 +02:00
850d22b5b1 Introduce LegacyGLGUIRenderer 2023-08-01 13:14:34 +02:00
475e44bcc5 Implement dummy LegacyGLShader 2023-07-31 13:14:24 +02:00
af0f8ecf3d Implement LegacyGLMeshRenderer 2023-07-30 13:09:43 +02:00
cc5d883482 Fix Legacy GL renderer compilation with X11 2023-07-29 10:41:17 +02:00
e9bb4470a2 Implement LegacyGLMesh 2023-07-28 20:14:36 +00:00
c4d9df60d9 Implement SerenityOSGLContext 2023-07-28 16:10:39 +00:00
ce4f65782f Create legacy OpenGL renderer 2023-07-28 10:23:47 +00:00
87e1a9aee0 Begin implementing legacy OpenGL renderer 2023-07-28 09:29:20 +00:00
2a85327a8e SerenityOSWindow: Implement TEXT_ENTER event support 2023-07-27 18:11:18 +00:00
5aaf24d8a7 SerenityOSWindow: WINDOW_RESIZE event support 2023-07-27 17:25:32 +00:00
b880279b42 SerenityOSWindow: Implement mouse events support 2023-07-27 12:21:34 +00:00
4c1d479dfe SerenityOSWindow: Implement KEY_DOWN and KEY_UP events 2023-07-27 10:07:49 +00:00
7045b5a6ed SerenityOSWindow: Window now creates 2023-07-26 13:04:12 +00:00
9eaf5a2f54 Game now compiles on SerenityOS 2023-07-24 11:07:17 +00:00
0e29610808 Begin adding support for SerenityOS 2023-07-23 12:59:26 +00:00
1299adbc68 Main menu is back. Finally! 2023-07-22 14:32:06 +02:00
31a6007f05 Implement GUI loading from file 2023-07-21 21:27:55 +02:00
61383029dc Add few more Constraints 2023-07-20 17:43:42 +02:00
1b1ae5cc3c Implement StackLayout 2023-07-20 13:35:24 +02:00
62fda5cc08 Add Box GUI component (static messagebox) 2023-07-19 19:14:57 +02:00
fe49c0ad1d Extrusion effect fixes in GUI 2023-07-19 12:34:49 +02:00
756a34128d Implement TextEdit GUI component
Please note that this component still has some issues which should be addressed in future
2023-07-18 21:26:28 +02:00
64db8d670b Add way to render part of texture 2023-07-17 20:38:01 +02:00
9833f2d757 Win32Window: Add TEXT_ENTER event support 2023-07-16 19:53:24 +02:00
f961018850 WaylandWindow: Add TEXT_ENTER event support 2023-07-13 18:42:01 +02:00
40a7372df9 INSTALL.MD improvements 2023-07-13 17:21:58 +02:00
5d6d48ebda Add TEXT_ENTER event 2023-07-12 13:13:06 +02:00
323d97d6fd Button now reacts to inactive state 2023-07-10 13:42:11 +02:00
5546775e55 Missing license headers 2023-07-10 12:55:51 +02:00
4d18d10c74 Some code cleanup 2023-07-10 12:46:34 +02:00
92a6d7c48f Add Button GUI component 2023-07-10 09:54:46 +02:00
2d00e6f19f Implement GUI master
It will be used for storing current GUI state
2023-07-09 13:35:02 +02:00
ae5b12bdd8 Some GUI tweaks 2023-07-08 21:43:37 +02:00
4be4f10c0c Add GUI container 2023-07-06 13:34:09 +02:00
8e929f44af Add StyleChangeListener for detecting Style changes 2023-07-03 14:08:12 +02:00
aa0557b1d8 Add Label GUI component 2023-07-03 12:24:29 +02:00
acb5b9fb16 Fix some memory leaks 2023-07-02 15:29:39 +02:00
0c64b08712 Implement basic Style loading 2023-07-02 14:36:18 +02:00
29d8bf474a Text rendering with line wrapping inside of area 2023-07-01 13:49:50 +02:00
e9e05d5ed1 Fix TCPSocket compilation error on Windows 2023-06-29 15:42:50 +02:00
e32ad97790 Add Constraint to GUI
It will be used to layout components in different way depending on Constraint type.
2023-06-28 19:56:05 +02:00
57e518e3b2 Remove libangelscript_addons.a which was added by accident 2023-06-28 19:10:41 +02:00
7c8202d182 Merge branch 'master' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun 2023-06-28 15:37:50 +02:00
baef716db1 remove files generated by build 2023-06-28 15:37:22 +02:00
7011bdc05f simple gui component class 2023-06-28 15:35:50 +02:00
16ed87afbb Add TCPSocket 2023-06-28 11:25:24 +02:00
0e6ebad2ba Implement TextureAtlas 2023-06-26 13:53:42 +02:00
8ec5777a7c Move media files to separate repo 2023-06-23 09:57:58 +02:00
f83bcbb194 Delete src/vendor 2023-06-22 20:30:29 +02:00
44a71dc477 Re-add nodes via scripting 2023-06-21 20:31:06 +02:00
2d76c42c9c Registered nodes are not hardcoded anymore 2023-06-21 12:42:44 +02:00
f303b17c41 Forgot to erase PendingDef from std::vector 2023-06-20 22:16:22 +02:00
24488e4495 Implement NodeDef retrieving from server 2023-06-20 22:11:47 +02:00
bfdb82a741 Mention FreeType in INSTALL.MD 2023-06-20 10:49:41 +00:00
07e79fd1ac Text rendering optimizations 2023-06-20 12:06:50 +02:00
6500ffd1d9 Add some methods to Font for usage in GUI 2023-06-20 11:06:50 +02:00
aa3c35ed1a Fix character positioning while rendering text 2023-06-19 22:19:05 +02:00
7986f9ac73 Very simple FreeType text rendering 2023-06-19 21:51:41 +02:00
285e83246e FreeType font loading 2023-06-19 11:18:30 +02:00
bb4a967290 Detect Freetype in CMakeLists.txt 2023-06-19 10:58:08 +02:00
11f7f7ff1a Add Windows with vcpkg and Visual Studio building instructions
Reviewed-on: http://git.cubesoftware.xyz:20524/PolyGun/PolyGun/pulls/7
Co-authored-by: bruhmoent <kmega757@gmail.com>
Co-committed-by: bruhmoent <kmega757@gmail.com>
2023-06-18 19:35:08 +00:00
63ee210e40 Move cmake to mk folder 2023-06-18 15:49:27 +02:00
8972f2f1f5 Merge branch 'custom_windowing_system' 2023-06-18 15:45:26 +02:00
8a5052ecc6 Update INSTALL.MD to mention Wayland libraries 2023-06-18 10:22:43 +02:00
73e4868ce8 WaylandWindow: Implement grab_mouse 2023-06-18 10:11:53 +02:00
a556d6468a WaylandWindow: Implement mouse events 2023-06-16 16:36:52 +02:00
6f3b5a6884 Remove testing code 2023-06-15 18:14:04 +02:00
9928fd4f1f WaylandWindow: Implement keyboard events 2023-06-15 18:12:37 +02:00
b45732c05d Fix misplaced #endif in window.cpp 2023-06-15 17:24:27 +02:00
d2ac9f8013 WaylandWindow: Window resize event support 2023-06-15 14:40:54 +02:00
0b341cdda1 Implement EGLGLContext 2023-06-14 18:56:52 +02:00
e0c70ae7e7 added concept of GUI system to the docs 2023-06-14 18:20:37 +02:00
d759e70a1d Move extension query code to GLContext 2023-06-13 21:58:18 +02:00
9a6c875398 Updated README.MD 2023-06-11 23:36:40 +00:00
efd3959b5b Begin implementing WaylandWindow 2023-06-10 15:35:27 +02:00
eb15f62f83 Update INSTALL.MD so it mentions libX11 instead of XCB 2023-06-10 12:26:42 +02:00
ecf6f7137f Win32Window: Fix some oversights 2023-06-10 12:18:45 +02:00
32218b00dc Implement X11Window::grab_mouse 2023-06-09 12:09:48 +02:00
9ceede5bbb Add mouse events support to X11Window 2023-06-08 19:33:40 +02:00
f166a85e69 Add key down and key up events support in X11Window 2023-06-08 14:59:42 +02:00
f825d1fe53 Window resize and close events in X11Window 2023-06-08 12:21:06 +02:00
a5972e4e1a Implement X11GLContext 2023-06-07 21:19:32 +02:00
fff349c71a Begin implementing X11Window 2023-06-07 16:11:37 +02:00
6d9b05c927 Remove GLFW3 dependency from INSTALL.md 2023-06-07 11:44:18 +02:00
33b0d44fc9 Implement mouse grabbing support in Win32Window 2023-06-07 11:24:43 +02:00
27b0d205dd Remove GLFW3 dependency 2023-06-06 19:41:21 +02:00
0639e6bbec Delete ImGui code because it won't be compatible with custom windowing system 2023-06-06 17:47:43 +02:00
bd1af5419e Implement GLContext for Win32 window 2023-06-06 17:35:57 +02:00
74f1103618 List client sources manually in CMakeLists.txt 2023-06-05 20:04:19 +02:00
4da8dd00ff React properly to Alt+F4 in Win32Window 2023-06-05 18:57:02 +02:00
7e6cb8f9b1 Add mouse wheel event support to Win32Window 2023-06-05 18:44:26 +02:00
85f5039c81 Add mouse move event support to Win32Window 2023-06-05 18:33:37 +02:00
3c973eb28d Add methods for querying keyboard and mouse state 2023-06-05 18:23:43 +02:00
20d8236701 Add mouse button down and mouse button up events support to Win32Window 2023-06-05 18:23:43 +02:00
2c421c37ff Add key up and key down event support to Win32Window 2023-06-05 18:23:43 +02:00
758cc39c19 Add KeyCode enum 2023-06-05 18:23:42 +02:00
55c24686f1 Fix Win32 window creation 2023-06-05 18:23:42 +02:00
f7dd288908 Win32 window creation 2023-06-05 18:23:42 +02:00
b5a79753ea Begin implementing custom windowing system 2023-06-05 18:23:41 +02:00
c4b7444b7a Implement ResourceManager for retrieving resources from server 2023-06-03 22:37:58 +02:00
eaf2765c96 Add Cygwin instructions to INSTALL.MD 2023-06-01 12:40:41 +00:00
3cb4f9a54b Add ThreadSafe util class 2023-05-31 21:05:29 +02:00
16f2ef8e02 Fix fs.cpp compilation issues on Windows 2023-05-31 21:04:53 +02:00
2ceb1ea26c More figlet adjustments 2023-05-29 22:17:46 +00:00
f9f3ee58ff Change screen only in game loop 2023-05-28 19:40:22 +02:00
9ca021133b Minor changes to the figlet 2023-05-28 17:03:54 +00:00
23b3700a42 Compile with highest warning mode by default 2023-05-24 11:56:31 +02:00
adea97280e Code quality fixes 2023-05-24 11:43:22 +02:00
d43890e4cf Override server config port while hosting game 2023-05-23 18:37:56 +02:00
e89406f8f2 Add support for server configuration 2023-05-23 13:02:07 +02:00
7aaa095fbc Implement XMLReader 2023-05-23 11:47:55 +02:00
af18839fe6 Implement polygun::utils::get_user_dir function 2023-05-22 20:07:04 +02:00
3d5bd4ebff Implement node registering in API 2023-05-21 11:50:53 +02:00
6278183960 Fix building client only executable 2023-05-20 14:56:00 +02:00
7d254ab0e5 extract_strings improvements 2023-05-19 16:44:06 +02:00
b22b7411eb Merge branch greedy-implementation 2023-05-19 16:22:21 +02:00
de21aa399e Fix some oversights 2023-05-18 18:32:28 +02:00
47b2dca56f Merge branch extract_strings: Implement extract_strings tool 2023-05-18 17:57:36 +02:00
3171e3f958 Fix compilation with MSVC 2023-05-18 12:08:29 +02:00
d9b7d02e4d Kewler header 2023-05-17 20:23:58 +00:00
b43b69a749 implement greedy meshing without textures 2023-05-16 15:30:29 +02:00
4b4ea9e4ff entity class base fixed 2023-05-16 15:28:06 +02:00
42b1c2aeb8 Merge branch 'master' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun into HEAD 2023-05-16 15:23:16 +02:00
eb7bb26804 entity class base added 2023-05-16 15:22:55 +02:00
4166103b68 Add Node class to API 2023-05-14 20:34:06 +02:00
854143a980 Cleanup extension detecting code 2023-05-13 21:08:28 +02:00
905019db00 Add AngelScript to BUILD_SERVER libraries 2023-05-13 17:40:26 +02:00
c7017f5508 .gitignore cleanup 2023-05-13 12:58:20 +02:00
3b1f9ae9c5 Add map file format documentation draft 2023-05-13 12:54:01 +02:00
93c00706fc Proper logging functions for API 2023-05-13 11:13:15 +02:00
69a2f2e14b Start implementing scripting support 2023-05-12 22:39:22 +02:00
c7fe733cd6 Merge HEAD into master to fix conflicts 2023-05-11 14:33:48 +02:00
c029a909a6 Fix server console input on Windows 2023-05-11 14:21:40 +02:00
bb0df38b70 Add Polish locale 2023-05-11 13:19:25 +02:00
c638acc117 Fix accessing freed memory caused by deleting root XMLNode in parser 2023-05-11 11:00:20 +02:00
Kacper Kostka
7e54de7c9d fixed errors 2023-05-10 22:34:38 +02:00
Kacper Kostka
cebf698aa5 Merge branch 'master' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun 2023-05-10 22:00:11 +02:00
5916f293c3 Merge branch 'master' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun into HEAD 2023-05-10 21:57:00 +02:00
8110767654 Generate mesh function added into chunk class 2023-05-10 21:56:41 +02:00
407e6ef039 Remove unnecessary audio source creation 2023-05-10 17:00:05 +02:00
e47215d71e Add way to add custom buffers to Mesh 2023-05-10 16:54:12 +02:00
1be9c270a1 Merge branch 'master' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun 2023-05-09 21:01:41 +02:00
2d6d0b189b greedy meshing finally working! not rendered yet 2023-05-09 21:01:34 +02:00
de4f8a11fe Fix comments support in XML lexer 2023-05-09 20:04:50 +02:00
Kacper Kostka
2952ff378f added license prefix 2023-05-09 15:55:18 +02:00
Kacper Kostka
27c7917338 added license prefix 2023-05-09 15:52:38 +02:00
b8456634ae Add way to directly join server or host it 2023-05-08 22:13:07 +02:00
f732a6a343 Fix XMLNode memory leak 2023-05-08 15:04:10 +02:00
0e6eac2829 Implement locale system 2023-05-07 21:16:54 +02:00
d093a0105e Fix flipped textures in GUIRenderer 2023-05-07 20:05:00 +02:00
df9a6efbf3 Make sure that Logger is thread safe 2023-05-07 15:30:01 +02:00
e339c234c0 added node breaking 2023-05-06 22:16:14 +02:00
bc914d7398 Merge branch 'master' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun 2023-05-06 20:08:56 +02:00
1f9dc57e11 fixed render going black when cursor is not captured 2023-05-06 20:08:49 +02:00
c45ee1b6ed Add XML parser 2023-05-06 19:39:50 +02:00
a88262463f automatic imgui frame size 2023-05-06 15:19:40 +02:00
1ca49626d5 overal meshing code cleanup 2023-05-06 15:02:50 +02:00
22ccf33e4a huge commit of idk if working meshing 2023-05-06 12:00:59 +02:00
80b0dcd51d fixed broken link in readme 2023-05-05 19:37:10 +02:00
10f6d9bebb Merge branch 'master' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun 2023-05-05 19:36:20 +02:00
410a883f12 fixed broken link in readme 2023-05-05 19:35:47 +02:00
df77a4b847 fixed broken readme link 2023-05-05 19:35:16 +02:00
07c3a1dad1 Update 'LICENSE.TXT' 2023-05-05 17:34:04 +00:00
2716bbf9d1 another readme change 2023-05-05 19:33:40 +02:00
4f7a1f4443 updated readme 2023-05-05 19:32:32 +02:00
Kacper Kostka
c5d60527a0 greedy meshing compilation errors fixed 2023-05-05 13:03:04 +02:00
771d624c4e updated INSTA.MD again 2023-05-04 13:51:19 +02:00
b0a931657a updated install guide 2023-05-04 13:45:50 +02:00
f6eaa5ff8e moved windows with msys build instructions to INSTALL.MD 2023-05-04 13:34:41 +02:00
351353ce63 updated greedy merging to math coding style 2023-05-04 12:53:45 +02:00
Kacper Kostka
1861ef16eb greedy meshing arguments again 2023-05-04 12:18:54 +02:00
Kacper Kostka
940eb961cd Merge branch 'master' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun 2023-05-04 12:09:10 +02:00
Kacper Kostka
8434f0f11e greedy meshing arguments 2023-05-04 12:08:46 +02:00
4ff099de99 near plane is now smaller 2023-05-04 11:59:40 +02:00
Kacper Kostka
44a92ea288 fix 2023-05-04 11:53:59 +02:00
59f8d4ab08 Merge branch 'master' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun into HEAD 2023-05-03 01:26:12 +02:00
86d6aba1f6 delete hud.hpp and hud.cpp 2023-05-03 01:25:47 +02:00
f08e090c65 Node Choosing HUD and header in main menu added 2023-05-03 01:25:22 +02:00
897b1c937b Capitalize 2023-05-02 22:05:20 +00:00
9d360fe9ed Detect if GLM is available 2023-05-02 16:16:56 +02:00
b06e98eadb OpenGL renderer tweaks 2023-05-02 13:59:41 +02:00
f45d54abe5 Fix formatting 2023-05-02 12:32:54 +02:00
2660bffe3e Update documentation 2023-05-02 12:32:13 +02:00
755ca93a4e Forgot to add CMake script for finding Wayland 2023-05-02 12:28:32 +02:00
e4cf4d4948 CMakeLists.txt tweaks 2023-05-02 10:55:23 +02:00
ed72cd0a5a Updated README 2023-05-01 21:53:54 +00:00
efaa8c86d6 Merge branch glew_replace: Don't use GLEW for loading OpenGL functions 2023-04-30 21:46:26 +02:00
98a60b507c require -> required 2023-04-30 17:37:09 +00:00
b369c925dc Added instructions for building on Windows w/ MSYS 2023-04-30 17:36:51 +00:00
fe71cef42f Merge branch 'master' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun into HEAD 2023-04-30 13:11:34 +02:00
19f050a2d0 Fix color blending in Surface 2023-04-30 10:52:24 +02:00
137c5d6464 Use libpng for loading images 2023-04-29 16:12:53 +02:00
c4614944aa Greedy Meshing base added 2023-04-28 16:26:36 +02:00
e4716d47d1 Implement GUIRenderer 2023-04-25 21:47:35 +02:00
3525ecac71 Fix issue introduced in previous commit 2023-04-24 14:08:48 +02:00
c4bdf73ca9 Fix compilation on Windows due to missing signal enums 2023-04-24 13:53:02 +02:00
0cb42976d8 BUILD_SERVER cleanup 2023-04-24 13:20:09 +02:00
bc0717b189 Implement Host game option and proper connection to server 2023-04-23 21:58:22 +02:00
c549e4cae9 Add main menu using ImGui 2023-04-23 18:47:41 +02:00
4ac64797e4 new blocktypes 2023-04-23 18:11:41 +02:00
7603da2bd2 Merge pull request 'merge graphics_api_abstraction_layer' (#3) from graphics_api_abstraction_layer into master
Reviewed-on: http://git.cubesoftware.xyz:20524/kacperks/PolyGun/pulls/3
2023-04-23 09:05:13 +00:00
e3c11e064f textures 2023-04-23 11:03:42 +02:00
1ef6bc560e Merge branch 'graphics_api_abstraction_layer' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun into HEAD 2023-04-23 11:03:01 +02:00
966fe26e10 new blocks, textures for each block 2023-04-23 11:02:50 +02:00
4ebd63f9ea Cleanup 2023-04-22 12:10:36 +02:00
50c5238219 Placing blocks fixed 2023-04-22 11:16:14 +02:00
c1afe4de62 Merge branch 'graphics_api_abstraction_layer' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun into HEAD 2023-04-22 09:49:25 +02:00
c9615dfc2b Implement graphics API abstraction layer 2023-04-21 20:45:32 +02:00
0561ed005a ECS base added 2023-04-16 15:19:31 +02:00
7b633a6a63 Greedy merging from branch greedy-merging added to avoid conflicts 2023-04-16 11:00:59 +02:00
0f4eae6eaf Merge branch screens: Implement state screens system 2023-04-15 18:37:39 +02:00
abc414046f Use for signal description in server 2023-04-14 21:23:29 +02:00
2523a91dfd .gitignore update 2023-04-14 20:40:21 +02:00
6dd8b27ae1 Add server console 2023-04-14 20:30:11 +02:00
3f31762859 Add colors to Logger 2023-04-12 22:21:57 +02:00
fa6f50eb84 Implement client <-> server connection 2023-04-12 21:49:15 +02:00
7d8fec8aff Implement OpenAL-based audio sound system with Ogg file loading support
Co-Authored-by: Looki2000 <electro.brzostek@gmail.com>
2023-04-11 12:59:36 +02:00
248e314644 Add MIT license information to every file which I created 2023-04-11 12:36:02 +02:00
e33445b4e2 Merge pull request 'greedy-merging' (#1) from greedy-merging into master
Reviewed-on: http://git.cubesoftware.xyz:20524/kacperks/PolyGun/pulls/1
2023-04-11 08:24:05 +00:00
0b521a3a63 VertexArray class fixed 2023-04-11 10:21:13 +02:00
cb648b2e20 fix 2023-04-11 08:12:33 +02:00
a08a18424a fixed bug causing camera to move very slowly when looking directly down 2023-04-11 01:45:21 +02:00
b05e22b110 fixed namespaces 2023-04-10 23:23:23 +02:00
4314254c04 Greedy Merging base added 2023-04-10 23:11:44 +02:00
9ffb3c116a VertexArray Class Deconstructor added 2023-04-10 15:41:13 +02:00
b8a0410d25 VertexArray Class added 2023-04-10 15:40:05 +02:00
6dc659a4e2 changed window size to bigger and 16:9, changed "zoom" to "fov", changed default fov to 90 2023-04-10 12:45:57 +02:00
b1dc69ed28 Merge branch 'master' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun 2023-04-08 11:00:22 -04:00
09667f9441 Nodepos's are now integers 2023-04-08 10:58:54 -04:00
86fa716f03 changed default camera position and rotation 2023-04-08 16:55:13 +02:00
4bf4e22383 camera movement changed to minecraft-like 2023-04-08 10:41:59 +02:00
acc07bcbbb fix 2023-04-07 11:06:43 +02:00
69561e0a7f fixed cursor releasing on esc key press 2023-04-07 00:06:49 +02:00
9962ac9dea updated readme.md 2023-04-06 21:45:02 +02:00
1d881a3f76 Merge branch 'master' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun 2023-04-06 21:37:11 +02:00
7913f50d4c projection matrix fixed 2023-04-06 21:37:02 +02:00
ec35c6e941 updated .gitignore 2023-04-06 21:31:43 +02:00
d06d7c3eef Merge branch 'master' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun 2023-04-06 20:47:26 +02:00
c1109cb72c Simple chunk rendering 2023-04-06 20:47:07 +02:00
a4d748f2dd Changes to .gitignore 2023-04-06 15:44:55 +02:00
415c5779fe Some work on server 2023-04-06 15:14:46 +02:00
c19f96f9ac fix 2023-04-06 11:32:39 +02:00
aa0cfd59e2 Merge branch 'master' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun 2023-04-06 11:22:59 +02:00
342738ff0f Chunk rendering refectoring 2023-04-06 11:22:40 +02:00
fc926692d6 Lowercaseization 2023-04-06 01:46:05 +00:00
SolindekDev
14099d85d5 Updated audio engine to work with openal, but sound is not working.. 2023-04-04 21:51:01 +02:00
de1b6e44ac Add Windows support to UDPSocket 2023-04-02 20:10:32 +02:00
4bd1062db9 Changed the ASCII "art" 2023-04-02 16:26:57 +00:00
afabbfc20f Merge branch 'master' of http://git.cubesoftware.xyz:20524/kacperks/PolyGun 2023-04-01 17:12:48 +02:00
89978fa5ed Added some stuff but it dosen't work yet 2023-04-01 17:08:32 +02:00
ddce87c047 Forgot to add config.hpp.in 2023-04-01 12:10:03 +02:00
d4b31299e6 Merge branch cmake_tweaks: Some tweaks to CMakeLists.txt 2023-04-01 11:27:39 +02:00
b2b114c94d Add some logging to NetworkManager 2023-04-01 10:10:55 +02:00
7b25295b8c Node, Chunk and ChunkRenderer base added 2023-03-31 22:06:44 +02:00
9a5f82aeac Merge branch logger: Implement simple logger 2023-03-31 21:16:05 +02:00
d874ff7708 Introduce initial version of NetworkManager 2023-03-31 20:07:04 +02:00
SolindekDev
eee1571fa4 Added audio support (linux) 2023-03-31 12:14:48 +02:00
6117fcd47b Add UDPSocket and NetworkPacket 2023-03-30 22:16:57 +02:00
2243e3d6ba Add utilities for converting from and to bytes 2023-03-30 21:22:48 +02:00
SolindekDev
ec40e313e4 Moved /src/audio to /src/game/audio 2023-03-30 20:16:02 +02:00
6ddfb19ed4 Merge branch fix_code_style: Fix code style project-wide 2023-03-30 19:43:16 +02:00
SolindekDev
25947288f7 Created new /src/audio direcotry in which audio files will be 2023-03-30 15:20:25 +02:00
3e06438f7a txt -> MD 2023-03-29 20:36:35 +00:00
828fe646ce changed to markdown 2023-03-29 20:34:33 +00:00
c3690acd5d Update 'CODING_STYLE.TXT' 2023-03-29 20:27:11 +00:00
d7c84b70e8 header guards fixed 2023-03-29 12:32:03 +02:00
f78f452d26 Merge branch 'master' of http://git.cubesoftware.xyz:20524/kacperks/rtfps 2023-03-29 11:59:01 +02:00
515db93d07 refactored code 2023-03-29 11:58:49 +02:00
392 changed files with 48378 additions and 56397 deletions

80
.gitignore vendored
View File

@@ -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

View File

@@ -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}")

View File

@@ -1,5 +1,3 @@
MIT License
Copyright (c) 2023 kacperks, Looki2000, Solindek, mrkubax10
Copyright (c) 2021-2023 Migdyn

40
config.hpp.in Normal file
View 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"

View 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

View 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

View 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

View 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()

Binary file not shown.

After

Width:  |  Height:  |  Size: 961 KiB

View File

@@ -0,0 +1,4 @@
Blender version: 4.1.1
cubemap.png generated on: https://tools.wwwtyro.net/space-3d/index.html
seed: retertert

Binary file not shown.

Binary file not shown.

136
docs/GUI.MD Normal file
View 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
View 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
View 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
View 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
View 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>

View 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
)

View 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)

View 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()

View 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
)

View 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()

View 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
)

View 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
View 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
View 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

View 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>

View 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>

View 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());
}

View 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
View 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
View 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;
}
}
}

View File

@@ -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)

View 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>

View 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
View 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
View 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
View 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
View 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>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 682 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 376 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 423 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 857 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 685 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 692 B

View File

@@ -1,11 +0,0 @@
#version 330 core
out vec4 FragColor;
in vec2 TexCoord;
uniform sampler2D texture1;
void main()
{
FragColor = texture(texture1, TexCoord);
}

View File

@@ -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);
}

View 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);
}

View 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;
}

View 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);
}

View 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;
}

View File

@@ -0,0 +1,9 @@
#version 330 core
uniform vec4 uniform_color;
out vec4 out_color;
void main() {
out_color = uniform_color;
}

View 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);
}

View 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;
}

View 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;
}

View File

@@ -0,0 +1,9 @@
#version 330 core
out vec4 out_color;
uniform vec4 uniform_color;
void main() {
out_color = uniform_color;
}

View 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);
}

View 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);
}

View 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;
}

View 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);
}

View 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;
}

View 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;
}

View 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;
}

View 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);
}

View 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;
}

View File

@@ -0,0 +1,7 @@
#version 110
uniform vec4 uniform_color;
void main() {
gl_FragColor = uniform_color;
}

View 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);
}

View 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;
}

View 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;
}

View File

@@ -0,0 +1,7 @@
#version 110
uniform vec4 uniform_color;
void main() {
gl_FragColor = uniform_color;
}

View 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);
}

View 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);
}

View 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;
}

View 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);
}

View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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

View 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
}

View 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
View 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];
}
}

View 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

View 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
}

View 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

View 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];
}

View 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
View 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
View 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

View 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];
}

Some files were not shown because too many files have changed in this diff Show More