blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
2
247
content_id
stringlengths
40
40
detected_licenses
listlengths
0
57
license_type
stringclasses
2 values
repo_name
stringlengths
4
111
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringlengths
4
58
visit_date
timestamp[ns]date
2015-07-25 18:16:41
2023-09-06 10:45:08
revision_date
timestamp[ns]date
1970-01-14 14:03:36
2023-09-06 06:22:19
committer_date
timestamp[ns]date
1970-01-14 14:03:36
2023-09-06 06:22:19
github_id
int64
3.89k
689M
star_events_count
int64
0
209k
fork_events_count
int64
0
110k
gha_license_id
stringclasses
25 values
gha_event_created_at
timestamp[ns]date
2012-06-07 00:51:45
2023-09-14 21:58:52
gha_created_at
timestamp[ns]date
2008-03-27 23:40:48
2023-08-24 19:49:39
gha_language
stringclasses
159 values
src_encoding
stringclasses
34 values
language
stringclasses
1 value
is_vendor
bool
1 class
is_generated
bool
2 classes
length_bytes
int64
7
10.5M
extension
stringclasses
111 values
filename
stringlengths
1
195
text
stringlengths
7
10.5M
4985409388a19c19a5b305455c4721e422144505
fa1b082268e8f6d7db795d856f5bd852329069b9
/src/zstd.cc
b8a0c4a1c45e214be06f4c743835a4285d905f32
[]
no_license
tkuminecz/node-zstandard
77b817bca3808d94cd39cb97e7db2d27ca087cdd
69dbaec2c4a7a9a41883ecaa4e795d7ea313b4a8
refs/heads/master
2020-09-18T21:18:30.741309
2016-09-02T17:29:34
2016-09-02T17:29:34
67,178,637
5
0
null
null
null
null
UTF-8
C++
false
false
3,524
cc
zstd.cc
#include <cstdlib> #include <node.h> #include <node_buffer.h> extern "C" { #include "zstd.h" } #define ZSTDJS_BLOCK_SIZE 128 * (1U<<10) //128 KB #define throwError(i,type,msg) (i->ThrowException(type( String::NewFromUtf8(i, msg) ))) const int compLevel = 3; namespace zstandard { using v8::Exception; using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; using v8::MaybeLocal; using v8::Object; using v8::String; using v8::Value; /** * Converts node buffer to char* */ char * fromNodeBuffer(Local<Object> buf, size_t &len) { len = node::Buffer::Length(buf); return node::Buffer::Data(buf); } /** * Converts char* to node buffer */ Local<Object> toNodeBuffer(Isolate *isolate, char *data, size_t len) { MaybeLocal<Object> result = node::Buffer::New(isolate, data, len); return result.ToLocalChecked(); } /** * Compresses data */ void Compress(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); // validate args if (args.Length() < 1 || !node::Buffer::HasInstance(args[0])) { throwError(isolate, Exception::TypeError, "Expected first argument to be a buffer"); return; } // convert node buffer Local<Object> srcBuffer = args[0]->ToObject(); size_t srcSize; char *srcData = fromNodeBuffer(srcBuffer, srcSize); // allocate memory for compressed data size_t maxCompressedSize = ZSTD_compressBound(srcSize); char *compressedData = (char *)std::malloc(maxCompressedSize); if (!compressedData) { throwError(isolate, Exception::Error, "Not enough memory"); return; } // actually compress the data size_t actualCompressedSize = ZSTD_compress(compressedData, maxCompressedSize, srcData, srcSize, compLevel); if (ZSTD_isError(actualCompressedSize)) { throwError(isolate, Exception::Error, "Error compressing data"); return; } // return as a node buffer args.GetReturnValue().Set(toNodeBuffer(isolate, compressedData, actualCompressedSize)); } /** * Decompresses data */ void Decompress(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); // validate args if (args.Length() < 1 || !node::Buffer::HasInstance(args[0])) { throwError(isolate, Exception::TypeError, "Expected first argument to be a buffer"); return; } // convert node buffer Local<Object> srcBuffer = args[0]->ToObject(); size_t srcSize; char *srcData = fromNodeBuffer(srcBuffer, srcSize); // allocate memory for decompressed data size_t maxDecompressedSize = ZSTD_getDecompressedSize(srcData, srcSize); char *decompressedData = (char *)std::malloc(maxDecompressedSize); if (!decompressedData) { throwError(isolate, Exception::Error, "Not enough memory"); return; } // actually compress the data size_t actualDecompressedSize = ZSTD_decompress(decompressedData, maxDecompressedSize, srcData, srcSize); if (actualDecompressedSize != maxDecompressedSize) { throwError(isolate, Exception::Error, "Error decompressing data"); return; } // return as a node buffer args.GetReturnValue().Set(toNodeBuffer(isolate, decompressedData, actualDecompressedSize)); } /** * Initialize the module */ void init(Local<Object> exports) { NODE_SET_METHOD(exports, "compress", Compress); NODE_SET_METHOD(exports, "decompress", Decompress); } NODE_MODULE(zstandard, init); }
82d9d0ae123432d0959c412659c6363c0553c6d8
a6a395070e8f5b415ff76267b5a2e8057b6cb4d8
/inc/Engine.h
809ec37306bfe5abb2e4f23cbda3f3d037590252
[]
no_license
manjot-b/cpsc587-asgn4
463f029987f2a4ac9da7a14c91a11965f579f1f4
5a831a08a8e2e4b3803d91aece911677efa8f7e4
refs/heads/master
2020-03-08T12:46:31.138534
2018-04-08T05:07:08
2018-04-08T05:07:08
128,136,460
0
0
null
null
null
null
UTF-8
C++
false
false
1,860
h
Engine.h
#pragma once #define GLFW_INCLUDE_NONE #include <GLFW/glfw3.h> #include <glm/glm.hpp> #include <memory> #include <vector> #include "Spring.h" #include "Shader.h" #include "VertexArray.h" #include "Camera.h" #include "TriangleMesh.h" #include "Boid.h" struct Cage { glm::vec3 origin = glm::vec3(-0.2f, -0.1f, 0.1f); glm::vec3 dimension = glm::vec3(0.4f, 0.27f, 0.4f); }; class Engine { public: Engine(int argc, const char* argv[]); int run(); private: struct DestroyglfwWin { void operator()(GLFWwindow* ptr) { glfwDestroyWindow(ptr); } }; typedef std::unique_ptr<GLFWwindow, DestroyglfwWin> GLFWwindowPtr; GLFWwindowPtr window_; bool windowInitialized_; std::shared_ptr<Shader> shader; std::shared_ptr<Shader> simpleShader; std::shared_ptr<VertexArray> vertexArray; std::shared_ptr<VertexArray> boxVertexArray; Camera camera; std::shared_ptr<TriangleMesh> fishMesh; std::vector<glm::mat4> modelMatrices; GLuint instanceVBO; std::vector<Boid> boids; uint bodyCount = 2000; uint neighbours = 20; float modelScale; struct Cage cage; float avoidance = 0.065; float cohesion = 0.12; float gather = 0.15; float maxSpeed = 0.15; const float EPSILON = 1E-5; float deltaT = 0.008; // in miliseconds uint updatesPerFrame = (1.0f / 60) / deltaT; glm::vec3 gravityForce = glm::vec3(0, -9.81f, 0); bool initWindow(); void initScene(); void processInput(); void update(); void render(); void checkCollisions(Boid& boid, uint boidIdx); void parseInputFile(); };
e7599c3a8c692deb3fff35aaa4e909d50fe958ef
16e9d2211de25e5aafc8f90280758df4368c0376
/REVISED Card.cpp
e4b291eead7adf94e35c0ad315fed39278fc4fc3
[]
no_license
scienceiscool/PlayingCards
87250f86016231ff8fcd55c344c4ab24b6f48a7f
7525b03fae03170a12b57ba31cc15ca66be422cb
refs/heads/master
2021-01-02T22:38:18.128026
2015-03-23T20:01:36
2015-03-23T20:01:36
18,344,328
0
0
null
null
null
null
UTF-8
C++
false
false
1,998
cpp
REVISED Card.cpp
//Kathy Saad //CPSC 131 - Section 01 //Assignment 02 - Playing Card //March 5, 2013 //REVISED #include "REVISED Card.h" int Card::getRank (int Rank) { rank = Rank; return Rank; } Card::Card(void) { rank = 1; suit = CLUB; } Card::Card(int initRank, Suits initSuit) { rank = initRank; suit = initSuit; } int Card::GetRank() const { return rank; } Suits Card::GetSuit() const { return suit; } bool Card::operator < (Card other) const { if (suit < other.suit) { return true; } else if (suit > other.suit) { return false; } else if (rank < other.rank) { return true; } else if (rank > other.rank) { return false; } else { return false; } } bool Card::operator > (Card other) const { if (suit > other.suit) { return true; } else if (suit < other.suit) { return false; } else if (rank > other.rank) { return true; } else if (rank < other.rank) { return false; } else { return false; } } bool Card::operator == (Card other) const { if (suit == other.suit && rank == other.rank) { return true; } else { return false; } } RelationType Card::ComparedTo(const Card * someCard) //Returns relative position of self to someCard { if (suit < someCard->suit) return LESS; else if (suit > someCard->suit) return GREATER; else if (rank == someCard->rank) return EQUAL; else if (rank == 1) return GREATER; else if (someCard->rank == 1) return LESS; else if (rank < someCard->rank) return LESS; else if (rank > someCard->rank) return GREATER; } std::string Card::PrintString() const { std::string convertRank[13] = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"}; std::string convertSuit[4] = {"Clubs", "Diamonds", "Hearts", "Spades"}; std::string printString = convertRank[rank - 1] + " of " + convertSuit[suit]; return printString; }
217e291fe89e3d07a715b07bf9fa6bb90b9ce8e1
464d6cb42fb8981595cbf7260069cd1e6a67fe2f
/Binary Search/Tricky and Important Binary Search/Search in a Sorted Array of Unknown Size.cpp
feab04980faa21090d2bebc37113147f7220ef45
[]
no_license
rahul799/leetcode_problems
fd42276f85dc881b869072b74654f5811c6618ea
cc7f086eb9ac9bbd20ea004c46d89aa84df10d36
refs/heads/main
2023-04-14T05:09:31.016878
2021-04-20T19:46:52
2021-04-20T19:46:52
359,933,382
2
0
null
null
null
null
UTF-8
C++
false
false
1,592
cpp
Search in a Sorted Array of Unknown Size.cpp
702. Search in a Sorted Array of Unknown Size Medium Given an integer array sorted in ascending order, write a function to search target in nums. If target exists, then return its index, otherwise return -1. However, the array size is unknown to you. You may only access the array using an ArrayReader interface, where ArrayReader.get(k) returns the element of the array at index k (0-indexed). You may assume all integers in the array are less than 10000, and if you access the array out of bounds, ArrayReader.get will return 2147483647. Example 1: Input: array = [-1,0,3,5,9,12], target = 9 Output: 4 Explanation: 9 exists in nums and its index is 4 Example 2: Input: array = [-1,0,3,5,9,12], target = 2 Output: -1 Explanation: 2 does not exist in nums so return -1 Constraints: You may assume that all elements in the array are unique. The value of each element in the array will be in the range [-9999, 9999]. The length of the array will be in the range [1, 10^4]. class ArrayReader; class Solution { public: int search(const ArrayReader& reader, int target) { if(reader.get(0)==target) return 0; int k=1; while(reader.get(k)<target){ k = k*2; } int low = k/2, high=k; while(low<=high) { int mid = low + (high-low)/2; if(reader.get(mid)==target) return mid; else if(reader.get(mid) < target) low = mid + 1; else high = mid - 1; } return -1; } };
d34ef69eef942b7a075dfb119e558eb71b177d88
51003f6af36ce7adaa753eb910d1bc33354be26a
/picture.cpp
bda2917cc82f66f70bbc03b90d69bba32ae2ee9f
[]
no_license
bluegr/scummvm-picture
c58d45273180b593980fbcd04d6856e5f105e3ce
3b73be498868b2983a7387c04a51a9b2c4feda2b
refs/heads/master
2020-05-17T17:14:31.683213
2011-11-03T21:30:54
2011-11-03T21:30:54
2,769,341
0
0
null
null
null
null
UTF-8
C++
false
false
15,773
cpp
picture.cpp
/* ScummVM - Graphic Adventure Engine * * ScummVM is the legal property of its developers, whose names * are too numerous to list here. Please refer to the COPYRIGHT * file distributed with this source distribution. * * 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 * of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * $URL$ * $Id$ * */ #include "common/config-manager.h" #include "common/events.h" #include "common/random.h" #include "common/str.h" #include "common/error.h" #include "common/textconsole.h" #include "base/plugins.h" #include "base/version.h" #include "graphics/cursorman.h" #include "engines/util.h" #include "audio/mixer.h" #include "picture/picture.h" #include "picture/animation.h" #include "picture/menu.h" #include "picture/movie.h" #include "picture/music.h" #include "picture/palette.h" #include "picture/render.h" #include "picture/resource.h" #include "picture/script.h" #include "picture/screen.h" #include "picture/segmap.h" #include "picture/sound.h" #include "picture/microtiles.h" namespace Picture { struct GameSettings { const char *gameid; const char *description; byte id; uint32 features; const char *detectname; }; PictureEngine::PictureEngine(OSystem *syst, const PictureGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) { // Setup mixer _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume")); _rnd = new Common::RandomSource("picture"); } PictureEngine::~PictureEngine() { delete _rnd; } void PictureEngine::syncSoundSettings() { /* _music->setVolume(ConfMan.getInt("music_volume")); _mixer->setVolumeForSoundType(Audio::Mixer::kPlainSoundType, ConfMan.getInt("sfx_volume")); _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume")); _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume")); */ } Common::Error PictureEngine::run() { initGraphics(640, 400, true); _isSaveAllowed = true; _counter01 = 0; _counter02 = 0; _movieSceneFlag = false; _flag01 = 0; _saveLoadRequested = 0; _cameraX = 0; _cameraY = 0; _newCameraX = 0; _newCameraY = 0; _cameraHeight = 0; _guiHeight = 26; _sceneWidth = 0; _sceneHeight = 0; _doSpeech = true; _doText = true; _walkSpeedY = 5; _walkSpeedX = 1; _mouseX = 0; _mouseY = 0; _mouseDblClickTicks = 60; _mouseWaitForRelease = false; _mouseButton = 0; _mouseDisabled = 0; _leftButtonDown = false; _rightButtonDown = false; _arc = new ArchiveReader(); _arc->openArchive("WESTERN"); _res = new ResourceCache(this); _screen = new Screen(this); _script = new ScriptInterpreter(this); _anim = new AnimationPlayer(this); _palette = new Palette(this); _segmap = new SegmentMap(this); _moviePlayer = new MoviePlayer(this); _musicPlayer = new MusicPlayer(); _menuSystem = new MenuSystem(this); _sound = new Sound(this); syncSoundSettings(); CursorMan.showMouse(true); setupSysStrings(); //#define TEST_MENU #ifdef TEST_MENU _screen->registerFont(0, 0x0D); _screen->registerFont(1, 0x0E); _screen->loadMouseCursor(12); _palette->loadAddPalette(9, 224); _palette->setDeltaPalette(_palette->getMainPalette(), 7, 0, 31, 224); _screen->finishTalkTextItems(); _screen->clearSprites(); _menuSystem->run(); /* while (1) { //updateInput(); _menuSystem->update(); updateScreen(); } */ return Common::kNoError; #endif // Start main game loop _script->loadScript(0, 0); _script->setMainScript(0); if (ConfMan.hasKey("save_slot")) { int saveSlot = ConfMan.getInt("save_slot"); if (saveSlot >= 0 && saveSlot <= 99) { _screen->loadMouseCursor(12); loadGameState(saveSlot); } } _script->runScript(); _musicPlayer->stopAndClear(); _sound->stopAll(); delete _arc; delete _res; delete _screen; delete _script; delete _anim; delete _palette; delete _segmap; delete _musicPlayer; delete _moviePlayer; delete _menuSystem; delete _sound; return Common::kNoError; } void PictureEngine::setupSysStrings() { Resource *sysStringsResource = _res->load(15); const char *sysStrings = (const char*)sysStringsResource->data; for (int i = 0; i < kSysStrCount; i++) { debug(1, "sysStrings[%d] = [%s]", i, sysStrings); _sysStrings[i] = sysStrings; sysStrings += strlen(sysStrings) + 1; } // TODO: Set yes/no chars } void PictureEngine::requestSavegame(int slotNum, Common::String &description) { _saveLoadRequested = 2; _saveLoadSlot = slotNum; _saveLoadDescription = description; } void PictureEngine::requestLoadgame(int slotNum) { _saveLoadRequested = 1; _saveLoadSlot = slotNum; } void PictureEngine::loadScene(uint resIndex) { Resource *sceneResource = _res->load(resIndex); byte *scene = sceneResource->data; uint32 imageSize = READ_LE_UINT32(scene); _sceneResIndex = resIndex; _sceneHeight = READ_LE_UINT16(scene + 4); _sceneWidth = READ_LE_UINT16(scene + 6); // Load scene palette _palette->loadAddPaletteFrom(scene + 8, 0, 128); // Load scene background byte *source = scene + 392; byte *destp = _screen->_backScreen; byte *destEnd = destp + _sceneWidth * _sceneHeight; while (destp < destEnd) { int count = 1; byte pixel = *source++; if (pixel & 0x80) { pixel &= 0x7F; count = *source++; count += 2; } memset(destp, pixel, count); destp += count; } debug(0, "_sceneWidth = %d; _sceneHeight = %d", _sceneWidth, _sceneHeight); // Load scene segmap _segmap->load(scene + imageSize + 4); _screen->_fullRefresh = true; _screen->_renderQueue->clear(); } void PictureEngine::updateScreen() { _sound->updateSpeech(); _screen->updateShakeScreen(); // TODO: Set quit flag if (shouldQuit()) return; if (!_movieSceneFlag) updateInput(); else _mouseButton = 0; // TODO? Check keyb _counter01--; if (_counter01 <= 0) { _counter01 = MIN(_counter02, 30); _counter02 = 0; drawScreen(); _flag01 = 1; _counter02 = 1; } else { _screen->clearSprites(); _flag01 = 0; } static uint32 prevUpdateTime = 0; uint32 currUpdateTime; do { currUpdateTime = _system->getMillis(); _counter02 = (currUpdateTime - prevUpdateTime) / 13; } while (_counter02 == 0); prevUpdateTime = currUpdateTime; } void PictureEngine::drawScreen() { // FIXME: Quick hack, sometimes cameraY was negative (the code in updateCamera was at fault) if (_cameraY < 0) _cameraY = 0; _segmap->addMasksToRenderQueue(); _screen->addTalkTextItemsToRenderQueue(); _screen->_renderQueue->update(); //debug("_guiHeight = %d\n", _guiHeight); if (_screen->_guiRefresh && _guiHeight > 0 && _cameraHeight > 0) { // Update the GUI when needed and it's visible _system->copyRectToScreen((const byte *)_screen->_frontScreen + _cameraHeight * 640, 640, 0, _cameraHeight, 640, _guiHeight); _screen->_guiRefresh = false; } _system->updateScreen(); updateCamera(); } void PictureEngine::updateInput() { Common::Event event; Common::EventManager *eventMan = _system->getEventManager(); while (eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_KEYDOWN: _keyState = event.kbd; //debug("key: flags = %02X; keycode = %d", _keyState.flags, _keyState.keycode); // FIXME: This is just for debugging switch (event.kbd.keycode) { case Common::KEYCODE_F7: savegame("toltecs.001", "Quicksave"); break; case Common::KEYCODE_F9: loadgame("toltecs.001"); break; case Common::KEYCODE_ESCAPE: // Skip current dialog line, if a dialog is active if (_screen->getTalkTextDuration() > 0) { _sound->stopSpeech(); _screen->finishTalkTextItems(); _keyState.reset(); // event consumed } break; default: break; } break; case Common::EVENT_KEYUP: _keyState.reset(); break; case Common::EVENT_QUIT: quitGame(); break; case Common::EVENT_MOUSEMOVE: _mouseX = event.mouse.x; _mouseY = event.mouse.y; break; case Common::EVENT_LBUTTONDOWN: _mouseX = event.mouse.x; _mouseY = event.mouse.y; _leftButtonDown = true; break; case Common::EVENT_LBUTTONUP: _mouseX = event.mouse.x; _mouseY = event.mouse.y; _leftButtonDown = false; break; case Common::EVENT_RBUTTONDOWN: _mouseX = event.mouse.x; _mouseY = event.mouse.y; _rightButtonDown = true; break; case Common::EVENT_RBUTTONUP: _mouseX = event.mouse.x; _mouseY = event.mouse.y; _rightButtonDown = false; break; default: break; } } if (!_mouseDisabled) { if (_mouseDblClickTicks > 0) _mouseDblClickTicks--; byte mouseButtons = 0; if (_leftButtonDown) mouseButtons |= 1; if (_rightButtonDown) mouseButtons |= 2; if (mouseButtons != 0) { if (!_mouseWaitForRelease) { _mouseButton = mouseButtons; if (_mouseDblClickTicks > 0) _mouseButton = 0x80; //if (_mouseButton == 0x80) debug("DBL!"); _mouseDblClickTicks = 30; // maybe TODO _mouseWaitForRelease = true; } else { _mouseButton = 0; } } else { _mouseWaitForRelease = false; _mouseButton = 0; } } } void PictureEngine::setGuiHeight(int16 guiHeight) { if (guiHeight != _guiHeight) { _guiHeight = guiHeight; _cameraHeight = 400 - _guiHeight; _screen->_guiRefresh = true; debug(0, "PictureEngine::setGuiHeight() _guiHeight = %d; _cameraHeight = %d", _guiHeight, _cameraHeight); // TODO: clearScreen(); } } void PictureEngine::setCamera(int16 x, int16 y) { _screen->finishTalkTextItems(); _screen->clearSprites(); _cameraX = x; _newCameraX = x; _cameraY = y; _newCameraY = y; } bool PictureEngine::getCameraChanged() { return _cameraX != _newCameraX || _cameraY != _newCameraY; } void PictureEngine::scrollCameraUp(int16 delta) { if (_newCameraY > 0) { if (_newCameraY < delta) _newCameraY = 0; else _newCameraY -= delta; } } void PictureEngine::scrollCameraDown(int16 delta) { debug(0, "PictureEngine::scrollCameraDown(%d)", delta); if (_newCameraY != _sceneHeight - _cameraHeight) { if (_sceneHeight - _cameraHeight < _newCameraY + delta) delta += (_sceneHeight - _cameraHeight) - (delta + _newCameraY); _newCameraY += delta; debug(0, "PictureEngine::scrollCameraDown() _newCameraY = %d; delta = %d", _newCameraY, delta); } } void PictureEngine::scrollCameraLeft(int16 delta) { if (_newCameraX > 0) { if (_newCameraX < delta) _newCameraX = 0; else _newCameraX -= delta; } } void PictureEngine::scrollCameraRight(int16 delta) { debug(0, "PictureEngine::scrollCameraRight(%d)", delta); if (_newCameraX != _sceneWidth - 640) { if (_sceneWidth - 640 < delta + _newCameraX) delta += (_sceneWidth - 640) - (delta + _newCameraX); _newCameraX += delta; debug(0, "PictureEngine::scrollCameraRight() _newCameraX = %d; delta = %d", _newCameraY, delta); } } void PictureEngine::updateCamera() { if (_cameraX != _newCameraX) { _cameraX = _newCameraX; _screen->_fullRefresh = true; _screen->finishTalkTextItems(); } if (_cameraY != _newCameraY) { _cameraY = _newCameraY; _screen->_fullRefresh = true; _screen->finishTalkTextItems(); } //debug(0, "PictureEngine::updateCamera() _cameraX = %d; _cameraY = %d", _cameraX, _cameraY); } void PictureEngine::talk(int16 slotIndex, int16 slotOffset) { byte *scanData = _script->getSlotData(slotIndex) + slotOffset; while (*scanData < 0xF0) { if (*scanData == 0x19) { scanData++; } else if (*scanData == 0x14) { scanData++; } else if (*scanData == 0x0A) { scanData += 4; } else if (*scanData < 0x0A) { scanData++; } scanData++; } if (*scanData == 0xFE) { if (_doSpeech) { int16 resIndex = READ_LE_UINT16(scanData + 1); debug(0, "PictureEngine::talk() playSound(resIndex: %d)", resIndex); _sound->playSpeech(resIndex); } if (_doText) { _screen->updateTalkText(slotIndex, slotOffset); } else { _screen->keepTalkTextItemsAlive(); } } else { _screen->updateTalkText(slotIndex, slotOffset); } } void PictureEngine::walk(byte *walkData) { int16 xdelta, ydelta, v8, v10, v11; int16 xstep, ystep; ScriptWalk walkInfo; walkInfo.y = READ_LE_UINT16(walkData + 0); walkInfo.x = READ_LE_UINT16(walkData + 2); walkInfo.y1 = READ_LE_UINT16(walkData + 4); walkInfo.x1 = READ_LE_UINT16(walkData + 6); walkInfo.y2 = READ_LE_UINT16(walkData + 8); walkInfo.x2 = READ_LE_UINT16(walkData + 10); walkInfo.yerror = READ_LE_UINT16(walkData + 12); walkInfo.xerror = READ_LE_UINT16(walkData + 14); walkInfo.mulValue = READ_LE_UINT16(walkData + 16); walkInfo.scaling = READ_LE_UINT16(walkData + 18); walkInfo.scaling = -_segmap->getScalingAtPoint(walkInfo.x, walkInfo.y); if (walkInfo.y1 < walkInfo.y2) ystep = -1; else ystep = 1; ydelta = ABS(walkInfo.y1 - walkInfo.y2) * _walkSpeedY; if (walkInfo.x1 < walkInfo.x2) xstep = -1; else xstep = 1; xdelta = ABS(walkInfo.x1 - walkInfo.x2) * _walkSpeedX; debug(0, "PictureEngine::walk() xdelta = %d; ydelta = %d", xdelta, ydelta); if (xdelta > ydelta) SWAP(xdelta, ydelta); v8 = 100 * xdelta; if (v8 != 0) { if (walkInfo.scaling > 0) v8 -= v8 * ABS(walkInfo.scaling) / 100; else v8 += v8 * ABS(walkInfo.scaling) / 100; if (ydelta != 0) v8 /= ydelta; } if (ydelta > ABS(walkInfo.x1 - walkInfo.x2) * _walkSpeedX) { v10 = 100 - walkInfo.scaling; v11 = v8; } else { v10 = v8; v11 = 100 - walkInfo.scaling; } walkInfo.yerror += walkInfo.mulValue * v10; while (walkInfo.yerror >= 100 * _walkSpeedY) { walkInfo.yerror -= 100 * _walkSpeedY; if (walkInfo.y == walkInfo.y1) { walkInfo.x = walkInfo.x1; break; } walkInfo.y += ystep; } walkInfo.xerror += walkInfo.mulValue * v11; while (walkInfo.xerror >= 100 * _walkSpeedX) { walkInfo.xerror -= 100 * _walkSpeedX; if (walkInfo.x == walkInfo.x1) { walkInfo.y = walkInfo.y1; break; } walkInfo.x += xstep; } WRITE_LE_UINT16(walkData + 0, walkInfo.y); WRITE_LE_UINT16(walkData + 2, walkInfo.x); WRITE_LE_UINT16(walkData + 4, walkInfo.y1); WRITE_LE_UINT16(walkData + 6, walkInfo.x1); WRITE_LE_UINT16(walkData + 8, walkInfo.y2); WRITE_LE_UINT16(walkData + 10, walkInfo.x2); WRITE_LE_UINT16(walkData + 12, walkInfo.yerror); WRITE_LE_UINT16(walkData + 14, walkInfo.xerror); WRITE_LE_UINT16(walkData + 16, walkInfo.mulValue); WRITE_LE_UINT16(walkData + 18, walkInfo.scaling); } int16 PictureEngine::findRectAtPoint(byte *rectData, int16 x, int16 y, int16 index, int16 itemSize, byte *rectDataEnd) { rectData += index * itemSize; while (rectData < rectDataEnd) { int16 rectY = READ_LE_UINT16(rectData); if (rectY == -10) break; int16 rectX = READ_LE_UINT16(rectData + 2); int16 rectH = READ_LE_UINT16(rectData + 4); int16 rectW = READ_LE_UINT16(rectData + 6); debug(0, "x = %d; y = %d; x1 = %d; y2 = %d; w = %d; h = %d", x, y, rectX, rectY, rectW, rectH); if (x >= rectX && x <= rectX + rectW && y >= rectY && y <= rectY + rectH) { return index; } index++; rectData += itemSize; } return -1; } } // End of namespace Picture
614e745e04b61a4855a644f5b89d3877a200c593
fa82f81ee373fe417af217bc24e27333bfd34484
/src/image_subscriber.cpp
23478b47222758ae2c36440b0a8f3ceb9ac06565
[]
no_license
QianYC/calculation_node
ada201e8415b1ef97516b9f6d4416a24142fbdc5
ecbbd60b0ef7057116176f4efac1905e76e42f28
refs/heads/master
2021-01-25T22:28:47.725608
2020-05-31T09:12:38
2020-05-31T09:12:38
243,206,949
0
0
null
2020-06-06T09:38:18
2020-02-26T08:17:03
C++
UTF-8
C++
false
false
6,048
cpp
image_subscriber.cpp
// // Created by yc_qian on 20-2-6. // #include "photoComposer.hpp" ThreadPool pool(1); STATE state = STATIC, last_state; MOTION motion = STOP; bool change_state = false; cv::Mat image; vector<FaceInfo> faces; DETECT_RESULT detect_result = NO_FACE; COMPOSE_RESULT compose_result, dynamic_compose_result; CHECK_ERROR_RESULT error_result; //failure time in adjusting position int adjust_fail = 0; ros::Subscriber image_subscriber; ros::ServiceServer state_server; ros::ServiceClient camera_client; MotionPublisher motion_publisher; void (*shutdown_sub)(); void (*start_sub)(); void sleep(int millisec) { pool.submit([shutdown_sub = shutdown_sub, start_sub = start_sub, millisec] { ROS_INFO("shutdown image subscriber"); shutdown_sub(); std::this_thread::sleep_for(std::chrono::milliseconds(millisec)); ROS_INFO("start image subscriber"); start_sub(); }); } void subscribe_callback(const sensor_msgs::CompressedImage::ConstPtr &msg) { //读取一帧画面 cv::Mat image = cv::imdecode(msg->data, CV_LOAD_IMAGE_COLOR); switch (state) { //摆拍模式 case STATIC: if (change_state) { state = DYNAMIC; change_state = false; break; } //目标检测 faces = object_detect(image, detect_result); if (detect_result == HAVE_FACE) { state = S_OBJECT_SELECTED; } else { last_state = STATIC; state = ROAMING; } break; //目标已确定1 case S_OBJECT_SELECTED: /** * 进行构图 */ compose_result = calculate_expected_position(faces); state = S_COMPOSITION_SELECTED; break; //构图已确定 case S_COMPOSITION_SELECTED: /** * 计算拍摄目标与期望位置的差距 * * 出错5次以上,重新返回摆拍阶段 */ error_result = calculate_error(compose_result, image); if (!error_result.success) { if (adjust_fail == 5) { adjust_fail = 0; state = STATIC; } else { adjust_fail++; } break; } else if (error_result.direction == STOP) { state = S_POSITION_ADJUSTED; break; } else { if (adjust_fail == 5) { adjust_fail = 0; state = STATIC; } else { adjust_fail++; state = S_ADJUSTING; } break; } //调整位置中 case S_ADJUSTING: /** * 发送运动指令给控制端 */ printf("moving %d\n", error_result.direction); motion_publisher.move(error_result.direction); state = S_COMPOSITION_SELECTED; break; //位置已调整 case S_POSITION_ADJUSTED: ROS_INFO("S_POSITION_ADJUSTED"); motion_publisher.move(STOP); sleep(100); //拍照 take_photo(camera_client, compose_result); sleep(3000); state = STATIC; break; //漫游模式 case ROAMING: ROS_INFO("ROAMING"); if (detect_result == FACE_TOO_SMALL) { motion = FORWARD; ROS_INFO("face too small, moving forward"); } else { motion = (MOTION) cv::theRNG().uniform(FORWARD, RIGHT + 1); ROS_INFO("moving direction : %d", motion); } motion_publisher.move_for(motion, 1000); state = last_state; break; //抓拍模式 case DYNAMIC: ROS_INFO("DYNAMIC"); if (change_state) { state = STATIC; change_state = false; break; } faces = object_detect(image, detect_result); if (detect_result == HAVE_FACE) { state = D_OBJECT_SELECTED; break; } else { state = ROAMING; last_state = DYNAMIC; break; } //目标已确定2 case D_OBJECT_SELECTED: ROS_INFO("D_OBJECT_SELECTED"); sleep(100); dynamic_compose_result = dynamic_get_target(faces); take_photo(camera_client, dynamic_compose_result); sleep(1000); state = ROAMING; last_state = DYNAMIC; break; } } bool service_change_state(pi_robot::SrvTriggerRequest &request, pi_robot::SrvTriggerResponse &response) { // ROS_INFO("change state server thread id : %d", this_thread::get_id()); if ((request.state && (state == DYNAMIC || state == D_OBJECT_SELECTED || (state == ROAMING && last_state == DYNAMIC))) || (!request.state && (state < DYNAMIC || (state == ROAMING && last_state == STATIC)))) { change_state = true; } response.success = true; return true; } int main(int argc, char **argv) { shutdown_sub = [] { image_subscriber.shutdown(); }; start_sub =[] { ros::NodeHandle nodeHandle; image_subscriber = nodeHandle.subscribe("/camera/image/compressed", 1, subscribe_callback); }; ros::init(argc, argv, "image_subscriber"); ros::NodeHandle nodeHandle; image_subscriber = nodeHandle.subscribe("/camera/image/compressed", 1, subscribe_callback); state_server = nodeHandle.advertiseService("/change_state", service_change_state); camera_client = nodeHandle.serviceClient<pi_robot::SrvCapture>("/camera_service"); motion_publisher = MotionPublisher("/mobile_base/commands/velocity", nodeHandle); ros::spin(); return 0; }
c56f73f9628fc1d99e2291affc1dc2455c7e45d0
5438f43d20f7ddb471068b81c70b75ba70ae27e1
/getchar_unlocked/main.cpp
da83029ab2b709bac01597d6169bf3f474a307b2
[]
no_license
dheerajkhatri/usinggit
5ff287ad9f7f827217747a6c2ea3c3be67c2cb72
57f28765f7850da6baf8b6f1897e02447cff5322
refs/heads/master
2021-01-01T17:01:05.902492
2020-01-15T07:56:57
2020-01-15T07:56:57
20,534,077
2
0
null
2017-02-17T07:28:02
2014-06-05T17:15:38
C++
UTF-8
C++
false
false
342
cpp
main.cpp
#include <iostream> #include <cstdio> #define gc getchar_unlocked using namespace std; inline int scan( ) { int n=0; int ch=getchar_unlocked(); while( ch <48 )ch=getchar_unlocked(); while( ch >47 ) n = (n<<3)+(n<<1) + ch-'0', ch=getchar_unlocked(); return n; } int main() { int n; n=scan(); cout<<n<<endl return 0; }
1c73ea9cdc86014b54c5be939aba51f68478271f
90539b70388259470debec076acc5a1e3c327ec7
/cast/dynamic.cpp
c72b1c09849d11ada29ed81a2629afa7dfd812bc
[]
no_license
shresthalucky/Cpping
2347720ec01a57baccc55e129e36db8954055d72
a3cd4fc6c0c20e71bd7bb945278fea1e20d69226
refs/heads/master
2021-06-27T22:49:44.168717
2020-09-07T17:29:30
2020-09-07T17:29:30
131,850,251
0
0
null
2018-05-02T12:53:46
2018-05-02T12:53:45
null
UTF-8
C++
false
false
292
cpp
dynamic.cpp
#include <iostream> #include <typeinfo> using namespace std; class A{ public: virtual void f(){} }; class B: public A{ }; int main(){ A* a; B b1, *b2; a = &b1; if(typeid(dynamic_cast<B*>(a)) == typeid(b2)){ cout << "true" << endl; } return 0; }
2e150443ac8bbb28cda0c4ed68b786e087ec805d
bae3cce507524b9d5b1f5fc5d3a3bb489f95b8df
/Upsolves/Codeforces/1438D.cpp
7bce544520152a3cb40d200d91bcafc62c778454
[]
no_license
tauhrick/Competitive-Programming
487e0221e29e8f28f1d5b65db06271f585541df8
abcdb18c3e0c48ea576c8b37f7db80c7807cd04c
refs/heads/master
2023-07-11T05:37:28.700431
2021-08-30T15:40:12
2021-08-30T15:40:12
193,487,394
0
0
null
null
null
null
UTF-8
C++
false
false
1,395
cpp
1438D.cpp
#ifndef LOCAL #include <bits/stdc++.h> using namespace std; #define debug(...) 42 #else #include "Debug.hpp" #endif class Task { public: void Perform() { Read(); Solve(); } private: int n; vector<int> a; vector<array<int, 3>> moves; void Read() { cin >> n; a.resize(n); for (auto &i : a) { cin >> i; } } void Solve() { if (n == 3) { cout << "YES\n" << "1\n" << "1 2 3\n"; return; } int all_xor = 0; for (auto &i : a) { all_xor ^= i; } if (n % 2 == 0) { if (all_xor != 0) { cout << "NO\n"; return; } for (int i = 1; i + 2 < n; i += 2) { AddMove(i, i + 1, i + 2); AddMove(0, i, i + 1); } } else { for (int cyc = 0; cyc < 2; ++cyc) { for (int i = 1; i + 1 < n; i += 2) { AddMove(0, i, i + 1); } } } assert(int(moves.size()) <= n && is_sorted(a.begin(), a.end()) && a[0] == a[n - 1]); cout << "YES\n" << moves.size() << '\n'; for (auto &[i, j, k] : moves) { cout << i << ' ' << j << ' ' << k << '\n'; } } void AddMove(int i, int j, int k) { int xor_ijk = a[i] ^ a[j] ^ a[k]; a[i] = a[j] = a[k] = xor_ijk; moves.push_back({i + 1, j + 1, k + 1}); } }; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); Task t; t.Perform(); return 0; }
a577b1e3ab171496c9ae944fb33d37c0b1a1f940
beb77aece047a98449c16bb8152c9d5d5f073dab
/test cpp/main.cpp
60a5615b3976bf5a10b3388cfed8d5b6d1817be5
[]
no_license
dev-jb-007/Data-Structure
65effa497facd2682bb8e66eb7cd82c95d562ec4
d439a09c53430f6f96ef9c34fa2bf83457ed93ba
refs/heads/main
2023-07-09T08:03:18.532213
2021-08-12T11:11:22
2021-08-12T11:11:22
395,220,207
0
0
null
null
null
null
UTF-8
C++
false
false
169
cpp
main.cpp
#include<iostream> using namespace std; #include "Header.h" int main(){ Queue<int> q; q.push(1); q.push(2); q.pop(); q.pop(); cout<<q.empty(); }
c1f405c53a9602f7d2ea9fb9c02378a2b426ca35
c18e3cba4f445613b2ed7503061cdfe088d46da5
/docs/atl/codesnippet/CPP/csimplearray-class_3.cpp
deb53230bfbfcc10fb859fa86383e96baa039eb2
[ "CC-BY-4.0", "MIT" ]
permissive
MicrosoftDocs/cpp-docs
dad03e548e13ca6a6e978df3ba84c4858c77d4bd
87bacc85d5a1e9118a69122d84c43d70f6893f72
refs/heads/main
2023-09-01T00:19:22.423787
2023-08-28T17:27:40
2023-08-28T17:27:40
73,740,405
1,354
1,213
CC-BY-4.0
2023-09-08T21:27:46
2016-11-14T19:38:32
PowerShell
UTF-8
C++
false
false
342
cpp
csimplearray-class_3.cpp
// Create an array of floats and search for a particular element CSimpleArray<float> fMyArray; for (int i = 0; i < 10; i++) fMyArray.Add((float)i * 100); int e = fMyArray.Find(200); if (e == -1) _tprintf_s(_T("Could not find element\n")); else _tprintf_s(_T("Found the element at location %d\n"), e);
462bb8bdfa392a20f888a06308e7486818da7811
ef1c9f3ff8e03dbc9d01d7292746068af8fa6214
/MFC_Lab6/MFC_Lab6/MFC_Lab6Dlg.cpp
dd494b61dd6be83acd5248ff4fb18cd6d19963b4
[]
no_license
BloodyRainRage/spb.stu_oop_mfc
4dd05860d20b50ccca676a4431c9114730a76611
cafb904362cea9bd9aa9915bc26183126d938892
refs/heads/master
2021-02-26T18:44:51.207388
2020-05-02T20:06:43
2020-05-02T20:06:43
245,546,575
0
0
null
null
null
null
UTF-8
C++
false
false
7,239
cpp
MFC_Lab6Dlg.cpp
 // MFC_Lab6Dlg.cpp: файл реализации // #include "pch.h" #include "framework.h" #include "MFC_Lab6.h" #include "MFC_Lab6Dlg.h" #include "afxdialogex.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // Диалоговое окно CAboutDlg используется для описания сведений о приложении class CAboutDlg : public CDialogEx { public: CAboutDlg(); // Данные диалогового окна #ifdef AFX_DESIGN_TIME enum { IDD = IDD_ABOUTBOX }; #endif protected: virtual void DoDataExchange(CDataExchange* pDX); // поддержка DDX/DDV // Реализация protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) END_MESSAGE_MAP() // Диалоговое окно CMFCLab6Dlg CMFCLab6Dlg::CMFCLab6Dlg(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_MFC_LAB6_DIALOG, pParent) , m_Edit(_T("")) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CMFCLab6Dlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Text(pDX, IDC_RESULT_EDIT, m_Edit); } BEGIN_MESSAGE_MAP(CMFCLab6Dlg, CDialogEx) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON5, &CMFCLab6Dlg::OnBnClickedButton5) ON_BN_CLICKED(IDC_OKCANCEL_BTN, &CMFCLab6Dlg::OnBnClickedOkcancelBtn) ON_BN_CLICKED(IDC_YESNOCANCEL_BTN, &CMFCLab6Dlg::OnBnClickedYesnocancelBtn) ON_BN_CLICKED(IDC_RETRYCANCEL_BTN, &CMFCLab6Dlg::OnBnClickedRetrycancelBtn) ON_BN_CLICKED(IDC_YESNO_BTN, &CMFCLab6Dlg::OnBnClickedYesnoBtn) END_MESSAGE_MAP() // Обработчики сообщений CMFCLab6Dlg BOOL CMFCLab6Dlg::OnInitDialog() { CDialogEx::OnInitDialog(); // Добавление пункта "О программе..." в системное меню. // IDM_ABOUTBOX должен быть в пределах системной команды. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != nullptr) { BOOL bNameValid; CString strAboutMenu; bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); ASSERT(bNameValid); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Задает значок для этого диалогового окна. Среда делает это автоматически, // если главное окно приложения не является диалоговым SetIcon(m_hIcon, TRUE); // Крупный значок SetIcon(m_hIcon, FALSE); // Мелкий значок // TODO: добавьте дополнительную инициализацию return TRUE; // возврат значения TRUE, если фокус не передан элементу управления } void CMFCLab6Dlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialogEx::OnSysCommand(nID, lParam); } } // При добавлении кнопки свертывания в диалоговое окно нужно воспользоваться приведенным ниже кодом, // чтобы нарисовать значок. Для приложений MFC, использующих модель документов или представлений, // это автоматически выполняется рабочей областью. void CMFCLab6Dlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // контекст устройства для рисования SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0); // Выравнивание значка по центру клиентского прямоугольника int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Нарисуйте значок dc.DrawIcon(x, y, m_hIcon); } else { CDialogEx::OnPaint(); } } // Система вызывает эту функцию для получения отображения курсора при перемещении // свернутого окна. HCURSOR CMFCLab6Dlg::OnQueryDragIcon() { return static_cast<HCURSOR>(m_hIcon); } void CMFCLab6Dlg::OnBnClickedButton5() { // TODO: добавьте свой код обработчика уведомлений int iResults; iResults = MessageBox(L"Do you really want to exit this amazing program?", L"Exit confirm", MB_YESNO + MB_ICONEXCLAMATION); if (iResults == IDYES) { OnOK(); } else if (iResults == IDNO) { return; } } void CMFCLab6Dlg::OnBnClickedOkcancelBtn() { // TODO: добавьте свой код обработчика уведомлений int iResults; iResults = MessageBox(L"You want Ok and Cancel buttons.", L"I am the second parameter of the MessageBox function", MB_OKCANCEL + MB_ICONSTOP); CString str = m_Edit; if (str != "") str += "\r\n"; if (iResults == IDOK){ str += "You Clicked the Ok button"; } else if (iResults == IDCANCEL){ str += "You clicked on the Cancel button"; } m_Edit = str; UpdateData(FALSE); } void CMFCLab6Dlg::OnBnClickedYesnocancelBtn() { // TODO: добавьте свой код обработчика уведомлений int iResults; iResults = MessageBox(L"You want Yes, No and Cancel buttons.", L"I am the second parameter of the MessageBox function", MB_YESNOCANCEL + MB_ICONINFORMATION); CString str = m_Edit; if (str != "") str += "\r\n"; if (iResults == IDYES){ str += "You clicked on the Yes button."; } else if (iResults == IDNO){ str += "You clicked on the No button"; } else if (iResults == IDCANCEL){ str += "You clicked on the Cancel button."; } m_Edit = str; UpdateData(FALSE); } void CMFCLab6Dlg::OnBnClickedRetrycancelBtn() { // TODO: добавьте свой код обработчика уведомлений int iResults; iResults = MessageBox(L"You want Retry and Cancel buttons.", L"I am the second parameter of the MessageBox function", MB_RETRYCANCEL + MB_ICONQUESTION); CString str = m_Edit; if (str != "") str += "\r\n"; if (iResults == IDRETRY){ str += "You clicked on the Retry button."; } else if (iResults == IDCANCEL){ str += "You clicked on the Cancel button."; } m_Edit = str; UpdateData(FALSE); } void CMFCLab6Dlg::OnBnClickedYesnoBtn() { // TODO: добавьте свой код обработчика уведомлений int iResults; iResults = MessageBox(L"You want Yes and No buttons.", L"I am the second parameter of the MessageBox function", MB_YESNO + MB_ICONEXCLAMATION); CString str = m_Edit; if (str != "") str += "\r\n"; if (iResults == IDYES){ str += "You clicked on the OK button."; } else if (iResults == IDNO) { str += "You clicked on the NO button."; } m_Edit = str; UpdateData(FALSE); }
8c2648a20d562f89f76d67a1113456ab690e0434
5fec989297cce17539214eb0839f069dd8f07b08
/hospital/main.cpp
2bad8d88f3d4b1f40821bad3c68aa7dd9ae8128a
[]
no_license
Xesian/QtHospital
40cffa63ac9c5b44b17c44f18cef1e2d73ca0a97
b33e115552b25db8042342742e76ad3576aea7f4
refs/heads/master
2021-01-19T06:36:27.580804
2015-07-31T02:35:48
2015-07-31T02:35:48
39,982,557
0
0
null
null
null
null
UTF-8
C++
false
false
548
cpp
main.cpp
#include "hos_main.h" #include <QApplication> #include<QtSql/QSqlDatabase> #include"login.h" QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL"); int main(int argc, char *argv[]) { db.setHostName("localhost");//设置数据库主机名 db.setDatabaseName("hos");//设置数据库名 db.setUserName("root");//设置账号 db.setPassword("240286024");//设置密码 if(!db.open())//如果打开数据库失败 return false; QApplication a(argc, argv); login *log=new login; log->show(); return a.exec(); }
f2eebec813add69b05169c3d03248dbb5ec9fbf7
d9472d42295f8096dbf40d26868dfce7ae4fae05
/src/FPChasingBall.cpp
a69700e7757e0186e2a933517566203e0a0d19bb
[]
no_license
chouqiu/FootballAI
75782bf73f4867d78b2ab73a5af1a0d531800743
a5ce1d87632ef29ebd9a2f3ef0137827e7e7d59a
refs/heads/master
2020-06-25T08:30:18.811982
2013-05-05T12:40:34
2013-05-05T12:40:34
null
0
0
null
null
null
null
UTF-8
C++
false
false
892
cpp
FPChasingBall.cpp
#include "FieldPlayerState.h" #include "Ball.h" #include "Team.h" // ChasingBall ChasingBall* ChasingBall::get() { static ChasingBall instance; return &instance; } void ChasingBall::enter(FieldPlayer* player) { player->getSteering()->setSeekOn(); } void ChasingBall::execute(FieldPlayer* player) { //player->getSteering()->setTarget(player->getBall()->getPosition()); // If the ball within kicking range if (player->getDistToBall() < player->getControlRange()) { player->getStateMachine()->changeState(KickingBall::get()); return; } if (player->isClosestTeamMemberToBall()) { player->setTarget(player->getBall()->getPosition()); return; } player->getStateMachine()->changeState(Positioning::get()); } void ChasingBall::exit(FieldPlayer* player) { player->getSteering()->setSeekOff(); } bool ChasingBall::onMessage(FieldPlayer*, const Message&) { return false; }
8cbcfd22b03bd0b8ac5ee12efb6ba10596a8191b
9ada6ca9bd5e669eb3e903f900bae306bf7fd75e
/case3/ddtFoam_Tutorial/0.004300000/fH
435123da6234838202529fe1b250e9f3f1af9397
[]
no_license
ptroyen/DDT
a6c8747f3a924a7039b71c96ee7d4a1618ad4197
6e6ddc7937324b04b22fbfcf974f9c9ea24e48bf
refs/heads/master
2020-05-24T15:04:39.786689
2018-01-28T21:36:40
2018-01-28T21:36:40
null
0
0
null
null
null
null
UTF-8
C++
false
false
123,602
fH
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 2.1.1 | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class volScalarField; location "0.004300000"; object fH; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [0 0 0 0 0 0 0]; internalField nonuniform List<scalar> 12384 ( 0.0373216 0.0378558 0.0380745 0.0380028 0.0377495 0.037263 0.0366506 0.0360171 0.0353389 0.0351149 0.0349534 0.0317787 0.0243703 0.0247414 0.0209707 0.0224515 0.0229197 0.0231476 0.0232552 0.0232834 0.0232804 0.0232529 0.0232283 0.0232054 0.0232197 0.0232248 0.023236 0.0232599 0.0233043 0.0233147 0.0233585 0.0234499 0.0235581 0.023636 0.0237495 0.0238773 0.024058 0.0245603 0.0242479 0.0220238 0.0198807 0.0191542 0.0210206 0.0257159 0.0272057 0.0292359 0.0303074 0.0306507 0.0306496 0.0305231 0.0303321 0.0301283 0.0299814 0.0297277 0.0296647 0.0293901 0.0292387 0.0290458 0.0288519 0.0287139 0.0286125 0.0284698 0.0283771 0.0281621 0.0275212 0.0257071 0.0253389 0.029292 0.0309841 0.0312275 0.0309796 0.0294254 0.0266337 0.0237567 0.029804 0.0302533 0.0311811 0.0317586 0.032029 0.0319501 0.0320069 0.0317844 0.0318602 0.0316191 0.0319079 0.0315874 0.031885 0.0316972 0.0319339 0.0318832 0.0316667 0.0319882 0.0318273 0.0317275 0.0314502 0.0304891 0.0294895 0.0286639 0.0273131 0.0271365 0.0273567 0.0274468 0.0274186 0.0273916 0.0287179 0.0270711 0.0266906 0.0267571 0.0267632 0.0266813 0.0266042 0.0265617 0.0265848 0.0267153 0.0267385 0.0268979 0.0268402 0.0271723 0.027049 0.0276655 0.0276354 0.0276466 0.0281696 0.028741 0.0300628 0.0313824 0.0316243 0.0309416 0.0288508 0.0265675 0.025678 0.025672 0.0259601 0.026129 0.0260728 0.0325313 0.0356446 0.0346958 0.0328227 0.0312892 0.0302283 0.0297732 0.0296453 0.0298958 0.0300853 0.0305158 0.0307954 0.0311393 0.0313618 0.0315373 0.0314991 0.0315452 0.0313338 0.0312039 0.031043 0.0309713 0.0308558 0.0308643 0.0308618 0.0308706 0.030867 0.0310448 0.0298449 0.0258326 0.0293151 0.0288299 0.0283011 0.029063 0.0332553 0.0370634 0.0387291 0.0386541 0.037626 0.0360164 0.0340783 0.0323513 0.0307887 0.0297781 0.0290438 0.0286168 0.0283482 0.0280631 0.0278553 0.0276875 0.0275362 0.027483 0.0273603 0.0274684 0.027479 0.0281404 0.0288986 0.0305949 0.0315448 0.0245462 0.0218031 0.0221435 0.0228708 0.0258002 0.0355049 0.0401962 0.0391632 0.0389368 0.0386257 0.0383922 0.0381239 0.0379478 0.0378379 0.0377839 0.0378047 0.037923 0.0379145 0.0377193 0.037263 0.0365204 0.0355779 0.0344461 0.033395 0.032416 0.0316549 0.0314065 0.0315906 0.032763 0.0346358 0.0357534 0.0181544 0.0186977 0.0211887 0.0445026 0.0533038 0.0500391 0.0488556 0.0480328 0.0473075 0.0470391 0.0467469 0.0467739 0.0468746 0.0471133 0.0474159 0.0478094 0.0482372 0.0486565 0.0489053 0.0490938 0.0489668 0.0488977 0.0485047 0.0479275 0.0475387 0.047789 0.0485832 0.0489463 0.0403031 0.0227573 0.021545 0.0312932 0.032986 0.0309595 0.0302013 0.0299394 0.0299493 0.0304722 0.0312385 0.0321142 0.0331442 0.0340444 0.0349024 0.0356264 0.0361867 0.0363926 0.036389 0.0362566 0.0360297 0.0358197 0.0354817 0.035714 0.035498 0.0359826 0.0361871 0.0368227 0.0380011 0.0394042 0.0396141 0.0373223 0.0209074 0.040112 0.042667 0.0421316 0.0418901 0.0418428 0.0422543 0.0429626 0.0438029 0.0445813 0.0453107 0.0458231 0.0460686 0.0462763 0.0462353 0.046422 0.0458634 0.0458941 0.0452273 0.0452351 0.0446245 0.0445442 0.0440023 0.0437971 0.0435216 0.0433367 0.0429292 0.0415111 0.0374676 0.0325363 0.0188302 0.0318836 0.0469181 0.0491984 0.050092 0.0503053 0.0501563 0.0490424 0.0480592 0.0469374 0.0458865 0.0448046 0.0437384 0.0430555 0.0424543 0.0423306 0.0427959 0.0434076 0.0451163 0.0462701 0.0478207 0.049236 0.0500481 0.0501488 0.0499759 0.0434534 0.0261018 0.0173286 0.0169427 0.018228 0.0172117 0.0167631 0.0161033 0.0172704 0.0198166 0.022329 0.0256367 0.0305675 0.0351921 0.0403963 0.0429539 0.044712 0.0465333 0.0477198 0.0480421 0.0477183 0.0467586 0.0451845 0.0428396 0.0404499 0.0373995 0.0353948 0.0326892 0.0302732 0.0259359 0.0220551 0.0181824 0.016876 0.0170983 0.0184259 0.0403353 0.0392158 0.0381144 0.0372818 0.0370709 0.0368507 0.0365646 0.0357768 0.0344826 0.033558 0.0338644 0.0325365 0.0263587 0.0244105 0.0209594 0.0228515 0.0233038 0.0233711 0.0232894 0.0231534 0.0230248 0.0229501 0.0229133 0.0229226 0.0229818 0.0230776 0.0231835 0.0232848 0.0233815 0.023444 0.0235233 0.0236041 0.0236827 0.0237426 0.0237933 0.0238274 0.0239183 0.0243052 0.0244873 0.0237586 0.0220164 0.0200703 0.0201239 0.0242752 0.0277463 0.0308922 0.031301 0.0313246 0.0309846 0.0301654 0.0294922 0.028769 0.0282421 0.027884 0.0276872 0.0276116 0.027614 0.027656 0.0277601 0.0279097 0.0280603 0.0282004 0.0282499 0.0282503 0.0279247 0.0265539 0.0252272 0.0256606 0.0263107 0.0282827 0.0307819 0.031367 0.0287854 0.0245796 0.0299801 0.0327944 0.0334454 0.0327575 0.0316617 0.0307548 0.0298966 0.0294644 0.0289922 0.0287949 0.0286227 0.0286101 0.0286694 0.0290377 0.0294112 0.0300038 0.0307409 0.0313764 0.031789 0.0319699 0.0318248 0.0312572 0.0302352 0.0292808 0.0279365 0.0274476 0.0279787 0.0282154 0.0280775 0.0277771 0.0252637 0.0262695 0.028464 0.0298703 0.0302089 0.0297229 0.0289238 0.0280032 0.0274304 0.0268329 0.0266068 0.0262316 0.0262551 0.0259862 0.0262731 0.0262707 0.0267548 0.0268105 0.0273161 0.0279107 0.0289822 0.0304043 0.0314289 0.0316165 0.0310214 0.0291361 0.0273104 0.0270585 0.0274251 0.0273492 0.0269933 0.0336817 0.0345915 0.0314987 0.0291405 0.0284867 0.0291097 0.03062 0.0320135 0.0332186 0.034117 0.0349006 0.0356202 0.0362408 0.0367616 0.0371722 0.0374431 0.0375399 0.0375078 0.0372472 0.0368925 0.0362184 0.0354743 0.0344627 0.0334585 0.0325663 0.0318396 0.0314764 0.0306348 0.0279397 0.0307363 0.028939 0.0287773 0.0317424 0.0374225 0.03994 0.0390346 0.0359858 0.0322183 0.0289013 0.0269899 0.0262617 0.0263031 0.0266151 0.0270836 0.0273341 0.0273399 0.027109 0.0267724 0.0264701 0.0261055 0.0256958 0.0253472 0.0249542 0.0247314 0.0251292 0.0263562 0.0286819 0.0311565 0.0261253 0.0221353 0.0233374 0.0266092 0.0342878 0.0389281 0.039317 0.0383552 0.0380044 0.0378426 0.0379148 0.037837 0.0376012 0.0370957 0.0363108 0.035592 0.0353586 0.0356496 0.0361768 0.0363595 0.0358328 0.034358 0.0318019 0.028761 0.0264046 0.0247693 0.0240664 0.0243445 0.0268222 0.0314709 0.0352938 0.0195415 0.0294386 0.039332 0.050326 0.0506767 0.0470739 0.0454954 0.0441836 0.0433108 0.0427312 0.04234 0.0421226 0.0425095 0.0430962 0.0441078 0.045224 0.04627 0.0470816 0.0476572 0.0477223 0.047297 0.0464156 0.0452121 0.0438321 0.0423392 0.0417602 0.0438569 0.0478019 0.0410884 0.0242711 0.0254895 0.031429 0.0302403 0.0272731 0.0262071 0.0260606 0.0266339 0.0280618 0.030237 0.0330841 0.0358058 0.0378835 0.0391086 0.0394225 0.0385831 0.0370139 0.0351112 0.0332182 0.0314594 0.0299194 0.0288904 0.0281276 0.0280765 0.0286787 0.0298574 0.0318804 0.0345112 0.0376296 0.0395898 0.0382707 0.027164 0.039877 0.0397146 0.0359727 0.0339389 0.0340525 0.0360669 0.0387193 0.0418043 0.0443181 0.0458581 0.0467926 0.0464169 0.0456886 0.0448113 0.0442377 0.0440595 0.0442463 0.0441605 0.0438853 0.0434158 0.0428162 0.0422793 0.0419227 0.041747 0.0419724 0.0421277 0.0415619 0.0394369 0.0348217 0.0247753 0.0396632 0.0492497 0.0503943 0.0506299 0.0489324 0.0463594 0.044097 0.0416148 0.0397865 0.0380769 0.0366338 0.0356689 0.0350095 0.034123 0.0333916 0.0322976 0.0325432 0.0329558 0.0359887 0.0398078 0.0445853 0.0483812 0.0504225 0.0512115 0.0479154 0.0349571 0.0221321 0.0171346 0.0174036 0.0171302 0.0164482 0.0167552 0.0193085 0.0231994 0.0289223 0.0369209 0.0467274 0.0553934 0.060111 0.0624189 0.0638366 0.0643118 0.0642044 0.064399 0.0649003 0.0654875 0.0662469 0.0667679 0.0656611 0.0641366 0.0594042 0.0547618 0.0495479 0.0459545 0.0372112 0.0260948 0.0197646 0.0172892 0.0178283 0.0352856 0.0331389 0.0310367 0.0299744 0.0298492 0.0308362 0.0322387 0.0333589 0.0331912 0.0320978 0.0321325 0.0323323 0.0283979 0.0244957 0.0211655 0.0232087 0.023308 0.0232036 0.0230868 0.0229486 0.0228102 0.0227713 0.0228214 0.0229664 0.0231598 0.0234002 0.0236709 0.023976 0.0243037 0.0246224 0.0249118 0.0251007 0.0251709 0.0250425 0.0247351 0.0243468 0.0240503 0.0241093 0.0244422 0.0245422 0.0236895 0.0214526 0.0200629 0.0231894 0.0282807 0.0311921 0.031011 0.0311461 0.0301734 0.028675 0.0273495 0.0262794 0.0255739 0.0253669 0.0252494 0.0253819 0.0255457 0.0257672 0.0260252 0.0263189 0.0267008 0.0271588 0.0275933 0.0278603 0.0279797 0.0272434 0.0258594 0.0249366 0.0245945 0.0250598 0.0272216 0.0305681 0.030931 0.0255782 0.0335734 0.0340715 0.0325794 0.0307704 0.0294616 0.0286756 0.0281223 0.0276751 0.0272274 0.0269787 0.0265502 0.026344 0.0263156 0.0264053 0.0268914 0.0276304 0.0285724 0.0297262 0.0307555 0.0315873 0.0319658 0.0317983 0.0309667 0.0298681 0.0285876 0.0278199 0.0281385 0.0285458 0.0286098 0.0279858 0.0250086 0.0306631 0.0348154 0.0362981 0.0365259 0.0359904 0.0348513 0.0332882 0.0316234 0.0299989 0.0285873 0.0273233 0.0265994 0.0264201 0.0263321 0.0266045 0.0270911 0.0273056 0.027549 0.0277717 0.0283276 0.029466 0.0308094 0.0316267 0.0317369 0.0310853 0.0293961 0.0279127 0.0277552 0.0275613 0.0283229 0.0338608 0.0320539 0.0289234 0.0288365 0.0310067 0.0335592 0.0346421 0.0351919 0.0356339 0.036112 0.0366686 0.0372859 0.0379104 0.0384695 0.0389493 0.0393139 0.0396307 0.0399842 0.0402392 0.0403434 0.0401885 0.0397564 0.0389385 0.0374979 0.035773 0.0339986 0.0325755 0.031386 0.0292461 0.0322036 0.0292566 0.0306027 0.0361255 0.0402651 0.0392521 0.0343184 0.0294289 0.0266975 0.026004 0.0265168 0.028238 0.0300273 0.031155 0.0311714 0.0301909 0.0287928 0.0277476 0.0272062 0.0270184 0.0268145 0.0264268 0.0257915 0.025021 0.0241913 0.0236202 0.0242944 0.0266029 0.0302375 0.0273577 0.0228018 0.025758 0.0319588 0.0381844 0.0393586 0.0387158 0.0385375 0.0388803 0.0400496 0.0411787 0.0419326 0.0419743 0.0410496 0.0391356 0.0366002 0.0343478 0.0331646 0.0335449 0.0348276 0.0355074 0.0342066 0.0300419 0.0260623 0.023458 0.0221152 0.0214434 0.0214651 0.0231785 0.0286878 0.0346907 0.0266212 0.0431635 0.0500824 0.0503178 0.0479846 0.0458658 0.0451231 0.0441937 0.0432659 0.0423339 0.041272 0.0404301 0.0401069 0.0405653 0.0417992 0.0435637 0.0450476 0.0454803 0.0444429 0.0420219 0.0394135 0.0367884 0.0355899 0.0351135 0.0360974 0.0370625 0.0395261 0.0457856 0.0422405 0.0251476 0.0273937 0.0305973 0.0277051 0.0259891 0.0256305 0.0254775 0.0256601 0.0270629 0.0303983 0.0348974 0.0394972 0.0424054 0.0431974 0.0420939 0.0385671 0.034731 0.0314879 0.0288737 0.0269965 0.0256263 0.0247382 0.023993 0.023754 0.0235764 0.0242997 0.0257708 0.0292382 0.0341449 0.0386017 0.038803 0.0312772 0.0387578 0.0339035 0.0291243 0.0282302 0.0294776 0.0325714 0.0374799 0.0423696 0.0457578 0.0466704 0.0448573 0.0413648 0.0383445 0.0362421 0.0354478 0.0360463 0.0371803 0.0391256 0.0403096 0.041031 0.0407641 0.0400209 0.039207 0.0386653 0.0388881 0.0395207 0.0404436 0.0398458 0.036391 0.0310364 0.0456925 0.050578 0.0503465 0.0484575 0.0456705 0.042911 0.0408786 0.0388328 0.037134 0.0358522 0.0351595 0.0350493 0.0351442 0.0339538 0.031328 0.0285709 0.0274231 0.0274008 0.0293336 0.0325109 0.0385752 0.0447843 0.0494777 0.0519909 0.0508173 0.0412634 0.0271276 0.0181862 0.0166192 0.0169109 0.0164799 0.0183099 0.0231519 0.0307036 0.0408783 0.0520609 0.0592465 0.0616525 0.0613499 0.0603778 0.0594054 0.0588673 0.0589142 0.0591993 0.0598128 0.0609395 0.062726 0.064874 0.0672383 0.0683007 0.0654064 0.0575885 0.0498082 0.0452209 0.0451278 0.0394167 0.0271619 0.018669 0.0170867 0.0306235 0.0283113 0.0265466 0.0258726 0.0258562 0.0263938 0.0277022 0.0298286 0.0311799 0.0308765 0.0306486 0.0317988 0.0297107 0.0247432 0.0218057 0.0233435 0.0233636 0.0233693 0.0234051 0.0234699 0.0235757 0.023641 0.0236973 0.0237507 0.0238126 0.0238871 0.0240855 0.0244753 0.0250787 0.0258757 0.0267196 0.0274119 0.0277409 0.0275724 0.0268114 0.0257321 0.0247206 0.0241855 0.0243111 0.0247106 0.0244728 0.0226372 0.020474 0.0226016 0.0285671 0.0306045 0.0303113 0.0309698 0.0295402 0.0276924 0.0259875 0.0248572 0.0244992 0.0244307 0.0247309 0.0249717 0.0252826 0.0255206 0.0256703 0.0257823 0.0259095 0.0262198 0.0267434 0.0272944 0.0276158 0.027484 0.026528 0.0253377 0.0244841 0.0242354 0.0251676 0.0283473 0.0304751 0.0264747 0.0355867 0.033111 0.0310434 0.0296995 0.0290434 0.0287061 0.0282925 0.0276442 0.0269516 0.0262135 0.025833 0.0254549 0.0254148 0.0253935 0.0255915 0.0260326 0.0269877 0.0282306 0.0296329 0.0309292 0.0318327 0.0320741 0.0315275 0.0303764 0.0291403 0.0283435 0.0283271 0.0287075 0.0290852 0.0284681 0.0267886 0.0334276 0.0369203 0.0375279 0.0374785 0.0370563 0.0361967 0.034723 0.0328209 0.0304835 0.028419 0.0266531 0.0262373 0.0262206 0.0266947 0.0273949 0.0280933 0.0285746 0.0286875 0.0284562 0.0283611 0.0290038 0.0302617 0.0313663 0.0318971 0.0317741 0.0307719 0.0290541 0.0279908 0.0275584 0.029505 0.0330122 0.0299433 0.0292588 0.0318187 0.0344261 0.0349124 0.0346554 0.0347048 0.0350973 0.0357532 0.0365861 0.0372654 0.0378477 0.0382223 0.0384161 0.038517 0.038662 0.0389235 0.0393236 0.0398351 0.0402621 0.0404185 0.0401991 0.0396338 0.0383318 0.0362322 0.0340303 0.0321437 0.0300878 0.0333511 0.030059 0.033242 0.0394132 0.0403728 0.0348649 0.0291962 0.0266885 0.0265781 0.0282424 0.0307979 0.0334117 0.0354047 0.0359662 0.0343651 0.0311141 0.0280068 0.0264663 0.0261562 0.0262981 0.0263611 0.0262747 0.0259561 0.0253289 0.0243536 0.02339 0.0233838 0.0252357 0.0293606 0.027849 0.0235641 0.0289156 0.0357246 0.0392068 0.0391861 0.0390003 0.0399603 0.0424033 0.0447794 0.0462351 0.0469935 0.0469632 0.0460663 0.044089 0.0405233 0.036074 0.0328435 0.0318933 0.0332444 0.0347744 0.0331969 0.0283961 0.0250936 0.0238951 0.0232405 0.0221965 0.0215581 0.0227445 0.0279813 0.0344884 0.0348856 0.0504164 0.0512932 0.0491943 0.0471319 0.0467645 0.0467987 0.0463585 0.0454094 0.0440044 0.0419961 0.0398878 0.0384131 0.0382592 0.0395512 0.0418325 0.0432176 0.0417612 0.0371586 0.0311485 0.0268611 0.0243359 0.0234715 0.0237527 0.02527 0.0294739 0.0355197 0.0439851 0.0428028 0.025711 0.0282858 0.0296228 0.027291 0.0270055 0.0269679 0.0261025 0.025445 0.0259773 0.029463 0.0357588 0.0419135 0.0448459 0.0450781 0.0410262 0.0349352 0.030444 0.027489 0.02591 0.0252151 0.0250572 0.025068 0.0250564 0.0246427 0.0239234 0.0230114 0.0228534 0.0248707 0.0300976 0.0369077 0.0391766 0.0331408 0.0362286 0.0297679 0.0275791 0.0277733 0.0295287 0.0339952 0.0404561 0.0452712 0.0471084 0.0443833 0.0374128 0.0318986 0.0286167 0.0270357 0.0269034 0.0270777 0.0293068 0.0314942 0.0350017 0.0372736 0.0387175 0.0384885 0.0372169 0.0358056 0.0352343 0.0357855 0.037771 0.0391929 0.036939 0.0361346 0.0487909 0.0509389 0.0493651 0.0465669 0.0441687 0.0421927 0.040437 0.0387483 0.0371141 0.0359107 0.0357138 0.0366079 0.0374401 0.0348002 0.0290952 0.0245727 0.023536 0.0239351 0.0256471 0.0288175 0.0346064 0.0421655 0.0486464 0.0529685 0.0527532 0.0464647 0.0342845 0.0218568 0.0161527 0.0167686 0.0168863 0.0208572 0.0295695 0.0409245 0.0522683 0.0598267 0.0613107 0.0602115 0.058415 0.0567772 0.0558032 0.0553816 0.0554111 0.0558995 0.0567074 0.0576706 0.0587833 0.0605104 0.0632951 0.0663105 0.0674272 0.0604144 0.0481572 0.0396345 0.0401333 0.0424523 0.0349912 0.0212712 0.0164528 0.0285062 0.0261447 0.0250964 0.0249863 0.0251128 0.025244 0.0257113 0.0270848 0.0289484 0.0295871 0.0294863 0.0311496 0.0304666 0.0252701 0.0225938 0.0233886 0.0237706 0.0240653 0.0244481 0.0248866 0.0253054 0.0254966 0.0254238 0.0251084 0.0246622 0.0242603 0.0240494 0.0242932 0.0251281 0.0264412 0.0278937 0.0290365 0.0294369 0.0292764 0.0286474 0.0272753 0.025665 0.0244898 0.0242731 0.0246829 0.0248029 0.0234429 0.0209444 0.0223597 0.0285128 0.0299754 0.0298797 0.0307914 0.0292392 0.0272716 0.0256059 0.0247114 0.0247331 0.0251257 0.0257701 0.0263983 0.0269029 0.0271178 0.0270317 0.026658 0.0261066 0.0259448 0.0262247 0.0267808 0.027256 0.0273162 0.0268107 0.0257968 0.0248186 0.0242092 0.0243172 0.026567 0.030269 0.0268631 0.0353722 0.0323643 0.0305773 0.0297129 0.0294848 0.0292461 0.0284871 0.0273937 0.0263279 0.0257411 0.0254512 0.0254762 0.0252089 0.0253271 0.0253069 0.0258109 0.0265001 0.0275501 0.0289438 0.0304569 0.031688 0.0322487 0.0319013 0.0307391 0.0295432 0.0288795 0.0287486 0.0289603 0.0293023 0.0288624 0.0288845 0.0337763 0.0367589 0.036413 0.0351742 0.0341947 0.0332865 0.0318972 0.0298844 0.027612 0.0261399 0.0257906 0.0264314 0.0277542 0.0289848 0.0298459 0.0302924 0.0303013 0.0299505 0.0293511 0.0288686 0.0289936 0.029977 0.0311356 0.0318714 0.0319917 0.0313624 0.0297724 0.0282896 0.0275466 0.0303193 0.0320623 0.0296692 0.0314339 0.0341497 0.0344699 0.0337862 0.0337228 0.0342066 0.0348781 0.0358183 0.0367803 0.0374507 0.0376321 0.0374362 0.0370813 0.0367694 0.0365703 0.0365498 0.0367228 0.0372148 0.0380403 0.0390448 0.0397503 0.0399296 0.0393234 0.0376855 0.0352398 0.0328574 0.0306412 0.0342728 0.0312073 0.0360767 0.0407391 0.0376728 0.030925 0.0276188 0.02738 0.029199 0.0320556 0.0350413 0.0379585 0.0399344 0.0398077 0.0366861 0.0312442 0.0271364 0.0257903 0.0261244 0.0269774 0.0273071 0.0271537 0.0267226 0.0260006 0.0248559 0.0235956 0.0232351 0.0247837 0.0291069 0.0277002 0.0244469 0.0308194 0.0375543 0.0394336 0.039375 0.0401893 0.0429162 0.0462298 0.048146 0.0492041 0.0495013 0.0492027 0.0483261 0.0468698 0.0438048 0.0386363 0.0336025 0.0313527 0.0320317 0.0335273 0.0316041 0.0280602 0.0275622 0.0287442 0.0285201 0.0263172 0.0244046 0.0247925 0.0293626 0.0346729 0.0404281 0.0524303 0.0510126 0.0483859 0.0477472 0.0482123 0.0484964 0.0484525 0.0480992 0.0469571 0.0444269 0.0407817 0.0375466 0.0364054 0.0378147 0.0406183 0.0414735 0.037513 0.0298106 0.0237287 0.0211786 0.0203073 0.0203657 0.0202749 0.0206613 0.0222564 0.0295353 0.0426289 0.0442421 0.027214 0.0286386 0.0293076 0.0284465 0.0297998 0.0294555 0.0273162 0.0256679 0.0255326 0.02901 0.0368226 0.0440228 0.046099 0.0436498 0.0350572 0.0282613 0.0248597 0.0236587 0.0238973 0.0250424 0.0266534 0.0280559 0.0288123 0.0283901 0.0269067 0.0245427 0.0225915 0.0226276 0.0267172 0.0348149 0.0390897 0.0337327 0.0337606 0.0286427 0.0282374 0.0292041 0.0311729 0.0365865 0.0434274 0.0467599 0.0455548 0.0377185 0.0291914 0.0260877 0.02448 0.0238959 0.0233478 0.0235889 0.0237981 0.0259709 0.0286407 0.0327901 0.035841 0.0370247 0.0359838 0.0337591 0.0319268 0.0318858 0.0344099 0.0377086 0.0369251 0.0394901 0.0501163 0.0504846 0.0479192 0.0450801 0.0430509 0.0415683 0.0404001 0.0390762 0.0373865 0.0357995 0.035518 0.0371795 0.0388393 0.0357484 0.0282032 0.0231318 0.0224438 0.0230447 0.0245897 0.0277098 0.0333063 0.0410506 0.0482702 0.053257 0.0542712 0.050822 0.0412068 0.0264535 0.0160368 0.0167391 0.0175466 0.0245875 0.0372417 0.0499035 0.0586674 0.0613279 0.0597946 0.0570835 0.0546709 0.0525338 0.051152 0.0503957 0.0506333 0.0518492 0.0536294 0.0555619 0.0571582 0.058529 0.0603502 0.0634033 0.0661175 0.0637926 0.0475551 0.0364864 0.0356932 0.0400548 0.0373672 0.0230724 0.0162927 0.0275856 0.0252668 0.02491 0.02525 0.0254832 0.0253906 0.0252894 0.0256573 0.0270445 0.0280903 0.0283808 0.0305396 0.0310209 0.0258993 0.023145 0.0238355 0.0247542 0.0250613 0.0255787 0.0262906 0.0269204 0.0271834 0.0269165 0.0262121 0.0252477 0.0243442 0.0237726 0.0238852 0.0249718 0.0267551 0.0284242 0.0291156 0.0290961 0.0289389 0.0286085 0.0277965 0.0262368 0.0247594 0.0242606 0.0246416 0.0249601 0.0238732 0.0213124 0.0221999 0.0283566 0.029218 0.0295038 0.030653 0.0293782 0.0276618 0.0263987 0.0260152 0.0266807 0.0279471 0.0290989 0.0299267 0.0302267 0.0302718 0.0300472 0.0294764 0.0282244 0.0265245 0.0259225 0.0262976 0.0268548 0.027 0.0267149 0.0259769 0.0250846 0.0242793 0.0240265 0.0257424 0.0294939 0.0270616 0.0348684 0.0321059 0.0304758 0.0299741 0.029913 0.0294548 0.0281804 0.0267344 0.0257123 0.0255445 0.0257927 0.0262337 0.0261717 0.0259528 0.0257883 0.0261405 0.0267011 0.027571 0.0289609 0.0304539 0.0317568 0.0324216 0.0321148 0.0309527 0.0297745 0.0292597 0.0292205 0.0293449 0.0295481 0.0291034 0.0302706 0.0343558 0.0361808 0.0340011 0.031363 0.0297472 0.028547 0.0271542 0.0257953 0.0251093 0.0258503 0.0274993 0.0294074 0.0309245 0.0312776 0.031396 0.031347 0.0311007 0.0306616 0.029983 0.0293346 0.0292497 0.0300489 0.0311527 0.0319556 0.032146 0.0316457 0.0303136 0.0284228 0.0275017 0.0308231 0.0312673 0.0306292 0.0335054 0.0344236 0.0336478 0.0334187 0.0339823 0.0346146 0.0352289 0.036154 0.0370566 0.0374072 0.0370341 0.0363729 0.0359128 0.0357476 0.035723 0.0357049 0.0358181 0.0360463 0.0363656 0.0371612 0.0382082 0.0391274 0.0392591 0.0382331 0.0360198 0.0333653 0.0310267 0.0347021 0.033007 0.038733 0.0404554 0.0348048 0.0296739 0.0284315 0.0296776 0.0324007 0.0353842 0.0385217 0.041121 0.0423644 0.0419146 0.0378326 0.0312119 0.0266647 0.0255964 0.0269282 0.0292127 0.0303526 0.0302495 0.029217 0.0275539 0.0256142 0.0240826 0.0236424 0.0253744 0.0292369 0.0273508 0.025311 0.0321398 0.0379915 0.0396403 0.0399777 0.0417784 0.0453721 0.0484101 0.0500169 0.0506428 0.050862 0.0503384 0.0492974 0.0478796 0.0454582 0.0405155 0.0343839 0.031189 0.0314165 0.0326288 0.0308764 0.0302012 0.0327532 0.0350452 0.0342867 0.0322222 0.0305699 0.0301845 0.0322785 0.0350812 0.0433628 0.0528447 0.0505712 0.0485474 0.0485622 0.0489678 0.0491389 0.0493164 0.0494963 0.0493074 0.0474044 0.0427061 0.0372772 0.0350105 0.0369533 0.0403731 0.0404026 0.0337975 0.0253414 0.0212013 0.0202348 0.0206415 0.0216963 0.0218921 0.0207347 0.0203635 0.0238863 0.0385506 0.0450771 0.0274467 0.028789 0.0296923 0.0309045 0.033292 0.032026 0.0288295 0.0263661 0.0256823 0.0286414 0.0381718 0.0451517 0.0456308 0.0379214 0.0278529 0.0230631 0.0216092 0.0219598 0.0235952 0.0260915 0.0290248 0.0310068 0.0317766 0.0313257 0.02943 0.0264397 0.0231299 0.0217774 0.024552 0.0330052 0.0391358 0.0337157 0.0323194 0.0290965 0.0299025 0.0305272 0.0324201 0.0384255 0.0451542 0.0471648 0.0413817 0.0313756 0.0259446 0.0250089 0.0240507 0.0236531 0.0229671 0.0226231 0.02309 0.0235821 0.0261037 0.0291638 0.0330867 0.0353762 0.0348888 0.0321785 0.0292209 0.02841 0.0311704 0.0359428 0.0365803 0.0416054 0.0505075 0.0496067 0.0462915 0.0434848 0.041734 0.0409358 0.0404934 0.0397048 0.0381622 0.0360249 0.0348157 0.0363555 0.0396614 0.0384696 0.0314727 0.0254389 0.0237133 0.0246043 0.0259206 0.0289748 0.0348953 0.0423655 0.0491795 0.0538468 0.0562314 0.0557937 0.0488295 0.0315645 0.0164469 0.0167456 0.0184968 0.0290404 0.0443964 0.056203 0.061272 0.0606278 0.0569994 0.0534919 0.0497438 0.0468241 0.044593 0.0436676 0.0442917 0.0461522 0.0488668 0.0520946 0.0551264 0.0572972 0.0588693 0.061343 0.0645451 0.0640115 0.0471685 0.0338977 0.0329883 0.0375889 0.0368546 0.0242973 0.016364 0.0270207 0.0248425 0.0250169 0.0258729 0.0264147 0.0262427 0.0254871 0.0250737 0.0255796 0.0263667 0.0270643 0.0295681 0.0313641 0.0267407 0.0233802 0.0246442 0.0260096 0.0261147 0.0264988 0.027162 0.0277427 0.0279365 0.0275804 0.0266816 0.0254397 0.0241638 0.023377 0.0235006 0.0249155 0.027054 0.028403 0.0282245 0.0274506 0.027098 0.0272517 0.0270078 0.0259788 0.0247001 0.024288 0.0246491 0.0250098 0.0241396 0.0216191 0.0220914 0.0282161 0.0284378 0.0291373 0.0306259 0.029802 0.028785 0.0282519 0.0287344 0.0301342 0.0315263 0.0322928 0.0323482 0.0320278 0.0316323 0.0314563 0.0313558 0.0310234 0.0294071 0.0263948 0.0258132 0.0262089 0.0265212 0.0263226 0.0257874 0.025078 0.0242659 0.0238805 0.025301 0.0292245 0.0269889 0.0345311 0.0316831 0.0305776 0.0302126 0.0301543 0.0294912 0.0278323 0.0263923 0.0254983 0.0258733 0.0266659 0.0273561 0.0275973 0.027354 0.0269797 0.0270706 0.0275725 0.0284238 0.0296297 0.0309706 0.0321486 0.0326216 0.0322195 0.0309566 0.0298157 0.0294184 0.0294812 0.0296962 0.0298286 0.0292746 0.030912 0.0356612 0.0351965 0.0309967 0.0276867 0.0260027 0.0249651 0.024292 0.0244167 0.0259249 0.0286659 0.0309463 0.0318047 0.0317585 0.0314985 0.0314126 0.0313775 0.0311967 0.0308274 0.0301681 0.0296407 0.0296816 0.0304195 0.0314259 0.0321425 0.0321971 0.0316608 0.0303365 0.0283117 0.0274498 0.0309464 0.0312345 0.0322013 0.0343257 0.0340478 0.0337265 0.0342945 0.0349394 0.0352232 0.0355454 0.0363619 0.0371765 0.0369752 0.0361064 0.0354745 0.0354708 0.0357456 0.0360747 0.0362722 0.0363375 0.0363116 0.0363471 0.0364518 0.0370418 0.0380324 0.0386399 0.0380902 0.036202 0.0335766 0.0312631 0.0352227 0.0346467 0.0401804 0.0394879 0.0334313 0.0303945 0.0305007 0.0326343 0.0352717 0.0380033 0.0403437 0.0418055 0.0423758 0.0418229 0.0385174 0.0319072 0.0265627 0.0252736 0.0272818 0.0307458 0.0324619 0.0327989 0.0314801 0.0289922 0.0264822 0.0249409 0.024801 0.0266998 0.0294887 0.0268253 0.0257917 0.0322191 0.0381051 0.0398753 0.040378 0.0429295 0.046925 0.0497306 0.0509032 0.0515678 0.0516471 0.0511894 0.0499738 0.0483011 0.0461851 0.0416486 0.0347128 0.0308617 0.0311179 0.0324727 0.0320312 0.0340131 0.0368908 0.0369388 0.0350568 0.0334416 0.0329444 0.0332442 0.034358 0.0353544 0.0449685 0.0536354 0.050095 0.0486465 0.0489864 0.0491741 0.0491146 0.0492313 0.0497933 0.0503821 0.0497435 0.0448575 0.03715 0.0338828 0.036844 0.0410165 0.0396206 0.03087 0.0234891 0.0211524 0.0211849 0.0226254 0.0242046 0.0245297 0.0229453 0.0204321 0.0219619 0.0339732 0.0453425 0.0298231 0.0289284 0.0306502 0.0335962 0.036069 0.0344909 0.0306287 0.0271304 0.0257137 0.0286435 0.0386992 0.0452989 0.0436954 0.032319 0.0237809 0.0210046 0.0206274 0.021624 0.0233496 0.0254043 0.0281335 0.0303047 0.0317564 0.0307678 0.0285938 0.025607 0.0225902 0.0210289 0.023278 0.0317991 0.0387874 0.0335405 0.031762 0.0302921 0.0316826 0.0315569 0.0329792 0.039601 0.0458731 0.0459653 0.037191 0.0285448 0.0258186 0.0252494 0.0242338 0.0235455 0.0224579 0.0224967 0.0224522 0.0230495 0.0243793 0.0274321 0.0312035 0.033899 0.0335721 0.0305385 0.0269732 0.0256964 0.0285158 0.0342731 0.0360604 0.0429879 0.0505699 0.0483778 0.044417 0.0415079 0.0400427 0.039822 0.04005 0.040069 0.0392778 0.0372139 0.0346546 0.034346 0.0385909 0.0411332 0.0374657 0.0309673 0.0276341 0.0276164 0.0291056 0.0321615 0.0374137 0.0441381 0.0503507 0.054844 0.0583927 0.0604292 0.0554377 0.0378597 0.0172413 0.0168428 0.019786 0.033637 0.0501125 0.059682 0.061773 0.0589566 0.0540807 0.0494709 0.0444119 0.040379 0.0381674 0.0378732 0.039004 0.0410852 0.0441831 0.048011 0.0522797 0.0557248 0.0578278 0.0600109 0.0637184 0.0641392 0.0468958 0.0323438 0.031594 0.0349565 0.0331724 0.0224429 0.0162793 0.0266899 0.0244918 0.0251789 0.0265772 0.027943 0.0282684 0.0266978 0.0256476 0.025433 0.0256553 0.0261857 0.0284946 0.031492 0.0274727 0.0234957 0.0258753 0.0278968 0.0274588 0.0273058 0.0276598 0.0280288 0.0280993 0.0277464 0.0268915 0.0255326 0.0240169 0.0229777 0.0230338 0.0247156 0.0272963 0.0281849 0.0272572 0.0257123 0.0250291 0.0252799 0.0255086 0.025019 0.0243897 0.0242259 0.0248059 0.0251634 0.0241922 0.0218058 0.0220303 0.0282792 0.0278694 0.0287129 0.0304684 0.030418 0.0302334 0.0304572 0.0315198 0.0328048 0.0336971 0.0338008 0.0334206 0.0327089 0.0319257 0.0315317 0.0315807 0.0319515 0.0318387 0.029356 0.026295 0.0257669 0.0258744 0.0257614 0.025377 0.0248134 0.0240682 0.0237521 0.0251792 0.0289568 0.0271587 0.0341543 0.0317064 0.0308679 0.0303577 0.0303153 0.0296974 0.0279459 0.0264543 0.0256592 0.0261677 0.0273366 0.0281031 0.0288508 0.0287322 0.028594 0.0286264 0.0290662 0.0298072 0.030788 0.0318565 0.0325437 0.03266 0.0319553 0.030631 0.029587 0.0293443 0.0296127 0.0299459 0.0299155 0.0292478 0.0322623 0.036869 0.0333793 0.0282561 0.0252763 0.0239578 0.0235623 0.0238265 0.0256068 0.0287048 0.0309809 0.0319939 0.0319352 0.031605 0.0314168 0.0313206 0.0312581 0.0310363 0.0306255 0.0301906 0.030035 0.030353 0.0311473 0.0319825 0.0324248 0.0321728 0.0315327 0.0297995 0.0276737 0.0273537 0.0310614 0.0316771 0.0335179 0.0346257 0.0344715 0.0351205 0.0360018 0.036083 0.0357354 0.0357904 0.0364473 0.0372078 0.0364697 0.035336 0.0351361 0.035567 0.0362129 0.0367683 0.0370343 0.0371176 0.0369542 0.0367219 0.036572 0.0366669 0.0372914 0.0379358 0.0376067 0.0359432 0.0335049 0.0314096 0.0356612 0.0362453 0.0408934 0.0387076 0.0338326 0.0322858 0.0334375 0.035581 0.0377155 0.0395522 0.040463 0.0405563 0.0406228 0.0407626 0.0392467 0.0336532 0.0271487 0.0245871 0.0256369 0.0291388 0.0318691 0.0327568 0.0322512 0.03016 0.027911 0.0267336 0.0268952 0.0283532 0.0291659 0.0257538 0.0256594 0.0320886 0.0382333 0.0401398 0.0407543 0.0431118 0.0471604 0.0500222 0.0512624 0.0519824 0.0523157 0.0517227 0.0502015 0.0483403 0.0462905 0.0423892 0.0346477 0.0305219 0.031104 0.0327211 0.0331942 0.036151 0.0372051 0.0341167 0.0307458 0.0299796 0.0307219 0.031411 0.0318141 0.034091 0.0470025 0.0531226 0.0499316 0.0489864 0.049218 0.0491161 0.0488465 0.0487789 0.0494072 0.0505857 0.0510599 0.0467559 0.0368988 0.0326992 0.0374646 0.0423108 0.0387232 0.0290787 0.0234265 0.0220815 0.0228034 0.0245633 0.0258193 0.0253629 0.0241226 0.0212616 0.0205113 0.0316385 0.0448218 0.0304486 0.0290691 0.0318399 0.0356377 0.0374637 0.0360479 0.0326711 0.0282657 0.0259132 0.0277699 0.0382674 0.0450783 0.0425253 0.0295649 0.0224264 0.020657 0.0209139 0.0221392 0.0233876 0.0244241 0.0262019 0.0282689 0.0301762 0.0289318 0.0253348 0.022535 0.0206353 0.0200685 0.0229547 0.0318443 0.0391556 0.0334411 0.0318899 0.03193 0.0330704 0.0322954 0.0331689 0.0399798 0.046191 0.0450131 0.035261 0.0281896 0.0262339 0.0256764 0.0242154 0.0233401 0.0221458 0.0223334 0.0224171 0.0230679 0.0246173 0.027099 0.0302815 0.0325079 0.0317561 0.0285503 0.0249179 0.0238194 0.0268422 0.0332015 0.0354557 0.0436787 0.0503376 0.0468767 0.042368 0.039352 0.0380051 0.037974 0.0385047 0.0394492 0.0399972 0.0391179 0.0358208 0.0326364 0.0353287 0.0416489 0.0423176 0.0386914 0.0340884 0.0323953 0.0337117 0.0367918 0.0414966 0.0467417 0.051832 0.0562476 0.0606454 0.0643485 0.060286 0.0405547 0.0176587 0.0169325 0.0212108 0.0375451 0.0540834 0.0613118 0.0613555 0.0573298 0.0514269 0.0459692 0.0396626 0.0362696 0.0346718 0.0349356 0.0359578 0.038111 0.0410792 0.0450612 0.0496517 0.0540515 0.0568763 0.058907 0.0630862 0.0655942 0.0513213 0.0320225 0.0289638 0.0295311 0.0262751 0.0205276 0.0190074 0.0265263 0.0242652 0.0251438 0.0270899 0.0299388 0.0319619 0.0304401 0.0285947 0.0272936 0.0270031 0.0268731 0.0283997 0.0317073 0.0283068 0.0290522 0.0270563 0.0246728 0.0290821 0.0306511 0.0293972 0.0282888 0.0282653 0.0283509 0.0282693 0.0278828 0.0270983 0.0259662 0.0242943 0.0228513 0.0225719 0.0241148 0.0267567 0.0280162 0.0269243 0.0249485 0.0240958 0.0241127 0.024306 0.0242804 0.02413 0.0244365 0.0250549 0.0252258 0.0243988 0.0223013 0.0218566 0.0228935 0.0264053 0.0283277 0.0273165 0.0281316 0.0301264 0.0306793 0.0312748 0.0321289 0.0331661 0.0341873 0.0347337 0.0348161 0.0344515 0.0336357 0.0324945 0.031547 0.0312807 0.0316745 0.0322121 0.0313996 0.0281135 0.0259279 0.0254682 0.025252 0.0249159 0.0244052 0.0237843 0.0237008 0.0253996 0.0286508 0.030376 0.0350193 0.0340986 0.0330433 0.0326834 0.0316556 0.0305416 0.0304536 0.0301157 0.0284922 0.0269569 0.0261034 0.0263895 0.0273902 0.0282782 0.0291272 0.0295631 0.0298686 0.0301194 0.0304913 0.031074 0.0317252 0.0322316 0.0324067 0.0320841 0.0309693 0.0297303 0.0291285 0.0293201 0.0297606 0.0299131 0.0296361 0.0290435 0.0278153 0.0278284 0.0356687 0.0369423 0.0317778 0.0270708 0.0243542 0.0234369 0.0234159 0.0245433 0.0270205 0.0296269 0.0312821 0.0319899 0.032112 0.0318011 0.0315116 0.0313064 0.0310917 0.0308612 0.0306352 0.0305743 0.0308041 0.0313329 0.0320131 0.0324346 0.0323506 0.0318087 0.0306188 0.028439 0.0272944 0.0276946 0.0283415 0.0302818 0.0312629 0.0326254 0.0345832 0.0353287 0.0359832 0.0373377 0.0378569 0.0372104 0.0362041 0.0358209 0.0364558 0.0372307 0.0361064 0.0349377 0.0350373 0.0356533 0.0364267 0.0370275 0.0374108 0.0374973 0.037335 0.0370555 0.0367894 0.0366501 0.0369243 0.0373821 0.0369759 0.03531 0.0330359 0.0320117 0.0355598 0.036828 0.0363236 0.0379234 0.0413841 0.0389228 0.0355474 0.0351344 0.036585 0.0381046 0.0393317 0.0400254 0.0399739 0.0396441 0.039602 0.0399195 0.0396697 0.0364331 0.0291269 0.0241115 0.023214 0.0249691 0.0277958 0.0302305 0.0315963 0.031576 0.0303567 0.029441 0.0294603 0.0297685 0.0292291 0.0259916 0.0233884 0.0224674 0.0224182 0.0241296 0.0307379 0.0381295 0.0409975 0.0430384 0.0465969 0.0496891 0.0511353 0.0519313 0.0521712 0.0516429 0.0499591 0.047857 0.0461219 0.0425635 0.0340877 0.0301466 0.031484 0.033028 0.0339996 0.0363408 0.0353998 0.0305232 0.0281007 0.0295048 0.0336096 0.0353198 0.0328077 0.0311522 0.0272305 0.0370535 0.0474578 0.0529145 0.0496246 0.0492389 0.0493155 0.0490797 0.0487792 0.0487125 0.0492759 0.0506742 0.0516396 0.0478889 0.0363646 0.0317168 0.0387122 0.0438629 0.0381774 0.0289844 0.0245368 0.0235041 0.0244543 0.026019 0.0260906 0.0247086 0.0230264 0.0211466 0.0206202 0.0304271 0.0444346 0.0334072 0.0315738 0.0287461 0.0295456 0.0331639 0.0369438 0.0382253 0.0370871 0.0347477 0.0300953 0.0260653 0.0265857 0.0367953 0.0451402 0.0424848 0.0294799 0.0229635 0.0217303 0.022963 0.0246767 0.0257697 0.0258605 0.0262728 0.0272442 0.0292169 0.0277153 0.0226561 0.0200425 0.0190789 0.0200354 0.0238793 0.0330401 0.0394558 0.0381595 0.0343543 0.0332366 0.0323378 0.0335725 0.0342702 0.0327878 0.0329434 0.0399924 0.0466072 0.0450119 0.0355242 0.0289623 0.0270348 0.0262753 0.0246313 0.023378 0.0222902 0.0223538 0.0226568 0.0234109 0.0249548 0.0270849 0.0293359 0.0304195 0.0291084 0.0259683 0.0231329 0.0227174 0.0261165 0.0324999 0.034787 0.0320255 0.0372972 0.0451353 0.0497549 0.0451474 0.040316 0.0369675 0.0355543 0.0353516 0.0361274 0.037694 0.0394595 0.040148 0.0383603 0.0328026 0.0306417 0.0373537 0.0429575 0.0436249 0.0423013 0.0408864 0.0407052 0.0426546 0.046464 0.05107 0.0557313 0.0600635 0.0640207 0.0663835 0.0645943 0.0500132 0.0251201 0.0222702 0.019093 0.0171644 0.0225479 0.0408685 0.0565735 0.0619701 0.0609296 0.0561447 0.049655 0.043874 0.0368441 0.0340605 0.0324663 0.0327776 0.0339764 0.036495 0.0400816 0.0436744 0.0481288 0.0527368 0.0560794 0.0582696 0.0626312 0.0664604 0.0559394 0.0344953 0.028284 0.0283497 0.0272801 0.0300264 0.0470441 0.070003 0.0704299 0.0264646 0.0239993 0.0248975 0.0269492 0.0309673 0.034572 0.0349099 0.0327478 0.0305413 0.0296055 0.0290611 0.0296133 0.0324221 0.0301353 0.0299658 0.0302218 0.0280502 0.0316686 0.0329246 0.0313455 0.0292874 0.029019 0.0291115 0.028803 0.0283847 0.027715 0.0266588 0.0251167 0.0232262 0.0222023 0.023157 0.0258846 0.0278104 0.0273062 0.0255719 0.0242603 0.0239523 0.0239932 0.0240729 0.0243551 0.0250215 0.0256056 0.0254364 0.0242899 0.0223077 0.0216988 0.022381 0.0255254 0.0278447 0.0252484 0.0259997 0.0292048 0.0304135 0.0314184 0.0327318 0.0339719 0.0349007 0.0354829 0.0355976 0.0353416 0.0346583 0.033436 0.0319204 0.0310494 0.031058 0.0317789 0.0318691 0.029775 0.0268008 0.0254797 0.0249469 0.0245399 0.0240328 0.0235699 0.0236822 0.0256389 0.029021 0.0323579 0.0351901 0.0343787 0.0343362 0.0352505 0.0333266 0.0310159 0.0305519 0.0306011 0.0293858 0.0277445 0.0267003 0.0266153 0.0271918 0.0278748 0.0286825 0.0293163 0.0298003 0.0302876 0.0306511 0.0310657 0.0313318 0.0314619 0.0311804 0.0304115 0.0295276 0.0289696 0.0290227 0.0292838 0.0293434 0.0289563 0.0283326 0.0281977 0.027572 0.031382 0.0385274 0.0360727 0.0317624 0.027397 0.0246401 0.0236018 0.0236281 0.0247242 0.0267602 0.0289336 0.0305371 0.0315549 0.0320146 0.032064 0.031902 0.0316945 0.0315157 0.0314018 0.031403 0.0315909 0.0319274 0.0322988 0.0324806 0.0323158 0.031811 0.0304929 0.0283888 0.027231 0.0281556 0.0298968 0.030549 0.0310461 0.0321491 0.0339849 0.0357979 0.0368196 0.038254 0.0394876 0.0394768 0.038407 0.0368384 0.0358354 0.0363915 0.0372393 0.0360326 0.0347167 0.0347681 0.0353629 0.0361017 0.0367866 0.0372181 0.0373245 0.0372576 0.0370779 0.036846 0.0367024 0.0367853 0.0368474 0.0361441 0.0344577 0.0327111 0.0324282 0.0360425 0.0372431 0.0368933 0.0388766 0.0420474 0.0400382 0.0378733 0.0381603 0.0390997 0.03978 0.0400646 0.0399973 0.0398947 0.0399891 0.0400392 0.0398476 0.0397019 0.0385264 0.032653 0.0251597 0.0220327 0.0216459 0.0227807 0.0249931 0.0279524 0.0302046 0.030472 0.0297624 0.0289281 0.0282063 0.0268078 0.0243848 0.0228063 0.0234494 0.0248917 0.0255977 0.0284691 0.0351069 0.040072 0.0425061 0.0453177 0.0483858 0.05033 0.0513239 0.0514596 0.0509025 0.049127 0.0471751 0.0456302 0.042052 0.033061 0.0297946 0.0321303 0.0330529 0.033848 0.035894 0.0343999 0.0287871 0.0270648 0.0309971 0.0394935 0.0429062 0.0397017 0.0353262 0.0365271 0.0434791 0.0501846 0.0523049 0.0497766 0.0494931 0.0494741 0.0492175 0.0489986 0.049104 0.0497538 0.0511176 0.0519165 0.0473847 0.0353666 0.0306 0.0402696 0.0456903 0.0390612 0.0303337 0.0257476 0.0247094 0.0257024 0.0265989 0.0255546 0.0234442 0.0214811 0.0202756 0.021557 0.0329328 0.0440872 0.0349312 0.0286709 0.0286142 0.0303867 0.0343046 0.0373137 0.0377933 0.0370501 0.0363637 0.0327134 0.0268904 0.0251671 0.0342179 0.0454803 0.0437374 0.0317047 0.0251982 0.0244344 0.0264483 0.0286549 0.0293818 0.0285638 0.0274584 0.0275832 0.0290267 0.0275826 0.0226439 0.0195988 0.019074 0.0209683 0.0266596 0.0354668 0.0393365 0.0354113 0.0338232 0.0332182 0.0333213 0.0351443 0.0356433 0.0336975 0.0324416 0.0397087 0.0472513 0.0460458 0.0372951 0.0302191 0.0281206 0.0272454 0.025589 0.0237308 0.0226198 0.0223882 0.0226824 0.0235506 0.0248604 0.0262792 0.02742 0.0273195 0.0256897 0.0234682 0.0219411 0.022766 0.0267641 0.0323014 0.0340192 0.0317051 0.0396006 0.046155 0.0487602 0.0432495 0.0382076 0.0350895 0.0339362 0.0337966 0.0341171 0.0356593 0.0381576 0.0401477 0.0401935 0.0357859 0.0286753 0.0305614 0.037315 0.0419443 0.0443593 0.0461081 0.0479207 0.0499096 0.0517894 0.0537778 0.0557896 0.0580677 0.0602289 0.0621076 0.0612692 0.05359 0.0362513 0.0242574 0.0181775 0.017554 0.0247986 0.04424 0.0581463 0.0622447 0.0607046 0.0556404 0.0493498 0.0431845 0.0363452 0.033113 0.0316847 0.0317044 0.0332237 0.0365093 0.0401249 0.0440668 0.0478156 0.0522848 0.0554872 0.0582007 0.0627211 0.0673828 0.0652565 0.0426812 0.0305797 0.0344016 0.0424656 0.0535329 0.0668131 0.0709769 0.0723011 0.0265424 0.0238026 0.0244039 0.0261365 0.0304596 0.035733 0.0382129 0.0364211 0.0330931 0.030908 0.0297604 0.0300427 0.0320893 0.0322003 0.0320316 0.0323648 0.032562 0.0335982 0.0335504 0.0316132 0.029533 0.0296704 0.0301921 0.0299614 0.0294752 0.0288016 0.0277237 0.0262373 0.024258 0.0223571 0.0221451 0.0241559 0.0268014 0.0276113 0.0268105 0.0255684 0.024839 0.0247244 0.0248935 0.0253675 0.0259137 0.0260528 0.0254206 0.0241156 0.0221854 0.0216381 0.0216385 0.0228824 0.0261003 0.0228366 0.0230275 0.0275393 0.0295714 0.0305847 0.0324411 0.0341647 0.0353527 0.0359796 0.0361107 0.0359139 0.0353786 0.0343593 0.0326629 0.0309498 0.0303205 0.0306481 0.0310411 0.0302463 0.027829 0.0258876 0.0249501 0.0243027 0.0237597 0.0234865 0.0240773 0.0267733 0.0304377 0.033799 0.0356417 0.0354012 0.0368042 0.0385453 0.0363678 0.0323617 0.0306688 0.0308894 0.0304201 0.0288633 0.0276291 0.0271095 0.0272371 0.0275868 0.0280293 0.0285117 0.0289386 0.0293018 0.0296303 0.0298018 0.0298622 0.0297697 0.0293567 0.0289885 0.0285965 0.0284501 0.0283046 0.027808 0.0268388 0.0261035 0.0261047 0.0267225 0.0311071 0.0383232 0.0388271 0.036173 0.0331238 0.0290891 0.0260224 0.024482 0.0240702 0.0245866 0.0258123 0.0273349 0.0288774 0.0301441 0.0310617 0.031674 0.0320369 0.0321078 0.0322016 0.0322007 0.0322536 0.0323311 0.0323472 0.0321853 0.0318185 0.031133 0.0298994 0.0282771 0.0272292 0.0277821 0.0298009 0.0313054 0.031809 0.0323374 0.0336852 0.0357172 0.0373103 0.0385972 0.0400682 0.0409283 0.0407539 0.0396063 0.0378143 0.0359265 0.0361242 0.0372672 0.0363795 0.0347126 0.0344181 0.0347704 0.0353769 0.0360518 0.0365759 0.0368292 0.0368763 0.036808 0.0366732 0.0365601 0.0364159 0.0360325 0.0350403 0.0336048 0.0325686 0.0330556 0.0375194 0.0375823 0.0375432 0.0400049 0.0427145 0.0413912 0.0400538 0.0402543 0.0404613 0.0403294 0.0400237 0.0399577 0.0404886 0.0413882 0.0415742 0.0407923 0.0399475 0.0394382 0.0366497 0.0286346 0.0225392 0.0207419 0.0204379 0.020924 0.022446 0.0247608 0.0265859 0.0263834 0.0249056 0.0232931 0.0219207 0.0220568 0.0234665 0.0272793 0.0297549 0.0302092 0.0311204 0.0349926 0.0393609 0.0420623 0.0440375 0.0468078 0.0486875 0.050087 0.050279 0.0493344 0.0477324 0.0463263 0.0448549 0.0405998 0.0314616 0.0295548 0.0328041 0.0329357 0.0334669 0.0354575 0.0333537 0.0277986 0.0260154 0.030962 0.0420118 0.0479616 0.0466615 0.0454563 0.0461445 0.0490055 0.0519789 0.0519757 0.0500296 0.0496978 0.0496181 0.0494349 0.0494116 0.0496653 0.0505459 0.0517556 0.051576 0.0458127 0.0334605 0.0295841 0.0416997 0.0478296 0.0408892 0.0314952 0.0266562 0.0255278 0.0267241 0.0267821 0.0249328 0.0229839 0.0214772 0.0220913 0.0274002 0.0373292 0.0425898 0.0330933 0.0269212 0.0288734 0.031402 0.0350964 0.0370232 0.0365451 0.0360129 0.0363866 0.0349242 0.0285625 0.0244997 0.0305384 0.0453008 0.0461755 0.0357705 0.0287775 0.0278008 0.0298927 0.0317482 0.031574 0.0306904 0.0286909 0.0280027 0.028523 0.0280608 0.0243564 0.0208873 0.0209457 0.0245179 0.0313542 0.0375678 0.038481 0.0344462 0.0335094 0.033435 0.0341513 0.0359859 0.0364354 0.0348099 0.0325454 0.0391509 0.047861 0.0479316 0.0402285 0.032437 0.0295249 0.0286609 0.0270364 0.0249031 0.0233806 0.0225741 0.0225402 0.0229426 0.0234603 0.0240479 0.024228 0.0236218 0.0225713 0.0218862 0.0220573 0.0243524 0.0284087 0.0321462 0.0328462 0.0333607 0.0416951 0.0470572 0.0473166 0.041547 0.0366775 0.0338762 0.0328403 0.0323927 0.0325877 0.0338682 0.0370846 0.0395038 0.0405793 0.0395421 0.029404 0.026665 0.0292568 0.0317496 0.033292 0.0338619 0.0341511 0.0345922 0.034908 0.0349881 0.0350744 0.0355257 0.0366716 0.0384675 0.0394932 0.0367387 0.0296691 0.020165 0.0178754 0.0191396 0.0306561 0.0486379 0.0594435 0.0624252 0.0608178 0.0562688 0.0502703 0.0446862 0.0380546 0.0347105 0.0324914 0.0328465 0.0344005 0.0380434 0.0418472 0.0452835 0.0487907 0.0525009 0.0552867 0.058545 0.0638284 0.0682849 0.0683886 0.0522522 0.036077 0.0413334 0.0547799 0.0643439 0.0666806 0.0677933 0.0722067 0.0267859 0.0236051 0.0238546 0.0248401 0.0280848 0.0341881 0.0387043 0.0393644 0.0368306 0.0332344 0.0302383 0.0287153 0.0293693 0.0308986 0.031789 0.0322708 0.0327542 0.0329787 0.0322253 0.0301701 0.0291328 0.029989 0.0310624 0.0310743 0.0306744 0.0302106 0.0291667 0.0275305 0.0256697 0.023246 0.0218445 0.0223057 0.0243702 0.026363 0.0268459 0.0266203 0.0262269 0.0260364 0.0260854 0.0262263 0.0262224 0.0256779 0.024674 0.023521 0.0219869 0.0213658 0.0209259 0.0205039 0.0223506 0.0209654 0.0213221 0.0255681 0.0288895 0.0294031 0.0309395 0.033268 0.0351978 0.0361364 0.0364742 0.0363145 0.0357373 0.0349355 0.0335082 0.0313652 0.0298605 0.0293715 0.0294555 0.029089 0.0277948 0.0260194 0.0248308 0.0240801 0.0237133 0.0239939 0.0259373 0.0295582 0.0328194 0.035125 0.0361505 0.0365017 0.0386484 0.0408792 0.0400122 0.0352548 0.0312913 0.0309104 0.0311003 0.0302118 0.0289088 0.0278976 0.027602 0.0276268 0.0277794 0.0279859 0.0282139 0.0284252 0.0284975 0.0285577 0.0284456 0.0282018 0.0278643 0.0274348 0.0269465 0.0264019 0.0257279 0.0253572 0.025268 0.0253873 0.0260402 0.0280033 0.0369894 0.0393765 0.0378539 0.0365075 0.0348768 0.031647 0.0285179 0.0265789 0.0254559 0.025099 0.0253618 0.026055 0.0268329 0.0277426 0.028722 0.0296377 0.0303462 0.0308839 0.0311435 0.0312395 0.0311885 0.0310492 0.0307189 0.0301438 0.029325 0.0283013 0.0275278 0.027317 0.0280125 0.0294223 0.0309571 0.0323152 0.0330513 0.0339854 0.0356197 0.0375393 0.0388607 0.0400935 0.0413214 0.0420602 0.0418632 0.0406302 0.0390829 0.036461 0.0357113 0.0370537 0.0370352 0.0351504 0.0341878 0.034204 0.0345496 0.0350194 0.0354897 0.0358248 0.0360076 0.0360165 0.035927 0.035736 0.0353947 0.0347695 0.0339396 0.0332532 0.0332164 0.0353478 0.0384391 0.0381644 0.0389566 0.0418253 0.0436027 0.0425877 0.0417551 0.0413989 0.0409499 0.0403283 0.0399532 0.0402334 0.0413047 0.0424172 0.0426819 0.0420607 0.0405369 0.0395728 0.0390791 0.033949 0.0253184 0.0213041 0.0202216 0.020021 0.0201579 0.0207928 0.0217989 0.0222858 0.0217309 0.0208751 0.0208409 0.0220393 0.0240567 0.0283477 0.0330534 0.0357215 0.0365773 0.0380464 0.0398101 0.0417006 0.0429291 0.0447544 0.0463604 0.0476152 0.0477469 0.0469988 0.0461285 0.0452488 0.0433856 0.0379057 0.0297493 0.0297964 0.0335616 0.0325172 0.0327241 0.0341941 0.0322075 0.0270595 0.0251118 0.0282458 0.0408464 0.0502313 0.0516281 0.0507247 0.0512247 0.0519832 0.0525874 0.051769 0.0502627 0.0499757 0.0498954 0.0498946 0.0500261 0.0506683 0.0516996 0.0522699 0.0501618 0.0421075 0.0311461 0.0284902 0.0426223 0.0502577 0.0431896 0.032658 0.0268786 0.0261916 0.0274973 0.0271419 0.0256588 0.0250825 0.0265303 0.030257 0.0353801 0.0385048 0.03648 0.0286477 0.0266871 0.0294793 0.0323386 0.0353675 0.0364547 0.0358032 0.0351718 0.0357683 0.036047 0.0305897 0.0244582 0.0277636 0.0438595 0.0489587 0.0411785 0.033197 0.0309571 0.0320825 0.0337125 0.0334907 0.0316046 0.0294916 0.028502 0.0283975 0.0288686 0.027774 0.0250126 0.0256187 0.0299176 0.0354351 0.0386569 0.0372734 0.0342007 0.03347 0.0337934 0.0345982 0.0356148 0.0361673 0.0356227 0.0336764 0.0385376 0.0481402 0.0500862 0.0444737 0.0358984 0.0315784 0.030343 0.0290522 0.0268685 0.024999 0.0235809 0.0228349 0.022579 0.0223919 0.0223864 0.0222764 0.022119 0.0222649 0.0229547 0.0246181 0.0273257 0.0300852 0.0315528 0.0320455 0.0366197 0.0437011 0.0472928 0.046155 0.0401493 0.0357309 0.0331533 0.0323776 0.0319766 0.032275 0.0333613 0.0364949 0.0393786 0.040309 0.0418445 0.0326042 0.0253916 0.0250834 0.0244728 0.0236702 0.0228349 0.021992 0.0213426 0.0210681 0.0208859 0.0207601 0.0207908 0.0210471 0.0213708 0.021742 0.0216772 0.0208384 0.0191984 0.0202273 0.0253907 0.0402983 0.0535259 0.0604985 0.0625488 0.061355 0.0574441 0.0527262 0.0474886 0.0428519 0.0385877 0.0373654 0.0370642 0.0392159 0.0418047 0.0447232 0.0474599 0.0503511 0.0533056 0.0555428 0.0595337 0.0657947 0.0694691 0.0704646 0.0617107 0.0444912 0.0418821 0.0510681 0.0565046 0.0569418 0.0653611 0.0720733 0.0273404 0.0235189 0.0232942 0.0236855 0.0248367 0.0288007 0.0344701 0.0382158 0.03838 0.0363576 0.0325971 0.0294172 0.027801 0.0278862 0.0287096 0.0293136 0.0298773 0.0298953 0.0292062 0.0285343 0.0289932 0.0304581 0.0310107 0.031001 0.0306632 0.030746 0.0305167 0.0290452 0.0270553 0.0248989 0.0225051 0.0215109 0.0219464 0.0232894 0.0246819 0.0252723 0.025521 0.0254091 0.0253201 0.0251104 0.0245004 0.0238507 0.0232105 0.0226417 0.0218991 0.0213326 0.0208588 0.0203795 0.0203419 0.0201576 0.0216179 0.0257644 0.0285962 0.0286805 0.0294733 0.0312506 0.0335565 0.0353467 0.0362743 0.0364046 0.0357735 0.0350167 0.0342319 0.0324009 0.0300366 0.0286917 0.0279681 0.0273131 0.0264855 0.0254278 0.0246271 0.0242728 0.0247384 0.0267253 0.0302297 0.0336818 0.0356201 0.0362808 0.0365704 0.0370843 0.0387394 0.0411869 0.0415062 0.0390408 0.0335213 0.0309042 0.0311936 0.0312523 0.030402 0.0290656 0.028296 0.0279242 0.0277501 0.0276166 0.0275035 0.0273714 0.0271603 0.0268414 0.0264945 0.0259931 0.0256815 0.0253618 0.0253168 0.0255473 0.0261019 0.0268251 0.0275807 0.0280762 0.0292563 0.0326394 0.0393217 0.0389372 0.0367552 0.0357123 0.035905 0.0343095 0.0316476 0.0298579 0.0284287 0.0273638 0.0266408 0.0263385 0.0263156 0.0265126 0.0267848 0.0271457 0.0274859 0.0278529 0.0280993 0.0282353 0.028169 0.02795 0.0276057 0.0273178 0.027215 0.0273995 0.028239 0.0293515 0.0301914 0.0307868 0.0317316 0.0331026 0.0343835 0.0356823 0.037357 0.0389649 0.0400135 0.0410183 0.042001 0.0428095 0.0424898 0.0413373 0.04011 0.0378009 0.035571 0.0364952 0.0375968 0.0362736 0.034672 0.0340899 0.0341416 0.0343873 0.0346593 0.0348191 0.0349858 0.035005 0.0349604 0.0348161 0.0346005 0.0343955 0.0343086 0.0348255 0.0363089 0.03833 0.0392762 0.0396736 0.0412393 0.0435961 0.0442273 0.0437311 0.0430077 0.0423377 0.0413721 0.0405157 0.0400966 0.0403756 0.0412543 0.0423219 0.0427635 0.0425025 0.0410746 0.0393157 0.0392425 0.0381147 0.0300459 0.0236058 0.0214608 0.0208795 0.0205443 0.0203701 0.0203738 0.0205112 0.0206092 0.0207558 0.0214041 0.0226152 0.02396 0.0269663 0.0323813 0.0370205 0.0395759 0.0407792 0.04118 0.0417492 0.0423217 0.0432731 0.0441897 0.0450035 0.0450842 0.0449323 0.0446687 0.0436685 0.0405438 0.0340708 0.0281596 0.0305964 0.0342847 0.0320816 0.0319033 0.0329304 0.0311569 0.0272327 0.0245645 0.0250962 0.0341665 0.0478789 0.0540859 0.0544315 0.0541696 0.0541723 0.053467 0.0521595 0.0510849 0.0508775 0.0508538 0.051069 0.0514823 0.0521671 0.0524447 0.051121 0.0460189 0.0370238 0.0279333 0.0270072 0.0426036 0.0523571 0.0459255 0.0334977 0.0272708 0.0266352 0.0282756 0.0282789 0.0272392 0.0271557 0.0287604 0.0309064 0.0316799 0.030328 0.0275944 0.026184 0.0274345 0.0303303 0.0330137 0.0352078 0.0357588 0.0354017 0.0346895 0.035417 0.0356897 0.0317649 0.0249429 0.0262392 0.041257 0.0504989 0.0470786 0.0388347 0.034282 0.0336975 0.0348164 0.0348942 0.0327433 0.0303532 0.0291987 0.0291976 0.0306806 0.0318433 0.0314677 0.0324491 0.035337 0.0384078 0.038917 0.0365344 0.0340317 0.0336532 0.0341442 0.0348027 0.0350338 0.0362674 0.0363326 0.0348082 0.0385095 0.0483621 0.0520241 0.0491156 0.0410945 0.0345917 0.0323136 0.0315194 0.0298709 0.0278955 0.026512 0.0253487 0.0246063 0.0239235 0.0237575 0.0237739 0.0242945 0.0250243 0.0263621 0.0279498 0.0294556 0.0304604 0.0315508 0.0345367 0.0403934 0.0452391 0.0469983 0.0449183 0.039482 0.035677 0.0333557 0.0323621 0.032181 0.0326712 0.0341617 0.0369615 0.0398832 0.0405405 0.042239 0.0375619 0.0256792 0.0240796 0.0226745 0.0216021 0.0215015 0.022189 0.02355 0.024397 0.0243519 0.0237806 0.0231275 0.0225903 0.0223 0.0221663 0.0222874 0.0229814 0.0253364 0.0300707 0.0386647 0.0509717 0.0578358 0.0613934 0.0625763 0.0618334 0.0591946 0.0555626 0.0518142 0.048126 0.0456263 0.0437903 0.0441424 0.0447903 0.046506 0.0481412 0.0500624 0.0523004 0.0543526 0.0562267 0.0616657 0.0683739 0.0705736 0.071129 0.068948 0.0560859 0.0447128 0.0426271 0.0453582 0.0495707 0.0641032 0.0721258 0.0282984 0.0237041 0.0226284 0.0228784 0.0231361 0.0239028 0.0260773 0.0305932 0.0329622 0.0326946 0.0309228 0.0284905 0.0267266 0.0260359 0.0262533 0.0267681 0.0273549 0.0277322 0.0280178 0.0285152 0.0292663 0.029577 0.029279 0.0282122 0.0277296 0.0284153 0.0301697 0.030402 0.0283447 0.0264869 0.0243607 0.0222287 0.021383 0.0214775 0.0221105 0.0226723 0.0232059 0.0233668 0.0235398 0.0236193 0.0236245 0.0236843 0.0238012 0.0240096 0.0241671 0.0234325 0.0226 0.0220651 0.0215253 0.0219275 0.0244995 0.0277763 0.0286929 0.0284049 0.0286867 0.0298967 0.0316233 0.0334143 0.0347221 0.0353575 0.0351911 0.0347543 0.0345682 0.0336966 0.0312884 0.0290734 0.0278875 0.0270411 0.0262031 0.025636 0.0254371 0.0259505 0.0275575 0.0304368 0.0338453 0.0368083 0.0381239 0.0382965 0.0378138 0.0380786 0.0392376 0.0406292 0.0413207 0.0406263 0.0369583 0.0322728 0.0310049 0.0313205 0.0315253 0.0306454 0.0295166 0.0286562 0.028065 0.0275003 0.0269928 0.0265001 0.0260259 0.0257513 0.0253577 0.0253419 0.0252421 0.0256056 0.0262662 0.0273155 0.0287383 0.0301945 0.0316502 0.0328825 0.0343429 0.0364893 0.0382631 0.0375885 0.0350732 0.0337539 0.0354249 0.0361999 0.0345256 0.0333565 0.0324546 0.0315808 0.0307636 0.0299843 0.0292864 0.0286407 0.0281239 0.0277422 0.0275052 0.0273765 0.0272701 0.0271806 0.0271348 0.0271762 0.0274058 0.0279764 0.0289743 0.0302241 0.0312934 0.0317613 0.0317487 0.0318098 0.0324262 0.0336579 0.0351535 0.0366857 0.0382726 0.039671 0.0406865 0.041423 0.0421473 0.0425878 0.0422129 0.0412492 0.0404444 0.0392241 0.0363059 0.0356913 0.0374261 0.0376713 0.0360344 0.0349601 0.0346455 0.0347778 0.0350705 0.0353241 0.035488 0.0355925 0.0356866 0.0358231 0.0360337 0.0364771 0.0372011 0.0380955 0.0389154 0.0396647 0.0404453 0.0414761 0.0430304 0.0442903 0.0446759 0.0444121 0.0440268 0.043349 0.0424887 0.041648 0.0411044 0.0411188 0.0415547 0.0421071 0.042349 0.0421107 0.0411397 0.038993 0.0388144 0.0401532 0.034948 0.0269952 0.0236698 0.0231263 0.02278 0.0222641 0.0216421 0.0212925 0.0213166 0.0217914 0.0224903 0.0231614 0.0237067 0.0252984 0.0285741 0.032745 0.0368947 0.040007 0.0413697 0.0423006 0.0421074 0.0432362 0.0430557 0.0438639 0.0437373 0.0435594 0.0427759 0.0403184 0.0357519 0.0296927 0.0271515 0.0318249 0.0349476 0.0315757 0.0311283 0.0324643 0.0318733 0.0287644 0.0249604 0.023168 0.0252479 0.0347559 0.046233 0.0521589 0.053474 0.0535114 0.0532798 0.0530358 0.0526999 0.0525294 0.0524402 0.0524609 0.0520822 0.0517142 0.0494762 0.04465 0.0378504 0.0304157 0.0253433 0.0255182 0.0404351 0.0535254 0.0495164 0.0357545 0.0279174 0.0268586 0.0285887 0.0295421 0.0286818 0.0276024 0.0269385 0.0266989 0.0264432 0.0262886 0.02654 0.0273438 0.0289343 0.0311613 0.0332516 0.0346477 0.0348291 0.0346061 0.0345638 0.0351704 0.0347736 0.0307266 0.0255632 0.02756 0.0378353 0.0496435 0.0518872 0.045994 0.0390597 0.0357742 0.0353471 0.0356895 0.0346193 0.0321772 0.030616 0.0309134 0.0326287 0.0346675 0.036513 0.0375865 0.0386353 0.0389658 0.0381181 0.0351908 0.0335184 0.0338577 0.0344634 0.0348986 0.0350283 0.0360253 0.0364614 0.0363915 0.039792 0.0493496 0.0540227 0.0534217 0.0479838 0.0398842 0.0349048 0.0338192 0.0334813 0.0320193 0.0306279 0.0296224 0.0290952 0.0287709 0.0284768 0.0287897 0.0291474 0.0299088 0.0305549 0.0312817 0.0320264 0.0332311 0.0355613 0.0393105 0.0433936 0.046031 0.0464271 0.0443192 0.0400141 0.0370525 0.0350954 0.0341826 0.0340043 0.034703 0.0366254 0.038764 0.0406104 0.0408069 0.0423508 0.0429272 0.0275538 0.0251196 0.0244635 0.0233588 0.0240355 0.0267832 0.0302544 0.0330075 0.0345354 0.0350732 0.0349544 0.0344558 0.0338456 0.033684 0.034708 0.0375322 0.0420253 0.0470815 0.052937 0.0582301 0.0602688 0.0614958 0.0621054 0.0618096 0.0603878 0.0582439 0.0557318 0.0535906 0.0515474 0.050651 0.0500318 0.0502203 0.0505991 0.0514396 0.0526544 0.0541192 0.0553369 0.0577335 0.0652316 0.070723 0.0712077 0.0714469 0.0713351 0.0658489 0.0550323 0.046685 0.0458218 0.0521641 0.0652311 0.0722173 0.0295593 0.0248064 0.0221624 0.0219184 0.0221913 0.022478 0.0225632 0.0233003 0.0239249 0.0243313 0.024302 0.023833 0.0233154 0.0230945 0.0233737 0.0239384 0.0246967 0.0254409 0.026111 0.0265463 0.0265288 0.0256623 0.0245397 0.023401 0.0229218 0.0241249 0.0276711 0.0305814 0.0293034 0.0274187 0.0262898 0.024659 0.0233332 0.0226545 0.0225633 0.0230367 0.0234934 0.0242202 0.024733 0.0253048 0.0259295 0.0263909 0.0267832 0.0272128 0.0275914 0.0271428 0.0265292 0.0262667 0.0258747 0.0265805 0.0278127 0.0286895 0.0284256 0.0280218 0.0285154 0.0298492 0.0313122 0.0322675 0.0330486 0.0335406 0.0338744 0.0340444 0.0345464 0.0347954 0.0334203 0.0308566 0.0290515 0.0281643 0.0275476 0.0271497 0.0271463 0.0275676 0.0284449 0.0297296 0.0314713 0.0337202 0.0360894 0.0375118 0.0380367 0.0385244 0.039194 0.0395349 0.039611 0.0395076 0.0384815 0.0354534 0.0320959 0.0307947 0.031587 0.031952 0.0313174 0.0304579 0.0297661 0.0290446 0.0284581 0.027978 0.0276209 0.0273341 0.0274189 0.0274368 0.0279092 0.0283287 0.0290297 0.0294762 0.0300563 0.0305976 0.0314388 0.032561 0.0338315 0.035145 0.0345804 0.0336636 0.0323685 0.0320307 0.0338444 0.0368562 0.0364717 0.0359003 0.0356574 0.0353017 0.0348665 0.0343388 0.0337196 0.0330097 0.0322313 0.0314811 0.0308356 0.0303043 0.0298926 0.0296995 0.0297464 0.0301062 0.0307403 0.031585 0.0323983 0.0329448 0.033124 0.0330395 0.0329058 0.0329353 0.0333084 0.0341117 0.0352738 0.0365878 0.0378465 0.0389955 0.0399227 0.0405654 0.0409155 0.0408942 0.0406202 0.0402443 0.0399918 0.0398328 0.0381193 0.0356973 0.0363069 0.0381745 0.0378963 0.036913 0.0364405 0.036413 0.0367566 0.0371383 0.0375769 0.0379146 0.0381949 0.0384135 0.0386455 0.0388813 0.0391409 0.0393778 0.0397692 0.0403057 0.041036 0.0420012 0.042863 0.0434355 0.0437347 0.0439123 0.0439049 0.0437092 0.0433111 0.0428981 0.0425245 0.0423766 0.0422414 0.0420706 0.0418415 0.0413499 0.0405043 0.0385373 0.038139 0.0405568 0.0390784 0.0308651 0.0258664 0.0246267 0.0242832 0.0236529 0.0231275 0.0228376 0.0228182 0.0229492 0.023151 0.0232435 0.0234481 0.0240557 0.0252125 0.0270932 0.0301897 0.0341853 0.0372202 0.0397454 0.0405387 0.0418828 0.0415531 0.0423529 0.0413479 0.0397785 0.0373645 0.0341345 0.0301623 0.0265746 0.0268438 0.0333458 0.0356241 0.0310519 0.0299279 0.0318266 0.0320139 0.0289088 0.0252013 0.0228804 0.0219817 0.0234907 0.0285913 0.0359236 0.0414384 0.0448484 0.0470176 0.0483165 0.0486961 0.0483953 0.0476112 0.0464977 0.0444192 0.0417215 0.0374055 0.0328511 0.0281713 0.0248753 0.0234687 0.0243672 0.0348202 0.0521614 0.0541232 0.0412825 0.0295627 0.0268016 0.0279104 0.0297208 0.0303516 0.0301087 0.0297853 0.0293977 0.0291484 0.0290457 0.0291785 0.0297064 0.0306574 0.0319403 0.0332659 0.0341932 0.0344691 0.0345762 0.0348042 0.0346319 0.0327882 0.028608 0.0258107 0.0294849 0.0371743 0.0448652 0.0522709 0.0528788 0.0470747 0.0400134 0.0363067 0.0359203 0.0359342 0.034929 0.0334064 0.0334519 0.0334166 0.0350256 0.0364046 0.0371204 0.0372316 0.0366313 0.0352521 0.0338398 0.0334881 0.034037 0.0347025 0.0351202 0.0357528 0.0366017 0.0367087 0.0376502 0.0428222 0.0520111 0.0567179 0.056339 0.0551356 0.0481958 0.0393192 0.0354214 0.0364962 0.0364906 0.0357259 0.0351673 0.0355456 0.035687 0.035847 0.0360693 0.0363367 0.0364915 0.0367226 0.0370934 0.0377994 0.0390184 0.0408066 0.0428988 0.0448059 0.0457738 0.0461664 0.044647 0.0423364 0.040497 0.0392081 0.0385905 0.0386749 0.0391162 0.0400001 0.040821 0.0412743 0.0409404 0.0434705 0.0482082 0.0327222 0.0264951 0.0273541 0.0279851 0.0287539 0.0314111 0.035243 0.0390443 0.0421683 0.0446058 0.0465287 0.0480905 0.0493761 0.0505364 0.0519153 0.0537133 0.0556337 0.057351 0.0586773 0.0594024 0.0600413 0.0605087 0.0609411 0.0607611 0.0602556 0.0592771 0.0580887 0.056904 0.0558157 0.0549093 0.0543237 0.0539776 0.0538582 0.054081 0.0546242 0.0553806 0.056095 0.0608247 0.0697496 0.0717323 0.0715548 0.0717849 0.0720256 0.0714378 0.0678568 0.0628703 0.059492 0.0640366 0.0700451 0.0724008 0.0304738 0.0264414 0.0229073 0.0215371 0.021349 0.0213337 0.021402 0.0213913 0.021398 0.0213549 0.0213114 0.0212043 0.0211856 0.0211181 0.0211285 0.0212316 0.0213978 0.0216258 0.0218117 0.0218107 0.021636 0.0212804 0.0211491 0.0209505 0.0211268 0.0224263 0.0263467 0.0303379 0.029531 0.0276351 0.02708 0.0266725 0.0260752 0.0256703 0.0254818 0.0255563 0.0258313 0.0262387 0.0266218 0.0269708 0.0272188 0.027389 0.027495 0.0275667 0.0275786 0.0276008 0.0276243 0.0276395 0.0277021 0.0279269 0.0278891 0.0278007 0.0277266 0.0276971 0.0286902 0.0310581 0.032264 0.0324672 0.0326233 0.0327972 0.033081 0.0334334 0.03415 0.035152 0.0354983 0.0339334 0.0316101 0.0303442 0.029985 0.0296169 0.029372 0.0293571 0.0294137 0.0296065 0.0300048 0.0306786 0.0318598 0.0331643 0.0343053 0.0351235 0.0357046 0.0363748 0.0370833 0.0376222 0.0376288 0.0368807 0.0348137 0.0311987 0.030573 0.0320555 0.032414 0.03222 0.0319931 0.0316602 0.0314983 0.0311873 0.0312383 0.0309513 0.0311051 0.0309854 0.0311313 0.0311001 0.0310611 0.030878 0.0306512 0.0304316 0.0302668 0.03028 0.0305435 0.030849 0.0306667 0.0306531 0.0306626 0.0312516 0.0325568 0.036569 0.0372604 0.0369173 0.0369925 0.037073 0.0370578 0.036942 0.0367792 0.0365466 0.0362706 0.0360028 0.0357484 0.0353601 0.0352321 0.0350171 0.03504 0.0349969 0.0351987 0.0353024 0.0353918 0.0353735 0.0352893 0.0351233 0.0349777 0.0350254 0.0350427 0.0353259 0.0357361 0.0362778 0.0368586 0.037358 0.0378405 0.0382201 0.0384261 0.0386808 0.0388795 0.0391398 0.0393907 0.0396496 0.0392947 0.0367614 0.0354648 0.0376499 0.0387884 0.0386227 0.0385118 0.0385035 0.0385636 0.0386569 0.0387723 0.038916 0.0389803 0.0391075 0.0391761 0.0392938 0.039437 0.0396014 0.0398165 0.040096 0.0403872 0.0408444 0.0411167 0.0412355 0.0413501 0.041455 0.0416041 0.0416589 0.041725 0.0416654 0.0416113 0.0414456 0.0413416 0.0411206 0.0409619 0.0405781 0.0398312 0.0380215 0.0375005 0.040247 0.0415769 0.0349211 0.0275649 0.02537 0.0249147 0.0244031 0.0239956 0.0237877 0.023659 0.0235777 0.0234789 0.0233907 0.0233558 0.023432 0.0236051 0.0240082 0.0247405 0.0261773 0.0272062 0.0298755 0.030125 0.0317227 0.0322082 0.031963 0.0317892 0.0307283 0.0296509 0.0285522 0.0265896 0.0253185 0.0269849 0.0339542 0.0365348 0.0308379 0.0276126 0.0281525 0.0286334 0.0266028 0.0240526 0.0226673 0.0218643 0.0214499 0.0216105 0.0221923 0.023614 0.0251979 0.026729 0.0280999 0.0289429 0.0287105 0.0280825 0.026658 0.0263696 0.0242359 0.0241944 0.0231854 0.0228507 0.0225863 0.0227903 0.0239951 0.0289374 0.0457681 0.0564515 0.0512434 0.033828 0.0268458 0.0265565 0.028793 0.0304639 0.0313554 0.0317193 0.0318931 0.0319468 0.0319846 0.0320218 0.0321244 0.0323545 0.0327981 0.0332284 0.0335644 0.0337089 0.0336365 0.0334318 0.032661 0.029917 0.0262245 0.0266157 0.0329352 0.0385375 0.0405873 0.0434566 0.0516052 0.0557546 0.0476103 0.0385978 0.0359526 0.0363067 0.0361898 0.0361531 0.0357131 0.0359591 0.0359295 0.0357682 0.0358257 0.0357934 0.0356341 0.0355152 0.0354596 0.0354196 0.0356004 0.0358594 0.0360973 0.0365614 0.037203 0.036638 0.0388598 0.0470172 0.0564281 0.0591019 0.0590304 0.0584944 0.0571819 0.0467094 0.0363927 0.0374149 0.0388878 0.0384012 0.0391091 0.0392919 0.0399755 0.040874 0.0409663 0.0414302 0.0413899 0.0414725 0.0416778 0.0420174 0.0423873 0.0429038 0.0434777 0.0439886 0.0442311 0.0442944 0.0440077 0.0435525 0.0430914 0.0426868 0.0424163 0.0425361 0.0417389 0.0420848 0.0418725 0.0413997 0.041204 0.0462155 0.0520942 0.0421889 0.0280383 0.0279222 0.0311239 0.0324245 0.0339757 0.0358624 0.0378972 0.0399727 0.0419834 0.0438422 0.0455758 0.0472639 0.0488883 0.0503804 0.0516882 0.0528913 0.0537978 0.0547439 0.0554347 0.0561386 0.0565764 0.0569774 0.0572189 0.0573515 0.0572928 0.0569806 0.0567547 0.0565523 0.0562333 0.0560603 0.0554719 0.0555532 0.0553094 0.0555153 0.0558813 0.0568415 0.0659599 0.071946 0.0719973 0.0719811 0.0720985 0.0721404 0.0722716 0.0722932 0.0721454 0.0716649 0.0721177 0.0725081 0.0724705 0.0375823 0.0380766 0.0382966 0.0381597 0.037818 0.0373375 0.0367047 0.0360584 0.0353944 0.0349948 0.035066 0.0317697 0.0231878 0.0245147 0.0209894 0.0223444 0.0229197 0.0231547 0.0232444 0.0232875 0.0232799 0.0232515 0.0232338 0.0232226 0.0232109 0.0232199 0.0232417 0.0232471 0.0232854 0.0233407 0.0233807 0.0234588 0.023537 0.0236358 0.0237516 0.023859 0.0240707 0.0245752 0.0241646 0.0218974 0.0197537 0.0192486 0.0215683 0.0255652 0.0271911 0.0292328 0.0302874 0.0306728 0.0306491 0.0305132 0.030335 0.0301473 0.0299253 0.0298349 0.0295485 0.0294613 0.0292197 0.0290319 0.0288632 0.0287148 0.0286044 0.0284883 0.0283692 0.028149 0.0275069 0.0257127 0.0252827 0.0293429 0.0309919 0.0312871 0.0309831 0.0291326 0.0261491 0.0237133 0.0297979 0.0302146 0.0311846 0.0317787 0.0319991 0.0320817 0.031886 0.0319066 0.0316654 0.0318548 0.0315982 0.0319021 0.0316013 0.0319322 0.0318074 0.0317715 0.0318556 0.0317337 0.0320147 0.0317561 0.0314409 0.030463 0.0294847 0.0286578 0.0273094 0.0271286 0.0273797 0.0274188 0.0274584 0.0273788 0.0287261 0.0270732 0.0266915 0.0267607 0.0267525 0.0267208 0.0265953 0.0265349 0.0266105 0.0266748 0.0268105 0.0267842 0.0270001 0.0270783 0.0271389 0.0273634 0.0277757 0.0277241 0.0279523 0.0288587 0.0300564 0.0313657 0.0316259 0.0309389 0.0288072 0.0265708 0.025691 0.0256518 0.025967 0.0261144 0.0259873 0.0326074 0.035639 0.0346522 0.0328574 0.0312483 0.0302624 0.029726 0.0297542 0.0298446 0.0301643 0.0304058 0.0308261 0.0311142 0.0313635 0.0314952 0.0315716 0.0314053 0.0314377 0.0312291 0.0310453 0.0309058 0.030868 0.0308691 0.0309275 0.0308805 0.0308678 0.0310439 0.0297911 0.0258446 0.0292885 0.0288002 0.0282857 0.0292225 0.0330541 0.0372224 0.0387562 0.0385501 0.0376871 0.0360057 0.0341567 0.0322704 0.0308577 0.0297266 0.0290665 0.0286474 0.0282979 0.0280764 0.0278591 0.0276799 0.027561 0.0274336 0.0274595 0.027362 0.0276462 0.0279676 0.0289346 0.0305639 0.0316923 0.0244649 0.0217989 0.0221751 0.0228905 0.0263539 0.0359478 0.0400825 0.0392479 0.0388497 0.0387037 0.0383533 0.0381238 0.0379406 0.037817 0.0377672 0.0378359 0.0379051 0.0379175 0.0377344 0.0372503 0.0365251 0.0355593 0.0345064 0.0333359 0.0324686 0.0317882 0.0314258 0.0316982 0.0328185 0.034733 0.0357481 0.018155 0.0184602 0.0215208 0.0441877 0.0533281 0.0500793 0.0487965 0.047932 0.0474083 0.0469811 0.0468351 0.0467602 0.046868 0.0471083 0.0474217 0.0478048 0.0482499 0.0486062 0.0489421 0.0490657 0.0491038 0.0488056 0.0484634 0.0480237 0.0474307 0.047339 0.0492214 0.0498395 0.0369334 0.0227266 0.021202 0.0302243 0.0330175 0.0309845 0.0302079 0.029942 0.0300109 0.0303924 0.0312106 0.0322008 0.033086 0.0340566 0.0349047 0.0356184 0.0361894 0.0363929 0.0363941 0.0362536 0.0360209 0.0357434 0.0357603 0.0354254 0.0357684 0.0358444 0.0362604 0.036826 0.0379616 0.0393937 0.0395933 0.0373059 0.0206956 0.0394508 0.0426743 0.0421077 0.0419275 0.0418929 0.0422134 0.0429819 0.0437974 0.0445835 0.0453152 0.045809 0.0461162 0.0462154 0.0464027 0.0460787 0.0462173 0.0455422 0.0455186 0.0449393 0.0448855 0.0442691 0.044227 0.0437285 0.0435016 0.0433043 0.0429398 0.0415129 0.0374191 0.0325822 0.018668 0.0308809 0.0465029 0.0489826 0.0501566 0.0504919 0.0498644 0.0492222 0.0480271 0.046951 0.0458476 0.044808 0.0438483 0.0429063 0.0424733 0.0424329 0.0426649 0.0438488 0.0446279 0.0463926 0.0478512 0.0492354 0.0500107 0.0501998 0.0499172 0.0435912 0.0270305 0.0177815 0.0173282 0.0183831 0.0173172 0.0167466 0.0162103 0.0174875 0.0198657 0.0225585 0.0260525 0.0304482 0.0354043 0.0385395 0.0420981 0.0446682 0.0462316 0.0474811 0.0480673 0.0479263 0.0470647 0.0453252 0.0431217 0.0399941 0.0376935 0.0351634 0.0335119 0.0296262 0.0255889 0.0200689 0.017693 0.0168944 0.0175949 0.0183456 0.0404386 0.0393468 0.0381089 0.0374359 0.0369734 0.036933 0.0365254 0.0357149 0.0345222 0.0335178 0.0339251 0.0325501 0.0257519 0.0243595 0.0210124 0.0227954 0.0232997 0.0233721 0.0232943 0.023151 0.0230236 0.0229449 0.0229123 0.0229245 0.0229843 0.0230769 0.0231831 0.0232885 0.0233699 0.0234565 0.023521 0.0235999 0.0236741 0.0237488 0.0237921 0.0238284 0.0239254 0.0243012 0.0244686 0.0237781 0.021975 0.0200451 0.0201713 0.0245127 0.0277482 0.0308196 0.0313176 0.0313277 0.030937 0.0302626 0.0294177 0.0287819 0.0282299 0.0278804 0.0276917 0.0276145 0.0276048 0.0276644 0.0277614 0.0279076 0.0280648 0.0281853 0.0282434 0.0282565 0.0278995 0.0265657 0.0251994 0.0256659 0.0262268 0.0282419 0.0307375 0.0315684 0.0294031 0.0245643 0.0300735 0.0327951 0.0334337 0.0327472 0.0317068 0.030671 0.0300176 0.0293552 0.029076 0.02876 0.0286313 0.0285972 0.0287085 0.0289734 0.0294648 0.0300334 0.0306655 0.0313831 0.0318172 0.0319996 0.0318305 0.0312371 0.0302251 0.0292807 0.0279277 0.0274347 0.0279827 0.0282127 0.0280818 0.0277622 0.0252569 0.0262724 0.0284703 0.0298757 0.0301854 0.0297351 0.0288701 0.0280996 0.0273118 0.0269425 0.0264651 0.026396 0.0260949 0.0261021 0.0262212 0.0264259 0.026472 0.0269973 0.0273027 0.0279176 0.0289673 0.0303955 0.031435 0.0316067 0.0310282 0.0292238 0.0272897 0.0271136 0.0274584 0.0273386 0.0269773 0.0335282 0.0346142 0.0316126 0.0290804 0.0284188 0.0291161 0.0306131 0.0320909 0.0331608 0.0341179 0.0349164 0.0355986 0.0362179 0.0367779 0.0371748 0.0374306 0.0375711 0.0374962 0.0372674 0.0368373 0.0363159 0.0353986 0.0344412 0.0334388 0.0325546 0.0318243 0.0314713 0.0306183 0.0279278 0.0306154 0.0289076 0.0287334 0.0320133 0.0374915 0.0398408 0.0391272 0.0360317 0.0321418 0.028914 0.027018 0.0262644 0.0262869 0.0266694 0.0270305 0.0273201 0.0273727 0.0270712 0.026798 0.0264591 0.0260926 0.0257123 0.0253389 0.0249928 0.0246894 0.0251595 0.026341 0.0286946 0.0312173 0.0260774 0.0222015 0.0234624 0.0269576 0.0343786 0.0390825 0.0393321 0.0384001 0.0379929 0.0378563 0.0378953 0.0378621 0.0376194 0.037098 0.0363139 0.0356092 0.0353455 0.0356761 0.0361668 0.0363726 0.0357995 0.0343781 0.0317715 0.0288062 0.0263824 0.0248418 0.0240914 0.0245717 0.0268993 0.0315623 0.0353086 0.0196785 0.0287698 0.0396118 0.0501954 0.0506101 0.0470471 0.0454981 0.0443159 0.0433261 0.0426857 0.0422721 0.0422454 0.042432 0.0431439 0.0441122 0.0452064 0.0462433 0.04715 0.0476075 0.0477271 0.047305 0.0464438 0.0452033 0.0438311 0.0423831 0.0414256 0.0441197 0.047488 0.0402522 0.0237225 0.0252775 0.0312378 0.0302823 0.0272808 0.0262342 0.0260482 0.0266966 0.0280381 0.0302016 0.0330646 0.0357631 0.0379299 0.0391276 0.0393535 0.0385815 0.0369936 0.0351381 0.0332324 0.0314291 0.0299576 0.0287612 0.0282423 0.0281054 0.0286074 0.029938 0.0318034 0.0345356 0.0376314 0.0395921 0.0382608 0.0270885 0.039793 0.0397041 0.0359461 0.0339814 0.0341418 0.0358595 0.0388307 0.0417697 0.0442789 0.0460142 0.046535 0.0465046 0.0457346 0.0448355 0.0442046 0.0441395 0.0442242 0.0441333 0.0438443 0.043409 0.0428226 0.0422642 0.0418849 0.0418451 0.0419086 0.0421163 0.0416004 0.0394109 0.0348177 0.0246985 0.0394525 0.0488618 0.0505311 0.0504028 0.0490106 0.0465304 0.0438121 0.0418445 0.0397168 0.0379712 0.0366772 0.0357686 0.034879 0.0342354 0.033145 0.0326002 0.0320739 0.0335423 0.0356116 0.0399663 0.0445276 0.0483664 0.0504023 0.0511459 0.0477349 0.0340545 0.0210064 0.0171123 0.0175624 0.0170862 0.016413 0.0169411 0.0194085 0.0232162 0.0290941 0.0373573 0.0467865 0.0549427 0.0602746 0.062426 0.0637534 0.0641732 0.0641854 0.0644706 0.0648303 0.0655408 0.0662288 0.066558 0.0661889 0.0633563 0.0588119 0.0537582 0.050317 0.0447926 0.0381889 0.0262958 0.0184604 0.0169094 0.0178853 0.0355812 0.0331362 0.0310978 0.0299944 0.0299702 0.0307366 0.032277 0.0333568 0.0331477 0.0320874 0.0321494 0.0322743 0.0282268 0.0245265 0.0212143 0.0231805 0.0233095 0.0232032 0.0230863 0.0229341 0.0228178 0.0227643 0.02282 0.022953 0.0231599 0.0234043 0.0236733 0.0239702 0.0243038 0.0246279 0.024902 0.0251102 0.025168 0.0250367 0.0247282 0.0243451 0.0240576 0.0241016 0.0244303 0.024569 0.0236332 0.0213638 0.0200566 0.0234784 0.0283283 0.0311311 0.0309465 0.0311957 0.0301094 0.0287144 0.0273427 0.0262252 0.0256546 0.0252936 0.0253076 0.0253577 0.0255488 0.0257706 0.0260276 0.0263194 0.0267015 0.0271703 0.0275859 0.0278659 0.0279762 0.0272636 0.0258637 0.0249621 0.024567 0.0250805 0.0273678 0.0304755 0.0302957 0.0256312 0.0335148 0.0341145 0.0325888 0.0307367 0.0294684 0.028686 0.0281266 0.027659 0.0272925 0.0268532 0.0266124 0.026362 0.0262632 0.0264434 0.0268746 0.0276162 0.0286308 0.0296979 0.0307621 0.0315922 0.031962 0.031804 0.0309638 0.0298685 0.0285836 0.0278051 0.0281386 0.0285397 0.0286145 0.0279936 0.0250177 0.0306604 0.0348111 0.0362837 0.0365274 0.0359972 0.0348394 0.0332918 0.0316107 0.0300287 0.0284925 0.0273616 0.026702 0.0263808 0.026371 0.0266128 0.0269666 0.0273801 0.0275762 0.0277715 0.0283126 0.0294541 0.0308179 0.0316336 0.0317312 0.0311035 0.0293404 0.0279448 0.0277627 0.0275618 0.0284467 0.0337886 0.0318472 0.028985 0.0289058 0.0310574 0.0334376 0.034682 0.0352099 0.0356297 0.036112 0.0366934 0.0373002 0.0378937 0.0384728 0.0389656 0.0393093 0.0396453 0.0399566 0.0402459 0.0403562 0.0401931 0.0397532 0.0388958 0.0374891 0.0357671 0.0339971 0.0325936 0.0313815 0.029258 0.0321742 0.0293295 0.0304484 0.0361457 0.0403907 0.0392121 0.0342371 0.0294235 0.026678 0.0260279 0.0265216 0.0282351 0.0300434 0.0311622 0.0311649 0.0301746 0.0288098 0.0277407 0.027191 0.0270059 0.0268139 0.026437 0.0258181 0.0250072 0.0241638 0.0236139 0.0242982 0.0266104 0.0302303 0.0273642 0.0228096 0.0261369 0.0326389 0.0383096 0.0393618 0.0386557 0.0384609 0.0390534 0.0399711 0.0412389 0.0419671 0.0419338 0.0410375 0.0391376 0.0366359 0.0343186 0.0331804 0.0335416 0.0348085 0.0355545 0.0341794 0.0301736 0.0259871 0.0235255 0.0220776 0.0214347 0.0214408 0.0231866 0.0287572 0.0347123 0.0264824 0.0429541 0.0500931 0.0502706 0.0479402 0.045873 0.0450955 0.0442221 0.0432757 0.0422767 0.0413135 0.0404338 0.040109 0.0405623 0.0418021 0.043542 0.0450481 0.0455101 0.0443599 0.0421292 0.039229 0.0370732 0.035324 0.0353343 0.035987 0.0368352 0.0400913 0.0453173 0.0409423 0.0242407 0.0273236 0.0305537 0.0277112 0.0259849 0.0256421 0.0254718 0.0257296 0.0271293 0.030233 0.0350022 0.0393865 0.0424144 0.0432294 0.0420775 0.0385553 0.0347349 0.0314751 0.0288866 0.0269582 0.0256649 0.0246862 0.0241373 0.0235873 0.0237031 0.0240802 0.025925 0.0291902 0.0341858 0.0386101 0.0388653 0.0312471 0.0387236 0.033869 0.0291248 0.0282682 0.0295207 0.0325287 0.0375321 0.042412 0.0456334 0.0467968 0.0449923 0.0415407 0.0381936 0.0363371 0.0355283 0.0358777 0.0377116 0.0390468 0.0405148 0.0409722 0.0407985 0.040019 0.0391225 0.0387476 0.0388131 0.0395673 0.04045 0.0398357 0.0363888 0.0309778 0.04579 0.0503676 0.0505723 0.0485255 0.0454038 0.0430645 0.0408196 0.0388813 0.0371223 0.0358414 0.0351793 0.035029 0.035161 0.0339798 0.0311449 0.0286512 0.0272789 0.0276769 0.0288704 0.0329633 0.0383781 0.0448826 0.0496223 0.0521195 0.0506173 0.0410824 0.0277069 0.0186528 0.0165203 0.0168806 0.0164371 0.0184461 0.0231991 0.0307102 0.0411073 0.0519425 0.0594653 0.0617416 0.0613409 0.0604148 0.0593683 0.0588973 0.0588994 0.0591934 0.0598576 0.0609409 0.0626021 0.065061 0.067027 0.0678737 0.0644402 0.0566596 0.0491683 0.046111 0.0450501 0.0379989 0.024061 0.017407 0.0172203 0.0308107 0.0282899 0.0265493 0.0258813 0.0258606 0.0263583 0.0277974 0.0297614 0.0311868 0.0309059 0.0306537 0.0317641 0.0295926 0.0248722 0.021847 0.0233448 0.0233566 0.0233764 0.023395 0.0234905 0.0235668 0.0236546 0.0237131 0.0237631 0.0238098 0.0238937 0.0240755 0.0244723 0.0250907 0.0258714 0.0267164 0.0274152 0.0277553 0.0275481 0.0268126 0.0257342 0.0247145 0.02419 0.0243152 0.0247123 0.0244659 0.0225494 0.0204419 0.0227978 0.0285902 0.0306566 0.0302949 0.030962 0.029552 0.0276467 0.0260283 0.0248592 0.0244254 0.0245438 0.0246506 0.0249985 0.0252794 0.0255149 0.0256755 0.0257794 0.0259133 0.0262104 0.0267366 0.0273058 0.0276194 0.0274577 0.0265374 0.0253229 0.0245049 0.0242548 0.0251013 0.0282405 0.0309299 0.0264051 0.0355593 0.0331029 0.0310535 0.0296952 0.0290579 0.0287089 0.02829 0.0276706 0.026896 0.0262631 0.0257805 0.0255041 0.025335 0.025465 0.0256032 0.0260263 0.0269708 0.0282586 0.0296145 0.0309183 0.0318321 0.0320761 0.0315304 0.0303773 0.0291338 0.0283322 0.0283171 0.0286972 0.0290837 0.0284574 0.026785 0.0334229 0.036907 0.0375236 0.0374886 0.0370801 0.0361657 0.034774 0.0327637 0.0305376 0.0283208 0.0268111 0.0260157 0.0262823 0.0267171 0.0273575 0.0280717 0.0285912 0.0286794 0.0284535 0.0283742 0.0289856 0.0302347 0.031372 0.0318741 0.0317682 0.0307175 0.0289467 0.0279613 0.0275515 0.0295786 0.0330673 0.0299795 0.0292463 0.0318665 0.0344501 0.034923 0.0346316 0.0347056 0.0350979 0.0357583 0.0365389 0.0372907 0.0378428 0.0382262 0.0384098 0.0385316 0.0386575 0.0389139 0.0393324 0.0398269 0.0402571 0.040393 0.0402384 0.0397023 0.0383125 0.0362242 0.0339812 0.0321422 0.0300687 0.0334187 0.0300149 0.033143 0.0393382 0.0402726 0.0348429 0.0291039 0.0267118 0.026622 0.028273 0.0307841 0.0333885 0.0354285 0.0359693 0.0343716 0.0310917 0.0280245 0.0264703 0.0261316 0.02632 0.0263634 0.0262802 0.025963 0.0253052 0.0243629 0.0234148 0.0233809 0.0252234 0.0293871 0.0278261 0.0236571 0.0286759 0.0358695 0.0391852 0.039186 0.0388931 0.0401728 0.0423332 0.0447069 0.0463209 0.0468949 0.0469946 0.0461221 0.0440723 0.0405026 0.03608 0.0328144 0.0318707 0.0332201 0.0347628 0.0332553 0.0283086 0.0251205 0.0238879 0.0232162 0.0221135 0.0215543 0.0226217 0.0277899 0.0344648 0.0348525 0.0502927 0.0513531 0.0492109 0.0470932 0.0468416 0.046863 0.0462732 0.0454375 0.0439977 0.0419984 0.0398676 0.038428 0.0382633 0.0395419 0.0418382 0.043218 0.0417866 0.0370109 0.0313314 0.0266614 0.0244664 0.0235133 0.0235091 0.0255507 0.0292398 0.0353834 0.0444347 0.0426663 0.0256987 0.0282563 0.02962 0.0272877 0.0270033 0.0269571 0.0260975 0.0254134 0.0260402 0.0294603 0.0357498 0.041904 0.0448645 0.0450684 0.0410181 0.0349548 0.0304327 0.0274898 0.0259093 0.0252179 0.0250337 0.0251075 0.025036 0.0246358 0.0238381 0.0230327 0.0229549 0.0248958 0.0301013 0.0368837 0.0390353 0.0331245 0.0362315 0.0297617 0.0275783 0.0277895 0.0295635 0.0340045 0.0404056 0.0453423 0.0470509 0.0439671 0.0378063 0.0319331 0.0286126 0.027101 0.0263852 0.0272419 0.0287132 0.03179 0.0344428 0.0373889 0.0386662 0.0384775 0.0372021 0.0358885 0.0351337 0.0358294 0.0377649 0.0392149 0.0369324 0.0360809 0.0488724 0.0508 0.0494122 0.0466014 0.0441308 0.042214 0.0404236 0.0387396 0.0371145 0.0359214 0.0357193 0.0366287 0.0374505 0.0347786 0.0289141 0.0248202 0.0233697 0.0239876 0.0255774 0.0288526 0.0346087 0.0419156 0.0484947 0.0527132 0.0525499 0.0459468 0.0339761 0.0209896 0.0159854 0.0167578 0.0168204 0.0209189 0.0295581 0.0409252 0.052385 0.0597212 0.0613675 0.0602088 0.0583476 0.0567037 0.0558018 0.0553904 0.0554154 0.0559111 0.0567075 0.057653 0.058819 0.0604966 0.0632556 0.0663814 0.0670455 0.0592894 0.0457771 0.0394028 0.0396402 0.0407154 0.0292539 0.01942 0.0166598 0.0285198 0.0261359 0.0251002 0.0250081 0.0251014 0.0252878 0.0256725 0.02706 0.02899 0.0296023 0.029468 0.031124 0.0304521 0.0253969 0.0226319 0.0233988 0.0237752 0.0240674 0.0244434 0.0249019 0.025296 0.0255341 0.0254596 0.0251241 0.0246676 0.0242466 0.0240472 0.0242968 0.0251245 0.0264329 0.0279045 0.0290528 0.0294122 0.0292914 0.0286376 0.0272712 0.0256598 0.0245016 0.0242632 0.0246806 0.0248189 0.0233789 0.0208799 0.0223829 0.0285536 0.0300179 0.0298274 0.0308078 0.0292704 0.027259 0.0255939 0.0247787 0.0246978 0.025136 0.0257571 0.0264238 0.0268983 0.0270992 0.0270226 0.0266393 0.0261086 0.0259528 0.0262311 0.0267895 0.0272334 0.0273074 0.0268287 0.0257961 0.0248328 0.0241862 0.0243221 0.0266589 0.0300287 0.0269176 0.0354221 0.0324159 0.0305892 0.0297186 0.0294763 0.0292325 0.0285153 0.027353 0.0263478 0.0256757 0.0255471 0.0253364 0.0254145 0.0251384 0.0254116 0.0257737 0.0265098 0.0275094 0.0289617 0.0304579 0.0316888 0.0322507 0.0319046 0.0307385 0.0295397 0.0288751 0.0287523 0.0289507 0.0293026 0.0288607 0.0288851 0.0337634 0.0367622 0.0364112 0.0351744 0.0342101 0.0332808 0.0319179 0.0298412 0.0276334 0.0261292 0.025878 0.0265478 0.027691 0.0289954 0.0298736 0.0303213 0.0302904 0.0299331 0.0293853 0.0288708 0.0289903 0.0299919 0.03114 0.0318849 0.0320197 0.0314029 0.0299021 0.0283085 0.0275398 0.030403 0.0320456 0.0296597 0.0314186 0.0342165 0.034479 0.0337805 0.0337452 0.0341738 0.0348971 0.0357938 0.0367876 0.0374093 0.0376356 0.0374443 0.037084 0.0367636 0.0365794 0.0365252 0.0367187 0.0372466 0.0380386 0.0390262 0.039765 0.0399414 0.0393106 0.0376681 0.0352569 0.032848 0.0306377 0.0340398 0.0313839 0.0365311 0.0407168 0.0376614 0.0309272 0.0276522 0.0273999 0.0291928 0.0320243 0.0350046 0.0379284 0.0399701 0.0398289 0.0366762 0.0312386 0.0271294 0.0258133 0.0261177 0.0269991 0.0273144 0.0271639 0.0267381 0.0259865 0.0248747 0.0235769 0.0232646 0.0247914 0.0291236 0.0277545 0.0245114 0.0310334 0.0373205 0.0394236 0.0393855 0.0401895 0.0427302 0.0460372 0.048323 0.04912 0.0495777 0.0492161 0.0483433 0.0468404 0.0438678 0.0386525 0.0336177 0.0313575 0.0320749 0.0335364 0.0314512 0.0279579 0.0274394 0.0287076 0.0286457 0.0264198 0.0243501 0.0249998 0.0293877 0.0347009 0.0402203 0.0523757 0.051131 0.0484959 0.047715 0.0482135 0.0484529 0.0484747 0.0481159 0.0469384 0.0444685 0.0407526 0.0375603 0.0363767 0.0378281 0.0406151 0.0414724 0.0374502 0.0298247 0.0237792 0.0211491 0.0203788 0.0202553 0.0204201 0.0204167 0.0224682 0.029254 0.0422504 0.0438195 0.026176 0.0286252 0.0293139 0.0284384 0.0297955 0.0294398 0.0272841 0.0257095 0.0256169 0.0287665 0.0369719 0.0440471 0.0460893 0.0436682 0.0350921 0.0282343 0.0248795 0.0236621 0.0238965 0.0250456 0.0266365 0.0280754 0.0287871 0.0285109 0.0268579 0.0244925 0.0225712 0.0227786 0.0267859 0.0348279 0.0391575 0.0337292 0.0337491 0.0286222 0.0282304 0.0291847 0.0312129 0.0366265 0.0433759 0.0467807 0.0458255 0.0370563 0.0299803 0.0258321 0.0245716 0.0238122 0.0235857 0.0233192 0.0246281 0.0257671 0.0292887 0.0328028 0.0360134 0.0370961 0.0360111 0.0337718 0.0318906 0.0318834 0.0344213 0.0377165 0.036916 0.03946 0.050129 0.0504918 0.0479221 0.0450953 0.0430544 0.0415679 0.040398 0.0390605 0.0373807 0.0358059 0.0355214 0.0371953 0.0388629 0.0356987 0.0281891 0.0231592 0.0223805 0.0230413 0.0246553 0.0277194 0.0336651 0.0413778 0.0485022 0.0533297 0.0542926 0.0509774 0.0415056 0.024767 0.0160434 0.0166948 0.0175613 0.0246652 0.0373121 0.0498496 0.0587304 0.0613736 0.0598002 0.0570777 0.0546526 0.052705 0.0512102 0.0504205 0.050624 0.0518538 0.0536344 0.055542 0.0571855 0.058517 0.0603587 0.0635166 0.0661311 0.0625557 0.0457592 0.0365498 0.0361023 0.039761 0.0340188 0.0223052 0.0164507 0.0276084 0.0253039 0.0249063 0.0252031 0.0255087 0.0254317 0.0252493 0.0256667 0.0270536 0.028096 0.0283605 0.0305459 0.0309903 0.0259781 0.0231796 0.0238362 0.0247594 0.0250641 0.0255871 0.0262977 0.0269168 0.0271429 0.0268743 0.0261759 0.025258 0.0243498 0.0237787 0.0238892 0.0250017 0.0267265 0.0284385 0.0290671 0.0290947 0.0289546 0.0286519 0.0277985 0.0262266 0.0247495 0.0242944 0.02464 0.024934 0.0238866 0.0212901 0.0222038 0.0283631 0.0292075 0.0295404 0.0306898 0.0293536 0.0276887 0.0263875 0.0259954 0.0266896 0.0279206 0.0291469 0.0298937 0.0302646 0.0302325 0.0300315 0.0294967 0.0283212 0.0264353 0.0259201 0.0263256 0.0268444 0.0270186 0.0267113 0.0259692 0.0250863 0.024296 0.02404 0.0257043 0.0295984 0.027012 0.0348284 0.0320449 0.0304688 0.0299771 0.0299076 0.029462 0.028222 0.026678 0.0257267 0.0254964 0.0259101 0.0261132 0.0262116 0.0259368 0.025836 0.026106 0.0266736 0.0276186 0.0289535 0.0304414 0.0317492 0.0324259 0.0321269 0.0309476 0.029768 0.0292755 0.029225 0.0293454 0.0295483 0.0290954 0.0302715 0.0343677 0.0361955 0.0339942 0.0313338 0.0297501 0.0285248 0.0271736 0.0257706 0.0252097 0.0257655 0.0274118 0.0296176 0.0307236 0.0313653 0.0314115 0.0313058 0.0311123 0.0306444 0.0299495 0.0293326 0.0292719 0.0300446 0.031118 0.0319286 0.0321222 0.0316107 0.0302286 0.0284782 0.0275345 0.0308358 0.0313566 0.0306129 0.033421 0.0344273 0.0336563 0.0334271 0.033978 0.034607 0.0352269 0.0361429 0.0370967 0.0374334 0.0370378 0.0363604 0.035924 0.035744 0.0356886 0.0357237 0.0358399 0.036042 0.0363755 0.0371294 0.0382124 0.0391379 0.039253 0.0382195 0.0360187 0.0333719 0.031036 0.034796 0.0327918 0.0386235 0.0404779 0.0347673 0.0297057 0.028419 0.0296856 0.0324035 0.035355 0.0384919 0.0411643 0.0424516 0.0418943 0.0377822 0.0312508 0.0266718 0.0256129 0.0269412 0.0292024 0.0303383 0.0302117 0.0292149 0.0275209 0.0256689 0.024071 0.0236297 0.0253255 0.0292835 0.0272867 0.0251968 0.0319546 0.0381738 0.0396506 0.0399315 0.0418077 0.0454269 0.0485911 0.0499792 0.0507196 0.0507284 0.0503329 0.0492832 0.0478021 0.0455033 0.0404978 0.0343878 0.0311092 0.0314009 0.0326091 0.0310376 0.0302348 0.0330103 0.0350338 0.0341893 0.0322066 0.0304284 0.0300787 0.0323065 0.0350769 0.0430679 0.0532082 0.0505382 0.0483692 0.0485055 0.0489789 0.0491696 0.0493124 0.0495316 0.0493224 0.0473954 0.0426996 0.0372471 0.0350099 0.03696 0.0403605 0.0403985 0.0338451 0.0253158 0.0212293 0.0202341 0.0206362 0.02161 0.0218644 0.0208487 0.0199715 0.024212 0.0388327 0.0449726 0.0282372 0.0287816 0.0296913 0.030898 0.0333175 0.0320807 0.0288542 0.0263283 0.0256034 0.0288901 0.0380958 0.0451478 0.04552 0.0379106 0.0278763 0.0230683 0.0216128 0.0219565 0.0236079 0.0260934 0.0288948 0.0310871 0.0318299 0.0312896 0.0293578 0.0263686 0.0231114 0.0217457 0.0245551 0.0329463 0.0388726 0.0337155 0.0323256 0.0290845 0.0299056 0.0305231 0.0324225 0.0384784 0.0450883 0.0471241 0.0415344 0.0308052 0.0264297 0.0246386 0.0243253 0.0234413 0.022949 0.0227689 0.0224981 0.0236528 0.0254845 0.0291751 0.0330355 0.0354018 0.0348745 0.0321555 0.0292308 0.0284155 0.0311508 0.0359335 0.0365785 0.041537 0.0504877 0.0496089 0.0462845 0.0434653 0.0417549 0.0409359 0.0404929 0.0396801 0.0381778 0.036026 0.0348177 0.0363702 0.039645 0.0384825 0.0314546 0.0253966 0.0237067 0.0246186 0.0259306 0.0289288 0.0344058 0.0419479 0.0490077 0.0539071 0.0561943 0.0558046 0.0481099 0.0293788 0.0162256 0.0166994 0.0185251 0.0291146 0.0443177 0.056308 0.0614795 0.060544 0.0572225 0.0532125 0.0499281 0.0464742 0.0442788 0.0436087 0.0442706 0.0461119 0.0488555 0.0520843 0.0551122 0.0573014 0.0588891 0.0613104 0.0644007 0.0634609 0.0456217 0.0348777 0.0340058 0.0378087 0.0359686 0.0232575 0.0163352 0.0270105 0.0248136 0.0250432 0.0258394 0.0265261 0.0261924 0.0254351 0.025125 0.0255379 0.0263779 0.027069 0.0295636 0.0313488 0.0267725 0.0233705 0.0246502 0.0260229 0.0261094 0.0264819 0.0271548 0.0277465 0.0279262 0.0276026 0.0267152 0.025419 0.0241633 0.0233694 0.0234649 0.0249095 0.0270973 0.028463 0.0282448 0.0274563 0.0271126 0.0272113 0.0269889 0.025937 0.0246963 0.024231 0.0246702 0.0250461 0.0240956 0.0216196 0.0220814 0.028247 0.0284398 0.0290878 0.0305769 0.029852 0.0287698 0.0282262 0.0287463 0.0301383 0.0315314 0.0322751 0.0323695 0.0320315 0.0316604 0.031425 0.0313686 0.0310452 0.0293646 0.0264132 0.025784 0.0261988 0.02652 0.0263208 0.0257921 0.0250784 0.0242699 0.0238635 0.025291 0.0290858 0.0270789 0.0345474 0.0317239 0.0305744 0.0302135 0.0301549 0.0294719 0.0279255 0.0262083 0.025643 0.0258742 0.0266244 0.0273971 0.0276252 0.0272886 0.0270176 0.0270548 0.0275782 0.0284501 0.0296287 0.0309795 0.0321371 0.0326169 0.032203 0.0309569 0.0298232 0.0294248 0.0294856 0.0297121 0.0298234 0.0292865 0.0309016 0.03566 0.0351974 0.0309897 0.0276618 0.025996 0.0249486 0.0242545 0.0244625 0.0258702 0.0287004 0.030909 0.0317248 0.0317895 0.0315012 0.0313992 0.0313644 0.031214 0.0308223 0.0301799 0.0296388 0.0296801 0.0304503 0.0314627 0.0321698 0.0322281 0.0316911 0.0303955 0.0282091 0.0274568 0.0310252 0.0312464 0.0322329 0.0343018 0.0340418 0.0337351 0.0343058 0.0349478 0.0352249 0.0355788 0.0363412 0.0371785 0.0370207 0.0360362 0.0354674 0.0354629 0.0357682 0.036058 0.0362757 0.0363302 0.0363418 0.0363346 0.036451 0.0370412 0.0380609 0.0386457 0.0380915 0.0362069 0.0335739 0.0312686 0.0351572 0.0346915 0.0401712 0.0394294 0.0334067 0.0304209 0.0304981 0.0326044 0.0352895 0.0379785 0.040322 0.0418382 0.0423555 0.0419176 0.0386029 0.031917 0.0265934 0.0252633 0.0272371 0.030734 0.0324699 0.0327702 0.0314513 0.0289499 0.0264796 0.0249749 0.0248107 0.0267116 0.0293995 0.0268611 0.0260308 0.0324639 0.0380783 0.039809 0.0404367 0.0428768 0.0468425 0.0495893 0.0509454 0.0515096 0.0518009 0.0512363 0.0499324 0.0483542 0.0461332 0.0417333 0.0347338 0.0308932 0.0310987 0.0324566 0.0320313 0.0337625 0.037109 0.0371816 0.0350611 0.0334594 0.0329216 0.0332313 0.0343614 0.0353503 0.0453851 0.0532049 0.0501922 0.0487816 0.0490199 0.0491716 0.0491047 0.0492046 0.0497394 0.0503062 0.0497354 0.0449092 0.0371855 0.0338435 0.0368334 0.0410131 0.0396513 0.0308542 0.0235345 0.021126 0.0211914 0.0225563 0.0242598 0.0245198 0.0231716 0.0205182 0.0212374 0.0346053 0.0451427 0.029234 0.0289209 0.0306619 0.0335999 0.0360546 0.0344914 0.0306183 0.027158 0.0257999 0.0285329 0.0387002 0.0452996 0.0438051 0.032372 0.0237495 0.0210116 0.0206243 0.0216349 0.0233389 0.0255298 0.0278561 0.0305546 0.0316135 0.0308572 0.0285725 0.026 0.022364 0.0209055 0.0233633 0.0317332 0.0391799 0.0335439 0.0317797 0.0302926 0.0316477 0.0315232 0.0330514 0.0396625 0.0458327 0.0459575 0.0371655 0.0284143 0.0259326 0.0250812 0.0244996 0.0231195 0.0228302 0.0223933 0.0225608 0.0228668 0.0248476 0.0273954 0.031132 0.0339074 0.0335562 0.0305885 0.0269689 0.0257127 0.0284965 0.0342656 0.0360716 0.0429971 0.0506489 0.0483684 0.0444268 0.0415453 0.0400975 0.0398459 0.0400387 0.040081 0.0392999 0.0372308 0.0346645 0.0342673 0.03854 0.0412003 0.0375265 0.0310177 0.0275775 0.0274484 0.0289516 0.0322649 0.0378025 0.0443568 0.0503576 0.054912 0.0583818 0.0604447 0.054855 0.0356614 0.0170539 0.0167975 0.0198643 0.0337091 0.0501631 0.0596032 0.0617497 0.0588559 0.0543188 0.0491297 0.0445329 0.0405927 0.0385449 0.0381833 0.03908 0.0411224 0.0441352 0.0480789 0.0522603 0.0557395 0.057824 0.0600265 0.0636234 0.0639147 0.0481358 0.0329374 0.0310881 0.0351654 0.0339269 0.0219379 0.0162984 0.0266806 0.0245303 0.025169 0.0265701 0.0281062 0.0279606 0.0268261 0.0256355 0.0254349 0.0256615 0.0261909 0.0285069 0.0314825 0.0274918 0.0234729 0.0258451 0.0278994 0.0274942 0.0273249 0.0276762 0.0280264 0.0281001 0.0277485 0.0268399 0.0255394 0.0240215 0.0229715 0.0230537 0.0247012 0.0271405 0.028157 0.0272899 0.0256404 0.0250592 0.0253192 0.0255341 0.0250738 0.0243952 0.0242955 0.0247739 0.025107 0.0242679 0.0217991 0.0220268 0.0283324 0.0279623 0.0287205 0.030484 0.0303743 0.0302049 0.0304817 0.0314483 0.0328724 0.033653 0.0338085 0.0334203 0.03273 0.0319738 0.0315243 0.0315809 0.0319248 0.0318129 0.0294326 0.026298 0.0257887 0.0258617 0.025766 0.0253791 0.0248166 0.0240601 0.0237523 0.0252362 0.0289961 0.0271476 0.034151 0.0316965 0.0308595 0.0303551 0.0303173 0.0296709 0.0280108 0.0262975 0.0258103 0.0262247 0.0271313 0.0283374 0.0286741 0.0287848 0.0285733 0.0286557 0.0290466 0.0298146 0.0308036 0.0318307 0.0325516 0.0326358 0.031958 0.0306366 0.0295914 0.0293361 0.0296127 0.0299397 0.0299188 0.0292463 0.0322764 0.0368807 0.0333693 0.0282556 0.0252667 0.0239563 0.0235299 0.0238893 0.0256316 0.0286609 0.0311192 0.0319126 0.0319901 0.0316227 0.031367 0.0313369 0.0312715 0.0310386 0.0306315 0.0301969 0.030014 0.0303272 0.0311112 0.0319829 0.032397 0.0321423 0.0315078 0.0298587 0.0277527 0.0273391 0.030968 0.0316304 0.0335069 0.0346418 0.0344298 0.0350808 0.035991 0.036066 0.0357399 0.0357623 0.0364486 0.0372289 0.0364936 0.0353164 0.0351611 0.0356092 0.0362122 0.0367241 0.0370723 0.0371119 0.0369677 0.0367184 0.0365524 0.0366598 0.0373051 0.0379394 0.0376057 0.0359386 0.0334688 0.0314022 0.0356808 0.0363832 0.0409218 0.0386811 0.0338562 0.0322768 0.0334075 0.0355926 0.0377261 0.0393824 0.0404925 0.0405464 0.0405798 0.0407114 0.0393117 0.0337121 0.0271345 0.024586 0.0256804 0.0291634 0.0318739 0.032813 0.0322506 0.0301475 0.0278861 0.0266941 0.0268937 0.0283449 0.0292298 0.0256414 0.0256351 0.0320558 0.038201 0.0402172 0.0407553 0.0432331 0.0472505 0.0501766 0.0512376 0.0520402 0.0522586 0.0517062 0.0502719 0.0482721 0.0463113 0.0423377 0.0346792 0.0305407 0.0311209 0.0327153 0.0333282 0.0361815 0.0371444 0.0341974 0.0308727 0.0301034 0.0308821 0.0313801 0.0320067 0.0341687 0.045685 0.0534561 0.0498919 0.0489639 0.0492096 0.0491126 0.0488513 0.0488 0.0494777 0.0506044 0.0510023 0.0468277 0.0369128 0.0328241 0.0374676 0.0422604 0.0387046 0.0290738 0.0233844 0.0220877 0.0228025 0.0246291 0.0258081 0.0253419 0.0238953 0.0213827 0.021087 0.0314239 0.0450612 0.0308177 0.0290594 0.0318439 0.0356515 0.0375134 0.0360756 0.0327034 0.0282793 0.0258371 0.0279124 0.038155 0.0449861 0.0425712 0.0295535 0.0224055 0.0206629 0.0209239 0.0221501 0.0233364 0.0245919 0.0258971 0.0284491 0.0300126 0.0292325 0.0252995 0.0227107 0.0205601 0.0201714 0.0229042 0.0318669 0.0392318 0.0334443 0.0318965 0.0318983 0.03308 0.0322232 0.0331566 0.0400618 0.0461981 0.0450015 0.0352513 0.0281897 0.0263014 0.0255201 0.0245547 0.0228473 0.0225816 0.0221567 0.0224832 0.0231291 0.0245987 0.0270241 0.0303291 0.0324563 0.0317202 0.0286071 0.0249331 0.0238294 0.0267695 0.0332174 0.0354327 0.0439504 0.0502387 0.0469151 0.042414 0.0392348 0.0378372 0.037793 0.0384639 0.0394243 0.0400125 0.0391103 0.0358499 0.032655 0.0352122 0.0415894 0.042299 0.0386189 0.0342207 0.0328842 0.0337042 0.0366758 0.0412533 0.0467142 0.0517951 0.0562701 0.0606526 0.0642597 0.0595187 0.0383259 0.017571 0.0169193 0.021313 0.0376248 0.0540794 0.0611372 0.0615216 0.0570861 0.0518348 0.0454006 0.0404729 0.0359239 0.0345223 0.0346229 0.0358298 0.0380084 0.0412046 0.0449523 0.0496188 0.054081 0.056838 0.0589354 0.063075 0.064921 0.0509005 0.0318443 0.0288715 0.0304666 0.0285218 0.0206186 0.0180095 0.0265241 0.0242515 0.0251625 0.0271103 0.029971 0.0316583 0.0307828 0.0284315 0.0273912 0.0269629 0.0268757 0.0283986 0.0316951 0.0283041 0.0290641 0.0270564 0.0247185 0.0290776 0.0306754 0.0293412 0.0282753 0.0282557 0.0283583 0.0282686 0.0278857 0.0271557 0.0259201 0.0243111 0.0228518 0.0225326 0.0241843 0.0269374 0.0280329 0.0269362 0.0250247 0.024105 0.024083 0.0243105 0.0242378 0.0241344 0.0244317 0.0251206 0.0253249 0.0243597 0.0222447 0.0218262 0.0229001 0.0263888 0.0283361 0.0271664 0.0282035 0.0301492 0.0307291 0.0312686 0.0321129 0.0331812 0.034164 0.0347482 0.0348049 0.0344521 0.0336264 0.0324895 0.0315658 0.0313067 0.0316825 0.0322374 0.0313168 0.0280622 0.0259638 0.0254602 0.0252591 0.0249161 0.0244017 0.0237852 0.023711 0.0254231 0.0286151 0.030424 0.0350313 0.0340827 0.0330199 0.0326751 0.0316511 0.0305414 0.0304709 0.0301004 0.0285845 0.0268261 0.026187 0.026404 0.0272756 0.0283562 0.029096 0.0296015 0.0298293 0.0301014 0.0305393 0.0310478 0.0317284 0.0322586 0.0324212 0.0320673 0.0309897 0.0297431 0.0291394 0.0293078 0.0297535 0.0299239 0.0296225 0.0290519 0.0278136 0.0278401 0.0356832 0.0369427 0.0317603 0.0270831 0.0243573 0.0234336 0.0234387 0.0245311 0.0270186 0.0296769 0.031203 0.0319724 0.0320739 0.0318372 0.0314826 0.0312758 0.0311056 0.0308411 0.0306338 0.0305862 0.0308261 0.0313529 0.032012 0.0324302 0.0323722 0.0318547 0.0306641 0.0283785 0.0272513 0.0277267 0.0283403 0.0303028 0.0312359 0.0325786 0.0345767 0.0353447 0.0360239 0.037375 0.0378694 0.03723 0.0362029 0.0358601 0.0364724 0.0372237 0.0360724 0.0349048 0.0350352 0.0356736 0.0363903 0.0370504 0.0373894 0.0374888 0.0373685 0.0370584 0.0367607 0.0366517 0.0369278 0.0373709 0.0369658 0.0353227 0.0330362 0.0319803 0.0355603 0.0368082 0.0362431 0.0379358 0.041428 0.03892 0.0355784 0.0351082 0.0366134 0.0381384 0.0393515 0.0401097 0.0399592 0.0396529 0.0396092 0.0398205 0.0396353 0.0362652 0.0290363 0.0241502 0.0232242 0.0249594 0.0277515 0.0303079 0.0316849 0.0315447 0.0303781 0.0294776 0.0294645 0.0297634 0.0292396 0.0261641 0.0233439 0.0224261 0.0225117 0.0240164 0.0306968 0.038219 0.0409466 0.0428961 0.0465091 0.0496472 0.0511391 0.0518793 0.0521304 0.05167 0.0500254 0.0478739 0.0461694 0.0425139 0.0341372 0.0301784 0.0315467 0.0329786 0.0339238 0.0365078 0.0354626 0.0304002 0.0279718 0.0294832 0.0337587 0.0353514 0.0323743 0.0307568 0.027398 0.0360183 0.0479893 0.0529031 0.0496091 0.049221 0.0493353 0.0490961 0.0487876 0.0487028 0.0493042 0.0506582 0.0516811 0.0477065 0.0363676 0.0316272 0.0386902 0.0439142 0.0382985 0.0290188 0.0244956 0.0234987 0.0244148 0.0260406 0.0260832 0.0246747 0.0231233 0.0210258 0.0204742 0.0305743 0.0444934 0.0331432 0.0313968 0.0287231 0.0295738 0.0331592 0.0368936 0.0381126 0.0370564 0.0348649 0.0301316 0.0261366 0.026566 0.0366793 0.045086 0.0424959 0.0294444 0.0229757 0.0217462 0.0229464 0.02469 0.0256836 0.0260623 0.0259342 0.0277481 0.0290808 0.0276422 0.0227598 0.0199598 0.0193652 0.0197936 0.0239535 0.0330433 0.0392773 0.0381858 0.0344017 0.0332253 0.0323699 0.0336254 0.0343408 0.0329294 0.0328394 0.0399208 0.0466379 0.044958 0.0355168 0.0288388 0.0271105 0.0262198 0.0247566 0.0231103 0.0225151 0.0223007 0.022746 0.0232451 0.0248938 0.0270473 0.0293531 0.030416 0.0291037 0.0261846 0.0231416 0.0227459 0.0261998 0.0324574 0.0348433 0.0320115 0.037264 0.0451656 0.049857 0.045125 0.0402308 0.0371423 0.0357622 0.0356988 0.0362338 0.0377533 0.0394753 0.0400912 0.0383532 0.0328368 0.0307068 0.0373633 0.0430148 0.0435986 0.0421643 0.040584 0.0407043 0.0427101 0.046609 0.0511383 0.0557245 0.0600628 0.0640367 0.0664474 0.0642429 0.0489475 0.0251758 0.0222329 0.0190301 0.0171546 0.0226715 0.0408581 0.0565265 0.0618902 0.0610377 0.0559181 0.0502515 0.0429261 0.0378759 0.0334816 0.0326793 0.032946 0.0338975 0.036666 0.0399423 0.0437749 0.0480952 0.052774 0.0560832 0.0582689 0.0625885 0.0667528 0.0587278 0.0341882 0.0279214 0.0279285 0.0284873 0.0314406 0.0476296 0.0705133 0.0708721 0.0264708 0.0240493 0.0248538 0.0270686 0.0309861 0.0345479 0.035081 0.0326062 0.0306552 0.0295567 0.029085 0.0296148 0.0324277 0.0301372 0.0299567 0.0301635 0.0280782 0.0316338 0.0329596 0.0313778 0.029277 0.0290085 0.0291117 0.0288213 0.0283782 0.0277202 0.0266817 0.0251173 0.0232029 0.0222146 0.0231761 0.0257394 0.0278086 0.027316 0.0254765 0.0242578 0.0239619 0.0239571 0.0241066 0.024329 0.0249884 0.0255267 0.0253564 0.0243333 0.0223937 0.0217179 0.0224668 0.0253865 0.0277817 0.0254686 0.0260864 0.0292636 0.0304164 0.0313824 0.0327893 0.0339475 0.0349148 0.0354708 0.0355998 0.0353416 0.0346405 0.0333988 0.0319219 0.0310257 0.0310764 0.0317958 0.0318039 0.0298451 0.026839 0.0254657 0.0249597 0.0245354 0.0240324 0.0235666 0.0236816 0.0256625 0.0290485 0.0323662 0.0352046 0.0343701 0.0343421 0.0352276 0.0333164 0.0310299 0.0305726 0.0305983 0.029418 0.0276749 0.0267561 0.0266698 0.0271329 0.0279465 0.0286489 0.0292938 0.0298445 0.0302443 0.030668 0.0310198 0.031374 0.0314843 0.0311255 0.0304898 0.0294695 0.0289889 0.0290106 0.0292514 0.0293799 0.0289097 0.028362 0.0282003 0.0275424 0.031387 0.0385066 0.0360445 0.0317578 0.0274036 0.0246197 0.0235836 0.0236689 0.024732 0.0267567 0.0289194 0.030624 0.0315527 0.0319965 0.0320752 0.0319151 0.0317004 0.0315309 0.0313858 0.0314035 0.0315898 0.0319347 0.0323049 0.0324805 0.0323159 0.0317654 0.030454 0.0283638 0.0272276 0.0282008 0.0299433 0.0305158 0.0310516 0.0321619 0.0339664 0.0357904 0.0367983 0.0382151 0.0394991 0.0394473 0.0384128 0.0368357 0.0358259 0.0363806 0.0372305 0.0360281 0.0347414 0.0347904 0.0353599 0.0360986 0.0368044 0.0372092 0.0373228 0.0372716 0.0370569 0.0368378 0.0367089 0.0368014 0.0368659 0.0361522 0.0344669 0.0327315 0.0324721 0.0361679 0.0372795 0.0369537 0.0388236 0.0419639 0.0400157 0.0378617 0.0381453 0.0391001 0.0397287 0.040051 0.0399853 0.0398763 0.0399777 0.0400293 0.0398569 0.0397646 0.0386347 0.032644 0.0251888 0.0220147 0.0216935 0.0227754 0.0249556 0.0279332 0.0301048 0.030457 0.0297256 0.0289282 0.0281919 0.0268977 0.024594 0.0227757 0.0234481 0.0249327 0.0256202 0.0280145 0.0347494 0.0400683 0.0425556 0.0453566 0.048434 0.0504628 0.0512766 0.0515606 0.0508438 0.0491909 0.0471543 0.0456729 0.0420094 0.0330384 0.0297734 0.0321223 0.0331269 0.0338699 0.0360316 0.0342031 0.0288593 0.0270766 0.0311338 0.0395142 0.042869 0.0395169 0.0367482 0.0374334 0.0433349 0.0502388 0.0523148 0.0497934 0.0494234 0.0494676 0.0492312 0.0489881 0.0491151 0.0496477 0.051157 0.0517789 0.047586 0.0353706 0.0306297 0.0402485 0.0456377 0.0389401 0.0301239 0.0258555 0.0246724 0.0257179 0.0266038 0.0254988 0.0233705 0.0214537 0.02021 0.0217738 0.0329376 0.0440663 0.0347555 0.0285215 0.0285806 0.0304028 0.0343039 0.0373838 0.0378097 0.036974 0.0362463 0.0325832 0.02693 0.0252868 0.0341147 0.0454766 0.0436846 0.0316962 0.0251702 0.0244357 0.026429 0.0287034 0.0293011 0.0285154 0.0276031 0.02759 0.0287825 0.0277758 0.0227193 0.0194399 0.0191651 0.0208375 0.0267555 0.0353798 0.0392739 0.0355406 0.0338554 0.0332227 0.0332943 0.0351061 0.0354976 0.0337046 0.0326894 0.0395478 0.0473373 0.0460207 0.0372603 0.0302462 0.0281078 0.0272456 0.025577 0.0237434 0.0226864 0.0224327 0.0227175 0.0234702 0.0245298 0.0262934 0.0273511 0.0272311 0.0255874 0.0232506 0.0218349 0.0227202 0.0267193 0.032306 0.0339886 0.0318063 0.0398086 0.0463113 0.0485078 0.0432306 0.0382287 0.0350523 0.033762 0.0334316 0.0338966 0.0356296 0.0381274 0.0401055 0.0402597 0.035783 0.0286622 0.0305178 0.0372996 0.041946 0.0443687 0.0460329 0.0479153 0.0499248 0.0518722 0.0538739 0.0559039 0.0580458 0.0603034 0.0622819 0.0613377 0.0535193 0.0357942 0.0241073 0.0181559 0.0175583 0.0248783 0.0442521 0.0581702 0.062237 0.0607042 0.0555489 0.0496731 0.042573 0.0370539 0.0327105 0.0317994 0.0317803 0.0331068 0.0362655 0.0403911 0.0438099 0.0480265 0.0521462 0.0555658 0.0581196 0.0627711 0.067491 0.0650885 0.0429082 0.0308598 0.0333256 0.0397507 0.0537995 0.0664658 0.0703964 0.0724487 0.0265364 0.023805 0.0243851 0.0261924 0.03042 0.0357962 0.0381586 0.0363597 0.033228 0.0308819 0.0297329 0.0300407 0.0320814 0.0322107 0.0320055 0.0323559 0.0326177 0.0335695 0.0334958 0.0316492 0.0294842 0.0296829 0.0302118 0.0299823 0.0294702 0.0288237 0.0277041 0.026259 0.0242189 0.022375 0.0221846 0.0240963 0.0267148 0.0276025 0.0268395 0.0255448 0.0248874 0.0246799 0.0249015 0.0253826 0.0259733 0.0260876 0.0253965 0.0241011 0.022151 0.0216166 0.0217229 0.0225478 0.026124 0.0229008 0.022979 0.0275429 0.0295784 0.0306419 0.0323515 0.034221 0.0353454 0.0359512 0.0361371 0.0358871 0.0353652 0.034378 0.0326652 0.0309529 0.0303173 0.0306343 0.0310572 0.0302787 0.0278281 0.0258704 0.0249532 0.0243039 0.0237663 0.0234839 0.0240453 0.0267005 0.0303693 0.0337889 0.0356454 0.0354017 0.0368292 0.0385517 0.0363495 0.0323255 0.0306807 0.0308838 0.0303559 0.0289445 0.0275797 0.0271272 0.0272279 0.0275899 0.0280456 0.028507 0.0289232 0.0293164 0.0296036 0.0298309 0.0298776 0.0296665 0.029429 0.0289765 0.0286243 0.028453 0.0283619 0.0277428 0.026882 0.0260914 0.0261214 0.0267603 0.0311202 0.0383357 0.0388316 0.0361655 0.0331251 0.0290804 0.0260405 0.0244932 0.0240534 0.0245687 0.0257913 0.0273502 0.0288707 0.0301585 0.0310312 0.0316599 0.0320134 0.032172 0.0321797 0.0322043 0.0322409 0.0323089 0.0323255 0.0321893 0.0318269 0.031154 0.0298993 0.0282611 0.027216 0.0277913 0.0297965 0.0313041 0.031701 0.0322478 0.0336885 0.0357181 0.0373133 0.0386116 0.0400917 0.0409238 0.0407558 0.0395843 0.0378065 0.035931 0.0361134 0.0372581 0.0363657 0.0347129 0.0343813 0.0347784 0.0353897 0.0360567 0.0365623 0.0368419 0.0368823 0.0368067 0.0366703 0.0365682 0.0364005 0.0360339 0.0350509 0.0335874 0.032556 0.0330161 0.0375014 0.0375866 0.0375034 0.0399831 0.0428224 0.0413667 0.0400925 0.0402139 0.0404892 0.0403808 0.0400209 0.0399434 0.040542 0.04143 0.0415759 0.0407934 0.0399421 0.039429 0.0368478 0.0287255 0.0225157 0.0206712 0.0204152 0.0209134 0.0224193 0.0248556 0.0266628 0.0264016 0.0249191 0.0232325 0.0219938 0.022033 0.0234868 0.0270676 0.0297559 0.0303976 0.0314809 0.0351526 0.0395509 0.0417192 0.0443359 0.0464582 0.048894 0.0499452 0.0502369 0.0492567 0.0477404 0.046341 0.0448173 0.0405571 0.0315726 0.029542 0.032816 0.0328813 0.0334355 0.0353091 0.0335432 0.0278632 0.0260953 0.0305514 0.0420108 0.0479302 0.0468059 0.0455018 0.0466321 0.049096 0.0520269 0.0519403 0.0499388 0.0496826 0.049607 0.0494694 0.0494104 0.0496488 0.050571 0.0517799 0.0517007 0.0456142 0.0337641 0.029696 0.041702 0.0478886 0.040841 0.031767 0.0265123 0.0255238 0.0267215 0.0267582 0.0250256 0.0229419 0.0215316 0.0220514 0.0272587 0.0372871 0.0425681 0.03288 0.0268895 0.0288544 0.0314262 0.0350434 0.0370356 0.0365682 0.036002 0.0363582 0.0349516 0.0285916 0.0245163 0.0305747 0.0453236 0.0462824 0.0358222 0.0287529 0.0278231 0.02987 0.0316481 0.0318839 0.0302139 0.0290187 0.0278317 0.0285579 0.0282969 0.0242577 0.0208435 0.0209373 0.0243572 0.0313675 0.0375281 0.0385071 0.0343999 0.033545 0.0334542 0.0341248 0.035981 0.0364664 0.0348394 0.0326515 0.0388991 0.0478171 0.0479355 0.0403677 0.0324404 0.0295451 0.0286294 0.0269963 0.0249268 0.0233799 0.022522 0.0224871 0.02283 0.0237719 0.0241147 0.0242473 0.0237187 0.0226578 0.0218005 0.0221505 0.0242996 0.028417 0.0321313 0.0328134 0.0336466 0.041968 0.046859 0.047657 0.0415206 0.0366385 0.0338231 0.0328486 0.0325092 0.03262 0.0341201 0.0368064 0.0395328 0.040623 0.0395289 0.029385 0.0266738 0.0292667 0.0317441 0.033303 0.0338775 0.0341447 0.0346047 0.0349758 0.0350202 0.0350568 0.0353183 0.0364516 0.0384502 0.0393477 0.0367675 0.0295015 0.02016 0.0178816 0.0191765 0.0305853 0.0486511 0.0594026 0.0623907 0.0609065 0.0560245 0.0506782 0.0439467 0.0388746 0.0341188 0.0329488 0.0324801 0.0346771 0.038042 0.041803 0.0452726 0.0488322 0.0524536 0.0553234 0.0584765 0.0639026 0.0681976 0.0692204 0.0543242 0.0378009 0.039663 0.0521263 0.0627465 0.0658772 0.0653915 0.0720748 0.0268114 0.0236315 0.0238134 0.0248835 0.0279579 0.0340963 0.0386282 0.0394029 0.0369026 0.0331717 0.0302739 0.0287539 0.0293399 0.0308785 0.0317717 0.0322716 0.0327683 0.0329772 0.0322089 0.0301702 0.0290992 0.0300092 0.031106 0.031069 0.0306526 0.0302048 0.0291894 0.0275283 0.0256435 0.02329 0.021843 0.0222638 0.0244437 0.0263885 0.0269763 0.0265806 0.026241 0.0260444 0.0260547 0.0262481 0.0261681 0.0256424 0.0247767 0.0235629 0.0220135 0.0213881 0.0209667 0.0204322 0.0222333 0.0209268 0.0213559 0.0257211 0.0288022 0.0293951 0.0310184 0.0332153 0.0352412 0.0361441 0.0364654 0.03633 0.0357445 0.0349031 0.0335299 0.0313957 0.0298193 0.0293785 0.0294728 0.029075 0.0277629 0.0260185 0.0248274 0.0240802 0.0237219 0.0239871 0.0259659 0.0295585 0.0328104 0.0350887 0.0361392 0.0364783 0.0386581 0.040946 0.0399784 0.0352071 0.0312726 0.0309127 0.0310809 0.0302948 0.0288559 0.0279266 0.0275956 0.027617 0.0277752 0.0279979 0.0282268 0.0283922 0.0285387 0.0285287 0.0284441 0.0282172 0.0278806 0.0274152 0.0269216 0.0263298 0.0258163 0.0253416 0.0252201 0.0254733 0.0259411 0.0280193 0.0369074 0.03944 0.0378617 0.0365046 0.0348473 0.0316472 0.0285205 0.026582 0.0254666 0.0250962 0.0253274 0.0260519 0.02684 0.0277463 0.0287278 0.0296396 0.0303682 0.0308548 0.0311806 0.0312237 0.0312115 0.0310521 0.0307254 0.0301521 0.029316 0.0283389 0.0275226 0.0273093 0.0280335 0.0294381 0.0309716 0.0322953 0.0331039 0.033978 0.0356417 0.0375456 0.0388466 0.04009 0.0412858 0.0420522 0.0418399 0.0406819 0.0390558 0.0364404 0.0357178 0.0370663 0.0370394 0.0351635 0.0341893 0.0342021 0.0345649 0.0350238 0.035473 0.0358356 0.0359982 0.0360145 0.0359251 0.0357267 0.0353934 0.0347727 0.0339326 0.0332321 0.0332568 0.0355004 0.0384006 0.0381744 0.0389692 0.0418089 0.0435078 0.0426486 0.0417457 0.0414166 0.0409213 0.0403286 0.0399426 0.0402157 0.0413102 0.0423528 0.0427737 0.0420226 0.0404502 0.0394409 0.0390138 0.0337497 0.0254179 0.0213125 0.0202299 0.0200374 0.020173 0.0208697 0.0218254 0.0223006 0.0217619 0.0209099 0.0208827 0.0220018 0.0242017 0.0283036 0.033155 0.0357104 0.036666 0.0380038 0.0399637 0.0415315 0.0430972 0.0446455 0.046446 0.0476118 0.0477875 0.04701 0.0461233 0.0452085 0.0434133 0.0379629 0.0296917 0.0298195 0.0335518 0.0325469 0.0327997 0.034297 0.0319027 0.0269205 0.0249547 0.0283968 0.0410682 0.049697 0.0516362 0.050715 0.0512694 0.0520582 0.0526581 0.0518107 0.0503073 0.05003 0.049914 0.0498743 0.0500431 0.0506742 0.0516902 0.0523202 0.0501878 0.0423604 0.0308341 0.0284221 0.042699 0.0502309 0.0432736 0.0324934 0.0269678 0.0261261 0.0275022 0.0272124 0.0256334 0.0250331 0.0265556 0.0302063 0.0353104 0.0384483 0.0364071 0.0286041 0.0266579 0.029465 0.0323452 0.0353693 0.0364756 0.0357717 0.0351956 0.0357747 0.0358945 0.0306387 0.0245054 0.0274789 0.0438554 0.0489516 0.0412129 0.03315 0.0309299 0.0320666 0.0336876 0.0335585 0.0313962 0.0297741 0.0283709 0.0285179 0.0290525 0.0275473 0.0249368 0.0255842 0.0298878 0.0354998 0.0386057 0.0372203 0.0341804 0.0334744 0.0338181 0.0345957 0.0356533 0.0364432 0.0356155 0.0331535 0.0384976 0.0482641 0.0500553 0.0444042 0.0359178 0.0315193 0.0303379 0.0290556 0.0269183 0.024997 0.023688 0.0229381 0.0226925 0.0224584 0.0223772 0.0222525 0.0222194 0.022271 0.0229443 0.0246637 0.0273236 0.0300522 0.0315488 0.0320968 0.0368323 0.0437502 0.0471653 0.0462231 0.0402012 0.0357316 0.0331981 0.0323774 0.0320602 0.032153 0.0334457 0.0362655 0.0394643 0.040264 0.0417732 0.0325704 0.0254679 0.0250895 0.0244837 0.0236451 0.0228631 0.0219838 0.0213398 0.0210283 0.0209184 0.0207594 0.0207692 0.0209438 0.0213837 0.0217064 0.0217247 0.0208232 0.0192375 0.0202034 0.0253203 0.0402877 0.0535765 0.0604903 0.0626079 0.0613456 0.0575315 0.0526161 0.0475798 0.0423962 0.0392637 0.036819 0.0374209 0.0388651 0.0418947 0.0446938 0.047406 0.0504023 0.0533138 0.0555342 0.0595222 0.065855 0.069387 0.070555 0.0644465 0.0477192 0.040392 0.0484617 0.056745 0.0574292 0.0622024 0.0718888 0.0273517 0.0235218 0.023214 0.0237005 0.0248739 0.0285376 0.0347851 0.0383034 0.0382809 0.0362746 0.0326894 0.029413 0.0277822 0.0278842 0.0287023 0.0293225 0.0298659 0.029892 0.029186 0.0286049 0.0290083 0.0303268 0.0310806 0.0309824 0.0307781 0.0306716 0.0305241 0.0290196 0.0270482 0.0249222 0.0224651 0.0215355 0.0219617 0.0233399 0.0245481 0.0253924 0.0254278 0.0254654 0.0253215 0.0250521 0.0245541 0.0238665 0.0232059 0.0226487 0.021918 0.0213572 0.0208581 0.0203893 0.0203144 0.0201985 0.0215658 0.0258181 0.0286107 0.0286964 0.029401 0.0312586 0.0334684 0.0353796 0.0362823 0.0363672 0.0357985 0.0350384 0.0342405 0.0324277 0.0300231 0.0286645 0.0279623 0.0272908 0.0264812 0.0254409 0.0245999 0.0242642 0.0247398 0.0267478 0.0302606 0.03374 0.0356342 0.036299 0.036576 0.0370731 0.0387072 0.0411913 0.0415216 0.0390765 0.0333865 0.0309619 0.0311803 0.0312362 0.0303278 0.029133 0.0282655 0.0279424 0.0277478 0.027611 0.0275167 0.0273682 0.0271407 0.0268743 0.0264616 0.0260726 0.0256054 0.0253884 0.0253061 0.0255622 0.0260827 0.0268641 0.0275415 0.0281467 0.0290895 0.0328263 0.0393261 0.0389016 0.0367619 0.0356909 0.0359107 0.0343099 0.0316493 0.0298491 0.0284547 0.0273799 0.0266806 0.0263707 0.0263421 0.0264738 0.0267884 0.0271539 0.0274914 0.0278396 0.0281164 0.0282312 0.028172 0.0279397 0.0276167 0.0272879 0.0272337 0.0273988 0.0282441 0.0293595 0.0301997 0.0307959 0.0317454 0.0330962 0.034368 0.0356849 0.0373644 0.0389545 0.0400209 0.041003 0.0420286 0.0428255 0.0424909 0.0413392 0.0401143 0.0378238 0.0355513 0.0364983 0.0376094 0.0362941 0.0346434 0.0341031 0.0341168 0.0343926 0.0346439 0.0348536 0.0349465 0.0350143 0.0349638 0.0348037 0.0346086 0.0343816 0.0343173 0.0347954 0.036293 0.038335 0.0393299 0.0396837 0.0412658 0.0435426 0.0442898 0.043667 0.0430589 0.0423082 0.0413888 0.0405267 0.0401042 0.0403048 0.0413407 0.0422763 0.0427765 0.0425204 0.0410766 0.0393638 0.0393644 0.0381331 0.0299637 0.0236527 0.0214378 0.0209709 0.0205824 0.0203239 0.0203295 0.0204943 0.0206017 0.0207661 0.0214027 0.0226194 0.0239295 0.0269215 0.0323841 0.0370138 0.0395904 0.0406438 0.0413154 0.0417091 0.0423641 0.0431836 0.044254 0.0449577 0.0451284 0.04488 0.0446434 0.0436604 0.040471 0.0340378 0.0281926 0.030573 0.0342982 0.0320936 0.0318871 0.0329521 0.0312235 0.0273403 0.0245945 0.0248229 0.0343522 0.0479213 0.0538755 0.0544301 0.0541477 0.0541325 0.053433 0.0521842 0.0511151 0.0508555 0.0508602 0.051053 0.0514839 0.0520776 0.0524041 0.0512307 0.0460038 0.0368382 0.0280333 0.0271286 0.0425438 0.0523591 0.0459132 0.0335131 0.0272482 0.026609 0.0282187 0.0283674 0.0272394 0.0271867 0.0287195 0.0309253 0.0316788 0.030354 0.0275755 0.0262089 0.0274357 0.0303231 0.0330154 0.0352203 0.0357683 0.0354053 0.0346943 0.0353847 0.0356973 0.031645 0.0248726 0.0266444 0.0411777 0.0504833 0.0471097 0.0388508 0.0342534 0.0336455 0.0347687 0.0349508 0.0328709 0.0305896 0.0290126 0.0292567 0.0306556 0.0319043 0.0315401 0.0322276 0.0354231 0.0383209 0.0390379 0.0364819 0.0340302 0.0336707 0.0341513 0.0347303 0.035057 0.0363085 0.0359021 0.0345444 0.0387337 0.0486196 0.0519142 0.0492386 0.0410704 0.0346597 0.0323214 0.0315051 0.0299004 0.0279372 0.0263578 0.0253128 0.0243732 0.0239303 0.023664 0.0238859 0.0241892 0.0250728 0.0262697 0.0279504 0.0294521 0.0304604 0.0315787 0.0346347 0.0404875 0.0452548 0.0469664 0.0448905 0.0394763 0.0357038 0.0333329 0.0324123 0.0320596 0.032516 0.0341802 0.0371114 0.0398045 0.0405528 0.0422364 0.0375874 0.0255822 0.0240651 0.0226691 0.0216246 0.0214959 0.0221841 0.0235381 0.0243883 0.0243447 0.023812 0.0231536 0.022625 0.0222726 0.0221898 0.0223017 0.0230294 0.0253294 0.029985 0.0387767 0.050816 0.0579057 0.0613838 0.0625396 0.0618258 0.0591541 0.0556612 0.0517532 0.0483151 0.0453074 0.0442688 0.0438186 0.0450384 0.0464224 0.0481948 0.0500701 0.0522736 0.0543615 0.0562366 0.061608 0.0684399 0.0705224 0.0710119 0.0694997 0.0588777 0.0451849 0.0434145 0.0454654 0.0487629 0.0616108 0.0719464 0.028346 0.023802 0.0225595 0.0228519 0.0231608 0.0237343 0.0265805 0.0300668 0.0329731 0.032918 0.0307448 0.0285462 0.0267252 0.0260345 0.0262303 0.0267782 0.027337 0.0277332 0.0280018 0.0285211 0.0292307 0.0296091 0.0291869 0.0283649 0.0275895 0.0284183 0.0302512 0.0303519 0.028328 0.0264733 0.0243036 0.0222813 0.0213519 0.0214734 0.0220742 0.0227661 0.0231029 0.023434 0.0235284 0.0236091 0.0235928 0.0236624 0.0238068 0.0239193 0.0241674 0.0234832 0.0225838 0.0221508 0.0214745 0.0220611 0.0244832 0.0276606 0.0287756 0.0283779 0.0286766 0.0299196 0.0316256 0.0333737 0.0347538 0.035318 0.0352215 0.0347361 0.0346025 0.0336817 0.0312984 0.0290876 0.0279215 0.0270203 0.0262332 0.0256528 0.0254216 0.0259438 0.0275355 0.0304166 0.0338393 0.0368232 0.0381172 0.0383026 0.0377952 0.0380852 0.0392459 0.040609 0.0413235 0.0406314 0.0369061 0.0323271 0.031025 0.0313519 0.0315597 0.0306862 0.0294502 0.0286895 0.0280492 0.0275122 0.0269715 0.0264939 0.0260856 0.0256369 0.0254898 0.0252061 0.0253699 0.0255821 0.0262584 0.0273713 0.0287019 0.0302369 0.0315981 0.0328904 0.0341988 0.0365734 0.0383606 0.0374399 0.035084 0.0337663 0.0354386 0.0361931 0.0345215 0.0333563 0.0324472 0.0315767 0.0307601 0.0299824 0.0292642 0.0286371 0.0281213 0.0277534 0.027519 0.0273647 0.0272629 0.0271718 0.0271396 0.0271702 0.0274004 0.0279823 0.0289716 0.0302255 0.0312895 0.0317591 0.0317567 0.03181 0.032425 0.0336576 0.0351482 0.0366863 0.0382587 0.0396766 0.0406813 0.0414301 0.0421388 0.0425945 0.0421849 0.041287 0.0403985 0.0392634 0.036355 0.0356504 0.0374354 0.037666 0.0360378 0.0349693 0.034647 0.0347713 0.0350684 0.0353284 0.0354921 0.0356002 0.0356987 0.0357922 0.0360668 0.0364734 0.0371922 0.0380897 0.0389162 0.0396363 0.0404351 0.0414798 0.0430189 0.044356 0.0445815 0.0444761 0.0439667 0.0433748 0.0425009 0.0416281 0.0411303 0.0410539 0.0416338 0.0420713 0.0423079 0.0422019 0.0410629 0.0390684 0.038832 0.0400575 0.0350315 0.026989 0.0236801 0.0229841 0.022734 0.0220877 0.0215781 0.0212573 0.0213127 0.0217327 0.0224977 0.0231184 0.0237588 0.0251757 0.02857 0.0327683 0.0370703 0.0399373 0.0416068 0.0418336 0.0427356 0.0424832 0.0436521 0.0434808 0.0439134 0.0434627 0.0428597 0.0403398 0.0357113 0.0297719 0.0271108 0.0318565 0.0349557 0.0316364 0.031074 0.032544 0.0318743 0.0287102 0.0250154 0.0233818 0.0250459 0.0348272 0.0462324 0.0521548 0.0534668 0.053526 0.0533086 0.0530321 0.0527007 0.0525239 0.0524515 0.0523523 0.0523412 0.0514525 0.0495878 0.0448239 0.0377922 0.0304736 0.0252935 0.025621 0.0404478 0.0534676 0.0495085 0.0358316 0.0279066 0.0268505 0.0285587 0.0295208 0.0286638 0.0276139 0.0269447 0.0266821 0.0264608 0.0262922 0.0265483 0.0273566 0.0289494 0.0311595 0.033251 0.0346477 0.0348287 0.0346088 0.0345571 0.0351798 0.0347632 0.0308327 0.0256612 0.0271145 0.0381891 0.0496011 0.0519007 0.0459108 0.0392176 0.0356884 0.0354075 0.0357839 0.034691 0.0321073 0.030729 0.031249 0.0318757 0.0349429 0.0364844 0.0376427 0.0386915 0.0391317 0.0379802 0.0352151 0.0335144 0.0338685 0.0344633 0.0349128 0.035134 0.03609 0.0363195 0.0358305 0.0402434 0.0494586 0.0538281 0.053503 0.0479965 0.0398685 0.03491 0.0338261 0.0335215 0.0319801 0.0305199 0.0299334 0.0291924 0.0286592 0.0285828 0.0286867 0.0292719 0.0298359 0.0306291 0.0312975 0.0320191 0.0332091 0.0355866 0.039332 0.0434252 0.0460432 0.0464163 0.0442848 0.0400155 0.0370319 0.0351231 0.0341119 0.0340732 0.0349417 0.0364744 0.03889 0.0405481 0.0408433 0.0423092 0.0430597 0.0277122 0.0251111 0.0244646 0.0233604 0.0240417 0.0267888 0.0302569 0.0330056 0.0345408 0.035089 0.0349983 0.0344822 0.0338587 0.0337214 0.0347187 0.0375339 0.0422177 0.0468774 0.0530807 0.0581318 0.0602846 0.0615064 0.0621145 0.0618264 0.0603756 0.0581926 0.055819 0.0534272 0.0517806 0.0504364 0.0501936 0.0500834 0.0506384 0.0514262 0.0526459 0.0541276 0.0553145 0.0577303 0.0652077 0.0708067 0.0710633 0.0712538 0.0715301 0.0682541 0.0581367 0.0492813 0.0471146 0.0513292 0.0652044 0.0722426 0.0295666 0.0247497 0.022175 0.0218972 0.0222281 0.0224093 0.0226804 0.0230527 0.0240199 0.024417 0.0242093 0.0238626 0.0233308 0.0231194 0.0233432 0.0239488 0.0246731 0.0254342 0.0261065 0.0265736 0.0264869 0.0257393 0.0244715 0.0234369 0.0229288 0.0240481 0.0277392 0.0305127 0.0294025 0.0274278 0.0262732 0.0246954 0.0232858 0.0226446 0.0226531 0.0229316 0.0236228 0.0241325 0.0247894 0.0253526 0.0258525 0.0263877 0.0268474 0.0271779 0.0275959 0.0272027 0.026489 0.0262909 0.0259227 0.0264987 0.0279859 0.0285185 0.0284819 0.0280343 0.0284595 0.0299249 0.0312152 0.0323104 0.0330369 0.0335651 0.0338498 0.0340687 0.0345162 0.0347748 0.0334376 0.0308667 0.029039 0.0281457 0.0275392 0.0271538 0.0271219 0.0275756 0.0284571 0.0297616 0.0314871 0.0337307 0.0361045 0.0375423 0.038078 0.0385275 0.039181 0.0395697 0.0395959 0.0395096 0.0384833 0.035443 0.0320719 0.0307711 0.0315483 0.0319382 0.0313054 0.0304979 0.0297161 0.029082 0.0284531 0.0279649 0.0275831 0.0274387 0.0272771 0.0275681 0.0278022 0.0284212 0.0289269 0.0295573 0.0299633 0.0306232 0.0314064 0.032571 0.0338504 0.0350406 0.0347054 0.0334929 0.032361 0.0320459 0.033855 0.0368553 0.0364682 0.0359051 0.0356648 0.0353005 0.0348721 0.0343434 0.0337214 0.0330072 0.0322319 0.0314897 0.0308556 0.0302968 0.0299095 0.02969 0.0297588 0.0300909 0.0307438 0.0315848 0.0323977 0.0329454 0.0331221 0.0330416 0.0328956 0.0329222 0.0333039 0.0341136 0.0352728 0.0365832 0.0378474 0.0389926 0.0399333 0.0405606 0.0409229 0.0409126 0.0406187 0.0402515 0.0399798 0.0398312 0.0381232 0.0356935 0.0363034 0.0381706 0.0378906 0.0369276 0.0364215 0.0364402 0.0367165 0.0371779 0.0375467 0.0379228 0.0381893 0.0384213 0.0386528 0.0388884 0.0391378 0.0393691 0.039781 0.0403143 0.0410579 0.0419859 0.0428928 0.0434425 0.0437467 0.0439072 0.043931 0.0436967 0.0433264 0.0428831 0.0425569 0.0423325 0.0422675 0.0420892 0.04179 0.0413908 0.0404517 0.0385704 0.0381356 0.040475 0.0390086 0.030906 0.0258952 0.0246385 0.0242864 0.0237099 0.0231874 0.0228733 0.0227937 0.0229896 0.0231462 0.0232419 0.0234527 0.0240112 0.025264 0.0271337 0.0304271 0.0340863 0.0375726 0.0392876 0.0409856 0.0412327 0.0423461 0.0417583 0.0415439 0.0399222 0.0373045 0.0341963 0.0301869 0.0265865 0.0269203 0.0332881 0.0356318 0.0311402 0.0299017 0.0318914 0.0319278 0.0288661 0.0251947 0.0229194 0.0220775 0.0233708 0.0286745 0.035805 0.0414568 0.044865 0.046993 0.0482622 0.0487046 0.0484405 0.0477183 0.0464191 0.0446409 0.0414822 0.0376397 0.032658 0.0281863 0.02488 0.0234676 0.0244514 0.0348963 0.0521703 0.0540891 0.0412714 0.0295784 0.0267871 0.0278752 0.0296853 0.0303441 0.0301594 0.0298011 0.0293944 0.0291556 0.0290383 0.0291823 0.0297092 0.0306635 0.0319421 0.033266 0.0341918 0.0344662 0.0345823 0.0348072 0.0346112 0.0328242 0.0285103 0.0257956 0.0296657 0.0368304 0.0450671 0.0522164 0.0528508 0.0469634 0.039942 0.0362418 0.0358387 0.0358631 0.034861 0.0335788 0.0334699 0.0339498 0.0345644 0.0364401 0.0372005 0.0372342 0.0365393 0.0351996 0.0338713 0.0334653 0.0340255 0.0347017 0.0351351 0.035708 0.036571 0.0369539 0.0372537 0.0431462 0.0520912 0.0566484 0.0564452 0.055131 0.0482026 0.0392787 0.0353649 0.0365409 0.0365872 0.0357355 0.0352664 0.0353291 0.0356977 0.0359433 0.03609 0.0362916 0.0365258 0.0367093 0.0370863 0.0378048 0.0390207 0.0408172 0.0429067 0.0448133 0.0457773 0.0461751 0.044642 0.0423366 0.0404899 0.0392382 0.0385503 0.0386512 0.0391363 0.0399194 0.0409088 0.0412973 0.0410337 0.0433325 0.0482992 0.0326552 0.026495 0.0273523 0.0279799 0.0287506 0.0314138 0.0352346 0.0390434 0.0421665 0.0446076 0.0465396 0.0480913 0.0493727 0.0505543 0.0519384 0.0536955 0.0556924 0.057247 0.0587156 0.0594771 0.0599964 0.060573 0.0608893 0.0608033 0.0602241 0.0592875 0.0580955 0.0568854 0.0558128 0.0549691 0.0542819 0.053941 0.0538633 0.054073 0.0546769 0.05537 0.0560825 0.0608139 0.0696665 0.0717354 0.0714495 0.0716882 0.072041 0.0715675 0.0683335 0.0627248 0.0615701 0.064555 0.0704522 0.0724604 0.0303201 0.0265282 0.0229614 0.0215951 0.0212997 0.0213599 0.0213807 0.0214094 0.0213854 0.0213661 0.0212754 0.021261 0.0211437 0.021126 0.0211322 0.0212206 0.0214061 0.0216263 0.021811 0.0218208 0.0215781 0.0213499 0.0210491 0.0210707 0.0211542 0.0221874 0.0264321 0.0303239 0.0295512 0.0276259 0.0270982 0.0266575 0.0260902 0.0256774 0.0254673 0.0255572 0.0258524 0.026216 0.0266355 0.0269674 0.027219 0.0273887 0.0274943 0.0275698 0.0275858 0.0275965 0.0276233 0.0276421 0.0277674 0.0278297 0.0278897 0.0278776 0.0276702 0.0276952 0.0287152 0.0310679 0.0322402 0.0324794 0.0326259 0.0327997 0.0330708 0.0334449 0.0340506 0.0351877 0.0356124 0.0338824 0.0315962 0.0304384 0.0298997 0.0296084 0.0294309 0.0293466 0.0294057 0.0296038 0.0300032 0.0306893 0.0318673 0.0331898 0.0343064 0.0351188 0.0357275 0.0363452 0.037073 0.0375913 0.0376782 0.036912 0.0348282 0.031074 0.030629 0.0320735 0.032404 0.0322207 0.0319579 0.0317268 0.0313997 0.0313453 0.0310396 0.0311505 0.0309389 0.0311051 0.0310587 0.0311471 0.0310248 0.030886 0.0306582 0.0304144 0.0302661 0.0303334 0.0305148 0.0307884 0.0307668 0.0305487 0.0306271 0.0313304 0.0325731 0.0365706 0.0372629 0.0369202 0.0369953 0.0370647 0.0370649 0.0369858 0.0367694 0.036544 0.0362638 0.0359273 0.0356788 0.0356013 0.0351083 0.0350567 0.0349479 0.0351006 0.035133 0.0353039 0.035385 0.0353941 0.0352685 0.0351362 0.0350428 0.0349396 0.0350732 0.0353209 0.0357363 0.0362761 0.0368571 0.0373611 0.0378358 0.0382256 0.0384617 0.0386535 0.0388966 0.0391539 0.0393524 0.039661 0.0392484 0.0367744 0.035494 0.0376528 0.0387914 0.0386254 0.0385054 0.0385056 0.0385655 0.0386673 0.0387824 0.0388702 0.0390211 0.0390911 0.0391791 0.0392947 0.0394297 0.0396114 0.0398299 0.0400764 0.0404285 0.0408078 0.0411283 0.0412416 0.0413332 0.041487 0.0415766 0.0416869 0.0416991 0.0416995 0.0415733 0.0414859 0.0412866 0.04119 0.0409071 0.0406026 0.0398145 0.0380701 0.0374988 0.0401106 0.0415716 0.0351246 0.0275354 0.0253726 0.0249276 0.0243876 0.0239848 0.0237795 0.0236605 0.0235691 0.0234789 0.0233917 0.0233587 0.0234201 0.0236165 0.0240062 0.0247742 0.0258861 0.0280487 0.0285541 0.0310864 0.0314936 0.0319425 0.0322261 0.0315258 0.0307206 0.0297898 0.0285161 0.026586 0.0253502 0.0268759 0.0338152 0.0365576 0.030742 0.027342 0.0281713 0.0284338 0.0266251 0.0242695 0.0226136 0.0217947 0.0214496 0.0214967 0.0222825 0.0235828 0.0251766 0.0267058 0.0280828 0.0289723 0.0287711 0.027945 0.0272662 0.0252269 0.0253677 0.023683 0.0233935 0.0227891 0.0225746 0.0228063 0.0239837 0.0288549 0.0459055 0.0565059 0.0511956 0.0338386 0.0267868 0.0264927 0.0286122 0.0305741 0.031329 0.0317245 0.0320826 0.0319093 0.0319857 0.0320216 0.0321244 0.0323558 0.0327977 0.0332281 0.0335628 0.0337095 0.0336307 0.0334323 0.0326887 0.0298387 0.0261674 0.0266722 0.0328607 0.0386123 0.0405719 0.0433832 0.0516538 0.0557612 0.0475206 0.0383088 0.0355155 0.0359399 0.0370077 0.0358425 0.0361484 0.0360168 0.0358527 0.0357837 0.0357328 0.0357787 0.0356999 0.0355128 0.0354625 0.0354331 0.0355938 0.0358519 0.0360801 0.0365379 0.0369397 0.0373303 0.0384938 0.047522 0.0564167 0.0591222 0.0590384 0.0584955 0.0571737 0.0466348 0.0362588 0.0373095 0.0386827 0.0390034 0.0384336 0.0394385 0.0403889 0.0405097 0.041296 0.0412809 0.0413446 0.0414461 0.0416828 0.0419814 0.04242 0.0428985 0.043477 0.0439892 0.0442329 0.0442935 0.0440092 0.0435552 0.0430885 0.0426983 0.0424274 0.0422868 0.0421087 0.0420099 0.0418538 0.0414013 0.0410677 0.0463444 0.0521219 0.042246 0.0280698 0.0279303 0.0311078 0.032415 0.0339675 0.0358501 0.0378916 0.0399745 0.0419867 0.0438488 0.0455771 0.047255 0.0488803 0.0503759 0.0517084 0.0527977 0.0539045 0.0546696 0.0554573 0.0561177 0.0565889 0.056969 0.0572567 0.0573268 0.0572545 0.0570482 0.0567672 0.0565395 0.0563002 0.0558425 0.0557663 0.0552751 0.0553987 0.0555171 0.0558503 0.056855 0.0658872 0.0719161 0.0719735 0.0719717 0.0720234 0.0721463 0.0722006 0.0722371 0.0718138 0.0718562 0.0722343 0.0725078 0.0724598 ) ; boundaryField { wand { type zeroGradient; } frontAndBack { type empty; } } // ************************************************************************* //
5c52abba203ecf1d7bad2eb7579fc950709b61ff
ba80a4bdda1d58df8c0e34cdeea14eebeadffdbe
/src/image_object_renderer.cpp
eacff4b614bb96ed8e85bd98db1aaba8beddea3c
[]
no_license
lms-org/image_object_renderer
abe51f637557d0e49fb19bad2bf4f16f6f7bc34b
fa0d47b3b77d7aba3bdf91d7d5a5e28e062cab66
refs/heads/master
2021-03-19T08:22:22.692707
2017-02-03T19:31:06
2017-02-03T19:31:06
null
0
0
null
null
null
null
UTF-8
C++
false
false
11,377
cpp
image_object_renderer.cpp
#include "image_object_renderer.h" #include "street_environment/start_line.h" #include <math.h> bool ImageObjectRenderer::initialize() { int imageWidth = config().get<int>("imageWidth", 512); int imageHeight = config().get<int>("imageHeight", 512); image = writeChannel<lms::imaging::Image>("IMAGE"); image->resize(imageWidth, imageHeight, lms::imaging::Format::BGRA); graphics = new lms::imaging::BGRAImageGraphics(*image); drawObjectStrings = config().getArray<std::string>("envObjects"); for (std::string &obj : drawObjectStrings) { drawObjects.push_back(readChannel<lms::Any>(obj)); } return true; } bool ImageObjectRenderer::deinitialize() { return true; } bool ImageObjectRenderer::cycle() { image->fill(0); for (lms::ReadDataChannel<lms::Any> &dO : drawObjects) { // set the color logger.debug("trying to draw: ") << dO.name(); bool customColor = setColor(dO.name()); if (dO.castableTo<lms::math::polyLine2f>()) { int crossLength = config(dO.name()).get<int>("crossLength", 2); if (config(dO.name()).get<std::string>("attr", "") == "point") { for (lms::math::vertex2f v : dO.getWithType<lms::math::polyLine2f>()->points()) { drawVertex2f(v, crossLength); } } else { drawPolyLine(dO.getWithType<lms::math::polyLine2f>()); } } else if (dO.castableTo<lms::math::vertex2f>()) { drawVertex2f(*dO.getWithType<lms::math::vertex2f>()); logger.debug("") << "drawing v2f"; } else if (dO.castableTo<street_environment::EnvironmentObjects>()) { logger.debug("") << "drawing evo, it has "<<dO.getWithType<street_environment::EnvironmentObjects>() ->objects.size(); for (const std::shared_ptr<street_environment::EnvironmentObject> &eo : (dO.getWithType<street_environment::EnvironmentObjects>() ->objects)) { drawObject(eo.get(), customColor); } } else if (dO.castableTo<street_environment::TrajectoryPoint>()) { logger.debug("") << "drawing TrajectoryPoint"; drawTrajectoryPoint( *(dO.getWithType<street_environment::TrajectoryPoint>())); } else if (dO.castableTo<std::vector<lms::math::Rect>>()) { logger.debug("") << "drawing rects"; for (lms::math::Rect r : *dO.getWithType<std::vector<lms::math::Rect>>()) { drawRect(r); } } else if (dO.castableTo<street_environment::Trajectory>()) { logger.debug("") << "drawing trajectory"; drawTrajectory(*dO.getWithType<street_environment::Trajectory>()); } else if (dO.castableTo<street_environment::RoadMatrix>()) { drawRoadMatrix(*dO.getWithType<street_environment::RoadMatrix>()); } else if (dO.castableTo<lms::math::PointCloud2f>()) { drawPointCloud2f(*dO.getWithType<lms::math::PointCloud2f>()); } else if (dO.castableTo<street_environment::BasicObstacleVector>()) { drawBasicObstacles( *dO.getWithType<street_environment::BasicObstacleVector>()); } else { logger.error("cycle") << "No valid type for " << dO.name(); } } return true; } void ImageObjectRenderer::drawRoadMatrix(const street_environment::RoadMatrix &rm){ for(int x = 0; x < rm.length(); x++){ for(int y = 0; y < rm.width(); y++){ street_environment::RoadMatrixCell rmc = rm.cell(x,y); lms::imaging::ARGBColor color; if (rmc.hasObstacle){ color = lms::imaging::ARGBColor(230,255,0,0); } else { color = lms::imaging::ARGBColor(230,0,255,0); } graphics->setColor(color); drawTriangle(rmc.points[0],rmc.points[1],rmc.points[2],true); drawTriangle(rmc.points[0],rmc.points[2],rmc.points[3],true); } } } void ImageObjectRenderer::drawPointCloud2f(const lms::math::PointCloud2f &pointCloud) { for (const lms::math::vertex2f &point : pointCloud.points()) { drawVertex2f(point, 1); } } void ImageObjectRenderer::drawTrajectory(const street_environment::Trajectory &tra){ for(int i = 1; i <(int)tra.size(); i++){ if(tra[i-1].velocity == 0){ lms::imaging::ARGBColor color=lms::imaging::ARGBColor(0,0,0); graphics->setColor(color); }else{ lms::imaging::ARGBColor color=lms::imaging::ARGBColor(0,255,255); graphics->setColor(color); } drawLine(tra[i-1].position.x,tra[i-1].position.y,tra[i].position.x,tra[i].position.y); drawVertex2f(tra[i-1].position); } } void ImageObjectRenderer::drawBasicObstacles( const street_environment::BasicObstacleVector &obstacles) { for(const auto& obstacle : obstacles) { drawBoundingBox(obstacle.boundingBox()); } } void ImageObjectRenderer::drawBoundingBox( const street_environment::BoundingBox2f &boundingBox) { drawLine(boundingBox.corners()[0],boundingBox.corners()[1]); drawLine(boundingBox.corners()[1],boundingBox.corners()[2]); drawLine(boundingBox.corners()[2],boundingBox.corners()[3]); drawLine(boundingBox.corners()[3],boundingBox.corners()[0]); } void ImageObjectRenderer::drawTriangle(lms::math::vertex2f v1, lms::math::vertex2f v2, lms::math::vertex2f v3,bool filled){ if(filled){ graphics->fillTriangle(xToImage(v1.x),yToImage(v1.y),xToImage(v2.x),yToImage(v2.y),xToImage(v3.x),yToImage(v3.y)); }else{ graphics->drawTriangle(xToImage(v1.x),yToImage(v1.y),xToImage(v2.x),yToImage(v2.y),xToImage(v3.x),yToImage(v3.y)); } } int ImageObjectRenderer::xToImage(float x){ return x * image->height() / 5 + config().get<float>("translateX", 0) * image->height() / 5; } int ImageObjectRenderer::yToImage(float y){ return -y*image->width()/5+image->width()/2; } void ImageObjectRenderer::drawVertex2f(const lms::math::vertex2f &v, int length){ graphics->drawCross(xToImage(v.x), yToImage(v.y), length); } void ImageObjectRenderer::drawPolyLine(const lms::math::polyLine2f *lane){ lms::imaging::BGRAImageGraphics g(*image); int xOld = 0; int yOld = 0; logger.debug("drawPolyLine")<<"points: "<<lane->points().size(); for(uint i = 0; i < lane->points().size(); i++){ lms::math::vertex2f v = lane->points()[i]; //TODO add some translate method to the config... int y = yToImage(v.y); int x = xToImage(v.x); graphics->drawCross(x,y,5); if(i != 0){ graphics->drawLine(x,y,xOld,yOld); } xOld = x; yOld = y; } } void ImageObjectRenderer::drawLine(lms::math::vertex2f p1, lms::math::vertex2f p2){ drawLine(p1.x,p1.y,p2.x,p2.y); } void ImageObjectRenderer::drawLine(float x1, float y1, float x2, float y2){ graphics->drawLine(xToImage(x1), yToImage(y1), xToImage(x2), yToImage(y2)); } void ImageObjectRenderer::drawRect(const lms::math::Rect &r){ drawLine(r.x,r.y,r.x,r.y+r.height); drawLine(r.x+r.width,r.y,r.x+r.width,r.y+r.height); drawLine(r.x,r.y+r.height,r.x+r.width,r.y+r.height); drawLine(r.x,r.y,r.x+r.width,r.y); } void ImageObjectRenderer::drawRect(float x, float y, float width, float height, bool filled){ //TODO if(filled) graphics->fillRect(x,y,width,height); else graphics->drawRect(x,y,width,height); } void ImageObjectRenderer::drawTrajectoryPoint(const street_environment::TrajectoryPoint &v){ drawVertex2f(lms::math::vertex2f(v.position.x,v.position.y)); //TODO draw direction } void ImageObjectRenderer::drawObject(const street_environment::EnvironmentObject *eo, bool customColor){ float lineWidth = 0.01; float lineWidthStep = 0.01; if(eo->getType() == 0){ const street_environment::RoadLane &lane = eo->getAsReference<const street_environment::RoadLane>(); drawPolyLine(&lane); }else if(eo->getType() == 1){ const street_environment::Obstacle &obst = eo->getAsReference<const street_environment::Obstacle>(); if(!customColor){ if(obst.trust() > config().get<float>("obstacleTrustThreshold",0.5)){ setColor("OBSTACLE_DETECTED"); }else{ setColor("DEFAULT_OBSTACLE"); } } drawObstacle(&obst); }else if(eo->getType() == street_environment::Crossing::TYPE){ const street_environment::Crossing &crossing = eo->getAsReference<const street_environment::Crossing>(); //if(!customColor){ //TODO if(crossing.trust() > config().get<float>("crossingTrustThreshold",0)){ setColor("CROSSING"); }else{ setColor("CROSSING_NOT_TRUSTED"); } //} lms::math::vertex2f toAdd =crossing.viewDirection().normalize(); toAdd = toAdd.rotateAntiClockwise90deg() * 0.2; for(float i = -lineWidth; i <= lineWidth; i += lineWidthStep){ drawLine(crossing.position()-toAdd+crossing.viewDirection()*i, crossing.position()+toAdd+crossing.viewDirection()*i); } drawRect(crossing.blockedRect()); //drawObstacle(&crossing); }else if(eo->getType() == street_environment::StartLine::TYPE){ const street_environment::StartLine &start = eo->getAsReference<const street_environment::StartLine>(); setColor("START_LINE"); lms::math::vertex2f toAdd =start.viewDirection(); toAdd = toAdd.rotateAntiClockwise90deg() * 0.4; for(float i = -lineWidth; i <= lineWidth; i += lineWidthStep){ drawLine(start.position()-toAdd+start.viewDirection()*i, start.position()+toAdd+start.viewDirection()*i); } } } void ImageObjectRenderer::drawObstacle(const street_environment::Obstacle *obstacle){ float lineWidth = 0.01; float lineWidthStep = 0.01; //Draw points drawVertex2f(obstacle->position()); //TODO draw bounding box! street_environment::BoundingBox2f box = obstacle->boundingBox(); drawLine(box.corners()[0],box.corners()[1]); drawLine(box.corners()[1],box.corners()[2]); drawLine(box.corners()[2],box.corners()[3]); drawLine(box.corners()[3],box.corners()[0]); /* lms::math::vertex2f toAdd = obstacle->viewDirection().rotateAntiClockwise90deg()*obstacle->width(); for(float i = -lineWidth; i <= lineWidth; i += lineWidthStep){ drawLine(obstacle->position()-toAdd+obstacle->viewDirection()*i, obstacle->position()+toAdd+obstacle->viewDirection()*i); }*/ } bool ImageObjectRenderer::setColor(std::string toDrawName){ const lms::Config* m_config = nullptr; bool customColor = false; if(hasConfig(toDrawName)){ m_config = &config(toDrawName); customColor = true; }else{ m_config = &config(); } lms::imaging::ARGBColor color=lms::imaging::ARGBColor(m_config->get<int>("colorA",255),m_config->get<int>("colorR"), m_config->get<int>("colorG"),m_config->get<int>("colorB")); graphics->setColor(color); return customColor; }
f47952fb9ed36373b1b6a987c00bd333b1c02f0d
4cae422afc5224db8846d9c454a12ef627fd4909
/MyRenderer/Grid.cpp
e527707fc78e766f5174401a35c9ebbd38d3cd2b
[]
no_license
EternalWind/MyRenderer
90adcbd79e68634c225532018e6507f756ac22fa
973e9090470d4992a97ab7c1caf708ec314638fd
refs/heads/master
2016-09-10T01:03:30.824093
2014-06-07T06:06:13
2014-06-07T06:06:13
20,586,847
0
0
null
null
null
null
UTF-8
C++
false
false
2,502
cpp
Grid.cpp
#include "Grid.h" Grid::Grid(float resolution_parameter, unsigned max_resolution) : m_BoundingBox(new AABB()), m_ResolutionParameter(resolution_parameter), m_MaxResolution(max_resolution) { } void Grid::Initialize(const List(Object)& objects) { unsigned total_triangle_number = 0; for (auto iter = objects.begin(); iter != objects.end(); ++iter) { auto object = *iter; m_BoundingBox->ExtendBy(object->BoundingVolume().get()); total_triangle_number += object->NumTriangles(); } Vector3 grid_size = m_BoundingBox->MaxExtent() - m_BoundingBox->MinExtent(); float inv_grid_vol = 1 / (grid_size.X() * grid_size.Y() * grid_size.Z()); float exp = 1.f / 3.f; float res_factor = powf(m_ResolutionParameter * total_triangle_number * inv_grid_vol, exp); unsigned total_cell_num = 1; for (unsigned i = 0; i < 3; ++i) { m_Resolution[i] = Math::Clamp(unsigned(grid_size[i] * res_factor), m_MaxResolution, unsigned(1)); m_CellSize[i] = grid_size[i] / m_Resolution[i]; total_cell_num *= m_Resolution[i]; } m_Cells.resize(total_cell_num); for (auto iter = objects.begin(); iter != objects.end(); ++iter) Insert(*iter); } void Grid::Insert(shared_ptr<Object> object) { auto triangles = object->Triangles(); static const float max = numeric_limits<float>::max(); static const float min = -max; Vector3 grid_orig = m_BoundingBox->MinExtent(); for (auto iter = triangles.begin(); iter != triangles.end(); ++iter) { Vector3 min_extent(max, max, max); Vector3 max_extent(min, min, min); for (unsigned i = 0; i < 3; ++i) { const Vector3& vertex = (*iter)->Vertex(i); for (unsigned j = 0; j < 3; ++j) { if (min_extent[j] > vertex[j]) min_extent[j] = vertex[j]; if (max_extent[j] < vertex[j]) max_extent[j] = vertex[j]; } } unsigned min_cell_indices[3]; unsigned max_cell_indices[3]; for (unsigned i = 0; i < 3; ++i) { min_cell_indices[i] = Math::Clamp(unsigned((min_extent[i] - grid_orig[i]) / m_CellSize[i]), m_Resolution[i] - 1, unsigned(0)); max_cell_indices[i] = Math::Clamp(unsigned((max_extent[i] - grid_orig[i]) / m_CellSize[i]), m_Resolution[i] - 1, unsigned(0)); } shared_ptr<Triangle> triangle = *iter; for (unsigned z = min_cell_indices[2]; z <= max_cell_indices[2]; ++z) for (unsigned y = min_cell_indices[1]; y <= max_cell_indices[1]; ++y) for (unsigned x = min_cell_indices[0]; x <= max_cell_indices[0]; ++x) _CellAt(x, y, z).triangles.push_back(triangle); } } Grid::~Grid(void) { }
ae0c7968936823bc089d5006b0cf755e45eab5d6
71cbc64910807ceab826a6c54e0fea8d96104506
/Cool3D/RenderMtl/MConstColor.cpp
9fe09059f8b5c7d9f45deed2bf36e2e0c5aec001
[]
no_license
adrianolls/ll
385580143dfc2365428469a51c220da08bfea8ec
9c7d480036b1e6f1e3bdffe93b44bd5c70bd944a
refs/heads/master
2022-12-26T07:06:13.260844
2020-09-16T04:36:17
2020-09-16T04:36:17
null
0
0
null
null
null
null
UTF-8
C++
false
false
751
cpp
MConstColor.cpp
#include "StdAfx.h" #include ".\mconstcolor.h" #include "..\RenderSys\RenderSys.h" namespace Cool3D { IMP_RTTI_DYNC(MConstColor,IRenderMtl); MConstColor::MConstColor(void) { m_color=RenderSys::WhiteRenderColor; m_bUsingVertColor=false; } MConstColor::~MConstColor(void) { } void MConstColor::Serialize(FArchive& ar) { ar<<m_color.ambient; ar<<m_color.diffuse; ar<<m_color.emissive; ar<<m_color.power; ar<<m_color.specular; ar<<m_bUsingVertColor; IRenderMtl::Serialize(ar); } void MConstColor::Deserialize(FArchive& ar) { ar>>m_color.ambient; ar>>m_color.diffuse; ar>>m_color.emissive; ar>>m_color.power; ar>>m_color.specular; ar>>m_bUsingVertColor; IRenderMtl::Deserialize(ar); } }//namespace Cool3D
f47ac8affd9eb8956367e99fe744e8ad990afb55
ba7ceccb3a9606dae22000eab8384fd000132977
/Inheritance/Polymorphism.cpp
71f70198ee75e7e8ffab51fa183f6e2895732623
[]
no_license
hitman699/C-Code
02c44cfc6c1f8d4b6218dae47bccb6bba072a027
45d029c6b89230d6ddc86e0bde7811054e6919b3
refs/heads/master
2020-09-01T19:19:00.567764
2019-12-04T18:30:21
2019-12-04T18:30:21
219,035,615
0
0
null
null
null
null
UTF-8
C++
false
false
559
cpp
Polymorphism.cpp
#include<bits/stdc++.h> using namespace std; class Person { public: virtual void intro() { cout<<"Called from Person"<<endl; } }; class Student : public Person { public: void intro() { cout<<"Called from Student"<<endl; } }; class Farmer : public Person { public: void intro() { cout<<"Called From Farmer"<<endl; } }; void name(Person &p) //If i put Person P(Person class Intro is called); { p.intro(); } int32_t main() { Farmer f1; Student s1; name(f1); name(s1); }
24b6de89831f8397f1d177c1e218492883126ec0
8262a782e189aed545a805ac67809a141f75a669
/NICEDAY (segment tree).cpp
e2683e419de261e13598f4f5bf1b0cd500c5c3ad
[]
no_license
rjrks/Spoj
7e245e877a9924a0bb4661be39121832ddda1fc7
a3236ee6a773d08078f13e46f5eee40b638d461b
refs/heads/master
2020-04-06T04:55:36.584359
2015-07-13T19:23:55
2015-07-13T19:24:17
35,376,048
0
0
null
null
null
null
UTF-8
C++
false
false
2,024
cpp
NICEDAY (segment tree).cpp
// // Created by Rohan on 23/12/14. // Copyright (c) 2014 Rohan. All rights reserved. // #include <math.h> #include <iostream> #include <vector> #include <string.h> #include <sstream> #include <stdio.h> #include <stdlib.h> #include <cmath> #include <list> #include <stack> #include <map> #include <string.h> #include <set> #include <algorithm> using namespace std; //typedef uint64_t ll; int fmini(int node, int b, int e, int j, int *m){ if(j<b)return 0; else if(e<=j)return m[node]; int p1=fmini(2*node, b, (b+e)/2, j,m); int p2=fmini(2*node+1, (b+e)/2+1, e, j,m); if(p1==0)return p2; else if(p2==0)return p1; else return min(p1,p2); } void setq(int node,int b,int e,int j,int val, int *m){ if(e<j || b>j)return; if(b==e){m[node]=val; return;} int mid=(b+e)/2; setq(2*node, b, mid, j,val,m); setq(2*node+1, mid+1, e, j,val,m); if(m[node]==0)m[node]=val; else m[node]=min(m[node],val); } class pos{ public: int a,b,c; }; bool comp(pos p1,pos p2){ return p1.a<p2.a; } int main(){ int tc; scanf("%d",&tc); while(tc--){ int n; scanf("%d",&n); int m[400000]={0}; // change here pos p[n+1]; for(int i=1;i<=n;i++){ scanf("%d",&p[i].a); scanf("%d",&p[i].b); scanf("%d",&p[i].c); } sort(p+1, p+n+1, comp); int cnt=0; for(int i=1;i<=n;i++){ int fmin=fmini(1, 1, n, p[i].b,m); // cout<<fmin<<endl; if(fmin==0 || p[i].c<fmin){ cnt++; setq(1, 1, n, p[i].b, p[i].c,m); } // cout<<m[4]<<endl; } printf("%d\n",cnt); } } /* 1 */
c10929d8d9193946147111f0e80af0b24476dc18
a5b55a2379f0e260330642ffff7ca8ca86e7eb5a
/test/testAccuracy.cpp
8b4a886a635ad24acd995a62d6e6f0f20c23387e
[]
no_license
Jonaslinderoth/MasterThesis
0a3d0c4dfeb05029906f87dd2817c804862a810c
145a0ce42c17761b505f8dc34f1a1e2d23dd82bd
refs/heads/master
2022-10-08T09:29:12.129778
2020-06-11T20:02:55
2020-06-11T20:02:55
238,170,716
0
0
null
null
null
null
UTF-8
C++
false
false
12,931
cpp
testAccuracy.cpp
#include <gtest/gtest.h> #include <vector> #include <math.h> #include "../src/testingTools/DataGeneratorBuilder.h" #include "../src/dataReader/Cluster.h" #include "../src/dataReader/DataReader.h" #include "../src/testingTools/MetaDataFileReader.h" #include "../src/testingTools/RandomFunction.h" #include "../src/DOC_GPU/DOCGPU.h" #include "../src/Fast_DOCGPU/Fast_DOCGPU.h" #include "../src/MineClusGPU/MineClusGPU.h" #include "../src/Evaluation.h" TEST(testAccuracy, testSimple){ auto clusters = new std::vector<std::vector<std::vector<float>*>*>; auto labels = new std::vector<std::vector<std::vector<float>*>*>; { auto point1 = new std::vector<float>{1,2}; auto point2 = new std::vector<float>{2,3}; auto cluster1 = new std::vector<std::vector<float>*>{point1,point2}; auto point3 = new std::vector<float>{3,4}; auto point4 = new std::vector<float>{4,5}; auto cluster2 = new std::vector<std::vector<float>*>{point3,point4}; clusters->push_back(cluster1); clusters->push_back(cluster2); } { auto point1 = new std::vector<float>{1,2}; auto point2 = new std::vector<float>{2,3}; auto cluster1 = new std::vector<std::vector<float>*>{point1,point2}; auto point3 = new std::vector<float>{3,4}; auto point4 = new std::vector<float>{4,5}; auto cluster2 = new std::vector<std::vector<float>*>{point3,point4}; labels->push_back(cluster1); labels->push_back(cluster2); } auto res = Evaluation::confusion(labels, clusters); EXPECT_EQ(res.at(0).at(0), 2); EXPECT_EQ(res.at(1).at(1), 2); EXPECT_EQ(res.at(0).at(1), 0); EXPECT_EQ(res.at(1).at(0), 0); EXPECT_FLOAT_EQ(Evaluation::accuracy(res), 1); } TEST(testAccuracy, testSimple2){ auto clusters = new std::vector<std::vector<std::vector<float>*>*>; auto labels = new std::vector<std::vector<std::vector<float>*>*>; { auto point1 = new std::vector<float>{1,2}; auto point2 = new std::vector<float>{2,3}; auto cluster1 = new std::vector<std::vector<float>*>{point1,point2}; auto point3 = new std::vector<float>{3,4}; auto point4 = new std::vector<float>{4,5}; auto cluster2 = new std::vector<std::vector<float>*>{point3,point4}; auto point5 = new std::vector<float>{5,6}; auto point6 = new std::vector<float>{6,7}; auto cluster3 = new std::vector<std::vector<float>*>{point5,point6}; clusters->push_back(cluster1); clusters->push_back(cluster2); clusters->push_back(cluster3); } { auto point1 = new std::vector<float>{1,2}; auto point2 = new std::vector<float>{2,3}; auto cluster1 = new std::vector<std::vector<float>*>{point1,point2}; auto point3 = new std::vector<float>{3,4}; auto point4 = new std::vector<float>{4,5}; auto cluster2 = new std::vector<std::vector<float>*>{point3,point4}; auto point6 = new std::vector<float>{6,7}; auto point5 = new std::vector<float>{5,6}; auto cluster3 = new std::vector<std::vector<float>*>{point5,point6}; labels->push_back(cluster1); labels->push_back(cluster2); labels->push_back(cluster3); } auto res = Evaluation::confusion(labels, clusters); EXPECT_EQ(res.at(0).at(0), 2); EXPECT_EQ(res.at(1).at(1), 2); EXPECT_EQ(res.at(2).at(2), 2); EXPECT_EQ(res.at(0).at(1), 0); EXPECT_EQ(res.at(0).at(2), 0); EXPECT_EQ(res.at(1).at(0), 0); EXPECT_EQ(res.at(1).at(2), 0); EXPECT_EQ(res.at(2).at(0), 0); EXPECT_EQ(res.at(2).at(1), 0); EXPECT_FLOAT_EQ(Evaluation::accuracy(res), 1); } TEST(testAccuracy, testSimple3){ auto clusters = new std::vector<std::vector<std::vector<float>*>*>; auto labels = new std::vector<std::vector<std::vector<float>*>*>; { auto point1 = new std::vector<float>{1,2}; auto point2 = new std::vector<float>{2,3}; auto cluster1 = new std::vector<std::vector<float>*>{point1,point2}; auto point3 = new std::vector<float>{3,4}; auto point4 = new std::vector<float>{4,5}; auto cluster2 = new std::vector<std::vector<float>*>{point3,point4}; auto point5 = new std::vector<float>{5,6}; auto point6 = new std::vector<float>{6,7}; auto cluster3 = new std::vector<std::vector<float>*>{point5,point6}; clusters->push_back(cluster1); clusters->push_back(cluster2); clusters->push_back(cluster3); } { auto point2 = new std::vector<float>{2,3}; auto point1 = new std::vector<float>{1,2}; auto point1_1 = new std::vector<float>{9,9}; auto cluster1 = new std::vector<std::vector<float>*>{point1,point2,point1_1}; auto point3 = new std::vector<float>{3,4}; auto point4 = new std::vector<float>{4,5}; auto cluster2 = new std::vector<std::vector<float>*>{point3,point4}; auto point6 = new std::vector<float>{6,7}; auto point5 = new std::vector<float>{5,6}; auto cluster3 = new std::vector<std::vector<float>*>{point5,point6}; labels->push_back(cluster1); labels->push_back(cluster2); labels->push_back(cluster3); } auto res = Evaluation::confusion(labels, clusters); EXPECT_EQ(res.at(0).at(0), 2); EXPECT_EQ(res.at(1).at(1), 2); EXPECT_EQ(res.at(2).at(2), 2); EXPECT_EQ(res.at(0).at(1), 0); EXPECT_EQ(res.at(0).at(2), 0); EXPECT_EQ(res.at(1).at(0), 0); EXPECT_EQ(res.at(1).at(2), 0); EXPECT_EQ(res.at(2).at(0), 0); EXPECT_EQ(res.at(2).at(1), 0); EXPECT_FLOAT_EQ(Evaluation::accuracy(res), 1); } TEST(testAccuracy, testSimple4){ auto clusters = new std::vector<std::vector<std::vector<float>*>*>; auto labels = new std::vector<std::vector<std::vector<float>*>*>; { auto point1 = new std::vector<float>{1,2}; auto point2 = new std::vector<float>{2,3}; auto cluster1 = new std::vector<std::vector<float>*>{point1,point2}; auto point3 = new std::vector<float>{3,4}; auto point4 = new std::vector<float>{4,5}; auto cluster2 = new std::vector<std::vector<float>*>{point3,point4}; auto point5 = new std::vector<float>{5,6}; auto point6 = new std::vector<float>{6,7}; auto point1_1 = new std::vector<float>{9,9}; auto cluster3 = new std::vector<std::vector<float>*>{point5,point6,point1_1}; clusters->push_back(cluster1); clusters->push_back(cluster2); clusters->push_back(cluster3); } { auto point2 = new std::vector<float>{2,3}; auto point1 = new std::vector<float>{1,2}; auto point1_1 = new std::vector<float>{9,9}; auto cluster1 = new std::vector<std::vector<float>*>{point1,point2,point1_1}; auto point3 = new std::vector<float>{3,4}; auto point4 = new std::vector<float>{4,5}; auto cluster2 = new std::vector<std::vector<float>*>{point3,point4}; auto point6 = new std::vector<float>{6,7}; auto point5 = new std::vector<float>{5,6}; auto cluster3 = new std::vector<std::vector<float>*>{point5,point6}; labels->push_back(cluster1); labels->push_back(cluster2); labels->push_back(cluster3); } auto res = Evaluation::confusion(labels, clusters); EXPECT_EQ(res.at(0).at(0), 2); EXPECT_EQ(res.at(1).at(1), 2); EXPECT_EQ(res.at(2).at(2), 2); EXPECT_EQ(res.at(0).at(1), 0); EXPECT_EQ(res.at(0).at(2), 1); EXPECT_EQ(res.at(1).at(0), 0); EXPECT_EQ(res.at(1).at(2), 0); EXPECT_EQ(res.at(2).at(0), 0); EXPECT_EQ(res.at(2).at(1), 0); EXPECT_FLOAT_EQ(Evaluation::accuracy(res), ((float)6/7)); } TEST(testAccuracy, testDataReader){ DataGeneratorBuilder dgb; dgb.setSeed(0); bool res2 = dgb.buildUClusters("test2222",20,2,15,2,1,0); EXPECT_TRUE(res2); auto dr = new DataReader("test2222"); EXPECT_EQ(dr->getSize(), 40); auto mdr = new MetaDataFileReader("test2222"); std::vector<std::vector<std::vector<float>*>*>* labels = new std::vector<std::vector<std::vector<float>*>*>; labels->push_back(new std::vector<std::vector<float>*>); labels->push_back(new std::vector<std::vector<float>*>); while(dr->isThereANextPoint()){ labels->at(mdr->nextCheat())->push_back(dr->nextPoint()); } auto res = Evaluation::confusion(labels, labels); EXPECT_FLOAT_EQ(Evaluation::accuracy(res), 1); } TEST(testAccuracy, testDataReader2){ DataGeneratorBuilder dgb; dgb.setSeed(0); bool res2 = dgb.buildUClusters("test2222",20,2,15,10,2,0, true); EXPECT_TRUE(res2); auto dr = new DataReader("test2222"); EXPECT_EQ(dr->getSize(), 40); auto mdr = new MetaDataFileReader("test2222"); std::vector<std::vector<std::vector<float>*>*>* labels = new std::vector<std::vector<std::vector<float>*>*>; labels->push_back(new std::vector<std::vector<float>*>); labels->push_back(new std::vector<std::vector<float>*>); while(dr->isThereANextPoint()){ labels->at(mdr->nextCheat())->push_back(dr->nextPoint()); } DOCGPU d = DOCGPU(new DataReader("test2222")); d.setWidth(15); d.setSeed(1); auto cluster = d.findKClusters(5); EXPECT_EQ(cluster.size(), 2); EXPECT_EQ(cluster.at(0).first->size(), 20); EXPECT_EQ(cluster.at(1).first->size(), 20); auto res = Evaluation::confusion(labels, cluster); EXPECT_FLOAT_EQ(Evaluation::accuracy(res), 1); } TEST(testAccuracy, SLOW_testDataReader3){ DataGeneratorBuilder dgb; dgb.setSeed(0); bool res2 = dgb.buildUClusters("test2222",200,10,15,10,2,0, true); EXPECT_TRUE(res2); auto dr = new DataReader("test2222"); EXPECT_EQ(dr->getSize(), 2000); auto mdr = new MetaDataFileReader("test2222"); std::vector<std::vector<std::vector<float>*>*>* labels = new std::vector<std::vector<std::vector<float>*>*>; labels->push_back(new std::vector<std::vector<float>*>); labels->push_back(new std::vector<std::vector<float>*>); labels->push_back(new std::vector<std::vector<float>*>); labels->push_back(new std::vector<std::vector<float>*>); labels->push_back(new std::vector<std::vector<float>*>); labels->push_back(new std::vector<std::vector<float>*>); labels->push_back(new std::vector<std::vector<float>*>); labels->push_back(new std::vector<std::vector<float>*>); labels->push_back(new std::vector<std::vector<float>*>); labels->push_back(new std::vector<std::vector<float>*>); while(dr->isThereANextPoint()){ labels->at(mdr->nextCheat())->push_back(dr->nextPoint()); } DOCGPU d = DOCGPU(new DataReader("test2222")); d.setWidth(15); d.setSeed(1); auto cluster = d.findKClusters(10); EXPECT_EQ(cluster.size(), 10); auto res = Evaluation::confusion(labels, cluster); for(unsigned int i = 0; i < res.size(); i++){ for(unsigned int j = 0; j < res.at(i).size(); j++){ std::cout << res.at(i).at(j) << " "; } std::cout << std::endl; } EXPECT_GT(Evaluation::accuracy(res), 0.99); } TEST(testAccuracy, SLOW_testDataReader4){ DataGeneratorBuilder dgb; dgb.setSeed(0); bool res2 = dgb.buildUClusters("test2222",200,10,15,10,2,0, true); EXPECT_TRUE(res2); auto labels = Evaluation::getCluster("test2222"); DOCGPU d = DOCGPU(new DataReader("test2222")); d.setWidth(15); d.setSeed(1); auto cluster = d.findKClusters(10); EXPECT_EQ(cluster.size(), 10); auto res = Evaluation::confusion(labels, cluster); for(unsigned int i = 0; i < res.size(); i++){ for(unsigned int j = 0; j < res.at(i).size(); j++){ std::cout << res.at(i).at(j) << " "; } std::cout << std::endl; } EXPECT_GT(Evaluation::accuracy(res), 0.99); } TEST(testAccuracy, SLOW_testDataReader4_2){ DataGeneratorBuilder dgb; dgb.setSeed(0); bool res2 = dgb.buildUClusters("test2222",200,10,15,10,2,0, true); EXPECT_TRUE(res2); auto labels = Evaluation::getCluster("test2222"); DOCGPU d = DOCGPU(new DataReader("test2222")); d.setWidth(15); d.setSeed(1); d.setNumberOfSamples(1024*4); auto cluster = d.findKClusters(10); EXPECT_EQ(cluster.size(), 10); auto res = Evaluation::confusion(labels, cluster); for(unsigned int i = 0; i < res.size(); i++){ for(unsigned int j = 0; j < res.at(i).size(); j++){ std::cout << res.at(i).at(j) << " "; } std::cout << std::endl; } EXPECT_GT(Evaluation::accuracy(res), 0.99); } TEST(testAccuracy, SLOW_testDataReader5){ DataGeneratorBuilder dgb; dgb.setSeed(0); bool res2 = dgb.buildUClusters("test2222",200,10,15,10,2,0, true); EXPECT_TRUE(res2); auto labels = Evaluation::getCluster("test2222"); Fast_DOCGPU d = Fast_DOCGPU(new DataReader("test2222")); d.setWidth(15); d.setSeed(1); auto cluster = d.findKClusters(10); EXPECT_EQ(cluster.size(), 10); auto res = Evaluation::confusion(labels, cluster); for(unsigned int i = 0; i < res.size(); i++){ for(unsigned int j = 0; j < res.at(i).size(); j++){ std::cout << res.at(i).at(j) << " "; } std::cout << std::endl; } EXPECT_GT(Evaluation::accuracy(res), 0.92); } TEST(testAccuracy, SLOW_testDataReader6){ DataGeneratorBuilder dgb; dgb.setSeed(0); bool res2 = dgb.buildUClusters("test2222",200,10,15,10,2,0, true); EXPECT_TRUE(res2); auto labels = Evaluation::getCluster("test2222"); MineClusGPU d = MineClusGPU(new DataReader("test2222")); d.setWidth(15); d.setSeed(1); auto cluster = d.findKClusters(10); EXPECT_EQ(cluster.size(), 4); auto res = Evaluation::confusion(labels, cluster); for(unsigned int i = 0; i < res.size(); i++){ for(unsigned int j = 0; j < res.at(i).size(); j++){ std::cout << res.at(i).at(j) << " "; } std::cout << std::endl; } EXPECT_GT(Evaluation::accuracy(res), 0.99); }
1c87895a6046ca80e2a8457c0146ba59ba838767
b6f935468dde02c112b1e81bc3bc8219ba95ef86
/Trie/SPOJ PHONELST.cpp
cab237bdfab9e65ade44b6d1445e53f6de1183ff
[]
no_license
shashank0107/CP-Solutions
fe15bae919529846de78e6218edd14c643d8027d
e9933a8611bdb3581d59d12136c88c319331118b
refs/heads/master
2020-04-13T01:24:38.998644
2019-05-30T17:52:31
2019-05-30T17:52:31
162,873,528
7
1
null
2019-03-16T13:42:11
2018-12-23T08:11:09
C++
UTF-8
C++
false
false
2,721
cpp
SPOJ PHONELST.cpp
#include <bits/stdc++.h> using namespace std; /*** Template Begins ***/ typedef long long ll; typedef pair<int,int> PII; typedef pair<ll, pair<int, int> > PIII; typedef vector<int> vi; typedef vector<pair<int, int> > vii; #define endl '\n' #define pb push_back #define INF INT_MAX/10 #define F first #define S second #define mp make_pair #define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define hell 1000000007 #define all(a) (a).begin(),(a).end() #define fr(i,a,b) for(int i=a;i<=b;i++) #define lp(i,a) for(int i=0;i< a;i++) // Debug // #define trace(x) cerr << #x << ": " << x << endl; #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl; #define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl; // Constants // const int N = 5e5+7; const int xinc[] = {0, 0, 1, -1}; const int yinc[] = {1, -1, 0, 0}; const long double PI = acos(-1.0); /*** Template Ends ***/ int tree[N][10], n; int root, cur; bool is_word[N], is_pre[N]; string s; bool insert(int now, string& s, int pos){ if (is_word[now]) return false; if (pos == s.size()){ if (is_pre[now]) return false; is_word[now] = true; return true; } is_pre[now] = true; int c = s[pos]-'0'; if (tree[now][c] == -1) tree[now][c] = ++cur; return insert(tree[now][c], s, pos+1); } void solve(){ memset(tree, -1, sizeof tree); memset(is_word, false, sizeof is_word); memset(is_pre, false, sizeof is_pre); root = 1; cur = 1; bool valid = true; cin >> n; lp(i,n){ cin >> s; if (valid) valid &= insert(root, s, 0); //trace2(s, valid); } if (valid) cout << "YES" << endl; else cout << "NO" << endl; } signed main(){ ios; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int t; cin >> t; //t = 1; while(t--) solve(); return 0; }
72243e182d7b82471ff741a092c3e68f9f898eb1
dab0cb3770232ddb0104fc5d00fc8fd7b14e69e5
/LSTMLayer/LSTMNeuroNetworkError.h
969d2d2ff8984695a3c82a977be9336de95382e9
[]
no_license
yfz912/LSTM_Layer
f8adbd65c538535a1cd9e3fe9fda5ec80bc1a578
92dba78f88aaae694bb12029f45fb88f5194b052
refs/heads/master
2020-04-28T01:46:39.739104
2017-04-06T05:59:21
2017-04-06T05:59:21
null
0
0
null
null
null
null
UTF-8
C++
false
false
431
h
LSTMNeuroNetworkError.h
#pragma once #include "NeuroNetworkError.h" class LSTMNeuroNetworkError : public NeuroNetworkError { public: MatrixD cError; LSTMNeuroNetworkError( const MatrixD &inputError ) :NeuroNetworkError( inputError ) { cError = MatrixD( inputError.Rows() , inputError.Columns(), 0.0 ); } LSTMNeuroNetworkError( const MatrixD &inputError , const MatrixD &cellError ) : NeuroNetworkError(inputError) { cError = cellError; } };
85562ef25492b7af20af19b0fef628b627c7663d
01bcef56ade123623725ca78d233ac8653a91ece
/materialsystem/stdshaders/lightmapped_4wayblend_dx9_helper.cpp
39e46b2800dbc329e8943ddb5bfe9255ded22dce
[ "LicenseRef-scancode-public-domain", "LicenseRef-scancode-unknown-license-reference" ]
permissive
SwagSoftware/Kisak-Strike
1085ba3c6003e622dac5ebc0c9424cb16ef58467
4c2fdc31432b4f5b911546c8c0d499a9cff68a85
refs/heads/master
2023-09-01T02:06:59.187775
2022-09-05T00:51:46
2022-09-05T00:51:46
266,676,410
921
123
null
2022-10-01T16:26:41
2020-05-25T03:41:35
C++
UTF-8
C++
false
false
51,046
cpp
lightmapped_4wayblend_dx9_helper.cpp
//========= Copyright (c) 1996-2014, Valve LLC, All rights reserved. ============ // // Purpose: Lightmapped_4WayBlend shader // // $Header: $ // $NoKeywords: $ //============================================================================= #include "lightmapped_4wayblend_dx9_helper.h" #include "BaseVSShader.h" #include "shaderlib/commandbuilder.h" #include "convar.h" #include "lightmapped_4wayblend_vs20.inc" #include "lightmapped_4wayblend_ps20b.inc" #if !defined( _X360 ) && !defined( _PS3 ) #include "lightmapped_4wayblend_vs30.inc" #include "lightmapped_4wayblend_ps30.inc" #endif #include "shaderapifast.h" #include "tier0/vprof.h" #include "tier0/memdbgon.h" extern ConVar mat_ambient_light_r; extern ConVar mat_ambient_light_g; extern ConVar mat_ambient_light_b; #if defined( CSTRIKE15 ) && defined( _X360 ) static ConVar r_shader_srgbread( "r_shader_srgbread", "1", 0, "1 = use shader srgb texture reads, 0 = use HW" ); #else static ConVar r_shader_srgbread( "r_shader_srgbread", "0", 0, "1 = use shader srgb texture reads, 0 = use HW" ); #endif static ConVar mat_force_vertexfog( "mat_force_vertexfog", "0", FCVAR_DEVELOPMENTONLY ); void InitParamsLightmapped_4WayBlend_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, Lightmapped_4WayBlend_DX9_Vars_t &info ) { // A little strange, but we do support "skinning" in that we can do // fast-path instance rendering with lightmapped generic, and this // tells the system to insert the PI command buffer to set the per-instance matrix. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); // Override vertex fog via the global setting if it isn't enabled/disabled in the material file. if ( !IS_FLAG_DEFINED( MATERIAL_VAR_VERTEXFOG ) && mat_force_vertexfog.GetBool() ) { SET_FLAGS( MATERIAL_VAR_VERTEXFOG ); } params[FLASHLIGHTTEXTURE]->SetStringValue( GetFlashlightTextureFilename() ); if( pShader->IsUsingGraphics() && params[info.m_nEnvmap]->IsDefined() && !pShader->CanUseEditorMaterials() ) { if( stricmp( params[info.m_nEnvmap]->GetStringValue(), "env_cubemap" ) == 0 ) { Warning( "env_cubemap used on world geometry without rebuilding map. . ignoring: %s\n", pMaterialName ); params[info.m_nEnvmap]->SetUndefined(); } } if( !params[info.m_nEnvmapTint]->IsDefined() ) params[info.m_nEnvmapTint]->SetVecValue( 1.0f, 1.0f, 1.0f ); if( !params[info.m_nNoDiffuseBumpLighting]->IsDefined() ) params[info.m_nNoDiffuseBumpLighting]->SetIntValue( 0 ); if( !params[info.m_nSelfIllumTint]->IsDefined() ) params[info.m_nSelfIllumTint]->SetVecValue( 1.0f, 1.0f, 1.0f ); if( !params[info.m_nDetailScale]->IsDefined() ) params[info.m_nDetailScale]->SetFloatValue( 4.0f ); if ( !params[info.m_nDetailTint]->IsDefined() ) params[info.m_nDetailTint]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f ); InitFloatParam( info.m_nDetailTextureBlendFactor, params, 1.0 ); InitFloatParam( info.m_nDetailTextureBlendFactor2, params, 1.0 ); InitFloatParam( info.m_nDetailTextureBlendFactor3, params, 1.0 ); InitFloatParam( info.m_nDetailTextureBlendFactor4, params, 1.0 ); InitIntParam( info.m_nDetailTextureCombineMode, params, 0 ); InitFloatParam( info.m_nTexture2uvScale, params, 1.0f ); InitFloatParam( info.m_nTexture3uvScale, params, 1.0f ); InitFloatParam( info.m_nTexture4uvScale, params, 1.0f ); InitFloatParam( info.m_nTexture2BlendStart, params, 0.0f ); InitFloatParam( info.m_nTexture3BlendStart, params, 0.0f ); InitFloatParam( info.m_nTexture4BlendStart, params, 0.0f ); InitFloatParam( info.m_nTexture2BlendEnd, params, 1.0f ); InitFloatParam( info.m_nTexture3BlendEnd, params, 1.0f ); InitFloatParam( info.m_nTexture4BlendEnd, params, 1.0f ); InitFloatParam( info.m_nTexture1LumStart, params, 0.0f ); InitFloatParam( info.m_nTexture2LumStart, params, 0.0f ); InitFloatParam( info.m_nTexture3LumStart, params, 0.0f ); InitFloatParam( info.m_nTexture4LumStart, params, 0.0f ); InitFloatParam( info.m_nTexture1LumEnd, params, 1.0f ); InitFloatParam( info.m_nTexture2LumEnd, params, 1.0f ); InitFloatParam( info.m_nTexture3LumEnd, params, 1.0f ); InitFloatParam( info.m_nTexture4LumEnd, params, 1.0f ); InitFloatParam( info.m_nTexture2BumpBlendFactor, params, 1.0f ); InitFloatParam( info.m_nTexture3BumpBlendFactor, params, 1.0f ); InitFloatParam( info.m_nTexture4BumpBlendFactor, params, 1.0f ); InitFloatParam( info.m_nLumBlendFactor2, params, 1.0f ); InitFloatParam( info.m_nLumBlendFactor3, params, 1.0f ); InitFloatParam( info.m_nLumBlendFactor4, params, 1.0f ); if( !params[info.m_nFresnelReflection]->IsDefined() ) params[info.m_nFresnelReflection]->SetFloatValue( 1.0f ); if( !params[info.m_nEnvmapMaskFrame]->IsDefined() ) params[info.m_nEnvmapMaskFrame]->SetIntValue( 0 ); if( !params[info.m_nEnvmapFrame]->IsDefined() ) params[info.m_nEnvmapFrame]->SetIntValue( 0 ); if( !params[info.m_nBumpFrame]->IsDefined() ) params[info.m_nBumpFrame]->SetIntValue( 0 ); if( !params[info.m_nDetailFrame]->IsDefined() ) params[info.m_nDetailFrame]->SetIntValue( 0 ); if( !params[info.m_nEnvmapContrast]->IsDefined() ) params[info.m_nEnvmapContrast]->SetFloatValue( 0.0f ); if( !params[info.m_nEnvmapSaturation]->IsDefined() ) params[info.m_nEnvmapSaturation]->SetFloatValue( 1.0f ); if ( ( info.m_nEnvmapAnisotropyScale != -1 ) && !params[info.m_nEnvmapAnisotropyScale]->IsDefined() ) params[info.m_nEnvmapAnisotropyScale]->SetFloatValue( 1.0f ); if ( ( info.m_nEnvMapLightScaleMinMax != -1 ) && !params[info.m_nEnvMapLightScaleMinMax]->IsDefined() ) params[info.m_nEnvMapLightScaleMinMax]->SetVecValue( 0.0, 1.0 ); InitFloatParam( info.m_nAlphaTestReference, params, 0.0f ); // No texture means no self-illum or env mask in base alpha if ( !params[info.m_nBaseTexture]->IsDefined() ) { CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); } if( params[info.m_nBumpmap]->IsDefined() ) { params[info.m_nEnvmapMask]->SetUndefined(); } // If in decal mode, no debug override... if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) { SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); } if ( !params[info.m_nForceBumpEnable]->IsDefined() ) { params[info.m_nForceBumpEnable]->SetIntValue( 0 ); } SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); bool bShouldUseBump = g_pConfig->UseBumpmapping() || !!params[info.m_nForceBumpEnable]->GetIntValue(); if( bShouldUseBump && params[info.m_nBumpmap]->IsDefined() && (params[info.m_nNoDiffuseBumpLighting]->GetIntValue() == 0) ) { SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP ); } // If mat_specular 0, then get rid of envmap if( !g_pConfig->UseSpecular() && params[info.m_nEnvmap]->IsDefined() && params[info.m_nBaseTexture]->IsDefined() ) { params[info.m_nEnvmap]->SetUndefined(); } if( ( info.m_nSelfShadowedBumpFlag != -1 ) && ( !params[info.m_nSelfShadowedBumpFlag]->IsDefined() ) ) { params[info.m_nSelfShadowedBumpFlag]->SetIntValue( 0 ); } // srgb read 360 #if defined( CSTRIKE15 ) InitIntParam( info.m_nShaderSrgbRead360, params, 1 ); #else InitIntParam( info.m_nShaderSrgbRead360, params, 0 ); #endif InitFloatParam( info.m_nEnvMapLightScale, params, 0.0f ); } void InitLightmapped_4WayBlend_DX9( CBaseVSShader *pShader, IMaterialVar** params, Lightmapped_4WayBlend_DX9_Vars_t &info ) { bool bShouldUseBump = g_pConfig->UseBumpmapping() || !!params[info.m_nForceBumpEnable]->GetIntValue(); if ( bShouldUseBump && params[info.m_nBumpmap]->IsDefined() ) { pShader->LoadBumpMap( info.m_nBumpmap, ANISOTROPIC_OVERRIDE ); } if ( bShouldUseBump && params[info.m_nBumpmap2]->IsDefined() ) { pShader->LoadBumpMap( info.m_nBumpmap2, ANISOTROPIC_OVERRIDE ); } if (params[info.m_nBaseTexture]->IsDefined()) { pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB | ANISOTROPIC_OVERRIDE ); if (!params[info.m_nBaseTexture]->GetTextureValue()->IsTranslucent()) { CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); } } if ( params[info.m_nBaseTexture2]->IsDefined() ) { pShader->LoadTexture( info.m_nBaseTexture2, TEXTUREFLAGS_SRGB | ANISOTROPIC_OVERRIDE ); } if ( params[info.m_nBaseTexture3]->IsDefined() ) { pShader->LoadTexture( info.m_nBaseTexture3, TEXTUREFLAGS_SRGB | ANISOTROPIC_OVERRIDE ); } if ( params[info.m_nBaseTexture4]->IsDefined() ) { pShader->LoadTexture( info.m_nBaseTexture4, TEXTUREFLAGS_SRGB | ANISOTROPIC_OVERRIDE ); } if (params[info.m_nDetail]->IsDefined()) { int nDetailBlendMode = ( info.m_nDetailTextureCombineMode == -1 ) ? 0 : params[info.m_nDetailTextureCombineMode]->GetIntValue(); if ( nDetailBlendMode != DETAIL_BLEND_MODE_RGB_EQUALS_BASE_x_DETAILx2 && nDetailBlendMode != DETAIL_BLEND_MODE_MOD2X_SELECT_TWO_PATTERNS && nDetailBlendMode != DETAIL_BLEND_MODE_NONE ) { Msg( "Invalid DetailBlendMode in %s, %d not supported!", pShader->GetName(), nDetailBlendMode ); } if ( nDetailBlendMode != DETAIL_BLEND_MODE_NONE ) { pShader->LoadTexture( info.m_nDetail, IsSRGBDetailTexture( nDetailBlendMode ) ? TEXTUREFLAGS_SRGB : 0 ); } } pShader->LoadTexture( info.m_nFlashlightTexture, TEXTUREFLAGS_SRGB ); // Don't alpha test if the alpha channel is used for other purposes if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) { CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); } if ( g_pConfig->UseSpecular() ) { if ( params[info.m_nEnvmap]->IsDefined() ) { pShader->LoadCubeMap( info.m_nEnvmap, ( g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ? TEXTUREFLAGS_SRGB : 0 ) | ANISOTROPIC_OVERRIDE ); if (params[info.m_nEnvmapMask]->IsDefined()) { pShader->LoadTexture( info.m_nEnvmapMask ); } } else { params[info.m_nEnvmapMask]->SetUndefined(); } } else { params[info.m_nEnvmap]->SetUndefined(); params[info.m_nEnvmapMask]->SetUndefined(); } // We always need this because of the flashlight. SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); } void DrawLightmapped_4WayBlend_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, Lightmapped_4WayBlend_DX9_Vars_t &info, CBasePerMaterialContextData **pContextDataPtr ) { bool bSinglePassFlashlight = true; bool hasFlashlight = pShader->UsingFlashlight( params ); CLightmapped_4WayBlend_DX9_Context *pContextData = reinterpret_cast< CLightmapped_4WayBlend_DX9_Context *> ( *pContextDataPtr ); #if defined( CSTRIKE15 ) bool bShaderSrgbRead = IsX360() && r_shader_srgbread.GetBool(); #else bool bShaderSrgbRead = ( IsX360() && IS_PARAM_DEFINED( info.m_nShaderSrgbRead360 ) && params[info.m_nShaderSrgbRead360]->GetIntValue() ); #endif bool bHDR = g_pHardwareConfig->GetHDRType() != HDR_TYPE_NONE; int nDetailBlendMode = GetIntParam( info.m_nDetailTextureCombineMode, params ); if ( pShaderShadow || ( ! pContextData ) || pContextData->m_bMaterialVarsChanged || ( hasFlashlight && !( IsX360() || IsPS3() ) ) ) { bool hasBaseTexture = params[info.m_nBaseTexture]->IsTexture(); int nAlphaChannelTextureVar = hasBaseTexture ? (int)info.m_nBaseTexture : (int)info.m_nEnvmapMask; BlendType_t nBlendType = pShader->EvaluateBlendRequirements( nAlphaChannelTextureVar, hasBaseTexture ); bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0; bool bFullyOpaqueWithoutAlphaTest = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && (!hasFlashlight || IsX360() || IsPS3()); //dest alpha is free for special use bool bFullyOpaque = bFullyOpaqueWithoutAlphaTest && !bIsAlphaTested; bool bNeedRegenStaticCmds = (! pContextData ) || pShaderShadow; if ( ! pContextData ) // make sure allocated { pContextData = new CLightmapped_4WayBlend_DX9_Context; *pContextDataPtr = pContextData; } bool shouldUseBump = g_pConfig->UseBumpmapping() || !!params[info.m_nForceBumpEnable]->GetIntValue(); bool hasBump = ( params[info.m_nBumpmap]->IsTexture() ) && shouldUseBump; bool hasSSBump = hasBump && (info.m_nSelfShadowedBumpFlag != -1) && ( params[info.m_nSelfShadowedBumpFlag]->GetIntValue() ); bool hasBump2 = hasBump && params[info.m_nBumpmap2]->IsTexture(); bool hasDetailTexture = params[info.m_nDetail]->IsTexture() && g_pConfig->UseDetailTexturing() && ( nDetailBlendMode != DETAIL_BLEND_MODE_NONE ); bool hasSelfIllum = IS_FLAG_SET( MATERIAL_VAR_SELFILLUM ); if ( hasFlashlight && !( IsX360() || IsPS3() ) ) { // !!speed!! do this in the caller so we don't build struct every time CBaseVSShader::DrawFlashlight_dx90_Vars_t vars; vars.m_bBump = hasBump; vars.m_nBumpmapVar = info.m_nBumpmap; vars.m_nBumpmapFrame = info.m_nBumpFrame; vars.m_nBumpTransform = info.m_nBumpTransform; vars.m_nFlashlightTextureVar = info.m_nFlashlightTexture; vars.m_nFlashlightTextureFrameVar = info.m_nFlashlightTextureFrame; vars.m_bLightmappedGeneric = true; vars.m_bWorldVertexTransition = true; vars.m_nBaseTexture2Var = info.m_nBaseTexture2; vars.m_nBaseTexture2FrameVar = info.m_nBaseTexture2Frame; vars.m_nBumpmapVar2 = info.m_nBumpmap2; vars.m_nBumpmapFrame2 = info.m_nBumpFrame2; vars.m_nBumpTransform2 = info.m_nBumpTransform2; vars.m_nAlphaTestReference = info.m_nAlphaTestReference; vars.m_bSSBump = hasSSBump; vars.m_nDetailVar = info.m_nDetail; vars.m_nDetailScale = info.m_nDetailScale; vars.m_nDetailTextureCombineMode = info.m_nDetailTextureCombineMode; vars.m_nDetailTextureBlendFactor = info.m_nDetailTextureBlendFactor; vars.m_nDetailTint = info.m_nDetailTint; if ( ( info.m_nSeamlessMappingScale != -1 ) ) vars.m_fSeamlessScale = params[info.m_nSeamlessMappingScale]->GetFloatValue(); else vars.m_fSeamlessScale = 0.0; pShader->DrawFlashlight_dx90( params, pShaderAPI, pShaderShadow, vars ); return; } pContextData->m_bFullyOpaque = bFullyOpaque; pContextData->m_bFullyOpaqueWithoutAlphaTest = bFullyOpaqueWithoutAlphaTest; bool hasEnvmapMask = params[info.m_nEnvmapMask]->IsTexture(); bool bEnvmapAnisotropy = hasBump && !hasSSBump && ( info.m_nEnvmapAnisotropy != -1 ) && ( params[info.m_nEnvmapAnisotropy]->GetIntValue() == 1 ); if ( pShaderShadow || bNeedRegenStaticCmds ) { bool hasVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ); bool hasEnvmap = params[info.m_nEnvmap]->IsTexture(); bEnvmapAnisotropy = bEnvmapAnisotropy && hasEnvmap; int envmap_variant; //0 = no envmap, 1 = regular, 2 = darken in shadow mode if( hasEnvmap ) { //only enabled darkened cubemap mode when the scale calls for it. And not supported in ps20 when also using a 2nd bumpmap envmap_variant = ((GetFloatParam( info.m_nEnvMapLightScale, params ) > 0.0f) && (g_pHardwareConfig->SupportsPixelShaders_2_b() || !hasBump2)) ? 2 : 1; } else { envmap_variant = 0; } if ( hasDetailTexture ) { ITexture *pDetailTexture = params[info.m_nDetail]->GetTextureValue(); if ( pDetailTexture->GetFlags() & TEXTUREFLAGS_SSBUMP ) { if ( hasBump ) nDetailBlendMode = DETAIL_BLEND_MODE_SSBUMP_BUMP; else nDetailBlendMode = DETAIL_BLEND_MODE_SSBUMP_NOBUMP; } } bool bSeamlessMapping = ( ( info.m_nSeamlessMappingScale != -1 ) && ( params[info.m_nSeamlessMappingScale]->GetFloatValue() != 0.0 ) ); if ( bNeedRegenStaticCmds ) { pContextData->ResetStaticCmds(); CCommandBufferBuilder< CFixedCommandStorageBuffer< 5000 > > staticCmdsBuf; int nLightingPreviewMode = IS_FLAG2_SET( MATERIAL_VAR2_USE_GBUFFER0 ) + 2 * IS_FLAG2_SET( MATERIAL_VAR2_USE_GBUFFER1 ); if ( ( nLightingPreviewMode == ENABLE_FIXED_LIGHTING_OUTPUTNORMAL_AND_DEPTH ) && IsPC() ) { staticCmdsBuf.SetVertexShaderNearAndFarZ( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6 ); // Needed for SSAO } if( !hasBaseTexture ) { if( hasEnvmap ) { // if we only have an envmap (no basetexture), then we want the albedo to be black. staticCmdsBuf.BindStandardTexture( SHADER_SAMPLER0, SRGBReadMask( !bShaderSrgbRead ), TEXTURE_BLACK ); } else { staticCmdsBuf.BindStandardTexture( SHADER_SAMPLER0, SRGBReadMask( !bShaderSrgbRead ), TEXTURE_WHITE ); } } // mariod - are lightmaps ever srgb? staticCmdsBuf.BindStandardTexture( SHADER_SAMPLER1, bHDR ? TEXTURE_BINDFLAGS_NONE : TEXTURE_BINDFLAGS_SRGBREAD, TEXTURE_LIGHTMAP ); if ( bSeamlessMapping ) { staticCmdsBuf.SetVertexShaderConstant4( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, params[info.m_nSeamlessMappingScale]->GetFloatValue(),0,0,0 ); } staticCmdsBuf.StoreEyePosInPixelShaderConstant( 10 ); #ifndef _PS3 staticCmdsBuf.SetPixelShaderFogParams( 11 ); #endif staticCmdsBuf.End(); // now, copy buf pContextData->m_pStaticCmds = new uint8[staticCmdsBuf.Size()]; memcpy( pContextData->m_pStaticCmds, staticCmdsBuf.Base(), staticCmdsBuf.Size() ); } if ( pShaderShadow ) { // Alpha test: FIXME: shouldn't this be handled in Shader_t::SetInitialShadowState pShaderShadow->EnableAlphaTest( bIsAlphaTested ); if ( info.m_nAlphaTestReference != -1 && params[info.m_nAlphaTestReference]->GetFloatValue() > 0.0f ) { pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[info.m_nAlphaTestReference]->GetFloatValue() ); } pShader->SetDefaultBlendingShadowState( nAlphaChannelTextureVar, hasBaseTexture ); unsigned int flags = VERTEX_POSITION; if( hasEnvmap || ( ( IsX360() || IsPS3() ) && hasFlashlight ) ) { flags |= VERTEX_TANGENT_S | VERTEX_TANGENT_T | VERTEX_NORMAL; } if ( hasDetailTexture ) { ITexture *pDetailTexture = params[info.m_nDetail]->GetTextureValue(); if ( pDetailTexture->GetFlags() & TEXTUREFLAGS_SSBUMP ) { if ( hasBump ) nDetailBlendMode = DETAIL_BLEND_MODE_SSBUMP_BUMP; else nDetailBlendMode = DETAIL_BLEND_MODE_SSBUMP_NOBUMP; } pShaderShadow->EnableTexture( SHADER_SAMPLER12, true ); pShaderShadow->EnableSRGBRead( SHADER_SAMPLER12, IsSRGBDetailTexture( nDetailBlendMode ) ); } if( hasFlashlight && ( IsX360() || IsPS3() ) ) { //pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER14 ); } if( hasVertexColor || hasBump2 ) { flags |= VERTEX_COLOR; } flags |= VERTEX_SPECULAR; // texcoord0 : base texcoord // texcoord1 : lightmap texcoord // texcoord2 : lightmap texcoord offset int numTexCoords; // if ( ShaderApiFast( pShaderAPI )->InEditorMode() ) // if ( pShader->CanUseEditorMaterials() ) // { // numTexCoords = 1; // } // else { numTexCoords = 2; if( hasBump ) { numTexCoords = 3; } } int nTexture3BlendMode = GetIntParam( info.m_nTexture3BlendMode, params ); int nTexture4BlendMode = GetIntParam( info.m_nTexture4BlendMode, params ); int nLightingPreviewMode = IS_FLAG2_SET( MATERIAL_VAR2_USE_GBUFFER0 ) + 2 * IS_FLAG2_SET( MATERIAL_VAR2_USE_GBUFFER1 ); pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 ); // Pre-cache pixel shaders bool hasBaseAlphaEnvmapMask = IS_FLAG_SET( MATERIAL_VAR_BASEALPHAENVMAPMASK ); int bumpmap_variant=(hasSSBump) ? 2 : hasBump; bool bCSMBlending = g_pHardwareConfig->GetCSMAccurateBlending(); #if !defined( _X360 ) && !defined( _PS3 ) if ( !g_pHardwareConfig->SupportsPixelShaders_3_0() ) #endif { DECLARE_STATIC_VERTEX_SHADER( lightmapped_4wayblend_vs20 ); SET_STATIC_VERTEX_SHADER_COMBO( ENVMAP_MASK, hasEnvmapMask ); SET_STATIC_VERTEX_SHADER_COMBO( TANGENTSPACE, params[info.m_nEnvmap]->IsTexture() ); SET_STATIC_VERTEX_SHADER_COMBO( BUMPMAP, hasBump ); SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ) ); SET_STATIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, nLightingPreviewMode ); SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); SET_STATIC_VERTEX_SHADER_COMBO( DETAILTEXTURE, hasDetailTexture ); SET_STATIC_VERTEX_SHADER_COMBO( SELFILLUM, hasSelfIllum ); #if defined( _X360 ) || defined( _PS3 ) SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, hasFlashlight); #endif SET_STATIC_VERTEX_SHADER( lightmapped_4wayblend_vs20 ); DECLARE_STATIC_PIXEL_SHADER( lightmapped_4wayblend_ps20b ); SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, bumpmap_variant ); SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP2, hasBump2 ); SET_STATIC_PIXEL_SHADER_COMBO( TEXTURE3_BLENDMODE, nTexture3BlendMode ); SET_STATIC_PIXEL_SHADER_COMBO( TEXTURE4_BLENDMODE, nTexture4BlendMode ); SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, envmap_variant ); SET_STATIC_PIXEL_SHADER_COMBO( ENVMAPMASK, hasEnvmapMask ); SET_STATIC_PIXEL_SHADER_COMBO( BASEALPHAENVMAPMASK, hasBaseAlphaEnvmapMask ); SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, hasSelfIllum ); SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_BLEND_MODE, nDetailBlendMode ); SET_STATIC_PIXEL_SHADER_COMBO( ENVMAPANISOTROPY, bEnvmapAnisotropy ); #if defined( _X360 ) || defined( _PS3 ) SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight); #endif SET_STATIC_PIXEL_SHADER_COMBO( SHADER_SRGB_READ, bShaderSrgbRead ); SET_STATIC_PIXEL_SHADER_COMBO( LIGHTING_PREVIEW, nLightingPreviewMode ); SET_STATIC_PIXEL_SHADER_COMBO( CSM_BLENDING, bCSMBlending ); SET_STATIC_PIXEL_SHADER( lightmapped_4wayblend_ps20b ); } #if !defined( _X360 ) && !defined( _PS3 ) else // Shader model 3.0, PC only { int nCSMQualityComboValue = g_pHardwareConfig->GetCSMShaderMode( materials->GetCurrentConfigForVideoCard().GetCSMQualityMode() ); DECLARE_STATIC_VERTEX_SHADER( lightmapped_4wayblend_vs30 ); SET_STATIC_VERTEX_SHADER_COMBO( ENVMAP_MASK, hasEnvmapMask ); SET_STATIC_VERTEX_SHADER_COMBO( TANGENTSPACE, params[info.m_nEnvmap]->IsTexture() ); SET_STATIC_VERTEX_SHADER_COMBO( BUMPMAP, hasBump ); SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ) ); SET_STATIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, nLightingPreviewMode ); SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); SET_STATIC_VERTEX_SHADER_COMBO( DETAILTEXTURE, hasDetailTexture ); SET_STATIC_VERTEX_SHADER_COMBO( SELFILLUM, hasSelfIllum ); SET_STATIC_VERTEX_SHADER( lightmapped_4wayblend_vs30 ); DECLARE_STATIC_PIXEL_SHADER( lightmapped_4wayblend_ps30 ); SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, bumpmap_variant ); SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP2, hasBump2 ); SET_STATIC_PIXEL_SHADER_COMBO( TEXTURE3_BLENDMODE, nTexture3BlendMode ); SET_STATIC_PIXEL_SHADER_COMBO( TEXTURE4_BLENDMODE, nTexture4BlendMode ); SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, envmap_variant ); SET_STATIC_PIXEL_SHADER_COMBO( ENVMAPMASK, hasEnvmapMask ); SET_STATIC_PIXEL_SHADER_COMBO( BASEALPHAENVMAPMASK, hasBaseAlphaEnvmapMask ); SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, hasSelfIllum ); SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_BLEND_MODE, nDetailBlendMode ); SET_STATIC_PIXEL_SHADER_COMBO( ENVMAPANISOTROPY, bEnvmapAnisotropy ); SET_STATIC_PIXEL_SHADER_COMBO( SHADER_SRGB_READ, bShaderSrgbRead ); SET_STATIC_PIXEL_SHADER_COMBO( LIGHTING_PREVIEW, nLightingPreviewMode ); SET_STATIC_PIXEL_SHADER_COMBO( CSM_MODE, ( g_pHardwareConfig->SupportsCascadedShadowMapping() && !ToolsEnabled() ) ? nCSMQualityComboValue : 0 ); SET_STATIC_PIXEL_SHADER_COMBO( CSM_BLENDING, bCSMBlending ); SET_STATIC_PIXEL_SHADER( lightmapped_4wayblend_ps30 ); } #endif // HACK HACK HACK - enable alpha writes all the time so that we have them for // underwater stuff and writing depth to dest alpha // But only do it if we're not using the alpha already for translucency pShaderShadow->EnableAlphaWrites( bFullyOpaque ); pShaderShadow->EnableSRGBWrite( true ); pShader->DefaultFog(); // NOTE: This isn't optimal. If $color2 is ever changed by a material // proxy, this code won't get re-run, but too bad. No time to make this work // Also note that if the lightmap scale factor changes // all shadow state blocks will be re-run, so that's ok float flLScale = pShaderShadow->GetLightMapScaleFactor(); pShader->PI_BeginCommandBuffer(); if ( g_pHardwareConfig->SupportsPixelShaders_3_0() ) { pShader->PI_SetModulationPixelShaderDynamicState( 21 ); } // MAINTOL4DMERGEFIXME // Need to reflect this change which is from this rel changelist since this constant set was moved from the dynamic block to here: // Change 578692 by Alex@alexv_rel on 2008/06/04 18:07:31 // // Fix for portalareawindows in ep2 being rendered black. The color variable was being multipurposed for both the vs and ps differently where the ps doesn't care about alpha, but the vs does. Only applying the alpha2 DoD hack to the pixel shader constant where the alpha was never used in the first place and leaving alpha as is for the vs. // color[3] *= ( IS_PARAM_DEFINED( info.m_nAlpha2 ) && params[ info.m_nAlpha2 ]->GetFloatValue() > 0.0f ) ? params[ info.m_nAlpha2 ]->GetFloatValue() : 1.0f; // pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 12, color ); pShader->PI_SetModulationPixelShaderDynamicState_LinearScale_ScaleInW( 12, flLScale ); pShader->PI_SetModulationVertexShaderDynamicState_LinearScale( flLScale ); pShader->PI_EndCommandBuffer(); } // end shadow state } // end shadow || regen display list if ( pShaderAPI && ( pContextData->m_bMaterialVarsChanged ) ) { // need to regenerate the semistatic cmds pContextData->m_SemiStaticCmdsOut.Reset(); #ifdef _PS3 pContextData->m_flashlightECB.Reset(); #endif pContextData->m_bMaterialVarsChanged = false; // If we don't have a texture transform, we don't have // to set vertex shader constants or run vertex shader instructions // for the texture transform. bool bHasTextureTransform = !( params[info.m_nBaseTextureTransform]->MatrixIsIdentity() && params[info.m_nBumpTransform]->MatrixIsIdentity() && params[info.m_nBumpTransform2]->MatrixIsIdentity() && params[info.m_nEnvmapMaskTransform]->MatrixIsIdentity() ); pContextData->m_bVertexShaderFastPath = !bHasTextureTransform; if( params[info.m_nDetail]->IsTexture() ) { pContextData->m_bVertexShaderFastPath = false; } int nTransformToLoad = -1; if( ( hasBump || hasSSBump ) && hasDetailTexture && !hasSelfIllum ) { nTransformToLoad = info.m_nBumpTransform; } pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_10, nTransformToLoad ); if ( ! pContextData->m_bVertexShaderFastPath ) { bool bSeamlessMapping = ( ( info.m_nSeamlessMappingScale != -1 ) && ( params[info.m_nSeamlessMappingScale]->GetFloatValue() != 0.0 ) ); bool hasEnvmapMask = params[info.m_nEnvmapMask]->IsTexture(); if (!bSeamlessMapping ) pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nBaseTextureTransform ); // If we have a detail texture, then the bump texcoords are the same as the base texcoords. if( hasBump && !hasDetailTexture ) { pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nBumpTransform ); } if( hasEnvmapMask ) { pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, info.m_nEnvmapMaskTransform ); } else if ( hasBump2 ) { pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, info.m_nBumpTransform2 ); } } pContextData->m_SemiStaticCmdsOut.SetEnvMapTintPixelShaderDynamicState( 0, info.m_nEnvmapTint ); float bumpblendfactors[ 3 ]; bumpblendfactors[ 0 ] = clamp( GetFloatParam( info.m_nTexture2BumpBlendFactor, params, 1.0f ), 0.0f, 1.0f ); bumpblendfactors[ 1 ] = clamp( GetFloatParam( info.m_nTexture3BumpBlendFactor, params, 1.0f ), 0.0f, 1.0f ); bumpblendfactors[ 2 ] = clamp( GetFloatParam( info.m_nTexture4BumpBlendFactor, params, 1.0f ), 0.0f, 1.0f ); pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 1, bumpblendfactors ); float ranges[ 4 ]; ranges[ 0 ] = clamp( GetFloatParam( info.m_nTexture1LumStart, params, 0.0f ), 0.0f, 1.0f ); ranges[ 1 ] = clamp( GetFloatParam( info.m_nTexture1LumEnd, params, 1.0f ), 0.0f, 1.0f ); ranges[ 2 ] = clamp( GetFloatParam( info.m_nTexture2LumStart, params, 0.0f ), 0.0f, 1.0f ); ranges[ 3 ] = clamp( GetFloatParam( info.m_nTexture2LumEnd, params, 1.0f ), 0.0f, 1.0f ); pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 5, ranges ); ranges[ 0 ] = clamp( GetFloatParam( info.m_nTexture3LumStart, params, 0.0f ), 0.0f, 1.0f ); ranges[ 1 ] = clamp( GetFloatParam( info.m_nTexture3LumEnd, params, 1.0f ), 0.0f, 1.0f ); ranges[ 2 ] = clamp( GetFloatParam( info.m_nTexture4LumStart, params, 0.0f ), 0.0f, 1.0f ); ranges[ 3 ] = clamp( GetFloatParam( info.m_nTexture4LumEnd, params, 1.0f ), 0.0f, 1.0f ); pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 28, ranges ); if ( hasDetailTexture ) { float detailTint[4] = {1, 1, 1, 1}; if ( info.m_nDetailTint != -1 ) { params[ info.m_nDetailTint ]->GetVecValue( detailTint, 3 ); } pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 8, detailTint ); float fDetailBlendFactors[ 4 ]; fDetailBlendFactors[ 0 ] = clamp( GetFloatParam( info.m_nDetailTextureBlendFactor, params, 1.0 ), 0.0f, 1.0f ); fDetailBlendFactors[ 1 ] = clamp( GetFloatParam( info.m_nDetailTextureBlendFactor2, params, 1.0 ), 0.0f, 1.0f ); fDetailBlendFactors[ 2 ] = clamp( GetFloatParam( info.m_nDetailTextureBlendFactor3, params, 1.0 ), 0.0f, 1.0f ); fDetailBlendFactors[ 3 ] = clamp( GetFloatParam( info.m_nDetailTextureBlendFactor4, params, 1.0 ), 0.0f, 1.0f ); pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 9, fDetailBlendFactors ); } ranges[ 0 ] = clamp( GetFloatParam( info.m_nTexture2BlendStart, params, 0.0f ), 0.0f, 1.0f ); ranges[ 1 ] = clamp( GetFloatParam( info.m_nTexture2BlendEnd, params, 1.0f ), 0.0f, 1.0f ); ranges[ 2 ] = clamp( GetFloatParam( info.m_nTexture3BlendStart, params, 0.0f ), 0.0f, 1.0f ); ranges[ 3 ] = clamp( GetFloatParam( info.m_nTexture3BlendEnd, params, 1.0f ), 0.0f, 1.0f ); pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 15, ranges ); float uvScales[ 4 ] = { 1.0f, 1.0f, 1.0f, 1.0f }; if ( info.m_nTexture2uvScale != -1 ) { params[ info.m_nTexture2uvScale ]->GetVecValue( &uvScales[ 0 ], 2 ); } if ( info.m_nTexture3uvScale != -1 ) { params[ info.m_nTexture3uvScale ]->GetVecValue( &uvScales[ 2 ], 2 ); } pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 16, uvScales ); uvScales[ 0 ] = clamp( GetFloatParam( info.m_nTexture4BlendStart, params, 0.0f ), 0.0f, 1.0f ); uvScales[ 1 ] = clamp( GetFloatParam( info.m_nTexture4BlendEnd, params, 1.0f ), 0.0f, 1.0f ); if ( info.m_nTexture4uvScale != -1 ) { params[ info.m_nTexture4uvScale ]->GetVecValue( &uvScales[ 2 ], 2 ); } else { uvScales[ 2 ] = 1.0f; uvScales[ 3 ] = 1.0f; } pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 17, uvScales ); float lumblends[ 3 ]; lumblends[ 0 ] = clamp( GetFloatParam( info.m_nLumBlendFactor2, params, 1.0f ), 0.0f, 1.0f ); lumblends[ 1 ] = clamp( GetFloatParam( info.m_nLumBlendFactor3, params, 1.0f ), 0.0f, 1.0f ); lumblends[ 2 ] = clamp( GetFloatParam( info.m_nLumBlendFactor4, params, 1.0f ), 0.0f, 1.0f ); pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 18, lumblends ); float envmapTintVal[4]; float selfIllumTintVal[4]; params[info.m_nEnvmapTint]->GetVecValue( envmapTintVal, 3 ); params[info.m_nSelfIllumTint]->GetVecValue( selfIllumTintVal, 3 ); float envmapContrast = params[info.m_nEnvmapContrast]->GetFloatValue(); float envmapSaturation = params[info.m_nEnvmapSaturation]->GetFloatValue(); float fresnelReflection = params[info.m_nFresnelReflection]->GetFloatValue(); bool hasEnvmap = params[info.m_nEnvmap]->IsTexture(); bEnvmapAnisotropy = bEnvmapAnisotropy && hasEnvmap; int envmap_variant; //0 = no envmap, 1 = regular, 2 = darken in shadow mode if( hasEnvmap ) { //only enabled darkened cubemap mode when the scale calls for it. And not supported in ps20 when also using a 2nd bumpmap envmap_variant = ((GetFloatParam( info.m_nEnvMapLightScale, params ) > 0.0f) && (g_pHardwareConfig->SupportsPixelShaders_2_b() || !hasBump2)) ? 2 : 1; } else { envmap_variant = 0; } pContextData->m_bPixelShaderFastPath = true; bool bUsingContrastOrSaturation = hasEnvmap && ( ( (envmapContrast != 0.0f) && (envmapContrast != 1.0f) ) || (envmapSaturation != 1.0f) ); bool bUsingFresnel = hasEnvmap && (fresnelReflection != 1.0f); bool bUsingSelfIllumTint = IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) && (selfIllumTintVal[0] != 1.0f || selfIllumTintVal[1] != 1.0f || selfIllumTintVal[2] != 1.0f); if ( bUsingContrastOrSaturation || bUsingFresnel || bUsingSelfIllumTint || !g_pConfig->bShowSpecular ) { pContextData->m_bPixelShaderFastPath = false; } if( !pContextData->m_bPixelShaderFastPath ) { pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstants( 2, 3 ); pContextData->m_SemiStaticCmdsOut.OutputConstantData( params[info.m_nEnvmapContrast]->GetVecValue() ); pContextData->m_SemiStaticCmdsOut.OutputConstantData( params[info.m_nEnvmapSaturation]->GetVecValue() ); float flFresnel = params[info.m_nFresnelReflection]->GetFloatValue(); // [ 0, 0, 1-R(0), R(0) ] pContextData->m_SemiStaticCmdsOut.OutputConstantData4( 0., 0., 1.0 - flFresnel, flFresnel ); pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 7, params[info.m_nSelfIllumTint]->GetVecValue() ); } // cubemap light scale mapping parms (c20) if ( ( envmap_variant == 2 ) || bEnvmapAnisotropy ) { float envMapParams[4] = { 0, 0, 0, 0 }; if ( bEnvmapAnisotropy ) { envMapParams[0] = GetFloatParam( info.m_nEnvmapAnisotropyScale, params ); } if ( envmap_variant == 2 ) { envMapParams[1] = GetFloatParam( info.m_nEnvMapLightScale, params ); float lightScaleMinMax[2] = { 0.0, 0.0 }; params[info.m_nEnvMapLightScaleMinMax]->GetVecValue( lightScaleMinMax, 2 ); envMapParams[2] = lightScaleMinMax[0]; envMapParams[3] = lightScaleMinMax[1] + lightScaleMinMax[0]; } pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 20, envMapParams ); } // texture binds if( hasBaseTexture ) { pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER0, SRGBReadMask( !bShaderSrgbRead ), info.m_nBaseTexture, info.m_nBaseTextureFrame ); } // always set the transform for detail textures since I'm assuming that you'll // always have a detailscale. if( hasDetailTexture ) { pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nBaseTextureTransform, info.m_nDetailScale ); } pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER7, SRGBReadMask( !bShaderSrgbRead ), info.m_nBaseTexture2, info.m_nBaseTexture2Frame ); pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER8, SRGBReadMask( !bShaderSrgbRead ), info.m_nBaseTexture3, info.m_nBaseTexture3Frame ); pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER11, SRGBReadMask( !bShaderSrgbRead ), info.m_nBaseTexture4, info.m_nBaseTexture4Frame ); if( hasDetailTexture ) { pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER12, SRGBReadMask( IsSRGBDetailTexture( nDetailBlendMode ) && !bShaderSrgbRead ), info.m_nDetail, info.m_nDetailFrame ); } if( hasBump ) { if( !g_pConfig->m_bFastNoBump ) { pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER4, TEXTURE_BINDFLAGS_NONE, info.m_nBumpmap, info.m_nBumpFrame ); } else { if( hasSSBump ) { pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER4, TEXTURE_BINDFLAGS_NONE, TEXTURE_SSBUMP_FLAT ); } else { pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER4, TEXTURE_BINDFLAGS_NONE, TEXTURE_NORMALMAP_FLAT ); } } } if( hasBump2 ) { if( !g_pConfig->m_bFastNoBump ) { pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER5, TEXTURE_BINDFLAGS_NONE, info.m_nBumpmap2, info.m_nBumpFrame2 ); } else { if( hasSSBump ) { pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER5, TEXTURE_BINDFLAGS_NONE, TEXTURE_NORMALMAP_FLAT ); } else { pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER5, TEXTURE_BINDFLAGS_NONE, TEXTURE_SSBUMP_FLAT ); } } } if( hasEnvmapMask ) { pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER5, TEXTURE_BINDFLAGS_NONE, info.m_nEnvmapMask, info.m_nEnvmapMaskFrame ); } // handle mat_fullbright 2 bool bLightingOnly = g_pConfig->nFullbright == 2 && !IS_FLAG_SET( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); if( bLightingOnly ) { // BASE TEXTURE if( hasSelfIllum ) { pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER0, SRGBReadMask( !bShaderSrgbRead ), TEXTURE_GREY_ALPHA_ZERO ); } else { pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER0, SRGBReadMask( !bShaderSrgbRead ), TEXTURE_GREY ); } // BASE TEXTURE 2 pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER7, SRGBReadMask( !bShaderSrgbRead ), TEXTURE_GREY ); pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER8, SRGBReadMask( !bShaderSrgbRead ), TEXTURE_GREY ); pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER11, SRGBReadMask( !bShaderSrgbRead ), TEXTURE_GREY ); // DETAIL TEXTURE if( hasDetailTexture ) { pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER12, TEXTURE_BINDFLAGS_NONE, TEXTURE_GREY ); } // disable color modulation float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; pContextData->m_SemiStaticCmdsOut.SetVertexShaderConstant( VERTEX_SHADER_MODULATION_COLOR, color ); // turn off environment mapping envmapTintVal[0] = 0.0f; envmapTintVal[1] = 0.0f; envmapTintVal[2] = 0.0f; } if ( hasFlashlight && ( IsX360() || IsPS3() ) ) { #ifdef _PS3 { pContextData->m_flashlightECB.SetVertexShaderFlashlightState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6 ); } #endif if( IsX360()) { pContextData->m_SemiStaticCmdsOut.SetVertexShaderFlashlightState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6 ); } CBCmdSetPixelShaderFlashlightState_t state; state.m_LightSampler = SHADER_SAMPLER13; state.m_DepthSampler = SHADER_SAMPLER14; state.m_ShadowNoiseSampler = SHADER_SAMPLER15; state.m_nColorConstant = 28; state.m_nAttenConstant = 13; state.m_nOriginConstant = 14; state.m_nDepthTweakConstant = 19; state.m_nScreenScaleConstant = 31; state.m_nWorldToTextureConstant = -1; state.m_bFlashlightNoLambert = false; state.m_bSinglePassFlashlight = bSinglePassFlashlight; #ifdef _PS3 { pContextData->m_flashlightECB.SetPixelShaderFlashlightState( state ); pContextData->m_flashlightECB.End(); } #else { pContextData->m_SemiStaticCmdsOut.SetPixelShaderFlashlightState( state ); } #endif } pContextData->m_SemiStaticCmdsOut.End(); } } DYNAMIC_STATE { #ifdef _PS3 CCommandBufferBuilder< CDynamicCommandStorageBuffer > DynamicCmdsOut; ShaderApiFast( pShaderAPI )->ExecuteCommandBuffer( pContextData->m_pStaticCmds ); ShaderApiFast( pShaderAPI )->ExecuteCommandBuffer( pContextData->m_SemiStaticCmdsOut.Base() ); if (hasFlashlight) ShaderApiFast( pShaderAPI )->ExecuteCommandBufferPPU( pContextData->m_flashlightECB.Base() ); #else CCommandBufferBuilder< CFixedCommandStorageBuffer< 1000 > > DynamicCmdsOut; DynamicCmdsOut.Call( pContextData->m_pStaticCmds ); DynamicCmdsOut.Call( pContextData->m_SemiStaticCmdsOut.Base() ); #endif bool hasEnvmap = params[info.m_nEnvmap]->IsTexture(); if( hasEnvmap ) { DynamicCmdsOut.BindEnvCubemapTexture( pShader, SHADER_SAMPLER2, bHDR ? TEXTURE_BINDFLAGS_NONE : TEXTURE_BINDFLAGS_SRGBREAD, info.m_nEnvmap, info.m_nEnvmapFrame ); } bool bVertexShaderFastPath = pContextData->m_bVertexShaderFastPath; int nFixedLightingMode = ShaderApiFast( pShaderAPI )->GetIntRenderingParameter( INT_RENDERPARM_ENABLE_FIXED_LIGHTING ); if( nFixedLightingMode != ENABLE_FIXED_LIGHTING_NONE ) { bVertexShaderFastPath = false; } bool bWorldNormal = ( nFixedLightingMode == ENABLE_FIXED_LIGHTING_OUTPUTNORMAL_AND_DEPTH ); if ( bWorldNormal && IsPC() ) { float vEyeDir[4]; ShaderApiFast( pShaderAPI )->GetWorldSpaceCameraDirection( vEyeDir ); float flFarZ = ShaderApiFast( pShaderAPI )->GetFarZ(); vEyeDir[0] /= flFarZ; // Divide by farZ for SSAO algorithm vEyeDir[1] /= flFarZ; vEyeDir[2] /= flFarZ; DynamicCmdsOut.SetVertexShaderConstant4( 12, vEyeDir[0], vEyeDir[1], vEyeDir[2], 1.0f ); } MaterialFogMode_t fogType = ShaderApiFast( pShaderAPI )->GetSceneFogMode(); #if !defined( _X360 ) && !defined( _PS3 ) if ( g_pHardwareConfig->SupportsPixelShaders_3_0() ) { DECLARE_DYNAMIC_VERTEX_SHADER( lightmapped_4wayblend_vs30 ); SET_DYNAMIC_VERTEX_SHADER_COMBO( FASTPATH, bVertexShaderFastPath ); SET_DYNAMIC_VERTEX_SHADER_CMD( DynamicCmdsOut, lightmapped_4wayblend_vs30 ); } else #endif { DECLARE_DYNAMIC_VERTEX_SHADER( lightmapped_4wayblend_vs20 ); SET_DYNAMIC_VERTEX_SHADER_COMBO( FASTPATH, bVertexShaderFastPath ); SET_DYNAMIC_VERTEX_SHADER_CMD( DynamicCmdsOut, lightmapped_4wayblend_vs20 ); } // This block of logic is up here and is so verbose because the compiler on the Mac was previously // optimizing much of this away and allowing out of range values into the logic which ultimately // computes the dynamic index. Please leave this here and don't try to weave it into the dynamic // combo setting macros below. bool bPixelShaderFastPath = false; if ( pContextData->m_bPixelShaderFastPath ) bPixelShaderFastPath = true; bool bFastPath = false; if ( bPixelShaderFastPath ) bFastPath = true; if ( nFixedLightingMode != ENABLE_FIXED_LIGHTING_NONE ) { bPixelShaderFastPath = false; } bool bWriteDepthToAlpha = false; bool bWriteWaterFogToAlpha; if( pContextData->m_bFullyOpaque ) { bWriteDepthToAlpha = ShaderApiFast( pShaderAPI )->ShouldWriteDepthToDestAlpha(); bWriteWaterFogToAlpha = (fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z); AssertMsg( !(bWriteDepthToAlpha && bWriteWaterFogToAlpha), "Can't write two values to alpha at the same time." ); } else { //can't write a special value to dest alpha if we're actually using as-intended alpha bWriteDepthToAlpha = false; bWriteWaterFogToAlpha = false; } bool bFlashlightShadows = false; bool bUberlight = false; if( hasFlashlight && ( IsX360() || IsPS3() ) ) { ShaderApiFast( pShaderAPI )->GetFlashlightShaderInfo( &bFlashlightShadows, &bUberlight ); } else { // only do ambient light when not using flashlight float vAmbientColor[4] = { mat_ambient_light_r.GetFloat(), mat_ambient_light_g.GetFloat(), mat_ambient_light_b.GetFloat(), 0.0f }; if ( g_pConfig->nFullbright == 1 ) { vAmbientColor[0] = vAmbientColor[1] = vAmbientColor[2] = 0.0f; } DynamicCmdsOut.SetPixelShaderConstant( 31, vAmbientColor, 1 ); } /* Time - used for debugging float vTimeConst[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; float flTime = pShaderAPI->CurrentTime(); vTimeConst[0] = flTime; DynamicCmdsOut.SetPixelShaderConstant( 27, vTimeConst, 1 ); //*/ float envmapContrast = params[info.m_nEnvmapContrast]->GetFloatValue(); #if !defined( _X360 ) && !defined( _PS3 ) if ( g_pHardwareConfig->SupportsPixelShaders_3_0() ) { BOOL bCSMEnabled = pShaderAPI->IsCascadedShadowMapping() && !ToolsEnabled(); if ( bCSMEnabled ) { ITexture *pDepthTextureAtlas = NULL; const CascadedShadowMappingState_t &cascadeState = pShaderAPI->GetCascadedShadowMappingState( &pDepthTextureAtlas, true ); DynamicCmdsOut.BindTexture( pShader, SHADER_SAMPLER15, TEXTURE_BINDFLAGS_SHADOWDEPTH, pDepthTextureAtlas, 0 ); DynamicCmdsOut.SetPixelShaderConstant( 64, &cascadeState.m_vLightColor.x, CASCADED_SHADOW_MAPPING_CONSTANT_BUFFER_SIZE ); } pShaderAPI->SetBooleanPixelShaderConstant( 0, &bCSMEnabled, 1 ); DECLARE_DYNAMIC_PIXEL_SHADER( lightmapped_4wayblend_ps30 ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FASTPATH, bFastPath ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FASTPATHENVMAPCONTRAST, bPixelShaderFastPath && envmapContrast == 1.0f ); // Don't write fog to alpha if we're using translucency SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha ); SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); SET_DYNAMIC_PIXEL_SHADER_CMD( DynamicCmdsOut, lightmapped_4wayblend_ps30 ); } else #endif { if ( IsGameConsole() && pShaderAPI->IsCascadedShadowMapping() ) { ITexture *pDepthTextureAtlas = NULL; const CascadedShadowMappingState_t &cascadeState = pShaderAPI->GetCascadedShadowMappingState( &pDepthTextureAtlas, true ); if ( pDepthTextureAtlas ) { DynamicCmdsOut.BindTexture( pShader, SHADER_SAMPLER15, TEXTURE_BINDFLAGS_SHADOWDEPTH, pDepthTextureAtlas, 0 ); DynamicCmdsOut.SetPixelShaderConstant( 64, &cascadeState.m_vLightColor.x, CASCADED_SHADOW_MAPPING_CONSTANT_BUFFER_SIZE ); DynamicCmdsOut.SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_13, &cascadeState.m_vLightDir.x, 1 ); } } DECLARE_DYNAMIC_PIXEL_SHADER( lightmapped_4wayblend_ps20b ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FASTPATH, bFastPath ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FASTPATHENVMAPCONTRAST, bPixelShaderFastPath && envmapContrast == 1.0f ); // Don't write fog to alpha if we're using translucency SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha ); SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); SET_DYNAMIC_PIXEL_SHADER_CMD( DynamicCmdsOut, lightmapped_4wayblend_ps20b ); } DynamicCmdsOut.End(); #ifdef _PS3 ShaderApiFast( pShaderAPI )->SetPixelShaderFogParams( 11 ); #endif ShaderApiFast( pShaderAPI )->ExecuteCommandBuffer( DynamicCmdsOut.Base() ); } pShader->Draw(); if( IsPC() && (IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0) && pContextData->m_bFullyOpaqueWithoutAlphaTest ) { //Alpha testing makes it so we can't write to dest alpha //Writing to depth makes it so later polygons can't write to dest alpha either //This leads to situations with garbage in dest alpha. //Fix it now by converting depth to dest alpha for any pixels that just wrote. pShader->DrawEqualDepthToDestAlpha(); } } void DrawLightmapped_4WayBlend_DX9_FastPath( int *dynVSIdx, int *dynPSIdx, CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, Lightmapped_4WayBlend_DX9_Vars_t &info, CBasePerMaterialContextData **pContextDataPtr, BOOL bCSMEnabled ) { CLightmapped_4WayBlend_DX9_Context *pContextData = reinterpret_cast< CLightmapped_4WayBlend_DX9_Context *> ( *pContextDataPtr ); CCommandBufferBuilder< CFixedCommandStorageBuffer< 1000 > > DynamicCmdsOut; DynamicCmdsOut.Call( pContextData->m_pStaticCmds ); DynamicCmdsOut.Call( pContextData->m_SemiStaticCmdsOut.Base() ); bool hasEnvmap = params[info.m_nEnvmap]->IsTexture(); if( hasEnvmap ) { DynamicCmdsOut.BindEnvCubemapTexture( pShader, SHADER_SAMPLER2, TEXTURE_BINDFLAGS_NONE, info.m_nEnvmap, info.m_nEnvmapFrame ); } DynamicCmdsOut.End(); ShaderApiFast( pShaderAPI )->ExecuteCommandBuffer( DynamicCmdsOut.Base() ); bool bVertexShaderFastPath = pContextData->m_bVertexShaderFastPath; DECLARE_DYNAMIC_VERTEX_SHADER( lightmapped_4wayblend_vs30 ); SET_DYNAMIC_VERTEX_SHADER_COMBO( FASTPATH, bVertexShaderFastPath ); SET_DYNAMIC_VERTEX_SHADER( lightmapped_4wayblend_vs30 ); float vAmbientColor[4] = { mat_ambient_light_r.GetFloat(), mat_ambient_light_g.GetFloat(), mat_ambient_light_b.GetFloat(), 0.0f }; if ( g_pConfig->nFullbright == 1 ) { vAmbientColor[0] = vAmbientColor[1] = vAmbientColor[2] = 0.0f; } pShaderAPI->SetPixelShaderConstant( 31, vAmbientColor, 1 ); pShaderAPI->SetBooleanPixelShaderConstant( 0, (BOOL*)&bCSMEnabled, 1 ); if ( bCSMEnabled ) { ITexture *pDepthTextureAtlas = NULL; const CascadedShadowMappingState_t &cascadeState = pShaderAPI->GetCascadedShadowMappingState( &pDepthTextureAtlas, true ); pShader->BindTexture( SHADER_SAMPLER15, TEXTURE_BINDFLAGS_SHADOWDEPTH, pDepthTextureAtlas, 0 ); pShaderAPI->SetPixelShaderConstant( 64, &cascadeState.m_vLightColor.x, CASCADED_SHADOW_MAPPING_CONSTANT_BUFFER_SIZE ); } bool bPixelShaderFastPath = pContextData->m_bPixelShaderFastPath; float envmapContrast = params[info.m_nEnvmapContrast]->GetFloatValue(); DECLARE_DYNAMIC_PIXEL_SHADER( lightmapped_4wayblend_ps30 ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FASTPATH, bPixelShaderFastPath ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FASTPATHENVMAPCONTRAST, bPixelShaderFastPath && envmapContrast == 1.0f ); MaterialFogMode_t fogType = ShaderApiFast( pShaderAPI )->GetSceneFogMode(); // Don't write fog to alpha if we're using translucency bool bWriteDepthToAlpha = false; bool bWriteWaterFogToAlpha; if( pContextData->m_bFullyOpaque ) { bWriteDepthToAlpha = ShaderApiFast( pShaderAPI )->ShouldWriteDepthToDestAlpha(); bWriteWaterFogToAlpha = (fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z); } else { //can't write a special value to dest alpha if we're actually using as-intended alpha bWriteDepthToAlpha = false; bWriteWaterFogToAlpha = false; } bool bFlashlightShadows = false; SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha ); SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); SET_DYNAMIC_PIXEL_SHADER_CMD( DynamicCmdsOut, lightmapped_4wayblend_ps30 ); *dynVSIdx = _vshIndex.GetIndex(); *dynPSIdx = _pshIndex.GetIndex(); }
313609f69749181e88753d6e1247168dc74ca77c
51e8ee2b409440bcca1c7c6eefc08dcb2f71c875
/Dictionary.h
69523cb85fac8c8d9d0bc0da610be1700983863e
[]
no_license
TheTipTapTyper/Dictionary
70e22c247c7d600bb20de0f5734a8889e56dc3fb
4f7b38e57a6be39edd224a67f175ab41aaa9f947
refs/heads/master
2020-04-02T20:21:57.937113
2018-10-26T03:17:57
2018-10-26T03:17:57
154,766,565
0
0
null
null
null
null
UTF-8
C++
false
false
718
h
Dictionary.h
#ifndef _DICTIONARY_H_ #define _DICTIONARY_H_ #include <string> #include "WordNode.h" using namespace std; class Dictionary{ private: WordNode * binTree; //binary search tree of words public: int isWord(string word_input); //check if word is a word in the english language. return 1 if yes, 0 if no Dictionary(); //constructor ~Dictionary(); //destructor int load(string FileName); //load up tree from text file int save(string FileName); //save data to text file int addWord(string word_input); //add word to binary search tree void buildTree(string FileName); //split and organize alphabatized list of words into binary search tree void deleteTree(); }; #endif // _DICTIONARY_H_
130565ba97bfefa40e88a3092c4f271b8d6ee145
6cf5c6be4bc03f6f8d6e5c162efda887f52d9c61
/section_12/list_in_STL.cpp
bbd03e5894876933e683bd3d80259777d277c67e
[]
no_license
Rishabhchauhan30/Cpp-Stuff--
a167b69f437947350e8647305db555ea4bfc2332
d2acc0bebed2ac8de817c31f054f51be6a3437d1
refs/heads/master
2023-01-30T17:46:01.965579
2020-12-14T13:52:28
2020-12-14T13:52:28
298,875,470
0
0
null
null
null
null
UTF-8
C++
false
false
754
cpp
list_in_STL.cpp
#include <iostream> #include <algorithm> #include <list> using namespace std; int main(){ list <int> mylist; for(int i = 3; i <= 10; ++i){ mylist.push_back(i); } cout << mylist.front() << endl; // just to see the front values cout << mylist.back() << endl; // just to see the back values mylist.pop_back(); // the last value is peranently delete or destroyes mylist.pop_front(); // the front value is peranently delete or destroyes mylist.reverse(); // reverse the list for (auto i : mylist){ cout << i << " "; } cout << endl; mylist.sort(); for(auto i : mylist){ cout << i << " "; } cout << endl; return 0; }
9e576fa4eb5a5d0d4b8af402072e1b2764113e55
a79f0d471709c947ad267f803ebbbef8b019feba
/summer/summerdlg.cpp
c1f2b8c66a9c09c4e43f1cbe50c676544019ceb7
[]
no_license
gazlan/Summer
ac305e791d4aa4f3671372336dbc12daf13ee571
70ff3b5207d70e55fdd7bbeb28b1595c618ac0a1
refs/heads/master
2021-05-04T15:33:11.304565
2018-02-04T23:01:58
2018-02-04T23:01:58
120,231,082
0
0
null
null
null
null
UTF-8
C++
false
false
6,854
cpp
summerdlg.cpp
#include "stdafx.h" #include "..\shared\mmf.h" #include "..\shared\file.h" #include "Summer.h" #include "SummerDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif CSummerDlg::CSummerDlg(CWnd* pParent /*=NULL*/) : CDialog(CSummerDlg::IDD, pParent) { //{{AFX_DATA_INIT(CSummerDlg) _sRich = _T(""); _sSum = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CSummerDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSummerDlg) DDX_Text(pDX, IDC_RICH, _sRich); DDV_MaxChars(pDX, _sRich, 65535); DDX_Text(pDX, IDC_EDT_SUM, _sSum); DDV_MaxChars(pDX, _sSum, 255); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSummerDlg, CDialog) //{{AFX_MSG_MAP(CSummerDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_NOTIFY(NM_CLICK, IDC_RICH, OnClickRich) ON_WM_DESTROY() ON_BN_CLICKED(IDC_BTN_EQU, OnBtnEqu) ON_BN_CLICKED(IDC_BTN_CLEAR, OnBtnClear) ON_BN_CLICKED(IDC_BTN_SAVE, OnBtnSave) ON_BN_CLICKED(IDC_BTN_LOAD, OnBtnLoad) //}}AFX_MSG_MAP END_MESSAGE_MAP() BOOL CSummerDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon CenterWindow(); CRichEditCtrl* pRich = (CRichEditCtrl*)GetDlgItem(IDC_RICH); ASSERT(pRich); if (pRich) { CHARFORMAT CF; CF.dwMask = CFM_BOLD | CFM_SIZE; CF.dwEffects = CFE_BOLD; CF.yHeight = 360; pRich->SetDefaultCharFormat(CF); } CRichEditCtrl* pSum = (CRichEditCtrl*)GetDlgItem(IDC_EDT_SUM); ASSERT(pSum); if (pSum) { CHARFORMAT CF; CF.dwMask = CFM_BOLD | CFM_SIZE; CF.dwEffects = CFE_BOLD; CF.yHeight = 360; pSum->SetDefaultCharFormat(CF); } return TRUE; // return TRUE unless you set the focus to a control } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CSummerDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CSummerDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CSummerDlg::OnClickRich(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here *pResult = 0; } void CSummerDlg::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here } void CSummerDlg::OnBtnEqu() { const char* pszDelimiters = " \t\v\r\n"; UpdateData(TRUE); if (_sRich.IsEmpty()) { // Nothing to do ! return; } _sRich.Replace(',','.'); // Float point DWORD dwSize = _sRich.GetLength(); char* pBuf = new char[dwSize + 1]; memset(pBuf,0,dwSize + 1); strncpy(pBuf,(LPCTSTR)_sRich,dwSize); pBuf[dwSize] = 0; // Ensure ASCIIZ double fSum = 0.0; char* pszLine = strtok(pBuf,pszDelimiters); while (pszLine && *pszLine) { double fLine = atof(pszLine); fSum += fLine; pszLine = strtok(NULL,pszDelimiters); } delete[] pBuf; pBuf = NULL; _sSum.Format("%.2f",fSum); UpdateData(FALSE); } void CSummerDlg::OnBtnClear() { _sRich = _T(""); _sSum = _T(""); UpdateData(FALSE); } void CSummerDlg::OnCancel() { // TODO: Add extra cleanup here CDialog::OnCancel(); } BOOL CSummerDlg::PreTranslateMessage(MSG* pMsg) { if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE) { // Prevent <ESC> exit ! return TRUE; } return CDialog::PreTranslateMessage(pMsg); } void CSummerDlg::OnBtnSave() { UpdateData(TRUE); char pszNewFile[MAX_PATH + 1]; memset(pszNewFile,0,sizeof(pszNewFile)); DWORD dwFlags = OFN_EXPLORER | OFN_CREATEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT; char pszFilter[] = "*.txt\0*.txt\0*.*\0*.*\0\0"; char pszDrive[_MAX_DRIVE]; char pszDir [_MAX_DIR]; char pszFName[_MAX_FNAME]; char pszExt [_MAX_EXT]; CWaitCursor Waiter; /* if (!_sCipher.IsEmpty()) { _splitpath((LPCTSTR)_sCipher,pszDrive,pszDir,pszFName,pszExt); } */ CString sReport = _T(""); OPENFILENAME OFN; memset(&OFN,0,sizeof(OPENFILENAME)); OFN.lStructSize = sizeof(OPENFILENAME); OFN.hwndOwner = GetSafeHwnd(); OFN.lpstrFilter = pszFilter; OFN.nFilterIndex = 1; OFN.lpstrInitialDir = pszDir; OFN.lpstrFile = pszNewFile; OFN.nMaxFile = MAX_PATH; OFN.lpstrFileTitle = NULL; OFN.nMaxFileTitle = MAX_PATH; OFN.Flags = dwFlags; if (GetSaveFileName(&OFN) == TRUE) { sReport = pszNewFile; FILE* pReport = fopen((LPCTSTR)sReport,"wt"); if (!pReport) { // Error ! ASSERT(0); return; } fprintf(pReport,"%s",(LPCTSTR)_sRich); fclose(pReport); pReport = NULL; } } void CSummerDlg::OnBtnLoad() { DWORD dwFlags = OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST; char pszFilter[MAX_PATH] = "TXT (*.txt)|*.txt|" "ALL (*.*)|*.*||"; CFileDialog FileSrc(TRUE,NULL,NULL,dwFlags,pszFilter); CWaitCursor Waiter; if (FileSrc.DoModal() == IDOK) { CString sReport = FileSrc.GetPathName(); MMF _MF; bool bOpen = _MF.OpenReadOnly((LPCTSTR)sReport) == TRUE; if (!bOpen) { // Error ! ASSERT(0); CString sMessage = _T(""); sMessage.Format("Can't Open file [%s] for Read.",(LPCTSTR)sReport); MessageBox(sMessage,"Error",MB_OK | MB_ICONEXCLAMATION); return; } _sRich = _MF.Buffer(); _MF.Close(); } UpdateData(FALSE); }
109bd0a1192ab30b52d05645cd6390ced6f67037
ebb70744ee7a500b6bdace13274eee3954832f7b
/commandLineWeek21/commandLineWeek21.cpp
2b8c6458aeba4e7cae549a62fe7a1d03b43014f5
[]
no_license
FruitJuice/commandLineWeek21
03bb87fe30c80ce9c12be4105574c5b499275782
728cbe404d30d7ed770be755de334d0e14ab4937
refs/heads/master
2021-01-17T23:05:13.178886
2017-03-07T15:58:53
2017-03-07T15:58:53
84,212,252
0
0
null
null
null
null
UTF-8
C++
false
false
771
cpp
commandLineWeek21.cpp
#include "stdafx.h" #include <stdio.h> #include <stdarg.h> #include <cstdlib> struct patient { int patientID; double temperature; int pulseRate; int respRate; int bldSystolic; int bldDiastolic; }; void main(int argc,char *argv[]) { FILE *ptr; ptr = fopen("log.txt", "a"); struct patient patients; patients.patientID = atof(argv[1]); patients.temperature = atof(argv[2]); patients.pulseRate = atof(argv[3]); patients.respRate = atof(argv[4]); patients.bldSystolic = atof(argv[5]); patients.bldDiastolic = atof(argv[6]); fprintf(ptr, "%s\t%s\t%d\t%.2lf\t%d\t%d\t%d\t%d\n", __DATE__, __TIME__, patients.patientID, patients.temperature, patients.pulseRate, patients.respRate, patients.bldSystolic, patients.bldDiastolic); fclose(ptr); }
d84264579500ed36e429f290ae5cfd64ec5eb44a
76f9883f6447abff33798572dc254c02af8451d1
/mz1.cpp
a8139b48c072cd5451e999b25078deede1a5619b
[]
no_license
jammer312/cpp_random_code_without_context
23728972312af85cfad1ad6411493870bc145500
c9eeefa4c4e3ccdc0eaca8fbbc3480f3546e2d0d
refs/heads/master
2022-12-21T08:01:30.741559
2020-10-05T12:09:02
2020-10-05T12:09:02
301,395,666
0
0
null
null
null
null
UTF-8
C++
false
false
659
cpp
mz1.cpp
#include <iterator> constexpr int second_addendum_rindex = 2; constexpr int third_addendum_rindex = 4; template<typename T> auto process(const T &container) { typename T::value_type ret{}; auto size = container.size(); if (size == 0) { return ret; } auto rev_it = container.rbegin(); ret += *rev_it; if (size <= second_addendum_rindex) { return ret; } std::advance(rev_it, second_addendum_rindex); ret += *rev_it; if (size <= third_addendum_rindex) { return ret; } std::advance(rev_it, third_addendum_rindex - second_addendum_rindex); ret += *rev_it; return ret; }
525c143d30bd232b00b8e808efafc820450716ae
d41983a1f22fdb13497068c000cd77bc04953753
/Projetos/Gerenciador de Tarefas/gerenciador.cpp
e2473bef5da610623def2aa11ef896634a0e687c
[]
no_license
Cleiton366/ED-2020.1
3d53ce4ab8013b33cbc9b5075b8ba492e86ea3f8
5f5199b09374f91b566dbba83d2a13aa978d10f1
refs/heads/main
2023-01-06T19:09:56.953830
2020-11-07T22:58:17
2020-11-07T22:58:17
310,944,282
0
0
null
null
null
null
UTF-8
C++
false
false
7,309
cpp
gerenciador.cpp
#include "gerenciador.hpp" #include <string> #include <iostream> #include <time.h> using namespace std; //construtores gerenciador::gerenciador(int tamanho){ this->vetor = new tarefa[tamanho]; this->tamanho = tamanho; qtd = 0; filtro = 1; } gerenciador::tarefa::tarefa(){} gerenciador::tarefa::tarefa(std::string descricao, bool estado, int data_criacao[3], int data_prazo[3]){ this->descricao = descricao; this->estado = estado; for(int i = 0; i < 3; i++){ this->data_criacao[i] = data_criacao[i]; this->data_prazo[i] = data_prazo[i]; } } bool gerenciador::adicionar_tarefa(std::string descricao, bool estado, int data_prazo[3]){ //tarefa* t = new tarefa(descricao, estado, data_criacao, data_prazo); if(qtd == tamanho) return false; this->vetor[qtd].descricao = descricao; this->vetor[qtd].estado = estado; preencher_datas(data_prazo); this->qtd++; return true; } bool gerenciador::remover_tarefa(int indice){ if(qtd == 0) return false; if(indice > qtd) return false; while(indice < qtd){ vetor[indice] = vetor[indice+1]; indice++; } qtd--; return true; } bool gerenciador::marcar_concluido(int indice){ int i = 0; while(i < qtd){ if(i == indice){ vetor[i].estado = true; } i++; } return true; } bool gerenciador::reabrir_tarefa(int indice){ int i = 0; while(i < qtd){ if(i == indice){ vetor[i].estado = false; } i++; } return true; } void gerenciador::filtrar(int op){ this->filtro = op; } void gerenciador::exibir(gerenciador a){ //op = 1 exibir todas / op = 2 exibir abertas / op = 3 exibir concluidas int indice = 0; if(this->filtro == 1){ cout << "Todas as tarefas:" << endl; for(int i = 0; i < qtd; i++){ cout << "Tarefa numero:" << indice++ << endl; cout <<"Descricao = "<< vetor[i].descricao << endl; if(vetor[i].estado == true){ cout << "Estado = Concluida." << endl; }else cout << "Estado = Pendente." << endl; cout << "Criado em = "; for(int k = 0; k < 3; k++) cout <<vetor[i].data_criacao[k] << "."; cout << endl; cout << "Prazo ate = "; for(int k = 0; k < 3; k++) cout <<vetor[i].data_prazo[k] << "."; cout << endl << endl; } }else if(this->filtro == 2){ cout << "Tarefas pendentes:" << endl; for(int i = 0; i < qtd; i++){ if(vetor[i].estado == false){ cout << "Tarefa numero:" << indice++ << endl; cout <<"Descricao = "<< vetor[i].descricao << endl; cout << "Estado = Pendente." << endl; cout << "Criado em = "; for(int k = 0; k < 3; k++) cout <<vetor[i].data_criacao[k] << "."; cout << endl; cout << "Prazo ate = "; for(int k = 0; k < 3; k++) cout <<vetor[i].data_prazo[k] << "."; cout << endl << endl; } } } else if(this->filtro == 3){ cout << "Tarefas concluidas:" << endl; for(int i = 0; i < qtd; i++){ if(vetor[i].estado == true){ cout << "Tarefa numero:" << indice++ << endl; cout <<"Descricao = "<< vetor[i].descricao << endl; cout << "Estado = Conluida." << endl; cout << "Criado em = "; for(int k = 0; k < 3; k++) cout <<vetor[i].data_criacao[k] << "."; cout << endl; cout << "Prazo ate = "; for(int k = 0; k < 3; k++) cout <<vetor[i].data_prazo[k] << "."; cout << endl << endl; } } } } void gerenciador::preencher_datas(int data_prazo[3]){ struct tm* data_criacao; time_t data; time(&data); data_criacao = localtime(&data); this->vetor[qtd].data_criacao[0] = data_criacao->tm_mday; this->vetor[qtd].data_criacao[1] = data_criacao->tm_mon+1; this->vetor[qtd].data_criacao[2] = data_criacao->tm_year+1900; this->vetor[qtd].data_prazo[0] = data_prazo[0]; this->vetor[qtd].data_prazo[1] = data_prazo[1]; this->vetor[qtd].data_prazo[2] = data_prazo[2]; } int dataint(int num, int vetor[3]){ num = 0; for (int i = 0; i < 3; i++) { num *= 10; num += vetor[i]; } return num; } bool gerenciador::adicionar_tarefa_em(int indice, tarefa* t){ if(qtd == tamanho) return false; int k = qtd + 1; while(indice < k){ vetor[k] = vetor[k-1]; k--; } vetor[k].descricao = t->descricao; vetor[k].estado = t->estado; copiar_datas(t, k); qtd++; return true; } void gerenciador::copiar_datas(tarefa* t, int indice){ for(int i = 0; i < 3; i++){ vetor[indice].data_criacao[i] = t->data_criacao[i]; vetor[indice].data_prazo[i] = t->data_prazo[i]; } } void gerenciador::ordenar_criacao(){ for(int i = 0; i < qtd; i++){ for(int j = 0; j < qtd-i; j++){ if(vetor[j].data_criacao[1] < vetor[j+1].data_criacao[1] || vetor[j].data_criacao[1] < vetor[j+1].data_criacao[1] && vetor[j].data_criacao[0] < vetor[j+1].data_criacao[0]){ tarefa* aux = new tarefa(vetor[j]); vetor[j] = vetor[j+1]; remover_tarefa(j+1); adicionar_tarefa_em(j+1, aux); } } } } void gerenciador::ordenar_prazo(){ for(int i = 0; i < qtd; i++){ for(int j = 0; j < qtd-i; j++){ if(vetor[j].data_prazo[1] < vetor[j+1].data_prazo[1] || vetor[j].data_prazo[1] < vetor[j+1].data_prazo[1] && vetor[j].data_prazo[0] < vetor[j+1].data_prazo[0]){ tarefa* aux = new tarefa(vetor[j]); vetor[j] = vetor[j+1]; remover_tarefa(j+1); adicionar_tarefa_em(j+1, aux); } } } } void gerenciador::ordenar_manual(int indice_alvo, int outro, int op){ //op = 1 trocar de posição com outra tarefa informada //op = 2 subir uma quantidade de posições informada //op = 3 descer uma quantidade de posições informada if(op == 1){ tarefa* aux = new tarefa(vetor[indice_alvo]); vetor[indice_alvo] = vetor[outro]; remover_tarefa(outro); adicionar_tarefa_em(outro, aux); }else if(op == 2){ tarefa* aux = new tarefa(vetor[indice_alvo]); vetor[indice_alvo] = vetor[indice_alvo-1]; remover_tarefa(indice_alvo); adicionar_tarefa_em(indice_alvo-1, aux); }else if(op == 3){ tarefa* aux = new tarefa(vetor[indice_alvo]); vetor[indice_alvo] = vetor[indice_alvo+1]; remover_tarefa(indice_alvo); adicionar_tarefa_em(indice_alvo + 1, aux); } } void gerenciador::limpar(){ system("CLS"); } void gerenciador::frezar_tela(){ std::string s; getline(cin,s); getline(cin,s); }
aee9cf76bd825adedec32a8859d9ad9144bbf37e
318b737f3fe69171f706d2d990c818090ee6afce
/src/nameserver/cluster_info.h
31cd0b038152bf8fa21385276b8eb18740bbedc6
[ "Apache-2.0" ]
permissive
4paradigm/OpenMLDB
e884c33f62177a70749749bd3b67e401c135f645
a013ba33e4ce131353edc71e27053b1801ffb8f7
refs/heads/main
2023-09-01T02:15:28.821235
2023-08-31T11:42:02
2023-08-31T11:42:02
346,976,717
3,323
699
Apache-2.0
2023-09-14T09:55:44
2021-03-12T07:18:31
C++
UTF-8
C++
false
false
2,618
h
cluster_info.h
/* * Copyright 2021 4Paradigm * * 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. */ #ifndef SRC_NAMESERVER_CLUSTER_INFO_H_ #define SRC_NAMESERVER_CLUSTER_INFO_H_ #include <map> #include <memory> #include <string> #include <vector> #include "client/ns_client.h" #include "proto/name_server.pb.h" #include "proto/tablet.pb.h" #include "zk/zk_client.h" namespace openmldb { namespace nameserver { class ClusterInfo { public: explicit ClusterInfo(const ::openmldb::nameserver::ClusterAddress& cdp); void CheckZkClient(); void UpdateNSClient(const std::vector<std::string>& children); int Init(std::string& msg); // NOLINT bool CreateTableRemote(const ::openmldb::api::TaskInfo& task_info, const ::openmldb::nameserver::TableInfo& table_info, const ::openmldb::nameserver::ZoneInfo& zone_info); bool DropTableRemote(const ::openmldb::api::TaskInfo& task_info, const std::string& name, const std::string& db, const ::openmldb::nameserver::ZoneInfo& zone_info); bool AddReplicaClusterByNs(const std::string& alias, const std::string& zone_name, const uint64_t term, std::string& msg); // NOLINT bool RemoveReplicaClusterByNs(const std::string& alias, const std::string& zone_name, const uint64_t term, int& code, // NOLINT std::string& msg); // NOLINT bool UpdateRemoteRealEpMap(); std::shared_ptr<::openmldb::client::NsClient> client_; std::map<std::string, std::map<std::string, std::vector<TablePartition>>> last_status; ::openmldb::nameserver::ClusterAddress cluster_add_; uint64_t ctime_; std::atomic<ClusterStatus> state_; std::shared_ptr<std::map<std::string, std::string>> remote_real_ep_map_; private: std::shared_ptr<::openmldb::zk::ZkClient> zk_client_; uint64_t session_term_; // todo :: add statsus variable show replicas status }; } // namespace nameserver } // namespace openmldb #endif // SRC_NAMESERVER_CLUSTER_INFO_H_
4bc4a42041f9fba6ebea1a79e6b2aa0a6db343b0
fc9e04fc6d9dae294c909124f294ce2b16d0cc0f
/FrameTL/biharmonic_equation.cpp
b001ab1a1c809dcb3691aba336db4601bdea4529
[ "MIT" ]
permissive
vogeldor/Marburg_Software_Library
07c5546b5f6222f4ad3855c0667a185a7b710d34
fe53c3ae9db23fc3cb260a735b13a1c6d2329c17
refs/heads/master
2022-11-15T13:14:37.053345
2020-07-16T11:23:47
2020-07-16T11:23:47
null
0
0
null
null
null
null
UTF-8
C++
false
false
13,270
cpp
biharmonic_equation.cpp
// implementation for biharmonic_equation.h #include <list> #include <numerics/gauss_data.h> #include <numerics/eigenvalues.h> #include <algebra/sparse_matrix.h> #include <frame_index.h> #include <frame_support.h> //#include <cuba.h> //#include <cube/cube_support.h> using WaveletTL::CubeBasis; namespace FrameTL { template <class IBASIS, unsigned int DIM> BiharmonicEquation<IBASIS,DIM>::BiharmonicEquation(const BiharmonicBVP<DIM>* bih_bvp, const AggregatedFrame<IBASIS,DIM>* frame, const int jmax) : bih_bvp_(bih_bvp), frame_(frame),jmax_(jmax) { compute_diagonal(); // compute_rhs(false); } template <class IBASIS, unsigned int DIM> double BiharmonicEquation<IBASIS,DIM>::D(const typename AggregatedFrame<IBASIS,DIM>::Index& lambda) const { //return ldexp(1.0,lambda.j() * operator_order()); return stiff_diagonal.get_coefficient(lambda); } template <class IBASIS, unsigned int DIM> void BiharmonicEquation<IBASIS,DIM>::compute_rhs(bool compute) { cout << "BiharmonicEquation(): precompute right-hand side..." << endl; typedef AggregatedFrame<IBASIS,DIM> Frame; typedef typename Frame::Index Index; // precompute the right-hand side on a fine level InfiniteVector<double,Index> fhelp; const int j0 = frame_->j0(); if(compute) { for (Index lambda(FrameTL::first_generator<IBASIS,DIM,DIM,Frame>(frame_,j0));; ++lambda) { const double coeff = f(lambda)/D(lambda); cout << lambda << " " << coeff << endl; if (fabs(coeff)>1e-15) { fhelp.set_coefficient(lambda, coeff); } if (lambda == last_wavelet<IBASIS,DIM,DIM,Frame>(frame_,jmax_)) break; //cout << lambda << endl; } } #if 0 else { Vector<double> f; Rhs_input(f); for(unsigned int i=0; i<f.size(); i++) { Index lambda=FrameIndex<IBASIS, DIM>(i, frame_); fhelp.set_coefficient(lambda, f[i]); } } #endif fnorm_sqr = l2_norm_sqr(fhelp); cout << "... done, all integrals for right-hand side computed" << endl; // sort the coefficients into fcoeffs fcoeffs.resize(0); // clear eventual old values fcoeffs.resize(fhelp.size()); unsigned int id(0); for (typename InfiniteVector<double,Index>::const_iterator it(fhelp.begin()), itend(fhelp.end()); it != itend; ++it, ++id) fcoeffs[id] = std::pair<Index,double>(it.index(), *it); sort(fcoeffs.begin(), fcoeffs.end(), typename InfiniteVector<double,Index>::decreasing_order()); } template <class IBASIS, unsigned int DIM> void BiharmonicEquation<IBASIS,DIM>::compute_diagonal() { cout << "BiharmonicEquation(): precompute diagonal of stiffness matrix..." << endl; typedef AggregatedFrame<IBASIS,DIM> Frame; typedef typename Frame::Index Index; // precompute the right-hand side on a fine level const int j0 = frame_->j0(); for (Index lambda(FrameTL::first_generator<IBASIS,DIM,DIM,Frame>(frame_,j0));; ++lambda) { stiff_diagonal.set_coefficient(lambda, sqrt(a(lambda,lambda))); // cout << "lambda: " <<lambda<< endl; if (lambda == last_wavelet<IBASIS,DIM,DIM,Frame>(frame_,jmax_)) break; //cout << " ok "; } cout << "... done, diagonal of stiffness matrix computed" << endl; } template <class IBASIS, unsigned int DIM> inline double BiharmonicEquation<IBASIS,DIM>:: integrate(const Index1D<IBASIS>& lambda, const Index1D<IBASIS>& mu, const FixedArray1D<Array1D<double>,DIM >& irregular_grid, const int N_Gauss, const int dir) const { double res = 0; Array1D<double> gauss_points_la, gauss_points_mu, gauss_weights, values_lambda, values_mu; gauss_points_la.resize(N_Gauss*(irregular_grid[dir].size()-1)); gauss_points_mu.resize(N_Gauss*(irregular_grid[dir].size()-1)); gauss_weights.resize(N_Gauss*(irregular_grid[dir].size()-1)); for (unsigned int k = 0; k < irregular_grid[dir].size()-1; k++) for (int n = 0; n < N_Gauss; n++) { gauss_points_la[ k * N_Gauss+n ] = 0.5 * (irregular_grid[dir][k+1]-irregular_grid[dir][k]) * (GaussPoints[N_Gauss-1][n]+1) + irregular_grid[dir][k]; gauss_weights[k*N_Gauss+n ] = (irregular_grid[dir][k+1]-irregular_grid[dir][k])*GaussWeights[N_Gauss-1][n]; } IBASIS* basis1D_lambda = frame_->bases()[lambda.p()]->bases()[dir]; IBASIS* basis1D_mu = frame_->bases()[mu.p()]->bases()[dir]; const Chart<DIM>* chart_la = frame_->atlas()->charts()[lambda.p()]; const Chart<DIM>* chart_mu = frame_->atlas()->charts()[mu.p()]; WaveletTL::evaluate(*(basis1D_lambda), lambda.derivative(), lambda.index(), gauss_points_la, values_lambda); Point<DIM> x; // = 0; Point<DIM> x_patch; Point<DIM> y; // setup mapped gauss points for (unsigned int i = 0; i < gauss_points_la.size(); i++) { x[dir] = gauss_points_la[i]; chart_la->map_point(x,x_patch); chart_mu->map_point_inv(x_patch,y); gauss_points_mu[i] = y[dir]; } WaveletTL::evaluate(*(basis1D_mu), mu.derivative(), mu.index(), gauss_points_mu, values_mu); for (unsigned int i = 0; i < values_lambda.size(); i++) res += gauss_weights[i] * values_lambda[i] * values_mu[i]; return res; } template <class IBASIS, unsigned int DIM> double BiharmonicEquation<IBASIS,DIM>::a(const typename AggregatedFrame<IBASIS,DIM>::Index& la, const typename AggregatedFrame<IBASIS,DIM>::Index& nu) const { double r = 0.0; Index lambda = la; Index mu = nu; Index tmp_ind; typedef WaveletTL::CubeBasis<IBASIS,DIM> CUBEBASIS; //typedef typename CUBEBASIS::Index CubeIndex; typename CUBEBASIS::Support supp_lambda_ = frame_->all_supports[lambda.number()]; typename CUBEBASIS::Support supp_mu_ = frame_->all_supports[mu.number()]; typename CUBEBASIS::Support tmp_supp; // swap indices and supports if necessary if (supp_mu_.j > supp_lambda_.j) { tmp_ind = lambda; lambda = mu; mu = tmp_ind; tmp_supp = supp_lambda_; supp_lambda_ = supp_mu_; supp_mu_ = tmp_supp; } const typename CUBEBASIS::Support* supp_lambda = &supp_lambda_; const typename CUBEBASIS::Support* supp_mu = &supp_mu_; FixedArray1D<Array1D<double>,DIM > irregular_grid; //int q_order; const int N_Gauss = 4; bool b = 0; b = intersect_supports<IBASIS,DIM,DIM>(*frame_, lambda, mu, supp_lambda, supp_mu, irregular_grid); if ( !b ) return 0.0; #if 0 for (unsigned int i = 0; i < DIM; i++) { cout << "intersect = " << b << endl; cout << "dim = " << i << " " << irregular_grid[i] << endl; } #endif //typedef typename IBASIS::Index Index_1D; const Chart<DIM>* chart_la = frame_->atlas()->charts()[lambda.p()]; const Chart<DIM>* chart_mu = frame_->atlas()->charts()[mu.p()]; FixedArray1D<IBASIS*,DIM> bases1D_lambda = frame_->bases()[lambda.p()]->bases(); FixedArray1D<IBASIS*,DIM> bases1D_mu = frame_->bases()[mu.p()]->bases(); int dim=(int)DIM; int terms=dim*dim; int d[2][dim]; //loop over all terms for (int i = 0; i <terms; i++) { double t = 1.; // loop over spatial direction for(int l=0; l < dim; l++) { d[0][l]=0;d[1][l]=0; } d[0][i/dim]=2; d[1][i%dim]=2; for (int j = 0; j < (int)DIM; j++) { Index1D<IBASIS> i1(typename IBASIS::Index ( lambda.j(),lambda.e()[j],lambda.k()[j], bases1D_lambda[j] ), lambda.p(),j,d[0][j] ); Index1D<IBASIS> i2(typename IBASIS::Index (mu.j(),mu.e()[j],mu.k()[j], bases1D_mu[j] ), mu.p(),j,d[1][j] ); t *= integrate(i1, i2, irregular_grid, N_Gauss, j);//cout << integrate(i1, i2, irregular_grid, N_Gauss, j) << endl; } t *=(1./(chart_la->a_i(i/dim) * chart_mu->a_i(i%dim)))*(1./(chart_la->a_i(i/dim) * chart_mu->a_i(i%dim))); r += t; } double tmp1 = 1., tmp2 = 1.; for (unsigned int i = 0; i < DIM; i++) { tmp1 *= chart_la->a_i(i); tmp2 *= chart_mu->a_i(i); } tmp1 = sqrt(fabs(tmp1)) / sqrt(fabs(tmp2)); r *= tmp1; return r; } template <class IBASIS, unsigned int DIM> void BiharmonicEquation<IBASIS,DIM>::RHS (const double eta, InfiniteVector<double, typename AggregatedFrame<IBASIS,DIM>::Index>& coeffs) const { coeffs.clear(); double coarsenorm(0); double bound(fnorm_sqr - eta*eta); typedef typename AggregatedFrame<IBASIS,DIM>::Index Index; typename Array1D<std::pair<Index, double> >::const_iterator it(fcoeffs.begin()); do { coarsenorm += it->second * it->second; coeffs.set_coefficient(it->first, it->second); ++it; } while (it != fcoeffs.end() && coarsenorm < bound); } template <class IBASIS, unsigned int DIM> double BiharmonicEquation<IBASIS,DIM>::norm_A() const { if (normA == 0.0) { typedef typename AggregatedFrame<IBASIS,DIM>::Index Index; std::set<Index> Lambda; const int j0 = frame_->j0(); const int jmax = j0+1; for (Index lambda = FrameTL::first_generator<IBASIS,DIM,DIM,Frame>(frame_,j0);; ++lambda) { Lambda.insert(lambda); if (lambda == FrameTL::last_wavelet<IBASIS,DIM,DIM,Frame>(frame_,jmax)) break; } SparseMatrix<double> A_Lambda; setup_stiffness_matrix(*this, Lambda, A_Lambda); Vector<double> xk(Lambda.size(), false); xk = 1; unsigned int iterations; normA = PowerIteration(A_Lambda, xk, 1e-6, 100, iterations); } return normA; } template <class IBASIS, unsigned int DIM> double BiharmonicEquation<IBASIS,DIM>::s_star() const { // cout << "Stern" << endl; // notation from [St04a] const double t = operator_order(); const int n = DIM; const int dT = frame_->bases()[0]->primal_vanishing_moments(); // we assume to have the same 'kind' // of wavelets on each patch, so use // patch 0 as reference case const double gamma = frame_->bases()[0]->primal_regularity(); return (n == 1 ? t+dT // [St04a], Th. 2.3 for n=1 : std::min((t+dT)/(double)n, (gamma-t)/1./*(n-1.)*/)); // [St04a, Th. 2.3] } template <class IBASIS, unsigned int DIM> double BiharmonicEquation<IBASIS,DIM>::f(const typename AggregatedFrame<IBASIS,DIM>::Index& lambda) const { //\int_\Omega f(Kappa(x)) \psi^\Box (x) \sqrt(\sqrt(det ((D Kappa)^T(x) (D Kappa)(x)) )) //recall: \sqrt(\sqrt(...)) = Gram_factor int N=10; double r = 0; const unsigned int p = lambda.p(); typedef WaveletTL::CubeBasis<IBASIS,DIM> CUBEBASIS; // first compute supp(psi_lambda) typename CUBEBASIS::Support supp; typename CubeBasis<IBASIS,DIM>::Index lambda_c(lambda.j(), lambda.e(), lambda.k(),frame_->bases()[p]); WaveletTL::support<IBASIS,DIM>(*(frame_->bases()[p]), lambda_c, supp); const Chart<DIM>* chart = frame_->atlas()->charts()[p]; // setup Gauss points and weights for a composite quadrature formula: const int N_Gauss = 8; //const double h = ldexp(1.0, -supp.j); // granularity for the quadrature const double h = 1.0 / (1 << supp.j); // granularity for the quadrature FixedArray1D<Array1D<double>,DIM> gauss_points, gauss_weights, v_values; for (unsigned int i = 0; i < DIM; i++) { gauss_points[i].resize(N*N_Gauss*(supp.b[i]-supp.a[i])); gauss_weights[i].resize(N*N_Gauss*(supp.b[i]-supp.a[i])); for (int patch = supp.a[i]; patch < supp.b[i]; patch++) for(int m=0;m<N;m++) for (int n = 0; n < N_Gauss; n++) { gauss_points[i][N*(patch-supp.a[i])*N_Gauss+m*N_Gauss+n] = h*(N*2*patch+1+GaussPoints[N_Gauss-1][n]+2.0*m)/(2.*N); gauss_weights[i][N*(patch-supp.a[i])*N_Gauss+m*N_Gauss+n] = h*GaussWeights[N_Gauss-1][n]/N; } } // compute the point values of the integrand (where we use that it is a tensor product) for (unsigned int i = 0; i < DIM; i++) { WaveletTL::evaluate(*(frame_->bases()[p]->bases()[i]), 0, typename IBASIS::Index(lambda.j(), lambda.e()[i], lambda.k()[i], frame_->bases()[p]->bases()[i]), gauss_points[i], v_values[i]); } // iterate over all points and sum up the integral shares int index[DIM]; // current multiindex for the point values for (unsigned int i = 0; i < DIM; i++) index[i] = 0; Point<DIM> x; Point<DIM> x_patch; while (true) { for (unsigned int i = 0; i < DIM; i++) x[i] = gauss_points[i][index[i]]; chart->map_point(x,x_patch); double share = bih_bvp_->f(x_patch) * chart->Gram_factor(x); for (unsigned int i = 0; i < DIM; i++) share *= gauss_weights[i][index[i]] * v_values[i][index[i]]; r += share; // "++index" bool exit = false; for (unsigned int i = 0; i < DIM; i++) { if (index[i] ==N* N_Gauss*(supp.b[i]-supp.a[i])-1) { index[i] = 0; exit = (i == DIM-1); } else { index[i]++; break; } } if (exit) break; } return r; } }
4a6155f833ebbc90302940bfc69c438f7f6b75bc
9a3dc95619df0487be6228ba628ba4ce97a139de
/SEUYac/LR1.h
e1792aa686f8336d61cab3d30a2b96ae48457d71
[]
no_license
five-20/SEUYacc-1
bcdd923417ea9ef509f0437f05c469c63d75720a
d35562fefdb2fe7319024d2cf2d317c33dfa627a
refs/heads/master
2023-03-22T23:52:06.356313
2017-05-25T13:00:06
2017-05-25T13:00:06
null
0
0
null
null
null
null
GB18030
C++
false
false
3,498
h
LR1.h
#pragma once #ifndef LR1_H #define LR1_H #include<vector> #include<map> #include<set> using namespace std; struct producer {//解析后的产生式 string left; vector<string> right; }; struct LrItem { string left; vector<string> right; int dotpos; vector<string>predict; bool &operator<=(const LrItem &item) {/*和==差不多,但没有要求预测符数量,只要前者的预测符都能在后者找到就算满足*/ bool tmp = true; if (item.dotpos == this->dotpos) { if (item.left == this->left) { if (item.right == this->right) { for (int i = 0; i < this->predict.size(); i++) { bool findpre = false; for (int j = 0; j < item.predict.size(); j++) { if (this->predict[i] == item.predict[j]) { findpre = true; } } if (!findpre) { tmp = false; } } } else tmp = false; } else tmp = false; } else tmp = false; return tmp; } bool &operator==(const LrItem &item) {/*重载等号运算符,判断是否两个状态相等*/ bool tmp = true;//两个Item是否相同的标志位 if (item.dotpos == this->dotpos) {//先判断点的位置 if (item.left == this->left) {//判断产生式左边 if (item.right == this->right) {//产生式右边 if (this->predict.size() == item.predict.size())//预测符数量 for (int i = 0; i < this->predict.size(); i++) { bool findpre = false;//预测符标记位,后面很多代码都用到了这种方式 for (int j = 0; j < item.predict.size(); j++) { if (this->predict[i] == item.predict[j]) { findpre = true;//如果在前者找到了后者中的预测符,那么标记位置1 } } if (!findpre) { tmp = false;//如果其中一个标志位没有找到,那么说明这两个Item不相同。 } } else tmp = false; } else tmp = false; } else tmp = false; } else tmp = false; return tmp; } }; struct LrState { int Number;//State编号 vector<LrItem> items; vector<pair<string, int>>edges;//出边 vector<string>outedge;//点向后看一位的集合 bool &operator==(const LrState &state) { bool ifequal = true;//两个State是否相同的标记位 if (this->items.size() == state.items.size()) {//判断Item数,提高代码效率 for (int i = 0; i < this->items.size(); i++) {/*判断items*/ bool ifitemssequal = false;//Item相同的标记位 for (int j = 0; j < state.items.size(); j++) { if (this->items[i] == state.items[j]) { ifitemssequal = true;//找到Item,标记位置1 break; } } if (!ifitemssequal) {//如果没找到Item,则两个State不同 ifequal = false; break; } } } else { ifequal = false; } return ifequal; } }; class LR1 { public: LR1(producer); vector<LrState> createLR1();//创建LR1 vector<LrState> AllStates;//保存所有State LrState createNewState(int, string);//被转换的State的序号,规则数,边 //vector<producer>expressions; LrState adjust(LrState tmpState);//移动点后,对点后面的非终结符进行扩展 //int currentStateNum = 0; bool LR1::ifTerminals(string a);//判断是否为终结符 LrState LR1::addpredict(LrState tmpState, int k, int j);//k是原有的式子的下标 int ifStateExistant(LrState newState);//判断State是否存在,若不存在,返回-1,如存在,返回那个State的编号 }; #endif // !LR1_H
e5b74c4fcd5b84539fb6d7b46be8b6ba24da63fb
bb6e8fdef91c4616848527bed7735cc9c7023451
/bee/nonstd/dynarray.h
8eff0b32f625182b32a86934194d34eeac5c6586
[ "MIT" ]
permissive
Xiaobin0860/bee.lua
655db594bddd5f60c1d103f771565a619c8526ad
2b2e3ac9b5cbb66dbf71bd33a1609f4b289fc6a5
refs/heads/master
2020-09-14T01:42:13.149141
2019-11-25T06:47:39
2019-11-25T06:47:39
222,972,203
2
0
MIT
2019-11-20T15:46:07
2019-11-20T15:46:06
null
UTF-8
C++
false
false
4,091
h
dynarray.h
#pragma once #include <bee/nonstd/span.h> namespace std { template <class T> class dynarray : public nonstd::span<T> { public: typedef nonstd::span<T> mybase; typedef T value_type; typedef T& reference; typedef const T& const_reference; typedef T* pointer; typedef const T* const_pointer; typedef T* iterator; typedef const T* const_iterator; typedef std::reverse_iterator<iterator> reverse_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator; typedef size_t size_type; typedef ptrdiff_t difference_type; explicit dynarray(size_type c) : mybase(alloc(c), c) { auto i = mybase::begin(); try { for (; i != mybase::end(); ++i) { new (&*i) T; } } catch (...) { for (; i >= mybase::begin(); --i) { i->~T(); } throw; } } dynarray(const dynarray& d) : mybase(alloc(d.size()), d.size()) { try { uninitialized_copy(d.begin(), d.end(), mybase::begin()); } catch (...) { delete[] reinterpret_cast<char*>(mybase::data()); throw; } } dynarray(dynarray&& d) : mybase(d.data(), d.size()) { d = mybase(); } dynarray(std::initializer_list<T> l) : mybase(alloc(l.size()), l.size()) { try { uninitialized_copy(l.begin(), l.end(), mybase::begin()); } catch (...) { delete[] reinterpret_cast<char*>(mybase::store_); throw; } } template <class Vec> dynarray(const Vec& v, typename std::enable_if<std::is_same<typename Vec::value_type, T>::value>::type* =0) : mybase(alloc(v.size()), v.size()) { try { uninitialized_copy(v.begin(), v.end(), mybase::begin()); } catch (...) { delete[] reinterpret_cast<char*>(mybase::data()); throw; } } ~dynarray() { for (auto& i : *this) { i.~T(); } delete[] reinterpret_cast<char*>(mybase::data()); } dynarray& operator=(const dynarray& d) { if (this != &d) { *(mybase*)this = mybase(alloc(d.size()), d.size()); try { uninitialized_copy(d.begin(), d.end(), mybase::begin()); } catch (...) { delete[] reinterpret_cast<char*>(mybase::data()); throw; } } return *this; } dynarray& operator=(dynarray&& d) { if (this != &d) { *(mybase*)this = mybase(d.data(), d.size()); *(mybase*)&d = mybase(); } return *this; } private: class bad_array_length : public bad_alloc { public: bad_array_length() throw() { } virtual ~bad_array_length() throw() { } virtual const char* what() const throw() { return "std::bad_array_length"; } }; pointer alloc(size_type n) { if (n > (std::numeric_limits<size_type>::max)()/sizeof(T)) { throw bad_array_length(); } return reinterpret_cast<pointer>(new char[n*sizeof(T)]); } }; }
082a5c52eba69dec474ba9c694783a1a22b7648f
795000f575aebcc0f1993194ce4e54c9d0096248
/1-D Array/problem3.cpp
cc834d39bed6e77a9fc3263d28fb1358073088d1
[]
no_license
nayalchitra/P3_Program
fb94329bf658cecda487249dc8cb96a1bd1b80af
06f3436f863e87a7b77f3bf74ca556bc1afac7a1
refs/heads/master
2023-03-09T09:24:45.189517
2023-02-21T16:45:45
2023-02-21T16:45:45
191,009,535
0
0
null
null
null
null
UTF-8
C++
false
false
246
cpp
problem3.cpp
#include<iostream> using namespace std; int main() { int n,i,c=0; cin>>n; int a[n]; for(i=0;i<n;i++) cin>>a[i]; int sum=0; for(i=0;i<n;i++) sum+=a[i]; sum=sum/n; for(i=0;i<n;i++) if(a[i]>sum) c++; cout<<c; }
6a8d486af59ff9c1c2e66fae9cf1f24d4c8fb6a1
309d1a5116bbc43133b95591b476b507a0d5f400
/src/trash/try_catch.cpp
1d71a140ecff80fc425d2c69ce80acc63bac71bb
[]
no_license
supercaracal/study-of-cpp
ff65863f72ac4f5559f4ab22a7436b74cb4b62e9
6e81543457f12da8c546a10775b5c2a1466743d6
refs/heads/master
2021-05-14T06:54:39.877667
2018-02-14T14:12:27
2018-02-14T14:12:27
116,251,503
0
0
null
null
null
null
UTF-8
C++
false
false
413
cpp
try_catch.cpp
#include <iostream> #include <string> class Exception { public: explicit Exception(std::string str) : m_str(str) { } ~Exception() { delete m_str.c_str(); } std::string message() const { return m_str; } private: std::string m_str; }; int main(int argc, char *argv[]) { try { throw new Exception("Oops!"); } catch (Exception *ex) { std::cout << ex->message() << std::endl; } exit(0); }
5fef3b084c29acc08103b62220d81069e261d8d3
2aad21460b2aa836721bc211ef9b1e7727dcf824
/IE_Command/ImgSelectRelease/ImgSelectRelease.cpp
7fc503377cfd03d68b5a864f30d6d85a9cce6394
[ "BSD-3-Clause" ]
permissive
chazix/frayer
4b38c9d378ce8b3b50d66d1e90426792b2196e5b
ec0a671bc6df3c5f0fe3a94d07b6748a14a8ba91
refs/heads/master
2020-03-16T20:28:34.440698
2018-01-09T15:13:03
2018-01-09T15:13:03
null
0
0
null
null
null
null
SHIFT_JIS
C++
false
false
2,050
cpp
ImgSelectRelease.cpp
// ImgSelectRelease.cpp : DLL アプリケーションのエントリ ポイントを定義します。 // #include "stdafx.h" #include "ImgSelectRelease.h" #ifdef _MANAGED #pragma managed(push, off) #endif BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } #ifdef _MANAGED #pragma managed(pop) #endif // for detect memory leak #ifdef _DEBUG #define _CRTDBG_MAP_ALLOC #include <stdlib.h> #include <cstdlib> #include <crtdbg.h> #define new new(_NORMAL_BLOCK, __FILE__, __LINE__) #endif #define DISPLAY_NAME_JA "選択を解除する" #define DISPLAY_NAME DISPLAY_NAME_JA IECOMMAND_EXPORT IEMODULE_ID GetIEModule_ID() { return IEMODULE_ID::COMMAND; } IECOMMAND_EXPORT void GetIECommandName(char* dst) { strcpy_s(dst, MAX_IE_MODULE_NAME, "ImgSelectRelease"); } IECOMMAND_EXPORT void GetIECommandDisplayNameJa(char* dst) { strcpy_s(dst, MAX_IE_MODULE_NAME, DISPLAY_NAME); } IECOMMAND_EXPORT IIECommand* CreateIECommand() { return new ImgSelectRelease; } IECOMMAND_EXPORT void ReleaseIECommand(IIECommand** ppCommand) { if (*ppCommand) { delete (*ppCommand); (*ppCommand) = NULL; } } ImgSelectRelease::ImgSelectRelease() { strcpy_s(m_name, MAX_IE_MODULE_NAME, "ImgSelectRelease"); strcpy_s(m_disp_name, MAX_IE_MODULE_DISPLAY_NAME, DISPLAY_NAME); } BOOL ImgSelectRelease::Run(ImgEdit* pEdit, void* pvoid) { ImgFile_Ptr f = pEdit->GetActiveFile(); if(f){ RECT rc; ImgMask_Ptr pMask = f->GetSelectMask(); f->GetMaskRect(&rc); EditMaskHandle* pEditMaskHandle = (EditMaskHandle*)f->CreateImgFileHandle(IFH_EDIT_MASK); strcpy_s(pEditMaskHandle->handle_name, MAX_IMG_FILE_HANDLE_NAME, DISPLAY_NAME); f->DoImgFileHandle( pEditMaskHandle ); EditNode* pEditNode; pEditNode = pEditMaskHandle->CreateEditNode(&rc); pEditNode->fourcc = IE_MASK_SYNTH_FOURCC('s','u','b',' '); pEditNode->edit_img.FillMask(255); // pEditMaskHandle->Update(&rc); pEditMaskHandle->EndEdit(); } return FALSE; }
5a5db6fa53e649bf7b600e8170544bdcce365092
3501288a559c3996eedda7d91609d2afc74af351
/uri/strings/1287.cpp
1356bf8ad5f766d89216c2d348bf3ecf713f1271
[]
no_license
josecleiton/contest
9b76035025943067bf7b1eedc40e9aa03b209d12
6e35bbda0f739782536fb6837194a86e7f52e89f
refs/heads/master
2023-06-22T20:10:06.980694
2023-06-18T13:50:07
2023-06-18T13:50:07
137,649,792
23
9
null
null
null
null
UTF-8
C++
false
false
2,499
cpp
1287.cpp
//TEMPLATE COM MACROS PARA OS CONTESTS //compile usando: g++ -std=c++11 -lm -O3 arquivo.cpp #include <bits/stdc++.h> #define FOR(x) for(int i=0;i<x;i++) #define ROF(x) for(int i=x-1;i>=0;i--) #define ROFJ(x) for(int j=x-1;j>=0;j--) #define FORJ(x) for(int j=0;j<x;j++) #define FORQ(Q) for(int i=0;Q;i++) #define FORM(x,y) for(int i=0;i<x;i++) for(int j=0;j<y;j++) #define FORT(x,y) for(int i=x;i<y;i++) #define ROFT(x,y) for(int i=x-1;i>=y;i--) #define WHILE(n,x) while((n--)&&cin>>x) #define SORT(v) sort(v.begin(), v.end()) #define SORTC(v, comp) sort(v.begin(), v.end(), comp) #define FORIT(v) for(auto& it: v) #define c(x) cout<<x<<endl #define C(x) cin>>x #define set(a,b) cout.precision(a); cout<<fixed<<b<<endl #define pcs(a) cout.precision(a) #define fx(a) fixed<<a #define gl(s) getline(cin,s) #define pb(a) push_back(a) #define matrixM(n,m) vector<vector<int>> M (n, vector<int> (m)) #define matrixN(n,m) vector<vector<int>> N (n, vector<int> (m)) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<string> vstr; typedef vector<double> vd; typedef vector<long> vl; typedef vector<ll> vll; typedef map<int, int> mii; typedef map<int, bool> mib; typedef map<char, int> mci; typedef map<string, int> msi; typedef pair<int, int> pii; int main(){ int n,m,l; string s; string max="2147483647"; size_t maxs=max.size(); bool error; char resp[60]; while(getline(cin, s)){ error=false; int j=0; if(s.size()){ for(auto c: s){ if(isdigit(c)) resp[j++]=c; else if(c=='l') resp[j++]='1'; else if(c=='o' or c=='O') resp[j++]='0'; else if(c!=',' and c!=' '){ error=true; break; } } resp[j]='\0'; l=j; if(!j){ error=true; } else{ j=0; while(resp[j]=='0') j++; if(j==l) j--; unsigned long long x; try{ x = stoull(resp); } catch(...){ error=true; } if(error or x>numeric_limits<int>::max()) error=true; } } else error=true; if(!error){ printf("%s", resp+j); } else cout<<"error"; cout<<endl; } return 0; }
1dea0b734c8706c9c9c3ac20211a72d41293715c
cf576ef1dff2d24defde1bc5e66c32b1c4adeb9e
/FroggerSource/Frogger/Phases/LineNoPhase.h
c67fec0659726c327c1027615fe0f8dc40f24164
[]
no_license
higgsch/Frogger
4395b5aafdd367c0c5e2cb934d27bf4f3262bce5
40b00316560c6a8a98bea3d9e4d3063b11cb872b
refs/heads/master
2020-12-25T18:43:03.578398
2017-08-04T14:08:56
2017-08-04T14:08:56
93,980,664
1
0
null
null
null
null
UTF-8
C++
false
false
1,420
h
LineNoPhase.h
// ----------------------------------------------------------------- // This is the header for the LineNoPhase class. // ----------------------------------------------------------------- #pragma once #include "phase.h" #include "..\DataStructures\Nodes\nodes.h" using namespace std; // ---------------------------------------------------------- // This class represents a visitor for setting line numbers. // // Version 3.0 // ---------------------------------------------------------- class LineNoPhase : public Phase { private: int lineCount; // a counter for current line number int getLineCount() { return lineCount; } public: LineNoPhase() { lineCount = 0; } void visit(ProgramNode * n); void visit(JmpStmtNode * n); void visit(IfNode * n); void visit(IdRefNode * n){} void visit(AssigningNode * n){} void visit(FunctionCallNode * n){} void visit(CommandCallNode * n){} void visit(ArgListNode * n){} void visit(StringConstingNode * n){} void visit(DoubleConstingNode * n){} void visit(AddingNode * n){} void visit(SubingNode * n){} void visit(MulingNode * n){} void visit(DivingNode * n){} void visit(ModDivingNode * n){} void visit(IDivingNode * n){} void visit(RootingNode * n){} void visit(ExpingNode * n){} void visit(NotingNode * n){} void visit(LTingNode * n){} void visit(GTingNode * n){} void visit(EQingNode * n){} void visit(LTEingNode * n){} void visit(GTEingNode * n){} };
96e9cc10dd5c48e6610855edf62765539d01574a
fbead5635dee647e6fd57fa1b307c3639b4d895c
/Week5/Word_Break_II/solution.cpp
4b1879cd56d99dedcc64139431f4e94129b23f77
[ "MIT" ]
permissive
AkashRajpurohit/leetcode-july-2020-challenge
c26300036a62f8fd7e928ee2c07fec2207067b0e
27665ef0776b028fba588a6899a4abafa5e4afff
refs/heads/master
2023-01-04T00:10:49.057931
2020-11-01T05:56:46
2020-11-01T05:56:46
276,367,685
2
0
null
null
null
null
UTF-8
C++
false
false
1,181
cpp
solution.cpp
class Solution { private: vector<string> wordBreakHelper(string s, unordered_set<string>& wordSet, unordered_map<string,vector<string>>& map) { if(map.find(s) != map.end()) return map[s]; vector<string> result; if(s.empty()) { result.push_back(""); return result; } for(int i = 1; i <= s.size(); ++i) { string left = s.substr(0, i); if(wordSet.find(left) != wordSet.end()) { vector<string> subList = wordBreakHelper(s.substr(i), wordSet, map); for(string sen: subList) { sen = sen.empty() ? sen : " " + sen; result.push_back(left + sen); } } } map[s] = result; return result; } public: vector<string> wordBreak(string s, vector<string>& wordDict) { unordered_set<string> wordSet; unordered_map<string,vector<string>> map; for(string word: wordDict) wordSet.insert(word); return wordBreakHelper(s, wordSet, map); } };
08198cbb61bba9c0c2dd44f1c68fde2356b90da8
5d253c51099f386dd5d25a3752fec65f9511d265
/T - Binary Treee/NJNUxzl.cpp
6f82b14fb06b2746da34036a5de8332adb4ee956
[]
no_license
NJUwuxiaotong/NJNU-CS-20
6f43db90cbf3ce895bd8bbeb41ed883634ae5b05
2cc14afc3d7ae3e055efe9d370afa0e86fffed79
refs/heads/main
2023-03-21T04:57:16.600970
2021-03-19T06:22:35
2021-03-19T06:22:35
319,336,533
1
5
null
2021-03-19T06:22:36
2020-12-07T13:58:23
C++
GB18030
C++
false
false
1,395
cpp
NJNUxzl.cpp
#include<stdio.h> #include<stdlib.h> #include<ctype.h> typedef struct BiTNode { int data; struct BiTNode *lchild,*rchild; }Node; Node *CreateBiTree() { Node *p; int a; scanf("%d",&a); if(a==0) { p=NULL; } else { p=(BiTNode *)malloc(sizeof(BiTNode)); p->data=a; p->lchild=CreateBiTree(); p->rchild=CreateBiTree(); } return p; } void Preorder(Node *p) { if(p) { printf("%d ",p->data); Preorder(p->lchild); Preorder(p->rchild); } } int chf(int n) { int i,m=1; if(n==0) return 1; else for(i=1;i<=n;i++) m*=2; return m; } void CreateBiTree2(int q[]) { char c; int i = 0; int n = 0; printf("请输入:"); while ((c = getchar()) != '\n') { if (isdigit(c)) { ungetc(c, stdin); scanf("%d", &q[n++]); } } } void Adjust(int q[]) { int i=0,t; for(i=2;q[i]!=0;i=i+2) { t=q[i]; q[i]=q[i-1]; q[i-1]=t; } } void Forder(int q[]) { int i,j,n=0; for(i=0;i<100;i++) { for(j=0;j<chf(i);j++) { if(q[n]==0) break; printf("%d ",q[n]); n++; } printf("\n"); if(q[n]==0) break; } } int main() { int a[100]={0}; Node *p; printf("层序遍历:\n"); CreateBiTree2(a); Adjust(a); Forder(a); printf("前序遍历:"); printf("请输入(输入时请用0将二叉树补成满二叉树):"); p=CreateBiTree(); Preorder(p); return 0; }
9f57047c96d1181f14c9f5eab9d0d37699375410
b34e6d6acf20e5e8b2edf1985ec6cbdfc74f574c
/src/PSO2TestPlugin.cpp
1f935e3de43068ce0fd3d2afd5a15ee519ffe6a1
[ "MIT" ]
permissive
karashiiro/PSO2TestPlugin
c883aa1a9980b3e6c5e90f8b7328f2fa9019d685
a80d33566f931f2551fc43534a2701c778dc496e
refs/heads/main
2023-03-20T03:21:20.294745
2021-03-17T23:18:50
2021-03-17T23:18:50
331,432,903
0
0
MIT
2021-03-17T23:16:30
2021-01-20T21:09:14
C++
UTF-8
C++
false
false
6,859
cpp
PSO2TestPlugin.cpp
#include "PSO2TestPlugin.h" #include "resources.h" #include "Util.h" #include "Web.h" #include "backends/imgui_impl_dx11.h" #include "backends/imgui_impl_win32.h" #include "d3d11.h" #include "detours.h" #include "imgui.h" #include "nlohmann/json.hpp" using namespace PSO2TestPlugin; typedef HRESULT(WINAPI *CreateDeviceAndSwapChain)(IDXGIAdapter *pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, UINT Flags, const D3D_FEATURE_LEVEL *pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, const DXGI_SWAP_CHAIN_DESC *pSwapChainDesc, IDXGISwapChain **ppSwapChain, ID3D11Device **ppDevice, D3D_FEATURE_LEVEL *pFeatureLevel, ID3D11DeviceContext **ppImmediateContext); typedef HRESULT(__fastcall *Present)(IDXGISwapChain *swapChain, UINT syncInterval, UINT flags); struct D3D11VTable { Present Present; }; static WNDPROC gameWindowProc = nullptr; static CreateDeviceAndSwapChain oCreateDeviceAndSwapChain; static IDXGISwapChain *stolenSwapChain; static ID3D11Device *device; static ID3D11DeviceContext *context; static ID3D11RenderTargetView *mainRenderTargetView; static D3D11VTable *d3d11VTable; static bool show = false; extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK HookedWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam); if (uMsg == WM_KEYDOWN && wParam == VK_DELETE) { show = !show; } if (ImGui::GetIO().WantCaptureMouse && uMsg != WM_MOUSEMOVE) { return TRUE; } return CallWindowProc(gameWindowProc, hWnd, uMsg, wParam, lParam); } D3D11VTable* BuildD3D11VTable(IDXGISwapChain *swapChainFrom) { auto dxVTable = reinterpret_cast<DWORD_PTR*>(swapChainFrom); dxVTable = reinterpret_cast<DWORD_PTR*>(dxVTable[0]); auto oPresent = reinterpret_cast<Present>(dxVTable[8]); auto dxVTableCopy = new D3D11VTable{oPresent}; return dxVTableCopy; } void InitImGui() { auto gameHWnd = Util::GetGameWindowHandle(); IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGui::StyleColorsDark(); ImGui::CaptureMouseFromApp(); ImGui::GetIO().IniFilename = PSO2TestPlugin::IniFilename; ImFontConfig cfg; cfg.FontDataOwnedByAtlas = false; ImGui::GetIO().Fonts->AddFontFromMemoryTTF((void*)open_sans_ttf, static_cast<int>(open_sans_ttf_size), 14, &cfg); gameWindowProc = reinterpret_cast<WNDPROC>(SetWindowLongPtr(gameHWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(HookedWndProc))); ImGui_ImplWin32_Init(gameHWnd); ImGui_ImplDX11_Init(device, context); ImGui::GetIO().ImeWindowHandle = gameHWnd; ID3D11Texture2D *backBuffer; stolenSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<LPVOID*>(&backBuffer)); device->CreateRenderTargetView(backBuffer, nullptr, &mainRenderTargetView); backBuffer->Release(); } HRESULT WINAPI HookedPresent(IDXGISwapChain *swapChain, UINT syncInterval, UINT flags) { if (gameWindowProc == nullptr) { InitImGui(); } ImGui_ImplDX11_NewFrame(); ImGui_ImplWin32_NewFrame(); ImGui::NewFrame(); ImGui::GetIO().MouseDrawCursor = ImGui::GetIO().WantCaptureMouse; if (show) { DrawManager->Execute(); } ImGui::Render(); context->OMSetRenderTargets(1, &mainRenderTargetView, nullptr); ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); return d3d11VTable->Present(swapChain, syncInterval, flags); } HRESULT HookedD3D11CreateDeviceAndSwapChain(IDXGIAdapter *pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, UINT Flags, const D3D_FEATURE_LEVEL *pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, const DXGI_SWAP_CHAIN_DESC *pSwapChainDesc, IDXGISwapChain **ppSwapChain, ID3D11Device **ppDevice, D3D_FEATURE_LEVEL *pFeatureLevel, ID3D11DeviceContext **ppImmediateContext) { auto res = oCreateDeviceAndSwapChain(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, pSwapChainDesc, ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext); if (SUCCEEDED(res)) { stolenSwapChain = *ppSwapChain; device = *ppDevice; context = *ppImmediateContext; d3d11VTable = BuildD3D11VTable(stolenSwapChain); DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); DetourAttach(&reinterpret_cast<PVOID&>(d3d11VTable->Present), reinterpret_cast<PVOID>(HookedPresent)); DetourTransactionCommit(); } return res; } BOOL WINAPI PSO2TestPlugin::Hook() { DrawManager = new Interface::InterfaceManager(); Initialize(); oCreateDeviceAndSwapChain = &D3D11CreateDeviceAndSwapChain; DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); DetourAttach(&reinterpret_cast<PVOID&>(oCreateDeviceAndSwapChain), reinterpret_cast<PVOID>(HookedD3D11CreateDeviceAndSwapChain)); DetourTransactionCommit(); return TRUE; } void PSO2TestPlugin::Initialize() { auto res = Web::Request(L"xivapi.com", L"/Item/30374", true, L"GET"); std::string raw(res.begin(), res.end()); auto data = nlohmann::json::parse(raw); auto itemName = data["Name"].get<std::string>(); static auto text = Util::JoinStrings("the text: ", itemName); DrawManager->AddHandler([] { ImGui::Begin("a very cool window", &show, ImGuiWindowFlags_AlwaysAutoResize); ImGui::Text("hm hmm, some very nice text"); ImGui::Text("%s", text.c_str()); ImGui::End(); }); }
1874341cf7028e8605356c62c0ef6343f40da4ea
069cd61631f8870162807d511ee9eea4a8a35f20
/src/solvers/flattening/boolbv_let.cpp
d14aa8487c6ad9dc976dacc37b93e1e9bba15b0b
[ "BSD-2-Clause", "LicenseRef-scancode-unknown-license-reference", "BSD-4-Clause" ]
permissive
angelhof/cbmc
6ba1ff59525e8eb8b88f4dd0cb3729f27dea7d4e
5c49b127da1658eb5413ce981fb4049d6d39e8be
refs/heads/develop
2020-06-08T04:15:24.437252
2019-06-21T12:07:45
2019-06-21T12:07:45
193,155,011
0
0
NOASSERTION
2019-07-10T15:17:42
2019-06-21T20:13:34
C++
UTF-8
C++
false
false
908
cpp
boolbv_let.cpp
/*******************************************************************\ Module: Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ #include "boolbv.h" #include <util/std_expr.h> #include <util/std_types.h> bvt boolbvt::convert_let(const let_exprt &expr) { const bvt value_bv=convert_bv(expr.value()); // We expect the identifiers of the bound symbols to be unique, // and thus, these can go straight into the symbol to literal map. // This property also allows us to cache any subexpressions. const irep_idt &id=expr.symbol().get_identifier(); // the symbol shall be visible during the recursive call // to convert_bv map.set_literals(id, expr.symbol().type(), value_bv); bvt result_bv=convert_bv(expr.where()); // now remove, no longer needed map.erase_literals(id, expr.symbol().type()); return result_bv; }
915331a8586726ba4a36300561629909258c76e8
8f8ede2d240cafa0b17f135c553a2ae64e6ea1bd
/voice/tts/ttslib/engine/TTS_Engine.cpp
9f8695b3787f6c5c926f9ac1cb589850e1804568
[]
no_license
hyCpp/MyDemo
176d86b720fbc9619807c2497fadb781f5dc4295
150c77ebe54fe7b7f60063e6488319d804a07d03
refs/heads/master
2020-03-18T05:33:37.338743
2019-03-10T04:21:01
2019-03-10T04:21:01
134,348,743
0
0
null
null
null
null
UTF-8
C++
false
false
2,633
cpp
TTS_Engine.cpp
/** * Copyright @ 2014 - 2017 Suntec Software(Shanghai) Co., Ltd. * All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are NOT permitted except as agreed by * Suntec Software(Shanghai) Co., Ltd. * * 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. */ #include "TTS_Engine.h" #include "CL_WaitObj.h" TTS_EngineBuffers::TTS_EngineBuffers() : m_readPos(0), m_writePos(0), m_stop(false), m_phraseFinish(false) { m_buffers.resize(m_size); } TTS_EngineBuffers::~TTS_EngineBuffers() { } void TTS_EngineBuffers::Clear() { m_readPos = 0; m_writePos = 0; m_stop = false; m_phraseFinish = false; m_writeObj.Reset(); m_readObj.Reset(); } void TTS_EngineBuffers::NewPlayer() { m_readPos = 0; m_writePos = 0; m_phraseFinish = false; } BYTE* TTS_EngineBuffers::GetWriteBuffer(int& nLen) { int freeSize = m_size - (m_writePos - m_readPos); while (freeSize <= 0) { if (m_stop || m_phraseFinish) { return NULL; } m_writeObj.Wait(); freeSize = m_size - (m_writePos - m_readPos); } if (m_stop || m_phraseFinish) { return NULL; } int nPhysicWritePos = m_writePos % m_size; if ((nPhysicWritePos + freeSize) > m_size) { freeSize = m_size - nPhysicWritePos; } nLen = freeSize > m_fragSize ? m_fragSize : freeSize; return &(*(m_buffers.begin())) + nPhysicWritePos; } BYTE* TTS_EngineBuffers::GetReadBuffer(int& nSize) { int len = m_writePos - m_readPos; while (len < m_fragSize) { if (m_stop || m_phraseFinish) { break; } m_readObj.Wait(); len = m_writePos - m_readPos; } int nPhysicReadPos = m_readPos % m_size; if (nPhysicReadPos + len > m_size) { len = m_size - nPhysicReadPos; } nSize = m_fragSize > len ? len : m_fragSize; return &(*(m_buffers.begin())) + nPhysicReadPos; } void TTS_EngineBuffers::SetWriteLen(const int& len) { m_writePos += len; m_readObj.Notify(); } void TTS_EngineBuffers::SetReadLen(const int& len) { m_readPos += len; m_writeObj.Notify(); } void TTS_EngineBuffers::Stop() { m_stop = true; m_writeObj.Notify(); m_readObj.Notify(); } void TTS_EngineBuffers::FinishPhrase() { m_phraseFinish = true; m_writeObj.Notify(); m_readObj.Notify(); } bool TTS_EngineBuffers::IsStop() { return m_stop; } /* EOF */
b74ed89b744ce36b211e63254a023c1a8392a7b5
cee5be19cff7fd682235e8c059e7a6afe29b3001
/sprint00/t07/src/inventory.h
215f3604c122a6b46be5281e46851f326f67a236
[]
no_license
nsubbotin/Cpp_Marathon
d61de8508a23d620218ddaf355d3d54564991d94
676c6bbd40abf59af3649ffb2af4aef38af383ed
refs/heads/master
2023-08-19T20:51:35.075266
2021-10-19T09:08:29
2021-10-19T09:08:29
413,491,380
0
0
null
null
null
null
UTF-8
C++
false
false
716
h
inventory.h
#include <string> #include <iostream> #include <sstream> #include <map> #include <vector> #include <algorithm> void CheckEnd(std::stringstream &ss); void CheckEnd(std::stringstream &ss, std::string &type); void CheckItemType(const std::string &type); void CheckItemOccurrence(const std::string &type, std::vector<std::string> &inventory); void CheckSize(std::vector<std::string> &inventory); void Insert(const std::string &type, std::vector<std::string> &inventory); void Remove(const std::string &type, std::vector<std::string> &inventory); void Show(const std::vector<std::string> &inventory); void Help(void); void CheckCommand(bool &process, std::stringstream &ss, std::vector<std::string> &inventory);
e58b3630ca4a640a57b84959046e44aeafe939c7
25c9caacb5220e2bc34b5a1bc4934e602c11c9fe
/Classes/GameCommon/GameData.cpp
281ba4f96e0b8f37856051946a3d7e63c18ca284
[]
no_license
EasonGan/CocosPlane1.0
20b9870b1ddafa9aebbdaa63034d1de86e3fe18b
e19f1a1b538c5b1c2e746b929406cb80955cda41
refs/heads/master
2016-08-13T00:03:05.610683
2015-12-04T02:41:12
2015-12-04T02:41:12
46,762,770
3
1
null
null
null
null
UTF-8
C++
false
false
9,784
cpp
GameData.cpp
#include "GameData.h" #include "AudioEngine.h" #include "../GamePlaying/Bullet/BulletFactory.h" #include "../GamePlaying/Weapon/WeaponFactory.h" #include "../GamePlaying/BasePlane/BasePlane.h" #include "../GamePlaying/BasePlane/PlaneAction.h" #include "../GamePlaying/DropGoods.h" #include "../GamePlaying/BasePlane/PlaneManager.h" #include "../GamePlaying/Layer/UIController.h" #include "../GameUI/GameMainLayer.h" #include "../GamePlaying/Layer/PhysicsLayer.h" #include "EffectsManager.h" #include "../GamePlaying/BasePlane/PlaneFactory.h" #include "../GamePlaying/AI.h" #include "NewDataMgr.h" #include "GameConfig.h" #include "GameSystem.h" #include "../GamePlaying/Layer/RollingBg.h" #include "../GamePlaying/RapidParticle/ParticleManager.h" #include "../GamePlaying/Layer/CloudLayer.h" GameData::GameData() { m_winSize = Director::getInstance()->getWinSize(); m_bulletFactory = BulletFactory::create(); m_weaponFactory = WeaponFactory::create(); m_planefactory = PlaneFactory::create(); m_planeAiFactory = PlaneAIFactory::create(); m_PlaneAction = EnterAction::create(); m_scoreFactory = DropsFactory::create(); m_planeManager = PlaneManager::create(); m_mainPlane = nullptr; m_Playing = false; m_gamePause = false; m_GameResult = false; m_IsHurtByBoss = false; resetGameData(); } GameData::~GameData() { m_bulletFactory->purge(); m_weaponFactory->purge(); m_planefactory->purge(); m_planeAiFactory->purge(); m_planeManager->purge(); m_PlaneAction->purge(); m_scoreFactory->purge(); ParticleManager::getInstance()->purge(); } void GameData::addScore(const int& num ) { m_Score += num; UIController::getInstance()->getMainUILayer()->updateUIScore( m_Score ); } void GameData::AddEnemyPlane( PhysicsUnit* pu ) { m_EnemyPlaneVec.push_back(pu); } void GameData::DelEnemyPlane( PhysicsUnit* pu ) { std::list<PhysicsUnit*>::iterator it = m_EnemyPlaneVec.begin(); for (it; it != m_EnemyPlaneVec.end();) { PhysicsUnit* physicsunit = (*it); if (physicsunit == pu) { m_EnemyPlaneVec.erase(it); //log(" enemyPlane del "); break; } else { ++it; } } } void GameData::SortByDis() { std::list<PhysicsUnit*>::iterator it_i = m_EnemyPlaneVec.begin(); std::list<PhysicsUnit*>::iterator it_j = m_EnemyPlaneVec.begin(); for (it_i; it_i != m_EnemyPlaneVec.end(); ++it_i) { for (it_j = it_i; it_j != m_EnemyPlaneVec.end(); ++it_j) { Point pos_i = (*it_i)->getPosition(); Point pos_j = (*it_j)->getPosition(); float dis_i = getDistance(pos_i); float dis_j = getDistance(pos_j); if (dis_i > dis_j) { PhysicsUnit* temp = (*it_i); (*it_i) = (*it_j); (*it_j) = temp; } } } } float GameData::getDistance( const Point& pos ) { Vec2 vec = Vec2(m_winSize.width * 0.5, 0); BasePlane* plane = GameData::getInstance()->getMainPlane(); if (plane) { vec = plane->getPosition(); } float dis = pos.distance(vec); return dis; } void GameData::setMainPlane( MainPlane* plane ) { m_mainPlane = plane; } MainPlane* GameData::getMainPlane() { return m_mainPlane; } void GameData::GameStart() { resetGameData(); } void GameData::GameOver(bool iswin) { setGameResult(iswin); if (m_Playing) { m_Playing = false; if (!iswin) { UIController::getInstance()->getMainUILayer()->showBuyFuHuoWidget(); } else { auto pl = GameData::getInstance()->getMainPlane(); if (pl) { auto mianpl = (MainPlane*)pl; mianpl->FlyUp(); } } } } void GameData::resetGameData() { m_Golds = 0; m_Score = 0; m_updateSpeed = 5.0; m_mainPlane = nullptr; m_Playing = true; m_IsBossDead = false; m_IsJustShowMainPlane = false; m_IsRewardValid = true; m_planeManager->resetData(); m_EnemyPlaneVec.clear(); m_BossGrade.clear(); } void GameData::SortByHpLimit() { //log("begin target"); std::list<PhysicsUnit*>::iterator it_i = m_EnemyPlaneVec.begin(); std::list<PhysicsUnit*>::iterator it_j = m_EnemyPlaneVec.begin(); for (it_i; it_i != m_EnemyPlaneVec.end(); ++it_i) { for (it_j = it_i; it_j != m_EnemyPlaneVec.end(); ++it_j) { PhysicsUnit* pu_i = (*it_i); PhysicsUnit* pu_j = (*it_j); if (pu_i || pu_j) { continue; } float blood_i = (*it_i)->getBasePro().getMaxHp(); float blood_j = (*it_j)->getBasePro().getMaxHp(); if (blood_i < blood_i) { PhysicsUnit* temp = (*it_i); (*it_i) = (*it_j); (*it_j) = temp; } } } } PhysicsUnit* GameData::getEnemyPlaneByMaxHp() { if (m_EnemyPlaneVec.empty()) { return nullptr; } //log("********************** size = %d",m_EnemyPlaneVec.size()); auto it = m_EnemyPlaneVec.begin(); //for (it; it != m_EnemyPlaneVec.end(); ++it) //{ // PhysicsUnit* pu = (*it); // if (pu->getBasePro().isTarget && pu->isLiving()) // { // //log("+++locked+++"); // return pu; // } //} SortByHpLimit(); it = m_EnemyPlaneVec.begin(); for (it; it != m_EnemyPlaneVec.end(); ++it) { PhysicsUnit* pu = (*it); bool isWudi = pu->getBasePro().getIsInvincible(); if (!isWudi) { //BasePro pro = pu->getBasePro(); //rs.isTarget = true; //pu->setBasePro(pro); return pu; } } return nullptr; } const Vec2& GameData::getNearTargetByPos( const Vec2& curPos ) { Vec2 nearPos = Vec2(0,0); float dis = 100000.0f; auto plVec = m_EnemyPlaneVec; for (auto it = plVec.begin(); it != plVec.end(); it++) { auto pl = (*it); if (pl) { Vec2 pos = pl->convertToWorldSpaceAR(Vec2::ZERO); float TempDis = pos.distance(curPos); if (TempDis < dis) { dis = TempDis; nearPos = pos; } } } return nearPos; } void GameData::GamePause() { if (m_gamePause) { return; } m_gamePause = true; m_TargetSet = Director::getInstance()->getScheduler()->pauseAllTargets(); m_AllNodes = Director::getInstance()->getActionManager()->pauseAllRunningActions(); auto world = Director::getInstance()->getRunningScene()->getPhysicsWorld(); if (world) { world->setSpeed(0); } Director::getInstance()->getScheduler()->schedule(schedule_selector(GameData::update),this, 0.0f, false);//一定要设为false } void GameData::GameResume() { if (!m_gamePause) { return; } m_gamePause = false; Director::getInstance()->getScheduler()->unschedule(schedule_selector(GameData::update),this); Director::getInstance()->getScheduler()->resumeTargets(m_TargetSet); Director::getInstance()->getActionManager()->resumeTargets(m_AllNodes); Director::getInstance()->getRunningScene()->getPhysicsWorld()->setSpeed(1); m_TargetSet.clear(); m_AllNodes.clear(); } void GameData::GameSlowDown(float duration, bool isToBlack) { float rate = 0.3; Director::getInstance()->getScheduler()->setTimeScale(rate); ActionInterval* delay = DelayTime::create(duration*rate); CallFunc* func = CallFunc::create(this,callfunc_selector(GameData::GameResumeScale)); ActionInterval* seq = Sequence::create(delay,func,nullptr); Node* node = UIController::getInstance()->getPhysicsLayer(); node->runAction(seq); if (isToBlack) { UIController::getInstance()->getPhysicsLayer()->ToBlack(duration); } } void GameData::GameResumeScale() { Director::getInstance()->getScheduler()->setTimeScale(1.0f); } void GameData::addGoldNum(const int& num ) { this->m_Golds+= num; UIController::getInstance()->getMainUILayer()->updateUIGold( num ); } void GameData::GameSpeedUp() { //Director::getInstance()->getScheduler()->setTimeScale(1.5f); m_updateSpeed = 30.0f; UIController::getInstance()->getCloudLayer()->setIsSpeedUp(); } int GameData::getGoldNum() { return this->getGolds(); } int GameData::getEmemyNums() { return m_EnemyPlaneVec.size(); } bool GameData::isContact( int mask1,int mask2,int mask3, int mask4, int mask5,int mask6 ) { bool b = false; int v1 = mask1 & mask5; int v2 = mask1 & mask6; int v3 = mask4 & mask2; int v4 = mask4 & mask3; int v = mask1 & mask1; if (v1 && v2 && v3 && v4) { b = true; } return b; } bool GameData::isContact_P( int mask1,int mask2,int mask3, int mask4, int mask5,int mask6 ) { bool b = false; int v1 = mask1 & mask5; int v2 = mask1 & mask6; int v3 = mask4 & mask2; int v4 = mask4 & mask3; if (!v1 && v2 && !v3 && v4) { b = true; } return b; } bool GameData::isGameEnd() { bool b = m_planeManager->getIsGroupOver(); if (b && m_EnemyPlaneVec.empty()) { return true; } return false; } void GameData::addBossRecord(int bossType, const BossRating& rating, float SurvivlaTime) { BossGrade bg; bg.bossType = bossType; bg.rateing = rating; m_BossGrade.push_back(bg); setSurvivlaTime(SurvivlaTime); } std::vector<BossGrade>& GameData::getBossRecords() { return m_BossGrade; } void GameData::addProp() { } int GameData::getBulletHurtsOfEnemyPl(float userdata) { int curMapId = UIController::getInstance()->getGameBgMgr()->getCurBgId(); int curLvl = m_planeManager->getCurLvl(); float val1 = NewDataMgr::getInstance()->getEnemyPlaneWithKey()->AtkCoe1; float val2 = NewDataMgr::getInstance()->getEnemyPlaneWithKey()->AtkCoe2; int ammoHurts = -(pow((userdata * curLvl * curMapId), val1) + val2 * userdata); return ammoHurts; } void GameData::update( float t ) { Director::getInstance()->getActionManager()->update(t); } void GameData::setAllEnemyPlaneInvincible( bool isInvincible ) { for (auto it = m_EnemyPlaneVec.begin(); it != m_EnemyPlaneVec.end(); it++) { PhysicsUnit* pl = (*it); pl->setInvincible(isInvincible); } }
85d9b825e51ddf58dd897da2d1bcf134565fdae1
6a07acb66e5471519110eb1136474fe3006c94d8
/src/rendering/nodes/DiffuseGIProbeDebug.cpp
d4428365ddd982f690b2d0fd8e6cbe277589c0a1
[ "MIT" ]
permissive
liuyangvspu/ArkoseRenderer
df49bcbbcfcacf358b8ab6ac0dcdfaf2ab9880cb
609c99aa899e5f5b10f21f0d9aba54599128fff2
refs/heads/master
2023-07-17T14:22:15.156644
2021-08-31T22:43:30
2021-08-31T22:43:30
null
0
0
null
null
null
null
UTF-8
C++
false
false
4,735
cpp
DiffuseGIProbeDebug.cpp
#include "DiffuseGIProbeDebug.h" #include "CameraState.h" #include "ProbeDebug.h" #include "utility/Logging.h" #include "utility/Profiling.h" #include <imgui.h> std::string DiffuseGIProbeDebug::name() { return "diffuse-gi-probe-debug"; } DiffuseGIProbeDebug::DiffuseGIProbeDebug(Scene& scene) : RenderGraphNode(DiffuseGIProbeDebug::name()) , m_scene(scene) { } void DiffuseGIProbeDebug::constructNode(Registry& reg) { SCOPED_PROFILE_ZONE(); #if PROBE_DEBUG_VIZ == PROBE_DEBUG_VISUALIZE_COLOR m_probeData = reg.getTexture("diffuse-gi", "irradianceProbes").value(); #elif (PROBE_DEBUG_VIZ == PROBE_DEBUG_VISUALIZE_DISTANCE) || (PROBE_DEBUG_VIZ == PROBE_DEBUG_VISUALIZE_DISTANCE2) m_probeData = reg.getTexture("diffuse-gi", "filteredDistanceProbes").value(); #endif setUpSphereRenderData(reg); } RenderGraphNode::ExecuteCallback DiffuseGIProbeDebug::constructFrame(Registry& reg) const { SCOPED_PROFILE_ZONE(); Texture& depthTexture = *reg.getTexture("g-buffer", "depth").value(); Texture& colorTexture = *reg.getTexture("forward", "color").value(); RenderTarget& renderTarget = reg.createRenderTarget({ { RenderTarget::AttachmentType::Color0, &colorTexture, LoadOp::Load, StoreOp::Store }, { RenderTarget::AttachmentType::Depth, &depthTexture, LoadOp::Load, StoreOp::Discard } }); BindingSet& probeDataBindingSet = reg.createBindingSet({ { 0, ShaderStageFragment, m_probeData, ShaderBindingType::TextureSampler } }); Shader debugShader = Shader::createBasicRasterize("diffuse-gi/probe-debug.vert", "diffuse-gi/probe-debug.frag"); RenderStateBuilder stateBuilder { renderTarget, debugShader, VertexLayout { VertexComponent::Position3F }}; BindingSet& cameraBindingSet = *reg.getBindingSet("scene", "cameraSet"); stateBuilder.stateBindings().at(0, cameraBindingSet); stateBuilder.stateBindings().at(1, probeDataBindingSet); stateBuilder.writeDepth = true; stateBuilder.testDepth = true; RenderState& renderState = reg.createRenderState(stateBuilder); return [&](const AppState& appState, CommandList& cmdList) { SCOPED_PROFILE_ZONE(); static bool enabled = false; ImGui::Checkbox("Enabled##diffuse-gi", &enabled); static float probeScale = 0.05f; ImGui::SliderFloat("Probe size (m)", &probeScale, 0.01f, 1.0f); if (!enabled) return; cmdList.beginRendering(renderState); cmdList.setNamedUniform("probeScale", probeScale); cmdList.setNamedUniform("indirectExposure", m_scene.lightPreExposureValue()); for (int probeIdx = 0; probeIdx < m_scene.probeGrid().probeCount(); ++probeIdx) { auto probeIdx3D = m_scene.probeGrid().probeIndexFromLinear(probeIdx); vec3 probeLocation = m_scene.probeGrid().probePositionForIndex(probeIdx3D); cmdList.setNamedUniform("probeIdx", probeIdx); cmdList.setNamedUniform("probeLocation", probeLocation); cmdList.drawIndexed(*m_sphereVertexBuffer, *m_sphereIndexBuffer, m_indexCount, IndexType::UInt16); } cmdList.endRendering(); }; } void DiffuseGIProbeDebug::setUpSphereRenderData(Registry& reg) { constexpr int rings = 48; constexpr int sectors = 48; using namespace moos; std::vector<vec3> positions {}; std::vector<uint16_t> indices {}; { float R = 1.0f / (rings - 1); float S = 1.0f / (sectors - 1); for (int r = 0; r < rings; ++r) { for (int s = 0; s < sectors; ++s) { float y = std::sin(-(PI / 2.0f) + PI * r * R); float x = std::cos(TWO_PI * s * S) * std::sin(PI * r * R); float z = std::sin(TWO_PI * s * S) * std::sin(PI * r * R); positions.emplace_back(x, y, z); } } for (int r = 0; r < rings - 1; ++r) { for (int s = 0; s < sectors - 1; ++s) { int i0 = r * sectors + s; int i1 = r * sectors + (s + 1); int i2 = (r + 1) * sectors + (s + 1); int i3 = (r + 1) * sectors + s; indices.push_back(i2); indices.push_back(i1); indices.push_back(i0); indices.push_back(i3); indices.push_back(i2); indices.push_back(i0); } } m_indexCount = (uint32_t)indices.size(); } m_sphereVertexBuffer = &reg.createBuffer(std::move(positions), Buffer::Usage::Vertex, Buffer::MemoryHint::GpuOptimal); m_sphereIndexBuffer = &reg.createBuffer(std::move(indices), Buffer::Usage::Index, Buffer::MemoryHint::GpuOptimal); }
175154cc27ce8d627432c9b4ed868f81f385189d
95a19dc766385127568ffb16e1a85ac751634003
/picam/libs/core/src/picam_camera_dummy.hpp
eb0dd422c01a8225085017ce7b41792c9e207404
[ "MIT" ]
permissive
avribacki/neato-pi
bc90710fc04f08e356a1a956162d305f65a886ad
dd415f0f6ab82492468fedcafc85f18277fc7c06
refs/heads/master
2021-01-02T08:35:03.627973
2017-08-04T00:48:02
2017-08-04T01:30:30
99,021,824
0
0
null
null
null
null
UTF-8
C++
false
false
1,585
hpp
picam_camera_dummy.hpp
#ifndef PICAM_CAMERA_IMPL_H #define PICAM_CAMERA_IMPL_H #include "picam_camera.hpp" #include <thread> #include <mutex> #include <atomic> namespace PiCam { /*************************************************************************************************/ // Dummy camera implementation to use when MMAL is not found. class Camera::Impl { public: // Construct camera using supplied configuration. Impl(const picam_config_t& config); // Stop capturing. ~Impl(); // Set callback that will be called every time a new frame is availabe. void set_callback(void* user_data, picam_callback_t callback); // Get current parameters. const picam_params_t& parameters(); // Update parameters to new value. void set_parameters(const picam_params_t& params); private: // Loop that will periodically provide random images. void main_loop(); // Configuration supplied during construction. picam_config_t config_; // Parameters for image. Ignore by this dummy implementation. picam_params_t params_; // Callback set by the user and associated mutex. void* user_data_; picam_callback_t user_callback_; std::mutex user_mutex_; // Used to indicate if thread should keep running or stop. std::atomic<bool> keep_running_; // Threads responsible for asynchronous execution. std::thread main_thread_; }; /*************************************************************************************************/ } #endif //PICAM_CAMERA_IMPL_H
673ee06b584302b8be8917c9b2947c125c74cda5
a66fc6dc89d73dc2973c5ec175ac26369d013edd
/VulkanLerning/src/firstApp.h
c0bebf6c619d55c05332ce9e3aa84bf91ada12fd
[]
no_license
herniklanger/VulkanLearning
ad653feb6e3fceb6467ded8f481c5789232fcbf9
3e98930dad80bb69004260abe92e42d8c16399c9
refs/heads/main
2023-07-02T05:28:21.810835
2021-08-05T21:34:14
2021-08-05T21:34:14
391,289,236
0
0
null
null
null
null
UTF-8
C++
false
false
618
h
firstApp.h
#pragma once #include "window.h" #include "device.h" #include "Model.h" #include "GaneObject.h" #include "Renderer.h" #include <memory> #include <vector> namespace VulkanTest { class FirstApp { public: static constexpr int WIDTH = 800; static constexpr int HEIGHT = 600; FirstApp(); ~FirstApp(); FirstApp(const FirstApp&) = delete; FirstApp& operator=(const FirstApp&) = delete; void run(); private: void loadGameObjects(); Window window{ WIDTH, HEIGHT, "Hallow Vulkan!" }; Device device{ window }; Renderer renderer{ window, device }; std::vector<GameObject> gameObjects; }; }
64dd7b199027c6ac5c3b58cd5e4ca5b131b8f2ff
34e2954b6b31d2213593fdbc989788055dd10891
/fish/fish.ino
cf8b83c021ff3fcad99342556f5559e1f1ceb098
[]
no_license
alemolinata/ArduinoFishServo
77f7a902d68bf5d7bde24c53dca664a566f160ee
a00783e5bc40f4f42c71e8b72585f0165d0a7d7d
refs/heads/master
2021-01-01T17:15:45.529448
2015-03-18T11:36:37
2015-03-18T11:36:37
32,455,181
0
0
null
null
null
null
UTF-8
C++
false
false
3,696
ino
fish.ino
#include <Servo.h> #define myFish 9 #define sensorPin A0 #define numSensorReadings 10 Servo fishServo; int fishDirection = 45; int lightLimit = 800; unsigned long prevTimeFish; unsigned long prevTimeWater; unsigned long prevTimeSensor; unsigned int fishDelay = 200; unsigned int waterDelay = 50; unsigned int sensorDelay = 2; uint8_t waterPosition = 0; uint8_t portValue = 0; int sensorReadings[numSensorReadings];// the readings from the light sensor int sensorReadIndex = 0; // the index of the current reading int sensorTotal = 0; // the running total int sensorAverage = 0; // the average void setup() { // initialize port for water lights for(uint8_t id = 0; id < 8 ; id++){ pinMode(id, OUTPUT); } //Serial.begin(9600); // initializes servo fishServo.attach(myFish); fishServo.write(fishDirection); // initializes timers prevTimeFish = millis(); prevTimeWater = millis(); prevTimeSensor = millis(); // initializing values for sensor readings, setting initial value to 0 for (int thisReading = 0; thisReading < numSensorReadings; thisReading++) sensorReadings[thisReading] = 0; } void loop() { // gather the current time unsigned long curMS = millis(); // make lights move! so pretty! :) if(curMS - prevTimeWater > waterDelay){ if(waterPosition == 0){ portValue = B11000000; // start with the 2 first ones on }else if(waterPosition == 7){ portValue = B10000001; // at the end, shift the light to the beginning. }else{ portValue = portValue >> 1; //slide the ON lights } waterPosition ++; // change to the next position for the next time that this runs! if(waterPosition == 8){ waterPosition = 0; // never let it go over 7, because we only have 8 leds. } prevTimeWater = curMS; // store the current time, to use it next time the loop runs. } // set the lights on! PORTD = portValue; // gather info from the sensor only every 2 ms if(curMS - prevTimeSensor > sensorDelay){ sensorTotal = sensorTotal - sensorReadings[sensorReadIndex]; sensorReadings[sensorReadIndex] = analogRead(sensorPin); sensorTotal = sensorTotal + sensorReadings[sensorReadIndex]; sensorReadIndex++; if (sensorReadIndex >= numSensorReadings) sensorReadIndex = 0; sensorAverage = sensorTotal / numSensorReadings; //Serial.println(sensorAverage); // IF there is a lot of light, it means that the fish IS NOT in the water if (sensorAverage > lightLimit){ // since it's NOT IN the water, we want to make it "jittery" (stressed) fishDelay = 8; } // IF there is not a lot of light, it means that the fish IS in the water else{ // since it's IN the water, it is swimming happily fishDelay = 200; } prevTimeSensor = curMS; // store the current time, to use it next time the loop runs. } // this loop only runs as often as the light sensor tells it to run. Very often when there is a lot of light (fish not in water), // not so often when there is not much light (fish is in the water) if(curMS - prevTimeFish > fishDelay){ // if the fish is going towards 45 when the loop runs, SWITCH to 135 (go CW) if(fishDirection == 45){ fishDirection = 135; } // if the fish is going towards 135 when the loop runs, SWITCH to 45 (go CCW) else{ fishDirection = 45; } // actually tell the fish to move! fishServo.write(fishDirection); prevTimeFish = curMS; // store the current time, to use it next time the loop runs. } }
ab6d4f61e641b8f44371f34e8df9f722f68aadbe
fbe61d48fada2102c4baf3c368398b47bea60654
/baekjoon/DP/2193.cpp
8d76a7a011bb1dba2da4592d17ee3daf460521e7
[]
no_license
tjdgus3537/algorithm
44be894a0bd24f75062c3a40c9eb84afa6a29212
78c8a7aa714f4edefac252b60622bfbd2eb08069
refs/heads/master
2020-03-19T10:02:44.868336
2019-02-07T09:52:31
2019-02-07T09:52:31
136,338,645
1
0
null
null
null
null
UTF-8
C++
false
false
814
cpp
2193.cpp
#include <iostream> #include <cstdio> #include <cmath> using namespace std; //int를 쓰니까 오답이 나옴. long long을 써야 함 //90을 넣으면 정답이 880067194370816120 void solution(); int main() { #ifdef _DEBUG freopen("/home/ubuntu/workspace/input", "r", stdin); #endif solution(); return 0; } void solution() { //dp[n][0]은 n자리 이친수 중, 0으로 끝나는 수의 개수 //dp[n][1]은 n자리 이친수 중, 1로 끝나는 수의 개수 int N; long long dp[91][2]; dp[1][0] = 0; dp[1][1] = 1; dp[2][0] = 1; dp[2][1] = 0; cin >> N; for(int i = 3; i <= N; i++) { dp[i][0] = dp[i - 1][0] + dp[i - 1][1]; dp[i][1] = dp[i - 1][0]; } cout << dp[N][0] + dp[N][1]; }
88240f46e7c9429d601bbab4642a88ebb0af0312
9b727ccbf91d12bbe10adb050784c04b4753758c
/UVA/10054 - The Necklace.cc
1aceb6bd832d1bf8887ae258c8853c3a3e62b488
[]
no_license
codeAligned/acm-icpc-1
b57ab179228f2acebaef01082fe6b67b0cae6403
090acaeb3705b6cf48790b977514965b22f6d43f
refs/heads/master
2020-09-19T19:39:30.929711
2015-10-06T15:13:12
2015-10-06T15:13:12
null
0
0
null
null
null
null
UTF-8
C++
false
false
959
cc
10054 - The Necklace.cc
#include <cstdio> #include <cstring> const int MAXN=55; const int MAXM=1005; int map[MAXN][MAXN]; int deg[MAXN]; int ans[MAXM]; int n,m,cnt; int root; void find(int u) { for (int v=1; v<=n; v++) if (map[u][v]>0) { map[u][v]--; map[v][u]--; find(v); } ans[cnt++]=u; } int main() { int test; scanf("%d",&test); for (int cas=1; cas<=test; cas++) { memset(map,0,sizeof(map)); memset(deg,0,sizeof(deg)); n=0; scanf("%d",&m); for (int i=0; i<m; i++) { int u, v; scanf("%d%d", &u, &v); if (u>n) n=u; if (v>n) n=v; map[u][v]++; map[v][u]++; deg[u]++; deg[v]++; root=u; } bool flag=true; for (int i=1; i<=n; i++) if (deg[i]&1) flag=false; cnt=0; if (flag) find(root); printf("Case #%d\n",cas); if (!flag) printf("some beads may be lost\n"); else { for (int i=0; i<cnt-1; i++) printf("%d %d\n",ans[i],ans[i+1]); } if (cas<test) printf("\n"); } return 0; }
ed9791f1d727eb4896a56d7f8447e5bbf8d26d43
93718ec4ba75e3871768d6f142a13e1cc6adac4e
/cell/network.h
5e6c36e0bd09b1e12062b5394414fbf306b6c1bc
[]
no_license
dunnker/cell
aa6d236593c0d791056b9375ba03d22c8412f4a7
cb75125a9d96480bf93e17f7f66494bbdce887eb
refs/heads/master
2021-01-10T12:21:19.783844
2016-02-21T02:02:52
2016-02-21T02:02:52
49,540,430
0
0
null
null
null
null
UTF-8
C++
false
false
5,237
h
network.h
#pragma once #include <vector> namespace NeuralNetwork { struct Network { static const unsigned short int MAX_HIDDEN_COUNT = 100; static const unsigned short int MAX_HIDDEN_LAYERS = 5; const unsigned short int _inputCount; const unsigned short int _hiddenCount; const unsigned short int _outputCount; const unsigned short int _hiddenLayerCount; const unsigned short int _inputNodeCount; const unsigned short int _inputWeightCount; const unsigned short int _hiddenNodeCount; const unsigned short int _hiddenWeightCount; const unsigned short int _outputNodeCount; const unsigned short int _outputWeightCount; float** _inputWeights; // 2d array [_inputNodeCount][_inputWeightCount] float*** _hiddenWeights; // 3d array [_hiddenLayerCount - 1][_hiddenNodeCount][_weightCount] float** _outputWeights; // 2d array [_outputNodeCount][_outputWeightCount] float* _inputs; // array [_inputNodeCount]; also includes bias node so length is _inputCount + 1 float* _outputs; // array [_outputCount] length _outputCount NOT _outputNodeCount Network(unsigned short int inputCount, unsigned short int hiddenCount, unsigned short int outputCount, unsigned short int hiddenLayerCount = 1) : _inputCount(inputCount), _hiddenCount(hiddenCount), _outputCount(outputCount), _inputNodeCount(inputCount + 1), _inputWeightCount(hiddenCount), _hiddenLayerCount(hiddenLayerCount), _hiddenNodeCount(hiddenCount + 1), _hiddenWeightCount(hiddenCount), _outputNodeCount(hiddenCount + 1), _outputWeightCount(outputCount) { if (hiddenCount > MAX_HIDDEN_COUNT) throw "hiddenCount exceeds maximum allowable value"; _inputs = new float[_inputNodeCount]; _inputs[_inputNodeCount - 1] = 1.0f; // bias value _outputs = new float[_outputCount]; _inputWeights = new float*[_inputNodeCount]; for (int i = 0; i < _inputNodeCount; i++) { _inputWeights[i] = new float[_inputWeightCount]; } if (_hiddenLayerCount > 1) { _hiddenWeights = new float**[_hiddenLayerCount - 1]; for (int h = 0; h < _hiddenLayerCount - 1; h++) { _hiddenWeights[h] = new float*[_hiddenNodeCount]; for (int i = 0; i < _hiddenNodeCount; i++) { _hiddenWeights[h][i] = new float[_hiddenWeightCount]; } } } _outputWeights = new float*[_outputNodeCount]; for (int i = 0; i < _outputNodeCount; i++) { _outputWeights[i] = new float[_outputWeightCount]; } } ~Network() { delete[] _inputs; delete[] _outputs; for (int i = 0; i < _inputNodeCount; i++) delete[] _inputWeights[i]; delete[] _inputWeights; if (_hiddenLayerCount > 1) { for (int h = 0; h < _hiddenLayerCount - 1; h++) { for (int i = 0; i < _hiddenNodeCount; i++) delete[] _hiddenWeights[h][i]; delete[] _hiddenWeights[h]; } delete[] _hiddenWeights; } for (int i = 0; i < _outputNodeCount; i++) delete[] _outputWeights[i]; delete[] _outputWeights; } static bool CompareBounds(Network& network1, Network& network2) { return network1._inputCount == network2._inputCount && network1._hiddenCount == network2._hiddenCount && network1._outputCount == network2._outputCount && network1._hiddenLayerCount == network2._hiddenLayerCount; } }; class NetworkUtils { public: /// return random float between 0 and less than 1.0 static float GetRandomFloat(); /// A neural network with a single hidden layer has a set of weight values for inputs, and a set for outputs. /// Initialize those input and output weights to random values between the given range, e.g. -(range/2) to range/2 static void Initialize(Network& network, float range = 4.0f); /// Calculate the outputs for a neural network with a single hidden layer, given its inputs and weights static void FeedForward(Network& network); /// Apply a mutation to the weights of a network static void Mutate(Network& network, float mutationRate = 0.3f, float mutationRange = 1.0f); /// Initialize weight values in network by using a random portion of weights from parent1 and parent2 static void Crossover(Network& parent1, Network& parent2, Network& network); private: NetworkUtils(); // static class so make constructor private }; }
b60d2a91fdf4a278a3123168eea640fc5aeb0a0f
a75910ca28c9f70f46e8a0f31f114660ba8575f6
/homework_showdown/pixelParticlesSequencerLeap2/src/testApp.cpp
903602b9b5d56c12134be09b5f68041878838c52
[]
no_license
bschorr/schorr_algo_2013_CLEAN
77069b12991cb1815fe1e64f91aa55c637cf0c2b
4fab3252c4cf89baee28cf9685b28ce59a30e2b0
refs/heads/master
2020-12-24T17:54:49.748388
2013-12-16T23:37:41
2013-12-16T23:37:41
null
0
0
null
null
null
null
UTF-8
C++
false
false
9,957
cpp
testApp.cpp
#include "testApp.h" //-------------------------------------------------------------- void testApp::setup(){ ofSetFrameRate(60); ofSetVerticalSync(true); ofSetLogLevel(OF_LOG_VERBOSE); leap.open(); leap.setupGestures(); // we enable our gesture detection here //sequencer setup //ofSetWindowShape(ofGetScreenWidth(), ofGetScreenHeight()); //ofToggleFullscreen(); ofEnableBlendMode(OF_BLENDMODE_ADD); img.loadImage("texture2.png"); hue = 0; bri = 150; ofHideCursor(); //sequencer setup sender.setup("localhost", 6534); recvr.setup(6666); circle.set(ofGetWidth()/2, ofGetHeight()/2); rotation = 0; //Set the background to black ofBackground( 0 , 0 , 0 ) ; //Loop through all the rows for ( float i = 0 ; i < 360 ; i += 0.2) { ofColor color = ofColor::fromHsb(hue, 255, bri); //red pixel //color.g = pixels[index+1] ; //blue pixel //color.b = pixels[index+2] ; //green pixel int tempRadius = ofRandom(130, 150); int x = ofGetWidth()/2 + cos(i)*150; int y = ofGetHeight()/2 + sin(i)*150; particles.push_back( Particle ( ofPoint ( x, y ) , color) ) ; } ofSetFrameRate( 30 ) ; numParticles = particles.size() ; //Set spring and sink values cursorMode = 0 ; forceRadius = 100 ; friction = 0.85 ; springFactor = 0.12 ; springEnabled = true ; inc = 2; } //-------------------------------------------------------------- void testApp::update(){ simpleHands = leap.getSimpleHands(); leap.updateGestures(); // check for gesture updates for(int i = 0; i < simpleHands.size(); i++){ //simpleHands[i].debugDraw(); tempX = ofMap (simpleHands[i].handPos.x, -120.0, 120.0, 0, ofGetWindowWidth()); tempY = ofMap (simpleHands[i].handPos.y, 400, 100, 0, ofGetWindowHeight()); } //IMPORTANT! - tell ofxLeapMotion that the frame is no longer new. leap.markFrameAsOld(); //start sequencer update oscReceiver(); //sequencer update prevRotation = rotation; rotation += inc; hue += 1; if (rotation > 360) rotation = 0; if (rotation < 0) rotation = 360-rotation; if (hue > 255) hue = 0; ofPoint diff ; //Difference between particle and mouse float dist ; //distance from particle to mouse ( as the crow flies ) float ratio ; //Ratio of how strong the effect is = 1 + (-dist/maxDistance) ; const ofPoint mousePosition = ofPoint( tempX , tempY ) ; //Allocate and retrieve mouse values once. //Create an iterator to cycle through the vector std::vector<Particle>::iterator p ; for ( p = particles.begin() ; p != particles.end() ; p++ ) { ratio = 1.0f ; p->velocity *= friction ; //reset acceleration every frame p->acceleration = ofPoint() ; diff = mousePosition - p->position ; dist = ofDist( 0 , 0 , diff.x , diff.y ) ; //If within the zone of interaction if ( dist < forceRadius ) { ratio = -1 + dist / forceRadius ; //Repulsion if ( cursorMode == 0 ) p->acceleration -= ( diff * ratio) ; //Attraction else p->acceleration += ( diff * ratio ) ; } if ( springEnabled ) { //Move back to the original position p->acceleration.x += springFactor * (p->spawnPoint.x - p->position.x); p->acceleration.y += springFactor * (p->spawnPoint.y - p->position.y) ; } p->velocity += p->acceleration * ratio ; p->position += p->velocity ; p->defineAngleNote(); } } //-------------------------------------------------------------- void testApp::draw(){ //ofDisableLighting(); ofBackground(0); ofSetColor(200); for(int i = 0; i < simpleHands.size(); i++){ //simpleHands[i].debugDraw(); ofCircle (tempX, tempY, 3); } //sequencer draw vector<Particle>::iterator p ; for ( p = particles.begin() ; p != particles.end() ; p++ ) //for ( int i = 0 ; i < particles.size() ; i++ ) { //playing the notes play = false; if (prevRotation <= int(p->angle) && rotation >= int(p->angle) && abs(rotation - prevRotation) < abs (inc*2)) play = true; if (prevRotation >= int(p->angle) && rotation <= int(p->angle) && abs(rotation - prevRotation) < abs(inc*2)) play =true; p->color.setHue(hue); if (play == true) { p->color.a = 255; p->color.setBrightness(255); p->color.setSaturation(255); p->size = 30; ofxOscMessage message; message.setAddress("/playtone"); message.addIntArg( p->note ); sender.sendMessage(message); } else { p->color.setBrightness(p->color.getBrightness()-10); p->color.setSaturation(p->color.getSaturation()+10); p->size -= 0.5; p->color.a -= 10; } if (p->color.a < 80) p->color.a = 80; if (p->color.getBrightness() < 150) p->color.setBrightness(150); if (p->color.getSaturation() > 200) p->color.setSaturation(200); if (p->size < 10) p->size=10; // draw the particles ofSetColor((unsigned char)p->color.r,(unsigned char)p->color.g,(unsigned char)p->color.b, (unsigned char)p->color.a); img.draw(p->position.x, p->position.y, p->size, p->size); } ofSetColor ( 255 , 255 , 255 ) ; string output = "S :: Springs on/off : " + ofToString(springEnabled) + "\n C :: CursorMode repel/attract " + ofToString( cursorMode ) + "\n # of particles : " + ofToString( numParticles ) + " \n fps:" +ofToString( ofGetFrameRate() ); if (debugtext)ofDrawBitmapString(output ,20,666); ofSetColor(255, 100); ofCircle (mouseX, mouseY, 5, 5); switch ( leap.iGestures ) { case 3: springEnabled = true ; break ; case 4: springEnabled = false ; break ; } } //-------------------------------------------------------------- void testApp::keyPressed(int key){ switch ( key ) { case 'c': case 'C': cursorMode = ( cursorMode + 1 > 1 ) ? 0 : 1 ; break ; case 2: springEnabled = !springEnabled ; break ; case 't': case 'T': debugtext = !debugtext ; break ; } } //-------------------------------------------------------------- void testApp::keyReleased(int key){ } //-------------------------------------------------------------- void testApp::mouseMoved(int x, int y ){ } //-------------------------------------------------------------- void testApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void testApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void testApp::dragEvent(ofDragInfo dragInfo){ } //-------------------------------------------------------------- void testApp::exit(){ // let's close down Leap and kill the controller leap.close(); } void testApp::oscReceiver () { ofxOscMessage message; recvr.getNextMessage(&message); string address = message.getAddress(); cout << "message address: " << message.getAddress() << endl; cout << "message num arguments: " << message.getNumArgs() << endl; for (int i = 0; i < message.getNumArgs(); i++){ cout << "argument " << i << " is type " << message.getArgTypeName(i); if (message.getArgType(i) == OFXOSC_TYPE_FLOAT){ if (address.compare("/1/speed")== 0)inc = message.getArgAsFloat(i); if (address.compare("/1/spring")== 0)springEnabled =message.getArgAsFloat(i); if (address.compare("/1/repel")== 0)cursorMode = message.getArgAsFloat(i); if (address.compare("/1/radius")== 0) { std::vector<Particle>::iterator p ; for ( p = particles.begin() ; p != particles.end() ; p++ ) { p->spawnPoint.x = ofGetWidth()/2 + cos(p - particles.begin() )* message.getArgAsFloat(i); p->spawnPoint.y = ofGetHeight()/2 + sin(p - particles.begin() )* message.getArgAsFloat(i); } } ; cout << " val = " << message.getArgAsFloat(i) << endl; } else if (message.getArgType(i) == OFXOSC_TYPE_INT32){ cout << " val = " << message.getArgAsInt32(i) << endl; } else if (message.getArgType(i) == OFXOSC_TYPE_STRING){ cout << " val = " << message.getArgAsString(i) << endl; } } }
79b3a52dcf681d88ad74d8d695bc5c4be52346c5
02541cc23351b013278c1ba4b4c5301b71e597cb
/HOJ/107.cpp
f77587d34332d51505307a344a5a5a8a30a6ce01
[]
no_license
austin880625/problem_solving
d5ac0865405df6d613e408c996c8b875b500a85a
b76cfabcea6e750b9e97c2a66961760fe8d70cf9
refs/heads/master
2021-05-04T11:01:03.178708
2018-07-14T14:14:04
2018-07-14T14:14:04
43,396,070
0
0
null
null
null
null
UTF-8
C++
false
false
2,183
cpp
107.cpp
#include<iostream> #include<stdio.h> #include<queue> #define MAXN 1000005 #define ll long long int using namespace std; int C[MAXN]; int X[MAXN]; int F[MAXN]; int nxt[MAXN]; int prev[MAXN]; int N,M,A,B; int T; int ran() { static int x=20151103; return x=x*0xdefaced+1; } struct Node { int v,pri,sz; Node *ch[2]; Node(int _v){v=_v;pri=ran();ch[0]=ch[1]=NULL;sz=1;} void maintain() { sz=1; if(ch[0])sz+=ch[0]->sz; if(ch[1])sz+=ch[1]->sz; } }; int getsz(Node *&O){return O ? O->sz : 0;} void rotate(Node *&O,int d) { Node *T=O->ch[d^1]; O->ch[d^1]=T->ch[d]; T->ch[d]=O; O->maintain();T->maintain(); O=T; } void Insert(Node *&O,int v) { if(!O){O=new Node(v);return ;} int dir=(v<O->v ? 0 : 1); Insert(O->ch[dir],v); if(O->ch[dir]->pri > O->pri)rotate(O,dir^1); O->maintain(); } void Delete(Node *&O,int v) { if(O->v==v) { Node *P=O; if(!O->ch[0]) { O=O->ch[1]; delete P; } else if(!O->ch[1]) { O=O->ch[0]; delete P; } else { int dir=(O->ch[0]->pri > O->ch[1]->pri ? 1 : 0); rotate(O,dir);Delete(O->ch[dir],v); } } else { int dir=v<O->v ? 0:1; Delete(O->ch[dir],v); } if(O)O->maintain(); } int kth(Node *&O,int k) { int now=getsz(O->ch[0])+1; if(k==now)return O->v; int dir=k<now ? 0 : 1; return kth(O->ch[dir],k-dir*now); } Node *Treap; int main() { scanf("%d",&T); while(T--) { Treap=NULL; scanf("%d%d%d%d%d",&N,&M,&X[0],&A,&B); for(int i=1;i<=N;i++) { Insert(Treap,i); X[i]=((ll)A*(ll)X[i-1]+(ll)B)%M; C[i]=(((ll)X[i]+(ll)N-(ll)i)%((ll)N-i+1))+1; } for(int i=1;i<=N;i++) { int x=kth(Treap,C[i]); F[i]=x; Delete(Treap,x); } ll ans=0; ll t=1; printf("%lld\n",ans); } return 0; }
ab5bd46256144386b9e493143478eda64a8134e7
80cc56f6063132eb9a76f8b9207426226d3d7b28
/Labs9_1.cpp
90c4f83fdac89d7f8a22d9ed29defb6e4f7d9e2c
[]
no_license
hoatq-fptaptech/T2009M_LBEP
56417dfcd2453a0392daeda4687bdff362c21b81
cf2052c198e183c5eac24fba54932d90b3720488
refs/heads/master
2022-12-25T13:12:56.460903
2020-10-03T07:42:56
2020-10-03T07:42:56
294,846,229
0
2
null
null
null
null
UTF-8
C++
false
false
444
cpp
Labs9_1.cpp
#include <stdio.h> #include <string.h> int main(){ char s[20]; printf("Nhap chuoi: "); scanf("%s",s); int a=0,e=0,i=0,o=0,u=0; for(int j=0;j<strlen(s);j++){ if(s[j] == 'A'|| s[j]=='a') a++; else if(s[j]== 'E' || s[j] == 'e') e++; else if(s[j]== 'I' || s[j] == 'i') i++; else if(s[j]== 'O' || s[j] == 'o') o++; else if(s[j]== 'u' || s[j] == 'u') u++; } printf("a: %d; e: %d; i: %d; o: %d; u: %d;",a,e,i,o,u); }
ab30b5cb02fa4803a216fc3f4a33273d9fc9ef2f
e58389168cc5e49b6377a5e7716c1a6a870616b1
/examples/simple.cpp
26622c4ac1249f7335a910e3c53f2983c1082c99
[]
no_license
tafoca/lockfree-bdd
8b71de516cfb69b709960568d3a43ace066b8588
e0f8672fa03a510900edfa79b76659e79f314a36
refs/heads/master
2020-08-27T17:55:21.444009
2016-05-09T14:24:59
2016-05-09T14:24:59
null
0
0
null
null
null
null
UTF-8
C++
false
false
523
cpp
simple.cpp
#include <iostream> #include "bdd.h" #include "visualize.h" int main() { bdd_init(100, 100, 3); bdd_ptr a = ithvar(0); bdd_ptr b = ithvar(1); /* bdd_ptr c = ithvar(2); */ bdd_ptr result = bdd_or(a, b); /* bdd_ptr result = bdd_or(a, bdd_and(b, c)); */ /* bdd_node *result = bdd_or(a,b); */ bdd_graphviz(result); std::cout << countsat(result) << std::endl; std::vector<std::map<int, bool>> *sats = allsat(result); for (auto &sat : (*sats)) { print_sat(sat); } delete sats; return 0; }
31d5782a23d2d0cf5d3b27716d61829f16c216bf
6f154afa302efeac5256e82c973616c0a428d3d5
/src/main/strategy_engine_common/Math/ProbDistrnFunc.h
7991c88ad592861db04faea41a6e8cb1609c0de0
[]
no_license
clhongooo/trading_engine
2ff58cc5d6cf7bef0a619549a4b4d63f923483dd
d4d74ad7ba21caa01f49054d63cdd8b2317d1702
refs/heads/master
2020-06-03T21:38:44.509346
2019-07-05T10:16:24
2019-07-05T10:16:24
191,741,370
0
1
null
2019-06-13T10:23:32
2019-06-13T10:23:32
null
UTF-8
C++
false
false
3,428
h
ProbDistrnFunc.h
#ifndef PROBDISTRNFUNC_H_ #define PROBDISTRNFUNC_H_ #include "PCH.h" #include "Constants.h" #include "SDateTime.h" #include "STool.h" using namespace std; using namespace boost; class ProbDistrnFunc { public: enum { PRECISION = 3 }; ProbDistrnFunc(); virtual ~ProbDistrnFunc(); //-------------------------------------------------- // Direct manipulation of a prob distrn function //-------------------------------------------------- void Reset (){} void Reset (const unsigned long){} double GetPr (const unsigned long,const int,const unsigned long); void SetPr (const unsigned long,const int,const unsigned long,const unsigned long){} double GetPr (const unsigned long,const double,const double); void SetPr (const unsigned long,const double,const double,const double); bool CheckValidity (const unsigned long); void Normalize (const unsigned long){} bool SaveDistrnFuncToFile(const char *, const unsigned long); bool LoadDistrnFuncFrFile(const char *, const unsigned long); private: //-------------------------------------------------- // Format: // YYYYMMDDHHMM - As at Date // double - Price return // double - Cum Probability // Reading probability should be much more frequent than updating //-------------------------------------------------- map<unsigned long, map<unsigned long,unsigned long> > m_CumProb; map<unsigned long, boost::shared_mutex*> m_CumProbMutex; }; //-------------------------------------------------- // Prob Distribution Function Builder //-------------------------------------------------- class ProbDistrnFuncBld { public: enum { PRECISION = 3 }; enum Method { LINEAR, QUADRATIC, CUBICSPLINE }; ProbDistrnFuncBld(); virtual ~ProbDistrnFuncBld(); //-------------------------------------------------- // For building a new prob distrn by collecting stat //-------------------------------------------------- unsigned long GetAllCounts (const unsigned long); void AddCount (const unsigned long,const int){} void AddCount (const unsigned long,const double){} void EraseAllCounts (){} void EraseCounts (const unsigned long){} void SetLowerBound (const unsigned long,const unsigned long){} void SetUpperBound (const unsigned long,const unsigned long){} void SetLowerBound (const unsigned long,const double){} void SetUpperBound (const unsigned long,const double){} bool GenerateDistrnFunc (Method, const unsigned long); bool GetProbDistrnFunc (const unsigned long,ProbDistrnFunc &); private: //-------------------------------------------------- // Format: // YYYYMMDDHHMM - As at Date // double - Price return // double - Cum Probability // Reading probability should be much more frequent than updating //-------------------------------------------------- map<unsigned long, map<unsigned long,unsigned long> > m_CumProb; map<unsigned long, boost::shared_mutex*> m_CumProbMutex; }; #endif /* PROBDISTRNFUNC_H_ */
d00399db68034f2607ee8a65acb177fdbc3908a2
aa619e3ed85030cba9ff3ec4837da948f4883907
/ShadyTreeEngine/Components/PhysicsComponent.h
f827226e8febe6776a500500291dd74c529e93a6
[]
no_license
Cody-Duncan/ShadyTreeEngine2
6c5fb5d016cfdaab1b5007d2020589b12ed5c31d
5ace6a2e99c4cc3186c2cbf36d6c8bfd5c05d5bb
refs/heads/master
2020-04-06T05:20:28.272360
2019-07-17T06:16:03
2019-07-17T06:16:03
16,856,421
1
1
null
2019-07-17T06:16:08
2014-02-15T04:19:42
C++
UTF-8
C++
false
false
1,166
h
PhysicsComponent.h
#pragma once #include "GameObject\Component.h" #include "Resources\GraphicsResourceHandles.h" #include "Math\MathLib.h" #include "GameObject\ComponentTypeID.h" #include "Physics\BB.h" #include "DelegateFunc.h" #include "Messaging\ContactMessage.h" class PhysicsComponent : public Component { public: ST_API PhysicsComponent(void); ST_API PhysicsComponent(int _id, bool _active); ST_API ~PhysicsComponent(void); ST_API virtual void CloneFrom(Component* c); bool IsStatic; bool IsGhost; float Mass; float InvMass; float Restitution; Vector2 velocity; Vector2 acceleration; Vector2 force; Vector2 offset; BB* body; std::list<DelegateFunc> collisionDelegates; template <class T, void (T::*TMethod)(Message*)> void registerCollideHandler(T* object); ST_API void clearCollideHandlers(); void CollideEvent(ContactMessage* m); private: void InitialValues(); }; RegisterType(PhysicsComponent) template <class T, void (T::*TMethod)(Message*)> void PhysicsComponent::registerCollideHandler(T* object) { collisionDelegates.push_back(DelegateFunc::from_method<T, TMethod>(object)); }
bab968c1a43cfb9ead683dbfa8ba8605814572df
2960167ca6fba5c49fcdf7fa4353017e1566246f
/Programming/Vladislav_Pustovoitenko/1/Individyalka1/CFraction.h
f068f1e8ef80bfa4c5cd9bd8331d2ede16597e94
[]
no_license
FriedrichFrankenstein/A.19-Green
ed95e28a0e6bbaa48d24db372642ad97d6b42772
1444c54e0400bbc3ab4ed4eac058691d4407421d
refs/heads/master
2020-07-29T20:37:21.584748
2019-10-16T13:39:42
2019-10-16T13:39:42
209,950,683
5
0
null
null
null
null
UTF-8
C++
false
false
635
h
CFraction.h
#ifndef CFRACTION_H_INCLUDED #define CFRACTION_H_INCLUDED #include <iostream> using namespace std; class CFraction { public: CFraction(){}; CFraction(unsigned long int,unsigned long int); void operator=(const CFraction&); CFraction operator+(const CFraction&); CFraction operator-(const CFraction&); CFraction operator*(const CFraction&); CFraction operator/(const CFraction&); operator int(); operator double(); string ToString(); friend ostream& operator<<(ostream&,CFraction&); friend istream& operator>>(istream&,CFraction&); protected: unsigned long int a=0; unsigned long int b=1; private: }; #endif // CFRACTION_H_INCLUDED
35800901086e96c3e50d2958236e8d17f2b96e2c
81919bd66da74363bc064fd88ef31fd4c33bcd2d
/thread_counter.h
0e6c2b6d148aa741f2064af8ef94587291c796b2
[]
no_license
jussimaki/Sequencer-2017
0e88e010fc0af6ac5a90e38ab6ee609fc4705b82
031f3a7de01791c1ce7e09eb141eb934f4276469
refs/heads/master
2022-10-13T13:27:49.779023
2020-06-08T18:00:41
2020-06-08T18:00:41
270,768,781
0
0
null
null
null
null
UTF-8
C++
false
false
773
h
thread_counter.h
#ifndef THREAD_COUNTER_H #define THREAD_COUNTER_H class ThreadCounter { public: ThreadCounter(std::atomic <int> *pointer) : pointer_(pointer) { std::cout << "thread++"; int oldValue, newValue; do { oldValue = (*pointer_).load(); newValue = oldValue + 1; } while(!(*pointer_).compare_exchange_weak(oldValue, newValue, std::memory_order_acquire)); } ~ThreadCounter() { std::cout << "thread--"; int oldValue, newValue; do { oldValue = (*pointer_).load(); newValue = oldValue - 1; } while (!(*pointer_).compare_exchange_weak(oldValue, newValue, std::memory_order_acquire)); } int getCount() { return (*pointer_).load(); } private: std::atomic <int> *pointer_; }; #endif
c28af7dc24c8d9b8c83cfffe22c71cda5ab7df06
b8a3aa80928d647c88fde7bc47cb50b4f5406855
/ckdgus0505/ACM/9372.cpp
38bc18fd2f721c9037663d0445be66b16d553cd7
[]
no_license
ckdgus0505/ACM
9eded656a0703d39ed8cb4f48e450df88fc25268
03a78f5018242f9e06dc681711540c1daed8ee52
refs/heads/master
2021-07-10T18:22:50.530584
2020-08-01T19:43:28
2020-08-01T19:43:28
176,450,497
0
0
null
null
null
null
UTF-8
C++
false
false
291
cpp
9372.cpp
#include<iostream> using namespace std; int T; int N, M; int main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> T; for (int i = 0; i < T; i++) { cin >> N >> M; for (int j = 0; j < M; j++) { int a, b; cin >> a >> b; } cout << N - 1 << '\n'; } return 0; }
511d2fa3bead5ece743ad92cceb55150d454e39c
a24a0fd51c5e98e93355acf1adf5bccacc3e94b8
/src/SerialModbusClient.cpp
aff052c78a70b1a5ab777793f7b8559bdc61baff
[ "MIT" ]
permissive
legicore/SerialModbus
0258eba015c00debb6c4a16fb4c6ebf1f2e875d5
0c854a54df519aab5eb37bbec75640b2cd43d89c
refs/heads/master
2023-08-07T07:22:38.730989
2023-08-06T13:54:36
2023-08-06T13:54:36
147,487,345
6
1
MIT
2018-09-14T03:58:35
2018-09-05T08:44:13
C++
UTF-8
C++
false
false
27,958
cpp
SerialModbusClient.cpp
//////////////////////////////////////////////////////////////////////////////// /** * @file SerialModbusClient.cpp * * @author Martin Legleiter * * @brief TODO * * @copyright (c) 2023 Martin Legleiter * * @license Use of this source code is governed by an MIT-style * license that can be found in the LICENSE file or at * @see https://opensource.org/licenses/MIT. */ //////////////////////////////////////////////////////////////////////////////// #include <stdint.h> #include <string.h> #include <stdbool.h> #include <ctype.h> #include "SerialModbusConfig.h" #include "SerialModbusBase.h" #include "SerialModbusClient.h" #include <Arduino.h> /*-----------------------------------------------------------*/ SerialModbusClient::SerialModbusClient() { xState = CLIENT_IDLE; pxRequestMap = NULL; xRequestMapIndex = 0; pxRequest = NULL; bSkipRequestMap = false; ulTurnaroundDelayUs = configTURNAROUND_DELAY_US; ulResponseTimeoutUs = configRESPONSE_TIMEOUT_US; ulTimerResponseTimeoutUs = 0; ulTimerTurnaroundDelayUs = 0; xStatusSimpleAPI = OK; } /*-----------------------------------------------------------*/ void SerialModbusClient::vSetState( MBClientState_t xStatePar ) { xState = xStatePar; } /*-----------------------------------------------------------*/ void SerialModbusClient::vStartTurnaroundDelay( void ) { ulTimerTurnaroundDelayUs = micros(); } /*-----------------------------------------------------------*/ void SerialModbusClient::vStartResponseTimeout( void ) { ulTimerResponseTimeoutUs = micros(); } /*-----------------------------------------------------------*/ bool SerialModbusClient::bTimeoutTurnaroundDelay( void ) { return ( micros() - ulTimerTurnaroundDelayUs ) >= ulTurnaroundDelayUs; } /*-----------------------------------------------------------*/ bool SerialModbusClient::bTimeoutResponseTimeout( void ) { return ( micros() - ulTimerResponseTimeoutUs ) >= ulResponseTimeoutUs; } /*-----------------------------------------------------------*/ void SerialModbusClient::setResponseTimeout( uint32_t timeMs ) { ulResponseTimeoutUs = timeMs * 1000; } /*-----------------------------------------------------------*/ void SerialModbusClient::setTurnaroundDelay( uint32_t timeMs ) { ulTurnaroundDelayUs = timeMs * 1000; } /*-----------------------------------------------------------*/ void SerialModbusClient::setRequestMap( const MBRequest_t * requestMap ) { pxRequestMap = requestMap; xRequestMapIndex = 0; } /*-----------------------------------------------------------*/ MBStatus_t SerialModbusClient::xProcessRequestMap( void ) { if( pxRequestMap != NULL ) { if( pxRequestMap[ xRequestMapIndex ].functionCode == 0x00 ) { xRequestMapIndex = 0; } return setRequest( &pxRequestMap[ xRequestMapIndex++ ], true ); } else { xRequestMapIndex = 0; } return OK; } /*-----------------------------------------------------------*/ MBStatus_t SerialModbusClient::setRequest( const MBRequest_t * request, bool requestMap ) { if( request == NULL ) { return xSetException( ILLEGAL_REQUEST ); } if( requestMap == false ) { bSkipRequestMap = true; } ( void ) xSetException( OK ); if( ( request->id > configID_SERVER_MAX ) || ( request->functionCode == 0x00 ) || ( request->dataSize == 0 ) ) { return xSetException( ILLEGAL_REQUEST ); } vClearRequestFrame(); pucRequestFrame[ 0 ] = request->id; pucRequestFrame[ 1 ] = request->functionCode; pucRequestFrame[ 2 ] = highByte( request->address ); pucRequestFrame[ 3 ] = lowByte( request->address ); switch( request->functionCode ) { #if( ( configFC03 == 1 ) || ( configFC04 == 1 ) ) case READ_HOLDING_REGISTERS: case READ_INPUT_REGISTERS: { pucRequestFrame[ 4 ] = highByte( request->dataSize ); pucRequestFrame[ 5 ] = lowByte( request->dataSize ); xRequestLength = 6; break; } #endif #if( ( configFC05 == 1 ) || ( configFC06 == 1 ) ) case WRITE_SINGLE_COIL: case WRITE_SINGLE_REGISTER: { if( request->data != NULL ) { pucRequestFrame[ 4 ] = highByte( request->data[ 0 ] ); pucRequestFrame[ 5 ] = lowByte( request->data[ 0 ] ); xRequestLength = 6; } else { return xSetException( ILLEGAL_REQUEST ); } break; } #endif #if( configFC08 == 1 ) case DIAGNOSTIC: { xRequestLength = 6; switch( request->address ) { #if( configSFC00 == 1 ) case RETURN_QUERY_DATA: { if( request->data != NULL ) { xRequestLength = 4; for( size_t i = 0; i < request->dataSize; i++ ) { pucRequestFrame[ 4 + i ] = ( uint8_t ) ( ( char * ) request->data )[ i ]; xRequestLength++; } } else { return xSetException( ILLEGAL_REQUEST ); } break; } #endif #if( configSFC01 == 1 ) case RESTART_COMMUNICATIONS_OPTION: { if( request->data != NULL ) { pucRequestFrame[ 4 ] = highByte( request->data[ 0 ] ); pucRequestFrame[ 5 ] = lowByte( request->data[ 0 ] ); } else { return xSetException( ILLEGAL_REQUEST ); } break; } #endif #if( configSFC03 == 1 ) case CHANGE_ASCII_INPUT_DELIMITER: { if( isAscii( *( ( char * ) request->data ) ) == true ) { pucRequestFrame[ 4 ] = ( uint8_t ) *( ( char * ) request->data ); pucRequestFrame[ 5 ] = 0x00; } else { return xSetException( ILLEGAL_REQUEST ); } break; } #endif #if( configSFC02 == 1 ) case RETURN_DIAGNOSTIC_REGISTER: #endif #if( configSFC04 == 1 ) case FORCE_LISTEN_ONLY_MODE: #endif #if( configSFC10 == 1 ) case CLEAR_COUNTERS_AND_DIAGNOSTIC_REGISTER: #endif #if( configSFC11 == 1 ) case RETURN_BUS_MESSAGE_COUNT: #endif #if( configSFC12 == 1 ) case RETURN_BUS_COMMUNICATION_ERROR_COUNT: #endif #if( configSFC13 == 1 ) case RETURN_BUS_EXCEPTION_ERROR_COUNT: #endif #if( configSFC14 == 1 ) case RETURN_SERVER_MESSAGE_COUNT: #endif #if( configSFC15 == 1 ) case RETURN_SERVER_NO_RESPONSE_COUNT: #endif #if( configSFC16 == 1 ) case RETURN_SERVER_NAK_COUNT: #endif #if( configSFC17 == 1 ) case RETURN_SERVER_BUSY_COUNT: #endif #if( configSFC18 == 1 ) case RETURN_BUS_CHARACTER_OVERRUN_COUNT: #endif #if( configSFC20 == 1 ) case CLEAR_OVERRUN_COUNTER_AND_FLAG: #endif #if( ( configSFC02 == 1 ) || ( configSFC04 == 1 ) || ( configSFC10 == 1 ) || \ ( configSFC11 == 1 ) || ( configSFC12 == 1 ) || ( configSFC13 == 1 ) || \ ( configSFC14 == 1 ) || ( configSFC15 == 1 ) || ( configSFC16 == 1 ) || \ ( configSFC17 == 1 ) || ( configSFC18 == 1 ) || ( configSFC20 == 1 ) ) { pucRequestFrame[ 4 ] = 0x00; pucRequestFrame[ 5 ] = 0x00; break; } #endif default: { return xSetException( ILLEGAL_SUB_FUNCTION ); } } break; } #endif #if( configFC16 == 1 ) case WRITE_MULTIPLE_REGISTERS: { /* Quantity */ pucRequestFrame[ 4 ] = highByte( request->dataSize ); pucRequestFrame[ 5 ] = lowByte( request->dataSize ); /* Byte-Count */ pucRequestFrame[ 6 ] = ( uint8_t ) request->dataSize * 2; xRequestLength = 7; if( request->data != NULL ) { for( size_t i = 0; i < request->dataSize; i++ ) { pucRequestFrame[ ( i * 2 ) + 7 ] = highByte( request->data[ i ] ); pucRequestFrame[ ( i * 2 ) + 8 ] = lowByte( request->data[ i ] ); xRequestLength += 2; } } else { return xSetException( ILLEGAL_REQUEST ); } break; } #endif default: { return xSetException( ILLEGAL_FUNCTION ); } } pxRequest = request; return xSetChecksum( pucRequestFrame, &xRequestLength ); } /*-----------------------------------------------------------*/ MBStatus_t SerialModbusClient::processModbus( void ) { if( bSkipRequestMap == false ) { if( xProcessRequestMap() != OK ) { ( void ) xSetException( ILLEGAL_REQUEST ); vSetState( PROCESSING_ERROR ); } } else { bSkipRequestMap = false; } do { /* Get the current state and select the associated action. */ switch( xState ) { case CLIENT_IDLE : { vClearReplyFrame(); #if( configMODE == configMODE_ASCII ) { /* We are in ASCII mode, so we convert the frame to the ASCII format (this also updates the pdu length). */ ( void ) xRtuToAscii( pucRequestFrame, &xRequestLength ); } #endif ( void ) xSendData( pucRequestFrame, xRequestLength ); /* Check if we have a broadcast or a normal reqest. */ #if( configMODE == configMODE_RTU ) if( ucREQUEST_ID == configID_BROADCAST ) #endif #if( configMODE == configMODE_ASCII ) if( ucAsciiToByte( pucRequestFrame[ 1 ], pucRequestFrame[ 2 ] ) == configID_BROADCAST ) #endif { /* Broadcast */ vSetState( WAITING_TURNAROUND_DELAY ); vStartTurnaroundDelay(); } else { /* Normal request */ vSetState( WAITING_FOR_REPLY ); vStartResponseTimeout(); } break; } case WAITING_TURNAROUND_DELAY : { /* Check if the Turnaround Delay has elapsed. */ if( bTimeoutTurnaroundDelay() == true ) { /* Just clear the request buffer and go back to idle. */ vClearRequestFrame(); vSetState( CLIENT_IDLE ); } break; } case WAITING_FOR_REPLY : { if( xReplyLength < configMAX_FRAME_LEN ) { if( bReceiveByte( pucReplyFrame, &xReplyLength ) == true ) { #if( configMODE == configMODE_RTU ) { vStartInterFrameDelay(); vStartInterCharacterTimeout(); } #endif #if( configMODE == configMODE_ASCII ) { if( pucReplyFrame[ 0 ] != ( uint8_t ) ':' ) { vClearReplyFrame(); } } #endif break; } } else { ( void ) xSetException( CHARACTER_OVERRUN ); vSetState( PROCESSING_ERROR ); break; } if( bTimeoutResponseTimeout() == true ) { ( void ) xSetException( NO_REPLY ); vSetState( PROCESSING_ERROR ); break; } /* Check if the start of a frame has been received. */ if( xReplyLength >= configMIN_FRAME_LEN ) { #if( configMODE == configMODE_RTU ) { if( bTimeoutInterCharacterTimeout() == true ) { if( xCheckChecksum( pucReplyFrame, xReplyLength ) == OK ) { if( ucREPLY_ID == ucREQUEST_ID ) { while( bTimeoutInterFrameDelay() != true ); vSetState( PROCESSING_REPLY ); } } else { ( void ) xSetException( ILLEGAL_CHECKSUM ); vSetState( PROCESSING_ERROR ); } } } #endif #if( configMODE == configMODE_ASCII ) { /* Check for the end of the ASCII frame which is marked by a carriage-return ('\r') followed by a variable input delimiter (default: line-feed/'\n'). */ if( pucReplyFrame[ xReplyLength - 1 ] == ( uint8_t ) cAsciiInputDelimiter ) { if( pucReplyFrame[ xReplyLength - 2 ] == ( uint8_t ) '\r' ) { /* From this point we handle the request and reply frames in the rtu format. */ ( void ) xAsciiToRtu( pucReplyFrame, &xReplyLength ); ( void ) xAsciiToRtu( pucRequestFrame, &xRequestLength ); if( xCheckChecksum( pucReplyFrame, xReplyLength ) == OK ) { if( ucREPLY_ID == ucREQUEST_ID ) { vSetState( PROCESSING_REPLY ); break; } } else { ( void ) xSetException( ILLEGAL_CHECKSUM ); vSetState( PROCESSING_ERROR ); } } } } #endif } break; } case PROCESSING_REPLY : { switch( ucREPLY_FUNCTION_CODE ) { #if( ( configFC03 == 1 ) || ( configFC04 == 1 ) ) case READ_HOLDING_REGISTERS : case READ_INPUT_REGISTERS : { vHandlerFC03_04(); break; } #endif #if( configFC05 == 1 ) case WRITE_SINGLE_COIL : { vHandlerFC05(); break; } #endif #if( configFC06 == 1 ) case WRITE_SINGLE_REGISTER : { vHandlerFC06(); break; } #endif #if( configFC08 == 1 ) case DIAGNOSTIC : { vHandlerFC08(); break; } #endif #if( configFC16 == 1 ) case WRITE_MULTIPLE_REGISTERS : { vHandlerFC16(); break; } #endif default : { /* The received reply could not be processed, so we check if it was illegal or an error reply. */ if( ucREPLY_FUNCTION_CODE == ( ucREQUEST_FUNCTION_CODE | 0x80 ) ) { ( void ) xSetException( ( MBException_t ) ucREPLY_ERROR_CODE ); } else { ( void ) xSetException( ILLEGAL_FUNCTION ); } vSetState( PROCESSING_ERROR ); } } if( xState != PROCESSING_ERROR ) { vSetState( CLIENT_IDLE ); } break; } case PROCESSING_ERROR : { vClearRequestFrame(); vClearReplyFrame(); vSetState( CLIENT_IDLE ); break; } default : { ( void ) xSetException( ILLEGAL_STATE ); vSetState( CLIENT_IDLE ); } } #if( configPROCESS_LOOP_HOOK == 1 ) { /* The process loop hook will only be executed when the state mashine is not in the idle state. Otherwise the loop hook would be execetued with every run through processModbus(). */ if( ( vProcessLoopHook != NULL ) && ( xState != CLIENT_IDLE ) ) { (*vProcessLoopHook)(); } } #endif } while( xState != CLIENT_IDLE ); return xException; } /*-----------------------------------------------------------*/ void SerialModbusClient::vHandlerFC03_04( void ) { size_t xOffset = 0; /* Check the reply byte count. */ if( ucREPLY_BYTE_COUNT == ( ( uint8_t ) usREQUEST_QUANTITY * 2 ) ) { if( pxRequest->data != NULL ) { xOffset = ( size_t ) ( usREQUEST_ADDRESS - pxRequest->address ); for( size_t i = 0; i < ( size_t ) usREQUEST_QUANTITY; i++ ) { pxRequest->data[ i + xOffset ] = usReplyWord( i ); } } if( pxRequest->callback != NULL ) { (*pxRequest->callback)(); } } else { ( void ) xSetException( ILLEGAL_BYTE_COUNT ); vSetState( PROCESSING_ERROR ); } } /*-----------------------------------------------------------*/ void SerialModbusClient::vHandlerFC05( void ) { /* Check the reply output address. */ if( usREPLY_ADDRESS == usREQUEST_ADDRESS ) { /* Check the reply output value. */ if( usREPLY_COIL_VALUE == usREQUEST_COIL_VALUE ) { if( pxRequest->callback != NULL ) { (*pxRequest->callback)(); } } else { ( void ) xSetException( ILLEGAL_COIL_VALUE ); vSetState( PROCESSING_ERROR ); } } else { ( void ) xSetException( ILLEGAL_OUTPUT_ADDRESS ); vSetState( PROCESSING_ERROR ); } } /*-----------------------------------------------------------*/ void SerialModbusClient::vHandlerFC06( void ) { /* Check the reply output address. */ if( usREPLY_ADDRESS == usREQUEST_ADDRESS ) { /* Check the reply output value. */ if( usREPLY_OUTPUT_VALUE == usREQUEST_OUTPUT_VALUE ) { if( pxRequest->callback != NULL ) { (*pxRequest->callback)(); } } else { ( void ) xSetException( ILLEGAL_OUTPUT_VALUE ); vSetState( PROCESSING_ERROR ); } } else { ( void ) xSetException( ILLEGAL_OUTPUT_ADDRESS ); vSetState( PROCESSING_ERROR ); } } /*-----------------------------------------------------------*/ void SerialModbusClient::vHandlerFC08( void ) { if( usREPLY_SUB_FUNCTION_CODE == usREQUEST_SUB_FUNCTION_CODE ) { switch( usREPLY_SUB_FUNCTION_CODE ) { #if( configSFC00 == 1 ) case RETURN_QUERY_DATA: { if( xReplyLength == xRequestLength ) { for( size_t i = 4; i < xReplyLength - xChecksumLength; i++ ) { if( pucReplyFrame[ i ] != pucRequestFrame[ i ] ) { ( void ) xSetException( ILLEGAL_QUERY_DATA ); vSetState( PROCESSING_ERROR ); return; } } } else { ( void ) xSetException( ILLEGAL_QUERY_DATA ); vSetState( PROCESSING_ERROR ); return; } break; } #endif #if( configSFC03 == 1 ) case CHANGE_ASCII_INPUT_DELIMITER: { if( usREPLY_INPUT_DELIMITER == usREQUEST_INPUT_DELIMITER ) { cAsciiInputDelimiter = ( char ) ucREPLY_INPUT_DELIMITER_HI; } else { ( void ) xSetException( ILLEGAL_OUTPUT_VALUE ); vSetState( PROCESSING_ERROR ); return; } break; } #endif #if( configSFC01 == 1 ) case RESTART_COMMUNICATIONS_OPTION: #endif #if( configSFC04 == 1 ) case FORCE_LISTEN_ONLY_MODE: #endif #if( configSFC10 == 1 ) case CLEAR_COUNTERS_AND_DIAGNOSTIC_REGISTER: #endif #if( configSFC20 == 1 ) case CLEAR_OVERRUN_COUNTER_AND_FLAG: #endif #if( ( configSFC01 == 1 ) || ( configSFC04 == 1 ) || \ ( configSFC10 == 1 ) || ( configSFC20 == 1 ) ) { if( usREPLY_DATA != usREQUEST_DATA ) { ( void ) xSetException( ILLEGAL_OUTPUT_VALUE ); vSetState( PROCESSING_ERROR ); return; } break; } #endif #if( configSFC02 == 1 ) case RETURN_DIAGNOSTIC_REGISTER: #endif #if( configSFC11 == 1 ) case RETURN_BUS_MESSAGE_COUNT: #endif #if( configSFC12 == 1 ) case RETURN_BUS_COMMUNICATION_ERROR_COUNT: #endif #if( configSFC13 == 1 ) case RETURN_BUS_EXCEPTION_ERROR_COUNT: #endif #if( configSFC14 == 1 ) case RETURN_SERVER_MESSAGE_COUNT: #endif #if( configSFC15 == 1 ) case RETURN_SERVER_NO_RESPONSE_COUNT: #endif #if( configSFC16 == 1 ) case RETURN_SERVER_NAK_COUNT: #endif #if( configSFC17 == 1 ) case RETURN_SERVER_BUSY_COUNT: #endif #if( configSFC18 == 1 ) case RETURN_BUS_CHARACTER_OVERRUN_COUNT: #endif #if( ( configSFC02 == 1 ) || ( configSFC11 == 1 ) || ( configSFC12 == 1 ) || \ ( configSFC13 == 1 ) || ( configSFC14 == 1 ) || ( configSFC15 == 1 ) || \ ( configSFC16 == 1 ) || ( configSFC17 == 1 ) || ( configSFC18 == 1 ) ) { if( pxRequest->data != NULL ) { pxRequest->data[ 0 ] = usREPLY_DATA; } break; } #endif default: { ( void ) xSetException( ILLEGAL_SUB_FUNCTION ); vSetState( PROCESSING_ERROR ); return; } } if( pxRequest->callback != NULL ) { (*pxRequest->callback)(); } } else { ( void ) xSetException( ILLEGAL_REPLY_SUB_FUNCTION ); vSetState( PROCESSING_ERROR ); } } /*-----------------------------------------------------------*/ void SerialModbusClient::vHandlerFC16( void ) { /* Check the reply output address. */ if( usREPLY_ADDRESS == usREQUEST_ADDRESS ) { /* Check the reply output quantity. */ if( usREPLY_QUANTITY == usREQUEST_QUANTITY ) { if( pxRequest->callback != NULL ) { (*pxRequest->callback)(); } } else { ( void ) xSetException( ILLEGAL_QUANTITY ); vSetState( PROCESSING_ERROR ); } } else { ( void ) xSetException( ILLEGAL_OUTPUT_ADDRESS ); vSetState( PROCESSING_ERROR ); } } /*-----------------------------------------------------------*/ int16_t SerialModbusClient::sendRequest( uint8_t id, uint8_t functionCode, uint16_t address, uint16_t value ) { uint16_t usData = 0x0000; MBRequest_t xRequest = { 0, 0x00, 0x0000, &usData, 1, NULL }; xRequest.id = id; xRequest.functionCode = functionCode; xRequest.address = address; usData = value; xStatusSimpleAPI = setRequest( &xRequest ); if( xStatusSimpleAPI == OK ) { xStatusSimpleAPI = processModbus(); if( xStatusSimpleAPI == OK ) { return ( int16_t ) usData; } } return -1; } /*-----------------------------------------------------------*/ int16_t SerialModbusClient::readHoldingRegister( uint8_t id, uint16_t address ) { return sendRequest( id, READ_HOLDING_REGISTERS, address, 0 ); } /*-----------------------------------------------------------*/ int16_t SerialModbusClient::readInputRegister( uint8_t id, uint16_t address ) { return sendRequest( id, READ_INPUT_REGISTERS, address, 0 ); } /*-----------------------------------------------------------*/ int16_t SerialModbusClient::writeSingleCoil( uint8_t id, uint16_t address, uint16_t value ) { return sendRequest( id, WRITE_SINGLE_COIL, address, value ); } /*-----------------------------------------------------------*/ int16_t SerialModbusClient::writeSingleRegister( uint8_t id, uint16_t address, uint16_t value ) { return sendRequest( id, WRITE_SINGLE_REGISTER, address, value ); } /*-----------------------------------------------------------*/ MBStatus_t SerialModbusClient::getLastException( void ) { return xStatusSimpleAPI; } /*-----------------------------------------------------------*/ const char * SerialModbusClient::getLastExceptionString( void ) { return getExceptionString( xStatusSimpleAPI ); }
18d33394fc7662aa10f6420ded4cbf67fe685bf8
a33aac97878b2cb15677be26e308cbc46e2862d2
/program_data/PKU_raw/86/82.c
82f16bf56764c8988f46a6aeeb2a29b8f0649adb
[]
no_license
GabeOchieng/ggnn.tensorflow
f5d7d0bca52258336fc12c9de6ae38223f28f786
7c62c0e8427bea6c8bec2cebf157b6f1ea70a213
refs/heads/master
2022-05-30T11:17:42.278048
2020-05-02T11:33:31
2020-05-02T11:33:31
null
0
0
null
null
null
null
UTF-8
C++
false
false
422
c
82.c
int main() { int n; scanf("%d",&n); int i,m,j,p; for(i=0;i<n;i++) { scanf("%d",&m); int time=0; for(j=1;j<=m;j++) { if(time<60) { scanf("%d",&p); time=p+3*j; } if(time>=60){break;} } if(time<=60)printf("%d\n",60-3*m); if(time>60) { if( p < ( 60-3*(j-2) ) )printf("%d\n",p); if( p >= ( 60-3*(j-2) ) )printf("%d\n",60-3*(j-1)); } } return 0; }
08b6e2bc1a4a0c8b6953674fb6f03df1feffc86d
e6cd01e382e985c72908240dde5987091b3f7dad
/src/main.cpp
5a93eec3d944295d0ee4ac3e190620bfd3da77d6
[]
no_license
andrei-herdt/goldfarb_idnani
2417a504e39acfd165c8fd3b7d34cab0467b1916
5fad0e8c72fbfee792a50979b6d05aeed5a3a65d
refs/heads/main
2023-04-28T11:29:22.367592
2021-05-18T22:01:31
2021-05-18T22:01:31
359,102,004
0
0
null
null
null
null
UTF-8
C++
false
false
452
cpp
main.cpp
#include <iostream> #include <Eigen/Dense> int main() { // Step 0: Assume that some S-pair (x,A) is given // Step 1: Repeat until all constraints are satisfied // (a): Choose a violated constraint within the set of non-active // constraints // (b): check for infeasibility, // Stof if infeasible // (c): If feasible, obtain a new solution, update the active set std::cout << "run solver" << std::endl; return 0; }
229170ab83d6047ae9f05fa7a9158bd5bf237c64
54db5404783bbaaef8bdd6b152be17b67f8ceee3
/SwitchButton.cpp
ea46966d8cf92e2f3eb4f2a5c059541d77103f31
[ "Apache-2.0" ]
permissive
pneumaticdeath/switchbox
23c9f0d646ecd8051131b9f21a5fc73e7a23bd94
aa129cf422217ad4dd61620902f513702152d3d9
refs/heads/master
2020-12-24T13:28:25.408699
2019-02-24T21:32:17
2019-02-24T21:32:17
38,138,056
0
0
null
null
null
null
UTF-8
C++
false
false
2,851
cpp
SwitchButton.cpp
/* Copyright 2015, Mitch Patenaude patenaude@gmail.com */ #include "SwitchButton.h" SwitchButton::SwitchButton(uint8_t pin, uint32_t long_press_time, uint32_t debouce_time, uint8_t speaker_pin, uint16_t down_tone, uint16_t down_tone_duration, uint16_t up_tone, uint16_t up_tone_duration) { this->pin = pin; this->long_press_time = long_press_time; this->speaker_pin = speaker_pin; this->down_tone = down_tone; this->down_tone_duration = down_tone_duration; this->up_tone = up_tone; this->up_tone_duration = up_tone_duration; this->debounce_time = debounce_time; // initialize the pin pinMode(this->pin, INPUT); digitalWrite(this->pin, HIGH); this->is_down = (digitalRead(this->pin) == 0); digitalWrite(this->pin, LOW); this->button_debounce_timer = millis(); this->clear_state(); } void SwitchButton::clear_state() { this->is_pressed = false; this->is_released = false; this->is_long_press = false; this->has_event = false; } boolean SwitchButton::read() { int val; if ( this->button_debounce_timer > millis() ) { // We've rolled over this->button_debounce_timer = 0; } this->clear_state(); if ( (millis() - this->button_debounce_timer) < this->debounce_time ) return false; digitalWrite(this->pin, HIGH); // set pull-up resistor for read val = digitalRead(this->pin); // read the state of the switch/button. 0 is down/closed. digitalWrite(this->pin, LOW); // clears pull-up resistor to save power if ( val == 0 ) { // 0 represents down/closed. if ( ! this->is_down ) { // if not previously down/closed this->is_down = true; this->is_pressed = true; this->has_event = true; this->button_debounce_timer = millis(); if ( this->down_tone && this->down_tone_duration ) { tone(this->speaker_pin, this->down_tone, this->down_tone_duration); } return true; } else if ( (millis() - this->button_debounce_timer) >= this->long_press_time ) { this->is_long_press = true; } } else { if ( this->is_down ) { this->is_down = false; this->is_released = true; this->has_event = true; this->prev_press_duration = millis() - this->button_debounce_timer; this->button_debounce_timer = millis(); if ( this->up_tone && this->up_tone_duration ) { tone(this->speaker_pin, this->up_tone, this->up_tone_duration); } return true; } } return false; } uint32_t SwitchButton::press_duration() { if ( this->is_released ) { return this->prev_press_duration; } else if ( this->is_down ) { return millis() - this->button_debounce_timer; } // logic is that when the button is up and not newly released we should return 0. return 0; } uint32_t SwitchButton::idle_time() { return millis() - this->button_debounce_timer; }
eeabdcf187336c33d3395d9a7bac0419ba4bb4a0
aa59edc791efa1eea8bb477689e5ae227f7621b2
/source/NanairoGui/Renderer/scene_value.hpp
5979ced4eabe6daaad7d9d95d6f1840feab6c50e
[ "MIT" ]
permissive
byzin/Nanairo
e5f30fb8fae8d65c45c768c8560524ac41f57d21
23fb6deeec73509c538a9c21009e12be63e8d0e4
refs/heads/master
2020-12-25T17:58:18.361872
2019-05-05T06:05:34
2019-05-05T06:05:34
18,831,971
32
6
null
null
null
null
UTF-8
C++
false
false
4,620
hpp
scene_value.hpp
/*! \file scene_value.hpp \author Sho Ikeda Copyright (c) 2015-2018 Sho Ikeda This software is released under the MIT License. http://opensource.org/licenses/mit-license.php */ #ifndef NANAIRO_SCENE_VALUE_HPP #define NANAIRO_SCENE_VALUE_HPP // Standard C++ library #include <memory> // Qt #include <QJsonArray> #include <QJsonObject> #include <QJsonValue> #include <QString> // Nanairo #include "NanairoCore/Setting/setting_node_base.hpp" namespace nanairo { //! \addtogroup Gui //! \{ /*! */ class SceneValue { public: //! Return a array value static QJsonArray toArray(const QJsonObject& object, const QString& key) noexcept; //! Return a array value static QJsonArray toArray(const QJsonValue& value) noexcept; //! Return a boolean value static bool toBool(const QJsonObject& object, const QString& key) noexcept; //! Return a boolean value static bool toBool(const QJsonValue& value) noexcept; //! Return a float value template <typename FloatingPoint> static FloatingPoint toFloat(const QJsonObject& object, const QString& key) noexcept; //! Return a float value template <typename FloatingPoint> static FloatingPoint toFloat(const QJsonValue& value) noexcept; //! Return a integer value template <typename Integer> static Integer toInt(const QJsonObject& object, const QString& key) noexcept; //! Return a integer value template <typename Integer> static Integer toInt(const QJsonValue& value) noexcept; //! Return a object value static QJsonObject toObject(const QJsonObject& object, const QString& key) noexcept; //! Return a object value static QJsonObject toObject(const QJsonValue& value) noexcept; //! Convert json scene to setting static std::unique_ptr<SettingNodeBase> toSetting( const QJsonObject& value) noexcept; //! Return a string value static QString toString(const QJsonObject& object, const QString& key) noexcept; //! Return a string value static QString toString(const QJsonValue& value) noexcept; private: // Prevent instance SceneValue() noexcept; //! Return a json value static QJsonValue getValue(const QJsonObject& object, const QString& key) noexcept; //! Convert json bvh to bvh setting static void toBvhSetting(const QJsonObject& value, SettingNodeBase* setting) noexcept; //! Convert json camera to camera setting static void toCameraSetting(const QJsonArray& value, SettingNodeBase* setting) noexcept; //! Convert json emitter to emitter setting static void toEmitterModelSetting(const QJsonObject& value, SettingNodeBase* setting) noexcept; //! Convert json object to object setting static void toObjectModelSetting(const QJsonObject& object_value, SettingNodeBase* setting) noexcept; //! Convert json object to object setting static void toObjectSetting(const QJsonArray& value, SettingNodeBase* setting) noexcept; //! Convert json rendering method to rendering method setting static void toRenderingMethodSetting(const QJsonObject& value, SettingNodeBase* setting) noexcept; //! Convert json scene to scene setting static void toSceneSetting(const QJsonObject& value, SettingNodeBase* setting) noexcept; //! Convert json single object to single object setting static void toSingleObjectSetting(const QJsonObject& object_value, SettingNodeBase* setting) noexcept; //! Convert json spectra object to spectra setting static void toSpectraSetting(const QJsonObject& spectra_value, SettingNodeBase* setting) noexcept; //! Convert json surface to surface setting static void toSurfaceModelSetting(const QJsonObject& value, SettingNodeBase* setting) noexcept; //! Convert json system to system setting static void toSystemSetting(const QJsonObject& value, SettingNodeBase* setting) noexcept; //! Convert json texture to texture setting static void toTextureModelSetting(const QJsonObject& value, SettingNodeBase* setting) noexcept; }; //! \} } // namespace nanairo #include "scene_value-inl.hpp" #endif // NANAIRO_SCENE_VALUE_HPP
dfa77683dc77da1b98ffba79c098f62cef1a6e55
b5d5aee773b6892e137692a8209127bb900de96d
/CPU Scheduler/process.h
871a78fc3d615c1b95016726346e10e7ba7e853b
[]
no_license
AkivaGreen/CPU-Scheduler
6c6ba5f7d9590ea547cfb383b47949a21efcd8c2
5b950b8153b96dd763fd21887a589ce1aef7a6de
refs/heads/master
2020-12-31T21:30:28.366784
2020-02-07T22:07:20
2020-02-07T22:07:20
239,031,325
0
0
null
null
null
null
UTF-8
C++
false
false
1,987
h
process.h
#pragma once #ifndef PROCESS_H #define PROCESS_H #include <iostream> using namespace std; class process { public: process(); process(const process & org); ~process(); string name; int getData(int loc); int getCount(); void setCount(int new_count); int getSize(); void setSize(int new_size); int getCPU(); //Get the current cpu_pos void setCPUPos(int new_cpu_pos); int getIO(); //Get the current io pos void setIOPos(int new_io_pos); int getCPUTotal(); void setCPUTotal(int new_cpu_total); int getIOTotal(); void setIOTotal(int new_io_total); void add(int data); int getWaiting(); void setWaiting(int new_waiting); int getTurnaround(); void setTurnaround(int new_turnaround); int getResponse(); void setResponse(int time); bool isEmpty(); bool isFull(); bool isBurst(int loc); //Checks location value if it is burst location bool isIO(int loc); //Checks location value if it is io location bool finished(); //Returns true if process is finished (All values in array is 0) void incrementWaiting(); //Increments Total Waiting Time void incrementCPU(); //Increments Total CPU Time void incrementCPUPos(); //Increments CPU Array Position Value void incrementIO(); //Increments Total IO Time void incrementIOPos(); //Increments IO Array Position Value void decrement(int loc); //Decrement value at location void double_size(); void displayArray(); //Test Method to Display Dynamic Array void printCPUContextSwitch(); //Used to Print Current Process void printIOContextSwitch(); //Used to Print IO Value of Process private: int waiting; //Waiting Time int turnaround; //Turnaround Time int response; //Response time int cpu_total; //Total CPU Time int io_total; //Total IO Time int cpu_pos; //Current CPU Burst Location int io_pos; //Current IO Burst Location int count; //Number of Elements in Dynamic Array int size; //Size of Dynamic Array int *process_data; //Array of integer values that hold CPU and IO Burst Times }; #endif
c33bcbb20b72f110958224f858c0f5140985c551
f07433ee47bbed403874a5d9232adcc746b20df3
/p8/complex.cpp
798010ce6fd31a2a4b584453a9d511bc09a8a113
[]
no_license
YihuiAndre/csc103-projects
013ccc4936dc831affb62e16e07032b70c556cad
1b155aab2f6fe3daf826ca8bdc97d753ccb80565
refs/heads/master
2021-07-03T07:29:56.080923
2020-09-30T16:21:47
2020-09-30T16:21:47
168,990,130
0
1
null
null
null
null
UTF-8
C++
false
false
2,023
cpp
complex.cpp
/* * file: complex.cpp * This is the implementation of our complex number * class whose interface resides in the file complex.h */ #include "complex.h" #include <cmath> // for the square root function needed for norm() complex::complex(double re, double im) { //initialize the real and imaginary parts: real = re; imag = im; } complex::complex(const complex& z) { //we need to make *this a copy of z: real = z.real; imag = z.imag; } ostream& operator<<(ostream& o, const complex& z) { o << "(" << z.real; if(z.imag>=0) o << " + " << z.imag; else o << " - " << -z.imag; o << "i)"; return o; } istream& operator>>(istream& i, complex& z) { return (i>> z.real >> z.imag); } complex complex::conj() { complex temp; temp.real = real; temp.imag = -imag; return temp; /* NOTE: alternatively, you could use a constructor to make a * new complex number with the right real and imaginary parts, * and return it straight away: */ // return complex(real,-imag); } complex::complex() { real = 0; imag = 0; } double complex::norm() { /* TODO: write this */ return 0; } complex operator+(const complex& w, const complex& z) { complex retVal; retVal.real = w.real + z.real; retVal.imag = w.imag + z.imag; return retVal; /* again, this could also be written as: */ // return complex(w.real+z.real,w.imag+z.imag); } complex operator-(const complex& w) { /* TODO: write this */ /* NOTE: this is unary negation, not subtraction. */ } complex operator-(const complex& w, const complex& z) { /* TODO: write this */ } complex operator*(const complex& w, const complex& z) { /* TODO: write this */ return complex(); } complex operator/(complex& w, complex& z) { /* TODO: write this */ return complex(); } complex operator^(const complex& w, int a) { /* NOTE: there are much more efficient ways to do exponentiation, * but it won't make much difference for our application. */ complex retVal(1,0); //initialize it to 1 for(int i=0; i<a; i++) retVal = retVal*w; return retVal; }
b6e0409684af234cec336a52ebc1721eda672f26
dba68ca53ce02985ed1b49f6813d578d24e94b27
/ProjectsServer/GameServer/FieldServer/MonthlyArmorManager.h
c174955444a30c07b68acb95fbce313bff3c974c
[]
no_license
DeathRivals/OpenAo
afd6c1fe6ddc00e3765c290f485805a7b3e0db59
bf6be4ee29b1f08588fe7fd12c02c8df94d705f5
refs/heads/master
2021-02-15T18:23:37.814569
2020-03-04T14:39:38
2020-03-04T14:39:38
244,919,960
2
2
null
2020-03-04T14:22:07
2020-03-04T14:22:07
null
UHC
C++
false
false
1,529
h
MonthlyArmorManager.h
// MonthlyArmorManager.h: interface for the CMonthlyArmorManager class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_MonthlyArmorManager_H__587F770B_FAA0_45E0_9EBB_556823A0EC7F__INCLUDED_) #define AFX_MonthlyArmorManager_H__587F770B_FAA0_45E0_9EBB_556823A0EC7F__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 typedef mt_vector<MONTHLY_ARMOR_EVNET_INFO> mtvectMONTHLY_ARMOR_EVNET_INFO; class CFieldIOCPSocket; class CMonthlyArmorManager { public: CMonthlyArmorManager(CFieldIOCP *i_pFieldIOCP); virtual ~CMonthlyArmorManager(); BOOL InitMonthlyArmorEventManager(vectMONTHLY_ARMOR_EVNET_INFO *i_pMonthlyArmorEventList); mtvectMONTHLY_ARMOR_EVNET_INFO * GetVectMonthlyArmorEventListPtr(void); void CheckMonthlyArmorEventItem(ITEM_GENERAL* io_pItemG, CFieldIOCPSocket* i_pSock = NULL); void SendMonthlyArmorEventListToAllClients(); void CheckMonthlyArmorEventCollection(CFieldIOCPSocket* i_pSock, ItemNum_t i_nShapeItemNum); // 2013-05-31 by jhseol,bckim 아머 컬렉션 - 하나의 컬렉션에 대하여 이달의 어머 이벤트 정보 보내기 void SendMonthlyArmorEventAllCollectionList(CFieldIOCPSocket* i_pSock); // 2013-05-31 by jhseol,bckim 아머 컬렉션 - 모든 컬렉션에 대하여 이달의 어머 이벤트 정보 보내기 protected: mtvectMONTHLY_ARMOR_EVNET_INFO m_mtMonthlyArmorEventList; CFieldIOCP *ms_pFieldIOCP; }; #endif // !defined(AFX_MonthlyArmorManager_H__587F770B_FAA0_45E0_9EBB_556823A0EC7F__INCLUDED_)
92db7eb3ca2ac3bed9220ddb0c4b97bf0c558284
8f11b828a75180161963f082a772e410ad1d95c6
/packages/estimation/include/modules/RangeAveragingModule.h
b5d01ad14613ee4eba40efa1bd43c9bb1f77c333
[]
no_license
venkatarajasekhar/tortuga
c0d61703d90a6f4e84d57f6750c01786ad21d214
f6336fb4d58b11ddfda62ce114097703340e9abd
refs/heads/master
2020-12-25T23:57:25.036347
2017-02-17T05:01:47
2017-02-17T05:01:47
43,284,285
0
0
null
2017-02-17T05:01:48
2015-09-28T06:39:21
C++
UTF-8
C++
false
false
1,197
h
RangeAveragingModule.h
/* * Copyright (C) 2011 Robotics at Maryland * Copyright (C) 2011 Eliot Rudnick-Cohen <erudnick@umd.edu> * All rights reserved. * * Author: Eliot Rudnick-Cohen <erudnick@umd.edu> * File: packages/estimation/include/modules/RangeAveraging.h */ #ifndef RAM_ESTIMATION_RANGEAVERAGINGMODULE #define RAM_ESTIMATION_RANGEAVERAGINGMODULE // STD Includes #include <iostream> // Library Includes #include <log4cpp/Category.hh> //Project Includes #include "vehicle/include/Events.h" #include "estimation/include/EstimatedState.h" #include "estimation/include/EstimationModule.h" #include "core/include/ConfigNode.h" #include "core/include/Event.h" #include "math/include/AveragingFilter.h" namespace ram { namespace estimation { static const int RANGE_FILTER_SIZE = 10; class RangeAveragingModule : public EstimationModule { public: RangeAveragingModule(core::ConfigNode config,core::EventHubPtr eventHub, EstimatedStatePtr estimatedState); virtual ~RangeAveragingModule(){}; virtual void update(core::EventPtr event); private: math::AveragingFilter<double,RANGE_FILTER_SIZE> filter; }; }// end of namespace estimation }// end of namespace ram #endif
4e5f050f07560c909464dc9468a684b540831d39
c6bddd88916e6c8697a9e02485bd22c58d76bcec
/GeneratedPlaceholders/Engine/AudioComponent.h
943dc2e94dacf7aa678e1a811f191187ae85ae6c
[]
no_license
GIRU-GIRU/Mordhau-Unofficial-SDK
18d13d62d746a838820e387907d13b0a37aed654
f831d7355cf553b81fb6e82468b3abf68f7955aa
refs/heads/master
2020-07-06T03:36:48.908227
2020-04-22T13:54:00
2020-04-22T13:54:00
202,872,898
7
4
null
null
null
null
UTF-8
C++
false
false
6,360
h
AudioComponent.h
#pragma once #include "CoreMinimal.h" #include "AudioComponent.generated.h" UCLASS() class UAudioComponent : public USceneComponent { GENERATED_BODY() public: UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) TArray<struct FAudioComponentParam> InstanceParameters; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) class USoundClass* SoundClassOverride; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) unsigned char bAutoDestroy : 1; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) unsigned char bStopWhenOwnerDestroyed : 1; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) unsigned char bShouldRemainActiveIfDropped : 1; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) unsigned char bAllowSpatialization : 1; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) unsigned char bOverrideAttenuation : 1; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) unsigned char bOverrideSubtitlePriority : 1; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) unsigned char bIsUISound : 1; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) unsigned char bEnableLowPassFilter : 1; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) unsigned char bOverridePriority : 1; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) unsigned char bSuppressSubtitles : 1; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) unsigned char UnknownData00 : 6; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) unsigned char UnknownData01 : 3; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) unsigned char bAutoManageAttachment : 1; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) struct FName AudioComponentUserID; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) float PitchModulationMin; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) float PitchModulationMax; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) float VolumeModulationMin; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) float VolumeModulationMax; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) float VolumeMultiplier; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) int EnvelopeFollowerAttackTime; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) int EnvelopeFollowerReleaseTime; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) float Priority; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) float SubtitlePriority; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) float PitchMultiplier; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) float LowPassFilterFrequency; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) class USoundAttenuation* AttenuationSettings; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) struct FSoundAttenuationSettings AttenuationOverrides; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) class USoundConcurrency* ConcurrencySettings; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) EAttachmentRule AutoAttachLocationRule; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) EAttachmentRule AutoAttachRotationRule; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) EAttachmentRule AutoAttachScaleRule; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) struct FScriptMulticastDelegate OnAudioFinished; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) struct FScriptMulticastDelegate OnAudioPlaybackPercent; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) struct FScriptMulticastDelegate OnAudioSingleEnvelopeValue; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) struct FScriptMulticastDelegate OnAudioMultiEnvelopeValue; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) struct FScriptDelegate OnQueueSubtitles; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) TWeakObjectPtr<class USceneComponent> AutoAttachParent; UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite) struct FName AutoAttachSocketName; UFUNCTION(BlueprintCallable, Category = "AudioComponent") void Stop(); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void SetWaveParameter(const struct FName& InName, class USoundWave* InWave); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void SetVolumeMultiplier(float NewVolumeMultiplier); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void SetUISound(bool bInUISound); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void SetSubmixSend(class USoundSubmix* Submix, float SendLevel); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void SetSound(class USoundBase* NewSound); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void SetPitchMultiplier(float NewPitchMultiplier); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void SetPaused(bool bPause); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void SetLowPassFilterFrequency(float InLowPassFilterFrequency); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void SetLowPassFilterEnabled(bool InLowPassFilterEnabled); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void SetIntParameter(const struct FName& InName, int inInt); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void SetFloatParameter(const struct FName& InName, float InFloat); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void SetBoolParameter(const struct FName& InName, bool InBool); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void Play(float StartTime); UFUNCTION(BlueprintCallable, Category = "AudioComponent") bool IsPlaying(); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void FadeOut(float FadeOutDuration, float FadeVolumeLevel); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void FadeIn(float FadeInDuration, float FadeVolumeLevel, float StartTime); UFUNCTION(BlueprintCallable, Category = "AudioComponent") bool BP_GetAttenuationSettingsToApply(struct FSoundAttenuationSettings* OutAttenuationSettings); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void AdjustVolume(float AdjustVolumeDuration, float AdjustVolumeLevel); UFUNCTION(BlueprintCallable, Category = "AudioComponent") void AdjustAttenuation(const struct FSoundAttenuationSettings& InAttenuationSettings); };
59ee5071bfc066743c23f78dd4e5977d6e0ac47e
fb0f9abad373cd635c2635bbdf491ea0f32da5ff
/src/coreclr/debug/createdump/dumpwritermacho.cpp
79b71132f3a3a8c1038ad950823a8aaea44970a2
[ "MIT" ]
permissive
dotnet/runtime
f6fd23936752e202f8e4d6d94f3a4f3b0e77f58f
47bb554d298e1e34c4e3895d7731e18ad1c47d02
refs/heads/main
2023-09-03T15:35:46.493337
2023-09-03T08:13:23
2023-09-03T08:13:23
210,716,005
13,765
5,179
MIT
2023-09-14T21:58:52
2019-09-24T23:36:39
C#
UTF-8
C++
false
false
10,093
cpp
dumpwritermacho.cpp
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #include "createdump.h" #include "specialthreadinfo.h" extern int g_readProcessMemoryResult; // // Write the core dump file // bool DumpWriter::WriteDump() { BuildSegmentLoadCommands(); BuildThreadLoadCommands(); uint64_t fileOffset = 0; if (!WriteHeader(&fileOffset)) { return false; } TRACE("Writing %zd thread commands to core file\n", m_threadLoadCommands.size()); // Write thread commands for (const ThreadCommand& thread : m_threadLoadCommands) { if (!WriteData(&thread, thread.command.cmdsize)) { return false; } } TRACE("Writing %zd segment commands to core file\n", m_segmentLoadCommands.size()); // Align first segment's file offset to the next page (0x1000) byte boundary uint64_t alignment = 0; if (fileOffset & (PAGE_SIZE - 1)) { alignment = fileOffset; fileOffset = (fileOffset + (PAGE_SIZE - 1)) & PAGE_MASK; alignment = fileOffset - alignment; } // Write segment commands for (segment_command_64& segment : m_segmentLoadCommands) { segment.fileoff = fileOffset; fileOffset += segment.vmsize; assert(segment.vmsize == segment.filesize); if (!WriteData(&segment, segment.cmdsize)) { return false; } } // Write any segment alignment required to the core file if (alignment > 0) { if (alignment > sizeof(m_tempBuffer)) { printf_error("Internal error: segment alignment %llu > sizeof(m_tempBuffer)\n", alignment); return false; } memset(m_tempBuffer, 0, alignment); if (!WriteData(m_tempBuffer, alignment)) { return false; } } // Write memory regions return WriteSegments(); } vm_prot_t ConvertFlags(uint32_t flags) { vm_prot_t prot = 0; if (flags & PF_R) { prot |= VM_PROT_READ; } if (flags & PF_W) { prot |= VM_PROT_WRITE; } if (flags & PF_X) { prot |= VM_PROT_EXECUTE; } return prot; } void DumpWriter::BuildSegmentLoadCommands() { for (const MemoryRegion& memoryRegion : m_crashInfo.MemoryRegions()) { uint64_t size = memoryRegion.Size(); uint32_t prot = ConvertFlags(memoryRegion.Permissions()); segment_command_64 segment = { LC_SEGMENT_64, // uint32_t cmd; sizeof(segment_command_64), // uint32_t cmdsize; {0}, // char segname[16]; memoryRegion.StartAddress(), // uint64_t vmaddr; size, // uint64_t vmsize; 0, // uint64_t fileoff; size, // uint64_t filesize; prot, // uint32_t maxprot; prot, // uint32_t initprot; 0, // uint32_t nsects; 0 // uint32_t flags; }; m_segmentLoadCommands.push_back(segment); } // Add special memory region containing the process and thread info uint64_t size = sizeof(SpecialThreadInfoHeader) + (m_crashInfo.Threads().size() * sizeof(SpecialThreadInfoEntry)); segment_command_64 segment = { LC_SEGMENT_64, // uint32_t cmd; sizeof(segment_command_64), // uint32_t cmdsize; {0}, // char segname[16]; SpecialThreadInfoAddress, // uint64_t vmaddr; size, // uint64_t vmsize; 0, // uint64_t fileoff; size, // uint64_t filesize; VM_PROT_READ, // uint32_t maxprot; VM_PROT_READ, // uint32_t initprot; 0, // uint32_t nsects; 0 // uint32_t flags; }; m_segmentLoadCommands.push_back(segment); } void DumpWriter::BuildThreadLoadCommands() { for (const ThreadInfo* thread : m_crashInfo.Threads()) { ThreadCommand threadCommand = { { LC_THREAD, sizeof(ThreadCommand) }, }; #if defined(__x86_64__) threadCommand.gpflavor = x86_THREAD_STATE64; threadCommand.gpcount = x86_THREAD_STATE64_COUNT; threadCommand.fpflavor = x86_FLOAT_STATE64; threadCommand.fpcount = x86_FLOAT_STATE64_COUNT; assert(x86_THREAD_STATE64_COUNT == sizeof(x86_thread_state64_t) / sizeof(uint32_t)); assert(x86_FLOAT_STATE64_COUNT == sizeof(x86_float_state64_t) / sizeof(uint32_t)); memcpy(&threadCommand.gpregisters, thread->GPRegisters(), sizeof(x86_thread_state64_t)); memcpy(&threadCommand.fpregisters, thread->FPRegisters(), sizeof(x86_float_state64_t)); #elif defined(__aarch64__) threadCommand.gpflavor = ARM_THREAD_STATE64; threadCommand.gpcount = ARM_THREAD_STATE64_COUNT; threadCommand.fpflavor = ARM_NEON_STATE64; threadCommand.fpcount = ARM_NEON_STATE64_COUNT; assert(ARM_THREAD_STATE64_COUNT == sizeof(arm_thread_state64_t) / sizeof(uint32_t)); assert(ARM_NEON_STATE64_COUNT == sizeof(arm_neon_state64_t) / sizeof(uint32_t)); memcpy(&threadCommand.gpregisters, thread->GPRegisters(), sizeof(arm_thread_state64_t)); memcpy(&threadCommand.fpregisters, thread->FPRegisters(), sizeof(arm_neon_state64_t)); #endif m_threadLoadCommands.push_back(threadCommand); } } bool DumpWriter::WriteHeader(uint64_t* pFileOffset) { mach_header_64 header; memset(&header, 0, sizeof(mach_header_64)); header.magic = MH_MAGIC_64; #if defined(__x86_64__) header.cputype = CPU_TYPE_X86_64; header.cpusubtype = CPU_SUBTYPE_I386_ALL | CPU_SUBTYPE_LITTLE_ENDIAN; #elif defined(__aarch64__) header.cputype = CPU_TYPE_ARM64; header.cpusubtype = CPU_SUBTYPE_ARM64_ALL | CPU_SUBTYPE_LITTLE_ENDIAN; #else #error Unexpected architecture #endif header.filetype = MH_CORE; for (const ThreadCommand& thread : m_threadLoadCommands) { header.ncmds++; header.sizeofcmds += thread.command.cmdsize; } for (const segment_command_64& segment : m_segmentLoadCommands) { header.ncmds++; header.sizeofcmds += segment.cmdsize; } *pFileOffset = sizeof(mach_header_64) + header.sizeofcmds; TRACE("Macho header: magic %08x cputype %08x cpusubtype %08x filetype %08x ncmds %08x sizeofcmds %08x flags %08x reserved %08x\n", header.magic, header.cputype, header.cpusubtype, header.filetype, header.ncmds, header.sizeofcmds, header.flags, header.reserved); // Write header return WriteData(&header, sizeof(mach_header_64)); } bool DumpWriter::WriteSegments() { TRACE("Writing %" PRIu64 " memory regions to core file\n", m_segmentLoadCommands.size()); // Read from target process and write memory regions to core uint64_t total = 0; for (const segment_command_64& segment : m_segmentLoadCommands) { uint64_t address = segment.vmaddr; size_t size = segment.vmsize; total += size; TRACE("%" PRIA PRIx64 " - %" PRIA PRIx64 " (%06" PRIx64 ") %" PRIA PRIx64 " %c%c%c %02x\n", segment.vmaddr, segment.vmaddr + segment.vmsize, segment.vmsize / PAGE_SIZE, segment.fileoff, (segment.initprot & VM_PROT_READ) ? 'r' : '-', (segment.initprot & VM_PROT_WRITE) ? 'w' : '-', (segment.initprot & VM_PROT_EXECUTE) ? 'x' : '-', segment.initprot); if (address == SpecialDiagInfoAddress) { if (!WriteDiagInfo(size)) { return false; } } else if (address == SpecialThreadInfoAddress) { // Write the header SpecialThreadInfoHeader header = { {SPECIAL_THREADINFO_SIGNATURE}, m_crashInfo.Pid(), m_crashInfo.Threads().size() }; if (!WriteData(&header, sizeof(header))) { return false; } // Write the tid and stack pointer for each thread for (const ThreadInfo* thread : m_crashInfo.Threads()) { SpecialThreadInfoEntry entry = { thread->Tid(), thread->GetStackPointer() }; if (!WriteData(&entry, sizeof(entry))) { return false; } } } else { while (size > 0) { size_t bytesToRead = std::min(size, sizeof(m_tempBuffer)); size_t read = 0; if (!m_crashInfo.ReadProcessMemory((void*)address, m_tempBuffer, bytesToRead, &read)) { printf_error("Error reading memory at %" PRIA PRIx64 " size %08zx FAILED %s (%x)\n", address, bytesToRead, mach_error_string(g_readProcessMemoryResult), g_readProcessMemoryResult); return false; } // This can happen if the target process dies before createdump is finished if (read == 0) { printf_error("Error reading memory at %" PRIA PRIx64 " size %08zx returned 0 bytes read: %s (%x)\n", address, bytesToRead, mach_error_string(g_readProcessMemoryResult), g_readProcessMemoryResult); return false; } if (!WriteData(m_tempBuffer, read)) { return false; } address += read; size -= read; } } } printf_status("Written %" PRId64 " bytes (%" PRId64 " pages) to core file\n", total, total / PAGE_SIZE); return true; }
6a1c6d14230705781bc4303904f77eb72c1518db
9680d30e967bcda5e07c278d42adbd4a3d09e72d
/static_list/Lista.cpp
d625fa81d2aa6cba077436a35252fb17b9c56360
[]
no_license
MatheusGobetti/data_structures
06407af06d76c31582731d8302fb5b378f6180fb
54f7bfe609f219b8af72067a2286422289b05264
refs/heads/main
2023-06-09T10:04:33.576434
2021-06-22T12:45:04
2021-06-22T12:45:04
350,571,248
0
0
null
null
null
null
UTF-8
C++
false
false
2,345
cpp
Lista.cpp
#include "Lista.h" Lista::Lista() { contador = 0; for (int i = 0 ; i < capacidade ; i ++) { elementos[i] = 0; } } bool Lista::vazia() { return contador == 0; } bool Lista::cheia() { return contador == capacidade; } string Lista::listar() { string ret = ""; for (int i = 0 ; i < contador ; i ++) { ret = ret + "[" + to_string(elementos[i]) + "] "; } ret = ret; return ret; } bool Lista::inserir(int p, int x) { // Inserção de elemento em determinada posição. // Esta posição deve ser um valor entre 1 (primeiro elemento da lista) // e último + 1 (após o último elemento da lista). // As entradas posteriores ao elemento inserido devem ter suas posições // incrementadas em uma unidade. // Seu código aqui if(vazia()) { elementos[0] = x; contador++; } else if (p <= contador && p < MAX){ elementos[p] = x; contador++; } else { cout << "Lista cheia!" << endl; } return true; } bool Lista::remover(int p, int &x) { // Remoção de elemento em determinada posição. // Esta posição deve ser um valor entre 1 (primeiro elemento da lista) // e último (último elemento da lista). // As entradas posteriores ao elemento removido devem ter suas posições // decrementadas em uma unidade. // Seu código aqui if(vazia()) return false; else if(p >= 0 && p <= contador) { for(int i = p; i < MAX+1; i++) { elementos[i] = elementos[i+1]; } contador--; } return true; } bool Lista::retornar(int p, int &x) { // Retorna elemento armazenado em determinada posição. // Esta posição deve ser um valor entre 1 (primeiro elemento da lista) // e último (último elemento da lista). // Seu código aqui string ret; if (p >= 1 && p <= contador){ ret = "[" + to_string(elementos[p]) + "] \n"; } cout << ret; return true; } bool Lista::substituir(int p, int x) { // Substitui elemento armazenado em determinada posição. // Esta posição deve ser um valor entre 1 (primeiro elemento da lista) // e último (último elemento da lista). // Seu código aqui if (p >= 1 && p <= contador){ elementos[p] = x; } return true; }
1161de0d2a325185e8b27c6461d679aeb2acf904
21b70522929f9cb99caec4e81af59a1359bf1447
/src/tools/main.cpp
60eb4fcb08d9d4c22f9157577624fcf581019a68
[]
no_license
psionic12/mycc
01c52b1214f41bb15dd8fece03d2ba313a648201
4b851fe956b5174b0655e2046bffb8ea44183a98
refs/heads/master
2021-08-07T05:17:12.434763
2020-05-14T10:04:52
2020-05-14T10:04:52
175,815,823
7
0
null
null
null
null
UTF-8
C++
false
false
1,454
cpp
main.cpp
#include <iostream> #include <fstream> #include <lex/lex.h> #include "first_set_generator.h" int main() { std::ifstream BNF; BNF.open("BNF"); std::unordered_map<std::string, mycc_first_set::NoneTerminalId> none_terminal_map; mycc_first_set::Productions productions = mycc_first_set::FirstSetGenerator::ToProductions(BNF, none_terminal_map); // for(auto p : productions) { // std::cout << p.first << " -> "; // for (auto symbol : p.second) { // if (symbol.isNone_terminal()) { // std::cout << symbol.getType(); // } else { // std::cout << symbol.getName(); // } // std::cout << ' '; // } // std::cout << std::endl; // } mycc_first_set::FirstSets first_sets = mycc_first_set::FirstSetGenerator::getFirstSets(productions, none_terminal_map.size()); for (auto k : none_terminal_map) { std::cout << k.first << " -> "; auto set = first_sets[k.second]; for (const auto &string : set) { std::cout << string << " "; } std::cout << std::endl; } std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; mycc_first_set::FirstSets production_first_sets = mycc_first_set::FirstSetGenerator::getProductionFirstSets(productions, first_sets); for (int i = 0; i < production_first_sets.size(); ++i) { std::cout << i + 1 << ": "; for (const auto& str: production_first_sets[i]) { std::cout << str << " "; } std::cout << std::endl; } }
946b29e12151425e4eae3be9d88369b9adc5978d
b7e47dc1586ddee0acdca9a1d476126ac5aebe28
/OptimiserLib/Optimiser/include/OptimiserFactory.h
acafaa448ccb712c4bc0cd484580f73a7f410c07
[]
no_license
ajpenner/OptimiserLibrary
02b505cc7d49610623f4b4dff9afdb423f1e4469
04c8e263def27d52a9b9e431920125b375908643
refs/heads/master
2020-09-07T11:38:12.955064
2019-11-15T06:44:28
2019-11-15T06:44:28
220,767,682
0
0
null
null
null
null
UTF-8
C++
false
false
1,526
h
OptimiserFactory.h
// OptimiserFactory.h // // 2017 ////////////////////////////////////////////////// #pragma once ////////////////////////////////////////////////// // Constrained #include "OptimiserEllipsoid.h" #include "OptimiserGRG.h" #include "OptimiserPenalty.h" #include "OptimiserMOM.h" #include "OptimiserComplex.h" #include "OptimiserRandom.h" // Unconstrained #include "OptimiserNewton.h" #include "OptimiserBrent.h" #include "OptimiserPowell.h" #include "OptimiserBox.h" #include "OptimiserSimplex.h" #include "OptimiserHJ.h" #include "OptimiserCauchy.h" #include "OptimiserMarquardt.h" #include "OptimiserCG.h" #include <memory> ////////////////////////////////////////////////// namespace eOptimiser { enum type { // Derivative eNewton, eCauchy, eMarquardt, eConjugateGradient, // No derivative eBrent, ePowell, eBox, eSimplex, eHJ, eMax = 255 }; } ////////////////////////////////////////////////// namespace eConstraintOptimiser { enum type { eEllipsoid = 0, eGRG, ePenalty, ePenaltyMOM, eComplex, // does not work eRandom, eMax = 255 }; } ////////////////////////////////////////////////// class OptimiserFactory { public: OPTIMISER static std::unique_ptr<IOptimiser> make_optimiser (eOptimiser::type choice); }; ////////////////////////////////////////////////// class ConstraintOptimiserFactory { public: OPTIMISER static std::unique_ptr<BConstraintOptimiser> make_optimiser (eConstraintOptimiser::type choice); }; //////////////////////////////////////////////////
6e0eb6d358586a83957168b381e52d01d4b9b165
bee03b7a62dd76d965b0cdf95df69bdf9fee7e64
/src/ValueDialog/valuecalc_1106.h
f150d839805b882d6eaed8a3ee3429c9364e3419
[]
no_license
mildrock/QuickTest
586f0479462988806acfa6834af4876df0a21773
137d3d50fec9864917d1d2beffa89daed1327160
refs/heads/master
2020-03-05T09:55:00.772030
2014-12-25T09:19:03
2014-12-25T09:19:03
29,772,936
0
1
null
2015-01-24T10:22:46
2015-01-24T10:22:45
null
UTF-8
C++
false
false
439
h
valuecalc_1106.h
#ifndef VALUECALC_1106_H #define VALUECALC_1106_H #include <QDialog> #include <QPushButton> namespace Ui { class ValueCalc_1106; } class ValueCalc_1106 : public QDialog { Q_OBJECT public: explicit ValueCalc_1106(QWidget *parent = 0); ~ValueCalc_1106(); private slots: void slot_calc(QAbstractButton*); private: Ui::ValueCalc_1106 *ui; void initWindow(); void initSignals(); }; #endif // VALUECALC_1106_H
9a48a28dfafb38429ea8d84541c2b5a78ba32e80
60c173e62b3511dc2dfc4d0c3e56c7ee1255a2ad
/RRT/rrtImpl.h
b42703db45423b0cc243557d7c59b4125ac5e8f5
[ "MIT" ]
permissive
mfkiwl/Fast_RRT-ROS
d8e8177b5a90901e8e5f64445c5e3dd2667e811d
daa6a4a92557ca4bba5108c969f10f335236f7b9
refs/heads/master
2023-01-01T07:09:26.772834
2020-10-27T12:14:05
2020-10-27T12:14:05
null
0
0
null
null
null
null
UTF-8
C++
false
false
6,049
h
rrtImpl.h
// The code was partly adapted from https://ompl.kavrakilab.org/classompl_1_1geometric_1_1RRT.html // #ifndef PROJECT_RRTIMPL_H #define PROJECT_RRTIMPL_H #endif #pragma once #include <iostream> #include <geometry_msgs/Point.h> #include <eigen3/Eigen/Dense> #include <random> struct Node { public: Node() {} Node(geometry_msgs::Point p) : point(p) {} int id; geometry_msgs::Point point; std::vector<Node> children; int parentId; }; class RRT { public: RRT(Node init, Node goal, float sigma, int x_max, int x_min, int y_max, int y_min) : _init(init), _goal(goal), sigma(sigma), x_max(x_max), x_min(x_min), y_max(y_max), y_min(y_min) { nodesList.reserve(1000); nodesList.push_back(init); } geometry_msgs::Point getRandomConfig() { geometry_msgs::Point point; std::random_device rand_dev; std::mt19937 generator(rand_dev()); std::uniform_int_distribution<int> distr(x_min, x_max); point.x = distr(generator); point.y = distr(generator); //todo: check for collisions. return point; } std::map<float, Node> distance_map; Node getNearestNode(geometry_msgs::Point p) { int n_nodes = nodesList.size(); if (n_nodes == 1) { return (nodesList[0]); } distance_map.clear(); for (int i = 0; i < n_nodes; i++) { Node treeNode = nodesList[i]; float d = getEuclideanDistance(p, treeNode.point); distance_map[d] = treeNode; } return distance_map.begin()->second; } /** * * @param p1 * @param p2 * @return euclidean distance between p1 and p2 */ float getEuclideanDistance(geometry_msgs::Point p1, geometry_msgs::Point p2) { return std::sqrt(std::pow((p1.x - p2.x), 2) + std::pow((p1.y - p2.y), 2)); } /** * * @param p1 nearest point * @param p2 random config * @return point P which is in sigma distance to p1 in the direction of p2 */ Node expand(Node p1, Node p2, std::vector<visualization_msgs::Marker> obsVec, int frameid) { //calculate the slope float m, nume, denom; if (p1.point.x != p2.point.x) { nume = (p2.point.y - p1.point.y); denom = (p2.point.x - p1.point.x); m = nume / denom; } float theta = atan(m); if (theta < 0) { if (denom < 0) { theta = theta + M_PI; } else { theta = theta + 2 * M_PI; } } else { if ((nume < 0) && (denom < 0)) { theta = theta + M_PI; } } float sin_theta = sin(theta); float cos_theta = cos(theta); //calculate P Node p; p.point.y = sigma * sin_theta + p1.point.y; p.point.x = sigma * cos_theta + p1.point.x; p.point.z = 0; p.id = frameid; // calculate if the point is within an obstacle if (!intersectsObs(p1.point, p.point, obsVec) && isWithinWorld(p.point)) { std::vector<Node>::iterator it = parentList.begin(); it = parentList.insert(it, p1); p.parentId = p1.id; p1.children.push_back(p); //children of init is not in the nodeslist nodesList.push_back(p); return p; } return p1; } bool isWithinWorld(geometry_msgs::Point p) { return (p.x > this->x_min && p.x < this->x_max && p.y > this->y_min && p.y < this->y_max); } bool intersectsObs(geometry_msgs::Point p1, geometry_msgs::Point p2, std::vector<visualization_msgs::Marker> obsVec) { float x1 = p1.x; float y1 = p1.y; float x2 = p2.x; float y2 = p2.y; for (int i = 0; i < obsVec.size(); i++) { visualization_msgs::Marker obs = obsVec[i]; float obs_xl = (obs.pose.position.x - obs.scale.x / 2) - 0.5; float obs_xr = (obs.pose.position.x + obs.scale.x / 2) + 0.5; float obs_yb = (obs.pose.position.y - obs.scale.y / 2) - 0.5; float obs_yt = (obs.pose.position.y + obs.scale.y / 2) + 0.5; //check for the bottom intersection bool bottom = lineIntersect(x1, y1, x2, y2, obs_xl, obs_yb, obs_xr, obs_yb); //left intersect bool left = lineIntersect(x1, y1, x2, y2, obs_xl, obs_yb, obs_xl, obs_yt); //right intersect bool right = lineIntersect(x1, y1, x2, y2, obs_xr, obs_yb, obs_xr, obs_yt); //top intersect bool top = lineIntersect(x1, y1, x2, y2, obs_xl, obs_yt, obs_xr, obs_yt); if (bottom || left || right || top) { return true; } } return false; } bool lineIntersect(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { // calculate the distance to intersection point float uA = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1)); float uB = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1)); // if uA and uB are between 0-1, lines are colliding if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) { float intersectionX = x1 + (uA * (x2 - x1)); float intersectionY = y1 + (uA * (y2 - y1)); return true; } return false; } std::vector<Node> getNodesList() { return this->nodesList; } private: Node _init, _goal; float sigma; int x_max; int x_min; int y_max; int y_min; std::vector<Node> nodesList; std::vector<Node> parentList; };
b78b0c22738a406bdb00845f90f9fc87398a75aa
0eb5062cf88cab9a1361162f6bb2f2fef2f561bf
/16MulticastConfiable/16MulticastConfiable/PaqueteDatagrama.cpp
e234b9b7f8ae4bf56fdc4e7fe0e6dd914eb7cf8a
[]
no_license
abiisnn/DistributedSystems
7461c37a094d1274ce97ca3087dfa05bb60cea2f
5f022d6152c13377466297a6ac7e81953cd082c1
refs/heads/master
2020-07-07T06:29:30.711298
2019-11-25T17:44:01
2019-11-25T17:44:01
203,277,802
1
0
null
null
null
null
UTF-8
C++
false
false
945
cpp
PaqueteDatagrama.cpp
#include <bits/stdc++.h> #include "PaqueteDatagrama.h" using namespace std; PaqueteDatagrama::PaqueteDatagrama(char* data, unsigned int longi,char* ip_envio, int puerto_envio){ datos = new char[longi]; strcpy(ip, ip_envio); memcpy(datos, data,longi); puerto = puerto_envio; longitud = longi; } PaqueteDatagrama::PaqueteDatagrama(unsigned int longi){ longitud = longi; datos = new char[longitud]; } PaqueteDatagrama::~PaqueteDatagrama(){ delete [] datos; } int PaqueteDatagrama::obtienePuerto(){ return puerto; } char* PaqueteDatagrama::obtieneDireccion(){ return ip; } unsigned int PaqueteDatagrama::obtieneLongitud(){ return longitud; } char* PaqueteDatagrama::obtieneDatos(){ return datos; } void PaqueteDatagrama::inicializaPuerto(int p){ puerto = p; } void PaqueteDatagrama::inicializaIp(char* ip_envio){ strcpy(ip, ip_envio); } void PaqueteDatagrama::inicializaDatos(char* data){ memcpy(datos, data,longitud); }
b08c3101459e4abed0c8179c1851e9e3a8e21788
93478c3082ebbd464bcee1b08e3ea5df7beb0839
/elements.hpp
49c7041c3bcb858bf487a1fd3c45d8925ccbe67a
[ "MIT" ]
permissive
5cript/cppdom
da59ff2e4c646fd2cd8e5f06ef42b0e159f64eb0
03e257d62f2b939544c5d1c2d8718e58f2d71e34
refs/heads/main
2023-02-15T16:07:22.829662
2021-01-10T14:39:25
2021-01-10T14:39:25
310,899,282
1
0
null
null
null
null
UTF-8
C++
false
false
469
hpp
elements.hpp
#pragma once #include "elements/div.hpp" #include "elements/button.hpp" #include "elements/text.hpp" #include "elements/a.hpp" #include "elements/sectioning.hpp" #include "elements/content.hpp" #include "elements/embedded.hpp" #include "elements/forms.hpp" #include "elements/interactive.hpp" #include "elements/media.hpp" #include "elements/scripting.hpp" #include "elements/sectioning.hpp" #include "elements/svgmath.hpp" #include "elements/table.hpp"
088d4e5c2b9d7be2361e621df035db199b67c482
8bf42e92730710e49e79f67d9efcf755a3bdf58f
/CPP/D04/ex01/Character.hpp
994c2bab51f3e9a875467b8795c03e96d25ec2f7
[]
no_license
tlepeche/Piscines
6d3565ffdd02906d019081151c614a22cffff9e5
abe7260f948aa2dbb7d3037cf688b997562ae725
refs/heads/master
2020-12-31T05:55:36.685193
2016-04-28T15:19:05
2016-04-28T15:19:05
57,311,133
0
0
null
null
null
null
UTF-8
C++
false
false
1,474
hpp
Character.hpp
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* Character.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tlepeche <tlepeche@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2015/06/19 13:25:06 by tlepeche #+# #+# */ /* Updated: 2015/06/19 14:46:46 by tlepeche ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef CHARACTER_HPP #define CHARACTER_HPP #include <fstream> #include "AWeapon.hpp" #include "Enemy.hpp" class Character { public: Character(std::string const & name); Character(Character & src); ~Character(); void recoverAP(); void equip(AWeapon*); void attack(Enemy*); std::string getName() const; int getAP() const; AWeapon * getWeapon() const; Character & operator=(Character const &); protected: Character(); std::string _Name; int _AP; AWeapon *_Weap; }; std::ostream & operator<<(std::ostream & lhs, Character const & rhs); #endif
81e2652110ccb57f704753ee54d8eed9a99173e7
36c00fe2afff4818c937e312ce0c6a79f35e2a77
/8-kyu/invert-values/c++/solution.cpp
b3f0f62a30fb3066f41455e690e0e95e51205058
[]
no_license
p-lots/codewars
0a67b6ee4c91180ff78c648421b9d2d64463ddc3
535faeee475c6b398124d6f5002b0e111406e8bb
refs/heads/master
2023-08-23T22:14:33.635011
2023-08-23T13:30:37
2023-08-23T13:30:37
195,320,309
0
0
null
2023-05-09T19:25:50
2019-07-05T01:40:15
Python
UTF-8
C++
false
false
263
cpp
solution.cpp
#include <algorithm> #include <vector> std::vector<int> invert(std::vector<int> values) { if (values.empty()) return std::vector<int>(); std::transform(values.begin(), values.end(), values.begin(), [](int &n) { return -n; }); return values; }
cd1ba7df0683fd62673fc9f2c4f026068cb4c07a
d41d5a4944f83c363b624e050d68c4ded1d656d0
/Wireframe/homogeneous_point3D.h
0b7d3b4c081a3b51ccf891f39c1c4d31d7701b3c
[]
no_license
ALikhachev/Computer-graphics
140e434115617e541016e5dbd39bb56f688a258a
f5e26ccd0f030d43f69f507dbc2ba8bbc3ab2752
refs/heads/master
2021-01-24T06:43:26.766854
2017-04-13T16:26:51
2017-06-04T13:56:04
93,315,613
0
1
null
null
null
null
UTF-8
C++
false
false
549
h
homogeneous_point3D.h
#ifndef HOMOGENEOUS_POINT3D_H #define HOMOGENEOUS_POINT3D_H #include <QVector3D> #include <QVector4D> #include <QSharedPointer> #include "transform.h" class Transform; class HomogeneousPoint3D { public: HomogeneousPoint3D(float x, float y, float z); const QVector3D to3D() const; QVector4D &to4D(); HomogeneousPoint3D &applyTransform(QSharedPointer<Transform> transform); HomogeneousPoint3D &applyTransform(Transform *transform); void normalize(); private: QVector4D _coordinates; }; #endif // HOMOGENEOUS_POINT3D_H
9e901d57bc795ddefadfb4c4f7b4f36ac29fc6cc
d007578440d72dbb3a354cef461c935e8dc64c44
/src/world/world.hpp
b4939d7eab46e271d676d9af1a93e9bf4d9bc555
[]
no_license
brendanfh/webassembly-game
4b26ae7eb29857a96e8af8a7f6f0e809f9a5b2a7
da1e6a45f47f4013fd84f9b1a83a6708bf5b28b3
refs/heads/master
2021-09-03T23:24:48.320656
2018-01-12T19:39:49
2018-01-12T19:39:49
109,322,459
0
0
null
null
null
null
UTF-8
C++
false
false
6,489
hpp
world.hpp
#ifndef __WORLD_H_ #define __WORLD_H_ #include "../gfx.hpp" #include "../utils/rect.hpp" #include "tilemap.hpp" #include "../utils/idmanager.hpp" #include <iostream> #include <vector> #include <algorithm> class World; class Entity; using namespace std; enum class EntityType { Unknown, Player, Enemy, Bullet, Particle }; class Entity { friend World; private: virtual bool Move2(vector<Entity*>* ents, float dx, float dy) final; protected: EntityType type; Gfx::Quad* quad; Rect* collRect; int health; bool alive; bool solid; virtual void UpdateCollRect() { collRect->Set(x, y, collRect->w, collRect->h); } public: float x; float y; World* world; Entity() { type = EntityType::Unknown; quad = new Gfx::Quad(-1); health = 0; solid = true; alive = true; collRect = new Rect(0.0f, 0.0f, 0.0f, 0.0f); } ~Entity() { delete quad; delete collRect; } void SetRenderOrder(int renderOrder) { if (renderOrder < quad->id) { float x, y, w, h; quad->GetRect(x, y, w, h); quad->SetRect(0, 0, 0, 0); quad->BufferData(); quad->SetSize(w, h); UpdateDrawRects(); } quad->id = renderOrder; } Rect* GetCollisionRect() { return collRect; } EntityType GetType() { return type; } bool IsAlive() { return alive; } virtual void UpdateDrawRects() { quad->SetPos(x, y); } void Move(float dx, float dy, int steps); virtual void OnTileCollision(int tx, int ty, float dx, float dy) { x -= dx; y -= dy; } virtual void OnEntityCollision(Entity* other, float dx, float dy) { x -= dx; y -= dy; } virtual void Hurt(int damage) { health -= damage; if (health <= 0) alive = false; } virtual void Tick(float dt) { } virtual void Render() { } }; class World { private: vector<Entity*> entities; Tilemap* tilemap; public: friend World* loadWorld(string path); Entity* player; World() { entities = vector<Entity*>(); tilemap = new Tilemap(20, 20); } ~World() { vector<Entity*>::iterator it; for (it = entities.begin(); it != entities.end(); it++) { delete *it; } //delete entities; } Tilemap* GetTilemap() { return tilemap; } void AddEntity(Entity* entity) { entity->world = this; if (entity->type == EntityType::Player) { player = entity; } entities.push_back(entity); } void RemoveEntity(Entity* entity) { int i; for (i = 0; i < entities.size(); i++) { if (entities[i] == entity) { break; } } delete *(entities.begin() + i); entities.erase(entities.begin() + i); } vector<Entity*>* EntsInRange(float x, float y, float r) { float r2 = r * r; vector<Entity*>* ents = new vector<Entity*>(); std::for_each(entities.begin(), entities.end(), [=](Entity*& e) { if (!e->solid) return; float dx = (e->x - x); float dy = (e->y - y); if (dx * dx + dy * dy < r2) { ents->push_back(e); } }); return ents; } void Tick(float dt) { for (int i = 0; i < entities.size(); i++) { entities[i]->Tick(dt); if (!entities[i]->IsAlive()) { RemoveEntity(entities[i]); } } } void Render() { std::sort(entities.begin(), entities.end(), [](Entity* a, Entity* b) { return a->collRect->y < b->collRect->y; }); float px, py; std::any_of(entities.begin(), entities.end(), [&](Entity* a) { if (a->GetType() == EntityType::Player) { px = a->x; py = a->y; return true; } return false; }); //Tilemap::Render returns how many ids it used IdMng::Use(0); tilemap->Render(px, py); for (int i = 0; i < entities.size(); i++) { entities[i]->SetRenderOrder(IdMng::Next()); entities[i]->Render(); } } }; //This has to be at the bottom because it references "RectsInRange", which has not been defined at the top yet. void Entity::Move(float dx, float dy, int steps) { float ddx = dx / steps; float ddy = dy / steps; vector<Entity*>* ents = world->EntsInRange(x + 0.5f, y + 0.5f, 2.0f + (dx * dx + dy * dy)); Entity* tmp; int tx, ty; bool xdone = false; bool ydone = false; for (int i = 0; i < steps; i++) { if (!xdone && ddx != 0) { xdone = Move2(ents, ddx, 0); } if (!ydone && ddy != 0) { ydone = Move2(ents, 0, ddy); } } this->UpdateCollRect(); delete ents; } bool Entity::Move2(vector<Entity*>* ents, float dx, float dy) { x += dx; y += dy; Entity* tmp; int tx, ty; this->UpdateCollRect(); bool collided = false; collided = any_of(ents->begin(), ents->end(), [&](Entity* e) mutable { if (e == this) return false; tmp = e; return e->collRect->Intersects(*this->collRect); }); if (collided) { OnEntityCollision(tmp, dx, dy); this->UpdateCollRect(); return true; } else { int xx = floor(x / TILE_SIZE); int yy = floor(y / TILE_SIZE); for (int yt = yy - 2; yt <= yy + 2; yt++) { for (int xt = xx - 2; xt <= xx + 2; xt++) { Tile* tile = world->GetTilemap()->GetTile(xt, yt); if (tile == NULL) continue; if (!tile->IsSolid()) continue; if (tile->GetRect(xt, yt).Intersects(*collRect)) { OnTileCollision(xt, yt, dx, dy); return true; } } } } return false; } #endif
010f04ff13518ecd10f301b0bea58d6133ac35a2
f765ce50ed9c80eb0c43275291f39bde062d8994
/Globals.h
657c2c899894fe645dcb09a595bf125afe3f4aab
[]
no_license
NeilOsbaldeston/Hover-Racing
059d15da1f9b6f61b0244a22b3310ac378dd6644
8703729f1ce4a090b01d899735a39a27d6124d73
refs/heads/master
2020-06-11T11:40:34.789008
2016-12-05T23:40:45
2016-12-05T23:40:45
75,676,053
0
0
null
null
null
null
UTF-8
C++
false
false
14,715
h
Globals.h
// Neil Osbaldeston #pragma once #include <TL-Engine.h> using namespace tle; ////////////// // States // ////////////// enum class GameStates { PLAYING, PAUSED, MENU }; enum class RaceStates { NOT_STARTED, IN_PROGRESS, FINISHED }; enum class MenuStates { MAIN_MENU, RACE_SETUP, EDITOR_SETUP, HIGH_SCORES, OPTIONS }; enum class CarState { NONE, TURNING_LEFT, TURNING_RIGHT, ACCELERATING_FORWARD, ACCELERATING_BACKWARD }; ////////////////// // Resolutions // ////////////////// const int FULLSCREEN_WIDTH = 1920; const int FULLSCREEN_HEIGHT = 1080; const int TITLEBAR_CORRECTION = (FULLSCREEN_HEIGHT / 1000) * 30; const int BORDER_CORRECTION = FULLSCREEN_HEIGHT / 100; const int WINDOWED_WIDTH = 1600; const int WINDOWED_HEIGHT = 900; const bool FULLSCREEN = false; ////////////////// // Key bindings // ////////////////// // system const EKeyCode ESCAPE = Key_Escape; const EKeyCode PAUSE = Key_P; const EKeyCode SELECT = Mouse_LButton; // car controls const EKeyCode FORWARD = Key_W; const EKeyCode BACKWARD = Key_S; const EKeyCode LEFT = Key_A; const EKeyCode RIGHT = Key_D; const EKeyCode BOOST = Key_Space; // camera controls const EKeyCode CAM_FORWARD = Key_Up; const EKeyCode CAM_BACKWARD = Key_Down; const EKeyCode CAM_LEFT = Key_Left; const EKeyCode CAM_RIGHT = Key_Right; const EKeyCode CAM_RESET_FOLLOW = Key_1; const EKeyCode CAM_RESET_COCKPIT = Key_2; // race controls const EKeyCode START_RACE = Key_Space; const EKeyCode TOGGLE_DEBUG_INFO = Key_F1; // track builder const EKeyCode SELECT_PLACE = Mouse_LButton; const EKeyCode DELETE_MODEL = Mouse_RButton; const EKeyCode PLACE_MODEL = Key_Return; const EKeyCode SCALE_UP = Key_Plus; const EKeyCode SCALE_DOWN = Key_Minus; const EKeyCode MOVE_OUT = Key_E; const EKeyCode MOVE_IN = Key_Q; const EKeyCode FLOOR_OVERIDE = static_cast<EKeyCode>(0x10); // shift const EKeyCode WALL_OVERIDE = Key_Tab; // allows normal camera movement when handling wall pieces const EKeyCode ROTATE_LEFT = Key_Left; // template rotation const EKeyCode ROTATE_RIGHT = Key_Right; // template rotation const EKeyCode ROTATE_UP = Key_Up; // template rotation const EKeyCode ROTATE_DOWN = Key_Down; // template rotation ////////////// // Menu // ////////////// const int MENU_SPACING = 60; // from the centre of one menu option to the centre of the next const int MENU_BOX_SPACING = 100; const int BOX_TEXT_X_OFFSET = 10; const int BOX_TEXT_Y_OFFSET = 10; const int TRACKS_SHOWN_MAX = 5; // how many tracks will be displayed in the track list (can be scrolled up and down through the list) const int SCROLLBAR_WIDTH = 40; ////////////////////// // Object sizes // ////////////////////// const int MAP_WIDTH = 2000; // map will be MAP_WIDTH X MAP_WIDTH const int MAP_GRID_SIZE = 20; // map must be MAP_GRID_SIZE X MAP_GRID_SIZE or grid must be big enough to hold the map as a square const int SECTOR_SIZE = MAP_WIDTH / MAP_GRID_SIZE; const float WAYPOINT_RADIUS2 = 10.0f; // used in track editor only const float START_POINT_RADIUS2 = 10.0f; // used in track editor only const float CHECKPOINT_RADIUS2 = 95.0f; // 9.74 radius squared (stage check only) const float HOVERCAR_RADIUS = 6.5f / 2.3f; const float HOVERCAR_RADIUS2 = 42.25f / 2.3f; // 6.5 radius const float TANK_SMALL_1_RADIUS2 = 9.86f; // 3.14 radius const float TANK_SMALL_2_RADIUS2 = 9.74f; // 3.12 radius const float TRIBUNE_1_RADIUS2 = 150.0f; // 21.85 radius , 5.0 radius at the bottom const float FLARE_RADIUS2 = 1.0f; // 1.0 radius const float TREE_RADIUS2 = 10.0f; const float HOVERCAR_WIDTH = 4.46f; const float HOVERCAR_LENGTH = 12.92f; const float CHECKPOINT_WIDTH = 17.15f; // between the centre of each pillar const float CHECKPOINT_PILLAR_RADIUS2 = 1.65f; // 1.285 radius const float CHECKPOINT_HEIGHT = 10.6f; const float WALL_WIDTH = 1.868f; const float WALL_LENGTH = 9.67f; const float WALL_HEIGHT = 4.52f; const float ISLE_STRAIGHT_WIDTH = 5.35f; const float ISLE_STRAIGHT_LENGTH = 6.83f; const float ISLE_STRAIGHT_HEIGHT = 5.44f; const float GARAGE_LARGE_WIDTH = 20.0f; const float GARAGE_LARGE_LENGTH = 13.85f; const float GARAGE_SMALL_WIDTH = 10.2f; const float GARAGE_SMALL_LENGTH = 9.85f; const float ISLE_CORNER_RADIUS2 = 25.0f; // 5.0f radius const float ISLE_CROSS_RADIUS2 = 32.49f; // 5.7f radius const float ISLE_TEE_RADIUS2 = 25.0f; // 5.0f radius const float LAMP_RADIUS2 = 0.593f; // 0.77f radius const float TANK_LARGE_1_RADIUS2 = 20.25f; // 4.5f radius const float TANK_LARGE_2_RADIUS2 = 16.0f; // 4.0f radius const float TRIBUNE_2_PILLAR_RADIUS2 = 25.0f; const float TRIBUNE_3_PILLAR_RADIUS2 = 25.0f; const float WALKWAY_WIDTH = 3.2f; const float WALKWAY_LENGTH = 4.4f; const float SKYBOX_WIDTH = 2000.0f; const float SKYBOX_BOUNDARY = 50.0f; // the size of the gap between the skybox and the cars collision boundary ////////////////// // Hover Car // ////////////////// const float DEFAULT_START_XPOS = 0.0f; const float DEFAULT_START_YPOS = 2.7f; const float DEFAULT_START_ZPOS = 0.0f; const float START_ANGLE_OFFSET = 10.0f; // the nose dip const float MOVE_MULTIPLIER = 150.0f; // increase the drift vector to a usable amount const float FORWARD_DRAG = 0.3f; // decay factor const float DRIFT_DRAG = 0.3; // decay factor const float BOUNCE_DAMPENING = 3.0f; // reduces the bounce vector by a factor const float BOUNCE_CAR_DAMPENING = 4.0f; // reduces the additional bounce vector by a factor const float FORWARD_ACCELERATION = 1.0f; // units per second per second const float BACKWARD_ACCELERATION = 0.6f; // units per second per second const float GRAVITY = 5.0f; // units per second per second const float LOW_GRAVITY = 1.0f; const float HOVER_STRENGTH_FULL = 3.0f; // distance from ground the car can maintain a hover const float HOVER_STRENGTH_MIN = 15.0f; // the distance from the ground when the hover engines start to reduce fall speed const float PORPOISE_CONTROL = 1.015f; // anti grav strength before dampening is activated (1.0f for completely stable) const float STRENGTH_MULTI = 6.0f; // only used to settle the car quicker after falling const float GRAVITY_CHANGE_MIN = 0.98f; // min hover strength value at which gravity will be altered to make the car bounce slower const float GRAVITY_CHANGE_MAX = 1.02f; // max hover strength value at which gravity will be altered to make the car bounce slower const float TERMINAL_VELOCITY = 50.0f; // max fall speed for the cars const float TURN_SPEED = 50.0f; // units per second const float ROLL_SPEED = 80.0f; // units per second const float RESET_ROLL_SPEED = 30.0f; // units per second const float MAX_ROLL = 40.0f; // amount the hover car can lean over in degrees const float PITCH_SPEED = 10.0f; // units per second const float RESET_PITCH_SPEED = 10.0f; // units per second const float MAX_FOWARD_PITCH = 8.0f; // the angle the car will tilt forward at when moving backwards const float MAX_BACKWARD_PITCH = 12.0f; // the angle the car will tilt back at when moving forward const float START_GRID_X_SPACING = 20.0f; // how far apart, left to right, the cars are on the start line const float START_GRID_Z_SPACING = 30.0f; // how far apart, front to back, the cars are on the start line const float STARTING_HITPOINTS = 100.0f; const float DAMAGE_MULTIPLIER = 3.0f; const float ROTATION_VEL_MIN = 10.0f; const float ROTATION_VEL_MAX = 150.0f; // the max amount of rotation that can be applied at any time after a collision const float ROTATION_MULTI = 30.0f; // how fast the rotation will be const float ROTATION_VEL_DECAY = 400.0f; // how quickly the rotation will slow const float COL_RES_DIVISION = 10.0f; // how much to increment the reverse direction by after a collision const int ENGINE_PARTICLE_COUNT = 40; const float ENGINE_PARTICLE_LIFETIME = 0.02f; const float ENGINE_PARTICLE_SCALE = 0.15f; const float ENGINE_PARTICLE_TIME_OFFSET = 0.002f; const float ENGINE_PARTICLE_GRAVITY = 0.0f; const int ENGINE_PARTICLE_MIN_VEL = 35; const int ENGINE_PARTICLE_MAX_VEL = 45; const int ENGINE_PARTICLE_MIN_SPRAY_ANGLE = 0; const int ENGINE_PARTICLE_MAX_SPRAY_ANGLE = 10; const int ENGINE_PARTICLE_MIN_CONE_ANGLE = -180; const int ENGINE_PARTICLE_MAX_CONE_ANGLE = 180; const int ENGINE_PARTICLE_Z_OFFSET = 80; // is divided by 100 const int ENGINE_PARTICLE_STARTING_MAX_RADIUS = 50; // is divided by 100 const float ENGINE_PARTICLE_EXHAUST_Y = 2.7f; const float ENGINE_PARTICLE_EXHAUST_Z = -7.5f; const float ENGINE_PARTICLE_EXHAUST_X_OFFSET = -0.5f; ////////////// // PLAYER // ////////////// const float FORWARD_MAX_SPEED = 1.42f; const float BACKWARD_MAX_SPEED = -0.41f; const float BOOST_HEAT_LIMIT = 3.0f; // how long in seconds before the booster over-heats const float BOOST_RECHARGE_SPEED = 4.0f; // how many times slower than the useage const float BOOST_RECHARGE_OVERHEAT = 8.0f; // how many times slower than the useage const float BOOST_MAX_PITCH = 18.0f; // the angle the car will tilt back at when boosting forward const float BOOST_MAX_SPEED = 2.02f; const float BOOST_ACCELERATION = 1.6f; // units per second per second const float BOOSTER_TIMEOUT = 8.0f; // how long after an over-heat you can use your booster again const float DECELERATION_PERIOD = 3.0f; // how long after an over-heat your engines will start working again const int BOOST_PARTICLE_COUNT = 50; const float BOOST_PARTICLE_LIFETIME = 0.03f; const float BOOST_PARTICLE_SCALE = 0.1f; const float BOOST_PARTICLE_TIME_OFFSET = 0.002f; const float BOOST_PARTICLE_GRAVITY = 0.0f; const int BOOST_PARTICLE_MIN_VEL = 40; const int BOOST_PARTICLE_MAX_VEL = 50; const int BOOST_PARTICLE_MIN_SPRAY_ANGLE = -5; const int BOOST_PARTICLE_MAX_SPRAY_ANGLE = 5; const int BOOST_PARTICLE_MIN_CONE_ANGLE = -180; const int BOOST_PARTICLE_MAX_CONE_ANGLE = 180; const int BOOST_PARTICLE_Z_OFFSET = 80; // is divided by 100 const int BOOST_PARTICLE_STARTING_MIN_RADIUS = 50; // is divided by 100 const int BOOST_PARTICLE_STARTING_MAX_RADIUS = 75; // is divided by 100 ////////// // AI // ////////// const float AI_MAX_SPEED = 1.4f; const float AI_ACCEL = 1.0f; const float AI_ACCEL_ANGLE_EIGHTH = 60.0f; // (degrees) accelerate the AI car at an eighth speed if the angle to // the next way point is below this but above AI_ACCEL_ANGLE_QUARTER const float AI_ACCEL_ANGLE_QUARTER = 40.0f; const float AI_ACCEL_ANGLE_HALF = 20.0f; // (degrees) accelerate the AI car at half speed if the angle to // the next way point is below this but above AI_ACCEL_ANGLE_FULL const float AI_ACCEL_ANGLE_FULL = 10.0f;// (degrees) accelerate the AI car at full speed as long as the // angle to the next way point is below this const float AI_TURN_DAMPING = 40.0f; // the angle at which the AI will start to turn less towards its target const float AI_WAYPOINT_RADIUS2 = CHECKPOINT_RADIUS2; // distance from waypoint to activate next waypoint ////////////// // Bombs // ////////////// const int BOMB_PARTICLE_COUNT = 200; const float BOMB_PARTICLE_LIFETIME = 0.3f; const float BOMB_PARTICLE_SCALE = 0.01f; const float BOMB_PARTICLE_GRAVITY = 5.0f; const int BOMB_PARTICLE_MIN_VEL = 50; const int BOMB_PARTICLE_MAX_VEL = 150; const int BOMB_PARTICLE_MIN_SPRAY_ANGLE = 0; const int BOMB_PARTICLE_MAX_SPRAY_ANGLE = 90; const int BOMB_PARTICLE_MIN_CONE_ANGLE = -180; const int BOMB_PARTICLE_MAX_CONE_ANGLE = 180; const float BOMB_BLAST_RADIUS2 = 1500.0f; // squared const float BOMB_BLAST_STRENGTH = 10.0f; // throw strength const float BOMB_BLAST_DAMAGE = 6.0f; // dmg multiplier ////////////// // Camera // ////////////// const float CAM_DEFAULT_ANGLE = 10.0f; const float CAM_DEFAULT_HEIGHT = 10.0f; const float CAM_DEFAULT_Z_OFFSET = -30.0f; const float CAM_MOVE_SPEED = 50.0f; const float CAM_ROTATE_SPEED = 0.02f; const float CAM_ROTATE_SPEED_EDITOR = 100.0f; const float CAM_COCKPIT_YPOS = 5.0f; const float CAM_COCKPIT_ZPOS = 1.0f; const float CAM_EDITOR_SIDE_WIDTH = 50.0f; // far from the edge of the screen before the camera starts to rotate ////////////// // Editor // ////////////// const float TEMPLATE_START_DISTANCE = 40.0f; const float MOVE_DISTANCE_SPEED = 50.0f; const int UI_HIT_BOX = 50; // pixels from centre in X and Y const float TEMPLATE_ROTATION_SPEED = 20.0f; const float SCALE_SPEED = 0.8f; // per second const int TRACK_NAME_INPUT_XPOS = 500; const int TRACK_NAME_INPUT_YPOS = 400; const int UI_FIRST_COLUMN_POS = 100; const int UI_SECOND_COLUMN_POS = 200; const int UI_THIRD_COLUMN_POS = 300; const float TRACK_SAVED_MAX_TIME = 2.0f; ////////////// // Other // ////////////// const int MENU_TITLE_WIDTH = 1000; const float MENU_TITLE_Y_POS = 100.0f; // distance from the top of the screen const float GAME_SPEED = 1.0f; // 1 is normal speed const float SKYBOX_YPOS = -960.0f; const float RACE_START_COUNTDOWN_TIME = -3.0f; // what the count down starts at to begin a race const float GO_SHOW_TIME = 2.0f; // how long the "GO!" stays on the screen after the race starts const float CROSS_EXPIRE_TIME = 5.0f; // how long after creation a cross is removed from its check point const float CROSS_SCALE = 0.3f; const float CROSS_X_POSITION_OFFSET = 5.0f; const std::string PRESS_TO_START = "Press space to start..."; const std::string GO = "Go!"; const std::string RACE_RESULTS = "Race Results"; const float PI = 3.142f; ////////////////////// // model classes // ////////////////////// class Sphere { private: Sphere() { } public: IModel* model; float scalar; float radius2; Sphere(IModel* mod, float scal, float rad) : model(mod), scalar(scal), radius2(rad) { } Sphere(const Sphere& sourse) { model = sourse.model; scalar = sourse.scalar; radius2 = sourse.radius2; } }; class Box { private: Box() { } public: IModel* model; float scalar; float width; float length; Box(IModel* mod, float scal, float wid, float len) : model(mod), scalar(scal), width(wid), length(len) { } Box(const Box& sourse) { model = sourse.model; scalar = sourse.scalar; width = sourse.width; length = sourse.length; } }; // for track builder UI models class UIBox { public: string name; IMesh* mesh; IModel* model; int xPos; int yPos; int size; UIBox(string name = "", IMesh* mesh = nullptr, IModel* mod = nullptr, int xPos = 0, int yPos = 0, int width = 0) : name(name), mesh(mesh), model(mod), xPos(xPos), yPos(yPos), size(width) { } };
a2398397e87e78556bae57b8f9a9435370ec301e
ee493d77d764534fd616de3954bfac816dc882ed
/mordor/socket.cpp
a17bdc39ad53f367171cf4aeaa6ab12c9638fdd4
[ "BSD-3-Clause", "LicenseRef-scancode-unknown-license-reference" ]
permissive
cgaebel/mordor
576854738d1da4fbfc8a66e7b04f644d27c65333
726c63d2f015071aea656dd0b979cdfe7e2ab534
refs/heads/master
2021-01-19T02:35:43.083599
2010-10-20T21:23:05
2010-10-21T14:30:33
1,015,107
2
0
null
null
null
null
UTF-8
C++
false
false
58,236
cpp
socket.cpp
// Copyright (c) 2009 - Mozy, Inc. #include "mordor/pch.h" #include "socket.h" #include <boost/bind.hpp> #include "assert.h" #include "exception.h" #include "log.h" #include "mordor/string.h" #include "version.h" #ifdef WINDOWS #include <mswsock.h> #include "eventloop.h" #include "runtime_linking.h" #pragma comment(lib, "ws2_32") #pragma comment(lib, "mswsock") #else #include <fcntl.h> #include <netdb.h> #define closesocket close #endif namespace Mordor { namespace { enum Family { UNSPECIFIED = AF_UNSPEC, IP4 = AF_INET, IP6 = AF_INET6 }; enum Type { STREAM = SOCK_STREAM, DATAGRAM = SOCK_DGRAM }; enum Protocol { ANY = 0, TCP = IPPROTO_TCP, UDP = IPPROTO_UDP }; std::ostream &operator <<(std::ostream &os, Family family) { switch (family) { case UNSPECIFIED: return os << "AF_UNSPEC"; case IP4: return os << "AF_INET"; case IP6: return os << "AF_INET6"; default: return os << (int)family; } } std::ostream &operator <<(std::ostream &os, Type type) { switch (type) { case STREAM: return os << "SOCK_STREAM"; case DATAGRAM: return os << "SOCK_DGRAM"; default: return os << (int)type; } } std::ostream &operator <<(std::ostream &os, Protocol protocol) { switch (protocol) { case TCP: return os << "IPPROTO_TCP"; case UDP: return os << "IPPROTO_UDP"; default: return os << (int)protocol; } } } #ifdef WINDOWS static LPFN_ACCEPTEX pAcceptEx; static LPFN_GETACCEPTEXSOCKADDRS pGetAcceptExSockaddrs; static LPFN_CONNECTEX ConnectEx; namespace { static struct Initializer { Initializer() { WSADATA wd; WSAStartup(MAKEWORD(2,2), &wd); socket_t sock = socket(AF_INET, SOCK_STREAM, 0); DWORD bytes = 0; GUID acceptExGuid = WSAID_ACCEPTEX; WSAIoctl(sock, SIO_GET_EXTENSION_FUNCTION_POINTER, &acceptExGuid, sizeof(GUID), &pAcceptEx, sizeof(LPFN_ACCEPTEX), &bytes, NULL, NULL); GUID getAcceptExSockaddrsGuid = WSAID_GETACCEPTEXSOCKADDRS; WSAIoctl(sock, SIO_GET_EXTENSION_FUNCTION_POINTER, &getAcceptExSockaddrsGuid, sizeof(GUID), &pGetAcceptExSockaddrs, sizeof(LPFN_GETACCEPTEXSOCKADDRS), &bytes, NULL, NULL); GUID connectExGuid = WSAID_CONNECTEX; WSAIoctl(sock, SIO_GET_EXTENSION_FUNCTION_POINTER, &connectExGuid, sizeof(GUID), &ConnectEx, sizeof(LPFN_CONNECTEX), &bytes, NULL, NULL); closesocket(sock); } ~Initializer() { WSACleanup(); } } g_init; } #endif static Logger::ptr g_log = Log::lookup("mordor:socket"); Socket::Socket(IOManager *ioManager, int family, int type, int protocol, int initialize) : m_sock(-1), m_family(family), m_protocol(protocol), m_ioManager(ioManager), m_receiveTimeout(~0ull), m_sendTimeout(~0ull), m_cancelledSend(0), m_cancelledReceive(0) #ifdef WINDOWS , m_eventLoop(NULL), m_hEvent(NULL), m_scheduler(NULL) #endif { #ifdef WINDOWS if (pAcceptEx && m_ioManager) { m_sock = socket(family, type, protocol); MORDOR_LOG_LEVEL(g_log, m_sock == -1 ? Log::ERROR : Log::DEBUG) << this << " socket(" << (Family)family << ", " << (Type)type << ", " << (Protocol)protocol << "): " << m_sock << " (" << lastError() << ")"; if (m_sock == -1) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("socket"); } #endif } #ifdef WINDOWS Socket::Socket(EventLoop *eventLoop, int family, int type, int protocol, int initialize) : m_sock(-1), m_family(family), m_protocol(protocol), m_ioManager(NULL), m_receiveTimeout(~0ull), m_sendTimeout(~0ull), m_cancelledSend(0), m_cancelledReceive(0), m_eventLoop(eventLoop), m_hEvent(NULL), m_scheduler(NULL) {} #endif Socket::Socket(int family, int type, int protocol) : m_sock(-1), m_family(family), m_protocol(protocol), m_ioManager(NULL) #ifdef WINDOWS , m_eventLoop(NULL) #endif { m_sock = socket(family, type, protocol); MORDOR_LOG_DEBUG(g_log) << this << " socket(" << (Family)family << ", " << (Type)type << ", " << (Protocol)protocol << "): " << m_sock << " (" << lastError() << ")"; if (m_sock == -1) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("socket"); #ifdef OSX unsigned int opt = 1; if (setsockopt(m_sock, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt)) == -1) { ::closesocket(m_sock); MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("setsockopt"); } #endif } Socket::Socket(IOManager &ioManager, int family, int type, int protocol) : m_sock(-1), m_family(family), m_protocol(protocol), m_ioManager(&ioManager), m_receiveTimeout(~0ull), m_sendTimeout(~0ull), m_cancelledSend(0), m_cancelledReceive(0) #ifdef WINDOWS , m_eventLoop(NULL), m_hEvent(NULL), m_scheduler(NULL) #endif { m_sock = socket(family, type, protocol); MORDOR_LOG_DEBUG(g_log) << this << " socket(" << (Family)family << ", " << (Type)type << ", " << (Protocol)protocol << "): " << m_sock << " (" << lastError() << ")"; if (m_sock == -1) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("socket"); #ifdef WINDOWS try { m_ioManager->registerFile((HANDLE)m_sock); m_skipCompletionPortOnSuccess = !!pSetFileCompletionNotificationModes((HANDLE)m_sock, FILE_SKIP_COMPLETION_PORT_ON_SUCCESS | FILE_SKIP_SET_EVENT_ON_HANDLE); } catch(...) { closesocket(m_sock); throw; } #else if (fcntl(m_sock, F_SETFL, O_NONBLOCK) == -1) { ::closesocket(m_sock); MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("fcntl"); } #endif #ifdef OSX unsigned int opt = 1; if (setsockopt(m_sock, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt)) == -1) { ::closesocket(m_sock); MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("setsockopt"); } #endif } #ifdef WINDOWS Socket::Socket(EventLoop &eventLoop, int family, int type, int protocol) : m_sock(-1), m_family(family), m_protocol(protocol), m_ioManager(NULL), m_receiveTimeout(~0ull), m_sendTimeout(~0ull), m_cancelledSend(0), m_cancelledReceive(0), m_eventLoop(&eventLoop), m_hEvent(NULL), m_scheduler(NULL) { m_sock = socket(family, type, protocol); MORDOR_LOG_DEBUG(g_log) << this << " socket(" << (Family)family << ", " << (Type)type << ", " << (Protocol)protocol << "): " << m_sock << " (" << lastError() << ")"; if (m_sock == -1) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("socket"); u_long arg = 1; if (ioctlsocket(m_sock, FIONBIO, &arg) == -1) { ::closesocket(m_sock); MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("ioctlsocket"); } } #endif Socket::~Socket() { if (m_sock != -1) { int rc = ::closesocket(m_sock); MORDOR_LOG_LEVEL(g_log, rc ? Log::ERROR : Log::INFO) << this << " close(" << m_sock << "): (" << lastError() << ")"; } #ifdef WINDOWS if (m_ioManager && m_hEvent) CloseHandle(m_hEvent); #endif } void Socket::bind(const Address &addr) { MORDOR_ASSERT(addr.family() == m_family); if (::bind(m_sock, addr.name(), addr.nameLen())) { error_t error = lastError(); MORDOR_LOG_ERROR(g_log) << this << " bind(" << m_sock << ", " << addr << "): (" << error << ")"; MORDOR_THROW_EXCEPTION_FROM_ERROR_API(error, "bind"); } MORDOR_LOG_DEBUG(g_log) << this << " bind(" << m_sock << ", " << addr << ")"; } void Socket::bind(Address::ptr addr) { MORDOR_ASSERT(addr->family() == m_family); if (::bind(m_sock, addr->name(), addr->nameLen())) { error_t error = lastError(); MORDOR_LOG_ERROR(g_log) << this << " bind(" << m_sock << ", " << *addr << "): (" << error << ")"; MORDOR_THROW_EXCEPTION_FROM_ERROR_API(error, "bind"); } MORDOR_LOG_DEBUG(g_log) << this << " bind(" << m_sock << ", " << *addr << ")"; m_localAddress = addr; } void Socket::connect(const Address &to) { MORDOR_ASSERT(to.family() == m_family); #ifdef WINDOWS if (m_eventLoop) { if (!::connect(m_sock, to.name(), to.nameLen())) { MORDOR_LOG_INFO(g_log) << this << " connect(" << m_sock << ", " << to << ")"; // Worked first time return; } if (GetLastError() == WSAEWOULDBLOCK) { m_eventLoop->registerEvent(m_sock, EventLoop::CONNECT); if (m_cancelledSend) { MORDOR_LOG_ERROR(g_log) << this << " connect(" << m_sock << ", " << to << "): (" << m_cancelledSend << ")"; if (!m_eventLoop->unregisterEvent(m_sock, EventLoop::CONNECT)) Scheduler::yieldTo(); MORDOR_THROW_EXCEPTION_FROM_ERROR_API(m_cancelledSend, "connect"); } Timer::ptr timeout; if (m_sendTimeout != ~0ull) timeout = m_eventLoop->registerTimer(m_sendTimeout, boost::bind(&Socket::cancelConnect, this)); Scheduler::yieldTo(); if (timeout) timeout->cancel(); // The timeout expired, but the event fired before we could // cancel it, so we got scheduled twice if (m_cancelledSend && !m_unregistered) Scheduler::yieldTo(); if (m_cancelledSend) { MORDOR_LOG_ERROR(g_log) << this << " connect(" << m_sock << ", " << to << "): (" << m_cancelledSend << ")"; MORDOR_THROW_EXCEPTION_FROM_ERROR_API(m_cancelledSend, "connect"); } ::connect(m_sock, to.name(), to.nameLen()); DWORD lastError = GetLastError(); // Windows 2000 is funny this way if (lastError == WSAEINVAL) { ::connect(m_sock, to.name(), to.nameLen()); lastError = GetLastError(); } if (lastError == WSAEISCONN) lastError = ERROR_SUCCESS; MORDOR_LOG_LEVEL(g_log, lastError ? Log::ERROR : Log::INFO) << this << " connect(" << m_sock << ", " << to << "): (" << lastError << ")"; if (lastError) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("connect"); return; } else { MORDOR_LOG_ERROR(g_log) << this << " connect(" << m_sock << ", " << to << "): (" << lastError() << ")"; MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("connect"); } } #endif if (!m_ioManager) { if (::connect(m_sock, to.name(), to.nameLen())) { MORDOR_LOG_ERROR(g_log) << this << " connect(" << m_sock << ", " << to << "): (" << lastError() << ")"; MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("connect"); } MORDOR_LOG_INFO(g_log) << this << " connect(" << m_sock << ", " << to << ")"; } else { #ifdef WINDOWS if (ConnectEx) { // need to be bound, even to ADDR_ANY, before calling ConnectEx switch (m_family) { case AF_INET: { sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = 0; addr.sin_addr.s_addr = ADDR_ANY; if(::bind(m_sock, (sockaddr*)&addr, sizeof(sockaddr_in))) { MORDOR_LOG_ERROR(g_log) << this << " bind(" << m_sock << ", 0.0.0.0:0): (" << lastError() << ")"; MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("bind"); } MORDOR_LOG_DEBUG(g_log) << this << " bind(" << m_sock << ", 0.0.0.0:0)"; break; } case AF_INET6: { sockaddr_in6 addr; memset(&addr, 0, sizeof(sockaddr_in6)); addr.sin6_family = AF_INET6; addr.sin6_port = 0; in6_addr anyaddr = IN6ADDR_ANY_INIT; addr.sin6_addr = anyaddr; if(::bind(m_sock, (sockaddr*)&addr, sizeof(sockaddr_in6))) { MORDOR_LOG_ERROR(g_log) << this << " bind(" << m_sock << ", [::]:0): (" << lastError() << ")"; MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("bind"); } MORDOR_LOG_DEBUG(g_log) << this << " bind(" << m_sock << ", [::]:0)"; break; } default: MORDOR_NOTREACHED(); } m_ioManager->registerEvent(&m_sendEvent); BOOL bRet = ConnectEx(m_sock, to.name(), to.nameLen(), NULL, 0, NULL, &m_sendEvent.overlapped); if (!bRet && GetLastError() != WSA_IO_PENDING) { if (GetLastError() == WSAEINVAL) { m_ioManager->unregisterEvent(&m_sendEvent); // Some LSPs are *borken* (I'm looking at you, bmnet.dll), // and don't properly support ConnectEx (and AcceptEx). In // that case, go to how we work on Windows 2000 without // ConnectEx at all goto suckylsp; } MORDOR_LOG_ERROR(g_log) << this << " ConnectEx(" << m_sock << ", " << to << "): (" << lastError() << ")"; m_ioManager->unregisterEvent(&m_sendEvent); MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("ConnectEx"); } if (m_skipCompletionPortOnSuccess && bRet) { m_ioManager->unregisterEvent(&m_sendEvent); m_sendEvent.overlapped.Internal = STATUS_SUCCESS; } else { if (m_cancelledSend) { MORDOR_LOG_ERROR(g_log) << this << " ConnectEx(" << m_sock << ", " << to << "): (" << m_cancelledSend << ")"; m_ioManager->cancelEvent((HANDLE)m_sock, &m_sendEvent); Scheduler::yieldTo(); MORDOR_THROW_EXCEPTION_FROM_ERROR_API(m_cancelledSend, "ConnectEx"); } Timer::ptr timeout; if (m_sendTimeout != ~0ull) timeout = m_ioManager->registerTimer(m_sendTimeout, boost::bind( &IOManagerIOCP::cancelEvent, m_ioManager, (HANDLE)m_sock, &m_sendEvent)); Scheduler::yieldTo(); if (timeout) timeout->cancel(); } DWORD error = pRtlNtStatusToDosError((NTSTATUS)m_sendEvent.overlapped.Internal); if (error == ERROR_OPERATION_ABORTED && m_cancelledSend != ERROR_OPERATION_ABORTED) error = WSAETIMEDOUT; // WTF, Windows!? if (error == ERROR_SEM_TIMEOUT) error = WSAETIMEDOUT; MORDOR_LOG_LEVEL(g_log, error ? Log::ERROR : Log::INFO) << this << " ConnectEx(" << m_sock << ", " << to << "): (" << error << ")"; if (error) MORDOR_THROW_EXCEPTION_FROM_ERROR_API(error, "ConnectEx"); setOption(SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, NULL, 0); } else { suckylsp: if (!m_hEvent) { m_hEvent = CreateEventW(NULL, TRUE, FALSE, NULL); if (!m_hEvent) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("CreateEventW"); } if (WSAEventSelect(m_sock, m_hEvent, FD_CONNECT)) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("WSAEventSelect"); if (!::connect(m_sock, to.name(), to.nameLen())) { MORDOR_LOG_INFO(g_log) << this << " connect(" << m_sock << ", " << to << ")"; // Worked first time return; } if (GetLastError() == WSAEWOULDBLOCK) { m_ioManager->registerEvent(m_hEvent); m_fiber = Fiber::getThis(); m_scheduler = Scheduler::getThis(); m_unregistered = false; if (m_cancelledSend) { MORDOR_LOG_ERROR(g_log) << this << " connect(" << m_sock << ", " << to << "): (" << m_cancelledSend << ")"; if (!m_ioManager->unregisterEvent(m_hEvent)) Scheduler::yieldTo(); MORDOR_THROW_EXCEPTION_FROM_ERROR_API(m_cancelledSend, "connect"); } Timer::ptr timeout; if (m_sendTimeout != ~0ull) timeout = m_ioManager->registerTimer(m_sendTimeout, boost::bind(&Socket::cancelIo, this, boost::ref(m_cancelledSend), WSAETIMEDOUT)); Scheduler::yieldTo(); m_fiber.reset(); m_scheduler = NULL; if (timeout) timeout->cancel(); // The timeout expired, but the event fired before we could // cancel it, so we got scheduled twice if (m_cancelledSend && !m_unregistered) Scheduler::yieldTo(); if (m_cancelledSend) { MORDOR_LOG_ERROR(g_log) << this << " connect(" << m_sock << ", " << to << "): (" << m_cancelledSend << ")"; MORDOR_THROW_EXCEPTION_FROM_ERROR_API(m_cancelledSend, "connect"); } ::connect(m_sock, to.name(), to.nameLen()); DWORD lastError = GetLastError(); // Windows 2000 is funny this way if (lastError == WSAEINVAL) { ::connect(m_sock, to.name(), to.nameLen()); lastError = GetLastError(); } if (lastError == WSAEISCONN) lastError = ERROR_SUCCESS; MORDOR_LOG_LEVEL(g_log, lastError ? Log::ERROR : Log::INFO) << this << " connect(" << m_sock << ", " << to << "): (" << lastError << ")"; if (lastError) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("connect"); } else { MORDOR_LOG_ERROR(g_log) << this << " connect(" << m_sock << ", " << to << "): (" << lastError() << ")"; MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("connect"); } } #else if (!::connect(m_sock, to.name(), to.nameLen())) { MORDOR_LOG_INFO(g_log) << this << " connect(" << m_sock << ", " << to << ")"; // Worked first time return; } if (errno == EINPROGRESS) { m_ioManager->registerEvent(m_sock, IOManager::WRITE); if (m_cancelledSend) { MORDOR_LOG_ERROR(g_log) << this << " connect(" << m_sock << ", " << to << "): (" << m_cancelledSend << ")"; m_ioManager->cancelEvent(m_sock, IOManager::WRITE); Scheduler::yieldTo(); MORDOR_THROW_EXCEPTION_FROM_ERROR_API(m_cancelledSend, "connect"); } Timer::ptr timeout; if (m_sendTimeout != ~0ull) timeout = m_ioManager->registerTimer(m_sendTimeout, boost::bind( &Socket::cancelIo, this, IOManager::WRITE, boost::ref(m_cancelledSend), ETIMEDOUT)); Scheduler::yieldTo(); if (timeout) timeout->cancel(); if (m_cancelledSend) { MORDOR_LOG_ERROR(g_log) << this << " connect(" << m_sock << ", " << to << "): (" << m_cancelledSend << ")"; MORDOR_THROW_EXCEPTION_FROM_ERROR_API(m_cancelledSend, "connect"); } int err; size_t size = sizeof(int); getOption(SOL_SOCKET, SO_ERROR, &err, &size); if (err != 0) { MORDOR_LOG_ERROR(g_log) << this << " connect(" << m_sock << ", " << to << "): (" << err << ")"; MORDOR_THROW_EXCEPTION_FROM_ERROR_API(err, "connect"); } MORDOR_LOG_INFO(g_log) << this << " connect(" << m_sock << ", " << to << ")"; } else { MORDOR_LOG_ERROR(g_log) << this << " connect(" << m_sock << ", " << to << "): (" << lastError() << ")"; MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("connect"); } #endif } } void Socket::listen(int backlog) { int rc = ::listen(m_sock, backlog); MORDOR_LOG_LEVEL(g_log, rc ? Log::ERROR : Log::DEBUG) << this << " listen(" << m_sock << ", " << backlog << "): " << rc << " (" << lastError() << ")"; if (rc) { MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("listen"); } } Socket::ptr Socket::accept() { #ifdef WINDOWS if (m_eventLoop) { Socket::ptr sock(new Socket(m_eventLoop, m_family, type(), m_protocol, 0)); accept(*sock.get()); return sock; } #endif Socket::ptr sock(new Socket(m_ioManager, m_family, type(), m_protocol, 0)); accept(*sock.get()); return sock; } void Socket::accept(Socket &target) { #ifdef WINDOWS if (m_ioManager) { MORDOR_ASSERT(target.m_sock != -1); } else { MORDOR_ASSERT(target.m_sock == -1); } #else MORDOR_ASSERT(target.m_sock == -1); #endif MORDOR_ASSERT(target.m_family == m_family); MORDOR_ASSERT(target.m_protocol == m_protocol); #ifdef WINDOWS if (m_eventLoop) { SOCKET newsock = ::accept(m_sock, NULL, NULL); while (newsock == -1 && GetLastError() == WSAEWOULDBLOCK) { m_eventLoop->registerEvent(m_sock, EventLoop::ACCEPT); if (m_cancelledReceive) { MORDOR_LOG_ERROR(g_log) << this << " accept(" << m_sock << "): (" << m_cancelledReceive << ")"; m_eventLoop->cancelEvent(m_sock, EventLoop::ACCEPT); Scheduler::yieldTo(); MORDOR_THROW_EXCEPTION_FROM_ERROR_API(m_cancelledReceive, "accept"); } Timer::ptr timeout; if (m_receiveTimeout != ~0ull) timeout = m_eventLoop->registerTimer(m_receiveTimeout, boost::bind( &Socket::cancelIo, this, EventLoop::ACCEPT, boost::ref(m_cancelledReceive), WSAETIMEDOUT)); Scheduler::yieldTo(); if (timeout) timeout->cancel(); if (m_cancelledReceive) { MORDOR_LOG_ERROR(g_log) << this << " accept(" << m_sock << "): (" << m_cancelledReceive << ")"; MORDOR_THROW_EXCEPTION_FROM_ERROR_API(m_cancelledReceive, "accept"); } newsock = ::accept(m_sock, NULL, NULL); } MORDOR_LOG_LEVEL(g_log, newsock == -1 ? Log::ERROR : Log::INFO) << this << " accept(" << m_sock << "): " << newsock << " (" << lastError() << ")"; if (newsock == -1) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("accept"); u_long arg = 1; if (ioctlsocket(newsock, FIONBIO, &arg) == -1) { ::closesocket(newsock); MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("ioctlsocket"); } try { m_eventLoop->clearEvents(newsock); } catch (...) { ::closesocket(newsock); throw; } target.m_sock = newsock; return; } #endif if (!m_ioManager) { socket_t newsock = ::accept(m_sock, NULL, NULL); MORDOR_LOG_LEVEL(g_log, newsock == -1 ? Log::ERROR : Log::INFO) << this << " accept(" << m_sock << "): " << newsock << " (" << lastError() << ")"; if (newsock == -1) { MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("accept"); } target.m_sock = newsock; } else { #ifdef WINDOWS if (pAcceptEx) { m_ioManager->registerEvent(&m_receiveEvent); unsigned char addrs[sizeof(SOCKADDR_STORAGE) * 2 + 16]; DWORD bytes; BOOL ret = pAcceptEx(m_sock, target.m_sock, addrs, 0, sizeof(SOCKADDR_STORAGE) + 16, sizeof(SOCKADDR_STORAGE) + 16, &bytes, &m_receiveEvent.overlapped); if (!ret && GetLastError() != WSA_IO_PENDING) { if (GetLastError() == WSAENOTSOCK) { m_ioManager->unregisterEvent(&m_receiveEvent); // See comment in similar line in connect() goto suckylsp; } MORDOR_LOG_ERROR(g_log) << this << " AcceptEx(" << m_sock << "): (" << lastError() << ")"; m_ioManager->unregisterEvent(&m_receiveEvent); MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("AcceptEx"); } if (m_skipCompletionPortOnSuccess && ret) { m_ioManager->unregisterEvent(&m_receiveEvent); m_receiveEvent.overlapped.Internal = STATUS_SUCCESS; } else { if (m_cancelledReceive) { MORDOR_LOG_ERROR(g_log) << this << " AcceptEx(" << m_sock << "): (" << m_cancelledReceive << ")"; m_ioManager->cancelEvent((HANDLE)m_sock, &m_receiveEvent); Scheduler::yieldTo(); MORDOR_THROW_EXCEPTION_FROM_ERROR_API(m_cancelledReceive, "AcceptEx"); } Timer::ptr timeout; if (m_receiveTimeout != ~0ull) timeout = m_ioManager->registerTimer(m_receiveTimeout, boost::bind( &IOManagerIOCP::cancelEvent, m_ioManager, (HANDLE)m_sock, &m_receiveEvent)); Scheduler::yieldTo(); if (timeout) timeout->cancel(); } DWORD error = pRtlNtStatusToDosError((NTSTATUS)m_receiveEvent.overlapped.Internal); if (error && error != ERROR_MORE_DATA) { if (error == ERROR_OPERATION_ABORTED && m_cancelledReceive != ERROR_OPERATION_ABORTED) error = WSAETIMEDOUT; MORDOR_LOG_ERROR(g_log) << this << " AcceptEx(" << m_sock << "): (" << error << ")"; MORDOR_THROW_EXCEPTION_FROM_ERROR_API(error, "AcceptEx"); } sockaddr *localAddr = NULL, *remoteAddr = NULL; INT localAddrLen, remoteAddrLen; if (pGetAcceptExSockaddrs) pGetAcceptExSockaddrs(addrs, 0, sizeof(SOCKADDR_STORAGE) + 16, sizeof(SOCKADDR_STORAGE) + 16, &localAddr, &localAddrLen, &remoteAddr, &remoteAddrLen); if (remoteAddr) m_remoteAddress = Address::create(remoteAddr, remoteAddrLen, m_family, m_protocol); std::ostringstream os; if (remoteAddr) os << " (" << *m_remoteAddress << ")"; MORDOR_LOG_INFO(g_log) << this << " AcceptEx(" << m_sock << "): " << target.m_sock << os.str(); target.setOption(SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, &m_sock, sizeof(m_sock)); target.m_ioManager->registerFile((HANDLE)target.m_sock); target.m_skipCompletionPortOnSuccess = !!pSetFileCompletionNotificationModes((HANDLE)target.m_sock, FILE_SKIP_COMPLETION_PORT_ON_SUCCESS | FILE_SKIP_SET_EVENT_ON_HANDLE); } else { suckylsp: if (!m_hEvent) { m_hEvent = CreateEventW(NULL, TRUE, FALSE, NULL); if (!m_hEvent) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("CreateEventW"); } if (WSAEventSelect(m_sock, m_hEvent, FD_ACCEPT)) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("WSAEventSelect"); socket_t newsock = ::accept(m_sock, NULL, NULL); if (newsock != -1) { MORDOR_LOG_INFO(g_log) << this << " accept(" << m_sock << "): " << newsock; // Worked first time } else if (GetLastError() == WSAEWOULDBLOCK) { m_ioManager->registerEvent(m_hEvent); m_fiber = Fiber::getThis(); m_scheduler = Scheduler::getThis(); if (m_cancelledReceive) { MORDOR_LOG_ERROR(g_log) << this << " accept(" << m_sock << "): (" << m_cancelledReceive << ")"; if (!m_ioManager->unregisterEvent(m_hEvent)) Scheduler::yieldTo(); MORDOR_THROW_EXCEPTION_FROM_ERROR_API(m_cancelledReceive, "accept"); } m_unregistered = false; Timer::ptr timeout; if (m_receiveTimeout != ~0ull) timeout = m_ioManager->registerTimer(m_sendTimeout, boost::bind(&Socket::cancelIo, this, boost::ref(m_cancelledReceive), WSAETIMEDOUT)); Scheduler::yieldTo(); m_fiber.reset(); m_scheduler = NULL; if (timeout) timeout->cancel(); // The timeout expired, but the event fired before we could // cancel it, so we got scheduled twice if (m_cancelledReceive && !m_unregistered) Scheduler::yieldTo(); if (m_cancelledReceive) { MORDOR_LOG_ERROR(g_log) << this << " accept(" << m_sock << "): (" << m_cancelledReceive << ")"; MORDOR_THROW_EXCEPTION_FROM_ERROR_API(m_cancelledReceive, "accept"); } newsock = ::accept(m_sock, NULL, NULL); MORDOR_LOG_LEVEL(g_log, GetLastError() ? Log::ERROR : Log::INFO) << this << " accept(" << m_sock << "): " << newsock << " (" << lastError() << ")"; if (newsock == -1) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("accept"); } else { MORDOR_LOG_ERROR(g_log) << this << " accept(" << m_sock << "): (" << lastError() << ")"; MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("accept"); } try { m_ioManager->registerFile((HANDLE)newsock); } catch(...) { closesocket(newsock); throw; } if (target.m_sock != -1) ::closesocket(target.m_sock); target.m_sock = newsock; target.m_skipCompletionPortOnSuccess = !!pSetFileCompletionNotificationModes((HANDLE)newsock, FILE_SKIP_COMPLETION_PORT_ON_SUCCESS | FILE_SKIP_SET_EVENT_ON_HANDLE); } #else int newsock = ::accept(m_sock, NULL, NULL); while (newsock == -1 && errno == EAGAIN) { m_ioManager->registerEvent(m_sock, IOManager::READ); if (m_cancelledReceive) { MORDOR_LOG_ERROR(g_log) << this << " accept(" << m_sock << "): (" << m_cancelledReceive << ")"; m_ioManager->cancelEvent(m_sock, IOManager::READ); Scheduler::yieldTo(); MORDOR_THROW_EXCEPTION_FROM_ERROR_API(m_cancelledReceive, "accept"); } Timer::ptr timeout; if (m_receiveTimeout != ~0ull) timeout = m_ioManager->registerTimer(m_receiveTimeout, boost::bind( &Socket::cancelIo, this, IOManager::READ, boost::ref(m_cancelledReceive), ETIMEDOUT)); Scheduler::yieldTo(); if (timeout) timeout->cancel(); if (m_cancelledReceive) { MORDOR_LOG_ERROR(g_log) << this << " accept(" << m_sock << "): (" << m_cancelledReceive << ")"; MORDOR_THROW_EXCEPTION_FROM_ERROR_API(m_cancelledReceive, "accept"); } newsock = ::accept(m_sock, NULL, NULL); } MORDOR_LOG_LEVEL(g_log, newsock == -1 ? Log::ERROR : Log::INFO) << this << " accept(" << m_sock << "): " << newsock << " (" << lastError() << ")"; if (newsock == -1) { MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("accept"); } if (fcntl(newsock, F_SETFL, O_NONBLOCK) == -1) { ::close(newsock); MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("fcntl"); } target.m_sock = newsock; #endif } } void Socket::shutdown(int how) { if(::shutdown(m_sock, how)) { MORDOR_LOG_ERROR(g_log) << this << " shutdown(" << m_sock << ", " << how << "): (" << lastError() << ")"; MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("shutdown"); } MORDOR_LOG_VERBOSE(g_log) << this << " shutdown(" << m_sock << ", " << how << ")"; } #define MORDOR_SOCKET_LOG(result, error) \ if (g_log->enabled(result == -1 ? Log::ERROR : Log::DEBUG)) { \ LogEvent event = g_log->log(result == -1 ? Log::ERROR : Log::DEBUG, \ __FILE__, __LINE__); \ event.os() << this << " " << api << " (" << m_sock << ", " \ << length; \ if (isSend && address) \ event.os() << ", " << *address; \ event.os() << "): "; \ if (result == -1) \ event.os() << "(" << error << ")"; \ else \ event.os() << result; \ if (result != -1 && !isSend && address) \ event.os() << ", " << *address; \ } template <bool isSend> size_t Socket::doIO(iovec *buffers, size_t length, int &flags, Address *address) { #if !defined(WINDOWS) && !defined(OSX) flags |= MSG_NOSIGNAL; #endif #ifdef WINDOWS const char *api = isSend ? (address ? "WSASendTo" : "WSASend") : (address ? "WSARecvFrom" : "WSARecv"); #else const char *api = isSend ? "sendmsg" : "recvmsg"; #endif error_t &cancelled = isSend ? m_cancelledSend : m_cancelledReceive; unsigned long long &timeout = isSend ? m_sendTimeout : m_receiveTimeout; #ifdef WINDOWS DWORD bufferCount = (DWORD)std::min<size_t>(length, 0xffffffff); AsyncEvent &event = isSend ? m_sendEvent : m_receiveEvent; OVERLAPPED *overlapped = m_ioManager ? &event.overlapped : NULL; if (m_ioManager) m_ioManager->registerEvent(&event); DWORD transferred; int result; INT addrLen; if (address) { addrLen = address->nameLen(); result = isSend ? WSASendTo(m_sock, (LPWSABUF)buffers, bufferCount, &transferred, flags, address->name(), address->nameLen(), overlapped, NULL) : WSARecvFrom(m_sock, (LPWSABUF)buffers, bufferCount, &transferred, (LPDWORD)&flags, address->name(), &addrLen, overlapped, NULL); } else { result = isSend ? WSASend(m_sock, (LPWSABUF)buffers, bufferCount, &transferred, flags, overlapped, NULL) : WSARecv(m_sock, (LPWSABUF)buffers, bufferCount, &transferred, (LPDWORD)&flags, overlapped, NULL); } if (result) { if (m_ioManager && GetLastError() == WSA_IO_PENDING || m_eventLoop && GetLastError() == WSAEWOULDBLOCK) { } else { MORDOR_SOCKET_LOG(-1, lastError()); if (m_ioManager) m_ioManager->unregisterEvent(&event); MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API(api); } } if (m_ioManager) { if (m_skipCompletionPortOnSuccess && result == 0) { m_ioManager->unregisterEvent(&event); } else { if (cancelled) { MORDOR_SOCKET_LOG(-1, cancelled); m_ioManager->cancelEvent((HANDLE)m_sock, &event); Scheduler::yieldTo(); MORDOR_THROW_EXCEPTION_FROM_ERROR_API(cancelled, api); } Timer::ptr timer; if (timeout != ~0ull) timer = m_ioManager->registerTimer(timeout, boost::bind( &IOManagerIOCP::cancelEvent, m_ioManager, (HANDLE)m_sock, &event)); Scheduler::yieldTo(); if (timer) timer->cancel(); } DWORD error = pRtlNtStatusToDosError( (NTSTATUS)event.overlapped.Internal); if (error == ERROR_OPERATION_ABORTED && cancelled != ERROR_OPERATION_ABORTED) error = WSAETIMEDOUT; if (error == ERROR_SEM_TIMEOUT) error = WSAETIMEDOUT; result = error ? -1 : (int)event.overlapped.InternalHigh; MORDOR_SOCKET_LOG(result, error); if (error) MORDOR_THROW_EXCEPTION_FROM_ERROR_API(error, api); return result; } else if (m_eventLoop && result) { EventLoop::Event elevent = isSend ? EventLoop::WRITE : EventLoop::READ; while (result && GetLastError() == WSAEWOULDBLOCK) { if (cancelled) { MORDOR_SOCKET_LOG(-1, cancelled); MORDOR_THROW_EXCEPTION_FROM_ERROR_API(cancelled, api); } m_eventLoop->registerEvent(m_sock, elevent); Timer::ptr timer; if (timeout != ~0ull) timer = m_eventLoop->registerTimer(timeout, boost::bind( &Socket::cancelIo, this, elevent, boost::ref(cancelled), WSAETIMEDOUT)); Scheduler::yieldTo(); if (timer) timer->cancel(); if (cancelled) { MORDOR_SOCKET_LOG(-1, cancelled); MORDOR_THROW_EXCEPTION_FROM_ERROR_API(cancelled, api); } if (address) { result = isSend ? WSASendTo(m_sock, (LPWSABUF)buffers, bufferCount, &transferred, flags, address->name(), address->nameLen(), overlapped, NULL) : WSARecvFrom(m_sock, (LPWSABUF)buffers, bufferCount, &transferred, (LPDWORD)&flags, address->name(), &addrLen, overlapped, NULL); } else { result = isSend ? WSASend(m_sock, (LPWSABUF)buffers, bufferCount, &transferred, flags, overlapped, NULL) : WSARecv(m_sock, (LPWSABUF)buffers, bufferCount, &transferred, (LPDWORD)&flags, overlapped, NULL); } } if (result) { MORDOR_SOCKET_LOG(-1, lastError()); MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API(api); } } MORDOR_SOCKET_LOG(transferred, lastError()); return transferred; #else msghdr msg; memset(&msg, 0, sizeof(msghdr)); msg.msg_iov = buffers; msg.msg_iovlen = length; if (address) { msg.msg_name = (sockaddr *)address->name(); msg.msg_namelen = address->nameLen(); } IOManager::Event event = isSend ? IOManager::WRITE : IOManager::READ; int rc = isSend ? sendmsg(m_sock, &msg, flags) : recvmsg(m_sock, &msg, flags); while (m_ioManager && rc == -1 && errno == EAGAIN) { if (cancelled) { MORDOR_SOCKET_LOG(-1, cancelled); MORDOR_THROW_EXCEPTION_FROM_ERROR_API(cancelled, api); } m_ioManager->registerEvent(m_sock, event); Timer::ptr timer; if (timeout != ~0ull) timer = m_ioManager->registerTimer(timeout, boost::bind( &Socket::cancelIo, this, event, boost::ref(cancelled), ETIMEDOUT)); Scheduler::yieldTo(); if (timer) timer->cancel(); if (cancelled) { MORDOR_SOCKET_LOG(-1, cancelled); MORDOR_THROW_EXCEPTION_FROM_ERROR_API(cancelled, api); } rc = isSend ? sendmsg(m_sock, &msg, flags) : recvmsg(m_sock, &msg, flags); } MORDOR_SOCKET_LOG(rc, lastError()); if (rc == -1) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API(api); if (!isSend) flags = msg.msg_flags; return rc; #endif } size_t Socket::send(const void *buffer, size_t length, int flags) { iovec buffers; buffers.iov_base = (void *)buffer; buffers.iov_len = (u_long)std::min<size_t>(length, 0xffffffff); return doIO<true>(&buffers, 1, flags); } size_t Socket::send(const iovec *buffers, size_t length, int flags) { return doIO<true>((iovec *)buffers, length, flags); } size_t Socket::sendTo(const void *buffer, size_t length, int flags, const Address &to) { iovec buffers; buffers.iov_base = (void *)buffer; buffers.iov_len = (u_long)std::min<size_t>(length, 0xffffffff); return doIO<true>(&buffers, 1, flags, (Address *)&to); } size_t Socket::sendTo(const iovec *buffers, size_t length, int flags, const Address &to) { return doIO<true>((iovec *)buffers, length, flags, (Address *)&to); } size_t Socket::receive(void *buffer, size_t length, int *flags) { iovec buffers; buffers.iov_base = buffer; buffers.iov_len = (u_long)std::min<size_t>(length, 0xffffffff); int flagStorage = 0; if (!flags) flags = &flagStorage; return doIO<false>(&buffers, 1, *flags); } size_t Socket::receive(iovec *buffers, size_t length, int *flags) { int flagStorage = 0; if (!flags) flags = &flagStorage; return doIO<false>(buffers, length, *flags); } size_t Socket::receiveFrom(void *buffer, size_t length, Address &from, int *flags) { iovec buffers; buffers.iov_base = buffer; buffers.iov_len = (u_long)std::min<size_t>(length, 0xffffffff); int flagStorage = 0; if (!flags) flags = &flagStorage; return doIO<false>(&buffers, 1, *flags, &from); } size_t Socket::receiveFrom(iovec *buffers, size_t length, Address &from, int *flags) { int flagStorage = 0; if (!flags) flags = &flagStorage; return doIO<false>(buffers, length, *flags, &from); } void Socket::getOption(int level, int option, void *result, size_t *len) { int ret = getsockopt(m_sock, level, option, (char*)result, (socklen_t*)len); if (ret) { MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("getsockopt"); } } void Socket::setOption(int level, int option, const void *value, size_t len) { if (setsockopt(m_sock, level, option, (const char*)value, (socklen_t)len)) { MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("setsockopt"); } } void Socket::cancelAccept() { #ifdef WINDOWS MORDOR_ASSERT(m_ioManager || m_eventLoop); #else MORDOR_ASSERT(m_ioManager); #endif #ifdef WINDOWS if (m_eventLoop) { cancelIo(EventLoop::ACCEPT, m_cancelledReceive, ERROR_OPERATION_ABORTED); return; } if (m_cancelledReceive) return; m_cancelledReceive = ERROR_OPERATION_ABORTED; if (pAcceptEx) { m_ioManager->cancelEvent((HANDLE)m_sock, &m_receiveEvent); } if (m_hEvent && m_scheduler && m_fiber) { m_unregistered = !!m_ioManager->unregisterEvent(m_hEvent); m_scheduler->schedule(m_fiber); } #else cancelIo(IOManager::READ, m_cancelledReceive, ECANCELED); #endif } void Socket::cancelConnect() { #ifdef WINDOWS MORDOR_ASSERT(m_ioManager || m_eventLoop); #else MORDOR_ASSERT(m_ioManager); #endif #ifdef WINDOWS if (m_eventLoop) { cancelIo(EventLoop::CONNECT, m_cancelledSend, ERROR_OPERATION_ABORTED); return; } if (m_cancelledSend) return; m_cancelledSend = ERROR_OPERATION_ABORTED; if (ConnectEx) { m_ioManager->cancelEvent((HANDLE)m_sock, &m_sendEvent); } if (m_hEvent && m_scheduler && m_fiber) { m_unregistered = !!m_ioManager->unregisterEvent(m_hEvent); m_scheduler->schedule(m_fiber); } #else cancelIo(IOManager::WRITE, m_cancelledSend, ECANCELED); #endif } void Socket::cancelSend() { #ifdef WINDOWS MORDOR_ASSERT(m_ioManager || m_eventLoop); #else MORDOR_ASSERT(m_ioManager); #endif #ifdef WINDOWS if (m_eventLoop) { cancelIo(EventLoop::WRITE, m_cancelledSend, ERROR_OPERATION_ABORTED); return; } if (m_cancelledSend) return; m_cancelledSend = ERROR_OPERATION_ABORTED; m_ioManager->cancelEvent((HANDLE)m_sock, &m_sendEvent); #else cancelIo(IOManager::WRITE, m_cancelledSend, ECANCELED); #endif } void Socket::cancelReceive() { #ifdef WINDOWS MORDOR_ASSERT(m_ioManager || m_eventLoop); #else MORDOR_ASSERT(m_ioManager); #endif #ifdef WINDOWS if (m_eventLoop) { cancelIo(EventLoop::READ, m_cancelledReceive, ERROR_OPERATION_ABORTED); return; } if (m_cancelledReceive) return; m_cancelledReceive = ERROR_OPERATION_ABORTED; m_ioManager->cancelEvent((HANDLE)m_sock, &m_receiveEvent); #else cancelIo(IOManager::READ, m_cancelledReceive, ECANCELED); #endif } #ifdef WINDOWS void Socket::cancelIo(int event, error_t &cancelled, error_t error) { MORDOR_ASSERT(error); if (cancelled) return; cancelled = error; m_eventLoop->cancelEvent(m_sock, (EventLoop::Event)event); } void Socket::cancelIo(error_t &cancelled, error_t error) { MORDOR_ASSERT(error); if (cancelled) return; cancelled = error; if (m_hEvent && m_scheduler && m_fiber) { m_unregistered = !!m_ioManager->unregisterEvent(m_hEvent); m_scheduler->schedule(m_fiber); } } #else void Socket::cancelIo(IOManager::Event event, error_t &cancelled, error_t error) { MORDOR_ASSERT(error); if (cancelled) return; cancelled = error; m_ioManager->cancelEvent(m_sock, event); } #endif Address::ptr Socket::emptyAddress() { switch (m_family) { case AF_INET: return Address::ptr(new IPv4Address(type(), m_protocol)); case AF_INET6: return Address::ptr(new IPv6Address(type(), m_protocol)); default: return Address::ptr(new UnknownAddress(m_family, type(), m_protocol)); } } Address::ptr Socket::remoteAddress() { if (m_remoteAddress) return m_remoteAddress; Address::ptr result; switch (m_family) { case AF_INET: result.reset(new IPv4Address(type(), m_protocol)); break; case AF_INET6: result.reset(new IPv6Address(type(), m_protocol)); break; default: result.reset(new UnknownAddress(m_family, type(), m_protocol)); break; } socklen_t namelen = result->nameLen(); if (getpeername(m_sock, result->name(), &namelen)) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("getpeername"); MORDOR_ASSERT(namelen <= result->nameLen()); return m_remoteAddress = result; } Address::ptr Socket::localAddress() { if (m_localAddress) return m_localAddress; Address::ptr result; switch (m_family) { case AF_INET: result.reset(new IPv4Address(type(), m_protocol)); break; case AF_INET6: result.reset(new IPv6Address(type(), m_protocol)); break; default: result.reset(new UnknownAddress(m_family, type(), m_protocol)); break; } socklen_t namelen = result->nameLen(); if (getsockname(m_sock, result->name(), &namelen)) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("getsockname"); MORDOR_ASSERT(namelen <= result->nameLen()); return m_localAddress = result; } int Socket::type() { int result; size_t len = sizeof(int); getOption(SOL_SOCKET, SO_TYPE, &result, &len); return result; } Address::Address(int type, int protocol) : m_type(type), m_protocol(protocol) {} std::vector<Address::ptr> Address::lookup(const std::string &host, int family, int type, int protocol) { #ifdef WINDOWS addrinfoW hints, *results, *next; #else addrinfo hints, *results, *next; #endif hints.ai_flags = 0; hints.ai_family = family; hints.ai_socktype = type; hints.ai_protocol = protocol; hints.ai_addrlen = 0; hints.ai_canonname = NULL; hints.ai_addr = NULL; hints.ai_next = NULL; std::string node; const char *service = NULL; // Check for [ipv6addr] (with optional :service) if (!host.empty() && host[0] == '[') { const char *endipv6 = (const char *)memchr(host.c_str() + 1, ']', host.size() - 1); if (endipv6) { if (*(endipv6 + 1) == ':') { service = endipv6 + 2; } node = host.substr(1, endipv6 - host.c_str() - 1); } } // Check for node:service if (node.empty()) { service = (const char*)memchr(host.c_str(), ':', host.size()); if (service) { // More than 1 : means it's not node:service if (!memchr(service + 1, ':', host.c_str() + host.size() - service - 1)) { node = host.substr(0, service - host.c_str()); ++service; } else { service = NULL; } } } if (node.empty()) node = host; int error; #ifdef WINDOWS std::wstring serviceWStorage; const wchar_t *serviceW = NULL; if (service) { if (stricmp(service, "socks") == 0) serviceWStorage = L"1080"; else serviceWStorage = toUtf16(service); serviceW = serviceWStorage.c_str(); } error = pGetAddrInfoW(toUtf16(node).c_str(), serviceW, &hints, &results); #else error = getaddrinfo(node.c_str(), service, &hints, &results); #endif if (error) MORDOR_LOG_ERROR(g_log) << "getaddrinfo(" << host << ", " << (Family)family << ", " << (Type)type << "): (" << error << ")"; switch (error) { case 0: break; case EAI_AGAIN: MORDOR_THROW_EXCEPTION(TemporaryNameServerFailureException() << errinfo_gaierror(error) << boost::errinfo_api_function("getaddrinfo")); case EAI_FAIL: MORDOR_THROW_EXCEPTION(PermanentNameServerFailureException() << errinfo_gaierror(error) << boost::errinfo_api_function("getaddrinfo")); #if defined(WSANO_DATA) || defined(EAI_NODATA) case MORDOR_NATIVE(WSANO_DATA, EAI_NODATA): MORDOR_THROW_EXCEPTION(NoNameServerDataException() << errinfo_gaierror(error) << boost::errinfo_api_function("getaddrinfo")); #endif case EAI_NONAME: MORDOR_THROW_EXCEPTION(HostNotFoundException() << errinfo_gaierror(error) << boost::errinfo_api_function("getaddrinfo")); #ifdef EAI_ADDRFAMILY case EAI_ADDRFAMILY: #endif case EAI_BADFLAGS: case EAI_FAMILY: case EAI_MEMORY: case EAI_SERVICE: case EAI_SOCKTYPE: #ifdef EAI_SYSTEM case EAI_SYSTEM: #endif default: MORDOR_THROW_EXCEPTION(NameLookupException() << errinfo_gaierror(error) << boost::errinfo_api_function("getaddrinfo")); } std::vector<Address::ptr> result; next = results; while (next) { result.push_back(create(next->ai_addr, (socklen_t)next->ai_addrlen, next->ai_socktype, next->ai_protocol)); next = next->ai_next; } #ifdef WINDOWS pFreeAddrInfoW(results); #else freeaddrinfo(results); #endif return result; } Address::ptr Address::create(const sockaddr *name, socklen_t nameLen, int type, int protocol) { MORDOR_ASSERT(name); Address::ptr result; switch (name->sa_family) { case AF_INET: result.reset(new IPv4Address(type, protocol)); MORDOR_ASSERT(nameLen <= result->nameLen()); memcpy(result->name(), name, nameLen); break; case AF_INET6: result.reset(new IPv6Address(type, protocol)); MORDOR_ASSERT(nameLen <= result->nameLen()); memcpy(result->name(), name, nameLen); break; default: result.reset(new UnknownAddress(name->sa_family, type, protocol)); MORDOR_ASSERT(nameLen <= result->nameLen()); memcpy(result->name(), name, nameLen); break; } return result; } Socket::ptr Address::createSocket() { return Socket::ptr(new Socket(family(), type(), protocol())); } Socket::ptr Address::createSocket(IOManager &ioManager) { return Socket::ptr(new Socket(ioManager, family(), type(), protocol())); } #ifdef WINDOWS Socket::ptr Address::createSocket(EventLoop &eventLoop) { return Socket::ptr(new Socket(eventLoop, family(), type(), protocol())); } #endif std::ostream & Address::insert(std::ostream &os) const { return os << "(Unknown addr " << m_type << ")"; } bool Address::operator<(const Address &rhs) const { if (m_type >= rhs.m_type || m_protocol >= rhs.m_protocol) return false; socklen_t minimum = std::min(nameLen(), rhs.nameLen()); int result = memcmp(name(), rhs.name(), minimum); if (result < 0) return true; else if (result > 0) return false; if (nameLen() < rhs.nameLen()) return true; return false; } bool Address::operator==(const Address &rhs) const { return m_type == rhs.m_type && m_protocol == rhs.m_protocol && nameLen() == rhs.nameLen() && memcmp(name(), rhs.name(), nameLen()) == 0; } bool Address::operator!=(const Address &rhs) const { return !(*this == rhs); } IPAddress::IPAddress(int type, int protocol) : Address(type, protocol) {} IPv4Address::IPv4Address(int type, int protocol) : IPAddress(type, protocol) { sin.sin_family = AF_INET; sin.sin_port = 0; sin.sin_addr.s_addr = INADDR_ANY; } std::ostream & IPv4Address::insert(std::ostream &os) const { int addr = htonl(sin.sin_addr.s_addr); return os << ((addr >> 24) & 0xff) << '.' << ((addr >> 16) & 0xff) << '.' << ((addr >> 8) & 0xff) << '.' << (addr & 0xff) << ':' << htons(sin.sin_port); } IPv6Address::IPv6Address(int type, int protocol) : IPAddress(type, protocol) { sin.sin6_family = AF_INET6; sin.sin6_port = 0; in6_addr anyaddr = IN6ADDR_ANY_INIT; sin.sin6_addr = anyaddr; } std::ostream & IPv6Address::insert(std::ostream &os) const { std::ios_base::fmtflags flags = os.setf(std::ios_base::hex, std::ios_base::basefield); os << '['; unsigned short *addr = (unsigned short *)sin.sin6_addr.s6_addr; bool usedZeros = false; for (size_t i = 0; i < 8; ++i) { if (addr[i] == 0 && !usedZeros) continue; if (i != 0 && addr[i - 1] == 0 && !usedZeros) { os << ':'; usedZeros = true; } if (i != 0) os << ':'; os << (int)htons(addr[i]); } if (!usedZeros && addr[7] == 0) os << "::"; os << "]:" << std::dec << (int)htons(sin.sin6_port); os.setf(flags, std::ios_base::basefield); return os; } #ifndef WINDOWS UnixAddress::UnixAddress(const std::string &path, int type, int protocol) : Address(type, protocol) { sun.sun_family = AF_UNIX; length = path.size() + 1; #ifdef LINUX // Abstract namespace; leading NULL, but no trailing NULL if (!path.empty() && path[0] == '\0') --length; #endif MORDOR_ASSERT(length <= sizeof(sun.sun_path)); memcpy(sun.sun_path, path.c_str(), length); length += offsetof(sockaddr_un, sun_path); } std::ostream & UnixAddress::insert(std::ostream &os) const { #ifdef LINUX if (length > offsetof(sockaddr_un, sun_path) && sun.sun_path[0] == '\0') return os << "\\0" << std::string(sun.sun_path + 1, length - offsetof(sockaddr_un, sun_path) - 1); #endif return os << sun.sun_path; } #endif UnknownAddress::UnknownAddress(int family, int type, int protocol) : Address(type, protocol) { sa.sa_family = family; } std::ostream &operator <<(std::ostream &os, const Address &addr) { return addr.insert(os); } bool operator <(const Address::ptr &lhs, const Address::ptr &rhs) { if (!lhs || !rhs) return rhs; return *lhs < *rhs; } }
ae0eead4ffe3fff473e72c15cd389b57a442d348
c499d5015f2cd2cb920a543435253c71a8e8f4ad
/lab1/main.cpp
8fec2f5e6ba6464d2fc2a6691343a181fd3004e8
[]
no_license
NewblyAaron/csdc103-serrano
f22007bbad5fc923429965118eaef72cb5da9048
c39a9c713d0904927d40bab54dace29d8cd9a3b8
refs/heads/master
2023-08-04T05:23:03.619794
2021-10-02T10:49:10
2021-10-02T10:49:10
398,978,743
0
0
null
null
null
null
UTF-8
C++
false
false
681
cpp
main.cpp
// Filename : main.cpp // Description : This program tests the implementation of the // function to approximate the value of PI. // Author : Aaron Serrano // Honor Code : I have not asked nor given any aunthorized help // in completing this exercise. #define FIXED_FLOAT(x) std::fixed << std::setprecision(15) << (x) #include <iostream> #include <iomanip> #include "approx.h" using namespace std; int main() { int cases; cin >> cases; for (int i = 1; i <= cases; i++) { int input; cin >> input; cout << "CASE " << i << ": " << FIXED_FLOAT(approx_pi(input)) << endl; } return 0; }
de3fbd9cef33ee0cda5815ee2b074e975bab5b24
0ee311e7cdb1108fbbd3b7fc8a3077dac9c12821
/include/geometry/linesegment.h
29bed4312e47cb49156b2991952d67f693662637
[ "MIT" ]
permissive
robinlzw/cs5237-VoronoiArt
f38543fbafa09658fda4258afdbc647458a8e449
f8b91fd386f5a04aea483ed4f2964e697322a882
refs/heads/master
2022-03-27T12:09:00.275909
2019-12-23T15:43:09
2019-12-23T15:43:09
null
0
0
null
null
null
null
UTF-8
C++
false
false
1,336
h
linesegment.h
#ifndef GEOMETRY_LINESEGMENTH #define GEOMETRY_LINESEGMENTH #include <utility> #include "point.h" namespace geometry { /// Abstraction for referring to (directed) line segments template<typename I> using LineSegment = std::pair<Point<I>, Point<I>>; enum class Orientation { CounterClockwise = 1, Colinear = 0, Clockwise = -1 }; /// Returns 1 if p3 is counter-clockwise to p1p2, /// 0 if co-linear, /// -1 if clockwise. // TODO enum class for type safety template<typename I> int orientation(const LineSegment<I>& p1p2, const Point<I>& p3); // ColinearOverlap only used in intersects(LineSeg,LineSeg), // so perhaps should be different type enum class Intersection { None, Incidental, ColinearOverlap, Overlap }; template<typename I> Intersection intersects(const LineSegment<I>& ab, const LineSegment<I>& cd); /// Whether the two segments Overlap. (i.e. Incidental returns false). bool isOverlapping(const Intersection& i); /// Whether the two segments touch. (Incidental or Overlap) bool isTouching(const Intersection& i); /// IMPRECISE /// Return approximate intersection point of line segments ab, cd. /// Undefined Behaviour if LineSeg ab doesn't intersect w/ cd. Point<int> findIntersectionPoint(const LineSegment<int>& ab, const LineSegment<int>& cd); } #endif
03e62a0f0b03f87589616cd82d5bbe45aabdefbc
3ca020d9bb180e49bd40de71fc2240a36fa7ac34
/Graph/Graph_traversal/280/280.cpp
f71447092fdc7e919ebb8373cb75630f48fcf2de
[]
no_license
arpit23697/For-Uva-solutions
b20bdc8acf341bb0a997e8ef29ad8181fbdd3a05
a268e0794029288d25b2d36b35112f500fa41c37
refs/heads/master
2021-05-14T08:30:30.006235
2020-06-25T09:57:44
2020-06-25T09:57:44
116,299,950
0
0
null
null
null
null
UTF-8
C++
false
false
1,764
cpp
280.cpp
#include <bits/stdc++.h> using namespace std; vector <vector <int> > graph; bool visited[105]; int counter; int n; void DFS (int start) { // cout << start << "hi " <<endl; for (int i = 0 ; i < graph[start].size() ; i++) { int v = graph[start][i]; if (visited[v] == false) { visited[v] = true; DFS(v); } } } int main () { freopen ("in.txt" , "r" , stdin); freopen ("out.txt" , "w" , stdout); while (1) { cin >> n; if (n == 0) break; graph.assign (n , vector<int> ()); while (1) { int x; int temp; cin >> x; if (x == 0) break; x--; while (1) { cin >> temp; if (temp == 0) break; temp--; graph[x].push_back (temp); } } /*for (int i = 0 ; i < n ; i++) { cout << i+1; for (int j = 0 ; j < graph[i].size() ; j++) cout << " " << graph[i][j]+1; cout << endl; }*/ int test; cin >> test; for (int i= 0 ; i < test ; i++) { memset (visited , false , sizeof visited); int start; cin >> start; start--; counter = 0; DFS (start); for (int i =0 ; i < n ; i++) if (visited[i] == false) counter++; cout << counter; for (int j = 0 ; j < n ; j++) if (visited[j] == false) cout << " " << j+1; cout << endl; } } return 0; }
1651f571da0656afbf738e5a45c459ea05f63b9d
c50a92029877fa3ef3f5c18e8d88506b7eee1c7f
/SPOJ/ITRIX12E - R Numbers.cpp
301b93eae754defe92affbf8b430d63d13403464
[ "Unlicense" ]
permissive
phoemur/competitive-programming
4025995b7904ed431e03316ecf5270e976fa9275
8963e450352aac660287551c28c113e2bf1ba38c
refs/heads/master
2023-08-09T23:43:03.237312
2023-08-06T22:45:50
2023-08-06T22:45:50
145,256,889
8
4
null
null
null
null
UTF-8
C++
false
false
3,339
cpp
ITRIX12E - R Numbers.cpp
/*ITRIX12E - R Numbers #matrix #linear-recurrence #digit-dp-1 R - Numbers R-numbers are numbers which have the property that they do not have the digit '0 ' and sum of every two adjacent digits of the number is prime. 123 is a R-number because 1+2 =3 and 2+3 =5 and 3 , 5 are primes. How many R-numbers can be formed with atmost length N? i.e R-numbers of length 1 + R-numbers of length 2 + R-numbers of length 3+....... R-numbers of length N Length of a number = Number of digits in the number Only four single digit numbers are R-numbers which are nothing but single digit primes 2,3,5,7 Input Specification The first line of the input file contains T which denotes the number of Test cases.The next T lines contain an integer N <= 10^9 Output Specification Print the numbers of R-numbers modulo 1000000007. [10^9+7]; Example Sample Input: 2 1 2 Sample Output: 4 33 */ #include <bits/stdc++.h> #define MOD 1000000007 // Based on solution from Arnaud Desombre on https://ideone.com/6ATT6k // Multiply a NxN (square) matrix template<typename T, std::size_t N> auto operator*(const std::array<std::array<T,N>,N>& lhs, const std::array<std::array<T,N>,N>& rhs) { static_assert(std::is_arithmetic<T>::value, "Matrix multiplication on non-arithmetic type"); std::array<std::array<T,N>,N> res {}; // Multiply -> O(n^3) for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) for (int k = 0; k < N; ++k) res[i][j] = (res[i][j] + lhs[i][k] * rhs[k][j]) % MOD; return res; } // Binary exponentiation of a square matrix template<typename T, std::size_t N> auto power(std::array<std::array<T,N>,N> base, int exp) // pass by value { static_assert(std::is_arithmetic<T>::value, "Matrix multiplication on non-arithmetic type"); std::array<std::array<T,N>,N> res {}; // Make res the identity matrix for (int i = 0; i < N; ++i) res[i][i] = 1; // Multiply by powers of 2 whose bit is set on exp while (exp > 0) { if (exp & 1) res = res * base; base = base * base; exp >>= 1; } return res; } long solve(int n) { std::array<std::array<long,10>,10> transform {{{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 1, 1, 0, 1, 0, 1, 0, 0, 0}, {0, 1, 0, 1, 0, 1, 0, 0, 0, 1}, {0, 0, 1, 0, 1, 0, 0, 0, 1, 0}, {0, 1, 0, 1, 0, 0, 0, 1, 0, 1}, {0, 0, 1, 0, 0, 0, 1, 0, 1, 0}, {0, 1, 0, 0, 0, 1, 0, 1, 0, 0}, {0, 0, 0, 0, 1, 0, 1, 0, 0, 0}, {0, 0, 0, 1, 0, 1, 0, 0, 0, 1}, {0, 0, 1, 0, 1, 0, 0, 0, 1, 0}}}; std::array<long,10> f2 {{4, 4, 4, 3, 4, 3, 3, 2, 3, 3}}; if (n <= 0) return 0; else if (n == 1) return 4; else { auto res = power(transform, n-2); long total = 0; for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) total = (total + res[i][j] * f2[j]) % MOD; return total; } } int main() { int tests; std::cin >> tests; while (tests--) { int n; std::cin >> n; std::cout << solve(n) << std::endl; } return 0; }
ff1023bbbcb1ec75a27855e134a8fcd976a8cdac
dc0bcfde42279eff6a3e76eb653de3c72e2c1616
/main.cpp
38c6e938abe88e1111f2ecb8f13cd2827530e6d7
[]
no_license
Chargui-Med-Amine/Demineur-cplusplus
25fb819add2f58a5b9d1e9d562c250c4082bfb98
dab00026aa7fba4a0576b089e486b1f6638ee5ef
refs/heads/master
2022-06-28T04:54:19.962342
2020-05-12T01:31:53
2020-05-12T01:31:53
259,491,311
0
0
null
null
null
null
UTF-8
C++
false
false
7,638
cpp
main.cpp
#include <iostream> #include <cstdlib> #include <ctime> #include "carreau.h" #include "champdesmines.h" #include "mini_game.h" #include <iomanip> #include <chrono> #include <fstream> #include <vector> using namespace std; //test int main() { string type_jeu; string decision; cout<<"\n\t\t\t\t\t**Bienvenue au Demineur**"<<endl; cout<<"\t\t\t\t\t*************************"<<endl; cout<<"\n\n\t\t\t\t Vous ne connaissez pas la jeu ? tapez "<<endl; do{ cout<<"\n\t\t\t\t\t oui pour un tutoriel"<<endl; cout<<"\n\t\t\t\t\t non pour continuer"<< endl; cin>>decision; }while(decision!="oui" && decision!="non"); if (decision=="oui") { srand((int)time(0)); auto start = chrono::steady_clock::now(); champdesmines m(10); m.compte_voisins(); m.Affichage(); cout<< "on peut commencer par choisir la case (0,0)"<< endl; m.open(0,0,"o"); cout<<"on remarque maitenant que les cases (7,2) et (6,2) sont les voisins d'une seul mine qu'elle peut etre seulement la case (7,3)"<<endl; cout<<"on marque alors la case (7,3) par un drapeau"<<endl; m.open(7,3,"d"); cout<<"on remarque maitenant que la case (6,3) est la voisin d'une seul mines qu'elle peut etre seulement la case (7,3) donc la case (7,4) voisine de (6,3) est sans mine "<<endl; cout<<"on ouvre alors la case (7,4) "<<endl; m.open(7,4,"o"); cout<<"on remarque maitenant que la case (7,4) est la voisin d'une seul mines qu'elle peut etre seulement la case (7,3) donc la case (7,5) voisine de (7,4) est sans mine "<<endl; cout<<"on ouvre alors la case (7,5) "<<endl; m.open(7,5,"o"); cout<<"on remarque maitenant que la case (6,4) est entouré par deux mine une mine deja marque dans la case (7,3) et une autre ne peut être que la case (5,5) "<<endl; cout<<" on marque alors la case (5,5) par un drapeau "<<endl; m.open(5,5,"d"); cout<<"le tutoriel est finie termine le jeu "<<endl; while ((m.get_res()!=1)&&(m.compte_ouvert()!=m.nb_carreau()-m.get_nb_mines())) { m.open(); } if((m.get_res()==1)) { m.aff_lose(); m.Affichage(); cout << " Vous avez perdu le jeu"<<endl<<endl; cout << " a$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$ $$$$$$ $$$$$a" << endl; cout << " a$$$$$ $$$$ $$$$$a" << endl; cout << " a$$$$$$$$$$$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$ $$$$$$a" << endl; cout << " a$$$$ $$$$$$$$ $$$$a" << endl; cout << " a$$ $$$$$$$$$$$$ $$a" << endl; cout << " a$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$a" << endl<<endl<<endl; } auto end = chrono::steady_clock::now(); cout << "###### Temps ecoule : [ "<< std::setw(2) << std::setfill('0') << (chrono::duration_cast<chrono::seconds>(end - start).count())/60 << ":"<< std::setw(2) << std::setfill('0')<<(chrono::duration_cast<chrono::seconds>(end - start).count())%60 <<" ] ######" <<endl; } if (decision=="non") { do { cout<<" Vous voulez jouer demineur Classique(c) ou Autour du Monde(am)"<<endl; cin>>type_jeu; }while(type_jeu!="c"&&type_jeu!="am"); if(type_jeu=="am") { srand((int)time(0)); champdesmines m(true); m.compte_voisins(); m.Affichage(); auto start = chrono::steady_clock::now(); while ((m.get_res()!=1)&&(m.compte_ouvert()!=m.nb_carreau()-m.get_nb_mines())) { m.open(); } if((m.get_res()==1)) { m.aff_lose(); m.Affichage(); cout << " Vous avez perdu le jeu"<<endl<<endl; cout << " a$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$ $$$$$$ $$$$$a" << endl; cout << " a$$$$$ $$$$ $$$$$a" << endl; cout << " a$$$$$$$$$$$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$ $$$$$$a" << endl; cout << " a$$$$ $$$$$$$$ $$$$a" << endl; cout << " a$$ $$$$$$$$$$$$ $$a" << endl; cout << " a$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$a" << endl<<endl<<endl; } auto end = chrono::steady_clock::now(); cout << "###### Temps ecoule : [ "<< std::setw(2) << std::setfill('0') << (chrono::duration_cast<chrono::seconds>(end - start).count())/60 << ":"<< std::setw(2) << std::setfill('0')<<(chrono::duration_cast<chrono::seconds>(end - start).count())%60 <<" ] ######" <<endl; m.score((chrono::duration_cast<chrono::seconds>(end - start).count()),m.get_res()); } else { srand((int)time(0)); champdesmines m; if(m.get_mode()=="a") { if (m.get_niveau() == "facile") {Quiz b(3); b.affiche(); m.set_R(b.get_chance()); } else if (m.get_niveau() == "moyen") { Quiz b(5); b.affiche(); m.set_R(b.get_chance()); } else if (m.get_niveau() == "difficile") { Quiz b(7); b.affiche(); m.set_R(b.get_chance()); } } m.compte_voisins(); m.Affichage(); auto start = chrono::steady_clock::now(); while ((m.get_res()!=1)&&(m.compte_ouvert()!=m.nb_carreau()-m.get_nb_mines())) { m.open(); } if((m.get_res()==1)) { m.aff_lose(); m.Affichage(); cout << " Vous avez perdu le jeu"<<endl<<endl; cout << " a$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$ $$$$$$ $$$$$a" << endl; cout << " a$$$$$ $$$$ $$$$$a" << endl; cout << " a$$$$$$$$$$$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$ $$$$$$a" << endl; cout << " a$$$$ $$$$$$$$ $$$$a" << endl; cout << " a$$ $$$$$$$$$$$$ $$a" << endl; cout << " a$$$$$$$$$$$$$$a" << endl; cout << " a$$$$$$$$$$a" << endl<<endl<<endl; } auto end = chrono::steady_clock::now(); cout << "###### Temps ecoule : [ "<< std::setw(2) << std::setfill('0') << (chrono::duration_cast<chrono::seconds>(end - start).count())/60 << ":"<< std::setw(2) << std::setfill('0')<<(chrono::duration_cast<chrono::seconds>(end - start).count())%60 <<" ] ######" <<endl; m.score((chrono::duration_cast<chrono::seconds>(end - start).count()),m.get_res()); } } return 0; }
f0f7f3b830c1540f69361bec6168e7cc851b391d
42bd33837ce950a7fd1021e04d97da65c7b00f55
/Line2D.cpp
1954f9a7f4f4b3a00e89978ed1aa78c85f8d1096
[]
no_license
ayrahisham/data-processing-program
f092e93bb06d7469327b8b62fd211c1755b20140
f443b4908ebefa6b16874d479c623b746af62dec
refs/heads/master
2020-09-20T23:52:22.177293
2019-11-28T09:50:36
2019-11-28T09:50:36
224,621,089
0
0
null
null
null
null
UTF-8
C++
false
false
4,207
cpp
Line2D.cpp
#include "Line2D.h" int Line2D::id = 0; ostream& operator<< (ostream& os, Line2D& l2d) { os << l2d.print (); return os; } bool operator== (const Line2D& l1, const Line2D& l2) { if ((l1.pt1 == l2.pt1) && (l1.pt2 == l2.pt2)) { return true; } return false; } // if pt1 and pt2 are the same points already means duplicated bool operator< (const Line2D& l1, const Line2D& l2) { if (l1.sorting == "Pt. 1") { if (l1.getP1().getX() < l2.getP1().getX()) { return true; } else if (l1.getP1().getX() == l2.getP1().getX()) { if (l1.getP1().getY() < l2.getP1().getY()) { return true; } } } else if (l1.sorting == "Pt. 2") { if (l1.getP2().getX() < l2.getP2().getX()) { return true; } else if (l1.getP2().getX() == l2.getP2().getX()) { if (l1.getP2().getY() < l2.getP2().getY()) { return true; } } } else if (l1.sorting == "Length") { if (l1.getScalarValue () < l2.getScalarValue ()) { return true; } else if (l1.getScalarValue () == l2.getScalarValue ()) { if (l1.getP1().getX() < l2.getP1().getX()) { return true; } else if (l1.getP1().getX() == l2.getP1().getX()) { if (l1.getP1().getY() < l2.getP1().getY()) { return true; } } } } return false; } // if pt1 and pt2 are the same points already means duplicated bool operator> (const Line2D& l1, const Line2D& l2) { if (l1.sorting == "Pt. 1") { if (l1.getP1().getX() > l2.getP1().getX()) { return true; } else if (l1.getP1().getX() == l2.getP1().getX()) { if (l1.getP1().getY() > l2.getP2().getY()) { return true; } } } else if (l1.sorting == "Pt. 2") { if (l1.getP2().getX() > l2.getP2().getX()) { return true; } else if (l1.getP2().getX() == l2.getP2().getX()) { if (l1.getP2().getY() > l2.getP2().getY()) { return true; } } } else if (l1.sorting == "Length") { if (l1.getScalarValue () > l2.getScalarValue ()) { return true; } else if (l1.getScalarValue () == l2.getScalarValue ()) { if (l1.getP1().getX() > l2.getP1().getX()) { return true; } else if (l1.getP1().getX() == l2.getP1().getX()) { if (l1.getP1().getY() > l2.getP1().getY()) { return true; } } } } return false; } Line2D::Line2D () { this->pt1.setX (0); this->pt1.setY (0); this->pt2.setX (0); this->pt2.setY (0); this->sorting = "Pt. 1"; this->setLength (); this->id = id; this->id++; } Line2D::Line2D (Point2D pt1, Point2D pt2) { this->pt1 = pt1; this->pt2 = pt2; this->sorting = "Pt. 1"; this->setLength (); this->id = id; this->id++; } Line2D::~Line2D () { // let compiler do it } Line2D::Line2D (const Line2D& l2d) { this->pt1 = l2d.pt1; this->pt2 = l2d.pt2; this->sorting = l2d.sorting; this->length = l2d.length; this->id = l2d.id; } Point2D Line2D::getP1 () const { return this->pt1; } Point2D Line2D::getP2 () const { return this->pt2; } double Line2D::getScalarValue () const { return this->length; } string Line2D::getSort () { return sorting; } string Line2D::print () { stringstream oss; oss << "[" << setw (4) << right << getP1().getX() << "," << setfill (' ') << setw (5) << right << getP1().getY() << "] " // including comma (+1); include 3 spaces aft [ << "[" << setw (4) << right << getP2().getX() << "," << setfill (' ') << setw (5) << right << getP2().getY() << "] " << setfill (' ') << fixed << setprecision (3) << this->length; // default print as left return (oss.str()); } void Line2D::setP1 (Point2D pt1) { this->pt1 = pt1; } void Line2D::setP2 (Point2D pt2) { this->pt2 = pt2; } void Line2D::setSort (string sorting) { this->sorting = sorting; } void Line2D::setLength () { this->length = this->round (sqrt ((pow ((getP1().getX() - getP2().getX()), 2)) + (pow ((getP1().getY() - getP2().getY()), 2)))); } double Line2D::round (double origin) { // 37.66666 * 1000 =37666.66 // 37666.66 + .5 =37667.16 for rounding off value // then type cast to int so value is 37667 // then divided by 1000 so the value converted into 37.667 double value = (int)(origin * 1000 + .5); return (double) value / 1000; }
7881f4de357ce919344e2a54b85c81f2cdf2a759
83791905a74b72b8c18175916a7e193ddccbd7e0
/BaymaxMini_1_0/MotorControl.ino
7b3b740d2b629daa19ed5846845b95c824c2ac68
[]
no_license
hambone53/baymax_mini_base
7a3a77ca10427b194f2ede0fb4995d8da23996df
a1a0393bcab4741912ff65555b153dd51445b15d
refs/heads/master
2020-12-01T04:59:37.448990
2017-05-21T02:04:21
2017-05-21T02:04:21
67,905,314
0
0
null
null
null
null
UTF-8
C++
false
false
7,778
ino
MotorControl.ino
#include <Arduino.h> /********************************************************* * Motor control software to drive front end and calculate position and velocity * information from quad encoders. * * By: Ryan Hamor * Data: 1/5/2016 ***********************************************************/ //Includes #include "MotorControl.h" //Define constant motor hardware parameters #define ENCODER_PPR 400 #define MOTOR_GEAR_RATION 30 #define ENCODER_PULSE_PER_METER 30641 #define WHEEL_BASE_IN_M 0.250 #define WHEEL_RADIUS_M 0.060 #define BASE_DRIVE_PGAIN 200.0 #define BASE_DRIVE_IGAIN 400.0 #define BASE_DRIVE_DGAIN 0.0 #define BASE_DRIVE_MAX 80.0 #define BASE_DRIVE_MIN -80.0 #define BASE_DRIVE_TS_MS 40 #define FEED_FWD_PERCENT 0.8 #define SABER_CMD_DEAD_ZONE 8 #define MAX_SABER_CMD 120 #define MIN_LINEAR_VEL_MS 0.2 /*********************************************************************************************** * * initMotorControl() * * Description: Function to initialize motor control PID Loops and other misc * ***********************************************************************************************/ void initMotorControl() { //Setup the PID parameters for the right and left drives g_RightSidePID.SetMode(MANUAL); g_RightSidePID.SetOutputLimits(BASE_DRIVE_MIN, BASE_DRIVE_MAX); g_RightSidePID.SetTunings(BASE_DRIVE_PGAIN, BASE_DRIVE_IGAIN, BASE_DRIVE_DGAIN); g_RightSidePID.SetSampleTime(BASE_DRIVE_TS_MS); g_LeftSidePID.SetMode(MANUAL); g_LeftSidePID.SetOutputLimits(BASE_DRIVE_MIN, BASE_DRIVE_MAX); g_LeftSidePID.SetTunings(BASE_DRIVE_PGAIN, BASE_DRIVE_IGAIN, BASE_DRIVE_DGAIN); g_LeftSidePID.SetSampleTime(BASE_DRIVE_TS_MS); } void readEncoderTest() { //Serial.print("Right Wheel Position: ");Serial.print(rightFrontWheelEncoder.read()); //Serial.print("\tLeft Wheel Position: ");Serial.println(leftFrontWheelEncoder.read()); } void calculateVelAndPos(unsigned long tasktime) { float leftEncoderCnts = (float)leftFrontWheelEncoder.read(); float rightEncoderCnts = (float)rightFrontWheelEncoder.read(); float f32_tasktime = (float)tasktime / 1000; (void) calcPosition(leftEncoderCnts, rightEncoderCnts); //Single Kalman Filter Perseistents static KalmanVars leftMotorKVars; static KalmanVars rightMotorKVars; //Calc M-method velocities. Note: we have zeroed out encoder reads each time so no need to subtract. leftMotor_RPM = (60 * leftEncoderCnts) / (ENCODER_PPR * f32_tasktime); rightMotor_RPM = (60 * rightEncoderCnts) / (ENCODER_PPR * f32_tasktime); //Get Velocity Estimates through single dimensional kalman filter leftMotorKVars = EstimateVelocity(leftMotorKVars, f32_tasktime, leftMotor_RPM); rightMotorKVars = EstimateVelocity(rightMotorKVars, f32_tasktime, rightMotor_RPM); leftMotor_RPM = leftMotorKVars.FilteredVelocity; rightMotor_RPM = rightMotorKVars.FilteredVelocity; g_rightVelocity_ms = (double)((rightMotor_RPM * ENCODER_PPR) / 60) / ENCODER_PULSE_PER_METER; g_leftVelocity_ms = (double)((leftMotor_RPM * ENCODER_PPR) / 60) / ENCODER_PULSE_PER_METER; (void) updateXYVelocityEstimate(); //Reset Encoders for next read rightFrontWheelEncoder.write(0); leftFrontWheelEncoder.write(0); } /********************************************************************************************* * * Description: This function updates an estimated x and y for the base unit. * *********************************************************************************************/ void calcPosition(float leftCnts, float rightCnts) { float leftMeters = leftCnts/ENCODER_PULSE_PER_METER; float rightMeters = rightCnts/ENCODER_PULSE_PER_METER; float avgMeters = (leftMeters + rightMeters) * 0.5; g_xPos_m += avgMeters * cos(g_theta_rad); g_yPos_m += avgMeters * sin(g_theta_rad); } /********************************************************************************************* * * Description: This function updates an estimated x and y velocity for the base unit. * *********************************************************************************************/ void updateXYVelocityEstimate() { float avgVelocityMS = (g_rightVelocity_ms + g_leftVelocity_ms) * 0.5; g_xVel_ms = avgVelocityMS * cos(g_theta_rad); g_yVel_ms = avgVelocityMS * sin(g_theta_rad); } /********************************************************************************************* * * DriveControl_Step * * Desc: This function when called computes the new base drive commands for left and right drives. * **********************************************************************************************/ void DriveControl_Step() { int8_t RightMotorCmd = 0; int8_t LeftMotorCmd = 0; g_LeftSidePID.SetMode(AUTOMATIC); g_RightSidePID.SetMode(AUTOMATIC); //Compute new setpoints g_rightDriveVelocityCmd_ms = (g_LinearVelocityChecked + g_AngularVelocityChecked * WHEEL_BASE_IN_M / 2.0); // WHEEL_RADIUS_M; g_leftDriveVelocityCmd_ms = (g_LinearVelocityChecked - g_AngularVelocityChecked * WHEEL_BASE_IN_M / 2.0); // WHEEL_RADIUS_M; //Apply Deadzone check on velocity to make sure we move if commanded g_rightDriveVelocityCmd_ms = DeadZoneVelocity(g_rightDriveVelocityCmd_ms); g_leftDriveVelocityCmd_ms = DeadZoneVelocity(g_leftDriveVelocityCmd_ms); //Compute feedforward command g_RightDriveFeedFwdCmd = FEED_FWD_PERCENT * (g_rightDriveVelocityCmd_ms * 100); g_LeftDriveFeedFwdCmd = FEED_FWD_PERCENT * (g_leftDriveVelocityCmd_ms * 100); g_LeftSidePID.Compute(); g_RightSidePID.Compute(); //Handle the fact that the drives won't really move unless we have some deadzone we take care of. RightMotorCmd = g_rightDriveSaberCmd + g_RightDriveFeedFwdCmd; LeftMotorCmd = g_leftDriveSaberCmd + g_LeftDriveFeedFwdCmd; //Limit Commands to saber controller LeftMotorCmd = LimitSaberCmd( LeftMotorCmd ); RightMotorCmd = LimitSaberCmd( RightMotorCmd ); //Output Final Commands to Saber motor controller ST.motor(1, RightMotorCmd); ST.motor(2, LeftMotorCmd); } /********************************************************************************************* * * LimitSaberCmd * * Desc: This func will saturate saber motor controller commands such that they don't cause it * to go open loop. * **********************************************************************************************/ int8_t LimitSaberCmd( int8_t Cmd ) { if (Cmd < -MAX_SABER_CMD) { Cmd = -MAX_SABER_CMD; } else if (Cmd > MAX_SABER_CMD) { Cmd = MAX_SABER_CMD; } return Cmd; } /********************************************************************************************* * * DeadZoneVelocity * * Desc: This func will apply a deadzone where commands that are non-zero but less than the min * are set to the minimum speed the system is capable of. * **********************************************************************************************/ double DeadZoneVelocity( double Cmd ) { double DeadZoneCheckedCmd = 0.0; //1. Check Not Zero if ((Cmd < -0.0001) || (Cmd > 0.0001)) { //Negative Command if ( Cmd < -0.0001 ) { if ( Cmd > -MIN_LINEAR_VEL_MS ) { DeadZoneCheckedCmd = -MIN_LINEAR_VEL_MS; } else { DeadZoneCheckedCmd = Cmd; } } //Positive Cmd else { if (Cmd < MIN_LINEAR_VEL_MS ) { DeadZoneCheckedCmd = MIN_LINEAR_VEL_MS; } else { DeadZoneCheckedCmd = Cmd; } } } else { DeadZoneCheckedCmd = 0.0; } return DeadZoneCheckedCmd; }
652259f92eaed6b14432500c6f1bc9932e6ae3c0
447260501e673d85654ff77371ef02806e64fbe9
/cf/cf#172/B.cpp
aaffbcd347a04927014fc40e91f2e1c7b909a183
[]
no_license
keroro520/ACM
2fe36bd70e48c63eef0f1db73fcd244dcc78795d
d538e96f46aebec8c58448f3d936ba81a1643ea3
refs/heads/master
2016-09-07T18:54:27.379026
2014-05-19T13:44:25
2014-05-19T13:44:25
18,795,719
3
2
null
null
null
null
UTF-8
C++
false
false
563
cpp
B.cpp
/* WA 不想做了 大体思路是枚举b,算出a,就是细节神马的比较麻烦,不想弄。 */ #include <stdio.h> #include <math.h> int main() { int x,y,n; scanf("%d%d%d", &x, &y, &n); int demo, nume; double ans = 9999999.99999; for(int b = 1; b <= n; b++) { int a = (int)round(fabs(b * x*1.0 / y-0.000001)); double tmp = fabs((b*x-a*y)*1.0/b*y); if(tmp < ans) { ans = tmp; demo = b; nume = a; } } printf("%d/%d\n", nume, demo); return 0; }
61d55746a0e386dfbe8ae3c2b59a196249d2e446
931209925ff404c20ca2aa9090b0587bd9674aa2
/lab_processing_arduino/arduino/readval/readval.ino
cbe17e446a185fc6345749e232203cf2e7ea8d9e
[]
no_license
markupartist/arduinolab
de69f0cffd08779e6dd59a21145b3dffe0a4c390
41a1b4ff24c6586c301cdda2e1cc16e7503930ac
refs/heads/master
2021-01-10T07:12:06.592407
2014-02-15T15:48:35
2014-02-15T15:48:35
null
0
0
null
null
null
null
UTF-8
C++
false
false
607
ino
readval.ino
// Read a value sent from Processing. // Use this demo with the Processing app "sendval". int ledPin = 13; int val = 0; void setup() { startSerial(); pinMode(ledPin, OUTPUT); } void loop() { loopSerial(); // Volume is sent as 0 to 100, we need to map this to 0 to 255. int brightness = map(val, 0, 100, 0, 255); analogWrite(ledPin, brightness); } // Called when we have something to read from the serial port. void onSerialData(char command) { switch(command) { // Format: v[value], where value is an integer. Example v42 case 'v': val = decode(1); break; } }
250c579e4ac4776276357d0f5dd798108525485e
e541d2bc575eb68818c0b2eeeeeabe0de209574f
/src/YouMeCommon/opus-1.1/celt/celt_encoder.cpp
105280e8f7ef42acc5aec05f5a435e1da14f8212
[]
no_license
wangscript007/dev
0d673981718993df0b971a5cd7a262cc217c6d9d
e47da659aadc220883b5e8067b25dc80108876b9
refs/heads/master
2022-08-05T00:53:31.844228
2020-05-24T05:20:44
2020-05-24T05:20:44
null
0
0
null
null
null
null
UTF-8
C++
false
false
76,855
cpp
celt_encoder.cpp
/* Copyright (c) 2007-2008 CSIRO Copyright (c) 2007-2010 Xiph.Org Foundation Copyright (c) 2008 Gregory Maxwell Written by Jean-Marc Valin and Gregory Maxwell */ /* 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. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #define CELT_ENCODER_C #include "cpu_support.h" #include "os_support.h" #include "mdct.h" #include <math.h> #include "celt.h" #include "pitch.h" #include "bands.h" #include "modes.h" #include "entcode.h" #include "quant_bands.h" #include "rate.h" #include "stack_alloc.h" #include "mathops.h" #include "float_cast.h" #include <stdarg.h> #include "celt_lpc.h" #include "vq.h" namespace youmecommon { /** Encoder state @brief Encoder state */ struct OpusCustomEncoder { const OpusCustomMode *mode; /**< Mode used by the encoder */ int channels; int stream_channels; int force_intra; int clip; int disable_pf; int complexity; int upsample; int start, end; opus_int32 bitrate; int vbr; int signalling; int constrained_vbr; /* If zero, VBR can do whatever it likes with the rate */ int loss_rate; int lsb_depth; int variable_duration; int lfe; int arch; /* Everything beyond this point gets cleared on a reset */ #define ENCODER_RESET_START rng opus_uint32 rng; int spread_decision; opus_val32 delayedIntra; int tonal_average; int lastCodedBands; int hf_average; int tapset_decision; int prefilter_period; opus_val16 prefilter_gain; int prefilter_tapset; #ifdef RESYNTH int prefilter_period_old; opus_val16 prefilter_gain_old; int prefilter_tapset_old; #endif int consec_transient; AnalysisInfo analysis; opus_val32 preemph_memE[2]; opus_val32 preemph_memD[2]; /* VBR-related parameters */ opus_int32 vbr_reservoir; opus_int32 vbr_drift; opus_int32 vbr_offset; opus_int32 vbr_count; opus_val32 overlap_max; opus_val16 stereo_saving; int intensity; opus_val16 *energy_mask; opus_val16 spec_avg; #ifdef RESYNTH /* +MAX_PERIOD/2 to make space for overlap */ celt_sig syn_mem[2][2*MAX_PERIOD+MAX_PERIOD/2]; #endif celt_sig in_mem[1]; /* Size = channels*mode->overlap */ /* celt_sig prefilter_mem[], Size = channels*COMBFILTER_MAXPERIOD */ /* opus_val16 oldBandE[], Size = channels*mode->nbEBands */ /* opus_val16 oldLogE[], Size = channels*mode->nbEBands */ /* opus_val16 oldLogE2[], Size = channels*mode->nbEBands */ }; int celt_encoder_get_size(int channels) { CELTMode *mode = opus_custom_mode_create(48000, 960, NULL); return opus_custom_encoder_get_size(mode, channels); } OPUS_CUSTOM_NOSTATIC int opus_custom_encoder_get_size(const CELTMode *mode, int channels) { int size = sizeof(struct CELTEncoder) + (channels*mode->overlap-1)*sizeof(celt_sig) /* celt_sig in_mem[channels*mode->overlap]; */ + channels*COMBFILTER_MAXPERIOD*sizeof(celt_sig) /* celt_sig prefilter_mem[channels*COMBFILTER_MAXPERIOD]; */ + 3*channels*mode->nbEBands*sizeof(opus_val16); /* opus_val16 oldBandE[channels*mode->nbEBands]; */ /* opus_val16 oldLogE[channels*mode->nbEBands]; */ /* opus_val16 oldLogE2[channels*mode->nbEBands]; */ return size; } #ifdef CUSTOM_MODES CELTEncoder *opus_custom_encoder_create(const CELTMode *mode, int channels, int *error) { int ret; CELTEncoder *st = (CELTEncoder *)opus_alloc(opus_custom_encoder_get_size(mode, channels)); /* init will handle the NULL case */ ret = opus_custom_encoder_init(st, mode, channels); if (ret != OPUS_OK) { opus_custom_encoder_destroy(st); st = NULL; } if (error) *error = ret; return st; } #endif /* CUSTOM_MODES */ static int opus_custom_encoder_init_arch(CELTEncoder *st, const CELTMode *mode, int channels, int arch) { if (channels < 0 || channels > 2) return OPUS_BAD_ARG; if (st==NULL || mode==NULL) return OPUS_ALLOC_FAIL; OPUS_CLEAR((char*)st, opus_custom_encoder_get_size(mode, channels)); st->mode = mode; st->stream_channels = st->channels = channels; st->upsample = 1; st->start = 0; st->end = st->mode->effEBands; st->signalling = 1; st->arch = arch; st->constrained_vbr = 1; st->clip = 1; st->bitrate = OPUS_BITRATE_MAX; st->vbr = 0; st->force_intra = 0; st->complexity = 5; st->lsb_depth=24; opus_custom_encoder_ctl(st, OPUS_RESET_STATE); return OPUS_OK; } #ifdef CUSTOM_MODES int opus_custom_encoder_init(CELTEncoder *st, const CELTMode *mode, int channels) { return opus_custom_encoder_init_arch(st, mode, channels, opus_select_arch()); } #endif int celt_encoder_init(CELTEncoder *st, opus_int32 sampling_rate, int channels, int arch) { int ret; ret = opus_custom_encoder_init_arch(st, opus_custom_mode_create(48000, 960, NULL), channels, arch); if (ret != OPUS_OK) return ret; st->upsample = resampling_factor(sampling_rate); return OPUS_OK; } #ifdef CUSTOM_MODES void opus_custom_encoder_destroy(CELTEncoder *st) { opus_free(st); } #endif /* CUSTOM_MODES */ static int transient_analysis(const opus_val32 * OPUS_RESTRICT in, int len, int C, opus_val16 *tf_estimate, int *tf_chan) { int i; VARDECL(opus_val16, tmp); opus_val32 mem0,mem1; int is_transient = 0; opus_int32 mask_metric = 0; int c; opus_val16 tf_max; int len2; /* Table of 6*64/x, trained on real data to minimize the average error */ static const unsigned char inv_table[128] = { 255,255,156,110, 86, 70, 59, 51, 45, 40, 37, 33, 31, 28, 26, 25, 23, 22, 21, 20, 19, 18, 17, 16, 16, 15, 15, 14, 13, 13, 12, 12, 12, 12, 11, 11, 11, 10, 10, 10, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, }; SAVE_STACK; ALLOC(tmp, len, opus_val16); len2=len/2; for (c=0;c<C;c++) { opus_val32 mean; opus_int32 unmask=0; opus_val32 norm; opus_val16 maxE; mem0=0; mem1=0; /* High-pass filter: (1 - 2*z^-1 + z^-2) / (1 - z^-1 + .5*z^-2) */ for (i=0;i<len;i++) { opus_val32 x,y; x = SHR32(in[i+c*len],SIG_SHIFT); y = ADD32(mem0, x); #ifdef FIXED_POINT mem0 = mem1 + y - SHL32(x,1); mem1 = x - SHR32(y,1); #else mem0 = mem1 + y - 2*x; mem1 = x - .5f*y; #endif tmp[i] = EXTRACT16(SHR32(y,2)); /*printf("%f ", tmp[i]);*/ } /*printf("\n");*/ /* First few samples are bad because we don't propagate the memory */ OPUS_CLEAR(tmp, 12); #ifdef FIXED_POINT /* Normalize tmp to max range */ { int shift=0; shift = 14-celt_ilog2(1+celt_maxabs16(tmp, len)); if (shift!=0) { for (i=0;i<len;i++) tmp[i] = SHL16(tmp[i], shift); } } #endif mean=0; mem0=0; /* Grouping by two to reduce complexity */ /* Forward pass to compute the post-echo threshold*/ for (i=0;i<len2;i++) { opus_val16 x2 = PSHR32(MULT16_16(tmp[2*i],tmp[2*i]) + MULT16_16(tmp[2*i+1],tmp[2*i+1]),16); mean += x2; #ifdef FIXED_POINT /* FIXME: Use PSHR16() instead */ tmp[i] = mem0 + PSHR32(x2-mem0,4); #else tmp[i] = mem0 + MULT16_16_P15(QCONST16(.0625f,15),x2-mem0); #endif mem0 = tmp[i]; } mem0=0; maxE=0; /* Backward pass to compute the pre-echo threshold */ for (i=len2-1;i>=0;i--) { #ifdef FIXED_POINT /* FIXME: Use PSHR16() instead */ tmp[i] = mem0 + PSHR32(tmp[i]-mem0,3); #else tmp[i] = mem0 + MULT16_16_P15(QCONST16(0.125f,15),tmp[i]-mem0); #endif mem0 = tmp[i]; maxE = MAX16(maxE, mem0); } /*for (i=0;i<len2;i++)printf("%f ", tmp[i]/mean);printf("\n");*/ /* Compute the ratio of the "frame energy" over the harmonic mean of the energy. This essentially corresponds to a bitrate-normalized temporal noise-to-mask ratio */ /* As a compromise with the old transient detector, frame energy is the geometric mean of the energy and half the max */ #ifdef FIXED_POINT /* Costs two sqrt() to avoid overflows */ mean = MULT16_16(celt_sqrt(mean), celt_sqrt(MULT16_16(maxE,len2>>1))); #else mean = celt_sqrt(mean * maxE*.5*len2); #endif /* Inverse of the mean energy in Q15+6 */ norm = SHL32(EXTEND32(len2),6+14)/ADD32(EPSILON,SHR32(mean,1)); /* Compute harmonic mean discarding the unreliable boundaries The data is smooth, so we only take 1/4th of the samples */ unmask=0; for (i=12;i<len2-5;i+=4) { int id; #ifdef FIXED_POINT id = MAX32(0,MIN32(127,MULT16_32_Q15(tmp[i]+EPSILON,norm))); /* Do not round to nearest */ #else id = (int)MAX32(0,MIN32(127,floor(64*norm*(tmp[i]+EPSILON)))); /* Do not round to nearest */ #endif unmask += inv_table[id]; } /*printf("%d\n", unmask);*/ /* Normalize, compensate for the 1/4th of the sample and the factor of 6 in the inverse table */ unmask = 64*unmask*4/(6*(len2-17)); if (unmask>mask_metric) { *tf_chan = c; mask_metric = unmask; } } is_transient = mask_metric>200; /* Arbitrary metric for VBR boost */ tf_max = MAX16(0,celt_sqrt(27*mask_metric)-42); /* *tf_estimate = 1 + MIN16(1, sqrt(MAX16(0, tf_max-30))/20); */ *tf_estimate = celt_sqrt(MAX32(0, SHL32(MULT16_16(QCONST16(0.0069,14),MIN16(163,tf_max)),14)-QCONST32(0.139,28))); /*printf("%d %f\n", tf_max, mask_metric);*/ RESTORE_STACK; #ifdef FUZZING is_transient = rand()&0x1; #endif /*printf("%d %f %d\n", is_transient, (float)*tf_estimate, tf_max);*/ return is_transient; } /* Looks for sudden increases of energy to decide whether we need to patch the transient decision */ static int patch_transient_decision(opus_val16 *newE, opus_val16 *oldE, int nbEBands, int start, int end, int C) { int i, c; opus_val32 mean_diff=0; opus_val16 spread_old[26]; /* Apply an aggressive (-6 dB/Bark) spreading function to the old frame to avoid false detection caused by irrelevant bands */ if (C==1) { spread_old[start] = oldE[start]; for (i=start+1;i<end;i++) spread_old[i] = MAX16(spread_old[i-1]-QCONST16(1.0f, DB_SHIFT), oldE[i]); } else { spread_old[start] = MAX16(oldE[start],oldE[start+nbEBands]); for (i=start+1;i<end;i++) spread_old[i] = MAX16(spread_old[i-1]-QCONST16(1.0f, DB_SHIFT), MAX16(oldE[i],oldE[i+nbEBands])); } for (i=end-2;i>=start;i--) spread_old[i] = MAX16(spread_old[i], spread_old[i+1]-QCONST16(1.0f, DB_SHIFT)); /* Compute mean increase */ c=0; do { for (i=IMAX(2,start);i<end-1;i++) { opus_val16 x1, x2; x1 = MAX16(0, newE[i + c*nbEBands]); x2 = MAX16(0, spread_old[i]); mean_diff = ADD32(mean_diff, EXTEND32(MAX16(0, SUB16(x1, x2)))); } } while (++c<C); mean_diff = DIV32(mean_diff, C*(end-1-IMAX(2,start))); /*printf("%f %f %d\n", mean_diff, max_diff, count);*/ return mean_diff > QCONST16(1.f, DB_SHIFT); } /** Apply window and compute the MDCT for all sub-frames and all channels in a frame */ static void compute_mdcts(const CELTMode *mode, int shortBlocks, celt_sig * OPUS_RESTRICT in, celt_sig * OPUS_RESTRICT out, int C, int CC, int LM, int upsample, int arch) { const int overlap = mode->overlap; int N; int B; int shift; int i, b, c; if (shortBlocks) { B = shortBlocks; N = mode->shortMdctSize; shift = mode->maxLM; } else { B = 1; N = mode->shortMdctSize<<LM; shift = mode->maxLM-LM; } c=0; do { for (b=0;b<B;b++) { /* Interleaving the sub-frames while doing the MDCTs */ clt_mdct_forward(&mode->mdct, in+c*(B*N+overlap)+b*N, &out[b+c*N*B], mode->window, overlap, shift, B, arch); } } while (++c<CC); if (CC==2&&C==1) { for (i=0;i<B*N;i++) out[i] = ADD32(HALF32(out[i]), HALF32(out[B*N+i])); } if (upsample != 1) { c=0; do { int bound = B*N/upsample; for (i=0;i<bound;i++) out[c*B*N+i] *= upsample; OPUS_CLEAR(&out[c*B*N+bound], B*N-bound); } while (++c<C); } } void celt_preemphasis(const opus_val16 * OPUS_RESTRICT pcmp, celt_sig * OPUS_RESTRICT inp, int N, int CC, int upsample, const opus_val16 *coef, celt_sig *mem, int clip) { int i; opus_val16 coef0; celt_sig m; int Nu; coef0 = coef[0]; m = *mem; /* Fast path for the normal 48kHz case and no clipping */ if (coef[1] == 0 && upsample == 1 && !clip) { for (i=0;i<N;i++) { opus_val16 x; x = SCALEIN(pcmp[CC*i]); /* Apply pre-emphasis */ inp[i] = SHL32(x, SIG_SHIFT) - m; m = SHR32(MULT16_16(coef0, x), 15-SIG_SHIFT); } *mem = m; return; } Nu = N/upsample; if (upsample!=1) { OPUS_CLEAR(inp, N); } for (i=0;i<Nu;i++) inp[i*upsample] = SCALEIN(pcmp[CC*i]); #ifndef FIXED_POINT if (clip) { /* Clip input to avoid encoding non-portable files */ for (i=0;i<Nu;i++) inp[i*upsample] = MAX32(-65536.f, MIN32(65536.f,inp[i*upsample])); } #else (void)clip; /* Avoids a warning about clip being unused. */ #endif #ifdef CUSTOM_MODES if (coef[1] != 0) { opus_val16 coef1 = coef[1]; opus_val16 coef2 = coef[2]; for (i=0;i<N;i++) { celt_sig x, tmp; x = inp[i]; /* Apply pre-emphasis */ tmp = MULT16_16(coef2, x); inp[i] = tmp + m; m = MULT16_32_Q15(coef1, inp[i]) - MULT16_32_Q15(coef0, tmp); } } else #endif { for (i=0;i<N;i++) { opus_val16 x; x = inp[i]; /* Apply pre-emphasis */ inp[i] = SHL32(x, SIG_SHIFT) - m; m = SHR32(MULT16_16(coef0, x), 15-SIG_SHIFT); } } *mem = m; } static opus_val32 l1_metric(const celt_norm *tmp, int N, int LM, opus_val16 bias) { int i; opus_val32 L1; L1 = 0; for (i=0;i<N;i++) L1 += EXTEND32(ABS16(tmp[i])); /* When in doubt, prefer good freq resolution */ L1 = MAC16_32_Q15(L1, LM*bias, L1); return L1; } static int tf_analysis(const CELTMode *m, int len, int isTransient, int *tf_res, int lambda, celt_norm *X, int N0, int LM, int *tf_sum, opus_val16 tf_estimate, int tf_chan) { int i; VARDECL(int, metric); int cost0; int cost1; VARDECL(int, path0); VARDECL(int, path1); VARDECL(celt_norm, tmp); VARDECL(celt_norm, tmp_1); int sel; int selcost[2]; int tf_select=0; opus_val16 bias; SAVE_STACK; bias = MULT16_16_Q14(QCONST16(.04f,15), MAX16(-QCONST16(.25f,14), QCONST16(.5f,14)-tf_estimate)); /*printf("%f ", bias);*/ ALLOC(metric, len, int); ALLOC(tmp, (m->eBands[len]-m->eBands[len-1])<<LM, celt_norm); ALLOC(tmp_1, (m->eBands[len]-m->eBands[len-1])<<LM, celt_norm); ALLOC(path0, len, int); ALLOC(path1, len, int); *tf_sum = 0; for (i=0;i<len;i++) { int k, N; int narrow; opus_val32 L1, best_L1; int best_level=0; N = (m->eBands[i+1]-m->eBands[i])<<LM; /* band is too narrow to be split down to LM=-1 */ narrow = (m->eBands[i+1]-m->eBands[i])==1; OPUS_COPY(tmp, &X[tf_chan*N0 + (m->eBands[i]<<LM)], N); /* Just add the right channel if we're in stereo */ /*if (C==2) for (j=0;j<N;j++) tmp[j] = ADD16(SHR16(tmp[j], 1),SHR16(X[N0+j+(m->eBands[i]<<LM)], 1));*/ L1 = l1_metric(tmp, N, isTransient ? LM : 0, bias); best_L1 = L1; /* Check the -1 case for transients */ if (isTransient && !narrow) { OPUS_COPY(tmp_1, tmp, N); haar1(tmp_1, N>>LM, 1<<LM); L1 = l1_metric(tmp_1, N, LM+1, bias); if (L1<best_L1) { best_L1 = L1; best_level = -1; } } /*printf ("%f ", L1);*/ for (k=0;k<LM+!(isTransient||narrow);k++) { int B; if (isTransient) B = (LM-k-1); else B = k+1; haar1(tmp, N>>k, 1<<k); L1 = l1_metric(tmp, N, B, bias); if (L1 < best_L1) { best_L1 = L1; best_level = k+1; } } /*printf ("%d ", isTransient ? LM-best_level : best_level);*/ /* metric is in Q1 to be able to select the mid-point (-0.5) for narrower bands */ if (isTransient) metric[i] = 2*best_level; else metric[i] = -2*best_level; *tf_sum += (isTransient ? LM : 0) - metric[i]/2; /* For bands that can't be split to -1, set the metric to the half-way point to avoid biasing the decision */ if (narrow && (metric[i]==0 || metric[i]==-2*LM)) metric[i]-=1; /*printf("%d ", metric[i]);*/ } /*printf("\n");*/ /* Search for the optimal tf resolution, including tf_select */ tf_select = 0; for (sel=0;sel<2;sel++) { cost0 = 0; cost1 = isTransient ? 0 : lambda; for (i=1;i<len;i++) { int curr0, curr1; curr0 = IMIN(cost0, cost1 + lambda); curr1 = IMIN(cost0 + lambda, cost1); cost0 = curr0 + abs(metric[i]-2*tf_select_table[LM][4*isTransient+2*sel+0]); cost1 = curr1 + abs(metric[i]-2*tf_select_table[LM][4*isTransient+2*sel+1]); } cost0 = IMIN(cost0, cost1); selcost[sel]=cost0; } /* For now, we're conservative and only allow tf_select=1 for transients. * If tests confirm it's useful for non-transients, we could allow it. */ if (selcost[1]<selcost[0] && isTransient) tf_select=1; cost0 = 0; cost1 = isTransient ? 0 : lambda; /* Viterbi forward pass */ for (i=1;i<len;i++) { int curr0, curr1; int from0, from1; from0 = cost0; from1 = cost1 + lambda; if (from0 < from1) { curr0 = from0; path0[i]= 0; } else { curr0 = from1; path0[i]= 1; } from0 = cost0 + lambda; from1 = cost1; if (from0 < from1) { curr1 = from0; path1[i]= 0; } else { curr1 = from1; path1[i]= 1; } cost0 = curr0 + abs(metric[i]-2*tf_select_table[LM][4*isTransient+2*tf_select+0]); cost1 = curr1 + abs(metric[i]-2*tf_select_table[LM][4*isTransient+2*tf_select+1]); } tf_res[len-1] = cost0 < cost1 ? 0 : 1; /* Viterbi backward pass to check the decisions */ for (i=len-2;i>=0;i--) { if (tf_res[i+1] == 1) tf_res[i] = path1[i+1]; else tf_res[i] = path0[i+1]; } /*printf("%d %f\n", *tf_sum, tf_estimate);*/ RESTORE_STACK; #ifdef FUZZING tf_select = rand()&0x1; tf_res[0] = rand()&0x1; for (i=1;i<len;i++) tf_res[i] = tf_res[i-1] ^ ((rand()&0xF) == 0); #endif return tf_select; } static void tf_encode(int start, int end, int isTransient, int *tf_res, int LM, int tf_select, ec_enc *enc) { int curr, i; int tf_select_rsv; int tf_changed; int logp; opus_uint32 budget; opus_uint32 tell; budget = enc->storage*8; tell = ec_tell(enc); logp = isTransient ? 2 : 4; /* Reserve space to code the tf_select decision. */ tf_select_rsv = LM>0 && tell+logp+1 <= budget; budget -= tf_select_rsv; curr = tf_changed = 0; for (i=start;i<end;i++) { if (tell+logp<=budget) { ec_enc_bit_logp(enc, tf_res[i] ^ curr, logp); tell = ec_tell(enc); curr = tf_res[i]; tf_changed |= curr; } else tf_res[i] = curr; logp = isTransient ? 4 : 5; } /* Only code tf_select if it would actually make a difference. */ if (tf_select_rsv && tf_select_table[LM][4*isTransient+0+tf_changed]!= tf_select_table[LM][4*isTransient+2+tf_changed]) ec_enc_bit_logp(enc, tf_select, 1); else tf_select = 0; for (i=start;i<end;i++) tf_res[i] = tf_select_table[LM][4*isTransient+2*tf_select+tf_res[i]]; /*for(i=0;i<end;i++)printf("%d ", isTransient ? tf_res[i] : LM+tf_res[i]);printf("\n");*/ } static int alloc_trim_analysis(const CELTMode *m, const celt_norm *X, const opus_val16 *bandLogE, int end, int LM, int C, int N0, AnalysisInfo *analysis, opus_val16 *stereo_saving, opus_val16 tf_estimate, int intensity, opus_val16 surround_trim, int arch) { int i; opus_val32 diff=0; int c; int trim_index; opus_val16 trim = QCONST16(5.f, 8); opus_val16 logXC, logXC2; if (C==2) { opus_val16 sum = 0; /* Q10 */ opus_val16 minXC; /* Q10 */ /* Compute inter-channel correlation for low frequencies */ for (i=0;i<8;i++) { opus_val32 partial; partial = celt_inner_prod(&X[m->eBands[i]<<LM], &X[N0+(m->eBands[i]<<LM)], (m->eBands[i+1]-m->eBands[i])<<LM, arch); sum = ADD16(sum, EXTRACT16(SHR32(partial, 18))); } sum = MULT16_16_Q15(QCONST16(1.f/8, 15), sum); sum = MIN16(QCONST16(1.f, 10), ABS16(sum)); minXC = sum; for (i=8;i<intensity;i++) { opus_val32 partial; partial = celt_inner_prod(&X[m->eBands[i]<<LM], &X[N0+(m->eBands[i]<<LM)], (m->eBands[i+1]-m->eBands[i])<<LM, arch); minXC = MIN16(minXC, ABS16(EXTRACT16(SHR32(partial, 18)))); } minXC = MIN16(QCONST16(1.f, 10), ABS16(minXC)); /*printf ("%f\n", sum);*/ /* mid-side savings estimations based on the LF average*/ logXC = celt_log2(QCONST32(1.001f, 20)-MULT16_16(sum, sum)); /* mid-side savings estimations based on min correlation */ logXC2 = MAX16(HALF16(logXC), celt_log2(QCONST32(1.001f, 20)-MULT16_16(minXC, minXC))); #ifdef FIXED_POINT /* Compensate for Q20 vs Q14 input and convert output to Q8 */ logXC = PSHR32(logXC-QCONST16(6.f, DB_SHIFT),DB_SHIFT-8); logXC2 = PSHR32(logXC2-QCONST16(6.f, DB_SHIFT),DB_SHIFT-8); #endif trim += MAX16(-QCONST16(4.f, 8), MULT16_16_Q15(QCONST16(.75f,15),logXC)); *stereo_saving = MIN16(*stereo_saving + QCONST16(0.25f, 8), -HALF16(logXC2)); } /* Estimate spectral tilt */ c=0; do { for (i=0;i<end-1;i++) { diff += bandLogE[i+c*m->nbEBands]*(opus_int32)(2+2*i-end); } } while (++c<C); diff /= C*(end-1); /*printf("%f\n", diff);*/ trim -= MAX16(-QCONST16(2.f, 8), MIN16(QCONST16(2.f, 8), SHR16(diff+QCONST16(1.f, DB_SHIFT),DB_SHIFT-8)/6 )); trim -= SHR16(surround_trim, DB_SHIFT-8); trim -= 2*SHR16(tf_estimate, 14-8); #ifndef DISABLE_FLOAT_API if (analysis->valid) { trim -= MAX16(-QCONST16(2.f, 8), MIN16(QCONST16(2.f, 8), (opus_val16)(QCONST16(2.f, 8)*(analysis->tonality_slope+.05f)))); } #else (void)analysis; #endif #ifdef FIXED_POINT trim_index = PSHR32(trim, 8); #else trim_index = (int)floor(.5f+trim); #endif trim_index = IMAX(0, IMIN(10, trim_index)); /*printf("%d\n", trim_index);*/ #ifdef FUZZING trim_index = rand()%11; #endif return trim_index; } static int stereo_analysis(const CELTMode *m, const celt_norm *X, int LM, int N0) { int i; int thetas; opus_val32 sumLR = EPSILON, sumMS = EPSILON; /* Use the L1 norm to model the entropy of the L/R signal vs the M/S signal */ for (i=0;i<13;i++) { int j; for (j=m->eBands[i]<<LM;j<m->eBands[i+1]<<LM;j++) { opus_val32 L, R, M, S; /* We cast to 32-bit first because of the -32768 case */ L = EXTEND32(X[j]); R = EXTEND32(X[N0+j]); M = ADD32(L, R); S = SUB32(L, R); sumLR = ADD32(sumLR, ADD32(ABS32(L), ABS32(R))); sumMS = ADD32(sumMS, ADD32(ABS32(M), ABS32(S))); } } sumMS = MULT16_32_Q15(QCONST16(0.707107f, 15), sumMS); thetas = 13; /* We don't need thetas for lower bands with LM<=1 */ if (LM<=1) thetas -= 8; return MULT16_32_Q15((m->eBands[13]<<(LM+1))+thetas, sumMS) > MULT16_32_Q15(m->eBands[13]<<(LM+1), sumLR); } #define MSWAP(a,b) do {opus_val16 tmp = a;a=b;b=tmp;} while(0) static opus_val16 median_of_5(const opus_val16 *x) { opus_val16 t0, t1, t2, t3, t4; t2 = x[2]; if (x[0] > x[1]) { t0 = x[1]; t1 = x[0]; } else { t0 = x[0]; t1 = x[1]; } if (x[3] > x[4]) { t3 = x[4]; t4 = x[3]; } else { t3 = x[3]; t4 = x[4]; } if (t0 > t3) { MSWAP(t0, t3); MSWAP(t1, t4); } if (t2 > t1) { if (t1 < t3) return MIN16(t2, t3); else return MIN16(t4, t1); } else { if (t2 < t3) return MIN16(t1, t3); else return MIN16(t2, t4); } } static opus_val16 median_of_3(const opus_val16 *x) { opus_val16 t0, t1, t2; if (x[0] > x[1]) { t0 = x[1]; t1 = x[0]; } else { t0 = x[0]; t1 = x[1]; } t2 = x[2]; if (t1 < t2) return t1; else if (t0 < t2) return t2; else return t0; } static opus_val16 dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16 *bandLogE2, int nbEBands, int start, int end, int C, int *offsets, int lsb_depth, const opus_int16 *logN, int isTransient, int vbr, int constrained_vbr, const opus_int16 *eBands, int LM, int effectiveBytes, opus_int32 *tot_boost_, int lfe, opus_val16 *surround_dynalloc) { int i, c; opus_int32 tot_boost=0; opus_val16 maxDepth; VARDECL(opus_val16, follower); VARDECL(opus_val16, noise_floor); SAVE_STACK; ALLOC(follower, C*nbEBands, opus_val16); ALLOC(noise_floor, C*nbEBands, opus_val16); OPUS_CLEAR(offsets, nbEBands); /* Dynamic allocation code */ maxDepth=-QCONST16(31.9f, DB_SHIFT); for (i=0;i<end;i++) { /* Noise floor must take into account eMeans, the depth, the width of the bands and the preemphasis filter (approx. square of bark band ID) */ noise_floor[i] = MULT16_16(QCONST16(0.0625f, DB_SHIFT),logN[i]) +QCONST16(.5f,DB_SHIFT)+SHL16(9-lsb_depth,DB_SHIFT)-SHL16(eMeans[i],6) +MULT16_16(QCONST16(.0062,DB_SHIFT),(i+5)*(i+5)); } c=0;do { for (i=0;i<end;i++) maxDepth = MAX16(maxDepth, bandLogE[c*nbEBands+i]-noise_floor[i]); } while (++c<C); /* Make sure that dynamic allocation can't make us bust the budget */ if (effectiveBytes > 50 && LM>=1 && !lfe) { int last=0; c=0;do { opus_val16 offset; opus_val16 tmp; opus_val16 *f; f = &follower[c*nbEBands]; f[0] = bandLogE2[c*nbEBands]; for (i=1;i<end;i++) { /* The last band to be at least 3 dB higher than the previous one is the last we'll consider. Otherwise, we run into problems on bandlimited signals. */ if (bandLogE2[c*nbEBands+i] > bandLogE2[c*nbEBands+i-1]+QCONST16(.5f,DB_SHIFT)) last=i; f[i] = MIN16(f[i-1]+QCONST16(1.5f,DB_SHIFT), bandLogE2[c*nbEBands+i]); } for (i=last-1;i>=0;i--) f[i] = MIN16(f[i], MIN16(f[i+1]+QCONST16(2.f,DB_SHIFT), bandLogE2[c*nbEBands+i])); /* Combine with a median filter to avoid dynalloc triggering unnecessarily. The "offset" value controls how conservative we are -- a higher offset reduces the impact of the median filter and makes dynalloc use more bits. */ offset = QCONST16(1.f, DB_SHIFT); for (i=2;i<end-2;i++) f[i] = MAX16(f[i], median_of_5(&bandLogE2[c*nbEBands+i-2])-offset); tmp = median_of_3(&bandLogE2[c*nbEBands])-offset; f[0] = MAX16(f[0], tmp); f[1] = MAX16(f[1], tmp); tmp = median_of_3(&bandLogE2[c*nbEBands+end-3])-offset; f[end-2] = MAX16(f[end-2], tmp); f[end-1] = MAX16(f[end-1], tmp); for (i=0;i<end;i++) f[i] = MAX16(f[i], noise_floor[i]); } while (++c<C); if (C==2) { for (i=start;i<end;i++) { /* Consider 24 dB "cross-talk" */ follower[nbEBands+i] = MAX16(follower[nbEBands+i], follower[ i]-QCONST16(4.f,DB_SHIFT)); follower[ i] = MAX16(follower[ i], follower[nbEBands+i]-QCONST16(4.f,DB_SHIFT)); follower[i] = HALF16(MAX16(0, bandLogE[i]-follower[i]) + MAX16(0, bandLogE[nbEBands+i]-follower[nbEBands+i])); } } else { for (i=start;i<end;i++) { follower[i] = MAX16(0, bandLogE[i]-follower[i]); } } for (i=start;i<end;i++) follower[i] = MAX16(follower[i], surround_dynalloc[i]); /* For non-transient CBR/CVBR frames, halve the dynalloc contribution */ if ((!vbr || constrained_vbr)&&!isTransient) { for (i=start;i<end;i++) follower[i] = HALF16(follower[i]); } for (i=start;i<end;i++) { int width; int boost; int boost_bits; if (i<8) follower[i] *= 2; if (i>=12) follower[i] = HALF16(follower[i]); follower[i] = MIN16(follower[i], QCONST16(4, DB_SHIFT)); width = C*(eBands[i+1]-eBands[i])<<LM; if (width<6) { boost = (int)SHR32(EXTEND32(follower[i]),DB_SHIFT); boost_bits = boost*width<<BITRES; } else if (width > 48) { boost = (int)SHR32(EXTEND32(follower[i])*8,DB_SHIFT); boost_bits = (boost*width<<BITRES)/8; } else { boost = (int)SHR32(EXTEND32(follower[i])*width/6,DB_SHIFT); boost_bits = boost*6<<BITRES; } /* For CBR and non-transient CVBR frames, limit dynalloc to 1/4 of the bits */ if ((!vbr || (constrained_vbr&&!isTransient)) && (tot_boost+boost_bits)>>BITRES>>3 > effectiveBytes/4) { opus_int32 cap = ((effectiveBytes/4)<<BITRES<<3); offsets[i] = cap-tot_boost; tot_boost = cap; break; } else { offsets[i] = boost; tot_boost += boost_bits; } } } *tot_boost_ = tot_boost; RESTORE_STACK; return maxDepth; } static int run_prefilter(CELTEncoder *st, celt_sig *in, celt_sig *prefilter_mem, int CC, int N, int prefilter_tapset, int *pitch, opus_val16 *gain, int *qgain, int enabled, int nbAvailableBytes) { int c; VARDECL(celt_sig, _pre); celt_sig *pre[2]; const CELTMode *mode; int pitch_index; opus_val16 gain1; opus_val16 pf_threshold; int pf_on; int qg; int overlap; SAVE_STACK; mode = st->mode; overlap = mode->overlap; ALLOC(_pre, CC*(N+COMBFILTER_MAXPERIOD), celt_sig); pre[0] = _pre; pre[1] = _pre + (N+COMBFILTER_MAXPERIOD); c=0; do { OPUS_COPY(pre[c], prefilter_mem+c*COMBFILTER_MAXPERIOD, COMBFILTER_MAXPERIOD); OPUS_COPY(pre[c]+COMBFILTER_MAXPERIOD, in+c*(N+overlap)+overlap, N); } while (++c<CC); if (enabled) { VARDECL(opus_val16, pitch_buf); ALLOC(pitch_buf, (COMBFILTER_MAXPERIOD+N)>>1, opus_val16); pitch_downsample(pre, pitch_buf, COMBFILTER_MAXPERIOD+N, CC, st->arch); /* Don't search for the fir last 1.5 octave of the range because there's too many false-positives due to short-term correlation */ pitch_search(pitch_buf+(COMBFILTER_MAXPERIOD>>1), pitch_buf, N, COMBFILTER_MAXPERIOD-3*COMBFILTER_MINPERIOD, &pitch_index, st->arch); pitch_index = COMBFILTER_MAXPERIOD-pitch_index; gain1 = remove_doubling(pitch_buf, COMBFILTER_MAXPERIOD, COMBFILTER_MINPERIOD, N, &pitch_index, st->prefilter_period, st->prefilter_gain, st->arch); if (pitch_index > COMBFILTER_MAXPERIOD-2) pitch_index = COMBFILTER_MAXPERIOD-2; gain1 = MULT16_16_Q15(QCONST16(.7f,15),gain1); /*printf("%d %d %f %f\n", pitch_change, pitch_index, gain1, st->analysis.tonality);*/ if (st->loss_rate>2) gain1 = HALF32(gain1); if (st->loss_rate>4) gain1 = HALF32(gain1); if (st->loss_rate>8) gain1 = 0; } else { gain1 = 0; pitch_index = COMBFILTER_MINPERIOD; } /* Gain threshold for enabling the prefilter/postfilter */ pf_threshold = QCONST16(.2f,15); /* Adjusting the threshold based on rate and continuity */ if (abs(pitch_index-st->prefilter_period)*10>pitch_index) pf_threshold += QCONST16(.2f,15); if (nbAvailableBytes<25) pf_threshold += QCONST16(.1f,15); if (nbAvailableBytes<35) pf_threshold += QCONST16(.1f,15); if (st->prefilter_gain > QCONST16(.4f,15)) pf_threshold -= QCONST16(.1f,15); if (st->prefilter_gain > QCONST16(.55f,15)) pf_threshold -= QCONST16(.1f,15); /* Hard threshold at 0.2 */ pf_threshold = MAX16(pf_threshold, QCONST16(.2f,15)); if (gain1<pf_threshold) { gain1 = 0; pf_on = 0; qg = 0; } else { /*This block is not gated by a total bits check only because of the nbAvailableBytes check above.*/ if (ABS16(gain1-st->prefilter_gain)<QCONST16(.1f,15)) gain1=st->prefilter_gain; #ifdef FIXED_POINT qg = ((gain1+1536)>>10)/3-1; #else qg = (int)floor(.5f+gain1*32/3)-1; #endif qg = IMAX(0, IMIN(7, qg)); gain1 = QCONST16(0.09375f,15)*(qg+1); pf_on = 1; } /*printf("%d %f\n", pitch_index, gain1);*/ c=0; do { int offset = mode->shortMdctSize-overlap; st->prefilter_period=IMAX(st->prefilter_period, COMBFILTER_MINPERIOD); OPUS_COPY(in+c*(N+overlap), st->in_mem+c*(overlap), overlap); if (offset) comb_filter(in+c*(N+overlap)+overlap, pre[c]+COMBFILTER_MAXPERIOD, st->prefilter_period, st->prefilter_period, offset, -st->prefilter_gain, -st->prefilter_gain, st->prefilter_tapset, st->prefilter_tapset, NULL, 0, st->arch); comb_filter(in+c*(N+overlap)+overlap+offset, pre[c]+COMBFILTER_MAXPERIOD+offset, st->prefilter_period, pitch_index, N-offset, -st->prefilter_gain, -gain1, st->prefilter_tapset, prefilter_tapset, mode->window, overlap, st->arch); OPUS_COPY(st->in_mem+c*(overlap), in+c*(N+overlap)+N, overlap); if (N>COMBFILTER_MAXPERIOD) { OPUS_MOVE(prefilter_mem+c*COMBFILTER_MAXPERIOD, pre[c]+N, COMBFILTER_MAXPERIOD); } else { OPUS_MOVE(prefilter_mem+c*COMBFILTER_MAXPERIOD, prefilter_mem+c*COMBFILTER_MAXPERIOD+N, COMBFILTER_MAXPERIOD-N); OPUS_MOVE(prefilter_mem+c*COMBFILTER_MAXPERIOD+COMBFILTER_MAXPERIOD-N, pre[c]+COMBFILTER_MAXPERIOD, N); } } while (++c<CC); RESTORE_STACK; *gain = gain1; *pitch = pitch_index; *qgain = qg; return pf_on; } static int compute_vbr(const CELTMode *mode, AnalysisInfo *analysis, opus_int32 base_target, int LM, opus_int32 bitrate, int lastCodedBands, int C, int intensity, int constrained_vbr, opus_val16 stereo_saving, int tot_boost, opus_val16 tf_estimate, int pitch_change, opus_val16 maxDepth, int variable_duration, int lfe, int has_surround_mask, opus_val16 surround_masking, opus_val16 temporal_vbr) { /* The target rate in 8th bits per frame */ opus_int32 target; int coded_bins; int coded_bands; opus_val16 tf_calibration; int nbEBands; const opus_int16 *eBands; nbEBands = mode->nbEBands; eBands = mode->eBands; coded_bands = lastCodedBands ? lastCodedBands : nbEBands; coded_bins = eBands[coded_bands]<<LM; if (C==2) coded_bins += eBands[IMIN(intensity, coded_bands)]<<LM; target = base_target; /*printf("%f %f %f %f %d %d ", st->analysis.activity, st->analysis.tonality, tf_estimate, st->stereo_saving, tot_boost, coded_bands);*/ #ifndef DISABLE_FLOAT_API if (analysis->valid && analysis->activity<.4) target -= (opus_int32)((coded_bins<<BITRES)*(.4f-analysis->activity)); #endif /* Stereo savings */ if (C==2) { int coded_stereo_bands; int coded_stereo_dof; opus_val16 max_frac; coded_stereo_bands = IMIN(intensity, coded_bands); coded_stereo_dof = (eBands[coded_stereo_bands]<<LM)-coded_stereo_bands; /* Maximum fraction of the bits we can save if the signal is mono. */ max_frac = DIV32_16(MULT16_16(QCONST16(0.8f, 15), coded_stereo_dof), coded_bins); stereo_saving = MIN16(stereo_saving, QCONST16(1.f, 8)); /*printf("%d %d %d ", coded_stereo_dof, coded_bins, tot_boost);*/ target -= (opus_int32)MIN32(MULT16_32_Q15(max_frac,target), SHR32(MULT16_16(stereo_saving-QCONST16(0.1f,8),(coded_stereo_dof<<BITRES)),8)); } /* Boost the rate according to dynalloc (minus the dynalloc average for calibration). */ target += tot_boost-(16<<LM); /* Apply transient boost, compensating for average boost. */ tf_calibration = variable_duration==OPUS_FRAMESIZE_VARIABLE ? QCONST16(0.02f,14) : QCONST16(0.04f,14); target += (opus_int32)SHL32(MULT16_32_Q15(tf_estimate-tf_calibration, target),1); #ifndef DISABLE_FLOAT_API /* Apply tonality boost */ if (analysis->valid && !lfe) { opus_int32 tonal_target; float tonal; /* Tonality boost (compensating for the average). */ tonal = MAX16(0.f,analysis->tonality-.15f)-0.09f; tonal_target = target + (opus_int32)((coded_bins<<BITRES)*1.2f*tonal); if (pitch_change) tonal_target += (opus_int32)((coded_bins<<BITRES)*.8f); /*printf("%f %f ", analysis->tonality, tonal);*/ target = tonal_target; } #else (void)analysis; (void)pitch_change; #endif if (has_surround_mask&&!lfe) { opus_int32 surround_target = target + (opus_int32)SHR32(MULT16_16(surround_masking,coded_bins<<BITRES), DB_SHIFT); /*printf("%f %d %d %d %d %d %d ", surround_masking, coded_bins, st->end, st->intensity, surround_target, target, st->bitrate);*/ target = IMAX(target/4, surround_target); } { opus_int32 floor_depth; int bins; bins = eBands[nbEBands-2]<<LM; /*floor_depth = SHR32(MULT16_16((C*bins<<BITRES),celt_log2(SHL32(MAX16(1,sample_max),13))), DB_SHIFT);*/ floor_depth = (opus_int32)SHR32(MULT16_16((C*bins<<BITRES),maxDepth), DB_SHIFT); floor_depth = IMAX(floor_depth, target>>2); target = IMIN(target, floor_depth); /*printf("%f %d\n", maxDepth, floor_depth);*/ } if ((!has_surround_mask||lfe) && (constrained_vbr || bitrate<64000)) { opus_val16 rate_factor; #ifdef FIXED_POINT rate_factor = MAX16(0,(bitrate-32000)); #else rate_factor = MAX16(0,(1.f/32768)*(bitrate-32000)); #endif if (constrained_vbr) rate_factor = MIN16(rate_factor, QCONST16(0.67f, 15)); target = base_target + (opus_int32)MULT16_32_Q15(rate_factor, target-base_target); } if (!has_surround_mask && tf_estimate < QCONST16(.2f, 14)) { opus_val16 amount; opus_val16 tvbr_factor; amount = MULT16_16_Q15(QCONST16(.0000031f, 30), IMAX(0, IMIN(32000, 96000-bitrate))); tvbr_factor = SHR32(MULT16_16(temporal_vbr, amount), DB_SHIFT); target += (opus_int32)MULT16_32_Q15(tvbr_factor, target); } /* Don't allow more than doubling the rate */ target = IMIN(2*base_target, target); return target; } int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc) { int i, c, N; opus_int32 bits; ec_enc _enc; VARDECL(celt_sig, in); VARDECL(celt_sig, freq); VARDECL(celt_norm, X); VARDECL(celt_ener, bandE); VARDECL(opus_val16, bandLogE); VARDECL(opus_val16, bandLogE2); VARDECL(int, fine_quant); VARDECL(opus_val16, error); VARDECL(int, pulses); VARDECL(int, cap); VARDECL(int, offsets); VARDECL(int, fine_priority); VARDECL(int, tf_res); VARDECL(unsigned char, collapse_masks); celt_sig *prefilter_mem; opus_val16 *oldBandE, *oldLogE, *oldLogE2; int shortBlocks=0; int isTransient=0; const int CC = st->channels; const int C = st->stream_channels; int LM, M; int tf_select; int nbFilledBytes, nbAvailableBytes; int start; int end; int effEnd; int codedBands; int tf_sum; int alloc_trim; int pitch_index=COMBFILTER_MINPERIOD; opus_val16 gain1 = 0; int dual_stereo=0; int effectiveBytes; int dynalloc_logp; opus_int32 vbr_rate; opus_int32 total_bits; opus_int32 total_boost; opus_int32 balance; opus_int32 tell; int prefilter_tapset=0; int pf_on; int anti_collapse_rsv; int anti_collapse_on=0; int silence=0; int tf_chan = 0; opus_val16 tf_estimate; int pitch_change=0; opus_int32 tot_boost; opus_val32 sample_max; opus_val16 maxDepth; const OpusCustomMode *mode; int nbEBands; int overlap; const opus_int16 *eBands; int secondMdct; int signalBandwidth; int transient_got_disabled=0; opus_val16 surround_masking=0; opus_val16 temporal_vbr=0; opus_val16 surround_trim = 0; opus_int32 equiv_rate = 510000; VARDECL(opus_val16, surround_dynalloc); ALLOC_STACK; mode = st->mode; nbEBands = mode->nbEBands; overlap = mode->overlap; eBands = mode->eBands; start = st->start; end = st->end; tf_estimate = 0; if (nbCompressedBytes<2 || pcm==NULL) { RESTORE_STACK; return OPUS_BAD_ARG; } frame_size *= st->upsample; for (LM=0;LM<=mode->maxLM;LM++) if (mode->shortMdctSize<<LM==frame_size) break; if (LM>mode->maxLM) { RESTORE_STACK; return OPUS_BAD_ARG; } M=1<<LM; N = M*mode->shortMdctSize; prefilter_mem = st->in_mem+CC*(overlap); oldBandE = (opus_val16*)(st->in_mem+CC*(overlap+COMBFILTER_MAXPERIOD)); oldLogE = oldBandE + CC*nbEBands; oldLogE2 = oldLogE + CC*nbEBands; if (enc==NULL) { tell=1; nbFilledBytes=0; } else { tell=ec_tell(enc); nbFilledBytes=(tell+4)>>3; } #ifdef CUSTOM_MODES if (st->signalling && enc==NULL) { int tmp = (mode->effEBands-end)>>1; end = st->end = IMAX(1, mode->effEBands-tmp); compressed[0] = tmp<<5; compressed[0] |= LM<<3; compressed[0] |= (C==2)<<2; /* Convert "standard mode" to Opus header */ if (mode->Fs==48000 && mode->shortMdctSize==120) { int c0 = toOpus(compressed[0]); if (c0<0) { RESTORE_STACK; return OPUS_BAD_ARG; } compressed[0] = c0; } compressed++; nbCompressedBytes--; } #else celt_assert(st->signalling==0); #endif /* Can't produce more than 1275 output bytes */ nbCompressedBytes = IMIN(nbCompressedBytes,1275); nbAvailableBytes = nbCompressedBytes - nbFilledBytes; if (st->vbr && st->bitrate!=OPUS_BITRATE_MAX) { opus_int32 den=mode->Fs>>BITRES; vbr_rate=(st->bitrate*frame_size+(den>>1))/den; #ifdef CUSTOM_MODES if (st->signalling) vbr_rate -= 8<<BITRES; #endif effectiveBytes = vbr_rate>>(3+BITRES); } else { opus_int32 tmp; vbr_rate = 0; tmp = st->bitrate*frame_size; if (tell>1) tmp += tell; if (st->bitrate!=OPUS_BITRATE_MAX) nbCompressedBytes = IMAX(2, IMIN(nbCompressedBytes, (tmp+4*mode->Fs)/(8*mode->Fs)-!!st->signalling)); effectiveBytes = nbCompressedBytes; } if (st->bitrate != OPUS_BITRATE_MAX) equiv_rate = st->bitrate - (40*C+20)*((400>>LM) - 50); if (enc==NULL) { ec_enc_init(&_enc, compressed, nbCompressedBytes); enc = &_enc; } if (vbr_rate>0) { /* Computes the max bit-rate allowed in VBR mode to avoid violating the target rate and buffering. We must do this up front so that bust-prevention logic triggers correctly if we don't have enough bits. */ if (st->constrained_vbr) { opus_int32 vbr_bound; opus_int32 max_allowed; /* We could use any multiple of vbr_rate as bound (depending on the delay). This is clamped to ensure we use at least two bytes if the encoder was entirely empty, but to allow 0 in hybrid mode. */ vbr_bound = vbr_rate; max_allowed = IMIN(IMAX(tell==1?2:0, (vbr_rate+vbr_bound-st->vbr_reservoir)>>(BITRES+3)), nbAvailableBytes); if(max_allowed < nbAvailableBytes) { nbCompressedBytes = nbFilledBytes+max_allowed; nbAvailableBytes = max_allowed; ec_enc_shrink(enc, nbCompressedBytes); } } } total_bits = nbCompressedBytes*8; effEnd = end; if (effEnd > mode->effEBands) effEnd = mode->effEBands; ALLOC(in, CC*(N+overlap), celt_sig); sample_max=MAX32(st->overlap_max, celt_maxabs16(pcm, C*(N-overlap)/st->upsample)); st->overlap_max=celt_maxabs16(pcm+C*(N-overlap)/st->upsample, C*overlap/st->upsample); sample_max=MAX32(sample_max, st->overlap_max); #ifdef FIXED_POINT silence = (sample_max==0); #else silence = (sample_max <= (opus_val16)1/(1<<st->lsb_depth)); #endif #ifdef FUZZING if ((rand()&0x3F)==0) silence = 1; #endif if (tell==1) ec_enc_bit_logp(enc, silence, 15); else silence=0; if (silence) { /*In VBR mode there is no need to send more than the minimum. */ if (vbr_rate>0) { effectiveBytes=nbCompressedBytes=IMIN(nbCompressedBytes, nbFilledBytes+2); total_bits=nbCompressedBytes*8; nbAvailableBytes=2; ec_enc_shrink(enc, nbCompressedBytes); } /* Pretend we've filled all the remaining bits with zeros (that's what the initialiser did anyway) */ tell = nbCompressedBytes*8; enc->nbits_total+=tell-ec_tell(enc); } c=0; do { int need_clip=0; #ifndef FIXED_POINT need_clip = st->clip && sample_max>65536.f; #endif celt_preemphasis(pcm+c, in+c*(N+overlap)+overlap, N, CC, st->upsample, mode->preemph, st->preemph_memE+c, need_clip); } while (++c<CC); /* Find pitch period and gain */ { int enabled; int qg; enabled = ((st->lfe&&nbAvailableBytes>3) || nbAvailableBytes>12*C) && start==0 && !silence && !st->disable_pf && st->complexity >= 5 && !(st->consec_transient && LM!=3 && st->variable_duration==OPUS_FRAMESIZE_VARIABLE); prefilter_tapset = st->tapset_decision; pf_on = run_prefilter(st, in, prefilter_mem, CC, N, prefilter_tapset, &pitch_index, &gain1, &qg, enabled, nbAvailableBytes); if ((gain1 > QCONST16(.4f,15) || st->prefilter_gain > QCONST16(.4f,15)) && (!st->analysis.valid || st->analysis.tonality > .3) && (pitch_index > 1.26*st->prefilter_period || pitch_index < .79*st->prefilter_period)) pitch_change = 1; if (pf_on==0) { if(start==0 && tell+16<=total_bits) ec_enc_bit_logp(enc, 0, 1); } else { /*This block is not gated by a total bits check only because of the nbAvailableBytes check above.*/ int octave; ec_enc_bit_logp(enc, 1, 1); pitch_index += 1; octave = EC_ILOG(pitch_index)-5; ec_enc_uint(enc, octave, 6); ec_enc_bits(enc, pitch_index-(16<<octave), 4+octave); pitch_index -= 1; ec_enc_bits(enc, qg, 3); ec_enc_icdf(enc, prefilter_tapset, tapset_icdf, 2); } } isTransient = 0; shortBlocks = 0; if (st->complexity >= 1 && !st->lfe) { isTransient = transient_analysis(in, N+overlap, CC, &tf_estimate, &tf_chan); } if (LM>0 && ec_tell(enc)+3<=total_bits) { if (isTransient) shortBlocks = M; } else { isTransient = 0; transient_got_disabled=1; } ALLOC(freq, CC*N, celt_sig); /**< Interleaved signal MDCTs */ ALLOC(bandE,nbEBands*CC, celt_ener); ALLOC(bandLogE,nbEBands*CC, opus_val16); secondMdct = shortBlocks && st->complexity>=8; ALLOC(bandLogE2, C*nbEBands, opus_val16); if (secondMdct) { compute_mdcts(mode, 0, in, freq, C, CC, LM, st->upsample, st->arch); compute_band_energies(mode, freq, bandE, effEnd, C, LM); amp2Log2(mode, effEnd, end, bandE, bandLogE2, C); for (i=0;i<C*nbEBands;i++) bandLogE2[i] += HALF16(SHL16(LM, DB_SHIFT)); } compute_mdcts(mode, shortBlocks, in, freq, C, CC, LM, st->upsample, st->arch); if (CC==2&&C==1) tf_chan = 0; compute_band_energies(mode, freq, bandE, effEnd, C, LM); if (st->lfe) { for (i=2;i<end;i++) { bandE[i] = IMIN(bandE[i], MULT16_32_Q15(QCONST16(1e-4f,15),bandE[0])); bandE[i] = MAX32(bandE[i], EPSILON); } } amp2Log2(mode, effEnd, end, bandE, bandLogE, C); ALLOC(surround_dynalloc, C*nbEBands, opus_val16); OPUS_CLEAR(surround_dynalloc, end); /* This computes how much masking takes place between surround channels */ if (start==0&&st->energy_mask&&!st->lfe) { int mask_end; int midband; int count_dynalloc; opus_val32 mask_avg=0; opus_val32 diff=0; int count=0; mask_end = IMAX(2,st->lastCodedBands); for (c=0;c<C;c++) { for(i=0;i<mask_end;i++) { opus_val16 mask; mask = MAX16(MIN16(st->energy_mask[nbEBands*c+i], QCONST16(.25f, DB_SHIFT)), -QCONST16(2.0f, DB_SHIFT)); if (mask > 0) mask = HALF16(mask); mask_avg += MULT16_16(mask, eBands[i+1]-eBands[i]); count += eBands[i+1]-eBands[i]; diff += MULT16_16(mask, 1+2*i-mask_end); } } celt_assert(count>0); mask_avg = DIV32_16(mask_avg,count); mask_avg += QCONST16(.2f, DB_SHIFT); diff = diff*6/(C*(mask_end-1)*(mask_end+1)*mask_end); /* Again, being conservative */ diff = HALF32(diff); diff = MAX32(MIN32(diff, QCONST32(.031f, DB_SHIFT)), -QCONST32(.031f, DB_SHIFT)); /* Find the band that's in the middle of the coded spectrum */ for (midband=0;eBands[midband+1] < eBands[mask_end]/2;midband++); count_dynalloc=0; for(i=0;i<mask_end;i++) { opus_val32 lin; opus_val16 unmask; lin = mask_avg + diff*(i-midband); if (C==2) unmask = MAX16(st->energy_mask[i], st->energy_mask[nbEBands+i]); else unmask = st->energy_mask[i]; unmask = MIN16(unmask, QCONST16(.0f, DB_SHIFT)); unmask -= lin; if (unmask > QCONST16(.25f, DB_SHIFT)) { surround_dynalloc[i] = unmask - QCONST16(.25f, DB_SHIFT); count_dynalloc++; } } if (count_dynalloc>=3) { /* If we need dynalloc in many bands, it's probably because our initial masking rate was too low. */ mask_avg += QCONST16(.25f, DB_SHIFT); if (mask_avg>0) { /* Something went really wrong in the original calculations, disabling masking. */ mask_avg = 0; diff = 0; OPUS_CLEAR(surround_dynalloc, mask_end); } else { for(i=0;i<mask_end;i++) surround_dynalloc[i] = MAX16(0, surround_dynalloc[i]-QCONST16(.25f, DB_SHIFT)); } } mask_avg += QCONST16(.2f, DB_SHIFT); /* Convert to 1/64th units used for the trim */ surround_trim = 64*diff; /*printf("%d %d ", mask_avg, surround_trim);*/ surround_masking = mask_avg; } /* Temporal VBR (but not for LFE) */ if (!st->lfe) { opus_val16 follow=-QCONST16(10.0f,DB_SHIFT); opus_val32 frame_avg=0; opus_val16 offset = shortBlocks?HALF16(SHL16(LM, DB_SHIFT)):0; for(i=start;i<end;i++) { follow = MAX16(follow-QCONST16(1.f, DB_SHIFT), bandLogE[i]-offset); if (C==2) follow = MAX16(follow, bandLogE[i+nbEBands]-offset); frame_avg += follow; } frame_avg /= (end-start); temporal_vbr = SUB16(frame_avg,st->spec_avg); temporal_vbr = MIN16(QCONST16(3.f, DB_SHIFT), MAX16(-QCONST16(1.5f, DB_SHIFT), temporal_vbr)); st->spec_avg += MULT16_16_Q15(QCONST16(.02f, 15), temporal_vbr); } /*for (i=0;i<21;i++) printf("%f ", bandLogE[i]); printf("\n");*/ if (!secondMdct) { OPUS_COPY(bandLogE2, bandLogE, C*nbEBands); } /* Last chance to catch any transient we might have missed in the time-domain analysis */ if (LM>0 && ec_tell(enc)+3<=total_bits && !isTransient && st->complexity>=5 && !st->lfe) { if (patch_transient_decision(bandLogE, oldBandE, nbEBands, start, end, C)) { isTransient = 1; shortBlocks = M; compute_mdcts(mode, shortBlocks, in, freq, C, CC, LM, st->upsample, st->arch); compute_band_energies(mode, freq, bandE, effEnd, C, LM); amp2Log2(mode, effEnd, end, bandE, bandLogE, C); /* Compensate for the scaling of short vs long mdcts */ for (i=0;i<C*nbEBands;i++) bandLogE2[i] += HALF16(SHL16(LM, DB_SHIFT)); tf_estimate = QCONST16(.2f,14); } } if (LM>0 && ec_tell(enc)+3<=total_bits) ec_enc_bit_logp(enc, isTransient, 3); ALLOC(X, C*N, celt_norm); /**< Interleaved normalised MDCTs */ /* Band normalisation */ normalise_bands(mode, freq, X, bandE, effEnd, C, M); ALLOC(tf_res, nbEBands, int); /* Disable variable tf resolution for hybrid and at very low bitrate */ if (effectiveBytes>=15*C && start==0 && st->complexity>=2 && !st->lfe) { int lambda; if (effectiveBytes<40) lambda = 12; else if (effectiveBytes<60) lambda = 6; else if (effectiveBytes<100) lambda = 4; else lambda = 3; lambda*=2; tf_select = tf_analysis(mode, effEnd, isTransient, tf_res, lambda, X, N, LM, &tf_sum, tf_estimate, tf_chan); for (i=effEnd;i<end;i++) tf_res[i] = tf_res[effEnd-1]; } else { tf_sum = 0; for (i=0;i<end;i++) tf_res[i] = isTransient; tf_select=0; } ALLOC(error, C*nbEBands, opus_val16); quant_coarse_energy(mode, start, end, effEnd, bandLogE, oldBandE, total_bits, error, enc, C, LM, nbAvailableBytes, st->force_intra, &st->delayedIntra, st->complexity >= 4, st->loss_rate, st->lfe); tf_encode(start, end, isTransient, tf_res, LM, tf_select, enc); if (ec_tell(enc)+4<=total_bits) { if (st->lfe) { st->tapset_decision = 0; st->spread_decision = SPREAD_NORMAL; } else if (shortBlocks || st->complexity < 3 || nbAvailableBytes < 10*C || start != 0) { if (st->complexity == 0) st->spread_decision = SPREAD_NONE; else st->spread_decision = SPREAD_NORMAL; } else { /* Disable new spreading+tapset estimator until we can show it works better than the old one. So far it seems like spreading_decision() works best. */ #if 0 if (st->analysis.valid) { static const opus_val16 spread_thresholds[3] = {-QCONST16(.6f, 15), -QCONST16(.2f, 15), -QCONST16(.07f, 15)}; static const opus_val16 spread_histeresis[3] = {QCONST16(.15f, 15), QCONST16(.07f, 15), QCONST16(.02f, 15)}; static const opus_val16 tapset_thresholds[2] = {QCONST16(.0f, 15), QCONST16(.15f, 15)}; static const opus_val16 tapset_histeresis[2] = {QCONST16(.1f, 15), QCONST16(.05f, 15)}; st->spread_decision = hysteresis_decision(-st->analysis.tonality, spread_thresholds, spread_histeresis, 3, st->spread_decision); st->tapset_decision = hysteresis_decision(st->analysis.tonality_slope, tapset_thresholds, tapset_histeresis, 2, st->tapset_decision); } else #endif { st->spread_decision = spreading_decision(mode, X, &st->tonal_average, st->spread_decision, &st->hf_average, &st->tapset_decision, pf_on&&!shortBlocks, effEnd, C, M); } /*printf("%d %d\n", st->tapset_decision, st->spread_decision);*/ /*printf("%f %d %f %d\n\n", st->analysis.tonality, st->spread_decision, st->analysis.tonality_slope, st->tapset_decision);*/ } ec_enc_icdf(enc, st->spread_decision, spread_icdf, 5); } ALLOC(offsets, nbEBands, int); maxDepth = dynalloc_analysis(bandLogE, bandLogE2, nbEBands, start, end, C, offsets, st->lsb_depth, mode->logN, isTransient, st->vbr, st->constrained_vbr, eBands, LM, effectiveBytes, &tot_boost, st->lfe, surround_dynalloc); /* For LFE, everything interesting is in the first band */ if (st->lfe) offsets[0] = IMIN(8, effectiveBytes/3); ALLOC(cap, nbEBands, int); init_caps(mode,cap,LM,C); dynalloc_logp = 6; total_bits<<=BITRES; total_boost = 0; tell = ec_tell_frac(enc); for (i=start;i<end;i++) { int width, quanta; int dynalloc_loop_logp; int boost; int j; width = C*(eBands[i+1]-eBands[i])<<LM; /* quanta is 6 bits, but no more than 1 bit/sample and no less than 1/8 bit/sample */ quanta = IMIN(width<<BITRES, IMAX(6<<BITRES, width)); dynalloc_loop_logp = dynalloc_logp; boost = 0; for (j = 0; tell+(dynalloc_loop_logp<<BITRES) < total_bits-total_boost && boost < cap[i]; j++) { int flag; flag = j<offsets[i]; ec_enc_bit_logp(enc, flag, dynalloc_loop_logp); tell = ec_tell_frac(enc); if (!flag) break; boost += quanta; total_boost += quanta; dynalloc_loop_logp = 1; } /* Making dynalloc more likely */ if (j) dynalloc_logp = IMAX(2, dynalloc_logp-1); offsets[i] = boost; } if (C==2) { static const opus_val16 intensity_thresholds[21]= /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 off*/ { 1, 2, 3, 4, 5, 6, 7, 8,16,24,36,44,50,56,62,67,72,79,88,106,134}; static const opus_val16 intensity_histeresis[21]= { 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 5, 6, 8, 8}; /* Always use MS for 2.5 ms frames until we can do a better analysis */ if (LM!=0) dual_stereo = stereo_analysis(mode, X, LM, N); st->intensity = hysteresis_decision((opus_val16)(equiv_rate/1000), intensity_thresholds, intensity_histeresis, 21, st->intensity); st->intensity = IMIN(end,IMAX(start, st->intensity)); } alloc_trim = 5; if (tell+(6<<BITRES) <= total_bits - total_boost) { if (st->lfe) alloc_trim = 5; else alloc_trim = alloc_trim_analysis(mode, X, bandLogE, end, LM, C, N, &st->analysis, &st->stereo_saving, tf_estimate, st->intensity, surround_trim, st->arch); ec_enc_icdf(enc, alloc_trim, trim_icdf, 7); tell = ec_tell_frac(enc); } /* Variable bitrate */ if (vbr_rate>0) { opus_val16 alpha; opus_int32 delta; /* The target rate in 8th bits per frame */ opus_int32 target, base_target; opus_int32 min_allowed; int lm_diff = mode->maxLM - LM; /* Don't attempt to use more than 510 kb/s, even for frames smaller than 20 ms. The CELT allocator will just not be able to use more than that anyway. */ nbCompressedBytes = IMIN(nbCompressedBytes,1275>>(3-LM)); base_target = vbr_rate - ((40*C+20)<<BITRES); if (st->constrained_vbr) base_target += (st->vbr_offset>>lm_diff); target = compute_vbr(mode, &st->analysis, base_target, LM, equiv_rate, st->lastCodedBands, C, st->intensity, st->constrained_vbr, st->stereo_saving, tot_boost, tf_estimate, pitch_change, maxDepth, st->variable_duration, st->lfe, st->energy_mask!=NULL, surround_masking, temporal_vbr); /* The current offset is removed from the target and the space used so far is added*/ target=target+tell; /* In VBR mode the frame size must not be reduced so much that it would result in the encoder running out of bits. The margin of 2 bytes ensures that none of the bust-prevention logic in the decoder will have triggered so far. */ min_allowed = ((tell+total_boost+(1<<(BITRES+3))-1)>>(BITRES+3)) + 2 - nbFilledBytes; nbAvailableBytes = (target+(1<<(BITRES+2)))>>(BITRES+3); nbAvailableBytes = IMAX(min_allowed,nbAvailableBytes); nbAvailableBytes = IMIN(nbCompressedBytes,nbAvailableBytes+nbFilledBytes) - nbFilledBytes; /* By how much did we "miss" the target on that frame */ delta = target - vbr_rate; target=nbAvailableBytes<<(BITRES+3); /*If the frame is silent we don't adjust our drift, otherwise the encoder will shoot to very high rates after hitting a span of silence, but we do allow the bitres to refill. This means that we'll undershoot our target in CVBR/VBR modes on files with lots of silence. */ if(silence) { nbAvailableBytes = 2; target = 2*8<<BITRES; delta = 0; } if (st->vbr_count < 970) { st->vbr_count++; alpha = celt_rcp(SHL32(EXTEND32(st->vbr_count+20),16)); } else alpha = QCONST16(.001f,15); /* How many bits have we used in excess of what we're allowed */ if (st->constrained_vbr) st->vbr_reservoir += target - vbr_rate; /*printf ("%d\n", st->vbr_reservoir);*/ /* Compute the offset we need to apply in order to reach the target */ if (st->constrained_vbr) { st->vbr_drift += (opus_int32)MULT16_32_Q15(alpha,(delta*(1<<lm_diff))-st->vbr_offset-st->vbr_drift); st->vbr_offset = -st->vbr_drift; } /*printf ("%d\n", st->vbr_drift);*/ if (st->constrained_vbr && st->vbr_reservoir < 0) { /* We're under the min value -- increase rate */ int adjust = (-st->vbr_reservoir)/(8<<BITRES); /* Unless we're just coding silence */ nbAvailableBytes += silence?0:adjust; st->vbr_reservoir = 0; /*printf ("+%d\n", adjust);*/ } nbCompressedBytes = IMIN(nbCompressedBytes,nbAvailableBytes+nbFilledBytes); /*printf("%d\n", nbCompressedBytes*50*8);*/ /* This moves the raw bits to take into account the new compressed size */ ec_enc_shrink(enc, nbCompressedBytes); } /* Bit allocation */ ALLOC(fine_quant, nbEBands, int); ALLOC(pulses, nbEBands, int); ALLOC(fine_priority, nbEBands, int); /* bits = packet size - where we are - safety*/ bits = (((opus_int32)nbCompressedBytes*8)<<BITRES) - ec_tell_frac(enc) - 1; anti_collapse_rsv = isTransient&&LM>=2&&bits>=((LM+2)<<BITRES) ? (1<<BITRES) : 0; bits -= anti_collapse_rsv; signalBandwidth = end-1; #ifndef DISABLE_FLOAT_API if (st->analysis.valid) { int min_bandwidth; if (equiv_rate < (opus_int32)32000*C) min_bandwidth = 13; else if (equiv_rate < (opus_int32)48000*C) min_bandwidth = 16; else if (equiv_rate < (opus_int32)60000*C) min_bandwidth = 18; else if (equiv_rate < (opus_int32)80000*C) min_bandwidth = 19; else min_bandwidth = 20; signalBandwidth = IMAX(st->analysis.bandwidth, min_bandwidth); } #endif if (st->lfe) signalBandwidth = 1; codedBands = compute_allocation(mode, start, end, offsets, cap, alloc_trim, &st->intensity, &dual_stereo, bits, &balance, pulses, fine_quant, fine_priority, C, LM, enc, 1, st->lastCodedBands, signalBandwidth); if (st->lastCodedBands) st->lastCodedBands = IMIN(st->lastCodedBands+1,IMAX(st->lastCodedBands-1,codedBands)); else st->lastCodedBands = codedBands; quant_fine_energy(mode, start, end, oldBandE, error, fine_quant, enc, C); /* Residual quantisation */ ALLOC(collapse_masks, C*nbEBands, unsigned char); quant_all_bands(1, mode, start, end, X, C==2 ? X+N : NULL, collapse_masks, bandE, pulses, shortBlocks, st->spread_decision, dual_stereo, st->intensity, tf_res, nbCompressedBytes*(8<<BITRES)-anti_collapse_rsv, balance, enc, LM, codedBands, &st->rng, st->arch); if (anti_collapse_rsv > 0) { anti_collapse_on = st->consec_transient<2; #ifdef FUZZING anti_collapse_on = rand()&0x1; #endif ec_enc_bits(enc, anti_collapse_on, 1); } quant_energy_finalise(mode, start, end, oldBandE, error, fine_quant, fine_priority, nbCompressedBytes*8-ec_tell(enc), enc, C); if (silence) { for (i=0;i<C*nbEBands;i++) oldBandE[i] = -QCONST16(28.f,DB_SHIFT); } #ifdef RESYNTH /* Re-synthesis of the coded audio if required */ { celt_sig *out_mem[2]; if (anti_collapse_on) { anti_collapse(mode, X, collapse_masks, LM, C, N, start, end, oldBandE, oldLogE, oldLogE2, pulses, st->rng); } c=0; do { OPUS_MOVE(st->syn_mem[c], st->syn_mem[c]+N, 2*MAX_PERIOD-N+overlap/2); } while (++c<CC); c=0; do { out_mem[c] = st->syn_mem[c]+2*MAX_PERIOD-N; } while (++c<CC); celt_synthesis(mode, X, out_mem, oldBandE, start, effEnd, C, CC, isTransient, LM, st->upsample, silence, st->arch); c=0; do { st->prefilter_period=IMAX(st->prefilter_period, COMBFILTER_MINPERIOD); st->prefilter_period_old=IMAX(st->prefilter_period_old, COMBFILTER_MINPERIOD); comb_filter(out_mem[c], out_mem[c], st->prefilter_period_old, st->prefilter_period, mode->shortMdctSize, st->prefilter_gain_old, st->prefilter_gain, st->prefilter_tapset_old, st->prefilter_tapset, mode->window, overlap); if (LM!=0) comb_filter(out_mem[c]+mode->shortMdctSize, out_mem[c]+mode->shortMdctSize, st->prefilter_period, pitch_index, N-mode->shortMdctSize, st->prefilter_gain, gain1, st->prefilter_tapset, prefilter_tapset, mode->window, overlap); } while (++c<CC); /* We reuse freq[] as scratch space for the de-emphasis */ deemphasis(out_mem, (opus_val16*)pcm, N, CC, st->upsample, mode->preemph, st->preemph_memD); st->prefilter_period_old = st->prefilter_period; st->prefilter_gain_old = st->prefilter_gain; st->prefilter_tapset_old = st->prefilter_tapset; } #endif st->prefilter_period = pitch_index; st->prefilter_gain = gain1; st->prefilter_tapset = prefilter_tapset; #ifdef RESYNTH if (LM!=0) { st->prefilter_period_old = st->prefilter_period; st->prefilter_gain_old = st->prefilter_gain; st->prefilter_tapset_old = st->prefilter_tapset; } #endif if (CC==2&&C==1) { OPUS_COPY(&oldBandE[nbEBands], oldBandE, nbEBands); } if (!isTransient) { OPUS_COPY(oldLogE2, oldLogE, CC*nbEBands); OPUS_COPY(oldLogE, oldBandE, CC*nbEBands); } else { for (i=0;i<CC*nbEBands;i++) oldLogE[i] = MIN16(oldLogE[i], oldBandE[i]); } /* In case start or end were to change */ c=0; do { for (i=0;i<start;i++) { oldBandE[c*nbEBands+i]=0; oldLogE[c*nbEBands+i]=oldLogE2[c*nbEBands+i]=-QCONST16(28.f,DB_SHIFT); } for (i=end;i<nbEBands;i++) { oldBandE[c*nbEBands+i]=0; oldLogE[c*nbEBands+i]=oldLogE2[c*nbEBands+i]=-QCONST16(28.f,DB_SHIFT); } } while (++c<CC); if (isTransient || transient_got_disabled) st->consec_transient++; else st->consec_transient=0; st->rng = enc->rng; /* If there's any room left (can only happen for very high rates), it's already filled with zeros */ ec_enc_done(enc); #ifdef CUSTOM_MODES if (st->signalling) nbCompressedBytes++; #endif RESTORE_STACK; if (ec_get_error(enc)) return OPUS_INTERNAL_ERROR; else return nbCompressedBytes; } #ifdef CUSTOM_MODES #ifdef FIXED_POINT int opus_custom_encode(CELTEncoder * OPUS_RESTRICT st, const opus_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes) { return celt_encode_with_ec(st, pcm, frame_size, compressed, nbCompressedBytes, NULL); } #ifndef DISABLE_FLOAT_API int opus_custom_encode_float(CELTEncoder * OPUS_RESTRICT st, const float * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes) { int j, ret, C, N; VARDECL(opus_int16, in); ALLOC_STACK; if (pcm==NULL) return OPUS_BAD_ARG; C = st->channels; N = frame_size; ALLOC(in, C*N, opus_int16); for (j=0;j<C*N;j++) in[j] = FLOAT2INT16(pcm[j]); ret=celt_encode_with_ec(st,in,frame_size,compressed,nbCompressedBytes, NULL); #ifdef RESYNTH for (j=0;j<C*N;j++) ((float*)pcm)[j]=in[j]*(1.f/32768.f); #endif RESTORE_STACK; return ret; } #endif /* DISABLE_FLOAT_API */ #else int opus_custom_encode(CELTEncoder * OPUS_RESTRICT st, const opus_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes) { int j, ret, C, N; VARDECL(celt_sig, in); ALLOC_STACK; if (pcm==NULL) return OPUS_BAD_ARG; C=st->channels; N=frame_size; ALLOC(in, C*N, celt_sig); for (j=0;j<C*N;j++) { in[j] = SCALEOUT(pcm[j]); } ret = celt_encode_with_ec(st,in,frame_size,compressed,nbCompressedBytes, NULL); #ifdef RESYNTH for (j=0;j<C*N;j++) ((opus_int16*)pcm)[j] = FLOAT2INT16(in[j]); #endif RESTORE_STACK; return ret; } int opus_custom_encode_float(CELTEncoder * OPUS_RESTRICT st, const float * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes) { return celt_encode_with_ec(st, pcm, frame_size, compressed, nbCompressedBytes, NULL); } #endif #endif /* CUSTOM_MODES */ int opus_custom_encoder_ctl(CELTEncoder * OPUS_RESTRICT st, int request, ...) { va_list ap; va_start(ap, request); switch (request) { case OPUS_SET_COMPLEXITY_REQUEST: { int value = va_arg(ap, opus_int32); if (value<0 || value>10) goto bad_arg; st->complexity = value; } break; case CELT_SET_START_BAND_REQUEST: { opus_int32 value = va_arg(ap, opus_int32); if (value<0 || value>=st->mode->nbEBands) goto bad_arg; st->start = value; } break; case CELT_SET_END_BAND_REQUEST: { opus_int32 value = va_arg(ap, opus_int32); if (value<1 || value>st->mode->nbEBands) goto bad_arg; st->end = value; } break; case CELT_SET_PREDICTION_REQUEST: { int value = va_arg(ap, opus_int32); if (value<0 || value>2) goto bad_arg; st->disable_pf = value<=1; st->force_intra = value==0; } break; case OPUS_SET_PACKET_LOSS_PERC_REQUEST: { int value = va_arg(ap, opus_int32); if (value<0 || value>100) goto bad_arg; st->loss_rate = value; } break; case OPUS_SET_VBR_CONSTRAINT_REQUEST: { opus_int32 value = va_arg(ap, opus_int32); st->constrained_vbr = value; } break; case OPUS_SET_VBR_REQUEST: { opus_int32 value = va_arg(ap, opus_int32); st->vbr = value; } break; case OPUS_SET_BITRATE_REQUEST: { opus_int32 value = va_arg(ap, opus_int32); if (value<=500 && value!=OPUS_BITRATE_MAX) goto bad_arg; value = IMIN(value, 260000*st->channels); st->bitrate = value; } break; case CELT_SET_CHANNELS_REQUEST: { opus_int32 value = va_arg(ap, opus_int32); if (value<1 || value>2) goto bad_arg; st->stream_channels = value; } break; case OPUS_SET_LSB_DEPTH_REQUEST: { opus_int32 value = va_arg(ap, opus_int32); if (value<8 || value>24) goto bad_arg; st->lsb_depth=value; } break; case OPUS_GET_LSB_DEPTH_REQUEST: { opus_int32 *value = va_arg(ap, opus_int32*); *value=st->lsb_depth; } break; case OPUS_SET_EXPERT_FRAME_DURATION_REQUEST: { opus_int32 value = va_arg(ap, opus_int32); st->variable_duration = value; } break; case OPUS_RESET_STATE: { int i; opus_val16 *oldBandE, *oldLogE, *oldLogE2; oldBandE = (opus_val16*)(st->in_mem+st->channels*(st->mode->overlap+COMBFILTER_MAXPERIOD)); oldLogE = oldBandE + st->channels*st->mode->nbEBands; oldLogE2 = oldLogE + st->channels*st->mode->nbEBands; OPUS_CLEAR((char*)&st->ENCODER_RESET_START, opus_custom_encoder_get_size(st->mode, st->channels)- ((char*)&st->ENCODER_RESET_START - (char*)st)); for (i=0;i<st->channels*st->mode->nbEBands;i++) oldLogE[i]=oldLogE2[i]=-QCONST16(28.f,DB_SHIFT); st->vbr_offset = 0; st->delayedIntra = 1; st->spread_decision = SPREAD_NORMAL; st->tonal_average = 256; st->hf_average = 0; st->tapset_decision = 0; } break; #ifdef CUSTOM_MODES case CELT_SET_INPUT_CLIPPING_REQUEST: { opus_int32 value = va_arg(ap, opus_int32); st->clip = value; } break; #endif case CELT_SET_SIGNALLING_REQUEST: { opus_int32 value = va_arg(ap, opus_int32); st->signalling = value; } break; case CELT_SET_ANALYSIS_REQUEST: { AnalysisInfo *info = va_arg(ap, AnalysisInfo *); if (info) OPUS_COPY(&st->analysis, info, 1); } break; case CELT_GET_MODE_REQUEST: { const CELTMode ** value = va_arg(ap, const CELTMode**); if (value==0) goto bad_arg; *value=st->mode; } break; case OPUS_GET_FINAL_RANGE_REQUEST: { opus_uint32 * value = va_arg(ap, opus_uint32 *); if (value==0) goto bad_arg; *value=st->rng; } break; case OPUS_SET_LFE_REQUEST: { opus_int32 value = va_arg(ap, opus_int32); st->lfe = value; } break; case OPUS_SET_ENERGY_MASK_REQUEST: { opus_val16 *value = va_arg(ap, opus_val16*); st->energy_mask = value; } break; default: goto bad_request; } va_end(ap); return OPUS_OK; bad_arg: va_end(ap); return OPUS_BAD_ARG; bad_request: va_end(ap); return OPUS_UNIMPLEMENTED; } } // namespace youmecommon
a0e64a0639db86dd10c5d16841342fe42efe56bf
a34ac1d315fb5916752d0c3e3bdde0fbf876c08d
/testpack/wen/2017.11.9/src/杨宇飞/prime.cpp
8ba74f020071a192c10188f5181eb23cde01ca7c
[]
no_license
RiverHamster/OI-Works
ae9f7543bb75501552042dc3d4346ff83dfd47df
7828a21183c49dde173e355a8d20ca7cebb4cd56
refs/heads/master
2021-05-14T11:46:57.198588
2018-01-06T09:29:35
2018-01-06T09:29:35
116,372,561
0
0
null
null
null
null
UTF-8
C++
false
false
734
cpp
prime.cpp
#include <iostream> #include <cstdio> #include <cmath> using namespace std; int ans=0; int a[10000]; bool zs(int i) { for(int j=2;j<i;j++) if(i%j==0) return false; return true; } int biao() { int ans=0; for(int i=2;i<10000;i++) { if(zs(i)) { a[ans]=i; ans++; } } } int main() { biao(); freopen("prime.in","r",stdin); freopen("prime.out","w",stdout); int n; scanf("%d",&n); int x[n],c; for(int i=0;i<n;i++) { scanf("%d",&c); int b=c; for(int j=0;a[j]<b;j++) { for(int l=j;a[l]<b;l++) { if(c==0) { ans++; break; } c-=a[l]; } c=b; } if(zs(c)) ans++; printf("%d\n",ans); ans=0; } //for(int i=0;i<100;i++) // printf("%d\n",a[i]); return 0; }
8f9b7cffe208b449fd85311f405dcf26c6ab3240
aa6d60423cbbec0c567c97748e130f11559ebbf0
/player/src/main/jni/compose/mycv.cpp
a7aca50f7e969d97627e80439a417f3d2035daa4
[]
no_license
weller0/PlayerDemo
d7ea97b4617cd1f05447d8ed6a0c46a19c2e85f6
441f16a0b4960156e372c234551180be6ac70e9f
refs/heads/master
2021-06-18T06:08:40.514813
2017-06-20T02:24:43
2017-06-20T02:24:43
87,904,124
2
0
null
null
null
null
UTF-8
C++
false
false
22,186
cpp
mycv.cpp
/* * mycv.cpp * * Created on: 2017-2-15 * Author: lyz1900 */ #include"mycv.h" #define IWSHOW_DEBUG 0 /* 外切法找圆心半径************************************************************************************************/ void Circumscribe(Mat src, //输入 原图 int T, //输入 亮度差 阈值 Point2f *centerf, //输出 中心 float *radiusf, //输出 半径 int num) //输入 序号 { Mat midImage; //灰度,或者其他中间处理图 Point center; //霍夫变换圆形参数 圆心 cvtColor(src, midImage, COLOR_BGR2GRAY); //转成灰度图 //vector<int> row_max_D; // 扫描行列最大亮度差 int rowNumber = midImage.rows; int colNumber = midImage.cols * midImage.channels(); int up = 0, down = 0, left = 0, right = 0; //扫描行极亮度差 up = 0; //初始值 for (int i = 0; i < rowNumber; i++) //行扫描,从上向下搜索 { uchar *data = midImage.ptr<uchar>(i); //获取第 i 行首地址 uchar max = 0, min = 0; for (int j = 0; j < colNumber; j++) //扫描第 i 行,找到最大值和最小值 { uchar Y = data[j]; if (Y > max) { max = Y; } if (Y < min) { min = Y; } } int YD = max - min; //row_max_D.push_back(YD); if (up != 0 && YD > T) { if ((i - up) != 1) //出现极亮度>T 的情况不连续,为躁点 { up = i; //更新 up 为新值 } else { break; //出现极亮度>T 的情况连续,为鱼眼边界 } } if (YD > T) { up = i; } } //扫描行极亮度差 down = rowNumber - 1; for (int i = rowNumber - 1; i > -1; i--) //行扫描,从下向上搜索 { uchar *data = midImage.ptr<uchar>(i); //获取第 i 行首地址 uchar max = 0, min = 0; for (int j = 0; j < colNumber; j++) //扫描第 i 行,找到最大值和最小值 { uchar Y = data[j]; if (Y > max) { max = Y; } if (Y < min) { min = Y; } } int YD = max - min; //row_max_D.push_back(YD); if (down != (rowNumber - 1) && YD > T) { if ((down - i) != 1) //出现极亮度>T 的情况不连续,为躁点 { down = i; //更新 up 为新值 } else { break; //出现极亮度>T 的情况连续,为鱼眼边界 } } if (YD > T) { down = i; } } //扫描列极亮度差 for (int j = 0; j < colNumber; j++) //列循环,从左到右搜索 { uchar max = 0, min = 0; for (int i = 0; i < rowNumber; i++) //列扫描 { uchar *data = midImage.ptr<uchar>(i); //获取第 i 行首地址 uchar Y = data[j]; //获取第 j 列 i 行 if (Y > max) { max = Y; } if (Y < min) { min = Y; } } int YD = max - min; //row_max_D.push_back(YD); if (left != 0 && YD > T) { if ((j - left) != 1) //出现极亮度>T 的情况不连续,为躁点 { left = j; //更新 up 为新值 } else { break; //出现极亮度>T 的情况连续,为鱼眼边界 } } if (YD > T) { left = j; } } //扫描列极亮度差 for (int j = colNumber - 1; j > 0; j--) //列循环,从左到右搜索 { uchar max = 0, min = 0; for (int i = 0; i < rowNumber; i++) //列扫描 { uchar *data = midImage.ptr<uchar>(i); //获取第 i 行首地址 uchar Y = data[j]; //获取第 j 列 i 行 if (Y > max) { max = Y; } if (Y < min) { min = Y; } } int YD = max - min; //row_max_D.push_back(YD); if (right != 0 && YD > T) { if ((right - j) != 1) //出现极亮度>T 的情况不连续,为躁点 { right = j; //更新 up 为新值 } else { break; //出现极亮度>T 的情况连续,为鱼眼边界 } } if (YD > T) { right = j; } } //找到外切四边形 *centerf = Point2f(((float) left + ((float) right - (float) left) / 2.0), ((float) up + ((float) down - (float) up) / 2.0)); *radiusf = (((float) down - (float) up) + ((float) right - (float) left)) / 4.0; #if IWSHOW_DEBUG int src_width = src.cols; int src_hight = src.rows; Mat src_clone = src.clone(); char imanme[50]; if (src_hight > 1080) { Mat src_resize; line(src_clone, Point(0, up), Point(src_width, up), Scalar(0, 255, 0), 3, 8); line(src_clone, Point(0, down), Point(src_width, down), Scalar(0, 255, 0), 3, 8); line(src_clone, Point(left, 0), Point(left, src_hight), Scalar(0, 255, 0), 3, 8); line(src_clone, Point(right, 0), Point(right, src_hight), Scalar(0, 255, 0), 3, 8); circle(src_clone, Point((left + (right - left) / 2), (up + (down - up) / 2)), 3, Scalar(0, 255, 0), 3, 8, 0);//绘制圆心 circle(src_clone, Point((left + (right - left) / 2), (up + (down - up) / 2)), ((down - up) + (right - left)) / 4, Scalar(155, 50, 255), 3, 8, 0);//绘制圆边 resize(src_clone, src_resize, Size(src.cols / 4, src.rows / 4), 0, 0, INTER_LINEAR); sprintf(imanme, "Circumscribe Src Resize %d", num); imshow(imanme, src_resize); } else { line(src_clone, Point(0, up), Point(src_width, up), Scalar(0, 255, 0), 1, 8); line(src_clone, Point(0, down), Point(src_width, down), Scalar(0, 255, 0), 1, 8); line(src_clone, Point(left, 0), Point(left, src_hight), Scalar(0, 255, 0), 1, 8); line(src_clone, Point(right, 0), Point(right, src_hight), Scalar(0, 255, 0), 1, 8); circle(src_clone, Point((left + (right - left) / 2), (up + (down - up) / 2)), 3, Scalar(0, 255, 0), -1, 8, 0);//绘制圆心 circle(src_clone, Point((left + (right - left) / 2), (up + (down - up) / 2)), ((down - up) + (right - left)) / 4, Scalar(155, 50, 255), 2, 8, 0);//绘制圆边 imshow("Circumscribe Src", src_clone); } waitKey(); #endif } /****************************************************************************************************************/ /*统计 yuv420p 图像数据 Y 通道图像亮度差*/ void YUV_match_avg_yuv420p(Mat src1, Mat src2, double *alpha1Y, double *alpha2Y) { size_t rowNumber = src1.rows; size_t colNumber = src1.cols * src1.channels(); unsigned int Y_sum_1 = 0, Y_sum_2 = 0; unsigned int Pix_num = 0; for (size_t i = 0; i < rowNumber; i++) { uchar *data1 = src1.ptr<uchar>(i); uchar *data2 = src2.ptr<uchar>(i); for (size_t j = 0; j < colNumber; j++) { Y_sum_1 += data1[j]; Y_sum_2 += data2[j]; Pix_num++; } } //double Yaveg = ((double) Y_sum_1 + (double) Y_sum_2) / 2.0; double Yaveg = 1.0; double alphaY1 = 1.0; double alphaY2 = 1.0; if (Y_sum_1 > Y_sum_2) { Yaveg = (double) Y_sum_1; alphaY2 = Yaveg / (double) Y_sum_2; } else { Yaveg = (double) Y_sum_2; alphaY1 = Yaveg / (double) Y_sum_1; } *alpha1Y = alphaY1; *alpha2Y = alphaY2; } /****************************************************************************************************************/ /* SRC0 生成完整映射情况 map_roi*************************************************************************************/ void Generate_Equirectangular_src_0_map_roi_yuv420sp(Size src_size, Size dest_size, Point2f centerf_0, float radiusf_0, Mat RotateMat, Vec3d TMatrix, double dbK, Mat *mapx_ud, Mat *mapy_ud, Mat *mapx_ud_2, Mat *mapy_ud_2)//,float zoom { int width, hight; int cols, rows; //循环变量 //原图大小 int src_w = src_size.width; int src_h = src_size.height; //半球投影大小 width = dest_size.width; hight = dest_size.height; int start_hight = cvRound((0.25 + 0.75 * ANGLE) * (float) hight); int roi_hight = cvRound((1.0 - ANGLE) * (float) hight * 0.5); //roi 区域的高度 int stop_hight = start_hight + roi_hight;//cvRound((0.75 + 0.25 * ANGLE) * (float )hight); //生成的映射表 Mat mapx(roi_hight, width, CV_32FC1); //转成 remap 函数所需格式,并判断范围是否在规定图像范围内 Mat mapy(roi_hight, width, CV_32FC1); double *pRotateMat = RotateMat.ptr<double>(0); for (rows = start_hight; rows < stop_hight; rows++) //行循环1080 y { float ty = ((float) rows / (float) hight); //归一化 Y for (cols = 0; cols < width; cols++) //列循环1920 x { float tx = (float) cols / (float) width; //归一化 X double x = ty * cos(P2PI * tx); double y = ty * sin(P2PI * tx); double x2y2 = (x * x + y * y); double z = 0; if (x2y2 <= 1) { z = sqrt(1 - x2y2); } double x1 = ((dbK * (pRotateMat[0] * x + pRotateMat[1] * y + pRotateMat[2] * z) + TMatrix[0]) * radiusf_0 + centerf_0.x); // * zoom只适应了原图 double y1 = ((dbK * (pRotateMat[3] * x + pRotateMat[4] * y + pRotateMat[5] * z) + TMatrix[1]) * radiusf_0 + centerf_0.y); // * zoom; //double z1 = (dbK*(pRotateMat[6]*x + pRotateMat[7]*y + pRotateMat[8]*z)+TMatrix[2]); mapx.at<float>(rows - start_hight, cols) = (x1 > (double) src_w) ? (float) src_w : (float) (x1); mapy.at<float>(rows - start_hight, cols) = (y1 > (double) src_h) ? (float) src_h : (float) (y1); } } //生成镜像 map 上下/左右 都镜像 Mat mapx_udlr = mapx.clone(); Mat mapy_udlr = mapy.clone(); for (rows = 0; rows < mapx.rows; rows++) //行循环1080 y { for (cols = 0; cols < mapx.cols; cols++) //列循环1920 x { mapx_udlr.at<float>(rows, cols) = mapx.at<float>(rows, cols); mapy_udlr.at<float>(rows, cols) = mapy.at<float>(rows, cols); } } Mat mapx_2(mapx.rows / 2, mapx.cols / 2, CV_32FC1); //转成 remap 函数所需格式,并判断范围是否在规定图像范围内 Mat mapy_2(mapy.rows / 2, mapy.cols / 2, CV_32FC1); for (rows = 0; rows < mapx.rows / 2; rows++) //行循环1080 y { for (cols = 0; cols < mapx.cols / 2; cols++) //列循环1920 x { mapx_2.at<float>(rows, cols) = mapx_udlr.at<float>(rows * 2, cols * 2) / 2; mapy_2.at<float>(rows, cols) = mapy_udlr.at<float>(rows * 2, cols * 2) / 2; } } *mapx_ud = mapx_udlr.clone(); *mapy_ud = mapy_udlr.clone(); *mapx_ud_2 = mapx_2.clone(); *mapy_ud_2 = mapy_2.clone(); } /****************************************************************************************************************/ /* SRC1 生成完整映射情况 map_roi*************************************************************************************/ void Generate_Equirectangular_src_1_map_roi_yuv420sp(Size src_size, Size dest_size, Point2f centerf_1, float radiusf_1, Mat *mapx_ud, Mat *mapy_ud, Mat *mapx_ud_2, Mat *mapy_ud_2)//, float zoom) { int width, hight; int cols, rows; //循环变量 //原图大小 int src_w = src_size.width; int src_h = src_size.height; //经纬图投影 float kx = (radiusf_1) / ((float) src_w); // * zoom float dx = (centerf_1.x) / (float) src_w; // * zoom float ky = (radiusf_1) / ((float) src_h); // * zoom float dy = (centerf_1.y) / (float) src_h; // * zoom //半球投影大小 width = dest_size.width; hight = dest_size.height; int start_hight = cvRound((1 - ANGLE) * (float) hight * 0.25); int roi_hight = cvRound((1.0 - ANGLE) * (float) hight * 0.5); //roi 区域的高度 int stop_hight = start_hight + roi_hight;//cvRound((1 - ANGLE) * (float )hight * 0.75); //生成的映射表 Mat mapx(roi_hight, width, CV_32FC1); //转成 remap 函数所需格式,并判断范围是否在规定图像范围内 Mat mapy(roi_hight, width, CV_32FC1); vector<Point3d> P2; for (rows = start_hight; rows < stop_hight; rows++) //行循环1080 y { float ty = 1.0 - (((float) rows / (float) hight)); //归一化 Y for (cols = 0; cols < width; cols++) //列循环1920 x { float tx = (float) cols / (float) width; //归一化 X double x = -1 * ty * cos(P2PI * tx) * kx + dx; double y = ty * sin(P2PI * tx) * ky + dy; mapx.at<float>(rows - start_hight, cols) = (float) (x) * (float) src_w; mapy.at<float>(rows - start_hight, cols) = (float) (y) * (float) src_h; } } //生成镜像 map 上下/左右 都镜像 Mat mapx_udlr = mapx.clone(); Mat mapy_udlr = mapy.clone(); for (rows = 0; rows < mapx.rows; rows++) //行循环1080 y { for (cols = 0; cols < mapx.cols; cols++) //列循环1920 x { mapx_udlr.at<float>(rows, cols) = mapx.at<float>(rows, cols); mapy_udlr.at<float>(rows, cols) = mapy.at<float>(rows, cols); } } Mat mapx_2(mapx.rows / 2, mapx.cols / 2, CV_32FC1); //转成 remap 函数所需格式,并判断范围是否在规定图像范围内 Mat mapy_2(mapy.rows / 2, mapy.cols / 2, CV_32FC1); for (rows = 0; rows < mapx.rows / 2; rows++) //行循环1080 y { for (cols = 0; cols < mapx.cols / 2; cols++) //列循环1920 x { mapx_2.at<float>(rows, cols) = mapx_udlr.at<float>(rows * 2, cols * 2) / 2; mapy_2.at<float>(rows, cols) = mapy_udlr.at<float>(rows * 2, cols * 2) / 2; } } *mapx_ud = mapx_udlr.clone(); *mapy_ud = mapy_udlr.clone(); *mapx_ud_2 = mapx_2.clone(); *mapy_ud_2 = mapy_2.clone(); } /****************************************************************************************************************/ /*最佳缝合线**暂时不能用************************************************************************************************/ bool Optimal_Stitching_Line(Mat eq_img_0, Mat eq_img_1, int Stitching_threshold, Mat *m) { /*4. 融合区最佳缝合线******************************************************************/ /*a.计算缝合线判决值******************************/ Mat diff, diff_Sobel_x, diff_Sobel_y; Mat eq_img_0_gray, eq_img_1_gray; cvtColor(eq_img_0, eq_img_0_gray, CV_BGR2GRAY); //转换成灰度 cvtColor(eq_img_1, eq_img_1_gray, CV_BGR2GRAY); eq_img_0_gray.convertTo(eq_img_0_gray, CV_32F, 1.0 / 255.0); //转换成浮点 eq_img_1_gray.convertTo(eq_img_1_gray, CV_32F, 1.0 / 255.0); absdiff(eq_img_0_gray, eq_img_1_gray, diff); //图像差值 Mat diff_2; diff_2 = diff.mul(diff); //图像差值平方 //改进 soble 算子 Mat myKnernel_x = (Mat_<double>(3, 3) << -2, 0, 2, -1, 0, 1, -2, 0, 2); Mat myKnernel_y = (Mat_<double>(3, 3) << -2, -1, -2, 0, 0, 0, 2, 1, 2); Mat dst_x_0, dst_y_0, dst_x_1, dst_y_1; //x,y 方向梯度值 filter2D(eq_img_0_gray, dst_x_0, -1, myKnernel_x, Point(-1, -1), 0, BORDER_DEFAULT); filter2D(eq_img_0_gray, dst_y_0, -1, myKnernel_y, Point(-1, -1), 0, BORDER_DEFAULT); filter2D(eq_img_1_gray, dst_x_1, -1, myKnernel_x, Point(-1, -1), 0, BORDER_DEFAULT); filter2D(eq_img_1_gray, dst_y_1, -1, myKnernel_y, Point(-1, -1), 0, BORDER_DEFAULT); absdiff(dst_x_0, dst_x_1, diff_Sobel_x); //x方向梯度差值 absdiff(dst_y_0, dst_y_1, diff_Sobel_y); //y方向梯度差值 Mat diff_Sobel_xy = diff_Sobel_x.mul(diff_Sobel_y); //(dx_0 - dx_1)*(dy_0 - dy_1) Mat geometry; geometry = diff_2 + diff_Sobel_xy; //缝合线判决值 = 颜色(灰度)相似度 + 结构相似度 /*b. 遍历判决值 Mat,查找缝合线********************************/ int rowNumber = geometry.rows; int colNumber = geometry.cols * geometry.channels(); vector<vector<Point> > all_line; vector<double> all_line_strength; vector<int> all_finish_loop; char finish_loop = 0; for (int i = 1; i < rowNumber - 1; i++) //行循环 { finish_loop = 0; int row_loop = i; vector<Point> line; double line_strength = 0; line_strength = (double) geometry.at<float>(row_loop, 0); for (int j = 1; j < colNumber - 1; j++) //列循环 { line.push_back(Point(j - 1, row_loop)); float elm_middle = geometry.at<float>(row_loop, (j)); float elm_left = geometry.at<float>((row_loop - 1), (j)); float elm_right = geometry.at<float>((row_loop + 1), (j)); int offse; if (elm_middle < elm_left) { if (elm_middle < elm_right) { offse = 0; line_strength += (double) elm_middle; } else { offse = 1; line_strength += (double) elm_right; } } else { if (elm_left < elm_right) { offse = -1; line_strength += (double) elm_left; } else { offse = 1; line_strength += (double) elm_right; } } row_loop = row_loop + offse; if (row_loop <= 1)//|| row_loop > rowNumber { row_loop = rowNumber / 2; finish_loop++; } else if (row_loop >= (rowNumber - 1)) //|| row_loop > rowNumber { finish_loop++; row_loop = rowNumber / 2; //如果查找到边缘,返回图像中心重新寻找 } if (finish_loop > Stitching_threshold) { break; } } if (finish_loop <= Stitching_threshold) { all_line.push_back(line); //缝合线 all_line_strength.push_back(line_strength); //缝合线强度 all_finish_loop.push_back(finish_loop); } } /*c. 在缝合线中找最小缝合线和********************************/ int flm_min = 0; if (0 != all_line.size()) { cout << "找到缝合线条数 = " << all_line.size() << endl; for (size_t flm = 0; flm < all_line.size(); flm++) { if (all_line_strength[flm_min] >= all_line_strength[flm]) { flm_min = flm; } } if (0 != all_line.size()) { rowNumber = m->rows; colNumber = m->cols * m->channels(); for (int rows = 0; rows < rowNumber; rows++) { float *data = m->ptr<float>(rows); for (int cols = 0; cols < colNumber; cols++) { if (rows > all_line[flm_min][cols].y) { data[cols] = 1; } else { data[cols] = 0; } } } } #if IWSHOW_DEBUG //绘制所有缝合线 Mat lines_mat_0 = eq_img_0.clone(); Mat lines_mat_1 = eq_img_1.clone(); uchar green_d = 255 / all_line.size(); for(size_t flm = 0; flm < all_line.size(); flm++) { uchar green = green_d * flm; uchar blue = (255 - green); for(size_t lines = 0; lines < all_line[flm].size() - 1; lines++) { line(lines_mat_0 , all_line[flm][lines], all_line[flm][lines + 1], Scalar(blue, green, 0), 1, LINE_AA); line(lines_mat_1 , all_line[flm][lines], all_line[flm][lines + 1], Scalar(blue, green, 0), 1, LINE_AA); } std::cout << "all_line_strength = " << all_line_strength[flm] << endl; std::cout << "all_finish_loop = " << all_finish_loop[flm] << endl; } imshow("lines_mat_0", lines_mat_0); imshow("lines_mat_1", lines_mat_1); waitKey(); //绘制最佳缝合线 Mat lines_mat = eq_img_0.clone(); for(size_t lines = 0; lines < all_line[flm_min].size() - 1; lines++) { line(lines_mat , all_line[flm_min][lines], all_line[flm_min][lines + 1], Scalar(255, 255, 0), 1, LINE_AA); } imshow("lines_mat", lines_mat); waitKey(); #endif return true; } else { cout << "未找到缝合线,线性融合 " << endl; return false; } } /****************************************************************************************************************/
ad11ca5385a79a7e3ac641f95219021748fae6d7
81c6ba4a12f30f8adf7d98dcac54bbba864122d2
/fibsum.cpp
2a374dd3d863e22f9d86042367e0697d4c1b6907
[]
no_license
SharmaManish/Spoj
a158881c059e20444e333841549df28169a3be41
5342e1c8ed87ef052983cbcc587c371cb876e758
refs/heads/master
2021-01-23T06:44:04.635579
2013-01-04T06:30:50
2013-01-04T06:30:50
7,436,084
10
17
null
null
null
null
UTF-8
C++
false
false
1,919
cpp
fibsum.cpp
#include<iostream> #include<stdio.h> int main() { long long int a[100001]; long long int b[100001]; int t,n,m; a[0]=0; a[1]=1; for(int i=2;i<100001;i++) a[i]=a[i-1]+a[i-2]; b[0]=a[100000]+a[99999]; b[1]=a[100000]+b[0]; for(int i=2;i<100001;i++) b[i]=b[i-1]+b[i-2]; scanf("%d",&t); /*for(int i=0;i<100001;i++) { cout<<a[i]<<endl; } for(int j=100001;j<1000000000;j++) { cout<<b[j-100001]<<endl; } */ while(t--) { long long unsigned int sum=0; scanf("%d%d",&n,&m); if(n>100000) { while(n<=m) { sum=sum+b[n-100001]; n++; } sum=sum%1000000007; } else if(n<100000 && m>100000) { while(n<=100000) { sum=sum+a[n]; n++; } while(n<=m) { sum=sum+b[n-100001]; n++; } sum=sum%1000000007; } else { while(n<=m) { sum=sum+a[n]; n++; } sum=sum%1000000007; } printf("%lld\n",sum); } system ("pause"); return 0; }
2163c5fd7784889032f4df3c8a0defe455541d10
ac6b3297e505b2fec2ad465b6260309a00fed914
/src/trigger_on_load.hpp
8271dc1cc0f0ad9305bb0eea9c5a745582830ebd
[ "WTFPL", "BSD-3-Clause" ]
permissive
RagBillySandstone/BogaudioModules
d43836d351b7ff1c7309efaab5cf2b84acacc9c8
c221b53171a3603e48551f1c8f644e3020b69398
refs/heads/master
2020-06-26T01:16:06.427826
2019-07-17T02:58:39
2019-07-17T02:58:39
null
0
0
null
null
null
null
UTF-8
C++
false
false
1,024
hpp
trigger_on_load.hpp
#pragma once #include "rack.hpp" using namespace rack; namespace bogaudio { struct TriggerOnLoadModule : Module { bool _triggerOnLoad = true; bool _shouldTriggerOnLoad = true; json_t* dataToJson() override; void dataFromJson(json_t* root) override; virtual bool shouldTriggerOnNextLoad() = 0; }; struct TriggerOnLoadModuleWidget : ModuleWidget { struct TriggerOnLoadMenuItem : MenuItem { TriggerOnLoadModule* _module; TriggerOnLoadMenuItem(TriggerOnLoadModule* module, const char* label) : _module(module) { this->text = label; } void onAction(const event::Action& e) override { _module->_triggerOnLoad = !_module->_triggerOnLoad; } void step() override { rightText = _module->_triggerOnLoad ? "✔" : ""; } }; void appendContextMenu(Menu* menu) override { TriggerOnLoadModule* m = dynamic_cast<TriggerOnLoadModule*>(module); assert(m); menu->addChild(new MenuLabel()); menu->addChild(new TriggerOnLoadMenuItem(m, "Resume loop on load")); } }; } // namespace bogaudio