nrtb-core team mailing list archive
-
nrtb-core team
-
Mailing list archive
-
Message #00488
[Branch ~nrtb-core/nrtb/alpha] Rev 14: Contains initial work on physics core to meet the original 3D specification. This is being promot...
Merge authors:
Rick Stovall <fpstovall>
Related merge proposals:
https://code.launchpad.net/~fpstovall/nrtb/ricks_alpha_d1/+merge/162555
proposed by: Rick Stovall (fpstovall)
review: Approve - Rick Stovall (fpstovall)
------------------------------------------------------------
revno: 14 [merge]
committer: Rick Stovall <fpstovall>
branch nick: alpha
timestamp: Wed 2013-05-08 07:30:48 -0400
message:
Contains initial work on physics core to meet the original 3D specification. This is being promoted primarily as a mark point as the project is being rescoped to use a simplier physics model at least for the early releases.
added:
D_lang/sim_engine/
D_lang/sim_engine/physics/
D_lang/sim_engine/physics/core_clock.d
D_lang/sim_engine/physics/core_data.d
D_lang/sim_engine/physics/core_listener.d
D_lang/sim_engine/physics/run_quanta.d
modified:
D_lang/testing/thread_pool/thread_pool.d
--
lp:nrtb
https://code.launchpad.net/~nrtb-core/nrtb/alpha
Your team NRTB Core is subscribed to branch lp:nrtb.
To unsubscribe from this branch go to https://code.launchpad.net/~nrtb-core/nrtb/alpha/+edit-subscription
=== added directory 'D_lang/sim_engine'
=== added directory 'D_lang/sim_engine/physics'
=== added file 'D_lang/sim_engine/physics/core_clock.d'
=== added file 'D_lang/sim_engine/physics/core_data.d'
--- D_lang/sim_engine/physics/core_data.d 1970-01-01 00:00:00 +0000
+++ D_lang/sim_engine/physics/core_data.d 2013-04-07 18:02:04 +0000
@@ -0,0 +1,132 @@
+/***********************************************
+This file is part of the NRTB project (https://launchpad.net/nrtb).
+
+ NRTB is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ NRTB is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with NRTB. If not, see <http://www.gnu.org/licenses/>.
+
+**********************************************/
+
+import std.string, std.concurrency, std.conv;
+import nrtb.common.vect3d;
+
+// ===== housekeeping messages ====== //
+
+struct kicker {
+ uint starttime;
+ uint tick;
+}
+
+struct start_sim {
+ string sim_name;
+ uint quanta_ms;
+ bool allow_late_entry;
+ bool randomize_start_positions;
+}
+
+struct stop_sim {
+ string sim_name;
+ bool force_bot_disconnect;
+}
+
+struct sim_starting {
+ uint quantams;
+ sim_object you_are_here;
+ bool clock_running;
+}
+
+struct sim_ended {
+ uint quanta;
+ sim_object final_status;
+ bool prep_for_restart;
+}
+
+// Object maint messages
+
+struct impact {
+ sim_object impactor;
+ uint quanta;
+}
+
+struct obj_status {
+ sim_object o;
+ uint quanta;
+}
+
+struct add_obj {
+ sim_object new_obj;
+ bool allow_random_placement;
+}
+
+struct removed_obj {
+ sim_object final_status;
+ string reason;
+ bool may_restart;
+ bool errored;
+}
+
+struct apply_force {
+ uint id;
+ vect3d translation;
+ vect3d rotation;
+}
+
+struct set_attribute {
+ uint id;
+ string name;
+ string value;
+}
+
+struct unset_attribute {
+ uint id;
+ string name;
+}
+
+struct contact_list {
+ uint quanta;
+ sim_object[uint] contacts;
+}
+
+// ===== internal data structures ===== //
+
+struct current_status {
+ uint quanta;
+ uint last_quanta;
+ uint ms_used;
+ uint starttime;
+ uint msgs_in;
+ uint msgs_out;
+}
+
+alias pure void function(ref sim_object, uint time) mod_func;
+
+struct sim_object {
+ uint id;
+ string name;
+ vect3d position;
+ vect3d attitude;
+ vect3d velocity;
+ vect3d rotation;
+ vect3d thrust;
+ vect3d torque;
+ double mass;
+ double radius; // temp for initial alpha
+}
+
+alias mod_func[uint] mod_func_list;
+alias string[string] key_value_list;
+
+struct world {
+ sim_object[Tid] objects;
+ mod_func_list[uint] modifiers;
+ key_value_list[uint] attributes;
+}
\ No newline at end of file
=== added file 'D_lang/sim_engine/physics/core_listener.d'
--- D_lang/sim_engine/physics/core_listener.d 1970-01-01 00:00:00 +0000
+++ D_lang/sim_engine/physics/core_listener.d 2013-05-05 23:17:08 +0000
@@ -0,0 +1,57 @@
+/***********************************************
+This file is part of the NRTB project (https://launchpad.net/nrtb).
+
+ NRTB is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ NRTB is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with NRTB. If not, see <http://www.gnu.org/licenses/>.
+
+**********************************************/
+
+import std.concurrency, std.stdio, core.thread, std.string;
+import core_listener, core_messages, run_quanta;
+
+public static struct sim_core_listener {
+
+ Tid listener_tid;
+
+ // does nothing but start the listenr
+ public this() {
+ listener_tid = spawn(&listener_thread)
+ }
+
+}
+
+private void listener_thread() {
+
+ current_status c;
+ world w;
+
+ // ==== service loop ===== //
+ bool running = true;
+ while (running) {
+ receive (
+ (Tid t, kicker) { run_quanta(t,c,w); },
+ (OwnerTerminated e) { running = false; }
+ );
+ };
+}
+
+private void kicker_thread(Tid listener, uint quantms) {
+ bool running = true;
+ uint quanta = 0;
+
+ while (running) {
+ listener.send(kicker(0,quanta);
+ quanta++;
+ Thread.sleep(dur!("msecs")(quantams));
+ }
+}
=== added file 'D_lang/sim_engine/physics/run_quanta.d'
--- D_lang/sim_engine/physics/run_quanta.d 1970-01-01 00:00:00 +0000
+++ D_lang/sim_engine/physics/run_quanta.d 2013-04-07 18:02:04 +0000
@@ -0,0 +1,61 @@
+/***********************************************
+This file is part of the NRTB project (https://launchpad.net/nrtb).
+
+ NRTB is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ NRTB is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with NRTB. If not, see <http://www.gnu.org/licenses/>.
+
+**********************************************/
+
+import std.string, std.concurrency, std.conv;
+import core_data;
+
+void run_quanta(Tid t, ref current_status c, ref world w) {
+ c.last_quanta++;
+ uint real_time = c.last_quanta * c.quanta; // sim time in ms.
+ real interval = c.quanta * 0.001; // convert ms to seconds.
+
+ // apply movement
+ foreach(Tid t, sim_object o; w.objects) {
+ // apply functional modifications
+ foreach(mod_func f; w.modifiers[o.id]) {
+ f(o,real_time);
+ }
+ // update rates
+ o.velocity = o.velocity + ((o.thrust * o.mass) * interval);
+ o.rotation = o.rotation + ((o.torque * o.mass) * interval); // nota good model!!
+ // move it
+ o.position = o.position + (o.velocity * interval);
+ o.attitude = o.attitude + (o.rotation * interval);
+ // send update to wrapper;
+ t.send(o,c.last_quanta);
+ }
+
+ // simple boundary sphere check for collisions
+ auto keys = w.objects.keys;
+ auto l = keys.length;
+ for(auto i=0; i<l-1; i++) {
+ auto a = w.objects[keys[i]];
+ for (auto j=i+1; j<l; j++) {
+ auto b = w.objects[keys[j]];
+ if (a.position.range(b.position) < (a.radius + b.radius)) {
+ // notify those involved in the collision.
+ impact ti;
+ ti.quanta = c.quanta;
+ ti.impactor = a;
+ keys[j].send(ti);
+ ti.impactor = b;
+ keys[i].send(ti);
+ }
+ }
+ }
+}
\ No newline at end of file
=== modified file 'D_lang/testing/thread_pool/thread_pool.d'
--- D_lang/testing/thread_pool/thread_pool.d 2013-02-21 02:59:03 +0000
+++ D_lang/testing/thread_pool/thread_pool.d 2013-03-07 18:13:30 +0000
@@ -3,7 +3,7 @@
*********************/
// import the concurrency and standard IO modules
-import std.concurrency, std.stdio, core.thread;
+import std.concurrency, std.stdio, core.thread, std.string;
struct thread_pool(wp_t, alias task)
{
@@ -11,8 +11,8 @@
private Tid listener_tid;
// Does nothing but start the listener.
- public this(int queue_size) {
- listener_tid = spawn(&listener_thread!(wp_t,task),queue_size);
+ public this(string name, int queue_size) {
+ listener_tid = spawn(&listener_thread!(wp_t,task),name,queue_size);
};
// submit a work, packet for processing.
@@ -22,17 +22,20 @@
}
-void worker_thread(wpt, alias task)() {
+void worker_thread(wpt, alias task)(string id) {
+ writeln(id," started.");
bool running = true;
+ int c = 0;
while (running) {
receive (
- (Tid t, wpt d) { task(t,d); },
+ (Tid t, wpt d) { task(t,d); c++; },
(OwnerTerminated e) { running = false; }
);
};
+ writeln(id," processed ",c," messages.");
}
-void listener_thread(wpt, alias task)(int queue_size) {
+void listener_thread(wpt, alias task)(string name, int queue_size) {
Tid worker_list[];
ulong next = 0;
@@ -43,25 +46,28 @@
}
// initial setup.
+ writeln(name," listener started");
for(int i = 0; i< queue_size; i++) {
- worker_list ~= spawn(&worker_thread!(wpt,task));
+ string id = format("%s_worker_%d",name,i);
+ worker_list ~= spawn(&worker_thread!(wpt, task), id);
}
// service loop
bool running = true;
+ int sent = 0;
while (running) {
receive (
- (Tid t, wpt d) { submit(t,d); },
+ (Tid t, wpt d) { submit(t,d); sent++; },
(OwnerTerminated e) { running = false; }
);
};
+ writeln(name," queued ",sent," messages to workers.");
};
//==== code starts here
void mytask(Tid t, int i) {
- writeln("Task ",thisTid," processed ",i);
- Thread.sleep(dur!("msecs") (20));
+ Thread.sleep(dur!("msecs") (i));
};
@@ -69,13 +75,12 @@
void main()
{
writeln("D Message Driven Work Queue Example.");
- auto myqueue = thread_pool!(int,mytask)(10);
-
+ auto myqueue = thread_pool!(int,mytask)("thread_pool",3);
+
for (auto i=0; i<100; i++) {
myqueue.submit(i);
};
- Thread.sleep(dur!("seconds") (3));
- writeln("Run complete");
-
+ //Thread.sleep(dur!("seconds") (3));
+ writeln("All messages sent.");
};
\ No newline at end of file