mirror of
https://github.com/encounter/cpp3ds.git
synced 2026-03-30 11:04:22 -07:00
Added display() template for synchronize buffer swapping of all screens.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
#ifndef CPP3DS_DISPLAY_H
|
||||
#define CPP3DS_DISPLAY_H
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <cpp3ds/Screen.h>
|
||||
#include <cpp3ds/TopScreen.h>
|
||||
|
||||
namespace cpp3ds {
|
||||
|
||||
template<class... T>
|
||||
void display(Screen& screen, T&... rest){
|
||||
screen._display();
|
||||
display(rest...);
|
||||
}
|
||||
|
||||
// template<class... T>
|
||||
// void display(TopScreen& screen, T&... rest){
|
||||
// screen._display();
|
||||
// display(rest...);
|
||||
// }
|
||||
|
||||
void display();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -8,6 +8,9 @@
|
||||
|
||||
namespace cpp3ds {
|
||||
|
||||
/**
|
||||
* Handles the main game loop for you.
|
||||
*/
|
||||
class Scene {
|
||||
protected:
|
||||
uint64_t lastTime;
|
||||
@@ -15,9 +18,10 @@ namespace cpp3ds {
|
||||
BottomScreen bottomScreen;
|
||||
TopScreen topScreen;
|
||||
Input input;
|
||||
void display();
|
||||
virtual int update(float deltaTime) = 0;
|
||||
virtual void render() = 0;
|
||||
int run();
|
||||
int run(bool useDisplay = true);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <cpp3ds/Screen.h>
|
||||
|
||||
#define BOTTOM_X (400-320)/2
|
||||
#define BOTTOM_Y 240
|
||||
#define BOTTOM_Y 240 + SIM_OUTLINE_THICKNESS*2
|
||||
#define BOTTOM_WIDTH 320
|
||||
#define BOTTOM_HEIGHT 240
|
||||
|
||||
|
||||
+18
-14
@@ -1,22 +1,26 @@
|
||||
#ifndef INPUT_H
|
||||
#define INPUT_H
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
namespace cpp3ds {
|
||||
|
||||
enum Button {
|
||||
BUTTON_A = 1,
|
||||
BUTTON_B = 2,
|
||||
BUTTON_X = 1024,
|
||||
BUTTON_Y = 2048,
|
||||
BUTTON_UP = 64,
|
||||
BUTTON_DOWN = 128,
|
||||
BUTTON_LEFT = 32,
|
||||
BUTTON_RIGHT = 16,
|
||||
BUTTON_L1 = 512,
|
||||
BUTTON_R1 = 256,
|
||||
BUTTON_START = 8,
|
||||
BUTTON_SELECT = 4
|
||||
};
|
||||
typedef sf::Keyboard::Key Button;
|
||||
|
||||
// enum Button {
|
||||
// BUTTON_A = 1,
|
||||
// BUTTON_B = 2,
|
||||
// BUTTON_X = 1024,
|
||||
// BUTTON_Y = 2048,
|
||||
const Button BUTTON_UP = sf::Keyboard::Up;
|
||||
const Button BUTTON_DOWN = sf::Keyboard::Down;
|
||||
const Button BUTTON_LEFT = sf::Keyboard::Left;
|
||||
const Button BUTTON_RIGHT = sf::Keyboard::Right;
|
||||
// BUTTON_L1 = 512,
|
||||
// BUTTON_R1 = 256,
|
||||
// BUTTON_START = 8,
|
||||
// BUTTON_SELECT = 4
|
||||
// };
|
||||
|
||||
enum Event {
|
||||
EVENT_DOWN,
|
||||
|
||||
@@ -23,7 +23,13 @@ namespace cpp3ds {
|
||||
int getHeight(){ return height; }
|
||||
void setPixel(int x, int y, Color color);
|
||||
void clear(Color color = {0,0,0});
|
||||
void display();
|
||||
|
||||
virtual void _display();
|
||||
|
||||
template<class... T>
|
||||
friend void display(Screen& screen, T&... rest);
|
||||
friend void display();
|
||||
|
||||
virtual void draw(Drawable& obj, float x = 0, float y = 0, bool use3D = false);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#define TOP_LEFT_Y 0
|
||||
#define TOP_LEFT_FRAME1 0x20184E60
|
||||
#define TOP_LEFT_FRAME2 0x201CB370
|
||||
#define TOP_RIGHT_X 400
|
||||
#define TOP_RIGHT_X 400 + SIM_OUTLINE_THICKNESS*2
|
||||
#define TOP_RIGHT_Y 0
|
||||
#define TOP_RIGHT_FRAME1 0x20282160
|
||||
#define TOP_RIGHT_FRAME2 0x202C8670
|
||||
@@ -29,7 +29,7 @@ namespace cpp3ds {
|
||||
right_screen(TOP_RIGHT_X, TOP_RIGHT_Y, TOP_WIDTH, TOP_HEIGHT)
|
||||
{};
|
||||
void clear(Color color = {0,0,0});
|
||||
void display();
|
||||
void _display();
|
||||
virtual void draw(Drawable& obj, float x = 0, float y = 0, bool use3D = true);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <sim3ds/sim/Simulator.h>
|
||||
#include <sim3ds/sim/SFMLWidget.h>
|
||||
|
||||
#define SIM_OUTLINE_THICKNESS 1
|
||||
|
||||
namespace cpp3ds {
|
||||
|
||||
class Simulator{
|
||||
@@ -21,7 +23,6 @@ namespace cpp3ds {
|
||||
Gtk::Scale *scale3D;
|
||||
|
||||
sf::Thread* thread;
|
||||
sf::Mutex mutex;
|
||||
|
||||
sf::Texture pausedFrameTexture;
|
||||
sf::Sprite pausedFrame;
|
||||
@@ -40,8 +41,9 @@ namespace cpp3ds {
|
||||
|
||||
public:
|
||||
SFMLWidget *screen;
|
||||
sf::Mutex mutex;
|
||||
|
||||
bool triggerStop = false;
|
||||
bool triggerPause = false;
|
||||
bool isPaused = true;
|
||||
bool isThreadRunning = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user