diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 69 | ||||
-rw-r--r-- | lib/libluajit.a | bin | 868920 -> 866936 bytes | |||
-rw-r--r-- | src/Script/entityx/entity_lua.cpp | 6 | ||||
-rw-r--r-- | src/Script/entityx/entity_lua.hpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 88 |
6 files changed, 122 insertions, 45 deletions
@@ -1,4 +1,6 @@ main out +.*.swp +.*.swo *.o @@ -3,6 +3,7 @@ # Script to build source files # # Copyright (C) 2019 Clyne Sullivan +# Copyright (C) 2019 Andy Belle-Isle # # 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 @@ -11,45 +12,67 @@ # # 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 +# 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 <https://www.gnu.org/licenses/>. +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# + +# +# VARIABLES # CC = gcc CXX = g++ +EXEC = main +EXECDIR = . + +SRCDIR = src +OUTDIR = out +SRCEXT = cpp +OBJEXT = o +DEPEXT = d + LIBDIR = lib -LIBS = -L$(LIBDIR) -lSDL2 -lpthread -lentityx -lluajit +LIBS = -L$(LIBDIR) -lSDL2 -lpthread -lentityx -ldl -lluajit -CXXFLAGS = -ggdb -std=c++17 \ - -Wall -Wextra -Werror -pedantic \ - -Isrc -I$(LIBDIR)/LuaJIT -I$(LIBDIR)/entityx/entityx -I$(LIBDIR)/entityx +CXXFLAGS = -ggdb -std=c++17 -Wall -Wextra -Werror -pedantic -CXXSRCDIR = src -CXXOUTDIR = out -CXXSRC = $(wildcard $(CXXSRCDIR)/*.cpp) $(wildcard $(CXXSRCDIR)/*/*.cpp) -CXXOBJ = $(patsubst $(CXXSRCDIR)/%.cpp, $(CXXOUTDIR)/%.o, $(CXXSRC)) +CXXINCS = -Isrc -I$(LIBDIR)/LuaJIT/src -I$(LIBDIR)/entityx -EXEC = main +CXXSRC := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) +CXXOBJ := $(patsubst $(SRCDIR)/%,$(OUTDIR)/%,$(CXXSRC:.$(SRCEXT)=.$(OBJEXT))) + +# +# COMPILE STUFF +# + +all: resources $(EXEC) + +resources: directories -all: $(EXEC) +directories: + @mkdir -p $(EXECDIR) + @mkdir -p $(OUTDIR) clean: - @echo " CLEAN" - @rm -f $(EXEC) - @rm -rf out + @$(RM) -rf $(OUTDIR) -$(EXEC): $(CXXOUTDIR) $(CXXOUTDIR)/$(CXXOBJ) - @echo " CXX/LD main" - @$(CXX) $(CXXFLAGS) -o $(EXEC) $(CXXOBJ) $(LIBS) +cleaner: clean + @$(RM) -rf $(EXECDIR) -$(CXXOUTDIR)/%.o: $(CXXSRCDIR)/%.cpp - @echo " CXX " $< - @$(CXX) $(CXXFLAGS) -c $< -o $@ +$(EXEC): $(CXXOBJ) + $(CXX) -o $(EXECDIR)/$(EXEC) $^ $(LIBS) -$(CXXOUTDIR): - @mkdir $(CXXOUTDIR) +$(OUTDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT) + @mkdir -p $(dir $@) + $(CXX) $(CXXFLAGS) $(CXXINCS) -c -o $@ $< + @$(CXX) $(CXXFLAGS) $(INCDEP) -MM $(SRCDIR)/$*.$(SRCEXT) > $(OUTDIR)/$*.$(DEPEXT) + @cp -f $(OUTDIR)/$*.$(DEPEXT) $(OUTDIR)/$*.$(DEPEXT).tmp + @sed -e 's|.*:|$(OUTDIR)/$*.$(OBJEXT):|' < $(OUTDIR)/$*.$(DEPEXT).tmp > $(OUTDIR)/$*.$(DEPEXT) + @sed -e 's/.*://' -e 's/\\$$//' < $(OUTDIR)/$*.$(DEPEXT).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(OUTDIR)/$*.$(DEPEXT) + @rm -f $(OUTDIR)/$*.$(DEPEXT).tmp +.PHONY: all remake clean cleaner resources diff --git a/lib/libluajit.a b/lib/libluajit.a Binary files differindex 76c6fbe..c82e81c 100644 --- a/lib/libluajit.a +++ b/lib/libluajit.a diff --git a/src/Script/entityx/entity_lua.cpp b/src/Script/entityx/entity_lua.cpp index e62f040..b23628b 100644 --- a/src/Script/entityx/entity_lua.cpp +++ b/src/Script/entityx/entity_lua.cpp @@ -1,4 +1,7 @@ -#include "entityx_lua.h" +//#include "entityx_lua.h" +#include <Script/entityx/entity_lua.hpp> +#include <stdio.h> +#include <string.h> using namespace entityx::lua; ComponentList entityx::lua::components; @@ -62,7 +65,6 @@ void entityx::lua::setup_entityx_api(lua_State* L) // We don't need __gc for Entity::Id (with static_assert it is_trivially_destructible) ref_EntityId = luaL_ref(L, LUA_REGISTRYINDEX); - // Create global entityx table lua_newtable(L); diff --git a/src/Script/entityx/entity_lua.hpp b/src/Script/entityx/entity_lua.hpp index 034640a..bcad91c 100644 --- a/src/Script/entityx/entity_lua.hpp +++ b/src/Script/entityx/entity_lua.hpp @@ -5,7 +5,7 @@ #include <type_traits> #include <lua.hpp> -#include <entityx.h> +#include <entityx/entityx.h> #include <Script/entityx/LuaTypes.hpp> #include <Script/entityx/EntityLua.hpp> diff --git a/src/main.cpp b/src/main.cpp index 65d80a7..0597d48 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,8 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include <entityx.h> +#include <lua.hpp> +#include <entityx/entityx.h> #include <Script/entityx/entity_lua.hpp> #include <SDL2/SDL.h> @@ -29,19 +30,63 @@ #include <memory> #include <thread> -constexpr const char *title = "gamedev2"; -constexpr int width = 640; -constexpr int height = 480; +class Window { +private: + constexpr static const char *title = "gamedev2"; + constexpr static int width = 640; + constexpr static int height = 480; + + static std::unique_ptr<SDL_Window, void (*)(SDL_Window *)> window; + static SDL_GLContext context; + + static void destroyWindow(SDL_Window *w) { + SDL_GL_DeleteContext(context); + SDL_DestroyWindow(w); + } + +public: + static int init(void) { + if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) { + std::cerr << "SDL video failed to initialize: " + << SDL_GetError() << std::endl; + return -1; + } + + window.reset(SDL_CreateWindow(title, + SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + width, height, + SDL_WINDOW_OPENGL)); + + if (window.get() == nullptr) { + std::cerr << "SDL window creation failed: " + << SDL_GetError() << std::endl; + return -1; + } + + context = SDL_GL_CreateContext(window.get()); + + return 0; + } + + static void render(void) { + SDL_GL_SwapWindow(window.get()); + } +}; + +std::unique_ptr<SDL_Window, void (*)(SDL_Window *)> Window::window (nullptr, + Window::destroyWindow); +SDL_GLContext Window::context; std::atomic_bool shouldRun; static void renderLoop(void); static void logicLoop(void); +static void LuaTest(void); int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[]) { // Initialize SDL - if (SDL_Init(SDL_INIT_VIDEO) != 0) { + if (SDL_Init(0) != 0) { std::cerr << "SDL failed to initialize: " << SDL_GetError() << std::endl; return -1; @@ -49,16 +94,10 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[]) atexit(SDL_Quit); } - // Create our window - std::unique_ptr<SDL_Window, decltype(&SDL_DestroyWindow)> window - (SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, width, height, 0), SDL_DestroyWindow); + LuaTest(); - if (window.get() == nullptr) { - std::cerr << "SDL window creation failed: " << SDL_GetError() - << std::endl; - return -1; - } + // Create our window + Window::init(); // Start game shouldRun.store(true); @@ -71,11 +110,10 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[]) void renderLoop(void) { - using namespace std::chrono_literals; - - // TODO render - while (shouldRun.load()) - std::this_thread::sleep_for(100ms); + while (shouldRun.load()) { + Window::render(); + std::this_thread::yield(); + } } void logicLoop(void) @@ -101,3 +139,15 @@ void logicLoop(void) } } + +void LuaTest(void) +{ + using namespace entityx; + using namespace entityx::lua; + + lua_State* L = luaL_newstate(); + luaL_openlibs(L); + setup_entityx_api(L); + + lua_close(L); +} |