start work on rendering
This commit is contained in:
parent
08b29ea864
commit
7206c53f8e
8 changed files with 121 additions and 57 deletions
|
@ -1,14 +1,28 @@
|
||||||
#ifndef _GAME_H
|
#ifndef _GAME_H
|
||||||
#define _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 {
|
struct Game : public GameObject {
|
||||||
Game() : GameObject("game") {
|
Game() : GameObject("game") {
|
||||||
std::cout << "[+] Game" << '\n';
|
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
|
#endif
|
|
@ -10,6 +10,10 @@ extern "C" {
|
||||||
#include <lauxlib.h>
|
#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 {
|
struct GameObject {
|
||||||
GameObject(std::string name) : name(name) {}
|
GameObject(std::string name) : name(name) {}
|
||||||
|
|
||||||
|
@ -20,11 +24,35 @@ struct GameObject {
|
||||||
std::vector<GameObject*> children;
|
std::vector<GameObject*> children;
|
||||||
std::map<std::string, std::function<void()>> handlers;
|
std::map<std::string, std::function<void()>> handlers;
|
||||||
|
|
||||||
GameObject& Get(std::string name);
|
std::vector<GameObject*>& GetChildren() {
|
||||||
void Add(GameObject* obj);
|
return this->children;
|
||||||
std::vector<GameObject*>& GetChildren();
|
}
|
||||||
|
|
||||||
|
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
|
#endif
|
12
include/Components/TopLevel/World.hpp
Normal file
12
include/Components/TopLevel/World.hpp
Normal 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
|
41
include/Components/World/Cube.hpp
Normal file
41
include/Components/World/Cube.hpp
Normal 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
|
19
include/Components/World/Renderable.hpp
Normal file
19
include/Components/World/Renderable.hpp
Normal 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
1
include/vendor/digraphene-headers
vendored
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit cce6b8dc39bf63d13cb01f0bb5ad4d82164da016
|
|
@ -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 ();
|
|
||||||
}
|
|
|
@ -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 ();
|
|
||||||
}
|
|
Reference in a new issue