My Right Forearm is Toast

image

I am writing this blog post mostly using a microphone.

I think I’ll try to do this in one shot, clean it up later but keep the original version around, so that the blemishes and problems with voice dictation can be seen.This is not a good sample though, because I am not using a headset: my Turtle Beach microphone has a TRS connector and the Samsung Surface doesn’t have that input.

I am having difficulty using my right hand (lateral epicondylitis) and in an effort to heal I am choosing not to use it for at least 3 weeks. This has led to several discoveries:

Taking things for granted Discoveries:

There are several things built into the muscle memory of my right hand.  For example in Visual Studio, Intellisense.  When a suggestion shows, to choose it is apparently down arrow enter, but when my left hand tried, it tried pressing enter and did not know about the down arrow involved.

I discovered that my brain would output code at the same speed that my hands could put it in. (Perhaps my brain puts it out faster than my hands can put it in and that is why I am having a problem). Now down to typing with one hand, I simply cannot keep up! I get frustrated, and the thoughts that were in my brain disappear leaving me wondering what I was typing.

I have to reevaluate how I am going to be effective at coding over the next few weeks.

Directions and Challenges

I am going to see a doctor whom I trust and see where she thinks I should go. I am hoping that rest will let my body self heal, but if there are major tears in the tendon etc that might need a different level of attention. I am very reluctant to go there. I have heard that once you invade, complications arise.  Bottom line: I need diagnostic stuff, x-ray or something, to determine what the state of things are under the skin.

I have been trying to find resources online that state exactly what the mechanism is for ice and compression leading to healing. I see a lot of sources that indicate that inflammation in the body’s attempt to recover in which case how can I get more inflammation? šŸ™‚ (A: Graston Method is one.)

I have another problem as well: by using my left hand more now, it too is in danger of burning out.  Friday I think my active left arm hurt more than my slinged right arm.

I have watched videos of people using various speech synthesis program to do programming. my reaction was: OMG that is so slow! I am hoping that if I do something like draw onto paper first and get the code out quickly, then I will be able to take my time typing it into the computer in a relaxed and optimal way. I wonder if I could hook up a midi keyboard to something that types in code for me.  lots and lots of macros.

Something very nice about my current employer colon he has had to go to this kind of pain as well, about two years ago.

Tools:

Here are the various tools and tricks that I have learned:

Typing one handed with a living room style small chicklet keyboard: this minimizes travel distance between keys; however I had a hard time finding a small keyboard which also had function keys. Wife and I found one, will try it on Monday.

I am now much more aware of the muscle tension in my forearm while typing.  Normally I would tense up everything and then out would come a burst of keystrokes.  I am now trying to be aware of keeping everything relaxed and returning to zero after every keystroke. 

Four ways of limiting motion:

1. Tennis elbow brace ā€“ bad. cut off a lot of blood circulation and ended up being less than effective, because my problem is along the entire length of the muscle / tendon and not just in the elbow region.

2. Sling: a lot better. the first two days using the sling, my hand definitely went into repair and recovery mode. however, the sling dug into my neck of lot and can be very uncomfortable.

3. Athletic Tape:  bind my right hand fingers together to prevent the temptation to use them.

4. Wear a glove on my right hand: this is very effective in stopping me from using it accidentally. However, it is not as healing for my hand as a sling, but it is better on my neck.

I find it very funny that my attempt to say third came out as a turd

Another thing that deserves a metnion is KT tape.   I used it for a week or so prior to becoming serious and using a sling.  It provides a lot of good support, but at the expense of skin sensitivity, as the support comes from elasticity of the skin.   Eventually the skin rebels.

And now I have a cat who is trying to use the microphone as well

Emotion:

So I have this amazing opportunity color to re-evaluate how I work, as well as something that forces me to choose what I do with my time. I am certainly not going to play much Elite dangerous, nor am I going to work on my side project, until this is better – trying to save my hands for generating income.  I could probably get around playing American Truck Simulator with my steering wheel and using my left hand just like driving my car.  However, thereā€™s only two cities left to visit, Iā€™m probably going to wait for the DLC / Arizona to show up before I play it more.

No, I now have an opportunity to catch up on several books that I have not yet read, and to focus on working out and nutrition and things like that.

