1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-17 10:52:46 +00:00

Merge pull request #208 from Hoikas/deadweight

Remove Junk
This commit is contained in:
Branan Purvine-Riley
2012-06-10 10:06:32 -07:00
148 changed files with 15 additions and 19723 deletions

View File

@ -10,14 +10,10 @@ add_subdirectory(plClientResMgr)
add_subdirectory(plClipboard)
add_subdirectory(plCompression)
add_subdirectory(plContainer)
#add_subdirectory(plDeviceSelector) # Not being used by any current slns
add_subdirectory(plDrawable)
add_subdirectory(plFile)
#add_subdirectory(plGClip) # Not being used by any current slns
#add_subdirectory(plGeometry) # Not being used by any current slns
add_subdirectory(plGImage)
add_subdirectory(plGLight)
#add_subdirectory(plGRenderProcs) # Not being used by any current slns
add_subdirectory(plInputCore)
add_subdirectory(plInterp)
add_subdirectory(plIntersect)

View File

@ -1,587 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "plDeviceSelector.h"
#include "hsStream.h"
#include "hsUtils.h"
#include <algorithm>
DeviceSelector::DeviceSelector() :
fSelDevType(hsG3DDeviceSelector::kDevTypeUnknown),
fSelDev(0),
fSelMode(0),
fDevDesc(0),
fModeDesc(0),
fPerformance(0),
fFilterBPP(0),
fFilterWidth(0),
fFilterHeight(0),
fWindowed(false)
{
memset(fStr, 0x00, sizeof(fStr));
}
const char *DeviceSelector::GetErrorString( void )
{
return fSelector.GetErrorString();
}
hsBool DeviceSelector::Enumerate(HWND hWnd, hsBool expertMode )
{
plDemoDebugFile::Enable( true ); /// ALWAYS enable (well, for now at least)
if( !fSelector.Init() )
return false;
fSelector.Enumerate(hWnd);
// 11.25.2000 mcn - Now we are tough if we're not in expert mode
fSelector.RemoveUnusableDevModes( !expertMode );
// Sort the modes
hsTArray<hsG3DDeviceRecord> &recs = fSelector.GetDeviceRecords();
for (int32_t i = 0; i < recs.Count(); i++)
{
hsTArray<hsG3DDeviceMode> &modes = recs[i].GetModes();
std::sort(modes.FirstIter(), modes.StopIter());
}
IRefreshFilter();
return true;
}
void DeviceSelector::SetModeFilter( int bitDepth, int minWidth, int minHeight )
{
fFilterBPP = bitDepth;
fFilterWidth = minWidth;
fFilterHeight = minHeight;
IRefreshFilter();
}
void DeviceSelector::IRefreshFilter( void )
{
if (fSelDev >= fRecords.Count() )
return;
// Make sure to preserve fSelMode if possible
const hsG3DDeviceMode *oldMode = nil;
if( fSelMode < fFilteredModes.GetCount() && fFilteredModes[ fSelMode ]<fSelRec.GetModes().GetCount() )
oldMode = fSelRec.GetMode( fFilteredModes[ fSelMode ] );
fFilteredModes.Reset();
int i;
for( i = 0; i < fRecords[ fSelDev ].GetModes().Count(); i++ )
{
hsG3DDeviceMode* mode = fRecords[ fSelDev ].GetMode( i );
// Filter out modes we don't want listed
if( fFilterBPP != 0 && fFilterBPP != mode->GetColorDepth() )
continue;
if( mode->GetWidth() < fFilterWidth || mode->GetHeight() < fFilterHeight )
continue;
// Remove any non 4:3 modes
bool goodAspectRatio = (mode->GetWidth() / 4 == mode->GetHeight() / 3) &&
(mode->GetWidth() % 4 == 0) &&
(mode->GetHeight() % 3 == 0);
if (!goodAspectRatio && !(mode->GetWidth() == 1280 && mode->GetHeight() == 1024))
{
continue;
}
// Add the remaining to our filter index
fFilteredModes.Append( i );
}
if( oldMode != nil )
{
fSelMode = IFindFiltered( GetModeNum( oldMode ) );
if( fSelMode == -1 )
{
// Try w/o bpp
fSelMode = IFindFiltered( IGetModeNumNoBPP( oldMode ) );
if( fSelMode == -1 )
fSelMode = 0;
}
}
else
fSelMode = 0;
}
int DeviceSelector::IFindFiltered( int realIndex )
{
int idx = fFilteredModes.Find( realIndex );
if( idx == fFilteredModes.kMissingIndex )
return -1;
return idx;
}
hsBool DeviceSelector::CheckDeviceType(uint32_t type)
{
hsTArray<hsG3DDeviceRecord>& records = fSelector.GetDeviceRecords();
for (int32_t i = 0; i < records.Count(); i++)
{
if (type == records[i].GetG3DDeviceType())
return true;
}
return false;
}
hsBool DeviceSelector::IsDirect3DAvailable()
{
return CheckDeviceType(hsG3DDeviceSelector::kDevTypeDirect3D);
}
hsBool DeviceSelector::IsDirect3DTnLAvailable()
{
return CheckDeviceType(hsG3DDeviceSelector::kDevTypeDirect3DTnL);
}
hsBool DeviceSelector::IsGlideAvailable()
{
return CheckDeviceType(hsG3DDeviceSelector::kDevTypeGlide);
}
hsBool DeviceSelector::IsOpenGLAvailable()
{
return CheckDeviceType(hsG3DDeviceSelector::kDevTypeOpenGL);
}
void DeviceSelector::SetDirect3D()
{
SetDeviceType(hsG3DDeviceSelector::kDevTypeDirect3D);
}
void DeviceSelector::SetDirect3DTnL()
{
SetDeviceType(hsG3DDeviceSelector::kDevTypeDirect3DTnL);
}
void DeviceSelector::SetGlide()
{
SetDeviceType(hsG3DDeviceSelector::kDevTypeGlide);
}
void DeviceSelector::SetOpenGL()
{
SetDeviceType(hsG3DDeviceSelector::kDevTypeOpenGL);
}
void DeviceSelector::SetDeviceType (uint32_t type)
{
int32_t i;
for(i = 0; i < fRecords.GetCount(); i++)
fRecords[i].Clear();
fRecords.Reset();
hsTArray<hsG3DDeviceRecord>& records = fSelector.GetDeviceRecords();
for (i = 0; i < records.Count(); i++)
{
if (records[i].GetG3DDeviceType() == type)
fRecords.Push(records[i]);
}
fSelDevType = type;
fSelDev = 0;
fDevDesc = 0;
fModeDesc = 0;
IRefreshFilter();
}
hsBool DeviceSelector::IsDirect3D()
{
if (fSelDevType == hsG3DDeviceSelector::kDevTypeDirect3D)
return true;
else
return false;
}
hsBool DeviceSelector::IsDirect3DTnL()
{
return ( fSelDevType == hsG3DDeviceSelector::kDevTypeDirect3DTnL ) ? true : false;
}
hsBool DeviceSelector::IsGlide()
{
if (fSelDevType == hsG3DDeviceSelector::kDevTypeGlide)
return true;
else
return false;
}
hsBool DeviceSelector::IsOpenGL()
{
if (fSelDevType == hsG3DDeviceSelector::kDevTypeOpenGL)
return true;
else
return false;
}
hsBool DeviceSelector::SetDevice(uint32_t index)
{
if (index < fRecords.Count())
{
fSelDev = index;
fSelMode = 0;
fSelRec = fRecords[index];
fSelRec.SetMaxAnisotropicSamples(0);
IRefreshFilter();
return true;
}
return false;
}
hsBool DeviceSelector::SetMode(uint32_t index)
{
if (fSelDev >= fRecords.Count())
return false;
if (index < fFilteredModes.GetCount())
{
fSelMode = index;
return true;
}
return false;
}
char* DeviceSelector::GetDeviceDescription()
{
if (fDevDesc == fRecords.Count())
{
fDevDesc = 0;
return nil;
}
sprintf(fStr, "%s [%s]", fRecords[fDevDesc].GetDriverDesc(), fRecords[fDevDesc].GetDeviceDesc());
fDevDesc++;
return fStr;
}
char* DeviceSelector::GetModeDescription( void )
{
if (fSelDev >= fRecords.Count() )
return nil;
if (fModeDesc == fFilteredModes.GetCount())
{
fModeDesc = 0;
return nil;
}
hsG3DDeviceMode* mode = fRecords[fSelDev].GetMode( fFilteredModes[ fModeDesc ] );
fModeDesc++;
if( fFilterBPP != 0 )
sprintf( fStr, "%ux%u", mode->GetWidth(), mode->GetHeight() );
else
sprintf(fStr, "%ux%u %u bit", mode->GetWidth(), mode->GetHeight(), mode->GetColorDepth());
return fStr;
}
uint32_t DeviceSelector::GetNumModes()
{
return fFilteredModes.GetCount();
}
void DeviceSelector::GetMode(uint32_t i, int& width, int& height, int& depth)
{
if (i >= fFilteredModes.GetCount())
return;
hsG3DDeviceMode* mode = fRecords[fSelDev].GetMode(fFilteredModes[i]);
width = mode->GetWidth();
height = mode->GetHeight();
depth = mode->GetColorDepth();
}
hsBool DeviceSelector::SetDefault()
{
hsG3DDeviceModeRecord dmr;
if (fSelector.GetDefault(&dmr))
{
SetDeviceType(dmr.GetDevice()->GetG3DDeviceType());
fSelDev = GetDeviceNum(dmr.GetDevice());
fSelMode = IFindFiltered( GetModeNum(dmr.GetMode()) );
fSelRec = fRecords[fSelDev];
fSelRec.SetMaxAnisotropicSamples( 0 ); // Also off unless explicitly requested
// Set a default detail level based on the available memory
if (hsMemorySpec() == kBlows)
fPerformance = 25;
else
fPerformance = 100;
IRefreshFilter();
return true;
}
return false;
}
hsBool DeviceSelector::Save()
{
hsUNIXStream stream;
if (!stream.Open(DEV_MODE_DAT, "wb"))
return false;
hsG3DDeviceRecord selRec = fSelRec;
hsG3DDeviceMode selMode = *(selRec.GetMode( fFilteredModes[ fSelMode ] ));
selRec.ClearModes();
selRec.Write(&stream);
if (fWindowed)
selMode.SetColorDepth(0);
selMode.Write(&stream);
stream.WriteSwap16(fPerformance);
stream.Close();
return true;
}
hsBool DeviceSelector::Load()
{
hsUNIXStream stream;
if (!stream.Open(DEV_MODE_DAT, "rb"))
return false;
hsG3DDeviceRecord LoadRec; // Device copy for reading/writing
hsG3DDeviceMode LoadMode; // Modes copy for reading/writing
LoadRec.Read(&stream);
if (LoadRec.IsInvalid())
{
stream.Close();
return false;
}
LoadMode.Read(&stream);
fPerformance = stream.ReadSwap16();
stream.Close();
// If selected device is available use it, otherwise return false
if ((LoadRec.GetG3DDeviceType() == hsG3DDeviceSelector::kDevTypeDirect3D) && IsDirect3DAvailable())
SetDirect3D();
else if ((LoadRec.GetG3DDeviceType() == hsG3DDeviceSelector::kDevTypeDirect3DTnL) && IsDirect3DTnLAvailable())
SetDirect3DTnL();
else if ((LoadRec.GetG3DDeviceType() == hsG3DDeviceSelector::kDevTypeGlide) && IsGlideAvailable())
SetGlide();
else
return false;
////////////////////////////////////////////////////////////////////////////
// Attempt to match the saved device and mode to the ones that are currently
// available.
////////////////////////////////////////////////////////////////////////////
int num = GetDeviceNum(&LoadRec);
if (num == -1)
return false;
SetDevice(num);
// Copy the flags
fSelRec.SetCap(hsG3DDeviceSelector::kCapsCompressTextures,
LoadRec.GetCap(hsG3DDeviceSelector::kCapsCompressTextures));
fSelRec.SetAASetting( LoadRec.GetAASetting() );
fSelRec.SetMaxAnisotropicSamples( LoadRec.GetMaxAnisotropicSamples() );
if (LoadMode.GetColorDepth() == 0)
{
fWindowed = true;
LoadMode.SetColorDepth(32);
}
num = GetModeNum(&LoadMode);
if (num == -1)
return false;
SetMode(IFindFiltered(num));
return true;
}
int DeviceSelector::GetDeviceNum(const hsG3DDeviceRecord *pLoadRec)
{
hsTArray<hsG3DDeviceRecord>& records = fRecords;
for (int i = 0; i < records.Count(); i++)
{
if (!strcmp(records[i].GetDriverDesc(), pLoadRec->GetDriverDesc()) &&
!strcmp(records[i].GetDriverName(), pLoadRec->GetDriverName()) &&
!strcmp(records[i].GetDriverVersion(), pLoadRec->GetDriverVersion()) &&
!strcmp(records[i].GetDeviceDesc(), pLoadRec->GetDeviceDesc()))
return i;
}
return -1;
}
int DeviceSelector::IGetModeNumNoBPP( const hsG3DDeviceMode *pLoadMode )
{
hsTArray<hsG3DDeviceMode>& modes = fRecords[fSelDev].GetModes();
for (int i = 0; i < modes.Count(); i++)
{
if ((modes[i].GetWidth() == pLoadMode->GetWidth()) &&
(modes[i].GetHeight() == pLoadMode->GetHeight())
)
{
if( fFilteredModes.Find( i ) != fFilteredModes.kMissingIndex )
{
#ifndef M3DRELEASE
if (pLoadMode->GetColorDepth() == 0)
fSelRec.GetMode( i )->SetColorDepth(0);
#endif
return i;
}
}
}
return -1;
}
int DeviceSelector::GetModeNum(const hsG3DDeviceMode *pLoadMode)
{
hsTArray<hsG3DDeviceMode>& modes = fRecords[fSelDev].GetModes();
for (int i = 0; i < modes.Count(); i++)
{
if ((modes[i].GetWidth() == pLoadMode->GetWidth()) &&
(modes[i].GetHeight() == pLoadMode->GetHeight()) &&
(modes[i].GetColorDepth() == pLoadMode->GetColorDepth()))
{
return i;
}
}
return -1;
}
uint8_t DeviceSelector::CanAntiAlias()
{
hsG3DDeviceMode *mode = fRecords[ fSelDev ].GetMode( fFilteredModes[ fSelMode ] );
return mode->GetNumFSAATypes();
}
uint8_t DeviceSelector::IsAntiAliased()
{
return fSelRec.GetAASetting();
}
void DeviceSelector::SetAntiAlias(uint8_t numSamples)
{
fSelRec.SetAASetting( numSamples );
}
uint8_t DeviceSelector::CanAnisotropicFilter()
{
uint8_t hi = fRecords[ fSelDev ].GetMaxAnisotropicSamples();
if( hi > 1 )
return hi;
return 0;
}
uint8_t DeviceSelector::GetAnisotropicLevel()
{
return fSelRec.GetMaxAnisotropicSamples();
}
void DeviceSelector::SetAnisotropicLevel( uint8_t level )
{
fSelRec.SetMaxAnisotropicSamples( level );
}
bool DeviceSelector::CanWindow ()
{
return !fSelRec.GetCap(hsG3DDeviceSelector::kCapsNoWindow);
}
bool DeviceSelector::IsWindowed()
{
return fWindowed;
}
void DeviceSelector::SetWindowed(bool state)
{
fWindowed = state;
}
hsBool DeviceSelector::CanCompress ()
{
return fRecords[fSelDev].GetCap(hsG3DDeviceSelector::kCapsCompressTextures);
}
hsBool DeviceSelector::IsCompressed()
{
return fSelRec.GetCap(hsG3DDeviceSelector::kCapsCompressTextures);
}
void DeviceSelector::SetCompressed(hsBool state)
{
fSelRec.SetCap(hsG3DDeviceSelector::kCapsCompressTextures, state);
}
bool DeviceSelector::GetCap(uint32_t cap)
{
return fSelRec.GetCap(cap) != 0;
}

View File

@ -1,160 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef DEVICESELECTOR_H
#define DEVICESELECTOR_H
#include "HeadSpin.h"
//#include "plRender.h"
#include "../../PubUtilLib/plPipeline/hsG3DDeviceSelector.h"
#define DEV_MODE_DAT "dev_mode.dat"
//
// A wrapper class to simplify hsG3DDeviceSelector.
// Make sure to call Enumerate before doing anything else.
//
class DeviceSelector
{
protected:
uint32_t fSelDevType; // Current type of driver. Set by the SetDirect3D/Glide/OpenGL functions
uint32_t fSelDev; // Index of selected device. Set by SetDevice() or
uint32_t fSelMode; // Index of selected mode for current device
int fDevDesc; // Used by GetDeviceDescription() to store index of current device
int fModeDesc; // Used by GetModeDescription() to store index of current mode
char fStr[1024]; // Used to return text
uint16_t fPerformance; // Performance level (0-100)
int fFilterBPP, fFilterWidth, fFilterHeight;
bool fWindowed;
hsG3DDeviceSelector fSelector;
hsTArray<hsG3DDeviceRecord> fRecords; // Copy of all records for the current device type
hsG3DDeviceRecord fSelRec; // Device copy for reading/writing
hsTArray<int> fFilteredModes;
void IRefreshFilter( void );
int IFindFiltered( int realIndex );
int IGetModeNumNoBPP( const hsG3DDeviceMode *pLoadMode ); // Returns index of passed in mode
public:
DeviceSelector();
hsBool Enumerate(HWND hWnd, hsBool expertMode); // Enumerates all devices
const char *GetErrorString( void );
// Determines if any devices of the specified type are available
hsBool IsDirect3DAvailable();
hsBool IsGlideAvailable();
hsBool IsOpenGLAvailable();
hsBool IsDirect3DTnLAvailable();
// Set current device type
void SetDirect3D();
void SetGlide();
void SetOpenGL();
void SetDirect3DTnL();
// Returns true if current device is of the specified type
hsBool IsDirect3D();
hsBool IsDirect3DTnL();
hsBool IsGlide();
hsBool IsOpenGL();
// Gets and sets the current device or mode.
uint32_t GetSelectedDevice() { return fSelDev; }
uint32_t GetSelectedMode() { return fSelMode; }
hsBool SetDevice(uint32_t index);
hsBool SetMode(uint32_t index);
// Returns the device or mode descriptions. Call repeatedly until nil is returned.
char* GetDeviceDescription();
char* GetModeDescription( void );
uint32_t GetNumModes();
void GetMode(uint32_t i, int& width, int& height, int& depth);
void SetModeFilter( int bitDepth = 0, int minWidth = 0, int minHeight = 0 );
void SetPerformance (uint16_t value) { fPerformance = value; }
uint16_t GetPerformance () { return fPerformance; }
// Returns max number of samples allowed for AA
uint8_t CanAntiAlias ();
// Returns current # of samples selected for AA, 0 if none
uint8_t IsAntiAliased ();
void SetAntiAlias (uint8_t numSamples);
uint8_t CanAnisotropicFilter();
uint8_t GetAnisotropicLevel();
void SetAnisotropicLevel( uint8_t level );
bool CanWindow();
bool IsWindowed();
void SetWindowed(bool state);
hsBool CanCompress ();
hsBool IsCompressed ();
void SetCompressed (hsBool state);
// Caps from hsG3DDeviceSelector
bool GetCap(uint32_t cap);
// Save and load
hsBool Save(); // Returns false if output file can't be opened
hsBool Load(); // Returns false if input file can't be opened
hsBool SetDefault(); // Returns false if no suitable renderers are found
protected:
hsBool CheckDeviceType(uint32_t type); // Used by the Is*Available() functions
void SetDeviceType(uint32_t type); // Used by SetDirect3D/Glide/OpenGL
// Helpers for LoadDeviceMode()
int GetDeviceNum(const hsG3DDeviceRecord *pLoadRec); // Returns index of passed in device
int GetModeNum(const hsG3DDeviceMode *pLoadMode); // Returns index of passed in mode
};
#endif //DEVICESELECTOR_H

