summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-04-21 21:46:37 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-04-21 21:46:37 (GMT)
commit96506610b276be1b4bc1cbc462d991237750fc62 (patch)
treec05e6d55d2a0aa2ad178cfa30f00041a104d6fed /src/game
parent75a9460c835f4ebea501a89d23e0c5f46da985cc (diff)
downloadpowder-96506610b276be1b4bc1cbc462d991237750fc62.zip
powder-96506610b276be1b4bc1cbc462d991237750fc62.tar.gz
Clean out graphics, add openGL graphics in seperate file, change brush to use unsigned char rather than boolean for bitmap/outline
Diffstat (limited to 'src/game')
-rw-r--r--src/game/Brush.h55
-rw-r--r--src/game/EllipseBrush.h16
-rw-r--r--src/game/GameController.cpp5
-rw-r--r--src/game/GameView.cpp6
4 files changed, 40 insertions, 42 deletions
diff --git a/src/game/Brush.h b/src/game/Brush.h
index 98d1321..656f9f3 100644
--- a/src/game/Brush.h
+++ b/src/game/Brush.h
@@ -8,14 +8,16 @@
#ifndef BRUSH_H_
#define BRUSH_H_
+#include <iostream>
#include "interface/Point.h"
class Brush
{
protected:
- bool * outline;
- bool * bitmap;
+ unsigned char * outline;
+ unsigned char * bitmap;
ui::Point size;
+ ui::Point radius;
void updateOutline()
{
if(!bitmap)
@@ -24,35 +26,35 @@ protected:
return;
if(outline)
free(outline);
- int width = size.X*2;
- int height = size.Y*2;
- outline = (bool *)malloc(sizeof(bool)*((width+1)*(height+1)));
- for(int x = 0; x <= width; x++)
+ outline = (unsigned char *)calloc(size.X*size.Y, sizeof(unsigned char));
+ for(int x = 0; x < size.X; x++)
{
- for(int y = 0; y <= height; y++)
+ for(int y = 0; y < size.Y; y++)
{
- if(bitmap[y*width+x] && (!y || !x || y == height || x == width || !bitmap[y*width+(x+1)] || !bitmap[y*width+(x-1)] || !bitmap[(y-1)*width+x] || !bitmap[(y+1)*width+x]))
- outline[y*width+x] = true;
+ if(bitmap[y*size.X+x] && (!y || !x || y == size.X-1 || x == size.Y-1 || !bitmap[y*size.X+(x+1)] || !bitmap[y*size.X+(x-1)] || !bitmap[(y-1)*size.X+x] || !bitmap[(y+1)*size.X+x]))
+ outline[y*size.X+x] = 255;
else
- outline[y*width+x] = false;
+ outline[y*size.X+x] = 0;
}
}
}
public:
Brush(ui::Point size_):
bitmap(NULL),
- size(size_),
- outline(NULL)
+ outline(NULL),
+ radius(0, 0),
+ size(0, 0)
{
-
+ SetRadius(size_);
};
ui::Point GetRadius()
{
- return size;
+ return radius;
}
- void SetRadius(ui::Point size)
+ void SetRadius(ui::Point radius)
{
- this->size = size;
+ this->radius = radius;
+ this->size = radius+radius+ui::Point(1, 1);
GenerateBitmap();
updateOutline();
}
@@ -93,37 +95,30 @@ public:
updateOutline();
if(!outline)
return;
- for(int x = 0; x <= size.X*2; x++)
- {
- for(int y = 0; y <= size.Y*2; y++)
- {
- if(outline[y*(size.X*2)+x])
- g->xor_pixel(position.X-size.X+x, position.Y-size.Y+y);
- }
- }
+ g->xor_bitmap(outline, position.X-radius.X, position.Y-radius.Y-1, size.X, size.Y);
}
virtual void GenerateBitmap()
{
if(bitmap)
free(bitmap);
- bitmap = (bool *)malloc(sizeof(bool)*(((size.X*2)+1)*((size.Y*2)+1)));
- for(int x = 0; x <= size.X*2; x++)
+ bitmap = (unsigned char *)calloc((size.X*size.Y), sizeof(unsigned char));
+ for(int x = 0; x < size.X; x++)
{
- for(int y = 0; y <= size.Y*2; y++)
+ for(int y = 0; y < size.Y; y++)
{
- bitmap[y*(size.X*2)+x] = true;
+ bitmap[(y*size.X)+x] = 255;
}
}
}
//Get a bitmap for drawing particles
- bool * GetBitmap()
+ unsigned char * GetBitmap()
{
if(!bitmap)
GenerateBitmap();
return bitmap;
}
- bool * GetOutline()
+ unsigned char * GetOutline()
{
if(!outline)
updateOutline();
diff --git a/src/game/EllipseBrush.h b/src/game/EllipseBrush.h
index 0953c01..26b3cf8 100644
--- a/src/game/EllipseBrush.h
+++ b/src/game/EllipseBrush.h
@@ -22,20 +22,20 @@ public:
{
if(bitmap)
free(bitmap);
- bitmap = (bool *)malloc(sizeof(bool)*(((size.X*2)+1)*((size.Y*2)+1)));
- int rx = size.X;
- int ry = size.Y;
- for(int x = 0; x <= size.X*2; x++)
+ bitmap = (unsigned char*)calloc((size.X*size.Y), sizeof(unsigned char));
+ int rx = radius.X;
+ int ry = radius.Y;
+ for(int x = 0; x <= radius.X*2; x++)
{
- for(int y = 0; y <= size.Y*2; y++)
+ for(int y = 0; y <= radius.Y*2; y++)
{
- if((pow(x-size.X,2)*pow(ry,2)+pow(y-size.Y,2)*pow(rx,2)<=pow(rx,2)*pow(ry,2)))
+ if((pow(x-radius.X,2)*pow(ry,2)+pow(y-radius.Y,2)*pow(rx,2)<=pow(rx,2)*pow(ry,2)))
{
- bitmap[y*(size.X*2)+x] = true;
+ bitmap[y*(size.X)+x] = 255;
}
else
{
- bitmap[y*(size.X*2)+x] = false;
+ bitmap[y*(size.X)+x] = 0;
}
}
}
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index f289f49..4f94ab8 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -580,6 +580,9 @@ void GameController::ReloadSim()
std::string GameController::ElementResolve(int type)
{
- return std::string(gameModel->GetSimulation()->ptypes[type].name);
+ if(gameModel && gameModel->GetSimulation() && gameModel->GetSimulation()->ptypes && type >= 0 && type < PT_NUM)
+ return std::string(gameModel->GetSimulation()->ptypes[type].name);
+ else
+ return "";
}
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 219c6ee..7e04c6e 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -857,9 +857,8 @@ void GameView::OnDraw()
ren->draw_air();
ren->render_parts();
ren->render_fire();
- //ren->draw_grav();
+ ren->draw_grav();
ren->DrawWalls();
- ren->FinaliseParts();
if(activeBrush && currentMouse.X > 0 && currentMouse.X < XRES && currentMouse.Y > 0 && currentMouse.Y < YRES)
{
if(drawMode==DrawRect && isMouseDown)
@@ -875,8 +874,9 @@ void GameView::OnDraw()
activeBrush->RenderPoint(g, c->PointTranslate(currentMouse));
}
}
- ren->RenderZoom();
ren->DrawSigns();
+ ren->FinaliseParts();
+ ren->RenderZoom();
if(selectMode!=SelectNone)
{