However, right now I am sad and just want to say cluck it all and watch TV shows and hide. and that’s okay, it’s just part of Grief. I am not sure I am out of denial yet. Maybe I’m near the pyramids. get it? Denial? the Nile? Ed used to make that joke all the time.

The other disadvantage of a voice dictation is that this laptop keeps thinking I am not doing anything, and shutting off in the middle of a sentence

Wish me well! I am now going to go back through this post and use my left hand to edit it so it is readable.  I also had a cat volunteer to sit on my right hand helping me not use it.

Original Text ā€“ before lots of editing.

I am writing this blog post mostly using a microphone.

I think I’ll try to do this in one shot and then clean it up later but keep the original version around so that it’s blemishes can be seen. space this is not a good sample though, because I am not using a headset comma because my Turtle Beach microphone has a TRS connector which My Little surface Samsung sing sing thing doesn’t have an input for

I am having difficulty using my right hand insert black muscle Palma and in an effort to heal this hand I am choosing not to use it for at least 3 weeks. this has led to several discoveries hole in the line

There are several things that I take for granted that are built into the muscle memory of my right hand for example in Visual Studio Computing intelligence is apparently down arrow enter, but I didn’t. Know that my right hand you that when my left hand try to do the same thing it tried just pressing enter and did not know about the down arrow involved

Other thing I discovered is that for many years, my brain would output code at the same speed that my hands could put it in. perhaps my brain puts it out faster than my hands and put it in and that is why I am having a problem. Now down to typing with one hand, I simply cannot keep up the mycohl I get frustrated, and the thoughts that were in my brain disappear leaving me wondering what I was typing. I have to reevaluate how I am going to be effective at coding over the next few weeks.

My solution plan is currently very simple: I am going to see a doctor whom I trust and see where she thinks I should go. I am hoping that rest will let my body curious, but if there are major tears in the tendon or something like that color that might need a different level of attention. I am very reluctant to go there. Center Center

I have another problem as well: by using my left hand more now, it too is in danger of burning out.

I have watched videos of people using various speech synthesis program to do programming. my reaction was color oh my God that is so slow exclamation I am hoping that if I do something like hold onto paper first and get the pot out quickly, then I will be able to take my time putting the code in to the computer in a relaxed and optimal way.

Something very nice about my current employer colon he has had to go to this kind of pain as well, about two years ago

Here are the various tools and tricks that I have learned colon um

Typing one handed with a living room style small chiclet keyboard color this minimizes travel distance between keys semicolon however I had a hard time finding a small keyboard which also had function keys

At first using a tennis elbow brace, however. Cut off a lot of blood circulation and ended up being less than effective, because my problem is along the entire length of the muscle / tendon and not just in the elbow region

Second attempt is using a sling, and that has worked a lot better. the first two days using the sling Kama my hand definitely went into repair and recovery mode. however, the slang dig into my neck of lot and can be very uncomfortable align

Turd was to use either some athletic To find my right hand fingers together to prevent the temptation to use them, or to wear a large fingerless mittens on my right hand colon this is very effective in stopping me from using it accidentally. However, it is not as healing for my hand as a link, but it is better on my neck

I find it very funny that my attempt to say third came out as a turd

I have been trying to find resources online that state exactly what the mechanism is for ice and swelling leading to Healing. I see a lot of sources that indicate that inflammation in the body’s attempt to recover in which case how can I get more information? šŸ™‚ New York

And now I have a cat who is trying to use the microphone as well

So I have this amazing opportunity color to re-evaluate how I work, as well as something that forces me to choose what I do with my time. I am certainly not going to play much Elite dangerous, nor am I going to work on my side project until this is better Kama trying to save my hands for generating income. I could probably get around playing American Truck Simulator with my steering wheel and using my left hand just like driving my car. Uline no, I now have an opportunity to catch up on several books that I have not yet read, and to focus on working out and nutrition and things like that.

However, right now I I am sad and Hi just want to say cluck it all and watch TV shows and hide. and that’s okay, it’s just part of Greece. I am not sure I am out of denial yet. Maybe I’m near the pyramids. get it? Denial? the space and I on? The Nile River? Ed used to make that joke all the time.

The other disadvantage of a voice dictation is that this laptop keeps thinking I am not doing anything, and shutting off in the middle of a sentence

Wish me well! I am now going to go back through this post and use my left hand to edit it so it is readable.

dotnetmud: spacemud: optimizing network traffic