View File

@ -1 +0,0 @@
What do you see? An empty folder.

View File

@ -1,250 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsTypes.h"
#include "hsUtils.h"
#include "hsScalar.h"
#include "hsMemory.h"
#include "hsGRenderProcs.h"
#include "hsStream.h"
#include "../plResMgr/plKey.h"
#include "../plResMgr/hsResMgr.h"
hsGRenderProcs::hsGRenderProcs()
: fNext(nil),
fBack(nil),
fPipeline(nil),
fFlags(kNone),
fLinkCount(0)
{
}
hsGRenderProcs::~hsGRenderProcs()
{
}
hsGRenderProcs** hsGRenderProcs::IOneBeforeMe(hsGRenderProcs** base)
{
hsAssert(base, "Searching for place in baseless list");
if( !*base ||((*base)->GetPriority() > GetPriority()) )
return base;
hsGRenderProcs* trav = *base;
while( trav->fNext && (trav->fNext->GetPriority() > GetPriority()) )
trav = trav->fNext;
hsAssert((trav != this)&&(trav->fNext != this), "Found self in bad place");
return &trav->fNext;
}
void hsGRenderProcs::IInsert(hsGRenderProcs** ptr)
{
hsAssert(*ptr != this, "Re-Inserting self");
hsAssert(ptr, "Inserting into nil list");
if( *ptr )
(*ptr)->fBack = &fNext;
fNext = *ptr;
fBack = ptr;
*ptr = this;
}
void hsGRenderProcs::IDetach()
{
if( fNext )
fNext->fBack = fBack;
*fBack = fNext;
fNext = nil;
fBack = nil;
}
void hsGRenderProcs::Enqueue(hsGRenderProcs** base)
{
// Already linked? Just note another link.
if( fLinkCount++ )
return;
IInsert(IOneBeforeMe(base));
Ref();
}
void hsGRenderProcs::Dequeue()
{
if( fBack && !--fLinkCount )
{
IDetach();
UnRef();
}
}
void hsGRenderProcs::Read(hsStream* s, hsResMgr* mgr)
{
SetFlags(s->ReadSwap32());
ReadObjectRefs(s, mgr);
Read(s);
}
void hsGRenderProcs::ReadObjectRefs(hsStream* s, hsResMgr* mgr)
{
if( fFlags & kObjectRefs )
{
int n = s->ReadSwap32();
fObjectRefs.SetCount(n);
int i;
for( i = 0; i < n; i++ )
{
fObjectRefs[i] = mgr->ReadKey(s);
}
}
}
void hsGRenderProcs::WriteObjectRefs(hsStream* s, hsResMgr* mgr)
{
if( fFlags & kObjectRefs )
{
s->WriteSwap32(fObjectRefs.GetCount());
int i;
for( i = 0; i < fObjectRefs.GetCount(); i++ )
{
// if( fObjectRefs[i] )
{
mgr->WriteKey(s,fObjectRefs[i]); // writes nil any...right?
}
// else
// {
// mgr->WriteKey(s, nil);
// }
}
}
}
void hsGRenderProcs::Write(hsStream* s, hsResMgr* mgr)
{
s->WriteSwap32(fFlags);
WriteObjectRefs(s, mgr);
Write(s);
}
plDrawable* hsGRenderProcs::GetObjectRef(int i)
{
return (plDrawable*)((i < fObjectRefs.GetCount()) && fObjectRefs[i] ? fObjectRefs[i]->GetObjectPtr() : nil);
}
void hsGRenderProcs::SetNumObjectRefs(int n)
{
if( n > fObjectRefs.GetCount() )
{
int oldCnt = fObjectRefs.GetCount();
fObjectRefs.SetCount(n);
int i;
for( i = oldCnt; i < n; i++ )
fObjectRefs[i] = nil;
}
}
void hsGRenderProcs::SetObjectRef(plKey* key, int i)
{
if( i >= fObjectRefs.GetCount() )
SetNumObjectRefs(i+1);
fObjectRefs[i] = key;
fFlags |= kObjectRefs;
}
hsBool32 hsGRenderProcs::BeginTree(plPipeline* pipe, plDrawable* root)
{
hsAssert(fFlags & kObjectRefsInit, "Should have had refs initialized on read");
fPipeline = pipe;
if( Inclusive() )
{
fColorizer.Init(pipe);
hsColorRGBA col = fColorizer.GetCurrentColor();
if( !fColorizer.Colorizing() )
{
col.r = col.g = col.b = 1.f;
}
if( !fColorizer.Alpharizing() )
col.a = 0.999f;
fColorizer.PushColorize(col, !fColorizer.Colorizing() /* alpha only */);
}
return true;
}
hsBool32 hsGRenderProcs::BeginObject(plPipeline* pipe, plDrawable* obj)
{
hsAssert(fFlags & kObjectRefsInit, "Should have had refs initialized on read");
fPipeline = pipe;
if( !Inclusive() )
{
fColorizer.Init(pipe);
hsColorRGBA col = fColorizer.GetCurrentColor();
if( !fColorizer.Colorizing() )
{
col.r = col.g = col.b = 1.f;
}
if( !fColorizer.Alpharizing() )
col.a = 0.999f;
fColorizer.PushColorize(col, !fColorizer.Colorizing() /* alpha only */);
}
return true;
}
void hsGRenderProcs::EndObject()
{
if( !Inclusive() )
fColorizer.PopColorize();
}
void hsGRenderProcs::EndTree()
{
if( Inclusive() )
fColorizer.PopColorize();
fPipeline = nil;
}

View File

@ -1,218 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef hsGRenderProcs_inc
#define hsGRenderProcs_inc
#include "hsRefCnt.h"
#include "hsScalar.h"
#include "hsMemory.h"
#include "hsBiExpander.h"
#include "../plPipeline/hsGColorizer.h"
#include "../plResMgr/plCreatable.h"
class plPipeline;
class plDrawable;
class hsTriangle3;
struct hsGTriVertex;
struct hsGVertex3;
struct hsGShadeVertex;
struct hsGSplat3;
class hsStream;
class plKey;
class hsBounds3Ext;
class hsResMgr;
class hsGRenderProcs : public plCreatable {
public:
enum {
kMaxLabelLen = 128
};
enum ProcType {
kTypeAngleFade,
kTypeDistFade,
kTypeMotionBlur1,
kTypeMotionBlur2,
kTypeIntenseAlpha,
kTypeGlobalShade,
kTypeObjDistFade,
kTypeDistShade,
kTypeObjDistShade
};
enum {
kNone = 0x0,
kInclusive = 0x1, // Affect children
kNOP = 0x2, // Turned off (till EndObject)
kOpaque = 0x4,
kCulled = 0x8,
kObjectRefs = 0x10,
kObjectRefsInit = 0x20
};
private:
// Base class private stuff for managing the Queue of Procs on the device.
uint32_t fLinkCount;
hsGRenderProcs* fNext;
hsGRenderProcs** fBack;
hsGRenderProcs** IOneBeforeMe(hsGRenderProcs** base);
void IInsert(hsGRenderProcs** beforeMe);
void IDetach();
protected:
uint32_t fFlags;
hsGColorizer fColorizer;
plPipeline* fPipeline;
hsDynamicArray<plKey*> fObjectRefs;
public:
hsGRenderProcs();
virtual ~hsGRenderProcs();
// BeginTree returns false if entire subtree is don't bother to draw,
// else true. Mostly a culling tool.
virtual hsBool32 BeginTree(plPipeline* pipe, plDrawable* root);
// BeginObject returns true if the object should be drawn, false if
// don't bother. Can also do any initialization it wants. Should this
// get something more innocuous like a bound instead of the SceneObject?
// Is there anything else it might need to know?
virtual hsBool32 BeginObject(plPipeline* pipe, plDrawable* obj);
// ProcessVerts takes the list of TriVerts and does what it will.
// I'll outline the hsGTriVertex below. The difference between
// the BaseVertex list and the UsedVertex list is interpolation.
// Shade values and generated Texture Coords are computed for
// the Base Triangle only, and then interpolated for vertices
// generated by clipping. So Shade Values and Texture Coordinates
// should only be computed in ProcessBaseVerts(). On the other
// hand, only the vertices from actual drawn triangles are
// transformed, and hence have a screen position to mess with.
// So any wiggling of the screen position should happen in
// ProcessUsedVerts(). These functions might be better named
// ProcessShadeVerts() and ProcessXformVerts(), except that
// vertex illumination (shade) is interpolated, but then
// the interpolated shade is fed into the material to calculate
// color. So messing with final color would happen in ProcessUsedVerts(),
// whereas messing with illumination's in ProcessBaseVerts(). Messing
// with UV's is equally valid in either. In general though, the number
// of BaseVerts is less than or equal to the number of UsedVerts. Most
// shaders would have one or the other a no-op.
// Process list of unique vertices (with unique hsGXformVerts) which will be drawn to screen
virtual void ProcessScreenVerts(hsExpander<hsGVertex3*>& vList) {}
// Take a list of verts and modulate shades for them. Care should be taken to only bother with verts that
// are not (hsGVertex3::kCulled|hsGVertex3::kDisabled). Also, any verts that this RenderProc causes
// to go completely transparent should be flagged hsGVertex3::kCulled (NOT DISABLED).
// See hsSfxDistFade for example (not exemplary) code.
// Process list of unique vertices (unique hsGShadeVerts) before interpolation
virtual void ProcessPreInterpShadeVerts(hsExpander<hsGShadeVertex*>& vList) {}
// Process list of unique vertices (unique hsGShadeVerts) after interpolation - these will be drawn to screen
virtual void ProcessPostInterpShadeVerts(hsExpander<hsGShadeVertex*>& vList) {}
// Process list of unique Pre or Post Interpolation TriVerts (with hsGShade and hsGXformVerts)
// While the TriVerts are unique, there may be sharing among constituents, i.e. position and uv.
// Care must be taken when accumulating effects.
virtual void ProcessPreInterpVerts(hsExpander<hsGTriVertex*>& vList) {}
virtual void ProcessPostInterpVerts(hsExpander<hsGTriVertex*>& vList) {}
// Process list of triangles which are headed for the screen. vList is the full list of unique TriVerts
// used by these triangles. If triangles are added, any generated verts MUST be added to vList. If
// Triangles are removed, verts may be removed from vList (keeping in mind that vList verts may be
// shared between triangles).
virtual void ProcessPreClipTris(hsExpander<hsTriangle3*>& tList, hsExpander<hsGTriVertex*>& vList) {}
virtual void ProcessPreInterpTris(hsExpander<hsTriangle3*>& tList, hsExpander<hsGTriVertex*>& vList) {}
virtual void ProcessPostInterpTris(hsExpander<hsTriangle3*>& tList, hsExpander<hsGTriVertex*>& vList) {}
// Any cleanup for this object
virtual void EndObject();
// Any cleanup for this subtree
virtual void EndTree();
// Shaders can set their priority to affect order in which they are called
// When pushed onto device, device uses this priority to sort into queue
virtual hsScalar GetPriority() { return 0; }
// When a shader is pushed onto the device (by an object), the object
// will pop it back off either before or after drawing its children,
// depending on Inclusive(). Not meaningful for mate
virtual hsBool32 Inclusive() { return fFlags & kInclusive; }
virtual void Enqueue(hsGRenderProcs** list);
virtual void Dequeue();
hsGRenderProcs* GetNext() { return fNext; }
// External object references. Individual RenderProc type responsible for what they're used for.
void SetNumObjectRefs(int n);
uint32_t GetNumObjectRefs() { return fObjectRefs.GetCount(); }
void AddObjectRef(plKey* key) { fObjectRefs.Append(key); fFlags |= kObjectRefs; }
void SetObjectRef(plKey* key, int i=0);
void InsertObjectRef(int i, plKey* key) { fObjectRefs.InsertAtIndex(i, key); fFlags |= kObjectRefs; }
plDrawable* GetObjectRef(int i);
plKey* GetObjectRefKey(int i) { return fObjectRefs[i]; }
void ReadObjectRefs(hsStream* s, hsResMgr* mgr);
void WriteObjectRefs(hsStream* s, hsResMgr* mgr);
virtual void Read(hsStream* s, hsResMgr* mgr);
virtual void Write(hsStream* s, hsResMgr* mgr);
virtual void Read(hsStream* s) = 0;
virtual void Write(hsStream* s) = 0;
virtual const char* GetLabel() const = 0;
virtual ProcType GetType() const = 0;
uint32_t GetFlags() { return fFlags; }
void SetFlags(uint32_t f) { fFlags = f; }
CLASSNAME_REGISTER( hsGRenderProcs );
GETINTERFACE_ANY( hsGRenderProcs, plCreatable );
};
#endif // hsGRenderProcs_inc

View File

@ -1,234 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsTypes.h"
#include "hsMemory.h"
#include "hsSfxAngleFade.h"
#include "hsStream.h"
#include "../plPipeline/plPipeline.h"
//#include "../plPipeline/hsG3DDevice.h"
#include "../plGeometry/hsTriangle3.h"
#include "../plMath/hsFastMath.h"
hsSfxAngleFade::hsSfxAngleFade()
{
}
hsSfxAngleFade::~hsSfxAngleFade()
{
}
hsScalar hsSfxAngleFade::IOpacFromDot(hsScalar dot)
{
if( (fFlags & kTwoSided)
&&(dot < 0) )
dot = -dot;
if( dot <= fTable[0].fCosineDel )
return fTable[0].fOpacity;
int i;
for( i = 0; (i < fTable.GetCount()) && (dot >= fTable[i].fCosineDel); i++ )
dot -= fTable[i].fCosineDel;
if( i >= fTable.GetCount() )
return fTable[fTable.GetCount()-1].fOpacity;
dot *= fTable[i-1].fCosineNorm;
hsScalar opac0 = fTable[i-1].fOpacity;
hsScalar opac1 = fTable[i].fOpacity;
return opac0 + dot * (opac1 - opac0);
}
void hsSfxAngleFade::ProcessPreInterpTris(hsExpander<hsTriangle3*>& tList, hsExpander<hsGTriVertex*>& vList)
{
if( !(fFlags & kFaceNormals) )
return;
#if 0 // Taken out 2.26.2001 mcn 'cause it accesses the (now defunct) 3DDevice directly
hsPoint3 vPos = fPipeline->GetViewPositionLocal();
hsG3DDevice* dev = fPipeline->Get3DDevice();
fSetVector.Clear();
for( tList.First(); tList.More(); tList.Plus() )
{
hsTriangle3* tri = tList.Current();
hsVector3& norm = tri->fNormal;
hsScalar dot, opac;
hsGVertex3* vtx;
hsGShadeVertex* shade;
hsVector3 vDir;
vtx = tri->GetVertex(0);
if( !fSetVector.IsBitSet(vtx->fShadeIdx) )
{
vDir.Set(&vPos, &vtx->fLocalPos);
dot = hsFastMath::InvSqrtAppr(vDir.MagnitudeSquared());
dot *= norm.InnerProduct(vDir);
shade = dev->GetShadeEntry(vtx);
opac = IOpacFromDot(dot);
shade->fColor.a *= opac;
fSetVector.SetBit(vtx->fShadeIdx);
}
vtx = tri->GetVertex(1);
if( !fSetVector.IsBitSet(vtx->fShadeIdx) )
{
vDir.Set(&vPos, &vtx->fLocalPos);
dot = hsFastMath::InvSqrtAppr(vDir.MagnitudeSquared());
dot *= norm.InnerProduct(vDir);
shade = dev->GetShadeEntry(vtx);
opac = IOpacFromDot(dot);
shade->fColor.a *= opac;
fSetVector.SetBit(vtx->fShadeIdx);
}
vtx = tri->GetVertex(2);
if( !fSetVector.IsBitSet(vtx->fShadeIdx) )
{
vDir.Set(&vPos, &vtx->fLocalPos);
dot = hsFastMath::InvSqrtAppr(vDir.MagnitudeSquared());
dot *= norm.InnerProduct(vDir);
shade = dev->GetShadeEntry(vtx);
opac = IOpacFromDot(dot);
shade->fColor.a *= opac;
fSetVector.SetBit(vtx->fShadeIdx);
}
}
#endif
}
void hsSfxAngleFade::ProcessPreInterpShadeVerts(hsExpander<hsGShadeVertex*>& vList)
{
if( fFlags & kFaceNormals )
return;
hsVector3 vDir =fPipeline->GetViewDirLocal();
hsPoint3 vPos = fPipeline->GetViewPositionLocal();
for( vList.First(); vList.More(); vList.Plus() )
{
hsGShadeVertex* shade = vList.Current();
hsScalar dot;
if( !(fFlags & kDirectional) )
{
vDir.Set(&vPos, &shade->fLocalPos);
dot = hsFastMath::InvSqrtAppr(vDir.MagnitudeSquared());
dot *= shade->fNormal.InnerProduct(vDir);
}
else
{
dot = shade->fNormal.InnerProduct(vDir);
}
hsScalar opac = IOpacFromDot(dot);
shade->fShade.a *= opac;
}
}
void hsSfxAngleFade::MakeTable(float* cosList, float* opacList, int num)
{
fTable.Reset();
if( !num )
return;
int i;
for( i = 0; i < num; i++ )
{
hsSfxAfTableEntry* t = fTable.Append();
t->fCosineDel = cosList[i];
t->fOpacity = opacList[i];
}
for( i = num-1; i > 0; i-- )
fTable[i].fCosineDel -= fTable[i-1].fCosineDel;
for( i = 0; i < num-1; i++ )
fTable[i].fCosineNorm = hsScalarInvert(fTable[i+1].fCosineDel);
fTable[num-1].fCosineNorm = 0;
hsAssert(fTable.GetCount() == num, "Mismatch making table");
}
void hsSfxAngleFade::Read(hsStream* s)
{
fTable.Reset();
int32_t cnt = s->ReadSwap32();
if( cnt )
{
hsSfxAfTableEntry* arr = new hsSfxAfTableEntry[cnt];
int i;
for( i = 0; i < cnt; i++ )
{
arr[i].fCosineDel = s->ReadSwapScalar();
arr[i].fCosineNorm = s->ReadSwapScalar();
arr[i].fOpacity = s->ReadSwapScalar();
}
fTable.SetArray(arr, cnt);
}
}
void hsSfxAngleFade::Write(hsStream* s)
{
s->WriteSwap32(fTable.GetCount());
for( fTable.First(); fTable.More(); fTable.Plus() )
{
s->WriteSwapScalar(fTable.Current().fCosineDel);
s->WriteSwapScalar(fTable.Current().fCosineNorm);
s->WriteSwapScalar(fTable.Current().fOpacity);
}
}

