fixed compilation under windows

- crashes sometimes for no obvious reason when loading fonts
main
Martin Felis (berta win) 2011-05-04 18:33:44 +02:00
parent b5c4ef359f
commit c2ca0a1a4d
18 changed files with 100 additions and 41 deletions

View File

@ -10,6 +10,9 @@ SET (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
SET (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
FIND_PACKAGE (SDL REQUIRED)
FIND_PACKAGE (SDL_net REQUIRED)
INCLUDE_DIRECTORIES (
engine/
asteroids/
@ -54,6 +57,11 @@ SET ( ASTEROIDSEDITOR_SOURCES
asteroids/View.cc
)
INCLUDE_DIRECTORIES (
${SDLMIXER_INCLUDE_DIRS}
${SDLNET_INCLUDE_DIRS}
)
ADD_EXECUTABLE ( fysxasteroids ${ASTEROIDS_SOURCES} )
ADD_EXECUTABLE ( fysxasteroidseditor ${ASTEROIDSEDITOR_SOURCES} )

View File

@ -38,9 +38,7 @@ void Controller::ResetPlayerEntity () {
Engine::EntityBase *player_entity = GetModel()->GetEntity(GetModel()->GetPlayerEntityId());
player_entity->mPhysicState->mAngleVelocity = 0.;
int i;
for (i = 0; i < EntityControllerMaxKeyStates; i++)
player_entity->UnsetControllerKeyState(i);
player_entity->ResetControllerKeyState();
}
// We definitely have to reset the player entity id

View File

@ -160,6 +160,7 @@ void Model::Process () {
}
unsigned int Model::InitLevelList () {
boost::filesystem::path level_dir_path;
std::string level_dir_name = Engine::GetResourceFullPath("/data/levels/");
Engine::LogDebug ("Searching for levels in %s", level_dir_name.c_str());
@ -167,12 +168,12 @@ unsigned int Model::InitLevelList () {
boost::filesystem::path level_dir(level_dir_name);
if (!boost::filesystem::exists(level_dir)) {
Engine::LogError ("Could not init level list: \todo %s does not exist!");
if (!boost::filesystem::exists(level_dir.file_string())) {
Engine::LogError ("Could not init level list: %s does not exist!", level_dir.filename());
}
if (!boost::filesystem::is_directory(level_dir)) {
Engine::LogError ("Could not init level list: \todo %s is not a directory!");
Engine::LogError ("Could not init level list: %s is not a directory!", level_dir_name.c_str());
}
boost::filesystem::directory_iterator end_iter;
@ -184,8 +185,8 @@ unsigned int Model::InitLevelList () {
level_relative_path += dir_iter->path().filename();
// check whether we found an official level
std::string map_name (level_relative_path);
map_name = map_name.substr(map_name.rfind ('/') + 1, map_name.size());
std::string map_name (dir_iter->filename());
if (mLevelHashes.find(map_name) == mLevelHashes.end()) {
Engine::LogDebug ("Skipping unofficial level %s", std::string(level_relative_path).c_str());
continue;
@ -559,7 +560,7 @@ void Model::SubmitHighscoreEntry (const std::string &name, const unsigned int po
int Model::DoLoadLevel (const char* filename) {
// verify the hash of the map
std::string map_name (filename);
map_name = map_name.substr(map_name.rfind ('/') + 1, map_name.size());
map_name = boost::filesystem::path(map_name).filename();
std::string map_hash = sha256_hash_file (filename);
if (map_hash != mLevelHashes[map_name]) {
Engine::LogMessage ("Map verification for file %s failed!", map_name.c_str());

View File

@ -116,22 +116,29 @@ int main (int argc, char* argv[]) {
SetLogPrintLevel (Engine::LogLevelWarning);
std::string user_path = ".";
std::string game_data_path = ".";
std::string user_path = "";
std::string game_data_path = "";
#ifndef WIN32
user_path = create_user_path();
game_data_path = find_game_data_dir();
#endif
boost::filesystem::path cpath = boost::filesystem::initial_path<boost::filesystem::path>();
std::cerr << "cwd: " << cpath.string() << std::endl;
// we assume the user path to be local folder
std::string log_file_path = user_path;
log_file_path += "/game.log";
user_path = boost::filesystem::path(cpath.string() + user_path).file_string();
game_data_path = boost::filesystem::path(cpath.string() + game_data_path).file_string();
log_file_path = boost::filesystem::path (cpath.string() + log_file_path).file_string();
cout << "User Data Dir = " << user_path << endl;
engine.SetUserDataPath (user_path);
Engine::SetLogFilename (log_file_path.c_str());
Engine::SetLogFilename (log_file_path);
engine.SetGameDataPath (game_data_path);
cout << "Game Data Dir = " << game_data_path << endl;

View File

@ -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:

View File

@ -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 ();
}
}

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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 ();

View File

@ -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
*

View File

@ -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);

View File

@ -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,7 +335,7 @@ 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());
font_iter = mFonts.find(font);

View File

@ -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>

View File

@ -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 )
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();
}

View File

@ -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

View File

@ -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
/*

View File

@ -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) */