]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
Started world system
authorAndy Belle-Isle <drumsetmonkey@gmail.com>
Wed, 11 Sep 2019 03:55:54 +0000 (23:55 -0400)
committerAndy Belle-Isle <drumsetmonkey@gmail.com>
Wed, 11 Sep 2019 03:55:54 +0000 (23:55 -0400)
12 files changed:
Scripts/init.lua
Scripts/world.lua
src/engine.cpp
src/main.cpp
src/physics.hpp
src/render.hpp
src/script.cpp
src/script.hpp
src/shader.hpp
src/texture.hpp
src/world.cpp [new file with mode: 0644]
src/world.hpp [new file with mode: 0644]

index f177462021b5eb2a0464f61f693a8e0f8e1ce80a..78b2a7655f634ff01152561667518c9eadd834d9 100644 (file)
@@ -129,6 +129,9 @@ wall = {
     }
 }
 
+-- Create the world
+dofile("Scripts/world.lua")
+
 birdSpawn = game.spawn(bird);
 
 dogSpawn = game.spawn(cat);
@@ -156,8 +159,6 @@ game.spawn({
     end
 });
 
-dofile("Scripts/world.lua")
-
 -------------------
 --  SERIALIZING  --
 -------------------
index db0dc709e012f4acd5a120c384b9c2d824c41d3e..345a9b4ef14d35d710a285030e2d8990d6d723d3 100644 (file)
@@ -32,4 +32,5 @@ world = {
     end
 }
 
-world:Generate()
+--world:Generate()
+game.worldRegister(world)
index 66739ffef966c5ba4e6b0e076d197d74bbe82980..ecc6501e5b14f883a327a7958536b729e34e9e6d 100644 (file)
@@ -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();
 
index a0632fd925cc9e10b83bffe32209867d9be463e3..5f39d952cfb9538cb40bd7977676e2eb03ec6f78 100644 (file)
@@ -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"
index 63443c4cc65f4f100304f3edab3fb166cb4305c8..8231d6d2452edef3fb5a63a9ee6f16db360f75ef 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * @file position.hpp
- * Manages all Lua scripts.
+ * Manages all entity movements
  *
  * Copyright (C) 2019  Belle-Isle, Andrew <drumsetmonkey@gmail.com>
  *
index 0e4275ed310cf0fddae59198c9118c1b01fe1c4c..8dcb4349d9ca9f9eb77dbf1c3a8284cc27acd45b 100644 (file)
 #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:
index a6f0968e51507b250ca792f4f351222fcaca66b0..e3aca3ebb82d50381202c903c3f17e7dc9d617b6 100644 (file)
@@ -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)
index d4e22347248651e1d6721104c8ffbef35a22b6ce..5c4c78011efacff1f7310cd52559dcdf731b229a 100644 (file)
@@ -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) {}
 
index 8691ab04bd1f544d1df942f2fb3a482c42ee5d75..2a93f9cfe895fe505e7dc85b648e3e908d2e2faa 100644 (file)
@@ -24,6 +24,7 @@
 #include <unordered_map>
 
 #include <GL/glew.h>
+#include <SDL2/SDL_opengl.h>
 
 class Shader
 {
index 16987f84688bcbf5fd363ad84164e5890ee87e87..4483d0f6f9620c4077a9cfd16fd992d492a042d3 100644 (file)
 #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 (file)
index 0000000..8b71316
--- /dev/null
@@ -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 (file)
index 0000000..7c66e6b
--- /dev/null
@@ -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_
+