View File

@ -1,90 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef hsSfxAngleFade_inc
#define hsSfxAngleFade_inc
#include "hsBiExpander.h"
#include "hsGRenderProcs.h"
#include "hsBitVector.h"
class hsSfxAngleFade : public hsGRenderProcs {
public:
enum {
kDirectional = 0x10000,
kTargetRelative = 0x20000,
kTwoSided = 0x40000,
kFaceNormals = 0x80000
};
struct hsSfxAfTableEntry {
hsScalar fCosineDel;
hsScalar fCosineNorm;
hsScalar fOpacity;
};
protected:
hsBitVector fSetVector;
hsExpander<hsSfxAfTableEntry> fTable;
hsScalar IOpacFromDot(hsScalar dot);
public:
hsSfxAngleFade();
virtual ~hsSfxAngleFade();
virtual void ProcessPreInterpShadeVerts(hsExpander<hsGShadeVertex*>& vList);
virtual void ProcessPreInterpTris(hsExpander<hsTriangle3*>& tList, hsExpander<hsGTriVertex*>& vList);
void MakeTable(float* cosList, float* opacList, int num); // lists sorted from lowest cosine to highest
virtual void Read(hsStream* s);
virtual void Write(hsStream* s);
virtual const char* GetLabel() const { return "hsSfxAngleFade"; }
virtual ProcType GetType() const { return kTypeAngleFade; }
CLASSNAME_REGISTER( hsSfxAngleFade );
GETINTERFACE_ANY( hsSfxAngleFade, hsGRenderProcs );
};
#endif // hsSfxAngleFade_inc

View File

@ -1,331 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsTypes.h"
#include "hsMemory.h"
#include "hsSfxDistFade.h"
#include "hsStream.h"
#include "../plPipeline/plPipeline.h"
#include "../plGeometry/hsTriangle3.h"
#include "../plDrawable/plDrawable.h"
#include "../plIntersect/hsBounds.h"
static hsScalar globalScale = 1.f;
hsSfxDistFade::hsSfxDistFade()
: fMinDist(0), fMaxDist(0)
{
}
hsSfxDistFade::~hsSfxDistFade()
{
}
hsScalar hsSfxDistFade::IOpacFromDist(hsScalar dist)
{
if( dist <= fTable[0].fDistDel )
return fTable[0].fOpacity;
int i;
for( i = 0; (i < fTable.GetCount()) && (dist >= fTable[i].fDistDel); i++ )
dist -= fTable[i].fDistDel;
if( i >= fTable.GetCount() )
return fTable[fTable.GetCount()-1].fOpacity;
dist *= fTable[i-1].fDistNorm;
hsScalar opac0 = fTable[i-1].fOpacity;
hsScalar opac1 = fTable[i].fOpacity;
return opac0 + dist * (opac1 - opac0);
}
hsBool32 hsSfxDistFade::BeginObject(plPipeline* pipe, plDrawable* obj)
{
hsGRenderProcs::BeginObject(pipe, obj);
fFlags &= ~(kCulled | kNOP);
hsPoint3 vPos;
if( GetObjectRef(1) )
{
hsPoint3 wPos;
GetObjectRef(1)->GetLocalToWorld().GetTranslate(&wPos);
hsMatrix44 w2l = fPipeline->GetWorldToLocal();
vPos = w2l * wPos;
}
else
{
vPos = fPipeline->GetViewPositionLocal();
}
hsScalar scale = 1.f / fPipeline->GetLocalScale();
scale *= globalScale;
const hsBounds3Ext& bnd = obj->GetLocalBounds();
hsPoint3 inner, outer;
bnd.ClosestPoint(vPos, inner, outer);
hsScalar minDist, maxDist;
minDist = hsVector3(&vPos, &inner).Magnitude();
maxDist = hsVector3(&vPos, &outer).Magnitude();
minDist *= scale;
maxDist *= scale;
if( (fFlags & kCullsBefore)
&&(maxDist <= fMinDist) )
{
fFlags |= kCulled;
return false;
}
if( (fFlags & kCullsBeyond)
&&(minDist > fMaxDist) )
{
fFlags |= kCulled;
return false;
}
if( (fFlags & kIdleBefore)
&&(maxDist < fMinIdle) )
fFlags |= kNOP;
if( (fFlags & kIdleBeyond)
&&(minDist > fMaxIdle) )
fFlags |= kNOP;
return true;
}
void hsSfxDistFade::ProcessPreInterpShadeVerts(hsExpander<hsGShadeVertex*>& vList)
{
if( fFlags & (kPostInterp | kNOP) )
return;
hsPoint3 vPos;
if( GetObjectRef(1) )
{
hsPoint3 wPos;
GetObjectRef(1)->GetLocalToWorld().GetTranslate(&wPos);
hsMatrix44 w2l = fPipeline->GetWorldToLocal();
vPos = w2l * wPos;
}
else
{
vPos = fPipeline->GetViewPositionLocal();
}
hsScalar scale = 1.f / fPipeline->GetLocalScale();
scale *= globalScale;
for( vList.First(); vList.More(); vList.Plus() )
{
hsGShadeVertex* shade = vList.Current();
hsScalar dist = hsVector3(&shade->fLocalPos, &vPos).Magnitude();
dist *= scale;
hsScalar opac = IOpacFromDist(dist);
if( opac > 0 )
shade->fShade.a *= opac;
else
{
shade->fShade.a = 0;
shade->fBaseVertex->fFlags |= hsGVertex3::kCulled;
}
}
}
void hsSfxDistFade::ProcessPostInterpShadeVerts(hsExpander<hsGShadeVertex*>& vList)
{
if( !(fFlags & kPostInterp) )
return;
if( fFlags & kNOP )
return;
hsPoint3 vPos;
if( GetObjectRef(1) )
{
hsPoint3 wPos;
GetObjectRef(1)->GetLocalToWorld().GetTranslate(&wPos);
hsMatrix44 w2l = fPipeline->GetWorldToLocal();
vPos = w2l * wPos;
}
else
{
vPos = fPipeline->GetViewPositionLocal();
}
hsScalar scale = 1.f / fPipeline->GetLocalScale();
for( vList.First(); vList.More(); vList.Plus() )
{
hsGShadeVertex* shade = vList.Current();
hsScalar dist = hsVector3(&shade->fLocalPos, &vPos).Magnitude();
dist *= scale;
hsScalar opac = IOpacFromDist(dist);
if( opac > 0 )
shade->fColor.a *= opac;
else
{
shade->fColor.a = 0;
shade->fBaseVertex->fFlags |= hsGVertex3::kCulled;
}
}
}
void hsSfxDistFade::MakeTable(float* distList, float* opacList, int num)
{
fTable.Reset();
if( !num )
return;
int i;
for( i = 0; i < num; i++ )
{
hsSfxDfTableEntry* t = fTable.Append();
t->fDistDel = distList[i];
t->fOpacity = opacList[i];
}
for( i = num-1; i > 0; i-- )
fTable[i].fDistDel -= fTable[i-1].fDistDel;
for( i = 0; i < num-1; i++ )
fTable[i].fDistNorm = hsScalarInvert(fTable[i+1].fDistDel);
fTable[num-1].fDistNorm = 0;
hsAssert(fTable.GetCount() == num, "Mismatch making table");
if( fTable[0].fOpacity <= 0 )
fFlags |= kCullsBefore;
if( fTable[num-1].fOpacity <= 0 )
fFlags |= kCullsBeyond;
if( fTable[0].fOpacity >= 1.f )
fFlags |= kIdleBefore;
if( fTable[num-1].fOpacity >= 1.f )
fFlags |= kIdleBeyond;
int iMin;
for( iMin = 0; (iMin < fTable.GetCount())&&(fTable[iMin].fOpacity <= 0); iMin++ );
fMinDist = fTable[0].fDistDel;
for( i = 1; i < iMin; i++ )
fMinDist += fTable[i].fDistDel;
for( iMin = 0; (iMin < fTable.GetCount())&&(fTable[iMin].fOpacity >= 1.f); iMin++ );
fMinIdle = fTable[0].fDistDel;
for( i = 1; i < iMin; i++ )
fMinIdle += fTable[i].fDistDel;
int iMax;
for( iMax = fTable.GetCount()-1; (iMax >= 0)&&(fTable[iMax].fOpacity <= 0); iMax-- );
if( ++iMax >= fTable.GetCount() )
iMax = fTable.GetCount()-1;
fMaxDist = fTable[0].fDistDel;
for( i = 1; i <= iMax; i++ )
fMaxDist += fTable[i].fDistDel;
for( iMax = fTable.GetCount()-1; (iMax >= 0)&&(fTable[iMax].fOpacity >= 1.f); iMax-- );
if( ++iMax >= fTable.GetCount() )
iMax = fTable.GetCount()-1;
fMaxIdle = fTable[0].fDistDel;
for( i = 1; i <= iMax; i++ )
fMaxIdle += fTable[i].fDistDel;
}
void hsSfxDistFade::Read(hsStream* s)
{
fTable.Reset();
fMinDist = s->ReadSwapScalar();
fMaxDist = s->ReadSwapScalar();
if( fFlags & (kIdleBefore | kIdleBeyond) )
{
fMinIdle = s->ReadSwapScalar();
fMaxIdle = s->ReadSwapScalar();
}
int32_t cnt = s->ReadSwap32();
if( cnt )
{
hsSfxDfTableEntry* arr = new hsSfxDfTableEntry[cnt];
int i;
for( i = 0; i < cnt; i++ )
{
arr[i].fDistDel = s->ReadSwapScalar();
arr[i].fDistNorm = s->ReadSwapScalar();
arr[i].fOpacity = s->ReadSwapScalar();
}
fTable.SetArray(arr, cnt);
}
}
void hsSfxDistFade::Write(hsStream* s)
{
s->WriteSwapScalar(fMinDist);
s->WriteSwapScalar(fMaxDist);
if( fFlags & (kIdleBefore | kIdleBeyond) )
{
s->WriteSwapScalar(fMinIdle);
s->WriteSwapScalar(fMaxIdle);
}
s->WriteSwap32(fTable.GetCount());
for( fTable.First(); fTable.More(); fTable.Plus() )
{
s->WriteSwapScalar(fTable.Current().fDistDel);
s->WriteSwapScalar(fTable.Current().fDistNorm);
s->WriteSwapScalar(fTable.Current().fOpacity);
}
}

View File

@ -1,107 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef hsSfxDistFade_inc
#define hsSfxDistFade_inc
#include "hsBiExpander.h"
#include "hsGRenderProcs.h"
class hsSfxDistFade : public hsGRenderProcs {
public:
enum {
kCullsBefore = 0x10000,
kCullsBeyond = 0x20000,
kDistFromView = 0x40000,
kDistFromTarget = 0x80000,
kDistAlongX = 0x100000,
kDistAlongY = 0x200000,
kDistAlongZ = 0x400000,
kWorldDist = 0x800000,
kPostInterp = 0x1000000,
kIdleBefore = 0x2000000,
kIdleBeyond = 0x4000000
};
struct hsSfxDfTableEntry {
hsScalar fDistDel;
hsScalar fDistNorm;
hsScalar fOpacity;
};
protected:
hsScalar fMinDist;
hsScalar fMaxDist;
hsScalar fMinIdle;
hsScalar fMaxIdle;
hsExpander<hsSfxDfTableEntry> fTable;
hsScalar IOpacFromDist(hsScalar dist);
public:
hsSfxDistFade();
virtual ~hsSfxDistFade();
virtual hsBool32 BeginObject(plPipeline* pipe, plDrawable* obj);
virtual void ProcessPreInterpShadeVerts(hsExpander<hsGShadeVertex*>& vList);
virtual void ProcessPostInterpShadeVerts(hsExpander<hsGShadeVertex*>& vList);
void MakeTable(float* distList, float* opacList, int num); // lists sorted from lowest cosine to highest
virtual void Read(hsStream* s);
virtual void Write(hsStream* s);
virtual const char* GetLabel() const { return "hsSfxDistFade"; }
virtual ProcType GetType() const { return kTypeDistFade; }
CLASSNAME_REGISTER( hsSfxDistFade );
GETINTERFACE_ANY( hsSfxDistFade, hsGRenderProcs );
};
#endif // hsSfxDistFade_inc

View File

@ -1,292 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsTypes.h"
#include "hsMemory.h"
#include "hsSfxDistShade.h"
#include "hsStream.h"
#include "../plGeometry/hsTriangle3.h"
#include "../plIntersect/hsBounds.h"
#include "../plDrawable/plDrawable.h"
#include "../plPipeline/plPipeline.h"
static hsScalar globalScale = 1.f;
hsSfxDistShade::hsSfxDistShade()
: fMinDist(0), fMaxDist(0)
{
}
hsSfxDistShade::~hsSfxDistShade()
{
}
hsScalar hsSfxDistShade::IShadeFromDist(hsScalar dist)
{
if( dist <= fTable[0].fDistDel )
return fTable[0].fShade;
int i;
for( i = 0; (i < fTable.GetCount()) && (dist >= fTable[i].fDistDel); i++ )
dist -= fTable[i].fDistDel;
if( i >= fTable.GetCount() )
return fTable[fTable.GetCount()-1].fShade;
dist *= fTable[i-1].fDistNorm;
hsScalar shade0 = fTable[i-1].fShade;
hsScalar shade1 = fTable[i].fShade;
return shade0 + dist * (shade1 - shade0);
}
hsBool32 hsSfxDistShade::BeginObject(plPipeline* pipe, plDrawable* obj)
{
hsGRenderProcs::BeginObject(pipe, obj);
fFlags &= ~(kCulled | kNOP);
hsPoint3 vPos;
if( GetObjectRef(1) )
{
hsPoint3 wPos;
GetObjectRef(1)->GetLocalToWorld().GetTranslate(&wPos);
hsMatrix44 w2l = pipe->GetWorldToLocal();
vPos = w2l * wPos;
}
else
{
vPos = pipe->GetViewPositionLocal();
}
hsVector3 vDir = -pipe->GetViewDirLocal();
hsScalar scale = 1.f / fPipeline->GetLocalScale();
scale *= globalScale;
hsScalar vD = -(vDir.InnerProduct(vPos));
vD *= scale;
const hsBounds3Ext& bnd = obj->GetLocalBounds();
hsPoint3 corner;
bnd.GetCorner(&corner);
hsVector3 axis[3];
bnd.GetAxes(axis+0, axis+1, axis+2);
hsScalar dist = vDir.InnerProduct(corner) + vD;
hsScalar minDist = dist;
hsScalar maxDist = dist;
int i;
for( i = 0; i < 3; i++ )
{
dist = vDir.InnerProduct(axis[i]);
if( dist < 0 )
minDist += dist;
else
maxDist += dist;
}
minDist *= scale;
maxDist *= scale;
fFlags &= ~kShadeConstant;
if( maxDist < fMinDist )
{
fFlags |= kShadeConstant;
fConstShade = fTable[0].fShade;
}
else if( minDist > fMaxDist )
{
fFlags |= kShadeConstant;
fConstShade = fTable[fTable.GetCount()-1].fShade;
}
return true;
}
void hsSfxDistShade::ProcessPreInterpShadeVerts(hsExpander<hsGShadeVertex*>& vList)
{
if( fFlags & kShadeConstant )
{
IConstShadeVerts(vList);
}
else
{
ICalcShadeVerts(vList);
}
}
void hsSfxDistShade::IConstShadeVerts(hsExpander<hsGShadeVertex*>& vList)
{
for( vList.First(); vList.More(); vList.Plus() )
{
hsGShadeVertex* svtx = vList.Current();
svtx->fShade.r *= fConstShade;
svtx->fShade.g *= fConstShade;
svtx->fShade.b *= fConstShade;
}
}
void hsSfxDistShade::ICalcShadeVerts(hsExpander<hsGShadeVertex*>& vList)
{
hsPoint3 vPos;
if( GetObjectRef(1) )
{
hsPoint3 wPos;
GetObjectRef(1)->GetLocalToWorld().GetTranslate(&wPos);
hsMatrix44 w2l = fPipeline->GetWorldToLocal();
vPos = w2l * wPos;
}
else
{
vPos = fPipeline->GetViewPositionLocal();
}
hsVector3 vDir = fPipeline->GetViewDirLocal();
hsScalar vDist = vDir.InnerProduct(vPos);
hsScalar scale = 1.f / fPipeline->GetLocalScale();
scale *= globalScale;
for( vList.First(); vList.More(); vList.Plus() )
{
hsGShadeVertex* svtx = vList.Current();
hsScalar dist = -vDir.InnerProduct(svtx->fLocalPos);
dist += vDist;
dist *= scale;
hsScalar shade = IShadeFromDist(dist);
if( shade > 0 )
{
svtx->fShade.r *= shade;
svtx->fShade.g *= shade;
svtx->fShade.b *= shade;
}
else
{
svtx->fShade.r = 0;
svtx->fShade.g = 0;
svtx->fShade.b = 0;
}
}
}
void hsSfxDistShade::MakeTable(float* distList, float* shadeList, int num)
{
fTable.Reset();
if( !num )
return;
int i;
for( i = 0; i < num; i++ )
{
hsSfxDfTableEntry* t = fTable.Append();
t->fDistDel = distList[i];
t->fShade = shadeList[i];
}
for( i = num-1; i > 0; i-- )
fTable[i].fDistDel -= fTable[i-1].fDistDel;
for( i = 0; i < num-1; i++ )
fTable[i].fDistNorm = hsScalarInvert(fTable[i+1].fDistDel);
fTable[num-1].fDistNorm = 0;
hsAssert(fTable.GetCount() == num, "Mismatch making table");
int iMin;
for( iMin = 0; (iMin < fTable.GetCount())&&(fTable[iMin].fShade <= 0); iMin++ );
fMinDist = fTable[0].fDistDel;
for( i = 1; i < iMin; i++ )
fMinDist += fTable[i].fDistDel;
int iMax;
for( iMax = fTable.GetCount()-1; (iMax >= 0)&&(fTable[iMax].fShade <= 0); iMax-- );
if( ++iMax >= fTable.GetCount() )
iMax = fTable.GetCount()-1;
fMaxDist = fTable[0].fDistDel;
for( i = 1; i <= iMax; i++ )
fMaxDist += fTable[i].fDistDel;
}
void hsSfxDistShade::Read(hsStream* s)
{
fTable.Reset();
fMinDist = s->ReadSwapScalar();
fMaxDist = s->ReadSwapScalar();
int32_t cnt = s->ReadSwap32();
if( cnt )
{
hsSfxDfTableEntry* arr = new hsSfxDfTableEntry[cnt];
int i;
for( i = 0; i < cnt; i++ )
{
arr[i].fDistDel = s->ReadSwapScalar();
arr[i].fDistNorm = s->ReadSwapScalar();
arr[i].fShade = s->ReadSwapScalar();
}
fTable.SetArray(arr, cnt);
}
}
void hsSfxDistShade::Write(hsStream* s)
{
s->WriteSwapScalar(fMinDist);
s->WriteSwapScalar(fMaxDist);
s->WriteSwap32(fTable.GetCount());
for( fTable.First(); fTable.More(); fTable.Plus() )
{
s->WriteSwapScalar(fTable.Current().fDistDel);
s->WriteSwapScalar(fTable.Current().fDistNorm);
s->WriteSwapScalar(fTable.Current().fShade);
}
}

