Author Topic: Shrugger! Unity!  (Read 60325 times)

Offline Draco18s

  • Resident Velociraptor
  • Core Member Mark V
  • *****
  • Posts: 4,182
Re: Shrugger! Unity!
« Reply #60 on: October 04, 2013, 05:55:15 PM »
I'm going back to modelling the asthenosphere now; not much point in having a roguelike without a planet to stand on.
Ah, but there's a great deal of point in a roguelike where, by a few actions and some particularly remarkable RNG rolls, you no longer have a planet to stand on! :)

Portable Hole, meet Bag of Holding.

Offline Shrugging Khan

  • Hero Member Mark III
  • *****
  • Posts: 1,217
  • Neinzul Y PzKpfw Tiger!
Re: Shrugger! Unity!
« Reply #61 on: October 05, 2013, 04:19:13 AM »
Well, blowing up the planet is certainly an option.

Anyways, you're all probably a lot better than me at math; what kind of formula could I use to spawn stars in a higher density towards the galactic plane?

Right now, I just spawn them at the centre of the scene, give them a random rotation, and tell them to move back by a few thousand kilometres (inb4 realistic distances - I tried, but unity did not like).

Oh, and if the entire sky were treated as a hollow sphere with the stars tacked onto the inside, then how would it have to rotate for the relative motion to emulate the rotation of the planet (at any given latitude)?
« Last Edit: October 05, 2013, 04:25:05 AM by Shrugging Khan »
The beatings shall continue
until morale improves!

Offline Draco18s

  • Resident Velociraptor
  • Core Member Mark V
  • *****
  • Posts: 4,182
Re: Shrugger! Unity!
« Reply #62 on: October 07, 2013, 10:09:33 AM »
Anyways, you're all probably a lot better than me at math; what kind of formula could I use to spawn stars in a higher density towards the galactic plane?

If we assume that you're placing stars along an X and Y axis, where X is longitude and Y is latitude (so Y90 is the north pole  and Y-90 is the south pole), then something like this:

Y = random(90) - random(90);

That'll get you a bell curve towards the equator plane (which is roughly where the galactic plane is).

Quote
Oh, and if the entire sky were treated as a hollow sphere with the stars tacked onto the inside, then how would it have to rotate for the relative motion to emulate the rotation of the planet (at any given latitude)?[/b]

This is where local rotation comes in.  Rotate the sphere by the latitude value, then use your localRotation.eulerAngles to spin it along its vertical axis (y?)

Offline Shrugging Khan

  • Hero Member Mark III
  • *****
  • Posts: 1,217
  • Neinzul Y PzKpfw Tiger!
Re: Shrugger! Unity!
« Reply #63 on: October 08, 2013, 11:07:26 AM »
Thankee! I'll make good use of that info.

PS: Other little question - when you put a Reaction wheel on a spacecraft (in space) but mount it far away from the centre of mass, how will that affect the rotation of the craft?

PPS: Nevermind, I think I found out. The reaction wheel will be less efficient the further out it is, won't it?
« Last Edit: October 08, 2013, 11:44:53 AM by Shrugging Khan »
The beatings shall continue
until morale improves!

Offline Draco18s

  • Resident Velociraptor
  • Core Member Mark V
  • *****
  • Posts: 4,182
Re: Shrugger! Unity!
« Reply #64 on: October 08, 2013, 01:16:57 PM »
PPS: Nevermind, I think I found out. The reaction wheel will be less efficient the further out it is, won't it?

I don't know what a reaction wheel is, but generally speaking in physics, the farther away from the center of rotation your force is being applied, the more effect it has.

It's called Mechanical Advantage (specifically: a lever).

Offline Shrugging Khan

  • Hero Member Mark III
  • *****
  • Posts: 1,217
  • Neinzul Y PzKpfw Tiger!
Re: Shrugger! Unity!
« Reply #65 on: October 08, 2013, 02:29:30 PM »
That would be my usual understanding, too. But the thing with machines in a vacuum is that you can't work with leverage. Spacecraft usually use flywheels for precision work on their attitude (else: manoeuvring thrusters); see http://en.wikipedia.org/wiki/Reaction_wheel for more information on that one.

The beatings shall continue
until morale improves!

Offline Draco18s

  • Resident Velociraptor
  • Core Member Mark V
  • *****
  • Posts: 4,182
Re: Shrugger! Unity!
« Reply #66 on: October 09, 2013, 10:15:34 AM »
Oh!

I don't know the answer to your question, but I do understand how they work.  They work on the principle of action-reaction.  It's not so much that they make the spacecraft rotate by spinning them, but rather the change in the spin on them changes the spin on the spacecraft.

I don't think you'd actually have to worry about that level of detail in a simulation.  Reaction Wheels are for very very tiny adjustments.

Offline Shrugging Khan

  • Hero Member Mark III
  • *****
  • Posts: 1,217
  • Neinzul Y PzKpfw Tiger!
Re: Shrugger! Unity!
« Reply #67 on: October 23, 2013, 07:24:15 AM »
On an unrelated note; do I have any physical (CPU / RAM) disadvantages from declaring public variables, objects or methods, as opposed to nonpublic ones?
The beatings shall continue
until morale improves!

