Parcourir la source

Use Console as Stream everywhere

Thomas Buck il y a 10 ans
Parent
révision
60df802f2a
14 fichiers modifiés avec 179 ajouts et 207 suppressions
  1. 1
    0
      ChangeLog.md
  2. 11
    4
      include/Console.h
  3. 2
    2
      include/OpenRaider.h
  4. 90
    95
      src/Command.cpp
  5. 3
    31
      src/Console.cpp
  6. 7
    5
      src/Entity.cpp
  7. 9
    9
      src/Game.cpp
  8. 2
    2
      src/Menu.cpp
  9. 5
    7
      src/Room.cpp
  10. 6
    5
      src/SkeletalModel.cpp
  11. 2
    2
      src/TextureManager.cpp
  12. 2
    4
      src/main.cpp
  13. 20
    20
      src/utils/pcx.cpp
  14. 19
    21
      src/utils/png.cpp

+ 1
- 0
ChangeLog.md Voir le fichier

13
     * Console is now using std::string instead of char *
13
     * Console is now using std::string instead of char *
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
 
17
 
17
     [ 20140809 ]
18
     [ 20140809 ]
18
     * Script Unit Test brings it’s own scripts to test
19
     * Script Unit Test brings it’s own scripts to test

+ 11
- 4
include/Console.h Voir le fichier

28
     bool isVisible();
28
     bool isVisible();
29
 
29
 
30
     template<typename T>
30
     template<typename T>
31
-    Console &operator<<(T t);
32
-
33
-    // Deprecated!
34
-    void print(const char *s, ...) __attribute__((format(printf, 2, 3)));
31
+    Console &operator<<(const T t) {
32
+        printBuffer << t;
33
+        if (printBuffer.str().back() == '\n') {
34
+            mHistory.push_back(printBuffer.str().substr(0, printBuffer.str().length() - 1));
35
+#ifdef DEBUG
36
+            std::cout << printBuffer.str().substr(0, printBuffer.str().length() - 1) << std::endl;
37
+#endif
38
+            printBuffer.str("");
39
+        }
40
+        return (*this);
41
+    }
35
 
42
 
36
     void display();
43
     void display();
37
 
44
 

+ 2
- 2
include/OpenRaider.h Voir le fichier

35
      */
35
      */
36
     int loadConfig(const char *config);
36
     int loadConfig(const char *config);
37
 
37
 
38
-    int command(std::string &command);
39
-    int command(const char *command);
38
+    int command(std::string command);
40
 
39
 
41
     void run();
40
     void run();
42
     void frame();
41
     void frame();
70
 OpenRaider &getOpenRaider();
69
 OpenRaider &getOpenRaider();
71
 
70
 
72
 #endif
71
 #endif
72
+

+ 90
- 95
src/Command.cpp Voir le fichier

30
     assert(config[0] != '\0');
30
     assert(config[0] != '\0');
31
 
31
 
32
     char *configFile = fullPath(config, 0);
32
     char *configFile = fullPath(config, 0);
33
-    getConsole().print("Loading config from \"%s\"...", configFile);
33
+    getConsole() << "Loading config from \"" << configFile << "\"..." << Console::endl;
34
 
34
 
35
     std::ifstream file(configFile);
35
     std::ifstream file(configFile);
36
     if (!file) {
36
     if (!file) {
37
-        getConsole().print("Could not open file!");
37
+        getConsole() << "Could not open file!" << Console::endl;
38
         return -1;
38
         return -1;
39
     }
39
     }
40
 
40
 
44
 
44
 
45
         int error = command(line);
45
         int error = command(line);
46
         if (error != 0)
46
         if (error != 0)
47
-            getConsole().print("Error Code: %d", error);
47
+            getConsole() << "Error Code: " << error << Console::endl;
48
     }
48
     }
49
 
49
 
50
     file.close();
50
     file.close();
52
     return 0;
52
     return 0;
53
 }
53
 }
54
 
54
 
55
-int OpenRaider::command(const char *command) {
56
-    std::string tmp(command);
57
-    return this->command(tmp);
58
-}
59
-
60
-int OpenRaider::command(std::string &c) {
55
+int OpenRaider::command(std::string c) {
61
     // Remove comment, if any
56
     // Remove comment, if any
62
     size_t comment = c.find_first_of('#');
57
     size_t comment = c.find_first_of('#');
63
     if (comment != std::string::npos)
58
     if (comment != std::string::npos)
77
     } else if (cmd.compare("bind") == 0) {
72
     } else if (cmd.compare("bind") == 0) {
78
         std::string a, b;
73
         std::string a, b;
79
         if (!(command >> a >> b)) {
74
         if (!(command >> a >> b)) {
80
-            getConsole().print("Invalid use of bind-command");
75
+            getConsole() << "Invalid use of bind-command" << Console::endl;
81
             return -1;
76
             return -1;
82
         } else {
77
         } else {
83
             return bind(a.c_str(), b.c_str());
78
             return bind(a.c_str(), b.c_str());
86
         exit(0);
81
         exit(0);
87
     } else if (cmd.compare("load") == 0) {
82
     } else if (cmd.compare("load") == 0) {
88
         if (!mRunning) {
83
         if (!mRunning) {
89
-            getConsole().print("Use load command interactively!");
84
+            getConsole() << "Use load command interactively!" << Console::endl;
90
             return -999;
85
             return -999;
91
         }
86
         }
92
         std::string temp;
87
         std::string temp;
96
     } else if (cmd.compare("help") == 0) {
91
     } else if (cmd.compare("help") == 0) {
97
         std::string tmp;
92
         std::string tmp;
98
         if (!(command >> tmp)) {
93
         if (!(command >> tmp)) {
99
-            getConsole().print("Available commands:");
100
-            getConsole().print("  load      - load a level");
101
-            getConsole().print("  set       - set a parameter");
102
-            getConsole().print("  bind      - bind a keyboard/mouse action");
103
-            getConsole().print("  animate   - [BOOL|n|p] - Animate models");
104
-            getConsole().print("  move      - [walk|fly|noclip]");
94
+            getConsole() << "Available commands:" << Console::endl;
95
+            getConsole() << "  load      - load a level" << Console::endl;
96
+            getConsole() << "  set       - set a parameter" << Console::endl;
97
+            getConsole() << "  bind      - bind a keyboard/mouse action" << Console::endl;
98
+            getConsole() << "  animate   - [BOOL|n|p] - Animate models" << Console::endl;
99
+            getConsole() << "  move      - [walk|fly|noclip]" << Console::endl;
105
 /*
100
 /*
106
-            getConsole().print("  sshot     - make a screenshot");
107
-            getConsole().print("  sound     - INT - Test play sound");
108
-            getConsole().print("  mode      - MODE - Render mode");
109
-            getConsole().print("  light     - BOOL - GL Lights");
110
-            getConsole().print("  fog       - BOOL - GL Fog");
111
-            getConsole().print("  viewmodel - INT - Change Laras model");
112
-            getConsole().print("  pos       - Print position info");
113
-            getConsole().print("  ralpha    - BOOL - Room Alpha");
114
-            getConsole().print("  upf       - BOOL - Update Room List Per Frame");
115
-            getConsole().print("  entmodel  - BOOL");
116
-            getConsole().print("  ponytail  - BOOL");
117
-            getConsole().print("  pigtail   - BOOL");
118
-            getConsole().print("  ponypos   - FLOAT FLOAT FLOAT FLOAT - x y z angle");
101
+            getConsole() << "  sshot     - make a screenshot" << Console::endl;
102
+            getConsole() << "  sound     - INT - Test play sound" << Console::endl;
103
+            getConsole() << "  mode      - MODE - Render mode" << Console::endl;
104
+            getConsole() << "  light     - BOOL - GL Lights" << Console::endl;
105
+            getConsole() << "  fog       - BOOL - GL Fog" << Console::endl;
106
+            getConsole() << "  viewmodel - INT - Change Laras model" << Console::endl;
107
+            getConsole() << "  pos       - Print position info" << Console::endl;
108
+            getConsole() << "  ralpha    - BOOL - Room Alpha" << Console::endl;
109
+            getConsole() << "  upf       - BOOL - Update Room List Per Frame" << Console::endl;
110
+            getConsole() << "  entmodel  - BOOL" << Console::endl;
111
+            getConsole() << "  ponytail  - BOOL" << Console::endl;
112
+            getConsole() << "  pigtail   - BOOL" << Console::endl;
113
+            getConsole() << "  ponypos   - FLOAT FLOAT FLOAT FLOAT - x y z angle" << Console::endl;
119
 */
114
 */
120
-            getConsole().print("  help      - print command help");
121
-            getConsole().print("  quit      - exit OpenRaider");
122
-            getConsole().print("Use help COMMAND to get additional info");
123
-            getConsole().print("Pass BOOLs as true or false");
115
+            getConsole() << "  help      - print command help" << Console::endl;
116
+            getConsole() << "  quit      - exit OpenRaider" << Console::endl;
117
+            getConsole() << "Use help COMMAND to get additional info" << Console::endl;
118
+            getConsole() << "Pass BOOLs as true or false" << Console::endl;
124
         } else {
119
         } else {
125
             return help(tmp);
120
             return help(tmp);
126
         }
121
         }
127
     } else if (cmd.compare("animate") == 0) {
122
     } else if (cmd.compare("animate") == 0) {
128
         if ((!mRunning) || (!getGame().isLoaded())) {
123
         if ((!mRunning) || (!getGame().isLoaded())) {
129
-            getConsole().print("Use animate command interactively!");
124
+            getConsole() << "Use animate command interactively!" << Console::endl;
130
             return -999;
125
             return -999;
131
         }
126
         }
132
         if (command.peek() == 'n') {
127
         if (command.peek() == 'n') {
141
                         e.setAnimation(0);
136
                         e.setAnimation(0);
142
                 }
137
                 }
143
             } else {
138
             } else {
144
-                getConsole().print("Animations need to be enabled!");
139
+                getConsole() << "Animations need to be enabled!" << Console::endl;
145
             }
140
             }
146
         } else if (command.peek() == 'p') {
141
         } else if (command.peek() == 'p') {
147
             // Step all skeletal models to their previous animation
142
             // Step all skeletal models to their previous animation
156
                             e.setAnimation(m.size() - 1);
151
                             e.setAnimation(m.size() - 1);
157
                 }
152
                 }
