Merge pull request #5 from nem0/member_naming
consistent naming of member variables
This commit is contained in:
commit
1d6c6038e4
8 changed files with 484 additions and 500 deletions
|
@ -18,13 +18,13 @@ namespace Lux
|
|||
{
|
||||
struct Animable
|
||||
{
|
||||
bool manual;
|
||||
Component renderable;
|
||||
float time;
|
||||
bool m_manual;
|
||||
Component m_renderable;
|
||||
float m_time;
|
||||
};
|
||||
|
||||
vector<Animable> animables;
|
||||
Universe* universe;
|
||||
vector<Animable> m_animables;
|
||||
Universe* m_universe;
|
||||
|
||||
void onEvent(Event& event);
|
||||
};
|
||||
|
@ -38,7 +38,7 @@ namespace Lux
|
|||
bool AnimationSystem::create()
|
||||
{
|
||||
m_impl = new AnimationSystemImpl();
|
||||
m_impl->universe = 0;
|
||||
m_impl->m_universe = 0;
|
||||
return m_impl != 0;
|
||||
}
|
||||
|
||||
|
@ -52,28 +52,28 @@ namespace Lux
|
|||
|
||||
void AnimationSystem::setUniverse(Universe* universe)
|
||||
{
|
||||
if(m_impl->universe)
|
||||
if(m_impl->m_universe)
|
||||
{
|
||||
m_impl->animables.clear();
|
||||
m_impl->universe->getEventManager()->unregisterListener(ComponentEvent::type, m_impl, &onEvent);
|
||||
m_impl->m_animables.clear();
|
||||
m_impl->m_universe->getEventManager()->unregisterListener(ComponentEvent::type, m_impl, &onEvent);
|
||||
}
|
||||
m_impl->universe = universe;
|
||||
if(m_impl->universe)
|
||||
m_impl->m_universe = universe;
|
||||
if(m_impl->m_universe)
|
||||
{
|
||||
m_impl->universe->getEventManager()->registerListener(ComponentEvent::type, m_impl, &onEvent);
|
||||
m_impl->m_universe->getEventManager()->registerListener(ComponentEvent::type, m_impl, &onEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AnimationSystem::serialize(ISerializer& serializer)
|
||||
{
|
||||
serializer.serialize("count", m_impl->animables.size());
|
||||
serializer.serialize("count", m_impl->m_animables.size());
|
||||
serializer.beginArray("animables");
|
||||
for(int i = 0; i < m_impl->animables.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_animables.size(); ++i)
|
||||
{
|
||||
serializer.serializeArrayItem(m_impl->animables[i].manual);
|
||||
serializer.serializeArrayItem(m_impl->animables[i].renderable.entity.index);
|
||||
serializer.serializeArrayItem(m_impl->animables[i].time);
|
||||
serializer.serializeArrayItem(m_impl->m_animables[i].m_manual);
|
||||
serializer.serializeArrayItem(m_impl->m_animables[i].m_renderable.entity.index);
|
||||
serializer.serializeArrayItem(m_impl->m_animables[i].m_time);
|
||||
}
|
||||
serializer.endArray();
|
||||
}
|
||||
|
@ -84,27 +84,27 @@ namespace Lux
|
|||
int count;
|
||||
serializer.deserialize("count", count);
|
||||
serializer.deserializeArrayBegin("animables");
|
||||
m_impl->animables.clear();
|
||||
m_impl->m_animables.clear();
|
||||
for(int i = 0; i < count; ++i)
|
||||
{
|
||||
m_impl->animables.push_back_empty();
|
||||
serializer.deserializeArrayItem(m_impl->animables[i].manual);
|
||||
m_impl->m_animables.push_back_empty();
|
||||
serializer.deserializeArrayItem(m_impl->m_animables[i].m_manual);
|
||||
int entity_index;
|
||||
serializer.deserializeArrayItem(entity_index);
|
||||
Entity e(m_impl->universe, entity_index);
|
||||
Entity e(m_impl->m_universe, entity_index);
|
||||
const Entity::ComponentList& cmps = e.getComponents();
|
||||
m_impl->animables[i].renderable = Component::INVALID;
|
||||
m_impl->m_animables[i].m_renderable = Component::INVALID;
|
||||
for(int j = 0; j < cmps.size(); ++j)
|
||||
{
|
||||
if(cmps[j].type == renderable_type)
|
||||
{
|
||||
m_impl->animables[i].renderable = cmps[j];
|
||||
m_impl->m_animables[i].m_renderable = cmps[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
serializer.deserializeArrayItem(m_impl->animables[i].time);
|
||||
serializer.deserializeArrayItem(m_impl->m_animables[i].m_time);
|
||||
Component cmp(e, animable_type, this, i);
|
||||
m_impl->universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
m_impl->m_universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
}
|
||||
serializer.deserializeArrayEnd();
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ namespace Lux
|
|||
{
|
||||
if(cmps[i].type == animable_type)
|
||||
{
|
||||
animables[cmps[i].index].renderable = e.component;
|
||||
m_animables[cmps[i].index].m_renderable = e.component;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -133,29 +133,29 @@ namespace Lux
|
|||
|
||||
Component AnimationSystem::createAnimable(const Entity& entity)
|
||||
{
|
||||
AnimationSystemImpl::Animable& animable = m_impl->animables.push_back_empty();
|
||||
animable.manual = true;
|
||||
animable.time = 0;
|
||||
animable.renderable = Component::INVALID;
|
||||
AnimationSystemImpl::Animable& animable = m_impl->m_animables.push_back_empty();
|
||||
animable.m_manual = true;
|
||||
animable.m_time = 0;
|
||||
animable.m_renderable = Component::INVALID;
|
||||
|
||||
const Entity::ComponentList& cmps = entity.getComponents();
|
||||
for(int i = 0; i < cmps.size(); ++i)
|
||||
{
|
||||
if(cmps[i].type == renderable_type)
|
||||
{
|
||||
animable.renderable = cmps[i];
|
||||
animable.m_renderable = cmps[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Component cmp(entity, animable_type, this, m_impl->animables.size() - 1);
|
||||
m_impl->universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
return Component(entity, animable_type, this, m_impl->animables.size() - 1);
|
||||
Component cmp(entity, animable_type, this, m_impl->m_animables.size() - 1);
|
||||
m_impl->m_universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
return Component(entity, animable_type, this, m_impl->m_animables.size() - 1);
|
||||
}
|
||||
|
||||
void AnimationSystem::playAnimation(const Component& cmp, const char* path)
|
||||
{
|
||||
Component renderable = m_impl->animables[cmp.index].renderable;
|
||||
Component renderable = m_impl->m_animables[cmp.index].m_renderable;
|
||||
if(renderable.isValid())
|
||||
{
|
||||
Renderer* renderer = static_cast<Renderer*>(renderable.system);
|
||||
|
@ -165,34 +165,34 @@ namespace Lux
|
|||
h3dSetupModelAnimStage(node, 0, animRes, 0, "", false);
|
||||
h3dSetModelAnimParams(node, 0, 0, 1.0f);
|
||||
|
||||
m_impl->animables[cmp.index].manual = false;
|
||||
m_impl->m_animables[cmp.index].m_manual = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AnimationSystem::setAnimationTime(const Component& cmp, float time)
|
||||
{
|
||||
Renderer* renderer = static_cast<Renderer*>(m_impl->animables[cmp.index].renderable.system);
|
||||
H3DNode node = renderer->getMeshNode(m_impl->animables[cmp.index].renderable);
|
||||
m_impl->animables[cmp.index].time = time;
|
||||
Renderer* renderer = static_cast<Renderer*>(m_impl->m_animables[cmp.index].m_renderable.system);
|
||||
H3DNode node = renderer->getMeshNode(m_impl->m_animables[cmp.index].m_renderable);
|
||||
m_impl->m_animables[cmp.index].m_time = time;
|
||||
h3dSetModelAnimParams(node, 0, time, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
void AnimationSystem::update(float time_delta)
|
||||
{
|
||||
if(m_impl->animables.empty())
|
||||
if(m_impl->m_animables.empty())
|
||||
return;
|
||||
Renderer* renderer = static_cast<Renderer*>(m_impl->animables[0].renderable.system);
|
||||
for(int i = 0, c = m_impl->animables.size(); i < c; ++i)
|
||||
Renderer* renderer = static_cast<Renderer*>(m_impl->m_animables[0].m_renderable.system);
|
||||
for(int i = 0, c = m_impl->m_animables.size(); i < c; ++i)
|
||||
{
|
||||
if(!m_impl->animables[i].manual)
|
||||
if(!m_impl->m_animables[i].m_manual)
|
||||
{
|
||||
H3DNode node = renderer->getMeshNode(m_impl->animables[i].renderable);
|
||||
float time = m_impl->animables[i].time;
|
||||
H3DNode node = renderer->getMeshNode(m_impl->m_animables[i].m_renderable);
|
||||
float time = m_impl->m_animables[i].m_time;
|
||||
time += time_delta;
|
||||
h3dSetModelAnimParams(node, 0, time, 1.0f);
|
||||
m_impl->animables[i].time = time;
|
||||
m_impl->m_animables[i].m_time = time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ static const Component::Type point_light_type = crc32("point_light");
|
|||
struct RenderNode
|
||||
{
|
||||
RenderNode() {}
|
||||
H3DNode node;
|
||||
int entity;
|
||||
H3DNode m_node;
|
||||
int m_entity;
|
||||
};
|
||||
|
||||
|
||||
|
@ -54,22 +54,22 @@ struct RendererImpl
|
|||
void destroyPointLight(Component cmp);
|
||||
void destroyRenderable(Component cmp);
|
||||
|
||||
int width;
|
||||
int height;
|
||||
vector<RenderNode> lights;
|
||||
vector<RenderNode> renderables;
|
||||
vector<string> paths;
|
||||
vector<Entity> entities;
|
||||
H3DRes pipeline_handle;
|
||||
Universe* universe;
|
||||
H3DNode camera_node;
|
||||
int first_free_renderable;
|
||||
int first_free_light;
|
||||
string base_path;
|
||||
IFileSystem* file_system;
|
||||
H3DRes loading_res;
|
||||
Renderer* owner;
|
||||
bool update_bb;
|
||||
int m_width;
|
||||
int m_height;
|
||||
vector<RenderNode> m_lights;
|
||||
vector<RenderNode> m_renderables;
|
||||
vector<string> m_paths;
|
||||
vector<Entity> m_entities;
|
||||
H3DRes m_pipeline_handle;
|
||||
Universe* m_universe;
|
||||
H3DNode m_camera_node;
|
||||
int m_first_free_renderable;
|
||||
int m_first_free_light;
|
||||
string m_base_path;
|
||||
IFileSystem* m_file_system;
|
||||
H3DRes m_loading_res;
|
||||
Renderer* m_owner;
|
||||
bool m_update_bb;
|
||||
};
|
||||
|
||||
|
||||
|
@ -87,14 +87,14 @@ void Renderer::onResize(int w, int h)
|
|||
|
||||
void RendererImpl::onResize(int w, int h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
h3dResizePipelineBuffers(pipeline_handle, width, height);
|
||||
h3dSetNodeParamI(camera_node, H3DCamera::ViewportXI, 0);
|
||||
h3dSetNodeParamI(camera_node, H3DCamera::ViewportYI, 0);
|
||||
h3dSetNodeParamI(camera_node, H3DCamera::ViewportWidthI, width);
|
||||
h3dSetNodeParamI(camera_node, H3DCamera::ViewportHeightI, height);
|
||||
h3dSetupCameraView(camera_node, 45.0f, (float)width / height, 0.1f, 1000.0f);
|
||||
m_width = w;
|
||||
m_height = h;
|
||||
h3dResizePipelineBuffers(m_pipeline_handle, m_width, m_height);
|
||||
h3dSetNodeParamI(m_camera_node, H3DCamera::ViewportXI, 0);
|
||||
h3dSetNodeParamI(m_camera_node, H3DCamera::ViewportYI, 0);
|
||||
h3dSetNodeParamI(m_camera_node, H3DCamera::ViewportWidthI, m_width);
|
||||
h3dSetNodeParamI(m_camera_node, H3DCamera::ViewportHeightI, m_height);
|
||||
h3dSetupCameraView(m_camera_node, 45.0f, (float)m_width / m_height, 0.1f, 1000.0f);
|
||||
}
|
||||
|
||||
|
||||
|
@ -104,26 +104,26 @@ void resourceLoaded(void* user_data, char* file_data, int length, bool success)
|
|||
RendererImpl* renderer = static_cast<RendererImpl*>(user_data);
|
||||
if(success)
|
||||
{
|
||||
renderer->update_bb = true;
|
||||
h3dLoadResource(renderer->loading_res, file_data, length);
|
||||
if(renderer->loading_res == renderer->pipeline_handle)
|
||||
renderer->m_update_bb = true;
|
||||
h3dLoadResource(renderer->m_loading_res, file_data, length);
|
||||
if(renderer->m_loading_res == renderer->m_pipeline_handle)
|
||||
{
|
||||
h3dResizePipelineBuffers(renderer->pipeline_handle, renderer->width, renderer->height);
|
||||
h3dResizePipelineBuffers(renderer->m_pipeline_handle, renderer->m_width, renderer->m_height);
|
||||
// h3dSetOption( H3DOptions::DebugViewMode, 1 );
|
||||
h3dSetOption( H3DOptions::LoadTextures, 1 );
|
||||
h3dSetOption( H3DOptions::TexCompression, 0 );
|
||||
h3dSetOption( H3DOptions::FastAnimation, 0 );
|
||||
h3dSetOption( H3DOptions::MaxAnisotropy, 4 );
|
||||
h3dSetOption( H3DOptions::ShadowMapSize, 512 );
|
||||
renderer->camera_node = h3dAddCameraNode(H3DRootNode, "", renderer->pipeline_handle);
|
||||
renderer->onResize(renderer->width, renderer->height);
|
||||
renderer->m_camera_node = h3dAddCameraNode(H3DRootNode, "", renderer->m_pipeline_handle);
|
||||
renderer->onResize(renderer->m_width, renderer->m_height);
|
||||
}
|
||||
renderer->loading_res = 0;
|
||||
renderer->m_loading_res = 0;
|
||||
renderer->loadResources();
|
||||
}
|
||||
else
|
||||
{
|
||||
h3dLoadResource(renderer->loading_res, 0, 0);
|
||||
h3dLoadResource(renderer->m_loading_res, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,11 +132,11 @@ void RendererImpl::loadResources()
|
|||
{
|
||||
H3DRes res = h3dQueryUnloadedResource(0);
|
||||
char path[255]; /// TODO 255 -> platform constant
|
||||
if(res != 0 && res != loading_res)
|
||||
if(res != 0 && res != m_loading_res)
|
||||
{
|
||||
loading_res = res;
|
||||
sprintf_s(path, "%s%s/%s", base_path.c_str(), h3dutGetResourcePath(h3dGetResType(res)), h3dGetResName(res));
|
||||
file_system->openFile(path, &resourceLoaded, this);
|
||||
m_loading_res = res;
|
||||
sprintf_s(path, "%s%s/%s", m_base_path.c_str(), h3dutGetResourcePath(h3dGetResType(res)), h3dGetResName(res));
|
||||
m_file_system->openFile(path, &resourceLoaded, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,17 +144,17 @@ void RendererImpl::loadResources()
|
|||
bool Renderer::create(IFileSystem* fs, int w, int h, const char* base_path)
|
||||
{
|
||||
m_impl = new RendererImpl();
|
||||
m_impl->owner = this;
|
||||
m_impl->file_system = fs;
|
||||
m_impl->first_free_renderable = -1;
|
||||
m_impl->first_free_light = -1;
|
||||
m_impl->width = -1;
|
||||
m_impl->height = -1;
|
||||
m_impl->universe = 0;
|
||||
m_impl->m_owner = this;
|
||||
m_impl->m_file_system = fs;
|
||||
m_impl->m_first_free_renderable = -1;
|
||||
m_impl->m_first_free_light = -1;
|
||||
m_impl->m_width = -1;
|
||||
m_impl->m_height = -1;
|
||||
m_impl->m_universe = 0;
|
||||
|
||||
m_impl->base_path = base_path;
|
||||
m_impl->width = w;
|
||||
m_impl->height = h;
|
||||
m_impl->m_base_path = base_path;
|
||||
m_impl->m_width = w;
|
||||
m_impl->m_height = h;
|
||||
|
||||
if(!h3dInit())
|
||||
{
|
||||
|
@ -163,7 +163,7 @@ bool Renderer::create(IFileSystem* fs, int w, int h, const char* base_path)
|
|||
h3dutDumpMessages();
|
||||
return false;
|
||||
}
|
||||
m_impl->pipeline_handle = h3dAddResource(H3DResTypes::Pipeline, "pipelines/forward.pipeline.xml", 0);
|
||||
m_impl->m_pipeline_handle = h3dAddResource(H3DResTypes::Pipeline, "pipelines/forward.pipeline.xml", 0);
|
||||
m_impl->loadResources();
|
||||
glUseProgramEXT = (glUseProgramEXT_func)wglGetProcAddress("glUseProgram");
|
||||
glActiveTextureEXT = (glActiveTextureEXT_func)wglGetProcAddress("glActiveTexture");
|
||||
|
@ -181,25 +181,25 @@ void Renderer::destroy()
|
|||
|
||||
void Renderer::renderScene()
|
||||
{
|
||||
if(m_impl->update_bb && h3dQueryUnloadedResource(0) == 0)
|
||||
if(m_impl->m_update_bb && h3dQueryUnloadedResource(0) == 0)
|
||||
{
|
||||
// update boundingboxes because horde3d does not update them when geometry is loaded
|
||||
for(int i = 0; i < m_impl->renderables.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_renderables.size(); ++i)
|
||||
{
|
||||
if(m_impl->renderables[i].node == 0)
|
||||
if(m_impl->m_renderables[i].m_node == 0)
|
||||
{
|
||||
H3DRes res = h3dFindResource(H3DResTypes::SceneGraph, m_impl->paths[i].c_str());
|
||||
H3DNode& node = m_impl->renderables[i].node;
|
||||
H3DRes res = h3dFindResource(H3DResTypes::SceneGraph, m_impl->m_paths[i].c_str());
|
||||
H3DNode& node = m_impl->m_renderables[i].m_node;
|
||||
node = h3dAddNodes(H3DRootNode, res);
|
||||
Matrix mtx;
|
||||
Entity(m_impl->universe, m_impl->renderables[i].entity).getMatrix(mtx);
|
||||
Entity(m_impl->m_universe, m_impl->m_renderables[i].m_entity).getMatrix(mtx);
|
||||
h3dSetNodeTransMat(node, &mtx.m11);
|
||||
Entity e(m_impl->universe, m_impl->renderables[i].entity);
|
||||
Entity e(m_impl->m_universe, m_impl->m_renderables[i].m_entity);
|
||||
}
|
||||
}
|
||||
m_impl->update_bb = false;
|
||||
m_impl->m_update_bb = false;
|
||||
}
|
||||
h3dRender(m_impl->camera_node);
|
||||
h3dRender(m_impl->m_camera_node);
|
||||
|
||||
h3dFinalizeFrame();
|
||||
glUseProgramEXT(0);
|
||||
|
@ -220,46 +220,46 @@ void Renderer::endFrame()
|
|||
|
||||
void Renderer::getLightFov(Component cmp, float& fov)
|
||||
{
|
||||
fov = h3dGetNodeParamF(m_impl->lights[cmp.index].node, H3DLight::FovF, 0);
|
||||
fov = h3dGetNodeParamF(m_impl->m_lights[cmp.index].m_node, H3DLight::FovF, 0);
|
||||
}
|
||||
|
||||
|
||||
void Renderer::setLightFov(Component cmp, const float& fov)
|
||||
{
|
||||
h3dSetNodeParamF(m_impl->lights[cmp.index].node, H3DLight::FovF, 0, fov);
|
||||
h3dSetNodeParamF(m_impl->m_lights[cmp.index].m_node, H3DLight::FovF, 0, fov);
|
||||
}
|
||||
|
||||
|
||||
void Renderer::getLightRadius(Component cmp, float& r)
|
||||
{
|
||||
r = h3dGetNodeParamF(m_impl->lights[cmp.index].node, H3DLight::RadiusF, 0);
|
||||
r = h3dGetNodeParamF(m_impl->m_lights[cmp.index].m_node, H3DLight::RadiusF, 0);
|
||||
}
|
||||
|
||||
|
||||
void Renderer::setLightRadius(Component cmp, const float& r)
|
||||
{
|
||||
h3dSetNodeParamF(m_impl->lights[cmp.index].node, H3DLight::RadiusF, 0, r);
|
||||
h3dSetNodeParamF(m_impl->m_lights[cmp.index].m_node, H3DLight::RadiusF, 0, r);
|
||||
}
|
||||
|
||||
|
||||
void Renderer::getMesh(Component cmp, string& str)
|
||||
{
|
||||
str = m_impl->paths[cmp.index];
|
||||
str = m_impl->m_paths[cmp.index];
|
||||
}
|
||||
|
||||
|
||||
void Renderer::setMesh(Component cmp, const string& str)
|
||||
{
|
||||
m_impl->paths[cmp.index] = str;
|
||||
m_impl->m_paths[cmp.index] = str;
|
||||
H3DRes res = h3dAddResource(H3DResTypes::SceneGraph, str.c_str(), 0);
|
||||
if(h3dIsResLoaded(res))
|
||||
{
|
||||
H3DNode& node = m_impl->renderables[cmp.index].node;
|
||||
H3DNode& node = m_impl->m_renderables[cmp.index].m_node;
|
||||
node = h3dAddNodes(H3DRootNode, res);
|
||||
Matrix mtx;
|
||||
Entity(m_impl->universe, m_impl->renderables[cmp.index].entity).getMatrix(mtx);
|
||||
Entity(m_impl->m_universe, m_impl->m_renderables[cmp.index].m_entity).getMatrix(mtx);
|
||||
h3dSetNodeTransMat(node, &mtx.m11);
|
||||
Entity e(m_impl->universe, m_impl->renderables[cmp.index].entity);
|
||||
Entity e(m_impl->m_universe, m_impl->m_renderables[cmp.index].m_entity);
|
||||
}
|
||||
m_impl->loadResources();
|
||||
}
|
||||
|
@ -267,11 +267,11 @@ void Renderer::setMesh(Component cmp, const string& str)
|
|||
|
||||
Component Renderer::getRenderable(Universe& universe, H3DNode node)
|
||||
{
|
||||
for(int i = 0; i < m_impl->renderables.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_renderables.size(); ++i)
|
||||
{
|
||||
if(m_impl->renderables[i].node == node)
|
||||
if(m_impl->m_renderables[i].m_node == node)
|
||||
{
|
||||
Entity e(m_impl->universe, i);
|
||||
Entity e(m_impl->m_universe, i);
|
||||
return Component(e, rend_type, this, i);
|
||||
}
|
||||
}
|
||||
|
@ -281,21 +281,21 @@ Component Renderer::getRenderable(Universe& universe, H3DNode node)
|
|||
|
||||
void Renderer::getRay(int x, int y, Vec3& origin, Vec3& dir)
|
||||
{
|
||||
h3dutPickRay(m_impl->camera_node, x / (float)m_impl->width, (m_impl->height - y) / (float)m_impl->height, &origin.x, &origin.y, &origin.z, &dir.x, &dir.y, &dir.z);
|
||||
h3dutPickRay(m_impl->m_camera_node, x / (float)m_impl->m_width, (m_impl->m_height - y) / (float)m_impl->m_height, &origin.x, &origin.y, &origin.z, &dir.x, &dir.y, &dir.z);
|
||||
}
|
||||
|
||||
|
||||
void RendererImpl::postDeserialize()
|
||||
{
|
||||
for(int i = 0; i < paths.size(); ++i)
|
||||
for(int i = 0; i < m_paths.size(); ++i)
|
||||
{
|
||||
Entity e(universe, renderables[i].entity);
|
||||
if(paths[i] != "")
|
||||
Entity e(m_universe, m_renderables[i].m_entity);
|
||||
if(m_paths[i] != "")
|
||||
{
|
||||
H3DRes res = h3dAddResource(H3DResTypes::SceneGraph, paths[i].c_str(), 0);
|
||||
H3DRes res = h3dAddResource(H3DResTypes::SceneGraph, m_paths[i].c_str(), 0);
|
||||
if(h3dIsResLoaded(res))
|
||||
{
|
||||
H3DNode& node = renderables[i].node;
|
||||
H3DNode& node = m_renderables[i].m_node;
|
||||
node = h3dAddNodes(H3DRootNode, res);
|
||||
Matrix mtx;
|
||||
e.getMatrix(mtx);
|
||||
|
@ -304,17 +304,17 @@ void RendererImpl::postDeserialize()
|
|||
}
|
||||
if(e.isValid())
|
||||
{
|
||||
universe->getEventManager()->emitEvent(ComponentEvent(Component(e, rend_type, owner, i)));
|
||||
m_universe->getEventManager()->emitEvent(ComponentEvent(Component(e, rend_type, m_owner, i)));
|
||||
}
|
||||
}
|
||||
loadResources();
|
||||
for(int i = 0; i < lights.size(); ++i)
|
||||
for(int i = 0; i < m_lights.size(); ++i)
|
||||
{
|
||||
H3DNode& node = lights[i].node;
|
||||
H3DNode& node = m_lights[i].m_node;
|
||||
node = h3dAddLightNode(H3DRootNode, "", 0, "LIGHTING", "SHADOWMAP");
|
||||
Matrix mtx;
|
||||
universe->getRotation(lights[i].entity).toMatrix(mtx);
|
||||
mtx.setTranslation(universe->getPosition(lights[i].entity));
|
||||
m_universe->getRotation(m_lights[i].m_entity).toMatrix(mtx);
|
||||
mtx.setTranslation(m_universe->getPosition(m_lights[i].m_entity));
|
||||
h3dSetNodeTransMat(node, &mtx.m11);
|
||||
h3dSetNodeParamF(node, H3DLight::RadiusF, 0, 20.0f);
|
||||
h3dSetNodeParamF(node, H3DLight::FovF, 0, 90);
|
||||
|
@ -324,8 +324,8 @@ void RendererImpl::postDeserialize()
|
|||
h3dSetNodeParamF(node, H3DLight::ColorF3, 1, 1.0f);
|
||||
h3dSetNodeParamF(node, H3DLight::ColorF3, 2, 1.0f);
|
||||
h3dSetNodeParamF(node, H3DLight::ColorMultiplierF, 0, 1.0f);
|
||||
Entity e(universe, lights[i].entity);
|
||||
universe->getEventManager()->emitEvent(ComponentEvent(Component(e, point_light_type, owner, i)));
|
||||
Entity e(m_universe, m_lights[i].m_entity);
|
||||
m_universe->getEventManager()->emitEvent(ComponentEvent(Component(e, point_light_type, m_owner, i)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,10 +339,10 @@ void Renderer::destroyPointLight(Component cmp)
|
|||
void RendererImpl::destroyPointLight(Component cmp)
|
||||
{
|
||||
assert(cmp.type == point_light_type);
|
||||
h3dRemoveNode(lights[cmp.index].node);
|
||||
lights[cmp.index].entity = first_free_light; // entity is used for freelist
|
||||
first_free_light = cmp.index;
|
||||
universe->getEventManager()->emitEvent(ComponentEvent(cmp, false));
|
||||
h3dRemoveNode(m_lights[cmp.index].m_node);
|
||||
m_lights[cmp.index].m_entity = m_first_free_light; // entity is used for freelist
|
||||
m_first_free_light = cmp.index;
|
||||
m_universe->getEventManager()->emitEvent(ComponentEvent(cmp, false));
|
||||
}
|
||||
|
||||
|
||||
|
@ -355,36 +355,36 @@ void Renderer::destroyRenderable(Component cmp)
|
|||
void RendererImpl::destroyRenderable(Component cmp)
|
||||
{
|
||||
assert(cmp.type == rend_type);
|
||||
h3dRemoveNode(renderables[cmp.index].node);
|
||||
paths[cmp.index] = "";
|
||||
renderables[cmp.index].entity = first_free_renderable; // entity is used for freelist
|
||||
first_free_renderable = cmp.index;
|
||||
universe->getEventManager()->emitEvent(ComponentEvent(cmp, false));
|
||||
h3dRemoveNode(m_renderables[cmp.index].m_node);
|
||||
m_paths[cmp.index] = "";
|
||||
m_renderables[cmp.index].m_entity = m_first_free_renderable; // entity is used for freelist
|
||||
m_first_free_renderable = cmp.index;
|
||||
m_universe->getEventManager()->emitEvent(ComponentEvent(cmp, false));
|
||||
}
|
||||
|
||||
|
||||
Component Renderer::createRenderable(Entity entity)
|
||||
{
|
||||
int index = -1;
|
||||
if(m_impl->first_free_renderable == -1)
|
||||
if(m_impl->m_first_free_renderable == -1)
|
||||
{
|
||||
m_impl->renderables.push_back_empty();
|
||||
m_impl->renderables.back().entity = entity.index;
|
||||
m_impl->renderables.back().node = 0;
|
||||
m_impl->paths.push_back("");
|
||||
index = m_impl->renderables.size() - 1;
|
||||
m_impl->m_renderables.push_back_empty();
|
||||
m_impl->m_renderables.back().m_entity = entity.index;
|
||||
m_impl->m_renderables.back().m_node = 0;
|
||||
m_impl->m_paths.push_back("");
|
||||
index = m_impl->m_renderables.size() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int next_free = m_impl->renderables[m_impl->first_free_renderable].entity;
|
||||
m_impl->renderables[m_impl->first_free_renderable].node = -1;
|
||||
m_impl->renderables[m_impl->first_free_renderable].entity = entity.index;
|
||||
m_impl->paths[m_impl->first_free_renderable] = "";
|
||||
index = m_impl->first_free_renderable;
|
||||
m_impl->first_free_renderable = next_free;
|
||||
int next_free = m_impl->m_renderables[m_impl->m_first_free_renderable].m_entity;
|
||||
m_impl->m_renderables[m_impl->m_first_free_renderable].m_node = -1;
|
||||
m_impl->m_renderables[m_impl->m_first_free_renderable].m_entity = entity.index;
|
||||
m_impl->m_paths[m_impl->m_first_free_renderable] = "";
|
||||
index = m_impl->m_first_free_renderable;
|
||||
m_impl->m_first_free_renderable = next_free;
|
||||
}
|
||||
Component cmp(entity, rend_type, this, index);
|
||||
m_impl->universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
m_impl->m_universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
return cmp;
|
||||
}
|
||||
|
||||
|
@ -392,7 +392,7 @@ Component Renderer::createRenderable(Entity entity)
|
|||
void Renderer::getCameraMatrix(Matrix& mtx)
|
||||
{
|
||||
const float* tmp;
|
||||
h3dGetNodeTransMats(m_impl->camera_node, 0, &tmp);
|
||||
h3dGetNodeTransMats(m_impl->m_camera_node, 0, &tmp);
|
||||
for(int i = 0; i < 16; ++i)
|
||||
{
|
||||
(&mtx.m11)[i] = tmp[i];
|
||||
|
@ -401,13 +401,13 @@ void Renderer::getCameraMatrix(Matrix& mtx)
|
|||
|
||||
void Renderer::setCameraMatrix(const Matrix& mtx)
|
||||
{
|
||||
h3dSetNodeTransMat(m_impl->camera_node, &mtx.m11);
|
||||
h3dSetNodeTransMat(m_impl->m_camera_node, &mtx.m11);
|
||||
}
|
||||
|
||||
|
||||
float Renderer::getHalfFovTan()
|
||||
{
|
||||
H3DNode node = m_impl->camera_node;
|
||||
H3DNode node = m_impl->m_camera_node;
|
||||
float top = h3dGetNodeParamF(node, H3DCamera::TopPlaneF, 1);
|
||||
float n = h3dGetNodeParamF(node, H3DCamera::NearPlaneF, 1);
|
||||
return top / n;
|
||||
|
@ -417,22 +417,22 @@ float Renderer::getHalfFovTan()
|
|||
Component Renderer::createPointLight(Entity entity)
|
||||
{
|
||||
int index = -1;
|
||||
if(m_impl->first_free_light == -1)
|
||||
if(m_impl->m_first_free_light == -1)
|
||||
{
|
||||
m_impl->lights.push_back_empty();
|
||||
m_impl->lights.back().entity = entity.index;
|
||||
index = m_impl->lights.size() - 1;
|
||||
m_impl->m_lights.push_back_empty();
|
||||
m_impl->m_lights.back().m_entity = entity.index;
|
||||
index = m_impl->m_lights.size() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int next_free = m_impl->lights[m_impl->first_free_light].entity;
|
||||
m_impl->lights[m_impl->first_free_light].node = -1;
|
||||
m_impl->lights[m_impl->first_free_light].entity = entity.index;
|
||||
index = m_impl->first_free_light;
|
||||
m_impl->first_free_light = next_free;
|
||||
int next_free = m_impl->m_lights[m_impl->m_first_free_light].m_entity;
|
||||
m_impl->m_lights[m_impl->m_first_free_light].m_node = -1;
|
||||
m_impl->m_lights[m_impl->m_first_free_light].m_entity = entity.index;
|
||||
index = m_impl->m_first_free_light;
|
||||
m_impl->m_first_free_light = next_free;
|
||||
}
|
||||
|
||||
H3DNode& node = m_impl->lights[index].node;
|
||||
H3DNode& node = m_impl->m_lights[index].m_node;
|
||||
node = h3dAddLightNode(H3DRootNode, "", 0, "LIGHTING", "SHADOWMAP");
|
||||
Matrix mtx;
|
||||
entity.getMatrix(mtx);
|
||||
|
@ -446,7 +446,7 @@ Component Renderer::createPointLight(Entity entity)
|
|||
h3dSetNodeParamF(node, H3DLight::ColorF3, 2, 1.0f);
|
||||
h3dSetNodeParamF(node, H3DLight::ColorMultiplierF, 0, 1.0f);
|
||||
Component cmp(entity, point_light_type, this, index);
|
||||
m_impl->universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
m_impl->m_universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
return cmp;
|
||||
}
|
||||
|
||||
|
@ -459,28 +459,28 @@ void onEvent(void* data, Event& event)
|
|||
|
||||
void Renderer::setUniverse(Universe* universe)
|
||||
{
|
||||
if(m_impl->universe)
|
||||
if(m_impl->m_universe)
|
||||
{
|
||||
for(int i = 0; i < m_impl->renderables.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_renderables.size(); ++i)
|
||||
{
|
||||
h3dRemoveNode(m_impl->renderables[i].node);
|
||||
h3dRemoveNode(m_impl->m_renderables[i].m_node);
|
||||
}
|
||||
m_impl->renderables.clear();
|
||||
for(int i = 0; i < m_impl->lights.size(); ++i)
|
||||
m_impl->m_renderables.clear();
|
||||
for(int i = 0; i < m_impl->m_lights.size(); ++i)
|
||||
{
|
||||
h3dRemoveNode(m_impl->lights[i].node);
|
||||
h3dRemoveNode(m_impl->m_lights[i].m_node);
|
||||
}
|
||||
m_impl->lights.clear();
|
||||
m_impl->entities.clear();
|
||||
m_impl->paths.clear();
|
||||
m_impl->universe->getEventManager()->unregisterListener(EntityMovedEvent::type, m_impl, &onEvent);
|
||||
m_impl->universe->getEventManager()->unregisterListener(EntityDestroyedEvent::type, m_impl, &onEvent);
|
||||
m_impl->m_lights.clear();
|
||||
m_impl->m_entities.clear();
|
||||
m_impl->m_paths.clear();
|
||||
m_impl->m_universe->getEventManager()->unregisterListener(EntityMovedEvent::type, m_impl, &onEvent);
|
||||
m_impl->m_universe->getEventManager()->unregisterListener(EntityDestroyedEvent::type, m_impl, &onEvent);
|
||||
}
|
||||
m_impl->universe = universe;
|
||||
if(m_impl->universe)
|
||||
m_impl->m_universe = universe;
|
||||
if(m_impl->m_universe)
|
||||
{
|
||||
m_impl->universe->getEventManager()->registerListener(EntityMovedEvent::type, m_impl, &onEvent);
|
||||
m_impl->universe->getEventManager()->registerListener(EntityDestroyedEvent::type, m_impl, &onEvent);
|
||||
m_impl->m_universe->getEventManager()->registerListener(EntityMovedEvent::type, m_impl, &onEvent);
|
||||
m_impl->m_universe->getEventManager()->registerListener(EntityDestroyedEvent::type, m_impl, &onEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -497,13 +497,13 @@ void RendererImpl::onEvent(Event& event)
|
|||
if(cmps[i].type == rend_type)
|
||||
{
|
||||
cmps[i].entity.getMatrix(mtx);
|
||||
h3dSetNodeTransMat(renderables[cmps[i].index].node, &mtx.m11);
|
||||
h3dSetNodeTransMat(m_renderables[cmps[i].index].m_node, &mtx.m11);
|
||||
break;
|
||||
}
|
||||
else if(cmps[i].type == point_light_type)
|
||||
{
|
||||
cmps[i].entity.getMatrix(mtx);
|
||||
h3dSetNodeTransMat(lights[cmps[i].index].node, &mtx.m11);
|
||||
h3dSetNodeTransMat(m_lights[cmps[i].index].m_node, &mtx.m11);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -534,49 +534,49 @@ void RendererImpl::onEvent(Event& event)
|
|||
|
||||
const char* Renderer::getBasePath() const
|
||||
{
|
||||
return m_impl->base_path.c_str();
|
||||
return m_impl->m_base_path.c_str();
|
||||
}
|
||||
|
||||
|
||||
int Renderer::getWidth() const
|
||||
{
|
||||
return m_impl->width;
|
||||
return m_impl->m_width;
|
||||
}
|
||||
|
||||
|
||||
int Renderer::getHeight() const
|
||||
{
|
||||
return m_impl->height;
|
||||
return m_impl->m_height;
|
||||
}
|
||||
|
||||
|
||||
H3DNode Renderer::getMeshNode(Component cmp)
|
||||
{
|
||||
return m_impl->renderables[cmp.index].node;
|
||||
return m_impl->m_renderables[cmp.index].m_node;
|
||||
}
|
||||
|
||||
|
||||
H3DNode Renderer::getRawCameraNode()
|
||||
{
|
||||
return m_impl->camera_node;
|
||||
return m_impl->m_camera_node;
|
||||
}
|
||||
|
||||
|
||||
void Renderer::serialize(ISerializer& serializer)
|
||||
{
|
||||
serializer.serialize("count", m_impl->renderables.size());
|
||||
serializer.serialize("count", m_impl->m_renderables.size());
|
||||
serializer.beginArray("renderables");
|
||||
for(int i = 0; i < m_impl->renderables.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_renderables.size(); ++i)
|
||||
{
|
||||
serializer.serializeArrayItem(m_impl->renderables[i].entity);
|
||||
serializer.serializeArrayItem(m_impl->paths[i]);
|
||||
serializer.serializeArrayItem(m_impl->m_renderables[i].m_entity);
|
||||
serializer.serializeArrayItem(m_impl->m_paths[i]);
|
||||
}
|
||||
serializer.endArray();
|
||||
serializer.serialize("count", m_impl->lights.size());
|
||||
serializer.serialize("count", m_impl->m_lights.size());
|
||||
serializer.beginArray("lights");
|
||||
for(int i = 0; i < m_impl->lights.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_lights.size(); ++i)
|
||||
{
|
||||
serializer.serializeArrayItem(m_impl->lights[i].entity);
|
||||
serializer.serializeArrayItem(m_impl->m_lights[i].m_entity);
|
||||
}
|
||||
serializer.endArray();
|
||||
}
|
||||
|
@ -585,22 +585,22 @@ void Renderer::deserialize(ISerializer& serializer)
|
|||
{
|
||||
int count;
|
||||
serializer.deserialize("count", count);
|
||||
m_impl->renderables.resize(count);
|
||||
m_impl->paths.resize(count);
|
||||
m_impl->m_renderables.resize(count);
|
||||
m_impl->m_paths.resize(count);
|
||||
serializer.deserializeArrayBegin("renderables");
|
||||
for(int i = 0; i < m_impl->paths.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_paths.size(); ++i)
|
||||
{
|
||||
m_impl->renderables[i].node = 0;
|
||||
serializer.deserializeArrayItem(m_impl->renderables[i].entity);
|
||||
serializer.deserializeArrayItem(m_impl->paths[i]);
|
||||
m_impl->m_renderables[i].m_node = 0;
|
||||
serializer.deserializeArrayItem(m_impl->m_renderables[i].m_entity);
|
||||
serializer.deserializeArrayItem(m_impl->m_paths[i]);
|
||||
}
|
||||
serializer.deserializeArrayEnd();
|
||||
serializer.deserialize("count", count);
|
||||
m_impl->lights.resize(count);
|
||||
m_impl->m_lights.resize(count);
|
||||
serializer.deserializeArrayBegin("lights");
|
||||
for(int i = 0; i < m_impl->lights.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_lights.size(); ++i)
|
||||
{
|
||||
serializer.deserializeArrayItem(m_impl->lights[i].entity);
|
||||
serializer.deserializeArrayItem(m_impl->m_lights[i].m_entity);
|
||||
}
|
||||
serializer.deserializeArrayEnd();
|
||||
m_impl->postDeserialize();
|
||||
|
|
|
@ -31,22 +31,21 @@ struct PhysicsSceneImpl
|
|||
|
||||
struct Controller
|
||||
{
|
||||
physx::PxController* controller;
|
||||
Entity entity;
|
||||
physx::PxController* m_controller;
|
||||
Entity m_entity;
|
||||
};
|
||||
|
||||
Universe* universe;
|
||||
physx::PxScene* scene;
|
||||
PhysicsSystem* system;
|
||||
physx::PxMaterial* default_material;
|
||||
vector<physx::PxRigidActor*> actors;
|
||||
vector<string> shape_sources;
|
||||
vector<bool> is_dynamic;
|
||||
vector<Entity> entities;
|
||||
vector<int> index_map;
|
||||
|
||||
vector<Controller> controllers;
|
||||
PhysicsScene* owner;
|
||||
Universe* m_universe;
|
||||
physx::PxScene* m_scene;
|
||||
PhysicsSystem* m_system;
|
||||
physx::PxMaterial* m_default_material;
|
||||
vector<physx::PxRigidActor*> m_actors;
|
||||
vector<string> m_shape_sources;
|
||||
vector<bool> m_is_dynamic;
|
||||
vector<Entity> m_entities;
|
||||
vector<int> m_index_map;
|
||||
vector<Controller> m_controllers;
|
||||
PhysicsScene* m_owner;
|
||||
};
|
||||
|
||||
|
||||
|
@ -132,10 +131,10 @@ PhysicsScene::PhysicsScene()
|
|||
bool PhysicsScene::create(PhysicsSystem& system, Universe& universe)
|
||||
{
|
||||
m_impl = new PhysicsSceneImpl;
|
||||
m_impl->owner = this;
|
||||
m_impl->universe = &universe;
|
||||
m_impl->universe->getEventManager()->registerListener(EntityMovedEvent::type, m_impl, &PhysicsSceneImpl::handleEvent);
|
||||
physx::PxSceneDesc sceneDesc(system.m_impl->physics->getTolerancesScale());
|
||||
m_impl->m_owner = this;
|
||||
m_impl->m_universe = &universe;
|
||||
m_impl->m_universe->getEventManager()->registerListener(EntityMovedEvent::type, m_impl, &PhysicsSceneImpl::handleEvent);
|
||||
physx::PxSceneDesc sceneDesc(system.m_impl->m_physics->getTolerancesScale());
|
||||
sceneDesc.gravity = physx::PxVec3(0.0f, -9.8f, 0.0f);
|
||||
if(!sceneDesc.cpuDispatcher) {
|
||||
physx::PxDefaultCpuDispatcher* cpu_dispatcher = physx::PxDefaultCpuDispatcherCreate(1);
|
||||
|
@ -146,21 +145,21 @@ bool PhysicsScene::create(PhysicsSystem& system, Universe& universe)
|
|||
if(!sceneDesc.filterShader)
|
||||
sceneDesc.filterShader = &physx::PxDefaultSimulationFilterShader;
|
||||
|
||||
m_impl->scene = system.m_impl->physics->createScene(sceneDesc);
|
||||
if (!m_impl->scene)
|
||||
m_impl->m_scene = system.m_impl->m_physics->createScene(sceneDesc);
|
||||
if (!m_impl->m_scene)
|
||||
return false;
|
||||
m_impl->scene->setVisualizationParameter(physx::PxVisualizationParameter::eSCALE, 1.0);
|
||||
m_impl->scene->setVisualizationParameter(physx::PxVisualizationParameter::eCOLLISION_SHAPES, 1.0f);
|
||||
m_impl->system = &system;
|
||||
m_impl->default_material = m_impl->system->m_impl->physics->createMaterial(0.5,0.5,0.5);
|
||||
m_impl->m_scene->setVisualizationParameter(physx::PxVisualizationParameter::eSCALE, 1.0);
|
||||
m_impl->m_scene->setVisualizationParameter(physx::PxVisualizationParameter::eCOLLISION_SHAPES, 1.0f);
|
||||
m_impl->m_system = &system;
|
||||
m_impl->m_default_material = m_impl->m_system->m_impl->m_physics->createMaterial(0.5,0.5,0.5);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void PhysicsScene::destroy()
|
||||
{
|
||||
m_impl->default_material->release();
|
||||
m_impl->scene->release();
|
||||
m_impl->m_default_material->release();
|
||||
m_impl->m_scene->release();
|
||||
delete m_impl;
|
||||
m_impl = 0;
|
||||
}
|
||||
|
@ -183,31 +182,31 @@ void matrix2Transform(const Matrix& mtx, physx::PxTransform& transform)
|
|||
void PhysicsScene::destroyActor(Component cmp)
|
||||
{
|
||||
assert(cmp.type == physical_type);
|
||||
int inner_index = m_impl->index_map[cmp.index];
|
||||
m_impl->scene->removeActor(*m_impl->actors[inner_index]);
|
||||
m_impl->actors[inner_index]->release();
|
||||
m_impl->universe->getEventManager()->emitEvent(ComponentEvent(cmp, false));
|
||||
m_impl->actors.eraseFast(inner_index);
|
||||
m_impl->shape_sources.eraseFast(inner_index);
|
||||
m_impl->is_dynamic.eraseFast(inner_index);
|
||||
m_impl->entities.eraseFast(inner_index);
|
||||
for(int i = 0; i < m_impl->index_map.size(); ++i)
|
||||
int inner_index = m_impl->m_index_map[cmp.index];
|
||||
m_impl->m_scene->removeActor(*m_impl->m_actors[inner_index]);
|
||||
m_impl->m_actors[inner_index]->release();
|
||||
m_impl->m_universe->getEventManager()->emitEvent(ComponentEvent(cmp, false));
|
||||
m_impl->m_actors.eraseFast(inner_index);
|
||||
m_impl->m_shape_sources.eraseFast(inner_index);
|
||||
m_impl->m_is_dynamic.eraseFast(inner_index);
|
||||
m_impl->m_entities.eraseFast(inner_index);
|
||||
for(int i = 0; i < m_impl->m_index_map.size(); ++i)
|
||||
{
|
||||
if(m_impl->index_map[i] == m_impl->entities.size())
|
||||
if(m_impl->m_index_map[i] == m_impl->m_entities.size())
|
||||
{
|
||||
m_impl->index_map[i] = inner_index;
|
||||
m_impl->m_index_map[i] = inner_index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_impl->index_map[cmp.index] = -1;
|
||||
m_impl->universe->getEventManager()->emitEvent(ComponentEvent(cmp, false));
|
||||
m_impl->m_index_map[cmp.index] = -1;
|
||||
m_impl->m_universe->getEventManager()->emitEvent(ComponentEvent(cmp, false));
|
||||
}
|
||||
|
||||
|
||||
Component PhysicsScene::createController(Entity entity)
|
||||
{
|
||||
physx::PxCapsuleControllerDesc cDesc;
|
||||
cDesc.material = m_impl->default_material;
|
||||
cDesc.material = m_impl->m_default_material;
|
||||
cDesc.height = 1.8f;
|
||||
cDesc.radius = 0.25f;
|
||||
cDesc.slopeLimit = 0.0f;
|
||||
|
@ -218,57 +217,57 @@ Component PhysicsScene::createController(Entity entity)
|
|||
Vec3 position = entity.getPosition();
|
||||
cDesc.position.set(position.x, position.y, position.z);
|
||||
PhysicsSceneImpl::Controller c;
|
||||
c.controller = m_impl->system->m_impl->controller_manager->createController(*m_impl->system->m_impl->physics, m_impl->scene, cDesc);
|
||||
c.entity = entity;
|
||||
c.m_controller = m_impl->m_system->m_impl->m_controller_manager->createController(*m_impl->m_system->m_impl->m_physics, m_impl->m_scene, cDesc);
|
||||
c.m_entity = entity;
|
||||
|
||||
m_impl->controllers.push_back(c);
|
||||
m_impl->m_controllers.push_back(c);
|
||||
|
||||
Component cmp(entity, controller_type, this, m_impl->controllers.size() - 1);
|
||||
m_impl->universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
Component cmp(entity, controller_type, this, m_impl->m_controllers.size() - 1);
|
||||
m_impl->m_universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
return cmp;
|
||||
}
|
||||
|
||||
|
||||
Component PhysicsScene::createActor(Entity entity)
|
||||
{
|
||||
int new_index = m_impl->entities.size();
|
||||
for(int i = 0; i < m_impl->index_map.size(); ++i)
|
||||
int new_index = m_impl->m_entities.size();
|
||||
for(int i = 0; i < m_impl->m_index_map.size(); ++i)
|
||||
{
|
||||
if(m_impl->index_map[i] == -1)
|
||||
if(m_impl->m_index_map[i] == -1)
|
||||
{
|
||||
new_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(new_index == m_impl->entities.size())
|
||||
if(new_index == m_impl->m_entities.size())
|
||||
{
|
||||
m_impl->actors.push_back(0);
|
||||
m_impl->shape_sources.push_back("");
|
||||
m_impl->is_dynamic.push_back(false);
|
||||
m_impl->entities.push_back(entity);
|
||||
m_impl->m_actors.push_back(0);
|
||||
m_impl->m_shape_sources.push_back("");
|
||||
m_impl->m_is_dynamic.push_back(false);
|
||||
m_impl->m_entities.push_back(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_impl->actors[new_index] = 0;
|
||||
m_impl->shape_sources[new_index] = "";
|
||||
m_impl->is_dynamic[new_index] = false;
|
||||
m_impl->entities[new_index] = entity;
|
||||
m_impl->m_actors[new_index] = 0;
|
||||
m_impl->m_shape_sources[new_index] = "";
|
||||
m_impl->m_is_dynamic[new_index] = false;
|
||||
m_impl->m_entities[new_index] = entity;
|
||||
}
|
||||
Component cmp(entity, physical_type, this, m_impl->actors.size() - 1);
|
||||
m_impl->universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
Component cmp(entity, physical_type, this, m_impl->m_actors.size() - 1);
|
||||
m_impl->m_universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
return cmp;
|
||||
}
|
||||
|
||||
|
||||
void PhysicsScene::getShapeSource(Component cmp, string& str)
|
||||
{
|
||||
str = m_impl->shape_sources[cmp.index];
|
||||
str = m_impl->m_shape_sources[cmp.index];
|
||||
}
|
||||
|
||||
|
||||
void PhysicsScene::setShapeSource(Component cmp, const string& str)
|
||||
{
|
||||
if(m_impl->actors[cmp.index] && m_impl->shape_sources[cmp.index] == str && m_impl->is_dynamic[cmp.index] == !m_impl->actors[cmp.index]->isRigidStatic())
|
||||
if(m_impl->m_actors[cmp.index] && m_impl->m_shape_sources[cmp.index] == str && m_impl->m_is_dynamic[cmp.index] == !m_impl->m_actors[cmp.index]->isRigidStatic())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -339,31 +338,31 @@ void PhysicsScene::setShapeSource(Component cmp, const string& str)
|
|||
}
|
||||
delete[] buffer;
|
||||
|
||||
if(m_impl->actors[cmp.index])
|
||||
if(m_impl->m_actors[cmp.index])
|
||||
{
|
||||
m_impl->scene->removeActor(*m_impl->actors[cmp.index]);
|
||||
m_impl->actors[cmp.index]->release();
|
||||
m_impl->actors[cmp.index] = 0;
|
||||
m_impl->m_scene->removeActor(*m_impl->m_actors[cmp.index]);
|
||||
m_impl->m_actors[cmp.index]->release();
|
||||
m_impl->m_actors[cmp.index] = 0;
|
||||
}
|
||||
|
||||
if(geom)
|
||||
{
|
||||
physx::PxRigidActor* actor;
|
||||
if(m_impl->is_dynamic[cmp.index])
|
||||
if(m_impl->m_is_dynamic[cmp.index])
|
||||
{
|
||||
actor = PxCreateDynamic(*m_impl->system->m_impl->physics, transform, *geom, *m_impl->default_material, 1.0f);
|
||||
actor = PxCreateDynamic(*m_impl->m_system->m_impl->m_physics, transform, *geom, *m_impl->m_default_material, 1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
actor = PxCreateStatic(*m_impl->system->m_impl->physics, transform, *geom, *m_impl->default_material);
|
||||
actor = PxCreateStatic(*m_impl->m_system->m_impl->m_physics, transform, *geom, *m_impl->m_default_material);
|
||||
}
|
||||
actor->userData = (void*)cmp.entity.index;
|
||||
m_impl->scene->addActor(*actor);
|
||||
m_impl->scene->simulate(0.01f);
|
||||
m_impl->scene->fetchResults(true);
|
||||
m_impl->actors[cmp.index] = actor;
|
||||
m_impl->m_scene->addActor(*actor);
|
||||
m_impl->m_scene->simulate(0.01f);
|
||||
m_impl->m_scene->fetchResults(true);
|
||||
m_impl->m_actors[cmp.index] = actor;
|
||||
actor->setActorFlag(physx::PxActorFlag::eVISUALIZATION, true);
|
||||
m_impl->shape_sources[cmp.index] = str;
|
||||
m_impl->m_shape_sources[cmp.index] = str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -395,10 +394,10 @@ void PhysicsSceneImpl::createTriMesh(const char* path, physx::PxTriangleMeshGeom
|
|||
meshDesc.triangles.data = &tris[0];
|
||||
|
||||
OutputStream writeBuffer;
|
||||
bool status = system->m_impl->cooking->cookTriangleMesh(meshDesc, writeBuffer);
|
||||
bool status = m_system->m_impl->m_cooking->cookTriangleMesh(meshDesc, writeBuffer);
|
||||
|
||||
InputStream readBuffer(writeBuffer.data, writeBuffer.size);
|
||||
geom.triangleMesh = system->m_impl->physics->createTriangleMesh(readBuffer);
|
||||
geom.triangleMesh = m_system->m_impl->m_physics->createTriangleMesh(readBuffer);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
@ -425,12 +424,12 @@ void PhysicsSceneImpl::createConvexGeom(const char* path, physx::PxConvexMeshGeo
|
|||
meshDesc.flags = physx::PxConvexFlag::eCOMPUTE_CONVEX;
|
||||
|
||||
OutputStream writeBuffer;
|
||||
bool status = system->m_impl->cooking->cookConvexMesh(meshDesc, writeBuffer);
|
||||
bool status = m_system->m_impl->m_cooking->cookConvexMesh(meshDesc, writeBuffer);
|
||||
if(!status)
|
||||
return;
|
||||
|
||||
InputStream readBuffer(writeBuffer.data, writeBuffer.size);
|
||||
physx::PxConvexMesh* mesh = system->m_impl->physics->createConvexMesh(readBuffer);
|
||||
physx::PxConvexMesh* mesh = m_system->m_impl->m_physics->createConvexMesh(readBuffer);
|
||||
geom.convexMesh = mesh;
|
||||
}
|
||||
}
|
||||
|
@ -438,18 +437,18 @@ void PhysicsSceneImpl::createConvexGeom(const char* path, physx::PxConvexMeshGeo
|
|||
|
||||
void PhysicsSceneImpl::postDeserialize()
|
||||
{
|
||||
actors.resize(shape_sources.size());
|
||||
for(int i = 0; i < shape_sources.size(); ++i)
|
||||
m_actors.resize(m_shape_sources.size());
|
||||
for(int i = 0; i < m_shape_sources.size(); ++i)
|
||||
{
|
||||
entities[i].universe = universe;
|
||||
owner->setIsDynamic(Component(entities[i], physical_type, this, i), is_dynamic[i]);
|
||||
Component cmp(entities[i], physical_type, owner, i);
|
||||
universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
m_entities[i].universe = m_universe;
|
||||
m_owner->setIsDynamic(Component(m_entities[i], physical_type, this, i), m_is_dynamic[i]);
|
||||
Component cmp(m_entities[i], physical_type, m_owner, i);
|
||||
m_universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
}
|
||||
index_map.resize(shape_sources.size());
|
||||
for(int i = 0; i < shape_sources.size(); ++i)
|
||||
m_index_map.resize(m_shape_sources.size());
|
||||
for(int i = 0; i < m_shape_sources.size(); ++i)
|
||||
{
|
||||
index_map[i] = i;
|
||||
m_index_map[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -457,30 +456,30 @@ void PhysicsSceneImpl::postDeserialize()
|
|||
void PhysicsSceneImpl::setControllerPosition(int index, const Vec3& pos)
|
||||
{
|
||||
physx::PxExtendedVec3 p(pos.x, pos.y, pos.z);
|
||||
controllers[index].controller->setPosition(p);
|
||||
m_controllers[index].m_controller->setPosition(p);
|
||||
}
|
||||
|
||||
|
||||
void PhysicsScene::update(float time_delta)
|
||||
{
|
||||
time_delta = 0.01f;
|
||||
m_impl->scene->simulate(time_delta);
|
||||
m_impl->scene->fetchResults(true);
|
||||
for(int i = 0; i < m_impl->is_dynamic.size(); ++i)
|
||||
m_impl->m_scene->simulate(time_delta);
|
||||
m_impl->m_scene->fetchResults(true);
|
||||
for(int i = 0; i < m_impl->m_is_dynamic.size(); ++i)
|
||||
{
|
||||
if(m_impl->is_dynamic[i])
|
||||
if(m_impl->m_is_dynamic[i])
|
||||
{
|
||||
physx::PxTransform trans = m_impl->actors[i]->getGlobalPose();
|
||||
m_impl->entities[i].setPosition(trans.p.x, trans.p.y, trans.p.z);
|
||||
m_impl->entities[i].setRotation(trans.q.x, trans.q.y, trans.q.z, trans.q.w);
|
||||
physx::PxTransform trans = m_impl->m_actors[i]->getGlobalPose();
|
||||
m_impl->m_entities[i].setPosition(trans.p.x, trans.p.y, trans.p.z);
|
||||
m_impl->m_entities[i].setRotation(trans.q.x, trans.q.y, trans.q.z, trans.q.w);
|
||||
}
|
||||
}
|
||||
physx::PxVec3 g(0, time_delta * -9.8f, 0);
|
||||
for(int i = 0; i < m_impl->controllers.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_controllers.size(); ++i)
|
||||
{
|
||||
const physx::PxExtendedVec3& p = m_impl->controllers[i].controller->getPosition();
|
||||
m_impl->controllers[i].controller->move(g, 0.0001f, time_delta, physx::PxControllerFilters());
|
||||
m_impl->controllers[i].entity.setPosition((float)p.x, (float)p.y, (float)p.z);
|
||||
const physx::PxExtendedVec3& p = m_impl->m_controllers[i].m_controller->getPosition();
|
||||
m_impl->m_controllers[i].m_controller->move(g, 0.0001f, time_delta, physx::PxControllerFilters());
|
||||
m_impl->m_controllers[i].m_entity.setPosition((float)p.x, (float)p.y, (float)p.z);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -488,7 +487,7 @@ void PhysicsScene::update(float time_delta)
|
|||
|
||||
void PhysicsScene::moveController(Component cmp, const Vec3& v, float dt)
|
||||
{
|
||||
m_impl->controllers[cmp.index].controller->move(physx::PxVec3(v.x, v.y, v.z), 0.001f, dt, physx::PxControllerFilters());
|
||||
m_impl->m_controllers[cmp.index].m_controller->move(physx::PxVec3(v.x, v.y, v.z), 0.001f, dt, physx::PxControllerFilters());
|
||||
}
|
||||
|
||||
|
||||
|
@ -501,7 +500,7 @@ bool PhysicsScene::raycast(const Vec3& origin, const Vec3& dir, float distance,
|
|||
|
||||
const physx::PxSceneQueryFlags outputFlags = physx::PxSceneQueryFlag::eDISTANCE | physx::PxSceneQueryFlag::eIMPACT | physx::PxSceneQueryFlag::eNORMAL;
|
||||
|
||||
bool status = m_impl->scene->raycastSingle(physx_origin, unit_dir, max_distance, outputFlags, hit);
|
||||
bool status = m_impl->m_scene->raycastSingle(physx_origin, unit_dir, max_distance, outputFlags, hit);
|
||||
result.normal.x = hit.normal.x;
|
||||
result.normal.y = hit.normal.y;
|
||||
result.normal.z = hit.normal.z;
|
||||
|
@ -541,9 +540,9 @@ void PhysicsSceneImpl::handleEvent(Event& event)
|
|||
e.getMatrix().getRotation(q);
|
||||
physx::PxQuat pquat(q.x, q.y, q.z, q.w);
|
||||
physx::PxTransform trans(pvec, pquat);
|
||||
if(actors[cmps[i].index])
|
||||
if(m_actors[cmps[i].index])
|
||||
{
|
||||
actors[cmps[i].index]->setGlobalPose(trans, false);
|
||||
m_actors[cmps[i].index]->setGlobalPose(trans, false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -551,7 +550,7 @@ void PhysicsSceneImpl::handleEvent(Event& event)
|
|||
{
|
||||
Vec3 pos = e.getPosition();
|
||||
physx::PxExtendedVec3 pvec(pos.x, pos.y, pos.z);
|
||||
controllers[cmps[i].index].controller->setPosition(pvec);
|
||||
m_controllers[cmps[i].index].m_controller->setPosition(pvec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -561,33 +560,33 @@ void PhysicsSceneImpl::handleEvent(Event& event)
|
|||
|
||||
void PhysicsScene::getIsDynamic(Component cmp, bool& is)
|
||||
{
|
||||
is = m_impl->is_dynamic[cmp.index];
|
||||
is = m_impl->m_is_dynamic[cmp.index];
|
||||
}
|
||||
|
||||
|
||||
void PhysicsScene::setIsDynamic(Component cmp, const bool& is)
|
||||
{
|
||||
m_impl->is_dynamic[cmp.index] = is;
|
||||
setShapeSource(cmp, m_impl->shape_sources[cmp.index]);
|
||||
m_impl->m_is_dynamic[cmp.index] = is;
|
||||
setShapeSource(cmp, m_impl->m_shape_sources[cmp.index]);
|
||||
}
|
||||
|
||||
|
||||
void PhysicsScene::serialize(ISerializer& serializer)
|
||||
{
|
||||
serializer.serialize("count", m_impl->shape_sources.size());
|
||||
serializer.serialize("count", m_impl->m_shape_sources.size());
|
||||
serializer.beginArray("actors");
|
||||
for(int i = 0; i < m_impl->shape_sources.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_shape_sources.size(); ++i)
|
||||
{
|
||||
serializer.serializeArrayItem(m_impl->shape_sources[i]);
|
||||
serializer.serializeArrayItem(m_impl->is_dynamic[i]);
|
||||
serializer.serializeArrayItem(m_impl->entities[i].index);
|
||||
serializer.serializeArrayItem(m_impl->m_shape_sources[i]);
|
||||
serializer.serializeArrayItem(m_impl->m_is_dynamic[i]);
|
||||
serializer.serializeArrayItem(m_impl->m_entities[i].index);
|
||||
}
|
||||
serializer.endArray();
|
||||
serializer.serialize("count", m_impl->controllers.size());
|
||||
serializer.serialize("count", m_impl->m_controllers.size());
|
||||
serializer.beginArray("controllers");
|
||||
for(int i = 0; i < m_impl->controllers.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_controllers.size(); ++i)
|
||||
{
|
||||
serializer.serializeArrayItem(m_impl->controllers[i].entity.index);
|
||||
serializer.serializeArrayItem(m_impl->m_controllers[i].m_entity.index);
|
||||
}
|
||||
serializer.endArray();
|
||||
}
|
||||
|
@ -597,24 +596,24 @@ void PhysicsScene::deserialize(ISerializer& serializer)
|
|||
{
|
||||
int count;
|
||||
serializer.deserialize("count", count);
|
||||
m_impl->shape_sources.resize(count);
|
||||
m_impl->is_dynamic.resize(count);
|
||||
m_impl->entities.resize(count);
|
||||
m_impl->m_shape_sources.resize(count);
|
||||
m_impl->m_is_dynamic.resize(count);
|
||||
m_impl->m_entities.resize(count);
|
||||
serializer.deserializeArrayBegin("actors");
|
||||
for(int i = 0; i < m_impl->shape_sources.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_shape_sources.size(); ++i)
|
||||
{
|
||||
serializer.deserializeArrayItem(m_impl->shape_sources[i]);
|
||||
serializer.deserializeArrayItem(m_impl->is_dynamic[i]);
|
||||
serializer.deserializeArrayItem(m_impl->entities[i].index);
|
||||
serializer.deserializeArrayItem(m_impl->m_shape_sources[i]);
|
||||
serializer.deserializeArrayItem(m_impl->m_is_dynamic[i]);
|
||||
serializer.deserializeArrayItem(m_impl->m_entities[i].index);
|
||||
}
|
||||
serializer.deserialize("count", count);
|
||||
m_impl->controllers.clear();
|
||||
m_impl->m_controllers.clear();
|
||||
serializer.deserializeArrayBegin("controllers");
|
||||
for(int i = 0; i < count; ++i)
|
||||
{
|
||||
int index;
|
||||
serializer.deserializeArrayItem(index);
|
||||
Entity e(m_impl->universe, index);
|
||||
Entity e(m_impl->m_universe, index);
|
||||
createController(e);
|
||||
m_impl->setControllerPosition(i, e.getPosition());
|
||||
}
|
||||
|
@ -625,13 +624,13 @@ void PhysicsScene::deserialize(ISerializer& serializer)
|
|||
|
||||
PhysicsSystem& PhysicsScene::getSystem() const
|
||||
{
|
||||
return *m_impl->system;
|
||||
return *m_impl->m_system;
|
||||
}
|
||||
|
||||
|
||||
physx::PxScene* PhysicsScene::getRawScene()
|
||||
{
|
||||
return m_impl->scene;
|
||||
return m_impl->m_scene;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,29 +40,29 @@ struct CustomErrorCallback : public physx::PxErrorCallback
|
|||
|
||||
void PhysicsSystem::onCreateUniverse(Universe& universe)
|
||||
{
|
||||
m_impl->scene = new PhysicsScene();
|
||||
m_impl->scene->create(*this, universe);
|
||||
m_impl->m_scene = new PhysicsScene();
|
||||
m_impl->m_scene->create(*this, universe);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void PhysicsSystem::onDestroyUniverse(Universe& universe)
|
||||
{
|
||||
m_impl->scene->destroy();
|
||||
delete m_impl->scene;
|
||||
m_impl->scene = 0;
|
||||
m_impl->m_scene->destroy();
|
||||
delete m_impl->m_scene;
|
||||
m_impl->m_scene = 0;
|
||||
}
|
||||
|
||||
|
||||
void PhysicsSystem::serialize(ISerializer& serializer)
|
||||
{
|
||||
m_impl->scene->serialize(serializer);
|
||||
m_impl->m_scene->serialize(serializer);
|
||||
}
|
||||
|
||||
|
||||
void PhysicsSystem::deserialize(ISerializer& serializer)
|
||||
{
|
||||
m_impl->scene->deserialize(serializer);
|
||||
m_impl->m_scene->deserialize(serializer);
|
||||
}
|
||||
|
||||
|
||||
|
@ -70,11 +70,11 @@ Component PhysicsSystem::createComponent(uint32_t component_type, const Entity&
|
|||
{
|
||||
if(component_type == controller_type)
|
||||
{
|
||||
return m_impl->scene->createController(entity);
|
||||
return m_impl->m_scene->createController(entity);
|
||||
}
|
||||
else if(component_type == physical_type)
|
||||
{
|
||||
return m_impl->scene->createActor(entity);
|
||||
return m_impl->m_scene->createActor(entity);
|
||||
}
|
||||
return Component::INVALID;
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ Component PhysicsSystem::createComponent(uint32_t component_type, const Entity&
|
|||
|
||||
void PhysicsSystem::update(float dt)
|
||||
{
|
||||
m_impl->scene->update(dt);
|
||||
m_impl->m_scene->update(dt);
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,22 +95,22 @@ bool PhysicsSystem::create(EditorPropertyMap& properties, ComponentCreatorList&
|
|||
creators.insert(controller_type, this);
|
||||
|
||||
m_impl = new PhysicsSystemImpl;
|
||||
m_impl->allocator = new physx::PxDefaultAllocator();
|
||||
m_impl->error_callback = new CustomErrorCallback();
|
||||
m_impl->foundation = PxCreateFoundation(
|
||||
m_impl->m_allocator = new physx::PxDefaultAllocator();
|
||||
m_impl->m_error_callback = new CustomErrorCallback();
|
||||
m_impl->m_foundation = PxCreateFoundation(
|
||||
PX_PHYSICS_VERSION,
|
||||
*m_impl->allocator,
|
||||
*m_impl->error_callback
|
||||
*m_impl->m_allocator,
|
||||
*m_impl->m_error_callback
|
||||
);
|
||||
|
||||
m_impl->physics = PxCreatePhysics(
|
||||
m_impl->m_physics = PxCreatePhysics(
|
||||
PX_PHYSICS_VERSION,
|
||||
*m_impl->foundation,
|
||||
*m_impl->m_foundation,
|
||||
physx::PxTolerancesScale()
|
||||
);
|
||||
|
||||
m_impl->controller_manager = PxCreateControllerManager(*m_impl->foundation);
|
||||
m_impl->cooking = PxCreateCooking(PX_PHYSICS_VERSION, *m_impl->foundation, physx::PxCookingParams());
|
||||
m_impl->m_controller_manager = PxCreateControllerManager(*m_impl->m_foundation);
|
||||
m_impl->m_cooking = PxCreateCooking(PX_PHYSICS_VERSION, *m_impl->m_foundation, physx::PxCookingParams());
|
||||
m_impl->connect2VisualDebugger();
|
||||
return true;
|
||||
}
|
||||
|
@ -118,12 +118,12 @@ bool PhysicsSystem::create(EditorPropertyMap& properties, ComponentCreatorList&
|
|||
|
||||
void PhysicsSystem::destroy()
|
||||
{
|
||||
m_impl->controller_manager->release();
|
||||
m_impl->cooking->release();
|
||||
m_impl->physics->release();
|
||||
m_impl->foundation->release();
|
||||
delete m_impl->allocator;
|
||||
delete m_impl->error_callback;
|
||||
m_impl->m_controller_manager->release();
|
||||
m_impl->m_cooking->release();
|
||||
m_impl->m_physics->release();
|
||||
m_impl->m_foundation->release();
|
||||
delete m_impl->m_allocator;
|
||||
delete m_impl->m_error_callback;
|
||||
delete m_impl;
|
||||
m_impl = 0;
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ void PhysicsSystem::destroy()
|
|||
|
||||
bool PhysicsSystemImpl::connect2VisualDebugger()
|
||||
{
|
||||
if(physics->getPvdConnectionManager() == NULL)
|
||||
if(m_physics->getPvdConnectionManager() == NULL)
|
||||
return false;
|
||||
|
||||
const char* pvd_host_ip = "127.0.0.1";
|
||||
|
@ -139,7 +139,7 @@ bool PhysicsSystemImpl::connect2VisualDebugger()
|
|||
unsigned int timeout = 100;
|
||||
physx::PxVisualDebuggerConnectionFlags connectionFlags = physx::PxVisualDebuggerExt::getAllConnectionFlags();
|
||||
|
||||
PVD::PvdConnection* theConnection = physx::PxVisualDebuggerExt::createConnection(physics->getPvdConnectionManager(), pvd_host_ip, port, timeout, connectionFlags);
|
||||
PVD::PvdConnection* theConnection = physx::PxVisualDebuggerExt::createConnection(m_physics->getPvdConnectionManager(), pvd_host_ip, port, timeout, connectionFlags);
|
||||
return theConnection != NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,13 +12,13 @@ struct PhysicsSystemImpl
|
|||
{
|
||||
bool connect2VisualDebugger();
|
||||
|
||||
physx::PxPhysics* physics;
|
||||
physx::PxFoundation* foundation;
|
||||
physx::PxControllerManager* controller_manager;
|
||||
physx::PxAllocatorCallback* allocator;
|
||||
physx::PxErrorCallback* error_callback;
|
||||
physx::PxCooking* cooking;
|
||||
class PhysicsScene* scene;
|
||||
physx::PxPhysics* m_physics;
|
||||
physx::PxFoundation* m_foundation;
|
||||
physx::PxControllerManager* m_controller_manager;
|
||||
physx::PxAllocatorCallback* m_allocator;
|
||||
physx::PxErrorCallback* m_error_callback;
|
||||
physx::PxCooking* m_cooking;
|
||||
class PhysicsScene* m_scene;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -32,20 +32,20 @@ namespace Lux
|
|||
SUCCESS,
|
||||
FAIL
|
||||
};
|
||||
string path;
|
||||
IFileSystem::ReadCallback callback;
|
||||
void* user_data;
|
||||
char* file_data;
|
||||
int file_length;
|
||||
int uid;
|
||||
Status status;
|
||||
string m_path;
|
||||
IFileSystem::ReadCallback m_callback;
|
||||
void* m_user_data;
|
||||
char* m_file_data;
|
||||
int m_file_length;
|
||||
int m_uid;
|
||||
Status m_status;
|
||||
};
|
||||
|
||||
TCPFileSystemTask* task;
|
||||
vector<FileItem*> queue;
|
||||
vector<FileItem*> loaded;
|
||||
vector<FileItem*> in_progress;
|
||||
int last_uid;
|
||||
TCPFileSystemTask* m_task;
|
||||
vector<FileItem*> m_queue;
|
||||
vector<FileItem*> m_loaded;
|
||||
vector<FileItem*> m_in_progress;
|
||||
int m_last_uid;
|
||||
};
|
||||
|
||||
|
||||
|
@ -60,21 +60,21 @@ namespace Lux
|
|||
while(!m_finished)
|
||||
{
|
||||
m_mutex.lock();
|
||||
if(!m_fs->queue.empty())
|
||||
if(!m_fs->m_queue.empty())
|
||||
{
|
||||
TCPFileSystemImpl::FileItem* item = m_fs->queue.back();
|
||||
m_fs->queue.pop_back();
|
||||
TCPFileSystemImpl::FileItem* item = m_fs->m_queue.back();
|
||||
m_fs->m_queue.pop_back();
|
||||
m_mutex.unlock();
|
||||
|
||||
int len = item->path.length() + 5;
|
||||
int len = item->m_path.length() + 5;
|
||||
memcpy(buffer, &len, sizeof(len));
|
||||
buffer[4] = 0;
|
||||
memcpy(buffer+5, &item->uid, sizeof(item->uid));
|
||||
memcpy(buffer+5, &item->m_uid, sizeof(item->m_uid));
|
||||
|
||||
m_work_socket->send(buffer, 9);
|
||||
m_work_socket->send(item->path.c_str(), item->path.length());
|
||||
m_work_socket->send(item->m_path.c_str(), item->m_path.length());
|
||||
|
||||
m_fs->in_progress.push_back(item);
|
||||
m_fs->m_in_progress.push_back(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -108,28 +108,28 @@ namespace Lux
|
|||
{
|
||||
int uid = *(int*)(buffer + 5);
|
||||
bool found = false;
|
||||
for(int i = 0; i < m_fs->in_progress.size(); ++i)
|
||||
for(int i = 0; i < m_fs->m_in_progress.size(); ++i)
|
||||
{
|
||||
if(m_fs->in_progress[i]->uid == uid)
|
||||
if(m_fs->m_in_progress[i]->m_uid == uid)
|
||||
{
|
||||
if(len < 0)
|
||||
{
|
||||
m_fs->in_progress[i]->file_length = -1;
|
||||
m_fs->in_progress[i]->file_data = 0;
|
||||
m_fs->in_progress[i]->status = TCPFileSystemImpl::FileItem::FAIL;
|
||||
m_fs->m_in_progress[i]->m_file_length = -1;
|
||||
m_fs->m_in_progress[i]->m_file_data = 0;
|
||||
m_fs->m_in_progress[i]->m_status = TCPFileSystemImpl::FileItem::FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_fs->in_progress[i]->file_length = len - 5;
|
||||
m_fs->in_progress[i]->file_data = new char[len - 5];
|
||||
m_fs->m_in_progress[i]->m_file_length = len - 5;
|
||||
m_fs->m_in_progress[i]->m_file_data = new char[len - 5];
|
||||
if(size > 9)
|
||||
memcpy(m_fs->in_progress[i]->file_data, buffer + 9, size - 9);
|
||||
m_work_socket->receiveAllBytes(m_fs->in_progress[i]->file_data + size - 9, len - size + 4);
|
||||
m_fs->in_progress[i]->status = TCPFileSystemImpl::FileItem::SUCCESS;
|
||||
memcpy(m_fs->m_in_progress[i]->m_file_data, buffer + 9, size - 9);
|
||||
m_work_socket->receiveAllBytes(m_fs->m_in_progress[i]->m_file_data + size - 9, len - size + 4);
|
||||
m_fs->m_in_progress[i]->m_status = TCPFileSystemImpl::FileItem::SUCCESS;
|
||||
}
|
||||
m_mutex.lock();
|
||||
m_fs->loaded.push_back(m_fs->in_progress[i]);
|
||||
m_fs->in_progress.eraseFast(i);
|
||||
m_fs->m_loaded.push_back(m_fs->m_in_progress[i]);
|
||||
m_fs->m_in_progress.eraseFast(i);
|
||||
m_mutex.unlock();
|
||||
found = true;
|
||||
break;
|
||||
|
@ -148,18 +148,18 @@ namespace Lux
|
|||
|
||||
void TCPFileSystem::processLoaded()
|
||||
{
|
||||
m_impl->task->m_mutex.lock();
|
||||
if(!m_impl->loaded.empty())
|
||||
m_impl->m_task->m_mutex.lock();
|
||||
if(!m_impl->m_loaded.empty())
|
||||
{
|
||||
TCPFileSystemImpl::FileItem* item = m_impl->loaded.back();
|
||||
m_impl->loaded.pop_back();
|
||||
m_impl->task->m_mutex.lock();
|
||||
item->callback(item->user_data, item->file_data, item->file_length, item->status == TCPFileSystemImpl::FileItem::SUCCESS);
|
||||
TCPFileSystemImpl::FileItem* item = m_impl->m_loaded.back();
|
||||
m_impl->m_loaded.pop_back();
|
||||
m_impl->m_task->m_mutex.lock();
|
||||
item->m_callback(item->m_user_data, item->m_file_data, item->m_file_length, item->m_status == TCPFileSystemImpl::FileItem::SUCCESS);
|
||||
delete item;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_impl->task->m_mutex.unlock();
|
||||
m_impl->m_task->m_mutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,19 +174,19 @@ namespace Lux
|
|||
{
|
||||
Socket::init();
|
||||
m_impl = new TCPFileSystemImpl();
|
||||
m_impl->last_uid = 0;
|
||||
m_impl->task = new TCPFileSystemTask();
|
||||
m_impl->task->m_fs = m_impl;
|
||||
if(!m_impl->task->create())
|
||||
m_impl->m_last_uid = 0;
|
||||
m_impl->m_task = new TCPFileSystemTask();
|
||||
m_impl->m_task->m_fs = m_impl;
|
||||
if(!m_impl->m_task->create())
|
||||
{
|
||||
m_impl->task->m_mutex.create();
|
||||
m_impl->m_task->m_mutex.create();
|
||||
delete m_impl;
|
||||
m_impl = 0;
|
||||
return false;
|
||||
}
|
||||
if(!m_impl->task->run())
|
||||
if(!m_impl->m_task->run())
|
||||
{
|
||||
m_impl->task->destroy();
|
||||
m_impl->m_task->destroy();
|
||||
delete m_impl;
|
||||
m_impl = 0;
|
||||
return false;
|
||||
|
@ -199,9 +199,9 @@ namespace Lux
|
|||
{
|
||||
if(m_impl)
|
||||
{
|
||||
m_impl->task->stop();
|
||||
m_impl->task->m_mutex.destroy();
|
||||
m_impl->task->destroy();
|
||||
m_impl->m_task->stop();
|
||||
m_impl->m_task->m_mutex.destroy();
|
||||
m_impl->m_task->destroy();
|
||||
delete m_impl;
|
||||
m_impl = 0;
|
||||
}
|
||||
|
@ -211,14 +211,14 @@ namespace Lux
|
|||
IFileSystem::Handle TCPFileSystem::openFile(const char* path, ReadCallback callback, void* user_data)
|
||||
{
|
||||
TCPFileSystemImpl::FileItem* item = new TCPFileSystemImpl::FileItem();
|
||||
item->callback = callback;
|
||||
item->path = path;
|
||||
item->user_data = user_data;
|
||||
item->uid = ++m_impl->last_uid;
|
||||
m_impl->task->m_mutex.lock();
|
||||
m_impl->queue.push_back(item);
|
||||
m_impl->task->m_mutex.unlock();
|
||||
return item->uid;
|
||||
item->m_callback = callback;
|
||||
item->m_path = path;
|
||||
item->m_user_data = user_data;
|
||||
item->m_uid = ++m_impl->m_last_uid;
|
||||
m_impl->m_task->m_mutex.lock();
|
||||
m_impl->m_queue.push_back(item);
|
||||
m_impl->m_task->m_mutex.unlock();
|
||||
return item->m_uid;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,16 +22,15 @@ namespace Lux
|
|||
void compile(const char* path);
|
||||
void getScriptDefaultPath(Entity e, char* path, int max_path, const char* ext);
|
||||
|
||||
vector<int> scripts;
|
||||
vector<BaseScript*> script_objs;
|
||||
vector<HMODULE> libs;
|
||||
vector<string> paths;
|
||||
Universe* universe;
|
||||
bool is_running;
|
||||
Renderer* renderer;
|
||||
Navigation* navigation;
|
||||
InputSystem* input_system;
|
||||
ScriptSystem* owner;
|
||||
vector<int> m_scripts;
|
||||
vector<BaseScript*> m_script_objs;
|
||||
vector<HMODULE> m_libs;
|
||||
vector<string> m_paths;
|
||||
Universe* m_universe;
|
||||
bool m_is_running;
|
||||
Renderer* m_renderer;
|
||||
InputSystem* m_input_system;
|
||||
ScriptSystem* m_owner;
|
||||
};
|
||||
|
||||
|
||||
|
@ -42,8 +41,8 @@ namespace Lux
|
|||
ScriptSystem::ScriptSystem()
|
||||
{
|
||||
m_impl = new ScriptSystemImpl;
|
||||
m_impl->owner = this;
|
||||
m_impl->is_running = false;
|
||||
m_impl->m_owner = this;
|
||||
m_impl->m_is_running = false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,51 +52,39 @@ namespace Lux
|
|||
}
|
||||
|
||||
|
||||
Navigation* ScriptSystem::getNavigation() const
|
||||
void ScriptSystem::setInputSystem(InputSystem* m_input_system)
|
||||
{
|
||||
return m_impl->navigation;
|
||||
}
|
||||
|
||||
|
||||
void ScriptSystem::setNavigation(Navigation* navigation)
|
||||
{
|
||||
m_impl->navigation = navigation;
|
||||
}
|
||||
|
||||
|
||||
void ScriptSystem::setInputSystem(InputSystem* input_system)
|
||||
{
|
||||
m_impl->input_system = input_system;
|
||||
m_impl->m_input_system = m_input_system;
|
||||
}
|
||||
|
||||
|
||||
InputSystem* ScriptSystem::getInputSystem() const
|
||||
{
|
||||
return m_impl->input_system;
|
||||
return m_impl->m_input_system;
|
||||
}
|
||||
|
||||
|
||||
Renderer* ScriptSystem::getRenderer() const
|
||||
{
|
||||
return m_impl->renderer;
|
||||
return m_impl->m_renderer;
|
||||
}
|
||||
|
||||
|
||||
void ScriptSystem::setRenderer(Renderer* renderer)
|
||||
{
|
||||
m_impl->renderer = renderer;
|
||||
m_impl->m_renderer = renderer;
|
||||
}
|
||||
|
||||
|
||||
Universe* ScriptSystem::getUniverse() const
|
||||
{
|
||||
return m_impl->universe;
|
||||
return m_impl->m_universe;
|
||||
}
|
||||
|
||||
|
||||
void ScriptSystem::setUniverse(Universe* universe)
|
||||
{
|
||||
m_impl->universe = universe;
|
||||
m_impl->m_universe = universe;
|
||||
}
|
||||
|
||||
|
||||
|
@ -105,38 +92,38 @@ namespace Lux
|
|||
{
|
||||
m_impl->compile();
|
||||
char path[MAX_PATH];
|
||||
for(int i = 0; i < m_impl->scripts.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_scripts.size(); ++i)
|
||||
{
|
||||
Entity e(m_impl->universe, m_impl->scripts[i]);
|
||||
m_impl->getDll(m_impl->paths[i].c_str(), path, MAX_PATH);
|
||||
Entity e(m_impl->m_universe, m_impl->m_scripts[i]);
|
||||
m_impl->getDll(m_impl->m_paths[i].c_str(), path, MAX_PATH);
|
||||
HMODULE h = LoadLibrary(path);
|
||||
m_impl->libs.push_back(h);
|
||||
m_impl->m_libs.push_back(h);
|
||||
if(h)
|
||||
{
|
||||
CreateScriptFunction f = (CreateScriptFunction)GetProcAddress(h, TEXT("createScript"));
|
||||
BaseScript* script = f();
|
||||
m_impl->script_objs.push_back(script);
|
||||
m_impl->m_script_objs.push_back(script);
|
||||
script->create(*this, e);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_impl->script_objs.push_back(0);
|
||||
m_impl->m_script_objs.push_back(0);
|
||||
}
|
||||
}
|
||||
m_impl->is_running = true;
|
||||
m_impl->m_is_running = true;
|
||||
}
|
||||
|
||||
void ScriptSystem::deserialize(ISerializer& serializer)
|
||||
{
|
||||
int count;
|
||||
serializer.deserialize("count", count);
|
||||
m_impl->scripts.resize(count);
|
||||
m_impl->paths.resize(count);
|
||||
m_impl->m_scripts.resize(count);
|
||||
m_impl->m_paths.resize(count);
|
||||
serializer.deserializeArrayBegin("scripts");
|
||||
for(int i = 0; i < m_impl->scripts.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_scripts.size(); ++i)
|
||||
{
|
||||
serializer.deserializeArrayItem(m_impl->scripts[i]);
|
||||
serializer.deserializeArrayItem(m_impl->paths[i]);
|
||||
serializer.deserializeArrayItem(m_impl->m_scripts[i]);
|
||||
serializer.deserializeArrayItem(m_impl->m_paths[i]);
|
||||
}
|
||||
serializer.deserializeArrayEnd();
|
||||
m_impl->postDeserialize();
|
||||
|
@ -144,34 +131,34 @@ namespace Lux
|
|||
|
||||
void ScriptSystem::serialize(ISerializer& serializer)
|
||||
{
|
||||
serializer.serialize("count", m_impl->scripts.size());
|
||||
serializer.serialize("count", m_impl->m_scripts.size());
|
||||
serializer.beginArray("scripts");
|
||||
for(int i = 0; i < m_impl->scripts.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_scripts.size(); ++i)
|
||||
{
|
||||
serializer.serializeArrayItem(m_impl->scripts[i]);
|
||||
serializer.serializeArrayItem(m_impl->paths[i]);
|
||||
serializer.serializeArrayItem(m_impl->m_scripts[i]);
|
||||
serializer.serializeArrayItem(m_impl->m_paths[i]);
|
||||
}
|
||||
serializer.endArray();
|
||||
}
|
||||
|
||||
void ScriptSystem::stop()
|
||||
{
|
||||
m_impl->is_running = false;
|
||||
for(int i = 0; i < m_impl->scripts.size(); ++i)
|
||||
m_impl->m_is_running = false;
|
||||
for(int i = 0; i < m_impl->m_scripts.size(); ++i)
|
||||
{
|
||||
DestroyScriptFunction f = (DestroyScriptFunction)GetProcAddress(m_impl->libs[i], "destroyScript");
|
||||
f(m_impl->script_objs[i]);
|
||||
FreeLibrary(m_impl->libs[i]);
|
||||
DestroyScriptFunction f = (DestroyScriptFunction)GetProcAddress(m_impl->m_libs[i], "destroyScript");
|
||||
f(m_impl->m_script_objs[i]);
|
||||
FreeLibrary(m_impl->m_libs[i]);
|
||||
}
|
||||
m_impl->libs.clear();
|
||||
m_impl->script_objs.clear();
|
||||
m_impl->m_libs.clear();
|
||||
m_impl->m_script_objs.clear();
|
||||
}
|
||||
|
||||
void ScriptSystem::update(float dt)
|
||||
{
|
||||
for(int i = 0; i < m_impl->scripts.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_scripts.size(); ++i)
|
||||
{
|
||||
m_impl->script_objs[i]->update(dt);
|
||||
m_impl->m_script_objs[i]->update(dt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,20 +185,20 @@ namespace Lux
|
|||
|
||||
void ScriptSystemImpl::compile()
|
||||
{
|
||||
for(int i = 0; i < scripts.size(); ++i)
|
||||
for(int i = 0; i < m_scripts.size(); ++i)
|
||||
{
|
||||
compile(paths[i].c_str());
|
||||
compile(m_paths[i].c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptSystem::getScriptPath(Component cmp, string& str)
|
||||
{
|
||||
str = m_impl->paths[cmp.index];
|
||||
str = m_impl->m_paths[cmp.index];
|
||||
}
|
||||
|
||||
void ScriptSystem::setScriptPath(Component cmp, const string& str)
|
||||
{
|
||||
m_impl->paths[cmp.index] = str;
|
||||
m_impl->m_paths[cmp.index] = str;
|
||||
m_impl->compile(str.c_str());
|
||||
}
|
||||
|
||||
|
@ -232,45 +219,45 @@ namespace Lux
|
|||
|
||||
void ScriptSystemImpl::postDeserialize()
|
||||
{
|
||||
for(int i = 0; i < scripts.size(); ++i)
|
||||
for(int i = 0; i < m_scripts.size(); ++i)
|
||||
{
|
||||
Entity e(universe, scripts[i]);
|
||||
universe->getEventManager()->emitEvent(ComponentEvent(Component(e, script_type, owner, i)));
|
||||
Entity e(m_universe, m_scripts[i]);
|
||||
m_universe->getEventManager()->emitEvent(ComponentEvent(Component(e, script_type, m_owner, i)));
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptSystem::reloadScript(const char* path)
|
||||
{
|
||||
if(m_impl->script_objs.empty())
|
||||
if(m_impl->m_script_objs.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
for(int i = 0; i < m_impl->paths.size(); ++i)
|
||||
for(int i = 0; i < m_impl->m_paths.size(); ++i)
|
||||
{
|
||||
if(m_impl->paths[i] == path)
|
||||
if(m_impl->m_paths[i] == path)
|
||||
{
|
||||
// serialize
|
||||
SaveScriptVisitor visitor;
|
||||
visitor.startSaving();
|
||||
m_impl->script_objs[i]->visit(visitor);
|
||||
m_impl->m_script_objs[i]->visit(visitor);
|
||||
|
||||
// destroy
|
||||
DestroyScriptFunction f = (DestroyScriptFunction)GetProcAddress(m_impl->libs[i], "destroyScript");
|
||||
f(m_impl->script_objs[i]);
|
||||
FreeLibrary(m_impl->libs[i]);
|
||||
DestroyScriptFunction f = (DestroyScriptFunction)GetProcAddress(m_impl->m_libs[i], "destroyScript");
|
||||
f(m_impl->m_script_objs[i]);
|
||||
FreeLibrary(m_impl->m_libs[i]);
|
||||
|
||||
//compile
|
||||
m_impl->compile(m_impl->paths[i].c_str());
|
||||
m_impl->compile(m_impl->m_paths[i].c_str());
|
||||
|
||||
//create
|
||||
char tmp[MAX_PATH];
|
||||
Entity e(m_impl->universe, m_impl->scripts[i]);
|
||||
m_impl->getDll(m_impl->paths[i].c_str(), tmp, MAX_PATH);
|
||||
m_impl->libs[i] = LoadLibrary(tmp);
|
||||
CreateScriptFunction f2 = (CreateScriptFunction)GetProcAddress(m_impl->libs[i], TEXT("createScript"));
|
||||
Entity e(m_impl->m_universe, m_impl->m_scripts[i]);
|
||||
m_impl->getDll(m_impl->m_paths[i].c_str(), tmp, MAX_PATH);
|
||||
m_impl->m_libs[i] = LoadLibrary(tmp);
|
||||
CreateScriptFunction f2 = (CreateScriptFunction)GetProcAddress(m_impl->m_libs[i], TEXT("createScript"));
|
||||
BaseScript* script = f2();
|
||||
script->create(*this, e);
|
||||
m_impl->script_objs[i] = script;
|
||||
m_impl->m_script_objs[i] = script;
|
||||
|
||||
// deserialize
|
||||
visitor.startLoading();
|
||||
|
@ -291,10 +278,10 @@ namespace Lux
|
|||
fopen_s(&fp, path, "w");
|
||||
}
|
||||
fclose(fp);
|
||||
m_impl->scripts.push_back(entity.index);
|
||||
m_impl->paths.push_back(path);
|
||||
Component cmp(entity, script_type, this, m_impl->scripts.size() - 1);
|
||||
m_impl->universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
m_impl->m_scripts.push_back(entity.index);
|
||||
m_impl->m_paths.push_back(path);
|
||||
Component cmp(entity, script_type, this, m_impl->m_scripts.size() - 1);
|
||||
m_impl->m_universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
return cmp;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,8 +30,6 @@ class LUX_ENGINE_API ScriptSystem
|
|||
void reloadScript(const char* path);
|
||||
Renderer* getRenderer() const;
|
||||
void setRenderer(Renderer* renderer);
|
||||
Navigation* getNavigation() const;
|
||||
void setNavigation(Navigation* navigation);
|
||||
void setInputSystem(InputSystem* input_system);
|
||||
InputSystem* getInputSystem() const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue