Skip to content

Commit f437ce2

Browse files
committed
Feat: Save project physics
1 parent 2643d65 commit f437ce2

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

src/atta/file/project/projectSerializer.cpp

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ Section ProjectSerializer::serializeGraphicsModule() {
108108

109109
Section ProjectSerializer::serializePhysicsModule() {
110110
Section section("physics");
111+
112+
section["engine"] = physics::Engine::typeToString.at(physics::getEngineType());
113+
section["gravity"] = physics::getGravity();
114+
section["showColliders"] = physics::getShowColliders();
115+
section["showContacts"] = physics::getShowContacts();
116+
section["showJoints"] = physics::getShowJoints();
117+
118+
auto bullet = physics::getEngine<physics::BulletEngine>();
119+
section["bullet.showAabb"] = bullet->getShowAabb();
120+
section["bullet.numSubSteps"] = bullet->getNumSubSteps();
121+
111122
return section;
112123
}
113124

@@ -162,29 +173,6 @@ std::vector<Section> ProjectSerializer::serializeResources() {
162173
sections.push_back(std::move(section));
163174
}
164175

165-
// Serialize images
166-
res::Image::CreateInfo defaultImage{};
167-
std::vector<StringId> imageSids = res::getResources<res::Image>();
168-
for (StringId sid : imageSids) {
169-
res::Image* img = res::get<res::Image>(sid.getString());
170-
Section section("image");
171-
172-
// Id
173-
section["id"] = sid.getString();
174-
175-
// Serialize dimensions if they are different from defaults
176-
if (img->getWidth() != defaultImage.width)
177-
section["width"] = img->getWidth();
178-
if (img->getHeight() != defaultImage.height)
179-
section["height"] = img->getHeight();
180-
181-
// Serialize format if it's not the default
182-
if (img->getFormat() != defaultImage.format)
183-
section["format"] = res::Image::formatToString.at(img->getFormat());
184-
185-
sections.push_back(std::move(section));
186-
}
187-
188176
return sections;
189177
}
190178

src/atta/physics/engines/engine.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@
99

1010
namespace atta::physics {
1111

12+
// Map Type to String
13+
const std::unordered_map<Engine::Type, std::string> Engine::typeToString = {
14+
{Engine::NONE, "NONE"},
15+
{Engine::BOX2D, "BOX2D"},
16+
{Engine::BULLET, "BULLET"},
17+
};
18+
19+
// Map String to Type
20+
const std::unordered_map<std::string, Engine::Type> Engine::stringToType = {
21+
{"NONE", Engine::NONE},
22+
{"BOX2D", Engine::BOX2D},
23+
{"BULLET", Engine::BULLET},
24+
};
25+
1226
Engine::Engine(Type type) : _type(type), _running(false) {}
1327

1428
void Engine::createRigidBody(component::EntityId entity) {}

src/atta/physics/engines/engine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class Engine {
3939
Type getType() const { return _type; }
4040
bool getRunning() const { return _running; }
4141

42+
static const std::unordered_map<Type, std::string> typeToString;
43+
static const std::unordered_map<std::string, Type> stringToType;
44+
4245
protected:
4346
Type _type; ///< Physics engine type
4447
bool _running; ///< If physics engine is performing simulations

src/atta/resource/resources/image.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
namespace atta::resource {
1919

20-
// Define Format-to-String Mapping
20+
// Map format to string
2121
const std::unordered_map<Image::Format, std::string> Image::formatToString = {
2222
{Format::NONE, "NONE"}, {Format::RED8, "RED8"}, {Format::RGB8, "RGB8"}, {Format::RGBA8, "RGBA8"}, {Format::RGB32F, "RGB32F"},
2323
};
2424

25-
// Define String-to-Format Mapping
25+
// Map string to format
2626
const std::unordered_map<std::string, Image::Format> Image::stringToFormat = {
2727
{"NONE", Format::NONE}, {"RED8", Format::RED8}, {"RGB8", Format::RGB8}, {"RGBA8", Format::RGBA8}, {"RGB32F", Format::RGB32F},
2828
};

0 commit comments

Comments
 (0)