mirror of
https://github.com/encounter/cpp3ds.git
synced 2026-03-30 11:04:22 -07:00
Fixed structure flaw that didn't draw stage actors with 3D effect.
This commit is contained in:
@@ -8,8 +8,8 @@ namespace cpp3ds {
|
||||
class Drawable {
|
||||
public:
|
||||
float depth3d;
|
||||
Drawable(){ depth3d = 0; }
|
||||
virtual void draw(Screen& screen, float x, float y) = 0;
|
||||
Drawable(float depth3d): depth3d(depth3d) {}
|
||||
virtual void draw(Screen& screen, float x, float y, bool use3D, bool isLeftside) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace cpp3ds {
|
||||
int getHeight(){ return height; }
|
||||
void setPixelAddress(int addr, Color color);
|
||||
void setPixel(int x, int y, Color color);
|
||||
void clear(Color color);
|
||||
void draw(Drawable& obj, float x = 0, float y = 0);
|
||||
void clear(Color color = {0,0,0});
|
||||
virtual void draw(Drawable& obj, float x = 0, float y = 0, bool use3D = false);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ namespace cpp3ds {
|
||||
float width, height;
|
||||
ActorNode *actorHead, *actorTail;
|
||||
public:
|
||||
Stage();
|
||||
void addActor(Actor& actor);
|
||||
void removeActor(Actor& actor);
|
||||
virtual void draw(Screen& screen, float x = 0, float y = 0);
|
||||
Stage(): Actors::Actor(0,0,0), actorHead(NULL), actorTail(NULL) {}
|
||||
void addActor(Actors::Actor& actor);
|
||||
void removeActor(Actors::Actor& actor);
|
||||
virtual void draw(Screen& screen, float x = 0, float y = 0, bool use3D = true, bool isLeftside = true);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,19 +11,21 @@
|
||||
#define TOP_LEFT_FRAME2 0x201CB370
|
||||
#define TOP_RIGHT_FRAME1 0x20282160
|
||||
#define TOP_RIGHT_FRAME2 0x202C8670
|
||||
#define SLIDER_STATE 0x10144000
|
||||
|
||||
namespace cpp3ds {
|
||||
class TopScreen: public Screen {
|
||||
protected:
|
||||
Screen right_screen;
|
||||
Screen left_screen, right_screen;
|
||||
int width, height;
|
||||
public:
|
||||
TopScreen():
|
||||
Screen(TOP_LEFT_FRAME1, TOP_LEFT_FRAME2, TOP_WIDTH, TOP_HEIGHT),
|
||||
Screen(0, 0, TOP_WIDTH, TOP_HEIGHT),
|
||||
left_screen(TOP_LEFT_FRAME1, TOP_LEFT_FRAME2, TOP_WIDTH, TOP_HEIGHT),
|
||||
right_screen(TOP_RIGHT_FRAME1, TOP_RIGHT_FRAME2, TOP_WIDTH, TOP_HEIGHT)
|
||||
{};
|
||||
void clear(Color color);
|
||||
void draw(Drawable& obj, float x = 0, float y = 0);
|
||||
void clear(Color color = {0,0,0});
|
||||
virtual void draw(Drawable& obj, float x = 0, float y = 0, bool use3D = true);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace cpp3ds {
|
||||
public:
|
||||
Color color;
|
||||
Rectangle(int w, int h, Color color, float x = 0, float y = 0, float depth3d = 0):
|
||||
width(w), height(h), color(color), Actor(x, y, depth3d) {}
|
||||
Actor(x, y, depth3d), width(w), height(h), color(color) {}
|
||||
virtual void draw(Screen& screen, float x = 0, float y = 0);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef TEXT_ACTOR_H
|
||||
#define TEXT_ACTOR_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <cpp3ds/actors/Actor.h>
|
||||
#include <cpp3ds/Color.h>
|
||||
#include <cpp3ds/Screen.h>
|
||||
@@ -14,9 +15,9 @@ namespace cpp3ds {
|
||||
public:
|
||||
char* text;
|
||||
Color color;
|
||||
Text(char* text, Color color, float x = 0, float y = 0, float depth3d = 0):
|
||||
text(text), color(color), Actor(x, y, depth3d) {}
|
||||
virtual void draw(Screen& screen, float x = 0, float y = 0);
|
||||
Text(char* text, Color color = {0,0,0}, float x = 0, float y = 0, float depth3d = 0):
|
||||
Actor(x, y, depth3d), text(text), color(color) {}
|
||||
virtual void draw(Screen& screen, float x = 0, float y = 0, bool use3D = true, bool isLeftside = true);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+15
-12
@@ -20,21 +20,24 @@ namespace cpp3ds {
|
||||
}
|
||||
|
||||
void Screen::clear(Color color){
|
||||
// Just clear to black
|
||||
// memset((char*)frame1, 0, width*height*3);
|
||||
// memset((char*)frame2, 0, width*height*3);
|
||||
// TODO: Too slow, maybe try memcpy?
|
||||
char* frameptr1 = (char*)frame1;
|
||||
char* frameptr2 = (char*)frame2;
|
||||
for (int i = 0; i < width*height; ++i){
|
||||
*frameptr1++ = *frameptr2++ = color.b;
|
||||
*frameptr1++ = *frameptr2++ = color.g;
|
||||
*frameptr1++ = *frameptr2++ = color.r;
|
||||
if (color.r == color.g && color.g == color.b){
|
||||
memset((char*)frame1, color.r, width*height*3);
|
||||
memset((char*)frame2, color.r, width*height*3);
|
||||
} else {
|
||||
// TODO: Too slow, maybe try memcpy?
|
||||
char* frameptr1 = (char*)frame1;
|
||||
char* frameptr2 = (char*)frame2;
|
||||
for (int i = 0; i < width*height; ++i){
|
||||
*frameptr1++ = *frameptr2++ = color.b;
|
||||
*frameptr1++ = *frameptr2++ = color.g;
|
||||
*frameptr1++ = *frameptr2++ = color.r;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::draw(Drawable& obj, float x, float y) {
|
||||
obj.draw(*this, x, y);
|
||||
void Screen::draw(Drawable& obj, float x, float y, bool use3D) {
|
||||
// TODO: Check bounds and don't draw objects outside screen
|
||||
obj.draw(*this, x, y, use3D, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-7
@@ -5,11 +5,6 @@
|
||||
|
||||
namespace cpp3ds {
|
||||
|
||||
Stage::Stage(){
|
||||
actorHead = NULL;
|
||||
actorTail = NULL;
|
||||
}
|
||||
|
||||
void Stage::addActor(Actors::Actor& actor){
|
||||
if (this == &actor)
|
||||
return; // Avoid infinite recursion
|
||||
@@ -39,11 +34,16 @@ namespace cpp3ds {
|
||||
}
|
||||
}
|
||||
|
||||
void Stage::draw(Screen& screen, float x, float y) {
|
||||
void Stage::draw(Screen& screen, float x, float y, bool use3D, bool isLeftside) {
|
||||
// Loop through and draw all actors on the stage
|
||||
ActorNode* cur = actorTail;
|
||||
while (cur != NULL) {
|
||||
cur->actor->draw(screen, this->x + x, this->y + y);
|
||||
Actors::Actor& actor = *cur->actor;
|
||||
if (use3D) {
|
||||
float slider = 1.0f * actor.depth3d;
|
||||
x = (isLeftside) ? x - slider : x + slider;
|
||||
}
|
||||
actor.draw(screen, this->x + x, this->y + y, use3D, isLeftside);
|
||||
cur = cur->prev;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-6
@@ -5,15 +5,19 @@
|
||||
namespace cpp3ds {
|
||||
|
||||
void TopScreen::clear(Color color){
|
||||
Screen::clear(color);
|
||||
left_screen.clear(color);
|
||||
right_screen.clear(color);
|
||||
}
|
||||
|
||||
void TopScreen::draw(Drawable& obj, float x, float y) {
|
||||
// TODO: Get real 3D Slider State
|
||||
float slider = 1.0f;
|
||||
obj.draw(*this, x - slider * obj.depth3d, y);
|
||||
obj.draw(right_screen, x + slider * obj.depth3d, y);
|
||||
void TopScreen::draw(Drawable& obj, float x, float y, bool use3D) {
|
||||
if (use3D) {
|
||||
float slider = 1.0f * obj.depth3d;
|
||||
obj.draw(left_screen, x - slider, y, use3D, true);
|
||||
obj.draw(right_screen, x + slider, y, use3D, false);
|
||||
} else {
|
||||
obj.draw(left_screen, x, y, use3D, true);
|
||||
obj.draw(right_screen, x, y, use3D, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,14 +4,6 @@
|
||||
|
||||
namespace cpp3ds {
|
||||
namespace Actors {
|
||||
|
||||
Actor::Actor(float x, float y, float depth3d) {
|
||||
stageHead = NULL;
|
||||
stageTail = NULL;
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->depth3d = depth3d;
|
||||
}
|
||||
|
||||
void Actor::addStage(Stage& stage){
|
||||
StageNode *node = new StageNode();
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ namespace cpp3ds {
|
||||
}
|
||||
}
|
||||
|
||||
void Text::draw(Screen& screen, float x, float y) {
|
||||
void Text::draw(Screen& screen, float x, float y, bool use3D, bool isLeftside) {
|
||||
float tmp_x = this->x + x;
|
||||
int i;
|
||||
int line = 0;
|
||||
|
||||
Reference in New Issue
Block a user