templeos-info/public/Wb/Apps/Span/SpanNew.HC.HTML

158 lines
12 KiB
Plaintext
Raw Normal View History

2024-03-24 21:24:44 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="generator" content="TempleOS V5.03">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="/style/templeos.css">
<script src="/script/templeos.js"></script>
<style type="text/css">
.cF0{color:#000000;background-color:#ffffff;}
.cF1{color:#0000aa;background-color:#ffffff;}
.cF2{color:#00aa00;background-color:#ffffff;}
.cF3{color:#00aaaa;background-color:#ffffff;}
.cF4{color:#aa0000;background-color:#ffffff;}
.cF5{color:#aa00aa;background-color:#ffffff;}
.cF6{color:#aa5500;background-color:#ffffff;}
.cF7{color:#aaaaaa;background-color:#ffffff;}
.cF8{color:#555555;background-color:#ffffff;}
.cF9{color:#5555ff;background-color:#ffffff;}
.cFA{color:#55ff55;background-color:#ffffff;}
.cFB{color:#55ffff;background-color:#ffffff;}
.cFC{color:#ff5555;background-color:#ffffff;}
.cFD{color:#ff55ff;background-color:#ffffff;}
.cFE{color:#ffff55;background-color:#ffffff;}
.cFF{color:#ffffff;background-color:#ffffff;}
</style>
</head>
<body>
<pre id="content">
<a name="l1"></a><span class=cF9>CMathODE</span><span class=cF0> *SpanNew()
<a name="l2"></a>{
<a name="l3"></a> </span><span class=cF9>CMathODE</span><span class=cF0> *ode=</span><span class=cF5>ODENew</span><span class=cF0>(0,1e-4,</span><span class=cF3>ODEF_HAS_MASSES</span><span class=cF0>|</span><span class=cF3>ODEF_PAUSED</span><span class=cF0>);
<a name="l4"></a> ode-&gt;derive=&amp;MyDerivative;
<a name="l5"></a> ode-&gt;drag_v2=0.002;
<a name="l6"></a> ode-&gt;drag_v3=0.00001;
<a name="l7"></a> ode-&gt;acceleration_limit=5e3;
<a name="l8"></a> </span><span class=cF5>QueIns</span><span class=cF0>(ode,</span><span class=cF5>Fs</span><span class=cF0>-&gt;last_ode);
<a name="l9"></a> </span><span class=cF1>return</span><span class=cF0> ode;
<a name="l10"></a>}
<a name="l11"></a>
<a name="l12"></a></span><span class=cF1>U0</span><span class=cF0> SpanDel(</span><span class=cF9>CMathODE</span><span class=cF0> *ode)
<a name="l13"></a>{
<a name="l14"></a> </span><span class=cF1>if</span><span class=cF0> (ode) </span><span class=cF7>{</span><span class=cF0>
<a name="l15"></a> </span><span class=cF5>QueRem</span><span class=cF0>(ode);
<a name="l16"></a> </span><span class=cF5>QueDel</span><span class=cF0>(&amp;ode-&gt;next_mass,</span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l17"></a> </span><span class=cF5>QueDel</span><span class=cF0>(&amp;ode-&gt;next_spring,</span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l18"></a> </span><span class=cF5>ODEDel</span><span class=cF0>(ode);
<a name="l19"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l20"></a>}
<a name="l21"></a>
<a name="l22"></a>#</span><span class=cF1>define</span><span class=cF0> M_SIZE (</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>MyMass</span><span class=cF7>)</span><span class=cF0> -</span><span class=cF1>offset</span><span class=cF7>(</span><span class=cF9>CMass</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF7>)</span><span class=cF0>)
<a name="l23"></a>#</span><span class=cF1>define</span><span class=cF0> S_SIZE (</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>MySpring</span><span class=cF7>)</span><span class=cF0>-</span><span class=cF1>offset</span><span class=cF7>(</span><span class=cF9>CSpring</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF7>)</span><span class=cF0>)
<a name="l24"></a>
<a name="l25"></a></span><span class=cF1>U8</span><span class=cF0> *SpanSave(</span><span class=cF9>CMathODE</span><span class=cF0> *ode,</span><span class=cF9>I64</span><span class=cF0> *_size=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l26"></a>{
<a name="l27"></a> </span><span class=cF9>I64</span><span class=cF0> cnt;
<a name="l28"></a> </span><span class=cF1>U8</span><span class=cF0> *res,*ptr;
<a name="l29"></a> MyMass *tmpm;
<a name="l30"></a> MySpring *tmps;
<a name="l31"></a> SpanHeader h;
<a name="l32"></a>
<a name="l33"></a> </span><span class=cF5>ODERenum</span><span class=cF0>(ode);
<a name="l34"></a> h.version=SPAN_VERSION;
<a name="l35"></a> </span><span class=cF1>if</span><span class=cF0> (ode-&gt;next_mass!=&amp;ode-&gt;next_mass)
<a name="l36"></a> h.num_masses=ode-&gt;last_mass-&gt;num+1;
<a name="l37"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l38"></a> h.num_masses=0;
<a name="l39"></a> </span><span class=cF1>if</span><span class=cF0> (ode-&gt;next_spring!=&amp;ode-&gt;next_spring)
<a name="l40"></a> h.num_springs=ode-&gt;last_spring-&gt;num+1;
<a name="l41"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l42"></a> h.num_springs=0;
<a name="l43"></a>
<a name="l44"></a> cnt=</span><span class=cF1>sizeof</span><span class=cF0>(SpanHeader)+h.num_masses*M_SIZE+h.num_springs*S_SIZE;
<a name="l45"></a>
<a name="l46"></a> ptr=res=</span><span class=cF5>MAlloc</span><span class=cF0>(cnt);
<a name="l47"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(ptr,&amp;h,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>SpanHeader</span><span class=cF7>)</span><span class=cF0>);
<a name="l48"></a> ptr+=</span><span class=cF1>sizeof</span><span class=cF0>(SpanHeader);
<a name="l49"></a>
<a name="l50"></a> tmpm=ode-&gt;next_mass;
<a name="l51"></a> </span><span class=cF1>while</span><span class=cF0> (tmpm!=&amp;ode-&gt;next_mass) </span><span class=cF7>{</span><span class=cF0>
<a name="l52"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(ptr,&amp;tmpm-&gt;</span><span class=cF1>start</span><span class=cF0>,M_SIZE);
<a name="l53"></a> ptr+=M_SIZE;
<a name="l54"></a> tmpm=tmpm-&gt;next;
<a name="l55"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l56"></a>
<a name="l57"></a> tmps=ode-&gt;next_spring;
<a name="l58"></a> </span><span class=cF1>while</span><span class=cF0> (tmps!=&amp;ode-&gt;next_spring) </span><span class=cF7>{</span><span class=cF0>
<a name="l59"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(ptr,&amp;tmps-&gt;</span><span class=cF1>start</span><span class=cF0>,S_SIZE);
<a name="l60"></a> ptr+=S_SIZE;
<a name="l61"></a> tmps=tmps-&gt;next;
<a name="l62"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l63"></a> </span><span class=cF1>if</span><span class=cF0> (_size) *_size=cnt;
<a name="l64"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l65"></a>}
<a name="l66"></a>
<a name="l67"></a></span><span class=cF1>Bool</span><span class=cF0> SpanWrite(</span><span class=cF9>CMathODE</span><span class=cF0> *ode)
<a name="l68"></a>{
<a name="l69"></a> </span><span class=cF1>U8</span><span class=cF0> *name,*buf;
<a name="l70"></a> </span><span class=cF9>I64</span><span class=cF0> size;
<a name="l71"></a> </span><span class=cF1>Bool</span><span class=cF0> res=</span><span class=cF3>FALSE</span><span class=cF0>,old_silent=</span><span class=cF5>Silent</span><span class=cF0>;
<a name="l72"></a> </span><span class=cF5>DirMk</span><span class=cF0>(</span><span class=cF6>&quot;~/Span&quot;</span><span class=cF0>);
<a name="l73"></a> </span><span class=cF5>Silent</span><span class=cF0>(old_silent);
<a name="l74"></a> </span><span class=cF1>if</span><span class=cF0> (name=</span><span class=cF5>PopUpFileName</span><span class=cF7>(</span><span class=cF6>&quot;~/Span/Game.DATA&quot;</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l75"></a> </span><span class=cF1>if</span><span class=cF0> (buf=SpanSave</span><span class=cF7>(</span><span class=cF0>ode,&amp;size</span><span class=cF7>)</span><span class=cF0>) {
<a name="l76"></a> </span><span class=cF5>FileWrite</span><span class=cF0>(name,buf,size);
<a name="l77"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l78"></a> res=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l79"></a> }
<a name="l80"></a> </span><span class=cF5>Free</span><span class=cF0>(name);
<a name="l81"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l82"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l83"></a>}
<a name="l84"></a>
<a name="l85"></a></span><span class=cF1>U0</span><span class=cF0> SpanLoad(</span><span class=cF9>CMathODE</span><span class=cF0> *ode,</span><span class=cF1>U8</span><span class=cF0> *src)
<a name="l86"></a>{
<a name="l87"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l88"></a> MyMass *tmpm;
<a name="l89"></a> MySpring *tmps;
<a name="l90"></a> SpanHeader h;
<a name="l91"></a>
<a name="l92"></a> </span><span class=cF1>if</span><span class=cF0> (!src) </span><span class=cF1>return</span><span class=cF0>;
<a name="l93"></a>
<a name="l94"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(&amp;h,src,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>SpanHeader</span><span class=cF7>)</span><span class=cF0>);
<a name="l95"></a> src+=</span><span class=cF1>sizeof</span><span class=cF0>(SpanHeader);
<a name="l96"></a>
<a name="l97"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;h.num_masses;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l98"></a> tmpm=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>MyMass</span><span class=cF7>)</span><span class=cF0>);
<a name="l99"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(&amp;tmpm-&gt;</span><span class=cF1>start</span><span class=cF0>,src,M_SIZE);
<a name="l100"></a> src+=M_SIZE;
<a name="l101"></a> </span><span class=cF5>QueIns</span><span class=cF0>(tmpm,ode-&gt;last_mass);
<a name="l102"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l103"></a>
<a name="l104"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;h.num_springs;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l105"></a> tmps=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>MySpring</span><span class=cF7>)</span><span class=cF0>);
<a name="l106"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(&amp;tmps-&gt;</span><span class=cF1>start</span><span class=cF0>,src,S_SIZE);
<a name="l107"></a> src+=S_SIZE;
<a name="l108"></a> </span><span class=cF5>QueIns</span><span class=cF0>(tmps,ode-&gt;last_spring);
<a name="l109"></a> tmps-&gt;end1=</span><span class=cF5>MassFindNum</span><span class=cF0>(ode,tmps-&gt;end1_num);
<a name="l110"></a> tmps-&gt;end2=</span><span class=cF5>MassFindNum</span><span class=cF0>(ode,tmps-&gt;end2_num);
<a name="l111"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l112"></a>}
<a name="l113"></a>
<a name="l114"></a></span><span class=cF1>U8</span><span class=cF0> *SpanRead()
<a name="l115"></a>{
<a name="l116"></a> </span><span class=cF1>U8</span><span class=cF0> *src=</span><span class=cF3>NULL</span><span class=cF0>,*name;
<a name="l117"></a> </span><span class=cF1>Bool</span><span class=cF0> old_silent=</span><span class=cF5>Silent</span><span class=cF0>;
<a name="l118"></a> </span><span class=cF5>DirMk</span><span class=cF0>(</span><span class=cF6>&quot;~/Span&quot;</span><span class=cF0>);
<a name="l119"></a> </span><span class=cF5>Silent</span><span class=cF0>(old_silent);
<a name="l120"></a> </span><span class=cF1>if</span><span class=cF0> (name=</span><span class=cF5>PopUpPickFile</span><span class=cF7>(</span><span class=cF6>&quot;~/Span&quot;</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l121"></a> src=</span><span class=cF5>FileRead</span><span class=cF0>(name);
<a name="l122"></a> </span><span class=cF5>Free</span><span class=cF0>(name);
<a name="l123"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l124"></a> </span><span class=cF1>return</span><span class=cF0> src;
<a name="l125"></a>}
<a name="l126"></a>
</span></pre></body>
</html>