Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .github/workflows/vangers_linux_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ name: Vangers Linux Build
on: [push, pull_request]

env:
VANGE_RS_REF: adf17c6b563b2b236847a04b5f8df3023b1d1b5b
VANGE_RS_REF: 5dae095d4d5bf13ba293b9e772657a004d808fc2

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: vange-rs -- cache build
uses: actions/cache@v2
id: vange-rs-cache-build
with:
path: vange-rs/target/release/librusty_vangers.a
key: ${{ env.VANGE_RS_REF }}
# TODO: enable cache
# - name: vange-rs -- cache build
# uses: actions/cache@v2
# id: vange-rs-cache-build
# with:
# path: vange-rs/target/release/librusty_vangers.a
# key: ${{ env.VANGE_RS_REF }}

- name: install rustup toolchain
if: steps.vange-rs-cache-build.outputs.cache-hit != 'true'
Expand All @@ -28,7 +29,7 @@ jobs:
if: steps.vange-rs-cache-build.outputs.cache-hit != 'true'
uses: actions/checkout@v2
with:
repository: kvark/vange-rs
repository: lpenguin/vange-rs
ref: ${{ env.VANGE_RS_REF }}
path: vange-rs

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/vangers_macos_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Vangers MacOS Build
on: [push, pull_request]

env:
VANGE_RS_REF: adf17c6b563b2b236847a04b5f8df3023b1d1b5b
VANGE_RS_REF: 5dae095d4d5bf13ba293b9e772657a004d808fc2

jobs:
build:
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
- name: vange-rs -- download
uses: actions/checkout@v2
with:
repository: kvark/vange-rs
repository: lpenguin/vange-rs
ref: ${{ env.VANGE_RS_REF }}
path: vange-rs

Expand Down Expand Up @@ -133,4 +133,4 @@ jobs:
- uses: actions/upload-artifact@v2
with:
name: Vangers.app.tar
path: Vangers.app.tar
path: Vangers.app.tar
4 changes: 2 additions & 2 deletions .github/workflows/vangers_windows_64_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Vangers Windows 64bit Build
on: [push, pull_request]

env:
VANGE_RS_REF: adf17c6b563b2b236847a04b5f8df3023b1d1b5b
VANGE_RS_REF: 5dae095d4d5bf13ba293b9e772657a004d808fc2

jobs:
build:
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
- name: vange-rs -- download
uses: actions/checkout@v2
with:
repository: kvark/vange-rs
repository: lpenguin/vange-rs
ref: ${{ env.VANGE_RS_REF }}
path: vange-rs

Expand Down
3 changes: 3 additions & 0 deletions lib/renderer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ SET(renderer_SRCS
src/renderer/ResourceId.h
src/renderer/common.h
src/renderer/common.cpp
src/renderer/vectormath.cpp
src/renderer/vectormath.h
src/renderer/compositor/AbstractCompositor.h
src/renderer/compositor/CompositorException.cpp
src/renderer/compositor/CompositorException.h
Expand All @@ -17,6 +19,7 @@ SET(renderer_SRCS
src/renderer/compositor/sdl_ext/SDL_extensions.cpp
src/renderer/compositor/sdl_ext/SDL_extensions.h
src/renderer/visualbackend/AbstractVisualBackend.h
src/renderer/visualbackend/AbstractVisualBackend.cpp
src/renderer/visualbackend/VisualBackendContext.cpp
src/renderer/visualbackend/VisualBackendContext.h
src/renderer/visualbackend/dummy/DummyVisualBackend.cpp
Expand Down
19 changes: 19 additions & 0 deletions lib/renderer/src/renderer/vectormath.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "vectormath.h"

using namespace renderer::vectormath;

Transform Transform::concat(const Transform& other)
{
return {
.position = position + rotation.transform(other.position * scale),
.scale = scale * other.scale,
.rotation = rotation * other.rotation
};
}

Vector3 Quaternion::transform(const Vector3& v) const
{
Vector3 u {x, y, z};
Vector3 uv = u.cross(v);
return v + ((uv * w) + u.cross(uv)) * ((float)2);
}
111 changes: 111 additions & 0 deletions lib/renderer/src/renderer/vectormath.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#ifndef MATH_H
#define MATH_H

#include <math.h>

namespace renderer::vectormath {
struct Vector3 {
float x;
float y;
float z;

inline Vector3 operator+(const Vector3& other) const {
return {
.x = x + other.x,
.y = y + other.y,
.z = z + other.z,
};
}

inline Vector3 operator-(const Vector3& other) const {
return {
.x = x - other.x,
.y = y - other.y,
.z = z - other.z,
};
}

inline Vector3 operator*(float value) const {
return {
.x = value * x,
.y = value * y,
.z = value * z,
};
}


inline Vector3 operator/(float value) const {
Vector3 r = {
.x = x / value,
.y = y / value,
.z = z / value,
};
return r;
}

inline Vector3 cross(const Vector3& other) const {
return {
.x = (y * other.z) - (z * other.y),
.y = (z * other.x) - (x * other.z),
.z = (x * other.y) - (y * other.x),
};
}

inline float dot(const Vector3& other) const {
return x * other.x + y * other.y + z * other.z;
}
};

struct Quaternion {
float x;
float y;
float z;
float w;

inline friend Quaternion operator*(const Quaternion& q1, const Quaternion& q2){
return {
.x = (q1.x * q2.w) + (q1.y * q2.z) - (q1.z * q2.y) + (q1.w * q2.x),
.y = (-q1.x * q2.z) + (q1.y * q2.w) + (q1.z * q2.x) + (q1.w * q2.y),
.z = (q1.x * q2.y) - (q1.y * q2.x) + (q1.z * q2.w) + (q1.w * q2.z),
.w = (-q1.x * q2.x) - (q1.y * q2.y) - (q1.z * q2.z) + (q1.w * q2.w),
};
}

inline Quaternion operator*(float value) const {
return {
x * value,
y * value,
z * value,
w * value,
};
}

inline Quaternion operator/(float value) const {
return {
x / value,
y / value,
z / value,
w / value,
};
}

inline float length() const {
return std::sqrt(x * x + y * y + z * z + w * w);
}

inline Quaternion normalized() const {
return *this / length();
}

Vector3 transform(const Vector3& v) const;
};

struct Transform {
Vector3 position;
float scale;
Quaternion rotation;

Transform concat(const Transform& other);
};
}
#endif // MATH_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "AbstractVisualBackend.h"
using namespace renderer::visualbackend;


32 changes: 16 additions & 16 deletions lib/renderer/src/renderer/visualbackend/AbstractVisualBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "../common.h"
#include "../ResourceId.h"
#include "../vectormath.h"

namespace renderer::visualbackend {
struct MapDescription {
Expand All @@ -25,30 +26,20 @@ namespace renderer::visualbackend {
float aspect;
float near_plane;
float far_plane;
};

struct Vector3 {
float x;
float y;
float z;
};
};

struct Quaternion {
float x;
float y;
float z;
float w;
struct ModelHandle {
uint64_t handle;
};

struct Transform {
Vector3 position;
Quaternion rotation;
struct ModelInstanceHandle {
uint64_t handle;
};

class AbstractVisualBackend {
public:
virtual void camera_set_projection(const CameraProjection& camera_projection) = 0;
virtual void camera_set_transform(const Transform& transform) = 0;
virtual void camera_set_transform(const vectormath::Transform& transform) = 0;

// Creates HeightMap from description
virtual void map_create(const MapDescription& map_description) = 0;
Expand All @@ -67,6 +58,15 @@ namespace renderer::visualbackend {
// Call this on screen resolution change
virtual void set_screen_resolution(int32_t width, int32_t height) = 0;

// TODO: replace void* with Model*
virtual ModelHandle model_create(const char* name, void* model) = 0;
virtual void model_destroy(ModelHandle model_handle) = 0;

virtual ModelInstanceHandle model_instance_create(ModelHandle model_handle, uint8_t color_id) = 0;
virtual void model_instance_destroy(ModelInstanceHandle model_instance_handle) = 0;
virtual void model_instance_set_transform(ModelInstanceHandle model_instance_handle, const vectormath::Transform& transform) = 0;
virtual void model_instance_set_visible(ModelInstanceHandle model_instance_handle, bool visible) = 0;

// Renders the scene into the viewport with size viewport_width*viewport_height and with camera position *camera_pos_XXX*
// TODO: need to discuss and refactor this function signature
virtual void render(const Rect& viewport) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
using namespace renderer::visualbackend;

std::unique_ptr<VisualBackendContext> VisualBackendContext::_instance(nullptr);
bool VisualBackendContext::_renderer_enabled(true);
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ namespace renderer::visualbackend {
_renderer = std::move(renderer);
}

static bool renderer_enabled() {
return _renderer_enabled;
}

private:
std::unique_ptr<AbstractVisualBackend> _renderer;
static std::unique_ptr<VisualBackendContext> _instance;
static bool _renderer_enabled;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void DummyVisualBackend::camera_set_projection(const CameraProjection &camera_pr

}

void DummyVisualBackend::camera_set_transform(const Transform &transform)
void DummyVisualBackend::camera_set_transform(const vectormath::Transform &transform)
{

}
Expand All @@ -45,3 +45,38 @@ void DummyVisualBackend::map_update_palette(uint32_t *palette, int32_t palette_s

}

void DummyVisualBackend::set_screen_resolution(int32_t width, int32_t height)
{

}

ModelHandle DummyVisualBackend::model_create(const char* name, void* model)
{

}

void DummyVisualBackend::model_destroy(ModelHandle model_handle)
{

}

ModelInstanceHandle DummyVisualBackend::model_instance_create(ModelHandle model_handle, uint8_t color_id)
{

}

void DummyVisualBackend::model_instance_destroy(ModelInstanceHandle model_instance_handle)
{

}

void DummyVisualBackend::model_instance_set_transform(ModelInstanceHandle model_instance_handle, const vectormath::Transform& transform)
{

}

void DummyVisualBackend::destroy()
{

}

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ namespace renderer::visualbackend::dummy {

void camera_set_projection(const CameraProjection &camera_projection) override;

void camera_set_transform(const Transform &transform) override;
void camera_set_transform(const vectormath::Transform &transform) override;

void map_update_palette(uint32_t *palette, int32_t palette_size) override;

void set_screen_resolution(int32_t width, int32_t height);
ModelHandle model_create(const char* name, void* model);
void model_destroy(ModelHandle model_handle);
ModelInstanceHandle model_instance_create(ModelHandle model_handle, uint8_t color_id);
void model_instance_destroy(ModelInstanceHandle model_instance_handle);
void model_instance_set_transform(ModelInstanceHandle model_instance_handle, const vectormath::Transform& transform);
void destroy();
};

}
Expand Down
Loading