## I couldnt sleep – Hyperdrive

It might be the 4 espresso drinks i drank earlier. But i couldn’t sleep. My brain was chewing on ways i could do a hyperdrive.

The idea is like .. a condor? big bird, floats on drafts/currents. Starts off on feet and wings, expends a bunch of energy getting up into the air, but once its there, it floats.

So, earlier, i wanted thrust in a direction to keep on building velocity. I would make it encounter a kind of resistance that goes up, so that there’s a terminal velocity that gets approached. Lets call that V=1.

Upon getting to that V=1, you kick in the … insert science fiction name here, but its the “flapping” part of getting flying. Say it kicks you into hyperspace, at V=1.3. If you get below V=1, you exit hyperspace. Maybe its the Hyperspace actuator. You can get better hyperspace actuators.

In hyperspace, there’s a different engine available. Its a directional “push” – you can push against what would normally be gravity sources in normal space. The closer the thing, the better the push. you aim your pusher beam against the target, and apply push power. This speeds you up well beyond into much better V’s.

However, there’s “friction” in hyperspace .. probably map-based. I’d probably do it as a function of how close you are to a star .. basically gravity wells have cleared out the friction stuff. So depending on where you are, you slow down. If you go far away from all stars, the distance to the stars = less push, and friction, makes it impossible to stay in hyperspace.

Would have to play with the numbers, but lets say that it would take 10-30 minutes to get between most stars at V=1. Lets take the 30 minute case, D=30 between them. Assume stars have mass M=1.

1. Line up your current star with your destination star. Speed up towards your current star, getting to V=1. Gravity pulls you in as well. Beginning your run as it were.
2. When you get close enough to V=1 kick in your hyperdrive actuator to boop over to hyperspace, maybe at V=1.5
3. Pass through/past the star and then use your hyperdrive vector engine to target your star, and push against it. At distance D=1, you get a nice M/D push of 1 bringing you up to 2.. i did a quick excel thing to expound on this …

I lost my bullet numbers. I get a transit in T=10 instead of T=30.. I’ll probably have to make more oomph available at longer distances, so its more like a pole, but i really wanted it to be “if you’re caught between the stars, its hard to get oomph.” Also, with the above setup, your max distance from a star works out to about 60-70 units if the star has mass 1.

If i change it to be Mass/sqrt(distance), i get still 4 minutes, but the distance greatly increases. Hmm.

But, anyway, that’s the idea. As you get close to the target star, you push against it bringing your velocity back under V=1 and you pop back into normal space. And avoid those “dense” areas where max-v is lower if you want to float longer.

Okay, now maybe i can sleep.

## Space Mud/Game Ideas

Long time no update .. a codebase. https://geekygulati.com/2016/03/12/dotnetmud-spacemud-optimizing-network-traffic/ is when I talked about it last.

I was playing Starcom Nexus, and it reminded me that once upon a time i was playing with flying a ship around in gravity. I looked, it was 7 years ago. I cloned it, I updated it, I ran it. I was amazed.

I’m not going to kid myself with “I have time to work on this” .. but, if I did, what would I make? This is like “If I win the lottery”, giving space for some creative stuff to sparkle. I would have planets that (slowly, unrealistically) orbit their stars.

I would have planet and sun gravity that draw ships in

But the ships won’t crash against the planet. Instead, there will be a “autopilot” bump that happens that assists the ships into a non-crashing orbit over time. (so a few times they’ll go through the planet, but eventually would end up orbiting)

ships can do a “land” feature if they are close enough to a city, goes into an automatic “shrink into the planet” type of thing. At that point, the game switches over to text mode of having landed, getting out of the ship, n/s/e/w to visit whatever places.

At first i wanted real thrust type stuff. But that can be very unmanageable.

So make it manageable. Choose an object to travel to. Accelerates towards, the decelerates. Can be planetary. Can be a ship. Different levels of autopilot around this can be purchased. Fuel cost for the big accelerations, free small ones to prevent stranding. Standard given autopilot = bring self to a stop relative to object (so you can end up at your target)

But i don’t want acceleration to be good for interstellar travel. Not without putting in 10 minutes of game time or more. For that, i want a hypertravel mode, but with a twist:

In hyperspace mode, gravity is inverted at d^5 or something silly like that. So to send yourself to another star, you get close to your current star, switch to hyperspace, and get catapulted out that way. If you aim wrong you can still use your hyperspace drives to point yourself in some direction, but they can only slow you down or speed you up to some absolute value. (the stellar launch can exceed that value). spend more money for better vectoring and acceleration and maximum controllable velocity. You would learn about stellar launch the hard way, you could just go into hyperspace and start accelerating towards a star.

