prob with framerate , and more xd ....

Blitz3D Forums/Blitz3D Beginners Area/prob with framerate , and more xd ....

danio(Posted 2016) [#1]
hi, as i might of posted before about this topic, about my classic engine project, im back on track and starting to work on it , as i have some time to program and stuff. so anyway, i was wondering how to fix the framerate, can anyone help me ? when i start up the test build of my engine , i get visuals of my models and a test cube that i've put in the scene , and whenever i wanna backup a little to see the models, i get 15, 20 fps , and here's the prob. so i dont know whats affecting this :( oh and how do i associate my weap models to be viewed from the 1st person perspective, because my models are for now at one point, and i still have the prob with changing the weaps so that the rest of the models would dissapear and only one should be viewed :/ i posted this prob before about the weaps, but i tried some of the code that people recommended me , and some partly worked, and some i didnt understood ;/ soo if anyone out there would help me with this, i would really apreceate for some help ;) and im sorry for some of my words, i might of wrote them incorectly because im Polish ;p


Omnicode(Posted 2016) [#2]
The model may be too complex in a way where the fps drop may be unavoidable with native Blitz3D. How many tris/textures do your models have?

The HideEntity command will toggle the visibility of an entity to false until ShowEntity for that entity is called. Hiding an entity also omits any collisions or picks on the targeted entity too. Hope that helps.


danio(Posted 2016) [#3]
the models arent actually textured yet :/ and the polies are very low, its like the Quake 1 models , and ive tried the HideEntity command, which doesnt work at all, and ive figured out how to attach the v_guns to the cam, but it doesnt seem to be visible ..... ughh, is there a blitz basic programer somewhere on facebook or skype so that i can use a little bit of help on my project ?? credits will be listed on the "credits" list xD


Cocopino(Posted 2016) [#4]
Post some code showing the error/problem you're having: chances of getting help will be a lot higher.


fox95871(Posted 2016) [#5]
Being Polish has nothing to do with it, believe me. We have less ram, but excellent processing power. As for your question, whenever I have a framerate problem, I can almost always solve it by turning off - putting semicolons before - different sections of code until I've narrowed it down to whatever's causing it. The only times I can think of where that didn't work was once when I used a physics .dll that refused to let me delete the collision mesh of the level no matter what I did, and right now actually, I'm currently unable to figure out why programs that run at between 500 and 1000 ifps on my tower run at about 50 on my laptop, when both have about the same amount of ram. But, it's your help request. One more thing I could do to help though is give you some render tweening code if you don't already use one.




danio(Posted 2016) [#6]
ok here is my code :

AppTitle "Classic Engine alpha v 0.10"
;ver history:
;alpha 0.1 - added initial functions
;alpha 0.2-.3 - experimenting with movement, added crosshair
;alpha 0.4 - .... forgot what changes i made xd, not good
;alpha 0.5 -removed my movement scheme and added other movement sheme, which did not please me d
;alpha 0.6 - recoded my movement sheme
;alpha 0.7 - added armor icon, which is terribly small :o (and then i removed it xd)
;alpha 0.8 - added more conts, and added weap slots, which dont werk >:(
;alpha 0.9 - weap models ,weap slots and collision in werk
;alpha 0.10 - werking on v_guns, which .... don't seem to show up .... god damn you Blitz Basic :'(
;
;something is slowing down the test builds..... need to figure it out
;okay ive scaled the models to a smaller size, but its still lagging

Global img_cross
Global img_barmor

HidePointer


;collisions (constants)
Const player_coll=1
Const level_coll=2
Const bullet_coll=3
Const rocket_coll=4
Const grenade_coll=5
Const light_coll=6
Const armor_coll=7
Const health1_coll=8
Const health5_coll=9
Const health25_coll=10
Const health100_coll=11
Const health200_coll=12
Const qd_coll=13
Const superqd_coll=14
Const ultimateqd_coll=15
Const hellqd_coll=16
Const item_shells_coll=17
Const item_bullets_coll=18
Const item_rockets_coll=19
Const item_cells_coll=20
Const item_backpack_coll=21
Const enemy_zombie_coll=22
Const enemy_fastzombie_coll=23
Const enemy_slowzombie_coll=24
Const enemy_redneck_coll=25
Const enemy_police_coll=26
Const enemy_soldier_coll=27
Const enemy_heavsold_coll=28
Const enemy_heavtrooper_coll=29
Const enemy_imp_coll=30
Const enemy_demon_coll=31
Const enemy_spectre_coll=32
Const enemy_ogre_coll=33
Const enemy_bigbadguy_coll=34

;types
Type bullettype
Field entityhandle
End Type

Type enemytype
Field entityhandle
Field state
End Type

;sets vid mode
Graphics3D 640,480,32,2
SetBuffer BackBuffer()


;sets up cams
player = CreatePivot()
fps_cam = CreateCamera(player)
CameraViewport fps_cam,0,0,640,480
MoveEntity fps_cam,0,0.9,0


;loads lvl objs eg. mdls, lights, terrain, water plane, skyb, sets coll
light1 = CreateLight()
cube1 = CreateCube()
PositionEntity cube1,-2,0,10


;---MAIN GAME LOOP STARTS HERE---

While Not KeyHit(1)
;keyoard/mouse controls

;keys for weap slots
weap_0 = KeyDown(2)
weap_1 = KeyDown(3)
weap_2 = KeyDown(4)
weap_3 = KeyDown(5)
weap_4 = KeyDown(6)
weap_5 = KeyDown(7)
weap_6 = KeyDown(8)
weap_7 = KeyDown(9)
weap_8 = KeyDown(10)
weap_9 = KeyDown(11)

; this is a piece of crapish code ... ugh
If weap_0 Then HideEntity(weap_sshotgun):HideEntity(weap_smg):HideEntity(weap_ssmg):HideEntity(weap_rl):HideEntity(weap_gl):HideEntity(weap_light):HideEntity(weap_bfg):ShowEntity(weap_shotgun)
If weap_1 Then HideEntity(weap_shotgun):HideEntity(weap_smg):HideEntity(weap_ssmg):HideEntity(weap_rl):HideEntity(weap_gl):HideEntity(weap_light):HideEntity(weap_bfg):ShowEntity(weap_sshotgun)
If weap_2 Then HideEntity(weap_shotgun):HideEntity(weap_sshotgun):HideEntity(weap_ssmg):HideEntity(weap_rl):HideEntity(weap_gl):HideEntity(weap_light):HideEntity(weap_bfg):ShowEntity(weap_smg)
If weap_3 Then HideEntity(weap_sshotgun):HideEntity(weap_smg):HideEntity(weap_ssmg):HideEntity(weap_rl):HideEntity(weap_gl):HideEntity(weap_light):HideEntity(weap_bfg):ShowEntity(weap_ssmg)
If weap_4 Then HideEntity(weap_sshotgun):HideEntity(weap_smg):HideEntity(weap_ssmg):HideEntity(weap_rl):HideEntity(weap_gl):HideEntity(weap_light):HideEntity(weap_bfg):ShowEntity(weap_rl)
If weap_5 Then HideEntity(weap_sshotgun):HideEntity(weap_smg):HideEntity(weap_ssmg):HideEntity(weap_rl):HideEntity(weap_gl):HideEntity(weap_light):HideEntity(weap_bfg):ShowEntity(weap_gl)
If weap_6 Then HideEntity(weap_sshotgun):HideEntity(weap_smg):HideEntity(weap_ssmg):HideEntity(weap_rl):HideEntity(weap_gl):HideEntity(weap_light):HideEntity(weap_bfg):ShowEntity(weap_light)
If weap_7 Then HideEntity(weap_sshotgun):HideEntity(weap_smg):HideEntity(weap_ssmg):HideEntity(weap_rl):HideEntity(weap_gl):HideEntity(weap_light):HideEntity(weap_bfg):ShowEntity(weap_bfg)

;wasd movement and jumping
If KeyDown(17) Then MoveEntity fps_cam,0,0,0.5 ;move forward (W)
If KeyDown(30) Then MoveEntity fps_cam,-0.5,0,0 ;strafe left (A)
If KeyDown(31) Then MoveEntity fps_cam,0,0,-0.5 ;move backwards (S)
If KeyDown(32) Then MoveEntity fps_cam,0.5,0,0 ;strafe right (D)
If KeyDown(57) Then MoveEntity fps_cam,0,0.5,0 ;jump (SPACE)
If KeyDown(29) Then MoveEntity fps_cam,0,-0.5,0 ;crouch (LFT_CTRL)

;mouse look
mxs# = mxs# + MouseXSpeed()
mys# = mys# + MouseYSpeed()

If mys# > 80 Then mys# = 80
If mys# < -80 Then mys# = -80

RotateEntity fps_cam,mys#,-mxs,0
MoveMouse 320,240


;3d stuff eg. move/animate mesh, launch projs, check coll, etc..

;first weap - shotgun, like in Quake1
weap_shotgun = LoadMesh("models\3ds\v_shotgun\v_shotgun.3ds", fps_cam)
ScaleEntity weap_shotgun,0.1,0.1,0.1
RotateEntity weap_shotgun,-90,0,0
MoveEntity weap_shotgun, .1, -.15, .1

;second weap - super shotgun, or aka double-barrel shotgun (im thinking of adding the Olympia shtgn model soon...)
weap_sshotgun = LoadMesh("models\3ds\v_sshotgun\v_sshotgun.3ds", fps_cam)
ScaleEntity weap_sshotgun,0.1,0.1,0.1
RotateEntity weap_sshotgun,-90,0,0
MoveEntity weap_sshotgun, .1, -.15, .1

;third weap - sub machine gun
weap_smg = LoadMesh("models\3ds\v_smg\v_smg.3ds", fps_cam)
ScaleEntity weap_smg,0.1,0.1,0.1
RotateEntity weap_smg,-90,0,0
MoveEntity weap_smg, .1, -.15, .1

;fourth weap - minigun, or machine gun (i cant decide to put in the m60 or the minigun as the fourth weapon xd)
weap_ssmg = LoadMesh("models\3ds\v_ssmg\v_ssmg.3ds", fps_cam)
ScaleEntity weap_ssmg,0.1,0.1,0.1
RotateEntity weap_ssmg,-90,0,0
MoveEntity weap_ssmg, .1, -.15, .1

;and finally ... THE ROCKET LAUNCHER !! :D
weap_rl = LoadMesh("models\3ds\v_rl\v_rl.3ds", fps_cam)
ScaleEntity weap_rl,0.1,0.1,0.1
RotateEntity weap_rl,-90,0,0
MoveEntity weap_rl, .1, -.15, .1

;sixth weap - grenade launcher (cant find a cool idea to make the gl look more cooler, my model is just a plain ol' block xd)
weap_gl = LoadMesh("models\3ds\v_gl\v_gl.3ds", fps_cam)
ScaleEntity weap_gl,0.1,0.1,0.1
RotateEntity weap_gl,-90,0,0
MoveEntity weap_gl, .1, -.15, .1

;seventh weap - lightning gun
weap_light = LoadMesh("models\3ds\v_light\v_light.3ds", fps_cam)
ScaleEntity weap_light,0.1,0.1,0.1
RotateEntity weap_light,-90,0,0
MoveEntity weap_light, .1, -.15, .1

;eighth weap - THE BIG FUCKING GUN !!! :D
weap_bfg = LoadMesh("models\3ds\v_bfg\v_bfg.3ds", fps_cam)
ScaleEntity weap_bfg,0.1,0.1,0.1
RotateEntity weap_bfg,-90,0,0
MoveEntity weap_bfg, .1, -.15, .1

;ill add a pistol, but i still need to work on the model itself :d

UpdateWorld
RenderWorld

;2d stuff eg. update hud, text, stats ...
LoadSprites()
DrawImage img_cross,320,240 ;crosshair
Flip

Wend
End

Include "func_classic.bb"
;subs and funcs can be inserted here


fox95871(Posted 2016) [#7]
My recommendation is to AddMesh all the weapons together. I've always found that having a lot of meshes slows things down a lot more than having a lot of polygons. So, as long as you know how many vertexes each weapon has, you can VertexColor say, vertexes 1 through 100 to be alpha 1, and vertexes 101 through 1000 to be 0, to "show" the first weapon, and "hide" the rest. It takes a little while to program, but your ifps skyrockets. And yes I've done it myself with something else, and yes I've burned a computer down before, so be careful.


Cocopino(Posted 2016) [#8]
You are using LoadMesh inside of your main loop, so it will keep loading the same meshes over and over until memory is full and your program will crash.

A tip: if you're copying the same code over and over again, you're doing something wrong. E.g. replace all your weapon loading by something like
Function LoadWeapon(file$,cam)
	local weap = LoadMesh("models\3ds\v_bfg\" + file$, cam)
	ScaleEntity weap,0.1,0.1,0.1
	RotateEntity weap,-90,0,0
	MoveEntity weap, .1, -.15, .1
	
	return weap
End Function


Then use it like:
weap_shotgun = LoadWeapon("v_shotgun.3ds", fps_cam)

(before, not inside your main loop)


danio(Posted 2016) [#9]
ahhhhhhh, ok now i get it, thanks for the tip though ;) i'll try it out and see if it works , but since there're pros out there in the community, im sure it'll work ;p


danio(Posted 2016) [#10]
Cocopino, i tried out the code you recommended me, and i get an error while building, "3D Graphics mode not set" at "Local weap = LoadMesh("models\3ds\" + file$, cam)", any suggestions ? :/


danio(Posted 2016) [#11]
ok im sorry my bad, the code works just made a mistake that i've put the code before the Graphics command xd


fox95871(Posted 2016) [#12]
Yeah, there are some commands that are "don't use this more than once!" type commands, and others you can run 1000 times a second, no problem. It's important to learn which are which. At the same time, you can get away with a lot in the main loop using tricks like runonce%=0, where some event turns runonce into a 1, then that runs the command, then runonce gets turned into a 0 again. Heck, you could probably make huge swaths of a program way more efficient than it really needs to be that way, but I think in general you can probably trust the "runtime safe" commands.