Render loop works. There's nothing there, but it works.
This commit is contained in:
parent
7394df0f62
commit
597b7c26e4
@ -1,4 +1,6 @@
|
||||
#include "basic_types.hpp"
|
||||
#include "enums.hpp"
|
||||
#include "global_misc.hpp"
|
||||
#include "interop.hpp"
|
||||
#include "macros.hpp"
|
||||
#include "window_types.hpp"
|
||||
|
||||
@ -8,6 +8,9 @@ namespace sharp
|
||||
namespace internal
|
||||
{
|
||||
void add_window(window_base* win_ptr, size_t size);
|
||||
|
||||
void render_iter();
|
||||
void render_loop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
35
include/sharpsoft/interop.hpp
Normal file
35
include/sharpsoft/interop.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "macros.hpp"
|
||||
|
||||
#ifdef SH_PROS_ACTIVE
|
||||
#include "pros/rtos.hpp"
|
||||
#else
|
||||
#error Unsupported library. Interoperability cannot be used here.
|
||||
#endif
|
||||
|
||||
namespace sharp
|
||||
{
|
||||
class thread
|
||||
{
|
||||
private:
|
||||
void (*func)();
|
||||
bool active;
|
||||
|
||||
#ifdef SH_PROS_ACTIVE
|
||||
pros::Task* underlying;
|
||||
#endif
|
||||
|
||||
public:
|
||||
~thread();
|
||||
thread(void (*function)());
|
||||
|
||||
static void delay(int time_ms);
|
||||
|
||||
bool is_active() const;
|
||||
|
||||
void join();
|
||||
void start();
|
||||
void stop();
|
||||
};
|
||||
}
|
||||
3
include/sharpsoft/macros.hpp
Normal file
3
include/sharpsoft/macros.hpp
Normal file
@ -0,0 +1,3 @@
|
||||
#ifdef _PROS_INCLUDE_LIBLVGL_LLEMU_H
|
||||
#define SH_PROS_ACTIVE
|
||||
#endif
|
||||
@ -9,7 +9,7 @@ class test_window : public sharp::window_base
|
||||
protected:
|
||||
void paint() override
|
||||
{
|
||||
printf("Printed: %d", test_variable);
|
||||
printf("Printed: %d\n", test_variable);
|
||||
}
|
||||
|
||||
public:
|
||||
@ -29,7 +29,7 @@ void initialize()
|
||||
test_window moment = test_window();
|
||||
moment.test_variable = 3;
|
||||
|
||||
sharp::add_window(&moment);
|
||||
sharp::add_window(moment);
|
||||
sharp::start();
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
#include "pros/rtos.hpp"
|
||||
#define SHARPSOFT_INTERNAL
|
||||
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#include "sharpsoft/global_misc.hpp"
|
||||
#include "sharpsoft/internal.hpp"
|
||||
#include "sharpsoft/interop.hpp"
|
||||
|
||||
using namespace sharp;
|
||||
using std::vector;
|
||||
@ -16,12 +18,12 @@ const global_properties global_properties::defaults =
|
||||
bool init = false;
|
||||
bool started = false;
|
||||
color back_col;
|
||||
thread* render_thread = nullptr;
|
||||
|
||||
vector<window_base*> windows;
|
||||
|
||||
void sharp::initialize()
|
||||
{
|
||||
if (init) return;
|
||||
sharp::initialize(global_properties::defaults);
|
||||
}
|
||||
void sharp::initialize(const global_properties& props)
|
||||
@ -65,6 +67,24 @@ bool sharp::is_initialized()
|
||||
return init;
|
||||
}
|
||||
|
||||
void sharp::internal::render_iter()
|
||||
{
|
||||
int window_count = windows.size();
|
||||
for (int i = 0; i < window_count; i++)
|
||||
{
|
||||
window_base* win = windows.at(i);
|
||||
win->paint();
|
||||
}
|
||||
}
|
||||
void sharp::internal::render_loop()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
render_iter();
|
||||
thread::delay(100); // TODO: should be something else.
|
||||
}
|
||||
}
|
||||
|
||||
void sharp::internal::add_window(window_base* win_ptr, size_t size)
|
||||
{
|
||||
void* copy_raw = malloc(size);
|
||||
@ -74,17 +94,12 @@ void sharp::internal::add_window(window_base* win_ptr, size_t size)
|
||||
windows.push_back(copy);
|
||||
}
|
||||
|
||||
void sharp::test()
|
||||
{
|
||||
window_base* item = windows.at(0);
|
||||
item->paint();
|
||||
}
|
||||
|
||||
void sharp::start()
|
||||
{
|
||||
if (!init || started) return;
|
||||
|
||||
// TODO
|
||||
render_thread = new thread(internal::render_loop);
|
||||
render_thread->start();
|
||||
|
||||
started = true;
|
||||
}
|
||||
@ -92,7 +107,8 @@ void sharp::end()
|
||||
{
|
||||
if (!init || !started) return;
|
||||
|
||||
// TODO
|
||||
render_thread->stop();
|
||||
delete render_thread;
|
||||
|
||||
started = false;
|
||||
}
|
||||
|
||||
51
src/sharpsoft/threading.cpp
Normal file
51
src/sharpsoft/threading.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include "pros/rtos.hpp"
|
||||
#include "sharpsoft/interop.hpp"
|
||||
|
||||
using namespace sharp;
|
||||
|
||||
bool thread::is_active() const
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
#ifdef SH_PROS_ACTIVE
|
||||
void thread::delay(int time_ms)
|
||||
{
|
||||
pros::delay(time_ms);
|
||||
}
|
||||
|
||||
thread::thread(void (*function)())
|
||||
{
|
||||
active = false;
|
||||
func = function;
|
||||
underlying = nullptr;
|
||||
}
|
||||
|
||||
thread::~thread()
|
||||
{
|
||||
if (active) stop();
|
||||
}
|
||||
|
||||
void thread::join()
|
||||
{
|
||||
underlying->join();
|
||||
}
|
||||
|
||||
void thread::start()
|
||||
{
|
||||
if (active) return;
|
||||
|
||||
underlying = new pros::Task(func);
|
||||
|
||||
active = true;
|
||||
}
|
||||
void thread::stop()
|
||||
{
|
||||
if (!active) return;
|
||||
|
||||
underlying->remove();
|
||||
delete underlying;
|
||||
|
||||
active = false;
|
||||
}
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user