158
             } else {
153
             } else {
159
-                getConsole().print("Animations need to be enabled!");
154
+                getConsole() << "Animations need to be enabled!" << Console::endl;
160
             }
155
             }
161
         } else {
156
         } else {
162
             // Enable or disable animating all skeletal models
157
             // Enable or disable animating all skeletal models
163
             bool b = false;
158
             bool b = false;
164
             if (!(command >> b)) {
159
             if (!(command >> b)) {
165
-                getConsole().print("Pass BOOL to animate command!");
160
+                getConsole() << "Pass BOOL to animate command!" << Console::endl;
166
                 return -2;
161
                 return -2;
167
             }
162
             }
168
             if (b)
163
             if (b)
169
                 getRender().setFlags(Render::fAnimateAllModels);
164
                 getRender().setFlags(Render::fAnimateAllModels);
170
             else
165
             else
171
                 getRender().clearFlags(Render::fAnimateAllModels);
166
                 getRender().clearFlags(Render::fAnimateAllModels);
172
-            getConsole().print(b ? "Animating all models" : "No longer animating all models");
167
+            getConsole() << (b ? "Animating all models" : "No longer animating all models") << Console::endl;
173
         }
168
         }
174
     } else if (cmd.compare("move") == 0) {
169
     } else if (cmd.compare("move") == 0) {
175
         if ((!mRunning) || (!getGame().isLoaded())) {
170
         if ((!mRunning) || (!getGame().isLoaded())) {
176
-            getConsole().print("Use move command interactively!");
171
+            getConsole() << "Use move command interactively!" << Console::endl;
177
             return -999;
172
             return -999;
178
         }
173
         }
179
         std::string temp;
174
         std::string temp;
185
         } else if (temp.compare("noclip") == 0) {
180
         } else if (temp.compare("noclip") == 0) {
186
             getGame().getLara().setMoveType(Entity::MoveTypeNoClipping);
181
             getGame().getLara().setMoveType(Entity::MoveTypeNoClipping);
187
         } else {
182
         } else {
188
-            getConsole().print("Invalid use of move command (%s)!", temp.c_str());
183
+            getConsole() << "Invalid use of move command (" << temp.c_str() << ")!" << Console::endl;
189
             return -9;
184
             return -9;
190
         }
185
         }
191
-        getConsole().print("%sing", temp.c_str());
186
+        getConsole() << temp.c_str()  << "ing" << Console::endl;
192
 
187
 
193
 /*
188
 /*
194
     } else if (cmd.compare("mode") == 0) {
189
     } else if (cmd.compare("mode") == 0) {
398
         }
393
         }
399
 */
394
 */
400
     } else {
395
     } else {
401
-        getConsole().print("Unknown command: %s", cmd.c_str());
396
+        getConsole() << "Unknown command: " << cmd.c_str() << Console::endl;
402
         return -50;
397
         return -50;
403
     }
398
     }
404
 
399
 
407
 
402
 
