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

GGJ Game #564

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
12 changes: 1 addition & 11 deletions rootex/assets/scenes/pause.scene.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,7 @@
],
"entity": {
"components": {
"MusicComponent": {
"attenuationModel": 53251,
"audio": "rootex/assets/ball.wav",
"isAttenuated": false,
"isLooping": true,
"maxDistance": 100.0,
"playOnStart": true,
"referenceDistance": 1.0,
"rollOffFactor": 1.0,
"volume": 1.0
},

"TextUIComponent": {
"color": {
"a": 1.0,
Expand Down
4 changes: 2 additions & 2 deletions rootex/framework/components/physics/rigid_body_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ class RigidBodyComponent : public CollisionComponent, public btMotionState
void getWorldTransform(btTransform& worldTrans) const override;
void setWorldTransform(const btTransform& worldTrans) override;

void updateTransform();

void handleHit(Hit* hit) override;

public:
virtual ~RigidBodyComponent() = default;

void updateTransform();

void applyForce(const Vector3& force);
void applyTorque(const Vector3& torque);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,26 +232,19 @@ void RenderableComponent::draw()

ImGui::BeginGroup();
ImGui::Text("%s", newMaterial->getPath().filename().generic_string().c_str());
if (ImGui::Button((ICON_ROOTEX_PENCIL_SQUARE_O "##" + newMaterial->getPath().generic_string()).c_str()))
if (ImGui::Button((ICON_ROOTEX_PENCIL_SQUARE_O "##1" + newMaterial->getPath().generic_string()).c_str()))
{
EventManager::GetSingleton()->call(EditorEvents::EditorOpenFile, VariantVector { newMaterial->getPath().generic_string(), (int)newMaterial->getType() });
}
ImGui::SameLine();
if (ImGui::Button((ICON_ROOTEX_FOLDER_OPEN "##" + newMaterial->getPath().generic_string()).c_str()))
if (ImGui::Button((ICON_ROOTEX_FOLDER_OPEN "##2" + newMaterial->getPath().generic_string()).c_str()))
{
if (Optional<String> result = OS::SelectFile("Material(*.rmat)\0*.rmat\0", "game/assets/materials/"))
{
setMaterialOverride(oldMaterial, ResourceLoader::CreateMaterialResourceFile(*result));
}
}
ImGui::SameLine();
if (ImGui::Button((ICON_ROOTEX_FOLDER_OPEN "##" + oldMaterial->getPath().generic_string()).c_str()))
{
if (Optional<String> result = OS::SelectFile("Material(*.rmat)\0*.rmat\0", "game/assets/materials/"))
{
setMaterialOverride(oldMaterial, ResourceLoader::CreateMaterialResourceFile(*result));
}
}
ImGui::EndGroup();
ImGui::NextColumn();
ImGui::Separator();
Expand Down
32 changes: 18 additions & 14 deletions rootex/framework/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,27 @@ void System::setActive(bool enabled)

void System::pause()
{
for (auto& systemType : GetSystems())
{
for (auto& system : systemType)
{
system->m_IsSystemPaused = true;
}
}
EventManager::GetSingleton()->defer([]()
{
for (auto& systemType : GetSystems())
{
for (auto& system : systemType)
{
system->m_IsSystemPaused = true;
}
} });
}
void System::unPause()
{
for (auto& systemType : GetSystems())
{
for (auto& system : systemType)
{
system->m_IsSystemPaused = false;
}
}
EventManager::GetSingleton()->defer([]()
{
for (auto& systemType : GetSystems())
{
for (auto& system : systemType)
{
system->m_IsSystemPaused = false;
}
} });
}

void System::draw()
Expand Down
128 changes: 87 additions & 41 deletions rootex/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,44 +123,65 @@ void LuaInterpreter::registerTypes()
sol::usertype<Vector2> vector2 = rootex.new_usertype<Vector2>(
"Vector2",
sol::constructors<Vector2(), Vector2(float, float)>(),
sol::meta_function::addition, [](Vector2& l, Vector2& r) { return l + r; },
sol::meta_function::subtraction, [](Vector2& l, Vector2& r) { return l - r; },
sol::meta_function::multiplication, [](Vector2& l, Vector2& r) { return l * r; },
sol::meta_function::multiplication, [](Vector2& l, float r) { return l * r; },
sol::meta_function::division, [](Vector2& l, float r) { return l / r; },
sol::meta_function::division, [](Vector2& l, Vector2& r) { return l / r; });
sol::meta_function::addition, [](Vector2& l, Vector2& r)
{ return l + r; },
sol::meta_function::subtraction, [](Vector2& l, Vector2& r)
{ return l - r; },
sol::meta_function::multiplication, [](Vector2& l, Vector2& r)
{ return l * r; },
sol::meta_function::multiplication, [](Vector2& l, float r)
{ return l * r; },
sol::meta_function::division, [](Vector2& l, float r)
{ return l / r; },
sol::meta_function::division, [](Vector2& l, Vector2& r)
{ return l / r; });
vector2["dot"] = &Vector2::Dot;
vector2["cross"] = [](const Vector2& l, const Vector2& r) { return l.Cross(r); };
vector2["cross"] = [](const Vector2& l, const Vector2& r)
{ return l.Cross(r); };
vector2["x"] = &Vector2::x;
vector2["y"] = &Vector2::y;
}
{
sol::usertype<Vector3> vector3 = rootex.new_usertype<Vector3>(
"Vector3",
sol::constructors<Vector3(), Vector3(float, float, float)>(),
sol::meta_function::addition, [](Vector3& l, Vector3& r) { return l + r; },
sol::meta_function::subtraction, [](Vector3& l, Vector3& r) { return l - r; },
sol::meta_function::multiplication, [](float l, Vector3& r) { return l * r; },
sol::meta_function::multiplication, [](Vector3& l, float r) { return l * r; },
sol::meta_function::division, [](Vector3& l, float r) { return l / r; },
sol::meta_function::division, [](Vector3& l, Vector3& r) { return l / r; });
sol::meta_function::addition, [](Vector3& l, Vector3& r)
{ return l + r; },
sol::meta_function::subtraction, [](Vector3& l, Vector3& r)
{ return l - r; },
sol::meta_function::multiplication, [](float l, Vector3& r)
{ return l * r; },
sol::meta_function::multiplication, [](Vector3& l, float r)
{ return l * r; },
sol::meta_function::division, [](Vector3& l, float r)
{ return l / r; },
sol::meta_function::division, [](Vector3& l, Vector3& r)
{ return l / r; });
vector3["dot"] = &Vector3::Dot;
vector3["cross"] = [](const Vector3& l, const Vector3& r) { return l.Cross(r); };
vector3["cross"] = [](const Vector3& l, const Vector3& r)
{ return l.Cross(r); };
vector3["x"] = &Vector3::x;
vector3["y"] = &Vector3::y;
vector3["z"] = &Vector3::z;
}
{
sol::usertype<Vector4> vector4 = rootex.new_usertype<Vector4>(
"Vector4", sol::constructors<Vector4(), Vector4(float, float, float, float)>(),
sol::meta_function::addition, [](Vector4& l, Vector4& r) { return l + r; },
sol::meta_function::subtraction, [](Vector4& l, Vector4& r) { return l - r; },
sol::meta_function::multiplication, [](Vector4& l, Vector4& r) { return l * r; },
sol::meta_function::multiplication, [](Vector4& l, float r) { return l * r; },
sol::meta_function::division, [](Vector4& l, Vector4& r) { return l / r; },
sol::meta_function::division, [](Vector4& l, float r) { return l / r; });
sol::meta_function::addition, [](Vector4& l, Vector4& r)
{ return l + r; },
sol::meta_function::subtraction, [](Vector4& l, Vector4& r)
{ return l - r; },
sol::meta_function::multiplication, [](Vector4& l, Vector4& r)
{ return l * r; },
sol::meta_function::multiplication, [](Vector4& l, float r)
{ return l * r; },
sol::meta_function::division, [](Vector4& l, Vector4& r)
{ return l / r; },
sol::meta_function::division, [](Vector4& l, float r)
{ return l / r; });
vector4["dot"] = &Vector4::Dot;
vector4["cross"] = [](const Vector4& l, const Vector4& r) { return l.Cross(l, r); };
vector4["cross"] = [](const Vector4& l, const Vector4& r)
{ return l.Cross(l, r); };
vector4["x"] = &Vector4::x;
vector4["y"] = &Vector4::y;
vector4["z"] = &Vector4::z;
Expand All @@ -169,9 +190,12 @@ void LuaInterpreter::registerTypes()
{
sol::usertype<Color> color = rootex.new_usertype<Color>(
"Color", sol::constructors<Color(), Color(float, float, float, float)>(),
sol::meta_function::addition, [](Color& l, Color& r) { return l + r; },
sol::meta_function::subtraction, [](Color& l, Color& r) { return l - r; },
sol::meta_function::multiplication, [](Color& l, Color& r) { return l * r; });
sol::meta_function::addition, [](Color& l, Color& r)
{ return l + r; },
sol::meta_function::subtraction, [](Color& l, Color& r)
{ return l - r; },
sol::meta_function::multiplication, [](Color& l, Color& r)
{ return l * r; });
color["x"] = &Color::x;
color["y"] = &Color::y;
color["z"] = &Color::z;
Expand All @@ -192,9 +216,12 @@ void LuaInterpreter::registerTypes()
sol::usertype<Matrix> matrix = rootex.new_usertype<Matrix>(
"Matrix",
sol::constructors<Matrix()>(),
sol::meta_function::addition, [](Matrix& l, Matrix& r) { return l + r; },
sol::meta_function::subtraction, [](Matrix& l, Matrix& r) { return l - r; },
sol::meta_function::multiplication, [](Matrix& l, Matrix& r) { return l * r; });
sol::meta_function::addition, [](Matrix& l, Matrix& r)
{ return l + r; },
sol::meta_function::subtraction, [](Matrix& l, Matrix& r)
{ return l - r; },
sol::meta_function::multiplication, [](Matrix& l, Matrix& r)
{ return l * r; });
matrix["Identity"] = sol::var(Matrix::Identity);
matrix["_11"] = &Matrix::_11;
matrix["_12"] = &Matrix::_12;
Expand All @@ -219,22 +246,34 @@ void LuaInterpreter::registerTypes()
event["getData"] = &Event::getData;
}
{
rootex["CallEvent"] = [](const Event& event) { EventManager::GetSingleton()->call(event); };
rootex["Call"] = [](const Event::Type& type, const Variant& data) { EventManager::GetSingleton()->call(type, data); };
rootex["DeferredCallEvent"] = [](const Ref<Event>& event) { EventManager::GetSingleton()->deferredCall(event); };
rootex["ReturnCallEvent"] = [](const Event& event) { return EventManager::GetSingleton()->returnCall(event); };
rootex["Bind"] = [this](const Event::Type& event, sol::function function) { m_Binder.bind(event, function); };
rootex["Unbind"] = [this](const Event::Type& event) { m_Binder.unbind(event); };
rootex["CallEvent"] = [](const Event& event)
{ EventManager::GetSingleton()->call(event); };
rootex["Call"] = [](const Event::Type& type, const Variant& data)
{ EventManager::GetSingleton()->call(type, data); };
rootex["DeferredCallEvent"] = [](const Ref<Event>& event)
{ EventManager::GetSingleton()->deferredCall(event); };
rootex["ReturnCallEvent"] = [](const Event& event)
{ return EventManager::GetSingleton()->returnCall(event); };
rootex["Bind"] = [this](const Event::Type& event, sol::function function)
{ m_Binder.bind(event, function); };
rootex["Unbind"] = [this](const Event::Type& event)
{ m_Binder.unbind(event); };
}
{
sol::usertype<Atomic<int>> atomicInt = rootex.new_usertype<Atomic<int>>("AtomicInt", sol::constructors<Atomic<int>(), Atomic<int>(int)>());
atomicInt["load"] = [](Atomic<int>* a) { return a->load(); };
atomicInt["load"] = [](Atomic<int>* a)
{ return a->load(); };

rootex["LoadScene"] = [](const String& sceneFile, const sol::table& arguments) { SceneLoader::GetSingleton()->loadScene(sceneFile, arguments.as<Vector<String>>()); };
rootex["PreloadScene"] = [](const String& sceneFile, Atomic<int>& progress) { return SceneLoader::GetSingleton()->preloadScene(sceneFile, progress); };
rootex["LoadPreloadedScene"] = [](const String& sceneFile, const sol::nested<Vector<String>>& arguments) { SceneLoader::GetSingleton()->loadPreloadedScene(sceneFile, arguments.value()); };
rootex["GetSceneArguments"] = []() { return SceneLoader::GetSingleton()->getArguments(); };
rootex["GetCurrentScene"] = []() { return SceneLoader::GetSingleton()->getCurrentScene(); };
rootex["LoadScene"] = [](const String& sceneFile, const sol::table& arguments)
{ SceneLoader::GetSingleton()->loadScene(sceneFile, arguments.as<Vector<String>>()); };
rootex["PreloadScene"] = [](const String& sceneFile, Atomic<int>& progress)
{ return SceneLoader::GetSingleton()->preloadScene(sceneFile, progress); };
rootex["LoadPreloadedScene"] = [](const String& sceneFile, const sol::nested<Vector<String>>& arguments)
{ SceneLoader::GetSingleton()->loadPreloadedScene(sceneFile, arguments.value()); };
rootex["GetSceneArguments"] = []()
{ return SceneLoader::GetSingleton()->getArguments(); };
rootex["GetCurrentScene"] = []()
{ return SceneLoader::GetSingleton()->getCurrentScene(); };
}
{
sol::usertype<InputManager> inputManager = rootex.new_usertype<InputManager>("Input");
Expand All @@ -260,11 +299,13 @@ void LuaInterpreter::registerTypes()
resourceLoader["CreateAnimatedModel"] = &ResourceLoader::CreateAnimatedModelResourceFile;
resourceLoader["CreateCollisionModel"] = &ResourceLoader::CreateAnimatedModelResourceFile;
resourceLoader["CreateParticleEffectResourceFile"] = &ResourceLoader::CreateParticleEffectResourceFile;
resourceLoader["CreateMaterialResourceFile"] = &ResourceLoader::CreateMaterialResourceFile;
}
{
sol::usertype<ResourceFile> resourceFile = rootex.new_usertype<ResourceFile>("ResourceFile");
resourceFile["isDirty"] = &ResourceFile::isDirty;
resourceFile["getPath"] = [](ResourceFile& f) { return f.getPath().string(); };
resourceFile["getPath"] = [](ResourceFile& f)
{ return f.getPath().string(); };
resourceFile["getType"] = &ResourceFile::getType;
}
{
Expand Down Expand Up @@ -521,6 +562,8 @@ void LuaInterpreter::registerTypes()
"ModelComponent",
sol::base_classes, sol::bases<Component, RenderableComponent>());
modelComponent["getModelResourceFile"] = &ModelComponent::getModelResourceFile;
modelComponent["setMaterialOverride"] = &RenderableComponent::setMaterialOverride;
modelComponent["getMaterialOverride"] = &RenderableComponent::getMaterialOverride;
}
{
sol::usertype<AnimatedModelComponent> animatedModelComponent = rootex.new_usertype<AnimatedModelComponent>(
Expand Down Expand Up @@ -567,7 +610,8 @@ void LuaInterpreter::registerTypes()
"UIComponent",
sol::base_classes, sol::bases<Component>(),
"document", sol::property(&UIComponent::getDocument));
ui["getDocumentID"] = [](UIComponent* ui) { return ui->getDocument()->GetId(); };
ui["getDocumentID"] = [](UIComponent* ui)
{ return ui->getDocument()->GetId(); };
}
{
sol::usertype<AudioComponent> audioComponent = rootex.new_usertype<AudioComponent>(
Expand Down Expand Up @@ -620,6 +664,8 @@ void LuaInterpreter::registerTypes()
rigidBodyComponent["applyTorque"] = &RigidBodyComponent::applyTorque;
rigidBodyComponent["setAxisLock"] = &RigidBodyComponent::setAxisLock;
rigidBodyComponent["translate"] = &RigidBodyComponent::translate;

rigidBodyComponent["update"] = &RigidBodyComponent::updateTransform;
}
{
sol::usertype<BoxColliderComponent> bcc = rootex.new_usertype<BoxColliderComponent>(
Expand Down