View File

@ -1,97 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef hsSfxDistShade_inc
#define hsSfxDistShade_inc
#include "hsBiExpander.h"
#include "hsGRenderProcs.h"
class hsSfxDistShade : public hsGRenderProcs {
public:
enum {
kShadeConstant = 0x10000
};
struct hsSfxDfTableEntry {
hsScalar fDistDel;
hsScalar fDistNorm;
hsScalar fShade;
};
protected:
hsScalar fMinDist;
hsScalar fMaxDist;
hsScalar fConstShade;
hsScalar fMinIdle;
hsScalar fMaxIdle;
hsExpander<hsSfxDfTableEntry> fTable;
void IConstShadeVerts(hsExpander<hsGShadeVertex*>& vList);
void ICalcShadeVerts(hsExpander<hsGShadeVertex*>& vList);
hsScalar IShadeFromDist(hsScalar dist);
public:
hsSfxDistShade();
virtual ~hsSfxDistShade();
virtual hsBool32 BeginObject(plPipeline* pipe, plDrawable* obj);
virtual void ProcessPreInterpShadeVerts(hsExpander<hsGShadeVertex*>& vList);
void MakeTable(float* distList, float* shadeList, int num); // lists sorted from lowest cosine to highest
virtual void Read(hsStream* s);
virtual void Write(hsStream* s);
virtual const char* GetLabel() const { return "hsSfxDistShade"; }
virtual ProcType GetType() const { return kTypeDistShade; }
CLASSNAME_REGISTER( hsSfxDistShade );
GETINTERFACE_ANY( hsSfxDistShade, hsGRenderProcs );
};
#endif // hsSfxDistShade_inc

View File

@ -1,242 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsTypes.h"
#include "hsMemory.h"
#include "hsSfxGlobalShade.h"
#include "hsStream.h"
//#include "../plPipeline/hsG3DDevice.h"
#include "../plPipeline/plPipeline.h"
#include "../plGLight/hsGProjector3.h"
#include "../plSurface/hsGLayer.h"
#include "../plSurface/hsGMaterial.h"
#include "../plDrawable/plDrawable.h"
#include "../plIntersect/hsBounds.h"
void hsSfxGlobalShade::ISetIntensity(hsPoint3& pos)
{
if( fGSFlags & kFromFog )
ISetFromFog(pos);
else
if( fGSFlags & kFromClear )
ISetFromClear(pos);
else
if( fGSFlags & kFromLights )
ISetFromLights(pos);
fIntensity.a = hsMaximum(fIntensity.r, hsMaximum(fIntensity.g, fIntensity.b));
}
void hsSfxGlobalShade::ISetFromClear(hsPoint3& pos)
{
fIntensity.Set(0,0,0,0);
#if 0 // Taken out 2.26.2001 mcn 'cause it accesses the (now defunct) 3DDevice directly
hsG3DDevice* dev = fPipeline->Get3DDevice();
hsGEnvironment* env = dev->GetEnvironment();
if( env && (env->GetFlags() & hsGEnvironment::kClearColorSet) )
{
fIntensity = env->GetClearColor();
}
#endif
}
void hsSfxGlobalShade::ISetFromFog(hsPoint3& pos)
{
fIntensity.Set(0,0,0,0);
#if 0 // Taken out 2.26.2001 mcn 'cause it accesses the (now defunct) 3DDevice directly
hsG3DDevice* dev = fPipeline->Get3DDevice();
hsGEnvironment* env = dev->GetEnvironment();
if( env && (env->GetFlags() & hsGEnvironment::kFogColorSet) )
{
fIntensity = env->GetFogColor();
}
#endif
}
void hsSfxGlobalShade::ISetFromLights(hsPoint3& pos)
{
fIntensity = ISumLights(pos);
}
hsColorRGBA hsSfxGlobalShade::ISumLights(hsPoint3& pos)
{
hsColorRGBA accum;
accum.Set(0,0,0,0);
#if 0 // Taken out 2.26.2001 mcn 'cause it accesses the (now defunct) 3DDevice directly
hsG3DDevice* dev = fPipeline->Get3DDevice();
for( dev->FirstProjector(); dev->MoreProjectors(); dev->IncProjector() )
{
hsGProjector3* proj = dev->CurrProjector();
if( proj->IsOmni() )
{
hsScalar intensity = proj->AttenuatePoint(&pos) * proj->GetIntensity();
if( intensity > 0.f )
{
hsColorRGBA col = intensity * proj->GetLightColor();
accum += col;
}
}
else
if( proj->IsPerspective() ) // spot
{
hsPoint4 ang;
uint32_t clips;
proj->GetNdcPoints(1, &pos, sizeof(pos), &ang, kClipAll, &clips);
if( !clips
|| !( proj->IsAttenuated() || proj->AttenuatesAlpha() || (clips & ~kClipYon) )
)
{
hsScalar intensity = proj->AttenuatePoint(&pos) * proj->GetIntensity();
if( intensity > 0.f )
{
hsColorRGBA col = intensity * proj->GetLightColor();
accum += col;
}
}
}
else // directional
{
hsColorRGBA col = proj->GetIntensity() * proj->GetLightColor();
accum += col;
}
}
#endif
return accum;
}
void hsSfxGlobalShade::ProcessPreInterpShadeVerts(hsExpander<hsGShadeVertex*>& vList)
{
if( fCurrentLayer )
{
if( fGSFlags & kAffectDiffuse )
fCurrentLayer->SetColor(fRestoreColor.r, fRestoreColor.g, fRestoreColor.b, fRestoreColor.a);
else
fCurrentLayer->SetAmbientColor(fRestoreColor.r, fRestoreColor.g, fRestoreColor.b, fRestoreColor.a);
}
#if 0 // Taken out 2.26.2001 mcn 'cause it accesses the (now defunct) 3DDevice directly
hsG3DDevice* dev = fPipeline->Get3DDevice();
hsRefCnt_SafeAssign(fCurrentLayer, dev->GetCurrentLayer());
if( fCurrentLayer )
{
fRestoreColor = fGSFlags & kAffectDiffuse ? fCurrentLayer->GetColor() : fCurrentLayer->GetAmbientColor();
hsColorRGBA col = fAmbient;
if( fGSFlags & kScalarIntensity )
{
col.r += fDiffuse.r * fIntensity.a;
col.g += fDiffuse.g * fIntensity.a;
col.b += fDiffuse.b * fIntensity.a;
}
else
{
col.r += fDiffuse.r * fIntensity.r;
col.g += fDiffuse.g * fIntensity.g;
col.b += fDiffuse.b * fIntensity.b;
}
if( fGSFlags & kAffectDiffuse )
fCurrentLayer->SetColor(col.r, col.g, col.b, fRestoreColor.a);
else
fCurrentLayer->SetAmbientColor(col.r, col.g, col.b, fRestoreColor.a);
}
#endif
}
hsBool32 hsSfxGlobalShade::BeginObject(plPipeline* pipe, plDrawable* obj)
{
hsBool32 retVal = hsGRenderProcs::BeginObject(pipe, obj);
const hsBounds3Ext& bnd = obj->GetLocalBounds();
hsPoint3 pos = bnd.GetCenter();
ISetIntensity(pos);
return retVal;
}
void hsSfxGlobalShade::EndObject()
{
hsGRenderProcs::EndObject();
if( fCurrentLayer )
{
if( fGSFlags & kAffectDiffuse )
fCurrentLayer->SetColor(fRestoreColor.r, fRestoreColor.g, fRestoreColor.b, fRestoreColor.a);
else
fCurrentLayer->SetAmbientColor(fRestoreColor.r, fRestoreColor.g, fRestoreColor.b, fRestoreColor.a);
hsRefCnt_SafeUnRef(fCurrentLayer);
fCurrentLayer = nil;
}
}
void hsSfxGlobalShade::Read(hsStream* s)
{
fGSFlags = s->ReadSwap32();
fAmbient.Read(s);
fDiffuse.Read(s);
if( fGSFlags & kFromLights )
fGSFlags |= kAffectDiffuse;
}
void hsSfxGlobalShade::Write(hsStream* s)
{
s->WriteSwap32(fGSFlags);
fAmbient.Write(s);
fDiffuse.Write(s);
}
hsSfxGlobalShade::hsSfxGlobalShade()
{
fCurrentLayer = nil;
fGSFlags = 0;
fAmbient.Set(0,0,0,0);
fDiffuse.Set(1.f,1.f,1.f,1.f);
}
hsSfxGlobalShade::~hsSfxGlobalShade()
{
hsRefCnt_SafeUnRef(fCurrentLayer); // should be nil anyway unless we're destroyed during processing
}

View File

@ -1,120 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef hsSfxGlobalShade_inc
#define hsSfxGlobalShade_inc
#include "hsBiExpander.h"
#include "hsGRenderProcs.h"
#include "hsColorRGBA.h"
#include "hsGeometry3.h"
class hsGLayer;
class hsSfxGlobalShade : public hsGRenderProcs {
public:
enum {
kNone = 0x0,
kFromFog = 0x1,
kFromClear = 0x2,
kFromLights = 0x4,
kSourceMask = kFromFog | kFromClear | kFromLights,
kScalarIntensity = 0x8,
kAffectDiffuse = 0x10
};
protected:
// Constants from which to work.
uint32_t fGSFlags;
hsColorRGBA fAmbient;
hsColorRGBA fDiffuse;
// Calculated each invocation.
hsColorRGBA fIntensity;
hsGLayer* fCurrentLayer;
hsColorRGBA fRestoreColor;
void ISetIntensity(hsPoint3& pos);
void ISetFromFog(hsPoint3& pos);
void ISetFromClear(hsPoint3& pos);
void ISetFromLights(hsPoint3& pos);
hsColorRGBA ISumLights(hsPoint3& pos);
public:
hsSfxGlobalShade();
virtual ~hsSfxGlobalShade();
virtual void ProcessPreInterpShadeVerts(hsExpander<hsGShadeVertex*>& vList);
virtual hsBool32 BeginObject(plPipeline* pipe, plDrawable* obj);
virtual void EndObject();
virtual void Read(hsStream* s);
virtual void Write(hsStream* s);
virtual const char* GetLabel() const { return "hsSfxGlobalShade"; }
virtual ProcType GetType() const { return kTypeGlobalShade; }
void SetAmbient(const hsColorRGBA& col) { fAmbient = col; }
hsColorRGBA GetAmbient() const { return fAmbient; }
void SetDiffuse(const hsColorRGBA& col) { fDiffuse = col; }
hsColorRGBA GetDiffuse() const { return fDiffuse; }
void SetSource(uint32_t f) { fGSFlags &= ~kSourceMask; fGSFlags |= f; }
uint32_t GetSource() { return fGSFlags & kSourceMask; }
void SetScalar(hsBool32 on) { if(on)fGSFlags |= kScalarIntensity; else fGSFlags &= ~kScalarIntensity; }
hsBool32 GetScalar() { return 0 != (fGSFlags & kScalarIntensity); }
void SetAffectDiffuse(hsBool32 on) { if(on)fGSFlags |= kAffectDiffuse; else fGSFlags &= ~kAffectDiffuse; }
hsBool32 GetAffectDiffuse() { return 0 != (fGSFlags & kAffectDiffuse); }
CLASSNAME_REGISTER( hsSfxGlobalShade );
GETINTERFACE_ANY( hsSfxGlobalShade, hsGRenderProcs );
};
#endif // hsSfxGlobalShade_inc

View File

@ -1,81 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsTypes.h"
#include "hsGeometry3.h"
#include "hsSfxIntenseAlpha.h"
#include "../plGeometry/hsTriangle3.h"
hsSfxIntenseAlpha::hsSfxIntenseAlpha()
: fMinAlpha(0)
{
fFlags |= kInclusive;
}
hsSfxIntenseAlpha::~hsSfxIntenseAlpha()
{
}
void hsSfxIntenseAlpha::ProcessPreInterpShadeVerts(hsExpander<hsGShadeVertex*>& vList)
{
hsScalar oScale = 1.f - fMinAlpha;
for( vList.First(); vList.More(); vList.Plus() )
{
hsGShadeVertex* s = vList.Current();
hsScalar o = hsMaximum(hsMaximum(s->fShade.r, s->fShade.g), s->fShade.b);
o *= oScale;
o += fMinAlpha;
s->fShade.a *= o;
}
}
void hsSfxIntenseAlpha::Read(hsStream* s)
{
fMinAlpha = s->ReadSwapScalar();
}
void hsSfxIntenseAlpha::Write(hsStream* s)
{
s->WriteSwapScalar(fMinAlpha);
}

View File

@ -1,82 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef hsSfxIntenseAlpha_inc
#define hsSfxIntenseAlpha_inc
#include "hsGRenderProcs.h"
#include "hsGeometry3.h"
class hsSfxIntenseAlpha : public hsGRenderProcs
{
protected:
hsVector3 fDirViewPerp;
hsVector3 fDirScreen;
hsScalar fOpacityScale;
hsScalar fOpacityMax;
hsScalar fMinAlpha;
public:
hsSfxIntenseAlpha();
virtual ~hsSfxIntenseAlpha();
void SetMinAlpha(hsScalar s) { fMinAlpha = s; }
hsScalar GetMinAlpha() { return fMinAlpha; }
virtual void ProcessPreInterpShadeVerts(hsExpander<hsGShadeVertex*>& vList);
virtual void Read(hsStream* s);
virtual void Write(hsStream* s);
virtual const char* GetLabel() const { return "hsSfxIntenseAlpha"; }
virtual ProcType GetType() const { return kTypeIntenseAlpha; }
CLASSNAME_REGISTER( hsSfxIntenseAlpha );
GETINTERFACE_ANY( hsSfxIntenseAlpha, hsGRenderProcs );
};
#endif // hsSfxIntenseAlpha_inc

View File

@ -1,320 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsTypes.h"
#include "hsMemory.h"
#include "hsSfxObjDistFade.h"
#include "hsStream.h"
//#include "hsG3DDevice.h"
#include "../plPipeline/plPipeline.h"
#include "../plGeometry/hsTriangle3.h"
#include "../plIntersect/hsBounds.h"
#include "../plDrawable/plDrawable.h"
static hsScalar globalScale = 1.f;
hsSfxObjDistFade::hsSfxObjDistFade()
: fMinDist(0), fMaxDist(0), fTreeCnt(0)
{
}
hsSfxObjDistFade::~hsSfxObjDistFade()
{
}
hsScalar hsSfxObjDistFade::IOpacFromDist(hsScalar dist)
{
if( dist <= fTable[0].fDistDel )
return fTable[0].fOpacity;
int i;
for( i = 0; (i < fTable.GetCount()) && (dist >= fTable[i].fDistDel); i++ )
dist -= fTable[i].fDistDel;
if( i >= fTable.GetCount() )
return fTable[fTable.GetCount()-1].fOpacity;
dist *= fTable[i-1].fDistNorm;
hsScalar opac0 = fTable[i-1].fOpacity;
hsScalar opac1 = fTable[i].fOpacity;
return opac0 + dist * (opac1 - opac0);
}
hsBool32 hsSfxObjDistFade::ISetOpac(plDrawable* refObj)
{
hsPoint3 refPos;
if( fFlags & kByBoundsCenter )
{
const hsBounds3Ext& bnd = refObj->GetWorldBounds();
if( kBoundsNormal != bnd.GetType() )
return true;
refPos = bnd.GetCenter();
}
else
{
refObj->GetLocalToWorld().GetTranslate(&refPos);
}
fFlags &= ~(kCulled | kNOP);
hsPoint3 vPos;
if( GetObjectRef(1) )
{
GetObjectRef(1)->GetLocalToWorld().GetTranslate(&vPos);
}
else
{
vPos = fPipeline->GetViewPositionWorld();
}
hsScalar dist = hsVector3(&vPos, &refPos).Magnitude();
if( (fFlags & kCullsBefore)
&&(dist <= fMinDist) )
{
fFlags |= kCulled;
return false;
}
if( (fFlags & kCullsBeyond)
&&(dist > fMaxDist) )
{
fFlags |= kCulled;
return false;
}
if( (fFlags & kIdleBefore)
&&(dist < fMinIdle) )
fFlags |= kNOP;
else
if( (fFlags & kIdleBeyond)
&&(dist > fMaxIdle) )
fFlags |= kNOP;
else
{
hsScalar opac = IOpacFromDist(dist);
hsColorRGBA col = fColorizer.GetCurrentColor();
if( fColorizer.Alpharizing() )
col.a *= opac;
else
col.a = opac;
fColorizer.PushColorize(col, fColorizer.Colorizing());
if( fFlags & kNoZTrans )
{
if( !(fPipeline->GetMaterialOverrideOff(hsGMatState::kZ) & hsGMatState::kZNoZWrite) )
{
fRestoreOver = fPipeline->PushMaterialOverride(hsGMatState::kZ, hsGMatState::kZNoZWrite, true);
}
}
}
return true;
}
hsBool32 hsSfxObjDistFade::BeginObject(plPipeline* pipe, plDrawable* obj)
{
if( Inclusive() )
return true;
hsGRenderProcs::BeginObject(pipe, obj);
#if 0
// This is bogus. We may want to fade something, but not fade it out entirely.
if( !(fFlags & (kCullsBefore | kCullsBeyond | kIdleBefore | kIdleBeyond)) )
return true;
#endif
plDrawable* refObj = fFlags & kObjectRefs ? GetObjectRef(0) : nil;
if( !refObj )
refObj = obj;
return ISetOpac(refObj);
}
hsBool32 hsSfxObjDistFade::BeginTree(plPipeline* pipe, plDrawable* obj)
{
if( !Inclusive() )
return true;
if( fTreeCnt++ )
return true;
hsGRenderProcs::BeginTree(pipe, obj);
plDrawable* refObj = fFlags & kObjectRefs ? GetObjectRef(0) : nil;
if( !refObj )
refObj = obj;
return ISetOpac(refObj);
}
void hsSfxObjDistFade::EndObject()
{
if( !Inclusive() )
{
fPipeline->PopMaterialOverride(fRestoreOver, true);
}
hsGRenderProcs::EndObject();
}
void hsSfxObjDistFade::EndTree()
{
if( Inclusive() )
{
fPipeline->PopMaterialOverride(fRestoreOver, true);
fTreeCnt--;
hsAssert(fTreeCnt >= 0, "Push/Pop tree problem");
}
hsGRenderProcs::EndTree();
}
void hsSfxObjDistFade::MakeTable(float* distList, float* opacList, int num)
{
fTable.Reset();
if( !num )
return;
int i;
for( i = 0; i < num; i++ )
{
hsSfxDfTableEntry* t = fTable.Append();
t->fDistDel = distList[i];
t->fOpacity = opacList[i];
}
for( i = num-1; i > 0; i-- )
fTable[i].fDistDel -= fTable[i-1].fDistDel;
for( i = 0; i < num-1; i++ )
fTable[i].fDistNorm = hsScalarInvert(fTable[i+1].fDistDel);
fTable[num-1].fDistNorm = 0;
hsAssert(fTable.GetCount() == num, "Mismatch making table");
if( fTable[0].fOpacity <= 0 )
fFlags |= kCullsBefore;
if( fTable[num-1].fOpacity <= 0 )
fFlags |= kCullsBeyond;
if( fTable[0].fOpacity >= 1.f )
fFlags |= kIdleBefore;
if( fTable[num-1].fOpacity >= 1.f )
fFlags |= kIdleBeyond;
int iMin;
for( iMin = 0; (iMin < fTable.GetCount())&&(fTable[iMin].fOpacity <= 0); iMin++ );
fMinDist = fTable[0].fDistDel;
for( i = 1; i < iMin; i++ )
fMinDist += fTable[i].fDistDel;
for( iMin = 0; (iMin < fTable.GetCount())&&(fTable[iMin].fOpacity >= 1.f); iMin++ );
fMinIdle = fTable[0].fDistDel;
for( i = 1; i < iMin; i++ )
fMinIdle += fTable[i].fDistDel;
int iMax;
for( iMax = fTable.GetCount()-1; (iMax >= 0)&&(fTable[iMax].fOpacity <= 0); iMax-- );
if( ++iMax >= fTable.GetCount() )
iMax = fTable.GetCount()-1;
fMaxDist = fTable[0].fDistDel;
for( i = 1; i <= iMax; i++ )
fMaxDist += fTable[i].fDistDel;
for( iMax = fTable.GetCount()-1; (iMax >= 0)&&(fTable[iMax].fOpacity >= 1.f); iMax-- );
if( ++iMax >= fTable.GetCount() )
iMax = fTable.GetCount()-1;
fMaxIdle = fTable[0].fDistDel;
for( i = 1; i <= iMax; i++ )
fMaxIdle += fTable[i].fDistDel;
}
void hsSfxObjDistFade::Read(hsStream* s)
{
fTable.Reset();
fMinDist = s->ReadSwapScalar();
fMaxDist = s->ReadSwapScalar();
if( fFlags & (kIdleBefore | kIdleBeyond) )
{
fMinIdle = s->ReadSwapScalar();
fMaxIdle = s->ReadSwapScalar();
}
int32_t cnt = s->ReadSwap32();
if( cnt )
{
hsSfxDfTableEntry* arr = new hsSfxDfTableEntry[cnt];
int i;
for( i = 0; i < cnt; i++ )
{
arr[i].fDistDel = s->ReadSwapScalar();
arr[i].fDistNorm = s->ReadSwapScalar();
arr[i].fOpacity = s->ReadSwapScalar();
}
fTable.SetArray(arr, cnt);
}
}
void hsSfxObjDistFade::Write(hsStream* s)
{
s->WriteSwapScalar(fMinDist);
s->WriteSwapScalar(fMaxDist);
if( fFlags & (kIdleBefore | kIdleBeyond) )
{
s->WriteSwapScalar(fMinIdle);
s->WriteSwapScalar(fMaxIdle);
}
s->WriteSwap32(fTable.GetCount());
for( fTable.First(); fTable.More(); fTable.Plus() )
{
s->WriteSwapScalar(fTable.Current().fDistDel);
s->WriteSwapScalar(fTable.Current().fDistNorm);
s->WriteSwapScalar(fTable.Current().fOpacity);
}
}

