Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Flicker cog problem...
Flicker cog problem...
2005-05-09, 12:00 PM #1
Code:
# Jedi Knight Cog Script
#
# 3do flicker cog clone
#
# [gbk]
#
# This Cog is Not supported by LucasArts Entertainment Co

flags=0x240

symbols

message   startup
message   pulse

thing     thing0=-1
thing     thing1=-1
thing     thing2=-1
thing     thing3=-1
thing     thing4=-1
thing     thing5=-1
thing     thing6=-1
thing     thing7=-1
thing     thing8=-1
thing     thing9=-1

vector    vec0            local
vector    vec1            local
vector    vec2            local
vector    vec3            local
vector    vec4            local
vector    vec5            local
vector    vec6            local
vector    vec7            local
vector    vec8            local
vector    vec9            local

template  temp0           local
template  temp1           local
template  temp2           local
template  temp3           local
template  temp4           local
template  temp5           local
template  temp6           local
template  temp7           local
template  temp8           local
template  temp9           local

flex      pulserate=0.1

int       used=0          local
int       i               local

end
#   ==================================================

code
# .......................................................................
startup:
	for(i = 0; i < 10; i = i + 1)
	{
		if(thing0 != -1)
		{
			//get needed unchanging properties of the things
			vec0 = GetThingPos(thing0);
			temp0 = GetThingTemplate(thing0);
			used = used + 1;	//get total number of thing slots used
		}
	}
	SetPulse(pulserate);

Stop;
# .......................................................................
pulse:
	// destroy things
	for(i = 0; i < used; i = i + 1) if(thing0 != -1) DestroyThing(thing0);
	// create them again
	for(i = 0; i < used; i = i + 1)
	{
		thing0 = CreateThingAtPos(temp0, GetThingSector(GetLocalPlayerThing()), vec0, '0 0 0');
		if(thing0 == -1) Print("thing creation failure");
	}

Stop;
# .......................................................................
end


The hellcat variation doesn't seem to work at all. This one works flawlessly except for on thing. If I'm floating in water (at the surface), the object specified in the cog, does not render at all.

Please help me someone. A lot is riding on this cog. Thanks.
"The solution is simple."
2005-05-09, 6:57 PM #2
It's probably because the water sector, which is the player's current sector, isn't being rendered. Because the sector is not being rendered, neither are the 3dos within.
That's my guess anyway.
No solid ideas to fix it just yet though.
May the mass times acceleration be with you.
2005-05-09, 9:39 PM #3
I Fixed this issue for JK co-op. Basically, the camera is not always in the same sector as the player, go figure.

Put this in your pulse:

Code:
testpt = VectorAdd(GetThingPos(player), VectorSet(0,0,0.037));  //actual camera position vector

sectorid = -1;
   sectorcount = GetSectorCount();
   for (s = 0; s < sectorcount; s = s + 1)
   {
      surfacecount = GetNumSectorSurfaces(s);
      for (f = 0; f < surfacecount; f = f + 1)
      {
         dot1 = VectorDot(testpt, GetSurfaceNormal(GetSectorSurfaceRef(s, f)));
         dot2 = VectorDot(GetSurfaceVertexPos(GetSectorSurfaceRef(s, f), 0), GetSurfaceNormal(GetSectorSurfaceRef(s, f)));
         // outside of the sector
         if (dot1 < dot2)
         {
            f = 9999999;
         }
      }
      if (f != 10000000)
      {
         sectorid = s;
         s = 9999999;
      }
   }


That code finds the sector of a point( thanks Sige!) and then change the create line to:
Code:
thing0 = CreateThingAtPos(temp0, sectorid, vec0, '0 0 0');


that aught to do it .
Jedi Knight Enhanced
Freelance Illustrator
2005-05-10, 8:08 AM #4
Great, thanks, that worked.

The only thing now is that it still disappears momentarily when resurfacing and diving.
"The solution is simple."
2005-05-10, 10:57 AM #5
hm..

Try setting the pulserate to 0.01.
Jedi Knight Enhanced
Freelance Illustrator
2005-05-11, 5:10 AM #6
I started with 0.5 and worked it down to 0.001. It's less noticable, but not by much. However, now, if the player is submerged and in 3rd person mode with the camera out of the water, the object is still not rendered at all. If you can fix that, I think it'll fix the other problem (as it's occuringin 1st person just as you surface).

Thanks
"The solution is simple."
2005-05-11, 8:32 AM #7
Did you define the player? If not, put

player=GetLocalPlayerThing();

under startup. Also dont forget to define the extra variables under the symbols section.

Code:
int         sectorid			local
int         sectorcount			local
int         surfacecount		local
int         s				local
int         f				local
int	    x				local
flex        dot1			local
flex        dot2			local
vector      testpt			local



Otherwise I dunno. It works perfect for me, including third person camera.
Jedi Knight Enhanced
Freelance Illustrator
2005-05-13, 6:16 AM #8
It's still doing it and I know why now.

The top surface of the water is flagged +Geo 4. Thus when the camera is outside the water sector and no part of the player is visible, then the objects controled by the cog don't get rendered. But if only a small protion of the player is visible (say the camera is showing partially through the water surface enough to see just 1 pixil of the player) then everything is rendered fine like it's suppose to. If I keep in +Geo 4 and change the surface to Transparent, it works fine. I just need a way now to keep it rendering reguardless if the player is visible or not.

Any way to use the local players camera position instead of the local player model to determine this?
"The solution is simple."
2005-05-13, 8:43 AM #9
Shred's code uses the first-person camera's postion (0, 0, 0.037).

The third-person camera's position varies based on head-pitch of player and on the camera 'bumping' into walls and things. SniperWolf has been working on a way to dynamically find it's position, but is still working on it.

SniperWolf has uploaded an initial version of the camera finding system, but we have already found a few bugs in it. Also, if you want to discuss possible alternatives, join us in #jkhub.

:)
2005-05-13, 10:11 AM #10
The thing is though, that the other things in my level that I haven't specified in the cog yet are rendering fine from outside the water. So it's an issue in the terminating (destroy) condition.
"The solution is simple."
2005-05-13, 11:32 AM #11
Hmm, well this is interesting.

I was wrong, my cog was not working right in the third person camera. It just wasnt noticeable, I had to look for it, heh.

The behavior wasn't as predicted. It looks like if the focus object isnt visible in third person, THEN you have to set the sector.

So I fixed it :D

Code:
if(GetCurrentCamera() == 0)
{
testpt = VectorAdd(GetThingPos(player), VectorSet(0,0,0.037));  //actual camera position vector
}

if(GetCurrentCamera() == 1)
{
testpt = VectorAdd(GetThingPos(player), VectorSet(0,0,0.1));  //somewhere over the player
}



I replaced the testpt line with that.

the object renders even when the camera isnt in the same sector, but the player is visible... so, it works :)
Jedi Knight Enhanced
Freelance Illustrator
2005-05-14, 4:53 AM #12
Okay, this is what I've got now. It's better, but still not perfect (maybe close enough that I can live with it though). If I'm close to the water surface but still covered up, it works. But if I'm a little bit deeper, it won't:
Code:
# Jedi Knight Cog Script
#
# 3do flicker cog clone
#
# [gbk]
#
# This Cog is Not supported by LucasArts Entertainment Co

flags=0x240

symbols

message   startup
message   pulse

thing     thing0=-1
thing     thing1=-1
thing     thing2=-1
thing     thing3=-1
thing     thing4=-1
thing     thing5=-1
thing     thing6=-1
thing     thing7=-1
thing     thing8=-1
thing     thing9=-1

vector    vec0            local
vector    vec1            local
vector    vec2            local
vector    vec3            local
vector    vec4            local
vector    vec5            local
vector    vec6            local
vector    vec7            local
vector    vec8            local
vector    vec9            local

template  temp0           local
template  temp1           local
template  temp2           local
template  temp3           local
template  temp4           local
template  temp5           local
template  temp6           local
template  temp7           local
template  temp8           local
template  temp9           local

flex      pulserate=0.1

int       used=0          local
int       i               local

int       sectorid	  local
int       sectorcount	  local
int       surfacecount	  local
int       s		  local
int       f		  local
int	  x		  local
flex      dot1		  local
flex      dot2		  local
vector    testpt	  local

end
#   ==================================================

code
# .......................................................................
startup:
	player=GetLocalPlayerThing();

	for(i = 0; i < 10; i = i + 1)
	{
		if(thing0 != -1)
		{
			//get needed unchanging properties of the things
			vec0 = GetThingPos(thing0);
			temp0 = GetThingTemplate(thing0);
			used = used + 1;	//get total number of thing slots used
		}
	}
	SetPulse(pulserate);

