hexsha
stringlengths 40
40
| size
int64 7
1.05M
| ext
stringclasses 13
values | lang
stringclasses 1
value | max_stars_repo_path
stringlengths 4
269
| max_stars_repo_name
stringlengths 5
109
| max_stars_repo_head_hexsha
stringlengths 40
40
| max_stars_repo_licenses
listlengths 1
9
| max_stars_count
int64 1
191k
⌀ | max_stars_repo_stars_event_min_datetime
stringlengths 24
24
⌀ | max_stars_repo_stars_event_max_datetime
stringlengths 24
24
⌀ | max_issues_repo_path
stringlengths 4
269
| max_issues_repo_name
stringlengths 5
116
| max_issues_repo_head_hexsha
stringlengths 40
40
| max_issues_repo_licenses
listlengths 1
9
| max_issues_count
int64 1
48.5k
⌀ | max_issues_repo_issues_event_min_datetime
stringlengths 24
24
⌀ | max_issues_repo_issues_event_max_datetime
stringlengths 24
24
⌀ | max_forks_repo_path
stringlengths 4
269
| max_forks_repo_name
stringlengths 5
116
| max_forks_repo_head_hexsha
stringlengths 40
40
| max_forks_repo_licenses
listlengths 1
9
| max_forks_count
int64 1
105k
⌀ | max_forks_repo_forks_event_min_datetime
stringlengths 24
24
⌀ | max_forks_repo_forks_event_max_datetime
stringlengths 24
24
⌀ | content
stringlengths 7
1.05M
| avg_line_length
float64 1.21
330k
| max_line_length
int64 6
990k
| alphanum_fraction
float64 0.01
0.99
| author_id
stringlengths 2
40
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
f79d563b6f639a248aa43fd4da3bcfc6a1f5f7d0
| 1,007
|
cpp
|
C++
|
uva/11770.cpp
|
cosmicray001/Online_judge_Solutions-
|
5dc6f90d3848eb192e6edea8e8c731f41a1761dd
|
[
"MIT"
] | 3
|
2018-01-08T02:52:51.000Z
|
2021-03-03T01:08:44.000Z
|
uva/11770.cpp
|
cosmicray001/Online_judge_Solutions-
|
5dc6f90d3848eb192e6edea8e8c731f41a1761dd
|
[
"MIT"
] | null | null | null |
uva/11770.cpp
|
cosmicray001/Online_judge_Solutions-
|
5dc6f90d3848eb192e6edea8e8c731f41a1761dd
|
[
"MIT"
] | 1
|
2020-08-13T18:07:35.000Z
|
2020-08-13T18:07:35.000Z
|
#include <bits/stdc++.h>
#define le 10004
using namespace std;
int in[le];
vector<int> v[le];
vector<int> ve;
bool vis[le];
void dfs(int a){
vis[a] = true;
for(int i = 0; i < v[a].size(); i++){
if(!vis[v[a][i]]) dfs(v[a][i]);
}
ve.push_back(a);
}
void dfs1(int a){
vis[a] = true;
for(int i = 0; i < v[a].size(); i++){
if(!vis[v[a][i]]) dfs1(v[a][i]);
}
}
int main(){
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int t, co = 0, a, b, n, m;
for(scanf("%d", &t); t--; ){
scanf("%d %d", &n, &m);
for(int i = 0; i < m; scanf("%d %d", &a, &b), v[a].push_back(b), i++);
memset(vis, false, sizeof(vis));
for(int i = 1; i < n + 1; i++) if(!vis[i]) dfs(i);
memset(vis, false, sizeof(vis));
int ans = 0;
for(int i = ve.size() - 1; i >= 0; i--) if(!vis[ve[i]]){
ans++;
dfs1(ve[i]);
}
printf("Case %d: %d\n", ++co, ans);
for(int i = 0; i < le; v[i].clear(), in[i] = 0, i++);
ve.clear();
}
return 0;
}
| 23.97619
| 74
| 0.472691
|
cosmicray001
|
f79dbd520e9752b41bb60bace27aa3187ac8cd99
| 1,001
|
cpp
|
C++
|
Codes/Volume 01/E0006 Sum square difference.cpp
|
upobir/Project-Euler-Codes
|
a4a95da7d87e159c8efecd94d258bab0fcc8af7f
|
[
"MIT"
] | 2
|
2021-02-17T05:19:14.000Z
|
2022-02-13T19:52:00.000Z
|
Codes/Volume 01/E0006 Sum square difference.cpp
|
upobir/Project-Euler-Codes
|
a4a95da7d87e159c8efecd94d258bab0fcc8af7f
|
[
"MIT"
] | null | null | null |
Codes/Volume 01/E0006 Sum square difference.cpp
|
upobir/Project-Euler-Codes
|
a4a95da7d87e159c8efecd94d258bab0fcc8af7f
|
[
"MIT"
] | null | null | null |
# include <bits/stdc++.h>
# include "../TimeMacro.h"
using namespace std;
typedef long long int ll;
/*
Statement:
The sum of the squares of the first ten natural numbers is,
12+22+...+102=385
The square of the sum of the first ten natural numbers is,
(1+2+...+10)2=552=3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025−385=2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
*/
ll sumTill(ll num){
return num * (num+1)/2;
}
ll sumSquareTill(ll num){
return num*(num+1)*(2*num+1)/6;
}
ll squareSumMinusSumSquare(ll num){
ll sum = sumTill(num);
ll sumSq = sumSquareTill(num);
return sum*sum - sumSq;
}
int main(){
Time(
cout<<squareSumMinusSumSquare(100)<<endl;
);
return 0;
}
/*
Notes:
sum of natural numbers and sum of their squares have well known formulas, just used those.
Complexity: O(1)
*/
| 22.244444
| 129
| 0.686314
|
upobir
|
f7a2295d23d4e1589637baac771e004bc15ccdeb
| 922
|
cpp
|
C++
|
Chapter11/problem_88/main.cpp
|
showa-yojyo/The-Modern-Cpp-Challenge
|
807b6be8faebe5bdd3ce138ab83648a3864aeab3
|
[
"MIT"
] | null | null | null |
Chapter11/problem_88/main.cpp
|
showa-yojyo/The-Modern-Cpp-Challenge
|
807b6be8faebe5bdd3ce138ab83648a3864aeab3
|
[
"MIT"
] | null | null | null |
Chapter11/problem_88/main.cpp
|
showa-yojyo/The-Modern-Cpp-Challenge
|
807b6be8faebe5bdd3ce138ab83648a3864aeab3
|
[
"MIT"
] | null | null | null |
// #88 シーザー暗号
// 簡単のために大文字しか処理しない
//
// C++ 新機能の学習には不向き
#include <iostream>
#include <string>
#include <string_view>
#include <cassert>
std::string caesar_encrypt(std::string_view text, int shift)
{
std::string str;
str.reserve(text.length());
for (auto const & c : text)
{
if (isalpha(c) && isupper(c))
str += 'A' + (c - 'A' + shift) % 26;
else
str += c;
}
return str;
}
std::string caesar_decrypt(std::string_view text, int shift)
{
std::string str;
str.reserve(text.length());
for (auto const & c : text)
{
if (isalpha(c) && isupper(c))
str += 'A' + (26 + c - 'A' - shift) % 26;
else
str += c;
}
return str;
}
int main()
{
std::string text("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
for (auto i: text)
{
auto enc = caesar_encrypt(text, i);
auto dec = caesar_decrypt(enc, i);
assert(text == dec);
}
}
| 18.44
| 60
| 0.555315
|
showa-yojyo
|
f7a563b649a6abac9d3551478c2bc74b93e56863
| 10,030
|
hpp
|
C++
|
include/interactive_mid_protocols/SigmaProtocolDlog.hpp
|
manel1874/libscapi
|
8cf705162af170c04c8e2299213f52888193cabe
|
[
"MIT"
] | 160
|
2016-05-11T09:45:56.000Z
|
2022-03-06T09:32:19.000Z
|
include/interactive_mid_protocols/SigmaProtocolDlog.hpp
|
cryptobiu/libscapi
|
49eee7aee9eb3544a7facb199d0a6e98097b058a
|
[
"MIT"
] | 57
|
2016-12-26T07:02:12.000Z
|
2022-03-06T16:34:31.000Z
|
include/interactive_mid_protocols/SigmaProtocolDlog.hpp
|
manel1874/libscapi
|
8cf705162af170c04c8e2299213f52888193cabe
|
[
"MIT"
] | 67
|
2016-10-10T17:56:22.000Z
|
2022-03-15T22:56:39.000Z
|
/**
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*
* Copyright (c) 2016 LIBSCAPI (http://crypto.biu.ac.il/SCAPI)
* This file is part of the SCAPI project.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* We request that any publication and/or code referring to and/or based on SCAPI contain an appropriate citation to SCAPI, including a reference to
* http://crypto.biu.ac.il/SCAPI.
*
* Libscapi uses several open source libraries. Please see these projects for any further licensing issues.
* For more information , See https://github.com/cryptobiu/libscapi/blob/master/LICENSE.MD
*
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*
*/
#pragma once
#include "SigmaProtocol.hpp"
#include "../primitives/Dlog.hpp"
#include "../primitives/Prg.hpp"
/**
* Checks if the given challenge length is equal to the soundness parameter.
*/
bool checkChallengeLength(const vector<byte> & challenge, int t);
/**
* Concrete implementation of SigmaProtocol input, used by the SigmaDlog verifier and simulator.<p>
* In SigmaProtocolDlog, the common input contains a GroupElement h.
*/
class SigmaDlogCommonInput : public SigmaCommonInput {
public:
SigmaDlogCommonInput(const shared_ptr<GroupElement> & h) { this->h = h; };
shared_ptr<GroupElement> getH() { return h; };
string toString() override { return h->generateSendableData()->toString(); }
private:
shared_ptr<GroupElement> h;
};
/**
* Concrete implementation of Sigma Simulator.<p>
* This implementation simulates the case that the prover convince a verifier that it knows the discrete log of the value h in G.<P>
*
* For more information see protocol 6.1.1, page 148 of Hazay - Lindell.<p>
* The pseudo code of this protocol can be found in Protocol 1.1 of pseudo codes document at{ @link http://cryptobiu.github.io/scapi/SDK_Pseudocode.pdf}.
*/
class SigmaDlogSimulator : public SigmaSimulator {
/*
This class computes the following calculations:
SAMPLE a random z <- Zq
COMPUTE a = g^z*h^(-e) (where -e here means -e mod q)
OUTPUT (a,e,z).
*/
public:
/**
* Constructor that gets the underlying DlogGroup, soundness parameter and SecureRandom.
*/
SigmaDlogSimulator(const shared_ptr<DlogGroup> & dlog, int t, const shared_ptr<PrgFromOpenSSLAES> & random = get_seeded_prg());
/**
* Returns the soundness parameter for this Sigma protocol.
*/
int getSoundnessParam() override { return t; };
/**
* Computes the simulator computation, using the given challenge.<p>
* "SAMPLE a random z <- Zq <p>
* COMPUTE a = g^z*h^(-e) (where -e here means -e mod q)<p>
* OUTPUT (a,e,z)". <p>
* @param input MUST be an instance of SigmaDlogCommonInput.
* @param challenge
* @return the output of the computation - (a, e, eSize, z).
*/
shared_ptr<SigmaSimulatorOutput> simulate(SigmaCommonInput* input,
const vector<byte> & challenge) override;
/**
* Computes the simulator computation, using random challenge.<p>
* "SAMPLE a random z <- Zq<p>
* COMPUTE a = g^z*h^(-e) (where -e here means -e mod q)<p>
* OUTPUT (a,e,z)". <p>
* @param input MUST be an instance of SigmaDlogCommonInput.
* @return the output of the computation - (a, e, z).
*/
shared_ptr<SigmaSimulatorOutput> simulate(SigmaCommonInput* input) override;
private:
shared_ptr<DlogGroup> dlog; //Underlying DlogGroup.
int t; //Soundness parameter.
shared_ptr<PrgFromOpenSSLAES> random;
biginteger qMinusOne;
/**
* Checks the validity of the given soundness parameter.
*/
bool checkSoundnessParam();
};
/**
* Concrete implementation of SigmaProtocol input, used by the SigmaDlogProver.<p>
* In SigmaProtocolDlog, the prover gets a GroupElement h and a BigInteger w such that g^w = h.
*/
class SigmaDlogProverInput : public SigmaProverInput {
public:
/**
* Sets the given h and w, such that g^w = h.
*/
SigmaDlogProverInput(const shared_ptr<GroupElement> & h, const biginteger & w) {
params = make_shared<SigmaDlogCommonInput>(h);
this->w = w;
};
/**
* Returns w element, such that g^w = h.
*/
biginteger getW() { return w; };
shared_ptr<SigmaCommonInput> getCommonInput() override { return params; };
private:
shared_ptr<SigmaDlogCommonInput> params;
biginteger w;
};
/**
* Concrete implementation of Sigma Protocol prover computation.<p>
* This protocol is used for a prover to convince a verifier that it knows the discrete log of the value h in G. <p>
* This implementation is based on Schnorr's sigma protocol for Dlog Group, see reference in Protocol 6.1.1, page 148 of Hazay-Lindell.<p>
*
* The pseudo code of this protocol can be found in Protocol 1.1 of pseudo codes document at {@link http://cryptobiu.github.io/scapi/SDK_Pseudocode.pdf}.
*/
class SigmaDlogProverComputation : public SigmaProverComputation, public DlogBasedSigma {
/*
This class computes the following calculations:
SAMPLE a random r in Zq
COMPUTE a = g^r
COMPUTE z = r + ew mod q
*/
public:
/**
* Constructor that gets the underlying DlogGroup, soundness parameter and SecureRandom.
*/
SigmaDlogProverComputation(const shared_ptr<DlogGroup> & dlog, int t, const shared_ptr<PrgFromOpenSSLAES> & random = get_seeded_prg());
int getSoundnessParam() override { return t; };
/**
* Computes the first message from the protocol.<p>
* "SAMPLE a random r in Zq<p>
* COMPUTE a = g^r". <p>
* @param input MUST be an instance of SigmaDlogProverInput.
* @return the computed message
*/
shared_ptr<SigmaProtocolMsg> computeFirstMsg(const shared_ptr<SigmaProverInput> & input) override;
/**
* Computes the secong message from the protocol.<p>
* "COMPUTE z = (r + ew) mod q".<p>
* @param challenge<p>
* @return the computed message.
*/
shared_ptr<SigmaProtocolMsg> computeSecondMsg(const vector<byte> & challenge) override;
/**
* Returns the simulator that matches this sigma protocol prover.
*/
shared_ptr<SigmaSimulator> getSimulator() override {
auto res = make_shared<SigmaDlogSimulator>(dlog, t, random);
return res; };
private:
shared_ptr<DlogGroup> dlog; // Underlying DlogGroup.
int t; // soundness parameter in BITS.
shared_ptr<PrgFromOpenSSLAES> random;
shared_ptr<SigmaDlogProverInput> input; // Contains h and w.
biginteger r; // The value chosen in the protocol.
biginteger qMinusOne;
/**
* Checks the validity of the given soundness parameter.
* @return true if the soundness parameter is valid; false, otherwise.
*/
bool checkSoundnessParam();
};
/**
* Concrete implementation of Sigma Protocol verifier computation. <p>
* This protocol is used for a prover to convince a verifier that it knows the discrete log of the value h in G. <P>
* This implementation is based on Schnorr's sigma protocol for Dlog Group, see reference in Protocol 6.1.1, page 148 of Hazay-Lindell..<p>
* The pseudo code of this protocol can be found in Protocol 1.1 of pseudo codes document at {@link http://cryptobiu.github.io/scapi/SDK_Pseudocode.pdf}.
*/
class SigmaDlogVerifierComputation : public SigmaVerifierComputation, public DlogBasedSigma {
/*
This class computes the following calculations:
SAMPLE a random challenge e <- {0, 1}^t
ACC IFF VALID_PARAMS(G,q,g) = TRUE AND h in G AND g^z = ah^e
*/
public:
/**
* Constructor that gets the underlying DlogGroup, soundness parameter and SecureRandom.
* @param dlog
* @param t Soundness parameter in BITS.
* @param random
*/
SigmaDlogVerifierComputation(const shared_ptr<DlogGroup> & dlog, int t, const shared_ptr<PrgFromOpenSSLAES> & random = get_seeded_prg());
/**
* Returns the soundness parameter for this Sigma protocol.
*/
int getSoundnessParam() override { return t; }
/**
* Samples the challenge to use in the protocol.<p>
* "SAMPLE a random challenge e<-{0,1}^t".
*/
void sampleChallenge() override;
/**
* Sets the given challenge and its size.
*/
void setChallenge(const vector<byte> & challenge) override { e = challenge; }
/**
* Returns the sampled challenge.
*/
vector<byte> getChallenge() override { return e; };
/**
* Verifies the proof.<p>
* Computes the following line from the protocol:<p>
* "ACC IFF VALID_PARAMS(G,q,g) = TRUE AND h in G AND g^z = ah^e".<p>
* @param a first message from prover
* @param z second message from prover
* @param input MUST be an instance of SigmaDlogCommonInput.
* @return true if the proof has been verified; false, otherwise.
*/
bool verify(SigmaCommonInput* input, SigmaProtocolMsg* a, SigmaProtocolMsg* z) override;
private:
shared_ptr<DlogGroup> dlog; // Underlying DlogGroup.
int t; // Soundness parameter in BITS.
vector<byte> e; // The challenge.
shared_ptr<PrgFromOpenSSLAES> random;
/**
* Checks the validity of the given soundness parameter.
*/
bool checkSoundnessParam();
};
| 39.333333
| 158
| 0.705085
|
manel1874
|
f7a86692e2f92eea95567f049e6922398bef8326
| 1,592
|
cpp
|
C++
|
tests/src/compressor.cpp
|
nospi/synth2
|
f4548e01753a74e826f4155685259750cfe2581f
|
[
"Unlicense"
] | 1
|
2021-07-14T07:49:46.000Z
|
2021-07-14T07:49:46.000Z
|
tests/src/compressor.cpp
|
nospi/synth2
|
f4548e01753a74e826f4155685259750cfe2581f
|
[
"Unlicense"
] | null | null | null |
tests/src/compressor.cpp
|
nospi/synth2
|
f4548e01753a74e826f4155685259750cfe2581f
|
[
"Unlicense"
] | null | null | null |
#include <catch.hpp>
#include <dsp.h>
using namespace dsp;
TEST_CASE("ratio -> gain reduction", "[compressor]")
{
SECTION("accurate gain reduction")
{
compressor comp;
comp.enabled = true;
comp.setAttack(1.0);
comp.setRelease(100.0);
comp.setRatio(0.5);
comp.setThreshold(-9.0);
double input = gain::dB2lin(-3.0);
comp.setMakeupGain(0.0);
for (int i = 0; i < 441; i++) comp.process(input);
REQUIRE(comp.process(input) == Approx(gain::dB2lin(-6.0)).margin(1.e-4));
comp.setMakeupGain(3.0);
for (int i = 0; i < 441; i++) comp.process(input);
REQUIRE(comp.process(input) == Approx(gain::dB2lin(-3.0)).margin(1.e-4));
comp.setMakeupGain(0.0);
comp.setRatio(0.25);
for (int i = 0; i < 441; i++) comp.process(input);
REQUIRE(comp.process(input) == Approx(gain::dB2lin(-7.5)).margin(1.e-4));
}
SECTION("no gain reduction when threshold is not met")
{
compressor comp;
comp.enabled = true;
comp.setAttack(0.00001);
comp.setRelease(1.0);
comp.setRatio(0.5);
comp.setThreshold(-3.0);
double input = gain::dB2lin(-9.0);
REQUIRE(comp.process(input) == Approx(input).margin(1.e-02));
REQUIRE(comp.getGainReduction() == 0.0);
}
}
//TEST_CASE("auto makeup gain", "[compressor]")
//{
// SECTION("makeup gain does not push output over unity")
// {
// compressor comp;
// comp.enabled = true;
// comp.autoMakeupGain = true;
// comp.setAttack(0.00001);
// comp.setRelease(1.0);
// comp.setRatio(0.5);
// comp.setThreshold(-9.0);
//
// double input = gain::dB2lin(18.0);
// REQUIRE(comp.process(input) <= gain::dB2lin(0.0));
// }
//}
| 24.875
| 75
| 0.64196
|
nospi
|
f7b0f53f9f04f0ab654c4df8d603decaf598f4bd
| 226
|
hpp
|
C++
|
plugins/content_compiler/include/TinyObjImporter.hpp
|
fuchstraumer/Caelestis
|
9c4b76288220681bb245d84e5d7bf8c7f69b2716
|
[
"MIT"
] | 5
|
2018-08-16T00:55:33.000Z
|
2020-06-19T14:30:17.000Z
|
plugins/content_compiler/include/TinyObjImporter.hpp
|
fuchstraumer/Caelestis
|
9c4b76288220681bb245d84e5d7bf8c7f69b2716
|
[
"MIT"
] | null | null | null |
plugins/content_compiler/include/TinyObjImporter.hpp
|
fuchstraumer/Caelestis
|
9c4b76288220681bb245d84e5d7bf8c7f69b2716
|
[
"MIT"
] | null | null | null |
#pragma once
#ifndef ASSET_PIPELINE_OBJ_FILE_IMPORTER_HPP
#define ASSET_PIPELINE_OBJ_FILE_IMPORTER_HPP
struct MeshData* LoadMeshDataFromObj(const char* fname, bool interleaved);
#endif //!ASSET_PIPELINE_OBJ_FILE_IMPORTER_HPP
| 32.285714
| 74
| 0.871681
|
fuchstraumer
|
f7b20b899b75b10530c962bf5d7bac41cd84fd46
| 61,618
|
cpp
|
C++
|
lumino/LuminoEngine/test/Test_Graphics_LowLevelRendering.cpp
|
lriki/Lumino
|
1a80430f4a83dbdfbe965b3d5b16064991b3edb0
|
[
"MIT"
] | 30
|
2016-01-24T05:35:45.000Z
|
2020-03-03T09:54:27.000Z
|
lumino/LuminoEngine/test/Test_Graphics_LowLevelRendering.cpp
|
lriki/Lumino
|
1a80430f4a83dbdfbe965b3d5b16064991b3edb0
|
[
"MIT"
] | 35
|
2016-04-18T06:14:08.000Z
|
2020-02-09T15:51:58.000Z
|
lumino/LuminoEngine/test/Test_Graphics_LowLevelRendering.cpp
|
lriki/Lumino
|
1a80430f4a83dbdfbe965b3d5b16064991b3edb0
|
[
"MIT"
] | 5
|
2016-04-03T02:52:05.000Z
|
2018-01-02T16:53:06.000Z
|
#include "Common.hpp"
#include <LuminoGraphics/RHI/ShaderDescriptor.hpp>
#include <LuminoGraphics/RHI/GraphicsCommandBuffer.hpp>
class Test_Graphics_LowLevelRendering : public ::testing::Test
{
public:
virtual void SetUp()
{
m_shader1 = Shader::create(LN_ASSETFILE("simple.vsh"), LN_ASSETFILE("simple.psh"));
m_vertexDecl1 = makeObject<VertexLayout>();
m_vertexDecl1->addElement(0, VertexElementType::Float4, VertexElementUsage::Position, 0);
}
virtual void TearDown() {}
Ref<Shader> m_shader1;
Ref<VertexLayout> m_vertexDecl1;
};
//------------------------------------------------------------------------------
TEST_F(Test_Graphics_LowLevelRendering, BasicTriangle)
{
auto descriptorLayout = m_shader1->descriptorLayout();
auto shaderPass = m_shader1->techniques()[0]->passes()[0];
// # 時計回り (左ねじ) で描画できること
{
#ifdef LN_COORD_RH
Vector4 v[] = { Vector4(0, 0.5, 0, 1), Vector4(-0.5, -0.25, 0, 1), Vector4(0.5, -0.25, 0, 1), };
#else
Vector4 v[] = { Vector4(0, 0.5, 0, 1), Vector4(0.5, -0.25, 0, 1), Vector4(-0.5, -0.25, 0, 1), };
#endif
auto vertexBuffer = makeObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);
// RenderPass は Swap の数だけ作ってもいいし、1つを使いまわしても良い。
// たくさんの RT に描画するときでも 1つだけ RenderPass を作れば良い。
// ただし、その場合は RenderPass 切り替えのたびにキャッシュを検索する処理が入るのでパフォーマンスが悪くなる。
// 常に RT,Depth,RenderPass をセットにして、RenderPass は生成後変更しないようにするとパフォーマンスがよくなる。
auto renderPass = makeObject<RenderPass>();
// 何回か回して同期の問題が無いことを見る
for (int i = 0; i < 10; i++)
{
auto ctx = TestEnv::beginFrame();
auto target = TestEnv::mainWindowSwapChain()->currentBackbuffer();
renderPass->setRenderTarget(0, target);
renderPass->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
auto descriptor = ctx->allocateShaderDescriptor_deprecated(shaderPass);
descriptor->setVector(descriptorLayout->findUniformMemberIndex(_TT("g_color")), Vector4(1, 0, 0, 1));
ctx->beginRenderPass(renderPass);
ctx->setVertexLayout(m_vertexDecl1);
ctx->setVertexBuffer(0, vertexBuffer);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(descriptor);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitive(0, 1);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-BasicTriangle.png"), target);
}
}
}
//------------------------------------------------------------------------------
TEST_F(Test_Graphics_LowLevelRendering, Clear)
{
auto descriptorLayout = m_shader1->descriptorLayout();
auto shaderPass = m_shader1->techniques()[0]->passes()[0];
#ifdef LN_COORD_RH
Vector4 v[] = { Vector4(0, 0.5, 0, 1), Vector4(-0.5, -0.25, 0, 1), Vector4(0.5, -0.25, 0, 1), };
#else
Vector4 v[] = { Vector4(0, 0.5, 0, 1), Vector4(0.5, -0.25, 0, 1), Vector4(-0.5, -0.25, 0, 1), };
#endif
auto vertexBuffer = makeObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto descriptor = ctx->allocateShaderDescriptor_deprecated(shaderPass);
descriptor->setVector(descriptorLayout->findUniformMemberIndex(_TT("g_color")), Vector4(1, 0, 0, 1));
ctx->beginRenderPass(TestEnv::renderPass());
ctx->setVertexLayout(m_vertexDecl1);
ctx->setVertexBuffer(0, vertexBuffer);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(descriptor);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitive(0, 1); // (ちゃんと全体に clear 効くか確認 & Vulkan 警告回避のため、) 適当に描いてから
ctx->clear(ClearFlags::All, Color::Blue, 1.0f, 0); // clear
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-Clear-1.png"), cbb);
}
//* [ ] Viewport や Scissor の影響を受けず、全体をクリアできること。
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto descriptor = ctx->allocateShaderDescriptor_deprecated(shaderPass);
descriptor->setVector(descriptorLayout->findUniformMemberIndex(_TT("g_color")), Vector4(1, 0, 0, 1));
ctx->beginRenderPass(TestEnv::renderPass());
ctx->setViewportRect(Rect(0, 0, 10, 10));
ctx->setScissorRect(Rect(0, 0, 10, 10));
ctx->setVertexLayout(m_vertexDecl1);
ctx->setVertexBuffer(0, vertexBuffer);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(descriptor);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitive(0, 1);
ctx->clear(ClearFlags::All, Color::Green, 1.0f, 0);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-Clear-2.png"), cbb);
}
#if 0 // TODO: glDrawBuffers がなんかうまく動かなかったので一度保留。今のところ clear でまとめてクリアしてるところはない。RenderPass でやってる。
//* [ ] 複数 RT 設定時は index 0 だけクリアされること。
{
auto renderPass = makeObject<RenderPass>();
auto t1 = makeObject<RenderTargetTexture>(32, 32, TextureFormat::RGBA8, false);
auto t2 = makeObject<RenderTargetTexture>(32, 32, TextureFormat::RGBA8, false);
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
ctx->setVertexLayout(m_vertexDecl1);
ctx->setVertexBuffer(0, vertexBuffer);
ctx->setShaderPass(m_shader1->techniques()[0]->passes()[0]);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
// 両方 Blue でクリアして、
renderPass->setRenderTarget(0, t1);
ctx->beginRenderPass(renderPass);
ctx->drawPrimitive(0, 1);
ctx->clear(ClearFlags::Color, Color::Blue, 1.0f, 0);
ctx->endRenderPass();
renderPass->setRenderTarget(0, t2);
ctx->beginRenderPass(renderPass);
ctx->drawPrimitive(0, 1);
ctx->clear(ClearFlags::Color, Color::Blue, 1.0f, 0);
ctx->endRenderPass();
// 2つ set して Red で clear
renderPass->setRenderTarget(0, t1);
renderPass->setRenderTarget(1, t2);
ctx->beginRenderPass(renderPass);
ctx->drawPrimitive(0, 1);
ctx->clear(ClearFlags::Color, Color::Red, 1.0f, 0);
ctx->endRenderPass();
TestEnv::endFrame();
//ASSERT_RENDERTARGET_S(LN_ASSETFILE("Graphics/Result/__.png"), t2);
// Red, Blue
ASSERT_EQ(true, TestEnv::equalsBitmapFile(detail::TextureInternal::readData(t1, nullptr), LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-Clear-3.png"), 100));
ASSERT_EQ(true, TestEnv::equalsBitmapFile(detail::TextureInternal::readData(t2, nullptr), LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-Clear-4.png"), 100));
}
#endif
//* [ ] RenderPass の begin/end だけでクリアできること
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
crp->setClearValues(ClearFlags::All, Color::Blue, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-Clear-1.png"), cbb);
}
}
//------------------------------------------------------------------------------
TEST_F(Test_Graphics_LowLevelRendering, VertexBuffer)
{
auto descriptorLayout = m_shader1->descriptorLayout();
auto shaderPass = m_shader1->techniques()[0]->passes()[0];
struct Param
{
GraphicsResourceUsage usage;
GraphicsResourcePool pool;
};
std::array<Param, 3> params =
{
Param{ GraphicsResourceUsage::Dynamic, GraphicsResourcePool::None },
Param{ GraphicsResourceUsage::Static, GraphicsResourcePool::Managed },
Param{ GraphicsResourceUsage::Dynamic, GraphicsResourcePool::Managed },
//{ GraphicsResourceUsage::Static, GraphicsResourcePool::None },
};
// test static and dynamic
for (int i = 0; i < params.size(); i++)
{
auto usage = params[i].usage;
auto pool = params[i].pool;
auto vb1 = makeObject<VertexBuffer>(sizeof(Vector4) * 3, usage);
auto vb2 = makeObject<VertexBuffer>(sizeof(Vector4) * 3, usage);
vb1->setResourcePool(pool);
vb2->setResourcePool(pool);
// * [ ] まだ一度もレンダリングに使用されていないバッファを、更新できること
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass);
shd->setVector(descriptorLayout->findUniformMemberIndex(_TT("g_color")), Vector4(1, 0, 0, 1));
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setVertexLayout(m_vertexDecl1);
ctx->setVertexBuffer(0, vb1);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(shd);
#ifdef LN_COORD_RH
Vector4 v1[] = {
Vector4(0, 0.5, 0, 1),
Vector4(-0.5, -0.25, 0, 1),
Vector4(0.5, -0.25, 0, 1),
};
#else
Vector4 v1[] = {
Vector4(0, 0.5, 0, 1),
Vector4(0.5, -0.25, 0, 1),
Vector4(-0.5, -0.25, 0, 1),
};
#endif
memcpy(vb1->writableData(), v1, vb1->size());
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitive(0, 1);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-VertexBuffer-2.png"), cbb);
}
// * [ ] 一度レンダリングに使用されたバッファを、再更新できること
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass);
shd->setVector(descriptorLayout->findUniformMemberIndex(_TT("g_color")), Vector4(1, 0, 0, 1));
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
#ifdef LN_COORD_RH
Vector4 v2[] = {
Vector4(0, 1, 0, 1),
Vector4(-1, -1, 0, 1),
Vector4(1, -1, 0, 1),
};
#else
Vector4 v2[] = {
Vector4(0, 1, 0, 1),
Vector4(1, -1, 0, 1),
Vector4(-1, -1, 0, 1),
};
#endif
memcpy(vb1->writableData(), v2, vb1->size());
ctx->beginRenderPass(crp);
ctx->setVertexLayout(m_vertexDecl1);
ctx->setVertexBuffer(0, vb1);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(shd);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitive(0, 1);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-VertexBuffer-3.png"), cbb);
}
// * [ ] まだ一度もレンダリングに使用されていないバッファを、拡張できること
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass);
shd->setVector(descriptorLayout->findUniformMemberIndex(_TT("g_color")), Vector4(1, 0, 0, 1));
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
#ifdef LN_COORD_RH
Vector4 v2[] = {
Vector4(-0.5, 0.5, 0, 1),
Vector4(-0.5, -0.5, 0, 1),
Vector4(0.5, 0.5, 0, 1),
Vector4(0.5, -0.5, 0, 1),
};
#else
Vector4 v2[] = {
Vector4(-0.5, 0.5, 0, 1),
Vector4(0.5, 0.5, 0, 1),
Vector4(-0.5, -0.5, 0, 1),
Vector4(0.5, -0.5, 0, 1),
};
#endif
vb2->resize(sizeof(Vector4) * 4);
ASSERT_EQ(sizeof(Vector4) * 4, vb2->size());
memcpy(vb2->writableData(), v2, vb2->size());
ctx->beginRenderPass(crp);
ctx->setVertexLayout(m_vertexDecl1);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(shd);
ctx->setVertexBuffer(0, vb2);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-VertexBuffer-4.png"), cbb);
}
// * [ ] 一度レンダリングに使用されたバッファを、拡張できること
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass);
shd->setVector(descriptorLayout->findUniformMemberIndex(_TT("g_color")), Vector4(1, 0, 0, 1));
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
#ifdef LN_COORD_RH
Vector4 v2[] = {
Vector4(-0.5, 0.5, 0, 1),
Vector4(-0.5, -0.5, 0, 1),
Vector4(0.5, 0.5, 0, 1),
Vector4(0.5, -0.5, 0, 1),
Vector4(1.0, 0.5, 0, 1),
};
#else
Vector4 v2[] = {
Vector4(-0.5, 0.5, 0, 1),
Vector4(0.5, 0.5, 0, 1),
Vector4(-0.5, -0.5, 0, 1),
Vector4(0.5, -0.5, 0, 1),
Vector4(-0.5, -1, 0, 1),
};
#endif
vb2->resize(sizeof(Vector4) * 5);
ASSERT_EQ(sizeof(Vector4) * 5, vb2->size());
memcpy(vb2->writableData(), v2, vb2->size());
ctx->beginRenderPass(crp);
ctx->setVertexLayout(m_vertexDecl1);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(shd);
ctx->setVertexBuffer(0, vb2);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 3);
ctx->endRenderPass();
TestEnv::endFrame();
#ifdef LN_COORD_RH
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-VertexBuffer-5-RH.png"), cbb);
#else
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-VertexBuffer-5.png"), cbb);
#endif
}
}
// TODO: 部分 lock
}
//------------------------------------------------------------------------------
TEST_F(Test_Graphics_LowLevelRendering, MultiStreamVertexBuffer)
{
auto shader1 = Shader::create(LN_ASSETFILE("MultiStreamVertexBuffer-1.vsh"), LN_ASSETFILE("MultiStreamVertexBuffer-1.psh"));
auto shaderPass = shader1->techniques()[0]->passes()[0];
struct PosColor
{
Vector3 pos;
Vector4 color;
};
PosColor v1[3] = {
{ { -1, 1, 0 }, { 0.5, 0, 0, 0 } },
{ {-1, 0, 0}, { 0, 0, 0.5, 0 } },
{ {0, 1, 0}, { 0, 1., 0, 0 } },
};
Vector3 uv1[3] = { { 0.5, 0, 0 }, { 0, 0, 0.5 }, { 0, -0.5, 0 }, };
Vector4 uv2[3] = { { 0, 0, 0, 1 }, { 0, 0, 0, 1 }, { 0, 0, 0, 1 }, };
auto vb1 = makeObject<VertexBuffer>(sizeof(v1), v1, GraphicsResourceUsage::Static);
auto vb2 = makeObject<VertexBuffer>(sizeof(uv1), uv1, GraphicsResourceUsage::Static);
auto vb3 = makeObject<VertexBuffer>(sizeof(uv2), uv2, GraphicsResourceUsage::Static);
auto vd1 = makeObject<VertexLayout>();
vd1->addElement(0, VertexElementType::Float3, VertexElementUsage::Position, 0);
vd1->addElement(0, VertexElementType::Float4, VertexElementUsage::Color, 0);
vd1->addElement(1, VertexElementType::Float3, VertexElementUsage::TexCoord, 0);
vd1->addElement(2, VertexElementType::Float4, VertexElementUsage::TexCoord, 1);
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setVertexBuffer(0, vb1);
ctx->setVertexBuffer(1, vb2);
ctx->setVertexBuffer(2, vb3);
ctx->setVertexLayout(vd1);
ctx->setShaderPass(shaderPass);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitive(0, 1);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-MultiStreamVertexBuffer-1.png"), cbb);
}
//------------------------------------------------------------------------------
TEST_F(Test_Graphics_LowLevelRendering, IndexBuffer)
{
auto descriptorLayout = m_shader1->descriptorLayout();
auto shaderPass = m_shader1->techniques()[0]->passes()[0];
//auto descriptor = m_shader1->descriptor();
//descriptor->setVector(descriptor->descriptorLayout()->findUniformMemberIndex(_TT("g_color"), Vector4(0, 0, 1, 1));
struct Param
{
GraphicsResourceUsage usage;
GraphicsResourcePool pool;
};
std::array<Param, 3> params =
{
//{ GraphicsResourceUsage::Static, GraphicsResourcePool::None },
Param{ GraphicsResourceUsage::Static, GraphicsResourcePool::Managed },
Param{ GraphicsResourceUsage::Dynamic, GraphicsResourcePool::None },
Param{ GraphicsResourceUsage::Dynamic, GraphicsResourcePool::Managed },
};
// test static and dynamic
for (int i = 0; i < params.size(); i++)
{
auto usage = params[i].usage;
auto pool = params[i].pool;
Vector4 vertices[] = {
Vector4(0, 0.5, 0, 1),
Vector4(0, 0, 0, 1),
Vector4(0.5, -0.25, 0, 1),
Vector4(0, 0, 0, 1),
Vector4(-0.5, -0.25, 0, 1),
};
auto vb1 = makeObject<VertexBuffer>(sizeof(Vector4) * 5, vertices, usage);
auto ib1 = makeObject<IndexBuffer>(3, IndexBufferFormat::UInt16, usage);
ib1->setResourcePool(pool);
// * [ ] まだ一度もレンダリングに使用されていないバッファを、更新できること
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass);
shd->setVector(descriptorLayout->findUniformMemberIndex(_TT("g_color")), Vector4(0, 0, 1, 1));
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
uint16_t indices[] = { 0, 4, 2 };
memcpy(ib1->map(MapMode::Write), indices, ib1->bytesSize());
ctx->beginRenderPass(crp);
ctx->setVertexLayout(m_vertexDecl1);
ctx->setVertexBuffer(0, vb1);
ctx->setIndexBuffer(ib1);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(shd);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitiveIndexed(0, 1);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-IndexBuffer-1.png"), cbb);
}
// * [ ] 一度レンダリングに使用されたバッファを、再更新できること
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass);
shd->setVector(descriptorLayout->findUniformMemberIndex(_TT("g_color")), Vector4(0, 0, 1, 1));
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
uint16_t indices[] = { 1, 4, 2 };
memcpy(ib1->map(MapMode::Write), indices, ib1->bytesSize());
ctx->beginRenderPass(crp);
ctx->setVertexLayout(m_vertexDecl1);
ctx->setVertexBuffer(0, vb1);
ctx->setIndexBuffer(ib1);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(shd);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitiveIndexed(0, 1);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-IndexBuffer-2.png"), cbb);
}
// * [ ] フォーマット変更 16 -> 32
{
if (usage == GraphicsResourceUsage::Static && pool == GraphicsResourcePool::None) {
// un supported
}
else
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass);
shd->setVector(descriptorLayout->findUniformMemberIndex(_TT("g_color")), Vector4(0, 0, 1, 1));
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ib1->setFormat(IndexBufferFormat::UInt32);
ctx->beginRenderPass(crp);
ctx->setVertexLayout(m_vertexDecl1);
ctx->setVertexBuffer(0, vb1);
ctx->setIndexBuffer(ib1);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(shd);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitiveIndexed(0, 1);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-IndexBuffer-2.png"), cbb); // ↑と同じ結果
}
}
}
}
//------------------------------------------------------------------------------
TEST_F(Test_Graphics_LowLevelRendering, ViewportAndScissor)
{
auto descriptorLayout = m_shader1->descriptorLayout();
auto shaderPass = m_shader1->techniques()[0]->passes()[0];
#ifdef LN_COORD_RH
Vector4 v[] = {
Vector4(0, 0.5, 0, 1),
Vector4(-0.5, -0.25, 0, 1),
Vector4(0.5, -0.25, 0, 1),
};
#else
Vector4 v[] = {
Vector4(0, 0.5, 0, 1),
Vector4(0.5, -0.25, 0, 1),
Vector4(-0.5, -0.25, 0, 1),
};
#endif
auto vertexBuffer = makeObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);
//* [ ] Viewport
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass);
shd->setVector(descriptorLayout->findUniformMemberIndex(_TT("g_color")), Vector4(1, 0, 0, 1));
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setVertexLayout(m_vertexDecl1);
ctx->setVertexBuffer(0, vertexBuffer);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(shd);
ctx->setViewportRect(Rect(0, 0, 80, 60)); // 左上
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitive(0, 1);
ctx->setViewportRect(Rect(80, 60, 80, 60)); // 右下
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitive(0, 1);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-ViewportAndScissor-1.png"), cbb);
ctx->setViewportRect(Rect::Empty); // reset
}
//* [ ] Scissor
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass);
shd->setVector(descriptorLayout->findUniformMemberIndex(_TT("g_color")), Vector4(1, 0, 0, 1));
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setVertexLayout(m_vertexDecl1);
ctx->setVertexBuffer(0, vertexBuffer);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(shd);
ctx->setScissorRect(Rect(0, 0, 80, 60)); // 左上
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitive(0, 1);
ctx->setScissorRect(Rect(80, 60, 80, 60)); // 右下
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitive(0, 1);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-ViewportAndScissor-2.png"), cbb);
ctx->setScissorRect(Rect(0, 0, 160, 120)); // reset
}
//* [ ] Viewport+Scissor (Experimental) ... OpenGL では Viewport が優先だった。
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass);
shd->setVector(descriptorLayout->findUniformMemberIndex(_TT("g_color")), Vector4(1, 0, 0, 1));
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setVertexLayout(m_vertexDecl1);
ctx->setVertexBuffer(0, vertexBuffer);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(shd);
ctx->setViewportRect(Rect(0, 0, 80, 60)); // 左上
ctx->setScissorRect(Rect(40, 30, 80, 60)); // 中央
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitive(0, 1);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-ViewportAndScissor-3.png"), cbb);
}
}
//------------------------------------------------------------------------------
TEST_F(Test_Graphics_LowLevelRendering, ConstantBuffer)
{
auto shader1 = Shader::create(LN_ASSETFILE("simple.vsh"), LN_ASSETFILE("ConstantBufferTest-1.psh"));
auto descriptorLayout = shader1->descriptorLayout();
auto shaderPass = shader1->techniques()[0]->passes()[0];
#ifdef LN_COORD_RH
Vector4 v[] = {
Vector4(-1, 1, 0, 1),
Vector4(-1, 0, 0, 1),
Vector4(0, 1, 0, 1),
};
#else
Vector4 v[] = {
Vector4(-1, 1, 0, 1),
Vector4(0, 1, 0, 1),
Vector4(-1, 0, 0, 1),
};
#endif
auto vertexBuffer = makeObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);
auto renderAndCapture = [&](std::function<void(detail::ShaderSecondaryDescriptor* shd)> setDescriptor) {
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass);
setDescriptor(shd);
crp->setClearValues(ClearFlags::All, Color::Black, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setVertexLayout(m_vertexDecl1);
ctx->setVertexBuffer(0, vertexBuffer);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(shd);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitive(0, 1);
ctx->endRenderPass();
TestEnv::endFrame();
return GraphicsTestHelper::capture(cbb)->getPixel32(0, 0);
};
// * [ ] float
{
auto color = renderAndCapture([&](detail::ShaderSecondaryDescriptor* shd) {
shd->setInt(descriptorLayout->findUniformMemberIndex(_TT("g_type")), 1);
shd->setFloat(descriptorLayout->findUniformMemberIndex(_TT("g_color1")), 0.5); // 赤っぽくする
});
ASSERT_EQ(true, color.r > 100); // 赤っぽくなっているはず
}
// * [ ] float2
{
auto color = renderAndCapture([&](detail::ShaderSecondaryDescriptor* shd) {
shd->setInt(descriptorLayout->findUniformMemberIndex(_TT("g_type")), 2);
shd->setVector(descriptorLayout->findUniformMemberIndex(_TT("g_color2")), Vector4(1, 0, 0, 1));
});
ASSERT_EQ(true, color.r > 200);
}
// * [ ] float3
{
auto color = renderAndCapture([&](detail::ShaderSecondaryDescriptor* shd) {
shd->setInt(descriptorLayout->findUniformMemberIndex(_TT("g_type")), 3);
shd->setVector(descriptorLayout->findUniformMemberIndex(_TT("g_color3")), Vector4(0, 1, 0, 1));
});
ASSERT_EQ(true, color.g > 200);
}
// * [ ] float4
{
auto color = renderAndCapture([&](detail::ShaderSecondaryDescriptor* shd) {
shd->setInt(descriptorLayout->findUniformMemberIndex(_TT("g_type")), 4);
shd->setVector(descriptorLayout->findUniformMemberIndex(_TT("g_color4")), Vector4(0, 0, 1, 1));
});
ASSERT_EQ(true, color.b > 200);
}
float ary1[3] = { 0, 0.5, 0 };
Vector4 ary2[3] = { {1, 0, 0, 1}, {0, 1, 0, 1}, {0, 0, 1, 1} };
// * [ ] float[]
{
auto color = renderAndCapture([&](detail::ShaderSecondaryDescriptor* shd) {
shd->setInt(descriptorLayout->findUniformMemberIndex(_TT("g_type")), 11);
shd->setFloatArray(descriptorLayout->findUniformMemberIndex(_TT("g_float1ary3")), ary1, 3);
});
ASSERT_EQ(true, color.r > 100);
// TODO: Vulkan で、array は要素が常に 16byte アライメントされる。
// float g_float1ary3[3]; // offset:112
// float2 g_float2ary3[3]; // offset:160
// 差は 48、3 で割ると 16
// float g_float1ary3[4]; // offset:112
// float2 g_float2ary3[4]; // offset:176
//
}
// * [ ] float2[]
{
auto color = renderAndCapture([&](detail::ShaderSecondaryDescriptor* shd) {
shd->setInt(descriptorLayout->findUniformMemberIndex(_TT("g_type")), 12);
shd->setVectorArray(descriptorLayout->findUniformMemberIndex(_TT("g_float2ary3")), ary2, 3);
});
ASSERT_EQ(true, color.g > 200);
}
// * [ ] float3[]
{
auto color = renderAndCapture([&](detail::ShaderSecondaryDescriptor* shd) {
shd->setInt(descriptorLayout->findUniformMemberIndex(_TT("g_type")), 13);
shd->setVectorArray(descriptorLayout->findUniformMemberIndex(_TT("g_float3ary3")), ary2, 3);
});
ASSERT_EQ(true, color.b > 200);
}
// * [ ] float4[]
{
auto color = renderAndCapture([&](detail::ShaderSecondaryDescriptor* shd) {
shd->setInt(descriptorLayout->findUniformMemberIndex(_TT("g_type")), 14);
shd->setVectorArray(descriptorLayout->findUniformMemberIndex(_TT("g_float4ary3")), ary2, 3);
});
ASSERT_EQ(true, color.g > 200);
}
#if 0
//* [ ] 座標変換したときに一般的な使い方ができるか
{
auto pos = Vector4(1, 0, 0, 1);
auto mat = Matrix::makeRotationY(-Math::PIDiv2);
auto r = Vector4::transform(pos, mat); // (0, 0, 1)
buffer1->findParameter("g_type")->setInt(99);
buffer1->findParameter("g_color4")->setVector(pos);
buffer2->findParameter("g_mat44")->setMatrix(mat);
ASSERT_EQ(true, renderAndCapture().b > 200);
}
//* [ ] 座標変換したときに一般的な使い方ができるか (array)
{
auto pos = Vector4(1, 0, 0, 1);
auto mat = Matrix::makeRotationY(-Math::PIDiv2);
auto r = Vector4::transform(pos, mat); // (0, 0, 1)
Matrix ary[3] = { {}, mat, {} };
buffer1->findParameter("g_type")->setInt(100);
buffer1->findParameter("g_color4")->setVector(pos);
buffer2->findParameter("g_mat44ary3")->setMatrixArray(ary, 3);
ASSERT_EQ(true, renderAndCapture().b > 200);
}
//* [ ] mul で想定通り座標変換できること
{
auto m = Matrix::makeRotationY(-Math::PI / 2);
auto v = Vector4::transform(Vector4(1, 0, 0, 1), m);
buffer1->findParameter("g_type")->setInt(35);
buffer2->findParameter("g_mat44")->setMatrix(m);
auto c = renderAndCapture();
ASSERT_EQ(true, c.r < 10); // expect 0
ASSERT_EQ(true, c.g < 10); // expect 0
ASSERT_EQ(true, c.b > 200); // expect 255
}
//* [ ] mul で想定通り座標変換できること
{
auto m = Matrix::makeRotationY(-Math::PI / 2);
Matrix ary[3] = { {}, m, {} };
//auto v = Vector4::transform(Vector4(1, 0, 0, 1), m);
buffer1->findParameter("g_type")->setInt(36);
buffer2->findParameter("g_mat44ary3")->setMatrixArray(ary, 3);
auto c = renderAndCapture();
ASSERT_EQ(true, c.r < 10); // expect 0
ASSERT_EQ(true, c.g < 10); // expect 0
ASSERT_EQ(true, c.b > 200); // expect 255
}
#endif
#if 0 // FIXME: AMD Radeon(TM) HD 8490 で転置されてしまった。
// 以下、Gforce や macOS では成功するが、Radeon では失敗する。何かパラメータがあるのか?
// ひとまず、↑の mul では配列かどうかにかかわらず想定通りに座標変換できたのでこのまま行ってみる。
//* [ ] array しても転置されないこと
{
auto mat = Matrix();
mat(0, 2) = 1;
mat(2, 0) = 0;
Matrix ary[3] = { {}, mat, {} };
buffer2->findParameter("g_mat44")->setMatrix(mat);
buffer2->findParameter("g_mat44ary3")->setMatrixArray(ary, 3);
buffer1->findParameter("g_type")->setInt(101);
auto c = renderAndCapture();
ASSERT_EQ(true, c.r > 200); // expect 255
ASSERT_EQ(true, c.g > 200); // expect 255
ASSERT_EQ(true, c.b < 10); // expect 0
}
//* [ ] float3x4 (Vector4[3])
{
Matrix m(
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0);
m(0, 1) = 1; // 転置とかされることなく、この配列アクセスで値が取り出せる
buffer1->findParameter("g_type")->setInt(21);
buffer2->findParameter("g_mat34")->setMatrix(m);
ASSERT_EQ(true, renderAndCapture().r > 200);
}
//* [ ] float2x2 (Vector2[2])
{
Matrix m(
0, 0, 0, 0,
1, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0);
buffer1->findParameter("g_type")->setInt(22);
buffer2->findParameter("g_mat22")->setMatrix(m);
ASSERT_EQ(true, renderAndCapture().g > 200);
}
//* [ ] float4x3 (Vector3[4])
{
Matrix m(
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 1, 0);
buffer1->findParameter("g_type")->setInt(23);
buffer2->findParameter("g_mat43")->setMatrix(m);
ASSERT_EQ(true, renderAndCapture().b > 200);
}
//* [ ] float4x4 (Vector4[4])
{
Matrix m(
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 1,
0, 0, 0, 0);
buffer1->findParameter("g_type")->setInt(24);
buffer2->findParameter("g_mat44")->setMatrix(m);
ASSERT_EQ(true, renderAndCapture().r > 200);
}
//* [ ] float3x4[3] (Vector4[3][,,])
{
Matrix m[3] = {
{},
{
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
},
{} };
m[1](0, 1) = 1;
buffer1->findParameter("g_type")->setInt(31);
buffer2->findParameter("g_mat34ary3")->setMatrixArray(m, 3);
auto c = renderAndCapture();
ASSERT_EQ(true, c.r < 10); // expect 0
ASSERT_EQ(true, c.g > 200);// expect 255
ASSERT_EQ(true, c.b < 10); // expect 0
}
//* [ ] float4x4 (Vector4[4][,,])
{
Matrix m[3] = {
{},
{
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 1,
0, 0, 0, 0,
},
{} };
buffer1->findParameter("g_type")->setInt(34);
buffer2->findParameter("g_mat44ary3")->setMatrixArray(m, 3);
auto c = renderAndCapture();
ASSERT_EQ(true, c.r > 200);// expect 255
ASSERT_EQ(true, c.g < 10); // expect 0
ASSERT_EQ(true, c.b < 10); // expect 0
}
#endif
}
//------------------------------------------------------------------------------
TEST_F(Test_Graphics_LowLevelRendering, Texture)
{
auto shader1 = Shader::create(LN_ASSETFILE("TextureTest-1.vsh"), LN_ASSETFILE("TextureTest-1.psh"));
auto descriptorLayout = shader1->descriptorLayout();
auto shaderPass = shader1->techniques()[0]->passes()[0];
auto vertexDecl1 = makeObject<VertexLayout>();
vertexDecl1->addElement(0, VertexElementType::Float2, VertexElementUsage::TexCoord, 0);
vertexDecl1->addElement(0, VertexElementType::Float3, VertexElementUsage::Position, 0);
struct Vertex
{
Vector2 uv;
Vector3 pos;
};
#ifdef LN_COORD_RH
Vertex v[] = {
{ { 0, 0 }, { -1, 1, 0 }, },
{ { 0, 1 }, { -1, 0, 0 }, },
{ { 1, 0 }, { 0, 1, 0 }, },
{ { 1, 1 }, { 0, 0, 0 }, },
};
#else
Vertex v[] = {
{ { 0, 0 }, { -1, 1, 0 }, },
{ { 1, 0 }, { 0, 1, 0 }, },
{ { 0, 1 }, { -1, 0, 0 }, },
{ { 1, 1 }, { 0, 0, 0 }, },
};
#endif
auto vb1 = makeObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);
auto tex1 = makeObject<Texture2D>(2, 2);
auto bmp1 = tex1->map(MapMode::Write);
bmp1->setPixel32(0, 0, ColorI(255, 0, 0, 255));
bmp1->setPixel32(1, 0, ColorI(255, 0, 255, 255));
bmp1->setPixel32(0, 1, ColorI(0, 255, 0, 255));
bmp1->setPixel32(1, 1, ColorI(0, 0, 255, 255));
// * [ ] default
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass);
shd->setTexture(descriptorLayout->findTextureRegisterIndex(_TT("g_texture1")), tex1);
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setVertexLayout(vertexDecl1);
ctx->setVertexBuffer(0, vb1);
ctx->setIndexBuffer(nullptr);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(shd);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-TextureTest-1.png"), cbb);
}
}
#if 0 // 一部のモバイル環境では 3D テクスチャが使えないので、直近では対応予定なし
//------------------------------------------------------------------------------
TEST_F(Test_Graphics_LowLevelRendering, Texture3D)
{
auto shader1 = Shader::create(LN_ASSETFILE("Texture3DTest-1.vsh"), LN_ASSETFILE("Texture3DTest-1.psh"));
auto vertexDecl1 = makeObject<VertexLayout>();
vertexDecl1->addElement(0, VertexElementType::Float3, VertexElementUsage::Position, 0);
vertexDecl1->addElement(0, VertexElementType::Float3, VertexElementUsage::TexCoord, 0);
struct Vertex
{
Vector3 pos;
Vector3 uv;
};
Vertex v[] = {
{ { -1, 1, 0 }, { 0, 0, 0.5 }, }, // 0.5 で中央の face からサンプリングする
{ { 0, 1, 0 }, { 1, 0, 0.5 }, },
{ { -1, 0, 0 }, { 0, 1, 0.5 }, },
{ { 0, 0, 0 }, { 1, 1, 0.5 }, },
};
auto vb1 = makeObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);
auto tex1 = makeObject<Texture3D>(2, 2, 3);
auto bmp1 = tex1->map(MapMode::Write);
bmp1->setPixel32(0, 0, 1, ColorI(255, 0, 0, 255));
bmp1->setPixel32(1, 0, 1, ColorI(255, 0, 255, 255));
bmp1->setPixel32(0, 1, 1, ColorI(0, 255, 0, 255));
bmp1->setPixel32(1, 1, 1, ColorI(0, 0, 255, 255));
shader1->findParameter("g_texture1")->setTexture(tex1);
auto ctx = TestEnv::graphicsContext();
TestEnv::resetGraphicsContext(ctx);
ctx->setVertexLayout(vertexDecl1);
ctx->setVertexBuffer(0, vb1);
ctx->setIndexBuffer(nullptr);
ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);
// * [ ] default
{
ctx->clear(ClearFlags::All, Color::White, 1.0f, 0);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2);
ASSERT_SCREEN(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-Texture3D-1.png"));
}
}
#endif
//------------------------------------------------------------------------------
TEST_F(Test_Graphics_LowLevelRendering, SamplerState)
{
auto shader1 = Shader::create(LN_ASSETFILE("TextureTest-1.vsh"), LN_ASSETFILE("TextureTest-1.psh"));
auto descriptorLayout = shader1->descriptorLayout();
auto shaderPass = shader1->techniques()[0]->passes()[0];
auto vertexDecl1 = makeObject<VertexLayout>();
vertexDecl1->addElement(0, VertexElementType::Float2, VertexElementUsage::TexCoord, 0);
vertexDecl1->addElement(0, VertexElementType::Float3, VertexElementUsage::Position, 0);
struct Vertex
{
Vector2 uv;
Vector3 pos;
};
#ifdef LN_COORD_RH
Vertex v[] = {
{ { 0, 0 },{ -1, 1, 0 }, },
{ { 0, 2 },{ -1, 0, 0 }, },
{ { 2, 0 },{ 0, 1, 0 }, },
{ { 2, 2 },{ 0, 0, 0 }, },
};
#else
Vertex v[] = {
{ { 0, 0 },{ -1, 1, 0 }, },
{ { 2, 0 },{ 0, 1, 0 }, },
{ { 0, 2 },{ -1, 0, 0 }, },
{ { 2, 2 },{ 0, 0, 0 }, },
};
#endif
auto vb1 = makeObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);
auto tex1 = makeObject<Texture2D>(2, 2);
auto bmp1 = tex1->map(MapMode::Write);
bmp1->setPixel32(0, 0, ColorI(255, 0, 0, 255));
bmp1->setPixel32(1, 0, ColorI(255, 0, 255, 255));
bmp1->setPixel32(0, 1, ColorI(0, 255, 0, 255));
bmp1->setPixel32(1, 1, ColorI(0, 0, 255, 255));
// * [ ] default (Point, Reprat)
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass);
shd->setTexture(descriptorLayout->findTextureRegisterIndex(_TT("g_texture1")), tex1);
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setVertexLayout(vertexDecl1);
ctx->setVertexBuffer(0, vb1);
ctx->setIndexBuffer(nullptr);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(shd);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-SamplerState-1.png"), cbb);
}
// * [ ] Linear, Clamp
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass);
shd->setTexture(descriptorLayout->findTextureRegisterIndex(_TT("g_texture1")), tex1);
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setVertexLayout(vertexDecl1);
ctx->setVertexBuffer(0, vb1);
ctx->setIndexBuffer(nullptr);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(shd);
auto sampler = makeObject<SamplerState>();
sampler->setFilterMode(TextureFilterMode::Linear);
sampler->setAddressMode(TextureAddressMode::Clamp);
tex1->setSamplerState(sampler);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-SamplerState-2.png"), cbb);
}
}
//------------------------------------------------------------------------------
//## RenderState 関係のテスト。設定が Native layer まで渡ることを確認する。
TEST_F(Test_Graphics_LowLevelRendering, RenderStateTest)
{
auto shader1 = Shader::create(LN_ASSETFILE("SimplePosColor.vsh"), LN_ASSETFILE("SimplePosColor.psh"));
auto descriptorLayout = shader1->descriptorLayout();
auto shaderPass = shader1->techniques()[0]->passes()[0];
auto vertexDecl1 = makeObject<VertexLayout>();
vertexDecl1->addElement(0, VertexElementType::Float3, VertexElementUsage::Position, 0);
vertexDecl1->addElement(0, VertexElementType::Float4, VertexElementUsage::Color, 0);
struct Vertex
{
Vector3 pos;
Color color;
};
#ifdef LN_COORD_RH
Vertex v1[] = { // 深度テスト用に少し奥に出しておく
{ { -1, 1, 0.5 }, Color::Red },
{ { -1, 0, 0.5 }, Color::Red },
{ { 0, 1, 0.5 }, Color::Red },
{ { 0, 0, 0.5 }, Color::Red },
};
#else
Vertex v1[] = { // 深度テスト用に少し奥に出しておく
{ { -1, 1, 0.5 }, Color::Red },
{ { 0, 1, 0.5 }, Color::Red },
{ { -1, 0, 0.5 }, Color::Red },
{ { 0, 0, 0.5 }, Color::Red },
};
#endif
auto vb1 = makeObject<VertexBuffer>(sizeof(v1), v1, GraphicsResourceUsage::Static);
#ifdef LN_COORD_RH
Vertex v2[] = {
{ { -0.5, 0.5, 0 }, Color::Blue },
{ { -0.5, -0.5, 0 }, Color::Blue },
{ { 0.5, 0.5, 0 }, Color::Blue },
{ { 0.5, -0.5, 0 }, Color::Blue },
};
#else
Vertex v2[] = {
{ { -0.5, 0.5, 0 }, Color::Blue },
{ { 0.5, 0.5, 0 }, Color::Blue },
{ { -0.5, -0.5, 0 }, Color::Blue },
{ { 0.5, -0.5, 0 }, Color::Blue },
};
#endif
auto vb2 = makeObject<VertexBuffer>(sizeof(v2), v2, GraphicsResourceUsage::Static);
#ifdef LN_COORD_RH
Vertex v3[] = { // 裏面テスト用
{ { 0, 0, 0 }, Color::Green },
{ { 1, 0, 0 }, Color::Green },
{ { 0, -1, 0 }, Color::Green },
{ { 1, -1, 0 }, Color::Green },
};
#else
Vertex v3[] = { // 裏面テスト用
{ { 0, 0, 0 }, Color::Green },
{ { 0, -1, 0 }, Color::Green },
{ { 1, 0, 0 }, Color::Green },
{ { 1, -1, 0 }, Color::Green },
};
#endif
auto vb3 = makeObject<VertexBuffer>(sizeof(v3), v3, GraphicsResourceUsage::Static);
// * [ ] check BlendState (RGB Add blend)
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
crp->setClearValues(ClearFlags::All, Color::Gray, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setVertexLayout(vertexDecl1);
ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);
BlendStateDesc state1;
state1.renderTargets[0].blendEnable = true;
state1.renderTargets[0].sourceBlend = BlendFactor::One;
state1.renderTargets[0].destinationBlend = BlendFactor::One;
state1.renderTargets[0].blendOp = BlendOp::Add;
ctx->setBlendState(BlendStateDesc());
ctx->setVertexBuffer(0, vb1);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2);
ctx->setBlendState(state1);
ctx->setVertexBuffer(0, vb2);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-RenderStateTest-1.png"), cbb);
//ctx->setBlendState(BlendStateDesc()); // 戻しておく
}
// * [ ] check RasterizerState
{
RasterizerStateDesc state1;
state1.cullMode = CullMode::Front;
RasterizerStateDesc state2;
state2.cullMode = CullMode::Back;
RasterizerStateDesc state3;
state3.cullMode = CullMode::None;
RasterizerStateDesc state4;
state4.fillMode = FillMode::Wireframe;
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setVertexLayout(vertexDecl1);
ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);
ctx->setRasterizerState(state1);
ctx->setVertexBuffer(0, vb1);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2); // 赤は描かれない
ctx->setVertexBuffer(0, vb3);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2); // 緑は描かれる
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-RenderStateTest-2-1.png"), cbb);
}
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);
ctx->setVertexLayout(vertexDecl1);
ctx->setRasterizerState(state2);
ctx->setVertexBuffer(0, vb1);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2); // 赤は描かれる
ctx->setVertexBuffer(0, vb3);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2); // 緑は描かれない
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-RenderStateTest-2-2.png"), cbb);
}
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);
ctx->setVertexLayout(vertexDecl1);
ctx->setRasterizerState(state3);
ctx->setVertexBuffer(0, vb1);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2); // 赤は描かれる
ctx->setVertexBuffer(0, vb3);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2); // 緑は描かれる
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-RenderStateTest-2-3.png"), cbb);
}
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);
ctx->setVertexLayout(vertexDecl1);
ctx->setRasterizerState(state4);
ctx->setVertexBuffer(0, vb2);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-RenderStateTest-2-4.png"), cbb);
}
//ctx->setRasterizerState(RasterizerStateDesc()); // 戻しておく
}
// * [ ] check DepthStencilState
{
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);
ctx->setVertexLayout(vertexDecl1);
ctx->setVertexBuffer(0, vb2);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2); // 青 (z=0)
ctx->setVertexBuffer(0, vb1);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2); // 赤 (z=0.5)
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-RenderStateTest-3-1.png"), cbb);
}
{
DepthStencilStateDesc state1;
state1.depthTestFunc = ComparisonFunc::Always;
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);
ctx->setVertexLayout(vertexDecl1);
ctx->setDepthStencilState(state1);
ctx->setVertexBuffer(0, vb2);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2); // 青 (z=0)
ctx->setVertexBuffer(0, vb1);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2); // 赤 (z=0.5)
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-RenderStateTest-3-2.png"), cbb);
}
{
DepthStencilStateDesc state2;
state2.depthWriteEnabled = false;
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);
ctx->setVertexLayout(vertexDecl1);
ctx->setDepthStencilState(state2);
ctx->setVertexBuffer(0, vb2);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2); // 青 (z=0)
ctx->setVertexBuffer(0, vb1);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2); // 赤 (z=0.5)
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-RenderStateTest-3-3.png"), cbb);
}
//ctx->setDepthStencilState(DepthStencilStateDesc()); // 戻しておく
}
// * [ ] check DepthStencilState (stencil test)
{
// ステンシル書き込み (参照値0xFF が型抜きの hole と考える)
DepthStencilStateDesc state1;
state1.stencilEnabled = true; // true にしないと書き込まれない
state1.frontFace.stencilPassOp = StencilOp::Replace; // 描画できたところに参照値を書き込む
state1.frontFace.stencilFunc = ComparisonFunc::Always; // 常に成功(常に上書き)
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);
ctx->setVertexLayout(vertexDecl1);
ctx->setDepthStencilState(state1);
ctx->setVertexBuffer(0, vb1);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2); // 赤 (z=0.5)
// ステンシルテスト
DepthStencilStateDesc state2;
state2.stencilEnabled = true;
state2.frontFace.stencilFunc = ComparisonFunc::Equal; // 0xFF(デフォルト値)と等しければ成功 → カラーバッファ書き込み
ctx->setDepthStencilState(state2);
ctx->setVertexBuffer(0, vb2);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2); // 青 (z=0)
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-RenderStateTest-4-1.png"), cbb);
}
//ctx->setDepthStencilState(DepthStencilStateDesc()); // 戻しておく
// TODO: ステンシル書き込み時に描画はしない
}
}
//------------------------------------------------------------------------------
//## RenderTarget
TEST_F(Test_Graphics_LowLevelRendering, RenderTarget)
{
//* [ ] 特に OpenGL を使用している場合に、RT をサンプリングすると上下反転しないことを確認する。
{
auto descriptorLayout1 = m_shader1->descriptorLayout();
auto shaderPass1 = m_shader1->techniques()[0]->passes()[0];
auto shader2 = Shader::create(LN_ASSETFILE("TextureTest-1.vsh"), LN_ASSETFILE("TextureTest-1.psh"));
auto descriptorLayout2 = shader2->descriptorLayout();
auto shaderPass2 = shader2->techniques()[0]->passes()[0];
#ifdef LN_COORD_RH
Vector4 v1[] = {
Vector4(0, 0.5, 0, 1),
Vector4(-0.5, -0.25, 0, 1),
Vector4(0.5, -0.25, 0, 1),
};
#else
Vector4 v1[] = {
Vector4(0, 0.5, 0, 1),
Vector4(0.5, -0.25, 0, 1),
Vector4(-0.5, -0.25, 0, 1),
};
#endif
auto vertexBuffer1 = makeObject<VertexBuffer>(sizeof(v1), v1, GraphicsResourceUsage::Static);
struct Vertex
{
Vector2 uv;
Vector3 pos;
};
#ifdef LN_COORD_RH
Vertex v[] = {
{ { 0, 0 }, { -1, 1, 0 }, },
{ { 0, 1 }, { -1, -1, 0 }, },
{ { 1, 0 }, { 1, 1, 0 }, },
{ { 1, 1 }, { 1, -1, 0 }, },
};
#else
Vertex v[] = {
{ { 0, 0 }, { -1, 1, 0 }, },
{ { 1, 0 }, { 1, 1, 0 }, },
{ { 0, 1 }, { -1, -1, 0 }, },
{ { 1, 1 }, { 1, -1, 0 }, },
};
#endif
auto vertexBuffer2 = makeObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);
auto vertexDecl2 = makeObject<VertexLayout>();
vertexDecl2->addElement(0, VertexElementType::Float2, VertexElementUsage::TexCoord, 0);
vertexDecl2->addElement(0, VertexElementType::Float3, VertexElementUsage::Position, 0);
auto renderTarget1 = makeObject<RenderTargetTexture>(160, 120, TextureFormat::RGBA8, false, false);
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto renderPass = makeObject<RenderPass>();
renderPass->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
// まず renderTarget1 へ緑色の三角形を描く
{
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass1);
shd->setVector(descriptorLayout1->findUniformMemberIndex(_TT("g_color")), Vector4(0, 1, 0, 1));
renderPass->setRenderTarget(0, renderTarget1);
ctx->beginRenderPass(renderPass);
ctx->setVertexLayout(m_vertexDecl1);
ctx->setVertexBuffer(0, vertexBuffer1);
ctx->setShaderPass(shaderPass1);
ctx->setShaderDescriptor_deprecated(shd);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitive(0, 1);
ctx->endRenderPass();
}
// 次に renderTarget1 からバックバッファへ全体を描く
{
auto crp = TestEnv::renderPass();
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass2);
shd->setTexture(descriptorLayout2->findTextureRegisterIndex(_TT("g_texture1")), renderTarget1);
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setVertexLayout(vertexDecl2);
ctx->setVertexBuffer(0, vertexBuffer2);
ctx->setShaderPass(shaderPass2);
ctx->setShaderDescriptor_deprecated(shd);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2);
ctx->endRenderPass();
}
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-RenderTarget-1.png"), cbb);
}
}
//------------------------------------------------------------------------------
//## MultiRenderTarget
TEST_F(Test_Graphics_LowLevelRendering, MultiRenderTarget)
{
auto shader1 = Shader::create(LN_ASSETFILE("Graphics/MultiRenderTargetTest-1.vsh"), LN_ASSETFILE("Graphics/MultiRenderTargetTest-1.psh"));
auto descriptorLayout = shader1->descriptorLayout();
auto shaderPass = shader1->techniques()[0]->passes()[0];
#ifdef LN_COORD_RH
Vector3 v[] = { { -1, 1, 0 },{ -1, -1, 0 },{ 1, 1, 0 },{ 1, -1, 0 } };
#else
Vector3 v[] = { { -1, 1, 0 },{ 1, 1, 0 },{ -1, -1, 0 },{ 1, -1, 0 } };
#endif
auto vertexBuffer1 = makeObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);
auto vertexDecl1 = makeObject<VertexLayout>();
vertexDecl1->addElement(0, VertexElementType::Float3, VertexElementUsage::Position, 0);
auto renderTarget0 = makeObject<RenderTargetTexture>(160, 120, TextureFormat::RGBA8, false, false);
auto renderTarget1 = makeObject<RenderTargetTexture>(160, 120, TextureFormat::RGBA8, false, false);
auto ctx = TestEnv::beginFrame();
auto renderPass1 = makeObject<RenderPass>();
renderPass1->setRenderTarget(0, renderTarget0);
renderPass1->setRenderTarget(1, renderTarget1);
renderPass1->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
{
ctx->beginRenderPass(renderPass1);
ctx->setVertexLayout(vertexDecl1);
ctx->setVertexBuffer(0, vertexBuffer1);
ctx->setShaderPass(shaderPass);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2);
ctx->endRenderPass();
}
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Expects/Test_Graphics_LowLevelRendering-MultiRenderTarget-0.png"), renderTarget0);
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Expects/Test_Graphics_LowLevelRendering-MultiRenderTarget-1.png"), renderTarget1);
}
//------------------------------------------------------------------------------
TEST_F(Test_Graphics_LowLevelRendering, Instancing)
{
struct InstanceData
{
Vector4 Pos;
Vector4 InstanceColor;
};
auto shader1 = Shader::create(LN_ASSETFILE("Graphics/Instancing.vsh"), LN_ASSETFILE("Graphics/Instancing.psh"));
auto descriptorLayout = shader1->descriptorLayout();
auto shaderPass = shader1->techniques()[0]->passes()[0];
// メッシュはひとつだけ
#ifdef LN_COORD_RH
Vector4 v[] = {
Vector4(-1, 1, 0, 1),
Vector4(-1, 0, 0, 1),
Vector4(0, 1, 0, 1),
};
#else
Vector4 v[] = {
Vector4(-1, 1, 0, 1),
Vector4(0, 1, 0, 1),
Vector4(-1, 0, 0, 1),
};
#endif
auto vertexBuffer1 = makeObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);
// オフセットとカラーをインスタンス分用意
InstanceData instanceData[] = {
{ Vector4(0, 0, 0, 1), Vector4(1, 0, 0, 1) },
{ Vector4(1, 0, 0, 1), Vector4(0, 1, 0, 1) },
{ Vector4(0, -1, 0, 1), Vector4(0, 0, 1, 1) },
{ Vector4(1, -1, 0, 1), Vector4(1, 1, 0, 1) },
};
auto vertexBuffer2 = makeObject<VertexBuffer>(sizeof(instanceData), instanceData, GraphicsResourceUsage::Static);
uint16_t ib[] = { 0, 1, 2 };
auto indexBuffer1 = makeObject<IndexBuffer>(3, IndexBufferFormat::UInt16, ib, GraphicsResourceUsage::Static);
auto vertexDecl1 = makeObject<VertexLayout>();
vertexDecl1->addElement(0, VertexElementType::Float4, VertexElementUsage::Position, 0);
vertexDecl1->addElement(1, VertexElementType::Float4, VertexElementUsage::Position, 1, VertexInputRate::Instance);
vertexDecl1->addElement(1, VertexElementType::Float4, VertexElementUsage::Color, 0, VertexInputRate::Instance);
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setVertexLayout(vertexDecl1);
ctx->setVertexBuffer(0, vertexBuffer1);
ctx->setVertexBuffer(1, vertexBuffer2);
ctx->setIndexBuffer(indexBuffer1);
ctx->setShaderPass(shaderPass);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
ctx->drawPrimitiveIndexed(0, 1, 4);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/LowLevelRendering-Instancing-1.png"), cbb);
}
//------------------------------------------------------------------------------
TEST_F(Test_Graphics_LowLevelRendering, MipMap)
{
auto shader1 = Shader::create(LN_ASSETFILE("TextureTest-1.vsh"), LN_ASSETFILE("TextureTest-1.psh"));
auto descriptorLayout = shader1->descriptorLayout();
auto shaderPass = shader1->techniques()[0]->passes()[0];
auto vertexDecl1 = makeObject<VertexLayout>();
vertexDecl1->addElement(0, VertexElementType::Float3, VertexElementUsage::Position, 0);
vertexDecl1->addElement(0, VertexElementType::Float2, VertexElementUsage::TexCoord, 0);
struct Vertex
{
Vector3 pos;
Vector2 uv;
};
#ifdef LN_COORD_RH
Vertex v[] = {
{ { -0.5, 0, 0 }, { 0, 0 }, }, // far
{ { -1, -1, 1 }, { 0, 1 }, }, // near
{ { 0.5, 0, 0 }, { 1, 0 }, }, // far
{ { 1, -1, 1 }, { 1, 1 }, }, // near
};
#else
Vertex v[] = {
{ { -0.5, 0, 0 }, { 0, 0 }, }, // far
{ { 0.5, 0, 0 }, { 1, 0 }, }, // far
{ { -1, -1, 1 }, { 0, 1 }, }, // near
{ { 1, -1, 1 }, { 1, 1 }, }, // near
};
#endif
auto vb1 = makeObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);
// 四辺に黒線を引いたテクスチャ
SizeI gridTexSize(128, 128);
auto gridTex = makeObject<Texture2D>(gridTexSize.width, gridTexSize.height, TextureFormat::RGBA8);
gridTex->setMipmapEnabled(true);
gridTex->setResourceUsage(GraphicsResourceUsage::Static);
gridTex->clear(Color::White);
for (int x = 0; x < gridTexSize.width; ++x) {
gridTex->setPixel(x, 0, Color::Black);
gridTex->setPixel(x, 1, Color::Black);
gridTex->setPixel(x, 2, Color::Black);
gridTex->setPixel(x, 3, Color::Black);
gridTex->setPixel(x, 4, Color::Black);
gridTex->setPixel(x, gridTexSize.width - 1, Color::Black);
gridTex->setPixel(x, gridTexSize.width - 2, Color::Black);
gridTex->setPixel(x, gridTexSize.width - 3, Color::Black);
gridTex->setPixel(x, gridTexSize.width - 4, Color::Black);
gridTex->setPixel(x, gridTexSize.width - 5, Color::Black);
}
for (int y = 0; y < gridTexSize.height; ++y) {
gridTex->setPixel(0, y, Color::Black);
gridTex->setPixel(1, y, Color::Black);
gridTex->setPixel(2, y, Color::Black);
gridTex->setPixel(3, y, Color::Black);
gridTex->setPixel(4, y, Color::Black);
gridTex->setPixel(gridTexSize.height - 1, y, Color::Black);
gridTex->setPixel(gridTexSize.height - 2, y, Color::Black);
gridTex->setPixel(gridTexSize.height - 3, y, Color::Black);
gridTex->setPixel(gridTexSize.height - 4, y, Color::Black);
gridTex->setPixel(gridTexSize.height - 5, y, Color::Black);
}
{
auto ctx = TestEnv::beginFrame();
auto cbb = TestEnv::mainWindowSwapChain()->currentBackbuffer();
auto crp = TestEnv::renderPass();
auto shd = ctx->allocateShaderDescriptor_deprecated(shaderPass);
shd->setTexture(descriptorLayout->findTextureRegisterIndex(_TT("g_texture1")), gridTex);
crp->setClearValues(ClearFlags::All, Color::White, 1.0f, 0);
ctx->beginRenderPass(crp);
ctx->setVertexLayout(vertexDecl1);
ctx->setVertexBuffer(0, vb1);
ctx->setIndexBuffer(nullptr);
ctx->setShaderPass(shaderPass);
ctx->setShaderDescriptor_deprecated(shd);
ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
ctx->drawPrimitive(0, 2);
ctx->endRenderPass();
TestEnv::endFrame();
ASSERT_RENDERTARGET(LN_ASSETFILE("Graphics/Result/Test_Graphics_LowLevelRendering-MipMap-1.png"), cbb);
// MipMap が正しく生成されていれば、内側の境界がぼかされるのでグレーになっているはず
}
}
| 35.907925
| 175
| 0.662436
|
lriki
|
fc8f78032ee6ba1a767dcf2a6177d3c738140678
| 892
|
cpp
|
C++
|
postOrderDolasim.cpp
|
musttafayildirim/veriYapilariUygulamalari
|
87015f19e566f71c0e48c8a7e4c2fb01070d808d
|
[
"Apache-2.0"
] | null | null | null |
postOrderDolasim.cpp
|
musttafayildirim/veriYapilariUygulamalari
|
87015f19e566f71c0e48c8a7e4c2fb01070d808d
|
[
"Apache-2.0"
] | null | null | null |
postOrderDolasim.cpp
|
musttafayildirim/veriYapilariUygulamalari
|
87015f19e566f71c0e48c8a7e4c2fb01070d808d
|
[
"Apache-2.0"
] | null | null | null |
#include <stdlib.h>
#include <iostream>
using namespace std;
struct dugum
{
int value;
dugum *sol;
dugum *sag;
};
struct dugum *ana;
struct dugum *ekle(struct dugum *r, int value);
void postOrder(struct dugum *r); // Kök sonda
int main()
{
ana = NULL;
int n, v;
cout << "Kac adet değer eklemek istiyorsunuz?" << endl;
cin >> n;
for(int i=0; i<n; i++){
cout << i+1 <<". Deger ";
cin >> v;
ana = ekle(ana, v);
}
cout << "Postorder Dolasim: ";
postOrder(ana);
cout << endl;
return 0;
}
struct dugum *ekle(struct dugum *r, int value)
{
if(r==NULL)
{
r = (struct dugum*) malloc(sizeof(struct dugum));
r->value = value;
r->sol = NULL;
r->sag = NULL;
}
else if(value < r->value){
r->sol = ekle(r->sol, value);
}
else {
r->sag = ekle(r->sag, value);
}
return r;
}
void postOrder(struct dugum *r) // Kök sonda
{
if(r!=NULL){
postOrder(r->sol);
postOrder(r->sag);
cout << r->value << " ";
}
}
| 14.387097
| 56
| 0.617713
|
musttafayildirim
|
fc8fe31d2dd383ec2b5a44bcaa440938d6277550
| 66,901
|
cc
|
C++
|
test/aarch32/test-assembler-cond-rdlow-rnlow-rmlow-in-it-block-t32.cc
|
capablevms/VIXL
|
769c8e46a09bb077e9a2148b86a2093addce8233
|
[
"BSD-3-Clause"
] | 573
|
2016-08-31T20:21:20.000Z
|
2021-08-29T14:01:11.000Z
|
test/aarch32/test-assembler-cond-rdlow-rnlow-rmlow-in-it-block-t32.cc
|
capablevms/VIXL
|
769c8e46a09bb077e9a2148b86a2093addce8233
|
[
"BSD-3-Clause"
] | 366
|
2016-09-02T06:37:43.000Z
|
2021-08-11T18:38:24.000Z
|
test/aarch32/test-assembler-cond-rdlow-rnlow-rmlow-in-it-block-t32.cc
|
capablevms/VIXL
|
769c8e46a09bb077e9a2148b86a2093addce8233
|
[
"BSD-3-Clause"
] | 135
|
2016-09-01T02:02:58.000Z
|
2021-08-13T01:25:22.000Z
|
// Copyright 2016, VIXL authors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of ARM Limited nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// -----------------------------------------------------------------------------
// This file is auto generated from the
// test/aarch32/config/template-assembler-aarch32.cc.in template file using
// tools/generate_tests.py.
//
// PLEASE DO NOT EDIT.
// -----------------------------------------------------------------------------
#include "test-runner.h"
#include "test-utils.h"
#include "test-utils-aarch32.h"
#include "aarch32/assembler-aarch32.h"
#include "aarch32/macro-assembler-aarch32.h"
#define BUF_SIZE (4096)
namespace vixl {
namespace aarch32 {
// List of instruction mnemonics.
#define FOREACH_INSTRUCTION(M) M(mul)
// The following definitions are defined again in each generated test, therefore
// we need to place them in an anomymous namespace. It expresses that they are
// local to this file only, and the compiler is not allowed to share these types
// across test files during template instantiation. Specifically, `Operands` has
// various layouts across generated tests so it absolutely cannot be shared.
#ifdef VIXL_INCLUDE_TARGET_T32
namespace {
// Values to be passed to the assembler to produce the instruction under test.
struct Operands {
Condition cond;
Register rd;
Register rn;
Register rm;
};
// This structure contains all data needed to test one specific
// instruction.
struct TestData {
// The `operands` field represents what to pass to the assembler to
// produce the instruction.
Operands operands;
// True if we need to generate an IT instruction for this test to be valid.
bool in_it_block;
// The condition to give the IT instruction, this will be set to "al" by
// default.
Condition it_condition;
// Description of the operands, used for error reporting.
const char* operands_description;
// Unique identifier, used for generating traces.
const char* identifier;
};
struct TestResult {
size_t size;
const byte* encoding;
};
// Each element of this array produce one instruction encoding.
const TestData kTests[] =
{{{eq, r0, r0, r0}, true, eq, "eq r0 r0 r0", "eq_r0_r0_r0"},
{{eq, r0, r1, r0}, true, eq, "eq r0 r1 r0", "eq_r0_r1_r0"},
{{eq, r0, r2, r0}, true, eq, "eq r0 r2 r0", "eq_r0_r2_r0"},
{{eq, r0, r3, r0}, true, eq, "eq r0 r3 r0", "eq_r0_r3_r0"},
{{eq, r0, r4, r0}, true, eq, "eq r0 r4 r0", "eq_r0_r4_r0"},
{{eq, r0, r5, r0}, true, eq, "eq r0 r5 r0", "eq_r0_r5_r0"},
{{eq, r0, r6, r0}, true, eq, "eq r0 r6 r0", "eq_r0_r6_r0"},
{{eq, r0, r7, r0}, true, eq, "eq r0 r7 r0", "eq_r0_r7_r0"},
{{eq, r1, r0, r1}, true, eq, "eq r1 r0 r1", "eq_r1_r0_r1"},
{{eq, r1, r1, r1}, true, eq, "eq r1 r1 r1", "eq_r1_r1_r1"},
{{eq, r1, r2, r1}, true, eq, "eq r1 r2 r1", "eq_r1_r2_r1"},
{{eq, r1, r3, r1}, true, eq, "eq r1 r3 r1", "eq_r1_r3_r1"},
{{eq, r1, r4, r1}, true, eq, "eq r1 r4 r1", "eq_r1_r4_r1"},
{{eq, r1, r5, r1}, true, eq, "eq r1 r5 r1", "eq_r1_r5_r1"},
{{eq, r1, r6, r1}, true, eq, "eq r1 r6 r1", "eq_r1_r6_r1"},
{{eq, r1, r7, r1}, true, eq, "eq r1 r7 r1", "eq_r1_r7_r1"},
{{eq, r2, r0, r2}, true, eq, "eq r2 r0 r2", "eq_r2_r0_r2"},
{{eq, r2, r1, r2}, true, eq, "eq r2 r1 r2", "eq_r2_r1_r2"},
{{eq, r2, r2, r2}, true, eq, "eq r2 r2 r2", "eq_r2_r2_r2"},
{{eq, r2, r3, r2}, true, eq, "eq r2 r3 r2", "eq_r2_r3_r2"},
{{eq, r2, r4, r2}, true, eq, "eq r2 r4 r2", "eq_r2_r4_r2"},
{{eq, r2, r5, r2}, true, eq, "eq r2 r5 r2", "eq_r2_r5_r2"},
{{eq, r2, r6, r2}, true, eq, "eq r2 r6 r2", "eq_r2_r6_r2"},
{{eq, r2, r7, r2}, true, eq, "eq r2 r7 r2", "eq_r2_r7_r2"},
{{eq, r3, r0, r3}, true, eq, "eq r3 r0 r3", "eq_r3_r0_r3"},
{{eq, r3, r1, r3}, true, eq, "eq r3 r1 r3", "eq_r3_r1_r3"},
{{eq, r3, r2, r3}, true, eq, "eq r3 r2 r3", "eq_r3_r2_r3"},
{{eq, r3, r3, r3}, true, eq, "eq r3 r3 r3", "eq_r3_r3_r3"},
{{eq, r3, r4, r3}, true, eq, "eq r3 r4 r3", "eq_r3_r4_r3"},
{{eq, r3, r5, r3}, true, eq, "eq r3 r5 r3", "eq_r3_r5_r3"},
{{eq, r3, r6, r3}, true, eq, "eq r3 r6 r3", "eq_r3_r6_r3"},
{{eq, r3, r7, r3}, true, eq, "eq r3 r7 r3", "eq_r3_r7_r3"},
{{eq, r4, r0, r4}, true, eq, "eq r4 r0 r4", "eq_r4_r0_r4"},
{{eq, r4, r1, r4}, true, eq, "eq r4 r1 r4", "eq_r4_r1_r4"},
{{eq, r4, r2, r4}, true, eq, "eq r4 r2 r4", "eq_r4_r2_r4"},
{{eq, r4, r3, r4}, true, eq, "eq r4 r3 r4", "eq_r4_r3_r4"},
{{eq, r4, r4, r4}, true, eq, "eq r4 r4 r4", "eq_r4_r4_r4"},
{{eq, r4, r5, r4}, true, eq, "eq r4 r5 r4", "eq_r4_r5_r4"},
{{eq, r4, r6, r4}, true, eq, "eq r4 r6 r4", "eq_r4_r6_r4"},
{{eq, r4, r7, r4}, true, eq, "eq r4 r7 r4", "eq_r4_r7_r4"},
{{eq, r5, r0, r5}, true, eq, "eq r5 r0 r5", "eq_r5_r0_r5"},
{{eq, r5, r1, r5}, true, eq, "eq r5 r1 r5", "eq_r5_r1_r5"},
{{eq, r5, r2, r5}, true, eq, "eq r5 r2 r5", "eq_r5_r2_r5"},
{{eq, r5, r3, r5}, true, eq, "eq r5 r3 r5", "eq_r5_r3_r5"},
{{eq, r5, r4, r5}, true, eq, "eq r5 r4 r5", "eq_r5_r4_r5"},
{{eq, r5, r5, r5}, true, eq, "eq r5 r5 r5", "eq_r5_r5_r5"},
{{eq, r5, r6, r5}, true, eq, "eq r5 r6 r5", "eq_r5_r6_r5"},
{{eq, r5, r7, r5}, true, eq, "eq r5 r7 r5", "eq_r5_r7_r5"},
{{eq, r6, r0, r6}, true, eq, "eq r6 r0 r6", "eq_r6_r0_r6"},
{{eq, r6, r1, r6}, true, eq, "eq r6 r1 r6", "eq_r6_r1_r6"},
{{eq, r6, r2, r6}, true, eq, "eq r6 r2 r6", "eq_r6_r2_r6"},
{{eq, r6, r3, r6}, true, eq, "eq r6 r3 r6", "eq_r6_r3_r6"},
{{eq, r6, r4, r6}, true, eq, "eq r6 r4 r6", "eq_r6_r4_r6"},
{{eq, r6, r5, r6}, true, eq, "eq r6 r5 r6", "eq_r6_r5_r6"},
{{eq, r6, r6, r6}, true, eq, "eq r6 r6 r6", "eq_r6_r6_r6"},
{{eq, r6, r7, r6}, true, eq, "eq r6 r7 r6", "eq_r6_r7_r6"},
{{eq, r7, r0, r7}, true, eq, "eq r7 r0 r7", "eq_r7_r0_r7"},
{{eq, r7, r1, r7}, true, eq, "eq r7 r1 r7", "eq_r7_r1_r7"},
{{eq, r7, r2, r7}, true, eq, "eq r7 r2 r7", "eq_r7_r2_r7"},
{{eq, r7, r3, r7}, true, eq, "eq r7 r3 r7", "eq_r7_r3_r7"},
{{eq, r7, r4, r7}, true, eq, "eq r7 r4 r7", "eq_r7_r4_r7"},
{{eq, r7, r5, r7}, true, eq, "eq r7 r5 r7", "eq_r7_r5_r7"},
{{eq, r7, r6, r7}, true, eq, "eq r7 r6 r7", "eq_r7_r6_r7"},
{{eq, r7, r7, r7}, true, eq, "eq r7 r7 r7", "eq_r7_r7_r7"},
{{ne, r0, r0, r0}, true, ne, "ne r0 r0 r0", "ne_r0_r0_r0"},
{{ne, r0, r1, r0}, true, ne, "ne r0 r1 r0", "ne_r0_r1_r0"},
{{ne, r0, r2, r0}, true, ne, "ne r0 r2 r0", "ne_r0_r2_r0"},
{{ne, r0, r3, r0}, true, ne, "ne r0 r3 r0", "ne_r0_r3_r0"},
{{ne, r0, r4, r0}, true, ne, "ne r0 r4 r0", "ne_r0_r4_r0"},
{{ne, r0, r5, r0}, true, ne, "ne r0 r5 r0", "ne_r0_r5_r0"},
{{ne, r0, r6, r0}, true, ne, "ne r0 r6 r0", "ne_r0_r6_r0"},
{{ne, r0, r7, r0}, true, ne, "ne r0 r7 r0", "ne_r0_r7_r0"},
{{ne, r1, r0, r1}, true, ne, "ne r1 r0 r1", "ne_r1_r0_r1"},
{{ne, r1, r1, r1}, true, ne, "ne r1 r1 r1", "ne_r1_r1_r1"},
{{ne, r1, r2, r1}, true, ne, "ne r1 r2 r1", "ne_r1_r2_r1"},
{{ne, r1, r3, r1}, true, ne, "ne r1 r3 r1", "ne_r1_r3_r1"},
{{ne, r1, r4, r1}, true, ne, "ne r1 r4 r1", "ne_r1_r4_r1"},
{{ne, r1, r5, r1}, true, ne, "ne r1 r5 r1", "ne_r1_r5_r1"},
{{ne, r1, r6, r1}, true, ne, "ne r1 r6 r1", "ne_r1_r6_r1"},
{{ne, r1, r7, r1}, true, ne, "ne r1 r7 r1", "ne_r1_r7_r1"},
{{ne, r2, r0, r2}, true, ne, "ne r2 r0 r2", "ne_r2_r0_r2"},
{{ne, r2, r1, r2}, true, ne, "ne r2 r1 r2", "ne_r2_r1_r2"},
{{ne, r2, r2, r2}, true, ne, "ne r2 r2 r2", "ne_r2_r2_r2"},
{{ne, r2, r3, r2}, true, ne, "ne r2 r3 r2", "ne_r2_r3_r2"},
{{ne, r2, r4, r2}, true, ne, "ne r2 r4 r2", "ne_r2_r4_r2"},
{{ne, r2, r5, r2}, true, ne, "ne r2 r5 r2", "ne_r2_r5_r2"},
{{ne, r2, r6, r2}, true, ne, "ne r2 r6 r2", "ne_r2_r6_r2"},
{{ne, r2, r7, r2}, true, ne, "ne r2 r7 r2", "ne_r2_r7_r2"},
{{ne, r3, r0, r3}, true, ne, "ne r3 r0 r3", "ne_r3_r0_r3"},
{{ne, r3, r1, r3}, true, ne, "ne r3 r1 r3", "ne_r3_r1_r3"},
{{ne, r3, r2, r3}, true, ne, "ne r3 r2 r3", "ne_r3_r2_r3"},
{{ne, r3, r3, r3}, true, ne, "ne r3 r3 r3", "ne_r3_r3_r3"},
{{ne, r3, r4, r3}, true, ne, "ne r3 r4 r3", "ne_r3_r4_r3"},
{{ne, r3, r5, r3}, true, ne, "ne r3 r5 r3", "ne_r3_r5_r3"},
{{ne, r3, r6, r3}, true, ne, "ne r3 r6 r3", "ne_r3_r6_r3"},
{{ne, r3, r7, r3}, true, ne, "ne r3 r7 r3", "ne_r3_r7_r3"},
{{ne, r4, r0, r4}, true, ne, "ne r4 r0 r4", "ne_r4_r0_r4"},
{{ne, r4, r1, r4}, true, ne, "ne r4 r1 r4", "ne_r4_r1_r4"},
{{ne, r4, r2, r4}, true, ne, "ne r4 r2 r4", "ne_r4_r2_r4"},
{{ne, r4, r3, r4}, true, ne, "ne r4 r3 r4", "ne_r4_r3_r4"},
{{ne, r4, r4, r4}, true, ne, "ne r4 r4 r4", "ne_r4_r4_r4"},
{{ne, r4, r5, r4}, true, ne, "ne r4 r5 r4", "ne_r4_r5_r4"},
{{ne, r4, r6, r4}, true, ne, "ne r4 r6 r4", "ne_r4_r6_r4"},
{{ne, r4, r7, r4}, true, ne, "ne r4 r7 r4", "ne_r4_r7_r4"},
{{ne, r5, r0, r5}, true, ne, "ne r5 r0 r5", "ne_r5_r0_r5"},
{{ne, r5, r1, r5}, true, ne, "ne r5 r1 r5", "ne_r5_r1_r5"},
{{ne, r5, r2, r5}, true, ne, "ne r5 r2 r5", "ne_r5_r2_r5"},
{{ne, r5, r3, r5}, true, ne, "ne r5 r3 r5", "ne_r5_r3_r5"},
{{ne, r5, r4, r5}, true, ne, "ne r5 r4 r5", "ne_r5_r4_r5"},
{{ne, r5, r5, r5}, true, ne, "ne r5 r5 r5", "ne_r5_r5_r5"},
{{ne, r5, r6, r5}, true, ne, "ne r5 r6 r5", "ne_r5_r6_r5"},
{{ne, r5, r7, r5}, true, ne, "ne r5 r7 r5", "ne_r5_r7_r5"},
{{ne, r6, r0, r6}, true, ne, "ne r6 r0 r6", "ne_r6_r0_r6"},
{{ne, r6, r1, r6}, true, ne, "ne r6 r1 r6", "ne_r6_r1_r6"},
{{ne, r6, r2, r6}, true, ne, "ne r6 r2 r6", "ne_r6_r2_r6"},
{{ne, r6, r3, r6}, true, ne, "ne r6 r3 r6", "ne_r6_r3_r6"},
{{ne, r6, r4, r6}, true, ne, "ne r6 r4 r6", "ne_r6_r4_r6"},
{{ne, r6, r5, r6}, true, ne, "ne r6 r5 r6", "ne_r6_r5_r6"},
{{ne, r6, r6, r6}, true, ne, "ne r6 r6 r6", "ne_r6_r6_r6"},
{{ne, r6, r7, r6}, true, ne, "ne r6 r7 r6", "ne_r6_r7_r6"},
{{ne, r7, r0, r7}, true, ne, "ne r7 r0 r7", "ne_r7_r0_r7"},
{{ne, r7, r1, r7}, true, ne, "ne r7 r1 r7", "ne_r7_r1_r7"},
{{ne, r7, r2, r7}, true, ne, "ne r7 r2 r7", "ne_r7_r2_r7"},
{{ne, r7, r3, r7}, true, ne, "ne r7 r3 r7", "ne_r7_r3_r7"},
{{ne, r7, r4, r7}, true, ne, "ne r7 r4 r7", "ne_r7_r4_r7"},
{{ne, r7, r5, r7}, true, ne, "ne r7 r5 r7", "ne_r7_r5_r7"},
{{ne, r7, r6, r7}, true, ne, "ne r7 r6 r7", "ne_r7_r6_r7"},
{{ne, r7, r7, r7}, true, ne, "ne r7 r7 r7", "ne_r7_r7_r7"},
{{cs, r0, r0, r0}, true, cs, "cs r0 r0 r0", "cs_r0_r0_r0"},
{{cs, r0, r1, r0}, true, cs, "cs r0 r1 r0", "cs_r0_r1_r0"},
{{cs, r0, r2, r0}, true, cs, "cs r0 r2 r0", "cs_r0_r2_r0"},
{{cs, r0, r3, r0}, true, cs, "cs r0 r3 r0", "cs_r0_r3_r0"},
{{cs, r0, r4, r0}, true, cs, "cs r0 r4 r0", "cs_r0_r4_r0"},
{{cs, r0, r5, r0}, true, cs, "cs r0 r5 r0", "cs_r0_r5_r0"},
{{cs, r0, r6, r0}, true, cs, "cs r0 r6 r0", "cs_r0_r6_r0"},
{{cs, r0, r7, r0}, true, cs, "cs r0 r7 r0", "cs_r0_r7_r0"},
{{cs, r1, r0, r1}, true, cs, "cs r1 r0 r1", "cs_r1_r0_r1"},
{{cs, r1, r1, r1}, true, cs, "cs r1 r1 r1", "cs_r1_r1_r1"},
{{cs, r1, r2, r1}, true, cs, "cs r1 r2 r1", "cs_r1_r2_r1"},
{{cs, r1, r3, r1}, true, cs, "cs r1 r3 r1", "cs_r1_r3_r1"},
{{cs, r1, r4, r1}, true, cs, "cs r1 r4 r1", "cs_r1_r4_r1"},
{{cs, r1, r5, r1}, true, cs, "cs r1 r5 r1", "cs_r1_r5_r1"},
{{cs, r1, r6, r1}, true, cs, "cs r1 r6 r1", "cs_r1_r6_r1"},
{{cs, r1, r7, r1}, true, cs, "cs r1 r7 r1", "cs_r1_r7_r1"},
{{cs, r2, r0, r2}, true, cs, "cs r2 r0 r2", "cs_r2_r0_r2"},
{{cs, r2, r1, r2}, true, cs, "cs r2 r1 r2", "cs_r2_r1_r2"},
{{cs, r2, r2, r2}, true, cs, "cs r2 r2 r2", "cs_r2_r2_r2"},
{{cs, r2, r3, r2}, true, cs, "cs r2 r3 r2", "cs_r2_r3_r2"},
{{cs, r2, r4, r2}, true, cs, "cs r2 r4 r2", "cs_r2_r4_r2"},
{{cs, r2, r5, r2}, true, cs, "cs r2 r5 r2", "cs_r2_r5_r2"},
{{cs, r2, r6, r2}, true, cs, "cs r2 r6 r2", "cs_r2_r6_r2"},
{{cs, r2, r7, r2}, true, cs, "cs r2 r7 r2", "cs_r2_r7_r2"},
{{cs, r3, r0, r3}, true, cs, "cs r3 r0 r3", "cs_r3_r0_r3"},
{{cs, r3, r1, r3}, true, cs, "cs r3 r1 r3", "cs_r3_r1_r3"},
{{cs, r3, r2, r3}, true, cs, "cs r3 r2 r3", "cs_r3_r2_r3"},
{{cs, r3, r3, r3}, true, cs, "cs r3 r3 r3", "cs_r3_r3_r3"},
{{cs, r3, r4, r3}, true, cs, "cs r3 r4 r3", "cs_r3_r4_r3"},
{{cs, r3, r5, r3}, true, cs, "cs r3 r5 r3", "cs_r3_r5_r3"},
{{cs, r3, r6, r3}, true, cs, "cs r3 r6 r3", "cs_r3_r6_r3"},
{{cs, r3, r7, r3}, true, cs, "cs r3 r7 r3", "cs_r3_r7_r3"},
{{cs, r4, r0, r4}, true, cs, "cs r4 r0 r4", "cs_r4_r0_r4"},
{{cs, r4, r1, r4}, true, cs, "cs r4 r1 r4", "cs_r4_r1_r4"},
{{cs, r4, r2, r4}, true, cs, "cs r4 r2 r4", "cs_r4_r2_r4"},
{{cs, r4, r3, r4}, true, cs, "cs r4 r3 r4", "cs_r4_r3_r4"},
{{cs, r4, r4, r4}, true, cs, "cs r4 r4 r4", "cs_r4_r4_r4"},
{{cs, r4, r5, r4}, true, cs, "cs r4 r5 r4", "cs_r4_r5_r4"},
{{cs, r4, r6, r4}, true, cs, "cs r4 r6 r4", "cs_r4_r6_r4"},
{{cs, r4, r7, r4}, true, cs, "cs r4 r7 r4", "cs_r4_r7_r4"},
{{cs, r5, r0, r5}, true, cs, "cs r5 r0 r5", "cs_r5_r0_r5"},
{{cs, r5, r1, r5}, true, cs, "cs r5 r1 r5", "cs_r5_r1_r5"},
{{cs, r5, r2, r5}, true, cs, "cs r5 r2 r5", "cs_r5_r2_r5"},
{{cs, r5, r3, r5}, true, cs, "cs r5 r3 r5", "cs_r5_r3_r5"},
{{cs, r5, r4, r5}, true, cs, "cs r5 r4 r5", "cs_r5_r4_r5"},
{{cs, r5, r5, r5}, true, cs, "cs r5 r5 r5", "cs_r5_r5_r5"},
{{cs, r5, r6, r5}, true, cs, "cs r5 r6 r5", "cs_r5_r6_r5"},
{{cs, r5, r7, r5}, true, cs, "cs r5 r7 r5", "cs_r5_r7_r5"},
{{cs, r6, r0, r6}, true, cs, "cs r6 r0 r6", "cs_r6_r0_r6"},
{{cs, r6, r1, r6}, true, cs, "cs r6 r1 r6", "cs_r6_r1_r6"},
{{cs, r6, r2, r6}, true, cs, "cs r6 r2 r6", "cs_r6_r2_r6"},
{{cs, r6, r3, r6}, true, cs, "cs r6 r3 r6", "cs_r6_r3_r6"},
{{cs, r6, r4, r6}, true, cs, "cs r6 r4 r6", "cs_r6_r4_r6"},
{{cs, r6, r5, r6}, true, cs, "cs r6 r5 r6", "cs_r6_r5_r6"},
{{cs, r6, r6, r6}, true, cs, "cs r6 r6 r6", "cs_r6_r6_r6"},
{{cs, r6, r7, r6}, true, cs, "cs r6 r7 r6", "cs_r6_r7_r6"},
{{cs, r7, r0, r7}, true, cs, "cs r7 r0 r7", "cs_r7_r0_r7"},
{{cs, r7, r1, r7}, true, cs, "cs r7 r1 r7", "cs_r7_r1_r7"},
{{cs, r7, r2, r7}, true, cs, "cs r7 r2 r7", "cs_r7_r2_r7"},
{{cs, r7, r3, r7}, true, cs, "cs r7 r3 r7", "cs_r7_r3_r7"},
{{cs, r7, r4, r7}, true, cs, "cs r7 r4 r7", "cs_r7_r4_r7"},
{{cs, r7, r5, r7}, true, cs, "cs r7 r5 r7", "cs_r7_r5_r7"},
{{cs, r7, r6, r7}, true, cs, "cs r7 r6 r7", "cs_r7_r6_r7"},
{{cs, r7, r7, r7}, true, cs, "cs r7 r7 r7", "cs_r7_r7_r7"},
{{cc, r0, r0, r0}, true, cc, "cc r0 r0 r0", "cc_r0_r0_r0"},
{{cc, r0, r1, r0}, true, cc, "cc r0 r1 r0", "cc_r0_r1_r0"},
{{cc, r0, r2, r0}, true, cc, "cc r0 r2 r0", "cc_r0_r2_r0"},
{{cc, r0, r3, r0}, true, cc, "cc r0 r3 r0", "cc_r0_r3_r0"},
{{cc, r0, r4, r0}, true, cc, "cc r0 r4 r0", "cc_r0_r4_r0"},
{{cc, r0, r5, r0}, true, cc, "cc r0 r5 r0", "cc_r0_r5_r0"},
{{cc, r0, r6, r0}, true, cc, "cc r0 r6 r0", "cc_r0_r6_r0"},
{{cc, r0, r7, r0}, true, cc, "cc r0 r7 r0", "cc_r0_r7_r0"},
{{cc, r1, r0, r1}, true, cc, "cc r1 r0 r1", "cc_r1_r0_r1"},
{{cc, r1, r1, r1}, true, cc, "cc r1 r1 r1", "cc_r1_r1_r1"},
{{cc, r1, r2, r1}, true, cc, "cc r1 r2 r1", "cc_r1_r2_r1"},
{{cc, r1, r3, r1}, true, cc, "cc r1 r3 r1", "cc_r1_r3_r1"},
{{cc, r1, r4, r1}, true, cc, "cc r1 r4 r1", "cc_r1_r4_r1"},
{{cc, r1, r5, r1}, true, cc, "cc r1 r5 r1", "cc_r1_r5_r1"},
{{cc, r1, r6, r1}, true, cc, "cc r1 r6 r1", "cc_r1_r6_r1"},
{{cc, r1, r7, r1}, true, cc, "cc r1 r7 r1", "cc_r1_r7_r1"},
{{cc, r2, r0, r2}, true, cc, "cc r2 r0 r2", "cc_r2_r0_r2"},
{{cc, r2, r1, r2}, true, cc, "cc r2 r1 r2", "cc_r2_r1_r2"},
{{cc, r2, r2, r2}, true, cc, "cc r2 r2 r2", "cc_r2_r2_r2"},
{{cc, r2, r3, r2}, true, cc, "cc r2 r3 r2", "cc_r2_r3_r2"},
{{cc, r2, r4, r2}, true, cc, "cc r2 r4 r2", "cc_r2_r4_r2"},
{{cc, r2, r5, r2}, true, cc, "cc r2 r5 r2", "cc_r2_r5_r2"},
{{cc, r2, r6, r2}, true, cc, "cc r2 r6 r2", "cc_r2_r6_r2"},
{{cc, r2, r7, r2}, true, cc, "cc r2 r7 r2", "cc_r2_r7_r2"},
{{cc, r3, r0, r3}, true, cc, "cc r3 r0 r3", "cc_r3_r0_r3"},
{{cc, r3, r1, r3}, true, cc, "cc r3 r1 r3", "cc_r3_r1_r3"},
{{cc, r3, r2, r3}, true, cc, "cc r3 r2 r3", "cc_r3_r2_r3"},
{{cc, r3, r3, r3}, true, cc, "cc r3 r3 r3", "cc_r3_r3_r3"},
{{cc, r3, r4, r3}, true, cc, "cc r3 r4 r3", "cc_r3_r4_r3"},
{{cc, r3, r5, r3}, true, cc, "cc r3 r5 r3", "cc_r3_r5_r3"},
{{cc, r3, r6, r3}, true, cc, "cc r3 r6 r3", "cc_r3_r6_r3"},
{{cc, r3, r7, r3}, true, cc, "cc r3 r7 r3", "cc_r3_r7_r3"},
{{cc, r4, r0, r4}, true, cc, "cc r4 r0 r4", "cc_r4_r0_r4"},
{{cc, r4, r1, r4}, true, cc, "cc r4 r1 r4", "cc_r4_r1_r4"},
{{cc, r4, r2, r4}, true, cc, "cc r4 r2 r4", "cc_r4_r2_r4"},
{{cc, r4, r3, r4}, true, cc, "cc r4 r3 r4", "cc_r4_r3_r4"},
{{cc, r4, r4, r4}, true, cc, "cc r4 r4 r4", "cc_r4_r4_r4"},
{{cc, r4, r5, r4}, true, cc, "cc r4 r5 r4", "cc_r4_r5_r4"},
{{cc, r4, r6, r4}, true, cc, "cc r4 r6 r4", "cc_r4_r6_r4"},
{{cc, r4, r7, r4}, true, cc, "cc r4 r7 r4", "cc_r4_r7_r4"},
{{cc, r5, r0, r5}, true, cc, "cc r5 r0 r5", "cc_r5_r0_r5"},
{{cc, r5, r1, r5}, true, cc, "cc r5 r1 r5", "cc_r5_r1_r5"},
{{cc, r5, r2, r5}, true, cc, "cc r5 r2 r5", "cc_r5_r2_r5"},
{{cc, r5, r3, r5}, true, cc, "cc r5 r3 r5", "cc_r5_r3_r5"},
{{cc, r5, r4, r5}, true, cc, "cc r5 r4 r5", "cc_r5_r4_r5"},
{{cc, r5, r5, r5}, true, cc, "cc r5 r5 r5", "cc_r5_r5_r5"},
{{cc, r5, r6, r5}, true, cc, "cc r5 r6 r5", "cc_r5_r6_r5"},
{{cc, r5, r7, r5}, true, cc, "cc r5 r7 r5", "cc_r5_r7_r5"},
{{cc, r6, r0, r6}, true, cc, "cc r6 r0 r6", "cc_r6_r0_r6"},
{{cc, r6, r1, r6}, true, cc, "cc r6 r1 r6", "cc_r6_r1_r6"},
{{cc, r6, r2, r6}, true, cc, "cc r6 r2 r6", "cc_r6_r2_r6"},
{{cc, r6, r3, r6}, true, cc, "cc r6 r3 r6", "cc_r6_r3_r6"},
{{cc, r6, r4, r6}, true, cc, "cc r6 r4 r6", "cc_r6_r4_r6"},
{{cc, r6, r5, r6}, true, cc, "cc r6 r5 r6", "cc_r6_r5_r6"},
{{cc, r6, r6, r6}, true, cc, "cc r6 r6 r6", "cc_r6_r6_r6"},
{{cc, r6, r7, r6}, true, cc, "cc r6 r7 r6", "cc_r6_r7_r6"},
{{cc, r7, r0, r7}, true, cc, "cc r7 r0 r7", "cc_r7_r0_r7"},
{{cc, r7, r1, r7}, true, cc, "cc r7 r1 r7", "cc_r7_r1_r7"},
{{cc, r7, r2, r7}, true, cc, "cc r7 r2 r7", "cc_r7_r2_r7"},
{{cc, r7, r3, r7}, true, cc, "cc r7 r3 r7", "cc_r7_r3_r7"},
{{cc, r7, r4, r7}, true, cc, "cc r7 r4 r7", "cc_r7_r4_r7"},
{{cc, r7, r5, r7}, true, cc, "cc r7 r5 r7", "cc_r7_r5_r7"},
{{cc, r7, r6, r7}, true, cc, "cc r7 r6 r7", "cc_r7_r6_r7"},
{{cc, r7, r7, r7}, true, cc, "cc r7 r7 r7", "cc_r7_r7_r7"},
{{mi, r0, r0, r0}, true, mi, "mi r0 r0 r0", "mi_r0_r0_r0"},
{{mi, r0, r1, r0}, true, mi, "mi r0 r1 r0", "mi_r0_r1_r0"},
{{mi, r0, r2, r0}, true, mi, "mi r0 r2 r0", "mi_r0_r2_r0"},
{{mi, r0, r3, r0}, true, mi, "mi r0 r3 r0", "mi_r0_r3_r0"},
{{mi, r0, r4, r0}, true, mi, "mi r0 r4 r0", "mi_r0_r4_r0"},
{{mi, r0, r5, r0}, true, mi, "mi r0 r5 r0", "mi_r0_r5_r0"},
{{mi, r0, r6, r0}, true, mi, "mi r0 r6 r0", "mi_r0_r6_r0"},
{{mi, r0, r7, r0}, true, mi, "mi r0 r7 r0", "mi_r0_r7_r0"},
{{mi, r1, r0, r1}, true, mi, "mi r1 r0 r1", "mi_r1_r0_r1"},
{{mi, r1, r1, r1}, true, mi, "mi r1 r1 r1", "mi_r1_r1_r1"},
{{mi, r1, r2, r1}, true, mi, "mi r1 r2 r1", "mi_r1_r2_r1"},
{{mi, r1, r3, r1}, true, mi, "mi r1 r3 r1", "mi_r1_r3_r1"},
{{mi, r1, r4, r1}, true, mi, "mi r1 r4 r1", "mi_r1_r4_r1"},
{{mi, r1, r5, r1}, true, mi, "mi r1 r5 r1", "mi_r1_r5_r1"},
{{mi, r1, r6, r1}, true, mi, "mi r1 r6 r1", "mi_r1_r6_r1"},
{{mi, r1, r7, r1}, true, mi, "mi r1 r7 r1", "mi_r1_r7_r1"},
{{mi, r2, r0, r2}, true, mi, "mi r2 r0 r2", "mi_r2_r0_r2"},
{{mi, r2, r1, r2}, true, mi, "mi r2 r1 r2", "mi_r2_r1_r2"},
{{mi, r2, r2, r2}, true, mi, "mi r2 r2 r2", "mi_r2_r2_r2"},
{{mi, r2, r3, r2}, true, mi, "mi r2 r3 r2", "mi_r2_r3_r2"},
{{mi, r2, r4, r2}, true, mi, "mi r2 r4 r2", "mi_r2_r4_r2"},
{{mi, r2, r5, r2}, true, mi, "mi r2 r5 r2", "mi_r2_r5_r2"},
{{mi, r2, r6, r2}, true, mi, "mi r2 r6 r2", "mi_r2_r6_r2"},
{{mi, r2, r7, r2}, true, mi, "mi r2 r7 r2", "mi_r2_r7_r2"},
{{mi, r3, r0, r3}, true, mi, "mi r3 r0 r3", "mi_r3_r0_r3"},
{{mi, r3, r1, r3}, true, mi, "mi r3 r1 r3", "mi_r3_r1_r3"},
{{mi, r3, r2, r3}, true, mi, "mi r3 r2 r3", "mi_r3_r2_r3"},
{{mi, r3, r3, r3}, true, mi, "mi r3 r3 r3", "mi_r3_r3_r3"},
{{mi, r3, r4, r3}, true, mi, "mi r3 r4 r3", "mi_r3_r4_r3"},
{{mi, r3, r5, r3}, true, mi, "mi r3 r5 r3", "mi_r3_r5_r3"},
{{mi, r3, r6, r3}, true, mi, "mi r3 r6 r3", "mi_r3_r6_r3"},
{{mi, r3, r7, r3}, true, mi, "mi r3 r7 r3", "mi_r3_r7_r3"},
{{mi, r4, r0, r4}, true, mi, "mi r4 r0 r4", "mi_r4_r0_r4"},
{{mi, r4, r1, r4}, true, mi, "mi r4 r1 r4", "mi_r4_r1_r4"},
{{mi, r4, r2, r4}, true, mi, "mi r4 r2 r4", "mi_r4_r2_r4"},
{{mi, r4, r3, r4}, true, mi, "mi r4 r3 r4", "mi_r4_r3_r4"},
{{mi, r4, r4, r4}, true, mi, "mi r4 r4 r4", "mi_r4_r4_r4"},
{{mi, r4, r5, r4}, true, mi, "mi r4 r5 r4", "mi_r4_r5_r4"},
{{mi, r4, r6, r4}, true, mi, "mi r4 r6 r4", "mi_r4_r6_r4"},
{{mi, r4, r7, r4}, true, mi, "mi r4 r7 r4", "mi_r4_r7_r4"},
{{mi, r5, r0, r5}, true, mi, "mi r5 r0 r5", "mi_r5_r0_r5"},
{{mi, r5, r1, r5}, true, mi, "mi r5 r1 r5", "mi_r5_r1_r5"},
{{mi, r5, r2, r5}, true, mi, "mi r5 r2 r5", "mi_r5_r2_r5"},
{{mi, r5, r3, r5}, true, mi, "mi r5 r3 r5", "mi_r5_r3_r5"},
{{mi, r5, r4, r5}, true, mi, "mi r5 r4 r5", "mi_r5_r4_r5"},
{{mi, r5, r5, r5}, true, mi, "mi r5 r5 r5", "mi_r5_r5_r5"},
{{mi, r5, r6, r5}, true, mi, "mi r5 r6 r5", "mi_r5_r6_r5"},
{{mi, r5, r7, r5}, true, mi, "mi r5 r7 r5", "mi_r5_r7_r5"},
{{mi, r6, r0, r6}, true, mi, "mi r6 r0 r6", "mi_r6_r0_r6"},
{{mi, r6, r1, r6}, true, mi, "mi r6 r1 r6", "mi_r6_r1_r6"},
{{mi, r6, r2, r6}, true, mi, "mi r6 r2 r6", "mi_r6_r2_r6"},
{{mi, r6, r3, r6}, true, mi, "mi r6 r3 r6", "mi_r6_r3_r6"},
{{mi, r6, r4, r6}, true, mi, "mi r6 r4 r6", "mi_r6_r4_r6"},
{{mi, r6, r5, r6}, true, mi, "mi r6 r5 r6", "mi_r6_r5_r6"},
{{mi, r6, r6, r6}, true, mi, "mi r6 r6 r6", "mi_r6_r6_r6"},
{{mi, r6, r7, r6}, true, mi, "mi r6 r7 r6", "mi_r6_r7_r6"},
{{mi, r7, r0, r7}, true, mi, "mi r7 r0 r7", "mi_r7_r0_r7"},
{{mi, r7, r1, r7}, true, mi, "mi r7 r1 r7", "mi_r7_r1_r7"},
{{mi, r7, r2, r7}, true, mi, "mi r7 r2 r7", "mi_r7_r2_r7"},
{{mi, r7, r3, r7}, true, mi, "mi r7 r3 r7", "mi_r7_r3_r7"},
{{mi, r7, r4, r7}, true, mi, "mi r7 r4 r7", "mi_r7_r4_r7"},
{{mi, r7, r5, r7}, true, mi, "mi r7 r5 r7", "mi_r7_r5_r7"},
{{mi, r7, r6, r7}, true, mi, "mi r7 r6 r7", "mi_r7_r6_r7"},
{{mi, r7, r7, r7}, true, mi, "mi r7 r7 r7", "mi_r7_r7_r7"},
{{pl, r0, r0, r0}, true, pl, "pl r0 r0 r0", "pl_r0_r0_r0"},
{{pl, r0, r1, r0}, true, pl, "pl r0 r1 r0", "pl_r0_r1_r0"},
{{pl, r0, r2, r0}, true, pl, "pl r0 r2 r0", "pl_r0_r2_r0"},
{{pl, r0, r3, r0}, true, pl, "pl r0 r3 r0", "pl_r0_r3_r0"},
{{pl, r0, r4, r0}, true, pl, "pl r0 r4 r0", "pl_r0_r4_r0"},
{{pl, r0, r5, r0}, true, pl, "pl r0 r5 r0", "pl_r0_r5_r0"},
{{pl, r0, r6, r0}, true, pl, "pl r0 r6 r0", "pl_r0_r6_r0"},
{{pl, r0, r7, r0}, true, pl, "pl r0 r7 r0", "pl_r0_r7_r0"},
{{pl, r1, r0, r1}, true, pl, "pl r1 r0 r1", "pl_r1_r0_r1"},
{{pl, r1, r1, r1}, true, pl, "pl r1 r1 r1", "pl_r1_r1_r1"},
{{pl, r1, r2, r1}, true, pl, "pl r1 r2 r1", "pl_r1_r2_r1"},
{{pl, r1, r3, r1}, true, pl, "pl r1 r3 r1", "pl_r1_r3_r1"},
{{pl, r1, r4, r1}, true, pl, "pl r1 r4 r1", "pl_r1_r4_r1"},
{{pl, r1, r5, r1}, true, pl, "pl r1 r5 r1", "pl_r1_r5_r1"},
{{pl, r1, r6, r1}, true, pl, "pl r1 r6 r1", "pl_r1_r6_r1"},
{{pl, r1, r7, r1}, true, pl, "pl r1 r7 r1", "pl_r1_r7_r1"},
{{pl, r2, r0, r2}, true, pl, "pl r2 r0 r2", "pl_r2_r0_r2"},
{{pl, r2, r1, r2}, true, pl, "pl r2 r1 r2", "pl_r2_r1_r2"},
{{pl, r2, r2, r2}, true, pl, "pl r2 r2 r2", "pl_r2_r2_r2"},
{{pl, r2, r3, r2}, true, pl, "pl r2 r3 r2", "pl_r2_r3_r2"},
{{pl, r2, r4, r2}, true, pl, "pl r2 r4 r2", "pl_r2_r4_r2"},
{{pl, r2, r5, r2}, true, pl, "pl r2 r5 r2", "pl_r2_r5_r2"},
{{pl, r2, r6, r2}, true, pl, "pl r2 r6 r2", "pl_r2_r6_r2"},
{{pl, r2, r7, r2}, true, pl, "pl r2 r7 r2", "pl_r2_r7_r2"},
{{pl, r3, r0, r3}, true, pl, "pl r3 r0 r3", "pl_r3_r0_r3"},
{{pl, r3, r1, r3}, true, pl, "pl r3 r1 r3", "pl_r3_r1_r3"},
{{pl, r3, r2, r3}, true, pl, "pl r3 r2 r3", "pl_r3_r2_r3"},
{{pl, r3, r3, r3}, true, pl, "pl r3 r3 r3", "pl_r3_r3_r3"},
{{pl, r3, r4, r3}, true, pl, "pl r3 r4 r3", "pl_r3_r4_r3"},
{{pl, r3, r5, r3}, true, pl, "pl r3 r5 r3", "pl_r3_r5_r3"},
{{pl, r3, r6, r3}, true, pl, "pl r3 r6 r3", "pl_r3_r6_r3"},
{{pl, r3, r7, r3}, true, pl, "pl r3 r7 r3", "pl_r3_r7_r3"},
{{pl, r4, r0, r4}, true, pl, "pl r4 r0 r4", "pl_r4_r0_r4"},
{{pl, r4, r1, r4}, true, pl, "pl r4 r1 r4", "pl_r4_r1_r4"},
{{pl, r4, r2, r4}, true, pl, "pl r4 r2 r4", "pl_r4_r2_r4"},
{{pl, r4, r3, r4}, true, pl, "pl r4 r3 r4", "pl_r4_r3_r4"},
{{pl, r4, r4, r4}, true, pl, "pl r4 r4 r4", "pl_r4_r4_r4"},
{{pl, r4, r5, r4}, true, pl, "pl r4 r5 r4", "pl_r4_r5_r4"},
{{pl, r4, r6, r4}, true, pl, "pl r4 r6 r4", "pl_r4_r6_r4"},
{{pl, r4, r7, r4}, true, pl, "pl r4 r7 r4", "pl_r4_r7_r4"},
{{pl, r5, r0, r5}, true, pl, "pl r5 r0 r5", "pl_r5_r0_r5"},
{{pl, r5, r1, r5}, true, pl, "pl r5 r1 r5", "pl_r5_r1_r5"},
{{pl, r5, r2, r5}, true, pl, "pl r5 r2 r5", "pl_r5_r2_r5"},
{{pl, r5, r3, r5}, true, pl, "pl r5 r3 r5", "pl_r5_r3_r5"},
{{pl, r5, r4, r5}, true, pl, "pl r5 r4 r5", "pl_r5_r4_r5"},
{{pl, r5, r5, r5}, true, pl, "pl r5 r5 r5", "pl_r5_r5_r5"},
{{pl, r5, r6, r5}, true, pl, "pl r5 r6 r5", "pl_r5_r6_r5"},
{{pl, r5, r7, r5}, true, pl, "pl r5 r7 r5", "pl_r5_r7_r5"},
{{pl, r6, r0, r6}, true, pl, "pl r6 r0 r6", "pl_r6_r0_r6"},
{{pl, r6, r1, r6}, true, pl, "pl r6 r1 r6", "pl_r6_r1_r6"},
{{pl, r6, r2, r6}, true, pl, "pl r6 r2 r6", "pl_r6_r2_r6"},
{{pl, r6, r3, r6}, true, pl, "pl r6 r3 r6", "pl_r6_r3_r6"},
{{pl, r6, r4, r6}, true, pl, "pl r6 r4 r6", "pl_r6_r4_r6"},
{{pl, r6, r5, r6}, true, pl, "pl r6 r5 r6", "pl_r6_r5_r6"},
{{pl, r6, r6, r6}, true, pl, "pl r6 r6 r6", "pl_r6_r6_r6"},
{{pl, r6, r7, r6}, true, pl, "pl r6 r7 r6", "pl_r6_r7_r6"},
{{pl, r7, r0, r7}, true, pl, "pl r7 r0 r7", "pl_r7_r0_r7"},
{{pl, r7, r1, r7}, true, pl, "pl r7 r1 r7", "pl_r7_r1_r7"},
{{pl, r7, r2, r7}, true, pl, "pl r7 r2 r7", "pl_r7_r2_r7"},
{{pl, r7, r3, r7}, true, pl, "pl r7 r3 r7", "pl_r7_r3_r7"},
{{pl, r7, r4, r7}, true, pl, "pl r7 r4 r7", "pl_r7_r4_r7"},
{{pl, r7, r5, r7}, true, pl, "pl r7 r5 r7", "pl_r7_r5_r7"},
{{pl, r7, r6, r7}, true, pl, "pl r7 r6 r7", "pl_r7_r6_r7"},
{{pl, r7, r7, r7}, true, pl, "pl r7 r7 r7", "pl_r7_r7_r7"},
{{vs, r0, r0, r0}, true, vs, "vs r0 r0 r0", "vs_r0_r0_r0"},
{{vs, r0, r1, r0}, true, vs, "vs r0 r1 r0", "vs_r0_r1_r0"},
{{vs, r0, r2, r0}, true, vs, "vs r0 r2 r0", "vs_r0_r2_r0"},
{{vs, r0, r3, r0}, true, vs, "vs r0 r3 r0", "vs_r0_r3_r0"},
{{vs, r0, r4, r0}, true, vs, "vs r0 r4 r0", "vs_r0_r4_r0"},
{{vs, r0, r5, r0}, true, vs, "vs r0 r5 r0", "vs_r0_r5_r0"},
{{vs, r0, r6, r0}, true, vs, "vs r0 r6 r0", "vs_r0_r6_r0"},
{{vs, r0, r7, r0}, true, vs, "vs r0 r7 r0", "vs_r0_r7_r0"},
{{vs, r1, r0, r1}, true, vs, "vs r1 r0 r1", "vs_r1_r0_r1"},
{{vs, r1, r1, r1}, true, vs, "vs r1 r1 r1", "vs_r1_r1_r1"},
{{vs, r1, r2, r1}, true, vs, "vs r1 r2 r1", "vs_r1_r2_r1"},
{{vs, r1, r3, r1}, true, vs, "vs r1 r3 r1", "vs_r1_r3_r1"},
{{vs, r1, r4, r1}, true, vs, "vs r1 r4 r1", "vs_r1_r4_r1"},
{{vs, r1, r5, r1}, true, vs, "vs r1 r5 r1", "vs_r1_r5_r1"},
{{vs, r1, r6, r1}, true, vs, "vs r1 r6 r1", "vs_r1_r6_r1"},
{{vs, r1, r7, r1}, true, vs, "vs r1 r7 r1", "vs_r1_r7_r1"},
{{vs, r2, r0, r2}, true, vs, "vs r2 r0 r2", "vs_r2_r0_r2"},
{{vs, r2, r1, r2}, true, vs, "vs r2 r1 r2", "vs_r2_r1_r2"},
{{vs, r2, r2, r2}, true, vs, "vs r2 r2 r2", "vs_r2_r2_r2"},
{{vs, r2, r3, r2}, true, vs, "vs r2 r3 r2", "vs_r2_r3_r2"},
{{vs, r2, r4, r2}, true, vs, "vs r2 r4 r2", "vs_r2_r4_r2"},
{{vs, r2, r5, r2}, true, vs, "vs r2 r5 r2", "vs_r2_r5_r2"},
{{vs, r2, r6, r2}, true, vs, "vs r2 r6 r2", "vs_r2_r6_r2"},
{{vs, r2, r7, r2}, true, vs, "vs r2 r7 r2", "vs_r2_r7_r2"},
{{vs, r3, r0, r3}, true, vs, "vs r3 r0 r3", "vs_r3_r0_r3"},
{{vs, r3, r1, r3}, true, vs, "vs r3 r1 r3", "vs_r3_r1_r3"},
{{vs, r3, r2, r3}, true, vs, "vs r3 r2 r3", "vs_r3_r2_r3"},
{{vs, r3, r3, r3}, true, vs, "vs r3 r3 r3", "vs_r3_r3_r3"},
{{vs, r3, r4, r3}, true, vs, "vs r3 r4 r3", "vs_r3_r4_r3"},
{{vs, r3, r5, r3}, true, vs, "vs r3 r5 r3", "vs_r3_r5_r3"},
{{vs, r3, r6, r3}, true, vs, "vs r3 r6 r3", "vs_r3_r6_r3"},
{{vs, r3, r7, r3}, true, vs, "vs r3 r7 r3", "vs_r3_r7_r3"},
{{vs, r4, r0, r4}, true, vs, "vs r4 r0 r4", "vs_r4_r0_r4"},
{{vs, r4, r1, r4}, true, vs, "vs r4 r1 r4", "vs_r4_r1_r4"},
{{vs, r4, r2, r4}, true, vs, "vs r4 r2 r4", "vs_r4_r2_r4"},
{{vs, r4, r3, r4}, true, vs, "vs r4 r3 r4", "vs_r4_r3_r4"},
{{vs, r4, r4, r4}, true, vs, "vs r4 r4 r4", "vs_r4_r4_r4"},
{{vs, r4, r5, r4}, true, vs, "vs r4 r5 r4", "vs_r4_r5_r4"},
{{vs, r4, r6, r4}, true, vs, "vs r4 r6 r4", "vs_r4_r6_r4"},
{{vs, r4, r7, r4}, true, vs, "vs r4 r7 r4", "vs_r4_r7_r4"},
{{vs, r5, r0, r5}, true, vs, "vs r5 r0 r5", "vs_r5_r0_r5"},
{{vs, r5, r1, r5}, true, vs, "vs r5 r1 r5", "vs_r5_r1_r5"},
{{vs, r5, r2, r5}, true, vs, "vs r5 r2 r5", "vs_r5_r2_r5"},
{{vs, r5, r3, r5}, true, vs, "vs r5 r3 r5", "vs_r5_r3_r5"},
{{vs, r5, r4, r5}, true, vs, "vs r5 r4 r5", "vs_r5_r4_r5"},
{{vs, r5, r5, r5}, true, vs, "vs r5 r5 r5", "vs_r5_r5_r5"},
{{vs, r5, r6, r5}, true, vs, "vs r5 r6 r5", "vs_r5_r6_r5"},
{{vs, r5, r7, r5}, true, vs, "vs r5 r7 r5", "vs_r5_r7_r5"},
{{vs, r6, r0, r6}, true, vs, "vs r6 r0 r6", "vs_r6_r0_r6"},
{{vs, r6, r1, r6}, true, vs, "vs r6 r1 r6", "vs_r6_r1_r6"},
{{vs, r6, r2, r6}, true, vs, "vs r6 r2 r6", "vs_r6_r2_r6"},
{{vs, r6, r3, r6}, true, vs, "vs r6 r3 r6", "vs_r6_r3_r6"},
{{vs, r6, r4, r6}, true, vs, "vs r6 r4 r6", "vs_r6_r4_r6"},
{{vs, r6, r5, r6}, true, vs, "vs r6 r5 r6", "vs_r6_r5_r6"},
{{vs, r6, r6, r6}, true, vs, "vs r6 r6 r6", "vs_r6_r6_r6"},
{{vs, r6, r7, r6}, true, vs, "vs r6 r7 r6", "vs_r6_r7_r6"},
{{vs, r7, r0, r7}, true, vs, "vs r7 r0 r7", "vs_r7_r0_r7"},
{{vs, r7, r1, r7}, true, vs, "vs r7 r1 r7", "vs_r7_r1_r7"},
{{vs, r7, r2, r7}, true, vs, "vs r7 r2 r7", "vs_r7_r2_r7"},
{{vs, r7, r3, r7}, true, vs, "vs r7 r3 r7", "vs_r7_r3_r7"},
{{vs, r7, r4, r7}, true, vs, "vs r7 r4 r7", "vs_r7_r4_r7"},
{{vs, r7, r5, r7}, true, vs, "vs r7 r5 r7", "vs_r7_r5_r7"},
{{vs, r7, r6, r7}, true, vs, "vs r7 r6 r7", "vs_r7_r6_r7"},
{{vs, r7, r7, r7}, true, vs, "vs r7 r7 r7", "vs_r7_r7_r7"},
{{vc, r0, r0, r0}, true, vc, "vc r0 r0 r0", "vc_r0_r0_r0"},
{{vc, r0, r1, r0}, true, vc, "vc r0 r1 r0", "vc_r0_r1_r0"},
{{vc, r0, r2, r0}, true, vc, "vc r0 r2 r0", "vc_r0_r2_r0"},
{{vc, r0, r3, r0}, true, vc, "vc r0 r3 r0", "vc_r0_r3_r0"},
{{vc, r0, r4, r0}, true, vc, "vc r0 r4 r0", "vc_r0_r4_r0"},
{{vc, r0, r5, r0}, true, vc, "vc r0 r5 r0", "vc_r0_r5_r0"},
{{vc, r0, r6, r0}, true, vc, "vc r0 r6 r0", "vc_r0_r6_r0"},
{{vc, r0, r7, r0}, true, vc, "vc r0 r7 r0", "vc_r0_r7_r0"},
{{vc, r1, r0, r1}, true, vc, "vc r1 r0 r1", "vc_r1_r0_r1"},
{{vc, r1, r1, r1}, true, vc, "vc r1 r1 r1", "vc_r1_r1_r1"},
{{vc, r1, r2, r1}, true, vc, "vc r1 r2 r1", "vc_r1_r2_r1"},
{{vc, r1, r3, r1}, true, vc, "vc r1 r3 r1", "vc_r1_r3_r1"},
{{vc, r1, r4, r1}, true, vc, "vc r1 r4 r1", "vc_r1_r4_r1"},
{{vc, r1, r5, r1}, true, vc, "vc r1 r5 r1", "vc_r1_r5_r1"},
{{vc, r1, r6, r1}, true, vc, "vc r1 r6 r1", "vc_r1_r6_r1"},
{{vc, r1, r7, r1}, true, vc, "vc r1 r7 r1", "vc_r1_r7_r1"},
{{vc, r2, r0, r2}, true, vc, "vc r2 r0 r2", "vc_r2_r0_r2"},
{{vc, r2, r1, r2}, true, vc, "vc r2 r1 r2", "vc_r2_r1_r2"},
{{vc, r2, r2, r2}, true, vc, "vc r2 r2 r2", "vc_r2_r2_r2"},
{{vc, r2, r3, r2}, true, vc, "vc r2 r3 r2", "vc_r2_r3_r2"},
{{vc, r2, r4, r2}, true, vc, "vc r2 r4 r2", "vc_r2_r4_r2"},
{{vc, r2, r5, r2}, true, vc, "vc r2 r5 r2", "vc_r2_r5_r2"},
{{vc, r2, r6, r2}, true, vc, "vc r2 r6 r2", "vc_r2_r6_r2"},
{{vc, r2, r7, r2}, true, vc, "vc r2 r7 r2", "vc_r2_r7_r2"},
{{vc, r3, r0, r3}, true, vc, "vc r3 r0 r3", "vc_r3_r0_r3"},
{{vc, r3, r1, r3}, true, vc, "vc r3 r1 r3", "vc_r3_r1_r3"},
{{vc, r3, r2, r3}, true, vc, "vc r3 r2 r3", "vc_r3_r2_r3"},
{{vc, r3, r3, r3}, true, vc, "vc r3 r3 r3", "vc_r3_r3_r3"},
{{vc, r3, r4, r3}, true, vc, "vc r3 r4 r3", "vc_r3_r4_r3"},
{{vc, r3, r5, r3}, true, vc, "vc r3 r5 r3", "vc_r3_r5_r3"},
{{vc, r3, r6, r3}, true, vc, "vc r3 r6 r3", "vc_r3_r6_r3"},
{{vc, r3, r7, r3}, true, vc, "vc r3 r7 r3", "vc_r3_r7_r3"},
{{vc, r4, r0, r4}, true, vc, "vc r4 r0 r4", "vc_r4_r0_r4"},
{{vc, r4, r1, r4}, true, vc, "vc r4 r1 r4", "vc_r4_r1_r4"},
{{vc, r4, r2, r4}, true, vc, "vc r4 r2 r4", "vc_r4_r2_r4"},
{{vc, r4, r3, r4}, true, vc, "vc r4 r3 r4", "vc_r4_r3_r4"},
{{vc, r4, r4, r4}, true, vc, "vc r4 r4 r4", "vc_r4_r4_r4"},
{{vc, r4, r5, r4}, true, vc, "vc r4 r5 r4", "vc_r4_r5_r4"},
{{vc, r4, r6, r4}, true, vc, "vc r4 r6 r4", "vc_r4_r6_r4"},
{{vc, r4, r7, r4}, true, vc, "vc r4 r7 r4", "vc_r4_r7_r4"},
{{vc, r5, r0, r5}, true, vc, "vc r5 r0 r5", "vc_r5_r0_r5"},
{{vc, r5, r1, r5}, true, vc, "vc r5 r1 r5", "vc_r5_r1_r5"},
{{vc, r5, r2, r5}, true, vc, "vc r5 r2 r5", "vc_r5_r2_r5"},
{{vc, r5, r3, r5}, true, vc, "vc r5 r3 r5", "vc_r5_r3_r5"},
{{vc, r5, r4, r5}, true, vc, "vc r5 r4 r5", "vc_r5_r4_r5"},
{{vc, r5, r5, r5}, true, vc, "vc r5 r5 r5", "vc_r5_r5_r5"},
{{vc, r5, r6, r5}, true, vc, "vc r5 r6 r5", "vc_r5_r6_r5"},
{{vc, r5, r7, r5}, true, vc, "vc r5 r7 r5", "vc_r5_r7_r5"},
{{vc, r6, r0, r6}, true, vc, "vc r6 r0 r6", "vc_r6_r0_r6"},
{{vc, r6, r1, r6}, true, vc, "vc r6 r1 r6", "vc_r6_r1_r6"},
{{vc, r6, r2, r6}, true, vc, "vc r6 r2 r6", "vc_r6_r2_r6"},
{{vc, r6, r3, r6}, true, vc, "vc r6 r3 r6", "vc_r6_r3_r6"},
{{vc, r6, r4, r6}, true, vc, "vc r6 r4 r6", "vc_r6_r4_r6"},
{{vc, r6, r5, r6}, true, vc, "vc r6 r5 r6", "vc_r6_r5_r6"},
{{vc, r6, r6, r6}, true, vc, "vc r6 r6 r6", "vc_r6_r6_r6"},
{{vc, r6, r7, r6}, true, vc, "vc r6 r7 r6", "vc_r6_r7_r6"},
{{vc, r7, r0, r7}, true, vc, "vc r7 r0 r7", "vc_r7_r0_r7"},
{{vc, r7, r1, r7}, true, vc, "vc r7 r1 r7", "vc_r7_r1_r7"},
{{vc, r7, r2, r7}, true, vc, "vc r7 r2 r7", "vc_r7_r2_r7"},
{{vc, r7, r3, r7}, true, vc, "vc r7 r3 r7", "vc_r7_r3_r7"},
{{vc, r7, r4, r7}, true, vc, "vc r7 r4 r7", "vc_r7_r4_r7"},
{{vc, r7, r5, r7}, true, vc, "vc r7 r5 r7", "vc_r7_r5_r7"},
{{vc, r7, r6, r7}, true, vc, "vc r7 r6 r7", "vc_r7_r6_r7"},
{{vc, r7, r7, r7}, true, vc, "vc r7 r7 r7", "vc_r7_r7_r7"},
{{hi, r0, r0, r0}, true, hi, "hi r0 r0 r0", "hi_r0_r0_r0"},
{{hi, r0, r1, r0}, true, hi, "hi r0 r1 r0", "hi_r0_r1_r0"},
{{hi, r0, r2, r0}, true, hi, "hi r0 r2 r0", "hi_r0_r2_r0"},
{{hi, r0, r3, r0}, true, hi, "hi r0 r3 r0", "hi_r0_r3_r0"},
{{hi, r0, r4, r0}, true, hi, "hi r0 r4 r0", "hi_r0_r4_r0"},
{{hi, r0, r5, r0}, true, hi, "hi r0 r5 r0", "hi_r0_r5_r0"},
{{hi, r0, r6, r0}, true, hi, "hi r0 r6 r0", "hi_r0_r6_r0"},
{{hi, r0, r7, r0}, true, hi, "hi r0 r7 r0", "hi_r0_r7_r0"},
{{hi, r1, r0, r1}, true, hi, "hi r1 r0 r1", "hi_r1_r0_r1"},
{{hi, r1, r1, r1}, true, hi, "hi r1 r1 r1", "hi_r1_r1_r1"},
{{hi, r1, r2, r1}, true, hi, "hi r1 r2 r1", "hi_r1_r2_r1"},
{{hi, r1, r3, r1}, true, hi, "hi r1 r3 r1", "hi_r1_r3_r1"},
{{hi, r1, r4, r1}, true, hi, "hi r1 r4 r1", "hi_r1_r4_r1"},
{{hi, r1, r5, r1}, true, hi, "hi r1 r5 r1", "hi_r1_r5_r1"},
{{hi, r1, r6, r1}, true, hi, "hi r1 r6 r1", "hi_r1_r6_r1"},
{{hi, r1, r7, r1}, true, hi, "hi r1 r7 r1", "hi_r1_r7_r1"},
{{hi, r2, r0, r2}, true, hi, "hi r2 r0 r2", "hi_r2_r0_r2"},
{{hi, r2, r1, r2}, true, hi, "hi r2 r1 r2", "hi_r2_r1_r2"},
{{hi, r2, r2, r2}, true, hi, "hi r2 r2 r2", "hi_r2_r2_r2"},
{{hi, r2, r3, r2}, true, hi, "hi r2 r3 r2", "hi_r2_r3_r2"},
{{hi, r2, r4, r2}, true, hi, "hi r2 r4 r2", "hi_r2_r4_r2"},
{{hi, r2, r5, r2}, true, hi, "hi r2 r5 r2", "hi_r2_r5_r2"},
{{hi, r2, r6, r2}, true, hi, "hi r2 r6 r2", "hi_r2_r6_r2"},
{{hi, r2, r7, r2}, true, hi, "hi r2 r7 r2", "hi_r2_r7_r2"},
{{hi, r3, r0, r3}, true, hi, "hi r3 r0 r3", "hi_r3_r0_r3"},
{{hi, r3, r1, r3}, true, hi, "hi r3 r1 r3", "hi_r3_r1_r3"},
{{hi, r3, r2, r3}, true, hi, "hi r3 r2 r3", "hi_r3_r2_r3"},
{{hi, r3, r3, r3}, true, hi, "hi r3 r3 r3", "hi_r3_r3_r3"},
{{hi, r3, r4, r3}, true, hi, "hi r3 r4 r3", "hi_r3_r4_r3"},
{{hi, r3, r5, r3}, true, hi, "hi r3 r5 r3", "hi_r3_r5_r3"},
{{hi, r3, r6, r3}, true, hi, "hi r3 r6 r3", "hi_r3_r6_r3"},
{{hi, r3, r7, r3}, true, hi, "hi r3 r7 r3", "hi_r3_r7_r3"},
{{hi, r4, r0, r4}, true, hi, "hi r4 r0 r4", "hi_r4_r0_r4"},
{{hi, r4, r1, r4}, true, hi, "hi r4 r1 r4", "hi_r4_r1_r4"},
{{hi, r4, r2, r4}, true, hi, "hi r4 r2 r4", "hi_r4_r2_r4"},
{{hi, r4, r3, r4}, true, hi, "hi r4 r3 r4", "hi_r4_r3_r4"},
{{hi, r4, r4, r4}, true, hi, "hi r4 r4 r4", "hi_r4_r4_r4"},
{{hi, r4, r5, r4}, true, hi, "hi r4 r5 r4", "hi_r4_r5_r4"},
{{hi, r4, r6, r4}, true, hi, "hi r4 r6 r4", "hi_r4_r6_r4"},
{{hi, r4, r7, r4}, true, hi, "hi r4 r7 r4", "hi_r4_r7_r4"},
{{hi, r5, r0, r5}, true, hi, "hi r5 r0 r5", "hi_r5_r0_r5"},
{{hi, r5, r1, r5}, true, hi, "hi r5 r1 r5", "hi_r5_r1_r5"},
{{hi, r5, r2, r5}, true, hi, "hi r5 r2 r5", "hi_r5_r2_r5"},
{{hi, r5, r3, r5}, true, hi, "hi r5 r3 r5", "hi_r5_r3_r5"},
{{hi, r5, r4, r5}, true, hi, "hi r5 r4 r5", "hi_r5_r4_r5"},
{{hi, r5, r5, r5}, true, hi, "hi r5 r5 r5", "hi_r5_r5_r5"},
{{hi, r5, r6, r5}, true, hi, "hi r5 r6 r5", "hi_r5_r6_r5"},
{{hi, r5, r7, r5}, true, hi, "hi r5 r7 r5", "hi_r5_r7_r5"},
{{hi, r6, r0, r6}, true, hi, "hi r6 r0 r6", "hi_r6_r0_r6"},
{{hi, r6, r1, r6}, true, hi, "hi r6 r1 r6", "hi_r6_r1_r6"},
{{hi, r6, r2, r6}, true, hi, "hi r6 r2 r6", "hi_r6_r2_r6"},
{{hi, r6, r3, r6}, true, hi, "hi r6 r3 r6", "hi_r6_r3_r6"},
{{hi, r6, r4, r6}, true, hi, "hi r6 r4 r6", "hi_r6_r4_r6"},
{{hi, r6, r5, r6}, true, hi, "hi r6 r5 r6", "hi_r6_r5_r6"},
{{hi, r6, r6, r6}, true, hi, "hi r6 r6 r6", "hi_r6_r6_r6"},
{{hi, r6, r7, r6}, true, hi, "hi r6 r7 r6", "hi_r6_r7_r6"},
{{hi, r7, r0, r7}, true, hi, "hi r7 r0 r7", "hi_r7_r0_r7"},
{{hi, r7, r1, r7}, true, hi, "hi r7 r1 r7", "hi_r7_r1_r7"},
{{hi, r7, r2, r7}, true, hi, "hi r7 r2 r7", "hi_r7_r2_r7"},
{{hi, r7, r3, r7}, true, hi, "hi r7 r3 r7", "hi_r7_r3_r7"},
{{hi, r7, r4, r7}, true, hi, "hi r7 r4 r7", "hi_r7_r4_r7"},
{{hi, r7, r5, r7}, true, hi, "hi r7 r5 r7", "hi_r7_r5_r7"},
{{hi, r7, r6, r7}, true, hi, "hi r7 r6 r7", "hi_r7_r6_r7"},
{{hi, r7, r7, r7}, true, hi, "hi r7 r7 r7", "hi_r7_r7_r7"},
{{ls, r0, r0, r0}, true, ls, "ls r0 r0 r0", "ls_r0_r0_r0"},
{{ls, r0, r1, r0}, true, ls, "ls r0 r1 r0", "ls_r0_r1_r0"},
{{ls, r0, r2, r0}, true, ls, "ls r0 r2 r0", "ls_r0_r2_r0"},
{{ls, r0, r3, r0}, true, ls, "ls r0 r3 r0", "ls_r0_r3_r0"},
{{ls, r0, r4, r0}, true, ls, "ls r0 r4 r0", "ls_r0_r4_r0"},
{{ls, r0, r5, r0}, true, ls, "ls r0 r5 r0", "ls_r0_r5_r0"},
{{ls, r0, r6, r0}, true, ls, "ls r0 r6 r0", "ls_r0_r6_r0"},
{{ls, r0, r7, r0}, true, ls, "ls r0 r7 r0", "ls_r0_r7_r0"},
{{ls, r1, r0, r1}, true, ls, "ls r1 r0 r1", "ls_r1_r0_r1"},
{{ls, r1, r1, r1}, true, ls, "ls r1 r1 r1", "ls_r1_r1_r1"},
{{ls, r1, r2, r1}, true, ls, "ls r1 r2 r1", "ls_r1_r2_r1"},
{{ls, r1, r3, r1}, true, ls, "ls r1 r3 r1", "ls_r1_r3_r1"},
{{ls, r1, r4, r1}, true, ls, "ls r1 r4 r1", "ls_r1_r4_r1"},
{{ls, r1, r5, r1}, true, ls, "ls r1 r5 r1", "ls_r1_r5_r1"},
{{ls, r1, r6, r1}, true, ls, "ls r1 r6 r1", "ls_r1_r6_r1"},
{{ls, r1, r7, r1}, true, ls, "ls r1 r7 r1", "ls_r1_r7_r1"},
{{ls, r2, r0, r2}, true, ls, "ls r2 r0 r2", "ls_r2_r0_r2"},
{{ls, r2, r1, r2}, true, ls, "ls r2 r1 r2", "ls_r2_r1_r2"},
{{ls, r2, r2, r2}, true, ls, "ls r2 r2 r2", "ls_r2_r2_r2"},
{{ls, r2, r3, r2}, true, ls, "ls r2 r3 r2", "ls_r2_r3_r2"},
{{ls, r2, r4, r2}, true, ls, "ls r2 r4 r2", "ls_r2_r4_r2"},
{{ls, r2, r5, r2}, true, ls, "ls r2 r5 r2", "ls_r2_r5_r2"},
{{ls, r2, r6, r2}, true, ls, "ls r2 r6 r2", "ls_r2_r6_r2"},
{{ls, r2, r7, r2}, true, ls, "ls r2 r7 r2", "ls_r2_r7_r2"},
{{ls, r3, r0, r3}, true, ls, "ls r3 r0 r3", "ls_r3_r0_r3"},
{{ls, r3, r1, r3}, true, ls, "ls r3 r1 r3", "ls_r3_r1_r3"},
{{ls, r3, r2, r3}, true, ls, "ls r3 r2 r3", "ls_r3_r2_r3"},
{{ls, r3, r3, r3}, true, ls, "ls r3 r3 r3", "ls_r3_r3_r3"},
{{ls, r3, r4, r3}, true, ls, "ls r3 r4 r3", "ls_r3_r4_r3"},
{{ls, r3, r5, r3}, true, ls, "ls r3 r5 r3", "ls_r3_r5_r3"},
{{ls, r3, r6, r3}, true, ls, "ls r3 r6 r3", "ls_r3_r6_r3"},
{{ls, r3, r7, r3}, true, ls, "ls r3 r7 r3", "ls_r3_r7_r3"},
{{ls, r4, r0, r4}, true, ls, "ls r4 r0 r4", "ls_r4_r0_r4"},
{{ls, r4, r1, r4}, true, ls, "ls r4 r1 r4", "ls_r4_r1_r4"},
{{ls, r4, r2, r4}, true, ls, "ls r4 r2 r4", "ls_r4_r2_r4"},
{{ls, r4, r3, r4}, true, ls, "ls r4 r3 r4", "ls_r4_r3_r4"},
{{ls, r4, r4, r4}, true, ls, "ls r4 r4 r4", "ls_r4_r4_r4"},
{{ls, r4, r5, r4}, true, ls, "ls r4 r5 r4", "ls_r4_r5_r4"},
{{ls, r4, r6, r4}, true, ls, "ls r4 r6 r4", "ls_r4_r6_r4"},
{{ls, r4, r7, r4}, true, ls, "ls r4 r7 r4", "ls_r4_r7_r4"},
{{ls, r5, r0, r5}, true, ls, "ls r5 r0 r5", "ls_r5_r0_r5"},
{{ls, r5, r1, r5}, true, ls, "ls r5 r1 r5", "ls_r5_r1_r5"},
{{ls, r5, r2, r5}, true, ls, "ls r5 r2 r5", "ls_r5_r2_r5"},
{{ls, r5, r3, r5}, true, ls, "ls r5 r3 r5", "ls_r5_r3_r5"},
{{ls, r5, r4, r5}, true, ls, "ls r5 r4 r5", "ls_r5_r4_r5"},
{{ls, r5, r5, r5}, true, ls, "ls r5 r5 r5", "ls_r5_r5_r5"},
{{ls, r5, r6, r5}, true, ls, "ls r5 r6 r5", "ls_r5_r6_r5"},
{{ls, r5, r7, r5}, true, ls, "ls r5 r7 r5", "ls_r5_r7_r5"},
{{ls, r6, r0, r6}, true, ls, "ls r6 r0 r6", "ls_r6_r0_r6"},
{{ls, r6, r1, r6}, true, ls, "ls r6 r1 r6", "ls_r6_r1_r6"},
{{ls, r6, r2, r6}, true, ls, "ls r6 r2 r6", "ls_r6_r2_r6"},
{{ls, r6, r3, r6}, true, ls, "ls r6 r3 r6", "ls_r6_r3_r6"},
{{ls, r6, r4, r6}, true, ls, "ls r6 r4 r6", "ls_r6_r4_r6"},
{{ls, r6, r5, r6}, true, ls, "ls r6 r5 r6", "ls_r6_r5_r6"},
{{ls, r6, r6, r6}, true, ls, "ls r6 r6 r6", "ls_r6_r6_r6"},
{{ls, r6, r7, r6}, true, ls, "ls r6 r7 r6", "ls_r6_r7_r6"},
{{ls, r7, r0, r7}, true, ls, "ls r7 r0 r7", "ls_r7_r0_r7"},
{{ls, r7, r1, r7}, true, ls, "ls r7 r1 r7", "ls_r7_r1_r7"},
{{ls, r7, r2, r7}, true, ls, "ls r7 r2 r7", "ls_r7_r2_r7"},
{{ls, r7, r3, r7}, true, ls, "ls r7 r3 r7", "ls_r7_r3_r7"},
{{ls, r7, r4, r7}, true, ls, "ls r7 r4 r7", "ls_r7_r4_r7"},
{{ls, r7, r5, r7}, true, ls, "ls r7 r5 r7", "ls_r7_r5_r7"},
{{ls, r7, r6, r7}, true, ls, "ls r7 r6 r7", "ls_r7_r6_r7"},
{{ls, r7, r7, r7}, true, ls, "ls r7 r7 r7", "ls_r7_r7_r7"},
{{ge, r0, r0, r0}, true, ge, "ge r0 r0 r0", "ge_r0_r0_r0"},
{{ge, r0, r1, r0}, true, ge, "ge r0 r1 r0", "ge_r0_r1_r0"},
{{ge, r0, r2, r0}, true, ge, "ge r0 r2 r0", "ge_r0_r2_r0"},
{{ge, r0, r3, r0}, true, ge, "ge r0 r3 r0", "ge_r0_r3_r0"},
{{ge, r0, r4, r0}, true, ge, "ge r0 r4 r0", "ge_r0_r4_r0"},
{{ge, r0, r5, r0}, true, ge, "ge r0 r5 r0", "ge_r0_r5_r0"},
{{ge, r0, r6, r0}, true, ge, "ge r0 r6 r0", "ge_r0_r6_r0"},
{{ge, r0, r7, r0}, true, ge, "ge r0 r7 r0", "ge_r0_r7_r0"},
{{ge, r1, r0, r1}, true, ge, "ge r1 r0 r1", "ge_r1_r0_r1"},
{{ge, r1, r1, r1}, true, ge, "ge r1 r1 r1", "ge_r1_r1_r1"},
{{ge, r1, r2, r1}, true, ge, "ge r1 r2 r1", "ge_r1_r2_r1"},
{{ge, r1, r3, r1}, true, ge, "ge r1 r3 r1", "ge_r1_r3_r1"},
{{ge, r1, r4, r1}, true, ge, "ge r1 r4 r1", "ge_r1_r4_r1"},
{{ge, r1, r5, r1}, true, ge, "ge r1 r5 r1", "ge_r1_r5_r1"},
{{ge, r1, r6, r1}, true, ge, "ge r1 r6 r1", "ge_r1_r6_r1"},
{{ge, r1, r7, r1}, true, ge, "ge r1 r7 r1", "ge_r1_r7_r1"},
{{ge, r2, r0, r2}, true, ge, "ge r2 r0 r2", "ge_r2_r0_r2"},
{{ge, r2, r1, r2}, true, ge, "ge r2 r1 r2", "ge_r2_r1_r2"},
{{ge, r2, r2, r2}, true, ge, "ge r2 r2 r2", "ge_r2_r2_r2"},
{{ge, r2, r3, r2}, true, ge, "ge r2 r3 r2", "ge_r2_r3_r2"},
{{ge, r2, r4, r2}, true, ge, "ge r2 r4 r2", "ge_r2_r4_r2"},
{{ge, r2, r5, r2}, true, ge, "ge r2 r5 r2", "ge_r2_r5_r2"},
{{ge, r2, r6, r2}, true, ge, "ge r2 r6 r2", "ge_r2_r6_r2"},
{{ge, r2, r7, r2}, true, ge, "ge r2 r7 r2", "ge_r2_r7_r2"},
{{ge, r3, r0, r3}, true, ge, "ge r3 r0 r3", "ge_r3_r0_r3"},
{{ge, r3, r1, r3}, true, ge, "ge r3 r1 r3", "ge_r3_r1_r3"},
{{ge, r3, r2, r3}, true, ge, "ge r3 r2 r3", "ge_r3_r2_r3"},
{{ge, r3, r3, r3}, true, ge, "ge r3 r3 r3", "ge_r3_r3_r3"},
{{ge, r3, r4, r3}, true, ge, "ge r3 r4 r3", "ge_r3_r4_r3"},
{{ge, r3, r5, r3}, true, ge, "ge r3 r5 r3", "ge_r3_r5_r3"},
{{ge, r3, r6, r3}, true, ge, "ge r3 r6 r3", "ge_r3_r6_r3"},
{{ge, r3, r7, r3}, true, ge, "ge r3 r7 r3", "ge_r3_r7_r3"},
{{ge, r4, r0, r4}, true, ge, "ge r4 r0 r4", "ge_r4_r0_r4"},
{{ge, r4, r1, r4}, true, ge, "ge r4 r1 r4", "ge_r4_r1_r4"},
{{ge, r4, r2, r4}, true, ge, "ge r4 r2 r4", "ge_r4_r2_r4"},
{{ge, r4, r3, r4}, true, ge, "ge r4 r3 r4", "ge_r4_r3_r4"},
{{ge, r4, r4, r4}, true, ge, "ge r4 r4 r4", "ge_r4_r4_r4"},
{{ge, r4, r5, r4}, true, ge, "ge r4 r5 r4", "ge_r4_r5_r4"},
{{ge, r4, r6, r4}, true, ge, "ge r4 r6 r4", "ge_r4_r6_r4"},
{{ge, r4, r7, r4}, true, ge, "ge r4 r7 r4", "ge_r4_r7_r4"},
{{ge, r5, r0, r5}, true, ge, "ge r5 r0 r5", "ge_r5_r0_r5"},
{{ge, r5, r1, r5}, true, ge, "ge r5 r1 r5", "ge_r5_r1_r5"},
{{ge, r5, r2, r5}, true, ge, "ge r5 r2 r5", "ge_r5_r2_r5"},
{{ge, r5, r3, r5}, true, ge, "ge r5 r3 r5", "ge_r5_r3_r5"},
{{ge, r5, r4, r5}, true, ge, "ge r5 r4 r5", "ge_r5_r4_r5"},
{{ge, r5, r5, r5}, true, ge, "ge r5 r5 r5", "ge_r5_r5_r5"},
{{ge, r5, r6, r5}, true, ge, "ge r5 r6 r5", "ge_r5_r6_r5"},
{{ge, r5, r7, r5}, true, ge, "ge r5 r7 r5", "ge_r5_r7_r5"},
{{ge, r6, r0, r6}, true, ge, "ge r6 r0 r6", "ge_r6_r0_r6"},
{{ge, r6, r1, r6}, true, ge, "ge r6 r1 r6", "ge_r6_r1_r6"},
{{ge, r6, r2, r6}, true, ge, "ge r6 r2 r6", "ge_r6_r2_r6"},
{{ge, r6, r3, r6}, true, ge, "ge r6 r3 r6", "ge_r6_r3_r6"},
{{ge, r6, r4, r6}, true, ge, "ge r6 r4 r6", "ge_r6_r4_r6"},
{{ge, r6, r5, r6}, true, ge, "ge r6 r5 r6", "ge_r6_r5_r6"},
{{ge, r6, r6, r6}, true, ge, "ge r6 r6 r6", "ge_r6_r6_r6"},
{{ge, r6, r7, r6}, true, ge, "ge r6 r7 r6", "ge_r6_r7_r6"},
{{ge, r7, r0, r7}, true, ge, "ge r7 r0 r7", "ge_r7_r0_r7"},
{{ge, r7, r1, r7}, true, ge, "ge r7 r1 r7", "ge_r7_r1_r7"},
{{ge, r7, r2, r7}, true, ge, "ge r7 r2 r7", "ge_r7_r2_r7"},
{{ge, r7, r3, r7}, true, ge, "ge r7 r3 r7", "ge_r7_r3_r7"},
{{ge, r7, r4, r7}, true, ge, "ge r7 r4 r7", "ge_r7_r4_r7"},
{{ge, r7, r5, r7}, true, ge, "ge r7 r5 r7", "ge_r7_r5_r7"},
{{ge, r7, r6, r7}, true, ge, "ge r7 r6 r7", "ge_r7_r6_r7"},
{{ge, r7, r7, r7}, true, ge, "ge r7 r7 r7", "ge_r7_r7_r7"},
{{lt, r0, r0, r0}, true, lt, "lt r0 r0 r0", "lt_r0_r0_r0"},
{{lt, r0, r1, r0}, true, lt, "lt r0 r1 r0", "lt_r0_r1_r0"},
{{lt, r0, r2, r0}, true, lt, "lt r0 r2 r0", "lt_r0_r2_r0"},
{{lt, r0, r3, r0}, true, lt, "lt r0 r3 r0", "lt_r0_r3_r0"},
{{lt, r0, r4, r0}, true, lt, "lt r0 r4 r0", "lt_r0_r4_r0"},
{{lt, r0, r5, r0}, true, lt, "lt r0 r5 r0", "lt_r0_r5_r0"},
{{lt, r0, r6, r0}, true, lt, "lt r0 r6 r0", "lt_r0_r6_r0"},
{{lt, r0, r7, r0}, true, lt, "lt r0 r7 r0", "lt_r0_r7_r0"},
{{lt, r1, r0, r1}, true, lt, "lt r1 r0 r1", "lt_r1_r0_r1"},
{{lt, r1, r1, r1}, true, lt, "lt r1 r1 r1", "lt_r1_r1_r1"},
{{lt, r1, r2, r1}, true, lt, "lt r1 r2 r1", "lt_r1_r2_r1"},
{{lt, r1, r3, r1}, true, lt, "lt r1 r3 r1", "lt_r1_r3_r1"},
{{lt, r1, r4, r1}, true, lt, "lt r1 r4 r1", "lt_r1_r4_r1"},
{{lt, r1, r5, r1}, true, lt, "lt r1 r5 r1", "lt_r1_r5_r1"},
{{lt, r1, r6, r1}, true, lt, "lt r1 r6 r1", "lt_r1_r6_r1"},
{{lt, r1, r7, r1}, true, lt, "lt r1 r7 r1", "lt_r1_r7_r1"},
{{lt, r2, r0, r2}, true, lt, "lt r2 r0 r2", "lt_r2_r0_r2"},
{{lt, r2, r1, r2}, true, lt, "lt r2 r1 r2", "lt_r2_r1_r2"},
{{lt, r2, r2, r2}, true, lt, "lt r2 r2 r2", "lt_r2_r2_r2"},
{{lt, r2, r3, r2}, true, lt, "lt r2 r3 r2", "lt_r2_r3_r2"},
{{lt, r2, r4, r2}, true, lt, "lt r2 r4 r2", "lt_r2_r4_r2"},
{{lt, r2, r5, r2}, true, lt, "lt r2 r5 r2", "lt_r2_r5_r2"},
{{lt, r2, r6, r2}, true, lt, "lt r2 r6 r2", "lt_r2_r6_r2"},
{{lt, r2, r7, r2}, true, lt, "lt r2 r7 r2", "lt_r2_r7_r2"},
{{lt, r3, r0, r3}, true, lt, "lt r3 r0 r3", "lt_r3_r0_r3"},
{{lt, r3, r1, r3}, true, lt, "lt r3 r1 r3", "lt_r3_r1_r3"},
{{lt, r3, r2, r3}, true, lt, "lt r3 r2 r3", "lt_r3_r2_r3"},
{{lt, r3, r3, r3}, true, lt, "lt r3 r3 r3", "lt_r3_r3_r3"},
{{lt, r3, r4, r3}, true, lt, "lt r3 r4 r3", "lt_r3_r4_r3"},
{{lt, r3, r5, r3}, true, lt, "lt r3 r5 r3", "lt_r3_r5_r3"},
{{lt, r3, r6, r3}, true, lt, "lt r3 r6 r3", "lt_r3_r6_r3"},
{{lt, r3, r7, r3}, true, lt, "lt r3 r7 r3", "lt_r3_r7_r3"},
{{lt, r4, r0, r4}, true, lt, "lt r4 r0 r4", "lt_r4_r0_r4"},
{{lt, r4, r1, r4}, true, lt, "lt r4 r1 r4", "lt_r4_r1_r4"},
{{lt, r4, r2, r4}, true, lt, "lt r4 r2 r4", "lt_r4_r2_r4"},
{{lt, r4, r3, r4}, true, lt, "lt r4 r3 r4", "lt_r4_r3_r4"},
{{lt, r4, r4, r4}, true, lt, "lt r4 r4 r4", "lt_r4_r4_r4"},
{{lt, r4, r5, r4}, true, lt, "lt r4 r5 r4", "lt_r4_r5_r4"},
{{lt, r4, r6, r4}, true, lt, "lt r4 r6 r4", "lt_r4_r6_r4"},
{{lt, r4, r7, r4}, true, lt, "lt r4 r7 r4", "lt_r4_r7_r4"},
{{lt, r5, r0, r5}, true, lt, "lt r5 r0 r5", "lt_r5_r0_r5"},
{{lt, r5, r1, r5}, true, lt, "lt r5 r1 r5", "lt_r5_r1_r5"},
{{lt, r5, r2, r5}, true, lt, "lt r5 r2 r5", "lt_r5_r2_r5"},
{{lt, r5, r3, r5}, true, lt, "lt r5 r3 r5", "lt_r5_r3_r5"},
{{lt, r5, r4, r5}, true, lt, "lt r5 r4 r5", "lt_r5_r4_r5"},
{{lt, r5, r5, r5}, true, lt, "lt r5 r5 r5", "lt_r5_r5_r5"},
{{lt, r5, r6, r5}, true, lt, "lt r5 r6 r5", "lt_r5_r6_r5"},
{{lt, r5, r7, r5}, true, lt, "lt r5 r7 r5", "lt_r5_r7_r5"},
{{lt, r6, r0, r6}, true, lt, "lt r6 r0 r6", "lt_r6_r0_r6"},
{{lt, r6, r1, r6}, true, lt, "lt r6 r1 r6", "lt_r6_r1_r6"},
{{lt, r6, r2, r6}, true, lt, "lt r6 r2 r6", "lt_r6_r2_r6"},
{{lt, r6, r3, r6}, true, lt, "lt r6 r3 r6", "lt_r6_r3_r6"},
{{lt, r6, r4, r6}, true, lt, "lt r6 r4 r6", "lt_r6_r4_r6"},
{{lt, r6, r5, r6}, true, lt, "lt r6 r5 r6", "lt_r6_r5_r6"},
{{lt, r6, r6, r6}, true, lt, "lt r6 r6 r6", "lt_r6_r6_r6"},
{{lt, r6, r7, r6}, true, lt, "lt r6 r7 r6", "lt_r6_r7_r6"},
{{lt, r7, r0, r7}, true, lt, "lt r7 r0 r7", "lt_r7_r0_r7"},
{{lt, r7, r1, r7}, true, lt, "lt r7 r1 r7", "lt_r7_r1_r7"},
{{lt, r7, r2, r7}, true, lt, "lt r7 r2 r7", "lt_r7_r2_r7"},
{{lt, r7, r3, r7}, true, lt, "lt r7 r3 r7", "lt_r7_r3_r7"},
{{lt, r7, r4, r7}, true, lt, "lt r7 r4 r7", "lt_r7_r4_r7"},
{{lt, r7, r5, r7}, true, lt, "lt r7 r5 r7", "lt_r7_r5_r7"},
{{lt, r7, r6, r7}, true, lt, "lt r7 r6 r7", "lt_r7_r6_r7"},
{{lt, r7, r7, r7}, true, lt, "lt r7 r7 r7", "lt_r7_r7_r7"},
{{gt, r0, r0, r0}, true, gt, "gt r0 r0 r0", "gt_r0_r0_r0"},
{{gt, r0, r1, r0}, true, gt, "gt r0 r1 r0", "gt_r0_r1_r0"},
{{gt, r0, r2, r0}, true, gt, "gt r0 r2 r0", "gt_r0_r2_r0"},
{{gt, r0, r3, r0}, true, gt, "gt r0 r3 r0", "gt_r0_r3_r0"},
{{gt, r0, r4, r0}, true, gt, "gt r0 r4 r0", "gt_r0_r4_r0"},
{{gt, r0, r5, r0}, true, gt, "gt r0 r5 r0", "gt_r0_r5_r0"},
{{gt, r0, r6, r0}, true, gt, "gt r0 r6 r0", "gt_r0_r6_r0"},
{{gt, r0, r7, r0}, true, gt, "gt r0 r7 r0", "gt_r0_r7_r0"},
{{gt, r1, r0, r1}, true, gt, "gt r1 r0 r1", "gt_r1_r0_r1"},
{{gt, r1, r1, r1}, true, gt, "gt r1 r1 r1", "gt_r1_r1_r1"},
{{gt, r1, r2, r1}, true, gt, "gt r1 r2 r1", "gt_r1_r2_r1"},
{{gt, r1, r3, r1}, true, gt, "gt r1 r3 r1", "gt_r1_r3_r1"},
{{gt, r1, r4, r1}, true, gt, "gt r1 r4 r1", "gt_r1_r4_r1"},
{{gt, r1, r5, r1}, true, gt, "gt r1 r5 r1", "gt_r1_r5_r1"},
{{gt, r1, r6, r1}, true, gt, "gt r1 r6 r1", "gt_r1_r6_r1"},
{{gt, r1, r7, r1}, true, gt, "gt r1 r7 r1", "gt_r1_r7_r1"},
{{gt, r2, r0, r2}, true, gt, "gt r2 r0 r2", "gt_r2_r0_r2"},
{{gt, r2, r1, r2}, true, gt, "gt r2 r1 r2", "gt_r2_r1_r2"},
{{gt, r2, r2, r2}, true, gt, "gt r2 r2 r2", "gt_r2_r2_r2"},
{{gt, r2, r3, r2}, true, gt, "gt r2 r3 r2", "gt_r2_r3_r2"},
{{gt, r2, r4, r2}, true, gt, "gt r2 r4 r2", "gt_r2_r4_r2"},
{{gt, r2, r5, r2}, true, gt, "gt r2 r5 r2", "gt_r2_r5_r2"},
{{gt, r2, r6, r2}, true, gt, "gt r2 r6 r2", "gt_r2_r6_r2"},
{{gt, r2, r7, r2}, true, gt, "gt r2 r7 r2", "gt_r2_r7_r2"},
{{gt, r3, r0, r3}, true, gt, "gt r3 r0 r3", "gt_r3_r0_r3"},
{{gt, r3, r1, r3}, true, gt, "gt r3 r1 r3", "gt_r3_r1_r3"},
{{gt, r3, r2, r3}, true, gt, "gt r3 r2 r3", "gt_r3_r2_r3"},
{{gt, r3, r3, r3}, true, gt, "gt r3 r3 r3", "gt_r3_r3_r3"},
{{gt, r3, r4, r3}, true, gt, "gt r3 r4 r3", "gt_r3_r4_r3"},
{{gt, r3, r5, r3}, true, gt, "gt r3 r5 r3", "gt_r3_r5_r3"},
{{gt, r3, r6, r3}, true, gt, "gt r3 r6 r3", "gt_r3_r6_r3"},
{{gt, r3, r7, r3}, true, gt, "gt r3 r7 r3", "gt_r3_r7_r3"},
{{gt, r4, r0, r4}, true, gt, "gt r4 r0 r4", "gt_r4_r0_r4"},
{{gt, r4, r1, r4}, true, gt, "gt r4 r1 r4", "gt_r4_r1_r4"},
{{gt, r4, r2, r4}, true, gt, "gt r4 r2 r4", "gt_r4_r2_r4"},
{{gt, r4, r3, r4}, true, gt, "gt r4 r3 r4", "gt_r4_r3_r4"},
{{gt, r4, r4, r4}, true, gt, "gt r4 r4 r4", "gt_r4_r4_r4"},
{{gt, r4, r5, r4}, true, gt, "gt r4 r5 r4", "gt_r4_r5_r4"},
{{gt, r4, r6, r4}, true, gt, "gt r4 r6 r4", "gt_r4_r6_r4"},
{{gt, r4, r7, r4}, true, gt, "gt r4 r7 r4", "gt_r4_r7_r4"},
{{gt, r5, r0, r5}, true, gt, "gt r5 r0 r5", "gt_r5_r0_r5"},
{{gt, r5, r1, r5}, true, gt, "gt r5 r1 r5", "gt_r5_r1_r5"},
{{gt, r5, r2, r5}, true, gt, "gt r5 r2 r5", "gt_r5_r2_r5"},
{{gt, r5, r3, r5}, true, gt, "gt r5 r3 r5", "gt_r5_r3_r5"},
{{gt, r5, r4, r5}, true, gt, "gt r5 r4 r5", "gt_r5_r4_r5"},
{{gt, r5, r5, r5}, true, gt, "gt r5 r5 r5", "gt_r5_r5_r5"},
{{gt, r5, r6, r5}, true, gt, "gt r5 r6 r5", "gt_r5_r6_r5"},
{{gt, r5, r7, r5}, true, gt, "gt r5 r7 r5", "gt_r5_r7_r5"},
{{gt, r6, r0, r6}, true, gt, "gt r6 r0 r6", "gt_r6_r0_r6"},
{{gt, r6, r1, r6}, true, gt, "gt r6 r1 r6", "gt_r6_r1_r6"},
{{gt, r6, r2, r6}, true, gt, "gt r6 r2 r6", "gt_r6_r2_r6"},
{{gt, r6, r3, r6}, true, gt, "gt r6 r3 r6", "gt_r6_r3_r6"},
{{gt, r6, r4, r6}, true, gt, "gt r6 r4 r6", "gt_r6_r4_r6"},
{{gt, r6, r5, r6}, true, gt, "gt r6 r5 r6", "gt_r6_r5_r6"},
{{gt, r6, r6, r6}, true, gt, "gt r6 r6 r6", "gt_r6_r6_r6"},
{{gt, r6, r7, r6}, true, gt, "gt r6 r7 r6", "gt_r6_r7_r6"},
{{gt, r7, r0, r7}, true, gt, "gt r7 r0 r7", "gt_r7_r0_r7"},
{{gt, r7, r1, r7}, true, gt, "gt r7 r1 r7", "gt_r7_r1_r7"},
{{gt, r7, r2, r7}, true, gt, "gt r7 r2 r7", "gt_r7_r2_r7"},
{{gt, r7, r3, r7}, true, gt, "gt r7 r3 r7", "gt_r7_r3_r7"},
{{gt, r7, r4, r7}, true, gt, "gt r7 r4 r7", "gt_r7_r4_r7"},
{{gt, r7, r5, r7}, true, gt, "gt r7 r5 r7", "gt_r7_r5_r7"},
{{gt, r7, r6, r7}, true, gt, "gt r7 r6 r7", "gt_r7_r6_r7"},
{{gt, r7, r7, r7}, true, gt, "gt r7 r7 r7", "gt_r7_r7_r7"},
{{le, r0, r0, r0}, true, le, "le r0 r0 r0", "le_r0_r0_r0"},
{{le, r0, r1, r0}, true, le, "le r0 r1 r0", "le_r0_r1_r0"},
{{le, r0, r2, r0}, true, le, "le r0 r2 r0", "le_r0_r2_r0"},
{{le, r0, r3, r0}, true, le, "le r0 r3 r0", "le_r0_r3_r0"},
{{le, r0, r4, r0}, true, le, "le r0 r4 r0", "le_r0_r4_r0"},
{{le, r0, r5, r0}, true, le, "le r0 r5 r0", "le_r0_r5_r0"},
{{le, r0, r6, r0}, true, le, "le r0 r6 r0", "le_r0_r6_r0"},
{{le, r0, r7, r0}, true, le, "le r0 r7 r0", "le_r0_r7_r0"},
{{le, r1, r0, r1}, true, le, "le r1 r0 r1", "le_r1_r0_r1"},
{{le, r1, r1, r1}, true, le, "le r1 r1 r1", "le_r1_r1_r1"},
{{le, r1, r2, r1}, true, le, "le r1 r2 r1", "le_r1_r2_r1"},
{{le, r1, r3, r1}, true, le, "le r1 r3 r1", "le_r1_r3_r1"},
{{le, r1, r4, r1}, true, le, "le r1 r4 r1", "le_r1_r4_r1"},
{{le, r1, r5, r1}, true, le, "le r1 r5 r1", "le_r1_r5_r1"},
{{le, r1, r6, r1}, true, le, "le r1 r6 r1", "le_r1_r6_r1"},
{{le, r1, r7, r1}, true, le, "le r1 r7 r1", "le_r1_r7_r1"},
{{le, r2, r0, r2}, true, le, "le r2 r0 r2", "le_r2_r0_r2"},
{{le, r2, r1, r2}, true, le, "le r2 r1 r2", "le_r2_r1_r2"},
{{le, r2, r2, r2}, true, le, "le r2 r2 r2", "le_r2_r2_r2"},
{{le, r2, r3, r2}, true, le, "le r2 r3 r2", "le_r2_r3_r2"},
{{le, r2, r4, r2}, true, le, "le r2 r4 r2", "le_r2_r4_r2"},
{{le, r2, r5, r2}, true, le, "le r2 r5 r2", "le_r2_r5_r2"},
{{le, r2, r6, r2}, true, le, "le r2 r6 r2", "le_r2_r6_r2"},
{{le, r2, r7, r2}, true, le, "le r2 r7 r2", "le_r2_r7_r2"},
{{le, r3, r0, r3}, true, le, "le r3 r0 r3", "le_r3_r0_r3"},
{{le, r3, r1, r3}, true, le, "le r3 r1 r3", "le_r3_r1_r3"},
{{le, r3, r2, r3}, true, le, "le r3 r2 r3", "le_r3_r2_r3"},
{{le, r3, r3, r3}, true, le, "le r3 r3 r3", "le_r3_r3_r3"},
{{le, r3, r4, r3}, true, le, "le r3 r4 r3", "le_r3_r4_r3"},
{{le, r3, r5, r3}, true, le, "le r3 r5 r3", "le_r3_r5_r3"},
{{le, r3, r6, r3}, true, le, "le r3 r6 r3", "le_r3_r6_r3"},
{{le, r3, r7, r3}, true, le, "le r3 r7 r3", "le_r3_r7_r3"},
{{le, r4, r0, r4}, true, le, "le r4 r0 r4", "le_r4_r0_r4"},
{{le, r4, r1, r4}, true, le, "le r4 r1 r4", "le_r4_r1_r4"},
{{le, r4, r2, r4}, true, le, "le r4 r2 r4", "le_r4_r2_r4"},
{{le, r4, r3, r4}, true, le, "le r4 r3 r4", "le_r4_r3_r4"},
{{le, r4, r4, r4}, true, le, "le r4 r4 r4", "le_r4_r4_r4"},
{{le, r4, r5, r4}, true, le, "le r4 r5 r4", "le_r4_r5_r4"},
{{le, r4, r6, r4}, true, le, "le r4 r6 r4", "le_r4_r6_r4"},
{{le, r4, r7, r4}, true, le, "le r4 r7 r4", "le_r4_r7_r4"},
{{le, r5, r0, r5}, true, le, "le r5 r0 r5", "le_r5_r0_r5"},
{{le, r5, r1, r5}, true, le, "le r5 r1 r5", "le_r5_r1_r5"},
{{le, r5, r2, r5}, true, le, "le r5 r2 r5", "le_r5_r2_r5"},
{{le, r5, r3, r5}, true, le, "le r5 r3 r5", "le_r5_r3_r5"},
{{le, r5, r4, r5}, true, le, "le r5 r4 r5", "le_r5_r4_r5"},
{{le, r5, r5, r5}, true, le, "le r5 r5 r5", "le_r5_r5_r5"},
{{le, r5, r6, r5}, true, le, "le r5 r6 r5", "le_r5_r6_r5"},
{{le, r5, r7, r5}, true, le, "le r5 r7 r5", "le_r5_r7_r5"},
{{le, r6, r0, r6}, true, le, "le r6 r0 r6", "le_r6_r0_r6"},
{{le, r6, r1, r6}, true, le, "le r6 r1 r6", "le_r6_r1_r6"},
{{le, r6, r2, r6}, true, le, "le r6 r2 r6", "le_r6_r2_r6"},
{{le, r6, r3, r6}, true, le, "le r6 r3 r6", "le_r6_r3_r6"},
{{le, r6, r4, r6}, true, le, "le r6 r4 r6", "le_r6_r4_r6"},
{{le, r6, r5, r6}, true, le, "le r6 r5 r6", "le_r6_r5_r6"},
{{le, r6, r6, r6}, true, le, "le r6 r6 r6", "le_r6_r6_r6"},
{{le, r6, r7, r6}, true, le, "le r6 r7 r6", "le_r6_r7_r6"},
{{le, r7, r0, r7}, true, le, "le r7 r0 r7", "le_r7_r0_r7"},
{{le, r7, r1, r7}, true, le, "le r7 r1 r7", "le_r7_r1_r7"},
{{le, r7, r2, r7}, true, le, "le r7 r2 r7", "le_r7_r2_r7"},
{{le, r7, r3, r7}, true, le, "le r7 r3 r7", "le_r7_r3_r7"},
{{le, r7, r4, r7}, true, le, "le r7 r4 r7", "le_r7_r4_r7"},
{{le, r7, r5, r7}, true, le, "le r7 r5 r7", "le_r7_r5_r7"},
{{le, r7, r6, r7}, true, le, "le r7 r6 r7", "le_r7_r6_r7"},
{{le, r7, r7, r7}, true, le, "le r7 r7 r7", "le_r7_r7_r7"}};
// These headers each contain an array of `TestResult` with the reference output
// values. The reference arrays are names `kReference{mnemonic}`.
#include "aarch32/traces/assembler-cond-rdlow-rnlow-rmlow-in-it-block-mul-t32.h"
// The maximum number of errors to report in detail for each test.
const unsigned kErrorReportLimit = 8;
typedef void (MacroAssembler::*Fn)(Condition cond,
Register rd,
Register rn,
Register rm);
void TestHelper(Fn instruction,
const char* mnemonic,
const TestResult reference[]) {
unsigned total_error_count = 0;
MacroAssembler masm(BUF_SIZE);
masm.UseT32();
for (unsigned i = 0; i < ARRAY_SIZE(kTests); i++) {
// Values to pass to the macro-assembler.
Condition cond = kTests[i].operands.cond;
Register rd = kTests[i].operands.rd;
Register rn = kTests[i].operands.rn;
Register rm = kTests[i].operands.rm;
int32_t start = masm.GetCursorOffset();
{
// We never generate more that 4 bytes, as IT instructions are only
// allowed for narrow encodings.
ExactAssemblyScope scope(&masm, 4, ExactAssemblyScope::kMaximumSize);
if (kTests[i].in_it_block) {
masm.it(kTests[i].it_condition);
}
(masm.*instruction)(cond, rd, rn, rm);
}
int32_t end = masm.GetCursorOffset();
const byte* result_ptr =
masm.GetBuffer()->GetOffsetAddress<const byte*>(start);
VIXL_ASSERT(start < end);
uint32_t result_size = end - start;
if (Test::generate_test_trace()) {
// Print the result bytes.
printf("const byte kInstruction_%s_%s[] = {\n",
mnemonic,
kTests[i].identifier);
for (uint32_t j = 0; j < result_size; j++) {
if (j == 0) {
printf(" 0x%02" PRIx8, result_ptr[j]);
} else {
printf(", 0x%02" PRIx8, result_ptr[j]);
}
}
// This comment is meant to be used by external tools to validate
// the encoding. We can parse the comment to figure out what
// instruction this corresponds to.
if (kTests[i].in_it_block) {
printf(" // It %s; %s %s\n};\n",
kTests[i].it_condition.GetName(),
mnemonic,
kTests[i].operands_description);
} else {
printf(" // %s %s\n};\n", mnemonic, kTests[i].operands_description);
}
} else {
// Check we've emitted the exact same encoding as present in the
// trace file. Only print up to `kErrorReportLimit` errors.
if (((result_size != reference[i].size) ||
(memcmp(result_ptr, reference[i].encoding, reference[i].size) !=
0)) &&
(++total_error_count <= kErrorReportLimit)) {
printf("Error when testing \"%s\" with operands \"%s\":\n",
mnemonic,
kTests[i].operands_description);
printf(" Expected: ");
for (uint32_t j = 0; j < reference[i].size; j++) {
if (j == 0) {
printf("0x%02" PRIx8, reference[i].encoding[j]);
} else {
printf(", 0x%02" PRIx8, reference[i].encoding[j]);
}
}
printf("\n");
printf(" Found: ");
for (uint32_t j = 0; j < result_size; j++) {
if (j == 0) {
printf("0x%02" PRIx8, result_ptr[j]);
} else {
printf(", 0x%02" PRIx8, result_ptr[j]);
}
}
printf("\n");
}
}
}
masm.FinalizeCode();
if (Test::generate_test_trace()) {
// Finalize the trace file by writing the final `TestResult` array
// which links all generated instruction encodings.
printf("const TestResult kReference%s[] = {\n", mnemonic);
for (unsigned i = 0; i < ARRAY_SIZE(kTests); i++) {
printf(" {\n");
printf(" ARRAY_SIZE(kInstruction_%s_%s),\n",
mnemonic,
kTests[i].identifier);
printf(" kInstruction_%s_%s,\n", mnemonic, kTests[i].identifier);
printf(" },\n");
}
printf("};\n");
} else {
if (total_error_count > kErrorReportLimit) {
printf("%u other errors follow.\n",
total_error_count - kErrorReportLimit);
}
// Crash if the test failed.
VIXL_CHECK(total_error_count == 0);
}
}
// Instantiate tests for each instruction in the list.
#define TEST(mnemonic) \
void Test_##mnemonic() { \
TestHelper(&MacroAssembler::mnemonic, #mnemonic, kReference##mnemonic); \
} \
Test test_##mnemonic( \
"AARCH32_ASSEMBLER_COND_RDLOW_RNLOW_RMLOW_IN_IT_BLOCK_" #mnemonic \
"_T32", \
&Test_##mnemonic);
FOREACH_INSTRUCTION(TEST)
#undef TEST
} // namespace
#endif
} // namespace aarch32
} // namespace vixl
| 58.995591
| 80
| 0.52192
|
capablevms
|
fc934b8cd745265f74102619d9ea7d423fcf2240
| 524
|
cpp
|
C++
|
warm-woody-knocker/src/Parameters/RelativeParameter.cpp
|
fedulvtubudul/warm-woody-knocker
|
fdf19c72e33397f4cef70832a0e04d6dfeffb6c3
|
[
"MIT"
] | 2
|
2020-01-20T02:39:34.000Z
|
2020-03-03T05:52:45.000Z
|
warm-woody-knocker/src/Parameters/RelativeParameter.cpp
|
fedulvtubudul/warm-woody-knocker
|
fdf19c72e33397f4cef70832a0e04d6dfeffb6c3
|
[
"MIT"
] | 1
|
2017-11-21T04:34:37.000Z
|
2017-11-21T04:34:37.000Z
|
warm-woody-knocker/src/Parameters/RelativeParameter.cpp
|
fedulvtubudul/warm-woody-knocker
|
fdf19c72e33397f4cef70832a0e04d6dfeffb6c3
|
[
"MIT"
] | null | null | null |
#include "RelativeParameter.h"
RelativeParameter::RelativeParameter(String *title, Storage *storage, StoredParameter parameter, int steps, void (*onChange)(RelativeParameter *sender)) :
IntegerParameter(title, storage, parameter, 0, steps, onChange) {
relativeValue = (float)(value - minValue) / (float)(maxValue - minValue);
}
void RelativeParameter::notify() {
relativeValue = (float)(value - minValue) / (float)(maxValue - minValue);
IntegerParameter::notify();
}
RelativeParameter::~RelativeParameter() {
}
| 27.578947
| 155
| 0.742366
|
fedulvtubudul
|
fc9f77231a38f04ba92b9283627f35a2bcf552e8
| 2,868
|
hpp
|
C++
|
src/texture/components/frame.hpp
|
hexoctal/zenith
|
eeef065ed62f35723da87c8e73a6716e50d34060
|
[
"MIT"
] | 2
|
2021-03-18T16:25:04.000Z
|
2021-11-13T00:29:27.000Z
|
src/texture/components/frame.hpp
|
hexoctal/zenith
|
eeef065ed62f35723da87c8e73a6716e50d34060
|
[
"MIT"
] | null | null | null |
src/texture/components/frame.hpp
|
hexoctal/zenith
|
eeef065ed62f35723da87c8e73a6716e50d34060
|
[
"MIT"
] | 1
|
2021-11-13T00:29:30.000Z
|
2021-11-13T00:29:30.000Z
|
/**
* @file
* @author __AUTHOR_NAME__ <mail@host.com>
* @copyright 2021 __COMPANY_LTD__
* @license <a href="https://opensource.org/licenses/MIT">MIT License</a>
*/
#ifndef ZEN_TEXTURES_COMPONENTS_FRAME_HPP
#define ZEN_TEXTURES_COMPONENTS_FRAME_HPP
#include <string>
#include "../../ecs/entity.hpp"
#include "../frame_data.hpp"
namespace Zen {
namespace Components {
struct Frame
{
/**
* The name of this Frame.
* The name is unique within the Texture.
*
* @since 0.0.0
*/
std::string name;
/**
* The TextureSource this Frame is part of.
*
* @since 0.0.0
*/
Entity source = entt::null;
/**
* The X rendering offset of this Frame, taking trim into account.
*
* @since 0.0.0
*/
int x = 0;
/**
* The Y rendering offset of this Frame, taking trim into account.
*
* @since 0.0.0
*/
int y = 0;
/**
* The rendering width of this Frame, taking trim into account.
*
* @since 0.0.0
*/
int width = 0;
/**
* The rendering height of this Frame, taking trim into account.
*
* @since 0.0.0
*/
int height = 0;
/**
* X position within the source image to cut from.
*
* @since 0.0.0
*/
int cutX = 0;
/**
* Y position within the source image to cut from.
*
* @since 0.0.0
*/
int cutY = 0;
/**
* The width of the area in the source image to cut.
*
* @since 0.0.0
*/
int cutWidth = 0;
/**
* The height of the area in the source image to cut.
*
* @since 0.0.0
*/
int cutHeight = 0;
/**
* Half the width, floored.
* Precalculated for the renderer.
*
* @since 0.0.0
*/
int halfWidth = 0;
/**
* Half the height, floored.
* Precalculated for the renderer.
*
* @since 0.0.0
*/
int halfHeight = 0;
/**
* The x center of this frame, floored.
*
* @since 0.0.0
*/
int centerX = 0;
/**
* The y center of this frame, floored.
*
* @since 0.0.0
*/
int centerY = 0;
/**
* The horizontal pivot point of this Frame.
*
* @since 0.0.0
*/
double pivotX = 0;
/**
* The vertical pivot point of this Frame.
*
* @since 0.0.0
*/
double pivotY = 0;
/**
* Does this Frame have a custom pivot point?
*
* @since 0.0.0
*/
bool customPivot = false;
/**
* Is this frame rotated or not in the Texture?
* Rotation allows you to use rotated frames in texture atlas packing.
* It has nothing to do with Sprite rotation.
*
* @since 0.0.0
*/
bool rotated = false;
/**
* OpenGL UV u0 value.
*
* @since 0.0.0
*/
double u0 = 0;
/**
* OpenGL UV v0 value.
*
* @since 0.0.0
*/
double v0 = 0;
/**
* OpenGL UV u1 value.
*
* @since 0.0.0
*/
double u1 = 0;
/**
* OpenGL UV v1 value.
*
* @since 0.0.0
*/
double v1 = 0;
/**
* The un-modified source frame, trim and UV data.
*
* @since 0.0.0
*/
FrameData data;
};
} // namespace Components
} // namespace Zen
#endif
| 15.015707
| 74
| 0.585077
|
hexoctal
|
fca149fe0688e4b8e9adc90af2c0051f8aa235c8
| 12,118
|
hpp
|
C++
|
3dc/avp/win95/heap_tem.hpp
|
Melanikus/AvP
|
9d61eb974a23538e32bf2ef1b738643a018935a0
|
[
"BSD-3-Clause"
] | null | null | null |
3dc/avp/win95/heap_tem.hpp
|
Melanikus/AvP
|
9d61eb974a23538e32bf2ef1b738643a018935a0
|
[
"BSD-3-Clause"
] | null | null | null |
3dc/avp/win95/heap_tem.hpp
|
Melanikus/AvP
|
9d61eb974a23538e32bf2ef1b738643a018935a0
|
[
"BSD-3-Clause"
] | null | null | null |
#ifndef _included_heap_tem_hpp_
#define _included_heap_tem_hpp_
// Author: Jake Hotson, Rebellion Developments Ltd.
// Previously, the first declaration of these class templates was as friends
// of Ordered_Heap_Member. But Visual C++ 5 will not parse the friend
// declarations unless we give a forward declaration first. I think this is
// a compiler bug - Garry.
template<class T>
class Ordered_Heap;
template<class T>
class Ordered_Heap_Iterator_Forward;
template<class T>
class Ordered_Heap_Iterator_Backward;
template<class T>
class Ordered_Heap_Member
{
private:
T data;
Ordered_Heap_Member<T> * lower, * higher, * parent;
int num_lower, num_higher;
// Ordered_Heap_Member() : lower(0), higher(0), parent(0), num_lower(0), num_higher(0) {}
Ordered_Heap_Member(const T & d) : lower(0), higher(0), parent(0), num_lower(0), num_higher(0), data(d) {}
void delete_tree()
{
if (lower)
{
lower->delete_tree();
delete lower;
}
if (higher)
{
higher->delete_tree();
delete higher;
}
}
friend class Ordered_Heap<T>;
friend class Ordered_Heap_Iterator_Forward<T>;
friend class Ordered_Heap_Iterator_Backward<T>;
};
// I haven't implemented balancing of the heap on addition or deletion of entries
// so if you build the heap by adding the elements in order, it will be lopsided and inefficient
// if anyone wants to suggest a good way of keeping the heap balanced, please do...
// the operator < must be defined (and should be transitive).
// equivalent elements (!(a<b) && !(b<a)) may both exist in a heap
template<class T>
class Ordered_Heap
{
private:
Ordered_Heap_Member<T> * lowest, * highest, * root;
int n_entries;
public:
// empty heap
Ordered_Heap() : lowest(0), highest(0), root(0), n_entries(0) {}
// heap with one element
Ordered_Heap(T const & d)
{
lowest = highest = root = new Ordered_Heap_Member<T>(d);
n_entries = 1;
}
// heap with all the elents of another heap
Ordered_Heap(const Ordered_Heap<T> & h) : lowest(0), highest(0), root(0), n_entries(0) { add_heap(h); }
// assignment from another heap
Ordered_Heap<T> & operator = (const Ordered_Heap<T> & h)
{
if (&h != this)
{
if (root)
{
root->delete_tree();
delete root;
}
n_entries = 0;
root = highest = lowest = 0;
add_heap(h);
}
return *this;
}
// deconstructor
~Ordered_Heap()
{
if (root)
{
root->delete_tree();
delete root;
}
}
// add all elements of another heap (merge)
void add_heap(const Ordered_Heap<T> & h)
{
if (h.root) add_heap(*h.root);
}
private:
void add_heap(const Ordered_Heap_Member<T> & m)
{
add_entry(m.data);
if (m.lower) add_heap(*m.lower);
if (m.higher) add_heap(*m.higher);
}
public:
// inclued a new element
void add_entry(const T & d)
{
if (n_entries)
{
Ordered_Heap_Member<T> * new_member = new Ordered_Heap_Member<T>(d);
Ordered_Heap_Member<T> * new_lowest = new_member;
Ordered_Heap_Member<T> * new_highest = new_member;
for (Ordered_Heap_Member<T> * m = root;1;)
{
if (d < m->data)
{
++ m->num_lower;
if (m->lower)
{
m = m->lower;
new_highest = highest;
}
else
{
m->lower = new_member;
new_member->parent = m;
lowest = new_lowest;
break;
}
}
else
{
++ m->num_higher;
if (m->higher)
{
m = m->higher;
new_lowest = lowest;
}
else
{
m->higher = new_member;
new_member->parent = m;
highest = new_highest;
break;
}
}
}
}
else
{
lowest = highest = root = new Ordered_Heap_Member<T>(d);
}
++ n_entries;
}
// delete the element a in heap h such that for all b in h : !(b < a)
void delete_lowest()
{
if (1==n_entries)
{
delete root;
n_entries = 0;
root = lowest = highest = 0;
}
else if (n_entries)
{
Ordered_Heap_Member<T> * new_lowest;
if (lowest->parent)
{
for (Ordered_Heap_Member<T> * m = lowest; m->parent; m = m->parent)
{
-- m->parent->num_lower;
}
if (lowest->higher)
{
new_lowest = lowest->higher;
lowest->parent->lower = new_lowest;
new_lowest->parent = lowest->parent;
delete lowest;
while (new_lowest->lower) new_lowest = new_lowest->lower;
}
else
{
new_lowest = lowest->parent;
new_lowest->lower = 0;
delete lowest;
}
}
else // lowest is root
{
new_lowest = lowest->higher;
new_lowest->parent = 0;
delete lowest;
root = new_lowest;
while (new_lowest->lower) new_lowest = new_lowest->lower;
}
lowest = new_lowest;
-- n_entries;
}
}
// delete the element a in heap h such that for all b in h : !(a < b)
void delete_highest()
{
if (1==n_entries)
{
delete root;
n_entries = 0;
root = lowest = highest = 0;
}
else if (n_entries)
{
Ordered_Heap_Member<T> * new_highest;
if (highest->parent)
{
for (Ordered_Heap_Member<T> * m = highest; m->parent; m = m->parent)
{
-- m->parent->num_higher;
}
if (highest->lower)
{
new_highest = highest->lower;
highest->parent->higher = new_highest;
new_highest->parent = highest->parent;
delete highest;
while (new_highest->higher) new_highest = new_highest->higher;
}
else
{
new_highest = highest->parent;
new_highest->higher = 0;
delete highest;
}
}
else // highest is root
{
new_highest = highest->lower;
new_highest->parent = 0;
delete highest;
root = new_highest;
while (new_highest->higher) new_highest = new_highest->higher;
}
highest = new_highest;
-- n_entries;
}
}
Ordered_Heap_Member<T> * equivalent_entry(T const & d)
{
Ordered_Heap_Member<T> * m = root;
while (m && (m->data<d || d<m->data))
m = d<m->data ? m->lower : m->higher;
return m;
}
void delete_entry_by_pointer(Ordered_Heap_Member<T> * m)
{
if (m == lowest) delete_lowest();
else if (m == highest) delete_highest();
else if (m->lower)
{
Ordered_Heap_Member<T> * new_node = m->lower;
while (new_node->higher)
{
-- new_node->num_higher;
new_node = new_node->higher;
}
if (new_node != m->lower)
{
new_node->parent->higher = new_node->lower;
if (new_node->lower) new_node->lower->parent = new_node->parent;
}
else
{
m->lower = new_node->lower;
}
if (m->parent)
{
if (m->parent->higher == m)
{
m->parent->higher = new_node;
-- m->parent->num_higher;
}
else
{
m->parent->lower = new_node;
-- m->parent->num_lower;
}
}
else root = new_node;
if (m->lower) m->lower->parent = new_node;
if (m->higher) m->higher->parent = new_node;
new_node->parent = m->parent;
new_node->lower = m->lower;
new_node->higher = m->higher;
new_node->num_lower = m->num_lower-1;
new_node->num_higher = m->num_higher;
delete m;
-- n_entries;
}
else
{
if (m->parent)
{
if (m->parent->higher == m)
{
m->parent->higher = m->higher;
-- m->parent->num_higher;
}
else
{
m->parent->lower = m->higher;
-- m->parent->num_lower;
}
}
else root = m->higher;
if (m->higher) m->higher->parent = m->parent;
delete m;
-- n_entries;
}
}
// return the ith element, when i=0 returns the lowest
T const & operator [](int i) const
{
Ordered_Heap_Member<T> * m = root;
while (m->num_lower != i)
{
if (m->num_lower > i) m = m->lower;
else
{
i -= m->num_lower;
m = m->higher;
-- i;
}
}
return m->data;
}
// return the element a in heap h such that for all b in h : !(b < a)
T const & lowest_entry() const { return lowest->data; }
// return the element a in heap h such that for all b in h : !(a < b)
T const & highest_entry() const { return highest->data; }
// return the number of elements
int size() const { return n_entries; }
friend class Ordered_Heap_Iterator_Forward<T>;
friend class Ordered_Heap_Iterator_Backward<T>;
};
template<class T>
class Ordered_Heap_Iterator_Forward
{
private:
Ordered_Heap_Member<T> * m;
Ordered_Heap<T> const * h;
Ordered_Heap<T> * hnc;
public:
// construct with pointer to heap, start at lowest
Ordered_Heap_Iterator_Forward() {}
Ordered_Heap_Iterator_Forward(Ordered_Heap<T> const * const h) : h(h), hnc(0), m(h->lowest) {}
Ordered_Heap_Iterator_Forward(Ordered_Heap<T> * const h) : h(h), hnc(h), m(h->lowest) {}
int operator == (Ordered_Heap_Iterator_Forward const & i2) const { return m==i2.m; }
int operator != (Ordered_Heap_Iterator_Forward const & i2) const { return m!=i2.m; }
// move to next highest, sequentially
void next()
{
if (m->higher)
{
m = m->higher;
while (m->lower) m = m->lower;
}
else
{
while (m->parent)
{
if (m->parent->lower == m) break;
m = m->parent;
}
if (m->parent) m = m->parent;
else m = 0;
}
}
// undo a next operation
void un_next()
{
if (m->lower)
{
m = m->lower;
while (m->higher) m = m->higher;
}
else
{
while (m->parent)
{
if (m->parent->higher == m) break;
m = m->parent;
}
if (m->parent) m = m->parent;
else m = 0;
}
}
// return the current element
T const & operator() () const { return m->data; }
operator T const & () const { return m->data; }
// delete the current element
// unpredictable if iterator constructed from a constant heap
void delete_current()
{
Ordered_Heap_Member<T> * old_m = m;
next();
hnc->delete_entry_by_pointer(old_m);
}
// change the current element, checking that the ordering is preserved
int change_current(T const & new_val) // be very careful with this -- check the return value which is non-zero on success
{
Ordered_Heap_Member<T> * old_m = m;
next();
Ordered_Heap_Member<T> * higher_m = m;
m = old_m;
un_next();
Ordered_Heap_Member<T> * lower_m = m;
m = old_m;
if (lower_m) if (new_val < lower_m->data) { return 0; }
if (higher_m) if (higher_m->data < new_val) { return 0; }
m->data = new_val;
return 1;
}
// have we gone past the highest?
int done() const { return m ? 0 : 1; }
// start again at lowest
void restart() { m = h->lowest; }
};
#define OHIF Ordered_Heap_Iterator_Forward
template<class T>
class Ordered_Heap_Iterator_Backward
{
private:
Ordered_Heap_Member<T> * m;
Ordered_Heap<T> const * h;
Ordered_Heap<T> * hnc;
public:
Ordered_Heap_Iterator_Backward() {}
Ordered_Heap_Iterator_Backward(Ordered_Heap<T> const * const h) : h(h), hnc(0), m(h->highest) {}
Ordered_Heap_Iterator_Backward(Ordered_Heap<T> * const h) : h(h), hnc(h), m(h->highest) {}
int operator == (Ordered_Heap_Iterator_Backward const & i2) const { return m==i2.m; }
int operator != (Ordered_Heap_Iterator_Backward const & i2) const { return m!=i2.m; }
void next()
{
if (m->lower)
{
m = m->lower;
while (m->higher) m = m->higher;
}
else
{
while (m->parent)
{
if (m->parent->higher == m) break;
m = m->parent;
}
if (m->parent) m = m->parent;
else m = 0;
}
}
void un_next()
{
if (m->higher)
{
m = m->higher;
while (m->lower) m = m->lower;
}
else
{
while (m->parent)
{
if (m->parent->lower == m) break;
m = m->parent;
}
if (m->parent) m = m->parent;
else m = 0;
}
}
T const & operator() () const { return m->data; }
operator T const & () const { return m->data; }
void delete_current()
{
Ordered_Heap_Member<T> * old_m = m;
next();
hnc->delete_entry_by_pointer(old_m);
}
int change_current(T const & new_val) // be very careful with this -- check the return value which is non-zero on success
{
Ordered_Heap_Member<T> * old_m = m;
next();
Ordered_Heap_Member<T> * lower_m = m;
m = old_m;
un_next();
Ordered_Heap_Member<T> * higher_m = m;
m = old_m;
if (lower_m) if (new_val < lower_m->data) { return 0; }
if (higher_m) if (higher_m->data < new_val) { return 0; }
m->data = new_val;
return 1;
}
int done() const { return m ? 0 : 1; }
void restart() { m = h->highest; }
};
#define OHIB Ordered_Heap_Iterator_Backward
#endif // !_included_heap_tem_hpp_
| 22.032727
| 122
| 0.620812
|
Melanikus
|
fca39b8f7c38636a36c894a516fd745946f9ef7c
| 4,828
|
cpp
|
C++
|
SoftBodyExample002/src/ofApp.cpp
|
elosine/of
|
c0e79029271869c38db8086a1ae4e093db3d06c5
|
[
"Apache-2.0"
] | null | null | null |
SoftBodyExample002/src/ofApp.cpp
|
elosine/of
|
c0e79029271869c38db8086a1ae4e093db3d06c5
|
[
"Apache-2.0"
] | null | null | null |
SoftBodyExample002/src/ofApp.cpp
|
elosine/of
|
c0e79029271869c38db8086a1ae4e093db3d06c5
|
[
"Apache-2.0"
] | null | null | null |
#include "ofApp.h"
#include "BulletSoftBody/btSoftRigidDynamicsWorld.h"
#ifndef round
#define round(x) (x<0?ceil((x)-0.5):floor((x)+0.5))
#endif
//--------------------------------------------------------------
void ofApp::setup() {
ofSetFrameRate(60);
ofSetVerticalSync(true);
sender.setup(HOST, PORT);
receiver.setup(PORTR);
camera.setPosition(ofVec3f(0, -4.f, -10.f));
camera.lookAt(ofVec3f(0, 0, 0), ofVec3f(0, -1, 0));
world.setup();
world.setCamera(&camera);
// ground = new ofxBulletBox();
// ground->create( world.world, ofVec3f(0., 5.5, 0.), 0., 50., 1.f, 50.f );
// ground->setProperties(.25, .95);
// ground->add();
colors[0] = ofColor(15,197,138);
colors[1] = ofColor(220, 0, 220);
colors[2] = ofColor(220, 180, 60);
colors[3] = ofColor(255, 20, 50);
ofVec3f node1 = camera.screenToWorld(ofVec3f( 0, ofGetHeight()/2, 0));
ofVec3f node2 = camera.screenToWorld(ofVec3f( ofGetWidth()+10, ofGetHeight()/2, 0));
ofVec3f node3 = camera.screenToWorld(ofVec3f( ofGetWidth()/2, ofGetHeight()/2, 0));
rope = new ofxBulletRope();
//rope->create(&world, ofVec3f(0, 2, 0), ofVec3f(0, 5.5, 0), 50);
rope->create(&world, node1, node2, 100);
rope->add();
rope->setMass(0.5f);
rope->setStiffness(1, 1, 1);
//rope->setFixedAt(0);
//rope->setNodePositionAt(0, node1);
rope->setFixedAt(0);
rope->setFixedAt(101);
rope2 = new ofxBulletRope();
rope2->create(&world, node3, node2, 20);
rope2->add();
rope2->setMass(0.5f);
rope2->setStiffness(1, 1, 1);
rope2->setFixedAt(21);
ofHideCursor();
}
//--------------------------------------------------------------
void ofApp::update() {
ofxOscMessage m;
m.setAddress("/getFreqAmp");
sender.sendMessage(m, false);
while(receiver.hasWaitingMessages()){
ofxOscMessage m;
receiver.getNextMessage(m);
if(m.getAddress() == "/freqAmp"){
freq = m.getArgAsFloat(0);
amp = m.getArgAsFloat(1);
}
}
world.update();
//ofSetWindowTitle(ofToString(ofGetFrameRate(), 0));
if(freq > 80 && freq < 90){
// float nypos = ofMap(amp, -30, -10, ofGetHeight(), 0);
float nypos = ofMap(amp, -30, -10, ofGetHeight()/2, 0);
nypos = ofClamp(nypos, -5, ofGetHeight()+5);
if(amp < -50){
nypos = ofGetHeight()/2;
}
// rope->setNodePositionAt(0, camera.screenToWorld( ofVec3f(-10, nypos, 0) ));
// rope->setNodePositionAt(51, camera.screenToWorld( ofVec3f(ofGetWidth()+10, ofGetHeight()-nypos, 0) ));
rope->setNodePositionAt(0, camera.screenToWorld( ofVec3f(-5, nypos, 0) ));
rope->setNodePositionAt(101, camera.screenToWorld( ofVec3f(ofGetWidth()+5, ofGetHeight()-nypos, 0) ));
//rope->setNodePositionAt(101, camera.screenToWorld( ofVec3f(ofGetWidth()+5, nypos, 0) ));
// rope->setNodePositionAt(0, camera.screenToWorld( ofVec3f((ofGetWidth()/2) - 100, nypos, 0) ));
// rope->setNodePositionAt(51, camera.screenToWorld( ofVec3f( (ofGetWidth()/2) + 100, ofGetHeight()-nypos, 0) ));
}
}
//--------------------------------------------------------------
void ofApp::draw() {
glEnable( GL_DEPTH_TEST );
//ofBackgroundGradient( ofColor( 255 ), ofColor( 128 ) );
ofBackground(0);
camera.begin();
ofSetLineWidth(1.f);
// ofEnableLighting();
// light.enable();
//light.setPosition( mousePos );
// light.setPosition( ofVec3f(0.24, -3.81, 4.23) );
ofSetColor(100, 100, 100);
//ground->draw();
ofSetColor(ofColor::lime);
ofSetLineWidth(3);
rope->draw();
//rope2->draw();
// light.disable();
// ofDisableLighting();
camera.end();
glDisable(GL_DEPTH_TEST);
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key) {
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key) {
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y) {
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button) {
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button) {
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h) {
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg) {
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo) {
}
| 26.822222
| 120
| 0.509528
|
elosine
|
fca417f10322a6f89e1ab22f4677646149e98356
| 1,019
|
cpp
|
C++
|
testapp/scenes/PhysicsTestScene.cpp
|
artfulbytes/sumobot_simulator
|
f2784d2ff506759019d7d5e840bd7aed591a0add
|
[
"MIT"
] | null | null | null |
testapp/scenes/PhysicsTestScene.cpp
|
artfulbytes/sumobot_simulator
|
f2784d2ff506759019d7d5e840bd7aed591a0add
|
[
"MIT"
] | null | null | null |
testapp/scenes/PhysicsTestScene.cpp
|
artfulbytes/sumobot_simulator
|
f2784d2ff506759019d7d5e840bd7aed591a0add
|
[
"MIT"
] | null | null | null |
#include "PhysicsTestScene.h"
#include "shapes/RectObject.h"
#include "shapes/CircleObject.h"
#include <glm/glm.hpp>
PhysicsTestScene::PhysicsTestScene() :
Scene("Test physics with 5x5cm@1kg box and 5cm@1kg ball", PhysicsWorld::Gravity::SideView)
{
const glm::vec4 color(1.0f, 1.0f, 1.0f, 1.0f);
const Body2D::Specification groundBodySpec = { false, true, 1.0f };
m_ground = std::make_unique<RectObject>(this, color, &groundBodySpec,
glm::vec2{ 0.0f, -0.2f }, glm::vec2{ 0.4f, 0.025f}, 0.0f);
const Body2D::Specification fallingBoxBodySpec = { true, true, 1.0f };
m_fallingBox = std::make_unique<RectObject>(this, color, &fallingBoxBodySpec,
glm::vec2{ 0.0f, 0.5f }, glm::vec2{ 0.05f, 0.05f }, 0.2f);
const Body2D::Specification fallingBallBodySpec = { true, true, 1.0f };
m_fallingBall = std::make_unique<CircleObject>(this, color, &fallingBallBodySpec, glm::vec2{ 0.04f, 0.7f }, 0.025f);
}
| 48.52381
| 120
| 0.632974
|
artfulbytes
|
fca4b92b735242ef96313a85ae68c5c736d3abb1
| 2,425
|
hpp
|
C++
|
source/modus_core/detail/Timer.hpp
|
Gurman8r/modus
|
5c97a89f77c1c5733793dddc20c5ce4afe1fd134
|
[
"MIT"
] | null | null | null |
source/modus_core/detail/Timer.hpp
|
Gurman8r/modus
|
5c97a89f77c1c5733793dddc20c5ce4afe1fd134
|
[
"MIT"
] | null | null | null |
source/modus_core/detail/Timer.hpp
|
Gurman8r/modus
|
5c97a89f77c1c5733793dddc20c5ce4afe1fd134
|
[
"MIT"
] | null | null | null |
#ifndef _ML_TIMER_HPP_
#define _ML_TIMER_HPP_
#include <modus_core/detail/Duration.hpp>
#include <modus_core/detail/NonCopyable.hpp>
namespace ml
{
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
ML_alias high_resolution_clock = typename chrono::high_resolution_clock;
ML_alias time_point = typename high_resolution_clock::time_point;
struct timer final : non_copyable
{
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
timer() noexcept
: m_running{}
, m_start_time{}
, m_stop_time{}
, m_elapsed{}
{
}
timer(bool running) noexcept
: m_running{ running }
, m_start_time{ high_resolution_clock::now() }
, m_stop_time{ m_start_time }
, m_elapsed{}
{
}
timer(timer && other) noexcept : timer{}
{
this->swap(std::move(other));
}
timer & operator=(timer && other) noexcept
{
this->swap(std::move(other));
return (*this);
}
void swap(timer & other) noexcept
{
if (this != std::addressof(other))
{
std::swap(m_running, other.m_running);
std::swap(m_start_time, other.m_start_time);
std::swap(m_stop_time, other.m_stop_time);
std::swap(m_elapsed, other.m_elapsed);
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
ML_NODISCARD bool running() const noexcept
{
return m_running;
}
ML_NODISCARD duration elapsed() const noexcept
{
if (m_running)
{
return high_resolution_clock::now() - m_start_time;
}
else
{
return m_elapsed;
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
timer & start() noexcept
{
return m_running ? (*this) : this->restart();
}
timer & restart() noexcept
{
m_running = true;
m_start_time = m_stop_time = high_resolution_clock::now();
m_elapsed = {};
return (*this);
}
timer & stop() noexcept
{
if (!m_running) { return (*this); }
m_running = false;
m_elapsed = ((m_stop_time = high_resolution_clock::now()) - m_start_time);
return (*this);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
private:
bool m_running; //
time_point m_start_time; //
time_point m_stop_time; //
duration m_elapsed; //
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
};
}
#endif // !_ML_TIMER_HPP_
| 20.726496
| 83
| 0.514639
|
Gurman8r
|
fca972212583242a52954757673e9472f6112631
| 1,592
|
cpp
|
C++
|
tests/test035.cpp
|
rpnx-net/rntcsv
|
dedb3463602dbefd10fb6e4c24673a304959616c
|
[
"BSD-3-Clause"
] | null | null | null |
tests/test035.cpp
|
rpnx-net/rntcsv
|
dedb3463602dbefd10fb6e4c24673a304959616c
|
[
"BSD-3-Clause"
] | null | null | null |
tests/test035.cpp
|
rpnx-net/rntcsv
|
dedb3463602dbefd10fb6e4c24673a304959616c
|
[
"BSD-3-Clause"
] | null | null | null |
// test035.cpp - custom conversion
#include <iomanip>
#include <math.h>
#include <rntcsv.h>
#include "unittest.h"
// Data requested as ints to be converted to fixed-point two decimal numbers
namespace rntcsv
{
template<>
void converter<int>::to_value(const std::string& pStr, int& pVal) const
{
pVal = static_cast<int>(roundf(100.0f * std::stof(pStr)));
}
template<>
void converter<int>::to_string(const int& pVal, std::string& pStr) const
{
std::ostringstream out;
out << std::fixed << std::setprecision(2) << static_cast<float>(pVal) / 100.0f;
pStr = out.str();
}
}
int main()
{
int rv = 0;
std::string csv =
"1,10,100,1000\n"
"0.1,0.01,0.001,0.006\n"
;
std::string path = unittest::TempPath();
unittest::WriteFile(path, csv);
try
{
rntcsv::document doc(path, rntcsv::label_parameters(-1, -1));
unittest::ExpectEqual(int, doc.cell<int>(0, 0), 100);
unittest::ExpectEqual(int, doc.cell<int>(1, 0), 1000);
unittest::ExpectEqual(int, doc.cell<int>(2, 0), 10000);
unittest::ExpectEqual(int, doc.cell<int>(3, 0), 100000);
unittest::ExpectEqual(int, doc.cell<int>(0, 1), 10);
unittest::ExpectEqual(int, doc.cell<int>(1, 1), 1);
unittest::ExpectEqual(int, doc.cell<int>(2, 1), 0);
unittest::ExpectEqual(int, doc.cell<int>(3, 1), 1);
doc.set_cell<int>(0, 0, 12345);
unittest::ExpectEqual(std::string, doc.cell<std::string>(0, 0), "123.45");
}
catch (const std::exception& ex)
{
std::cout << ex.what() << std::endl;
rv = 1;
}
unittest::DeleteFile(path);
return rv;
}
| 24.492308
| 83
| 0.627513
|
rpnx-net
|
fcac94d26e672483b77aac90086fef421c03c832
| 1,308
|
cpp
|
C++
|
c535.cpp
|
puyuliao/ZJ-d879
|
bead48e0a500f21bc78f745992f137706d15abf8
|
[
"MIT"
] | null | null | null |
c535.cpp
|
puyuliao/ZJ-d879
|
bead48e0a500f21bc78f745992f137706d15abf8
|
[
"MIT"
] | null | null | null |
c535.cpp
|
puyuliao/ZJ-d879
|
bead48e0a500f21bc78f745992f137706d15abf8
|
[
"MIT"
] | null | null | null |
#include<bits/stdc++.h>
#include<stdint.h>
using namespace std;
#define IOS {cin.tie(0);ios_base::sync_with_stdio(false);}
#define N 1000000
#pragma GCC target("avx")
#define ttry 200
int seed;
struct point{
int x,y;
double mx,my;
point(int _x,int _y):x(_x),y(_y),mx(_x * cos(seed) - _y * sin(seed)),my(-_x * sin(seed) + _y * cos(seed)){}
bool operator <(const point &b)const{
return mx < b.mx || mx == b.mx && my < b.my;
}
};
set<point> s;
int main()
{
IOS;
srand(time(NULL));
seed = rand();
int n,last_ans = 0,c,x,y;
cin >> n;
for(int i=0;i<n;i++){
cin >> c >> x >> y;
x = (last_ans + x) % 100000000 + 1;
y = (last_ans + y) % 100000000 + 1;
if(c == 1) s.insert(point(x,y));
else{
int ans = 2147483647;
point p = point(x,y);
auto it = s.lower_bound(p);
int cnt = 0;
for(auto i = it; i != s.end() && cnt < ttry; i++,cnt++) ans = min(ans,abs(i->x-p.x) + abs(i->y-p.y));
cnt = 0;
if(it != s.begin()) for(auto i = --it; cnt < ttry; i--,cnt++) {
ans = min(ans,abs(i->x-p.x) + abs(i->y-p.y));
if(i == s.begin()) break;
}
if(ans == 2147483647) ans = 0;
last_ans = ans;
cout << ans << '\n';
}
//for(auto i : s) cout << '(' << i.mx << ',' << i.my << ')' << ' '; cout << '\n';
}
return 0;
}
| 25.153846
| 109
| 0.506881
|
puyuliao
|
fcae18ee50cec18cbf26660dcefac1f022977bf3
| 3,308
|
cpp
|
C++
|
Game/Engine/WorldPhysics/GravityStrategy.cpp
|
LukasKalinski/Gravity-Game
|
5c817e3ae7658e5e42a8cff760a57380eb11fe3e
|
[
"MIT"
] | null | null | null |
Game/Engine/WorldPhysics/GravityStrategy.cpp
|
LukasKalinski/Gravity-Game
|
5c817e3ae7658e5e42a8cff760a57380eb11fe3e
|
[
"MIT"
] | null | null | null |
Game/Engine/WorldPhysics/GravityStrategy.cpp
|
LukasKalinski/Gravity-Game
|
5c817e3ae7658e5e42a8cff760a57380eb11fe3e
|
[
"MIT"
] | null | null | null |
///////////////////////////////////////////////////////////
// GravityStrategy.cpp
// Implementation of the Class GravityStrategy
// Created on: 28-mar-2008 10:27:34
// Original author: Lukas Kalinski
///////////////////////////////////////////////////////////
#include <iostream>
#include "GravityStrategy.h"
GravityStrategy::GravityStrategy() {
}
GravityStrategy::~GravityStrategy() {
}
//
//GravityStrategy::GravityStrategy(const GravityStrategy& strategy) {
// throw std::exception("GravityStrategy.cpp: Copy constructor called.");
//}
/**
* Does no affection. This function only exists to catch all cases which the other
* affect function(s) can't handle.
*/
void GravityStrategy::affect(const WorldObject& wo1, const WorldObject& wo2) {
throw std::exception("GravityStrategy::affect() Catch all function called.");
}
/**
* Affects a movable object with a planet's gravity, in proportion to the object's
* mass.
*/
void GravityStrategy::affect(MovableObject& mwo, const Planet& swo) {
// Vector from planet to object.
Vector2d mwo_to_swo = swo.getPosition() - mwo.getPosition();
// Distance between centers of object and planet.
float distance = mwo_to_swo.getLength();
// Unit vector pointing at planet from MovableObject.
Vector2d planet_to_obj = mwo_to_swo/distance;
// Note to Jesper: Should it be this way?
// The gravity strategy seems to mess up when mass is 0...
if (mwo.getMass() == 0) {
return;
}
if(distance < 15.0)
return;
// std::cout << "Planet to obj: " << planet_to_obj.getX() << " " << planet_to_obj.getY() << std::endl;
float G = 10.0f;
// Value of force.
float force = (G * mwo.getMass() * swo.getMass()) / (distance*distance);
// Complete force with direction.
Vector2d forcedir = planet_to_obj * force;
// Amount of acceleration.
Vector2d acc = forcedir / mwo.getMass();
// Accelerate movableobject.
Vector2d mov(mwo.getMovement());
mov = mov + acc;
mwo.setMovement(mov);
}
/**
* Affects all movable world objects found in the world according to their gravity
* fields.
*/
void GravityStrategy::applyWorldStrategy(World& world) {
// Movable objects
typedef WorldObjectsManager::movable_objects_t movable_objects_t;
movable_objects_t mov_objects =
world.getWorldObjectsManager().getMovableObjects();
// All objects.
typedef WorldObjectsManager::world_objects_t world_objects_t;
world_objects_t wobjects =
world.getWorldObjectsManager().getWorldObjects();
// Build a temporary array with pointers to all planets.
std::vector<Planet*> planets;
for(world_objects_t::iterator it = wobjects.begin();
it != wobjects.end();
++it)
{
if(Planet* planet = dynamic_cast<Planet*> (*it)) {
planets.push_back(planet);
}
}
// Go through all movable objects and affect them by gravity.
for(std::vector<Planet*>::iterator it = planets.begin();
it!=planets.end();
++it) {
for(movable_objects_t::iterator mov_it = mov_objects.begin();
mov_it!=mov_objects.end();
++mov_it) {
affect(**mov_it, **it);
}
}
}
/**
* Clones the gravity strategy, returning the clone.
*/
GravityStrategy* GravityStrategy::clone() const {
return new GravityStrategy(*this);
}
| 26.677419
| 104
| 0.657497
|
LukasKalinski
|
fcb6211ebe0b44a7f024789d671a8f512ba0b613
| 1,619
|
cpp
|
C++
|
Behavioral/ChainOfResponsibility.cpp
|
ivan-volnov/DesignPatterns
|
fbbf8ec8a72d5b9c5d0563c7162feccdd3a6f34e
|
[
"MIT"
] | null | null | null |
Behavioral/ChainOfResponsibility.cpp
|
ivan-volnov/DesignPatterns
|
fbbf8ec8a72d5b9c5d0563c7162feccdd3a6f34e
|
[
"MIT"
] | null | null | null |
Behavioral/ChainOfResponsibility.cpp
|
ivan-volnov/DesignPatterns
|
fbbf8ec8a72d5b9c5d0563c7162feccdd3a6f34e
|
[
"MIT"
] | null | null | null |
#include <iostream>
using namespace std;
typedef enum {READ, WRITE, EXECUTE, UNKNOWN} Type;
class IHandler
{
public:
virtual void handle(Type arg)
{
}
protected:
IHandler *_handler;
IHandler(IHandler *handler) :
_handler(handler)
{
}
};
class IReadHander : public IHandler
{
public:
IReadHander(IHandler *handler) :
IHandler(handler)
{
}
void handle(Type arg)
{
if (arg == READ) {
cout << "This Request is handled by IReadHander" << endl;
} else if (IHandler::_handler != 0) {
IHandler::_handler->handle(arg);
}
}
};
class IWriteHander : public IHandler
{
public:
IWriteHander(IHandler *handler) :
IHandler(handler)
{
}
void handle(Type arg)
{
if (arg == WRITE) {
cout << "This Request is handled by IWriteHander" << endl;
} else if (IHandler::_handler != 0) {
IHandler::_handler->handle(arg);
}
}
};
class IExecHander : public IHandler
{
public:
IExecHander(IHandler *handler) :
IHandler(handler)
{
}
void handle(Type arg)
{
if (arg == EXECUTE) {
cout << "This Request is handled by IExecHander" << endl;
} else if (IHandler::_handler != 0) {
IHandler::_handler->handle(arg);
}
}
};
void ChainOfResponsibilityTest()
{
IHandler *readHandler = new IReadHander(0);
IHandler *writeHandler = new IWriteHander(readHandler);
IHandler *execHandler = new IExecHander(writeHandler);
execHandler->handle(UNKNOWN);
}
| 17.408602
| 70
| 0.578752
|
ivan-volnov
|
fcb69abd15338bf8287bd277f4df3dc10b2529f3
| 1,487
|
cpp
|
C++
|
reactor/Reactors.cpp
|
ty7swkr/abc
|
3986908b0b0667a8c7f5f5fb6d6241a96a32b1e9
|
[
"MIT"
] | 2
|
2021-08-15T03:42:52.000Z
|
2021-12-02T08:22:08.000Z
|
reactor/Reactors.cpp
|
ty7swkr/open_reactor
|
3986908b0b0667a8c7f5f5fb6d6241a96a32b1e9
|
[
"MIT"
] | null | null | null |
reactor/Reactors.cpp
|
ty7swkr/open_reactor
|
3986908b0b0667a8c7f5f5fb6d6241a96a32b1e9
|
[
"MIT"
] | null | null | null |
/*
* Reactors.cpp
*
* Created on: 2020. 2. 12.
* Author: tys
*/
#include "Reactors.h"
using namespace reactor;
bool
Reactors::init(const size_t &thread_num,
const size_t &max_clients_per_reactor,
const size_t &max_events_per_reactor,
ReactorHandlerFactory *factory)
{
for (size_t index = 0; index < thread_num; ++index)
{
ReactorThread *reactor_thread = new ReactorThread;
reactor_thread->reactor.init(max_clients_per_reactor,
max_events_per_reactor,
factory);
reactor_threads_.push_back(reactor_thread);
reactors_ .push_back(&reactor_thread->reactor);
}
return true;
}
bool
Reactors::init(const size_t &thread_num,
ReactorHandlerFactory *factory,
const size_t &max_clients_per_reactor,
const size_t &max_events_per_reactor)
{
return this->init(thread_num, max_clients_per_reactor, max_events_per_reactor, factory);
}
bool
Reactors::start()
{
for (ReactorThread *reactor_thread : reactor_threads_)
reactor_thread->start();
return true;
}
void
Reactors::stop()
{
for (ReactorThread *reactor_thread : reactor_threads_)
reactor_thread->stop();
}
size_t
Reactors::handler_count() const
{
size_t count = 0;
for (Reactor *reactor : reactors_)
count += reactor->handler_count();
return count;
}
| 22.19403
| 90
| 0.62811
|
ty7swkr
|
fcb8560557372a3312b85885f1b00a1dc8dfa869
| 6,568
|
cpp
|
C++
|
unit_tests/test_classes/pull_stub_param.cpp
|
17605699101/oolua
|
09df5d184f263a3e5538e869eb94cdc6fecd8707
|
[
"MIT"
] | 1
|
2018-01-25T03:14:11.000Z
|
2018-01-25T03:14:11.000Z
|
unit_tests/test_classes/pull_stub_param.cpp
|
17605699101/oolua
|
09df5d184f263a3e5538e869eb94cdc6fecd8707
|
[
"MIT"
] | null | null | null |
unit_tests/test_classes/pull_stub_param.cpp
|
17605699101/oolua
|
09df5d184f263a3e5538e869eb94cdc6fecd8707
|
[
"MIT"
] | null | null | null |
# include "oolua_tests_pch.h"
# include "common_cppunit_headers.h"
# include "gmock/gmock.h"
# include "oolua.h"
# include "expose_pulls_stub_param.h"
# include <string>
//We are testing that a proxy class method can correctly pull a stub
//and can convert to the required type for the method which it is proxying.
class Pulls_stub_param : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(Pulls_stub_param);
CPPUNIT_TEST(ref_noneConstantPointerPassed_CalledOnce);
CPPUNIT_TEST(refConst_noneConstantPointerPassed_CalledOnce);
CPPUNIT_TEST(refConst_ConstantPointerPassed_CalledOnce);
CPPUNIT_TEST(ptr_noneConstantPointerPassed_CalledOnce);
CPPUNIT_TEST(ptrConst_noneConstantPointerPassed_CalledOnce);
CPPUNIT_TEST(ptrConst_ConstantPointerPassed_CalledOnce);
CPPUNIT_TEST(refPtrConst_noneConstantPointerPassed_CalledOnce);
CPPUNIT_TEST(refPtrConst_ConstantPointerPassed_CalledOnce);
CPPUNIT_TEST(refConstPtrConst_noneConstantPointerPassed_CalledOnce);
CPPUNIT_TEST(refConstPtrConst_ConstantPointerPassed_CalledOnce);
CPPUNIT_TEST(constPtrConst_noneConstantPointerPassed_CalledOnce);
CPPUNIT_TEST(constPtrConst_ConstantPointerPassed_CalledOnce);
#if OOLUA_STORE_LAST_ERROR == 1
CPPUNIT_TEST(ref_ConstantPointerPassed_callReturnsFalse);
CPPUNIT_TEST(ptr_ConstantPointerPassed_callReturnsFalse);
#endif
#if OOLUA_USE_EXCEPTIONS == 1
CPPUNIT_TEST(ref_ConstantPointerPassed_throwsRuntimeError);
CPPUNIT_TEST(ptr_ConstantPointerPassed_throwsRuntimeError);
#endif
CPPUNIT_TEST_SUITE_END();
struct Pull_stub_helper
{
Pull_stub_helper()
:mock(),instance(&mock),stub()
{}
Stub1 const* ptr_const_stub()
{
return &stub;
}
Stub1* ptr_stub()
{
return &stub;
}
Mock_pulls_stub mock;
Pulls_stub* instance;
Stub1 stub;
LVD_NOCOPY(Pull_stub_helper)
};
OOLUA::Script * m_lua;
Pull_stub_helper * m_helper;
//Generates a Lua function that when called and passed an class instance and stub
//will call the method (func_name) on the instance.
//returns the Lua function name which is generated.
std::string generate_and_run_chunk_for_the_function_named(std::string const& func_name)
{
std::string lua_func_name("func");
std::string chunk ( lua_func_name + std::string(" = function(obj,stub)\n")
+std::string("obj:") + func_name + std::string("(stub)\n")
+std::string("end\n"));
m_lua->run_chunk(chunk);
return lua_func_name;
}
bool generate_and_call_func_passing_const_ptr(std::string const& func_name)
{
std::string lua_func_name = generate_and_run_chunk_for_the_function_named(func_name);
return m_lua->call(lua_func_name
,m_helper->instance
,m_helper->ptr_const_stub());
}
bool generate_and_call_func_passing_none_const_ptr(std::string const& func_name)
{
std::string lua_func_name = generate_and_run_chunk_for_the_function_named(func_name);
return m_lua->call(lua_func_name
,m_helper->instance
,m_helper->ptr_stub());
}
public:
Pulls_stub_param():m_lua(0),m_helper(0){}
LVD_NOCOPY(Pulls_stub_param)
void setUp()
{
m_lua = new OOLUA::Script;
m_lua->register_class<Pulls_stub>();
m_lua->register_class<Stub1>();
m_helper = new Pull_stub_helper;
}
void tearDown()
{
delete m_helper;
delete m_lua;
}
void ref_noneConstantPointerPassed_CalledOnce()
{
EXPECT_CALL(m_helper->mock,ref(::testing::Ref(m_helper->stub)))
.Times(1);
generate_and_call_func_passing_none_const_ptr("ref");
}
void refConst_noneConstantPointerPassed_CalledOnce()
{
EXPECT_CALL(m_helper->mock
,ref_const(::testing::Ref(m_helper->stub)))
.Times(1);
generate_and_call_func_passing_none_const_ptr("ref_const");
}
void refConst_ConstantPointerPassed_CalledOnce()
{
EXPECT_CALL(m_helper->mock,ref_const(::testing::Ref(m_helper->stub)))
.Times(1);
generate_and_call_func_passing_const_ptr("ref_const");
}
void ptr_noneConstantPointerPassed_CalledOnce()
{
EXPECT_CALL(m_helper->mock,ptr(::testing::Eq( m_helper->ptr_stub() )))
.Times(1);
generate_and_call_func_passing_none_const_ptr("ptr");
}
void ptrConst_noneConstantPointerPassed_CalledOnce()
{
EXPECT_CALL(m_helper->mock,ptr_const(::testing::Eq( m_helper->ptr_stub() )))
.Times(1);
generate_and_call_func_passing_none_const_ptr("ptr_const");
}
void ptrConst_ConstantPointerPassed_CalledOnce()
{
EXPECT_CALL(m_helper->mock,ptr_const(::testing::Eq(m_helper->ptr_stub())))
.Times(1);
generate_and_call_func_passing_const_ptr("ptr_const");
}
void refPtrConst_noneConstantPointerPassed_CalledOnce()
{
EXPECT_CALL(m_helper->mock,ref_ptr_const(::testing::Eq(m_helper->ptr_stub())))
.Times(1);
generate_and_call_func_passing_none_const_ptr("ref_ptr_const");
}
void refPtrConst_ConstantPointerPassed_CalledOnce()
{
EXPECT_CALL(m_helper->mock,ref_ptr_const(::testing::Eq(m_helper->ptr_stub())))
.Times(1);
generate_and_call_func_passing_const_ptr("ref_ptr_const");
}
void refConstPtrConst_noneConstantPointerPassed_CalledOnce()
{
EXPECT_CALL(m_helper->mock,ref_const_ptr_const(::testing::Eq(m_helper->ptr_stub())))
.Times(1);
generate_and_call_func_passing_none_const_ptr("ref_const_ptr_const");
}
void refConstPtrConst_ConstantPointerPassed_CalledOnce()
{
EXPECT_CALL(m_helper->mock,ref_const_ptr_const(::testing::Eq(m_helper->ptr_stub())))
.Times(1);
generate_and_call_func_passing_const_ptr("ref_const_ptr_const");
}
void constPtrConst_noneConstantPointerPassed_CalledOnce()
{
EXPECT_CALL(m_helper->mock,const_ptr_const(::testing::Eq(m_helper->ptr_stub())))
.Times(1);
generate_and_call_func_passing_none_const_ptr("const_ptr_const");
}
void constPtrConst_ConstantPointerPassed_CalledOnce()
{
EXPECT_CALL(m_helper->mock,const_ptr_const(::testing::Eq(m_helper->ptr_stub())))
.Times(1);
generate_and_call_func_passing_const_ptr("const_ptr_const");
}
#if OOLUA_STORE_LAST_ERROR == 1
void ref_ConstantPointerPassed_callReturnsFalse()
{
CPPUNIT_ASSERT_EQUAL(false,generate_and_call_func_passing_const_ptr("ref"));
}
void ptr_ConstantPointerPassed_callReturnsFalse()
{
CPPUNIT_ASSERT_EQUAL(false,generate_and_call_func_passing_const_ptr("ptr"));
}
#endif
#if OOLUA_USE_EXCEPTIONS == 1
void ref_ConstantPointerPassed_throwsRuntimeError()
{
CPPUNIT_ASSERT_THROW( (generate_and_call_func_passing_const_ptr("ref")), OOLUA::Runtime_error);
}
void ptr_ConstantPointerPassed_throwsRuntimeError()
{
CPPUNIT_ASSERT_THROW( (generate_and_call_func_passing_const_ptr("ptr")), OOLUA::Runtime_error);
}
#endif
};
CPPUNIT_TEST_SUITE_REGISTRATION( Pulls_stub_param );
| 31.27619
| 97
| 0.784866
|
17605699101
|
fcba7fcef9dce7f98b69305ea5a0366ab2cbddcf
| 260
|
cpp
|
C++
|
Olamundo/operador_ternario/main.cpp
|
tosantos1/LIP
|
7dbc045afa02729f4e2f2f1d3b29baebf5be72ad
|
[
"MIT"
] | null | null | null |
Olamundo/operador_ternario/main.cpp
|
tosantos1/LIP
|
7dbc045afa02729f4e2f2f1d3b29baebf5be72ad
|
[
"MIT"
] | null | null | null |
Olamundo/operador_ternario/main.cpp
|
tosantos1/LIP
|
7dbc045afa02729f4e2f2f1d3b29baebf5be72ad
|
[
"MIT"
] | null | null | null |
#include <iostream>
using namespace std;
int main()
{
/*int x, y;
cin >> x;
if(x>10)
{
y = x +3;
}else {
y = 3*x;
}*/
int x, y;
cin >> x;
y = x > 10? x+3 : x*3;
cout << "y = " << y << endl;
return 0;
}
| 12.380952
| 28
| 0.373077
|
tosantos1
|
fcc0df8b0f510bd9bafb61dc16890f4f7b40a750
| 232
|
cpp
|
C++
|
API/GameEngineContents/TitleLevel.cpp
|
Bellcow4/Portfolio
|
4f04cbf6d5a3af77eed885de25d51c8a3083dfc7
|
[
"MIT"
] | null | null | null |
API/GameEngineContents/TitleLevel.cpp
|
Bellcow4/Portfolio
|
4f04cbf6d5a3af77eed885de25d51c8a3083dfc7
|
[
"MIT"
] | null | null | null |
API/GameEngineContents/TitleLevel.cpp
|
Bellcow4/Portfolio
|
4f04cbf6d5a3af77eed885de25d51c8a3083dfc7
|
[
"MIT"
] | null | null | null |
#include "TitleLevel.h"
#include "GameEngine/GameEngine.h"
TitleLevel::TitleLevel()
{
}
TitleLevel::~TitleLevel()
{
}
void TitleLevel::Loading()
{
}
void TitleLevel::Update()
{
GameEngine::GlobalEngine().ChangeLevel("Play");
}
| 11.6
| 48
| 0.706897
|
Bellcow4
|
fcc6dc4ae622bccfd365842e47ab231e25e3bef5
| 1,179
|
cpp
|
C++
|
source/slang/slang-ir-ssa-simplification.cpp
|
lucy96chen/slang
|
fc84455d0d1cb6b9396ba869a17d6f8d4b65ecc6
|
[
"MIT"
] | null | null | null |
source/slang/slang-ir-ssa-simplification.cpp
|
lucy96chen/slang
|
fc84455d0d1cb6b9396ba869a17d6f8d4b65ecc6
|
[
"MIT"
] | null | null | null |
source/slang/slang-ir-ssa-simplification.cpp
|
lucy96chen/slang
|
fc84455d0d1cb6b9396ba869a17d6f8d4b65ecc6
|
[
"MIT"
] | null | null | null |
// slang-ir-ssa-simplification.cpp
#include "slang-ir-ssa-simplification.h"
#include "slang-ir.h"
#include "slang-ir-ssa.h"
#include "slang-ir-sccp.h"
#include "slang-ir-dce.h"
#include "slang-ir-simplify-cfg.h"
namespace Slang
{
struct IRModule;
// Run a combination of SSA, SCCP, SimplifyCFG, and DeadCodeElimination pass
// until no more changes are possible.
void simplifyIR(IRModule* module)
{
bool changed = true;
const int kMaxIterations = 8;
int iterationCounter = 0;
while (changed && iterationCounter < kMaxIterations)
{
changed = false;
changed |= applySparseConditionalConstantPropagation(module);
changed |= simplifyCFG(module);
// Note: we disregard the `changed` state from dead code elimination pass since
// SCCP pass could be generating temporarily evaluated constant values and never actually use them.
// DCE will always remove those nearly generated consts and always returns true here.
eliminateDeadCode(module);
changed |= constructSSA(module);
iterationCounter++;
}
}
}
| 31.864865
| 111
| 0.651399
|
lucy96chen
|
fcc96a9e1300c7c8bbce1c731d75565523e9607a
| 9,529
|
cpp
|
C++
|
ToolKit/Controls/Deprecated/XTVC50Helpers.cpp
|
11Zero/DemoBCG
|
8f41d5243899cf1c82990ca9863fb1cb9f76491c
|
[
"MIT"
] | 2
|
2018-03-30T06:40:08.000Z
|
2022-02-23T12:40:13.000Z
|
ToolKit/Controls/Deprecated/XTVC50Helpers.cpp
|
11Zero/DemoBCG
|
8f41d5243899cf1c82990ca9863fb1cb9f76491c
|
[
"MIT"
] | null | null | null |
ToolKit/Controls/Deprecated/XTVC50Helpers.cpp
|
11Zero/DemoBCG
|
8f41d5243899cf1c82990ca9863fb1cb9f76491c
|
[
"MIT"
] | 1
|
2020-08-11T05:48:02.000Z
|
2020-08-11T05:48:02.000Z
|
// XTVC50Helpers.cpp : Visual C++ 5.0 helpers
//
// This file is a part of the XTREME CONTROLS MFC class library.
// (c)1998-2011 Codejock Software, All Rights Reserved.
//
// THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
// RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
// CONSENT OF CODEJOCK SOFTWARE.
//
// THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
// IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
// YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
// SINGLE COMPUTER.
//
// CONTACT INFORMATION:
// support@codejock.com
// http://www.codejock.com
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Common/XTPColorManager.h"
#include "Controls/Util/XTPGlobal.h"
#include "XTVC50Helpers.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#if (_MSC_VER <= 1100) // Using Visual C++ 5.0
/////////////////////////////////////////////////////////////////////////////
// CXTStringHelper
CXTStringHelper::CXTStringHelper()
{
}
CXTStringHelper::CXTStringHelper(CString strIn) : CString(strIn)
{
}
int CXTStringHelper::Find(TCHAR ch) const
{
return CString::Find(ch);
}
int CXTStringHelper::Find(LPCTSTR lpszSub) const
{
return CString::Find(lpszSub);
}
const CString& CXTStringHelper::operator=(const CString& stringSrc)
{
return CString::operator=(stringSrc);
}
const CString& CXTStringHelper::operator=(TCHAR ch)
{
return CString::operator=(ch);
}
const CString& CXTStringHelper::operator=(const unsigned char* psz)
{
return CString::operator=(psz);
}
const CString& CXTStringHelper::operator=(LPCWSTR lpsz)
{
return CString::operator=(lpsz);
}
const CString& CXTStringHelper::operator=(LPCSTR lpsz)
{
return CString::operator=(lpsz);
}
int CXTStringHelper::Find(LPCTSTR lpszSub, int nStart) const
{
ASSERT(AfxIsValidString(lpszSub));
int nLength = GetData()->nDataLength;
if (nStart > nLength)
return -1;
// find first matching substring
LPTSTR lpsz = _tcsstr(m_pchData + nStart, lpszSub);
// return -1 for not found, distance from beginning otherwise
return (lpsz == NULL) ? -1 : (int)(lpsz - m_pchData);
}
int CXTStringHelper::Insert(int nIndex, TCHAR ch)
{
CopyBeforeWrite();
if (nIndex < 0)
nIndex = 0;
int nNewLength = GetData()->nDataLength;
if (nIndex > nNewLength)
nIndex = nNewLength;
nNewLength++;
if (GetData()->nAllocLength < nNewLength)
{
CStringData* pOldData = GetData();
LPTSTR pstr = m_pchData;
AllocBuffer(nNewLength);
memcpy(m_pchData, pstr, (pOldData->nDataLength + 1)*sizeof(TCHAR));
CString::Release(pOldData);
}
// move existing bytes down
memmove(m_pchData + nIndex + 1,
m_pchData + nIndex, (nNewLength-nIndex)*sizeof(TCHAR));
m_pchData[nIndex] = ch;
GetData()->nDataLength = nNewLength;
return nNewLength;
}
int CXTStringHelper::Insert(int nIndex, LPCTSTR pstr)
{
if (nIndex < 0)
nIndex = 0;
int nInsertLength = SafeStrlen(pstr);
int nNewLength = GetData()->nDataLength;
if (nInsertLength > 0)
{
CopyBeforeWrite();
if (nIndex > nNewLength)
nIndex = nNewLength;
nNewLength += nInsertLength;
if (GetData()->nAllocLength < nNewLength)
{
CStringData* pOldData = GetData();
LPTSTR pstr = m_pchData;
AllocBuffer(nNewLength);
memcpy(m_pchData, pstr, (pOldData->nDataLength + 1)*sizeof(TCHAR));
CString::Release(pOldData);
}
// move existing bytes down
memmove(m_pchData + nIndex + nInsertLength,
m_pchData + nIndex,
(nNewLength-nIndex-nInsertLength + 1)*sizeof(TCHAR));
memmove(m_pchData + nIndex,
pstr, nInsertLength*sizeof(TCHAR));
GetData()->nDataLength = nNewLength;
}
return nNewLength;
}
int CXTStringHelper::Remove(TCHAR chRemove)
{
CopyBeforeWrite();
LPTSTR pstrSource = m_pchData;
LPTSTR pstrDest = m_pchData;
LPTSTR pstrEnd = m_pchData + GetData()->nDataLength;
while (pstrSource < pstrEnd)
{
if (*pstrSource != chRemove)
{
*pstrDest = *pstrSource;
pstrDest = _tcsinc(pstrDest);
}
pstrSource = _tcsinc(pstrSource);
}
*pstrDest = '\0';
int nCount = pstrSource - pstrDest;
GetData()->nDataLength -= nCount;
return nCount;
}
int CXTStringHelper::Replace(TCHAR chOld, TCHAR chNew)
{
int nCount = 0;
// short-circuit the nop case
if (chOld != chNew)
{
// otherwise modify each character that matches in the string
CopyBeforeWrite();
LPTSTR psz = m_pchData;
LPTSTR pszEnd = psz + GetData()->nDataLength;
while (psz < pszEnd)
{
// replace instances of the specified character only
if (*psz == chOld)
{
*psz = chNew;
nCount++;
}
psz = _tcsinc(psz);
}
}
return nCount;
}
int CXTStringHelper::Replace(LPCTSTR lpszOld, LPCTSTR lpszNew)
{
// can't have empty or NULL lpszOld
int nSourceLen = SafeStrlen(lpszOld);
if (nSourceLen == 0)
return 0;
int nReplacementLen = SafeStrlen(lpszNew);
// loop once to figure out the size of the result string
int nCount = 0;
LPTSTR lpszStart = m_pchData;
LPTSTR lpszEnd = m_pchData + GetData()->nDataLength;
LPTSTR lpszTarget;
while (lpszStart < lpszEnd)
{
while ((lpszTarget = _tcsstr(lpszStart, lpszOld)) != NULL)
{
nCount++;
lpszStart = lpszTarget + nSourceLen;
}
lpszStart += lstrlen(lpszStart) + 1;
}
// if any changes were made, make them
if (nCount > 0)
{
CopyBeforeWrite();
// if the buffer is too small, just
// allocate a new buffer (slow but sure)
int nOldLength = GetData()->nDataLength;
int nNewLength = nOldLength + (nReplacementLen-nSourceLen)*nCount;
if (GetData()->nAllocLength < nNewLength || GetData()->nRefs > 1)
{
CStringData* pOldData = GetData();
LPTSTR pstr = m_pchData;
AllocBuffer(nNewLength);
memcpy(m_pchData, pstr, pOldData->nDataLength*sizeof(TCHAR));
CString::Release(pOldData);
}
// else, we just do it in-place
lpszStart = m_pchData;
lpszEnd = m_pchData + GetData()->nDataLength;
// loop again to actually do the work
while (lpszStart < lpszEnd)
{
while ((lpszTarget = _tcsstr(lpszStart, lpszOld)) != NULL)
{
int nBalance = nOldLength - (lpszTarget - m_pchData + nSourceLen);
memmove(lpszTarget + nReplacementLen, lpszTarget + nSourceLen,
nBalance * sizeof(TCHAR));
memcpy(lpszTarget, lpszNew, nReplacementLen*sizeof(TCHAR));
lpszStart = lpszTarget + nReplacementLen;
lpszStart[nBalance] = '\0';
nOldLength += (nReplacementLen - nSourceLen);
}
lpszStart += lstrlen(lpszStart) + 1;
}
ASSERT(m_pchData[nNewLength] == '\0');
GetData()->nDataLength = nNewLength;
}
return nCount;
}
int CXTStringHelper::Delete(int nIndex, int nCount)
{
if (nIndex < 0)
nIndex = 0;
int nNewLength = GetData()->nDataLength;
if (nCount > 0 && nIndex < nNewLength)
{
CopyBeforeWrite();
int nBytesToCopy = nNewLength - (nIndex + nCount) + 1;
memcpy(m_pchData + nIndex,
m_pchData + nIndex + nCount, nBytesToCopy * sizeof(TCHAR));
GetData()->nDataLength = nNewLength - nCount;
}
return nNewLength;
}
CXTStringHelper CXTStringHelper::Left(int nCount) const
{
if (nCount < 0)
nCount = 0;
if (nCount >= GetData()->nDataLength)
return *this;
CXTStringHelper dest;
AllocCopy(dest, nCount, 0, 0);
return dest;
}
/////////////////////////////////////////////////////////////////////////////
// CXTHeaderCtrlHelper
int CXTHeaderCtrlHelper::GetItemCount() const
{
ASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, HDM_GETITEMCOUNT, 0, 0L);
}
BOOL CXTHeaderCtrlHelper::GetItemRect(int nIndex, LPRECT lpRect) const
{
ASSERT(::IsWindow(m_hWnd));
ASSERT(lpRect != NULL);
return (BOOL)::SendMessage(m_hWnd, HDM_GETITEMRECT, nIndex, (LPARAM)lpRect);
}
BOOL CXTHeaderCtrlHelper::GetOrderArray(LPINT piArray, int iCount /* = -1 */)
{
ASSERT(::IsWindow(m_hWnd));
// if -1 was passed, find the count ourselves
int nCount = iCount;
if (nCount == -1)
{
nCount = GetItemCount();
if (nCount == -1)
return FALSE;
}
ASSERT(AfxIsValidAddress(piArray, iCount * sizeof(int)));
return (BOOL) ::SendMessage(m_hWnd, HDM_GETORDERARRAY,
(WPARAM) iCount, (LPARAM) piArray);
}
/////////////////////////////////////////////////////////////////////////////
// CXTListCtrlHelper
POSITION CXTListCtrlHelper::GetFirstSelectedItemPosition() const
{
ASSERT(::IsWindow(GetSafeHwnd()));
return (POSITION)(1 + GetNextItem(-1, LVIS_SELECTED));
}
int CXTListCtrlHelper::GetNextSelectedItem(POSITION& pos) const
{
ASSERT(::IsWindow(GetSafeHwnd()));
int nOldPos = (int)pos-1;
pos = (POSITION)(1 + GetNextItem(nOldPos, LVIS_SELECTED));
return nOldPos;
}
/////////////////////////////////////////////////////////////////////////////
// CXTListViewHelper
POSITION CXTListViewHelper::GetFirstSelectedItemPosition() const
{
ASSERT(::IsWindow(GetListCtrl().GetSafeHwnd()));
return (POSITION)(1 + GetListCtrl().GetNextItem(-1, LVIS_SELECTED));
}
int CXTListViewHelper::GetNextSelectedItem(POSITION& pos) const
{
ASSERT(::IsWindow(GetListCtrl().GetSafeHwnd()));
int nOldPos = (int)pos-1;
pos = (POSITION)(1 + GetListCtrl().GetNextItem(nOldPos, LVIS_SELECTED));
return nOldPos;
}
#else
/////////////////////////////////////////////////////////////////////////////
// CXTListViewHelper
POSITION CXTListViewHelper::GetFirstSelectedItemPosition() const
{
return GetListCtrl().GetFirstSelectedItemPosition();
}
int CXTListViewHelper::GetNextSelectedItem(POSITION& pos) const
{
return GetListCtrl().GetNextSelectedItem(pos);
}
#endif//#if (_MSC_VER <= 1100)
| 23.942211
| 77
| 0.673628
|
11Zero
|
fcca148a1e72ffc4c900f388cb19bbf00f850513
| 2,031
|
cpp
|
C++
|
source/tests/widgetzeug-test/ColorGradientInterpolation_test.cpp
|
kateyy/libzeug
|
ffb697721cd8ef7d6e685fd5e2c655d711565634
|
[
"MIT"
] | null | null | null |
source/tests/widgetzeug-test/ColorGradientInterpolation_test.cpp
|
kateyy/libzeug
|
ffb697721cd8ef7d6e685fd5e2c655d711565634
|
[
"MIT"
] | null | null | null |
source/tests/widgetzeug-test/ColorGradientInterpolation_test.cpp
|
kateyy/libzeug
|
ffb697721cd8ef7d6e685fd5e2c655d711565634
|
[
"MIT"
] | null | null | null |
#include <gmock/gmock.h>
#include <QColor>
#include <QDebug>
#include <QList>
#include <widgetzeug/ColorGradient.h>
class ColorGradientInterpolation_test : public testing::Test
{
public:
ColorGradientInterpolation_test()
: m_colors({ { 221, 69, 76 }, { 47, 120, 224 }, { 172, 221, 122 } })
, m_positions({ 0.0, 0.5, 1.0 })
{
widgetzeug::ColorGradientStops stops;
for (int i = 0; i < 3; ++i)
stops << widgetzeug::ColorGradientStop(m_colors[i], m_positions[i]);
m_gradient = widgetzeug::ColorGradient(stops);
}
protected:
const QList<QColor> m_colors;
const QList<qreal> m_positions;
widgetzeug::ColorGradient m_gradient;
};
TEST_F(ColorGradientInterpolation_test, LinearPureColors)
{
m_gradient.setType(widgetzeug::ColorGradientType::Linear);
ASSERT_EQ(m_colors[0], m_gradient.interpolateColor(0.0));
ASSERT_EQ(m_colors[1], m_gradient.interpolateColor(0.5));
ASSERT_EQ(m_colors[2], m_gradient.interpolateColor(1.0));
}
TEST_F(ColorGradientInterpolation_test, DiscretePureColors)
{
m_gradient.setType(widgetzeug::ColorGradientType::Discrete);
m_gradient.setSteps(3u);
ASSERT_EQ(m_colors[0], m_gradient.interpolateColor(0.0));
ASSERT_EQ(m_colors[1], m_gradient.interpolateColor(0.5));
ASSERT_EQ(m_colors[2], m_gradient.interpolateColor(1.0));
}
TEST_F(ColorGradientInterpolation_test, CornsweetPureColors)
{
m_gradient.setType(widgetzeug::ColorGradientType::Cornsweet);
m_gradient.setSteps(3u);
ASSERT_EQ(m_colors[0], m_gradient.interpolateColor(0.5 / 3));
ASSERT_EQ(m_colors[1], m_gradient.interpolateColor(1.5 / 3));
ASSERT_EQ(m_colors[2], m_gradient.interpolateColor(2.5 / 3));
}
/** TODO: This passes right now, but it very fragile.
*/
TEST_F(ColorGradientInterpolation_test, LinearColors)
{
m_gradient.setType(widgetzeug::ColorGradientType::Linear);
ASSERT_EQ(QColor::fromRgbF(109.5 / 255, 170.5 / 255, 173.0 / 255).rgba(), m_gradient.interpolateColor(0.75).rgba());
}
| 31.734375
| 120
| 0.712457
|
kateyy
|
fccd75f39c80811871b905e8b12053b851b46ea9
| 679
|
hpp
|
C++
|
spinok/source/ECS/ComponentList.hpp
|
ckgomes/projects_archive
|
f5282d51dd1539bbefb5c1d12d2ab35ec3d6e548
|
[
"MIT"
] | 1
|
2016-06-04T14:34:23.000Z
|
2016-06-04T14:34:23.000Z
|
spinok/source/ECS/ComponentList.hpp
|
ckgomes/projects_archive
|
f5282d51dd1539bbefb5c1d12d2ab35ec3d6e548
|
[
"MIT"
] | null | null | null |
spinok/source/ECS/ComponentList.hpp
|
ckgomes/projects_archive
|
f5282d51dd1539bbefb5c1d12d2ab35ec3d6e548
|
[
"MIT"
] | null | null | null |
#ifndef COMPONENT_LIST_HPP
#define COMPONENT_LIST_HPP
#include "../Common/Configuration.hpp"
#include "../Common/LanguageExtensions.hpp"
#include "../Components/Transform2DComponent.hpp"
#include "../Components/GraphicsComponent.hpp"
#include "../Components/PhysicsComponent.hpp"
#include "../Components/HullComponent.hpp"
#include "../Components/PlayerComponent.hpp"
struct Components
{
using ListPointer = std::tuple
<
Transform2DComponent*,
PlayerComponent*,
GraphicsComponent*,
PhysicsComponent*,
HullComponent*
>;
static const size_t count = std::tuple_size<ListPointer>::value;
};
#endif // COMPONENT_LIST_HPP
| 22.633333
| 68
| 0.717231
|
ckgomes
|
fcd02c0e3f6d4612631ebefc530193b0951d1904
| 22,033
|
hpp
|
C++
|
include/crab/domains/array_smashing.hpp
|
LinerSu/crab
|
8f3516f4b4765f4a093bb3c3a94ac2daa174130c
|
[
"Apache-2.0"
] | 152
|
2016-02-28T06:04:02.000Z
|
2022-03-30T10:44:56.000Z
|
include/crab/domains/array_smashing.hpp
|
LinerSu/crab
|
8f3516f4b4765f4a093bb3c3a94ac2daa174130c
|
[
"Apache-2.0"
] | 43
|
2017-07-03T06:25:19.000Z
|
2022-03-23T21:09:32.000Z
|
include/crab/domains/array_smashing.hpp
|
LinerSu/crab
|
8f3516f4b4765f4a093bb3c3a94ac2daa174130c
|
[
"Apache-2.0"
] | 28
|
2015-11-22T15:51:52.000Z
|
2022-01-30T00:46:57.000Z
|
/*******************************************************************************
* Array smashing domain
*
* Word-level assumption: for any array load, it assumes that the
* number of read bytes is equal to the number of bytes written during
* the last array write. If this assumption is too strong then use the
* array_adaptive domain.
*
* For efficiency reasons, the domain does not generate a ghost
* variable for the summarized variable (i.e., the variable that
* represents the smashed array). This means that array variables are
* passed to the bool/numerical domain. In particular, the smashing
* domain passes an array variable to the base domain in the following
* operations: assign_bool_cst, assign_bool_var, assign, and expand
* for the modeling of array operations.
******************************************************************************/
#pragma once
#include <crab/domains/abstract_domain.hpp>
#include <crab/domains/abstract_domain_specialized_traits.hpp>
#include <crab/support/debug.hpp>
#include <crab/support/stats.hpp>
namespace crab {
namespace domains {
// Abstract domain to reason about summarized variables. All
// array elements are `smashed` into a single variable.
template <typename BaseNumDomain>
class array_smashing final
: public abstract_domain_api<array_smashing<BaseNumDomain>> {
public:
using number_t = typename BaseNumDomain::number_t;
using varname_t = typename BaseNumDomain::varname_t;
private:
using array_smashing_t = array_smashing<BaseNumDomain>;
using abstract_domain_t = abstract_domain_api<array_smashing_t>;
public:
using typename abstract_domain_t::disjunctive_linear_constraint_system_t;
using typename abstract_domain_t::linear_constraint_system_t;
using typename abstract_domain_t::linear_constraint_t;
using typename abstract_domain_t::linear_expression_t;
using typename abstract_domain_t::reference_constraint_t;
using typename abstract_domain_t::variable_or_constant_t;
using typename abstract_domain_t::variable_t;
using typename abstract_domain_t::variable_vector_t;
using typename abstract_domain_t::variable_or_constant_vector_t;
using base_dom_t = BaseNumDomain;
using interval_t = ikos::interval<number_t>;
private:
using bound_t = ikos::bound<number_t>;
// Contain scalar and summarized array variables.
//
// XXX: We need to be careful in methods such as
// to_linear_constraint_system and
// to_disjunctive_linear_constraint_system. These methods
// convert the internal representation to linear constraints
// which should not contain array variables.
base_dom_t m_base_dom;
array_smashing(base_dom_t &&base_dom) : m_base_dom(std::move(base_dom)) {}
void do_strong_update(base_dom_t &dom, const variable_t &a,
const linear_expression_t &rhs) {
auto ty = a.get_type();
if (ty.is_bool_array()) {
if (rhs.is_constant()) {
if (rhs.constant() >= number_t(1)) {
dom.assign_bool_cst(a, linear_constraint_t::get_true());
} else {
dom.assign_bool_cst(a, linear_constraint_t::get_false());
}
} else if (auto rhs_v = rhs.get_variable()) {
dom.assign_bool_var(a, (*rhs_v), false);
}
} else if (ty.is_integer_array() || ty.is_real_array()) {
dom.assign(a, rhs);
} else {
/* unreachable */
}
}
void do_strong_update(const variable_t &a, const linear_expression_t &rhs) {
do_strong_update(m_base_dom, a, rhs);
}
// We perform the strong update on a copy of *this. Then, we join
// the copy of *this with *this.
void do_weak_update(const variable_t &a, const linear_expression_t &rhs) {
base_dom_t other(m_base_dom);
do_strong_update(other, a, rhs);
m_base_dom |= other;
}
// The internal representation contains variables of array
// type and add them as dimensions in the underlying numerical
// domain. This is OK but it shouldn't be exposed outside via
// linear constraints.
linear_constraint_system_t
filter_noninteger_vars(linear_constraint_system_t &&csts) const {
linear_constraint_system_t res;
for (auto const &cst : csts) {
if (std::all_of(
cst.expression().variables_begin(),
cst.expression().variables_end(), [](const variable_t &v) {
return v.get_type().is_integer() || v.get_type().is_bool();
})) {
res += cst;
}
}
return res;
}
public:
array_smashing() { m_base_dom.set_to_top(); }
array_smashing make_top() const override {
base_dom_t base_dom;
array_smashing out(base_dom.make_top());
return out;
}
array_smashing make_bottom() const override {
base_dom_t base_dom;
array_smashing out(base_dom.make_bottom());
return out;
}
void set_to_top() override {
base_dom_t base_dom;
array_smashing abs(base_dom.make_top());
std::swap(*this, abs);
}
void set_to_bottom() override {
base_dom_t base_dom;
array_smashing abs(base_dom.make_bottom());
std::swap(*this, abs);
}
array_smashing(const array_smashing_t &other) : m_base_dom(other.m_base_dom) {
crab::CrabStats::count(domain_name() + ".count.copy");
crab::ScopedCrabStats __st__(domain_name() + ".copy");
}
array_smashing(const array_smashing_t &&other)
: m_base_dom(std::move(other.m_base_dom)) {}
array_smashing_t &operator=(const array_smashing_t &other) {
crab::CrabStats::count(domain_name() + ".count.copy");
crab::ScopedCrabStats __st__(domain_name() + ".copy");
if (this != &other) {
m_base_dom = other.m_base_dom;
}
return *this;
}
array_smashing_t &operator=(const array_smashing_t &&other) {
if (this != &other) {
m_base_dom = std::move(other.m_base_dom);
}
return *this;
}
bool is_bottom() const override { return (m_base_dom.is_bottom()); }
bool is_top() const override { return (m_base_dom.is_top()); }
bool operator<=(const array_smashing_t &other) const override {
return (m_base_dom <= other.m_base_dom);
}
void operator|=(const array_smashing_t &other) override {
m_base_dom |= other.m_base_dom;
}
array_smashing_t operator|(const array_smashing_t &other) const override {
return array_smashing_t(m_base_dom | other.m_base_dom);
}
array_smashing_t operator&(const array_smashing_t &other) const override {
return array_smashing_t(m_base_dom & other.m_base_dom);
}
array_smashing_t operator||(const array_smashing_t &other) const override {
return array_smashing_t(m_base_dom || other.m_base_dom);
}
array_smashing_t widening_thresholds(
const array_smashing_t &other,
const iterators::thresholds<number_t> &ts) const override {
return array_smashing_t(m_base_dom.widening_thresholds(other.m_base_dom, ts));
}
array_smashing_t operator&&(const array_smashing_t &other) const override {
return array_smashing_t(m_base_dom && other.m_base_dom);
}
virtual interval_t operator[](const variable_t &v) override {
return m_base_dom[v];
}
void forget(const variable_vector_t &variables) override {
m_base_dom.forget(variables);
}
void project(const variable_vector_t &variables) override {
m_base_dom.project(variables);
}
void expand(const variable_t &var, const variable_t &new_var) override {
if (var.get_type() != new_var.get_type()) {
CRAB_ERROR(domain_name(), "::expand must preserve the same type");
}
m_base_dom.expand(var, new_var);
}
void normalize() override { m_base_dom.normalize(); }
void minimize() override { m_base_dom.minimize(); }
void operator+=(const linear_constraint_system_t &csts) override {
m_base_dom += csts;
}
void operator-=(const variable_t &var) override { m_base_dom -= var; }
void assign(const variable_t &x, const linear_expression_t &e) override {
m_base_dom.assign(x, e);
CRAB_LOG("smashing", crab::outs()
<< "apply " << x << " := " << e << *this << "\n";);
}
void apply(arith_operation_t op, const variable_t &x, const variable_t &y,
number_t z) override {
m_base_dom.apply(op, x, y, z);
CRAB_LOG("smashing", crab::outs() << "apply " << x << " := " << y << " "
<< op << " " << z << *this << "\n";);
}
void apply(arith_operation_t op, const variable_t &x, const variable_t &y,
const variable_t &z) override {
m_base_dom.apply(op, x, y, z);
CRAB_LOG("smashing", crab::outs() << "apply " << x << " := " << y << " "
<< op << " " << z << *this << "\n";);
}
void select(const variable_t &lhs, const linear_constraint_t &cond,
const linear_expression_t &e1, const linear_expression_t &e2) override {
m_base_dom.select(lhs, cond, e1, e2);
}
void backward_assign(const variable_t &x, const linear_expression_t &e,
const array_smashing_t &inv) override {
m_base_dom.backward_assign(x, e, inv.m_base_dom);
}
void backward_apply(arith_operation_t op, const variable_t &x,
const variable_t &y, number_t z,
const array_smashing_t &inv) override {
m_base_dom.backward_apply(op, x, y, z, inv.m_base_dom);
}
void backward_apply(arith_operation_t op, const variable_t &x,
const variable_t &y, const variable_t &z,
const array_smashing_t &inv) override {
m_base_dom.backward_apply(op, x, y, z, inv.m_base_dom);
}
void apply(int_conv_operation_t op, const variable_t &dst,
const variable_t &src) override {
m_base_dom.apply(op, dst, src);
}
void apply(bitwise_operation_t op, const variable_t &x, const variable_t &y,
const variable_t &z) override {
m_base_dom.apply(op, x, y, z);
CRAB_LOG("smashing", crab::outs() << "apply " << x << " := " << y << " "
<< op << " " << z << *this << "\n";);
}
void apply(bitwise_operation_t op, const variable_t &x, const variable_t &y,
number_t k) override {
m_base_dom.apply(op, x, y, k);
CRAB_LOG("smashing", crab::outs() << "apply " << x << " := " << y << " "
<< op << " " << k << *this << "\n";);
}
// boolean operators
virtual void assign_bool_cst(const variable_t &lhs,
const linear_constraint_t &rhs) override {
m_base_dom.assign_bool_cst(lhs, rhs);
}
virtual void assign_bool_ref_cst(const variable_t &lhs,
const reference_constraint_t &rhs) override {
m_base_dom.assign_bool_ref_cst(lhs, rhs);
}
virtual void assign_bool_var(const variable_t &lhs, const variable_t &rhs,
bool is_not_rhs) override {
m_base_dom.assign_bool_var(lhs, rhs, is_not_rhs);
}
virtual void apply_binary_bool(bool_operation_t op, const variable_t &x,
const variable_t &y,
const variable_t &z) override {
m_base_dom.apply_binary_bool(op, x, y, z);
}
virtual void assume_bool(const variable_t &v, bool is_negated) override {
m_base_dom.assume_bool(v, is_negated);
}
virtual void select_bool(const variable_t &lhs, const variable_t &cond,
const variable_t &b1, const variable_t &b2) override {
m_base_dom.select_bool(lhs, cond, b1, b2);
}
// backward boolean operators
virtual void backward_assign_bool_cst(const variable_t &lhs,
const linear_constraint_t &rhs,
const array_smashing_t &inv) override {
m_base_dom.backward_assign_bool_cst(lhs, rhs, inv.m_base_dom);
}
virtual void
backward_assign_bool_ref_cst(const variable_t &lhs,
const reference_constraint_t &rhs,
const array_smashing_t &inv) override {
m_base_dom.backward_assign_bool_ref_cst(lhs, rhs, inv.m_base_dom);
}
virtual void backward_assign_bool_var(const variable_t &lhs,
const variable_t &rhs, bool is_not_rhs,
const array_smashing_t &inv) override {
m_base_dom.backward_assign_bool_var(lhs, rhs, is_not_rhs, inv.m_base_dom);
}
virtual void
backward_apply_binary_bool(bool_operation_t op, const variable_t &x,
const variable_t &y, const variable_t &z,
const array_smashing_t &inv) override {
m_base_dom.backward_apply_binary_bool(op, x, y, z, inv.m_base_dom);
}
// array_operators_api
// All the array elements are initialized to val
virtual void array_init(const variable_t &a,
const linear_expression_t & /*elem_size*/,
const linear_expression_t & /*lb_idx*/,
const linear_expression_t & /*ub_idx*/,
const linear_expression_t &val) override {
auto ty = a.get_type();
if (ty.is_bool_array()) {
if (val.is_constant()) {
if (val.constant() >= number_t(1)) {
m_base_dom.assign_bool_cst(a, linear_constraint_t::get_true());
} else {
m_base_dom.assign_bool_cst(a, linear_constraint_t::get_false());
}
} else if (auto var = val.get_variable()) {
m_base_dom.assign_bool_var(a, (*var), false);
}
} else if (ty.is_integer_array() || ty.is_real_array()) {
m_base_dom.assign(a, val);
}
CRAB_LOG("smashing", crab::outs() << "forall i:: " << a << "[i]==" << val
<< " -- " << *this << "\n";);
}
virtual void array_load(const variable_t &lhs, const variable_t &a,
const linear_expression_t & /*elem_size*/,
const linear_expression_t &i) override {
crab::CrabStats::count(domain_name() + ".count.load");
crab::ScopedCrabStats __st__(domain_name() + ".load");
// We need to be careful when assigning a summarized variable a
// into a non-summarized variable lhs. Simply m_base_dom.assign(lhs,a)
// is not sound.
auto &vfac = const_cast<varname_t *>(&(a.name()))->get_var_factory();
variable_t a_prime(vfac.get());
m_base_dom.expand(a, a_prime);
auto ty = a.get_type();
if (ty.is_bool_array()) {
m_base_dom.assign_bool_var(lhs, a_prime, false);
} else if (ty.is_integer_array() || ty.is_real_array()) {
m_base_dom.assign(lhs, a_prime);
}
m_base_dom -= a_prime;
CRAB_LOG("smashing", crab::outs() << lhs << ":=" << a << "[" << i
<< "] -- " << *this << "\n";);
}
virtual void array_store(const variable_t &a,
const linear_expression_t & /*elem_size*/,
const linear_expression_t &i,
const linear_expression_t &val,
bool is_strong_update) override {
crab::CrabStats::count(domain_name() + ".count.store");
crab::ScopedCrabStats __st__(domain_name() + ".store");
if (is_strong_update) {
do_strong_update(a, val);
} else {
do_weak_update(a, val);
}
CRAB_LOG("smashing", crab::outs() << a << "[" << i << "]:=" << val << " -- "
<< *this << "\n";);
}
virtual void array_store_range(const variable_t &a,
const linear_expression_t & /*elem_size*/,
const linear_expression_t &i,
const linear_expression_t &j,
const linear_expression_t &val) override {
crab::CrabStats::count(domain_name() + ".count.store");
crab::ScopedCrabStats __st__(domain_name() + ".store");
do_weak_update(a, val);
CRAB_LOG("smashing", crab::outs() << a << "[" << i << ".." << j << "]:="
<< val << " -- " << *this << "\n";);
}
virtual void array_assign(const variable_t &lhs,
const variable_t &rhs) override {
auto ty = lhs.get_type();
if (ty.is_bool_array()) {
m_base_dom.assign_bool_var(lhs, rhs, false);
} else if (ty.is_integer_array() || ty.is_real_array()) {
m_base_dom.assign(lhs, rhs);
}
}
// backward array operations
void backward_array_init(const variable_t &a,
const linear_expression_t &elem_size,
const linear_expression_t &lb_idx,
const linear_expression_t &ub_idx,
const linear_expression_t &val,
const array_smashing_t &invariant) override {
CRAB_WARN("backward_array_init in array smashing domain not implemented");
}
void backward_array_load(const variable_t &lhs, const variable_t &a,
const linear_expression_t &elem_size,
const linear_expression_t &i,
const array_smashing_t &invariant) override {
CRAB_WARN("backward_array_load in array smashing domain not implemented");
this->operator-=(lhs);
}
void backward_array_store(const variable_t &a,
const linear_expression_t &elem_size,
const linear_expression_t &i,
const linear_expression_t &v, bool is_strong_update,
const array_smashing_t &invariant) override {
CRAB_WARN("backward_array_store in array smashing domain not implemented");
}
void backward_array_store_range(const variable_t &a,
const linear_expression_t &elem_size,
const linear_expression_t &i,
const linear_expression_t &j,
const linear_expression_t &v,
const array_smashing_t &invariant) override {
CRAB_WARN(
"backward_array_store_range in array smashing domain not implemented");
}
void backward_array_assign(const variable_t &lhs, const variable_t &rhs,
const array_smashing_t &invariant) override {
CRAB_WARN("backward_array_assign in array smashing domain not implemented");
}
/// array_smashing is a functor domain that implements all
/// operations except region/reference operations.
REGION_AND_REFERENCE_OPERATIONS_NOT_IMPLEMENTED(array_smashing_t)
linear_constraint_system_t to_linear_constraint_system() const override {
return filter_noninteger_vars(
std::move(m_base_dom.to_linear_constraint_system()));
}
disjunctive_linear_constraint_system_t
to_disjunctive_linear_constraint_system() const override {
disjunctive_linear_constraint_system_t res;
auto disj_csts = m_base_dom.to_disjunctive_linear_constraint_system();
for (auto &csts : disj_csts) {
auto filtered_csts = filter_noninteger_vars(std::move(csts));
if (!filtered_csts.is_true()) {
res += filtered_csts;
}
}
return res;
}
/* Deprecated: do not use them */
base_dom_t &get_content_domain() { return m_base_dom; }
const base_dom_t &get_content_domain() const { return m_base_dom; }
/* begin intrinsics operations */
void intrinsic(std::string name,
const variable_or_constant_vector_t &inputs,
const variable_vector_t &outputs) override {
m_base_dom.intrinsic(name, inputs, outputs);
}
void backward_intrinsic(std::string name,
const variable_or_constant_vector_t &inputs,
const variable_vector_t &outputs,
const array_smashing_t &invariant) override {
m_base_dom.backward_intrinsic(name, inputs, outputs, invariant.m_base_dom);
}
/* end intrinsics operations */
void rename(const variable_vector_t &from,
const variable_vector_t &to) override {
if (from.size() != to.size()) {
CRAB_ERROR(domain_name(), "::rename expects vectors same sizes");
}
for (unsigned i = 0, sz = from.size(); i < sz; ++i) {
if (from[i].get_type() != to[i].get_type()) {
CRAB_ERROR(domain_name(), "::rename must preserve the same type");
}
}
m_base_dom.rename(from, to);
}
void write(crab_os &o) const override { o << m_base_dom; }
std::string domain_name() const override {
std::string name("ArraySmashing(" + m_base_dom.domain_name() + ")");
return name;
}
}; // end array_smashing
template <typename BaseDomain>
struct abstract_domain_traits<array_smashing<BaseDomain>> {
using number_t = typename BaseDomain::number_t;
using varname_t = typename BaseDomain::varname_t;
};
template <typename BaseDom>
class checker_domain_traits<array_smashing<BaseDom>> {
public:
using this_type = array_smashing<BaseDom>;
using linear_constraint_t = typename this_type::linear_constraint_t;
using disjunctive_linear_constraint_system_t =
typename this_type::disjunctive_linear_constraint_system_t;
static bool entail(this_type &lhs,
const disjunctive_linear_constraint_system_t &rhs) {
BaseDom &lhs_dom = lhs.get_content_domain();
return checker_domain_traits<BaseDom>::entail(lhs_dom, rhs);
}
static bool entail(const disjunctive_linear_constraint_system_t &lhs,
this_type &rhs) {
BaseDom &rhs_dom = rhs.get_content_domain();
return checker_domain_traits<BaseDom>::entail(lhs, rhs_dom);
}
static bool entail(this_type &lhs, const linear_constraint_t &rhs) {
BaseDom &lhs_dom = lhs.get_content_domain();
return checker_domain_traits<BaseDom>::entail(lhs_dom, rhs);
}
static bool intersect(this_type &inv, const linear_constraint_t &cst) {
BaseDom &dom = inv.get_content_domain();
return checker_domain_traits<BaseDom>::intersect(dom, cst);
}
};
} // namespace domains
} // namespace crab
| 37.40747
| 82
| 0.636318
|
LinerSu
|
fcd3ff48e589a0c909cd6e1cc6360193765c9cbf
| 10,307
|
hpp
|
C++
|
game_essentials/vector2d.hpp
|
martycagas/particle-game
|
9ee67cc6ff029e94e08ad1b875ba3055ac3fa814
|
[
"MIT"
] | null | null | null |
game_essentials/vector2d.hpp
|
martycagas/particle-game
|
9ee67cc6ff029e94e08ad1b875ba3055ac3fa814
|
[
"MIT"
] | null | null | null |
game_essentials/vector2d.hpp
|
martycagas/particle-game
|
9ee67cc6ff029e94e08ad1b875ba3055ac3fa814
|
[
"MIT"
] | null | null | null |
/**
* @file vector2d.hpp
* @author Martin Cagas
*
* @brief Mathematical 2D vector.
*
* @section ATTRIBUTION
*
* This library contains pieces of code and ideas taken from the Godot Engine's implementation of
* the Vector2 class, licensed under the following license:
*
* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.
* Copyright (c) 2014-2021 Godot Engine contributors.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdlib>
namespace essentials
{
/**
* @class Vector2D
*
* @brief Mathematical 2D vector.
*
* @section DESCRIPTION
*
* A class representing a two-dimensional, mathematical vector with all the features that are
* required for a game, such as adding, multiplying and normalising vectors.
*
* @section USAGE
*
* @code
*
* Vector2D v1(1, 2);
*
* Vector2D v2(3, 4);
*
* Vector2D v3 = v1 + v2;
*
* Vector2D v4 = v1 * v2;
*
* Vector2D v5 = v1 * 2;
*
* Vector2D v6 = 2 * v1;
*
* Vector2D v7 = v1.normalized();
*
* @endcode
*/
struct Vector2D
{
/**
* @brief A set of anonymous unions and structures that hold the vector data.
*/
union
{
struct
{
union
{
double x; ///< The X component. Alternate name for width.
double width; ///< The width component. Alternate name for X.
};
union
{
double y; ///< The Y component. Alternate name for height.
double height; ///< The height component. Alternate name for Y.
};
};
double coord[2] = {0}; ///< Both components as an array.
};
/**
* @brief Empty contructor.
*
* @details
*
* Creates a [0; 0] vector.
*/
Vector2D(void);
/**
* @brief Parametrised constructor.
*
* @param x Value to which to initialise the X axis.
* @param y Value to which to initialise the Y axis.
*/
Vector2D(double x, double y);
/**
* @brief The subscript operator.
*/
inline double &operator[](int index);
/**
* @brief The constant subscript operator.
*/
inline const double &operator[](int index) const;
/**
* @brief The addition operator.
*/
inline Vector2D operator+(const Vector2D &rvalue) const;
/**
* @brief The addition assignment operator.
*/
inline void operator+=(const Vector2D &rvalue);
/**
* @brief The subtraction operator.
*/
inline Vector2D operator-(const Vector2D &rvalue) const;
/**
* @brief The subtraction assignment operator.
*/
inline void operator-=(const Vector2D &rvalue);
/**
* @brief The vector multiplication operator.
*/
inline Vector2D operator*(const Vector2D &rvalue) const;
/**
* @brief The scalar multiplication operator.
*/
inline Vector2D operator*(const double &rvalue) const;
/**
* @brief The vector multiplication assignment operator.
*/
inline void operator*=(const Vector2D &rvalue);
/**
* @brief The scalar multiplication assignment operator.
*/
inline void operator*=(const double &rvalue);
/**
* @brief The vector division operator.
*/
inline Vector2D operator/(const Vector2D &rvalue) const;
/**
* @brief The scalar division operator.
*/
inline Vector2D operator/(const double &rvalue) const;
/**
* @brief The vector division assignment operator.
*/
inline void operator/=(const Vector2D &rvalue);
/**
* @brief The scalar division assignment operator.
*/
inline void operator/=(const double &rvalue);
/**
* @brief The unary negation operator.
*/
inline Vector2D operator-(void) const;
/**
* @brief The "equal to" operator.
*/
inline bool operator==(const Vector2D &rvalue) const;
/**
* @brief The "not equal to" operator.
*/
inline bool operator!=(const Vector2D &rvalue) const;
/**
* @brief The "less than" operator.
*/
inline bool operator<(const Vector2D &rvalue) const;
/**
* @brief The "greater than" operator.
*/
inline bool operator>(const Vector2D &rvalue) const;
/**
* @brief The "less or equal than" operator.
*/
inline bool operator<=(const Vector2D &rvalue) const;
/**
* @brief The "greater or equal than" operator.
*/
inline bool operator>=(const Vector2D &rvalue) const;
/**
* @brief Sets both vector components to the specified value.
*
* @param xy The new value for components.
*/
inline void set_all(double xy);
/**
* @brief Sets both components to form a new unit vector with the given angle.
*
* @param angle Angle in radians.
*/
void set_from_angle(double angle);
/**
* @brief Returns the axis with the lower value.
*
* @return The axis with the lower value.
*/
inline int min_axis(void) const;
/**
* @brief Returns the axis with the greater value.
*
* @return The axis with the greater value.
*/
inline int max_axis(void) const;
/**
* @brief Returns the length of this vector.
*
* @return The length.
*/
double length(void) const;
/**
* @brief Returns the length of this vector, squared.
*
* @return The length.
*/
double length_squared(void) const;
/**
* @brief Returns this vector's angle with respect to the positive X axis, or [1; 0]
* vector, in radians.
*
* @return Angle in radians.
*/
double angle(void) const;
/**
* @brief Normalises the vector in-place.
*/
void normalize(void);
/**
* @brief Returns a new vector that has values of the normalised original vector.
*
* @return New instance of the vector with normalised axes.
*/
Vector2D normalized(void) const;
/**
* @brief Returns the dot product between this vector and other_vector.
*
* @param other_vector The second vector used to calculate the dot product.
*
* @return Dot product.
*/
double dot(const Vector2D &other_vector) const;
/**
* @brief Returns the cross product between this vector and other_vector.
*
* @param other_vector The second vector used to calculate the cross product.
*
* @return Cross product.
*/
double cross(const Vector2D &other_vector) const;
/**
* @brief Returns the angle in radians formed by two rays defined by this vector and the
* other_vector.
*
* @param other_vector Vector used to construct the second ray.
*
* @return Angle in radians.
*/
double angle_formed_by(const Vector2D &other_vector) const;
/**
* @brief Returns the angle in radians between the line connecting the two points and the
* X axis.
*
* @param other_point The second point used to construct the line.
*
* @return Angle in radians.
*/
double angle_to_point(const Point2D &other_point) const;
/**
* @brief Returns the distance to another point.
*
* @param other_point The second point used to calculate distance.
*
* @return Returns the distance.
*/
double distance_to(const Point2D &other_point) const;
/**
* @brief Returns the normalised vector pointing from this point (a) to the other point
* (b). This is equivalent to using (b - a).normalized().
*
* @param other_point The second point used in determining the direction.
*
* @return Returns the normalised vector that is the direction to the other_point.
*/
Vector2D direction_to(const Point2D &other_point) const;
};
/**
* @brief Alternate name for the Vector2D class.
*/
typedef Vector2D Size2D;
/**
* @brief Alternate name for the Vector2D class.
*/
typedef Vector2D Point2D;
} // namespace essentials
| 29.617816
| 99
| 0.551858
|
martycagas
|
fce19e7ea60fd7cf2d81e95963ef82a75ed605ef
| 292
|
cpp
|
C++
|
Chapter06/Exercise39/Exercise39.cpp
|
PacktWorkshops/The-Cpp-Workshop
|
e96d86734d2c277eb3522fc3da8b9a0b765a94f7
|
[
"MIT"
] | 86
|
2020-03-23T20:50:05.000Z
|
2022-02-19T21:41:38.000Z
|
Chapter06/Exercise39/Exercise39.cpp
|
PacktWorkshops/The-Cpp-Workshop
|
e96d86734d2c277eb3522fc3da8b9a0b765a94f7
|
[
"MIT"
] | 7
|
2020-02-14T12:14:39.000Z
|
2021-12-27T09:15:01.000Z
|
Chapter06/Exercise39/Exercise39.cpp
|
PacktWorkshops/The-Cpp-Workshop
|
e96d86734d2c277eb3522fc3da8b9a0b765a94f7
|
[
"MIT"
] | 66
|
2020-03-23T22:25:17.000Z
|
2022-02-01T09:01:41.000Z
|
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char const* cp = "arbitrary null terminated text string";
char* buffer = new char[ strlen(cp)+1 ];
strcpy(buffer, cp);
cout << "buffer = " << buffer << endl;
delete[] buffer;
return 0;
}
| 17.176471
| 61
| 0.60274
|
PacktWorkshops
|
fce2e50ab548e23f98bb759114bb7425811cc1bd
| 9,746
|
cpp
|
C++
|
code/source/texture.cpp
|
DEAKSoftware/KFX
|
8a759d21a651d9f8acbfef2e3d19b1e8580a74b5
|
[
"MIT"
] | null | null | null |
code/source/texture.cpp
|
DEAKSoftware/KFX
|
8a759d21a651d9f8acbfef2e3d19b1e8580a74b5
|
[
"MIT"
] | null | null | null |
code/source/texture.cpp
|
DEAKSoftware/KFX
|
8a759d21a651d9f8acbfef2e3d19b1e8580a74b5
|
[
"MIT"
] | null | null | null |
/*===========================================================================
Texture Object
Dominik Deak
===========================================================================*/
#ifndef ___TEXTURE_CPP___
#define ___TEXTURE_CPP___
/*---------------------------------------------------------------------------
Header files
---------------------------------------------------------------------------*/
#include "array.h"
#include "common.h"
#include "debug.h"
#include "texture.h"
//Namespaces
NAMESPACE_BEGIN(NAMESPACE_PROJECT)
/*---------------------------------------------------------------------------
Constructor.
---------------------------------------------------------------------------*/
Texture::Texture(void)
{
Clear();
}
/*---------------------------------------------------------------------------
Copy constructor, invoked when the current object is instantiated. This
method performs a deep copy of the specified object. The current object is
unitialised, which must be cleared.
---------------------------------------------------------------------------*/
Texture::Texture(const Texture &obj) : MutexHandle()
{
Clear();
Type = obj.Type;
Format = obj.Format;
CompType = obj.CompType;
//Arrays use assginment operators for deep copying
Data = obj.Data;
BitsPerPixel = obj.BitsPerPixel;
BytesPerPixel = obj.BytesPerPixel;
BytesPerLine = obj.BytesPerLine;
Res = obj.Res;
}
/*---------------------------------------------------------------------------
Assignment operator, invoked only when the current object already exist.
This method performs a deep copy of the specified object. The current
object may have allocated data which must be destroyed.
---------------------------------------------------------------------------*/
Texture &Texture::operator = (const Texture &obj)
{
//No action on self assignment
if (this == &obj) {return *this;}
Destroy();
Type = obj.Type;
Format = obj.Format;
CompType = obj.CompType;
//Arrays use assginment operators for deep copying
Data = obj.Data;
BitsPerPixel = obj.BitsPerPixel;
BytesPerPixel = obj.BytesPerPixel;
BytesPerLine = obj.BytesPerLine;
Res = obj.Res;
return *this;
}
/*---------------------------------------------------------------------------
Destructor.
---------------------------------------------------------------------------*/
Texture::~Texture(void)
{
Destroy();
}
/*---------------------------------------------------------------------------
Clears the structure.
---------------------------------------------------------------------------*/
void Texture::Clear(void)
{
Type = Texture::TypeRGB;
Format = Texture::FormatRGB;
CompType = GL_UNSIGNED_BYTE;
BitsPerPixel = 0;
BytesPerPixel = 0;
BytesPerLine = 0;
Res = 0;
Wrap = false;
MinFilter = MinLinMipLin;
MagFilter = MagLinear;
ID = 0;
}
/*---------------------------------------------------------------------------
Destroys the structure.
---------------------------------------------------------------------------*/
void Texture::Destroy(void)
{
if (ID > 0) {glDeleteTextures(1, &ID);}
Data.Destroy();
Clear();
}
/*---------------------------------------------------------------------------
Creates a new texture.
Res : Texture resolution in pixels.
Type : Texture format or type.
---------------------------------------------------------------------------*/
void Texture::Create(const vector2u &Res, TexType Type)
{
Destroy();
Texture::Type = Type;
Texture::Res = Res.Max(1);
switch (Type)
{
case Texture::TypeAlpha :
BitsPerPixel = 8;
Format = FormatAlpha;
CompType = GL_UNSIGNED_BYTE;
break;
case Texture::TypeLum :
BitsPerPixel = 8;
Format = FormatLum;
CompType = GL_UNSIGNED_BYTE;
break;
case Texture::TypeDepth :
BitsPerPixel = 16;
Format = FormatDepth;
CompType = GL_UNSIGNED_SHORT;
break;
case Texture::TypeDisp :
if (!GLEW_ARB_texture_float)
{throw dexception("Current OpenGL context does not support ARB_texture_float extensions.");}
BitsPerPixel = 32;
Format = FormatDisp;
CompType = GL_FLOAT;
break;
case Texture::TypeRGB :
BitsPerPixel = 24;
Format = FormatRGB;
CompType = GL_UNSIGNED_BYTE;
break;
case Texture::TypeRGBA :
BitsPerPixel = 32;
Format = FormatRGBA;
CompType = GL_UNSIGNED_BYTE;
break;
default : throw dexception("Undefined texture type.");
}
BytesPerPixel = Math::ByteSize(BitsPerPixel);
BytesPerLine = BytesPerPixel * Texture::Res.U;
Data.Create(BytesPerLine * Texture::Res.V);
}
/*---------------------------------------------------------------------------
Clears the texture data.
---------------------------------------------------------------------------*/
void Texture::ClearData(void)
{
if (Data.Size() < 1) {return;}
memset(Data.Pointer(), 0, Data.Size());
}
/*---------------------------------------------------------------------------
Sets the minification filter.
---------------------------------------------------------------------------*/
void Texture::SetMinFilter(TexMinFilter Filter)
{
MinFilter = Filter;
}
/*---------------------------------------------------------------------------
Sets the magnification filter.
---------------------------------------------------------------------------*/
void Texture::SetMagFilter(TexMagFilter Filter)
{
MagFilter = Filter;
}
/*---------------------------------------------------------------------------
Sets the texture wrapping attribute.
---------------------------------------------------------------------------*/
void Texture::SetWrap(const vector2b &Wrap)
{
Texture::Wrap = Wrap;
}
/*---------------------------------------------------------------------------
Generates OpenGL texture objects from texture data.
Keep : If set true, the original data will be preserved.
---------------------------------------------------------------------------*/
void Texture::Buffer(bool Keep)
{
if (ID > 0) {glDeleteTextures(1, &ID);}
ID = 0;
if (Data.Size() < 1) {return;}
glEnable(GL_TEXTURE_2D); //Needed for glGenerateMipmap( ) to work on ATI
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &ID);
glBindTexture(GL_TEXTURE_2D, ID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, MinFilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, MagFilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, Wrap.U ? GL_REPEAT : GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, Wrap.V ? GL_REPEAT : GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, Type, Res.U, Res.V, 0, Format, CompType, Data.Pointer());
glGenerateMipmap(GL_TEXTURE_2D);
GLenum Error = glGetError();
if (Error != GL_NO_ERROR) {throw dexception("OpenGL generated an error: %s", Debug::ErrorGL(Error));}
if (!Keep)
{
Data.Destroy();
BitsPerPixel = 0;
BytesPerPixel = 0;
BytesPerLine = 0;
}
debug("Committed texture ID: %d.\n", ID);
}
/*---------------------------------------------------------------------------
Binds a particular texture unit for rendering.
---------------------------------------------------------------------------*/
void Texture::Bind(uiter Unit) const
{
if (ID < 1) {return;}
glActiveTexture(GL_TEXTURE0 + (GLenum)Unit);
glBindTexture(GL_TEXTURE_2D, ID);
}
/*---------------------------------------------------------------------------
Unbinds a particular texture unit after rendering.
---------------------------------------------------------------------------*/
void Texture::Unbind(uiter Unit) const
{
if (ID < 1) {return;}
glActiveTexture(GL_TEXTURE0 + (GLenum)Unit);
glBindTexture(GL_TEXTURE_2D, 0);
}
/*---------------------------------------------------------------------------
Updates the texture object in video memory with the current data.
Assumes Bind( ) was called prior.
---------------------------------------------------------------------------*/
void Texture::Update(void)
{
if (ID < 1 || Data.Size() < 1) {return;}
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, Res.U, Res.V, Format, CompType, Data.Pointer());
glGenerateMipmap(GL_TEXTURE_2D);
}
/*---------------------------------------------------------------------------
Updates the texture object in video memory with data from another texture.
Assumes Bind( ) was called prior.
---------------------------------------------------------------------------*/
void Texture::Update(const Texture &obj)
{
if (ID < 1 || obj.Size() < 1 || Type != obj.DataType()) {return;}
const vector2u TexRes = obj.Resolution();
if (Res.U != TexRes.U || Res.V != TexRes.V) {return;}
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, Res.U, Res.V, Format, CompType, obj.Pointer());
glGenerateMipmap(GL_TEXTURE_2D);
}
//Close namespaces
NAMESPACE_END(NAMESPACE_PROJECT)
//==== End of file ===========================================================
#endif
| 30.939683
| 105
| 0.437
|
DEAKSoftware
|
fce94b344083aade5dcc79cb4a7b91dc88052981
| 2,501
|
cpp
|
C++
|
source/ashes/renderer/GlRenderer/Command/Commands/GlClearColourFboCommand.cpp
|
DragonJoker/Ashes
|
a6ed950b3fd8fb9626c60b4291fbd52ea75ac66e
|
[
"MIT"
] | 227
|
2018-09-17T16:03:35.000Z
|
2022-03-19T02:02:45.000Z
|
source/ashes/renderer/GlRenderer/Command/Commands/GlClearColourFboCommand.cpp
|
DragonJoker/RendererLib
|
0f8ad8edec1b0929ebd10247d3dd0a9ee8f8c91a
|
[
"MIT"
] | 39
|
2018-02-06T22:22:24.000Z
|
2018-08-29T07:11:06.000Z
|
source/ashes/renderer/GlRenderer/Command/Commands/GlClearColourFboCommand.cpp
|
DragonJoker/Ashes
|
a6ed950b3fd8fb9626c60b4291fbd52ea75ac66e
|
[
"MIT"
] | 8
|
2019-05-04T10:33:32.000Z
|
2021-04-05T13:19:27.000Z
|
/*
This file belongs to Ashes.
See LICENSE file in root folder.
*/
#include "Command/Commands/GlClearColourFboCommand.hpp"
#include "Core/GlContextStateStack.hpp"
#include "Core/GlDevice.hpp"
#include "Image/GlImageView.hpp"
#include "Image/GlImage.hpp"
#include "RenderPass/GlFrameBuffer.hpp"
#include "ashesgl_api.hpp"
namespace ashes::gl
{
void buildClearColourFboCommand( VkDevice device
, ContextStateStack & stack
, VkImage image
, VkImageLayout imageLayout
, VkClearColorValue value
, ArrayView< VkImageSubresourceRange const > ranges
, CmdList & list )
{
glLogCommand( list, "ClearColourFboCommand" );
stack.applyDisableBlend( list );
auto & glimage = *get( image );
auto target = GL_TEXTURE_2D;
if ( glimage.getSamples() > VK_SAMPLE_COUNT_1_BIT )
{
target = GL_TEXTURE_2D_MULTISAMPLE;
}
bool hadFbo = stack.hasCurrentFramebuffer();
list.push_back( makeCmd< OpType::eBindDstFramebuffer >( GL_FRAMEBUFFER ) );
auto point = getAttachmentPoint( glimage.getFormatVk() );
for ( auto range : ranges )
{
if ( range.levelCount == RemainingArrayLayers )
{
range.levelCount = ashes::getMaxMipCount( get( image )->getDimensions() );
}
if ( range.layerCount == RemainingArrayLayers )
{
range.layerCount = get( device )->getLimits().maxImageArrayLayers;
}
for ( auto level = range.baseMipLevel; level < range.baseMipLevel + range.levelCount; ++level )
{
if ( get( image )->getArrayLayers() > 1u )
{
for ( auto layer = range.baseArrayLayer; layer < range.baseArrayLayer + range.layerCount; ++layer )
{
list.push_back( makeCmd< OpType::eFramebufferTextureLayer >( GL_FRAMEBUFFER
, point
, get( image )->getInternal()
, level
, layer ) );
list.push_back( makeCmd< OpType::eDrawBuffers >( point ) );
list.push_back( makeCmd< OpType::eClearColour >( value
, 0u ) );
}
}
else
{
list.push_back( makeCmd< OpType::eFramebufferTexture2D >( GL_FRAMEBUFFER
, point
, target
, get( image )->getInternal()
, level ) );
list.push_back( makeCmd< OpType::eDrawBuffers >( point ) );
list.push_back( makeCmd< OpType::eClearColour >( value
, 0u ) );
}
}
}
if ( hadFbo )
{
list.push_back( makeCmd< OpType::eBindFramebuffer >( GL_FRAMEBUFFER
, stack.getCurrentFramebuffer() ) );
}
else
{
list.push_back( makeCmd< OpType::eBindFramebuffer >( GL_FRAMEBUFFER
, nullptr ) );
}
}
}
| 26.892473
| 104
| 0.665734
|
DragonJoker
|
fceedace44d9c566c27510e2eee838460792a711
| 1,025
|
cpp
|
C++
|
src/impl@win32/md_impl@mci.cpp
|
strear/saam
|
4c0b4dd70d30caf606926825daa75ca2dd5ab0b9
|
[
"MIT"
] | null | null | null |
src/impl@win32/md_impl@mci.cpp
|
strear/saam
|
4c0b4dd70d30caf606926825daa75ca2dd5ab0b9
|
[
"MIT"
] | null | null | null |
src/impl@win32/md_impl@mci.cpp
|
strear/saam
|
4c0b4dd70d30caf606926825daa75ca2dd5ab0b9
|
[
"MIT"
] | null | null | null |
#include "../media.hpp"
#undef UNICODE
#include <windows.h>
#pragma comment(lib, "winmm.lib")
using namespace Saam;
namespace {
struct ImplData {
UINT id;
};
}
Media::Media(const char* file) : impl(new ImplData()) {
MCI_OPEN_PARMS openp;
openp.lpstrElementName = file;
mciSendCommand(NULL, MCI_OPEN, MCI_OPEN_ELEMENT, (DWORD_PTR)&openp);
((ImplData*)impl)->id = openp.wDeviceID;
}
Media::~Media() {
mciSendCommand(((ImplData*)impl)->id, MCI_STOP, MCI_WAIT, NULL);
mciSendCommand(((ImplData*)impl)->id, MCI_CLOSE, 0, NULL);
delete (ImplData*)impl;
}
void Media::play() {
MCI_PLAY_PARMS mciPlayParms;
mciSendCommand(((ImplData*)impl)->id, MCI_PLAY, 0,
(DWORD_PTR)&mciPlayParms);
}
void Media::pause() {
MCI_GENERIC_PARMS params;
params.dwCallback = NULL;
mciSendCommand(((ImplData*)impl)->id, MCI_PAUSE,
MCI_WAIT, (DWORD_PTR)¶ms);
}
void Media::reset() {
MCI_PLAY_PARMS mciPlayParms;
mciSendCommand(((ImplData*)impl)->id, MCI_SEEK,
MCI_WAIT | MCI_SEEK_TO_START, (DWORD_PTR)&mciPlayParms);
}
| 22.282609
| 69
| 0.715122
|
strear
|
fcf1cc4b5a9d61d6bd084dc79a0a722c6b985316
| 2,063
|
hpp
|
C++
|
include/nana-source-view/skeleton/text_renderer.hpp
|
5cript/nana-source-view
|
6c9ad0c439e2a4952ff799eb99364e2bdf184b65
|
[
"Unlicense"
] | null | null | null |
include/nana-source-view/skeleton/text_renderer.hpp
|
5cript/nana-source-view
|
6c9ad0c439e2a4952ff799eb99364e2bdf184b65
|
[
"Unlicense"
] | null | null | null |
include/nana-source-view/skeleton/text_renderer.hpp
|
5cript/nana-source-view
|
6c9ad0c439e2a4952ff799eb99364e2bdf184b65
|
[
"Unlicense"
] | null | null | null |
#pragma once
#include <nana-source-view/interfaces/styler.hpp>
#include <nana-source-view/abstractions/store.hpp>
#include <nana/basic_types.hpp>
#include <nana/paint/graphics.hpp>
namespace nana_source_view::skeletons
{
class text_renderer
{
public: // Typedefs
using graph_reference = ::nana::paint::graphics&;
using index_type = data_store::index_type;
public:
text_renderer(data_store const* store);
/**
* Inplace creates a styler.
* Returns a pointer to it, that is NON-OWNING. The renderer owns it.
*/
template <typename T, typename... Args>
T* replace_styler(Args&&... args)
{
auto* sty = new T{store_, std::forward <Args&&> (args)...};
styler_.reset(sty);
return sty;
}
/**
* Retrieves the text styler casted to the given type.
*/
template <typename T>
T* get_styler()
{
return dynamic_cast <T*> (styler_.get());
}
/**
* @brief text_area Sets the text area
* @param rect
*/
void text_area(nana::rectangle const& rect);
/**
* @brief render Renders the visible text into the box.
* @param graph
*/
void render(graph_reference graph);
/**
* @brief update_scroll Set the first line that is scrolled to.
* @param scroll_top_line the top line in the scrolled area.
*/
void update_scroll(index_type scroll_top_line);
/**
* @brief font Sets the base font.
* @param font
*/
void font(nana::paint::font const& font, bool assume_monospace = false);
/**
* @brief font Retrieves the font.
* @return
*/
nana::paint::font font() const;
private:
data_store const* store_;
nana::rectangle area_;
std::unique_ptr <styler> styler_;
nana::paint::font font_;
index_type scroll_top_;
};
}
| 26.113924
| 80
| 0.555986
|
5cript
|
fcff7910d7e166f864e44517d7f7e4accfe4c87f
| 30
|
cpp
|
C++
|
VehicleSirenMute.cpp
|
CakeA/AdvancedVehicleSirens
|
aa1208b8028c69502d442e3aa285350a7aa1eda3
|
[
"MIT"
] | 1
|
2021-08-01T18:07:34.000Z
|
2021-08-01T18:07:34.000Z
|
VehicleSirenMute.cpp
|
CakeA/AdvancedVehicleSirens
|
aa1208b8028c69502d442e3aa285350a7aa1eda3
|
[
"MIT"
] | null | null | null |
VehicleSirenMute.cpp
|
CakeA/AdvancedVehicleSirens
|
aa1208b8028c69502d442e3aa285350a7aa1eda3
|
[
"MIT"
] | 2
|
2021-03-06T12:37:50.000Z
|
2021-04-09T14:03:02.000Z
|
#include "VehicleSirenMute.h"
| 15
| 29
| 0.8
|
CakeA
|
fcffaa6b931735086d60d9182c185b1959656430
| 6,129
|
cpp
|
C++
|
example/src/myWindowClass.cpp
|
arntrk/SplineBasis
|
de142177fd92df8bd6c8b9cb4533ce7f8994f426
|
[
"MIT"
] | null | null | null |
example/src/myWindowClass.cpp
|
arntrk/SplineBasis
|
de142177fd92df8bd6c8b9cb4533ce7f8994f426
|
[
"MIT"
] | null | null | null |
example/src/myWindowClass.cpp
|
arntrk/SplineBasis
|
de142177fd92df8bd6c8b9cb4533ce7f8994f426
|
[
"MIT"
] | null | null | null |
#include "myWindowClass.h"
#include "BSplineBasis.hpp"
#include "KnotVector.h"
#include "OpenGLShader.hpp"
#include <string>
#include <iostream>
struct Point {
GLfloat x;
GLfloat y;
GLfloat z;
};
std::vector<Point> vertices = {
{ -0.5f, -0.5f, 0.0f },
{ 0.5f, -0.5f, 0.0f },
{ 0.0f, 0.5f, 0.0f }
};
void myWindowClass::resize(int width, int height)
{
glViewport(0, 0, width, height);
}
void myWindowClass::keypress(int key, int scancode, int mods)
{
switch (key)
{
case GLFW_KEY_ESCAPE:
closeWindow();
break;
}
}
void myWindowClass::keyrelease(int key, int scancode, int mods)
{
}
/**
* @brief Initializing OpenGL
*
*/
void myWindowClass::initialize()
{
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
/**
* Prepare Vertex shader
*/
GLuint vertexShader = CreateVertexShader();
CompileShader(vertexShader, std::string(vertexShaderSource));
auto successVertex = GetCompileStatus(vertexShader);
if (!successVertex)
{
std::cout << GetCompileErrorMessage(vertexShader) << std::endl;
}
/**
* Prepare Fragment shader
*/
GLuint fragmentShader = CreateFragmentShader();
CompileShader(fragmentShader, std::string(fragmentShaderSource));
auto successFragment = GetCompileStatus(fragmentShader);
if (!successFragment)
{
std::cout << GetCompileErrorMessage(fragmentShader) << std::endl;
}
/**
* Attach shaders and Link Program
*/
if (successVertex && successFragment)
{
shaderProgram = CreateProgram();
AttachShader(shaderProgram, vertexShader);
AttachShader(shaderProgram, fragmentShader);
GLint success = LinkProgram(shaderProgram);
if (!success)
{
std::cout << GetLinkErrorMessage(shaderProgram) << std::endl;
}
}
DeleteShader(vertexShader);
DeleteShader(fragmentShader);
/* knot vector of order 4 in interval [-0.5, 0.5]
* --> { -0.5, -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 0.5 }
*/
cad::KnotVector<float> knots(-0.5, 0.5, 4);
// insert points in the interval [-0.5, 0.5], multiplicity is allowed
knots.insert(-0.375);
knots.insert(-0.25);
//knots.insert(-0.125);
knots.insert(0.0);
//knots.insert(0.125);
knots.insert(0.25);
//knots.insert(0.375);
/**
* Preparing Vertex Arrays with points to rendered (points from knot vector)
*/
std::vector<Point> point;
int order = knots.getOrder();
/* Creating a Point for each knots omiting multiple points at start and end */
for (int i = order-1; i < (knots.size() - order + 1); ++i)
point.push_back({knots[i], 0.0, 0.0});
// storing number of points to be created Vertex Array
pointSize = point.size();
// creating Vertex Array of points in video memory based on point variable
glGenVertexArrays(1, &pointsVAO);
glGenBuffers(1, &pointsVBO);
glBindVertexArray(pointsVAO);
glBindBuffer(GL_ARRAY_BUFFER, pointsVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(Point) * point.size(), &point[0], GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid *)0);
glEnableVertexAttribArray(0);
/**
* Prepare to create Vertex Arrays for each b-spline basis curve
*/
std::vector<std::vector<Point>> basisFunc;
// prepare space for n b-spline basis curves (n = number of knots - order)
basisFunc.resize(knots.size() - order);
// declearing bspline basis function and result vector
cad::BSplineBasis<float> basis;
cad::BSplineBasis<float>::Result result;
int n = 400;
/**
* calculating basis functions for t in [start, stop]
* with a resolution of n values inside the interval
*/
for (int i = 0; i < n; ++i)
{
Point p;
p.z = 0.0;
// calculate next t to evaluate
float t = (knots.getStop() - knots.getStart()) / (n - 1);
p.x = knots[0] + t * i;
// calculate basis functions for t, k gives the index to the first curve to be added to
result = basis(p.x, knots);
// add all results into respective basisfunc variable
/**
* Add result to the basisFunc[result.i+j] --> each is a curve in the interval
* result.i is the first curve to add results to
*/
for (unsigned int j = 0; j < result.basis.size(); ++j)
{
p.y = result.basis[j];
basisFunc[result.i + j].push_back(p);
}
}
// creating Vertex Array for each b-spline basis function in video memory
VBO.resize(basisFunc.size());
VAO.resize(basisFunc.size());
for (unsigned int j = 0; j < basisFunc.size(); ++j)
{
VAO[j] = 0;
VBO[j] = 0;
curveSize.push_back(basisFunc[j].size());
if (basisFunc[j].size() > 1)
{
glGenVertexArrays(1, &VAO[j]);
glGenBuffers(1, &VBO[j]);
glBindVertexArray(VAO[j]);
glBindBuffer(GL_ARRAY_BUFFER, VBO[j]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Point) * basisFunc[j].size(), &basisFunc[j][0], GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid *)0);
glEnableVertexAttribArray(0);
}
}
// ubind vertex array buffers
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
void myWindowClass::render()
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(shaderProgram);
for (unsigned int j = 0; j < VBO.size(); ++j)
{
if (VAO[j] != 0)
{
// draw Vertex Array for each b-spline basis curve
glBindVertexArray(VAO[j]);
glDrawArrays(GL_LINE_STRIP, 0, curveSize[j]);
glBindVertexArray(0);
}
}
// draw Vertex Array of knots
glBindVertexArray(pointsVAO);
glPointSize(6.0f);
glDrawArrays(GL_POINTS, 0, pointSize);
// reset binding to vertex array buffers in video memory
glBindVertexArray(0);
// Base class will swapbuffers
}
| 24.813765
| 113
| 0.606135
|
arntrk
|
1e03c2823579360d4c79623acea7eb9fa691ebc6
| 8,630
|
cpp
|
C++
|
DaggerXL/DaggerXL_Game.cpp
|
kcat/XLEngine
|
0e735ad67fa40632add3872e0cbe5a244689cbe5
|
[
"MIT"
] | 1
|
2021-07-25T15:10:39.000Z
|
2021-07-25T15:10:39.000Z
|
DaggerXL/DaggerXL_Game.cpp
|
kcat/XLEngine
|
0e735ad67fa40632add3872e0cbe5a244689cbe5
|
[
"MIT"
] | null | null | null |
DaggerXL/DaggerXL_Game.cpp
|
kcat/XLEngine
|
0e735ad67fa40632add3872e0cbe5a244689cbe5
|
[
"MIT"
] | null | null | null |
#include "DaggerXL_Game.h"
#include "DaggerXL_Player.h"
#include "Logic_Door.h"
#include "Logic_Obj_Action.h"
#include "Logic_NPC.h"
#include "../fileformats/ArchiveTypes.h"
#include "../fileformats/CellTypes.h"
#include "../ui/Console.h"
//Game instance used for console commands.
DaggerXL_Game *DaggerXL_Game::s_pGame_Console=NULL;
#define NPC_COUNT 32
static DaggerXL_Game *s_pGamePtr = NULL;
DaggerXL_Game::DaggerXL_Game(const XLEngine_Plugin_API *API)
{
m_pAPI = API;
m_nVersionMajor = 0;
m_nVersionMinor = 10;
m_bNPCs_Created = false;
m_pAPI->SetConsoleColor(0.20f, 0.025f, 0.025f, 0.85f);
m_pAPI->SetGameData("DaggerXL", m_nVersionMajor, m_nVersionMinor);
m_pAPI->PrintToConsole("Starting DaggerXL version %d.%03d", m_nVersionMajor, m_nVersionMinor);
//Add game specific console commands.
s_pGame_Console = this;
m_pAPI->RegisterConsoleCmd("g_version", (void *)CC_GameVersion, Console::CTYPE_FUNCTION, "Prints out the name and version of the currently loaded game.", this);
m_pAPI->RegisterScriptFunc("void Game_NewGame()", asFUNCTION(SC_Game_NewGame));
//We only worry about the UI scripts, palettes, color maps and so on if we're running a client.
if ( m_pAPI->IsServer() == false )
{
//Load the WorldMap.
m_pAPI->LoadWorldMap();
//Start the UI script for title screen.
m_pAPI->Start_UI_Script( "DaggerXL/CoreUI.as" );
//load the game palette so that the UI is correct.
LoadPals();
}
m_pAPI->World_CreateTerrain(1000, 500);
//m_Player = xlNew DaggerXL_Player(API);
m_DoorLogic = xlNew Logic_Door(API);
m_ObjActionLogic = xlNew Logic_Obj_Action(API);
m_NPC_Logic = xlNew Logic_NPC(API);
m_Player = xlNew DaggerXL_Player(API);
m_pAPI->World_SetUpdateCallback( DaggerXL_Game::WorldUpdate, NULL );
s_pGamePtr = this;
}
DaggerXL_Game::~DaggerXL_Game(void)
{
if ( m_Player )
{
xlDelete m_Player;
m_Player = NULL;
}
if ( m_DoorLogic )
{
xlDelete m_DoorLogic;
m_DoorLogic = NULL;
}
if ( m_ObjActionLogic )
{
xlDelete m_ObjActionLogic;
m_ObjActionLogic = NULL;
}
if ( m_NPC_Logic )
{
xlDelete m_NPC_Logic;
m_NPC_Logic = NULL;
}
for (uint32_t n=0; n<NPC_COUNT; n++)
{
xlDelete m_NPC_List[n];
}
}
void DaggerXL_Game::FixedUpdate()
{
}
void DaggerXL_Game::VariableUpdate(float dt)
{
}
void DaggerXL_Game::PreRender(float dt)
{
}
void DaggerXL_Game::PostRender(float dt)
{
}
//385 - 394
void DaggerXL_Game::KeyDown(int32_t key)
{
m_Player->KeyDown(key);
//test
if ( key == XL_N )
{
PlaceNPC();
}
}
void DaggerXL_Game::CreateNPCs()
{
if ( m_bNPCs_Created )
return;
for (uint32_t n=0; n<NPC_COUNT; n++)
{
m_NPC_List[n] = new NPC(m_pAPI);
}
m_bNPCs_Created = true;
}
void DaggerXL_Game::WorldUpdate(int32_t newWorldX, int32_t newWorldY, XLEngine_Plugin_API *API, void *pUserData)
{
s_pGamePtr->CreateNPCs();
//first remove NPCs that are out of range.
for (uint32_t n=0; n<NPC_COUNT; n++)
{
NPC *pNPC = s_pGamePtr->m_NPC_List[n];
if ( pNPC->IsEnabled() )
{
int32_t wx, wy;
pNPC->GetWorldPos(s_pGamePtr->m_pAPI, wx, wy);
int32_t dx = wx - newWorldX;
int32_t dy = wy - newWorldY;
if ( dx < 0 ) dx = -dx;
if ( dy < 0 ) dy = -dy;
if ( dx > 1 || dy > 1 )
{
pNPC->Enable(s_pGamePtr->m_pAPI, false);
}
}
}
//then add in new NPCs that are in range.
for (uint32_t n=0; n<NPC_COUNT; n++)
{
NPC *pNPC = s_pGamePtr->m_NPC_List[n];
if ( !pNPC->IsEnabled() )
{
s_pGamePtr->PlaceNPC(n);
}
}
}
bool DaggerXL_Game::PlaceNPC(int32_t newNPC)
{
bool bNPC_Added = false;
//find next inactive NPC.
if ( newNPC == -1 )
{
for (int32_t n=0; n<NPC_COUNT; n++)
{
if ( !m_NPC_List[n]->IsEnabled() )
{
newNPC = n;
break;
}
}
}
if ( newNPC > -1 )
{
int32_t nodeX, nodeY;
float x, y, z;
int32_t sx, sy;
if ( m_pAPI->Pathing_GetRandomNode(nodeX, nodeY, x, y, z, sx, sy) )
{
float fAngle = (float)(rand()%360) * 0.01745329252f;
float dirX = cosf(fAngle);
float dirY = sinf(fAngle);
NPC *pNPC = m_NPC_List[newNPC];
pNPC->Reset(m_pAPI, 385 + (rand()%9), x, y, z, sx, sy, dirX, dirY);
pNPC->Enable(m_pAPI, true);
}
bNPC_Added = true;
}
return bNPC_Added;
}
void DaggerXL_Game::NewGame()
{
//m_pAPI->World_UnloadAllCells();
//m_pAPI->World_LoadCell( CELLTYPE_DAGGERFALL, ARCHIVETYPE_BSA, "", "Privateer's Hold", 0, 0 );
//m_pAPI->World_LoadCell( CELLTYPE_DAGGERFALL, ARCHIVETYPE_BSA, "", "Daggerfall", 0, 0 );
//m_pAPI->World_LoadCell( CELLTYPE_DAGGERFALL, ARCHIVETYPE_BSA, "", "Ruins of Copperhart Orchard", 0, 0 );
//one new game only, set the proper start location.
//m_Player->SetPos( Vector3(120.0f, 430.0f, 8.6f) );
}
/************************
*** Script Commands ***
************************/
void DaggerXL_Game::SC_Game_NewGame()
{
s_pGame_Console->NewGame();
}
/************************
*** Console commands ***
************************/
void DaggerXL_Game::CC_GameVersion(const vector<string>& args, void *pUserData)
{
s_pGame_Console->m_pAPI->PrintToConsole("DaggerXL version %d.%03d", s_pGame_Console->m_nVersionMajor, s_pGame_Console->m_nVersionMinor);
}
/************************
******* Palettes *******
************************/
enum
{
PAL_MAP=0,
PAL_OLDMAP,
PAL_OLDPAL,
PAL_ART,
PAL_DANKBMAP,
PAL_FMAP,
PAL_NIGHTSKY,
PAL_PAL,
PAL_COUNT
};
const char *_apszPalFiles[]=
{
"Map.Pal",
"OldMap.Pal",
"OldPal.Pal"
};
int _Pal_Count = 3;
const char *_apszColFiles[]=
{
"Art_Pal.Col",
"DankBmap.Col",
"Fmap_Pal.Col",
"NightSky.Col",
"Pal.Pal",
};
int _Col_Count = 5;
int _Num_Colormap_Levels = 64;
void DaggerXL_Game::LoadPal(struct Color *pPalData, const char *pszFile)
{
memset(pPalData, 0, sizeof(Color)*256);
if ( m_pAPI->SysFile_Open(pszFile) )
{
uint32_t len = m_pAPI->SysFile_GetLength();
m_pAPI->SysFile_Read(pPalData, 0, len);
m_pAPI->SysFile_Close();
}
}
void DaggerXL_Game::LoadCol(Color *pPalData, const char *pszFile)
{
int sizeOfColor = sizeof(Color);
memset(pPalData, 0, sizeOfColor*256);
if ( m_pAPI->SysFile_Open(pszFile) )
{
uint32_t len = m_pAPI->SysFile_GetLength();
m_pAPI->SysFile_Read(pPalData, sizeof(ColHeader), len-sizeof(ColHeader));
m_pAPI->SysFile_Close();
}
}
void DaggerXL_Game::LoadColormap(uint8_t *pColormap, const char *pszFile)
{
memset(pColormap, 0, 256*_Num_Colormap_Levels);
if ( m_pAPI->SysFile_Open(pszFile) )
{
uint32_t len = m_pAPI->SysFile_GetLength();
m_pAPI->SysFile_Read(pColormap, 0, len);
m_pAPI->SysFile_Close();
}
}
void DaggerXL_Game::ClearColorToColor(uint8_t *pColormap, uint32_t color, uint32_t newColor)
{
for (int32_t nLevel=0; nLevel<_Num_Colormap_Levels; nLevel++)
{
pColormap[ (nLevel<<8)+color ] = pColormap[ (nLevel<<8)+newColor ];
}
}
void DaggerXL_Game::LoadPals()
{
uint8_t *new_pal = xlNew uint8_t[768*3+1];
uint8_t *new_colmap = xlNew uint8_t[256*_Num_Colormap_Levels];
for (int i=0; i<_Pal_Count; i++)
{
LoadPal( (Color *)new_pal, _apszPalFiles[i] );
m_pAPI->SetGamePalette( i, new_pal, 768, 0 );
}
for (int i=0; i<_Col_Count; i++)
{
LoadCol( (Color *)new_pal, _apszColFiles[i] );
m_pAPI->SetGamePalette( i+_Pal_Count, new_pal, 768, 0 );
}
LoadColormap( new_colmap, "SHADE.000" );
ClearColorToColor(new_colmap, 0, 223);
m_pAPI->SetColormap(0, new_colmap, _Num_Colormap_Levels);
LoadColormap( new_colmap, "SHADE.001" );
ClearColorToColor(new_colmap, 0, 223);
m_pAPI->SetColormap(1, new_colmap, _Num_Colormap_Levels);
LoadColormap( new_colmap, "HAZE.000" );
ClearColorToColor(new_colmap, 0, 223);
m_pAPI->SetColormap(2, new_colmap, _Num_Colormap_Levels);
LoadColormap( new_colmap, "HAZE.001" );
ClearColorToColor(new_colmap, 0, 223);
m_pAPI->SetColormap(3, new_colmap, _Num_Colormap_Levels);
xlDelete [] new_pal;
xlDelete [] new_colmap;
}
| 25.382353
| 164
| 0.61066
|
kcat
|
1e06aa92151892bb0f24629466337353225df0dc
| 1,439
|
cpp
|
C++
|
test/tuple_try.cpp
|
mdobrea/effective-fix
|
0dc8013a8470366f99281f191ea4379d59ef761a
|
[
"BSD-2-Clause"
] | 3
|
2016-08-08T08:05:11.000Z
|
2021-02-02T09:11:35.000Z
|
test/tuple_try.cpp
|
mdobrea/effective-fix
|
0dc8013a8470366f99281f191ea4379d59ef761a
|
[
"BSD-2-Clause"
] | null | null | null |
test/tuple_try.cpp
|
mdobrea/effective-fix
|
0dc8013a8470366f99281f191ea4379d59ef761a
|
[
"BSD-2-Clause"
] | 1
|
2019-12-29T22:19:47.000Z
|
2019-12-29T22:19:47.000Z
|
#include <iostream>
#include <utility>
#include <tuple>
struct Currency
{
using ValueType=std::string;
Currency(const ValueType& value_) : value(value_) {}
ValueType value;
};
struct MarketID
{
using ValueType=std::string;
MarketID(const ValueType& value_) : value(value_) {}
ValueType value;
};
struct SecurityID
{
using ValueType=std::string;
SecurityID(const ValueType& value_) : value(value_) {}
ValueType value;
};
struct SecurityIDSource
{
using ValueType=std::string;
SecurityIDSource(const ValueType& value_) : value(value_) {}
ValueType value;
};
using SecurityDefinition=std::tuple<MarketID, SecurityIDSource, SecurityID, Currency>;
template<std::size_t I = 0, typename OstreamT, typename... Tp>
typename std::enable_if<I == sizeof...(Tp), void>::type print(OstreamT& out, const std::tuple<Tp...>& tp)
{
out << "}";
}
template<std::size_t I = 0, typename OstreamT, typename... Tp>
typename std::enable_if<I < sizeof...(Tp), void>::type print(OstreamT& out, const std::tuple<Tp...>& tp)
{
if(I==0)
out << '{';
else
out << ',';
out << std::get<I>(tp).value;
print<I+1, OstreamT, Tp...>(out, tp);
}
template<typename OstreamT, typename... Tp>
OstreamT& operator<<(OstreamT& out, const std::tuple<Tp...>& tp)
{
print(out, tp);
}
int main()
{
SecurityDefinition sd(std::string{"XETR"}, std::string{"4"}, std::string{"DE1234567890"}, std::string{"EUR"});
std::cout << sd << '\n';
return 0;
}
| 22.484375
| 111
| 0.672689
|
mdobrea
|
1e071e9d66c8cd59df672ae8589ff5754624e340
| 2,088
|
cpp
|
C++
|
Solution/PhoenixEngine/Source/Rendering/GFXUtils.cpp
|
rohunb/PhoenixEngine
|
4d21f9000c2e0c553c398785e8cebff1bc190a8c
|
[
"MIT"
] | 2
|
2017-11-09T20:05:36.000Z
|
2018-07-05T00:55:01.000Z
|
Solution/PhoenixEngine/Source/Rendering/GFXUtils.cpp
|
rohunb/PhoenixEngine
|
4d21f9000c2e0c553c398785e8cebff1bc190a8c
|
[
"MIT"
] | null | null | null |
Solution/PhoenixEngine/Source/Rendering/GFXUtils.cpp
|
rohunb/PhoenixEngine
|
4d21f9000c2e0c553c398785e8cebff1bc190a8c
|
[
"MIT"
] | null | null | null |
#include "Stdafx.h"
#include "Rendering/GFXUtils.h"
#include "Config/GFXCompileConfig.h"
#include "Rendering/Debug/GFXDebug.h"
#include "Rendering/GL/GLInterface.h"
#include "Rendering/GL/GLTypes.h"
#ifndef PHOENIX_GFX_COMPILE_CONFIG
# error("Config/GFXCompileConfig.h should be included in this file.")
#endif
using namespace Phoenix;
using namespace Phoenix::GL;
namespace Phoenix
{
namespace EAssetPath
{
const FChar* const Get(const Value AssetPath)
{
static_assert(EAssetPath::Count == 4, "This table needs updating.");
TArray<const FChar* const, EAssetPath::Count> LookUpTable =
{
"../Assets/Fonts/",
"../Assets/Models/",
"../Assets/Shaders/",
"../Assets/Textures/"
};
const FChar* const Result = LookUpTable[AssetPath];
return Result;
}
}
namespace GFXUtils
{
FString GetFontKey(const FChar* const FileName, const FontPixelSizeT PixelSize)
{
FStringStream SS;
SS << FileName << PixelSize;
const FString FontKey = SS.str();
return FontKey;
}
void LogOpenGLInfo()
{
#if PHOENIX_GFX_DISPLAY_OPEN_GL_INFO
F_GLDisplayErrors();
const SizeT ArraySize = 4;
const TArray<const GLubyte*, ArraySize> GLInfoArray =
{
GL::GetString(EGLInfo::Vendor),
GL::GetString(EGLInfo::Renderer),
GL::GetString(EGLInfo::Version),
GL::GetString(EGLInfo::ShadingLanguageVersion)
};
F_GLDisplayErrors();
const TArray<const FChar* const, ArraySize> GLInfoDescArray =
{
"Vendor: ",
"Renderer: ",
"Running Version: ",
"Shading Language Version: "
};
F_GFXLog("OpenGL: Compiled For Version 3.3.0");
for (SizeT I = 0; I < ArraySize; ++I)
{
if (GLInfoArray[I])
{
F_GFXLog(GLInfoDescArray[I] << GLInfoArray[I]);
}
}
# if PHOENIX_GFX_DISPLAY_OPEN_GL_EXTENSIONS
const GLubyte* const GLExtensions = GL::GetString(EGLInfo::Extensions);
const GLubyte* const NoGLExtensions = reinterpret_cast<const GLubyte*>("None.");
F_GFXLog("OpenGL Extensions: " << (GLExtensions ? GLExtensions : NoGLExtensions));
F_GLIgnoreErrors();
# endif
#endif
}
}
}
| 24
| 85
| 0.687739
|
rohunb
|
1e080990ec95179fd575d579fb1dd27ef65a9dc1
| 1,333
|
cpp
|
C++
|
Game/PlayerManager.cpp
|
BenzoL17/Dots
|
4db6322d9a66da83a88a9fc24f5c3016682ff5bd
|
[
"MIT"
] | null | null | null |
Game/PlayerManager.cpp
|
BenzoL17/Dots
|
4db6322d9a66da83a88a9fc24f5c3016682ff5bd
|
[
"MIT"
] | null | null | null |
Game/PlayerManager.cpp
|
BenzoL17/Dots
|
4db6322d9a66da83a88a9fc24f5c3016682ff5bd
|
[
"MIT"
] | null | null | null |
#include "PlayerManager.h"
IPlayer *player;
IPlayer *firstPlayer;
IPlayer *secondPlayer;
PlayerManager::PlayerManager()
{
}
PlayerManager::~PlayerManager()
{
}
PlayerManager * PlayerManager::getInstance()
{
static PlayerManager *instance;
if (!instance)
instance = new PlayerManager();
return instance;
}
void PlayerManager::init()
{
firstPlayer = new FirstPlayer();
secondPlayer = new SecondPlayer();
firstPlayer->init();
secondPlayer->init();
}
void PlayerManager::clearPlayerInfo()
{
firstPlayer->clearInfo();
secondPlayer->clearInfo();
}
void PlayerManager::setPlayer(int playerNumber)
{
switch (playerNumber)
{
case FIRST:
init();
player = firstPlayer;
break;
case SECOND:
init();
player = secondPlayer;
break;
}
}
void PlayerManager::setOppositePlayer()
{
if (player->getPlayerNumber() == FIRST) {
player = secondPlayer;
return;
}
else if (player->getPlayerNumber() == SECOND) {
player = firstPlayer;
}
}
void PlayerManager::plusScore()
{
player->increasePlayerScore();
}
sf::Color PlayerManager::getPlayerColor()
{
return player->getColor();
}
int PlayerManager::getPlayerNumber()
{
return player->getPlayerNumber();
}
int PlayerManager::getPlayerScore()
{
return player->getScore();
}
| 15.869048
| 49
| 0.669167
|
BenzoL17
|
1e0bc4e288d8da3916af0a30811643600364f7e9
| 8,389
|
hpp
|
C++
|
include/fpt/Pairs.hpp
|
frobnitzem/FastParticleToolkit
|
d5bc77f891d8aae18d777b8855ff4a6b3dd79761
|
[
"CC-BY-4.0"
] | null | null | null |
include/fpt/Pairs.hpp
|
frobnitzem/FastParticleToolkit
|
d5bc77f891d8aae18d777b8855ff4a6b3dd79761
|
[
"CC-BY-4.0"
] | null | null | null |
include/fpt/Pairs.hpp
|
frobnitzem/FastParticleToolkit
|
d5bc77f891d8aae18d777b8855ff4a6b3dd79761
|
[
"CC-BY-4.0"
] | null | null | null |
#pragma once
#include <fpt/Cell.hpp>
#define SQR(x) ((x)*(x))
/* E = eps ( s/r^12 - 2 s/r^6 ) = 4 eps (s1/r^12 - s1/r^6)
* s = 2^(1/6) s1
*
* for s = eps = 1
* E = r2^(-6) - 2 r2^(-3)
*
* dE / d(r2) = -6 r2^(-7) + 6 r2^(-4)
* given r2 = (x1-x2)**2 + (y1-y2)**2 + (z1-z2)**2
*
* d(r2) / dx1 = 2 (x1-x2)
*
*/
ALPAKA_FN_HOST_ACC inline float lj_en(const float r2) {
float ir2 = 1.0/r2;
float ir6 = ir2*ir2*ir2;
float ir12 = ir6*ir6;
return fmaf(-2.0, ir6, ir12);
}
ALPAKA_FN_HOST_ACC inline float lj_deriv(const float &dx, const float &dy, float &dz) {
float r2 = dx*dx;
r2 = fmaf(dy, dy, r2);
r2 = fmaf(dz, dz, r2);
float ir2 = 1.0/r2;
float ir4 = ir2*ir2;
float ir8 = ir4*ir4;
float ir6 = ir2*ir4;
float ir14 = ir6*ir8;
//float en = fmaf(-2.0, ir6, ir12);
float two_dEdr2 = 12.0f*(ir8 - ir14);
return two_dEdr2;
/*dx *= two_dEdr2;
dy *= two_dEdr2;
dz *= two_dEdr2;*/
}
/** Pair computation leaving the LJ energy on every particle.
*/
struct LJEnOper {
using Output = fpt::CellEnergy;
using Accum = double[1];
static inline ALPAKA_FN_ACC void pair(Accum en, float dx, float dy, float dz) {
float r2 = SQR(dx) + SQR(dy) + SQR(dz);
en[0] += lj_en(r2); //erfcf(sqrtf(r2));
}
static inline ALPAKA_FN_ACC void finalize(Output &E, Accum en, uint32_t n, int j) {
if(n == 0)
en[0] = 0.0;
E.n[j] = n;
E.en[j] = en[0]*0.5; // half due to double-iterating over all-pairs
}
};
/** Pair computation leaving the derivative of the LJ energy on every particle.
*/
struct LJDerivOper {
using Output = fpt::Cell;
using Accum = float[3];
static inline ALPAKA_FN_ACC void pair(Accum de, float dx, float dy, float dz) {
float scale = lj_deriv(dx, dy, dz);
de[0] = fmaf(scale, dx, de[0]);
de[1] = fmaf(scale, dy, de[1]);
de[2] = fmaf(scale, dz, de[2]);
}
static inline ALPAKA_FN_ACC void finalize(Output &dE, Accum de, uint32_t n, int j) {
if(n == 0) {
dE.x[j] = 0.0;
dE.y[j] = 0.0;
dE.z[j] = 0.0;
}
dE.n[j] = n;
dE.x[j] = de[0];
dE.y[j] = de[1];
dE.z[j] = de[2];
}
};
namespace fpt {
/**
Compute a pairwise function by summing over all atoms in a far cell.
Work is distributed such that every thread is associated with
an atom in the `near' cell. We therefore loop over all `far' cells,
and all atoms in those far cells.
Loading of data from the `next' far cell is overlapped with computations
on the `current' far cell.
Data Layout Schematic
(WARNING: outdated, currently using 1 thread per 'near' atom slot):
c0 = blockIdx.x*ATOMS_PER_CELL
r0 = blockIdx.y*ATOMS_PER_CELL
--x--> (a)
. c0, c0+1, ..., c0+ATOMS_PER_CELL
y r0 0 1 ... 31
| r0+1 0 1 ... 31
v ...
(b) r0+ATOMS_PER_CELL 0 1 ... 31
*/
// pairFunc
template <typename Oper2, typename Vec>
struct Oper2Kernel {
ALPAKA_NO_HOST_ACC_WARNING
template<typename TAcc>
ALPAKA_FN_ACC void operator()(
TAcc const& acc,
const CellSorter_d box,
const CellRange *__restrict__ nbr,
const Cell *__restrict__ X,
typename Oper2::Output *__restrict__ const out
) const {
auto const j = alpaka::getIdx<alpaka::Block, alpaka::Threads>(acc)[0];
auto const bin = alpaka::getIdx<alpaka::Grid, alpaka::Blocks>(acc)[0];
// far cell read repeatedly
auto& far = alpaka::declareSharedVar<CellTranspose, __COUNTER__>(acc);
// local copy for overlapping:
uint32_t an[ATOMS_PER_CELL];
float ax[ATOMS_PER_CELL], ay[ATOMS_PER_CELL], az[ATOMS_PER_CELL];
// atom belonging to this thread
uint32_t bn;
float bx, by, bz;
int bi, bj, bk;
box.decodeBin(bin, bi, bj, bk);
// prevent modulo wrapping issues
bi += box.n[0]; bj += box.n[1]; bk += box.n[2];
const Cell &B = X[bin];
bn = B.n[j];
bx = B.x[j];
by = B.y[j];
bz = B.z[j];
typename Oper2::Accum ans{};
CellRange off = nbr[0];
unsigned int start = box.calcBin(0, (bj+off.j)%box.n[1], (bk+off.k)%box.n[2]);
int self2 = load_cell(acc, X, start + (bi + off.i0)%box.n[0], far);
for(int k=0; off.i0 <= off.i1; k++) { // offsets define a valid range
for(int i = off.i0; i <= off.i1; i++) {
alpaka::syncBlockThreads(acc);
// Copy last far cell
const int self = self2;
for(int m=0; m<ATOMS_PER_CELL; m++) {
an[m] = far.n[m];
ax[m] = far.x[m];
ay[m] = far.y[m];
az[m] = far.z[m];
}
// Load next far cell (A) as a group
if(i < off.i1) {
self2 = load_cell(acc, X, start + (bi + i+1)%box.n[0], far);
} else {
off = nbr[k+1]; // the old 'off' isn't useful anymore
if(off.i0 <= off.i1) {
start = box.calcBin(0, (bj+off.j)%box.n[1], (bk+off.k)%box.n[2]);
self2 = load_cell(acc, X, start + (bi + off.i0)%box.n[0], far);
}
}
/*if(bn != 0) {
const int i0 = self*(j+1);
for (int i = i0; i < ATOMS_PER_CELL; i++) {
if(an[i] == 0) continue;
//for (int i = 0; i < ATOMS_PER_CELL; i++) { // this code is technically correct,
// if(i < i0 || an[i] == 0) continue; // but some compiler transform evaluates ans += nan ...
float r2 = SQR(ax[i]-bx) + SQR(ay[i]-by) + SQR(az[i]-bz);
ans += lj_en(r2); //erfcf(sqrtf(r2));
}}
}*/
// The loop above would be twice as fast, but should exclude some far cells
// and I don't want to bother, since the weird loop starting at i0 makes it buggy / slow!
//if(bn != 0) {
for (int m = 0; m < ATOMS_PER_CELL; m++) {
if(an[m] == 0 || self*(m==j)) continue;
float dx = bx - ax[m];
float dy = by - ay[m];
float dz = bz - az[m];
Oper2::pair(ans, dx, dy, dz);
}
//}
}
}
Oper2::finalize(out[bin], ans, bn, j);
}
};
/** Create a 2-body operation.
*
* Oper2 must be a class including members:
* type Output = type of output per cell
* type Accum = local variable to pass to f
* pair : Accum, dx, dy, dz -> void
* finalize : Output,Accum,n,idx -> void
*
* Example enque calls:
*
* LJEnK = mk2Body<LJEnKernel,Acc,Dim,Idx>(devAcc, srt, nbr, X, out);
* alpaka::enqueue(queue, LJEnK);
*
*/
template <typename Oper2, typename Acc, typename Dim, typename Idx, typename Dev>
auto mk2Body(const Dev &devAcc, const CellSorter &srt, const alpaka::Buf<Dev, CellRange, Dim, Idx> &nbr,
const alpaka::Buf<Dev, Cell, Dim, Idx> &X,
alpaka::Buf<Dev, typename Oper2::Output, Dim, Idx> &out) {
using Vec = alpaka::Vec<Dim,Idx>;
// Launch with one warp per thread block
Idx const warpExtent = alpaka::getWarpSize(devAcc);
// Spaces must match.
Idx const ncells = alpaka::extent::getExtent<0>(X);
assert( ncells == alpaka::extent::getExtent<0>(out) );
Vec const gridBlockExtent = Vec::all(ncells);
// min of 2
Vec blockThreadExtent = Vec::all(
warpExtent < ATOMS_PER_CELL ?
warpExtent : ATOMS_PER_CELL);
alpaka::WorkDivMembers<Dim, Idx> workDiv{
gridBlockExtent,
blockThreadExtent,
Vec::all(1)};
std::cout << "Creating 2-body kernel for " << ncells << " cells.\n";
Oper2Kernel<Oper2,Vec> K{};
return alpaka::createTaskKernel<Acc>(workDiv, K,
srt.device(), alpaka::getPtrNative(nbr),
alpaka::getPtrNative(X), alpaka::getPtrNative(out));
}
}
| 33.027559
| 120
| 0.513291
|
frobnitzem
|
1f62e127190c17b3b1c3b682767ebf75b7a9fdff
| 1,169
|
cpp
|
C++
|
heap_priorityQueue/BINHEAP.cpp
|
heyswappy/Data-Structures-In-C
|
58945a8125f821a17cabb622f381c4b37ddef578
|
[
"MIT"
] | 1
|
2019-03-14T13:37:44.000Z
|
2019-03-14T13:37:44.000Z
|
heap_priorityQueue/BINHEAP.cpp
|
heyswappy/Data-Structures-In-C
|
58945a8125f821a17cabb622f381c4b37ddef578
|
[
"MIT"
] | null | null | null |
heap_priorityQueue/BINHEAP.cpp
|
heyswappy/Data-Structures-In-C
|
58945a8125f821a17cabb622f381c4b37ddef578
|
[
"MIT"
] | 1
|
2021-03-23T16:42:37.000Z
|
2021-03-23T16:42:37.000Z
|
#include<iostream>
#include<cstdlib>
class Heap{
private:
int *arr;
int count;
public:
void percolateUp(int i);
void percolateDown(int i);
void insert(int a);
int pop();
int *sort();
};
void Heap :: percolateUp(int i){
int parent = (i-1)/2;
if(parent<0 || i<0){
return;
}
if(arr[parent] < arr[i]){
int t = arr[parent];
arr[parent] = arr[i];
arr[i] = t;
return percolateUp(parent);
}
else{
return;
}
return;
}
void Heap :: percolateDown(int i = 0){
int L = 2*i+1;
int R = 2*i+2;
int max = i;
if(L<count && arr[L]>arr[max]){
max = L;
}
if(R<count && arr[R]>arr[max]){
max = R;
}
if(max==i){
return;
}
else{
//swap them
int t = arr[max];
arr[max] = arr[i];
arr[i] = arr[max];
return(percolateDown(max));
}
return;
}
void Heap :: insert(int n){
arr[count] = n;
count++;
percolateUp(count-1);
return;
}
int Heap :: pop(){
int t = arr[0];
arr[0] = arr[count-1];
percolateDown(0);
return t;
}
int* Heap :: sort(){
int *srt = (int*)calloc(sizeof(int),count);
for(int i = 0; i<count; i++){
srt[count-1] = pop();
}
return srt;
}
| 15.381579
| 45
| 0.534645
|
heyswappy
|
1f65b6f9dc134fd16f681d9bf8142503797b2d99
| 17,297
|
hpp
|
C++
|
boost/graph/distributed/distributed_control.hpp
|
thejkane/AGM
|
4d5cfe9522461d207ceaef7d90c1cd10ce9b469c
|
[
"BSL-1.0"
] | 1
|
2021-09-03T10:22:04.000Z
|
2021-09-03T10:22:04.000Z
|
boost/graph/distributed/distributed_control.hpp
|
thejkane/AGM
|
4d5cfe9522461d207ceaef7d90c1cd10ce9b469c
|
[
"BSL-1.0"
] | null | null | null |
boost/graph/distributed/distributed_control.hpp
|
thejkane/AGM
|
4d5cfe9522461d207ceaef7d90c1cd10ce9b469c
|
[
"BSL-1.0"
] | null | null | null |
// Copyright (C) 2018 Thejaka Amila Kanewala, Marcin Zalewski, Andrew Lumsdaine.
// Boost Software License - Version 1.0 - August 17th, 2003
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// Authors: Thejaka Kanewala
// Marcin Zalewski
// Andrew Lumsdaine
#ifndef BOOST_GRAPH_DISTRIBUTED_CONTROL
#define BOOST_GRAPH_DISTRIBUTED_CONTROL
#ifndef BOOST_GRAPH_USE_MPI
#error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
#endif
#include <am++/counter_coalesced_message_type.hpp>
#include <am++/transport.hpp>
#include <am++/detail/thread_support.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/graph/iteration_macros.hpp>
#include <boost/graph/parallel/thread_support.hpp> // for compare_and_swap
#include <queue>
#include <algorithm> // for std::min, std::max
#include <iostream>
#include <atomic>
#include <tuple>
#include <climits>
namespace boost {
namespace graph {
namespace distributed {
// The default priority queue
template<typename V, typename D, typename Compare>
struct default_priority_queue {
typedef std::priority_queue<std::pair<V, D>, std::vector<std::pair<V, D> >, Compare> DefaultPriorityQueueType;
DefaultPriorityQueueType priority_q;
void put(const std::pair<V, D>& p) {
priority_q.push(p);
}
std::pair<V, D> pop() {
// get the top vertex
std::pair<V, D> topv = priority_q.top();
// remove top element from the queue
priority_q.pop();
return topv;
}
bool is_empty() const {
return priority_q.empty();
}
std::pair<V, D> top() {
// get the top vertex
std::pair<V, D> topv = priority_q.top();
return topv;
}
size_t size() const {
return priority_q.size();
}
};
// Default priority queue generator
struct default_priority_queue_gen {
template<typename V, typename D, typename Compare>
struct queue {
typedef default_priority_queue<V, D, Compare> type;
};
};
// Vector of vector implementation
/*template<typename V, typename D, typename Compare>
class vector_of_vector_table {
public:
vector_of_vector_table()
: max_distance(0),min_distance(std::numeric_limits<int32_t>::max()),_size(0){}
void put(const std::pair<V, D>& p) {
//if the pair passed to has greater distance than the max, resize more
//then push
D current_distance = p.second;
#ifdef PRINT_DEBUG
std::cerr<<"pushing vertex "<<p.first<< " distance processing "<<current_distance<<"\n";
#endif
if (current_distance >= max_distance) {
buckets.resize(current_distance+1);
max_distance = current_distance;
}
if (current_distance <= min_distance) {
min_distance = current_distance;
}
++_size;
if(buckets.size() < current_distance || buckets.size() == 0) {
if(buckets.size() == 0){
buckets.resize(1);
//min_distance = 0;
}
else
buckets.resize(current_distance+1);
}
buckets[current_distance].push_back(p.first);
#ifdef PRINT_DEBUG
std::cerr<<"PUSH min: "<< min_distance<< " Max "<<max_distance<<"\n";
#endif
}
std::pair<V, D> pop() {
// get the top vertex
// remove top element from the bucket
--_size;
V& topv = buckets[min_distance].back();
D distance_ret = min_distance;
#ifdef PRINT_DEBUG
std::cerr<<"POP min"<<min_distance<<" \n";
std::cerr<<"Popping "<< topv <<" with distance " << min_distance <<"\n";
#endif
buckets[min_distance].pop_back();
if(buckets[min_distance].empty()) {
for(auto i = min_distance+1; i <= max_distance;i++) {
if(!buckets[i].empty()){
min_distance = i;
break;
}
}
}
if (_size==0) {
min_distance = std::numeric_limits<int32_t>::max();
max_distance = 0;
}
return std::make_pair(topv, distance_ret);
}
bool is_empty() const {
return (_size==0);
}
std::pair<V, D> top() {
// get the top vertex
V& topv = buckets[min_distance].back();
D distance_ret = min_distance;
return std::make_pair(topv, distance_ret);
}
size_t size() const {
return _size;
}
private:
typedef std::vector<std::vector<V> > Buckets;
Buckets buckets;
D max_distance;
D min_distance;
int _size;
};
// vector of vector generator
struct vector_of_vector_gen {
template<typename V, typename D, typename Compare>
struct queue {
typedef vector_of_vector_table<V, D, Compare> type;
};
};*/
template<typename Graph,
typename DistanceMap,
typename EdgeWeightMap,
typename WorkStats,
typename PriorityQueueGenerator = default_priority_queue_gen,
typename MessageGenerator = amplusplus::simple_generator<amplusplus::counter_coalesced_message_type_gen> >
class distributed_control {
// Type definitions for Vertex and Distance
// Vertex information is in graph_traits::vertex_descriptor
typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
// The distance is in the property traits of the edge
typedef typename property_traits<EdgeWeightMap>::value_type Distance;
// This is going to be our message
typedef std::pair<Vertex, Distance> vertex_distance_data;
// Default comparer
// TODO: MZ: We can probably turn of sorting as discussed. Sorting will occur in the priority queue. Once we want to try intra-buffer sorting we can revisit this. - this can be done using the preprocessor macro. I guess once we integrate Jesun's code on command line switch we dont need the preprocessor macro
struct default_comparer {
bool operator()(const vertex_distance_data& vd1, const vertex_distance_data& vd2) {
return vd1.second > vd2.second;
}
};
// Owner map type - To calculate which vertex belong to which node
typedef typename boost::property_map<Graph, vertex_owner_t>::const_type OwnerMap;
// Create the default queue generator type
typedef typename PriorityQueueGenerator::template queue<Vertex, Distance, default_comparer>::type PriorityQueueType;
// The handler, forward decleration
struct vertex_distance_handler;
typedef typename MessageGenerator::template call_result<
vertex_distance_data,
vertex_distance_handler,
vertex_distance_owner<OwnerMap, vertex_distance_data>,
amplusplus::idempotent_combination_t<boost::parallel::minimum<Distance>, Distance> >::type
RelaxMessage;
public:
distributed_control(Graph& g,
DistanceMap distance_map,
EdgeWeightMap weight_map,
amplusplus::transport &t,
int offs,
WorkStats& stats,
MessageGenerator message_gen =
MessageGenerator(amplusplus::counter_coalesced_message_type_gen(1 << 12)),
unsigned int flushFreq = 2000)
: dummy_first_member_for_init_order((amplusplus::register_mpi_datatype<vertex_distance_data>(), 0)),
graph(g),
transport(t),
core_offset(offs),
work_stats(stats),
distance_map(distance_map),
weight_map(weight_map),
owner_map(get(vertex_owner, g)),
relax_msg(message_gen,
transport,
vertex_distance_owner<OwnerMap, vertex_distance_data>(owner_map),
amplusplus::idempotent_combination(boost::parallel::minimum<Distance>(), std::numeric_limits<Distance>::max())),
flushFrequency(flushFreq)
{
initialize();
}
#ifdef AMPLUSPLUS_PRINT_HIT_RATES
typedef std::pair<unsigned long long, unsigned long long> cache_stats;
cache_stats
get_cache_stats() {
cache_stats stats(0, 0);
for(size_t i = 0; i < relax_msg.counters.hits.size(); ++i) {
stats.first += relax_msg.counters.hits[i];
stats.second += relax_msg.counters.tests[i];
}
return stats;
}
#endif // AMPLUSPLUS_PRINT_HIT_RATES
void set_source(Vertex s) { source = s; }
// What is actually getting called is this operator
void operator() (int tid) { run(source, tid); }
void run(Vertex s, int tid = 0);
time_type get_start_time() { return start_time; }
/*void print_in_edge_map() {
typename graph_traits<Graph>::vertex_iterator i, end;
unsigned int k = 0;
// std::pair<vertex_iter, vertex_iter> vp;
//for (vp = vertices(graph); vp.first != vp.second; ++vp.first)
for(tie(i, end) = vertices(graph); i != end; ++i) {
++k;
unsigned int val = processed_in_edge_count_map[*i];
std::cout << "The vertex " << k << " is visited " << val << " times." << std::endl;
if (k == 100000)
break;
}
}*/
private:
void initialize();
void relax(const vertex_distance_data&, const int);
void handle_queue(const int, amplusplus::transport::end_epoch_request&);
const int dummy_first_member_for_init_order; // Unused
const Graph& graph;
amplusplus::transport& transport;
int core_offset;
WorkStats& work_stats;
DistanceMap distance_map;
EdgeWeightMap weight_map;
//ProcessedInEdgeCountMap processed_in_edge_count_map;
OwnerMap owner_map;
Vertex source;
unsigned int flushFrequency;
RelaxMessage relax_msg;
std::vector<PriorityQueueType> thread_buckets;
shared_ptr<amplusplus::detail::barrier> t_bar;
unsigned int in_edge_factor;
time_type start_time;
#ifdef DC_USE_PRIORITY
std::vector<Distance> current_min;
#endif // DC_USE_PRIORITY
};
#define DISTRIBUTE_CONTROL_PARMS \
typename Graph, typename DistanceMap, typename EdgeWeightMap, typename WorkStats, typename PriorityQueueGenerator, typename MessageGenerator
#define DISTRIBUTE_CONTROL_TYPE \
distributed_control<Graph, DistanceMap, EdgeWeightMap, WorkStats, PriorityQueueGenerator, MessageGenerator>
template<DISTRIBUTE_CONTROL_PARMS> void
DISTRIBUTE_CONTROL_TYPE::initialize() {
relax_msg.set_handler(vertex_distance_handler(*this));
// Initialize distance labels
BGL_FORALL_VERTICES_T(v, graph, Graph) {
put(distance_map, v, (std::numeric_limits<Distance>::max)());
}
}
template<DISTRIBUTE_CONTROL_PARMS> void
DISTRIBUTE_CONTROL_TYPE::run(Vertex s, int tid) {
AMPLUSPLUS_WITH_THREAD_ID(tid) {
if (0 == tid) {
int nthreads = transport.get_nthreads();
// Set the number of threads to the barrier
t_bar.reset(new amplusplus::detail::barrier(nthreads));
// Resize thread queue
thread_buckets.resize(nthreads);
#ifdef DC_USE_PRIORITY
// Resize current minimums
current_min.resize(nthreads);
#endif // DC_USE_PRIORITY
for (int k = 0; k < nthreads; ++k) {
// For each thread create a priority queue
thread_buckets[k] = PriorityQueueType();
#ifdef DC_USE_PRIORITY
// For each thread set the minimum to 0
current_min[k] = 0;
#endif // DC_USE_PRIORITY
}
}
// TODO delta had following. Not sure we also need this - ask
// This barrier acts as a temporary barrier until we can be sure t_bar is initialized
{ amplusplus::scoped_epoch epoch(transport); }
// Now above if branch needs to be executed to every thread
// Therefore wait till every thread comes to this point
t_bar->wait();
if (pin(tid+core_offset) != 0) {
std::cerr << "[ERROR] Unable to pin current thread to "
<< "core : " << tid << std::endl;
assert(false);
}
// wait till all threads are pinned
t_bar->wait();
{ amplusplus::scoped_epoch epoch(transport); }
validate_thread_core_relation();
// should come before begin epoch
start_time = get_time();
// Start the algorithm
transport.begin_epoch();
// If this is main thread and if node is the owner of the vertex do relax
// for source with distance 0
if (get(owner_map, s) == transport.rank() && tid == 0) {
relax(vertex_distance_data(s, 0), tid);
}
// Check whether we still have work to do
amplusplus::transport::end_epoch_request request = transport.i_end_epoch();
// if we have work process queues. queue is populated in the relax_msg
handle_queue(tid, request);
}
#ifdef PRINT_DEBUG
std::cerr<<"Done with run\n";
#endif
}
template<DISTRIBUTE_CONTROL_PARMS>
void DISTRIBUTE_CONTROL_TYPE::handle_queue(const int tid, amplusplus::transport::end_epoch_request& request) {
// get the queue
PriorityQueueType& queue = thread_buckets[tid];
int doFlushCounter = 0;
while (true) {
if (!queue.is_empty()) {
// get the top vertex
std::pair<Vertex, Distance> vd = queue.pop();
Vertex v = vd.first;
Distance v_distance = vd.second;
#ifdef DC_USE_PRIORITY
current_min[tid] = vd.second;
#endif // DC_USE_PRIORITY
// remember if the queue was empty after pop
bool was_empty = queue.is_empty();
// get existing distance
// if distance in distance map is better that distance we got from queue
// then we dont need to do anything (i.e. another thread has updated distance map with better
// distance), otherwise send new distances for neighbours
Distance map_dist = get(distance_map, v);
if (map_dist == v_distance) {
BGL_FORALL_OUTEDGES_T(v, e, graph, Graph) {
Vertex u = target(e, graph);
Distance we = get(weight_map, e);
relax_msg.send(vertex_distance_data(u, v_distance + we));
}
}
// If the queue was empty after the pop, we need to decrease activity count. The queue may not be empty at this point, because a send could result in a push to the queue.
if (was_empty) {
#ifdef PRINT_DEBUG
std::cout << "########### Decrease activity count by 1 ########## " << std::endl;
#endif
// after poping element if queue is empty decrease the activity count
transport.decrease_activity_count(1);
}
doFlushCounter++;
if(doFlushCounter == flushFrequency) {
doFlushCounter = 0;
if(request.test()) {
#ifdef PRINT_DEBUG
assert(queue.is_empty());
#endif
break;
}
}
} else {
if (request.test()) break;
}
}
}
template<DISTRIBUTE_CONTROL_PARMS> void
DISTRIBUTE_CONTROL_TYPE::relax(const vertex_distance_data& vd, const int tid) {
#ifdef PBGL2_PRINT_WORK_STATS
work_stats.increment_edges(amplusplus::detail::get_thread_id());
#endif
using boost::parallel::val_compare_and_swap;
Vertex v = vd.first;
Distance new_distance = vd.second;
// we are processing an incoming edge for vertex v
// increase incoming edge count
//++processed_in_edge_count_map[v];
// get existing distance
// need last_old_dist to atomically update distance map
Distance old_dist = get(distance_map, v), last_old_dist;
// check whether we got a better distance if we got better
// distance update the distance map
// credit : took from delta_stepping_shortest_paths.hpp
while (new_distance < old_dist) {
last_old_dist = old_dist;
old_dist = val_compare_and_swap(&distance_map[v], old_dist, new_distance);
if (last_old_dist == old_dist) {
// we got a better distance - insert it to work queue
PriorityQueueType& queue = thread_buckets[tid];
if (queue.is_empty()) {
// If the queue was empty, increase activity count to notify AM++ that work is being held off.
#ifdef PRINT_DEBUG
std::cout << "########### Increasing activity count by 1 ########## " << std::endl;
#endif
transport.increase_activity_count(1);
}
queue.put(vd);
#ifdef PBGL2_PRINT_WORK_STATS
int tid = amplusplus::detail::get_thread_id();
if(old_dist < std::numeric_limits<Distance>::max()) {
work_stats.increment_invalidated(tid);
} else {
work_stats.increment_useful(tid);
}
#endif // PBGL2_PRINT_WORK_STATS
return;
}
}
#ifdef PBGL2_PRINT_WORK_STATS
work_stats.increment_rejected(amplusplus::detail::get_thread_id());
#endif // PBGL2_PRINT_WORK_STATS
}
template<DISTRIBUTE_CONTROL_PARMS>
struct DISTRIBUTE_CONTROL_TYPE::vertex_distance_handler {
vertex_distance_handler() : self(NULL) {}
vertex_distance_handler(distributed_control& self) : self(&self) {}
void operator() (const vertex_distance_data& data) const {
const int tid = amplusplus::detail::get_thread_id();
self->relax(data, tid);
}
protected:
distributed_control* self;
};
} // end namespace distributed
} // end namespace graph
} // end namespace boost
#endif
| 31.109712
| 313
| 0.704284
|
thejkane
|
1f6696544f49df3477ae868fa23312e02f622314
| 1,304
|
cpp
|
C++
|
LinkedList/SearchinLL.cpp
|
ShivamDureja/Data-Structures-And-Algorithms
|
49c8fe18cbb57c54e8af900ca166604f967e7285
|
[
"Unlicense"
] | 1
|
2021-11-24T05:25:42.000Z
|
2021-11-24T05:25:42.000Z
|
LinkedList/SearchinLL.cpp
|
ShivamDureja/Data-Structures-And-Algorithms
|
49c8fe18cbb57c54e8af900ca166604f967e7285
|
[
"Unlicense"
] | null | null | null |
LinkedList/SearchinLL.cpp
|
ShivamDureja/Data-Structures-And-Algorithms
|
49c8fe18cbb57c54e8af900ca166604f967e7285
|
[
"Unlicense"
] | null | null | null |
#include <iostream>
using namespace std;
struct Node
{
int data;
struct Node *next;
} *first = NULL;
void create(int A[], int n)
{
struct Node *t, *last;
first = (struct Node *)malloc(sizeof(struct Node));
first->data = A[0];
first->next = NULL;
last = first;
for (int i = 1; i < n; i++)
{
t = (struct Node *)malloc(sizeof(struct Node));
t->data = A[i];
t->next = NULL;
last->next = t;
last = t;
}
}
Node *Search(Node *p, int key)
{
Node *q = NULL;
while (p != NULL)
{
if (key == p->data)
{
q->next = p->next;
p->next = first;
first = p;
return p;
}
q = p;
p = p->next;
}
return NULL;
}
int main()
{
int A[50];
int n;
struct Node *temp;
cout << "Enter size =>";
cin >> n;
cout << "Enter elements of linked list" << endl;
for (int i = 0; i < n; i++)
{
cin >> A[i];
}
create(A, n);
int key;
cout << "Enter the element u want to search" << endl;
cin >> key;
temp = Search(first, key);
if (temp!=NULL)
{
cout << "Key is found" << temp->data << endl;
}
else
{
cout << "Key not found" << endl;
};
return 0;
}
| 17.863014
| 57
| 0.450153
|
ShivamDureja
|
1f74b8528d5d1e3388d4c61563bddfaed127b572
| 4,818
|
cpp
|
C++
|
src/main.cpp
|
zzx9636/BosonUSB_Stereo
|
270ee5c4ce161c83481fa3b318bfaf6aaa6207b9
|
[
"MIT"
] | null | null | null |
src/main.cpp
|
zzx9636/BosonUSB_Stereo
|
270ee5c4ce161c83481fa3b318bfaf6aaa6207b9
|
[
"MIT"
] | null | null | null |
src/main.cpp
|
zzx9636/BosonUSB_Stereo
|
270ee5c4ce161c83481fa3b318bfaf6aaa6207b9
|
[
"MIT"
] | null | null | null |
#include "CameraStreamer.hpp"
#include "cvMatContainer.hpp"
#include "opencv2/highgui.hpp"
#include <sys/types.h>
#include <sys/stat.h>
#include <cmath>
#define MAX_DT 33334
#define NUM_CAM 2
int main()
{
//USB Camera indices
vector<string> capture_index = { "/dev/video1", "/dev/video2" };
bool show_img = false;
const char * folder_name_0 = "./Cam_0/";
const char * folder_name_1 = "./Cam_1/";
char filename[60];
unsigned long frame=1;
if(capture_index.size()!=NUM_CAM){
cout<<"Number of Cameras should be "<<NUM_CAM<<endl;
return 0;
}
//Highgui window titles
vector<string> label;
for (int i = 0; i < capture_index.size(); i++)
{
string title = "CAM_" + to_string(i);
label.push_back(title);
}
//Make an instance of CameraStreamer
CameraStreamer cam(capture_index, RAW16_AGC, Boson_640);
if(show_img){
cvMatContainer* cur_container;
cv::Mat frame;
while(!cam.stream_stopped() && cv::waitKey(20))
{
for (int i = 0; i < capture_index.size(); i++){
//Pop frame from queue and check if the frame is valid
if (cam.frame_queue[i]->try_pop(cur_container))
{
//cout<<__LINE__<<endl;
frame = cur_container->getImg();
//cout<<cur_container->getTimeCam()<<endl;
imshow(capture_index[i], frame);
delete cur_container;
cur_container=NULL;
}
}
}
}else{
// create folders to record images
struct stat info0;
if( stat( folder_name_0, &info0 ) != -1 ){
if( S_ISDIR(info0.st_mode) )
printf( "%s is a directory\n", folder_name_0 );
}
else{
printf( "create the directory %s\n", folder_name_0 );
mkdir(folder_name_0, 0700);
}
struct stat info1;
if( stat( folder_name_1, &info1 ) != -1 ){
if( S_ISDIR(info1.st_mode) )
printf( "%s is a directory\n", folder_name_1 );
}
else{
printf( "create the directory %s\n", folder_name_1 );
mkdir(folder_name_1, 0700);
}
//some parameters for sync
cvMatContainer* curMat0=NULL;
cvMatContainer* curMat1=NULL;
int curTime0=0;
int curTime1=0;
// if camera is not stopped or there are still images in the outcomming queue
while(!(cam.stream_stopped()) || !(cam.frame_queue[0]->empty()) || !(cam.frame_queue[1]->empty()))
{
if(curMat0==NULL)
cam.frame_queue[0]->try_pop(curMat0);
if(curMat1==NULL)
cam.frame_queue[1]->try_pop(curMat1);
if(curMat0 != NULL && curMat1 != NULL)
{
curTime0 = curMat0->getTimeCam();
curTime1 = curMat1->getTimeCam();
// if both incoming stream's timestamps are less than MAX_DT
if( abs(curTime0-curTime1) < MAX_DT)
{
if(curMat0->getFFCMode()!=3 || curMat1->getFFCMode()!=3)
cout<<"At Frame "<<frame<<" cam1 in "<<curMat0->getFFCMode()<<" cam2 in "<<curMat1->getFFCMode()<<endl;
sprintf(filename, "%scam0_raw16_%lu.tiff", folder_name_0, frame);
if(curMat0->saveImg(filename))
{
delete curMat0;
curMat0 = NULL;
}
sprintf(filename, "%scam1_raw16_%lu.tiff", folder_name_1, frame);
if(curMat1->saveImg(filename))
{
delete curMat1;
curMat1 = NULL;
}
frame++;
}else if(curTime0 < curTime1)
{
//cam0 is ahead. Drop frame and wait for cam1
delete curMat0;
curMat0 = NULL;
//debug
/*
cout<<curTime0<<" "<<curTime1<<" "<<abs(curTime0-curTime1)<<endl;
cout<<"At frame "<<frame<<" Cam 0 is dropped"<<endl;
*/
}
else{
delete curMat1;
curMat1 = NULL;
//debug
/*
cout<<curTime0<<" "<<curTime1<<" "<<abs(curTime0-curTime1)<<endl;
cout<<"At frame "<<frame<<" Cam 1 is dropped"<<endl;
*/
}
}
}
}
return 0;
}
| 34.170213
| 127
| 0.471773
|
zzx9636
|
1f754ac95b4b9d38c24d44229f78d8f042085519
| 939
|
cpp
|
C++
|
src/jsxer/nodes/IfStatement.cpp
|
psyirius/jsxer
|
e55dea39356dcbd482a03e0069eb3dd64473751e
|
[
"BSD-3-Clause"
] | 5
|
2022-01-18T17:46:17.000Z
|
2022-03-08T19:16:10.000Z
|
src/jsxer/nodes/IfStatement.cpp
|
psyirius/jsxer
|
e55dea39356dcbd482a03e0069eb3dd64473751e
|
[
"BSD-3-Clause"
] | 15
|
2022-02-07T15:31:59.000Z
|
2022-03-26T00:20:09.000Z
|
src/jsxer/nodes/IfStatement.cpp
|
psyirius/jsxer
|
e55dea39356dcbd482a03e0069eb3dd64473751e
|
[
"BSD-3-Clause"
] | 1
|
2022-02-07T05:09:32.000Z
|
2022-02-07T05:09:32.000Z
|
#include "IfStatement.h"
void IfStatement::parse() {
bodyInfo = decoders::d_line_info(reader);
test = decoders::d_node(reader);
otherwise = decoders::d_node(reader);
}
string IfStatement::to_string() {
string result = bodyInfo.lbl_statement() + "if (" + test->to_string() + ") { \n"
+ bodyInfo.create_body() + "\n}";
if (otherwise == nullptr) {
return result;
}
AstNode *current = otherwise;
while ((current->type() == NodeType::IfStatement) && ((IfStatement*) current)->otherwise != nullptr) {
auto* elif = (IfStatement *)current;
result += '\n' + elif->bodyInfo.lbl_statement() + "else if (" + elif->test->to_string() + ") {\n"
+ elif->bodyInfo.create_body() + "\n}";
current = elif->otherwise;
}
// WARN_ME: something feels wrong here...
result += "\nelse {\n" + current->to_string() + "\n}";
return result;
}
| 29.34375
| 106
| 0.574015
|
psyirius
|
1f89886662e342f30a3e338c592179368e7d0d1e
| 2,356
|
hpp
|
C++
|
PlayRho/Dynamics/WorldImplJoint.hpp
|
Hexlord/PlayRho
|
a3a91554cf9b267894d06a996c5799a0479c5b5f
|
[
"Zlib"
] | 88
|
2017-07-13T18:12:40.000Z
|
2022-03-23T03:43:11.000Z
|
PlayRho/Dynamics/WorldImplJoint.hpp
|
Hexlord/PlayRho
|
a3a91554cf9b267894d06a996c5799a0479c5b5f
|
[
"Zlib"
] | 388
|
2017-07-13T04:32:09.000Z
|
2021-11-10T20:59:23.000Z
|
PlayRho/Dynamics/WorldImplJoint.hpp
|
Hexlord/PlayRho
|
a3a91554cf9b267894d06a996c5799a0479c5b5f
|
[
"Zlib"
] | 18
|
2017-07-20T16:14:57.000Z
|
2021-06-20T07:17:23.000Z
|
/*
* Original work Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
* Modified work Copyright (c) 2021 Louis Langholtz https://github.com/louis-langholtz/PlayRho
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef PLAYRHO_DYNAMICS_WORLDIMPLJOINT_HPP
#define PLAYRHO_DYNAMICS_WORLDIMPLJOINT_HPP
/// @file
/// Declarations of free functions of WorldImpl for joints.
#include <PlayRho/Common/Units.hpp>
#include <PlayRho/Common/UnitVec.hpp>
#include <PlayRho/Common/Vector2.hpp> // for Momentum2, Length2
#include <PlayRho/Dynamics/BodyID.hpp>
#include <PlayRho/Dynamics/Joints/JointID.hpp>
namespace playrho {
namespace d2 {
class WorldImpl;
class Joint;
/// @brief Gets the extent of the currently valid joint range.
/// @note This is one higher than the maxium <code>JointID</code> that is in range
/// for joint related functions.
/// @relatedalso WorldImpl
JointCounter GetJointRange(const WorldImpl& world) noexcept;
/// @brief Creates a new joint.
/// @relatedalso WorldImpl
JointID CreateJoint(WorldImpl& world, const Joint& def);
/// @brief Destroys the identified joint.
/// @relatedalso WorldImpl
void Destroy(WorldImpl& world, JointID id);
/// @brief Gets the identified joint's value.
/// @relatedalso WorldImpl
const Joint& GetJoint(const WorldImpl& world, JointID id);
/// @brief Sets the identified joint's new value.
/// @relatedalso WorldImpl
void SetJoint(WorldImpl& world, JointID id, const Joint& def);
} // namespace d2
} // namespace playrho
#endif // PLAYRHO_DYNAMICS_WORLDIMPLJOINT_HPP
| 35.164179
| 94
| 0.75764
|
Hexlord
|
1f8da2357183dbd656fc96ad0430a573d63fdddc
| 1,217
|
cpp
|
C++
|
AliceVector3.cpp
|
BattleFireLTD/Rasterizer
|
ca6f25a0e14ee338bd4378264380be2e861cb18a
|
[
"MIT"
] | 2
|
2021-11-15T12:42:26.000Z
|
2022-03-14T11:06:27.000Z
|
AliceVector3.cpp
|
BattleFireLTD/Rasterizer
|
ca6f25a0e14ee338bd4378264380be2e861cb18a
|
[
"MIT"
] | null | null | null |
AliceVector3.cpp
|
BattleFireLTD/Rasterizer
|
ca6f25a0e14ee338bd4378264380be2e861cb18a
|
[
"MIT"
] | 1
|
2020-09-15T07:57:39.000Z
|
2020-09-15T07:57:39.000Z
|
#include "AliceVector3.h"
#include <math.h>
namespace Alice {
Vector3 Vector3::operator+(const Vector3&r) {
return Vector3(x + r.x, y + r.y, z + r.z);
}
Vector3 Vector3::operator-(const Vector3&r) {
return Vector3(x - r.x, y - r.y, z - r.z);
}
Vector3 Vector3::operator*(float scalar) {
return Vector3(x*scalar, y*scalar, z*scalar);
}
float Vector3::operator*(const Vector3&r) {
return x * r.x + y * r.y + z * r.z;
}
Vector3 Vector3::operator^(const Vector3&r) const {
return Vector3(y*r.z - r.y*z, z*r.x - r.z*x, x*r.y - r.x*y);
}
float Vector3::magnitude() {
return sqrtf(x*x + y * y + z * z);
}
void Vector3::normalize() {
float len = magnitude();
if (len > 0.000001f) {
x /= len;
y /= len;
z /= len;
}
else {
x = 0.0f;
y = 0.0f;
z = 0.0f;
}
}
Vector3 Vector3::ProjectTo(Vector3&v) {
float lenSquared = v.LengthSquared();
return (*this)*v*v* (1.0f/lenSquared);
}
Vector3 Vector3::PerpendicularTo(Vector3&v) {
Vector3 projP2Q = ProjectTo(v);
return (*this) - projP2Q;
}
float Vector3::LengthSquared() {
float len = x * x + y * y + z * z;
return len != 0.0f ? len : 1.0f;
}
Vector3 operator*(float scalar,Vector3&r) {
return r * scalar;
}
}
| 24.34
| 62
| 0.599014
|
BattleFireLTD
|
1fa065a50128977eb33e73f32abeea11c20ee39d
| 66
|
cpp
|
C++
|
energy/src/energy/solve_angle/solve_angle.cpp
|
tianyuecao/SJTU-RM-CV-2019
|
f6845aa8dfe785d6a025e698ac2e227638cb0fa0
|
[
"MIT"
] | null | null | null |
energy/src/energy/solve_angle/solve_angle.cpp
|
tianyuecao/SJTU-RM-CV-2019
|
f6845aa8dfe785d6a025e698ac2e227638cb0fa0
|
[
"MIT"
] | null | null | null |
energy/src/energy/solve_angle/solve_angle.cpp
|
tianyuecao/SJTU-RM-CV-2019
|
f6845aa8dfe785d6a025e698ac2e227638cb0fa0
|
[
"MIT"
] | null | null | null |
//
// Created by vanessa on 12/7/19.
//
#include "solve_angle.h"
| 11
| 33
| 0.636364
|
tianyuecao
|
1fa0c6626fc2ceaa37e8bf1789cf46c8e45f1ae4
| 977
|
cpp
|
C++
|
08_class_copy/main.cpp
|
acc-cosc-1337-spring-2019/midterm-spring-2019-littlefeller
|
2d8268c5f7a4de0f40a2a2b2e855cdac41f4b213
|
[
"MIT"
] | null | null | null |
08_class_copy/main.cpp
|
acc-cosc-1337-spring-2019/midterm-spring-2019-littlefeller
|
2d8268c5f7a4de0f40a2a2b2e855cdac41f4b213
|
[
"MIT"
] | null | null | null |
08_class_copy/main.cpp
|
acc-cosc-1337-spring-2019/midterm-spring-2019-littlefeller
|
2d8268c5f7a4de0f40a2a2b2e855cdac41f4b213
|
[
"MIT"
] | null | null | null |
/*
Create a Die instance and copy to another Die variable.
Explain what happens with comments in your code.
Create a reference to a Die, explain what happens with comments in your code.
Create test cases in 08_class_copy_test.
*/
#include "die.h"
#include<iostream>
int main()
{
//d2 is a copy of d1, meaning that it is the same as d1, but is a different variable (different memory location)
Die d1;
Die d2 = d1;
// test
int num1 = 5;
int num2 = num1;
std::cout << num1 << "\n";
std::cout << num2 << "\n";
num2 += 3;
std::cout << num1 << "\n";
std::cout << num2 << "\n";
std::cout << "\n\n";
// d3_ref is a reference to the original d3 variable memory location, meaning that is you change d3_ref, you will change d3
Die d3;
Die& d3_ref = d3;
// test
num1 = 5;
int& num1_ref = num1;
std::cout << num1 << "\n";
std::cout << num1_ref << "\n";
num1_ref += 3;
std::cout << num1 << "\n";
std::cout << num1_ref << "\n";
return 0;
}
| 16.844828
| 124
| 0.62129
|
acc-cosc-1337-spring-2019
|
1fa7e88810b5cbbd7df71a709fde62130e7931ff
| 1,363
|
cpp
|
C++
|
solved/l-n/monitoring-processes/monitoring.cpp
|
abuasifkhan/pc-code
|
77ce51d692acf6edcb9e47aeb7b7f06bf56e4e90
|
[
"Unlicense"
] | 13
|
2015-09-30T19:18:04.000Z
|
2021-06-26T21:11:30.000Z
|
solved/l-n/monitoring-processes/monitoring.cpp
|
sbmaruf/pc-code
|
77ce51d692acf6edcb9e47aeb7b7f06bf56e4e90
|
[
"Unlicense"
] | null | null | null |
solved/l-n/monitoring-processes/monitoring.cpp
|
sbmaruf/pc-code
|
77ce51d692acf6edcb9e47aeb7b7f06bf56e4e90
|
[
"Unlicense"
] | 13
|
2015-01-04T09:49:54.000Z
|
2021-06-03T13:18:44.000Z
|
#include <algorithm>
#include <cstdio>
using namespace std;
#define MAXN 50000
typedef unsigned int u32;
struct Reader {
char b; Reader() { read(); }
void read() { int r = fgetc_unlocked(stdin); b = r == EOF ? 0 : r; }
void skip() { while (b > 0 && b <= 32) read(); }
u32 next_u32() {
u32 v = 0; for (skip(); b > 32; read()) v = v*10 + b-48; return v; }
};
struct Point {
int n, t; // number and type (0: process start, 1: process end)
Point() {}
Point (int N, int T) : n(N), t(T) {}
bool operator<(const Point &x) const {
if (n != x.n) return n < x.n;
return t < x.t;
}
};
int n;
Point pts[2*MAXN];
int np;
int solve()
{
sort(pts, pts + np);
int t = 0; // total number of wrappers
int f = 0; // free wrappers
for (int i = 0; i < np; ++i) {
if (pts[i].t == 1) ++f;
else {
if (f == 0) ++t;
else --f;
}
}
return t;
}
int main()
{
Reader rr;
int T = rr.next_u32();
int ncase = 0;
while (T--) {
n = rr.next_u32();
np = 0;
for (int i = 0; i < n; ++i) {
int t = rr.next_u32();
pts[np++] = Point(t, 0);
t = rr.next_u32();
pts[np++] = Point(t, 1);
}
printf("Case %d: %d\n", ++ncase, solve());
}
return 0;
}
| 18.418919
| 76
| 0.450477
|
abuasifkhan
|
1faa2c60162073cf4340d9f4036581a80ebb6f80
| 522
|
hpp
|
C++
|
CNN/value_array_matcher.hpp
|
suiyili/projects
|
29b4ab0435c8994809113c444b3dea4fff60b75c
|
[
"MIT"
] | null | null | null |
CNN/value_array_matcher.hpp
|
suiyili/projects
|
29b4ab0435c8994809113c444b3dea4fff60b75c
|
[
"MIT"
] | null | null | null |
CNN/value_array_matcher.hpp
|
suiyili/projects
|
29b4ab0435c8994809113c444b3dea4fff60b75c
|
[
"MIT"
] | null | null | null |
#pragma once
#include "dnn_type.hpp"
#include <catch2/matchers/catch_matchers.hpp>
using namespace cnn;
using namespace Catch::Matchers;
class value_array_matcher final : public MatcherBase<value_array> {
public:
explicit value_array_matcher(const value_array &expected);
~value_array_matcher() override = default;
std::string describe() const override;
bool match(const value_array &actual) const override;
private:
const value_array &expected_;
};
value_array_matcher Equals(const value_array &expected);
| 24.857143
| 67
| 0.791188
|
suiyili
|
1fafc9aa3f2f3993de4fda4df460de15de5655bf
| 1,066
|
cpp
|
C++
|
data/dailyCodingProblem235.cpp
|
vidit1999/daily_coding_problem
|
b90319cb4ddce11149f54010ba36c4bd6fa0a787
|
[
"MIT"
] | 2
|
2020-09-04T20:56:23.000Z
|
2021-06-11T07:42:26.000Z
|
data/dailyCodingProblem235.cpp
|
vidit1999/daily_coding_problem
|
b90319cb4ddce11149f54010ba36c4bd6fa0a787
|
[
"MIT"
] | null | null | null |
data/dailyCodingProblem235.cpp
|
vidit1999/daily_coding_problem
|
b90319cb4ddce11149f54010ba36c4bd6fa0a787
|
[
"MIT"
] | null | null | null |
#include <bits/stdc++.h>
using namespace std;
/*
Given an array of numbers of length N, find both
the minimum and maximum using less than 2 * (N - 2) comparisons.
*/
// first elment is min and second in max
pair<int, int> minMaxArray(int arr[], int n) {
if(n == 0) return {INT_MAX, INT_MIN};
pair<int, int> ans;
int i=0;
if(n%2 == 0) {
if(arr[i] > arr[i+1]){
ans.first = arr[i+1];
ans.second = arr[i];
} else {
ans.first = arr[i];
ans.second = arr[i+1];
}
i += 2;
} else {
ans.first = ans.second = arr[i];
i += 1;
}
while(i < n-1) {
if(arr[i] > arr[i+1]) {
if(arr[i] > ans.second)
ans.second = arr[i];
if(arr[i+1] < ans.first)
ans.first = arr[i+1];
} else {
if(arr[i+1] > ans.second)
ans.second = arr[i+1];
if(arr[i] < ans.first)
ans.first = arr[i];
}
i += 2;
}
return ans;
}
// main function
int main() {
int arr[] = { 1000, 11, 445, 18, 330, 300 };
int n = sizeof(arr)/sizeof(arr[0]);
auto ans = minMaxArray(arr, n);
cout << ans.first << " -- " << ans.second << "\n";
return 0;
}
| 19.381818
| 64
| 0.547842
|
vidit1999
|
1fb6069a91f81e2a719d7ae02860588bbe7f5949
| 6,820
|
cc
|
C++
|
src/mlir/driver.cc
|
aghosn/verona
|
b75b96bd2b496b662caea58b69fb1c2893cd5f72
|
[
"MIT"
] | 3,477
|
2020-01-16T20:13:28.000Z
|
2022-03-28T10:46:50.000Z
|
src/mlir/driver.cc
|
aghosn/verona
|
b75b96bd2b496b662caea58b69fb1c2893cd5f72
|
[
"MIT"
] | 328
|
2020-01-17T00:33:59.000Z
|
2022-03-25T09:40:33.000Z
|
src/mlir/driver.cc
|
aghosn/verona
|
b75b96bd2b496b662caea58b69fb1c2893cd5f72
|
[
"MIT"
] | 198
|
2020-01-16T20:55:57.000Z
|
2022-02-19T09:26:43.000Z
|
// Copyright Microsoft and Project Verona Contributors.
// SPDX-License-Identifier: MIT
#include "driver.h"
#include "consumer.h"
#include "mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/ExecutionEngine/ExecutionEngine.h"
#include "mlir/ExecutionEngine/OptUtils.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/Verifier.h"
#include "mlir/Parser.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
#include "mlir/Target/LLVMIR/Export.h"
#include "mlir/Transforms/Passes.h"
#include "orcjit.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/ToolOutputFile.h"
#include <iostream>
namespace
{
/// Return the correct output stream for writing operations.
/// Possible returns are: file, stdout or null
llvm::Expected<std::unique_ptr<llvm::raw_ostream>>
getOutputStream(llvm::StringRef filename)
{
std::unique_ptr<llvm::raw_ostream> out;
if (filename.empty())
{
// Empty filename is null output
out = std::make_unique<llvm::raw_null_ostream>();
}
else
{
// Otherwise, both filename and - do the right thing
std::error_code error;
out = std::make_unique<llvm::raw_fd_ostream>(filename, error);
if (error)
return mlir::verona::runtimeError("Cannot open output filename");
}
return out;
}
}
namespace mlir::verona
{
Driver::Driver(unsigned optLevel)
: optLevel(optLevel),
passManager(&mlirContext),
diagnosticHandler(sourceManager, &mlirContext)
{
// These are the dialects we emit directly
mlirContext.getOrLoadDialect<mlir::StandardOpsDialect>();
mlirContext.getOrLoadDialect<mlir::LLVM::LLVMDialect>();
// Initialize LLVM targets.
// TODO: Use target triples here, for cross-compilation
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
}
llvm::Error Driver::readAST(::verona::parser::Ast ast)
{
// Use the MLIR generator to lower the AST into MLIR
auto result = ASTConsumer::lower(&mlirContext, ast);
if (!result)
return result.takeError();
mlirModule = std::move(*result);
// Verify the mlirModule to make sure we didn't do anything silly
if (failed(verify(*mlirModule)))
{
mlirModule->dump();
return runtimeError("AST was lowered to invalid MLIR");
}
return llvm::Error::success();
}
llvm::Error Driver::readMLIR(const std::string& filename)
{
if (filename.empty())
return runtimeError("No input filename provided");
// Read an MLIR file into a buffer
auto srcOrErr = llvm::MemoryBuffer::getFileOrSTDIN(filename);
if (auto err = srcOrErr.getError())
return runtimeError(
"Cannot open file " + filename + ": " + err.message());
// Add the input to the source manager and parse it.
// `parseSourceFile` already includes verification of the IR.
sourceManager.AddNewSourceBuffer(std::move(*srcOrErr), llvm::SMLoc());
mlirModule = mlir::parseSourceFile(sourceManager, &mlirContext);
if (!mlirModule)
return runtimeError("Can't load MLIR file");
return llvm::Error::success();
}
llvm::Error Driver::emitMLIR(llvm::StringRef filename)
{
assert(mlirModule);
auto out = getOutputStream(filename);
if (auto err = out.takeError())
return err;
// Write to the file requested
mlirModule->print(*out.get());
return llvm::Error::success();
}
llvm::Error Driver::optimiseMLIR()
{
assert(mlirModule);
if (mlirOptimised)
return llvm::Error::success();
// Some simple MLIR optimisations
if (optLevel > 0)
{
passManager.addPass(mlir::createInlinerPass());
passManager.addPass(mlir::createSymbolDCEPass());
mlir::OpPassManager& funcPM = passManager.nest<mlir::FuncOp>();
funcPM.addPass(mlir::createCanonicalizerPass());
funcPM.addPass(mlir::createCSEPass());
}
// If optimisation levels higher than 0, run some opts
if (failed(passManager.run(mlirModule.get())))
{
mlirModule->dump();
return runtimeError("Failed to run some passes");
}
mlirOptimised = true;
return llvm::Error::success();
}
llvm::Error Driver::lowerToLLVM()
{
assert(mlirModule);
// The lowering "pass manager"
passManager.addPass(mlir::createLowerToLLVMPass());
// If optimisation levels higher than 0, run some opts
if (mlir::failed(passManager.run(mlirModule.get())))
{
mlirModule->dump();
return runtimeError("Failed to run some passes");
}
// Register the translation to LLVM IR with the MLIR mlirContext.
mlir::registerLLVMDialectTranslation(*mlirModule->getContext());
// Then lower to LLVM IR (via LLVM dialect)
if (!llvmContext)
llvmContext = std::make_unique<llvm::LLVMContext>();
llvmModule = mlir::translateModuleToLLVMIR(mlirModule.get(), *llvmContext);
if (!llvmModule)
return runtimeError("Failed to lower to LLVM IR");
// Optimise if requested
if (optLevel)
{
mlir::ExecutionEngine::setupTargetTriple(llvmModule.get());
// Optionally run an optimization pipeline over the llvm mlirModule.
auto optPipeline = mlir::makeOptimizingTransformer(
optLevel,
/*sizeLevel=*/0,
/*targetMachine=*/nullptr);
if (auto err = optPipeline(llvmModule.get()))
return runtimeError("Failed to generate LLVM IR");
}
return llvm::Error::success();
}
llvm::Error Driver::emitLLVM(llvm::StringRef filename)
{
if (!llvmModule)
{
auto err = lowerToLLVM();
if (err)
return err;
}
auto out = getOutputStream(filename);
if (auto err = out.takeError())
return err;
// Write to the file requested
llvmModule->print(*out.get(), nullptr);
return llvm::Error::success();
}
llvm::Error Driver::runLLVM(int& returnValue)
{
if (!llvmModule)
{
auto err = lowerToLLVM();
if (err)
return err;
}
llvm::ExitOnError check;
auto J = llvm::orc::VeronaJIT::Create();
if (!J)
return J.takeError();
auto& JIT = *J;
llvm::orc::ThreadSafeModule TSM(
std::move(llvmModule), std::move(llvmContext));
check(JIT->addModule(std::move(TSM)));
auto MainSymbol = JIT->lookup("main");
if (!MainSymbol)
return MainSymbol.takeError();
auto* Main = (int (*)(int, char*[]))MainSymbol->getAddress();
returnValue = Main(0, {});
return llvm::Error::success();
}
llvm::Error Driver::codeGeneration(const llvm::StringRef filename)
{
return runtimeError("Not implemented yet");
}
}
| 27.95082
| 79
| 0.665836
|
aghosn
|
1fb7992c1ac8eebf69f7f03119aef5fc810c20e2
| 659
|
cpp
|
C++
|
raygame/ShootingComponent.cpp
|
RavisSavoy47/AIDecisionMakingExercise
|
eb0f7d97c7261aabc244ae2f048bc786383bfa3e
|
[
"MIT"
] | null | null | null |
raygame/ShootingComponent.cpp
|
RavisSavoy47/AIDecisionMakingExercise
|
eb0f7d97c7261aabc244ae2f048bc786383bfa3e
|
[
"MIT"
] | null | null | null |
raygame/ShootingComponent.cpp
|
RavisSavoy47/AIDecisionMakingExercise
|
eb0f7d97c7261aabc244ae2f048bc786383bfa3e
|
[
"MIT"
] | null | null | null |
#include "ShootingComponent.h"
#include "Bullet.h"
#include "Transform2D.h"
#include "Engine.h"
#include "GameManager.h"
#include "Transform2D.h"
ShootingComponent::ShootingComponent(Actor* target, float cooldown)
{
m_timer = 0;
m_cooldown = cooldown;
m_target = target;
}
void ShootingComponent::update(float deltaTime)
{
m_timer += deltaTime;
if (m_timer > m_cooldown) {
MathLibrary::Vector2 ownerPos = getOwner()->getTransform()->getWorldPosition();
Bullet* bullet = new Bullet(ownerPos.x, ownerPos.y, "AgentOneBullet", 2000, 2000, GameManager::getInstance()->getAgent2());
Engine::getCurrentScene()->addActor(bullet);
m_timer = 0;
}
}
| 24.407407
| 125
| 0.729894
|
RavisSavoy47
|
1fb7cd5ef74eaf5fdfe3a9247e8e95cabb3696aa
| 1,540
|
cpp
|
C++
|
graph/_dinic2.cpp
|
albexl/team-reference
|
eeeeb5f715c59890cc1d7753fdadb0d29ad3273b
|
[
"MIT"
] | 1
|
2021-07-16T19:59:38.000Z
|
2021-07-16T19:59:38.000Z
|
graph/_dinic2.cpp
|
albexl/team-reference
|
eeeeb5f715c59890cc1d7753fdadb0d29ad3273b
|
[
"MIT"
] | null | null | null |
graph/_dinic2.cpp
|
albexl/team-reference
|
eeeeb5f715c59890cc1d7753fdadb0d29ad3273b
|
[
"MIT"
] | null | null | null |
template<typename F>
struct dinic
{
struct edge
{
int src, dst, rev;
F flow, cap;
};
int n;
vector<vector<edge>> adj;
dinic(int n) : n(n), adj(n), it(n), level(n) {}
void add_edge(int u, int v, F cuv, F cvu = 0)
{
adj[u].push_back({u, v, (int) adj[v].size(), 0, cuv});
if (u == v) adj[u].back().rev++;
adj[v].push_back({v, u, (int) adj[u].size() - 1, 0, cvu});
}
vector<decltype(adj.front().begin())> it;
vector<int> level;
bool bfs(int s, int t)
{
fill(level.begin(), level.end(), -1);
queue<int> q;
for (q.push(t), level[t] = 0; !q.empty(); q.pop())
{
t = q.front();
for (edge &e : adj[t])
{
edge &ee = adj[e.dst][e.rev];
if (ee.flow < ee.cap && level[e.dst] == -1)
level[e.dst] = 1 + level[t], q.push(e.dst);
}
}
return level[s] >= 0;
}
F dfs(int s, int t, F f)
{
if (s == t)
return f;
F flow = 0;
for (; it[s] != adj[s].end(); ++it[s])
{
edge &e = *it[s];
if (level[s] == 1 + level[e.dst] && e.flow < e.cap)
{
F delta = dfs(e.dst, t, min(f - flow, e.cap - e.flow));
e.flow += delta;
adj[e.dst][e.rev].flow -= delta;
flow += delta;
}
if (flow == f) return flow;
}
return flow;
}
const F oo = numeric_limits<F>::max();
F max_flow(int s, int t)
{
for (int u = 0; u < n; ++u)
for (edge &e : adj[u])
e.flow = 0;
F flow = 0;
while (bfs(s, t))
{
for (int u = 0; u < n; ++u)
it[u] = adj[u].begin();
flow += dfs(s, t, oo);
}
// level[u] == -1 => s side of min cut
return flow;
}
};
| 17.111111
| 60
| 0.48961
|
albexl
|
1fc4fe503fea3864c0b057651905f0b49c4d286d
| 210
|
hpp
|
C++
|
srcXcode/srcXcode/MyBot.hpp
|
alexsct20/antsChallenge
|
c96854ee0d61315db1b1c46ccbf5ed0fe2103c05
|
[
"Apache-1.1"
] | null | null | null |
srcXcode/srcXcode/MyBot.hpp
|
alexsct20/antsChallenge
|
c96854ee0d61315db1b1c46ccbf5ed0fe2103c05
|
[
"Apache-1.1"
] | null | null | null |
srcXcode/srcXcode/MyBot.hpp
|
alexsct20/antsChallenge
|
c96854ee0d61315db1b1c46ccbf5ed0fe2103c05
|
[
"Apache-1.1"
] | null | null | null |
//
// MyBot.hpp
// srcXcode
//
// Created by Alexandre on 07/01/2017.
// Copyright © 2017 Alexandre. All rights reserved.
//
#ifndef MyBot_hpp
#define MyBot_hpp
#include <stdio.h>
#endif /* MyBot_hpp */
| 14
| 52
| 0.666667
|
alexsct20
|
1fc57e8068d3766eb4efe1fe12e3672f012b573f
| 486
|
cpp
|
C++
|
vm/builtin/autoload.cpp
|
DCarper/rubinius
|
6d1f079d0e792fda5606de65c81c8d622366a822
|
[
"BSD-3-Clause"
] | 2
|
2016-08-07T17:14:57.000Z
|
2020-03-03T08:51:37.000Z
|
vm/builtin/autoload.cpp
|
slawosz/rubinius
|
6cb4a19a33e942110ae14a1721cf4b48036fcc06
|
[
"BSD-3-Clause"
] | 1
|
2022-03-12T14:09:00.000Z
|
2022-03-12T14:09:00.000Z
|
vm/builtin/autoload.cpp
|
slawosz/rubinius
|
6cb4a19a33e942110ae14a1721cf4b48036fcc06
|
[
"BSD-3-Clause"
] | 1
|
2021-09-18T04:55:38.000Z
|
2021-09-18T04:55:38.000Z
|
#include "prelude.hpp"
#include "call_frame.hpp"
#include "builtin/class.hpp"
#include "builtin/autoload.hpp"
namespace rubinius {
Autoload* Autoload::create(STATE) {
return state->new_object<Autoload>(G(autoload));
}
void Autoload::init(STATE) {
GO(autoload).set(state->new_class("Autoload"));
G(autoload)->set_object_type(state, AutoloadType);
}
Object* Autoload::resolve(STATE, CallFrame* call_frame) {
return send(state, call_frame, G(sym_call));
}
}
| 24.3
| 59
| 0.703704
|
DCarper
|
1fc657661af12d2deaed997d65c43aa44f8bc275
| 1,698
|
cc
|
C++
|
ext/capn_proto/stream_fd_message_reader.cc
|
peakxu/capnp-ruby
|
f310932d6fab58e04a5346b45f48b2e2ad0afed9
|
[
"MIT"
] | 40
|
2015-01-21T21:15:14.000Z
|
2022-02-14T07:31:07.000Z
|
ext/capn_proto/stream_fd_message_reader.cc
|
peakxu/capnp-ruby
|
f310932d6fab58e04a5346b45f48b2e2ad0afed9
|
[
"MIT"
] | 4
|
2015-03-27T16:21:15.000Z
|
2017-07-14T21:35:28.000Z
|
ext/capn_proto/stream_fd_message_reader.cc
|
peakxu/capnp-ruby
|
f310932d6fab58e04a5346b45f48b2e2ad0afed9
|
[
"MIT"
] | 8
|
2015-03-21T13:02:53.000Z
|
2018-05-11T09:06:09.000Z
|
#include "ruby_capn_proto.h"
#include "message_reader.h"
#include "stream_fd_message_reader.h"
#include "struct_schema.h"
#include "dynamic_struct_reader.h"
#include "class_builder.h"
#include "exception.h"
namespace ruby_capn_proto {
using WrappedType = capnp::StreamFdMessageReader;
VALUE StreamFdMessageReader::Class;
void StreamFdMessageReader::Init() {
ClassBuilder("StreamFdMessageReader", MessageReader::Class).
defineAlloc(&alloc).
defineMethod("initialize", &initialize).
defineMethod("get_root", &get_root).
store(&Class);
}
VALUE StreamFdMessageReader::alloc(VALUE klass) {
return Data_Wrap_Struct(klass, NULL, free, ruby_xmalloc(sizeof(WrappedType)));
}
VALUE StreamFdMessageReader::initialize(VALUE self, VALUE rb_io) {
VALUE rb_fileno = rb_funcall(rb_io, rb_intern("fileno"), 0);
auto fileno = FIX2INT(rb_fileno);
WrappedType* p = unwrap(self);
try {
new (p) WrappedType(fileno);
} catch (kj::Exception ex) {
return Exception::raise(ex);
}
return Qnil;
}
void StreamFdMessageReader::free(WrappedType* p) {
p->~StreamFdMessageReader();
ruby_xfree(p);
}
WrappedType* StreamFdMessageReader::unwrap(VALUE self) {
WrappedType* p;
Data_Get_Struct(self, WrappedType, p);
return p;
}
VALUE StreamFdMessageReader::get_root(VALUE self, VALUE rb_schema) {
if (rb_respond_to(rb_schema, rb_intern("schema"))) {
rb_schema = rb_funcall(rb_schema, rb_intern("schema"), 0);
}
auto schema = *StructSchema::unwrap(rb_schema);
auto reader = unwrap(self)->getRoot<capnp::DynamicStruct>(schema);
return DynamicStructReader::create(reader, self);
}
}
| 28.3
| 82
| 0.703769
|
peakxu
|
1fc7a20b6e3746f63e44544aab29550e2c539bc2
| 9,764
|
cpp
|
C++
|
src/c/PlayingData.cpp
|
Hiiragi/Harmonia
|
e47e811364e15a9bc7b2322c10d1e35fca041e2a
|
[
"MIT"
] | null | null | null |
src/c/PlayingData.cpp
|
Hiiragi/Harmonia
|
e47e811364e15a9bc7b2322c10d1e35fca041e2a
|
[
"MIT"
] | null | null | null |
src/c/PlayingData.cpp
|
Hiiragi/Harmonia
|
e47e811364e15a9bc7b2322c10d1e35fca041e2a
|
[
"MIT"
] | null | null | null |
/**
* Harmonia
*
* Copyright (c) 2018 Hiiragi
*
* This software is released under the MIT License.
* http://opensource.org/licenses/mit-license.php
*/
#include "PlayingData.h"
#include "SoundGroup.h"
#include "Harmonia.h"
#include "SoundStatus.h"
#include "SoundEventType.h"
#include "ogg/ogg.h"
#include "vorbis/vorbisfile.h"
#include <algorithm>
#include <string>
ogg_int64_t __currentPositionOnBinary = 0;
ogg_int64_t __binarySize = 0;
size_t read_callback(void* ptr, size_t size, size_t nmemb, void *datasource)
{
ogg_int64_t resSize;
ogg_int64_t count;
ogg_int64_t writeSize;
ogg_int64_t currentPositionOnBinary = __currentPositionOnBinary;
if (datasource == 0)
{
return 0;
}
// 取得可能カウント数を算出
resSize = __binarySize - currentPositionOnBinary;
count = resSize / size;
if (count > (int)nmemb)
{
count = nmemb;
}
writeSize = size * count;
memcpy(ptr, (char*)datasource + currentPositionOnBinary, writeSize);
// ポインタ位置を移動
__currentPositionOnBinary = writeSize + currentPositionOnBinary;
return count;
}
int seek_callback(void* datasource, ogg_int64_t offset, int whence)
{
switch (whence)
{
case SEEK_CUR:
__currentPositionOnBinary += offset;
break;
case SEEK_END:
__currentPositionOnBinary = __binarySize + offset;
break;
case SEEK_SET:
__currentPositionOnBinary = offset;
break;
default:
return -1;
}
if (__currentPositionOnBinary > __binarySize)
{
__currentPositionOnBinary = __binarySize;
return -1;
}
else if (__currentPositionOnBinary < 0)
{
__currentPositionOnBinary = 0;
return -1;
}
return 0;
}
int close_callback(void* datasource)
{
return 0;
}
long tell_callback(void* datasource)
{
return (long)__currentPositionOnBinary;
}
PlayingData::PlayingData(RegisteredSoundData* registeredSoundData, std::string soundId)
: AbstractSoundData(soundId)
, _buffer(nullptr)
{
_registeredSoundData = registeredSoundData;
_currentPositionOnBinary = 0;
_currentStatus = SoundStatus::WAIT_INITIALIZE;
}
PlayingData::~PlayingData()
{
delete[] _buffer;
ov_clear(&_oggFile);
}
void PlayingData::initialize()
{
if (_currentStatus != SoundStatus::WAIT_INITIALIZE)
{
return;
}
printf("PlayingData construct\n");
// グローバル変数に割り当て
__currentPositionOnBinary = _currentPositionOnBinary;
__binarySize = _registeredSoundData->get_binary_size();
ov_callbacks callbacks;
callbacks.read_func = &read_callback;
callbacks.seek_func = &seek_callback;
callbacks.close_func = &close_callback;
callbacks.tell_func = &tell_callback;
printf("start ov_open_callbacks\n");
unsigned char* binary = _registeredSoundData->get_binary_data();
int result = ov_open_callbacks((void *)binary, &_oggFile, 0, 0, callbacks);
if (result == OV_ENOTVORBIS)
{
printf("OV_ENOTVORBIS\n");
}
printf("ov_open_callbacks result : %d\n", result);
vorbis_comment *comment = ov_comment(&_oggFile, -1);
for (int i = 0; i < comment->comments; i++)
{
printf(" %d, %s\n", comment->comment_lengths[i], comment->user_comments[i]);
if (strncmp(comment->user_comments[i], "LOOPSTART=", 10) == 0)
{
//_loopStartPosition = strtol((const char*)(comment->user_comments[i] + 10), NULL, 10);
}
else if (strncmp(comment->user_comments[i], "LOOPLENGTH=", 11) == 0)
{
//_loopLength = strtol((const char*)(comment->user_comments[i] + 11), NULL, 10);
}
}
//printf("\nLOOPSTART : %lld\n", _loopStartPosition);
//printf("LOOPLENGTH : %lld\n", _loopLength);
// グローバル変数から取り出し
_currentPositionOnBinary = __currentPositionOnBinary;
_currentStatus = SoundStatus::PLAYING;
}
void PlayingData::write_raw_pcm(int* combinedBuffer, int numSamples)
{
// 再生中以外、あるいはグループによって一時停止されている場合は、何もせずに終了
if (_currentStatus != SoundStatus::PLAYING || _pausedGroupList->size() > 0)
{
return;
}
// グローバル変数に割り当て
__currentPositionOnBinary = _currentPositionOnBinary;
__binarySize = _registeredSoundData->get_binary_size();
// 個数から short 型配列のバイナリサイズを求める
int bufferSize = numSamples * 2;
if (_buffer == NULL)
{
_buffer = new char[bufferSize];
_intBuffer = new int[numSamples];
}
memset(_buffer, 0, bufferSize);
const int maxRequestSize = std::min(bufferSize, 4096);
ogg_int64_t requestSize = maxRequestSize;
int bitstream = 0;
ogg_int64_t readSize = 0;
ogg_int64_t comSize = 0;
ogg_int64_t loopStartPoint = _registeredSoundData->get_loop_start_point();
ogg_int64_t loopLength = _registeredSoundData->get_loop_length();
ogg_int64_t loopPoint = loopStartPoint + loopLength;
ogg_int64_t currentPosition = ov_pcm_tell(&_oggFile);
bool isMuted = _isMuted || _mutedGroupList->size() > 0;
//printf("id : %s / current position : %lld / buffer size : %d / loop position : %lld\n", _id, currentPosition, bufferSize, loopPoint);
if (currentPosition < 0)
{
// error
return;
}
// ループありで、今回のバッファ書き込みでループ地点をまたぐ場合の処理
// 4で割っているのは、2チャンネル * short のバイトサイズ
ogg_int64_t destinationPoint = currentPosition + bufferSize / 4;
if (loopLength > 0 && destinationPoint > loopPoint)
{
// ミュート時はシークだけして終了
if (isMuted || _mutedGroupList->size() > 0)
{
// seek
ov_pcm_seek(&_oggFile, destinationPoint - loopPoint + loopStartPoint);
// グローバル変数から取り出し
_currentPositionOnBinary = __currentPositionOnBinary;
__currentPositionOnBinary = 0;
return;
}
// ループ地点まで読み込み
while (1)
{
requestSize = loopPoint - currentPosition;
if (requestSize > maxRequestSize)
{
requestSize = maxRequestSize;
}
readSize = ov_read(&_oggFile, (char*)(_buffer + comSize), (int)requestSize, 0, 2, 1, &bitstream);
if (readSize < 0)
{
break;
}
currentPosition = ov_pcm_tell(&_oggFile);
comSize += readSize;
printf(" adjuting -> request size : %lld, readed size : %lld, position : %lld\n", requestSize, readSize, currentPosition);
if (currentPosition >= loopPoint)
{
break;
}
}
// ループ開始地点へ移動
int seekResult = ov_pcm_seek(&_oggFile, loopStartPoint);
if (seekResult < 0)
{
// error
}
currentPosition = ov_pcm_tell(&_oggFile);
printf("loop back! -> position : %lld\n", currentPosition);
// 残りを読み込むための前処理
requestSize = bufferSize - comSize;
printf(" recent request size : %lld\n", requestSize);
if (requestSize > maxRequestSize)
{
requestSize = maxRequestSize;
}
printf(" limited recent request size : %lld\n", requestSize);
}
while (1)
{
// ミュート時はシークだけして終了
if (isMuted || _mutedGroupList->size() > 0)
{
// seek
ov_pcm_seek(&_oggFile, destinationPoint);
// グローバル変数から取り出し
_currentPositionOnBinary = __currentPositionOnBinary;
__currentPositionOnBinary = 0;
return;
}
readSize = ov_read(&_oggFile, (char*)(_buffer + comSize), (int)requestSize, 0, 2, 1, &bitstream);
// 読み込みが最後に達したので抜ける
if (readSize == 0)
{
stop();
if (_id == "")
{
Harmonia::_set_captured_event(_get_registered_sound_id(), "", SoundEventType::SOUND_PLAY_COMPLETE);
}
else
{
Harmonia::_set_captured_event(_get_registered_sound_id(), _id.c_str(), SoundEventType::SOUND_PLAY_COMPLETE);
}
break;
}
comSize += readSize;
if (comSize >= bufferSize) {
// バッファを埋め尽くしたので抜ける
break;
}
if (bufferSize - comSize < maxRequestSize) {
requestSize = bufferSize - comSize;
}
}
// int 配列に変換 & ボリューム反映
union shortConverter {
char c[2];
short value;
} converter;
for (int i = 0; i < comSize / 2; ++i)
{
converter.c[0] = _buffer[i * 2];
converter.c[1] = _buffer[i * 2 + 1];
short sample = (short)(converter.value * _currentVolume);
_intBuffer[i] = (int)sample;
}
// エフェクトコマンド実行
size_t size = _effectCommandList->size();
int* intBuffer = _intBuffer;
if (size > 0)
{
std::for_each(_effectCommandList->cbegin(), _effectCommandList->cend(), [intBuffer, bufferSize](AbstractEffectCommand* command) {
command->execute(intBuffer, bufferSize * 2);
});
}
// int として合算
for (int i = 0; i < comSize / 2; ++i)
{
combinedBuffer[i] += _intBuffer[i];
}
// グローバル変数から取り出し
_currentPositionOnBinary = __currentPositionOnBinary;
__currentPositionOnBinary = 0;
}
void PlayingData::pause()
{
printf("sound pause [%s]\n", _id.c_str());
if (_currentStatus == SoundStatus::PLAYING)
{
_currentStatus = SoundStatus::PAUSED;
}
}
void PlayingData::resume()
{
printf("sound resume [%s]\n", _id.c_str());
if (_currentStatus == SoundStatus::PAUSED)
{
_currentStatus = SoundStatus::PLAYING;
}
}
void PlayingData::stop()
{
printf("sound stop [%s]\n", _id.c_str());
_currentStatus = SoundStatus::STOPPED;
// 削除
SoundGroup* soundGroup = Harmonia::get_group(_parentGroupId.c_str());
soundGroup->_registerStoppedSound(this);
}
void PlayingData::mute()
{
printf("sound mute [%s]\n", _id.c_str());
if (_isMuted)
return;
_isMuted = true;
}
void PlayingData::unmute()
{
printf("sound unmute [%s]\n", _id.c_str());
if (!_isMuted)
return;
_isMuted = false;
}
void PlayingData::destroy()
{
Harmonia::_remove_playing_data(this);
SoundGroup* soundGroup = Harmonia::get_group(_parentGroupId.c_str());
soundGroup->remove_sound(this);
}
ogg_int64_t PlayingData::get_current_position()
{
ogg_int64_t currentPosition = ov_pcm_tell(&_oggFile);
if (currentPosition < 0)
{
currentPosition = 0;
}
return currentPosition;
}
std::string PlayingData::_get_registered_sound_id()
{
return _registeredSoundData->get_id();
}
void PlayingData::_pause_by_group(std::string soundGroupId)
{
_pausedGroupList->push_back(soundGroupId);
}
void PlayingData::_resume_by_group(std::string soundGroupId)
{
_pausedGroupList->remove(soundGroupId);
}
void PlayingData::_mute_by_group(std::string soundGroupId)
{
_mutedGroupList->push_back(soundGroupId);
}
void PlayingData::_unmute_by_group(std::string soundGroupId)
{
_mutedGroupList->remove(soundGroupId);
}
| 21.272331
| 136
| 0.704322
|
Hiiragi
|
1fd257b24bb09c0085bee1408cb419d36eeb42da
| 2,203
|
cpp
|
C++
|
src/forms/editors/BaseEditor.cpp
|
stoneface86/gbsynth
|
b585378227522e02cc76f29e7b4b4be4b0568689
|
[
"MIT"
] | null | null | null |
src/forms/editors/BaseEditor.cpp
|
stoneface86/gbsynth
|
b585378227522e02cc76f29e7b4b4be4b0568689
|
[
"MIT"
] | null | null | null |
src/forms/editors/BaseEditor.cpp
|
stoneface86/gbsynth
|
b585378227522e02cc76f29e7b4b4be4b0568689
|
[
"MIT"
] | null | null | null |
#include "forms/editors/BaseEditor.hpp"
#include <QSignalBlocker>
#include <QHBoxLayout>
#include <QLabel>
#include <QShowEvent>
#include <QtDebug>
BaseEditor::BaseEditor(
BaseTableModel &model,
PianoInput const& input,
QWidget *parent
) :
PersistantDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint),
mModel(model)
{
mCombo = new QComboBox;
mNameEdit = new QLineEdit;
mEditorWidget = new QWidget;
mPiano = new PianoWidget(input);
auto tableLayout = new QHBoxLayout;
tableLayout->addWidget(mCombo, 1);
tableLayout->addWidget(new QLabel(tr("Name:")));
tableLayout->addWidget(mNameEdit, 1);
auto layout = new QVBoxLayout;
layout->addLayout(tableLayout);
layout->addWidget(mEditorWidget, 1);
layout->addWidget(mPiano);
layout->setSizeConstraint(QLayout::SizeConstraint::SetFixedSize);
setLayout(layout);
mCombo->setModel(&model);
connect(mCombo, qOverload<int>(&QComboBox::currentIndexChanged), this, &BaseEditor::onIndexChanged);
connect(mNameEdit, &QLineEdit::textEdited, this, &BaseEditor::onNameEdited);
connect(&model, &BaseTableModel::modelReset, this,
[this]() {
int index = mModel.rowCount() > 0 ? 0 : -1;
QSignalBlocker blocker(mCombo);
mCombo->setCurrentIndex(index);
onIndexChanged(index);
});
setEnabled(false);
}
PianoWidget* BaseEditor::piano() {
return mPiano;
}
void BaseEditor::openItem(int index) {
mCombo->setCurrentIndex(index);
raise();
}
QWidget* BaseEditor::editorWidget() {
return mEditorWidget;
}
int BaseEditor::currentItem() const {
return mCombo->currentIndex();
}
void BaseEditor::init() {
onIndexChanged(mCombo->currentIndex());
}
void BaseEditor::onIndexChanged(int index) {
bool const hasIndex = index != -1;
if (hasIndex) {
mNameEdit->setText(mModel.name(index));
} else {
mNameEdit->clear();
}
setEnabled(hasIndex);
setCurrentItem(index);
if (!hasIndex) {
hide();
}
}
void BaseEditor::onNameEdited(QString const& name) {
mModel.rename(mCombo->currentIndex(), name);
}
| 23.945652
| 105
| 0.668634
|
stoneface86
|
1fd49032f52ecd2460e9e3439237a9074620a8cb
| 1,019
|
cpp
|
C++
|
src/algorithms/warmup/PlusMinus.cpp
|
notoes/HackerRankChallenges
|
95f280334846a57cfc8433662a1ed0de2aacc3e9
|
[
"MIT"
] | null | null | null |
src/algorithms/warmup/PlusMinus.cpp
|
notoes/HackerRankChallenges
|
95f280334846a57cfc8433662a1ed0de2aacc3e9
|
[
"MIT"
] | null | null | null |
src/algorithms/warmup/PlusMinus.cpp
|
notoes/HackerRankChallenges
|
95f280334846a57cfc8433662a1ed0de2aacc3e9
|
[
"MIT"
] | null | null | null |
/*
https://www.hackerrank.com/challenges/plus-minus
Given an array of integers, calculate which fraction of its elements are positive, which fraction of its elements are negative, and which fraction of its elements are zeroes, respectively. Print the decimal value of each fraction on a new line.
*/
#include <limits>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
int size;
// The first line is the number of ints
cin >> size;
// Strip new lines
cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');
double positiveAvg = 0;
double negativeAvg = 0;
double zeroAvg = 0;
int item;
for(int i=0; i<size; i++) {
cin >> item;
if( item==0 ) zeroAvg++;
else if( item> 0 ) positiveAvg++;
else negativeAvg++;
}
cout << setprecision(6) << fixed;
cout << positiveAvg/size << endl;
cout << negativeAvg/size << endl;
cout << zeroAvg/size << endl;
return 0;
}
| 24.853659
| 248
| 0.615309
|
notoes
|
1fd522855c93ee7a49caaefd520ea7535c9587bd
| 1,281
|
hpp
|
C++
|
boost/sequence/end.hpp
|
ericniebler/time_series
|
4040119366cc21f25c7734bb355e4a647296a96d
|
[
"BSL-1.0"
] | 11
|
2015-02-21T11:23:44.000Z
|
2021-08-15T03:39:29.000Z
|
boost/sequence/end.hpp
|
ericniebler/time_series
|
4040119366cc21f25c7734bb355e4a647296a96d
|
[
"BSL-1.0"
] | null | null | null |
boost/sequence/end.hpp
|
ericniebler/time_series
|
4040119366cc21f25c7734bb355e4a647296a96d
|
[
"BSL-1.0"
] | 3
|
2015-05-09T02:25:42.000Z
|
2019-11-02T13:39:29.000Z
|
// Copyright David Abrahams 2006. Distributed under the Boost
// Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_SEQUENCE_END_DWA200655_HPP
# define BOOST_SEQUENCE_END_DWA200655_HPP
# include <boost/detail/function1.hpp>
# include <boost/detail/pod_singleton.hpp>
# include <boost/range/result_iterator.hpp>
# include <boost/range/end.hpp>
# include <boost/sequence/tag.hpp>
# include <boost/mpl/placeholders.hpp>
# include <boost/iterator/counting_iterator.hpp>
namespace boost { namespace sequence
{
/// INTERNAL ONLY
namespace impl
{
template<typename S, typename T = typename tag<S>::type>
struct end
{
typedef counting_iterator<
typename range_result_iterator<S>::type
> result_type;
result_type operator ()(S &s) const
{
return result_type(boost::end(s));
}
};
}
namespace op
{
using mpl::_;
struct end
: boost::detail::function1<impl::end<_, impl::tag<_> > >
{};
}
namespace
{
op::end const &end = boost::detail::pod_singleton<op::end>::instance;
}
}} // namespace boost::sequence
#endif // BOOST_SEQUENCE_END_DWA200655_HPP
| 24.634615
| 74
| 0.662763
|
ericniebler
|
1fd7c8c8023682b54edb138f4ab1f1e1648b5882
| 4,212
|
hpp
|
C++
|
benchmark.hpp
|
lebensterben/pq-fast-scan
|
cf4a26ddae4540811b7479c55c87ade3d186fd94
|
[
"BSD-3-Clause-Clear"
] | 45
|
2015-09-12T12:32:18.000Z
|
2022-03-09T02:24:34.000Z
|
benchmark.hpp
|
lebensterben/pq-fast-scan
|
cf4a26ddae4540811b7479c55c87ade3d186fd94
|
[
"BSD-3-Clause-Clear"
] | 3
|
2016-01-21T03:23:16.000Z
|
2021-01-19T11:21:31.000Z
|
benchmark.hpp
|
lebensterben/pq-fast-scan
|
cf4a26ddae4540811b7479c55c87ade3d186fd94
|
[
"BSD-3-Clause-Clear"
] | 13
|
2016-04-13T07:43:39.000Z
|
2022-03-09T02:24:36.000Z
|
//
// Copyright (c) 2015 – Thomson Licensing, SAS
//
// The source code form of this open source project is subject to the terms of the
// Clear BSD license.
//
// You can redistribute it and/or modify it under the terms of the Clear BSD
// License (See LICENSE file).
//
#ifndef BENCHMARK_HPP_
#define BENCHMARK_HPP_
#include <sys/time.h>
#include <functional>
#include "common.hpp"
#include "perfevents.hpp"
#include "binheap.hpp"
#include "config.h"
using namespace std;
inline std::uint64_t get_us_clock() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (std::uint64_t) tv.tv_sec * 1000000 + tv.tv_usec;
}
template<typename T>
T* time_func(std::function<void(T*)> bench_f, std::function<T*(T*, T*)> check_f,
std::function<T*()> setup_f, T* oracle_data, unsigned long& time, int repeat) {
T* out_data = NULL;
time = 0;
for (int r = 0; r < repeat; ++r) {
if(setup_f != NULL) {
out_data = setup_f();
}
unsigned long before_us = get_us_clock();
bench_f(out_data);
time += get_us_clock() - before_us;
if (check_f != NULL) {
out_data = check_f(oracle_data, out_data);
}
}
time = time / repeat;
return out_data;
}
template<typename T>
T* time_func_display(std::function<void(T*)> bench_f, std::function<T*(T*, T*)> check_f,
std::function<T*()> setup_f, T* oracle_data, const char* desc, int repeat) {
cout << desc << ": ";
cout.flush();
unsigned long time;
T* out_data = time_func(bench_f, check_f, setup_f, oracle_data, time, repeat);
cout << time << "us" << endl;
return out_data;
}
typedef std::function<void(binheap*)> binheap_scan_func;
binheap* time_func_binheap_display(binheap_scan_func func, int k, binheap* oracle_data,
const char* desc, int repeat);
binheap* time_func_binheap(binheap_scan_func func, int k,
binheap* oracle_data, int repeat, unsigned long& time);
void simple_time_display(function<void()> func, const char* desc, int repeat);
template<typename T>
void divide_array(T* array, int size, int divisor) {
for(int i = 0; i < size; ++i) {
array[i] /= divisor;
}
}
// libpfm and Linux perf_events - New Hardware Performance Counters interface
template<typename T>
T* perf_func(std::function<void(T*)> bench_f, std::function<T*(T*, T*)> check_f,
std::function<T*()> setup_f, T* oracle_data,
std::uint64_t event_values[], int repeat, const char* events[],
int event_count) {
T* out_data = NULL;
event_values[0] = 0;
int perf_events_fds[event_count];
perf_events_open_by_name(perf_events_fds, event_count, events);
for (int r = 0; r < repeat; ++r) {
if (setup_f != NULL) {
out_data = setup_f();
}
const unsigned long before_us = get_us_clock();
perf_events_start();
bench_f(out_data);
perf_events_stop();
event_values[0] += get_us_clock() - before_us;
if (check_f != NULL) {
out_data = check_f(oracle_data, out_data);
}
}
//
std::uint64_t raw[event_count][3];
perf_events_read(perf_events_fds, event_count, event_values + 1, raw);
divide_array(event_values + 1, event_count, repeat);
event_values[0] = event_values[0] / repeat;
perf_events_close(perf_events_fds, event_count);
return out_data;
}
template<typename T>
T* perf_func_display(std::function<void(T*)> bench_f, std::function<T*(T*, T*)> check_f,
std::function<T*()> setup_f, T* oracle_data, const char* desc, int repeat, const char* events[],
int event_count) {
cout << desc << ": ";
cout.flush();
std::uint64_t event_values[event_count + 1];
T* out_data = perf_func(bench_f, check_f, setup_f, oracle_data, event_values, repeat, events, event_count);
std::cout << "time=" << event_values[0] << ",";
for(int event_id = 0; event_id < event_count - 1; ++event_id) {
std::cout << events[event_id] << "=" << event_values[event_id + 1] << ",";
}
std::cout << events[event_count - 1] << "=" << event_values[event_count] << std::endl;
return out_data;
}
binheap* perf_func_binheap(binheap_scan_func func, int k,
binheap* oracle_data,
std::uint64_t event_values[],
int repeat, const char* events[], int event_count);
binheap* perf_func_binheap_display(binheap_scan_func func, int k, binheap* oracle_data,
const char* desc, int repeat, const char* events[],
int event_count);
#endif /* BENCHMARK_HPP_ */
| 30.302158
| 108
| 0.696581
|
lebensterben
|
1fdaeb819447040659a9af2a0f7a481eacbb13a3
| 439
|
cpp
|
C++
|
ojo.cpp
|
EnriqueJose99/P3Lab-5_EnriqueJoseGaleanoTalavera
|
69b2e7f20256b4da6dd1dc182609d23fffdd855c
|
[
"MIT"
] | null | null | null |
ojo.cpp
|
EnriqueJose99/P3Lab-5_EnriqueJoseGaleanoTalavera
|
69b2e7f20256b4da6dd1dc182609d23fffdd855c
|
[
"MIT"
] | null | null | null |
ojo.cpp
|
EnriqueJose99/P3Lab-5_EnriqueJoseGaleanoTalavera
|
69b2e7f20256b4da6dd1dc182609d23fffdd855c
|
[
"MIT"
] | null | null | null |
#include "ojo.h"
#include <string>
using namespace std;
Ojo::Ojo(){
}
Ojo::Ojo(string pColorOJ, bool pVisionNocturna){
colorOJ = pColorOJ;
visionNocturna = pVisionNocturna;
}
void Ojo::setColorOJ(string pColorOJ){
colorOJ = pColorOJ;
}
string Ojo::getColorOJ(){
return colorOJ;
}
void Ojo::setVisionNocturna(bool pVisionNocturna){
visionNocturna = pVisionNocturna;
}
bool Ojo::getVisionNocturna(){
return visionNocturna;
}
| 16.884615
| 50
| 0.738041
|
EnriqueJose99
|
1fdb68927e0800997f016d8d2d0663bbb3ce365b
| 746
|
cpp
|
C++
|
src/StackAllocator.cpp
|
vazgriz/NovaEngine
|
ce0dba1408a61d4387193556353731f1f2678b66
|
[
"MIT"
] | null | null | null |
src/StackAllocator.cpp
|
vazgriz/NovaEngine
|
ce0dba1408a61d4387193556353731f1f2678b66
|
[
"MIT"
] | null | null | null |
src/StackAllocator.cpp
|
vazgriz/NovaEngine
|
ce0dba1408a61d4387193556353731f1f2678b66
|
[
"MIT"
] | null | null | null |
#include "NovaEngine/StackAllocator.h"
using namespace Nova;
StackAllocator::StackAllocator(size_t offset, size_t size) {
m_offset = offset;
m_size = size;
m_ptr = offset;
}
Allocation StackAllocator::allocate(size_t size, size_t alignment) {
size_t ptr = IGenericAllocator::align(m_ptr, alignment);
size_t end = ptr + size;
if (end <= m_offset + m_size) {
m_stack.push_back(m_ptr);
m_ptr = end;
return { this, ptr, size };
} else {
return {};
}
}
void StackAllocator::free(Allocation allocation) {
if (allocation.allocator == nullptr) return;
m_ptr = m_stack.back();
m_stack.pop_back();
}
void StackAllocator::reset() {
m_stack.clear();
m_ptr = m_offset;
}
| 23.3125
| 68
| 0.647453
|
vazgriz
|
1fdc8e454b13ceb31683dc5a4145c882c8472c56
| 2,945
|
cpp
|
C++
|
TopmostThumbnail/main.cpp
|
robmikh/TopmostThumbnail
|
b5351963b6fa6041b2c7175a7f2911dfa2e71e5c
|
[
"MIT"
] | null | null | null |
TopmostThumbnail/main.cpp
|
robmikh/TopmostThumbnail
|
b5351963b6fa6041b2c7175a7f2911dfa2e71e5c
|
[
"MIT"
] | null | null | null |
TopmostThumbnail/main.cpp
|
robmikh/TopmostThumbnail
|
b5351963b6fa6041b2c7175a7f2911dfa2e71e5c
|
[
"MIT"
] | null | null | null |
#include "pch.h"
#include "MainWindow.h"
namespace winrt
{
using namespace Windows::Foundation;
using namespace Windows::Foundation::Numerics;
}
namespace util
{
using namespace robmikh::common::desktop;
}
util::WindowInfo GetWindowToCapture(std::vector<util::WindowInfo> const& windows);
int wmain(int argc, wchar_t* argv[])
{
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
// Initialize COM
winrt::init_apartment();
// Args
std::vector<std::wstring> args(argv + 1, argv + argc);
if (args.size() <= 0)
{
throw std::runtime_error("Invalid input!");
}
// Get the window to thumbnail
auto windowQuery = args[0];
wprintf(L"Looking for \"%s\"...\n", windowQuery.c_str());
auto windows = util::FindTopLevelWindowsByTitle(windowQuery);
if (windows.size() == 0)
{
wprintf(L"No windows found!\n");
return 1;
}
auto foundWindow = GetWindowToCapture(windows);
wprintf(L"Using window \"%s\"\n", foundWindow.Title.c_str());
auto windowToThumbnail = foundWindow.WindowHandle;
// Register our window classes
MainWindow::RegisterWindowClass();
// Create our thumbnail window
auto window = MainWindow(L"TopmostThumbnail", windowToThumbnail);
// Message pump
MSG msg;
while (GetMessageW(&msg, nullptr, 0, 0))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return static_cast<int>(msg.wParam);
}
util::WindowInfo GetWindowToCapture(std::vector<util::WindowInfo> const& windows)
{
if (windows.empty())
{
throw winrt::hresult_invalid_argument();
}
auto numWindowsFound = windows.size();
auto foundWindow = windows[0];
if (numWindowsFound > 1)
{
wprintf(L"Found %I64u windows that match:\n", numWindowsFound);
wprintf(L" Num PID Window Title\n");
auto count = 0;
for (auto const& window : windows)
{
DWORD pid = 0;
auto ignored = GetWindowThreadProcessId(window.WindowHandle, &pid);
wprintf(L" %3i %06u %s\n", count, pid, window.Title.c_str());
count++;
}
do
{
wprintf(L"Please make a selection (q to quit): ");
std::wstring selectionString;
std::getline(std::wcin, selectionString);
if (selectionString.rfind(L"q", 0) == 0 ||
selectionString.rfind(L"Q", 0) == 0)
{
return 0;
}
auto selection = std::stoi(selectionString);
if (selection >= 0 && selection < windows.size())
{
foundWindow = windows[selection];
break;
}
else
{
wprintf(L"Invalid input, '%s'!\n", selectionString.c_str());
}
} while (true);
}
return foundWindow;
}
| 27.268519
| 82
| 0.580985
|
robmikh
|
1fdca8fbb7f658eeb6ad1f137ed043f89648a861
| 1,615
|
cpp
|
C++
|
tests/card_test.cpp
|
CS126SP20/kingdoms-project
|
393a4e2007785cdac709c55ecf63a6abc3914830
|
[
"MIT"
] | null | null | null |
tests/card_test.cpp
|
CS126SP20/kingdoms-project
|
393a4e2007785cdac709c55ecf63a6abc3914830
|
[
"MIT"
] | null | null | null |
tests/card_test.cpp
|
CS126SP20/kingdoms-project
|
393a4e2007785cdac709c55ecf63a6abc3914830
|
[
"MIT"
] | null | null | null |
// Created by Eric Xu on 4/30/20.
#include <mylibrary/card.h>
#include <catch2/catch.hpp>
using mylibrary::Card;
TEST_CASE("5-arg Constructor") {
string name = "hit";
string match = "dodge";
string file = "cards/hit.jpeg";
Card hit(-1,name, match, 30, file);
REQUIRE(hit.GetHealth() == -1);
REQUIRE(hit.GetName() == "hit");
REQUIRE(hit.GetImage() == "cards/hit.jpeg");
REQUIRE(hit.GetNumber() == 30);
REQUIRE(hit.GetMatch() == "dodge");
}
TEST_CASE("Default Constructor") {
Card card;
REQUIRE(card.GetHealth() == 0);
REQUIRE(card.GetName().empty());
REQUIRE(card.GetImage().empty());
REQUIRE(card.GetNumber() == 0);
REQUIRE(card.GetMatch().empty());
}
TEST_CASE("Reset") {
string name = "CS126";
string match = "Woodley";
string file = "siebel.png";
Card card(126,name, match, 1, file);
REQUIRE(card.GetHealth() == 126);
REQUIRE(card.GetName() == "CS126");
REQUIRE(card.GetImage() == "siebel.png");
REQUIRE(card.GetNumber() == 1);
REQUIRE(card.GetMatch() == "Woodley");
card.reset();
REQUIRE(card.GetHealth() == 0);
REQUIRE(card.GetName().empty());
REQUIRE(card.GetImage().empty());
REQUIRE(card.GetNumber() == 0);
REQUIRE(card.GetMatch().empty());
}
TEST_CASE("All Getter Methods") {
string name = "Get 100 on Final";
string match = "No Excuses";
string file = "victory.jpeg";
Card hit(1000000000,name, match, 126, file);
REQUIRE(hit.GetHealth() == 1000000000);
REQUIRE(hit.GetName() == "Get 100 on Final");
REQUIRE(hit.GetImage() == "victory.jpeg");
REQUIRE(hit.GetNumber() == 126);
REQUIRE(hit.GetMatch() == "No Excuses");
}
| 26.47541
| 47
| 0.640867
|
CS126SP20
|
1fdcb224cf4a350197282ffa908afba6259459c7
| 3,043
|
cpp
|
C++
|
src/common/Auth.cpp
|
aafemt/firebird
|
6f5617524996a8ef6eb721cc782d7fa3513b7d3b
|
[
"Condor-1.1"
] | 1
|
2021-04-04T12:16:07.000Z
|
2021-04-04T12:16:07.000Z
|
src/common/Auth.cpp
|
mistmist/firebird
|
d31495be14daa8bca46c879bdaf0e30194abd891
|
[
"Condor-1.1"
] | null | null | null |
src/common/Auth.cpp
|
mistmist/firebird
|
d31495be14daa8bca46c879bdaf0e30194abd891
|
[
"Condor-1.1"
] | null | null | null |
/*
* PROGRAM: Firebird authentication
* MODULE: Auth.cpp
* DESCRIPTION: Implementation of interfaces, passed to plugins
* Plugins loader
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
*
* Software distributed under the License is distributed AS IS,
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific language governing rights
* and limitations under the License.
*
* The Original Code was created by Alex Peshkov
* for the Firebird Open Source RDBMS project.
*
* Copyright (c) 2010 Alex Peshkov <peshkoff at mail.ru>
* and all contributors signed below.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "firebird.h"
#include "../common/Auth.h"
#include "../jrd/ibase.h"
#include "../common/classes/ImplementHelper.h"
#include "../common/utils_proto.h"
#include "../common/db_alias.h"
using namespace Firebird;
namespace Auth {
WriterImplementation::WriterImplementation()
: current(*getDefaultMemoryPool(), ClumpletReader::WideUnTagged, MAX_DPB_SIZE),
result(*getDefaultMemoryPool(), ClumpletReader::WideUnTagged, MAX_DPB_SIZE),
plugin(*getDefaultMemoryPool()), type(*getDefaultMemoryPool()),
sequence(0)
{ }
void WriterImplementation::store(ClumpletWriter* to, unsigned char tag)
{
putLevel();
if (to)
{
to->deleteWithTag(tag);
to->insertBytes(tag, result.getBuffer(), result.getBufferLength());
}
}
void WriterImplementation::reset()
{
result.clear();
current.clear();
sequence = 0;
}
void WriterImplementation::add(Firebird::CheckStatusWrapper* st, const char* name)
{
try
{
putLevel();
current.clear();
current.insertString(AuthReader::AUTH_NAME, name, strlen(name));
fb_assert(plugin.hasData());
if (plugin.hasData())
{
current.insertString(AuthReader::AUTH_PLUGIN, plugin);
}
type = "USER";
}
catch (const Firebird::Exception& ex)
{
ex.stuffException(st);
}
}
void WriterImplementation::setPlugin(const char* m)
{
plugin = m;
}
void WriterImplementation::putLevel()
{
current.rewind();
if (current.isEof())
{
return;
}
current.insertString(AuthReader::AUTH_TYPE, type);
result.insertBytes(sequence++, current.getBuffer(), current.getBufferLength());
}
void WriterImplementation::setType(Firebird::CheckStatusWrapper* st, const char* value)
{
try
{
if (value)
type = value;
}
catch (const Firebird::Exception& ex)
{
ex.stuffException(st);
}
}
void WriterImplementation::setDb(Firebird::CheckStatusWrapper* st, const char* value)
{
try
{
if (value)
{
PathName target;
expandDatabaseName(value, target, NULL);
current.insertPath(AuthReader::AUTH_SECURE_DB, target);
}
}
catch (const Firebird::Exception& ex)
{
ex.stuffException(st);
}
}
} // namespace Auth
| 23.05303
| 87
| 0.717713
|
aafemt
|
1feb501116316bf198728b9b2936c49afdd93823
| 27,607
|
cpp
|
C++
|
speedcc/lua-support/src/native/SCLuaRegisterSCRole.cpp
|
kevinwu1024/SpeedCC
|
7b32e3444236d8aebf8198ebc3fede8faf201dee
|
[
"MIT"
] | 7
|
2018-03-10T02:01:49.000Z
|
2021-09-14T15:42:10.000Z
|
speedcc/lua-support/src/native/SCLuaRegisterSCRole.cpp
|
kevinwu1024/SpeedCC
|
7b32e3444236d8aebf8198ebc3fede8faf201dee
|
[
"MIT"
] | null | null | null |
speedcc/lua-support/src/native/SCLuaRegisterSCRole.cpp
|
kevinwu1024/SpeedCC
|
7b32e3444236d8aebf8198ebc3fede8faf201dee
|
[
"MIT"
] | 1
|
2018-03-10T02:01:58.000Z
|
2018-03-10T02:01:58.000Z
|
/****************************************************************************
Copyright (c) 2017-2020 Kevin Wu (Wu Feng)
github: http://github.com/kevinwu1024
Licensed under the MIT License (the "License"); you may not use this file except
in compliance with the License. You may obtain a copy of the License at
http://opensource.org/licenses/MIT
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "platform/CCPlatformConfig.h"
#include "../../../stage/SCRole.h"
#include "../../../stage/SCStage.h"
#include "scripting/lua-bindings/manual/CCComponentLua.h"
#include "scripting/lua-bindings/manual/tolua_fix.h"
#include "scripting/lua-bindings/manual/LuaBasicConversions.h"
#include "scripting/lua-bindings/manual/CCLuaEngine.h"
#include "SCLuaUtils.h"
NAMESPACE_SPEEDCC_BEGIN
#ifdef __cplusplus
extern "C" {
#endif
#define SCLUA_MODULE "SCRole"
#define SCLUA_CLASSTYPE_LUA "sc." SCLUA_MODULE
#define SCLUA_CLASSTYPE_CPP SCRole::Ptr
#define SCLUA_OBJ_CONTAINER SMessageMatchContainer
#define SCLUA_MODULE_BASE "sc.SCPropertyHolder"
///------------ SCRole
int lua_speedcc_SCRole_addActor(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 1)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
SCActor::Ptr arg0;
bool ok = true;
ok = SCLuaUtils::luaValue2Actor(tolua_S, 2, arg0, "sc.SCRole:addActor");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
auto result = pRawInstance->addActor(arg0);
lua_pushboolean(tolua_S, result);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 1);
return 0;
}
int lua_speedcc_SCRole_removeActor(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 1)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
int arg0;
bool ok = true;
ok = luaval_to_int32(tolua_S, 2, &arg0, "sc.SCRole:removeActor");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
pRawInstance->removeActor(arg0);
lua_settop(tolua_S,1);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 1);
return 0;
}
int lua_speedcc_SCRole_hasActor(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 1)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
int arg0;
bool ok = true;
ok = luaval_to_int32(tolua_S, 2, &arg0, "sc.SCRole:hasActor");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
auto result = pRawInstance->hasActor(arg0);
lua_pushinteger(tolua_S,result);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 1);
return 0;
}
int lua_speedcc_SCRole_getActor(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 1)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
int arg0;
bool ok = true;
ok = luaval_to_int32(tolua_S, 2, &arg0, "sc.SCRole:getActor");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
auto result = pRawInstance->getActor(arg0);
auto obj = SCMemAllocator::newObject<SCObject::Ptr>();
(*obj) = result;
tolua_pushusertype_and_takeownership(tolua_S, (void*)obj, "sc.SCActor");
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 1);
return 0;
}
int lua_speedcc_SCRole_setInitStrategyID(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 1)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
int arg0;
bool ok = true;
ok = luaval_to_int32(tolua_S, 2, &arg0, "sc.SCRole:setInitStrategyID");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
auto result = pRawInstance->setInitStrategyID(arg0);
lua_pushboolean(tolua_S,result);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 1);
return 0;
}
int lua_speedcc_SCRole_addStrategy(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 1)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
SCStrategy::Ptr arg0;
bool ok = true;
ok = SCLuaUtils::luaValue2Strategy(tolua_S, 2, arg0, "sc.SCRole:addStrategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
pRawInstance->addStrategy(arg0);
lua_settop(tolua_S,1);
return 1;
}
else if (nArgc == 2)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
SCStrategy::Ptr arg0;
int arg1;
bool ok = true;
ok = SCLuaUtils::luaValue2Strategy(tolua_S, 2, arg0, "sc.SCRole:addStrategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
ok = luaval_to_int32(tolua_S, 3, &arg1, "sc.SCRole:addStrategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
pRawInstance->addStrategy(arg0, arg1);
lua_settop(tolua_S, 1);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 1);
return 0;
}
int lua_speedcc_SCRole_getStrategy(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 1)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
int arg0;
bool ok = true;
ok = luaval_to_int32(tolua_S, 2, &arg0, "sc.SCRole:getStrategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
auto result = pRawInstance->getStrategy(arg0);
auto obj = SCMemAllocator::newObject<SCObject::Ptr>();
(*obj) = result;
tolua_pushusertype_and_takeownership(tolua_S, (void*)obj, "sc.SCStrategy");
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 1);
return 0;
}
int lua_speedcc_SCRole_getStrategyInfo(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 1)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
int arg0;
bool ok = true;
ok = luaval_to_int32(tolua_S, 2, &arg0, "sc.SCRole:getStrategyInfo");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
auto result = pRawInstance->getStrategyInfo(arg0);
auto obj = SCMemAllocator::newObject<SCObject::Ptr>();
(*obj) = result;
tolua_pushusertype_and_takeownership(tolua_S, (void*)obj, "sc.SCStrategyInfo");
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 1);
return 0;
}
int lua_speedcc_SCRole_hasStrategy(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 1)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
int arg0;
bool ok = true;
ok = luaval_to_int32(tolua_S, 2, &arg0, "sc.SCRole:hasStrategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
auto result = pRawInstance->hasStrategy(arg0);
lua_pushboolean(tolua_S, result);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 1);
return 0;
}
int lua_speedcc_SCRole_forEach(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 1)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
int handler = toluafix_ref_function(tolua_S, 2, 0);
SCLUA_CHECK_LUA_ARG(tolua_S, handler);
pRawInstance->forEach([tolua_S, handler](SCActor::Ptr& ptrActor) -> bool
{
toluafix_get_function_by_refid(tolua_S, handler); /* L: ... func */
if (!lua_isfunction(tolua_S, -1))
{
luaL_error(tolua_S, " function refid '%d' does not reference a Lua function\n ", handler);
lua_pop(tolua_S, 1);
return false;
}
tolua_pushusertype(tolua_S, (void*)&ptrActor, "sc.SCActor");
int ret = lua_pcall(tolua_S, 1, 1, 0);
if (ret != 0)
{
lua_error(tolua_S);
}
return lua_toboolean(tolua_S, 1);
});
lua_settop(tolua_S,0);
return 0;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 1);
return 0;
}
int lua_speedcc_SCRole_addBehavior2Strategy(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 3)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
int arg0;
SCMessageMatcher::Ptr arg1;
SCBehavior::Ptr arg2;
bool ok;
ok = luaval_to_int32(tolua_S, 2, &arg0, "sc.SCRole:addBehavior2Strategy"); //SCLuaUtils::luaValue2MessageMatcher(tolua_S, 2, arg1, "sc.SCRole:addBehavior2Strategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
ok = SCLuaUtils::luaValue2MessageMatcher(tolua_S, 3, arg1, "sc.SCRole:addBehavior2Strategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
ok = SCLuaUtils::luaValue2Behavior(tolua_S, 4, arg2, "sc.SCRole:addBehavior2Strategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
auto result = pRawInstance->addBehavior2Strategy(arg0, arg1, arg2);
lua_pushboolean(tolua_S, result);
return 1;
}
else if (nArgc == 4)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
int arg0;
SCBehavior::Ptr arg2;
SCMessageMatcher::Ptr arg3;
bool ok;
ok = luaval_to_int32(tolua_S, 2, &arg0, "sc.SCRole:addBehavior2Strategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
ok = SCLuaUtils::luaValue2Behavior(tolua_S, 4, arg2, "sc.SCRole:addBehavior2Strategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
ok = SCLuaUtils::luaValue2MessageMatcher(tolua_S, 5, arg3, "sc.SCRole:addBehavior2Strategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
if (lua_isstring(tolua_S, 3))
{
SCString arg1;
ok = SCLuaUtils::luaValue2String(tolua_S, 3, arg1, "sc.SCRole:addBehavior2Strategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
auto result = pRawInstance->addBehavior2Strategy(arg0, arg1, arg2, arg3);
lua_pushboolean(tolua_S, result);
return 1;
}
else if (lua_isnumber(tolua_S, 3))
{
int arg1;
ok = luaval_to_int32(tolua_S, 3, &arg1, "sc.SCRole:addBehavior2Strategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
auto result = pRawInstance->addBehavior2Strategy(arg0, arg1, arg2, arg3);
lua_pushboolean(tolua_S, result);
return 1;
}
SCLUA_CHECK_LUA_ARG(tolua_S, false);
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting 3 or 4\n ", SCLUA_CLASSTYPE_LUA, nArgc);
return 0;
}
int lua_speedcc_SCRole_addEnterBehavior2Strategy(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 2)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
int arg0;
SCBehavior::Ptr arg1;
bool ok;
ok = luaval_to_int32(tolua_S, 2, &arg0, "sc.SCRole:addEnterBehavior2Strategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
ok = SCLuaUtils::luaValue2Behavior(tolua_S, 3, arg1, "sc.SCRole:addEnterBehavior2Strategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
auto result = pRawInstance->addEnterBehavior2Strategy(arg0, arg1);
lua_pushboolean(tolua_S, result);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 2);
return 0;
}
int lua_speedcc_SCRole_addExitBehavior2Strategy(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 2)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
int arg0;
SCBehavior::Ptr arg1;
bool ok;
ok = luaval_to_int32(tolua_S, 2, &arg0, "sc.SCRole:addExitBehavior2Strategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
ok = SCLuaUtils::luaValue2Behavior(tolua_S, 3, arg1, "sc.SCRole:addExitBehavior2Strategy");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
auto result = pRawInstance->addExitBehavior2Strategy(arg0, arg1);
lua_pushboolean(tolua_S, result);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 2);
return 0;
}
int lua_speedcc_SCRole_getStage(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 0)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
SCStage* pStage = pRawInstance->getStage();
auto obj = SCMemAllocator::newObject<SLuaObjectContainer>();
obj->pWeakObj = pStage;
tolua_pushusertype_and_takeownership(tolua_S, (void*)obj, "sc.SCStage");
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 0);
return 0;
}
int lua_speedcc_SCRole_update(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 1)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
SCMessage::Ptr arg0;
bool ok;
ok = SCLuaUtils::luaValue2Message(tolua_S, 2, arg0, "sc.SCRole:update");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
auto result = pRawInstance->update(arg0);
lua_pushboolean(tolua_S,result);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 1);
return 0;
}
int lua_speedcc_SCRole_getMsgFilterEnabled(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 0)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
auto result = pRawInstance->getMsgFilterEnabled();
lua_pushboolean(tolua_S, result);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 0);
return 0;
}
int lua_speedcc_SCRole_setMsgFilterEnabled(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_USERTYPE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 1)
{
auto pContainer = (SCLUA_OBJ_CONTAINER*)tolua_tousertype(tolua_S, 1, 0);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer);
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pContainer->ptrObj != nullptr || pContainer->pWeakObj != nullptr);
SCLUA_CLASSTYPE_CPP::type* pRawInstance = nullptr;
if (pContainer->ptrObj != nullptr)
{
auto ptr = pContainer->ptrObj.cast<SCLUA_CLASSTYPE_CPP>();
pRawInstance = ptr.getRawPointer();
}
else if (pContainer->pWeakObj)
{
pRawInstance = dynamic_cast<SCLUA_CLASSTYPE_CPP::type*>(pContainer->pWeakObj);
}
SCLUA_CHECK_LUA_INSTANCE(tolua_S, pRawInstance != nullptr);
bool arg0;
bool ok;
ok = luaval_to_boolean(tolua_S, 2, &arg0, "sc.SCRole:setMsgFilterEnabled");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
pRawInstance->setMsgFilterEnabled(arg0);
lua_settop(tolua_S,1);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 1);
return 0;
}
int lua_speedcc_SCRole_create(lua_State* tolua_S)
{
SCLUA_CHECK_LUA_TABLE(tolua_S);
auto nArgc = lua_gettop(tolua_S) - 1;
if (nArgc == 2)
{
int arg0;
SCStage::Ptr arg1;
bool ok;
ok = luaval_to_int32(tolua_S, 2, &arg0, "sc.SCRole:create");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
ok = SCLuaUtils::luaValue2Stage(tolua_S, 3, arg1, "sc.SCRole:create");
SCLUA_CHECK_LUA_ARG(tolua_S, ok);
auto obj = SCMemAllocator::newObject<SCLUA_OBJ_CONTAINER>();
obj->ptrObj = SCRole::create(arg0, arg1.getRawPointer());
tolua_pushusertype_and_takeownership(tolua_S, (void*)obj, SCLUA_CLASSTYPE_LUA);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", SCLUA_CLASSTYPE_LUA, nArgc, 2);
return 0;
}
SCLUA_SCDESTRUCT_PTR_FUNC_IMPLEMENT(SCRole)
int lua_register_speedcc_SCRole(lua_State* tolua_S)
{
tolua_usertype(tolua_S, SCLUA_CLASSTYPE_LUA);
tolua_cclass(tolua_S, SCLUA_MODULE, SCLUA_CLASSTYPE_LUA, SCLUA_MODULE_BASE, lua_speedcc_SCRole_destruct);
tolua_beginmodule(tolua_S, SCLUA_MODULE);
tolua_function(tolua_S, "create", lua_speedcc_SCRole_create);
tolua_function(tolua_S, "addActor", lua_speedcc_SCRole_addActor);
tolua_function(tolua_S, "removeActor", lua_speedcc_SCRole_removeActor);
tolua_function(tolua_S, "hasActor", lua_speedcc_SCRole_hasActor);
tolua_function(tolua_S, "getActor", lua_speedcc_SCRole_getActor);
tolua_function(tolua_S, "setInitStrategyID", lua_speedcc_SCRole_setInitStrategyID);
tolua_function(tolua_S, "addStrategy", lua_speedcc_SCRole_addStrategy);
tolua_function(tolua_S, "getStrategy", lua_speedcc_SCRole_getStrategy);
tolua_function(tolua_S, "getStrategyInfo", lua_speedcc_SCRole_getStrategyInfo);
tolua_function(tolua_S, "hasStrategy", lua_speedcc_SCRole_hasStrategy);
tolua_function(tolua_S, "forEach", lua_speedcc_SCRole_forEach);
tolua_function(tolua_S, "addBehavior2Strategy", lua_speedcc_SCRole_addBehavior2Strategy);
tolua_function(tolua_S, "addEnterBehavior2Strategy", lua_speedcc_SCRole_addEnterBehavior2Strategy);
tolua_function(tolua_S, "addExitBehavior2Strategy", lua_speedcc_SCRole_addExitBehavior2Strategy);
tolua_function(tolua_S, "getStage", lua_speedcc_SCRole_getStage);
tolua_function(tolua_S, "update", lua_speedcc_SCRole_update);
tolua_function(tolua_S, "getMsgFilterEnabled", lua_speedcc_SCRole_getMsgFilterEnabled);
tolua_function(tolua_S, "setMsgFilterEnabled", lua_speedcc_SCRole_setMsgFilterEnabled);
tolua_endmodule(tolua_S);
return 1;
}
#ifdef __cplusplus
}
#endif
NAMESPACE_SPEEDCC_END
| 31.371591
| 167
| 0.736697
|
kevinwu1024
|
1fecb9a81d9d32650e56086b4bda045376c4a573
| 1,084
|
cpp
|
C++
|
code/Hackers_with_Bits.cpp
|
Shiv-sharma-111/Data-Structure
|
4ce78da070ca2fb3a8552e9997e2607be25ff16e
|
[
"MIT"
] | null | null | null |
code/Hackers_with_Bits.cpp
|
Shiv-sharma-111/Data-Structure
|
4ce78da070ca2fb3a8552e9997e2607be25ff16e
|
[
"MIT"
] | null | null | null |
code/Hackers_with_Bits.cpp
|
Shiv-sharma-111/Data-Structure
|
4ce78da070ca2fb3a8552e9997e2607be25ff16e
|
[
"MIT"
] | null | null | null |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,count=0;
vector<int> v;
cin>>n;
int *arr=new int[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
for(int i=0;i<n;i++)
{
if(arr[i]==1)
{
count++;
}
else if(arr[i-1]==1 && arr[i]==0)
{
count++;
}
else
{
v.push_back(count);
count=0;
}
}
int l=v.size();
if(v.size()==0)
{
cout<<count-1<<endl;
}
else
{
sort(v.begin(),v.end());
cout<<v[l-1]-1<<endl;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Second approach
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a,i,c=0,o=0,j,z=0,minz=0,maxo=0;
vector<int> v;
for(i=0;i<n;i++)
{
cin>>a;
if(a==0)
minz++;
v.push_back(a);
}
for(i=0;i<n;i++)
{for(j=i;j<n;j++)
{
o=count(v.begin()+i,v.begin()+j,1);
z=count(v.begin()+i,v.begin()+j,0);
if((o>maxo)&&(z<=1))
maxo=o;
if(z>1)
break;
}
}
if(v.size()==minz)
cout<<0<<'\n';
else cout<<maxo+1<<'\n';
return 0;
}
| 14.453333
| 112
| 0.433579
|
Shiv-sharma-111
|
1fed03fef0d3b8d30793896bc84060e9cbd8c093
| 956
|
cpp
|
C++
|
src/arken/digest/sha1/embedded.cpp
|
charonplatform/charonplatform
|
ba5f711b2f8a8da760ccb71925d21a53f3255817
|
[
"BSD-3-Clause"
] | 1
|
2018-01-26T14:54:27.000Z
|
2018-01-26T14:54:27.000Z
|
src/arken/digest/sha1/embedded.cpp
|
arken-dev/arken
|
ba5f711b2f8a8da760ccb71925d21a53f3255817
|
[
"BSD-3-Clause"
] | null | null | null |
src/arken/digest/sha1/embedded.cpp
|
arken-dev/arken
|
ba5f711b2f8a8da760ccb71925d21a53f3255817
|
[
"BSD-3-Clause"
] | null | null | null |
// Copyright 2016 The Arken Platform Authors.
// All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include <arken/base>
extern "C" {
#include <digest/sha1.h>
}
using namespace arken::digest;
char * sha1::hash(const char * hash)
{
return sha1::hash(hash, strlen(hash));
}
char * sha1::hash(const char * hash, int length)
{
unsigned char x[40];
char * out = new char[41];
int i;
sha1_buffer (hash, length, x);
for (i = 0; i < 20; i++)
sprintf (out + 2 * i, "%02x", x[i]);
out[40] = '\0';
return out;
}
char * sha1::file(const char * path)
{
char * buffer;
std::ifstream file;
int length;
file.open(path);
file.seekg(0, std::ios::end);
length = file.tellg();
file.seekg(0, std::ios::beg);
buffer = new char[length];
file.read(buffer, length);
file.close();
char * result = hash(buffer, length);
delete[] buffer;
return result;
}
| 19.510204
| 53
| 0.630753
|
charonplatform
|
1feeef5d9c4218cccc624393d386090413a9133b
| 3,321
|
cpp
|
C++
|
src/tools/dedicated_arbitrator/client.cpp
|
afrostalin/FireNET
|
212bd7b0bf5a3ceef4c19fe527c7f23e624e296b
|
[
"BSL-1.0"
] | 27
|
2015-12-22T20:29:12.000Z
|
2021-06-05T18:25:27.000Z
|
src/tools/dedicated_arbitrator/client.cpp
|
afrostalin/FireNET
|
212bd7b0bf5a3ceef4c19fe527c7f23e624e296b
|
[
"BSL-1.0"
] | 36
|
2015-06-14T15:17:19.000Z
|
2017-12-28T16:01:02.000Z
|
src/tools/dedicated_arbitrator/client.cpp
|
afrostalin/FireNET
|
212bd7b0bf5a3ceef4c19fe527c7f23e624e296b
|
[
"BSL-1.0"
] | 14
|
2016-01-14T11:15:47.000Z
|
2021-05-04T20:24:46.000Z
|
// Copyright (C) 2014-2018 Ilya Chernetsov. All rights reserved. Contacts: <chernecoff@gmail.com>
// License: https://github.com/afrostalin/FireNET/blob/master/LICENSE
#include "global.h"
#include "client.h"
#include <QTcpServer>
RemoteClient::RemoteClient(QObject *parent) : QObject(parent),
m_socket(nullptr),
bLastMsgSended(true),
bConnected(false)
{
connect(&m_Timer, &QTimer::timeout, this, &RemoteClient::Update);
m_Timer.start(33);
}
void RemoteClient::Update()
{
if (bConnected && bLastMsgSended && m_packets.size() > 0)
{
CTcpPacket packet = m_packets.front();
m_packets.pop();
bLastMsgSended = false;
m_socket->write(packet.toString());
}
}
void RemoteClient::ConnectToServer(const QString &ip, int port)
{
LogInfo("Connecting to FireNet...");
m_socket = new QSslSocket(this);
connect(m_socket, &QSslSocket::encrypted, this, &RemoteClient::onConnectedToServer);
connect(m_socket, &QSslSocket::readyRead, this, &RemoteClient::onReadyRead);
connect(m_socket, &QSslSocket::disconnected, this, &RemoteClient::onDisconnected);
connect(m_socket, &QSslSocket::bytesWritten, this, &RemoteClient::onBytesWritten);
m_socket->addCaCertificates("key.pem");
m_socket->connectToHostEncrypted(ip ,port);
if(!m_socket->waitForEncrypted(3000))
{
LogError("Connection timeout");
}
}
void RemoteClient::SendMessage(CTcpPacket &packet)
{
m_packets.push(packet);
}
void RemoteClient::onConnectedToServer()
{
LogInfo("Connected to FireNET");
bConnected = true;
LogInfo("Registering in arbitrator mode...");
CTcpPacket packet(EFireNetTcpPacketType::Query);
packet.WriteQuery(EFireNetTcpQuery::RegisterArbitrator);
packet.WriteString(gEnv->m_Name.toStdString().c_str());
packet.WriteInt(gEnv->m_GameServersMaxCount);
packet.WriteInt(gEnv->m_GameServersCount);
SendMessage(packet);
}
void RemoteClient::onReadyRead()
{
if (m_socket)
{
CTcpPacket packet(m_socket->readAll());
EFireNetTcpPacketType packetType = packet.getType();
switch (packetType)
{
case EFireNetTcpPacketType::Empty:
break;
case EFireNetTcpPacketType::Query:
break;
case EFireNetTcpPacketType::Result:
ReadResult(packet);
break;
case EFireNetTcpPacketType::Error:
ReadError(packet);
break;
case EFireNetTcpPacketType::ServerMessage:
break;
default:
break;
}
}
}
void RemoteClient::onBytesWritten(qint64 bytes)
{
bLastMsgSended = true;
}
void RemoteClient::onDisconnected()
{
LogWarning("Connection with FireNET lost!");
bConnected = false;
}
void RemoteClient::ReadResult(CTcpPacket & packet) const
{
EFireNetTcpResult result = packet.ReadResult();
switch (result)
{
case EFireNetTcpResult::RegisterArbitratorComplete:
{
LogInfo("Succesfully register in arbitrator mode");
break;
}
case EFireNetTcpResult::UpdateArbitratorComplete:
{
LogInfo("Succesfully update arbitrator data");
break;
}
default:
break;
}
}
void RemoteClient::ReadError(CTcpPacket & packet) const
{
EFireNetTcpError error = packet.ReadError();
switch (error)
{
case EFireNetTcpError::RegisterArbitratorFail:
{
LogError("Can't register in arbitrator mode!");
break;
}
case EFireNetTcpError::UpdateArbitratorFail:
{
LogError("Can't update arbitrator data in FireNet");
break;
}
default:
break;
}
}
| 22.288591
| 97
| 0.73231
|
afrostalin
|
1ff336a533d933201a6259e1e122e9ed17a472f9
| 6,195
|
cpp
|
C++
|
sgfx/src/image.cpp
|
keithoma/the_shape_of_data
|
143f94685f5b77e562463f158cc97544579f14ad
|
[
"MIT"
] | null | null | null |
sgfx/src/image.cpp
|
keithoma/the_shape_of_data
|
143f94685f5b77e562463f158cc97544579f14ad
|
[
"MIT"
] | null | null | null |
sgfx/src/image.cpp
|
keithoma/the_shape_of_data
|
143f94685f5b77e562463f158cc97544579f14ad
|
[
"MIT"
] | null | null | null |
#include <sgfx/color.hpp>
#include <sgfx/image.hpp>
#include <sgfx/ppm.hpp>
#include <sgfx/primitive_types.hpp>
#include <sgfx/primitives.hpp>
//#include "sysconfig.h"
#include <experimental/filesystem>
#include <algorithm>
#include <fstream>
#include <map>
#include <sstream>
#include <stdexcept>
#include <string>
#include <utility>
#include <cassert>
using namespace std;
using namespace std::experimental;
#define let auto /* Pure provocation with respect to my dire love to F# & my hate to C++ auto keyword. */
namespace {
template <typename T>
T read(std::istream& source)
{
T value;
source.read((char*) &value, sizeof(value));
return value;
}
template <typename T>
void write(std::ostream& os, T const& value)
{
os.write((char*) &value, sizeof(value));
}
} // namespace
namespace sgfx {
canvas load_ppm(const std::string& _path)
{
experimental::filesystem::path path{_path};
let fileSize = experimental::filesystem::file_size(path);
let data = string{};
data.resize(fileSize);
ifstream ifs{path, ios::binary};
if (!ifs.is_open())
throw runtime_error("Could not open file.");
ifs.read(data.data(), fileSize);
if (static_cast<size_t>(ifs.tellg()) < static_cast<size_t>(fileSize))
{
auto msg = ostringstream{};
msg << "Expected to read " << fileSize << " bytes but only read " << ifs.tellg() << " bytes.";
throw runtime_error{msg.str()};
}
return ppm::Parser{}.parseString(data);
}
void save_ppm(widget const& image, const std::string& filename)
{
let os = ofstream{filename};
os << "P3\n"
<< "# Created by Gods of Code\n"
<< image.width() << ' ' << image.height() << '\n'
<< "255\n";
let const pixelWriter = [&](let pixel) {
os << pixel.red() << ' ' << pixel.green() << ' ' << pixel.blue() << '\n';
};
for_each(cbegin(image.pixels()), cend(image.pixels()), pixelWriter);
}
void rle_image::encodeLine(std::vector<uint8_t> const& input, std::vector<uint8_t>& output)
{
size_t i = 0;
while (i + 2 < input.size())
{
auto const red = input[i++];
auto const green = input[i++];
auto const blue = input[i++];
auto count = uint8_t{1};
while (i + 2 < input.size() && count < 255 && input[i] == red && input[i + 1] == green
&& input[i + 2] == blue)
{
i += 3;
++count;
}
output.push_back(count);
output.push_back(red);
output.push_back(green);
output.push_back(blue);
}
assert(i == input.size());
}
std::vector<rle_image::Run> rle_image::decodeLine(uint8_t const* line, size_t width)
{
let runs = vector<Run>(line[0] | (line[1] << 8));
line += 2;
for (unsigned i = 0; i < runs.size(); ++i)
{
let const length = *line++;
let const red = *line++;
let const green = *line++;
let const blue = *line++;
runs[i] = Run{length, color::rgb_color{red, green, blue}};
}
return runs;
}
rle_image load_rle(const std::string& filename)
{
let in = ifstream{filename, ios::binary};
if (!in.is_open())
throw std::runtime_error{"Could not open file."};
let const width = read<uint16_t>(in);
let const height = read<uint16_t>(in);
let lines = vector<vector<rle_image::Run>>();
while (in.good())
{
let runs = vector<rle_image::Run>(read<uint16_t>(in));
for (unsigned i = 0; i < runs.size(); ++i)
{
let const length = read<uint8_t>(in);
let const red = read<uint8_t>(in);
let const green = read<uint8_t>(in);
let const blue = read<uint8_t>(in);
runs[i] = rle_image::Run{length, color::rgb_color{red, green, blue}};
}
lines.emplace_back(move(runs));
// TODO: lines.emplace_back(rle_image::decodeLine(line, width));
}
return rle_image{dimension{width, height}, move(lines)};
}
void save_rle(const rle_image& image, const std::string& filename)
{
ofstream os{filename, ios::binary};
write<uint16_t>(os, image.dim().width);
write<uint16_t>(os, image.dim().height);
for (rle_image::Row const& row : image.rows())
{
write<uint16_t>(os, static_cast<uint16_t>(row.size()));
for (rle_image::Run const& run : row)
{
write<uint8_t>(os, run.length);
write<uint8_t>(os, run.color.red());
write<uint8_t>(os, run.color.green());
write<uint8_t>(os, run.color.blue());
}
}
}
rle_image rle_encode(widget& image)
{
using Run = rle_image::Run;
// reads one run, i.e. one color and all up to 255 following colors that match that first color.
auto readOne = [&image](int x, int y) -> Run {
let const color = image[point{x, y}];
let length = uint8_t{1};
++x;
while (x < image.width() && length < 255 && image[point{x, y}] == color)
++length, ++x;
return {length, color};
};
vector<rle_image::Row> rows;
rows.reserve(image.height());
for (int x = 0, y = 0; y < image.height(); x = 0, ++y)
rows.emplace_back([&]() {
rle_image::Row row;
for (auto run = readOne(x, y); run.length > 0; run = readOne(x, y), x += row.back().length)
row.emplace_back(move(run));
return row;
}());
return rle_image{dimension{image.width(), image.height()}, move(rows)};
}
void draw(widget& target, const rle_image& source, point top_left)
{
for (int x = 0, y = 0; y < source.dim().height; x = 0, ++y)
for (rle_image::Run const& run : source.row(y))
for (unsigned i = 0; i < run.length; ++i, ++x)
target[top_left + point{x, y}] = run.color;
}
void draw(widget& target, const rle_image& source, point top_left, color::rgb_color colorkey)
{
for (int x = 0, y = 0; y < source.dim().height; x = 0, ++y)
for (rle_image::Run const& run : source.row(y))
for (unsigned i = 0; i < run.length; ++i, ++x)
if (run.color != colorkey)
target[top_left + point{x, y}] = run.color;
}
} // namespace sgfx
| 27.780269
| 105
| 0.574496
|
keithoma
|
1ff4c9257fba55df1268dfdcb84d88921d3b23ca
| 7,759
|
cpp
|
C++
|
Classes/patterns/gamescene.cpp
|
wendy556609/Game_middle
|
de0cb13b1d4bea07c12c278972c9555a22ab24cc
|
[
"MIT"
] | null | null | null |
Classes/patterns/gamescene.cpp
|
wendy556609/Game_middle
|
de0cb13b1d4bea07c12c278972c9555a22ab24cc
|
[
"MIT"
] | null | null | null |
Classes/patterns/gamescene.cpp
|
wendy556609/Game_middle
|
de0cb13b1d4bea07c12c278972c9555a22ab24cc
|
[
"MIT"
] | null | null | null |
#include "GameScene.h"
USING_NS_CC;
GameScene::GameScene() {
_c3sButton = nullptr;
_midObj = nullptr;
_runner = nullptr;
_enemy = nullptr;
_Bar = nullptr;
}
GameScene::~GameScene() {
CC_SAFE_DELETE(_c3sButton);
CC_SAFE_DELETE(_midObj);
CC_SAFE_DELETE(_runner);
CC_SAFE_DELETE(_enemy);
CC_SAFE_DELETE(_Bar);
this->removeAllChildren();
SpriteFrameCache::getInstance()->removeSpriteFramesFromFile("gamescene.plist");
SpriteFrameCache::getInstance()->removeSpriteFramesFromFile("gamescene_object.plist");
Director::getInstance()->getTextureCache()->removeUnusedTextures();
AudioEngine::end();
}
Scene* GameScene::createScene()
{
return GameScene::create();
}
static void problemLoading(const char* filename)
{
printf("Error while loading: %s\n", filename);
printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in HelloWorldScene.cpp\n");
}
bool GameScene::init() {
if (!Scene::init()) { return false; }
auto visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
// 設定搜尋路徑
std::vector<std::string> searchPath;
searchPath.push_back("./patterns/");
CCFileUtils::getInstance()->setSearchPaths(searchPath);
auto rootNode = CSLoader::createNode("mainscene.csb");
this->addChild(rootNode); // 加入目前的 scene 中
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("gamescene.plist");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("gamescene_object.plist");
auto loctag = dynamic_cast<cocos2d::Node*>(rootNode->getChildByName("_runner"));
loctag->setVisible(false);
auto position = loctag->getPosition();
_runner = new (std::nothrow) CRunner();
_runner->init(position, *this, "runner_demo.csb", "collider", 3);
loctag = dynamic_cast<cocos2d::Sprite*>(rootNode->getChildByName("road00"));
loctag->setVisible(false);
position = loctag->getPosition();
_midObj = new (std::nothrow) CMiddleObject();
_midObj->init(position, *this, "road00");
loctag = dynamic_cast<cocos2d::Sprite*>(rootNode->getChildByName("jumpButton"));
loctag->setVisible(false);
position = loctag->getPosition();
_c3sButton = new (std::nothrow)C3SButton();
_c3sButton->init(_c3sButton->BtnType::jumpBtn, position, *this, "jumpnormal", "jumpon");
loctag = dynamic_cast<cocos2d::Sprite*>(rootNode->getChildByName("startButton"));
loctag->setVisible(false);
position = loctag->getPosition();
_c3sButton->init(_c3sButton->BtnType::startBtn, position, *this, "startnormal", "starton");
CScoring::create()->init(1, position, *this);
loctag = dynamic_cast<cocos2d::Sprite*>(rootNode->getChildByName("replaybtn"));
loctag->setVisible(false);
position = loctag->getPosition();
_c3sButton->init(_c3sButton->BtnType::restartBtn, position, *this, "replaybtn", "replaybtn");
loctag = dynamic_cast<cocos2d::Sprite*>(rootNode->getChildByName("speedButton"));
loctag->setVisible(false);
position = loctag->getPosition();
_c3sButton->init(_c3sButton->BtnType::runBtn, position, *this, "runnormal", "runon");
loctag = dynamic_cast<cocos2d::Sprite*>(rootNode->getChildByName("btn_cuber"));
loctag->setVisible(false);
position = loctag->getPosition();
_c3sButton->init(_c3sButton->BtnType::boardBtn, position, *this, "cuberbtn1", "cuberbtn2");
_enemy = new (std::nothrow)CEnemy();
_enemy->init(*this, _runner->getPosition());
loctag = dynamic_cast<cocos2d::Node*>(rootNode->getChildByName("scoreText"));
loctag->setVisible(false);
position = loctag->getPosition();
CScoring::getInstance()->init(0, position, *this);
loctag = dynamic_cast<cocos2d::Node*>(rootNode->getChildByName("LevelText"));
loctag->setVisible(false);
position = loctag->getPosition();
CScoring::getInstance()->init(2, position, *this);
loctag = dynamic_cast<cocos2d::Node*>(rootNode->getChildByName("bloodBar_track"));
loctag->setVisible(false);
position = loctag->getPosition();
_Bar = new (std::nothrow)CCanvas();
_Bar->init(1, position, *this);
loctag = dynamic_cast<cocos2d::Node*>(rootNode->getChildByName("gameSlider_track"));
loctag->setVisible(false);
position = loctag->getPosition();
_Bar->init(2, position, *this);
//創建一個一對一的事件聆聽器
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = CC_CALLBACK_2(GameScene::onTouchBegan, this);
listener->onTouchMoved = CC_CALLBACK_2(GameScene::onTouchMoved, this);//加入觸碰移動事件
listener->onTouchEnded = CC_CALLBACK_2(GameScene::onTouchEnded, this);//加入觸碰離開事件
this->_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); //加入剛創建的事件聆聽器
this->schedule(CC_SCHEDULE_SELECTOR(GameScene::update));
return true;
}
void GameScene::update(float dt) {
if (CScoring::getInstance()->getStart()) {
if (!CScoring::getInstance()->_isFinal) {
if (CScoring::getInstance()->_isInit) {
CScoring::getInstance()->_isInit = false;
_c3sButton->setEnable(true);
_c3sButton->setEnable(false, _c3sButton->BtnType::boardBtn);
}
_midObj->update(dt);
_runner->update(dt);
_enemy->update(dt);
_c3sButton->setEnable(!_runner->_isJump, _c3sButton->BtnType::jumpBtn);
if (_runner->_isJump) {
if (!_runner->passing) {
_runner->passing = _enemy->passPlayer(*_runner);
CScoring::getInstance()->currentScore = _enemy->getPassScore();
}
}
_enemy->setSpeed(CScoring::getInstance()->getMoveSpeed());
_midObj->setSpeed(CScoring::getInstance()->getMoveSpeed());
if (_enemy->checkCollider(*_runner)) {
if (!_runner->_isHurt) {
_runner->_faceTime = 0;
_runner->getHurt(_enemy->getHurt());
_runner->_isHurt = true;
_Bar->setBlood(_runner->_blood);
}
}
_Bar->update();
}
}
else {
if (!CScoring::getInstance()->_isInit) {
CScoring::getInstance()->initState();
_runner->initState();
_enemy->initState();
_midObj->initState();
_c3sButton->initState();
_Bar->initState();
_c3sButton->setEnable(true, _c3sButton->BtnType::boardBtn);
if (!CScoring::getInstance()->_isRestart) {
_c3sButton->setVisible(true);
_c3sButton->setEnable(true, _c3sButton->startBtn);
}
else {
CScoring::getInstance()->setStart(true, 1);
CScoring::getInstance()->setStart(false, 2);
}
CScoring::getInstance()->_isInit = true;
}
}
CScoring::getInstance()->update(dt);
}
bool GameScene::onTouchBegan(cocos2d::Touch* pTouch, cocos2d::Event* pEvent)//觸碰開始事件
{
Point touchLoc = pTouch->getLocation();
if (_c3sButton->touchesBegin(touchLoc, _c3sButton->BtnType::jumpBtn)) {
_runner->_isJump = true;
CScoring::getInstance()->setPlay(0, true);
}
_c3sButton->touchesBegin(touchLoc);
return true;
}
void GameScene::onTouchMoved(cocos2d::Touch* pTouch, cocos2d::Event* pEvent)//觸碰開始事件
{
Point touchLoc = pTouch->getLocation();
_c3sButton->touchesMove(touchLoc);
}
void GameScene::onTouchEnded(cocos2d::Touch* pTouch, cocos2d::Event* pEvent)//觸碰開始事件
{
Point touchLoc = pTouch->getLocation();
_c3sButton->touchesEnd(touchLoc);
}
| 34.484444
| 126
| 0.64596
|
wendy556609
|
1ffdd76e6dd27ce971c3c05de3d6c10c501ec640
| 751
|
cpp
|
C++
|
ClientMigration/TShared/Random.cpp
|
Fiskmans/ClientMigration
|
ab863986fb580b790c5918819878f86e8c5b4d6b
|
[
"MIT"
] | 1
|
2020-03-16T12:19:42.000Z
|
2020-03-16T12:19:42.000Z
|
ClientMigration/TShared/Random.cpp
|
Fiskmans/ClientMigration
|
ab863986fb580b790c5918819878f86e8c5b4d6b
|
[
"MIT"
] | null | null | null |
ClientMigration/TShared/Random.cpp
|
Fiskmans/ClientMigration
|
ab863986fb580b790c5918819878f86e8c5b4d6b
|
[
"MIT"
] | null | null | null |
#include <pch.h>
#include "Random.h"
#include <random>
std::mt19937& random()
{
static std::random_device seed;
#ifdef _DEBUG
static std::mt19937 rng(1337);
#else
static std::mt19937 rng(seed());
#endif // _DEBUG
return rng;
}
float Tools::RandomNormalized()
{
static std::uniform_real_distribution<float> dist(0.0f, 1.f);
return dist(random());
}
size_t Tools::RandomRange(size_t aMin, size_t aMax)
{
std::uniform_int_distribution<int> dist(aMin, aMax);
return dist(random());
}
int Tools::RandomRange(int aMin, int aMax)
{
std::uniform_int_distribution<int> dist(aMin, aMax);
return dist(random());
}
float Tools::RandomRange(float aMin, float aMax)
{
std::uniform_real_distribution<float> dist(aMin,aMax);
return dist(random());
}
| 19.25641
| 62
| 0.721704
|
Fiskmans
|
9504ef15e93b2e515c891570ccf262c9a9bcb67b
| 37,517
|
cpp
|
C++
|
01.Firmware/components/FabGL/src/emudevs/i8080.cpp
|
POMIN-163/xbw
|
ebda2fb925ec54e48e806ba1c3cd4e04a7b25368
|
[
"Apache-2.0"
] | 5
|
2022-02-14T03:12:57.000Z
|
2022-03-06T11:58:31.000Z
|
01.Firmware/components/FabGL/src/emudevs/i8080.cpp
|
POMIN-163/xbw
|
ebda2fb925ec54e48e806ba1c3cd4e04a7b25368
|
[
"Apache-2.0"
] | null | null | null |
01.Firmware/components/FabGL/src/emudevs/i8080.cpp
|
POMIN-163/xbw
|
ebda2fb925ec54e48e806ba1c3cd4e04a7b25368
|
[
"Apache-2.0"
] | 4
|
2022-02-23T07:00:59.000Z
|
2022-03-10T03:58:11.000Z
|
// Intel 8080 (KR580VM80A) microprocessor core model
//
// Copyright (C) 2012 Alexander Demin <alexander@demin.ws>
//
// Credits
//
// Viacheslav Slavinsky, Vector-06C FPGA Replica
// http://code.google.com/p/vector06cc/
//
// Dmitry Tselikov, Bashrikia-2M and Radio-86RK on Altera DE1
// http://bashkiria-2m.narod.ru/fpga.html
//
// Ian Bartholomew, 8080/8085 CPU Exerciser
// http://www.idb.me.uk/sunhillow/8080.html
//
// Frank Cringle, The original exerciser for the Z80.
//
// Thanks to zx.pk.ru and nedopc.org/forum communities.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//
// 2020 adapted by Fabrizio Di Vittorio for fabgl ESP32 library
#include "i8080.h"
#pragma GCC optimize ("O2")
namespace fabgl {
#define RD_BYTE(addr) m_readByte(m_context, addr)
#define RD_WORD(addr) m_readWord(m_context, addr)
#define WR_BYTE(addr, value) m_writeByte(m_context, addr, value)
#define WR_WORD(addr, value) m_writeWord(m_context, addr, value)
#define FLAGS cpu.f
#define AF cpu.af.w
#define BC cpu.bc.w
#define DE cpu.de.w
#define HL cpu.hl.w
#define SP cpu.sp.w
#define PC cpu.pc.w
#define A cpu.af.b.h
#define F cpu.af.b.l
#define B cpu.bc.b.h
#define C cpu.bc.b.l
#define D cpu.de.b.h
#define E cpu.de.b.l
#define H cpu.hl.b.h
#define L cpu.hl.b.l
#define HSP cpu.sp.b.h
#define LSP cpu.sp.b.l
#define HPC cpu.pc.b.h
#define LPC cpu.pc.b.l
#define IFF cpu.iff
#define F_CARRY 0x01
#define F_UN1 0x02
#define F_PARITY 0x04
#define F_UN3 0x08
#define F_HCARRY 0x10
#define F_UN5 0x20
#define F_ZERO 0x40
#define F_NEG 0x80
#define C_FLAG FLAGS.carry_flag
#define P_FLAG FLAGS.parity_flag
#define H_FLAG FLAGS.half_carry_flag
#define Z_FLAG FLAGS.zero_flag
#define S_FLAG FLAGS.sign_flag
#define UN1_FLAG FLAGS.unused1
#define UN3_FLAG FLAGS.unused3
#define UN5_FLAG FLAGS.unused5
#define SET(flag) (flag = 1)
#define CLR(flag) (flag = 0)
#define TST(flag) (flag)
#define CPL(flag) (flag = !flag)
#define POP(reg) { (reg) = RD_WORD(SP); SP += 2; }
#define PUSH(reg) { SP -= 2; WR_WORD(SP, (reg)); }
#define RET() { POP(PC); }
#define STC() { SET(C_FLAG); }
#define CMC() { CPL(C_FLAG); }
#define INR(reg) \
{ \
++(reg); \
S_FLAG = (((reg) & 0x80) != 0); \
Z_FLAG = ((reg) == 0); \
H_FLAG = (((reg) & 0x0f) == 0); \
P_FLAG = PARITY(reg); \
}
#define DCR(reg) \
{ \
--(reg); \
S_FLAG = (((reg) & 0x80) != 0); \
Z_FLAG = ((reg) == 0); \
H_FLAG = !(((reg) & 0x0f) == 0x0f); \
P_FLAG = PARITY(reg); \
}
#define ADD(val) \
{ \
work16 = (uint16_t)A + (val); \
index = ((A & 0x88) >> 1) | \
(((val) & 0x88) >> 2) | \
((work16 & 0x88) >> 3); \
A = work16 & 0xff; \
S_FLAG = ((A & 0x80) != 0); \
Z_FLAG = (A == 0); \
H_FLAG = half_carry_table[index & 0x7]; \
P_FLAG = PARITY(A); \
C_FLAG = ((work16 & 0x0100) != 0); \
}
#define ADC(val) \
{ \
work16 = (uint16_t)A + (val) + C_FLAG; \
index = ((A & 0x88) >> 1) | \
(((val) & 0x88) >> 2) | \
((work16 & 0x88) >> 3); \
A = work16 & 0xff; \
S_FLAG = ((A & 0x80) != 0); \
Z_FLAG = (A == 0); \
H_FLAG = half_carry_table[index & 0x7]; \
P_FLAG = PARITY(A); \
C_FLAG = ((work16 & 0x0100) != 0); \
}
#define SUB(val) \
{ \
work16 = (uint16_t)A - (val); \
index = ((A & 0x88) >> 1) | \
(((val) & 0x88) >> 2) | \
((work16 & 0x88) >> 3); \
A = work16 & 0xff; \
S_FLAG = ((A & 0x80) != 0); \
Z_FLAG = (A == 0); \
H_FLAG = !sub_half_carry_table[index & 0x7]; \
P_FLAG = PARITY(A); \
C_FLAG = ((work16 & 0x0100) != 0); \
}
#define SBB(val) \
{ \
work16 = (uint16_t)A - (val) - C_FLAG; \
index = ((A & 0x88) >> 1) | \
(((val) & 0x88) >> 2) | \
((work16 & 0x88) >> 3); \
A = work16 & 0xff; \
S_FLAG = ((A & 0x80) != 0); \
Z_FLAG = (A == 0); \
H_FLAG = !sub_half_carry_table[index & 0x7]; \
P_FLAG = PARITY(A); \
C_FLAG = ((work16 & 0x0100) != 0); \
}
#define CMP(val) \
{ \
work16 = (uint16_t)A - (val); \
index = ((A & 0x88) >> 1) | \
(((val) & 0x88) >> 2) | \
((work16 & 0x88) >> 3); \
S_FLAG = ((work16 & 0x80) != 0); \
Z_FLAG = ((work16 & 0xff) == 0); \
H_FLAG = !sub_half_carry_table[index & 0x7]; \
C_FLAG = ((work16 & 0x0100) != 0); \
P_FLAG = PARITY(work16 & 0xff); \
}
#define ANA(val) \
{ \
H_FLAG = ((A | val) & 0x08) != 0; \
A &= (val); \
S_FLAG = ((A & 0x80) != 0); \
Z_FLAG = (A == 0); \
P_FLAG = PARITY(A); \
CLR(C_FLAG); \
}
#define XRA(val) \
{ \
A ^= (val); \
S_FLAG = ((A & 0x80) != 0); \
Z_FLAG = (A == 0); \
CLR(H_FLAG); \
P_FLAG = PARITY(A); \
CLR(C_FLAG); \
}
#define ORA(val) \
{ \
A |= (val); \
S_FLAG = ((A & 0x80) != 0); \
Z_FLAG = (A == 0); \
CLR(H_FLAG); \
P_FLAG = PARITY(A); \
CLR(C_FLAG); \
}
#define DAD(reg) \
{ \
work32 = (uint32_t)HL + (reg); \
HL = work32 & 0xffff; \
C_FLAG = ((work32 & 0x10000L) != 0); \
}
#define CALL \
{ \
PUSH(PC + 2); \
PC = RD_WORD(PC); \
}
#define RST(addr) \
{ \
PUSH(PC); \
PC = (addr); \
}
#define PARITY(reg) getParity(reg)
int getParity(int val)
{
val ^= val >> 4;
val &= 0xf;
return !((0x6996 >> val) & 1);
}
static const int half_carry_table[] = { 0, 0, 1, 0, 1, 0, 1, 1 };
static const int sub_half_carry_table[] = { 0, 1, 1, 1, 0, 0, 0, 1 };
void i8080::reset()
{
C_FLAG = 0;
S_FLAG = 0;
Z_FLAG = 0;
H_FLAG = 0;
P_FLAG = 0;
UN1_FLAG = 1;
UN3_FLAG = 0;
UN5_FLAG = 0;
PC = 0xF800;
}
void i8080::store_flags()
{
if (S_FLAG) F |= F_NEG; else F &= ~F_NEG;
if (Z_FLAG) F |= F_ZERO; else F &= ~F_ZERO;
if (H_FLAG) F |= F_HCARRY; else F &= ~F_HCARRY;
if (P_FLAG) F |= F_PARITY; else F &= ~F_PARITY;
if (C_FLAG) F |= F_CARRY; else F &= ~F_CARRY;
F |= F_UN1; // UN1_FLAG is always 1.
F &= ~F_UN3; // UN3_FLAG is always 0.
F &= ~F_UN5; // UN5_FLAG is always 0.
}
void i8080::retrieve_flags()
{
S_FLAG = F & F_NEG ? 1 : 0;
Z_FLAG = F & F_ZERO ? 1 : 0;
H_FLAG = F & F_HCARRY ? 1 : 0;
P_FLAG = F & F_PARITY ? 1 : 0;
C_FLAG = F & F_CARRY ? 1 : 0;
}
int i8080::step()
{
int opcode = RD_BYTE(PC++);
int cpu_cycles;
switch (opcode) {
case 0x00: /* nop */
// Undocumented NOP.
case 0x08: /* nop */
case 0x10: /* nop */
case 0x18: /* nop */
case 0x20: /* nop */
case 0x28: /* nop */
case 0x30: /* nop */
case 0x38: /* nop */
cpu_cycles = 4;
break;
case 0x01: /* lxi b, data16 */
cpu_cycles = 10;
BC = RD_WORD(PC);
PC += 2;
break;
case 0x02: /* stax b */
cpu_cycles = 7;
WR_BYTE(BC, A);
break;
case 0x03: /* inx b */
cpu_cycles = 5;
BC++;
break;
case 0x04: /* inr b */
cpu_cycles = 5;
INR(B);
break;
case 0x05: /* dcr b */
cpu_cycles = 5;
DCR(B);
break;
case 0x06: /* mvi b, data8 */
cpu_cycles = 7;
B = RD_BYTE(PC++);
break;
case 0x07: /* rlc */
cpu_cycles = 4;
C_FLAG = ((A & 0x80) != 0);
A = (A << 1) | C_FLAG;
break;
case 0x09: /* dad b */
cpu_cycles = 10;
DAD(BC);
break;
case 0x0A: /* ldax b */
cpu_cycles = 7;
A = RD_BYTE(BC);
break;
case 0x0B: /* dcx b */
cpu_cycles = 5;
BC--;
break;
case 0x0C: /* inr c */
cpu_cycles = 5;
INR(C);
break;
case 0x0D: /* dcr c */
cpu_cycles = 5;
DCR(C);
break;
case 0x0E: /* mvi c, data8 */
cpu_cycles = 7;
C = RD_BYTE(PC++);
break;
case 0x0F: /* rrc */
cpu_cycles = 4;
C_FLAG = A & 0x01;
A = (A >> 1) | (C_FLAG << 7);
break;
case 0x11: /* lxi d, data16 */
cpu_cycles = 10;
DE = RD_WORD(PC);
PC += 2;
break;
case 0x12: /* stax d */
cpu_cycles = 7;
WR_BYTE(DE, A);
break;
case 0x13: /* inx d */
cpu_cycles = 5;
DE++;
break;
case 0x14: /* inr d */
cpu_cycles = 5;
INR(D);
break;
case 0x15: /* dcr d */
cpu_cycles = 5;
DCR(D);
break;
case 0x16: /* mvi d, data8 */
cpu_cycles = 7;
D = RD_BYTE(PC++);
break;
case 0x17: /* ral */
cpu_cycles = 4;
work8 = (uint8_t)C_FLAG;
C_FLAG = ((A & 0x80) != 0);
A = (A << 1) | work8;
break;
case 0x19: /* dad d */
cpu_cycles = 10;
DAD(DE);
break;
case 0x1A: /* ldax d */
cpu_cycles = 7;
A = RD_BYTE(DE);
break;
case 0x1B: /* dcx d */
cpu_cycles = 5;
DE--;
break;
case 0x1C: /* inr e */
cpu_cycles = 5;
INR(E);
break;
case 0x1D: /* dcr e */
cpu_cycles = 5;
DCR(E);
break;
case 0x1E: /* mvi e, data8 */
cpu_cycles = 7;
E = RD_BYTE(PC++);
break;
case 0x1F: /* rar */
cpu_cycles = 4;
work8 = (uint8_t)C_FLAG;
C_FLAG = A & 0x01;
A = (A >> 1) | (work8 << 7);
break;
case 0x21: /* lxi h, data16 */
cpu_cycles = 10;
HL = RD_WORD(PC);
PC += 2;
break;
case 0x22: /* shld addr */
cpu_cycles = 16;
WR_WORD(RD_WORD(PC), HL);
PC += 2;
break;
case 0x23: /* inx h */
cpu_cycles = 5;
HL++;
break;
case 0x24: /* inr h */
cpu_cycles = 5;
INR(H);
break;
case 0x25: /* dcr h */
cpu_cycles = 5;
DCR(H);
break;
case 0x26: /* mvi h, data8 */
cpu_cycles = 7;
H = RD_BYTE(PC++);
break;
case 0x27: /* daa */
cpu_cycles = 4;
carry = (uint8_t)C_FLAG;
add = 0;
if (H_FLAG || (A & 0x0f) > 9) {
add = 0x06;
}
if (C_FLAG || (A >> 4) > 9 || ((A >> 4) >= 9 && (A & 0x0f) > 9)) {
add |= 0x60;
carry = 1;
}
ADD(add);
P_FLAG = PARITY(A);
C_FLAG = carry;
break;
case 0x29: /* dad hl */
cpu_cycles = 10;
DAD(HL);
break;
case 0x2A: /* ldhl addr */
cpu_cycles = 16;
HL = RD_WORD(RD_WORD(PC));
PC += 2;
break;
case 0x2B: /* dcx h */
cpu_cycles = 5;
HL--;
break;
case 0x2C: /* inr l */
cpu_cycles = 5;
INR(L);
break;
case 0x2D: /* dcr l */
cpu_cycles = 5;
DCR(L);
break;
case 0x2E: /* mvi l, data8 */
cpu_cycles = 7;
L = RD_BYTE(PC++);
break;
case 0x2F: /* cma */
cpu_cycles = 4;
A ^= 0xff;
break;
case 0x31: /* lxi sp, data16 */
cpu_cycles = 10;
SP = RD_WORD(PC);
PC += 2;
break;
case 0x32: /* sta addr */
cpu_cycles = 13;
WR_BYTE(RD_WORD(PC), A);
PC += 2;
break;
case 0x33: /* inx sp */
cpu_cycles = 5;
SP++;
break;
case 0x34: /* inr m */
cpu_cycles = 10;
work8 = RD_BYTE(HL);
INR(work8);
WR_BYTE(HL, work8);
break;
case 0x35: /* dcr m */
cpu_cycles = 10;
work8 = RD_BYTE(HL);
DCR(work8);
WR_BYTE(HL, work8);
break;
case 0x36: /* mvi m, data8 */
cpu_cycles = 10;
WR_BYTE(HL, RD_BYTE(PC++));
break;
case 0x37: /* stc */
cpu_cycles = 4;
SET(C_FLAG);
break;
case 0x39: /* dad sp */
cpu_cycles = 10;
DAD(SP);
break;
case 0x3A: /* lda addr */
cpu_cycles = 13;
A = RD_BYTE(RD_WORD(PC));
PC += 2;
break;
case 0x3B: /* dcx sp */
cpu_cycles = 5;
SP--;
break;
case 0x3C: /* inr a */
cpu_cycles = 5;
INR(A);
break;
case 0x3D: /* dcr a */
cpu_cycles = 5;
DCR(A);
break;
case 0x3E: /* mvi a, data8 */
cpu_cycles = 7;
A = RD_BYTE(PC++);
break;
case 0x3F: /* cmc */
cpu_cycles = 4;
CPL(C_FLAG);
break;
case 0x40: /* mov b, b */
cpu_cycles = 4;
break;
case 0x41: /* mov b, c */
cpu_cycles = 5;
B = C;
break;
case 0x42: /* mov b, d */
cpu_cycles = 5;
B = D;
break;
case 0x43: /* mov b, e */
cpu_cycles = 5;
B = E;
break;
case 0x44: /* mov b, h */
cpu_cycles = 5;
B = H;
break;
case 0x45: /* mov b, l */
cpu_cycles = 5;
B = L;
break;
case 0x46: /* mov b, m */
cpu_cycles = 7;
B = RD_BYTE(HL);
break;
case 0x47: /* mov b, a */
cpu_cycles = 5;
B = A;
break;
case 0x48: /* mov c, b */
cpu_cycles = 5;
C = B;
break;
case 0x49: /* mov c, c */
cpu_cycles = 5;
break;
case 0x4A: /* mov c, d */
cpu_cycles = 5;
C = D;
break;
case 0x4B: /* mov c, e */
cpu_cycles = 5;
C = E;
break;
case 0x4C: /* mov c, h */
cpu_cycles = 5;
C = H;
break;
case 0x4D: /* mov c, l */
cpu_cycles = 5;
C = L;
break;
case 0x4E: /* mov c, m */
cpu_cycles = 7;
C = RD_BYTE(HL);
break;
case 0x4F: /* mov c, a */
cpu_cycles = 5;
C = A;
break;
case 0x50: /* mov d, b */
cpu_cycles = 5;
D = B;
break;
case 0x51: /* mov d, c */
cpu_cycles = 5;
D = C;
break;
case 0x52: /* mov d, d */
cpu_cycles = 5;
break;
case 0x53: /* mov d, e */
cpu_cycles = 5;
D = E;
break;
case 0x54: /* mov d, h */
cpu_cycles = 5;
D = H;
break;
case 0x55: /* mov d, l */
cpu_cycles = 5;
D = L;
break;
case 0x56: /* mov d, m */
cpu_cycles = 7;
D = RD_BYTE(HL);
break;
case 0x57: /* mov d, a */
cpu_cycles = 5;
D = A;
break;
case 0x58: /* mov e, b */
cpu_cycles = 5;
E = B;
break;
case 0x59: /* mov e, c */
cpu_cycles = 5;
E = C;
break;
case 0x5A: /* mov e, d */
cpu_cycles = 5;
E = D;
break;
case 0x5B: /* mov e, e */
cpu_cycles = 5;
break;
case 0x5C: /* mov c, h */
cpu_cycles = 5;
E = H;
break;
case 0x5D: /* mov c, l */
cpu_cycles = 5;
E = L;
break;
case 0x5E: /* mov c, m */
cpu_cycles = 7;
E = RD_BYTE(HL);
break;
case 0x5F: /* mov c, a */
cpu_cycles = 5;
E = A;
break;
case 0x60: /* mov h, b */
cpu_cycles = 5;
H = B;
break;
case 0x61: /* mov h, c */
cpu_cycles = 5;
H = C;
break;
case 0x62: /* mov h, d */
cpu_cycles = 5;
H = D;
break;
case 0x63: /* mov h, e */
cpu_cycles = 5;
H = E;
break;
case 0x64: /* mov h, h */
cpu_cycles = 5;
break;
case 0x65: /* mov h, l */
cpu_cycles = 5;
H = L;
break;
case 0x66: /* mov h, m */
cpu_cycles = 7;
H = RD_BYTE(HL);
break;
case 0x67: /* mov h, a */
cpu_cycles = 5;
H = A;
break;
case 0x68: /* mov l, b */
cpu_cycles = 5;
L = B;
break;
case 0x69: /* mov l, c */
cpu_cycles = 5;
L = C;
break;
case 0x6A: /* mov l, d */
cpu_cycles = 5;
L = D;
break;
case 0x6B: /* mov l, e */
cpu_cycles = 5;
L = E;
break;
case 0x6C: /* mov l, h */
cpu_cycles = 5;
L = H;
break;
case 0x6D: /* mov l, l */
cpu_cycles = 5;
break;
case 0x6E: /* mov l, m */
cpu_cycles = 7;
L = RD_BYTE(HL);
break;
case 0x6F: /* mov l, a */
cpu_cycles = 5;
L = A;
break;
case 0x70: /* mov m, b */
cpu_cycles = 7;
WR_BYTE(HL, B);
break;
case 0x71: /* mov m, c */
cpu_cycles = 7;
WR_BYTE(HL, C);
break;
case 0x72: /* mov m, d */
cpu_cycles = 7;
WR_BYTE(HL, D);
break;
case 0x73: /* mov m, e */
cpu_cycles = 7;
WR_BYTE(HL, E);
break;
case 0x74: /* mov m, h */
cpu_cycles = 7;
WR_BYTE(HL, H);
break;
case 0x75: /* mov m, l */
cpu_cycles = 7;
WR_BYTE(HL, L);
break;
case 0x76: /* hlt */
cpu_cycles = 4;
PC--;
break;
case 0x77: /* mov m, a */
cpu_cycles = 7;
WR_BYTE(HL, A);
break;
case 0x78: /* mov a, b */
cpu_cycles = 5;
A = B;
break;
case 0x79: /* mov a, c */
cpu_cycles = 5;
A = C;
break;
case 0x7A: /* mov a, d */
cpu_cycles = 5;
A = D;
break;
case 0x7B: /* mov a, e */
cpu_cycles = 5;
A = E;
break;
case 0x7C: /* mov a, h */
cpu_cycles = 5;
A = H;
break;
case 0x7D: /* mov a, l */
cpu_cycles = 5;
A = L;
break;
case 0x7E: /* mov a, m */
cpu_cycles = 7;
A = RD_BYTE(HL);
break;
case 0x7F: /* mov a, a */
cpu_cycles = 5;
break;
case 0x80: /* add b */
cpu_cycles = 4;
ADD(B);
break;
case 0x81: /* add c */
cpu_cycles = 4;
ADD(C);
break;
case 0x82: /* add d */
cpu_cycles = 4;
ADD(D);
break;
case 0x83: /* add e */
cpu_cycles = 4;
ADD(E);
break;
case 0x84: /* add h */
cpu_cycles = 4;
ADD(H);
break;
case 0x85: /* add l */
cpu_cycles = 4;
ADD(L);
break;
case 0x86: /* add m */
cpu_cycles = 7;
work8 = RD_BYTE(HL);
ADD(work8);
break;
case 0x87: /* add a */
cpu_cycles = 4;
ADD(A);
break;
case 0x88: /* adc b */
cpu_cycles = 4;
ADC(B);
break;
case 0x89: /* adc c */
cpu_cycles = 4;
ADC(C);
break;
case 0x8A: /* adc d */
cpu_cycles = 4;
ADC(D);
break;
case 0x8B: /* adc e */
cpu_cycles = 4;
ADC(E);
break;
case 0x8C: /* adc h */
cpu_cycles = 4;
ADC(H);
break;
case 0x8D: /* adc l */
cpu_cycles = 4;
ADC(L);
break;
case 0x8E: /* adc m */
cpu_cycles = 7;
work8 = RD_BYTE(HL);
ADC(work8);
break;
case 0x8F: /* adc a */
cpu_cycles = 4;
ADC(A);
break;
case 0x90: /* sub b */
cpu_cycles = 4;
SUB(B);
break;
case 0x91: /* sub c */
cpu_cycles = 4;
SUB(C);
break;
case 0x92: /* sub d */
cpu_cycles = 4;
SUB(D);
break;
case 0x93: /* sub e */
cpu_cycles = 4;
SUB(E);
break;
case 0x94: /* sub h */
cpu_cycles = 4;
SUB(H);
break;
case 0x95: /* sub l */
cpu_cycles = 4;
SUB(L);
break;
case 0x96: /* sub m */
cpu_cycles = 7;
work8 = RD_BYTE(HL);
SUB(work8);
break;
case 0x97: /* sub a */
cpu_cycles = 4;
SUB(A);
break;
case 0x98: /* sbb b */
cpu_cycles = 4;
SBB(B);
break;
case 0x99: /* sbb c */
cpu_cycles = 4;
SBB(C);
break;
case 0x9A: /* sbb d */
cpu_cycles = 4;
SBB(D);
break;
case 0x9B: /* sbb e */
cpu_cycles = 4;
SBB(E);
break;
case 0x9C: /* sbb h */
cpu_cycles = 4;
SBB(H);
break;
case 0x9D: /* sbb l */
cpu_cycles = 4;
SBB(L);
break;
case 0x9E: /* sbb m */
cpu_cycles = 7;
work8 = RD_BYTE(HL);
SBB(work8);
break;
case 0x9F: /* sbb a */
cpu_cycles = 4;
SBB(A);
break;
case 0xA0: /* ana b */
cpu_cycles = 4;
ANA(B);
break;
case 0xA1: /* ana c */
cpu_cycles = 4;
ANA(C);
break;
case 0xA2: /* ana d */
cpu_cycles = 4;
ANA(D);
break;
case 0xA3: /* ana e */
cpu_cycles = 4;
ANA(E);
break;
case 0xA4: /* ana h */
cpu_cycles = 4;
ANA(H);
break;
case 0xA5: /* ana l */
cpu_cycles = 4;
ANA(L);
break;
case 0xA6: /* ana m */
cpu_cycles = 7;
work8 = RD_BYTE(HL);
ANA(work8);
break;
case 0xA7: /* ana a */
cpu_cycles = 4;
ANA(A);
break;
case 0xA8: /* xra b */
cpu_cycles = 4;
XRA(B);
break;
case 0xA9: /* xra c */
cpu_cycles = 4;
XRA(C);
break;
case 0xAA: /* xra d */
cpu_cycles = 4;
XRA(D);
break;
case 0xAB: /* xra e */
cpu_cycles = 4;
XRA(E);
break;
case 0xAC: /* xra h */
cpu_cycles = 4;
XRA(H);
break;
case 0xAD: /* xra l */
cpu_cycles = 4;
XRA(L);
break;
case 0xAE: /* xra m */
cpu_cycles = 7;
work8 = RD_BYTE(HL);
XRA(work8);
break;
case 0xAF: /* xra a */
cpu_cycles = 4;
XRA(A);
break;
case 0xB0: /* ora b */
cpu_cycles = 4;
ORA(B);
break;
case 0xB1: /* ora c */
cpu_cycles = 4;
ORA(C);
break;
case 0xB2: /* ora d */
cpu_cycles = 4;
ORA(D);
break;
case 0xB3: /* ora e */
cpu_cycles = 4;
ORA(E);
break;
case 0xB4: /* ora h */
cpu_cycles = 4;
ORA(H);
break;
case 0xB5: /* ora l */
cpu_cycles = 4;
ORA(L);
break;
case 0xB6: /* ora m */
cpu_cycles = 7;
work8 = RD_BYTE(HL);
ORA(work8);
break;
case 0xB7: /* ora a */
cpu_cycles = 4;
ORA(A);
break;
case 0xB8: /* cmp b */
cpu_cycles = 4;
CMP(B);
break;
case 0xB9: /* cmp c */
cpu_cycles = 4;
CMP(C);
break;
case 0xBA: /* cmp d */
cpu_cycles = 4;
CMP(D);
break;
case 0xBB: /* cmp e */
cpu_cycles = 4;
CMP(E);
break;
case 0xBC: /* cmp h */
cpu_cycles = 4;
CMP(H);
break;
case 0xBD: /* cmp l */
cpu_cycles = 4;
CMP(L);
break;
case 0xBE: /* cmp m */
cpu_cycles = 7;
work8 = RD_BYTE(HL);
CMP(work8);
break;
case 0xBF: /* cmp a */
cpu_cycles = 4;
CMP(A);
break;
case 0xC0: /* rnz */
cpu_cycles = 5;
if (!TST(Z_FLAG)) {
cpu_cycles = 11;
POP(PC);
}
break;
case 0xC1: /* pop b */
cpu_cycles = 11;
POP(BC);
break;
case 0xC2: /* jnz addr */
cpu_cycles = 10;
if (!TST(Z_FLAG)) {
PC = RD_WORD(PC);
}
else {
PC += 2;
}
break;
case 0xC3: /* jmp addr */
case 0xCB: /* jmp addr, undocumented */
cpu_cycles = 10;
PC = RD_WORD(PC);
break;
case 0xC4: /* cnz addr */
if (!TST(Z_FLAG)) {
cpu_cycles = 17;
CALL;
} else {
cpu_cycles = 11;
PC += 2;
}
break;
case 0xC5: /* push b */
cpu_cycles = 11;
PUSH(BC);
break;
case 0xC6: /* adi data8 */
cpu_cycles = 7;
work8 = RD_BYTE(PC++);
ADD(work8);
break;
case 0xC7: /* rst 0 */
cpu_cycles = 11;
RST(0x0000);
break;
case 0xC8: /* rz */
cpu_cycles = 5;
if (TST(Z_FLAG)) {
cpu_cycles = 11;
POP(PC);
}
break;
case 0xC9: /* ret */
case 0xD9: /* ret, undocumented */
cpu_cycles = 10;
POP(PC);
break;
case 0xCA: /* jz addr */
cpu_cycles = 10;
if (TST(Z_FLAG)) {
PC = RD_WORD(PC);
} else {
PC += 2;
}
break;
case 0xCC: /* cz addr */
if (TST(Z_FLAG)) {
cpu_cycles = 17;
CALL;
} else {
cpu_cycles = 11;
PC += 2;
}
break;
case 0xCD: /* call addr */
case 0xDD: /* call, undocumented */
case 0xED:
case 0xFD:
cpu_cycles = 17;
CALL;
break;
case 0xCE: /* aci data8 */
cpu_cycles = 7;
work8 = RD_BYTE(PC++);
ADC(work8);
break;
case 0xCF: /* rst 1 */
cpu_cycles = 11;
RST(0x0008);
break;
case 0xD0: /* rnc */
cpu_cycles = 5;
if (!TST(C_FLAG)) {
cpu_cycles = 11;
POP(PC);
}
break;
case 0xD1: /* pop d */
cpu_cycles = 11;
POP(DE);
break;
case 0xD2: /* jnc addr */
cpu_cycles = 10;
if (!TST(C_FLAG)) {
PC = RD_WORD(PC);
} else {
PC += 2;
}
break;
case 0xD3: /* out port8 */
cpu_cycles = 10;
m_writeIO(m_context, RD_BYTE(PC++), A);
break;
case 0xD4: /* cnc addr */
if (!TST(C_FLAG)) {
cpu_cycles = 17;
CALL;
} else {
cpu_cycles = 11;
PC += 2;
}
break;
case 0xD5: /* push d */
cpu_cycles = 11;
PUSH(DE);
break;
case 0xD6: /* sui data8 */
cpu_cycles = 7;
work8 = RD_BYTE(PC++);
SUB(work8);
break;
case 0xD7: /* rst 2 */
cpu_cycles = 11;
RST(0x0010);
break;
case 0xD8: /* rc */
cpu_cycles = 5;
if (TST(C_FLAG)) {
cpu_cycles = 11;
POP(PC);
}
break;
case 0xDA: /* jc addr */
cpu_cycles = 10;
if (TST(C_FLAG)) {
PC = RD_WORD(PC);
} else {
PC += 2;
}
break;
case 0xDB: /* in port8 */
cpu_cycles = 10;
A = m_readIO(m_context, RD_BYTE(PC++));
break;
case 0xDC: /* cc addr */
if (TST(C_FLAG)) {
cpu_cycles = 17;
CALL;
} else {
cpu_cycles = 11;
PC += 2;
}
break;
case 0xDE: /* sbi data8 */
cpu_cycles = 7;
work8 = RD_BYTE(PC++);
SBB(work8);
break;
case 0xDF: /* rst 3 */
cpu_cycles = 11;
RST(0x0018);
break;
case 0xE0: /* rpo */
cpu_cycles = 5;
if (!TST(P_FLAG)) {
cpu_cycles = 11;
POP(PC);
}
break;
case 0xE1: /* pop h */
cpu_cycles = 11;
POP(HL);
break;
case 0xE2: /* jpo addr */
cpu_cycles = 10;
if (!TST(P_FLAG)) {
PC = RD_WORD(PC);
}
else {
PC += 2;
}
break;
case 0xE3: /* xthl */
cpu_cycles = 18;
work16 = RD_WORD(SP);
WR_WORD(SP, HL);
HL = work16;
break;
case 0xE4: /* cpo addr */
if (!TST(P_FLAG)) {
cpu_cycles = 17;
CALL;
} else {
cpu_cycles = 11;
PC += 2;
}
break;
case 0xE5: /* push h */
cpu_cycles = 11;
PUSH(HL);
break;
case 0xE6: /* ani data8 */
cpu_cycles = 7;
work8 = RD_BYTE(PC++);
ANA(work8);
break;
case 0xE7: /* rst 4 */
cpu_cycles = 11;
RST(0x0020);
break;
case 0xE8: /* rpe */
cpu_cycles = 5;
if (TST(P_FLAG)) {
cpu_cycles = 11;
POP(PC);
}
break;
case 0xE9: /* pchl */
cpu_cycles = 5;
PC = HL;
break;
case 0xEA: /* jpe addr */
cpu_cycles = 10;
if (TST(P_FLAG)) {
PC = RD_WORD(PC);
} else {
PC += 2;
}
break;
case 0xEB: /* xchg */
cpu_cycles = 4;
work16 = DE;
DE = HL;
HL = work16;
break;
case 0xEC: /* cpe addr */
if (TST(P_FLAG)) {
cpu_cycles = 17;
CALL;
} else {
cpu_cycles = 11;
PC += 2;
}
break;
case 0xEE: /* xri data8 */
cpu_cycles = 7;
work8 = RD_BYTE(PC++);
XRA(work8);
break;
case 0xEF: /* rst 5 */
cpu_cycles = 11;
RST(0x0028);
break;
case 0xF0: /* rp */
cpu_cycles = 5;
if (!TST(S_FLAG)) {
cpu_cycles = 11;
POP(PC);
}
break;
case 0xF1: /* pop psw */
cpu_cycles = 10;
POP(AF);
retrieve_flags();
break;
case 0xF2: /* jp addr */
cpu_cycles = 10;
if (!TST(S_FLAG)) {
PC = RD_WORD(PC);
} else {
PC += 2;
}
break;
case 0xF3: /* di */
cpu_cycles = 4;
IFF = 0;
break;
case 0xF4: /* cp addr */
if (!TST(S_FLAG)) {
cpu_cycles = 17;
CALL;
} else {
cpu_cycles = 11;
PC += 2;
}
break;
case 0xF5: /* push psw */
cpu_cycles = 11;
store_flags();
PUSH(AF);
break;
case 0xF6: /* ori data8 */
cpu_cycles = 7;
work8 = RD_BYTE(PC++);
ORA(work8);
break;
case 0xF7: /* rst 6 */
cpu_cycles = 11;
RST(0x0030);
break;
case 0xF8: /* rm */
cpu_cycles = 5;
if (TST(S_FLAG)) {
cpu_cycles = 11;
POP(PC);
}
break;
case 0xF9: /* sphl */
cpu_cycles = 5;
SP = HL;
break;
case 0xFA: /* jm addr */
cpu_cycles = 10;
if (TST(S_FLAG)) {
PC = RD_WORD(PC);
} else {
PC += 2;
}
break;
case 0xFB: /* ei */
cpu_cycles = 4;
IFF = 1;
break;
case 0xFC: /* cm addr */
if (TST(S_FLAG)) {
cpu_cycles = 17;
CALL;
} else {
cpu_cycles = 11;
PC += 2;
}
break;
case 0xFE: /* cpi data8 */
cpu_cycles = 7;
work8 = RD_BYTE(PC++);
CMP(work8);
break;
case 0xFF: /* rst 7 */
cpu_cycles = 11;
RST(0x0038);
break;
default:
cpu_cycles = -1; /* Shouldn't be really here. */
break;
}
return cpu_cycles;
}
}; // fabgl namespace
| 22.225711
| 77
| 0.366341
|
POMIN-163
|
95056509bd91c195b856715ccafc75d483a1dd5a
| 27,927
|
cpp
|
C++
|
packages/data_gen/electron_photon/test/tstStandardEvaluatedElectronDataGenerator.cpp
|
lkersting/SCR-2123
|
06ae3d92998664a520dc6a271809a5aeffe18f72
|
[
"BSD-3-Clause"
] | null | null | null |
packages/data_gen/electron_photon/test/tstStandardEvaluatedElectronDataGenerator.cpp
|
lkersting/SCR-2123
|
06ae3d92998664a520dc6a271809a5aeffe18f72
|
[
"BSD-3-Clause"
] | null | null | null |
packages/data_gen/electron_photon/test/tstStandardEvaluatedElectronDataGenerator.cpp
|
lkersting/SCR-2123
|
06ae3d92998664a520dc6a271809a5aeffe18f72
|
[
"BSD-3-Clause"
] | null | null | null |
//---------------------------------------------------------------------------//
//!
//! \file tstStandardEvaluatedElectronDataGenerator.cpp
//! \author Luke Kersting
//! \brief The eedl data generator class unit tests
//!
//---------------------------------------------------------------------------//
// Std Lib Includes
#include <string>
#include <iostream>
// Trilinos Includes
#include <Teuchos_UnitTestHarness.hpp>
#include <Teuchos_VerboseObject.hpp>
#include <Teuchos_RCP.hpp>
// FRENSIE Includes
#include "DataGen_StandardEvaluatedElectronDataGenerator.hpp"
#include "DataGen_EvaluatedElectronDataGenerator.hpp"
#include "Data_ENDLFileHandler.hpp"
#include "Data_ACEFileHandler.hpp"
#include "Data_XSSEPRDataExtractor.hpp"
#include "Utility_UnitTestHarnessExtensions.hpp"
//---------------------------------------------------------------------------//
// Testing Variables
//---------------------------------------------------------------------------//
Teuchos::RCP<const DataGen::StandardEvaluatedElectronDataGenerator>
data_generator_h, data_generator_pb;
Teuchos::RCP<Data::XSSEPRDataExtractor>
h_xss_data_extractor, pb_xss_data_extractor;
std::string test_h_eedl_file_name, test_pb_eedl_file_name;
//---------------------------------------------------------------------------//
// Tests
//---------------------------------------------------------------------------//
// Check that a data container can be populated
TEUCHOS_UNIT_TEST( StandardEvaluatedElectronDataGenerator,
populateEvaluatedDataContainer_h )
{
unsigned atomic_number;
double min_electron_energy = 1.0e-5;
double max_electron_energy = 1.0e+5;
double cutoff_angle = 1.0e-6;
double grid_convergence_tol = 0.001;
double grid_absolute_diff_tol = 1e-13;
double grid_distance_tol = 1e-13;
atomic_number = 1u;
Teuchos::RCP<Data::ENDLFileHandler> eedl_file_handler(
new Data::ENDLFileHandler( test_h_eedl_file_name ) );
data_generator_h.reset(
new DataGen::StandardEvaluatedElectronDataGenerator(
atomic_number,
eedl_file_handler,
h_xss_data_extractor,
min_electron_energy,
max_electron_energy,
cutoff_angle,
grid_convergence_tol,
grid_absolute_diff_tol,
grid_distance_tol ) );
Data::EvaluatedElectronVolatileDataContainer data_container;
data_generator_h->populateEvaluatedDataContainer( data_container );
TEST_EQUALITY_CONST( data_container.getAtomicNumber(), 1 );
std::set<unsigned> atomic_subshells = data_container.getSubshells();
TEST_EQUALITY_CONST( *atomic_subshells.begin(), 1 );
TEST_EQUALITY_CONST( atomic_subshells.size(), 1 );
TEST_EQUALITY_CONST( data_container.getSubshellOccupancy( 1 ), 1 );
TEST_ASSERT( !data_container.hasRelaxationData() );
TEST_ASSERT( !data_container.hasSubshellRelaxationData( 1 ) );
double binding_energy =
data_container.getSubshellBindingEnergy( *atomic_subshells.begin() );
TEST_EQUALITY_CONST( binding_energy, 1.36100e-5 );
std::vector<double> energy_grid = data_container.getElectronEnergyGrid();
TEST_EQUALITY_CONST( energy_grid.front(), 1.0e-5 );
TEST_EQUALITY_CONST( energy_grid.back(), 1.0e+5 );
TEST_EQUALITY_CONST( energy_grid.size(), 728 );
TEST_EQUALITY_CONST( data_container.getCutoffAngle(), 1.0e-6 );
// Check the elastic data
unsigned threshold =
data_container.getCutoffElasticCrossSectionThresholdEnergyIndex();
TEST_EQUALITY_CONST( threshold, 0 );
std::vector<double> cross_section =
data_container.getCutoffElasticCrossSection();
TEST_EQUALITY_CONST( cross_section.front(), 2.74896e+8 );
TEST_FLOATING_EQUALITY( cross_section.back(), 1.31176e-5, 1e-15 );
TEST_EQUALITY_CONST( cross_section.size(), 728-threshold );
threshold =
data_container.getScreenedRutherfordElasticCrossSectionThresholdEnergyIndex();
TEST_EQUALITY_CONST( threshold, 263 );
cross_section =
data_container.getScreenedRutherfordElasticCrossSection();
TEST_EQUALITY_CONST( cross_section.front(), 2.5745520470700284932 );
TEST_EQUALITY_CONST( cross_section.back(), 1.29871e+4-1.31176e-5 );
TEST_EQUALITY_CONST( cross_section.size(), 728-threshold );
std::vector<double> angular_grid =
data_container.getElasticAngularEnergyGrid();
TEST_EQUALITY_CONST( angular_grid.front(), 1.0e-5 );
TEST_EQUALITY_CONST( angular_grid.back(), 1.0e+5 );
TEST_EQUALITY_CONST( angular_grid.size(), 16 );
std::vector<double> elastic_angles =
data_container.getAnalogElasticAngles(1.0e-5);
TEST_EQUALITY_CONST( elastic_angles.front(), 1.0e-6 );
TEST_EQUALITY_CONST( elastic_angles.back(), 2.0 );
TEST_EQUALITY_CONST( elastic_angles.size(), 2 );
elastic_angles =
data_container.getAnalogElasticAngles(1.0e+5);
TEST_EQUALITY_CONST( elastic_angles.front(), 1.0e-6 );
TEST_EQUALITY_CONST( elastic_angles.back(), 2.0 );
TEST_EQUALITY_CONST( elastic_angles.size(), 96 );
std::vector<double> elastic_pdf =
data_container.getAnalogElasticPDF(1.0e-5);
TEST_EQUALITY_CONST( elastic_pdf.front(), 0.5 );
TEST_EQUALITY_CONST( elastic_pdf.back(), 0.5 );
TEST_EQUALITY_CONST( elastic_pdf.size(), 2 );
elastic_pdf =
data_container.getAnalogElasticPDF(1.0e+5);
TEST_EQUALITY_CONST( elastic_pdf.front(), 9.86945e+5 );
TEST_EQUALITY_CONST( elastic_pdf.back(), 6.25670e-13 );
TEST_EQUALITY_CONST( elastic_pdf.size(), 96 );
std::vector<double> moliere_screening_constant =
data_container.getMoliereScreeningConstant();
TEST_EQUALITY_CONST( moliere_screening_constant.front(),
-1.0e-6 );
TEST_EQUALITY_CONST( moliere_screening_constant[1],
-1.0039841898413188328e-06 );
TEST_EQUALITY_CONST( moliere_screening_constant.back(),
9.968622523875358279e-16 );
TEST_EQUALITY_CONST( moliere_screening_constant.size(), 8 );
std::vector<double> screened_rutherford_normalization_constant =
data_container.getScreenedRutherfordNormalizationConstant();
TEST_EQUALITY_CONST( screened_rutherford_normalization_constant.front(),
0.0 );
TEST_EQUALITY_CONST( screened_rutherford_normalization_constant[1],
2.75592435140403470e-13 );
TEST_EQUALITY_CONST( screened_rutherford_normalization_constant.back(),
9.86945001967696289e-07 );
TEST_EQUALITY_CONST( screened_rutherford_normalization_constant.size(), 8 );
// Check the electroionization data
threshold =
data_container.getElectroionizationCrossSectionThresholdEnergyIndex( 1u );
TEST_EQUALITY_CONST( threshold, 7 );
cross_section =
data_container.getElectroionizationCrossSection( 1u );
TEST_EQUALITY_CONST( cross_section.front(), 1.26041968911917554e+06 );
TEST_EQUALITY_CONST( cross_section.back(), 8.28924e+4 );
TEST_EQUALITY_CONST( cross_section.size(), 728-threshold );
std::vector<double> electroionization_energy_grid =
data_container.getElectroionizationEnergyGrid( 1u );
TEST_EQUALITY_CONST( electroionization_energy_grid.front(), 1.36100e-5 );
TEST_EQUALITY_CONST( electroionization_energy_grid.back(), 1.00000e+5 );
TEST_EQUALITY_CONST( electroionization_energy_grid.size(), 8 );
std::vector<double> electroionization_recoil_energy =
data_container.getElectroionizationRecoilEnergy( 1u, 1.36100e-5 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.front(), 2.79866e-9 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.back(), 2.79866e-8 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.size(), 2 );
electroionization_recoil_energy =
data_container.getElectroionizationRecoilEnergy( 1u, 1.00000e+5 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.front(), 1.00000e-7 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.back(), 5.00000e+4 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.size(), 147 );
std::vector<double> electroionization_recoil_pdf =
data_container.getElectroionizationRecoilPDF( 1u, 1.36100e-5 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.front(), 3.97015e+7 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.back(), 3.97015e+7 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.size(), 2 );
electroionization_recoil_pdf =
data_container.getElectroionizationRecoilPDF( 1u, 1.00000e+5 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.front(), 1.61897e+5 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.back(), 2.77550e-15 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.size(), 147 );
// Check the bremsstrahlung data
threshold =
data_container.getBremsstrahlungCrossSectionThresholdEnergyIndex();
TEST_EQUALITY_CONST( threshold, 0 );
cross_section =
data_container.getBremsstrahlungCrossSection();
TEST_EQUALITY_CONST( cross_section.front(), 2.97832e+1 );
TEST_EQUALITY_CONST( cross_section.back(), 9.90621e-1 );
TEST_EQUALITY_CONST( cross_section.size(), 728-threshold );
std::vector<double> bremsstrahlung_energy_grid =
data_container.getBremsstrahlungEnergyGrid();
TEST_EQUALITY_CONST( bremsstrahlung_energy_grid.front(), 1.00000e-5 );
TEST_EQUALITY_CONST( bremsstrahlung_energy_grid.back(), 1.00000e+5 );
TEST_EQUALITY_CONST( bremsstrahlung_energy_grid.size(), 10 );
std::vector<double> bremsstrahlung_photon_energy =
data_container.getBremsstrahlungPhotonEnergy( 1.00000e-5 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.front(), 1.00000e-7 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.back(), 1.00000e-5 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.size(), 17 );
bremsstrahlung_photon_energy =
data_container.getBremsstrahlungPhotonEnergy( 1.00000e+5 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.front(), 1.00000e-7 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.back(), 1.00000e+5 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.size(), 111 );
std::vector<double> bremsstrahlung_photon_pdf =
data_container.getBremsstrahlungPhotonPDF( 1.00000e-5 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.front(), 2.13940e+6 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.back(), 2.12245e+4 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.size(), 17 );
bremsstrahlung_photon_pdf =
data_container.getBremsstrahlungPhotonPDF( 1.00000e+5 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.front(), 3.65591e+5 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.back(), 5.16344e-10 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.size(), 111 );
// Check the atomic excitation data
threshold =
data_container.getAtomicExcitationCrossSectionThresholdEnergyIndex();
TEST_EQUALITY_CONST( threshold, 7 );
cross_section =
data_container.getAtomicExcitationCrossSection();
TEST_EQUALITY_CONST( cross_section.front(), 6.23029e+5 );
TEST_EQUALITY_CONST( cross_section.back(), 8.14416e+4 );
TEST_EQUALITY_CONST( cross_section.size(), 728-threshold );
std::vector<double> atomic_excitation_energy_grid =
data_container.getAtomicExcitationEnergyGrid();
TEST_EQUALITY_CONST( atomic_excitation_energy_grid.front(), 1.36100e-5 );
TEST_EQUALITY_CONST( atomic_excitation_energy_grid.back(), 1.00000e+5 );
TEST_EQUALITY_CONST( atomic_excitation_energy_grid.size(), 170 );
std::vector<double> atomic_excitation_energy_loss =
data_container.getAtomicExcitationEnergyLoss();
TEST_EQUALITY_CONST( atomic_excitation_energy_loss.front(), 1.36100e-5 );
TEST_EQUALITY_CONST( atomic_excitation_energy_loss.back(), 2.10777e-5 );
TEST_EQUALITY_CONST( atomic_excitation_energy_loss.size(), 170 );
data_container.exportData( "test_h_epr.xml",
Utility::ArchivableObject::XML_ARCHIVE );
/*
data_container.exportData( "/home/ljkerst/software/frensie/data/test_h_epr.xml",
Utility::ArchivableObject::XML_ARCHIVE );*/
}
//---------------------------------------------------------------------------//
// Check that a data container can be populated
TEUCHOS_UNIT_TEST( StandardEvaluatedElectronDataGenerator,
populateEvaluatedDataContainer_pb )
{
unsigned atomic_number;
double min_electron_energy = 1.0e-5;
double max_electron_energy = 1.0e+5;
double cutoff_angle = 1.0e-6;
double grid_convergence_tol = 0.001;
double grid_absolute_diff_tol = 1e-13;
double grid_distance_tol = 1e-13;
atomic_number = 82u;
Teuchos::RCP<Data::ENDLFileHandler> eedl_file_handler(
new Data::ENDLFileHandler( test_pb_eedl_file_name ) );
data_generator_pb.reset(
new DataGen::StandardEvaluatedElectronDataGenerator(
atomic_number,
eedl_file_handler,
pb_xss_data_extractor,
min_electron_energy,
max_electron_energy,
cutoff_angle,
grid_convergence_tol,
grid_absolute_diff_tol,
grid_distance_tol ) );
Data::EvaluatedElectronVolatileDataContainer data_container;
data_generator_pb->populateEvaluatedDataContainer( data_container );
TEST_EQUALITY_CONST( data_container.getAtomicNumber(), 82 );
std::set<unsigned> atomic_subshells = data_container.getSubshells();
TEST_EQUALITY_CONST( *atomic_subshells.begin(), 1 );
TEST_EQUALITY_CONST( *--atomic_subshells.end(), 44 );
TEST_EQUALITY_CONST( atomic_subshells.size(), 24 );
TEST_EQUALITY_CONST( data_container.getSubshellOccupancy( 1 ), 2 );
TEST_ASSERT( data_container.hasRelaxationData() );
TEST_ASSERT( data_container.hasSubshellRelaxationData( 1 ) );
TEST_ASSERT( !data_container.hasSubshellRelaxationData( 44 ) );
double binding_energy =
data_container.getSubshellBindingEnergy( *atomic_subshells.begin() );
TEST_EQUALITY_CONST( binding_energy, 8.82900e-2 );
binding_energy =
data_container.getSubshellBindingEnergy( *--atomic_subshells.end() );
TEST_EQUALITY_CONST( binding_energy, 5.29000e-6 );
std::vector<double> energy_grid = data_container.getElectronEnergyGrid();
TEST_EQUALITY_CONST( energy_grid.front(), 1.0e-5 );
TEST_EQUALITY_CONST( energy_grid.back(), 1.0e+5 );
TEST_EQUALITY_CONST( energy_grid.size(), 759 );
TEST_EQUALITY_CONST( data_container.getCutoffAngle(), 1.0e-6 );
// Check the elastic data
unsigned threshold =
data_container.getCutoffElasticCrossSectionThresholdEnergyIndex();
TEST_EQUALITY_CONST( threshold, 0 );
std::vector<double> cross_section =
data_container.getCutoffElasticCrossSection();
TEST_EQUALITY_CONST( cross_section.front(), 2.48924e+9 );
TEST_FLOATING_EQUALITY( cross_section.back(), 8.83051e-2, 1e-15 );
TEST_EQUALITY_CONST( cross_section.size(), 759-threshold );
threshold =
data_container.getScreenedRutherfordElasticCrossSectionThresholdEnergyIndex();
TEST_EQUALITY_CONST( threshold, 399 );
cross_section =
data_container.getScreenedRutherfordElasticCrossSection();
TEST_EQUALITY_CONST( cross_section.front(), 3.40785608241669834e+04 );
TEST_EQUALITY_CONST( cross_section.back(), 2.11161e+6-8.83051e-2 );
TEST_EQUALITY_CONST( cross_section.size(), 759-threshold );
std::vector<double> angular_grid =
data_container.getElasticAngularEnergyGrid();
TEST_EQUALITY_CONST( angular_grid.front(), 1.0e-5 );
TEST_EQUALITY_CONST( angular_grid.back(), 1.0e+5 );
TEST_EQUALITY_CONST( angular_grid.size(), 14 );
std::vector<double> elastic_angles =
data_container.getAnalogElasticAngles(1.0e-5);
TEST_EQUALITY_CONST( elastic_angles.front(), 1.0e-6 );
TEST_EQUALITY_CONST( elastic_angles.back(), 2.0 );
TEST_EQUALITY_CONST( elastic_angles.size(), 2 );
elastic_angles =
data_container.getAnalogElasticAngles(1.0e+5);
TEST_EQUALITY_CONST( elastic_angles.front(), 1.0e-6 );
TEST_EQUALITY_CONST( elastic_angles.back(), 2.0 );
TEST_EQUALITY_CONST( elastic_angles.size(), 90 );
std::vector<double> elastic_pdf =
data_container.getAnalogElasticPDF(1.0e-5);
TEST_EQUALITY_CONST( elastic_pdf.front(), 0.5 );
TEST_EQUALITY_CONST( elastic_pdf.back(), 0.5 );
TEST_EQUALITY_CONST( elastic_pdf.size(), 2 );
elastic_pdf =
data_container.getAnalogElasticPDF(1.0e+5);
TEST_EQUALITY_CONST( elastic_pdf.front(), 9.86374e+5 );
TEST_EQUALITY_CONST( elastic_pdf.back(), 1.76576e-8 );
TEST_EQUALITY_CONST( elastic_pdf.size(), 90 );
std::vector<double> moliere_screening_constant =
data_container.getMoliereScreeningConstant();
TEST_FLOATING_EQUALITY( moliere_screening_constant.front(),
-1.0e-06,
1e-12 );
TEST_FLOATING_EQUALITY( moliere_screening_constant[1],
-1.06552060095948850e-05,
1e-12 );
TEST_FLOATING_EQUALITY( moliere_screening_constant.back(),
4.124902891289890E-14,
1e-12 );
TEST_EQUALITY_CONST( moliere_screening_constant.size(), 5 );
std::vector<double> screened_rutherford_normalization_constant =
data_container.getScreenedRutherfordNormalizationConstant();
TEST_FLOATING_EQUALITY( screened_rutherford_normalization_constant.front(),
0.0,
1e-12 );
TEST_FLOATING_EQUALITY( screened_rutherford_normalization_constant[1],
1.94353181297334527e-05,
1e-12 );
TEST_FLOATING_EQUALITY( screened_rutherford_normalization_constant.back(),
9.863740813739410E-07,
1e-12 );
TEST_EQUALITY_CONST( screened_rutherford_normalization_constant.size(), 5 );
// Check the electroionization data
threshold =
data_container.getElectroionizationCrossSectionThresholdEnergyIndex( 1u );
TEST_EQUALITY_CONST( threshold, 309 );
cross_section =
data_container.getElectroionizationCrossSection( 1u );
TEST_EQUALITY_CONST( cross_section.front(), 1.25067357130657558e-01 );
TEST_EQUALITY_CONST( cross_section.back(), 3.64919e+1 );
TEST_EQUALITY_CONST( cross_section.size(), 759-threshold );
std::vector<double> electroionization_energy_grid =
data_container.getElectroionizationEnergyGrid( 1u );
TEST_EQUALITY_CONST( electroionization_energy_grid.front(), 8.82900e-2 );
TEST_EQUALITY_CONST( electroionization_energy_grid.back(), 1.00000e+5 );
TEST_EQUALITY_CONST( electroionization_energy_grid.size(), 5 );
std::vector<double> electroionization_recoil_energy =
data_container.getElectroionizationRecoilEnergy( 1u, 8.82900e-2 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.front(), 1.00000e-8 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.back(), 1.00000e-7 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.size(), 2 );
electroionization_recoil_energy =
data_container.getElectroionizationRecoilEnergy( 1u, 1.00000e+5 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.front(), 1.00000e-7 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.back(), 5.00000e+4 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.size(), 90 );
std::vector<double> electroionization_recoil_pdf =
data_container.getElectroionizationRecoilPDF( 1u, 8.82900e-2 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.front(), 1.11111e+7 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.back(), 1.11111e+7 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.size(), 2 );
electroionization_recoil_pdf =
data_container.getElectroionizationRecoilPDF( 1u, 1.00000e+5 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.front(), 2.52642e+1 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.back(), 1.26188e-11 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.size(), 90 );
threshold =
data_container.getElectroionizationCrossSectionThresholdEnergyIndex( 44u );
TEST_EQUALITY_CONST( threshold, 0 );
cross_section =
data_container.getElectroionizationCrossSection( 44u );
TEST_EQUALITY_CONST( cross_section.front(), 1.06530e+8 );
TEST_EQUALITY_CONST( cross_section.back(), 1.82234e+5 );
TEST_EQUALITY_CONST( cross_section.size(), 759-threshold );
electroionization_energy_grid =
data_container.getElectroionizationEnergyGrid( 44u );
TEST_EQUALITY_CONST( electroionization_energy_grid.front(), 5.29000e-6 );
TEST_EQUALITY_CONST( electroionization_energy_grid.back(), 1.00000e+5 );
TEST_EQUALITY_CONST( electroionization_energy_grid.size(), 8 );
electroionization_recoil_energy =
data_container.getElectroionizationRecoilEnergy( 44u, 5.29000e-6 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.front(), 2.54893e-9 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.back(), 2.54893e-8 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.size(), 2 );
electroionization_recoil_energy =
data_container.getElectroionizationRecoilEnergy( 44u, 1.00000e+5 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.front(), 1.00000e-7 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.back(), 5.00000e+4 );
TEST_EQUALITY_CONST( electroionization_recoil_energy.size(), 141 );
electroionization_recoil_pdf =
data_container.getElectroionizationRecoilPDF( 44u, 5.29000e-6 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.front(), 4.35913e+7 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.back(), 4.35913e+7 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.size(), 2 );
electroionization_recoil_pdf =
data_container.getElectroionizationRecoilPDF( 44u, 1.00000e+5 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.front(), 1.64629e+5 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.back(), 1.68999e-15 );
TEST_EQUALITY_CONST( electroionization_recoil_pdf.size(), 141 );
// Check the bremsstrahlung data
threshold =
data_container.getBremsstrahlungCrossSectionThresholdEnergyIndex();
TEST_EQUALITY_CONST( threshold, 0 );
cross_section =
data_container.getBremsstrahlungCrossSection();
TEST_EQUALITY_CONST( cross_section.front(), 4.86980e+3 );
TEST_EQUALITY_CONST( cross_section.back(), 1.95417e+3 );
TEST_EQUALITY_CONST( cross_section.size(), 759-threshold );
std::vector<double> bremsstrahlung_energy_grid =
data_container.getBremsstrahlungEnergyGrid();
TEST_EQUALITY_CONST( bremsstrahlung_energy_grid.front(), 1.00000e-5 );
TEST_EQUALITY_CONST( bremsstrahlung_energy_grid.back(), 1.00000e+5 );
TEST_EQUALITY_CONST( bremsstrahlung_energy_grid.size(), 9 );
std::vector<double> bremsstrahlung_photon_energy =
data_container.getBremsstrahlungPhotonEnergy( 1.00000e-5 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.front(), 1.00000e-7 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.back(), 1.00000e-5 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.size(), 17 );
bremsstrahlung_photon_energy =
data_container.getBremsstrahlungPhotonEnergy( 1.00000e+5 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.front(), 1.00000e-7 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.back(), 1.00000e+5 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.size(), 101 );
std::vector<double> bremsstrahlung_photon_pdf =
data_container.getBremsstrahlungPhotonPDF( 1.00000e-5 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.front(), 2.12760e+6 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.back(), 2.16305e+4 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.size(), 17 );
bremsstrahlung_photon_pdf =
data_container.getBremsstrahlungPhotonPDF( 1.00000e+5 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.front(), 3.64644e+5 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.back(), 4.47808e-8 );
TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.size(), 101 );
// Check the atomic excitation data
threshold =
data_container.getAtomicExcitationCrossSectionThresholdEnergyIndex();
TEST_EQUALITY_CONST( threshold, 0 );
cross_section =
data_container.getAtomicExcitationCrossSection();
TEST_EQUALITY_CONST( cross_section.front(), 8.75755e+6 );
TEST_EQUALITY_CONST( cross_section.back(), 1.57861e+6 );
TEST_EQUALITY_CONST( cross_section.size(), 759-threshold );
std::vector<double> atomic_excitation_energy_grid =
data_container.getAtomicExcitationEnergyGrid();
TEST_EQUALITY_CONST( atomic_excitation_energy_grid.front(), 1.00000e-5 );
TEST_EQUALITY_CONST( atomic_excitation_energy_grid.back(), 1.00000e+5 );
TEST_EQUALITY_CONST( atomic_excitation_energy_grid.size(), 286 );
std::vector<double> atomic_excitation_energy_loss =
data_container.getAtomicExcitationEnergyLoss();
TEST_EQUALITY_CONST( atomic_excitation_energy_loss.front(), 6.29685e-6 );
TEST_EQUALITY_CONST( atomic_excitation_energy_loss.back(), 1.09533e-5 );
TEST_EQUALITY_CONST( atomic_excitation_energy_loss.size(), 286 );
data_container.exportData( "test_pb_epr.xml",
Utility::ArchivableObject::XML_ARCHIVE );
/*
data_container.exportData( "/home/ljkerst/software/frensie/data/test_pb_epr.xml",
Utility::ArchivableObject::XML_ARCHIVE );
*/
}
//---------------------------------------------------------------------------//
// Custom main function
//---------------------------------------------------------------------------//
int main( int argc, char** argv )
{
std::string test_h_ace_file_name, test_pb_ace_file_name;
std::string test_h_ace_table_name, test_pb_ace_table_name;
Teuchos::CommandLineProcessor& clp = Teuchos::UnitTestRepository::getCLP();
clp.setOption( "test_h_eedl_file",
&test_h_eedl_file_name,
"Test EEDL file name" );
clp.setOption( "test_h_ace_file",
&test_h_ace_file_name,
"Test ACE file name" );
clp.setOption( "test_h_ace_table",
&test_h_ace_table_name,
"Test ACE table name" );
clp.setOption( "test_pb_eedl_file",
&test_pb_eedl_file_name,
"Test EEDL file name" );
clp.setOption( "test_pb_ace_file",
&test_pb_ace_file_name,
"Test ACE file name" );
clp.setOption( "test_pb_ace_table",
&test_pb_ace_table_name,
"Test ACE table name" );
const Teuchos::RCP<Teuchos::FancyOStream> out =
Teuchos::VerboseObjectBase::getDefaultOStream();
Teuchos::CommandLineProcessor::EParseCommandLineReturn parse_return =
clp.parse(argc,argv);
if ( parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) {
*out << "\nEnd Result: TEST FAILED" << std::endl;
return parse_return;
}
{
// Create the ace file handler and data extractor for hydrogen
Teuchos::RCP<Data::ACEFileHandler> ace_file_handler(
new Data::ACEFileHandler( test_h_ace_file_name,
test_h_ace_table_name,
1u ) );
h_xss_data_extractor.reset(
new Data::XSSEPRDataExtractor(
ace_file_handler->getTableNXSArray(),
ace_file_handler->getTableJXSArray(),
ace_file_handler->getTableXSSArray() ) );
}
{
// Create the ace file handler and data extractor for lead
Teuchos::RCP<Data::ACEFileHandler> ace_file_handler(
new Data::ACEFileHandler( test_pb_ace_file_name,
test_pb_ace_table_name,
1u ) );
pb_xss_data_extractor.reset(
new Data::XSSEPRDataExtractor(
ace_file_handler->getTableNXSArray(),
ace_file_handler->getTableJXSArray(),
ace_file_handler->getTableXSSArray() ) );
}
// Run the unit tests
Teuchos::GlobalMPISession mpiSession( &argc, &argv );
const bool success = Teuchos::UnitTestRepository::runUnitTests( *out );
if (success)
*out << "\nEnd Result: TEST PASSED" << std::endl;
else
*out << "\nEnd Result: TEST FAILED" << std::endl;
clp.printFinalTimerSummary(out.ptr());
return (success ? 0 : 1);
}
//---------------------------------------------------------------------------//
// end tstStandardEvaluatedElectronDataGenerator.cpp
//---------------------------------------------------------------------------//
| 38.626556
| 83
| 0.73044
|
lkersting
|
9507afa76950b2b0d47b7eb3a349fe44f6a1ff90
| 7,391
|
cpp
|
C++
|
path_follower/src/utils/path_interpolated.cpp
|
sunarditay/gerona
|
7ca6bb169571d498c4a2d627faddc8cbe590d2c9
|
[
"BSD-3-Clause"
] | 296
|
2017-06-19T07:06:58.000Z
|
2022-03-09T01:27:44.000Z
|
path_follower/src/utils/path_interpolated.cpp
|
sunarditay/gerona
|
7ca6bb169571d498c4a2d627faddc8cbe590d2c9
|
[
"BSD-3-Clause"
] | 29
|
2017-11-07T08:49:12.000Z
|
2021-09-21T22:18:28.000Z
|
path_follower/src/utils/path_interpolated.cpp
|
sunarditay/gerona
|
7ca6bb169571d498c4a2d627faddc8cbe590d2c9
|
[
"BSD-3-Clause"
] | 117
|
2017-05-30T10:50:36.000Z
|
2022-03-09T01:27:23.000Z
|
// HEADER
#include <path_follower/utils/path_interpolated.h>
// PROJECT
#include <path_follower/utils/cubic_spline_interpolation.h>
#include <cslibs_navigation_utilities/MathHelper.h>
#include <path_follower/parameters/path_follower_parameters.h>
// SYSTEM
#include <deque>
#include <nav_msgs/Path.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
#include <interpolation.h>
#pragma GCC diagnostic pop
using namespace Eigen;
PathInterpolated::PathInterpolated()
: frame_id_(PathFollowerParameters::getInstance()->world_frame()),
N_(0),
s_new_(0),
s_prim_(0)
{
}
PathInterpolated::~PathInterpolated() {
}
void PathInterpolated::interpolatePath(const Path::Ptr path, const bool hack) {
clearBuffers();
original_path_ = path;
frame_id_ = path->getFrameId();
std::deque<Waypoint> waypoints;
while (!path->isDone()) {
waypoints.insert(waypoints.end(), path->getCurrentSubPath().wps.begin(), path->getCurrentSubPath().wps.end());
if(hack){
int originalNumWaypoints = waypoints.size();
// (messy) hack!!!!!
// remove waypoints that are closer than 0.1 meters to the starting point
Waypoint start = waypoints.front();
while(!waypoints.empty()) {
std::deque<Waypoint>::iterator it = waypoints.begin();
const Waypoint& wp = *it;
double dx = wp.x - start.x;
double dy = wp.y - start.y;
double distance = hypot(dx, dy);
if(distance < 0.1) {
waypoints.pop_front();
} else {
break;
}
}
// eliminate subpaths containing only the same points
if(waypoints.size() > 1)
break;
//special case where all waypoints are below 0.1m, keep at least last two waypoints
if (originalNumWaypoints >= 2 && waypoints.size() < 2)
{
waypoints.insert(waypoints.end(), path->getCurrentSubPath().wps.begin(), path->getCurrentSubPath().wps.end());
while (waypoints.size() > 2) waypoints.pop_front();
break;
}
//path->switchToNextSubPath();
}else{
break;
}
}
// In case path->switchToNextSubPath(); was called a reset is required
// why?? limits the number of subpathes to 2!?
//path->reset();
try {
interpolatePath(waypoints);
} catch(const alglib::ap_error& error) {
throw std::runtime_error(error.msg);
}
}
void PathInterpolated::interpolatePath(const SubPath& path, const std::string& frame_id){
clearBuffers();
frame_id_ = frame_id;
std::deque<Waypoint> waypoints;
waypoints.insert(waypoints.end(),path.wps.begin(),path.wps.end());
interpolatePath(waypoints);
}
void PathInterpolated::interpolatePath(const std::deque<Waypoint>& waypoints){
//copy the waypoints to arrays X_arr and Y_arr, and introduce a new array l_arr_unif required for the interpolation
//as an intermediate step, calculate the arclength of the curve, and do the reparameterization with respect to arclength
N_ = waypoints.size();
if(N_ < 2) {
N_ = 0;
return;
}
double X_arr[N_], Y_arr[N_], l_arr[N_], l_arr_unif[N_];
double L = 0;
X_arr[0] = waypoints[0].x;
Y_arr[0] = waypoints[0].y;
l_arr[0] = 0;
for(std::size_t wp_index = 1, insert_index = 1, n = N_; wp_index < n; ++wp_index){
const Waypoint& waypoint = waypoints[wp_index];
auto dist = hypot(waypoint.x - X_arr[insert_index-1], waypoint.y - Y_arr[insert_index-1]);
if(dist >= 1e-3) {
X_arr[insert_index] = waypoint.x;
Y_arr[insert_index] = waypoint.y;
L += dist;
l_arr[insert_index] = L;
++insert_index;
} else {
// two points were to close...
ROS_WARN_STREAM("dropping point (" << waypoint.x << " / " << waypoint.y <<
") because it is too close to the last point (" << X_arr[insert_index-1] << " / " << Y_arr[insert_index-1] << ")" );
--N_;
}
}
// ROS_INFO("Length of the path: %lf m", L);
double f = std::max(0.0001, L / (double) (N_-1));
for(std::size_t i = 0; i < N_; i++){
l_arr_unif[i] = i * f;
}
//initialization before the interpolation
alglib::real_1d_array X_alg, Y_alg, l_alg, l_alg_unif;
alglib::real_1d_array x_s, y_s, x_s_prim, y_s_prim, x_s_sek, y_s_sek;
X_alg.setcontent(N_, X_arr);
Y_alg.setcontent(N_, Y_arr);
l_alg.setcontent(N_, l_arr);
l_alg_unif.setcontent(N_, l_arr_unif);
//interpolate the path and find the derivatives
try {
alglib::spline1dconvdiff2cubic(l_alg, X_alg, l_alg_unif, x_s, x_s_prim, x_s_sek);
alglib::spline1dconvdiff2cubic(l_alg, Y_alg, l_alg_unif, y_s, y_s_prim, y_s_sek);
} catch(const alglib::ap_error& error) {
ROS_FATAL_STREAM("alglib error: " << error.msg);
throw std::runtime_error(error.msg);
}
//define path components, its derivatives, and curvilinear abscissa, then calculate the path curvature
for(uint i = 0; i < N_; ++i) {
s_.push_back(l_arr_unif[i]);
p_.push_back(x_s[i]);
q_.push_back(y_s[i]);
p_prim_.push_back(x_s_prim[i]);
q_prim_.push_back(y_s_prim[i]);
p_sek_.push_back(x_s_sek[i]);
q_sek_.push_back(y_s_sek[i]);
curvature_.push_back((x_s_prim[i]*y_s_sek[i] - x_s_sek[i]*y_s_prim[i])/
(sqrt(pow((x_s_prim[i]*x_s_prim[i] + y_s_prim[i]*y_s_prim[i]), 3))));
}
assert(p_prim_.size() == N_);
assert(q_prim_.size() == N_);
assert(p_.size() == N_);
assert(q_.size() == N_);
assert(p_sek_.size() == N_);
assert(q_sek_.size() == N_);
assert(n() == N_);
}
double PathInterpolated::curvature_prim(const unsigned int i) const {
if(n() <= 1)
return 0.;
unsigned int i_1 = i == n() - 1 ? i : i + 1;
unsigned int i_0 = i_1 - 1;
// differential quotient
return (curvature(i_1) - curvature(i_0)) / (s(i_1) - s(i_0));
}
double PathInterpolated::curvature_sek(const unsigned int i) const {
if(n() <= 2)
return 0.;
unsigned int i_1 = i == n() - 1 ? i : i + 1;
unsigned int i_0 = i_1 - 1;
// differential quotient
return (curvature_prim(i_1) - curvature_prim(i_0)) / (s(i_1) - s(i_0));
}
PathInterpolated::operator nav_msgs::Path() const {
nav_msgs::Path path;
const unsigned int length = p_.size();
for (uint i = 0; i < length; ++i) {
geometry_msgs::PoseStamped poza;
poza.pose.position.x = p_[i];
poza.pose.position.y = q_[i];
path.poses.push_back(poza);
}
path.header.frame_id = frame_id_;
return path;
}
PathInterpolated::operator SubPath() const {
SubPath path(true);
path.wps.resize(p_.size());
const unsigned int length = p_.size();
for (uint i = 0; i < length; ++i) {
auto& wp = path.wps.at(i);
wp.x = p_[i];
wp.y = q_[i];
wp.orientation = std::atan2(q_prim_[i],p_prim_[i]);
wp.s = s_[i];
}
return path;
}
Path::Ptr PathInterpolated::getOriginalPath() const
{
return original_path_;
}
void PathInterpolated::clearBuffers() {
N_ = 0;
s_.clear();
p_.clear();
q_.clear();
p_prim_.clear();
q_prim_.clear();
p_sek_.clear();
q_sek_.clear();
s_new_ = 0;
s_prim_ = 0;
curvature_.clear();
interp_path.poses.clear();
}
| 26.116608
| 144
| 0.61629
|
sunarditay
|
950d7784d61f9d1a8ff34dcace7698279cd59bb3
| 2,034
|
hpp
|
C++
|
src/config/rcconfig.hpp
|
project-trident/pc-firewall
|
ef08c96faff5bdb4b1d3c2341f35a65587512fba
|
[
"BSD-2-Clause"
] | 1
|
2019-12-10T03:51:34.000Z
|
2019-12-10T03:51:34.000Z
|
src/config/rcconfig.hpp
|
project-trident/pc-firewall
|
ef08c96faff5bdb4b1d3c2341f35a65587512fba
|
[
"BSD-2-Clause"
] | null | null | null |
src/config/rcconfig.hpp
|
project-trident/pc-firewall
|
ef08c96faff5bdb4b1d3c2341f35a65587512fba
|
[
"BSD-2-Clause"
] | null | null | null |
#ifndef __RC_CONFIG
#define __RC_CONFIG
#include <qobject.h>
#include <qstring.h>
#include <qregexp.h>
#include <vector>
/*
* This class provides basic manipulation of the
* rc.conf file. It aims to reserve original file as
* good as possible, by allowing enabling/disabling of
* services and adding service depended parameters with values.
* Notice: It will automatically save the file to disk
* after a modification of the config state stored internally
* happened. Since the class does not check if the
* configuration file has been modified externally it may
* overrides external settings which where added to the file
* manually after the opening.
* It is wise to use this class just in time.
*/
class RcConfig : public QObject
{
Q_OBJECT
private:
typedef std::vector<QString> qstr_vector;
typedef std::vector<QString>::iterator qstr_vector_it;
typedef std::vector<QString>::const_iterator qstr_vector_cit;
typedef std::vector<QString>::reverse_iterator qstr_vector_revit;
typedef std::vector<QString>::const_reverse_iterator qstr_vector_crevit;
qstr_vector _lines;
QString _file;
bool _modified;
qstr_vector_it findLine ( const QRegExp& regexp );
qstr_vector_cit findLine ( const QRegExp& regexp ) const;
void save ( void );
void enable ( const QString& service, const QString& enable );
public:
RcConfig ( void );
~RcConfig ( void );
static RcConfig* fromDefault ( void );
static RcConfig* fromFile ( const QString& file );
void enable ( const QString& service );
bool isEnabled ( const QString& service ) const;
void disable ( const QString& service );
void addParameter ( const QString& service, const QString& param, const QString& value );
bool exists ( const QString& service ) const;
bool exists ( const QString& service, const QString& param ) const;
bool getParameter ( const QString& service, const QString& param, QString& retvalue ) const;
};
#endif
| 30.818182
| 96
| 0.711898
|
project-trident
|
95174568680c2dc4f1bbf5f0b1f254243bc9843a
| 5,920
|
cpp
|
C++
|
tests/constraint/test_NewtonsMethodProjectable.cpp
|
usc-csci-545/aikido
|
afd8b203c17cb0b05d7db436f8bffbbe2111a75a
|
[
"BSD-3-Clause"
] | null | null | null |
tests/constraint/test_NewtonsMethodProjectable.cpp
|
usc-csci-545/aikido
|
afd8b203c17cb0b05d7db436f8bffbbe2111a75a
|
[
"BSD-3-Clause"
] | null | null | null |
tests/constraint/test_NewtonsMethodProjectable.cpp
|
usc-csci-545/aikido
|
afd8b203c17cb0b05d7db436f8bffbbe2111a75a
|
[
"BSD-3-Clause"
] | null | null | null |
#include <aikido/constraint/NewtonsMethodProjectable.hpp>
#include <aikido/constraint/Satisfied.hpp>
#include <aikido/constraint/dart/TSR.hpp>
#include "PolynomialConstraint.hpp"
#include <aikido/statespace/Rn.hpp>
#include <Eigen/Dense>
#include <gtest/gtest.h>
using aikido::constraint::NewtonsMethodProjectable;
using aikido::constraint::Satisfied;
using aikido::constraint::dart::TSR;
using aikido::statespace::R1;
using aikido::statespace::R3;
TEST(NewtonsMethodProjectableTest, ConstructorThrowsOnNullDifferentiable)
{
EXPECT_THROW(
NewtonsMethodProjectable(nullptr, std::vector<double>{}, 1, 1),
std::invalid_argument);
}
TEST(NewtonsMethodProjectableTest, ConstructorThrowsOnBadToleranceDimension)
{
auto ss = std::make_shared<R3>();
auto constraint = std::make_shared<Satisfied>(ss); // dimension = 0
EXPECT_THROW(
NewtonsMethodProjectable(constraint, std::vector<double>({0.1}), 1, 1e-4),
std::invalid_argument);
}
TEST(NewtonsMethodProjectableTest, ConstructorThrowsOnNegativeTolerance)
{
auto constraint
= std::make_shared<PolynomialConstraint<1>>(Eigen::Vector3d(1, 2, 3));
EXPECT_THROW(
NewtonsMethodProjectable(
constraint, std::vector<double>({-0.1}), 1, 1e-4),
std::invalid_argument);
}
TEST(NewtonsMethodProjectableTest, ConstructorThrowsOnNegativeIteration)
{
auto ss = std::make_shared<R3>();
auto constraint = std::make_shared<Satisfied>(ss); // dimension = 0
EXPECT_THROW(
NewtonsMethodProjectable(constraint, std::vector<double>(), 0, 1e-4),
std::invalid_argument);
EXPECT_THROW(
NewtonsMethodProjectable(constraint, std::vector<double>(), -1, 1e-4),
std::invalid_argument);
}
TEST(NewtonsMethodProjectableTest, ConstructorThrowsOnNegativeStepsize)
{
auto ss = std::make_shared<R3>();
auto constraint = std::make_shared<Satisfied>(ss); // dimension = 0
EXPECT_THROW(
NewtonsMethodProjectable(constraint, std::vector<double>(), 1, 0),
std::invalid_argument);
EXPECT_THROW(
NewtonsMethodProjectable(constraint, std::vector<double>(), 1, -0.1),
std::invalid_argument);
}
TEST(NewtonsMethodProjectable, Constructor)
{
// Constraint: x^2 - 1 = 0.
NewtonsMethodProjectable projector(
std::make_shared<PolynomialConstraint<1>>(Eigen::Vector3d(-1, 0, 1)),
std::vector<double>({0.1}),
10,
1e-4);
}
TEST(NewtonsMethodProjectable, ProjectPolynomialFirstOrder)
{
NewtonsMethodProjectable projector(
std::make_shared<PolynomialConstraint<1>>(Eigen::Vector2d(1, 2)),
std::vector<double>({0.1}),
1,
1e-4);
Eigen::VectorXd v(1);
v(0) = -2;
R1 rvss;
auto s1 = rvss.createState();
s1.setValue(v);
auto out = rvss.createState();
ASSERT_TRUE(projector.project(s1, out));
Eigen::VectorXd projected = rvss.getValue(out);
Eigen::VectorXd expected(1);
expected(0) = -0.5;
EXPECT_TRUE(expected.isApprox(projected));
}
TEST(NewtonsMethodProjectable, ProjectPolynomialSecondOrder)
{
// Constraint: x^2 - 1 = 0.
NewtonsMethodProjectable projector(
std::make_shared<PolynomialConstraint<1>>(Eigen::Vector3d(-1, 0, 1)),
std::vector<double>({1e-6}),
10,
1e-8);
// Project x = -2. Should get -1 as projected solution.
Eigen::VectorXd v(1);
v(0) = -2;
R1 rvss;
auto seedState = rvss.createState();
seedState.setValue(v);
auto out = rvss.createState();
EXPECT_TRUE(projector.project(seedState, out));
Eigen::VectorXd projected = rvss.getValue(out);
Eigen::VectorXd expected(1);
expected(0) = -1;
EXPECT_TRUE(expected.isApprox(projected, 1e-5));
// Project x = 1.5. Should get 1 as projected solution.
v(0) = 1.5;
seedState.setValue(v);
EXPECT_TRUE(projector.project(seedState, out));
projected = rvss.getValue(out);
expected(0) = 1;
EXPECT_TRUE(expected.isApprox(projected, 1e-5));
// Project x = 1. Should get 1 as projected solution.
v(0) = 1;
seedState.setValue(v);
EXPECT_TRUE(projector.project(seedState, out));
projected = rvss.getValue(out);
expected(0) = 1;
EXPECT_TRUE(expected.isApprox(projected, 1e-5));
}
TEST(NewtonsMethodProjectable, ProjectTSRTranslation)
{
std::shared_ptr<TSR> tsr = std::make_shared<TSR>();
// non-trivial translation bounds
Eigen::MatrixXd Bw = Eigen::Matrix<double, 6, 2>::Zero();
Bw(0, 0) = 1;
Bw(0, 1) = 2;
tsr->mBw = Bw;
auto space = tsr->getSE3();
auto seedState = space->createState();
Eigen::Isometry3d isometry = Eigen::Isometry3d::Identity();
isometry.translation() = Eigen::Vector3d(-1, 0, 1);
seedState.setIsometry(isometry);
NewtonsMethodProjectable projector(
tsr, std::vector<double>(6, 1e-4), 1000, 1e-8);
auto out = space->createState();
EXPECT_TRUE(projector.project(seedState, out));
auto projected = space->getIsometry(out);
Eigen::Isometry3d expected = Eigen::Isometry3d::Identity();
expected.translation() = Eigen::Vector3d(1, 0, 0);
EXPECT_TRUE(expected.isApprox(projected, 5e-4));
}
TEST(NewtonsMethodProjectable, ProjectTSRRotation)
{
std::shared_ptr<TSR> tsr = std::make_shared<TSR>();
// non-trivial rotation bounds
Eigen::MatrixXd Bw = Eigen::Matrix<double, 6, 2>::Zero();
Bw(3, 0) = M_PI_4;
Bw(3, 1) = M_PI_2;
tsr->mBw = Bw;
auto space = tsr->getSE3();
auto seedState = space->createState();
NewtonsMethodProjectable projector(
tsr, std::vector<double>(6, 1e-4), 1000, 1e-8);
auto out = space->createState();
EXPECT_TRUE(projector.project(seedState, out));
auto projected = space->getIsometry(out);
Eigen::Isometry3d expected = Eigen::Isometry3d::Identity();
Eigen::Matrix3d rotation;
rotation = Eigen::AngleAxisd(0, Eigen::Vector3d::UnitZ())
* Eigen::AngleAxisd(0, Eigen::Vector3d::UnitY())
* Eigen::AngleAxisd(M_PI_4, Eigen::Vector3d::UnitX());
expected.linear() = rotation;
EXPECT_TRUE(expected.isApprox(projected, 5e-4));
}
| 27.663551
| 80
| 0.69527
|
usc-csci-545
|
9519e680c587c51ac577eb7957409e12dba07f14
| 3,668
|
hpp
|
C++
|
luaponte/detail/format_signature.hpp
|
jb--/luaponte
|
06bfe551bce23e411e75895797b8bb84bb662ed2
|
[
"BSL-1.0"
] | 3
|
2015-08-30T10:02:10.000Z
|
2018-08-27T06:54:44.000Z
|
luaponte/detail/format_signature.hpp
|
halmd-org/luaponte
|
165328485954a51524a0b1aec27518861c6be719
|
[
"BSL-1.0"
] | null | null | null |
luaponte/detail/format_signature.hpp
|
halmd-org/luaponte
|
165328485954a51524a0b1aec27518861c6be719
|
[
"BSL-1.0"
] | null | null | null |
// Luaponte library
// Copyright (c) 2012 Peter Colberg
// Luaponte is based on Luabind, a library, inspired by and similar to
// Boost.Python, that helps you create bindings between C++ and Lua,
// Copyright (c) 2003-2010 Daniel Wallin and Arvid Norberg.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef LUAPONTE_DETAIL_FORMAT_SIGNATURE_HPP
# define LUAPONTE_DETAIL_FORMAT_SIGNATURE_HPP
# include <luaponte/config.hpp>
# include <luaponte/lua_include.hpp>
# include <luaponte/typeid.hpp>
# include <boost/mpl/begin_end.hpp>
# include <boost/mpl/next.hpp>
# include <boost/mpl/size.hpp>
namespace luaponte {
namespace adl {
class object;
class argument;
template <class Base>
struct table;
} // namespace adl
using adl::object;
using adl::argument;
using adl::table;
namespace detail {
LUAPONTE_API std::string get_class_name(lua_State* L, type_id const& i);
template <class T>
struct type_to_string
{
static void get(lua_State* L)
{
lua_pushstring(L, get_class_name(L, typeid(T)).c_str());
}
};
template <class T>
struct type_to_string<T*>
{
static void get(lua_State* L)
{
type_to_string<T>::get(L);
lua_pushstring(L, "*");
lua_concat(L, 2);
}
};
template <class T>
struct type_to_string<T&>
{
static void get(lua_State* L)
{
type_to_string<T>::get(L);
lua_pushstring(L, "&");
lua_concat(L, 2);
}
};
template <class T>
struct type_to_string<T const>
{
static void get(lua_State* L)
{
type_to_string<T>::get(L);
lua_pushstring(L, " const");
lua_concat(L, 2);
}
};
# define LUAPONTE_TYPE_TO_STRING(x) \
template <> \
struct type_to_string<x> \
{ \
static void get(lua_State* L) \
{ \
lua_pushstring(L, #x); \
} \
};
# define LUAPONTE_INTEGRAL_TYPE_TO_STRING(x) \
LUAPONTE_TYPE_TO_STRING(x) \
LUAPONTE_TYPE_TO_STRING(unsigned x)
LUAPONTE_INTEGRAL_TYPE_TO_STRING(char)
LUAPONTE_INTEGRAL_TYPE_TO_STRING(short)
LUAPONTE_INTEGRAL_TYPE_TO_STRING(int)
LUAPONTE_INTEGRAL_TYPE_TO_STRING(long)
LUAPONTE_TYPE_TO_STRING(void)
LUAPONTE_TYPE_TO_STRING(bool)
LUAPONTE_TYPE_TO_STRING(std::string)
LUAPONTE_TYPE_TO_STRING(lua_State)
LUAPONTE_TYPE_TO_STRING(luaponte::object)
LUAPONTE_TYPE_TO_STRING(luaponte::argument)
# undef LUAPONTE_INTEGRAL_TYPE_TO_STRING
# undef LUAPONTE_TYPE_TO_STRING
template <class Base>
struct type_to_string<table<Base> >
{
static void get(lua_State* L)
{
lua_pushstring(L, "table");
}
};
template <class End>
void format_signature_aux(lua_State*, bool, End, End)
{}
template <class Iter, class End>
void format_signature_aux(lua_State* L, bool first, Iter, End end)
{
if (!first)
lua_pushstring(L, ",");
type_to_string<typename Iter::type>::get(L);
format_signature_aux(L, false, typename mpl::next<Iter>::type(), end);
}
template <class Signature>
void format_signature(lua_State* L, char const* function, Signature)
{
typedef typename mpl::begin<Signature>::type first;
type_to_string<typename first::type>::get(L);
lua_pushstring(L, " ");
lua_pushstring(L, function);
lua_pushstring(L, "(");
format_signature_aux(
L
, true
, typename mpl::next<first>::type()
, typename mpl::end<Signature>::type()
);
lua_pushstring(L, ")");
lua_concat(L, static_cast<int>(mpl::size<Signature>()) * 2 + 2);
}
} // namespace detail
} // namespace luaponte
#endif // LUAPONTE_DETAIL_FORMAT_SIGNATURE_HPP
| 22.641975
| 79
| 0.690567
|
jb--
|
951c28ea4ba42ed2e62293f33f823d22d4cd3b75
| 1,344
|
cpp
|
C++
|
src/Cpp/Learning_Cpp/Course_Codes/The_Udeamy_Course/Source_Codes_Cpp_Udeamy_Course/8. Statements-and-Operators-Source-code/ArithmeticOperators/main.cpp
|
Ahmopasa/TheCodes
|
560ed94190fd0da8cc12285e9b4b5e27b19010a5
|
[
"MIT"
] | 2
|
2021-07-18T18:12:10.000Z
|
2021-07-19T15:40:25.000Z
|
Section08/ArithmeticOperators/main.cpp
|
Himanshu40/Learn-Cpp
|
f0854f7c88bf31857c0c6216af80245666ca9b54
|
[
"CC-BY-4.0"
] | null | null | null |
Section08/ArithmeticOperators/main.cpp
|
Himanshu40/Learn-Cpp
|
f0854f7c88bf31857c0c6216af80245666ca9b54
|
[
"CC-BY-4.0"
] | null | null | null |
// Section 8
// Arithmetic operators
/*
+ addition
- subtraction
* multiplication
/ division
% modulo or remainder (works only with integers)
+, -. * and / operators are overloaded to work with multiple types such as int, double, etc.
% only for integer types
*/
#include <iostream>
using namespace std;
int main() {
int num1 {200};
int num2 {100};
// cout << num1 << " + " << num2 << " = "<< num1+ num2 << endl;
int result {0};
result = num1 + num2;
cout << num1 << " + " << num2 << " = "<< result << endl;
result = num1 - num2;
cout << num1 << " - " << num2 << " = "<< result << endl;
result = num1 * num2;
cout << num1 << " * " << num2 << " = "<< result << endl;
result = num1 / num2;
cout << num1 << " / " << num2 << " = "<< result << endl;
result = num2 / num1;
cout << num2 << " / " << num1 << " = "<< result << endl;
result = num1 % num2;
cout << num1 << " % " << num2 << " = "<< result << endl;
num1 = 10;
num2 = 3;
result = num1 % num2;
cout << num1 << " % " << num2 << " = "<< result << endl;
result = num1 * 10 + num2;
cout << 5/10 << endl;
cout << 5.0/10.0 << endl;
cout << endl;
return 0;
}
| 22.4
| 97
| 0.447917
|
Ahmopasa
|
951da4b27091e2d53251754d42ebb84d2a7b116f
| 5,529
|
cpp
|
C++
|
Final/Dataset/B2016_Z3_Z4/student5867.cpp
|
Team-PyRated/PyRated
|
1df171c8a5a98977b7a96ee298a288314d1b1b96
|
[
"MIT"
] | null | null | null |
Final/Dataset/B2016_Z3_Z4/student5867.cpp
|
Team-PyRated/PyRated
|
1df171c8a5a98977b7a96ee298a288314d1b1b96
|
[
"MIT"
] | null | null | null |
Final/Dataset/B2016_Z3_Z4/student5867.cpp
|
Team-PyRated/PyRated
|
1df171c8a5a98977b7a96ee298a288314d1b1b96
|
[
"MIT"
] | null | null | null |
/B2016/2017: Zadaća 3, Zadatak 4
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <stdexcept>
int duzina (std::string s)
{
int razmak(0);
for(int i = 0; i < s.size(); i++)
{
if(s[i] == ' ' || s[i] == '-')
razmak++;
}
return razmak;
}
std::vector<std::set<std::string>> Razvrstavanje (std::vector<std::string>v, int k)
{
if(k < 1 || k > v.size())
throw std::logic_error("Izuzetak: Razvrstavanje nemoguce");
int visak = v.size() % k;
//std::cout<<visak<<std::endl;
std::vector<int>timovi;
for(int i = 0; i < k; i++)
{
if(visak != 0)
{
timovi.push_back((int)(v.size()/k)+1);
visak--;
continue;
}
timovi.push_back(v.size()/k);
}
//for(auto x : timovi)
// std::cout<<x<<" ";
std::list<std::string>lista;
std::vector<std::set<std::string>>vektor;
std::set<std::string>skup;
for(int i = 0; i < v.size(); i++)
{
lista.push_back(v[i]);
}
auto it = lista.begin();
int brojac(0);
bool hehe(false);
int j(0);
while(17)
{
if(timovi[j] > brojac)
{
std::string s;
s = *it;
//std::cout<<s<<std::endl;
int vel(s.size());
int razmak = duzina(s);
if(razmak != 0)
vel -= razmak;
skup.insert(s);
brojac++;
it = lista.erase(it);
if(it == lista.end())
it = lista.begin();
if(it == lista.end() && --it == lista.end())
{
vektor.push_back(skup);
break;
}
//std::cout<<*it<<"*"<<std::endl;
int suma(0);
for(auto iti = lista.begin(); iti != lista.end(); iti++)
{
suma++;
}
//std::cout<<suma<<" ";
if(suma == timovi[timovi.size() - 1])
{
//it--;
vektor.push_back(skup);
auto iti(skup.begin());
for(int i = 0; i < brojac; i++)
iti = skup.erase(iti);
it = lista.begin();
for(int k = 0; k < suma ; k++)
{
skup.insert(*it);
it++;
}
vektor.push_back(skup);
//std::cout<<"bla";
hehe = true;
}
if(!hehe)
{
for(int i = 0; i < vel-1; i++)
{
if(it != lista.end())
it++;
if(it == lista.end())
it = lista.begin();
}
}
}
if(hehe)
brojac = timovi[j];
//std::cout<<j<<"*";
//std::cout<<brojac<<std::endl;
if(brojac == timovi[j])
{
//std::cout<<hehe;
/*for(auto x : skup)
std::cout<<x<<" ";
std::cout<<std::endl;*/
if(hehe)
{
//vektor.push_back(skup);
break;
}
vektor.push_back(skup);
j++;
//std::cout<<"*";
auto iti(skup.begin());
for(int i = 0; i < brojac; i++)
{
iti = skup.erase(iti);
}
brojac = 0;
// for(auto x : skup)
// std::cout<<x<<" ";
// std::cout<<std::endl;
}
}
return vektor;
}
int main ()
{
/*std::vector<std::string> v = {"ana marija", "harry james", "50 cent", "lea alma"};
auto v1 = Razvrstavanje(v, 2);
std::cout<<"main"<<std::endl;
for(std::set<std::string> const &skup : v1)
{
for(const std::string i : skup)
std::cout<<i<<" ";
std::cout<<std::endl;
}*/
std::cout<<"Unesite broj djece: ";
int broj_djece;
std::cin>>broj_djece;
std::cout<<"Unesite imena djece: ";
std::vector<std::string>v;
std::cin.ignore(1000, '\n');
for(int i = 0; i < broj_djece; i++)
{
std::string s;
std::getline(std::cin, s);
// std::cin.ignore(10000, '\n');
v.push_back(s);
}
//std::cout<<v.size();
//for(auto x : v)
// std::cout<<x<<" ";
std::cout<<std::endl<<"Unesite broj timova: ";
int broj_timova;
std::cin>>broj_timova;
try
{
auto v1 = Razvrstavanje(v, broj_timova);
int i (1);
for(std::set<std::string> const &skup : v1)
{
std::cout<<"Tim "<<i<<": ";
int br(0), vel(0);
for(auto it = skup.begin(); it != skup.end(); it++)
vel++;
for(const std::string j : skup)
{
if(br == vel-1)
std::cout<<j;
else
//std::cout<<vel<<"*";
std::cout<<j<<", ";
br++;
}
std::cout<<std::endl;
i++;
}
}
catch(std::logic_error er1)
{
std::cout<<er1.what();
return 0;
}
/*for(int i = 0; i < v1.size(); i++)
{
for(auto it = v[i].begin(); it != v[i].end(); it++)
std::cout<<*it;
std::cout<<std::endl;
}*/
return 0;
}
| 26.710145
| 86
| 0.380539
|
Team-PyRated
|
9529950721996ae477c83f006d80e4682bde144a
| 6,464
|
hh
|
C++
|
src/physics/PhysicsEngine.hh
|
nherment/gazebo
|
fff0aa30b4b5748e43c2b0aa54ffcd366e9f042a
|
[
"ECL-2.0",
"Apache-2.0"
] | 5
|
2016-01-17T20:41:39.000Z
|
2018-05-01T12:02:58.000Z
|
src/physics/PhysicsEngine.hh
|
nherment/gazebo
|
fff0aa30b4b5748e43c2b0aa54ffcd366e9f042a
|
[
"ECL-2.0",
"Apache-2.0"
] | null | null | null |
src/physics/PhysicsEngine.hh
|
nherment/gazebo
|
fff0aa30b4b5748e43c2b0aa54ffcd366e9f042a
|
[
"ECL-2.0",
"Apache-2.0"
] | 5
|
2015-09-29T02:30:16.000Z
|
2022-03-30T12:11:22.000Z
|
/*
* Copyright 2011 Nate Koenig & Andrew Howard
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/* Desc: The base class for all physics engines
* Author: Nate Koenig
*/
#ifndef PHYSICSENGINE_HH
#define PHYSICSENGINE_HH
#include <boost/thread/recursive_mutex.hpp>
#include <map>
#include <string>
#include "common/Event.hh"
#include "common/CommonTypes.hh"
#include "msgs/msgs.h"
#include "transport/TransportTypes.hh"
#include "physics/PhysicsTypes.hh"
namespace gazebo
{
namespace physics
{
/// \addtogroup gazebo_physics
/// \{
/// \brief Base class for a physics engine
class PhysicsEngine
{
/// \brief Default constructor
/// \param world Pointer to the world
public: PhysicsEngine(WorldPtr _world);
/// \brief Destructor
public: virtual ~PhysicsEngine();
/// \brief Load the physics engine
/// \param _sdf Pointer to the SDF parameters
public: virtual void Load(sdf::ElementPtr _sdf);
/// \brief Initialize the physics engine
public: virtual void Init() = 0;
/// \brief Finilize the physics engine
public: virtual void Fini();
public: virtual void Reset() {}
/// \brief Init the engine for threads.
public: virtual void InitForThread() = 0;
/// \brief Update the physics engine collision
public: virtual void UpdateCollision() = 0;
/// \brief Set the simulation update rate
public: void SetUpdateRate(double _value);
/// \brief Get the simulation update rate
public: double GetUpdateRate();
public: double GetUpdatePeriod();
/// \brief Set the simulation step time
public: virtual void SetStepTime(double _value) = 0;
/// \brief Get the simulation step time
public: virtual double GetStepTime() = 0;
/// \brief Update the physics engine
public: virtual void UpdatePhysics() {}
/// \brief Create a new body
public: virtual LinkPtr CreateLink(ModelPtr _parent) = 0;
/// \brief Create a collision
public: virtual CollisionPtr CreateCollision(
const std::string &_shapeType, LinkPtr _link) = 0;
/// \brief Create a collision
public: CollisionPtr CreateCollision(const std::string &_shapeType,
const std::string &_linkName);
public: virtual ShapePtr CreateShape(
const std::string &_shapeType,
CollisionPtr _collision) = 0;
/// \brief Create a new joint
public: virtual JointPtr CreateJoint(const std::string &_type) = 0;
/// \brief Return the gavity vector
/// \return The gavity vector
public: math::Vector3 GetGravity() const;
/// \brief Set the gavity vector
public: virtual void SetGravity(const gazebo::math::Vector3 &gravity) = 0;
/// \brief Set whether to show contacts
public: void ShowContacts(const bool &show);
/// \brief access functions to set ODE parameters
public: virtual void SetWorldCFM(double /*cfm_*/) {}
/// \brief access functions to set ODE parameters
public: virtual void SetWorldERP(double /*erp_*/) {}
/// \brief access functions to set ODE parameters
public: virtual void SetAutoDisableFlag(bool /*autoDisable_*/) {}
/// \brief access functions to set ODE parameters
public: virtual void SetSORPGSPreconIters(unsigned int /*iters_*/) {}
/// \brief access functions to set ODE parameters
public: virtual void SetSORPGSIters(unsigned int /*iters_*/) {}
/// \brief access functions to set ODE parameters
public: virtual void SetSORPGSW(double /*w_*/) {}
/// \brief access functions to set ODE parameters
public: virtual void SetContactMaxCorrectingVel(double /*vel_*/) {}
/// \brief access functions to set ODE parameters
public: virtual void SetContactSurfaceLayer(double /*layerDepth_*/) {}
/// \brief access functions to set ODE parameters
public: virtual void SetMaxContacts(double /*maxContacts_*/) {}
/// \brief access functions to set ODE parameters
public: virtual double GetWorldCFM() {return 0;}
/// \brief access functions to set ODE parameters
public: virtual double GetWorldERP() {return 0;}
/// \brief access functions to set ODE parameters
public: virtual bool GetAutoDisableFlag() {return 0;}
/// \brief access functions to set ODE parameters
public: virtual int GetSORPGSPreconIters() {return 0;}
/// \brief access functions to set ODE parameters
public: virtual int GetSORPGSIters() {return 0;}
/// \brief access functions to set ODE parameters
public: virtual double GetSORPGSW() {return 0;}
/// \brief access functions to set ODE parameters
public: virtual double GetContactMaxCorrectingVel() {return 0;}
/// \brief access functions to set ODE parameters
public: virtual double GetContactSurfaceLayer() {return 0;}
/// \brief access functions to set ODE parameters
public: virtual int GetMaxContacts() {return 0;}
/// \brief Debug print out of the physic engine state
public: virtual void DebugPrint() const = 0;
public: boost::recursive_mutex* GetPhysicsUpdateMutex() const
{ return this->physicsUpdateMutex; }
protected: virtual void OnRequest(ConstRequestPtr &/*_msg*/) {}
protected: virtual void OnPhysicsMsg(ConstPhysicsPtr &/*_msg*/) {}
protected: WorldPtr world;
protected: sdf::ElementPtr sdf;
protected: transport::NodePtr node;
protected: transport::PublisherPtr responsePub, contactPub;
protected: transport::SubscriberPtr physicsSub, requestSub;
protected: boost::recursive_mutex *physicsUpdateMutex;
/// Store the value of the updateRate parameter in double form.
/// To improve efficiency.
private: double updateRateDouble;
};
/// \}
}
}
#endif
| 36.937143
| 80
| 0.670483
|
nherment
|
952b3309e85bbcb8f04d3e63ded6b9c8220e199d
| 12,554
|
hpp
|
C++
|
include/wire/encoding/message.hpp
|
zmij/wire
|
9981eb9ea182fc49ef7243eed26b9d37be70a395
|
[
"Artistic-2.0"
] | 5
|
2016-04-07T19:49:39.000Z
|
2021-08-03T05:24:11.000Z
|
include/wire/encoding/message.hpp
|
zmij/wire
|
9981eb9ea182fc49ef7243eed26b9d37be70a395
|
[
"Artistic-2.0"
] | null | null | null |
include/wire/encoding/message.hpp
|
zmij/wire
|
9981eb9ea182fc49ef7243eed26b9d37be70a395
|
[
"Artistic-2.0"
] | 1
|
2020-12-27T11:47:31.000Z
|
2020-12-27T11:47:31.000Z
|
/*
* message.hpp
*
* Created on: Jan 21, 2016
* Author: zmij
*/
#ifndef WIRE_ENCODING_MESSAGE_HPP_
#define WIRE_ENCODING_MESSAGE_HPP_
#include <wire/encoding/types.hpp>
#include <wire/encoding/wire_io.hpp>
#include <wire/core/identity.hpp>
#include <wire/core/context.hpp>
#include <wire/version.hpp>
#include <iomanip>
#include <cctype>
namespace wire {
namespace encoding {
struct version {
uint32_t major;
uint32_t minor;
bool
operator == (version const& rhs) const
{
return major == rhs.major && minor == rhs.minor;
}
bool
operator != (version const& rhs) const
{
return !(*this == rhs);
}
bool
operator < (version const& rhs) const
{
return major < rhs.major || (major == rhs.major && minor < rhs.minor);
}
bool
operator <= (version const& rhs) const
{
return major <= rhs.major || (major == rhs.major && minor <= rhs.minor);
}
bool
operator > (version const& rhs) const
{
return rhs < *this;
}
bool
operator >= (version const& rhs) const
{
return rhs <= *this;
}
void
swap(version& rhs) noexcept
{
using ::std::swap;
swap(major, rhs.major);
swap(minor, rhs.minor);
}
};
template < typename OutputIterator >
void
wire_write(OutputIterator o, version const& v)
{
write(o, v.major, v.minor);
}
template < typename InputIterator >
void
wire_read(InputIterator& begin, InputIterator end, version& v)
{
version tmp;
read(begin, end, tmp.major, tmp.minor);
v.swap(tmp);
}
template < typename InputIterator >
bool
try_read(InputIterator& start, InputIterator end, version& v)
{
using reader = detail::reader<decltype(v.major)>;
version tmp;
auto begin = start;
if (!reader::try_input(begin, end, tmp.major))
return false;
if (!reader::try_input(begin, end, tmp.minor))
return false;
v.swap(tmp);
start = begin;
return true;
}
struct message {
using size_type = uint64_t;
enum message_flags {
// Types
request = 0,
reply = 2,
validate = 3,
close = 4,
// Flags
protocol = 8, /**< Message header contains protocol version */
encoding = 0x10, /**< Message header contains encoding version */
// Combinations
validate_flags = validate | protocol | encoding,
// Masks
type_bits = reply | validate | close,
flag_bits = ~type_bits,
};
static constexpr uint32_t MAGIC_NUMBER =
('w') | ('i' << 8) | ('r' << 16) | ('e' << 24);
static constexpr uint32_t magic_number_size = sizeof(uint32_t);
/** 4 bytes for magic number, 1 for flags, 1 for size */
static constexpr uint32_t min_header_size = 6;
/** 4 bytes for magic number, 1 for flags, 2 for protocol version
* 2 for encoding version, 9 - for maximum possible size
*/
static constexpr uint32_t max_header_size = 18;
version protocol_version = version{ ::wire::PROTOCOL_MAJOR, ::wire::PROTOCOL_MINOR };
version encoding_version = version{ ::wire::ENCODING_MAJOR, ::wire::ENCODING_MINOR };
message_flags flags = request;
size_type size = 0;
message() = default;
message(message_flags flags, size_type size)
: flags(flags), size(size)
{}
bool
operator == (message const& rhs) const
{
return protocol_version == rhs.protocol_version
&& encoding_version == rhs.encoding_version
&& flags == rhs.flags
&& size == rhs.size;
}
void
swap(message& rhs) noexcept
{
using ::std::swap;
swap(protocol_version, rhs.protocol_version);
swap(encoding_version, rhs.encoding_version);
swap(flags, rhs.flags);
swap(size, rhs.size);
}
message_flags
type() const
{
return static_cast<message_flags>(flags & type_bits);
}
};
::std::ostream&
operator << (::std::ostream& out, message::message_flags val);
} // namespace encoding
} // namespace wire
namespace std {
inline void
swap(wire::encoding::message& lhs, wire::encoding::message& rhs)
{
lhs.swap(rhs);
}
}
namespace wire {
namespace encoding {
template < typename OutputIterator >
void
wire_write(OutputIterator o, message const& v)
{
write(o, int32_fixed_t(message::MAGIC_NUMBER));
write(o, v.flags);
// write this info depending on flags
if (v.flags & message::protocol)
write(o, PROTOCOL_MAJOR, PROTOCOL_MINOR);
if (v.flags & message::encoding)
write(o, v.encoding_version);
write(o, v.size);
}
template < typename InputIterator >
void
read(InputIterator& begin, InputIterator end, message& v)
{
int32_fixed_t magic;
read(begin, end, magic);
if (magic != message::MAGIC_NUMBER) {
// Unrecoverable
throw errors::invalid_magic_number("Invalid magic number in message header");
}
message tmp;
read(begin, end, tmp.flags);
// read this info depending on message flags
if (tmp.flags & message::protocol)
read(begin, end, tmp.protocol_version);
if (tmp.flags & message::encoding)
read(begin, end, tmp.encoding_version);
read(begin, end, tmp.size);
v.swap(tmp);
}
/**
* Try to read message header from buffer.
* @pre Minimum size of the buffer to succeed is message::min_header_size
* @param begin
* @param end
* @param v
* @return
*/
template < typename InputIterator >
bool
try_read(InputIterator& start, InputIterator end, message& v)
{
using flags_reader = detail::reader<message::message_flags>;
using size_reader = detail::reader<message::size_type>;
if (end - start < message::magic_number_size)
return false; // We cannot read even the magic number
auto begin = start;
int32_fixed_t magic;
read(begin, end, magic);
if (magic != message::MAGIC_NUMBER) {
// Unrecoverable
::std::ostringstream os;
os << "Invalid magic number in message header (buffer size "
<< (end - start) << ", first bytes of message: ";
begin = start;
::std::ostringstream hex_rep;
hex_rep << "0x";
for (int i = 0; i < 8 && begin != end; ++i, ++begin) {
char c = *begin;
if (::std::isprint(c)) {
os.put(c);
} else {
os.put('.');
}
hex_rep << ::std::hex << ::std::setfill('0') << ::std::setw(2)
<< ((int)c & 0xff);
}
os << " [" << hex_rep.str() << "])";
throw errors::invalid_magic_number(os.str());
}
message tmp;
if (!flags_reader::try_input(begin, end, tmp.flags))
return false;
if (tmp.flags & message::protocol) {
if (!try_read(begin, end, tmp.protocol_version))
return false;
}
if (tmp.flags & message::encoding) {
if (!try_read(begin, end, tmp.encoding_version))
return false;
}
if (!size_reader::try_input(begin, end, tmp.size))
return false;
v.swap(tmp);
start = begin;
return true;
}
struct invocation_target {
core::identity identity;
::std::string facet;
void
swap(invocation_target& rhs)
{
using ::std::swap;
swap(identity, rhs.identity);
swap(facet, rhs.facet);
}
bool
operator == (invocation_target const& rhs) const
{
return identity == rhs.identity && facet == rhs.facet;
}
bool
operator != (invocation_target const& rhs) const
{
return !(*this == rhs);
}
bool
operator < (invocation_target const& rhs) const
{
return identity < rhs.identity ||
(identity == rhs.identity && facet < rhs.facet);
}
};
template < typename OutputIterator >
void
wire_write(OutputIterator o, invocation_target const& v)
{
write(o,
v.identity, v.facet
);
}
template < typename InputIterator >
void
wire_read(InputIterator& begin, InputIterator end, invocation_target& v)
{
invocation_target tmp;
read(begin, end, tmp.identity, tmp.facet);
v.swap(tmp);
}
::std::ostream&
operator << (::std::ostream& os, invocation_target const& val);
using multiple_targets = ::std::set<invocation_target>;
struct operation_specs {
enum operation_type {
name_hash,
name_string
};
using hash_type = uint32_fixed_t;
using operation_id = boost::variant< hash_type, ::std::string >;
invocation_target target;
operation_id operation;
void
swap(operation_specs& rhs)
{
using ::std::swap;
swap(target, rhs.target);
swap(operation, rhs.operation);
}
bool
operator == (operation_specs const& rhs) const
{
return target == rhs.target && operation == rhs.operation;
}
bool
operator != (operation_specs const& rhs) const
{
return !(*this == rhs);
}
operation_type
type() const
{
return static_cast<operation_type>(operation.which());
}
::std::string const&
name() const
{
if (type() != name_string)
throw ::std::runtime_error("Operation name is hashed");
return ::boost::get<::std::string>(operation);
}
};
template < typename OutputIterator >
void
wire_write(OutputIterator o, operation_specs const& v)
{
write(o,
v.target, v.operation
);
}
template < typename InputIterator >
void
wire_read(InputIterator& begin, InputIterator end, operation_specs& v)
{
operation_specs tmp;
read(begin, end, tmp.target, tmp.operation);
v.swap(tmp);
}
struct request {
using request_number = ::std::uint64_t;
enum request_mode {
normal = 0x00,
one_way = 0x01,
multi_target = 0x02,
no_context = 0x10,
no_body = 0x20,
};
request_number number;
operation_specs operation;
request_mode mode;
void
swap(request& rhs)
{
using ::std::swap;
swap(number, rhs.number);
swap(operation, rhs.operation);
swap(mode, rhs.mode);
}
bool
operator == (request const& rhs) const
{
return number == rhs.number && operation == rhs.operation && mode == rhs.mode;
}
bool
operator != (request const& rhs) const
{
return !(*this == rhs);
}
};
inline request::request_mode
operator | (request::request_mode lhs, request::request_mode rhs)
{
using integral_type = ::std::underlying_type<request::request_mode>::type;
return static_cast<request::request_mode>(
static_cast<integral_type>(lhs) | static_cast<integral_type>(rhs) );
}
inline request::request_mode&
operator |= (request::request_mode& lhs, request::request_mode rhs)
{
return lhs = lhs | rhs;
}
template < typename OutputIterator >
void
wire_write(OutputIterator o, request const& v)
{
write(o, v.number, v.operation, v.mode);
}
template < typename InputIterator >
void
wire_read(InputIterator& begin, InputIterator end, request& v)
{
request tmp;
read(begin, end, tmp.number, tmp.operation, tmp.mode);
v.swap(tmp);
}
struct reply {
using request_number = request::request_number;
enum reply_status {
success,
success_no_body,
user_exception,
no_object,
no_facet,
no_operation,
unknown_wire_exception,
unknown_user_exception,
unknown_exception
};
request_number number;
reply_status status;
void
swap(reply& rhs)
{
using ::std::swap;
swap(number, rhs.number);
swap(status, rhs.status);
}
bool
operator == (reply const& rhs) const
{
return number == rhs.number && status == rhs.status;
}
bool
operator != (reply const& rhs) const
{
return !(*this == rhs);
}
};
template < typename OutputIterator >
void
wire_write(OutputIterator o, reply const& v)
{
write(o, v.number, v.status);
}
template < typename InputIterator >
void
wire_read(InputIterator& begin, InputIterator end, reply& v)
{
reply tmp;
read(begin, end, tmp.number, tmp.status);
v.swap(tmp);
}
} // namespace encoding
} // namespace wire
#endif /* WIRE_ENCODING_MESSAGE_HPP_ */
| 23.86692
| 100
| 0.598295
|
zmij
|
952c8c203293fcea3f1a4316e26e92ca53194fb0
| 66
|
cpp
|
C++
|
Unreal/CtaCpp/Runtime/Scripts/Combat/IDamageCalculationSystem.cpp
|
areilly711/CtaApi
|
8c7a80c48f2a6d02fb6680a5d8f62e6ff7da8d4c
|
[
"MIT"
] | 3
|
2021-06-02T16:44:02.000Z
|
2022-01-24T20:20:10.000Z
|
Unreal/CtaCpp/Runtime/Scripts/Combat/IDamageCalculationSystem.cpp
|
areilly711/CtaApi
|
8c7a80c48f2a6d02fb6680a5d8f62e6ff7da8d4c
|
[
"MIT"
] | null | null | null |
Unreal/CtaCpp/Runtime/Scripts/Combat/IDamageCalculationSystem.cpp
|
areilly711/CtaApi
|
8c7a80c48f2a6d02fb6680a5d8f62e6ff7da8d4c
|
[
"MIT"
] | null | null | null |
#include "IDamageCalculationSystem.h"
namespace Cta::Combat
{
}
| 11
| 38
| 0.757576
|
areilly711
|
953833ac2864423265ddc4a58fda008ef5fd79ce
| 1,395
|
cc
|
C++
|
Kernel/KernelMain.cc
|
ahoka/esrtk
|
bb5ff7f9caa22b6d6d91e660c6d78e471394a0cc
|
[
"BSD-2-Clause"
] | 1
|
2018-07-08T15:47:57.000Z
|
2018-07-08T15:47:57.000Z
|
Kernel/KernelMain.cc
|
ahoka/esrtk
|
bb5ff7f9caa22b6d6d91e660c6d78e471394a0cc
|
[
"BSD-2-Clause"
] | null | null | null |
Kernel/KernelMain.cc
|
ahoka/esrtk
|
bb5ff7f9caa22b6d6d91e660c6d78e471394a0cc
|
[
"BSD-2-Clause"
] | null | null | null |
#include <Memory.hh>
#include <Modules.hh>
#include <Platform.hh>
#include <CompilerSupport.hh>
#include <Kernel/Scheduler.hh>
#include <Multiboot.hh>
// XXX remove these
#include <X86/PageDirectory.hh>
#include <X86/Idt.hh>
#include <X86/EarlySerial.hh>
#include <Kernel/ProcessContext.hh>
#include <Supervisor/Supervisor.hh>
#include <Kernel/PerfCounter.hh>
#include <Kernel/Heap.hh>
#include <Kernel/Thread.hh>
#include <Power.hh>
#include <cstdio>
extern unsigned int magic;
extern "C" void mi_startup(void);
extern "C" void
kmain()
{
if (magic != 0x2badb002)
{
printf("Incorrect multiboot magic: 0x%0x != 0x%0x\n", magic, 0x2badb002);
// not loaded by a multiboot loader, this is not yet supported
//
Power::halt();
}
Kernel::ProcessContext::init();
EarlySerial::init();
printf("Kernel main starting...\n");
initInterrupts();
Memory::copyMemoryMap();
Modules::init();
PageDirectory::init();
Memory::init();
Kernel::Heap::init();
printf("Memory management initialized...\n");
Kernel::Scheduler::init();
// Call C++ constructors
__cxaimpl_call_constructors();
Platform::init();
Multiboot::getSymbols();
Supervisor::Supervisor::init();
printf("Initializing BSD...\n");
//mi_startup();
printf("Kernel initialized!\n");
Kernel::Thread::main(Kernel::Scheduler::getKernelThread());
}
| 19.647887
| 79
| 0.670251
|
ahoka
|
953bf65856af1b3824fe1cc6b79b53ad0801d7ef
| 471
|
cpp
|
C++
|
p1140.cpp
|
ThinkiNOriginal/PTA-Advanced
|
55cae28f76102964d0f6fd728dd62d6eba980c49
|
[
"MIT"
] | null | null | null |
p1140.cpp
|
ThinkiNOriginal/PTA-Advanced
|
55cae28f76102964d0f6fd728dd62d6eba980c49
|
[
"MIT"
] | null | null | null |
p1140.cpp
|
ThinkiNOriginal/PTA-Advanced
|
55cae28f76102964d0f6fd728dd62d6eba980c49
|
[
"MIT"
] | null | null | null |
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
string D;
int N;
cin >> D >> N;
for (int i = 1; i < N; i++) {
string tmp;
int len = D.size();
for (int j = 0; j < len; j++) {
int cnt = 1;
for (int k = j + 1; k < len; k++) {
if (D[k] == D[j]) {
cnt++;
j = k;
} else {
break;
}
}
tmp += D[j] + to_string(cnt);
}
D = tmp;
}
cout << D << endl;
return 0;
}
| 13.852941
| 38
| 0.458599
|
ThinkiNOriginal
|
953e171f9981e0dc9e6b6c867345b228cec9f9e0
| 34,071
|
cpp
|
C++
|
Client/client/World/PacketHandler.cpp
|
pinkmouse/SlayersWorld
|
53cdde28f3464ee9ada9b655f8c4df63f0e9389e
|
[
"MIT"
] | 14
|
2019-03-05T10:03:59.000Z
|
2021-12-21T03:00:18.000Z
|
Client/client/World/PacketHandler.cpp
|
pinkmouse/SlayersWorld
|
53cdde28f3464ee9ada9b655f8c4df63f0e9389e
|
[
"MIT"
] | 1
|
2019-10-24T21:37:59.000Z
|
2019-10-24T21:37:59.000Z
|
Client/client/World/PacketHandler.cpp
|
pinkmouse/SlayersWorld
|
53cdde28f3464ee9ada9b655f8c4df63f0e9389e
|
[
"MIT"
] | 1
|
2020-12-06T21:07:52.000Z
|
2020-12-06T21:07:52.000Z
|
#include "PacketHandler.hpp"
#include "../Entities/Player.hpp"
#include "../Entities/Creature.hpp"
#include "../Entities/AnimationUnit.hpp"
#include "../Entities/DynamicObject.hpp"
#include "../Graphics/Interface/MenuTitles.hpp"
#include "../Graphics/Interface/MenuWardrobe.hpp"
#include "../Graphics/Interface/MenuSpells.hpp"
#include "../Graphics/Interface/MenuBag.hpp"
#include "../Graphics/Interface/MenuEquipment.hpp"
#include "../Graphics/Interface/MenuSell.hpp"
#include "../Global.hpp"
#include "PacketDefine.hpp"
PacketHandler::PacketHandler(MapManager* p_MapManager, InterfaceManager* p_InterfaceManager) :
m_MapManager(p_MapManager),
m_InterfaceManager(p_InterfaceManager)
{
p_HasMinimalRequiered = false;
}
PacketHandler::~PacketHandler()
{
}
void PacketHandler::LoadPacketHandlerMap()
{
m_PacketHandleMap[SMSG::S_Connexion] = &PacketHandler::HandleConnexion;
m_PacketHandleMap[SMSG::S_PlayerCreate] = &PacketHandler::HandleCreateMainPlayer;
m_PacketHandleMap[SMSG::S_UnitCreate] = &PacketHandler::HandleCreateUnit;
m_PacketHandleMap[SMSG::S_UnitRemove] = &PacketHandler::HandleRemoveUnit;
m_PacketHandleMap[SMSG::S_SwitchMap] = &PacketHandler::HandleSwitchMap;
m_PacketHandleMap[SMSG::S_UnitUpdateResource] = &PacketHandler::HandleUpdateResource;
m_PacketHandleMap[SMSG::S_PlayerUpdateXp] = &PacketHandler::HandleUpdateXpPct;
m_PacketHandleMap[SMSG::S_UnitGoDirection] = &PacketHandler::HandleUnitGoDirection;
m_PacketHandleMap[SMSG::S_UnitStopMovement] = &PacketHandler::HandleStopMovement;
m_PacketHandleMap[SMSG::S_UnitUpdatePosition] = &PacketHandler::HandleUpdatePosition;
m_PacketHandleMap[SMSG::S_UnitUpdateOrientation] = &PacketHandler::HandleUpdateOrientation;
m_PacketHandleMap[SMSG::S_UnitTalk] = &PacketHandler::HandleTalk;
m_PacketHandleMap[SMSG::S_SrvPlayerMsg] = &PacketHandler::HandleSrvPlayerMsg;
m_PacketHandleMap[SMSG::S_UnitStartAttack] = &PacketHandler::HandleUnitStartAttack;
m_PacketHandleMap[SMSG::S_UnitStopAttack] = &PacketHandler::HandleUnitStopAttack;
m_PacketHandleMap[SMSG::S_UnitUpdateSkin] = &PacketHandler::HandleUpdateSkin;
m_PacketHandleMap[SMSG::S_LogDamage] = &PacketHandler::HandleLogDamage;
m_PacketHandleMap[SMSG::S_WarningMsg] = &PacketHandler::HandleWarningMsg;
m_PacketHandleMap[SMSG::S_UnitPlayVisual] = &PacketHandler::HandleUnitPlayVisual;
m_PacketHandleMap[SMSG::S_UnitUpdateStat] = &PacketHandler::HandleUpdateStat;
m_PacketHandleMap[SMSG::S_KeyBoardBind] = &PacketHandler::HandleKeyBoardBind;
m_PacketHandleMap[SMSG::S_BlockBind] = &PacketHandler::HandleKeyBindBlock;
m_PacketHandleMap[SMSG::S_CastBar] = &PacketHandler::HandleCastBar;
m_PacketHandleMap[SMSG::S_LoadingPing] = &PacketHandler::HandleLoadingPing;
m_PacketHandleMap[SMSG::S_ExtraInterface] = &PacketHandler::HandleExtraUI;
m_PacketHandleMap[SMSG::S_UnitIsInGroup] = &PacketHandler::HandleUnitIsInGroup;
m_PacketHandleMap[SMSG::S_SrvPlayerQuestion] = &PacketHandler::HandleSrvPlayerQuestion;
m_PacketHandleMap[SMSG::S_ExtraInterfaceData] = &PacketHandler::HandleExtraUIData;
m_PacketHandleMap[SMSG::S_UnitPlayAuraVisual] = &PacketHandler::HandleUnitPlayVisualAura;
m_PacketHandleMap[SMSG::S_UnitMount] = &PacketHandler::HandleMount;
m_PacketHandleMap[SMSG::S_PlayerTitle] = &PacketHandler::HandlePlayerTitle;
m_PacketHandleMap[SMSG::S_PlayerSkin] = &PacketHandler::HandlePlayerSkin;
m_PacketHandleMap[SMSG::S_PlayerSpell] = &PacketHandler::HandlePlayerSpell;
m_PacketHandleMap[SMSG::S_PlayerItem] = &PacketHandler::HandlePlayerItem;
m_PacketHandleMap[SMSG::S_PlayerEquipment] = &PacketHandler::HandlePlayerEquipment;
m_PacketHandleMap[SMSG::S_PlayerBagSize] = &PacketHandler::HandlePlayerBagSize;
m_PacketHandleMap[SMSG::S_PlayerRemoveItem] = &PacketHandler::HandlePlayerRemoveItem;
m_PacketHandleMap[SMSG::S_PlayerRemoveEquipment] = &PacketHandler::HandlePlayerRemoveEquipment;
m_PacketHandleMap[SMSG::S_PlayerStackItem] = &PacketHandler::HandlePlayerStackItem;
m_PacketHandleMap[SMSG::S_PlayerUpdateCurrency] = &PacketHandler::HandlePlayerUpdateCurrency;
m_PacketHandleMap[SMSG::S_UnitUpdateName] = &PacketHandler::HanleUnitUpdateName;
m_PacketHandleMap[SMSG::S_SellItemInterface] = &PacketHandler::HandleSellItemInterface;
m_PacketHandleMap[SMSG::S_BindingSpell] = &PacketHandler::HandleBindingSpell;
}
void PacketHandler::HandleExtraUI(WorldPacket &p_Packet)
{
uint8 l_ExtraUI;
bool l_Enable;
p_Packet >> l_ExtraUI;
p_Packet >> l_Enable;
if (l_Enable)
m_InterfaceManager->AddExtraInterface((eExtraInterface)l_ExtraUI);
else
m_InterfaceManager->RemoveExtraInterface((eExtraInterface)l_ExtraUI);
}
void PacketHandler::HandleExtraUIData(WorldPacket &p_Packet)
{
uint8 l_ExtraUI;
uint8 l_Index;
uint8 l_Type;
int16 l_Data;
p_Packet >> l_ExtraUI;
p_Packet >> l_Index;
p_Packet >> l_Type;
p_Packet >> l_Data;
m_InterfaceManager->AddExtraUiData((eExtraInterface)l_ExtraUI, l_Index, l_Type, l_Data);
printf("Data = %d\n", l_Data);
}
void PacketHandler::HandleMount(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_ID;
int16 l_MountSkin;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
p_Packet >> l_MountSkin;
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_ID);
if (l_Unit == nullptr)
return;
l_Unit->SetMount(l_MountSkin);
}
}
void PacketHandler::HandleRemoveUnit(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_ID;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_ID);
if (l_Unit == nullptr)
return;
l_Map->RemoveUnit(l_Unit);
delete l_Unit;
}
}
void PacketHandler::HandleUpdateResource(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_ID;
uint8 l_Resource;
uint8 l_NewNb;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
p_Packet >> l_Resource;
p_Packet >> l_NewNb;
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = nullptr;
l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_ID);
if (l_Unit == nullptr)
return;
l_Unit->SetResourceNb((eResourceType)l_Resource, l_NewNb);
}
}
void PacketHandler::HandleUpdateXpPct(WorldPacket &p_Packet)
{
float l_XpPct;
p_Packet >> l_XpPct;
g_Player->SetXpPct(l_XpPct);
}
void PacketHandler::HandleTalk(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_ID;
std::string l_String;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
p_Packet >> l_String;
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = nullptr;
l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_ID);
if (l_Unit == nullptr)
return;
l_Unit->SetTalk(l_String);
if ((TypeUnit)l_TypeID == TypeUnit::PLAYER)
m_InterfaceManager->GetHistoryField()->AddHistoryLine(l_Unit->GetName() + ": " + l_String);
}
}
void PacketHandler::HandleStopMovement(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_ID;
Position l_Pos;
uint16 l_PosX;
uint16 l_PosY;
uint8 l_Orientation;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
p_Packet >> l_PosX;
p_Packet >> l_PosY;
p_Packet >> l_Orientation;
l_Pos.x = l_PosX;
l_Pos.y = l_PosY;
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_ID);
if (l_Unit == nullptr)
{
g_Socket->SendUnitUnknow(l_TypeID, l_ID); ///< Ask for unknow unit to server
return;
}
l_Unit->GetMovementHandler()->AddMovementToStack(eActionType::Stop, l_Pos, (Orientation)l_Unit->GetOrientation());
}
}
void PacketHandler::HandleUnitStartAttack(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_ID;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
//printf("Attack for Type :%d, ID:%d, posX:%d, posY:%d, orientation:%d\n", l_TypeID, l_ID, l_Pos.x, l_Pos.y, l_Orientation);
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_ID);
if (l_Unit == nullptr)
{
g_Socket->SendUnitUnknow(l_TypeID, l_ID); ///< Ask for unknow unit to server
return;
}
if ((TypeUnit)l_TypeID == TypeUnit::ANIMATIONUNIT)
l_Unit->LaunchAnim();
else
l_Unit->GetMovementHandler()->AddMovementToStack(eActionType::Attack);
}
}
void PacketHandler::HandleUnitStopAttack(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_ID;
Position l_Pos;
l_Pos.x = 0;
l_Pos.y = 0;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_ID);
if (l_Unit == nullptr)
{
g_Socket->SendUnitUnknow(l_TypeID, l_ID); ///< Ask for unknow unit to server
return;
}
l_Unit->GetMovementHandler()->AddMovementToStack(eActionType::StopAttack);
}
}
void PacketHandler::HandleUpdateOrientation(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_ID;
uint8 l_Orientation;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
p_Packet >> l_Orientation;
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_ID);
if (l_Unit == nullptr)
{
printf("Unit Unknow %d\n", l_ID);
g_Socket->SendUnitUnknow(l_TypeID, l_ID); ///< Ask for unknow unit to server
return;
}
l_Unit->SetOrientation((Orientation)l_Orientation);
}
}
void PacketHandler::HandleUpdatePosition(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_UnitID;
uint16 l_MapId;
uint16 l_PosX;
uint16 l_PosY;
uint8 l_Orientation;
p_Packet >> l_TypeID;
p_Packet >> l_UnitID;
p_Packet >> l_MapId;
p_Packet >> l_PosX;
p_Packet >> l_PosY;
p_Packet >> l_Orientation;
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_UnitID);
if (l_Unit == nullptr)
{
g_Socket->SendUnitUnknow(l_TypeID, l_UnitID); ///< Ask for unknow unit to server
return;
}
WorldPosition l_WorldPosition((uint32)l_PosX, (uint32)l_PosY, l_MapId, (Orientation)l_Orientation);
l_Unit->TeleportTo(l_WorldPosition);
}
}
void PacketHandler::HandleUnitGoDirection(WorldPacket &p_Packet)
{
uint8 l_Type;
uint16 l_UnitID;
uint8 l_Direction;
Position l_Pos;
uint16 l_PosX;
uint16 l_PosY;
p_Packet >> l_Type;
p_Packet >> l_UnitID;
p_Packet >> l_PosX;
p_Packet >> l_PosY;
p_Packet >> l_Direction;
l_Pos.x = (uint32)l_PosX;
l_Pos.y = (uint32)l_PosY;
if (Map* l_Map = m_MapManager->GetActualMap())
l_Map->MoveUnitToDirection((TypeUnit)l_Type, l_UnitID, l_Pos, l_Direction);
}
void PacketHandler::HandleConnexion(WorldPacket &p_Packet)
{
uint8 l_Status;
p_Packet >> l_Status;
printf("Auth Status: %d\n", l_Status);
switch (l_Status)
{
case 0:
m_InterfaceManager->SetSystemMsg("Authentication failed");
printf("Auth Failed\n");
break;
case 1:
m_InterfaceManager->SetSystemMsg("Authentication success");
printf("Auth Success\n");
break;
case 2:
m_InterfaceManager->SetSystemMsg("Already connected");
printf("Already connected\n");
break;
case 3:
m_InterfaceManager->SetSystemMsg("Access denied");
printf("Access denied\n");
break;
}
}
void PacketHandler::HandleCreateMainPlayer(WorldPacket &p_Packet)
{
uint32 l_ID;
std::string l_Name;
uint8 l_Level;
uint8 l_Health;
uint8 l_Mana;
uint8 l_Alignment;
int16 l_SkinID;
uint16 l_MapID;
std::string l_MapFileName;
std::string l_MapChipsetName;
std::string l_MapName;
uint32 l_PosX;
uint32 l_PosY;
uint8 l_Orientation;
p_Packet >> l_ID;
p_Packet >> l_Name;
p_Packet >> l_Level;
p_Packet >> l_Health;
p_Packet >> l_Mana;
p_Packet >> l_Alignment;
p_Packet >> l_SkinID;
p_Packet >> l_MapID;
p_Packet >> l_MapFileName;
p_Packet >> l_MapChipsetName;
p_Packet >> l_MapName;
p_Packet >> l_PosX;
p_Packet >> l_PosY;
p_Packet >> l_Orientation;
if (!m_MapManager->LoadMap(l_MapID, l_MapFileName, l_MapChipsetName, l_MapName))
return;
g_Player = new Player(l_ID, l_Name, l_Level, l_Health, l_Mana, l_Alignment, l_SkinID, 24, 32, l_MapID, l_PosX, l_PosY, (Orientation)l_Orientation);
m_MapManager->SetPosX(l_PosX);
m_MapManager->SetPosY(l_PosY);
if (Map* l_ActualMap = m_MapManager->GetActualMap())
{
g_Player->SetMap(l_ActualMap);
l_ActualMap->AddUnit(g_Player);
p_HasMinimalRequiered = true;
}
else
delete g_Player;
}
void PacketHandler::HandleCreateUnit(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_ID;
std::string l_Name;
uint8 l_Level = 1;
uint8 l_Health = 100;
uint8 l_Mana = 100;
uint8 l_Alignment = 100;
int16 l_SkinID;
uint8 l_SizeX;
uint8 l_SizeY;
uint8 l_Speed;
uint16 l_MapID;
Position l_Pos;
uint8 l_Orientation;
bool l_IsInMovement;
bool l_IsInAttack = false;
bool l_IsBlocking = false;
bool l_IsInGroup = false;
uint16 l_PosX;
uint16 l_PosY;
/* PLAYER/CREATURE : Orientation / IsMovement / IsAttack / IsGroup */
/* AREATRIGGER/GOB : Orientation / IsMovement / IsBlocking */
CharOn41111 l_StructData;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
p_Packet >> l_Name;
if (l_TypeID < TypeUnit::AREATRIGGER) ///< Only Player and Creature
{
p_Packet >> l_Level;
p_Packet >> l_Health;
p_Packet >> l_Mana;
p_Packet >> l_Alignment;
}
p_Packet >> l_SkinID;
p_Packet >> l_SizeX;
p_Packet >> l_SizeY;
p_Packet >> l_Speed;
p_Packet >> l_MapID;
p_Packet >> l_PosX;
p_Packet >> l_PosY;
p_Packet >> l_StructData.m_Byte_value;
l_Pos.x = (uint32)l_PosX;
l_Pos.y = (uint32)l_PosY;
l_Orientation = l_StructData.charOn41111.first;
l_IsInMovement = (bool)l_StructData.charOn41111.second;
if (l_TypeID < 2) ///< Only Player and Creature
{
l_IsInAttack = (bool)l_StructData.charOn41111.third;
l_IsInGroup = (bool)l_StructData.charOn41111.fourth;
}
else
{
l_IsBlocking = (bool)l_StructData.charOn41111.third;
}
/* if (l_TypeID == (uint8)TypeUnit::PLAYER)
printf("Create new Player: %d %s %d %d %d %d\n", l_ID, l_Name.c_str(), l_SkinID, l_MapID, l_Pos.x, l_Pos.y);
else
printf("Create new Unit: %d %s %d %d %d %d\n", l_ID, l_Name.c_str(), l_SkinID, l_MapID, l_Pos.x, l_Pos.y);*/
Unit* l_NewUnit = nullptr;
Map* l_ActualMap = m_MapManager->GetActualMap();
if (l_ActualMap == nullptr)
return;
if (l_ActualMap->GetID() == l_MapID && l_ActualMap->GetUnit((TypeUnit)l_TypeID, l_ID) == nullptr)
{
if (l_TypeID == (uint8)TypeUnit::PLAYER)
l_NewUnit = new Player(l_ID, l_Name, l_Level, l_Health, l_Mana, l_Alignment, l_SkinID, l_SizeX, l_SizeY, l_MapID, l_Pos.x, l_Pos.y, (Orientation)l_Orientation);
else if (l_TypeID == (uint8)TypeUnit::CREATURE)
l_NewUnit = new Creature(l_ID, l_Name, l_Level, l_Health, l_SkinID, l_SizeX, l_SizeY, l_MapID, l_Pos.x, l_Pos.y, (Orientation)l_Orientation);
else if (l_TypeID == (uint8)TypeUnit::ANIMATIONUNIT)
l_NewUnit = new AnimationUnit(l_ID, l_Name, l_Level, l_Health, l_SkinID, l_SizeX, l_SizeY, l_MapID, l_Pos.x, l_Pos.y, (Orientation)l_Orientation);
else if (l_TypeID == (uint8)TypeUnit::AREATRIGGER || l_TypeID == (uint8)TypeUnit::GAMEOBJECT)
{
/* DynamicObject* l_DynIbj*/l_NewUnit = new DynamicObject(l_ID, (TypeUnit)l_TypeID, l_Name, l_Level, l_Health, l_SkinID, l_SizeX, l_SizeY, l_MapID, l_Pos.x, l_Pos.y, (Orientation)l_Orientation, l_IsBlocking);
VisualEffect l_VisualEffect(eVisualType::VisualGob, false, l_SkinID, 3);
l_VisualEffect.StartAnim();
l_NewUnit->AddVisualEffect(l_NewUnit->GetType(), l_NewUnit->GetID(), l_VisualEffect);
l_ActualMap->GetCase(l_Pos.x, l_Pos.y)->AddDynamicOject(l_NewUnit->ToDynamicObject());
}
float l_SpeedFloat = (float)l_Speed / 10.0f;
l_NewUnit->SetSpeed(l_SpeedFloat);
l_NewUnit->SetMap(l_ActualMap);
l_ActualMap->AddUnit(l_NewUnit);
printf("Create new Unit DONE: %d %s %d %d %d %d\n", l_ID, l_Name.c_str(), l_SkinID, l_MapID, l_Pos.x, l_Pos.y);
if (l_IsInMovement)
l_NewUnit->GetMovementHandler()->AddMovementToStack(eActionType::Go, l_Pos, (Orientation)l_NewUnit->GetOrientation());
if (l_IsInAttack)
l_NewUnit->GetMovementHandler()->AddMovementToStack(eActionType::Attack, l_Pos, (Orientation)l_NewUnit->GetOrientation());
l_NewUnit->SetIsInGroup(l_IsInGroup);
}
}
void PacketHandler::OperatePacket(WorldPacket &p_Packet)
{
uint8 l_PacketID;
p_Packet >> l_PacketID;
printf("Receive Packet %d\n", l_PacketID);
m_Func l_Fun = m_PacketHandleMap[l_PacketID];
if (l_Fun != nullptr)
(this->*(l_Fun))(p_Packet);
else
printf("Packet %d Unknow\n", l_PacketID);
}
bool PacketHandler::HasMinimalRequiered() const
{
return p_HasMinimalRequiered;
}
void PacketHandler::HandleUpdateSkin(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_ID;
int16 l_Skin;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
p_Packet >> l_Skin;
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_ID);
if (l_Unit == nullptr)
{
g_Socket->SendUnitUnknow(l_TypeID, l_ID); ///< Ask for unknow unit to server
return;
}
l_Unit->SetSkinID(l_Skin);
}
}
void PacketHandler::HandleSwitchMap(WorldPacket &p_Packet)
{
uint16 l_MapID;
std::string l_MapFileName;
std::string l_MapChipsetName;
std::string l_MapName;
p_Packet >> l_MapID;
p_Packet >> l_MapFileName;
p_Packet >> l_MapChipsetName;
p_Packet >> l_MapName;
delete m_MapManager->GetActualMap();
m_InterfaceManager->SetIsLoading(true);
if (!m_MapManager->LoadMap(l_MapID, l_MapFileName, l_MapChipsetName, l_MapName))
return;
if (Map* l_ActualMap = m_MapManager->GetActualMap())
{
g_Player->GetMovementHandler()->StopMovement();
g_Player->GetMovementHandler()->StopAttack();
g_Player->SetMap(l_ActualMap);
l_ActualMap->AddUnit(g_Player);
}
}
void PacketHandler::HandleSrvPlayerMsg(WorldPacket &p_Packet)
{
std::string l_Msg;
CharOn44 l_StructData;
p_Packet >> l_StructData.m_Byte_value;
p_Packet >> l_Msg;
SWText l_Text(l_Msg, (eTextColor)l_StructData.charOn44.first, (eTextStyle)l_StructData.charOn44.second);
m_InterfaceManager->GetHistoryField()->OpenTemporary(5000);
m_InterfaceManager->GetHistoryField()->AddHistoryLine(l_Text);
}
void PacketHandler::HandleSrvPlayerQuestion(WorldPacket &p_Packet)
{
uint16 l_QuestionID;
std::string l_Msg;
p_Packet >> l_QuestionID;
p_Packet >> l_Msg;
printf("I--> Question %d:%s\n", l_QuestionID, l_Msg.c_str());
m_InterfaceManager->AddSimpleQuestion(l_QuestionID, l_Msg);
}
void PacketHandler::HandleLogDamage(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_ID;
sf::Int8 l_Damage;
uint8 l_DamageResult;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
p_Packet >> l_Damage;
p_Packet >> l_DamageResult;
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_ID);
if (l_Unit == nullptr)
{
g_Socket->SendUnitUnknow(l_TypeID, l_ID); ///< Ask for unknow unit to server
return;
}
l_Unit->AddDamageLog(DamageInfo(l_Damage, (DamageResult)l_DamageResult));
}
}
void PacketHandler::HandleWarningMsg(WorldPacket &p_Packet)
{
uint8 l_Type;
std::string l_WarningMsg;
p_Packet >> l_Type;
p_Packet >> l_WarningMsg;
m_InterfaceManager->AddWarningMsg((eTypeWarningMsg)l_Type, l_WarningMsg);
}
void PacketHandler::HandleUnitPlayVisual(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_ID;
bool l_Under;
uint8 l_VisualID;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
p_Packet >> l_Under;
p_Packet >> l_VisualID;
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_ID);
if (l_Unit == nullptr)
{
g_Socket->SendUnitUnknow(l_TypeID, l_ID); ///< Ask for unknow unit to server
return;
}
VisualEffect l_VisualEffect(eVisualType::VisualSpell, l_Under, l_VisualID, MAX_VISUAL_IMG_X);
l_VisualEffect.StartAnimAndStop();
l_Unit->AddVisualEffect(l_Unit->GetType(), l_Unit->GetID(), l_VisualEffect);
}
}
void PacketHandler::HandleUnitPlayVisualAura(WorldPacket &p_Packet)
{
bool l_Apply = false;
uint8 l_TypeID;
uint16 l_ID;
uint8 l_TypeIDFrom;
uint16 l_IDFrom;
bool l_Under;
uint8 l_VisualID;
CharOn116 l_Struct;
//p_Packet >> l_Apply;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
p_Packet >> l_TypeIDFrom;
p_Packet >> l_IDFrom;
p_Packet >> l_Struct.m_Byte_value;
//p_Packet >> l_Under;
//p_Packet >> l_VisualID;
l_Apply = l_Struct.charOn116.first ? true : false;
l_Under = l_Struct.charOn116.second ? true : false;
l_VisualID = l_Struct.charOn116.third;
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_ID);
if (l_Unit == nullptr)
{
g_Socket->SendUnitUnknow(l_TypeID, l_ID); ///< Ask for unknow unit to server
return;
}
if (l_Apply)
{
VisualEffect l_VisualEffect(eVisualType::VisualSpell, l_Under, l_VisualID, MAX_VISUAL_IMG_X);
l_VisualEffect.StartAnim();
l_Unit->AddVisualEffect((TypeUnit)l_TypeIDFrom, l_IDFrom, l_VisualEffect);
}
else
{
l_Unit->RemoveVisualEffect((TypeUnit)l_TypeIDFrom, l_IDFrom, l_VisualID);
}
}
}
void PacketHandler::HandleUpdateStat(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_ID;
uint8 l_TypeStat;
uint16 l_StatNb;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
p_Packet >> l_TypeStat;
p_Packet >> l_StatNb;
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_ID);
if (l_Unit == nullptr)
{
g_Socket->SendUnitUnknow(l_TypeID, l_ID); ///< Ask for unknow unit to server
return;
}
if (l_TypeStat == eStats::Speed)
{
float l_SpeedFloat = (float)l_StatNb / 10.0f;
l_Unit->SetSpeed(l_SpeedFloat);
}
else
{
MenuManager* l_MenuManager = m_InterfaceManager->GetMenuManager();
if (l_MenuManager == nullptr)
return;
if (l_TypeStat == eStats::Level)
{
l_MenuManager->AddElementToMenu(eMenuType::StatsMenu, 1, 1, std::to_string(l_StatNb));
return;
}
l_MenuManager->AddElementToMenu(eMenuType::StatsMenu, 1, l_TypeStat + 2, std::to_string(l_StatNb));
}
}
}
void PacketHandler::HandleKeyBoardBind(WorldPacket &p_Packet)
{
uint8 l_Nb;
p_Packet >> l_Nb;
for (uint8 i = 0; i < l_Nb; i++)
{
uint8 l_TypeAction;
uint8 l_Key;
p_Packet >> l_TypeAction;
p_Packet >> l_Key;
m_InterfaceManager->AddKeyBind(l_Key, l_TypeAction);
}
}
void PacketHandler::HandleKeyBindBlock(WorldPacket &p_Packet)
{
uint8 l_TypeAction;
uint16 l_Time;
p_Packet >> l_TypeAction;
p_Packet >> l_Time;
m_InterfaceManager->AddBlockingBind(l_TypeAction, l_Time);
}
void PacketHandler::HandleUnitIsInGroup(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_ID;
bool l_IsInGroup;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
p_Packet >> l_IsInGroup;
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_ID);
if (l_Unit == nullptr)
{
g_Socket->SendUnitUnknow(l_TypeID, l_ID); ///< Ask for unknow unit to server
return;
}
l_Unit->SetIsInGroup(l_IsInGroup);
}
}
void PacketHandler::HandleCastBar(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_ID;
uint8 l_Time;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
p_Packet >> l_Time;
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_ID);
if (l_Unit == nullptr)
{
g_Socket->SendUnitUnknow(l_TypeID, l_ID); ///< Ask for unknow unit to server
return;
}
l_Unit->LaunchCastBar((uint16)l_Time * 100);
}
}
void PacketHandler::HandlePlayerTitle(WorldPacket &p_Packet)
{
uint8 l_Nb;
MenuManager* l_MenuManager = m_InterfaceManager->GetMenuManager();
MenuTitles* l_MenuTitles = reinterpret_cast<MenuTitles*>(l_MenuManager->GetMenu(eMenuType::TitlesMenu));
if (l_MenuTitles == nullptr)
return;
p_Packet >> l_Nb;
for (uint8 i = 0; i < l_Nb; i++)
{
uint16 l_ID;
std::string l_Name;
p_Packet >> l_ID;
p_Packet >> l_Name;
l_MenuTitles->AddTitle(l_ID, l_Name);
}
}
void PacketHandler::HandlePlayerSkin(WorldPacket &p_Packet)
{
uint8 l_Nb;
MenuManager* l_MenuManager = m_InterfaceManager->GetMenuManager();
MenuWardrobe* l_MenuWardRobe = reinterpret_cast<MenuWardrobe*>(l_MenuManager->GetMenu(eMenuType::WardrobeMenu));
if (l_MenuWardRobe == nullptr)
return;
p_Packet >> l_Nb;
for (uint8 i = 0; i < l_Nb; i++)
{
uint16 l_ID;
std::string l_Name;
p_Packet >> l_ID;
p_Packet >> l_Name;
l_MenuWardRobe->AddSkin(l_ID, l_Name);
}
}
void PacketHandler::HandlePlayerRemoveItem(WorldPacket &p_Packet)
{
uint8 l_SlotID;
MenuManager* l_MenuManager = m_InterfaceManager->GetMenuManager();
MenuBag* l_MenuBag = reinterpret_cast<MenuBag*>(l_MenuManager->GetMenu(eMenuType::BagMenu));
if (l_MenuBag == nullptr)
return;
MenuSell* l_MenuSell = reinterpret_cast<MenuSell*>(m_InterfaceManager->GetMenuInterface(eMenuType::SellMenu));
if (l_MenuSell == nullptr)
return;
p_Packet >> l_SlotID;
l_MenuBag->RemoveItem(l_SlotID);
l_MenuSell->RemoveItem(l_SlotID);
}
void PacketHandler::HandlePlayerUpdateCurrency(WorldPacket &p_Packet)
{
uint8 l_Nb;
MenuManager* l_MenuManager = m_InterfaceManager->GetMenuManager();
MenuBag* l_MenuBag = reinterpret_cast<MenuBag*>(l_MenuManager->GetMenu(eMenuType::BagMenu));
if (l_MenuBag == nullptr)
return;
MenuSell* l_MenuSell = reinterpret_cast<MenuSell*>(m_InterfaceManager->GetMenuInterface(eMenuType::SellMenu));
if (l_MenuSell == nullptr)
return;
printf("Set Currency\n");
p_Packet >> l_Nb;
for (uint8 i = 0; i < l_Nb; i++)
{
uint8 l_Type;
uint16 l_Value;
p_Packet >> l_Type;
p_Packet >> l_Value;
l_MenuBag->SetCurrency((eTypeCurrency)l_Type, l_Value);
l_MenuSell->SetCurrency((eTypeCurrency)l_Type, l_Value);
}
}
void PacketHandler::HandlePlayerStackItem(WorldPacket &p_Packet)
{
uint8 l_SlotID;
uint8 l_Stack;
MenuManager* l_MenuManager = m_InterfaceManager->GetMenuManager();
MenuBag* l_MenuBag = reinterpret_cast<MenuBag*>(l_MenuManager->GetMenu(eMenuType::BagMenu));
if (l_MenuBag == nullptr)
return;
MenuSell* l_MenuSell = reinterpret_cast<MenuSell*>(m_InterfaceManager->GetMenuInterface(eMenuType::SellMenu));
if (l_MenuSell == nullptr)
return;
p_Packet >> l_SlotID;
p_Packet >> l_Stack;
l_MenuBag->SetStackItem(l_SlotID, l_Stack);
l_MenuSell->SetStackItem(l_SlotID, l_Stack);
}
void PacketHandler::HandlePlayerRemoveEquipment(WorldPacket &p_Packet)
{
uint8 l_SlotID;
MenuManager* l_MenuManager = m_InterfaceManager->GetMenuManager();
MenuEquipment* l_MenuEquipment = reinterpret_cast<MenuEquipment*>(l_MenuManager->GetMenu(eMenuType::EquipmentMenu));
if (l_MenuEquipment == nullptr)
return;
p_Packet >> l_SlotID;
l_MenuEquipment->RemoveEquipment((eTypeEquipment)l_SlotID);
}
void PacketHandler::HandlePlayerBagSize(WorldPacket &p_Packet)
{
uint8 l_Size;
MenuManager* l_MenuManager = m_InterfaceManager->GetMenuManager();
MenuBag* l_MenuBag = reinterpret_cast<MenuBag*>(l_MenuManager->GetMenu(eMenuType::BagMenu));
if (l_MenuBag == nullptr)
return;
MenuSell* l_MenuSell = reinterpret_cast<MenuSell*>(m_InterfaceManager->GetMenuInterface(eMenuType::SellMenu));
if (l_MenuSell == nullptr)
return;
p_Packet >> l_Size;
l_MenuManager->GetElement(0, 4)->SetLabel(l_MenuManager->GetElement(0, 4)->GetLabel() + " x" + std::to_string(l_Size));
l_MenuBag->SetSize(l_Size);
l_MenuSell->SetSize(l_Size);
}
void PacketHandler::HandleBindingSpell(WorldPacket &p_Packet)
{
uint8 l_Nb;
p_Packet >> l_Nb;
uint8 l_Bind = 0;
uint16 l_SpellID = 0;
for (uint8 i = 0; i < l_Nb; i++)
{
p_Packet >> l_Bind;
p_Packet >> l_SpellID;
m_InterfaceManager->AddSpellBind(l_Bind, l_SpellID);
}
}
void PacketHandler::HandleSellItemInterface(WorldPacket &p_Packet)
{
uint8 l_Nb;
MenuManager* l_MenuManager = m_InterfaceManager->GetMenuManager();
MenuSell* l_MenuSell = reinterpret_cast<MenuSell*>(m_InterfaceManager->GetMenuInterface(eMenuType::SellMenu));
if (l_MenuSell == nullptr)
return;
p_Packet >> l_Nb;
uint8 l_SlotID = 0;
uint16 l_Price = 0;
for (uint8 i = 0; i < l_Nb; i++)
{
p_Packet >> l_SlotID;
p_Packet >> l_Price;
l_MenuSell->AddItemPrice(l_SlotID, l_Price);
}
l_MenuSell->Open();
}
void PacketHandler::HandlePlayerItem(WorldPacket &p_Packet)
{
uint8 l_Nb;
MenuManager* l_MenuManager = m_InterfaceManager->GetMenuManager();
MenuBag* l_MenuBag = reinterpret_cast<MenuBag*>(l_MenuManager->GetMenu(eMenuType::BagMenu));
if (l_MenuBag == nullptr)
return;
MenuSell* l_MenuSell = reinterpret_cast<MenuSell*>(m_InterfaceManager->GetMenuInterface(eMenuType::SellMenu));
if (l_MenuSell == nullptr)
return;
p_Packet >> l_Nb;
uint8 l_SlotID;
std::string l_Name;
uint8 l_StackNb;
uint8 l_TypeID;
uint8 l_SubType;
uint8 l_Level;
uint8 l_RareLevel;
int32 l_Data;
for (uint8 i = 0; i < l_Nb; i++)
{
p_Packet >> l_SlotID;
p_Packet >> l_Name;
p_Packet >> l_StackNb;
p_Packet >> l_TypeID;
p_Packet >> l_SubType;
p_Packet >> l_Level;
p_Packet >> l_RareLevel;
Item l_Item((eItemType)l_TypeID, l_SubType, l_Name, (eItemRareLevel)l_RareLevel, l_Level, l_StackNb);
for (uint8 j = 0; j < 4; j++)
{
p_Packet >> l_Data;
l_Item.AddData(l_Data);
}
l_MenuBag->AddItem(l_SlotID, l_Item);
l_MenuSell->AddItem(l_SlotID, l_Item);
printf("Get Item on slot %d : %s\n", l_SlotID, l_Name.c_str());
}
}
void PacketHandler::HandlePlayerEquipment(WorldPacket &p_Packet)
{
uint8 l_Nb;
MenuManager* l_MenuManager = m_InterfaceManager->GetMenuManager();
MenuEquipment* l_MenuEquipment = reinterpret_cast<MenuEquipment*>(l_MenuManager->GetMenu(eMenuType::EquipmentMenu));
if (l_MenuEquipment == nullptr)
return;
p_Packet >> l_Nb;
uint8 l_TypeID;
std::string l_Name;
uint8 l_Level;
uint8 l_RareLevel;
int32 l_Data;
for (uint8 i = 0; i < l_Nb; i++)
{
p_Packet >> l_TypeID;
p_Packet >> l_Name;
p_Packet >> l_Level;
p_Packet >> l_RareLevel;
Item l_Item(eItemType::ITEM_EQUIPMENT, l_TypeID, l_Name, (eItemRareLevel)l_RareLevel, l_Level, 1);
for (uint8 j = 0; j < 4; j++)
{
p_Packet >> l_Data;
l_Item.AddData(l_Data);
}
l_MenuEquipment->AddEquipment((eTypeEquipment)l_TypeID, l_Item);
printf("Get Equipement on placement %d : %s\n", l_TypeID, l_Name.c_str());
}
}
void PacketHandler::HandlePlayerSpell(WorldPacket &p_Packet)
{
uint8 l_Nb;
MenuManager* l_MenuManager = m_InterfaceManager->GetMenuManager();
MenuSpells* l_MenuSpells = reinterpret_cast<MenuSpells*>(l_MenuManager->GetMenu(eMenuType::SpellsMenu));
if (l_MenuSpells == nullptr)
return;
p_Packet >> l_Nb;
for (uint8 i = 0; i < l_Nb; i++)
{
uint16 l_ID;
std::string l_Name;
p_Packet >> l_ID;
p_Packet >> l_Name;
l_MenuSpells->AddSpell(l_ID, l_Name);
}
}
void PacketHandler::HanleUnitUpdateName(WorldPacket &p_Packet)
{
uint8 l_TypeID;
uint16 l_ID;
std::string l_Name;
p_Packet >> l_TypeID;
p_Packet >> l_ID;
p_Packet >> l_Name;
if (Map* l_Map = m_MapManager->GetActualMap())
{
Unit* l_Unit = l_Map->GetUnit((TypeUnit)l_TypeID, l_ID);
if (l_Unit == nullptr)
{
g_Socket->SendUnitUnknow(l_TypeID, l_ID); ///< Ask for unknow unit to server
return;
}
l_Unit->SetName(l_Name);
}
}
void PacketHandler::HandleLoadingPing(WorldPacket &p_Packet)
{
g_Socket->SendLoadingPong();
}
| 29.120513
| 219
| 0.666931
|
pinkmouse
|
954d378192a469c8a9500f1780f63d17bd129257
| 8,641
|
cpp
|
C++
|
OilSpillage/Inventory/ItemWeapon.cpp
|
Xemrion/Exam-work
|
7243f8db9951a0cdaebcfb5804df737a4d795b10
|
[
"Apache-2.0"
] | 3
|
2020-04-25T22:23:07.000Z
|
2022-03-03T17:44:00.000Z
|
OilSpillage/Inventory/ItemWeapon.cpp
|
Xemrion/Exam-work
|
7243f8db9951a0cdaebcfb5804df737a4d795b10
|
[
"Apache-2.0"
] | null | null | null |
OilSpillage/Inventory/ItemWeapon.cpp
|
Xemrion/Exam-work
|
7243f8db9951a0cdaebcfb5804df737a4d795b10
|
[
"Apache-2.0"
] | null | null | null |
#include "ItemWeapon.h"
#include <sstream>
#include "../game.h"
#include <iomanip>
std::string ItemWeapon::generateDescription(Weapon weapon)
{
std::stringstream stream;
stream << std::boolalpha;
if (weapon.type == WeaponType::MachineGun) {
stream << "Damage/S: " << Item::fixedDecimals(weapon.damage / weapon.fireRate, 2) << "\n";
stream << "Fire Rate: " << Item::fixedDecimals(weapon.fireRate, 2) << "\n";
stream << "Bullet Speed: " << Item::fixedDecimals(weapon.bulletSpeed, 2) << "\n";
stream << "Max Spread: " << Item::fixedDecimals(weapon.maxSpread, 2) << "\n";
}
else if(weapon.type == WeaponType::Laser){
stream << "Damage/S: " << Item::fixedDecimals(weapon.damage, 2) << "\n";
stream << "Overheat : " << Item::fixedDecimals(weapon.maxSpread, 2) << "\n";
}
else if(weapon.type == WeaponType::Flamethrower) {
stream << "Damage/S: " << Item::fixedDecimals(weapon.damage / weapon.fireRate, 2) << "\n";
stream << "Fire Rate: " << Item::fixedDecimals(weapon.fireRate, 2) << "\n";
stream << "Bullet Speed: " << Item::fixedDecimals(weapon.bulletSpeed, 2) << "\n";
stream << "Max Spread: " << Item::fixedDecimals(weapon.maxSpread, 2) << "\n";
}
else if(weapon.type == WeaponType::Spikes){
stream << "Damage/S: " << Item::fixedDecimals(weapon.damage, 2) << "\n";
}
else {
stream << "Damage/S: " << Item::fixedDecimals(weapon.damage / weapon.fireRate, 2) << "\n";
stream << "Fire Rate: " << Item::fixedDecimals(weapon.fireRate, 2) << "\n";
stream << "Bullet Speed: " << Item::fixedDecimals(weapon.bulletSpeed, 2) << "\n";
stream << "Max Spread: " << Item::fixedDecimals(weapon.maxSpread, 2) << "\n";
}
if (weapon.doesDoT)
{
stream << "DoT duration: " << Item::fixedDecimals(weapon.doTTimer, 2) << "\n";
}
if (weapon.doesKnockBack)
{
stream << "Knockback force: " << Item::fixedDecimals(weapon.knockbackForce, 2) << "\n";
}
if (weapon.doesSplashDmg)
{
stream << "Splash damage range: " << Item::fixedDecimals(weapon.splashRange, 2) << "\n";
}
return stream.str();
}
ItemWeapon::ItemWeapon(std::string name, Weapon weapon, GameObject * object) : Item(name, generateDescription(weapon), ItemType::TYPE_WEAPON, object), weapon(weapon)
{
}
ItemWeapon::~ItemWeapon()
{
}
ItemWeapon::ItemWeapon(const ItemWeapon& obj) : Item(obj)
{
this->weapon = obj.weapon;
}
Item* ItemWeapon::clone() const
{
return new ItemWeapon(*this);
}
void ItemWeapon::randomize()
{
//damage
//fireRate
//bulletSpeed
//bulletLifetime
//spreadRadians
//maxSpread
//spreadIncreasePerSecond
//spreadDecreasePerSecond
if (weapon.type == WeaponType::MachineGun)
{
this->weapon.damage = static_cast<int>(this->weapon.damage * (((rand() % 400) *0.01f) + (1 * Game::getLocalScale())));
this->weapon.bulletSpeed = this->weapon.bulletSpeed * (((rand() % 101) * 0.01f) + 1);
this->weapon.bulletLifetime = this->weapon.bulletLifetime * (((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale()));
this->weapon.spreadRadians = this->weapon.spreadRadians + ((rand() % 101) *0.01f)*0.52f;//30 degree = 0.52 radians
this->weapon.maxSpread = this->weapon.maxSpread + ((rand() % 101) * 0.01f+1.0f) * this->weapon.spreadRadians;
this->weapon.spreadIncreasePerSecond = this->weapon.spreadIncreasePerSecond * (((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale()));
this->weapon.spreadDecreasePerSecond = this->weapon.spreadDecreasePerSecond * (((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale()));
int chance = (rand() % 100) + 1;
if(chance <= 10)
{
weapon.doesDoT = true;
weapon.doTTimer = 2;
}
else if(chance > 10 && chance <= 20)
{
weapon.doesKnockBack = true;
weapon.knockbackForce = 2;
}
else if (chance > 20 && chance <= 30)
{
weapon.doesSplashDmg = true;
weapon.splashRange = 20;
}
}
else if (weapon.type == WeaponType::Laser)
{
this->weapon.damage = static_cast<int>(this->weapon.damage * (((rand() % 201+400) * 0.01f) + (1 * Game::getLocalScale())));
this->weapon.bulletSpeed = this->weapon.bulletSpeed * 1;
this->weapon.bulletLifetime = this->weapon.bulletLifetime * 1;
this->weapon.spreadRadians = this->weapon.spreadRadians * (((rand() % 101) * 0.01f) + (1 * Game::getLocalScale()));
this->weapon.maxSpread = this->weapon.maxSpread * (((rand() % 101) * 0.01f) + (1 * Game::getLocalScale()));
this->weapon.spreadIncreasePerSecond = this->weapon.spreadIncreasePerSecond * 1/*(((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale()))*/;
this->weapon.spreadDecreasePerSecond = this->weapon.spreadDecreasePerSecond *1 /*(((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale()))*/;
int chance = (rand() % 100) + 1;
if (chance <= 10)
{
weapon.doesDoT = true;
weapon.doTTimer = 2;
}
else if (chance > 10 && chance <= 20)
{
weapon.doesKnockBack = true;
weapon.knockbackForce = 2;
}
else if (chance > 20 && chance <= 30)
{
weapon.doesSplashDmg = true;
weapon.splashRange = 20;
}
}
else if (weapon.type == WeaponType::Flamethrower)
{
this->weapon.damage = static_cast<int>(this->weapon.damage * (((rand() % 50) * 0.01f) + (1 * Game::getLocalScale())));
this->weapon.bulletSpeed = this->weapon.bulletSpeed;// *(((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale()));
this->weapon.bulletLifetime = this->weapon.bulletLifetime * (((rand() % 50)*0.01f) + (1 * Game::getLocalScale()));
this->weapon.spreadRadians = this->weapon.spreadRadians + ((rand() % 101) * 0.01f) * 0.52f;//30 degree = 0.52 radians
this->weapon.maxSpread = this->weapon.maxSpread + ((rand() % 101) * 0.01f + 1.0f) * this->weapon.spreadRadians;
this->weapon.spreadIncreasePerSecond = this->weapon.spreadIncreasePerSecond * (((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale()));
this->weapon.spreadDecreasePerSecond = this->weapon.spreadDecreasePerSecond * (((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale()));
int chance = (rand() % 100) + 1;
if (chance > 10 && chance <= 20)
{
weapon.doesKnockBack = true;
weapon.knockbackForce = 2;
}
else if (chance > 20 && chance <= 30)
{
weapon.doesSplashDmg = true;
weapon.splashRange = 20;
}
}
else if (weapon.type == WeaponType::Spikes)
{
this->weapon.damage = static_cast<int>(this->weapon.damage * (((rand() % 500 + 200) * 0.01f) + (1 * Game::getLocalScale())));
int chance = (rand() % 100) + 1;
if (chance <= 10)
{
weapon.doesDoT = true;
weapon.doTTimer = 2;
}
else if (chance > 10 && chance <= 20)
{
weapon.doesKnockBack = true;
weapon.knockbackForce = 2;
}
else if (chance > 20 && chance <= 30)
{
weapon.doesSplashDmg = true;
weapon.splashRange = 20;
}
/*this->weapon.bulletSpeed = this->weapon.bulletSpeed * (((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale()));
this->weapon.bulletLifetime = this->weapon.bulletLifetime * (((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale()));
this->weapon.spreadRadians = this->weapon.spreadRadians * (((rand() % 1000 + 1) / 100) + (1));
this->weapon.maxSpread = this->weapon.maxSpread * (((rand() % 1000 + 1) / 100) + (1));
this->weapon.spreadIncreasePerSecond = this->weapon.spreadIncreasePerSecond * (((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale()));
this->weapon.spreadDecreasePerSecond = this->weapon.spreadDecreasePerSecond * (((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale()));*/
}
else
{
this->weapon.damage = static_cast<int>(this->weapon.damage * (((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale())));
this->weapon.bulletSpeed = this->weapon.bulletSpeed * (((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale()));
this->weapon.bulletLifetime = this->weapon.bulletLifetime * (((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale()));
this->weapon.spreadRadians = this->weapon.spreadRadians * (((rand() % 1000 + 1) / 100) + (1));
this->weapon.maxSpread = this->weapon.maxSpread * (((rand() % 1000 + 1) / 100) + (1));
this->weapon.spreadIncreasePerSecond = this->weapon.spreadIncreasePerSecond * (((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale()));
this->weapon.spreadDecreasePerSecond = this->weapon.spreadDecreasePerSecond * (((rand() % 1000 + 1) / 100) + (1 * Game::getLocalScale()));
}
this->description = generateDescription(this->weapon);
if (this->weapon.type == WeaponType::Laser)
{
this->weapon.lightColor = Vector3(rand(), rand(), rand());
this->weapon.lightColor /= max(max(this->weapon.lightColor.x, this->weapon.lightColor.y), this->weapon.lightColor.z);
}
Item::randomize();
}
Weapon& ItemWeapon::getWeapon()
{
return this->weapon;
}
void ItemWeapon::update(float dt)
{
if (weapon.type == WeaponType::Spikes)
{
}
}
| 40.00463
| 165
| 0.638468
|
Xemrion
|
954d7a7c4806750968c1a8abfdf30247a06d1145
| 6,039
|
hpp
|
C++
|
include/SimpleBuffer.hpp
|
cosama/zed-context-driver
|
3459c76599a2175a7af3c1986b79da9f3222d135
|
[
"BSD-3-Clause-LBNL"
] | null | null | null |
include/SimpleBuffer.hpp
|
cosama/zed-context-driver
|
3459c76599a2175a7af3c1986b79da9f3222d135
|
[
"BSD-3-Clause-LBNL"
] | null | null | null |
include/SimpleBuffer.hpp
|
cosama/zed-context-driver
|
3459c76599a2175a7af3c1986b79da9f3222d135
|
[
"BSD-3-Clause-LBNL"
] | null | null | null |
/***********************************************************************************
* Header file that defines the SimpleBuffer class, a simpler way to use shared
* SharedBuffers,
*
* Author: Marco Salathe <msalathe@lbl.gov>
* Date: Mai 2018
* License: See License.txt in parent folder of this repository.
*
**********************************************************************************/
#ifndef SIMPLEBUFFER_HPP
#define SIMPLEBUFFER_HPP
#include "SharedBuffer.hpp"
#include "MsgDefinition.hpp"
#include <chrono>
#include <thread>
#include <iostream>
template <class T> class SimpleBuffer: public SharedBuffer<T>
{
private:
std::vector<T> buffer;
typename std::vector<T>::iterator iter;
public:
SimpleBuffer<T>(): SharedBuffer<T>() { iter = buffer.end(); };
SimpleBuffer(std::string bname, int bsize = 65536): SharedBuffer<T>(bname, bsize) { iter = buffer.end(); };
//A function that can be used to read a fixed sized structure/class (return) from the buffer, ms_sleep indicates
//how many milliseconds it should sleep if the buffer is empty before trying to grab a gain and timeout is the time in
//milliseconds after that it returns NULL. If timeout is 0 then it waits indefinitely. 'number' tells the function how
//many elements it should try to grab maximally (it is better to grab multiple, as the remaining images might get cleared
//from the buffer any time). If 'number' is 0 then it grabs all available data (if the buffer is large this might cause a
//memory error).
T* read_simple(int number, int ms_sleep, int timeout)
{
int cnt=0;
if(iter==buffer.end()){ SharedBuffer<T>::lock(); buffer.clear(); iter=SharedBuffer<T>::read(buffer, number); }
while(iter==buffer.end() && (timeout==0 || cnt*ms_sleep<timeout))
{
SharedBuffer<T>::unlock();
std::this_thread::sleep_for(std::chrono::milliseconds(ms_sleep));
SharedBuffer<T>::lock();
iter=SharedBuffer<T>::read(buffer, number);
cnt++;
}
SharedBuffer<T>::unlock();
if(iter==buffer.end()){ return nullptr; }
T *hdr=(T*)&*iter; //create a pointer to the header of the image (first image block)
iter++; //move the iterator to the begining of the image data
return hdr;
};
//A function that can be used to write a fixed sized structure/class 'data' to the buffer.
//'max_data' defines the maximum number of images that are stored in the buffer. Once the buffer
//exceeds that number it will be resized to that size.
int write_simple(T &data, int max_data)
{
SharedBuffer<T>::lock();
int buf_size = SharedBuffer<T>::write(data);
while(max_data>0 && buf_size>max_data)
{
SharedBuffer<T>::resize(max_data);
buf_size = SharedBuffer<T>::size();
}
SharedBuffer<T>::unlock();
return buf_size;
};
};
//A function that can be used to write a image 'hdr' to the buffer. The hdr.data
//needs to point to the memory block (continous) where the image data are stored. 'max_img'
//defines the maximum number of images that are stored in the buffer. Once the buffer exceeds
//that number it will be resized to that size.
template<> ImageHeaderMsg* SimpleBuffer<ImageHeaderMsg>::read_simple(int number, int ms_sleep, int timeout)
{
ImageHeaderMsg* hdr;
int cnt=0;
if(iter==buffer.end()){ SharedBuffer<ImageHeaderMsg>::lock(); buffer.clear(); iter=SharedBuffer<ImageHeaderMsg>::read(buffer, (number?1:0)); }
while(iter==buffer.end() && (timeout==0 || cnt*ms_sleep<timeout))
{
SharedBuffer<ImageHeaderMsg>::unlock();
std::this_thread::sleep_for(std::chrono::milliseconds(ms_sleep));
SharedBuffer<ImageHeaderMsg>::lock();
iter=SharedBuffer<ImageHeaderMsg>::read(buffer, (number?1:0));
cnt++;
}
if(iter==buffer.end()){ SharedBuffer<ImageHeaderMsg>::unlock(); return nullptr; }
hdr=(ImageHeaderMsg*)&*iter; //create a pointer to the header of the image (first image block)
iter++; //move the iterator to the begining of the image data
if(iter==buffer.end())
{
iter=SharedBuffer<ImageHeaderMsg>::read(buffer, ((number>0)?(number*(hdr->block_nmb+1)-1):0));
hdr=(ImageHeaderMsg*)&*(iter-1); //previous stuff might reallocate vector thus we have to link it again
}
SharedBuffer<ImageHeaderMsg>::unlock(); //we always unlock, if already unlocked nothing really will happen
hdr->data=(void*)&*iter;
iter+=hdr->block_nmb;
return hdr;
};
//A function that can be used to write a image 'hdr' to the buffer. The hdr.data
//needs to point to the memory block (continous) where the image data are stored. 'max_img'
//defines the maximum number of images that are stored in the buffer. Once the buffer exceeds
//that number it will be resized to that size.
template<> int SimpleBuffer<ImageHeaderMsg>::write_simple(ImageHeaderMsg &hdr, int max_img)
{
ImageHeaderMsg* img_ptr= (ImageHeaderMsg*)hdr.data;
int img_len=hdr.block_nmb;
if(!hdr.data) img_len=0;
SharedBuffer<ImageHeaderMsg>::lock(); //we need the lock anyways, this way nobody can access the buffer before the resize
int buf_size = SharedBuffer<ImageHeaderMsg>::write({ &hdr, &hdr+1, img_ptr, img_ptr+img_len });
int cur_img = get_user_info();
if(buf_size == 0) cur_img = 0; else if(buf_size == img_len+1) cur_img = 1; else cur_img++;
while(max_img>0 && cur_img>max_img)
{
std::vector <ImageHeaderMsg> buf_tmp;
SharedBuffer<ImageHeaderMsg>::read(buf_tmp, 1);
if(buf_tmp.size()==1)
{
ImageHeaderMsg* hdr_tmp = (ImageHeaderMsg*)&buf_tmp.front();
SharedBuffer<ImageHeaderMsg>::resize(buf_size-(hdr_tmp->block_nmb+1)); //internally makes sure we don't pass zero
cur_img--;
}
buf_size = SharedBuffer<ImageHeaderMsg>::size();
if(buf_size == 0) cur_img = 0;
}
set_user_info(cur_img);
SharedBuffer<ImageHeaderMsg>::unlock();
return cur_img;
};
#endif //#ifndef SIMPLEBUFFER_HPP
| 44.080292
| 144
| 0.664348
|
cosama
|
95537f37a62c7779178ea7066163603847a27aa3
| 1,189
|
cxx
|
C++
|
src/CData.cxx
|
DieSkaarj/Conways-GameOfLife
|
12fc27cb747027c5379da5be7d222c7326eeee08
|
[
"CC0-1.0"
] | null | null | null |
src/CData.cxx
|
DieSkaarj/Conways-GameOfLife
|
12fc27cb747027c5379da5be7d222c7326eeee08
|
[
"CC0-1.0"
] | null | null | null |
src/CData.cxx
|
DieSkaarj/Conways-GameOfLife
|
12fc27cb747027c5379da5be7d222c7326eeee08
|
[
"CC0-1.0"
] | null | null | null |
#include "CData.h"
#include "CGame.h"
#include "NUtil.h"
#include "CCluster.h"
void CData::draw(WINDOW* t_window){
auto cleanLineBetweenBorder=[&t_window](int y){
for(int i=1;i<t_window->_maxx;++i)
mvwprintw(t_window,y,i," ");
};
cleanLineBetweenBorder(2);
cleanLineBetweenBorder(4);
cleanLineBetweenBorder(5);
cleanLineBetweenBorder(7);
cleanLineBetweenBorder(8);
cleanLineBetweenBorder(9);
int center =NUtil::center(static_cast<int>(GameOfLife::getCurrentGameState()->name.size()),static_cast<int>(getmaxx(t_window))),
liveCount =GameOfLife::getCluster()->getLiveCount(),
totalCount =GameOfLife::getCluster()->getSize(),
deadCount =totalCount-liveCount;
wattron(t_window,COLOR_PAIR(4)|A_BOLD);
mvwprintw(t_window,
2,center,
"%s",
GameOfLife::getCurrentGameState()->name.c_str());
wattroff(t_window,COLOR_PAIR(4)|A_BOLD);
mvwprintw( t_window,4,2,"%s%i","Cycle: ",
GameOfLife::getCycle());
mvwprintw( t_window,5,2,"%s%i","Speed: ",
GameData::getSpeed());
mvwprintw( t_window,7,2,"%s%i","Live: ",
liveCount);
mvwprintw( t_window,8,2,"%s%i","Dead: ",
deadCount);
mvwprintw( t_window,9,2,"%s%i","Total: ",
totalCount);
};
| 27.022727
| 130
| 0.693019
|
DieSkaarj
|
95544104a8d9de09d0832e84a2cf3fe2f3209db6
| 367
|
cpp
|
C++
|
PROGRAMMERS/no12948.cpp
|
minjujuu/Algorithm
|
3787b57b818db9ef9b9f96bd430f57c95bbbe86d
|
[
"MIT"
] | null | null | null |
PROGRAMMERS/no12948.cpp
|
minjujuu/Algorithm
|
3787b57b818db9ef9b9f96bd430f57c95bbbe86d
|
[
"MIT"
] | null | null | null |
PROGRAMMERS/no12948.cpp
|
minjujuu/Algorithm
|
3787b57b818db9ef9b9f96bd430f57c95bbbe86d
|
[
"MIT"
] | null | null | null |
// 핸드폰 번호 가리기 https://programmers.co.kr/learn/courses/30/lessons/12948
#include <string>
#include <vector>
using namespace std;
string solution(string phone_number) {
string answer = "";
// phone_number의 길이-4 보다 작으면 *로 채움
for(int i=0; i<phone_number.length()-4; i++) {
phone_number[i] = '*';
}
answer = phone_number;
return answer;
}
| 24.466667
| 70
| 0.645777
|
minjujuu
|
9559d8eb5ad6310f4463b47efff1177259aa9c60
| 1,148
|
hpp
|
C++
|
src/new_tree_rearrangements/Twice_Bloom_Filter.hpp
|
theosanderson/usher
|
a58c56361cbd40be9dd671afabfa0839aa1cd58e
|
[
"MIT"
] | null | null | null |
src/new_tree_rearrangements/Twice_Bloom_Filter.hpp
|
theosanderson/usher
|
a58c56361cbd40be9dd671afabfa0839aa1cd58e
|
[
"MIT"
] | null | null | null |
src/new_tree_rearrangements/Twice_Bloom_Filter.hpp
|
theosanderson/usher
|
a58c56361cbd40be9dd671afabfa0839aa1cd58e
|
[
"MIT"
] | null | null | null |
#include <atomic>
#include <cstdio>
#include <sys/mman.h>
//See whether a valus appeared twice
class Twice_Bloom_Filter{
uint16_t* filter;
int hash(int pos){
//This works for coronavirus whose length is 29903<32767, it basically does nothing
return pos&0x7FFF;
}
public:
Twice_Bloom_Filter(){
filter=(uint16_t*) mmap(0,4096*2,PROT_READ|PROT_WRITE,MAP_SHARED | MAP_ANONYMOUS,-1,0);
//perror("");
}
~Twice_Bloom_Filter(){
munmap(filter, 4096);
}
void insert(int pos){
int hash_code=hash(pos);
//MSB is twice mask, LSB is once mask
uint16_t* value_ptr=filter+(hash_code>>3);
uint16_t value=*value_ptr;
uint16_t once_mask=1<<(hash_code&7);
//select the hit once bit, and move up to become hit twice mask, so hit twice will be set only if hit once is set
uint16_t mark_twice_mask=((once_mask&value)<<8);
*value_ptr=value|once_mask|mark_twice_mask;
}
bool query(int pos){
int hash_code=hash(pos);
uint16_t value=filter[hash_code>>3];
return value&(1<<((hash_code&7)+8));
}
};
| 31.027027
| 121
| 0.633275
|
theosanderson
|
955a5990cecad6107c13d991e0d5c343a93c7a3d
| 2,892
|
cpp
|
C++
|
rmw_gurumdds_shared_cpp/src/rmw_count.cpp
|
clemjh/rmw_gurumdds
|
c8c472854fa2eca57cee0e409bf0cb3f787a265a
|
[
"Apache-2.0"
] | null | null | null |
rmw_gurumdds_shared_cpp/src/rmw_count.cpp
|
clemjh/rmw_gurumdds
|
c8c472854fa2eca57cee0e409bf0cb3f787a265a
|
[
"Apache-2.0"
] | null | null | null |
rmw_gurumdds_shared_cpp/src/rmw_count.cpp
|
clemjh/rmw_gurumdds
|
c8c472854fa2eca57cee0e409bf0cb3f787a265a
|
[
"Apache-2.0"
] | null | null | null |
// Copyright 2019 GurumNetworks, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <map>
#include "rmw/error_handling.h"
#include "rmw_gurumdds_shared_cpp/rmw_common.hpp"
#include "rmw_gurumdds_shared_cpp/demangle.hpp"
#include "rmw_gurumdds_shared_cpp/types.hpp"
rmw_ret_t
shared__rmw_count_publishers(
const char * implementation_identifier,
const rmw_node_t * node,
const char * topic_name,
size_t * count)
{
if (node == nullptr) {
RMW_SET_ERROR_MSG("node handle is null");
return RMW_RET_ERROR;
}
if (node->implementation_identifier != implementation_identifier) {
RMW_SET_ERROR_MSG("node handle is not from this rmw implementation");
return RMW_RET_ERROR;
}
if (topic_name == nullptr) {
RMW_SET_ERROR_MSG("topic name is null");
return RMW_RET_ERROR;
}
if (count == nullptr) {
RMW_SET_ERROR_MSG("count handle is null");
return RMW_RET_ERROR;
}
GurumddsNodeInfo * node_info = static_cast<GurumddsNodeInfo *>(node->data);
if (node_info == nullptr) {
RMW_SET_ERROR_MSG("node info handle is null");
return RMW_RET_ERROR;
}
if (node_info->pub_listener == nullptr) {
RMW_SET_ERROR_MSG("publisher listener handle is null");
return RMW_RET_ERROR;
}
*count = node_info->pub_listener->count_topic(topic_name);
return RMW_RET_OK;
}
rmw_ret_t
shared__rmw_count_subscribers(
const char * implementation_identifier,
const rmw_node_t * node,
const char * topic_name,
size_t * count)
{
if (node == nullptr) {
RMW_SET_ERROR_MSG("node handle is null");
return RMW_RET_ERROR;
}
if (node->implementation_identifier != implementation_identifier) {
RMW_SET_ERROR_MSG("node handle is not from this rmw implementation");
return RMW_RET_ERROR;
}
if (topic_name == nullptr) {
RMW_SET_ERROR_MSG("topic name is null");
return RMW_RET_ERROR;
}
if (count == nullptr) {
RMW_SET_ERROR_MSG("count handle is null");
return RMW_RET_ERROR;
}
GurumddsNodeInfo * node_info = static_cast<GurumddsNodeInfo *>(node->data);
if (node_info == nullptr) {
RMW_SET_ERROR_MSG("node info handle is null");
return RMW_RET_ERROR;
}
if (node_info->sub_listener == nullptr) {
RMW_SET_ERROR_MSG("sublisher listener handle is null");
return RMW_RET_ERROR;
}
*count = node_info->sub_listener->count_topic(topic_name);
return RMW_RET_OK;
}
| 28.92
| 77
| 0.724412
|
clemjh
|
955b8c9a0d982db5ccc080815ed91e81033e7c30
| 644
|
cpp
|
C++
|
source/blink/system/AngularVelocitySystem.cpp
|
zjhlogo/blink
|
025da3506b34e3f0b02be524c97ae1f39c4c5854
|
[
"Apache-2.0"
] | null | null | null |
source/blink/system/AngularVelocitySystem.cpp
|
zjhlogo/blink
|
025da3506b34e3f0b02be524c97ae1f39c4c5854
|
[
"Apache-2.0"
] | null | null | null |
source/blink/system/AngularVelocitySystem.cpp
|
zjhlogo/blink
|
025da3506b34e3f0b02be524c97ae1f39c4c5854
|
[
"Apache-2.0"
] | null | null | null |
/**
@file AngularVelocitySystem.cpp
@brief
@details ~
@author zjhlogo
@date 8.11.2021
@copyright Copyright zjhlogo, 2021. All right reserved.
**/
#include "AngularVelocitySystem.h"
#include "../component/Components.h"
namespace blink
{
bool AngularVelocitySystem::initialize(flecs::world& world)
{
world.system<Rotation&, const AngularVelocity&>().each([](flecs::entity e, Rotation& rot, const AngularVelocity& vel)
{ rot.value *= glm::quat(vel.value * e.delta_time()); });
return true;
}
} // namespace blink
| 26.833333
| 125
| 0.583851
|
zjhlogo
|
955ceedf077bb8f69c10b544b635e8a59245a588
| 322
|
cpp
|
C++
|
Scanner/src/Controllers/LoggerController.cpp
|
Vyraax/gt511c3
|
23197526a241977103b03397a4bde9116230b079
|
[
"OML"
] | null | null | null |
Scanner/src/Controllers/LoggerController.cpp
|
Vyraax/gt511c3
|
23197526a241977103b03397a4bde9116230b079
|
[
"OML"
] | null | null | null |
Scanner/src/Controllers/LoggerController.cpp
|
Vyraax/gt511c3
|
23197526a241977103b03397a4bde9116230b079
|
[
"OML"
] | null | null | null |
#include "LoggerController.h"
#include "Interfaces/LoggerInterface.h"
LoggerController::LoggerController() : Controller()
{
this->ui = new LoggerInterface();
}
void LoggerController::OnEvent(Event& event)
{
}
void LoggerController::OnUpdate(float delta)
{
}
void LoggerController::OnRender()
{
this->ui->render();
}
| 15.333333
| 51
| 0.73913
|
Vyraax
|
95655a5e3d4021a63f61d88df2c7cf725fa8b032
| 45,713
|
hpp
|
C++
|
src/Evolution/Systems/Cce/Equations.hpp
|
nilsvu/spectre
|
1455b9a8d7e92db8ad600c66f54795c29c3052ee
|
[
"MIT"
] | 117
|
2017-04-08T22:52:48.000Z
|
2022-03-25T07:23:36.000Z
|
src/Evolution/Systems/Cce/Equations.hpp
|
GitHimanshuc/spectre
|
4de4033ba36547113293fe4dbdd77591485a4aee
|
[
"MIT"
] | 3,177
|
2017-04-07T21:10:18.000Z
|
2022-03-31T23:55:59.000Z
|
src/Evolution/Systems/Cce/Equations.hpp
|
geoffrey4444/spectre
|
9350d61830b360e2d5b273fdd176dcc841dbefb0
|
[
"MIT"
] | 85
|
2017-04-07T19:36:13.000Z
|
2022-03-01T10:21:00.000Z
|
// Distributed under the MIT License.
// See LICENSE.txt for details.
#pragma once
#include <type_traits>
#include "DataStructures/SpinWeighted.hpp" // IWYU pragma: keep
#include "DataStructures/Tags.hpp"
#include "DataStructures/Tags/TempTensor.hpp"
#include "DataStructures/Tensor/Tensor.hpp"
#include "Evolution/Systems/Cce/Tags.hpp" // IWYU pragma: keep
#include "NumericalAlgorithms/Spectral/SwshTags.hpp"
#include "Utilities/Gsl.hpp"
#include "Utilities/TMPL.hpp"
// IWYU pragma: no_forward_declare Cce::Tags::BondiBeta
// IWYU pragma: no_forward_declare Cce::Tags::DuRDividedByR
// IWYU pragma: no_forward_declare Cce::Tags::EthRDividedByR
// IWYU pragma: no_forward_declare Cce::Tags::Exp2Beta
// IWYU pragma: no_forward_declare Cce::Tags::BondiH
// IWYU pragma: no_forward_declare Cce::Tags::BondiJ
// IWYU pragma: no_forward_declare Cce::Tags::BondiJbar
// IWYU pragma: no_forward_declare Cce::Tags::JbarQMinus2EthBeta
// IWYU pragma: no_forward_declare Cce::Tags::BondiK
// IWYU pragma: no_forward_declare Cce::Tags::OneMinusY
// IWYU pragma: no_forward_declare Cce::Tags::BondiQ
// IWYU pragma: no_forward_declare Cce::Tags::BondiR
// IWYU pragma: no_forward_declare Cce::Tags::BondiU
// IWYU pragma: no_forward_declare Cce::Tags::BondiUbar
// IWYU pragma: no_forward_declare Cce::Tags::BondiW
// IWYU pragma: no_forward_declare ::Tags::Multiplies
// IWYU pragma: no_forward_declare Cce::Tags::Dy
// IWYU pragma: no_forward_declare Cce::Tags::Integrand
// IWYU pragma: no_forward_declare Cce::Tags::LinearFactor
// IWYU pragma: no_forward_declare Cce::Tags::LinearFactorForConjugate
// IWYU pragma: no_forward_declare Cce::Tags::PoleOfIntegrand
// IWYU pragma: no_forward_declare Cce::Tags::RegularIntegrand
// IWYU pragma: no_forward_declare Spectral::Swsh::Tags::Eth
// IWYU pragma: no_forward_declare Spectral::Swsh::Tags::EthEth
// IWYU pragma: no_forward_declare Spectral::Swsh::Tags::EthEthbar
// IWYU pragma: no_forward_declare Spectral::Swsh::Tags::Ethbar
// IWYU pragma: no_forward_declare Spectral::Swsh::Tags::EthbarEthbar
// IWYU pragma: no_forward_declare Spectral::Swsh::Tags::Derivative
// IWYU pragma: no_forward_declare Tags::TempTensor
// IWYU pragma: no_forward_declare Tags::SpinWeighted
// IWYU pragma: no_forward_declare SpinWeighted
// IWYU pragma: no_forward_declare Tensor
/// \cond
class ComplexDataVector;
/// \endcond
namespace Cce {
namespace detail {
template <typename BondiVariable>
struct integrand_terms_to_compute_for_bondi_variable_impl;
// template specializations for the individual tags
template <>
struct integrand_terms_to_compute_for_bondi_variable_impl<Tags::BondiBeta> {
using type = tmpl::list<Tags::Integrand<Tags::BondiBeta>>;
};
template <>
struct integrand_terms_to_compute_for_bondi_variable_impl<Tags::BondiQ> {
using type = tmpl::list<Tags::PoleOfIntegrand<Tags::BondiQ>,
Tags::RegularIntegrand<Tags::BondiQ>>;
};
template <>
struct integrand_terms_to_compute_for_bondi_variable_impl<Tags::BondiU> {
using type = tmpl::list<Tags::Integrand<Tags::BondiU>>;
};
template <>
struct integrand_terms_to_compute_for_bondi_variable_impl<Tags::BondiW> {
using type = tmpl::list<Tags::PoleOfIntegrand<Tags::BondiW>,
Tags::RegularIntegrand<Tags::BondiW>>;
};
template <>
struct integrand_terms_to_compute_for_bondi_variable_impl<Tags::BondiH> {
using type = tmpl::list<Tags::PoleOfIntegrand<Tags::BondiH>,
Tags::RegularIntegrand<Tags::BondiH>,
Tags::LinearFactor<Tags::BondiH>,
Tags::LinearFactorForConjugate<Tags::BondiH>>;
};
} // namespace detail
/// \brief A struct for providing a `tmpl::list` of integrand tags that need to
/// be computed before integration can proceed for a given Bondi variable tag.
template <typename BondiVariable>
using integrand_terms_to_compute_for_bondi_variable =
typename detail::integrand_terms_to_compute_for_bondi_variable_impl<
BondiVariable>::type;
/*!
* \brief Computes one of the inputs for the integration of one of the
* Characteristic hypersurface equations.
*
* \details The template argument must be one of the integrand-related prefix
* tags templated on a Bondi quantity tag for which that integrand is required.
* The relevant prefix tags are `Tags::Integrand`, `Tags::PoleOfIntegrand`,
* `Tags::RegularIntegrand`, `Tags::LinearFactor`, and
* `Tags::LinearFactorForConjugate`. The Bondi quantity tags that these tags may
* wrap are `Tags::BondiBeta`, `Tags::BondiQ`, `Tags::BondiU`, `Tags::BondiW`,
* and `Tags::BondiH`.
*
* The integrand terms which may be computed for a given Bondi variable are
* enumerated in the type alias `integrand_terms_to_compute_for_bondi_variable`,
* which takes as a single template argument the tag for which integrand terms
* would be computed, and is a `tmpl::list` of the integrand terms needed.
*
* The resulting quantity is returned by `not_null` pointer, and the required
* argument tags are given in `return_tags` and `argument_tags` type aliases,
* where the `return_tags` are passed by `not_null` pointer (so include
* temporary buffers) and the `argument_tags` are passed by const reference.
*
* Additional mathematical details for each of the computations can be found in
* the template specializations of this struct. All of the specializations have
* a static `apply` function which takes as arguments
* `SpinWeighted<ComplexDataVector, N>`s for each of the Bondi arguments.
*/
template <typename IntegrandTag>
struct ComputeBondiIntegrand;
/*!
* \brief Computes the integrand (right-hand side) of the equation which
* determines the radial (y) dependence of the Bondi quantity \f$\beta\f$.
*
* \details The quantity \f$\beta\f$ is defined via the Bondi form of the
* metric:
* \f[
* ds^2 = - \left(e^{2 \beta} (1 + r W) - r^2 h_{AB} U^A U^B\right) du^2 - 2
* e^{2 \beta} du dr - 2 r^2 h_{AB} U^B du dx^A + r^2 h_{A B} dx^A dx^B. \f]
* Additional quantities \f$J\f$ and \f$K\f$ are defined using a spherical
* angular dyad \f$q^A\f$:
* \f[ J \equiv h_{A B} q^A q^B, K \equiv h_{A B} q^A
* \bar{q}^B.\f]
* See \cite Bishop1997ik \cite Handmer2014qha for full details.
*
* We write the equations of motion in the compactified coordinate \f$ y \equiv
* 1 - 2 R/ r\f$, where \f$r(u, \theta, \phi)\f$ is the Bondi radius of the
* \f$y=\f$ constant surface and \f$R(u,\theta,\phi)\f$ is the Bondi radius of
* the worldtube. The equation which determines \f$\beta\f$ on a surface of
* constant \f$u\f$ given \f$J\f$ on the same surface is
* \f[\partial_y (\beta) =
* \frac{1}{8} (-1 + y) \left(\partial_y (J) \partial_y(\bar{J})
* - \frac{(\partial_y (J \bar{J}))^2}{4 K^2}\right). \f]
*/
template <>
struct ComputeBondiIntegrand<Tags::Integrand<Tags::BondiBeta>> {
public:
using pre_swsh_derivative_tags =
tmpl::list<Tags::Dy<Tags::BondiJ>, Tags::BondiJ>;
using swsh_derivative_tags = tmpl::list<>;
using integration_independent_tags = tmpl::list<Tags::OneMinusY>;
using temporary_tags = tmpl::list<>;
using return_tags = tmpl::append<tmpl::list<Tags::Integrand<Tags::BondiBeta>>,
temporary_tags>;
using argument_tags =
tmpl::append<pre_swsh_derivative_tags, swsh_derivative_tags,
integration_independent_tags>;
template <typename... Args>
static void apply(
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 0>>*>
integrand_for_beta,
const Args&... args) {
apply_impl(make_not_null(&get(*integrand_for_beta)), get(args)...);
}
private:
static void apply_impl(
gsl::not_null<SpinWeighted<ComplexDataVector, 0>*> integrand_for_beta,
const SpinWeighted<ComplexDataVector, 2>& dy_j,
const SpinWeighted<ComplexDataVector, 2>& j,
const SpinWeighted<ComplexDataVector, 0>& one_minus_y);
};
/*!
* \brief Computes the pole part of the integrand (right-hand side) of the
* equation which determines the radial (y) dependence of the Bondi quantity
* \f$Q\f$.
*
* \details The quantity \f$Q\f$ is defined via the Bondi form of the metric:
* \f[ds^2 = - \left(e^{2 \beta} (1 + r W) - r^2 h_{AB} U^A U^B\right) du^2 - 2
* e^{2 \beta} du dr - 2 r^2 h_{AB} U^B du dx^A + r^2 h_{A B} dx^A dx^B. \f]
* Additional quantities \f$J\f$ and \f$K\f$ are defined using a spherical
* angular dyad \f$q^A\f$:
* \f[ J \equiv h_{A B} q^A q^B, K \equiv h_{A B} q^A \bar{q}^B,\f]
* and \f$Q\f$ is defined as a supplemental variable for radial integration of
* \f$U\f$:
* \f[ Q_A = r^2 e^{-2\beta} h_{AB} \partial_r U^B\f]
* and \f$Q = Q_A q^A\f$. See \cite Bishop1997ik \cite Handmer2014qha for full
* details.
*
* We write the equations of motion in the compactified coordinate \f$ y \equiv
* 1 - 2 R/ r\f$, where \f$r(u, \theta, \phi)\f$ is the Bondi radius of the
* \f$y=\f$ constant surface and \f$R(u,\theta,\phi)\f$ is the Bondi radius of
* the worldtube. The equation which determines \f$Q\f$ on a surface of constant
* \f$u\f$ given \f$J\f$ and \f$\beta\f$ on the same surface is written as
* \f[(1 - y) \partial_y Q + 2 Q = A_Q + (1 - y) B_Q.\f]
* We refer to \f$A_Q\f$ as the "pole part" of the integrand and \f$B_Q\f$
* as the "regular part". The pole part is computed by this function, and has
* the expression
* \f[A_Q = -4 \eth \beta.\f]
*/
template <>
struct ComputeBondiIntegrand<Tags::PoleOfIntegrand<Tags::BondiQ>> {
public:
using pre_swsh_derivative_tags = tmpl::list<>;
using swsh_derivative_tags =
tmpl::list<Spectral::Swsh::Tags::Derivative<Tags::BondiBeta,
Spectral::Swsh::Tags::Eth>>;
using integration_independent_tags = tmpl::list<>;
using temporary_tags = tmpl::list<>;
using return_tags =
tmpl::append<tmpl::list<Tags::PoleOfIntegrand<Tags::BondiQ>>,
temporary_tags>;
using argument_tags =
tmpl::append<pre_swsh_derivative_tags, swsh_derivative_tags,
integration_independent_tags>;
template <typename... Args>
static void apply(
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 1>>*>
pole_of_integrand_for_q,
const Args&... args) {
apply_impl(make_not_null(&get(*pole_of_integrand_for_q)), get(args)...);
}
private:
static void apply_impl(gsl::not_null<SpinWeighted<ComplexDataVector, 1>*>
pole_of_integrand_for_q,
const SpinWeighted<ComplexDataVector, 1>& eth_beta);
};
/*!
* \brief Computes the regular part of the integrand (right-hand side) of the
* equation which determines the radial (y) dependence of the Bondi quantity
* \f$Q\f$.
*
* \details The quantity \f$Q\f$ is defined via the Bondi form of the metric:
* \f[ds^2 = - \left(e^{2 \beta} (1 + r W) - r^2 h_{AB} U^A U^B\right) du^2 - 2
* e^{2 \beta} du dr - 2 r^2 h_{AB} U^B du dx^A + r^2 h_{A B} dx^A dx^B. \f]
* Additional quantities \f$J\f$ and \f$K\f$ are defined using a spherical
* angular dyad \f$q^A\f$:
* \f[ J \equiv h_{A B} q^A q^B, K \equiv h_{A B} q^A \bar{q}^B,\f]
* and \f$Q\f$ is defined as a supplemental variable for radial integration of
* \f$U\f$:
* \f[ Q_A = r^2 e^{-2\beta} h_{AB} \partial_r U^B\f]
* and \f$Q = Q_A q^A\f$. See \cite Bishop1997ik \cite Handmer2014qha for
* full details.
*
* We write the equations of motion in the compactified coordinate \f$ y \equiv
* 1 - 2 R/ r\f$, where \f$r(u, \theta, \phi)\f$ is the Bondi radius of the
* \f$y=\f$ constant surface and \f$R(u,\theta,\phi)\f$ is the Bondi radius of
* the worldtube. The equation which determines \f$Q\f$ on a surface of constant
* \f$u\f$ given \f$J\f$ and \f$\beta\f$ on the same surface is written as
* \f[(1 - y) \partial_y Q + 2 Q = A_Q + (1 - y) B_Q. \f]
* We refer to \f$A_Q\f$ as the "pole part" of the integrand and \f$B_Q\f$ as
* the "regular part". The regular part is computed by this function, and has
* the expression
* \f[ B_Q = - \left(2 \mathcal{A}_Q + \frac{2
* \bar{\mathcal{A}_Q} J}{K} - 2 \partial_y (\eth (\beta)) +
* \frac{\partial_y (\bar{\eth} (J))}{K}\right), \f]
* where
* \f[ \mathcal{A}_Q = - \tfrac{1}{4} \eth (\bar{J} \partial_y (J)) +
* \tfrac{1}{4} J \partial_y (\eth (\bar{J})) - \tfrac{1}{4} \eth (\bar{J})
* \partial_y (J) + \frac{\eth (J \bar{J}) \partial_y (J \bar{J})}{8 K^2} -
* \frac{\bar{J} \eth (R) \partial_y (J)}{4 R}. \f].
*/
template <>
struct ComputeBondiIntegrand<Tags::RegularIntegrand<Tags::BondiQ>> {
public:
using pre_swsh_derivative_tags =
tmpl::list<Tags::Dy<Tags::BondiBeta>, Tags::Dy<Tags::BondiJ>,
Tags::BondiJ>;
using swsh_derivative_tags = tmpl::list<
Spectral::Swsh::Tags::Derivative<Tags::Dy<Tags::BondiBeta>,
Spectral::Swsh::Tags::Eth>,
Spectral::Swsh::Tags::Derivative<
::Tags::Multiplies<Tags::BondiJ, Tags::BondiJbar>,
Spectral::Swsh::Tags::Eth>,
Spectral::Swsh::Tags::Derivative<
::Tags::Multiplies<Tags::BondiJbar, Tags::Dy<Tags::BondiJ>>,
Spectral::Swsh::Tags::Eth>,
Spectral::Swsh::Tags::Derivative<Tags::Dy<Tags::BondiJ>,
Spectral::Swsh::Tags::Ethbar>,
Spectral::Swsh::Tags::Derivative<Tags::BondiJ,
Spectral::Swsh::Tags::Ethbar>>;
using integration_independent_tags =
tmpl::list<Tags::EthRDividedByR, Tags::BondiK>;
using temporary_tags =
tmpl::list<::Tags::SpinWeighted<::Tags::TempScalar<0, ComplexDataVector>,
std::integral_constant<int, 1>>>;
using return_tags =
tmpl::append<tmpl::list<Tags::RegularIntegrand<Tags::BondiQ>>,
temporary_tags>;
using argument_tags =
tmpl::append<pre_swsh_derivative_tags, swsh_derivative_tags,
integration_independent_tags>;
template <typename... Args>
static void apply(
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 1>>*>
regular_integrand_for_q,
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 1>>*>
script_aq,
const Args&... args) {
apply_impl(make_not_null(&get(*regular_integrand_for_q)),
make_not_null(&get(*script_aq)), get(args)...);
}
private:
static void apply_impl(
gsl::not_null<SpinWeighted<ComplexDataVector, 1>*>
regular_integrand_for_q,
gsl::not_null<SpinWeighted<ComplexDataVector, 1>*> script_aq,
const SpinWeighted<ComplexDataVector, 0>& dy_beta,
const SpinWeighted<ComplexDataVector, 2>& dy_j,
const SpinWeighted<ComplexDataVector, 2>& j,
const SpinWeighted<ComplexDataVector, 1>& eth_dy_beta,
const SpinWeighted<ComplexDataVector, 1>& eth_j_jbar,
const SpinWeighted<ComplexDataVector, 1>& eth_jbar_dy_j,
const SpinWeighted<ComplexDataVector, 1>& ethbar_dy_j,
const SpinWeighted<ComplexDataVector, 1>& ethbar_j,
const SpinWeighted<ComplexDataVector, 1>& eth_r_divided_by_r,
const SpinWeighted<ComplexDataVector, 0>& k);
};
/*!
* \brief Computes the integrand (right-hand side) of the equation which
* determines the radial (y) dependence of the Bondi quantity \f$U\f$.
*
* \details The quantity \f$U\f$ is defined via the Bondi form of the metric:
* \f[ds^2 = - \left(e^{2 \beta} (1 + r W) - r^2 h_{AB} U^A U^B\right) du^2 - 2
* e^{2 \beta} du dr - 2 r^2 h_{AB} U^B du dx^A + r^2 h_{A B} dx^A dx^B. \f]
* Additional quantities \f$J\f$ and \f$K\f$ are defined using a spherical
* angular dyad \f$q^A\f$:
* \f[ J \equiv h_{A B} q^A q^B, K \equiv h_{A B} q^A \bar{q}^B,\f]
* and \f$Q\f$ is defined as a supplemental variable for radial integration of
* \f$U\f$:
* \f[ Q_A = r^2 e^{-2\beta} h_{AB} \partial_r U^B\f]
* and \f$U = U_A q^A\f$. See \cite Bishop1997ik \cite Handmer2014qha for full
* details.
*
* We write the equations of motion in the compactified coordinate \f$ y \equiv
* 1 - 2 R/ r\f$, where \f$r(u, \theta, \phi)\f$ is the Bondi radius of the
* \f$y=\f$ constant surface and \f$R(u,\theta,\phi)\f$ is the Bondi radius of
* the worldtube. The equation which determines \f$U\f$ on a surface of constant
* \f$u\f$ given \f$J\f$, \f$\beta\f$, and \f$Q\f$ on the same surface is
* written as
* \f[\partial_y U = \frac{e^{2\beta}}{2 R} (K Q - J \bar{Q}). \f]
*/
template <>
struct ComputeBondiIntegrand<Tags::Integrand<Tags::BondiU>> {
public:
using pre_swsh_derivative_tags =
tmpl::list<Tags::Exp2Beta, Tags::BondiJ, Tags::BondiQ>;
using swsh_derivative_tags = tmpl::list<>;
using integration_independent_tags = tmpl::list<Tags::BondiK, Tags::BondiR>;
using temporary_tags = tmpl::list<>;
using return_tags =
tmpl::append<tmpl::list<Tags::Integrand<Tags::BondiU>>, temporary_tags>;
using argument_tags =
tmpl::append<pre_swsh_derivative_tags, swsh_derivative_tags,
integration_independent_tags>;
template <typename... Args>
static void apply(
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 1>>*>
regular_integrand_for_u,
const Args&... args) {
apply_impl(make_not_null(&get(*regular_integrand_for_u)), get(args)...);
}
private:
static void apply_impl(gsl::not_null<SpinWeighted<ComplexDataVector, 1>*>
regular_integrand_for_u,
const SpinWeighted<ComplexDataVector, 0>& exp_2_beta,
const SpinWeighted<ComplexDataVector, 2>& j,
const SpinWeighted<ComplexDataVector, 1>& q,
const SpinWeighted<ComplexDataVector, 0>& k,
const SpinWeighted<ComplexDataVector, 0>& r);
};
/*!
* \brief Computes the pole part of the integrand (right-hand side) of the
* equation which determines the radial (y) dependence of the Bondi quantity
* \f$W\f$.
*
* \details The quantity \f$W\f$ is defined via the Bondi form of the metric:
* \f[ds^2 = - \left(e^{2 \beta} (1 + r W) - r^2 h_{AB} U^A U^B\right) du^2 - 2
* e^{2 \beta} du dr - 2 r^2 h_{AB} U^B du dx^A + r^2 h_{A B} dx^A dx^B. \f]
* Additional quantities \f$J\f$ and \f$K\f$ are defined using a spherical
* angular dyad \f$q^A\f$:
* \f[ J \equiv h_{A B} q^A q^B, K \equiv h_{A B} q^A \bar{q}^B.\f]
* See \cite Bishop1997ik \cite Handmer2014qha for full details.
*
* We write the equations of motion in the compactified coordinate \f$ y \equiv
* 1 - 2 R/ r\f$, where \f$r(u, \theta, \phi)\f$ is the Bondi radius of the
* \f$y=\f$ constant surface and \f$R(u,\theta,\phi)\f$ is the Bondi radius of
* the worldtube. The equation which determines \f$W\f$ on a surface of constant
* \f$u\f$ given \f$J\f$,\f$\beta\f$, \f$Q\f$, and \f$U\f$ on the same surface
* is written as
* \f[(1 - y) \partial_y W + 2 W = A_W + (1 - y) B_W.\f] We refer
* to \f$A_W\f$ as the "pole part" of the integrand and \f$B_W\f$ as the
* "regular part". The pole part is computed by this function, and has the
* expression
* \f[A_W = \eth (\bar{U}) + \bar{\eth} (U).\f]
*/
template <>
struct ComputeBondiIntegrand<Tags::PoleOfIntegrand<Tags::BondiW>> {
public:
using pre_swsh_derivative_tags = tmpl::list<>;
using swsh_derivative_tags = tmpl::list<Spectral::Swsh::Tags::Derivative<
Tags::BondiU, Spectral::Swsh::Tags::Ethbar>>;
using integration_independent_tags = tmpl::list<>;
using temporary_tags = tmpl::list<>;
using return_tags =
tmpl::append<tmpl::list<Tags::PoleOfIntegrand<Tags::BondiW>>,
temporary_tags>;
using argument_tags =
tmpl::append<pre_swsh_derivative_tags, swsh_derivative_tags,
integration_independent_tags>;
template <typename... Args>
static void apply(
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 0>>*>
pole_of_integrand_for_w,
const Args&... args) {
apply_impl(make_not_null(&get(*pole_of_integrand_for_w)), get(args)...);
}
private:
static void apply_impl(gsl::not_null<SpinWeighted<ComplexDataVector, 0>*>
pole_of_integrand_for_w,
const SpinWeighted<ComplexDataVector, 0>& ethbar_u);
};
/*!
* \brief Computes the regular part of the integrand (right-hand side) of the
* equation which determines the radial (y) dependence of the Bondi quantity
* \f$W\f$.
*
* \details The quantity \f$W\f$ is defined via the Bondi form of the metric:
* \f[ds^2 = - \left(e^{2 \beta} (1 + r W) - r^2 h_{AB} U^A U^B\right) du^2 - 2
* e^{2 \beta} du dr - 2 r^2 h_{AB} U^B du dx^A + r^2 h_{A B} dx^A dx^B. \f]
* Additional quantities \f$J\f$ and \f$K\f$ are defined using a spherical
* angular dyad \f$q^A\f$:
* \f[ J \equiv h_{A B} q^A q^B, K \equiv h_{A B} q^A \bar{q}^B,\f]
* See \cite Bishop1997ik \cite Handmer2014qha for full details.
*
* We write the equations of motion in the compactified coordinate \f$ y \equiv
* 1 - 2 R/ r\f$, where \f$r(u, \theta, \phi)\f$ is the Bondi radius of the
* \f$y=\f$ constant surface and \f$R(u,\theta,\phi)\f$ is the Bondi radius of
* the worldtube. The equation which determines \f$W\f$ on a surface of constant
* \f$u\f$ given \f$J\f$, \f$\beta\f$, \f$Q\f$, \f$U\f$ on the same surface is
* written as
* \f[(1 - y) \partial_y W + 2 W = A_W + (1 - y) B_W. \f]
* We refer to \f$A_W\f$ as the "pole part" of the integrand and \f$B_W\f$ as
* the "regular part". The regular part is computed by this function, and has
* the expression
* \f[ B_W = \tfrac{1}{4} \partial_y (\eth (\bar{U})) + \tfrac{1}{4} \partial_y
* (\bar{\eth} (U)) - \frac{1}{2 R} + \frac{e^{2 \beta} (\mathcal{A}_W +
* \bar{\mathcal{A}_W})}{4 R}, \f]
* where
* \f{align*}
* \mathcal{A}_W =& - \eth (\beta) \eth (\bar{J}) + \tfrac{1}{2} \bar{\eth}
* (\bar{\eth} (J)) + 2 \bar{\eth} (\beta) \bar{\eth} (J) + (\bar{\eth}
* (\beta))^2 J + \bar{\eth}
* (\bar{\eth} (\beta)) J + \frac{\eth (J \bar{J}) \bar{\eth} (J \bar{J})}{8
* K^3} + \frac{1}{2 K} - \frac{\eth (\bar{\eth} (J \bar{J}))}{8 K} -
* \frac{\eth (J
* \bar{J}) \bar{\eth} (\beta)}{2 K} \nonumber \\
* &- \frac{\eth (\bar{J}) \bar{\eth} (J)}{4 K} - \frac{\eth (\bar{\eth} (J))
* \bar{J}}{4 K} + \tfrac{1}{2} K - \eth (\bar{\eth} (\beta)) K - \eth
* (\beta) \bar{\eth} (\beta) K + \tfrac{1}{4} (- K Q \bar{Q} + J \bar{Q}^2).
* \f}
*/
template <>
struct ComputeBondiIntegrand<Tags::RegularIntegrand<Tags::BondiW>> {
public:
using pre_swsh_derivative_tags =
tmpl::list<Tags::Dy<Tags::BondiU>, Tags::Exp2Beta, Tags::BondiJ,
Tags::BondiQ>;
using swsh_derivative_tags = tmpl::list<
Spectral::Swsh::Tags::Derivative<Tags::BondiBeta,
Spectral::Swsh::Tags::Eth>,
Spectral::Swsh::Tags::Derivative<Tags::BondiBeta,
Spectral::Swsh::Tags::EthEth>,
Spectral::Swsh::Tags::Derivative<Tags::BondiBeta,
Spectral::Swsh::Tags::EthEthbar>,
Spectral::Swsh::Tags::Derivative<
Spectral::Swsh::Tags::Derivative<Tags::BondiJ,
Spectral::Swsh::Tags::Ethbar>,
Spectral::Swsh::Tags::Eth>,
Spectral::Swsh::Tags::Derivative<
::Tags::Multiplies<Tags::BondiJ, Tags::BondiJbar>,
Spectral::Swsh::Tags::EthEthbar>,
Spectral::Swsh::Tags::Derivative<
::Tags::Multiplies<Tags::BondiJ, Tags::BondiJbar>,
Spectral::Swsh::Tags::Eth>,
Spectral::Swsh::Tags::Derivative<Tags::Dy<Tags::BondiU>,
Spectral::Swsh::Tags::Ethbar>,
Spectral::Swsh::Tags::Derivative<Tags::BondiJ,
Spectral::Swsh::Tags::EthbarEthbar>,
Spectral::Swsh::Tags::Derivative<Tags::BondiJ,
Spectral::Swsh::Tags::Ethbar>>;
using integration_independent_tags =
tmpl::list<Tags::EthRDividedByR, Tags::BondiK, Tags::BondiR>;
using temporary_tags =
tmpl::list<::Tags::SpinWeighted<::Tags::TempScalar<0, ComplexDataVector>,
std::integral_constant<int, 0>>>;
using return_tags =
tmpl::append<tmpl::list<Tags::RegularIntegrand<Tags::BondiW>>,
temporary_tags>;
using argument_tags =
tmpl::append<pre_swsh_derivative_tags, swsh_derivative_tags,
integration_independent_tags>;
template <typename... Args>
static void apply(
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 0>>*>
regular_integrand_for_w,
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 0>>*>
script_av,
const Args&... args) {
apply_impl(make_not_null(&get(*regular_integrand_for_w)),
make_not_null(&get(*script_av)), get(args)...);
}
private:
static void apply_impl(
gsl::not_null<SpinWeighted<ComplexDataVector, 0>*>
regular_integrand_for_w,
gsl::not_null<SpinWeighted<ComplexDataVector, 0>*> script_av,
const SpinWeighted<ComplexDataVector, 1>& dy_u,
const SpinWeighted<ComplexDataVector, 0>& exp_2_beta,
const SpinWeighted<ComplexDataVector, 2>& j,
const SpinWeighted<ComplexDataVector, 1>& q,
const SpinWeighted<ComplexDataVector, 1>& eth_beta,
const SpinWeighted<ComplexDataVector, 2>& eth_eth_beta,
const SpinWeighted<ComplexDataVector, 0>& eth_ethbar_beta,
const SpinWeighted<ComplexDataVector, 2>& eth_ethbar_j,
const SpinWeighted<ComplexDataVector, 0>& eth_ethbar_j_jbar,
const SpinWeighted<ComplexDataVector, 1>& eth_j_jbar,
const SpinWeighted<ComplexDataVector, 0>& ethbar_dy_u,
const SpinWeighted<ComplexDataVector, 0>& ethbar_ethbar_j,
const SpinWeighted<ComplexDataVector, 1>& ethbar_j,
const SpinWeighted<ComplexDataVector, 1>& eth_r_divided_by_r,
const SpinWeighted<ComplexDataVector, 0>& k,
const SpinWeighted<ComplexDataVector, 0>& r);
};
/*!
* \brief Computes the pole part of the integrand (right-hand side) of the
* equation which determines the radial (y) dependence of the Bondi quantity
* \f$H\f$.
*
* \details The quantity \f$H \equiv \partial_u J\f$ (evaluated at constant y)
* is defined via the Bondi form of the metric:
* \f[ds^2 = - \left(e^{2 \beta} (1 + r W) - r^2 h_{AB} U^A U^B\right) du^2 - 2
* e^{2 \beta} du dr - 2 r^2 h_{AB} U^B du dx^A + r^2 h_{A B} dx^A dx^B. \f]
* Additional quantities \f$J\f$ and \f$K\f$ are defined using a spherical
* angular dyad \f$q^A\f$:
* \f[ J \equiv h_{A B} q^A q^B, K \equiv h_{A B} q^A \bar{q}^B.\f]
* See \cite Bishop1997ik \cite Handmer2014qha for full details.
*
* We write the equations of motion in the compactified coordinate \f$ y \equiv
* 1 - 2 R/ r\f$, where \f$r(u, \theta, \phi)\f$ is the Bondi radius of the
* \f$y=\f$ constant surface and \f$R(u,\theta,\phi)\f$ is the Bondi radius of
* the worldtube. The equation which determines \f$W\f$ on a surface of constant
* \f$u\f$ given \f$J\f$,\f$\beta\f$, \f$Q\f$, \f$U\f$, and \f$W\f$ on the same
* surface is written as
* \f[(1 - y) \partial_y H + H + (1 - y)(\mathcal{D}_J H
* + \bar{\mathcal{D}}_J \bar{H}) = A_J + (1 - y) B_J.\f]
*
* We refer to \f$A_J\f$ as the "pole part" of the integrand
* and \f$B_J\f$ as the "regular part". The pole part is computed by this
* function, and has the expression
* \f{align*}
* A_J =& - \tfrac{1}{2} \eth (J \bar{U}) - \eth (\bar{U}) J - \tfrac{1}{2}
* \bar{\eth} (U) J - \eth (U) K - \tfrac{1}{2} (\bar{\eth} (J) U) + 2 J W
* \f}
*/
template <>
struct ComputeBondiIntegrand<Tags::PoleOfIntegrand<Tags::BondiH>> {
public:
using pre_swsh_derivative_tags =
tmpl::list<Tags::BondiJ, Tags::BondiU, Tags::BondiW>;
using swsh_derivative_tags = tmpl::list<
Spectral::Swsh::Tags::Derivative<Tags::BondiU, Spectral::Swsh::Tags::Eth>,
Spectral::Swsh::Tags::Derivative<Tags::BondiJ,
Spectral::Swsh::Tags::Ethbar>,
Spectral::Swsh::Tags::Derivative<
::Tags::Multiplies<Tags::BondiJbar, Tags::BondiU>,
Spectral::Swsh::Tags::Ethbar>,
Spectral::Swsh::Tags::Derivative<Tags::BondiU,
Spectral::Swsh::Tags::Ethbar>>;
using integration_independent_tags = tmpl::list<Tags::BondiK>;
using temporary_tags = tmpl::list<>;
using return_tags =
tmpl::append<tmpl::list<Tags::PoleOfIntegrand<Tags::BondiH>>,
temporary_tags>;
using argument_tags =
tmpl::append<pre_swsh_derivative_tags, swsh_derivative_tags,
integration_independent_tags>;
template <typename... Args>
static void apply(
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 2>>*>
pole_of_integrand_for_h,
const Args&... args) {
apply_impl(make_not_null(&get(*pole_of_integrand_for_h)), get(args)...);
}
private:
static void apply_impl(
gsl::not_null<SpinWeighted<ComplexDataVector, 2>*>
pole_of_integrand_for_h,
const SpinWeighted<ComplexDataVector, 2>& j,
const SpinWeighted<ComplexDataVector, 1>& u,
const SpinWeighted<ComplexDataVector, 0>& w,
const SpinWeighted<ComplexDataVector, 2>& eth_u,
const SpinWeighted<ComplexDataVector, 1>& ethbar_j,
const SpinWeighted<ComplexDataVector, -2>& ethbar_jbar_u,
const SpinWeighted<ComplexDataVector, 0>& ethbar_u,
const SpinWeighted<ComplexDataVector, 0>& k);
};
/*!
* \brief Computes the pole part of the integrand (right-hand side) of the
* equation which determines the radial (y) dependence of the Bondi quantity
* \f$H\f$.
*
* \details The quantity \f$H \equiv \partial_u J\f$ (evaluated at constant y)
* is defined via the Bondi form of the metric:
* \f[ds^2 = - \left(e^{2 \beta} (1 + r W) - r^2 h_{AB} U^A U^B\right) du^2 - 2
* e^{2 \beta} du dr - 2 r^2 h_{AB} U^B du dx^A + r^2 h_{A B} dx^A dx^B. \f]
* Additional quantities \f$J\f$ and \f$K\f$ are defined using a spherical
* angular dyad \f$q^A\f$:
* \f[ J \equiv h_{A B} q^A q^B, K \equiv h_{A B} q^A \bar{q}^B.\f]
* See \cite Bishop1997ik \cite Handmer2014qha for full details.
*
* We write the equations of motion in the compactified coordinate \f$ y \equiv
* 1 - 2 R/ r\f$, where \f$r(u, \theta, \phi)\f$ is the Bondi radius of the
* \f$y=\f$ constant surface and \f$R(u,\theta,\phi)\f$ is the Bondi radius of
* the worldtube. The equation which determines \f$H\f$ on a surface of constant
* \f$u\f$ given \f$J\f$,\f$\beta\f$, \f$Q\f$, \f$U\f$, and \f$W\f$ on the same
* surface is written as
* \f[(1 - y) \partial_y H + H + (1 - y)(\mathcal{D}_J H + \bar{\mathcal{D}}_J
* \bar{H}) = A_J + (1 - y) B_J.\f]
* We refer to \f$A_J\f$ as the "pole part" of the integrand
* and \f$B_J\f$ as the "regular part". The pole part is computed by this
* function, and has the expression
* \f{align*}
* B_J =& -\tfrac{1}{2} \left(\eth(\partial_y (J) \bar{U}) + \partial_y
* (\bar{\eth} (J)) U \right) + J (\mathcal{B}_J + \bar{\mathcal{B}}_J) \notag\\
* &+ \frac{e^{2 \beta}}{2 R} \left(\mathcal{C}_J + \eth (\eth (\beta)) -
* \tfrac{1}{2} \eth (Q) - (\mathcal{A}_J + \bar{\mathcal{A}_J}) J +
* \frac{\bar{\mathcal{C}_J} J^2}{K^2} + \frac{\eth (J (-2 \bar{\eth} (\beta) +
* \bar{Q}))}{4 K} - \frac{\eth (\bar{Q}) J}{4 K} + (\eth (\beta) -
* \tfrac{1}{2} Q)^2\right) \notag\\
* &- \partial_y (J) \left(\frac{\eth (U) \bar{J}}{2 K} - \tfrac{1}{2}
* \bar{\eth} (\bar{U}) J K + \tfrac{1}{4} (\eth (\bar{U}) - \bar{\eth} (U))
* K^2 + \frac{1}{2} \frac{\eth (R) \bar{U}}{R} - \frac{1}{2}
* W\right)\notag\\
* &+ \partial_y (\bar{J}) \left(- \tfrac{1}{4} (- \eth (\bar{U}) + \bar{\eth}
* (U)) J^2 + \eth (U) J \left(- \frac{1}{2 K} + \tfrac{1}{2}
* K\right)\right)\notag\\
* &+ (1 - y) \bigg[\frac{1}{2} \left(- \frac{\partial_y (J)}{R} + \frac{2
* \partial_{u} (R) \partial_y (\partial_y (J))}{R} + \partial_y
* (\partial_y (J)) W\right) + \partial_y (J) \left(\tfrac{1}{2} \partial_y (W)
* + \frac{1}{2 R}\right)\bigg]\notag\\
* &+ (1 - y)^2 \bigg[ \frac{\partial_y (\partial_y (J)) }{4 R} \bigg],
* \f}
* where
* \f{align*}
* \mathcal{A}_J =& \tfrac{1}{4} \eth (\eth (\bar{J})) - \frac{1}{4 K^3} -
* \frac{\eth (\bar{\eth} (J \bar{J})) - (\eth (\bar{\eth} (\bar{J})) - 4
\bar{J})
* J}{16 K^3} + \frac{3}{4 K} - \frac{\eth (\bar{\eth} (\beta))}{4 K} \notag\\
* &- \frac{\eth (\bar{\eth} (J)) \bar{J} (1 - \frac{1}{4 K^2})}{4 K} +
* \tfrac{1}{2} \eth (\bar{J}) \left(\eth (\beta) + \frac{\bar{\eth} (J \bar{J})
* J}{4 K^3} - \frac{\bar{\eth} (J) (-1 + 2 K^2)}{4 K^3} - \tfrac{1}{2}
* Q\right)\\
* \mathcal{B}_J =& - \frac{\eth (U) \bar{J} \partial_y (J \bar{J})}{4 K} +
* \tfrac{1}{2} \partial_y (W) + \frac{1}{4 R} + \tfrac{1}{4} \bar{\eth} (J)
* \partial_y (\bar{J}) U - \frac{\bar{\eth} (J \bar{J}) \partial_y (J \bar{J})
* U}{8 K^2} \notag\\&- \tfrac{1}{4} J \partial_y (\eth (\bar{J})) \bar{U} +
* \tfrac{1}{4} (\eth (J \partial_y (\bar{J})) + \frac{J \eth (R)
* \partial_y(\bar{J})}{R}) \bar{U} \\
* &+ (1 - y) \bigg[ \frac{\mathcal{D}_J \partial_{u} (R)
* \partial_y (J)}{R} - \tfrac{1}{4} \partial_y (J) \partial_y (\bar{J}) W +
* \frac{(\partial_y (J \bar{J}))^2 W}{16 K^2} \bigg] \\
* &+ (1 - y)^2 \bigg[ - \frac{\partial_y (J) \partial_y (\bar{J})}{8 R} +
* \frac{(\partial_y (J \bar{J}))^2}{32 K^2 R} \bigg]\\
* \mathcal{C}_J =& \tfrac{1}{2} \bar{\eth} (J) K (\eth (\beta) - \tfrac{1}{2}
* Q)\\ \mathcal{D}_J =& \tfrac{1}{4} \left(-2 \partial_y (\bar{J}) +
* \frac{\bar{J} \partial_y (J \bar{J})}{K^2}\right)
* \f}
*/
template <>
struct ComputeBondiIntegrand<Tags::RegularIntegrand<Tags::BondiH>> {
public:
using pre_swsh_derivative_tags =
tmpl::list<Tags::Dy<Tags::Dy<Tags::BondiJ>>, Tags::Dy<Tags::BondiJ>,
Tags::Dy<Tags::BondiW>, Tags::Exp2Beta, Tags::BondiJ,
Tags::BondiQ, Tags::BondiU, Tags::BondiW>;
using swsh_derivative_tags = tmpl::list<
Spectral::Swsh::Tags::Derivative<Tags::BondiBeta,
Spectral::Swsh::Tags::Eth>,
Spectral::Swsh::Tags::Derivative<Tags::BondiBeta,
Spectral::Swsh::Tags::EthEth>,
Spectral::Swsh::Tags::Derivative<Tags::BondiBeta,
Spectral::Swsh::Tags::EthEthbar>,
Spectral::Swsh::Tags::Derivative<
Spectral::Swsh::Tags::Derivative<Tags::BondiJ,
Spectral::Swsh::Tags::Ethbar>,
Spectral::Swsh::Tags::Eth>,
Spectral::Swsh::Tags::Derivative<
::Tags::Multiplies<Tags::BondiJ, Tags::BondiJbar>,
Spectral::Swsh::Tags::EthEthbar>,
Spectral::Swsh::Tags::Derivative<
::Tags::Multiplies<Tags::BondiJ, Tags::BondiJbar>,
Spectral::Swsh::Tags::Eth>,
Spectral::Swsh::Tags::Derivative<Tags::BondiQ, Spectral::Swsh::Tags::Eth>,
Spectral::Swsh::Tags::Derivative<Tags::BondiU, Spectral::Swsh::Tags::Eth>,
Spectral::Swsh::Tags::Derivative<
::Tags::Multiplies<Tags::BondiUbar, Tags::Dy<Tags::BondiJ>>,
Spectral::Swsh::Tags::Eth>,
Spectral::Swsh::Tags::Derivative<Tags::Dy<Tags::BondiJ>,
Spectral::Swsh::Tags::Ethbar>,
Spectral::Swsh::Tags::Derivative<Tags::BondiJ,
Spectral::Swsh::Tags::EthbarEthbar>,
Spectral::Swsh::Tags::Derivative<Tags::BondiJ,
Spectral::Swsh::Tags::Ethbar>,
Spectral::Swsh::Tags::Derivative<
::Tags::Multiplies<Tags::BondiJbar, Tags::Dy<Tags::BondiJ>>,
Spectral::Swsh::Tags::Ethbar>,
Spectral::Swsh::Tags::Derivative<Tags::JbarQMinus2EthBeta,
Spectral::Swsh::Tags::Ethbar>,
Spectral::Swsh::Tags::Derivative<Tags::BondiQ,
Spectral::Swsh::Tags::Ethbar>,
Spectral::Swsh::Tags::Derivative<Tags::BondiU,
Spectral::Swsh::Tags::Ethbar>>;
using integration_independent_tags =
tmpl::list<Tags::DuRDividedByR, Tags::EthRDividedByR, Tags::BondiK,
Tags::OneMinusY, Tags::BondiR>;
using temporary_tags =
tmpl::list<::Tags::SpinWeighted<::Tags::TempScalar<0, ComplexDataVector>,
std::integral_constant<int, 0>>,
::Tags::SpinWeighted<::Tags::TempScalar<1, ComplexDataVector>,
std::integral_constant<int, 0>>,
::Tags::SpinWeighted<::Tags::TempScalar<0, ComplexDataVector>,
std::integral_constant<int, 2>>>;
using return_tags =
tmpl::append<tmpl::list<Tags::RegularIntegrand<Tags::BondiH>>,
temporary_tags>;
using argument_tags =
tmpl::append<pre_swsh_derivative_tags, swsh_derivative_tags,
integration_independent_tags>;
template <typename... Args>
static void apply(
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 2>>*>
regular_integrand_for_h,
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 0>>*>
script_aj,
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 0>>*>
script_bj,
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 2>>*>
script_cj,
const Args&... args) {
apply_impl(make_not_null(&get(*regular_integrand_for_h)),
make_not_null(&get(*script_aj)), make_not_null(&get(*script_bj)),
make_not_null(&get(*script_cj)), get(args)...);
}
private:
static void apply_impl(
gsl::not_null<SpinWeighted<ComplexDataVector, 2>*>
regular_integrand_for_h,
gsl::not_null<SpinWeighted<ComplexDataVector, 0>*> script_aj,
gsl::not_null<SpinWeighted<ComplexDataVector, 0>*> script_bj,
gsl::not_null<SpinWeighted<ComplexDataVector, 2>*> script_cj,
const SpinWeighted<ComplexDataVector, 2>& dy_dy_j,
const SpinWeighted<ComplexDataVector, 2>& dy_j,
const SpinWeighted<ComplexDataVector, 0>& dy_w,
const SpinWeighted<ComplexDataVector, 0>& exp_2_beta,
const SpinWeighted<ComplexDataVector, 2>& j,
const SpinWeighted<ComplexDataVector, 1>& q,
const SpinWeighted<ComplexDataVector, 1>& u,
const SpinWeighted<ComplexDataVector, 0>& w,
const SpinWeighted<ComplexDataVector, 1>& eth_beta,
const SpinWeighted<ComplexDataVector, 2>& eth_eth_beta,
const SpinWeighted<ComplexDataVector, 0>& eth_ethbar_beta,
const SpinWeighted<ComplexDataVector, 2>& eth_ethbar_j,
const SpinWeighted<ComplexDataVector, 0>& eth_ethbar_j_jbar,
const SpinWeighted<ComplexDataVector, 1>& eth_j_jbar,
const SpinWeighted<ComplexDataVector, 2>& eth_q,
const SpinWeighted<ComplexDataVector, 2>& eth_u,
const SpinWeighted<ComplexDataVector, 2>& eth_ubar_dy_j,
const SpinWeighted<ComplexDataVector, 1>& ethbar_dy_j,
const SpinWeighted<ComplexDataVector, 0>& ethbar_ethbar_j,
const SpinWeighted<ComplexDataVector, 1>& ethbar_j,
const SpinWeighted<ComplexDataVector, -1>& ethbar_jbar_dy_j,
const SpinWeighted<ComplexDataVector, -2>& ethbar_jbar_q_minus_2_eth_beta,
const SpinWeighted<ComplexDataVector, 0>& ethbar_q,
const SpinWeighted<ComplexDataVector, 0>& ethbar_u,
const SpinWeighted<ComplexDataVector, 0>& du_r_divided_by_r,
const SpinWeighted<ComplexDataVector, 1>& eth_r_divided_by_r,
const SpinWeighted<ComplexDataVector, 0>& k,
const SpinWeighted<ComplexDataVector, 0>& one_minus_y,
const SpinWeighted<ComplexDataVector, 0>& r);
};
/*!
* \brief Computes the linear factor which multiplies \f$H\f$ in the
* equation which determines the radial (y) dependence of the Bondi quantity
* \f$H\f$.
*
* \details The quantity \f$H \equiv \partial_u J\f$ (evaluated at constant y)
* is defined via the Bondi form of the metric:
* \f[ds^2 = - \left(e^{2 \beta} (1 + r W) - r^2 h_{AB} U^A U^B\right) du^2 - 2
* e^{2 \beta} du dr - 2 r^2 h_{AB} U^B du dx^A + r^2 h_{A B} dx^A dx^B. \f]
* Additional quantities \f$J\f$ and \f$K\f$ are defined using a spherical
* angular dyad \f$q^A\f$:
* \f[ J \equiv h_{A B} q^A q^B, K \equiv h_{A B} q^A \bar{q}^B.\f]
* See \cite Bishop1997ik \cite Handmer2014qha for full details.
*
* We write the equations of motion in the compactified coordinate \f$ y \equiv
* 1 - 2 R/ r\f$, where \f$r(u, \theta, \phi)\f$ is the Bondi radius of the
* \f$y=\f$ constant surface and \f$R(u,\theta,\phi)\f$ is the Bondi radius of
* the worldtube. The equation which determines \f$H\f$ on a surface of constant
* \f$u\f$ given \f$J\f$,\f$\beta\f$, \f$Q\f$, \f$U\f$, and \f$W\f$ on the same
* surface is written as
* \f[(1 - y) \partial_y H + H + (1 - y) J (\mathcal{D}_J
* H + \bar{\mathcal{D}}_J \bar{H}) = A_J + (1 - y) B_J.\f]
* The quantity \f$1 +(1 - y) J \mathcal{D}_J\f$ is the linear factor
* for the non-conjugated \f$H\f$, and is computed from the equation:
* \f[\mathcal{D}_J = \frac{1}{4}(-2 \partial_y \bar{J} + \frac{\bar{J}
* \partial_y (J \bar{J})}{K^2})\f]
*/
template <>
struct ComputeBondiIntegrand<Tags::LinearFactor<Tags::BondiH>> {
public:
using pre_swsh_derivative_tags =
tmpl::list<Tags::Dy<Tags::BondiJ>, Tags::BondiJ>;
using swsh_derivative_tags = tmpl::list<>;
using integration_independent_tags = tmpl::list<Tags::OneMinusY>;
using temporary_tags =
tmpl::list<::Tags::SpinWeighted<::Tags::TempScalar<0, ComplexDataVector>,
std::integral_constant<int, 2>>>;
using return_tags = tmpl::append<tmpl::list<Tags::LinearFactor<Tags::BondiH>>,
temporary_tags>;
using argument_tags =
tmpl::append<pre_swsh_derivative_tags, swsh_derivative_tags,
integration_independent_tags>;
template <typename... Args>
static void apply(
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 0>>*>
linear_factor_for_h,
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 2>>*>
script_djbar,
const Args&... args) {
apply_impl(make_not_null(&get(*linear_factor_for_h)),
make_not_null(&get(*script_djbar)), get(args)...);
}
private:
static void apply_impl(
gsl::not_null<SpinWeighted<ComplexDataVector, 0>*> linear_factor_for_h,
gsl::not_null<SpinWeighted<ComplexDataVector, 2>*> script_djbar,
const SpinWeighted<ComplexDataVector, 2>& dy_j,
const SpinWeighted<ComplexDataVector, 2>& j,
const SpinWeighted<ComplexDataVector, 0>& one_minus_y);
};
/*!
* \brief Computes the linear factor which multiplies \f$\bar{H}\f$ in the
* equation which determines the radial (y) dependence of the Bondi quantity
* \f$H\f$.
*
* \details The quantity \f$H \equiv \partial_u J\f$ (evaluated at constant y)
* is defined via the Bondi form of the metric:
* \f[ds^2 = - \left(e^{2 \beta} (1 + r W) - r^2 h_{AB} U^A U^B\right) du^2 - 2
* e^{2 \beta} du dr - 2 r^2 h_{AB} U^B du dx^A + r^2 h_{A B} dx^A dx^B. \f]
* Additional quantities \f$J\f$ and \f$K\f$ are defined using a spherical
* angular dyad \f$q^A\f$:
* \f[ J \equiv h_{A B} q^A q^B, K \equiv h_{A B} q^A \bar{q}^B.\f]
* See \cite Bishop1997ik \cite Handmer2014qha for full details.
*
* We write the equations of motion in the compactified coordinate \f$ y \equiv
* 1 - 2 R/ r\f$, where \f$r(u, \theta, \phi)\f$ is the Bondi radius of the
* \f$y=\f$ constant surface and \f$R(u,\theta,\phi)\f$ is the Bondi radius of
* the worldtube. The equation which determines \f$H\f$ on a surface of constant
* \f$u\f$ given \f$J\f$,\f$\beta\f$, \f$Q\f$, \f$U\f$, and \f$W\f$ on the same
* surface is written as
* \f[(1 - y) \partial_y H + H + (1 - y) J (\mathcal{D}_J H +
* \bar{\mathcal{D}}_J \bar{H}) = A_J + (1 - y) B_J.\f]
* The quantity \f$ (1 - y) J \bar{\mathcal{D}}_J\f$ is the linear factor
* for the non-conjugated \f$H\f$, and is computed from the equation:
* \f[\mathcal{D}_J = \frac{1}{4}(-2 \partial_y \bar{J} + \frac{\bar{J}
* \partial_y (J \bar{J})}{K^2})\f]
*/
template <>
struct ComputeBondiIntegrand<Tags::LinearFactorForConjugate<Tags::BondiH>> {
public:
using pre_swsh_derivative_tags =
tmpl::list<Tags::Dy<Tags::BondiJ>, Tags::BondiJ>;
using swsh_derivative_tags = tmpl::list<>;
using integration_independent_tags = tmpl::list<Tags::OneMinusY>;
using temporary_tags =
tmpl::list<::Tags::SpinWeighted<::Tags::TempScalar<0, ComplexDataVector>,
std::integral_constant<int, 2>>>;
using return_tags =
tmpl::append<tmpl::list<Tags::LinearFactorForConjugate<Tags::BondiH>>,
temporary_tags>;
using argument_tags =
tmpl::append<pre_swsh_derivative_tags, swsh_derivative_tags,
integration_independent_tags>;
template <typename... Args>
static void apply(
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 4>>*>
linear_factor_for_conjugate_h,
const gsl::not_null<Scalar<SpinWeighted<ComplexDataVector, 2>>*>
script_djbar,
const Args&... args) {
apply_impl(make_not_null(&get(*linear_factor_for_conjugate_h)),
make_not_null(&get(*script_djbar)), get(args)...);
}
private:
static void apply_impl(
gsl::not_null<SpinWeighted<ComplexDataVector, 4>*>
linear_factor_for_conjugate_h,
gsl::not_null<SpinWeighted<ComplexDataVector, 2>*> script_djbar,
const SpinWeighted<ComplexDataVector, 2>& dy_j,
const SpinWeighted<ComplexDataVector, 2>& j,
const SpinWeighted<ComplexDataVector, 0>& one_minus_y);
};
} // namespace Cce
| 47.76698
| 80
| 0.639971
|
nilsvu
|
9568f543c00f7e126effa3d20b3329e154886c2e
| 575
|
cpp
|
C++
|
src/BaseTools/Chombo_Interval.cpp
|
novertonCSU/Chombo_4
|
b833e49793758a7d6d22f976694c9d2e90d29c00
|
[
"BSD-3-Clause-LBNL"
] | 11
|
2019-06-08T01:20:51.000Z
|
2021-12-21T12:18:54.000Z
|
src/BaseTools/Chombo_Interval.cpp
|
novertonCSU/Chombo_4
|
b833e49793758a7d6d22f976694c9d2e90d29c00
|
[
"BSD-3-Clause-LBNL"
] | 3
|
2020-03-13T06:25:55.000Z
|
2021-06-23T18:12:53.000Z
|
src/BaseTools/Chombo_Interval.cpp
|
novertonCSU/Chombo_4
|
b833e49793758a7d6d22f976694c9d2e90d29c00
|
[
"BSD-3-Clause-LBNL"
] | 4
|
2019-08-27T14:34:34.000Z
|
2021-10-04T21:46:59.000Z
|
#ifdef CH_LANG_CC
/*
* _______ __
* / ___/ / ___ __ _ / / ___
* / /__/ _ \/ _ \/ V \/ _ \/ _ \
* \___/_//_/\___/_/_/_/_.__/\___/
* Please refer to Copyright.txt, in Chombo's root directory.
*/
#endif
#include <cstdlib>
#include <iostream>
#include "Chombo_Interval.H"
#include "Chombo_parstream.H"
#include "Chombo_BaseNamespaceHeader.H"
std::ostream&
operator<< (std::ostream& os, const Interval& dit)
{
os << " (" << dit.m_begin << "," << dit.m_end << ") " ;
return os;
}
#include "Chombo_BaseNamespaceFooter.H"
| 23.958333
| 64
| 0.573913
|
novertonCSU
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.