forked from 0ad/0ad
# housekeeping
sorry, update-workspaces + rebuild is necessary (moved boost/utility into PCH) - ps/ : committed additional documentation on behalf of Joe. - lib/ : HAVE_C99 - replace with specific e.g. HAVE_NPRINTF; intended to help with MacOSX compat (by no longer requiring us to lie about STDC_VERSION) - NO_COPY_CTOR -> boost::noncopyable This was SVN commit r4825.
This commit is contained in:
parent
1e195ac519
commit
27b6ffe2d6
@ -323,7 +323,8 @@ function setup_all_libs ()
|
||||
"i18n"
|
||||
}
|
||||
extern_libs = {
|
||||
"spidermonkey"
|
||||
"spidermonkey",
|
||||
"boost"
|
||||
}
|
||||
setup_static_lib_package("i18n", source_dirs, extern_libs, {})
|
||||
|
||||
@ -364,6 +365,7 @@ function setup_all_libs ()
|
||||
"lib/res/sound"
|
||||
}
|
||||
extern_libs = {
|
||||
"boost",
|
||||
"sdl",
|
||||
"opengl",
|
||||
"libpng",
|
||||
|
@ -293,7 +293,7 @@ int CMapReader::ApplyData()
|
||||
|
||||
// Holds various state data while reading maps, so that loading can be
|
||||
// interrupted (e.g. to update the progress display) then later resumed.
|
||||
class CXMLReader
|
||||
class CXMLReader : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
CXMLReader(const CStr& xml_filename, CMapReader& mapReader)
|
||||
@ -340,8 +340,6 @@ private:
|
||||
void ReadTriggerGroup(XMBElement parent, MapTriggerGroup& group);
|
||||
int ReadEntities(XMBElement parent, double end_time);
|
||||
int ReadNonEntities(XMBElement parent, double end_time);
|
||||
|
||||
NO_COPY_CTOR(CXMLReader);
|
||||
};
|
||||
|
||||
|
||||
|
@ -10,7 +10,7 @@ class CObjectManager;
|
||||
#include <map>
|
||||
#include "ps/CStr.h"
|
||||
|
||||
class CObjectBase
|
||||
class CObjectBase : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
|
||||
@ -101,8 +101,6 @@ public:
|
||||
private:
|
||||
std::vector< std::vector<Variant> > m_VariantGroups;
|
||||
CObjectManager& m_ObjectManager;
|
||||
|
||||
NO_COPY_CTOR(CObjectBase);
|
||||
};
|
||||
|
||||
|
||||
|
@ -13,7 +13,7 @@ class CMeshManager;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// CObjectManager: manager class for all possible actor types
|
||||
class CObjectManager
|
||||
class CObjectManager : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
struct ObjectKey
|
||||
@ -53,8 +53,6 @@ private:
|
||||
|
||||
std::map<ObjectKey, CObjectEntry*> m_Objects;
|
||||
std::map<CStr, CObjectBase*> m_ObjectBases;
|
||||
|
||||
NO_COPY_CTOR(CObjectManager);
|
||||
};
|
||||
|
||||
|
||||
|
@ -14,7 +14,7 @@ class CStrW;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// CUnit: simple "actor" definition - defines a sole object within the world
|
||||
class CUnit
|
||||
class CUnit : boost::noncopyable
|
||||
{
|
||||
private:
|
||||
// Private constructor. Needs complete list of selections for the variation.
|
||||
@ -98,8 +98,6 @@ private:
|
||||
CObjectManager& m_ObjectManager;
|
||||
|
||||
void ReloadObject();
|
||||
|
||||
NO_COPY_CTOR(CUnit);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -19,7 +19,7 @@ namespace I18n
|
||||
{
|
||||
class CLocale;
|
||||
|
||||
class TSComponent
|
||||
class TSComponent : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
virtual const StrImW ToString(CLocale* locale, std::vector<BufferVariable*>& vars) const = 0;
|
||||
@ -35,8 +35,6 @@ namespace I18n
|
||||
|
||||
private:
|
||||
const StrImW String;
|
||||
|
||||
NO_COPY_CTOR(TSComponentString);
|
||||
};
|
||||
|
||||
|
||||
@ -66,8 +64,6 @@ namespace I18n
|
||||
private:
|
||||
const std::string Name;
|
||||
std::vector<ScriptValue*> Params;
|
||||
|
||||
NO_COPY_CTOR(TSComponentFunction);
|
||||
};
|
||||
|
||||
|
||||
|
@ -285,22 +285,39 @@
|
||||
|
||||
// compiler support for C99
|
||||
// (this is more convenient than testing __STDC_VERSION__ directly)
|
||||
// note: we currently lie about __STDC_VERSION__ via premake on
|
||||
// MacOS X to enable support for some C99 functions. unfortunately this
|
||||
// causes the OS X system headers to use the restrict keyword, which
|
||||
// gcc doesn't actually support there.
|
||||
// TODO: we therefore need to get rid of HAVE_C99, since we're using C++,
|
||||
// which is not C99. some useful features from C99 - e.g. stdint and
|
||||
// restrict - will surely be added to C++; we should test for their
|
||||
// existence and not all of C99.
|
||||
//
|
||||
// note: C99 provides several useful but disjunct bits of functionality.
|
||||
// unfortunately, most C++ compilers do not offer a complete C99
|
||||
// implementation. however, many of these features are likely to be added to
|
||||
// C++, and/or are already available as extensions. what we'll do is add a
|
||||
// HAVE_ macro for each and test those instead. they are set if HAVE_C99, or
|
||||
// also if the compiler happens to support something compatible.
|
||||
//
|
||||
// rationale: lying about __STDC_VERSION__ via Premake so as to enable support
|
||||
// for some C99 functions doesn't work. Mac OS X headers would then use the
|
||||
// restrict keyword, which is not actually supported on older GCC.
|
||||
#define HAVE_C99 0
|
||||
#ifdef __STDC_VERSION__
|
||||
# if __STDC_VERSION__ >= 199901L
|
||||
# undef HAVE_C99
|
||||
# undef HAVE_C99
|
||||
# define HAVE_C99 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// snprintf, swprintf, etc.
|
||||
#define HAVE_NPRINTF 0
|
||||
#if HAVE_C99
|
||||
# undef HAVE_NPRINTF
|
||||
# define HAVE_NPRINTF 1
|
||||
#endif
|
||||
|
||||
// rint*, fminf, fpclassify (too few/diverse to make separate HAVE_ for each)
|
||||
#define HAVE_C99_MATH 0
|
||||
#if HAVE_C99
|
||||
# undef HAVE_C99_MATH
|
||||
# define HAVE_C99_MATH 1
|
||||
#endif
|
||||
|
||||
// gettimeofday()
|
||||
#if OS_UNIX
|
||||
# define HAVE_GETTIMEOFDAY 1
|
||||
|
@ -221,18 +221,6 @@ STMT(\
|
||||
**/
|
||||
#define UNUSED(param)
|
||||
|
||||
/**
|
||||
* mark the copy constructor as inaccessible. this squelches
|
||||
* "cannot be generated" warnings for classes with const members.
|
||||
*
|
||||
* intended to be used at end of class definition.
|
||||
* must be followed by semicolon.
|
||||
**/
|
||||
#define NO_COPY_CTOR(class_name)\
|
||||
private:\
|
||||
class_name& operator=(const class_name&);\
|
||||
class_name(const class_name&)
|
||||
|
||||
|
||||
/**
|
||||
"unreachable code" helpers
|
||||
|
@ -162,6 +162,10 @@
|
||||
# include <hash_set>
|
||||
#endif
|
||||
|
||||
// Boost
|
||||
#include <boost/utility.hpp> // noncopyable
|
||||
|
||||
|
||||
// (further headers to be precompiled go here)
|
||||
|
||||
#endif // #if HAVE_PCH
|
||||
|
@ -201,7 +201,7 @@ static const Mount& add_mount(const char* V_mount_point, const char* P_real_path
|
||||
uint flags, uint pri);
|
||||
|
||||
// passed through dirent_cb's afile_enum to afile_cb
|
||||
struct ZipCBParams
|
||||
struct ZipCBParams : boost::noncopyable
|
||||
{
|
||||
// tree directory into which we are adding the archive's files
|
||||
TDir* const td;
|
||||
@ -220,8 +220,6 @@ struct ZipCBParams
|
||||
last_path = 0;
|
||||
last_td = 0;
|
||||
}
|
||||
|
||||
NO_COPY_CTOR(ZipCBParams);
|
||||
};
|
||||
|
||||
// called by add_ent's afile_enum for each file in the archive.
|
||||
@ -361,7 +359,7 @@ struct TDirAndPath
|
||||
|
||||
// can't implement or generate assignment operator because of the
|
||||
// const member. just disallow its use.
|
||||
// NB: can't use NO_COPY_CTOR because we need one for STL.
|
||||
// NB: can't use boost::noncopyable because STL requires a copy ctor.
|
||||
private:
|
||||
TDirAndPath& operator=(const TDirAndPath& rhs);
|
||||
};
|
||||
|
@ -407,7 +407,7 @@ static void displayR(TDir* td, int indent_level)
|
||||
}
|
||||
|
||||
|
||||
struct LookupCbParams
|
||||
struct LookupCbParams : boost::noncopyable
|
||||
{
|
||||
const bool create_missing;
|
||||
TDir* td; // current dir; assigned from node
|
||||
@ -419,8 +419,6 @@ struct LookupCbParams
|
||||
// this works because TDir is derived from TNode.
|
||||
node = (TNode*)td;
|
||||
}
|
||||
|
||||
NO_COPY_CTOR(LookupCbParams);
|
||||
};
|
||||
|
||||
static LibError lookup_cb(const char* component, bool is_dir, void* ctx)
|
||||
@ -624,14 +622,12 @@ LibError tree_lookup(const char* V_path, TFile** pfile, uint flags)
|
||||
}
|
||||
|
||||
|
||||
struct AddPathCbParams
|
||||
struct AddPathCbParams : boost::noncopyable
|
||||
{
|
||||
const Mount* const m;
|
||||
TDir* td;
|
||||
AddPathCbParams(const Mount* m_)
|
||||
: m(m_), td(tree_root) {}
|
||||
|
||||
NO_COPY_CTOR(AddPathCbParams);
|
||||
};
|
||||
|
||||
static LibError add_path_cb(const char* component, bool is_dir, void* ctx)
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
|
||||
// emulate C99 functionality
|
||||
#if !HAVE_C99
|
||||
#if !HAVE_C99_MATH
|
||||
|
||||
// fallback versions in case ia32 optimized versions are unavailable.
|
||||
#if !HAVE_MS_ASM
|
||||
@ -67,7 +67,7 @@ uint fpclassifyf(float f)
|
||||
|
||||
#endif
|
||||
|
||||
#endif // #if !HAVE_C99
|
||||
#endif // #if !HAVE_C99_MATH
|
||||
|
||||
|
||||
// float->int conversion: not using the ia32 version; just implement as a
|
||||
|
@ -106,7 +106,7 @@ extern void* alloca(size_t size);
|
||||
// rint: round float to nearest integral value, according to
|
||||
// current rounding mode.
|
||||
// fminf/fmaxf: return minimum/maximum of two floats.
|
||||
#if !HAVE_C99
|
||||
#if !HAVE_C99_MATH
|
||||
// .. fast IA-32 versions
|
||||
# if CPU_IA32
|
||||
# define rintf ia32_rintf
|
||||
@ -140,7 +140,7 @@ extern void* alloca(size_t size);
|
||||
# define isinf(d) (fpclassify(d) == FP_NAN|FP_NORMAL)
|
||||
# define isnormal(d) (fpclassify(d) == FP_NORMAL)
|
||||
//# define signbit
|
||||
#else
|
||||
#else // HAVE_C99_MATH
|
||||
// Some systems have C99 support but in C++ they provide only std::isfinite
|
||||
// and not isfinite. C99 specifies that isfinite is a macro, so we can use
|
||||
// #ifndef and define it if it's not there already.
|
||||
@ -151,7 +151,7 @@ extern void* alloca(size_t size);
|
||||
# define isinf std::isinf
|
||||
# define isnormal std::isnormal
|
||||
# endif
|
||||
#endif
|
||||
#endif // HAVE_C99_MATH
|
||||
|
||||
// C99-like restrict (non-standard in C++, but widely supported in various forms).
|
||||
//
|
||||
|
@ -556,7 +556,7 @@ static void out(const wchar_t* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int len = _vsnwprintf(out_pos, out_chars_left, fmt, args);
|
||||
int len = vswprintf(out_pos, out_chars_left, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
// success
|
||||
@ -575,7 +575,7 @@ static void out(const wchar_t* fmt, ...)
|
||||
else
|
||||
{
|
||||
// the buffer really is full yet out_chars_left may not be 0
|
||||
// (since it isn't updated if _vsnwprintf returns -1).
|
||||
// (since it isn't updated if vswprintf returns -1).
|
||||
// must be set so subsequent calls don't try to squeeze stuff in.
|
||||
out_chars_left = 0;
|
||||
|
||||
|
@ -33,11 +33,11 @@
|
||||
|
||||
// provide C99 *snprintf functions if compiler doesn't already
|
||||
// (MinGW does, VC7.1 doesn't).
|
||||
#if !HAVE_C99
|
||||
#if !HAVE_NPRINTF
|
||||
# define snprintf _snprintf
|
||||
# define swprintf _snwprintf
|
||||
# define vsnprintf _vsnprintf
|
||||
# define vsnwprintf _vsnwprintf
|
||||
# define vswprintf _vsnwprintf
|
||||
#endif
|
||||
|
||||
#include <stddef.h> // wchar_t
|
||||
|
@ -19,7 +19,7 @@ enum ELogMethod
|
||||
WARNING
|
||||
};
|
||||
|
||||
class CLogger
|
||||
class CLogger : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
|
||||
@ -63,8 +63,6 @@ private:
|
||||
|
||||
// Used to remember LogOnce messages
|
||||
std::set<std::string> m_LoggedOnce;
|
||||
|
||||
NO_COPY_CTOR(CLogger);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,3 +1,12 @@
|
||||
/**
|
||||
* File : CStr.cpp
|
||||
* Project : engine
|
||||
* Description : Controls compilation of CStr class and
|
||||
* : includes some function implementations.
|
||||
*
|
||||
* @author Caecus
|
||||
* Caecus@0ad.wildfiregames.com
|
||||
**/
|
||||
#include "precompiled.h"
|
||||
|
||||
#ifndef CStr_CPP_FIRST
|
||||
@ -20,7 +29,13 @@ CStr8::CStr8(const CStrW& wideStr) : std:: string(wideStr.begin(), wideStr.end()
|
||||
|
||||
// UTF conversion code adapted from http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.c
|
||||
|
||||
/**
|
||||
* Used by ToUTF8
|
||||
**/
|
||||
static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
|
||||
/**
|
||||
* Used by FromUTF8
|
||||
**/
|
||||
static const char trailingBytesForUTF8[256] = {
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
@ -30,10 +45,18 @@ static const char trailingBytesForUTF8[256] = {
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 };
|
||||
/**
|
||||
* Used by FromUTF8
|
||||
**/
|
||||
static const u32 offsetsFromUTF8[6] = {
|
||||
0x00000000UL, 0x00003080UL, 0x000E2080UL,
|
||||
0x03C82080UL, 0xFA082080UL, 0x82082080UL };
|
||||
|
||||
/**
|
||||
* Convert CStr to UTF-8
|
||||
*
|
||||
* @return CStr8 converted string
|
||||
**/
|
||||
CStr8 CStrW::ToUTF8() const
|
||||
{
|
||||
CStr8 result;
|
||||
@ -64,6 +87,14 @@ CStr8 CStrW::ToUTF8() const
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for valid UTF-8 string
|
||||
*
|
||||
* @param const unsigned char * source pointer to string to test.
|
||||
* @param int length of string to test.
|
||||
* @return bool true if source string is legal UTF-8,
|
||||
* false if not.
|
||||
**/
|
||||
static bool isLegalUTF8(const unsigned char *source, int length)
|
||||
{
|
||||
unsigned char a;
|
||||
@ -90,6 +121,11 @@ static bool isLegalUTF8(const unsigned char *source, int length)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert UTF-8 to CStr
|
||||
*
|
||||
* @return CStrW converted string
|
||||
**/
|
||||
CStrW CStr8::FromUTF8() const
|
||||
{
|
||||
CStrW result;
|
||||
@ -130,7 +166,6 @@ CStrW CStr8::FromUTF8() const
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
// The following code is compiled twice, as CStrW then as CStr8:
|
||||
|
417
source/ps/CStr.h
417
source/ps/CStr.h
@ -1,48 +1,46 @@
|
||||
/**
|
||||
* File : CStr.h
|
||||
* Project : engine
|
||||
* Description : Contains CStr class which is a versatile class for making string use easy.
|
||||
* : The class implements a series of string manipulation/formatting functions.
|
||||
*
|
||||
* @author Caecus
|
||||
* Caecus@0ad.wildfiregames.com
|
||||
**/
|
||||
/*
|
||||
CStr.h
|
||||
by Caecus
|
||||
Caecus@0ad.wildfiregames.com
|
||||
|
||||
Overview:
|
||||
|
||||
Contains CStr class which is a versatile class for making string use easy.
|
||||
Basic functionality implemented via STL string, so performance is limited
|
||||
based on the STL implementation we use.
|
||||
|
||||
Example:
|
||||
|
||||
CStr MyString = _T("Hello, World.");
|
||||
int MyNum = 126;
|
||||
MyString += _T(" I'm the number ") += CStr(MyNumber);
|
||||
|
||||
// Prints "Hello, World. I'm the number 126"
|
||||
|
||||
_tcout << (LPCTSTR)MyString << endl;
|
||||
|
||||
MyString = _("2341");
|
||||
MyNum = MyString.ToInt();
|
||||
|
||||
// Prints "2341"
|
||||
_tcout << MyNum << endl;
|
||||
|
||||
More Info:
|
||||
http://wildfiregames.com/0ad/codepit/TDD/CStr.html
|
||||
|
||||
|
||||
[[ This documentation is out of date; CStr is always 8 bits, and CStrW is always
|
||||
sizeof(wchar_t) (16 or 32). Don't use _T; CStrW constants are just L"string". ]]
|
||||
Examples:
|
||||
Generic text mapping is simply the ability to compile the final game in both UNICODE and ANSI.
|
||||
These are the ways in which we deal with strings.
|
||||
UNICODE uses 16 bits per character, whereas ANSI uses the traditional 8 bit character.
|
||||
In order to use both, most of the standard library functions come in T form.
|
||||
The following shows several examples of traditional ANSI vs UNICODE.
|
||||
// ANSI
|
||||
LPCSTR str = "PI";
|
||||
printf( "%s = %fn", str, 3.1459f );
|
||||
|
||||
// UNICODE
|
||||
LPCWSTR str = L"PI";
|
||||
wprintf( L"%s = %fn", str, 3.1459f );
|
||||
*/
|
||||
|
||||
// history:
|
||||
// 19 May 04, Mark Thompson (mot20@cam.ac.uk / mark@wildfiregames.com)
|
||||
// 2004-06-18 janwas: replaced conversion buffer with stringstream
|
||||
// 2004-10-31 Philip: Changed to inherit from std::[w]string
|
||||
// 2007-1-26 greybeard(joe@wildfiregames.com): added comments for doc generation
|
||||
|
||||
#ifndef CSTR_H_FIRST
|
||||
#define CSTR_H_FIRST
|
||||
|
||||
enum PS_TRIM_MODE { PS_TRIM_LEFT, PS_TRIM_RIGHT, PS_TRIM_BOTH };
|
||||
/**
|
||||
* Whitespace trim identifier for Trim and Pad functions
|
||||
**/
|
||||
enum PS_TRIM_MODE
|
||||
{
|
||||
PS_TRIM_LEFT, /// Trim all white space from the beginning of the string
|
||||
PS_TRIM_RIGHT, /// Trim all white space from the end of the string
|
||||
PS_TRIM_BOTH /// Trim all white space from the beginning and end of the string
|
||||
};
|
||||
|
||||
#ifndef IN_UNIDOUBLER
|
||||
#define UNIDOUBLER_HEADER "CStr.h"
|
||||
@ -67,7 +65,9 @@ enum PS_TRIM_MODE { PS_TRIM_LEFT, PS_TRIM_RIGHT, PS_TRIM_BOTH };
|
||||
class CStr8;
|
||||
class CStrW;
|
||||
|
||||
// CStr class, the mother of all strings
|
||||
/**
|
||||
* The base class of all strings
|
||||
**/
|
||||
class CStr: public std::tstring
|
||||
{
|
||||
// The two variations must be friends with each other
|
||||
@ -81,20 +81,60 @@ public:
|
||||
|
||||
// CONSTRUCTORS
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
**/
|
||||
CStr() {}
|
||||
/**
|
||||
* Alternate Constructor
|
||||
*
|
||||
* @param const CStr & String reference to another CStr object to be used for initialization
|
||||
**/
|
||||
CStr(const CStr& String) : std::tstring(String) {}
|
||||
/**
|
||||
* Alternate Constructor
|
||||
*
|
||||
* @param const tchar * String pointer to an array of tchar to be used for initialization
|
||||
**/
|
||||
CStr(const tchar* String) : std::tstring(String) {}
|
||||
/**
|
||||
* Alternate Constructor
|
||||
*
|
||||
* @param const tchar * String pointer to first tchar to be used for initialization
|
||||
* @param size_t Length number of tchar to be used from first tchar
|
||||
**/
|
||||
CStr(const tchar* String, size_t Length)
|
||||
: std::tstring(String, Length) {}
|
||||
/**
|
||||
* Alternate Constructor
|
||||
*
|
||||
* @param const tchar Char tchar to be used for initialization
|
||||
**/
|
||||
CStr(const tchar Char) : std::tstring(1, Char) {} // std::string's constructor is (repeats, chr)
|
||||
/**
|
||||
* Alternate Constructor
|
||||
*
|
||||
* @param std::tstring String reference to basic string object to be used for inititalization
|
||||
**/
|
||||
CStr(std::tstring String) : std::tstring(String) {}
|
||||
|
||||
// Named constructor, to avoid overload overload.
|
||||
/**
|
||||
* Repeat: Named constructor, to avoid overload overload.
|
||||
*
|
||||
* @param const CStr & String reference to another CStr object to be repeated for initialization
|
||||
* @param size_t Reps number of times to repeat the initialization
|
||||
* @return CStr new CStr object
|
||||
**/
|
||||
static CStr Repeat(const CStr& String, size_t Reps);
|
||||
|
||||
// CStr(8|W) construction from utf16strings.
|
||||
// allowed on MSVC as of 2006-02-03 because utf16string is
|
||||
// now distinct from CStrW.
|
||||
|
||||
/**
|
||||
* Construction from utf16strings.
|
||||
* allowed on MSVC as of 2006-02-03 because utf16string is
|
||||
* now distinct from CStrW.
|
||||
*
|
||||
* @param utf16string String utf16string to be used for initialization.
|
||||
**/
|
||||
CStr(utf16string String) : std::tstring(String.begin(), String.end()) {}
|
||||
|
||||
// Transparent CStrW/8 conversion. Non-ASCII characters are not
|
||||
@ -116,93 +156,330 @@ public:
|
||||
CStrW FromUTF8() const;
|
||||
#endif
|
||||
|
||||
CStr(int Number); // Creates CStr from a int
|
||||
CStr(unsigned int Number); // Creates CStr from a uint
|
||||
CStr(long Number); // Creates CStr from a long
|
||||
CStr(unsigned long Number); // Creates CStr from a ulong
|
||||
CStr(float Number); // Creates CStr from a float
|
||||
CStr(double Number); // Creates CStr from a double
|
||||
/**
|
||||
* Alternate Constructor
|
||||
*
|
||||
* @param int Number integer to be used for initialization
|
||||
**/
|
||||
CStr(int Number);
|
||||
/**
|
||||
* Alternate Constructor
|
||||
*
|
||||
* @param unsigned int Number unsigned integer to be used for initialization
|
||||
**/
|
||||
CStr(unsigned int Number);
|
||||
/**
|
||||
* Alternate Constructor
|
||||
*
|
||||
* @param long Number long to be used for initialization
|
||||
**/
|
||||
CStr(long Number);
|
||||
/**
|
||||
* Alternate Constructor
|
||||
*
|
||||
* @param unsigned long Number unsigned long to be used for initialization
|
||||
**/
|
||||
CStr(unsigned long Number);
|
||||
/**
|
||||
* Alternate Constructor
|
||||
*
|
||||
* @param float Number float to be used for initialization
|
||||
**/
|
||||
CStr(float Number);
|
||||
/**
|
||||
* Alternate Constructor
|
||||
*
|
||||
* @param double Number double to be used for initialization
|
||||
**/
|
||||
CStr(double Number);
|
||||
|
||||
~CStr() {}; // Destructor
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
**/
|
||||
~CStr() {};
|
||||
|
||||
// Conversions
|
||||
/**
|
||||
* Return CStr as Integer.
|
||||
* Conversion is from the beginning of CStr.
|
||||
*
|
||||
* @return int CStr represented as an integer.
|
||||
**/
|
||||
int ToInt() const;
|
||||
/**
|
||||
* Return CStr as Unsigned Integer.
|
||||
* Conversion is from the beginning of CStr.
|
||||
*
|
||||
* @return unsigned int CStr represented as an unsigned integer.
|
||||
**/
|
||||
unsigned int ToUInt() const;
|
||||
/**
|
||||
* Return CStr as Long.
|
||||
* Conversion is from the beginning of CStr.
|
||||
*
|
||||
* @return long CStr represented as a long.
|
||||
**/
|
||||
long ToLong() const;
|
||||
/**
|
||||
* Return CStr as Unsigned Long.
|
||||
* Conversion is from the beginning of CStr.
|
||||
*
|
||||
* @return unsigned long CStr represented as an unsigned long.
|
||||
**/
|
||||
unsigned long ToULong() const;
|
||||
/**
|
||||
* Return CStr as Float.
|
||||
* Conversion is from the beginning of CStr.
|
||||
*
|
||||
* @return float CStr represented as a float.
|
||||
**/
|
||||
float ToFloat() const;
|
||||
/**
|
||||
* Return CStr as Double.
|
||||
* Conversion is from the beginning of CStr.
|
||||
*
|
||||
* @return double CStr represented as a double.
|
||||
**/
|
||||
double ToDouble() const;
|
||||
|
||||
// Returns the length of the string in characters
|
||||
/**
|
||||
* Return the length of the CStr in characters.
|
||||
*
|
||||
* @return size_t character count
|
||||
**/
|
||||
size_t Length() const { return length(); }
|
||||
|
||||
// Retrieves the substring within the string
|
||||
/**
|
||||
* Retrieve the substring within the CStr.
|
||||
*
|
||||
* @param size_t start starting character position in CStr
|
||||
* @param size_t len number of characters to retrieve in CStr
|
||||
* @return CStr substring
|
||||
**/
|
||||
CStr GetSubstring(size_t start, size_t len) const;
|
||||
|
||||
// Search the string for another string. Returns the offset of the first
|
||||
// match, or -1 if no matches are found.
|
||||
/**
|
||||
* Search the CStr for another string.
|
||||
* The search is case-sensitive.
|
||||
*
|
||||
* @param const CStr & Str reference to the search string
|
||||
* @return long offset into the CStr of the first occurrence of the search string
|
||||
* -1 if the search string is not found
|
||||
**/
|
||||
long Find(const CStr& Str) const;
|
||||
/**
|
||||
* Search the CStr for another string.
|
||||
* The search is case-sensitive.
|
||||
*
|
||||
* @param const {t|w}char_t & chr reference to the search string
|
||||
* @return long offset into the CStr of the first occurrence of the search string
|
||||
* -1 if the search string is not found
|
||||
**/
|
||||
long Find(const tchar &chr) const;
|
||||
/**
|
||||
* Search the CStr for another string with starting offset.
|
||||
* The search is case-sensitive.
|
||||
*
|
||||
* @param const int & start character offset into CStr to begin search
|
||||
* @param const {t|w}char_t & chr reference to the search string
|
||||
* @return long offset into the CStr of the first occurrence of the search string
|
||||
* -1 if the search string is not found
|
||||
**/
|
||||
long Find(const int &start, const tchar &chr) const;
|
||||
|
||||
// Case-insensitive versions of Find
|
||||
/**
|
||||
* Search the CStr for another string.
|
||||
* The search is case-insensitive.
|
||||
*
|
||||
* @param const CStr & Str reference to the search string
|
||||
* @return long offset into the CStr of the first occurrence of the search string
|
||||
* -1 if the search string is not found
|
||||
**/
|
||||
long FindInsensitive(const CStr& Str) const;
|
||||
/**
|
||||
* Search the CStr for another string.
|
||||
* The search is case-insensitive.
|
||||
*
|
||||
* @param const {t|w}char_t & chr reference to the search string
|
||||
* @return long offset into the CStr of the first occurrence of the search string
|
||||
* -1 if the search string is not found
|
||||
**/
|
||||
long FindInsensitive(const tchar &chr) const;
|
||||
/**
|
||||
* Search the CStr for another string with starting offset.
|
||||
* The search is case-insensitive.
|
||||
*
|
||||
* @param const int & start character offset into CStr to begin search
|
||||
* @param const {t|w}char_t & chr reference to the search string
|
||||
* @return long offset into the CStr of the first occurrence of the search string
|
||||
* -1 if the search string is not found
|
||||
**/
|
||||
long FindInsensitive(const int &start, const tchar &chr) const;
|
||||
|
||||
// You can also do a "ReverseFind" - i.e. search starting from the end
|
||||
/**
|
||||
* Search the CStr for another string.
|
||||
* The search is case-sensitive.
|
||||
*
|
||||
* @param const CStr & Str reference to the search string
|
||||
* @return long offset into the CStr of the last occurrence of the search string
|
||||
* -1 if the search string is not found
|
||||
**/
|
||||
long ReverseFind(const CStr& Str) const;
|
||||
|
||||
// Lowercase and uppercase
|
||||
/**
|
||||
* Make a copy of the CStr in lower-case.
|
||||
*
|
||||
* @return CStr converted copy of CStr.
|
||||
**/
|
||||
CStr LowerCase() const;
|
||||
/**
|
||||
* Make a copy of the CStr in upper-case.
|
||||
*
|
||||
* @return CStr converted copy of CStr.
|
||||
**/
|
||||
CStr UpperCase() const;
|
||||
CStr LCase() const;
|
||||
CStr UCase() const;
|
||||
|
||||
// Retrieve the substring of the first n characters
|
||||
/**
|
||||
* Retrieve first n characters of the CStr.
|
||||
*
|
||||
* @param size_t len the number of characters to retrieve.
|
||||
* @return CStr retrieved substring.
|
||||
**/
|
||||
CStr Left(size_t len) const;
|
||||
|
||||
// Retrieve the substring of the last n characters
|
||||
/**
|
||||
* Retrieve last n characters of the CStr.
|
||||
*
|
||||
* @param size_t len the number of characters to retrieve.
|
||||
* @return CStr retrieved substring.
|
||||
**/
|
||||
CStr Right(size_t len) const;
|
||||
|
||||
// Retrieve the substring following the last occurrence of Str
|
||||
// (or the whole string if it doesn't contain Str)
|
||||
/**
|
||||
* Retrieve substring of the CStr after last occurrence of a string.
|
||||
* Return substring of the CStr after the last occurrence of the search string.
|
||||
*
|
||||
* @param const CStr & Str reference to search string
|
||||
* @return CStr substring remaining after match
|
||||
* the CStr if no match is found
|
||||
**/
|
||||
CStr AfterLast(const CStr& Str) const;
|
||||
|
||||
// Retrieve the substring preceding the last occurrence of Str
|
||||
// (or the whole string if it doesn't contain Str)
|
||||
|
||||
/**
|
||||
* Retrieve substring of the CStr preceding last occurrence of a string.
|
||||
* Return substring of the CStr preceding the last occurrence of the search string.
|
||||
*
|
||||
* @param const CStr & Str reference to search string
|
||||
* @return CStr substring preceding before match
|
||||
* the CStr if no match is found
|
||||
**/
|
||||
CStr BeforeLast(const CStr& Str) const;
|
||||
|
||||
// Retrieve the substring following the first occurrence of Str
|
||||
// (or the whole string if it doesn't contain Str)
|
||||
/**
|
||||
* Retrieve substring of the CStr after first occurrence of a string.
|
||||
* Return substring of the CStr after the first occurrence of the search string.
|
||||
*
|
||||
* @param const CStr & Str reference to search string
|
||||
* @return CStr substring remaining after match
|
||||
* the CStr if no match is found
|
||||
**/
|
||||
CStr AfterFirst(const CStr& Str) const;
|
||||
|
||||
// Retrieve the substring preceding the first occurrence of Str
|
||||
// (or the whole string if it doesn't contain Str)
|
||||
/**
|
||||
* Retrieve substring of the CStr preceding first occurrence of a string.
|
||||
* Return substring of the CStr preceding the first occurrence of the search string.
|
||||
*
|
||||
* @param const CStr & Str reference to search string
|
||||
* @return CStr substring preceding before match
|
||||
* the CStr if no match is found
|
||||
**/
|
||||
CStr BeforeFirst(const CStr& Str) const;
|
||||
|
||||
// Remove all occurrences of some character or substring
|
||||
/**
|
||||
* Remove all occurrences of a string from the CStr.
|
||||
*
|
||||
* @param const CStr & Str reference to search string to remove.
|
||||
**/
|
||||
void Remove(const CStr& Str);
|
||||
|
||||
// Replace all occurrences of some substring by another
|
||||
/**
|
||||
* Replace all occurrences of one string by another string in the CStr.
|
||||
*
|
||||
* @param const CStr & StrToReplace reference to search string.
|
||||
* @param const CStr & ReplaceWith reference to replace string.
|
||||
**/
|
||||
void Replace(const CStr& StrToReplace, const CStr& ReplaceWith);
|
||||
|
||||
// Convert strings like \\\n into <backslash><newline>
|
||||
/**
|
||||
* Convert strings like \\\n into <backslash><newline>
|
||||
*
|
||||
* @return CStr converted copy of CStr.
|
||||
**/
|
||||
CStr UnescapeBackslashes();
|
||||
|
||||
// Returns a trimmed string, removes whitespace from the left/right/both
|
||||
/**
|
||||
* Return a trimmed copy of the CStr.
|
||||
*
|
||||
* @param PS_TRIM_MODE Mode value from trim mode enumeration.
|
||||
* @return CStr copy of trimmed CStr.
|
||||
**/
|
||||
CStr Trim(PS_TRIM_MODE Mode) const;
|
||||
|
||||
// Returns a padded string, adding spaces to the left/right/both
|
||||
/**
|
||||
* Return a space padded copy of the CStr.
|
||||
*
|
||||
* @param PS_TRIM_MODE Mode value from trim mode enumeration.
|
||||
* @param size_t Length number of pad spaces to add
|
||||
* @return CStr copy of padded CStr.
|
||||
**/
|
||||
CStr Pad(PS_TRIM_MODE Mode, size_t Length) const;
|
||||
|
||||
// Overloaded operations
|
||||
|
||||
/**
|
||||
* Set the CStr equal to an integer.
|
||||
*
|
||||
* @param int Number integer to convert to a CStr.
|
||||
* @return CStr
|
||||
**/
|
||||
CStr& operator=(int Number);
|
||||
/**
|
||||
* Set the CStr equal to a long.
|
||||
*
|
||||
* @param long Number long to convert to a CStr.
|
||||
* @return CStr
|
||||
**/
|
||||
CStr& operator=(long Number);
|
||||
/**
|
||||
* Set the CStr equal to an unsigned integer.
|
||||
*
|
||||
* @param unsigned int Number unsigned int to convert to a CStr.
|
||||
* @return CStr
|
||||
**/
|
||||
CStr& operator=(unsigned int Number);
|
||||
/**
|
||||
* Set the CStr equal to an unsigned long.
|
||||
*
|
||||
* @param unsigned long Number unsigned long to convert to a CStr.
|
||||
* @return CStr
|
||||
**/
|
||||
CStr& operator=(unsigned long Number);
|
||||
/**
|
||||
* Set the CStr equal to a float.
|
||||
*
|
||||
* @param float Number float to convert to a CStr.
|
||||
* @return CStr
|
||||
**/
|
||||
CStr& operator=(float Number);
|
||||
/**
|
||||
* Set the CStr equal to a double.
|
||||
*
|
||||
* @param double Number double to convert to a CStr.
|
||||
* @return CStr
|
||||
**/
|
||||
CStr& operator=(double Number);
|
||||
|
||||
CStr operator+(const CStr& Str);
|
||||
@ -218,7 +495,7 @@ public:
|
||||
// Do some range checking in debug builds
|
||||
tchar& operator[](size_t n) { debug_assert(n < length()); return this->std::tstring::operator[](n); }
|
||||
tchar& operator[](int n) { debug_assert((size_t)n < length()); return this->std::tstring::operator[](n); }
|
||||
|
||||
|
||||
// Conversion to utf16string
|
||||
inline utf16string utf16() const
|
||||
{ return utf16string(begin(), end()); }
|
||||
|
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* File : Game.cpp
|
||||
* Project : engine
|
||||
* Description : Contains the CGame Class implementation.
|
||||
*
|
||||
**/
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "Game.h"
|
||||
@ -26,6 +32,9 @@ extern CNetServer *g_NetServer;
|
||||
|
||||
extern bool g_GameRestarted;
|
||||
|
||||
/**
|
||||
* Globally accessible pointer to the CGame object.
|
||||
**/
|
||||
CGame *g_Game=NULL;
|
||||
|
||||
// Disable "warning C4355: 'this' : used in base member initializer list".
|
||||
@ -39,6 +48,10 @@ CGame *g_Game=NULL;
|
||||
# pragma warning (disable: 4355)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
**/
|
||||
CGame::CGame():
|
||||
m_World(new CWorld(this)),
|
||||
m_Simulation(new CSimulation(this)),
|
||||
@ -58,6 +71,10 @@ CGame::CGame():
|
||||
# pragma warning (default: 4355)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
**/
|
||||
CGame::~CGame()
|
||||
{
|
||||
// Again, the in-game call tree is going to be different to the main menu one.
|
||||
@ -70,14 +87,22 @@ CGame::~CGame()
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the game with the set of attributes provided.
|
||||
* Makes calls to initialize the game view, world, and simulation objects.
|
||||
* Calls are made to facilitate progress reporting of the initialization.
|
||||
*
|
||||
* @param CGameAttributes * pAttribs pointer to the game attribute values
|
||||
* @return PSRETURN 0
|
||||
**/
|
||||
PSRETURN CGame::RegisterInit(CGameAttributes* pAttribs)
|
||||
{
|
||||
LDR_BeginRegistering();
|
||||
|
||||
// RC, 040804 - GameView needs to be initialised before World, otherwise GameView initialisation
|
||||
// RC, 040804 - GameView needs to be initialized before World, otherwise GameView initialization
|
||||
// overwrites anything stored in the map file that gets loaded by CWorld::Initialize with default
|
||||
// values. At the minute, it's just lighting settings, but could be extended to store camera position.
|
||||
// Storing lighting settings in the gameview seems a little odd, but it's no big deal; maybe move it at
|
||||
// Storing lighting settings in the game view seems a little odd, but it's no big deal; maybe move it at
|
||||
// some point to be stored in the world object?
|
||||
m_GameView->RegisterInit(pAttribs);
|
||||
m_World->RegisterInit(pAttribs);
|
||||
@ -85,6 +110,11 @@ PSRETURN CGame::RegisterInit(CGameAttributes* pAttribs)
|
||||
LDR_EndRegistering();
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* Game initialization has been completed. Set game started flag and start the session.
|
||||
*
|
||||
* @return PSRETURN 0
|
||||
**/
|
||||
PSRETURN CGame::ReallyStartGame()
|
||||
{
|
||||
#ifndef NO_GUI
|
||||
@ -117,6 +147,14 @@ PSRETURN CGame::ReallyStartGame()
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare to start the game.
|
||||
* Set up the players list then call RegisterInit that initializes the game and is used to report progress.
|
||||
*
|
||||
* @param CGameAttributes * pGameAttributes game attributes for initialization.
|
||||
* @return PSRETURN 0 if successful,
|
||||
* error information if not.
|
||||
**/
|
||||
PSRETURN CGame::StartGame(CGameAttributes *pAttribs)
|
||||
{
|
||||
try
|
||||
@ -157,6 +195,20 @@ PSRETURN CGame::StartGame(CGameAttributes *pAttribs)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// TODO: doInterpolate is optional because Atlas interpolates explicitly,
|
||||
// so that it has more control over the update rate. The game might want to
|
||||
// do the same, and then doInterpolate should be redundant and removed.
|
||||
|
||||
/**
|
||||
* Periodic heartbeat that controls the process.
|
||||
* Simulation update is called and game status update is called.
|
||||
*
|
||||
* @param double deltaTime elapsed time since last beat in seconds.
|
||||
* @param bool doInterpolate perform interpolation if true.
|
||||
* @return bool false if it can't keep up with the desired simulation rate
|
||||
* indicating that you might want to render less frequently.
|
||||
**/
|
||||
bool CGame::Update(double deltaTime, bool doInterpolate)
|
||||
{
|
||||
if (m_Paused)
|
||||
@ -183,6 +235,10 @@ bool CGame::Update(double deltaTime, bool doInterpolate)
|
||||
return ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test player statistics and update game status as required.
|
||||
*
|
||||
**/
|
||||
void CGame::UpdateGameStatus()
|
||||
{
|
||||
bool EOG_lose = true;
|
||||
@ -221,6 +277,10 @@ void CGame::UpdateGameStatus()
|
||||
GameStatus = EOG_NEUTRAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* End of game console message creation.
|
||||
*
|
||||
**/
|
||||
void CGame::EndGame()
|
||||
{
|
||||
g_Console->InsertMessage( L"It's the end of the game as we know it!");
|
||||
@ -242,6 +302,12 @@ void CGame::EndGame()
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the player object from the players list at the provided index.
|
||||
*
|
||||
* @param PS_uint idx sequential position in the list.
|
||||
* @return CPlayer * pointer to player requested.
|
||||
**/
|
||||
CPlayer *CGame::GetPlayer(uint idx)
|
||||
{
|
||||
if (idx > m_NumPlayers)
|
||||
|
141
source/ps/Game.h
141
source/ps/Game.h
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* File : Game.h
|
||||
* Project : engine
|
||||
* Description : Contains the CGame Class which is a representation of the game itself.
|
||||
*
|
||||
**/
|
||||
#ifndef _ps_Game_H
|
||||
#define _ps_Game_H
|
||||
|
||||
@ -11,38 +17,75 @@ class CSimulation;
|
||||
class CPlayer;
|
||||
class CGameAttributes;
|
||||
|
||||
// Default player limit (not counting the Gaia player)
|
||||
// This may be overridden by system.cfg ("max_players")
|
||||
/**
|
||||
* Default player limit (not counting the Gaia player)
|
||||
* This may be overridden by system.cfg ("max_players")
|
||||
**/
|
||||
#define PS_MAX_PLAYERS 8
|
||||
|
||||
class CGame
|
||||
/**
|
||||
* The container that holds the rules, resources and attributes of the game.
|
||||
* The CGame object is responsible for creating a game that is defined by
|
||||
* a set of attributes provided. The CGame object is also responsible for
|
||||
* maintaining the relations between CPlayer and CWorld, CSimulation and CWorld.
|
||||
**/
|
||||
class CGame : boost::noncopyable
|
||||
{
|
||||
/**
|
||||
* pointer to the CWorld object representing the game world.
|
||||
**/
|
||||
CWorld *m_World;
|
||||
/**
|
||||
* pointer to the CSimulation object operating on the game world.
|
||||
**/
|
||||
CSimulation *m_Simulation;
|
||||
/**
|
||||
* pointer to the CGameView object representing the view into the game world.
|
||||
**/
|
||||
CGameView *m_GameView;
|
||||
|
||||
/**
|
||||
* pointer to the local CPlayer object operating on the game world.
|
||||
**/
|
||||
CPlayer *m_pLocalPlayer;
|
||||
/**
|
||||
* STL vectors of pointers to all CPlayer objects(including gaia) operating on the game world.
|
||||
**/
|
||||
std::vector<CPlayer *> m_Players;
|
||||
/**
|
||||
* number of players operating on the game world(not including gaia).
|
||||
**/
|
||||
uint m_NumPlayers;
|
||||
|
||||
/**
|
||||
* the game has been initialized and ready for use if true.
|
||||
**/
|
||||
bool m_GameStarted;
|
||||
|
||||
/**
|
||||
* total elapsed game time in seconds.
|
||||
**/
|
||||
double m_Time; // needs to be double to get enough precision
|
||||
/**
|
||||
* scale multiplier for simulation rate.
|
||||
**/
|
||||
float m_SimRate;
|
||||
|
||||
/**
|
||||
* enumerated values for game status.
|
||||
**/
|
||||
enum EOG
|
||||
{
|
||||
EOG_NEUTRAL,
|
||||
EOG_DRAW, //Draw by means of agreement of civilization
|
||||
EOG_SPECIAL_DRAW, //Theoretically, players could die at the same time...?
|
||||
EOG_LOSE,
|
||||
EOG_WIN
|
||||
EOG_NEUTRAL, /// Game is in progress
|
||||
EOG_DRAW, /// Game is over as a Draw by means of agreement of civilizations
|
||||
EOG_SPECIAL_DRAW, /// Game is over by players dying at the same time...?
|
||||
EOG_LOSE, /// Game is over, local player loses
|
||||
EOG_WIN /// Game is over, local player wins
|
||||
} GameStatus;
|
||||
|
||||
public:
|
||||
CGame();
|
||||
~CGame();
|
||||
|
||||
/**
|
||||
* the game is paused and no updates will be performed if true.
|
||||
**/
|
||||
bool m_Paused;
|
||||
|
||||
/*
|
||||
@ -57,19 +100,23 @@ public:
|
||||
/*
|
||||
Perform all per-frame updates
|
||||
*/
|
||||
|
||||
// Returns false if it can't keep up with the desired simulation rate
|
||||
// (indicating that you might want to render less frequently, or something).
|
||||
// TODO: doInterpolate is optional because Atlas interpolates explicitly,
|
||||
// so that it has more control over the update rate. The game might want to
|
||||
// do the same, and then doInterpolate should be redundant and removed.
|
||||
bool Update(double deltaTime, bool doInterpolate = true);
|
||||
|
||||
void UpdateGameStatus();
|
||||
void EndGame();
|
||||
|
||||
/**
|
||||
* Get pointer to the local player object.
|
||||
*
|
||||
* @return CPlayer * the value of m_pLocalPlayer.
|
||||
**/
|
||||
inline CPlayer *GetLocalPlayer()
|
||||
{ return m_pLocalPlayer; }
|
||||
/**
|
||||
* Change the pointer to the local player object.
|
||||
*
|
||||
* @param CPlayer * pLocalPlayer pointer to a valid player object.
|
||||
**/
|
||||
inline void SetLocalPlayer(CPlayer *pLocalPlayer)
|
||||
{ m_pLocalPlayer=pLocalPlayer; }
|
||||
|
||||
@ -78,36 +125,82 @@ public:
|
||||
// free to put the inline version back.
|
||||
CPlayer *GetPlayer(uint idx);
|
||||
|
||||
/**
|
||||
* Get a reference to the m_Players vector.
|
||||
*
|
||||
* @return std::vector<CPlayer*> * reference to m_Players.
|
||||
**/
|
||||
inline std::vector<CPlayer*>* GetPlayers()
|
||||
{ return( &m_Players ); }
|
||||
|
||||
inline uint GetNumPlayers()
|
||||
/**
|
||||
* Get m_NumPlayers.
|
||||
*
|
||||
* @return PS_uint the value of m_NumPlayers.
|
||||
**/
|
||||
inline uint GetNumPlayers() const
|
||||
{ return m_NumPlayers; }
|
||||
|
||||
inline bool IsGameStarted()
|
||||
/**
|
||||
* Get m_GameStarted.
|
||||
*
|
||||
* @return bool the value of m_GameStarted.
|
||||
**/
|
||||
inline bool IsGameStarted() const
|
||||
{
|
||||
return m_GameStarted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pointer to the game world object.
|
||||
*
|
||||
* @return CWorld * the value of m_World.
|
||||
**/
|
||||
inline CWorld *GetWorld()
|
||||
{ return m_World; }
|
||||
/**
|
||||
* Get the pointer to the game view object.
|
||||
*
|
||||
* @return CGameView * the value of m_GameView.
|
||||
**/
|
||||
inline CGameView *GetView()
|
||||
{ return m_GameView; }
|
||||
/**
|
||||
* Get the pointer to the simulation object.
|
||||
*
|
||||
* @return CSimulation * the value of m_Simulation.
|
||||
**/
|
||||
inline CSimulation *GetSimulation()
|
||||
{ return m_Simulation; }
|
||||
|
||||
inline double GetTime()
|
||||
/**
|
||||
* Get the current game elapsed time.
|
||||
*
|
||||
* @return double value of m_Time.
|
||||
**/
|
||||
inline double GetTime() const
|
||||
{ return m_Time; }
|
||||
|
||||
/**
|
||||
* Set the simulation scale multiplier.
|
||||
*
|
||||
* @param float simRate value to set m_SimRate to.
|
||||
* Because m_SimRate is also used to
|
||||
* scale TimeSinceLastFrame it must be
|
||||
* clamped to 0.0f.
|
||||
**/
|
||||
inline void SetSimRate(float simRate)
|
||||
{ m_SimRate = std::max(simRate, 0.0f); }
|
||||
inline float GetSimRate()
|
||||
/**
|
||||
* Get the simulation scale multiplier.
|
||||
*
|
||||
* @return float value of m_SimRate.
|
||||
**/
|
||||
inline float GetSimRate() const
|
||||
{ return m_SimRate; }
|
||||
|
||||
private:
|
||||
PSRETURN RegisterInit(CGameAttributes* pAttribs);
|
||||
|
||||
NO_COPY_CTOR(CGame);
|
||||
};
|
||||
|
||||
extern CGame *g_Game;
|
||||
|
@ -24,14 +24,12 @@ static bool ldr_was_interrupted(int ret)
|
||||
return (0 < ret && ret <= 100);
|
||||
}
|
||||
|
||||
template<class T> struct MemFun_t
|
||||
template<class T> struct MemFun_t : boost::noncopyable
|
||||
{
|
||||
T* const this_;
|
||||
int (T::*func)(void);
|
||||
MemFun_t(T* this__, int(T::*func_)(void))
|
||||
: this_(this__), func(func_) {}
|
||||
|
||||
NO_COPY_CTOR(MemFun_t);
|
||||
};
|
||||
|
||||
template<class T> static int MemFunThunk(void* param, double UNUSED(time_left))
|
||||
@ -55,15 +53,13 @@ template<class T> void RegMemFun(T* this_, int(T::*func)(void),
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
template<class T, class Arg> struct MemFun1_t
|
||||
template<class T, class Arg> struct MemFun1_t : boost::noncopyable
|
||||
{
|
||||
T* const this_;
|
||||
Arg arg;
|
||||
int (T::*func)(Arg);
|
||||
MemFun1_t(T* this__, int(T::*func_)(Arg), Arg arg_)
|
||||
: this_(this__), func(func_), arg(arg_) {}
|
||||
|
||||
NO_COPY_CTOR(MemFun1_t);
|
||||
};
|
||||
|
||||
template<class T, class Arg> static int MemFun1Thunk(void* param, double UNUSED(time_left))
|
||||
|
@ -138,7 +138,7 @@ public:
|
||||
// CScopeLock
|
||||
// ---------------------------------------------------------------------| Class
|
||||
// Locks a CMutex over the objects lifetime
|
||||
class CScopeLock
|
||||
class CScopeLock : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
inline CScopeLock(pthread_mutex_t &mutex): m_Mutex(mutex)
|
||||
@ -158,8 +158,6 @@ public:
|
||||
|
||||
private:
|
||||
pthread_mutex_t &m_Mutex;
|
||||
|
||||
NO_COPY_CTOR(CScopeLock);
|
||||
};
|
||||
|
||||
// CLocker
|
||||
|
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* File : World.cpp
|
||||
* Project : engine
|
||||
* Description : Contains the CWorld Class implementation.
|
||||
*
|
||||
**/
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "graphics/GameView.h"
|
||||
@ -26,11 +32,19 @@
|
||||
|
||||
#define LOG_CATEGORY "world"
|
||||
|
||||
// global light settings. this is not a member of CWorld because it is
|
||||
// passed to the renderer before CWorld exists.
|
||||
/**
|
||||
* Global light settings.
|
||||
* It is not a member of CWorld because it is passed
|
||||
* to the renderer before CWorld exists.
|
||||
**/
|
||||
CLightEnv g_LightEnv;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param CGame * pGame pointer to the container game object.
|
||||
**/
|
||||
CWorld::CWorld(CGame *pGame):
|
||||
m_pGame(pGame),
|
||||
m_Terrain(new CTerrain()),
|
||||
@ -42,6 +56,11 @@ CWorld::CWorld(CGame *pGame):
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the game world and loads required world resources.
|
||||
*
|
||||
* @param CGameAttributes * pGameAttributes pointer to the game attribute values.
|
||||
**/
|
||||
void CWorld::Initialize(CGameAttributes *pAttribs)
|
||||
{
|
||||
// TODO: Find a better way of handling these global things
|
||||
@ -70,12 +89,21 @@ void CWorld::Initialize(CGameAttributes *pAttribs)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the game world with the attributes provided.
|
||||
*
|
||||
* @param CGameAttributes * pGameAttributes pointer to the game attribute values.
|
||||
**/
|
||||
void CWorld::RegisterInit(CGameAttributes *pAttribs)
|
||||
{
|
||||
Initialize(pAttribs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*
|
||||
**/
|
||||
CWorld::~CWorld()
|
||||
{
|
||||
delete m_Terrain;
|
||||
@ -87,6 +115,11 @@ CWorld::~CWorld()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Redraw the world.
|
||||
* Provided for JS _rewritemaps function.
|
||||
*
|
||||
**/
|
||||
void CWorld::RewriteMap()
|
||||
{
|
||||
CMapWriter::RewriteAllMaps(m_Terrain, m_UnitManager,
|
||||
|
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* File : World.h
|
||||
* Project : engine
|
||||
* Description : Contains the CWorld Class which contains all the entities and represents them at a specific moment in time.
|
||||
*
|
||||
**/
|
||||
#ifndef _ps_World_H
|
||||
#define _ps_World_H
|
||||
|
||||
@ -19,16 +25,41 @@ class CLOSManager;
|
||||
class CTerritoryManager;
|
||||
class CTerrain;
|
||||
|
||||
class CWorld
|
||||
/**
|
||||
* CWorld is a general data class containing whatever is needed to accurately represent the world.
|
||||
* This includes the map, entities, influence maps, tiles, heightmap, etc.
|
||||
**/
|
||||
class CWorld : boost::noncopyable
|
||||
{
|
||||
/**
|
||||
* pointer to the CGame object representing the game.
|
||||
**/
|
||||
CGame *m_pGame;
|
||||
|
||||
/**
|
||||
* pointer to the CTerrain object representing the height map.
|
||||
**/
|
||||
CTerrain *m_Terrain;
|
||||
|
||||
/**
|
||||
* pointer to the CUnitManager that holds all the units in the world.
|
||||
**/
|
||||
CUnitManager *m_UnitManager;
|
||||
/**
|
||||
* pointer to the CEntityManager that holds all the entities in the world.
|
||||
**/
|
||||
CEntityManager *m_EntityManager;
|
||||
/**
|
||||
* pointer to the CProjectileManager that holds all the projectiles in the world.
|
||||
**/
|
||||
CProjectileManager *m_ProjectileManager;
|
||||
/**
|
||||
* pointer to the CLOSManager that holds the visibility matrix for the world.
|
||||
**/
|
||||
CLOSManager *m_LOSManager;
|
||||
/**
|
||||
* pointer to the CTerritoryManager that holds territory matrix for the world.
|
||||
**/
|
||||
CTerritoryManager *m_TerritoryManager;
|
||||
|
||||
public:
|
||||
@ -44,20 +75,49 @@ public:
|
||||
// provided for JS _rewritemaps function
|
||||
void RewriteMap();
|
||||
|
||||
/**
|
||||
* Get the pointer to the terrain object.
|
||||
*
|
||||
* @return CTerrain * the value of m_Terrain.
|
||||
**/
|
||||
inline CTerrain *GetTerrain()
|
||||
{ return m_Terrain; }
|
||||
|
||||
/**
|
||||
* Get a reference to the unit manager object.
|
||||
*
|
||||
* @return CUnitManager & dereferenced m_UnitManager.
|
||||
**/
|
||||
inline CUnitManager &GetUnitManager()
|
||||
{ return *m_UnitManager; }
|
||||
/**
|
||||
* Get a reference to the entity manager object.
|
||||
*
|
||||
* @return CWorld CEntityManager & dereferenced m_EntityManager.
|
||||
**/
|
||||
inline CEntityManager &GetEntityManager()
|
||||
{ return *m_EntityManager; }
|
||||
/**
|
||||
* Get a reference to the projectile manager object.
|
||||
*
|
||||
* @return CProjectileManager & dereferenced m_ProjectileManager.
|
||||
**/
|
||||
inline CProjectileManager &GetProjectileManager()
|
||||
{ return *m_ProjectileManager; }
|
||||
/**
|
||||
* Get the pointer to the LOS manager object.
|
||||
*
|
||||
* @return CLOSManager * the value of m_LOSManager.
|
||||
**/
|
||||
inline CLOSManager *GetLOSManager()
|
||||
{ return m_LOSManager; }
|
||||
/**
|
||||
* Get the pointer to the territory manager object.
|
||||
*
|
||||
* @return CTerritoryManager * the value of m_TerritoryManager.
|
||||
**/
|
||||
inline CTerritoryManager *GetTerritoryManager()
|
||||
{ return m_TerritoryManager; }
|
||||
|
||||
NO_COPY_CTOR(CWorld);
|
||||
};
|
||||
|
||||
// rationale: see definition.
|
||||
|
@ -76,7 +76,7 @@
|
||||
* Accesses CRenderer::m_Stats by keeping the reference passed to the
|
||||
* constructor.
|
||||
*/
|
||||
class CRendererStatsTable : public AbstractProfileTable
|
||||
class CRendererStatsTable : public AbstractProfileTable, boost::noncopyable
|
||||
{
|
||||
public:
|
||||
CRendererStatsTable(const CRenderer::Stats& st);
|
||||
@ -106,8 +106,6 @@ private:
|
||||
// Must be last to count number of rows
|
||||
NumberRows
|
||||
};
|
||||
|
||||
NO_COPY_CTOR(CRendererStatsTable);
|
||||
};
|
||||
|
||||
// Construction
|
||||
|
@ -75,7 +75,7 @@ enum EntityFlags
|
||||
|
||||
// TODO MT: Put this is /some/ sort of order...
|
||||
|
||||
class CEntity : public CJSComplex<CEntity>, public IEventTarget
|
||||
class CEntity : public CJSComplex<CEntity>, public IEventTarget, boost::noncopyable
|
||||
{
|
||||
friend class CEntityManager;
|
||||
friend class CUnit;
|
||||
@ -485,8 +485,6 @@ public:
|
||||
|
||||
// Functions that call script code
|
||||
int GetAttackAction( HEntity target );
|
||||
|
||||
NO_COPY_CTOR(CEntity);
|
||||
};
|
||||
|
||||
// General entity globals
|
||||
|
@ -29,7 +29,7 @@ class CPlayer;
|
||||
class CXeromyces;
|
||||
class XMBElement;
|
||||
|
||||
class CEntityTemplate : public CJSComplex<CEntityTemplate>, public IEventTarget
|
||||
class CEntityTemplate : public CJSComplex<CEntityTemplate>, public IEventTarget, boost::noncopyable
|
||||
{
|
||||
public:
|
||||
CPlayer* m_player; // Which player this template is for, or null for the no-player template
|
||||
@ -172,8 +172,6 @@ public:
|
||||
|
||||
private:
|
||||
static STL_HASH_SET<CStr, CStr_hash_compare> scriptsLoaded;
|
||||
|
||||
NO_COPY_CTOR(CEntityTemplate);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "renderer/Scene.h"
|
||||
#include "renderer/SkyManager.h"
|
||||
|
||||
struct ActorViewerImpl : public Scene
|
||||
struct ActorViewerImpl : public Scene, boost::noncopyable
|
||||
{
|
||||
ActorViewerImpl()
|
||||
: Unit(NULL), MeshManager(), ObjectManager(MeshManager)
|
||||
@ -53,8 +53,6 @@ struct ActorViewerImpl : public Scene
|
||||
if (Unit)
|
||||
c->SubmitRecursive(Unit->GetModel());
|
||||
}
|
||||
|
||||
NO_COPY_CTOR(ActorViewerImpl);
|
||||
};
|
||||
|
||||
ActorViewer::ActorViewer()
|
||||
|
@ -6,7 +6,7 @@ struct SColor4ub;
|
||||
class CUnit;
|
||||
class CStrW;
|
||||
|
||||
class ActorViewer
|
||||
class ActorViewer : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
ActorViewer();
|
||||
@ -29,8 +29,6 @@ public:
|
||||
|
||||
private:
|
||||
ActorViewerImpl& m;
|
||||
|
||||
NO_COPY_CTOR(ActorViewer);
|
||||
};
|
||||
|
||||
#endif // ACTORVIEWER_H__
|
||||
|
Loading…
Reference in New Issue
Block a user