Stop;
# .......................................................................
pulse:
	// destroy things
	for(i = 0; i < used; i = i + 1) if(thing0 != -1) DestroyThing(thing0);
	// create them again
	for(i = 0; i < used; i = i + 1)
	{
		//Old Code -> thing0 = CreateThingAtPos(temp0, GetThingSector(GetLocalPlayerThing()), vec0, '0 0 0');
		thing0 = CreateThingAtPos(temp0, sectorid, vec0, '0 0 0');
		if(thing0 == -1) Print("thing creation failure");
	}
	//Added code by Shred18
	if(GetCurrentCamera() == 0)
	{
		testpt = VectorAdd(GetThingPos(player), VectorSet(0,0,0.037));  //actual camera position vector
	}

	if(GetCurrentCamera() == 1)
	{
		testpt = VectorAdd(GetThingPos(player), VectorSet(0,0,0.1));  //somewhere over the player
	}	

	sectorid = -1;
   	
	sectorcount = GetSectorCount();
   	for (s = 0; s < sectorcount; s = s + 1)
   	{
      		surfacecount = GetNumSectorSurfaces(s);
      		for (f = 0; f < surfacecount; f = f + 1)
      		{
         		dot1 = VectorDot(testpt, GetSurfaceNormal(GetSectorSurfaceRef(s, f)));
         		dot2 =  VectorDot(GetSurfaceVertexPos(GetSectorSurfaceRef(
		s, f), 0), GetSurfaceNormal(GetSectorSurfaceRef(s, f)));
         		// outside of the sector
         		if (dot1 < dot2)
         		{
            			f = 9999999;
         		}
      		}
      		if (f != 10000000)
      		{
         		sectorid = s;
         		s = 9999999;
      		}
   	}

Stop;
# .......................................................................
end


Any ideas?
"The solution is simple."
2005-05-14, 9:03 AM #13
Not sure if this is the problem, but the code in the pulse isn't in order to complete the operation in during one pulse.

I have the camera position code first, then the sector finding code, then the destroy/create code.

If that doesn't fix it , change the 0.1 in

Code:
if(GetCurrentCamera() == 1)
{
testpt = VectorAdd(GetThingPos(player), VectorSet(0,0,0.1));  //somewhere over the player
}


to something higher until it works for you.
Jedi Knight Enhanced
Freelance Illustrator
2005-05-14, 9:21 AM #14
I noticed this problem when I was originally writing the RVTCS for Friend14... The "watertable" in his level would cause all the ground objects to disappear occasionally. I never could figure it out.

Quote:
Originally posted by CaptBevvil
Code:
# Jedi Knight Cog Script
#
# 3do flicker cog clone
#
# [gbk]
#
# This Cog is Not supported by LucasArts Entertainment Co

flags=0x240

symbols
...

[/B]
I didnt write that cog. I wrote a similar cog a few years ago to handle dynamic lights, but not this cog. Its obvious from the structure, spelling, the fact it has comments, etc. Whoever wrote it used 'Stop', which is funny, but it wasnt me. :\

So, yeah, take my name out of the header... ;)
And when the moment is right, I'm gonna fly a kite.
2005-05-14, 9:23 AM #15
I "wrote" that from your light flicker cog... that's why your name is there and mine not.

(the only significant "change" I made was the for loop at the beginning that will count up how many things you have, instead of you having to do it yourself... )
May the mass times acceleration be with you.
2005-05-14, 11:23 AM #16
JK seems to use the *camera's* sector and not the player's sector when determining what to render.

Thus, the problem occurs with the third-person camera because the camera is not always at the same offset from the player (as I explained in my previous post).

:)
2005-05-16, 3:01 PM #17
"JK seems to use the *camera's* sector and not the player's sector when determining what to render."

Incorrect.



"Thus, the problem occurs with the third-person camera because the camera is not always at the same offset from the player (as I explained in my previous post)."

Correct.




In fact, the reason there are issues is because it DOES use the player's sector to decide what to render and NOT the camera's. We already know the camera is in the 'correct' sector right?


