Kaynağa Gözat

Don't test by default. Added support for doorways mode.

Steve Thielemann 4 yıl önce
ebeveyn
işleme
25f69a06fe
2 değiştirilmiş dosya ile 99 ekleme ve 21 silme
  1. 21 21
      CMakeLists.txt
  2. 78 0
      door.cpp

+ 21 - 21
CMakeLists.txt

@@ -42,27 +42,27 @@ endif()
 
 add_library(door++ ${HEADERS} ${SOURCES})
 
-## if(NOT EXISTS ${CMAKE_SOURCE_DIR}/googletest)
-if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
-  message("***")
-  message("*** ERROR/MISSING *** please run: git clone https://github.com/google/googletest.git")
-  message("***")
-endif()
-
-add_subdirectory(googletest)
-
-option(gtest_build_samples "Build gtest's sample programs." OFF)
-option(gtest_disable_pthreads "Disable uses of pthreads in gtest." OFF)
-
-### TESTS
-add_executable(test-door test-door.cpp)
-add_dependencies(test-door gtest)
-target_link_libraries(test-door gtest_main door++)
-
-enable_testing()
-add_test(NAME test-door 
-  COMMAND test-door)
-
+if(TESTS)
+  if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
+    message("***")
+    message("*** ERROR/MISSING *** please run: git clone https://github.com/google/googletest.git")
+    message("***")
+  endif()
+
+  add_subdirectory(googletest)
+
+  option(gtest_build_samples "Build gtest's sample programs." OFF)
+  option(gtest_disable_pthreads "Disable uses of pthreads in gtest." OFF)
+
+  ### TESTS
+  add_executable(test-door test-door.cpp)
+  add_dependencies(test-door gtest)
+  target_link_libraries(test-door gtest_main door++)
+
+  enable_testing()
+  add_test(NAME test-door 
+    COMMAND test-door)
+endif()  
 # target_link_libraries(door++ pthread)
 
 target_include_directories(door++ PUBLIC $<BUILD_INTERFACE:${HEADERS_DIR}>)

+ 78 - 0
door.cpp

@@ -550,8 +550,11 @@ signed int Door::getch(void) {
     FD_ZERO(&socket_set);
     FD_SET(STDIN_FILENO, &socket_set);
 
+    // This delay isn't long enough for QModem in a DOSBOX.
+    // doorway mode arrow keys aren't always caught.
     tv.tv_sec = 0;
     tv.tv_usec = 100;
+    // tv.tv_usec = 500;
 
     select_ret = select(STDIN_FILENO + 1, &socket_set, NULL, NULL, &tv);
     // select(STDIN_FILENO + 1, &socket_set, NULL, NULL, bWait ? NULL : &tv);
@@ -573,6 +576,8 @@ signed int Door::getch(void) {
     hangup = true;
     return -2;
   }
+  // debug weird keys/layouts.
+  // log() << "read " << std::hex << (int)key << std::endl;
   return key;
 }
 
@@ -617,6 +622,79 @@ signed int Door::getkey(void) {
     return c;
   }
 
+  if (c == 0) {
+    // possibly "doorway mode"
+    int tries = 0;
+
+    c2 = getch();
+    while (c2 < 0) {
+      if (tries > 7) {
+        log() << "ok, got " << c2 << " and " << tries << " so returning 0x00!"
+              << std::endl;
+
+        return c;
+      }
+      c2 = getch();
+      ++tries;
+    }
+
+    if (tries > 0) {
+      log() << "tries " << tries << std::endl;
+    }
+
+    switch (c2) {
+    case 0x50:
+      return XKEY_DOWN_ARROW;
+    case 0x48:
+      return XKEY_UP_ARROW;
+    case 0x4b:
+      return XKEY_LEFT_ARROW;
+    case 0x4d:
+      return XKEY_RIGHT_ARROW;
+    case 0x47:
+      return XKEY_HOME;
+    case 0x4f:
+      return XKEY_END;
+    case 0x49:
+      return XKEY_PGUP;
+    case 0x51:
+      return XKEY_PGDN;
+    case 0x3b:
+      return XKEY_F1;
+    case 0x3c:
+      return XKEY_F2;
+    case 0x3d:
+      return XKEY_F3;
+    case 0x3e:
+      return XKEY_F4;
+    case 0x3f:
+      return XKEY_F5;
+    case 0x40:
+      return XKEY_F6;
+    case 0x41:
+      return XKEY_F7;
+    case 0x42:
+      return XKEY_F8;
+    case 0x43:
+      return XKEY_F9;
+    case 0x44:
+      return XKEY_F10;
+      /*
+    case 0x45:
+      return XKEY_F11;
+    case 0x46:
+      return XKEY_F12;
+      */
+    case 0x52:
+      return XKEY_INSERT;
+    case 0x53:
+      return XKEY_DELETE;
+    }
+    logf << "\r\nDEBUG:\r\n0x00 + 0x" << std::hex << (int)c2;
+    logf << "\r\n";
+    logf.flush();
+  }
+
   if (c == 0x1b) {
     // possible extended key
     c2 = getch();