View File

@ -1,116 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef hsSfxObjDistFade_inc
#define hsSfxObjDistFade_inc
#include "hsBiExpander.h"
#include "hsGRenderProcs.h"
#include "../plPipeline/hsGMatState.h"
class hsSfxObjDistFade : public hsGRenderProcs {
public:
enum {
kCullsBefore = 0x10000,
kCullsBeyond = 0x20000,
kDistFromView = 0x40000,
kDistFromTarget = 0x80000,
kDistAlongX = 0x100000,
kZOff = 0x200000,
kNoZTrans = 0x400000,
kByBoundsCenter = 0x800000,
kPostInterp = 0x1000000,
kIdleBefore = 0x2000000,
kIdleBeyond = 0x4000000,
kZWasOff = 0x8000000
};
struct hsSfxDfTableEntry {
hsScalar fDistDel;
hsScalar fDistNorm;
hsScalar fOpacity;
};
protected:
hsScalar fMinDist;
hsScalar fMaxDist;
hsScalar fMinIdle;
hsScalar fMaxIdle;
int32_t fTreeCnt;
hsExpander<hsSfxDfTableEntry> fTable;
hsGMatState fRestoreOver;
hsBool32 ISetOpac(plDrawable* refObj);
hsScalar IOpacFromDist(hsScalar dist);
public:
hsSfxObjDistFade();
virtual ~hsSfxObjDistFade();
virtual hsBool32 BeginTree(plPipeline* pipe, plDrawable* root);
virtual hsBool32 BeginObject(plPipeline* pipe, plDrawable* obj);
virtual void EndObject();
virtual void EndTree();
void MakeTable(float* distList, float* opacList, int num); // lists sorted from lowest cosine to highest
virtual void Read(hsStream* s);
virtual void Write(hsStream* s);
virtual const char* GetLabel() const { return "hsSfxObjDistFade"; }
virtual ProcType GetType() const { return kTypeObjDistFade; }
CLASSNAME_REGISTER( hsSfxObjDistFade );
GETINTERFACE_ANY( hsSfxObjDistFade, hsGRenderProcs );
};
#endif // hsSfxObjDistFade_inc

View File

@ -1,217 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsTypes.h"
#include "hsMemory.h"
#include "hsSfxObjDistShade.h"
#include "hsStream.h"
#include "../plPipeline/plPipeline.h"
#include "../plGeometry/hsTriangle3.h"
#include "../plIntersect/hsBounds.h"
#include "../plDrawable/plDrawable.h"
static hsScalar globalScale = 1.f;
hsSfxObjDistShade::hsSfxObjDistShade()
: fMinDist(0), fMaxDist(0), fTreeCnt(0)
{
}
hsSfxObjDistShade::~hsSfxObjDistShade()
{
}
hsScalar hsSfxObjDistShade::IShadeFromDist(hsScalar dist)
{
if( dist <= fTable[0].fDistDel )
return fTable[0].fShade;
int i;
for( i = 0; (i < fTable.GetCount()) && (dist >= fTable[i].fDistDel); i++ )
dist -= fTable[i].fDistDel;
if( i >= fTable.GetCount() )
return fTable[fTable.GetCount()-1].fShade;
dist *= fTable[i-1].fDistNorm;
hsScalar shade0 = fTable[i-1].fShade;
hsScalar shade1 = fTable[i].fShade;
return shade0 + dist * (shade1 - shade0);
}
hsBool32 hsSfxObjDistShade::ISetShade(plDrawable* refObj)
{
hsPoint3 refPos;
if( fFlags & kByBoundsCenter )
{
const hsBounds3Ext& bnd = refObj->GetWorldBounds();
if( kBoundsNormal != bnd.GetType() )
return true;
refPos = bnd.GetCenter();
}
else
{
refObj->GetLocalToWorld().GetTranslate(&refPos);
}
hsPoint3 vPos;
if( GetObjectRef(1) )
{
GetObjectRef(1)->GetLocalToWorld().GetTranslate(&vPos);
}
else
{
vPos = fPipeline->GetViewPositionWorld();
}
hsScalar dist = hsVector3(&vPos, &refPos).Magnitude();
hsScalar shade = IShadeFromDist(dist);
hsColorRGBA col = fColorizer.GetCurrentColor();
if( fColorizer.Colorizing() )
{
col.r *= shade;
col.g *= shade;
col.b *= shade;
}
else
{
col.r = shade;
col.g = shade;
col.b = shade;
}
fColorizer.PushColorize(col, false);
return true;
}
hsBool32 hsSfxObjDistShade::BeginObject(plPipeline* pipe, plDrawable* obj)
{
hsGRenderProcs::BeginObject(pipe, obj);
plDrawable* refObj = fFlags & kObjectRefs ? GetObjectRef(0) : nil;
if( !refObj )
refObj = obj;
return ISetShade(refObj);
}
void hsSfxObjDistShade::MakeTable(float* distList, float* shadeList, int num)
{
fTable.Reset();
if( !num )
return;
int i;
for( i = 0; i < num; i++ )
{
hsSfxDfTableEntry* t = fTable.Append();
t->fDistDel = distList[i];
t->fShade = shadeList[i];
}
for( i = num-1; i > 0; i-- )
fTable[i].fDistDel -= fTable[i-1].fDistDel;
for( i = 0; i < num-1; i++ )
fTable[i].fDistNorm = hsScalarInvert(fTable[i+1].fDistDel);
fTable[num-1].fDistNorm = 0;
hsAssert(fTable.GetCount() == num, "Mismatch making table");
int iMin;
for( iMin = 0; (iMin < fTable.GetCount())&&(fTable[iMin].fShade <= 0); iMin++ );
fMinDist = fTable[0].fDistDel;
for( i = 1; i < iMin; i++ )
fMinDist += fTable[i].fDistDel;
int iMax;
for( iMax = fTable.GetCount()-1; (iMax >= 0)&&(fTable[iMax].fShade <= 0); iMax-- );
if( ++iMax >= fTable.GetCount() )
iMax = fTable.GetCount()-1;
fMaxDist = fTable[0].fDistDel;
for( i = 1; i <= iMax; i++ )
fMaxDist += fTable[i].fDistDel;
}
void hsSfxObjDistShade::Read(hsStream* s)
{
fTable.Reset();
fMinDist = s->ReadSwapScalar();
fMaxDist = s->ReadSwapScalar();
int32_t cnt = s->ReadSwap32();
if( cnt )
{
hsSfxDfTableEntry* arr = new hsSfxDfTableEntry[cnt];
int i;
for( i = 0; i < cnt; i++ )
{
arr[i].fDistDel = s->ReadSwapScalar();
arr[i].fDistNorm = s->ReadSwapScalar();
arr[i].fShade = s->ReadSwapScalar();
}
fTable.SetArray(arr, cnt);
}
}
void hsSfxObjDistShade::Write(hsStream* s)
{
s->WriteSwapScalar(fMinDist);
s->WriteSwapScalar(fMaxDist);
s->WriteSwap32(fTable.GetCount());
for( fTable.First(); fTable.More(); fTable.Plus() )
{
s->WriteSwapScalar(fTable.Current().fDistDel);
s->WriteSwapScalar(fTable.Current().fDistNorm);
s->WriteSwapScalar(fTable.Current().fShade);
}
}

View File

@ -1,98 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef hsSfxObjDistShade_inc
#define hsSfxObjDistShade_inc
#include "hsBiExpander.h"
#include "hsGRenderProcs.h"
class hsSfxObjDistShade : public hsGRenderProcs {
public:
enum {
kShadeConstant = 0x10000,
kByBoundsCenter = 0x800000,
};
struct hsSfxDfTableEntry {
hsScalar fDistDel;
hsScalar fDistNorm;
hsScalar fShade;
};
protected:
hsScalar fMinDist;
hsScalar fMaxDist;
hsScalar fConstShade;
hsScalar fMinIdle;
hsScalar fMaxIdle;
int32_t fTreeCnt;
hsExpander<hsSfxDfTableEntry> fTable;
hsBool32 ISetShade(plDrawable* refObj);
hsScalar IShadeFromDist(hsScalar dist);
public:
hsSfxObjDistShade();
virtual ~hsSfxObjDistShade();
virtual hsBool32 BeginObject(plPipeline* pipe, plDrawable* obj);
void MakeTable(float* distList, float* shadeList, int num); // lists sorted from lowest cosine to highest
virtual void Read(hsStream* s);
virtual void Write(hsStream* s);
virtual const char* GetLabel() const { return "hsSfxObjDistShade"; }
virtual ProcType GetType() const { return kTypeObjDistShade; }
CLASSNAME_REGISTER( hsSfxObjDistShade );
GETINTERFACE_ANY( hsSfxObjDistShade, hsGRenderProcs );
};
#endif // hsSfxObjDistShade_inc

View File

@ -1,80 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef plGRenderProcsCreatable_inc
#define plGRenderProcsCreatable_inc
#include "../plResMgr/plCreator.h"
#include "hsGRenderProcs.h"
REGISTER_NONCREATABLE( hsGRenderProcs );
#include "hsSfxAngleFade.h"
REGISTER_CREATABLE( hsSfxAngleFade );
#include "hsSfxDistFade.h"
REGISTER_CREATABLE( hsSfxDistFade );
#include "hsSfxDistShade.h"
REGISTER_CREATABLE( hsSfxDistShade );
#include "hsSfxGlobalShade.h"
REGISTER_CREATABLE( hsSfxGlobalShade );
#include "hsSfxIntenseAlpha.h"
REGISTER_CREATABLE( hsSfxIntenseAlpha );
#include "hsSfxObjDistFade.h"
REGISTER_CREATABLE( hsSfxObjDistFade );
#include "hsSfxObjDistShade.h"
REGISTER_CREATABLE( hsSfxObjDistShade );
#endif // plGRenderProcsCreatable_inc

View File

