summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authorpauldubois <pauldubois@c06c8d41-db1a-0410-9941-cceddc491573>2008-03-10 06:31:01 +0000
committerpauldubois <pauldubois@c06c8d41-db1a-0410-9941-cceddc491573>2008-03-10 06:31:01 +0000
commit8a737d409cea505589f5b67fab49f138265a8174 (patch)
treedf38e20bb1eed6abd6c3603094e109aec11fa96e /crawl-ref/source
parent70b1954c4daae8ee3f364481d0bc245a81720513 (diff)
downloadcrawl-ref-8a737d409cea505589f5b67fab49f138265a8174.tar.gz
crawl-ref-8a737d409cea505589f5b67fab49f138265a8174.zip
Another batch of msvc compile fixes.
Added wrapper implementation for opendir/readdir Other functions left stubbed out. It's a shame that crawl's "direct.h" conflicts with <direct.h>. Fixed up use of AppHdr.h in a couple places (it must be included first); changed project to use precompiled headers. crawl now compiles cleanly but doesn't link. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3573 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/AppHdr.h6
-rw-r--r--crawl-ref/source/FixVec.h5
-rw-r--r--crawl-ref/source/MSVC/crawl-ref.vcproj112
-rw-r--r--crawl-ref/source/dungeon.cc2
-rw-r--r--crawl-ref/source/files.cc9
-rw-r--r--crawl-ref/source/hiscores.cc7
-rw-r--r--crawl-ref/source/initfile.cc3
-rw-r--r--crawl-ref/source/libutil.cc2
-rw-r--r--crawl-ref/source/libw32c.cc115
-rw-r--r--crawl-ref/source/maps.cc2
-rw-r--r--crawl-ref/source/misc.cc6
-rw-r--r--crawl-ref/source/msvc.h50
-rw-r--r--crawl-ref/source/notes.cc2
-rw-r--r--crawl-ref/source/religion.cc2
-rw-r--r--crawl-ref/source/tags.cc8
-rw-r--r--crawl-ref/source/tile1.cc3
-rw-r--r--crawl-ref/source/tile2.cc4
-rw-r--r--crawl-ref/source/tutorial.cc4
18 files changed, 270 insertions, 72 deletions
diff --git a/crawl-ref/source/AppHdr.h b/crawl-ref/source/AppHdr.h
index 899a818d53..adf517303f 100644
--- a/crawl-ref/source/AppHdr.h
+++ b/crawl-ref/source/AppHdr.h
@@ -383,7 +383,6 @@
//jmf: end of new defines
// ====================== -----------------------------------------------------
-
#ifdef MULTIUSER
// If you are installing Crawl for multiple users, define SAVE_DIR
// to the directory where saves, bones, and score file will go...
@@ -439,7 +438,7 @@
#include <sys/types.h>
#include <sys/stat.h>
-#endif
+#endif /* MULTIUSER */
#if defined(DGL_SIMPLE_MESSAGING) && !defined(USE_FILE_LOCKING)
# error Must define USE_FILE_LOCKING for DGL_SIMPLE_MESSAGING
@@ -461,4 +460,7 @@ inline void UNUSED(const volatile T &)
{
}
+// And now headers we want precompiled
+#include <externs.h>
+
#endif
diff --git a/crawl-ref/source/FixVec.h b/crawl-ref/source/FixVec.h
index 6fd2f91caa..06a7f919fc 100644
--- a/crawl-ref/source/FixVec.h
+++ b/crawl-ref/source/FixVec.h
@@ -14,6 +14,11 @@
#ifndef FIXVEC_H
#define FIXVEC_H
+#if _MSC_VER
+// Benign: FixedVector has an array in member init list
+# pragma warning(disable : 4351)
+#endif
+
#include <cstdarg>
#include <cstring>
diff --git a/crawl-ref/source/MSVC/crawl-ref.vcproj b/crawl-ref/source/MSVC/crawl-ref.vcproj
index 332f3c27a7..168c25d5d1 100644
--- a/crawl-ref/source/MSVC/crawl-ref.vcproj
+++ b/crawl-ref/source/MSVC/crawl-ref.vcproj
@@ -20,7 +20,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
- CharacterSet="1"
+ CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
@@ -45,7 +45,8 @@
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
- UsePrecompiledHeader="0"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderThrough="AppHdr.h"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
@@ -119,7 +120,8 @@
AdditionalIncludeDirectories="util/lua/src"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="2"
- UsePrecompiledHeader="0"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderThrough="AppHdr.h"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
@@ -190,6 +192,22 @@
<File
RelativePath="..\acr.cc"
>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="1"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="1"
+ />
+ </FileConfiguration>
</File>
<File
RelativePath="..\AppHdr.h"
@@ -254,6 +272,22 @@
<File
RelativePath="..\database.cc"
>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="0"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="0"
+ />
+ </FileConfiguration>
</File>
<File
RelativePath="..\database.h"
@@ -400,14 +434,6 @@
>
</File>
<File
- RelativePath="..\insult.cc"
- >
- </File>
- <File
- RelativePath="..\insult.h"
- >
- </File>
- <File
RelativePath="..\invent.cc"
>
</File>
@@ -480,30 +506,6 @@
>
</File>
<File
- RelativePath="..\libdos.cc"
- >
- </File>
- <File
- RelativePath="..\libdos.h"
- >
- </File>
- <File
- RelativePath="..\libgui.cc"
- >
- </File>
- <File
- RelativePath="..\libgui.h"
- >
- </File>
- <File
- RelativePath="..\libunix.cc"
- >
- </File>
- <File
- RelativePath="..\libunix.h"
- >
- </File>
- <File
RelativePath="..\libutil.cc"
>
</File>
@@ -514,20 +516,28 @@
<File
RelativePath="..\libw32c.cc"
>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="2"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="2"
+ />
+ </FileConfiguration>
</File>
<File
RelativePath="..\libw32c.h"
>
</File>
<File
- RelativePath="..\libwt.cc"
- >
- </File>
- <File
- RelativePath="..\libx11.cc"
- >
- </File>
- <File
RelativePath="..\luadgn.cc"
>
</File>
@@ -670,6 +680,22 @@
<File
RelativePath="..\mt19937ar.cc"
>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="0"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="0"
+ />
+ </FileConfiguration>
</File>
<File
RelativePath="..\mt19937ar.h"
diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc
index 828559db35..cec70d8cce 100644
--- a/crawl-ref/source/dungeon.cc
+++ b/crawl-ref/source/dungeon.cc
@@ -1170,7 +1170,7 @@ void dgn_set_colours_from_monsters()
env.rock_colour = BROWN;
}
else
- env.rock_colour = fix_black_colour(mcolour[env.mons_alloc[8]]);
+ env.rock_colour = fix_black_colour((char)mcolour[env.mons_alloc[8]]);
}
static void dgn_set_floor_colours()
diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc
index de893583a1..a1572e51cd 100644
--- a/crawl-ref/source/files.cc
+++ b/crawl-ref/source/files.cc
@@ -52,7 +52,10 @@
#include <sys/types.h>
#include <sys/stat.h>
-#if !_MSC_VER
+#if _MSC_VER
+// # include <direct.h> conflicts with crawl's header. Yes this sucks
+# include <c:/Program Files/Microsoft Visual Studio 8/VC/include/direct.h>
+#else
#include <dirent.h>
#endif
@@ -113,7 +116,7 @@ void save_level(int level_saved, level_area_type lt,
// 2: append piety_hysteresis to TAG_YOU
#define YOU_MINOR_VERSION 2
-const short GHOST_SIGNATURE = static_cast<short>( 0xDC55 );
+const short GHOST_SIGNATURE = short( 0xDC55 );
static void redraw_all(void)
{
@@ -333,6 +336,8 @@ static int create_directory(const char *dir)
return mkdir(dir, SHARED_FILES_CHMOD_PUBLIC | 0111);
#elif defined(DOS)
return mkdir(dir, 0755);
+#elif defined(_MSC_VER)
+ return _mkdir(dir);
#else
return mkdir(dir);
#endif
diff --git a/crawl-ref/source/hiscores.cc b/crawl-ref/source/hiscores.cc
index b3bfa27056..1462a37a9a 100644
--- a/crawl-ref/source/hiscores.cc
+++ b/crawl-ref/source/hiscores.cc
@@ -31,9 +31,11 @@
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
-#include <unistd.h>
#include <algorithm>
#include <memory>
+#if !_MSC_VER
+#include <unistd.h>
+#endif
#include "AppHdr.h"
#include "externs.h"
@@ -61,7 +63,6 @@
#include "view.h"
#include "skills2.h"
-
#define SCORE_VERSION "0.1"
#ifdef MULTIUSER
@@ -1001,7 +1002,7 @@ void scorefile_entry::init()
death_time = time( NULL ); // end time of game
if (you.real_time != -1)
- real_time = you.real_time + (death_time - you.start_time);
+ real_time = you.real_time + long(death_time - you.start_time);
else
real_time = -1;
diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc
index 805d9d4312..785acb35af 100644
--- a/crawl-ref/source/initfile.cc
+++ b/crawl-ref/source/initfile.cc
@@ -2543,7 +2543,8 @@ void game_options::read_option_line(const std::string &str, bool runscript)
}
}
}
- else if (key == "menu_colour" || key == "menu_color")
+ // MSVC has a limit on how many if/else if can be chained together.
+ /* else */ if (key == "menu_colour" || key == "menu_color")
{
std::vector<std::string> seg = split_string(",", field);
for (int i = 0, count = seg.size(); i < count; ++i)
diff --git a/crawl-ref/source/libutil.cc b/crawl-ref/source/libutil.cc
index c5751a27eb..52fa9094d1 100644
--- a/crawl-ref/source/libutil.cc
+++ b/crawl-ref/source/libutil.cc
@@ -395,7 +395,7 @@ std::string number_in_words(unsigned num, int pow)
return number_in_words(num, 0) + pow_in_words(pow);
unsigned thousands = num % 1000, rest = num / 1000;
- if (!rest and !thousands)
+ if (!rest && !thousands)
return ("zero");
return join_strings((rest? number_in_words(rest, pow + 3) : ""),
diff --git a/crawl-ref/source/libw32c.cc b/crawl-ref/source/libw32c.cc
index db758eee12..27b1ca9377 100644
--- a/crawl-ref/source/libw32c.cc
+++ b/crawl-ref/source/libw32c.cc
@@ -1,3 +1,5 @@
+#include "AppHdr.h"
+
#if defined(WIN32CONSOLE)
/*
@@ -42,7 +44,6 @@
#define NOMDI /* MDI support */
#define NOCTLMGR /* Control management and controls */
#define NOHELP /* Help support */
-
/*
* Exclude parts of WINDOWS.H that are not needed (Win32)
*/
@@ -57,7 +58,9 @@
#include <excpt.h>
#include <stdarg.h>
+#undef ARRAYSIZE
#include <windows.h>
+#undef max
// END -- WINDOWS INCLUDES
@@ -67,7 +70,6 @@
#include <string.h>
#include <stdio.h>
-#include "AppHdr.h"
#include "cio.h"
#include "defines.h"
#include "libutil.h"
@@ -866,7 +868,7 @@ int getch_ck(void)
case KEY_EVENT:
kr = &ir.Event.KeyEvent;
// ignore if it is a 'key up' - we only want 'key down'
- if (kr->bKeyDown == true)
+ if (kr->bKeyDown)
{
key = vk_translate( kr->wVirtualKeyCode,
kr->uChar.AsciiChar,
@@ -1038,4 +1040,111 @@ int get_number_of_cols()
return (screensize.X);
}
+#if _MSC_VER
+struct DIR
+{
+ public:
+ DIR()
+ : hFind(INVALID_HANDLE_VALUE),
+ wfd_valid(false)
+ {
+ memset(&wfd, 0, sizeof(wfd));
+ memset(&entry, 0, sizeof(entry));
+ }
+
+ ~DIR()
+ {
+ if (hFind != INVALID_HANDLE_VALUE)
+ {
+ FindClose(hFind);
+ }
+ }
+
+ bool init(const char* szFind)
+ {
+ // Check that it's a directory, first
+ {
+ const DWORD dwAttr = GetFileAttributes(szFind);
+ if (dwAttr == INVALID_FILE_ATTRIBUTES)
+ return false;
+ if ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) == 0)
+ return false;
+ }
+
+ find = szFind;
+ find += "\\*";
+
+ hFind = FindFirstFileA(find.c_str(), &wfd);
+ wfd_valid = (hFind != INVALID_HANDLE_VALUE);
+ return true;
+ }
+
+ dirent* readdir()
+ {
+ if (! wfd_valid) return 0;
+
+ _convert_wfd_to_dirent();
+ wfd_valid = (bool) FindNextFileA(hFind, &wfd);
+
+ return &entry;
+ }
+
+ private:
+ void _convert_wfd_to_dirent()
+ {
+ entry.d_reclen = sizeof(dirent);
+ entry.d_namlen = strlen(entry.d_name);
+ entry.d_type = (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ ? DT_DIR : DT_REG;
+ strncpy(entry.d_name, wfd.cFileName, sizeof(entry.d_name));
+ entry.d_name[sizeof(entry.d_name)-1] = 0;
+ }
+
+ private:
+ HANDLE hFind;
+ bool wfd_valid;
+ WIN32_FIND_DATA wfd;
+ std::string find;
+ dirent entry;
+ // since opendir calls FindFirstFile, we need a means of telling the
+ // first call to readdir that we already have a file.
+ // that's the case iff this is == 0; we use a counter rather than a
+ // flag because that allows keeping statistics.
+ int num_entries_scanned;
+};
+
+
+DIR* opendir(char* path)
+{
+ DIR* d = new DIR();
+ if (d->init(path))
+ {
+ return d;
+ }
+ else
+ {
+ delete d;
+ return 0;
+ }
+}
+
+dirent* readdir(DIR* d)
+{
+ return d->readdir();
+}
+
+int closedir(DIR* d)
+{
+ delete d;
+ return 0;
+}
+
+int ftruncate(int fp, int size)
+{
+ ASSERT(false); // unimplemented
+ return 0;
+}
+
+#endif /* #if _MSC_VER */
+
#endif /* #if defined(WIN32CONSOLE) */
diff --git a/crawl-ref/source/maps.cc b/crawl-ref/source/maps.cc
index e4f598dff6..05558cecae 100644
--- a/crawl-ref/source/maps.cc
+++ b/crawl-ref/source/maps.cc
@@ -18,7 +18,9 @@
#include <cstring>
#include <cstdlib>
#include <errno.h>
+#if !_MSC_VER
#include <unistd.h>
+#endif
#include "dungeon.h"
#include "enum.h"
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc
index 545529aa48..50107ebd2f 100644
--- a/crawl-ref/source/misc.cc
+++ b/crawl-ref/source/misc.cc
@@ -18,7 +18,7 @@
#include "notes.h"
#include <string.h>
-#if !defined(__IBMCPP__)
+#if !defined(__IBMCPP__) && !defined(_MSC_VER)
#include <unistd.h>
#endif
@@ -1840,7 +1840,7 @@ void monster_threat_values(double *general, double *highest)
if (monster->alive() && mons_near(monster) && !mons_friendly(monster))
{
const int xp = exper_value(monster);
- const double log_xp = log(xp);
+ const double log_xp = log((double)xp);
sum += log_xp;
if (xp > highest_xp)
{
@@ -1855,7 +1855,7 @@ void monster_threat_values(double *general, double *highest)
bool player_in_a_dangerous_place()
{
- const double logexp = log(you.experience);
+ const double logexp = log((double)you.experience);
double gen_threat = 0.0, hi_threat = 0.0;
monster_threat_values(&gen_threat, &hi_threat);
diff --git a/crawl-ref/source/msvc.h b/crawl-ref/source/msvc.h
index d1dab39485..ddedb40be8 100644
--- a/crawl-ref/source/msvc.h
+++ b/crawl-ref/source/msvc.h
@@ -1,11 +1,25 @@
-#define snprintf _snprintf
+/*
+ * File: msvc.h
+ * Summary: Header file for MSVC compiles
+ * Written by: Paul Du Bois
+ *
+ * $Author$ on $Date$
+ */
+
+#if defined(_MSC_VER)
+
+
+#define fileno _fileno
#define itoa _itoa
+#define snprintf _snprintf
#define strcasecmp _stricmp
+#define stricmp _stricmp
+#define strlwr _strlwr
#define strncasecmp _strnicmp
#define unlink _unlink
// No va_copy in MSVC
-#if defined(_MSC_VER) || !defined(va_copy)
+#if !defined(va_copy)
#define va_copy(dst, src) \
((void) memcpy(&(dst), &(src), sizeof(va_list)))
#endif
@@ -14,3 +28,35 @@
#pragma warning( disable : 4351 )
// bool -> int
#pragma warning( disable : 4800 )
+
+// struct vs class XXX: fix these some day!
+#pragma warning( disable : 4099 )
+
+// truncating conversions XXX: fix these too!
+#pragma warning( disable : 4244 )
+
+
+// ----------------------------------------------------------------------
+// dirent.h replacement
+// ----------------------------------------------------------------------
+
+#define DT_DIR 4
+#define DT_REG 8
+
+struct DIR;
+struct dirent
+{
+ // ino_t d_ino;
+ unsigned short d_reclen;
+ unsigned char d_type;
+ unsigned short d_namlen;
+ char d_name[255];
+};
+
+DIR* opendir(const char* path);
+dirent* readdir(DIR*);
+int closedir(DIR*);
+int ftruncate(int fp, int size);
+
+
+#endif /* defined(_MSC_VER) */
diff --git a/crawl-ref/source/notes.cc b/crawl-ref/source/notes.cc
index b8abc54bed..8712dd1280 100644
--- a/crawl-ref/source/notes.cc
+++ b/crawl-ref/source/notes.cc
@@ -6,11 +6,11 @@
* Modified for Crawl Reference by $Author$ on $Date$
*/
+#include "AppHdr.h"
#include <vector>
#include <sstream>
#include <iomanip>
-#include "AppHdr.h"
#include "notes.h"
#include "branch.h"
diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc
index 631fcc05b0..7b508a2594 100644
--- a/crawl-ref/source/religion.cc
+++ b/crawl-ref/source/religion.cc
@@ -3613,7 +3613,7 @@ void offer_items()
if (!yesno("Do you wish to part with all of your money? ", true, 'n'))
return;
- int donation_value = (int) (you.gold/200 * log(you.gold));
+ int donation_value = (int) (you.gold/200 * log((double)you.gold));
#if DEBUG_DIAGNOSTICS || DEBUG_SACRIFICE || DEBUG_PIETY
mprf(MSGCH_DIAGNOSTICS, "A donation of $%d amounts to an "
"increase of piety by %d.", you.gold, donation_value);
diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc
index 3ab4284782..62fe026ad0 100644
--- a/crawl-ref/source/tags.cc
+++ b/crawl-ref/source/tags.cc
@@ -1127,9 +1127,9 @@ static void tag_construct_you_dungeon(tagHeader &th)
marshallPlaceInfo(th, list[k]);
marshall_iterator(th, you.uniq_map_tags.begin(), you.uniq_map_tags.end(),
- marshallString);
+ marshall_string);
marshall_iterator(th, you.uniq_map_names.begin(), you.uniq_map_names.end(),
- marshallString);
+ marshall_string);
}
static void marshall_follower(tagHeader &th, const follower &f)
@@ -1566,11 +1566,11 @@ static void tag_read_you_dungeon(tagHeader &th)
unmarshall_container(th, you.uniq_map_tags,
(ssipair (string_set::*)(const std::string &))
&string_set::insert,
- unmarshallString);
+ unmarshall_string);
unmarshall_container(th, you.uniq_map_names,
(ssipair (string_set::*)(const std::string &))
&string_set::insert,
- unmarshallString);
+ unmarshall_string);
}
static void tag_read_lost_monsters(tagHeader &th, int minorVersion)
diff --git a/crawl-ref/source/tile1.cc b/crawl-ref/source/tile1.cc
index bca08c56ca..0e5279c9b3 100644
--- a/crawl-ref/source/tile1.cc
+++ b/crawl-ref/source/tile1.cc
@@ -5,10 +5,9 @@
* Modified for Crawl Reference by $Author: j-p-e-g $ on $Date: 2008-03-07 $
*/
+#include "AppHdr.h"
#ifdef USE_TILE
-
#include <stdio.h>
-#include "AppHdr.h"
#include "decks.h"
#include "direct.h"
#include "externs.h"
diff --git a/crawl-ref/source/tile2.cc b/crawl-ref/source/tile2.cc
index b69d133406..7926afcc67 100644
--- a/crawl-ref/source/tile2.cc
+++ b/crawl-ref/source/tile2.cc
@@ -5,13 +5,13 @@
* Modified for Crawl Reference by $Author: j-p-e-g $ on $Date: 2008-03-07 $
*/
-#ifdef USE_TILE
+#include "AppHdr.h"
+#ifdef USE_TILE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "AppHdr.h"
#include "branch.h"
#include "describe.h"
#include "direct.h"
diff --git a/crawl-ref/source/tutorial.cc b/crawl-ref/source/tutorial.cc
index 7e5b0a5d70..b43aef4b8d 100644
--- a/crawl-ref/source/tutorial.cc
+++ b/crawl-ref/source/tutorial.cc
@@ -8,10 +8,12 @@
* Created on 2007-01-11.
*/
-#include "tutorial.h"
+#include "AppHdr.h"
+
#include <cstring>
#include <sstream>
+#include "tutorial.h"
#include "cio.h"
#include "command.h"
#include "files.h"