Technically, the original cog (creating the thing in the player's sector) is very bad, damn good thing this is probably for special fx and set to run locally.

The reason it 'works' is exactly the same reason it doesn't work. The reason you need to specify a sector is because JK doesnt actually do any of that vector math to decide what's in a sector and what's not. The object's sector is explicitly set, and updated when passing through adjoins. The whole point of sectors IS visibility testing. It decides which sectors are visible using a cell and portal system which I'm not 100% sure on (still trying to write mine), then renders objects that are contained within the visible sector IDs.

Again, the reason it 'works' is because you are explicitly creating the object in the player's sector. Since the player's sector is used as the starting point in the visibility test, it automatically decides that all the objects in the player's sector are visible - even if they technically should not be. So this is bad on it's own and could produce some very unexpected results, or crashes; the more expected result.



First, I would fix your cog. You should be placing the things in the correct sectors, not ghetto-riggin' it.

Original cog posted, modified. I also took the liberty of optimizing it a little and fixing a couple bugs and potential bugs lol.
Code:
# Jedi Knight Cog Script
#
# 3do flicker cog clone
#
# [gbk]
#
# This Cog is Not supported by LucasArts Entertainment Co

flags=0x240

symbols

message   startup
message   pulse

thing     thing0=-1
thing     thing1=-1
thing     thing2=-1
thing     thing3=-1
thing     thing4=-1
thing     thing5=-1
thing     thing6=-1
thing     thing7=-1
thing     thing8=-1
thing     thing9=-1

vector    vec0            local
vector    vec1            local
vector    vec2            local
vector    vec3            local
vector    vec4            local
vector    vec5            local
vector    vec6            local
vector    vec7            local
vector    vec8            local
vector    vec9            local

template  temp0           local
template  temp1           local
template  temp2           local
template  temp3           local
template  temp4           local
template  temp5           local
template  temp6           local
template  temp7           local
template  temp8           local
template  temp9           local

sector    sec0                local
sector    sec1                local
sector    sec2                local
sector    sec3                local
sector    sec4                local
sector    sec5                local
sector    sec6                local
sector    sec7                local
sector    sec8                local
sector    sec9                local

flex      pulserate=1.0

int       i               local

end
#    ==================================================


code
# .......................................................................
startup:
	for(i=0;i<10;i=i+1)
        if(thing0 != -1)
        {
			vec0 = GetThingPos(thing0);
			temp0 = GetThingTemplate(thing0);
                        sect0 = GetThingSector(thing0);
	}
	SetPulse(pulserate);

return;
//Stop;     <--- im assuming this was a mistake?
# .......................................................................
pulse:
	// destroy and recreate things in one fell swoop!
	for(i = 0; i < 10; i = i + 1)
        if(thing0 != -1)
        {
                DestroyThing(thing0);
                thing0 = CreateThingAtPos(temp0, sect0, vec0, '0 0 0');
        }

return;
//Stop;
# .......................................................................
end
[ B A H ]
Bad *** by nature,
Hackers by choice
2005-05-17, 5:01 AM #18
That cog causes the following error (X) to occur:

The instruction at "0x00e2037" referenced memory at "0x00000004". The memory could not be "written".
"The solution is simple."
2005-05-17, 7:53 AM #19
stop; works just the same as return;
Just like "goto [message];" works just the same as "call [message];" (try it if you don't believe me -- this one AFAIK hasn't been added to the Datamaster because of its recent discovery)

Also, you lost me... why are we destroying and recreating things to set the sector to the original sector?
I mean, that eliminates the purpose of the cog doesn't it? (The purpose, of course, being to get the 3do to always render...)
May the mass times acceleration be with you.
2005-05-17, 8:00 AM #20
StrikeAthius : Your cog just recreates the object in its assigned sector.. that won't actually do anything. The point is to create it in the sector that the camera sees to keep it from not rendering.

and stop; is an alternate verb for return; just fyi ;)
Jedi Knight Enhanced
Freelance Illustrator
2005-05-17, 8:23 AM #21
CaptBevill, just a guess, but if you don't have the adjoin flag "render past adjoin" set, then set it and see if it helps
It might not do anything, but when I was trying to recreate your problem, disabling that flag caused the player to disappear when in the water and in 3rd person (if the cam was above the water)
May the mass times acceleration be with you.
2005-05-17, 9:54 AM #22
"render past adjoin" just out of curiousity, does that just affect 3do's or does it render adjoins also?

I need a cog later down the road that will actually turn off all adjoins by ching their +GEO 0 flag to +Geo 4 so that what's behind them are no longer rendred. My question is in line with that because I don't want the two to contradict later on for one and for two I'm trying to maintain the highest possible level of optimization as possible.
"The solution is simple."
2005-05-17, 10:16 AM #23
I was just going on a guess.
If the water sector (also the player's sector) is not rendered, neither are the objects inside of it (your disappearing 3do)
The "render past adjoin" flag would, I imagine, cause the water sector to be rendered (even though you can't see thru the geo=4 water surface) and thus all objects within are rendered.
At least, that's what I reasoned.
May the mass times acceleration be with you.
2005-05-17, 10:16 AM #24
Okay it works perfectly with the +GEO 4 top adjoin surfaces having that flag unchecked. However, the player model no long renders when it's float on top of the water. If the top surfaces is changed to +GEO 0, then obviously it HOM's, but the player still doesn't render. Apparently, even though it's floating on the surface, it's still technically in the water sector.
"The solution is simple."
2005-05-17, 10:23 AM #25
I'm assuming you had the flag checked before, judging by your wording... which is what i wanted you to do -- make sure it is checked.
But I suppose it's back to the drawing board now... if you had it checked before and it still gave you problems

Oh, and the "floating on surface but still in water sector" line is absolutely correct -- it makes sense to be that way or the player would be standing instead of swimming in the water
May the mass times acceleration be with you.
2005-05-17, 11:32 AM #26
I wish there was a way to create/destroy the player model without create/destroy the player...
"The solution is simple."
2005-05-19, 8:22 AM #27
My mistake lol, I had no idea what the original cog was supposed to do *feels like a dope* :o
[ B A H ]
Bad *** by nature,
Hackers by choice

↑ Up to the top!