Various fixes

- disabled UserDir() in path lookup
 - fixed crashes on loading missions in CObject
 - fixed texture bug in CTerrain
 - changed mouse move event handling to avoid flooding event queue
 - enabled all missions for testing
dev-ui
Piotr Dziwinski 2012-09-22 17:36:10 +02:00
parent fd09071c29
commit b1edcc822f
8 changed files with 132 additions and 51 deletions

View File

@ -65,6 +65,8 @@ struct ApplicationPrivate
SDL_Surface *surface; SDL_Surface *surface;
//! Currently handled event //! Currently handled event
SDL_Event currentEvent; SDL_Event currentEvent;
//! Mouse motion event to be handled
SDL_Event lastMouseMotionEvent;
//! Joystick //! Joystick
SDL_Joystick *joystick; SDL_Joystick *joystick;
//! Id of joystick timer //! Id of joystick timer
@ -73,6 +75,7 @@ struct ApplicationPrivate
ApplicationPrivate() ApplicationPrivate()
{ {
memset(&currentEvent, 0, sizeof(SDL_Event)); memset(&currentEvent, 0, sizeof(SDL_Event));
memset(&lastMouseMotionEvent, 0, sizeof(SDL_Event));
surface = nullptr; surface = nullptr;
joystick = nullptr; joystick = nullptr;
joystickTimer = 0; joystickTimer = 0;
@ -721,6 +724,8 @@ int CApplication::Run()
if (m_active) if (m_active)
SDL_PumpEvents(); SDL_PumpEvents();
m_private->lastMouseMotionEvent.type = SDL_NOEVENT;
bool haveEvent = true; bool haveEvent = true;
while (haveEvent) while (haveEvent)
{ {
@ -739,6 +744,13 @@ int CApplication::Run()
{ {
haveEvent = true; 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(); Event event = ProcessSystemEvent();
if (event.type == EVENT_QUIT) 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 // Enter game update & frame rendering only if active
if (m_active) if (m_active)
{ {

View File

@ -14,10 +14,10 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * along with this program. If not, see http://www.gnu.org/licenses/.
// event.cpp
#include "common/event.h" #include "common/event.h"
#include "common/iman.h" #include "common/iman.h"
#include "common/logger.h"
static EventType g_uniqueEventType = EVENT_USER; static EventType g_uniqueEventType = EVENT_USER;
@ -54,7 +54,11 @@ void CEventQueue::Flush()
Else, adds the event to the queue and returns \c true. */ Else, adds the event to the queue and returns \c true. */
bool CEventQueue::AddEvent(const Event &event) 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; m_fifo[m_head++] = event;
if ( m_head >= MAX_EVENT_QUEUE ) m_head = 0; if ( m_head >= MAX_EVENT_QUEUE ) m_head = 0;

View File

@ -162,7 +162,7 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app)
m_limitLOD[1] = 200.0f; m_limitLOD[1] = 200.0f;
m_particleDensity = 1.0f; m_particleDensity = 1.0f;
m_clippingDistance = 1.0f; m_clippingDistance = 1.0f;
m_lastClippingDistance = m_clippingDistance; m_lastClippingDistance = m_clippingDistance = 1.0f;
m_objectDetail = 1.0f; m_objectDetail = 1.0f;
m_lastObjectDetail = m_objectDetail; m_lastObjectDetail = m_objectDetail;
m_terrainVision = 1000.0f; 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) 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()) if (m_texBlacklist.find(texName) != m_texBlacklist.end())
return Texture(); // invalid texture return Texture(); // invalid texture

View File

@ -131,14 +131,15 @@ bool CTerrain::InitTextures(const std::string& baseName, int* table, int dx, int
m_texBaseName = baseName; m_texBaseName = baseName;
size_t pos = baseName.find('.'); size_t pos = baseName.find('.');
if (pos == baseName.npos)
if (pos == std::string::npos)
{ {
m_texBaseExt = ".png"; m_texBaseExt = ".png";
} }
else else
{ {
m_texBaseName = m_texBaseName.substr(0, pos);
m_texBaseExt = m_texBaseName.substr(pos); m_texBaseExt = m_texBaseName.substr(pos);
m_texBaseName = m_texBaseName.substr(0, pos);
} }
for (int y = 0; y < m_mosaicCount*m_textureSubdivCount; y++) 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) bool CTerrain::LoadResources(const std::string& fileName)
{ {
CImage img; 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; return false;
}
ImageData *data = img.GetData(); ImageData *data = img.GetData();
@ -210,7 +215,10 @@ bool CTerrain::LoadResources(const std::string& fileName)
if ( (data->surface->w != size) || (data->surface->h != size) || if ( (data->surface->w != size) || (data->surface->h != size) ||
(data->surface->format->BytesPerPixel != 3) ) (data->surface->format->BytesPerPixel != 3) )
{
GetLogger()->Error("Invalid resource file\n");
return false; return false;
}
unsigned char* pixels = static_cast<unsigned char*>(data->surface->pixels); unsigned char* pixels = static_cast<unsigned char*>(data->surface->pixels);
int pitch = data->surface->pitch; 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 * The image must be 24 bits/pixel and dx x dy in size
* with dx = dy = (mosaic*brick)+1 */ * with dx = dy = (mosaic*brick)+1 */
bool CTerrain::LoadRelief(const std::string &fileName, float scaleRelief, bool CTerrain::LoadRelief(const std::string &fileName, float scaleRelief,
bool adjustBorder) bool adjustBorder)
{ {
m_scaleRelief = scaleRelief; m_scaleRelief = scaleRelief;
CImage img; 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; return false;
}
ImageData *data = img.GetData(); 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) || if ( (data->surface->w != size) || (data->surface->h != size) ||
(data->surface->format->BytesPerPixel != 3) ) (data->surface->format->BytesPerPixel != 3) )
{
GetLogger()->Error("Invalid relief file!\n");
return false; return false;
}
unsigned char* pixels = static_cast<unsigned char*>(data->surface->pixels); unsigned char* pixels = static_cast<unsigned char*>(data->surface->pixels);
int pitch = data->surface->pitch; 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); TerrainMaterial* tm = FindMaterial(m_materialPoints[x+y*m_materialPointCount].id);
if (tm == nullptr) if (tm == nullptr)
{ {
name = "xxx.png"; name = "";
uv = Math::Point(0.0f, 0.0f); uv = Math::Point(0.0f, 0.0f);
} }
else else

View File

@ -7528,49 +7528,73 @@ void CObject::DeleteDeselList(CObject* pObj)
bool CObject::GetTraceDown() bool CObject::GetTraceDown()
{ {
CMotionVehicle* mv; if (m_motion == nullptr) return false;
if ( m_motion == 0 ) return false; CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr)
{
GetLogger()->Warn("GetTraceDown() invalid m_motion class!\n");
return false;
}
return mv->GetTraceDown(); return mv->GetTraceDown();
} }
void CObject::SetTraceDown(bool bDown) void CObject::SetTraceDown(bool bDown)
{ {
CMotionVehicle* mv; if (m_motion == nullptr) return;
if ( m_motion == 0 ) return; CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr)
{
GetLogger()->Warn("SetTraceDown() invalid m_motion class!\n");
return;
}
mv->SetTraceDown(bDown); mv->SetTraceDown(bDown);
} }
int CObject::GetTraceColor() int CObject::GetTraceColor()
{ {
CMotionVehicle* mv; if (m_motion == nullptr) return 0;
if ( m_motion == 0 ) return 0; CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr)
{
GetLogger()->Warn("GetTraceColor() invalid m_motion class!\n");
return 0;
}
return mv->GetTraceColor(); return mv->GetTraceColor();
} }
void CObject::SetTraceColor(int color) void CObject::SetTraceColor(int color)
{ {
CMotionVehicle* mv; if (m_motion == nullptr) return;
if ( m_motion == 0 ) return; CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr)
{
GetLogger()->Warn("SetTraceColor() invalid m_motion class!\n");
return;
}
mv->SetTraceColor(color); mv->SetTraceColor(color);
} }
float CObject::GetTraceWidth() float CObject::GetTraceWidth()
{ {
CMotionVehicle* mv; if (m_motion == nullptr) return 0.0f;
if ( m_motion == 0 ) return 0.0f; CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr)
{
GetLogger()->Warn("GetTraceWidth() invalid m_motion class!\n");
return 0.0f;
}
return mv->GetTraceWidth(); return mv->GetTraceWidth();
} }
void CObject::SetTraceWidth(float width) void CObject::SetTraceWidth(float width)
{ {
CMotionVehicle* mv; if (m_motion == nullptr) return;
if ( m_motion == 0 ) return; CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr)
{
GetLogger()->Warn("SetTraceWidth() invalid m_motion class!\n");
return;
}
mv->SetTraceWidth(width); mv->SetTraceWidth(width);
} }

