engine plugin system; physics is an engine plugin

This commit is contained in:
Mikulas Florek 2013-11-28 01:02:26 +01:00
parent d405119283
commit 640224487e
18 changed files with 336 additions and 157 deletions

View file

@ -19,6 +19,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "editor_ng", "editor_ng\edit
{575E3E55-7662-4D79-92C4-2CF77C56E3EA} = {575E3E55-7662-4D79-92C4-2CF77C56E3EA}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "physics", "projects\physics\physics.vcxproj", "{13B10E62-BBE6-4B9C-86D0-F90141319326}"
ProjectSection(ProjectDependencies) = postProject
{575E3E55-7662-4D79-92C4-2CF77C56E3EA} = {575E3E55-7662-4D79-92C4-2CF77C56E3EA}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -69,6 +74,16 @@ Global
{950F0C29-6267-4121-96B0-4A0AEA44633E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{950F0C29-6267-4121-96B0-4A0AEA44633E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{950F0C29-6267-4121-96B0-4A0AEA44633E}.Release|Win32.ActiveCfg = Release|Any CPU
{13B10E62-BBE6-4B9C-86D0-F90141319326}.Debug|Any CPU.ActiveCfg = Debug|Win32
{13B10E62-BBE6-4B9C-86D0-F90141319326}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{13B10E62-BBE6-4B9C-86D0-F90141319326}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{13B10E62-BBE6-4B9C-86D0-F90141319326}.Debug|Win32.ActiveCfg = Debug|Win32
{13B10E62-BBE6-4B9C-86D0-F90141319326}.Debug|Win32.Build.0 = Debug|Win32
{13B10E62-BBE6-4B9C-86D0-F90141319326}.Release|Any CPU.ActiveCfg = Release|Win32
{13B10E62-BBE6-4B9C-86D0-F90141319326}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{13B10E62-BBE6-4B9C-86D0-F90141319326}.Release|Mixed Platforms.Build.0 = Release|Win32
{13B10E62-BBE6-4B9C-86D0-F90141319326}.Release|Win32.ActiveCfg = Release|Win32
{13B10E62-BBE6-4B9C-86D0-F90141319326}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -447,6 +447,7 @@ namespace editor_ng
foreach (uint cmp in e.cmps)
{
DataGridView dgv = new DataGridView();
dgv.CurrentCellDirtyStateChanged += dgv_CurrentCellDirtyStateChanged;
dgv.Tag = cmp;
dgv.Columns.Add("name", "name");
dgv.Columns[0].ReadOnly = true;
@ -490,7 +491,12 @@ namespace editor_ng
}
server.requestPosition();
}
}
void dgv_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
(sender as DataGridView).EndEdit();
}
public PropertyGrid()
{

View file

@ -54,13 +54,13 @@
<Optimization>Disabled</Optimization>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
<AdditionalIncludeDirectories>..\..\external\physx\include;..\..\src;..\..\external\sdl\include;..\..\external\horde3d\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\external\physx\include;..\..\src;..\..\external\horde3d\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PreprocessorDefinitions>WIN32;BUILDING_ENGINE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\..\external\physx\lib;..\..\external\horde3d\lib\$(Configuration);..\..\external\sdl\lib;..\..\bin\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>..\..\external\horde3d\lib\$(Configuration);..\..\bin\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>core.lib;platform.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<IgnoreSpecificDefaultLibraries>libcmt.lib</IgnoreSpecificDefaultLibraries>
@ -114,14 +114,9 @@
<ClCompile Include="..\..\src\editor\editor_icon.cpp" />
<ClCompile Include="..\..\src\editor\editor_server.cpp" />
<ClCompile Include="..\..\src\editor\gizmo.cpp" />
<ClCompile Include="..\..\src\editor\iplugin.cpp" />
<ClCompile Include="..\..\src\editor\property_descriptor.cpp" />
<ClCompile Include="..\..\src\graphics\renderer.cpp" />
<ClCompile Include="..\..\src\physics\physics_scene.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\physics\physics_system.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\script\get_property_visitor.cpp" />
<ClCompile Include="..\..\src\script\save_script_visitor.cpp" />
<ClCompile Include="..\..\src\script\script_system.cpp" />
@ -156,15 +151,9 @@
<ClInclude Include="..\..\src\editor\editor_icon.h" />
<ClInclude Include="..\..\src\editor\editor_server.h" />
<ClInclude Include="..\..\src\editor\gizmo.h" />
<ClInclude Include="..\..\src\editor\iplugin.h" />
<ClInclude Include="..\..\src\editor\property_descriptor.h" />
<ClInclude Include="..\..\src\graphics\renderer.h" />
<ClInclude Include="..\..\src\physics\physics_scene.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="..\..\src\physics\physics_system.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="..\..\src\physics\physics_system_impl.h" />
<ClInclude Include="..\..\src\script\base_script.h" />
<ClInclude Include="..\..\src\script\get_property_visitor.h" />
<ClInclude Include="..\..\src\script\save_script_visitor.h" />

View file

@ -7,9 +7,6 @@
<Filter Include="universe">
<UniqueIdentifier>{72baf105-26cd-4555-9e97-a4b92ab1f676}</UniqueIdentifier>
</Filter>
<Filter Include="physics">
<UniqueIdentifier>{41e86905-3a15-460f-af40-92fe8e542217}</UniqueIdentifier>
</Filter>
<Filter Include="editor">
<UniqueIdentifier>{69a0e835-15da-4c43-a0ed-57a169bbe67f}</UniqueIdentifier>
</Filter>
@ -33,12 +30,6 @@
<ClCompile Include="..\..\src\universe\universe.cpp">
<Filter>universe</Filter>
</ClCompile>
<ClCompile Include="..\..\src\physics\physics_scene.cpp">
<Filter>physics</Filter>
</ClCompile>
<ClCompile Include="..\..\src\physics\physics_system.cpp">
<Filter>physics</Filter>
</ClCompile>
<ClCompile Include="..\..\src\universe\component_event.cpp">
<Filter>universe</Filter>
</ClCompile>
@ -144,6 +135,9 @@
<ClCompile Include="..\..\src\animation\animation_system.cpp">
<Filter>animation</Filter>
</ClCompile>
<ClCompile Include="..\..\src\editor\iplugin.cpp">
<Filter>editor</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\graphics\renderer.h">
@ -152,12 +146,6 @@
<ClInclude Include="..\..\src\universe\universe.h">
<Filter>universe</Filter>
</ClInclude>
<ClInclude Include="..\..\src\physics\physics_scene.h">
<Filter>physics</Filter>
</ClInclude>
<ClInclude Include="..\..\src\physics\physics_system.h">
<Filter>physics</Filter>
</ClInclude>
<ClInclude Include="..\..\src\universe\component_event.h">
<Filter>universe</Filter>
</ClInclude>
@ -254,8 +242,8 @@
<ClInclude Include="..\..\src\animation\animation_system.h">
<Filter>animation</Filter>
</ClInclude>
<ClInclude Include="..\..\src\physics\physics_system_impl.h">
<Filter>physics</Filter>
<ClInclude Include="..\..\src\editor\iplugin.h">
<Filter>editor</Filter>
</ClInclude>
</ItemGroup>
</Project>

View file

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{13B10E62-BBE6-4B9C-86D0-F90141319326}</ProjectGuid>
<RootNamespace>physics</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IntDir>$(SolutionDir)tmp\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)bin\$(Configuration)\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>
</SDLCheck>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalIncludeDirectories>..\..\external\physx\include;..\..\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MinimalRebuild>false</MinimalRebuild>
<PreprocessorDefinitions>WIN32;BUILDING_PHYSICS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\..\external\physx\lib;..\..\bin\$(Configuration)\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>core.lib;engine.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<IgnoreSpecificDefaultLibraries>libcmt.lib</IgnoreSpecificDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\src\physics\physics_scene.cpp" />
<ClCompile Include="..\..\src\physics\physics_system.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\physics\physics_scene.h" />
<ClInclude Include="..\..\src\physics\physics_system.h" />
<ClInclude Include="..\..\src\physics\physics_system_impl.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="..\..\src\physics\physics_scene.cpp" />
<ClCompile Include="..\..\src\physics\physics_system.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\physics\physics_scene.h" />
<ClInclude Include="..\..\src\physics\physics_system.h" />
<ClInclude Include="..\..\src\physics\physics_system_impl.h" />
</ItemGroup>
</Project>