408
 int OpenRaider::help(std::string &cmd) {
403
 int OpenRaider::help(std::string &cmd) {
409
     if (cmd.compare("set") == 0) {
404
     if (cmd.compare("set") == 0) {
410
-        getConsole().print("set-Command Usage:");
411
-        getConsole().print("  set VAR VAL");
412
-        getConsole().print("Available Variables:");
413
-        getConsole().print("  basedir    STRING");
414
-        getConsole().print("  pakdir     STRING");
415
-        getConsole().print("  audiodir   STRING");
416
-        getConsole().print("  datadir    STRING");
417
-        getConsole().print("  font       STRING");
418
-        getConsole().print("  size       INT INT");
419
-        getConsole().print("  fullscreen BOOL");
420
-        getConsole().print("  audio      BOOL");
421
-        getConsole().print("  volume     BOOL");
422
-        getConsole().print("  mouse_x    FLOAT");
423
-        getConsole().print("  mouse_y    FLOAT");
424
-        getConsole().print("  fps        BOOL");
425
-        getConsole().print("Enclose STRINGs with \"\"!");
405
+        getConsole() << "set-Command Usage:" << Console::endl;
406
+        getConsole() << "  set VAR VAL" << Console::endl;
407
+        getConsole() << "Available Variables:" << Console::endl;
408
+        getConsole() << "  basedir    STRING" << Console::endl;
409
+        getConsole() << "  pakdir     STRING" << Console::endl;
410
+        getConsole() << "  audiodir   STRING" << Console::endl;
411
+        getConsole() << "  datadir    STRING" << Console::endl;
412
+        getConsole() << "  font       STRING" << Console::endl;
413
+        getConsole() << "  size       INT INT" << Console::endl;
414
+        getConsole() << "  fullscreen BOOL" << Console::endl;
415
+        getConsole() << "  audio      BOOL" << Console::endl;
416
+        getConsole() << "  volume     BOOL" << Console::endl;
417
+        getConsole() << "  mouse_x    FLOAT" << Console::endl;
418
+        getConsole() << "  mouse_y    FLOAT" << Console::endl;
419
+        getConsole() << "  fps        BOOL" << Console::endl;
420
+        getConsole() << "Enclose STRINGs with \"\"!" << Console::endl;
426
     } else if (cmd.compare("bind") == 0) {
421
     } else if (cmd.compare("bind") == 0) {
427
-        getConsole().print("bind-Command Usage:");
428
-        getConsole().print("  bind ACTION KEY");
429
-        getConsole().print("Available Actions:");
430
-        getConsole().print("  menu");
431
-        getConsole().print("  console");
432
-        getConsole().print("  forward");
433
-        getConsole().print("  backward");
434
-        getConsole().print("  left");
435
-        getConsole().print("  right");
436
-        getConsole().print("  jump");
437
-        getConsole().print("  crouch");
438
-        getConsole().print("  use");
439
-        getConsole().print("  holster");
440
-        getConsole().print("  walk");
441
-        getConsole().print("Key-Format:");
442
-        getConsole().print("  'a' or '1'    for character/number keys");
443
-        getConsole().print("  \"leftctrl\"  for symbols and special keys");
422
+        getConsole() << "bind-Command Usage:" << Console::endl;
423
+        getConsole() << "  bind ACTION KEY" << Console::endl;
424
+        getConsole() << "Available Actions:" << Console::endl;
425
+        getConsole() << "  menu" << Console::endl;
426
+        getConsole() << "  console" << Console::endl;
427
+        getConsole() << "  forward" << Console::endl;
428
+        getConsole() << "  backward" << Console::endl;
429
+        getConsole() << "  left" << Console::endl;
430
+        getConsole() << "  right" << Console::endl;
431
+        getConsole() << "  jump" << Console::endl;
432
+        getConsole() << "  crouch" << Console::endl;
433
+        getConsole() << "  use" << Console::endl;
434
+        getConsole() << "  holster" << Console::endl;
435
+        getConsole() << "  walk" << Console::endl;
436
+        getConsole() << "Key-Format:" << Console::endl;
437
+        getConsole() << "  'a' or '1'    for character/number keys" << Console::endl;
438
+        getConsole() << "  \"leftctrl\"  for symbols and special keys" << Console::endl;
444
     } else if (cmd.compare("load") == 0) {
439
     } else if (cmd.compare("load") == 0) {
445
-        getConsole().print("load-Command Usage:");
446
-        getConsole().print("  load /path/to/level");
440
+        getConsole() << "load-Command Usage:" << Console::endl;
441
+        getConsole() << "  load /path/to/level" << Console::endl;
447
 /*
442
 /*
448
     } else if (cmd.compare("sshot") == 0) {
443
     } else if (cmd.compare("sshot") == 0) {
449
         getConsole().print("sshot-Command Usage:");
444
         getConsole().print("sshot-Command Usage:");
471
         getConsole().print("  titlescreen");
466
         getConsole().print("  titlescreen");
472
 */
467
 */
473
     } else if (cmd.compare("animate") == 0) {
468
     } else if (cmd.compare("animate") == 0) {
474
-        getConsole().print("animate-Command Usage:");
475
-        getConsole().print("  animate [n|p|BOOL]");
476
-        getConsole().print("Where the commands have the following meaning:");
477
-        getConsole().print("  BOOL to (de)activate animating all models");
478
-        getConsole().print("  n to step all models to their next animation");
479
-        getConsole().print("  p to step all models to their previous animation");
469
+        getConsole() << "animate-Command Usage:" << Console::endl;
470
+        getConsole() << "  animate [n|p|BOOL]" << Console::endl;
471
+        getConsole() << "Where the commands have the following meaning:" << Console::endl;
472
+        getConsole() << "  BOOL to (de)activate animating all models" << Console::endl;
473
+        getConsole() << "  n to step all models to their next animation" << Console::endl;
474
+        getConsole() << "  p to step all models to their previous animation" << Console::endl;
480
     } else {
475
     } else {
481
-        getConsole().print("No help available for %s", cmd.c_str());
476
+        getConsole() << "No help available for " << cmd.c_str() << Console::endl;
482
         return -1;
477
         return -1;
483
     }
478
     }
484
 
479
 
536
     if (var.compare("size") == 0) {
531
     if (var.compare("size") == 0) {
537
         unsigned int w = DEFAULT_WIDTH, h = DEFAULT_HEIGHT;
532
         unsigned int w = DEFAULT_WIDTH, h = DEFAULT_HEIGHT;
538
         if (!(command >> w >> h)) {
533
         if (!(command >> w >> h)) {
539
-            getConsole().print("set-size-Error: Invalid value(s)");
534
+            getConsole() << "set-size-Error: Invalid value(s)" << Console::endl;
540
             return -2;
535
             return -2;
541
         }
536
         }
542
         getWindow().setSize(w, h);
537
         getWindow().setSize(w, h);
543
     } else if (var.compare("fullscreen") == 0) {
538
     } else if (var.compare("fullscreen") == 0) {
544
         bool fullscreen = false;
539
         bool fullscreen = false;
545
         if (!(command >> fullscreen)) {
540
         if (!(command >> fullscreen)) {
546
-            getConsole().print("set-fullscreen-Error: Invalid value");
541
+            getConsole() << "set-fullscreen-Error: Invalid value" << Console::endl;
547
             return -3;
542
             return -3;
548
         }
543
         }
549
         getWindow().setFullscreen(fullscreen);
544
         getWindow().setFullscreen(fullscreen);
550
     } else if (var.compare("audio") == 0) {
545
     } else if (var.compare("audio") == 0) {
551
         bool audio = false;
546
         bool audio = false;
552
         if (!(command >> audio)) {
547
         if (!(command >> audio)) {
553
-            getConsole().print("set-audio-Error: Invalid value");
548
+            getConsole() << "set-audio-Error: Invalid value" << Console::endl;
554
             return -4;
549
             return -4;
555
         }
550
         }
556
         getSound().setEnabled(audio);
551
         getSound().setEnabled(audio);
557
     } else if (var.compare("volume") == 0) {
552
     } else if (var.compare("volume") == 0) {
558
         float vol = 1.0f;
553
         float vol = 1.0f;
559
         if (!(command >> vol)) {
554
         if (!(command >> vol)) {
560
-            getConsole().print("set-volume-Error: Invalid value");
555
+            getConsole() << "set-volume-Error: Invalid value" << Console::endl;
561
             return -5;
556
             return -5;
562
         }
557
         }
563
         getSound().setVolume(vol);
558
         getSound().setVolume(vol);
564
     } else if (var.compare("mouse_x") == 0) {
559
     } else if (var.compare("mouse_x") == 0) {
565
         float sense = 1.0f;
560
         float sense = 1.0f;
566
         if (!(command >> sense)) {
561
         if (!(command >> sense)) {
567
-            getConsole().print("set-mouse_x-Error: Invalid value");
562
+            getConsole() << "set-mouse_x-Error: Invalid value" << Console::endl;
568
             return -6;
563
             return -6;
569
         }
564
         }
570
         getCamera().setSensitivityX(OR_DEG_TO_RAD(sense));
565
         getCamera().setSensitivityX(OR_DEG_TO_RAD(sense));
571
     } else if (var.compare("mouse_y") == 0) {
566
     } else if (var.compare("mouse_y") == 0) {
572
         float sense = 1.0f;
567
         float sense = 1.0f;
573
         if (!(command >> sense)) {
568
         if (!(command >> sense)) {
574
-            getConsole().print("set-mouse_y-Error: Invalid value");
569
+            getConsole() << "set-mouse_y-Error: Invalid value" << Console::endl;
575
             return -7;
570
             return -7;
576
         }
571
         }
577
         getCamera().setSensitivityY(OR_DEG_TO_RAD(sense));
572
         getCamera().setSensitivityY(OR_DEG_TO_RAD(sense));
578
     } else if (var.compare("fps") == 0) {
573
     } else if (var.compare("fps") == 0) {
579
         bool fps = false;
574
         bool fps = false;
580
         if (!(command >> fps)) {
575
         if (!(command >> fps)) {
581
-            getConsole().print("set-fps-Error: Invalid value");
576
+            getConsole() << "set-fps-Error: Invalid value" << Console::endl;
582
             return -8;
577
             return -8;
583
         }
578
         }
584
         mFPS = fps;
579
         mFPS = fps;
600
         delete [] tmp;
595
         delete [] tmp;
601
         delete [] quotes;
596
         delete [] quotes;
602
     } else {
597
     } else {
603
-        getConsole().print("set-Error: Unknown variable (%s)", var.c_str());
598
+        getConsole() << "set-Error: Unknown variable (" << var.c_str() << ")" << Console::endl;
604
         return -1;
599
         return -1;
605
     }
600
     }
606
 
601
 
615
 
610
 
616
     ActionEvents e = stringToActionEvent(action);
611
     ActionEvents e = stringToActionEvent(action);
617
     if (e == ActionEventCount) {
612
     if (e == ActionEventCount) {
618
-        getConsole().print("bind-Error: Unknown action (%s --> %s)", key, action);
613
+        getConsole() << "bind-Error: Unknown action (" << key << " --> " << action << ")" << Console::endl;
619
         return -1;
614
         return -1;
620
     }
615
     }
621
 
616
 
622
     KeyboardButton c = stringToKeyboardButton(key);
617
     KeyboardButton c = stringToKeyboardButton(key);
623
     if (c == unknownKey) {
618
     if (c == unknownKey) {
624
-        getConsole().print("bind-Error: Unknown key (%s)", key);
619
+        getConsole() << "bind-Error: Unknown key (" << key << ")" << Console::endl;
625
         return -2;
620
         return -2;
626
     }
621
     }
627
 
622
 

+ 3
- 31
src/Console.cpp Voir le fichier

31
     return mVisible;
31
     return mVisible;
32
 }
32
 }
