// third party includes
#include <raylib.h>
-class Game {
+// local includes
+#include "game_renderer.h"
+
+class Game : public GameRenderer {
public:
Game();
const char *currentPlayer, char first_first,
char first_second, char first_third, char second_first,
char second_second, char second_third, bool first_ready,
- bool second_ready, int pos, int matchup_idx);
+ bool second_ready, int pos, int matchup_idx) override;
- void do_update();
+ void do_update() override;
- void screen_size_changed();
+ void screen_size_changed() override;
private:
void update_impl();
--- /dev/null
+#ifndef ROCK_PAPER_SCISSORS_DUEL_GAME_RENDERER_H_
+#define ROCK_PAPER_SCISSORS_DUEL_GAME_RENDERER_H_
+
+class GameRenderer {
+public:
+ GameRenderer() {}
+ virtual ~GameRenderer() {}
+
+ virtual void update_state(const char *playerOne, const char *playerTwo,
+ const char *currentPlayer, char first_first,
+ char first_second, char first_third,
+ char second_first, char second_second,
+ char second_third, bool first_ready,
+ bool second_ready, int pos, int matchup_idx) = 0;
+
+ virtual void do_update() = 0;
+
+ virtual void screen_size_changed() = 0;
+};
+
+#endif
#include <random>
#endif
+// standard library includes
+#include <memory>
+
// third party includes
#include <raylib.h>
// local includes
#include "constants.h"
#include "game.h"
+#include "game_renderer.h"
#ifdef __EMSCRIPTEN__
static void *global_game_ptr = nullptr;
char first_first, char first_second, char first_third, char second_first,
char second_second, char second_third, bool first_ready, bool second_ready,
int pos, int matchup_idx) {
- ((Game *)global_game_ptr)
+ ((GameRenderer *)global_game_ptr)
->update_state(playerOne, playerTwo, currentPlayer, first_first,
first_second, first_third, second_first, second_second,
second_third, first_ready, second_ready, pos, matchup_idx);
void *ud) {
if (event_type == EMSCRIPTEN_EVENT_RESIZE) {
SetWindowSize(call_js_get_canvas_width(), call_js_get_canvas_height());
- ((Game *)ud)->screen_size_changed();
+ ((GameRenderer *)ud)->screen_size_changed();
}
return false;
}
#endif
-void game_update(void *game_ptr) { ((Game *)game_ptr)->do_update(); }
+void game_update(void *game_ptr) { ((GameRenderer *)game_ptr)->do_update(); }
int main() {
#ifdef __EMSCRIPTEN__
InitWindow(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, "RPSDuel_Native");
#endif
- Game game{};
+ std::unique_ptr<GameRenderer> renderer = std::make_unique<Game>();
#ifdef __EMSCRIPTEN__
- global_game_ptr = &game;
+ global_game_ptr = renderer.get();
SetWindowSize(call_js_get_canvas_width(), call_js_get_canvas_height());
- emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, &game, false,
- resize_event_callback);
+ emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, renderer.get(),
+ false, resize_event_callback);
- emscripten_set_main_loop_arg(game_update, &game, 0, 1);
+ emscripten_set_main_loop_arg(game_update, renderer.get(), 0, 1);
#else
SetTargetFPS(60);
while (!WindowShouldClose()) {
- game_update(&game);
+ game_update(renderer.get());
}
CloseAudioDevice();