diff --git a/src/core/path.h b/src/core/path.h index 5083f999a..ff4019678 100644 --- a/src/core/path.h +++ b/src/core/path.h @@ -25,6 +25,7 @@ namespace Lux operator string() const { return string(m_path); } const char* c_str() const { return m_path; } + int length() const { return strlen(m_path); } bool operator == (const Path& rhs) const { return m_id == rhs.m_id; } bool operator == (const char* rhs) const { Path path(rhs); return m_id == path.m_id; } diff --git a/src/core/path_utils.h b/src/core/path_utils.h index b3865fdaa..537e0f0e6 100644 --- a/src/core/path_utils.h +++ b/src/core/path_utils.h @@ -9,7 +9,7 @@ namespace Lux uint32_t i = 0; while (*path != '\0' && i < max_size) { - *out = *path == '/' ? '\\' : *path; + *out = *path == '\\' ? '/' : *path; *out = *path >= 'A' && *path <= 'Z' ? *path - 'A' + 'a' : *out; path++; diff --git a/src/core/pod_array.h b/src/core/pod_array.h index 355953464..5af1ffb0c 100644 --- a/src/core/pod_array.h +++ b/src/core/pod_array.h @@ -146,7 +146,7 @@ class PODArray } } - const T& operator[] (int index) const { ASSERT(index < m_size); return m_data[index]; } + const T& operator[] (int index) const { ASSERT(index >= 0 && index < m_size); return m_data[index]; } T& operator[](int index) { ASSERT(index >= 0 && index < m_size); return m_data[index]; } int size() const { return m_size; } int capacity() const { return m_capacity; } diff --git a/src/core/tcp_file_server.cpp b/src/core/tcp_file_server.cpp index 96bac65c7..99b37b453 100644 --- a/src/core/tcp_file_server.cpp +++ b/src/core/tcp_file_server.cpp @@ -3,6 +3,7 @@ #include "core/array.h" #include "core/free_list.h" #include "core/os_file.h" +#include "core/path.h" #include "core/static_array.h" #include "core/string.h" #include "core/tcp_file_device.h" @@ -50,7 +51,7 @@ namespace Lux string path; if (strncmp(m_buffer.data(), m_base_path.c_str(), m_base_path.length()) != 0) { - path = m_base_path; + path = m_base_path.c_str(); path += m_buffer.data(); } else @@ -168,11 +169,12 @@ namespace Lux void stop() {} // TODO: implement stop void setBasePath(const char* base_path) { - m_base_path = base_path; - if (m_base_path[m_base_path.length() - 1] != '/') + string base_path_str(base_path); + if (base_path_str[base_path_str.length() - 1] != '/') { - m_base_path += "/"; + base_path_str += "/"; } + m_base_path = base_path_str; } private: @@ -180,7 +182,7 @@ namespace Lux StaticArray m_buffer; StaticArray m_files; FreeList m_ids; - string m_base_path; + Path m_base_path; }; struct TCPFileServerImpl diff --git a/src/editor/editor_icon.cpp b/src/editor/editor_icon.cpp index d7a9a5af7..8a2e93f7a 100644 --- a/src/editor/editor_icon.cpp +++ b/src/editor/editor_icon.cpp @@ -57,7 +57,9 @@ void EditorIcon::render(Renderer* renderer, IRenderDevice& render_device) Component camera = render_device.getPipeline().getCamera(0); Lux::Matrix mtx = camera.entity.getMatrix(); - float scale = /*renderer->getHalfFovTan()*/ 0.0333f * (m_entity.getPosition() - mtx.getTranslation()).length() * 2; + float fov; + renderer->getCameraFov(camera, fov); + float scale = tan(fov * 0.5f) * (m_entity.getPosition() - mtx.getTranslation()).length() * 2; mtx.setTranslation(m_entity.getPosition()); Matrix scale_mtx = Matrix::IDENTITY; @@ -67,10 +69,10 @@ void EditorIcon::render(Renderer* renderer, IRenderDevice& render_device) glPushMatrix(); glMultMatrixf(&mtx.m11); glBegin(GL_QUADS); - glVertex3f(0, 0, 0); - glVertex3f(0, 1, 0); - glVertex3f(1, 1, 0); - glVertex3f(1, 0, 0); + glVertex3f(-0.015f, -0.015f, 0); + glVertex3f(-0.015f, 0.015f, 0); + glVertex3f(0.015f, 0.015f, 0); + glVertex3f(0.015f, -0.015f, 0); glEnd(); glPopMatrix(); } diff --git a/src/editor/editor_server.cpp b/src/editor/editor_server.cpp index d56eea6e1..86e018d80 100644 --- a/src/editor/editor_server.cpp +++ b/src/editor/editor_server.cpp @@ -867,7 +867,7 @@ void EditorServerImpl::renderScene(IRenderDevice& render_device) m_engine.getRenderer().render(render_device); for(int i = 0, c = m_editor_icons.size(); i < c; ++i) { - // m_editor_icons[i]->render(&m_engine.getRenderer(), render_device); + m_editor_icons[i]->render(&m_engine.getRenderer(), render_device); } @@ -1160,7 +1160,7 @@ void EditorServerImpl::createUniverse(bool create_scene, const char* base_path) m_camera.setRotation(Quat(Vec3(0, 1, 0), -Math::PI)); Component cmp = m_engine.getRenderer().createComponent(camera_type, m_camera); - Entity light = m_engine.getUniverse()->createEntity(); + /*Entity light = m_engine.getUniverse()->createEntity(); Matrix mtx = Matrix::IDENTITY; mtx.setXVector(Vec3(1, 0, 0)); mtx.setYVector(Vec3(0, -1, 1).normalized()); diff --git a/src/editor_native/property_frame/renderable_ui.cpp b/src/editor_native/property_frame/renderable_ui.cpp index 3079f2659..97ef09833 100644 --- a/src/editor_native/property_frame/renderable_ui.cpp +++ b/src/editor_native/property_frame/renderable_ui.cpp @@ -2,6 +2,7 @@ #include #include #include "core/crc32.h" +#include "core/path_utils.h" #include "editor/editor_client.h" #include "editor/server_message_types.h" #include "editor_native/main_frame.h" @@ -69,16 +70,7 @@ void RenderableUI::browseSource(Lux::UI::Block& block, void*) strcpy_s(buf, buf + s.length()); } } - /// TODO make this function - char* c = buf; - while(*c) - { - if(*c == '\\') - { - *c = '/'; - } - ++c; - } + Lux::PathUtils::normalize(buf, buf, MAX_PATH); m_source_box->getChild(0)->setBlockText(buf); m_source_box->getChild(0)->emitEvent("text_accepted"); } diff --git a/src/graphics/pipeline.cpp b/src/graphics/pipeline.cpp index efd2a2f6c..1f1ddf8c8 100644 --- a/src/graphics/pipeline.cpp +++ b/src/graphics/pipeline.cpp @@ -318,10 +318,14 @@ struct PipelineImpl : public Pipeline void renderShadowmap() { + Component light_cmp = m_renderer.getLight(0); + if (!light_cmp.isValid()) + { + return; + } glEnable(GL_CULL_FACE); m_shadowmap_framebuffer->bind(); glClear(GL_DEPTH_BUFFER_BIT); - Component light_cmp = m_renderer.getLight(0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); @@ -503,8 +507,9 @@ void UnbindFramebufferCommand::execute(PipelineImpl& pipeline) void DrawFullscreenQuadCommand::deserialize(PipelineImpl& pipeline, ISerializer& serializer) { - char material[100]; - serializer.deserializeArrayItem(material, 100); + const int MATERIAL_NAME_MAX_LENGTH = 100; + char material[MATERIAL_NAME_MAX_LENGTH]; + serializer.deserializeArrayItem(material, MATERIAL_NAME_MAX_LENGTH); char material_path[MAX_PATH]; strcpy(material_path, "materials/"); strcat(material_path, material); diff --git a/src/graphics/renderer.cpp b/src/graphics/renderer.cpp index 5eeca3d18..71e2d5f82 100644 --- a/src/graphics/renderer.cpp +++ b/src/graphics/renderer.cpp @@ -203,6 +203,12 @@ struct RendererImpl : public Renderer } + virtual void getCameraFov(Component cmp, float& fov) LUX_OVERRIDE + { + fov = m_cameras[cmp.index]->m_fov; + } + + virtual void getRenderablePath(Component cmp, string& path) LUX_OVERRIDE { if(m_renderables[cmp.index].m_model) @@ -266,6 +272,10 @@ struct RendererImpl : public Renderer virtual Component getLight(int index) LUX_OVERRIDE { + if (index >= m_lights.size()) + { + return Component::INVALID; + } return Component(m_lights[index].m_entity, crc32("light"), this, index); }; diff --git a/src/graphics/renderer.h b/src/graphics/renderer.h index 0a459deab..2d3e4a206 100644 --- a/src/graphics/renderer.h +++ b/src/graphics/renderer.h @@ -46,6 +46,7 @@ class LUX_ENGINE_API Renderer : public IPlugin virtual void setRenderablePath(Component cmp, const string& path) = 0; virtual void getRenderablePath(Component cmp, string& path) = 0; virtual void getRenderableInfos(PODArray& infos) = 0; + virtual void getCameraFov(Component cmp, float& fov) = 0; virtual Pipeline* loadPipeline(const char* path) = 0; virtual Engine& getEngine() = 0;