Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Landergame #264

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ OSP-MAGNUM.cbp
CMakeSettings.json
out/
.vs/
.vscode/
build/
.vscode/
2 changes: 1 addition & 1 deletion src/osp/util/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
#pragma once

#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
#include <spdlog/spdlog.h>

namespace osp
Expand Down
4 changes: 3 additions & 1 deletion src/testapp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ int main(int argc, char** argv)
// Command line argument parsing
Corrade::Utility::Arguments args;
args.addSkippedPrefix("magnum", "Magnum options")
.addOption("scene", "none") .setHelp("scene", "Set the scene to launch")
.addOption("scene", "lander") .setHelp("scene", "Set the scene to launch")
.addOption("config") .setHelp("config", "path to configuration file to use")
.addBooleanOption("norepl") .setHelp("norepl", "don't enter read, evaluate, print, loop.")
.addBooleanOption("log-exec") .setHelp("log-exec", "Log Task/Pipeline Execution (Extremely chatty!)")
Expand Down Expand Up @@ -298,6 +298,7 @@ void start_magnum_async(int argc, char** argv)
g_testApp.close_session(g_testApp.m_windowApp);

OSP_LOG_INFO("Closed Magnum Application");
std::exit(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm fairly certain we would want to keep the behavior of a "graceful" exit.

if that's not working, we should debug why and get it fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was for debugging something. Will remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, if I remove it and close the window it doesn't stop the application. So I think exiting here is more expected behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closing the window isn't supposed to exit the application in the current code.

Arguably that's not really what most people want, but it's what the current code was intended to do.

});
g_magnumThread.swap(t);
}
Expand All @@ -306,6 +307,7 @@ void load_a_bunch_of_stuff()
{
using namespace osp::restypes;
using namespace Magnum;
using namespace testapp::scenes;
using Primitives::ConeFlag;
using Primitives::CylinderFlag;

Expand Down
136 changes: 6 additions & 130 deletions src/testapp/scenarios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@

#include <algorithm>

#include "scenarios/lander.h"

using namespace adera;
using namespace osp;
using namespace osp::active;

namespace testapp
{

static void setup_magnum_draw(TestApp& rTestApp, Session const& scene, Session const& sceneRenderer, Session const& magnumScene);

// MaterialIds hints which shaders should be used to draw a DrawEnt
// DrawEnts can be assigned to multiple materials
static constexpr auto sc_matVisualizer = draw::MaterialId(0);
Expand Down Expand Up @@ -446,6 +446,10 @@ static ScenarioMap_t make_scenarios()
return setup_renderer;
});

using lander::setup_lander_scenario;

add_scenario("lander", "Lander simulation game", setup_lander_scenario);

return scenarioMap;
}

Expand All @@ -455,134 +459,6 @@ ScenarioMap_t const& scenarios()
return s_scenarioMap;
}


//-----------------------------------------------------------------------------


struct MainLoopSignals
{
PipelineId mainLoop;
PipelineId inputs;
PipelineId renderSync;
PipelineId renderResync;
PipelineId sceneUpdate;
PipelineId sceneRender;
};

