Skip to content

Commit

Permalink
Merge remote-tracking branch 'tmj/master' into sim
Browse files Browse the repository at this point in the history
  • Loading branch information
Milek7 committed Oct 18, 2020
2 parents 1dc1bd5 + 4da87e9 commit 29f8f91
Show file tree
Hide file tree
Showing 244 changed files with 54,311 additions and 11,783 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ install_manifest.txt
*.opensdf
*.sdf
*.sln
*.vcxproj
*.filters
#*.vcxproj
#*.filters
format_all_files.py
*.suo
EU07.tds
Expand Down
30 changes: 30 additions & 0 deletions AirCoupler.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,34 @@ class AirCoupler
xOn = true;
Update();
};

// if the xOn model is missing, activate plain On instead
inline void TurnxOnWithOnAsFallback()
{
if (ModelxOn != nullptr) {
On = false;
xOn = true;
Update();
}
else {
TurnOn();
}
};
// if the xOn model is missing, activate plain Off instead
inline void TurnxOnWithOffAsFallback()
{
if (ModelxOn != nullptr) {
On = false;
xOn = true;
Update();
}
else {
TurnOff();
}
};
inline bool Active() const
{
return ( ( ModelOn != nullptr ) || ( ModelxOn != nullptr ) );
};
};

95 changes: 59 additions & 36 deletions AnimModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ obtain one at
#include "stdafx.h"
#include "AnimModel.h"

#include "opengl33renderer.h"
#include "renderer.h"
#include "MdlMngr.h"
#include "simulation.h"
#include "simulationtime.h"
#include "Event.h"
#include "Globals.h"
#include "Timer.h"
#include "Logs.h"
#include "opengl33renderer.h"
#include "renderer.h"

std::list<std::weak_ptr<TAnimContainer>> TAnimModel::acAnimList;

Expand Down Expand Up @@ -256,28 +256,7 @@ bool TAnimModel::Init(std::string const &asName, std::string const &asReplacable
asText = asReplacableTexture.substr( 1, asReplacableTexture.length() - 1 ); // zapamiętanie tekstu
}
else if( asReplacableTexture != "none" ) {
/*
auto const texturepath { substr_path( asReplacableTexture ) };
if( false == texturepath.empty() ) {
Global.asCurrentTexturePath = texturepath;
}
*/
m_materialdata.replacable_skins[ 1 ] = GfxRenderer.Fetch_Material( asReplacableTexture );
/*
if( false == texturepath.empty() ) {
// z powrotem defaultowa sciezka do tekstur
Global.asCurrentTexturePath = std::string( szTexturePath );
}
*/
}
if( ( m_materialdata.replacable_skins[ 1 ] != null_handle )
&& ( GfxRenderer.Material( m_materialdata.replacable_skins[ 1 ] ).get_or_guess_opacity() == 0.0f ) ) {
// tekstura z kanałem alfa - nie renderować w cyklu nieprzezroczystych
m_materialdata.textures_alpha = 0x31310031;
}
else{
// tekstura nieprzezroczysta - nie renderować w cyklu przezroczystych
m_materialdata.textures_alpha = 0x30300030;
m_materialdata.assign( asReplacableTexture );
}

// TODO: redo the random timer initialization
Expand All @@ -287,6 +266,16 @@ bool TAnimModel::Init(std::string const &asName, std::string const &asReplacable
return ( pModel != nullptr );
}

bool
TAnimModel::is_keyword( std::string const &Token ) const {

return ( Token == "endmodel" )
|| ( Token == "lights" )
|| ( Token == "lightcolors" )
|| ( Token == "angles" )
|| ( Token == "notransition" );
}

