Skip to content

KROIA/QSFML_EditorWidget

Repository files navigation

QSFML EditorWidget

About

QT_cmake_library_template This library was created using the library template

This library is used to create simulations or simple games. It doesn't have all the advanced features that a modern game engine supports, but it is designed to be simple and easy. The idea behind this project is to have a tool that can be used to create simulation environments for AI-based or physics simulations.

Features

  • Easy integration into a QT widget
  • GameObjects organized in a tree structure
  • Multi-threaded GameObject updates for complex scenes (if enabled)
  • GameObjects can be customized without creating an inherited class
  • Components allow you to add special functionality to a GameObject.
  • Collision detection for polygon shapes using Collider component.
  • Multiple camera views can be used in one scene.
  • Predefined Components ready to use.
  • Disable specific parts of the update loop for all or individual objects to speed up the engine
  • Dear Im Gui compatible
  • Built in performance profiler

Installation

This Project is CMake based, you need to install CMake and QT5 with the MSVC compiler. After that, download this repository and open the root CMakeLists.txt Project with Visual Studio.
CMake will automaticly download the dependencies for this library. After CMake has configured the Project, press build->install.
This will build all targets and copies the nessesarry QT dll's to the build directory.

Dependencies

Optional

How to use

Quickstart

#include <QApplication>
#include "QSFML_EditorWidget.h"

int main(int argc, char* argv[])
{
    QApplication a(argc, argv);
    // Create a QWidget to show the Scene in
    QWidget screenWidget;
    screenWidget.resize(500, 500);

    // Create the scene that holds all GameObjects
    QSFML::SceneSettings settings;
    settings.timing.frameTime = 0.03; // ms -> ~60 FPS
    QSFML::Scene scene(&screenWidget, settings);	

    // Create a editor GameObject, it creates a simple grid and manages 
    // camera movement.
    QSFML::Objects::DefaultEditor* editor = new QSFML::Objects::DefaultEditor("Editor", sf::Vector2f(1000, 800));
    scene.addObject(editor); // Add the object to the scene

    // Create a empty GameObject
    QSFML::Objects::GameObject* object = new QSFML::Objects::GameObject("MyObject");

    // Add a custom update lambda function to that empty GameObject
    object->addUpdateFunction([](QSFML::Objects::GameObject& obj)
    {
        // obj is a ref to it self, rotate it self a bit
        obj.rotate(obj.getDeltaT() * 50.f);
    });
    
    // Add a custom draw lambda function to the GameObject
    object->addDrawFunction([](const QSFML::Objects::GameObject& obj, sf::RenderTarget& target, sf::RenderStates states)
    {
        // Create a square to visualize the rotating object
        sf::RectangleShape shape(sf::Vector2f(400, 400));
        shape.setPosition(-200, -200);
        shape.setFillColor(sf::Color::Red);
        target.draw(shape, states);
    });

    // Add the GameObject to the scene
    scene.addObject(object);

    // Start the updat loop of the scene
    scene.start();
    screenWidget.show();
    return a.exec();
}

Visit the tutorials:

Icon Scene

Icon GameObject

Icon Component

Logger Logging to console

Profiler Profiling the application

ImGui Im Gui Integration

EA STL Using EA STL

About

A simple game enginge to create simulation projects

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages