summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2019-01-25 02:54:54 +0100
committerNao Pross <naopross@thearcway.org>2019-01-25 02:54:54 +0100
commitf58dea71037dca847e373f6efbf75b6056f212ac (patch)
tree3b9b66379a583eb0b162418d037ec00b66e6bebc
parentUpdate configure.py to default build libflatland.{so, a} (diff)
downloadflatland-f58dea71037dca847e373f6efbf75b6056f212ac.tar.gz
flatland-f58dea71037dca847e373f6efbf75b6056f212ac.zip
It compiles! Probably super broken, but compiles!
-rw-r--r--engine/actor.cpp2
-rw-r--r--engine/collector.cpp1
-rw-r--r--engine/exception.cpp2
-rw-r--r--engine/flatland.cpp57
-rw-r--r--engine/focusable.cpp6
-rw-r--r--engine/include/actor.hpp4
-rw-r--r--engine/include/bound.hpp4
-rw-r--r--engine/include/collector.hpp4
-rw-r--r--engine/include/exception.hpp4
-rw-r--r--engine/include/exceptions/forcequit.hpp11
-rw-r--r--engine/include/flatland.hpp6
-rw-r--r--engine/include/layer.hpp17
-rw-r--r--engine/include/serial/focusable.hpp7
-rw-r--r--engine/include/serial/keyfocusable.hpp8
-rw-r--r--engine/include/serial/mousefocusable.hpp0
-rw-r--r--engine/include/types.hpp26
-rw-r--r--engine/include/window.hpp16
-rw-r--r--engine/keyfocusable.cpp2
-rw-r--r--engine/layer.cpp2
-rw-r--r--engine/serial.cpp10
-rw-r--r--engine/surface.cpp41
-rw-r--r--engine/window.cpp7
-rw-r--r--test/test1.cpp2
-rw-r--r--test/test2.cpp2
24 files changed, 110 insertions, 131 deletions
diff --git a/engine/actor.cpp b/engine/actor.cpp
index dd4bc96..8eb27da 100644
--- a/engine/actor.cpp
+++ b/engine/actor.cpp
@@ -2,6 +2,8 @@
#include "flatland.hpp"
+using namespace flat;
+
FlatActor::FlatActor(FlatCollector *parent, FlatBound *bounds)
: FlatCollector(parent), bounds(bounds)
diff --git a/engine/collector.cpp b/engine/collector.cpp
index 6365de2..3fc2a0e 100644
--- a/engine/collector.cpp
+++ b/engine/collector.cpp
@@ -1,6 +1,7 @@
#include "collector.hpp"
using namespace std;
+using namespace flat;
FlatCollector::FlatCollector(FlatCollector *parent)
diff --git a/engine/exception.cpp b/engine/exception.cpp
index 8dd70d6..d4f1a74 100644
--- a/engine/exception.cpp
+++ b/engine/exception.cpp
@@ -1,6 +1,8 @@
#include "exception.hpp"
#include <stdio.h>
+using namespace flat;
+
FlatException::FlatException(const char* error) : error(error) {}
FlatException::~FlatException() {}
diff --git a/engine/flatland.cpp b/engine/flatland.cpp
index 306d094..f761473 100644
--- a/engine/flatland.cpp
+++ b/engine/flatland.cpp
@@ -8,6 +8,7 @@
#include <ctime>
using namespace std;
+using namespace flat;
#include "core/task.hpp"
#include "core/signal.hpp"
@@ -20,7 +21,6 @@ float flatland_dt;
set<flat::core::object*> objects;
FlatWindow * window = 0;
-SignalChannel * core = 0;
gameloop loop_function;
@@ -57,33 +57,10 @@ uint32_t status_to_flags(const flat_status& s)
return flags;
}
-/* Listen to simple quit calls */
-class QuitListener : public FlatListener
-{
- virtual void callback(flat::core::object*, void*) override
- {
- /* Order to quit */
- quit_flatland();
- }
-
-public:
-
- QuitListener()
- {
- addFilter("quit");
- core->connect(this);
- }
-};
-
int init_flatland(FlatWindow* w, gameloop loop, const flat_status& s, float _fps)
{
cout << "Flatland: Initializing flatland" << endl;
- // Init core channel
-
- core = new SignalChannel("core");
- QuitListener quitter;
-
// init variables
cout << "Flatland: Initializing window" << endl;
@@ -130,17 +107,6 @@ int init_flatland(FlatWindow* w, gameloop loop, const flat_status& s, float _fps
try {
try {
-
- /* Execute tasks */
- task_s::executePreProcess();
-
- } catch (const exception &e) {
-
- cerr << "Flatland: exception thrown while executing pre-process tasks" << endl;
- cerr << e.what() << endl;
- }
-
- try {
/* Execute loop function */
loop_function(flatland_dt);
@@ -150,17 +116,6 @@ int init_flatland(FlatWindow* w, gameloop loop, const flat_status& s, float _fps
cerr << "Flatland: exception thrown while executing loop" << endl;
cerr << e.what() << endl;
}
-
- try {
-
- /* Execute tasks */
- task_s::executePostProcess();
-
- } catch (const exception &e) {
-
- cerr << "Flatland: exception thrown while executing post-process tasks" << endl;
- cerr << e.what() << endl;
- }
} catch (const ForceQuit& f) {
@@ -184,11 +139,6 @@ int init_flatland(FlatWindow* w, gameloop loop, const flat_status& s, float _fps
window->close();
- cout << "Flatland: destroying core channel" << endl;
-
- delete core;
- core = 0;
-
cout << "Flatland: quitting SDL" << endl;
SDL_Quit();
@@ -207,8 +157,3 @@ flat_status flatland_status()
return status;
}
-SignalChannel * getCoreChannel()
-{
- return core;
-}
-
diff --git a/engine/focusable.cpp b/engine/focusable.cpp
index 29a7274..cdf8b1f 100644
--- a/engine/focusable.cpp
+++ b/engine/focusable.cpp
@@ -2,14 +2,16 @@
#include "core/task.hpp"
#include "serial.hpp"
+using namespace flat;
+
Focusable::Focusable(bool focused) : focused(focused)
{
- event_trigger = new flat::core::task<Focusable>(this, &Focusable::serial_precall, 0);
+ // event_trigger = new flat::core::task<Focusable>(this, &Focusable::serial_precall, 0);
}
Focusable::~Focusable()
{
- delete event_trigger;
+ // delete event_trigger;
}
void Focusable::setFocused(bool flag)
diff --git a/engine/include/actor.hpp b/engine/include/actor.hpp
index b5a8285..75a3474 100644
--- a/engine/include/actor.hpp
+++ b/engine/include/actor.hpp
@@ -3,6 +3,8 @@
#include "collector.hpp"
+namespace flat {
+
class FlatBound;
class FlatActor : public FlatCollector
@@ -24,4 +26,6 @@ public:
FlatBound * getBounds() const;
};
+}
+
#endif
diff --git a/engine/include/bound.hpp b/engine/include/bound.hpp
index f5a2c0d..9b7b755 100644
--- a/engine/include/bound.hpp
+++ b/engine/include/bound.hpp
@@ -4,6 +4,8 @@
#include "object.hpp"
#include "svector.h"
+namespace flat {
+
typedef SVector<int, 2> pixel;
class FlatBound : virtual public flat::core::object
@@ -35,4 +37,6 @@ public:
}
};
+}
+
#endif
diff --git a/engine/include/collector.hpp b/engine/include/collector.hpp
index 5b1e718..bc50f4d 100644
--- a/engine/include/collector.hpp
+++ b/engine/include/collector.hpp
@@ -4,6 +4,8 @@
#include "core/object.hpp"
#include <set>
+namespace flat {
+
class FlatCollector : virtual public flat::core::object
{
FlatCollector * parent;
@@ -42,4 +44,6 @@ public:
std::set<FlatCollector*>::const_iterator end() const;
};
+}
+
#endif
diff --git a/engine/include/exception.hpp b/engine/include/exception.hpp
index 47eb272..6f578e8 100644
--- a/engine/include/exception.hpp
+++ b/engine/include/exception.hpp
@@ -3,6 +3,8 @@
#include <exception>
+namespace flat {
+
class FlatException : public std::exception
{
const char * error;
@@ -19,4 +21,6 @@ public:
virtual const char* what() const throw() override;
};
+}
+
#endif
diff --git a/engine/include/exceptions/forcequit.hpp b/engine/include/exceptions/forcequit.hpp
index 7b2b324..451190e 100644
--- a/engine/include/exceptions/forcequit.hpp
+++ b/engine/include/exceptions/forcequit.hpp
@@ -1,11 +1,12 @@
#ifndef __FORCE_QUIT_H__
#define __FORCE_QUIT_H__
-struct ForceQuit
-{
- const char * reason;
+namespace flat {
+ struct ForceQuit {
+ const char * reason;
- ForceQuit(const char *reason) : reason(reason) {}
-};
+ ForceQuit(const char *reason) : reason(reason) {}
+ };
+}
#endif
diff --git a/engine/include/flatland.hpp b/engine/include/flatland.hpp
index e01201f..331093b 100644
--- a/engine/include/flatland.hpp
+++ b/engine/include/flatland.hpp
@@ -28,10 +28,10 @@ struct flat_status
unsigned char video:1;
unsigned char audio:1;
unsigned char timer:1;
+ unsigned char events: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;
@@ -66,10 +66,6 @@ flat_status flatland_status();
void load_flatland_status(const flat_status&);
-/* Common defined variables */
-
-extern float flatland_dt;
-
}
#endif
diff --git a/engine/include/layer.hpp b/engine/include/layer.hpp
index c3294e4..c6ff0c9 100644
--- a/engine/include/layer.hpp
+++ b/engine/include/layer.hpp
@@ -3,13 +3,14 @@
#include "collector.hpp"
-class FlatLayer : public FlatCollector
-{
-
-public:
-
- FlatLayer(FlatLayer *parent);
- ~FlatLayer();
-};
+namespace flat {
+ class FlatLayer : public FlatCollector
+ {
+
+ public:
+ FlatLayer(FlatLayer *parent);
+ ~FlatLayer();
+ };
+}
#endif
diff --git a/engine/include/serial/focusable.hpp b/engine/include/serial/focusable.hpp
index 008f7a3..f139577 100644
--- a/engine/include/serial/focusable.hpp
+++ b/engine/include/serial/focusable.hpp
@@ -4,15 +4,14 @@
#include "core/object.hpp"
#include "types.hpp"
-class task_s;
union SDL_Event;
+namespace flat {
+
class Focusable : virtual public flat::core::object
{
bool focused;
- task_s * event_trigger;
-
protected:
/* Callback to event */
@@ -34,4 +33,6 @@ public:
void serial_precall(void*);
};
+}
+
#endif
diff --git a/engine/include/serial/keyfocusable.hpp b/engine/include/serial/keyfocusable.hpp
index e28e333..26f3ce2 100644
--- a/engine/include/serial/keyfocusable.hpp
+++ b/engine/include/serial/keyfocusable.hpp
@@ -5,6 +5,8 @@
struct SDL_KeyboardEvent;
+namespace flat {
+
class KeyFocusable : virtual public Focusable
{
@@ -15,10 +17,8 @@ class KeyFocusable : virtual public Focusable
protected:
virtual void key_cb(const SDL_KeyboardEvent*) = 0;
-
-public:
-
- using Focusable::Focusable;
};
+}
+
#endif
diff --git a/engine/include/serial/mousefocusable.hpp b/engine/include/serial/mousefocusable.hpp
deleted file mode 100644
index e69de29..0000000
--- a/engine/include/serial/mousefocusable.hpp
+++ /dev/null
diff --git a/engine/include/types.hpp b/engine/include/types.hpp
index 436cc7c..e7a1d3a 100644
--- a/engine/include/types.hpp
+++ b/engine/include/types.hpp
@@ -10,26 +10,24 @@ namespace flat
class object;
}
-}
-
-class FlatActor;
-class FlatSprite;
+ class FlatActor;
+ class FlatSprite;
-class Focusable;
+ class Focusable;
-class KeyFocusable;
-class MouseFocusable;
+ class KeyFocusable;
+ class MouseFocusable;
-class FlatEvent;
-class EventListener;
-class Eventrigger;
+ class FlatEvent;
+ class EventListener;
+ class Eventrigger;
-class FlatWindow;
+ class FlatWindow;
-class FlatSpriter;
-class FlatMultiSpriter;
+ class FlatSpriter;
+ class FlatMultiSpriter;
+}
-class task_s;
/* SDL types */
diff --git a/engine/include/window.hpp b/engine/include/window.hpp
index 7b3fa9a..98e8e04 100644
--- a/engine/include/window.hpp
+++ b/engine/include/window.hpp
@@ -1,8 +1,16 @@
#ifndef __FLATWINDOW_H__
#define __FLATWINDOW_H__
+#include "core/object.hpp"
+#include "serial/keyfocusable.hpp"
+
#include <string>
+class SDL_Window;
+class SDL_KeyEvent;
+
+namespace flat {
+
struct window_status
{
window_status( unsigned char fullscreen = 0,
@@ -26,15 +34,10 @@ struct window_status
unsigned char focus:1;
};
-#include "core/object.hpp"
-#include "serial/keyfocusable.hpp"
-class SDL_Window;
class FlatLayer;
-class SDL_KeyEvent;
-
-class FlatWindow : virtual public flat::core::object, public KeyFocusable
+class FlatWindow : virtual public core::object, public KeyFocusable
{
std::string title;
window_status status;
@@ -94,4 +97,5 @@ public:
static uint32_t winstatus_to_flags(window_status);
};
+}
#endif
diff --git a/engine/keyfocusable.cpp b/engine/keyfocusable.cpp
index 59e97b3..a46d03b 100644
--- a/engine/keyfocusable.cpp
+++ b/engine/keyfocusable.cpp
@@ -1,6 +1,8 @@
#include "serial/keyfocusable.hpp"
#include "SDL2/SDL.h"
+using namespace flat;
+
void KeyFocusable::serial_cb(const SDL_Event *event)
{
key_cb(&event->key);
diff --git a/engine/layer.cpp b/engine/layer.cpp
index 07a9270..a09d268 100644
--- a/engine/layer.cpp
+++ b/engine/layer.cpp
@@ -1,5 +1,7 @@
#include "layer.hpp"
+using namespace flat;
+
FlatLayer::FlatLayer(FlatLayer *parent)
{
diff --git a/engine/serial.cpp b/engine/serial.cpp
index fdbb79e..b3218be 100644
--- a/engine/serial.cpp
+++ b/engine/serial.cpp
@@ -1,19 +1,21 @@
#include "serial.hpp"
#include "core/task.hpp"
+using namespace flat;
+
SDL_EventCollector::SDL_EventCollector()
{
/* Checker task, pre-process, maximum priority */
- checker = new flat::core::task<SDL_EventCollector>(this, &SDL_EventCollector::collect, 0, true, 0);
+ // checker = new flat::core::task<SDL_EventCollector>(this, &SDL_EventCollector::collect, 0, true, 0);
/* Eraser task, post-process, minimum priority */
- eraser = new flat::core::task<SDL_EventCollector>(this, &SDL_EventCollector::erase, 0, false, 0xff);
+ // eraser = new flat::core::task<SDL_EventCollector>(this, &SDL_EventCollector::erase, 0, false, 0xff);
}
SDL_EventCollector::~SDL_EventCollector()
{
- delete checker;
- delete eraser;
+ // delete checker;
+ // delete eraser;
}
void SDL_EventCollector::collect(void*)
diff --git a/engine/surface.cpp b/engine/surface.cpp
index 2533022..31f6388 100644
--- a/engine/surface.cpp
+++ b/engine/surface.cpp
@@ -3,12 +3,13 @@
#include <iostream>
using namespace std;
+using namespace flat;
-FlatSurface::FlatSurface(const char *filename, uint32_t format, SDL_Surface *parent)
+surface::surface(const char *filename, uint32_t format, SDL_Surface *parent)
: flat::core::labelled(filename, true), parent(parent), hide(false)
{
- cout << "FlatSurface: loading " << filename << endl;
+ cout << "surface: loading " << filename << endl;
sdl_surface = loadOptimizedSurface(filename, format);
if (!sdl_surface)
@@ -31,7 +32,7 @@ FlatSurface::FlatSurface(const char *filename, uint32_t format, SDL_Surface *par
viewport->h = sdl_surface->h;
}
-FlatSurface::FlatSurface(SDL_Surface *sdl_surface, SDL_Surface *parent)
+surface::surface(SDL_Surface *sdl_surface, SDL_Surface *parent)
: flat::core::object(), parent(parent), hide(false)
{
@@ -52,7 +53,7 @@ FlatSurface::FlatSurface(SDL_Surface *sdl_surface, SDL_Surface *parent)
viewport->h = sdl_surface->h;
}
-FlatSurface::FlatSurface(const FlatSurface &sprite)
+surface::surface(const surface &sprite)
: flat::core::object(sprite), parent(sprite.parent),
hide(sprite.hide)
@@ -61,10 +62,10 @@ FlatSurface::FlatSurface(const FlatSurface &sprite)
viewport = new SDL_Rect(*sprite.viewport);
- sdl_surface = copySurface(sprite.surface);
+ sdl_surface = copySurface(sprite.sdl_surface);
}
-FlatSurface::~FlatSurface()
+surface::~surface()
{
SDL_FreeSurface(sdl_surface);
@@ -72,7 +73,7 @@ FlatSurface::~FlatSurface()
delete viewport;
}
-void FlatSurface::setOffset(int x, int y, int w, int h)
+void surface::setOffset(int x, int y, int w, int h)
{
offset->x = x;
offset->y = y;
@@ -84,7 +85,7 @@ void FlatSurface::setOffset(int x, int y, int w, int h)
offset->h = h;
}
-void FlatSurface::setViewport(int x, int y, int w, int h)
+void surface::setViewport(int x, int y, int w, int h)
{
viewport->x = x;
viewport->y = y;
@@ -92,59 +93,59 @@ void FlatSurface::setViewport(int x, int y, int w, int h)
viewport->h = h;
}
-void FlatSurface::setViewport(const SDL_Rect &rect)
+void surface::setViewport(const SDL_Rect &rect)
{
*viewport = rect;
}
-void FlatSurface::setOffset(const SDL_Rect &offset)
+void surface::setOffset(const SDL_Rect &offset)
{
*this->offset = offset;
}
-const SDL_Rect * FlatSurface::getOffset() const
+const SDL_Rect * surface::getOffset() const
{
return offset;
}
-const SDL_Rect * FlatSurface::getViewport() const
+const SDL_Rect * surface::getViewport() const
{
return viewport;
}
-void FlatSurface::setParent(SDL_Surface *parent)
+void surface::setParent(SDL_Surface *parent)
{
this->parent = parent;
}
-SDL_Surface * FlatSurface::getParent()
+SDL_Surface * surface::getParent()
{
return parent;
}
-SDL_Surface * FlatSurface::getSurface()
+SDL_Surface * surface::getSurface()
{
return sdl_surface;
}
-void FlatSurface::setHidden(bool flag)
+void surface::setHidden(bool flag)
{
hide = flag;
}
-bool FlatSurface::isHidden() const
+bool surface::isHidden() const
{
return hide;
}
-void FlatSurface::blit()
+void surface::blit()
{
if (!hide)
SDL_BlitSurface(sdl_surface, viewport, parent, offset);
}
-SDL_Surface * FlatSurface::loadOptimizedSurface(const char *filename, uint32_t format)
+SDL_Surface * surface::loadOptimizedSurface(const char *filename, uint32_t format)
{
SDL_Surface * optimized = 0;
@@ -159,7 +160,7 @@ SDL_Surface * FlatSurface::loadOptimizedSurface(const char *filename, uint32_t f
return optimized;
}
-SDL_Surface * FlatSurface::copySurface(SDL_Surface *src)
+SDL_Surface * surface::copySurface(SDL_Surface *src)
{
return SDL_ConvertSurface(src, src->format, src->flags);
}
diff --git a/engine/window.cpp b/engine/window.cpp
index a460328..4f22310 100644
--- a/engine/window.cpp
+++ b/engine/window.cpp
@@ -6,6 +6,7 @@
#include "core/signal.hpp"
using namespace std;
+using namespace flat;
FlatWindow::FlatWindow( int x, int y,
int width, int height,
@@ -15,8 +16,6 @@ FlatWindow::FlatWindow( int x, int y,
: title(title), status(status),
sdl_window(0), screen(0)
{
- set_id(title);
-
bounds = new SDL_Rect;
bounds->x = x;
@@ -166,8 +165,8 @@ void FlatWindow::key_cb(const SDL_KeyboardEvent *event)
close();
/* Say flatland to quit */
- flat::core::signal quit(this, "quit", 0, 0xff);
- quit.emit("core");
+ // flat::core::signal quit(this, "quit", 0, 0xff);
+ // quit.emit("core");
}
}
diff --git a/test/test1.cpp b/test/test1.cpp
index 847e1ab..5de357b 100644
--- a/test/test1.cpp
+++ b/test/test1.cpp
@@ -1,6 +1,8 @@
#include "flatland.hpp"
#include "window.hpp"
+using namespace flat;
+
int count = 0;
void loop(float);
diff --git a/test/test2.cpp b/test/test2.cpp
index ca14ac7..55c6e55 100644
--- a/test/test2.cpp
+++ b/test/test2.cpp
@@ -2,6 +2,8 @@
#include "window.hpp"
#include "exceptions/forcequit.hpp"
+using namespace flat;
+
int count = 0;
void loop(float);