/**
* @brief Runs Task/Pipeline main loop within MagnumApplication
*/
class CommonMagnumApp : public IOspApplication
{
public:
CommonMagnumApp(TestApp &rTestApp, MainLoopControl &rMainLoopCtrl, MainLoopSignals signals) noexcept
: m_rTestApp { rTestApp }
, m_rMainLoopCtrl { rMainLoopCtrl }
, m_signals { signals }
{ }

void run(MagnumApplication& rApp) override
{
// Start the main loop

PipelineId const mainLoop = m_rTestApp.m_application.get_pipelines<PlApplication>().mainLoop;
m_rTestApp.m_pExecutor->run(m_rTestApp, mainLoop);

// Resyncronize renderer

m_rMainLoopCtrl = MainLoopControl{
.doUpdate = false,
.doSync = true,
.doResync = true,
.doRender = false,
};

signal_all();

m_rTestApp.m_pExecutor->wait(m_rTestApp);
}

void draw(MagnumApplication& rApp, float delta) override
{
// Magnum Application's main loop calls this

m_rMainLoopCtrl = MainLoopControl{
.doUpdate = true,
.doSync = true,
.doResync = false,
.doRender = true,
};

signal_all();

m_rTestApp.m_pExecutor->wait(m_rTestApp);
}

void exit(MagnumApplication& rApp) override
{
m_rMainLoopCtrl = MainLoopControl{
.doUpdate = false,
.doSync = false,
.doResync = false,
.doRender = false,
};

signal_all();

m_rTestApp.m_pExecutor->wait(m_rTestApp);

if (m_rTestApp.m_pExecutor->is_running(m_rTestApp))
{
// Main loop must have stopped, but didn't!
m_rTestApp.m_pExecutor->wait(m_rTestApp);
std::abort();
}
}

private:

void signal_all()
{
m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.mainLoop);
m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.inputs);
m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.renderSync);
m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.renderResync);
m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.sceneUpdate);
m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.sceneRender);
}

TestApp &m_rTestApp;
MainLoopControl &m_rMainLoopCtrl;

MainLoopSignals m_signals;
};

void setup_magnum_draw(TestApp& rTestApp, Session const& scene, Session const& sceneRenderer, Session const& magnumScene)
{
OSP_DECLARE_GET_DATA_IDS(rTestApp.m_application, TESTAPP_DATA_APPLICATION);
OSP_DECLARE_GET_DATA_IDS(sceneRenderer, TESTAPP_DATA_SCENE_RENDERER);
OSP_DECLARE_GET_DATA_IDS(rTestApp.m_magnum, TESTAPP_DATA_MAGNUM);
OSP_DECLARE_GET_DATA_IDS(magnumScene, TESTAPP_DATA_MAGNUM_SCENE);

auto &rMainLoopCtrl = top_get<MainLoopControl> (rTestApp.m_topData, idMainLoopCtrl);
auto &rActiveApp = top_get<MagnumApplication>(rTestApp.m_topData, idActiveApp);
auto &rCamera = top_get<draw::Camera> (rTestApp.m_topData, idCamera);

rCamera.set_aspect_ratio(Vector2{Magnum::GL::defaultFramebuffer.viewport().size()});

MainLoopSignals const signals
{
.mainLoop = rTestApp.m_application .get_pipelines<PlApplication>() .mainLoop,
.inputs = rTestApp.m_windowApp .get_pipelines<PlWindowApp>() .inputs,
.renderSync = rTestApp.m_windowApp .get_pipelines<PlWindowApp>() .sync,
.renderResync = rTestApp.m_windowApp .get_pipelines<PlWindowApp>() .resync,
.sceneUpdate = scene .get_pipelines<PlScene>() .update,
.sceneRender = sceneRenderer .get_pipelines<PlSceneRenderer>() .render,
};

rActiveApp.set_osp_app( std::make_unique<CommonMagnumApp>(rTestApp, rMainLoopCtrl, signals) );
}

} // namespace testapp


7 changes: 0 additions & 7 deletions src/testapp/scenarios.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ namespace scenes
using enum EStgLink;
}

struct MainLoopControl
{
bool doUpdate;
bool doSync;
bool doResync;
bool doRender;
};

