SyntaxBomb - Indie Coders

General Category => General Game and Application Development => Topic started by: Santiago on August 26, 2019, 09:50:34 PM

Title: Optimizing resources for a game
Post by: Santiago 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

folder$ = "users\estadisticas\"


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

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

While Not Eof(file)


linea$ =  ReadLine(file)



CloseFile file

End If

If archivo$="" Then Exit

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]


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

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

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

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

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

v\over = 0
End If

If v\over = 1 Or v\visible = 1 Then
Color v\c[1],v\c[2],v\c[3]
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

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

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


If MouseDown(1) Then Cls




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

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
684 fps maximo
0 fps minimo
59 fps promedio
2 salidas abruptas del soft
2564 inicializaciones del soft
288186 segundos en navegacion
10605 segundos en la carta
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
Title: Re: Optimizing resources for a game
Post by: Qube 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.
Title: Re: Optimizing resources for a game
Post by: RemiD 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...
Title: Re: Optimizing resources for a game
Post by: Santiago 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.

Title: Re: Optimizing resources for a game
Post by: grindalf 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.
Title: Re: Optimizing resources for a game
Post by: RemiD on September 09, 2019, 06:43:56 PM
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...)
Title: Re: Optimizing resources for a game
Post by: RemiD 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.
Title: Re: Optimizing resources for a game
Post by: grindalf 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
Title: Re: Optimizing resources for a game
Post by: Derron 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.

SimplePortal 2.3.6 © 2008-2014, SimplePortal