View file

@ -1,6 +1,9 @@
#pragma once
#include <cstdint>
#ifdef BUILDING_CORE
#define LUX_CORE_API __declspec(dllexport)
#else
@ -8,6 +11,13 @@
#endif
#ifdef BUILDING_PHYSICS
#define LUX_PHYSICS_API __declspec(dllexport)
#else
#define LUX_PHYSICS_API __declspec(dllimport)
#endif
#ifdef BUILDING_ENGINE
#define LUX_ENGINE_API __declspec(dllexport)
#else
@ -24,6 +34,4 @@
#define LUX_OVERRIDE override
#define LUX_ABSTRACT abstract
#define DISABLE_PHYSICS
#pragma warning( disable : 4251 )

View file

@ -3,7 +3,6 @@
#include "core/string.h"
#include "universe/universe.h"
#include "Gwen/Controls.h"
@ -59,37 +58,6 @@ struct EditorProperty
};
struct CustomGwenBooleanProperty : public Gwen::Controls::Property::Checkbox
{
CustomGwenBooleanProperty(Component _cmp, Gwen::Controls::Base* parent);
void onPropertyChange(Gwen::Controls::Base* ctrl);
Component cmp;
};
struct CustomGwenTextProperty : public Gwen::Controls::Property::Text
{
CustomGwenTextProperty(Component _cmp, Gwen::Controls::Base* parent);
void onPropertyChange(Gwen::Controls::Base* ctrl);
Component cmp;
};
struct CustomGwenFileProperty : public Gwen::Controls::Property::File
{
CustomGwenFileProperty(Component _cmp, Gwen::Controls::Base* parent);
void onPropertyChange(Gwen::Controls::Base* ctrl);
Component cmp;
};
Gwen::Controls::Property::Base* createGwenProperty(EditorProperty& prop, Component cmp, Gwen::Controls::Base* parent);
extern map<Component::Type, vector<EditorProperty> > g_properties;

