Ver código fonte

Screenshot command and other small improvements

Thomas Buck 10 anos atrás
pai
commit
16dbdf29cd

+ 1
- 0
ChangeLog.md Ver arquivo

14
     * Added utf8-cpp dependency to allow Console to delete multi-byte chars
14
     * Added utf8-cpp dependency to allow Console to delete multi-byte chars
15
     * Added stream-style printing to Console
15
     * Added stream-style printing to Console
16
     * Using Console like Stream everywhere, removed old print method
16
     * Using Console like Stream everywhere, removed old print method
17
+    * Added Screenshot command back
17
 
18
 
18
     [ 20140809 ]
19
     [ 20140809 ]
19
     * Script Unit Test brings it’s own scripts to test
20
     * Script Unit Test brings it’s own scripts to test

+ 2
- 1
include/Game.h Ver arquivo

8
 #ifndef _GAME_H_
8
 #ifndef _GAME_H_
9
 #define _GAME_H_
9
 #define _GAME_H_
10
 
10
 
11
+#include <string>
11
 #include <vector>
12
 #include <vector>
12
 
13
 
13
 #include "Entity.h"
14
 #include "Entity.h"
50
     void processModels();
51
     void processModels();
51
     void processRooms();
52
     void processRooms();
52
 
53
 
53
-    char *mName;
54
+    std::string levelName;
54
     bool mLoaded;
55
     bool mLoaded;
55
 
56
 
56
     TombRaider mTombRaider;
57
     TombRaider mTombRaider;

+ 1
- 1
include/Render.h Ver arquivo

53
      * \brief Makes a screenshot, writes to disk
53
      * \brief Makes a screenshot, writes to disk
54
      * \param filenameBase basename of file to be written
54
      * \param filenameBase basename of file to be written
55
      */
55
      */
56
-    void screenShot(char *filenameBase);
56
+    void screenShot(const char *filenameBase);
57
 
57
 
58
     /*!
58
     /*!
59
      * \brief Gets current rendering mode
59
      * \brief Gets current rendering mode

+ 2
- 2
include/TombRaider.h Ver arquivo

134
      * \returns 0 on success, < 0 on error
134
      * \returns 0 on success, < 0 on error
135
      * \sa TombRaider::loadTR5()
135
      * \sa TombRaider::loadTR5()
136
      */
136
      */
137
-    int Load(char *filename);
137
+    int Load(const char *filename);
138
 
138
 
139
     /*!
139
     /*!
140
      * \brief Makes a clamped 0.0 to 1.0 texel from coord pair
140
      * \brief Makes a clamped 0.0 to 1.0 texel from coord pair
586
      * \param filename pak to load
586
      * \param filename pak to load
587
      * \returns < 0 on error
587
      * \returns < 0 on error
588
      */
588
      */
589
-    int loadSFX(char *filename);
589
+    int loadSFX(const char *filename);
590
 
590
 
591
     void reset();
591
     void reset();
592
 
592
 

+ 1
- 0
include/config.h.in Ver arquivo

9
 #define _CONFIG_H_
9
 #define _CONFIG_H_
10
 
10
 
11
 extern const char *VERSION;
11
 extern const char *VERSION;
12
+extern const char *VERSION_SHORT;
12
 extern const char *BUILD_HOST;
13
 extern const char *BUILD_HOST;
13
 
14
 
14
 #cmakedefine USING_AL
15
 #cmakedefine USING_AL

+ 0
- 8
include/utils/strings.h Ver arquivo

28
 /*!
28
 /*!
29
  * \brief Generates a buffered string for the printf call
29
  * \brief Generates a buffered string for the printf call
30
  * \param string format string like for printf
30
  * \param string format string like for printf
31
- * \param args arguments matching format string
32
- * \returns string in a buffer
33
- */
34
-char *bufferString(const char *string, va_list args) __attribute__((format(printf, 1, 0)));
35
-
36
-/*!
37
- * \brief Generates a buffered string for the printf call
38
- * \param string format string like for printf
39
  * \returns string in a buffer
31
  * \returns string in a buffer
40
  */
32
  */
41
 char *bufferString(const char *string, ...) __attribute__((format(printf, 1, 2)));
33
 char *bufferString(const char *string, ...) __attribute__((format(printf, 1, 2)));

+ 34
- 29
src/Command.cpp Ver arquivo

97
             getConsole() << "  bind      - bind a keyboard/mouse action" << Console::endl;
97
             getConsole() << "  bind      - bind a keyboard/mouse action" << Console::endl;
