From 0a0b61287e90ca512074039f597bb4e241318351 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 11 Aug 2013 20:39:08 +1000 Subject: [PATCH] Started working on the room system --- makefile | 16 ++++++++++++++++ server/application.cpp | 30 ++++++++++++++++++++++++++++++ server/application.hpp | 25 +++++++++++++++++++++++++ server/main.cpp | 28 ++++++++++++++++++++++++++++ server/makefile | 36 ++++++++++++++++++++++++++++++++++++ server/room.cpp | 26 ++++++++++++++++++++++++++ server/room.hpp | 18 ++++++++++++++++++ server/threading.cpp | 23 +++++++++++++++++++++++ server/threading.hpp | 15 +++++++++++++++ 9 files changed, 217 insertions(+) create mode 100644 makefile create mode 100644 server/application.cpp create mode 100644 server/application.hpp create mode 100644 server/main.cpp create mode 100644 server/makefile create mode 100644 server/room.cpp create mode 100644 server/room.hpp create mode 100644 server/threading.cpp create mode 100644 server/threading.hpp diff --git a/makefile b/makefile new file mode 100644 index 0000000..c8ac88a --- /dev/null +++ b/makefile @@ -0,0 +1,16 @@ +LIBDIR=lib +OUTDIR=out + +all: $(LIBDIR) $(OUTDIR) + $(MAKE) -C server + +$(LIBDIR): + mkdir $(LIBDIR) + +$(OUTDIR): + mkdir $(OUTDIR) + +clean: + $(RM) *.o *.a *.exe + +rebuild: clean all diff --git a/server/application.cpp b/server/application.cpp new file mode 100644 index 0000000..c20c99d --- /dev/null +++ b/server/application.cpp @@ -0,0 +1,30 @@ +#include "application.hpp" + +Application::Application() { + //TODO +} + +Application::~Application() { + //TODO +} + +void Application::Init() { + //TODO + + //disable this for debugging + running = false; +} + +void Application::Loop() { + while(running) { + //TODO + } +} + +void Application::Quit() { + //TODO +} + +void Application::NewRoom() { + //TODO +} diff --git a/server/application.hpp b/server/application.hpp new file mode 100644 index 0000000..3512973 --- /dev/null +++ b/server/application.hpp @@ -0,0 +1,25 @@ +#ifndef APPLICATION_HPP_ +#define APPLICATION_HPP_ + +#include "threading.hpp" + +#include + +class Application { +public: + Application(); + ~Application(); + + void Init(); + void Loop(); + void Quit(); + + bool GetRunning() const { return running; } +private: + void NewRoom(/* args */); + + std::vector rooms; + bool running = true; +}; + +#endif diff --git a/server/main.cpp b/server/main.cpp new file mode 100644 index 0000000..cf64f6c --- /dev/null +++ b/server/main.cpp @@ -0,0 +1,28 @@ +#include "application.hpp" + +#include "SDL/SDL.h" + +#include +#include + +using namespace std; + +int main(int, char**) { +#ifdef DEBUG + cout << "Beginning server" << endl; +#endif + try { + Application app; + app.Init(); + app.Loop(); + app.Quit(); + } + catch(exception& e) { + cerr << "Fatal error: " << e.what() << endl; + return 1; + } +#ifdef DEBUG + cout << "Clean exit" << endl; +#endif + return 0; +} diff --git a/server/makefile b/server/makefile new file mode 100644 index 0000000..fc62440 --- /dev/null +++ b/server/makefile @@ -0,0 +1,36 @@ +#config +LIB=-lmingw32 -lSDLmain -lSDL -llua +CXXFLAGS+=-std=c++11 -DDEBUG + +#source +SRC=$(wildcard *.cpp) + +#objects +OBJDIR=obj +OBJ=$(addprefix $(OBJDIR)/,$(SRC:.cpp=.o)) + +#output +OUTDIR=../out +OUT=$(addprefix $(OUTDIR)/,server) + +#targets +all: $(OBJ) $(OUT) + $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIB) + +$(OBJ): | $(OBJDIR) + +$(OUT): | $(OUTDIR) + +$(OBJDIR): + mkdir $(OBJDIR) + +$(OUTDIR): + mkdir $(OUTDIR) + +$(OBJDIR)/%.o: %.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +clean: + $(RM) *.o *.a *.exe + +rebuild: clean all diff --git a/server/room.cpp b/server/room.cpp new file mode 100644 index 0000000..c61fe24 --- /dev/null +++ b/server/room.cpp @@ -0,0 +1,26 @@ +#include "room.hpp" + +Room::Room() { + //TODO +} + +Room::~Room() { + //TODO +} + +void Room::Init() { + //TODO + + //disable this for debugging + running = false; +} + +void Room::Loop() { + while(running) { + //TODO + } +} + +void Room::Quit() { + //TODO +} diff --git a/server/room.hpp b/server/room.hpp new file mode 100644 index 0000000..8538438 --- /dev/null +++ b/server/room.hpp @@ -0,0 +1,18 @@ +#ifndef ROOM_HPP_ +#define ROOM_HPP_ + +class Room { +public: + Room(/* args */); + ~Room(); + + void Init(); + void Loop(); + void Quit(); + + bool GetRunning() const { return running; } +private: + bool running = true; +}; + +#endif diff --git a/server/threading.cpp b/server/threading.cpp new file mode 100644 index 0000000..0b83b9a --- /dev/null +++ b/server/threading.cpp @@ -0,0 +1,23 @@ +#include "threading.hpp" + +#include +#include + +int roomThread(void* ptr) { +#ifdef DEBUG + std::cout << "Opening room" << std::endl; +#endif + try { + reinterpret_cast(ptr)->Init(); + reinterpret_cast(ptr)->Loop(); + reinterpret_cast(ptr)->Quit(); + } + catch(std::exception& e) { + std::cerr << "Fatal room error: " << e.what() << std::endl; + return 1; + } +#ifdef DEBUG + std::cout << "Closing room" << std::endl; +#endif + return 0; +} diff --git a/server/threading.hpp b/server/threading.hpp new file mode 100644 index 0000000..630f88f --- /dev/null +++ b/server/threading.hpp @@ -0,0 +1,15 @@ +#ifndef THREADING_HPP_ +#define THREADING_HPP_ + +#include "room.hpp" + +#include "SDL/SDL_thread.h" + +struct roomHandle { + SDL_Thread* thread = nullptr; + Room* room = nullptr; +}; + +int roomThread(void*); + +#endif