Skip to content

Commit

Permalink
GLFW plugin, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bobke committed Feb 14, 2024
1 parent c3fbe34 commit bc1b1cc
Show file tree
Hide file tree
Showing 33 changed files with 1,025 additions and 251 deletions.
4 changes: 3 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ REQUIREMENTS

Qt6
Qwt (compiled against Qt6)
SDL
FGLW or SDL
glew
boost
glm
Expand All @@ -26,6 +26,8 @@ KEYS
F1 open admin window
F2 open control panel
F3 open system monitor
F11 toggle fullscreen
F12 toggle vsync

up move forward
down move backwards
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/be_entity_children_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "be_entity_id_handler.h"
#include "be_entity_io_handler.h"
// #include "be_lib_handler.h"
// #include <iostream>
#include <iostream>
// #include <sstream>


Expand Down
7 changes: 6 additions & 1 deletion src/kernel/be_entity_core_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@

bool BEntity_trigger::apply( BEntity* e )
{
// std::cout << "BEntity_trigger::apply : " << id() << std::endl;
// auto boolEntity = static_cast<BEntity_bool*>(e);
// if ( boolEntity )
// {
// std::cout << "BEntity_trigger::apply : " << id() << std::endl;
// return boolEntity->set( !boolEntity->get_bool() );
// }
return e->set();
}

Expand Down
8 changes: 4 additions & 4 deletions src/kernel/be_entity_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "be_entity_children_handler.h"
#include "be_lib_handler.h"
// #include <iostream>
#include <iostream>
// #include <sstream>

BEntity::BEntity()
Expand Down Expand Up @@ -175,8 +175,7 @@
(void)id;
return 0;
}



// SET NAMED VALUES
bool BEntity::set( const Bstring& id, BEntity* value )
{
Expand Down Expand Up @@ -225,6 +224,7 @@
(void)id; (void)value; return false;
}


template <typename T>
bool BEntity::compareAndSetValue (T& original, T const& value)
{
Expand Down Expand Up @@ -700,7 +700,7 @@
const auto& end(children_vector.end());
for ( auto it(begin); it != end; ++it )
{
if ( (*it)->name() == name )
if ( std::string((*it)->name()) == std::string(name) )
{
return (*it);
}
Expand Down
1 change: 1 addition & 0 deletions src/kernel/be_entity_io_handler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "be_entity_io_handler.h"
#include "be_entity_core_types.h"
#include <iostream> // NOTE: KEEPING THIS ONE HERES SAVES 3 SECONDS COMPILE TIME

// CONSTRUCTORS / DESTRUCTOR

Expand Down
2 changes: 1 addition & 1 deletion src/kernel/be_entity_io_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define BE_ENTITY_IO_HANDLER_H_INCLUDED

#include <vector>
#include <iostream> // NOTE: KEEPING THIS ONE HERES SAVES 3 SECONDS COMPILE TIME
// #include <iostream> // NOTE: KEEPING THIS ONE HERES SAVES 3 SECONDS COMPILE TIME

class BEntity;
class BEInput;
Expand Down
65 changes: 65 additions & 0 deletions src/kernel/be_entity_top.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "be_entity_core_types.h"
#include <iostream>
#include <algorithm>
#include <array>
#include <sstream>

BEntityTop::BEntityTop(bool connection_type)
: m_processor(new BProcessor())
Expand Down Expand Up @@ -350,6 +352,54 @@
}
}

else if ( c->name() == "update_plugin" )
{
auto plugin = dynamic_cast<BEntity_Plugin*>(c->get_reference());
if ( plugin )
{
if ( is_not_in_removed_entities( plugin ) )
{
auto location = plugin->m_location;
auto filename = plugin->m_filename;
auto name = plugin->name();

// RECOMPILE LIBRARY
std::cout << "recompiling: " << plugin->name() << std::endl;
std::stringstream cmd;
// cmd << "cd src && cd plugins && cd be_plugin_" << "test_editing" << " && time make" << std::endl;
std::cout << "cd " << plugin->m_location << " && time make -j8" << std::endl;
cmd << "cd " << plugin->m_location << " && time make -j8" << std::endl;

std::cout << exec( cmd.str().c_str() );

// // REMOVE LIB'S ENTITIES
// auto ent = getChild("bin")->getChild("test_editing");
// if ( ent )
// {
// std::cout << "removing entities" << std::endl;
// ent->parent()->removeChild(ent);
// }

// REMOVE LIBRARY
auto lib = getChild("lib", 1)->getChild(name.c_str(), 1);
if ( lib )
{
std::cout << "unloading library" << std::endl;
lib->parent()->removeChild(lib);
}

// RELOAD LIBRARY
std::cout << "loading library" << std::endl;
pluginManager()->load( name, location, filename );


//
// m_entitySave.saveEntity( entity, t_filename );
}
}
}


else
{
std::cout << "WARNING::unknown command: " << c->id() << " " << c->name() << std::endl;
Expand All @@ -376,6 +426,21 @@
}
}

std::string BEntityTop::exec(const char* cmd)
{
std::array<char, 128> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
if (!pipe) {
throw std::runtime_error("popen() failed!");
}
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result += buffer.data();
}
return result;
}


void BEntityTop::print( BEntity* entity, const Buint max_levels )
{
m_child_handler->print( entity, max_levels );
Expand Down
3 changes: 3 additions & 0 deletions src/kernel/be_entity_top.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
private:
BEntityCopy m_entityCopy;
BEntitySave m_entitySave;

// COMMAND EXEC
std::string exec(const char* cmd);
};


Expand Down
36 changes: 23 additions & 13 deletions src/kernel/be_lib_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@

BEntity_Plugin::~BEntity_Plugin()
{
m_create_plugin = 0;
m_destroy_plugin = 0;

#ifndef NDEBUG
// #ifndef NDEBUG
// NOTE COMMENTING THIS FIXES (<unknown module>) IN DEBUGGING
if ( m_sceneLibHandle != 0 )
dlclose(m_sceneLibHandle);
#endif
// #endif

m_create_plugin = 0;
m_destroy_plugin = 0;

}

void BEntity_Plugin::destroy( BEntity* e )
{
std::cout << "destroying" << std::endl;
e->clearChildren();
m_destroy_plugin( e );
}

const std::string& BEntity_Plugin::error() const
Expand All @@ -28,10 +36,14 @@

bool BEntity_Plugin::open( const std::string& dir, const std::string& lib )
{
if ( !open(dir+"/lib"+lib+".so") )
m_location = dir;
m_filename = lib;

if ( !open( m_location+"/lib"+m_filename+".so" ) )
{
std::cout << error() << std::endl;
exit(0);
// exit(1);
return false;
}
BEntity* e = addChild("Classes", new BEntity());
create(e, 0);
Expand Down Expand Up @@ -76,11 +88,6 @@
return m_create_plugin( parent, id ); // FIXME MEMLEAK
}

void BEntity_Plugin::destroy( BEntity* e )
{
e->clearChildren();
m_destroy_plugin( e );
}



Expand All @@ -92,7 +99,10 @@

BEntity_Plugin* t(new BEntity_Plugin());
addChild(name, t);
t->open( dir, lib );
if ( !t->open( dir, lib ) )
{
return 0;
}
return t;
}

Expand Down
6 changes: 4 additions & 2 deletions src/kernel/be_lib_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
bool open( const std::string& dir, const std::string& lib );
BEntity* create( BEntity* parent, const Buint id );
void destroy( BEntity* e );
void adminButtons( BEntity* hboxlayout, BEntity* plugin_manager ) { (void)hboxlayout; (void) plugin_manager; }
// void adminButtons( BEntity* hboxlayout, BEntity* plugin_manager ) { (void)hboxlayout; (void) plugin_manager; }
const std::string& error() const;
std::string m_filename;
std::string m_location;
private:
bool open( const std::string& location );
void* m_sceneLibHandle;
Expand All @@ -34,7 +36,7 @@
BEntity_Plugin* load( const std::string& name, const std::string& dir, const std::string& lib );
BEntity* create( BEntity* parent, const std::string& name );
BEntity* create( BEntity* parent, const std::string& library, const std::string& name );
void adminButtons( BEntity* hboxlayout, BEntity* plugin_manager ) { (void)hboxlayout; (void) plugin_manager; }
// void adminButtons( BEntity* hboxlayout, BEntity* plugin_manager ) { (void)hboxlayout; (void) plugin_manager; }
private:
};

Expand Down
4 changes: 3 additions & 1 deletion src/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
# ADD_SUBDIRECTORY(be_plugin_alsa)
# ADD_SUBDIRECTORY(be_plugin_app_alsa)
# ADD_SUBDIRECTORY(be_plugin_test)
# ADD_SUBDIRECTORY(be_plugin_test_editing)
# ADD_SUBDIRECTORY(be_plugin_app_attractors)
# ADD_SUBDIRECTORY(be_plugin_app_stunt_coureur)

# ADD_SUBDIRECTORY(be_plugin_opengl)
ADD_SUBDIRECTORY(be_plugin_opengl)
ADD_SUBDIRECTORY(be_plugin_opengl_modern)

ADD_SUBDIRECTORY(be_plugin_thread)
ADD_SUBDIRECTORY(be_plugin_qt6)
ADD_SUBDIRECTORY(be_plugin_system)
ADD_SUBDIRECTORY(be_plugin_bullet)
ADD_SUBDIRECTORY(be_plugin_sdl)
ADD_SUBDIRECTORY(be_plugin_glfw)
ADD_SUBDIRECTORY(be_plugin_brainz)
ADD_SUBDIRECTORY(be_plugin_qwt)

