mirror of
https://github.com/SWG-Source/src.git
synced 2026-07-28 22:15:49 -04:00
Added sharedFractal library
This commit is contained in:
@@ -5,6 +5,7 @@ add_subdirectory(sharedDebug)
|
||||
add_subdirectory(sharedFile)
|
||||
add_subdirectory(sharedFoundation)
|
||||
add_subdirectory(sharedFoundationTypes)
|
||||
add_subdirectory(sharedFractal)
|
||||
add_subdirectory(sharedGame)
|
||||
add_subdirectory(sharedLog)
|
||||
add_subdirectory(sharedMath)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(sharedFractal)
|
||||
|
||||
if(WIN32)
|
||||
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/public)
|
||||
|
||||
add_subdirectory(src)
|
||||
@@ -0,0 +1 @@
|
||||
#include "../../src/shared/FirstSharedFractal.h"
|
||||
@@ -0,0 +1 @@
|
||||
#include "../../src/shared/MultiFractal.h"
|
||||
+1
@@ -0,0 +1 @@
|
||||
#include "../../src/shared/MultiFractalReaderWriter.h"
|
||||
@@ -0,0 +1,33 @@
|
||||
|
||||
set(SHARED_SOURCES
|
||||
shared/FirstSharedFractal.h
|
||||
shared/MultiFractal.cpp
|
||||
shared/MultiFractal.h
|
||||
shared/MultiFractalReaderWriter.cpp
|
||||
shared/MultiFractalReaderWriter.h
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set(PLATFORM_SOURCES
|
||||
win32/FirstSharedFractal.cpp
|
||||
)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/win32)
|
||||
else()
|
||||
set(PLATFORM_SOURCES "")
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shared
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedDebug/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFile/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundation/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundationTypes/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMemoryManager/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedRandom/include/public
|
||||
)
|
||||
|
||||
add_library(sharedFractal STATIC
|
||||
${SHARED_SOURCES}
|
||||
${PLATFORM_SOURCES}
|
||||
)
|
||||
@@ -0,0 +1,20 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// FirstFractal.h
|
||||
// copyright (c) 2001 Sony Online Entertainment
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef INCLUDED_FirstFractal_H
|
||||
#define INCLUDED_FirstFractal_H
|
||||
|
||||
// ======================================================================
|
||||
|
||||
#include "sharedFoundation/FirstSharedFoundation.h"
|
||||
#include "sharedDebug/FirstSharedDebug.h"
|
||||
#include "sharedMemoryManager/FirstSharedMemoryManager.h"
|
||||
|
||||
// ======================================================================
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,332 @@
|
||||
//
|
||||
// MultiFractal.h
|
||||
// asommers
|
||||
//
|
||||
// copyright 2001, sony online entertainment
|
||||
//
|
||||
//--
|
||||
//
|
||||
// MultiFractal will return values from 0 to 1
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#ifndef INCLUDED_MultiFractal_H
|
||||
#define INCLUDED_MultiFractal_H
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#include "sharedRandom/RandomGenerator.h"
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
class MultiFractal
|
||||
{
|
||||
public:
|
||||
|
||||
static const float ms_defaultScaleX;
|
||||
static const float ms_defaultScaleY;
|
||||
static const float ms_defaultOffsetX;
|
||||
static const float ms_defaultOffsetY;
|
||||
static const float ms_defaultBias;
|
||||
static const float ms_defaultGain;
|
||||
static const int ms_defaultNumberOfOctaves;
|
||||
static const float ms_defaultFrequency;
|
||||
static const float ms_defaultAmplitude;
|
||||
|
||||
public:
|
||||
|
||||
#ifdef _DEBUG
|
||||
static void debugDump ();
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
enum CombinationRule
|
||||
{
|
||||
CR_add,
|
||||
CR_multiply,
|
||||
CR_crest,
|
||||
CR_turbulence,
|
||||
CR_crestClamp,
|
||||
CR_turbulenceClamp,
|
||||
|
||||
CR_COUNT
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
MultiFractal (void);
|
||||
~MultiFractal (void);
|
||||
MultiFractal (const MultiFractal& rhs);
|
||||
MultiFractal& operator= (const MultiFractal& rhs);
|
||||
|
||||
bool operator== (const MultiFractal& rhs) const;
|
||||
|
||||
void allocateCache (int x, int y);
|
||||
|
||||
//--
|
||||
float getValue (float x) const;
|
||||
float getValue (float x, float y) const;
|
||||
float getValueCache (float x, float y, int cx, int cy) const;
|
||||
float getValue2 (float x, float y) const;
|
||||
float getValueCache2 (float x, float y, int cx, int cy) const;
|
||||
|
||||
//-- parameters
|
||||
uint32 getSeed (void) const;
|
||||
void setSeed (uint32 seed);
|
||||
|
||||
float getScaleX (void) const;
|
||||
float getScaleY (void) const;
|
||||
void setScale (float x=ms_defaultScaleX, float y=ms_defaultScaleY);
|
||||
|
||||
float getOffsetX (void) const;
|
||||
float getOffsetY (void) const;
|
||||
void setOffset (float x=ms_defaultOffsetX, float y=ms_defaultOffsetY);
|
||||
|
||||
//-- number of iterations of the noise
|
||||
int getNumberOfOctaves (void) const;
|
||||
void setNumberOfOctaves (int numberOfOctaves=ms_defaultNumberOfOctaves);
|
||||
|
||||
//-- multiplier for the period of each successive octave
|
||||
float getFrequency (void) const;
|
||||
void setFrequency (float frequency=ms_defaultFrequency);
|
||||
|
||||
//-- multiplier for the amplitude of each successive octave
|
||||
float getAmplitude (void) const;
|
||||
void setAmplitude (float amplitude=ms_defaultAmplitude);
|
||||
|
||||
//-- rule used to combine octaves
|
||||
CombinationRule getCombinationRule (void) const;
|
||||
void setCombinationRule (CombinationRule combinationRule);
|
||||
|
||||
//-- modifiers
|
||||
bool getUseSin (void) const;
|
||||
void setUseSin (bool newUseSin);
|
||||
|
||||
bool getUseBias (void) const;
|
||||
float getBias (void) const;
|
||||
void setBias (bool useBias, float bias);
|
||||
|
||||
bool getUseGain (void) const;
|
||||
float getGain (void) const;
|
||||
void setGain (bool useGain, float gain);
|
||||
|
||||
//--
|
||||
void reset (void);
|
||||
|
||||
private:
|
||||
|
||||
static float getValueAdd_1 (float x, const MultiFractal& multiFractal);
|
||||
static float getValueCrest_1 (float x, const MultiFractal& multiFractal);
|
||||
static float getValueTurbulence_1 (float x, const MultiFractal& multiFractal);
|
||||
static float getValueCrestClamp_1 (float x, const MultiFractal& multiFractal);
|
||||
static float getValueTurbulenceClamp_1 (float x, const MultiFractal& multiFractal);
|
||||
|
||||
static float getValueAdd_2 (float x, float y, const MultiFractal& multiFractal);
|
||||
static float getValueCrest_2 (float x, float y, const MultiFractal& multiFractal);
|
||||
static float getValueTurbulence_2 (float x, float y, const MultiFractal& multiFractal);
|
||||
static float getValueCrestClamp_2 (float x, float y, const MultiFractal& multiFractal);
|
||||
static float getValueTurbulenceClamp_2 (float x, float y, const MultiFractal& multiFractal);
|
||||
|
||||
private:
|
||||
|
||||
void copy (const MultiFractal& rhs);
|
||||
|
||||
void initTotalAmplitude (void);
|
||||
void resetCache ();
|
||||
|
||||
private:
|
||||
|
||||
typedef float (*CombinationFunction_1) (float x, const MultiFractal& multiFractal);
|
||||
typedef float (*CombinationFunction_2) (float x, float y, const MultiFractal& multiFractal);
|
||||
|
||||
private:
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// The NoiseGenerator algorithm came from Ken Perlin's PERLIN.C.
|
||||
// it has been c++-ified. NoiseGenerator will return values from -1 to 1
|
||||
|
||||
class NoiseGenerator
|
||||
{
|
||||
public:
|
||||
|
||||
explicit NoiseGenerator (uint32 seed=0);
|
||||
~NoiseGenerator (void);
|
||||
|
||||
void init (uint32 seed);
|
||||
|
||||
float getValue (float x) const;
|
||||
float getValue (float x, float y) const;
|
||||
|
||||
private:
|
||||
|
||||
float realGetValue (float x) const;
|
||||
float realGetValue (float x, float y) const;
|
||||
|
||||
private:
|
||||
|
||||
enum
|
||||
{
|
||||
B = 256,
|
||||
BM = 255,
|
||||
N = 4096,
|
||||
NP = 12,
|
||||
NM = 4095
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
RandomGenerator m_random;
|
||||
|
||||
int m_p [B + B + 2];
|
||||
float m_g2 [B + B + 2][2];
|
||||
float m_g1 [B + B + 2];
|
||||
};
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
private:
|
||||
|
||||
#ifdef _DEBUG
|
||||
static int ms_numberOfMultiFractalGetValueCalls;
|
||||
static int ms_numberOfMultiFractalGetValueCacheHits;
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
uint32 m_seed;
|
||||
float m_scaleX;
|
||||
float m_scaleY;
|
||||
float m_offsetX;
|
||||
float m_offsetY;
|
||||
int m_numberOfOctaves;
|
||||
float m_frequency;
|
||||
float m_amplitude;
|
||||
float m_ooTotalAmplitude;
|
||||
bool m_useBias;
|
||||
float m_bias;
|
||||
bool m_useGain;
|
||||
float m_gain;
|
||||
bool m_useSin;
|
||||
|
||||
CombinationRule m_combinationRule;
|
||||
CombinationFunction_1 m_combinationFunction_1;
|
||||
CombinationFunction_2 m_combinationFunction_2;
|
||||
|
||||
NoiseGenerator m_noiseGenerator;
|
||||
|
||||
//-- used to cache generated values
|
||||
struct CachedNode
|
||||
{
|
||||
bool cached;
|
||||
float x;
|
||||
float y;
|
||||
float value;
|
||||
};
|
||||
|
||||
int m_cacheX;
|
||||
int m_cacheY;
|
||||
mutable CachedNode* m_cache;
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
inline uint32 MultiFractal::getSeed (void) const
|
||||
{
|
||||
return m_seed;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
inline float MultiFractal::getScaleX (void) const
|
||||
{
|
||||
return m_scaleX;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
inline float MultiFractal::getScaleY (void) const
|
||||
{
|
||||
return m_scaleY;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
inline float MultiFractal::getOffsetX (void) const
|
||||
{
|
||||
return m_offsetX;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
inline float MultiFractal::getOffsetY (void) const
|
||||
{
|
||||
return m_offsetY;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
inline int MultiFractal::getNumberOfOctaves (void) const
|
||||
{
|
||||
return m_numberOfOctaves;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
inline float MultiFractal::getFrequency (void) const
|
||||
{
|
||||
return m_frequency;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
inline float MultiFractal::getAmplitude (void) const
|
||||
{
|
||||
return m_amplitude;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
inline bool MultiFractal::getUseBias (void) const
|
||||
{
|
||||
return m_useBias;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
inline float MultiFractal::getBias (void) const
|
||||
{
|
||||
return m_bias;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
inline bool MultiFractal::getUseGain (void) const
|
||||
{
|
||||
return m_useGain;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
inline float MultiFractal::getGain (void) const
|
||||
{
|
||||
return m_gain;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
inline bool MultiFractal::getUseSin (void) const
|
||||
{
|
||||
return m_useSin;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
inline MultiFractal::CombinationRule MultiFractal::getCombinationRule (void) const
|
||||
{
|
||||
return m_combinationRule;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,149 @@
|
||||
//
|
||||
// MultiFractalReaderWriter.cpp
|
||||
// asommers
|
||||
//
|
||||
// copyright 2001, sony online entertainment
|
||||
//
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#include "sharedFractal/FirstSharedFractal.h"
|
||||
#include "sharedFractal/MultiFractalReaderWriter.h"
|
||||
|
||||
#include "sharedFile/Iff.h"
|
||||
#include "sharedFractal/MultiFractal.h"
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
void MultiFractalReaderWriter::save (Iff& iff, const MultiFractal& multiFractal)
|
||||
{
|
||||
iff.insertForm (TAG (M,F,R,C));
|
||||
|
||||
iff.insertForm (TAG_0001);
|
||||
|
||||
iff.insertChunk (TAG_DATA);
|
||||
|
||||
iff.insertChunkData (multiFractal.getSeed ());
|
||||
iff.insertChunkData (multiFractal.getUseBias () ? static_cast<int32> (1) : static_cast<int32> (0));
|
||||
iff.insertChunkData (multiFractal.getBias ());
|
||||
iff.insertChunkData (multiFractal.getUseGain () ? static_cast<int32> (1) : static_cast<int32> (0));
|
||||
iff.insertChunkData (multiFractal.getGain ());
|
||||
iff.insertChunkData (multiFractal.getNumberOfOctaves ());
|
||||
iff.insertChunkData (multiFractal.getFrequency ());
|
||||
iff.insertChunkData (multiFractal.getAmplitude ());
|
||||
iff.insertChunkData (multiFractal.getScaleX ());
|
||||
iff.insertChunkData (multiFractal.getScaleY ());
|
||||
iff.insertChunkData (multiFractal.getOffsetX ());
|
||||
iff.insertChunkData (multiFractal.getOffsetY ());
|
||||
iff.insertChunkData (static_cast<int32> (multiFractal.getCombinationRule ()));
|
||||
|
||||
iff.exitChunk ();
|
||||
|
||||
iff.exitForm ();
|
||||
|
||||
iff.exitForm ();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
void MultiFractalReaderWriter::load (Iff& iff, MultiFractal& multiFractal)
|
||||
{
|
||||
iff.enterForm (TAG (M,F,R,C));
|
||||
|
||||
switch (iff.getCurrentName ())
|
||||
{
|
||||
case TAG_0000:
|
||||
load_0000 (iff, multiFractal);
|
||||
break;
|
||||
|
||||
case TAG_0001:
|
||||
load_0001 (iff, multiFractal);
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
char tagBuffer [5];
|
||||
ConvertTagToString (iff.getCurrentName (), tagBuffer);
|
||||
|
||||
char buffer [128];
|
||||
iff.formatLocation (buffer, sizeof (buffer));
|
||||
DEBUG_FATAL (true, ("unknown affector type %s/%s", buffer, tagBuffer));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
iff.exitForm ();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
void MultiFractalReaderWriter::load_0000 (Iff& iff, MultiFractal& multiFractal)
|
||||
{
|
||||
iff.enterForm (TAG_0000);
|
||||
|
||||
iff.enterChunk (TAG_DATA);
|
||||
|
||||
multiFractal.setSeed (iff.read_uint32 ());
|
||||
|
||||
const bool useBias = iff.read_int32 () != 0;
|
||||
const real bias = iff.read_float ();
|
||||
multiFractal.setBias (useBias, bias);
|
||||
|
||||
const bool useGain = iff.read_int32 () != 0;
|
||||
const real gain = iff.read_float ();
|
||||
multiFractal.setGain (useGain, gain);
|
||||
|
||||
multiFractal.setNumberOfOctaves (iff.read_int32 ());
|
||||
multiFractal.setFrequency (iff.read_float ());
|
||||
multiFractal.setAmplitude (iff.read_float ());
|
||||
|
||||
const real scaleX = iff.read_float ();
|
||||
const real scaleY = iff.read_float ();
|
||||
multiFractal.setScale (scaleX, scaleY);
|
||||
|
||||
multiFractal.setCombinationRule (static_cast<MultiFractal::CombinationRule> (iff.read_int32 ()));
|
||||
|
||||
iff.exitChunk ();
|
||||
|
||||
iff.exitForm ();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
void MultiFractalReaderWriter::load_0001 (Iff& iff, MultiFractal& multiFractal)
|
||||
{
|
||||
iff.enterForm (TAG_0001);
|
||||
|
||||
iff.enterChunk (TAG_DATA);
|
||||
|
||||
multiFractal.setSeed (iff.read_uint32 ());
|
||||
|
||||
const bool useBias = iff.read_int32 () != 0;
|
||||
const real bias = iff.read_float ();
|
||||
multiFractal.setBias (useBias, bias);
|
||||
|
||||
const bool useGain = iff.read_int32 () != 0;
|
||||
const real gain = iff.read_float ();
|
||||
multiFractal.setGain (useGain, gain);
|
||||
|
||||
multiFractal.setNumberOfOctaves (iff.read_int32 ());
|
||||
multiFractal.setFrequency (iff.read_float ());
|
||||
multiFractal.setAmplitude (iff.read_float ());
|
||||
|
||||
const real scaleX = iff.read_float ();
|
||||
const real scaleY = iff.read_float ();
|
||||
multiFractal.setScale (scaleX, scaleY);
|
||||
|
||||
const real offsetX = iff.read_float ();
|
||||
const real offsetY = iff.read_float ();
|
||||
multiFractal.setOffset (offsetX, offsetY);
|
||||
|
||||
multiFractal.setCombinationRule (static_cast<MultiFractal::CombinationRule> (iff.read_int32 ()));
|
||||
|
||||
iff.exitChunk ();
|
||||
|
||||
iff.exitForm ();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// MultiFractalReaderWriter.h
|
||||
// asommers
|
||||
//
|
||||
// copyright 2001, sony online entertainment
|
||||
//
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#ifndef INCLUDED_MultiFractalReaderWriter_H
|
||||
#define INCLUDED_MultiFractalReaderWriter_H
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
class Iff;
|
||||
class MultiFractal;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
class MultiFractalReaderWriter
|
||||
{
|
||||
public:
|
||||
|
||||
static void save (Iff& iff, const MultiFractal& multiFractal);
|
||||
static void load (Iff& iff, MultiFractal& multiFractal);
|
||||
|
||||
private:
|
||||
|
||||
static void load_0000 (Iff& iff, MultiFractal& multiFractal);
|
||||
static void load_0001 (Iff& iff, MultiFractal& multiFractal);
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// FirstFractal.cpp
|
||||
// copyright (c) 2001 Sony Online Entertainment
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include "sharedFractal/FirstSharedFractal.h"
|
||||
Reference in New Issue
Block a user