Monday, August 1, 2016

Only 12 Enemies, And My Fps Drops To 30, Why Is That?(Solved)

Only 12 Enemies, And My Fps Drops To 30, Why Is That?(Solved)

Guys, I have 7 animated enemies. And my fps is 62 for now( not capped). But when I add 5 more enemies and make them 12, my fps drops to 31. I traced the problem and I finally found it, it's my BoneTransform() function, which fills my vector of TransformMatrices that I use in the vertex shader in order to animate the skeleton. But it rapes my CPU. ( when I comment the BoneTransform() function, framerate goes from 30 to 166!( sometimes jumps between 166 and 200 ). And I kind of stole most of the function from a tutorial on skeletal animation, and I'm sure it's pretty optimized, so there must be some other reason.

 

lowfps.gif

 

I used some models from World of Warcraft. And the interesting thing is that I have the game, and when I play it( when I play WoW ), I can have 20 players around me, and my fps is great, but when I add the same models in my own game, my fps drops like crazy and it's 10 times slower than the original game, why? ( bear in mind that I haven't even loaded any map, I just spawn 12 enemies walking on air, and my cpu runs like a fat truckdriver, wtf is that?? ).


Unity 5 - 2D Tower Defense Tutorial

Unity 5 - 2D Tower Defense Tutorial

Video tutorial:
http://bit.ly/29aQHZs

 

 

Official page of inScope:
 
Description
This tutorial will teach you how to create a 2D tower defense games in Unity. When you have completed the tutorial, you will have a finished game with a "Beginning and an End". Below are some of the things, that we will be implementing in the game.
 
Towers
We will be implementing 4 kinds of towers in our game.
 
Fire tower: This tower shoots fire projectiles, these projectiles has a chance to apply a fire debuff. The fire debuff is a damage over time effect. When applied to a monster it deals damage every x amount of seconds, as long as the debuff is applied to a target.
 
FireTower.png
 
Frost tower: This tower fires frost projectiles. These projectiles has a chance to apply a frost debuff, that slows down the targets movement speed
 
.FrostTower.png
 
Poison tower: This tower fires poison projectiles. These projectiles has a chance to apply a poison debuff, this debuff drops poison on the ground behind the target. If another mob steps in the poison it will take damage.
 
PoisonTower.png
 
Storm tower: This tower fires thunderbolt projectiles, these projectiles has a chance to apply a storm debuff to the target. This debuff will stun the target for an amount of seconds.
 
StormTower.png
 
Monsters
We will also be adding 4 kinds of monsters to the game
 
Red: This monster takes less damage from fire towers, and is immune to fire debuffs.
Blue: This monster takes less damage from frost towers, and is immune to frost debuffs.
Purple: This monster takes less damage from storm towers, and is immune to storm debuffs.
Green: This monster takes less damage from poison towers, and is immune to poison debuffs.
 
 
What will you learn?
General Object oriented C# programming
 
  • Structs
  • Dictionaries
  • Stacks
  • Lambda expressions
  • ICompareable interface
  • Operator overloading
  • Abstract classes
  • Abstract methods
  • Inheritance
  • Constructors
  • Constructor overloading
  • Instantiating objects
  • Virtual methods
  • Overloading methods
  • Enumerations
  • Generics
Design patterns
 
  • Singleton
  • Object pool
Algorithms
 
  • A* algorithm for pathfinding
Game mechanics
 
  • Generating a tile map based on a text document
  • Creating a loading screen with a loading bar
  • Using the A* algorithm to find a path from start to goal
  • Creating debuffs
  • Adding a health bar to the mobs
  • Creating towers with different stats
  • Upgrading towers
  • Showing tooltips ingame
  • Setting win and lose conditions
  • Restarting the game
  • Camera movement inside level bounds
  • Buying and selling towers
  • Spawning waves of monsters
  • Animating the towers and mobs based on their current actions
  • Adding main menu, ingame menu and an options menu
  • Adding SFX -and background sounds.
  • Adjusing the sound levels from the menu

Mess With Matrix Multiplication

Mess With Matrix Multiplication

I am currently refactoring the code and i bumped once again on the shader. There is something definitely wrong. I read the "mul" documentation, the row/column matrix/vector and in my opinion, the math in my shader is wrong, but suddenly it turns out that it renders properly...

 

So, inside my shader file i have

cbuffer cbPerFrameViewProjection : register(b1)
{
    column_major float4x4 PV;
};

cbuffer cbPerObjectWorldMatrix : register(b0)
{
    column_major float4x4 World;
};

Where "PV" is set once at the beginning of a frame, and world is per object.

 

The multiplication inside vertex shader

float4x4 wvp = mul(World, PV);
output.Pos = mul(wvp,inPos);

I set the constant buffers like that:

Camera:

&XMMatrixTranspose(cam.GetViewMatrix()*cam.GetProjectionMatrix())

And for every object:

&XMMatrixTranspose(world.GetTransform())

Now the maths: C++ stores matrices as row major, hlsl as column.

Camera ((view row * projection row) transposed) equals to (((projection column * view column) transposed) transposed) which is (projection column * view column).

World row transposed equals to world column.

So - both constant buffers are fed a column matrices.

