Merge branch 'master' into NDK-ShadowMapping
Former-commit-id: e2be28b65207dfbb81efe58f31ca31548afecee7
This commit is contained in:
@@ -3,3 +3,47 @@
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Application.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
bool Application::Run()
|
||||
{
|
||||
#ifndef NDK_SERVER
|
||||
bool hasAtLeastOneActiveWindow = false;
|
||||
|
||||
auto it = m_windows.begin();
|
||||
while (it != m_windows.end())
|
||||
{
|
||||
Nz::Window& window = **it;
|
||||
|
||||
if (!window.IsOpen(true))
|
||||
{
|
||||
it = m_windows.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
hasAtLeastOneActiveWindow = true;
|
||||
|
||||
++it;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
if (m_exitOnClosedWindows && !hasAtLeastOneActiveWindow)
|
||||
return false;
|
||||
#endif
|
||||
|
||||
if (m_shouldQuit)
|
||||
return false;
|
||||
|
||||
m_updateTime = m_updateClock.GetSeconds();
|
||||
m_updateClock.Restart();
|
||||
|
||||
for (World& world : m_worlds)
|
||||
world.Update(m_updateTime);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Application* Application::s_application = nullptr;
|
||||
}
|
||||
@@ -119,9 +119,14 @@ namespace Ndk
|
||||
switch (m_projectionType)
|
||||
{
|
||||
case Nz::ProjectionType_Orthogonal:
|
||||
EnsureViewportUpdate();
|
||||
if (m_size.x <= 0.f || m_size.y <= 0.f)
|
||||
{
|
||||
EnsureViewportUpdate();
|
||||
|
||||
m_projectionMatrix.MakeOrtho(0.f, static_cast<float>(m_viewport.width), 0.f, static_cast<float>(m_viewport.height), m_zNear, m_zFar);
|
||||
m_projectionMatrix.MakeOrtho(0.f, static_cast<float>(m_viewport.width), 0.f, static_cast<float>(m_viewport.height), m_zNear, m_zFar);
|
||||
}
|
||||
else
|
||||
m_projectionMatrix.MakeOrtho(0.f, m_size.x, 0.f, m_size.y, m_zNear, m_zFar);
|
||||
break;
|
||||
|
||||
case Nz::ProjectionType_Perspective:
|
||||
|
||||
@@ -63,6 +63,18 @@ namespace Ndk
|
||||
InvalidateTransformMatrix();
|
||||
}
|
||||
|
||||
void GraphicsComponent::UpdateBoundingVolume() const
|
||||
{
|
||||
EnsureTransformMatrixUpdate();
|
||||
|
||||
m_boundingVolume.MakeNull();
|
||||
for (const Renderable& r : m_renderables)
|
||||
m_boundingVolume.ExtendTo(r.renderable->GetBoundingVolume());
|
||||
|
||||
m_boundingVolume.Update(m_transformMatrix);
|
||||
m_boundingVolumeUpdated = true;
|
||||
}
|
||||
|
||||
void GraphicsComponent::UpdateTransformMatrix() const
|
||||
{
|
||||
NazaraAssert(m_entity && m_entity->HasComponent<NodeComponent>(), "GraphicsComponent requires NodeComponent");
|
||||
|
||||
272
SDK/src/NDK/Console.cpp
Normal file
272
SDK/src/NDK/Console.cpp
Normal file
@@ -0,0 +1,272 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Console.hpp>
|
||||
#include <Nazara/Core/Unicode.hpp>
|
||||
#include <Nazara/Lua/LuaInstance.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
||||
///TODO: For now is unable to display different color in the history, it needs a RichTextDrawer to do so
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
namespace
|
||||
{
|
||||
const char s_inputPrefix[] = "> ";
|
||||
constexpr std::size_t s_inputPrefixSize = Nz::CountOf(s_inputPrefix) - 1;
|
||||
}
|
||||
|
||||
Console::Console(World& world, const Nz::Vector2f& size, Nz::LuaInstance& instance) :
|
||||
m_historyPosition(0),
|
||||
m_defaultFont(Nz::Font::GetDefault()),
|
||||
m_instance(instance),
|
||||
m_size(size),
|
||||
m_opened(false),
|
||||
m_characterSize(24)
|
||||
{
|
||||
Nz::MaterialRef backgroundMaterial = Nz::Material::New();
|
||||
backgroundMaterial->Enable(Nz::RendererParameter_Blend, true);
|
||||
backgroundMaterial->Enable(Nz::RendererParameter_DepthBuffer, false);
|
||||
backgroundMaterial->SetDstBlend(Nz::BlendFunc_InvSrcAlpha);
|
||||
backgroundMaterial->SetSrcBlend(Nz::BlendFunc_SrcAlpha);
|
||||
|
||||
// History bakckground
|
||||
m_historyBackgroundSprite = Nz::Sprite::New();
|
||||
m_historyBackgroundSprite->SetColor(Nz::Color(80, 80, 160, 128));
|
||||
m_historyBackgroundSprite->SetMaterial(backgroundMaterial);
|
||||
|
||||
m_historyBackground = world.CreateEntity();
|
||||
m_historyBackground->Enable(m_opened);
|
||||
m_historyBackground->AddComponent<Ndk::GraphicsComponent>().Attach(m_historyBackgroundSprite, -1);
|
||||
m_historyBackground->AddComponent<Ndk::NodeComponent>().SetParent(this);
|
||||
|
||||
// History
|
||||
m_historyDrawer.SetCharacterSize(m_characterSize);
|
||||
m_historyDrawer.SetColor(Nz::Color(200, 200, 200));
|
||||
m_historyDrawer.SetFont(m_defaultFont);
|
||||
|
||||
m_historyTextSprite = Nz::TextSprite::New();
|
||||
|
||||
m_history = world.CreateEntity();
|
||||
m_history->Enable(m_opened);
|
||||
m_history->AddComponent<Ndk::GraphicsComponent>().Attach(m_historyTextSprite);
|
||||
|
||||
Ndk::NodeComponent& historyNode = m_history->AddComponent<Ndk::NodeComponent>();
|
||||
historyNode.SetParent(this);
|
||||
|
||||
// Input background
|
||||
m_inputBackgroundSprite = Nz::Sprite::New();
|
||||
m_inputBackgroundSprite->SetColor(Nz::Color(255, 255, 255, 200));
|
||||
m_inputBackgroundSprite->SetMaterial(backgroundMaterial);
|
||||
|
||||
m_inputBackground = world.CreateEntity();
|
||||
m_inputBackground->Enable(m_opened);
|
||||
m_inputBackground->AddComponent<Ndk::GraphicsComponent>().Attach(m_inputBackgroundSprite, -1);
|
||||
m_inputBackground->AddComponent<Ndk::NodeComponent>().SetParent(this);
|
||||
|
||||
// Input
|
||||
m_inputDrawer.SetColor(Nz::Color::Black);
|
||||
m_inputDrawer.SetCharacterSize(m_characterSize);
|
||||
m_inputDrawer.SetFont(m_defaultFont);
|
||||
m_inputDrawer.SetText(s_inputPrefix);
|
||||
|
||||
m_inputTextSprite = Nz::TextSprite::New();
|
||||
m_inputTextSprite->Update(m_inputDrawer);
|
||||
|
||||
m_input = world.CreateEntity();
|
||||
m_input->Enable(m_opened);
|
||||
m_input->AddComponent<Ndk::GraphicsComponent>().Attach(m_inputTextSprite);
|
||||
|
||||
Ndk::NodeComponent& inputNode = m_input->AddComponent<Ndk::NodeComponent>();
|
||||
inputNode.SetParent(this);
|
||||
|
||||
Layout();
|
||||
}
|
||||
|
||||
void Console::AddLine(const Nz::String& text, const Nz::Color& color)
|
||||
{
|
||||
AddLineInternal(text, color);
|
||||
RefreshHistory();
|
||||
}
|
||||
|
||||
void Console::Clear()
|
||||
{
|
||||
m_historyLines.clear();
|
||||
RefreshHistory();
|
||||
}
|
||||
|
||||
void Console::SendCharacter(char32_t character)
|
||||
{
|
||||
switch (character)
|
||||
{
|
||||
case '\b':
|
||||
{
|
||||
Nz::String input = m_inputDrawer.GetText();
|
||||
if (input.GetLength() <= s_inputPrefixSize) // Prevent removal of the input prefix
|
||||
return; // Ignore if no user character is there
|
||||
|
||||
input.Resize(-1, Nz::String::HandleUtf8);
|
||||
m_inputDrawer.SetText(input);
|
||||
break;
|
||||
}
|
||||
|
||||
case '\r':
|
||||
case '\n':
|
||||
ExecuteInput();
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
if (Nz::Unicode::GetCategory(character) == Nz::Unicode::Category_Other_Control)
|
||||
return;
|
||||
|
||||
m_inputDrawer.AppendText(Nz::String::Unicode(character));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_inputTextSprite->Update(m_inputDrawer);
|
||||
}
|
||||
|
||||
void Console::SendEvent(Nz::WindowEvent event)
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case Nz::WindowEventType_TextEntered:
|
||||
SendCharacter(event.text.character);
|
||||
break;
|
||||
|
||||
case Nz::WindowEventType_KeyPressed:
|
||||
{
|
||||
switch (event.key.code)
|
||||
{
|
||||
case Nz::Keyboard::Down:
|
||||
case Nz::Keyboard::Up:
|
||||
if (event.key.code == Nz::Keyboard::Up)
|
||||
m_historyPosition = std::min<std::size_t>(m_commandHistory.size(), m_historyPosition + 1);
|
||||
else
|
||||
{
|
||||
if (m_historyPosition > 1)
|
||||
m_historyPosition--;
|
||||
else if (m_historyPosition == 0)
|
||||
m_historyPosition = 1;
|
||||
}
|
||||
|
||||
Nz::String text = m_commandHistory[m_commandHistory.size() - m_historyPosition];
|
||||
m_inputDrawer.SetText(s_inputPrefix + text);
|
||||
m_inputTextSprite->Update(m_inputDrawer);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Console::SetCharacterSize(unsigned int size)
|
||||
{
|
||||
m_characterSize = size;
|
||||
|
||||
m_historyDrawer.SetCharacterSize(m_characterSize);
|
||||
m_historyTextSprite->Update(m_historyDrawer);
|
||||
m_inputDrawer.SetCharacterSize(m_characterSize);
|
||||
m_inputTextSprite->Update(m_inputDrawer);
|
||||
|
||||
Layout();
|
||||
}
|
||||
|
||||
void Console::SetSize(const Nz::Vector2f& size)
|
||||
{
|
||||
m_size = size;
|
||||
m_historyBackgroundSprite->SetSize(m_size);
|
||||
Layout();
|
||||
}
|
||||
|
||||
void Console::SetTextFont(Nz::FontRef font)
|
||||
{
|
||||
Layout();
|
||||
}
|
||||
|
||||
void Console::Show(bool show)
|
||||
{
|
||||
if (m_opened != show)
|
||||
{
|
||||
m_historyBackground->Enable(show);
|
||||
m_history->Enable(show);
|
||||
m_input->Enable(show);
|
||||
m_inputBackground->Enable(show);
|
||||
|
||||
m_opened = show;
|
||||
}
|
||||
}
|
||||
|
||||
void Console::AddLineInternal(const Nz::String& text, const Nz::Color& color)
|
||||
{
|
||||
m_historyLines.emplace_back(Line{color, text});
|
||||
}
|
||||
|
||||
void Console::ExecuteInput()
|
||||
{
|
||||
Nz::String input = m_inputDrawer.GetText();
|
||||
Nz::String inputCmd = input.SubString(s_inputPrefixSize);;
|
||||
m_inputDrawer.SetText(s_inputPrefix);
|
||||
|
||||
if (m_commandHistory.empty() || m_commandHistory.back() != inputCmd)
|
||||
m_commandHistory.push_back(inputCmd);
|
||||
|
||||
m_historyPosition = 0;
|
||||
|
||||
AddLineInternal(input); //< With the input prefix
|
||||
|
||||
if (!m_instance.Execute(inputCmd))
|
||||
AddLineInternal(m_instance.GetLastError(), Nz::Color::Red);
|
||||
|
||||
RefreshHistory();
|
||||
}
|
||||
|
||||
void Console::Layout()
|
||||
{
|
||||
unsigned int lineHeight = m_defaultFont->GetSizeInfo(m_characterSize).lineHeight;
|
||||
|
||||
Ndk::NodeComponent& inputNode = m_input->GetComponent<Ndk::NodeComponent>();
|
||||
inputNode.SetPosition(0.f, m_size.y - lineHeight - 5.f);
|
||||
|
||||
float historyHeight = m_size.y - lineHeight - 5.f - 2.f;
|
||||
m_historyBackgroundSprite->SetSize(m_size.x, historyHeight);
|
||||
|
||||
m_maxHistoryLines = static_cast<unsigned int>(std::ceil(historyHeight / lineHeight));
|
||||
|
||||
Ndk::NodeComponent& historyNode = m_history->GetComponent<Ndk::NodeComponent>();
|
||||
historyNode.SetPosition(0.f, historyHeight - m_maxHistoryLines * lineHeight);
|
||||
|
||||
Ndk::NodeComponent& inputBackgroundNode = m_inputBackground->GetComponent<Ndk::NodeComponent>();
|
||||
inputBackgroundNode.SetPosition(0.f, historyHeight + 2.f);
|
||||
|
||||
m_inputBackgroundSprite->SetSize(m_size.x, m_size.y - historyHeight);
|
||||
}
|
||||
|
||||
void Console::RefreshHistory()
|
||||
{
|
||||
m_historyDrawer.Clear();
|
||||
auto it = m_historyLines.end();
|
||||
if (m_historyLines.size() > m_maxHistoryLines)
|
||||
it -= m_maxHistoryLines;
|
||||
else
|
||||
it = m_historyLines.begin();
|
||||
|
||||
for (unsigned int i = 0; i < m_maxHistoryLines; ++i)
|
||||
{
|
||||
if (m_maxHistoryLines - i <= m_historyLines.size() && it != m_historyLines.end())
|
||||
{
|
||||
m_historyDrawer.AppendText(it->text);
|
||||
++it;
|
||||
}
|
||||
|
||||
m_historyDrawer.AppendText(Nz::String('\n'));
|
||||
}
|
||||
|
||||
m_historyTextSprite->Update(m_historyDrawer);
|
||||
}
|
||||
}
|
||||
@@ -4,27 +4,25 @@
|
||||
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/BaseComponent.hpp>
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
Entity::Entity(Entity&& entity) :
|
||||
HandledObject(std::move(entity)),
|
||||
m_components(std::move(entity.m_components)),
|
||||
m_handles(std::move(entity.m_handles)),
|
||||
m_componentBits(std::move(entity.m_componentBits)),
|
||||
m_systemBits(std::move(entity.m_systemBits)),
|
||||
m_id(entity.m_id),
|
||||
m_world(entity.m_world),
|
||||
m_enabled(entity.m_enabled),
|
||||
m_valid(entity.m_valid)
|
||||
{
|
||||
for (EntityHandle* handle : m_handles)
|
||||
handle->OnEntityMoved(this);
|
||||
}
|
||||
|
||||
Entity::Entity(World& world, EntityId id) :
|
||||
Entity::Entity(World* world, EntityId id) :
|
||||
m_id(id),
|
||||
m_world(&world)
|
||||
m_world(world)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -62,11 +60,6 @@ namespace Ndk
|
||||
return component;
|
||||
}
|
||||
|
||||
EntityHandle Entity::CreateHandle()
|
||||
{
|
||||
return EntityHandle(this);
|
||||
}
|
||||
|
||||
void Entity::Kill()
|
||||
{
|
||||
m_world->KillEntity(this);
|
||||
@@ -114,6 +107,7 @@ namespace Ndk
|
||||
|
||||
void Entity::Create()
|
||||
{
|
||||
m_enabled = true;
|
||||
m_valid = true;
|
||||
}
|
||||
|
||||
@@ -130,11 +124,7 @@ namespace Ndk
|
||||
}
|
||||
m_systemBits.Clear();
|
||||
|
||||
// On informe chaque handle de notre destruction pour éviter qu'il ne continue de pointer sur nous
|
||||
for (EntityHandle* handle : m_handles)
|
||||
handle->OnEntityDestroyed();
|
||||
|
||||
m_handles.clear();
|
||||
UnregisterAllHandles();
|
||||
|
||||
m_valid = false;
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
const EntityHandle EntityHandle::InvalidHandle;
|
||||
}
|
||||
31
SDK/src/NDK/LuaAPI.cpp
Normal file
31
SDK/src/NDK/LuaAPI.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
bool LuaAPI::Initialize()
|
||||
{
|
||||
s_binding = new LuaBinding;
|
||||
return true;
|
||||
}
|
||||
|
||||
void LuaAPI::RegisterClasses(Nz::LuaInstance& instance)
|
||||
{
|
||||
if (!s_binding && !Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize binding");
|
||||
return;
|
||||
}
|
||||
|
||||
s_binding->RegisterClasses(instance);
|
||||
}
|
||||
|
||||
void LuaAPI::Uninitialize()
|
||||
{
|
||||
delete s_binding;
|
||||
}
|
||||
|
||||
LuaBinding* LuaAPI::s_binding = nullptr;
|
||||
}
|
||||
80
SDK/src/NDK/LuaBinding.cpp
Normal file
80
SDK/src/NDK/LuaBinding.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
LuaBinding::LuaBinding() :
|
||||
// Core
|
||||
clockClass("Clock"),
|
||||
directoryClass("Directory"),
|
||||
fileClass("File"),
|
||||
streamClass("Stream"),
|
||||
|
||||
// Math
|
||||
eulerAnglesClass("EulerAngles"),
|
||||
quaternionClass("Quaternion"),
|
||||
vector2dClass("Vector2"),
|
||||
vector3dClass("Vector3"),
|
||||
|
||||
// Network
|
||||
abstractSocketClass("AbstractSocket"),
|
||||
ipAddressClass("IpAddress"),
|
||||
|
||||
// Utility
|
||||
abstractImage("AbstractImage"),
|
||||
nodeClass("Node"),
|
||||
|
||||
// SDK
|
||||
application("Application"),
|
||||
nodeComponent("NodeComponent"),
|
||||
entityClass("Entity"),
|
||||
velocityComponent("VelocityComponent"),
|
||||
worldClass("World")
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
,
|
||||
|
||||
// Audio
|
||||
musicClass("Music"),
|
||||
soundBuffer("SoundBuffer"),
|
||||
soundEmitter("SoundEmitter"),
|
||||
soundClass("Sound"),
|
||||
|
||||
// Graphics
|
||||
instancedRenderable("InstancedRenderable"),
|
||||
modelClass("Model"),
|
||||
|
||||
// SDK
|
||||
consoleClass("Console"),
|
||||
graphicsComponent("GraphicsComponent")
|
||||
#endif
|
||||
{
|
||||
BindCore();
|
||||
BindMath();
|
||||
BindNetwork();
|
||||
BindSDK();
|
||||
BindUtility();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
BindAudio();
|
||||
BindGraphics();
|
||||
BindRenderer();
|
||||
#endif
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterClasses(Nz::LuaInstance& instance)
|
||||
{
|
||||
RegisterCore(instance);
|
||||
RegisterMath(instance);
|
||||
RegisterNetwork(instance);
|
||||
RegisterSDK(instance);
|
||||
RegisterUtility(instance);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
RegisterAudio(instance);
|
||||
RegisterGraphics(instance);
|
||||
RegisterRenderer(instance);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
120
SDK/src/NDK/LuaBinding.hpp
Normal file
120
SDK/src/NDK/LuaBinding.hpp
Normal file
@@ -0,0 +1,120 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_LUABINDING_HPP
|
||||
#define NDK_LUABINDING_HPP
|
||||
|
||||
#include <Nazara/Core.hpp>
|
||||
#include <Nazara/Lua.hpp>
|
||||
#include <Nazara/Math.hpp>
|
||||
#include <Nazara/Network.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
#include <NDK/Application.hpp>
|
||||
#include <NDK/Components.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/Systems.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <Nazara/Audio.hpp>
|
||||
#include <Nazara/Graphics.hpp>
|
||||
#include <Nazara/Renderer.hpp>
|
||||
#include <NDK/Console.hpp>
|
||||
#endif
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class LuaBinding
|
||||
{
|
||||
public:
|
||||
LuaBinding();
|
||||
~LuaBinding() = default;
|
||||
|
||||
void RegisterClasses(Nz::LuaInstance& instance);
|
||||
|
||||
private:
|
||||
void BindCore();
|
||||
void BindMath();
|
||||
void BindNetwork();
|
||||
void BindSDK();
|
||||
void BindUtility();
|
||||
|
||||
template<typename T> void EnableComponentBinding();
|
||||
|
||||
void RegisterCore(Nz::LuaInstance& instance);
|
||||
void RegisterMath(Nz::LuaInstance& instance);
|
||||
void RegisterNetwork(Nz::LuaInstance& instance);
|
||||
void RegisterSDK(Nz::LuaInstance& instance);
|
||||
void RegisterUtility(Nz::LuaInstance& instance);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
void BindAudio();
|
||||
void BindGraphics();
|
||||
void BindRenderer();
|
||||
|
||||
void RegisterAudio(Nz::LuaInstance& instance);
|
||||
void RegisterGraphics(Nz::LuaInstance& instance);
|
||||
void RegisterRenderer(Nz::LuaInstance& instance);
|
||||
#endif
|
||||
|
||||
// Core
|
||||
Nz::LuaClass<Nz::Clock> clockClass;
|
||||
Nz::LuaClass<Nz::Directory> directoryClass;
|
||||
Nz::LuaClass<Nz::File> fileClass;
|
||||
Nz::LuaClass<Nz::Stream> streamClass;
|
||||
|
||||
// Math
|
||||
Nz::LuaClass<Nz::EulerAnglesd> eulerAnglesClass;
|
||||
Nz::LuaClass<Nz::Quaterniond> quaternionClass;
|
||||
Nz::LuaClass<Nz::Vector2d> vector2dClass;
|
||||
Nz::LuaClass<Nz::Vector3d> vector3dClass;
|
||||
|
||||
// Network
|
||||
Nz::LuaClass<Nz::AbstractSocket> abstractSocketClass;
|
||||
Nz::LuaClass<Nz::IpAddress> ipAddressClass;
|
||||
|
||||
// Utility
|
||||
Nz::LuaClass<Nz::AbstractImage*> abstractImage;
|
||||
Nz::LuaClass<Nz::Node> nodeClass;
|
||||
|
||||
// SDK
|
||||
Nz::LuaClass<Application*> application;
|
||||
Nz::LuaClass<EntityHandle> entityClass;
|
||||
Nz::LuaClass<NodeComponentHandle> nodeComponent;
|
||||
Nz::LuaClass<VelocityComponentHandle> velocityComponent;
|
||||
Nz::LuaClass<WorldHandle> worldClass;
|
||||
|
||||
using AddComponentFunc = int(*)(Nz::LuaInstance&, EntityHandle&);
|
||||
using GetComponentFunc = int(*)(Nz::LuaInstance&, BaseComponent&);
|
||||
|
||||
struct ComponentBinding
|
||||
{
|
||||
AddComponentFunc adder;
|
||||
GetComponentFunc getter;
|
||||
bool valid = false;
|
||||
};
|
||||
|
||||
std::vector<ComponentBinding> m_componentBinding;
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
// Audio
|
||||
Nz::LuaClass<Nz::Music> musicClass;
|
||||
Nz::LuaClass<Nz::Sound> soundClass;
|
||||
Nz::LuaClass<Nz::SoundBufferRef> soundBuffer;
|
||||
Nz::LuaClass<Nz::SoundEmitter> soundEmitter;
|
||||
|
||||
// Graphics
|
||||
Nz::LuaClass<Nz::InstancedRenderableRef> instancedRenderable;
|
||||
Nz::LuaClass<Nz::ModelRef> modelClass;
|
||||
|
||||
// SDK
|
||||
Nz::LuaClass<ConsoleHandle> consoleClass;
|
||||
Nz::LuaClass<GraphicsComponentHandle> graphicsComponent;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_LUABINDING_HPP
|
||||
176
SDK/src/NDK/LuaBinding_Audio.cpp
Normal file
176
SDK/src/NDK/LuaBinding_Audio.cpp
Normal file
@@ -0,0 +1,176 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindAudio()
|
||||
{
|
||||
/*********************************** Nz::Music **********************************/
|
||||
musicClass.Inherit(soundEmitter);
|
||||
|
||||
musicClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Music*
|
||||
{
|
||||
return new Nz::Music;
|
||||
});
|
||||
|
||||
//musicClass.SetMethod("Create", &Nz::Music::Create);
|
||||
//musicClass.SetMethod("Destroy", &Nz::Music::Destroy);
|
||||
|
||||
musicClass.BindMethod("EnableLooping", &Nz::Music::EnableLooping);
|
||||
|
||||
musicClass.BindMethod("GetDuration", &Nz::Music::GetDuration);
|
||||
musicClass.BindMethod("GetFormat", &Nz::Music::GetFormat);
|
||||
musicClass.BindMethod("GetPlayingOffset", &Nz::Music::GetPlayingOffset);
|
||||
musicClass.BindMethod("GetSampleCount", &Nz::Music::GetSampleCount);
|
||||
musicClass.BindMethod("GetSampleRate", &Nz::Music::GetSampleRate);
|
||||
musicClass.BindMethod("GetStatus", &Nz::Music::GetStatus);
|
||||
|
||||
musicClass.BindMethod("IsLooping", &Nz::Music::IsLooping);
|
||||
|
||||
musicClass.BindMethod("OpenFromFile", &Nz::Music::OpenFromFile, Nz::MusicParams());
|
||||
|
||||
musicClass.BindMethod("Pause", &Nz::Music::Pause);
|
||||
musicClass.BindMethod("Play", &Nz::Music::Play);
|
||||
|
||||
musicClass.BindMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset);
|
||||
|
||||
musicClass.BindMethod("Stop", &Nz::Music::Stop);
|
||||
|
||||
// Manual
|
||||
musicClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& music) -> int
|
||||
{
|
||||
Nz::StringStream stream("Music(");
|
||||
stream << music.GetFilePath() << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Sound **********************************/
|
||||
soundClass.Inherit(soundEmitter);
|
||||
|
||||
soundClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Sound*
|
||||
{
|
||||
return new Nz::Sound;
|
||||
});
|
||||
|
||||
soundClass.BindMethod("GetBuffer", &Nz::Sound::GetBuffer);
|
||||
|
||||
soundClass.BindMethod("IsPlayable", &Nz::Sound::IsPlayable);
|
||||
soundClass.BindMethod("IsPlaying", &Nz::Sound::IsPlaying);
|
||||
|
||||
soundClass.BindMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams());
|
||||
|
||||
soundClass.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset);
|
||||
|
||||
// Manual
|
||||
soundClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound) -> int
|
||||
{
|
||||
Nz::StringStream stream("Sound(");
|
||||
if (const Nz::SoundBuffer* buffer = sound.GetBuffer())
|
||||
stream << buffer;
|
||||
|
||||
stream << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
|
||||
/*********************************** Nz::SoundBuffer **********************************/
|
||||
soundBuffer.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::SoundBufferRef*
|
||||
{
|
||||
return new Nz::SoundBufferRef(new Nz::SoundBuffer);
|
||||
});
|
||||
|
||||
soundBuffer.BindMethod("Destroy", &Nz::SoundBuffer::Destroy);
|
||||
|
||||
soundBuffer.BindMethod("GetDuration", &Nz::SoundBuffer::GetDuration);
|
||||
soundBuffer.BindMethod("GetFormat", &Nz::SoundBuffer::GetFormat);
|
||||
soundBuffer.BindMethod("GetSampleCount", &Nz::SoundBuffer::GetSampleCount);
|
||||
soundBuffer.BindMethod("GetSampleRate", &Nz::SoundBuffer::GetSampleRate);
|
||||
|
||||
soundBuffer.BindMethod("IsValid", &Nz::SoundBuffer::IsValid);
|
||||
|
||||
soundBuffer.BindMethod("LoadFromFile", &Nz::SoundBuffer::LoadFromFile, Nz::SoundBufferParams());
|
||||
|
||||
soundBuffer.BindStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported);
|
||||
|
||||
// Manual
|
||||
soundBuffer.BindMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int
|
||||
{
|
||||
int index = 1;
|
||||
Nz::AudioFormat format = lua.Check<Nz::AudioFormat>(&index);
|
||||
unsigned int sampleCount = lua.Check<unsigned int>(&index);
|
||||
unsigned int sampleRate = lua.Check<unsigned int>(&index);
|
||||
|
||||
std::size_t bufferSize = 0;
|
||||
const char* buffer = lua.CheckString(index, &bufferSize);
|
||||
lua.ArgCheck(buffer && bufferSize >= sampleCount * sizeof(Nz::Int16), index, "Invalid buffer");
|
||||
|
||||
lua.PushBoolean(instance->Create(format, sampleCount, sampleRate, reinterpret_cast<const Nz::Int16*>(buffer)));
|
||||
return 1;
|
||||
});
|
||||
|
||||
soundBuffer.BindMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int
|
||||
{
|
||||
lua.PushString(reinterpret_cast<const char*>(instance->GetSamples()), instance->GetSampleCount() * sizeof(Nz::Int16));
|
||||
return 1;
|
||||
});
|
||||
|
||||
soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& soundBuffer) -> int
|
||||
{
|
||||
Nz::StringStream stream("SoundBuffer(");
|
||||
if (soundBuffer->IsValid())
|
||||
{
|
||||
Nz::String filePath = soundBuffer->GetFilePath();
|
||||
if (!filePath.IsEmpty())
|
||||
stream << "File: " << filePath << ", ";
|
||||
|
||||
stream << "Duration: " << soundBuffer->GetDuration() / 1000.f << "s";
|
||||
}
|
||||
stream << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
|
||||
/*********************************** Nz::SoundEmitter **********************************/
|
||||
soundEmitter.BindMethod("EnableLooping", &Nz::SoundEmitter::EnableLooping);
|
||||
soundEmitter.BindMethod("EnableSpatialization", &Nz::SoundEmitter::EnableSpatialization);
|
||||
|
||||
soundEmitter.BindMethod("GetAttenuation", &Nz::SoundEmitter::GetAttenuation);
|
||||
soundEmitter.BindMethod("GetDuration", &Nz::SoundEmitter::GetDuration);
|
||||
soundEmitter.BindMethod("GetMinDistance", &Nz::SoundEmitter::GetMinDistance);
|
||||
soundEmitter.BindMethod("GetPitch", &Nz::SoundEmitter::GetPitch);
|
||||
soundEmitter.BindMethod("GetPlayingOffset", &Nz::SoundEmitter::GetPlayingOffset);
|
||||
soundEmitter.BindMethod("GetPosition", &Nz::Sound::GetPosition);
|
||||
soundEmitter.BindMethod("GetStatus", &Nz::SoundEmitter::GetStatus);
|
||||
soundEmitter.BindMethod("GetVelocity", &Nz::Sound::GetVelocity);
|
||||
soundEmitter.BindMethod("GetVolume", &Nz::SoundEmitter::GetVolume);
|
||||
|
||||
soundEmitter.BindMethod("IsLooping", &Nz::SoundEmitter::IsLooping);
|
||||
soundEmitter.BindMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized);
|
||||
|
||||
soundEmitter.BindMethod("Pause", &Nz::SoundEmitter::Pause);
|
||||
soundEmitter.BindMethod("Play", &Nz::SoundEmitter::Play);
|
||||
|
||||
soundEmitter.BindMethod("SetAttenuation", &Nz::SoundEmitter::SetAttenuation);
|
||||
soundEmitter.BindMethod("SetMinDistance", &Nz::SoundEmitter::SetMinDistance);
|
||||
soundEmitter.BindMethod("SetPitch", &Nz::SoundEmitter::SetPitch);
|
||||
soundEmitter.BindMethod("SetPosition", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetPosition);
|
||||
soundEmitter.BindMethod("SetVelocity", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetVelocity);
|
||||
soundEmitter.BindMethod("SetVolume", &Nz::SoundEmitter::SetVolume);
|
||||
|
||||
soundEmitter.BindMethod("Stop", &Nz::SoundEmitter::Stop);
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterAudio(Nz::LuaInstance& instance)
|
||||
{
|
||||
musicClass.Register(instance);
|
||||
soundClass.Register(instance);
|
||||
soundBuffer.Register(instance);
|
||||
soundEmitter.Register(instance);
|
||||
}
|
||||
}
|
||||
280
SDK/src/NDK/LuaBinding_Core.cpp
Normal file
280
SDK/src/NDK/LuaBinding_Core.cpp
Normal file
@@ -0,0 +1,280 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindCore()
|
||||
{
|
||||
/*********************************** Nz::Clock **********************************/
|
||||
clockClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Clock*
|
||||
{
|
||||
int argIndex = 1;
|
||||
return new Nz::Clock(lua.Check<Nz::Int64>(&argIndex, 0), lua.Check<bool>(&argIndex, false));
|
||||
});
|
||||
|
||||
clockClass.BindMethod("GetMicroseconds", &Nz::Clock::GetMicroseconds);
|
||||
clockClass.BindMethod("GetMilliseconds", &Nz::Clock::GetMilliseconds);
|
||||
clockClass.BindMethod("GetSeconds", &Nz::Clock::GetSeconds);
|
||||
clockClass.BindMethod("IsPaused", &Nz::Clock::IsPaused);
|
||||
clockClass.BindMethod("Pause", &Nz::Clock::Pause);
|
||||
clockClass.BindMethod("Restart", &Nz::Clock::Restart);
|
||||
clockClass.BindMethod("Unpause", &Nz::Clock::Unpause);
|
||||
|
||||
// Manual
|
||||
clockClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& clock) -> int {
|
||||
Nz::StringStream stream("Clock(Elapsed: ");
|
||||
stream << clock.GetSeconds();
|
||||
stream << "s, Paused: ";
|
||||
stream << clock.IsPaused();
|
||||
stream << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
|
||||
/********************************* Nz::Directory ********************************/
|
||||
directoryClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Directory*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 1U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return new Nz::Directory;
|
||||
|
||||
case 1:
|
||||
return new Nz::Directory(lua.Check<Nz::String>(&argIndex));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
directoryClass.BindMethod("Close", &Nz::Directory::Close);
|
||||
directoryClass.BindMethod("Exists", &Nz::Directory::Exists);
|
||||
directoryClass.BindMethod("GetPath", &Nz::Directory::GetPath);
|
||||
directoryClass.BindMethod("GetPattern", &Nz::Directory::GetPattern);
|
||||
directoryClass.BindMethod("GetResultName", &Nz::Directory::GetResultName);
|
||||
directoryClass.BindMethod("GetResultPath", &Nz::Directory::GetResultPath);
|
||||
directoryClass.BindMethod("GetResultSize", &Nz::Directory::GetResultSize);
|
||||
directoryClass.BindMethod("IsOpen", &Nz::Directory::IsOpen);
|
||||
directoryClass.BindMethod("IsResultDirectory", &Nz::Directory::IsResultDirectory);
|
||||
directoryClass.BindMethod("NextResult", &Nz::Directory::NextResult, true);
|
||||
directoryClass.BindMethod("Open", &Nz::Directory::Open);
|
||||
directoryClass.BindMethod("SetPath", &Nz::Directory::SetPath);
|
||||
directoryClass.BindMethod("SetPattern", &Nz::Directory::SetPattern);
|
||||
|
||||
directoryClass.BindStaticMethod("Copy", Nz::Directory::Copy);
|
||||
directoryClass.BindStaticMethod("Create", Nz::Directory::Create);
|
||||
directoryClass.BindStaticMethod("Exists", Nz::Directory::Exists);
|
||||
directoryClass.BindStaticMethod("GetCurrent", Nz::Directory::GetCurrent);
|
||||
directoryClass.BindStaticMethod("Remove", Nz::Directory::Remove);
|
||||
directoryClass.BindStaticMethod("SetCurrent", Nz::Directory::SetCurrent);
|
||||
|
||||
// Manual
|
||||
directoryClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& directory) -> int {
|
||||
Nz::StringStream stream("Directory(");
|
||||
stream << directory.GetPath();
|
||||
stream << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Stream ***********************************/
|
||||
streamClass.BindMethod("EnableTextMode", &Nz::Stream::EnableTextMode);
|
||||
streamClass.BindMethod("Flush", &Nz::Stream::Flush);
|
||||
streamClass.BindMethod("GetCursorPos", &Nz::Stream::GetCursorPos);
|
||||
streamClass.BindMethod("GetDirectory", &Nz::Stream::GetDirectory);
|
||||
streamClass.BindMethod("GetPath", &Nz::Stream::GetPath);
|
||||
streamClass.BindMethod("GetOpenMode", &Nz::Stream::GetOpenMode);
|
||||
streamClass.BindMethod("GetStreamOptions", &Nz::Stream::GetStreamOptions);
|
||||
streamClass.BindMethod("GetSize", &Nz::Stream::GetSize);
|
||||
streamClass.BindMethod("ReadLine", &Nz::Stream::ReadLine, 0U);
|
||||
streamClass.BindMethod("IsReadable", &Nz::Stream::IsReadable);
|
||||
streamClass.BindMethod("IsSequential", &Nz::Stream::IsSequential);
|
||||
streamClass.BindMethod("IsTextModeEnabled", &Nz::Stream::IsTextModeEnabled);
|
||||
streamClass.BindMethod("IsWritable", &Nz::Stream::IsWritable);
|
||||
streamClass.BindMethod("SetCursorPos", &Nz::Stream::SetCursorPos);
|
||||
|
||||
streamClass.BindMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int {
|
||||
int argIndex = 1;
|
||||
|
||||
std::size_t length = lua.Check<std::size_t>(&argIndex);
|
||||
|
||||
std::unique_ptr<char[]> buffer(new char[length]);
|
||||
std::size_t readLength = stream.Read(buffer.get(), length);
|
||||
|
||||
lua.PushString(Nz::String(buffer.get(), readLength));
|
||||
return 1;
|
||||
});
|
||||
|
||||
streamClass.BindMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int {
|
||||
int argIndex = 1;
|
||||
|
||||
std::size_t bufferSize = 0;
|
||||
const char* buffer = lua.CheckString(argIndex, &bufferSize);
|
||||
|
||||
if (stream.IsTextModeEnabled())
|
||||
lua.Push(stream.Write(Nz::String(buffer, bufferSize)));
|
||||
else
|
||||
lua.Push(stream.Write(buffer, bufferSize));
|
||||
return 1;
|
||||
});
|
||||
|
||||
/*********************************** Nz::File ***********************************/
|
||||
fileClass.Inherit(streamClass);
|
||||
|
||||
fileClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::File*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return new Nz::File;
|
||||
|
||||
case 1:
|
||||
return new Nz::File(lua.Check<Nz::String>(&argIndex));
|
||||
|
||||
case 2:
|
||||
return new Nz::File(lua.Check<Nz::String>(&argIndex), lua.Check<Nz::UInt32>(&argIndex));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
fileClass.BindMethod("Close", &Nz::File::Close);
|
||||
fileClass.BindMethod("Copy", &Nz::File::Copy);
|
||||
fileClass.BindMethod("Delete", &Nz::File::Delete);
|
||||
fileClass.BindMethod("EndOfFile", &Nz::File::EndOfFile);
|
||||
fileClass.BindMethod("Exists", &Nz::File::Exists);
|
||||
fileClass.BindMethod("GetCreationTime", &Nz::File::GetCreationTime);
|
||||
fileClass.BindMethod("GetFileName", &Nz::File::GetFileName);
|
||||
fileClass.BindMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime);
|
||||
fileClass.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
||||
fileClass.BindMethod("IsOpen", &Nz::File::IsOpen);
|
||||
fileClass.BindMethod("Rename", &Nz::File::GetLastWriteTime);
|
||||
fileClass.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
||||
fileClass.BindMethod("SetFile", &Nz::File::GetLastWriteTime);
|
||||
|
||||
fileClass.BindStaticMethod("AbsolutePath", &Nz::File::AbsolutePath);
|
||||
fileClass.BindStaticMethod("ComputeHash", (Nz::ByteArray (*)(Nz::HashType, const Nz::String&)) &Nz::File::ComputeHash);
|
||||
fileClass.BindStaticMethod("Copy", &Nz::File::Copy);
|
||||
fileClass.BindStaticMethod("Delete", &Nz::File::Delete);
|
||||
fileClass.BindStaticMethod("Exists", &Nz::File::Exists);
|
||||
//fileClass.SetStaticMethod("GetCreationTime", &Nz::File::GetCreationTime);
|
||||
fileClass.BindStaticMethod("GetDirectory", &Nz::File::GetDirectory);
|
||||
//fileClass.SetStaticMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime);
|
||||
//fileClass.SetStaticMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
||||
fileClass.BindStaticMethod("GetSize", &Nz::File::GetSize);
|
||||
fileClass.BindStaticMethod("IsAbsolute", &Nz::File::IsAbsolute);
|
||||
fileClass.BindStaticMethod("NormalizePath", &Nz::File::NormalizePath);
|
||||
fileClass.BindStaticMethod("NormalizeSeparators", &Nz::File::NormalizeSeparators);
|
||||
fileClass.BindStaticMethod("Rename", &Nz::File::Rename);
|
||||
|
||||
// Manual
|
||||
fileClass.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& file) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
return lua.Push(file.Open(lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen)));
|
||||
|
||||
case 2:
|
||||
return lua.Push(file.Open(lua.Check<Nz::String>(&argIndex), lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen)));
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method Open");
|
||||
return 0;
|
||||
});
|
||||
|
||||
fileClass.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& file) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
return lua.Push(file.SetCursorPos(lua.Check<Nz::UInt64>(&argIndex)));
|
||||
|
||||
case 2:
|
||||
return lua.Push(file.SetCursorPos(lua.Check<Nz::CursorPosition>(&argIndex), lua.Check<Nz::Int64>(&argIndex)));
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method SetCursorPos");
|
||||
return 0;
|
||||
});
|
||||
|
||||
fileClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& file) -> int {
|
||||
Nz::StringStream stream("File(");
|
||||
if (file.IsOpen())
|
||||
stream << "Path: " << file.GetPath();
|
||||
|
||||
stream << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterCore(Nz::LuaInstance& instance)
|
||||
{
|
||||
// Classes
|
||||
clockClass.Register(instance);
|
||||
directoryClass.Register(instance);
|
||||
fileClass.Register(instance);
|
||||
streamClass.Register(instance);
|
||||
|
||||
// Enums
|
||||
|
||||
// Nz::CursorPosition
|
||||
static_assert(Nz::CursorPosition_Max + 1 == 3, "Nz::CursorPosition has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 3);
|
||||
{
|
||||
instance.SetField("AtBegin", Nz::CursorPosition_AtBegin);
|
||||
instance.SetField("AtCurrent", Nz::CursorPosition_AtCurrent);
|
||||
instance.SetField("AtEnd", Nz::CursorPosition_AtEnd);
|
||||
}
|
||||
instance.SetGlobal("CursorPosition");
|
||||
|
||||
// Nz::HashType
|
||||
static_assert(Nz::HashType_Max + 1 == 9, "Nz::HashType has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 9);
|
||||
{
|
||||
instance.SetField("CRC32", Nz::HashType_CRC32);
|
||||
instance.SetField("Fletcher16", Nz::HashType_Fletcher16);
|
||||
instance.SetField("MD5", Nz::HashType_MD5);
|
||||
instance.SetField("SHA1", Nz::HashType_SHA1);
|
||||
instance.SetField("SHA224", Nz::HashType_SHA224);
|
||||
instance.SetField("SHA256", Nz::HashType_SHA256);
|
||||
instance.SetField("SHA384", Nz::HashType_SHA384);
|
||||
instance.SetField("SHA512", Nz::HashType_SHA512);
|
||||
instance.SetField("Whirlpool", Nz::HashType_Whirlpool);
|
||||
}
|
||||
instance.SetGlobal("HashType");
|
||||
|
||||
// Nz::OpenMode
|
||||
static_assert(Nz::OpenMode_Max + 1 == 2 * (64), "Nz::OpenModeFlags has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 8);
|
||||
{
|
||||
instance.SetField("Append", Nz::OpenMode_Append);
|
||||
instance.SetField("NotOpen", Nz::OpenMode_NotOpen);
|
||||
instance.SetField("Lock", Nz::OpenMode_Lock);
|
||||
instance.SetField("ReadOnly", Nz::OpenMode_ReadOnly);
|
||||
instance.SetField("ReadWrite", Nz::OpenMode_ReadWrite);
|
||||
instance.SetField("Text", Nz::OpenMode_Text);
|
||||
instance.SetField("Truncate", Nz::OpenMode_Truncate);
|
||||
instance.SetField("WriteOnly", Nz::OpenMode_WriteOnly);
|
||||
}
|
||||
instance.SetGlobal("OpenMode");
|
||||
}
|
||||
}
|
||||
47
SDK/src/NDK/LuaBinding_Graphics.cpp
Normal file
47
SDK/src/NDK/LuaBinding_Graphics.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindGraphics()
|
||||
{
|
||||
/*********************************** Nz::InstancedRenderable ***********************************/
|
||||
|
||||
/*********************************** Nz::Model ***********************************/
|
||||
modelClass.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::ModelRef* model) -> Nz::InstancedRenderableRef*
|
||||
{
|
||||
return reinterpret_cast<Nz::InstancedRenderableRef*>(model); //TODO: Make a ObjectRefCast
|
||||
});
|
||||
|
||||
modelClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::ModelRef*
|
||||
{
|
||||
return new Nz::ModelRef(new Nz::Model);
|
||||
});
|
||||
|
||||
//modelClass.SetMethod("GetMaterial", &Nz::Model::GetMaterial);
|
||||
modelClass.BindMethod("GetMaterialCount", &Nz::Model::GetMaterialCount);
|
||||
//modelClass.SetMethod("GetMesh", &Nz::Model::GetMesh);
|
||||
modelClass.BindMethod("GetSkin", &Nz::Model::GetSkin);
|
||||
modelClass.BindMethod("GetSkinCount", &Nz::Model::GetSkinCount);
|
||||
|
||||
modelClass.BindMethod("IsAnimated", &Nz::Model::IsAnimated);
|
||||
modelClass.BindMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters());
|
||||
|
||||
modelClass.BindMethod("Reset", &Nz::Model::Reset);
|
||||
|
||||
//modelClass.SetMethod("SetMaterial", &Nz::Model::SetMaterial);
|
||||
//modelClass.SetMethod("SetMesh", &Nz::Model::SetMesh);
|
||||
//modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence);
|
||||
modelClass.BindMethod("SetSkin", &Nz::Model::SetSkin);
|
||||
modelClass.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount);
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterGraphics(Nz::LuaInstance& instance)
|
||||
{
|
||||
instancedRenderable.Register(instance);
|
||||
modelClass.Register(instance);
|
||||
}
|
||||
}
|
||||
482
SDK/src/NDK/LuaBinding_Math.cpp
Normal file
482
SDK/src/NDK/LuaBinding_Math.cpp
Normal file
@@ -0,0 +1,482 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <cstring>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindMath()
|
||||
{
|
||||
/*********************************** Nz::EulerAngles **********************************/
|
||||
eulerAnglesClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::EulerAnglesd*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 3U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return new Nz::EulerAnglesd(0.0, 0.0, 0.0);
|
||||
|
||||
case 1:
|
||||
return new Nz::EulerAnglesd(*(*static_cast<Nz::EulerAnglesd**>(lua.CheckUserdata(1, "EulerAngles"))));
|
||||
|
||||
case 3:
|
||||
return new Nz::EulerAnglesd(lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3));
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for EulerAngles constructor");
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
eulerAnglesClass.BindMethod("__tostring", &Nz::EulerAnglesd::ToString);
|
||||
|
||||
eulerAnglesClass.SetGetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* ypr = lua.CheckString(1, &length);
|
||||
|
||||
switch (length)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
switch (ypr[0])
|
||||
{
|
||||
case 'p':
|
||||
lua.Push(instance.pitch);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.yaw);
|
||||
return true;
|
||||
|
||||
case 'r':
|
||||
lua.Push(instance.roll);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 3:
|
||||
{
|
||||
if (std::memcmp(ypr, "yaw", 3) != 0)
|
||||
break;
|
||||
|
||||
lua.Push(instance.yaw);
|
||||
return true;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
if (std::memcmp(ypr, "roll", 4) != 0)
|
||||
break;
|
||||
|
||||
lua.Push(instance.roll);
|
||||
return true;
|
||||
}
|
||||
|
||||
case 5:
|
||||
{
|
||||
if (std::memcmp(ypr, "pitch", 5) != 0)
|
||||
break;
|
||||
|
||||
lua.Push(instance.pitch);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
eulerAnglesClass.SetSetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* ypr = lua.CheckString(1, &length);
|
||||
double value = lua.CheckNumber(2);
|
||||
|
||||
switch (length)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
switch (ypr[0])
|
||||
{
|
||||
case 'p':
|
||||
instance.pitch = value;
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
instance.yaw = value;
|
||||
return true;
|
||||
|
||||
case 'r':
|
||||
instance.roll = value;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 3:
|
||||
{
|
||||
if (std::memcmp(ypr, "yaw", 3) != 0)
|
||||
break;
|
||||
|
||||
instance.yaw = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
if (std::memcmp(ypr, "roll", 4) != 0)
|
||||
break;
|
||||
|
||||
instance.roll = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
case 5:
|
||||
{
|
||||
if (std::memcmp(ypr, "pitch", 5) != 0)
|
||||
break;
|
||||
|
||||
instance.pitch = value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Quaternion **********************************/
|
||||
quaternionClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Quaterniond*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return new Nz::Quaterniond(1.0, 0.0, 0.0, 0.0);
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, "EulerAngles"))
|
||||
return new Nz::Quaterniond(*(*static_cast<Nz::EulerAnglesd**>(lua.ToUserdata(1))));
|
||||
else if (lua.IsOfType(1, "Quaternion"))
|
||||
return new Nz::Quaterniond(*(*static_cast<Nz::Quaterniond**>(lua.ToUserdata(1))));
|
||||
}
|
||||
|
||||
case 2:
|
||||
return new Nz::Quaterniond(lua.CheckNumber(1), *(*static_cast<Nz::Vector3d**>(lua.CheckUserdata(2, "Vector3"))));
|
||||
|
||||
case 4:
|
||||
return new Nz::Quaterniond(lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3), lua.CheckNumber(4));
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for Quaternion constructor");
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
quaternionClass.BindMethod("__tostring", &Nz::Quaterniond::ToString);
|
||||
|
||||
quaternionClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* wxyz = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
return false;
|
||||
|
||||
switch (wxyz[0])
|
||||
{
|
||||
case 'w':
|
||||
lua.Push(instance.w);
|
||||
return true;
|
||||
|
||||
case 'x':
|
||||
lua.Push(instance.x);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.y);
|
||||
return true;
|
||||
|
||||
case 'z':
|
||||
lua.Push(instance.z);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
quaternionClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* wxyz = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
return false;
|
||||
|
||||
double value = lua.CheckNumber(2);
|
||||
|
||||
switch (wxyz[0])
|
||||
{
|
||||
case 'w':
|
||||
instance.w = value;
|
||||
return true;
|
||||
|
||||
case 'x':
|
||||
instance.x = value;
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
instance.y = value;
|
||||
return true;
|
||||
|
||||
case 'z':
|
||||
instance.z = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Vector2 **********************************/
|
||||
vector2dClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Vector2d*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 2:
|
||||
return new Nz::Vector2d(lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0));
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
return new Nz::Vector2d(lua.CheckNumber(1));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
return new Nz::Vector2d(*(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for Vector2 constructor");
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
vector2dClass.BindMethod("__tostring", &Nz::Vector2d::ToString);
|
||||
|
||||
vector2dClass.SetGetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
if (index < 1 || index > 2)
|
||||
return false;
|
||||
|
||||
lua.Push(instance[index - 1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
std::size_t length;
|
||||
const char* xy = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
switch (xy[0])
|
||||
{
|
||||
case 'x':
|
||||
lua.Push(instance.x);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.y);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
vector2dClass.SetSetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
if (index < 1 || index > 2)
|
||||
return false;
|
||||
|
||||
instance[index - 1] = lua.CheckNumber(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
std::size_t length;
|
||||
const char* xy = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
double value = lua.CheckNumber(2);
|
||||
|
||||
switch (xy[0])
|
||||
{
|
||||
case 'x':
|
||||
instance.x = value;
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
instance.y = value;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Vector3 **********************************/
|
||||
vector3dClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Vector3d*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 3U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 3:
|
||||
return new Nz::Vector3d(lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0));
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
return new Nz::Vector3d(lua.CheckNumber(1), *(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
return new Nz::Vector3d(*(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))));
|
||||
else if (lua.IsOfType(1, "Vector3"))
|
||||
return new Nz::Vector3d(*(*static_cast<Nz::Vector3d**>(lua.ToUserdata(1))));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
return new Nz::Vector3d(lua.CheckNumber(1), *(*static_cast<Nz::Vector2d**>(lua.CheckUserdata(1, "Vector2"))));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
return new Nz::Vector3d(*(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))), lua.CheckNumber(2));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for constructor");
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
vector3dClass.BindMethod("__tostring", &Nz::Vector3d::ToString);
|
||||
|
||||
vector3dClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
if (index < 1 || index > 3)
|
||||
return false;
|
||||
|
||||
lua.Push(instance[index - 1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
std::size_t length;
|
||||
const char* xyz = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
switch (xyz[0])
|
||||
{
|
||||
case 'x':
|
||||
lua.Push(instance.x);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.y);
|
||||
return true;
|
||||
|
||||
case 'z':
|
||||
lua.Push(instance.z);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
vector3dClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
if (index < 1 || index > 3)
|
||||
return false;
|
||||
|
||||
instance[index - 1] = lua.CheckNumber(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
std::size_t length;
|
||||
const char* xyz = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
double value = lua.CheckNumber(2);
|
||||
|
||||
switch (xyz[0])
|
||||
{
|
||||
case 'x':
|
||||
instance.x = value;
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
instance.y = value;
|
||||
return true;
|
||||
|
||||
case 'z':
|
||||
instance.z = value;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterMath(Nz::LuaInstance& instance)
|
||||
{
|
||||
eulerAnglesClass.Register(instance);
|
||||
quaternionClass.Register(instance);
|
||||
vector2dClass.Register(instance);
|
||||
vector3dClass.Register(instance);
|
||||
}
|
||||
}
|
||||
214
SDK/src/NDK/LuaBinding_Network.cpp
Normal file
214
SDK/src/NDK/LuaBinding_Network.cpp
Normal file
@@ -0,0 +1,214 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindNetwork()
|
||||
{
|
||||
/*********************************** Nz::AbstractSocket **********************************/
|
||||
abstractSocketClass.BindMethod("Close", &Nz::AbstractSocket::Close);
|
||||
abstractSocketClass.BindMethod("EnableBlocking", &Nz::AbstractSocket::EnableBlocking);
|
||||
abstractSocketClass.BindMethod("GetLastError", &Nz::AbstractSocket::GetLastError);
|
||||
abstractSocketClass.BindMethod("GetState", &Nz::AbstractSocket::GetState);
|
||||
abstractSocketClass.BindMethod("GetType", &Nz::AbstractSocket::GetType);
|
||||
abstractSocketClass.BindMethod("IsBlockingEnabled", &Nz::AbstractSocket::IsBlockingEnabled);
|
||||
abstractSocketClass.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes);
|
||||
|
||||
/*********************************** Nz::IpAddress **********************************/
|
||||
ipAddressClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::IpAddress*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 9U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return new Nz::IpAddress;
|
||||
|
||||
case 1:
|
||||
return new Nz::IpAddress(lua.CheckString(argIndex));
|
||||
|
||||
case 4:
|
||||
case 5:
|
||||
return new Nz::IpAddress(lua.Check<Nz::UInt8>(&argIndex), lua.Check<Nz::UInt8>(&argIndex), lua.Check<Nz::UInt8>(&argIndex), lua.Check<Nz::UInt8>(&argIndex), lua.Check<Nz::UInt16>(&argIndex, 0));
|
||||
|
||||
case 8:
|
||||
case 9:
|
||||
return new Nz::IpAddress(lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex),
|
||||
lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex, 0));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
ipAddressClass.BindMethod("GetPort", &Nz::IpAddress::GetPort);
|
||||
ipAddressClass.BindMethod("GetProtocol", &Nz::IpAddress::GetProtocol);
|
||||
ipAddressClass.BindMethod("IsLoopback", &Nz::IpAddress::IsLoopback);
|
||||
ipAddressClass.BindMethod("IsValid", &Nz::IpAddress::IsValid);
|
||||
ipAddressClass.BindMethod("ToUInt32", &Nz::IpAddress::ToUInt32);
|
||||
ipAddressClass.BindMethod("__tostring", &Nz::IpAddress::ToString);
|
||||
|
||||
ipAddressClass.BindStaticMethod("ResolveAddress", [] (Nz::LuaInstance& instance) -> int
|
||||
{
|
||||
Nz::String service;
|
||||
Nz::ResolveError error = Nz::ResolveError_Unknown;
|
||||
|
||||
int argIndex = 1;
|
||||
Nz::String hostName = Nz::IpAddress::ResolveAddress(instance.Check<Nz::IpAddress>(&argIndex), &service, &error);
|
||||
|
||||
if (error == Nz::ResolveError_NoError)
|
||||
{
|
||||
instance.Push(hostName);
|
||||
instance.Push(service);
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
instance.PushBoolean(false);
|
||||
instance.Push(error);
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
|
||||
ipAddressClass.BindStaticMethod("ResolveHostname", [] (Nz::LuaInstance& instance) -> int
|
||||
{
|
||||
Nz::ResolveError error = Nz::ResolveError_Unknown;
|
||||
|
||||
int argIndex = 1;
|
||||
Nz::NetProtocol protocol = instance.Check<Nz::NetProtocol>(&argIndex);
|
||||
Nz::String hostname = instance.Check<Nz::String>(&argIndex);
|
||||
Nz::String service = instance.Check<Nz::String>(&argIndex, "http");
|
||||
|
||||
std::vector<Nz::HostnameInfo> addresses = Nz::IpAddress::ResolveHostname(protocol, hostname, service, &error);
|
||||
if (error == Nz::ResolveError_NoError)
|
||||
{
|
||||
int index = 1;
|
||||
instance.PushTable(addresses.size());
|
||||
for (Nz::HostnameInfo& info : addresses)
|
||||
{
|
||||
instance.PushInteger(index++);
|
||||
instance.PushTable(0, 4);
|
||||
instance.SetField("Address", std::move(info.address));
|
||||
instance.SetField("CanonicalName", std::move(info.canonicalName));
|
||||
instance.SetField("Protocol", std::move(info.protocol));
|
||||
instance.SetField("SocketType", std::move(info.socketType));
|
||||
instance.SetTable();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
instance.PushBoolean(false);
|
||||
instance.Push(error);
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterNetwork(Nz::LuaInstance& instance)
|
||||
{
|
||||
// Classes
|
||||
abstractSocketClass.Register(instance);
|
||||
ipAddressClass.Register(instance);
|
||||
|
||||
// Enums
|
||||
|
||||
// Nz::NetProtocol
|
||||
static_assert(Nz::NetProtocol_Max + 1 == 4, "Nz::NetProtocol has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 4);
|
||||
{
|
||||
instance.SetField("Any", Nz::NetProtocol_Any);
|
||||
instance.SetField("IPv4", Nz::NetProtocol_IPv4);
|
||||
instance.SetField("IPv6", Nz::NetProtocol_IPv6);
|
||||
instance.SetField("Unknown", Nz::NetProtocol_Unknown);
|
||||
}
|
||||
instance.SetGlobal("NetProtocol");
|
||||
|
||||
// Nz::PacketPriority
|
||||
static_assert(Nz::PacketPriority_Max + 1 == 4, "Nz::PacketPriority has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 6);
|
||||
{
|
||||
instance.SetField("High", Nz::PacketPriority_High);
|
||||
instance.SetField("Highest", Nz::PacketPriority_Highest);
|
||||
instance.SetField("Immediate", Nz::PacketPriority_Immediate);
|
||||
instance.SetField("Medium", Nz::PacketPriority_Medium);
|
||||
instance.SetField("Low", Nz::PacketPriority_Low);
|
||||
instance.SetField("Lowest", Nz::PacketPriority_Lowest);
|
||||
}
|
||||
instance.SetGlobal("PacketPriority");
|
||||
|
||||
// Nz::PacketReliability
|
||||
static_assert(Nz::PacketReliability_Max + 1 == 3, "Nz::PacketReliability has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 3);
|
||||
{
|
||||
instance.SetField("Reliable", Nz::PacketReliability_Reliable);
|
||||
instance.SetField("ReliableOrdered", Nz::PacketReliability_ReliableOrdered);
|
||||
instance.SetField("Unreliable", Nz::PacketReliability_Unreliable);
|
||||
}
|
||||
instance.SetGlobal("PacketReliability");
|
||||
|
||||
// Nz::ResolveError
|
||||
static_assert(Nz::ResolveError_Max + 1 == 9, "Nz::ResolveError has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 9);
|
||||
{
|
||||
instance.SetField("Internal", Nz::ResolveError_Internal);
|
||||
instance.SetField("ResourceError", Nz::ResolveError_ResourceError);
|
||||
instance.SetField("NoError", Nz::ResolveError_NoError);
|
||||
instance.SetField("NonRecoverable", Nz::ResolveError_NonRecoverable);
|
||||
instance.SetField("NotFound", Nz::ResolveError_NotFound);
|
||||
instance.SetField("NotInitialized", Nz::ResolveError_NotInitialized);
|
||||
instance.SetField("ProtocolNotSupported", Nz::ResolveError_ProtocolNotSupported);
|
||||
instance.SetField("TemporaryFailure", Nz::ResolveError_TemporaryFailure);
|
||||
instance.SetField("Unknown", Nz::ResolveError_Unknown);
|
||||
}
|
||||
instance.SetGlobal("ResolveError");
|
||||
|
||||
// Nz::SocketError
|
||||
static_assert(Nz::SocketError_Max + 1 == 15, "Nz::ResolveError has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 15);
|
||||
{
|
||||
instance.SetField("AddressNotAvailable", Nz::SocketError_AddressNotAvailable);
|
||||
instance.SetField("ConnectionClosed", Nz::SocketError_ConnectionClosed);
|
||||
instance.SetField("ConnectionRefused", Nz::SocketError_ConnectionRefused);
|
||||
instance.SetField("DatagramSize", Nz::SocketError_DatagramSize);
|
||||
instance.SetField("Internal", Nz::SocketError_Internal);
|
||||
instance.SetField("Packet", Nz::SocketError_Packet);
|
||||
instance.SetField("NetworkError", Nz::SocketError_NetworkError);
|
||||
instance.SetField("NoError", Nz::SocketError_NoError);
|
||||
instance.SetField("NotInitialized", Nz::SocketError_NotInitialized);
|
||||
instance.SetField("NotSupported", Nz::SocketError_NotSupported);
|
||||
instance.SetField("ResolveError", Nz::SocketError_ResolveError);
|
||||
instance.SetField("ResourceError", Nz::SocketError_ResourceError);
|
||||
instance.SetField("TimedOut", Nz::SocketError_TimedOut);
|
||||
instance.SetField("Unknown", Nz::SocketError_Unknown);
|
||||
instance.SetField("UnreachableHost", Nz::SocketError_UnreachableHost);
|
||||
}
|
||||
instance.SetGlobal("SocketError");
|
||||
|
||||
// Nz::SocketState
|
||||
static_assert(Nz::SocketState_Max + 1 == 5, "Nz::SocketState has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 5);
|
||||
{
|
||||
instance.SetField("Bound", Nz::SocketState_Bound);
|
||||
instance.SetField("Connecting", Nz::SocketState_Connecting);
|
||||
instance.SetField("Connected", Nz::SocketState_Connected);
|
||||
instance.SetField("NotConnected", Nz::SocketState_NotConnected);
|
||||
instance.SetField("Resolving", Nz::SocketState_Resolving);
|
||||
}
|
||||
instance.SetGlobal("SocketState");
|
||||
|
||||
// Nz::SocketType
|
||||
static_assert(Nz::SocketType_Max + 1 == 4, "Nz::SocketState has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 4);
|
||||
{
|
||||
instance.SetField("Raw", Nz::SocketType_Raw);
|
||||
instance.SetField("TCP", Nz::SocketType_TCP);
|
||||
instance.SetField("UDP", Nz::SocketType_UDP);
|
||||
instance.SetField("Unknown", Nz::SocketType_Unknown);
|
||||
}
|
||||
instance.SetGlobal("SocketType");
|
||||
}
|
||||
}
|
||||
17
SDK/src/NDK/LuaBinding_Renderer.cpp
Normal file
17
SDK/src/NDK/LuaBinding_Renderer.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindRenderer()
|
||||
{
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterRenderer(Nz::LuaInstance& instance)
|
||||
{
|
||||
}
|
||||
}
|
||||
253
SDK/src/NDK/LuaBinding_SDK.cpp
Normal file
253
SDK/src/NDK/LuaBinding_SDK.cpp
Normal file
@@ -0,0 +1,253 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
namespace
|
||||
{
|
||||
int AddNilComponent(Nz::LuaInstance& lua, EntityHandle&)
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||
|
||||
T& component = handle->AddComponent<T>();
|
||||
lua.Push(component.CreateHandle());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int PushNilComponent(Nz::LuaInstance& lua, BaseComponent&)
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||
|
||||
T& rightComponent = static_cast<T&>(component);
|
||||
lua.Push(rightComponent.CreateHandle());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void LuaBinding::BindSDK()
|
||||
{
|
||||
/*********************************** Ndk::Application **********************************/
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
//application.SetMethod("AddWindow", &Application::AddWindow);
|
||||
#endif
|
||||
application.BindMethod("AddWorld", [] (Nz::LuaInstance& instance, Application* application) -> int
|
||||
{
|
||||
instance.Push(application->AddWorld().CreateHandle());
|
||||
return 1;
|
||||
});
|
||||
|
||||
application.BindMethod("GetUpdateTime", &Application::GetUpdateTime);
|
||||
application.BindMethod("Quit", &Application::Quit);
|
||||
|
||||
/*********************************** Ndk::Console **********************************/
|
||||
#ifndef NDK_SERVER
|
||||
consoleClass.Inherit<Nz::Node>(nodeClass, [] (ConsoleHandle* handle) -> Nz::Node*
|
||||
{
|
||||
return handle->GetObject();
|
||||
});
|
||||
|
||||
consoleClass.BindMethod("AddLine", &Console::AddLine, Nz::Color::White);
|
||||
consoleClass.BindMethod("Clear", &Console::Clear);
|
||||
consoleClass.BindMethod("GetCharacterSize", &Console::GetCharacterSize);
|
||||
consoleClass.BindMethod("GetHistory", &Console::GetHistory);
|
||||
consoleClass.BindMethod("GetHistoryBackground", &Console::GetHistoryBackground);
|
||||
consoleClass.BindMethod("GetInput", &Console::GetInput);
|
||||
consoleClass.BindMethod("GetInputBackground", &Console::GetInputBackground);
|
||||
consoleClass.BindMethod("GetSize", &Console::GetSize);
|
||||
//consoleClass.SetMethod("GetTextFont", &Console::GetTextFont);
|
||||
|
||||
consoleClass.BindMethod("IsVisible", &Console::IsVisible);
|
||||
|
||||
consoleClass.BindMethod("SendCharacter", &Console::SendCharacter);
|
||||
//consoleClass.SetMethod("SendEvent", &Console::SendEvent);
|
||||
|
||||
consoleClass.BindMethod("SetCharacterSize", &Console::SetCharacterSize);
|
||||
consoleClass.BindMethod("SetSize", &Console::SetSize);
|
||||
//consoleClass.SetMethod("SetTextFont", &Console::SetTextFont);
|
||||
|
||||
consoleClass.BindMethod("Show", &Console::Show, true);
|
||||
#endif
|
||||
|
||||
/*********************************** Ndk::Entity **********************************/
|
||||
entityClass.BindMethod("Enable", &Entity::Enable);
|
||||
entityClass.BindMethod("GetId", &Entity::GetId);
|
||||
entityClass.BindMethod("GetWorld", &Entity::GetWorld);
|
||||
entityClass.BindMethod("Kill", &Entity::Kill);
|
||||
entityClass.BindMethod("IsEnabled", &Entity::IsEnabled);
|
||||
entityClass.BindMethod("IsValid", &Entity::IsValid);
|
||||
entityClass.BindMethod("RemoveComponent", (void(Entity::*)(ComponentIndex)) &Entity::RemoveComponent);
|
||||
entityClass.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents);
|
||||
entityClass.BindMethod("__tostring", &EntityHandle::ToString);
|
||||
|
||||
entityClass.BindMethod("AddComponent", [this] (Nz::LuaInstance& lua, EntityHandle& handle) -> int
|
||||
{
|
||||
int index = 1;
|
||||
ComponentIndex componentIndex = lua.Check<ComponentIndex>(&index);
|
||||
|
||||
if (componentIndex > m_componentBinding.size())
|
||||
{
|
||||
lua.Error("Invalid component index");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ComponentBinding& binding = m_componentBinding[componentIndex];
|
||||
if (!binding.valid)
|
||||
{
|
||||
lua.Error("This component is not available to the LuaAPI");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return binding.adder(lua, handle);
|
||||
});
|
||||
|
||||
entityClass.BindMethod("GetComponent", [this] (Nz::LuaInstance& lua, EntityHandle& handle) -> int
|
||||
{
|
||||
int index = 1;
|
||||
ComponentIndex componentIndex = lua.Check<ComponentIndex>(&index);
|
||||
|
||||
if (!handle->HasComponent(componentIndex))
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (componentIndex > m_componentBinding.size())
|
||||
{
|
||||
lua.Error("Invalid component index");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ComponentBinding& binding = m_componentBinding[componentIndex];
|
||||
if (!binding.valid)
|
||||
{
|
||||
lua.Error("This component is not available to the LuaAPI");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return binding.getter(lua, handle->GetComponent(componentIndex));
|
||||
});
|
||||
|
||||
/*********************************** Ndk::NodeComponent **********************************/
|
||||
nodeComponent.Inherit<Nz::Node>(nodeClass, [] (NodeComponentHandle* handle) -> Nz::Node*
|
||||
{
|
||||
return handle->GetObject();
|
||||
});
|
||||
|
||||
/*********************************** Ndk::VelocityComponent **********************************/
|
||||
velocityComponent.SetGetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* member = lua.CheckString(1, &length);
|
||||
|
||||
if (std::strcmp(member, "Linear") == 0)
|
||||
{
|
||||
lua.Push(instance->linearVelocity);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
velocityComponent.SetSetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* member = lua.CheckString(1, &length);
|
||||
|
||||
int argIndex = 2;
|
||||
if (std::strcmp(member, "Linear") == 0)
|
||||
{
|
||||
instance->linearVelocity = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/*********************************** Ndk::World **********************************/
|
||||
worldClass.BindMethod("CreateEntity", &World::CreateEntity);
|
||||
worldClass.BindMethod("CreateEntities", &World::CreateEntities);
|
||||
worldClass.BindMethod("Clear", &World::Clear);
|
||||
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
/*********************************** Ndk::GraphicsComponent **********************************/
|
||||
graphicsComponent.BindMethod("Attach", &GraphicsComponent::Attach, 0);
|
||||
#endif
|
||||
|
||||
|
||||
// Components functions
|
||||
m_componentBinding.resize(BaseComponent::GetMaxComponentIndex() + 1);
|
||||
|
||||
EnableComponentBinding<NodeComponent>();
|
||||
EnableComponentBinding<VelocityComponent>();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
EnableComponentBinding<GraphicsComponent>();
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void LuaBinding::EnableComponentBinding()
|
||||
{
|
||||
ComponentBinding binding;
|
||||
binding.adder = &AddComponentOfType<T>;
|
||||
binding.getter = &PushComponentOfType<T>;
|
||||
binding.valid = true;
|
||||
|
||||
NazaraAssert(T::componentIndex < m_componentBinding.size(), "Component index is over component binding size");
|
||||
|
||||
m_componentBinding[T::componentIndex] = std::move(binding);
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterSDK(Nz::LuaInstance& instance)
|
||||
{
|
||||
// Classes
|
||||
application.Register(instance);
|
||||
entityClass.Register(instance);
|
||||
nodeComponent.Register(instance);
|
||||
velocityComponent.Register(instance);
|
||||
worldClass.Register(instance);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
consoleClass.Register(instance);
|
||||
graphicsComponent.Register(instance);
|
||||
#endif
|
||||
|
||||
// Enums
|
||||
|
||||
// ComponentType (fake enumeration to expose component indexes)
|
||||
instance.PushTable();
|
||||
{
|
||||
#ifndef NDK_SERVER
|
||||
instance.PushInteger(GraphicsComponent::componentIndex);
|
||||
instance.SetField("Graphics");
|
||||
#endif
|
||||
|
||||
instance.PushInteger(NodeComponent::componentIndex);
|
||||
instance.SetField("Node");
|
||||
|
||||
instance.PushInteger(VelocityComponent::componentIndex);
|
||||
instance.SetField("Velocity");
|
||||
}
|
||||
instance.SetGlobal("ComponentType");
|
||||
}
|
||||
}
|
||||
255
SDK/src/NDK/LuaBinding_Utility.cpp
Normal file
255
SDK/src/NDK/LuaBinding_Utility.cpp
Normal file
@@ -0,0 +1,255 @@
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindUtility()
|
||||
{
|
||||
/*********************************** Nz::AbstractImage **********************************/
|
||||
abstractImage.BindMethod("GetBytesPerPixel", &Nz::AbstractImage::GetBytesPerPixel);
|
||||
abstractImage.BindMethod("GetDepth", &Nz::AbstractImage::GetDepth, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("GetFormat", &Nz::AbstractImage::GetFormat);
|
||||
abstractImage.BindMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount);
|
||||
abstractImage.BindMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel);
|
||||
abstractImage.BindMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("GetType", &Nz::AbstractImage::GetType);
|
||||
abstractImage.BindMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("IsCompressed", &Nz::AbstractImage::IsCompressed);
|
||||
abstractImage.BindMethod("IsCubemap", &Nz::AbstractImage::IsCubemap);
|
||||
|
||||
abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 1U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return lua.Push(abstractImage->GetMemoryUsage());
|
||||
|
||||
case 1:
|
||||
{
|
||||
int index = 1;
|
||||
Nz::UInt8 level(lua.Check<Nz::UInt8>(&index));
|
||||
|
||||
return lua.Push(abstractImage->GetMemoryUsage(level));
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method GetMemoryUsage");
|
||||
return 0;
|
||||
});
|
||||
|
||||
abstractImage.BindMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 6U);
|
||||
int argIndex = 1;
|
||||
|
||||
std::size_t bufferSize = 0;
|
||||
const Nz::UInt8* pixels = reinterpret_cast<const Nz::UInt8*>(lua.CheckString(argIndex++, &bufferSize));
|
||||
|
||||
if (argCount < 2 || lua.IsOfType(2, Nz::LuaType_Number))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}
|
||||
/* Disabled until Box and Rect have been ported
|
||||
else if (lua.IsOfType(2, "Box"))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
Nz::Boxui box = lua.Check<Nz::Boxui>(&argIndex);
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}
|
||||
else if (lua.IsOfType(2, "Rect"))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
Nz::Rectui box = lua.Check<Nz::Rectui>(&argIndex);
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}*/
|
||||
|
||||
lua.Error("No matching overload for method Update");
|
||||
return 0;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Node **********************************/
|
||||
nodeClass.BindMethod("GetBackward", &Nz::Node::GetBackward);
|
||||
//nodeClass.SetMethod("GetChilds", &Nz::Node::GetChilds);
|
||||
nodeClass.BindMethod("GetDown", &Nz::Node::GetDown);
|
||||
nodeClass.BindMethod("GetForward", &Nz::Node::GetForward);
|
||||
nodeClass.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
|
||||
nodeClass.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
|
||||
nodeClass.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale);
|
||||
nodeClass.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
|
||||
//nodeClass.SetMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
|
||||
nodeClass.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
|
||||
nodeClass.BindMethod("GetLeft", &Nz::Node::GetLeft);
|
||||
nodeClass.BindMethod("GetNodeType", &Nz::Node::GetNodeType);
|
||||
//nodeClass.SetMethod("GetParent", &Nz::Node::GetParent);
|
||||
nodeClass.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
|
||||
nodeClass.BindMethod("GetRight", &Nz::Node::GetRight);
|
||||
//nodeClass.SetMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
|
||||
nodeClass.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
|
||||
//nodeClass.SetMethod("GetTransformMatrix", &Nz::Node::GetTransformMatrix);
|
||||
nodeClass.BindMethod("GetUp", &Nz::Node::GetUp);
|
||||
|
||||
nodeClass.BindMethod("HasChilds", &Nz::Node::HasChilds);
|
||||
|
||||
nodeClass.BindMethod("GetBackward", &Nz::Node::GetBackward);
|
||||
nodeClass.BindMethod("GetDown", &Nz::Node::GetDown);
|
||||
nodeClass.BindMethod("GetForward", &Nz::Node::GetForward);
|
||||
nodeClass.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
|
||||
nodeClass.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
|
||||
nodeClass.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale);
|
||||
nodeClass.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
|
||||
nodeClass.BindMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
|
||||
nodeClass.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
|
||||
nodeClass.BindMethod("GetLeft", &Nz::Node::GetLeft);
|
||||
nodeClass.BindMethod("GetNodeType", &Nz::Node::GetNodeType);
|
||||
nodeClass.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
|
||||
nodeClass.BindMethod("GetRight", &Nz::Node::GetRight);
|
||||
nodeClass.BindMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
|
||||
nodeClass.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
|
||||
nodeClass.BindMethod("GetUp", &Nz::Node::GetUp);
|
||||
|
||||
nodeClass.BindMethod("SetInitialPosition", (void(Nz::Node::*)(const Nz::Vector3f&)) &Nz::Node::SetInitialPosition);
|
||||
nodeClass.BindMethod("SetInitialRotation", (void(Nz::Node::*)(const Nz::Quaternionf&)) &Nz::Node::SetInitialRotation);
|
||||
|
||||
nodeClass.BindMethod("SetPosition", (void(Nz::Node::*)(const Nz::Vector3f&, Nz::CoordSys)) &Nz::Node::SetPosition, Nz::CoordSys_Local);
|
||||
nodeClass.BindMethod("SetRotation", (void(Nz::Node::*)(const Nz::Quaternionf&, Nz::CoordSys)) &Nz::Node::SetRotation, Nz::CoordSys_Local);
|
||||
|
||||
nodeClass.BindMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||
{
|
||||
int argIndex = 1;
|
||||
|
||||
Nz::Vector3f offset = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
node.Move(offset, coordSys);
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
nodeClass.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||
{
|
||||
int argIndex = 1;
|
||||
|
||||
Nz::Quaternionf rotation = lua.Check<Nz::Quaternionf>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
node.Rotate(rotation, coordSys);
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
nodeClass.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
node.Scale(lua.Check<float>(&argIndex));
|
||||
else
|
||||
node.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 3:
|
||||
node.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method Scale");
|
||||
return 0;
|
||||
});
|
||||
|
||||
nodeClass.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
{
|
||||
float scale = lua.Check<float>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
node.SetScale(scale, coordSys);
|
||||
}
|
||||
else
|
||||
node.SetScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 3:
|
||||
case 4:
|
||||
{
|
||||
Nz::Vector3f scale = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
|
||||
node.SetScale(scale, coordSys);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method SetScale");
|
||||
return 0;
|
||||
});
|
||||
|
||||
nodeClass.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
node.SetInitialScale(lua.Check<float>(&argIndex));
|
||||
else
|
||||
node.SetInitialScale(lua.Check<Nz::Vector2f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
node.SetInitialScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method SetInitialScale");
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterUtility(Nz::LuaInstance& instance)
|
||||
{
|
||||
abstractImage.Register(instance);
|
||||
nodeClass.Register(instance);
|
||||
}
|
||||
}
|
||||
@@ -13,64 +13,80 @@
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <NDK/BaseSystem.hpp>
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
#include <NDK/Components/CollisionComponent.hpp>
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/PhysicsComponent.hpp>
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/PhysicsSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#endif
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
bool Sdk::Initialize()
|
||||
{
|
||||
if (s_referenceCounter++ > 0)
|
||||
return true; // Déjà initialisé
|
||||
return true; // Already initialized
|
||||
|
||||
try
|
||||
{
|
||||
Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true);
|
||||
|
||||
// Initialisation du moteur
|
||||
// Initialize the engine first
|
||||
|
||||
// Modules clients
|
||||
Nz::Audio::Initialize();
|
||||
Nz::Graphics::Initialize();
|
||||
|
||||
// Modules serveurs
|
||||
// Shared modules
|
||||
Nz::Lua::Initialize();
|
||||
Nz::Noise::Initialize();
|
||||
Nz::Physics::Initialize();
|
||||
Nz::Utility::Initialize();
|
||||
|
||||
// Initialisation du SDK
|
||||
#ifndef NDK_SERVER
|
||||
// Client modules
|
||||
Nz::Audio::Initialize();
|
||||
Nz::Graphics::Initialize();
|
||||
#endif
|
||||
|
||||
// Initialisation des composants et systèmes
|
||||
// SDK Initialization
|
||||
|
||||
// Components
|
||||
BaseComponent::Initialize();
|
||||
BaseSystem::Initialize();
|
||||
|
||||
// Composants
|
||||
InitializeComponent<CameraComponent>("NdkCam");
|
||||
// Shared components
|
||||
InitializeComponent<CollisionComponent>("NdkColli");
|
||||
InitializeComponent<LightComponent>("NdkLight");
|
||||
InitializeComponent<ListenerComponent>("NdkList");
|
||||
InitializeComponent<GraphicsComponent>("NdkGfx");
|
||||
InitializeComponent<NodeComponent>("NdkNode");
|
||||
InitializeComponent<PhysicsComponent>("NdkPhys");
|
||||
InitializeComponent<VelocityComponent>("NdkVeloc");
|
||||
|
||||
// Systèmes
|
||||
InitializeSystem<ListenerSystem>();
|
||||
#ifndef NDK_SERVER
|
||||
// Client components
|
||||
InitializeComponent<CameraComponent>("NdkCam");
|
||||
InitializeComponent<LightComponent>("NdkLight");
|
||||
InitializeComponent<ListenerComponent>("NdkList");
|
||||
InitializeComponent<GraphicsComponent>("NdkGfx");
|
||||
#endif
|
||||
|
||||
// Systems
|
||||
|
||||
BaseSystem::Initialize();
|
||||
|
||||
// Shared systems
|
||||
InitializeSystem<PhysicsSystem>();
|
||||
InitializeSystem<RenderSystem>();
|
||||
InitializeSystem<VelocitySystem>();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
// Client systems
|
||||
InitializeSystem<ListenerSystem>();
|
||||
InitializeSystem<RenderSystem>();
|
||||
#endif
|
||||
|
||||
NazaraNotice("Initialized: SDK");
|
||||
return true;
|
||||
}
|
||||
@@ -86,23 +102,25 @@ namespace Ndk
|
||||
{
|
||||
if (s_referenceCounter != 1)
|
||||
{
|
||||
// Le module est soit encore utilisé, soit pas initialisé
|
||||
// Either the module is not initialized, either it was initialized multiple times
|
||||
if (s_referenceCounter > 1)
|
||||
s_referenceCounter--;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Libération du SDK
|
||||
// Uninitialize the SDK
|
||||
s_referenceCounter = 0;
|
||||
|
||||
// Libération du moteur
|
||||
// Uninitialize the engine
|
||||
|
||||
// Modules clients
|
||||
#ifndef NDK_SERVER
|
||||
// Client modules
|
||||
Nz::Audio::Uninitialize();
|
||||
Nz::Graphics::Uninitialize();
|
||||
#endif
|
||||
|
||||
// Modules serveurs
|
||||
// Shared modules
|
||||
Nz::Lua::Uninitialize();
|
||||
Nz::Noise::Uninitialize();
|
||||
Nz::Physics::Uninitialize();
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Ndk
|
||||
m_coordinateSystemMatrix(Nz::Matrix4f::Identity()),
|
||||
m_coordinateSystemInvalidated(true)
|
||||
{
|
||||
ChangeRenderTechnique<Nz::ForwardRenderTechnique>();
|
||||
SetDefaultBackground(Nz::ColorBackground::New());
|
||||
SetUpdateRate(0.f);
|
||||
}
|
||||
@@ -95,7 +96,7 @@ namespace Ndk
|
||||
|
||||
//UpdateDirectionalShadowMaps(camComponent);
|
||||
|
||||
Nz::AbstractRenderQueue* renderQueue = m_renderTechnique.GetRenderQueue();
|
||||
Nz::AbstractRenderQueue* renderQueue = m_renderTechnique->GetRenderQueue();
|
||||
renderQueue->Clear();
|
||||
|
||||
//TODO: Culling
|
||||
@@ -123,7 +124,8 @@ namespace Ndk
|
||||
sceneData.background = m_background;
|
||||
sceneData.viewer = &camComponent;
|
||||
|
||||
m_renderTechnique.Draw(sceneData);
|
||||
m_renderTechnique->Clear(sceneData);
|
||||
m_renderTechnique->Draw(sceneData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,14 +4,17 @@
|
||||
|
||||
#include <NDK/World.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/PhysicsSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#endif
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
World::~World()
|
||||
World::~World() noexcept
|
||||
{
|
||||
// La destruction doit se faire dans un ordre précis
|
||||
Clear();
|
||||
@@ -19,10 +22,13 @@ namespace Ndk
|
||||
|
||||
void World::AddDefaultSystems()
|
||||
{
|
||||
AddSystem<ListenerSystem>();
|
||||
AddSystem<PhysicsSystem>();
|
||||
AddSystem<RenderSystem>();
|
||||
AddSystem<VelocitySystem>();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
AddSystem<ListenerSystem>();
|
||||
AddSystem<RenderSystem>();
|
||||
#endif
|
||||
}
|
||||
|
||||
const EntityHandle& World::CreateEntity()
|
||||
@@ -40,7 +46,7 @@ namespace Ndk
|
||||
id = m_entities.size();
|
||||
|
||||
// Impossible d'utiliser emplace_back à cause de la portée
|
||||
m_entities.push_back(Entity(*this, id));
|
||||
m_entities.push_back(Entity(this, id));
|
||||
}
|
||||
|
||||
// On initialise l'entité et on l'ajoute à la liste des entités vivantes
|
||||
@@ -53,9 +59,9 @@ namespace Ndk
|
||||
return m_aliveEntities.back();
|
||||
}
|
||||
|
||||
void World::Clear()
|
||||
void World::Clear() noexcept
|
||||
{
|
||||
///DOC: Tous les handles sont correctement invalidés
|
||||
///DOC: Tous les handles sont correctement invalidés, les entités sont immédiatement invalidées
|
||||
|
||||
// Destruction des entités d'abord, et des handles ensuite
|
||||
// ceci pour éviter que les handles n'informent les entités inutilement lors de leur destruction
|
||||
@@ -127,33 +133,33 @@ namespace Ndk
|
||||
|
||||
Entity* entity = &m_entities[i].entity;
|
||||
|
||||
// Aucun intérêt de traiter une entité n'existant plus
|
||||
if (entity->IsValid())
|
||||
// Check entity validity (as it could have been reported as dirty and killed during the same iteration)
|
||||
if (!entity->IsValid())
|
||||
continue;
|
||||
|
||||
for (auto& system : m_systems)
|
||||
{
|
||||
for (auto& system : m_systems)
|
||||
// Ignore non-existent systems
|
||||
if (!system)
|
||||
continue;
|
||||
|
||||
// Is our entity already part of this system?
|
||||
bool partOfSystem = system->HasEntity(entity);
|
||||
|
||||
// Should it be part of it?
|
||||
if (entity->IsEnabled() && system->Filters(entity))
|
||||
{
|
||||
// Ignore non-existent systems
|
||||
if (!system)
|
||||
continue;
|
||||
// Yes it should, add it to the system if not already done and validate it (again)
|
||||
if (!partOfSystem)
|
||||
system->AddEntity(entity);
|
||||
|
||||
// L'entité est-elle enregistrée comme faisant partie du système ?
|
||||
bool partOfSystem = system->HasEntity(entity);
|
||||
|
||||
// Doit-elle en faire partie ?
|
||||
if (system->Filters(entity))
|
||||
{
|
||||
// L'entité doit faire partie du système, revalidons-là (événement système) ou ajoutons-la au système
|
||||
if (!partOfSystem)
|
||||
system->AddEntity(entity);
|
||||
|
||||
system->ValidateEntity(entity, !partOfSystem);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Elle ne doit pas en faire partie, si elle en faisait partie nous devons la retirer
|
||||
if (partOfSystem)
|
||||
system->RemoveEntity(entity);
|
||||
}
|
||||
system->ValidateEntity(entity, !partOfSystem);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No, it shouldn't, remove it if it's part of the system
|
||||
if (partOfSystem)
|
||||
system->RemoveEntity(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user