Files @ r25014:e1f1bf3a062e
Branch filter:

Location: cpp/openttd-patchpack/source/cmake/LinkPackage.cmake

Patric Stout
Add: [Video] move GameLoop into its own thread

This allows drawing to happen while the GameLoop is doing an
iteration too.

Sadly, not much drawing currently can be done while the GameLoop
is running, as for example PollEvent() or UpdateWindows() can
influence the game-state. As such, they first need to acquire a
lock on the game-state before they can be called.

Currently, the main advantage is the time spend in Paint(), which
for non-OpenGL drivers can be a few milliseconds. For OpenGL this
is more like 0.05 milliseconds; in these instances this change
doesn't add any benefits for now.

This is an alternative to the former "draw-thread", which moved
the drawing in a thread for some OSes. It has similar performance
gain as this does, although this implementation allows for more
finer control over what suffers when the GameLoop takes too
long: drawing or the next GameLoop. For now they both suffer
equally.
function(link_package NAME)
    cmake_parse_arguments(LP "ENCOURAGED" "TARGET" "" ${ARGN})

    if(${NAME}_FOUND)
        string(TOUPPER "${NAME}" UCNAME)
        add_definitions(-DWITH_${UCNAME})
        # Some libraries' cmake packages (looking at you, SDL2) leave trailing whitespace in the link commands,
        # which (later) cmake considers to be an error. Work around this with by stripping the incoming string.
        if(LP_TARGET AND TARGET ${LP_TARGET})
            string(STRIP "${LP_TARGET}" LP_TARGET)
            target_link_libraries(openttd ${LP_TARGET})
            message(STATUS "${NAME} found -- -DWITH_${UCNAME} -- ${LP_TARGET}")
        else()
            string(STRIP "${${NAME}_LIBRARY}" ${NAME}_LIBRARY)
            string(STRIP "${${NAME}_LIBRARIES}" ${NAME}_LIBRARIES)
            include_directories(${${NAME}_INCLUDE_DIRS} ${${NAME}_INCLUDE_DIR})
            target_link_libraries(openttd ${${NAME}_LIBRARIES} ${${NAME}_LIBRARY})
            message(STATUS "${NAME} found -- -DWITH_${UCNAME} -- ${${NAME}_INCLUDE_DIRS} ${${NAME}_INCLUDE_DIR} -- ${${NAME}_LIBRARIES} ${${NAME}_LIBRARY}")
        endif()
    elseif(LP_ENCOURAGED)
        message(WARNING "${NAME} not found; compiling OpenTTD without ${NAME} is strongly disencouraged")
    endif()
endfunction()