8#include <nlohmann/json.hpp>
12#include "galaxy/core/ServiceLocator.hpp"
14#include "galaxy/flags/DenySerialization.hpp"
17#include "galaxy/meta/EntityMeta.hpp"
20#include "galaxy/scripting/JSON.hpp"
21#include "galaxy/scripting/Lua.hpp"
25#ifdef GALAXY_WIN_PLATFORM
27#pragma warning(disable : 26487)
28#pragma warning(disable : 4244)
39 , m_b2world {b2Vec2 {0.0f, 0.0f}}
40 , m_velocity_iterations {8}
41 , m_position_iterations {3}
43 auto& w = core::ServiceLocator<core::Window>::ref();
53 core::ServiceLocator<core::Window>::ref().set_dispatcher(&
m_dispatcher);
58 core::ServiceLocator<sol::state>::ref().collect_garbage();
95 nlohmann::json json =
"{}"_json;
97 json[
"entities"] = nlohmann::json::array();
99 auto& em = core::ServiceLocator<meta::EntityMeta>::ref();
101 for (
const auto& [entity] :
m_registry.
m_entt.view<entt::entity>(entt::exclude<flags::DenySerialization>).each())
106 json[
"physics"] = nlohmann::json::object();
107 auto& physics = json.at(
"physics");
110 physics[
"gravity"][
"x"] = gravity.x;
111 physics[
"gravity"][
"y"] = gravity.y;
113 physics[
"allow_sleeping"] =
m_b2world.GetAllowSleeping();
114 physics[
"allow_autoclearforces"] =
m_b2world.GetAutoClearForces();
127 auto& em = core::ServiceLocator<meta::EntityMeta>::ref();
131 const auto& physics = json.at(
"physics");
132 const auto& gravity = physics.at(
"gravity");
134 m_b2world.SetGravity({gravity.at(
"x"), gravity.at(
"y")});
135 m_b2world.SetAllowSleeping(physics.at(
"allow_sleeping"));
136 m_b2world.SetAutoClearForces(physics.at(
"allow_autoclearforces"));
140 const auto& entity_json = json.at(
"entities");
141 for (
const auto& data : entity_json)
148 tag.
m_tag =
"Untagged";
163#ifdef GALAXY_WIN_PLATFORM
void clear()
Clear any pending data.
void update(b2World &b2World)
Updates pending component data.
entt::registry m_entt
Scene entities.
void set_viewport(const float width, const float height)
Set Viewport.
nlohmann::json serialize() override
Serializes object.
void deserialize(const nlohmann::json &json) override
Deserializes from object.
void end_default()
Swaps buffers.
void begin_post()
Begin rendering to post process framebuffer.
void render_post()
Renders final post processing output to active framebuffer.
void end_post()
Renders effects to post processing framebuffer and rebinds to default framebuffer.
void flush()
Deletes all submitted render commands.
void submit_camera(Camera &camera)
Set the camera to use when calling draw().
void draw()
Draw all submitted render commands to screen.
static Renderer & ref()
Get reference to renderer singleton.
void begin_default()
Start rendering to default framebuffer.
const std::string & name() const
Get map name.
bool load(const std::string &file)
Load a world.
void set_active(const std::string &map)
Set currently active map.
map::Map * get_active() const
Get currently active map.
void parse()
Parse world and create entities.
const std::string & file() const
Get file.
map::World m_world
LDTK world.
virtual void load()
When scene is loaded and made active.
Scene()=delete
Constructor.
virtual ~Scene()
Destructor.
virtual void render()
Render scene.
virtual void update()
Process events and updates.
int m_position_iterations
Box2d world position iterations.
graphics::Camera m_camera
Camera.
std::string m_name
Scene name for debug purposes.
nlohmann::json serialize() override
Serializes object.
entt::dispatcher m_dispatcher
Scene event handler.
b2World m_b2world
Box2D physics world.
core::Registry m_registry
Entity data.
bool load_world(const std::string &file)
Loads an LDTK world for this scene.
void deserialize(const nlohmann::json &json) override
Deserializes from object.
int m_velocity_iterations
Box2D world velocity iterations.
virtual void unload()
When scene is deactivated / unloaded.