mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
changes for standalone e3d export
This commit is contained in:
@@ -72,6 +72,7 @@ set(SOURCES
|
||||
"dumb3d.cpp"
|
||||
"DynObj.cpp"
|
||||
"EU07.cpp"
|
||||
"export_e3d_standalone.cpp"
|
||||
"Event.cpp"
|
||||
"EvLaunch.cpp"
|
||||
"Float3d.cpp"
|
||||
@@ -87,6 +88,7 @@ set(SOURCES
|
||||
"Model3d.cpp"
|
||||
"mtable.cpp"
|
||||
"parser.cpp"
|
||||
"nullrenderer.cpp"
|
||||
"renderer.cpp"
|
||||
"PyInt.cpp"
|
||||
"ResourceManager.cpp"
|
||||
|
||||
19
EU07.cpp
19
EU07.cpp
@@ -22,13 +22,24 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others
|
||||
#include "Logs.h"
|
||||
#include <cstdlib>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
|
||||
#endif
|
||||
|
||||
void export_e3d_standalone(std::string in, std::string out, int flags, bool dynamic);
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// quick short-circuit for standalone e3d export
|
||||
if (argc == 6 && std::string(argv[1]) == "-e3d") {
|
||||
std::string in(argv[2]);
|
||||
std::string out(argv[3]);
|
||||
int flags = std::stoi(std::string(argv[4]));
|
||||
int dynamic = std::stoi(std::string(argv[5]));
|
||||
export_e3d_standalone(in, out, flags, dynamic);
|
||||
std::_Exit(0);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
auto result { Application.init( argc, argv ) };
|
||||
|
||||
@@ -487,8 +487,6 @@ global_settings::ConfigParse(cParser &Parser) {
|
||||
// tworzenie plików binarnych
|
||||
Parser.getTokens(1, false);
|
||||
Parser >> iConvertModels;
|
||||
// temporary override, to prevent generation of .e3d not compatible with old exe
|
||||
iConvertModels = (iConvertModels > 128 ? iConvertModels - 128 : 0);
|
||||
}
|
||||
else if (token == "file.binary.terrain")
|
||||
{
|
||||
@@ -1266,7 +1264,7 @@ global_settings::export_as_text( std::ostream &Output ) const {
|
||||
export_as_text( Output, "timespeed", fTimeSpeed );
|
||||
export_as_text( Output, "multisampling", iMultisampling );
|
||||
export_as_text( Output, "latitude", fLatitudeDeg );
|
||||
export_as_text( Output, "convertmodels", iConvertModels + ( iConvertModels > 0 ? 128 : 0 ) );
|
||||
export_as_text( Output, "convertmodels", iConvertModels );
|
||||
export_as_text( Output, "file.binary.terrain", file_binary_terrain );
|
||||
export_as_text( Output, "inactivepause", bInactivePause );
|
||||
export_as_text( Output, "slowmotion", iSlowMotionMask );
|
||||
|
||||
@@ -75,6 +75,7 @@ struct global_settings {
|
||||
int iWriteLogEnabled{ 3 }; // maska bitowa: 1-zapis do pliku, 2-okienko, 4-nazwy torów
|
||||
bool MultipleLogs{ false };
|
||||
unsigned int DisabledLogTypes{ 0 };
|
||||
bool ParserLogIncludes{ false };
|
||||
// simulation
|
||||
bool RealisticControlMode{ false }; // controls ability to steer the vehicle from outside views
|
||||
bool bEnableTraction{ true };
|
||||
|
||||
4
Logs.cpp
4
Logs.cpp
@@ -103,12 +103,14 @@ void WriteLog( const char *str, logtype const Type ) {
|
||||
}
|
||||
}
|
||||
|
||||
// Ra: bezwarunkowa rejestracja poważnych błędów
|
||||
void ErrorLog( const char *str, logtype const Type ) {
|
||||
|
||||
if( str == nullptr ) { return; }
|
||||
if( true == TestFlag( Global.DisabledLogTypes, static_cast<unsigned int>( Type ) ) ) { return; }
|
||||
|
||||
if (!(Global.iWriteLogEnabled & 1))
|
||||
return;
|
||||
|
||||
if (!errors.is_open()) {
|
||||
|
||||
std::string const filename =
|
||||
|
||||
@@ -2277,7 +2277,7 @@ void TModel3d::Init()
|
||||
Root->m_boundingradius = std::max( Root->m_boundingradius, root->m_boundingradius );
|
||||
}
|
||||
|
||||
if( ( Global.iConvertModels > 0 )
|
||||
if( ( Global.iConvertModels & 1 )
|
||||
&& ( false == asBinary.empty() ) ) {
|
||||
SaveToBinFile( asBinary );
|
||||
asBinary = ""; // zablokowanie powtórnego zapisu
|
||||
|
||||
17
export_e3d_standalone.cpp
Normal file
17
export_e3d_standalone.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "Model3d.h"
|
||||
#include "Globals.h"
|
||||
#include "renderer.h"
|
||||
|
||||
void export_e3d_standalone(std::string in, std::string out, int flags, bool dynamic)
|
||||
{
|
||||
Global.iConvertModels = flags;
|
||||
Global.iWriteLogEnabled = 2;
|
||||
Global.ParserLogIncludes = true;
|
||||
GfxRenderer = gfx_renderer_factory::get_instance()->create("null");
|
||||
TModel3d model;
|
||||
model.LoadFromTextFile(in, dynamic);
|
||||
model.Init();
|
||||
model.SaveToBinFile(out);
|
||||
}
|
||||
9
nullrenderer.cpp
Normal file
9
nullrenderer.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "stdafx.h"
|
||||
#include "nullrenderer.h"
|
||||
|
||||
std::unique_ptr<gfx_renderer> null_renderer::create_func()
|
||||
{
|
||||
return std::unique_ptr<null_renderer>(new null_renderer());
|
||||
}
|
||||
|
||||
bool null_renderer::renderer_register = gfx_renderer_factory::get_instance()->register_backend("null", null_renderer::create_func);
|
||||
156
nullrenderer.h
Normal file
156
nullrenderer.h
Normal file
@@ -0,0 +1,156 @@
|
||||
/* 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/. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Texture.h"
|
||||
#include "geometrybank.h"
|
||||
#include "material.h"
|
||||
#include "renderer.h"
|
||||
#include "stdafx.h"
|
||||
#include <glm/fwd.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
class null_geometrybank : public gfx::geometry_bank {
|
||||
public:
|
||||
// constructors:
|
||||
null_geometrybank() = default;
|
||||
// destructor
|
||||
~null_geometrybank() {};
|
||||
|
||||
private:
|
||||
// methods:
|
||||
// create() subclass details
|
||||
void
|
||||
create_( gfx::geometry_handle const &Geometry ) override {}
|
||||
// replace() subclass details
|
||||
void
|
||||
replace_( gfx::geometry_handle const &Geometry ) override {}
|
||||
// draw() subclass details
|
||||
auto
|
||||
draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) -> std::size_t override { return 0; }
|
||||
// release() subclass details
|
||||
void
|
||||
release_() override {}
|
||||
};
|
||||
|
||||
// bare-bones render controller, in lack of anything better yet
|
||||
class null_renderer : public gfx_renderer {
|
||||
|
||||
public:
|
||||
// types
|
||||
// constructors
|
||||
null_renderer() = default;
|
||||
// destructor
|
||||
~null_renderer() { }
|
||||
// methods
|
||||
bool
|
||||
Init( GLFWwindow *Window ) override { return true; }
|
||||
// main draw call. returns false on error
|
||||
bool
|
||||
Render() override { return true; }
|
||||
void
|
||||
SwapBuffers() override {}
|
||||
inline
|
||||
float
|
||||
Framerate() override { return 10.0f; }
|
||||
|
||||
bool AddViewport(const global_settings::extraviewport_config &conf) override { return false; }
|
||||
bool Debug_Ui_State(std::optional<bool>) override { return false; }
|
||||
void Shutdown() override {}
|
||||
|
||||
// geometry methods
|
||||
// NOTE: hands-on geometry management is exposed as a temporary measure; ultimately all visualization data should be generated/handled automatically by the renderer itself
|
||||
// creates a new geometry bank. returns: handle to the bank or NULL
|
||||
gfx::geometrybank_handle
|
||||
Create_Bank() override { return m_geometry.register_bank(std::make_unique<null_geometrybank>()); }
|
||||
// creates a new indexed geometry chunk of specified type from supplied data, in specified bank. returns: handle to the chunk or NULL
|
||||
gfx::geometry_handle
|
||||
Insert( gfx::index_array &Indices, gfx::vertex_array &Vertices, gfx::geometrybank_handle const &Geometry, int const Type ) override { return m_geometry.create_chunk( Indices, Vertices, Geometry, Type ); }
|
||||
// creates a new geometry chunk of specified type from supplied data, in specified bank. returns: handle to the chunk or NULL
|
||||
gfx::geometry_handle
|
||||
Insert( gfx::vertex_array &Vertices, gfx::geometrybank_handle const &Geometry, int const Type ) override {
|
||||
gfx::calculate_tangents(Vertices, gfx::index_array(), Type);
|
||||
|
||||
return m_geometry.create_chunk(Vertices, Geometry, Type);
|
||||
}
|
||||
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
|
||||
bool
|
||||
Replace( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, int const Type, std::size_t const Offset = 0 ) override {
|
||||
gfx::calculate_tangents(Vertices, gfx::index_array(), Type);
|
||||
|
||||
return m_geometry.replace(Vertices, Geometry, Offset);
|
||||
}
|
||||
// adds supplied vertex data at the end of specified chunk
|
||||
bool
|
||||
Append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, int const Type ) override {
|
||||
gfx::calculate_tangents(Vertices, gfx::index_array(), Type);
|
||||
|
||||
return m_geometry.append(Vertices, Geometry);
|
||||
}
|
||||
// provides direct access to index data of specfied chunk
|
||||
gfx::index_array const &
|
||||
Indices( gfx::geometry_handle const &Geometry ) const override { return m_geometry.indices(Geometry); }
|
||||
// provides direct access to vertex data of specfied chunk
|
||||
gfx::vertex_array const &
|
||||
Vertices( gfx::geometry_handle const &Geometry ) const override { return m_geometry.vertices(Geometry); }
|
||||
// material methods
|
||||
material_handle
|
||||
Fetch_Material( std::string const &Filename, bool const Loadnow = true ) override {
|
||||
m_materials.push_back(std::make_shared<opengl_material>());
|
||||
m_materials.back()->name = Filename;
|
||||
return m_materials.size();
|
||||
}
|
||||
void
|
||||
Bind_Material( material_handle const Material, TSubModel const *sm = nullptr, lighting_data const *lighting = nullptr ) override {}
|
||||
opengl_material const &
|
||||
Material( material_handle const Material ) const override { return *m_materials.at(Material - 1); }
|
||||
// shader methods
|
||||
auto Fetch_Shader( std::string const &name ) -> std::shared_ptr<gl::program> override { throw std::runtime_error("not impl"); }
|
||||
// texture methods
|
||||
texture_handle
|
||||
Fetch_Texture( std::string const &Filename, bool const Loadnow = true, GLint format_hint = GL_SRGB_ALPHA ) override { throw std::runtime_error("not impl"); }
|
||||
void
|
||||
Bind_Texture( texture_handle const Texture ) override {}
|
||||
void
|
||||
Bind_Texture( std::size_t const Unit, texture_handle const Texture ) override {}
|
||||
opengl_texture &
|
||||
Texture( texture_handle const Texture ) override { throw std::runtime_error("not impl"); }
|
||||
opengl_texture const &
|
||||
Texture( texture_handle const Texture ) const override { throw std::runtime_error("not impl"); }
|
||||
// utility methods
|
||||
void
|
||||
Pick_Control_Callback( std::function<void( TSubModel const *, const glm::vec2 )> Callback ) override {}
|
||||
void
|
||||
Pick_Node_Callback( std::function<void( scene::basic_node * )> Callback ) override {}
|
||||
TSubModel const *
|
||||
Pick_Control() const override { return nullptr; }
|
||||
scene::basic_node const *
|
||||
Pick_Node() const override { return nullptr; }
|
||||
glm::dvec3
|
||||
Mouse_Position() const override { return glm::dvec3(); }
|
||||
// maintenance methods
|
||||
void
|
||||
Update( double const Deltatime ) override {}
|
||||
void
|
||||
Update_Pick_Control() override {}
|
||||
void
|
||||
Update_Pick_Node() override {}
|
||||
glm::dvec3
|
||||
Update_Mouse_Position() override { return glm::dvec3(); }
|
||||
// debug methods
|
||||
std::string const &
|
||||
info_times() const override { return empty_str; }
|
||||
std::string const &
|
||||
info_stats() const override { return empty_str; }
|
||||
|
||||
static std::unique_ptr<gfx_renderer> create_func();
|
||||
|
||||
static bool renderer_register;
|
||||
|
||||
private:
|
||||
std::string empty_str;
|
||||
gfx::geometrybank_manager m_geometry;
|
||||
std::vector<std::shared_ptr<opengl_material>> m_materials;
|
||||
};
|
||||
@@ -7,6 +7,7 @@ obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "Globals.h"
|
||||
#include "stdafx.h"
|
||||
#include "parser.h"
|
||||
#include "utilities.h"
|
||||
@@ -250,6 +251,8 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
|
||||
if( ( true == LoadTraction )
|
||||
|| ( ( false == contains( includefile, "tr/" ) )
|
||||
&& ( false == contains( includefile, "tra/" ) ) ) ) {
|
||||
if (Global.ParserLogIncludes)
|
||||
WriteLog("including: " + includefile);
|
||||
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( *this ) );
|
||||
mIncludeParser->autoclear( m_autoclear );
|
||||
if( mIncludeParser->mSize <= 0 ) {
|
||||
@@ -270,6 +273,8 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
|
||||
if( ( true == LoadTraction )
|
||||
|| ( ( false == contains( includefile, "tr/" ) )
|
||||
&& ( false == contains( includefile, "tra/" ) ) ) ) {
|
||||
if (Global.ParserLogIncludes)
|
||||
WriteLog("including: " + includefile);
|
||||
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( includeparser ) );
|
||||
mIncludeParser->autoclear( m_autoclear );
|
||||
if( mIncludeParser->mSize <= 0 ) {
|
||||
|
||||
Reference in New Issue
Block a user