@ -1,763 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsTypes.h"
#include "hsStream.h"
#include "hsOscillator.h"
#include "../plMath/hsFastMath.h"
#include "hsGTriMesh.h"
#include "hsTriangle3.h"
#include "../plPipeline/plPipeline.h"
#if defined(__MWERKS__) && !defined(HS_DEBUGGING)
#pragma optimization_level 0
#endif
static hsScalar rnd0_1()
{
return hsScalar(rand()) / hsScalar(RAND_MAX);
}
void hsWave::Save(hsStream* s, hsScalar secs)
{
fWorldCenter.Write(s);
s->WriteSwapScalar(fWorldFrequency);
s->WriteSwapScalar(fWorldAmplitude);
s->WriteSwapScalar(fPhase);
s->WriteSwapScalar(fRate);
s->WriteSwapScalar(secs - fStartSecs);
s->WriteSwapScalar(fSecsToLive);
}
void hsWave::Load(hsStream* s, hsScalar secs)
{
fWorldCenter.Read(s);
fWorldFrequency = s->ReadSwapScalar();
fWorldAmplitude = s->ReadSwapScalar();
fPhase = s->ReadSwapScalar();
fRate = s->ReadSwapScalar();
fStartSecs = s->ReadSwapScalar();
fStartSecs = secs - fStartSecs;
fSecsToLive = s->ReadSwapScalar();
}
void hsWave::Init(hsScalar secs, hsPoint3& center, hsScalar per, hsScalar amp, hsScalar rate, hsScalar life, hsBool32 attenOut)
{
fStartSecs = secs;
fWorldCenter = center;
fWorldFrequency = hsScalarInvert(per);
fWorldAmplitude = amp;
fRate = rate;
fSecsToLive = life;
AttenuateOut(attenOut);
}
hsBool32 hsWave::IsSpent(hsScalar secs) const
{
return secs - fStartSecs > fSecsToLive;
}
void hsWave::Accumulate(const hsPoint3& pos, const hsVector3& localZ, hsVector3& accum, hsVector3& accumNorm) const
{
hsVector3 del(&pos, &fLocalCenter);
hsScalar dot = del.InnerProduct(localZ);
dot *= -2.f;
del += localZ * dot;
hsScalar dist = del.MagnitudeSquared();
dist = hsFastMath::InvSqrtAppr(dist);
del *= dist;
dist = hsScalarInvert(dist);
hsScalar ampl = fLocalAmplitude;
if( fAttenuateOutScale > 0 )
{
if( dist > fInnerRadius )
{
if( dist > fOuterRadius )
return;
ampl *= fOuterRadius - dist;
ampl *= fAttenuateOutScale;
}
}
dist *= fLocalFrequency;
dist += fPhase;
hsScalar s, c;
hsFastMath::SinCosAppr(dist, s, c);
s *= ampl;
s += ampl;
c *= ampl * fLocalFrequency;
// accum += s * localZ;
accum.fZ += s / localZ.fZ;
hsVector3 norm;
norm = localZ;
norm += del * -c;
accumNorm += norm;
return;
}
void hsWave::Update(hsScalar secs, const hsMatrix44& l2w, const hsMatrix44& w2l)
{
if( l2w.fFlags & hsMatrix44::kIsIdent )
{
fLocalCenter = fWorldCenter;
fLocalFrequency = fWorldFrequency;
fLocalAmplitude = fWorldAmplitude;
}
else
{
hsVector3 ax;
ax.Set(w2l.fMap[0][2], w2l.fMap[1][2], w2l.fMap[2][2]);
hsScalar ooScale = ax.MagnitudeSquared();
ooScale = hsFastMath::InvSqrtAppr(ooScale);
fLocalCenter = w2l * fWorldCenter;
fLocalFrequency = fWorldFrequency * ooScale;
hsScalar scale = 1.f / ooScale;
fLocalAmplitude = fWorldAmplitude * scale;
}
fLocalAmplitude *= AgeScale(secs);
if( fAttenuateOutScale > 0 )
{
fInnerRadius = fRate * (secs - fStartSecs) * hsScalarPI * 2.f;
fOuterRadius = fInnerRadius * (5.f/4.f);
fAttenuateOutScale = hsScalarInvert(fOuterRadius - fInnerRadius);
}
fPhase = -(secs - fStartSecs) * fRate * hsScalarPI * 2.f;
}
hsScalar hsWave::ScaledAmplitude(hsScalar secs) const
{
return fWorldAmplitude * AgeScale(secs);
}
hsScalar hsWave::AgeScale(hsScalar secs) const
{
hsScalar age = secs - fStartSecs;
extern int dbgCurrentTest;
if( dbgCurrentTest )
{
age *= 4.f;
age -= 2.f * fSecsToLive;
if( age < 0 )
age = -age;
age -= fSecsToLive;
}
else
{
age *= 2.f;
age -= fSecsToLive;
if( age < 0 )
age = -age;
}
hsScalar ageScale = 1.f - age / fSecsToLive;
if( ageScale < 0 )
ageScale = 0;
else if( ageScale > 1.f )
ageScale = 1.f;
return ageScale;
}
hsOscillator::hsOscillator()
{
}
hsOscillator::~hsOscillator()
{
}
hsWave& hsOscillator::GetWeakestWave(hsScalar secs)
{
hsAssert(!GetDisabled(), "Shouldn't be messing with disabled oscillator system");
int weakest = 0;
hsScalar amp = fWaves[0].ScaledAmplitude(secs);
int i;
for( i = 0; i < fWaves.GetCount(); i++ )
{
hsScalar tAmp = fWaves[i].ScaledAmplitude(secs);
if( tAmp < amp )
{
weakest = i;
amp = tAmp;
}
}
return fWaves[weakest];
}
hsWave& hsOscillator::GetTempWave(hsScalar secs)
{
int i;
for( i = 0; i < fTempWaves.GetCount(); i++ )
{
if( fTempWaves[i].IsSpent(secs) )
return fTempWaves[i];
}
fTempWaves.Push();
return fTempWaves[fTempWaves.GetCount()-1];
}
void hsOscillator::ISpawnWave(hsScalar secs, int i)
{
hsPoint3 corner;
fWorldCenterBounds.GetCorner(&corner);
hsVector3 ax[3];
fWorldCenterBounds.GetAxes(ax+0, ax+1, ax+2);
hsScalar r;
r = rnd0_1();
ax[0] *= r;
corner += ax[0];
r = rnd0_1();
ax[1] *= r;
corner += ax[1];
r = rnd0_1();
ax[2] *= r;
corner += ax[2];
hsScalar per = fMinPeriod;
r = rnd0_1();
hsScalar rr = r;
r *= fMaxPeriod - fMinPeriod;
per += r;
hsScalar amp = fMinAmplitude;
r = rr * rnd0_1();
r *= fMaxAmplitude - fMinAmplitude;
amp += r;
hsScalar life = fMinLife;
r = rnd0_1();
r *= fMaxLife - fMinLife;
life += r;
hsScalar rate = fMinRate;
r = rnd0_1();
r *= fMaxRate - fMinRate;
rate += r;
fWaves[i].Init(secs, corner, per, amp, rate, life);
}
void hsOscillator::IUpdate(hsScalar secs, plPipeline* pipe, const hsMatrix44& l2w, const hsMatrix44& w2l)
{
if( GetDisabled() )
return;
fWorldCenter = pipe->GetViewPositionWorld();
fWorldCenter.fZ = (fWorldCenterBounds.GetMins().fZ + fWorldCenterBounds.GetMaxs().fZ) * 0.5f;
fLocalCenter = w2l * fWorldCenter;
fLocalToWorld = l2w;
fWorldToLocal = w2l;
fLocalX.Set(w2l.fMap[0][0],w2l.fMap[1][0],w2l.fMap[2][0]);
fLocalX.Normalize();
fLocalY.Set(w2l.fMap[0][1],w2l.fMap[1][1],w2l.fMap[2][1]);
fLocalY.Normalize();
fLocalZ.Set(w2l.fMap[0][2],w2l.fMap[1][2],w2l.fMap[2][2]);
fLocalZ.Normalize();
hsVector3 ax;
hsScalar ooScale;
ax.Set(w2l.fMap[0][0], w2l.fMap[1][0], w2l.fMap[2][0]);
ooScale = ax.MagnitudeSquared();
ooScale = hsFastMath::InvSqrtAppr(ooScale);
fLocalAttenScale.fX = fWorldAttenScale.fX * ooScale;
ax.Set(w2l.fMap[0][1], w2l.fMap[1][1], w2l.fMap[2][1]);
ooScale = ax.MagnitudeSquared();
ooScale = hsFastMath::InvSqrtAppr(ooScale);
fLocalAttenScale.fY = fWorldAttenScale.fY * ooScale;
fLocalAttenScale.fZ = 0;
int i;
for( i = 0; i < fWaves.GetCount(); i++ )
{
if( fWaves[i].IsSpent(secs) )
ISpawnWave(secs, i);
fWaves[i].Update(secs, l2w, w2l);
}
for( i = 0; i < fTempWaves.GetCount(); i++ )
{
while( (i < fTempWaves.GetCount()) && fTempWaves[i].IsSpent(secs) )
fTempWaves.Remove(i, 1);
if( i < fTempWaves.GetCount() )
fTempWaves[i].Update(secs, l2w, w2l);
}
}
hsScalar hsOscillator::IAttenuate(const hsPoint3& in) const
{
const hsPoint3& cen = fLocalCenter;
hsVector3 del(&in, &cen);
hsScalar atX = del.InnerProduct(fLocalX);
atX *= fLocalAttenScale.fX;
if( atX > 0 )
atX = -atX;
atX += 1.f;
if( atX < 0 )
atX = 0;
hsScalar atY = del.InnerProduct(fLocalY);
atY *= fLocalAttenScale.fY;
if( atY > 0 )
atY = -atY;
atY += 1.f;
if( atY < 0 )
atY = 0;
hsScalar at = atX * atY;
return at;
}
void hsOscillator::AdjustWorldBounds(const hsMatrix44& l2w, const hsMatrix44& w2l, hsBounds3Ext& bnd) const
{
if( GetDisabled() )
return;
hsVector3 adj;
adj.Set(0,1.f/fLocalZ.fZ,0);
adj = l2w * adj;
adj *= fMaxAmplitude * fWaves.GetCount();
bnd.Union(&adj);
adj = -adj;
bnd.Union(&adj);
}
void hsOscillator::IPerterb(const hsPoint3& in, hsGVertex3& out) const
{
hsPoint3 pos = in;
hsVector3 del(&pos, &fLocalCenter);
hsScalar dot = del.InnerProduct(fLocalZ);
pos += fLocalZ * -dot;
hsVector3 accum;
hsVector3 accumNorm;
accum.Set(0,0,0);
accumNorm.Set(0,0,0);
int i;
for( i = 0; i < fWaves.GetCount(); i++ )
{
fWaves[i].Accumulate(pos, fLocalZ, accum, accumNorm);
}
for( i = 0; i < fTempWaves.GetCount(); i++ )
{
fTempWaves[i].Accumulate(pos, fLocalZ, accum, accumNorm);
}
hsScalar atten = IAttenuate(pos);
static int attenuating = 1;
if( attenuating ) // nuke me
accum *= atten;
out.fLocalPos = in + accum;
hsScalar invNorm = hsFastMath::InvSqrtAppr(accumNorm.MagnitudeSquared());
accumNorm *= invNorm;
out.fNormal = accumNorm;
}
void hsOscillator::Read(hsStream* s)
{
int n = s->ReadSwap32();
SetNumWaves(n);
fWorldAttenScale.Read(s);
fWorldCenterBounds.Read(s);
fMinPeriod = s->ReadSwapScalar();
fMaxPeriod = s->ReadSwapScalar();
fMinAmplitude = s->ReadSwapScalar();
fMaxAmplitude = s->ReadSwapScalar();
fMinRate = s->ReadSwapScalar();
fMaxRate = s->ReadSwapScalar();
fMinLife = s->ReadSwapScalar();
fMaxLife = s->ReadSwapScalar();
int i;
for( i = 0; i < fWaves.GetCount(); i++ )
fWaves[i].Kill();
fTempWaves.Reset();
}
void hsOscillator::Load(hsStream* s, hsScalar secs)
{
Read(s);
int i;
for( i = 0; i < fWaves.GetCount(); i++ )
fWaves[i].Load(s, secs);
fTempWaves.Reset();
}
void hsOscillator::Write(hsStream* s)
{
s->WriteSwap32(fWaves.GetCount());
fWorldAttenScale.Write(s);
fWorldCenterBounds.Write(s);
s->WriteSwapScalar(fMinPeriod);
s->WriteSwapScalar(fMaxPeriod);
s->WriteSwapScalar(fMinAmplitude);
s->WriteSwapScalar(fMaxAmplitude);
s->WriteSwapScalar(fMinRate);
s->WriteSwapScalar(fMaxRate);
s->WriteSwapScalar(fMinLife);
s->WriteSwapScalar(fMaxLife);
}
void hsOscillator::Save(hsStream* s, hsScalar secs)
{
Write(s);
int i;
for( i = 0; i < fWaves.GetCount(); i++ )
fWaves[i].Save(s, secs);
}
void hsOscillator::SetNumWaves(int n)
{
fWaves.SetCount(n);
int i;
for( i = 0; i < n; i++ )
fWaves[i].Kill();
}
void hsOscillator::Init(int32_t nParams, hsScalar* params)
{
// NumWaves = 1
// AttenScale = 2
// WorldCenterBounds = 6
// Period = 2
// Amp = 2
// Rate = 2
// Life = 2
hsAssert(17 == nParams, "Parameter input mismatch");
SetNumWaves(int(*params++));
fWorldAttenScale.fX = *params++;
fWorldAttenScale.fY = *params++;
fWorldAttenScale.fZ = 0;
hsPoint3 pt;
hsBounds3Ext bnd;
pt.fX = *params++;
pt.fY = *params++;
pt.fZ = *params++;
bnd.Reset(&pt);
pt.fX = *params++;
pt.fY = *params++;
pt.fZ = *params++;
bnd.Union(&pt);
SetWorldCenterBounds(bnd);
SetPeriodRange(params[0], params[1]);
params += 2;
SetAmplitudeRange(params[0], params[1]);
params += 2;
SetRateRange(params[0], params[1]);
params += 2;
SetLifeRange(params[0], params[1]);
fTempWaves.Reset();
}
#if 1
hsGTriMesh* hsOscillator::MakeWaveMesh(int nSpokes, const hsPoint3& center, hsScalar minRad, hsScalar maxRad, hsScalar uRange, hsScalar vRange, hsScalar attenStartFrac, hsBool32 stitch)
{
hsGTriMesh* triMesh = new hsGTriMesh;
hsTArray<hsScalar> radii;
hsScalar cRad = 0;
while( cRad < maxRad )
{
// OOPS - for the half circle, this should be PI*R/n, not 2PI. Don't fix until we've corrected the callers. Or we might want to leave it like
// this anyway, since we're looking obliquely at these faces anyway, and this error stretches the side that perspective compresses. May
// want to make the unstitched version wrong in the same way.
hsScalar tRad = 2.f * hsScalarPI * cRad / nSpokes;
if( tRad < minRad )
tRad = minRad;
cRad += tRad;
radii.Append(cRad);
}
int nShell = radii.GetCount();
int nTris = stitch
? 2 * nSpokes * (nShell-1) + nSpokes
: 2 * (nSpokes-1) * (nShell-1) + (nSpokes-1);
int nVerts = nSpokes * nShell + 1;
triMesh->AllocatePointers(nTris, nVerts, nVerts, nVerts);
triMesh->SetNumTriVertex(nVerts);
triMesh->SetNumPoints(nVerts);
triMesh->SetNumUvs(nVerts);
triMesh->SetHasColors(true);
*triMesh->GetPoint(0) = center;
triMesh->GetNormal(0)->Set(0,1.f,0);
triMesh->GetColor(0)->Set(0,0,0,1.f);
triMesh->GetUvs(0)->fX = triMesh->GetUvs(0)->fY = triMesh->GetUvs(0)->fZ = 0;
hsScalar iToRadians = stitch
? 2.f * hsScalarPI / nSpokes
: hsScalarPI / nSpokes;
hsScalar attenStart = maxRad * attenStartFrac;
hsScalar attenEnd = maxRad;
hsScalar attenScale = hsScalarInvert(attenEnd - attenStart);
int i, j;
for( i = 0; i < nSpokes; i++ )
{
hsScalar s = hsSine(i * iToRadians);
hsScalar c = hsCosine(i * iToRadians);
for( j = 0; j < nShell; j++ )
{
hsAssert(1 + i*nShell + j < nVerts, "Going out of range on verts");
hsGVertex3* vtx = triMesh->GetVertex(1 + i*nShell + j);
hsColorRGBA* col = triMesh->GetColor(1 + i*nShell + j);
hsGUv* uv = triMesh->GetUvs(1 + i*nShell + j);
hsScalar x = c * radii[j];
hsScalar y = s * radii[j];
hsScalar u = x / uRange;
hsScalar v = y / vRange;
vtx->fLocalPos.fX = center.fX + x;
vtx->fLocalPos.fY = center.fY + y;
vtx->fLocalPos.fZ = 0.f;
vtx->fNormal.Set(0,0,1.f);
uv->fX = u;
uv->fY = v;
uv->fZ = 0.f;
if( radii[j] > attenStart )
{
hsScalar a = (attenEnd - radii[j]) * attenScale;
if( a < 0 )
a = 0;
else if( a > 1.f )
a = 1.f;
col->Set(0,0,0,a);
}
else
col->Set(0,0,0,1.f);
}
}
int spokeEnd = stitch ? nSpokes : nSpokes-1;
int nextTri = 0;
for( i = 0; i < spokeEnd; i++ )
{
hsTriangle3* tri = triMesh->GetTriFromPool(nextTri);
tri->Zero();
tri->fOrigTri = tri;
triMesh->SetTriangle(nextTri++, tri);
tri->fVert[0] = triMesh->GetTriVertex(0);
tri->fVert[0]->fVtx = triMesh->GetVertex(0);
tri->fVert[0]->SetNumUvChannels(1);
tri->fVert[0]->fUvChan[0] = triMesh->GetUvs(0);
tri->fVert[0]->fVtxColor = triMesh->GetColor(0);
int iv0 = 1 + i * nShell;
int iv1 = i < nSpokes - 1 ? 1 + (i+1)*nShell : 1;
hsAssert((iv0 < nVerts)&&(iv1 < nVerts), "Out of range on triverts");
tri->fVert[1] = triMesh->GetTriVertex(iv0);
tri->fVert[1]->fVtx = triMesh->GetVertex(iv0);
tri->fVert[1]->SetNumUvChannels(1);
tri->fVert[1]->fUvChan[0] = triMesh->GetUvs(iv0);
tri->fVert[1]->fVtxColor = triMesh->GetColor(iv0);
tri->fVert[2] = triMesh->GetTriVertex(iv1);
tri->fVert[2]->fVtx = triMesh->GetVertex(iv1);
tri->fVert[2]->SetNumUvChannels(1);
tri->fVert[2]->fUvChan[0] = triMesh->GetUvs(iv1);
tri->fVert[2]->fVtxColor = triMesh->GetColor(iv1);
tri->fVert[0]->fFlags = hsGTriVertex::kHasPointers
| hsGTriVertex::kHasVertexUvs
| hsGTriVertex::kHasVertexColors;
tri->fVert[1]->fFlags = hsGTriVertex::kHasPointers
| hsGTriVertex::kHasVertexUvs
| hsGTriVertex::kHasVertexColors;
tri->fVert[2]->fFlags = hsGTriVertex::kHasPointers
| hsGTriVertex::kHasVertexUvs
| hsGTriVertex::kHasVertexColors;
tri->fFlags |= hsTriangle3::kHasVertexPosNorms
| hsTriangle3::kHasVertexUvs
| hsTriangle3::kHasVertexColors
| hsTriangle3::kHasPointers;
int iv2 = iv0 + 1;
int iv3 = iv1 + 1;
hsAssert((iv1 < nVerts)&&(iv2 < nVerts), "Out of range on triverts");
for( j = 0; j < nShell-1; j++ )
{
tri = triMesh->GetTriFromPool(nextTri);
tri->Zero();
tri->fOrigTri = tri;
triMesh->SetTriangle(nextTri++, tri);
tri->fVert[0] = triMesh->GetTriVertex(iv0);
tri->fVert[0]->fVtx = triMesh->GetVertex(iv0);
tri->fVert[0]->SetNumUvChannels(1);
tri->fVert[0]->fUvChan[0] = triMesh->GetUvs(iv0);
tri->fVert[0]->fVtxColor = triMesh->GetColor(iv0);
tri->fVert[1] = triMesh->GetTriVertex(iv2);
tri->fVert[1]->fVtx = triMesh->GetVertex(iv2);
tri->fVert[1]->SetNumUvChannels(1);
tri->fVert[1]->fUvChan[1] = triMesh->GetUvs(iv2);
tri->fVert[1]->fVtxColor = triMesh->GetColor(iv2);
tri->fVert[2] = triMesh->GetTriVertex(iv3);
tri->fVert[2]->fVtx = triMesh->GetVertex(iv3);
tri->fVert[2]->SetNumUvChannels(1);
tri->fVert[2]->fUvChan[0] = triMesh->GetUvs(iv3);
tri->fVert[2]->fVtxColor = triMesh->GetColor(iv3);
tri->fVert[0]->fFlags = hsGTriVertex::kHasPointers
| hsGTriVertex::kHasVertexUvs
| hsGTriVertex::kHasVertexColors;
tri->fVert[1]->fFlags = hsGTriVertex::kHasPointers
| hsGTriVertex::kHasVertexUvs
| hsGTriVertex::kHasVertexColors;
tri->fVert[2]->fFlags = hsGTriVertex::kHasPointers
| hsGTriVertex::kHasVertexUvs
| hsGTriVertex::kHasVertexColors;
tri->fFlags |= hsTriangle3::kHasVertexPosNorms
| hsTriangle3::kHasVertexUvs
| hsTriangle3::kHasVertexColors
| hsTriangle3::kHasPointers;
tri = triMesh->GetTriFromPool(nextTri);
tri->Zero();
tri->fOrigTri = tri;
triMesh->SetTriangle(nextTri++, tri);
tri->fVert[0] = triMesh->GetTriVertex(iv0);
tri->fVert[0]->fVtx = triMesh->GetVertex(iv0);
tri->fVert[0]->SetNumUvChannels(1);
tri->fVert[0]->fUvChan[0] = triMesh->GetUvs(iv0);
tri->fVert[0]->fVtxColor = triMesh->GetColor(iv0);
tri->fVert[1] = triMesh->GetTriVertex(iv3);
tri->fVert[1]->fVtx = triMesh->GetVertex(iv3);
tri->fVert[1]->SetNumUvChannels(1);
tri->fVert[1]->fUvChan[0] = triMesh->GetUvs(iv3);
tri->fVert[1]->fVtxColor = triMesh->GetColor(iv3);
tri->fVert[2] = triMesh->GetTriVertex(iv1);
tri->fVert[2]->fVtx = triMesh->GetVertex(iv1);
tri->fVert[2]->SetNumUvChannels(1);
tri->fVert[2]->fUvChan[0] = triMesh->GetUvs(iv1);
tri->fVert[2]->fVtxColor = triMesh->GetColor(iv1);
tri->fVert[0]->fFlags = hsGTriVertex::kHasPointers
| hsGTriVertex::kHasVertexUvs
| hsGTriVertex::kHasVertexColors;
tri->fVert[1]->fFlags = hsGTriVertex::kHasPointers
| hsGTriVertex::kHasVertexUvs
| hsGTriVertex::kHasVertexColors;
tri->fVert[2]->fFlags = hsGTriVertex::kHasPointers
| hsGTriVertex::kHasVertexUvs
| hsGTriVertex::kHasVertexColors;
tri->fFlags |= hsTriangle3::kHasVertexPosNorms
| hsTriangle3::kHasVertexUvs
| hsTriangle3::kHasVertexColors
| hsTriangle3::kHasPointers;
iv0++;
iv1++;
iv2++;
iv3++;
}
}
hsAssert(nextTri <= nTris, "Out of range on tris");
triMesh->StoreOrigPoints();
return triMesh;
}
#endif

View File

