Sunday, December 31, 2017

pronouns - Difference between myself and by myself


Could you please explain me which option should I use?



I would like to have a green house with rare plants from all over the world. I could take care of them (myself / by myself)?




And why?



Answer



They're both correct, but they mean slightly different things.


In "I could take care of them myself", the myself emphasizes that I'd be the one taking care of them, as opposed to someone else. It doesn't really change the meaning of the sentence, it just emphasizes a certain aspect of it.


In "I could take care of them by myself", the by myself means "without help from others".


word usage - Which to use, 'washroom' or 'restroom'?


I'm from India; in our office we refer toilet to 'Wash-room' and 'Rest-room', which is the correct form to use and if there is a difference, what is the difference between the two words?




Saturday, December 30, 2017

physics - How do I set angular velocity/torque so that it's pointing to velocity/direction?


Right now, when I spawn a shootable object, it goes like this:



enter image description here


Because I just set it's angle to this:


float aimAngle = (float) Math.atan2(velocity.y, velocity.x);
bullet.setBodyAngle(aimAngle);

I want it to be like this:


enter image description here


I think I should use angular velocity or torque, but I have no idea how. I can't just set it's angle like in previous code every frame, because it makes physics collisions glitch.




complementation - When to omit "to" with infinitives


I want you to feel better
I want you feel better


That was the right thing to do
That was the right thing do



when somebody challenges you to dance
when somebody challenges you dance


I'm not telling you to go around
I'm not telling you go around


you are trying to make us not practice
you are trying make us not practice


just try to relax and breath
just try relax and breath


What does to point to in the sentences? Is it OK if I remove to in the above sentences?




Can a material noun be countable?


I get stuck to differentiate between some common and material noun.


Can material noun be countable?


Are egg, earth, nail, sun and moon material nouns?


when can I use article in front of a material noun?


I am not a native speaker.



Thanks in advance.




prepositions - Using “before” for relationships other than time


As I read books and posts on G+, I am confused from using of some adverbs of place and time.


And why? Because some ones I have paired with time (for example before) are used as adverb of place.


For example



The Church of Our Lady Before Týn



But in my opinion it should be



The Church of Our Lady in the front of Týn




because Týn is a place and the church stands near this place — and really it stands in front of it, in the direction of the Old town square (Staroměstské náměstí).


So, what are the rules for using of before? Is the first translation correct?




word usage - Using 'on' with any social media platform


I normally use 'on' with mentioned site whereas I would like to know the main reason behind it. I am wondering that should I always use 'on' with related sites?


To put it more clearly,



I saw your message on [ Internet | Facebook | Twitter | LinkedIn | and so on].


I wrote you another comment on [ Internet | Facebook | Twitter | LinkedIn | and so on].



How about 'in'?, would 'in' be used for the same purpose?



Answer




This is tricky (+1) but being a mouse potato, I'll try my best for this!


We prefer using on when it is all about the site or the platform or for such matter even the portal. It's bigger. You see something on the Internet and so the sites on it (not just restricted to social media). I read that on the BBC Website.


On the other hand, when you write or read something within some block, you use in. You always write your message in your email and you see someone's message in your inbox. It's within that particular frame, block or whatever you say.


As a general rule, on is for some surface and in is for something inside. With a little adjustment, we can make this out. On the website and in the email.


Additional but maybe, a useful note: There could be change in the website. However, that's from a webmaster's view. That's again because when the change happens, it happens within the frame provided (Say WordPress or HTML). One may say... There is a change (to be done) in our homepage -put this element there.


On the other hand, if the visitors are talking about a change, for them, it's the change on the website. Because again, what I said, for them, it's just happening over the surface! One may say ... I see the change on this website. The element which was here is here now...


Can the Khmer Rouge be a singular noun?


In the four years that the Khmer Rouge ruled Cambodia, it was responsible for one of the worst mass killings of the 20th Century.


I am surprised by the usage "it" ("it was responsible") in my sentence, where "it" here stands for the Khmer Rouge that were/was the ethnic and political group of many people.



Answer



This is an example of the semantic number, and the grammatical number not being the same



You may use "it" and "was", to agree with the grammatically singular "Khmer Rouge", or you may use "they" and "were" to agree with the semantically plural "Khmer Rouge". Both are correct.


For example, from TIME:



Simultaneously, the Khmer Rouge were planning the steps necessary for a radical shift to an agrarian society



Or Britania.com



The Khmer Rouge was the strongest partner in this coalition, which carried on guerrilla warfare until 1991.



In American English it is more common to follow the grammatical number (Americans would be more likely to say "The government is...") British speakers are more likely to follow the semantic number (Britons are more likely to say "the government are"). But this is not a hard rule, and there is a lot of variation on both sides of the Atlantic.



It can be used to add nuance "The Khmer Rouge was..." suggests that it was a single body that acted like a unit, rather than an association of different people.


Friday, December 29, 2017

xna - Ball Physics : Bounce height altered by elasticity of ball and bounce surface



I have created a bouncing ball simulator using XNA and I am happy with my use of gravity, acceleration, change of direction and friction/spin.


However, I am now at a stage where I would like to define my ball as being made of a different material, subsequently meaning that the "bounce height" will be different depending on the elasticity of the material.


Ultimately, I will also want differing types of bounce surfaces as well. This will mean that I could have bounces as varied as:



  • Rubber ball on concrete.

  • Ping-pong ball on wood.

  • Concrete ball on mud.

  • Etc., etc.


My question is; How should I alter my bounce height depending on the material(s)?



I have found some information about Young's Modulus of Elasticity but I would be grateful if someone could advise as to how I use this (or another) value as a ratio in my "bounce" calculation.


Thanks in advance and please let me know if you would like to know anything else.



Answer



The bounce is implemented by inverting the Y component of velocity, when the ball collides with the ground.


Ball.Velocity.Y *= -1 * COEFF;


If the COEFF is 1, the ball will have a "perfect" bounce, i.e. no energy will be lost. If COEFF is 0, the ball won't bounce at all. Put a fractional value between 0 and 1 in COEFF to get a realistic bounce.


Now you want to implement two "materials". So you could have two coefficients and calculate COEFF as follows:


COEFF = BALL_COEFF * SURFACE_COEFF


"which" as relative determiner?


Sentence 1: I was told my work was unsatisfactory, at which point I submitted my resignation.


Sentence 2:Sometimes you may feel too frail to cope with things, in which case do them as soon as it is convenient.


I am confused with "which" in the above two sentences. Does it serve relative determiner, rather than relative pronoun? Does "which point" in the first sentence stand for "I was told my work was unsatisfactory"?Does "which case" in the second sentence stand for "sometimes you may feel too frail to cope with things"?


Thank you in advance!





tense - "May" is not possible in the past?


Do I always have to use might when talk about the past and may does not belong there?




I may beat him now / tomorrow.


I may might beat him a year ago.




Answer