I spent some time getting the network load produced by the game down.     The rest of this post, I test out the changes to see how much better everything became.  

Methodology

Two ships connected; Iā€™m going to leave their starting locations as random.  Iā€™m going to have them turn in circles and constantly fire.  This will yield some explosions against the planet, and others against each other, but most of the missiles will be flying out into space.

Running against a deployed web server in the cloud

Using WIFI and my home internet connection.

Collecting data via portal.azure.comā€™s App Service Monitoring graph set to minutes.  (This didnā€™t work, I had to go with my local wifi connection)

image

https://github.com/sunnywiz/dotnetmud2015/tree/chatty1

This is where we started at.    Sample packet and network load:

imageimage

 

https://github.com/sunnywiz/dotnetmud2015/tree/chatty2

The main change was to give custom JsonProperty names, as well as to reduce the number of decimal places being transmitted.

imageimage

I use Decimal  instead of Double because in doubleā€™s, thereā€™s a chance that the underlying representation isnā€™t quite so digit friendly; decimals are exact for every digit.  However, decimals are harder on the processor for doing math ā€“ supposedly.   I havenā€™t tested that.

The result:  Not too much better.   5.5 MB came down to 3.1MB on the receive side.

 

imageimage  

https://github.com/sunnywiz/dotnetmud2015/tree/chatty4

chatty3, which Iā€™m skipping, changed the method signatures to two-character method names.  Not too much saved there.

chatty4 added ā€œblanking outā€ data that doesnā€™t change much.  It does this by keeping track of what it believes the client thinks the state is, and doing a diff:

image image

imageimage

In order to pull this off, I had to go to a dictionary of objects to render, rather than an array.   I also kept a ā€œfullā€ frame every 10 frames, similar to MPEG encoding G vs I frames.

I thought Iā€™d get fancy and send nulls if various values (DX, DY) had not changed (for example, they do not change for bullets) ā€“ however, JSON sends a ā€œ:nullā€ which can be longer than just sending the value.  The more advanced version of ā€œdonā€™t include the property if it hasnā€™t changedā€ is possible, but it got too complicated, so I ignored that for now.   So this version only does the image and name attributes, but thatā€™s enough to get a nice reduction in size:

 

imageimage

The savings:  another 30%.  Its still a lot of data.  Not quite the gains I was hoping for.

At this point, an average entity on the screen is taking 100 bytes or so, instead of the 500 they were before. 

Network Optimization: Where to go from here?

Iā€™m going to call this good enough for now.  The directions to go from here for network optimization:

  • Instead of using the system JSON serialization, write my own serializer.   This could do things like ā€œIf It hasnā€™t changed, donā€™t send itā€.
    • so instead of: {“DR”:0.0,”DX”:17.109,”DY”:299.512,”ID”:0,”IM”:null,”N”:null,”R”:446.7,”RA”:3.0,”X”:37.0,”Y”:1474.8}
    • ā€œdx17.109dy299.512id341r446.7x37y1474.8ā€   thatā€™s about half the size.   But needs a lot more code to massage it.
    • Could use a binary packing method as well.   Quick search doesnā€™t find anything that is happy in both C# and Javascript.
  • Put some logic in as to whether something needs to be sent every time or not.  For example,
    • bullets pretty much go in a straight line once fired.  They donā€™t need to be sent every time.   In fact, if the current X,Y is approximately where the previous update X,Y + DX,DY would put it, then thereā€™s no need to send those values.
    • Planets currently donā€™t move. (That will change).      This is a broader case of ā€œnothing has changed in this object from what the client expects, so just acknowledge the object still exists, nothing moreā€.

Whatā€™s next?

I think that authorization / identity of clients (and dealing with disconnection better) is in order.  

Then I can do the ā€œsingle person logged in, multiple clientsā€ code

And then we can launch a spaceship from the text game.

And then we can design an actual playable game.   (oooo!)

dotnetmud: spacegame: Timing Loops 1: Client / Server timing loop

imageI feel stalled in my project.  It might be that I need to write about the important stuff done so far before I continue to redo/optimize the game; setting the stage to understand the need for some of those optimizations.

Reference code for this post (tag): https://github.com/sunnywiz/dotnetmud2015/tree/blog20160302.

The playable game (which might be updated, not frozen to this post) is: http://dotnetmud.azurewebsites.net/Home/SpaceClient

