diff --git a/rwgame/CMakeLists.txt b/rwgame/CMakeLists.txt index 2647df08..700d2260 100644 --- a/rwgame/CMakeLists.txt +++ b/rwgame/CMakeLists.txt @@ -21,9 +21,6 @@ set(RWGAME_SOURCES benchmarkstate.cpp DrawUI.cpp - - debug/HttpServer.cpp - debug/TcpSocket.cpp ) add_executable(rwgame @@ -48,8 +45,7 @@ if(MINGW) add_definitions(-D _USE_MATH_DEFINES) target_link_libraries(rwgame iconv - mman - ws2_32) + mman) endif() install(TARGETS rwgame RUNTIME DESTINATION "${BIN_DIR}") diff --git a/rwgame/RWGame.cpp b/rwgame/RWGame.cpp index e4a6a68b..7149343c 100644 --- a/rwgame/RWGame.cpp +++ b/rwgame/RWGame.cpp @@ -5,7 +5,6 @@ #include "ingamestate.hpp" #include "menustate.hpp" #include "benchmarkstate.hpp" -#include "debug/HttpServer.hpp" #include @@ -74,10 +73,6 @@ RWGame::RWGame(int argc, char* argv[]) { test = true; } - if( strcmp( "--debug", argv[i] ) == 0 ) - { - debugScript = true; - } if( strcmp( "--load", argv[i] ) == 0 && i+1 < argc ) { startSave = argv[i+1]; @@ -253,28 +248,12 @@ void RWGame::startScript(const std::string& name) if( f ) { if( script ) delete script; - if ( debugScript ) { - if( httpserver ) { - delete httpserver; - } - httpserver_thread = new std::thread([&](){ - httpserver = new HttpServer(this, world); - httpserver->run(); - }); - } - SCMOpcodes* opcodes = new SCMOpcodes; opcodes->modules.push_back(new VMModule); opcodes->modules.push_back(new GameModule); opcodes->modules.push_back(new ObjectModule); script = new ScriptMachine(state, f, opcodes); - - /* If Debug server is available, break on the first opcode executed */ - if( httpserver ) { - //script->interuptNext(); - } - //script->addBreakpoint(SCMBreakpointInfo::breakThreadName("i_save")); // Set up breakpoint handler script->setBreakpointHandler( @@ -295,7 +274,6 @@ void RWGame::startScript(const std::string& name) } log.info("Script", ss.str()); - httpserver->handleBreakpoint(bp); }); state->script = script; } @@ -413,11 +391,6 @@ int RWGame::run() window->swap(); } - if( httpserver_thread ) - { - httpserver_thread->join(); - } - return 0; } diff --git a/rwgame/RWGame.hpp b/rwgame/RWGame.hpp index 9262b4e8..19d77bc3 100644 --- a/rwgame/RWGame.hpp +++ b/rwgame/RWGame.hpp @@ -15,7 +15,6 @@ #include class PlayerController; -class HttpServer; class RWGame { @@ -30,9 +29,6 @@ class RWGame GameWindow *window = nullptr; // Background worker WorkContext *work = nullptr; - bool debugScript = false; - HttpServer* httpserver = nullptr; - std::thread* httpserver_thread = nullptr; std::chrono::steady_clock clock; std::chrono::steady_clock::time_point last_clock_time; diff --git a/rwgame/debug/HttpServer.cpp b/rwgame/debug/HttpServer.cpp deleted file mode 100644 index 7cbcfa34..00000000 --- a/rwgame/debug/HttpServer.cpp +++ /dev/null @@ -1,372 +0,0 @@ -#include "HttpServer.hpp" -#include - -#include -#include - -const char* src_debugger_js = R"( -var app = angular.module('debugApp', []); -app.controller('DebugCtrl', function($scope,$http) { - $scope.threads = []; - $scope.running = true; - $scope.breakpoint = {}; - $scope.refresh = function() { - var promise = $http.get('/state') - .success(function(data, status, headers, config) { - $scope.running = data.status == 'running'; - $scope.threads = data.threads; - $scope.breakpoint = data.breakpoint; - }); - }; - $scope.interrupt = function() { - var promise = $http.get('/interrupt') - .success(function(data, status, headers, config) { - $scope.refresh(); - }); - } - $scope.step = function() { - var promise = $http.get('/step') - .success(function(data, status, headers, config) { - $scope.refresh(); - }); - } - $scope.continue = function() { - var promise = $http.get('/continue') - .success(function(data, status, headers, config) { - $scope.refresh(); - }); - } - $scope.refresh(); -}); - -)"; - -const char* src_page = R"( - - - - - - -

OpenRW Debugger

-
- - - -
- Game is running -
- {{ breakpoint.program_counter }} {{ breakpoint.thread }} -

Threads

-
    -
  • -

    {{thread.name}} ({{thread.address}})

    - program counter: {{thread.program_counter}}
    - wake counter: {{thread.wake_counter}} ms
    -

    Return Stack

    -
      -
    1. - Address {{return_address}} -
    2. -
    -

    Disassembly

    -
    -
    - - {{ call.address }} - - - {{call.function }} - - - ( - - {{param.value}}, - - ) - -
    -
    -
      -
    1. - Address {{return_address}} -
    2. -
    -
  • -
-
-
- - - )"; - -HttpServer::HttpServer(RWGame* game, GameWorld* world) - : game(game), world(world), paused(false), lastBreakpoint(nullptr) -{} - -void HttpServer::run() -{ - if (!socket.bind(8091)) - return; - - std::cout << "STARTING HTTP SERVER" << std::endl; - - TcpSocket client; - while (game->getWindow().isOpen() && socket.listen(client)) { - std::cout << "New connection from " - << client.getRemoteAddress() << ":" << client.getRemotePort() - << std::endl; - - std::string buffer; - client.recv(buffer, 1024); - - std::cout << "Got " << buffer.length() << " bytes: " << buffer.c_str() << std::endl; - - try - { - std::regex regex_http_first_line("(\\w+)\\s+(/.*?)\\s+HTTP/\\d+.\\d+"); - std::cmatch regex_match; - std::regex_search(buffer.c_str(), regex_match, regex_http_first_line); - - if (regex_match.size() == 3) { - std::string http_method = regex_match.str(1); - std::string http_path = regex_match.str(2); - - std::string response = dispatch(http_method, http_path); - client.send(response); - } - } - catch(std::regex_error er) - { - std::cerr << er.what() << " " << er.code() << std::endl; - } - - client.disconnect(); - } -} - -void HttpServer::handleBreakpoint(const SCMBreakpoint &bp) -{ - lastBreakpoint = &bp; - paused = true; - - while( paused ) { - // Do nothing - } -} -std::string thread_stack(SCMThread& th) -{ - std::stringstream ss; - for(unsigned int i = 0; i < th.stackDepth; ++i) - { - bool last = (th.stackDepth == i+1); - ss << th.calls[i] - << (last ? "" : ","); - } - return ss.str(); -} - -#include