Skip to content

Commit

Permalink
[3DS] Implementing LineBatcher and RectangleBatcher and fixing a warn…
Browse files Browse the repository at this point in the history
…ing in Entity.cpp
  • Loading branch information
sgowdev committed Aug 25, 2015
1 parent 284a255 commit 7e35e86
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/framework/entity/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "Entity.h"

Entity::Entity() : m_ID(getUniqueEntityID()), m_fStateTime(0.0f)
Entity::Entity() : m_fStateTime(0.0f), m_ID(getUniqueEntityID())
{
// Empty
}
Expand Down
79 changes: 79 additions & 0 deletions src/core/framework/ui/3ds/DSCircleBatcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// DSCircleBatcher.cpp
// gowengamedev-framework
//
// Created by Stephen Gowen on 8/25/15.
// Copyright (c) 2015 Gowen Game Dev. All rights reserved.
//

#define DEGREE_SPACING 6

#include "DSCircleBatcher.h"
#include "macros.h"
#include "Circle.h"
#include "Vector2D.h"
#include "math.h"

DSCircleBatcher::DSCircleBatcher() : CircleBatcher()
{
// Empty
}

void DSCircleBatcher::renderCircle(Circle &circle, Color &color)
{
// OGLESManager->m_colorVertices.clear();

int numPointsOnCircle = 0;

for (int i = 0; i < 360; i += DEGREE_SPACING)
{
float rad = DEGREES_TO_RADIANS(i);
float cos = cosf(rad);
float sin = sinf(rad);

// OGLESManager->addVertexCoordinate(cos * circle.m_fRadius + circle.getCenter().getX(), sin * circle.m_fRadius + circle.getCenter().getY(), 0, color.red, color.green, color.blue, color.alpha);

numPointsOnCircle++;
}

endBatch(numPointsOnCircle);
}

void DSCircleBatcher::renderPartialCircle(Circle &circle, int arcDegrees, Color &color)
{
// OGLESManager->m_colorVertices.clear();

// OGLESManager->addVertexCoordinate(circle.getCenter().getX(), circle.getCenter().getY(), 0, color.red, color.green, color.blue, color.alpha);

int numPointsOnCircle = 1;

for (int i = 90 - arcDegrees; i > -270; i -= DEGREE_SPACING)
{
float rad = DEGREES_TO_RADIANS(i);
float cos = cosf(rad);
float sin = sinf(rad);

// OGLESManager->addVertexCoordinate(cos * circle.m_fRadius + circle.getCenter().getX(), sin * circle.m_fRadius + circle.getCenter().getY(), 0, color.red, color.green, color.blue, color.alpha);

numPointsOnCircle++;
}

float rad = DEGREES_TO_RADIANS(-270);
float cos = cosf(rad);
float sin = sinf(rad);

// OGLESManager->addVertexCoordinate(cos * circle.m_fRadius + circle.getCenter().getX(), sin * circle.m_fRadius + circle.getCenter().getY(), 0, color.red, color.green, color.blue, color.alpha);

numPointsOnCircle++;

endBatch(numPointsOnCircle);
}

void DSCircleBatcher::endBatch(int numPoints)
{
// OGLESManager->prepareForGeometryRendering();

// glDrawArrays(GL_TRIANGLE_FAN, 0, numPoints);

// OGLESManager->finishGeometryRendering();
}
27 changes: 27 additions & 0 deletions src/core/framework/ui/3ds/DSCircleBatcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// DSCircleBatcher.h
// gowengamedev-framework
//
// Created by Stephen Gowen on 8/25/15.
// Copyright (c) 2015 Gowen Game Dev. All rights reserved.
//

#ifndef __gowengamedev__DSCircleBatcher__
#define __gowengamedev__DSCircleBatcher__

#include "CircleBatcher.h"

class DSCircleBatcher : public CircleBatcher
{
public:
DSCircleBatcher();

virtual void renderCircle(Circle &circle, Color &color);

virtual void renderPartialCircle(Circle &circle, int arcDegrees, Color &color);

private:
void endBatch(int numPoints);
};

#endif /* defined(__gowengamedev__DSCircleBatcher__) */
49 changes: 49 additions & 0 deletions src/core/framework/ui/3ds/DSLineBatcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// DSLineBatcher.cpp
// gowengamedev-framework
//
// Created by Stephen Gowen on 8/25/15.
// Copyright (c) 2015 Gowen Game Dev. All rights reserved.
//

#include "DSLineBatcher.h"
#include "macros.h"
#include "Line.h"
#include "Vector2D.h"
#include "GameConstants.h"

#include <sf2d.h>

#define LINE_THICKNESS GAME_WIDTH / 1000.0f

DSLineBatcher::DSLineBatcher(gfxScreen_t screen, int screenWidth, int screenHeight) : m_screen(screen), m_iScreenWidth(screenWidth), m_iScreenHeight(screenHeight)
{
m_iNumLines = 0;
}

void DSLineBatcher::beginBatch()
{
m_lines.clear();
m_iNumLines = 0;
}

void DSLineBatcher::endBatch()
{
if (m_iNumLines > 0)
{
for (std::vector<LINE>::iterator itr = m_lines.begin(); itr != m_lines.end(); ++itr)
{
LINE l = *itr;

sf2d_draw_line(l.oX, l.oY, l.eX, l.eY, LINE_THICKNESS, RGBA8((int) (l.r * 255), (int) (l.g * 255), (int) (l.b * 255), (int) (l.a * 255)));
}
}
}