33
 
33
 
34
-template<typename T>
35
-Console &Console::operator<<(T t) {
36
-    printBuffer << t;
37
-
38
-    if (printBuffer.str().back() == '\n') {
39
-        mHistory.push_back(printBuffer.str().substr(0, printBuffer.str().length() - 1));
40
-#ifdef DEBUG
41
-        std::cout << printBuffer.str().substr(0, printBuffer.str().length() - 1) << std::endl;
42
-#endif
43
-        printBuffer.str("");
44
-    }
45
-
46
-    return (*this);
47
-}
48
-
49
-// Deprecated!
50
-void Console::print(const char *s, ...) {
51
-    va_list args;
52
-    va_start(args, s);
53
-    char *tmp = bufferString(s, args);
54
-    va_end(args);
55
-
56
-    if (tmp != nullptr)
57
-        (*this) << tmp << endl;
58
-
59
-    delete [] tmp;
60
-}
61
-
62
 #define LINE_GEOMETRY(window) \
34
 #define LINE_GEOMETRY(window) \
63
     unsigned int firstLine = 35; \
35
     unsigned int firstLine = 35; \
64
     unsigned int lastLine = (window.getHeight() / 2) - 55; \
36
     unsigned int lastLine = (window.getHeight() / 2) - 55; \
120
     if (pressed && (key == enterKey)) {
92
     if (pressed && (key == enterKey)) {
121
         // Execute entered command
93
         // Execute entered command
122
         if (mInputBuffer.length() > 0) {
94
         if (mInputBuffer.length() > 0) {
123
-            print("> %s", mInputBuffer.c_str());
95
+            (*this) << "> " << mInputBuffer.c_str() << endl;
124
             mCommandHistory.push_back(mInputBuffer.c_str());
96
             mCommandHistory.push_back(mInputBuffer.c_str());
125
             int error = getOpenRaider().command(mInputBuffer);
97
             int error = getOpenRaider().command(mInputBuffer);
126
             if (error != 0) {
98
             if (error != 0) {
127
-                print("Error Code: %d", error);
99
+                (*this) << "Error Code: " << error << endl;
128
             }
100
             }
129
         } else {
101
         } else {
130
-            print("> ");
102
+            (*this) << "> " << endl;
131
         }
103
         }
132
 
104
 
133
         // Clear partial and input buffer
105
         // Clear partial and input buffer

+ 7
- 5
src/Entity.cpp Voir le fichier

117
                 x, y, z);
117
                 x, y, z);
118
 
118
 
119
         if (roomNew > -1)
119
         if (roomNew > -1)
120
-            getConsole().print("Crossing from room %li to %li", room, roomNew);
120
+            getConsole() << "Crossing from room " << room << " to " << roomNew << Console::endl;
121
         else
121
         else
122
             //! \fixme mRooms, sectors, ... are now std::vector, but often upper bound checks are missing
122
             //! \fixme mRooms, sectors, ... are now std::vector, but often upper bound checks are missing
123
             return;
123
             return;
213
 }
213
 }
214
 
214
 
215
 void Entity::print() {
215
 void Entity::print() {
216
-    getConsole().print("Entity %d:", objectId);
217
-    getConsole().print("  Room %li (0x%X)", room, getWorld().getRoom(room).getFlags());
218
-    getConsole().print("  %.1fx %.1fy %.1fz", pos[0], pos[1], pos[2]);
219
-    getConsole().print("  %.1f Yaw", OR_RAD_TO_DEG(angles[1]));
216
+    getConsole() << "Entity " << objectId << ":" << Console::endl
217
+        << "  Room " << room << " (" << getWorld().getRoom(room).getFlags()
218
+        << ")" << Console::endl
219
+        << "  " << pos[0] << "x " << pos[1] << "y " << pos[2] << "z"
220
+        << Console::endl
221
+        << "  " << OR_RAD_TO_DEG(angles[1]) << " Yaw" << Console::endl;
220
 }
222
 }
221
 
223
 
