summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/app/app.cpp34
-rw-r--r--src/common/event.cpp8
-rw-r--r--src/graphics/engine/engine.cpp5
-rw-r--r--src/graphics/engine/terrain.cpp27
-rw-r--r--src/object/object.cpp60
-rw-r--r--src/object/robotmain.cpp43
-rw-r--r--src/ui/color.cpp4
-rw-r--r--src/ui/maindialog.cpp2
8 files changed, 132 insertions, 51 deletions
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 1d67745..00977d1 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -65,6 +65,8 @@ struct ApplicationPrivate
SDL_Surface *surface;
//! Currently handled event
SDL_Event currentEvent;
+ //! Mouse motion event to be handled
+ SDL_Event lastMouseMotionEvent;
//! Joystick
SDL_Joystick *joystick;
//! Id of joystick timer
@@ -73,6 +75,7 @@ struct ApplicationPrivate
ApplicationPrivate()
{
memset(&currentEvent, 0, sizeof(SDL_Event));
+ memset(&lastMouseMotionEvent, 0, sizeof(SDL_Event));
surface = nullptr;
joystick = nullptr;
joystickTimer = 0;
@@ -721,6 +724,8 @@ int CApplication::Run()
if (m_active)
SDL_PumpEvents();
+ m_private->lastMouseMotionEvent.type = SDL_NOEVENT;
+
bool haveEvent = true;
while (haveEvent)
{
@@ -739,6 +744,13 @@ int CApplication::Run()
{
haveEvent = true;
+ // Skip mouse motion events, for now
+ if (m_private->currentEvent.type == SDL_MOUSEMOTION)
+ {
+ m_private->lastMouseMotionEvent = m_private->currentEvent;
+ continue;
+ }
+
Event event = ProcessSystemEvent();
if (event.type == EVENT_QUIT)
@@ -769,6 +781,28 @@ int CApplication::Run()
}
}
+ // Now, process the last received mouse motion
+ if (m_private->lastMouseMotionEvent.type != SDL_NOEVENT)
+ {
+ m_private->currentEvent = m_private->lastMouseMotionEvent;
+
+ Event event = ProcessSystemEvent();
+
+ if (event.type == EVENT_QUIT)
+ goto end; // exit the loop
+
+ if (event.type != EVENT_NULL)
+ {
+ bool passOn = ProcessEvent(event);
+
+ if (m_engine != nullptr && passOn)
+ passOn = m_engine->ProcessEvent(event);
+
+ if (passOn)
+ m_eventQueue->AddEvent(event);
+ }
+ }
+
// Enter game update & frame rendering only if active
if (m_active)
{
diff --git a/src/common/event.cpp b/src/common/event.cpp
index 87c8a5c..4e5ec1a 100644
--- a/src/common/event.cpp
+++ b/src/common/event.cpp
@@ -14,10 +14,10 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
-// event.cpp
#include "common/event.h"
#include "common/iman.h"
+#include "common/logger.h"
static EventType g_uniqueEventType = EVENT_USER;
@@ -54,7 +54,11 @@ void CEventQueue::Flush()
Else, adds the event to the queue and returns \c true. */
bool CEventQueue::AddEvent(const Event &event)
{
- if ( m_total >= MAX_EVENT_QUEUE ) return false;
+ if ( m_total >= MAX_EVENT_QUEUE )
+ {
+ GetLogger()->Warn("Event queue flood!\n");
+ return false;
+ }
m_fifo[m_head++] = event;
if ( m_head >= MAX_EVENT_QUEUE ) m_head = 0;
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index beb7508..37f9b00 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -162,7 +162,7 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app)
m_limitLOD[1] = 200.0f;
m_particleDensity = 1.0f;
m_clippingDistance = 1.0f;
- m_lastClippingDistance = m_clippingDistance;
+ m_lastClippingDistance = m_clippingDistance = 1.0f;
m_objectDetail = 1.0f;
m_lastObjectDetail = m_objectDetail;
m_terrainVision = 1000.0f;
@@ -2096,6 +2096,9 @@ void CEngine::SetViewParams(const Math::Vector& eyePt, const Math::Vector& looka
Texture CEngine::CreateTexture(const std::string& texName, const TextureCreateParams& params)
{
+ if (texName.empty())
+ return Texture(); // invalid texture
+
if (m_texBlacklist.find(texName) != m_texBlacklist.end())
return Texture(); // invalid texture
diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp
index 427e7f6..d70ba0c 100644
--- a/src/graphics/engine/terrain.cpp
+++ b/src/graphics/engine/terrain.cpp
@@ -131,14 +131,15 @@ bool CTerrain::InitTextures(const std::string& baseName, int* table, int dx, int
m_texBaseName = baseName;
size_t pos = baseName.find('.');
- if (pos == baseName.npos)
+
+ if (pos == std::string::npos)
{
m_texBaseExt = ".png";
}
else
{
- m_texBaseName = m_texBaseName.substr(0, pos);
m_texBaseExt = m_texBaseName.substr(pos);
+ m_texBaseName = m_texBaseName.substr(0, pos);
}
for (int y = 0; y < m_mosaicCount*m_textureSubdivCount; y++)
@@ -197,8 +198,12 @@ void CTerrain::AddMaterial(int id, const std::string& texName, const Math::Point
bool CTerrain::LoadResources(const std::string& fileName)
{
CImage img;
- if (! img.Load(CApplication::GetInstance().GetDataFilePath(DIR_TEXTURE, fileName)))
+ std::string path = CApplication::GetInstance().GetDataFilePath(DIR_TEXTURE, fileName);
+ if (! img.Load(path))
+ {
+ GetLogger()->Error("Cannot load resource file: '%s'\n", path.c_str());
return false;
+ }
ImageData *data = img.GetData();
@@ -210,7 +215,10 @@ bool CTerrain::LoadResources(const std::string& fileName)
if ( (data->surface->w != size) || (data->surface->h != size) ||
(data->surface->format->BytesPerPixel != 3) )
+ {
+ GetLogger()->Error("Invalid resource file\n");
return false;
+ }
unsigned char* pixels = static_cast<unsigned char*>(data->surface->pixels);
int pitch = data->surface->pitch;
@@ -263,13 +271,17 @@ void CTerrain::FlushRelief()
* The image must be 24 bits/pixel and dx x dy in size
* with dx = dy = (mosaic*brick)+1 */
bool CTerrain::LoadRelief(const std::string &fileName, float scaleRelief,
- bool adjustBorder)
+ bool adjustBorder)
{
m_scaleRelief = scaleRelief;
CImage img;
- if (! img.Load(CApplication::GetInstance().GetDataFilePath(DIR_TEXTURE, fileName)))
+ std::string path = CApplication::GetInstance().GetDataFilePath(DIR_TEXTURE, fileName);
+ if (! img.Load(path))
+ {
+ GetLogger()->Error("Could not load relief file: '%s'!\n", path.c_str());
return false;
+ }
ImageData *data = img.GetData();
@@ -277,7 +289,10 @@ bool CTerrain::LoadRelief(const std::string &fileName, float scaleRelief,
if ( (data->surface->w != size) || (data->surface->h != size) ||
(data->surface->format->BytesPerPixel != 3) )
+ {
+ GetLogger()->Error("Invalid relief file!\n");
return false;
+ }
unsigned char* pixels = static_cast<unsigned char*>(data->surface->pixels);
int pitch = data->surface->pitch;
@@ -655,7 +670,7 @@ void CTerrain::GetTexture(int x, int y, std::string& name, Math::Point &uv)
TerrainMaterial* tm = FindMaterial(m_materialPoints[x+y*m_materialPointCount].id);
if (tm == nullptr)
{
- name = "xxx.png";
+ name = "";
uv = Math::Point(0.0f, 0.0f);
}
else
diff --git a/src/object/object.cpp b/src/object/object.cpp
index 953de94..e93fa1e 100644
--- a/src/object/object.cpp
+++ b/src/object/object.cpp
@@ -7528,49 +7528,73 @@ void CObject::DeleteDeselList(CObject* pObj)
bool CObject::GetTraceDown()
{
- CMotionVehicle* mv;
- if ( m_motion == 0 ) return false;
- mv = dynamic_cast<CMotionVehicle*>(m_motion);
+ if (m_motion == nullptr) return false;
+ CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
+ if (mv == nullptr)
+ {
+ GetLogger()->Warn("GetTraceDown() invalid m_motion class!\n");
+ return false;
+ }
return mv->GetTraceDown();
}
void CObject::SetTraceDown(bool bDown)
{
- CMotionVehicle* mv;
- if ( m_motion == 0 ) return;
- mv = dynamic_cast<CMotionVehicle*>(m_motion);
+ if (m_motion == nullptr) return;
+ CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
+ if (mv == nullptr)
+ {
+ GetLogger()->Warn("SetTraceDown() invalid m_motion class!\n");
+ return;
+ }
mv->SetTraceDown(bDown);
}
int CObject::GetTraceColor()
{
- CMotionVehicle* mv;
- if ( m_motion == 0 ) return 0;
- mv = dynamic_cast<CMotionVehicle*>(m_motion);
+ if (m_motion == nullptr) return 0;
+ CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
+ if (mv == nullptr)
+ {
+ GetLogger()->Warn("GetTraceColor() invalid m_motion class!\n");
+ return 0;
+ }
return mv->GetTraceColor();
}
void CObject::SetTraceColor(int color)
{
- CMotionVehicle* mv;
- if ( m_motion == 0 ) return;
- mv = dynamic_cast<CMotionVehicle*>(m_motion);
+ if (m_motion == nullptr) return;
+ CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
+ if (mv == nullptr)
+ {
+ GetLogger()->Warn("SetTraceColor() invalid m_motion class!\n");
+ return;
+ }
mv->SetTraceColor(color);
}
float CObject::GetTraceWidth()
{
- CMotionVehicle* mv;
- if ( m_motion == 0 ) return 0.0f;
- mv = dynamic_cast<CMotionVehicle*>(m_motion);
+ if (m_motion == nullptr) return 0.0f;
+ CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
+ if (mv == nullptr)
+ {
+ GetLogger()->Warn("GetTraceWidth() invalid m_motion class!\n");
+ return 0.0f;
+ }
return mv->GetTraceWidth();
}
void CObject::SetTraceWidth(float width)
{
- CMotionVehicle* mv;
- if ( m_motion == 0 ) return;
- mv = dynamic_cast<CMotionVehicle*>(m_motion);
+ if (m_motion == nullptr) return;
+ CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
+ if (mv == nullptr)
+ {
+ GetLogger()->Warn("SetTraceWidth() invalid m_motion class!\n");
+ return;
+ }
mv->SetTraceWidth(width);
}
diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp
index 7a963a0..d6f2d2d 100644
--- a/src/object/robotmain.cpp
+++ b/src/object/robotmain.cpp
@@ -664,7 +664,7 @@ CRobotMain::CRobotMain(CInstanceManager* iMan, CApplication* app)
m_showPos = false;
m_selectInsect = false;
m_showSoluce = false;
- m_showAll = false;
+ m_showAll = true; // for development
m_cheatRadar = false;
m_fixScene = false;
m_trainerPilot = false;
@@ -3682,6 +3682,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
char* stack = m_dialog->GetStackRead();
m_dialog->SetUserDir(base, rank);
+ /*
+ * TODO: original code relying on UserDir() was removed.
+ * A new way of providing custom data file paths will need to be devised.
+ */
+
m_fixScene = fixScene;
g_id = 0;
@@ -3791,7 +3796,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (Cmd(line, "Instructions") && !resetObject)
{
OpString(line, "name", name);
- UserDir(m_infoFilename[SATCOM_HUSTON], name, "help");
+ std::string path = m_app->GetDataFilePath(DIR_HELP, name);
+ strcpy(m_infoFilename[SATCOM_HUSTON], path.c_str());
m_immediatSatCom = OpInt(line, "immediat", 0);
}
@@ -3799,24 +3805,28 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (Cmd(line, "Satellite") && !resetObject)
{
OpString(line, "name", name);
- UserDir(m_infoFilename[SATCOM_SAT], name, "help");
+ std::string path = m_app->GetDataFilePath(DIR_HELP, name);
+ strcpy(m_infoFilename[SATCOM_SAT], path.c_str());
}
if (Cmd(line, "Loading") && !resetObject)
{
OpString(line, "name", name);
- UserDir(m_infoFilename[SATCOM_LOADING], name, "help");
+ std::string path = m_app->GetDataFilePath(DIR_HELP, name);
+ strcpy(m_infoFilename[SATCOM_LOADING], path.c_str());
}
if (Cmd(line, "HelpFile") && !resetObject)
{
OpString(line, "name", name);
- UserDir(m_infoFilename[SATCOM_PROG], name, "help");
+ std::string path = m_app->GetDataFilePath(DIR_HELP, name);
+ strcpy(m_infoFilename[SATCOM_PROG], path.c_str());
}
if (Cmd(line, "SoluceFile") && !resetObject)
{
OpString(line, "name", name);
- UserDir(m_infoFilename[SATCOM_SOLUCE], name, "help");
+ std::string path = m_app->GetDataFilePath(DIR_HELP, name);
+ strcpy(m_infoFilename[SATCOM_SOLUCE], path.c_str());
}
if (Cmd(line, "EndingFile") && !resetObject)
@@ -3875,8 +3885,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (Cmd(line, "Background") && !resetObject)
{
OpString(line, "image", name);
- UserDir(dir, name, "");
- m_engine->SetBackground(dir,
+ m_engine->SetBackground(name,
OpColor(line, "up", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)),
OpColor(line, "down", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)),
OpColor(line, "cloudUp", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)),
@@ -3892,13 +3901,12 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
uv1 = OpPos(line, "uv1");
uv2 = OpPos(line, "uv2");
OpString(line, "image", name);
- UserDir(dir, name, "");
m_planet->Create(OpInt(line, "mode", 0),
Math::Point(ppos.x, ppos.z),
OpFloat(line, "dim", 0.2f),
OpFloat(line, "speed", 0.0f),
OpFloat(line, "dir", 0.0f),
- dir,
+ name,
Math::Point(uv1.x, uv1.z),
Math::Point(uv2.x, uv2.z));
}
@@ -3906,8 +3914,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (Cmd(line, "FrontsizeName") && !resetObject)
{
OpString(line, "image", name);
- UserDir(dir, name, "");
- m_engine->SetForegroundName(dir);
+ m_engine->SetForegroundName(name);
}
if (Cmd(line, "Global") && !resetObject)
@@ -3933,28 +3940,25 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (Cmd(line, "TerrainRelief") && !resetObject)
{
OpString(line, "image", name);
- UserDir(dir, name, "textures");
- m_terrain->LoadRelief(dir, OpFloat(line, "factor", 1.0f), OpInt(line, "border", 1));
+ m_terrain->LoadRelief(name, OpFloat(line, "factor", 1.0f), OpInt(line, "border", 1));
}
if (Cmd(line, "TerrainResource") && !resetObject)
{
OpString(line, "image", name);
- UserDir(dir, name, "textures");
- m_terrain->LoadResources(dir);
+ m_terrain->LoadResources(name);
}
if (Cmd(line, "TerrainWater") && !resetObject)
{
OpString(line, "image", name);
- UserDir(dir, name, "");
Math::Vector pos;
pos.x = OpFloat(line, "moveX", 0.0f);
pos.y = OpFloat(line, "moveY", 0.0f);
pos.z = pos.x;
m_water->Create(OpTypeWater(line, "air", Gfx::WATER_TT),
OpTypeWater(line, "water", Gfx::WATER_TT),
- dir,
+ name,
OpColor(line, "diffuse", Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)),
OpColor(line, "ambiant", Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)),
OpFloat(line, "level", 100.0f)*UNIT,
@@ -3970,8 +3974,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (Cmd(line, "TerrainCloud") && !resetObject)
{
OpString(line, "image", name);
- UserDir(dir, name, "");
- m_cloud->Create(dir,
+ m_cloud->Create(name,
OpColor(line, "diffuse", Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)),
OpColor(line, "ambiant", Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)),
OpFloat(line, "level", 500.0f) * UNIT);
diff --git a/src/ui/color.cpp b/src/ui/color.cpp
index a727642..2ba87a3 100644
--- a/src/ui/color.cpp
+++ b/src/ui/color.cpp
@@ -153,7 +153,7 @@ void CColor::Draw()
// color = GetColor(m_color);
color = GetColor();
- m_engine->SetTexture("xxx.png"); // no texture
+ m_engine->SetTexture(""); // no texture
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
device = m_engine->GetDevice();
@@ -187,7 +187,7 @@ void CColor::Draw()
color = GetColor();
- m_engine->SetTexture("xxx.png"); // no texture
+ m_engine->SetTexture(""); // no texture
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
vertex[0] = Gfx::VertexCol(Math::Vector(p1.x, p1.y, 0.0f), color, Gfx::Color(), Math::Point(0.0f, 0.0f));
diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp
index 010e087..6395acf 100644
--- a/src/ui/maindialog.cpp
+++ b/src/ui/maindialog.cpp
@@ -4824,8 +4824,6 @@ void CMainDialog::UpdateSceneChap(int &chap)
pl->SetCheck(j, bPassed);
pl->SetEnable(j, true);
- continue;
-
if ( m_phase == PHASE_MISSION && !m_main->GetShowAll() && !bPassed )
{
j ++;