New build system for Windows
This commit is contained in:
parent
ed2a1afa6f
commit
4f62a201a0
|
@ -1,4 +1,9 @@
|
||||||
CARLA UE4 Plugin
|
CARLA UE4 Plugin
|
||||||
================
|
================
|
||||||
|
|
||||||
|
To build within a project [CarlaServer](Source/CarlaServer/README.md) needs to
|
||||||
|
be built first.
|
||||||
|
|
||||||
See [carla-ue4](https://bitbucket.org/carla-cvc/carla-ue4).
|
See [carla-ue4](https://bitbucket.org/carla-cvc/carla-ue4).
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ using UnrealBuildTool;
|
||||||
|
|
||||||
public class Carla : ModuleRules
|
public class Carla : ModuleRules
|
||||||
{
|
{
|
||||||
|
private readonly bool bUseDebugLibs = false;
|
||||||
|
|
||||||
public Carla(TargetInfo Target)
|
public Carla(TargetInfo Target)
|
||||||
{
|
{
|
||||||
PublicIncludePaths.AddRange(
|
PublicIncludePaths.AddRange(
|
||||||
|
@ -48,6 +50,7 @@ public class Carla : ModuleRules
|
||||||
|
|
||||||
AddBoostDependency(Target);
|
AddBoostDependency(Target);
|
||||||
AddProtobufDependency(Target);
|
AddProtobufDependency(Target);
|
||||||
|
AddTurboJPEGDependency(Target);
|
||||||
AddCarlaServerDependency(Target);
|
AddCarlaServerDependency(Target);
|
||||||
|
|
||||||
if (Target.Platform == UnrealTargetPlatform.Linux)
|
if (Target.Platform == UnrealTargetPlatform.Linux)
|
||||||
|
@ -55,7 +58,6 @@ public class Carla : ModuleRules
|
||||||
// Fails to link the std libraries.
|
// Fails to link the std libraries.
|
||||||
PublicAdditionalLibraries.Add("stdc++");
|
PublicAdditionalLibraries.Add("stdc++");
|
||||||
}
|
}
|
||||||
PublicAdditionalLibraries.Add("turbojpeg");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsWindows(TargetInfo Target)
|
private bool IsWindows(TargetInfo Target)
|
||||||
|
@ -97,12 +99,23 @@ public class Carla : ModuleRules
|
||||||
if (IsWindows(Target))
|
if (IsWindows(Target))
|
||||||
{
|
{
|
||||||
string ProtobufRoot = System.Environment.GetEnvironmentVariable("PROTOBUF_ROOT");
|
string ProtobufRoot = System.Environment.GetEnvironmentVariable("PROTOBUF_ROOT");
|
||||||
|
string ProtobufLib;
|
||||||
|
if (bUseDebugLibs)
|
||||||
|
{
|
||||||
|
ProtobufRoot = Path.Combine(ProtobufRoot, "Debug");
|
||||||
|
ProtobufLib = "libprotobufd.lib";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ProtobufRoot = Path.Combine(ProtobufRoot, "Release");
|
||||||
|
ProtobufLib = "libprotobuf.lib";
|
||||||
|
}
|
||||||
if (string.IsNullOrEmpty(ProtobufRoot) || !System.IO.Directory.Exists(ProtobufRoot))
|
if (string.IsNullOrEmpty(ProtobufRoot) || !System.IO.Directory.Exists(ProtobufRoot))
|
||||||
{
|
{
|
||||||
throw new System.Exception("PROTOBUF_ROOT is not defined, or points to a non-existant directory, please set this environment variable.");
|
throw new System.Exception("PROTOBUF_ROOT is not defined, or points to a non-existant directory, please set this environment variable.");
|
||||||
}
|
}
|
||||||
PrivateIncludePaths.Add(Path.Combine(ProtobufRoot, "include"));
|
PrivateIncludePaths.Add(Path.Combine(ProtobufRoot, "include"));
|
||||||
PublicAdditionalLibraries.Add(Path.Combine(ProtobufRoot, "lib", "libprotobuf.lib"));
|
PublicAdditionalLibraries.Add(Path.Combine(ProtobufRoot, "lib", ProtobufLib));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -110,31 +123,41 @@ public class Carla : ModuleRules
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddCarlaServerDependency(TargetInfo Target)
|
private void AddTurboJPEGDependency(TargetInfo Target)
|
||||||
{
|
{
|
||||||
string CarlaServerIncludePath;
|
if (Target.Platform == UnrealTargetPlatform.Linux)
|
||||||
string CarlaServerLibPath;
|
|
||||||
string CarlaServerLib;
|
|
||||||
string TurboJpegLib;
|
|
||||||
|
|
||||||
if (IsWindows(Target))
|
|
||||||
{
|
{
|
||||||
CarlaServerIncludePath = "CarlaServer/include";
|
PublicAdditionalLibraries.Add("turbojpeg");
|
||||||
CarlaServerLibPath = "CarlaServer/lib/Release";
|
}
|
||||||
CarlaServerLib = Path.Combine(ModuleDirectory, "..", CarlaServerLibPath, "carla_server.lib");
|
}
|
||||||
TurboJpegLib = Path.Combine(ModuleDirectory, "..", CarlaServerLibPath, "turbojpeg.lib");
|
|
||||||
|
private void AddCarlaServerDependency(TargetInfo Target)
|
||||||
|
{
|
||||||
|
string CarlaServerIncludePath = "CarlaServer/include";
|
||||||
|
string CarlaServerLibPath = Path.Combine(ModuleDirectory, "..", "CarlaServer/lib");
|
||||||
|
|
||||||
|
string CarlaServerLibBaseName;
|
||||||
|
if (bUseDebugLibs)
|
||||||
|
{
|
||||||
|
CarlaServerLibBaseName = "carlaserverd";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CarlaServerIncludePath = "CarlaServer/include";
|
CarlaServerLibBaseName = "carlaserver";
|
||||||
CarlaServerLibPath = "CarlaServer/lib";
|
}
|
||||||
CarlaServerLib = Path.Combine(ModuleDirectory, "..", CarlaServerLibPath, "libcarla_server.a");
|
|
||||||
TurboJpegLib = Path.Combine(ModuleDirectory, "..", CarlaServerLibPath, "libturbojpeg.a");
|
string CarlaServerLib;
|
||||||
|
if (IsWindows(Target))
|
||||||
|
{
|
||||||
|
CarlaServerLib = Path.Combine(CarlaServerLibPath, CarlaServerLibBaseName + ".lib");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CarlaServerLib = Path.Combine(CarlaServerLibPath, "lib" + CarlaServerLibBaseName + ".a");
|
||||||
}
|
}
|
||||||
|
|
||||||
PublicIncludePaths.Add(CarlaServerIncludePath);
|
PublicIncludePaths.Add(CarlaServerIncludePath);
|
||||||
PrivateIncludePaths.Add(CarlaServerIncludePath);
|
PrivateIncludePaths.Add(CarlaServerIncludePath);
|
||||||
PublicAdditionalLibraries.Add(CarlaServerLib);
|
PublicAdditionalLibraries.Add(CarlaServerLib);
|
||||||
PublicAdditionalLibraries.Add(TurboJpegLib);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ static bool SendAndReadSceneValues(
|
||||||
if (!Server.sendSceneValues(sceneValues))
|
if (!Server.sendSceneValues(sceneValues))
|
||||||
return false;
|
return false;
|
||||||
// Wait till we receive an answer.
|
// Wait till we receive an answer.
|
||||||
uint32 EndIndex;
|
uint32 EndIndex = 0u;
|
||||||
bool Success = false;
|
bool Success = false;
|
||||||
UE_LOG(LogCarlaServer, Log, TEXT("(tryReadEpisodeStart) Waiting for client..."));
|
UE_LOG(LogCarlaServer, Log, TEXT("(tryReadEpisodeStart) Waiting for client..."));
|
||||||
while (!Success) {
|
while (!Success) {
|
||||||
|
@ -125,7 +125,7 @@ static bool SendAndReadSceneValues(
|
||||||
}
|
}
|
||||||
UE_LOG(LogCarlaServer, Log, TEXT("Episode start received: { StartIndex = %d, EndIndex = %d }"), StartIndex, EndIndex);
|
UE_LOG(LogCarlaServer, Log, TEXT("Episode start received: { StartIndex = %d, EndIndex = %d }"), StartIndex, EndIndex);
|
||||||
// Make sure the index is in range.
|
// Make sure the index is in range.
|
||||||
if (StartIndex >= AvailableStartSpots.Num()) {
|
if (StartIndex >= static_cast<uint32>(AvailableStartSpots.Num())) {
|
||||||
UE_LOG(
|
UE_LOG(
|
||||||
LogCarlaServer,
|
LogCarlaServer,
|
||||||
Error,
|
Error,
|
||||||
|
|
|
@ -40,7 +40,7 @@ void ACarlaPlayerState::CopyProperties(APlayerState *PlayerState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ACarlaPlayerState::RegisterCollision(AActor */*Actor*/, FVector NormalImpulse)
|
void ACarlaPlayerState::RegisterCollision(AActor * /*Actor*/, FVector NormalImpulse)
|
||||||
{
|
{
|
||||||
CollisionIntensityOther += NormalImpulse.Size();
|
CollisionIntensityOther += NormalImpulse.Size();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ CMakeCache.txt
|
||||||
CMakeFiles
|
CMakeFiles
|
||||||
|
|
||||||
bin
|
bin
|
||||||
|
bin_debug
|
||||||
build
|
build
|
||||||
include
|
include
|
||||||
lib
|
lib
|
||||||
|
|
|
@ -10,24 +10,115 @@ endif (UNIX)
|
||||||
set(CMAKE_CXX_STANDARD 14)
|
set(CMAKE_CXX_STANDARD 14)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED 14)
|
set(CMAKE_CXX_STANDARD_REQUIRED 14)
|
||||||
|
|
||||||
# Boost configuration.
|
# ==============================================================================
|
||||||
|
# -- Suppress windows warning --------------------------------------------------
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
# http://stackoverflow.com/a/40217291
|
||||||
|
if (WIN32)
|
||||||
|
macro(get_WIN32_WINNT version)
|
||||||
|
if (CMAKE_SYSTEM_VERSION)
|
||||||
|
set(ver ${CMAKE_SYSTEM_VERSION})
|
||||||
|
string(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver})
|
||||||
|
string(REGEX MATCH "^([0-9]+)" verMajor ${ver})
|
||||||
|
# Check for Windows 10, b/c we'll need to convert to hex 'A'.
|
||||||
|
if ("${verMajor}" MATCHES "10")
|
||||||
|
set(verMajor "A")
|
||||||
|
string(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver})
|
||||||
|
endif ("${verMajor}" MATCHES "10")
|
||||||
|
# Remove all remaining '.' characters.
|
||||||
|
string(REPLACE "." "" ver ${ver})
|
||||||
|
# Prepend each digit with a zero.
|
||||||
|
string(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver})
|
||||||
|
set(${version} "0x${ver}")
|
||||||
|
endif(CMAKE_SYSTEM_VERSION)
|
||||||
|
endmacro(get_WIN32_WINNT)
|
||||||
|
get_WIN32_WINNT(ver)
|
||||||
|
add_definitions(-D_WIN32_WINNT=${ver})
|
||||||
|
endif(WIN32)
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# -- Boost ---------------------------------------------------------------------
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
set(Boost_USE_STATIC_LIBS ON)
|
set(Boost_USE_STATIC_LIBS ON)
|
||||||
find_package(Boost REQUIRED system date_time regex)
|
find_package(Boost REQUIRED system date_time regex)
|
||||||
include_directories(${Boost_INCLUDE_DIRS})
|
include_directories(${Boost_INCLUDE_DIRS})
|
||||||
|
|
||||||
#TurboJPEG
|
# ==============================================================================
|
||||||
|
# -- Protobuf ------------------------------------------------------------------
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
# Protobuf.
|
|
||||||
include(FindProtobuf)
|
|
||||||
find_package(Protobuf REQUIRED)
|
|
||||||
include_directories(${PROTOBUF_INCLUDE_DIR})
|
|
||||||
if (UNIX)
|
if (UNIX)
|
||||||
set(Protobuf_LIBRARIES ${Protobuf_LIBRARIES} protobuf turbojpeg)
|
|
||||||
|
include(FindProtobuf)
|
||||||
|
find_package(Protobuf REQUIRED)
|
||||||
|
include_directories(${PROTOBUF_INCLUDE_DIR})
|
||||||
|
set(Protobuf_LIBRARIES protobuf)
|
||||||
|
|
||||||
|
elseif (WIN32)
|
||||||
|
|
||||||
|
if (CMAKE_BUILD_TYPE MATCHES Debug)
|
||||||
|
|
||||||
|
if (EXISTS $ENV{PROTOBUF_ROOT}/Debug)
|
||||||
|
message(STATUS "Using Protobuf DEBUG at " $ENV{PROTOBUF_ROOT}/Debug)
|
||||||
|
include_directories($ENV{PROTOBUF_ROOT}/Debug/include)
|
||||||
|
link_directories($ENV{PROTOBUF_ROOT}/Debug/lib)
|
||||||
|
set(Protobuf_LIBRARIES libprotobufd.lib)
|
||||||
|
else (EXISTS $ENV{PROTOBUF_ROOT}/Debug)
|
||||||
|
message(FATAL_ERROR "Cannot find PROTOBUF_ROOT/Debug")
|
||||||
|
endif (EXISTS $ENV{PROTOBUF_ROOT}/Debug)
|
||||||
|
|
||||||
|
else (CMAKE_BUILD_TYPE MATCHES Release)
|
||||||
|
|
||||||
|
if (EXISTS $ENV{PROTOBUF_ROOT}/Release)
|
||||||
|
message(STATUS "Using Protobuf RELEASE at " $ENV{PROTOBUF_ROOT}/Release)
|
||||||
|
include_directories($ENV{PROTOBUF_ROOT}/Release/include)
|
||||||
|
link_directories($ENV{PROTOBUF_ROOT}/Release/lib)
|
||||||
|
set(Protobuf_LIBRARIES libprotobuf.lib)
|
||||||
|
else (EXISTS $ENV{PROTOBUF_ROOT}/Release)
|
||||||
|
message(FATAL_ERROR "Cannot find PROTOBUF_ROOT/Release")
|
||||||
|
endif (EXISTS $ENV{PROTOBUF_ROOT}/Release)
|
||||||
|
|
||||||
|
endif (CMAKE_BUILD_TYPE MATCHES Debug)
|
||||||
|
|
||||||
endif (UNIX)
|
endif (UNIX)
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# -- TurboJPEG -----------------------------------------------------------------
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
if (UNIX)
|
||||||
|
|
||||||
|
set(TurboJPEG_LIBRARIES ${TurboJPEG_LIBRARIES} turbojpeg)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWITH_TURBOJPEG")
|
||||||
|
|
||||||
|
elseif (WIN32)
|
||||||
|
|
||||||
|
message(WARNING "TurboJPEG not available for Windows yet")
|
||||||
|
|
||||||
|
endif (UNIX)
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# -- Project config ------------------------------------------------------------
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
set(CarlaServer_Deps_LIBRARIES
|
||||||
|
${TurboJPEG_LIBRARIES}
|
||||||
|
${Protobuf_LIBRARIES}
|
||||||
|
${Boost_DATE_TIME_LIBRARY}
|
||||||
|
${Boost_REGEX_LIBRARY}
|
||||||
|
${Boost_SYSTEM_LIBRARY}
|
||||||
|
${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
|
||||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
|
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
|
||||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
|
if (CMAKE_BUILD_TYPE MATCHES Debug)
|
||||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
|
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin_debug)
|
||||||
|
set(CarlaServer_LIBRARIES carlaserverd ${CarlaServer_Deps_LIBRARIES})
|
||||||
|
elseif (CMAKE_BUILD_TYPE MATCHES Release)
|
||||||
|
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
|
||||||
|
set(CarlaServer_LIBRARIES carlaserver ${CarlaServer_Deps_LIBRARIES})
|
||||||
|
endif (CMAKE_BUILD_TYPE MATCHES Debug)
|
||||||
|
|
||||||
include_directories("${PROJECT_SOURCE_DIR}/source")
|
include_directories("${PROJECT_SOURCE_DIR}/source")
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,35 @@
|
||||||
BUILD_FOLDER=build
|
|
||||||
PROTOBUF_SRC_DIR=source/carla/server
|
PROTOBUF_SRC_DIR=source/carla/server
|
||||||
|
|
||||||
default: build
|
MY_CMAKE_FLAGS=-H. -B$(BUILD_FOLDER)
|
||||||
cd build && ninja && ninja install
|
|
||||||
|
|
||||||
build: protobuf
|
ifeq ($(OS),Windows_NT)
|
||||||
cmake -H. -B$(BUILD_FOLDER) -G "Ninja"
|
DEFAULT_RULE=build_windows
|
||||||
|
else
|
||||||
|
DEFAULT_RULE=build_linux
|
||||||
|
endif
|
||||||
|
|
||||||
|
default: release
|
||||||
|
|
||||||
|
debug: BUILD_FOLDER=build/debug
|
||||||
|
debug: MY_CMAKE_FLAGS+=-DCMAKE_BUILD_TYPE=Debug
|
||||||
|
debug: $(DEFAULT_RULE)
|
||||||
|
|
||||||
|
release: BUILD_FOLDER=build/release
|
||||||
|
release: MY_CMAKE_FLAGS+=-DCMAKE_BUILD_TYPE=Release
|
||||||
|
release: $(DEFAULT_RULE)
|
||||||
|
|
||||||
|
build_linux: protobuf
|
||||||
|
cmake $(MY_CMAKE_FLAGS) -G "Ninja"
|
||||||
|
cd $(BUILD_FOLDER) && ninja && ninja install
|
||||||
|
|
||||||
|
build_windows: protobuf
|
||||||
|
cmake $(MY_CMAKE_FLAGS) -G "NMake Makefiles"
|
||||||
|
cd $(BUILD_FOLDER) && nmake && nmake install
|
||||||
|
|
||||||
|
vsproject: BUILD_FOLDER=build/visualstudio
|
||||||
|
vsproject: MY_CMAKE_FLAGS+=-DCMAKE_BUILD_TYPE=Debug
|
||||||
vsproject: protobuf
|
vsproject: protobuf
|
||||||
cmake -H. -B$(BUILD_FOLDER) -G "Visual Studio 14 2015 Win64"
|
cmake $(MY_CMAKE_FLAGS) -G "Visual Studio 14 2015 Win64"
|
||||||
|
|
||||||
protobuf: $(PROTOBUF_SRC_DIR)/carla_protocol.pb.cc
|
protobuf: $(PROTOBUF_SRC_DIR)/carla_protocol.pb.cc
|
||||||
|
|
||||||
|
@ -20,4 +41,4 @@ clean:
|
||||||
rm -Rf build CMakeFiles
|
rm -Rf build CMakeFiles
|
||||||
|
|
||||||
clean-all: clean
|
clean-all: clean
|
||||||
rm -Rf bin lib include
|
rm -Rf bin bin_debug lib include
|
||||||
|
|
|
@ -27,25 +27,42 @@ At the configure step add PIC compile option
|
||||||
|
|
||||||
#### Windows
|
#### Windows
|
||||||
|
|
||||||
Warning: Outdated
|
Note: JPEG compression is not implemented on Windows, the server won't send any
|
||||||
|
images.
|
||||||
|
|
||||||
Install and compile [boost](http://www.boost.org/).
|
Compile and install [boost](http://www.boost.org/).
|
||||||
|
|
||||||
Install and compile [protobuf](https://developers.google.com/protocol-buffers/).
|
Compile [protobuf](https://developers.google.com/protocol-buffers/). While
|
||||||
While compiling protobuf, use `-Dprotobuf_MSVC_STATIC_RUNTIME=OFF` when calling
|
compiling protobuf, use `-Dprotobuf_MSVC_STATIC_RUNTIME=OFF` when calling CMake
|
||||||
CMake in order to use the static runtime library, otherwise may give errors
|
in order to use the static runtime library, otherwise may give errors while
|
||||||
while trying to link with CarlaServer.
|
trying to link with CarlaServer. Generate both debug and release and install
|
||||||
|
under `$PROTOBUF_ROOT/Debug` and `$PROTOBUF_ROOT/Release` respectively.
|
||||||
|
|
||||||
CMake looks at the following environment variables
|
The Makefile uses cmake to generate project files. Under Windows, it requires
|
||||||
|
the following environment variables set
|
||||||
|
|
||||||
* `CMAKE_INCLUDE_PATH` should contain the protobuf include folder.
|
|
||||||
* `CMAKE_LIBRARY_PATH` should contain "libprotobuf" "libprotobuf-lite" "liteprotoc" .lib files.
|
|
||||||
* `BOOST_ROOT` root of the boost folder.
|
* `BOOST_ROOT` root of the boost folder.
|
||||||
|
* `PROTOBUF_ROOT` contains two folder `Debug` and `Release`, each of them with subfolders `lib` and `include`.
|
||||||
|
|
||||||
To generate the Visual Studio solution
|
Before calling make you need to set up the environment calling `vcvarsall.bat`,
|
||||||
|
usually located at the Visual Studio installation folder. Call it (don't forget
|
||||||
|
the amd64 at the end)
|
||||||
|
|
||||||
|
$ "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
|
||||||
|
|
||||||
|
Then build either debug or release
|
||||||
|
|
||||||
|
$ make debug
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
$ make release
|
||||||
|
|
||||||
|
To generate the Visual Studio project
|
||||||
|
|
||||||
$ make vsproject
|
$ make vsproject
|
||||||
|
|
||||||
The solution gets generated at `./build/CarlaServer.sln`. Change the solution
|
The solution gets generated at `./build/visualstudio/CarlaServer.sln`. Change
|
||||||
configuration to match protobuf (release, most probably). Don't forget to build
|
the solution configuration to match protobuf (release, most probably). Don't
|
||||||
the project INSTALL, it doesn't build when building the solution.
|
forget to build the project INSTALL, it doesn't build when building the
|
||||||
|
solution.
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
file(GLOB carla_server_SRC
|
file(GLOB carlaserver_SRC
|
||||||
"*.h"
|
"*.h"
|
||||||
"*.cpp"
|
"*.cpp"
|
||||||
"*.pb.h"
|
"*.pb.h"
|
||||||
"*.pb.cc"
|
"*.pb.cc"
|
||||||
)
|
)
|
||||||
|
set(carlaserver_SRC ${carlaserver_SRC} ../CarlaServer.cpp)
|
||||||
|
|
||||||
add_library(carla_server STATIC ../CarlaServer.cpp ${carla_server_SRC})
|
if (CMAKE_BUILD_TYPE MATCHES Debug)
|
||||||
|
add_library(carlaserverd STATIC ${carlaserver_SRC})
|
||||||
|
elseif (CMAKE_BUILD_TYPE MATCHES Release)
|
||||||
|
add_library(carlaserver STATIC ${carlaserver_SRC})
|
||||||
|
endif (CMAKE_BUILD_TYPE MATCHES Debug)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "CarlaCommunication.h"
|
#include "CarlaCommunication.h"
|
||||||
#include "lodepng.h"
|
|
||||||
|
|
||||||
#include "carla_protocol.pb.h"
|
#include "carla_protocol.pb.h"
|
||||||
#include "../CarlaServer.h"
|
#include "../CarlaServer.h"
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include "CarlaCommunication.h"
|
#include "CarlaCommunication.h"
|
||||||
#include "carla/CarlaServer.h"
|
#include "carla/CarlaServer.h"
|
||||||
//#include "lodepng.h"
|
|
||||||
|
|
||||||
#include "carla_protocol.pb.h"
|
#include "carla_protocol.pb.h"
|
||||||
|
|
||||||
|
@ -11,76 +10,51 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef WITH_TURBOJPEG
|
||||||
#include <turbojpeg.h>
|
#include <turbojpeg.h>
|
||||||
//#include "jpeglib.h"
|
#endif // WITH_TURBOJPEG
|
||||||
|
|
||||||
|
|
||||||
namespace carla {
|
namespace carla {
|
||||||
namespace server {
|
namespace server {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void WriteImage(const unsigned char *image, long unsigned int size){
|
|
||||||
FILE *out;
|
|
||||||
out = fopen("test.jpeg","w");
|
|
||||||
fwrite(image,1,size,out);
|
|
||||||
fclose(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//static bool getPNGImage(
|
|
||||||
// const std::vector<Color> &in,
|
|
||||||
// uint32_t width,
|
|
||||||
// uint32_t height,
|
|
||||||
// std::vector<unsigned char> &outPNG) {
|
|
||||||
static bool getJPEGImage(
|
static bool getJPEGImage(
|
||||||
const int jpeg_quality,
|
const int jpeg_quality,
|
||||||
const int color_components,
|
const int color_components,
|
||||||
const int width,
|
const int width,
|
||||||
const int height,
|
const int height,
|
||||||
const std::vector<Color> &image,
|
const std::vector<Color> &image,
|
||||||
bool depth,
|
bool depth,
|
||||||
Reward &rwd
|
Reward &rwd){
|
||||||
){
|
#ifndef WITH_TURBOJPEG
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
long unsigned int jpegSize = 0;
|
long unsigned int jpegSize = 0;
|
||||||
|
|
||||||
unsigned char *compressedImage;
|
unsigned char *compressedImage;
|
||||||
|
|
||||||
if (image.empty())
|
if (image.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
if (image.size() != width * height) {
|
if (image.size() != width * height) {
|
||||||
std::cerr << "Invalid image size" << std::endl;
|
std::cerr << "Invalid image size" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Convert to char array RGBA.
|
// Convert to char array RGBA.
|
||||||
int size = 3u * image.size();
|
std::vector<unsigned char> color_image;
|
||||||
unsigned char color_img[size];
|
color_image.reserve(3u * image.size());
|
||||||
|
for (const Color &color : image) {
|
||||||
for (int i = 0, color_it = 0; i < size; ++color_it){
|
color_image.push_back(color.R);
|
||||||
color_img[i++] = image[color_it].R;
|
color_image.push_back(color.G);
|
||||||
color_img[i++] = image[color_it].G;
|
color_image.push_back(color.B);
|
||||||
color_img[i++] = image[color_it].B;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tjhandle jpegCompressor = tjInitCompress();
|
tjhandle jpegCompressor = tjInitCompress();
|
||||||
|
tjCompress2(jpegCompressor, color_image.data(), width, 0, height, TJPF_RGB,
|
||||||
tjCompress2(jpegCompressor, color_img, width, 0, height, TJPF_RGB,
|
|
||||||
&compressedImage, &jpegSize, TJSAMP_444, jpeg_quality, TJFLAG_FASTDCT);
|
&compressedImage, &jpegSize, TJSAMP_444, jpeg_quality, TJFLAG_FASTDCT);
|
||||||
|
|
||||||
|
|
||||||
tjDestroy(jpegCompressor);
|
tjDestroy(jpegCompressor);
|
||||||
|
if (!depth) {
|
||||||
WriteImage(compressedImage, jpegSize);
|
rwd.set_image(compressedImage, jpegSize);
|
||||||
|
} else {
|
||||||
if (!depth) rwd.set_image(compressedImage, jpegSize);
|
rwd.set_depth(compressedImage, jpegSize);
|
||||||
|
}
|
||||||
else rwd.set_depth(compressedImage, jpegSize);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
#endif // WITH_TURBOJPEG
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,10 +82,8 @@ namespace server {
|
||||||
|
|
||||||
auto images = {values.image_rgb_0/*, values.image_rgb_1*/};
|
auto images = {values.image_rgb_0/*, values.image_rgb_1*/};
|
||||||
for (const std::vector<Color> &image : images) {
|
for (const std::vector<Color> &image : images) {
|
||||||
unsigned char *png_image;
|
|
||||||
long unsigned int jpegSize = 0;
|
long unsigned int jpegSize = 0;
|
||||||
if (!getJPEGImage(75, 3, values.image_width, values.image_height, image, false, reward)){
|
if (!getJPEGImage(75, 3, values.image_width, values.image_height, image, false, reward)) {
|
||||||
|
|
||||||
std::cout << "ERROR" << std::endl;
|
std::cout << "ERROR" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,22 +102,10 @@ namespace server {
|
||||||
|
|
||||||
void Protocol::LoadScene(Scene &scene, const Scene_Values &values) {
|
void Protocol::LoadScene(Scene &scene, const Scene_Values &values) {
|
||||||
std::vector<Vector2D> positions = values.possible_positions;
|
std::vector<Vector2D> positions = values.possible_positions;
|
||||||
|
|
||||||
|
|
||||||
/* std::cout << "POSSIBLE POSITIONS 3"<< std::endl;
|
|
||||||
|
|
||||||
for (int i=0; i<values.possible_positions.size(); ++i){
|
|
||||||
std::cout << " x: " << values.possible_positions[i].x << " y: " << values.possible_positions[i].y << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "POSSIBLE POSITIONS 4"<< std::endl;
|
|
||||||
*/
|
|
||||||
for (int i = 0; i < positions.size(); ++i) {
|
for (int i = 0; i < positions.size(); ++i) {
|
||||||
Scene::Position* point = scene.add_position();
|
Scene::Position* point = scene.add_position();
|
||||||
point->set_pos_x(positions[i].x);
|
point->set_pos_x(positions[i].x);
|
||||||
point->set_pos_y(positions[i].y);
|
point->set_pos_y(positions[i].y);
|
||||||
|
|
||||||
//std::cout << " x: " << point->pos_x() << " y: " << point->pos_y() << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_communication->GetMode() == Mode::STEREO) {
|
if (_communication->GetMode() == Mode::STEREO) {
|
||||||
|
|
|
@ -58,8 +58,8 @@ namespace carla {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPServer::writeString(const std::string &message, error_code &error) {
|
void TCPServer::writeString(const std::string &message, error_code &error) {
|
||||||
|
const int messageSize = static_cast<int>(message.length());
|
||||||
std::string outMessage(GetBytes(message.length()) + message);
|
std::string outMessage(GetBytes(messageSize) + message);
|
||||||
|
|
||||||
boost::asio::write(_socket, boost::asio::buffer(outMessage), error);
|
boost::asio::write(_socket, boost::asio::buffer(outMessage), error);
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ namespace carla {
|
||||||
_socket.close();
|
_socket.close();
|
||||||
_socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both);
|
_socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both);
|
||||||
_acceptor.cancel();*/
|
_acceptor.cancel();*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace server
|
} // namespace server
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
syntax = "proto2";
|
||||||
|
|
||||||
// Client Messages
|
// Client Messages
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,26 +1,8 @@
|
||||||
add_executable(test_async_server async_server.cpp)
|
add_executable(test_async_server async_server.cpp)
|
||||||
target_link_libraries(test_async_server
|
target_link_libraries(test_async_server ${CarlaServer_LIBRARIES})
|
||||||
carla_server
|
|
||||||
${Protobuf_LIBRARIES}
|
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
|
||||||
${Boost_DATE_TIME_LIBRARY}
|
|
||||||
${Boost_REGEX_LIBRARY}
|
|
||||||
${Boost_SYSTEM_LIBRARY})
|
|
||||||
|
|
||||||
add_executable(test_sync_server sync_server.cpp)
|
add_executable(test_sync_server sync_server.cpp)
|
||||||
target_link_libraries(test_sync_server
|
target_link_libraries(test_sync_server ${CarlaServer_LIBRARIES})
|
||||||
carla_server
|
|
||||||
${Protobuf_LIBRARIES}
|
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
|
||||||
${Boost_DATE_TIME_LIBRARY}
|
|
||||||
${Boost_REGEX_LIBRARY}
|
|
||||||
${Boost_SYSTEM_LIBRARY})
|
|
||||||
|
|
||||||
add_executable(test_client client.cpp)
|
add_executable(test_client client.cpp)
|
||||||
target_link_libraries(test_client
|
target_link_libraries(test_client ${CarlaServer_LIBRARIES})
|
||||||
carla_server
|
|
||||||
${Protobuf_LIBRARIES}
|
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
|
||||||
${Boost_DATE_TIME_LIBRARY}
|
|
||||||
${Boost_REGEX_LIBRARY}
|
|
||||||
${Boost_SYSTEM_LIBRARY})
|
|
||||||
|
|
|
@ -30,8 +30,8 @@ static std::string daytimeString() {
|
||||||
static std::vector<carla::Color> makeImage(uint32_t width, uint32_t height) {
|
static std::vector<carla::Color> makeImage(uint32_t width, uint32_t height) {
|
||||||
// Xisco's magic image generator.
|
// Xisco's magic image generator.
|
||||||
std::vector<unsigned char> img(width * height * 4);
|
std::vector<unsigned char> img(width * height * 4);
|
||||||
for (int i = 0; i < height; ++i) {
|
for (uint32_t i = 0; i < height; ++i) {
|
||||||
for (int e = 0; e < width; ++e) {
|
for (uint32_t e = 0; e < width; ++e) {
|
||||||
img[4 * width * i + 4 * e + 0] = 255 * !(e & i);
|
img[4 * width * i + 4 * e + 0] = 255 * !(e & i);
|
||||||
img[4 * width * i + 4 * e + 1] = e ^ i;
|
img[4 * width * i + 4 * e + 1] = e ^ i;
|
||||||
img[4 * width * i + 4 * e + 2] = e | i;
|
img[4 * width * i + 4 * e + 2] = e | i;
|
||||||
|
|
Loading…
Reference in New Issue