The past-tense forms of the modal auxiliaries can, may, shall and will are always used in sentences with past reference. But they are used in different ways. That is because these verbs have dual uses which present a special problem.




  1. Just like the past-tense forms of other verbs, they are used to represent present-tense forms 'backshifted' into the past:


     You are going to fight. I think     You were going to fight. I thought   

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    you can beat him. ⇨ you could beat him.
    you may beat him. ⇨ you might beat him.
    ?you shall beat him. ⇨ you should beat him. (this use of 'shall' is dying)
     you will beat him. ⇨ you would beat him.


  2. But these auxiliaries, unlike ‘lexical’ verbs also employ their past-tense forms with present or future reference. This is particularly visible in so-called 'first conditional' constructions: non-past conditionals in which the condition is regarded as possible:


     If the fight is fair, I think      If the fight is fair, I think 
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    you can beat him. AND you could beat him.
    you may beat him. AND you might beat him.
    you shall beat him. AND you should beat him.
    you will beat him. ? you would beat him.
    (This one's a bit iffy; but it would certainly be acceptable
    in a context like "If the contests are fair, I think you
    would beat him sixty times out of a hundred.")

    In many cases, the difference between 'present-reference/present-tense' and 'present-reference/past-tense' use is so slight that the simple past form may be used for either when the sentence is backshifted to past-reference—for instance, in a backshifted ‘first conditional’ (we might call it a ‘one-and-a-halfth conditional’):




    Back in '06 I thought that if the fight was fair you could / might / should / would beat him.



    In the case of higher-level conditionals, however—what are sometimes called counterfactual or irrealis conditionals, in which the condition is regarded as impossible—this does not suffice. These constructions must be strongly marked with a past-tense form.


    When an irrealis sentence has present reference, the so-called ‘second conditional’, this marking is accomplished by casting the verb into a past-tense form undifferentiated for person, what used to be called the past subjunctive:



    If the fight were fair, you could / might / should / would beat him.



    But now all the verb sequences have been cast into past-tense forms. How, then, do you backshift this sentence into past reference?


    The workaround which English has evolved is to mark both sequences with a HAVE + past participle construction. This marker is placed on the finite verb which heads each verb sequence if it is capable of taking it. But modal verbs are 'defective', they have no past participles with which this marker can realized; so the marker is moved to the next verb in the sequence:


    PRESENT: If the fight [  were  ] fair you [might    beat    ] him, but it’s not;

    past ↓ ↳ →
    marker ↓ (oops!) ↴
    PAST: If the fight [had been] fair you [might have beaten] him; but it wasn’t.


The last sentence looks like a perfect construction, but it’s not. It's the form taken by a subjunctive past with past reference. You must be careful to distinguish this from such sentences as:



He may have won; I'm not sure and its past version
He might have won; I wasn't sure.


He may have been cheated; I'm not sure and its past version

He might have been cheated; I wasn't sure.



These are true perfect constructions, with current (past or present) reference, designating his current state of "championship" resulting from his past action winning or of "cheatedness" resulting from somebody's past action of cheating him. They are cast into infinitive form because they are headed by the modal MAY, indicating uncertainty. They are thus equivalent to:



It is possible that he has won ... and
It was possible that he had won.


It is possible that he has been cheated ... and
It was possible that he had been cheated.



unity - Why is the IntelliSense not working when I open a new script in Visual Studio?


The strange thing is that opened scripts or newly opened ones are working fine. It's the new created C# scripts that are not working.


With not working, I mean the MonoBehaviour is not in light blue color it's in black color. In this screenshot I took, I marked it with a red circle.


Not light blue


What have I tried so far? I have closed Visual Studio and started over again. Since it didn't solve it, I closed the unity editor and started it over again, to no avail.


I pressed 'clean solution', I pressed 'rebuild solution', I pressed 'build solution'.


What else can I do ? And why are the other scripts working fine? If I type gameo...it will auto complete it to GameObject but in this specific script it's just not working.


This is a screenshot of the editor. I have in the Hierarchy a Ladder object. In the Assets I created a folder name Ladder and a script name Ladder. But this Ladder script is not working.


Editor


This is the Ladder script and this script was working before but once I created another script inside the ladder folder name Raise empty script the Raise script didn't work and now the Ladder is not working either. But other scripts are working fine.



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ladder : MonoBehaviour
{
public Transform charcontroller;

private bool inside = false;
private float heightFactor = 3.2f;


private void OnTriggerEnter(Collider other)
{
inside = true;
}

private void OnTriggerExit(Collider other)
{
inside = false;
}


private void Update()
{
if (inside == true && Input.GetKey("w"))
charcontroller.transform.position += Vector3.up / heightFactor;
}
}


prepositions - experience at/in/on high school levels


Are the prepositions at, in, on interchangeable here? If yes, do they all mean the same?




I have student-teaching experience at/in/on (all) high school levels.




Answer



I think at is your best choice; that's the preposition usually used in that context.


More specifically, I would use at, because we usually say at all levels:



I have student-teaching experience at the high school level.



It may be worth noting that, at least in the U.S. educational system, all of high school is considered one level, consisting of four grades. So, this is the way I'd recommend saying this (depending on what grades you taught):




I have student-teaching experience at the high school level. [i.e., I taught students in grades 9 - 12]
I have student-teaching experience in all high school grades. [i.e., students in grades 9, 10, 11 & 12]
I have student-teaching experience at both the high school and middle school level. [i.e., students in grades 9 - 12, as well as students in grades 6 - 8]



However, that might be different in other countries.


One other thing worth mentioning: when we use a past tense verb with the phrase "in high school," that usually indicates an activity we did as a student.



I took geometry in high school.



So, I would avoid, "I had my student-teaching experience in Chattanooga High School" (even though it's not grammatically incorrect), because that could be interpreted to mean that you did student teaching while you were a high school student. It would be much better to say:




I had my student-teaching experience at Chattanooga High School.



Thursday, December 28, 2017

how to use 2D noise with a voxel sphere


I have a bunch of voxels, lets just say 64x64x64, that I use to create a sphere/planet. This works very well, but once I try to apply noise to create a more interesting terrain things go wrong.


3D noise works fine, but I don't always want to create terrain with caves, overhangs etc, so I figured in those cases 2D noise would be a good solution, but I can't figure out how to use it correctly.


I tried this, where pos (world position) is a float3 and x and y are the input values for the noise function:


float x = math.acos(pos.z / math.length(pos));
float y = math.atan(pos.y / pos.x);


That results in a very noticeable seam along one axis and pinching at the poles though.


Is there any way I can convert my 3D world position into 2D coordinates, so that the noise function (Perlin or Simplex) will produce a seamless result without pinching? I don't mind in the least if this causes symmetry or repeating features.



Answer



There is no perfect way to map the surface of a sphere to a flat plane - you always get seams or stretching/pinching somewhere. This is why map projections are such a rich subject - every one offers different trade-offs that are good for some uses and less good for others.


A better route for your purposes is probably to continue using your 3D noise, but sample just a 2D manifold out of it:


GetSphereSurfaceNoise(float3 worldPosition, float3 center) {
float3 surfacePosition = normalize(worldPosition - center) * noiseRadius;
return GetNoise(surfacePosition);
}


This ensures all samples along a ray radiating out from the center of your sphere get the same noise value, so you can raise/lower whole columns of terrain without creating caves/overhangs, and the result will be continuous & seamless all around your sphere.


Tuning the noiseRadius parameter lets you control the density of the noise (scaling up or down the 2D shell you're sampling from in noise space)


c# - AABB collision resolution issues


I'm trying to make a character collide with some tiled terrain.


I have an issue with the collision resolution, and after days of shooting in the dark ant not finding any relevant help online, I'm no closer to working collision resolution.


I can detect if the player is colliding with the tiles, but I can't figure out how to properly resolve the collision.


I have is so gravity is only applied when there is no collisions in the downward direction, and I have set it so that the proper velocity resolution, so that if I collide with the ground, I don't go through it, but I still go a few pixels into the tile if going at high velocities, and for some reason, if I'm colliding with a surface whose normal is along the x axis (floors and ceilings) It decides that I'm also colliding on the left and right sides as well, and I don't collide with vertical walls at all.


I should note that I'm using MonoGame 3.4.



Physics update code for character


public void Update()
{
Position += Velocity * TimeHandler.DeltaTime;

//TODO: add tile collision based on the entity.world property
var tiles = entity.World.Tiles;

int minTileX = (int)Math.Floor (Bounds.MinX);
int maxTileX = (int)Math.Ceiling (Bounds.MaxX);

int minTileY = (int)Math.Floor (Bounds.MinY) - 1;
int maxTileY = (int)Math.Ceiling (Bounds.MaxY) - 1;

bool collidedNegY = false;
for (int x = minTileX; x <= maxTileX; x++)
{
for (int y = minTileY; y <= maxTileY; y++)
{
bool kKeyDown = Keyboard.GetState ().IsKeyDown (Keys.K);
if (kKeyDown)

tiles.SetID (1, x, y);
bool jKeyDown = Keyboard.GetState ().IsKeyDown (Keys.J);
if (jKeyDown)
tiles.SetID (0, x, y);

AABB tileAABB = new AABB (new Vector2(x, y), new Vector2(1f, 1f), new Vector2(0f, 1f));
//CollisionInfo info;
if (tileAABB.Check (Bounds))
{
if (tiles.GetID (x, y) == 0)

continue;

Vector2 collisionDirection = tileAABB.Position - Bounds.Position;
bool xIsRight = collisionDirection.X > 0;
bool yIsUp = collisionDirection.Y > 0;
bool differentX = xIsRight == Velocity.X > 0;
bool differentY = yIsUp == Velocity.Y > 0;

if (differentX)
{

Velocity.X *= 0f;
if (Bounds.MaxX > tileAABB.MaxX)
{

}
if (Bounds.MinX < tileAABB.MinX)
{

}
}

if (differentY)
{
Velocity.Y *= 0f;
if (Bounds.MaxY > tileAABB.MaxY)
{
collidedNegY = true;
}
if (Bounds.MinY < tileAABB.MinY)
{


}
}
}
}
}
if(!collidedNegY)
{
//apply gravity
Velocity.Y -= entity.World.Gravity * TimeHandler.DeltaTime;
}


Bounds.Position = Position;
}

AABB class:


public struct AABB
{
private Vector2 min;
private Vector2 max;
private float y;

private float x;
private float width;
private float height;
private Vector2 offset;

//position
public Vector2 Position
{
get
{

return new Vector2 (x, y);
}
set
{
UpdateBounds (value.X, value.Y);
}
}

public Vector2 Size
{

get
{
return new Vector2 (width, height);
}
set
{
UpdateBounds (x, y, value.X, value.Y);
}
}


public float MinX
{
get
{
return min.X;
}
}
public float MinY
{
get

{
return min.Y;
}
}
public float MaxX
{
get
{
return max.X;
}

}
public float MaxY
{
get
{
return max.Y;
}
}

public float Width

{
get
{
return width;
}
set
{
UpdateBounds (min.X, min.Y, value, height);
}
}

public float Height
{
get
{
return height;
}
set
{
UpdateBounds (min.X, min.Y, width, value);
}

}

//update
private void UpdateBounds(float x, float y)
{
this.x = x;
this.y = y;
min = new Vector2 (x + offset.X, y + offset.Y);
max = new Vector2 (min.X + width, min.Y + height);
}

private void UpdateBounds(float x, float y, float width, float height)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
min = new Vector2 (x + offset.X, y + offset.Y);
max = new Vector2 (min.X + width, min.Y + height);
}


//constructors
public AABB(Vector2 pos, Vector2 size, Vector2 offset)
{
this.x = pos.X;
this.y = pos.Y;
this.width = size.X;
this.height = size.Y;
this.offset = offset;
this.min = new Vector2(pos.X + offset.X, pos.Y + offset.Y);
this.max = new Vector2 (min.X + size.X, min.Y + size.Y);

}

//checking
public bool Check(AABB b)
{
if (this.max.X < b.min.X || this.min.X > b.max.X)
return false;
if (this.max.Y < b.min.Y || this.min.Y > b.max.Y)
return false;


return true;
}

public static bool Check(AABB a, AABB b)
{
return a.Check (b);
}
}


flash - Fixed timestep with interpolation in AS3


I'm trying to implement Glenn Fiedler's popular fixed timestep system as documented here:


http://gafferongames.com/game-physics/fix-your-timestep/


In Flash. I'm fairly sure that I've got it set up correctly, along with state interpolation.


The result is that if my character is supposed to move at 6 pixels per frame, 35 frames per second = 210 pixels a second, it does exactly that, even if the framerate climbs or falls.


The problem is it looks awful. The movement is very stuttery and just doesn't look good.



I find that the amount of time in between ENTER_FRAME events, which I'm adding on to my accumulator, averages out to 28.5ms (1000/35) just as it should, but individual frame times vary wildly, sometimes an ENTER_FRAME event will come 16ms after the last, sometimes 42ms.


This means that at each graphical redraw the character graphic moves by a different amount, because a different amount of time has passed since the last draw. In theory it should look smooth, but it doesn't at all. In contrast, if I just use the ultra simple system of moving the character 6px every frame, it looks completely smooth, even with these large variances in frame times.


How can this be possible? I'm using getTimer() to measure these time differences, are they even reliable?




About the idiom in Hindi (चुल्लू भर पानी में डूब जा) that literally translate 'Go, commit suicide"!


There's an idiom in Hindi




चुल्लू भर पानी में डूब जा



This literally translates - go, die/commit suicide!


The context where it is used -


This phrase is always used in a sarcastic way advising someone to go, die or commit suicide because they could not perform at all in the field they master.


Example -


If I am a pro at the language English and if I cannot explain what is verb, you will say, "चुल्लू भर पानी में डूब जा".


The closest phrase I can think of is Couldn't you explain what is verb? Shame on you. But this is much milder than the idiom in Hindi. What else it could be? Go, hang yourself? Is it valid and understood in the context?


Any suggestions?




american english - combine two sentence into one sentence


I want to combine two sentence into one sentence. But I'm not sure what whether correct or not.



  1. I have been honeymoon trip to Hongkong.

  2. It was my last trip.



1+2: I have been honeymoon trip (that) was my last trip to HongKong.


Is this correct? Or is there any other options? How about to use 'was' make sentence at #1 instead 'have pp'? I'm not sure what is correct using tense?


How about this for else option, instead #1. 1-1 I did honeymoon trip to Hongkong. 2-1 It was my last trip. 3-1 I did honeymoon trip (that) was my last trip to hongkong.



Answer



Sentence 1 is not correct. It needs "on", or other wording.


I have been on my honeymoon trip to Hong Kong. I was on my honeymoon trip to Honk Kong. I went to Hong Kong on my honeymoon.


Sentence 2 uses "last". Do you mean "latest,most recent", or "last, I will never go again."


Putting the two main sentences together


I have been on my honeymoon which was my latest trip to Hong Kong.


I was on my honeymoon trip to Hong Kong ; it was my last trip. (Fancy semi-colon) On my last trip to Hong Kong I went on my honeymoon. My last trip to Hong Kong was my honeymoon.



architecture - How to design a replay system


So how would I design a replay system?


You may know it from certain games like Warcraft 3 or Starcraft where you can watch the game again after it has been played already.



You end up with a relatively small replay file. So my questions are:



  • How to save the data? (custom format?) (small filesize)

  • What shall be saved?

  • How to make it generic so it can be used in other games to record a time period (and not a complete match for example)?

  • Make it possible to forward and rewind (WC3 couldn't rewind as far as I remember)




Wednesday, December 27, 2017

mathematics - Vector problem: which one is the left / centre / right one?


In aviation, runways are named according to their magnetic orientation seen from the pilot's perspective. For example: a strip of asphalt oriented along the east-west axis will be named 9 for the pilot coming from west (east is at 90° from North) and 27 for a pilot coming from east (west is 270° from North).


enter image description here


When several runways have the same orientation, the naming convention uses letters L/C/R for distinguishing between the Left/Centre/Right ones (look at the 22 runways in the capture above).


In the game I'm coding, I chose to describe runways by the following three attributes:



  • Orientation (between 0° and 180°).

  • Position of their geometrical centre relative to the aeroport one.

  • Length



With this data I'm able to generate all the touchdown points and give them the correct number, but I can't find a straightforward method to assign the correct letter, as I could not think to a straightforward way to mathematically determine which one is "left/centre/right" from a "landing pilot's perspective".


So the question is:



Is there a simple, straightforward vector formula that - given two parallel vectors pointing in the same direction - will return the leftmost (or rightmost) one?



Please note that this question is really about the straightforwardness of the formula, as I already found a non-straightforward way to get the result, but I would like to find a more elegant way to solve the problem.


Many thanks in advance for your expertise and contributions!



Answer



Of course there is. Compute the determinant of the orientation vector of the runways and the vector from one runway centre to another, the result will be positive or negative depending on which runway are to the right of the other.


Calculation of determinant for a pair of 2D vectors:



Det(A,B) = Ax*By - Ay*Bx

There is a load of other stuff one can learn about the use of determinants, but for this purpose it's all you need to know.


Edit, same thing in different words:
Compute the dot product of the orientation vector of the runways and the tværvector of the vector from one runway centre to another, the result will be positive or negative depending on which runway are to the right of the other.


DotProduct(A,B) = Ax*Bx + Ay*By

A tværvector is the rotation of a 2D vector 90 degrees counter-clockwise. The tværvector T of A is calculated as follow:


Tx = -Ay
Ty = Ax


Edit, I guess I should try to explain why this works.
The result of a dot product is equal to the product of the length of the two vectors, by the cosine of the angle between them. Since lengths are always positive and cosine is positive for angles in the range ]-90 deg; 90 deg[ the dot product is positive for acute angles, and negative for obtuse angles.


Imagine two parallel lines and a vector from any point on line 1 to any point on line 2, this vector may point in any direction within a 180 degrees arc, except from the two extremes. If we rotate this vector 90 degrees we also rotate the arc 90 degrees. This rotated arc is positioned exactly so that a vector parallel to the lines will either have an acute angle to all vectors within the arc, or an obtuse angle to all of them, depending on the position of the lines and the direction of the vector. Since the dot product works as an acute/obtuse test it can be used to tell whether a line is to the right of left of another, depending on which direction you look at them.


articles - most/most of/ the most of


Are all of the following sentences correct? Is there any difference in their meaning?



  • Most birds can fly.

  • The most of birds can fly.

  • Most of birds can fly.




Answer



Use most to refer to a quantity of an unspecific group. We use most when we are speaking in general and do not have a specific group of people or things in mind:





  • Most students ask questions.




  • All students want A's.





  • Many students want less homework.




  • A few students had to stay for a review session. (some)




  • Few students had to stay for a review session. (not many)






Use most of the X to refer to a quantity of a specific group. Note the expression includes a phrase defining the number to a specific group:





  • Most of the students in my English class ask questions. (most - specific to those who are in my English class)




  • All of the students in my class want A's. (all - specific to those who are in my class)





  • Many of the students in my school want less homework. (many - specific to those who are in my school)




  • A few of the students who have low grades had to stay for a review session. (a few - specific to those who have low grades)




  • Few of the students who have low grades had to stay for a review session. (few - specific to those who have low grades)






So it means only your first example is correct. But it is correct if for example you write:



Most of the birds which are living in highlands can fly.



About The most I think it refers to the rules of the and there is nothing more.


word usage - Using 'may' and 'might' in AmE


Do the following sentences sound natural in formal AmE speech:






  • You may go now if you want to.




  • You might go now if you want to.





I think both of them are correct, but the latter is far more formal or rather literal. Though I doubt about this opinion.




meaning - What does the word "it" mean?




Even if determinism isn't true for everything that happens—even if some things just happen without being determined by causes that were there in advance—it would still be very significant if everything we did were determined before we did it. However free you might feel when choosing


[Thomas Nagel - What does it all mean? p.52]



What does the word "it" mean?




Tuesday, December 26, 2017

meaning - What does "between drink and dignity" mean?


I'm reading one book now (Black Arrow, by Robert Louis Stevenson), and I found one sentence (or, rather, part of a sentence) I can't understand.



“What!” bawled one of the grumblers, “he carrieth us to seaward!”



“’Tis sooth,” cried another. “Nay, we are betrayed for sure.”


And they all began to cry out in chorus that they were betrayed, and in shrill tones and with abominable oaths bade Lawless go about-ship and bring them speedily ashore. Lawless, grinding his teeth, continued in silence to steer the true course, guiding the Good Hope among the formidable billows. To their empty terrors, as to their dishonourable threats, between drink and dignity he scorned to make reply.



I've checked original translation in my language, and it is (almost literally): Sometimes he is drunk, and when he is drunk, he is very proud. So he scorned to make [a] reply.


Is this translation correct? If yes, can you please give some examples with word "between" with same meaning? Or is it just some sophisticated figure of speech which I hardly can meet in other place except this book?



Answer



You've got the right idea. The between drink and dignity simply means that "the combination of his being drunk and feeling too much pride" caused him to refuse to reply to their threats. "Between" = "the combination of".


Simple past vs Perfect Past


A) He was arrested by police. b) He had been arrested by police.


In newspaper reporter want to tell about past event that has already happened.


In above statements Reporter conveyed same meaning, that police have arrested criminal and he is still in there custody.


I am aware that above sentence are In past Tense i.e. former is in simple past and later is in Past perfect. And also in Passive voice



My question is that why reporter purposely used was and had been in sentence? instead of that he could have used Present perfect. e.g he has been arrested by police.


Also Some times reporters does not use simple past before using past perfect.


e.g. He had been arrested by police when I was reached on the spot.




Monday, December 25, 2017

"Only the masochist would choose to study Russian" or "Only a masochist would choose to study Russian"? (use of articles in generic noun phrases)


From English is not Normal, by John McWhorter:




If someone were told he had a year to get as good at either Russian or Hebrew as possible, and would lose a fingernail for every mistake he made during a three-minute test of his competence, only the masochist would choose Russian – unless he already happened to speak a language related to it.



Could we substitute "a" for "the" here? Both "the masochist" and "a masochist" are generic noun phrases.



If someone were told he had a year to get as good at either Russian or Hebrew as possible, and would lose a fingernail for every mistake he made during a three-minute test of his competence, only a masochist would choose Russian – unless he already happened to speak a language related to it.



Would this be okay? If not, why?



Answer



I'm another native speaker who can attest that a masochist is fine here.



Since the sentence is not taking about any particular masochist, then I agree with you that it is taking about a generic masochist. So I have to turn to John Lawler's post Re: A question about the generic use of..., which succinctly explains the difference in generic noun phrases when you use a and the. I assume you've read this page, probably several times.


The masochist is the definite generic, which refers to



the Prototype of a species, roughly the image we associate with tiger...



and


a masochist



refers to the Definition of a species, that is, those properties that are absolutely necessary for anything to be a member. It doesn't work as the subject of any predicate that isn't definitional. But with a definitional property, it's certainly true for any member.




Since the sentence would then assert what any masochist would do, then yes, using the indefinite generic is fine here. At least that's how I interpret my intuitive and unflinching assurance that a masochist is fine here.


By the way, I tried to create a tag generic noun phrase but it got shot down without any reason given. Since not even English speakers are taught what they are, I think it's an important and germane topic for this site. Maybe someone should do a metapost about it but I feel like I did my part and really don't want to repeat my attempt.


Edit: okay, thanks for creating the tag.


present perfect - Are these sentences that mix different tenses grammatically correct?



There are some phrases English native speakers have sent me in the past and I'm not sure how they can be grammatically correct.



I got your order and have processed it.


She has agreed to my terms, so I only did my part yesterday.


[she] quietly slipped away today from the hospital where she has been staying since being freed [...]


If you have just registered, you received your current bill via USPS.



Are these sentences alright? I thought the simple past couldn't be used with the present perfect.



This part on the invoice signifies the quantity shipped but that part signifies the quantity he had wanted.




Why doesn't the sentence use "he wanted"?



There had been an error on the exam, so here are the correct answers.



Can you really use the past perfect here when you are referring to a single event, or does this depend from the context?


ADDITIONAL QUESTION: I saw this sentence on Amazon today: "We noticed that you have created a return label for this order". Does this make sense? Isn't it similar to "She has agreed to my terms, so I only did my part yesterday"?



Answer




I got your order and have processed it




This is okay; there's an action in the past, and a just-completed action, presented in the correct order.



She has agreed to my terms, so I only did my part yesterday.



I don't like this one; it's kind of a "garden-path" sentence, where when you start reading it you automatically assume one thing and when you're done you have to go back and think "oh yeah, I suppose they could have meant it that way." The default reading is that "she has agreed" is a just-completed action; then as a consequence of that, you cannot have an action entirely in the past. You then have to think "oh, they must have meant 'has agreed' as an ongoing thing that started at some point in the past (prior to yesterday)." So while it is perhaps technically justifiable, it's still misleading.



[She] quietly slipped away today from the hospital where she has been staying



This one is okay; you can "slip away" from someplace that you're staying as long as you return there. She might have slipped away to go visit a friend, or to go to a birthday party, or something.




If you have just registered, you received your current bill via USPS.



This is a conditional statement with a lot of implied bits to it, but I believe it is okay. The things going into this are:



  • we normally bill via USPS

  • when you register, you can change how you receive your bill

  • you weren't registered before

  • in order to get to this point, you must have been billed at least once already

  • therefore, since you are at this point, it must be the case that your most recent bill (that is, the "current" one) was sent by USPS.




This part on the invoice signifies the quantity shipped but that part signifies the quantity he had wanted.



I think this would be better with the simple past, but someone could make a case for the past perfect, since the sequence of events is that at time A in the past, someone wanted X units; later (but still in the past), the company shipped Y units; and now, we are talking about it.



There had been an error on the exam, so here are the correct answers.



This one is clearly wrong, since there is no "later, but still in the past" event to make the past perfect useful. (It should be "There was an error.")


grammaticality - Use of simple present vs. present perfect to announce something



"The car is sold for thirty thousand euros," the auctioneer said.



Vs



"The car has been sold for thirty thousand euros," the auctioneer said.




Also



You are fired.



Vs



You have been fired.



What's the difference ?




phrase meaning - What does it mean? "I can't people today"


There is a shirt with a sentence written on it. The sentence is :



I can't people today




What does it mean? I've seen this link and I know that "people" can be a verb but in this special case, I don't get the meaning of the phrase.



Answer



It's supposed to be funny.


It implies



I can't deal with people today.



I personally didn't find it funny because this structure



I can't [noun]




seems cliche to me.


It is supposed to invoke something like this enter image description here


It's akin to



I can't even



if you are familiar with that expression.




I felt like I should probably note that the structure (using nouns as verbs) can change meaning. It isn't fixed. But it is usually used to be funny. For example,




I can't math today.



It could mean I can't do/comprehend/tolerate/teach math, all depending on context.


Today, before I went to class, I saw this post. I was exhausted and I really didn't plan anything for class. So I was thinking, I can't math today. In other words, I can't teach math today. (I wasn't trying to be funny; that's how I felt. But it could be used by someone else to be funny, like if they really hated math.)




Here is an instance of to [noun]. The speaker is talking about the abundance of tutorials in the game Pokemon LeafGreen



You get a tutorial battle where you are told how to play Pokemon. And then there is an old man later on who tells you how to Pokemon.




In this instance, we infer that "to Pokemon" means "to play [the game] Pokemon [LeafGreen]". He's trying to be funny/cutesy. He gets a couple of smiles, but no one really laughs out loud.


word usage - Difference between "Let someone taste" and "Have someone taste"


I tried a new recipe for coming guests. After cooking I let my sister taste it. Can I also say, "I had my sister taste it"?


I don't know the difference of these two sentences in terms of meaning. Is there a big difference? Which sentence is more appropriate?



Answer



In English, "have" is a very flexible word that can be used in a variety of contexts. I can have freckles on my face, I can have cake for dessert, and I can have a dead battery in my car. Furthermore, we can have parties, conversations, naps, arguments, elections, and children.


Getting back to your question, we can also have a taste of the soup.


There's only a small difference in meaning between "let my sister taste it," and "had my sister taste it," although "let" carries a connotation of allow or permit, while "had" might imply a little insistence on your part. In other words, had she asked for a taste, and you said yes, then "let" might be a better word to use. However, if you weren't sure the soup tasted satisfactory, so you wanted your sister to give a second opinion, then "had" might be a better word.



My sister thought the soup smelled delicious, so I let her taste it.


I thought the soup tasted funny, so I had my sister taste it.




Incidentally, yet another way to word this would be:



After cooking, I let my sister have a taste.



which combines both of those words, and would sound perfectly natural to a native speaker.


networking - Client-side prediction and interpolation


Although my game uses a peer-to-peer model, I've still taken the approach of assigning each player to be a partial authority. What I mean by this is that each player acts as the "server" for a number of objects, and all the other players are "clients" for those objects.


It also uses a fixed update interval and variable render interval. I'm considering a 50Hz update frequency, so the rendered time lags behind the current time by 20ms in order to guarantee two states to interpolate between.


When a client recieves authoritative state information from the server, it comes with the timestamp of when it was sent. Because all the players use a synchronized clock, the client can correctly place the state along its "update timeline", the state history of which is stored for up to 100ms back.


However, in order to hide latency, each client also predicts the behaviour of all objects in the vicinity, regardless of whether or not they are the authority.


The difficulty I'm having is figuring out how to correct errors on the client side and stay synchronized with the server state, when server information for a specific object will be coming far less often than updates happen. What is a good way to smoothly correct current information with information from the past after several prediction steps have been done on estimated information?





Sunday, December 24, 2017

american english - Meaning: "waiting for 6 hours" vs. "6 hours since I was waiting"



Do the following sentences denote the same thing?



  1. I have been waiting for you for 6 hours.

  2. It's been 6 hours since I was waiting for you.




grammar - When to use "be going to" / present continuous in future?



In our lesson we have


Be going to




  • future plans (personal)

  • prediction based on something we can see or hear


Present continuous



  • future arrangement

  • fixed plan


Is this right? Can someone explain this to me with examples?



Answer




You use "be going to" for your future plans - the things you intend/have decided to do in the future. For example:


I am going to have a meal with my friends tonight.


you can also use "be going to" for a prediction as you see or hear. For example:


There are clouds in the sky. It's going to rain.


You use the present continuous for future arrangements and fixed plans. For example:


I am going to an ice hockey match in the evening. I bought a ticket for it yesterday.


Nevertheless, you often use either be going to or the present continuous to have similar meanings.


We are going to have a party next week (we intend/have decided to do so).


We are having a party next week (we have made arrangements).


Saturday, December 23, 2017

textures - Creating a retro-style palette swapping effect in OpenGL


I'm working on a Megaman-like game where I need to change the color of certain pixels at runtime. For reference: in Megaman when you change your selected weapon then main character's palette changes to reflect the selected weapon. Not all of the sprite's colors change, only certain ones do.


This kind of effect was common and quite easy to do on the NES since the programmer had access to the palette and the logical mapping between pixels and palette indices. On modern hardware, though, this is a bit more challenging because the concept of palettes is not the same.


All of my textures are 32-bit and do not use palettes.


There are two ways I know of to achieve the effect I want, but I'm curious if there are better ways to achieve this effect easily. The two options I know of are:



  1. Use a shader and write some GLSL to perform the "palette swapping" behavior.


  2. If shaders are not available (say, because the graphics card doesn't support them) then it is possible to clone the "original" textures and generate different versions with the color changes pre-applied.


Ideally I would like to use a shader since it seems straightforward and requires little additional work opposed to the duplicated-texture method. I worry that duplicating textures just to change a color in them is wasting VRAM -- should I not worry about that?


Edit: I ended up using the accepted answer's technique and here is my shader for reference.


uniform sampler2D texture;
uniform sampler2D colorTable;
uniform float paletteIndex;

void main()
{

vec2 pos = gl_TexCoord[0].xy;
vec4 color = texture2D(texture, pos);
vec2 index = vec2(color.r + paletteIndex, 0);
vec4 indexedColor = texture2D(colorTable, index);
gl_FragColor = indexedColor;
}

Both textures are 32-bit, one texture is used as lookup table containing several palettes which are all the same size (in my case 6 colors). I use the source pixel's red channel as an index to the color table. This worked like a charm for achieving Megaman-like palette swapping!



Answer



I wouldn't worry about wasting VRAM for a few character textures.



To me using your option 2. (with different textures or different UV offsets if that fits) is the way to go: more flexible, data-driven, less impact on the code, less bugs, less worries.




This put aside, if you start to accumulate tons of characters with tons of sprite animations in memory, maybe you could start using what's recommended by OpenGL, do-it-yourself palettes:



Paletted textures


Support for the EXT_paletted_texture extension has been dropped by the major GL vendors. If you really need paletted textures on new hardware, you may use shaders to achieve that effect.


Shader example:


//Fragment shader
#version 110
uniform sampler2D ColorTable; //256 x 1 pixels

uniform sampler2D MyIndexTexture;
varying vec2 TexCoord0;

void main()
{
//What color do we want to index?
vec4 myindex = texture2D(MyIndexTexture, TexCoord0);
//Do a dependency texture read
vec4 texel = texture2D(ColorTable, myindex.xy);
gl_FragColor = texel; //Output the color

}

This is simply sampling in ColorTable (a palette in RGBA8), using MyIndexTexture (an 8 bits square texture in indexed colors). Just reproduces the way retro-style palettes work.




The above-quoted example uses two sampler2D, where it could actually use one sampler1D + one sampler2D. I suspect this is for compatibility reasons (no one-dimensional textures in OpenGL ES)... But nevermind, for desktop OpenGL this can be simplified to:


uniform sampler1D Palette;             // A palette of 256 colors
uniform sampler2D IndexedColorTexture; // A texture using indexed color
varying vec2 TexCoord0; // UVs

void main()

{
// Pick up a color index
vec4 index = texture2D(IndexedColorTexture, TexCoord0);
// Retrieve the actual color from the palette
vec4 texel = texture1D(Palette, index.x);
gl_FragColor = texel; //Output the color
}

Palette is a one-dimensional texture of "real" colors (e.g. GL_RGBA8), and IndexedColorTexture is a two-dimensional textures of indexed colors (typically GL_R8, which gives you 256 indices). To create those, there are several authoring tools and image file formats out there that support paletted images, it should be doable to find the one that fits your needs.


ambiguity - The department shredded all the files from the inquiry[,] 'which'/'that' contained embarrassing material



The department shredded all the files from the inquiry which contained embarrassing material.



After having read the sentence above, I was wondering if the department destroy every file, or only those with embarrasing contents.


Could one avoid ambiguity using a comma before 'which', like in A? Or is it better to this pourpose replacing 'which' with 'that', like in B?




A. The department shredded all the files from the inquiry, which contained embarrassing material.


B. The department shredded all the files from the inquiry that contained embarrassing material.





svg - High Performance Vector Graphics Solutions



I'm looking for a high performance vector graphics library I can use in my games.


I'm thinking along the lines of vector graphics such as those that can be made with SVG.


I'll consider any language at the moment (but must run on Windows). A solution that takes advantage of GPU hardware would be great.


Thanks in advance.





meaning - What does 'scape mean in this quote by Shakespeare?


I found this line in Hamlet by William Shakespeare.



And 'scape detecting, I will pay the theft.



What does "'scape" mean? Google says this.





  1. A long, leafless flower stalk coming directly from a root.

  2. The basal segment of an insect's antenna, esp. when it is enlarged and lengthened (as in a weevil).



Should I read this as "And flower stalk detecting, I will pay the theft."?



Answer



The apostrophe at the beginning is your clue that it is missing a letter or two. The word is



escape : (transitive) To avoid (any unpleasant person or thing); to elude, get away from.




linking verbs - "This Page Intentionally Left Blank"


This sentence often appears in a "blank" page of books. Why there's no linking verb after the subject (Page)? e.g.:



This Page Was Intentionally Left Blank




If the adverb in the original sentence is removed, we only have:



This Page Left Blank




So I wonder why the original sentence without a linking verb often appears in books. Is it not odd without a linking verb? Based on my understanding of the original sentence, it means that the page left itself blank, which is odd for me.


Hope to get some clarifications about this.




Friday, December 22, 2017

idioms - (Up to / until / by) 50% off



I wonder if someone could tell me which choice works in the following sentence and why the others do not work: (From my point of view, all of these choices work in this context.)



They have great promotion till January 5th......50% off.


a) up to; b) until; c) by