222
 SkeletalModel &Entity::getModel() {
224
 SkeletalModel &Entity::getModel() {

+ 9
- 9
src/Game.cpp Voir le fichier

80
 
80
 
81
     mName = bufferString("%s", level);
81
     mName = bufferString("%s", level);
82
 
82
 
83
-    getConsole().print("Loading %s", mName);
83
+    getConsole() << "Loading " << mName << Console::endl;
84
     int error = mTombRaider.Load(mName);
84
     int error = mTombRaider.Load(mName);
85
     if (error != 0)
85
     if (error != 0)
86
         return error;
86
         return error;
100
         tmp[dir + 8] = '\0';
100
         tmp[dir + 8] = '\0';
101
         error = mTombRaider.loadSFX(tmp);
101
         error = mTombRaider.loadSFX(tmp);
102
         if (error != 0)
102
         if (error != 0)
103
-            getConsole().print("Could not load %s", tmp);
103
+            getConsole() << "Could not load " << tmp << Console::endl;
104
         delete [] tmp;
104
         delete [] tmp;
105
     }
105
     }
106
 
106
 
115
     mTombRaider.reset();
115
     mTombRaider.reset();
116
 
116
 
117
     if (mLara == -1) {
117
     if (mLara == -1) {
118
-        getConsole().print("Can't find Lara entity in level pak!");
118
+        getConsole() << "Can't find Lara entity in level pak!" << Console::endl;
119
         destroy();
119
         destroy();
120
         return -1;
120
         return -1;
121
     } else {
121
     } else {
190
         }
190
         }
191
     }
191
     }
192
 
192
 
193
-    getConsole().print("Found %d sprites.", mTombRaider.NumSpriteSequences());
193
+    getConsole() << "Found " << mTombRaider.NumSpriteSequences() << " sprites." << Console::endl;
194
 }
194
 }
195
 
195
 
196
 void Game::processRooms() {
196
 void Game::processRooms() {
197
     for (int index = 0; index < mTombRaider.NumRooms(); index++)
197
     for (int index = 0; index < mTombRaider.NumRooms(); index++)
198
         getWorld().addRoom(*new Room(mTombRaider, index));
198
         getWorld().addRoom(*new Room(mTombRaider, index));
199
 
199
 
200
-    getConsole().print("Found %d rooms.", mTombRaider.NumRooms());
200
+    getConsole() << "Found " << mTombRaider.NumRooms() << " rooms." << Console::endl;
201
 }
201
 }
202
 
202
 
203
 void Game::processModels() {
203
 void Game::processModels() {
204
     for (int index = 0; index < mTombRaider.getMeshCount(); index++)
204
     for (int index = 0; index < mTombRaider.getMeshCount(); index++)
205
         getWorld().addStaticMesh(*new StaticMesh(mTombRaider, index));
205
         getWorld().addStaticMesh(*new StaticMesh(mTombRaider, index));
206
 
206
 
207
-    getConsole().print("Found %d meshes.", mTombRaider.getMeshCount());
207
+    getConsole() << "Found " << mTombRaider.getMeshCount() << " meshes." << Console::endl;
208
 }
208
 }
209
 
209
 
210
 void Game::processPakSounds()
210
 void Game::processPakSounds()
246
         //getSound().SourceAt(id, pos);
246
         //getSound().SourceAt(id, pos);
247
     }
247
     }
248
 
248
 
249
-    getConsole().print("Found %u sound samples.", mTombRaider.getSoundSamplesCount());
249
+    getConsole() << "Found " << mTombRaider.getSoundSamplesCount() << " sound samples." << Console::endl;
250
 }
250
 }
251
 
251
 
252
 void Game::processTextures()
252
 void Game::processTextures()
290
 
290
 
291
     mTextureOffset = (mTextureStart - 1) + mTombRaider.NumTextures();
291
     mTextureOffset = (mTextureStart - 1) + mTombRaider.NumTextures();
292
 
292
 
293
-    getConsole().print("Found %d textures.", mTombRaider.NumTextures());
293
+    getConsole() << "Found " << mTombRaider.NumTextures() << " textures." << Console::endl;
294
 }
294
 }
295
 
295
 
296
 void Game::processMoveables()
296
 void Game::processMoveables()
375
     }
375
     }
376
     */
376
     */
377
 
377
 
378
-    getConsole().print("Found %d moveables.", mTombRaider.NumMoveables() + statCount);
378
+    getConsole() << "Found " << mTombRaider.NumMoveables() + statCount << " moveables." << Console::endl;
379
 }
379
 }
380
 
380
 
381
 // index moveable, i item, sometimes both moveable
381
 // index moveable, i item, sometimes both moveable

+ 2
- 2
src/Menu.cpp Voir le fichier

57
         // Check maps for validity
57
         // Check maps for validity
58
         int error = TombRaider::checkMime(f.getPath().c_str());
58
         int error = TombRaider::checkMime(f.getPath().c_str());
59
         if (error != 0) {
59
         if (error != 0) {
60
-            getConsole().print("Error: pak file '%s' %s",
61
-                    f.getName().c_str(), (error == -1) ? "not found" : "invalid");
60
+            getConsole() << "Error: pak file '" << f.getName().c_str()
61
+                << "' " << ((error == -1) ? "not found" : "invalid") << Console::endl;
62
             return true; // delete file from list
62
             return true; // delete file from list
63
         }
63
         }
64
 
64
 

+ 5
- 7
src/Room.cpp Voir le fichier

24
     Matrix transform;
24
     Matrix transform;
25
 
25
 
26
     if (!tr.isRoomValid(index)) {
26
     if (!tr.isRoomValid(index)) {
27
-        getConsole().print("WARNING: Handling invalid vertex array in room");
28
-        //printf("x");
29
-        //fflush(stdout);
27
+        getConsole() << "WARNING: Handling invalid vertex array in room" << Console::endl;
30
         return;
28
         return;
31
     }
29
     }
32
 
30
 
170
 
168
 
171
         if (texture > (int)TextureLimit)
169
         if (texture > (int)TextureLimit)
172
         {
170
         {
173
-            getConsole().print("Handling bad room[%i].tris[%i].texture = %i",
174
-                    index, t, texture);
171
+            getConsole() << "Handling bad room[" << index << "].tris["
172
+                << t << "].texture = " << texture << Console::endl;
175
             texture = TextureLimit - 1;
173
             texture = TextureLimit - 1;
176
         }
174
         }
177
 
175
 
204
 
202
 
205
         if (texture > (int)TextureLimit)
203
         if (texture > (int)TextureLimit)
206
         {
204
         {
207
-            getConsole().print("Handling bad room[%i].quad[%i].texture = %i",
208
-                    index, r, texture);
205
+            getConsole() << "Handling bad room[" << index << "].quad["
206
+                << r << "].texture = " << texture << Console::endl;
209
             texture = TextureLimit - 1;
207
             texture = TextureLimit - 1;
210
         }
208
         }
211
 
209
 

+ 6
- 5
src/SkeletalModel.cpp Voir le fichier

137
         }
137
         }
138
 
138
 
139
         if (*frame_offset > tr.NumFrames()) {
139
         if (*frame_offset > tr.NumFrames()) {
140
-            getConsole().print("WARNING: Bad animation frame %i > %i (%u.%d)",
141
-                    *frame_offset, tr.NumFrames(), index, a);
140
+            getConsole() << "WARNING: Bad animation frame " << *frame_offset
141
+                << " > " << tr.NumFrames() << " (" << index << "." << a << ")"
142
+                << Console::endl;
142
             return;
143
             return;
143
         }
144
         }
