Skip to content

Commit

Permalink
shell and slate
Browse files Browse the repository at this point in the history
  • Loading branch information
popojan committed Dec 3, 2021
1 parent 50a104f commit d96e9bc
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ ExternalProject_Add(project_libsgfcplusplus
SOURCE_DIR ${CMAKE_SOURCE_DIR}/deps/libsgfcplusplus
BINARY_DIR ${CMAKE_BINARY_DIR}/deps/libsgfcplusplus
STEP_TARGETS build
UPDATE_DISCONNECTED TRUE
UPDATE_COMMAND git restore --source=HEAD --staged --worktree -- sgfc
COMMAND git fetch
COMMAND git checkout sgfc
INSTALL_COMMAND echo Skipping install step for libsndfile
)

Expand Down
3 changes: 2 additions & 1 deletion data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"name": "Pachi 10.00",
"path": "./engine/pachi",
"command": "pachi",
"parameters": "-t _120 threads=2,maximize_score"
"parameters": "-t _120 threads=2,maximize_score",
"enabled": 0
},
{
"name": "Katago #170 b20",
Expand Down
34 changes: 21 additions & 13 deletions data/shaders/fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 330
#version 300 es
precision highp float;

/* === DO NOT CHANGE BELOW === */
Expand Down Expand Up @@ -132,9 +132,9 @@ const vec3 bgB = vec3(0.0, 0.0, 0.0);

const Material mCupBlack = Material(idCupBlack, vec3(0.4, 0.6, 0.15), 16.0, vec3(0.65826, 0.528209, 0.238209), vec3(0.387763, 0.3289191, 0.12761), vec3(0.22005, 0.180002, 0.1244), 1.3);
const Material mCupWhite = Material(idCupWhite, vec3(0.4, 0.6, 0.15), 16.0, vec3(0.45826, 0.428209, 0.238209), vec3(0.287763, 0.289191, 0.12761), vec3(0.12005, 0.120002, 0.085744), 1.3);
const Material mBoard = Material(idBoard, vec3(0.7, 0.3, 0.05), 42.0, vec3(0.93333, 0.713725, 0.38039), vec3(0.53333,0.313725,0.09039), vec3(0.7333,0.613725,0.19039), 1.5);
const Material mBoard = Material(idBoard, 1.3*vec3(0.7, 0.3, 0.05), 42.0, vec3(0.93333, 0.713725, 0.38039), vec3(0.53333,0.313725,0.09039), vec3(0.7333,0.613725,0.19039), 1.5);
const Material mTable = Material(idTable, vec3(1.2, 0.15, 0.0), 4.0, vec3(0.566,0.1196,0.0176), vec3(0.766,0.3196,0.2176), vec3(0.666,0.2196,0.1176), 0.0);
const Material mWhite = Material(idWhiteStone, vec3(0.23, 0.63, 0.2), 42.0, vec3(0.94), vec3(0.92,0.97,0.67), vec3(0.92), 0.5);
const Material mWhite = Material(idWhiteStone, vec3(0.23, 0.73, 0.2), 42.0, vec3(0.96), vec3(0.86,0.82,0.87), vec3(0.93), 0.5);
const Material mBlack = Material(idBlackStone, vec3(0.23, 0.83, 0.15), 28.0, vec3(0.08), vec3(0.04), vec3(0.10), 0.5);
const Material mRed = Material(idLastBlackStone, vec3(0.3, 0.7, 0.25), 4.0, vec3(0.5, 0.0, 0.0), vec3(0.5, 0.0, 0.0), vec3(0.5, 0.0, 0.0), 0.0);
const Material mBack = Material(idBack, vec3(0.0, 1.0, 0.0), 1.0, bgA, bgB, bgA, 0.0);
Expand Down Expand Up @@ -1040,8 +1040,12 @@ vec2 softshadow(in vec3 pos, in vec3 nor, const vec3 lig, const float ldia, int
else {
vec3 u = normalize(cross(nor, nBoard));
vec3 v = cross(u, nor);
float acs = acos(dot(v, normalize(vec3(pos.x, 0.000, pos.z) - vec3(xz.x, 0.0, xz.y))));
//ret.y *= min(1.0, acs / PI);
vec3 diff = vec3(pos.x, 0.000, pos.z) - vec3(xz.x, 0.0, xz.y);
if(length(diff) > 0.01) {
float acs = acos(dot(v, normalize(diff)));
//ret.y *= min(1.0, acs / PI);
ret.y *= mix(1.0,min(1.0, acs / PI),2.0*(length(diff)-0.01)/ww);
}
}
}
if (isBoard && pos.y > -0.001){
Expand Down Expand Up @@ -1151,15 +1155,16 @@ Material getMaterialColor(in Intersection ip, out vec3 mcol, in vec3 rd, in vec3
float sfreq;
float mixcoef, smult1, smult2, smult3, sadd1, mixmult;
float fpow = 1.0;
mixmult = 1.0;
mixmult = 0.0;
smult1 = 0.0;
smult2 = 0.0;
smult3 = 1.0;
mcol = m0.clrA;
vec3 mcolb = m0.clrB;
vec3 mcolc = m0.clrC;
vec3 scrd2 = 64.0*(ip.p-ip.dummy.xyz);
vec3 scrd = ip.p.xyz - ip.dummy.xyz;
vec3 flr = ip.dummy.xyz;
vec3 scrd2 = 64.0*(ip.p.xyz-flr);
vec3 scrd = ip.p.xyz - flr;
float degrade = (1.0 + floor(length(ro) / 3.0));
vec2 xz;
xz = scrd.xz;
Expand All @@ -1171,6 +1176,7 @@ Material getMaterialColor(in Intersection ip, out vec3 mcol, in vec3 rd, in vec3
scoord.xyz = 0.1*vec3(length(scoord.yz));
noisy = true;
scrd = scoord;
mixmult = 0.015;
}
else if (mat.id == mGrid.id) {
scoord = 350.0*scrd;
Expand All @@ -1191,12 +1197,13 @@ Material getMaterialColor(in Intersection ip, out vec3 mcol, in vec3 rd, in vec3
scrd2 *= 5.0;
}
else {
scrd2 *= 3.0;
//scrd2 *= 3.0;
vec2 xz = mat2(cosa, sina, -sina, cosa)*scrd2.xz;
scrd2 = xz.xyy;
scrd2.y = scrd.y;
scrd2.z = 1.0;
}
mixmult = 0.015;
}
if (m0.id == mTable.id) {
vec3 color;// = mix(mTable.clrA,mTable.clrB,density);
Expand Down Expand Up @@ -1236,7 +1243,7 @@ Material getMaterialColor(in Intersection ip, out vec3 mcol, in vec3 rd, in vec3
float sina = sin(alpha);
xz = mat2(cosa, sina, -sina, cosa)*ip.p.xz;
scoord = 16.0*vec3(xz.x, ip.p.y, xz.y) + vec3(0.0, 0.25, 0.0);
scrd = 13.3*scoord;
scrd = 3.3*scoord;
noisy = true;
const float al = 0.15;
float mixt = exp(-0.35*max(0.0, length(ip.p)));
Expand All @@ -1249,8 +1256,8 @@ Material getMaterialColor(in Intersection ip, out vec3 mcol, in vec3 rd, in vec3
vec3 grad = vec3(0.0, 1.0, 0.0);
vec3 grad2 = vec3(0.0, 1.0, 0.0);
//if (noisy) {
rnd2 = snoise(scrd2, grad2);
rnd = snoise(scrd, grad);
rnd2 = snoise(scrd2+grad, grad2);
//}
if (mat.id == mBoard.id || mat.id == mCupBlack.id || mat.id == mCupWhite.id) {
float w1 = 3.0*length(scoord.yx - 0.5*vec2(1.57 + 3.1415*rnd));
Expand All @@ -1264,10 +1271,11 @@ Material getMaterialColor(in Intersection ip, out vec3 mcol, in vec3 rd, in vec3
smult1 = clamp(abs(rnd),0.0,1.0);
smult2 = clamp(abs(rnd2),0.0,1.0);
smult3 = 0.5;//clamp(abs(grad.z),0.0,1.0);
mixmult = 1.0;
mixmult = 0.0;
}
mcol = mix(mix(mcol, mcolb, smult2), mix(mcol, mcolc, 1.0 - smult2), smult1);
nn = normalize(mix(ip.n, grad2, 0.015));
nn = normalize(mix(ip.n, grad2, mixmult));
//nn = ip.n;
return mat;
}

Expand Down
1 change: 0 additions & 1 deletion engine/install-engines.bat

This file was deleted.

15 changes: 5 additions & 10 deletions src/Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ double Board::fixStone(int i, int j, int i0, int j0, size_t rep) {
p.y = v.y;
spdlog::debug("2nd IF [{},{}]->[{},{}]", x0,y0, p.x,p.y);
unsigned idx = ((boardSize * i0 + j0) << 2u) + 2u;
x = glstones[idx - 2];
y = glstones[idx - 1];
x = glstones[idx - 2];
y = glstones[idx - 1];
glstones[idx0 - 2] = p.x;
glstones[idx0 - 1] = p.y;
Point& pt = (*this)[Position(j0, i0)];
Expand Down Expand Up @@ -199,7 +199,8 @@ double Board::placeFuzzy(const Position& p, bool nofix){
(*this)[p].x = x;
(*this)[p].y = y;

glstones[idx + 1] = 3.14f*dist(generator);
//random rotation for the first time
glstones[idx + 1] = randomStoneRotation;
if(nofix == false) {
if (i + 1 < boardSize)
ret = std::max(ret, fixStone(i, j, i + 1u, j));
Expand Down Expand Up @@ -244,7 +245,7 @@ int Board::stoneChanged(const Position& p, const Color& c) {
removeOverlay(p);
}
//TODO refactor arrays and indexing to simplify
glstones[idx + 0] = mValue;
glstones[idx + 0] = mValue;
(*this)[p].stone = c;
return ret;
}
Expand Down Expand Up @@ -573,10 +574,4 @@ double Board::placeCursor(const Position& coord, const Color& col) {
pos.y = coord.row() + add.y;

return stoneChanged(pos, col);
/*int oidx = ((boardSize * coord.row() + coord.col()) << 2u) + 2u;
spdlog::debug("oidx = [{},{}] = {} ... {} {}", coord.col(), coord.row(), oidx, board[coord].toString(), col.toString());
double altered = placeFuzzy(coord);
stones[oidx + 0] = (col == Color::WHITE) ? mWhite : mBlack;
spdlog::debug("overlay coord = [{},{}] = {}", stones[oidx - 2], stones[oidx - 1], stones[oidx + 0]);*/
//return 0.2;//std::min(1.0, altered);
}
18 changes: 11 additions & 7 deletions src/Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,18 @@ class Board
int updateStones(const Board& previous, bool showTerritory);

bool isEmpty() const;
bool toggleTerritory();
bool toggleTerritoryAuto(bool);
bool toggleTerritory();
bool toggleTerritoryAuto(bool);

double placeCursor(const Position& p, const Color& col);
double placeCursor(const Position& p, const Color& col);
double placeFuzzy(const Position& p, bool nofix = false);

bool collides(int i, int j, int i0, int j0);
void removeOverlay(const Position& p);
void setOverlay(const Position& p, const std::string& text, const Color& c);

void setRandomStoneRotation() {
randomStoneRotation = 3.1415f * udist(generator);
}
private:

inline int ord(const Position& p) const {
Expand All @@ -244,19 +246,21 @@ class Board

std::default_random_engine generator;
std::normal_distribution<float> dist;
std::uniform_real_distribution<float> udist;

bool invalidated;

const static float mEmpty;
double randomStoneRotation;

public:
volatile long positionNumber;
volatile long positionNumber;
bool showTerritory;
bool showTerritoryAuto;
bool territoryReady;
private:
int lastPlayed_i, lastPlayed_j;
Position cursor;
int lastPlayed_i, lastPlayed_j;
Position cursor, lastCursor;
volatile long moveNumber;
public:
double collision;
Expand Down
6 changes: 5 additions & 1 deletion src/GobanView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,13 @@ int GobanView::updateCursor(const Position& lastCursor){
int ret = 0;
auto& np = model.board[cursor];

if(state.holdsStone != model.state.holdsStone) {
board.setRandomStoneRotation();
state.holdsStone = model.state.holdsStone;
}
if(model.state.holdsStone && model.isPointOnBoard(cursor) && np.stone == Color::EMPTY){
board.placeCursor(cursor, state.colorToMove);
}
state.holdsStone = model.state.holdsStone;
return ret;
}

Expand All @@ -372,6 +375,7 @@ void GobanView::onGameMove(const Move& move) {
board.removeOverlay(lastMove);
}
lastMove = move.pos;
board.setRandomStoneRotation();
board.setOverlay(move.pos, ss.str(), move.col);
}
}
32 changes: 32 additions & 0 deletions src/sound/StreamHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
#include "StreamHandler.hpp"
#include <spdlog/spdlog.h>

#include <Rocket/Core/Platform.h>

#if defined(ROCKET_PLATFORM_LINUX)
#include <alsa/error.h>
#include <cstdarg>
#include <cstdio>

void alsa_error_callback (
const char *file,
int line,
const char *function,
int err, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
char * msg;
vasprintf(&msg, fmt, args);
if(err >= SND_ERROR_BEGIN)
spdlog::error("Alsa error {} in {} at {}:{}: {}", err, function, file, line, msg);
else
spdlog::warn("Alsa info {} in {} at {}:{}: {}", err, function, file, line, msg);
free(msg);
va_end(args);
}
#endif

int StreamHandler::PortAudioCallback(const void * input,
void * output,
unsigned long frameCount,
Expand Down Expand Up @@ -123,6 +149,10 @@ void StreamHandler::init() {
//putenv(latency);
#endif

#if defined(ROCKET_PLATFORM_LINUX)
snd_lib_error_set_handler(alsa_error_callback);
#endif

Pa_Initialize();
PaError errorCode;
PaStreamParameters outputParameters;
Expand Down Expand Up @@ -155,10 +185,12 @@ void StreamHandler::init() {

StreamHandler::~StreamHandler()
{
spdlog::debug("PortAudio Termination in progress..");
Pa_CloseStream(stream);
for (auto wrapper : data)
{
delete wrapper;
}
Pa_Sleep(1000);
Pa_Terminate();
}

0 comments on commit d96e9bc

Please sign in to comment.