why these 'if' seems ignored?

Pages: 123
Nov 19, 2022 at 9:28am
Cambalinho wrote:
i found that i lose 600FPS here

When you get such high FPS the slightest slowdown will make the FPS drop dramatically.

It's often more relevant to look at the average time spent per frame.

X FPS = 1000/X milliseconds (ms) per frame

1000 FPS = 1 ms per frame
800 FPS = 1.25 ms per frame
600 FPS ≈ 1.67 ms per frame
400 FPS = 2.5 ms per frame
200 FPS = 5 ms per frame
100 FPS = 10 ms per frame
50 FPS = 20 ms per frame
25 FPS = 40 ms per frame
10 FPS = 100 ms per frame

I don't know what FPS you had without that code but you said you lost 600 FPS so it must have been higher than that.

If you had 800 FPS before and 200 FPS after that is an increase of 3.75 ms per frame. That's not a whole lot.

If you had 610 FPS before and 10 FPS after that is an increase of about 98 ms per frame, which is quite a bit more.
Last edited on Nov 19, 2022 at 9:39am
Nov 19, 2022 at 7:58pm
before continue let me ask you 1 thing: draw these line dot a dot, using Z, is the same that i change Origin3D to Origin2D and Destiny3D to Destiny2D? the result will be the same?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
void DrawLine2(float X0, float Y0, float Z0, float X1, float Y1, float Z1, COLORREF LineColor = RGB(255,0,0))
    {
        //Calculate the Perspective:
        float EyeDistance = 500;
        float d = EyeDistance+Z0; // Note that Z==0 is irrelevant here
        float Perspective = (d != 0) ? (EyeDistance/d) : 0;
        float X2D0 = X0*Perspective;
        float Y2D0 = Y0*Perspective;
        d = EyeDistance+Z1;
        Perspective = (d != 0) ? (EyeDistance/d) : 0;

        //Convert the 3D coordenates to 2D coordenates:
        float X2D1 = X1*Perspective;
        float Y2D1 = Y1*Perspective;

        //Getting Line Distance(float results):
        float DX = X2D1 - X2D0;
        float DY = Y2D1 - Y2D0;
        float LineDistance =sqrt((DX * DX) + (DY * DY));
        if(LineDistance < 1) return;


        //Getting the Steps incrementation(float results):
        float XSteps = DX/LineDistance;
        float YSteps = DY/LineDistance;

        //Draw Line using the Steps\ Incrementation:
        float X = X2D0;
        float Y = Y2D0;

        //Getting RGB from the color:
        BYTE R = GetRValue(LineColor);
        BYTE G = GetGValue(LineColor);
        BYTE B = GetBValue(LineColor);

        for(int i=0; i<LineDistance; i++)
        {
            //Draw the pixel on valid positions:
            if(X<Width && X>=0 && Y<Height && Y>=0)
            {
                size_t pixelOffset = Y * scanlineSize + X * pixelSize;
                int PosR = pixelOffset+2;
                int PosG = pixelOffset+1;
                int PosB = pixelOffset+0;

                Pixels[PosR]=R;
                Pixels[PosG]=G;
                Pixels[PosB]=B;
            }


            //Increment steps(integer results):
            X+=XSteps;
            Y+=YSteps;
        }
    }

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
int main()
{
    HDC HDCConsole = GetConsoleHDC();

    RECT rec;
    GetClientRect(GetConsoleWindow(),&rec);

    int Speed=1;
    LineSteps line(20,100,100,700,400,700);
    image test(1000,600);

    int FramePerSecond=0;
    int Frames=0;
    RECT rec2 ={0,30,170,50};
    auto Start =GetTickCount();
    do
    {
        test.Clear();
        string s="Frame Per Second: " + to_string(FramePerSecond);
        DrawText(test,s.c_str(),-1, &rec2, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
        int TextureY=0;

        for(int i=0; i<600; i++)
        {
          test.DrawLine(line.OriginX, line.OriginY+i, line.OriginZ, line.DestinationX, line.DestinationY+i, line.DestinationZ,RGB(0,255,0), false);
          
        }
        BitBlt(HDCConsole,50,0,test.Width, test.Height,test,0,0,SRCCOPY);
/////////////************** 

is the Speed that i need, but i get unexpected results :(
results: https://imgur.com/R9xMqCF
Last edited on Nov 19, 2022 at 8:21pm
Nov 22, 2022 at 12:47pm
In theory it should work. I'd suggest to try with one line and see where it goes wrong.

Is the background properly cleared?
Nov 22, 2022 at 10:46pm
yes.... i'm doing another test.. maybe i can win much more speed. i'm testing the multithread.
i will go back here
Topic archived. No new replies allowed.
Pages: 123