September 23, 2019, 03:05:11 PM

Author Topic: Optimizing resources for a game  (Read 279 times)

Offline Santiago

  • Jr. Member
  • **
  • Posts: 48
  • Blitz3d
    • Indiesoft
Optimizing resources for a game
« on: August 26, 2019, 09:50:34 PM »
Optimizing resources for a game to work well on any computer.

The problem is when I have 30,000 lines of code, many functions, many types, objects, elements and updates for everything.

To know where there are leaks of resources, I must make my own programs to find the problems.

Now, I'm going to make the Naval Simulator have an extreme Lowdetail, skybox, noreflects, noshoadows, etc. etc., because laptops don't work well.

I show you some of the methods I use to find problems.

- function to see how many millisecs use each function or sector of code.
- information about memory, pc, video, etc
- Graphics to see data save in stadistics each day the soft is running, like a Log for sistem information, fps, memory, video memory, polycounts, etc

but anyway the battle to control resourses is a lost battle, allways. :)











i wrote today this soft to see graphics, for future use, fps, polycount, freemem, or any data that i want to see to managment the resources.
Code: [Select]
gancho = 1800
Graphics gancho,800,0,2

ClsColor 10,20,30
ClsColor 230,230,230
Cls



folder$ = "users\estadisticas\"

myDir=ReadDir(folder$)
Repeat
archivo$=NextFile$(myDir)