Game state at this time:   Multiplayer, can shoot missiles, missiles hit things, score is kept.

There are 3 interacting timing loops:

Client / Server Update Loop

I made the client ā€œin chargeā€ of this.  Starting in Javascript, the client requests an update from the server:

image

image

Along with the request for game data, the client is also sending the state of controls for the user.  I went with ā€œhow many ms has the thrust key been pressedā€ as my input ā€“ thereā€™s a separate set of handlers which watch key-up and key-down events and long how long keys have been pressed for.

This then travels up through Signal/R, and shows up at the server 20-50ms (an eternity) later:

image

The SIgnal/R side of the hub takes the connection, looks up which server-game-object that connection is tied to, and asks that game object (which happens to be a Ship.cs) to craft what it thinks the world looks like.

The Ship has several things it has to do. 

First is to look at the keypresses and turn those into thrust amounts.  I went with a % of thrust:

image

There is similar code for ā€œcan I fire another missile yetā€ (not pictured).

Then, it makes a copy of all the stuff that the client needs to draw the world:

image

It records itself, all the other 2D objects in space, some scores, and what the current ā€œServer Timeā€ is (and rate of change of server time, which is a YAGNIY for when the server gets overloaded and has to go into bullet time).

It packages all that into a return (of type object, which gets JSON-serialized), and SpaceHub happily sends it back to the client:

image

Then, 25-50ms later (another eternity), the client receives the game-update:

image

  • Green ā€“ the client updates what it knows about whatā€™s going on on the server.   I tried to keep this in its own ā€œobject spaceā€, to indicate that the server is the authority here.
  • Blue ā€“ the client updates various things that are of interest to the client
  • Purple ā€“ thereā€™s some bulk copying going on that isnā€™t very sexy and is very network-inefficient.
  • Red ā€“ and the client immediately requests another packet.

Places to Improve: Network Traffic.

The server sends ALL the data, ALL the time.   A network packet looks like this (raw, pretty printed):

image image

There is a LOT of stuff in there that is needed once (like image URLā€™s), and then does not change.   Also, many property names, while nice for humans, is not optimal for network traffic (words like ā€œClientREquestsPollFromServerā€) for example.

ā€œNo Big Deal?ā€  — Doing a test, holding down the fire button and shooting the planet, for a few minutes, in Azure Data:

image

Doing some math:

image

If I have a successful game, and thereā€™s about 1 combat going all the time, weā€™re looking at $18 per month.

The solution for this is to only send diffs across the network.  Thatā€™s on my list for pretty soon.  But it will require some hand-crafting detail.   And some before/after testing.  This will be its own blog post.

Places to Improve: Network Lag

This model is similar to how Kermit used to work ā€“ there is a LOT of dead time between updates.   

One way to improve this might be to have the client keep track of the lag between server updates, and then, in its request to the server, ask ā€œplease give me additional packets at the following times, until you hear from me againā€.    So, the server could send 2 game-updates for every 1 client-inputs-update.     Its on my list, sometime after sending diffs.   Have to be careful and mark the intermediate frames as intermediate, so that only the major frames cause the cycle to continue.

Another direction we could go is completely decouple the client-input from the server-response.   Iā€™m not going to do that, because I like how the client has to constantly remind the server of its existence ā€“ if the client goes haywire, I donā€™t need to write additional server code to detect that and shut down the server sending stuff to the client.   Iā€™m also lazy. Smile 

In Conclusion

So, thereā€™s the ugliest timing loop in the game so far.   The other two are relatively easy, may not get written about soon. 

dotNetMud: Its Alive! (on azure)

The link:Ā  http://dotnetmud.azurewebsites.net/

From there you can either get into the old-fashioned text-and-chat mud:

image

(Valid commands are who, look, shout, say, and east and west)

 

Or you can get into the space-mud side of things:

image

(Valid controls are W for thrust, A and D for rotate)

Neither of these are really interesting until you have more than one client (browser, tab) logged in.Ā  In the case of the latter, perhaps from different computers, with different network speeds.

Corresponding source code:Ā  approximately here (as of these screenshots):Ā  https://github.com/sunnywiz/dotnetmud2015/tree/blog20160220

Where to go from here?

