--- /dev/null
+#include "game.h"
+
+// third party includes
+#include <raylib.h>
+
+Game::Game() {}
+
+void Game::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) {}
+
+void Game::do_update() {
+ update_impl();
+ draw_impl();
+}
+
+void Game::update_impl() {}
+
+void Game::draw_impl() {
+ BeginDrawing();
+ ClearBackground(BLACK);
+ DrawText("Testing...", 100, 100, 30, RAYWHITE);
+ EndDrawing();
+}
--- /dev/null
+#ifndef ROCK_PAPER_SCISSORS_DUEL_GAME_H_
+#define ROCK_PAPER_SCISSORS_DUEL_GAME_H_
+
+class Game {
+public:
+ Game();
+
+ 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);
+
+ void do_update();
+
+private:
+
+ void update_impl();
+ void draw_impl();
+
+};
+
+#endif
// local includes
#include "constants.h"
+#include "game.h"
#ifdef __EMSCRIPTEN__
+static void *global_game_ptr = nullptr;
+
// em exposed fns
extern "C" {
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) {
- // TODO
+ ((Game *)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);
}
} // end em exposed functions
}
#endif
-void game_update(void *game_ptr) {
- BeginDrawing();
- ClearBackground(BLACK);
- DrawText("Testing...", 100, 100, 30, RAYWHITE);
- EndDrawing();
-}
+void game_update(void *game_ptr) { ((Game *)game_ptr)->do_update(); }
int main() {
#ifdef __EMSCRIPTEN__
InitWindow(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, "RPSDuel_Native");
#endif
+ Game game{};
+ global_game_ptr = &game;
+
#ifdef __EMSCRIPTEN__
SetWindowSize(call_js_get_canvas_width(), call_js_get_canvas_height());
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, false,
resize_event_callback);
- // TODO set game ptr
- emscripten_set_main_loop_arg(game_update, nullptr, 0, 1);
+ emscripten_set_main_loop_arg(game_update, &game, 0, 1);
#else
SetTargetFPS(60);
while (!WindowShouldClose()) {
- game_update(nullptr);
+ game_update(&game);
}
CloseAudioDevice();