浏览代码

LoaderTR2 supports Animated Textuers

Thomas Buck 10 年前
父节点
当前提交
1c6648ddbf
共有 5 个文件被更改,包括 245 次插入13 次删除
  1. 4
    0
      ChangeLog.md
  2. 6
    0
      include/TextureManager.h
  3. 31
    0
      src/TextureManager.cpp
  4. 160
    7
      src/UI.cpp
  5. 44
    6
      src/loader/LoaderTR2.cpp

+ 4
- 0
ChangeLog.md 查看文件

@@ -2,8 +2,12 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20141129 ]
6
+    * LoaderTR2 now supports loading animated textiles
7
+
5 8
     [ 20141128 ]
6 9
     * Added FPS Histogram Debug UI
10
+    * Added RunTime Settings Debug UI
7 11
 
8 12
     [ 20141127 ]
9 13
     * Started work on loading the object texture mapping, with debug UI

+ 6
- 0
include/TextureManager.h 查看文件

@@ -90,6 +90,11 @@ class TextureManager {
90 90
     int numTiles();
91 91
     TextureTile& getTile(int index);
92 92
 
93
+    void addAnimatedTile(int index, int tile);
94
+    int numAnimatedTiles();
95
+    int getFirstTileAnimation(int index);
96
+    int getNextTileAnimation(int tile);
97
+
93 98
   private:
94 99
     std::vector<unsigned int>& getIds(TextureStorage s);
95 100
 
@@ -101,6 +106,7 @@ class TextureManager {
101 106
     std::vector<unsigned int> mTextureIdsSystem;
102 107
 
103 108
     std::vector<TextureTile*> tiles;
109
+    std::vector<std::vector<int>> animations;
104 110
 };
105 111
 
106 112
 TextureManager& getTextureManager();

+ 31
- 0
src/TextureManager.cpp 查看文件

@@ -164,6 +164,37 @@ TextureTile& TextureManager::getTile(int index) {
164 164
     return *tiles.at(index);
165 165
 }
166 166
 
167
+void TextureManager::addAnimatedTile(int index, int tile) {
168
+    while (index >= animations.size())
169
+        animations.push_back(std::vector<int>());
170
+
171
+    animations.at(index).push_back(tile);
172
+}
173
+
174
+int TextureManager::numAnimatedTiles() {
175
+    return animations.size();
176
+}
177
+
178
+int TextureManager::getFirstTileAnimation(int index) {
179
+    assert(index < animations.size());
180
+    assert(animations.at(index).size() > 0);
181
+    return animations.at(index).at(0);
182
+}
183
+
184
+int TextureManager::getNextTileAnimation(int tile) {
185
+    for (int a = 0; a < animations.size(); a++) {
186
+        for (int i = 0; i < animations.at(a).size(); i++) {
187
+            if (animations.at(a).at(i) == tile) {
188
+                if (i < (animations.at(a).size() - 1))
189
+                    return animations.at(a).at(i + 1);
190
+                else
191
+                    return animations.at(a).at(0);
192
+            }
193
+        }
194
+    }
195
+    return -1;
196
+}
197
+
167 198
 std::vector<unsigned int>& TextureManager::getIds(TextureStorage s) {
168 199
     if (s == TextureStorage::GAME)
169 200
         return mTextureIdsGame;

+ 160
- 7
src/UI.cpp 查看文件

@@ -6,6 +6,7 @@
6 6
  */
7 7
 
8 8
 #include <algorithm>
9
+#include <cstring>
9 10
 
10 11
 #include "global.h"
11 12
 #include "Console.h"
@@ -186,15 +187,15 @@ void UI::display() {
186 187
     Console::display();
187 188
 
188 189
     if (ImGui::Begin("Engine")) {
189
-        if (ImGui::CollapsingHeader("RunTime Info")) {
190
+        if (ImGui::CollapsingHeader("Engine Info")) {
190 191
             ImGui::Text("Uptime: %lums", systemTimerGet());
191 192
             ImGui::Text("Frames per Second: %luFPS", getRunTime().getFPS());
192 193
             if (getRunTime().getHistoryFPS().size() > 1) {
193 194
                 static bool scroll = true;
194 195
                 if (scroll) {
195 196
                     int offset = getRunTime().getHistoryFPS().size() - 1;
196
-                    if (offset > 15)
197
-                        offset = 15;
197
+                    if (offset > 10)
198
+                        offset = 10;
198 199
                     ImGui::PlotLines("FPS", &getRunTime().getHistoryFPS()[1],
199 200
                             getRunTime().getHistoryFPS().size() - 1,
200 201
                             getRunTime().getHistoryFPS().size() - offset - 1);
@@ -207,8 +208,105 @@ void UI::display() {
207 208
             }
208 209
         }
209 210
 
211
+        if (ImGui::CollapsingHeader("RunTime Settings")) {
212
+            bool showFPS = getRunTime().getShowFPS();
213
+            if (ImGui::Checkbox("Show FPS##runtime", &showFPS)) {
214
+                getRunTime().setShowFPS(showFPS);
215
+            }
216
+            ImGui::SameLine();
217
+            bool running = getRunTime().isRunning();
218
+            if (ImGui::Checkbox("Running (!)##runtime", &running)) {
219
+                getRunTime().setRunning(running);
220
+            }
221
+            ImGui::SameLine();
222
+            bool sound = getSound().getEnabled();
223
+            if (ImGui::Checkbox("Sound##runtime", &sound)) {
224
+                getSound().setEnabled(sound);
225
+            }
226
+            ImGui::SameLine();
227
+            bool fullscreen = getWindow().getFullscreen();
228
+            if (ImGui::Checkbox("Fullscreen##runtime", &fullscreen)) {
229
+                getWindow().setFullscreen(fullscreen);
230
+            }
231
+
232
+            float vol = getSound().getVolume();
233
+            if (ImGui::InputFloat("Volume##runtime", &vol, 0.0f, 0.0f, 3, ImGuiInputTextFlags_EnterReturnsTrue)) {
234
+                if (vol < 0.0f)
235
+                    vol = 0.0f;
236
+                if (vol > 1.0f)
237
+                    vol = 1.0f;
238
+                getSound().setVolume(vol);
239
+            }
240
+
241
+            int w = getWindow().getWidth();
242
+            if (ImGui::InputInt("Width##runtime", &w, 10, 100, ImGuiInputTextFlags_EnterReturnsTrue)) {
243
+                if (w < 1)
244
+                    w = 1;
245
+                getWindow().setSize(w, getWindow().getHeight());
246
+            }
247
+            int h = getWindow().getHeight();
248
+            if (ImGui::InputInt("Height##runtime", &h, 10, 100, ImGuiInputTextFlags_EnterReturnsTrue)) {
249
+                if (h < 1)
250
+                    h = 1;
251
+                getWindow().setSize(getWindow().getWidth(), h);
252
+            }
253
+
254
+            static int fr = 0;
255
+            char buff[1024];
256
+            strncpy(buff, getRunTime().getBaseDir().c_str(), 1024);
257
+            if (ImGui::InputText("BaseDir##runtime", buff, 1024, ImGuiInputTextFlags_EnterReturnsTrue)) {
258
+                getRunTime().setBaseDir(buff);
259
+                fr = getRunTime().getFPS();
260
+            }
261
+            if (fr > 0) {
262
+                ImGui::SameLine();
263
+                ImGui::Text("Done!##runtime1");
264
+                fr--;
265
+            }
266
+
267
+            static int fr2 = 0;
268
+            char buff2[1024];
269
+            strncpy(buff2, getRunTime().getPakDir().c_str(), 1024);
270
+            if (ImGui::InputText("PakDir##runtime", buff2, 1024, ImGuiInputTextFlags_EnterReturnsTrue)) {
271
+                getRunTime().setPakDir(buff2);
272
+                fr2 = getRunTime().getFPS();
273
+            }
274
+            if (fr2 > 0) {
275
+                ImGui::SameLine();
276
+                ImGui::Text("Done!##runtime2");
277
+                fr2--;
278
+            }
279
+
280
+            static int fr3 = 0;
281
+            char buff3[1024];
282
+            strncpy(buff3, getRunTime().getAudioDir().c_str(), 1024);
283
+            if (ImGui::InputText("AudioDir##runtime", buff3, 1024, ImGuiInputTextFlags_EnterReturnsTrue)) {
284
+                getRunTime().setAudioDir(buff3);
285
+                fr3 = getRunTime().getFPS();
286
+            }
287
+            if (fr3 > 0) {
288
+                ImGui::SameLine();
289
+                ImGui::Text("Done!##runtime3");
290
+                fr3--;
291
+            }
292
+
293
+            static int fr4 = 0;
294
+            char buff4[1024];
295
+            strncpy(buff4, getRunTime().getDataDir().c_str(), 1024);
296
+            if (ImGui::InputText("DataDir##runtime", buff4, 1024, ImGuiInputTextFlags_EnterReturnsTrue)) {
297
+                getRunTime().setDataDir(buff4);
298
+                fr4 = getRunTime().getFPS();
299
+            }
300
+            if (fr4 > 0) {
301
+                ImGui::SameLine();
302
+                ImGui::Text("Done!##runtime4");
303
+                fr4--;
304
+            }
305
+        }
306
+
210 307
         static bool visibleTex = false;
211 308
         static bool visibleTile = false;
309
+        static bool visibleAnim = false;
212 310
         if (ImGui::CollapsingHeader("Texture Viewer")) {
213 311
             static bool game = getGame().isLoaded();
214 312
             static int index = 0;
@@ -245,6 +343,7 @@ void UI::display() {
245 343
             if (ImGui::Button("Show##texshow")) {
246 344
                 visibleTex = true;
247 345
                 visibleTile = false;
346
+                visibleAnim = false;
248 347
             }
249 348
             ImGui::SameLine();
250 349
             if (ImGui::Button("Clear##texclear")) {
@@ -285,6 +384,7 @@ void UI::display() {
285 384
                 if (ImGui::Button("Show##tileshow")) {
286 385
                     visibleTile = true;
287 386
                     visibleTex = false;
387
+                    visibleAnim = false;
288 388
                 }
289 389
                 ImGui::SameLine();
290 390
                 if (ImGui::Button("Clear##tileclear")) {
@@ -301,7 +401,62 @@ void UI::display() {
301 401
                             (ImGui::GetWindowWidth() / 2), (ImGui::GetWindowWidth() / 2));
302 402
                 }
303 403
             } else {
304
-                ImGui::Text("Please load a level!");
404
+                ImGui::Text("Please load a level using the new loader!");
405
+            }
406
+        }
407
+
408
+        if (ImGui::CollapsingHeader("Animated Textile Viewer")) {
409
+            if (getTextureManager().numAnimatedTiles() > 0) {
410
+                static int index = 0;
411
+                static int tile = getTextureManager().getFirstTileAnimation(index);
412
+                ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
413
+                if (ImGui::SliderInt("##animslide", &index, 0, getTextureManager().numAnimatedTiles() - 1)) {
414
+                    tile = getTextureManager().getFirstTileAnimation(index);
415
+                }
416
+                ImGui::PopItemWidth();
417
+                ImGui::SameLine();
418
+                if (ImGui::Button("+##animplus", ImVec2(0, 0), true)) {
419
+                    if (index < (getTextureManager().numAnimatedTiles() - 1))
420
+                        index++;
421
+                    else
422
+                        index = 0;
423
+                    tile = getTextureManager().getFirstTileAnimation(index);
424
+                }
425
+                ImGui::SameLine();
426
+                if (ImGui::Button("-##animminus", ImVec2(0, 0), true)) {
427
+                    if (index > 0)
428
+                        index--;
429
+                    else
430
+                        index = getTextureManager().numAnimatedTiles() - 1;
431
+                    tile = getTextureManager().getFirstTileAnimation(index);
432
+                }
433
+                ImGui::SameLine();
434
+                static int fr = 0;
435
+                if (ImGui::Button("Show##animshow")) {
436
+                    visibleAnim = true;
437
+                    visibleTex = false;
438
+                    visibleTile = false;
439
+                }
440
+                ImGui::SameLine();
441
+                if (ImGui::Button("Clear##animclear")) {
442
+                    getRender().debugDisplayTextile();
443
+                    visibleAnim = false;
444
+                }
445
+                if (visibleAnim) {
446
+                    if (fr > 0) {
447
+                        fr--;
448
+                    } else {
449
+                        getRender().debugDisplayTextile(tile,
450
+                                ImGui::GetWindowPos().x - (ImGui::GetWindowWidth() / 2),
451
+                                ImGui::GetWindowPos().y,
452
+                                (ImGui::GetWindowWidth() / 2), (ImGui::GetWindowWidth() / 2));
453
+                        fr = getRunTime().getFPS() / 2;
454
+                        tile = getTextureManager().getNextTileAnimation(tile);
455
+                    }
456
+                    ImGui::Text("Current Tile: %d", tile);
457
+                }
458
+            } else {
459
+                ImGui::Text("Please load a level with animated textures!");
305 460
             }
306 461
         }
307 462
 
@@ -339,11 +494,9 @@ void UI::display() {
339 494
             }
340 495
         }
341 496
 
342
-        /*
343
-        if (ImGui::CollapsingHeader("UI Help")) {
497
+        if (ImGui::CollapsingHeader("ImGui UI Help")) {
344 498
             ImGui::ShowUserGuide();
345 499
         }
346
-        */
347 500
     }
348 501
     ImGui::End();
349 502
 

+ 44
- 6
src/loader/LoaderTR2.cpp 查看文件

@@ -276,6 +276,9 @@ void LoaderTR2::loadFloorData() {
276 276
 
277 277
         // TODO store floor data somewhere
278 278
     }
279
+
280
+    if (numFloorData > 0)
281
+        getLog() << "LoaderTR2: Found " << numFloorData << " words FloorData, unimplemented!" << Log::endl;
279 282
 }
280 283
 
281 284
 void LoaderTR2::loadMeshes() {
@@ -292,7 +295,6 @@ void LoaderTR2::loadMeshes() {
292 295
     uint32_t numMeshPointers = file.readU32();
293 296
 
294 297
     if ((numMeshData == 0) || (numMeshPointers == 0)) {
295
-        //! \fixme debug level regulating output?
296 298
         getLog() << "LoaderTR2: No mesh data found!" << Log::endl;
297 299
         return;
298 300
     }
@@ -438,6 +440,9 @@ void LoaderTR2::loadStaticMeshes() {
438 440
 
439 441
         // TODO store static meshes somewhere
440 442
     }
443
+
444
+    if (numStaticMeshes > 0)
445
+        getLog() << "LoaderTR2: Found " << numStaticMeshes << " StaticMeshes, unimplemented!" << Log::endl;
441 446
 }
442 447
 
443 448
 void LoaderTR2::loadTextures() {
@@ -515,6 +520,9 @@ void LoaderTR2::loadCameras() {
515 520
 
516 521
         // TODO store cameras somewhere
517 522
     }
523
+
524
+    if (numCameras > 0)
525
+        getLog() << "LoaderTR2: Found " << numCameras << " Cameras, unimplemented!" << Log::endl;
518 526
 }
519 527
 
520 528
 void LoaderTR2::loadSoundSources() {
@@ -533,6 +541,9 @@ void LoaderTR2::loadSoundSources() {
533 541
 
534 542
         // TODO store sound sources somewhere
535 543
     }
544
+
545
+    if (numSoundSources > 0)
546
+        getLog() << "LoaderTR2: Found " << numSoundSources << " SoundSources, unimplemented!" << Log::endl;
536 547
 }
537 548
 
538 549
 void LoaderTR2::loadBoxesOverlapsZones() {
@@ -575,13 +586,31 @@ void LoaderTR2::loadBoxesOverlapsZones() {
575 586
 }
576 587
 
577 588
 void LoaderTR2::loadAnimatedTextures() {
578
-    uint32_t numAnimatedTextures = file.readU32();
589
+    uint32_t numWords = file.readU32() - 1;
590
+    uint16_t numAnimatedTextures = file.readU16();
579 591
     std::vector<uint16_t> animatedTextures;
580
-    for (unsigned int a = 0; a < numAnimatedTextures; a++) {
592
+    for (unsigned int a = 0; a < numWords; a++) {
581 593
         animatedTextures.push_back(file.readU16());
582 594
     }
583 595
 
584
-    // TODO store animated textures somewhere. Format?
596
+    int pos = 0;
597
+    for (unsigned int a = 0; a < numAnimatedTextures; a++) {
598
+        int count = animatedTextures.at(pos) + 1;
599
+        if ((pos + count) >= numWords) {
600
+            getLog() << "LoaderTR2: Invalid AnimatedTextures ("
601
+                << pos + count << " >= " << numWords << ")!" << Log::endl;
602
+            return;
603
+        }
604
+
605
+        for (int i = 0; i < count; i++) {
606
+            getTextureManager().addAnimatedTile(a, animatedTextures.at(pos + i + 1));
607
+        }
608
+
609
+        pos += count + 1;
610
+    }
611
+
612
+    if (pos != numWords)
613
+        getLog() << "LoaderTR2: Extra bytes at end of AnimatedTextures?" << Log::endl;
585 614
 }
586 615
 
587 616
 void LoaderTR2::loadItems() {
@@ -605,6 +634,9 @@ void LoaderTR2::loadItems() {
605 634
 
606 635
         // TODO store items somewhere
607 636
     }
637
+
638
+    if (numItems > 0)
639
+        getLog() << "LoaderTR2: Found " << numItems << " Items, unimplemented!" << Log::endl;
608 640
 }
609 641
 
610 642
 void LoaderTR2::loadCinematicFrames() {
@@ -623,7 +655,8 @@ void LoaderTR2::loadCinematicFrames() {
623 655
     }
624 656
 
625 657
     if (numCinematicFrames > 0)
626
-        getLog() << "LoaderTR2: Found CinematicFrames, not yet implemented!" << Log::endl;
658
+        getLog() << "LoaderTR2: Found " << numCinematicFrames
659
+            << " CinematicFrames, not yet implemented!" << Log::endl;
627 660
 }
628 661
 
629 662
 void LoaderTR2::loadDemoData() {
@@ -633,7 +666,7 @@ void LoaderTR2::loadDemoData() {
633 666
 
634 667
     // TODO store demo data somewhere, find out meaning
635 668
     if (numDemoData > 0)
636
-        getLog() << "LoaderTR2: Found DemoData, not yet implemented!" << Log::endl;
669
+        getLog() << "LoaderTR2: Found " << numDemoData << " bytes DemoData, not yet implemented!" << Log::endl;
637 670
 }
638 671
 
639 672
 void LoaderTR2::loadSoundMap() {
@@ -661,6 +694,9 @@ void LoaderTR2::loadSoundDetails() {
661 694
 
662 695
         // TODO store sound details somewhere
663 696
     }
697
+
698
+    if (numSoundDetails > 0)
699
+        getLog() << "LoaderTR2: Found " << numSoundDetails << " SoundDetails, unimplemented!" << Log::endl;
664 700
 }
665 701
 
666 702
 void LoaderTR2::loadSampleIndices() {
@@ -671,6 +707,8 @@ void LoaderTR2::loadSampleIndices() {
671 707
     }
672 708
 
673 709
     // TODO store sample indices somewhere
710
+    if (numSampleIndices > 0)
711
+        getLog() << "LoaderTR2: Found " << numSampleIndices << " SampleIndices, unimplemented!" << Log::endl;
674 712
 }
675 713
 
676 714
 void LoaderTR2::loadExternalSoundFile(std::string f) {

正在加载...
取消
保存