98
             getConsole() << "  animate   - [BOOL|n|p] - Animate models" << Console::endl;
98
             getConsole() << "  animate   - [BOOL|n|p] - Animate models" << Console::endl;
99
             getConsole() << "  move      - [walk|fly|noclip]" << Console::endl;
99
             getConsole() << "  move      - [walk|fly|noclip]" << Console::endl;
100
-/*
101
             getConsole() << "  sshot     - make a screenshot" << Console::endl;
100
             getConsole() << "  sshot     - make a screenshot" << Console::endl;
101
+/*
102
             getConsole() << "  sound     - INT - Test play sound" << Console::endl;
102
             getConsole() << "  sound     - INT - Test play sound" << Console::endl;
103
             getConsole() << "  mode      - MODE - Render mode" << Console::endl;
103
             getConsole() << "  mode      - MODE - Render mode" << Console::endl;
104
             getConsole() << "  light     - BOOL - GL Lights" << Console::endl;
104
             getConsole() << "  light     - BOOL - GL Lights" << Console::endl;
184
             return -9;
184
             return -9;
185
         }
185
         }
186
         getConsole() << temp.c_str()  << "ing" << Console::endl;
186
         getConsole() << temp.c_str()  << "ing" << Console::endl;
187
-
187
+    } else if (cmd.compare("sshot") == 0) {
188
+        if (!mRunning) {
189
+            getConsole() << "Use sshot command interactively!" << Console::endl;
190
+            return -999;
191
+        }
192
+        std::string filename(mBaseDir);
193
+        filename += "/sshots/";
194
+        filename += VERSION_SHORT;
195
+        bool console = false, menu = false;
196
+        std::string temp;
197
+        command >> temp;
198
+        if (temp.compare("console") == 0)
199
+            console = true;
200
+        if (temp.compare("menu") == 0)
201
+            menu = true;
202
+        if (!console) {
203
+            getConsole().setVisible(false);
204
+            if (menu)
205
+                getMenu().setVisible(true);
206
+            frame();
207
+            frame(); // Double buffered
208
+        }
209
+        getRender().screenShot(filename.c_str());
210
+        if (!console) {
211
+            getConsole().setVisible(true);
212
+            if (menu)
213
+                getMenu().setVisible(false);
214
+        }
215
+        getConsole() << "Screenshot stored..." << Console::endl;
188
 /*
216
 /*
189
     } else if (cmd.compare("mode") == 0) {
217
     } else if (cmd.compare("mode") == 0) {
190
         std::string mode;
218
         std::string mode;
308
             getConsole().print("Invalid use of ponytail-command!");
336
             getConsole().print("Invalid use of ponytail-command!");
309
             return -45;
337
             return -45;
310
         }
338
         }
311
-    } else if (cmd.compare("sshot") == 0) {
312
-        if (!mRunning) {
313
-            getConsole().print("Use sshot command interactively!");
314
-            return -999;
315
-        }
316
-        char *filename = bufferString("%s/sshots/%s", mBaseDir, VERSION);
317
-        bool console = (args->size() > 0) && (strcmp(args->at(0), "console") == 0);
318
-        bool menu = (args->size() > 0) && (strcmp(args->at(0), "menu") == 0);
319
-        if (!console) {
320
-            getConsole().setVisible(false);
321
-            if (menu)
322
-                getMenu().setVisible(true);
323
-            frame();
324
-            frame(); // Double buffered
325
-        }
326
-        getRender().screenShot(filename);
327
-        if (!console) {
328
-            getConsole().setVisible(true);
329
-            if (menu)
330
-                getMenu().setVisible(false);
331
-        }
332
-        getConsole().print("Screenshot stored...");
333
-        delete filename;
334
     } else if (cmd.compare("sound") == 0) {
339
     } else if (cmd.compare("sound") == 0) {
335
         if ((!mRunning) || (!getGame().isLoaded())) {
340
         if ((!mRunning) || (!getGame().isLoaded())) {
336
             getConsole().print("Use sound command interactively!");
341
             getConsole().print("Use sound command interactively!");
439
     } else if (cmd.compare("load") == 0) {
444
     } else if (cmd.compare("load") == 0) {
440
         getConsole() << "load-Command Usage:" << Console::endl;
445
         getConsole() << "load-Command Usage:" << Console::endl;
441
         getConsole() << "  load /path/to/level" << Console::endl;
446
         getConsole() << "  load /path/to/level" << Console::endl;
442
-/*
443
     } else if (cmd.compare("sshot") == 0) {
447
     } else if (cmd.compare("sshot") == 0) {
444
-        getConsole().print("sshot-Command Usage:");
445
-        getConsole().print("  sshot [console|menu]");
446
-        getConsole().print("Add console/menu to capture them too");
448
+        getConsole() << "sshot-Command Usage:" << Console::endl;
449
+        getConsole() << "  sshot [console|menu]" << Console::endl;
450
+        getConsole() << "Add console/menu to capture them too" << Console::endl;
451
+/*
447
     } else if (cmd.compare("sound") == 0) {
452
     } else if (cmd.compare("sound") == 0) {
448
         getConsole().print("sound-Command Usage:");
453
         getConsole().print("sound-Command Usage:");
449
         getConsole().print("  sound INT");
454
         getConsole().print("  sound INT");

+ 9
- 20
src/Game.cpp Ver arquivo

30
 
30
 
31
 Game::Game() {
31
 Game::Game() {
32
     mLoaded = false;
32
     mLoaded = false;
33
-    mName = NULL;
34
     mLara = -1;
33
     mLara = -1;
35
     mTextureStart = 0;
34
     mTextureStart = 0;
36
     mTextureOffset = 0;
35
     mTextureOffset = 0;
58
 }
57
 }
59
 
58
 
60
 void Game::destroy() {
59
 void Game::destroy() {
61
-    delete [] mName;
62
-    mName = NULL;
63
-
64
     mLoaded = false;
60
     mLoaded = false;
65
     mLara = -1;
61
     mLara = -1;
66
     getRender().setMode(Render::modeDisabled);
62
     getRender().setMode(Render::modeDisabled);
78
     if (mLoaded)
74
     if (mLoaded)
79
         destroy();
75
         destroy();
80
 
76
 
81
-    mName = bufferString("%s", level);
77
+    levelName = level;
82
 
78
 
83
-    getConsole() << "Loading " << mName << Console::endl;
84
-    int error = mTombRaider.Load(mName);
79
+    getConsole() << "Loading " << levelName << Console::endl;
80
+    int error = mTombRaider.Load(levelName.c_str());
85
     if (error != 0)
81
     if (error != 0)
86
         return error;
82
         return error;
87
 
83
 
88
     // If required, load the external sound effect file MAIN.SFX into TombRaider
84
     // If required, load the external sound effect file MAIN.SFX into TombRaider
89
     if ((mTombRaider.getEngine() == TR_VERSION_2) || (mTombRaider.getEngine() == TR_VERSION_3)) {
85
     if ((mTombRaider.getEngine() == TR_VERSION_2) || (mTombRaider.getEngine() == TR_VERSION_3)) {
90
-        char *tmp = bufferString("%sMAIN.SFX", level); // Ensure theres enough space
91
-        size_t length = strlen(tmp);
92
-        size_t dir = 0;
93
-        for (long i = length - 1; i >= 0; i--) {
94
-            if ((tmp[i] == '/') || (tmp[i] == '\\')) {
95
-                dir = i + 1; // Find where the filename (bla.tr2) starts
96
-                break;
97
-            }
98
-        }
99
-        strcpy(tmp + dir, "MAIN.SFX"); // overwrite the name itself with MAIN.SFX
100
-        tmp[dir + 8] = '\0';
101
-        error = mTombRaider.loadSFX(tmp);
86
+        std::string tmp(levelName);
87
+        size_t pos = tmp.rfind('/');
88
+        tmp.erase(pos + 1);
89
+        tmp += "MAIN.SFX";
90
+        error = mTombRaider.loadSFX(tmp.c_str());
102
         if (error != 0)
91
         if (error != 0)
103
             getConsole() << "Could not load " << tmp << Console::endl;
92
             getConsole() << "Could not load " << tmp << Console::endl;
104
-        delete [] tmp;
105
     }
93
     }
106
 
94
 
107
     // Process data
95
     // Process data
115
     mTombRaider.reset();
103
     mTombRaider.reset();
116
 
104
 
117
     if (mLara == -1) {
105
     if (mLara == -1) {
106
+        //! \todo Cutscene support
118
         getConsole() << "Can't find Lara entity in level pak!" << Console::endl;
107
         getConsole() << "Can't find Lara entity in level pak!" << Console::endl;
119
         destroy();
108
         destroy();
120
         return -1;
109
         return -1;

+ 3
- 4
src/Menu.cpp Ver arquivo

120
             //! \todo Display something if an error occurs
120
             //! \todo Display something if an error occurs
121
         }
121
         }
122
     } else {
122
     } else {
123
-        char *tmp = bufferString("load %s",
124
-                mapFolder->getFile((unsigned long)mCursor - 1 - mapFolder->folderCount()).getPath().c_str());
125
-        if (getOpenRaider().command(tmp) == 0) {
123
+        std::string tmp = "load ";
124
+        tmp += mapFolder->getFile((unsigned long)mCursor - 1 - mapFolder->folderCount()).getPath();
125
+        if (getOpenRaider().command(tmp.c_str()) == 0) {
126
             setVisible(false);
126
             setVisible(false);
127
         } else {
127
         } else {
128
             //! \todo Display something if an error occurs
128
             //! \todo Display something if an error occurs
129
         }
129
         }
130
-        delete [] tmp;
131
     }
130
     }
132
 }
131
 }
133
 
132
 

+ 10
- 14
src/Render.cpp Ver arquivo

7
  */
