Browse Source

added credits and basic test suite for WLambda

tags/v0.4.0_alpha
Weird Constructor 3 years ago
parent
commit
afc660d8b5
  1. 61
      README.md
  2. BIN
      doc/game_design_and_core_loop_diagram.odg
  3. 222
      godot_bind/Cargo.lock
  4. 15
      godot_bind/Cargo.toml
  5. 38
      godot_bind/src/gui/game_painter.rs
  6. 858
      godot_bind/src/gui/logic.rs
  7. 4
      godot_bind/src/gui/mod.rs
  8. 227
      godot_bind/src/gui/tree_painter.rs
  9. 1163
      godot_bind/src/gui/widgets.rs
  10. 486
      godot_bind/src/gui/wlambda_api.rs
  11. 5
      godot_bind/src/lib.rs
  12. 21
      godot_bind/src/state.rs
  13. 39
      godot_bind/src/util.rs
  14. 2
      godot_bind/src/voxel_structure.rs
  15. 2
      godot_bind/src/wl_gd_mod_resolver.rs
  16. 119
      godot_project/elements.csv
  17. 26
      godot_project/gamelib/credits.wl
  18. 7
      godot_project/gamelib/elements.wl
  19. 6
      godot_project/gamelib/game_mockup.wl
  20. 30
      godot_project/gamelib/main.wl
  21. 21
      godot_project/gamelib/test_game.wl
  22. 23
      godot_project/gamelib/test_util.wl
  23. 34
      godot_project/gamelib/util.wl
  24. 9
      godot_project/scenes/entities/VoxelStructure.tscn
  25. 2
      godot_project/scenes/system_map/system_map.tscn

61
README.md

