Merge branch 'dev-0.1.8' into dev

dev-time-step
krzys-h 2016-03-29 16:16:20 +02:00
commit 64fef98bd7
24 changed files with 977 additions and 279 deletions

View File

@ -218,6 +218,7 @@ set(BASE_SOURCES
script/scriptfunc.cpp script/scriptfunc.cpp
sound/sound.cpp sound/sound.cpp
sound/sound_type.cpp sound/sound_type.cpp
ui/debug_menu.cpp
ui/displayinfo.cpp ui/displayinfo.cpp
ui/displaytext.cpp ui/displaytext.cpp
ui/object_interface.cpp ui/object_interface.cpp

View File

@ -833,7 +833,7 @@ bool CApplication::ChangeVideoConfig(const Gfx::DeviceConfig &newConfig)
m_device->ConfigChanged(m_deviceConfig); m_device->ConfigChanged(m_deviceConfig);
m_engine->ResetAfterVideoConfigChanged(); m_eventQueue->AddEvent(Event(EVENT_RESOLUTION_CHANGED));
return true; return true;
} }

View File

@ -332,7 +332,7 @@ InputSlot CInput::FindBinding(unsigned int key)
void CInput::SaveKeyBindings() void CInput::SaveKeyBindings()
{ {
std::stringstream key; std::stringstream key;
CConfigFile::GetInstancePointer()->SetStringProperty("Keybindings", "_Version", "SDL2"); GetConfigFile().SetStringProperty("Keybindings", "_Version", "SDL2");
for (int i = 0; i < INPUT_SLOT_MAX; i++) for (int i = 0; i < INPUT_SLOT_MAX; i++)
{ {
InputBinding b = GetInputBinding(static_cast<InputSlot>(i)); InputBinding b = GetInputBinding(static_cast<InputSlot>(i));
@ -341,30 +341,30 @@ void CInput::SaveKeyBindings()
key.str(""); key.str("");
key << b.primary << " " << b.secondary; key << b.primary << " " << b.secondary;
CConfigFile::GetInstancePointer()->SetStringProperty("Keybindings", m_keyTable[static_cast<InputSlot>(i)], key.str()); GetConfigFile().SetStringProperty("Keybindings", m_keyTable[static_cast<InputSlot>(i)], key.str());
} }
for (int i = 0; i < JOY_AXIS_SLOT_MAX; i++) for (int i = 0; i < JOY_AXIS_SLOT_MAX; i++)
{ {
JoyAxisBinding b = GetJoyAxisBinding(static_cast<JoyAxisSlot>(i)); JoyAxisBinding b = GetJoyAxisBinding(static_cast<JoyAxisSlot>(i));
CConfigFile::GetInstancePointer()->SetIntProperty("Setup", "JoystickAxisBinding"+boost::lexical_cast<std::string>(i), b.axis); GetConfigFile().SetIntProperty("Setup", "JoystickAxisBinding"+boost::lexical_cast<std::string>(i), b.axis);
CConfigFile::GetInstancePointer()->SetIntProperty("Setup", "JoystickAxisInvert"+boost::lexical_cast<std::string>(i), b.invert); GetConfigFile().SetIntProperty("Setup", "JoystickAxisInvert"+boost::lexical_cast<std::string>(i), b.invert);
} }
CConfigFile::GetInstancePointer()->SetFloatProperty("Setup", "JoystickDeadzone", GetJoystickDeadzone()); GetConfigFile().SetFloatProperty("Setup", "JoystickDeadzone", GetJoystickDeadzone());
} }
void CInput::LoadKeyBindings() void CInput::LoadKeyBindings()
{ {
std::stringstream skey; std::stringstream skey;
std::string keys; std::string keys;
if (CConfigFile::GetInstancePointer()->GetStringProperty("Keybindings", "_Version", keys) && keys == "SDL2") // Keybindings from SDL1.2 are incompatible with SDL2 !! if (GetConfigFile().GetStringProperty("Keybindings", "_Version", keys) && keys == "SDL2") // Keybindings from SDL1.2 are incompatible with SDL2 !!
{ {
for (int i = 0; i < INPUT_SLOT_MAX; i++) for (int i = 0; i < INPUT_SLOT_MAX; i++)
{ {
InputBinding b; InputBinding b;
if (!CConfigFile::GetInstancePointer()->GetStringProperty("Keybindings", m_keyTable[static_cast<InputSlot>(i)], keys)) if (!GetConfigFile().GetStringProperty("Keybindings", m_keyTable[static_cast<InputSlot>(i)], keys))
continue; continue;
skey.clear(); skey.clear();
skey.str(keys); skey.str(keys);
@ -380,17 +380,17 @@ void CInput::LoadKeyBindings()
{ {
JoyAxisBinding b; JoyAxisBinding b;
if (!CConfigFile::GetInstancePointer()->GetIntProperty("Setup", "JoystickAxisBinding"+boost::lexical_cast<std::string>(i), b.axis)) if (!GetConfigFile().GetIntProperty("Setup", "JoystickAxisBinding"+boost::lexical_cast<std::string>(i), b.axis))
continue; continue;
int x = 0; int x = 0;
CConfigFile::GetInstancePointer()->GetIntProperty("Setup", "JoystickAxisInvert"+boost::lexical_cast<std::string>(i), x); // If doesn't exist, use default (0) GetConfigFile().GetIntProperty("Setup", "JoystickAxisInvert"+boost::lexical_cast<std::string>(i), x); // If doesn't exist, use default (0)
b.invert = (x != 0); b.invert = (x != 0);
SetJoyAxisBinding(static_cast<JoyAxisSlot>(i), b); SetJoyAxisBinding(static_cast<JoyAxisSlot>(i), b);
} }
float deadzone; float deadzone;
if (CConfigFile::GetInstancePointer()->GetFloatProperty("Setup", "JoystickDeadzone", deadzone)) if (GetConfigFile().GetFloatProperty("Setup", "JoystickDeadzone", deadzone))
SetJoystickDeadzone(deadzone); SetJoystickDeadzone(deadzone);
} }

View File

@ -107,8 +107,8 @@ private:
bool m_loaded; bool m_loaded;
}; };
//! Global function to get profile instance //! Global function to get config file instance
inline CConfigFile & GetConfigFile() inline CConfigFile & GetConfigFile()
{ {
return *CConfigFile::GetInstancePointer(); return CConfigFile::GetInstance();
} }

View File

@ -68,6 +68,8 @@ void InitializeEventTypeTexts()
EVENT_TYPE_TEXT[EVENT_UPDINTERFACE] = "EVENT_UPDINTERFACE"; EVENT_TYPE_TEXT[EVENT_UPDINTERFACE] = "EVENT_UPDINTERFACE";
EVENT_TYPE_TEXT[EVENT_RESOLUTION_CHANGED]= "EVENT_RESOLUTION_CHANGED";
EVENT_TYPE_TEXT[EVENT_RELOAD_TEXTURES] = "EVENT_RELOAD_TEXTURES";
EVENT_TYPE_TEXT[EVENT_WIN] = "EVENT_WIN"; EVENT_TYPE_TEXT[EVENT_WIN] = "EVENT_WIN";
EVENT_TYPE_TEXT[EVENT_LOST] = "EVENT_LOST"; EVENT_TYPE_TEXT[EVENT_LOST] = "EVENT_LOST";

View File

@ -95,6 +95,10 @@ enum EventType
//! Event sent on user quit request //! Event sent on user quit request
EVENT_QUIT = 20, EVENT_QUIT = 20,
EVENT_UPDINTERFACE = 21, EVENT_UPDINTERFACE = 21,
//! Event sent on resolution change
EVENT_RESOLUTION_CHANGED = 22,
//! Event sent when textures have to be reloaded
EVENT_RELOAD_TEXTURES = 23,
EVENT_WIN = 30, EVENT_WIN = 30,
EVENT_LOST = 31, EVENT_LOST = 31,
@ -145,7 +149,7 @@ enum EventType
EVENT_WINDOW4 = 84, //!< CDisplayInfo EVENT_WINDOW4 = 84, //!< CDisplayInfo
EVENT_WINDOW5 = 85, //!< all menu windows EVENT_WINDOW5 = 85, //!< all menu windows
EVENT_WINDOW6 = 86, //!< code battle interface EVENT_WINDOW6 = 86, //!< code battle interface
EVENT_WINDOW7 = 87, //!< (unused) EVENT_WINDOW7 = 87, //!< debug interface
EVENT_WINDOW8 = 88, //!< (unused) EVENT_WINDOW8 = 88, //!< (unused)
EVENT_WINDOW9 = 89, //!< CMainDialog and CStudio file selector EVENT_WINDOW9 = 89, //!< CMainDialog and CStudio file selector
@ -376,6 +380,31 @@ enum EventType
EVENT_CMD = 800, EVENT_CMD = 800,
EVENT_SPEED = 801, EVENT_SPEED = 801,
EVENT_DBG_STATS = 850,
EVENT_DBG_SPAWN_OBJ = 851,
EVENT_DBG_TELEPORT = 852,
EVENT_DBG_LIGHTNING = 853,
EVENT_DBG_RESOURCES = 854,
EVENT_DBG_GOTO = 855,
EVENT_DBG_CRASHSPHERES = 856,
EVENT_DBG_LIGHTS = 857,
EVENT_DBG_LIGHTS_DUMP = 858,
EVENT_SPAWN_CANCEL = 860,
EVENT_SPAWN_ME = 861,
EVENT_SPAWN_WHEELEDGRABBER = 862,
EVENT_SPAWN_WHEELEDSHOOTER = 863,
EVENT_SPAWN_PHAZERSHOOTER = 864,
EVENT_SPAWN_BOTFACTORY = 865,
EVENT_SPAWN_CONVERTER = 866,
EVENT_SPAWN_DERRICK = 867,
EVENT_SPAWN_POWERSTATION= 868,
EVENT_SPAWN_TITANIUM = 869,
EVENT_SPAWN_TITANIUMORE = 870,
EVENT_SPAWN_URANIUMORE = 871,
EVENT_SPAWN_POWERCELL = 872,
EVENT_SPAWN_NUCLEARCELL = 873,
EVENT_HYPER_PREV = 900, EVENT_HYPER_PREV = 900,
EVENT_HYPER_NEXT = 901, EVENT_HYPER_NEXT = 901,
EVENT_HYPER_HOME = 902, EVENT_HYPER_HOME = 902,

View File

@ -27,9 +27,6 @@ namespace Gfx
CNullDevice::CNullDevice() CNullDevice::CNullDevice()
{ {
m_matrix = Math::Matrix();
m_material = Material();
m_light = Light();
} }
CNullDevice::~CNullDevice() CNullDevice::~CNullDevice()

View File

@ -17,11 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses * along with this program. If not, see http://gnu.org/licenses
*/ */
/**
* \file graphics/core/device.h
* \brief Abstract graphics device - CDevice class and related structs/enums
*/
#pragma once #pragma once
#include "graphics/core/device.h" #include "graphics/core/device.h"
@ -38,7 +33,6 @@ namespace Gfx
/** /**
* \class CNullDevice * \class CNullDevice
* \brief Device implementation that doesn't render anything * \brief Device implementation that doesn't render anything
*
*/ */
class CNullDevice : public CDevice class CNullDevice : public CDevice
{ {
@ -160,11 +154,6 @@ public:
int GetMaxTextureSize() override; int GetMaxTextureSize() override;
bool IsFramebufferSupported() override; bool IsFramebufferSupported() override;
private:
Math::Matrix m_matrix;
Material m_material;
Light m_light;
}; };

View File

@ -359,8 +359,6 @@ void CEngine::ResetAfterVideoConfigChanged()
m_size = m_app->GetVideoConfig().size; m_size = m_app->GetVideoConfig().size;
m_mouseSize = Math::Point(0.04f, 0.04f * (static_cast<float>(m_size.x) / static_cast<float>(m_size.y))); m_mouseSize = Math::Point(0.04f, 0.04f * (static_cast<float>(m_size.x) / static_cast<float>(m_size.y)));
CRobotMain::GetInstancePointer()->ResetAfterVideoConfigChanged(); //TODO: Remove cross-reference to CRobotMain
// Update the camera projection matrix for new aspect ratio // Update the camera projection matrix for new aspect ratio
SetFocus(m_focus); SetFocus(m_focus);
@ -373,13 +371,18 @@ void CEngine::ReloadAllTextures()
FlushTextureCache(); FlushTextureCache();
m_text->FlushCache(); m_text->FlushCache();
CRobotMain::GetInstancePointer()->ReloadAllTextures(); //TODO: Remove cross-reference to CRobotMain m_app->GetEventQueue()->AddEvent(Event(EVENT_RELOAD_TEXTURES));
UpdateGroundSpotTextures(); UpdateGroundSpotTextures();
LoadAllTextures(); LoadAllTextures();
} }
bool CEngine::ProcessEvent(const Event &event) bool CEngine::ProcessEvent(const Event &event)
{ {
if (event.type == EVENT_RESOLUTION_CHANGED)
{
ResetAfterVideoConfigChanged();
}
if (event.type == EVENT_KEY_DOWN) if (event.type == EVENT_KEY_DOWN)
{ {
auto data = event.GetData<KeyEventData>(); auto data = event.GetData<KeyEventData>();
@ -389,18 +392,6 @@ bool CEngine::ProcessEvent(const Event &event)
m_showStats = !m_showStats; m_showStats = !m_showStats;
return false; return false;
} }
if (data->key == KEY(F11))
{
m_debugLights = !m_debugLights;
return false;
}
if (data->key == KEY(F10))
{
m_debugDumpLights = true;
return false;
}
} }
// By default, pass on all events // By default, pass on all events
@ -1750,17 +1741,18 @@ bool CEngine::DetectBBox(int objRank, Math::Point mouse)
mouse.y <= max.y ); mouse.y <= max.y );
} }
int CEngine::DetectObject(Math::Point mouse) int CEngine::DetectObject(Math::Point mouse, Math::Vector& targetPos, bool terrain)
{ {
float min = 1000000.0f; float min = 1000000.0f;
int nearest = -1; int nearest = -1;
Math::Vector pos;
for (int objRank = 0; objRank < static_cast<int>( m_objects.size() ); objRank++) for (int objRank = 0; objRank < static_cast<int>( m_objects.size() ); objRank++)
{ {
if (! m_objects[objRank].used) if (! m_objects[objRank].used)
continue; continue;
if (m_objects[objRank].type == ENG_OBJTYPE_TERRAIN) if (m_objects[objRank].type == ENG_OBJTYPE_TERRAIN && !terrain)
continue; continue;
if (! DetectBBox(objRank, mouse)) if (! DetectBBox(objRank, mouse))
@ -1789,10 +1781,11 @@ int CEngine::DetectObject(Math::Point mouse)
for (int i = 0; i < static_cast<int>( p3.vertices.size() ); i += 3) for (int i = 0; i < static_cast<int>( p3.vertices.size() ); i += 3)
{ {
float dist = 0.0f; float dist = 0.0f;
if (DetectTriangle(mouse, &p3.vertices[i], objRank, dist) && dist < min) if (DetectTriangle(mouse, &p3.vertices[i], objRank, dist, pos) && dist < min)
{ {
min = dist; min = dist;
nearest = objRank; nearest = objRank;
targetPos = pos;
} }
} }
} }
@ -1801,10 +1794,11 @@ int CEngine::DetectObject(Math::Point mouse)
for (int i = 0; i < static_cast<int>( p3.vertices.size() ) - 2; i += 1) for (int i = 0; i < static_cast<int>( p3.vertices.size() ) - 2; i += 1)
{ {
float dist = 0.0f; float dist = 0.0f;
if (DetectTriangle(mouse, &p3.vertices[i], objRank, dist) && dist < min) if (DetectTriangle(mouse, &p3.vertices[i], objRank, dist, pos) && dist < min)
{ {
min = dist; min = dist;
nearest = objRank; nearest = objRank;
targetPos = pos;
} }
} }
} }
@ -1815,7 +1809,7 @@ int CEngine::DetectObject(Math::Point mouse)
return nearest; return nearest;
} }
bool CEngine::DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRank, float& dist) bool CEngine::DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRank, float& dist, Math::Vector& pos)
{ {
assert(objRank >= 0 && objRank < static_cast<int>(m_objects.size())); assert(objRank >= 0 && objRank < static_cast<int>(m_objects.size()));
@ -1862,6 +1856,16 @@ bool CEngine::DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRan
if (! Math::IsInsideTriangle(a, b, c, mouse)) if (! Math::IsInsideTriangle(a, b, c, mouse))
return false; return false;
Math::Vector a2 = Math::Transform(m_objects[objRank].transform, triangle[0].coord);
Math::Vector b2 = Math::Transform(m_objects[objRank].transform, triangle[1].coord);
Math::Vector c2 = Math::Transform(m_objects[objRank].transform, triangle[2].coord);
Math::Vector e = Math::Transform(m_matView.Inverse(), Math::Vector(0.0f, 0.0f, -1.0f));
Math::Vector f = Math::Transform(m_matView.Inverse(), Math::Vector(
(mouse.x*2.0f-1.0f)*m_matProj.Inverse().Get(1,1),
(mouse.y*2.0f-1.0f)*m_matProj.Inverse().Get(2,2),
0.0f));
Math::Intersect(a2, b2, c2, e, f, pos);
dist = (p2D[0].z + p2D[1].z + p2D[2].z) / 3.0f; dist = (p2D[0].z + p2D[1].z + p2D[2].z) / 3.0f;
return true; return true;
} }
@ -3374,6 +3378,21 @@ void CEngine::Draw3DScene()
if (m_debugCrashSpheres) if (m_debugCrashSpheres)
DrawCrashSpheres(); DrawCrashSpheres();
if (m_debugGoto)
{
Math::Matrix worldMatrix;
worldMatrix.LoadIdentity();
m_device->SetTransform(TRANSFORM_WORLD, worldMatrix);
SetState(ENG_RSTATE_OPAQUE_COLOR);
for (const auto& line : m_displayGoto)
{
m_device->DrawPrimitive(PRIMITIVE_LINE_STRIP, line.data(), line.size());
}
}
m_displayGoto.clear();
m_app->StartPerformanceCounter(PCNT_RENDER_PARTICLE); m_app->StartPerformanceCounter(PCNT_RENDER_PARTICLE);
m_particle->DrawParticle(SH_WORLD); // draws the particles of the 3D world m_particle->DrawParticle(SH_WORLD); // draws the particles of the 3D world
m_app->StopPerformanceCounter(PCNT_RENDER_PARTICLE); m_app->StopPerformanceCounter(PCNT_RENDER_PARTICLE);
@ -3967,7 +3986,7 @@ void CEngine::UpdateGroundSpotTextures()
set = true; set = true;
} }
if (clear || set) if (clear || set || m_debugResources || m_displayGotoImage != nullptr)
{ {
CImage shadowImg(Math::IntPoint(256, 256)); CImage shadowImg(Math::IntPoint(256, 256));
shadowImg.Fill(Gfx::IntColor(255, 255, 255, 255)); shadowImg.Fill(Gfx::IntColor(255, 255, 255, 255));
@ -4127,6 +4146,43 @@ void CEngine::UpdateGroundSpotTextures()
} }
} }
if (m_debugResources)
{
for (float x = min.x; x < max.x; x += 1.0f)
{
for (float y = min.y; y < max.y; y += 1.0f)
{
Math::Vector pos(
x / 4.0f / 254.0f * 3200.0f - 1600.0f,
0.0f,
y / 4.0f / 254.0f * 3200.0f - 1600.0f
);
TerrainRes res = m_terrain->GetResource(pos);
Math::IntPoint p(x-min.x, y-min.y);
if (res == TR_NULL)
{
shadowImg.SetPixel(p, Gfx::Color(0.5f, 0.5f, 0.5f));
continue;
}
shadowImg.SetPixelInt(p, ResourceToColor(res));
}
}
}
if (m_displayGotoImage != nullptr)
{
Math::IntPoint size = m_displayGotoImage->GetSize();
for (float x = min.x; x < max.x; x += 1.0f)
{
for (float y = min.y; y < max.y; y += 1.0f)
{
int px = x / 4.0f / 254.0f * size.x;
int py = y / 4.0f / 254.0f * size.y;
shadowImg.SetPixelInt(Math::IntPoint(x-min.x, y-min.y), m_displayGotoImage->GetPixelInt(Math::IntPoint(px, py)));
}
}
}
std::stringstream str; std::stringstream str;
str << "textures/shadow" << std::setfill('0') << std::setw(2) << s << ".png"; str << "textures/shadow" << std::setfill('0') << std::setw(2) << s << ".png";
std::string texName = str.str(); std::string texName = str.str();
@ -5075,4 +5131,57 @@ void CEngine::SetStaticMeshTransparency(int meshHandle, float value)
SetObjectTransparency(objRank, value); SetObjectTransparency(objRank, value);
} }
void CEngine::SetDebugLights(bool debugLights)
{
m_debugLights = debugLights;
}
bool CEngine::GetDebugLights()
{
return m_debugLights;
}
void CEngine::DebugDumpLights()
{
m_debugDumpLights = true;
}
void CEngine::SetDebugResources(bool debugResources)
{
m_debugResources = debugResources;
m_firstGroundSpot = true; // Force a refresh of ground spot textures
UpdateGroundSpotTextures();
}
bool CEngine::GetDebugResources()
{
return m_debugResources;
}
void CEngine::SetDebugGoto(bool debugGoto)
{
m_debugGoto = debugGoto;
if (!m_debugGoto)
{
m_displayGotoImage.reset();
}
}
bool CEngine::GetDebugGoto()
{
return m_debugGoto;
}
void CEngine::AddDebugGotoLine(std::vector<Gfx::VertexCol> line)
{
m_displayGoto.push_back(line);
}
void CEngine::SetDebugGotoBitmap(std::unique_ptr<CImage> debugImage)
{
m_displayGotoImage = std::move(debugImage);
m_firstGroundSpot = true; // Force ground spot texture reload
UpdateGroundSpotTextures();
}
} // namespace Gfx } // namespace Gfx

