16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-19 07:39:19 +02:00

Merge branch 'tmj-dev'

This commit is contained in:
milek7
2018-02-16 15:25:53 +01:00
113 changed files with 4617 additions and 4057 deletions

View File

@@ -11,8 +11,19 @@ http://mozilla.org/MPL/2.0/.
#include "material.h"
#include "renderer.h"
#include "usefull.h"
#include "Globals.h"
#include "utilities.h"
// helper, returns potential path part from provided file name
std::string path( std::string const &Filename )
{
std::string fn = Filename;
std::replace(fn.begin(), fn.end(), '\\', '/');
return (
fn.rfind( '/' ) != std::string::npos ?
fn.substr( 0, fn.rfind( '/' ) + 1 ) :
"" );
}
bool
opengl_material::deserialize( cParser &Input, bool const Loadnow ) {
@@ -33,43 +44,58 @@ opengl_material::deserialize( cParser &Input, bool const Loadnow ) {
// imports member data pair from the config file
bool
opengl_material::deserialize_mapping( cParser &Input, int const Priority, bool const Loadnow ) {
// token can be a key or block end
std::string const key { Input.getToken<std::string>( true, "\n\r\t ,;[]" ) };
if( false == Input.getTokens( 2, true, "\n\r\t;, " ) ) {
return false;
}
if( ( true == key.empty() ) || ( key == "}" ) ) { return false; }
std::string path;
if( name.rfind( '/' ) != std::string::npos ) {
path = name.substr( 0, name.rfind( '/' ) + 1 );
}
auto const value { Input.getToken<std::string>( true, "\n\r\t ,;" ) };
std::string key, value;
Input
>> key
>> value;
if( value == "{" ) {
// detect and optionally process config blocks
cParser blockparser( Input.getToken<std::string>( false, "}" ) );
if( key == Global::Season ) {
if( Priority != -1 ) {
// regular attribute processing mode
if( key == Global.Weather ) {
// weather textures override generic (pri 0) and seasonal (pri 1) textures
// seasonal weather textures (pri 1+2=3) override generic weather (pri 2) textures
while( true == deserialize_mapping( Input, Priority + 2, Loadnow ) ) {
; // all work is done in the header
}
}
else if( key == Global.Season ) {
// seasonal textures override generic textures
while( true == deserialize_mapping( blockparser, 1, Loadnow ) ) {
while( true == deserialize_mapping( Input, 1, Loadnow ) ) {
; // all work is done in the header
}
}
else if( key == "texture1:" ) {
if( ( texture1 == null_handle )
|| ( Priority > priority1 ) ) {
texture1 = GfxRenderer.Fetch_Texture( path( name ) + value, Loadnow );
priority1 = Priority;
}
}
else if( key == "texture2:" ) {
if( ( texture2 == null_handle )
|| ( Priority > priority2 ) ) {
texture2 = GfxRenderer.Fetch_Texture( path( name ) + value, Loadnow );
priority2 = Priority;
}
}
else if( value == "{" ) {
// unrecognized or ignored token, but comes with attribute block and potential further nesting
// go through it and discard the content
while( true == deserialize_mapping( Input, -1, Loadnow ) ) {
; // all work is done in the header
}
}
}
else if( key == "texture1:" ) {
// TODO: full-fledged priority system
if( ( texture1 == null_handle )
|| ( Priority > 0 ) ) {
texture1 = GfxRenderer.Fetch_Texture( path + value, Loadnow );
}
}
else if( key == "texture2:" ) {
// TODO: full-fledged priority system
if( ( texture2 == null_handle )
|| ( Priority > 0 ) ) {
texture2 = GfxRenderer.Fetch_Texture( path + value, Loadnow );
else {
// discard mode; ignores all retrieved tokens
if( value == "{" ) {
// ignored tokens can come with their own blocks, ignore these recursively
// go through it and discard the content
while( true == deserialize_mapping( Input, -1, Loadnow ) ) {
; // all work is done in the header
}
}
}