Expand Down
21 changes: 19 additions & 2 deletions src/plugins/be_plugin_app_admin_window/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@
// pluginManager()->load( "test", "src/plugins/be_plugin_test", "be_plugin_test" );
// pluginManager()->load( "sdl", "src/plugins/be_plugin_sdl", "be_plugin_sdl" );
// pluginManager()->load( "bullet", "src/plugins/be_plugin_bullet", "be_plugin_bullet" );

pluginManager()->load( "test_editing", "src/plugins/be_plugin_test_editing", "be_plugin_test_editing" );

pluginManager()->load( "system_monitor", "src/plugins/be_plugin_app_sysmon", "be_plugin_app_sysmon" );
// pluginManager()->load( "attractors", "src/plugins/be_plugin_app_attractors", "be_plugin_app_attractors" );
// pluginManager()->load( "critterding", "src/plugins/be_plugin_app_critterding", "be_plugin_app_critterding" );
pluginManager()->load( "critterding", "src/plugins/be_plugin_app_critterding", "be_plugin_app_critterding" );
pluginManager()->load( "stunt coureur", "src/plugins/be_plugin_app_stunt_coureur", "be_plugin_app_stunt_coureur" );

// SYSTEM MONITOR
// FIXME seems it hangs, multiple qt inits?
Expand Down Expand Up @@ -807,7 +810,7 @@
command->set(entity->get_reference());
}
}

// GRAPH FOR FLOAT
auto t_float = dynamic_cast<BEntity_float*>( entity );
if ( t_float )
Expand All @@ -820,6 +823,20 @@
auto command = actions->addChild("admin_entity_graph", new BEntity_reference() );
command->set(entity);
}

// RECOMPILE LIBRARY
auto t_plugin = dynamic_cast<BEntity_Plugin*>( entity );
if ( t_plugin )
{
auto button = to_layout->addChild("qt button", "QPushButton" );
button->set("text", "update");

// COMMAND
auto actions = button->addChild("_commands", new BEntity() );
auto command = actions->addChild("update_plugin", new BEntity_reference() );
command->set(entity);
}


}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/be_plugin_app_critterding/body_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@
// GRAPHICS
BEntity* graphics_transform(0);
// auto graphicsmodelsystem = body->topParent()->getChild("Scene", 1)->getChild("GraphicsModelSystem");
auto graphicsmodelsystem = body->topParent()->getChild("bin", 1)->getChild("Critterding", 1)->getChild("SDL GLWindow", 1)->getChild("GraphicsModelSystem", 1);
auto graphicsmodelsystem = body->topParent()->getChild("bin", 1)->getChild("Critterding", 1)->getChild("GLWindow", 1)->getChild("GraphicsModelSystem", 1);

if ( graphicsmodelsystem )
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/be_plugin_app_critterding/critter_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
m_minimum_number_of_units->set( Buint(20) );
m_intitial_energy->set( Bfloat(1500.0f) );
m_procreate_minimum_energy->set( Bfloat(2501.0f) );
m_maximum_age->set( Buint(16000) );
m_maximum_age->set( Buint(18000) );
m_dropzone_position_x->set( Bfloat(-100.0f) );
m_dropzone_position_y->set( Bfloat(-18.0f) );
m_dropzone_position_z->set( Bfloat(-170.0f) );
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/be_plugin_app_critterding/food_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@

// GRAPHICS ENTITY
BEntity* graphics_transform(0);
auto graphicsmodelsystem = topParent()->getChild("bin", 1)->getChild("Critterding", 1)->getChild("SDL GLWindow", 1)->getChild("GraphicsModelSystem", 1);
auto graphicsmodelsystem = topParent()->getChild("bin", 1)->getChild("Critterding", 1)->getChild("GLWindow", 1)->getChild("GraphicsModelSystem", 1);
if ( graphicsmodelsystem )
{
// LOAD MODEL IF NEEDED, ADD TRANSFORM
Expand Down
9 changes: 0 additions & 9 deletions src/plugins/be_plugin_app_critterding/opengl_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,4 @@
{
glDisable(GL_NORMALIZE);
}

// // FIXME MOVE TO CAMERA
// glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
//
// // glViewport( 0, 0, m_width->get_int(), m_height->get_int() );
// glViewport( 0, 0, 1224, 768 );

// glUseProgram(0);
}
1 change: 1 addition & 0 deletions src/plugins/be_plugin_app_critterding/opengl_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
OpenGL_Setup();
virtual ~OpenGL_Setup() {};
void construct();
const char* class_id() const { return "OpenGL_Setup"; }
void process();

private:
Expand Down
Loading

0 comments on commit bc1b1cc

Please sign in to comment.