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 → RVTCS.cog - Revamp
RVTCS.cog - Revamp
2005-10-14, 1:19 PM #1
Is there anyway to take the RVTCS and alter it such that it instead of placing the thing number you simply put in a template and then the cog creates and destroys all things of that template relative to the player?

Code:
# RVTCS - Ranged Vector Thing Culling System
#
# Visibility controller - 10 objects.
#
# Version 0.3.1
#
# 6/02,5/05 gbk
# Cog used to supliment as a primitive object culling system for JK.  Good for up to 10 objects.
# Must be used with the JK.EXE Patch.

Flags=0x240
Symbols
Message Startup
Message Pulse

Thing Player				Local

Int Used=0			#How many objects youve used.  (Just put the number of the last object)

Flex Min_range=0		#Distance to/from player in which an object is visible.
Flex Max_range=2
Flex Pulserate=0.1		#How often the cog checks for distance.

Thing Object0
Thing Object1
Thing Object2
Thing Object3
Thing Object4
Thing Object5
Thing Object6
Thing Object7
Thing Object8
Thing Object9

Int I=0					Local

Vector Pos_T				Local

End
Code
Startup:
	Sleep(Getselfcog()/10);
	Player = JKgetlocalplayer();
	Setpulse(Pulserate);
Stop;
Pulse:
	Pos_t = Getthingpos(Player);
	For(I=0;I<=Used;I=I+1)
	{
		If(Vectordist(Getthingpos(Object0), Pos_t) <= Max_range && Vectordist(Getthingpos(Object0), Pos_t) >= Min_range)
			SetThingCurGeoMode(Object0, 4);
				# Set the object visible...
		Else
			SetThingCurGeoMode(Object0, 0);
				# Set the object invisible...
	}
Stop;
End
"The solution is simple."
2005-10-14, 3:14 PM #2
This ought to do it :)
Code:
# RVTCS - Ranged Vector Thing Culling System
#
# Visibility controller - 10 objects.
#
# Version 0.3.1
#
# 6/02,5/05 gbk, 10/05 darthslaw
# Cog used to supliment as a primitive object culling system for JK.  Good for up to 10 objects.
# Must be used with the JK.EXE Patch.

Flags=0x240
Symbols
Message Startup
Message Pulse

Thing Player				Local

template temp

Flex Min_range=0		#Distance to/from player in which an object is visible.
Flex Max_range=2
Flex Pulserate=0.1		#How often the cog checks for distance.

Int I=0					Local

Vector Pos_T				Local

End
Code
Startup:
	Sleep(Getselfcog()/10);
	Player = JKgetlocalplayer();
	Setpulse(Pulserate);
Stop;
Pulse:
	Pos_t = Getthingpos(Player);
	For(I=0;I<=GetThingCount();I=I+1)
	{
		if(GetThingTemplate(I) == temp)
		{
			If(Vectordist(Getthingpos(I), Pos_t) <= Max_range && Vectordist(Getthingpos(I), Pos_t) >= Min_range)
				SetThingCurGeoMode(I, 4);
					# Set the object visible...
			Else
				SetThingCurGeoMode(I, 0);
					# Set the object invisible...
		}
	}
Stop;
End



[You forgot to add your name... ;)]
May the mass times acceleration be with you.
2005-10-15, 10:14 AM #3
Okay, perfect!

Now, let's take it one step further...

Is it now possible to add 4 templates to the cog and 1 min (for template1) 4 maxes (for template1, template2, template3, and template4) such that when template1 reaches the max it switches to template2 and so forth?

I'm trying to make it easier to empliment the rvtcs in a level by having one cog control all of the 'LOD' changes for 1 3do...
"The solution is simple."
2005-10-15, 11:06 AM #4
I think just switching the model would be easier (e.g. 4 models, each of a differing LOD)

Or is there something specific you need the template switching for?
May the mass times acceleration be with you.
2005-10-15, 11:17 AM #5
Yeah, I'm developing these levels on my machine at work. To do it that way, I'd have to have all three to four models in the same place in the editor at one time. Since I'm dealing with trees and stuff, I have to use wireframe mode and considering the number of trees and such, going through and layering AND adding the LOD's for the models to the same position is a very long painstaking task.

