DrawingContext::~DrawingContext()
{
+ clear_drawing_requests(lightmap_requests);
+ clear_drawing_requests(drawing_requests);
+
obstack_free(&obst, NULL);
}
void
+DrawingContext::clear_drawing_requests(DrawingRequests& requests)
+{
+ for(auto& request : requests)
+ {
+ if (request->request_data)
+ {
+ request->request_data->~DrawingRequestData();
+ }
+ request->~DrawingRequest();
+ }
+ requests.clear();
+}
+
+void
DrawingContext::draw_surface(SurfacePtr surface, const Vector& position,
float angle, const Color& color, const Blend& blend,
int layer)
request->color = color;
request->blend = blend;
- request->request_data = surface.get();
+ SurfaceRequest* surfacerequest = new(obst) SurfaceRequest();
+ surfacerequest->surface = surface.get();
+ request->request_data = surfacerequest;
requests->push_back(request);
}
fillrectrequest->radius = radius;
request->request_data = fillrectrequest;
- requests->push_back(request);
+ requests->push_back(request);
}
void
request->alpha = transform.alpha;
InverseEllipseRequest* ellipse = new(obst)InverseEllipseRequest;
-
+
ellipse->color = color;
ellipse->color.alpha = color.alpha * transform.alpha;
ellipse->size = size;
request->request_data = ellipse;
- requests->push_back(request);
+ requests->push_back(request);
}
Rectf
DrawingContext::get_cliprect() const
{
return Rectf(get_translation().x, get_translation().y,
- get_translation().x + SCREEN_WIDTH,
+ get_translation().x + SCREEN_WIDTH,
get_translation().y + SCREEN_HEIGHT);
}
request->layer = LAYER_HUD - 1;
drawing_requests.push_back(request);
}
- lightmap_requests.clear();
+
+ clear_drawing_requests(lightmap_requests);
handle_drawing_requests(drawing_requests);
- drawing_requests.clear();
+ clear_drawing_requests(drawing_requests);
+
obstack_free(&obst, NULL);
obstack_init(&obst);
ambient_color = new_color;
}
-void
+void
DrawingContext::take_screenshot()
{
screenshot_requested = true;
LAYER_OBJECTS = 50,
// Objects that pass through walls
LAYER_FLOATINGOBJECTS = 150,
- //
+ //
LAYER_FOREGROUNDTILES = 200,
- //
+ //
LAYER_FOREGROUND0 = 300,
- //
+ //
LAYER_FOREGROUND1 = 400,
// Hitpoints, time, coins, etc.
LAYER_HUD = 500,
SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT, INVERSEELLIPSE, DRAW_LIGHTMAP, GETLIGHT
};
-struct SurfacePartRequest
+struct DrawingRequestData
+{
+ virtual ~DrawingRequestData()
+ {}
+};
+
+struct SurfaceRequest : public DrawingRequestData
+{
+ SurfaceRequest() :
+ surface()
+ {}
+
+ const Surface* surface;
+
+private:
+ SurfaceRequest(const SurfaceRequest&) = delete;
+ SurfaceRequest& operator=(const SurfaceRequest&) = delete;
+};
+
+struct SurfacePartRequest : public DrawingRequestData
{
SurfacePartRequest() :
surface(),
const Surface* surface;
Vector source;
Vector size;
+
+private:
+ SurfacePartRequest(const SurfacePartRequest&) = delete;
+ SurfacePartRequest& operator=(const SurfacePartRequest&) = delete;
};
-struct TextRequest
+struct TextRequest : public DrawingRequestData
{
TextRequest() :
font(),
TextRequest& operator=(const TextRequest&);
};
-struct GradientRequest
+struct GradientRequest : public DrawingRequestData
{
GradientRequest() :
top(),
Vector size;
};
-struct FillRectRequest
+struct FillRectRequest : public DrawingRequestData
{
FillRectRequest() :
color(),
float radius;
};
-struct InverseEllipseRequest
+struct InverseEllipseRequest : public DrawingRequestData
{
InverseEllipseRequest() :
color(),
float angle;
Color color;
- void* request_data;
+ DrawingRequestData* request_data;
DrawingRequest() :
target(),
}
};
-struct GetLightRequest
+struct GetLightRequest : public DrawingRequestData
{
+ GetLightRequest() : color_ptr() {}
+
Color* color_ptr;
+
+private:
+ GetLightRequest(const GetLightRequest&) = delete;
+ GetLightRequest& operator=(const GetLightRequest&) = delete;
};
#endif