7
  */
8
 
8
 
9
 #include <algorithm>
9
 #include <algorithm>
10
+#include <sstream>
10
 
11
 
11
 #include <stdlib.h>
12
 #include <stdlib.h>
12
 #include <math.h>
13
 #include <math.h>
41
 }
42
 }
42
 
43
 
43
 
44
 
44
-void Render::screenShot(char *filenameBase)
45
+void Render::screenShot(const char *filenameBase)
45
 {
46
 {
46
     int sz = getWindow().getWidth() * getWindow().getHeight();
47
     int sz = getWindow().getWidth() * getWindow().getHeight();
47
     unsigned char *image = new unsigned char[sz * 3];
48
     unsigned char *image = new unsigned char[sz * 3];
48
-    char *filename = NULL;
49
     static int count = 0;
49
     static int count = 0;
50
     bool done = false;
50
     bool done = false;
51
 
51
 
52
-    assert(filenameBase != NULL);
52
+    assert(filenameBase != nullptr);
53
 
53
 
54
     // Don't overwrite files
54
     // Don't overwrite files
55
+    std::ostringstream filename;
55
     while (!done) {
56
     while (!done) {
56
-        filename = bufferString("%s-%04i.tga", filenameBase, count++);
57
+        filename << filenameBase << "-" << count++ << ".tga";
57
 
58
 
58
-        FILE *f = fopen(filename, "rb");
59
-
60
-        if (f)
59
+        FILE *f = fopen(filename.str().c_str(), "rb");
60
+        if (f) {
61
             fclose(f);
61
             fclose(f);
62
-        else
62
+        } else {
63
             done = true;
63
             done = true;
64
+        }
64
     }
65
     }
65
 
66
 
66
-    // Capture frame buffer
67
     glReadPixels(0, 0, getWindow().getWidth(), getWindow().getHeight(), GL_BGR_EXT, GL_UNSIGNED_BYTE, image);
67
     glReadPixels(0, 0, getWindow().getWidth(), getWindow().getHeight(), GL_BGR_EXT, GL_UNSIGNED_BYTE, image);
68
-
69
-    tgaSave(filename, image, getWindow().getWidth(), getWindow().getHeight(), 0);
70
-    printf("Took screenshot '%s'.\n", filename);
71
-
72
-    delete [] filename;
68
+    tgaSave(filename.str().c_str(), image, getWindow().getWidth(), getWindow().getHeight(), 0);
73
     delete [] image;
69
     delete [] image;
74
 }
70
 }
