fixed compilation under windows
- crashes sometimes for no obvious reason when loading fonts
This commit is contained in:
+4
-2
@@ -18,6 +18,8 @@
|
||||
#include <bitset>
|
||||
#include <limits>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "Module.h"
|
||||
#include "EngineEnums.h"
|
||||
#include "Utils.h"
|
||||
@@ -115,13 +117,13 @@ class Engine : public Module {
|
||||
* \brief it
|
||||
*/
|
||||
std::string GetResourceFullPath (const std::string &resource) {
|
||||
return mGameDataPath + resource;
|
||||
return boost::filesystem::path(mGameDataPath + resource).file_string();
|
||||
};
|
||||
|
||||
/** \brief Returns the path to a file by prepending the user data path to it
|
||||
*/
|
||||
std::string GetUserDirFullPath (const std::string &path) {
|
||||
return mUserDataPath + path;
|
||||
return boost::filesystem::path(mUserDataPath + path).file_string();
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
+16
-2
@@ -13,17 +13,22 @@ bool EntityControllerState::GetKey (int state) {
|
||||
void EntityControllerState::SetKey (int state) {
|
||||
assert (state < EntityControllerMaxKeyStates && state >= 0);
|
||||
|
||||
LogDebug ("Setting Entity Key State %d", state);
|
||||
LogDebug ("Entity %d: Setting Entity Key State %d", mId, state);
|
||||
mKeyState.set (state);
|
||||
}
|
||||
|
||||
void EntityControllerState::UnsetKey (int state) {
|
||||
assert (state < EntityControllerMaxKeyStates && state >= 0);
|
||||
|
||||
LogDebug ("Unsetting Entity Key State %d", state);
|
||||
LogDebug ("Entity %d: Unsetting Entity Key State %d", mId, state);
|
||||
mKeyState.reset (state);
|
||||
}
|
||||
|
||||
void EntityControllerState::Reset () {
|
||||
LogDebug ("Entity %d: Resetting all key states", mId);
|
||||
mKeyState.reset ();
|
||||
}
|
||||
|
||||
void EntityBase::SetControllerKeyState (int state) {
|
||||
if (!mControllerState) {
|
||||
LogError ("Error when trying to send a KeyState to an Entity that has no EntityControllerState!");
|
||||
@@ -40,4 +45,13 @@ void EntityBase::UnsetControllerKeyState (int state) {
|
||||
mControllerState->UnsetKey (state);
|
||||
}
|
||||
|
||||
void EntityBase::ResetControllerKeyState () {
|
||||
if (!mControllerState) {
|
||||
LogError ("Error when trying to send a KeyState to an Entity that has no EntityControllerState!");
|
||||
}
|
||||
|
||||
LogDebug ("Entity %d: Resetting key states", mId);
|
||||
mControllerState->Reset ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -100,11 +100,14 @@ struct EntityPhysicState {
|
||||
* \todo [Low] The current design is very unflexible. Is there a better way?
|
||||
*/
|
||||
struct EntityControllerState {
|
||||
unsigned int mId;
|
||||
|
||||
std::bitset<EntityControllerMaxKeyStates> mKeyState;
|
||||
|
||||
bool GetKey (int state);
|
||||
void SetKey (int state);
|
||||
void UnsetKey (int state);
|
||||
void Reset ();
|
||||
};
|
||||
|
||||
/** \brief Represents the base of everything that exists in the engine
|
||||
@@ -131,6 +134,8 @@ struct EntityBase {
|
||||
virtual void SetControllerKeyState (int state);
|
||||
/** \brief Removes the given state to the current movement state of the Entity */
|
||||
virtual void UnsetControllerKeyState (int state);
|
||||
/** \brief Resets all keys (i.e. no keys are pressed) */
|
||||
virtual void ResetControllerKeyState ();
|
||||
|
||||
/** \brief Helper function to set the id to all substates */
|
||||
void SetId (unsigned int id) {
|
||||
@@ -138,6 +143,8 @@ struct EntityBase {
|
||||
|
||||
if (mPhysicState)
|
||||
mPhysicState->mId = id;
|
||||
if (mControllerState)
|
||||
mControllerState->mId = id;
|
||||
}
|
||||
|
||||
/** Executes game logic for the collision event
|
||||
|
||||
@@ -250,7 +250,7 @@ bool Button (int id, const char* caption, int x, int y, int w, int h) {
|
||||
SelectFont("console.ttf size=23 color=#ffffff");
|
||||
view->DrawGLString( xpos, ypos, caption);
|
||||
} else {
|
||||
SelectFont("console.ttf size=23 color=#4d4d4d");
|
||||
SelectFont("console.ttf size=23 color=#444444");
|
||||
view->DrawGLString( xpos - 2., ypos + 2., caption);
|
||||
SelectFont("console.ttf size=23 color=#b3b3b3");
|
||||
view->DrawGLString( xpos, ypos, caption);
|
||||
@@ -371,7 +371,7 @@ bool CheckButton (int id, const char* caption, bool checked, int x, int y, int w
|
||||
SelectFont("console.ttf size=23 color=#ffffff");
|
||||
view->DrawGLString( xpos, ypos, caption);
|
||||
} else {
|
||||
SelectFont("console.ttf size=23 color=#4d4d4d");
|
||||
SelectFont("console.ttf size=23 color=#444444");
|
||||
view->DrawGLString( xpos - 2., ypos + 2., caption);
|
||||
SelectFont("console.ttf size=23 color=#b3b3b3");
|
||||
view->DrawGLString( xpos, ypos, caption);
|
||||
|
||||
+4
-4
@@ -90,11 +90,11 @@ void Logging::SetLogPrintLevel (LogLevel print_level) {
|
||||
mPrintLevel = print_level;
|
||||
}
|
||||
|
||||
void Logging::SetLogFilename (const char *filename) {
|
||||
mLogFileOut.open (filename, std::ios_base::trunc);
|
||||
void Logging::SetLogFilename (const std::string &filename) {
|
||||
mLogFileOut.open (filename.c_str(), std::ios_base::trunc);
|
||||
|
||||
if (!mLogFileOut) {
|
||||
LogError ("Could not open logfile %s for writing!", filename);
|
||||
LogError ("Could not open logfile %s for writing!", filename.c_str());
|
||||
}
|
||||
|
||||
requested_logfilename = "";
|
||||
@@ -122,7 +122,7 @@ void SetLogPrintLevel (LogLevel print_level) {
|
||||
LoggingInstance->SetLogPrintLevel (print_level);
|
||||
}
|
||||
|
||||
void SetLogFilename (const char *filename) {
|
||||
void SetLogFilename (const std::string &filename) {
|
||||
if (!LoggingInstance) {
|
||||
requested_logfilename = filename;
|
||||
return;
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ class Logging : public Module {
|
||||
public:
|
||||
void Log (LogLevel level, const char *str, ...);
|
||||
void SetLogPrintLevel (LogLevel print_level);
|
||||
void SetLogFilename (const char *filename);
|
||||
void SetLogFilename (const std::string &filename);
|
||||
/** \brief Returns the last LogEntry that was sent to the Logging module
|
||||
*/
|
||||
const LogEntry& GetLastEntry ();
|
||||
|
||||
@@ -24,7 +24,7 @@ struct LogEntry {
|
||||
/** \brief Sets the level for which messages should be printed out */
|
||||
void SetLogPrintLevel (LogLevel print_level);
|
||||
/** \brief Sets the filename to which all the logging is sent, set to NULL to disable logging */
|
||||
void SetLogFilename (const char *filename);
|
||||
void SetLogFilename (const std::string &filename);
|
||||
|
||||
/** \brief Sends the Message to the Logging system
|
||||
*
|
||||
|
||||
+6
-4
@@ -43,7 +43,8 @@ bool create_dir (const std::string &dir_str) {
|
||||
}
|
||||
|
||||
std::string sha256_hash (std::string input) {
|
||||
char result_buf[64];
|
||||
char result_buf[65];
|
||||
result_buf[64] = '\0';
|
||||
|
||||
SHA256_CTX ctx256;
|
||||
|
||||
@@ -51,7 +52,7 @@ std::string sha256_hash (std::string input) {
|
||||
SHA256_Update(&ctx256, (unsigned char*) input.c_str(), input.size());
|
||||
SHA256_End (&ctx256, result_buf);
|
||||
|
||||
return std::string (result_buf, 64);
|
||||
return std::string (result_buf);
|
||||
}
|
||||
|
||||
std::string sha256_hash_file (const char *filename) {
|
||||
@@ -62,7 +63,6 @@ std::string sha256_hash_file (const char *filename) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
file_stream.seekg (0,std::ios_base::end);
|
||||
std::streampos file_end = file_stream.tellg();
|
||||
|
||||
@@ -78,7 +78,7 @@ std::string sha256_hash_file (const char *filename) {
|
||||
file_stream.seekg(0, std::ios_base::beg);
|
||||
file_stream.read ((char*)file_buffer, file_size);
|
||||
|
||||
char result_buf[64];
|
||||
char result_buf[65];
|
||||
|
||||
SHA256_CTX ctx256;
|
||||
|
||||
@@ -90,6 +90,8 @@ std::string sha256_hash_file (const char *filename) {
|
||||
|
||||
delete[] file_buffer;
|
||||
|
||||
result_buf[64] = '\0';
|
||||
|
||||
// std::cerr << "file hash is " << std::string (result_buf, 64) << std::endl;
|
||||
|
||||
return std::string (result_buf, 64);
|
||||
|
||||
+4
-4
@@ -312,7 +312,7 @@ bool ViewBase::LoadFont (const std::string &font_spec_string) {
|
||||
|
||||
OGLFT::Monochrome *font = new OGLFT::Monochrome (font_path.c_str(), font_size);
|
||||
if ( font == 0 || !font->isValid() ) {
|
||||
LogError ("Could not load font %s!", font_path.c_str());
|
||||
LogError ("Could not load font %s! (ptr=%x", font_path.c_str(), (void*)font);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ bool ViewBase::LoadFont (const std::string &font_spec_string) {
|
||||
font->setBackgroundColor(0., 0., 0., 0.);
|
||||
|
||||
mFonts.insert(std::make_pair<std::string, OGLFT::Monochrome*>(font_spec_string, font));
|
||||
|
||||
LogDebug ("Loading font %s successful!", font_name.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -335,9 +335,9 @@ void ViewBase::SelectFont (const char *font) {
|
||||
}
|
||||
|
||||
LogDebug ("Selecting font %s failed, trying to load it", font);
|
||||
LogDebug ("font count = %d", mFonts.size());
|
||||
|
||||
if (LoadFont (font)) {
|
||||
LogDebug ("font count = %d", mFonts.size());
|
||||
LogDebug ("font count = %d", mFonts.size());
|
||||
font_iter = mFonts.find(font);
|
||||
|
||||
assert (mFonts.find(font) != mFonts.end());
|
||||
|
||||
@@ -8,7 +8,12 @@
|
||||
#define VIEW_DEFAULT_WIDTH 800
|
||||
|
||||
#ifdef WIN32
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
|
||||
|
||||
#include <cmath>
|
||||
inline double roundf(double x) { return floor(x + 0.5); }
|
||||
#endif
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
@@ -89,8 +89,11 @@ namespace OGLFT {
|
||||
FT_Face ft_face;
|
||||
|
||||
FT_Error error = FT_New_Face( Library::instance(), filename, 0, &ft_face );
|
||||
assert (0);
|
||||
std::cerr << "FreeType error code: " << error << std::endl;
|
||||
|
||||
if ( error != 0 ) {
|
||||
std::cerr << "FreeType error code: " << error << std::endl;
|
||||
valid_ = false;
|
||||
return;
|
||||
}
|
||||
@@ -178,8 +181,10 @@ namespace OGLFT {
|
||||
|
||||
FT_Error error = FT_New_Face( Library::instance(), filename, 0, &ft_face );
|
||||
|
||||
if ( error != 0 )
|
||||
return false;
|
||||
if ( error != 0 ) {
|
||||
std::cerr << "FreeType error code: " << error << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
faces_.push_back( FaceData( ft_face ) );
|
||||
|
||||
@@ -406,7 +411,10 @@ namespace OGLFT {
|
||||
FT_Error error = FT_Load_Glyph( faces_[f].face_, glyph_index,
|
||||
FT_LOAD_DEFAULT );
|
||||
|
||||
if ( error != 0 ) return;
|
||||
if ( error != 0 ) {
|
||||
std::cerr << "FreeType error code: " << error << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
rotation_reference_glyph_ = glyph_index;
|
||||
|
||||
@@ -1348,6 +1356,8 @@ namespace OGLFT {
|
||||
{
|
||||
if ( !isValid() ) return;
|
||||
|
||||
std::cerr << "Raster is valid!" << std::endl;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
@@ -619,7 +619,7 @@ namespace OGLFT {
|
||||
* \param blue the blue component of the background color.
|
||||
* \param alpha the alpha component of the background color.
|
||||
*/
|
||||
void setBackgroundColor ( GLfloat red = 1.0,
|
||||
OGLFT_API void setBackgroundColor ( GLfloat red = 1.0,
|
||||
GLfloat green = 1.0,
|
||||
GLfloat blue = 1.0,
|
||||
GLfloat alpha = 0.0 );
|
||||
@@ -631,7 +631,7 @@ namespace OGLFT {
|
||||
* \param background_color an array of 4 values corresponding to the
|
||||
* red, green, blue and alpha components of the background color.
|
||||
*/
|
||||
void setBackgroundColor ( const GLfloat background_color[4] );
|
||||
OGLFT_API void setBackgroundColor ( const GLfloat background_color[4] );
|
||||
#ifndef OGLFT_NO_QT
|
||||
/*!
|
||||
* This is the nominal background color of the glyphs. A lot of other things
|
||||
|
||||
@@ -86,7 +86,12 @@
|
||||
* made).
|
||||
*/
|
||||
#if !defined(BYTE_ORDER) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN)
|
||||
#error Define BYTE_ORDER to be equal to either LITTLE_ENDIAN or BIG_ENDIAN
|
||||
#ifdef WIN32
|
||||
#define LITTLE_ENDIAN 12345
|
||||
#define BYTE_ORDER LITTLE_ENDIAN
|
||||
#else
|
||||
#error Define BYTE_ORDER to be equal to either LITTLE_ENDIAN or BIG_ENDIAN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
@@ -71,7 +71,7 @@ extern "C" {
|
||||
* uintXX_t (from inttypes.h), you may need to define things by hand
|
||||
* for your system:
|
||||
*/
|
||||
#if 0
|
||||
#if 1
|
||||
typedef unsigned char u_int8_t; /* 1-byte (8-bits) */
|
||||
typedef unsigned int u_int32_t; /* 4-bytes (32-bits) */
|
||||
typedef unsigned long long u_int64_t; /* 8-bytes (64-bits) */
|
||||
|
||||
Reference in New Issue
Block a user