summaryrefslogtreecommitdiffstats
path: root/engine/include
diff options
context:
space:
mode:
authorancarola <raffaele.ancarola@epfl.ch>2018-11-17 22:46:15 +0100
committerancarola <raffaele.ancarola@epfl.ch>2018-11-17 22:46:15 +0100
commitce7b39f47a1112941b3579f6502dd4e950cb099a (patch)
tree1d2a46f7dde690415302539c989f21067f270324 /engine/include
downloadflatland-ce7b39f47a1112941b3579f6502dd4e950cb099a.tar.gz
flatland-ce7b39f47a1112941b3579f6502dd4e950cb099a.zip
initialization
Diffstat (limited to 'engine/include')
-rw-r--r--engine/include/flatactor.h36
-rw-r--r--engine/include/flatcollector.h45
-rw-r--r--engine/include/flatevent.h0
-rw-r--r--engine/include/flatland.h55
-rw-r--r--engine/include/flatlayer.h15
-rw-r--r--engine/include/flatlistener.h0
-rw-r--r--engine/include/flatmultispriter.h0
-rw-r--r--engine/include/flatobject.h33
-rw-r--r--engine/include/flatserial.h14
-rw-r--r--engine/include/flatsprite.h55
-rw-r--r--engine/include/flatspriter.h31
-rw-r--r--engine/include/flatsurface.h0
-rw-r--r--engine/include/flattask.h59
-rw-r--r--engine/include/flattrigger.h0
-rw-r--r--engine/include/flatwindow.h96
-rw-r--r--engine/include/focusable.h29
-rw-r--r--engine/include/serial/keyfocusable.h0
-rw-r--r--engine/include/serial/mousefocusable.h0
-rw-r--r--engine/include/types.h34
19 files changed, 502 insertions, 0 deletions
diff --git a/engine/include/flatactor.h b/engine/include/flatactor.h
new file mode 100644
index 0000000..2c8b92d
--- /dev/null
+++ b/engine/include/flatactor.h
@@ -0,0 +1,36 @@
+#ifndef __FLATACTOR_H__
+#define __FLATACTOR_H__
+
+#include "flatcollector.h"
+
+struct task_s;
+
+class FlatActor : public FlatCollector
+{
+ task_s * task;
+
+ // TODO, event binding
+ // TODO, serial binding
+
+public:
+
+ FlatActor(FlatCollector *parent = 0, bool evolving = false);
+
+ virtual ~FlatActor();
+
+ /* Evolution fields */
+
+ void evolve_task(void*);
+
+ virtual void evolve(float dt);
+
+ void setEvolving(bool flag);
+
+ bool isEvolving() const;
+
+ /* Surface fields */
+
+ virtual SDL_Surface * sdl_surface() = 0;
+};
+
+#endif
diff --git a/engine/include/flatcollector.h b/engine/include/flatcollector.h
new file mode 100644
index 0000000..ed9a824
--- /dev/null
+++ b/engine/include/flatcollector.h
@@ -0,0 +1,45 @@
+#ifndef __FLATCOLLECTOR_H__
+#define __FLATCOLLECTOR_H__
+
+#include "flatobject.h"
+#include <set>
+
+class FlatCollector : virtual public FlatObject
+{
+ FlatCollector * parent;
+
+ bool released;
+
+ std::set<FlatCollector*> children;
+
+public:
+
+ FlatCollector(FlatCollector *parent = 0);
+
+ virtual ~FlatCollector();
+
+ /* Ownership functions */
+
+ bool isReleased() const;
+
+ /* Release object from automatic ownership destruction */
+ void release();
+
+ void attach(FlatCollector*);
+ void detach(FlatCollector*);
+
+ void setParent(FlatCollector*);
+ void releaseParent();
+
+ FlatCollector * getParent();
+
+ bool isParentOf(FlatCollector*) const;
+
+ std::set<FlatCollector*>::iterator begin();
+ std::set<FlatCollector*>::iterator end();
+
+ std::set<FlatCollector*>::const_iterator begin() const;
+ std::set<FlatCollector*>::const_iterator end() const;
+};
+
+#endif
diff --git a/engine/include/flatevent.h b/engine/include/flatevent.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/engine/include/flatevent.h
diff --git a/engine/include/flatland.h b/engine/include/flatland.h
new file mode 100644
index 0000000..18b1a89
--- /dev/null
+++ b/engine/include/flatland.h
@@ -0,0 +1,55 @@
+#ifndef __FLATLAND_H__
+#define __FLATLAND_H__
+
+class FlatWindow;
+
+typedef void (*gameloop)(float);
+
+struct flat_status
+{
+
+ flat_status(unsigned char video = 1,
+ unsigned char audio = 1,
+ unsigned char timer = 1,
+ unsigned char events = 1,
+ unsigned char joystick = 0,
+ unsigned char controller = 0,
+ unsigned char haptic = 0,
+ unsigned char error = 0,
+ unsigned char running = 0,
+ unsigned char loop = 0)
+
+ : video(video), audio(audio), timer(timer), events(events),
+ joystick(joystick), controller(controller), haptic(haptic),
+ error(error), running(running), loop(loop) {}
+
+ unsigned char video:1;
+ unsigned char audio:1;
+ unsigned char timer:1;
+ unsigned char joystick:1;
+ unsigned char controller:1;
+ unsigned char haptic:1;
+ unsigned char events:1;
+ unsigned char error:1;
+ unsigned char running:1;
+ unsigned char loop:1;
+};
+
+int init_flatland(const FlatWindow&, gameloop, const flat_status&, float fps = 60);
+void quit_flatland();
+
+/* Window and status accessors */
+
+FlatWindow * getFlatWindow();
+
+flat_status flatland_status();
+
+/* Window and status modifiers */
+
+void load_flatland_status(const flat_status&);
+
+/* Common defined variables */
+
+extern float flatland_dt;
+
+#endif
diff --git a/engine/include/flatlayer.h b/engine/include/flatlayer.h
new file mode 100644
index 0000000..f4f6734
--- /dev/null
+++ b/engine/include/flatlayer.h
@@ -0,0 +1,15 @@
+#ifndef __FLATLAYER_H__
+#define __FLATLAYER_H__
+
+#include "flatcollector.h"
+
+class FlatLayer : public FlatCollector
+{
+
+public:
+
+ FlatLayer(FlatLayer *parent);
+ ~FlatLayer();
+};
+
+#endif
diff --git a/engine/include/flatlistener.h b/engine/include/flatlistener.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/engine/include/flatlistener.h
diff --git a/engine/include/flatmultispriter.h b/engine/include/flatmultispriter.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/engine/include/flatmultispriter.h
diff --git a/engine/include/flatobject.h b/engine/include/flatobject.h
new file mode 100644
index 0000000..fe7b107
--- /dev/null
+++ b/engine/include/flatobject.h
@@ -0,0 +1,33 @@
+#ifndef __FLATOBJECT_H__
+#define __FLATOBJECT_H__
+
+#include <list>
+#include <vector>
+#include <initializer_list>
+
+#include "types.h"
+
+class FlatObject
+{
+ char id[32];
+
+ /* Common list of objects */
+ static std::list<FlatObject*> allObjects;
+
+public:
+
+ FlatObject();
+ ~FlatObject();
+
+ void setID(const char*);
+
+ const char* getID() const;
+
+ /* Static accessors to allObject */
+
+ static bool isAllocated(FlatObject*);
+
+ static std::vector<FlatObject*>& getByID(const char *id, std::vector<FlatObject*>&);
+};
+
+#endif
diff --git a/engine/include/flatserial.h b/engine/include/flatserial.h
new file mode 100644
index 0000000..b95413d
--- /dev/null
+++ b/engine/include/flatserial.h
@@ -0,0 +1,14 @@
+#ifndef __FLATSERIAL_H__
+#define __FLATSERIAL_H__
+
+/* SDL serial events handling */
+
+class Focusable;
+
+void process_events();
+
+void registerFocusable(Focusable*);
+
+void unregisterFocusable(Focusable*);
+
+#endif
diff --git a/engine/include/flatsprite.h b/engine/include/flatsprite.h
new file mode 100644
index 0000000..3fef3b3
--- /dev/null
+++ b/engine/include/flatsprite.h
@@ -0,0 +1,55 @@
+#ifndef __FLATSPRITE_H__
+#define __FLATSPRITE_H__
+
+#include "flatobject.h"
+#include <SDL2/SDL.h>
+
+class FlatSprite : public FlatObject
+{
+ SDL_Surface * surface;
+ SDL_Surface * parent;
+
+ SDL_Rect * offset;
+ SDL_Rect * viewport;
+
+ bool hide;
+
+public:
+
+ FlatSprite(const char *filename, Uint32 format = SDL_PIXELFORMAT_RGBA32, SDL_Surface *parent = 0);
+ FlatSprite(SDL_Surface *surface, SDL_Surface *parent = 0);
+
+ FlatSprite(const FlatSprite&);
+
+ ~FlatSprite();
+
+ void setOffset(int, int, int w = -1, int h = -1);
+
+ void setOffset(const SDL_Rect&);
+
+ void setViewport(int x = 0, int y = 0, int w = -1, int h = -1);
+
+ void setViewport(const SDL_Rect&);
+
+ const SDL_Rect * getOffset() const;
+
+ const SDL_Rect * getViewport() const;
+
+ void setParent(SDL_Surface *parent);
+
+ SDL_Surface * getParent();
+
+ SDL_Surface * getSurface();
+
+ void setHidden(bool);
+
+ bool isHidden() const;
+
+ void blit();
+
+ static SDL_Surface * loadOptimizedSurface(const char* filename, Uint32 format);
+
+ static SDL_Surface * copySurface(SDL_Surface*);
+};
+
+#endif
diff --git a/engine/include/flatspriter.h b/engine/include/flatspriter.h
new file mode 100644
index 0000000..0043272
--- /dev/null
+++ b/engine/include/flatspriter.h
@@ -0,0 +1,31 @@
+#ifndef __FLATSPRITER_H__
+#define __FLATSPRITER_H__
+
+#include "flatactor.h"
+
+class FlatSprite;
+
+class FlatSpriter : public FlatActor
+{
+ FlatSprite * sprite;
+
+public:
+
+ FlatSpriter(const char *filename, Uint32 format, FlatSpriter *parent = 0);
+ FlatSpriter(SDL_Surface *surface, FlatSpriter *parent = 0);
+ FlatSpriter(FlatSprite * sprite, FlatSpriter *parent = 0);
+
+ ~FlatSpriter();
+
+ /* Sprite modifiers */
+
+ FlatSprite * getSprite();
+
+ void setSprite(FlatSprite*);
+
+ FlatActor * getParent();
+
+ void setParent(FlatActor*);
+};
+
+#endif
diff --git a/engine/include/flatsurface.h b/engine/include/flatsurface.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/engine/include/flatsurface.h
diff --git a/engine/include/flattask.h b/engine/include/flattask.h
new file mode 100644
index 0000000..bb8c175
--- /dev/null
+++ b/engine/include/flattask.h
@@ -0,0 +1,59 @@
+#ifndef __FLAT_TASK_H__
+#define __FLAT_TASK_H__
+
+#include <list>
+
+class task_s
+{
+
+ /* Callback list */
+ static std::list<task_s*> tasks;
+
+public:
+
+ task_s()
+ {
+ /* Push into the public callback list */
+ tasks.push_back(this);
+ }
+
+ virtual ~task_s()
+ {
+ /* Remove from the public callback list */
+ tasks.remove(this);
+ }
+
+ virtual void exec() = 0;
+
+ /* Execute all tasks */
+ static void executeAll()
+ {
+ for (task_s * task : tasks)
+ task->exec();
+ }
+};
+
+
+template<class T>
+class FlatTask : public task_s
+{
+ typedef void (T::*callback_t)(void*);
+
+ T * object;
+ callback_t callback;
+
+ void * args;
+
+public:
+
+ FlatTask(T *object, callback_t callback, void* args)
+
+ : task_s(), object(object), callback(callback), args(args) {}
+
+ virtual void exec() override
+ {
+ (object->*callback)(args);
+ }
+};
+
+#endif
diff --git a/engine/include/flattrigger.h b/engine/include/flattrigger.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/engine/include/flattrigger.h
diff --git a/engine/include/flatwindow.h b/engine/include/flatwindow.h
new file mode 100644
index 0000000..f6645f6
--- /dev/null
+++ b/engine/include/flatwindow.h
@@ -0,0 +1,96 @@
+#ifndef __FLATWINDOW_H__
+#define __FLATWINDOW_H__
+
+#include <string>
+
+struct window_status
+{
+ window_status( unsigned char fullscreen = 0,
+ unsigned char hidden = 0,
+ unsigned char borderless = 0,
+ unsigned char resizable = 1,
+ unsigned char minimized = 0,
+ unsigned char maximized = 0,
+ unsigned char focus = 1)
+
+ : fullscreen(fullscreen), hidden(hidden), borderless(borderless),
+ resizable(resizable), minimized(minimized), maximized(maximized),
+ focus(focus) {}
+
+ unsigned char fullscreen:1;
+ unsigned char hidden:1;
+ unsigned char borderless:1;
+ unsigned char resizable:1;
+ unsigned char minimized:1;
+ unsigned char maximized:1;
+ unsigned char focus:1;
+};
+
+#include "flatobject.h"
+#include "focusable.h"
+
+class SDL_Window;
+class FlatLayer;
+
+class SDL_KeyEvent;
+
+class FlatWindow : public FlatObject, public Focusable
+{
+ std::string title;
+ window_status status;
+
+ SDL_Rect * bounds;
+ SDL_Window * sdl_window;
+ SDL_Surface * screen;
+
+ FlatLayer * main_layer;
+
+ void serial_cb(SDL_Event*) override;
+
+protected:
+
+ virtual void keyEvent(SDL_KeyEvent*);
+
+ virtual void quitEvent();
+
+public:
+
+ FlatWindow(int x, int y,
+ int width, int height,
+ const std::string& title,
+ window_status status = window_status());
+
+ FlatWindow( SDL_Rect *bounds, const std::string& title,
+ window_status status = window_status());
+
+ FlatWindow( int width, int height,
+ const std::string &title,
+ window_status status = window_status());
+
+ FlatWindow(const FlatWindow&);
+
+ ~FlatWindow();
+
+ int open();
+ void close();
+
+ int getWidth() const;
+ int getHeight() const;
+
+ const SDL_Rect * getBounds() const;
+
+ SDL_Window * getSDLWindow();
+ SDL_Surface * getScreenSurface();
+
+ const std::string& getTitle() const;
+
+ void setTitle(const std::string&);
+
+ window_status getWindowStatus() const;
+
+ void setWindowStatus(window_status);
+
+ static Uint32 winstatus_to_flags(window_status);
+};
+
+#endif
diff --git a/engine/include/focusable.h b/engine/include/focusable.h
new file mode 100644
index 0000000..6438ab8
--- /dev/null
+++ b/engine/include/focusable.h
@@ -0,0 +1,29 @@
+#ifndef __FOCUSABLE_H__
+#define __FOCUSABLE_H__
+
+union SDL_Event;
+
+class Focusable
+{
+ bool focused;
+
+public:
+
+ Focusable(bool focused = true)
+
+ : focused(focused) {}
+
+ virtual void serial_cb(SDL_Event *) = 0;
+
+ void setFocused(bool flag)
+ {
+ focused = flag;
+ }
+
+ bool isFocused() const
+ {
+ return focused;
+ }
+};
+
+#endif
diff --git a/engine/include/serial/keyfocusable.h b/engine/include/serial/keyfocusable.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/engine/include/serial/keyfocusable.h
diff --git a/engine/include/serial/mousefocusable.h b/engine/include/serial/mousefocusable.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/engine/include/serial/mousefocusable.h
diff --git a/engine/include/types.h b/engine/include/types.h
new file mode 100644
index 0000000..3141e6c
--- /dev/null
+++ b/engine/include/types.h
@@ -0,0 +1,34 @@
+#ifndef __TYPES_H__
+#define __TYPES_H__
+
+/* Flatland types */
+
+class FlatObject;
+
+class FlatActor;
+class FlatSprite;
+
+class Focusable;
+
+class KeyFocusable;
+class MouseFocusable;
+
+class FlatEvent;
+class EventListener;
+class Eventrigger;
+
+class FlatWindow;
+
+class FlatSpriter;
+class FlatMultiSpriter;
+
+/* SDL types */
+
+typedef unsigned int Uint32;
+
+struct SDL_Surface;
+struct SDL_Rect;
+
+union SDL_Event;
+
+#endif