You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
22 KiB
138 lines
22 KiB
<html>
|
|
<head>
|
|
<title>state.rs</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<style type="text/css">
|
|
.s0 { color: #ed864a;}
|
|
.s1 { color: #ebebeb;}
|
|
.s2 { color: #ffffff;}
|
|
.s3 { color: #ed864a; font-weight: bold;}
|
|
.s4 { color: #54b33e;}
|
|
.s5 { color: #7ec3e6;}
|
|
.ln { color: #999999; font-weight: normal; font-style: normal; }
|
|
</style>
|
|
</head>
|
|
<body bgcolor="#131314">
|
|
<table CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#606060" >
|
|
<tr><td><center>
|
|
<font face="Arial, Helvetica" color="#000000">
|
|
state.rs</font>
|
|
</center></td></tr></table>
|
|
<pre><a name="l1"><span class="ln">1 </span></a><span class="s0">use </span><span class="s2">std</span><span class="s1">::</span><span class="s2">collections</span><span class="s1">::</span><span class="s2">HashMap</span><span class="s3">;</span>
|
|
<a name="l2"><span class="ln">2 </span></a><span class="s0">use </span><span class="s2">std</span><span class="s1">::</span><span class="s2">fs</span><span class="s3">;</span>
|
|
<a name="l3"><span class="ln">3 </span></a><span class="s0">use </span><span class="s2">std</span><span class="s1">::</span><span class="s2">path</span><span class="s1">::</span><span class="s2">PathBuf</span><span class="s3">;</span>
|
|
<a name="l4"><span class="ln">4 </span></a><span class="s0">use </span><span class="s2">std</span><span class="s1">::</span><span class="s2">time</span><span class="s1">::</span><span class="s2">Instant</span><span class="s3">;</span>
|
|
<a name="l5"><span class="ln">5 </span></a><span class="s0">use </span><span class="s2">serde_derive</span><span class="s1">::</span><span class="s2">Deserialize</span><span class="s3">;</span>
|
|
<a name="l6"><span class="ln">6 </span></a>
|
|
<a name="l7"><span class="ln">7 </span></a><span class="s0">use </span><span class="s2">cgmath</span><span class="s1">::{</span><span class="s2">Euler</span><span class="s3">, </span><span class="s2">Quaternion</span><span class="s3">, </span><span class="s2">Deg</span><span class="s1">}</span><span class="s3">;</span>
|
|
<a name="l8"><span class="ln">8 </span></a><span class="s0">use </span><span class="s2">legion</span><span class="s1">::</span><span class="s2">world</span><span class="s1">::</span><span class="s2">SubWorld</span><span class="s3">;</span>
|
|
<a name="l9"><span class="ln">9 </span></a><span class="s0">use </span><span class="s2">legion</span><span class="s1">::</span><span class="s2">IntoQuery</span><span class="s3">;</span>
|
|
<a name="l10"><span class="ln">10 </span></a><span class="s0">use </span><span class="s2">legion</span><span class="s1">::*</span><span class="s3">;</span>
|
|
<a name="l11"><span class="ln">11 </span></a><span class="s0">use </span><span class="s2">nalgebra</span><span class="s1">::</span><span class="s2">Quaternion </span><span class="s0">as </span><span class="s2">naQuaternion</span><span class="s3">;</span>
|
|
<a name="l12"><span class="ln">12 </span></a><span class="s0">use </span><span class="s2">rapier3d</span><span class="s1">::</span><span class="s2">dynamics</span><span class="s1">::{</span><span class="s2">IntegrationParameters</span><span class="s3">, </span><span class="s2">JointSet</span><span class="s3">, </span><span class="s2">RigidBodySet</span><span class="s1">}</span><span class="s3">;</span>
|
|
<a name="l13"><span class="ln">13 </span></a><span class="s0">use </span><span class="s2">rapier3d</span><span class="s1">::</span><span class="s2">geometry</span><span class="s1">::{</span><span class="s2">BroadPhase</span><span class="s3">, </span><span class="s2">ColliderSet</span><span class="s3">, </span><span class="s2">NarrowPhase</span><span class="s1">}</span><span class="s3">;</span>
|
|
<a name="l14"><span class="ln">14 </span></a><span class="s0">use </span><span class="s2">rapier3d</span><span class="s1">::</span><span class="s2">pipeline</span><span class="s1">::</span><span class="s2">PhysicsPipeline</span><span class="s3">;</span>
|
|
<a name="l15"><span class="ln">15 </span></a><span class="s0">use crate</span><span class="s1">::</span><span class="s2">camera</span><span class="s1">::{</span><span class="s2">Camera</span><span class="s3">, </span><span class="s2">CameraController</span><span class="s1">}</span><span class="s3">;</span>
|
|
<a name="l16"><span class="ln">16 </span></a><span class="s0">use crate</span><span class="s1">::</span><span class="s2">components</span><span class="s1">::{</span><span class="s2">Collider</span><span class="s3">, </span><span class="s2">LoopState</span><span class="s3">, </span><span class="s2">Mesh</span><span class="s3">, </span><span class="s2">Physics</span><span class="s3">, </span><span class="s2">Position</span><span class="s1">}</span><span class="s3">;</span>
|
|
<a name="l17"><span class="ln">17 </span></a><span class="s0">use crate</span><span class="s1">::</span><span class="s2">geometry</span><span class="s1">::{</span><span class="s2">load_obj</span><span class="s3">, </span><span class="s2">RawMesh</span><span class="s1">}</span><span class="s3">;</span>
|
|
<a name="l18"><span class="ln">18 </span></a><span class="s0">use </span><span class="s2">std</span><span class="s1">::</span><span class="s2">io</span><span class="s1">::</span><span class="s2">Read</span><span class="s3">;</span>
|
|
<a name="l19"><span class="ln">19 </span></a>
|
|
<a name="l20"><span class="ln">20 </span></a>
|
|
<a name="l21"><span class="ln">21 </span></a>
|
|
<a name="l22"><span class="ln">22 </span></a><span class="s1">#[</span><span class="s2">derive</span><span class="s1">(</span><span class="s2">Deserialize</span><span class="s3">, </span><span class="s2">Clone</span><span class="s1">)]</span>
|
|
<a name="l23"><span class="ln">23 </span></a><span class="s0">pub struct </span><span class="s2">TomlBallPhysicsBodyDescription </span><span class="s1">{</span>
|
|
<a name="l24"><span class="ln">24 </span></a> <span class="s0">pub </span><span class="s2">radius</span><span class="s1">: </span><span class="s2">String</span>
|
|
<a name="l25"><span class="ln">25 </span></a><span class="s1">}</span>
|
|
<a name="l26"><span class="ln">26 </span></a>
|
|
<a name="l27"><span class="ln">27 </span></a><span class="s1">#[</span><span class="s2">derive</span><span class="s1">(</span><span class="s2">Deserialize</span><span class="s3">, </span><span class="s2">Clone</span><span class="s1">)]</span>
|
|
<a name="l28"><span class="ln">28 </span></a><span class="s0">pub struct </span><span class="s2">TomlCuboidPhysicsBodyDescription </span><span class="s1">{</span>
|
|
<a name="l29"><span class="ln">29 </span></a> <span class="s0">pub </span><span class="s2">x</span><span class="s1">: </span><span class="s2">f32</span><span class="s3">,</span>
|
|
<a name="l30"><span class="ln">30 </span></a> <span class="s0">pub </span><span class="s2">y</span><span class="s1">: </span><span class="s2">f32</span><span class="s3">,</span>
|
|
<a name="l31"><span class="ln">31 </span></a> <span class="s0">pub </span><span class="s2">z</span><span class="s1">: </span><span class="s2">f32</span><span class="s3">,</span>
|
|
<a name="l32"><span class="ln">32 </span></a><span class="s1">}</span>
|
|
<a name="l33"><span class="ln">33 </span></a>
|
|
<a name="l34"><span class="ln">34 </span></a><span class="s1">#[</span><span class="s2">derive</span><span class="s1">(</span><span class="s2">Deserialize</span><span class="s3">, </span><span class="s2">Clone</span><span class="s1">)]</span>
|
|
<a name="l35"><span class="ln">35 </span></a><span class="s0">pub struct </span><span class="s2">TomlPhysicsDescription </span><span class="s1">{</span>
|
|
<a name="l36"><span class="ln">36 </span></a> <span class="s0">pub </span><span class="s2">body_status</span><span class="s1">: </span><span class="s2">String</span><span class="s3">,</span>
|
|
<a name="l37"><span class="ln">37 </span></a> <span class="s0">pub </span><span class="s2">ball</span><span class="s1">: </span><span class="s2">Option</span><span class="s1"><</span><span class="s2">TomlBallPhysicsBodyDescription</span><span class="s1">></span><span class="s3">,</span>
|
|
<a name="l38"><span class="ln">38 </span></a> <span class="s0">pub </span><span class="s2">cuboid</span><span class="s1">: </span><span class="s2">Option</span><span class="s1"><</span><span class="s2">TomlCuboidPhysicsBodyDescription</span><span class="s1">></span><span class="s3">,</span>
|
|
<a name="l39"><span class="ln">39 </span></a><span class="s1">}</span>
|
|
<a name="l40"><span class="ln">40 </span></a>
|
|
<a name="l41"><span class="ln">41 </span></a><span class="s1">#[</span><span class="s2">derive</span><span class="s1">(</span><span class="s2">Deserialize</span><span class="s3">, </span><span class="s2">Clone</span><span class="s1">)]</span>
|
|
<a name="l42"><span class="ln">42 </span></a><span class="s0">pub struct </span><span class="s2">TomlRotationDescription </span><span class="s1">{</span>
|
|
<a name="l43"><span class="ln">43 </span></a> <span class="s0">pub </span><span class="s2">x</span><span class="s1">: </span><span class="s2">f32</span><span class="s3">,</span>
|
|
<a name="l44"><span class="ln">44 </span></a> <span class="s0">pub </span><span class="s2">y</span><span class="s1">: </span><span class="s2">f32</span><span class="s3">,</span>
|
|
<a name="l45"><span class="ln">45 </span></a> <span class="s0">pub </span><span class="s2">z</span><span class="s1">: </span><span class="s2">f32</span><span class="s3">,</span>
|
|
<a name="l46"><span class="ln">46 </span></a><span class="s1">}</span>
|
|
<a name="l47"><span class="ln">47 </span></a>
|
|
<a name="l48"><span class="ln">48 </span></a><span class="s1">#[</span><span class="s2">derive</span><span class="s1">(</span><span class="s2">Deserialize</span><span class="s3">, </span><span class="s2">Clone</span><span class="s1">)]</span>
|
|
<a name="l49"><span class="ln">49 </span></a><span class="s0">pub struct </span><span class="s2">TomlPositionDescription </span><span class="s1">{</span>
|
|
<a name="l50"><span class="ln">50 </span></a> <span class="s0">pub </span><span class="s2">x</span><span class="s1">: </span><span class="s2">f32</span><span class="s3">,</span>
|
|
<a name="l51"><span class="ln">51 </span></a> <span class="s0">pub </span><span class="s2">y</span><span class="s1">: </span><span class="s2">f32</span><span class="s3">,</span>
|
|
<a name="l52"><span class="ln">52 </span></a> <span class="s0">pub </span><span class="s2">z</span><span class="s1">: </span><span class="s2">f32</span><span class="s3">,</span>
|
|
<a name="l53"><span class="ln">53 </span></a> <span class="s0">pub </span><span class="s2">rot</span><span class="s1">: </span><span class="s2">Option</span><span class="s1"><</span><span class="s2">TomlRotationDescription</span><span class="s1">></span><span class="s3">,</span>
|
|
<a name="l54"><span class="ln">54 </span></a><span class="s1">}</span>
|
|
<a name="l55"><span class="ln">55 </span></a>
|
|
<a name="l56"><span class="ln">56 </span></a><span class="s1">#[</span><span class="s2">derive</span><span class="s1">(</span><span class="s2">Deserialize</span><span class="s3">, </span><span class="s2">Clone</span><span class="s1">)]</span>
|
|
<a name="l57"><span class="ln">57 </span></a><span class="s0">pub struct </span><span class="s2">TomlEntityDescription </span><span class="s1">{</span>
|
|
<a name="l58"><span class="ln">58 </span></a> <span class="s0">pub </span><span class="s2">name</span><span class="s1">: </span><span class="s2">String</span><span class="s3">,</span>
|
|
<a name="l59"><span class="ln">59 </span></a> <span class="s1">#[</span><span class="s2">serde</span><span class="s1">(</span><span class="s2">rename </span><span class="s1">= </span><span class="s4">"type"</span><span class="s1">)]</span>
|
|
<a name="l60"><span class="ln">60 </span></a> <span class="s0">pub </span><span class="s2">type_name</span><span class="s1">: </span><span class="s2">String</span><span class="s3">,</span>
|
|
<a name="l61"><span class="ln">61 </span></a> <span class="s0">pub </span><span class="s2">mesh</span><span class="s1">: </span><span class="s2">Option</span><span class="s1"><</span><span class="s2">String</span><span class="s1">></span><span class="s3">,</span>
|
|
<a name="l62"><span class="ln">62 </span></a> <span class="s0">pub </span><span class="s2">position</span><span class="s1">: </span><span class="s2">Option</span><span class="s1"><</span><span class="s2">TomlPositionDescription</span><span class="s1">></span><span class="s3">,</span>
|
|
<a name="l63"><span class="ln">63 </span></a> <span class="s0">pub </span><span class="s2">physics</span><span class="s1">: </span><span class="s2">Option</span><span class="s1"><</span><span class="s2">TomlPhysicsDescription</span><span class="s1">></span><span class="s3">,</span>
|
|
<a name="l64"><span class="ln">64 </span></a><span class="s1">}</span>
|
|
<a name="l65"><span class="ln">65 </span></a>
|
|
<a name="l66"><span class="ln">66 </span></a><span class="s1">#[</span><span class="s2">derive</span><span class="s1">(</span><span class="s2">Deserialize</span><span class="s3">, </span><span class="s2">Clone</span><span class="s1">)]</span>
|
|
<a name="l67"><span class="ln">67 </span></a><span class="s0">pub struct </span><span class="s2">TomlEntityContainer </span><span class="s1">{</span>
|
|
<a name="l68"><span class="ln">68 </span></a> <span class="s0">pub </span><span class="s2">entities</span><span class="s1">: </span><span class="s2">Vec</span><span class="s1"><</span><span class="s2">TomlEntityDescription</span><span class="s1">></span><span class="s3">,</span>
|
|
<a name="l69"><span class="ln">69 </span></a><span class="s1">}</span>
|
|
<a name="l70"><span class="ln">70 </span></a>
|
|
<a name="l71"><span class="ln">71 </span></a><span class="s0">pub struct </span><span class="s2">RuntimeState </span><span class="s1">{</span>
|
|
<a name="l72"><span class="ln">72 </span></a> <span class="s2">config_db</span><span class="s1">: </span><span class="s2">TomlEntityContainer</span><span class="s3">,</span>
|
|
<a name="l73"><span class="ln">73 </span></a> <span class="s2">mesh_cache</span><span class="s1">: </span><span class="s2">HashMap</span><span class="s1"><</span><span class="s2">String</span><span class="s3">, </span><span class="s2">RawMesh</span><span class="s1">></span><span class="s3">,</span>
|
|
<a name="l74"><span class="ln">74 </span></a><span class="s1">}</span>
|
|
<a name="l75"><span class="ln">75 </span></a>
|
|
<a name="l76"><span class="ln">76 </span></a><span class="s0">impl </span><span class="s2">RuntimeState </span><span class="s1">{</span>
|
|
<a name="l77"><span class="ln">77 </span></a> <span class="s0">pub fn </span><span class="s2">new</span><span class="s1">() -> </span><span class="s2">RuntimeState </span><span class="s1">{</span>
|
|
<a name="l78"><span class="ln">78 </span></a> <span class="s5">// TODO: Hook this file to the gui</span>
|
|
<a name="l79"><span class="ln">79 </span></a> <span class="s0">let mut </span><span class="s2">file </span><span class="s1">= </span><span class="s2">fs</span><span class="s1">::</span><span class="s2">File</span><span class="s1">::</span><span class="s2">open</span><span class="s1">(</span><span class="s4">"./conf/entity_spawns.toml"</span><span class="s1">).</span><span class="s2">unwrap</span><span class="s1">()</span><span class="s3">;</span>
|
|
<a name="l80"><span class="ln">80 </span></a> <span class="s0">let mut </span><span class="s2">content </span><span class="s1">= </span><span class="s2">String</span><span class="s1">::</span><span class="s2">new</span><span class="s1">()</span><span class="s3">;</span>
|
|
<a name="l81"><span class="ln">81 </span></a> <span class="s2">file</span><span class="s1">.</span><span class="s2">read_to_string</span><span class="s1">(&</span><span class="s0">mut </span><span class="s2">content</span><span class="s1">).</span><span class="s2">unwrap</span><span class="s1">()</span><span class="s3">;</span>
|
|
<a name="l82"><span class="ln">82 </span></a>
|
|
<a name="l83"><span class="ln">83 </span></a> <span class="s5">// TODO: gracefully fail</span>
|
|
<a name="l84"><span class="ln">84 </span></a> <span class="s0">let mut </span><span class="s2">settings </span><span class="s1">: </span><span class="s2">TomlEntityContainer </span><span class="s1">= </span><span class="s2">toml</span><span class="s1">::</span><span class="s2">from_str</span><span class="s1">(</span><span class="s2">content</span><span class="s1">.</span><span class="s2">as_str</span><span class="s1">()).</span><span class="s2">unwrap</span><span class="s1">()</span><span class="s3">;</span>
|
|
<a name="l85"><span class="ln">85 </span></a>
|
|
<a name="l86"><span class="ln">86 </span></a> <span class="s2">RuntimeState </span><span class="s1">{</span>
|
|
<a name="l87"><span class="ln">87 </span></a> <span class="s2">config_db</span><span class="s1">: </span><span class="s2">settings</span><span class="s3">,</span>
|
|
<a name="l88"><span class="ln">88 </span></a> <span class="s2">mesh_cache</span><span class="s1">: </span><span class="s2">Default</span><span class="s1">::</span><span class="s2">default</span><span class="s1">()</span><span class="s3">,</span>
|
|
<a name="l89"><span class="ln">89 </span></a> <span class="s1">}</span>
|
|
<a name="l90"><span class="ln">90 </span></a> <span class="s1">}</span>
|
|
<a name="l91"><span class="ln">91 </span></a>
|
|
<a name="l92"><span class="ln">92 </span></a> <span class="s0">pub fn </span><span class="s2">get_mesh</span><span class="s1">(&</span><span class="s0">mut self</span><span class="s3">, </span><span class="s2">mesh</span><span class="s1">: &</span><span class="s2">str</span><span class="s1">) -> </span><span class="s2">Option</span><span class="s1"><&</span><span class="s2">RawMesh</span><span class="s1">> {</span>
|
|
<a name="l93"><span class="ln">93 </span></a> <span class="s0">self</span><span class="s1">.</span><span class="s2">mesh_cache</span><span class="s1">.</span><span class="s2">get</span><span class="s1">(</span><span class="s2">mesh</span><span class="s1">)</span>
|
|
<a name="l94"><span class="ln">94 </span></a> <span class="s1">}</span>
|
|
<a name="l95"><span class="ln">95 </span></a>
|
|
<a name="l96"><span class="ln">96 </span></a> <span class="s0">pub fn </span><span class="s2">get_entities</span><span class="s1">(&</span><span class="s0">mut self</span><span class="s1">) -> </span><span class="s2">Vec</span><span class="s1"><</span><span class="s2">TomlEntityDescription</span><span class="s1">> {</span>
|
|
<a name="l97"><span class="ln">97 </span></a> <span class="s0">self</span><span class="s1">.</span><span class="s2">config_db</span><span class="s1">.</span><span class="s2">entities</span><span class="s1">.</span><span class="s2">clone</span><span class="s1">()</span>
|
|
<a name="l98"><span class="ln">98 </span></a> <span class="s1">}</span>
|
|
<a name="l99"><span class="ln">99 </span></a>
|
|
<a name="l100"><span class="ln">100 </span></a> <span class="s0">pub fn </span><span class="s2">preload_meshes</span><span class="s1">(&</span><span class="s0">mut self</span><span class="s3">, </span><span class="s2">resources_path</span><span class="s1">: </span><span class="s2">PathBuf</span><span class="s1">) {</span>
|
|
<a name="l101"><span class="ln">101 </span></a> <span class="s2">log</span><span class="s1">::</span><span class="s2">info</span><span class="s1">!(</span><span class="s4">"Preloading meshes..."</span><span class="s1">)</span><span class="s3">;</span>
|
|
<a name="l102"><span class="ln">102 </span></a>
|
|
<a name="l103"><span class="ln">103 </span></a> <span class="s0">let </span><span class="s2">paths </span><span class="s1">= </span><span class="s2">fs</span><span class="s1">::</span><span class="s2">read_dir</span><span class="s1">(</span><span class="s2">resources_path</span><span class="s1">).</span><span class="s2">unwrap</span><span class="s1">()</span><span class="s3">;</span>
|
|
<a name="l104"><span class="ln">104 </span></a> <span class="s0">for </span><span class="s2">file </span><span class="s0">in </span><span class="s2">paths </span><span class="s1">{</span>
|
|
<a name="l105"><span class="ln">105 </span></a> <span class="s0">let </span><span class="s2">file </span><span class="s1">= </span><span class="s2">file</span><span class="s1">.</span><span class="s2">unwrap</span><span class="s1">()</span><span class="s3">;</span>
|
|
<a name="l106"><span class="ln">106 </span></a> <span class="s0">let </span><span class="s2">filepath </span><span class="s1">= </span><span class="s2">file</span><span class="s1">.</span><span class="s2">path</span><span class="s1">().</span><span class="s2">clone</span><span class="s1">()</span><span class="s3">;</span>
|
|
<a name="l107"><span class="ln">107 </span></a> <span class="s0">let </span><span class="s2">filename </span><span class="s1">= </span><span class="s2">String</span><span class="s1">::</span><span class="s2">from</span><span class="s1">(</span><span class="s2">file</span><span class="s1">.</span><span class="s2">file_name</span><span class="s1">().</span><span class="s2">to_str</span><span class="s1">().</span><span class="s2">unwrap</span><span class="s1">())</span><span class="s3">;</span>
|
|
<a name="l108"><span class="ln">108 </span></a>
|
|
<a name="l109"><span class="ln">109 </span></a> <span class="s0">if </span><span class="s2">filename</span><span class="s1">.</span><span class="s2">ends_with</span><span class="s1">(</span><span class="s4">".obj"</span><span class="s1">) {</span>
|
|
<a name="l110"><span class="ln">110 </span></a> <span class="s0">let </span><span class="s2">mesh </span><span class="s1">= </span><span class="s2">load_obj</span><span class="s1">(</span><span class="s2">filepath</span><span class="s1">.</span><span class="s2">to_str</span><span class="s1">().</span><span class="s2">unwrap</span><span class="s1">()).</span><span class="s2">unwrap</span><span class="s1">()</span><span class="s3">;</span>
|
|
<a name="l111"><span class="ln">111 </span></a> <span class="s0">self</span><span class="s1">.</span><span class="s2">mesh_cache</span><span class="s1">.</span><span class="s2">insert</span><span class="s1">(</span><span class="s2">filename</span><span class="s3">, </span><span class="s2">mesh</span><span class="s1">)</span><span class="s3">;</span>
|
|
<a name="l112"><span class="ln">112 </span></a> <span class="s1">}</span>
|
|
<a name="l113"><span class="ln">113 </span></a> <span class="s1">}</span>
|
|
<a name="l114"><span class="ln">114 </span></a> <span class="s1">}</span>
|
|
<a name="l115"><span class="ln">115 </span></a><span class="s1">}</span>
|
|
<a name="l116"><span class="ln">116 </span></a></pre>
|
|
</body>
|
|
</html> |