@ -17,6 +17,16 @@ If GitHub is failing, I recommend looking at my backup Git repositories:
- [Backup Git Repositories](https://m8geil.de:3000/WeirdConstructor)
# Screenshots
---
![screenshot1](https://m8geil.de/data/push/136_97_image.png)
---
![screenshot2](https://m8geil.de/data/push/136_142_image.png)
---
![screenshot3](https://m8geil.de/data/push/274_152_image.png)
---
# Code and Assets License
This project is licensed under the GNU General Public License Version 3 or
@ -87,57 +97,12 @@ without any additional terms or conditions.
# Asset Licenses and Attribution
## 3D Models
### Copyright 2019 WeirdConstructor - GPLv3 or later
- models/skys/sky1.blend
- models/map/crosshair.blend
- models/stations/space\_station\_1\*
- models/rocks/asteroid\_1\*
- models/ships/ship\_1\*
## Images
- images/Orion\_Nebula\_-\_Hubble\_2006\*
From Wikipedia: `https://de.wikipedia.org/wiki/Datei:Orion_Nebula_-_Hubble_2006_mosaic_18000.jpg`
NASA, ESA, M. Robberto (Space Telescope Science Institute/ESA)
and the Hubble Space Telescope Orion Treasury Project Team;
Regarding copyright: NASA & Space Telescope Science Institute images are public domain;
this image also involved ESA, but it can be found at ESA's Hubble site,
which states that "The Hubble material you see on these pages is copyright-free"
- images/Hubble2005-01-barred-spiral-galaxy-NGC1300.\*
From Wikipedia: `https://de.wikipedia.org/wiki/Datei:Hubble2005-01-barred-spiral-galaxy-NGC1300.jpg`
http://hubblesite.org/newscenter/archive/releases/2005/01/image/a
NASA, ESA, and The Hubble Heritage Team STScI/AURA)
Regarding copyright: This file is in the public domain because it was created
by NASA and ESA. NASA Hubble material (and ESA Hubble material prior to 2009)
is copyright-free and may be freely used as in the public domain without fee,
on the condition that only NASA, STScI, and/or ESA is credited as the source
of the material. This license does not apply if ESA material created after
2008 or source material from other organizations is in use.
The material was created for NASA by Space Telescope Science Institute under
Contract NAS5-26555, or for ESA by the Hubble European Space Agency Information
Centre. Copyright statement at hubblesite.org or 2008 copyright statement at
spacetelescope.org. For material created by the European Space Agency on the
spacetelescope.org site since 2009, use the {{ESA-Hubble}} tag.
## Sounds
- 240566\_\_onikage22\_\_blip-plock-pop.wav
- CC0 - https://freesound.org/people/onikage22/sounds/240566/
- 11221\_\_jnr-hacksaw\_\_zap.flac
- CC0 - https://freesound.org/people/jnr%20hacksaw/sounds/11221/
Please refer to `assets/LICENSES_ATTRIB.md`.
# Credits
## Feedback, Tips and Ideas
- Gargaj for hints and feedback.
- szczm for play testing and feedback.
- Tom from Recall Singularity Project for throwing ideas back and forth.
- Ilmuri from Recall Singularity Discord for input about graphics programming.
- Itmuckel from Discord for feedback.
Please refer to `godot_project/gamelib/credits.wl` for a listing
of contributors and media sources.
# Authors

BIN
doc/game_design_and_core_loop_diagram.odg

Binary file not shown.

222
godot_bind/Cargo.lock generated

@ -27,16 +27,6 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "astar"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
"typed-arena 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "autocfg"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -82,7 +72,7 @@ dependencies = [
"peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -116,11 +106,6 @@ dependencies = [
]
[[package]]
name = "c_vec"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cc"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -220,11 +205,6 @@ dependencies = [
]
[[package]]
name = "fnv"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -391,16 +371,6 @@ dependencies = [
]
[[package]]
name = "num"
version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
"num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-integer"
version = "0.1.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -410,24 +380,6 @@ dependencies = [
]
[[package]]
name = "num-iter"
version = "0.1.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -521,11 +473,6 @@ dependencies = [
]
[[package]]
name = "piston-float"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "ppv-lite86"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -539,11 +486,6 @@ dependencies = [
]
[[package]]
name = "proc_vector2d"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "quote"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -553,24 +495,6 @@ dependencies = [
[[package]]
name = "rand"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@ -584,15 +508,6 @@ dependencies = [
[[package]]
name = "rand_chacha"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_chacha"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@ -623,14 +538,6 @@ dependencies = [
[[package]]
name = "rand_hc"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_hc"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@ -638,24 +545,6 @@ dependencies = [
]
[[package]]
name = "rand_isaac"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_jitter"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_os"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -670,15 +559,6 @@ dependencies = [
[[package]]
name = "rand_pcg"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_pcg"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@ -686,14 +566,6 @@ dependencies = [
]
[[package]]
name = "rand_xorshift"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rdrand"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -719,13 +591,13 @@ dependencies = [
[[package]]
name = "regex"
version = "1.3.1"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -810,29 +682,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "sdl2"
version = "0.32.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"c_vec 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2-sys 0.32.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sdl2-sys"
version = "0.32.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -892,26 +741,14 @@ dependencies = [
]
[[package]]
name = "sscg"
version = "0.1.0"
dependencies = [
"astar 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2 0.32.2 (registry+https://github.com/rust-lang/crates.io-index)",
"vecmath 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"vector2d 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"wlambda 0.3.5",
]
[[package]]
name = "sscg_gd"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"euclid 0.20.3 (registry+https://github.com/rust-lang/crates.io-index)",
"gdnative 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"palette 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sscg 0.1.0",
"regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"wlambda 0.3.5",
]
@ -938,7 +775,7 @@ dependencies = [
[[package]]
name = "thread_local"
version = "0.3.6"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -955,11 +792,6 @@ dependencies = [
]
[[package]]
name = "typed-arena"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-segmentation"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -980,22 +812,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "vecmath"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"piston-float 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "vector2d"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc_vector2d 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "version_check"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -1034,7 +850,7 @@ name = "wlambda"
version = "0.3.5"
dependencies = [
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rmp-serde 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustyline 4.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1046,7 +862,6 @@ dependencies = [
"checksum approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3"
"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee"
"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
"checksum astar 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05aa121d5262761e2e39dc6ca33bc16f5bff74feae0bc8d010b4c93b979143bf"
"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
"checksum backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea"
"checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491"
@ -1056,7 +871,6 @@ dependencies = [
"checksum blake2b_simd 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b83b7baab1e671718d78204225800d6b170e648188ac7dc992e9d6bddf87d0c0"
"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
"checksum c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb"
"checksum c_vec 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f8a318911dce53b5f1ca6539c44f5342c632269f0fa7ea3e35f32458c27a7c30"
"checksum cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)" = "aa87058dce70a3ff5621797f1506cb837edd02ac4c0ae642b4542dce802908b8"
"checksum cexpr 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "fce5b5fb86b0c57c20c834c1b412fd09c77c8a59b9473f86272709e78874cd1d"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
@ -1069,7 +883,6 @@ dependencies = [
"checksum euclid 0.20.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f46a3516f04c5e05870f71ae6242a97e8f72ee12cfc2f7f5deb16111a98b0670"
"checksum failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9"
"checksum failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08"
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
"checksum gdnative 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "03ab4424c22fee9f1080c31261a13263814d24055ff895817755f6dbb58d5523"
"checksum gdnative-bindings 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7c956bded8e1fb9e2e00c9aefbc1e5b3766b4d41b177188a2bdbe5b62a3ddb3"
@ -1090,10 +903,7 @@ dependencies = [
"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
"checksum nix 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4dbdc256eaac2e3bd236d93ad999d3479ef775c863dbda3068c4006a92eec51b"
"checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
"checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e"
"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09"
"checksum num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "76bd5272412d173d6bf9afdf98db8612bbabc9a7a830b7bfc9c188911716132e"
"checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32"
"checksum palette 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a05c0334468e62a4dfbda34b29110aa7d70d58c7fdb2c9857b5874dd9827cc59"
"checksum palette_derive 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0b4b5f600e60dd3a147fb57b4547033d382d1979eb087af310e91cb45a63b1f4"
@ -1104,30 +914,21 @@ dependencies = [
"checksum phf_codegen 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cbffee61585b0411840d3ece935cce9cb6321f01c45477d30066498cd5e1a815"
"checksum phf_generator 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526"
"checksum phf_shared 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7"
"checksum piston-float 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f900be47e312e126cc71d35548e8e31edd3901b92ab82d1c4c4757e6b5526564"
"checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b"
"checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27"
"checksum proc_vector2d 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "42ecc0faae16de3ca772d9083ce96872ab6758767deb1efb46e954dfc1d98342"
"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
"checksum rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
"checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853"
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
"checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
"checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08"
"checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b"
"checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
"checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44"
"checksum rand_pcg 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
"checksum redox_users 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecedbca3bf205f8d8f5c2b44d83cd0690e39ee84b951ed649e9f1841132b66d"
"checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd"
"checksum regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b5508c1941e4e7cb19965abef075d35a9a8b5cdf0846f30b4050e9b55dc55e87"
"checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716"
"checksum rmp 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0f594cb7ff8f1c5a7907f6be91f15795c8301e0d5718eb007fb5832723dd716e"
"checksum rmp-serde 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4a31c0798045f039ace94e0166f76478b3ba83116ec7c9d4bc934c5b13b8df21"
@ -1138,8 +939,6 @@ dependencies = [
"checksum rustyline 4.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0f47ea1ceb347d2deae482d655dc8eef4bd82363d3329baffa3818bd76fea48b"
"checksum ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8"
"checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d"
"checksum sdl2 0.32.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d051a07231e303f5f719da78cb6f7394f6d5b54f733aef5b0b447804a83edd7b"
"checksum sdl2-sys 0.32.6 (registry+https://github.com/rust-lang/crates.io-index)" = "34e71125077d297d57e4c1acfe8981b5bdfbf5a20e7b589abfdcb33bf1127f86"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4b39bd9b0b087684013a792c59e3e07a46a01d2322518d8a1104641a0b1be0"
@ -1150,15 +949,12 @@ dependencies = [
"checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6"
"checksum syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "661641ea2aa15845cddeb97dad000d22070bb5c1fb456b96c1cba883ec691e92"
"checksum synstructure 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "575be94ccb86e8da37efb894a87e2b660be299b41d8ef347f9d6d79fbe61b1ba"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
"checksum typed-arena 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8e2f9dc90da4f9d66ffc9ad3ead2c7d57582a26f4a3292d2ce7011bd29965100"
"checksum unicode-segmentation 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49f5526225fd8b77342d5986ab5f6055552e9c0776193b5b63fd53b46debfad7"
"checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20"
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
"checksum utf8parse 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8772a4ccbb4e89959023bc5b7cb8623a795caa7092d99f3aa9501b9484d4557d"
"checksum vecmath 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "956ae1e0d85bca567dee1dcf87fb1ca2e792792f66f87dced8381f99cd91156a"
"checksum vector2d 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b0ec481eac35d50b7544c58613da9f823561612b0221e67bdf04823b4c6e1358"
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"

15
godot_bind/Cargo.toml

@ -1,19 +1,16 @@
[package]
name = "sscg_gd"
version = "0.1.0"
name = "sscg_gd"
version = "0.2.0"
authors = ["weictr"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
lazy_static = "1.4.0"
palette = "0.5"
#;gdnative = { path = "../../other/godot-rust/gdnative" }
gdnative = "0.7.0"
sscg = { path = "../sscg_game" }
wlambda = { path = "../../wlambda" }
euclid = "0.20.1"
gdnative = "0.7.0"
regex = "1.3.3"
wlambda = { path = "../../wlambda" }
euclid = "0.20.1"
[lib]
crate-type = ["cdylib"]

38
godot_bind/src/gui/game_painter.rs

@ -0,0 +1,38 @@
#[derive(Debug, Clone, PartialEq, Hash, Copy)]
pub enum FontSize {
Normal,
Small,
}
pub trait GamePainter {
fn push_offs(&mut self, xo: i32, yo: i32);
fn push_add_offs(&mut self, xo: i32, yo: i32);
fn declare_cache_draw(&mut self, xo: i32, yo: i32, w: u32, h: u32, id: usize, repaint: bool);
fn done_cache_draw(&mut self);
fn pop_offs(&mut self);
fn get_screen_pos(&self, xo: i32, yo: i32) -> (i32, i32);
fn disable_clip_rect(&mut self);
fn set_clip_rect(&mut self, xo: i32, yo: i32, w: u32, h: u32);
fn draw_rect(&mut self, xo: i32, yo: i32, w: u32, h: u32,
color: (u8, u8, u8, u8));
fn draw_rect_filled(&mut self, xo: i32, yo: i32, w: u32, h: u32,
color: (u8, u8, u8, u8));
fn draw_texture(&mut self, idx: usize, xo: i32, yo: i32, w: u32, h: u32);
fn draw_dot(&mut self, xo: i32, yo: i32, r: u32, color: (u8, u8, u8, u8));
fn draw_circle(&mut self, xo: i32, yo: i32, r: u32, color: (u8, u8, u8, u8));
fn draw_line(&mut self, xo: i32, yo: i32, x2o: i32, y2o: i32, t: u32,
color: (u8, u8, u8, u8));
fn text_size(&mut self, txt: &str, fs: FontSize) -> (u32, u32);
fn texture_crop(&mut self, idx: usize, xo: i32, yo: i32, w: u32, h: u32);
fn texture(&mut self, idx: usize, xo: i32, yo: i32, centered: bool);
fn texture_size(&mut self, idx: usize) -> (u32, u32);
fn draw_text(&mut self, xo: i32, yo: i32, max_w: u32,
fg: (u8, u8, u8, u8),
bg: Option<(u8, u8, u8, u8)>,
align: i32,
txt: &str,
fs: FontSize);
}

858
godot_bind/src/gui/logic.rs

@ -0,0 +1,858 @@
use wlambda::VVal;
use std::rc::Rc;
use std::cell::RefCell;
use vector2d::Vector2D;
const TICK_RES : i32 = 1000 / 25;
pub type ObjectID = usize;
pub type EventCallback = dyn Fn(&Rc<RefCell<GameState>>, VVal);
pub fn sys2screen(v: i32) -> i32 { (v * 1280) / 10000 }
pub fn screen2sys(v: i32) -> i32 { (v * 10000) / 1280 }
#[derive(Clone)]
pub struct GameState {
pub object_registry: Rc<RefCell<ObjectRegistry>>,
pub event_router: Rc<RefCell<EventRouter>>,
pub active_ship_id: ObjectID,
pub state: VVal,
}
impl GameState {
pub fn new_ref() -> Rc<RefCell<Self>> {
Rc::new(RefCell::new(GameState {
object_registry: Rc::new(RefCell::new(ObjectRegistry::new())),
event_router: Rc::new(RefCell::new(EventRouter::new())),
state: VVal::map(),
active_ship_id: 0,
}))
}
pub fn serialize(&self) -> VVal {
let objreg = self.object_registry.borrow().serialize();
let v = VVal::vec();
v.push(VVal::new_str("sscg_savegame"));
v.push(VVal::Int(0)); // version
v.push(self.state.clone());
v.push(VVal::Int(self.active_ship_id as i64));
v.push(objreg);
return v;
}
pub fn deserialize(&mut self, v: VVal) {
self.object_registry.borrow_mut().deserialize(v.at(4).unwrap_or(VVal::Nul));
self.state = v.at(2).unwrap_or(VVal::Nul);
self.active_ship_id = v.at(3).unwrap_or(VVal::Nul).i() as ObjectID;
}
pub fn get_ship(&self, id: ObjectID) -> Option<Rc<RefCell<Ship>>> {
match self.object_registry.borrow_mut().get(id) {
Some(Object::Ship(s)) => Some(s.clone()),
_ => None,
}
}
pub fn get_system(&self, id: ObjectID) -> Option<Rc<RefCell<System>>> {
match self.object_registry.borrow_mut().get(id) {
Some(Object::System(s)) => Some(s.clone()),
_ => None,
}
}
pub fn add_system(&self, x: i32, y: i32, state: VVal) -> Rc<RefCell<System>> {
for o in self.object_registry.borrow().objects.iter() {
match o {
Object::System(s) => {
return s.clone();
},
_ => (),
}
}
let mut sys = System::new(x, y);
sys.state = state;
self.object_registry.borrow_mut().add_system(sys)
}
pub fn system_add_entity(
&self, sys: Rc<RefCell<System>>,
x: i32, y: i32, state: VVal) -> Rc<RefCell<Entity>> {
let typ =
match &state.get_key("type").unwrap_or(VVal::Nul).s_raw()[..] {
"station" => SystemObject::Station,
"asteroid_field" => SystemObject::AsteroidField,
_ => SystemObject::AsteroidField,
};
let mut ent = Entity::new(typ);
ent.state = state;
let e = self.object_registry.borrow_mut().add_entity(ent);
sys.borrow_mut().add(x, y, e.clone());
e
}
pub fn reg_cb<F>(&self, ev: String, f: F)
where F: 'static + Fn(&Rc<RefCell<GameState>>, VVal) {
self.event_router.borrow_mut().reg_cb(ev, f);
}
pub fn update(&self, frame_time_ms: f64) {
let mut os = self.object_registry.borrow_mut();
let mut er = self.event_router.borrow_mut();
os.update(frame_time_ms, &mut *er);
}
}
#[derive(Debug, Clone)]
pub enum Object {
None,
Entity(Rc<RefCell<Entity>>),
System(Rc<RefCell<System>>),
Ship(Rc<RefCell<Ship>>),
}
impl Object {
pub fn id(&self) -> ObjectID {
match self {
Object::None => 0,
Object::Entity(e) => e.borrow().id,
Object::System(s) => s.borrow().id,
Object::Ship(s) => s.borrow().id,
}
}
}
#[derive(Debug, Clone)]
pub struct ObjectRegistry {
pub objects: std::vec::Vec<Object>,
tick_count: i32,
tick_time_ms: f64,
}
impl ObjectRegistry {
pub fn new() -> Self {
ObjectRegistry {
objects: std::vec::Vec::new(),
tick_count: 0,
tick_time_ms: 0.0,
}
}
pub fn serialize(&self) -> VVal {
let v = VVal::vec();
v.push(VVal::Int(self.objects.len() as i64));
let objs = VVal::vec();
for o in self.objects.iter() {
objs.push(match o {
Object::Entity(e) => e.borrow().serialize(),
Object::System(e) => e.borrow().serialize(),
Object::Ship(e) => e.borrow().serialize(),
_ => VVal::Nul,
});
}
v.push(objs);
v
}
fn vval_to_object(&mut self, v: VVal) -> Object {
let typ : String = v.at(0).unwrap_or(VVal::Nul).s_raw();
match &typ[..] {
"ship" => Object::Ship(Rc::new(RefCell::new(Ship::deserialize(self, v)))),
"system" => Object::System(Rc::new(RefCell::new(System::deserialize(self, v)))),
_ => Object::None,
}
}
pub fn set_object_at(&mut self, idx: usize, o: Object) {
println!("SET OBJ {} = {:?}", idx, o);
self.objects[idx] = o;
}
pub fn deserialize(&mut self, s: VVal) {
self.objects = std::vec::Vec::new();
self.tick_time_ms = 0.0;
self.objects.resize(
s.at(0).unwrap_or(VVal::Int(0)).i() as usize,
Object::None);
if let VVal::Lst(m) = s.at(1).unwrap_or(VVal::Nul) {
for v in m.borrow().iter() {
let o = self.vval_to_object(v.clone());
match o {
Object::None => (),
_ => self.set_object_at(o.id(), o),
}
}
}
}
pub fn update(&mut self, dt: f64, er: &mut EventRouter) {
self.tick_time_ms += dt;
//d// println!("UPD: {} {}", dt, self.tick_time_ms);
while self.tick_time_ms > 25.0 {
self.tick(er);
self.tick_time_ms = self.tick_time_ms - 25.0;
}
}
pub fn tick(&mut self, er: &mut EventRouter) {
self.tick_count += 1;
if self.tick_count > TICK_RES {
self.tick_count = 0;
er.emit("tick".to_string(), VVal::Nul);
}
for o in self.objects.iter() {
match o {
Object::Ship(s) => s.borrow_mut().tick(er),
Object::System(s) => s.borrow_mut().tick(er),
_ => (),
}
}
}
pub fn all_entities_need_redraw(&mut self) {
for o in self.objects.iter_mut() {
match o {
Object::Entity(e) => { e.borrow_mut().does_need_redraw(); },
_ => (),
}
}
}
pub fn add_entity(&mut self, mut e: Entity) -> Rc<RefCell<Entity>> {
e.set_id(self.objects.len());
let r = Rc::new(RefCell::new(e));
self.objects.push(Object::Entity(r.clone()));
r
}
pub fn add_ship(&mut self, mut s: Ship) -> Rc<RefCell<Ship>> {
s.set_id(self.objects.len());
let r = Rc::new(RefCell::new(s));
self.objects.push(Object::Ship(r.clone()));
r
}
pub fn add_system(&mut self, mut s: System) -> Rc<RefCell<System>> {
s.set_id(self.objects.len());
let r = Rc::new(RefCell::new(s));
self.objects.push(Object::System(r.clone()));
r
}
pub fn get(&self, id: ObjectID) -> Option<Object> {
if let Some(o) = self.objects.get(id) {
match o {
Object::None => None,
Object::Entity(_) => Some(o.clone()),
Object::System(_) => Some(o.clone()),
Object::Ship(_) => Some(o.clone()),
}
} else {
None
}
}
}
pub struct EventRouter {
callbacks: std::collections::HashMap<String, std::vec::Vec<Rc<EventCallback>>>,
event_queue: std::vec::Vec<(String, VVal)>,
}
impl EventRouter {
pub fn new() -> Self {
EventRouter {
event_queue: std::vec::Vec::new(),
callbacks: std::collections::HashMap::new(),
}
}
pub fn reg_cb<F>(&mut self, ev: String, f: F)
where F: 'static + Fn(&Rc<RefCell<GameState>>, VVal) {
if let Some(cbs) = self.callbacks.get_mut(&ev) {
cbs.push(Rc::new(f));
} else {
let mut cbs : std::vec::Vec<Rc<EventCallback>> = std::vec::Vec::new();
cbs.push(Rc::new(f));
self.callbacks.insert(ev, cbs);
}
}
pub fn emit(&mut self, ev: String, args: VVal) {
if self.callbacks.get(&ev).is_none() {
let a2 = VVal::vec();
a2.push(VVal::new_str_mv(ev));
a2.push(args);
self.event_queue.push(("*".to_string(), a2));
} else {
self.event_queue.push((ev, args));
}
}
pub fn get_events(&mut self, vec: &mut Vec<(Rc<EventCallback>, VVal)>) {
while !self.event_queue.is_empty() {
let ev = self.event_queue.pop().unwrap();
if let Some(cbs) = self.callbacks.get_mut(&ev.0) {
for c in cbs.iter() {
vec.push((c.clone(), ev.1.clone()));
}
}
}
}
}
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum SystemObject {
Station,
AsteroidField,
}
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct Course {
pub from: (i32, i32),
pub to: (i32, i32),
}
impl Course {
pub fn new(x_from: i32, y_from: i32, x_to: i32, y_to: i32) -> Self {
Course {
from: (x_from, y_from),
to: (x_to, y_to),
}
}
pub fn rotation_quadrant(&self) -> i32 {
let v = Vector2D::new(
(self.to.0 - self.from.0) as f32,
(self.to.1 - self.from.1) as f32).normalise();
let ang = v.angle();
let ang = if ang < 0.0 { ang + 2.0 * std::f32::consts::PI } else { ang };
let a = ang / (2.0 * std::f32::consts::PI);
(a * 8.0).round() as i32
}
pub fn interpolate(&self, v: f64) -> (i32, i32) {
let xd = ((self.to.0 as f64 * v) + (self.from.0 as f64 * (1.0 - v))) as i32;
let yd = ((self.to.1 as f64 * v) + (self.from.1 as f64 * (1.0 - v))) as i32;
(xd, yd)
}
pub fn distance(&self) -> i32 {
(( (self.from.0 - self.to.0).pow(2)
+ (self.from.1 - self.to.1).pow(2)) as f64).sqrt() as i32
}
}
// 10 ticks == 1 second
#[derive(Debug, Clone)]
pub struct Ship {
pub id: ObjectID,
pub system: ObjectID,
pub name: String,
pub notify_txt: String,
pub pos: (i32, i32),
pub speed_t: i32, // 100:1 => speed_t * 10 is speed per second
pub state: VVal,
course_progress: i32, // 100:1
course: Option<Course>,
tick_count: i32,
}
impl Ship {
pub fn new(name: String) -> Self {
Ship {
name,
course_progress: 0,
speed_t: 1000,
course: None,
pos: (0, 0),
system: 0,
id: 0,
state: VVal::map(),
tick_count: 0,
notify_txt: String::from(""),
}
}
pub fn deserialize(_or: &mut ObjectRegistry, v: VVal) -> Self {
let mut s = Self::new("".to_string());
s.id = v.at(2).unwrap_or(VVal::Int(0)).i() as ObjectID;
s.system = v.at(3).unwrap_or(VVal::Int(0)).i() as ObjectID;
s.name = v.at(4).unwrap_or(VVal::new_str("")).s_raw();
s.pos.0 = v.at(5).unwrap_or(VVal::Int(0)).i() as i32;
s.pos.1 = v.at(6).unwrap_or(VVal::Int(0)).i() as i32;
s.speed_t = v.at(7).unwrap_or(VVal::Int(0)).i() as i32;
s.course_progress = v.at(8).unwrap_or(VVal::Int(0)).i() as i32;
if let Some(VVal::Lst(l)) = v.at(9) {
let mut c = Course::new(0, 0, 0, 0);
c.from.0 = l.borrow().get(0).unwrap().i() as i32;
c.from.1 = l.borrow().get(1).unwrap().i() as i32;
c.to.0 = l.borrow().get(2).unwrap().i() as i32;
c.to.1 = l.borrow().get(3).unwrap().i() as i32;
s.course = Some(c);
} else {
s.course = None;
}
s.tick_count = v.at(10).unwrap_or(VVal::Int(0)).i() as i32;
s.state = v.at(11).unwrap_or(VVal::Nul);
s
}
pub fn serialize(&self) -> VVal {
let v = VVal::vec();
v.push(VVal::new_str("ship"));
v.push(VVal::Int(0)); // version
v.push(VVal::Int(self.id as i64));
v.push(VVal::Int(self.system as i64));
v.push(VVal::new_str(&self.name));
v.push(VVal::Int(self.pos.0 as i64));
v.push(VVal::Int(self.pos.1 as i64));
v.push(VVal::Int(self.speed_t as i64));
v.push(VVal::Int(self.course_progress as i64));
if let Some(c) = self.course {
let cv = VVal::vec();
cv.push(VVal::Int(c.from.0 as i64));
cv.push(VVal::Int(c.from.1 as i64));
cv.push(VVal::Int(c.to.0 as i64));
cv.push(VVal::Int(c.to.1 as i64));
v.push(cv);
} else {
v.push(VVal::Nul);
}
v.push(VVal::Int(self.tick_count as i64));
v.push(self.state.clone());
v
}
pub fn set_id(&mut self, id: ObjectID) { self.id = id; }
pub fn set_system(&mut self, sys_id: ObjectID) { self.system = sys_id; }
pub fn set_notification(&mut self, not: String) { self.notify_txt = not; }
pub fn set_course_to(&mut self, x: i32, y: i32) {
self.course = Some(Course::new(self.pos.0, self.pos.1, x, y));
self.course_progress = 0;
}
pub fn tick(&mut self, er: &mut EventRouter) {
let mut tick_now = false;
if let Some(_) = self.course {
let started = self.course_progress == 0;
self.course_progress += self.speed_t;
let d = self.course.unwrap().distance() * 100;
if self.course_progress >= d {
self.pos = self.course.unwrap().to;
self.course = None;
self.state.set_map_key(
"_state".to_string(), VVal::new_str("arrived"));
tick_now = true;
} else {
if started {
tick_now = true;
self.state.set_map_key(
"_state".to_string(), VVal::new_str("started"));
} else {
self.state.set_map_key(
"_state".to_string(), VVal::new_str("flying"));
}
self.pos = self.course.unwrap().interpolate(
self.course_progress as f64 / d as f64);
}
// println!("SHIP: pos={:?} dis={} cp={}", self.pos, d, self.course_progress);
} else {
self.state.set_map_key(
"_state".to_string(), VVal::new_str("stopped"));
}
self.tick_count += 1;
if self.tick_count > TICK_RES {
self.tick_count = 0;
tick_now = true;
}
if tick_now {
er.emit("ship_tick".to_string(),
VVal::Int(self.id as i64));
}
}
pub fn draw<P>(&mut self, p: &mut P) where P: GamePainter {
let x = sys2screen(self.pos.0);
let y = sys2screen(self.pos.1);
let a =
if let Some(c) = self.course {
c.rotation_quadrant()
} else {
1
};
if let Some(c) = self.course {
p.draw_line(
x, y, sys2screen(c.to.0), sys2screen(c.to.1),
1, (190, 190, 190, 255));
}
p.texture(3 + ((8 - a) as usize + 3) % 8, x, y, true);
if self.notify_txt.len() > 0 {
p.draw_text(
x - 100, y + 10, 200,
(255, 0, 255, 255), None,
0, &self.notify_txt, FontSize::Normal);
}
}
}
#[derive(Debug, Clone)]
pub struct Entity {
pub id: ObjectID,
pub typ: SystemObject,
pub x: i32,
pub y: i32,
pub state: VVal,
pub name: String,
draw_pos: (i32, i32),
is_highlighted: bool,
redraw: bool,
}
impl Entity {
pub fn new(typ: SystemObject) -> Self {
Entity {
typ,
id: 0,
draw_pos: (0, 0),
x: 0,
y: 0,
state: VVal::map(),
is_highlighted: false,
redraw: true,
name: String::from(""),
}
}
pub fn does_need_redraw(&mut self) { self.redraw = true; }
pub fn deserialize(_or: &mut ObjectRegistry, v: VVal) -> Self {
let mut s = Self::new(SystemObject::Station);
s.id = v.at(2).unwrap_or(VVal::Int(0)).i() as ObjectID;
s.typ = match v.at(3).unwrap_or(VVal::Int(0)).i() {
0 => SystemObject::Station,
1 => SystemObject::AsteroidField,
_ => SystemObject::Station,
};
s.x = v.at(4).unwrap_or(VVal::Int(0)).i() as i32;
s.y = v.at(5).unwrap_or(VVal::Int(0)).i() as i32;
s.name = v.at(6).unwrap_or(VVal::new_str("")).s_raw();
s.state = v.at(7).unwrap_or(VVal::Nul);
s
}
pub fn serialize(&self) -> VVal {
let v = VVal::vec();
v.push(VVal::new_str("entity"));
v.push(VVal::Int(0)); // version
v.push(VVal::Int(self.id as i64));
v.push(VVal::Int(self.typ as i64));
v.push(VVal::Int(self.x as i64));
v.push(VVal::Int(self.y as i64));
v.push(VVal::new_str(&self.name));
v.push(self.state.clone());
v
}
pub fn set_id(&mut self, id: ObjectID) { self.id = id; }
fn draw<P>(&mut self, p: &mut P) where P: GamePainter {
let t_id =
match self.typ {
SystemObject::Station => 2,
SystemObject::AsteroidField => 0,
};
let q = p.texture_size(t_id);
// TODO: Offset rendering completely for fitting text.
let tw : i32 = (q.0 / 2) as i32;
p.declare_cache_draw(-tw, -tw, 256, 156, self.id as usize, self.redraw);
if self.redraw {
self.redraw = false;
p.texture(t_id, 0, 0, false);
p.draw_text(1, tw + (tw / 2) + 20 + 2, 2 * tw as u32, (0, 0, 0, 255), None, 0, &self.name, FontSize::Normal);
p.draw_text(0, tw + (tw / 2) + 20, 2 * tw as u32, (255, 255, 255, 255), None, 0, &self.name, FontSize::Normal);
if self.is_highlighted {
p.draw_circle(tw, tw, 30, (255, 0, 0, 255));
}
}
p.done_cache_draw();
self.draw_pos = p.get_screen_pos(0, 0);
}
fn set_highlight(&mut self, h: bool) {
if self.is_highlighted != h {
// TODO: FIXME: The entity is redrawn all the time, because
// try_highlight_entity_close_to does set all highlights
// to `false` before checking which entity is highlighted.
self.redraw = true;
}
self.is_highlighted = h;
}
}
#[derive(Debug, Clone, Copy)]
pub struct MouseScreenSystemPos {
screen_x0: i32,
screen_x1: i32,
screen_y0: i32,
screen_y1: i32,
system_x0: i32,
system_x1: i32,
system_y0: i32,
system_y1: i32,
}
impl MouseScreenSystemPos {
pub fn new() -> Self {
Self {
screen_x0: 0,
screen_x1: 0,
screen_y0: 0,
screen_y1: 0,
system_x0: 0,
system_x1: 0,
system_y0: 0,
system_y1: 0,
}
}
pub fn mouse2system(&self, x: i32, y: i32) -> Option<(i32, i32)> {
if !( x >= self.screen_x0
&& x <= self.screen_x1
&& y >= self.screen_y0
&& y <= self.screen_y1) {
return None;
}
println!("CLICK {}:{} => {:?}", x, y, self);
let scr_w = self.screen_x1 - self.screen_x0;
let scr_h = self.screen_y1 - self.screen_y0;
let sys_w = self.system_x1 - self.system_x0;
let sys_h = self.system_y1 - self.system_y0;
if scr_w == 0 { return None; }
if scr_h == 0 { return None; }
let xsys = self.system_x0 + ((x - self.screen_x0) * sys_w) / scr_w;
let ysys = self.system_y0 + ((y - self.screen_y0) * sys_h) / scr_h;
Some((xsys, ysys))
}
}
#[derive(Debug, Clone)]
pub struct System {
pub id: ObjectID,
pub x: i32,
pub y: i32,
pub state: VVal,
objects: std::vec::Vec<Rc<RefCell<Entity>>>,
tick_count: i32,
}
impl System {
pub fn new(x: i32, y: i32) -> Self {
System {
id: 0,
x,
y,
objects: std::vec::Vec::new(),
tick_count: 0,
state: VVal::map()
}
}
pub fn deserialize(or: &mut ObjectRegistry, v: VVal) -> Self {
let mut s = Self::new(0, 0);
s.id = v.at(2).unwrap_or(VVal::Int(0)).i() as ObjectID;
s.x = v.at(3).unwrap_or(VVal::Int(0)).i() as i32;
s.y = v.at(4).unwrap_or(VVal::Int(0)).i() as i32;
s.tick_count = v.at(5).unwrap_or(VVal::Int(0)).i() as i32;