I could try to make the space game more fun ā€“ adding missiles and lasers.Ā Ā  More realistic game.Ā Ā  You canā€™t have a space game without combat.. can you?

I could try to make the space game more single-player interesting ā€“ adding gravity, multiple planets. (your mission: try to get into orbit around a planet).Ā  This lends itself to ā€œmore realistic server side computational loadā€.

I could try to make the space game more efficient ā€“ optimizing network traffic (right now, VERY large messages).

I could try to make both clients work better ā€“ by having ā€œsessionā€ be the unifying factor, and the text game launches the space game, both in the context of the same player object, somehow.Ā Ā Ā  This would probably involve hooking up to a database for persistence of user information as well.Ā Ā Ā  This is complicatedā€¦Ā  this is probably where I should go if Iā€™m focusing on the ā€œsample gameā€ side of things.

I could try to make space more interesting ā€“ by voronoiā€™ing it, so that it can have 10000 or more objects, but its very easy to find the objects that are within, say, 100000 units of you.Ā Ā  So that I can do hyperdrive between star systems that you can drop out of and be in the middle of nowhere.Ā  Also complicated.. probably comes after multiple planets.

I could try to stress test it ā€“ get a bunch of computers attached to it, see how it performs on the azure side.Ā  I have it running on a Free web-node at the moment, and its surprisingly happy ā€“ 1.9% CPU.

dotnetmud: Hitting a wall on clients, hubs, and games

Till now, Iā€™ve had this pretty simple layout:

The browser fires up a signal/R client, which connects to a signal/R server, which talks to a driver, which talks to a game-specific engine.

One signal/R client maps to a user in the game somewhere.

This Situation is not Covered:

You are standing in a spaceport

You see:

a ship

>> board ship

You are inside the ship.  you can ā€˜launchā€™ to launch the ship.

>> launch

 

At this point, something happens that tells the client ā€œhey, start this other client upā€ ā€“ possibly in a new tab.    Maybe it leaves the current tab in place. The new client connects up to its own hub, with its own mudlib, and does its own kinds of commands. The user can then fly the ship around in space.  The space stuff doesnā€™t know that the ship is also a ā€œmudlibā€ object.

This could also be used with Shop Transactions, or a Game of Uno, or whatever ā€“ custom client for custom situation, in the same userā€™s session.

What this Means

a) I need a different sort of Auth mechanism to bind the user to an Identity.  I think Iā€™ll probably go ahead and use the stock websiteā€™s authentication methods to get myself an actual UserIdentity;  I donā€™t know if that would flow down into any signal/R client or not.

b) Every user can have MULTIPLE clients going on at any point in time.   

This is making my head hurt.  Iā€™ll let it percolate.   For now, no cross-jumping between clients.

HOWEVER, I do want to move the <T> that I currently have on the Driver so that the Driver stands alone, and the Signal/R Hub is the one that knows about the mudlib GameSpecific. 

(dotnetmud) spacegame: accelerating to a planet

I shook some dust off some old braincells, and re-remembered some algebra.

My quandry, as hinted by previous post:  GIven that Iā€™m 42000 units away from the planet, and I have a max acceleration of 100 units/(sec^2), how much do I accelerate in the direction of the planet?

Some googling finds this:   https://van.physics.illinois.edu/qa/listing.php?id=116

d = vt + (1/2)at2

I know my distance, 42000.  And I know my a, 100.   What I need to calculate is v.  But not the one in the equation ā€“ thatā€™s starting velocity.

Reverse it.  At the planet, starting at v=0, whatā€™s my final velocity when I get to distance d?

The velocity is v = at.  So if I can solve for t, then I can plug that in.

d = (1/2) att

tt = 2d/a

t = Math.sqrt(2*d/a)

v = a * Math.sqrt(2*d/a).

Check the numbers in excel.   I set it up like this:

image

And plug in the formula to see how well it calculates speed:

image

The drift is due to the coarse 1 second time interval on the calculations, Iā€™m pretty sure.

 

So, the answer is, if Iā€™m 42000 u away from the planet, and I can thrust at 100 u/s^2, I want to be going 100 * Math.Sqrt(2*42000/100) = 2895 units/sec in the direction of the planet.

  • If Iā€™m not going this speed, I need to boost in the direction of the planet.
  • If Iā€™m going faster than this speed, I need to boost in the other direction.

