Skip to content

oyagci/opfor-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

3D Engine

Game Engine in C++ and OpenGL.

Notable Features: - C++17 - OpenGL - PBR Renderering - Lua Scripting Support

Editor Screenshot 1

Editor Screenshot 2

Editor Screenshot 3

Examples

Creating a Component

#include "ecs/Component.h"

struct MyComponent : ecs::ComponentBase
{
  // Data fields ...
  int Health;
  float Speed;
  // ...
};

Creating an Entity

auto &engine = Engine::Instance();

/// Create an IEntity with components MeshComponent and TransformComponent and returns a non-owning pointer
auto object = engine.CreateEntity<MeshComponent, TransformComponent>();

Modifying an Entity

/// IEntity::GetAll returns a tuple with the components registered in the IEntity
auto [ mesh, transform ] = object->GetAll();

transform.position = glm::vec3(42.0f, 0.0f, 0.0f);
mesh->Set(transform);
// or (without type deduction)
mesh->Set<TransformComponent>(transform);

Creating a System

#include "ecs/System.hpp"

class MySystem : ecs::ComponentSystem
{
public:
  void OnUpdate(float) override
  {
    auto entities = GetEntities<MeshComponent, TransformComponent>();
    // Do your computations here...
  }
};

Instanciating a System

engine.CreateSystem<MySystem>();

Lua Scripting

This engine supports Lua scripting through a LuaScriptComponent you can attach on any entity

#include "components/LuaScriptComponent.hpp"

// [...]

auto myEntity = engine.CreateEntity<LuaScriptComponent>();

auto &luaScript = myEntity->Get<LuaScriptComponent>();
	luaScript.Runtime.Load("scripts/myScript.lua");
-- File: script/myScript.lua

-- This function is called on each frame
function onUpdate(deltaTime)
	io.write("Hello World!\n")
end

Build

Linux, macOS

meson build && ninja -C build

Dependencies

Common

glew
glfw3
FreeType
OpenGL
OpenAL

Linux

x11
xi
xrandr

(Light Bulb icon)[https://icons8.com/icons/set/blunt-bulb] icon by (Icons8)[https://icons8.com]

About

A toy game engine for learning purposes. ECS, C++17, OpenGL, reflection

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published