summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-09-19 22:53:06 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-09-19 22:53:06 +0200
commit7479f486b671acb2a6aea2c84a56b383aaba00ca (patch)
tree4043545a14234dfaa2d7d08d59c7ee9ee97f0de9 /src/common
parent901f10b2bac18a2063cd21798f22b3917e8519b5 (diff)
parent57d33d79ea570773d84ad81d4a61f50e079979ef (diff)
downloadcolobot-7479f486b671acb2a6aea2c84a56b383aaba00ca.tar.gz
colobot-7479f486b671acb2a6aea2c84a56b383aaba00ca.tar.bz2
colobot-7479f486b671acb2a6aea2c84a56b383aaba00ca.zip
Forgotten fix in dev-graphics
Diffstat (limited to 'src/common')
-rw-r--r--src/common/error_ids.h5
-rw-r--r--src/common/event.cpp10
-rw-r--r--src/common/event.h196
-rw-r--r--src/common/event_ids.h8
-rw-r--r--src/common/global.h141
-rw-r--r--src/common/image.cpp142
-rw-r--r--src/common/image.h22
-rw-r--r--src/common/iman.cpp136
-rw-r--r--src/common/iman.h108
-rw-r--r--src/common/ioutils.h5
-rw-r--r--src/common/key.h26
-rw-r--r--src/common/language.h54
-rw-r--r--src/common/logger.h14
-rw-r--r--src/common/metafile.cpp28
-rw-r--r--src/common/misc.cpp332
-rw-r--r--src/common/misc.h71
-rw-r--r--src/common/profile.cpp5
-rw-r--r--src/common/profile.h19
-rw-r--r--src/common/restext.cpp89
-rw-r--r--src/common/restext.h32
-rw-r--r--src/common/restext_ids.h3
-rw-r--r--src/common/restext_strings.c63
-rw-r--r--src/common/singleton.h5
-rw-r--r--src/common/stringutils.h5
-rw-r--r--src/common/struct.h54
-rw-r--r--src/common/test/CMakeLists.txt2
-rw-r--r--src/common/test/image_test.cpp23
27 files changed, 821 insertions, 777 deletions
diff --git a/src/common/error_ids.h b/src/common/error_ids.h
index b17a018..fc1f7d6 100644
--- a/src/common/error_ids.h
+++ b/src/common/error_ids.h
@@ -14,6 +14,9 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
+
+// TODO: move to global.h after restext rewrite
+
#pragma once
enum Error
@@ -23,8 +26,6 @@ enum Error
ERR_CONTINUE = 2, // continues
ERR_STOP = 3, // stops
ERR_CMD = 4, // unknown command
- ERR_INSTALL = 20, // incorrectly installed program
- ERR_NOCD = 21, // CD not found
ERR_MANIP_VEH = 100, // inappropriate vehicle
ERR_MANIP_FLY = 101, // impossible in flight
ERR_MANIP_BUSY = 102, // taking: hands already occupied
diff --git a/src/common/event.cpp b/src/common/event.cpp
index 6a5f4d3..87c8a5c 100644
--- a/src/common/event.cpp
+++ b/src/common/event.cpp
@@ -19,6 +19,16 @@
#include "common/event.h"
#include "common/iman.h"
+static EventType g_uniqueEventType = EVENT_USER;
+
+
+EventType GetUniqueEventType()
+{
+ int i = static_cast<int>(g_uniqueEventType+1);
+ g_uniqueEventType = static_cast<EventType>(i);
+ return g_uniqueEventType;
+}
+
CEventQueue::CEventQueue(CInstanceManager* iMan)
diff --git a/src/common/event.h b/src/common/event.h
index 3192931..378960c 100644
--- a/src/common/event.h
+++ b/src/common/event.h
@@ -14,23 +14,26 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
-// event.h
+/**
+ * \file common/event.h
+ * \brief Event types, structs and event queue
+ */
#pragma once
-#include <common/key.h>
-#include <common/event_ids.h>
-#include <math/point.h>
-
-#include <string.h>
-
+#include "common/key.h"
+#include "common/event_ids.h"
+#include "math/point.h"
+#include "math/vector.h"
class CInstanceManager;
-/** \enum PressState
- \brief State of key/mouse button */
+/**
+ * \enum PressState
+ * \brief State of key/mouse button
+ */
enum PressState
{
STATE_PRESSED,
@@ -38,21 +41,22 @@ enum PressState
};
-/** \struct KeyEventData
- \brief Additional data for keyboard event */
+/**
+ * \struct KeyEventData
+ * \brief Additional data for keyboard event
+ */
struct KeyEventData
{
//! STATE_PRESSED or STATE_RELEASED */
PressState state;
- //! Key symbol: KEY(...) macro value (from common/key.h)
+ //! If true, the key is a virtual code generated by key modifier press or joystick button press
+ bool virt;
+ //! Key symbol: KEY(...) macro value or virtual key VIRTUAL_... (from common/key.h)
unsigned int key;
//! Keyboard modifiers: a bitmask made of KEY_MOD(...) macro values (from common/key.h)
unsigned int mod;
//! Unicode character
unsigned int unicode;
-
- KeyEventData()
- : state(STATE_PRESSED), key(0), mod(0), unicode(0) {}
};
/** \struct MouseMotionEventData
@@ -60,16 +64,15 @@ struct KeyEventData
struct MouseMoveEventData
{
//! Current button state
- unsigned char state;
+ PressState state;
//! Position of mouse in normalized coordinates (0..1)
Math::Point pos;
-
- MouseMoveEventData()
- : state(STATE_PRESSED) {}
};
-/** \struct MouseButtonEventData
- \brief Additional data mouse button event */
+/**
+ * \struct MouseButtonEventData
+ * \brief Additional data mouse button event
+ */
struct MouseButtonEventData
{
//! The mouse button index
@@ -78,39 +81,58 @@ struct MouseButtonEventData
PressState state;
//! Position of mouse in normalized coordinates (0..1)
Math::Point pos;
+};
+
+/**
+ * \enum WheelDirection
+ * \brief Direction of mouse wheel movement
+ */
+enum WheelDirection
+{
+ WHEEL_UP,
+ WHEEL_DOWN
+};
- MouseButtonEventData()
- : button(0), state(STATE_PRESSED) {}
+/**
+ * \enum MouseWheelEventData
+ * \brief Additional data for mouse wheel event.
+ */
+struct MouseWheelEventData
+{
+ //! Wheel direction
+ WheelDirection dir;
+ //! Position of mouse in normalized coordinates (0..1)
+ Math::Point pos;
};
-/** \struct JoyAxisEventData
- \brief Additional data for joystick axis event */
+/**
+ * \struct JoyAxisEventData
+ * \brief Additional data for joystick axis event
+ */
struct JoyAxisEventData
{
//! The joystick axis index
unsigned char axis;
//! The axis value (range: -32768 to 32767)
int value;
-
- JoyAxisEventData()
- : axis(axis), value(value) {}
};
-/** \struct JoyButtonEventData
- \brief Additional data for joystick button event */
+/**
+ * \struct JoyButtonEventData
+ * \brief Additional data for joystick button event
+ */
struct JoyButtonEventData
{
//! The joystick button index
unsigned char button;
//! STATE_PRESSED or STATE_RELEASED
PressState state;
-
- JoyButtonEventData()
- : button(0), state(STATE_PRESSED) {}
};
-/** \enum ActiveEventFlags
- \brief Type of focus gained/lost */
+/**
+ * \enum ActiveEventFlags
+ * \brief Type of focus gained/lost
+ */
enum ActiveEventFlags
{
//! Application window focus
@@ -122,30 +144,29 @@ enum ActiveEventFlags
};
-/** \struct ActiveEventData
- \brief Additional data for active event */
+/**
+ * \struct ActiveEventData
+ * \brief Additional data for active event
+ */
struct ActiveEventData
{
//! Flags (bitmask of enum values ActiveEventFlags)
unsigned char flags;
//! True if the focus was gained; false otherwise
bool gain;
-
- ActiveEventData()
- : flags(0), gain(false) {}
};
/**
- \struct Event
- \brief Event sent by system, interface or game
-
- Event is described by its type (EventType) and the union
- \a data contains additional data about the event.
- Different members of the union are filled with different event types.
- With some events, nothing is filled (it's zeroed out).
- The union contains roughly the same information as SDL_Event struct
- but packaged to independent structs and fields.
+ * \struct Event
+ * \brief Event sent by system, interface or game
+ *
+ * Event is described by its type (EventType) and the union
+ * \a data contains additional data about the event.
+ * Different members of the union are filled with different event types.
+ * With some events, nothing is filled (it's zeroed out).
+ * The union contains roughly the same information as SDL_Event struct
+ * but packaged to independent structs and fields.
**/
struct Event
{
@@ -163,6 +184,8 @@ struct Event
MouseButtonEventData mouseButton;
//! Additional data for EVENT_MOUSE_MOVE
MouseMoveEventData mouseMove;
+ //! Additional data for EVENT_MOUSE_WHEEL
+ MouseWheelEventData mouseWheel;
//! Additional data for EVENT_JOY
JoyAxisEventData joyAxis;
//! Additional data for EVENT_JOY_AXIS
@@ -171,70 +194,49 @@ struct Event
ActiveEventData active;
};
- // TODO: refactor/rewrite
+ //! State of tracked keys (mask of TrackedKey enum values)
+ unsigned int trackedKeys;
+
+ //! Mouse position is provided also for other types of events besides mouse events
+ Math::Point mousePos;
+
+ //! Motion vector set by keyboard or joystick
+ Math::Vector motionInput;
+
+ // TODO: remove and replace references with trackedKeys
+ short keyState;
+
+ // TODO: remove and replace references with mousePos
+ Math::Point pos;
+
+ // TODO: remove
long param; // parameter
- Math::Point pos; // mouse position (0 .. 1)
- float axeX; // control the X axis (-1 .. 1)
- float axeY; // control of the Y axis (-1 .. 1)
- float axeZ; // control the Z axis (-1 .. 1)
- short keyState; // state of the keyboard (KS_ *)
+
+ // TODO: remove in longer term (use CApplication's new time functions instead)
float rTime; // relative time
Event(EventType aType = EVENT_NULL)
{
type = aType;
systemEvent = false;
+ trackedKeys = 0;
param = 0;
- axeX = axeY = axeZ = 0.0f;
- keyState = 0;
rTime = 0.0f;
}
};
-/**
- \enum KeyRank
- \brief Slots for key assignment of user controls
- */
-
-// TODO: move to global.h ?
-
-enum KeyRank
-{
- KEYRANK_LEFT = 0,
- KEYRANK_RIGHT = 1,
- KEYRANK_UP = 2,
- KEYRANK_DOWN = 3,
- KEYRANK_GUP = 4,
- KEYRANK_GDOWN = 5,
- KEYRANK_CAMERA = 6,
- KEYRANK_DESEL = 7,
- KEYRANK_ACTION = 8,
- KEYRANK_NEAR = 9,
- KEYRANK_AWAY = 10,
- KEYRANK_NEXT = 11,
- KEYRANK_HUMAN = 12,
- KEYRANK_QUIT = 13,
- KEYRANK_HELP = 14,
- KEYRANK_PROG = 15,
- KEYRANK_VISIT = 16,
- KEYRANK_SPEED10 = 17,
- KEYRANK_SPEED15 = 18,
- KEYRANK_SPEED20 = 19,
- KEYRANK_SPEED30 = 20,
- KEYRANK_AIMUP = 21,
- KEYRANK_AIMDOWN = 22,
- KEYRANK_CBOT = 23,
-};
+//! Returns an unique event type (above the standard IDs)
+EventType GetUniqueEventType();
/**
- \class CEventQueue
- \brief Global event queue
-
- Provides an interface to a global FIFO queue with events (both system- and user-generated).
- The queue has a fixed maximum size but it should not be a problem.
+ * \class CEventQueue
+ * \brief Global event queue
+ *
+ * Provides an interface to a global FIFO queue with events (both system- and user-generated).
+ * The queue has a fixed maximum size but it should not be a problem.
*/
class CEventQueue
{
@@ -261,5 +263,3 @@ protected:
int m_tail;
int m_total;
};
-
-
diff --git a/src/common/event_ids.h b/src/common/event_ids.h
index ab235d5..9cbbf94 100644
--- a/src/common/event_ids.h
+++ b/src/common/event_ids.h
@@ -14,6 +14,9 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
+
+// TODO: move to event.h after restext rewrite
+
#pragma once
/**
@@ -38,6 +41,8 @@ enum EventType
EVENT_MOUSE_BUTTON_DOWN = 3,
//! Event sent after releasing a mouse button
EVENT_MOUSE_BUTTON_UP = 4,
+ //! Event sent after moving mouse wheel up or down
+ EVENT_MOUSE_WHEEL = 5,
//! Event sent after moving the mouse
EVENT_MOUSE_MOVE = 7,
//! Event sent after pressing a key
@@ -48,9 +53,6 @@ enum EventType
//! Event sent when application window loses/gains focus
EVENT_ACTIVE = 10,
- //? EVENT_CHAR = 10,
- //? EVENT_FOCUS = 11,
-
//! Event sent after moving joystick axes
EVENT_JOY_AXIS = 12,
//! Event sent after pressing a joystick button
diff --git a/src/common/global.h b/src/common/global.h
index 670c578..3433aeb 100644
--- a/src/common/global.h
+++ b/src/common/global.h
@@ -14,53 +14,124 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
-// global.h
+/**
+ * \file common/global.h
+ * \brief Some common, global definitions
+ */
#pragma once
+#include "error_ids.h"
-enum BuildType
+/**
+ * \enum Language
+ * \brief Application language
+ */
+enum Language
{
- BUILD_FACTORY = (1<<0), // factory
- BUILD_DERRICK = (1<<1), // derrick
- BUILD_CONVERT = (1<<2), // converter
- BUILD_RADAR = (1<<3), // radar
- BUILD_ENERGY = (1<<4), // factory of cells
- BUILD_NUCLEAR = (1<<5), // nuclear power plant
- BUILD_STATION = (1<<6), // base station
- BUILD_REPAIR = (1<<7), // repair center
- BUILD_TOWER = (1<<8), // defense tower
- BUILD_RESEARCH = (1<<9), // research center
- BUILD_LABO = (1<<10), // laboratory
- BUILD_PARA = (1<<11), // lightning protection
- BUILD_INFO = (1<<12), // information terminal
- BUILD_GFLAT = (1<<16), // flat floor
- BUILD_FLAG = (1<<17) // puts / removes colored flag
+ LANG_ENGLISH = 0,
+ LANG_FRENCH = 1,
+ LANG_GERMAN = 2,
+ LANG_POLISH = 3
};
+/**
+ * \enum BuildType
+ * \brief Construction actions (buildings, etc.) available to user
+ *
+ * TODO: refactor
+ */
+enum BuildType
+{
+ BUILD_FACTORY = (1<<0), //! < factory
+ BUILD_DERRICK = (1<<1), //! < derrick
+ BUILD_CONVERT = (1<<2), //! < converter
+ BUILD_RADAR = (1<<3), //! < radar
+ BUILD_ENERGY = (1<<4), //! < factory of cells
+ BUILD_NUCLEAR = (1<<5), //! < nuclear power plant
+ BUILD_STATION = (1<<6), //! < base station
+ BUILD_REPAIR = (1<<7), //! < repair center
+ BUILD_TOWER = (1<<8), //! < defense tower
+ BUILD_RESEARCH = (1<<9), //! < research center
+ BUILD_LABO = (1<<10), //! < laboratory
+ BUILD_PARA = (1<<11), //! < lightning protection
+ BUILD_INFO = (1<<12), //! < information terminal
+ BUILD_GFLAT = (1<<16), //! < flat floor
+ BUILD_FLAG = (1<<17) //! < puts / removes colored flag
+};
-// Do not change values ​​was because of backups (bits = ...).
+/**
+ * \enum ResearchType
+ * \brief Research actions available to user
+ */
enum ResearchType
{
- RESEARCH_TANK = (1<<0), // caterpillars
- RESEARCH_FLY = (1<<1), // wings
- RESEARCH_CANON = (1<<2), // cannon
- RESEARCH_TOWER = (1<<3), // defense tower
- RESEARCH_ATOMIC = (1<<4), // nuclear
- RESEARCH_THUMP = (1<<5), // thumper
- RESEARCH_SHIELD = (1<<6), // shield
- RESEARCH_PHAZER = (1<<7), // phazer gun
- RESEARCH_iPAW = (1<<8), // legs of insects
- RESEARCH_iGUN = (1<<9), // cannon of insects
- RESEARCH_RECYCLER = (1<<10), // recycler
- RESEARCH_SUBM = (1<<11), // submarine
- RESEARCH_SNIFFER = (1<<12) // sniffer
+ RESEARCH_TANK = (1<<0), //! < caterpillars
+ RESEARCH_FLY = (1<<1), //! < wings
+ RESEARCH_CANON = (1<<2), //! < cannon
+ RESEARCH_TOWER = (1<<3), //! < defense tower
+ RESEARCH_ATOMIC = (1<<4), //! < nuclear
+ RESEARCH_THUMP = (1<<5), //! < thumper
+ RESEARCH_SHIELD = (1<<6), //! < shield
+ RESEARCH_PHAZER = (1<<7), //! < phazer gun
+ RESEARCH_iPAW = (1<<8), //! < legs of insects
+ RESEARCH_iGUN = (1<<9), //! < cannon of insects
+ RESEARCH_RECYCLER = (1<<10), //! < recycler
+ RESEARCH_SUBM = (1<<11), //! < submarine
+ RESEARCH_SNIFFER = (1<<12) //! < sniffer
+};
+
+/**
+ * \enum InputSlot
+ * \brief Available slots for input bindings
+ */
+enum InputSlot
+{
+ INPUT_SLOT_LEFT = 0,
+ INPUT_SLOT_RIGHT = 1,
+ INPUT_SLOT_UP = 2,
+ INPUT_SLOT_DOWN = 3,
+ INPUT_SLOT_GUP = 4,
+ INPUT_SLOT_GDOWN = 5,
+ INPUT_SLOT_CAMERA = 6,
+ INPUT_SLOT_DESEL = 7,
+ INPUT_SLOT_ACTION = 8,
+ INPUT_SLOT_NEAR = 9,
+ INPUT_SLOT_AWAY = 10,
+ INPUT_SLOT_NEXT = 11,
+ INPUT_SLOT_HUMAN = 12,
+ INPUT_SLOT_QUIT = 13,
+ INPUT_SLOT_HELP = 14,
+ INPUT_SLOT_PROG = 15,
+ INPUT_SLOT_VISIT = 16,
+ INPUT_SLOT_SPEED10 = 17,
+ INPUT_SLOT_SPEED15 = 18,
+ INPUT_SLOT_SPEED20 = 19,
+ INPUT_SLOT_SPEED30 = 20,
+ INPUT_SLOT_AIMUP = 21,
+ INPUT_SLOT_AIMDOWN = 22,
+ INPUT_SLOT_CBOT = 23,
+
+ INPUT_SLOT_MAX
};
+/**
+ * \enum JoyAxisSlot
+ * \brief Slots for joystick axes inputs
+ */
+enum JoyAxisSlot
+{
+ JOY_AXIS_SLOT_X,
+ JOY_AXIS_SLOT_Y,
+ JOY_AXIS_SLOT_Z,
+
+ JOY_AXIS_SLOT_MAX
+};
+
+
+// TODO: move to CRobotMain
extern long g_id; // unique identifier
-extern long g_build; // constructible buildings
-extern long g_researchDone; // research done
+extern int g_build; // constructible buildings
+extern int g_researchDone; // research done
extern long g_researchEnable; // research available
extern float g_unit; // conversion factor
-
-
diff --git a/src/common/image.cpp b/src/common/image.cpp
index 3d64377..50f6eee 100644
--- a/src/common/image.cpp
+++ b/src/common/image.cpp
@@ -21,6 +21,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <assert.h>
+
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <png.h>
@@ -88,21 +90,21 @@ bool PNGSaveSurface(const char *filename, SDL_Surface *surf)
/* Opening output file */
fp = fopen(filename, "wb");
- if (fp == NULL)
+ if (fp == nullptr)
{
PNG_ERROR = std::string("Could not open file '") + std::string(filename) + std::string("' for saving");
return false;
}
/* Initializing png structures and callbacks */
- png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, PNGUserError, NULL);
- if (png_ptr == NULL)
+ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, PNGUserError, nullptr);
+ if (png_ptr == nullptr)
return false;
info_ptr = png_create_info_struct(png_ptr);
- if (info_ptr == NULL)
+ if (info_ptr == nullptr)
{
- png_destroy_write_struct(&png_ptr, static_cast<png_infopp>(NULL));
+ png_destroy_write_struct(&png_ptr, static_cast<png_infopp>(nullptr));
PNG_ERROR = "png_create_info_struct() error!";
return false;
}
@@ -142,7 +144,7 @@ bool PNGSaveSurface(const char *filename, SDL_Surface *surf)
CImage::CImage()
{
- m_data = NULL;
+ m_data = nullptr;
}
CImage::~CImage()
@@ -150,22 +152,22 @@ CImage::~CImage()
Free();
}
-bool CImage::IsEmpty()
+bool CImage::IsEmpty() const
{
- return m_data == NULL;
+ return m_data == nullptr;
}
void CImage::Free()
{
- if (m_data != NULL)
+ if (m_data != nullptr)
{
- if (m_data->surface != NULL)
+ if (m_data->surface != nullptr)
{
SDL_FreeSurface(m_data->surface);
- m_data->surface = NULL;
+ m_data->surface = nullptr;
}
delete m_data;
- m_data = NULL;
+ m_data = nullptr;
}
}
@@ -174,6 +176,118 @@ ImageData* CImage::GetData()
return m_data;
}
+Math::IntPoint CImage::GetSize() const
+{
+ if (m_data == nullptr)
+ return Math::IntPoint();
+
+ return Math::IntPoint(m_data->surface->w, m_data->surface->h);
+}
+
+/**
+ * Image must be valid and pixel coords in valid range.
+ *
+ * \param pixel pixel coords (range x: 0..width-1 y: 0..height-1)
+ * \returns color
+ */
+Gfx::Color CImage::GetPixel(Math::IntPoint pixel)
+{
+ assert(m_data != nullptr);
+ assert(pixel.x >= 0 || pixel.x <= m_data->surface->w);
+ assert(pixel.y >= 0 || pixel.y <= m_data->surface->h);
+
+ int bpp = m_data->surface->format->BytesPerPixel;
+ int index = pixel.y * m_data->surface->pitch + pixel.x * bpp;
+ Uint8* p = &static_cast<Uint8*>(m_data->surface->pixels)[index];
+
+ Uint32 u = 0;
+ switch (bpp)
+ {
+ case 1:
+ u = *p;
+ break;
+
+ case 2:
+ u = *reinterpret_cast<Uint16*>(p);
+ break;
+
+ case 3:
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ u = (p[0] << 16) | (p[1] << 8) | p[2];
+ else
+ u = p[0] | (p[1] << 8) | (p[2] << 16);
+ break;
+
+ case 4:
+ u = *reinterpret_cast<Uint32*>(p);
+ break;
+
+ default:
+ assert(false);
+ }
+
+ Uint8 r = 0, g = 0, b = 0, a = 0;
+ SDL_GetRGBA(u, m_data->surface->format, &r, &g, &b, &a);
+
+ return Gfx::Color(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
+}
+
+/**
+ * Image must be valid and pixel coords in valid range.
+ *
+ * \param pixel pixel coords (range x: 0..width-1 y: 0..height-1)
+ * \param color color
+ */
+void CImage::SetPixel(Math::IntPoint pixel, Gfx::Color color)
+{
+ assert(m_data != nullptr);
+ assert(pixel.x >= 0 || pixel.x <= m_data->surface->w);
+ assert(pixel.y >= 0 || pixel.y <= m_data->surface->h);
+
+ int bpp = m_data->surface->format->BytesPerPixel;
+ int index = pixel.y * m_data->surface->pitch + pixel.x * bpp;
+ Uint8* p = &static_cast<Uint8*>(m_data->surface->pixels)[index];
+
+ Uint8 r = static_cast<Uint8>(color.r * 255.0f);
+ Uint8 g = static_cast<Uint8>(color.g * 255.0f);
+ Uint8 b = static_cast<Uint8>(color.b * 255.0f);
+ Uint8 a = static_cast<Uint8>(color.a * 255.0f);
+ Uint32 u = SDL_MapRGBA(m_data->surface->format, r, g, b, a);
+
+ switch(bpp)
+ {
+ case 1:
+ *p = u;
+ break;
+
+ case 2:
+ *reinterpret_cast<Uint16*>(p) = u;
+ break;
+
+ case 3:
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ {
+ p[0] = (u >> 16) & 0xFF;
+ p[1] = (u >> 8) & 0xFF;
+ p[2] = u & 0xFF;
+ }
+ else
+ {
+ p[0] = u & 0xFF;
+ p[1] = (u >> 8) & 0xFF;
+ p[2] = (u >> 16) & 0xFF;
+ }
+ break;
+
+ case 4:
+ *reinterpret_cast<Uint32*>(p) = u;
+ break;
+
+ default:
+ assert(false);
+ }
+}
+
std::string CImage::GetError()
{
return m_error;
@@ -189,10 +303,10 @@ bool CImage::Load(const std::string& fileName)
m_error = "";
m_data->surface = IMG_Load(fileName.c_str());
- if (m_data->surface == NULL)
+ if (m_data->surface == nullptr)
{
delete m_data;
- m_data = NULL;
+ m_data = nullptr;
m_error = std::string(IMG_GetError());
return false;
diff --git a/src/common/image.h b/src/common/image.h
index 4d86d31..93c7cab 100644
--- a/src/common/image.h
+++ b/src/common/image.h
@@ -14,10 +14,15 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
-// image.h
+/**
+ * \file common/image.h
+ * \brief Class for loading and saving images
+ */
#pragma once
+#include "graphics/core/color.h"
+#include "math/intpoint.h"
#include <stddef.h>
#include <string>
@@ -61,12 +66,21 @@ public:
//! Frees the allocated image data
void Free();
- //! Returns whether the image is empty (has NULL data)
- bool IsEmpty();
+ //! Returns whether the image is empty (has null data)
+ bool IsEmpty() const;
- //! Returns the image data; if empty - returns NULL
+ //! Returns the image data; if empty - returns nullptr
ImageData* GetData();
+ //! Returns the image size
+ Math::IntPoint GetSize() const;
+
+ //! Sets the color at given pixel
+ void SetPixel(Math::IntPoint pixel, Gfx::Color color);
+
+ //! Returns the color at given pixel
+ Gfx::Color GetPixel(Math::IntPoint pixel);
+
//! Loads an image from the specified file
bool Load(const std::string &fileName);
diff --git a/src/common/iman.cpp b/src/common/iman.cpp
index 4b89ecf..e59afb1 100644
--- a/src/common/iman.cpp
+++ b/src/common/iman.cpp
@@ -16,12 +16,10 @@
// iman.cpp
-
-#include <stdio.h>
-
-#include "common/struct.h"
#include "common/iman.h"
+#include <cassert>
+
template<> CInstanceManager* CSingleton<CInstanceManager>::mInstance = nullptr;
@@ -39,139 +37,91 @@ CInstanceManager* CInstanceManager::GetInstancePointer()
return mInstance;
}
-
-// Object's constructor.
-
CInstanceManager::CInstanceManager()
{
- int i;
-
- for ( i=0 ; i<CLASS_MAX ; i++ )
+ for (int i = 0; i < CLASS_MAX; i++)
{
- m_table[i].totalPossible = 0;
- m_table[i].totalUsed = 0;
- m_table[i].classPointer = 0;
+ m_table[i].maxCount = 0;
+ m_table[i].usedCount = 0;
+ m_table[i].instances = nullptr;
}
}
-// Object's destructor.
-
CInstanceManager::~CInstanceManager()
{
- int i;
-
- for ( i=0 ; i<CLASS_MAX ; i++ )
- {
- if ( m_table[i].classPointer != 0 )
- {
- free(m_table[i].classPointer);
- }
- }
+ Flush();
}
-
-// Empty the list of all classes.
-
void CInstanceManager::Flush()
{
- int i;
-
- for ( i=0 ; i<CLASS_MAX ; i++ )
+ for (int i = 0; i < CLASS_MAX; i++)
{
- if ( m_table[i].classPointer != 0 )
- {
- free(m_table[i].classPointer);
- }
- m_table[i].classPointer = 0;
+ if (m_table[i].instances != nullptr)
+ delete[] m_table[i].instances;
+
+ m_table[i].instances = nullptr;
}
}
-// Empty all instances of a given class.
-
-void CInstanceManager::Flush(ClassType classType)
+void CInstanceManager::Flush(ManagedClassType classType)
{
- if ( classType < 0 || classType >= CLASS_MAX ) return;
- if ( m_table[classType].classPointer == 0 ) return;
+ if (classType < 0 || classType >= CLASS_MAX) return;
+ if (m_table[classType].instances == nullptr) return;
- free(m_table[classType].classPointer);
- m_table[classType].classPointer = 0;
+ delete[] m_table[classType].instances;
+ m_table[classType].instances = nullptr;
}
-
-// Adds a new instance of a class.
-
-bool CInstanceManager::AddInstance(ClassType classType, void* pointer, int max)
+bool CInstanceManager::AddInstance(ManagedClassType classType, void* instance, int max)
{
- int i;
+ if (classType < 0 || classType >= CLASS_MAX) return false;
- if ( classType < 0 || classType >= CLASS_MAX ) return false;
-
- if ( m_table[classType].classPointer == 0 )
+ if (m_table[classType].instances == nullptr)
{
- m_table[classType].classPointer = static_cast<void**>( malloc(max*sizeof(void*)) );
- m_table[classType].totalPossible = max;
- m_table[classType].totalUsed = 0;
+ m_table[classType].instances = new void*[max];
+ m_table[classType].maxCount = max;
+ m_table[classType].usedCount = 0;
}
- if ( m_table[classType].totalUsed >= m_table[classType].totalPossible ) return false;
+ if (m_table[classType].usedCount >= m_table[classType].maxCount) return false;
- i = m_table[classType].totalUsed++;
- m_table[classType].classPointer[i] = pointer;
+ int i = m_table[classType].usedCount++;
+ m_table[classType].instances[i] = instance;
return true;
}
-// Deletes an instance of a class.
-
-bool CInstanceManager::DeleteInstance(ClassType classType, void* pointer)
+bool CInstanceManager::DeleteInstance(ManagedClassType classType, void* instance)
{
- int i;
-
- if ( classType < 0 || classType >= CLASS_MAX ) return false;
+ if (classType < 0 || classType >= CLASS_MAX) return false;
- for ( i=0 ; i<m_table[classType].totalUsed ; i++ )
+ for (int i = 0; i < m_table[classType].usedCount; i++)
{
- if ( m_table[classType].classPointer[i] == pointer )
- {
- m_table[classType].classPointer[i] = 0;
- }
+ if (m_table[classType].instances[i] == instance)
+ m_table[classType].instances[i] = nullptr;
}
Compress(classType);
return true;
}
-// Seeking an existing instance. Returns 0 if it does not exist.
-// Must be super fast!
-
-void* CInstanceManager::SearchInstance(ClassType classType, int rank)
+void* CInstanceManager::SearchInstance(ManagedClassType classType, int rank)
{
-#if _DEBUG
- if ( classType < 0 || classType >= CLASS_MAX ) return 0;
- if ( m_table[classType].classPointer == 0 ) return 0;
-#endif
- if ( rank >= m_table[classType].totalUsed ) return 0;
+ if (classType < 0 || classType >= CLASS_MAX) return nullptr;
+ if (m_table[classType].instances == nullptr) return nullptr;
+ if (rank >= m_table[classType].usedCount) return nullptr;
- return m_table[classType].classPointer[rank];
+ return m_table[classType].instances[rank];
}
-
-// Fills holes in a table.
-
-void CInstanceManager::Compress(ClassType classType)
+void CInstanceManager::Compress(ManagedClassType classType)
{
- int i, j;
+ if (classType < 0 || classType >= CLASS_MAX) return;
- if ( classType < 0 || classType >= CLASS_MAX ) return;
-
- j = 0;
- for ( i=0 ; i<m_table[classType].totalUsed ; i++ )
+ int j = 0;
+ for (int i = 0; i < m_table[classType].usedCount; i++)
{
- if ( m_table[classType].classPointer[i] != 0 )
- {
- m_table[classType].classPointer[j++] = m_table[classType].classPointer[i];
- }
+ if (m_table[classType].instances[i] != nullptr)
+ m_table[classType].instances[j++] = m_table[classType].instances[i];
}
- m_table[classType].totalUsed = j;
+ m_table[classType].usedCount = j;
}
-
-
diff --git a/src/common/iman.h b/src/common/iman.h
index 89b5206..44f143a 100644
--- a/src/common/iman.h
+++ b/src/common/iman.h
@@ -14,7 +14,10 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
-// iman.h
+/**
+ * \file iman.h
+ * \brief Instance manager for managed classes
+ */
#pragma once
@@ -22,36 +25,119 @@
#include <common/misc.h>
+/**
+ * \enum ManagedClassType
+ * \brief Type of class managed by CInstanceManager
+ */
-struct BaseClass
+// TODO: remove unnecessary, refactor to singletons, move to CRobotMain, keep others?
+
+enum ManagedClassType
{
- int totalPossible;
- int totalUsed;
- void** classPointer;
+ //! CEventQueue
+ CLASS_EVENT = 1,
+ //! Ui::CInterface
+ CLASS_INTERFACE = 2,
+ //! CRobotMain
+ CLASS_MAIN = 3,
+ //! Gfx::CEngine
+ CLASS_ENGINE = 4,
+ //! Gfx::CTerrain
+ CLASS_TERRAIN = 5,
+ //! CObject
+ CLASS_OBJECT = 6,
+ //! CPhysics
+ CLASS_PHYSICS = 7,
+ //! CBrain
+ CLASS_BRAIN = 8,
+ //! Gfx::CCamera
+ CLASS_CAMERA = 9,
+ //! Gfx::CLightManager
+ CLASS_LIGHT = 10,
+ //! Gfx::CParticle
+ CLASS_PARTICULE = 11,
+ //! CAuto; TODO: remove (unused)
+ CLASS_AUTO = 12,
+ //! Ui::CDisplayText
+ CLASS_DISPLAYTEXT = 13,
+ //! Gfx::CPyro
+ CLASS_PYRO = 14,
+ //! Ui::CScript; TODO: remove (unused)
+ CLASS_SCRIPT = 15,
+ //! Gfx::CText
+ CLASS_TEXT = 16,
+ //! Ui::CStudio, Ui::CDisplayText; TODO: remove (unused)
+ CLASS_STUDIO = 17,
+ //! Gfx::CWater
+ CLASS_WATER = 18,
+ //! Gfx::CCloud; TODO: remove (unused)
+ CLASS_CLOUD = 19,
+ //! CMotion; TODO: remove (unused)
+ CLASS_MOTION = 20,
+ //! CSoundInterface
+ CLASS_SOUND = 21,
+ //! Gfx::CPlanet
+ CLASS_PLANET = 22,
+ //! CTaskManager; TODO: remove (unused)
+ CLASS_TASKMANAGER = 23,
+ //! Ui::CMainDialog; TODO: remove (unused)
+ CLASS_DIALOG = 24,
+ //! Ui::CMainMap; TODO: remove (unused)
+ CLASS_MAP = 25,
+ //! Ui::CMainShort, CMainMovie; TODO: remove (unused)
+ CLASS_SHORT = 26,
+ //! Gfx::CLightning; TODO: remove (unused)
+ CLASS_BLITZ = 27,
+
+ //! Maximum (number of managed classes)
+ CLASS_MAX = 30
};
+/**
+ * \enum ManagedClassInstances
+ * \brief Instances of class managed by CInstanceManager
+ */
+struct ManagedClassInstances
+{
+ int maxCount;
+ int usedCount;
+ void** instances;
+};
+/**
+ * \class CInstanceManager
+ * \brief Manager for instances of certain classes
+ *
+ * Instance manager (often shortened to iMan) allows to register instances of
+ * classes and search them.
+ */
class CInstanceManager : public CSingleton<CInstanceManager>
{
public:
CInstanceManager();
~CInstanceManager();
+ //! Remove all managed instances
void Flush();
- void Flush(ClassType classType);
- bool AddInstance(ClassType classType, void* pointer, int max=1);
- bool DeleteInstance(ClassType classType, void* pointer);
- void* SearchInstance(ClassType classType, int rank=0);
+ //! Removes instances of one type of class
+ void Flush(ManagedClassType classType);
+ //! Registers new instance of class type
+ bool AddInstance(ManagedClassType classType, void* instance, int max=1);
+ //! Deletes the registered instance of class type
+ bool DeleteInstance(ManagedClassType classType, void* instance);
+ //! Seeks a class instance of given type
+ void* SearchInstance(ManagedClassType classType, int rank=0);
static CInstanceManager& GetInstance();
static CInstanceManager* GetInstancePointer();
protected:
- void Compress(ClassType classType);
+ //! Fills holes in instance table
+ void Compress(ManagedClassType classType);
protected:
- BaseClass m_table[CLASS_MAX];
+ ManagedClassInstances m_table[CLASS_MAX];
};
diff --git a/src/common/ioutils.h b/src/common/ioutils.h
index 2a542c6..e7668eb 100644
--- a/src/common/ioutils.h
+++ b/src/common/ioutils.h
@@ -14,7 +14,10 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
-// ioutils.h
+/**
+ * \file ioutils.h
+ * \brief Functions for binary I/O
+ */
#pragma once
diff --git a/src/common/key.h b/src/common/key.h
index de31c09..11076a3 100644
--- a/src/common/key.h
+++ b/src/common/key.h
@@ -29,6 +29,32 @@
// If need arises, it can be changed to custom function or anything else
#define KEY(x) SDLK_ ## x
+
// Key modifier defined as concatenation to KMOD_...
// If need arises, it can be changed to custom function or anything else
#define KEY_MOD(x) KMOD_ ## x
+
+/**
+ * \enum VirtualKmod
+ * \brief Virtual key codes generated on kmod presses
+ *
+ * These are provided here because left and right pair of keys generate different codes.
+ */
+enum VirtualKmod
+{
+ VIRTUAL_KMOD_CTRL = SDLK_LAST + 100, //! < control (left or right)
+ VIRTUAL_KMOD_SHIFT = SDLK_LAST + 101, //! < shift (left or right)
+ VIRTUAL_KMOD_ALT = SDLK_LAST + 102, //! < alt (left or right)
+ VIRTUAL_KMOD_META = SDLK_LAST + 103 //! < win key (left or right)
+};
+
+// Just syntax sugar
+// So it is the same as other macros
+#define VIRTUAL_KMOD(x) VIRTUAL_KMOD_ ## x
+
+// Virtual key code generated on joystick button presses
+// num is number of joystick button
+#define VIRTUAL_JOY(num) (SDLK_LAST + 200 + num)
+
+//! Special value for invalid key bindings
+const unsigned int KEY_INVALID = SDLK_LAST + 1000;
diff --git a/src/common/language.h b/src/common/language.h
deleted file mode 100644
index 82a7235..0000000
--- a/src/common/language.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// * This file is part of the COLOBOT source code
-// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
-// *
-// * 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://www.gnu.org/licenses/.
-
-// language.h
-
-#pragma once
-
-
-#define _FULL true // CoLoBoT
-#define _SCHOOL false // CeeBot-A or Teen
- #define _TEEN false // false for CeeBot-A, true for CeeBot-Teen
- #define _EDU false
- #define _PERSO false
- #define _CEEBOTDEMO false
-#define _NET false
-#define _DEMO false // DEMO only CoLoBoT (with _Full = false)!
-
-#define _FRENCH false
-#define _ENGLISH true
-#define _GERMAN false
-#define _WG false
-#define _POLISH false
-
-#define _NEWLOOK false // false for CoLoBoT, true for all CeeBot
-#define _SOUNDTRACKS false // always false since InitAudioTrackVolume crop in Vista
-
-
-// Verifications
-
-#if !_FULL & !_SCHOOL & !_NET & !_DEMO
--> no version chosen!
-#endif
-
-#if _SCHOOL
-#if !_EDU & !_PERSO & !_CEEBOTDEMO
--> EDU or PERSO or CEEBOTDEMO?
-#endif
-#if _EDU & _PERSO & _CEEBOTDEMO
--> EDU and PERSO and CEEBOTDEMO not at the same time!!!
-#endif
-#endif
diff --git a/src/common/logger.h b/src/common/logger.h
index fc43735..dfeeb98 100644
--- a/src/common/logger.h
+++ b/src/common/logger.h
@@ -14,22 +14,20 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
-// logger.h
+/**
+ * \file common/logger.h
+ * \brief Class for logging information to file or console
+ */
#pragma once
+#include "common/singleton.h"
+
#include <string>
#include <cstdarg>
#include <cstdio>
-#include <common/singleton.h>
-
-/**
- * @file common/logger.h
- * @brief Class for loggin information to file or console
- */
-
/**
* \public
diff --git a/src/common/metafile.cpp b/src/common/metafile.cpp
index 9d54f78..4e7e916 100644
--- a/src/common/metafile.cpp
+++ b/src/common/metafile.cpp
@@ -16,17 +16,15 @@
// metafile.cpp
-
-#include <windows.h>
-#include <stdio.h>
-
-#include "common/language.h"
#include "common/metafile.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
-#if _FULL | _NET
+//#if _FULL | _NET
static unsigned char table_codec[23] =
{
0x85, 0x91, 0x73, 0xcf, 0xa2, 0xbb, 0xf4, 0x77,
@@ -36,7 +34,7 @@ static unsigned char table_codec[23] =
void Codec(void* buffer, int len, int start)
{
- unsigned char *b = (unsigned char*)buffer;
+ unsigned char *b = static_cast<unsigned char*>(buffer);
int i;
for ( i=0 ; i<len ; i++ )
@@ -44,9 +42,9 @@ void Codec(void* buffer, int len, int start)
b[i] ^= table_codec[(start++)%23];
}
}
-#endif
+//#endif
-#if _SCHOOL
+/*#if _SCHOOL
#if _CEEBOTDEMO
static unsigned char table_codec[136] =
{
@@ -99,9 +97,9 @@ void Codec(void* buffer, int len, int start)
}
}
#endif
-#endif
+#endif*/
-#if _DEMO
+/*#if _DEMO
static unsigned char table_codec[27] =
{
0x85, 0x91, 0x77, 0xcf, 0xa3, 0xbb, 0xf4, 0x77,
@@ -120,7 +118,7 @@ void Codec(void* buffer, int len, int start)
b[i] ^= table_codec[(start++)%27];
}
}
-#endif
+#endif*/
@@ -286,7 +284,7 @@ int CMetaFile::Read(void *buffer, int size)
int CMetaFile::GetByte()
{
- BYTE b;
+ int b;
if ( !m_bOpen ) return 1;
@@ -303,7 +301,7 @@ int CMetaFile::GetByte()
int CMetaFile::GetWord()
{
- WORD w;
+ int w;
if ( !m_bOpen ) return 1;
@@ -352,7 +350,7 @@ int CMetaFile::MetaOpen(char *metaname)
strcpy(m_list[i].name, metaname); // memorized the name
fread(&m_list[i].total, sizeof(int), 1, m_list[i].stream);
- m_list[i].headers = (MetaHeader*)malloc(sizeof(MetaHeader)*m_list[i].total);
+ m_list[i].headers = static_cast<MetaHeader*>(malloc(sizeof(MetaHeader)*m_list[i].total));
offset = 4;
for ( j=0 ; j<m_list[i].total ; j++ )
diff --git a/src/common/misc.cpp b/src/common/misc.cpp
index 2427356..2ed6e2c 100644
--- a/src/common/misc.cpp
+++ b/src/common/misc.cpp
@@ -17,195 +17,171 @@
// misc.cpp
+#include "common/misc.h"
+
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <ctype.h>
-#include <direct.h>
#include <time.h>
-#include <d3d.h>
-
-#include "common/struct.h"
-#include "old/d3dengine.h"
-#include "old/d3dmath.h"
-#include "old/d3dutil.h"
-#include "common/language.h"
-#include "common/event.h"
-#include "common/misc.h"
-
-
-CMetaFile g_metafile;
-static EventMsg g_uniqueEventMsg = EVENT_USER;
static bool g_bUserDir = false;
static char g_userDir[100] = "";
-
-// Gives a single user event.
-
-EventMsg GetUniqueEventMsg()
-{
- int i;
-
- i = (int)g_uniqueEventMsg+1;
- g_uniqueEventMsg = (EventMsg)i;
- return g_uniqueEventMsg;
-}
-
-
-
// Returns a non-accented letter.
-char RetNoAccent(char letter)
+char GetNoAccent(char letter)
{
+ /*
if ( letter < 0 )
{
- if ( letter == 'á' ||
- letter == 'à' ||
- letter == 'â' ||
- letter == 'ä' ||
- letter == 'ã' ) return 'a';
-
- if ( letter == 'é' ||
- letter == 'è' ||
- letter == 'ê' ||
- letter == 'ë' ) return 'e';
-
- if ( letter == 'í' ||
- letter == 'ì' ||
- letter == 'î' ||
- letter == 'ï' ) return 'i';
-
- if ( letter == 'ó' ||
- letter == 'ò' ||
- letter == 'ô' ||
- letter == 'ö' ||
- letter == 'õ' ) return 'o';
-
- if ( letter == 'ú' ||
- letter == 'ù' ||
- letter == 'û' ||
- letter == 'ü' ) return 'u';
-
- if ( letter == 'ç' ) return 'c';
-
- if ( letter == 'ñ' ) return 'n';
-
- if ( letter == 'Á' ||
- letter == 'À' ||
- letter == 'Â' ||
- letter == 'Ä' ||
- letter == 'Ã' ) return 'A';
-
- if ( letter == 'É' ||
- letter == 'È' ||
- letter == 'Ê' ||
- letter == 'Ë' ) return 'E';
-
- if ( letter == 'Í' ||
- letter == 'Ì' ||
- letter == 'Î' ||
- letter == 'Ï' ) return 'I';
-
- if ( letter == 'Ó' ||
- letter == 'Ò' ||
- letter == 'Ô' ||
- letter == 'Ö' ||
- letter == 'Õ' ) return 'O';
-
- if ( letter == 'Ú' ||
- letter == 'Ù' ||
- letter == 'Û' ||
- letter == 'Ü' ) return 'U';
-
- if ( letter == 'Ç' ) return 'C';
-
- if ( letter == 'Ñ' ) return 'N';
- }
+ if ( letter == '�' ||
+ letter == '�' ||
+ letter == '�' ||
+ letter == '�' ||
+ letter == '�' ) return 'a';
+
+ if ( letter == '�' ||
+ letter == '�' ||
+ letter == '�' ||
+ letter == '�' ) return 'e';
+
+ if ( letter == '�' ||
+ letter == '�' ||
+ letter == '�' ||
+ letter == '�' ) return 'i';
+
+ if ( letter == '�' ||
+ letter == '�' ||
+ letter == '�' ||
+ letter == '�' ||
+ letter == '�' ) return 'o';
+
+ if ( letter == '�' ||
+ letter == '�' ||
+ letter == '�' ||
+ letter == '�' ) return 'u';
+
+ if ( letter == '�' ) return 'c';
+
+ if ( letter == '�' ) return 'n';
+
+ if ( letter == '�' ||
+ letter == '�' ||
+ letter == '�' ||
+ letter == '�' ||
+ letter == '�' ) return 'A';
+
+ if ( letter == '�' ||
+ letter == '�' ||
+ letter == '�' ||
+ letter == '�' ) return 'E';
+
+ if ( letter == '�' ||
+ letter == '�' ||
+ letter == '�' ||
+ letter == '�' ) return 'I';
+
+ if ( letter == '�' ||
+ letter == '�' ||
+ letter == '�' ||
+ letter == '�' ||
+ letter == '�' ) return 'O';
+
+ if ( letter == '�' ||
+ letter == '�' ||
+ letter == '�' ||
+ letter == '�' ) return 'U';
+
+ if ( letter == '�' ) return 'C';
+
+ if ( letter == '�' ) return 'N';
+ }*/
return letter;
}
// Returns an uppercase letter.
-char RetToUpper(char letter)
+char GetToUpper(char letter)
{
- if ( letter < 0 )
+ /*if ( letter < 0 )
{
- if ( letter == 'á' ) return 'Á';
- if ( letter == 'à' ) return 'À';
- if ( letter == 'â' ) return 'Â';
- if ( letter == 'ä' ) return 'Ä';
- if ( letter == 'ã' ) return 'Ã';
-
- if ( letter == 'é' ) return 'É';
- if ( letter == 'è' ) return 'È';
- if ( letter == 'ê' ) return 'Ê';
- if ( letter == 'ë' ) return 'Ë';
-
- if ( letter == 'í' ) return 'Í';
- if ( letter == 'ì' ) return 'Ì';
- if ( letter == 'î' ) return 'Î';
- if ( letter == 'ï' ) return 'Ï';
-
- if ( letter == 'ó' ) return 'Ó';
- if ( letter == 'ò' ) return 'Ò';
- if ( letter == 'ô' ) return 'Ô';
- if ( letter == 'ö' ) return 'Ö';
- if ( letter == 'õ' ) return 'Õ';
-
- if ( letter == 'ú' ) return 'Ú';
- if ( letter == 'ù' ) return 'Ù';
- if ( letter == 'û' ) return 'Û';
- if ( letter == 'ü' ) return 'Ü';
-
- if ( letter == 'ç' ) return 'Ç';
-
- if ( letter == 'ñ' ) return 'Ñ';
- }
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+
+ if ( letter == '�' ) return '�';
+
+ if ( letter == '�' ) return '�';
+ }*/
return toupper(letter);
}
// Returns a lowercase letter.
-char RetToLower(char letter)
+char GetToLower(char letter)
{
- if ( letter < 0 )
+ /*if ( letter < 0 )
{
- if ( letter == 'Á' ) return 'á';
- if ( letter == 'À' ) return 'à';
- if ( letter == 'Â' ) return 'â';
- if ( letter == 'Ä' ) return 'ä';
- if ( letter == 'Ã' ) return 'ã';
-
- if ( letter == 'É' ) return 'é';
- if ( letter == 'È' ) return 'è';
- if ( letter == 'Ê' ) return 'ê';
- if ( letter == 'Ë' ) return 'ë';
-
- if ( letter == 'Í' ) return 'í';
- if ( letter == 'Ì' ) return 'ì';
- if ( letter == 'Î' ) return 'î';
- if ( letter == 'Ï' ) return 'ï';
-
- if ( letter == 'Ó' ) return 'ó';
- if ( letter == 'Ò' ) return 'ò';
- if ( letter == 'Ô' ) return 'ô';
- if ( letter == 'Ö' ) return 'ö';
- if ( letter == 'Õ' ) return 'õ';
-
- if ( letter == 'Ú' ) return 'ú';
- if ( letter == 'Ù' ) return 'ù';
- if ( letter == 'Û' ) return 'û';
- if ( letter == 'Ü' ) return 'ü';
-
- if ( letter == 'Ç' ) return 'ç';
-
- if ( letter == 'Ñ' ) return 'ñ';
- }
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+ if ( letter == '�' ) return '�';
+
+ if ( letter == '�' ) return '�';
+
+ if ( letter == '�' ) return '�';
+ }*/
return tolower(letter);
}
@@ -222,6 +198,7 @@ void TimeToAscii(time_t time, char *buffer)
year = when.tm_year+1900;
if ( year < 2000 ) year -= 1900;
else year -= 2000;
+/* TODO
#if _FRENCH
sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d",
when.tm_mday, when.tm_mon+1, year,
@@ -232,7 +209,7 @@ void TimeToAscii(time_t time, char *buffer)
when.tm_mday, when.tm_mon+1, year,
when.tm_hour, when.tm_min);
#endif
-#if _ENGLISH
+#if _ENGLISH*/
char format[10];
int hour;
@@ -251,12 +228,12 @@ void TimeToAscii(time_t time, char *buffer)
sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d %s",
when.tm_mon+1, when.tm_mday, year,
hour, when.tm_min, format);
-#endif
+/*#endif
#if _POLISH
sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d",
when.tm_mday, when.tm_mon+1, year,
when.tm_hour, when.tm_min);
-#endif
+#endif*/
}
@@ -281,7 +258,7 @@ bool Xfer(char* src, char* dst)
return false;
}
- buffer = (char*)malloc(10000);
+ buffer = static_cast<char*>(malloc(10000));
while ( true )
{
@@ -311,7 +288,9 @@ bool CopyFileToTemp(char* filename)
UserDir(dst, filename, "textures");
strcpy(g_userDir, save);
- _mkdir("temp");
+ //_mkdir("temp");
+ system("mkdir temp");
+
if ( !Xfer(src, dst) ) return false;
strcpy(filename, dst);
@@ -359,7 +338,7 @@ bool CopyFileListToTemp(char* filename, int* list, int total)
// Adds an extension to file, if doesn't already one.
-void AddExt(char* filename, char* ext)
+void AddExt(char* filename, const char* ext)
{
if ( strchr(filename, '.') != 0 ) return; // already an extension?
strcat(filename, ext);
@@ -368,7 +347,7 @@ void AddExt(char* filename, char* ext)
// Specifies the user folder.
-void UserDir(bool bUser, char* dir)
+void UserDir(bool bUser, const char* dir)
{
g_bUserDir = bUser;
strcpy(g_userDir, dir);
@@ -379,10 +358,10 @@ void UserDir(bool bUser, char* dir)
// def = "abc\"
// out: buffer = "abc\toto.txt"
-void UserDir(char* buffer, char* dir, char* def)
+void UserDir(char* buffer, const char* dir, const char* def)
{
char ddir[100];
- char* add;
+ const char* add;
if ( strstr(dir, "\\") == 0 && def[0] != 0 )
{
@@ -418,24 +397,3 @@ void UserDir(char* buffer, char* dir, char* def)
}
*buffer = 0;
}
-
-
-// Returns the letter corresponding to the language.
-
-char RetLanguageLetter()
-{
-#if _FRENCH
- return 'F';
-#endif
-#if _ENGLISH
- return 'E';
-#endif
-#if _GERMAN | _WG
- return 'D';
-#endif
-#if _POLISH
- return 'P';
-#endif
- return 'X';
-}
-
diff --git a/src/common/misc.h b/src/common/misc.h
index dca801f..f6fd609 100644
--- a/src/common/misc.h
+++ b/src/common/misc.h
@@ -22,55 +22,7 @@
#include <time.h>
-#include "common/metafile.h"
-#include "common/event.h"
-#include "common/error_ids.h"
-
-
-extern CMetaFile g_metafile;
-
-
-
-// Existing classes.
-
-enum ClassType
-{
- CLASS_EVENT = 1,
- CLASS_INTERFACE = 2,
- CLASS_MAIN = 3,
- CLASS_ENGINE = 4,
- CLASS_TERRAIN = 5,
- CLASS_OBJECT = 6,
- CLASS_PHYSICS = 7,
- CLASS_BRAIN = 8,
- CLASS_CAMERA = 9,
- CLASS_LIGHT = 10,
- CLASS_PARTICULE = 11,
- CLASS_AUTO = 12,
- CLASS_DISPLAYTEXT = 13,
- CLASS_PYRO = 14,
- CLASS_SCRIPT = 15,
- CLASS_TEXT = 16,
- CLASS_STUDIO = 17,
- CLASS_WATER = 18,
- CLASS_CLOUD = 19,
- CLASS_MOTION = 20,
- CLASS_SOUND = 21,
- CLASS_PLANET = 22,
- CLASS_TASKMANAGER = 23,
- CLASS_DIALOG = 24,
- CLASS_MAP = 25,
- CLASS_SHORT = 26,
- CLASS_BLITZ = 27,
-};
-
-const int CLASS_MAX = 30;
-
-
-
-
-// Keyboard state.
-
+// TODO: to be removed (replaced by TrackedKey enum and mouse states in app.h)
const int KS_PAGEUP = (1<<4);
const int KS_PAGEDOWN = (1<<5);
const int KS_SHIFT = (1<<6);
@@ -84,23 +36,16 @@ const int KS_NUMRIGHT = (1<<13);
const int KS_NUMPLUS = (1<<14);
const int KS_NUMMINUS = (1<<15);
+// TODO: rewrite/refactor or remove
-// Procedures.
-
-extern EventType GetUniqueEventType();
-
-extern char RetNoAccent(char letter);
-extern char RetToUpper(char letter);
-extern char RetToLower(char letter);
+extern char GetNoAccent(char letter);
+extern char GetToUpper(char letter);
+extern char GetToLower(char letter);
extern void TimeToAscii(time_t time, char *buffer);
extern bool CopyFileToTemp(char* filename);
extern bool CopyFileListToTemp(char* filename, int* list, int total);
-extern void AddExt(char* filename, char* ext);
-extern void UserDir(bool bUser, char* dir);
-extern void UserDir(char* buffer, char* dir, char* def);
-
-extern char RetLanguageLetter();
-
-
+extern void AddExt(char* filename, const char* ext);
+extern void UserDir(bool bUser, const char* dir);
+extern void UserDir(char* buffer, const char* dir, const char* def);
diff --git a/src/common/profile.cpp b/src/common/profile.cpp
index 29a68e1..efcfa66 100644
--- a/src/common/profile.cpp
+++ b/src/common/profile.cpp
@@ -17,7 +17,10 @@
// profile.cpp
-#include <common/profile.h>
+#include "common/profile.h"
+
+#include <utility>
+#include <cstring>
template<> CProfile* CSingleton<CProfile>::mInstance = nullptr;
diff --git a/src/common/profile.h b/src/common/profile.h
index 0886522..7a23d94 100644
--- a/src/common/profile.h
+++ b/src/common/profile.h
@@ -14,22 +14,19 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
-// profile.h
+/**
+ * \file common/profile.h
+ * \brief Class for loading profile (currently for loading ini config file)
+ */
#pragma once
-#include <cstdlib>
-#include <vector>
-#include <utility>
-
-#include <lib/simpleini/SimpleIni.h>
+#include "lib/simpleini/SimpleIni.h"
-#include <common/singleton.h>
+#include "common/singleton.h"
-/**
- * @file common/profile.h
- * @brief Class for loading profile (currently for loading ini config file)
- */
+#include <string>
+#include <vector>
/**
diff --git a/src/common/restext.cpp b/src/common/restext.cpp
index 487d1a6..40d11b7 100644
--- a/src/common/restext.cpp
+++ b/src/common/restext.cpp
@@ -14,29 +14,21 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.// restext.cpp
-#include <libintl.h>
-#include <SDL/SDL_keyboard.h>
-#include "common/struct.h"
-#include "common/language.h"
-#include "common/misc.h"
+#include "common/restext.h"
+
+#include "common/global.h"
#include "common/event.h"
-#include "object/object.h"
+#include "common/logger.h"
#include "CBot/resource.h"
-#include "common/restext.h"
+#include "object/object.h"
+#include "object/robotmain.h"
+#include <libintl.h>
+#include <SDL/SDL_keyboard.h>
-// Gives the pointer to the engine.
-static CD3DEngine* g_engine;
static char g_gamerName[100];
-void SetEngine(CD3DEngine *engine)
-{
- g_engine = engine;
-}
-
-// Give the player's name.
-
void SetGlobalGamerName(char *name)
{
strcpy(g_gamerName, name);
@@ -46,39 +38,38 @@ void SetGlobalGamerName(char *name)
struct KeyDesc
{
- KeyRank key;
+ InputSlot key;
char name[20];
};
static KeyDesc keyTable[22] =
{
- { KEYRANK_LEFT, "left;" },
- { KEYRANK_RIGHT, "right;" },
- { KEYRANK_UP, "up;" },
- { KEYRANK_DOWN, "down;" },
- { KEYRANK_GUP, "gup;" },
- { KEYRANK_GDOWN, "gdown;" },
- { KEYRANK_CAMERA, "camera;" },
- { KEYRANK_DESEL, "desel;" },
- { KEYRANK_ACTION, "action;" },
- { KEYRANK_NEAR, "near;" },
- { KEYRANK_AWAY, "away;" },
- { KEYRANK_NEXT, "next;" },
- { KEYRANK_HUMAN, "human;" },
- { KEYRANK_QUIT, "quit;" },
- { KEYRANK_HELP, "help;" },
- { KEYRANK_PROG, "prog;" },
- { KEYRANK_CBOT, "cbot;" },
- { KEYRANK_VISIT, "visit;" },
- { KEYRANK_SPEED10, "speed10;" },
- { KEYRANK_SPEED15, "speed15;" },
- { KEYRANK_SPEED20, "speed20;" },
- { KEYRANK_SPEED30, "speed30;" },
+ { INPUT_SLOT_LEFT, "left;" },
+ { INPUT_SLOT_RIGHT, "right;" },
+ { INPUT_SLOT_UP, "up;" },
+ { INPUT_SLOT_DOWN, "down;" },
+ { INPUT_SLOT_GUP, "gup;" },
+ { INPUT_SLOT_GDOWN, "gdown;" },
+ { INPUT_SLOT_CAMERA, "camera;" },
+ { INPUT_SLOT_DESEL, "desel;" },
+ { INPUT_SLOT_ACTION, "action;" },
+ { INPUT_SLOT_NEAR, "near;" },
+ { INPUT_SLOT_AWAY, "away;" },
+ { INPUT_SLOT_NEXT, "next;" },
+ { INPUT_SLOT_HUMAN, "human;" },
+ { INPUT_SLOT_QUIT, "quit;" },
+ { INPUT_SLOT_HELP, "help;" },
+ { INPUT_SLOT_PROG, "prog;" },
+ { INPUT_SLOT_CBOT, "cbot;" },
+ { INPUT_SLOT_VISIT, "visit;" },
+ { INPUT_SLOT_SPEED10, "speed10;" },
+ { INPUT_SLOT_SPEED15, "speed15;" },
+ { INPUT_SLOT_SPEED20, "speed20;" }
};
// Seeks a key.
-bool SearchKey(const char *cmd, KeyRank &key)
+bool SearchKey(const char *cmd, InputSlot &key)
{
int i;
@@ -97,9 +88,10 @@ bool SearchKey(const char *cmd, KeyRank &key)
static void PutKeyName(char* dst, const char* src)
{
- KeyRank key;
+ InputSlot key;
char name[50];
- int s, d, n, res;
+ int s, d, n;
+ unsigned int res;
s = d = 0;
while ( src[s] != 0 )
@@ -112,9 +104,8 @@ static void PutKeyName(char* dst, const char* src)
{
if ( SearchKey(src+s+5, key) )
{
- // FIXME: res = g_engine->RetKey(key, 0);
- res = 0;
- if ( res != 0 )
+ res = CRobotMain::GetInstancePointer()->GetInputBinding(key).key;
+ if (res != KEY_INVALID)
{
if ( GetResource(RES_KEY, res, name) )
{
@@ -150,7 +141,12 @@ static const char* GetResourceBase(ResType type, int num)
str = strings_text[num];
break;
case RES_EVENT:
- assert(num < strings_event_len);
+ // assert(num < strings_event_len);
+ if (num >= strings_event_len)
+ {
+ GetLogger()->Warn("GetResource invalid event num: %d\n", num);
+ return "";
+ }
str = strings_event[num];
break;
case RES_OBJECT:
@@ -169,6 +165,7 @@ static const char* GetResourceBase(ResType type, int num)
break;
case RES_KEY:
assert(num < SDLK_LAST);
+ // TODO: virtual keys
str = SDL_GetKeyName(static_cast<SDLKey>(num));
break;
default:
diff --git a/src/common/restext.h b/src/common/restext.h
index 624803b..6abb7f5 100644
--- a/src/common/restext.h
+++ b/src/common/restext.h
@@ -14,32 +14,36 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
-// restext.h
+/**
+ * \file common/restext.h
+ * \brief Translation and string resource utilities
+ */
#pragma once
+#include "common/global.h"
#include "common/restext_ids.h"
-
-class CD3DEngine;
-
-// Possible types of the text resources.
-
+/**
+ * \enum ResType
+ * \brief Types of text resources
+ */
enum ResType
{
- RES_TEXT = 0, // RT_*
- RES_EVENT = 1, // EVENT_* (EventMsg)
- RES_OBJECT = 2, // OBJECT_* (ObjectType)
- RES_ERR = 3, // ERR_* (Error)
- RES_KEY = 4, // VK_* (keys)
- RES_CBOT = 5, // TX_* (cbot.dll)
+ RES_TEXT = 0, //! < RT_*
+ RES_EVENT = 1, //! < EVENT_* (EventMsg)
+ RES_OBJECT = 2, //! < OBJECT_* (ObjectType)
+ RES_ERR = 3, //! < ERR_* (Error)
+ RES_KEY = 4, //! < KEY() (keys)
+ RES_CBOT = 5, //! < TX_* (CBot)
};
-extern void SetEngine(CD3DEngine *engine);
+// TODO: move to CRobotMain
+
extern void SetGlobalGamerName(char *name);
-extern bool SearchKey(char *cmd, KeyRank &key);
+extern bool SearchKey(const char *cmd, InputSlot& slot);
extern bool GetResource(ResType type, int num, char* text);
extern const char * const strings_text[];
diff --git a/src/common/restext_ids.h b/src/common/restext_ids.h
index bee8620..4223a1c 100644
--- a/src/common/restext_ids.h
+++ b/src/common/restext_ids.h
@@ -14,6 +14,9 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
+
+// TODO: move to restext.h after restext rewrite
+
#pragma once
enum ResTextType
diff --git a/src/common/restext_strings.c b/src/common/restext_strings.c
index 8e9471b..d041a28 100644
--- a/src/common/restext_strings.c
+++ b/src/common/restext_strings.c
@@ -22,36 +22,8 @@
const char * const strings_text[] =
{
-#if _FULL
- [RT_VERSION_ID] = "1.18 /e",
-#endif
-#if _NET
- [RT_VERSION_ID] = "CeeBot-A 1.18",
-#endif
-#if _SCHOOL & _EDU
-#if _TEEN
- [RT_VERSION_ID] = "CeeBot-Teen EDU 1.18",
-#else
- [RT_VERSION_ID] = "CeeBot-A EDU 1.18",
-#endif
-#endif
-#if _SCHOOL & _PERSO
-#if _TEEN
- [RT_VERSION_ID] = "CeeBot-Teen PERSO 1.18",
-#else
- [RT_VERSION_ID] = "CeeBot-A PERSO 1.18",
-#endif
-#endif
-#if _SCHOOL & _CEEBOTDEMO
-#if _TEEN
- [RT_VERSION_ID] = "CeeBot-Teen DEMO 1.18",
-#else
- [RT_VERSION_ID] = "CeeBot-A DEMO 1.18",
-#endif
-#endif
-#if _DEMO
- [RT_VERSION_ID] = "Demo 1.18 /e",
-#endif
+ [RT_VERSION_ID] = "Colobot Gold",
+
[RT_DISINFO_TITLE] = "SatCom",
[RT_WINDOW_MAXIMIZED] = "Maximize",
[RT_WINDOW_MINIMIZED] = "Minimize",
@@ -64,13 +36,8 @@ const char * const strings_text[] =
[RT_IO_NEW] = "New ...",
[RT_KEY_OR] = " or ",
-#if _NEWLOOK
- [RT_TITLE_BASE] = "CeeBot",
- [RT_TITLE_INIT] = "CeeBot",
-#else
[RT_TITLE_BASE] = "COLOBOT",
[RT_TITLE_INIT] = "COLOBOT",
-#endif
[RT_TITLE_TRAINER] = "Programming exercises",
[RT_TITLE_DEFI] = "Challenges",
[RT_TITLE_MISSION] = "Missions",
@@ -111,15 +78,9 @@ const char * const strings_text[] =
[RT_PERSO_COMBI] = "Suit color:",
[RT_PERSO_BAND] = "Strip color:",
-#if _NEWLOOK
- [RT_DIALOG_QUIT] = "Do you want to quit CeeBot ?",
- [RT_DIALOG_TITLE] = "CeeBot",
- [RT_DIALOG_YESQUIT] = "Quit\\Quit CeeBot",
-#else
[RT_DIALOG_QUIT] = "Do you want to quit COLOBOT ?",
[RT_DIALOG_TITLE] = "COLOBOT",
[RT_DIALOG_YESQUIT] = "Quit\\Quit COLOBOT",
-#endif
[RT_DIALOG_ABORT] = "Quit the mission?",
[RT_DIALOG_YES] = "Abort\\Abort the current mission",
[RT_DIALOG_NO] = "Continue\\Continue the current mission",
@@ -182,13 +143,8 @@ const char * const strings_event[] =
[EVENT_INTERFACE_AGAIN] = "Restart\\Restart the mission from the beginning",
[EVENT_INTERFACE_WRITE] = "Save\\Save the current mission ",
[EVENT_INTERFACE_READ] = "Load\\Load a saved mission",
-#if _NEWLOOK
- [EVENT_INTERFACE_ABORT] = "\\Return to CeeBot",
- [EVENT_INTERFACE_QUIT] = "Quit\\Quit CeeBot",
-#else
[EVENT_INTERFACE_ABORT] = "\\Return to COLOBOT",
[EVENT_INTERFACE_QUIT] = "Quit\\Quit COLOBOT",
-#endif
[EVENT_INTERFACE_BACK] = "<< Back \\Back to the previous screen",
[EVENT_INTERFACE_PLAY] = "Play\\Start mission!",
[EVENT_INTERFACE_SETUPd] = "Device\\Driver and resolution settings",
@@ -432,11 +388,7 @@ const char * const strings_event[] =
[EVENT_HYPER_SIZE4] = "Size 4",
[EVENT_HYPER_SIZE5] = "Size 5",
[EVENT_SATCOM_HUSTON] = "Instructions from Houston",
-#if _TEEN
- [EVENT_SATCOM_SAT] = "Dictionnary",
-#else
[EVENT_SATCOM_SAT] = "Satellite report",
-#endif
[EVENT_SATCOM_LOADING] = "Programs dispatched by Houston",
[EVENT_SATCOM_OBJECT] = "List of objects",
[EVENT_SATCOM_PROG] = "Programming help",
@@ -475,11 +427,7 @@ const char * const strings_object[] =
[OBJECT_RESEARCH] = "Research center",
[OBJECT_RADAR] = "Radar station",
[OBJECT_INFO] = "Information exchange post",
-#if _TEEN
- [OBJECT_ENERGY] = "Disintegrator",
-#else
[OBJECT_ENERGY] = "Power cell factory",
-#endif
[OBJECT_LABO] = "Autolab",
[OBJECT_NUCLEAR] = "Nuclear power station",
[OBJECT_PARA] = "Lightning conductor",
@@ -574,13 +522,6 @@ const char * const strings_object[] =
const char * const strings_err[] =
{
[ERR_CMD] = "Unknown command",
-#if _NEWLOOK
- [ERR_INSTALL] = "CeeBot not installed.",
- [ERR_NOCD] = "Please insert the CeeBot CD\nand re-run the game.",
-#else
- [ERR_INSTALL] = "COLOBOT not installed.",
- [ERR_NOCD] = "Please insert the COLOBOT CD\nand re-run the game.",
-#endif
[ERR_MANIP_VEH] = "Inappropriate bot",
[ERR_MANIP_FLY] = "Impossible when flying",
[ERR_MANIP_BUSY] = "Already carrying something",
diff --git a/src/common/singleton.h b/src/common/singleton.h
index f631ed4..7407504 100644
--- a/src/common/singleton.h
+++ b/src/common/singleton.h
@@ -14,7 +14,10 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
-// singleton.h
+/**
+ * \file common/singleton.h
+ * \brief CSingleton base class for singletons
+ */
#pragma once
diff --git a/src/common/stringutils.h b/src/common/stringutils.h
index a0cae70..064351d 100644
--- a/src/common/stringutils.h
+++ b/src/common/stringutils.h
@@ -14,7 +14,10 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
-// stringutils.h
+/**
+ * \file common/stringutils.h
+ * \brief Some useful string operations
+ */
#pragma once
diff --git a/src/common/struct.h b/src/common/struct.h
deleted file mode 100644
index 45ac314..0000000
--- a/src/common/struct.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// * This file is part of the COLOBOT source code
-// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
-// *
-// * 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://www.gnu.org/licenses/.
-
-// struct.h
-
-#pragma once
-
-
-#include <math/vector.h>
-
-
-#define D3DFVF_VERTEX2 (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX2)
-
-struct D3DVERTEX2
-{
- float x,y,z;
- float nx,ny,nz;
- float tu, tv;
- float tu2, tv2;
-
- D3DVERTEX2() { }
- D3DVERTEX2(const Math::Vector& _v, const Math::Vector& _n, float _tu=0.0f, float _tv=0.0f, float _tu2=0.0f, float _tv2=0.0f)
- {
- x = _v.x;
- y = _v.y;
- z = _v.z;
- nx = _n.x;
- ny = _n.y;
- nz = _n.z;
- tu = _tu;
- tv = _tv;
- tu2 = _tu2;
- tv2 = _tv2;
- }
-};
-
-
-struct ColorHSV
-{
- float h,s,v;
-}; \ No newline at end of file
diff --git a/src/common/test/CMakeLists.txt b/src/common/test/CMakeLists.txt
index d81acab..a1a7a50 100644
--- a/src/common/test/CMakeLists.txt
+++ b/src/common/test/CMakeLists.txt
@@ -7,6 +7,8 @@ include_directories("../../")
include_directories("../../../")
add_executable(image_test ../image.cpp image_test.cpp)
+target_link_libraries(image_test -lpng -lSDL -lSDL_image)
+
add_executable(profile_test ../profile.cpp profile_test.cpp)
add_test(profile_test ./profile_test)
diff --git a/src/common/test/image_test.cpp b/src/common/test/image_test.cpp
index 0ad1ee2..a98c9cc 100644
--- a/src/common/test/image_test.cpp
+++ b/src/common/test/image_test.cpp
@@ -22,6 +22,29 @@ int main(int argc, char *argv[])
printf("Error loading '%s': %s\n", err.c_str());
return 1;
}
+ Gfx::Color color;
+ std::string str;
+
+ color = image.GetPixel(Math::IntPoint(0, 0));
+ str = color.ToString();
+ printf("pixel @ (0,0): %s\n", str.c_str());
+
+ color = image.GetPixel(Math::IntPoint(0, 1));
+ str = color.ToString();
+ printf("pixel @ (0,1): %s\n", str.c_str());
+
+ color = image.GetPixel(Math::IntPoint(1, 0));
+ str = color.ToString();
+ printf("pixel @ (1,0): %s\n", str.c_str());
+
+ color = image.GetPixel(Math::IntPoint(1, 1));
+ str = color.ToString();
+ printf("pixel @ (1,1): %s\n", str.c_str());
+
+ image.SetPixel(Math::IntPoint(0, 0), Gfx::Color(0.1f, 0.2f, 0.3f, 0.0f));
+ image.SetPixel(Math::IntPoint(1, 0), Gfx::Color(0.3f, 0.2f, 0.1f, 1.0f));
+ image.SetPixel(Math::IntPoint(0, 1), Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f));
+ image.SetPixel(Math::IntPoint(1, 1), Gfx::Color(0.0f, 0.0f, 0.0f, 1.0f));
if (! image.SavePNG(argv[2]))
{