View File

@ -655,9 +655,6 @@ public:
//! Frees all resources before exit //! Frees all resources before exit
void Destroy(); void Destroy();
//! Resets some states and flushes textures after device was changed (e.g. resoulution changed)
void ResetAfterVideoConfigChanged();
//! Called once per frame, the call is the entry point for rendering //! Called once per frame, the call is the entry point for rendering
void Render(); void Render();
@ -844,7 +841,7 @@ public:
//! Detects the target object that is selected with the mouse //! Detects the target object that is selected with the mouse
/** Returns the rank of the object or -1. */ /** Returns the rank of the object or -1. */
int DetectObject(Math::Point mouse); int DetectObject(Math::Point mouse, Math::Vector& targetPos, bool terrain = false);
//! Creates a shadow for the given object //! Creates a shadow for the given object
void CreateShadowSpot(int objRank); void CreateShadowSpot(int objRank);
@ -1187,7 +1184,23 @@ public:
void ClearDisplayCrashSpheres(); void ClearDisplayCrashSpheres();
void AddDisplayCrashSpheres(const std::vector<Math::Sphere>& crashSpheres); void AddDisplayCrashSpheres(const std::vector<Math::Sphere>& crashSpheres);
void SetDebugLights(bool debugLights);
bool GetDebugLights();
void DebugDumpLights();
void SetDebugResources(bool debugResources);
bool GetDebugResources();
void SetDebugGoto(bool debugGoto);
bool GetDebugGoto();
void AddDebugGotoLine(std::vector<Gfx::VertexCol> line);
void SetDebugGotoBitmap(std::unique_ptr<CImage> debugImage);
protected: protected:
//! Resets some states and flushes textures after device was changed (e.g. resoulution changed)
/** Instead of calling this directly, send EVENT_RESOLUTION_CHANGED event **/
void ResetAfterVideoConfigChanged();
//! Prepares the interface for 3D scene //! Prepares the interface for 3D scene
void Draw3DScene(); void Draw3DScene();
//! Renders shadow map //! Renders shadow map
@ -1249,7 +1262,7 @@ protected:
bool GetBBox2D(int objRank, Math::Point& min, Math::Point& max); bool GetBBox2D(int objRank, Math::Point& min, Math::Point& max);
//! Detects whether the mouse is in a triangle. //! Detects whether the mouse is in a triangle.
bool DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRank, float& dist); bool DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRank, float& dist, Math::Vector& pos);
//! Transforms a 3D point (x, y, z) in 2D space (x, y, -) of the window //! Transforms a 3D point (x, y, z) in 2D space (x, y, -) of the window
/** The coordinated p2D.z gives the distance. */ /** The coordinated p2D.z gives the distance. */
@ -1281,6 +1294,7 @@ protected:
static void WriteScreenShotThread(std::unique_ptr<WriteScreenShotData> data); static void WriteScreenShotThread(std::unique_ptr<WriteScreenShotData> data);
//! Reloads all textures //! Reloads all textures
/** This additionally sends EVENT_RELOAD_TEXTURES to reload all textures not maintained by CEngine **/
void ReloadAllTextures(); void ReloadAllTextures();
protected: protected:
@ -1472,12 +1486,16 @@ protected:
bool m_debugLights; bool m_debugLights;
bool m_debugDumpLights; bool m_debugDumpLights;
bool m_debugCrashSpheres = false; bool m_debugCrashSpheres = false;
bool m_debugResources = false;
bool m_debugGoto = false;
std::string m_timerText; std::string m_timerText;
std::unordered_map<std::string, int> m_staticMeshBaseObjects; std::unordered_map<std::string, int> m_staticMeshBaseObjects;
std::vector<Math::Sphere> m_displayCrashSpheres; std::vector<Math::Sphere> m_displayCrashSpheres;
std::vector<std::vector<VertexCol>> m_displayGoto;
std::unique_ptr<CImage> m_displayGotoImage;
//! Pause the animation updates //! Pause the animation updates
bool m_pause = false; bool m_pause = false;