75
 
71
 

+ 6
- 6
src/TextureManager.cpp Ver arquivo

46
     delete [] image;
46
     delete [] image;
47
 
47
 
48
     //! \fixme Temporary
48
     //! \fixme Temporary
49
-    char *filename = bufferString("%s/tr2/TITLE.PCX", getOpenRaider().mPakDir);
50
-    if (loadPCX(filename) < 0) {
51
-        delete [] filename;
49
+    std::string filename(getOpenRaider().mPakDir);
50
+    filename += "/tr2/TITLE.PCX";
51
+    if (loadPCX(filename.c_str()) < 0) {
52
         //! \fixme Error Checking. Return negative error code, check in calling place too
52
         //! \fixme Error Checking. Return negative error code, check in calling place too
53
-        filename = bufferString("%s/%s", getOpenRaider().mDataDir, "splash.tga");
54
-        loadTGA(filename);
53
+        filename = getOpenRaider().mDataDir;
54
+        filename += "/splash.tga";
55
+        loadTGA(filename.c_str());
55
     }
56
     }
56
-    delete [] filename;
57
 
57
 
58
     return (mTextureIds.size() == 0) ? -1 : 0;
58
     return (mTextureIds.size() == 0) ? -1 : 0;
59
 }
59
 }

+ 2
- 2
src/TombRaider.cpp Ver arquivo