So you would theoretically line up against a star, go into hyperspace, get catapulted, get close, and if you did it just right you would get slowed down by the target star but if not you would drop out of hyperspace somewhere around your target star. You drop out of hyperspace only when your hyperspace velocity gets slow enough.

The rest of the game would be similar, i guess, to Starcom Nexus. You visit planets, you solve things, you get resources, you fight baddies, you mine stuff, etc. That’s the game built on top of the above. Except that planet visits are text adventures.

I’m writing this from a hotel in Phoenix, where i’m on vacation with my wife. Its only taken .. 2 days? of vacation time, to get my brain clear enough to where this stuff starts coming up for creativity. yay!

## Star Citizen: Delivery Missions

I’ve been obsessing with Star Citizen delivery missions. Video 1 and Video 2.

I thought maybe I could take two of them, and optimize my route. I was assuming that time spent going between planets was the longest. It might be, but just barely.

Upon examining video 2 in more detail (I didn’t have a recording of my own), I logged timestamps and made a pivot chart:

So even if a bunch of packages are at the same location, the effort of walking them to the ship may not be that much worse than doing a extra flight. But theoretically, what would the sort be?

• Well, DESTINATION port MUST come after SOURCE port.
• Put the same port together if you can (sometimes you have to visit it twice)
• Group the planets together? One less QT hop

So I tried it – Here’s my work in progress –

However, the game crashed on me, and I lost all the packages. So there’s a good reason to get done with a simple mission first without thinking too hard about it. Oh, and Planetary maps at this link: https://www.reddit.com/r/starcitizen/comments/i3xhxr/3100ptu_sunrisesunset_triangulation_tool_and/

Ok, I might be off to try Mining thanks to Intergalactic Lan Party’s awesome playlist!

## Star Citizen, take my money!

I got a hankering to play Star Citizen and decided to jump in with \$55. I very quickly upped my pledge to .. i don’t even know where I’m at so far. Probably \$80. And its awesome.

Quick Myth: If you destroy your ship you are out real \$. Reality: currently everybody has insurance until they release, and when they release, there will be in-game insurance per ship that you can buy. Just like Elite: don’t fly without insurance!

Quick Myth: Need a kick ass computer. Reality: My i7/gtx1070 from 3-4 years ago with 16G ram total, runs it about okay.

Quick Myth: Its full of bugs because its alpha. Reality: yes; but if you call an elevator and you see a black emptiness, DONT STEP IN IT.

What I’ve done so far:

• Participate in a server-wide event which netted me almost 1/2 of a entry-level ship’s worth of in game money, while doing almost nothing other than fly around not knowing what to do. (The xenothreat thing over labor day weekend)
• Try to land my ship at a settlement on the dark side of a planet. The light I saw was the door light not a city light, i rammed into the settlement instead. Boom + Tresspassing = Crimestat.
• Served time in the penitentiary (14 minutes) for my crimestat. I did not try to escape.
• Almost run out of fuel flying a ship rental to join some action. Luckily I checked before I got past the halfway mark and could jump back to get some gas.
• Decide to trade in my first pledge ship for a better one (which has cargo space! And a bunk bed!)
• Trying to take out my first bounty, got there too late and somebody else got him.
• Trying to take out my first bounty, got jumped by a second bad guy. Ran away.
• Try to descend upon a bounty target at full speed in an asteroid field. I could not dodge the asteroid that showed up in front of me. Boom.
• Actually destroy a bounty myself with my gimpy hands.
• Do my first cargo mission, turns out I picked the one where I visit an abandoned powered off station, float around debris in zero G, somebody destroys my ship while I’m in the station and I have to stash the box and suicide and come back and get it after I respawn.
• EVA across a space station to get to the correct strut where I could turn in a delivery box to the right place.
• Do a “pick up recycle waste from 3 stations” mission. Turns out I need to land closer, because I have to hoof it on foot to get into the buildings to pick up the salvage WITH MY BARE HANDS. 2nd and 3rd station, i got a bit closer in my landing.
• Decide to upgrade my ship, find the websites which guide me to where the components can be bought, and try to go to Area 18 the big industrial complex plant … and could not find the space port. Had to go back up to look for it from afar, it was hidden behind some skyscrapers.
• Forget to look at trade routes and missed some great trading opportunities.

This game is amazing. Its everything I dreamed Elite could be. And the ship power management and all that stuff.. its like, “super realistic” + “computer control to make it seem more like a game”, but if you want you can switch off the “Coupled” mode and go raw. Just like Elite.

