Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Nypyren

Member Since 19 Aug 2002
Online Last Active Today, 12:13 PM

#5230292 Oauth 2.0 and Unity

Posted by Nypyren on 21 May 2015 - 01:25 PM

Oops, sorry, I was thinking of standalone windows forms apps and Metro apps when I said that, not Windows desktop apps that use Unity. To take complete control over the web browser widget, you have to be a Windows app that has access to one of the programmatically controllable web widgets. Unity doesn't include one of those as far as I know.


With a Unity app, I've never done "real" OAuth authentication on a PC. The hack we use when running our game in the Unity editor is to start an HttpListener locally, use Application.OpenURL to launch a browser window with the OAuth login URL, and have the redirect_uri go to localhost on whatever port you're listening on. The HttpListener then catches the response. This would probably not be an acceptable solution to ship in your game, though.


#5230277 Oauth 2.0 and Unity

Posted by Nypyren on 21 May 2015 - 11:23 AM

Hmm, well it didn't work on the droid build either so gonna look into it. Saw a page about the WWW class in unity which apparently opens the page IN the unity app as opposed to the Application.openurl I guess? Gotta fiddle more I guess


WWW lets you make web requests. For example, you can use it to access a web service or download an AssetBundle containing DLC for your game. It doesn't have a web browser user interface.


#5230186 How do they get games to open themselves?

Posted by Nypyren on 20 May 2015 - 10:28 PM

The game doesn't necessarily need to terminate if its main window is closed. I've had a lot of accidents where I didn't properly shut down my program and it continued to run in the background.

You could use this approach intentionally to "relaunch" the game by re-initializing your game after a period of time.

 
If you take this approach be sure to release any memory you no longer need and put your process to sleep. You wouldn't want your game to be eating up system resources in the background.


You'll likely need to do this anyway to properly reinitialize your game. Anyone relying on the process being terminated to free up resources for them is gonna have a bad time!


#5230157 How do they get games to open themselves?

Posted by Nypyren on 20 May 2015 - 06:23 PM

The game doesn't necessarily need to terminate if its main window is closed. I've had a lot of accidents where I didn't properly shut down my program and it continued to run in the background.

You could use this approach intentionally to "relaunch" the game by re-initializing your game after a period of time.


#5230146 Too clever...?

Posted by Nypyren on 20 May 2015 - 05:51 PM