View file

@ -1,7 +1,6 @@
#include "editor_server.h"
#include "graphics/renderer.h"
#include "universe/universe.h"
#include "physics/physics_system.h"
#include "core/matrix.h"
#include "core/memory_stream.h"
#include "core/vector.h"
@ -13,10 +12,8 @@
#include "universe/component_event.h"
#include "core/raw_file_stream.h"
#include "core/json_serializer.h"
#include "physics/physics_scene.h"
#include "graphics/renderer.h"
#include "universe/universe.h"
#include "PxPhysicsAPI.h"
#include "ai/navigation.h"
#include "universe/entity_moved_event.h"
#include "universe/entity_destroyed_event.h"
@ -31,6 +28,7 @@
#include <gl/GL.h>
#include "Horde3DUtils.h"
#include "animation/animation_system.h"
#include "editor/iplugin.h"
namespace Lux
@ -114,8 +112,8 @@ private:
void rotateCamera(int x, int y);
void onEvent(Event& evt);
void destroyUniverse();
void renderPhysics();
void gameModeLoop();
bool loadPlugin(const char* plugin_name);
static void onEvent(void* data, Event& evt);
@ -127,11 +125,11 @@ private:
ScriptSystem* m_script_system;
Universe* m_universe;
Navigation m_navigation;
PhysicsSystem* m_physics_system;
PhysicsScene* m_physics_scene;
vector<IPlugin*> m_plugins;
ResponceCallback m_response_callback;
MemoryStream m_stream;
map<unsigned int, vector<PropertyDescriptor> > m_component_properties;
map<uint32_t, vector<PropertyDescriptor> > m_component_properties;
map<uint32_t, IPlugin*> m_creators;
MouseMode::Value m_mouse_mode;
vector<EditorIcon*> m_editor_icons;
HWND m_hwnd;
@ -146,8 +144,8 @@ private:
void EditorServer::registerProperties()
{
m_component_properties[crc32("renderable")].push_back(PropertyDescriptor("path", (PropertyDescriptor::Getter)&Renderer::getMesh, (PropertyDescriptor::Setter)&Renderer::setMesh, PropertyDescriptor::FILE));
m_component_properties[crc32("physical")].push_back(PropertyDescriptor("source", (PropertyDescriptor::Getter)&PhysicsScene::getShapeSource, (PropertyDescriptor::Setter)&PhysicsScene::setShapeSource, PropertyDescriptor::FILE));
m_component_properties[crc32("physical")].push_back(PropertyDescriptor("dynamic", (PropertyDescriptor::BoolGetter)&PhysicsScene::getIsDynamic, (PropertyDescriptor::BoolSetter)&PhysicsScene::setIsDynamic));
//m_component_properties[crc32("physical")].push_back(PropertyDescriptor("source", (PropertyDescriptor::Getter)&PhysicsScene::getShapeSource, (PropertyDescriptor::Setter)&PhysicsScene::setShapeSource, PropertyDescriptor::FILE));
//m_component_properties[crc32("physical")].push_back(PropertyDescriptor("dynamic", (PropertyDescriptor::BoolGetter)&PhysicsScene::getIsDynamic, (PropertyDescriptor::BoolSetter)&PhysicsScene::setIsDynamic));
m_component_properties[crc32("point_light")].push_back(PropertyDescriptor("fov", (PropertyDescriptor::DecimalGetter)&Renderer::getLightFov, (PropertyDescriptor::DecimalSetter)&Renderer::setLightFov));
m_component_properties[crc32("point_light")].push_back(PropertyDescriptor("radius", (PropertyDescriptor::DecimalGetter)&Renderer::getLightRadius, (PropertyDescriptor::DecimalSetter)&Renderer::setLightRadius));
m_component_properties[crc32("script")].push_back(PropertyDescriptor("path", (PropertyDescriptor::Getter)&ScriptSystem::getScriptPath, (PropertyDescriptor::Setter)&ScriptSystem::setScriptPath, PropertyDescriptor::FILE));
@ -249,7 +247,10 @@ void EditorServer::save(IStream& stream)
m_universe->serialize(serializer);
m_script_system->serialize(serializer);
m_renderer->serialize(serializer);
m_physics_scene->serialize(serializer);
for(int i = 0; i < m_plugins.size(); ++i)
{
m_plugins[i]->serialize(serializer);
}
m_animation_system->serialize(serializer);
serializer.serialize("cam_pos_x", m_camera_pos.x);
serializer.serialize("cam_pos_y", m_camera_pos.y);
@ -340,10 +341,14 @@ void EditorServer::gameModeLoop()
}
}
m_script_system->update(0.05f);
m_navigation.update(0.05f);
m_physics_scene->update(0.05f);
input_system.update(0.05f);
float dt = 0.05f;
m_script_system->update(dt);
m_navigation.update(dt);
for(int i = 0; i < m_plugins.size(); ++i)
{
m_plugins[i]->update(dt);
}
input_system.update(dt);
}
HDC hdc;
PAINTSTRUCT ps;
@ -454,13 +459,18 @@ void EditorServer::addComponent(unsigned int type_crc)
}
}
if(type_crc == renderable_type)
IPlugin* plugin = 0;
if(m_creators.find(type_crc, plugin))
{
plugin->createComponent(type_crc, m_selected_entity);
}
else if(type_crc == renderable_type)
{
m_renderer->createRenderable(m_selected_entity);
}
else if(type_crc == physical_type)
{
m_physics_scene->createActor(m_selected_entity);
//m_physics_scene->createActor(m_selected_entity);
}
else if(type_crc == point_light_type)
{
@ -468,7 +478,7 @@ void EditorServer::addComponent(unsigned int type_crc)
}
else if(type_crc == physical_controller_type)
{
m_physics_scene->createController(m_selected_entity);
//m_physics_scene->createController(m_selected_entity);
}
else if(type_crc == script_type)
{
@ -549,7 +559,7 @@ void EditorServer::removeComponent(unsigned int type_crc)
}
else if(type_crc == physical_type)
{
m_physics_scene->destroyActor(cmp);
//m_physics_scene->destroyActor(cmp);
}
else if(type_crc == point_light_type)
{
@ -596,7 +606,10 @@ void EditorServer::load(IStream& stream)
m_universe->deserialize(serializer);
m_script_system->deserialize(serializer);
m_renderer->deserialize(serializer);
m_physics_scene->deserialize(serializer);
for(int i = 0; i < m_plugins.size(); ++i)
{
m_plugins[i]->deserialize(serializer);
}
m_animation_system->deserialize(serializer);
serializer.deserialize("cam_pos_x", m_camera_pos.x);
serializer.deserialize("cam_pos_y", m_camera_pos.y);
@ -625,7 +638,6 @@ bool EditorServer::create(HWND hwnd, const char* base_path)
m_message_mutex.create();
m_fs.create();
m_hwnd = hwnd;
registerProperties();
m_renderer = new Renderer();
m_animation_system = new AnimationSystem();
RECT rect;
@ -643,20 +655,39 @@ bool EditorServer::create(HWND hwnd, const char* base_path)
}
glPopAttrib();
m_physics_system = new PhysicsSystem();
m_physics_system->create();
loadPlugin("physics.dll");
EditorIcon::createResources(base_path);
createUniverse(true, base_path);
m_gizmo.create(base_path);
m_gizmo.hide();
registerProperties();
//m_navigation.load("models/level2/level2.pda");
return true;
}
bool EditorServer::loadPlugin(const char* plugin_name)
{
typedef IPlugin* (*PluginCreator)();
HMODULE lib = LoadLibrary(TEXT("physics.dll"));
if(lib)
{
PluginCreator creator = (PluginCreator)GetProcAddress(lib, TEXT("createPlugin"));
if(creator)
{
IPlugin* plugin = creator();
plugin->create(m_component_properties, m_creators);
m_plugins.push_back(plugin);
return true;
}
}
return false;
}
void EditorServer::update()
{
m_fs.processLoaded();
@ -699,7 +730,7 @@ void EditorServer::renderScene()
}
void EditorServer::renderPhysics()
/*void EditorServer::renderPhysics()
{
glMatrixMode(GL_PROJECTION);
float proj[16];
@ -743,7 +774,7 @@ void EditorServer::renderPhysics()
}
glEnd();
}
}
}*/
EditorServer::EditorServer()
@ -1010,9 +1041,10 @@ void EditorServer::destroyUniverse()
m_animation_system->setUniverse(0);
m_script_system->setUniverse(0);
m_gizmo.setUniverse(0);
m_physics_scene->destroy();
delete m_physics_scene;
m_physics_scene = 0;
for(int i = 0; i < m_plugins.size(); ++i)
{
m_plugins[i]->onDestroyUniverse(*m_universe);
}
m_universe->destroy();
delete m_universe;
m_universe = 0;
@ -1021,8 +1053,10 @@ void EditorServer::destroyUniverse()
void EditorServer::createUniverse(bool create_scene, const char* base_path)
{
m_universe = new Universe();
m_physics_scene = new PhysicsScene();
m_physics_scene->create(*m_physics_system, *m_universe);
for(int i = 0; i < m_plugins.size(); ++i)
{
m_plugins[i]->onCreateUniverse(*m_universe);
}
m_universe->create();
m_universe->getEventManager()->registerListener(EntityMovedEvent::type, this, &EditorServer::onEvent);
m_universe->getEventManager()->registerListener(ComponentEvent::type, this, &EditorServer::onEvent);

7
src/editor/iplugin.cpp Normal file
View file

@ -0,0 +1,7 @@
#include "editor/iplugin.h"
namespace Lux
{
IPlugin::~IPlugin() {}
}

34
src/editor/iplugin.h Normal file
View file

@ -0,0 +1,34 @@
#pragma once
#include "core/lux.h"
#include "core/vector.h"
#include "core/map.h"
#include "universe/universe.h"
namespace Lux
{
class Universe;
class ISerializer;
class PropertyDescriptor;
class IPlugin;
typedef map<uint32_t, vector<PropertyDescriptor> > EditorPropertyMap;
typedef map<uint32_t, IPlugin*> ComponentCreatorList;
class LUX_ENGINE_API IPlugin LUX_ABSTRACT
{
public:
virtual ~IPlugin();
virtual bool create(EditorPropertyMap&, ComponentCreatorList&) = 0;
virtual void onCreateUniverse(Universe&) {}
virtual void onDestroyUniverse(Universe&) {}
virtual void serialize(ISerializer&) {}
virtual void deserialize(ISerializer&) {}
virtual void update(float) {}
virtual Component createComponent(uint32_t, const Entity&) = 0;
};
};

View file

@ -11,7 +11,6 @@ namespace Lux
class Event;
class PhysicsScene;
struct Vec3;
class IFileSystem;
class ISerializer;

View file

@ -20,9 +20,6 @@ namespace Lux
{
#ifndef DISABLE_PHYSICS
struct PhysicsSceneImpl
{
static void handleEvent(void* data, Event& event);
@ -446,7 +443,7 @@ void PhysicsSceneImpl::postDeserialize()
{
entities[i].universe = universe;
owner->setIsDynamic(Component(entities[i], physical_type, this, i), is_dynamic[i]);
Component cmp(entities[i], physical_type, this, i);
Component cmp(entities[i], physical_type, owner, i);
universe->getEventManager()->emitEvent(ComponentEvent(cmp));
}
index_map.resize(shape_sources.size());
@ -533,7 +530,7 @@ void PhysicsSceneImpl::handleEvent(Event& event)
if(event.getType() == EntityMovedEvent::type)
{
Entity& e = static_cast<EntityMovedEvent&>(event).entity;
const vector<Component>& cmps = universe->getComponents(e);
const vector<Component>& cmps = e.getComponents();
for(int i = 0, c = cmps.size(); i < c; ++i)
{
if(cmps[i].type == physical_type)
@ -638,26 +635,4 @@ physx::PxScene* PhysicsScene::getRawScene()
}
#else
PhysicsScene::PhysicsScene() {}
bool PhysicsScene::create(PhysicsSystem& system, Universe& universe) { return true; }
void PhysicsScene::destroy() {}
void PhysicsScene::destroyActor(Component cmp) {}
void PhysicsScene::serialize(ISerializer& serializer) {}
void PhysicsScene::deserialize(ISerializer& serializer){}
Component PhysicsScene::createController(Entity entity) { return Component::INVALID; }
Component PhysicsScene::createActor(Entity entity) { return Component::INVALID; }
void PhysicsScene::getShapeSource(Component cmp, string& str) {}
void PhysicsScene::setShapeSource(Component cmp, const string& str) {}
void PhysicsScene::update(float time_delta) {}
void PhysicsScene::moveController(Component cmp, const Vec3& v, float dt) {}
bool PhysicsScene::raycast(const Vec3& origin, const Vec3& dir, float distance, RaycastHit& result) { return false; }
void PhysicsScene::getIsDynamic(Component cmp, bool& is) {}
void PhysicsScene::setIsDynamic(Component cmp, const bool& is) {}
physx::PxScene* PhysicsScene::getRawScene() { return 0; }
#endif // DISABLE_PHYSICS
} // !namespace Lux

View file

@ -28,7 +28,7 @@ struct RaycastHit
};
class LUX_ENGINE_API PhysicsScene
class LUX_PHYSICS_API PhysicsScene
{
friend class PhysicsSystem;
public:

View file

@ -5,9 +5,9 @@
#include "cooking/PxCooking.h"
#include "universe/entity_moved_event.h"
#include "physics_system_impl.h"
#ifndef DISABLE_PHYSICS
#include "editor/editor_properties.h"
#include "editor/property_descriptor.h"
#include "core/crc32.h"
#pragma comment(lib, "PhysXVisualDebuggerSDKCHECKED.lib")
@ -18,13 +18,18 @@
#pragma comment(lib, "PhysX3CookingCHECKED_x86.lib")
#endif // DISABLE_PHYSICS
namespace Lux
{
#ifndef DISABLE_PHYSICS
static const uint32_t physical_type = crc32("physical");
static const uint32_t controller_type = crc32("physical_controller");
extern "C" IPlugin* createPlugin()
{
return new PhysicsSystem();
}
struct CustomErrorCallback : public physx::PxErrorCallback
@ -33,8 +38,62 @@ struct CustomErrorCallback : public physx::PxErrorCallback
};
bool PhysicsSystem::create()
void PhysicsSystem::onCreateUniverse(Universe& universe)
{
m_impl->scene = new PhysicsScene();
m_impl->scene->create(*this, universe);
}
void PhysicsSystem::onDestroyUniverse(Universe& universe)
{
m_impl->scene->destroy();
delete m_impl->scene;
m_impl->scene = 0;
}
void PhysicsSystem::serialize(ISerializer& serializer)
{
m_impl->scene->serialize(serializer);
}
void PhysicsSystem::deserialize(ISerializer& serializer)
{
m_impl->scene->deserialize(serializer);
}
Component PhysicsSystem::createComponent(uint32_t component_type, const Entity& entity)
{
if(component_type == controller_type)
{
return m_impl->scene->createController(entity);
}
else if(component_type == physical_type)
{
return m_impl->scene->createActor(entity);
}
return Component::INVALID;
}
void PhysicsSystem::update(float dt)
{
m_impl->scene->update(dt);
}
bool PhysicsSystem::create(EditorPropertyMap& properties, ComponentCreatorList& creators)
{
properties[crc32("physical")].push_back(PropertyDescriptor("source", (PropertyDescriptor::Getter)&PhysicsScene::getShapeSource, (PropertyDescriptor::Setter)&PhysicsScene::setShapeSource, PropertyDescriptor::FILE));
properties[crc32("physical")].push_back(PropertyDescriptor("dynamic", (PropertyDescriptor::BoolGetter)&PhysicsScene::getIsDynamic, (PropertyDescriptor::BoolSetter)&PhysicsScene::setIsDynamic));
creators.insert(physical_type, this);
creators.insert(controller_type, this);
m_impl = new PhysicsSystemImpl;
m_impl->allocator = new physx::PxDefaultAllocator();
m_impl->error_callback = new CustomErrorCallback();
@ -90,16 +149,6 @@ void CustomErrorCallback::reportError(physx::PxErrorCode::Enum code, const char*
}
#else // DISABLE_PHYSICS
bool PhysicsSystem::create() { return true; }
void PhysicsSystem::destroy() {}
#endif // DISABLE_PHYSICS
} // !namespace Lux

View file

@ -2,25 +2,40 @@
#include "core/lux.h"
#include "editor/iplugin.h"
namespace Lux
{
class LUX_ENGINE_API PhysicsSystem
class LUX_PHYSICS_API PhysicsSystem : public IPlugin
{
friend class PhysicsScene;
friend struct PhysicsSceneImpl;
public:
PhysicsSystem() { m_impl = 0; }
bool create();
void destroy();
virtual bool create(EditorPropertyMap& properties, ComponentCreatorList& creators) LUX_OVERRIDE;
virtual void onCreateUniverse(Universe& universe) LUX_OVERRIDE;
virtual void onDestroyUniverse(Universe& universe) LUX_OVERRIDE;
virtual void serialize(ISerializer& serializer) LUX_OVERRIDE;
virtual void deserialize(ISerializer& serializer) LUX_OVERRIDE;
virtual void update(float dt) LUX_OVERRIDE;
virtual Component createComponent(uint32_t component_type, const Entity& entity) LUX_OVERRIDE;
virtual void destroy();
private:
struct PhysicsSystemImpl* m_impl;
};
extern "C"
{
LUX_PHYSICS_API IPlugin* createPlugin();
}
} // !namespace Lux

View file

@ -8,9 +8,6 @@ namespace Lux
{
#ifndef DISABLE_PHYSICS
struct PhysicsSystemImpl
{
bool connect2VisualDebugger();
@ -21,13 +18,8 @@ struct PhysicsSystemImpl
physx::PxAllocatorCallback* allocator;
physx::PxErrorCallback* error_callback;
physx::PxCooking* cooking;
class PhysicsScene* scene;
};
#else
struct PhysicsSystemImpl {};
#endif
};

View file

@ -1,7 +1,5 @@
#include "universe.h"
#include "core/event_manager.h"
//#include "physics/physics_system.h"
#include "physics/physics_scene.h"
#include "component_event.h"
#include "core/matrix.h"
#include "entity_moved_event.h"