Then, inside shader, to count WVP transposed (which in column order is PVW) i should do mul(PV,World) from constant buffers data to get the right answer, but NOT mul(World,PV) as i do now - and the second (wrong in my opinion) solution is correct. Why is that?

 

And second problem.

Why is that correct

output.Pos = mul(inPos, wvp);

And this is wrong??

output.Pos = mul(wvp, inPos);

HLSL uses column matrices, and as far as i know from theory, to transform a vector you multiply matrix * vector.

 

Could someone explain what is goin on here? What am i missing in the matrix mess?

Thanks in advance


Multithreaded User Interface

Multithreaded User Interface

Hello, I want to move the whole UI logic + rendering, which is based on flash, on a separate thread, while the game logic will be on the main thread.

Have any of you met this problem and how did you solve it?

Do think it is practical to make any part of the UI multithreaded, or it should be left in the main thread, since there might be a lot of synchronization in some screens between the UI thread and main thread?


Coding Languages For Starting Game Design

Coding Languages For Starting Game Design

What languages do you guys find that are the easiest to work with when learning how to code for video games?

I'll read the books or take the classes or watch the videos to learn it, but it's a little overwhelming how many coding languages exist out there, so I'm just looking for a language to begin with.

 

Truth is, I've got a small amount of experience with C++ and almost nothing else (HTML doesn't really count.)

I also know there are a fair number of computer languages out there that has the processing capability to create games for all sorts of media (whether its for retro systems, arcades, PC, mobile, whatever.)  I would be most interested in coding for retro systems, but I'm open to suggestions.


Visual Studio Compilation Problem

Visual Studio Compilation Problem

I tried to compile some code and got:

fatal error C1083: Cannot open include file: 'atlimage.h': No such file or directory

 

I searched the whole computer and I have not this file. I checked vc files and microsoft windows sdk. Where I can download this file, is it included in another vc versions? I saw on the internet that not only I had this problem but I didn't find a solution.I think that this file should be in windows SDK. Could you check it?


Need Explanation With Distance Between Two Segments

Need Explanation With Distance Between Two Segments

The code below is from book Real-Time Collection Detection ch5.cpp file

Some of them I don't know where it come from.

 

float denom = a*e-b*b;

 

what does this mean?I know a is square length of d1,e is square length of d2,b is d1 projection on d2,

but what does a*e-b*b means?where this guy come from,for what reason?any rule or fomular ralated??

Can somebody point me the direction or something to figure this out.Thanks

// Computes closest points C1 and C2 of S1(s)=P1+s*(Q1-P1) and
// S2(t)=P2+t*(Q2-P2), returning s and t. Function result is squared
// distance between between S1(s) and S2(t)
float ClosestPtSegmentSegment(Point p1, Point q1, Point p2, Point q2,
                              float &s, float &t, Point &c1, Point &c2)
{
    Vector d1 = q1 - p1; // Direction vector of segment S1
    Vector d2 = q2 - p2; // Direction vector of segment S2
    Vector r = p1 - p2;
    float a = Dot(d1, d1); // Squared length of segment S1, always nonnegative
    float e = Dot(d2, d2); // Squared length of segment S2, always nonnegative
    float f = Dot(d2, r);

    // Check if either or both segments degenerate into points
    if (a <= EPSILON && e <= EPSILON) {
        // Both segments degenerate into points
        s = t = 0.0f;
        c1 = p1;
        c2 = p2;
        return Dot(c1 - c2, c1 - c2);
    }
    if (a <= EPSILON) {
        // First segment degenerates into a point
        s = 0.0f;
        t = f / e; // s = 0 => t = (b*s + f) / e = f / e
        t = Clamp(t, 0.0f, 1.0f);
    } else {
        float c = Dot(d1, r);
        if (e <= EPSILON) {
            // Second segment degenerates into a point
            t = 0.0f;
            s = Clamp(-c / a, 0.0f, 1.0f); // t = 0 => s = (b*t - c) / a = -c / a
        } else {
            // The general nondegenerate case starts here
            float b = Dot(d1, d2);
            float denom = a*e-b*b; // Always nonnegative,======================================Here is the one ======================================

            // If segments not parallel, compute closest point on L1 to L2, and
            // clamp to segment S1. Else pick arbitrary s (here 0)
            if (denom != 0.0f) {
                s = Clamp((b*f - c*e) / denom, 0.0f, 1.0f);
            } else s = 0.0f;

            // Compute point on L2 closest to S1(s) using
            // t = Dot((P1+D1*s)-P2,D2) / Dot(D2,D2) = (b*s + f) / e
            t = (b*s + f) / e;

            // If t in [0,1] done. Else clamp t, recompute s for the new value
            // of t using s = Dot((P2+D2*t)-P1,D1) / Dot(D1,D1)= (t*b - c) / a
            // and clamp s to [0, 1]
            if (t < 0.0f) {
                t = 0.0f;
                s = Clamp(-c / a, 0.0f, 1.0f);
            } else if (t > 1.0f) {
                t = 1.0f;
                s = Clamp((b - c) / a, 0.0f, 1.0f);
            }
        }
    }

    c1 = p1 + d1 * s;
    c2 = p2 + d2 * t;
    return Dot(c1 - c2, c1 - c2);
}