62class RenderPassManager;
64class EnvironmentProbeComponent;
67struct ResourceDescriptorBase;
83 struct MemoryBarrierCommand;
87 class SceneProjectManager;
89 class SceneRenderPass;
93 class SceneEnvironmentProbeComponent;
100 std::array<I64, MAX_SELECTIONS>
_selections = create_array<MAX_SELECTIONS, I64>(-1);
117using PlayerList = eastl::array<Player_ptr, Config::MAX_LOCAL_PLAYER_COUNT>;
158 virtual ~Scene()
override;
161 [[nodiscard]]
bool idle();
166#pragma region Logic Loop
180#pragma region Task Management
186#pragma region Object Picking
197#pragma region Entity Management
206#pragma region Time Of Day
226#pragma region Player Camera
273#pragma region Save Load
282 [[nodiscard]]
virtual bool loadXML();
284 [[nodiscard]]
virtual bool load();
285 [[nodiscard]]
virtual bool unload();
286 [[nodiscard]]
virtual bool postLoad();
291#pragma region Player Management
342 std::array<SceneGraphNode*, Config::MAX_LOCAL_PLAYER_COUNT>
_flashLight;
360 return scene->loadComplete();
376 scene->
debugDraw(bufferInOut, memCmdInOut);
380 scene->
drawCustomUI(targetViewport, bufferInOut, memCmdInOut);
392 return scene->
load();
421 return scene->_GUI.get();
437 return scene->_envProbePool.get();
442 return scene->_scenePlayers;
452 return scene->_envProbePool.get();
469 return scene->
save(outputBuffer);
473 return scene->
load(inputBuffer);
485 return scene->
saveXML(msgCallback, finishCallback);
497 return scene->_envProbePool.get();
501 return scene->lightPool().get();
513 return scene->_GUI.get();
529#pragma region Scene Factory
545#define STRUCT_NAME(M) BOOST_PP_CAT(M, RegisterStruct)
546#define REGISTER_SCENE(SceneName) \
548static struct STRUCT_NAME(SceneName) { \
549 STRUCT_NAME(SceneName)() \
551 SceneList::registerScene(#SceneName, SceneList::SharedPtrFactory<SceneName>()); \
553} BOOST_PP_CAT(SceneName, RegisterVariable);
554#define BEGIN_SCENE(SceneName) \
555REGISTER_SCENE(SceneName); \
556class SceneName final : public Scene { \
558#define END_SCENE(SceneName) };
static void unregisterProbe(Scene *scene, const EnvironmentProbeComponent *const probe)
static void registerProbe(Scene *scene, EnvironmentProbeComponent *probe)
static SceneGUIElements * guiElements(Scene *scene) noexcept
static LightPool * getLightPool(Scene *scene) noexcept
static void onNodeDestroy(Scene *scene, SceneGraphNode *node)
static void addSceneGraphToLoad(Scene *scene, const XML::SceneNode &&rootNode)
static SceneEnvironmentProbePool * getEnvProbes(Scene *scene) noexcept
static bool saveXML(Scene *scene, const DELEGATE< void, std::string_view > &msgCallback, const DELEGATE< void, bool > &finishCallback)
static bool load(Scene *scene, ByteBuffer &inputBuffer)
static bool save(const Scene *scene, ByteBuffer &outputBuffer)
static bool saveNodeToXML(Scene *scene, const SceneGraphNode *node)
static bool loadNodeFromXML(Scene *scene, SceneGraphNode *node)
static bool onShutdown(PlatformContext &context)
static void postLoadMainThread(Scene *scene)
static void drawCustomUI(Scene *scene, const Rect< I32 > &targetViewport, GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
static bool resetSelection(Scene *scene, const PlayerIndex idx, const bool resetIfLocked)
static void onSetActive(Scene *scene)
static bool load(Scene *scene)
static bool frameEnded(Scene *scene)
static bool onStartup(PlatformContext &context)
static PlayerList & getPlayers(Scene *scene) noexcept
static bool loadComplete(Scene *scene) noexcept
static bool unload(Scene *scene)
static void onPlayerRemove(Scene *scene, const Player_ptr &player)
static void onPlayerAdd(Scene *scene, const Player_ptr &player)
static void onRemoveActive(Scene *scene)
static bool frameStarted(Scene *scene)
static SceneEnvironmentProbePool * getEnvProbes(Scene *scene) noexcept
static void currentPlayerPass(Scene *scene, const PlayerIndex idx)
static void debugDraw(Scene *scene, GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
static SceneGUIElements * gui(Scene *scene) noexcept
static void clearHoverTarget(Scene *scene, const Input::MouseMoveEvent &arg)
static void setSelected(Scene *scene, const PlayerIndex idx, const vector< SceneGraphNode * > &sgns, const bool recursive)
static SceneEnvironmentProbePool * getEnvProbes(Scene *scene) noexcept
Graphical User Interface.
IMPrimitive replaces immediate mode calls to VB based rendering.
PlatformContext & context() noexcept
virtual bool save(ByteBuffer &outputBuffer) const
PROPERTY_R(SceneGraph_uptr, sceneGraph)
static bool OnStartup(PlatformContext &context)
PROPERTY_R(LightPool_uptr, lightPool)
static I64 DEFAULT_SCENE_GUID
PROPERTY_R_IW(DayNightData, dayNightData)
void removeTask(const Task &task)
IMPrimitive * _linesPrimitive
void setSelected(PlayerIndex idx, const vector< SceneGraphNode * > &SGNs, bool recursive)
vec3< F32 > getSunPosition() const
virtual ~Scene() override
bool resetSelection(PlayerIndex idx, const bool resetIfLocked)
void updateSceneState(U64 deltaTimeUS)
Update animations, network data, sounds, triggers etc.
virtual void postLoadMainThread()
Gets called on the main thread when the scene finishes loading (e.g. used by the GUI system)
PROPERTY_R(SceneState_uptr, state)
Contains all game related info for the scene (wind speed, visibility ranges, etc)
std::array< Selections, Config::MAX_LOCAL_PLAYER_COUNT > _currentSelection
static ResourcePath GetSceneRootFolder(const Project &project)
Return the full path to the location of Scenes folder in the project (e.g. ./Projects/Foo/Scenes/ for...
const SimpleTime & getTimeOfDay() const noexcept
vector< size_t > _selectionCallbackIndices
Player * getPlayerForIndex(PlayerIndex idx) const
virtual void debugDraw(GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
Draw debug entities.
const Project & parent() const noexcept
PROPERTY_RW(bool, dayNightCycleEnabled, true)
U8 getSceneIndexForPlayer(PlayerIndex idx) const
std::array< U32, Config::MAX_LOCAL_PLAYER_COUNT > _cameraUpdateListeners
PROPERTY_R(SceneInput_uptr, input)
virtual bool frameEnded()
vector< TimerStruct > _taskTimers
bool findSelection(PlayerIndex idx, bool clearOld)
vector< TimerStruct > _guiTimers
virtual void drawCustomUI(const Rect< I32 > &targetViewport, GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
Draw custom ui elements.
void onNodeDestroy(SceneGraphNode *node)
PROPERTY_R_IW(U64, sceneRuntimeUS, 0ULL)
virtual void processTasks(U64 gameDeltaTimeUS, U64 appDeltaTimeUS)
Update the scene based on the inputs.
virtual void processGUI(U64 gameDeltaTimeUS, U64 appDeltaTimeUS)
void toggleFlashlight(PlayerIndex idx)
void addTaskTimer(TimerClass intervalClass, U64 intervalUS, DELEGATE< void, U64 > cbk)
void addGuiTimer(TimerClass intervalClass, U64 intervalUS, DELEGATE< void, U64 > cbk)
bool saveNodeToXML(const SceneGraphNode *node) const
void findHoverTarget(PlayerIndex idx, vec2< I32 > aimPos)
static ResourcePath GetSceneFullPath(const Scene &scene)
Return the full path to the scene's location on disk. It's equivalent to GetSceneRootFolder(scene....
static constexpr U32 SUN_LIGHT_TAG
std::array< SceneGraphNode *, Config::MAX_LOCAL_PLAYER_COUNT > _flashLight
vec3< F32 > getSunDirection() const
void updateSelectionData(PlayerIndex idx, DragSelectData &data)
virtual bool frameStarted()
void loadAsset(const Task *parentTask, const XML::SceneNode &sceneNode, SceneGraphNode *parent)
Atmosphere getCurrentAtmosphere() const noexcept
std::array< Selections, Config::MAX_LOCAL_PLAYER_COUNT > _tempSelection
virtual bool mouseMoved(const Input::MouseMoveEvent &arg)
Return true if input was consumed.
void addWater(SceneGraphNode *parentNode, const boost::property_tree::ptree &pt, const Str< 64 > &nodeName="")
SceneGraphNode * addParticleEmitter(const std::string_view name, std::shared_ptr< ParticleData > data, SceneGraphNode *parentNode)
bool updateCameraControls(PlayerIndex idx) const
Returns true if the camera was moved/rotated/etc.
virtual void onRemoveActive()
void removePlayerInternal(PlayerIndex idx)
void setCurrentAtmosphere(const Atmosphere &atmosphere) const noexcept
Project & parent() noexcept
virtual void onChangeFocus(bool hasFocus)
The application has lost or gained focus.
void onPlayerRemove(const Player_ptr &player)
PROPERTY_R(U8, playerCount, 0u)
const Selections & getCurrentSelection(const PlayerIndex index=0) const
void endDragSelection(PlayerIndex idx, bool clearSelection)
virtual void updateSceneStateInternal(U64 deltaTimeUS)
void addPlayerInternal(bool queue)
std::array< DragSelectData, Config::MAX_LOCAL_PLAYER_COUNT > _dragSelectData
SceneGraphNode * addInfPlane(SceneGraphNode *parentNode, const boost::property_tree::ptree &pt, const Str< 64 > &nodeName="")
const SimpleLocation & getGeographicLocation() const noexcept
void beginDragSelection(PlayerIndex idx, vec2< I32 > mousePos)
void addMusic(MusicType type, const std::string_view name, const ResourcePath &srcFile)
Camera * playerCamera(const bool skipOverride=false) const
PROPERTY_R(AI::AIManager_uptr, aiManager)
virtual void onSetActive()
virtual bool load(ByteBuffer &inputBuffer)
bool lockCameraToPlayerMouse(PlayerIndex index, bool lockState) const noexcept
U8 getPlayerIndexForDevice(U8 deviceIndex) const
void setTimeOfDay(const SimpleTime &time) noexcept
void setGeographicLocation(const SimpleLocation &location) noexcept
virtual bool saveXML(const DELEGATE< void, std::string_view > &msgCallback, const DELEGATE< void, bool > &finishCallback) const
Can save at any time, I guess?
PROPERTY_R(SceneEntry, entry)
SunInfo getCurrentSunDetails() const noexcept
void onPlayerAdd(const Player_ptr &player)
PROPERTY_R(SceneEnvironmentProbePool_uptr, envProbePool)
PROPERTY_R(SceneGUIElements_uptr, GUI)
static bool OnShutdown(PlatformContext &context)
bool loadNodeFromXML(SceneGraphNode *node) const
bool checkCameraUnderwater(PlayerIndex idx) const
virtual void processInput(PlayerIndex idx, U64 gameDeltaTimeUS, U64 appDeltaTimeUS)
Get all input commands from the user.
SceneGraphNode * addSky(SceneGraphNode *parentNode, const boost::property_tree::ptree &pt, const Str< 64 > &nodeName="")
XML::SceneNode _xmlSceneGraphRootNode
void registerTask(Task &taskItem, bool start=true, TaskPriority priority=TaskPriority::DONT_CARE)
void initDayNightCycle(Sky &skyInstance, DirectionalLightComponent &sunLight) noexcept
static string GetPlayerSGNName(PlayerIndex idx)
void setDayNightCycleTimeFactor(F32 factor) noexcept
Negative values should work.
void clearHoverTarget(PlayerIndex idx)
PROPERTY_R_IW(bool, loadComplete, false)
vector< SGNRayResult > _sceneSelectionCandidates
void processInternalTimers(U64 appDeltaUS, U64 gameDeltaUS, vector< TimerStruct > &timers)
std::array< I64, Config::MAX_LOCAL_PLAYER_COUNT > _currentHoverTarget
bool idle()
Scene is rendering, so add intensive tasks here to save CPU cycles.
void currentPlayerPass(PlayerIndex idx)
virtual U16 registerInputActions()
Returns the first available action ID.
void addTerrain(SceneGraphNode *parentNode, const boost::property_tree::ptree &pt, const Str< 64 > &nodeName="")
F32 getDayNightCycleTimeFactor() const noexcept
std::atomic_uint _loadingTasks
void registerSceneFactory(const char *name, const ScenePtrFactory &factoryFunc)
std::unordered_map< U64, ScenePtrFactory > SceneFactoryMap
std::unordered_map< U64, Str< 256 > > SceneNameMap
void registerScene(const char *name, const SharedPtrFactory< T > &scenePtr)
boost::factory< std::shared_ptr< T > > SharedPtrFactory
std::function< std::shared_ptr< Scene >(PlatformContext &context, Project &parent, const SceneEntry &name)> ScenePtrFactory
Handle console commands that start with a forward slash.
DELEGATE_STD< Ret, Args... > DELEGATE
eastl::array< Player_ptr, Config::MAX_LOCAL_PLAYER_COUNT > PlayerList
vector< SceneEntry > SceneEntries
std::shared_mutex SharedMutex
DirectionalLightComponent(SceneGraphNode *sgn, PlatformContext &context)
eastl::vector< Type > vector
Project const SceneEntry & entry
vec2< I32 > _startDragPos
DirectionalLightComponent * _sunLight
DELEGATE< void, U64 > _cbk
const TimerClass _timerClass
const U64 _callbackIntervalUS
std::array< I64, MAX_SELECTIONS > _selections
static constexpr U8 MAX_SELECTIONS