start work on rendering

This commit is contained in:
hippoz 2021-04-12 18:04:25 +03:00
parent 08b29ea864
commit 7206c53f8e
No known key found for this signature in database
GPG key ID: 7C52899193467641
8 changed files with 121 additions and 57 deletions

View file

@ -1,14 +1,28 @@
#ifndef _GAME_H
#define _GAME_H
#include <Components/TopLevel/GameObject.hpp>
#include <Components/TopLevel/Game.hpp>
#include <vendor/LuaBridge3/Source/LuaBridge/LuaBridge.h> // Pain
struct Game : public GameObject {
Game() : GameObject("game") {
std::cout << "[+] Game" << '\n';
}
bool isGame();
bool isGame() {
return true;
}
};
void registerGame(lua_State* L);
void registerGame(lua_State* L) {
luabridge::getGlobalNamespace (L)
.beginNamespace ("Core")
.deriveClass <Game, GameObject> ("Game")
.addFunction ("isGame", &Game::isGame)
.endClass ()
.endNamespace ();
}
#endif

View file

@ -10,6 +10,10 @@ extern "C" {
#include <lauxlib.h>
}
#include <Components/TopLevel/GameObject.hpp>
#include <vendor/LuaBridge3/Source/LuaBridge/LuaBridge.h> // Pain
#include <vendor/LuaBridge3/Source/LuaBridge/Vector.h> // Pain
struct GameObject {
GameObject(std::string name) : name(name) {}
@ -20,11 +24,35 @@ struct GameObject {
std::vector<GameObject*> children;
std::map<std::string, std::function<void()>> handlers;
GameObject& Get(std::string name);
void Add(GameObject* obj);
std::vector<GameObject*>& GetChildren();
std::vector<GameObject*>& GetChildren() {
return this->children;
}
GameObject& Get(std::string name) {
// NOTE(hippoz): This is a mess.
// I should be using find_if, not a loop
for (int i = this->children.size()-1; i >= 0; i--) {
if (this->children[i]->name == name) {
return *this->children[i];
}
}
}
void Add(GameObject* gameObject) {
this->children.push_back(gameObject);
}
};
void registerGameObject(lua_State* L);
void registerGameObject(lua_State* L) {
luabridge::getGlobalNamespace (L)
.beginNamespace ("Core")
.beginClass <GameObject> ("GameObject")
.addProperty ("name", &GameObject::name)
.addFunction ("GetChildren", &GameObject::GetChildren)
.addFunction ("Add", &GameObject::Add)
.addFunction ("Get", &GameObject::Get)
.endClass ()
.endNamespace ();
}
#endif

View file

@ -0,0 +1,12 @@
#ifndef _WORLD_H
#define _WORLD_H
struct World : public GameObject {
Game() : GameObject("World") {}
void addRenderCandidate();
};
void registerWorld(lua_State* L);
#endif

View file

@ -0,0 +1,41 @@
#ifndef _CUBE_H
#define _CUBE_H
#define DIGRAPHENE_GRAPHICS_BUFFER_IMPLEMENTATION
#define DIGRAPHENE_GRAPHICS_CAMERA_IMPLEMENTATION
#define DIGRAPHENE_GRAPHICS_MESH_IMPLEMENTATION
#define DIGRAPHENE_GRAPHICS_SHADER_IMPLEMENTATION
#include <Components/World/Renderable.cpp>
#include <vendor/digraphene-headers/graphics/buffer.h>
#include <vendor/digraphene-headers/graphics/camera.h>
#include <vendor/digraphene-headers/graphics/mesh.h>
#include <vendor/digraphene-headers/graphics/shader.h>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iostream>
// Using this allows us to pass a vector or matrix
// from linalg to something like std::cout
using namespace linalg::ostream_overloads;
using namespace Digraphene;
struct Cube : public Renderable {
Game() : GameObject("Cube") {}
void render() {
}
};
void registerCube(lua_State* L) {
luabridge::getGlobalNamespace(L)
.beginNamespace("Core")
.deriveClass <Cube, GameObject> ("Cube").endClass()
.endNamespace();
}
#endif

View file

@ -0,0 +1,19 @@
#ifndef _RENDERABLE_H
#define _RENDERABLE_H
#include <Components/World/GameObject.cpp>
struct Renderable : public GameObject {
Game() : GameObject("Renderable") {}
virtual void render();
};
void registerRenderable(lua_State* L) {
luabridge::getGlobalNamespace(L)
.beginNamespace("Core")
.deriveClass <Renderable, GameObject> ("Renderable").endClass()
.endNamespace();
}
#endif

1
include/vendor/digraphene-headers vendored Submodule

@ -0,0 +1 @@
Subproject commit cce6b8dc39bf63d13cb01f0bb5ad4d82164da016

View file

@ -1,17 +0,0 @@
#include <Components/TopLevel/GameObject.hpp>
#include <Components/TopLevel/Game.hpp>
#include <vendor/LuaBridge3/Source/LuaBridge/LuaBridge.h> // Pain
bool Game::isGame() {
return true;
}
void registerGame(lua_State* L) {
luabridge::getGlobalNamespace (L)
.beginNamespace ("Core")
.deriveClass <Game, GameObject> ("Game")
.addFunction ("isGame", &Game::isGame)
.endClass ()
.endNamespace ();
}

View file

@ -1,34 +0,0 @@
#include <Components/TopLevel/GameObject.hpp>
#include <vendor/LuaBridge3/Source/LuaBridge/LuaBridge.h> // Pain
#include <vendor/LuaBridge3/Source/LuaBridge/Vector.h> // Pain
std::vector<GameObject*>& GameObject::GetChildren() {
return this->children;
}
GameObject& GameObject::Get(std::string name) {
// NOTE(hippoz): This is a mess.
// I should be using find_if, not a loop
for (int i = this->children.size()-1; i >= 0; i--) {
if (this->children[i]->name == name) {
return *this->children[i];
}
}
}
void GameObject::Add(GameObject* gameObject) {
this->children.push_back(gameObject);
}
void registerGameObject(lua_State* L) {
luabridge::getGlobalNamespace (L)
.beginNamespace ("Core")
.beginClass <GameObject> ("GameObject")
.addProperty ("name", &GameObject::name)
.addFunction ("GetChildren", &GameObject::GetChildren)
.addFunction ("Add", &GameObject::Add)
.addFunction ("Get", &GameObject::Get)
.endClass ()
.endNamespace ();
}