View File

@ -664,7 +664,7 @@ CRobotMain::CRobotMain(CInstanceManager* iMan, CApplication* app)
m_showPos = false; m_showPos = false;
m_selectInsect = false; m_selectInsect = false;
m_showSoluce = false; m_showSoluce = false;
m_showAll = false; m_showAll = true; // for development
m_cheatRadar = false; m_cheatRadar = false;
m_fixScene = false; m_fixScene = false;
m_trainerPilot = false; m_trainerPilot = false;
@ -3682,6 +3682,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
char* stack = m_dialog->GetStackRead(); char* stack = m_dialog->GetStackRead();
m_dialog->SetUserDir(base, rank); 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; m_fixScene = fixScene;
g_id = 0; g_id = 0;
@ -3791,7 +3796,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (Cmd(line, "Instructions") && !resetObject) if (Cmd(line, "Instructions") && !resetObject)
{ {
OpString(line, "name", name); 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); m_immediatSatCom = OpInt(line, "immediat", 0);
} }
@ -3799,24 +3805,28 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (Cmd(line, "Satellite") && !resetObject) if (Cmd(line, "Satellite") && !resetObject)
{ {
OpString(line, "name", name); 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) if (Cmd(line, "Loading") && !resetObject)
{ {
OpString(line, "name", name); 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) if (Cmd(line, "HelpFile") && !resetObject)
{ {
OpString(line, "name", name); 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) if (Cmd(line, "SoluceFile") && !resetObject)
{ {
OpString(line, "name", name); 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) if (Cmd(line, "EndingFile") && !resetObject)
@ -3875,8 +3885,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (Cmd(line, "Background") && !resetObject) if (Cmd(line, "Background") && !resetObject)
{ {
OpString(line, "image", name); OpString(line, "image", name);
UserDir(dir, name, ""); m_engine->SetBackground(name,
m_engine->SetBackground(dir,
OpColor(line, "up", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)), 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, "down", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)),
OpColor(line, "cloudUp", 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"); uv1 = OpPos(line, "uv1");
uv2 = OpPos(line, "uv2"); uv2 = OpPos(line, "uv2");
OpString(line, "image", name); OpString(line, "image", name);
UserDir(dir, name, "");
m_planet->Create(OpInt(line, "mode", 0), m_planet->Create(OpInt(line, "mode", 0),
Math::Point(ppos.x, ppos.z), Math::Point(ppos.x, ppos.z),
OpFloat(line, "dim", 0.2f), OpFloat(line, "dim", 0.2f),
OpFloat(line, "speed", 0.0f), OpFloat(line, "speed", 0.0f),
OpFloat(line, "dir", 0.0f), OpFloat(line, "dir", 0.0f),
dir, name,
Math::Point(uv1.x, uv1.z), Math::Point(uv1.x, uv1.z),
Math::Point(uv2.x, uv2.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) if (Cmd(line, "FrontsizeName") && !resetObject)
{ {
OpString(line, "image", name); OpString(line, "image", name);
UserDir(dir, name, ""); m_engine->SetForegroundName(name);
m_engine->SetForegroundName(dir);
} }
if (Cmd(line, "Global") && !resetObject) if (Cmd(line, "Global") && !resetObject)
@ -3933,28 +3940,25 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (Cmd(line, "TerrainRelief") && !resetObject) if (Cmd(line, "TerrainRelief") && !resetObject)
{ {
OpString(line, "image", name); OpString(line, "image", name);
UserDir(dir, name, "textures"); m_terrain->LoadRelief(name, OpFloat(line, "factor", 1.0f), OpInt(line, "border", 1));
m_terrain->LoadRelief(dir, OpFloat(line, "factor", 1.0f), OpInt(line, "border", 1));
} }
if (Cmd(line, "TerrainResource") && !resetObject) if (Cmd(line, "TerrainResource") && !resetObject)
{ {
OpString(line, "image", name); OpString(line, "image", name);
UserDir(dir, name, "textures"); m_terrain->LoadResources(name);
m_terrain->LoadResources(dir);
} }
if (Cmd(line, "TerrainWater") && !resetObject) if (Cmd(line, "TerrainWater") && !resetObject)
{ {
OpString(line, "image", name); OpString(line, "image", name);
UserDir(dir, name, "");
Math::Vector pos; Math::Vector pos;
pos.x = OpFloat(line, "moveX", 0.0f); pos.x = OpFloat(line, "moveX", 0.0f);
pos.y = OpFloat(line, "moveY", 0.0f); pos.y = OpFloat(line, "moveY", 0.0f);
pos.z = pos.x; pos.z = pos.x;
m_water->Create(OpTypeWater(line, "air", Gfx::WATER_TT), m_water->Create(OpTypeWater(line, "air", Gfx::WATER_TT),
OpTypeWater(line, "water", 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, "diffuse", Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)),
OpColor(line, "ambiant", 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, OpFloat(line, "level", 100.0f)*UNIT,
@ -3970,8 +3974,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (Cmd(line, "TerrainCloud") && !resetObject) if (Cmd(line, "TerrainCloud") && !resetObject)
{ {
OpString(line, "image", name); OpString(line, "image", name);
UserDir(dir, name, ""); m_cloud->Create(name,
m_cloud->Create(dir,
OpColor(line, "diffuse", Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)), 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)), OpColor(line, "ambiant", Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)),
OpFloat(line, "level", 500.0f) * UNIT); OpFloat(line, "level", 500.0f) * UNIT);

View File

@ -153,7 +153,7 @@ void CColor::Draw()
// color = GetColor(m_color); // color = GetColor(m_color);
color = GetColor(); color = GetColor();
m_engine->SetTexture("xxx.png"); // no texture m_engine->SetTexture(""); // no texture
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
device = m_engine->GetDevice(); device = m_engine->GetDevice();
@ -187,7 +187,7 @@ void CColor::Draw()
color = GetColor(); color = GetColor();
m_engine->SetTexture("xxx.png"); // no texture m_engine->SetTexture(""); // no texture
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); 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)); vertex[0] = Gfx::VertexCol(Math::Vector(p1.x, p1.y, 0.0f), color, Gfx::Color(), Math::Point(0.0f, 0.0f));

View File

@ -4824,8 +4824,6 @@ void CMainDialog::UpdateSceneChap(int &chap)
pl->SetCheck(j, bPassed); pl->SetCheck(j, bPassed);
pl->SetEnable(j, true); pl->SetEnable(j, true);
continue;
if ( m_phase == PHASE_MISSION && !m_main->GetShowAll() && !bPassed ) if ( m_phase == PHASE_MISSION && !m_main->GetShowAll() && !bPassed )
{ {
j ++; j ++;