Answer



Up to is correct. your sentence would look like this


They have **a** great promotion, **up to** 50% off.

Meaning on different products, discount is between 0 and 50 per cent.



until is also correct, if you change the sentence a bit, although the context changes.


They have **a** great promotion **from** January fifth, **till** January 8th, 50% off.

the 50% discount is available from January fifth till eighth.


actionscript 3 - How do I get the distance between 2 points on an isometric grid?


How do I get the distance between 2 points on an isometric grid? I'm creating a facebook isometric game (in as3), and when I move around a particular type of building, I need to know if it comes within range of another type of structure, for example a tree. I tried taking the grid x,y points for both items, and calculating the x,y from that but it doesn't seem to work.



Answer



There are a lot of ways to compute distances, every dot product can be used: a looot of ways.


In your case you surely want to compute the distance between the center of the tiles. I take for granted that you know how to compute the center of a tile.


Once you know the position, you can use the Euclidean distance in the canvas' coordinate space (i.e. √[(x'-x")²+(y'-y")²]) or the same in tile's coordinate system.


Another option is the Manhattan or taxicab distance: d = |x'-x"|+|y'+y"|; even in this case you can use tile's coordinate or canvas' coordinate.



The last option (after L2 and L1 norm) the L"infinite" norm where d is the max between |x'-x"| and |y'-y"|.