struct ScenarioOption
{
Expand Down
129 changes: 129 additions & 0 deletions src/testapp/scenarios/lander.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#include "lander.h"
#include "../testapp.h"
#include "../identifiers.h"
#include "../sessions/common.h"
#include "../sessions/magnum.h"
#include "../sessions/misc.h"
#include "../sessions/newton.h"
#include "../sessions/physics.h"
#include "../sessions/shapes.h"
#include "../sessions/terrain.h"
#include "../sessions/universe.h"
#include "../sessions/vehicles.h"
#include "../sessions/vehicles_machines.h"
#include "../sessions/vehicles_prebuilt.h"
#include "../scenarios.h"

#include <osp/tasks/top_utils.h>

#include <adera/activescene/vehicles_vb_fn.h>

namespace lander
{
// MaterialIds hints which shaders should be used to draw a DrawEnt
// DrawEnts can be assigned to multiple materials
static constexpr auto sc_matVisualizer = osp::draw::MaterialId(0);
static constexpr auto sc_matFlat = osp::draw::MaterialId(1);
static constexpr auto sc_matPhong = osp::draw::MaterialId(2);
static constexpr int sc_materialCount = 4;

RendererSetupFunc_t lander::setup_lander_scenario(TestApp &rTestApp)
{
#define SCENE_SESSIONS scene, commonScene, uniCore, uniScnFrame, uniPlanet, physics, \
prefabs, parts, signalsFloat, vehicleSpawn, vehicleSpawnVB, vehicles, \
newton, vehicleSpawnNwt, nwtRocketSet, rocketsNwt, \
machRocket, machRcsDriver
#define SCENE_SESSIONS_COUNT 18
#define RENDERER_SESSIONS sceneRenderer, magnumScene, planetDraw, \
cameraCtrl, cameraFree, shVisual, shFlat, shPhong, \
prefabDraw, vehicleDraw, vehicleCtrl, cameraVehicle
#define RENDERER_SESSIONS_COUNT 12

using namespace testapp::scenes;
using adera::ACtxVehicleSpawnVB;
using osp::top_get;
using osp::TopTaskBuilder;
using osp::active::ACtxVehicleSpawn;
using testapp::PlApplication;
// using osp::active::ad;

auto const defaultPkg = rTestApp.m_defaultPkg;
auto const application = rTestApp.m_application;
auto &rTopData = rTestApp.m_topData;

TopTaskBuilder builder{rTestApp.m_tasks, rTestApp.m_scene.m_edges, rTestApp.m_taskData};

auto &[SCENE_SESSIONS] = resize_then_unpack<SCENE_SESSIONS_COUNT>(rTestApp.m_scene.m_sessions);

scene = setup_scene(builder, rTopData, application);
commonScene = setup_common_scene(builder, rTopData, scene, application, defaultPkg);

auto const tgApp = application.get_pipelines<PlApplication>();
uniCore = setup_uni_core(builder, rTopData, tgApp.mainLoop);
uniScnFrame = setup_uni_sceneframe(builder, rTopData, uniCore);
uniPlanet = setup_uni_landerplanet(builder, rTopData, uniCore, uniScnFrame);

physics = setup_physics(builder, rTopData, scene, commonScene);
prefabs = setup_prefabs(builder, rTopData, application, scene, commonScene, physics);
parts = setup_parts(builder, rTopData, application, scene);
signalsFloat = setup_signals_float(builder, rTopData, scene, parts);
vehicleSpawn = setup_vehicle_spawn(builder, rTopData, scene);
vehicleSpawnVB = setup_vehicle_spawn_vb(builder, rTopData, application, scene, commonScene, prefabs, parts, vehicleSpawn, signalsFloat);
vehicles = setup_prebuilt_vehicles(builder, rTopData, application, scene);

machRocket = setup_mach_rocket(builder, rTopData, scene, parts, signalsFloat);
machRcsDriver = setup_mach_rcsdriver(builder, rTopData, scene, parts, signalsFloat);

newton = setup_newton(builder, rTopData, scene, commonScene, physics);
vehicleSpawnNwt = setup_vehicle_spawn_newton(builder, rTopData, application, commonScene, physics, prefabs, parts, vehicleSpawn, newton);
nwtRocketSet = setup_newton_factors(builder, rTopData);
rocketsNwt = setup_rocket_thrust_newton(builder, rTopData, scene, commonScene, physics, prefabs, parts, signalsFloat, newton, nwtRocketSet);

OSP_DECLARE_GET_DATA_IDS(vehicleSpawn, TESTAPP_DATA_VEHICLE_SPAWN);
OSP_DECLARE_GET_DATA_IDS(vehicleSpawnVB, TESTAPP_DATA_VEHICLE_SPAWN_VB);
OSP_DECLARE_GET_DATA_IDS(vehicles, TESTAPP_DATA_TEST_VEHICLES);

auto &rVehicleSpawn = top_get<ACtxVehicleSpawn>(rTopData, idVehicleSpawn);
auto &rVehicleSpawnVB = top_get<ACtxVehicleSpawnVB>(rTopData, idVehicleSpawnVB);
auto &rPrebuiltVehicles = top_get<PrebuiltVehicles>(rTopData, idPrebuiltVehicles);

rVehicleSpawn.spawnRequest.push_back(
{.position = {30.0f, 0.0f, 0.0f},
.velocity = {0.0f, 0.0f, 0.0f},
.rotation = {}});
rVehicleSpawnVB.dataVB.push_back(rPrebuiltVehicles[gc_pbvSimpleCommandServiceModule].get());

RendererSetupFunc_t const setup_renderer = [](TestApp &rTestApp) -> void
{
auto const application = rTestApp.m_application;
auto const windowApp = rTestApp.m_windowApp;
auto const magnum = rTestApp.m_magnum;
auto &rTopData = rTestApp.m_topData;

TopTaskBuilder builder{rTestApp.m_tasks, rTestApp.m_renderer.m_edges, rTestApp.m_taskData};

auto &[SCENE_SESSIONS] = unpack<SCENE_SESSIONS_COUNT>(rTestApp.m_scene.m_sessions);
auto &[RENDERER_SESSIONS] = resize_then_unpack<RENDERER_SESSIONS_COUNT>(rTestApp.m_renderer.m_sessions);

sceneRenderer = setup_scene_renderer(builder, rTopData, application, windowApp, commonScene);
create_materials(rTopData, sceneRenderer, sc_materialCount);

magnumScene = setup_magnum_scene(builder, rTopData, application, rTestApp.m_windowApp, sceneRenderer, rTestApp.m_magnum, scene, commonScene);
cameraCtrl = setup_camera_ctrl(builder, rTopData, windowApp, sceneRenderer, magnumScene);
// cameraFree = setup_camera_free (builder, rTopData, windowApp, scene, cameraCtrl);
shVisual = setup_shader_visualizer(builder, rTopData, windowApp, sceneRenderer, magnum, magnumScene, sc_matVisualizer);
// shFlat = setup_shader_flat (builder, rTopData, windowApp, sceneRenderer, magnum, magnumScene, sc_matFlat);
shPhong = setup_shader_phong(builder, rTopData, windowApp, sceneRenderer, magnum, magnumScene, sc_matPhong);
planetDraw = setup_landerplanet_draw(builder, rTopData, windowApp, sceneRenderer, cameraCtrl, commonScene, uniCore, uniScnFrame, uniPlanet, sc_matVisualizer, sc_matFlat);

prefabDraw = setup_prefab_draw(builder, rTopData, application, windowApp, sceneRenderer, commonScene, prefabs, sc_matPhong);
vehicleDraw = setup_vehicle_spawn_draw(builder, rTopData, sceneRenderer, vehicleSpawn);
vehicleCtrl = setup_vehicle_control(builder, rTopData, windowApp, scene, parts, signalsFloat);
cameraVehicle = setup_camera_vehicle(builder, rTopData, windowApp, scene, sceneRenderer, commonScene, physics, parts, cameraCtrl, vehicleCtrl);

setup_magnum_draw(rTestApp, scene, sceneRenderer, magnumScene);
};
return setup_renderer;
}

} // namespace lander
11 changes: 11 additions & 0 deletions src/testapp/scenarios/lander.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "../testapp.h"

namespace lander
{
using testapp::TestApp;

using RendererSetupFunc_t = void (*)(TestApp &);
using MagnumDrawFunc_t = void (*)(TestApp &, osp::Session const &, osp::Session const &, osp::Session const &);

RendererSetupFunc_t setup_lander_scenario(TestApp &rTestApp);
} // namespace lander
1 change: 1 addition & 0 deletions src/testapp/sessions/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
#include "common.h"
#include "../scenarios.h"
#include "magnum.h"

#include <adera/drawing/CameraController.h>
#include <osp/activescene/basic_fn.h>
Expand Down
Loading
Loading