# Sky set can now be changed through the console.
This was SVN commit r3869.
This commit is contained in:
parent
3cb34fb311
commit
4879b98fc7
@ -1450,6 +1450,21 @@ void CRenderer::JSI_SetDepthTextureBits(JSContext* ctx, jsval newval)
|
||||
m->shadow->SetDepthTextureBits(depthTextureBits);
|
||||
}
|
||||
|
||||
jsval CRenderer::JSI_GetSky(JSContext*)
|
||||
{
|
||||
return ToJSVal(m->skyManager.GetSkySet());
|
||||
}
|
||||
|
||||
void CRenderer::JSI_SetSky(JSContext* ctx, jsval newval)
|
||||
{
|
||||
CStrW skySet;
|
||||
|
||||
if (!ToPrimitive<CStrW>(ctx, newval, skySet))
|
||||
return;
|
||||
|
||||
m->skyManager.SetSkySet(skySet);
|
||||
}
|
||||
|
||||
void CRenderer::ScriptingInit()
|
||||
{
|
||||
AddProperty(L"fastPlayerColor", &CRenderer::JSI_GetFastPlayerColor, &CRenderer::JSI_SetFastPlayerColor);
|
||||
@ -1461,6 +1476,7 @@ void CRenderer::ScriptingInit()
|
||||
AddProperty(L"shadowZBias", &CRenderer::m_ShadowZBias);
|
||||
AddProperty(L"disableCopyShadow", &CRenderer::m_DisableCopyShadow);
|
||||
AddProperty(L"depthTextureBits", &CRenderer::JSI_GetDepthTextureBits, &CRenderer::JSI_SetDepthTextureBits);
|
||||
AddProperty(L"skySet", &CRenderer::JSI_GetSky, &CRenderer::JSI_SetSky);
|
||||
|
||||
CJSObject<CRenderer>::ScriptingInit("Renderer");
|
||||
}
|
||||
|
@ -327,6 +327,8 @@ protected:
|
||||
void JSI_SetUseDepthTexture(JSContext* ctx, jsval newval);
|
||||
jsval JSI_GetDepthTextureBits(JSContext*);
|
||||
void JSI_SetDepthTextureBits(JSContext* ctx, jsval newval);
|
||||
jsval JSI_GetSky(JSContext*);
|
||||
void JSI_SetSky(JSContext* ctx, jsval newval);
|
||||
static void ScriptingInit();
|
||||
|
||||
// patch rendering stuff
|
||||
|
@ -30,13 +30,26 @@
|
||||
// SkyManager implementation
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// String names for each image, in order of the IMG_ constants
|
||||
const char* SkyManager::IMAGE_NAMES[5] = {
|
||||
"front",
|
||||
"back",
|
||||
"right",
|
||||
"left",
|
||||
"top"
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
SkyManager::SkyManager()
|
||||
{
|
||||
// water
|
||||
m_RenderSky = true;
|
||||
|
||||
// TODO: add a way to set the initial skyset before progressive load
|
||||
m_SkySet = L"default";
|
||||
|
||||
for (uint i = 0; i < ARRAY_SIZE(m_SkyTexture); i++)
|
||||
m_SkyTexture[i] = 0;
|
||||
|
||||
@ -54,16 +67,6 @@ SkyManager::~SkyManager()
|
||||
// Progressive load of sky textures
|
||||
int SkyManager::LoadSkyTextures()
|
||||
{
|
||||
// Note: this must be kept in sync with the IMG_ constants in SkyManager.h
|
||||
static const char* IMAGE_NAMES[6] = {
|
||||
"front",
|
||||
"back",
|
||||
"right",
|
||||
"left",
|
||||
"top",
|
||||
"bottom"
|
||||
};
|
||||
|
||||
const uint num_textures = ARRAY_SIZE(m_SkyTexture);
|
||||
|
||||
// yield after this time is reached. balances increased progress bar
|
||||
@ -73,10 +76,8 @@ int SkyManager::LoadSkyTextures()
|
||||
while (cur_loading_tex < num_textures)
|
||||
{
|
||||
char filename[PATH_MAX];
|
||||
// TODO: add a member variable and setter for this. (can't make this
|
||||
// a parameter because this function is called via delay-load code)
|
||||
static const char* const set_name = "day1";
|
||||
snprintf(filename, ARRAY_SIZE(filename), "art/textures/skies/%s/%s.dds", set_name, IMAGE_NAMES[cur_loading_tex]);
|
||||
snprintf(filename, ARRAY_SIZE(filename), "art/textures/skies/%s/%s.dds",
|
||||
CStr8(m_SkySet).c_str(), IMAGE_NAMES[cur_loading_tex]);
|
||||
Handle ht = ogl_tex_load(filename);
|
||||
if (ht <= 0)
|
||||
{
|
||||
@ -104,7 +105,35 @@ void SkyManager::UnloadSkyTextures()
|
||||
ogl_tex_free(m_SkyTexture[i]);
|
||||
m_SkyTexture[i] = 0;
|
||||
}
|
||||
cur_loading_tex = 0; // so they will be reloaded if LoadWaterTextures is called again
|
||||
cur_loading_tex = 0;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Switch to a different sky set (while the game is running)
|
||||
void SkyManager::SetSkySet( CStrW newSet )
|
||||
{
|
||||
if( newSet != m_SkySet )
|
||||
{
|
||||
m_SkySet = newSet;
|
||||
|
||||
UnloadSkyTextures();
|
||||
|
||||
for( int i=0; i<ARRAY_SIZE(m_SkyTexture); i++ ) {
|
||||
char filename[PATH_MAX];
|
||||
snprintf(filename, ARRAY_SIZE(filename), "art/textures/skies/%s/%s.dds",
|
||||
CStr8(m_SkySet).c_str(), IMAGE_NAMES[i]);
|
||||
Handle ht = ogl_tex_load(filename);
|
||||
if (ht <= 0)
|
||||
{
|
||||
LOG(ERROR, LOG_CATEGORY, "SkyManager::SetSkySet failed on \"%s\"", filename);
|
||||
return;
|
||||
}
|
||||
ogl_tex_set_wrap(ht, GL_CLAMP_TO_EDGE);
|
||||
m_SkyTexture[i] = ht;
|
||||
ogl_tex_upload(ht);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -200,20 +229,6 @@ void SkyManager::RenderSky()
|
||||
glVertex3f( +D, +D, +D );
|
||||
glEnd();
|
||||
|
||||
// Bottom face (negative Y)
|
||||
// Note: These texcoords not be completely correct (haven't had a good texture to test with)
|
||||
ogl_tex_bind( m_SkyTexture[IMG_BOTTOM] );
|
||||
glBegin( GL_QUADS );
|
||||
glTexCoord2f( 1, 0 );
|
||||
glVertex3f( +D, -D, -D );
|
||||
glTexCoord2f( 1, 1 );
|
||||
glVertex3f( +D, -D, +D );
|
||||
glTexCoord2f( 0, 1 );
|
||||
glVertex3f( -D, -D, +D );
|
||||
glTexCoord2f( 0, 0 );
|
||||
glVertex3f( -D, -D, -D );
|
||||
glEnd();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glDepthMask( GL_TRUE );
|
||||
|
@ -19,18 +19,6 @@
|
||||
class SkyManager
|
||||
{
|
||||
public:
|
||||
Handle m_SkyTexture[6];
|
||||
|
||||
// Indices into m_SkyTexture
|
||||
// Note: these must be kept in sync with the string constants in LoadSkyTextures;
|
||||
// perhaps there is a more clever way to do that.
|
||||
static const int IMG_FRONT = 0;
|
||||
static const int IMG_BACK = 1;
|
||||
static const int IMG_RIGHT = 2;
|
||||
static const int IMG_LEFT = 3;
|
||||
static const int IMG_TOP = 4;
|
||||
static const int IMG_BOTTOM = 5;
|
||||
|
||||
bool m_RenderSky;
|
||||
|
||||
public:
|
||||
@ -57,7 +45,35 @@ public:
|
||||
*/
|
||||
void RenderSky();
|
||||
|
||||
/**
|
||||
* GetSkySet(): Return the currently selected sky set name
|
||||
*/
|
||||
inline CStrW GetSkySet() {
|
||||
return m_SkySet;
|
||||
}
|
||||
|
||||
/**
|
||||
* GetSkySet(): Set the sky set name, potentially loading the textures
|
||||
*/
|
||||
void SetSkySet(CStrW name);
|
||||
|
||||
private:
|
||||
/// Name of current skyset (a directory within art/textures/skies)
|
||||
CStrW m_SkySet;
|
||||
|
||||
// Sky textures
|
||||
Handle m_SkyTexture[5];
|
||||
|
||||
// Indices into m_SkyTexture
|
||||
static const int IMG_FRONT = 0;
|
||||
static const int IMG_BACK = 1;
|
||||
static const int IMG_RIGHT = 2;
|
||||
static const int IMG_LEFT = 3;
|
||||
static const int IMG_TOP = 4;
|
||||
|
||||
// Array of image names (defined in SkyManager.cpp), in the order of the IMG_ id's
|
||||
static const char* IMAGE_NAMES[5];
|
||||
|
||||
/// State of progressive loading (in # of loaded textures)
|
||||
uint cur_loading_tex;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user