Lets see the differences:


The best way to evaluate this norms is to see the shape of a disc.


Given a center, a disc is every point that falls within a fixed distance (however computed).


Euclidean Norm:


The disc is a standard circle in the canvas space and an ellipse in tile space


L2 canvas


Euclidean Canvas


L2 tile


Euclidean Tile



While the first one is easier to compute in general (you don't have to go back and forth tile and canvas coords), the second gives a better fill.


The "Euclidean Tile" is the norm that is generally considered the most correct one.




Taxicab Norm:


The disc becomes a diamond in canvas coordinate and a sort of rectangle in the tile coordinate (showing how applying the same coordinate changes two times rawly gives the initial result)


L1 canvas


Taxicab Canvas


L1 tile


Taxicab Tile


We can see even this time how the canvas coordinate gives the worst results: this is the price for an easier way to compute distances.



The "Taxicab Tile" gives a reasonable results, quite similar to the "Euclidean Tile", but simply summing the tile coordinate. This is a very popular norm for this kind of problems




L0 Norm:


Using the max if axial distances, the disc becomes a rectangle and the equivalent diamond in canvas and tile space respectively


L0 canvas


L0 Canvas


L0 tile


L0 Tile


Ok, let's face it: the L0 canvas is horrible.


On the other hand the "L0 Tile" make it sense: it is quite clean and very easy to compute. Can be taken into account when playing with slow device and we need to use every clock cycle.





Conclusions


The norms computed on canvas coordinates give the worst of the results: the two coordinate systems does not match very well so the price to have a easier norm is simply too high.


The Euclidean norm is the better choice but the slower one; The Taxycab norm offer a very good trade off.


The "L0" is the fastest and easier but the price is to have a distance that is a little unrealistic.


architecture - Role of an entity state in a component based system?


Component-based entity systems are all the rage these days; everyone seems to agree they are the way to go, but no one really has a definitive implementation of such a system. I was wondering, what role do entity states (walking-left, standing, jumping, etc) have in a CBS? Do they act like controllers (i.e. they handle events and change the entity's attributes based on those events)?



What about cases where a state would, for example, require that the entity enters no-clip mode? Should, that state, when it enters, maybe set the CollisionComponent of the entity to a null pointer or something? (Then, on exit, the state should restore the entity's CollisionComponent to its previous state.)


Also, I guess it's the current state's job to change the entity's state to something else, right?



Answer



I was under the impression that in a components based design the entities are essentially components containers (with possibly some message thrown in). Viewed from this perspective the each components would store a little of the state. For instance if the ghost-behavior-components decides it needs to enter the intangible mode it also sends a message to the physics component telling it to enable no-clip. It would probably also send a message to the ghost-model-components telling to kick up the alpha.


How can I properly access the components in my C++ Entity-Component-Systems?


(What I'm describing is based on this design: What is an entity system framework?, scroll down and you'll find it)



I'm having some problems creating an entity-component system in C++. I have my Component class:


class Component { /* ... */ };

Which is actually an interface, for other components to be created. So, to create a custom component, I just implement the interface and add the data that will be used in-game:


class SampleComponent : public Component { int foo, float bar ... };

These components are stored inside an Entity class, which gives each instance of Entity a unique ID:


class Entity {
int ID;
std::unordered_map components;

string getName();
/* ... */
};

Components are added to the entity by hashing the component's name (this probably isn't such a great idea). When I add a custom component, it is stored as a Component type (base class).


Now, on the other hand, I have a System interface, which uses a Node interface inside. The Node class is used to store some of a single entity's components (as the System isn't interested in using all of the entity's components). When the System has to update(), it only need to iterate through the Nodes it stored created from different entities. So:


/* System and Node implementations: (not the interfaces!) */

class SampleSystem : public System {
std::list nodes; //uses SampleNode, not Node

void update();
/* ... */
};

class SampleNode : public Node {
/* Here I define which components SampleNode (and SampleSystem) "needs" */
SampleComponent* sc;
PhysicsComponent* pc;
/* ... more components could go here */
};


Now the problem: let's say I build the SampleNodes by passing an entity to the SampleSystem. The SampleNode then "checks" if the entity has the required components to be used by the SampleSystem. The problem appears when I need access the desired component inside the Entity: the component is stored in a Component (base class) collection, so I can't access the component and copy it over to the new node. I've temporarily solved the problem by casting the Component down to a derived type, but I wanted to know if there is a better way of doing this. I understand if this would mean re-designing what I already have. Thanks.



Answer



If you are going to be storing the Components in a collection all together then you must use a common base class as the type stored in the collection, and thus you must cast to the correct type when you try to access the Components in the collection. The problems of trying to cast to the wrong derived class can be eliminated by clever use of templates and the typeid function, however:


With a map declared like so:


std::unordered_map components;

an addComponent function like:


components[&typeid(*component)] = component;


and a getComponent:


template 
T* getComponent()
{
if(components.count(&typeid(T)) != 0)
{
return static_cast(components[&typeid(T)]);
}
else
{

return NullComponent;
}
}

You will not get a miscast. This is because typeid will return a pointer to the type info of the runtime type (the most derived type) of the component. Since the component is stored with that type info as it's key, the cast can not possibly cause issues because of mismatched types. You also get compile time type checking on the template type as it has to be a type derived from Component or the static_cast will have mismatched types with the unordered_map.


You do not need to store the components of different types in common collection, though. If you abandon the idea of an Entity containing Components, and instead have each Component store an Entity (in reality, it will probably be just an integer ID), then you can store each derived component type in its own collection of the derived type instead of as the common base type, and find the Components "belonging to" an Entity through that ID.


This second implementation is a bit more unintuitive to think about than the first, but it could probably be hidden as implementation details behind an interface so the users of the system don't need to care. I won't comment on which is better as I have not really used the second, but I don't see using static_cast as a problem with as strong a guarantee on types as the first implementation provides. Note that it requires RTTI which may or may not be an issue depending on platform and/or philosophical convictions.


jobs - What does a Game Designer do? what skills do they need?




I know someone who is thinking about getting into game design, and I wondered, what does the job game designer entail? what tools do you have to learn how to use? what unique skills do you need? what exactly is it you'd do from day to day. I may be wording this a bit wrong because I'm not sure if the college program is become a game designer or learn game design. but I think the same questions apply either way.



Answer



What does the job game designer entail?


I always explain design to people like this:




What's the difference between Black Jack and Poker?



They both involved players and the same deck of cards, but are entirely different games because the rules that define how the games are played are different. In essence that is what a designer does, writes a series of rules as to how a game plays.


These days as games get more complicated, the job often includes narrative elements in the areas of story/setting/characters. Although many parts of that are given to people dedicated to writing and not design.


Design is a pretty broad term in the industry and it covers everything from high level system design (rules) to narrative design (story/character) to level design (the placing of assets and scripting)


What tools do you have to learn how to use?


Getting a job directly as a designer is hard. Many of us came from either Programming or Art backgrounds or in my case both. On smaller teams, it'll be expected that you can do something other than design full time as well. The tools change depending on the type of design you are doing.


System designer/Creative Director - Most time spent in Excel, Word, and Powerpoint.


Narrative designer - Word, maybe Final Draft. These guys are mostly writers.


Level Designers - Excel, custom level design software or common 3rd party tools (UnrealEd, and so on) Typically should be comfortable navigating the popular 3D-art packages (Max/Maya)



What unique skills do you need?


Communication, both writing and verbal is probably your most often used skill once you get to the higher levels of design. Coming up with a design is a pretty small part of the job. You spend most of the time communicating how to build that design to the rest of the team.


Critical thinking, ability to break down a problem into a series of small discrete steps. It's not enough to play a bunch of games. You need to be able to clearly understand how the parts of those games work together. When/why they combine and work, and why they can fail when combined.


Level designers benefit from an art background. An understanding of composition and architecture both help.


A basic psychology understanding is also helpful for designers. The more you understand about how and why people respond to stimulus the better your can predict their response to future designs.


Thursday, December 21, 2017

pronouns - Who or whom? "Figure 1 depicts a surveillance system, detecting pedestrians whom are crossing dangerous regions."


In the following sentence, should I use who or whom? It is highlighted in bold.



For instance, Figure 1.1 depicts an operating smart surveillance system, detecting pedestrians whom are crossing dangerous regions, cars in parking lots, and ships.




I think it should be whom because the "operating smart surveillance system" is the subject, while "pedestrians" are the object. But, my professor corrected it to who and now I'm not sure.



Answer



The system is subject but then the next clause talks about pedestrians who also become subject crossing the regions etc. Removing the pronoun itself will also work.


A quick trick!


Now, cut off the sentence.



Pedestrians whom are crossing [something]



Here only, we get a hint that it seems incorrect.


Now, think that it's about 'you'. If 'I' fits, put 'who' and if 'me' fits, put 'whom'.




me I am crossing [something]



Technically, if the pronoun in question is doing something, prefer putting 'who' (what they call subject) and if it's receiving something, prefer 'whom' (what they call object)!


user generated content - How to attract modders to your game?


I am developing a game, but as I am working on it alone, the amount of content I can create is very limited. Because of that I want my game to be modded, for this purpose I am planning to create a complete modding API which would be exposed for lua scripting. I would also create tutorials to get people started. And the "Original" game would also be a "mod"(similar to Warcraft III maps) .



My question is: What can a developer do to encourage modding of its game?


PS: my game is a sandbox-ish multiplayer survival(most things are procedural).



Answer




  • Make the modding tools very easy to use. There should be a tool for creating the mod, and a fast way to test the mod, ideally live creation if that's practical for your game.

  • Make the distribution and installation of mods dead simple (think steamworks). People are more likely to make mods if they know they'll be used! A rating system will give recognition to modders and allow people to choose the best mods.

  • Make many aspects of the game modifiable. If users can add levels, enemies, weapons, etc. they're more likely to make a mod. If the aspect of the game they want to change isn't modifiable, they won't make a mod.


And the most difficult task:




  • Make a game that people love to play. People won't bother modifying a game they don't like.


verb forms - How does the grammar work in "here be dragons"?


Why is the phrase here be dragons not here are dragons? Is this a special grammatical form? If so, what is it?


I found a related ELU question on the topic.



Answer



I thought I'd add this as well, just for those who are inferring that "Here Be Dragons" is an inference on the illiteracy of the scholars during the middle ages. I've separated it out from the other answer because it's not a direct answer to the question.


Anyway, "Here Be Dragons" is actually just an example of Old English (it is invalid modern English)- in particular it's just an inversion of a sentence in the Old English sentence ordering.


In particular



Here Be Dragons




Is an inversion of



[if] here, there Dragons are



In much the same way that in Jack and the Beanstalk the sentence



Be he alive or be he dead, I'll grind his bones to make my bread



is an inversion of the sentence




[if he is] alive or dead, I'll grind his bones to make my bread



Now "If here, there dragons are" is a word ordering that is no longer valid (although the word order should be familiar to German speakers which has the same sentence structure as Old English), and that is why the sentence "Here Be Dragons" is no longer valid.


Note that the subjunctive form in English is still there, so we can construct our own sentences to show that this is still valid English so long as we shuffle the word order around:



I must insist that you be here by 9 am tomorrow for a debrief.


I agree with the recommendation that komodo dragons be here in the public part of the zoo where visitors can see them.



So anyway, long story short is that "Here Be Dragons" used to be valid English, but no longer is. Its use idiomatically is used to insinuate "oldness" rather than "illiteracy".


word meaning - Does "off" mean "beginning with" in this sentence?


I am wondering what does "off" mean in following sentence:



"This year, production is off to a slow start; only five vehicles are manufactured each hour."




Does it mean that the production is beginning with a slow start? Or does it mean something else?


Thank you in advance, and have a great day.




gerunds - What is "No parking" short for?


I am studying in the imperative sentence and I wonder what "No parking" is short for.I also want to get more comprehensive material of the imperative sentence.



Answer



It's not short for anything. It's a direct instruction.


When forming a basic imperative, instructing someone to do an action, we just use the verb form directly, possibly with an exclamation mark:



Run!


Stop!



Come back!



This is the case whether we are instructing someone specific or people in general to perform the action.


But when we construct a sentence instructing someone to not do an action, there are two forms. The first form is a basic negated imperative - used when we are telling someone that the action must either not happen, or must stop happening. For this we use the simple negation of the imperative by adding don't (or equivalent) to the front of the sentence:



Don't run!


Don't stop!


Don't come back!



The second form is when we are telling someone that the action is forbidden. In this case we add the determiner no and change the verb into gerund form, and this is the form generally found in slogans and signage:




No running!


No stopping!


No coming back!



Indeed, if you look up the dictionary definition of no, you'll find this listed as one of the many specific uses of the word:



No - determiner


used in notices or slogans forbidding or rejecting something specified.




So as you can see, "no parking" is not, in fact, short for anything. It's a direct instruction, telling people in general that parking is forbidden in the vicinity of the sign.


Wednesday, December 20, 2017

architecture - Multithreading: Each system on a different thread or a thread pool?


I'm building a fairly involved game using OpenGL and C++. I've been thinking about how to implement multithreading, and the two options are:


1) Each system (Graphics, Audio, Physics, et cetera) gets their own dedicated thread that they run off of.


2) Implement a thread pool, that picks up a jobs from a queue (priority queue), executes it and gets re-inserted into the pool to wait for new available job.