View File

@ -82,16 +82,24 @@ bool CLightning::EventProcess(const Event &event)
bool CLightning::EventFrame(const Event &event) bool CLightning::EventFrame(const Event &event)
{ {
if (m_terrain == nullptr)
m_terrain = CRobotMain::GetInstancePointer()->GetTerrain();
if (m_camera == nullptr)
m_camera = CRobotMain::GetInstancePointer()->GetCamera();
if (m_sound == nullptr)
m_sound = CApplication::GetInstancePointer()->GetSound();
if (m_engine->GetPause()) return true; if (m_engine->GetPause()) return true;
if (CRobotMain::GetInstancePointer()->GetMovieLock()) return true; if (CRobotMain::GetInstancePointer()->GetMovieLock()) return true;
m_progress += event.rTime*m_speed; m_progress += event.rTime*m_speed;
if (m_phase == LightningPhase::Wait) if (m_phase == LightningPhase::Wait && m_lightningExists)
{ {
if (m_progress >= 1.0f) if (m_progress >= 1.0f)
{ {
m_pos.x = (Math::Rand()-0.5f)*(3200.0f-200.0f); m_pos.x = (Math::Rand()-0.5f)*(3200.0f-200.0f);
m_pos.z = (Math::Rand()-0.5f)*(3200.0f-200.0f); m_pos.z = (Math::Rand()-0.5f)*(3200.0f-200.0f);
m_pos.y = 0.0f; m_pos.y = 0.0f;
@ -127,21 +135,7 @@ bool CLightning::EventFrame(const Event &event)
} }
} }
Math::Vector eye = m_engine->GetEyePt(); StrikeAtPos(m_pos);
float dist = Math::Distance(m_pos, eye);
float deep = m_engine->GetDeepView();
if (dist < deep)
{
Math::Vector pos = eye+((m_pos-eye)*0.2f); // like so close!
m_sound->Play(SOUND_BLITZ, pos);
m_camera->StartOver(CAM_OVER_EFFECT_LIGHTNING, m_pos, 1.0f);
m_phase = LightningPhase::Flash;
m_progress = 0.0f;
m_speed = 1.0f;
}
} }
} }
@ -193,15 +187,6 @@ bool CLightning::Create(float sleep, float delay, float magnetic)
m_progress = 0.0f; m_progress = 0.0f;
m_speed = 1.0f / m_sleep; m_speed = 1.0f / m_sleep;
if (m_terrain == nullptr)
m_terrain = CRobotMain::GetInstancePointer()->GetTerrain();
if (m_camera == nullptr)
m_camera = CRobotMain::GetInstancePointer()->GetCamera();
if (m_sound == nullptr)
m_sound = CApplication::GetInstancePointer()->GetSound();
return false; return false;
} }
@ -233,7 +218,6 @@ bool CLightning::SetStatus(float sleep, float delay, float magnetic, float progr
void CLightning::Draw() void CLightning::Draw()
{ {
if (!m_lightningExists) return;
if (m_phase != LightningPhase::Flash) return; if (m_phase != LightningPhase::Flash) return;
CDevice* device = m_engine->GetDevice(); CDevice* device = m_engine->GetDevice();
@ -368,4 +352,25 @@ CObject* CLightning::SearchObject(Math::Vector pos)
} }
void CLightning::StrikeAtPos(Math::Vector pos)
{
m_pos = pos;
Math::Vector eye = m_engine->GetEyePt();
float dist = Math::Distance(m_pos, eye);
float deep = m_engine->GetDeepView();
if (dist < deep)
{
Math::Vector pos = eye+((m_pos-eye)*0.2f); // like so close!
m_sound->Play(SOUND_BLITZ, pos);
m_camera->StartOver(CAM_OVER_EFFECT_LIGHTNING, m_pos, 1.0f);
m_phase = LightningPhase::Flash;
m_progress = 0.0f;
m_speed = 1.0f;
}
}
} // namespace Gfx } // namespace Gfx

View File

@ -75,6 +75,9 @@ public:
//! Draws lightning //! Draws lightning
void Draw(); void Draw();
//! Shoots lightning strike at given position
void StrikeAtPos(Math::Vector pos);
protected: protected:
//! Updates lightning //! Updates lightning
bool EventFrame(const Event &event); bool EventFrame(const Event &event);

View File

@ -647,13 +647,13 @@ bool CParticle::CheckChannel(int &channel)
if (!m_particle[channel].used) if (!m_particle[channel].used)
{ {
GetLogger()->Error("CheckChannel used=false !\n"); GetLogger()->Error("CParticle::CheckChannel used=false !\n");
return false; return false;
} }
if (m_particle[channel].uniqueStamp != uniqueStamp) if (m_particle[channel].uniqueStamp != uniqueStamp)
{ {
GetLogger()->Error("CheckChannel uniqueStamp !\n"); GetLogger()->Error("CParticle::CheckChannel uniqueStamp !\n");
return false; return false;
} }
@ -3724,12 +3724,4 @@ Color CParticle::GetFogColor(Math::Vector pos)
return result; return result;
} }
bool CParticle::WriteWheelTrace(const char *filename, int width, int height,
Math::Vector dl, Math::Vector ur)
{
// TODO: stub!
GetLogger()->Trace("CParticle::WriteWheelTrace(): stub!\n");
return true;
}
} // namespace Gfx } // namespace Gfx

View File

@ -291,9 +291,6 @@ public:
//! Draws all the particles //! Draws all the particles
void DrawParticle(int sheet); void DrawParticle(int sheet);
//! Writes a file containing all the tire tracks
bool WriteWheelTrace(const char *filename, int width, int height, Math::Vector dl, Math::Vector ur);
protected: protected:
//! Removes a particle of given rank //! Removes a particle of given rank
void DeleteRank(int rank); void DeleteRank(int rank);

View File

@ -192,6 +192,22 @@ void CTerrain::AddMaterial(int id, const std::string& texName, const Math::Point
} }
// values from original bitmap palette
const std::map<TerrainRes, Gfx::IntColor> RESOURCE_PALETTE = {
{TR_STONE, Gfx::IntColor(255, 0, 0)},
{TR_URANIUM, Gfx::IntColor(255, 255, 0)},
{TR_POWER, Gfx::IntColor( 0, 255, 0)},
{TR_KEY_A, Gfx::IntColor( 0, 204, 0)},
{TR_KEY_B, Gfx::IntColor( 51, 204, 0)},
{TR_KEY_C, Gfx::IntColor(102, 204, 0)},
{TR_KEY_D, Gfx::IntColor(153, 204, 0)}
};
Gfx::IntColor ResourceToColor(TerrainRes res)
{
return RESOURCE_PALETTE.at(res);
}
/** /**
* The image must be 24 bits/pixel and grayscale and dx x dy in size * The image must be 24 bits/pixel and grayscale and dx x dy in size
* with dx = dy = (mosaic*brick)+1 */ * with dx = dy = (mosaic*brick)+1 */
@ -224,21 +240,11 @@ bool CTerrain::LoadResources(const std::string& fileName)
Gfx::IntColor pixel = img.GetPixelInt(Math::IntPoint(x, size - y - 1)); Gfx::IntColor pixel = img.GetPixelInt(Math::IntPoint(x, size - y - 1));
TerrainRes res = TR_NULL; TerrainRes res = TR_NULL;
// values from original bitmap palette for (const auto& it : RESOURCE_PALETTE)
if (pixel.r == 255 && pixel.g == 0 && pixel.b == 0) {
res = TR_STONE; if (pixel.r == it.second.r && pixel.g == it.second.g && pixel.b == it.second.b)
else if (pixel.r == 255 && pixel.g == 255 && pixel.b == 0) res = it.first;
res = TR_URANIUM; }
else if (pixel.r == 0 && pixel.g == 255 && pixel.b == 0)
res = TR_POWER;
else if (pixel.r == 0 && pixel.g == 204 && pixel.b == 0)
res = TR_KEY_A;
else if (pixel.r == 51 && pixel.g == 204 && pixel.b == 0)
res = TR_KEY_B;
else if (pixel.r == 102 && pixel.g == 204 && pixel.b == 0)
res = TR_KEY_C;
else if (pixel.r == 153 && pixel.g == 204 && pixel.b == 0)
res = TR_KEY_D;
m_resources[x+size*y] = static_cast<unsigned char>(res); m_resources[x+size*y] = static_cast<unsigned char>(res);
} }

View File

