#include <valfunc.h>
Inheritance diagram for ValueFunctionRandom:
Public Member Functions | |
ValueFunctionRandom (UINT32 Seed=0, double Min=0.8, double Max=1.0) | |
Constructor The Random ValueFunction returns a pseudo-random value between Min & Max. | |
virtual double | GetValue (double Position) |
To read the value of this function at a given position. | |
virtual ValueFunction * | Clone (void) |
Clone operator. Creates an exact copy of this object. | |
virtual BOOL | IsDifferent (ValueFunction *pOther) |
Comparator. Determines if 2 different ValueFunction objects are considered different. | |
virtual CamelotFileRecord * | WriteFileRecord (INT32 RecordTag, INT32 ExtraBytes, BaseCamelotFilter *pFilter) |
Saves a ValueFunction object to a Xara file. This function will create a new variable-sized record with the given record tag, and will write out whatever data is needed to save this ValueFunction's state to the file. | |
virtual ValueFunctionID | GetUniqueID (void) |
Protected Member Functions | |
virtual ValueFunction * | CreateAndReadFileRecord (CXaraFileRecord *pInputRecord) |
Loads a ValueFunction object from a record which was saved into a file using the WriteFileRecord call. This is called by the base class loader routine ReadFileRecord, which finds an appropriate instance of a derived class to call to load the data in question. | |
Protected Attributes | |
short | Array [NumRandomValues] |
UINT32 | SeedValue |
double | MinValue |
double | MaxValue |
Private Member Functions | |
CC_DECLARE_DYNAMIC (ValueFunctionRandom) |
Definition at line 318 of file valfunc.h.
|
Constructor The Random ValueFunction returns a pseudo-random value between Min & Max.
Definition at line 692 of file valfunc.cpp. 00693 { 00694 ERROR3IF(Min > Max, "ValueFunctionRandom: Min should be smaller than Max"); 00695 00696 MinValue = Min; 00697 MaxValue = Max; 00698 SeedValue = Seed; 00699 00700 // Fill in the array with random values 00701 srand(SeedValue); 00702 for (INT32 i = 0; i < NumRandomValues; i++) 00703 Array[i] = rand() & 0xffff; 00704 }
|
|
|
|
Clone operator. Creates an exact copy of this object.
Implements ValueFunction. Definition at line 765 of file valfunc.cpp. 00766 { 00767 ValueFunction *pClone = new ValueFunctionRandom(SeedValue, MinValue, MaxValue); 00768 return(pClone); 00769 }
|
|
Loads a ValueFunction object from a record which was saved into a file using the WriteFileRecord call. This is called by the base class loader routine ReadFileRecord, which finds an appropriate instance of a derived class to call to load the data in question.
Implements ValueFunction. Definition at line 903 of file valfunc.cpp. 00904 { 00905 ERROR3IF(pInputRecord == NULL, "Illegal NULL param"); 00906 00907 UINT32 SeedValue = 1; 00908 float MinValue = (float) 0.0; 00909 float MaxValue = (float) 0.0; 00910 00911 pInputRecord->ReadUINT32(&SeedValue); 00912 pInputRecord->ReadFLOAT(&MinValue); 00913 pInputRecord->ReadFLOAT(&MaxValue); 00914 00915 return(new ValueFunctionRandom((UINT32) SeedValue, (double) MinValue, (double) MinValue)); 00916 }
|
|
Implements ValueFunction. Definition at line 331 of file valfunc.h. 00331 { return(ValueFunctionID_Random); };
|
|
To read the value of this function at a given position.
Implements ValueFunction. Definition at line 728 of file valfunc.cpp. 00729 { 00730 // Determine which array entry to use, and how much to linearly interpolate 00731 // between it and the next value 00732 INT32 Index = (INT32) floor(Position * (double)(0x400 * (NumRandomValues - 2))); 00733 double MixFraction = (double)(Index & 0x3ff) / (double)0x3ff; 00734 00735 // Scale the Index value down into the proper range now, and make sure it's safe 00736 Index /= 0x400; 00737 if (Index < 0) 00738 Index = 0; 00739 if (Index > NumRandomValues - 2) 00740 Index = NumRandomValues - 2; 00741 00742 // Get a random number between 0.0 and 1.0 00743 double Value = ((double)Array[Index] * (1.0 - MixFraction)) + ((double)Array[Index+1] * MixFraction); 00744 Value /= (double) 0xffff; 00745 00746 // And scale the result into the range specified by the caller 00747 return( MinValue + (Value * (MaxValue - MinValue)) ); 00748 }
|
|
Comparator. Determines if 2 different ValueFunction objects are considered different.
Reimplemented from ValueFunction. Definition at line 790 of file valfunc.cpp. 00791 { 00792 return(TRUE); // Random value functions always consider themselves different 00793 }
|
|
Saves a ValueFunction object to a Xara file. This function will create a new variable-sized record with the given record tag, and will write out whatever data is needed to save this ValueFunction's state to the file.
All ValueFunction record data has 3 sections, whiich are recorded as follows: 1. ValueFunction header, identifying which type of VF is being saved INT32 ValueFunctionUniqueID (4 bytes) 2. Derived-class-data (0 or more bytes). This particular class adds: UINT32 SeedValue float MinValue float MaxValue (12 bytes) 3. Caller data. This is written by the caller to the returned record object. This data must be ExtraBytes (0 or more) bytes in length.
Implements ValueFunction. Definition at line 841 of file valfunc.cpp. 00843 { 00844 ERROR3IF(pFilter == NULL, "Illegal NULL param"); 00845 ERROR3IF(ExtraBytes < 0, "Stupid ExtraBytes request in ValueFunction::WriteFileRecord"); 00846 00847 // Calculate how many bytes of information this VF will write. We do not include 00848 // the header info written by the base class or the ExtraInfo desired by the caller - 00849 // the base class adds all that in for us. 00850 const INT32 MyRecordSize = 12; 00851 00852 // Create an appropriate record, and write our data to it 00853 CamelotFileRecord *pRec = CreateAndWriteFileRecord(RecordTag, MyRecordSize, ExtraBytes, pFilter); 00854 00855 if (pRec != NULL) 00856 { 00857 // Write out our ValueFunction's specific data. If it fails, then we'll return NULL 00858 BOOL ok = TRUE; 00859 if (ok) ok = pRec->WriteUINT32((UINT32)SeedValue); 00860 if (ok) ok = pRec->WriteFLOAT((float)MinValue); 00861 if (ok) ok = pRec->WriteFLOAT((float)MaxValue); 00862 00863 if (!ok) 00864 { 00865 delete pRec; 00866 pRec = NULL; 00867 } 00868 } 00869 00870 return(pRec); 00871 }
|
|
|
|
|
|
|
|
|