Started working on the room system

This commit is contained in:
Kayne Ruse
2013-08-11 20:39:08 +10:00
commit 0a0b61287e
9 changed files with 217 additions and 0 deletions
+16
View File
@@ -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
+30
View File
@@ -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
}
+25
View File
@@ -0,0 +1,25 @@
#ifndef APPLICATION_HPP_
#define APPLICATION_HPP_
#include "threading.hpp"
#include <vector>
class Application {
public:
Application();
~Application();
void Init();
void Loop();
void Quit();
bool GetRunning() const { return running; }
private:
void NewRoom(/* args */);
std::vector<roomHandle> rooms;
bool running = true;
};
#endif
+28
View File
@@ -0,0 +1,28 @@
#include "application.hpp"
#include "SDL/SDL.h"
#include <stdexcept>
#include <iostream>
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;
}
+36
View File
@@ -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
+26
View File
@@ -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
}
+18
View File
@@ -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
+23
View File
@@ -0,0 +1,23 @@
#include "threading.hpp"
#include <stdexcept>
#include <iostream>
int roomThread(void* ptr) {
#ifdef DEBUG
std::cout << "Opening room" << std::endl;
#endif
try {
reinterpret_cast<Room*>(ptr)->Init();
reinterpret_cast<Room*>(ptr)->Loop();
reinterpret_cast<Room*>(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;
}
+15
View File
@@ -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