@ -69,6 +69,8 @@ enum TerrainRes
TR_KEY_D = 7 TR_KEY_D = 7
//@} //@}
}; };
//! Converts TerrainRes to color
Gfx::IntColor ResourceToColor(TerrainRes res);
/** /**
* \class CTerrain * \class CTerrain

View File

@ -86,6 +86,7 @@
#include "sound/sound.h" #include "sound/sound.h"
#include "ui/debug_menu.h"
#include "ui/displayinfo.h" #include "ui/displayinfo.h"
#include "ui/displaytext.h" #include "ui/displaytext.h"
#include "ui/maindialog.h" #include "ui/maindialog.h"
@ -116,6 +117,12 @@
const float UNIT = 4.0f; // default for g_unit const float UNIT = 4.0f; // default for g_unit
float g_unit; // conversion factor float g_unit; // conversion factor
// Reference colors used when recoloring textures, see ChangeColor()
const Gfx::Color COLOR_REF_BOT = Gfx::Color( 10.0f/256.0f, 166.0f/256.0f, 254.0f/256.0f); // blue
const Gfx::Color COLOR_REF_ALIEN = Gfx::Color(135.0f/256.0f, 170.0f/256.0f, 13.0f/256.0f); // green
const Gfx::Color COLOR_REF_GREEN = Gfx::Color(135.0f/256.0f, 170.0f/256.0f, 13.0f/256.0f); // green
const Gfx::Color COLOR_REF_WATER = Gfx::Color( 25.0f/256.0f, 255.0f/256.0f, 240.0f/256.0f); // cyan
template<> CRobotMain* CSingleton<CRobotMain>::m_instance = nullptr; template<> CRobotMain* CSingleton<CRobotMain>::m_instance = nullptr;
@ -156,6 +163,8 @@ CRobotMain::CRobotMain()
m_modelManager.get(), m_modelManager.get(),
m_particle); m_particle);
m_debugMenu = MakeUnique<Ui::CDebugMenu>(this, m_engine, m_objMan.get(), m_sound);
m_time = 0.0f; m_time = 0.0f;
m_gameTime = 0.0f; m_gameTime = 0.0f;
m_gameTimeAbsolute = 0.0f; m_gameTimeAbsolute = 0.0f;
@ -225,8 +234,6 @@ CRobotMain::CRobotMain()
m_globalMagnifyDamage = 1.0f; m_globalMagnifyDamage = 1.0f;
m_exitAfterMission = false;
m_autosave = true; m_autosave = true;
m_autosaveInterval = 5; m_autosaveInterval = 5;
m_autosaveSlots = 3; m_autosaveSlots = 3;
@ -303,30 +310,6 @@ CPauseManager* CRobotMain::GetPauseManager()
return m_pause.get(); return m_pause.get();
} }
void CRobotMain::ResetAfterVideoConfigChanged()
{
// Recreate the interface (needed if the aspect ratio changes)
// TODO: This can sometimes cause unwanted side effects, like hidden windows reappearing. To be fixed during CEGUI refactoring.
m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE));
CreateShortcuts();
}
void CRobotMain::ReloadAllTextures()
{
if (m_phase == PHASE_SETUPds ||
m_phase == PHASE_SETUPgs ||
m_phase == PHASE_SETUPps ||
m_phase == PHASE_SETUPcs ||
m_phase == PHASE_SETUPss ||
m_phase == PHASE_SIMUL ||
m_phase == PHASE_WIN ||
m_phase == PHASE_LOST)
{
ChangeColor();
UpdateMap();
}
}
std::string PhaseToString(Phase phase) std::string PhaseToString(Phase phase)
{ {
if (phase == PHASE_WELCOME1) return "PHASE_WELCOME1"; if (phase == PHASE_WELCOME1) return "PHASE_WELCOME1";
@ -384,6 +367,13 @@ void CRobotMain::ChangePhase(Phase phase)
bool resetWorld = false; bool resetWorld = false;
if ((IsPhaseWithWorld(m_phase) || IsPhaseWithWorld(phase)) && !IsInSimulationConfigPhase(m_phase) && !IsInSimulationConfigPhase(phase)) if ((IsPhaseWithWorld(m_phase) || IsPhaseWithWorld(phase)) && !IsInSimulationConfigPhase(m_phase) && !IsInSimulationConfigPhase(phase))
{ {
if (IsPhaseWithWorld(m_phase) && !IsPhaseWithWorld(phase) && m_exitAfterMission)
{
GetLogger()->Info("Mission finished in single mission mode, exiting\n");
m_eventQueue->AddEvent(Event(EVENT_QUIT));
return;
}
GetLogger()->Info("Reseting world on phase change...\n"); GetLogger()->Info("Reseting world on phase change...\n");
resetWorld = true; resetWorld = true;
} }
@ -663,6 +653,12 @@ Phase CRobotMain::GetPhase()
bool CRobotMain::ProcessEvent(Event &event) bool CRobotMain::ProcessEvent(Event &event)
{ {
if (!m_ui->EventProcess(event)) return false; if (!m_ui->EventProcess(event)) return false;
if (m_phase == PHASE_SIMUL)
{
if (!m_editFull)
m_camera->EventProcess(event);
}
if (!m_debugMenu->EventProcess(event)) return false;
if (event.type == EVENT_FRAME) if (event.type == EVENT_FRAME)
{ {
@ -693,6 +689,23 @@ bool CRobotMain::ProcessEvent(Event &event)
return EventFrame(event); return EventFrame(event);
} }
if (event.type == EVENT_RELOAD_TEXTURES)
{
if (IsPhaseWithWorld(m_phase))
{
ChangeColor();
UpdateMap();
}
}
if (event.type == EVENT_RESOLUTION_CHANGED)
{
// Recreate the interface (needed if the aspect ratio changes)
// TODO: This can sometimes cause unwanted side effects, like hidden windows reappearing. To be fixed during CEGUI refactoring.
m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE));
CreateShortcuts();
}
if (event.type == EVENT_FOCUS_LOST) if (event.type == EVENT_FOCUS_LOST)
{ {
GetLogger()->Trace("Window unfocused\n"); GetLogger()->Trace("Window unfocused\n");
@ -759,6 +772,15 @@ bool CRobotMain::ProcessEvent(Event &event)
} }
return false; return false;
} }
if (IsPhaseWithWorld(m_phase))
{
if (data->key == KEY(F11))
{
m_debugMenu->ToggleInterface();
return false;
}
}
} }
if (event.type == EVENT_KEY_DOWN && if (event.type == EVENT_KEY_DOWN &&
@ -826,9 +848,6 @@ bool CRobotMain::ProcessEvent(Event &event)
// Simulation phase of the game // Simulation phase of the game
if (m_phase == PHASE_SIMUL) if (m_phase == PHASE_SIMUL)
{ {
if (!m_editFull)
m_camera->EventProcess(event);
switch (event.type) switch (event.type)
{ {
case EVENT_KEY_DOWN: case EVENT_KEY_DOWN:
@ -837,11 +856,6 @@ bool CRobotMain::ProcessEvent(Event &event)
KeyCamera(event.type, data->slot); KeyCamera(event.type, data->slot);
HiliteClear(); HiliteClear();
if (data->key == KEY(F11))
{
m_particle->WriteWheelTrace("Savegame/t.png", 256, 256, Math::Vector(16.0f, 0.0f, -368.0f), Math::Vector(140.0f, 0.0f, -248.0f));
return false;
}
if (m_editLock) // current edition? if (m_editLock) // current edition?
{ {
if (data->slot == INPUT_SLOT_HELP) if (data->slot == INPUT_SLOT_HELP)
@ -1163,25 +1177,25 @@ bool CRobotMain::ProcessEvent(Event &event)
//! Executes a command //! Executes a command
void CRobotMain::ExecuteCmd(char *cmd) void CRobotMain::ExecuteCmd(const std::string& cmd)
{ {
if (cmd[0] == 0) return; if (cmd.empty()) return;
if (m_phase == PHASE_SIMUL) if (m_phase == PHASE_SIMUL)
{ {
if (strcmp(cmd, "winmission") == 0) if (cmd == "winmission")
m_eventQueue->AddEvent(Event(EVENT_WIN)); m_eventQueue->AddEvent(Event(EVENT_WIN));
if (strcmp(cmd, "lostmission") == 0) if (cmd == "lostmission")
m_eventQueue->AddEvent(Event(EVENT_LOST)); m_eventQueue->AddEvent(Event(EVENT_LOST));
if (strcmp(cmd, "trainerpilot") == 0) if (cmd == "trainerpilot")
{ {
m_trainerPilot = !m_trainerPilot; m_trainerPilot = !m_trainerPilot;
return; return;
} }
if (strcmp(cmd, "fly") == 0) if (cmd == "fly")
{ {
m_researchDone[0] |= RESEARCH_FLY; m_researchDone[0] |= RESEARCH_FLY;
@ -1189,7 +1203,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
return; return;
} }
if (strcmp(cmd, "allresearch") == 0) if (cmd == "allresearch")
{ {
m_researchDone[0] = -1; // all research are done m_researchDone[0] = -1; // all research are done
@ -1197,7 +1211,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
return; return;
} }
if (strcmp(cmd, "allbuildings") == 0) if (cmd == "allbuildings")
{ {
m_build = -1; // all buildings are available m_build = -1; // all buildings are available
@ -1205,7 +1219,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
return; return;
} }
if (strcmp(cmd, "all") == 0) if (cmd == "all")
{ {
m_researchDone[0] = -1; // all research are done m_researchDone[0] = -1; // all research are done
m_build = -1; // all buildings are available m_build = -1; // all buildings are available
@ -1214,13 +1228,13 @@ void CRobotMain::ExecuteCmd(char *cmd)
return; return;
} }
if (strcmp(cmd, "nolimit") == 0) if (cmd == "nolimit")
{ {
m_terrain->SetFlyingMaxHeight(280.0f); m_terrain->SetFlyingMaxHeight(280.0f);
return; return;
} }
if (strcmp(cmd, "controller") == 0) if (cmd == "controller")
{ {
if (m_controller != nullptr) if (m_controller != nullptr)
{ {
@ -1238,7 +1252,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
return; return;
} }
if (strcmp(cmd, "photo1") == 0) if (cmd == "photo1")
{ {
if (m_freePhotoPause == nullptr) if (m_freePhotoPause == nullptr)
{ {
@ -1254,7 +1268,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
return; return;
} }
if (strcmp(cmd, "photo2") == 0) if (cmd == "photo2")
{ {
if (m_freePhotoPause == nullptr) if (m_freePhotoPause == nullptr)
{ {
@ -1276,26 +1290,26 @@ void CRobotMain::ExecuteCmd(char *cmd)
} }
int camtype; int camtype;
if (sscanf(cmd, "camtype %d", &camtype) > 0) if (sscanf(cmd.c_str(), "camtype %d", &camtype) > 0)
{ {
m_camera->SetType(static_cast<Gfx::CameraType>(camtype)); m_camera->SetType(static_cast<Gfx::CameraType>(camtype));
return; return;
} }
float camspeed; float camspeed;
if (sscanf(cmd, "camspeed %f", &camspeed) > 0) if (sscanf(cmd.c_str(), "camspeed %f", &camspeed) > 0)
{ {
m_camera->SetCameraSpeed(camspeed); m_camera->SetCameraSpeed(camspeed);
return; return;
} }
if (strcmp(cmd, "freecam") == 0) if (cmd == "freecam")
{ {
m_camera->SetType(Gfx::CAM_TYPE_FREE); m_camera->SetType(Gfx::CAM_TYPE_FREE);
return; return;
} }
if (strcmp(cmd, "noclip") == 0) if (cmd == "noclip")
{ {
CObject* object = GetSelect(); CObject* object = GetSelect();
if (object != nullptr) if (object != nullptr)
@ -1303,7 +1317,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
return; return;
} }
if (strcmp(cmd, "clip") == 0) if (cmd == "clip")
{ {
CObject* object = GetSelect(); CObject* object = GetSelect();
if (object != nullptr) if (object != nullptr)
@ -1311,7 +1325,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
return; return;
} }
if (strcmp(cmd, "addhusky") == 0) if (cmd == "addhusky")
{ {
CObject* object = GetSelect(); CObject* object = GetSelect();
if (object != nullptr && object->Implements(ObjectInterfaceType::Shielded)) if (object != nullptr && object->Implements(ObjectInterfaceType::Shielded))
@ -1319,7 +1333,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
return; return;
} }
if (strcmp(cmd, "addfreezer") == 0) if (cmd == "addfreezer")
{ {
CObject* object = GetSelect(); CObject* object = GetSelect();
if (object != nullptr && object->Implements(ObjectInterfaceType::JetFlying)) if (object != nullptr && object->Implements(ObjectInterfaceType::JetFlying))
@ -1327,7 +1341,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
return; return;
} }
if (strcmp(cmd, "\155\157\157") == 0) if (cmd == "\155\157\157")
{ {
// VGhpcyBpcyBlYXN0ZXItZWdnIGFuZCBzbyBpdCBzaG91bGQgYmUgb2JmdXNjYXRlZCEgRG8gbm90 // VGhpcyBpcyBlYXN0ZXItZWdnIGFuZCBzbyBpdCBzaG91bGQgYmUgb2JmdXNjYXRlZCEgRG8gbm90
// IGNsZWFuLXVwIHRoaXMgY29kZSEK // IGNsZWFuLXVwIHRoaXMgY29kZSEK
@ -1341,7 +1355,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
GetLogger()->Info(" \x20\x20 \x7C\x7C\x20\x20\x20\x20 ||\n"); GetLogger()->Info(" \x20\x20 \x7C\x7C\x20\x20\x20\x20 ||\n");
} }
if (strcmp(cmd, "fullpower") == 0) if (cmd == "fullpower")
{ {
CObject* object = GetSelect(); CObject* object = GetSelect();
if (object != nullptr) if (object != nullptr)
@ -1362,7 +1376,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
return; return;
} }
if (strcmp(cmd, "fullenergy") == 0) if (cmd == "fullenergy")
{ {
CObject* object = GetSelect(); CObject* object = GetSelect();
@ -1378,7 +1392,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
return; return;
} }
if (strcmp(cmd, "fullshield") == 0) if (cmd == "fullshield")
{ {
CObject* object = GetSelect(); CObject* object = GetSelect();
if (object != nullptr && object->Implements(ObjectInterfaceType::Shielded)) if (object != nullptr && object->Implements(ObjectInterfaceType::Shielded))
@ -1386,7 +1400,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
return; return;
} }
if (strcmp(cmd, "fullrange") == 0) if (cmd == "fullrange")
{ {
CObject* object = GetSelect(); CObject* object = GetSelect();
if (object != nullptr) if (object != nullptr)
@ -1396,19 +1410,9 @@ void CRobotMain::ExecuteCmd(char *cmd)
} }
return; return;
} }
if (strcmp(cmd, "debugcrashon") == 0)
{
m_debugCrashSpheres = true;
return;
}
if (strcmp(cmd, "debugcrashoff") == 0)
{
m_debugCrashSpheres = false;
return;
}
} }
if (strcmp(cmd, "debugmode") == 0) if (cmd == "debugmode")
{ {
if (m_app->IsDebugModeActive(DEBUG_ALL)) if (m_app->IsDebugModeActive(DEBUG_ALL))
{ {
@ -1421,46 +1425,46 @@ void CRobotMain::ExecuteCmd(char *cmd)
return; return;
} }
if (strcmp(cmd, "showstat") == 0) if (cmd == "showstat")
{ {
m_engine->SetShowStats(!m_engine->GetShowStats()); m_engine->SetShowStats(!m_engine->GetShowStats());
return; return;
} }
if (strcmp(cmd, "invui") == 0) if (cmd == "invui")
{ {
m_engine->SetRenderInterface(!m_engine->GetRenderInterface()); m_engine->SetRenderInterface(!m_engine->GetRenderInterface());
return; return;
} }
if (strcmp(cmd, "selectinsect") == 0) if (cmd == "selectinsect")
{ {
m_selectInsect = !m_selectInsect; m_selectInsect = !m_selectInsect;
return; return;
} }
if (strcmp(cmd, "showsoluce") == 0) if (cmd == "showsoluce")
{ {
m_showSoluce = !m_showSoluce; m_showSoluce = !m_showSoluce;
m_ui->ShowSoluceUpdate(); m_ui->ShowSoluceUpdate();
return; return;
} }
if (strcmp(cmd, "allmission") == 0) if (cmd == "allmission")
{ {
m_showAll = !m_showAll; m_showAll = !m_showAll;
m_ui->AllMissionUpdate(); m_ui->AllMissionUpdate();
return; return;
} }
if (strcmp(cmd, "invradar") == 0) if (cmd == "invradar")
{ {
m_cheatRadar = !m_cheatRadar; m_cheatRadar = !m_cheatRadar;
return; return;
} }
float speed; float speed;
if (sscanf(cmd, "speed %f", &speed) > 0) if (sscanf(cmd.c_str(), "speed %f", &speed) > 0)
{ {
SetSpeed(speed); SetSpeed(speed);
UpdateSpeedLabel(); UpdateSpeedLabel();
@ -1989,7 +1993,8 @@ CObject* CRobotMain::GetSelect()
//! Detects the object aimed by the mouse //! Detects the object aimed by the mouse
CObject* CRobotMain::DetectObject(Math::Point pos) CObject* CRobotMain::DetectObject(Math::Point pos)
{ {
int objRank = m_engine->DetectObject(pos); Math::Vector p;
int objRank = m_engine->DetectObject(pos, p);
for (CObject* obj : m_objMan->GetAllObjects()) for (CObject* obj : m_objMan->GetAllObjects())
{ {
@ -2830,30 +2835,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
m_controller = nullptr; m_controller = nullptr;
m_colorRefBot.r = 10.0f/256.0f;
m_colorRefBot.g = 166.0f/256.0f;
m_colorRefBot.b = 254.0f/256.0f; // blue
m_colorRefBot.a = 0.0f;
m_colorNewBot.clear(); m_colorNewBot.clear();
m_colorNewBot[0] = m_colorRefBot; m_colorNewBot[0] = COLOR_REF_BOT;
m_colorNewAlien = COLOR_REF_ALIEN;
m_colorRefAlien.r = 135.0f/256.0f; m_colorNewGreen = COLOR_REF_GREEN;
m_colorRefAlien.g = 170.0f/256.0f; m_colorNewWater = COLOR_REF_WATER;
m_colorRefAlien.b = 13.0f/256.0f; // green
m_colorRefAlien.a = 0.0f;
m_colorNewAlien = m_colorRefAlien;
m_colorRefGreen.r = 135.0f/256.0f;
m_colorRefGreen.g = 170.0f/256.0f;
m_colorRefGreen.b = 13.0f/256.0f; // green
m_colorRefGreen.a = 0.0f;
m_colorNewGreen = m_colorRefGreen;
m_colorRefWater.r = 25.0f/256.0f;
m_colorRefWater.g = 255.0f/256.0f;
m_colorRefWater.b = 240.0f/256.0f; // cyan
m_colorRefWater.a = 0.0f;
m_colorNewWater = m_colorRefWater;
m_engine->SetAmbientColor(Gfx::Color(0.5f, 0.5f, 0.5f, 0.5f), 0); m_engine->SetAmbientColor(Gfx::Color(0.5f, 0.5f, 0.5f, 0.5f), 0);
m_engine->SetAmbientColor(Gfx::Color(0.5f, 0.5f, 0.5f, 0.5f), 1); m_engine->SetAmbientColor(Gfx::Color(0.5f, 0.5f, 0.5f, 0.5f), 1);
@ -3256,7 +3242,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
line->GetParam("level")->AsFloat(100.0f)*g_unit, line->GetParam("level")->AsFloat(100.0f)*g_unit,
line->GetParam("glint")->AsFloat(1.0f), line->GetParam("glint")->AsFloat(1.0f),
pos); pos);
m_colorNewWater = line->GetParam("color")->AsColor(m_colorRefWater); m_colorNewWater = line->GetParam("color")->AsColor(COLOR_REF_WATER);
m_colorShiftWater = line->GetParam("brightness")->AsFloat(0.0f); m_colorShiftWater = line->GetParam("brightness")->AsFloat(0.0f);
continue; continue;
} }
@ -3965,19 +3951,19 @@ void CRobotMain::ChangeColor()
std::string teamStr = StrUtils::ToString<int>(team); std::string teamStr = StrUtils::ToString<int>(team);
if(team == 0) teamStr = ""; if(team == 0) teamStr = "";
m_engine->ChangeTextureColor("textures/objects/base1.png"+teamStr, "textures/objects/base1.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); m_engine->ChangeTextureColor("textures/objects/base1.png"+teamStr, "textures/objects/base1.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true);
m_engine->ChangeTextureColor("textures/objects/convert.png"+teamStr, "textures/objects/convert.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); m_engine->ChangeTextureColor("textures/objects/convert.png"+teamStr, "textures/objects/convert.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true);
m_engine->ChangeTextureColor("textures/objects/derrick.png"+teamStr, "textures/objects/derrick.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); m_engine->ChangeTextureColor("textures/objects/derrick.png"+teamStr, "textures/objects/derrick.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true);
m_engine->ChangeTextureColor("textures/objects/factory.png"+teamStr, "textures/objects/factory.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); m_engine->ChangeTextureColor("textures/objects/factory.png"+teamStr, "textures/objects/factory.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true);
m_engine->ChangeTextureColor("textures/objects/lemt.png"+teamStr, "textures/objects/lemt.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); m_engine->ChangeTextureColor("textures/objects/lemt.png"+teamStr, "textures/objects/lemt.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true);
m_engine->ChangeTextureColor("textures/objects/roller.png"+teamStr, "textures/objects/roller.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); m_engine->ChangeTextureColor("textures/objects/roller.png"+teamStr, "textures/objects/roller.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true);
m_engine->ChangeTextureColor("textures/objects/search.png"+teamStr, "textures/objects/search.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); m_engine->ChangeTextureColor("textures/objects/search.png"+teamStr, "textures/objects/search.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true);
exclu[0] = Math::Point( 0.0f/256.0f, 160.0f/256.0f); exclu[0] = Math::Point( 0.0f/256.0f, 160.0f/256.0f);
exclu[1] = Math::Point(256.0f/256.0f, 256.0f/256.0f); // pencils exclu[1] = Math::Point(256.0f/256.0f, 256.0f/256.0f); // pencils
exclu[2] = Math::Point(0.0f, 0.0f); exclu[2] = Math::Point(0.0f, 0.0f);
exclu[3] = Math::Point(0.0f, 0.0f); // terminator exclu[3] = Math::Point(0.0f, 0.0f); // terminator
m_engine->ChangeTextureColor("textures/objects/drawer.png"+teamStr, "textures/objects/drawer.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, exclu, 0, true); m_engine->ChangeTextureColor("textures/objects/drawer.png"+teamStr, "textures/objects/drawer.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, exclu, 0, true);
exclu[0] = Math::Point(237.0f/256.0f, 176.0f/256.0f); exclu[0] = Math::Point(237.0f/256.0f, 176.0f/256.0f);
exclu[1] = Math::Point(256.0f/256.0f, 220.0f/256.0f); // blue canister exclu[1] = Math::Point(256.0f/256.0f, 220.0f/256.0f); // blue canister
@ -3985,7 +3971,7 @@ void CRobotMain::ChangeColor()
exclu[3] = Math::Point(130.0f/256.0f, 214.0f/256.0f); // safe location exclu[3] = Math::Point(130.0f/256.0f, 214.0f/256.0f); // safe location
exclu[4] = Math::Point(0.0f, 0.0f); exclu[4] = Math::Point(0.0f, 0.0f);
exclu[5] = Math::Point(0.0f, 0.0f); // terminator exclu[5] = Math::Point(0.0f, 0.0f); // terminator
m_engine->ChangeTextureColor("textures/objects/subm.png"+teamStr, "textures/objects/subm.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, exclu, 0, true); m_engine->ChangeTextureColor("textures/objects/subm.png"+teamStr, "textures/objects/subm.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, exclu, 0, true);
} }
// AlienColor // AlienColor
@ -3994,23 +3980,23 @@ void CRobotMain::ChangeColor()
exclu[1] = Math::Point(256.0f/256.0f, 256.0f/256.0f); // SatCom exclu[1] = Math::Point(256.0f/256.0f, 256.0f/256.0f); // SatCom
exclu[2] = Math::Point(0.0f, 0.0f); exclu[2] = Math::Point(0.0f, 0.0f);
exclu[3] = Math::Point(0.0f, 0.0f); // terminator exclu[3] = Math::Point(0.0f, 0.0f); // terminator
m_engine->ChangeTextureColor("textures/objects/ant.png", m_colorRefAlien, m_colorNewAlien, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti, exclu); m_engine->ChangeTextureColor("textures/objects/ant.png", COLOR_REF_ALIEN, m_colorNewAlien, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti, exclu);
m_engine->ChangeTextureColor("textures/objects/mother.png", m_colorRefAlien, m_colorNewAlien, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti); m_engine->ChangeTextureColor("textures/objects/mother.png", COLOR_REF_ALIEN, m_colorNewAlien, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti);
// GreeneryColor // GreeneryColor
m_engine->ChangeTextureColor("textures/objects/plant.png", m_colorRefGreen, m_colorNewGreen, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti); m_engine->ChangeTextureColor("textures/objects/plant.png", COLOR_REF_GREEN, m_colorNewGreen, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti);
// water color // water color
// PARTIPLOUF0 and PARTIDROP : // PARTIPLOUF0 and PARTIDROP :
ts = Math::Point(0.500f, 0.500f); ts = Math::Point(0.500f, 0.500f);
ti = Math::Point(0.875f, 0.750f); ti = Math::Point(0.875f, 0.750f);
m_engine->ChangeTextureColor("textures/effect00.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, nullptr, m_colorShiftWater, true); m_engine->ChangeTextureColor("textures/effect00.png", COLOR_REF_WATER, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, nullptr, m_colorShiftWater, true);
// PARTIFLIC : // PARTIFLIC :
ts = Math::Point(0.00f, 0.75f); ts = Math::Point(0.00f, 0.75f);
ti = Math::Point(0.25f, 1.00f); ti = Math::Point(0.25f, 1.00f);
m_engine->ChangeTextureColor("textures/effect02.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, nullptr, m_colorShiftWater, true); m_engine->ChangeTextureColor("textures/effect02.png", COLOR_REF_WATER, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, nullptr, m_colorShiftWater, true);
} }
//! Calculates the distance to the nearest object //! Calculates the distance to the nearest object
@ -5125,8 +5111,6 @@ Error CRobotMain::CheckEndMission(bool frame)
m_missionTimerEnabled = m_missionTimerStarted = false; m_missionTimerEnabled = m_missionTimerStarted = false;
m_winDelay = m_endTakeWinDelay; // wins in two seconds m_winDelay = m_endTakeWinDelay; // wins in two seconds
m_lostDelay = 0.0f; m_lostDelay = 0.0f;
if (m_exitAfterMission)
m_eventQueue->AddEvent(Event(EVENT_QUIT));
m_displayText->SetEnable(false); m_displayText->SetEnable(false);
} }
m_missionResult = ERR_OK; m_missionResult = ERR_OK;
@ -5159,8 +5143,6 @@ Error CRobotMain::CheckEndMission(bool frame)
} }
m_missionTimerEnabled = m_missionTimerStarted = false; m_missionTimerEnabled = m_missionTimerStarted = false;
m_displayText->SetEnable(false); m_displayText->SetEnable(false);
if (m_exitAfterMission)
m_eventQueue->AddEvent(Event(EVENT_QUIT));
return INFO_LOSTq; return INFO_LOSTq;
} }
@ -5174,8 +5156,6 @@ Error CRobotMain::CheckEndMission(bool frame)
} }
m_missionTimerEnabled = m_missionTimerStarted = false; m_missionTimerEnabled = m_missionTimerStarted = false;
m_displayText->SetEnable(false); m_displayText->SetEnable(false);
if (m_exitAfterMission)
m_eventQueue->AddEvent(Event(EVENT_QUIT));
return INFO_LOST; return INFO_LOST;
} }
@ -5187,8 +5167,6 @@ Error CRobotMain::CheckEndMission(bool frame)
m_lostDelay = 0.0f; m_lostDelay = 0.0f;
m_missionTimerEnabled = m_missionTimerStarted = false; m_missionTimerEnabled = m_missionTimerStarted = false;
m_displayText->SetEnable(false); m_displayText->SetEnable(false);
if (m_exitAfterMission)
m_eventQueue->AddEvent(Event(EVENT_QUIT));
return ERR_OK; // mission ended return ERR_OK; // mission ended
} }
@ -5214,8 +5192,6 @@ Error CRobotMain::CheckEndMission(bool frame)
m_winDelay = m_endTakeWinDelay; // wins in two seconds m_winDelay = m_endTakeWinDelay; // wins in two seconds
m_lostDelay = 0.0f; m_lostDelay = 0.0f;
} }
if (m_exitAfterMission)
m_eventQueue->AddEvent(Event(EVENT_QUIT));
m_displayText->SetEnable(false); m_displayText->SetEnable(false);
return ERR_OK; // mission ended return ERR_OK; // mission ended
} }
@ -6032,3 +6008,13 @@ void CRobotMain::UpdateDebugCrashSpheres()
} }
} }
} }
void CRobotMain::SetDebugCrashSpheres(bool draw)
{
m_debugCrashSpheres = draw;
}
bool CRobotMain::GetDebugCrashSpheres()
{
return m_debugCrashSpheres;
}

View File

@ -113,6 +113,7 @@ class CMainMap;
class CInterface; class CInterface;
class CDisplayText; class CDisplayText;
class CDisplayInfo; class CDisplayInfo;
class CDebugMenu;
} }
struct NewScriptName struct NewScriptName
@ -161,9 +162,6 @@ public:
Ui::CDisplayText* GetDisplayText(); Ui::CDisplayText* GetDisplayText();
CPauseManager* GetPauseManager(); CPauseManager* GetPauseManager();
void ResetAfterVideoConfigChanged();
void ReloadAllTextures();
void ChangePhase(Phase phase); void ChangePhase(Phase phase);
bool ProcessEvent(Event &event); bool ProcessEvent(Event &event);
Phase GetPhase(); Phase GetPhase();
@ -364,6 +362,10 @@ public:
bool IsSelectable(CObject* obj); bool IsSelectable(CObject* obj);
void SetDebugCrashSpheres(bool draw);
bool GetDebugCrashSpheres();
protected: protected:
bool EventFrame(const Event &event); bool EventFrame(const Event &event);
bool EventObject(const Event &event); bool EventObject(const Event &event);
@ -395,7 +397,7 @@ protected:
void StartDisplayVisit(EventType event); void StartDisplayVisit(EventType event);
void FrameVisit(float rTime); void FrameVisit(float rTime);
void StopDisplayVisit(); void StopDisplayVisit();
void ExecuteCmd(char *cmd); void ExecuteCmd(const std::string& cmd);
void UpdateSpeedLabel(); void UpdateSpeedLabel();
int AutosaveRotate(bool freeOne); int AutosaveRotate(bool freeOne);
@ -435,6 +437,7 @@ protected:
std::unique_ptr<Ui::CInterface> m_interface; std::unique_ptr<Ui::CInterface> m_interface;
std::unique_ptr<Ui::CDisplayInfo> m_displayInfo; std::unique_ptr<Ui::CDisplayInfo> m_displayInfo;
std::unique_ptr<Ui::CDisplayText> m_displayText; std::unique_ptr<Ui::CDisplayText> m_displayText;
std::unique_ptr<Ui::CDebugMenu> m_debugMenu;
std::unique_ptr<CSettings> m_settings; std::unique_ptr<CSettings> m_settings;
//! Progress of loaded player //! Progress of loaded player
@ -562,13 +565,9 @@ protected:
ShowLimit m_showLimit[MAXSHOWLIMIT]; ShowLimit m_showLimit[MAXSHOWLIMIT];
Gfx::Color m_colorRefBot;
std::map<int, Gfx::Color> m_colorNewBot; std::map<int, Gfx::Color> m_colorNewBot;
Gfx::Color m_colorRefAlien;
Gfx::Color m_colorNewAlien; Gfx::Color m_colorNewAlien;
Gfx::Color m_colorRefGreen;
Gfx::Color m_colorNewGreen; Gfx::Color m_colorNewGreen;
Gfx::Color m_colorRefWater;
Gfx::Color m_colorNewWater; Gfx::Color m_colorNewWater;
float m_colorShiftWater = 0.0f; float m_colorShiftWater = 0.0f;

View File

@ -18,6 +18,7 @@
*/ */
#include <math/geometry.h>
#include "object/auto/autohouston.h" #include "object/auto/autohouston.h"
#include "object/old_object.h" #include "object/old_object.h"
@ -30,23 +31,19 @@
CAutoHouston::CAutoHouston(COldObject* object) : CAuto(object) CAutoHouston::CAutoHouston(COldObject* object) : CAuto(object)
{ {
Math::Vector pos; for (int i = 0; i < HUSTONMAXLENS; i++)
int i;
for ( i=0 ; i<HUSTONMAXLENS ; i++ )
{ {
m_lens[i].parti = -1; m_lens[i].parti = -1;
} }
pos = m_object->GetPosition();
m_lens[0].type = Gfx::PARTISELR; m_lens[0].type = Gfx::PARTISELR;
m_lens[1].type = Gfx::PARTISELR; m_lens[1].type = Gfx::PARTISELR;
m_lens[2].type = Gfx::PARTISELR; m_lens[2].type = Gfx::PARTISELR;
m_lens[3].type = Gfx::PARTISELR; m_lens[3].type = Gfx::PARTISELR;
m_lens[0].pos = pos+Math::Vector(0.0f+13.0f, 34.0f, 30.0f ); m_lens[0].pos = Math::Vector(0.0f+13.0f, 34.0f, 30.0f );
m_lens[1].pos = pos+Math::Vector(0.0f-13.0f, 34.0f, 30.0f ); m_lens[1].pos = Math::Vector(0.0f-13.0f, 34.0f, 30.0f );
m_lens[2].pos = pos+Math::Vector(0.0f , 34.0f, 30.0f+13.0f); m_lens[2].pos = Math::Vector(0.0f , 34.0f, 30.0f+13.0f);
m_lens[3].pos = pos+Math::Vector(0.0f , 34.0f, 30.0f-13.0f); m_lens[3].pos = Math::Vector(0.0f , 34.0f, 30.0f-13.0f);
m_lens[0].dim = 4.0f; m_lens[0].dim = 4.0f;
m_lens[1].dim = 4.0f; m_lens[1].dim = 4.0f;
m_lens[2].dim = 4.0f; m_lens[2].dim = 4.0f;
@ -60,49 +57,50 @@ CAutoHouston::CAutoHouston(COldObject* object) : CAuto(object)
m_lens[2].off = 0.4f; m_lens[2].off = 0.4f;
m_lens[3].off = 0.4f; m_lens[3].off = 0.4f;
int i = 4;
// Part under the radar. // Part under the radar.
i = 4;
m_lens[i].type = Gfx::PARTISELR; m_lens[i].type = Gfx::PARTISELR;
m_lens[i].pos = pos+Math::Vector(-7.0f, 9.9f, 40.1f); m_lens[i].pos = Math::Vector(-7.0f, 9.9f, 40.1f);
m_lens[i].dim = 1.8f; m_lens[i].dim = 1.8f;
m_lens[i].total = 0.4f; m_lens[i].total = 0.4f;
m_lens[i].off = 0.2f; m_lens[i].off = 0.2f;
i ++; i ++;
m_lens[i].type = Gfx::PARTISELY; m_lens[i].type = Gfx::PARTISELY;
m_lens[i].pos = pos+Math::Vector(-7.0f, 7.2f, 34.8f); m_lens[i].pos = Math::Vector(-7.0f, 7.2f, 34.8f);
m_lens[i].dim = 0.4f; m_lens[i].dim = 0.4f;
m_lens[i].total = 0.7f; m_lens[i].total = 0.7f;
m_lens[i].off = 0.3f; m_lens[i].off = 0.3f;
i ++; i ++;
m_lens[i].type = Gfx::PARTISELY; m_lens[i].type = Gfx::PARTISELY;
m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 34.3f); m_lens[i].pos = Math::Vector(-7.0f, 6.5f, 34.3f);
m_lens[i].dim = 0.4f; m_lens[i].dim = 0.4f;
m_lens[i].total = 0.7f; m_lens[i].total = 0.7f;
m_lens[i].off = 0.3f; m_lens[i].off = 0.3f;
i ++; i ++;
m_lens[i].type = Gfx::PARTISELR; m_lens[i].type = Gfx::PARTISELR;
m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 33.4f); m_lens[i].pos = Math::Vector(-7.0f, 6.5f, 33.4f);
m_lens[i].dim = 0.4f; m_lens[i].dim = 0.4f;
m_lens[i].total = 0.0f; m_lens[i].total = 0.0f;
m_lens[i].off = 0.0f; m_lens[i].off = 0.0f;
i ++; i ++;
m_lens[i].type = Gfx::PARTISELR; m_lens[i].type = Gfx::PARTISELR;
m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 33.0f); m_lens[i].pos = Math::Vector(-7.0f, 6.5f, 33.0f);
m_lens[i].dim = 0.4f; m_lens[i].dim = 0.4f;
m_lens[i].total = 1.0f; m_lens[i].total = 1.0f;
m_lens[i].off = 0.5f; m_lens[i].off = 0.5f;
i ++; i ++;
m_lens[i].type = Gfx::PARTISELY; m_lens[i].type = Gfx::PARTISELY;
m_lens[i].pos = pos+Math::Vector(-7.0f, 8.5f, 14.0f); m_lens[i].pos = Math::Vector(-7.0f, 8.5f, 14.0f);
m_lens[i].dim = 1.2f; m_lens[i].dim = 1.2f;
m_lens[i].total = 0.8f; m_lens[i].total = 0.8f;
m_lens[i].off = 0.2f; m_lens[i].off = 0.2f;
i ++; i ++;
m_lens[i].type = Gfx::PARTISELR; m_lens[i].type = Gfx::PARTISELR;
m_lens[i].pos = pos+Math::Vector(4.0f, 6.0f, 8.6f); m_lens[i].pos = Math::Vector(4.0f, 6.0f, 8.6f);
m_lens[i].dim = 1.0f; m_lens[i].dim = 1.0f;
m_lens[i].total = 0.9f; m_lens[i].total = 0.9f;
m_lens[i].off = 0.7f; m_lens[i].off = 0.7f;
@ -110,53 +108,53 @@ CAutoHouston::CAutoHouston(COldObject* object) : CAuto(object)
// Part with three windows. // Part with three windows.
m_lens[i].type = Gfx::PARTISELR; m_lens[i].type = Gfx::PARTISELR;
m_lens[i].pos = pos+Math::Vector(-7.0f, 9.9f, -19.9f); m_lens[i].pos = Math::Vector(-7.0f, 9.9f, -19.9f);
m_lens[i].dim = 1.0f; m_lens[i].dim = 1.0f;
m_lens[i].total = 0.6f; m_lens[i].total = 0.6f;
m_lens[i].off = 0.3f; m_lens[i].off = 0.3f;
i ++; i ++;
m_lens[i].type = Gfx::PARTISELY; m_lens[i].type = Gfx::PARTISELY;
m_lens[i].pos = pos+Math::Vector(-7.0f, 7.2f, 34.8f-60.0f); m_lens[i].pos = Math::Vector(-7.0f, 7.2f, 34.8f-60.0f);
m_lens[i].dim = 0.4f; m_lens[i].dim = 0.4f;
m_lens[i].total = 0.7f; m_lens[i].total = 0.7f;
m_lens[i].off = 0.3f; m_lens[i].off = 0.3f;
i ++; i ++;
m_lens[i].type = Gfx::PARTISELY; m_lens[i].type = Gfx::PARTISELY;
m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 34.3f-60.0f); m_lens[i].pos = Math::Vector(-7.0f, 6.5f, 34.3f-60.0f);
m_lens[i].dim = 0.4f; m_lens[i].dim = 0.4f;
m_lens[i].total = 0.0f; m_lens[i].total = 0.0f;
m_lens[i].off = 0.0f; m_lens[i].off = 0.0f;
i ++; i ++;
m_lens[i].type = Gfx::PARTISELR; m_lens[i].type = Gfx::PARTISELR;
m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 33.4f-60.0f); m_lens[i].pos = Math::Vector(-7.0f, 6.5f, 33.4f-60.0f);
m_lens[i].dim = 0.4f; m_lens[i].dim = 0.4f;
m_lens[i].total = 0.6f; m_lens[i].total = 0.6f;
m_lens[i].off = 0.4f; m_lens[i].off = 0.4f;
i ++; i ++;
m_lens[i].type = Gfx::PARTISELR; m_lens[i].type = Gfx::PARTISELR;
m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 33.0f-60.0f); m_lens[i].pos = Math::Vector(-7.0f, 6.5f, 33.0f-60.0f);
m_lens[i].dim = 0.4f; m_lens[i].dim = 0.4f;
m_lens[i].total = 0.8f; m_lens[i].total = 0.8f;
m_lens[i].off = 0.2f; m_lens[i].off = 0.2f;
i ++; i ++;
m_lens[i].type = Gfx::PARTISELY; m_lens[i].type = Gfx::PARTISELY;
m_lens[i].pos = pos+Math::Vector(-6.5f, 13.5f, -37.0f); m_lens[i].pos = Math::Vector(-6.5f, 13.5f, -37.0f);
m_lens[i].dim = 1.0f; m_lens[i].dim = 1.0f;
m_lens[i].total = 0.0f; m_lens[i].total = 0.0f;
m_lens[i].off = 0.0f; m_lens[i].off = 0.0f;
i ++; i ++;
m_lens[i].type = Gfx::PARTISELY; m_lens[i].type = Gfx::PARTISELY;
m_lens[i].pos = pos+Math::Vector(-7.0f, 12.2f, -39.8f); m_lens[i].pos = Math::Vector(-7.0f, 12.2f, -39.8f);
m_lens[i].dim = 1.8f; m_lens[i].dim = 1.8f;
m_lens[i].total = 1.5f; m_lens[i].total = 1.5f;
m_lens[i].off = 0.5f; m_lens[i].off = 0.5f;
i ++; i ++;
m_lens[i].type = Gfx::PARTISELY; m_lens[i].type = Gfx::PARTISELY;
m_lens[i].pos = pos+Math::Vector(-7.0f, 8.5f, -47.0f); m_lens[i].pos = Math::Vector(-7.0f, 8.5f, -47.0f);
m_lens[i].dim = 0.6f; m_lens[i].dim = 0.6f;
m_lens[i].total = 0.7f; m_lens[i].total = 0.7f;
m_lens[i].off = 0.5f; m_lens[i].off = 0.5f;
@ -204,15 +202,11 @@ void CAutoHouston::Start(int param)
bool CAutoHouston::EventProcess(const Event &event) bool CAutoHouston::EventProcess(const Event &event)
{ {
Math::Vector speed;
Math::Point dim;
float angle;
int i;
CAuto::EventProcess(event); CAuto::EventProcess(event);
if ( m_engine->GetPause() ) return true; if ( m_engine->GetPause() ) return true;
float angle;
angle = -m_time*1.0f; angle = -m_time*1.0f;
m_object->SetPartRotationY(1, angle); // rotates the radar m_object->SetPartRotationY(1, angle); // rotates the radar
angle = sinf(m_time*4.0f)*0.3f; angle = sinf(m_time*4.0f)*0.3f;
@ -223,8 +217,7 @@ bool CAutoHouston::EventProcess(const Event &event)
m_progress += event.rTime*m_speed; m_progress += event.rTime*m_speed;
// Flashes the keys. // Flashes the keys.
speed = Math::Vector(0.0f, 0.0f, 0.0f); for (int i = 0; i < m_lensTotal; i++ )
for ( i=0 ; i<m_lensTotal ; i++ )
{ {
if ( m_lens[i].total != 0.0f && if ( m_lens[i].total != 0.0f &&
Math::Mod(m_time, m_lens[i].total) < m_lens[i].off ) Math::Mod(m_time, m_lens[i].total) < m_lens[i].off )
@ -239,9 +232,14 @@ bool CAutoHouston::EventProcess(const Event &event)
{ {
if ( m_lens[i].parti == -1 ) if ( m_lens[i].parti == -1 )
{ {
Math::Point dim;
dim.x = m_lens[i].dim; dim.x = m_lens[i].dim;
dim.y = dim.x; dim.y = dim.x;
m_lens[i].parti = m_particle->CreateParticle(m_lens[i].pos, speed, dim, m_lens[i].type, 1.0f, 0.0f, 0.0f);
Math::Vector pos = m_lens[i].pos;
Math::RotatePoint(Math::Vector(0.0f, 0.0f, 0.0f), -m_object->GetRotationY(), 0.0f, pos);
m_lens[i].parti = m_particle->CreateParticle(m_object->GetPosition()+pos, Math::Vector(0.0f, 0.0f, 0.0f), dim, m_lens[i].type, 1.0f, 0.0f, 0.0f);
} }
} }
} }

View File

@ -22,6 +22,7 @@
#include "common/event.h" #include "common/event.h"
#include "common/global.h" #include "common/global.h"
#include "common/image.h"
#include "common/make_unique.h" #include "common/make_unique.h"
#include "graphics/engine/terrain.h" #include "graphics/engine/terrain.h"
@ -65,6 +66,9 @@ CTaskGoto::CTaskGoto(COldObject* object) : CForegroundTask(object)
CTaskGoto::~CTaskGoto() CTaskGoto::~CTaskGoto()
{ {
BitmapClose(); BitmapClose();
if (m_engine->GetDebugGoto() && m_object->GetSelect())
m_engine->SetDebugGotoBitmap(std::move(nullptr));
} }
@ -77,9 +81,63 @@ bool CTaskGoto::EventProcess(const Event &event)
float a, g, dist, linSpeed, cirSpeed, h, hh, factor, dir; float a, g, dist, linSpeed, cirSpeed, h, hh, factor, dir;
Error ret; Error ret;
if ( m_engine->GetPause() ) return true;
if ( event.type != EVENT_FRAME ) return true; if ( event.type != EVENT_FRAME ) return true;
if (m_engine->GetDebugGoto())
{
auto AdjustPoint = [&](Math::Vector p) -> Math::Vector
{
m_terrain->AdjustToFloor(p);
p.y += 2.0f;
return p;
};
std::vector<Gfx::VertexCol> debugLine;
if (m_bmTotal > 0)
{
Gfx::Color color = Gfx::Color(0.0f, 1.0f, 0.0f);
for (int i = 0; i < m_bmTotal; i++)
{
if (i > m_bmIndex-1)
color = Gfx::Color(1.0f, 0.0f, 0.0f);
debugLine.push_back(Gfx::VertexCol(AdjustPoint(m_bmPoints[i]), color));
}
m_engine->AddDebugGotoLine(debugLine);
debugLine.clear();
}
Gfx::Color color = Gfx::Color(0.0f, 0.0f, 1.0f);
debugLine.push_back(Gfx::VertexCol(m_object->GetPosition(), color));
debugLine.push_back(Gfx::VertexCol(AdjustPoint(m_bmTotal > 0 && m_bmIndex <= m_bmTotal && m_phase != TGP_BEAMSEARCH ? m_bmPoints[m_bmIndex] : m_goal), color));
m_engine->AddDebugGotoLine(debugLine);
if (m_object->GetSelect() && m_bmChanged)
{
if (m_bmArray != nullptr)
{
std::unique_ptr<CImage> debugImage = MakeUnique<CImage>(Math::IntPoint(m_bmSize, m_bmSize));
debugImage->Fill(Gfx::IntColor(255, 255, 255, 255));
for (int x = 0; x < m_bmSize; x++)
{
for (int y = 0; y < m_bmSize; y++)
{
bool a = BitmapTestDot(0, x, y);
bool b = BitmapTestDot(1, x, y);
if (a || b)
{
Gfx::Color c = Gfx::Color(0.0f, 0.0f, 0.0f, 1.0f);
if (b) c = Gfx::Color(0.0f, 0.0f, 1.0f, 1.0f);
debugImage->SetPixel(Math::IntPoint(x, y), c);
}
}
}
m_engine->SetDebugGotoBitmap(std::move(debugImage));
}
m_bmChanged = false;
}
}
if ( m_engine->GetPause() ) return true;
// Momentarily stationary object (ant on the back)? // Momentarily stationary object (ant on the back)?
CBaseAlien* alien = dynamic_cast<CBaseAlien*>(m_object); CBaseAlien* alien = dynamic_cast<CBaseAlien*>(m_object);
if ( alien != nullptr && alien->GetFixed() ) if ( alien != nullptr && alien->GetFixed() )
@ -1616,6 +1674,8 @@ Error CTaskGoto::BeamExplore(const Math::Vector &prevPos, const Math::Vector &cu
iLar = 0; iLar = 0;
if ( i >= MAXPOINTS ) return ERR_GOTO_ITER; // too many recursions if ( i >= MAXPOINTS ) return ERR_GOTO_ITER; // too many recursions
m_bmTotal = i;
if ( m_bmIter[i] == -1 ) if ( m_bmIter[i] == -1 )
{ {
m_bmIter[i] = 0; m_bmIter[i] = 0;
@ -1970,6 +2030,7 @@ bool CTaskGoto::BitmapOpen()
m_bmSize = static_cast<int>(3200.0f/BM_DIM_STEP); m_bmSize = static_cast<int>(3200.0f/BM_DIM_STEP);
m_bmArray = MakeUniqueArray<unsigned char>(m_bmSize*m_bmSize/8*2); m_bmArray = MakeUniqueArray<unsigned char>(m_bmSize*m_bmSize/8*2);
m_bmChanged = true;
m_bmOffset = m_bmSize/2; m_bmOffset = m_bmSize/2;
m_bmLine = m_bmSize/8; m_bmLine = m_bmSize/8;
@ -1987,6 +2048,7 @@ bool CTaskGoto::BitmapOpen()
bool CTaskGoto::BitmapClose() bool CTaskGoto::BitmapClose()
{ {
m_bmArray.reset(); m_bmArray.reset();
m_bmChanged = true;
return true; return true;
} }
@ -2043,6 +2105,7 @@ void CTaskGoto::BitmapSetDot(int rank, int x, int y)
y < 0 || y >= m_bmSize ) return; y < 0 || y >= m_bmSize ) return;
m_bmArray[rank*m_bmLine*m_bmSize + m_bmLine*y + x/8] |= (1<<x%8); m_bmArray[rank*m_bmLine*m_bmSize + m_bmLine*y + x/8] |= (1<<x%8);
m_bmChanged = true;
} }
// Removes a point in the bitmap. // Removes a point in the bitmap.
@ -2054,6 +2117,7 @@ void CTaskGoto::BitmapClearDot(int rank, int x, int y)
y < 0 || y >= m_bmSize ) return; y < 0 || y >= m_bmSize ) return;
m_bmArray[rank*m_bmLine*m_bmSize + m_bmLine*y + x/8] &= ~(1<<x%8); m_bmArray[rank*m_bmLine*m_bmSize + m_bmLine*y + x/8] &= ~(1<<x%8);
m_bmChanged = true;
} }
// Tests a point in the bitmap. // Tests a point in the bitmap.

