Camera & vector.cpp : Fixed shifted_perspective crash with almost zero FOV.undefined
@@ -12,6 +12,7 @@ liblolcore_a_SOURCES = \ | |||||
tileset.cpp tileset.h forge.cpp forge.h video.cpp video.h \ | tileset.cpp tileset.h forge.cpp forge.h video.cpp video.h \ | ||||
world.cpp world.h sample.cpp sample.h sampler.cpp sampler.h \ | world.cpp world.h sample.cpp sample.h sampler.cpp sampler.h \ | ||||
profiler.cpp profiler.h text.cpp text.h emitter.cpp emitter.h numeric.h utils.h \ | profiler.cpp profiler.h text.cpp text.h emitter.cpp emitter.h numeric.h utils.h \ | ||||
messageservice.cpp messageservice.h \ | |||||
worldentity.cpp worldentity.h gradient.cpp gradient.h gradient.lolfx \ | worldentity.cpp worldentity.h gradient.cpp gradient.h gradient.lolfx \ | ||||
platform.cpp platform.h sprite.cpp sprite.h camera.cpp camera.h \ | platform.cpp platform.h sprite.cpp sprite.h camera.cpp camera.h \ | ||||
light.cpp light.h \ | light.cpp light.h \ | ||||
@@ -107,7 +107,7 @@ void Camera::SetProjection(float fov, float near, float far, float screen_size, | |||||
m_screen_size = screen_size; | m_screen_size = screen_size; | ||||
m_screen_ratio = screen_ratio; | m_screen_ratio = screen_ratio; | ||||
mat4 screen_scale = mat4::scale(vec3(m_screen_scale.xy, 1.f)); | mat4 screen_scale = mat4::scale(vec3(m_screen_scale.xy, 1.f)); | ||||
if (m_fov > .0f) | |||||
if (m_fov > .001f) | |||||
{ | { | ||||
if (m_is_shifted) | if (m_is_shifted) | ||||
SetProjection(screen_scale * mat4::shifted_perspective(m_fov, screen_size, screen_ratio, m_near, m_far)); | SetProjection(screen_scale * mat4::shifted_perspective(m_fov, screen_size, screen_ratio, m_near, m_far)); | ||||
@@ -126,6 +126,7 @@ static inline int isnan(float f) | |||||
#include "audio.h" | #include "audio.h" | ||||
#include "scene.h" | #include "scene.h" | ||||
#include "profiler.h" | #include "profiler.h" | ||||
#include "messageservice.h" | |||||
// Input | // Input | ||||
#include "input/input.h" | #include "input/input.h" | ||||
@@ -155,6 +155,7 @@ | |||||
<ClCompile Include="math\trig.cpp" /> | <ClCompile Include="math\trig.cpp" /> | ||||
<ClCompile Include="math\vector.cpp" /> | <ClCompile Include="math\vector.cpp" /> | ||||
<ClCompile Include="mesh\mesh.cpp" /> | <ClCompile Include="mesh\mesh.cpp" /> | ||||
<ClCompile Include="messageservice.cpp" /> | |||||
<ClCompile Include="platform.cpp" /> | <ClCompile Include="platform.cpp" /> | ||||
<ClCompile Include="platform\d3d9\d3d9input.cpp" /> | <ClCompile Include="platform\d3d9\d3d9input.cpp" /> | ||||
<ClCompile Include="platform\ps3\ps3app.cpp" /> | <ClCompile Include="platform\ps3\ps3app.cpp" /> | ||||
@@ -253,6 +254,7 @@ | |||||
<ClInclude Include="lol\unit.h" /> | <ClInclude Include="lol\unit.h" /> | ||||
<ClInclude Include="mesh\mesh.h" /> | <ClInclude Include="mesh\mesh.h" /> | ||||
<ClInclude Include="map.h" /> | <ClInclude Include="map.h" /> | ||||
<ClInclude Include="messageservice.h" /> | |||||
<ClInclude Include="numeric.h" /> | <ClInclude Include="numeric.h" /> | ||||
<ClInclude Include="platform.h" /> | <ClInclude Include="platform.h" /> | ||||
<ClInclude Include="platform\d3d9\d3d9input.h" /> | <ClInclude Include="platform\d3d9\d3d9input.h" /> | ||||
@@ -298,6 +300,7 @@ | |||||
<None Include="easymesh\easymesh-scanner.l" /> | <None Include="easymesh\easymesh-scanner.l" /> | ||||
<None Include="gpu\lolfx-parser.y" /> | <None Include="gpu\lolfx-parser.y" /> | ||||
<None Include="gpu\lolfx-scanner.l" /> | <None Include="gpu\lolfx-scanner.l" /> | ||||
<None Include="Makefile.am" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="bullet\lolbullet.vcxproj"> | <ProjectReference Include="bullet\lolbullet.vcxproj"> | ||||
@@ -309,6 +309,9 @@ | |||||
<ClCompile Include="input\controller.cpp"> | <ClCompile Include="input\controller.cpp"> | ||||
<Filter>input</Filter> | <Filter>input</Filter> | ||||
</ClCompile> | </ClCompile> | ||||
<ClCompile Include="MessageService.cpp"> | |||||
<Filter>...</Filter> | |||||
</ClCompile> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ClInclude Include="debug\fps.h"> | <ClInclude Include="debug\fps.h"> | ||||
@@ -611,6 +614,9 @@ | |||||
<ClInclude Include="utils.h"> | <ClInclude Include="utils.h"> | ||||
<Filter>...</Filter> | <Filter>...</Filter> | ||||
</ClInclude> | </ClInclude> | ||||
<ClInclude Include="messageservice.h"> | |||||
<Filter>...</Filter> | |||||
</ClInclude> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<LolFxCompile Include="gpu\emptymaterial.lolfx"> | <LolFxCompile Include="gpu\emptymaterial.lolfx"> | ||||
@@ -663,5 +669,6 @@ | |||||
<None Include="gpu\lolfx-parser.y"> | <None Include="gpu\lolfx-parser.y"> | ||||
<Filter>gpu</Filter> | <Filter>gpu</Filter> | ||||
</None> | </None> | ||||
<None Include="Makefile.am" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
</Project> | </Project> |
@@ -785,7 +785,9 @@ template<> mat4 mat4::shifted_perspective(float fov_y, float screen_size, | |||||
float screen_ratio_yx, float near, float far) | float screen_ratio_yx, float near, float far) | ||||
{ | { | ||||
float new_fov_y = fov_y * (F_PI / 180.0f); | float new_fov_y = fov_y * (F_PI / 180.0f); | ||||
float dist_scr = (screen_size * screen_ratio_yx * .5f) / tanf(new_fov_y * .5f); | |||||
float tan_y = tanf(new_fov_y * .5f); | |||||
ASSERT(tan_y > 0.000001f); | |||||
float dist_scr = (screen_size * screen_ratio_yx * .5f) / tan_y; | |||||
return mat4::perspective(fov_y, screen_size, screen_size * screen_ratio_yx, | return mat4::perspective(fov_y, screen_size, screen_size * screen_ratio_yx, | ||||
max(.001f, dist_scr + near), | max(.001f, dist_scr + near), | ||||
@@ -0,0 +1,143 @@ | |||||
// | |||||
// Lol Engine | |||||
// | |||||
// Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||||
// 2013 Sam Hocevar <sam@hocevar.net> | |||||
// This program is free software; you can redistribute it and/or | |||||
// modify it under the terms of the Do What The Fuck You Want To | |||||
// Public License, Version 2, as published by Sam Hocevar. See | |||||
// http://www.wtfpl.net/ for more details. | |||||
// | |||||
#if defined HAVE_CONFIG_H | |||||
# include "config.h" | |||||
#endif | |||||
#include <cstring> | |||||
#include <cstdlib> | |||||
#include <time.h> | |||||
#include "core.h" | |||||
namespace lol | |||||
{ | |||||
/* | |||||
* The global g_renderer object, initialised by Video::Init | |||||
*/ | |||||
MessageService *g_messageservice = nullptr; | |||||
//----------------------------------------------------------------------------- | |||||
// Ctor/Dtor | |||||
//---- | |||||
MessageService::MessageService() | |||||
{ | |||||
} | |||||
MessageService::~MessageService() | |||||
{ | |||||
m_bucket.Empty(); | |||||
} | |||||
//Setup/Destroy | |||||
void MessageService::Setup(int bucket_size) | |||||
{ | |||||
g_messageservice = new MessageService(); | |||||
g_messageservice->m_bucket.Resize(bucket_size); | |||||
} | |||||
void MessageService::Destroy() | |||||
{ | |||||
delete g_messageservice; | |||||
g_messageservice = nullptr; | |||||
} | |||||
//----------------------------------------------------------------------------- | |||||
bool MessageService::Send(int id, const String& message) | |||||
{ | |||||
if (g_messageservice) | |||||
{ | |||||
ASSERT(0 <= id && id < g_messageservice->m_bucket.Count()); | |||||
return g_messageservice->Send(id, message.C()); | |||||
} | |||||
return false; | |||||
} | |||||
bool MessageService::Send(int id, const char* message) | |||||
{ | |||||
if (g_messageservice) | |||||
{ | |||||
ASSERT(0 <= id && id < g_messageservice->m_bucket.Count()); | |||||
MessageService& g = *g_messageservice; | |||||
Array<MessageList>& bucket = g.m_bucket[id]; | |||||
bucket << MessageList(time(nullptr), String(message)); | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
//---- | |||||
bool MessageService::FetchFirst(int id, String& message) | |||||
{ | |||||
if (g_messageservice) | |||||
{ | |||||
ASSERT(0 <= id && id < g_messageservice->m_bucket.Count()); | |||||
time_t timestamp; | |||||
return g_messageservice->FetchFirst(id, message, timestamp); | |||||
} | |||||
return false; | |||||
} | |||||
bool MessageService::FetchFirst(int id, String& message, time_t& timestamp) | |||||
{ | |||||
if (g_messageservice) | |||||
{ | |||||
ASSERT(0 <= id && id < g_messageservice->m_bucket.Count()); | |||||
MessageService& g = *g_messageservice; | |||||
Array<MessageList>& bucket = g.m_bucket[id]; | |||||
if (bucket.Count()) | |||||
{ | |||||
message = bucket[0].m_message; | |||||
timestamp = bucket[0].m_timestamp; | |||||
bucket.Remove(0); | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
//---- | |||||
bool MessageService::FetchAll(int id, String& message) | |||||
{ | |||||
if (g_messageservice) | |||||
{ | |||||
ASSERT(0 <= id && id < g_messageservice->m_bucket.Count()); | |||||
time_t timestamp; | |||||
return g_messageservice->FetchAll(id, message, timestamp); | |||||
} | |||||
return false; | |||||
} | |||||
bool MessageService::FetchAll(int id, String& message, time_t& first_timestamp) | |||||
{ | |||||
if (g_messageservice) | |||||
{ | |||||
ASSERT(0 <= id && id < g_messageservice->m_bucket.Count()); | |||||
MessageService& g = *g_messageservice; | |||||
Array<MessageList>& bucket = g.m_bucket[id]; | |||||
message = String(""); | |||||
if (bucket.Count()) | |||||
{ | |||||
first_timestamp = bucket[0].m_timestamp; | |||||
for (int i = 0; i < bucket.Count(); ++i) | |||||
message += bucket[i].m_message; | |||||
bucket.Empty(); | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
} /* namespace lol */ |
@@ -0,0 +1,67 @@ | |||||
// | |||||
// Lol Engine | |||||
// | |||||
// Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||||
// (c) 2013 Sam Hocevar <sam@hocevar.net> | |||||
// This program is free software; you can redistribute it and/or | |||||
// modify it under the terms of the Do What The Fuck You Want To | |||||
// Public License, Version 2, as published by Sam Hocevar. See | |||||
// http://www.wtfpl.net/ for more details. | |||||
// | |||||
// | |||||
// The Message Service class | |||||
// ---------------- | |||||
// | |||||
#if !defined __MESSAGESERVICE_H__ | |||||
#define __MESSAGESERVICE_H__ | |||||
namespace lol | |||||
{ | |||||
struct MessageList | |||||
{ | |||||
MessageList(time_t timestamp, String& message) | |||||
{ | |||||
m_timestamp = timestamp; | |||||
m_message = message; | |||||
} | |||||
time_t m_timestamp; | |||||
String m_message; | |||||
}; | |||||
/* | |||||
A template class perhaps ? | |||||
*/ | |||||
class MessageService | |||||
{ | |||||
public: | |||||
//CTor/DTor | |||||
MessageService(); | |||||
~MessageService(); | |||||
static char const *GetName() { return "<messageservice>"; } | |||||
//Setup/Destroy | |||||
static void Setup(int bucket_size); | |||||
static void Destroy(); | |||||
//Common interactions | |||||
static bool Send(int id, const String& message); | |||||
static bool Send(int id, const char* message); | |||||
static bool FetchFirst(int id, String& message); | |||||
static bool FetchFirst(int id, String& message, time_t ×tamp); | |||||
static bool FetchAll(int id, String& message); | |||||
static bool FetchAll(int id, String& message, time_t &first_timestamp); | |||||
private: | |||||
Array<Array<MessageList> > m_bucket; | |||||
}; | |||||
extern MessageService *g_messageservice; | |||||
} /* namespace lol */ | |||||
#endif /* __MESSAGESERVICE_H__ */ |