400
 }
400
 }
401
 
401
 
402
 
402
 
403
-int TombRaider::Load(char *filename)
403
+int TombRaider::Load(const char *filename)
404
 {
404
 {
405
     FILE *f;
405
     FILE *f;
406
     int i, j, l;
406
     int i, j, l;
4046
 // Public Mutators
4046
 // Public Mutators
4047
 ////////////////////////////////////////////////////////////
4047
 ////////////////////////////////////////////////////////////
4048
 
4048
 
4049
-int TombRaider::loadSFX(char *filename)
4049
+int TombRaider::loadSFX(const char *filename)
4050
 {
4050
 {
4051
     FILE *f = fopen(filename, "rb");
4051
     FILE *f = fopen(filename, "rb");
4052
     long bytes = 0;
4052
     long bytes = 0;

+ 2
- 0
src/config.cpp.in Ver arquivo

9
 
9
 
10
 const char *VERSION = "OpenRaider-@OpenRaider_VERSION_MAJOR@.@OpenRaider_VERSION_MINOR@.@OpenRaider_VERSION_MICRO@@OpenRaider_VERSION_RELEASE@ (@CMAKE_BUILD_TYPE@)";
10
 const char *VERSION = "OpenRaider-@OpenRaider_VERSION_MAJOR@.@OpenRaider_VERSION_MINOR@.@OpenRaider_VERSION_MICRO@@OpenRaider_VERSION_RELEASE@ (@CMAKE_BUILD_TYPE@)";
11
 
11
 
12
+const char *VERSION_SHORT = "OpenRaider-@OpenRaider_VERSION_MAJOR@.@OpenRaider_VERSION_MINOR@.@OpenRaider_VERSION_MICRO@@OpenRaider_VERSION_RELEASE@";
13
+
12
 const char *BUILD_HOST = "@OpenRaider_BUILD_HOST@ @OpenRaider_HOSTNAME@";
14
 const char *BUILD_HOST = "@OpenRaider_BUILD_HOST@ @OpenRaider_HOSTNAME@";
13
 
15
 

+ 6
- 15
src/utils/strings.cpp Ver arquivo

80
     return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
80
     return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
81
 }
81
 }
82
 
82
 
83
-char *bufferString(const char *string, va_list args) {
83
+char *bufferString(const char *string, ...) {
84
+    va_list args, tmp;
84
     int sz = 60;
85
     int sz = 60;
85
     int n;
86
     int n;
86
     char *text;
87
     char *text;
87
-    va_list tmp;
88
 
88
 
89
     assert(string != NULL);
89
     assert(string != NULL);
90
     assert(string[0] != '\0');
90
     assert(string[0] != '\0');
91
 
91
 
92
     text = new char[sz];
92
     text = new char[sz];
93
 
93
 
94
-    va_copy(tmp, args);
95
-    n = vsnprintf(text, sz, string, tmp);
96
-    va_end(tmp);
94
+    va_start(args, string);
95
+    n = vsnprintf(text, sz, string, args);
97
 
96
 
98
     if (n < 0) {
97
     if (n < 0) {
99
         delete [] text;
98
         delete [] text;
99
+        va_end(args);
100
         return NULL; // encoding error
100
         return NULL; // encoding error
101
     } else if (n >= sz) {
101
     } else if (n >= sz) {
102
         sz = n + 1; // buffer too small
102
         sz = n + 1; // buffer too small
103
         delete [] text;
103
         delete [] text;
104
         text = new char[sz + 1];
104
         text = new char[sz + 1];
105
-        va_copy(tmp, args);
106
-        vsnprintf(text, sz, string, tmp);
107
-        va_end(tmp);
105
+        vsnprintf(text, sz, string, args);
108
     }
106
     }
109
 
107
 
110
-    return text;
111
-}
112
-
113
-char *bufferString(const char *string, ...) {
114
-    va_list args;
115
-    va_start(args, string);
116
-    char *text = bufferString(string, args);
117
     va_end(args);
108
     va_end(args);
118
     return text;
109
     return text;
119
 }
110
 }

Carregando…
Cancelar
Salvar