Guest Posted October 28, 2005 Report Share Posted October 28, 2005 Witam! chodzi o to ze napisalem "gierke", a raczej ciagle ja pisze ;p bazujacej na GOL, no i wyciaga mi ledwo 21-32 FPS'y :/ prubowalem juz z TThread (chyba tak sie to pisalo) i z grupowaniem kodu na odpowiedznie procedury ale ciagle bez zmian wiec moze wy mi poradzicie cos ? Link to comment Share on other sites More sharing options...
Iskar Posted October 29, 2005 Report Share Posted October 29, 2005 Musisz pobawić sie w optymlizację kodu, starać się przyspieszyć najważniejsze procki/funkcje, sprawdzić, co jest nie potrzebne. Wychwyć najsłabszą cześć kodu i skup się na niej. Może za często wykonujesz jakieś złożone obliczenia itp.?..popatrz co można by zrobić lepiej, możę nie potrzebnie ładujesz ogromne dane z plików do pamięci? Napisz może coś więcej o projekcie, albo zapodaj procki/fun, które wiesz, że można by przyspieszyć, ale nie wiesz jak. Link to comment Share on other sites More sharing options...
LukaStrz Posted October 29, 2005 Report Share Posted October 29, 2005 1. Rysowania elementów stałych (nieruchomych) np: Góry, Drzewa, kamienie (nie wiem czy dobre przykłady do Towjego projektu dałem) umieść w listach.Coś takiego:KOD type Tengine=class private procedure rob_Drzewa; public procedure Listy(); procedure RenderSko; end;var Engine:Tengine; Drzewko:Gluint; // lista wyswietlania drzew{***************************************************************************}procedure Tengine.rob_Drzewa;var i:integer;begin(...)end;{***************************************************************************}procedure Tengine.Listy;begin drzewko:=glGenLists(4); glNewList(drzewko,GL_COMPILE); Rob_Drzewa; glEndList(); (...)end;I rysowanie wywołujesz nie poprzez rob_Drzewa tylko poprzez Listy. 2. Gdy masz wiele textur w programie to rób tak aby zmieniac je przy rysowania jak najmniej razy. Tzn. włączasz texture1, rysujesz wszystko co z niej korzysta (nieważne czy jest to na pierwszym planie czy całkiem w tle), następnie textura2 i to samo. Link to comment Share on other sites More sharing options...
Guest Posted October 29, 2005 Report Share Posted October 29, 2005 To moze zapodam wiekszym kawalkiem kodu ale ostrzegam wiekszosc ludzi mowi ze strasznie wyglada moj kod zrudlowy KODunit mapper;interfaceuses Windows, Messages, SysUtils, OpenGl, Gl, Glu;procedure Lmap;procedure Tmap;varXX, XX2, YY, YY2, i, licz, MX, PX, MZ, PZ, ii, jj, kk, m, przesow: integer;implementationuses Render;procedure Lmap;beginif pier1 = true thenbeginfor ii := 0 to 7 dofor jj := 0 to 7 dofor kk := 0 to 3 doTchoinka[ii, jj, kk] := random(64)+64;pier1 := False;end;if (X >= -50) and (X <= -40)thenbegin PX := 1; MX := -50;end;if (X >= -40) and (X <= -30)thenbegin PX := 2; MX := -40;end;if (X >= -30) and (X <= -20)thenbegin PX := 3; MX := -30;end;if (X >= -20) and (X <= -10)thenbegin PX := 4; MX := -20;end;if (X >= -10) and (X <= 0) thenbegin PX := 5; MX := -10;end;if (X >= 0) and (X <= 10) thenbegin PX := 6; MX := 0;end;if (X >= 10) and (X <= 20) thenbegin PX := 7; MX := 10;end;if (X >= 20) and (X <= 30) thenbegin PX := 8; MX := 20;end;if (X >= 30) and (X <= 40) thenbegin PX := 9; MX := 30;end;if (X >= 40) and (X <= 50) thenbegin PX := 10; MX := 40;end;if (X >= 50) and (X <= 60) thenbegin PX := 11; MX := 50;end;if (X >= 60) and (X <= 70) thenbegin PX := 12; MX := 60;end;if (X >= 70) and (X <= 80) thenbegin PX := 13; MX := 70;end;if (X >= 80) and (X <= 90) thenbegin PX := 14; MX := 80;end;if (X >= 90) and (X <= 100)thenbegin PX := 15; MX := 90;end;if (X >= 100) and (X <= 110)thenbegin PX := 16; MX := 100;end;if (X >= 110) and (X <= 120)thenbegin PX := 17; MX := 110;end;if (X >= 120) and (X <= 130)thenbegin PX := 18; MX := 120;end;if (X >= 130) and (X <= 140)thenbegin PX := 19; MX := 130;end;if (X >= 140) and (X <= 150)thenbegin PX := 20; MX := 140;end;if (X >= 150) and (X <= 160)thenbegin PX := 21; MX := 150;end;if (X >= 160) and (X <= 170)thenbegin PX := 22; MX := 160;end;if (Z >= -40) and (Z <= -30)thenbeginPZ := 19;MZ := -40;end;if (Z >= -30) and (Z <= -20)thenbeginPZ := 18;MZ := -30;end;if (Z >= -20) and (Z <= -10)thenbeginPZ := 17;MZ := -20;end;if (Z >= -10) and (Z <= 0) thenbeginPZ := 16;MZ := -10;end;if (Z >= 0) and (Z <= 10) thenbeginPZ := 15;MZ := 0;end;if (Z >= 10) and (Z <= 20) thenbeginPZ := 14;MZ := 10;end;if (Z >= 20) and (Z <= 30) thenbeginPZ := 13;MZ := 20;end;if (Z >= 30) and (Z <= 40) thenbeginPZ := 12;MZ := 30;end;if (Z >= 40) and (Z <= 50) thenbeginPZ := 11;MZ := 40;end;if (Z >= 50) and (Z <= 60) thenbeginPZ := 10;MZ := 50;end;if (Z >= 60) and (Z <= 70) thenbeginPZ := 9;MZ := 60;end;if (Z >= 70) and (Z <= 80) thenbeginPZ := 8;MZ := 70;end;if (Z >= 80) and (Z <= 90) thenbeginPZ := 7;MZ := 80;end;if (Z >= 90) and (Z <= 100)thenbeginPZ := 6;MZ := 90;end;if (Z >= 100) and (Z <= 110)thenbeginPZ := 5;MZ := 100;end;if (Z >= 110) and (Z <= 120)thenbeginPZ := 4;MZ := 110;end;if (Z >= 120) and (Z <= 130)thenbeginPZ := 3;MZ := 120;end;if (Z >= 130) and (Z <= 140)thenbeginPZ := 2;MZ := 130;end;if (Z >= 140) and (Z <= 150)thenbeginPZ := 1;MZ := 140;end;for m := 0 to 8 dobeginif M =0 thenbeginPX := PX-1;PZ := PZ-1;end;if M =1 thenbeginPX := PX-1end;if M =2 thenbeginPX := PX-1;PZ := PZ+1;end;if M =3 thenbeginPZ := PZ-1;end;if M =4 thenbeginend;if M =5 thenbeginPZ := PZ+1;end;if M =6 thenbeginPX := PX+1;PZ := PZ-1;end;if M =7 thenbeginPX := PX+1;end;if M =8 thenbeginPX := PX+1;PZ := PZ+1;end;assignfile(TF,ExtractFilePath('mapper')+'mapyTWG'+IntToStr(PZ)+'_'+IntToStr(PX)+'.map');if not fileExists(ExtractFilePath('mapper')+'mapyTWG'+IntToStr(PZ)+'_'+IntToStr(PX)+'.map')thenbeginfor YY := 0 to 9 dofor XX := 0 to 9 domapa[m][YY][XX]:= 0;end elsebeginreset(TF);licz:=-1;while not(eof(TF)) dobegininc(licz);readln(TF,str);for I := 1 to length(str) dobeginif str[I]='0' then mapa[m][licz][I-1]:= 0;if str[I]='1' then mapa[m][licz][I-1]:= 1;if str[I]='2' then mapa[m][licz][I-1]:= 2;end;end;closefile(TF);end;if M =0 thenbeginPX := PX+1;PZ := PZ+1;end;if M =1 thenbeginPX := PX+1end;if M =2 thenbeginPX := PX+1;PZ := PZ-1;end;if M =3 thenbeginPZ := PZ+1;end;if M =4 thenbeginend;if M =5 thenbeginPZ := PZ-1;end;if M =6 thenbeginPX := PX-1;PZ := PZ+1;end;if M =7 thenbeginPX := PX-1;end;if M =8 thenbeginPX := PX-1;PZ := PZ-1;end;end; {for YY := 0 to 9 dofor XX := 0 to 9 dobeginif (x+cos(t)/20 >= XX+MX) and (x+cos(t)/20 <= XX+1+MX)thenif (z+sin(t)/20 >= YY+MZ) and (z+sin(t)/20 <= YY+1+MZ) thenbeginif mapa[4,XX,YY] <> 0 thenprzeszkoda_P := false;if mapa[4,XX,YY] = 0 thenprzeszkoda_P := true;end;if (x-cos(t)/20 >= XX+MX) and (x-cos(t)/20 <= XX+1+MX)thenif (z-sin(t)/20 >= YY+MZ) and (z-sin(t)/20 <= YY+1+MZ) thenbeginif mapa[4,XX,YY] <> 0 thenprzeszkoda_T := false;if mapa[4,XX,YY] = 0 then przeszkoda_T := true;end;end; }end;procedure Tmap;beginfor m := 0 to 8 dobeginif M =0 thenbeginPX := PX-1;PZ := PZ-1;end;if M =1 thenbeginPX := PX-1;end;if M =2 thenbeginPX := PX-1;PZ := PZ+1;end;if M =3 thenbeginPZ := PZ-1;end;if M =4 thenbeginend;if M =5 thenbeginPZ := PZ+1;end;if M =6 thenbeginPX := PX+1;PZ := PZ-1;end;if M =7 thenbeginPX := PX+1;end;if M =8 thenbeginPX := PX+1;PZ := PZ+1;end;assignfile(TF2,ExtractFilePath('mapper')+'mapyTPG'+IntToStr(PZ)+'_'+IntToStr(PX)+'_T.map');if FileExists(ExtractFilePath('mapper')+'mapyTPG'+IntToStr(PZ)+'_'+IntToStr(PX)+'_T.map')thenbeginreset(TF2);licz:=-1;while not(eof(TF2)) dobegininc(licz);readln(TF2,str);for I := 1 to length(str) dobeginif M =0 thenbeginMX := MX-10;MZ := MZ+10;end;if M =1 thenbeginMX := MX-10end;if M =2 thenbeginMX := MX-10;MZ := MZ-10;end;if M =3 thenbeginMZ := MZ+10;end;if M =4 thenbeginend;if M =5 thenbeginMZ := MZ-10;end;if M =6 thenbeginMX := MX+10;MZ := MZ+10;end;if M =7 thenbeginMX := MX+10;end;if M =8 thenbeginMX := MX+10;MZ := MZ-10;end;if str[I]='T' thenbeginglEnable(GL_TEXTURE_2D);glTexImage2D(GL_TEXTURE_2D,0,3,32,32,0,GL_RGB, GL_UNSIGNED_BYTE,@Ttrawa);glcolor3f(0.1,0.4,0.1);glbegin(GL_QUADS); glTexCoord2f(0,0); glVertex3f(0+MX+licz*1,0,0+MZ+(I-1)*1); glTexCoord2f(0,1); glVertex3f(0+MX+licz*1,0,1+MZ+(I-1)*1); glTexCoord2f(1,1); glVertex3f(1+MX+licz*1,0,1+MZ+(I-1)*1); glTexCoord2f(1,0); glVertex3f(1+MX+licz*1,0,0+MZ+(I-1)*1);glEnd();glPopAttrib;end;if str[I]= 'W' thenbeginglEnable(GL_TEXTURE_2D);glTexImage2D(GL_TEXTURE_2D,0,4,8,8,0,GL_RGB, GL_UNSIGNED_BYTE,@Tpiach);glcolor3f(0,0,0.35);glbegin(GL_QUADS); glTexCoord2f(0,0); glVertex3f(0+MX+licz*1,0,0+MZ+(I-1)*1); glTexCoord2f(0,1); glVertex3f(0+MX+licz*1,0,1+MZ+(I-1)*1); glTexCoord2f(1,1); glVertex3f(1+MX+licz*1,0,1+MZ+(I-1)*1); glTexCoord2f(1,0); glVertex3f(1+MX+licz*1,0,0+MZ+(I-1)*1);glEnd();end;if str[I]= 'P' thenbeginglEnable(GL_TEXTURE_2D);glTexImage2D(GL_TEXTURE_2D,0,4,8,8,0,GL_RGB, GL_UNSIGNED_BYTE,@Tpiach);glcolor3f(0.1,0.4,0.1);glbegin(GL_QUADS); glcolor3f(1,1,0); glTexCoord2f(0,0); glVertex3f(0+MX+licz*1,0,0+MZ+(I-1)*1); glTexCoord2f(0,1); glVertex3f(0+MX+licz*1,0,1+MZ+(I-1)*1); glTexCoord2f(1,1); glVertex3f(1+MX+licz*1,0,1+MZ+(I-1)*1); glTexCoord2f(1,0); glVertex3f(1+MX+licz*1,0,0+MZ+(I-1)*1);glEnd();glPopAttrib;end;if m = 4 thenif (x+cos(t)/20 >= licz+MX) and (x+cos(t)/20 <= licz+1+MX)thenif (z+sin(t)/20 >= (I-1)+MZ) and (z+sin(t)/20 <= (I-1)+1+MZ) thenbeginif str[I]= 'W'thenprzeszkoda_P := false;if str[I]<> 'W' then//przeszkoda_P := true;end;if (x-cos(t)/20 >= licz+MX) and (x-cos(t)/20 <= licz+1+MX)thenif (z-sin(t)/20 >= (I-1)+MZ) and (z-sin(t)/20 <= (I-1)+1+MZ) thenbeginif str[I]= 'W'thenprzeszkoda_T := false;if str[I]<> 'W' then//przeszkoda_T := true;end;if M =0 thenbeginMX := MX+10;MZ := MZ-10;end;if M =1 thenbeginMX := MX+10end;if M =2 thenbeginMX := MX+10;MZ := MZ+10;end;if M =3 thenbeginMZ := MZ-10;end;if M =4 thenbeginend;if M =5 thenbeginMZ := MZ+10;end;if M =6 thenbeginMX := MX-10;MZ := MZ-10;end;if M =7 thenbeginMX := MX-10;end;if M =8 thenbeginMX := MX-10;MZ := MZ+10;end;end;end;closefile(TF2);end;if M =0 thenbeginPX := PX+1;PZ := PZ+1;end;if M =1 thenbeginPX := PX+1end;if M =2 thenbeginPX := PX+1;PZ := PZ-1;end;if M =3 thenbeginPZ := PZ+1;end;if M =4 thenbeginend;if M =5 thenbeginPZ := PZ-1;end;if M =6 thenbeginPX := PX-1;PZ := PZ+1;end;if M =7 thenbeginPX := PX-1;end;if M =8 thenbeginPX := PX-1;PZ := PZ-1;end;end;end;end.To jest kod do wczytywania mapy terenu w stylu Drzewa, krzaki itd. nastepnie jest wczytywanie podloza czyli trawa piach itd. i odrazu jest wyswietlanie tego :> Wiem mozna bylo to napisac docej i zapewne polowa rzeczy jest do kitu pomyslana no ale mam nadzieje ze pomozecie mi to zoptymalizowac :>// EDIT by HNB nie źrudło tylko źródło! jakie byki ;(// kod wygląda naprawdę strasznie...stosuj wcięcia, spójrz na swój kod: [code=Delphi] if m = 4 then if (x+cos(t)/20 >= licz+MX) and (x+cos(t) HXJÓV ][BY [ K H KLJJÓVH[B6Bó#fCłÓłFV\0Ś&Vv\0Śb7G%ÓuŃĄ4)}@ą4)Ńm%tąŃĄ //przeszkoda_P := true; end; if (x-cos(t)/20 >= liczÓV H[ XĘ K HXJÓV ][BY [ KfwCłÓćB6Bó#fCłÓłFV\0Ś&V4)Ńm%tŃĄ4)}Pą4)Ńm%tlt;> 'W' then //przeszkoda_T := true; end;*hŻ ĘĘk)Ź~ćj0j|ŚŚź^bpvbBFV\0bś62Bó#fwCłĆ7ćBś62źąąŹ5`ŃĄ4(ĄĄźĄ$Z) and (z+sin(t)/20 <= (I-1)+1+MZ) then begin (YWOH [BWH[NBb7G%fCfwCurrFV\0'ŚW7ŚśFŁG'VS4(4(4)ĄĄźą5`ĄĄ0 <= licz+1+MX)then if (z-sin(t)/20 >= (I-1)+MZ) k [ K H KLJJJÓVH[BY[BYÓurwFV\0'ŚW7ŚśFBŁf6S\0b7G%aŃĄ4(ź}PŃ4( [/code]Poza tym, nie stosuj znaczników code tylko syntax="delphi"Iskar Link to comment Share on other sites More sharing options...
Guest Posted October 29, 2005 Report Share Posted October 29, 2005 masz rację, że wygląda strasznie bo nie ma wcięć ! :twisted: Jakiś czas temu ( w wakację) bawiłem się w OGL-a i wsumie rysowanie glVertex-em to sobie odpuść już na starcie to się nadaje by narysować jakieś menu albo coś... Skorzystaj z tablic wierzchołków, list wyświetlania i lepiej z VBO jeszcze . Jak załapiesz t.wierzchołków to dodanie do nich VBO które da ci dość przyzwoitego kopa to jest kwesja około 20-30 linijek.Przykładowy tutorial o Vertex buffer object: http://steinsoft.net/index.php?site=Progra...ets/OpenGL/no11Jest dość krótki i prosty. Link to comment Share on other sites More sharing options...
5corpio Posted October 29, 2005 Report Share Posted October 29, 2005 Ten post powyżej to mój ale zapomniałem się lognąć . Pozatym jak już koledzy powiedzieli unikaj częstych zmian stanu maszyny OpenGL. Tak to się chyba nazywa "fachowo" czyli np. unikaj częstego: glBindTexture(). Pogrupuj trójkąty które korzystają z tej samej textury i rysuj najpierw je a potem te które korzystają z drugiej i tak dalej.PS. wrzuć ten kod na jakiś link bo trzeba strasznie dużo przewijać. Pozatym jak po warunku if masz wykonywaną tylko jedną instrukcję to nie musisz dawać begin end; tylko piszesz:if (Warunek1) and (warunek cos tam 2) then Instrukcja.Zaoszczędzasz 2-3 linijki Edit1: Po co w linijce: [code=Delphi] glVertex3f(1+MX+licz*1,0,0+MZ+(I-1)*1);fŹYĄzó{=&Śźr'\"'ł')^)zlz7Źśjez{6r6('x,ł8%Uę{hóĘZ4ćn*mjH'Źx'Ź^w*Zjnn'hłjhrr b\"3jho)jśvxŁ{ (w87Źś6vVŚ'jsŻ7ŁŻ<Ź\"zg3ĘĄb(3ui' if str[I]<> 'W' then //przeszkoda_T := true; [/code]to zakomentuj też warunek a nie tylko "skutek"I jeszcze glEnable(GL_TEXTURE_2D); tam gzieś masz pare razy to wrzuć go gdzieś w GLInit czy coś podobnego a nie wywołujesz go co chwilę. Ustaw na starcie programu, że używasz tekstur 2d i już nigdzie tego nie wpisuj. Ot taka mini-strona moja po godzinach http://www.wnetrzekuchni.pl Link to comment Share on other sites More sharing options...
Wosiedem Posted October 29, 2005 Report Share Posted October 29, 2005 [code=Delphi] if (X >= -50) and (X <= -40)then begin PX := 1; VHMLB[BBY HM H[ HL ][B&VvŁ#ŁÓCŚVćCŚbfwCłÓ3ćB`ąŃĄ4)4(A`4(5`4)4(4)X >= -20) and (X <= -10)then begin PX := 4; MX :=LB[BY HLL H[ H H[BY[BŁSŁÓŚVćCŚbfwCłćBfCłŃĄ4)4(A`4(5`4)4)Ą`nd (X <= 20) then begin PX := 7; MX := 10; end; if H H[ H H[BY[BHBV#ŚVćCŚbfwCł3ćBfCłCFVŚ&VvA`4(5`4)4)Ą`Ą`ą then begin PX := 10; MX := 40; end; if (X >= 50) [ H H[BY[BHLNBVH LB[BbfwCłcćBfCłsFVŚ&VvŁ#`4)4)Ą`Ą`ąŃĄ4) PX := 13; MX := 70; end; if (X >= 80) and (X <HL H[BY[BHMBVHB[BY HćBfCłFVŚ&VvŁSŁŚV4)Ą`Ą`ąŃĄ4)4(A` MX := 100; end; if (X >= 110) and (X <= 120)then Y[BHMBVHLLB[BY HL H[ fCł3FVŚ&VvŁŁ#ŚVćCŚbĄ`ąŃĄ4)4(A`4(5`130; end; if (X >= 140) and (X <= 150)then begin HBVHMB[BY HML H[ HcFVŚ&VvŁ#ŁSŚVćCŚbfwCłĄ`ąŃĄ4)4(A`4(5`4); [/code]Pozostałe bloki IF też można zastąpić funkcjami liniowymi (czyli tak jak zrobiłem to przed chwilą).// używaj formatowania kodu źródłowego No dobrze... zapomnialem. Przepraszam Pozdrawiam, vo7 (; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.