mirror of
https://github.com/WiVRn/WiVRn.git
synced 2026-11-20 00:51:32 -08:00
138 lines
3.5 KiB
C++
138 lines
3.5 KiB
C++
/*
|
|
* WiVRn VR streaming
|
|
* Copyright (C) 2022 Guillaume Meunier <[email protected]>
|
|
* Copyright (C) 2022 Patrick Nicolas <[email protected]>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "application.h"
|
|
#include "scenes/lobby.h"
|
|
#include "spdlog/spdlog.h"
|
|
#include "utils/env.h"
|
|
#include "version.h"
|
|
|
|
#include <algorithm>
|
|
#include <arpa/inet.h>
|
|
#include <netdb.h>
|
|
#include <string>
|
|
#include <sys/socket.h>
|
|
#include <sys/types.h>
|
|
|
|
#ifdef __ANDROID__
|
|
#include "spdlog/sinks/android_sink.h"
|
|
#include <android/native_window.h>
|
|
#include <android_native_app_glue.h>
|
|
#else
|
|
#include "spdlog/sinks/stdout_color_sinks.h"
|
|
#endif
|
|
|
|
#ifdef __ANDROID__
|
|
void real_main(android_app * native_app)
|
|
#else
|
|
void real_main(int argc, char ** argv)
|
|
#endif
|
|
{
|
|
auto log_level = env<std::string>("loglevel");
|
|
if (log_level)
|
|
{
|
|
std::transform(log_level->begin(), log_level->end(), log_level->begin(), [](char c) { return tolower(c); });
|
|
if (log_level == "trace")
|
|
spdlog::set_level(spdlog::level::trace);
|
|
else if (log_level == "debug")
|
|
spdlog::set_level(spdlog::level::debug);
|
|
else if (log_level == "info")
|
|
spdlog::set_level(spdlog::level::info);
|
|
else if (log_level == "warning")
|
|
spdlog::set_level(spdlog::level::warn);
|
|
else if (log_level == "error")
|
|
spdlog::set_level(spdlog::level::err);
|
|
else if (log_level == "critical")
|
|
spdlog::set_level(spdlog::level::critical);
|
|
else if (log_level == "off")
|
|
spdlog::set_level(spdlog::level::off);
|
|
else
|
|
spdlog::warn("Invalid value for log level: {}", *log_level);
|
|
}
|
|
|
|
if (wivrn::is_tag)
|
|
spdlog::info("Starting WiVRn version {}", wivrn::display_version());
|
|
else
|
|
spdlog::info("Starting WiVRn version {} ({})", wivrn::display_version(), wivrn::git_commit);
|
|
try
|
|
{
|
|
application_info info;
|
|
#ifdef __ANDROID__
|
|
info.native_app = native_app;
|
|
#endif
|
|
info.name = "WiVRn";
|
|
info.version = VK_MAKE_VERSION(1, 0, 0);
|
|
application app(info);
|
|
|
|
#ifndef __ANDROID__
|
|
if (argc == 2)
|
|
app.set_server_uri(argv[1]);
|
|
#endif
|
|
|
|
app.push_scene<scenes::lobby>();
|
|
|
|
app.run();
|
|
}
|
|
catch (std::exception & e)
|
|
{
|
|
spdlog::error("Caught exception: \"{}\"", e.what());
|
|
}
|
|
catch (...)
|
|
{
|
|
spdlog::error("Caught unknown exception");
|
|
}
|
|
|
|
#ifdef __ANDROID__
|
|
ANativeActivity_finish(native_app->activity);
|
|
|
|
// Read all pending events.
|
|
while (!native_app->destroyRequested)
|
|
{
|
|
int events;
|
|
struct android_poll_source * source;
|
|
|
|
while (ALooper_pollOnce(100, nullptr, &events, (void **)&source) >= 0)
|
|
{
|
|
// Process this event.
|
|
if (source != nullptr)
|
|
source->process(native_app, source);
|
|
}
|
|
}
|
|
exit(0);
|
|
#endif
|
|
}
|
|
|
|
#ifdef __ANDROID__
|
|
void android_main(android_app * native_app)
|
|
{
|
|
static auto logger = spdlog::android_logger_mt("WiVRn", "WiVRn");
|
|
|
|
spdlog::set_default_logger(logger);
|
|
|
|
real_main(native_app);
|
|
}
|
|
#else
|
|
int main(int argc, char * argv[])
|
|
{
|
|
spdlog::set_default_logger(spdlog::stdout_color_mt("WiVRn"));
|
|
|
|
real_main(argc, argv);
|
|
}
|
|
#endif
|