void DSLineBatcher::renderLine(float originX, float originY, float endX, float endY, Color &color)
{
LINE l = {originX, GAME_HEIGHT - originY, endX, GAME_HEIGHT - endY, color.red, color.green, color.blue, color.alpha};
m_lines.push_back(l);

m_iNumLines++;
}
42 changes: 42 additions & 0 deletions src/core/framework/ui/3ds/DSLineBatcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// DSLineBatcher.h
// gowengamedev-framework
//
// Created by Stephen Gowen on 8/25/15.
// Copyright (c) 2015 Gowen Game Dev. All rights reserved.
//

#ifndef __gowengamedev__DSLineBatcher__
#define __gowengamedev__DSLineBatcher__

#include "LineBatcher.h"

#include <vector>

#include <3ds.h>

struct LINE
{
float oX, oY, eX, eY; // Vertices
float r, g, b, a; // Color for Vertices
};

class DSLineBatcher : public LineBatcher
{
public:
DSLineBatcher(gfxScreen_t screen, int screenWidth, int screenHeight);

virtual void beginBatch();

virtual void endBatch();

virtual void renderLine(float originX, float originY, float endX, float endY, Color &color);

private:
std::vector<LINE> m_lines;
gfxScreen_t m_screen;
int m_iScreenWidth;
int m_iScreenHeight;
};

#endif /* defined(__gowengamedev__DSLineBatcher__) */
69 changes: 69 additions & 0 deletions src/core/framework/ui/3ds/DSRectangleBatcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// DSRectangleBatcher.cpp
// gowengamedev-framework
//
// Created by Stephen Gowen on 8/25/15.
// Copyright (c) 2015 Gowen Game Dev. All rights reserved.
//

#include "DSRectangleBatcher.h"
#include "macros.h"
#include "Rectangle.h"
#include "Vector2D.h"
#include "GameConstants.h"

#include <sf2d.h>

#define RECT_LINE_THICKNESS GAME_WIDTH / 800.0f

DSRectangleBatcher::DSRectangleBatcher(gfxScreen_t screen, int screenWidth, int screenHeight, bool isFill) : RectangleBatcher(isFill), m_screen(screen), m_iScreenWidth(screenWidth), m_iScreenHeight(screenHeight)
{
m_iNumRectangles = 0;
}

void DSRectangleBatcher::beginBatch()
{
m_rects.clear();
m_iNumRectangles = 0;
}

void DSRectangleBatcher::endBatch()
{
if (m_iNumRectangles > 0)
{
if (m_isFill)
{
for (std::vector<RECT>::iterator itr = m_rects.begin(); itr != m_rects.end(); ++itr)
{
RECT r = *itr;

float width = r.x2 - r.x1;
float height = r.y2 - r.y1;
float x = r.x1 + width / 2;
float y = r.y1 + height / 2;

sf2d_draw_rectangle(x, y, width, height, RGBA8((int) (r.r * 255), (int) (r.g * 255), (int) (r.b * 255), (int) (r.a * 255)));
}
}
else
{
for (std::vector<RECT>::iterator itr = m_rects.begin(); itr != m_rects.end(); ++itr)
{
RECT r = *itr;

sf2d_draw_line(r.x1, r.y1, r.x2, r.y1, RECT_LINE_THICKNESS, RGBA8((int) (r.r * 255), (int) (r.g * 255), (int) (r.b * 255), (int) (r.a * 255)));
sf2d_draw_line(r.x2, r.y1, r.x2, r.y2, RECT_LINE_THICKNESS, RGBA8((int) (r.r * 255), (int) (r.g * 255), (int) (r.b * 255), (int) (r.a * 255)));
sf2d_draw_line(r.x2, r.y2, r.x1, r.y2, RECT_LINE_THICKNESS, RGBA8((int) (r.r * 255), (int) (r.g * 255), (int) (r.b * 255), (int) (r.a * 255)));
sf2d_draw_line(r.x1, r.y2, r.x1, r.y1, RECT_LINE_THICKNESS, RGBA8((int) (r.r * 255), (int) (r.g * 255), (int) (r.b * 255), (int) (r.a * 255)));
}
}
}
}

void DSRectangleBatcher::renderRectangle(float x1, float y1, float x2, float y2, Color &color)
{
RECT r = {x1, GAME_HEIGHT - y1, x2, GAME_HEIGHT - y2, color.red, color.green, color.blue, color.alpha};
m_rects.push_back(r);

m_iNumRectangles++;
}
42 changes: 42 additions & 0 deletions src/core/framework/ui/3ds/DSRectangleBatcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// DSRectangleBatcher.h
// gowengamedev-framework
//
// Created by Stephen Gowen on 8/25/15.
// Copyright (c) 2015 Gowen Game Dev. All rights reserved.
//

#ifndef __gowengamedev__DSRectangleBatcher__
#define __gowengamedev__DSRectangleBatcher__

#include "RectangleBatcher.h"

#include <vector>

#include <3ds.h>

struct RECT
{
float x1, y1, x2, y2; // Rectangle Data
float r, g, b, a; // Color for Vertices
};

class DSRectangleBatcher : public RectangleBatcher
{
public:
DSRectangleBatcher(gfxScreen_t screen, int screenWidth, int screenHeight, bool isFill);

virtual void beginBatch();

virtual void endBatch();

virtual void renderRectangle(float x1, float y1, float x2, float y2, Color &color);

private:
std::vector<RECT> m_rects;
gfxScreen_t m_screen;
int m_iScreenWidth;
int m_iScreenHeight;
};

#endif /* defined(__gowengamedev__DSRectangleBatcher__) */
1 change: 0 additions & 1 deletion src/core/framework/ui/3ds/DSSpriteBatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "Rectangle.h"
#include "Vector2D.h"
#include "math.h"
#include "OverlapTester.h"

#include <sf2d.h>

Expand Down

0 comments on commit 7e35e86

Please sign in to comment.