I was wondering which one is generally considered better: in terms of performance, maintenance, scalability, code smell, et cetera.



Answer



One important concern when deciding units of parallelization is usually to avoid sharing data between threads. Multiple threads operating on the same data is always hairy, because:



  • if those accesses are not properly synchronized, you can encounter bugs triggered by race conditions which appear seemingly randomly and are extremely difficult to reproduce and analyze.

  • if they are properly synchronized, those synchronization techniques can often lead to performance problems and even deadlocks (two threads are locking different data structures and waiting for the other thread to release theirs)


So you generally want threads to communicate with each other as little as possible.


Unfortunately, systems often operate on data delivered by other systems. A good example is the graphics system which renders the game state which gets constantly changed by the physics system. That means that access to the game state must be synchronized. If you render the game state while the physics system changes it, you might occasionally encounter really weird artifacts on the screen. For example, let's say the rendering system wants to render a character who is swinging a sword. The character and their sword are implemented as separate entities by the physics system. At the moment where the rendering system renders both entities, the physics system might have already updated the position of the character but not yet the position of the sword. So you occasionally see the sword getting rendered outside of the fist of the character.


There are two solutions to this synchronization problem, and neither is good. The first is to have one system wait until the other is finished. But if you run your systems in sequence anyway, then you gain nothing by multithreading and can just as well run them on the same thread. The second is to have two copies of the game state. While the rendering engine renders the old state, the physics engine calculates the next state. Then you have a synchronization point, switch out the two states, and proceed with the next frame. But this doubles the amount of RAM you need for your game state.