Looks fine to me. In some other languages (like C# which I use most of the time) another common practice is to throw ArgumentException in those three cases.


#5229890 Oauth 2.0 and Unity

Posted by Nypyren on 19 May 2015 - 12:57 PM

I haven't tried Fitbit, but I've done Facebook and Twitter authentication on mobile devices. You register a special URI scheme for your app, and use a URI with that scheme for the redirect_uri you pass to Facebook/Twitter. Once you login via the web interface, they redirect to the URI you provide. Your app then handles the URI scheme and receives the authentication token, which you use however you need to.

Facebook and Twitter have specific restrictions on what redirect_uri you have to use (to prevent malicious entities from redirecting to their own services/apps), so perhaps Fitbit does as well.


#5229372 Multiplayer to an existing game?

Posted by Nypyren on 16 May 2015 - 05:03 PM

You need several years of experience programming in C, C++, and assembly language.

You also need lots of experience with:

- Reverse engineering
- Game programming
- Network programming
- A tremendous amount of patience and motivation


It's not easy, or fun, but it's possible.


#5227638 (7+9)**(1/2): Why isn't this returning 4?

Posted by Nypyren on 06 May 2015 - 08:28 PM

So Python 2 follows most programming languages in that arithmetic operations on two integers give an integer result. So 1/2 is 0, and anything raised to a 0 power is 1. Python 3 came along can said that most people find that 1/2 being 0 is unnatural so will let integer arithmetic yield floating point results, so 1/2 is 0.5.


That's one HELL of a breaking change... does that only hold true for literals, or does it do that for variables as well?


#5227620 (7+9)**(1/2): Why isn't this returning 4?

Posted by Nypyren on 06 May 2015 - 07:12 PM

Does python evaluate (1/2) as zero like most other languages?


#5227542 Small C++11 regex question

Posted by Nypyren on 06 May 2015 - 11:25 AM

I'm not familiar with C++'s regexes, but I've used C# and bash regexes and it looks similar.

Looks like it's matching a time string in the form "##:##:##".

\d is usually the same as [0-9]. "digit". I'm not sure if it needs to be in brackets in C++ or if that's redundant.

{2} means "require the pattern to the left to match twice"

: isn't a special character, so it just matches colon characters.


#5227385 C# class library and external functions

Posted by Nypyren on 05 May 2015 - 03:13 PM

A C# user would expect a vector subtraction function to look more like one of these:
 
public struct Vector3
{
   public float X, Y, Z;

   // constructor(s) omitted since they are trivial

    public static Vector3 Subtract(Vector3 a, Vector3 b)
    {
       return new Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
    }

    public static void Subtract(out Vector3 a, Vector3 b, Vector3 c)
    {
       // Might not compile without some tweaks; I forget the exact struct-out requirements.
       a.X = b.X - c.X;
       a.Y = b.Y - c.Y;
       a.Z = b.Z - c.Z;
    }
}



#5227182 ISO quick max distance check

Posted by Nypyren on 04 May 2015 - 11:51 AM

Also, instead of flagging the player as a cheater, you can enforce the speed limit. This would prevent other players from seeing the cheater moving unacceptably fast.
 
float maxDifference = SPEED_LIMIT_PER_SECOND_CONSTANT * timeSinceLastUpdateInSeconds;
Vector3 diff = newPos - oldPos;
if (LengthSquared(diff) > maxDifference * maxDifference)
{
   newPos = oldPos + Normalize(diff) * maxDifference;
   // send forced position update back to the client with newPos - this is sometimes called "rubber-banding"
}



#5227176 ISO quick max distance check

Posted by Nypyren on 04 May 2015 - 11:32 AM

The maximum distance they can move relative to their current position should have nothing to do with their current position or velocity.

You want to make sure they don't suddenly go in ANY direction further than what's possible.

If the player could move in any direction, a constant limit creates a spherical area that they must be within.
 
float maxDifference = SPEED_LIMIT_PER_SECOND_CONSTANT * timeSinceLastUpdateInSeconds;
float actualDifferenceSquared = LengthSquared(oldPos - newPos);

if (actualDifferenceSquared > maxDifference * maxDifference)
{
// probably cheating.
}



#5226402 Need Some Assistance with XNA

Posted by Nypyren on 29 April 2015 - 07:26 PM

OK. The SpriteBatch class is only for sprites (sprites are 2D rectangles).

To draw a 3D model, you need to use something specific for that:

https://msdn.microsoft.com/en-us/library/bb197293(v=xnagamestudio.31).aspx

*** IMPORTANT NOTE: This is from XNA 3.1. If you're using a different version, google search for "XNA 3D model example", because things often change slightly between different versions, so the code might not even compile on a different version! ***


Quote taken from that example:
protected override void Draw(GameTime gameTime)
{
    graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

    // Copy any parent transforms.
    Matrix[] transforms = new Matrix[myModel.Bones.Count];
    myModel.CopyAbsoluteBoneTransformsTo(transforms);

    // Draw the model. A model can have multiple meshes, so loop.
    foreach (ModelMesh mesh in myModel.Meshes)
    {
        // This is where the mesh orientation is set, as well 
        // as our camera and projection.
        foreach (BasicEffect effect in mesh.Effects)
        {
            effect.EnableDefaultLighting();
            effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(modelRotation) * Matrix.CreateTranslation(modelPosition);
            effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
            effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);
        }
        // Draw the mesh, using the effects set above.
        mesh.Draw();
    }
    base.Draw(gameTime);
}
As you can see, 3D models require more setup steps to draw!

Transforms:
World matrix: Used to control how the model is translated (moved), oriented (rotated), and scaled (made larger/smaller).

View matrix: Used to control the "camera" (your viewpoint in space).
Projection matrix: Used to control the camera's field of view.


Effects: Are used to control how the pixels of the model are colored - they can take into account things like light sources, shiny spots on the surface, and MUCH more. These are also known as "Shaders".

Hopefully that helps some. 3D rendering takes a lot of getting used to!


#5226331 C# class library and external functions

Posted by Nypyren on 29 April 2015 - 01:43 PM

I concur with ferrous - If you've ported it to C#, why do you have 'unsafe' and 'float *' exposed in the public interface at all?

Even if your port is just a lightweight P/Invoke layer, you should try to make the public interface use .NET class library design guidelines. This may mean adding some marshalling functions, but that's usually pretty simple.

https://msdn.microsoft.com/en-us/library/vstudio/ms229042(v=vs.100).aspx




PARTNERS