Offline Draco18s

  • Resident Velociraptor
  • Core Member Mark V
  • *****
  • Posts: 4,182
Re: Shrugger! Unity!
« Reply #68 on: October 23, 2013, 08:24:06 AM »
On an unrelated note; do I have any physical (CPU / RAM) disadvantages from declaring public variables, objects or methods, as opposed to nonpublic ones?

No.  Public/private is just error checking preventing you, the coder, from changing values you shouldn't be.
(Not entirely true, there are differences at runtime, but the gain/loss of resources is unbelievably tiny; takes upwards of 10 million accesses to accumulate 1 ms of lost processor)

Offline keith.lamothe

  • Arcen Games Staff
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 19,505
Re: Shrugger! Unity!
« Reply #69 on: October 23, 2013, 08:41:34 AM »
Yea, I suggest making everything private unless it needs to be broader, just to avoid unintentional access/modification from other classes.

It isn't hypothetical; a lot of my bugs are actually from braindead typos like picking the wrong field.  Though most of those I catch in internal testing before they sneak out.

On a similar note, I find it preferable to not do getter/setters except when the associated logic is complex or the field in question really needs the protection.  Saves coding time and cpu time.  Of course, this is from my perspective of "only an Arcen programmer will ever maintain this code", which is radically different than writing a library or whatever.

That said, the "readonly" modifier is great for fields you don't plan to change after construction.  We have tons of those in our enum/typedata-pattern classes.  Granted, I've only _once_ accidentally modified a typedata field that I meant to access, but I don't think Space Tanks have ever quite forgiven me for intermittently revoking their ability to enter transports.  During the game.  ALL Space Tanks.  Everywhere.
Have ideas or bug reports for one of our games? Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Shrugging Khan

  • Hero Member Mark III
  • *****
  • Posts: 1,217
  • Neinzul Y PzKpfw Tiger!
Re: Shrugger! Unity!
« Reply #70 on: October 23, 2013, 10:41:00 AM »
I also pretty much dropped the teaching of "Getters and Setters everywhere!" (as taught at our university), and only use them where it actually provides necessary functionality.

But alright, thanks gents. I'll stop feeling guilty about all those public values, then.
The beatings shall continue
until morale improves!

Offline Draco18s

  • Resident Velociraptor
  • Core Member Mark V
  • *****
  • Posts: 4,182
Re: Shrugger! Unity!
« Reply #71 on: October 23, 2013, 10:50:35 AM »
I also pretty much dropped the teaching of "Getters and Setters everywhere!" (as taught at our university), and only use them where it actually provides necessary functionality.

Pretty much.  For a semi-RPG I built I was performing some cryptography on the player's stats, so that it was harder to use CheatEngine to access and modify the values.  So I used getter/setter to translate between the obfuscated value and the actual value.

Minecraft also has getters for a lot of values simply because it allows for a lot of power in terms of future or mod content.  So you can have a block that looks different based on side and metadata, or items that have different icons based on NBT data.

But in general it's probably fine to skip them if you don't see a use for it.

Offline windgen

  • Jr. Member
  • **
  • Posts: 51
Re: Shrugger! Unity!
« Reply #72 on: October 24, 2013, 04:35:32 AM »

> I suggest making everything private unless it needs to be broader, just to avoid unintentional access/modification from other classes.

Python has a good solution to this dilemma.  Instead of a "private" keyword that gives you a compiler-enforced "this field can't be accessed from other classes," the Python Way is to use an underscore in front of the names of fields that are intended to be internal as a strong suggestion that outside classes shouldn't use it.

When you get right down to it, sometimes it's good to be able to access private fields if you really need to.  The underscore tells you "This isn't intended to be part of the public API, so it may break in later releases without warning, and it's also probably totally undocumented so you ought to read the code to be sure it does what you think it does."

There are countless times I've wanted to access a private field in some library, and I have to either re-implement that part of the library, or make my own fork, for no good reason other than the library author made the field private because they weren't creative enough to envision my use case.

Then again, if you're writing application code that's not going to have any downstream users, "private" doesn't matter so much, because if you discover later that you need to access it, you can always just change the declaration yourself.

Offline Draco18s

  • Resident Velociraptor
  • Core Member Mark V
  • *****
  • Posts: 4,182
Re: Shrugger! Unity!
« Reply #73 on: October 24, 2013, 08:53:28 AM »
There are countless times I've wanted to access a private field in some library, and I have to either re-implement that part of the library, or make my own fork, for no good reason other than the library author made the field private because they weren't creative enough to envision my use case.

Reminds me of the ItemStack sensitive version of getIcon for Minecraft, which was marked as Final.

http://www.minecraftforge.net/forum/index.php/topic,12446.0.html

Just read Lex's replies when I tried to ask for Forge to un-finalize the function.

Three days later someone else made the same suggestion and the change was made.

Offline keith.lamothe

  • Arcen Games Staff
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 19,505
Re: Shrugger! Unity!
« Reply #74 on: October 24, 2013, 10:02:19 AM »
Yea, my tendency towards "private" was in the context of writing code that's entirely internal to Arcen.

If I ever write library code again, many things will need to be different :)  Though there I would probably expose it through getter/setter stuff.
Have ideas or bug reports for one of our games? Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!