Another problem with using one thread per system is that the resource consumption between systems is often very unequal. There is little benefit in having 4 threads when 3 of them stall most of the time while only one of them actually maxes out its CPU core. You ideally want to distribute your load on all CPU cores equally.


For these reasons, you might rather look for units of parallelization within your systems.


If you need to run an update on 2000 objects, and those updates do not depend on the states of other objects, then you can use 4 threads and have each one process a set of 500 objects. In the idealized case, this cuts the processing time of that system down to one quarter.


Keep in mind that creating threads is expensive, so you should always use a thread-pool which maintains a number of long-living threads and passes units of work to these threads. I have also seen thread-pool implementations which allow you to pass a job together with a list of other jobs it depends on. The thread-pool will then wait with enqueueing that job until all the dependencies have finished. This makes it a lot safer to implement multithreading across system boundaries if those systems have dependencies on each other.


spritesheet - Combining multiple sprites vs separate sprites


I have a character which can hold ten types of weapons.


Should I:



  1. Create ten sets of animations for the character with each weapon

  2. Create animations for each weapon, and programmatically draw them on the character


Option 1 is simpler in general, but requires more work on the artist, and results in larger game size.



Option 2, to me, is a programming nightmare...


Whats the better practice in general? Thanks.



Answer



Unless you have a high frame rate and very low size requirements, the number of sprites you're talking about won't matter compared to, say, the audio files (especially music!). If game size was the only requirement, I'd say go with pre-baked animations.


As long as you only have ten weapons, either way will be roughly the same amount of work for the artist; I'm assuming she'll be reusing most of the character animations and only changing a bit for each weapon.


If you have combinations of items, then Option 2 becomes more appealing. If you have, say, 10 weapons and 4 armors that can be worn in combination, you suddenly have the choice between 40 animations or combining 14 programmatically. If you add 10 hats, it's 200 versus 24. Combinations of items is the most common reason I've seen that developers programmatically layer sprite animation.


So I say you might as well go for Option 1 unless you're combining stuff.


As an aside, though, the code for layering sprites shouldn't be too hard if you're using a decent library or framework. The fact that it seems intimidating may show a weakness in your development skills. It might be worth it to expand your programming knowledge by treating this as an exercise.


Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...