Question about HideEntity command

Blitz3D Forums/Blitz3D Programming/Question about HideEntity command

Cubed Inc.(Posted 2011) [#1]
Does the HideEntity command temporarily relieves the data of an entity or does it just hide the entity and it's collisions?


Yasha(Posted 2011) [#2]
temporarily relieves the data of an entity


Eh?

If you mean is anything freed, then no. It just drops the entity from the lists of things to render and update. Otherwise it would be unusably slow.

Consider: if anything was freed, when you showed the entity again, it would have to be loaded again. But Blitz3D has no way of knowing where to load it from!


Cubed Inc.(Posted 2011) [#3]
When I said temporarily relieves the data of an entity, I actually kinda meant it like this.

Let's say there is this game with 50 animated models rendering and animating all at once. With out the usage of any tricks, the game would run very slowely.

Now let's say a system was set up where when the space key is pressed, 40 of those 50 characters were hidden with the hideentity function. Would the game run faster with those 40 character not being visibly rendered at once, or would it make no difference to the framerate?

I'm pretty bad at explaining technical things in short terms-_-


Yasha(Posted 2011) [#4]
It should be faster. Those characters simply won't pass through the renderer, so while some maths needs to be done on their positions and so on, the engine doesn't have to work out vertex positions or any of that complicated stuff.


Cubed Inc.(Posted 2011) [#5]
thanks for explaining:P


Kryzon(Posted 2011) [#6]
Skeletally-animated models cost a lot of CPU, so I think it's even more efficient to hide them and stop their animation.

The following requires you to animate all your models manually with SetAnimTime instead of Animate:
;Pseudo-code.

Type TCharacter
Field mesh
Field visible
Field animation.TAnimaton
End Type

For C.TCharacter = Each TCharacter
	;Update visibility.
	If C\visible Then
		ShowEntity C\mesh
	Else
		HideEntity C\mesh
	EndIf
	
	;Update animation.
	If C\animation\type Then ;If the animation type is different than 'zero' (stopped).
		;Update frame-counter regardless of model's visibility:
		C\animation\frame = C\animation\frame + C\animation\speed
	
		;Manually implement animation-type behavior:
		Select C\animation\type
			Case 1 ;LOOP
				If (C\animation\frame < C\animation\seqStart) Then C\animation\frame = C\animation\seqEnd
				If (C\animation\frame > C\animation\seqEnd) Then C\animation\frame = C\animation\seqStart
			Case 2 ;PING-PONG
				If (C\animation\frame < C\animation\seqStart) Or (C\animation\frame > C\animation\seqEnd) Then C\animation\speed = -C\animation\speed
			Case 3 ;ONE-SHOT
				If (C\animation\frame < C\animation\seqStart) Or (C\animation\frame > C\animation\seqEnd) Then 
					C\animation\type = 0
					C\animation\frame = 0
				EndIf
		End Select
		
		;Update internal animation state.
		SetAnimKey C\mesh, C\animation\frame, C\animation\seq
	EndIf
Next

;PS: Some vestigial BMax programming... nested types. Your models can have an 'animation' class that handles itself.
Since you're manually animating them with SetAnimTime, there won't be any visual difference and you get the benefit of not spending animation processing with invisible models.

(Writing code while listening to music is very relaxing... I was listening to this when I wrote the above. I forgot how fun it is to code in B3D.)

Last edited 2011


Adam Novagen(Posted 2011) [#7]
Nice link to that music, Kryzon. :D

About your animation remark, doesn't HideEntity just flag EVERYTHING about said entity to be ignored? i.e., doesn't Blitz just ignore everything about it, other than the fact that it exists?


Kryzon(Posted 2011) [#8]
The problem is if HideEntity still has the entity animating in the background. I don't have Blitz3D right now, but this is easy to test:

- HideEntity a character mesh.
- Loop-Animate it.
- Parent a sphere to any of its bones (I'm assuming the sphere will remain visible since it was parented after hiding the mesh).

If the sphere moves this means animations do run in the background, so it's necessary to disable them with hidden entities (or manually handle them so you don't have to restart them every time the entity is shown again, like that remark exemplifies).


Rob the Great(Posted 2011) [#9]
I just ran a test, and I'm getting some pretty weird results.

Hiding my character in the game results in the following:

1. I have sounds cued to play on certain animation frames. None of those played when the entity was hidden

2. I'm using the Fast Extension Shadow System, and the shadow will hold on the last frame of my character after the entity is hidden.

3. The sword that's attached to his hand will always be invisible with my character so long as it's a child to the character. Thus, I can't tell if it's moving or not, but the Shadow System shows that the sword is frozen as well.

All of these things would leave me to suspect that the entity is not animating, but then I texted some information to the screen:

1. Texting Animating(character) always returns true, even after HideEntity is called. The only exception was if I disabled animation using Animate character,0, in which Animating(character) would return 0, even after being hidden.

2. Texting AnimSeq(character) always returns the correct sequence, even after HideEntity is called (That was unexpected).

3. Texting AnimTime(character) returns the current frame of the animation, but holds on the last frame when HideEntity is called. This remains true even though the AnimSeq() is constantly being updated (e.g., if the character is hidden while it's currently on the 7th frame of the running sequence, AnimTime() will always return 7, even though AnimSeq() is constantly changing from one sequence to the next).

Taking all of this information in, what I think is happening is that Blitz is not actually processing the animation sequences on hidden entities, but rather, keeps track of that information as if it were animating. Along the lines that you can update the position, rotation, ect., on a hidden entity, you can also update the animation information on a hidden entity, but Blitz won't take the time to actually apply the animation to the model.


John Blackledge(Posted 2011) [#10]
"AnimTime(character) returns the current frame of the animation, but holds on the last frame when HideEntity is called"

That's quite correct. I did the same test, and a Hidden animated entity simply returns the constant same frame from AnimTime(character), so I haven't bothered with any fancy stop/start of animation.

What did screw up though, was the fact that I had - via AnimTime() frames 2 and 19 (foot down) triggering a footfall sound.
And if the frame stuck on 2 or 19 through HideEntity it would just keep on playing the sound - not a good tap-dancing effect!
So now my HideEntity code also sets a flag whereby foot sounds are not played, although I still allow speaking sounds, so that someone can mumble even though they're behind you.

This is the core code for hiding what's out of sight:


Last edited 2011