ctrl: write some broken sdl and imgui code
This commit is contained in:
parent
cd99af391f
commit
d6829aa9cd
4 changed files with 59 additions and 8 deletions
|
@ -6,7 +6,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
## Create binaries in the root of the build directory
|
## Create binaries in the root of the build directory
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "ON")
|
||||||
|
|
||||||
add_subdirectory(external)
|
add_subdirectory(external)
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
|
@ -6,6 +6,7 @@ target_compile_options(logc INTERFACE "-ffile-prefix-map=${CMAKE_SOURCE_DIR}=."
|
||||||
|
|
||||||
find_package(Threads)
|
find_package(Threads)
|
||||||
|
|
||||||
|
|
||||||
add_library(dp_common dp_common.c)
|
add_library(dp_common dp_common.c)
|
||||||
target_compile_features(dp_common PRIVATE c_std_11)
|
target_compile_features(dp_common PRIVATE c_std_11)
|
||||||
target_compile_options(dp_common PUBLIC "-Wall" "-Wextra")
|
target_compile_options(dp_common PUBLIC "-Wall" "-Wextra")
|
||||||
|
@ -15,10 +16,16 @@ target_link_libraries(dp_common
|
||||||
PUBLIC Threads::Threads
|
PUBLIC Threads::Threads
|
||||||
)
|
)
|
||||||
|
|
||||||
|
find_package(SDL2 REQUIRED)
|
||||||
|
|
||||||
add_executable(doompanning doompanning.cc)
|
add_executable(doompanning doompanning.cc)
|
||||||
target_compile_features(doompanning PRIVATE cxx_std_17)
|
target_compile_features(doompanning PRIVATE cxx_std_17)
|
||||||
|
#target_compile_options(doompanning PRIVATE ${IMGUI_CFLAGS})
|
||||||
|
#target_include_directories(doompanning PRIVATE ${IMGUI_INCLUDE_DIRS})
|
||||||
target_link_libraries(doompanning
|
target_link_libraries(doompanning
|
||||||
PRIVATE dp_common
|
PRIVATE dp_common
|
||||||
|
#PRIVATE ${IMGUI_LIBRARIES}
|
||||||
|
PRIVATE SDL2::SDL2-static
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(doomsim doomsim.cc)
|
add_executable(doomsim doomsim.cc)
|
||||||
|
|
|
@ -1,14 +1,36 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <nng/nng.h>
|
#include <nng/nng.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
//#include <imgui.h>
|
||||||
|
//#include <backends/imgui_impl_sdl.h>
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
#include "dp_common.h"
|
#include "dp_common.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
void dp_sdl_fatal(const char *const msg)
|
||||||
|
{
|
||||||
|
log_fatal("%s: %s", SDL_GetError());
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
static const size_t NumDooms = 3;
|
static const size_t NumDooms = 3;
|
||||||
|
|
||||||
int doom_controller_loop(nng_socket pubSock, nng_socket subSock)
|
int doom_controller_loop(nng_socket pubSock, nng_socket subSock, SDL_Window *window, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
|
bool done = false;
|
||||||
|
|
||||||
|
while (!done)
|
||||||
|
{
|
||||||
|
SDL_Event event;
|
||||||
|
while (SDL_PollEvent(&event))
|
||||||
|
{
|
||||||
|
if (event.type == SDL_QUIT)
|
||||||
|
done = true;
|
||||||
|
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +47,29 @@ int main(int argc, char *argv[])
|
||||||
auto pubSock = make_ctrl_pub(CtrlUrl);
|
auto pubSock = make_ctrl_pub(CtrlUrl);
|
||||||
auto subSock = make_ctrl_sub(DoomUrl);
|
auto subSock = make_ctrl_sub(DoomUrl);
|
||||||
|
|
||||||
int ret = doom_controller_loop(pubSock, subSock);
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER))
|
||||||
|
dp_sdl_fatal("SDL_Init");
|
||||||
|
|
||||||
|
#ifdef SDL_HINT_IME_SHOW_UI
|
||||||
|
SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const auto windowFlags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;
|
||||||
|
auto window = SDL_CreateWindow("doompanning", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, windowFlags);
|
||||||
|
if (!window)
|
||||||
|
dp_sdl_fatal("SDL_CreateWindow");
|
||||||
|
|
||||||
|
auto renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
|
||||||
|
|
||||||
|
if (!renderer)
|
||||||
|
dp_sdl_fatal("SDL_CreateRenderer");
|
||||||
|
|
||||||
|
//IMGUI_CHECKVERSION();
|
||||||
|
//ImGui::CreateContext();
|
||||||
|
//ImGui::StyleColorsDark();
|
||||||
|
//ImGui_ImplSDL2_InitForSDLRenderer(window);
|
||||||
|
|
||||||
|
int ret = doom_controller_loop(pubSock, subSock, window, renderer);
|
||||||
|
|
||||||
nng_close(pubSock);
|
nng_close(pubSock);
|
||||||
nng_close(subSock);
|
nng_close(subSock);
|
||||||
|
|
|
@ -102,14 +102,14 @@ DEF_DOOM_STATE_FUNC(do_doom_running)
|
||||||
{
|
{
|
||||||
assert(ctx->state == DP_DS_Running);
|
assert(ctx->state == DP_DS_Running);
|
||||||
|
|
||||||
// Read and handle input messages
|
// Non-blocking receive of incoming messages.
|
||||||
|
// Check if we should quit.
|
||||||
|
// Handle incoming input.
|
||||||
|
|
||||||
// Let doom render a new frame
|
// Let doom render a new frame
|
||||||
|
|
||||||
// Publish the frame
|
// Publish the frame
|
||||||
|
|
||||||
// Check if we should quit
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue