diff options
author | Andy Belle-Isle <drumsetmonkey@gmail.com> | 2019-09-10 23:55:54 -0400 |
---|---|---|
committer | Andy Belle-Isle <drumsetmonkey@gmail.com> | 2019-09-10 23:55:54 -0400 |
commit | 2b095e30f7786526da9339ccada3aae7f2ab5df4 (patch) | |
tree | 2f1b89406e387308f7d59818963a14e0ed8c6858 /src | |
parent | 2349bd2ffdd7b312c4b13e5794f12d2b7613f3b4 (diff) |
Started world system
Diffstat (limited to 'src')
-rw-r--r-- | src/engine.cpp | 3 | ||||
-rw-r--r-- | src/main.cpp | 1 | ||||
-rw-r--r-- | src/physics.hpp | 2 | ||||
-rw-r--r-- | src/render.hpp | 6 | ||||
-rw-r--r-- | src/script.cpp | 8 | ||||
-rw-r--r-- | src/script.hpp | 8 | ||||
-rw-r--r-- | src/shader.hpp | 1 | ||||
-rw-r--r-- | src/texture.hpp | 3 | ||||
-rw-r--r-- | src/world.cpp | 58 | ||||
-rw-r--r-- | src/world.hpp | 78 |
10 files changed, 160 insertions, 8 deletions
diff --git a/src/engine.cpp b/src/engine.cpp index 66739ff..ecc6501 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -45,7 +45,8 @@ int Engine::init(void) systems.add<InputSystem>(); systems.add<PlayerSystem>(entities); systems.add<RenderSystem>(); - systems.add<ScriptSystem>(entities); + systems.add<WorldSystem>(); + systems.add<ScriptSystem>(entities, *(systems.system<WorldSystem>().get())); systems.add<PhysicsSystem>(); systems.configure(); diff --git a/src/main.cpp b/src/main.cpp index a0632fd..5f39d95 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,6 +18,7 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ +#define GLEW_STATIC #define SOL_ALL_SAFETIES_ON = 1 #include "engine.hpp" diff --git a/src/physics.hpp b/src/physics.hpp index 63443c4..8231d6d 100644 --- a/src/physics.hpp +++ b/src/physics.hpp @@ -1,6 +1,6 @@ /** * @file position.hpp - * Manages all Lua scripts. + * Manages all entity movements * * Copyright (C) 2019 Belle-Isle, Andrew <drumsetmonkey@gmail.com> * diff --git a/src/render.hpp b/src/render.hpp index 0e4275e..8dcb434 100644 --- a/src/render.hpp +++ b/src/render.hpp @@ -22,11 +22,11 @@ #ifndef SYSTEM_RENDER_HPP_ #define SYSTEM_RENDER_HPP_ -#include "shader.hpp" - #include <entityx/entityx.h> +#include <GL/glew.h> #include <SDL2/SDL.h> +#include <SDL2/SDL_opengl.h> #define GLM_FORCE_RADIANS #include <glm/glm.hpp> @@ -34,6 +34,8 @@ #include <glm/gtc/type_ptr.hpp> #include <glm/gtc/noise.hpp> +#include "shader.hpp" + class RenderSystem : public entityx::System<RenderSystem> { private: diff --git a/src/script.cpp b/src/script.cpp index a6f0968..e3aca3e 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -87,9 +87,12 @@ void ScriptSystem::doFile(void) void ScriptSystem::scriptExport(void) { - std::function<sol::table(sol::table)> func = + std::function<sol::table(sol::table)> entitySpawn = [this](sol::table t){ return spawn(t);}; + std::function<unsigned int(sol::object)> worldRegister = + [this](sol::object t){ return worldSystem.addWorld(t); }; + lua.new_usertype<Position>("Position", sol::constructors<Position(double x, double y), Position()>(), "x", &Position::x, @@ -125,7 +128,8 @@ void ScriptSystem::scriptExport(void) "standing", &Physics::standing); auto gamespace = lua["game"].get_or_create<sol::table>(); - gamespace.set_function("spawn", func); + gamespace.set_function("spawn", entitySpawn); + gamespace.set_function("worldRegister", worldRegister); } sol::table ScriptSystem::spawn(sol::object param) diff --git a/src/script.hpp b/src/script.hpp index d4e2234..5c4c780 100644 --- a/src/script.hpp +++ b/src/script.hpp @@ -24,6 +24,8 @@ #include <entityx/entityx.h> #include <sol/sol.hpp> +#include "world.hpp" + struct EntitySpawnEvent { sol::object ref; @@ -47,10 +49,12 @@ private: sol::state lua; entityx::EntityManager& manager; + + WorldSystem &worldSystem; public: - ScriptSystem(entityx::EntityManager& _manager): - manager(_manager) {} + ScriptSystem(entityx::EntityManager& _mg, WorldSystem& _ws): + manager(_mg), worldSystem(_ws) {} ~ScriptSystem(void) {} diff --git a/src/shader.hpp b/src/shader.hpp index 8691ab0..2a93f9c 100644 --- a/src/shader.hpp +++ b/src/shader.hpp @@ -24,6 +24,7 @@ #include <unordered_map> #include <GL/glew.h> +#include <SDL2/SDL_opengl.h> class Shader { diff --git a/src/texture.hpp b/src/texture.hpp index 16987f8..4483d0f 100644 --- a/src/texture.hpp +++ b/src/texture.hpp @@ -21,7 +21,10 @@ #define TEXTURE_HPP_ #include <soil/SOIL.h> + +#include <GL/glew.h> #include <SDL2/SDL_opengl.h> + #include <string> class Texture diff --git a/src/world.cpp b/src/world.cpp new file mode 100644 index 0000000..8b71316 --- /dev/null +++ b/src/world.cpp @@ -0,0 +1,58 @@ +/** + * @file world.cpp + * + * Copyright (C) 2019 Belle-Isle, Andrew <drumsetmonkey@gmail.com> + * Author: Belle-Isle, Andrew <drumsetmonkey@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "world.hpp" + +/***************** +* WORLD CLASS * +*****************/ +World::World(sol::object ref) +{ + if (ref.get_type() == sol::type::table) { + + } else { + // TODO better logging + std::cerr << "World paramaters must be stored in a table" << std::endl; + } +} + + +/****************** +* WORLD SYSTEM * +******************/ + +unsigned int WorldSystem::addWorld(sol::object t) +{ + worlds.push_back(World(t)); + return worlds.size()-1; +} + +void WorldSystem::configure([[maybe_unused]]entityx::EntityManager& entities, + [[maybe_unused]]entityx::EventManager& events) +{ + +} + +void WorldSystem::update([[maybe_unused]]entityx::EntityManager& entities, + [[maybe_unused]]entityx::EventManager& events, + [[maybe_unused]]entityx::TimeDelta dt) +{ + +} diff --git a/src/world.hpp b/src/world.hpp new file mode 100644 index 0000000..7c66e6b --- /dev/null +++ b/src/world.hpp @@ -0,0 +1,78 @@ +/** + * @file world.hpp + * Manages the world systems + * + * Copyright (C) 2019 Belle-Isle, Andrew <drumsetmonkey@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SYSTEM_WORLD_HPP_ +#define SYSTEM_WORLD_HPP_ + +#include <vector> + +#include <entityx/entityx.h> +#include <sol/sol.hpp> + +#include "texture.hpp" + +struct WorldMaterial +{ + Texture texture; + Texture normal; +}; + +class World +{ +private: + std::vector<unsigned int> registry; + std::vector<std::vector<unsigned int>> worldData; +public: + World(sol::object ref); + ~World() {} +}; + +/** + * @class WorldSystem + * Handles the game's world system + */ +class WorldSystem : public entityx::System<WorldSystem> +{ +private: + std::vector<World> worlds; + //World& currentWorld; +public: + WorldSystem(void) {} + + ~WorldSystem(void) {} + + unsigned int addWorld(sol::object); + + /** + * Prepares the system for running. + */ + void configure(entityx::EntityManager& entities, + entityx::EventManager& events) final; + + /** + * Updates the world ticks (entity spawns and world events) + */ + void update(entityx::EntityManager& entites, + entityx::EventManager& events, + entityx::TimeDelta dt) final; +}; + +#endif // SYSTEM_WORLD_HPP_ + |