PDA

View Full Version : Local Cogs



Ace1
07-26-2004, 03:22 PM
I use this cog that is based on the "Seifer" cog, and well.. that cog uses an insanly fast pulse to use a thing as a weapon model. Using a fast pulse in a multiplayer game makes lots of lag, but is there a way to make the cog run where none of the data produced by the cog is sent over the network? I set the cog so nothing will be sent over the network(0x200, NOSYNC 0x200 COG results are not broadcast to the other machines, says the JKSpecs), but for some reason or another, something is still sent over the network making massive amounts of lag. SOMETHING is being sent, I know because I set the cog to slow the pulse down when the player is in external view, and when we are in external view, the lag ceases.

Here is the cog:

# Jedi Knight Cog Script
#
# WEAPONPOV.COG
#
# controls first person weapon models. Based on the Seifer cog

flags=0x200

symbols

model bryarpistol=bryV.3do local

keyframe bryarfire=bryvpst1.key local

template facetpl=+ghost1 local
template povtemp=+gunmodel local
template positiontpl=+ghost1 local

thing player local
thing weapmodelv local

int swaydir local

int trackID=-1 local

int ourweapon local
int lastweapon local
int modelpostion local
int weaponfacing local
int povinvisible=0 local
int weaponchange=0 local
int weapmounted=0 local

vector X_AxisVec local
vector Y_AxisVec local
vector forwardvector local

message startup
message newplayer
message timer
message pulse
message killed
message shutdown
message leave
message removed

end

# ================================================== ======================================

code

startup:

SetPulse(1);
SetPulse(0);
SetTimerEx(0.51, 1, 0, 0);
Return;

# .................................................. ......................................

newplayer:

SetPulse(1);
SetPulse(0);
SetTimerEx(0.51, 1, 0, 0);
Return;

# .................................................. ......................................

timer:

player = jkGetLocalPlayer();

if(GetSenderID() == 1)
{
weapmodelv = CreateThing(povtemp, player);
AttachThingToThingEx(weapmodelv, player, 0x8);
SetThingFlags(weapmodelv, 0x10);
SetThingPos(weapmodelv, GetThingPos(player));
SetActorFlags(weapmodelv, 0x8);
SetPulse(0.15);
}

Return;

# .................................................. ......................................

pulse:

player = jkGetLocalPlayer();

ourweapon = GetCurWeapon(player);

if(ourweapon == 2)
{
weaponModel = LoadModel("bryv.3do");
mountAnim = LoadKeyframe("bryvmnt.key");
fireAnim = LoadKeyframe("bryvpst1.key");
}
else if(ourweapon == 3)
{
weaponModel = LoadModel("strv.3do");
mountAnim = LoadKeyframe("strvmnt.key");
fireAnim = LoadKeyframe("strvpst1.key");
}

if(ourweapon != lastweapon)
{
weaponchanged = 1;
weapmounted = 0;
Print("weaponchanged");
}

lastweapon = ourweapon;

if(weapmounted != 1)
{
SetThingModel(weapmodelv, weaponModel);
if(trackID != -1)
{
StopKey(weapmodelv, trackID, 0.0);
trackID = -1;
}
trackID = PlayKey(weapmodelv, mountAnim, 1, 0x14);
weapmounted = 1;
}

if((GetThingHealth(player) < 1) || (GetActorFlags(player) == 0x400000))
{
SetPulse(0);
if((weapmodelv != -1) && (weapmodelv != player))
{
DetachThing(weapmodelv);
DestroyThing(weapmodelv);
}
Return;
}

if(GetCurrentCamera() == 0)
{
if((ourweapon == 2) || (ourweapon == 3))
{
ClearThingFlags(weapmodelv, 0x10);
}
else
{
SetThingFlags(weapmodelv, 0x10);
}
SetPulse(0.016);
}
else
{
SetThingFlags(weapmodelv, 0x10);
SetPulse(0.15);
}

weaponfacing = FireProjectile(player, facetpl, -1, -1, '0.0 0.0 0.0', '0.0 0.0 0.0', 1.0, 0x20, 30, 10);
SetThingLook(weapmodelv, GetThingLVec(weaponfacing));

playerthrust = ((VectorY(GetThingThrust(player)) + VectorY(GetThingThrust(player))) * 0.001) * 0.2;

if(Y_AxisVec >= 0.007)
{
swaydir = 0;
}
if(Y_AxisVec <= -0.004)
{
swaydir = 1;
}
if(Y_AxisVec >= 0.0046)
{
playerthrust = (playerthrust/2.2);
}
if(Y_AxisVec <= -0.0016)
{
playerthrust = (playerthrust/2.2);
}

if(playerthrust <= 0 )
{
if(swaydir == 0)
{
Y_AxisVec = Y_AxisVec + playerthrust;
}
if(swaydir == 1)
{
Y_AxisVec = Y_AxisVec - playerthrust;
}
}
else
{
if(swaydir == 0)
{
Y_AxisVec = Y_AxisVec - playerthrust;
}
if(swaydir == 1)
{
Y_AxisVec = Y_AxisVec + playerthrust;
}
}

if((VectorY(GetThingThrust(player)) == 0))
{
if(Y_AxisVec >= 0.0015)
{
Y_AxisVec = Y_AxisVec - 0.001;
}
else if(Y_AxisVec <= -0.0015)
{
Y_AxisVec = Y_AxisVec + 0.001;
}
else
{
Y_AxisVec = 0;
}
}


