Skip to content
Merged
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
6 changes: 5 additions & 1 deletion src/BoardView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ Item {
specularAAEnabled: true
tonemapMode: SceneEnvironment.TonemapModeAces
}
// Two surfaces dress the whole scene, shared by every square and piece: the set's own, and the pale wood of Atelier's light side.
Texture { id: surfaceMap; textureData: SurfaceTexture { style: board.design } tilingModeHorizontal: Texture.Repeat; tilingModeVertical: Texture.Repeat }
Texture { id: paleMap; textureData: SurfaceTexture { style: 5 } tilingModeHorizontal: Texture.Repeat; tilingModeVertical: Texture.Repeat }
Node {
eulerRotation: Qt.vector3d(board.elevation,board.azimuth,0)
PerspectiveCamera { id: camera; z: board.distance; clipNear: .1; clipFar: 150; fieldOfView: board.lens }
Expand Down Expand Up @@ -176,7 +178,7 @@ Item {
y: .04
scale: Qt.vector3d(.00996,.001,.00996)
materials: PrincipledMaterial {
baseColorMap: Texture { textureData: SurfaceTexture { style: board.design === 1 && (Math.floor(tile.index / 8) + tile.index % 8) % 2 === 1 ? 5 : board.design } }
baseColorMap: board.design === 1 && (Math.floor(tile.index / 8) + tile.index % 8) % 2 === 1 ? paleMap : surfaceMap
baseColor: tile.marked ? board.accents[board.design] : (Math.floor(index / 8) + index % 8) % 2 === 1 ? board.lightSquares[board.design] : board.darkSquares[board.design]
roughness: board.design === 3 ? .3 : .55
metalness: board.design === 0 ? .15 : 0
Expand All @@ -202,6 +204,8 @@ Item {
design: board.design
seat: board.seat
motion: board.motion
grain: surfaceMap
paleGrain: paleMap
clock: board.clock
attention: backend.selected
selected: backend.selected === record.square && record.alive
Expand Down
6 changes: 4 additions & 2 deletions src/ChessPiece.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Node {
required property bool motion
required property bool selected
required property real seat
// The scene's shared surfaces: the set's own, and Atelier's pale wood.
required property Texture grain
required property Texture paleGrain
property real lift: 0
// Followed by hand, like `place`, so a capture can be timed to its captor's arrival.
property bool alive: record.alive
Expand Down Expand Up @@ -266,10 +269,9 @@ Node {
property int boardSquare: piece.record.square
pickable: piece.record.alive
geometry: SculptGeometry { kind: piece.record.kind; design: piece.design; tone: piece.record.white ? 0 : 1; part: 0 }
Texture { id: surface; textureData: SurfaceTexture { style: piece.design === 1 ? (piece.record.white ? 5 : 1) : piece.design } tilingModeVertical: Texture.Repeat }
// Ceramic or gunmetal, polished wood, painted carving, boiled sugar.
materials: PrincipledMaterial {
baseColorMap: piece.woodland ? null : surface
baseColorMap: piece.woodland ? null : piece.design === 1 && piece.record.white ? piece.paleGrain : piece.grain
baseColor: piece.bodyColor
vertexColorsEnabled: true
metalness: piece.design === 0 ? (piece.record.white ? .2 : .5) : 0
Expand Down
37 changes: 31 additions & 6 deletions src/sculptgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,25 @@
#include <QVector2D>
#include <QVector3D>
#include <QVector4D>
#include <QtConcurrent>
#include <algorithm>
#include <map>

SculptGeometry::SculptGeometry(QQuick3DObject *parent) : QQuick3DGeometry(parent) { rebuild(); }
void SculptGeometry::setKind(int value) { if (m_kind != value) { m_kind=value; rebuild(); emit changed(); } }
void SculptGeometry::setDesign(int value) { if (m_design != value) { m_design=value; rebuild(); emit changed(); } }
void SculptGeometry::setPart(int value) { if (m_part != value) { m_part=value; rebuild(); emit changed(); } }
void SculptGeometry::setTone(int value) { if (m_tone != value) { m_tone=value; rebuild(); emit changed(); } }
// Nothing is sculpted for the defaults a geometry starts with: one made in code builds on its first setter,
// and one declared in QML waits for the last of them, so neither casts a figure nobody asked for.
SculptGeometry::SculptGeometry(QQuick3DObject *parent) : QQuick3DGeometry(parent) {}
void SculptGeometry::setKind(int value) { const bool moved=m_kind != value; m_kind=value; if (moved || !m_built) { rebuild(); if (moved) emit changed(); } }
void SculptGeometry::setDesign(int value) { const bool moved=m_design != value; m_design=value; if (moved || !m_built) { rebuild(); if (moved) emit changed(); } }
void SculptGeometry::setPart(int value) { const bool moved=m_part != value; m_part=value; if (moved || !m_built) { rebuild(); if (moved) emit changed(); } }
void SculptGeometry::setTone(int value) { const bool moved=m_tone != value; m_tone=value; if (moved || !m_built) { rebuild(); if (moved) emit changed(); } }
void SculptGeometry::componentComplete() {
QQuick3DGeometry::componentComplete();
m_declared=false;
rebuild();
}
void SculptGeometry::rebuild() {
if(m_declared) return;
m_built=true;
// Sculpting takes a moment, so every part is made once and shared by all the pieces that wear it.
struct Sculpture { QByteArray vertices, indices; QVector3D minimum, maximum; };
static std::map<int,Sculpture> sculptures;
Expand All @@ -39,8 +49,23 @@ void SculptGeometry::rebuild() {
const auto found=sculptures.find(key);
if(found!=sculptures.end()) { upload(found->second); return; }
// Moss & Myth figures are whole painted carvings; the other sets are cast part by part.
// A cast set is wanted whole the moment one part of it is, so its parts are cast side by side on every core
// rather than one after another while the window waits. Moss & Myth carves its six figures the same way.
static std::map<int,SculptFigure> cast;
static bool poured[4]={};
if(!woodland && m_part<4 && !poured[m_design]) {
poured[m_design]=true;
struct Job { int kind,part; SculptFigure figure; };
QList<Job> jobs;
for(int kind=1;kind<=6;++kind) for(int part=0;part<4;++part) jobs.append({kind,part,{}});
const int design=m_design;
QtConcurrent::blockingMap(jobs,[design](Job &job) { job.figure=Figures::part(design,job.kind,job.part); });
for(Job &job:jobs) cast.emplace((design*6+job.kind-1)*6+job.part,std::move(job.figure));
}
SculptFigure figure;
if(!woodland) figure=Figures::part(m_design,m_kind,m_part);
const auto ready=cast.find((m_design*6+m_kind-1)*6+m_part);
if(!woodland && ready!=cast.end()) { figure=std::move(ready->second); cast.erase(ready); }
else if(!woodland) figure=Figures::part(m_design,m_kind,m_part);
else if(m_part==0) figure=Woodland::figure(m_kind,m_tone);
// A part a piece does not have is a single point, which draws nothing.
if(figure.vertices.empty()) {
Expand Down
4 changes: 4 additions & 0 deletions src/sculptgeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ class SculptGeometry : public QQuick3DGeometry {
void setDesign(int value);
void setPart(int value);
void setTone(int value);
// A geometry declared in QML is built once, when all four of its properties are in.
void classBegin() override { m_declared = true; }
void componentComplete() override;
signals:
void changed();
private:
void rebuild();
int m_kind = 1, m_design = 0, m_part = 0, m_tone = 0;
bool m_declared = false, m_built = false;
};
9 changes: 7 additions & 2 deletions src/surfacetexture.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "surfacetexture.h"
#include <QHash>
#include <algorithm>
#include <QSize>
#include <cmath>
Expand All @@ -12,9 +13,13 @@ void SurfaceTexture::rebuild() {
const int width = 256, height = m_style == 4 ? 128 : 256;
setSize({width,height});
setHasTransparency(false);
setFormat(m_style == 4 ? QQuick3DTextureData::RGBA32F : QQuick3DTextureData::RGBA8);
// Each surface is computed once and shared by every texture that shows it.
static QHash<int,QByteArray> surfaces;
const auto made = surfaces.constFind(m_style);
if (made != surfaces.constEnd()) { setTextureData(*made); return; }
QByteArray data;
if (m_style == 4) {
setFormat(QQuick3DTextureData::RGBA32F);
data.resize(width*height*4*sizeof(float));
for (int y=0;y<height;++y) for (int x=0;x<width;++x) {
// Procedural probe rows run from nadir to zenith.
Expand All @@ -33,7 +38,6 @@ void SurfaceTexture::rebuild() {
std::memcpy(data.data()+(y*width+x)*sizeof(pixel),pixel,sizeof(pixel));
}
} else {
setFormat(QQuick3DTextureData::RGBA8);
data.resize(width*height*4);
for (int y=0;y<height;++y) for (int x=0;x<width;++x) {
float noise=std::sin(x*.73f+y*1.37f)*std::sin(x*2.27f-y*.37f);
Expand All @@ -49,5 +53,6 @@ void SurfaceTexture::rebuild() {
data[offset]=shade; data[offset+1]=shade; data[offset+2]=shade; data[offset+3]=char(255);
}
}
surfaces.insert(m_style,data);
setTextureData(data);
}
10 changes: 9 additions & 1 deletion src/woodland.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "woodland.h"
#include <thread>
#include "clay.h"
#include <algorithm>
#include <cmath>
Expand Down Expand Up @@ -604,8 +605,15 @@ const Woodland::Figure &Woodland::figure(int kind,int tone) {
const int key=kind*2+(tone ? 1 : 0);
const auto found=figures.find(key);
if(found!=figures.end()) return found->second;
// The first figure asked for has all six carved, each on a thread of its own: a set is never wanted one figure at a time.
if(carvings.empty()) {
Carving carved[6];
std::vector<std::thread> carvers;
for(int each=0;each<6;++each) carvers.emplace_back([&carved,each] { carved[each]=sculpture(each+1); });
for(auto &carver:carvers) carver.join();
for(int each=0;each<6;++each) carvings.emplace(each+1,std::move(carved[each]));
}
auto carving=carvings.find(kind);
if(carving==carvings.end()) carving=carvings.emplace(kind,sculpture(kind)).first;
const Carving &carved=carving->second;
Figure figure;
figure.indices=carved.indices;
Expand Down
Loading