Partial Physics
This commit is contained in:
1
.gitmodules
vendored
1
.gitmodules
vendored
@ -13,3 +13,4 @@
|
||||
[submodule "Dependencies/IAMath"]
|
||||
path = Dependencies/IAMath
|
||||
url = https://git.iasoft.dev/dev0/IAMath
|
||||
|
||||
11
.vscode/launch.json
vendored
11
.vscode/launch.json
vendored
@ -5,16 +5,17 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++: debiug",
|
||||
"name": "(Windows) Launch",
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build/bin/IAESandbox.exe",
|
||||
"program": "${workspaceFolder}/build/bin/Debug/IAESandbox.exe",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}/Src/IAESandbox",
|
||||
"cwd": "${workspaceFolder}/Src/IAESandbox/Res",
|
||||
"environment": [],
|
||||
"preLaunchTask": "build",
|
||||
"console": "integratedTerminal"
|
||||
"console": "externalTerminal",
|
||||
"preLaunchTask": "CMake: build"
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
72
.vscode/settings.json
vendored
72
.vscode/settings.json
vendored
@ -1,72 +0,0 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"stdexcept": "cpp",
|
||||
"chrono": "cpp",
|
||||
"forward_list": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"list": "cpp",
|
||||
"vector": "cpp",
|
||||
"xhash": "cpp",
|
||||
"xiosbase": "cpp",
|
||||
"xstring": "cpp",
|
||||
"xutility": "cpp",
|
||||
"format": "cpp",
|
||||
"functional": "cpp",
|
||||
"filesystem": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"iterator": "cpp",
|
||||
"xmemory": "cpp",
|
||||
"cmath": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"cctype": "cpp",
|
||||
"charconv": "cpp",
|
||||
"clocale": "cpp",
|
||||
"codecvt": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"exception": "cpp",
|
||||
"fstream": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"ios": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"locale": "cpp",
|
||||
"memory": "cpp",
|
||||
"new": "cpp",
|
||||
"optional": "cpp",
|
||||
"ratio": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stop_token": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"string": "cpp",
|
||||
"system_error": "cpp",
|
||||
"thread": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"utility": "cpp",
|
||||
"xfacet": "cpp",
|
||||
"xlocale": "cpp",
|
||||
"xlocbuf": "cpp",
|
||||
"xlocinfo": "cpp",
|
||||
"xlocmes": "cpp",
|
||||
"xlocmon": "cpp",
|
||||
"xlocnum": "cpp",
|
||||
"xloctime": "cpp",
|
||||
"xtr1common": "cpp",
|
||||
"iostream": "cpp",
|
||||
"map": "cpp",
|
||||
"ostream": "cpp",
|
||||
"xtree": "cpp"
|
||||
}
|
||||
}
|
||||
26
.vscode/tasks.json
vendored
26
.vscode/tasks.json
vendored
@ -1,19 +1,19 @@
|
||||
{
|
||||
"tasks": [
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"type": "shell",
|
||||
"command": "cmake -S. -B./build -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ && cmake --build build",
|
||||
"group": {
|
||||
"type": "cmake",
|
||||
"label": "CMake: build",
|
||||
"command": "build",
|
||||
"targets": [
|
||||
"ALL_BUILD"
|
||||
],
|
||||
"group":{
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
},
|
||||
"problemMatcher": [],
|
||||
"detail": "CMake template build task"
|
||||
}
|
||||
],
|
||||
"options": {
|
||||
"env": {
|
||||
"INCLUDE": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/include;C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/ATLMFC/include;C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/VS/include;C:/Program Files (x86)/Windows Kits/10/include/10.0.26100.0/ucrt;C:/Program Files (x86)/Windows Kits/10//include/10.0.26100.0//um;C:/Program Files (x86)/Windows Kits/10//include/10.0.26100.0//shared;C:/Program Files (x86)/Windows Kits/10//include/10.0.26100.0//winrt;C:/Program Files (x86)/Windows Kits/10//include/10.0.26100.0//cppwinrt;C:/Program Files (x86)/Windows Kits/NETFXSDK/4.8/include/um",
|
||||
"LIB": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/ATLMFC/lib/x64;C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/lib/x64;C:/Program Files (x86)/Windows Kits/NETFXSDK/4.8/lib/um/x64;C:/Program Files (x86)/Windows Kits/10/lib/10.0.26100.0/ucrt/x64;C:/Program Files (x86)/Windows Kits/10//lib/10.0.26100.0//um/x64"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -3,6 +3,7 @@ set(IAESandbox_Sources
|
||||
imp/cpp/Main.cpp
|
||||
imp/cpp/Game.cpp
|
||||
imp/cpp/Map.cpp
|
||||
imp/cpp/Ground.cpp
|
||||
imp/cpp/Player.cpp
|
||||
)
|
||||
|
||||
|
||||
@ -1,25 +1,29 @@
|
||||
#include <Game.hpp>
|
||||
#include <Player.hpp>
|
||||
#include <Map.hpp>
|
||||
#include <Ground.hpp>
|
||||
|
||||
#include <IAEngine/ResourceManager.hpp>
|
||||
|
||||
namespace ia::iae::game
|
||||
{
|
||||
RefPtr<iae::Scene> scene;
|
||||
|
||||
ResourceManager* g_resourceManager{};
|
||||
|
||||
VOID Game::Initialize()
|
||||
{
|
||||
const auto player = MakeRefPtr<Player>(m_engine);
|
||||
player->SetLocalPosition({200, 150, 0});
|
||||
|
||||
const auto map = MakeRefPtr<TiledMap>(m_engine);
|
||||
g_resourceManager = m_engine->RegisterResourceManager<ResourceManager>();
|
||||
|
||||
scene = m_engine->CreateScene();
|
||||
scene->AddNode(map);
|
||||
scene->AddNode(player);
|
||||
|
||||
m_engine->ChangeScene(scene);
|
||||
|
||||
const auto player = MakeRefPtr<Player>(m_engine);
|
||||
player->SetLocalPosition({100.0f, 200.0f, 0.0f});
|
||||
scene->AddNode(player);
|
||||
|
||||
const auto ground = MakeRefPtr<Ground>(m_engine);
|
||||
ground->SetLocalPosition({50.0f, 500.0f, 0.0f});
|
||||
scene->AddNode(ground);
|
||||
}
|
||||
|
||||
VOID Game::Terminate()
|
||||
|
||||
49
Src/IAESandbox/imp/cpp/Ground.cpp
Normal file
49
Src/IAESandbox/imp/cpp/Ground.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include <Ground.hpp>
|
||||
|
||||
#include <IAEngine/Physics/Physics.hpp>
|
||||
|
||||
#include <IACore/File.hpp>
|
||||
|
||||
namespace ia::iae::game
|
||||
{
|
||||
extern ResourceManager* g_resourceManager;
|
||||
|
||||
Handle m_id2;
|
||||
|
||||
Ground::Ground(IN Engine *engine) : m_engine(engine)
|
||||
{
|
||||
m_spriteRenderer = AddComponent<SpriteRendererComponent>();
|
||||
}
|
||||
|
||||
VOID Ground::OnAdded(IN Scene *scene)
|
||||
{
|
||||
Node::OnAdded(scene);
|
||||
|
||||
iae::SpriteRendererComponent::AnimationKeyFrame keyFrame{};
|
||||
const auto d = File::ReadToVector("Graphics/red.png");
|
||||
keyFrame.Texture = g_resourceManager->CreateTexture(d.data(), d.size());
|
||||
keyFrame.Scale = {3.0f, 0.25f, 1.0f};
|
||||
|
||||
m_spriteRenderer->AddAnimation({.ShouldLoop = true, .Keys = {keyFrame}});
|
||||
m_spriteRenderer->BakeAnimations();
|
||||
|
||||
m_id2 = Physics::CreateStaticBody({GetPosition().X + 300, GetPosition().Y + 25});
|
||||
Physics::AddBoxCollider(m_id2, {600.0f, 50.0f});
|
||||
}
|
||||
|
||||
VOID Ground::OnRemoved()
|
||||
{
|
||||
|
||||
Node::OnRemoved();
|
||||
}
|
||||
|
||||
VOID Ground::Draw()
|
||||
{
|
||||
Node::Draw();
|
||||
}
|
||||
|
||||
VOID Ground::Update()
|
||||
{
|
||||
Node::Update();
|
||||
}
|
||||
} // namespace ia::iae::game
|
||||
@ -1,11 +1,16 @@
|
||||
#include <Player.hpp>
|
||||
|
||||
#include <IAEngine/Physics/Physics.hpp>
|
||||
#include <IAEngine/Input.hpp>
|
||||
|
||||
#include <IACore/File.hpp>
|
||||
|
||||
namespace ia::iae::game
|
||||
{
|
||||
extern ResourceManager* g_resourceManager;
|
||||
|
||||
Handle m_id;
|
||||
|
||||
Player::Player(IN Engine *engine) : m_engine(engine)
|
||||
{
|
||||
m_spriteRenderer = AddComponent<SpriteRendererComponent>();
|
||||
@ -14,6 +19,17 @@ namespace ia::iae::game
|
||||
VOID Player::OnAdded(IN Scene *scene)
|
||||
{
|
||||
Node::OnAdded(scene);
|
||||
|
||||
iae::SpriteRendererComponent::AnimationKeyFrame keyFrame{};
|
||||
const auto d = File::ReadToVector("Graphics/green.png");
|
||||
keyFrame.Texture = g_resourceManager->CreateTexture(d.data(), d.size());
|
||||
keyFrame.Scale = {0.2f, 0.2f, 1.0f};
|
||||
|
||||
m_spriteRenderer->AddAnimation({.ShouldLoop = true, .Keys = {keyFrame}});
|
||||
m_spriteRenderer->BakeAnimations();
|
||||
|
||||
m_id = Physics::CreateDynamicBody({GetPosition().X + 20, GetPosition().Y + 20});
|
||||
Physics::AddBoxCollider(m_id, {40.0f, 40.0f});
|
||||
}
|
||||
|
||||
VOID Player::OnRemoved()
|
||||
@ -30,5 +46,6 @@ namespace ia::iae::game
|
||||
VOID Player::Update()
|
||||
{
|
||||
Node::Update();
|
||||
SetLocalPosition(Physics::GetBodyPosition(m_id) - iam::Vec3f{20.0f, 20.0f, 0.0f});
|
||||
}
|
||||
} // namespace ia::iae::game
|
||||
27
Src/IAESandbox/imp/hpp/Ground.hpp
Normal file
27
Src/IAESandbox/imp/hpp/Ground.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Components/SoundEmitter.hpp>
|
||||
#include <IAEngine/Components/SpriteRenderer.hpp>
|
||||
#include <IAEngine/IAEngine.hpp>
|
||||
|
||||
namespace ia::iae::game
|
||||
{
|
||||
class Ground : public Node
|
||||
{
|
||||
public:
|
||||
Ground(IN Engine *engine);
|
||||
|
||||
VIRTUAL VOID OnAdded(IN Scene *scene) OVERRIDE;
|
||||
VIRTUAL VOID OnRemoved() OVERRIDE;
|
||||
VIRTUAL VOID Draw() OVERRIDE;
|
||||
VIRTUAL VOID Update() OVERRIDE;
|
||||
|
||||
private:
|
||||
INT32 m_speed{};
|
||||
UINT8 m_direction{};
|
||||
|
||||
private:
|
||||
Engine *CONST m_engine;
|
||||
RefPtr<SpriteRendererComponent> m_spriteRenderer;
|
||||
};
|
||||
} // namespace ia::iae::game
|
||||
@ -10,6 +10,8 @@ set(IAEngine_Sources
|
||||
|
||||
imp/cpp/ResourceManager.cpp
|
||||
|
||||
imp/cpp/Physics/Physics.cpp
|
||||
|
||||
imp/cpp/Events/Event.cpp
|
||||
|
||||
imp/cpp/Nodes/Transform.cpp
|
||||
@ -18,9 +20,8 @@ set(IAEngine_Sources
|
||||
imp/cpp/Components/AtlasRenderer.cpp
|
||||
imp/cpp/Components/SpriteRenderer.cpp
|
||||
imp/cpp/Components/SoundEmitter.cpp
|
||||
imp/cpp/Components/Collider.cpp
|
||||
imp/cpp/Components/ParticleEmitter.cpp
|
||||
imp/cpp/Components/StackedCollider.cpp
|
||||
imp/cpp/Components/PhysicsBody.cpp
|
||||
)
|
||||
|
||||
add_library(IAEngine STATIC ${IAEngine_Sources})
|
||||
|
||||
6
Src/IAEngine/imp/cpp/Components/PhysicsBody.cpp
Normal file
6
Src/IAEngine/imp/cpp/Components/PhysicsBody.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include <IAEngine/Components/PhysicsBody.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
}
|
||||
@ -3,6 +3,7 @@
|
||||
#include <IAEngine/Input.hpp>
|
||||
#include <IAEngine/Random.hpp>
|
||||
#include <IAEngine/Time.hpp>
|
||||
#include <IAEngine/Physics/Physics.hpp>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
@ -77,6 +78,7 @@ namespace ia::iae
|
||||
Random::Initialize();
|
||||
Input::Initialize();
|
||||
Audio::Initialize();
|
||||
Physics::Initialize();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -85,6 +87,7 @@ namespace ia::iae
|
||||
{
|
||||
IAE_LOG_INFO("Shutting down IAEngine");
|
||||
|
||||
Physics::Terminate();
|
||||
Audio::Terminate();
|
||||
|
||||
ImGui_ImplSDLRenderer3_Shutdown();
|
||||
@ -145,6 +148,8 @@ namespace ia::iae
|
||||
|
||||
VOID Engine::UpdateGame()
|
||||
{
|
||||
Physics::Update();
|
||||
|
||||
if B_LIKELY (m_activeScene)
|
||||
m_activeScene->Update();
|
||||
}
|
||||
|
||||
37
Src/IAEngine/imp/cpp/Physics/Physics.cpp
Normal file
37
Src/IAEngine/imp/cpp/Physics/Physics.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <IAEngine/Physics/Physics.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
|
||||
VOID Physics::Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
VOID Physics::Terminate()
|
||||
{
|
||||
}
|
||||
|
||||
VOID Physics::Update()
|
||||
{
|
||||
}
|
||||
|
||||
Handle Physics::CreateStaticBody(IN iam::Vec3f position)
|
||||
{
|
||||
return INVALID_HANDLE;
|
||||
}
|
||||
|
||||
Handle Physics::CreateDynamicBody(IN iam::Vec3f position)
|
||||
{
|
||||
return INVALID_HANDLE;
|
||||
}
|
||||
|
||||
VOID Physics::AddBoxCollider(IN Handle body, IN iam::Vec3f size)
|
||||
{
|
||||
}
|
||||
|
||||
iam::Vec3f Physics::GetBodyPosition(IN Handle body)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
} // namespace ia::iae
|
||||
24
Src/IAEngine/inc/IAEngine/Components/PhysicsBody.hpp
Normal file
24
Src/IAEngine/inc/IAEngine/Components/PhysicsBody.hpp
Normal file
@ -0,0 +1,24 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IAS (ias@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Components/Component.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
}
|
||||
37
Src/IAEngine/inc/IAEngine/Physics/Physics.hpp
Normal file
37
Src/IAEngine/inc/IAEngine/Physics/Physics.hpp
Normal file
@ -0,0 +1,37 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IAS (ias@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Base.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class Physics
|
||||
{
|
||||
public:
|
||||
STATIC VOID Initialize();
|
||||
STATIC VOID Terminate();
|
||||
|
||||
STATIC VOID Update();
|
||||
|
||||
STATIC Handle CreateStaticBody(IN iam::Vec3f position);
|
||||
STATIC Handle CreateDynamicBody(IN iam::Vec3f position);
|
||||
STATIC VOID AddBoxCollider(IN Handle body, IN iam::Vec3f size);
|
||||
|
||||
STATIC iam::Vec3f GetBodyPosition(IN Handle body);
|
||||
};
|
||||
}
|
||||
@ -26,6 +26,8 @@ namespace ia::iae
|
||||
class ResourceManager
|
||||
{
|
||||
public:
|
||||
ResourceManager(IN Engine *engine);
|
||||
|
||||
RefPtr<Texture> CreateTexture(IN CONST Span<CONST UINT8> &encodedData);
|
||||
RefPtr<Texture> CreateTexture(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize);
|
||||
RefPtr<Texture> CreateTexture(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height);
|
||||
@ -44,7 +46,6 @@ namespace ia::iae
|
||||
protected:
|
||||
Engine *CONST m_engine;
|
||||
|
||||
ResourceManager(IN Engine *engine);
|
||||
friend class Engine;
|
||||
};
|
||||
} // namespace ia::iae
|
||||
1
Vendor/CMakeLists.txt
vendored
1
Vendor/CMakeLists.txt
vendored
@ -36,3 +36,4 @@ target_include_directories(
|
||||
"imgui/"
|
||||
"imgui/backends"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user