To make up for inaccuracies, Iā€™ll set the target velocity to match, say, 90% of my actual available acceleration.

Iā€™m not accounting for my initial velocity at all, even if its not in the right direction.  The point is, at any point in space I can caluate what my velocity should be, and what direction it should be in, for the fastest approach to the planet.  Whatever Iā€™m doing, change to match that.   It should be a nice curve, followed by some nice acceleration, followed by a turnaround, and then some deceleration with some waggles. 

Looking forward to implementing it.  No time tonight, so I just blogged about my resurrection of Physics 101 instead.   Super-excited.

DotNetMud: SpaceGame: Autopilot

After an aborted run at Rares Trading in Elite Dangerous (idea: pick up rares, go to Fehu, sell them, and then pick up missions there.Ā  Problem: takes many hours to get enough worth selling), I took a look at writing an autopilot in my javascript space game (the part that is not yet Mud-like, but I intend for it to be).

Nice: Javascript has a Math.atan2(y,x) which _possibly_ avoids the x=0 problem that normal Math.atan() solutions do.Ā  (arctangent gets you the angle to something so you know where to point the ship).

However, my code doesnā€™t work.Ā  My ship very often points AWAY from the target, and applies FULL THRUST FOREVER.Ā  This is NOT how you go somewhere.

Thereā€™s another aspect ā€“ Iā€™m simulating ā€œkeyboard controlā€, ie, IsThrusting, IsLeft, IsRight.Ā Ā  For the ship to feel responsive when playing the game, need to have good numbers for these.Ā  But with autopilot, thereā€™s a lot of jigger (LRLRLRLR) because it continually overshoots its target.

So, hereā€™s what I have to do for the relatively final solution:

  • Set up the ship so that thereā€™s a finer gradient of control.
    • What Iā€™ve seen other games do is, the longer you have it pressed, the more thrust you get, up to max.
      • This means I need to swap out my current keyboard handler (keyup, keydown) to change to a dictionary of ā€œwhen was it pressedā€, so that I can calculate how long its been held.
    • Or, I could go with W = 12.5% thrust, Ctrl-W = 25%, shift-W= 50%, and ctrl/shift = 100%.Ā  Almost 8 stops.Ā  More instantaneous full thrust available.
      • I want to avoid something where the autopilot can take a shortcut thatā€™s not really available to a player.Ā Ā  So if I did the slow build up, Iā€™d have to have the autopilot also do a slow build up.
  • Change how I do the maths for the autopilot.Ā Ā  Inputs to autopilot:Ā  Who to go to, and what distance to orbit them at when we get there.
    • I see a few major layers.
    • First one is ā€œclose the distanceā€.Ā Ā  This would use the calculation of ā€¦ http://physics.info/motion-equations/Ā  ā€¦ ouch, my brain hurts.Ā Ā  Basically, I need to find a solution for:
      • If I start at the orbit distance, and accelerate away at 75% thrust, what velocity am I at when I get to my current distance away?Ā Ā  Reverse that.Ā  Thatā€™s the velocity towards the object that I want.Ā Ā  Call that V1.Ā  I want it to shut off as I get close to the destination so that orbital stuff can kick in.
    • Second one is orbital force.Ā Ā  Skip this if Iā€™m more than 2x the desired distance.
      • Figure out if Iā€™m going clockwise or counter clockwise from the destination.Ā  OR, just assume one direction for now.Ā  clockwise.
      • Figure out the vector I need to be in a perfect circular orbit around the object at the desired distance.Ā Ā  Magnitude is known (previous post on orbital mechanics has link to the article), and Direction is 90 degrees from where the destination is.
      • Thatā€™s my desired vector V2.
    • Combine V1 and V2.Ā  This is my desired vector V3
    • Look at my current vector V4 and figure out the change that needs to happen V5 = V3-V4.
      • Do a left/right thrust as needed to point me at that vector (do a smoothing function here).
      • if Iā€™m pointing in relatively the right direction, do a thrust along that vector (do a smoothing function here).

This could be really fun.

Image: wikipedia

When Maths goes right

I found out I had been doing gravity wrong.

This is what I was getting:

image

There seemed to be gravity, but it was messy.

I had been using the good old (G*m1*m2)/(r^2) equation.   However, in an effort to be smart, I calculated the (x2-x1) * (y2-y1) to be the (r^2) value..

WHICH IS TRUE.