144
 
145
 
200
                 }
201
                 }
201
 
202
 
202
                 getRender().setFlags(Render::fRenderPonytail);
203
                 getRender().setFlags(Render::fRenderPonytail);
203
-                getConsole().print("Found known ponytail");
204
+                getConsole() << "Found known ponytail" << Console::endl;
204
             }
205
             }
205
             break;
206
             break;
206
 
207
 
222
                 ponyOff2 = 0;
223
                 ponyOff2 = 0;
223
 
224
 
224
                 getRender().setFlags(Render::fRenderPonytail);
225
                 getRender().setFlags(Render::fRenderPonytail);
225
-                getConsole().print("Found ponytail?");
226
+                getConsole() << "Found ponytail?" << Console::endl;
226
             }
227
             }
227
             break;
228
             break;
228
     }
229
     }
246
         frame_offset += frame_step * (frame_cycle % a);
247
         frame_offset += frame_step * (frame_cycle % a);
247
 
248
 
248
     if (a < 0) {
249
     if (a < 0) {
249
-        getConsole().print("Invalid animation data for model %d. Skip!", index);
250
+        getConsole() << "Invalid animation data for model " << index << ". Skip!" << Console::endl;
250
         return;
251
         return;
251
     } else {
252
     } else {
252
         for (; a < tr.getNumAnimsForMoveable(index); a++) {
253
         for (; a < tr.getNumAnimsForMoveable(index); a++) {

+ 2
- 2
src/TextureManager.cpp Voir le fichier

198
     } else if (stringEndsWith(filename, ".tga") || stringEndsWith(filename, ".TGA")) {
198
     } else if (stringEndsWith(filename, ".tga") || stringEndsWith(filename, ".TGA")) {
199
         return loadTGA(filename);
199
         return loadTGA(filename);
200
     } else {
200
     } else {
201
-        getConsole().print("No known image file type? (%s)", filename);
201
+        getConsole() << "No known image file type? (" << filename << ")" << Console::endl;
202
     }
202
     }
203
 
203
 
204
     return -1;
204
     return -1;
254
 
254
 
255
     return id;
255
     return id;
256
 #else
256
 #else
257
-    getConsole().print("No PNG support available (%s)", filename);
257
+    getConsole() << "No PNG support available (" << filename << ")" << Console::endl;
258
     return -1;
258
     return -1;
259
 #endif
259
 #endif
260
 }
260
 }

+ 2
- 4
src/main.cpp Voir le fichier

133
     }
133
     }
134
 
134
 
135
 #ifdef DEBUG
135
 #ifdef DEBUG
136
-    getConsole().print("Initializing %s", VERSION);
136
+    getConsole() << "Initializing " << VERSION << Console::endl;
137
 #endif
137
 #endif
138
 
138
 
139
     atexit(cleanupHandler);
139
     atexit(cleanupHandler);
146
 
146
 
147
     command_free(&cmd);
147
     command_free(&cmd);
148
 
148
 
149
-    getConsole().print("Starting %s", VERSION);
149
+    getConsole() << "Starting " << VERSION << Console::endl;
150
     getOpenRaider().run();
150
     getOpenRaider().run();
151
 
151
 
152
     return 0;
152
     return 0;
176
     } else if (strcmp(action, "walk") == 0) {
176
     } else if (strcmp(action, "walk") == 0) {
177
         return walkAction;
177
         return walkAction;
178
     } else {
178
     } else {
179
-        getConsole().print("Unknown action: \"%s\"", action);
180
         return ActionEventCount;
179
         return ActionEventCount;
181
     }
180
     }
182
 }
181
 }
361
         delete [] tmp;
360
         delete [] tmp;
362
     }
361
     }
363
 
362
 
364
-    getConsole().print("Unknown key: %s", key);
365
     return unknownKey;
363
     return unknownKey;
366
 }
364
 }
367
 
365
 

+ 20
- 20
src/utils/pcx.cpp Voir le fichier

9
  */
9
  */
10
 
10
 
11
 #include <fstream>
11
 #include <fstream>
12
+#include <iostream>
12
 
13
 
13
 #include "global.h"
14
 #include "global.h"
14
 #include "utils/pcx.h"
15
 #include "utils/pcx.h"
15
 
16
 