bool TAnimModel::Load(cParser *parser, bool ter)
{ // rozpoznanie wpisu modelu i ustawienie świateł
std::string name = ToLower(parser->getToken<std::string>());
Expand Down Expand Up @@ -341,8 +330,7 @@ bool TAnimModel::Load(cParser *parser, bool ter)
if( token == "lights" ) {
auto i{ 0 };
while( ( false == ( token = parser->getToken<std::string>() ).empty() )
&& ( token != "lightcolors" )
&& ( token != "endmodel" ) ) {
&& ( false == is_keyword( token ) ) ) {

if( i < iNumLights ) {
// stan światła jest liczbą z ułamkiem
Expand All @@ -355,8 +343,7 @@ bool TAnimModel::Load(cParser *parser, bool ter)
if( token == "lightcolors" ) {
auto i{ 0 };
while( ( false == ( token = parser->getToken<std::string>() ).empty() )
&& ( token != "lights" )
&& ( token != "endmodel" ) ) {
&& ( false == is_keyword( token ) ) ) {

if( ( i < iNumLights )
&& ( token != "-1" ) ) { // -1 leaves the default color intact
Expand All @@ -369,6 +356,19 @@ bool TAnimModel::Load(cParser *parser, bool ter)
++i;
}
}

if( token == "angles" ) {
parser->getTokens( 3 );
*parser
>> vAngle[ 0 ]
>> vAngle[ 1 ]
>> vAngle[ 2 ];
}

if( token == "notransition" ) {
m_transition = false;
}

} while( ( false == token.empty() )
&& ( token != "endmodel" ) );

Expand Down Expand Up @@ -429,6 +429,13 @@ void TAnimModel::RaAnimate( unsigned int const Framestamp ) {
auto &timer { m_lighttimers[ idx ] };
if( ( modeintegral < ls_Blink ) && ( modefractional < 0.01f ) ) {
// simple flip modes
auto const transitiontime { (
m_transition ?
std::min(
1.f,
std::min( fOnTime, fOffTime ) * 0.9f ) :
0.01f ) };

switch( mode ) {
case ls_Off: {
// reduce to zero
Expand All @@ -437,14 +444,14 @@ void TAnimModel::RaAnimate( unsigned int const Framestamp ) {
}
case ls_On: {
// increase to max value
timer = std::min<float>( fTransitionTime, timer + timedelta );
timer = std::min<float>( transitiontime, timer + timedelta );
break;
}
default: {
break;
}
}
opacity = timer / fTransitionTime;
opacity = timer / transitiontime;
}
else {
// blink modes
Expand All @@ -458,10 +465,12 @@ void TAnimModel::RaAnimate( unsigned int const Framestamp ) {
( mode == ls_Off ) ? ontime :
( mode == ls_On ) ? ( fOnTime + fOffTime ) - ontime :
fOffTime ) }; // fallback
auto const transitiontime {
std::min(
1.f,
std::min( ontime, offtime ) * 0.9f ) };
auto const transitiontime { (
m_transition ?
std::min(
1.f,
std::min( ontime, offtime ) * 0.9f ) :
0.01f ) };

timer = clamp_circular<float>( timer + timedelta * ( lsLights[ idx ] > 0.f ? 1.f : -1.f ), ontime + offtime );
// set opacity depending on blink stage
Expand Down Expand Up @@ -600,6 +609,11 @@ std::optional<std::tuple<float, float, std::optional<glm::vec3>> > TAnimModel::L
return std::make_tuple(lsLights[n], m_lightopacities[n], color);
}

void TAnimModel::SkinSet( int const Index, material_handle const Material ) {

m_materialdata.replacable_skins[ clamp( Index, 1, 4 ) ] = Material;
}

void TAnimModel::AnimUpdate(double dt)
{ // wykonanie zakolejkowanych animacji, nawet gdy modele nie są aktualnie wyświetlane
acAnimList.remove_if([](std::weak_ptr<TAnimContainer> ptr)
Expand Down Expand Up @@ -660,20 +674,29 @@ TAnimModel::export_as_text_( std::ostream &Output ) const {
// texture
auto texturefile { (
m_materialdata.replacable_skins[ 1 ] != null_handle ?
GfxRenderer.Material( m_materialdata.replacable_skins[ 1 ] ).name :
GfxRenderer->Material( m_materialdata.replacable_skins[ 1 ] ).name :
"none" ) };
if( texturefile.find( szTexturePath ) == 0 ) {
// don't include 'textures/' in the path
texturefile.erase( 0, std::string{ szTexturePath }.size() );
}
Output << texturefile << ' ';
if( texturefile.find( ' ' ) == std::string::npos ) {
Output << texturefile << ' ';
}
else {
Output << "\"" << texturefile << "\"" << ' ';
}
// light submodels activation configuration
if( iNumLights > 0 ) {
Output << "lights ";
for( int lightidx = 0; lightidx < iNumLights; ++lightidx ) {
Output << lsLights[ lightidx ] << ' ';
}
}
// potential light transition switch
if( false == m_transition ) {
Output << "notransition" << ' ';
}
// footer
Output
<< "endmodel"
Expand Down
7 changes: 6 additions & 1 deletion AnimModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class TAnimContainer : std::enable_shared_from_this<TAnimContainer>
class TAnimModel : public scene::basic_node {

friend opengl_renderer;
friend opengl33_renderer;
friend itemproperties_panel;

public:
Expand All @@ -116,6 +117,7 @@ class TAnimModel : public scene::basic_node {
std::shared_ptr<TAnimContainer> AddContainer(std::string const &Name);
std::shared_ptr<TAnimContainer> GetContainer(std::string const &Name = "");
void LightSet( int const n, float const v );
void SkinSet( int const Index, material_handle const Material );
std::optional<std::tuple<float, float, std::optional<glm::vec3> > > LightGet( int const n );
int TerrainCount();
TSubModel * TerrainSquare(int n);
Expand Down Expand Up @@ -155,6 +157,8 @@ class TAnimModel : public scene::basic_node {
void deserialize_( std::istream &Input );
// export() subclass details, sends basic content of the class in legacy (text) format to provided stream
void export_as_text_( std::ostream &Output ) const;
// checks whether provided token is a legacy (text) format keyword
bool is_keyword( std::string const &Token ) const;

// members
std::shared_ptr<TAnimContainer> pRoot; // pojemniki sterujące, tylko dla aniomowanych submodeli
Expand All @@ -173,7 +177,8 @@ class TAnimModel : public scene::basic_node {
std::array<float, iMaxNumLights> m_lightopacities; // {1} in constructor
float fOnTime { 1.f / 2 };// { 60.f / 45.f / 2 };
float fOffTime { 1.f / 2 };// { 60.f / 45.f / 2 }; // były stałymi, teraz mogą być zmienne dla każdego egzemplarza
float fTransitionTime { fOnTime * 0.9f }; // time
// float fTransitionTime { fOnTime * 0.9f }; // time
bool m_transition { true }; // smooth transition between light states
unsigned int m_framestamp { 0 }; // id of last rendered gfx frame
};

Expand Down
3 changes: 2 additions & 1 deletion Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ obtain one at
#include "DynObj.h"
#include "Console.h"
#include "Logs.h"
#include "opengl33renderer.h"
#include "renderer.h"

void TButton::Clear(int i)
{
Expand Down Expand Up @@ -124,6 +124,7 @@ TButton::Turn( bool const State ) {
}

void TButton::Update( bool const Power ) {
// TODO: remove passing manually power state when LD is in place

auto const state { Power && ( bData ? *bData : m_state ) };

Expand Down
43 changes: 35 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ if (APPLE)
endif()

option(USE_IMGUI_GL3 "Use OpenGL3+ imgui implementation" ON)
option(WITH_OPENGL_MODERN "Compile with OpenGL modern renderer" ON)
option(WITH_OPENGL_LEGACY "Compile with OpenGL legacy renderer" ON)
option(WITH_UART "Compile with libserialport" ON)
option(WITH_OPENVR "Compile with OpenVR" ON)
option(WITH_ZMQ "Compile with cppzmq" ON)
Expand Down Expand Up @@ -74,7 +76,7 @@ set(SOURCES
"Model3d.cpp"
"mtable.cpp"
"parser.cpp"
"opengl33renderer.cpp"
"renderer.cpp"
"PyInt.cpp"
"ResourceManager.cpp"
"sn_utils.cpp"
Expand All @@ -83,7 +85,7 @@ set(SOURCES
"sun.cpp"
"stars.cpp"
"lightarray.cpp"
"opengl33skydome.cpp"
"skydome.cpp"
"sound.cpp"
"Spring.cpp"
"frustum.cpp"
Expand All @@ -93,7 +95,6 @@ set(SOURCES
"command.cpp"
"keyboardinput.cpp"
"gamepadinput.cpp"
"opengl33geometrybank.cpp"
"drivermouseinput.cpp"
"translation.cpp"
"material.cpp"
Expand Down Expand Up @@ -127,12 +128,17 @@ set(SOURCES
"scenenodegroups.cpp"
"simulationenvironment.cpp"
"simulationstateserializer.cpp"
"opengl33precipitation.cpp"
"precipitation.cpp"
"pythonscreenviewer.cpp"
"dictionary.cpp"
"opengl33particles.cpp"
"particles.cpp"
"headtrack.cpp"
"headtrack.h"
"ladderlogic.cpp"
"geometrybank.cpp"
"openglcolor.cpp"
"simulationsounds.cpp"
"openglcamera.cpp"

"network/network.cpp"
"network/message.cpp"
Expand Down Expand Up @@ -202,6 +208,27 @@ if (WITH_OPENVR)
set(SOURCES ${SOURCES} "vr/openvr_imp.cpp" "vr/vr_interface.cpp")
endif()

if (WITH_OPENGL_MODERN)
set(SOURCES ${SOURCES}
"opengl33geometrybank.cpp"
"opengl33light.cpp"
"opengl33skydome.cpp"
"opengl33precipitation.cpp"
"opengl33particles.cpp"
"opengl33renderer.cpp")
add_definitions(-DWITH_OPENGL_MODERN)
endif()

if (WITH_OPENGL_LEGACY)
set(SOURCES ${SOURCES}
"openglgeometrybank.cpp"
"opengllight.cpp"
"openglskydome.cpp"
"openglprecipitation.cpp"
"openglparticles.cpp"
"openglrenderer.cpp")
add_definitions(-DWITH_OPENGL_LEGACY)
endif()

if (USE_VSDEV_CAMERA)
add_definitions(-DUSE_VSDEV_CAMERA)
Expand Down Expand Up @@ -334,6 +361,6 @@ endif()
#target_compile_options(${PROJECT_NAME} PRIVATE -flto)
#target_link_libraries(${PROJECT_NAME} -flto)

set_target_properties(${PROJECT_NAME} PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "stdafx.h")
set_target_properties(${PROJECT_NAME} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
cotire(${PROJECT_NAME})
#set_target_properties(${PROJECT_NAME} PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "stdafx.h")
#set_target_properties(${PROJECT_NAME} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
#cotire(${PROJECT_NAME})
2 changes: 1 addition & 1 deletion CMake_modules/Findlibsndfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ find_library(LIBSNDFILE_LIBRARY
)

find_package(PackageHandleStandardArgs)
find_package_handle_standard_args(LibSndFile DEFAULT_MSG LIBSNDFILE_LIBRARY LIBSNDFILE_INCLUDE_DIR)
find_package_handle_standard_args(libsndfile DEFAULT_MSG LIBSNDFILE_LIBRARY LIBSNDFILE_INCLUDE_DIR)

if(LIBSNDFILE_FOUND)
set(LIBSNDFILE_LIBRARIES ${LIBSNDFILE_LIBRARY})
Expand Down
Loading

0 comments on commit 29f8f91

Please sign in to comment.