diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b723841c..0ce375b50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,6 +213,7 @@ set(SOURCES "input/drivermouseinput.cpp" "utilities/translation.cpp" "model/material.cpp" +"model/materialdata.cpp" "stdafx.cpp" "input/messaging.cpp" "scene/scene.cpp" diff --git a/application/editormode.cpp b/application/editormode.cpp index 4d858e325..1f8b2d224 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -21,6 +21,7 @@ http://mozilla.org/MPL/2.0/. #include "scene/scenenodegroups.h" #include "application/editoruilayer.h" #include "physics/mover.h" +#include "vehicle/DynObj.h" #ifndef _WIN32 #include #include diff --git a/input/drivermouseinput.cpp b/input/drivermouseinput.cpp index 35d8fbffe..468a51dc4 100644 --- a/input/drivermouseinput.cpp +++ b/input/drivermouseinput.cpp @@ -22,6 +22,7 @@ http://mozilla.org/MPL/2.0/. #include "utilities/Logs.h" #include "utilities/utilities.h" #include "physics/mover.h" +#include "vehicle/DynObj.h" auto const EU07_CONTROLLER_MOUSESLIDERSIZE{ 0.6 }; diff --git a/model/AnimModel.cpp b/model/AnimModel.cpp index 8553d63e5..5f538cdd8 100644 --- a/model/AnimModel.cpp +++ b/model/AnimModel.cpp @@ -24,6 +24,7 @@ http://mozilla.org/MPL/2.0/. #include "utilities/Timer.h" #include "utilities/Logs.h" #include "rendering/renderer.h" +#include "vehicle/DynObj.h" std::list> TAnimModel::acAnimList; diff --git a/model/AnimModel.h b/model/AnimModel.h index a66def742..8650165ba 100644 --- a/model/AnimModel.h +++ b/model/AnimModel.h @@ -17,7 +17,8 @@ http://mozilla.org/MPL/2.0/. #include "utilities/Classes.h" #include "utilities/Float3d.h" #include "model/Model3d.h" -#include "vehicle/DynObj.h" +#include "model/materialdata.h" +#include "utilities/Names.h" #include "scene/scenenode.h" const int iMaxNumLights = 8; diff --git a/model/materialdata.cpp b/model/materialdata.cpp new file mode 100644 index 000000000..8d026d71a --- /dev/null +++ b/model/materialdata.cpp @@ -0,0 +1,94 @@ +/* +This Source Code Form is subject to the +terms of the Mozilla Public License, v. +2.0. If a copy of the MPL was not +distributed with this file, You can +obtain one at +http://mozilla.org/MPL/2.0/. +*/ + +#include "stdafx.h" +#include "model/materialdata.h" + +#include "model/Texture.h" +#include "rendering/renderer.h" +#include "utilities/parser.h" +#include "utilities/utilities.h" +#include "utilities/Globals.h" + +// Ra 2015-01: sprawdzenie dostępności tekstury o podanej nazwie +std::string +TextureTest( std::string const &Name ) { + + auto const lookup { + FileExists( + { Global.asCurrentTexturePath + Name, Name, paths::textures + Name }, + { ".mat", ".dds", ".tga", ".ktx", ".png", ".bmp", ".jpg", ".tex" } ) }; + + return lookup.first + lookup.second; +} + +// assigns specified texture or a group of textures to replacable texture slots +void +material_data::assign( std::string const &Replacableskin ) { + + // a template puts its parameter after a folder ("tabl/(p6)"): a texture made by a script given there keeps its scheme + if( auto const scheme { Replacableskin.find( "/make:" ) }; + scheme != std::string::npos + && false == contains( Replacableskin, '|' ) ) { + assign( Replacableskin.substr( scheme + 1 ) ); + return; + } + // check for the pipe method first + if( contains( Replacableskin, '|' ) ) { + cParser nameparser( Replacableskin ); + nameparser.getTokens( 4, false, "|" ); + int skinindex = 0; + std::string texturename; nameparser >> texturename; + while( texturename != "" && skinindex < 4 ) { + replacable_skins[ skinindex + 1 ] = GfxRenderer->Fetch_Material( texturename ); + ++skinindex; + texturename = ""; nameparser >> texturename; + } + multi_textures = skinindex; + } + else { + // otherwise try the basic approach + int skinindex = 0; + do { + // test quietly for file existence so we don't generate tons of false errors in the log + // NOTE: this means actual missing files won't get reported which is hardly ideal, but still somewhat better + auto const material { TextureTest( ToLower( Replacableskin + "," + std::to_string( skinindex + 1 ) ) ) }; + if( true == material.empty() ) { break; } + + replacable_skins[ skinindex + 1 ] = GfxRenderer->Fetch_Material( material ); + ++skinindex; + } while( skinindex < 4 ); + multi_textures = skinindex; + if( multi_textures == 0 ) { + // zestaw nie zadziałał, próbujemy normanie + replacable_skins[ 1 ] = GfxRenderer->Fetch_Material( Replacableskin ); + } + } + if( replacable_skins[ 1 ] == null_handle ) { + // last ditch attempt, check for single replacable skin texture + replacable_skins[ 1 ] = GfxRenderer->Fetch_Material( Replacableskin ); + } + + // BUGS! it's not entierly designed whether opacity is property of material or submodel, + // and code does confusing things with this in various places + textures_alpha = GfxRenderer->Material(replacable_skins[1])->is_translucent() ? 0x31310031 : // tekstura -1 z kanałem alfa - nie renderować w cyklu nieprzezroczystych + 0x30300030; // wszystkie tekstury nieprzezroczyste - nie renderować w cyklu przezroczystych + if( GfxRenderer->Material( replacable_skins[ 2 ] )->is_translucent() ) { + // tekstura -2 z kanałem alfa - nie renderować w cyklu nieprzezroczystych + textures_alpha |= 0x02020002; + } + if( GfxRenderer->Material( replacable_skins[ 3 ] )->is_translucent() ) { + // tekstura -3 z kanałem alfa - nie renderować w cyklu nieprzezroczystych + textures_alpha |= 0x04040004; + } + if( GfxRenderer->Material( replacable_skins[ 4 ] )->is_translucent() ) { + // tekstura -4 z kanałem alfa - nie renderować w cyklu nieprzezroczystych + textures_alpha |= 0x08080008; + } +} diff --git a/model/materialdata.h b/model/materialdata.h new file mode 100644 index 000000000..e149e9e5e --- /dev/null +++ b/model/materialdata.h @@ -0,0 +1,30 @@ +/* +This Source Code Form is subject to the +terms of the Mozilla Public License, v. +2.0. If a copy of the MPL was not +distributed with this file, You can +obtain one at +http://mozilla.org/MPL/2.0/. +*/ + +// the replaceable skins of a model: the textures a vehicle or a scenery model puts in place of the replaceable ones + +#pragma once + +#include + +#include "interfaces/IMaterial.h" +#include "utilities/Classes.h" + +struct material_data { + + int textures_alpha{ 0x30300030 }; // maska przezroczystości tekstur. default: tekstury wymienne nie mają przezroczystości + material_handle replacable_skins[ 5 ] = { null_handle, null_handle, null_handle, null_handle, null_handle }; // McZapkie:zmienialne nadwozie + int multi_textures{ 0 }; //<0 tekstury wskazane wpisem, >0 tekstury z przecinkami, =0 jedna + + // assigns specified texture or a group of textures to replacable texture slots + void assign( std::string const &Replacableskin ); +}; + +// the file of the texture or the material of the given name, looked up as the models do; empty when there is none +std::string TextureTest( std::string const &Name ); diff --git a/rendering/common/scenewalkindirect.cpp b/rendering/common/scenewalkindirect.cpp index 85f54b699..e65606827 100644 --- a/rendering/common/scenewalkindirect.cpp +++ b/rendering/common/scenewalkindirect.cpp @@ -19,6 +19,7 @@ http://mozilla.org/MPL/2.0/. #include "model/Model3d.h" #include "utilities/Globals.h" #include "utilities/utilities.h" +#include "vehicle/DynObj.h" #include diff --git a/rendering/opengl46/opengl46renderer.cpp b/rendering/opengl46/opengl46renderer.cpp index 1bbeb17fe..f2e611859 100644 --- a/rendering/opengl46/opengl46renderer.cpp +++ b/rendering/opengl46/opengl46renderer.cpp @@ -30,6 +30,7 @@ http://mozilla.org/MPL/2.0/. #include "rendering/screenshot.h" #include "rendering/editoroverlay.h" #include "physics/mover.h" +#include "vehicle/DynObj.h" #include #include diff --git a/rendering/particles.cpp b/rendering/particles.cpp index 9879cba25..67d81f3c2 100644 --- a/rendering/particles.cpp +++ b/rendering/particles.cpp @@ -17,6 +17,7 @@ http://mozilla.org/MPL/2.0/. #include "utilities/Logs.h" #include "vehicle/smoke.h" #include "physics/mover.h" +#include "vehicle/DynObj.h" void diff --git a/rendering/vulkan14/vulkan14scene.cpp b/rendering/vulkan14/vulkan14scene.cpp index 75d580bb2..3a25e0fb4 100644 --- a/rendering/vulkan14/vulkan14scene.cpp +++ b/rendering/vulkan14/vulkan14scene.cpp @@ -24,6 +24,7 @@ http://mozilla.org/MPL/2.0/. #include "utilities/Logs.h" #include "utilities/color.h" #include "utilities/utilities.h" +#include "vehicle/DynObj.h" #include #include diff --git a/scene/scene.cpp b/scene/scene.cpp index c8272519f..bdcb3efb4 100644 --- a/scene/scene.cpp +++ b/scene/scene.cpp @@ -25,6 +25,7 @@ http://mozilla.org/MPL/2.0/. #include "widgets/map_objects.h" #include "vehicle/aiwire.h" #include "physics/mover.h" +#include "vehicle/DynObj.h" #include diff --git a/tests/unit/test_camera.cpp b/tests/unit/test_camera.cpp index 684fadb56..c0a75978d 100644 --- a/tests/unit/test_camera.cpp +++ b/tests/unit/test_camera.cpp @@ -9,6 +9,7 @@ #include "input/command.h" #include "utilities/Timer.h" #include "vehicle/Camera.h" +#include "vehicle/DynObj.h" // the view matrix of the camera (TCamera::SetMatrix): the pitch (Angle.x) and the yaw (Angle.y) give the line of sight, // the roll (Angle.z) turns the view about that line, wherever the camera looks. The roll comes from the sway of the cab diff --git a/utilities/Classes.h b/utilities/Classes.h index 89872d450..b8c470ec9 100644 --- a/utilities/Classes.h +++ b/utilities/Classes.h @@ -9,6 +9,8 @@ http://mozilla.org/MPL/2.0/. #ifndef ClassesH #define ClassesH + +#include "interfaces/ITexture.h" // null_handle, for the handles below //--------------------------------------------------------------------------- // Ra: zestaw klas do robienia wskaźników, aby uporządkować nagłówki //--------------------------------------------------------------------------- diff --git a/vehicle/Camera.h b/vehicle/Camera.h index 5e2f72810..a53aac497 100644 --- a/vehicle/Camera.h +++ b/vehicle/Camera.h @@ -10,7 +10,7 @@ http://mozilla.org/MPL/2.0/. #pragma once #include "input/command.h" -#include "vehicle/DynObj.h" +#include "utilities/Classes.h" //--------------------------------------------------------------------------- diff --git a/vehicle/DynObj.cpp b/vehicle/DynObj.cpp index 53a1680b0..5464570cb 100644 --- a/vehicle/DynObj.cpp +++ b/vehicle/DynObj.cpp @@ -78,18 +78,6 @@ GetSubmodelFromName( TModel3d * const Model, std::string const Name ) { return Model ? Model->GetFromName(Name) : nullptr; } -// Ra 2015-01: sprawdzenie dostępności tekstury o podanej nazwie -std::string -TextureTest( std::string const &Name ) { - - auto const lookup { - FileExists( - { Global.asCurrentTexturePath + Name, Name, paths::textures + Name }, - { ".mat", ".dds", ".tga", ".ktx", ".png", ".bmp", ".jpg", ".tex" } ) }; - - return lookup.first + lookup.second; -} - //--------------------------------------------------------------------------- void TAnimPant::common_pantograph_settings() { // wspólne ustawienia, liczone po przypisaniu wymiarów ramion @@ -258,72 +246,6 @@ void TAnim::Parovoz(){ */ -// assigns specified texture or a group of textures to replacable texture slots -void -material_data::assign( std::string const &Replacableskin ) { - - // a template puts its parameter after a folder ("tabl/(p6)"): a texture made by a script given there keeps its scheme - if( auto const scheme { Replacableskin.find( "/make:" ) }; - scheme != std::string::npos - && false == contains( Replacableskin, '|' ) ) { - assign( Replacableskin.substr( scheme + 1 ) ); - return; - } - // check for the pipe method first - if( contains( Replacableskin, '|' ) ) { - cParser nameparser( Replacableskin ); - nameparser.getTokens( 4, false, "|" ); - int skinindex = 0; - std::string texturename; nameparser >> texturename; - while( texturename != "" && skinindex < 4 ) { - replacable_skins[ skinindex + 1 ] = GfxRenderer->Fetch_Material( texturename ); - ++skinindex; - texturename = ""; nameparser >> texturename; - } - multi_textures = skinindex; - } - else { - // otherwise try the basic approach - int skinindex = 0; - do { - // test quietly for file existence so we don't generate tons of false errors in the log - // NOTE: this means actual missing files won't get reported which is hardly ideal, but still somewhat better - auto const material { TextureTest( ToLower( Replacableskin + "," + std::to_string( skinindex + 1 ) ) ) }; - if( true == material.empty() ) { break; } - - replacable_skins[ skinindex + 1 ] = GfxRenderer->Fetch_Material( material ); - ++skinindex; - } while( skinindex < 4 ); - multi_textures = skinindex; - if( multi_textures == 0 ) { - // zestaw nie zadziałał, próbujemy normanie - replacable_skins[ 1 ] = GfxRenderer->Fetch_Material( Replacableskin ); - } - } - if( replacable_skins[ 1 ] == null_handle ) { - // last ditch attempt, check for single replacable skin texture - replacable_skins[ 1 ] = GfxRenderer->Fetch_Material( Replacableskin ); - } - - // BUGS! it's not entierly designed whether opacity is property of material or submodel, - // and code does confusing things with this in various places - textures_alpha = GfxRenderer->Material(replacable_skins[1])->is_translucent() ? 0x31310031 : // tekstura -1 z kanałem alfa - nie renderować w cyklu nieprzezroczystych - 0x30300030; // wszystkie tekstury nieprzezroczyste - nie renderować w cyklu przezroczystych - if( GfxRenderer->Material( replacable_skins[ 2 ] )->is_translucent() ) { - // tekstura -2 z kanałem alfa - nie renderować w cyklu nieprzezroczystych - textures_alpha |= 0x02020002; - } - if( GfxRenderer->Material( replacable_skins[ 3 ] )->is_translucent() ) { - // tekstura -3 z kanałem alfa - nie renderować w cyklu nieprzezroczystych - textures_alpha |= 0x04040004; - } - if( GfxRenderer->Material( replacable_skins[ 4 ] )->is_translucent() ) { - // tekstura -4 z kanałem alfa - nie renderować w cyklu nieprzezroczystych - textures_alpha |= 0x08080008; - } -} - - namespace { // a luadestinationsign: or wasmdestinationsign: block, its script in the vehicle folder when it has no path of its own diff --git a/vehicle/DynObj.h b/vehicle/DynObj.h index b11ec9e84..1923e8889 100644 --- a/vehicle/DynObj.h +++ b/vehicle/DynObj.h @@ -14,6 +14,7 @@ http://mozilla.org/MPL/2.0/. #include "utilities/Classes.h" #include "interfaces/IMaterial.h" +#include "model/materialdata.h" #include "physics/vehicletypes.h" #include "physics/derailment.h" #include "vehicle/derailmotion.h" @@ -189,16 +190,6 @@ enum class announcement_t : int { }; // parameters for the material object, as currently used by various simulator models -struct material_data { - - int textures_alpha{ 0x30300030 }; // maska przezroczystości tekstur. default: tekstury wymienne nie mają przezroczystości - material_handle replacable_skins[ 5 ] = { null_handle, null_handle, null_handle, null_handle, null_handle }; // McZapkie:zmienialne nadwozie - int multi_textures{ 0 }; //<0 tekstury wskazane wpisem, >0 tekstury z przecinkami, =0 jedna - - // assigns specified texture or a group of textures to replacable texture slots - void assign( std::string const &Replacableskin ); -}; - class TDynamicObject { // klasa pojazdu friend opengl46_renderer; diff --git a/widgets/map.cpp b/widgets/map.cpp index d750bbb60..19b509814 100644 --- a/widgets/map.cpp +++ b/widgets/map.cpp @@ -8,6 +8,7 @@ #include "vehicle/Driver.h" #include "model/AnimModel.h" #include "application/application.h" +#include "vehicle/DynObj.h" ui::map_panel::map_panel() : ui_panel(STR_C("Map"), false) { diff --git a/widgets/trainingcard.cpp b/widgets/trainingcard.cpp index de46f9cd8..31434237f 100644 --- a/widgets/trainingcard.cpp +++ b/widgets/trainingcard.cpp @@ -3,6 +3,7 @@ #include "simulation/simulation.h" #include "utilities/utilities.h" #include "physics/mover.h" +#include "vehicle/DynObj.h" #ifdef __linux__ #include diff --git a/world/Sweep.h b/world/Sweep.h index b83b7fa12..365c599ac 100644 --- a/world/Sweep.h +++ b/world/Sweep.h @@ -20,7 +20,7 @@ http://mozilla.org/MPL/2.0/. #include "scene/scenenode.h" #include "world/Road.h" #include "world/Segment.h" -#include "vehicle/DynObj.h" +#include "model/materialdata.h" namespace scene {