Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
Main.cpp
1/*
2Copyright (C) 2016,2019,2021,2022,2025 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#include <iostream>
17#include <unordered_map>
18#include <functional>
19#include <memory>
20
21#ifdef _MSC_VER
22#pragma warning( push )
23#pragma warning( disable : PROTOBUF_WARNINGS )
24#endif
25#include <google/protobuf/text_format.h>
26#ifdef _MSC_VER
27#pragma warning( pop )
28#endif
29
30#include <cassert>
31#include <cstdint>
32#include "Convert.h"
33#include "Pack.h"
34#include "Base64.h"
35#include "PipelineTool.h"
36
37int main ( int argc, char *argv[] )
38{
39 GOOGLE_PROTOBUF_VERIFY_VERSION;
40 std::unordered_map<std::string, std::function<std::unique_ptr<AeonGames::Tool>() > > ToolFactories
41 {
42 { "convert", [] { return std::make_unique<AeonGames::Convert>(); } },
43 { "pack", [] { return std::make_unique<AeonGames::Pack>(); } },
44 { "base64", [] { return std::make_unique<AeonGames::Base64>(); } },
45 { "pipeline", [] { return std::make_unique<AeonGames::PipelineTool>(); } },
46 };
47#ifdef _MSC_VER
48 _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
49#if 0
50 // Send all reports to STDOUT
51 _CrtSetReportMode ( _CRT_WARN, _CRTDBG_MODE_FILE );
52 _CrtSetReportFile ( _CRT_WARN, _CRTDBG_FILE_STDOUT );
53 _CrtSetReportMode ( _CRT_ERROR, _CRTDBG_MODE_FILE );
54 _CrtSetReportFile ( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
55 _CrtSetReportMode ( _CRT_ASSERT, _CRTDBG_MODE_FILE );
56 _CrtSetReportFile ( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
57#endif
58 // Use _CrtSetBreakAlloc( ) to set breakpoints on allocations.
59#endif
60 try
61 {
62 int retval = 0;
63 if ( argc >= 2 && ToolFactories.find ( argv[1] ) != ToolFactories.end() )
64 {
65 retval = ToolFactories[argv[1]]()->operator() ( argc, argv );
66 }
67 else
68 {
69 std::cout << "Usage: " << argv[0] << " <tool> [-help | ...]" << std::endl;
70 }
71 return retval;
72 }
73 catch ( const std::runtime_error &e )
74 {
75 std::cout << e.what() << std::endl;
76 }
77 catch ( ... )
78 {
79 std::cout << "Error: Unknown Exception caught." << std::endl;
80 }
81#if defined(__linux__) && GOOGLE_PROTOBUF_VERSION > 3006001
82 // protobuf 3.6.1 on Linux has a bug in the Shutdown code
83 google::protobuf::ShutdownProtobufLibrary();
84#endif
85 return -1;
86}