Game Development Community

dev|Pro Game Development Curriculum

Change Cloudlayer coverage in script

by Richard Marrevee · 06/09/2013 (12:41 pm) · 4 comments

While designing one of the missions for my game The Master's Eye I wanted to change the coverage of a Cloudlayer in script. Unfortunately there was no such function and directly changing the coverage value of the cloudlayer didn't work without updating the client. So I needed to add this function in the engine and I thought that it may be useful for some of you indies out there, so here it is.

In Engine\environment\cloudlayer.h add the following line in the public section:

// NetObject
   virtual U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
   virtual void unpackUpdate( NetConnection *conn, BitStream *stream );

   // SceneObject
   void prepRenderImage( SceneRenderState *state );
   void renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *mi );

   void ChangeCoverage(F32 newCoverage);//<======== Add this line

protected:

Now in Engine\environment\cloudlayer.cpp add the following line in the include section:

#include "gfx/gfxTransformSaver.h"
#include "gfx/gfxTextureManager.h"
#include "core/stream/fileStream.h"
#include "core/stream/bitStream.h"
#include "console/engineAPI.h"//<========== Add this line
#include "scene/sceneRenderState.h"
#include "renderInstance/renderPassManager.h"
#include "gfx/primBuilder.h"

Still in Engine\environment\cloudlayer.cpp add the following code at the end of the file:

void CloudLayer::ChangeCoverage(F32 newCoverage)
{
   mCoverage = newCoverage;
   setMaskBits( CloudLayerMask );
}

DefineEngineMethod(CloudLayer, ChangeCoverage, void, (F32 newCoverage),,
	"Change coverage of the cloudlayer.")
{
	object->ChangeCoverage(newCoverage);
}

After rebuilding the engine you can use this function in script like this:

MyCloudLayerName.setCoverage(0.5);

Where MyCloudLayerName is the name of your Cloudlayer object and 0.5 is the new value for the coverage (change this value to the value you want.

That's all there is. I apologize to all those people who want vids, I didn't had the time to make one, and this is a pretty straight forward resource (I think).

I hope you like it.

Richard

About the author

Started programming in 1984 on an Oric, when time progressed switched to MSX, Amiga and finally the Windows PC with T3D. Now developing an epic fantasy game: The Master's Eye. Creator of the DoorClass pack and VolumetricFog pack @ richardsgamestudio.com


#1
06/09/2013 (4:41 pm)
That will be useful for dynamic weather thanks :-)
#2
06/09/2013 (6:05 pm)
yeah, very cool ... or very cloudy, anyhow! ;)
#3
06/10/2013 (8:58 am)
This sort of thing would be a perfect example of a Community Addition of a feature/improvement if it was contributed as a Pull Request on Github...
#4
06/10/2013 (11:14 am)
Thanks guys.

@Michael:
I would gladly add this as a Pull Request on Github, but.... I really don't have any knowledge of Github and I'm lacking the time at this moment to dig deeper into it.

Edit:
I have just added a pull request, it seems pretty easy so I hope it works out.