starting game planning
This commit is contained in:
@@ -8,20 +8,12 @@ if(NOT CMAKE_BUILD_TYPE)
|
|||||||
set(CMAKE_BUILD_TYPE Release)
|
set(CMAKE_BUILD_TYPE Release)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Dependencies
|
|
||||||
#
|
|
||||||
# Native build: raylib + RmlUi come from nixpkgs / the `rmlui` derivation,
|
|
||||||
# found on the default system paths set up by the dev shell.
|
|
||||||
#
|
|
||||||
# Wasm build: raylib + RmlUi come from the `raylibWasm` / `rmluiWasm`
|
|
||||||
# derivations, located via -DCMAKE_PREFIX_PATH set by devShells.wasm.
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
find_package(raylib REQUIRED)
|
find_package(raylib REQUIRED)
|
||||||
find_package(RmlUi REQUIRED)
|
find_package(RmlUi REQUIRED)
|
||||||
|
|
||||||
add_executable(gamejam
|
add_executable(gamejam
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
|
src/Game.cpp
|
||||||
src/Application.cpp
|
src/Application.cpp
|
||||||
src/backend/RaylibSystemInterface.cpp
|
src/backend/RaylibSystemInterface.cpp
|
||||||
src/backend/RaylibRenderInterface.cpp
|
src/backend/RaylibRenderInterface.cpp
|
||||||
@@ -39,9 +31,6 @@ target_include_directories(gamejam PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
|||||||
set(ASSET_DIR ${CMAKE_SOURCE_DIR}/assets)
|
set(ASSET_DIR ${CMAKE_SOURCE_DIR}/assets)
|
||||||
|
|
||||||
if(EMSCRIPTEN)
|
if(EMSCRIPTEN)
|
||||||
# -----------------------------------------------------------------------
|
|
||||||
# Wasm-specific settings
|
|
||||||
# -----------------------------------------------------------------------
|
|
||||||
set(CMAKE_EXECUTABLE_SUFFIX ".html")
|
set(CMAKE_EXECUTABLE_SUFFIX ".html")
|
||||||
|
|
||||||
target_link_options(gamejam PRIVATE
|
target_link_options(gamejam PRIVATE
|
||||||
@@ -53,7 +42,6 @@ if(EMSCRIPTEN)
|
|||||||
# "--shell-file=${CMAKE_SOURCE_DIR}/shell.html"
|
# "--shell-file=${CMAKE_SOURCE_DIR}/shell.html"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
else()
|
else()
|
||||||
add_custom_command(TARGET gamejam POST_BUILD
|
add_custom_command(TARGET gamejam POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ body {
|
|||||||
font-family: rmlui-debugger-font;
|
font-family: rmlui-debugger-font;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
color: white;
|
color: white;
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
#panel {
|
#panel {
|
||||||
@@ -24,7 +26,11 @@ p {
|
|||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#start-btn {
|
.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-btn {
|
||||||
display: block;
|
display: block;
|
||||||
width: 100px;
|
width: 100px;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
@@ -34,6 +40,6 @@ p {
|
|||||||
border: 1px #5a8ec5;
|
border: 1px #5a8ec5;
|
||||||
}
|
}
|
||||||
|
|
||||||
#start-btn:hover {
|
.menu-btn:hover {
|
||||||
background-color: #4a7eb5;
|
background-color: #4a7eb5;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<link type="text/rcss" href="main.rcss"/>
|
<link type="text/rcss" href="main.rcss"/>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="panel">
|
<div id="start_menu">
|
||||||
<h1>gamejam</h1>
|
<h1>gamejam</h1>
|
||||||
<p>RmlUi + raylib scaffold is alive.</p>
|
<p>RmlUi + raylib scaffold is alive.</p>
|
||||||
<button id="start-btn">Start</button>
|
<button id="start-btn">Start</button>
|
||||||
|
|||||||
@@ -25,11 +25,6 @@
|
|||||||
"-DBUILD_TESTING=OFF"
|
"-DBUILD_TESTING=OFF"
|
||||||
];
|
];
|
||||||
|
|
||||||
# Emscripten's toolchain file restricts find_library/find_path/find_package
|
|
||||||
# to CMAKE_FIND_ROOT_PATH (its own sysroot) by default. Our externally-built
|
|
||||||
# wasm deps (freetypeWasm, raylibWasm, rmluiWasm) live in the Nix store,
|
|
||||||
# outside that sysroot, so CMAKE_PREFIX_PATH alone is silently ignored
|
|
||||||
# unless we relax these three modes to BOTH.
|
|
||||||
wasmFindOverrides = [
|
wasmFindOverrides = [
|
||||||
"-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH"
|
"-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH"
|
||||||
"-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=BOTH"
|
"-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=BOTH"
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
#include "Game.h"
|
||||||
#include "backend/RaylibInput.h"
|
#include "backend/RaylibInput.h"
|
||||||
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <RmlUi/Core.h>
|
#include <RmlUi/Core.h>
|
||||||
#include <RmlUi/Debugger.h>
|
#include <RmlUi/Debugger.h>
|
||||||
|
|
||||||
|
Game game;
|
||||||
|
|
||||||
bool Application::Init(int width, int height, const char* title, const char* documentPath) {
|
bool Application::Init(int width, int height, const char* title, const char* documentPath) {
|
||||||
InitWindow(width, height, title);
|
InitWindow(width, height, title);
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
@@ -24,6 +27,8 @@ bool Application::Init(int width, int height, const char* title, const char* doc
|
|||||||
TraceLog(LOG_WARNING, "Failed to load %s", documentPath);
|
TraceLog(LOG_WARNING, "Failed to load %s", documentPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
game.Init(context);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,10 +41,12 @@ void Application::Frame() {
|
|||||||
ForwardInputToRml(context);
|
ForwardInputToRml(context);
|
||||||
context->Update();
|
context->Update();
|
||||||
|
|
||||||
|
game.Update();
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(DARKGRAY);
|
ClearBackground(DARKGRAY);
|
||||||
|
|
||||||
// --- game world rendering goes here, before the UI ---
|
game.Draw2D();
|
||||||
|
|
||||||
context->Render();
|
context->Render();
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <RmlUi/Core/Context.h>
|
#include <RmlUi/Core/Context.h>
|
||||||
#include "backend/RaylibSystemInterface.h"
|
#include "backend/RaylibSystemInterface.h"
|
||||||
#include "backend/RaylibRenderInterface.h"
|
#include "backend/RaylibRenderInterface.h"
|
||||||
|
#include "Game.h"
|
||||||
|
|
||||||
class Application {
|
class Application {
|
||||||
public:
|
public:
|
||||||
|
|||||||
20
src/Game.cpp
Normal file
20
src/Game.cpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#include "Game.h"
|
||||||
|
#include <RmlUi/Core/Context.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <raylib.h>
|
||||||
|
#include <RmlUi/Core.h>
|
||||||
|
|
||||||
|
void Game::Draw2D() {return;}
|
||||||
|
|
||||||
|
void Game::Update() {
|
||||||
|
// TODO: Remove this debug
|
||||||
|
std::cout << "Game update" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Game::Init(Rml::Context *context) {
|
||||||
|
if (!ctx) return false;
|
||||||
|
|
||||||
|
ctx = context;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
32
src/Game.h
Normal file
32
src/Game.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <RmlUi/Core/Context.h>
|
||||||
|
#include <RmlUi/Core/DataModelHandle.h>
|
||||||
|
enum GameState {
|
||||||
|
START_MENU,
|
||||||
|
PAUSE_MENU,
|
||||||
|
STATS_MENU,
|
||||||
|
OPTIONS_MENU,
|
||||||
|
IN_GAME
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GameData {
|
||||||
|
GameState game_state = START_MENU;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Game {
|
||||||
|
public:
|
||||||
|
GameData game_data;
|
||||||
|
|
||||||
|
bool Init(Rml::Context *context);
|
||||||
|
|
||||||
|
bool setup_rml_data_binding(Rml::Context *ctx, Rml::DataModelHandle &model_handle, GameData &game_data);
|
||||||
|
|
||||||
|
void Update();
|
||||||
|
void Draw2D();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Rml::Context *ctx = nullptr;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user