From 38acc083d16a0d846681e41bcc5d59cb3508baa2 Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Mon, 20 Mar 2017 22:09:27 +0100 Subject: [PATCH] fixed light controls in EZT modules, added missing vbo code --- DynObj.cpp | 19 +++++++------- lightarray.cpp | 4 ++- renderer.cpp | 67 ++++++++++++++++++++++++++++++++++++-------------- stars.cpp | 9 +++++-- 4 files changed, 67 insertions(+), 32 deletions(-) diff --git a/DynObj.cpp b/DynObj.cpp index 3a59e335..e31f1d55 100644 --- a/DynObj.cpp +++ b/DynObj.cpp @@ -2451,19 +2451,18 @@ void TDynamicObject::AttachPrev(TDynamicObject *Object, int iType) Object->NextConnected = this; // on ma nas z tyłu Object->NextConnectedNo = iDirection; } +/* + // NOTE: this appears unnecessary and only messes things for the programmable lights function, which walks along + // whole trainset and expects each module to point to its own lights. Disabled, TBD, TODO: test for side-effects and delete if there's none if (MoverParameters->TrainType & dt_EZT) // w przypadku łączenia członów, - // światła w rozrządczym zależą od - // stanu w silnikowym - if (MoverParameters->Couplers[iDirection].AllowedFlag & - ctrain_depot) // gdy sprzęgi łączone warsztatowo (powiedzmy) - if ((MoverParameters->Power < 1.0) && - (Object->MoverParameters->Power > 1.0)) // my nie mamy mocy, ale ten drugi ma - iLights = Object->MoverParameters->iLights; // to w tym z mocą będą światła - // załączane, a w tym bez tylko widoczne + // światła w rozrządczym zależą od stanu w silnikowym + if (MoverParameters->Couplers[iDirection].AllowedFlag & ctrain_depot) // gdy sprzęgi łączone warsztatowo (powiedzmy) + if ((MoverParameters->Power < 1.0) && (Object->MoverParameters->Power > 1.0)) // my nie mamy mocy, ale ten drugi ma + iLights = Object->MoverParameters->iLights; // to w tym z mocą będą światła załączane, a w tym bez tylko widoczne else if ((MoverParameters->Power > 1.0) && (Object->MoverParameters->Power < 1.0)) // my mamy moc, ale ten drugi nie ma - Object->iLights = MoverParameters->iLights; // to w tym z mocą będą światła - // załączane, a w tym bez tylko widoczne + Object->iLights = MoverParameters->iLights; // to w tym z mocą będą światła załączane, a w tym bez tylko widoczne +*/ return; // SetPneumatic(1,1); //Ra: to i tak się nie wykonywało po return // SetPneumatic(1,0); diff --git a/lightarray.cpp b/lightarray.cpp index d37082e3..5cc85168 100644 --- a/lightarray.cpp +++ b/lightarray.cpp @@ -73,16 +73,18 @@ light_array::update() { else { light.intensity = 0.0f; } - +/* // crude catch for unmanned modules which share the light state with the controlled unit. // why don't they get their own light bits btw ._. // TODO, TBD: have separate light bits for each vehicle, so this override isn't necessary + // NOTE: should be no longer needed, test and delete if there's no ill effects if( ( light.owner->Controller == AIdriver ) && ( light.owner->Mechanik == nullptr ) ) { light.intensity = 0.0f; light.count = 0; } +*/ } else { // with battery off the lights are off diff --git a/renderer.cpp b/renderer.cpp index 8c23dbb1..9fe8678c 100644 --- a/renderer.cpp +++ b/renderer.cpp @@ -363,34 +363,63 @@ opengl_renderer::Render_Alpha( TDynamicObject *Dynamic ) { ::glTranslated( Dynamic->vPosition.x, Dynamic->vPosition.y, Dynamic->vPosition.z ); // standardowe przesunięcie względem początku scenerii ::glMultMatrixd( Dynamic->mMatrix.getArray() ); - // wersja Display Lists - // NOTE: VBO path is removed + // TODO: implement universal render path down the road - if( Dynamic->mdLowPolyInt ) { - // low poly interior - if( FreeFlyModeFlag ? true : !Dynamic->mdKabina || !Dynamic->bDisplayCab ) { - // enable cab light if needed - if( Dynamic->InteriorLightLevel > 0.0f ) { + if( Global::bUseVBO ) { + // wersja VBO + if( Dynamic->mdLowPolyInt ) { + if( FreeFlyModeFlag ? true : !Dynamic->mdKabina || !Dynamic->bDisplayCab ) { + // enable cab light if needed + if( Dynamic->InteriorLightLevel > 0.0f ) { - // crude way to light the cabin, until we have something more complete in place - auto const cablight = Dynamic->InteriorLight * Dynamic->InteriorLightLevel; - ::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, &cablight.x ); - } + // crude way to light the cabin, until we have something more complete in place + auto const cablight = Dynamic->InteriorLight * Dynamic->InteriorLightLevel; + ::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, &cablight.x ); + } - Render_Alpha( Dynamic->mdLowPolyInt, Dynamic->Material(), squaredistance ); + Dynamic->mdLowPolyInt->RaRenderAlpha( squaredistance, Dynamic->Material()->replacable_skins, Dynamic->Material()->textures_alpha ); - if( Dynamic->InteriorLightLevel > 0.0f ) { - // reset the overall ambient - GLfloat ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f }; - ::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, ambient ); + if( Dynamic->InteriorLightLevel > 0.0f ) { + // reset the overall ambient + GLfloat ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f }; + ::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, ambient ); + } } } + + Dynamic->mdModel->RaRenderAlpha( squaredistance, Dynamic->Material()->replacable_skins, Dynamic->Material()->textures_alpha ); + + if( Dynamic->mdLoad ) // renderowanie nieprzezroczystego ładunku + Dynamic->mdLoad->RaRenderAlpha( squaredistance, Dynamic->Material()->replacable_skins, Dynamic->Material()->textures_alpha ); } + else { + // wersja Display Lists + if( Dynamic->mdLowPolyInt ) { + // low poly interior + if( FreeFlyModeFlag ? true : !Dynamic->mdKabina || !Dynamic->bDisplayCab ) { + // enable cab light if needed + if( Dynamic->InteriorLightLevel > 0.0f ) { - Render_Alpha( Dynamic->mdModel, Dynamic->Material(), squaredistance ); + // crude way to light the cabin, until we have something more complete in place + auto const cablight = Dynamic->InteriorLight * Dynamic->InteriorLightLevel; + ::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, &cablight.x ); + } - if( Dynamic->mdLoad ) // renderowanie nieprzezroczystego ładunku - Render_Alpha( Dynamic->mdLoad, Dynamic->Material(), squaredistance ); + Render_Alpha( Dynamic->mdLowPolyInt, Dynamic->Material(), squaredistance ); + + if( Dynamic->InteriorLightLevel > 0.0f ) { + // reset the overall ambient + GLfloat ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f }; + ::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, ambient ); + } + } + } + + Render_Alpha( Dynamic->mdModel, Dynamic->Material(), squaredistance ); + + if( Dynamic->mdLoad ) // renderowanie nieprzezroczystego ładunku + Render_Alpha( Dynamic->mdLoad, Dynamic->Material(), squaredistance ); + } ::glPopMatrix(); diff --git a/stars.cpp b/stars.cpp index 1dafcdcb..b8ee3aa8 100644 --- a/stars.cpp +++ b/stars.cpp @@ -21,11 +21,16 @@ cStars::render() { ::glRotatef( -std::fmod( Global::fTimeAngleDeg, 360.0f ), 0.0f, 1.0f, 0.0f ); // obrót dobowy osi OX ::glPointSize( 2.0f ); + if( Global::bUseVBO ) { + m_stars.RaRender( 1.0, 0 ); + } + else { #ifdef EU07_USE_OLD_RENDERCODE - m_stars.Render( 1.0 ); + m_stars.Render( 1.0 ); #else - GfxRenderer.Render( &m_stars, nullptr, 1.0 ); + GfxRenderer.Render( &m_stars, nullptr, 1.0 ); #endif + } ::glPointSize( 3.0f ); ::glPopMatrix();