@ -1,180 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef hsOscillator_inc
#define hsOscillator_inc
#include "hsPerterber.h"
#include "hsTemplates.h"
#include "hsGeometry3.h"
#include "../plIntersect/hsBounds.h"
class hsStream;
class plPipeline;
class hsWave
{
protected:
hsPoint3 fWorldCenter;
hsPoint3 fLocalCenter;
hsScalar fWorldFrequency; // 1.0 / Period
hsScalar fLocalFrequency;
hsScalar fWorldAmplitude;
hsScalar fLocalAmplitude;
hsScalar fPhase;
hsScalar fRate; // how long a crest takes to reach next crest
hsScalar fStartSecs;
hsScalar fSecsToLive;
hsScalar fInnerRadius;
hsScalar fOuterRadius;
hsScalar fAttenuateOutScale;
hsScalar AgeScale(hsScalar secs) const;
public:
void Accumulate(const hsPoint3& pos, const hsVector3& localZ, hsVector3& accum, hsVector3& accumNorm) const;
hsScalar ScaledAmplitude(hsScalar secs) const;
void Init(hsScalar secs, hsPoint3& center, hsScalar per, hsScalar amp, hsScalar rate, hsScalar life, hsBool32 attenOut=false);
void Update(hsScalar secs, const hsMatrix44& l2w, const hsMatrix44& w2l);
hsBool32 IsSpent(hsScalar secs) const;
void Kill() { fStartSecs = fSecsToLive = 0; }
void AttenuateOut(hsBool32 on) { fAttenuateOutScale = (on ? 1.f : 0); }
hsBool32 GetAttenuateOut() { return fAttenuateOutScale > 0; }
void Save(hsStream* s, hsScalar secs);
void Load(hsStream* s, hsScalar secs);
};
class hsOscillator : public hsPerterber
{
protected:
hsTArray<hsWave> fWaves;
hsTArray<hsWave> fTempWaves;
hsMatrix44 fLocalToWorld;
hsMatrix44 fWorldToLocal;
hsPoint3 fWorldCenter;
hsPoint3 fLocalCenter;
hsVector3 fWorldAttenScale;
hsVector3 fLocalAttenScale;
hsBounds3Ext fWorldCenterBounds;
hsScalar fMinPeriod;
hsScalar fMaxPeriod;
hsScalar fMinAmplitude;
hsScalar fMaxAmplitude;
hsScalar fMinRate;
hsScalar fMaxRate;
hsScalar fMinLife;
hsScalar fMaxLife;
hsVector3 fLocalX;
hsVector3 fLocalY;
hsVector3 fLocalZ;
hsScalar IAttenuate(const hsPoint3& in) const;
void ISpawnWave(hsScalar secs, int i);
virtual void IUpdate(hsScalar secs, plPipeline* pipe, const hsMatrix44& l2w, const hsMatrix44& w2l);
virtual void IPerterb(const hsPoint3& in, hsGVertex3& out) const;
public:
hsOscillator();
virtual ~hsOscillator();
virtual void AdjustWorldBounds(const hsMatrix44& l2w, const hsMatrix44& w2l, hsBounds3Ext& bnd) const;
virtual uint32_t GetType() const { return kTypeOscillator; }
// Don't call these, use base class LabelAndWrite() and CreateAndRead()
virtual void Read(hsStream* s);
virtual void Write(hsStream* s);
virtual void Load(hsStream* s, hsScalar secs);
virtual void Save(hsStream* s, hsScalar secs);
void SetPeriodRange(hsScalar lo, hsScalar hi) { fMinPeriod = lo; fMaxPeriod = hi; }
void SetAmplitudeRange(hsScalar lo, hsScalar hi) { fMinAmplitude = lo; fMaxAmplitude = hi; }
void SetRateRange(hsScalar lo, hsScalar hi) { fMinRate = lo; fMaxRate = hi; }
void SetLifeRange(hsScalar lo, hsScalar hi) { fMinLife = lo; fMaxLife = hi; }
hsScalar GetMinPeriod() const { return fMinPeriod; }
hsScalar GetMaxPeriod() const { return fMaxPeriod; }
hsScalar GetMinAmplitude() const { return fMinAmplitude; }
hsScalar GetMaxAmplitude() const { return fMaxAmplitude; }
hsScalar GetMinRate() const { return fMinRate; }
hsScalar GetMaxRate() const { return fMaxRate; }
hsScalar GetMinLife() const { return fMinLife; }
hsScalar GetMaxLife() const { return fMaxLife; }
void SetWorldAttenScale(const hsVector3& s) { fWorldAttenScale = s; }
void SetWorldCenterBounds(const hsBounds3Ext& bnd) { fWorldCenterBounds = bnd; }
const hsVector3& GetWorldAttenScale() const { return fWorldAttenScale; }
const hsBounds3Ext& GetWorldCenterBounds() const { return fWorldCenterBounds; }
void SetNumWaves(int n);
uint32_t GetNumWaves() const { return fWaves.GetCount(); }
hsWave& GetWeakestWave(hsScalar secs);
hsWave& GetTempWave(hsScalar secs);
virtual void Init(int32_t nParams, hsScalar* params);
static hsGTriMesh* MakeWaveMesh(int nSpokes, const hsPoint3& center, hsScalar minRad, hsScalar maxRad, hsScalar uRange, hsScalar vRange, hsScalar attenStartFrac, hsBool32 stitch);
};
#endif // hsOscillator_inc

View File

@ -1,350 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsTypes.h"
#include "hsStream.h"
#include "hsPerterber.h"
#include "hsOscillator.h"
#include "hsGMesh.h"
#if 0 // GET_RID_OF_SHAPE_LAYER_DEFER
#include "hsGShape3.h"
#include "hsGShape3MegaMesh.h"
#endif// GET_RID_OF_SHAPE_LAYER_DEFER
#include "../plResMgr/plKey.h"
#include "../plSurface/hsGMaterial.h"
#include "hsTimer.h"
#include "../plPipeline/plPipeline.h"
hsBool32 hsPerterber::fDisabled = false;
hsPerterber::hsPerterber()
{
}
hsPerterber::~hsPerterber()
{
}
void hsPerterber::IUpdate(hsScalar secs, plPipeline* pipe, const hsMatrix44& l2w, const hsMatrix44& w2l)
{
}
void hsPerterber::TimeStampAndSave(hsStream* s)
{
hsScalar secs = hsTimer::GetSeconds();
hsKeyedObject::Save(s, nil);
Save(s, secs);
}
void hsPerterber::TimeStampAndLoad(hsStream* s)
{
hsScalar secs = hsTimer::GetSeconds();
hsKeyedObject::Load(s, nil);
Load(s, secs);
}
void hsPerterber::LabelAndWrite(hsStream* s)
{
s->WriteSwap32(GetType());
Write(s);
}
hsPerterber* hsPerterber::CreateAndRead(hsStream* s)
{
hsPerterber* retVal = nil;
uint32_t t = s->ReadSwap32();
switch( t )
{
case kTypeOscillator:
retVal = new hsOscillator;
break;
default:
hsAssert(false, "Unknown perterber type");
return nil;
}
retVal->Read(s);
return retVal;
}
hsGMesh* hsPerterber::IGetMesh(hsGShape3* shape)
{
hsGMesh* mesh = nil;
#if 0 // GET_RID_OF_SHAPE_LAYER_DEFER
if( shape->GetShapeType() == hsGShape3::kTypeTriMesh )
{
hsGShape3TriMesh* shp = (hsGShape3TriMesh*)shape;
mesh = shp->GetMesh();
#if 0 // move to export
if( mesh->GetKey() && strstr(mesh->GetKey()->GetName(), "create") )
{
hsTArray<hsGMaterial*> matList;
shp->AppendMaterials(matList);
hsGTriMesh* newMesh = hsOscillator::MakeWaveMesh(40, hsPoint3(0,0,0), 4.f, 75.f, 1200.f, 1200.f, 0.75f, false);
newMesh->SetMaterial(matList[0]);
hsRefCnt_SafeUnRef(matList[0]);
shp->SetMesh(newMesh);
hsRefCnt_SafeUnRef(newMesh);
mesh = newMesh;
}
else if( mesh->GetKey() && strstr(mesh->GetKey()->GetName(), "destroy") )
{
hsTArray<hsGMaterial*> matList;
shp->AppendMaterials(matList);
hsGTriMesh* newMesh = hsOscillator::MakeWaveMesh(50, hsPoint3(0,0,0), 1.5f, 30.f, 600.f, 600.f, 0.6f, true);
newMesh->SetMaterial(matList[0]);
hsRefCnt_SafeUnRef(matList[0]);
shp->SetMesh(newMesh);
hsRefCnt_SafeUnRef(newMesh);
mesh = newMesh;
}
else
#endif // move to export
{
hsGTriMesh* triMesh = (hsGTriMesh*)shp->GetMesh();
if( triMesh->GetTriangle(0)->fFlags & hsTriangle3::kHasFacePlane )
triMesh->TrashPlanes();
mesh = triMesh;
}
}
else if( shape->GetShapeType() == hsGShape3::kTypeMegaMesh )
{
hsGShape3MegaMesh* mega = (hsGShape3MegaMesh*)shape;
hsGMegaMesh* megaMesh = (hsGMegaMesh*)mega->GetMegaMesh();
hsGTriMesh* triMesh = (hsGTriMesh*)megaMesh->GetMesh(0);
if( triMesh->GetTriangle(0)->fFlags & hsTriangle3::kHasFacePlane )
{
int iMesh;
for( iMesh = 0; iMesh < megaMesh->GetMeshCount(); iMesh++ )
{
triMesh = (hsGTriMesh*)megaMesh->GetMesh(iMesh);
triMesh->TrashPlanes();
}
}
mesh = mega->GetMegaMesh();
}
#endif // GET_RID_OF_SHAPE_LAYER_DEFER
return mesh;
}
void hsPerterber::Perterb(hsScalar secs, plPipeline* pipe, const hsMatrix44& l2w, const hsMatrix44& w2l, hsGShape3* shape)
{
if( GetDisabled() )
return;
hsGMesh* mesh = IGetMesh(shape);
IUpdate(secs, pipe, l2w, w2l);
if( !mesh->HasOrigPoints() )
mesh->StoreOrigPoints();
int i;
for( i = 0; i < mesh->GetNumPoints(); i++ )
{
IPerterb(*mesh->GetOrigPoint(i), *mesh->GetVertex(i));
}
}
const int kPertCount = 6;
const int kMaxPertParams = 32;
struct hsPertDesc
{
char fName[256];
uint32_t fType;
uint32_t fNumParams;
hsScalar fParams[kMaxPertParams];
};
// NumWaves = 1
// AttenScale = 2
// WorldCenterBounds = 6
// Period = 2
// Amp = 2
// Rate = 2
// Life = 2
//
hsPertDesc sPertTable[kPertCount] =
{
{
"mystocean",
hsPerterber::kTypeOscillator,
17,
{
5.f,
1.f/100.f, 1.f/100.f,
-100.f, 100.f, 0, 100.f, 150.f, 0,
2.f, 5.f,
0.5, 0.75f,
0.68f, 0.68f,
5.f, 10.f
}
},
{
"stoneocean",
hsPerterber::kTypeOscillator,
17,
{
5.f,
1.f/100.f, 1.f/100.f,
-100.f, 100.f, 0, 100.f, 150.f, 0,
2.f, 5.f,
0.5, 0.75f,
0.68f, 0.68f,
5.f, 10.f
}
},
{
"seleniticocean",
hsPerterber::kTypeOscillator,
17,
{
5.f,
1.f/100.f, 1.f/100.f,
-100.f, 100.f, 0, 100.f, 150.f, 0,
2.f, 5.f,
0.25, 0.45f,
0.6f, 0.6f,
5.f, 10.f
}
},
{
"channelocean",
hsPerterber::kTypeOscillator,
17,
{
5.f,
1.f/30.f, 1.f/30.f,
-100.f, -100.f, 0, 100.f, 100.f, 0,
0.25f, 0.5f,
0.1, 0.2f,
0.4f, 0.8f,
5.f, 10.f
}
},
{
"mechocean",
hsPerterber::kTypeOscillator,
17,
{
5.f,
1.f/100.f, 1.f/100.f,
-100.f, 100.f, 0, 100.f, 150.f, 0,
2.f, 5.f,
0.5, 0.4f,
0.68f, 0.68f,
5.f, 10.f
}
},
{
"rimeocean",
hsPerterber::kTypeOscillator,
17,
{
5.f,
1.f/100.f, 1.f/100.f,
-100.f, 100.f, 0, 100.f, 150.f, 0,
2.f, 5.f,
0.5, 0.75,
0.68f, 0.68f,
5.f, 10.f
}
}
};
#if 0 // Used Registry...need to change paulg
void hsPerterber::InitSystem(hsRegistry* reg)
{
if( GetDisabled() )
return;
int i;
for( i = 0; i < kPertCount; i++ )
{
switch( sPertTable[i].fType )
{
case kTypeOscillator:
{
hsOscillator* oscar = new hsOscillator;
oscar->Init(sPertTable[i].fNumParams, sPertTable[i].fParams);
#ifdef PAULFIX
oscar->Register(reg, sPertTable[i].fName, 0, true);
#endif
}
break;
default:
hsAssert(false, "Unknown perterber type");
break;
}
}
}
void hsPerterber::Shutdown(hsRegistry* reg)
{
#ifdef PAULFIX
int i;
for( i = 0; i < reg->GetNumKeys(); i++ )
{
hsPerterber* pert = (hsPerterber*)(reg->GetKey(i)->GetObjectPtr());
delete pert;
}
#endif
}
#endif

View File

@ -1,107 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef hsPerterber_inc
#define hsPerterber_inc
#include "../plResMgr/hsKeyedObject.h"
#include "hsGeometry3.h"
class hsStream;
class hsGShape3;
class hsBounds3Ext;
class hsGMesh;
class plPipeline;
struct hsMatrix44;
struct hsGVertex3;
class hsPerterber : public hsKeyedObject
{
public:
enum {
kTypeUndefined = 0x0,
kTypeOscillator = 0x1
};
protected:
static hsBool32 fDisabled;
virtual void IUpdate(hsScalar secs, plPipeline* pipe, const hsMatrix44& l2w, const hsMatrix44& w2l);
virtual void IPerterb(const hsPoint3& in, hsGVertex3& out) const = 0;
hsGMesh* IGetMesh(hsGShape3* shape);
public:
hsPerterber();
virtual ~hsPerterber();
static void SetDisabled(hsBool32 on) { fDisabled = on; }
static void ToggleDisabled() { fDisabled = !fDisabled; }
static hsBool32 GetDisabled() { return fDisabled; }
virtual void Perterb(hsScalar secs, plPipeline* pipe, const hsMatrix44& l2w, const hsMatrix44& w2l, hsGShape3* shape);
virtual void AdjustWorldBounds(const hsMatrix44& l2w, const hsMatrix44& w2l, hsBounds3Ext& bnd) const = 0;
virtual uint32_t GetType() const = 0;
virtual void Write(hsStream* s) = 0;
virtual void Read(hsStream* s) = 0;
virtual void Save(hsStream* s, hsScalar secs) = 0;
virtual void Load(hsStream* s, hsScalar secs) = 0;
void TimeStampAndSave(hsStream* s);
void TimeStampAndLoad(hsStream* s);
void LabelAndWrite(hsStream* s);
static hsPerterber* CreateAndRead(hsStream* s);
virtual void Init(int32_t nParams, hsScalar* params) = 0;
#if 0 // Used Registry...need to change paulg
static void InitSystem(plResMgr* reg);
static void Shutdown(plResMgr* reg);
#endif
};
#endif hsPerterber_inc

View File

@ -1,70 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef plGeometryCreatable_inc
#define plGeometryCreatable_inc
#include "../pnFactory/plCreator.h"
/* Taken out 6.12.2001 mcn - You can remove this file entirely if you wish, I just left
it in in case we wanted to use it in the future...
#include "hsGVertexPool.h"
REGISTER_CREATABLE( hsGVertexPool );
#include "hsGMesh.h"
REGISTER_NONCREATABLE( hsGMesh );
#include "hsGTriMesh.h"
REGISTER_CREATABLE( hsGTriMesh );
#include "hsGMegaMesh.h"
REGISTER_CREATABLE( hsGMegaMesh );
*/
#endif plGeometryCreatable_inc

View File