View File

@ -137,6 +137,7 @@ protected:
float m_wormLastTime = 0.0f; float m_wormLastTime = 0.0f;
float m_lastDistance = 0.0f; float m_lastDistance = 0.0f;
bool m_bmChanged = true;
int m_bmSize = 0; // width or height of the table int m_bmSize = 0; // width or height of the table
int m_bmOffset = 0; // m_bmSize/2 int m_bmOffset = 0; // m_bmSize/2
int m_bmLine = 0; // increment line m_bmSize/8 int m_bmLine = 0; // increment line m_bmSize/8

View File

@ -135,7 +135,8 @@ bool CTarget::GetTooltip(Math::Point pos, std::string &name)
CObject* CTarget::DetectFriendObject(Math::Point pos) CObject* CTarget::DetectFriendObject(Math::Point pos)
{ {
int objRank = m_engine->DetectObject(pos); Math::Vector p;
int objRank = m_engine->DetectObject(pos, p);
for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects())
{ {

429
src/ui/debug_menu.cpp Normal file
View File

@ -0,0 +1,429 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "ui/debug_menu.h"
#include "common/event.h"
#include "graphics/engine/lightning.h"
#include "graphics/engine/terrain.h"
#include "level/robotmain.h"
#include "object/object_create_params.h"
#include "object/object_manager.h"
#include "object/object.h"
#include "ui/controls/interface.h"
#include "ui/controls/window.h"
#include "ui/controls/check.h"
#include "ui/controls/button.h"
namespace Ui
{
CDebugMenu::CDebugMenu(CRobotMain* main, Gfx::CEngine* engine, CObjectManager* objMan, CSoundInterface* sound)
{
m_main = main;
m_interface = m_main->GetInterface();
m_engine = engine;
m_objMan = objMan;
m_sound = sound;
}
CDebugMenu::~CDebugMenu()
{
}
void CDebugMenu::ToggleInterface()
{
if (m_interface->SearchControl(EVENT_WINDOW7) == nullptr)
CreateInterface();
else
DestroyInterface();
}
const Math::Point dim = Math::Point(33.0f/640.0f, 33.0f/480.0f);
const float ox = 3.0f/640.0f, oy = 3.0f/480.0f;
const float sx = 33.0f/640.0f, sy = 33.0f/480.0f;
void CDebugMenu::CreateInterface()
{
CWindow* pw = m_interface->CreateWindows(Math::Point(), Math::Point(), 0, EVENT_WINDOW7);
Math::Point pos, ddim;
CCheck* pc;
CButton* pb;
ddim.x = 4*dim.x+4*ox;
ddim.y = 222.0f/480.0f;
pos.x = 1.0f-ddim.x;
pos.y = oy+sy*3.0f;
pw->CreateGroup(pos, ddim, 6, EVENT_WINDOW7);
ddim.x = ddim.x - 4*ox;
ddim.y = dim.y*0.5f;
pos.x += 2*ox;
pos.y = oy+sy*9.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_DBG_SPAWN_OBJ);
pb->SetName("Spawn object");
pos.y -= ddim.y;
pb = pw->CreateButton(pos, ddim, -1, EVENT_DBG_TELEPORT);
pb->SetName("Teleport");
pos.y -= ddim.y;
pb = pw->CreateButton(pos, ddim, -1, EVENT_DBG_LIGHTNING);
pb->SetName("Lightning");
pos.y -= 0.048f;
pc = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_STATS);
pc->SetName("Display stats");
pos.y -= 0.048f;
pos.y -= 0.048f;
pc = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_RESOURCES);
pc->SetName("Underground resources");
pos.y -= 0.048f;
pc = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_GOTO);
pc->SetName("Render goto() path");
pos.y -= 0.048f;
pc = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_CRASHSPHERES);
pc->SetName("Render crash spheres");
pos.y -= 0.048f;
pc = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_LIGHTS);
pc->SetName("Render dynamic lights");
pos.y -= 0.048f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_DBG_LIGHTS_DUMP);
pb->SetName("Dump lights to log");
UpdateInterface();
}
void CDebugMenu::CreateSpawnInterface()
{
CWindow* pw = m_interface->CreateWindows(Math::Point(), Math::Point(), 0, EVENT_WINDOW7);
Math::Point pos, ddim;
CButton* pb;
ddim.x = 4*dim.x+4*ox;
ddim.y = 222.0f/480.0f;
pos.x = 1.0f-ddim.x;
pos.y = oy+sy*3.0f;
pw->CreateGroup(pos, ddim, 6, EVENT_WINDOW7);
ddim.x = ddim.x - 4*ox;
ddim.y = dim.y*0.5f;
pos.x += 2*ox;
pos.y = oy+sy*9.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_SPAWN_CANCEL);
pb->SetName("Cancel");
pos.y -= ddim.y;
pos.y -= dim.y;
pw->CreateButton(pos, dim, 128+8, EVENT_SPAWN_ME);
pos.x += dim.x;
pw->CreateButton(pos, dim, 128+9, EVENT_SPAWN_WHEELEDGRABBER);
pos.x += dim.x;
pw->CreateButton(pos, dim, 128+15, EVENT_SPAWN_WHEELEDSHOOTER);
pos.x += dim.x;
pw->CreateButton(pos, dim, 128+19, EVENT_SPAWN_PHAZERSHOOTER);
pos.x -= 3*dim.x;
pos.y -= dim.y;
pw->CreateButton(pos, dim, 128+32, EVENT_SPAWN_BOTFACTORY);
pos.x += dim.x;
pw->CreateButton(pos, dim, 128+34, EVENT_SPAWN_CONVERTER);
pos.x += dim.x;
pw->CreateButton(pos, dim, 128+33, EVENT_SPAWN_DERRICK);
pos.x += dim.x;
pw->CreateButton(pos, dim, 128+36, EVENT_SPAWN_POWERSTATION);
pos.x -= 3*dim.x;
pos.y -= ddim.y;
pb = pw->CreateButton(pos, ddim, -1, EVENT_SPAWN_TITANIUM);
pb->SetName("Titanium");
pos.y -= ddim.y;
pb = pw->CreateButton(pos, ddim, -1, EVENT_SPAWN_TITANIUMORE);
pb->SetName("TitaniumOre");
pos.y -= ddim.y;
pb = pw->CreateButton(pos, ddim, -1, EVENT_SPAWN_URANIUMORE);
pb->SetName("UraniumOre");
pos.y -= ddim.y;
pb = pw->CreateButton(pos, ddim, -1, EVENT_SPAWN_POWERCELL);
pb->SetName("PowerCell");
pos.y -= ddim.y;
pb = pw->CreateButton(pos, ddim, -1, EVENT_SPAWN_NUCLEARCELL);
pb->SetName("NuclearCell");
}
const std::map<EventType, ObjectType> SPAWN_TYPES = {
{EVENT_SPAWN_ME, OBJECT_HUMAN},
{EVENT_SPAWN_WHEELEDGRABBER, OBJECT_MOBILEwa},
{EVENT_SPAWN_WHEELEDSHOOTER, OBJECT_MOBILEwc},
{EVENT_SPAWN_PHAZERSHOOTER, OBJECT_MOBILErc},
{EVENT_SPAWN_BOTFACTORY, OBJECT_FACTORY},
{EVENT_SPAWN_CONVERTER, OBJECT_CONVERT},
{EVENT_SPAWN_DERRICK, OBJECT_DERRICK},
{EVENT_SPAWN_POWERSTATION, OBJECT_STATION},
{EVENT_SPAWN_TITANIUM, OBJECT_METAL},
{EVENT_SPAWN_TITANIUMORE, OBJECT_STONE},
{EVENT_SPAWN_URANIUMORE, OBJECT_URANIUM},
{EVENT_SPAWN_POWERCELL, OBJECT_POWER},
{EVENT_SPAWN_NUCLEARCELL, OBJECT_ATOMIC},
};
void CDebugMenu::UpdateInterface()
{
CCheck* pc;
CButton* pb;
CWindow* pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW7));
if (pw == nullptr) return;
pb = static_cast<CButton*>(pw->SearchControl(EVENT_DBG_LIGHTNING));
if (pb != nullptr)
{
pb->SetName(m_lightningActive ? "Disable lightning" : "Lightning");
}
pb = static_cast<CButton*>(pw->SearchControl(EVENT_DBG_TELEPORT));
if (pb != nullptr)
{
pb->SetName(m_teleportActive ? "Abort teleport" : "Teleport");
}
pc = static_cast<CCheck*>(pw->SearchControl(EVENT_DBG_STATS));
if (pc != nullptr)
{
pc->SetState(STATE_CHECK, m_engine->GetShowStats());
}
pc = static_cast<CCheck*>(pw->SearchControl(EVENT_DBG_RESOURCES));
if (pc != nullptr)
{
pc->SetState(STATE_CHECK, m_engine->GetDebugResources());
}
pc = static_cast<CCheck*>(pw->SearchControl(EVENT_DBG_GOTO));
if (pc != nullptr)
{
pc->SetState(STATE_CHECK, m_engine->GetDebugGoto());
}
pc = static_cast<CCheck*>(pw->SearchControl(EVENT_DBG_CRASHSPHERES));
if (pc != nullptr)
{
pc->SetState(STATE_CHECK, m_main->GetDebugCrashSpheres());
}
pc = static_cast<CCheck*>(pw->SearchControl(EVENT_DBG_LIGHTS));
if (pc != nullptr)
{
pc->SetState(STATE_CHECK, m_engine->GetDebugLights());
}
for (const auto& it : SPAWN_TYPES)
{
pb = static_cast<CButton*>(pw->SearchControl(it.first));
if (pb != nullptr)
{
pb->SetState(STATE_ENABLE, it.second != m_spawningType);
}
}
}
void CDebugMenu::DestroyInterface()
{
m_interface->DeleteControl(EVENT_WINDOW7);
m_spawningType = OBJECT_NULL;
}
bool CDebugMenu::EventProcess(const Event &event)
{
switch (event.type)
{
case EVENT_DBG_STATS:
m_engine->SetShowStats(!m_engine->GetShowStats());
UpdateInterface();
break;
case EVENT_DBG_SPAWN_OBJ:
DestroyInterface();
CreateSpawnInterface();
break;
case EVENT_DBG_TELEPORT:
if (!m_teleportActive)
{
if (m_main->GetSelect() != nullptr)
m_teleportActive = true;
else
m_sound->Play(SOUND_CLICK);
}
else
{
m_teleportActive = false;
}
UpdateInterface();
break;
case EVENT_DBG_LIGHTNING:
m_lightningActive = !m_lightningActive;
UpdateInterface();
break;
case EVENT_DBG_RESOURCES:
m_engine->SetDebugResources(!m_engine->GetDebugResources());
UpdateInterface();
break;
case EVENT_DBG_GOTO:
m_engine->SetDebugGoto(!m_engine->GetDebugGoto());
UpdateInterface();
break;
case EVENT_DBG_CRASHSPHERES:
m_main->SetDebugCrashSpheres(!m_main->GetDebugCrashSpheres());
UpdateInterface();
break;
case EVENT_DBG_LIGHTS:
m_engine->SetDebugLights(!m_engine->GetDebugLights());
UpdateInterface();
break;
case EVENT_DBG_LIGHTS_DUMP:
m_engine->DebugDumpLights();
break;
case EVENT_SPAWN_CANCEL:
DestroyInterface();
CreateInterface();
break;
case EVENT_SPAWN_ME:
case EVENT_SPAWN_WHEELEDGRABBER:
case EVENT_SPAWN_WHEELEDSHOOTER:
case EVENT_SPAWN_PHAZERSHOOTER:
case EVENT_SPAWN_BOTFACTORY:
case EVENT_SPAWN_CONVERTER:
case EVENT_SPAWN_DERRICK:
case EVENT_SPAWN_POWERSTATION:
case EVENT_SPAWN_TITANIUM:
case EVENT_SPAWN_TITANIUMORE:
case EVENT_SPAWN_URANIUMORE:
case EVENT_SPAWN_POWERCELL:
case EVENT_SPAWN_NUCLEARCELL:
m_spawningType = SPAWN_TYPES.at(event.type);
UpdateInterface();
break;
case EVENT_MOUSE_BUTTON_DOWN:
if (event.GetData<MouseButtonEventData>()->button == MOUSE_BUTTON_LEFT)
{
if (m_lightningActive)
{
return !HandleLightning(event.mousePos);
}
if (m_teleportActive)
{
return !HandleTeleport(event.mousePos);
}
if (m_spawningType != OBJECT_NULL)
{
return !HandleSpawnObject(m_spawningType, event.mousePos);
}
}
break;
case EVENT_MOUSE_MOVE:
if (m_spawningType != OBJECT_NULL || m_teleportActive || m_lightningActive)
{
return false;
}
break;
default:
break;
}
return true;
}
bool CDebugMenu::HandleSpawnObject(ObjectType type, Math::Point mousePos)
{
Math::Vector pos;
if (m_engine->DetectObject(mousePos, pos, true) == -1)
{
m_sound->Play(SOUND_CLICK, 1.0f, 0.5f);
return false;
}
ObjectCreateParams params;
params.pos = pos;
params.type = type;
params.power = 100.0f;
m_objMan->CreateObject(params);
// Update shortcuts in the upper-left corner
m_main->CreateShortcuts();
m_sound->Play(SOUND_RADAR, 2.0f, 1.5f);
return true;
}
bool CDebugMenu::HandleLightning(Math::Point mousePos)
{
Math::Vector pos;
if (m_engine->DetectObject(mousePos, pos, true) == -1)
{
m_sound->Play(SOUND_CLICK, 1.0f, 0.5f);
return false;
}
m_engine->GetLightning()->StrikeAtPos(pos);
return true;
}
bool CDebugMenu::HandleTeleport(Math::Point mousePos)
{
CObject* select = m_main->GetSelect();
Math::Vector pos;
if (m_engine->DetectObject(mousePos, pos, true) == -1 || !m_engine->GetTerrain()->AdjustToFloor(pos) || select == nullptr)
{
m_sound->Play(SOUND_CLICK, 1.0f, 0.5f);
m_teleportActive = false;
UpdateInterface();
return false;
}
select->SetPosition(pos);
m_sound->Play(SOUND_BUILD, 4.0f, 0.75f);
m_sound->Play(SOUND_BUILD, pos, 4.0f, 0.75f);
m_teleportActive = false;
UpdateInterface();
return true;
}
}

70
src/ui/debug_menu.h Normal file
View File

@ -0,0 +1,70 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
#include <math/point.h>
#include <sound/sound.h>
#include "object/object_type.h"
class CRobotMain;
class CObjectManager;
struct Event;
namespace Gfx
{
class CEngine;
}
namespace Ui
{
class CInterface;
class CDebugMenu
{
public:
CDebugMenu(CRobotMain* main, Gfx::CEngine* engine, CObjectManager* objMan, CSoundInterface* sound);
virtual ~CDebugMenu();
void ToggleInterface();
bool EventProcess(const Event& event);
protected:
void CreateInterface();
void CreateSpawnInterface();
void UpdateInterface();
void DestroyInterface();
bool HandleSpawnObject(ObjectType type, Math::Point mousePos);
bool HandleLightning(Math::Point mousePos);
bool HandleTeleport(Math::Point mousePos);
protected:
CRobotMain* m_main;
CInterface* m_interface;
Gfx::CEngine* m_engine;
CObjectManager* m_objMan;
CSoundInterface* m_sound;
ObjectType m_spawningType = OBJECT_NULL;
bool m_lightningActive = false;
bool m_teleportActive = false;
};
}