And when you apply that force to an object of mass m1, the m1 disappears (F=ma; a=F/m) and you get the acceleration, the pull of gravity.

But, the kicker is, I then have to scale the normal vector out by that.   And the normal vector isā€¦  just the x component .. is .. (x2-x1)/r. 

When you do the whole thing, the acceleration felt is proportional to 1/r^3, not r^2.

So I did that.  And I pulled out the gravitational constant, G, to use elsewhere (turns out you can calculate orbital velocities and periods as well). 

The result:

image

No matter where you start, no matter your initial velocity and direction (within reason), you get a nice orbit.

Whatā€™s more, I could use the maths where ā€œvelocity at distance rā€ can be calculated, as well as ā€œradians per unit timeā€ can be calculated, for a circular orbit.

This means, I could write an autopilot to get you in a circular orbit around a star or planet at a particular distance pretty easily.  I think.

However, I also found out that due to gravitational effects of planets,  it was very easy to get swept into the sun.. and then gravitationally flung out of the solar system.

So, I changed it when you get within the radius of a planet, gravity is about constant ā€“ like it would be at the surface.  ā€œAirbrakesā€, as it were.  

THIS HAS PROMISE!  I spent probably an half hour flying around in this simulation, gravity made it so interesting. 

source: https://github.com/sunnywiz/dotnetmud2015/blob/e5db82581382e43a721f0abc4a5c45710ed7fee4/canvasTest/solarSystemFlight.html

it needs one image from the same directory.  Otherwise, just run that file.

dotnetmud: inheritance and awareness and IoC

Iā€™m running around in circles, so I thought I should try to draw it out.  Click to zoom in if not legible; text below explaining.

image

All the words are driving me nuts.      So I added A,B,C,D to the diagram above.

  • A = the layer that talks network transport stuff, like Signal/R. 
  • B = the layer of the game that cares about booting up, shutting down, who is logged into the game, loading and unloading of realms.
    • This stuff should NOT be directly available to in-game objects to mess with!
  • C = subset of B.  This is the stuff that should be available to in-game objects.  Itā€™s the O/S of the game, as it were.
  • D = game code.  In the case of wizard-coded realms, probably gets scanned to make sure it has no assembly references, and in days of old might have run under CAS. 
    • Iā€™m not actually going to secure it, just want to make sure its probably securable.

Requirements:

  • A should not know about all the stuff in B;  just bare minimums to talk network occurences to.
  • B should definitely not know about the specifics of A.  In fact, Iā€™d say B is an assembly that HAS NO REFERENCE to Signal/R.
  • D should not know about B.  Iā€™d go with: D can ONLY have an assembly reference to C, and NOTHING else; if something is to be made available to code in D, it must be added to C as a pass-through.
  • B & C can know all about each other.

Singletons vs Static vs ..

Lets call ā€œCā€ the driver layer.   Ie,  IDriver.FindObjectByName() would be an example. 

For all the code in the Mudlib, right now, it does stuff like Driver.Instance.FindObjectByName().

It might be better to use IoC and take an IDriver in the constructor, and then call _driver.FindObjectByName().  HOWEVER, then I get into things like ā€œCan I have IoC limit which objects can be createdā€, and ā€œI want to make sure as the objects are created that I can keep track of realms and stuff like thatā€, and all of a sudden IoC is too nice a tool to use.  Iā€™m sure it could be used with guards on it, but ..    leave that to somebody else, I have no joy in solving that.

So then I could go with how many libraries get a hold of things ā€“ (static class DotNetMud.XXX).Driver.      Always gets you the same one every time.

But if Iā€™m doing that, why not just have a static class, Driver.FIndObjectByName()?     No, I donā€™t want to do this, because I MIGHT want people to be able to unit test their mudlib objects, and I want the driver to at least be an IDriver so it can be mocked somehow.

So, I think where its going is, Iā€™ll have a poor manā€™s IoC.  DotNetMud.Global.Driver   gets you the driver.  

Who References Whom? How to deal with the Inverse?  

D references C for sure.

A references and feeds B, including telling it how to talk back to A (via Lambdaā€™s)

B is configured to know how to get to D.

C, when asked, can create objects from D.  but it only knows D through configuration.

C needs access to stuff in B

B doesnā€™t need much from C/D, other than the interactives list, I think.

