Skip to content

Commit

Permalink
finally we have a window
Browse files Browse the repository at this point in the history
  • Loading branch information
翟环宇 committed May 18, 2020
1 parent 4b94335 commit 116dcea
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
29 changes: 29 additions & 0 deletions SimViewer/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#include "App/App.hpp"


#include <Poco/Logger.h>
#include <Poco/AutoPtr.h>
#include <Poco/FileChannel.h>
#include <tera/Core/Logger.hpp>
#include <tera/Core/TeraSystem.hpp>


// alias tera::Logger
using tera::Logger;
using tera::TeraSystem;


/**
* @brief SimViewer Driver
Expand All @@ -13,7 +24,25 @@ int main(int argc, char const *argv[])
{
sv::App app;
{
using Poco::AutoPtr;
using Poco::FileChannel;
using Poco::Logger;
AutoPtr<FileChannel> pChannel(new FileChannel);
pChannel->setProperty("path", "sv.log");
pChannel->setProperty("rotation", "2 K");
pChannel->setProperty("archive", "timestamp");
Logger::root().setChannel(pChannel);

Logger& logger = Logger::get("svInfo");
tera::Logger::add("svInfo", logger);
}

// init tera system
TeraSystem::init(argv[0], "SimViewer");

Logger::info("------ TeraSystem init ------");

Logger::info("------ svMain() init ------");

return app.run(argc, argv);
}
10 changes: 8 additions & 2 deletions Tera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ find_library(glfw3
NAMES glfw3 HINTS ${GLFW_PATH}/lib
)
find_library(PocoFoundation
NAMES PocoFoundation HINTS ${POCO_PATH}/*lib*
NAMES PocoFoundation HINTS ${POCO_PATH}/lib
)
find_library(PocoUtil
NAMES PocoUtil HINTS ${POCO_PATH}/*lib*
NAMES PocoUtil HINTS ${POCO_PATH}/lib
)


message(STATUS "POCO_PATH: ${POCO_PATH}")
message(STATUS "PocoFoundation: ${PocoFoundation}")
message(STATUS "PocoUtil: ${PocoUtil}")
message(STATUS "glfw3: ${glfw3}")


if(NOT MSVC)
# set(CMAKE_C_FLAGS )
set(CMAKE_C_FLAGS_DEBUG "-Og -D_DEBUG -g")
Expand Down
4 changes: 2 additions & 2 deletions Tera/src/Core/TeraSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ std::string TeraSystem::m_exePath = "";

// callback for glfw errors
static void onErrorGlfwCb(int code, const char* mess)
{ Logger::error( Poco::format("glfw(code = %d): %s", code, mess) ); }
{ Logger::error( Poco::format("glfw(code = %d): %s", code, std::string(mess)) ); }


void TeraSystem::pollEvents()
Expand Down Expand Up @@ -49,13 +49,13 @@ void TeraSystem::init(const char* exeFileNameWPath, const char* projectName)
m_exePath = Poco::Path(exeFileNameWPath).absolute().parent().toString();

// init the glfw library
glfwSetErrorCallback(onErrorGlfwCb);
int result = glfwInit();
if (!result) {
Logger::fatal("could not init glfw, exiting");
errMsg( "GLFW initialization failed" );
}

glfwSetErrorCallback(onErrorGlfwCb);

m_sysInit = true;

Expand Down
25 changes: 24 additions & 1 deletion Tera/src/Core/WindowedApp.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "WindowedApp.hpp"
#include "Logger.hpp"
#include "TeraSystem.hpp"


#include <cstdlib>


Expand All @@ -18,12 +22,31 @@ WindowedApp::~WindowedApp()

int WindowedApp::run()
{
int winpos[2]{50, 50};
int winsize[2]{800, 600};

if (!Window::open(winpos[0], winpos[1], winsize[0], winsize[1], "Test Window", false))
{
Logger::error("Could not create window...");
return EXIT_FAILURE;
}

bool run_ = true;

if (run_)
{
while (true)
bool wasClosed = false;
while (pollEvents())
{
while(!isOpen())
{
TeraSystem::waitEvents();
wasClosed = true;
}
if (wasClosed)
{
continue;
}
/* code */
}
}
Expand Down

0 comments on commit 116dcea

Please sign in to comment.