Merge branch 'dev' into dev-mod-manager

pyro-refactor
MrSimbax 2020-07-23 18:19:42 +02:00
commit b685d0060c
13 changed files with 160 additions and 54 deletions

View File

@ -13,16 +13,61 @@ jobs:
steps:
- name: Download Colobot dependencies
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends build-essential cmake libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsndfile1-dev libvorbis-dev libogg-dev libpng-dev libglew-dev libopenal-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev libphysfs-dev gettext git po4a vorbis-tools librsvg2-bin xmlstarlet
# TODO: migrate colobot-lint to GitHub Actions
- name: Download colobot-lint dependencies
run: sudo apt-get install -y --no-install-recommends clang-3.6 libtinyxml2.6.2v5
- run: pip install requests
- run: mkdir -p /tmp/colobot-lint
- name: Download colobot-lint
working-directory: /tmp/colobot-lint
shell: python
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO_NAME: colobot/colobot-lint
BRANCH_NAME: master
ARTIFACT_NAME: colobot-lint
run: |
sudo apt-get install -y --no-install-recommends clang-3.6 libtinyxml2.6.2v5
mkdir -p /tmp/colobot-lint
cd /tmp/colobot-lint
wget -O colobot-lint.zip "https://compiled.colobot.info/job/colobot/job/colobot-lint/job/dev/lastSuccessfulBuild/artifact/*zip*/archive.zip"
import os
import requests
# How there can be no builtin action to download the latest artifact from another repo?!
s = requests.Session()
s.headers.update({
'Authorization': 'token ' + os.environ['GITHUB_TOKEN'],
'Accept': 'application/vnd.github.v3+json'
})
r = s.get("https://api.github.com/repos/" + os.environ['REPO_NAME'] + "/actions/runs", params={'branch': os.environ['BRANCH_NAME'], 'event': 'push', 'status': 'success'})
r.raise_for_status()
# Querying for "dev" returns all branches that have "dev" anywhere in the name... is that a GitHub bug or intended behaviour?
runs = list(filter(lambda x: x['head_branch'] == os.environ['BRANCH_NAME'], r.json()['workflow_runs']))
if len(runs) == 0:
raise Exception('No valid run found')
run = runs[0]
print("Using colobot-lint from run #{} ({}) for commit {}".format(run['run_number'], run['id'], run['head_sha']))
r = s.get(run['artifacts_url'])
r.raise_for_status()
artifacts = list(filter(lambda x: x['name'] == os.environ['ARTIFACT_NAME'], r.json()['artifacts']))
if len(artifacts) != 1:
raise Exception('Artifact not found')
artifact = artifacts[0]
print(artifact['archive_download_url'])
r = s.get(artifact['archive_download_url'], stream=True)
r.raise_for_status()
with open(os.environ['ARTIFACT_NAME'] + '.zip', 'wb') as f:
for block in r.iter_content(1024):
f.write(block)
print("Download finished")
- name: Unpack colobot-lint
working-directory: /tmp/colobot-lint
run: |
# Unzip the archive
unzip ./colobot-lint.zip
mkdir archive; cd archive
unzip ../colobot-lint.zip
cd ..
# Workaround for Clang not finding system headers
mkdir ./bin
mv ./archive/build/colobot-lint ./bin/
@ -73,11 +118,11 @@ jobs:
with:
name: HTML results
path: build/html_report
- run: pip install requests
- name: Send linter results to GitHub
shell: python
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ACTUALLY_SEND: ${{ github.event.type != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
run: |
import os
import sys
@ -185,21 +230,25 @@ jobs:
summary = 'colobot-lint found {} issues'.format(len(annotations))
all_ok = len(annotations) == 0
print('Conclusion: {}'.format(summary))
# Annotations have to be sent in batches of 50
first = True
while first or len(annotations) > 0:
first = False
to_send = annotations[:50]
annotations = annotations[50:]
data = {
'output': {
'title': summary,
'summary': summary,
'annotations': to_send
if os.environ['ACTUALLY_SEND'] != "true":
print('Skip uploading the results as annotations because tokens from forks are readonly and there seems to be no way to do it. Blame GitHub Actions devs.')
else:
# Annotations have to be sent in batches of 50
first = True
while first or len(annotations) > 0:
first = False
to_send = annotations[:50]
annotations = annotations[50:]
data = {
'output': {
'title': summary,
'summary': summary,
'annotations': to_send
}
}
}
r = s.patch(check_run['url'], json=data)
r.raise_for_status()
r = s.patch(check_run['url'], json=data)
r.raise_for_status()
sys.exit(0 if all_ok else 1)

View File

@ -448,7 +448,7 @@ float CText::GetStringWidth(const std::string &text,
UTF8Char ch;
int len = StrUtils::Utf8CharSizeAt(text, index);
int len = GetCharSizeAt(font, text, index);
if (len >= 1)
ch.c1 = text[index];
if (len >= 2)
@ -583,7 +583,7 @@ int CText::Justify(const std::string &text, std::vector<FontMetaChar>::iterator
UTF8Char ch;
int len = StrUtils::Utf8CharSizeAt(text, index);
int len = GetCharSizeAt(font, text, index);
if (len >= 1)
ch.c1 = text[index];
if (len >= 2)
@ -624,7 +624,7 @@ int CText::Justify(const std::string &text, FontType font, float size, float wid
{
UTF8Char ch;
int len = StrUtils::Utf8CharSizeAt(text, index);
int len = GetCharSizeAt(font, text, index);
if (len >= 1)
ch.c1 = text[index];
if (len >= 2)
@ -666,12 +666,9 @@ int CText::Detect(const std::string &text, std::vector<FontMetaChar>::iterator f
if (format + fmtIndex != end)
font = static_cast<FontType>(*(format + fmtIndex) & FONT_MASK_FONT);
// TODO: if (font == FONT_BUTTON)
//if (font == FONT_BUTTON) continue;
UTF8Char ch;
int len = StrUtils::Utf8CharSizeAt(text, index);
int len = GetCharSizeAt(font, text, index);
if (len >= 1)
ch.c1 = text[index];
if (len >= 2)
@ -704,7 +701,7 @@ int CText::Detect(const std::string &text, FontType font, float size, float offs
{
UTF8Char ch;
int len = StrUtils::Utf8CharSizeAt(text, index);
int len = GetCharSizeAt(font, text, index);
if (len >= 1)
ch.c1 = text[index];
if (len >= 2)
@ -916,16 +913,7 @@ void CText::StringToUTFCharList(const std::string &text, std::vector<UTF8Char> &
if (format + index != end)
font = static_cast<FontType>(*(format + index) & FONT_MASK_FONT);
int len;
if(font == FONT_BUTTON)
{
len = 1;
}
else
{
len = StrUtils::Utf8CharSizeAt(text, index);
}
int len = GetCharSizeAt(font, text, index);
if (len >= 1)
ch.c1 = text[index];
@ -940,6 +928,20 @@ void CText::StringToUTFCharList(const std::string &text, std::vector<UTF8Char> &
}
}
int CText::GetCharSizeAt(Gfx::FontType font, const std::string& text, unsigned int index) const
{
int len = 0;
if (font == FONT_BUTTON)
{
len = 1;
}
else
{
len = StrUtils::Utf8CharSizeAt(text, index);
}
return len;
}
void CText::DrawString(const std::string &text, FontType font,
float size, Math::IntPoint pos, int width, int eol, Color color)
{

View File

@ -339,6 +339,8 @@ protected:
void StringToUTFCharList(const std::string &text, std::vector<UTF8Char> &chars);
void StringToUTFCharList(const std::string &text, std::vector<UTF8Char> &chars, std::vector<FontMetaChar>::iterator format, std::vector<FontMetaChar>::iterator end);
int GetCharSizeAt(Gfx::FontType font, const std::string& text, unsigned int index) const;
protected:
CEngine* m_engine;
CDevice* m_device;

View File

@ -388,6 +388,7 @@ bool CGL21Device::Create()
uni.modelMatrix = glGetUniformLocation(m_normalProgram, "uni_ModelMatrix");
uni.normalMatrix = glGetUniformLocation(m_normalProgram, "uni_NormalMatrix");
uni.shadowMatrix = glGetUniformLocation(m_normalProgram, "uni_ShadowMatrix");
uni.cameraPosition = glGetUniformLocation(m_normalProgram, "uni_CameraPosition");
uni.primaryTexture = glGetUniformLocation(m_normalProgram, "uni_PrimaryTexture");
uni.secondaryTexture = glGetUniformLocation(m_normalProgram, "uni_SecondaryTexture");
@ -408,6 +409,7 @@ bool CGL21Device::Create()
uni.fogColor = glGetUniformLocation(m_normalProgram, "uni_FogColor");
uni.shadowColor = glGetUniformLocation(m_normalProgram, "uni_ShadowColor");
uni.shadowTexelSize = glGetUniformLocation(m_normalProgram, "uni_ShadowTexelSize");
uni.lightCount = glGetUniformLocation(m_normalProgram, "uni_LightCount");
uni.ambientColor = glGetUniformLocation(m_normalProgram, "uni_Material.ambient");
@ -441,6 +443,7 @@ bool CGL21Device::Create()
glUniformMatrix4fv(uni.modelMatrix, 1, GL_FALSE, matrix.Array());
glUniformMatrix4fv(uni.normalMatrix, 1, GL_FALSE, matrix.Array());
glUniformMatrix4fv(uni.shadowMatrix, 1, GL_FALSE, matrix.Array());
glUniform3f(uni.cameraPosition, 0.0f, 0.0f, 0.0f);
glUniform1i(uni.primaryTexture, 0);
glUniform1i(uni.secondaryTexture, 1);
@ -457,6 +460,7 @@ bool CGL21Device::Create()
glUniform4f(uni.fogColor, 0.8f, 0.8f, 0.8f, 1.0f);
glUniform1f(uni.shadowColor, 0.5f);
glUniform1f(uni.shadowTexelSize, 0.5f);
glUniform1i(uni.lightCount, 0);
}
@ -653,6 +657,7 @@ void CGL21Device::SetTransform(TransformType type, const Math::Matrix &matrix)
else if (type == TRANSFORM_VIEW)
{
Math::Matrix scale;
Math::Vector cameraPosition;
scale.Set(3, 3, -1.0f);
m_viewMat = Math::MultiplyMatrices(scale, matrix);
@ -660,6 +665,13 @@ void CGL21Device::SetTransform(TransformType type, const Math::Matrix &matrix)
m_combinedMatrix = Math::MultiplyMatrices(m_projectionMat, m_modelviewMat);
glUniformMatrix4fv(m_uniforms[m_mode].viewMatrix, 1, GL_FALSE, m_viewMat.Array());
if (m_uniforms[m_mode].cameraPosition >= 0)
{
cameraPosition.LoadZero();
cameraPosition = MatrixVectorMultiply(m_viewMat.Inverse(), cameraPosition);
glUniform3fv(m_uniforms[m_mode].cameraPosition, 1, cameraPosition.Array());
}
}
else if (type == TRANSFORM_PROJECTION)
{
@ -1439,6 +1451,7 @@ void CGL21Device::SetRenderState(RenderState state, bool enabled)
}
else if (state == RENDER_STATE_SHADOW_MAPPING)
{
glUniform1f(m_uniforms[m_mode].shadowTexelSize, 1.0/m_currentTextures[TEXTURE_SHADOW].size.x);
SetTextureEnabled(TEXTURE_SHADOW, enabled);
return;

View File

@ -363,6 +363,7 @@ bool CGL33Device::Create()
uni.modelMatrix = glGetUniformLocation(m_normalProgram, "uni_ModelMatrix");
uni.normalMatrix = glGetUniformLocation(m_normalProgram, "uni_NormalMatrix");
uni.shadowMatrix = glGetUniformLocation(m_normalProgram, "uni_ShadowMatrix");
uni.cameraPosition = glGetUniformLocation(m_normalProgram, "uni_CameraPosition");
uni.primaryTexture = glGetUniformLocation(m_normalProgram, "uni_PrimaryTexture");
uni.secondaryTexture = glGetUniformLocation(m_normalProgram, "uni_SecondaryTexture");
@ -420,6 +421,7 @@ bool CGL33Device::Create()
glUniformMatrix4fv(uni.modelMatrix, 1, GL_FALSE, matrix.Array());
glUniformMatrix4fv(uni.normalMatrix, 1, GL_FALSE, matrix.Array());
glUniformMatrix4fv(uni.shadowMatrix, 1, GL_FALSE, matrix.Array());
glUniform3f(uni.cameraPosition, 0.0f, 0.0f, 0.0f);
glUniform1i(uni.primaryTexture, 0);
glUniform1i(uni.secondaryTexture, 1);
@ -660,6 +662,7 @@ void CGL33Device::SetTransform(TransformType type, const Math::Matrix &matrix)
else if (type == TRANSFORM_VIEW)
{
Math::Matrix scale;
Math::Vector cameraPosition;
scale.Set(3, 3, -1.0f);
m_viewMat = Math::MultiplyMatrices(scale, matrix);
@ -667,6 +670,13 @@ void CGL33Device::SetTransform(TransformType type, const Math::Matrix &matrix)
m_combinedMatrixOutdated = true;
glUniformMatrix4fv(m_uni->viewMatrix, 1, GL_FALSE, m_viewMat.Array());
if (m_uni->cameraPosition >= 0)
{
cameraPosition.LoadZero();
cameraPosition = MatrixVectorMultiply(m_viewMat.Inverse(), cameraPosition);
glUniform3fv(m_uni->cameraPosition, 1, cameraPosition.Array());
}
}
else if (type == TRANSFORM_PROJECTION)
{

View File

@ -167,6 +167,8 @@ struct UniformLocations
GLint shadowMatrix = -1;
//! Normal matrix
GLint normalMatrix = -1;
//! Camera position
GLint cameraPosition = -1;
//! Primary texture sampler
GLint primaryTexture = -1;
@ -193,6 +195,8 @@ struct UniformLocations
//! Shadow color
GLint shadowColor = -1;
//! Shadow texel size
GLint shadowTexelSize = -1;
// Number of enabled lights
GLint lightCount = -1;

View File

@ -35,6 +35,7 @@ uniform vec2 uni_FogRange;
uniform vec4 uni_FogColor;
uniform float uni_ShadowColor;
uniform float uni_ShadowTexelSize;
struct LightParams
{
@ -56,6 +57,7 @@ uniform Material uni_Material;
uniform int uni_LightCount;
uniform LightParams uni_Light[4];
varying vec3 pass_CameraDirection;
varying float pass_Distance;
varying vec4 pass_Color;
varying vec3 pass_Normal;
@ -76,16 +78,17 @@ void main()
vec4 specular = vec4(0.0f);
vec3 normal = normalize(pass_Normal);
vec3 camera = normalize(pass_CameraDirection);
for (int i = 0; i < uni_LightCount; i++)
{
LightParams light = uni_Light[i];
vec3 lightDirection = light.Position.xyz;
vec3 reflectDirection = -reflect(lightDirection, normal);
vec3 lightDirection = normalize(light.Position.xyz);
vec3 reflectAxis = normalize(lightDirection + camera);
float diffuseComponent = clamp(dot(normal, lightDirection), 0.0f, 1.0f);
float specularComponent = clamp(pow(dot(normal, lightDirection + reflectDirection), 10.0f), 0.0f, 1.0f);
float specularComponent = pow(clamp(dot(normal, reflectAxis), 0.0f, 1.0f), 10.0f);
ambient += light.Ambient;
diffuse += diffuseComponent * light.Diffuse;
@ -97,13 +100,11 @@ void main()
if (uni_TextureEnabled[2])
{
#ifdef CONFIG_QUALITY_SHADOWS
float offset = 0.00025f;
float value = (1.0f / 5.0f) * (shadow2D(uni_ShadowTexture, pass_TexCoord2).x
+ shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3( offset, 0.0f, 0.0f)).x
+ shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3(-offset, 0.0f, 0.0f)).x
+ shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3( 0.0f, offset, 0.0f)).x
+ shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3( 0.0f, -offset, 0.0f)).x);
+ shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3( uni_ShadowTexelSize, 0.0f, 0.0f)).x
+ shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3(-uni_ShadowTexelSize, 0.0f, 0.0f)).x
+ shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3( 0.0f, uni_ShadowTexelSize, 0.0f)).x
+ shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3( 0.0f, -uni_ShadowTexelSize, 0.0f)).x);
shadow = mix(uni_ShadowColor, 1.0f, value);
#else

View File

@ -24,7 +24,9 @@ uniform mat4 uni_ViewMatrix;
uniform mat4 uni_ModelMatrix;
uniform mat4 uni_ShadowMatrix;
uniform mat4 uni_NormalMatrix;
uniform vec3 uni_CameraPosition;
varying vec3 pass_CameraDirection;
varying float pass_Distance;
varying vec4 pass_Color;
varying vec3 pass_Normal;
@ -40,6 +42,7 @@ void main()
gl_Position = uni_ProjectionMatrix * eyeSpace;
pass_CameraDirection = uni_CameraPosition - position.xyz;
pass_Color = gl_Color;
pass_Normal = normalize((uni_NormalMatrix * vec4(gl_Normal, 0.0f)).xyz);
pass_Distance = abs(eyeSpace.z / eyeSpace.w);

View File

@ -63,6 +63,7 @@ in VertexData
vec4 ShadowCoord;
vec4 LightColor;
float Distance;
vec3 CameraDirection;
} data;
out vec4 out_FragColor;
@ -78,17 +79,17 @@ void main()
vec4 specular = vec4(0.0f);
vec3 normal = normalize(data.Normal);
vec3 camera = normalize(data.CameraDirection);
for (int i = 0; i < uni_LightCount; i++)
{
vec3 lightDirection = uni_Light[i].Position.xyz;
vec3 reflectDirection = -reflect(lightDirection, normal);
vec3 lightDirection = normalize(uni_Light[i].Position.xyz);
vec3 reflectAxis = normalize(lightDirection + camera);
ambient += uni_Light[i].Ambient;
diffuse += clamp(dot(normal, lightDirection), 0.0f, 1.0f)
* uni_Light[i].Diffuse;
specular += clamp(pow(dot(normal, lightDirection + reflectDirection), 10.0f), 0.0f, 1.0f)
specular += pow(clamp(dot(normal, reflectAxis), 0.0f, 1.0f), 10.0f)
* uni_Light[i].Specular;
}

View File

@ -25,6 +25,7 @@ uniform mat4 uni_ViewMatrix;
uniform mat4 uni_ModelMatrix;
uniform mat4 uni_ShadowMatrix;
uniform mat4 uni_NormalMatrix;
uniform vec3 uni_CameraPosition;
layout(location = 0) in vec4 in_VertexCoord;
layout(location = 1) in vec3 in_Normal;
@ -41,6 +42,7 @@ out VertexData
vec4 ShadowCoord;
vec4 LightColor;
float Distance;
vec3 CameraDirection;
} data;
void main()
@ -56,4 +58,5 @@ void main()
data.Normal = normalize((uni_NormalMatrix * vec4(in_Normal, 0.0f)).xyz);
data.ShadowCoord = vec4(shadowCoord.xyz / shadowCoord.w, 1.0f);
data.Distance = abs(eyeSpace.z);
data.CameraDirection = uni_CameraPosition - position.xyz;
}

View File

@ -142,6 +142,8 @@ CObject* CObjectManager::CreateObject(ObjectCreateParams params)
}
}
params.power = ClampPower(params.type,params.power);
assert(m_objects.find(params.id) == m_objects.end());
auto objectUPtr = m_objectFactory->CreateObject(params);
@ -163,10 +165,20 @@ CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, ObjectType
params.angle = angle;
params.type = type;
params.power = power;
return CreateObject(params);
}
float CObjectManager::ClampPower(ObjectType type, float power)
{
float min = 0;
float max = 100;
if (type == OBJECT_POWER || type == OBJECT_ATOMIC)
{
max = 1;
}
return Math::Clamp(power, min, max);
}
std::vector<CObject*> CObjectManager::GetObjectsOfTeam(int team)
{
std::vector<CObject*> result;

View File

@ -303,6 +303,8 @@ public:
//@}
private:
//! Prevents creation of overcharged power cells
float ClampPower(ObjectType type, float power);
void CleanRemovedObjectsIfNeeded();
private:

View File

@ -1565,7 +1565,11 @@ bool CScriptFunctions::rProduce(CBotVar* var, CBotVar* result, int& exception, v
{
power = 1.0f;
}
object = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, type, power);
bool exists = !std::string(GetObjectName(type)).empty(); //The object type exists in object_type.h
if (exists)
{
object = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, type, power);
}
if (object == nullptr)
{
result->SetValInt(1); // error