@ -9,8 +9,6 @@ set(plNetGameLib_PRIVATE
Private/plNglAuth.cpp
Private/plNglCore.h
Private/plNglCore.cpp
Private/plNglCsr.h
Private/plNglCsr.cpp
Private/plNglFile.h
Private/plNglFile.cpp
Private/plNglGame.h

View File

@ -118,19 +118,6 @@ bool FileQueryConnected ();
unsigned FileGetConnId ();
/*****************************************************************************
*
* Csr
*
***/
void CsrInitialize ();
void CsrDestroy (bool wait);
bool CsrQueryConnected ();
unsigned CsrGetConnId ();
/*****************************************************************************
*
* GateKeeper
@ -208,11 +195,6 @@ enum ETransType {
kDownloadRequestTrans,
kFileRcvdFileDownloadChunkTrans,
//========================================================================
// NglCsr.cpp transactions
kCsrConnectedNotifyTrans,
kCsrLoginTrans,
//========================================================================
// NglCore.cpp transactions
kReportNetErrorTrans,
@ -280,10 +262,6 @@ static const char * s_transTypes[] = {
"ManifestRequestTrans",
"DownloadRequestTrans",
"FileRcvdFileDownloadChunkTrans",
// NglCsr.cpp
"CsrConnectedNotifyTrans",
"CsrLoginTrans",
// NglCore.cpp
"ReportNetErrorTrans",
@ -300,7 +278,6 @@ static long s_perfTransCount[kNumTransTypes];
namespace Auth { struct CliAuConn; }
namespace Game { struct CliGmConn; }
namespace Csr { struct CliCsConn; }
namespace File { struct CliFileConn; }
namespace GateKeeper { struct CliGkConn; }
@ -364,17 +341,6 @@ struct NetFileTrans : NetTrans {
void ReleaseConn ();
};
struct NetCsrTrans : NetTrans {
Csr::CliCsConn * m_conn;
NetCsrTrans (ETransType transType);
~NetCsrTrans ();
bool AcquireConn ();
void ReleaseConn ();
};
struct NetGateKeeperTrans : NetTrans {
GateKeeper::CliGkConn * m_conn;

View File

@ -58,5 +58,4 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plNglAuth.h"
#include "plNglGame.h"
#include "plNglFile.h"
#include "plNglCsr.h"
#include "plNglGateKeeper.h"

View File

@ -148,7 +148,6 @@ void NetClientInitialize () {
AuthInitialize();
GameInitialize();
FileInitialize();
CsrInitialize();
GateKeeperInitialize();
}
}
@ -165,14 +164,12 @@ void NetClientDestroy (bool wait) {
s_errorProc = nil;
GateKeeperDestroy(false);
CsrDestroy(false);
FileDestroy(false);
GameDestroy(false);
AuthDestroy(false);
NetTransDestroy(false);
if (wait) {
GateKeeperDestroy(true);
CsrDestroy(true);
FileDestroy(true);
GameDestroy(true);
AuthDestroy(true);

View File

@ -1,900 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp
*
***/
#include "../Pch.h"
#pragma hdrstop
#include "pnEncryption/plChallengeHash.h"
namespace Ngl { namespace Csr {
/*****************************************************************************
*
* Internal types
*
***/
struct ConnectParam {
FNetCliCsrConnectedCallback callback;
void * param;
};
//============================================================================
// Connection record
//============================================================================
struct CliCsConn : AtomicRef {
LINK(CliCsConn) link;
CCritSect critsect;
AsyncSocket sock;
AsyncCancelId cancelId;
NetCli * cli;
plNetAddress addr;
unsigned seq;
bool abandoned;
unsigned serverChallenge;
unsigned latestBuildId;
ConnectParam * connectParam;
// ping
AsyncTimer * pingTimer;
unsigned pingSendTimeMs;
unsigned lastHeardTimeMs;
CliCsConn ();
~CliCsConn ();
void AutoPing ();
void StopAutoPing ();
void TimerPing ();
void Send (const uintptr_t fields[], unsigned count);
};
//============================================================================
// Transaction objects
//============================================================================
struct ConnectedNotifyTrans : NetNotifyTrans {
ConnectParam * m_connectParam;
unsigned m_latestBuildId;
ConnectedNotifyTrans (ConnectParam * cp, unsigned lbi)
: NetNotifyTrans(kCsrConnectedNotifyTrans)
, m_connectParam(cp)
, m_latestBuildId(lbi)
{ }
~ConnectedNotifyTrans () {
delete m_connectParam;
}
void Post ();
};
struct LoginRequestTrans : NetCsrTrans {
wchar_t m_csrName[kMaxAccountNameLength];
ShaDigest m_namePassHash;
FNetCliCsrLoginCallback m_callback;
void * m_param;
Uuid m_csrId;
unsigned m_csrFlags;
LoginRequestTrans (
const wchar_t csrName[],
const ShaDigest & namePassHash,
FNetCliCsrLoginCallback callback,
void * param
);
bool Send ();
void Post ();
bool Recv (
const uint8_t msg[],
unsigned bytes
);
};
/*****************************************************************************
*
* Internal data
*
***/
enum {
kPerfConnCount,
kPingDisabled,
kNumPerf
};
static bool s_running;
static CCritSect s_critsect;
static LISTDECL(CliCsConn, link) s_conns;
static CliCsConn * s_active;
static long s_perf[kNumPerf];
/*****************************************************************************
*
* Internal functions
*
***/
//===========================================================================
static unsigned GetNonZeroTimeMs () {
if (unsigned ms = TimeGetMs())
return ms;
return 1;
}
//============================================================================
static CliCsConn * GetConnIncRef_CS (const char tag[]) {
if (CliCsConn * conn = s_active)
if (conn->cli) {
conn->IncRef(tag);
return conn;
}
return nil;
}
//============================================================================
static CliCsConn * GetConnIncRef (const char tag[]) {
CliCsConn * conn;
s_critsect.Enter();
{
conn = GetConnIncRef_CS(tag);
}
s_critsect.Leave();
return conn;
}
//============================================================================
static void UnlinkAndAbandonConn_CS (CliCsConn * conn) {
s_conns.Unlink(conn);
conn->abandoned = true;
if (conn->cancelId) {
AsyncSocketConnectCancel(nil, conn->cancelId);
conn->cancelId = 0;
}
else if (conn->sock) {
AsyncSocketDisconnect(conn->sock, true);
}
else {
conn->DecRef("Lifetime");
}
}
//============================================================================
static void SendRegisterRequest (CliCsConn * conn) {
const uintptr_t msg[] = {
kCli2Csr_RegisterRequest,
0
};
conn->Send(msg, arrsize(msg));
}
//============================================================================
static bool ConnEncrypt (ENetError error, void * param) {
CliCsConn * conn = (CliCsConn *) param;
if (IS_NET_SUCCESS(error)) {
s_critsect.Enter();
{
s_active = conn;
conn->AutoPing();
conn->IncRef();
}
s_critsect.Leave();
SendRegisterRequest(conn);
conn->DecRef();
}
return IS_NET_SUCCESS(error);
}
//============================================================================
static void NotifyConnSocketConnect (CliCsConn * conn) {
conn->cli = NetCliConnectAccept(
conn->sock,
kNetProtocolCli2Csr,
false,
ConnEncrypt,
0,
nil,
conn
);
}
//============================================================================
static void NotifyConnSocketConnectFailed (CliCsConn * conn) {
bool notify;
s_critsect.Enter();
{
conn->cancelId = 0;
s_conns.Unlink(conn);
notify
= s_running
&& !conn->abandoned
&& (!s_active || conn == s_active);
if (conn == s_active)
s_active = nil;
}
s_critsect.Leave();
NetTransCancelByConnId(conn->seq, kNetErrTimeout);
conn->DecRef("Connecting");
conn->DecRef("Lifetime");
if (notify)
ReportNetError(kNetProtocolCli2Csr, kNetErrConnectFailed);
}
//============================================================================
static void NotifyConnSocketDisconnect (CliCsConn * conn) {
conn->StopAutoPing();
bool notify;
s_critsect.Enter();
{
s_conns.Unlink(conn);
notify
= s_running
&& !conn->abandoned
&& (!s_active || conn == s_active);
if (conn == s_active)
s_active = nil;
}
s_critsect.Leave();
// Cancel all transactions in process on this connection.
NetTransCancelByConnId(conn->seq, kNetErrTimeout);
conn->DecRef("Connected");
conn->DecRef("Lifetime");
if (notify)
ReportNetError(kNetProtocolCli2Csr, kNetErrDisconnected);
}
//============================================================================
static bool NotifyConnSocketRead (CliCsConn * conn, AsyncNotifySocketRead * read) {
conn->lastHeardTimeMs = GetNonZeroTimeMs();
bool result = NetCliDispatch(conn->cli, read->buffer, read->bytes, conn);
read->bytesProcessed += read->bytes;
return result;
}
//============================================================================
static bool SocketNotifyCallback (
AsyncSocket sock,
EAsyncNotifySocket code,
AsyncNotifySocket * notify,
void ** userState
) {
bool result = true;
CliCsConn * conn;
switch (code) {
case kNotifySocketConnectSuccess: {
conn = (CliCsConn *) notify->param;
*userState = conn;
conn->TransferRef("Connecting", "Connected");
bool abandoned = true;
if (abandoned)
AsyncSocketDisconnect(sock, true);
else
NotifyConnSocketConnect(conn);
}
break;
case kNotifySocketConnectFailed:
conn = (CliCsConn *) notify->param;
NotifyConnSocketConnectFailed(conn);
break;
case kNotifySocketDisconnect:
conn = (CliCsConn *) *userState;
NotifyConnSocketDisconnect(conn);
break;
case kNotifySocketRead:
conn = (CliCsConn *) *userState;
result = NotifyConnSocketRead(conn, (AsyncNotifySocketRead *) notify);
break;
}
return result;
}
//============================================================================
static void Connect (
const plNetAddress& addr,
ConnectParam * cp
) {
CliCsConn * conn = NEWZERO(CliCsConn);
conn->addr = addr;
conn->seq = ConnNextSequence();
conn->lastHeardTimeMs = GetNonZeroTimeMs();
conn->connectParam = cp;
conn->IncRef("Lifetime");
conn->IncRef("Connecting");
s_critsect.Enter();
{
while (CliCsConn * conn = s_conns.Head())
UnlinkAndAbandonConn_CS(conn);
s_conns.Link(conn);
}
s_critsect.Leave();
Cli2Csr_Connect connect;
connect.hdr.connType = kConnTypeCliToCsr;
connect.hdr.hdrBytes = sizeof(connect.hdr);
connect.hdr.buildId = BuildId();
connect.hdr.buildType = BUILD_TYPE_LIVE;
connect.hdr.branchId = BranchId();
connect.hdr.productId = ProductId();
connect.data.dataBytes = sizeof(connect.data);
AsyncSocketConnect(
&conn->cancelId,
addr,
SocketNotifyCallback,
conn,
&connect,
sizeof(connect),
0,
0
);
}
//============================================================================
static void AsyncLookupCallback (
void * param,
const char name[],
unsigned addrCount,
const plNetAddress addrs[]
) {
if (!addrCount) {
ReportNetError(kNetProtocolCli2Auth, kNetErrNameLookupFailed);
return;
}
// Only connect to one server
addrCount = MIN(addrCount, 1);
for (unsigned i = 0; i < addrCount; ++i) {
Connect(addrs[i], (ConnectParam *)param);
}
}
/*****************************************************************************
*
* Message handlers
*
***/
//============================================================================
static bool Recv_PingReply (
const uint8_t msg[],
unsigned bytes,
void *
) {
const Csr2Cli_PingReply & reply = *(const Csr2Cli_PingReply *)msg;
NetTransRecv(reply.transId, msg, bytes);
return true;
}
//============================================================================
static bool Recv_RegisterReply (
const uint8_t msg[],
unsigned ,
void * param
) {
CliCsConn * conn = (CliCsConn *)param;
const Csr2Cli_RegisterReply & reply = *(const Csr2Cli_RegisterReply *)msg;
conn->serverChallenge = reply.serverChallenge;
conn->latestBuildId = reply.csrBuildId;
ConnectedNotifyTrans * trans = new ConnectedNotifyTrans(
conn->connectParam,
conn->latestBuildId
);
NetTransSend(trans);
conn->connectParam = nil;
return true;
}
//============================================================================
static bool Recv_LoginReply (
const uint8_t msg[],
unsigned bytes,
void *
) {
const Csr2Cli_LoginReply & reply = *(const Csr2Cli_LoginReply *)msg;
NetTransRecv(reply.transId, msg, bytes);
return true;
}
/*****************************************************************************
*
* Protocol
*
***/
#define MSG(s) kNetMsg_Cli2Csr_##s
static NetMsgInitSend s_send[] = {
{ MSG(PingRequest) },
{ MSG(RegisterRequest) },
{ MSG(LoginRequest) },
};
#undef MSG
#define MSG(s) kNetMsg_Csr2Cli_##s, Recv_##s
static NetMsgInitRecv s_recv[] = {
{ MSG(PingReply) },
{ MSG(RegisterReply) },
{ MSG(LoginReply) },
};
#undef MSG
/*****************************************************************************
*
* CliCsConn
*
***/
//===========================================================================
static unsigned CliCsConnTimerDestroyed (void * param) {
CliCsConn * conn = (CliCsConn *) param;
conn->DecRef("PingTimer");
return kAsyncTimeInfinite;
}
//===========================================================================
static unsigned CliCsConnPingTimerProc (void * param) {
((CliCsConn *) param)->TimerPing();
return kPingIntervalMs;
}
//============================================================================
CliCsConn::CliCsConn () {
AtomicAdd(&s_perf[kPerfConnCount], 1);
}
//============================================================================
CliCsConn::~CliCsConn () {
// Delete 'cli' after all refs have been removed
if (cli)
NetCliDelete(cli, true);
delete connectParam;
AtomicAdd(&s_perf[kPerfConnCount], -1);
}
//============================================================================
void CliCsConn::AutoPing () {
ASSERT(!pingTimer);
IncRef("PingTimer");
critsect.Enter();
{
AsyncTimerCreate(
&pingTimer,
CliCsConnPingTimerProc,
sock ? 0 : kAsyncTimeInfinite,
this
);
}
critsect.Leave();
}
//============================================================================
void CliCsConn::StopAutoPing () {
critsect.Enter();
{
if (AsyncTimer * timer = pingTimer) {
pingTimer = nil;
AsyncTimerDeleteCallback(timer, CliCsConnTimerDestroyed);
}
}
critsect.Leave();
}
//============================================================================
void CliCsConn::TimerPing () {
// Send a ping request
pingSendTimeMs = GetNonZeroTimeMs();
const uintptr_t msg[] = {
kCli2Auth_PingRequest,
0, // not a transaction
pingSendTimeMs,
0, // no payload
nil
};
Send(msg, arrsize(msg));
}
//============================================================================
void CliCsConn::Send (const uintptr_t fields[], unsigned count) {
critsect.Enter();
{
NetCliSend(cli, fields, count);
NetCliFlush(cli);
}
critsect.Leave();
}
/*****************************************************************************
*
* ConnectedNotifyTrans
*
***/
//============================================================================
void ConnectedNotifyTrans::Post () {
if (m_connectParam && m_connectParam->callback)
m_connectParam->callback(m_connectParam->param, m_latestBuildId);
}
/*****************************************************************************
*
* LoginRequestTrans
*
***/
//============================================================================
LoginRequestTrans::LoginRequestTrans (
const wchar_t csrName[],
const ShaDigest & namePassHash,
FNetCliCsrLoginCallback callback,
void * param
) : NetCsrTrans(kCsrLoginTrans)
, m_callback(callback)
, m_param(param)
{
ASSERT(callback);
memcpy(m_namePassHash, namePassHash, sizeof(ShaDigest));
StrCopy(m_csrName, csrName, arrsize(m_csrName));
}
//============================================================================
bool LoginRequestTrans::Send () {
if (!AcquireConn())
return false;
ShaDigest challengeHash;
uint32_t clientChallenge = 0;
CryptCreateRandomSeed(
sizeof(clientChallenge),
(uint8_t *) &clientChallenge
);
CryptHashPasswordChallenge(
clientChallenge,
s_active->serverChallenge,
m_namePassHash,
challengeHash
);
const uintptr_t msg[] = {
kCli2Csr_LoginRequest,
m_transId,
clientChallenge,
(uintptr_t) m_csrName,
(uintptr_t) &challengeHash
};
m_conn->Send(msg, arrsize(msg));
return true;
}
//============================================================================
void LoginRequestTrans::Post () {
m_callback(
m_result,
m_param,
m_csrId,
m_csrFlags
);
}
//============================================================================
bool LoginRequestTrans::Recv (
const uint8_t msg[],
unsigned bytes
) {
const Csr2Cli_LoginReply & reply = *(const Csr2Cli_LoginReply *) msg;
m_result = reply.result;
m_csrId = reply.csrId;
m_csrFlags = reply.csrFlags;
m_state = kTransStateComplete;
return true;
}
} using namespace Csr;
/*****************************************************************************
*
* NetCsrTrans
*
***/
//============================================================================
NetCsrTrans::NetCsrTrans (ETransType transType)
: NetTrans(kNetProtocolCli2Csr, transType)
, m_conn(nil)
{
}
//============================================================================
NetCsrTrans::~NetCsrTrans () {
ReleaseConn();
}
//============================================================================
bool NetCsrTrans::AcquireConn () {
if (!m_conn)
m_conn = GetConnIncRef("AcquireConn");
return m_conn != nil;
}
//============================================================================
void NetCsrTrans::ReleaseConn () {
if (m_conn) {
m_conn->DecRef("AcquireConn");
m_conn = nil;
}
}
/*****************************************************************************
*
* Module functions
*
***/
//============================================================================
void CsrInitialize () {
s_running = true;
NetMsgProtocolRegister(
kNetProtocolCli2Csr,
false,
s_send, arrsize(s_send),
s_recv, arrsize(s_recv),
kCsrDhGValue,
plBigNum(sizeof(kCsrDhXData), kCsrDhXData),
plBigNum(sizeof(kCsrDhNData), kCsrDhNData)
);
}
//============================================================================
void CsrDestroy (bool wait) {
s_running = false;
NetTransCancelByProtocol(
kNetProtocolCli2Csr,
kNetErrRemoteShutdown
);
NetMsgProtocolDestroy(
kNetProtocolCli2Csr,
false
);
s_critsect.Enter();
{
while (CliCsConn * conn = s_conns.Head())
UnlinkAndAbandonConn_CS(conn);
s_active = nil;
}
s_critsect.Leave();
if (!wait)
return;
while (s_perf[kPerfConnCount]) {
NetTransUpdate();
AsyncSleep(10);
}
}
//============================================================================
bool CsrQueryConnected () {
bool result;
s_critsect.Enter();
{
if (nil != (result = s_active))
result &= (nil != s_active->cli);
}
s_critsect.Leave();
return result;
}
//============================================================================
unsigned CsrGetConnId () {
unsigned connId;
s_critsect.Enter();
{
connId = (s_active) ? s_active->seq : 0;
}
s_critsect.Leave();
return connId;
}
} using namespace Ngl;
/*****************************************************************************
*
* Exports
*
***/
//============================================================================
void NetCliCsrStartConnect (
const char* addrList[],
uint32_t addrCount,
FNetCliCsrConnectedCallback callback,
void * param
) {
// Only connect to one server
addrCount = min(addrCount, 1);
for (unsigned i = 0; i < addrCount; ++i) {
// Do we need to lookup the address?
const char* name = addrList[i];
while (unsigned ch = *name) {
++name;
if (!(isdigit(ch) || ch == L'.' || ch == L':')) {
ConnectParam * cp = new ConnectParam;
cp->callback = callback;
cp->param = param;
AsyncCancelId cancelId;
AsyncAddressLookupName(
&cancelId,
AsyncLookupCallback,
addrList[i],
kNetDefaultClientPort,
cp
);
break;
}
}
if (!name[0]) {
plNetAddress addr(addrList[i], kNetDefaultClientPort);
ConnectParam * cp = new ConnectParam;
cp->callback = callback;
cp->param = param;
Connect(addr, cp);
}
}
}
//============================================================================
void NetCliCsrDisconnect () {
s_critsect.Enter();
{
while (CliCsConn * conn = s_conns.Head())
UnlinkAndAbandonConn_CS(conn);
s_active = nil;
}
s_critsect.Leave();
}
//============================================================================
void NetCliCsrLoginRequest (
const wchar_t csrName[],
const ShaDigest & namePassHash,
FNetCliCsrLoginCallback callback,
void * param
) {
LoginRequestTrans * trans = new LoginRequestTrans(
csrName,
namePassHash,
callback,
param
);
NetTransSend(trans);
}

View File

@ -1,94 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.h
*
***/
#ifdef PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLCSR_H
#error "Header $/Plasma20/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.h included more than once"
#endif
#define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLCSR_H
/*****************************************************************************
*
* Client-side CSR functions
*
***/
typedef void (*FNetCliCsrConnectedCallback) (
void * param,
unsigned latestBuildId
);
void NetCliCsrStartConnect (
const char* addrList[],
uint32_t addrCount,
FNetCliCsrConnectedCallback callback = nil,
void * param = nil
);
void NetCliCsrDisconnect ();
typedef void (*FNetCliCsrLoginCallback)(
ENetError result,
void * param,
const Uuid & csrId,
unsigned csrFlags
);
void NetCliCsrLoginRequest (
const wchar_t csrName[],
const ShaDigest & namePassHash,
FNetCliCsrLoginCallback callback,
void * param
);
typedef void (*FNetCliCsrSetTicketFilterCallback)(
ENetError result,
void * param
);
void NetCliCsrSetTicketFilter (
const wchar_t filterSpec[],
FNetCliCsrSetTicketFilterCallback callback,
void * param
);

View File

@ -79,7 +79,6 @@ unsigned ConnGetId (ENetProtocol protocol) {
case kNetProtocolCli2Auth: return AuthGetConnId();
case kNetProtocolCli2Game: return GameGetConnId();
case kNetProtocolCli2File: return FileGetConnId();
case kNetProtocolCli2Csr: return CsrGetConnId();
case kNetProtocolCli2GateKeeper: return GateKeeperGetConnId();
DEFAULT_FATAL(protocol);
}

View File

@ -144,7 +144,6 @@ bool NetTrans::CanStart () const {
case kNetProtocolCli2Auth: return AuthQueryConnected();
case kNetProtocolCli2Game: return GameQueryConnected();
case kNetProtocolCli2File: return FileQueryConnected();
case kNetProtocolCli2Csr: return CsrQueryConnected();
case kNetProtocolCli2GateKeeper: return GateKeeperQueryConnected();
DEFAULT_FATAL(m_protocol);
}