If FileType(folder$+"\"+archivo$) = 1 Then

file = ReadFile(folder$+"\"+archivo$)

i=0
While Not Eof(file)

i=i+1

linea$ =  ReadLine(file)

extraer(linea$)


Wend

CloseFile file

End If

If archivo$="" Then Exit

Forever
CloseDir myDir


Type dato
Field fecha$
Field valor%
Field nombre$
End Type

Type variable
Field nombre$
Field c%[3]
Field over
Field visible

End Type


Function extraer(linea$)

;si el int de la izq es un numero, extra de izq a der
;si no, extre el nombre primero y luego el numero


If Int(linea$) <> 0 Then

dato.dato = New dato
dato\valor = Int(linea$)
dato\nombre = Right(linea$,Len(linea)-Len(Str(dato\valor)))

;DebugLog "A " +dato\nombre$[i] + "  " + dato\valor[i]


Else

pos =  Instr(linea$,":",1)
If pos <> 0 Then

dato.dato = New dato
dato\nombre = Left(linea$,pos)
dato\valor = Int(Right(linea$,Len(linea)-pos))

;DebugLog "B " +dato\nombre$[i] +" "+ dato\valor[i]
End If

End If



End Function


c_datos = 0
c_campos = 0
c_variables = 0

For dato.dato = Each dato
existe = 0
c_datos = c_datos + 1
If dato\nombre$ <> "" Then
c_campos = c_campos + 1

For v.variable = Each variable
If v\nombre$ = dato\nombre$  Then
existe = 1
End If
Next

If existe = 0 Then
v.variable = New variable
v\nombre = dato\nombre$
v\c[1] = Rnd(10,255)
v\c[2] = Rnd(10,255)
v\c[3] = Rnd(10,255)
End If


End If
Next

For v.variable = Each variable
c_variables = c_variables + 1
Next

f_normal = LoadFont("arial",18,1)
f_small = LoadFont("arial",12)

While Not KeyHit(1)


Text 10,10,"Datos : " + c_datos
Text 10,30,"campos : " + c_campos
Text 10,50,"variables : " + c_variables



x0 = 400
y0 = 750
ancho = gancho
line_ancho = 1
paso = 40

Color 255,255,255
Line x0,y0,ancho,y0

For i = 0 To 1000 Step 50
Color 50,50,50
Line x0,y0-i,ancho,y0-i
Next

my = MouseY()
mx = MouseX()
vc = 0



For v.variable = Each variable
SetFont f_normal
x = x0
y = y0

Color 255,255,255

Text 10,100,my

xt = 10
yt = 100
vc = vc + 15

yvt = yt+vc

If Abs(my-yvt) < 10 Then
v\over = 1
If MouseHit(1) Then
If v\visible = 1 Then v\visible = 0 Else v\visible = 1
End If

Else
v\over = 0
End If


If v\over = 1 Or v\visible = 1 Then
Color v\c[1],v\c[2],v\c[3]
Else
Color 50,50,50
End If

Text xt,yvt,v\nombre,0,1

last_valor = 0
If v\visible = 1 Then
For dato.dato = Each dato
If dato\nombre$ = v\nombre$  Then
valor = dato\valor
While valor > 600
valor = valor *.1
Wend


x=x+ paso
For la = 0 To line_ancho
Line x-paso,y-last_valor-la,x,y-valor-la
Next

SetFont f_small
Text x,y-valor-15,dato\valor,1,1
last_valor = valor
End If
Next
End If

Next

If MouseDown(1) Then Cls

Flip

Wend

End


the .txt files i save all time i run the app

Quote
Santiago Gonzalez nombre del usuario
01 Nov 2018 fecha de inicio de la partida
17:39:43 hora de inicio de la partida
298791 segundos
SISTEMA
684 fps maximo
0 fps minimo
59 fps promedio
2 salidas abruptas del soft
2564 inicializaciones del soft
NAVEGACION
288186 segundos en navegacion
10605 segundos en la carta
SISTEMA 2
Resolucion : 1360 x 768 0 Bits
FPS : 61
Millisecs : 9486990
miMillisecs : 9486990
HWTexUnits Availables :8
Triangles Rendered    : 23191
Free Video memory : 1615 mb
 
 G_FX : 1
 g_rays_posprocces : 1
 g_shadow : 1
 g_water_type : 10
 
 PC_BrushBlendsSrc : 8191
 PC_BrushBlendsDest : 8191
 PC_TextureCaps : 1613
 PC_TextureBlends : 16777215
 PC_TextureMaxStages : 8
 PC_TextureMaxWidth : 4096
 PC_TextureMaxHeight : 4096
 PC_TextureMaxAspectRatio : 8192
 PC_ClipplanesMax : 6
 PC_LightsMax : 8
 PC_Bump : 1
 PC_BumpLum : 1
 PC_AnisotropyMax : 16
 g_d_reflejos : 1
 g_d_sombras : 1
 g_d_particulas : 1
 g_d_detalles : 1

Offline Qube

  • Administrator
  • Hero Member
  • *****
  • Posts: 2115
Re: Optimizing resources for a game
« Reply #1 on: August 26, 2019, 11:33:59 PM »
I’d say you have the right idea in that you have settings to reduce graphical features, texture size and also screen resolution.
Until the next time...

Offline RemiD

  • Hero Member
  • *****
  • Posts: 852
Re: Optimizing resources for a game
« Reply #2 on: August 31, 2019, 09:34:35 AM »
some tips to make your loop / rendering faster :
->separate logic and rendering, so that you can decide to render only the necessary surfaces
->use out of camera view culling, and hidden surfaces culling
->merge several surfaces which use the same material in one
->use copyentity() of a source mesh instead of copymesh() or loadmesh()
->don't run a routine each loop (AI, pathfinding, gui update, etc...)
->allow to activate or disactivate some graphics effects (glow, reflections, depth of field, blur, real time lighting shading, shadows, etc...)
->use one surface one texture per entity (unless you can merge them or copy them...)
->use "impostors" (=textured quads), or "far away environement box" (=skybox but for sky + terrain + buildings) for big far away shapes, instead of rendering complex meshes and textures...
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline Santiago

  • Jr. Member
  • **
  • Posts: 48
  • Blitz3d
    • Indiesoft
Re: Optimizing resources for a game
« Reply #3 on: September 09, 2019, 05:10:53 PM »

uuuu, thanks for reminding me of all that!

especially about separating the logic of the render.

I used to use a code that I think was called Frametweek, or something like that, that separated the logic from the render.

I'm going to look for it in my blitz files!

I will take that list as the 10 commandments, since some stop applying them.

Greetings!!

Offline grindalf

  • Jr. Member
  • **
  • Posts: 75
Re: Optimizing resources for a game
« Reply #4 on: September 09, 2019, 06:38:05 PM »
I would suggest using Blitz3D-NG. I was using Vanilla Blitz3D and had an issue with a MAV and everybody assumed it was a NaN object but I could not track down what was wrong. When running it in B3DNG I didn't get the mav anymore, it also runs a little smoother and slightly faster.

Offline RemiD

  • Hero Member
  • *****
  • Posts: 852
Re: Optimizing resources for a game
« Reply #5 on: September 09, 2019, 06:43:56 PM »
Quote
but I could not track down what was wrong.
well, i bet that the problem was more your code than blitz3d (or please show us what is the mysterious unknown bug!)  ;)

(i have found only 1 bug which was caused by Blitz3d, but that's all, and i have done many many many tests...)
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline RemiD

  • Hero Member
  • *****
  • Posts: 852
Re: Optimizing resources for a game
« Reply #6 on: September 09, 2019, 06:45:45 PM »
@santiago>> hidden (= not visible) surfaces determination and culling (=not considered for rendering), is very powerfull if done smartly.
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline grindalf

  • Jr. Member
  • **
  • Posts: 75
Re: Optimizing resources for a game
« Reply #7 on: September 10, 2019, 09:44:00 AM »
I never actually said it was Blitz that caused my NaN object. but NG stopped it from being an issue.
And no Im not posting my 30000 plus lines of code here :P

Online Derron

  • Hero Member
  • *****
  • Posts: 2419
Re: Optimizing resources for a game
« Reply #8 on: September 10, 2019, 10:26:45 AM »
No need for 30k+ LOC, just post the line with the piece of code creating the error  :P


Ok, now serious again: Sometimes replacing functions with stubs (or commenting out things) helps to narrow down issues.


bye
Ron