3 play sessions in, cannot wait for the next one. I need to investigate using a joystick and learn more about gimballed weapons and power distribution.

Loving the game SpritFarer. Resource gathering, with a cute little story line, until you read the back story, and then who cut the onions.

Playing it my way — i got too many people on the boat, restarted, and now I’m separating out “gathering” from “action”. Using a spreadsheet to guide me on what I need to get more of.

View only link to spreadsheet is here – as I satisfy things i cut and move them down. I thought about writing a helper app, but i don’t have that kind of free time.

Speaking of free time.. this is the first evening in i-don’t-know-when that i have had an hour or two to myself, AND i’m not exhausted and just need to veg out. Hence the post.

If i had all kinds of time, i could post about these technical things:

• Powershell script to automate connecting to cisco vpn
• Powershell script that runs a query against a database then checks if matching images exist and flags the ones that don’t.
• Surprise that you can’t connect to a Azure File System from Windows Server 2008R2 because SMB 2.0 vs 3.0. Even more reason to upgrade those servers. The plan is to move those to the cloud.
• The world of Epicor P21.
• Fun times working with a company called Heraflux and its chief geek David Klee. That guy knows his stuff, he’s the next level of whatever perfmon skills I used to have.
• Designing a task-tracking system – we’re separating out “popcorn” from “projects”. Sounds familiar.
• What happens when a SQL Server doesn’t have enough RAM: the 88G vs 8G typo problem. đź™‚
• Various small problem – small tool/feature wins. But that would reveal too much of the business.

I could also post about these other things:

• Color Changing Disney Pixar Cars .. the magic temperature is between 60 and 90 degrees, I think.
• Challenging a grandchild to eat – if you finish one of these three things, you can choose another: 1 pretzel, 3 grapes, 1 pepperoni.
• Outdoor pools might be simpler than I thought.
• Awesome channel – Perkins builder brothers, YouTube.
• I have seen Model Y in person and I still want it.

Be well!

## No Mans Skyâ€“Spreadsheet of Desire

Still playing it.   Iâ€™m actually finding the number of story missions .. relentless.  Like, stop bugging me, lemme go free play for a bit dangit.   OTOH, its definitely .. hey I have an hour to play .. lets go knock something out .. 5 things later .. oh, I never got around to the one I was going to do.

I do not have a head for remembering detail (anymore).   So, I came up with this â€“ I tried it in Google Sheets first, but they donâ€™t have good visualization of formulas, so Excel wins this round:

The plan is that the Calcs stuff (Column I onwards) is a bunch of rows where I can say â€śif I want 1 metal plate, you gotta have 50 ferrite dustâ€ť.   Unfortunately, in Excel, i canâ€™t sort this .. not the way it is.  This would be better done as a quick app.   Anyhoo, I can type in my inventory on things, and then it gives me how much I need of what, and using the visual tree above I can figure out the build order.

If I did it as an app, I could probably also factor in stuff like â€śhow much carbon to run the refinerâ€ť and â€śhow much carbon to run the mining laserâ€ť, although the latter would need some â€śhow good is your equipmentâ€ť estimates.   Could probably also try to calculate â€śhow much time would this takeâ€ť and optimization of which fuels to use â€śby costâ€ť vs â€śby time to acquireâ€ť.

If I did it as an app, I would load it with a text file which has a one-line language for describing things and what they are dependent on, for example â€śWarp Cell|Craft|Antimatter Housing:1,Antimatter:1â€ť.  That way the 2nd thing, if it were â€śRefineâ€ť, could then bring in additional costs associated with that.

## No Mans Sky

Started playing with the 1.5 update.   Fun so far..   went back because I was feeling lost, and mapped out the starting part of the game. Here it is, probably 85% consistent, till the point where you can leave the surface.   I was trying to do solid line = component, and dashed = influence, but that got a bit tangled.  (Thanks to draw.io for the auto-layout).

Its a pretty large game.  I still need to re-build a base, and then possibly get to hyperdrive.  Havenâ€™t done much archeology yet, nor have I done much stuff in space.

Donâ€™t know that Iâ€™ll play it too much longer, weâ€™ll see.

## 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)

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

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

### 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.

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.

### 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:

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:

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â€ť.
• â€ś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

I 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.

## Client / Server Update Loop

I made the client â€śin chargeâ€ť of this.  Starting in Javascript, the client requests an update from the server:

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:

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:

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:

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:

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

• 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):

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:

Doing some math:

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.

## 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)

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

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

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

(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.