The idea behind this is that I can put down the lowest detailed 3do of the object for developing purposes and then just go back in the cog later and added the others. It would literally take weeks off of development time.
"The solution is simple."
2005-10-15, 2:25 PM #6
No, you won't have to have all 4 models in at one time.

What you can do is insert one thing in Jed, with model3d as the default lod model in the template (the one with lowest LOD), and then use SetThingModel() on that thing to control LOD change in game. This way, you have one template and 4 models, instead of 4 templates and 4 models

Either way will work, but swapping models (SetThingModel() ) is easier than swapping templates (DestroyThing() and CreateThingAtPos() ). Swapping models is a little easier to code, takes less code, and makes it all one step shorter for the editor too (no need to make multiple templates; just multiple models, which you'd have to do anyway)

Code:
# Based on: RVTCS - Ranged Vector Thing Culling System
#
# LOD controller
#
# Version 0.3.1
#
# 6/02,5/05 gbk, 10/05 darthslaw
#
# For each thing of the specified template, changes it's model 
#  to a certain LOD model based on distance from the player.

Flags=0x240
Symbols
Message Startup
Message Pulse

Thing Player				Local

template temp			# the template whose LOD you want to control

model lod0			# lod = 0, highest LOD
model lod1			# lod = 1
model lod2			# lod = 2
model lod3			# lod = 3, lowest LOD

				# distance = distance between player and object
Flex range0=0.6			# distance < range0           : lod = 0
Flex range1=0.6			# range0 < distance < range1  : lod = 1
Flex range2=0.6			# range1 < distance < range2  : lod = 2
				# range2 < distance           : lod = 2

flex dist				local

Flex Pulserate=0.1		#How often the cog checks for distance.

Int I=0					Local
int LOD					Local

Vector Pos_T				Local

End
Code
Startup:
	Sleep(Getselfcog()/10);
	Player = JKgetlocalplayer();
	Setpulse(Pulserate);
Stop;
Pulse:
	Pos_t = Getthingpos(Player);
	For(I=0;I<=GetThingCount();I=I+1)
	{
		if(GetThingTemplate(I) == temp)
		{
			dist = VectorDist(Pos_T, GetThingPos(I));
			if(dist < range0) lod = 0;				// distance < range0
			else if(range0 <= dist && dist < range1) lod = 1;	// range0 < distance < range1
			else if(range1 <= dist && dist < range2) lod = 2;	// range1 < distance < range2
			else lod = 3;						// range2 < distance
			SetThingModel(I, lod0[lod]);				// set model to appropriate LOD
		}
	}
Stop;
End
May the mass times acceleration be with you.
2005-10-15, 3:16 PM #7
The only problem is that the 1st LOD is _walkstruct, 2 and 3 are _ghoststruct, and 4 is simply _ghost.

So, ideally, the cog would request which 3do in the level will be effected by the cog. Then, it'll replace all of those 3do's with the 3do's specified for the appropriate distance from the player. In doing that, the templates of each 3do should carry over automatically, correct?
"The solution is simple."
2005-10-16, 6:09 AM #8
Ok, I can kinda see where you're going...

But in any case, here is the cog. If the template of a thing matches one of the ones specified in the cog, the cog will swap (destroy+recreate) the template to the appropriate lod template, depending on the player's distance from the object, and objects closer than range0 and further than range4 will be turned invisible (geo=0).

Did I get that right?

Code:
# Based on: RVTCS 0.3.1 - Ranged Vector Thing Culling System
#
# LOD controller - templates
#
# For the specified templates, 
#
# 6/02,5/05 gbk, 10/05 darthslaw
#

Flags=0x240
Symbols
Message Startup
Message Pulse

Thing Player				Local

template lod0			# lod = 0, highest LOD
template lod1			# lod = 1
template lod2			# lod = 2
template lod3			# lod = 3, lowest LOD

				# distance = distance between player and object
Flex range0=0.60		# distance < range0 		: geo = 0
Flex range1=0.12		# range0 < distance < range1	: lod = 0
Flex range2=0.18		# range1 < distance < range2	: lod = 1
flex range3=0.24		# range2 < distance < range3	: lod = 2
flex range4=0.30		# range3 < distance < range4	: lod = 3
				# range4 < distance		: geo = 0

flex dist				local

Flex Pulserate=0.1		#How often the cog checks for distance.

Int I=0					Local
int LOD					Local

Vector Pos_T				Local

template temp    local
sector sec       local
vector pos       local
vector lvec      local
thing dummy      local

End
Code
Startup:
	Sleep(Getselfcog()/10);
	Player = JKgetlocalplayer();
	Setpulse(Pulserate);
Stop;
Pulse:
	Pos_t = Getthingpos(Player);
	For(I=0;I<=GetThingCount();I=I+1)
	{
		temp = GetThingTemplate(I);
		if(temp == lod0 || temp == lod1 || temp == lod2 || temp == lod3)	// one of the specified tamplates
		{
			dist = VectorDist(Pos_T, GetThingPos(I));
			if(range0 <= dist && dist < range1) lod = 0;
			else if(range1 <= dist && dist < range2) lod = 1;
			else if(range2 <= dist && dist < range3) lod = 2;
			else if(range3 <= dist && dist < range4) lod = 3;
			else lod = -1;
			if(lod != -1)
			{
				SetThingCurGeoMode(I, 4);
				sec = GetThingSector(I);
				pos = GetThingPos(I);
				lvec = GetThingLVec(I);
				DestroyThing(I);
				dummy = CreateThingAtPos(lod0[lod], sec, pos, '0 0 0');
				SetThingLook(dummy, lvec);
			}
			else SetThingCurGeoMode(I, 0);
		}
	}
Stop;
End
May the mass times acceleration be with you.
2005-10-17, 6:22 AM #9
Woah, the strangest thing just happend when using that cog.

For starters, the highest LOD isn't rendering at all...but that's been the case with the other cogs as well.

Secondly, the min rendering distance isn't needed. In fact, it seems to be causing the 3do's to be destroyed when they are less then 1 (even if it's set to 0 in the cog).

In an attempt to compensate for this (and since I only have two other LOD's), I set the first two templates to the highest, the third to the middle, and the fourth to the lowest. I set the range to 0,0, 2, 4, 6, and left the pulse at 0.1. When I tested it that time, I ended up with small, dflt boxes traveling (if you're looking in JED from top view (Shift+1)) downward at approx. 0.2 JKUs/sec.

**EDIT**

Nevermind, it seems to have gone away since I fixed the hires 3do. Apparently, I'd forgot to re-export when I changed some of the layer names to allow for the extra meshes.

However, it seems that now, the 3do's within the initial range4 destroy themselves on startup and never recreate themselves...

Any thoughts?
"The solution is simple."
2005-10-17, 9:10 AM #10
Hmmm.... I'm not understanding JK right now. The cog I posted before doesn't work right... somehow it's not getting the correct position of the objects
They are always recreated 2.4 jku above me... when I fly upward, they still are recreated 2.4 jku above my position... (e.g. I am at 0 z jku, the object is created at 2.4 z jku; I am at 1.3 z jku, the object is created at 3.7 z jku)

I dunno

This cog below works for me though, so use it. I don't understand why the original won't work as well -- the only difference is that I used CreateThing() and TeleportThing() instead of CreateThingAtPos()

Code:
# Based on: RVTCS 0.3.1 - Ranged Vector Thing Culling System
#
# LOD controller - templates
#
# For the specified templates, 
#
# 6/02,5/05 gbk, 10/05 darthslaw
#

Flags=0x240
Symbols
Message Startup
Message Pulse

Thing Player				Local

template lod0			# lod = 0, highest LOD
template lod1			# lod = 1
template lod2			# lod = 2
template lod3			# lod = 3, lowest LOD

				# distance = distance between player and object
Flex range0=0.60		# distance < range0 		: geo = 0
Flex range1=0.12		# range0 < distance < range1	: lod = 0
Flex range2=0.18		# range1 < distance < range2	: lod = 1
flex range3=0.24		# range2 < distance < range3	: lod = 2
flex range4=0.30		# range3 < distance < range4	: lod = 3
				# range4 < distance		: geo = 0

flex dist				local

Flex Pulserate=0.1		#How often the cog checks for distance.

Int I=0					Local
int LOD					Local

Vector Pos_T				Local

template temp    local

thing dummy      local

End
Code
Startup:
	Sleep(Getselfcog()/10);
	Player = JKgetlocalplayer();
	Setpulse(Pulserate);
Stop;
Pulse:
	Pos_t = Getthingpos(Player);
	For(I=0;I<=GetThingCount();I=I+1)
	{
		temp = GetThingTemplate(I);
		if(temp == lod0 || temp == lod1 || temp == lod2 || temp == lod3)	// one of the specified tamplates
		{
			dist = VectorDist(Pos_T, GetThingPos(I));
			if(range0 <= dist && dist < range1) lod = 0;
			else if(range1 <= dist && dist < range2) lod = 1;
			else if(range2 <= dist && dist < range3) lod = 2;
			else if(range3 <= dist && dist < range4) lod = 3;
			else lod = -1;
			if(lod != -1)
			{
				SetThingCurGeoMode(I, 4);
			## This method works.... ##
				dummy = CreateThing(lod0[lod], I);
				TeleportThing(dummy, I);
			#######

			## ...and this one doesn't.... wtf? ##
			#	dummy = CreateThingAtPosNR(lod0[lod], GetThingSector(I), GetThingPos(I), '0 0 0');
			#	SetThingLook(dummy, GetThingLVec(I));
			#######
				DestroyThing(I);
			}
			else SetThingCurGeoMode(I, 0);
		}
	}
Stop;
End
May the mass times acceleration be with you.
2005-10-17, 10:41 AM #11
No change on my end.

I never experience the error you mentioned.

I'm still having the same problem as before with all of the 3do's within range4 (all ranges 0,1,2,3, & 4) disappear just after start up and then never recreate themselves even if I leave the area completely and come back to it later. Everything outside of that initial radius works perfectly, though. :D
"The solution is simple."
2005-10-17, 5:35 PM #12
Well, I'm just stumped then... :confused:

The attached level demonstrates the cog working as it should. You can compare implementation of the cog to yours and see if something got goofed somewhere. But if everything appears okay, I dunno what to say =\
May the mass times acceleration be with you.
2005-10-18, 6:58 AM #13
I don't know... :(

http://jkhub.massassi.net/project/show.php?projid=123§ion=download

It's only 4Mb. I don't know why it says 12Mb...
"The solution is simple."
2005-10-18, 4:43 PM #14
I downloaded the zip; it really is 12 MB.

:)
2005-10-19, 8:38 AM #15
Odd, it's only 4MB on my system...

Perhaps the way the hub uploads the file decompresses it?
"The solution is simple."
2005-10-21, 4:27 PM #16
I've tried something similar to this because Jedi Knights LOD system isnt working for me. But I am unable to get it to work with SetThingModel.
2005-10-23, 8:33 AM #17
well i hope you fellas get it working soon, cos my levels will be needing a working version of this Cog, and apply to about 2000 things in the level.

I was also hoping that the nearest lod template could use an extra cog, that was affected by damage (leaves falling off etc)

Well, I aint no cogger, so ... BACK TO WORK CHAPS
Code:
if(getThingFlags(source) & 0x8){
  do her}
elseif(getThingFlags(source) & 0x4){
  do other babe}
else{
  do a dude}
2005-10-24, 9:14 AM #18
Originally posted by Ruthven:
well i hope you fellas get it working soon, cos my levels will be needing a working version of this Cog, and apply to about 2000 things in the level.

I was also hoping that the nearest lod template could use an extra cog, that was affected by damage (leaves falling off etc)

Well, I aint no cogger, so ... BACK TO WORK CHAPS


Having a cog that produced an effect based off the nearest (highest) lod shouldn't be effected by this cog. Just have the cog allow you to choose which models will be effected by the cog.
"The solution is simple."

↑ Up to the top!