[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Enigma-cvs] enigma/src enigma.cc,1.29,1.30
From: |
Daniel Heck <address@hidden> |
Subject: |
[Enigma-cvs] enigma/src enigma.cc,1.29,1.30 |
Date: |
Sun, 16 Nov 2003 19:24:06 +0000 |
Update of /cvsroot/enigma/enigma/src
In directory subversions:/tmp/cvs-serv13053/src
Modified Files:
enigma.cc
Log Message:
Added RegisterImage(). Adapt to px::Cache changes.
Index: enigma.cc
===================================================================
RCS file: /cvsroot/enigma/enigma/src/enigma.cc,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** enigma.cc 1 Nov 2003 23:44:34 -0000 1.29
--- enigma.cc 16 Nov 2003 19:24:03 -0000 1.30
***************
*** 35,67 ****
using namespace enigma;
- namespace
- {
- class FontAlloc {
- public:
- Font *acquire (const std::string &name) {
- string png, bmf;
- using enigma::FindFile;
- if (FindFile (string("fonts/")+name+".png", png) &&
- FindFile (string("fonts/")+name+".bmf", bmf))
- {
- return px::LoadBitmapFont(png.c_str(), bmf.c_str());
- }
- else
- return 0;
- }
- void release(Font *f) { delete f; }
- };
-
- class ImageAlloc {
- public:
- Surface *acquire(const std::string &name) {
- return px::LoadImage(name.c_str());
- }
- void release(Surface *s) { delete s; }
- };
-
- typedef Cache<Surface*, ImageAlloc> ImageCache;
- }
-
// ---------------------
// Direction :
--- 35,38 ----
***************
*** 416,424 ****
rep.alarms.clear();
}
- //----------------------------------------------------------------------
- // Data path
- //----------------------------------------------------------------------
namespace
{
--- 387,418 ----
rep.alarms.clear();
}
+
+ /* -------------------- Random numbers -------------------- */
+
+ void enigma::Randomize ()
+ {
+ srand (time(NULL));
+ }
+
+ void enigma::Randomize (unsigned seed)
+ {
+ srand (seed);
+ }
+
+ int enigma::IntegerRand (int min, int max)
+ {
+ int r = int((max-min+1) * (rand()/(RAND_MAX+1.0)));
+ return r+min;
+ }
+
+ double enigma::DoubleRand (double min, double max)
+ {
+ return min + double(rand())/RAND_MAX * (max-min);
+ }
+
+
+ /* -------------------- Searching for files -------------------- */
namespace
{
***************
*** 546,556 ****
}
! //----------------------------------------------------------------------
! // Resource management
! //----------------------------------------------------------------------
namespace
{
! px::Cache<px::Font *, FontAlloc> font_cache;
! px::Cache<px::Surface*, ImageAlloc> image_cache;
}
--- 540,596 ----
}
!
! /* -------------------- Time & Date -------------------- */
!
! #define MAX_DATE_LENGTH 256
! const char *enigma::date(const char *format) { // format see 'man strftime'
! static char *result = 0;
! char buffer[MAX_DATE_LENGTH];
!
! time_t t;
! time(&t);
!
! struct tm *tm = localtime(&t);
! strftime(buffer, MAX_DATE_LENGTH, format, tm);
!
! if (result) free(result);
! result = strdup(buffer);
!
! return result;
! }
!
!
! /* -------------------- Resource management -------------------- */
!
namespace
{
! class FontCache : public PtrCache<Font> {
! public:
! Font *acquire (const std::string &name) {
! string png, bmf;
! using enigma::FindFile;
! if (FindFile (string("fonts/")+name+".png", png) &&
! FindFile (string("fonts/")+name+".bmf", bmf))
! {
! return px::LoadBitmapFont(png.c_str(), bmf.c_str());
! }
! else
! return 0;
! }
! };
!
! class ImageCache : public PtrCache<Surface> {
! public:
! using Cache<Surface*>::store;
!
! Surface *acquire(const std::string &name) {
! return px::LoadImage(name.c_str());
! }
! };
!
! // ---------- Variables ----------
!
! FontCache font_cache;
! ImageCache image_cache;
}
***************
*** 585,627 ****
}
!
! //----------------------------------------
! // Random numbers
! //----------------------------------------
! void enigma::Randomize ()
! {
! srand (time(NULL));
! }
!
! void enigma::Randomize (unsigned seed)
! {
! srand (seed);
! }
!
! int enigma::IntegerRand (int min, int max)
! {
! int r = int((max-min+1) * (rand()/(RAND_MAX+1.0)));
! return r+min;
! }
!
! double enigma::DoubleRand (double min, double max)
! {
! return min + double(rand())/RAND_MAX * (max-min);
! }
!
! #define MAX_DATE_LENGTH 256
! const char *enigma::date(const char *format) { // format see 'man strftime'
! static char *result = 0;
! char buffer[MAX_DATE_LENGTH];
!
! time_t t;
! time(&t);
!
! struct tm *tm = localtime(&t);
! strftime(buffer, MAX_DATE_LENGTH, format, tm);
!
! if (result) free(result);
! result = strdup(buffer);
!
! return result;
}
--- 625,631 ----
}
! px::Surface *
! enigma::RegisterImage (const char *name, px::Surface *s) {
! image_cache.store(name, s);
! return s;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Enigma-cvs] enigma/src enigma.cc,1.29,1.30,
Daniel Heck <address@hidden> <=
- Prev by Date:
[Enigma-cvs] enigma/src enigma-lua.pkg, 1.21, 1.22 enigma-lua.hh, 1.25, 1.26 enigma-lua.cc, 1.26, 1.27
- Next by Date:
[Enigma-cvs] enigma/src enigma.hh,1.20,1.21
- Previous by thread:
[Enigma-cvs] enigma/src enigma-lua.pkg, 1.21, 1.22 enigma-lua.hh, 1.25, 1.26 enigma-lua.cc, 1.26, 1.27
- Next by thread:
[Enigma-cvs] enigma/src enigma.hh,1.20,1.21
- Index(es):