if((VectorX(GetThingThrust(player)) > 0))
{
if(X_AxisVec <= 0.004)
{
X_AxisVec = X_AxisVec + 0.001;
}
if((X_AxisVec > 0.004) && (X_AxisVec <= 0.0065))
{
X_AxisVec = X_AxisVec + 0.0005;
}
if(X_AxisVec > 0.0065)
{
X_AxisVec = 0.0065;
}
}
if((VectorX(GetThingThrust(player)) < 0))
{
if(X_AxisVec >= -0.004)
{
X_AxisVec = X_AxisVec - 0.001;
}
if((X_AxisVec < -0.004) && (X_AxisVec >= -0.0065))
{
X_AxisVec = X_AxisVec - 0.0005;
}
if(X_AxisVec < -0.0065)
{
X_AxisVec = -0.0065;
}
}
if((VectorX(GetThingThrust(player)) == 0))
{
if((X_AxisVec >= 0.0005) || (X_AxisVec <= -0.0005))
{
if(X_AxisVec > 0.002)
{
X_AxisVec = X_AxisVec - 0.001;
}
if(X_AxisVec < 0.002)
{
X_AxisVec = X_AxisVec - 0.0005;
}

if(X_AxisVec < -0.002)
{
X_AxisVec = X_AxisVec + 0.001;
}
else if(X_AxisVec > -0.002)
{
X_AxisVec = X_AxisVec + 0.0005;
}
}
if((X_AxisVec > -0.0005) && (X_AxisVec < 0.0005) && (X_AxisVec != 0))
{
X_AxisVec = 0;
}
}

forwardvector = VectorSet(-Y_AxisVec/8+X_AxisVec, Y_AxisVec/4, -Y_AxisVec/8);
modelposition = FireProjectile(player, positiontpl, -1, -1, forwardvector, '0 0 0', 0, 0, -1, -1);
SetThingPos(weapmodelv, GetThingPos(modelposition));

Return;

# .................................................. ......................................

killed:
SetPulse(0);
if((weapmodelv != -1) && (weapmodelv != player))
{
DetachThing(weapmodelv);
DestroyThing(weapmodelv);
}
Return;

# .................................................. ......................................

shutdown:
SetPulse(0);
if((weapmodelv != -1) && (weapmodelv != player))
{
DetachThing(weapmodelv);
DestroyThing(weapmodelv);
}
Return;

# .................................................. ......................................

leave:
SetPulse(0);
if((weapmodelv != -1) && (weapmodelv != player))
{
DetachThing(weapmodelv);
DestroyThing(weapmodelv);
}
Return;

# .................................................. ......................................

removed:
SetPulse(0);
if((weapmodelv != -1) && (weapmodelv != player))
{
DetachThing(weapmodelv);
DestroyThing(weapmodelv);
}
Return;

# .................................................. ......................................

end

Any help and a way to stop the pulse from sending and flooding data over the network would be GREATLY appreciated.

------------------
GetThingSignature(Ace1);

JediKirby
07-26-2004, 03:39 PM
Please, gods of cog, come to our rescue.

JediKirby

------------------
jEDIkIRBY - Putting the Romance back into Necromancer.
Proud Leader of the Minnessassian Council

Live on, Adam.

SG-fan
07-26-2004, 07:22 PM
There is one more flag (0x40) that removes data synced over the network. I think this will even prevent thing creation from syncing, but I can't remember. If you're sure NOTHING should be synced, add that flag to the 0x200.

I had it backwards, 0x200 prevents creation/other things from syncing. 0x40 prevents messages from being fowarded to the server. Only use this flag if you don't want other computers to run the messages.

------------------
Sam: "Sir we can't call it 'The Enterprise'"
Jack: "Why not!"

[This message has been edited by SG-fan (edited July 26, 2004).]

Quib Mask
07-26-2004, 09:27 PM
Ace1, try flags=0x240 and tell us if it fixes it. If not I'll look into it more for you.

Quib Mask

lucky_jackpot
07-27-2004, 05:33 AM
Yep, what Quib suggests should certainly be your first "port of call" in-so-far-as ways to fine-tune your cog http://forums.massassi.net/html/smile.gif "flags=0x240" http://forums.massassi.net/html/smile.gif

Hope this helps http://forums.massassi.net/html/biggrin.gif

-Jackpot

------------------
"lucky_jackpot is the smily god..." - gothicX
"jackpot is an evil evil man... so evil, in fact, that he's awesome." - Seb

"Life is mostly froth and bubble, but two things stand in stone,
Kindness in another's trouble, courage in your own"
("Ye Wearie Wayfarer" - by Adam Lindsay Gordon)

Ace1
07-27-2004, 06:13 PM
Adding the 40 to the flags killed the lag! You guys saved the day for the UR mod. This has been a great help.

------------------
GetThingSignature(Ace1);

Quib Mask
07-27-2004, 07:22 PM
The reason 240 worked over 200, is because with just 200, you were still making the cog be run only on the server, meaning the effects were unsynced, but the commands were run across the network.

Quib Mask

SG-fan
07-27-2004, 09:59 PM
Basically what I said.

------------------
Sam: "Sir we can't call it 'The Enterprise'"
Jack: "Why not!"

F-Body
07-31-2004, 09:55 AM
<font face="Verdana, Arial" size="2">Originally posted by SG-fan:
Basically what I said.
</font>
Well just so long as you know what you're saying. I read your post and it got me confused http://forums.massassi.net/html/confused.gif


------------------
nil nip nada zip zero naught lip zil