PDA

View Full Version : Flicker cog problem...


CaptBevvil
05-09-2005, 03:00 PM
# 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[i] != -1)
{
//get needed unchanging properties of the things
vec0[i] = GetThingPos(thing0[i]);
temp0[i] = GetThingTemplate(thing0[i]);
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[i] != -1) DestroyThing(thing0[i]);
// create them again
for(i = 0; i < used; i = i + 1)
{
thing0[i] = CreateThingAtPos(temp0[i], GetThingSector(GetLocalPlayerThing()), vec0[i], '0 0 0');
if(thing0[i] == -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.

darthslaw
05-09-2005, 09:57 PM
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.

Shred18
05-10-2005, 12:39 AM
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:

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:
thing0[i] = CreateThingAtPos(temp0[i], sectorid, vec0[i], '0 0 0');

that aught to do it .

CaptBevvil
05-10-2005, 11:08 AM
Great, thanks, that worked.

The only thing now is that it still disappears momentarily when resurfacing and diving.

Shred18
05-10-2005, 01:57 PM
hm..

Try setting the pulserate to 0.01.

CaptBevvil
05-11-2005, 08:10 AM
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

Shred18
05-11-2005, 11:32 AM
Did you define the player? If not, put

player=GetLocalPlayerThing();

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


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.

CaptBevvil
05-13-2005, 09:16 AM
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?

ZeqMacaw
05-13-2005, 11:43 AM
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 (http://www.hellraiser64.com/jkhub/download/index.php?dlid=75), but we have already found a few bugs in it. Also, if you want to discuss possible alternatives, join us in #jkhub.

:)

CaptBevvil
05-13-2005, 01:11 PM
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.

Shred18
05-13-2005, 02:32 PM
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

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 :)

CaptBevvil
05-14-2005, 07:53 AM
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:

# 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[i] != -1)
{
//get needed unchanging properties of the things
vec0[i] = GetThingPos(thing0[i]);
temp0[i] = GetThingTemplate(thing0[i]);
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[i] != -1) DestroyThing(thing0[i]);
// create them again
for(i = 0; i < used; i = i + 1)
{
//Old Code -> thing0[i] = CreateThingAtPos(temp0[i], GetThingSector(GetLocalPlayerThing()), vec0[i], '0 0 0');
thing0[i] = CreateThingAtPos(temp0[i], sectorid, vec0[i], '0 0 0');
if(thing0[i] == -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?

Shred18
05-14-2005, 12:03 PM
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

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

to something higher until it works for you.

gbk
05-14-2005, 12:21 PM
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.

Originally posted by CaptBevvil

# Jedi Knight Cog Script
#
# 3do flicker cog clone
#
# [gbk]
#
# This Cog is Not supported by LucasArts Entertainment Co

flags=0x240

symbols
...

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... ;)

darthslaw
05-14-2005, 12:23 PM
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... )

ZeqMacaw
05-14-2005, 02:23 PM
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).

:)

StrikeAthius
05-16-2005, 06:01 PM
"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.

# 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[i] != -1)
{
vec0[i] = GetThingPos(thing0[i]);
temp0[i] = GetThingTemplate(thing0[i]);
sect0[i] = GetThingSector(thing0[i]);
}
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[i] != -1)
{
DestroyThing(thing0[i]);
thing0[i] = CreateThingAtPos(temp0[i], sect0[i], vec0[i], '0 0 0');
}

return;
//Stop;
# .................................................. .....................
end

CaptBevvil
05-17-2005, 08:01 AM
That cog causes the following error (X) to occur:

The instruction at "0x00e2037" referenced memory at "0x00000004". The memory could not be "written".

darthslaw
05-17-2005, 10:53 AM
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...)

Shred18
05-17-2005, 11:00 AM
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 ;)

darthslaw
05-17-2005, 11:23 AM
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)

CaptBevvil
05-17-2005, 12:54 PM
"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.

darthslaw
05-17-2005, 01:16 PM
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.

CaptBevvil
05-17-2005, 01:16 PM
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.

darthslaw
05-17-2005, 01:23 PM
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

CaptBevvil
05-17-2005, 02:32 PM
I wish there was a way to create/destroy the player model without create/destroy the player...

StrikeAthius
05-19-2005, 11:22 AM
My mistake lol, I had no idea what the original cog was supposed to do *feels like a dope* :o