Skip to content

Commit

Permalink
WIP port to raylib
Browse files Browse the repository at this point in the history
  • Loading branch information
albertvaka committed May 1, 2024
1 parent cd59148 commit fbb5d8b
Show file tree
Hide file tree
Showing 272 changed files with 28,045 additions and 117,580 deletions.
2 changes: 1 addition & 1 deletion asset_src/tiled_tile.cpp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tiled {

const GPU_Rect Tile::TileToTextureRect[] = {
const Rectangle Tile::TileToTextureRect[] = {
{}, //NONE
{% for t in gids -%}
{ {{t%tileset_cols}} * {{tilesize}}, {{t//tileset_cols}} * {{tilesize}}, {{tilesize}}, {{tilesize}} }, //={{gid_to_tileid[t]}}, {{ tilenames[t] }}, gid={{t}}
Expand Down
5 changes: 2 additions & 3 deletions asset_src/tiled_tile.h.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "vec.h"
#include "bounds.h"
#include "mates.h"
#include "SDL_gpu.h"

namespace Tiled {

Expand All @@ -12,8 +11,8 @@ struct Tile {
static constexpr const int Size = {{tilesize}};
static constexpr const vec Sizes = vec({{tilesize}},{{tilesize}});

static const GPU_Rect TileToTextureRect[];
constexpr const GPU_Rect& textureRect() const { return TileToTextureRect[int(value)]; }
static const Rectangle TileToTextureRect[];
constexpr const Rectangle& textureRect() const { return TileToTextureRect[int(value)]; }

// Coordinate conversion functions

Expand Down
Binary file removed bin/SDL2.dll
Binary file not shown.
Binary file removed bin/SDL2_mixer.dll
Binary file not shown.
Binary file removed bin/SDL2_ttf.dll
Binary file not shown.
Binary file removed bin/libfreetype-6.dll
Binary file not shown.
Binary file removed bin/libogg-0.dll
Binary file not shown.
Binary file removed bin/libvorbis-0.dll
Binary file not shown.
Binary file removed bin/libvorbisfile-3.dll
Binary file not shown.
Binary file removed bin/zlib1.dll
Binary file not shown.
6 changes: 2 additions & 4 deletions engine/animation.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include "SDL_gpu.h"

#include "vec.h"
#include "animation_frame.h"
#include <array>
Expand Down Expand Up @@ -140,7 +138,7 @@ struct Animation
return anim_size;
}

const GPU_Rect& CurrentFrameRect() const
const Rectangle& CurrentFrameRect() const
{
return anim[current_frame].rect;
}
Expand Down Expand Up @@ -168,7 +166,7 @@ struct Animation
}

template<uint8_t size>
static const GPU_Rect& GetRectAtTime(const AnimationFrame(&animation)[size], float time)
static const Rectangle& GetRectAtTime(const AnimationFrame(&animation)[size], float time)
{
// This is not very efficient, but it's handy if you are too lazy to store an Animation between frames and want to use something like the global clock
Animation anim(animation);
Expand Down
10 changes: 5 additions & 5 deletions engine/animation_frame.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#pragma once

#include "SDL_gpu.h"
#include <raylib.h>

#include "vec.h"

#include <array>

struct AnimationFrame
{
const GPU_Rect rect;
const Rectangle rect;
const float duration;
constexpr vec GetSize() const { return vec(rect.w, rect.h); }
constexpr vec GetSize() const { return vec(rect.width, rect.height); }
};

// TODO: All constexpr here should be consteval in C++20
Expand All @@ -32,8 +32,8 @@ struct SheetFrameCalculator {
{
return make_array(begin, duration, std::make_index_sequence<N>{});
}
constexpr const GPU_Rect Rect(int index) const {
return GPU_Rect { (float) (offset_x + sprite_w * (index % columns)), (float) (offset_y + sprite_h * (index / columns)), (float)sprite_w, (float)sprite_h};
constexpr const Rectangle Rect(int index) const {
return Rectangle { (float) (offset_x + sprite_w * (index % columns)), (float) (offset_y + sprite_h * (index / columns)), (float)sprite_w, (float)sprite_h};
}
constexpr const AnimationFrame Frame(int index, float duration) const {
return AnimationFrame { Rect(index), duration};
Expand Down
19 changes: 9 additions & 10 deletions engine/asset_load.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#pragma once

#include "SDL_gpu.h"
#include <SDL_ttf.h>
#include <SDL_mixer.h>
#include "raylib.h"
#include <cassert>
/*
inline Texture* LoadImage(const std::string& path) {
inline GPU_Image* LoadImage(const std::string& path) {

GPU_Image* texture = GPU_LoadImage(path.c_str());
Texture* texture = GPU_LoadImage(path.c_str());
if (!texture) {
Debug::out << "Unable to load image '" << path.c_str() << "': " << SDL_GetError();
assert(false);
Expand All @@ -18,16 +16,16 @@ inline GPU_Image* LoadImage(const std::string& path) {
return texture;
}
inline TTF_Font* LoadFont(const std::string& path, int size) {
TTF_Font* font = TTF_OpenFont(path.c_str(), size);
inline Font* LoadFont(const std::string& path, int size) {
Font* font = TTF_OpenFont(path.c_str(), size);
if (!font) {
Debug::out << "Unable to load font '" << path.c_str() << "': " << TTF_GetError();
assert(false);
}
return font;
}
inline TTF_Font* LoadFontOutline(const std::string& path, int size, int outline) {
TTF_Font* font = LoadFont(path, size);
inline Font* LoadFontOutline(const std::string& path, int size, int outline) {
Font* font = LoadFont(path, size);
TTF_SetFontOutline(font, outline);
return font;
}
Expand All @@ -40,3 +38,4 @@ inline Mix_Music* LoadMusic(const std::string& path) {
}
return music;
}
*/
8 changes: 4 additions & 4 deletions engine/bounds.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <math.h>

#include "vec.h"
#include "SDL_gpu.h"
#include <raylib.h>

struct CircleBounds;

Expand All @@ -23,14 +23,14 @@ struct BoxBounds
left -= origin.x;
top -= origin.y;
}
template<typename T> //Works with GPU_Rect, SDL_Rect and SDL_FRect
template<typename T> // Works with Rectangle, SDL_Rect and SDL_FRect
constexpr explicit BoxBounds(T rect) : BoxBounds(rect.x, rect.y, rect.w, rect.h) { }


[[nodiscard]] static constexpr BoxBounds FromCenter(vec center, vec size) { return BoxBounds(center - size / 2, size); }

[[nodiscard]] GPU_Rect AsRect() {
return GPU_Rect{ left, top, width, height };
[[nodiscard]] Rectangle AsRect() {
return Rectangle{ left, top, width, height };
}

//Expands arround the center by a factor
Expand Down
30 changes: 15 additions & 15 deletions engine/camera.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
#include "camera.h"
#include "raw_input.h"

namespace Camera {
GPU_Camera camera;
GPU_Camera gui_camera;
}

namespace Camera {
namespace GameCamera {
Camera2D camera = { {0.f, 0.f}, {0.f, 0.f}, 0, 1.f };

//Useful for debug pourposes
void MoveCameraWithArrows(float dt, float velocity) {
vec c = Center();
float zoom = Zoom();
if (Keyboard::IsKeyPressed(SDL_SCANCODE_RIGHT))
if (IsKeyDown(KeyboardKey::KEY_RIGHT))
{
c.x += velocity * dt * 10 / zoom;
}
if (Keyboard::IsKeyPressed(SDL_SCANCODE_LEFT))
if (IsKeyDown(KeyboardKey::KEY_LEFT))
{
c.x -= velocity * dt * 10 / zoom;
}
if (Keyboard::IsKeyPressed(SDL_SCANCODE_DOWN))
if (IsKeyDown(KeyboardKey::KEY_DOWN))
{
c.y += velocity * dt * 10 / zoom;
}
if (Keyboard::IsKeyPressed(SDL_SCANCODE_UP))
if (IsKeyDown(KeyboardKey::KEY_UP))
{
c.y -= velocity * dt * 10 / zoom;
}
Expand All @@ -34,12 +29,12 @@ namespace Camera {
void ChangeZoomWithPlusAndMinus(float dt, float zoomVel)
{
float zoom = Zoom();
if (Keyboard::IsKeyPressed(SDL_SCANCODE_EQUALS) || Keyboard::IsKeyPressed(SDL_SCANCODE_KP_PLUS))
if (IsKeyDown(KeyboardKey::KEY_EQUAL) || IsKeyDown(KeyboardKey::KEY_KP_ADD))
{
zoom += zoomVel * dt;
SetZoom(zoom);
}
if (Keyboard::IsKeyPressed(SDL_SCANCODE_MINUS) || Keyboard::IsKeyPressed(SDL_SCANCODE_KP_MINUS)) {
if (IsKeyDown(KeyboardKey::KEY_MINUS) || IsKeyDown(KeyboardKey::KEY_KP_SUBTRACT)) {
zoom -= zoomVel * dt;
if (zoom < 0.01f) zoom = 0.01f;
SetZoom(zoom);
Expand All @@ -48,15 +43,20 @@ namespace Camera {

void RotateWithPagUpDown(float dt, float velocity) {
float r = GetRotationDegs();
if (Keyboard::IsKeyPressed(SDL_SCANCODE_PAGEDOWN))
if (IsKeyDown(KeyboardKey::KEY_PAGE_DOWN))
{
r += velocity * dt;
}
if (Keyboard::IsKeyPressed(SDL_SCANCODE_PAGEUP))
if (IsKeyDown(KeyboardKey::KEY_PAGE_UP))
{
r -= velocity * dt;
}
SetRotationDegs(r);
}

}


namespace GuiCamera {
Camera2D gui_camera = { {0.f, 0.f}, {0.f, 0.f}, 0, 1.f };
}
Loading

0 comments on commit fbb5d8b

Please sign in to comment.