16
-#include "Console.h"
17
-#define pcxPrint getConsole().print
18
-
19
 int pcxCheck(const char *filename) {
17
 int pcxCheck(const char *filename) {
20
     assert(filename != NULL);
18
     assert(filename != NULL);
21
     assert(filename[0] != '\0');
19
     assert(filename[0] != '\0');
27
 
25
 
28
     // Basic validation
26
     // Basic validation
29
     if (!file.read((char *)(&header[0]), 128)) {
27
     if (!file.read((char *)(&header[0]), 128)) {
30
-        pcxPrint("File not big enough for valid PCX header!");
28
+        std::cout << "File not big enough for valid PCX header!" << std::endl;
31
         delete [] header;
29
         delete [] header;
32
         return -1;
30
         return -1;
33
     }
31
     }
34
 
32
 
35
     if (header[0] != 0x0A) {
33
     if (header[0] != 0x0A) {
36
-        pcxPrint("Magic number at file start is wrong (0x%X != 0x0A)", header[0]);
34
+        std::cout << "Magic number at file start is wrong (" << header[0] << " != 0x0A)" << std::endl;
37
         delete [] header;
35
         delete [] header;
38
         return -2;
36
         return -2;
39
     }
37
     }
40
 
38
 
41
     if ((header[1] != 0) && ((header[1] < 2) || (header[1] > 5))) {
39
     if ((header[1] != 0) && ((header[1] < 2) || (header[1] > 5))) {
42
         // Valid: 0, 2, 3, 4, 5
40
         // Valid: 0, 2, 3, 4, 5
43
-        pcxPrint("Unknown PCX file format version (%d)", header[1]);
41
+        std::cout << "Unknown PCX file format version (" << header[1] << ")" << std::endl;
44
         delete [] header;
42
         delete [] header;
45
         return -3;
43
         return -3;
46
     }
44
     }
47
 
45
 
48
     if ((header[2] != 0) && (header[2] != 1)) {
46
     if ((header[2] != 0) && (header[2] != 1)) {
49
-        pcxPrint("Unknown PCX file encoding (%d)", header[2]);
47
+        std::cout << "Unknown PCX file encoding (" << header[2] << ")" << std::endl;
50
         delete [] header;
48
         delete [] header;
51
         return -4;
49
         return -4;
52
     }
50
     }
53
 
51
 
54
     if (header[3] != 8) {
52
     if (header[3] != 8) {
55
-        pcxPrint("Only supporting 8bit (%dbit)", header[3]);
53
+        std::cout << "Only supporting 8bit (" << header[3] << "bit)" << std::endl;
56
         delete [] header;
54
         delete [] header;
57
         return -5;
55
         return -5;
58
     }
56
     }
59
 
57
 
60
     if (header[64] != 0) {
58
     if (header[64] != 0) {
61
-        pcxPrint("Reserved field is  used (%d != 0)", header[64]);
59
+        std::cout << "Reserved field is  used (" << header[64] << " != 0)" << std::endl;
62
         delete [] header;
60
         delete [] header;
63
         return -6;
61
         return -6;
64
     }
62
     }
84
 
82
 
85
     // Basic validation
83
     // Basic validation
86
     if (!file.read((char *)(&header[0]), 128)) {
84
     if (!file.read((char *)(&header[0]), 128)) {
87
-        pcxPrint("File not big enough for valid PCX header!");
85
+        std::cout << "File not big enough for valid PCX header!" << std::endl;
88
         delete [] header;
86
         delete [] header;
89
         return -1;
87
         return -1;
90
     }
88
     }
91
 
89
 
92
     if (header[0] != 0x0A) {
90
     if (header[0] != 0x0A) {
93
-        pcxPrint("Magic number at file start is wrong (0x%X != 0x0A)", header[0]);
91
+        std::cout << "Magic number at file start is wrong (" << header[0] << " != 0x0A)" << std::endl;
94
         delete [] header;
92
         delete [] header;
95
         return -2;
93
         return -2;
96
     }
94
     }
97
 
95
 
98
     if ((header[1] != 0) && ((header[1] < 2) || (header[1] > 5))) {
96
     if ((header[1] != 0) && ((header[1] < 2) || (header[1] > 5))) {
99
         // Valid: 0, 2, 3, 4, 5
97
         // Valid: 0, 2, 3, 4, 5
100
-        pcxPrint("Unknown PCX file format version (%d)", header[1]);
98
+        std::cout << "Unknown PCX file format version (" << header[1] << ")" << std::endl;
101
         delete [] header;
99
         delete [] header;
102
         return -3;
100
         return -3;
103
     }
101
     }
104
 
102
 
105
     if ((header[2] != 0) && (header[2] != 1)) {
103
     if ((header[2] != 0) && (header[2] != 1)) {
106
-        pcxPrint("Unknown PCX file encoding (%d)", header[2]);
104
+        std::cout << "Unknown PCX file encoding (" << header[2] << ")" << std::endl;
107
         delete [] header;
105
         delete [] header;
108
         return -4;
106
         return -4;
109
     }
107
     }
110
 
108
 
111
     if (header[3] != 8) {
109
     if (header[3] != 8) {
112
-        pcxPrint("Only supporting 8bit (%dbit)", header[3]);
110
+        std::cout << "Only supporting 8bit (" << header[3] << "bit)" << std::endl;
113
         delete [] header;
111
         delete [] header;
114
         return -5;
112
         return -5;
115
     }
113
     }
116
 
114
 
117
     if (header[64] != 0) {
115
     if (header[64] != 0) {
118
-        pcxPrint("Reserved field is  used (%d != 0)", header[64]);
116
+        std::cout << "Reserved field is  used (" << header[64] << " != 0)" << std::endl;
119
         delete [] header;
117
         delete [] header;
120
         return -6;
118
         return -6;
121
     }
119
     }
152
         unsigned int n = 1; // Run-length-encoding assumes 1
150
         unsigned int n = 1; // Run-length-encoding assumes 1
153
         int c = file.get();
151
         int c = file.get();
154
         if (!file) {
152
         if (!file) {
155
-            pcxPrint("Could not read data (%lu%s)", i, (file.eof() ? " EOF" : ""));
153
+            std::cout << "Could not read data (" << i
154
+                << (file.eof() ? " EOF" : "") << ")" << std::endl;
156
             delete [] buffer;
155
             delete [] buffer;
157
             return -7;
156
             return -7;
158
         }
157
         }
163
                 n = c & 0x3F;
162
                 n = c & 0x3F;
164
                 c = file.get();
163
                 c = file.get();
165
                 if (!file) {
164
                 if (!file) {
166
-                    pcxPrint("Could not read data rle (%lu%s)", i, (file.eof() ? " EOF" : ""));
165
+                    std::cout << "Could not read data rle (" << i
166
+                        << (file.eof() ? " EOF" : "") << ")" << std::endl;
167
                     delete [] buffer;
167
                     delete [] buffer;
168
                     return -8;
168
                     return -8;
169
                 }
169
                 }
185
             for (unsigned int i = 0; i < 768; i++) {
185
             for (unsigned int i = 0; i < 768; i++) {
186
                 palette[i] = (unsigned char)file.get();
186
                 palette[i] = (unsigned char)file.get();
187
                 if (!file) {
187
                 if (!file) {
188
-                    pcxPrint("Could not read 256 color palette (%d)", i);
188
+                    std::cout << "Could not read 256 color palette (" << i << ")" << std::endl;
189
                     delete [] buffer;
189
                     delete [] buffer;
190
                     delete [] palette;
190
                     delete [] palette;
191
                     return -9;
191
                     return -9;
208
                     green = palette[(buffer[(y * totalBytes) + x] * 3) + 1];
208
                     green = palette[(buffer[(y * totalBytes) + x] * 3) + 1];
209
                     blue = palette[(buffer[(y * totalBytes) + x] * 3) + 2];
209
                     blue = palette[(buffer[(y * totalBytes) + x] * 3) + 2];
210
                 } else {
210
                 } else {
211
-                    pcxPrint("Unsupported number of planes (%d)", nPlanes);
211
+                    std::cout << "Unsupported number of planes (" << nPlanes << ")" << std::endl;
212
                     delete [] buffer;
212
                     delete [] buffer;
213
                     delete [] palette;
213
                     delete [] palette;
214
                     delete [] *image;
214
                     delete [] *image;
225
                 } else if (nPlanes == 1) {
225
                 } else if (nPlanes == 1) {
226
                     red = green = blue = buffer[(y * totalBytes) + x];
226
                     red = green = blue = buffer[(y * totalBytes) + x];
227
                 } else {
227
                 } else {
228
-                    pcxPrint("Unsupported number of planes (%d)", nPlanes);
228
+                    std::cout << "Unsupported number of planes (" << nPlanes << ")" << std::endl;
229
                     delete [] buffer;
229
                     delete [] buffer;
230
                     delete [] palette;
230
                     delete [] palette;
231
                     delete [] *image;
231
                     delete [] *image;

+ 19
- 21
src/utils/png.cpp Voir le fichier

10
 
10
 
11
 #include <png.h>
11
 #include <png.h>
12
 #include <cstdio>
12
 #include <cstdio>
13
+#include <iostream>
13
 
14
 
14
 #include "global.h"
15
 #include "global.h"
15
 #include "utils/pixel.h"
16
 #include "utils/pixel.h"
16
 #include "utils/png.h"
17
 #include "utils/png.h"
17
 
18
 
18
-#include "Console.h"
19
-#define pngPrint getConsole().print
20
-
21
 int pngCheck(const char *filename) {
19
 int pngCheck(const char *filename) {
22
     png_byte header[8];
20
     png_byte header[8];
23
 
21
 
26
 
24
 
27
     FILE *fp = fopen(filename, "rb");
25
     FILE *fp = fopen(filename, "rb");
28
     if (fp == NULL) {
26
     if (fp == NULL) {
29
-        pngPrint("Could not open %s", filename);
27
+        std::cout << "Could not open " << filename << std::endl;
30
         return -1;
28
         return -1;
31
     }
29
     }
32
 
30
 
34
     fclose(fp);
32
     fclose(fp);
35
 
33
 
36
     if (png_sig_cmp(header, 0, 8)) {
34
     if (png_sig_cmp(header, 0, 8)) {
37
-        pngPrint("File %s is not a PNG.", filename);
35
+        std::cout << "File " << filename << " is not a PNG." << std::endl;
38
         return -2;
36
         return -2;
39
     }
37
     }
40
 
38
 
55
 
53
 
56
     FILE *fp = fopen(filename, "rb");
54
     FILE *fp = fopen(filename, "rb");
57
     if (fp == NULL) {
55
     if (fp == NULL) {
58
-        pngPrint("Could not open %s", filename);
56
+        std::cout << "Could not open " << filename << std::endl;
59
         return -1;
57
         return -1;
60
     }
58
     }
61
 
59
 
62
     fread(header, 1, 8, fp);
60
     fread(header, 1, 8, fp);
63
 
61
 
64
     if (png_sig_cmp(header, 0, 8)) {
62
     if (png_sig_cmp(header, 0, 8)) {
65
-        pngPrint("File %s is not a PNG.", filename);
63
+        std::cout << "File " << filename << " is not a PNG." << std::endl;
66
         fclose(fp);
64
         fclose(fp);
67
         return -2;
65
         return -2;
68
     }
66
     }
69
 
67
 
70
     png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
68
     png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
71
     if (!png_ptr) {
69
     if (!png_ptr) {
72
-        pngPrint("png_create_read_struct returned 0.");
70
+        std::cout << "png_create_read_struct returned 0." << std::endl;
73
         fclose(fp);
71
         fclose(fp);
74
         return -3;
72
         return -3;
75
     }
73
     }
76
 
74
 
77
     png_infop info_ptr = png_create_info_struct(png_ptr);
75
     png_infop info_ptr = png_create_info_struct(png_ptr);
78
     if (!info_ptr) {
76
     if (!info_ptr) {
79
-        pngPrint("png_create_info_struct returned 0.");
77
+        std::cout << "png_create_info_struct returned 0." << std::endl;
80
         png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
78
         png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
81
         fclose(fp);
79
         fclose(fp);
82
         return -4;
80
         return -4;
84
 
82
 
85
     png_infop end_info = png_create_info_struct(png_ptr);
83
     png_infop end_info = png_create_info_struct(png_ptr);
86
     if (!end_info) {
84
     if (!end_info) {
87
-        pngPrint("png_create_info_struct returned 0.");
85
+        std::cout << "png_create_info_struct returned 0." << std::endl;
88
         png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
86
         png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
89
         fclose(fp);
87
         fclose(fp);
90
         return -5;
88
         return -5;
91
     }
89
     }
92
 
90
 
93
     if (setjmp(png_jmpbuf(png_ptr))) {
91
     if (setjmp(png_jmpbuf(png_ptr))) {
94
-        pngPrint("Error from libpng");
92
+        std::cout << "Error from libpng" << std::endl;
95
         png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
93
         png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
96
         fclose(fp);
94
         fclose(fp);
97
         return -6;
95
         return -6;
111
     *height = tmpHeight;
109
     *height = tmpHeight;
112
 
110
 
113
     if (bit_depth != 8) {
111
     if (bit_depth != 8) {
114
-        pngPrint("%s: Unsupported bit depth %d.  Must be 8.", filename, bit_depth);
112
+        std::cout << filename << ": Unsupported bit depth " << bit_depth << ".  Must be 8." << std::endl;
115
         return -7;
113
         return -7;
116
     }
114
     }
117
 
115
 
141
         *mode = RGBA;
139
         *mode = RGBA;
142
         *bpp = 32;
140
         *bpp = 32;
143
     } else {
141
     } else {
144
-        pngPrint("%s: Unknown libpng color type %d.", filename, color_type);
142
+        std::cout << filename << ": Unknown libpng color type " << color_type << std::endl;
145
         delete [] image_data;
143
         delete [] image_data;
146
         return -8;
144
         return -8;
147
     }
145
     }
175
 
173
 
176
     FILE *fp = fopen(filename, "wb");
174
     FILE *fp = fopen(filename, "wb");
177
     if (!fp) {
175
     if (!fp) {
178
-        pngPrint("File %s could not be opened for writing", filename);
176
+        std::cout << "File " << filename << " could not be opened for writing" << std::endl;
179
         return -1;
177
         return -1;
180
     }
178
     }
181
 
179
 
182
     png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
180
     png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
183
 
181
 
184
     if (!png_ptr) {
182
     if (!png_ptr) {
185
-        pngPrint("png_create_write_struct failed");
183
+        std::cout << "png_create_write_struct failed" << std::endl;
186
         fclose(fp);
184
         fclose(fp);
187
         return -2;
185
         return -2;
188
     }
186
     }
189
 
187
 
190
     png_infop info_ptr = png_create_info_struct(png_ptr);
188
     png_infop info_ptr = png_create_info_struct(png_ptr);
191
     if (!info_ptr) {
189
     if (!info_ptr) {
192
-        pngPrint("png_create_info_struct failed");
190
+        std::cout << "png_create_info_struct failed" << std::endl;
193
         fclose(fp);
191
         fclose(fp);
194
         return -3;
192
         return -3;
195
     }
193
     }
196
 
194
 
197
     if (setjmp(png_jmpbuf(png_ptr))) {
195
     if (setjmp(png_jmpbuf(png_ptr))) {
198
-        pngPrint("Error during init_io");
196
+        std::cout << "Error during init_io" << std::endl;
199
         fclose(fp);
197
         fclose(fp);
200
         return -4;
198
         return -4;
201
     }
199
     }
203
     png_init_io(png_ptr, fp);
201
     png_init_io(png_ptr, fp);
204
 
202
 
205
     if (setjmp(png_jmpbuf(png_ptr))) {
203
     if (setjmp(png_jmpbuf(png_ptr))) {
206
-        pngPrint("Error during writing header");
204
+        std::cout << "Error during writing header" << std::endl;
207
         fclose(fp);
205
         fclose(fp);
208
         return -5;
206
         return -5;
209
     }
207
     }
222
         }
220
         }
223
         color_type = PNG_COLOR_TYPE_RGB_ALPHA;
221
         color_type = PNG_COLOR_TYPE_RGB_ALPHA;
224
     } else {
222
     } else {
225
-        pngPrint("Error invalid color mode");
223
+        std::cout << "Error invalid color mode" << std::endl;
226
         fclose(fp);
224
         fclose(fp);
227
         return -6;
225
         return -6;
228
     }
226
     }
239
         row_pointers[height - 1 - i] = image + (i * width * 4);
237
         row_pointers[height - 1 - i] = image + (i * width * 4);
240
 
238
 
241
     if (setjmp(png_jmpbuf(png_ptr))) {
239
     if (setjmp(png_jmpbuf(png_ptr))) {
242
-        pngPrint("Error during writing bytes");
240
+        std::cout << "Error during writing bytes" << std::endl;
243
         delete [] row_pointers;
241
         delete [] row_pointers;
244
         fclose(fp);
242
         fclose(fp);
245
         return -7;
243
         return -7;
248
     png_write_image(png_ptr, row_pointers);
246
     png_write_image(png_ptr, row_pointers);
249
 
247
 
250
     if (setjmp(png_jmpbuf(png_ptr))) {
248
     if (setjmp(png_jmpbuf(png_ptr))) {
251
-        pngPrint("Error during end of write");
249
+        std::cout << "Error during end of write" << std::endl;
252
         delete [] row_pointers;
250
         delete [] row_pointers;
253
         fclose(fp);
251
         fclose(fp);
254
         return -8;
252
         return -8;

Chargement…
Annuler
Enregistrer