So thereā€™s another guy, @, who:

  • reads configuration to determine
    • Who is D
    • Who is D.GameSpecifics
  • Creates or Gets Singleton of B
  • Creates or Gets Singleton of C
  • Informs B of C or C or B or whatever.   Not sure about this part yet.   Probably they each know each otherā€™s interface.
  • Tells C enough stuff about D so that it can create objects from D on demand.
  • Tells A about B
    • I would say creates A, but ā€¦ SignalR does its own creation. So really more like when A is created, self-registers the context somewhere and triggers something so that A can talk to B.

 

Right now its all in one assembly.

This stuff is TOUGH.

And it gets tougher with code loaded on the fly.  I donā€™t think Iā€™m going to deal with that yet.

No wonder when I open up the project, this stuff isnā€™t flowing well.  Smile 

How to get it there

I think I should probably get everything living in the same assembly at first, except under a web server rather than a console app.

Then, get the singleton-reference stuff in place.   DotNetMud.Global.xxx.  Change all references to do that.

Then, peel out the MudLib to its own thing.  It still references all of B/C combined.

Then, peel out C to its own thing. 

Then, peel out B to its own thing, separate from A.

This is a several-hour project, I fear.

Offline Briefcase Sneaker Sync

Problem

I have 1.6TB of ā€œstuffā€, that I want to keep synced between home and off-site.

Iā€™ve tried several ways of online syncing ā€“ Crashplan, BtSync, Rsync, etc ā€“ and it always breaks down somehow.  Iā€™m tired of relying on the internet to get it done.

I travel back and forth between these locations all the time.  How about a sneaker-sync?

  • Two desktop computers, with 1.6 TB of stuff
  • 1 128G USB drive to store the Deltas
  • A program to run at either site, that can figure out what to put on the USB drive, to bring the two repositories in sync with each other.

Solution Proposal

Hereā€™s my thoughts on what it would take.   It can be given a pretty UI later.

  • USB flash drive of arbitrary size
  • SneakerSync.exe, .config
    • Relative location to path where files are kept.
    • maximum size of the USB flash drive to use.
    • % to keep for deleted files
    • Repository/db of tracking stuff.

Target computer #1:

  • F:\Share   <ā€”has the tons of stuff

Target computer #2:

  • \\NetworkLocation\Share   <ā€”also has the tons of stuff.   To be kept in sync.

To make things simpler, Iā€™m just going to call this the ā€œshareā€. 

Command line Usage:

  • sneakersync.exe  f:\share   when at computer 1
  • sneakersync.exe \\networklocation\share when at computer 2

What it does:

  • Scans to see what the latest/greatest are at a given computer.
  • Determines files that need to be synced to other sites
  • Determines files that are out of date with reference to other sites
  • Updates local files if it knows what it has on the stick is fresher
  • Grabs any files that DEFINITELY need syncing on some other computer somewhere else
  • Backfills other interesting files if thereā€™s space available.  Probably in most-recently-updated order. 
  • doesnā€™t delete anything ā€“ saves copies on usb stick, rotating buffer.

Future Autorun usage:

Autoruns, looks around for file systems it can update that it knows about, does the update.

To pull this off, what would it need

Define: ā€œLogical Shareā€ = the concept of the file system, regardless of how many machines it is spread across.  Think of it as ā€œthe dropboxā€, for example, when using dropbox.

Define ā€œPhysical shareā€ = the files on a disk on a computer.

We would need to track:

  • Logical file system contents, plus which computer has the ā€œmost recentā€ or authoritative version of a file.
  • physical file system contents, as best known, for all physical file systems.
    • With each physical file system file, the determination that it needs to be updated (ie, its stale, logical has newer)
  • Whatā€™s in the briefcase for transfer
  • Whatā€™s in the briefcase in the trash can.

Side Effects / Interesting conditions.

There will be conflicts where the file has been modified on both computers.  Iā€™d say, alert the user, take the most recent one, and stick both copies of files into the trash can.

If you somehow loose all physical instances of a share, you should have the most recent N files in your briefcase.  Hopefully thatā€™s enough to get you back to a backup.

When will I write this code

Maybe never.  Its been in my head for a few years; I have some other stuff Iā€™m working on right now.  Maybe somebody else is interested in writing this and monetizing it?  Smile  

Or even better, maybe somebody else has already written this.