blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
3
264
content_id
stringlengths
40
40
detected_licenses
listlengths
0
85
license_type
stringclasses
2 values
repo_name
stringlengths
5
140
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringclasses
905 values
visit_date
timestamp[us]date
2015-08-09 11:21:18
2023-09-06 10:45:07
revision_date
timestamp[us]date
1997-09-14 05:04:47
2023-09-17 19:19:19
committer_date
timestamp[us]date
1997-09-14 05:04:47
2023-09-06 06:22:19
github_id
int64
3.89k
681M
โŒ€
star_events_count
int64
0
209k
fork_events_count
int64
0
110k
gha_license_id
stringclasses
22 values
gha_event_created_at
timestamp[us]date
2012-06-07 00:51:45
2023-09-14 21:58:39
โŒ€
gha_created_at
timestamp[us]date
2008-03-27 23:40:48
2023-08-21 23:17:38
โŒ€
gha_language
stringclasses
141 values
src_encoding
stringclasses
34 values
language
stringclasses
1 value
is_vendor
bool
1 class
is_generated
bool
2 classes
length_bytes
int64
3
10.4M
extension
stringclasses
115 values
content
stringlengths
3
10.4M
authors
listlengths
1
1
author_id
stringlengths
0
158
47febedda61077f35cfd6caec90895854a7d3a41
1d0def2ec8eacce21b33b641229bb8dbcb4dfd8a
/sailfishclient/TapMenu.cpp
98debd00c3313697e4e9e59ad5ff2505d757bb04
[]
no_license
Nokius/monavsailfish
64dda8536c12852545e0454b9fa8a8ac43eac543
a762d58c765a4959d55dc5f31cce669513aaf33b
refs/heads/master
2020-12-24T23:11:30.830226
2015-03-08T18:04:35
2015-03-08T18:04:35
31,856,840
0
0
null
2015-03-08T16:34:03
2015-03-08T16:34:03
null
UTF-8
C++
false
false
1,737
cpp
#include "TapMenu.h" #include "interfaces/iaddresslookup.h" #include "interfaces/irenderer.h" #include "utils/qthelpers.h" #include "client/mapdata.h" #include "client/routinglogic.h" TapMenu::TapMenu(QObject *parent) : QObject(parent) { } TapMenu::~TapMenu() { } void TapMenu::searchTextChanged(QString text) { IAddressLookup* addressLookup = MapData::instance()->addressLookup(); if ( addressLookup == NULL ) return; search_suggestions.clear(); search_dataIndex.clear(); QStringList characters; QStringList placeNames; if (text.length() == 0) { emit searchResultUpdated(search_suggestions, placeNames); return; } Timer time; bool found = addressLookup->GetStreetSuggestions( 0, text, 10, &search_suggestions, &placeNames, &search_dataIndex, &characters ); qDebug() << "Street Lookup:" << time.elapsed() << "ms"; emit searchResultUpdated(search_suggestions, placeNames); } void TapMenu::searchResultSelected(QString command, int index) { IAddressLookup* addressLookup = MapData::instance()->addressLookup(); if ( addressLookup == NULL ) return; qDebug() << search_dataIndex[index]; QVector< int > segmentLength; QVector< UnsignedCoordinate > coordinates; QString place; if ( !addressLookup->GetStreetData( 0, search_suggestions[index], search_dataIndex[index], &segmentLength, &coordinates, &place ) ) return; IRenderer* renderer = MapData::instance()->renderer(); if ( renderer == NULL ) return; if (command == "source") { RoutingLogic::instance()->setSource( coordinates[0] ); } else if (command == "destination") { RoutingLogic::instance()->setTarget( coordinates[0] ); } } void TapMenu::setSourceFollowLocation(bool follow) { RoutingLogic::instance()->setGPSLink(follow); }
[ "jettis@gmail.com" ]
jettis@gmail.com
de3f0598ead2227c2596415e15ae4a9ca57e6fbb
adc6ec6f7845f5c3ca81a17c09a938b6c399c8a7
/Chapter 6 - Threaded safe stack using mutex - A class definition example.cpp
fdf4e18f648d11f0952409562a62007288a1a262
[]
no_license
CyberExplosion/Concurrency-In-Action
57d9eb7cd885c3bb01a2618d94fbfd105239894c
a5786650874bdec36d5dffe34cb677be819c0d7b
refs/heads/main
2023-06-02T11:44:05.662065
2021-06-18T10:49:02
2021-06-18T10:49:02
324,660,323
0
0
null
null
null
null
UTF-8
C++
false
false
1,706
cpp
#include <thread> #include <stack> #include <mutex> #include <exception> using namespace std; struct empty_stack : std::exception { const char* what () const noexcept; }; template <typename T> class threadsafe_stack { private: stack<T> data; mutable mutex m; public: threadsafe_stack () {}; threadsafe_stack (const threadsafe_stack& other) { scoped_lock guard{ m }; data = other.data; //Use the stack assignment op } threadsafe_stack& operator= (const threadsafe_stack&) = delete; //Can't use assignment //no assignment op for mutex. Also only copy-swap idiom makes assignment exception safe void push (T new_value) { //Copy in because thread scoped_lock guard{ m }; data.push (move (new_value)); //Might throw an exception if the move fail //Stack guarantee push to be exception free tho so it's good } shared_ptr<T> pop () { //1 option to return pointer. (Can't return reference because they //can change from the outside scoped_lock guard{ m }; if (data.empty ()) throw empty_stack (); shared_ptr<T> const res{ make_shared<T> (move (data.top ())) }; //Move so no need to //copy the file into making a new value. Also avoid making new data //Also const so you can't do anything funny like swap the pointer or reset it data.pop (); return res; } void pop (T& value) { //2 option to pass in a reference for result scoped_lock guard{ m }; if (data.empty ()) throw empty_stack (); value = move(data.top ()); //Assign to reference so no exception //The move or the inner copy assignment can throw data.pop (); } bool empty () const { scoped_lock guard{ m }; return data.empty (); //Empty never throw so this function is safe } };
[ "minhkhoi632000@gmail.com" ]
minhkhoi632000@gmail.com
851fbf1ba4355da7fdab1061d22fa598e4bf2052
d40efadec5724c236f1ec681ac811466fcf848d8
/tags/volition_import/fs2_open/code/network/multiteamselect.cpp
3edeca2fdf8c0c105c4da888ac762f764b53253d
[]
no_license
svn2github/fs2open
0fcbe9345fb54d2abbe45e61ef44a41fa7e02e15
c6d35120e8372c2c74270c85a9e7d88709086278
refs/heads/master
2020-05-17T17:37:03.969697
2015-01-08T15:24:21
2015-01-08T15:24:21
14,258,345
0
0
null
null
null
null
UTF-8
C++
false
false
100,422
cpp
/* * Copyright (C) Volition, Inc. 1999. All rights reserved. * * All source code herein is the property of Volition, Inc. You may not sell * or otherwise commercially exploit the source or things you created based on the * source. * */ /* * $Logfile: /Freespace2/code/Network/MultiTeamSelect.cpp $ * $Revision: 1.1 $ * $Date: 2002-06-03 03:26:00 $ * $Author: penguin $ * * Multiplayer Team Selection Code * * $Log: not supported by cvs2svn $ * Revision 1.1 2002/05/02 18:03:11 mharris * Initial checkin - converted filenames and includes to lower case * * * 27 9/13/99 12:54p Jefff * coord fix * * 26 9/12/99 3:21p Jefff * commit button coord fix in 640 * * 25 8/05/99 9:57p Jefff * fixed some button wierdness * * 24 8/05/99 5:08p Jefff * fixed some location probs * * 23 7/28/99 5:34p Dave * Nailed the missing stats bug to the wall. Problem was optimized build * and using GET_DATA() with array elements. BLECH. * * 22 7/24/99 6:02p Jefff * Added "lock" text to lock button * * 21 5/03/99 8:32p Dave * New version of multi host options screen. * * 20 3/25/99 6:36p Neilk * more hires coord fixes * * 19 3/25/99 2:44p Neilk * Fixed lock button * * 18 3/23/99 11:56a Neilk * new source safe checkin * * 17 3/10/99 6:50p Dave * Changed the way we buffer packets for all clients. Optimized turret * fired packets. Did some weapon firing optimizations. * * 16 3/09/99 6:24p Dave * More work on object update revamping. Identified several sources of * unnecessary bandwidth. * * 15 2/21/99 6:02p Dave * Fixed standalone WSS packets. * * 14 2/11/99 3:08p Dave * PXO refresh button. Very preliminary squad war support. * * 13 2/01/99 5:55p Dave * Removed the idea of explicit bitmaps for buttons. Fixed text * highlighting for disabled gadgets. * * 12 1/30/99 5:08p Dave * More new hi-res stuff.Support for nice D3D textures. * * 11 1/30/99 1:29a Dave * Fixed nebula thumbnail problem. Full support for 1024x768 choose pilot * screen. Fixed beam weapon death messages. * * 10 1/29/99 5:07p Dave * Fixed multiplayer stuff. Put in multiplayer support for rapid fire * missiles. * * 9 1/13/99 7:19p Neilk * Converted Mission Brief, Barracks, Synch to high res support * * 8 12/18/98 1:13a Dave * Rough 1024x768 support for Direct3D. Proper detection and usage through * the launcher. * * 7 11/30/98 1:07p Dave * 16 bit conversion, first run. * * 6 11/19/98 8:04a Dave * Full support for D3-style reliable sockets. Revamped packet lag/loss * system, made it receiver side and at the lowest possible level. * * 5 11/17/98 11:12a Dave * Removed player identification by address. Now assign explicit id #'s. * * 4 11/05/98 5:55p Dave * Big pass at reducing #includes * * 3 10/13/98 9:29a Dave * Started neatening up freespace.h. Many variables renamed and * reorganized. Added AlphaColors.[h,cpp] * * 2 10/07/98 10:53a Dave * Initial checkin. * * 1 10/07/98 10:50a Dave * * 112 9/18/98 2:22a Dave * Fixed freespace-side PXO api to correctly handle length 10 id strings. * Fixed team select screen to handle alpha/beta/gamma ships which are not * marked as OF_PLAYER_SHIP * * 111 9/17/98 3:08p Dave * PXO to non-pxo game warning popup. Player icon stuff in create and join * game screens. Upped server count refresh time in PXO to 35 secs (from * 20). * * 110 8/20/98 5:31p Dave * Put in handy multiplayer logfile system. Now need to put in useful * applications of it all over the code. * * 109 8/07/98 10:17a Allender * use obj_set_flags for setting COULD_BE_PLAYER flag to trap bugs * * 108 7/24/98 9:27a Dave * Tidied up endgame sequencing by removing several old flags and * standardizing _all_ endgame stuff with a single function call. * * 107 6/13/98 6:01p Hoffoss * Externalized all new (or forgot to be added) strings to all the code. * * 106 6/13/98 3:19p Hoffoss * NOX()ed out a bunch of strings that shouldn't be translated. * * 105 5/19/98 8:35p Dave * Revamp PXO channel listing system. Send campaign goals/events to * clients for evaluation. Made lock button pressable on all screens. * * 104 5/19/98 11:23a Dave * Change mask value for "lock" button. * * 103 5/18/98 12:41a Allender * fixed subsystem problems on clients (i.e. not reporting properly on * damage indicator). Fixed ingame join problem with respawns. minor * comm menu stuff * * 102 5/17/98 1:43a Dave * Eradicated chatbox problems. Remove speed match for observers. Put in * help screens for PXO. Fix messaging and end mission privelges. Fixed * team select screen bugs. Misc UI fixes. * * 101 5/15/98 5:16p Dave * Fix a standalone resetting bug.Tweaked PXO interface. Display captaincy * status for team vs. team. Put in asserts to check for invalid team vs. * team situations. * * 100 5/10/98 7:06p Dave * Fix endgame sequencing ESC key. Changed how host options warning popups * are done. Fixed pause/message scrollback/options screen problems in mp. * Make sure observer HUD doesn't try to lock weapons. * */ #include "multiteamselect.h" #include "ui.h" #include "chatbox.h" #include "bmpman.h" #include "gamesnd.h" #include "key.h" #include "linklist.h" #include "gamesequence.h" #include "font.h" #include "multiutil.h" #include "freespace.h" #include "missionscreencommon.h" #include "missionshipchoice.h" #include "missionweaponchoice.h" #include "missionbrief.h" #include "missionparse.h" #include "multimsgs.h" #include "snazzyui.h" #include "mouse.h" #include "popup.h" #include "multiui.h" #include "multi_endgame.h" #include "alphacolors.h" #include "multi.h" // ------------------------------------------------------------------------------------------------------ // TEAM SELECT DEFINES/VARS // // mission screen common data extern int Next_screen; //XSTR:OFF // bitmap defines #define MULTI_TS_PALETTE "InterfacePalette" char *Multi_ts_bitmap_fname[GR_NUM_RESOLUTIONS] = { "TeamSelect", // GR_640 "2_TeamSelect" // GR_1024 }; char *Multi_ts_bitmap_mask_fname[GR_NUM_RESOLUTIONS] = { "TeamSelect-M", // GR_640 "2_TeamSelect-M" // GR_1024 }; // constants for coordinate lookup #define MULTI_TS_X_COORD 0 #define MULTI_TS_Y_COORD 1 #define MULTI_TS_W_COORD 2 #define MULTI_TS_H_COORD 3 #define MULTI_TS_NUM_BUTTONS 7 #define MULTI_TS_BRIEFING 0 // go to the briefing #define MULTI_TS_SHIP_SELECT 1 // this screen #define MULTI_TS_WEAPON_SELECT 2 // go to the weapon select screen #define MULTI_TS_SHIPS_UP 3 // scroll the ships list up #define MULTI_TS_SHIPS_DOWN 4 // scroll the ships list down #define MULTI_TS_COMMIT 5 // commit #define MULTI_TS_LOCK 6 // lock (free) ship/weapon select ui_button_info Multi_ts_buttons[GR_NUM_RESOLUTIONS][MULTI_TS_NUM_BUTTONS] = { { // GR_640 ui_button_info("CB_00", 7, 3, 37, 7, 0), ui_button_info("CB_01", 7, 19, 37, 23, 1), ui_button_info("CB_02", 7, 35, 37, 39, 2), ui_button_info("TSB_03", 5, 303, -1, -1, 3), ui_button_info("TSB_04", 5, 454, -1, -1, 4), ui_button_info("TSB_09", 571, 425, 572, 413, 9), ui_button_info("TSB_34", 603, 374, 602, 364, 34) }, { // GR_1024 ui_button_info("2_CB_00", 12, 5, 59, 12, 0), ui_button_info("2_CB_01", 12, 31, 59, 37, 1), ui_button_info("2_CB_02", 12, 56, 59, 62, 2), ui_button_info("2_TSB_03", 8, 485, -1, -1, 3), ui_button_info("2_TSB_04", 8, 727, -1, -1, 4), ui_button_info("2_TSB_09", 914, 681, 937, 660, 9), ui_button_info("2_TSB_34", 966, 599, 964, 584, 34) }, }; // players locked ani graphic #define MULTI_TS_NUM_LOCKED_BITMAPS 3 char *Multi_ts_bmap_names[GR_NUM_RESOLUTIONS][3] = { { // GR_640 "TSB_340000", "TSB_340001", "TSB_340002" }, { // GR_1024 "2_TSB_340000", "2_TSB_340001", "2_TSB_340002" } }; int Multi_ts_locked_bitmaps[MULTI_TS_NUM_LOCKED_BITMAPS]; // snazzy menu regions #define TSWING_0_SHIP_0 10 #define TSWING_0_SHIP_1 12 #define TSWING_0_SHIP_2 14 #define TSWING_0_SHIP_3 16 #define TSWING_1_SHIP_0 18 #define TSWING_1_SHIP_1 20 #define TSWING_1_SHIP_2 22 #define TSWING_1_SHIP_3 24 #define TSWING_2_SHIP_0 26 #define TSWING_2_SHIP_1 28 #define TSWING_2_SHIP_2 30 #define TSWING_2_SHIP_3 32 #define TSWING_0_NAME_0 11 #define TSWING_0_NAME_1 13 #define TSWING_0_NAME_2 15 #define TSWING_0_NAME_3 17 #define TSWING_1_NAME_0 19 #define TSWING_1_NAME_1 21 #define TSWING_1_NAME_2 23 #define TSWING_1_NAME_3 25 #define TSWING_2_NAME_0 27 #define TSWING_2_NAME_1 29 #define TSWING_2_NAME_2 31 #define TSWING_2_NAME_3 33 #define TSWING_LIST_0 5 #define TSWING_LIST_1 6 #define TSWING_LIST_2 7 #define TSWING_LIST_3 8 #define MULTI_TS_SLOT_LIST 0 #define MULTI_TS_PLAYER_LIST 1 #define MULTI_TS_AVAIL_LIST 2 // interface data #define MULTI_TS_NUM_SNAZZY_REGIONS 28 int Multi_ts_bitmap; int Multi_ts_mask; int Multi_ts_inited = 0; int Multi_ts_snazzy_regions; ubyte *Multi_ts_mask_data; int Multi_ts_mask_w, Multi_ts_mask_h; MENU_REGION Multi_ts_region[MULTI_TS_NUM_SNAZZY_REGIONS]; UI_WINDOW Multi_ts_window; // ship slot data #define MULTI_TS_NUM_SHIP_SLOTS_TEAM 4 // # of ship slots in team v team #define MULTI_TS_FLAG_NONE -2 // never has any ships #define MULTI_TS_FLAG_EMPTY -1 // currently empty char *Multi_ts_slot_names[MULTI_TS_NUM_SHIP_SLOTS] = { // "alpha 1", "alpha 2", "alpha 3", "alpha 4", "beta 1", "beta 2", "beta 3", "beta 4", "gamma 1", "gamma 2", "gamma 3", "gamma 4" }; char *Multi_ts_slot_team_names[MULTI_TS_MAX_TEAMS][MULTI_TS_NUM_SHIP_SLOTS_TEAM] = { {"alpha 1", "alpha 2", "alpha 3", "alpha 4"}, {"zeta 1", "zeta 2", "zeta 3", "zeta 4"} }; static int Multi_ts_slot_icon_coords[MULTI_TS_NUM_SHIP_SLOTS][GR_NUM_RESOLUTIONS][2] = { // x,y { // {128,301}, // GR_640 {205,482} // GR_1024 }, { // {91,347}, // GR_640 {146,555} // GR_1024 }, { // {166,347}, // GR_640 {266,555} // GR_1024 }, { // alpha {128,395}, // GR_640 {205,632} // GR_1024 }, { // {290,301}, // GR_640 {464,482} // GR_1024 }, { // {253,347}, // GR_640 {405,555} // GR_1024 }, { // {328,347}, // GR_640 {525,555} // GR_1024 }, { // beta {290,395}, // GR_640 {464,632} // GR_1024 }, { // {453,301}, // GR_640 {725,482} // GR_1024 }, { // {416,347}, // GR_640 {666,555} // GR_1024 }, { // {491,347}, // GR_640 {786,555} // GR_1024 }, { // gamma {453,395}, // GR_640 {725,632} // GR_1024 } }; static int Multi_ts_slot_text_coords[MULTI_TS_NUM_SHIP_SLOTS][GR_NUM_RESOLUTIONS][3] = { // x,y,width { // alpha {112,330,181-112}, // GR_640 {187,517,181-112} // GR_1024 }, { // alpha {74,377,143-74}, // GR_640 {126,592,143-74} // GR_1024 }, { // alpha {149,377,218-149},// GR_640 {248,592,218-149} // GR_1024 }, { // alpha {112,424,181-112},// GR_640 {187,667,181-112} // GR_1024 }, { // beta {274,330,343-274},// GR_640 {446,517,343-274} // GR_1024 }, { // beta {236,377,305-236},// GR_640 {385,592,305-236} // GR_1024 }, { // beta {311,377,380-311},// GR_640 {507,592,380-311} // GR_1024 }, { // beta {274,424,343-274},// GR_640 {446,667,343-274} // GR_1024 }, { // gamma {437,330,506-437},// GR_640 {707,517,506-437} // GR_1024 }, { // gamma {399,377,468-399},// GR_640 {646,592,468-399} // GR_1024 }, { // gamma {474,377,543-474},// GR_640 {768,592,543-474} // GR_1024 }, { // gamma {437,424,506-437},// GR_640 {707,667,506-437} // GR_1024 } }; // avail ship list data #define MULTI_TS_AVAIL_MAX_DISPLAY 4 static int Multi_ts_avail_coords[MULTI_TS_AVAIL_MAX_DISPLAY][GR_NUM_RESOLUTIONS][2] = { // x,y coords { // {23,331}, // GR_640 {37,530} // GR_1024 }, { // {23,361}, // GR_640 {37,578} // GR_1024 }, { // {23,391}, // GR_640 {37,626} // GR_1024 }, { // {23,421}, // GR_640 {37,674} // GR_1024 } }; int Multi_ts_avail_start = 0; // starting index of where we will display the available ships int Multi_ts_avail_count = 0; // the # of available ship classes // ship information stuff #define MULTI_TS_SHIP_INFO_MAX_LINE_LEN 150 #define MULTI_TS_SHIP_INFO_MAX_LINES 10 #define MULTI_TS_SHIP_INFO_MAX_TEXT (MULTI_TS_SHIP_INFO_MAX_LINE_LEN * MULTI_TS_SHIP_INFO_MAX_LINES) static int Multi_ts_ship_info_coords[GR_NUM_RESOLUTIONS][3] = { { // GR_640 33, 150, 387 }, { // GR_1024 53, 240, 618 } }; char Multi_ts_ship_info_lines[MULTI_TS_SHIP_INFO_MAX_LINES][MULTI_TS_SHIP_INFO_MAX_LINE_LEN]; char Multi_ts_ship_info_text[MULTI_TS_SHIP_INFO_MAX_TEXT]; int Multi_ts_ship_info_line_count; // status bar mode static int Multi_ts_status_coords[GR_NUM_RESOLUTIONS][3] = { { // GR_640 95, 467, 426 }, { // GR_1024 152, 747, 688 } }; int Multi_ts_status_bar_mode = 0; // carried icon information int Multi_ts_carried_flag = 0; int Multi_ts_clicked_flag = 0; int Multi_ts_clicked_x,Multi_ts_clicked_y; int Multi_ts_carried_ship_class; int Multi_ts_carried_from_type = 0; int Multi_ts_carried_from_index = 0; // selected ship types (for informational purposes) int Multi_ts_select_type = -1; int Multi_ts_select_index = -1; int Multi_ts_select_ship_class = -1; // per-frame mouse hotspot vars int Multi_ts_hotspot_type = -1; int Multi_ts_hotspot_index = -1; // operation types #define TS_GRAB_FROM_LIST 0 #define TS_SWAP_LIST_SLOT 1 #define TS_SWAP_SLOT_SLOT 2 #define TS_DUMP_TO_LIST 3 #define TS_SWAP_PLAYER_PLAYER 4 #define TS_MOVE_PLAYER 5 // packet codes #define TS_CODE_LOCK_TEAM 0 // the specified team's slots are locked #define TS_CODE_PLAYER_UPDATE 1 // a player slot update for the specified team // team data #define MULTI_TS_FLAG_NONE -2 // slot is _always_ empty #define MULTI_TS_FLAG_EMPTY -1 // flag is temporarily empty typedef struct ts_team_data { int multi_ts_objnum[MULTI_TS_NUM_SHIP_SLOTS]; // objnums for all slots in this team net_player *multi_ts_player[MULTI_TS_NUM_SHIP_SLOTS]; // net players corresponding to the same slots int multi_ts_flag[MULTI_TS_NUM_SHIP_SLOTS]; // flags indicating the "status" of a slot int multi_players_locked; // are the players locked into place } ts_team_data; ts_team_data Multi_ts_team[MULTI_TS_MAX_TEAMS]; // data for all teams // deleted ship objnums int Multi_ts_deleted_objnums[MULTI_TS_MAX_TEAMS * MULTI_TS_NUM_SHIP_SLOTS]; int Multi_ts_num_deleted; //XSTR:ON // ------------------------------------------------------------------------------------------------------ // TEAM SELECT FORWARD DECLARATIONS // // check for button presses void multi_ts_check_buttons(); // act on a button press void multi_ts_button_pressed(int n); // initialize all screen data, etc void multi_ts_init_graphics(); // blit all of the icons representing all wings void multi_ts_blit_wings(); // blit all of the player callsigns under the correct ships void multi_ts_blit_wing_callsigns(); // blit the ships on the avail list void multi_ts_blit_avail_ships(); // initialize the snazzy menu stuff for dragging ships,players around void multi_ts_init_snazzy(); // what type of region the index is (0 == ship avail list, 1 == ship slots, 2 == player slot) int multi_ts_region_type(int region); // convert the region num to a ship slot index int multi_ts_slot_index(int region); // convert the region num to an avail list index int multi_ts_avail_index(int region); // convert the region num to a player slot index int multi_ts_player_index(int region); // blit the status bar void multi_ts_blit_status_bar(); // assign the correct players to the correct slots void multi_ts_init_players(); // assign the correct objnums to the correct slots void multi_ts_init_objnums(); // assign the correct flags to the correct slots void multi_ts_init_flags(); // get the proper team and slot index for the given ship name void multi_ts_get_team_and_slot(char *ship_name,int *team_index,int *slot_index); // handle an available ship scroll down button press void multi_ts_avail_scroll_down(); // handle an available ship scroll up button press void multi_ts_avail_scroll_up(); // handle all mouse events (clicking, dragging, and dropping) void multi_ts_handle_mouse(); // can the specified player perform the action he is attempting int multi_ts_can_perform(int from_type,int from_index,int to_type,int to_index,int ship_class,int player_index = -1); // determine the kind of drag and drop operation this is int multi_ts_get_dnd_type(int from_type,int from_index,int to_type,int to_index,int player_index = -1); // swap two player positions int multi_ts_swap_player_player(int from_index,int to_index,int *sound,int player_index = -1); // move a player int multi_ts_move_player(int from_index,int to_index,int *sound,int player_index = -1); // get the ship class of the current index in the avail list or -1 if none exists int multi_ts_get_avail_ship_class(int index); // blit the currently carried icon (if any) void multi_ts_blit_carried_icon(); // if the (console) player is allowed to grab a player slot at this point int multi_ts_can_grab_player(int slot_index,int player_index = -1); // return the bitmap index into the ships icon array (in ship select) which should be displayed for the given slot int multi_ts_slot_bmap_num(int slot_index); // blit any active ship information text void multi_ts_blit_ship_info(); // select the given slot and setup any information, etc void multi_ts_select_ship(); // is it ok for this player to commit int multi_ts_ok_to_commit(); // return the bitmap index into the ships icon array (in ship select) which should be displayed for the given slot int multi_ts_avail_bmap_num(int slot_index); // set the status bar to reflect the status of wing slots (free or not free). 0 or 1 are valid values for now void multi_ts_set_status_bar_mode(int m); // check to see that no illegal ship settings have occurred void multi_ts_check_errors(); // ------------------------------------------------------------------------------------------------------ // TEAM SELECT FUNCTIONS // // initialize the team select screen (always call, even when switching between weapon select, etc) void multi_ts_init() { // if we haven't initialized at all yet, then do it if(!Multi_ts_inited){ multi_ts_init_graphics(); Multi_ts_inited = 1; } // use the common interface palette multi_common_set_palette(); // set the interface palette // common_set_interface_palette(MULTI_TS_PALETTE); Net_player->state = NETPLAYER_STATE_SHIP_SELECT; Current_screen = ON_SHIP_SELECT; } // initialize all critical internal data structures void multi_ts_common_init() { int idx; // reset timestamps here. they seem to get hosed by the loadinh of the mission file multi_reset_timestamps(); // saying "not allowed to mess with ships" Multi_ts_status_bar_mode = 0; // intialize ship info stuff memset(Multi_ts_ship_info_text,0,MULTI_TS_SHIP_INFO_MAX_TEXT); memset(Multi_ts_ship_info_lines,0,MULTI_TS_SHIP_INFO_MAX_TEXT); Multi_ts_ship_info_line_count = 0; // initialize carried icon information Multi_ts_carried_flag = 0; Multi_ts_clicked_flag = 0; Multi_ts_clicked_x = 0; Multi_ts_clicked_y = 0; Multi_ts_carried_ship_class = -1; Multi_ts_carried_from_type = 0; Multi_ts_carried_from_index = 0; // selected slot information (should be default player ship) if(!MULTI_PERM_OBSERVER(Net_players[MY_NET_PLAYER_NUM])){ Multi_ts_select_type = MULTI_TS_SLOT_LIST; Multi_ts_select_index = Net_player->p_info.ship_index; // select this ship and setup his info Multi_ts_select_ship_class = Wss_slots[Multi_ts_select_index].ship_class; multi_ts_select_ship(); } else { Multi_ts_select_type = -1; Multi_ts_select_index = -1; // no ship class selected for information purposes Multi_ts_select_ship_class = -1; } // deleted ship information memset(Multi_ts_deleted_objnums,0,sizeof(int) * MULTI_TS_MAX_TEAMS * MULTI_TS_NUM_SHIP_SLOTS); Multi_ts_num_deleted = 0; // mouse hotspot information Multi_ts_hotspot_type = -1; Multi_ts_hotspot_index = -1; // initialize avail ship list data Multi_ts_avail_start = 0; // load the locked button bitmaps bitmaps for(idx=0;idx<MULTI_TS_NUM_LOCKED_BITMAPS;idx++){ Multi_ts_locked_bitmaps[idx] = -1; Multi_ts_locked_bitmaps[idx] = bm_load(Multi_ts_bmap_names[gr_screen.res][idx]); } // blast the team data clean memset(Multi_ts_team,0,sizeof(ts_team_data) * MULTI_TS_MAX_TEAMS); // assign the correct players to the correct slots multi_ts_init_players(); // assign the correct objnums to the correct slots multi_ts_init_objnums(); // sync the interface as normal multi_ts_sync_interface(); } // do frame for team select void multi_ts_do() { int k = chatbox_process(); k = Multi_ts_window.process(k); // process any keypresses switch(k){ case KEY_ESC : gamesnd_play_iface(SND_USER_SELECT); multi_quit_game(PROMPT_ALL); break; // cycle to the weapon select screen case KEY_TAB : gamesnd_play_iface(SND_USER_SELECT); Next_screen = ON_WEAPON_SELECT; gameseq_post_event(GS_EVENT_WEAPON_SELECTION); break; case KEY_ENTER|KEY_CTRLED: multi_ts_commit_pressed(); break; } // check any button presses multi_ts_check_buttons(); // handle all mouse related events multi_ts_handle_mouse(); // check for errors multi_ts_check_errors(); // draw the background, etc gr_reset_clip(); GR_MAYBE_CLEAR_RES(Multi_ts_bitmap); if(Multi_ts_bitmap != -1){ gr_set_bitmap(Multi_ts_bitmap); gr_bitmap(0,0); } Multi_ts_window.draw(); // render all wings multi_ts_blit_wings(); // blit all callsigns multi_ts_blit_wing_callsigns(); // blit the ships on the available list multi_ts_blit_avail_ships(); // force draw the ship select button Multi_ts_buttons[gr_screen.res][MULTI_TS_SHIP_SELECT].button.draw_forced(2); // force draw the "locked" button if necessary if(multi_ts_is_locked()){ Multi_ts_buttons[gr_screen.res][MULTI_TS_LOCK].button.draw_forced(2); } else { if( ((Netgame.type_flags & NG_TYPE_TEAM) && !(Net_player->flags & NETINFO_FLAG_TEAM_CAPTAIN)) || ((Netgame.type_flags & NG_TYPE_TEAM) && !(Net_player->flags & NETINFO_FLAG_GAME_HOST)) ){ Multi_ts_buttons[gr_screen.res][MULTI_TS_LOCK].button.draw_forced(0); } else { Multi_ts_buttons[gr_screen.res][MULTI_TS_LOCK].button.draw(); } } // blit any active ship information multi_ts_blit_ship_info(); // blit the status bar multi_ts_blit_status_bar(); // render the chatbox chatbox_render(); // render tooltips Multi_ts_window.draw_tooltip(); // display the status of the voice system multi_common_voice_display_status(); // blit any carried icons multi_ts_blit_carried_icon(); // flip the buffer gr_flip(); } // close the team select screen (always call, even when switching between weapon select, etc) void multi_ts_close() { int idx; if(!Multi_ts_inited){ return; } Multi_ts_inited = 0; // shut down the snazzy menu snazzy_menu_close(); // unload any bitmaps if(!bm_unload(Multi_ts_bitmap)){ nprintf(("General","WARNING : could not unload background bitmap %s\n",Multi_ts_bitmap_fname[gr_screen.res])); } for(idx=0;idx<MULTI_TS_NUM_LOCKED_BITMAPS;idx++){ if(Multi_ts_locked_bitmaps[idx] != -1){ bm_release(Multi_ts_locked_bitmaps[idx]); Multi_ts_locked_bitmaps[idx] = -1; } } // destroy the UI_WINDOW Multi_ts_window.destroy(); } // is the given slot disabled for the specified player int multi_ts_disabled_slot(int slot_num, int player_index) { net_player *pl; // get the appropriate net player if(player_index == -1){ pl = Net_player; } else { pl = &Net_players[player_index]; } // if the player is an observer, its _always_ disabled if(pl->flags & NETINFO_FLAG_OBSERVER){ return 1; } // if the flag for this team isn't set to "free" we can't do anything if(!Multi_ts_team[pl->p_info.team].multi_players_locked){ return 1; } // if the "leaders" only flag is set if(Netgame.options.flags & MSO_FLAG_SS_LEADERS){ // in a team vs. team situation if(Netgame.type_flags & NG_TYPE_TEAM){ if(pl->flags & NETINFO_FLAG_TEAM_CAPTAIN){ return 0; } } // in a non team vs. team situation else { if(pl->flags & NETINFO_FLAG_GAME_HOST){ return 0; } } } else { // in a team vs. team situation if(Netgame.type_flags & NG_TYPE_TEAM){ // if i'm the team captain I can mess with my own ships as well as those of the ai ships on my team if(pl->flags & NETINFO_FLAG_TEAM_CAPTAIN){ if((Multi_ts_team[pl->p_info.team].multi_ts_player[slot_num] != NULL) && (Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[slot_num]].flags & OF_PLAYER_SHIP) && (slot_num != pl->p_info.ship_index)){ return 1; } return 0; } } // in a non team vs. team situation else { // if we're the host, we can our own ship and ai ships if(pl->flags & NETINFO_FLAG_GAME_HOST){ // can't grab player ships if((Multi_ts_team[pl->p_info.team].multi_ts_player[slot_num] != NULL) && (Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[slot_num]].flags & OF_PLAYER_SHIP) && (slot_num != pl->p_info.ship_index)){ return 1; } return 0; } } // if this is our slot, then we can grab it if(slot_num == pl->p_info.ship_index){ return 0; } } return 1; } // is the given slot disabled for the specified player, _and_ it is his ship as well int multi_ts_disabled_high_slot(int slot_index,int player_index) { net_player *pl; // get the appropriate net player if(player_index == -1){ pl = Net_player; } else { pl = &Net_players[player_index]; } // if this is disabled for him and its also _his_ slot if(multi_ts_disabled_slot(slot_index,player_index) && !Multi_ts_team[pl->p_info.team].multi_players_locked && (slot_index == pl->p_info.ship_index)){ return 1; } return 0; } // resynch all display/interface elements based upon all the ship/weapon pool values void multi_ts_sync_interface() { int idx; // item 1 - determine how many ship types are available in the ship pool Multi_ts_avail_count = 0; for(idx=0;idx<MAX_SHIP_TYPES;idx++){ if(Ss_pool[idx] > 0){ Multi_ts_avail_count++; } } // item 2 - make sure our local Multi_ts_slot_flag array is up to date multi_ts_init_flags(); // item 3 - set/unset any necessary flags in underlying ship select data structures for(idx=0;idx<MAX_WSS_SLOTS;idx++){ switch(Multi_ts_team[Net_player->p_info.team].multi_ts_flag[idx]){ case MULTI_TS_FLAG_EMPTY : ss_make_slot_empty(idx); break; case MULTI_TS_FLAG_NONE : break; default : ss_make_slot_full(idx); break; } } // item 4 - reset the locked/unlocked status of all ships in the weapon select screen ss_recalc_multiplayer_slots(); } void multi_ts_assign_players_all() { int idx,team_index,slot_index,found,player_count,shipnum; char name_lookup[100]; object *objp; // set all player ship indices to -1 for(idx=0;idx<MAX_PLAYERS;idx++){ if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx])){ Net_players[idx].p_info.ship_index = -1; } } // merge the created object list with the actual object list so we have all available ships obj_merge_created_list(); // get the # of players currently in the game player_count = multi_num_players(); // always assign the host to Alpha 1 (or Zeta 1 in team vs. team - as appropriate) memset(name_lookup,0,100); if(Netgame.type_flags & NG_TYPE_TEAM){ switch(Netgame.host->p_info.team){ case 0 : strcpy(name_lookup,NOX("alpha 1")); break; case 1 : strcpy(name_lookup,NOX("zeta 1")); break; } } else { strcpy(name_lookup,NOX("alpha 1")); } shipnum = ship_name_lookup(name_lookup); // if we couldn't find the ship for the host if(shipnum == -1){ // Netgame.flags |= NG_FLAG_QUITTING; multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_SHIP_ASSIGN); return; } multi_ts_get_team_and_slot(Ships[shipnum].ship_name,&team_index,&slot_index); multi_assign_player_ship(NET_PLAYER_INDEX(Netgame.host),&Objects[Ships[shipnum].objnum],Ships[shipnum].ship_info_index); Netgame.host->p_info.ship_index = slot_index; Assert(Netgame.host->p_info.ship_index >= 0); Netgame.host->p_info.ship_class = Ships[shipnum].ship_info_index; Netgame.host->player->objnum = Ships[shipnum].objnum; // for each netplayer, try and find a ship objp = GET_FIRST(&obj_used_list); while(objp != END_OF_LIST(&obj_used_list)){ // find a valid player ship - ignoring the ship which was assigned to the host if((objp->flags & OF_PLAYER_SHIP) && stricmp(Ships[objp->instance].ship_name,name_lookup)){ // determine what team and slot this ship is multi_ts_get_team_and_slot(Ships[objp->instance].ship_name,&team_index,&slot_index); Assert((team_index != -1) && (slot_index != -1)); // in a team vs. team situation if(Netgame.type_flags & NG_TYPE_TEAM){ // find a player on this team who needs a ship found = 0; for(idx=0;idx<MAX_PLAYERS;idx++){ if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_OBSERVER(Net_players[idx]) && (Net_players[idx].p_info.ship_index == -1) && (Net_players[idx].p_info.team == team_index)){ found = 1; break; } } } // in a non team vs. team situation else { // find any player on this who needs a ship found = 0; for(idx=0;idx<MAX_PLAYERS;idx++){ if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_OBSERVER(Net_players[idx]) && (Net_players[idx].p_info.ship_index == -1)){ found = 1; break; } } } // if we found a player if(found){ multi_assign_player_ship(idx,objp,Ships[objp->instance].ship_info_index); Net_players[idx].p_info.ship_index = slot_index; Assert(Net_players[idx].p_info.ship_index >= 0); Net_players[idx].p_info.ship_class = Ships[objp->instance].ship_info_index; Net_players[idx].player->objnum = OBJ_INDEX(objp); // decrement the player count player_count--; } else { objp->flags &= ~OF_PLAYER_SHIP; obj_set_flags( objp, objp->flags | OF_COULD_BE_PLAYER ); } // if we've assigned all players, we're done if(player_count <= 0){ break; } } // move to the next item objp = GET_NEXT(objp); } // go through and change any ships marked as player ships to be COULD_BE_PLAYER if ( objp != END_OF_LIST(&obj_used_list) ) { for ( objp = GET_NEXT(objp); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) { if ( objp->flags & OF_PLAYER_SHIP ){ objp->flags &= ~OF_PLAYER_SHIP; obj_set_flags( objp, objp->flags | OF_COULD_BE_PLAYER ); } } } if(Game_mode & GM_STANDALONE_SERVER){ Player_obj = NULL; Net_player->player->objnum = -1; } // check to make sure all players were assigned correctly for(idx=0;idx<MAX_PLAYERS;idx++){ if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_OBSERVER(Net_players[idx])){ // if this guy never got assigned a player ship, there's a mission problem if(Net_players[idx].p_info.ship_index == -1){ // Netgame.flags |= NG_FLAG_QUITTING; multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_SHIP_ASSIGN); return; } } } } // delete ships which have been removed from the game, tidy things void multi_ts_create_wings() { int idx,s_idx; // the standalone never went through this screen so he should never call this function! // the standalone and all other clients will have this equivalent function performed whey they receieve // the post_sync_data_packet!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Assert(!(Game_mode & GM_STANDALONE_SERVER)); // check status of all ships and delete or change ship type as necessary Multi_ts_num_deleted = 0; for(idx=0;idx<MULTI_TS_MAX_TEAMS;idx++){ for(s_idx=0;s_idx<MULTI_TS_NUM_SHIP_SLOTS;s_idx++){ // otherwise if there's a valid ship in this spot if(Multi_ts_team[idx].multi_ts_flag[s_idx] >= 0){ int objnum; // set the ship type appropriately Assert(Wss_slots_teams[idx][s_idx].ship_class >= 0); objnum = Multi_ts_team[idx].multi_ts_objnum[s_idx]; change_ship_type(Objects[objnum].instance,Wss_slots_teams[idx][s_idx].ship_class); // set the ship weapons correctly wl_update_ship_weapons(objnum,&Wss_slots_teams[idx][s_idx]); // assign ts_index of the ship to point to the proper Wss_slots slot Ships[Objects[objnum].instance].ts_index = s_idx; } else if(Multi_ts_team[idx].multi_ts_flag[s_idx] == MULTI_TS_FLAG_EMPTY){ Assert(Multi_ts_team[idx].multi_ts_objnum[s_idx] >= 0); // mark the object as having been deleted Multi_ts_deleted_objnums[Multi_ts_num_deleted] = Multi_ts_team[idx].multi_ts_objnum[s_idx]; // delete the ship ship_add_exited_ship( &Ships[Objects[Multi_ts_deleted_objnums[Multi_ts_num_deleted]].instance], SEF_PLAYER_DELETED ); obj_delete(Multi_ts_deleted_objnums[Multi_ts_num_deleted]); ship_wing_cleanup(Objects[Multi_ts_deleted_objnums[Multi_ts_num_deleted]].instance,&Wings[Ships[Objects[Multi_ts_team[idx].multi_ts_objnum[s_idx]].instance].wingnum]); // increment the # of ships deleted Multi_ts_num_deleted++; } } } } // do any necessary processing for players who have left the game void multi_ts_handle_player_drop() { int idx,s_idx; // find the player for(idx=0;idx<MULTI_TS_MAX_TEAMS;idx++){ for(s_idx=0;s_idx<MULTI_TS_NUM_SHIP_SLOTS;s_idx++){ // if we found him, clear his player slot and set his object back to being OF_COULD_BE_PLAYER if((Multi_ts_team[idx].multi_ts_player[s_idx] != NULL) && !MULTI_CONNECTED((*Multi_ts_team[idx].multi_ts_player[s_idx]))){ Assert(Multi_ts_team[idx].multi_ts_objnum[s_idx] != -1); Multi_ts_team[idx].multi_ts_player[s_idx] = NULL; Objects[Multi_ts_team[idx].multi_ts_objnum[s_idx]].flags &= ~(OF_PLAYER_SHIP); obj_set_flags( &Objects[Multi_ts_team[idx].multi_ts_objnum[s_idx]], Objects[Multi_ts_team[idx].multi_ts_objnum[s_idx]].flags | OF_COULD_BE_PLAYER); } } } } // set the status bar to reflect the status of wing slots (free or not free). 0 or 1 are valid values for now void multi_ts_set_status_bar_mode(int m) { Multi_ts_status_bar_mode = m; } // blit the proper "locked" button - used for weapon select and briefing screens void multi_ts_blit_locked_button() { // if we're locked down and we have a valid bitmap if((Multi_ts_team[Net_player->p_info.team].multi_players_locked) && (Multi_ts_locked_bitmaps[2] != -1)){ gr_set_bitmap(Multi_ts_locked_bitmaps[2]); gr_bitmap(Multi_ts_buttons[gr_screen.res][MULTI_TS_LOCK].x, Multi_ts_buttons[gr_screen.res][MULTI_TS_LOCK].y); } // draw as "not locked" if possible else if(Multi_ts_locked_bitmaps[0] != -1){ gr_set_bitmap(Multi_ts_locked_bitmaps[0]); gr_bitmap( Multi_ts_buttons[gr_screen.res][MULTI_TS_LOCK].x, Multi_ts_buttons[gr_screen.res][MULTI_TS_LOCK].y); } } // the "lock" button has been pressed void multi_ts_lock_pressed() { // do nothing if the button has already been pressed if(multi_ts_is_locked()){ gamesnd_play_iface(SND_GENERAL_FAIL); return; } if(Netgame.type_flags & NG_TYPE_TEAM){ Assert(Net_player->flags & NETINFO_FLAG_TEAM_CAPTAIN); } else { Assert(Net_player->flags & NETINFO_FLAG_GAME_HOST); } gamesnd_play_iface(SND_USER_SELECT); // send a final player slot update packet send_pslot_update_packet(Net_player->p_info.team,TS_CODE_LOCK_TEAM,-1); Multi_ts_team[Net_player->p_info.team].multi_players_locked = 1; // sync interface stuff multi_ts_set_status_bar_mode(1); multi_ts_sync_interface(); ss_recalc_multiplayer_slots(); // disable this button now Multi_ts_buttons[gr_screen.res][MULTI_TS_LOCK].button.disable(); } // if i'm "locked" int multi_ts_is_locked() { return Multi_ts_team[Net_player->p_info.team].multi_players_locked; } // show a popup saying "only host and team captains can modify, etc, etc" void multi_ts_maybe_host_only_popup() { /* // if this is because the "host modifies" option is set if((Netgame.options.flags & MSO_FLAG_SS_LEADERS) && !(Net_player->flags & NETINFO_FLAG_GAME_HOST) && !(Net_player->flags & NETINFO_FLAG_TEAM_CAPTAIN)){ multi_ts_host_only_popup(); } if(Netgame.type == NG_TYPE_TEAM){ popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,"Only team captains may modify ships and weapons in this game"); } else { popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,"Only the host may modify ships and weapons in this game"); } */ } // ------------------------------------------------------------------------------------------------------ // TEAM SELECT FORWARD DEFINITIONS // // check for button presses void multi_ts_check_buttons() { int idx; for(idx=0;idx<MULTI_TS_NUM_BUTTONS;idx++){ // we only really need to check for one button pressed at a time, so we can break after // finding one. if(Multi_ts_buttons[gr_screen.res][idx].button.pressed()){ multi_ts_button_pressed(idx); break; } } } // act on a button press void multi_ts_button_pressed(int n) { switch(n){ // back to the briefing screen case MULTI_TS_BRIEFING : gamesnd_play_iface(SND_USER_SELECT); Next_screen = ON_BRIEFING_SELECT; gameseq_post_event( GS_EVENT_START_BRIEFING ); break; // already on this screen case MULTI_TS_SHIP_SELECT: gamesnd_play_iface(SND_GENERAL_FAIL); break; // back to the weapon select screen case MULTI_TS_WEAPON_SELECT: gamesnd_play_iface(SND_USER_SELECT); Next_screen = ON_WEAPON_SELECT; gameseq_post_event(GS_EVENT_WEAPON_SELECTION); break; // scroll the available ships list down case MULTI_TS_SHIPS_DOWN: multi_ts_avail_scroll_down(); break; // scroll the available ships list up case MULTI_TS_SHIPS_UP: multi_ts_avail_scroll_up(); break; // free ship/weapon select case MULTI_TS_LOCK: Assert(Game_mode & GM_MULTIPLAYER); // the "lock" button has been pressed multi_ts_lock_pressed(); // disable the button if it is now locked if(multi_ts_is_locked()){ Multi_ts_buttons[gr_screen.res][MULTI_TS_LOCK].button.disable(); } break; // commit button case MULTI_TS_COMMIT : multi_ts_commit_pressed(); break; default : gamesnd_play_iface(SND_GENERAL_FAIL); break; } } // initialize all screen data, etc void multi_ts_init_graphics() { int idx; // create the interface window Multi_ts_window.create(0,0,gr_screen.max_w,gr_screen.max_h,0); Multi_ts_window.set_mask_bmap(Multi_ts_bitmap_mask_fname[gr_screen.res]); // load the background bitmap Multi_ts_bitmap = bm_load(Multi_ts_bitmap_fname[gr_screen.res]); if(Multi_ts_bitmap < 0){ // we failed to load the bitmap - this is very bad Int3(); } // create the interface buttons for(idx=0;idx<MULTI_TS_NUM_BUTTONS;idx++){ // create the object if((idx == MULTI_TS_SHIPS_UP) || (idx == MULTI_TS_SHIPS_DOWN)){ Multi_ts_buttons[gr_screen.res][idx].button.create(&Multi_ts_window, "", Multi_ts_buttons[gr_screen.res][idx].x, Multi_ts_buttons[gr_screen.res][idx].y, 1, 1, 1, 1); } else { Multi_ts_buttons[gr_screen.res][idx].button.create(&Multi_ts_window, "", Multi_ts_buttons[gr_screen.res][idx].x, Multi_ts_buttons[gr_screen.res][idx].y, 1, 1, 0, 1); } // set the sound to play when highlighted Multi_ts_buttons[gr_screen.res][idx].button.set_highlight_action(common_play_highlight_sound); // set the ani for the button Multi_ts_buttons[gr_screen.res][idx].button.set_bmaps(Multi_ts_buttons[gr_screen.res][idx].filename); // set the hotspot Multi_ts_buttons[gr_screen.res][idx].button.link_hotspot(Multi_ts_buttons[gr_screen.res][idx].hotspot); } // add some text Multi_ts_window.add_XSTR("Briefing", 765, Multi_ts_buttons[gr_screen.res][MULTI_TS_BRIEFING].xt, Multi_ts_buttons[gr_screen.res][MULTI_TS_BRIEFING].yt, &Multi_ts_buttons[gr_screen.res][MULTI_TS_BRIEFING].button, UI_XSTR_COLOR_GREEN); Multi_ts_window.add_XSTR("Ship Selection", 1067, Multi_ts_buttons[gr_screen.res][MULTI_TS_SHIP_SELECT].xt, Multi_ts_buttons[gr_screen.res][MULTI_TS_SHIP_SELECT].yt, &Multi_ts_buttons[gr_screen.res][MULTI_TS_SHIP_SELECT].button, UI_XSTR_COLOR_GREEN); Multi_ts_window.add_XSTR("Weapon Loadout", 1068, Multi_ts_buttons[gr_screen.res][MULTI_TS_WEAPON_SELECT].xt, Multi_ts_buttons[gr_screen.res][MULTI_TS_WEAPON_SELECT].yt, &Multi_ts_buttons[gr_screen.res][MULTI_TS_WEAPON_SELECT].button, UI_XSTR_COLOR_GREEN); Multi_ts_window.add_XSTR("Commit", 1062, Multi_ts_buttons[gr_screen.res][MULTI_TS_COMMIT].xt, Multi_ts_buttons[gr_screen.res][MULTI_TS_COMMIT].yt, &Multi_ts_buttons[gr_screen.res][MULTI_TS_COMMIT].button, UI_XSTR_COLOR_PINK); Multi_ts_window.add_XSTR("Lock", 1270, Multi_ts_buttons[gr_screen.res][MULTI_TS_LOCK].xt, Multi_ts_buttons[gr_screen.res][MULTI_TS_LOCK].yt, &Multi_ts_buttons[gr_screen.res][MULTI_TS_LOCK].button, UI_XSTR_COLOR_GREEN); // Multi_ts_window.add_XSTR("Help", 928, Multi_ts_buttons[Current_screen-1][gr_screen.res][COMMON_HELP_BUTTON].xt, Multi_ts_buttons[Current_screen-1][gr_screen.res][COMMON_HELP_BUTTON].yt, &Multi_ts_buttons[Current_screen-1][gr_screen.res][COMMON_HELP_BUTTON].button, UI_XSTR_COLOR_GREEN); // Multi_ts_window.add_XSTR("Options", 1036, Multi_ts_buttons[Current_screen-1][gr_screen.res][COMMON_OPTIONS_BUTTON].xt, Multi_ts_buttons[Current_screen-1][gr_screen.res][COMMON_OPTIONS_BUTTON].yt, &Multi_ts_buttons[Current_screen-1][gr_screen.res][COMMON_OPTIONS_BUTTON].button, UI_XSTR_COLOR_GREEN); // make the ship scrolling lists // if we're not the host of the game (or a tema captain in team vs. team mode), disable the lock button if (Netgame.type_flags & NG_TYPE_TEAM) { if(!(Net_player->flags & NETINFO_FLAG_TEAM_CAPTAIN)){ Multi_ts_buttons[gr_screen.res][MULTI_TS_LOCK].button.disable(); } } else { if(!(Net_player->flags & NETINFO_FLAG_GAME_HOST)){ Multi_ts_buttons[gr_screen.res][MULTI_TS_LOCK].button.disable(); } } // initialize the snazzy menu stuff (for grabbing ships, names, etc) multi_ts_init_snazzy(); // create the chatbox (again, should not be necessary at this point) chatbox_create(); // sync the interface as normal multi_ts_sync_interface(); } // blit all of the icons representing all wings void multi_ts_blit_wings() { int idx; // blit them all blindly for now for(idx=0;idx<MAX_WSS_SLOTS;idx++){ // if this ship doesn't exist, then continue if(Multi_ts_team[Net_player->p_info.team].multi_ts_flag[idx] == MULTI_TS_FLAG_NONE){ continue; } // otherwise blit the ship icon or the "empty" icon if(Multi_ts_team[Net_player->p_info.team].multi_ts_flag[idx] == MULTI_TS_FLAG_EMPTY){ ss_blit_ship_icon(Multi_ts_slot_icon_coords[idx][gr_screen.res][MULTI_TS_X_COORD],Multi_ts_slot_icon_coords[idx][gr_screen.res][MULTI_TS_Y_COORD],-1,0); } else { ss_blit_ship_icon(Multi_ts_slot_icon_coords[idx][gr_screen.res][MULTI_TS_X_COORD],Multi_ts_slot_icon_coords[idx][gr_screen.res][MULTI_TS_Y_COORD],Wss_slots[idx].ship_class,multi_ts_slot_bmap_num(idx)); // if this is a team vs team game, and the slot is occupised by a team captain, put a c there if((Netgame.type_flags & NG_TYPE_TEAM) && (Multi_ts_team[Net_player->p_info.team].multi_ts_player[idx] != NULL) && (Multi_ts_team[Net_player->p_info.team].multi_ts_player[idx]->flags & NETINFO_FLAG_TEAM_CAPTAIN)){ gr_set_color_fast(&Color_bright); gr_string(Multi_ts_slot_icon_coords[idx][gr_screen.res][MULTI_TS_X_COORD] - 5,Multi_ts_slot_icon_coords[idx][gr_screen.res][MULTI_TS_Y_COORD] - 5,XSTR("C",737)); // [[ Team captain ]] } } } } // blit all of the player callsigns under the correct ships void multi_ts_blit_wing_callsigns() { int idx,callsign_w; char callsign[CALLSIGN_LEN+2]; p_object *pobj; // blit them all blindly for now for(idx=0;idx<MAX_WSS_SLOTS;idx++){ // if this ship doesn't exist, then continue if(Multi_ts_team[Net_player->p_info.team].multi_ts_flag[idx] == MULTI_TS_FLAG_NONE){ continue; } // if there is a player in the slot if(Multi_ts_team[Net_player->p_info.team].multi_ts_player[idx] != NULL){ // make sure the string fits strcpy(callsign,Multi_ts_team[Net_player->p_info.team].multi_ts_player[idx]->player->callsign); } else { // determine if this is a locked AI ship pobj = mission_parse_get_arrival_ship(Ships[Objects[Multi_ts_team[Net_player->p_info.team].multi_ts_objnum[idx]].instance].ship_name); if((pobj == NULL) || !(pobj->flags & OF_PLAYER_SHIP)){ strcpy(callsign, NOX("<")); strcat(callsign,XSTR("AI",738)); // [[ Artificial Intellegence ]] strcat(callsign, NOX(">")); } else { strcpy(callsign,XSTR("AI",738)); // [[ Artificial Intellegence ]] } } gr_force_fit_string(callsign, CALLSIGN_LEN, Multi_ts_slot_text_coords[idx][gr_screen.res][MULTI_TS_W_COORD]); // get the final length gr_get_string_size(&callsign_w, NULL, callsign); // blit the string if((Multi_ts_hotspot_type == MULTI_TS_PLAYER_LIST) && (Multi_ts_hotspot_index == idx) && (Multi_ts_team[Net_player->p_info.team].multi_ts_player[idx] != NULL)){ gr_set_color_fast(&Color_text_active_hi); } else { gr_set_color_fast(&Color_normal); } gr_string(Multi_ts_slot_text_coords[idx][gr_screen.res][MULTI_TS_X_COORD] + ((Multi_ts_slot_text_coords[idx][gr_screen.res][MULTI_TS_W_COORD] - callsign_w)/2),Multi_ts_slot_text_coords[idx][gr_screen.res][MULTI_TS_Y_COORD],callsign); } } // blit the ships on the avail list void multi_ts_blit_avail_ships() { int display_count,ship_count,idx; char count[6]; // blit the availability of all ship counts display_count = 0; ship_count = 0; for(idx=0;idx<MAX_SHIP_TYPES;idx++){ if(Ss_pool[idx] > 0){ // if our starting display index is after this, then skip it if(ship_count < Multi_ts_avail_start){ ship_count++; } else { // blit the icon ss_blit_ship_icon(Multi_ts_avail_coords[display_count][gr_screen.res][MULTI_TS_X_COORD],Multi_ts_avail_coords[display_count][gr_screen.res][MULTI_TS_Y_COORD],idx,multi_ts_avail_bmap_num(display_count)); // blit the ship count available sprintf(count,"%d",Ss_pool[idx]); gr_set_color_fast(&Color_normal); gr_string(Multi_ts_avail_coords[display_count][gr_screen.res][MULTI_TS_X_COORD] - 20,Multi_ts_avail_coords[display_count][gr_screen.res][MULTI_TS_Y_COORD],count); // increment the counts display_count++; ship_count++; } } // if we've reached the max amount we can display, then stop if(display_count >= MULTI_TS_AVAIL_MAX_DISPLAY){ return; } } } // initialize the snazzy menu stuff for dragging ships,players around void multi_ts_init_snazzy() { // initialize the snazzy menu snazzy_menu_init(); // blast the data Multi_ts_snazzy_regions = 0; memset(Multi_ts_region,0,sizeof(MENU_REGION) * MULTI_TS_NUM_SNAZZY_REGIONS); // get a pointer to the mask bitmap data Multi_ts_mask_data = (ubyte*)Multi_ts_window.get_mask_data(&Multi_ts_mask_w, &Multi_ts_mask_h); // add the wing slots information snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_0_SHIP_0, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_0_SHIP_1, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_0_SHIP_2, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_0_SHIP_3, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_1_SHIP_0, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_1_SHIP_1, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_1_SHIP_2, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_1_SHIP_3, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_2_SHIP_0, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_2_SHIP_1, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_2_SHIP_2, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_2_SHIP_3, 0); // add the name slots information snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_0_NAME_0, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_0_NAME_1, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_0_NAME_2, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_0_NAME_3, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_1_NAME_0, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_1_NAME_1, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_1_NAME_2, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_1_NAME_3, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_2_NAME_0, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_2_NAME_1, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_2_NAME_2, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_2_NAME_3, 0); // add the available ships region snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_LIST_0, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_LIST_1, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_LIST_2, 0); snazzy_menu_add_region(&Multi_ts_region[Multi_ts_snazzy_regions++], "", TSWING_LIST_3, 0); } // what type of region the index is (0 == ship avail list, 1 == ship slots, 2 == player slot) int multi_ts_region_type(int region) { if((region == TSWING_0_SHIP_0) || (region == TSWING_0_SHIP_1) || (region == TSWING_0_SHIP_2) || (region == TSWING_0_SHIP_3) || (region == TSWING_1_SHIP_0) || (region == TSWING_1_SHIP_1) || (region == TSWING_1_SHIP_2) || (region == TSWING_1_SHIP_3) || (region == TSWING_2_SHIP_0) || (region == TSWING_2_SHIP_1) || (region == TSWING_2_SHIP_2) || (region == TSWING_2_SHIP_3) ){ return MULTI_TS_SLOT_LIST; } if((region == TSWING_0_NAME_0) || (region == TSWING_0_NAME_1) || (region == TSWING_0_NAME_2) || (region == TSWING_0_NAME_3) || (region == TSWING_1_NAME_0) || (region == TSWING_1_NAME_1) || (region == TSWING_1_NAME_2) || (region == TSWING_1_NAME_3) || (region == TSWING_2_NAME_0) || (region == TSWING_2_NAME_1) || (region == TSWING_2_NAME_2) || (region == TSWING_2_NAME_3) ){ return MULTI_TS_PLAYER_LIST; } if((region == TSWING_LIST_0) || (region == TSWING_LIST_1) || (region == TSWING_LIST_2) || (region == TSWING_LIST_3)){ return MULTI_TS_AVAIL_LIST; } return -1; } // convert the region num to a ship slot index int multi_ts_slot_index(int region) { switch(region){ case TSWING_0_SHIP_0: return 0; case TSWING_0_SHIP_1: return 1; case TSWING_0_SHIP_2: return 2; case TSWING_0_SHIP_3: return 3; case TSWING_1_SHIP_0: return 4; case TSWING_1_SHIP_1: return 5; case TSWING_1_SHIP_2: return 6; case TSWING_1_SHIP_3: return 7; case TSWING_2_SHIP_0: return 8; case TSWING_2_SHIP_1: return 9; case TSWING_2_SHIP_2: return 10; case TSWING_2_SHIP_3: return 11; } return -1; } // convert the region num to an avail list index (starting from absolute 0) int multi_ts_avail_index(int region) { switch(region){ case TSWING_LIST_0: return 0; case TSWING_LIST_1: return 1; case TSWING_LIST_2: return 2; case TSWING_LIST_3: return 3; } return -1; } // convert the region num to a player slot index int multi_ts_player_index(int region) { switch(region){ case TSWING_0_NAME_0: return 0; case TSWING_0_NAME_1: return 1; case TSWING_0_NAME_2: return 2; case TSWING_0_NAME_3: return 3; case TSWING_1_NAME_0: return 4; case TSWING_1_NAME_1: return 5; case TSWING_1_NAME_2: return 6; case TSWING_1_NAME_3: return 7; case TSWING_2_NAME_0: return 8; case TSWING_2_NAME_1: return 9; case TSWING_2_NAME_2: return 10; case TSWING_2_NAME_3: return 11; } return -1; } // blit any active ship information text void multi_ts_blit_ship_info() { int y_start; ship_info *sip; char str[100]; // if we don't have a valid ship selected, do nothing if(Multi_ts_select_ship_class == -1){ return; } // get the ship class sip = &Ship_info[Multi_ts_select_ship_class]; // starting line y_start = Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_Y_COORD]; memset(str,0,100); // blit the ship class (name) gr_set_color_fast(&Color_normal); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD], y_start,XSTR("Class",739)); if(strlen(sip->name)){ gr_set_color_fast(&Color_bright); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD] + 150, y_start,sip->name); } y_start += 10; // blit the ship type gr_set_color_fast(&Color_normal); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD], y_start,XSTR("Type",740)); if((sip->type_str != NULL) && strlen(sip->type_str)){ gr_set_color_fast(&Color_bright); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD] + 150, y_start,sip->type_str); } y_start += 10; // blit the ship length gr_set_color_fast(&Color_normal); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD], y_start,XSTR("Length",741)); if((sip->ship_length != NULL) && strlen(sip->ship_length)){ gr_set_color_fast(&Color_bright); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD] + 150, y_start,sip->ship_length); } y_start += 10; // blit the max velocity gr_set_color_fast(&Color_normal); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD], y_start,XSTR("Max Velocity",742)); sprintf(str,XSTR("%d m/s",743),(int)sip->max_vel.z); gr_set_color_fast(&Color_bright); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD] + 150, y_start,str); y_start += 10; // blit the maneuverability gr_set_color_fast(&Color_normal); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD], y_start,XSTR("Maneuverability",744)); if((sip->maneuverability_str != NULL) && strlen(sip->maneuverability_str)){ gr_set_color_fast(&Color_bright); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD] + 150, y_start,sip->maneuverability_str); } y_start += 10; // blit the armor gr_set_color_fast(&Color_normal); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD], y_start,XSTR("Armor",745)); if((sip->armor_str != NULL) && strlen(sip->armor_str)){ gr_set_color_fast(&Color_bright); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD] + 150, y_start,sip->armor_str); } y_start += 10; // blit the gun mounts gr_set_color_fast(&Color_normal); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD], y_start,XSTR("Gun Mounts",746)); if((sip->gun_mounts != NULL) && strlen(sip->gun_mounts)){ gr_set_color_fast(&Color_bright); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD] + 150, y_start,sip->gun_mounts); } y_start += 10; // blit the missile banke gr_set_color_fast(&Color_normal); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD], y_start,XSTR("Missile Banks",747)); if((sip->missile_banks != NULL) && strlen(sip->missile_banks)){ gr_set_color_fast(&Color_bright); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD] + 150, y_start,sip->missile_banks); } y_start += 10; // blit the manufacturer gr_set_color_fast(&Color_normal); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD], y_start,XSTR("Manufacturer",748)); if((sip->manufacturer_str != NULL) && strlen(sip->manufacturer_str)){ gr_set_color_fast(&Color_bright); gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD] + 150, y_start,sip->manufacturer_str); } y_start += 10; // blit the _short_ text description /* Assert(Multi_ts_ship_info_line_count < 3); gr_set_color_fast(&Color_normal); for(idx=0;idx<Multi_ts_ship_info_line_count;idx++){ gr_string(Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_X_COORD], y_start, Multi_ts_ship_info_lines[idx]); y_start += 10; } */ } // blit the status bar void multi_ts_blit_status_bar() { char text[50]; int text_w; int blit = 0; // mode specific text switch(Multi_ts_status_bar_mode){ case 0 : strcpy(text,XSTR("Ships/Weapons Locked",749)); blit = 1; break; case 1 : strcpy(text,XSTR("Ships/Weapons Are Now Free",750)); blit = 1; break; } // if we should be blitting if(blit){ gr_get_string_size(&text_w,NULL,text); gr_set_color_fast(&Color_bright_blue); gr_string(Multi_ts_status_coords[gr_screen.res][MULTI_TS_X_COORD] + ((Multi_ts_status_coords[gr_screen.res][MULTI_TS_W_COORD] - text_w)/2),Multi_ts_status_coords[gr_screen.res][MULTI_TS_Y_COORD],text); } } // assign the correct players to the correct slots void multi_ts_init_players() { int idx; // if i'm an observer, i have no ship if(Net_player->flags & NETINFO_FLAG_OBSERVER){ Net_player->p_info.ship_index = -1; } // initialize all players and observer for(idx=0;idx<MAX_PLAYERS;idx++){ if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx])){ if(MULTI_OBSERVER(Net_players[idx])){ Net_players[idx].p_info.ship_index = -1; } else { Multi_ts_team[Net_players[idx].p_info.team].multi_ts_player[Net_players[idx].p_info.ship_index] = &Net_players[idx]; } } } } // assign the correct objnums to the correct slots void multi_ts_init_objnums() { int idx,s_idx,team_index,slot_index; object *objp; // zero out the indices for(idx=0;idx<MULTI_TS_MAX_TEAMS;idx++){ for(s_idx=0;s_idx<MULTI_TS_NUM_SHIP_SLOTS;s_idx++){ Multi_ts_team[idx].multi_ts_objnum[s_idx] = -1; } } // set all the objnums objp = GET_FIRST(&obj_used_list); while(objp != END_OF_LIST(&obj_used_list)){ // if its a ship, get its slot index (if any) if(objp->type == OBJ_SHIP){ multi_ts_get_team_and_slot(Ships[objp->instance].ship_name,&team_index,&slot_index); if((slot_index != -1) && (team_index != -1)){ Multi_ts_team[team_index].multi_ts_objnum[slot_index] = Ships[objp->instance].objnum; } } objp = GET_NEXT(objp); } } // get the proper team and slot index for the given ship name void multi_ts_get_team_and_slot(char *ship_name,int *team_index,int *slot_index) { int idx,s_idx; // set the return values to default values *team_index = -1; *slot_index = -1; // if we're in team vs. team mode if(Netgame.type_flags & NG_TYPE_TEAM){ for(idx=0;idx<MULTI_TS_MAX_TEAMS;idx++){ for(s_idx=0;s_idx<MULTI_TS_NUM_SHIP_SLOTS_TEAM;s_idx++){ if(!stricmp(ship_name,Multi_ts_slot_team_names[idx][s_idx])){ *team_index = idx; *slot_index = s_idx; return; } } } } // if we're _not_ in team vs. team mode else { for(idx=0;idx<MULTI_TS_NUM_SHIP_SLOTS;idx++){ if(!stricmp(ship_name,Multi_ts_slot_names[idx])){ *team_index = 0; *slot_index = idx; return; } } } } // function to return the shipname of the ship in the slot designated by the team and slot // parameters char *multi_ts_get_shipname( int team, int slot_index ) { if ( Netgame.type_flags & NG_TYPE_TEAM ) { Assert( (team >= 0) && (team < MULTI_TS_MAX_TEAMS) ); return Multi_ts_slot_team_names[team][slot_index]; } else { Assert( team == 0 ); return Multi_ts_slot_names[slot_index]; } } // assign the correct flags to the correct slots void multi_ts_init_flags() { int idx,s_idx; // zero out the flags for(idx=0;idx<MULTI_TS_MAX_TEAMS;idx++){ for(s_idx=0;s_idx<MULTI_TS_NUM_SHIP_SLOTS;s_idx++){ Multi_ts_team[idx].multi_ts_flag[s_idx] = MULTI_TS_FLAG_NONE; } } // in a team vs. team situation if(Netgame.type_flags & NG_TYPE_TEAM){ for(idx=0;idx<MULTI_TS_MAX_TEAMS;idx++){ for(s_idx=0;s_idx<MULTI_TS_NUM_SHIP_SLOTS_TEAM;s_idx++){ // if the there is an objnum here but no ship class, we know its currently empty if((Multi_ts_team[idx].multi_ts_objnum[s_idx] != -1) && (Wss_slots_teams[idx][s_idx].ship_class == -1)){ Multi_ts_team[idx].multi_ts_flag[s_idx] = MULTI_TS_FLAG_EMPTY; } else if((Multi_ts_team[idx].multi_ts_objnum[s_idx] != -1) && (Wss_slots_teams[idx][s_idx].ship_class != -1)){ Multi_ts_team[idx].multi_ts_flag[s_idx] = Wss_slots_teams[idx][s_idx].ship_class; } } } } // in a non team vs. team situation else { for(idx=0;idx<MULTI_TS_NUM_SHIP_SLOTS;idx++){ // if the there is an objnum here but no ship class, we know its currently empty if((Multi_ts_team[0].multi_ts_objnum[idx] != -1) && (Wss_slots[idx].ship_class == -1)){ Multi_ts_team[0].multi_ts_flag[idx] = MULTI_TS_FLAG_EMPTY; } else if((Multi_ts_team[0].multi_ts_objnum[idx] != -1) && (Wss_slots[idx].ship_class != -1)){ Multi_ts_team[0].multi_ts_flag[idx] = Wss_slots[idx].ship_class; } } } } // handle an available ship scroll down button press void multi_ts_avail_scroll_down() { if((Multi_ts_avail_count - Multi_ts_avail_start) > MULTI_TS_AVAIL_MAX_DISPLAY){ gamesnd_play_iface(SND_USER_SELECT); Multi_ts_avail_start++; } else { gamesnd_play_iface(SND_GENERAL_FAIL); } } // handle an available ship scroll up button press void multi_ts_avail_scroll_up() { if(Multi_ts_avail_start > 0){ gamesnd_play_iface(SND_USER_SELECT); Multi_ts_avail_start--; } else { gamesnd_play_iface(SND_GENERAL_FAIL); } } // handle all mouse events (clicking, dragging, and dropping) void multi_ts_handle_mouse() { int snazzy_region,snazzy_action; int region_type,region_index,region_empty; int mouse_x,mouse_y,ship_class; // get the mouse coords mouse_get_pos(&mouse_x,&mouse_y); // do frame for the snazzy menu snazzy_region = snazzy_menu_do(Multi_ts_mask_data, Multi_ts_mask_w, Multi_ts_mask_h, Multi_ts_snazzy_regions, Multi_ts_region, &snazzy_action, 0); region_type = -1; region_index = -1; region_empty = 1; ship_class = -1; if(snazzy_region != -1){ region_type = multi_ts_region_type(snazzy_region); Assert(region_type != -1); // determine what type of region the mouse is over and the appropriate index switch(region_type){ case MULTI_TS_AVAIL_LIST: region_index = multi_ts_avail_index(snazzy_region); ship_class = multi_ts_get_avail_ship_class(region_index); if(ship_class == -1){ region_empty = 1; } else { region_empty = (Ss_pool[ship_class] > 0) ? 0 : 1; } break; case MULTI_TS_SLOT_LIST: region_index = multi_ts_slot_index(snazzy_region); region_empty = (Multi_ts_team[Net_player->p_info.team].multi_ts_flag[region_index] >= 0) ? 0 : 1; if(!region_empty){ ship_class = Wss_slots[region_index].ship_class; } break; case MULTI_TS_PLAYER_LIST: region_index = multi_ts_player_index(snazzy_region); region_empty = (Multi_ts_team[Net_player->p_info.team].multi_ts_player[region_index] != NULL) ? 0 : 1; break; } } // maybe play a "highlight" sound switch(region_type){ case MULTI_TS_PLAYER_LIST: if((Multi_ts_hotspot_index != region_index) && (region_index >= 0) && (Multi_ts_team[Net_player->p_info.team].multi_ts_player[region_index] != NULL)){ gamesnd_play_iface(SND_USER_SELECT); } break; } // set the current frame mouse hotspot vars Multi_ts_hotspot_type = region_type; Multi_ts_hotspot_index = region_index; // if we currently have clicked on something and have just released it if(!Multi_ts_carried_flag && Multi_ts_clicked_flag && !mouse_down(MOUSE_LEFT_BUTTON)){ Multi_ts_clicked_flag = 0; } // if we're currently not carrying anything and the user has clicked if(!Multi_ts_carried_flag && !Multi_ts_clicked_flag && mouse_down(MOUSE_LEFT_BUTTON) && !region_empty){ // set the "clicked" flag Multi_ts_clicked_flag = 1; // check to see if he clicked on a ship type and highlight if necessary switch(region_type){ // selected a ship in the wing slots case MULTI_TS_SLOT_LIST: Multi_ts_select_type = MULTI_TS_SLOT_LIST; Multi_ts_select_index = region_index; multi_ts_select_ship(); break; // selected a ship on the avail list case MULTI_TS_AVAIL_LIST: Multi_ts_select_type = MULTI_TS_AVAIL_LIST; Multi_ts_select_index = region_index; multi_ts_select_ship(); break; // selected something else - unselect default : Multi_ts_select_type = -1; Multi_ts_select_index = -1; Multi_ts_select_ship_class = -1; break; } Multi_ts_clicked_x = mouse_x; Multi_ts_clicked_y = mouse_y; } // if we had something clicked and have started dragging it if(!Multi_ts_carried_flag && Multi_ts_clicked_flag && mouse_down(MOUSE_LEFT_BUTTON) && ((Multi_ts_clicked_x != mouse_x) || (Multi_ts_clicked_y != mouse_y))){ // if this player is an observer, he shouldn't be able to do jack if(Net_player->flags & NETINFO_FLAG_OBSERVER){ return; } // first we check for illegal conditions (any case where he cannot grab what he is attempting to grab) switch(region_type){ case MULTI_TS_AVAIL_LIST : // if players are not yet locked, can't grab ships if(!Multi_ts_team[Net_player->p_info.team].multi_players_locked){ return; } if(region_empty){ return; } break; case MULTI_TS_SLOT_LIST: // if players are not yet locked, can't grab ships if(!Multi_ts_team[Net_player->p_info.team].multi_players_locked){ return; } if(multi_ts_disabled_slot(region_index)){ multi_ts_maybe_host_only_popup(); return; } if(Multi_ts_team[Net_player->p_info.team].multi_ts_flag[region_index] < 0){ return; } break; case MULTI_TS_PLAYER_LIST: if(!multi_ts_can_grab_player(region_index)){ return; } break; } Multi_ts_clicked_flag = 0; Multi_ts_carried_flag = 1; // set up the carried icon here Multi_ts_carried_from_type = region_type; Multi_ts_carried_from_index = region_index; Multi_ts_carried_ship_class = ship_class; } // if we were carrying something but have dropped it if(Multi_ts_carried_flag && !mouse_down(MOUSE_LEFT_BUTTON)){ Multi_ts_carried_flag = 0; Multi_ts_clicked_flag = 0; // if we're not allowed to drop onto this slot if((region_type == MULTI_TS_SLOT_LIST) && multi_ts_disabled_slot(region_index)){ multi_ts_maybe_host_only_popup(); } // if we're over some kind of valid region, apply multi_ts_drop(Multi_ts_carried_from_type,Multi_ts_carried_from_index,region_type,region_index,Multi_ts_carried_ship_class); } } // can the specified player perform the action he is attempting int multi_ts_can_perform(int from_type,int from_index,int to_type,int to_index,int ship_class,int player_index) { net_player *pl; int op_type; p_object *pobj; // get the appropriate player if(player_index == -1){ pl = Net_player; } else { pl = &Net_players[player_index]; } // get the operation type op_type = multi_ts_get_dnd_type(from_type,from_index,to_type,to_index,player_index); // if either of the indices are bogus, then bail if((from_index == -1) || (to_index == -1)){ return 0; } switch(op_type){ case TS_GRAB_FROM_LIST: // if there are no more of this ship class, its no go if(Ss_pool_teams[pl->p_info.team][ship_class] <= 0){ return 0; } // if he's not allowed to touch the wing slot if(multi_ts_disabled_slot(to_index,player_index)){ return 0; } // if the slot he's trying to drop it on is "permanently" empty if(Multi_ts_team[pl->p_info.team].multi_ts_flag[to_index] == MULTI_TS_FLAG_NONE){ return 0; } break; case TS_SWAP_LIST_SLOT: // if there are no more of this ship class, its no go if(Ss_pool_teams[pl->p_info.team][ship_class] <= 0){ return 0; } // if he's not allowed to touch the wing slot if(multi_ts_disabled_slot(to_index,player_index)){ return 0; } // if the slot we're trying to move to is invalid, then do nothing if(Multi_ts_team[pl->p_info.team].multi_ts_flag[to_index] == MULTI_TS_FLAG_NONE){ return 0; } // if the slot he's trying to drop it on is "permanently" empty if(Multi_ts_team[pl->p_info.team].multi_ts_flag[to_index] == MULTI_TS_FLAG_NONE){ return 0; } break; case TS_SWAP_SLOT_SLOT: // if he's not allowed to touch one of the slots, its no go if(multi_ts_disabled_slot(from_index,player_index) || multi_ts_disabled_slot(to_index,player_index)){ return 0; } // if the slot we're taking from is invalid if(Multi_ts_team[pl->p_info.team].multi_ts_flag[to_index] == MULTI_TS_FLAG_NONE){ return 0; } // if the slot he's trying to drop it on is "permanently" empty if(Multi_ts_team[pl->p_info.team].multi_ts_flag[to_index] == MULTI_TS_FLAG_NONE){ return 0; } break; case TS_DUMP_TO_LIST: // if he's not allowed to be touching the slot to begin with, it no go if(multi_ts_disabled_slot(from_index,player_index)){ return 0; } // if the slot we're trying to move to is invalid, then do nothing if(Multi_ts_team[pl->p_info.team].multi_ts_flag[to_index] == MULTI_TS_FLAG_NONE){ return 0; } break; case TS_SWAP_PLAYER_PLAYER: // if his team is already locked, he cannot do this if(Multi_ts_team[pl->p_info.team].multi_players_locked){ return 0; } // if there isn't a player at one of the positions if((Multi_ts_team[pl->p_info.team].multi_ts_player[from_index] == NULL) || (Multi_ts_team[pl->p_info.team].multi_ts_player[to_index] == NULL)){ return 0; } // if this is not a player ship type object if(Multi_ts_team[pl->p_info.team].multi_ts_objnum[to_index] != -1){ pobj = mission_parse_get_arrival_ship(Ships[Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[to_index]].instance].ship_name); if((pobj == NULL) || !(pobj->flags & OF_PLAYER_SHIP)){ return 0; } } if(Netgame.type_flags & NG_TYPE_TEAM){ // if he's not the team captain, he cannot do this if(!(pl->flags & NETINFO_FLAG_TEAM_CAPTAIN)){ return 0; } } else { // if he's not the host, he cannot do this if(!(pl->flags & NETINFO_FLAG_GAME_HOST)){ return 0; } } break; case TS_MOVE_PLAYER: // if his team is already locked, he cannot do this if(Multi_ts_team[pl->p_info.team].multi_players_locked){ return 0; } // if there isn't a player at the _from_ if(Multi_ts_team[pl->p_info.team].multi_ts_player[from_index] == NULL){ return 0; } // if there is no ship at the _to_ location if(Multi_ts_team[pl->p_info.team].multi_ts_objnum[to_index] < 0){ return 0; } // if this is not a player ship type object if(Multi_ts_team[pl->p_info.team].multi_ts_objnum[to_index] != -1){ pobj = mission_parse_get_arrival_ship(Ships[Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[to_index]].instance].ship_name); if((pobj == NULL) || !(pobj->flags & OF_PLAYER_SHIP)){ return 0; } } if(Netgame.type_flags & NG_TYPE_TEAM){ // if he's not the team captain, he cannot do this if(!(pl->flags & NETINFO_FLAG_TEAM_CAPTAIN)){ return 0; } } else { // if he's not the host, he cannot do this if(!(pl->flags & NETINFO_FLAG_GAME_HOST)){ return 0; } } break; default : return 0; break; } return 1; } // determine the kind of drag and drop operation this is int multi_ts_get_dnd_type(int from_type,int from_index,int to_type,int to_index,int player_index) { net_player *pl; // get the appropriate player if(player_index == -1){ pl = Net_player; } else { pl = &Net_players[player_index]; } switch(from_type){ // came from the ship avail list case MULTI_TS_AVAIL_LIST : // do nothing if(to_type == MULTI_TS_AVAIL_LIST){ return -1; } // if placing it on a slot if(to_type == MULTI_TS_SLOT_LIST){ if(Wss_slots_teams[pl->p_info.team][to_index].ship_class == -1){ return TS_GRAB_FROM_LIST; } else { return TS_SWAP_LIST_SLOT; } } break; // came from the ship slots case MULTI_TS_SLOT_LIST : if(to_type == MULTI_TS_SLOT_LIST){ return TS_SWAP_SLOT_SLOT; } if(to_type == MULTI_TS_AVAIL_LIST){ return TS_DUMP_TO_LIST; } break; // came from the player lists case MULTI_TS_PLAYER_LIST : if(to_type == MULTI_TS_PLAYER_LIST){ if(Multi_ts_team[pl->p_info.team].multi_ts_player[to_index] == NULL){ return TS_MOVE_PLAYER; } else { return TS_SWAP_PLAYER_PLAYER; } } break; } return -1; } void multi_ts_apply(int from_type,int from_index,int to_type,int to_index,int ship_class,int player_index) { int size,update,sound; ubyte wss_data[MAX_PACKET_SIZE-20]; net_player *pl; // determine what kind of operation this is int type = multi_ts_get_dnd_type(from_type,from_index,to_type,to_index,player_index); // get the proper net player if(player_index == -1){ pl = Net_player; } else { pl = &Net_players[player_index]; } // set the proper pool pointers ss_set_team_pointers(pl->p_info.team); sound = -1; switch(type){ case TS_SWAP_SLOT_SLOT : nprintf(("Network","Apply swap slot slot %d %d\n",from_index,to_index)); update = ss_swap_slot_slot(from_index,to_index,&sound); break; case TS_DUMP_TO_LIST : nprintf(("Network","Apply dump to list %d %d\n",from_index,to_index)); update = ss_dump_to_list(from_index,ship_class,&sound); break; case TS_SWAP_LIST_SLOT : nprintf(("Network","Apply swap list slot %d %d\n",from_index,to_index)); update = ss_swap_list_slot(ship_class,to_index,&sound); break; case TS_GRAB_FROM_LIST : nprintf(("Network","Apply grab from list %d %d\n",from_index,to_index)); update = ss_grab_from_list(ship_class,to_index,&sound); break; case TS_SWAP_PLAYER_PLAYER : nprintf(("Network","Apply swap player player %d %d\n",from_index,to_index)); update = multi_ts_swap_player_player(from_index,to_index,&sound,player_index); break; case TS_MOVE_PLAYER : nprintf(("Network","Apply move player %d %d\n",from_index,to_index)); update = multi_ts_move_player(from_index,to_index,&sound,player_index); default : update = 0; break; } if(update){ // if we're the host, send an update to all players if ( MULTIPLAYER_HOST ) { // send the correct type of update if(type == TS_SWAP_PLAYER_PLAYER){ } else { size = store_wss_data(wss_data, MAX_PACKET_SIZE-20, sound, player_index); send_wss_update_packet(pl->p_info.team,wss_data, size); // send a player slot update packet as well, so ship class information, etc is kept correct send_pslot_update_packet(pl->p_info.team,TS_CODE_PLAYER_UPDATE,-1); } // if the player index == -1, it means the action was done locally - so play a sound if((player_index == -1) && (sound != -1)){ gamesnd_play_iface(sound); } } // sync the interface screen up ourselves, if necessary if(Net_player->p_info.team == pl->p_info.team){ multi_ts_sync_interface(); } // make sure all flags are set properly for all teams multi_ts_init_flags(); } // set the proper pool pointers ss_set_team_pointers(Net_player->p_info.team); } // drop a carried icon void multi_ts_drop(int from_type,int from_index,int to_type,int to_index,int ship_class,int player_index) { // if I'm the host, apply immediately if(Net_player->flags & NETINFO_FLAG_GAME_HOST){ // if this is a legal operation if(multi_ts_can_perform(from_type,from_index,to_type,to_index,ship_class,player_index)){ multi_ts_apply(from_type,from_index,to_type,to_index,ship_class,player_index); } else { nprintf(("Network","Could not apply operation!\n")); } } // otherwise send a request to the host else { send_wss_request_packet(Net_player->player_id, from_type, from_index, to_type, to_index, -1, ship_class, WSS_SHIP_SELECT); } } // swap two player positions int multi_ts_swap_player_player(int from_index,int to_index,int *sound,int player_index) { net_player *pl,*temp; // get the proper player pointer if(player_index == -1){ pl = Net_player; } else { pl = &Net_players[player_index]; } // swap the players temp = Multi_ts_team[pl->p_info.team].multi_ts_player[to_index]; Multi_ts_team[pl->p_info.team].multi_ts_player[to_index] = Multi_ts_team[pl->p_info.team].multi_ts_player[from_index]; Multi_ts_team[pl->p_info.team].multi_ts_player[from_index] = temp; // update netplayer information if necessary if(Multi_ts_team[pl->p_info.team].multi_ts_player[from_index] != NULL){ Multi_ts_team[pl->p_info.team].multi_ts_player[from_index]->p_info.ship_index = from_index; Multi_ts_team[pl->p_info.team].multi_ts_player[from_index]->p_info.ship_class = Wss_slots_teams[pl->p_info.team][from_index].ship_class; multi_assign_player_ship(NET_PLAYER_INDEX(Multi_ts_team[pl->p_info.team].multi_ts_player[from_index]),&Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[from_index]],Wss_slots_teams[pl->p_info.team][from_index].ship_class); } if(Multi_ts_team[pl->p_info.team].multi_ts_player[to_index] != NULL){ Multi_ts_team[pl->p_info.team].multi_ts_player[to_index]->p_info.ship_index = to_index; Multi_ts_team[pl->p_info.team].multi_ts_player[to_index]->p_info.ship_class = Wss_slots_teams[pl->p_info.team][to_index].ship_class; multi_assign_player_ship(NET_PLAYER_INDEX(Multi_ts_team[pl->p_info.team].multi_ts_player[to_index]),&Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[to_index]],Wss_slots_teams[pl->p_info.team][to_index].ship_class); } // update ship flags Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[to_index]].flags &= ~(OF_COULD_BE_PLAYER); Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[to_index]].flags &= ~(OF_PLAYER_SHIP); if(Multi_ts_team[pl->p_info.team].multi_ts_player[to_index] != NULL){ Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[to_index]].flags |= OF_PLAYER_SHIP; } Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[from_index]].flags &= ~(OF_COULD_BE_PLAYER); Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[from_index]].flags &= ~(OF_PLAYER_SHIP); if(Multi_ts_team[pl->p_info.team].multi_ts_player[from_index] != NULL){ Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[from_index]].flags |= OF_PLAYER_SHIP; } // recalcalate which slots are locked/unlocked, etc ss_recalc_multiplayer_slots(); // send an update packet to all players if(Net_player->flags & NETINFO_FLAG_GAME_HOST){ send_pslot_update_packet(pl->p_info.team,TS_CODE_PLAYER_UPDATE,SND_ICON_DROP_ON_WING); gamesnd_play_iface(SND_ICON_DROP_ON_WING); } *sound = SND_ICON_DROP; return 1; } // move a player int multi_ts_move_player(int from_index,int to_index,int *sound,int player_index) { net_player *pl; // get the proper player pointer if(player_index == -1){ pl = Net_player; } else { pl = &Net_players[player_index]; } // swap the players Multi_ts_team[pl->p_info.team].multi_ts_player[to_index] = Multi_ts_team[pl->p_info.team].multi_ts_player[from_index]; Multi_ts_team[pl->p_info.team].multi_ts_player[from_index] = NULL; // update netplayer information if necessary if(Multi_ts_team[pl->p_info.team].multi_ts_player[from_index] != NULL){ Multi_ts_team[pl->p_info.team].multi_ts_player[from_index]->p_info.ship_index = from_index; Multi_ts_team[pl->p_info.team].multi_ts_player[from_index]->p_info.ship_class = Wss_slots_teams[pl->p_info.team][from_index].ship_class; multi_assign_player_ship(NET_PLAYER_INDEX(Multi_ts_team[pl->p_info.team].multi_ts_player[from_index]),&Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[from_index]],Wss_slots_teams[pl->p_info.team][from_index].ship_class); } if(Multi_ts_team[pl->p_info.team].multi_ts_player[to_index] != NULL){ Multi_ts_team[pl->p_info.team].multi_ts_player[to_index]->p_info.ship_index = to_index; Multi_ts_team[pl->p_info.team].multi_ts_player[to_index]->p_info.ship_class = Wss_slots_teams[pl->p_info.team][to_index].ship_class; multi_assign_player_ship(NET_PLAYER_INDEX(Multi_ts_team[pl->p_info.team].multi_ts_player[to_index]),&Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[to_index]],Wss_slots_teams[pl->p_info.team][to_index].ship_class); } // update ship flags Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[to_index]].flags &= ~(OF_COULD_BE_PLAYER); Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[to_index]].flags &= ~(OF_PLAYER_SHIP); if(Multi_ts_team[pl->p_info.team].multi_ts_player[to_index] != NULL){ Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[to_index]].flags |= OF_PLAYER_SHIP; } Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[from_index]].flags &= ~(OF_COULD_BE_PLAYER); Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[from_index]].flags &= ~(OF_PLAYER_SHIP); if(Multi_ts_team[pl->p_info.team].multi_ts_player[from_index] != NULL){ Objects[Multi_ts_team[pl->p_info.team].multi_ts_objnum[from_index]].flags |= OF_PLAYER_SHIP; } // recalcalate which slots are locked/unlocked, etc ss_recalc_multiplayer_slots(); // send an update packet to all players if(Net_player->flags & NETINFO_FLAG_GAME_HOST){ send_pslot_update_packet(pl->p_info.team,TS_CODE_PLAYER_UPDATE,SND_ICON_DROP_ON_WING); gamesnd_play_iface(SND_ICON_DROP_ON_WING); } *sound = SND_ICON_DROP; return 1; } // get the ship class of the current index in the avail list or -1 if none exists int multi_ts_get_avail_ship_class(int index) { int ship_count,class_index; ship_count = index + Multi_ts_avail_start; class_index = 0; while((ship_count >= 0) && (class_index < MAX_SHIP_TYPES)){ if(Ss_pool[class_index] > 0){ ship_count--; } if(ship_count >= 0){ class_index++; } } if(ship_count < 0){ return class_index; } return -1; } // blit the currently carried icon (if any) void multi_ts_blit_carried_icon() { int x,y; int offset_x,offset_y,callsign_w; char callsign[CALLSIGN_LEN+2]; // if we're not carrying anything, then return if(!Multi_ts_carried_flag){ return; } // get the mouse position mouse_get_pos(&x,&y); // if we're carrying an icon of some kind switch(Multi_ts_carried_from_type){ case MULTI_TS_SLOT_LIST: offset_x = Multi_ts_slot_icon_coords[Multi_ts_carried_from_index][gr_screen.res][MULTI_TS_X_COORD] - Multi_ts_clicked_x; offset_y = Multi_ts_slot_icon_coords[Multi_ts_carried_from_index][gr_screen.res][MULTI_TS_Y_COORD] - Multi_ts_clicked_y; // blit the icon ss_blit_ship_icon(x + offset_x,y + offset_y,Multi_ts_carried_ship_class,0); break; case MULTI_TS_AVAIL_LIST: offset_x = Multi_ts_avail_coords[Multi_ts_carried_from_index][gr_screen.res][MULTI_TS_X_COORD] - Multi_ts_clicked_x; offset_y = Multi_ts_avail_coords[Multi_ts_carried_from_index][gr_screen.res][MULTI_TS_Y_COORD] - Multi_ts_clicked_y; // blit the icon ss_blit_ship_icon(x + offset_x,y + offset_y,Multi_ts_carried_ship_class,0); break; case MULTI_TS_PLAYER_LIST: // get the final length of the string so we can calculate a valid offset strcpy(callsign,Multi_ts_team[Net_player->p_info.team].multi_ts_player[Multi_ts_carried_from_index]->player->callsign); gr_force_fit_string(callsign,CALLSIGN_LEN,Multi_ts_slot_text_coords[Multi_ts_carried_from_index][gr_screen.res][MULTI_TS_W_COORD]); gr_get_string_size(&callsign_w,NULL,callsign); // calculate the offsets offset_x = (Multi_ts_slot_text_coords[Multi_ts_carried_from_index][gr_screen.res][MULTI_TS_X_COORD] - Multi_ts_clicked_x) + ((Multi_ts_slot_text_coords[Multi_ts_carried_from_index][gr_screen.res][MULTI_TS_W_COORD] - callsign_w)/2); offset_y = Multi_ts_slot_text_coords[Multi_ts_carried_from_index][gr_screen.res][MULTI_TS_Y_COORD] - Multi_ts_clicked_y; gr_set_color_fast(&Color_normal); gr_string(x + offset_x,y + offset_y,Multi_ts_team[Net_player->p_info.team].multi_ts_player[Multi_ts_carried_from_index]->player->callsign); break; default : break; } } // if the (console) player is allowed to grab a player slot at this point int multi_ts_can_grab_player(int slot_index, int player_index) { net_player *pl; // get a pointe rto the proper net player if(player_index == -1){ pl = Net_player; } else { pl = &Net_players[player_index]; } // if the players are locked in any case, he annot grab it if(Multi_ts_team[pl->p_info.team].multi_players_locked){ return 0; } if(Netgame.type_flags & NG_TYPE_TEAM){ // if he's not the team captain, he cannot do this if(!(pl->flags & NETINFO_FLAG_TEAM_CAPTAIN)){ return 0; } } else { // if he's not the host, he cannot do this if(!(pl->flags & NETINFO_FLAG_GAME_HOST)){ return 0; } } // if the slot is empty if(Multi_ts_team[pl->p_info.team].multi_ts_player[slot_index] == NULL){ return 0; } return 1; } // get the team # of the given ship int multi_ts_get_team(char *ship_name) { int idx,s_idx; // lookup through all team ship names for(idx=0;idx<MULTI_TS_MAX_TEAMS;idx++){ for(s_idx=0;s_idx<MULTI_TS_NUM_SHIP_SLOTS_TEAM;s_idx++){ if(!stricmp(ship_name,Multi_ts_slot_team_names[idx][s_idx])){ return idx; } } } // always on team 0 if not found otherwise return 0; } // return the bitmap index into the ships icon array (in ship select) which should be displayed for the given slot int multi_ts_avail_bmap_num(int slot_index) { // if this slot has been highlighted for informational purposes if((Multi_ts_select_type == MULTI_TS_AVAIL_LIST) && (Multi_ts_select_index == slot_index)){ return ICON_FRAME_SELECTED; } // if its otherwise being lit by the mouse if((Multi_ts_hotspot_type == MULTI_TS_AVAIL_LIST) && (Multi_ts_hotspot_index == slot_index)){ return ICON_FRAME_HOT; } return ICON_FRAME_NORMAL; } // return the bitmap index into the ships icon array (in ship select) which should be displayed for the given slot int multi_ts_slot_bmap_num(int slot_index) { // special case - slot is disabled, its my ship and the host hasn't locked the ships yet if(multi_ts_disabled_high_slot(slot_index)){ return ICON_FRAME_DISABLED_HIGH; } // if this slot is disabled for us, then show it as such if(multi_ts_disabled_slot(slot_index)){ return ICON_FRAME_DISABLED; } // if this slot has been highlighted for informational purposes if((Multi_ts_select_type == MULTI_TS_SLOT_LIST) && (Multi_ts_select_index == slot_index)){ return ICON_FRAME_SELECTED; } // if this is our ship, then highlight it as so if(Net_player->p_info.ship_index == slot_index){ return ICON_FRAME_PLAYER; } // if its otherwise being lit by the mouse if((Multi_ts_hotspot_type == MULTI_TS_SLOT_LIST) && (Multi_ts_hotspot_index == slot_index)){ return ICON_FRAME_HOT; } // normal unhighlighted frame return ICON_FRAME_NORMAL; } // select the given slot and setup any information, etc void multi_ts_select_ship() { /* int n_lines, idx; int n_chars[MAX_BRIEF_LINES]; char ship_desc[1000]; char *p_str[MAX_BRIEF_LINES]; char *token; */ // blast all current text memset(Multi_ts_ship_info_lines,0,MULTI_TS_SHIP_INFO_MAX_TEXT); memset(Multi_ts_ship_info_text,0,MULTI_TS_SHIP_INFO_MAX_TEXT); // get the selected ship class Assert(Multi_ts_select_index >= 0); Multi_ts_select_ship_class = -1; switch(Multi_ts_select_type){ case MULTI_TS_SLOT_LIST: Multi_ts_select_ship_class = Wss_slots[Multi_ts_select_index].ship_class; break; case MULTI_TS_AVAIL_LIST: Multi_ts_select_ship_class = multi_ts_get_avail_ship_class(Multi_ts_select_index); // if he has selected an empty slot, don't do anything if(Multi_ts_select_ship_class < 0){ return; } break; default : // should always have one of the 2 above types selected Int3(); break; } // split the text info up /* Assert(Multi_ts_select_ship_class >= 0); Assert((Ship_info[Multi_ts_select_ship_class].desc != NULL) && strlen(Ship_info[Multi_ts_select_ship_class].desc)); // strip out newlines memset(ship_desc,0,1000); strcpy(ship_desc,Ship_info[Multi_ts_select_ship_class].desc); token = strtok(ship_desc,"\n"); if(token != NULL){ strcpy(Multi_ts_ship_info_text,token); while(token != NULL){ token = strtok(NULL,"\n"); if(token != NULL){ strcat(Multi_ts_ship_info_text," "); strcat(Multi_ts_ship_info_text,token); } } } if(strlen(Multi_ts_ship_info_text) > 0){ // split the string into multiple lines n_lines = split_str(Multi_ts_ship_info_text, Multi_ts_ship_info_coords[gr_screen.res][MULTI_TS_W_COORD], n_chars, p_str, MULTI_TS_SHIP_INFO_MAX_LINES, 0); // copy the split up lines into the text lines array for (idx=0;idx<n_lines;idx++ ) { Assert(n_chars[idx] < MULTI_TS_SHIP_INFO_MAX_LINE_LEN); strncpy(Multi_ts_ship_info_lines[idx], p_str[idx], n_chars[idx]); Multi_ts_ship_info_lines[idx][n_chars[idx]] = 0; drop_leading_white_space(Multi_ts_ship_info_lines[idx]); } // get the line count Multi_ts_ship_info_line_count = n_lines; } else { // set the line count to Multi_ts_ship_info_line_count = 0; } */ } // handle all details when the commit button is pressed (including possibly reporting errors/popups) void multi_ts_commit_pressed() { // if my team's slots are still not "locked", we cannot commit unless we're the only player in the game if(!Multi_ts_team[Net_player->p_info.team].multi_players_locked){ if(multi_num_players() != 1){ popup(PF_USE_AFFIRMATIVE_ICON | PF_BODY_BIG,1,POPUP_OK,XSTR("Players have not yet been assigned to their ships",751)); return; } else { Multi_ts_team[Net_player->p_info.team].multi_players_locked = 1; } } // check to see if its not ok for this player to commit switch(multi_ts_ok_to_commit()){ // yes, it _is_ ok to commit case 0: extern void commit_pressed(); commit_pressed(); break; // player has not assigned all necessary ships case 1: gamesnd_play_iface(SND_GENERAL_FAIL); popup(PF_USE_AFFIRMATIVE_ICON | PF_BODY_BIG,1,POPUP_OK,XSTR("You have not yet assigned all necessary ships",752)); break; // there are ships without primary weapons case 2: gamesnd_play_iface(SND_GENERAL_FAIL); popup(PF_USE_AFFIRMATIVE_ICON | PF_BODY_BIG,1,POPUP_OK,XSTR("There are ships without primary weapons!",753)); break; // there are ships without secondary weapons case 3: gamesnd_play_iface(SND_GENERAL_FAIL); popup(PF_USE_AFFIRMATIVE_ICON | PF_BODY_BIG,1,POPUP_OK,XSTR("There are ships without secondary weapons!",754)); break; } } // is it ok for this player to commit int multi_ts_ok_to_commit() { int idx,s_idx; int primary_ok,secondary_ok; // if this player is an observer, he can always commit if(Net_player->flags & NETINFO_FLAG_OBSERVER){ return 0; } for(idx=0;idx<MULTI_TS_NUM_SHIP_SLOTS;idx++){ // if this is a player slot this player can modify and it is empty, then he cannot continue // implies there is never an object in this slot if((Multi_ts_team[Net_player->p_info.team].multi_ts_objnum[idx] != -1) && // implies player can't touch this slot anyway !multi_ts_disabled_slot(idx) && // implies that there should be a player ship here but there isn't ((Multi_ts_team[Net_player->p_info.team].multi_ts_player[idx] != NULL) && (Multi_ts_team[Net_player->p_info.team].multi_ts_flag[idx] == MULTI_TS_FLAG_EMPTY)) ){ return 1; } // if the ship in this slot has a ship which can be a player but has 0 primary or secondary weapons, then he cannot continue if( (Multi_ts_team[Net_player->p_info.team].multi_ts_objnum[idx] != -1) && ((Objects[Multi_ts_team[Net_player->p_info.team].multi_ts_objnum[idx]].flags & OF_COULD_BE_PLAYER) || (Objects[Multi_ts_team[Net_player->p_info.team].multi_ts_objnum[idx]].flags & OF_PLAYER_SHIP)) && !multi_ts_disabled_slot(idx)){ primary_ok = 0; secondary_ok = 0; // go through all weapons in the list for(s_idx=0;s_idx<MAX_WL_WEAPONS;s_idx++){ // if this slot has a weapon with a greater than 0 count, check if((Wss_slots_teams[Net_player->p_info.team][idx].wep[s_idx] >= 0) && (Wss_slots_teams[Net_player->p_info.team][idx].wep_count[s_idx] > 0)){ switch(Weapon_info[Wss_slots_teams[Net_player->p_info.team][idx].wep[s_idx]].subtype){ case WP_LASER: primary_ok = 1; break; case WP_MISSILE: secondary_ok = 1; break; default : Int3(); } } // if we've got both primary and secondary weapons if(primary_ok && secondary_ok){ break; } } // if the ship doesn't have primary weapons if(!primary_ok){ return 2; } // if the ship doesn't have secondary weapons if(!secondary_ok){ return 3; } } } return 0; } // check to see that no illegal ship settings have occurred void multi_ts_check_errors() { /* int idx; ship *shipp; for(idx=0;idx<MULTI_TS_NUM_SHIP_SLOTS;idx++){ if(Multi_ts_team[0].multi_ts_objnum[idx] == -1){ continue; } shipp = &Ships[Objects[Multi_ts_team[0].multi_ts_objnum[idx]].instance]; Assert((shipp->weapons.current_primary_bank != -1) && (shipp->weapons.current_secondary_bank != -1)); } */ } // ------------------------------------------------------------------------------------------------------ // TEAM SELECT PACKET HANDLERS // // send a player slot position update void send_pslot_update_packet(int team,int code,int sound) { ubyte data[MAX_PACKET_SIZE],stop,val; short s_sound; int idx; int packet_size = 0; int i_tmp; // build the header and add the data BUILD_HEADER(SLOT_UPDATE); // add the opcode val = (ubyte)code; ADD_DATA(val); // add the team val = (ubyte)team; ADD_DATA(val); // add the sound to play s_sound = (short)sound; ADD_DATA(s_sound); // add data based upon the packet code switch(code){ case TS_CODE_LOCK_TEAM: // don't have to do anything break; case TS_CODE_PLAYER_UPDATE: // only the host should ever be doing this Assert(Net_player->flags & NETINFO_FLAG_GAME_HOST); // add individual slot data for(idx=0;idx<MAX_WSS_SLOTS;idx++){ if(Multi_ts_team[team].multi_ts_flag[idx] != MULTI_TS_FLAG_NONE){ // add a stop byte stop = 0x0; ADD_DATA(stop); // add the slot # val = (ubyte)idx; ADD_DATA(val); // add the ship class val = (ubyte)Wss_slots_teams[team][idx].ship_class; ADD_DATA(val); // add the objnum we're working with i_tmp = Multi_ts_team[team].multi_ts_objnum[idx]; ADD_DATA(i_tmp); // add a byte indicating if a player is here or not if(Multi_ts_team[team].multi_ts_player[idx] == NULL){ val = 0; } else { val = 1; } ADD_DATA(val); // if there's a player, add his address if(val){ ADD_DATA(Multi_ts_team[team].multi_ts_player[idx]->player_id); // should also update his p_info settings locally Multi_ts_team[team].multi_ts_player[idx]->p_info.ship_class = Wss_slots_teams[team][idx].ship_class; Multi_ts_team[team].multi_ts_player[idx]->p_info.ship_index = idx; } // add a byte indicating what object flag should be set (0 == ~(OF_COULD_BE_PLAYER | OF_PLAYER_SHIP), 1 == player ship, 2 == could be player ship) if(Objects[Multi_ts_team[team].multi_ts_objnum[idx]].flags & OF_COULD_BE_PLAYER){ val = 2; } else if(Objects[Multi_ts_team[team].multi_ts_objnum[idx]].flags & OF_PLAYER_SHIP){ val = 1; } else { val = 0; } ADD_DATA(val); } } // add a final stop byte val = 0xff; ADD_DATA(val); break; default : Int3(); break; } // send the packet to the standalone if(Net_player->flags & NETINFO_FLAG_AM_MASTER) { multi_io_send_to_all_reliable(data, packet_size); } else { multi_io_send_reliable(Net_player, data, packet_size); } } // process a player slot position update void process_pslot_update_packet(ubyte *data, header *hinfo) { int offset = HEADER_LENGTH; int my_index; int player_index,idx,team,code,objnum; short sound; short player_id; ubyte stop,val,slot_num,ship_class; my_index = Net_player->p_info.ship_index; // if we're the standalone, then we should be routing this data to all the other clients player_index = -1; if(Net_player->flags & NETINFO_FLAG_AM_MASTER){ // fill in the address information of where this came from player_index = find_player_id(hinfo->id); Assert(player_index != -1); } // get the opcode GET_DATA(val); code = (int)val; // get the team GET_DATA(val); team = (int)val; // get the sound to play GET_DATA(sound); // process the different opcodes switch(code){ case TS_CODE_LOCK_TEAM: // lock the team Multi_ts_team[team].multi_players_locked = 1; // if this was my team, sync stuff up if((team == Net_player->p_info.team) && !(Game_mode & GM_STANDALONE_SERVER)){ multi_ts_set_status_bar_mode(1); multi_ts_sync_interface(); ss_recalc_multiplayer_slots(); } // if this is the standalone server, we need to re-route the packet here and there if(Net_player->flags & NETINFO_FLAG_AM_MASTER){ // in team vs team mode, only a team captain should ever be sending this if(Netgame.type_flags & NG_TYPE_TEAM){ Assert(Net_players[player_index].flags & NETINFO_FLAG_TEAM_CAPTAIN); } // in any other mode, it better be coming from the game host else { Assert(Net_players[player_index].flags & NETINFO_FLAG_GAME_HOST); } // re-route to all other players for(idx=0;idx<MAX_PLAYERS;idx++){ if(MULTI_CONNECTED(Net_players[idx]) && (&Net_players[idx] != Net_player) && (&Net_players[idx] != &Net_players[player_index]) ){ multi_io_send_reliable(&Net_players[idx], data, offset); } } } break; case TS_CODE_PLAYER_UPDATE: // get the first stop byte GET_DATA(stop); while(stop != 0xff){ // get the slot # GET_DATA(slot_num); // get the ship class GET_DATA(ship_class); // get the objnum GET_DATA(objnum); // flag indicating if a player is in this slot GET_DATA(val); if(val){ // look the player up GET_DATA(player_id); player_index = find_player_id(player_id); // if we couldn't find him if(player_index == -1){ nprintf(("Network","Couldn't find player for pslot update!\n")); Multi_ts_team[team].multi_ts_player[slot_num] = NULL; } // if we found him, assign him to this ship else { Net_players[player_index].p_info.ship_class = (int)ship_class; Net_players[player_index].p_info.ship_index = (int)slot_num; multi_assign_player_ship(player_index,&Objects[objnum],(int)ship_class); // ui stuff Multi_ts_team[team].multi_ts_player[slot_num] = &Net_players[player_index]; // if this was me and my ship index changed, update the weapon select screen if(my_index != Net_player->p_info.ship_index){ wl_reset_selected_slot(); my_index = Net_player->p_info.ship_index; } } } else { Multi_ts_team[team].multi_ts_player[slot_num] = NULL; } // get the ship flag byte GET_DATA(val); Objects[objnum].flags &= ~(OF_PLAYER_SHIP | OF_COULD_BE_PLAYER); switch(val){ case 1 : Objects[objnum].flags |= OF_PLAYER_SHIP; break; case 2 : obj_set_flags( &Objects[objnum], Objects[objnum].flags | OF_COULD_BE_PLAYER ); break; } // get the next stop byte GET_DATA(stop); } // if we have a sound we're supposed to play if((sound != -1) && !(Game_mode & GM_STANDALONE_SERVER) && (gameseq_get_state() == GS_STATE_TEAM_SELECT)){ gamesnd_play_iface(sound); } // if i'm the standalone server, I should rebroadcast this packet if(Game_mode & GM_STANDALONE_SERVER){ for(idx=0;idx<MAX_PLAYERS;idx++){ if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_HOST(Net_players[idx]) && (Net_player != &Net_players[idx])){ multi_io_send_reliable(&Net_players[idx], data, offset); } } } break; } PACKET_SET_SIZE(); // recalculate stuff if(!(Game_mode & GM_STANDALONE_SERVER)){ ss_recalc_multiplayer_slots(); } }
[ "(no author)@387891d4-d844-0410-90c0-e4c51a9137d3" ]
(no author)@387891d4-d844-0410-90c0-e4c51a9137d3
b3c2f91638773c24d19815fb73b012aa51d7d493
5499e8b91353ef910d2514c8a57a80565ba6f05b
/zircon/system/utest/nand-redundant-storage/nand-rs-tests.cc
621b0b70cab556cd7b8b21716abf65bb3b346f22
[ "BSD-3-Clause", "MIT" ]
permissive
winksaville/fuchsia
410f451b8dfc671f6372cb3de6ff0165a2ef30ec
a0ec86f1d51ae8d2538ff3404dad46eb302f9b4f
refs/heads/master
2022-11-01T11:57:38.343655
2019-11-01T17:06:19
2019-11-01T17:06:19
223,695,500
3
2
BSD-3-Clause
2022-10-13T13:47:02
2019-11-24T05:08:59
C++
UTF-8
C++
false
false
7,163
cc
// Copyright 2019 The Fuchsia Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include <lib/mtd/mtd-interface.h> #include <lib/nand-redundant-storage/nand-redundant-storage.h> #include <stdint.h> #include <vector> #include <zxtest/zxtest.h> // This NAND interface test relies on an MTD device file located at /dev/mtd0/ // for non-astro tests, and /dev/mtd/mtd9 for astro-based tests. // // On the host machine, nandsim is used to create a virtual MTD device. // The following command was used to create the device for this test. // // $ sudo modprobe nandsim id_bytes=0x2c,0xdc,0x90,0xa6,0x54,0x0 badblocks=5 using namespace nand_rs; namespace { #ifdef ASTRO constexpr const char* kTestDevicePath = "/dev/mtd/mtd9"; #else constexpr const char* kTestDevicePath = "/dev/mtd0"; #endif class MtdRsTest : public zxtest::Test { protected: void Wipe() { for (uint32_t offset = 0; offset < mtd_ptr_->Size(); offset += mtd_ptr_->BlockSize()) { bool is_bad_block; ASSERT_OK(mtd_ptr_->IsBadBlock(offset, &is_bad_block)); if (is_bad_block) { continue; } ASSERT_OK(mtd_ptr_->EraseBlock(offset)); } } // Zero-index-based block erase. void EraseBlockAtIndex(uint32_t index) { ASSERT_OK(mtd_ptr_->EraseBlock(mtd_ptr_->BlockSize() * index)); } void SetUp() override { auto mtd = mtd::MtdInterface::Create(kTestDevicePath); mtd_ptr_ = mtd.get(); // Sanity "test" to make sure the interface is valid. ASSERT_NE(nullptr, mtd_ptr_, "Failed to initialize nand_ with device %s", kTestDevicePath); nand_ = NandRedundantStorage::Create(std::move(mtd)); max_blocks_ = mtd_ptr_->Size() / mtd_ptr_->BlockSize(); num_copies_written_ = 0; Wipe(); } std::vector<uint8_t> MakeFakePage(uint8_t value, uint32_t checksum, uint32_t file_size) { std::vector<uint8_t> res(mtd_ptr_->PageSize(), value); res[0] = 'Z'; res[1] = 'N'; res[2] = 'N'; res[3] = 'D'; // Avoid byte-masking, as the struct is just copied into memory. auto checksum_ptr = reinterpret_cast<uint32_t*>(&res[4]); *checksum_ptr = checksum; auto file_size_ptr = reinterpret_cast<uint32_t*>(&res[8]); *file_size_ptr = file_size; return res; } mtd::MtdInterface* mtd_ptr_; std::unique_ptr<NandRedundantStorage> nand_; std::vector<uint8_t> out_buffer_; uint32_t num_copies_written_; uint32_t max_blocks_; }; TEST_F(MtdRsTest, ReadWriteTest) { std::vector<uint8_t> nonsense_buffer = {12, 14, 22, 0, 12, 8, 0, 0, 0, 3, 45, 0xFF}; ASSERT_OK(nand_->WriteBuffer(nonsense_buffer, 10, &num_copies_written_)); ASSERT_EQ(10, num_copies_written_); ASSERT_OK(nand_->ReadToBuffer(&out_buffer_)); ASSERT_BYTES_EQ(out_buffer_.data(), nonsense_buffer.data(), nonsense_buffer.size()); std::vector<uint8_t> page_crossing_buffer(mtd_ptr_->PageSize() * 2 + 13, 0xF5); ASSERT_OK(nand_->WriteBuffer(page_crossing_buffer, 10, &num_copies_written_)); ASSERT_EQ(10, num_copies_written_); ASSERT_OK(nand_->ReadToBuffer(&out_buffer_)); ASSERT_BYTES_EQ(out_buffer_.data(), page_crossing_buffer.data(), page_crossing_buffer.size()); } TEST_F(MtdRsTest, WriteNoHeaderTest) { std::vector<uint8_t> nonsense_buffer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; size_t buffer_size = nonsense_buffer.size(); ASSERT_OK(nand_->WriteBuffer(nonsense_buffer, 10, &num_copies_written_, true)); ASSERT_EQ(10, num_copies_written_); ASSERT_OK(nand_->ReadToBuffer(&out_buffer_, true, buffer_size)); ASSERT_BYTES_EQ(out_buffer_.data(), nonsense_buffer.data(), nonsense_buffer.size()); } TEST_F(MtdRsTest, WriteNoHeaderWithoutFileSizeTest) { std::vector<uint8_t> nonsense_buffer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; ASSERT_OK(nand_->WriteBuffer(nonsense_buffer, 10, &num_copies_written_, true)); ASSERT_EQ(10, num_copies_written_); ASSERT_EQ(ZX_ERR_INVALID_ARGS, nand_->ReadToBuffer(&out_buffer_, true)); } TEST_F(MtdRsTest, ReadWriteTestWithErasedBlock) { std::vector<uint8_t> page_crossing_buffer(mtd_ptr_->PageSize() * 2 + 13, 0xF5); ASSERT_OK(nand_->WriteBuffer(page_crossing_buffer, 20, &num_copies_written_)); ASSERT_EQ(20, num_copies_written_); EraseBlockAtIndex(0); EraseBlockAtIndex(1); EraseBlockAtIndex(2); EraseBlockAtIndex(3); ASSERT_OK(nand_->ReadToBuffer(&out_buffer_)); ASSERT_BYTES_EQ(out_buffer_.data(), page_crossing_buffer.data(), page_crossing_buffer.size()); } TEST_F(MtdRsTest, ReadWriteTestWithCorruptedBlockValidHeader) { std::vector<uint8_t> page_crossing_buffer(mtd_ptr_->PageSize() * 2 + 13, 0xF5); ASSERT_OK(nand_->WriteBuffer(page_crossing_buffer, 10, &num_copies_written_)); ASSERT_EQ(10, num_copies_written_); EraseBlockAtIndex(0); EraseBlockAtIndex(1); EraseBlockAtIndex(2); EraseBlockAtIndex(3); uint32_t block_three_start = mtd_ptr_->BlockSize() * 2; std::vector<uint8_t> page_of_nonsense = MakeFakePage(0x40, 0x40404040, 0x40404040); ASSERT_OK(mtd_ptr_->WritePage(block_three_start, page_of_nonsense.data(), nullptr)); ASSERT_OK(nand_->ReadToBuffer(&out_buffer_)); ASSERT_BYTES_EQ(out_buffer_.data(), page_crossing_buffer.data(), page_crossing_buffer.size()); } TEST_F(MtdRsTest, ReadWiteTestWithCorruptedBlockWrongCrc) { std::vector<uint8_t> page_crossing_buffer(mtd_ptr_->PageSize() * 2 + 13, 0xF5); ASSERT_OK(nand_->WriteBuffer(page_crossing_buffer, 10, &num_copies_written_)); ASSERT_EQ(10, num_copies_written_); EraseBlockAtIndex(0); EraseBlockAtIndex(1); EraseBlockAtIndex(2); EraseBlockAtIndex(3); // Nonsense block, but with valid looking CRC and file size. uint32_t block_three_start = mtd_ptr_->BlockSize() * 2; std::vector<uint8_t> page_of_nonsense = MakeFakePage(0x40, 1, 34); ASSERT_OK(mtd_ptr_->WritePage(block_three_start, page_of_nonsense.data(), nullptr)); ASSERT_OK(nand_->ReadToBuffer(&out_buffer_)); ASSERT_BYTES_EQ(out_buffer_.data(), page_crossing_buffer.data(), page_crossing_buffer.size()); } TEST_F(MtdRsTest, ReadWriteTestWithCorruptedBlockWrongHeader) { std::vector<uint8_t> page_crossing_buffer(mtd_ptr_->PageSize() * 2 + 13, 0xF5); ASSERT_OK(nand_->WriteBuffer(page_crossing_buffer, 10, &num_copies_written_)); ASSERT_EQ(10, num_copies_written_); EraseBlockAtIndex(0); EraseBlockAtIndex(1); EraseBlockAtIndex(2); EraseBlockAtIndex(3); // Nonsense block, but with invalid header. uint32_t block_three_start = mtd_ptr_->BlockSize() * 2; std::vector<uint8_t> page_of_nonsense = MakeFakePage(0x40, 1, 34); page_of_nonsense[0] = 'z'; ASSERT_OK(mtd_ptr_->WritePage(block_three_start, page_of_nonsense.data(), nullptr)); ASSERT_OK(nand_->ReadToBuffer(&out_buffer_)); ASSERT_BYTES_EQ(out_buffer_.data(), page_crossing_buffer.data(), page_crossing_buffer.size()); } TEST_F(MtdRsTest, ReadEmptyMtd) { ASSERT_EQ(ZX_ERR_IO, nand_->ReadToBuffer(&out_buffer_)); } TEST_F(MtdRsTest, TestBlockWriteLimits) { std::vector<uint8_t> some_bits = {1, 2, 3, 5, 10, 9, 25, 83}; ASSERT_OK(nand_->WriteBuffer(some_bits, max_blocks_, &num_copies_written_)); ASSERT_EQ(max_blocks_ - 1, num_copies_written_); } } // namespace
[ "commit-bot@chromium.org" ]
commit-bot@chromium.org
d5dfc6655be8265a97162ec9f4a42ef9aa2012c3
5740ea2c2d9d5fb5626ff5ad651f3789048ae86b
/Extensions/Editor/AppCommands.cpp
d3de4866c9b37ede48e45d9421a034527b9f65ec
[ "LicenseRef-scancode-scintilla", "MIT" ]
permissive
donovan680/Plasma
4945b92b7c6e642a557f12e05c7d53819186de55
51d40ef0669b7a3015f95e3c84c6d639d5469b62
refs/heads/master
2022-04-15T02:42:26.469268
2020-02-26T22:32:12
2020-02-26T22:32:12
null
0
0
null
null
null
null
UTF-8
C++
false
false
6,640
cpp
#include "Precompiled.hpp" namespace Plasma { void OpenHelp() { Os::SystemOpenNetworkFile(Urls::cUserHelp); } void OpenPlasmaHub() { Os::SystemOpenNetworkFile(Urls::cUserPlasmaHub); } void OpenDocumentation() { Os::SystemOpenNetworkFile(Urls::cUserOnlineDocs); } void ExitEditor() { PL::gEditor->RequestQuit(false); } void Restart() { bool quitSuccess = PL::gEditor->RequestQuit(true); if(quitSuccess) Os::SystemOpenFile( GetApplication().c_str() ); } void FullScreen(Editor* editor) { OsWindow* osWindow = editor->mOsWindow; if (osWindow->GetState() != WindowState::Fullscreen) osWindow->SetState(WindowState::Fullscreen); else osWindow->SetState(WindowState::Windowed); } void ShowTextWindow(StringParam windowTitle, StringParam windowText) { Window* window = new Window(PL::gEditor); window->SetTitle(windowTitle); window->SetTranslation(Vec3(0, -500, 0)); MultiLineText* textBox = new MultiLineText(window); textBox->SetText(windowText); window->SizeToContents(); CenterToWindow(PL::gEditor, window, true); } void ShowAbout() { String text = "DigiPen Plasma Engine\n" "Copyright: \n" "DigiPen Institute of Technology 2016\n" "All rights reserved. \n" "Version: \n"; ShowTextWindow("About", BuildString(text, GetBuildVersionName())); } DeclareEnum3(VersionStatus, Unknown, UpToDate, NewVersionAvailable); VersionStatus::Type GlobalVersionStatus = VersionStatus::Unknown; void BuildVersion() { String buildVersionString = String::Format("BuildVersion: %s", GetBuildVersionName()); ZPrintFilter(Filter::DefaultFilter, "%s\n", buildVersionString.c_str()); OsShell* platform = PL::gEngine->has(OsShell); platform->SetClipboardText(buildVersionString); } void WriteBuildInfo() { String sourceDir = PL::gEngine->GetConfigCog()->has(MainConfig)->SourceDirectory; Environment* environment = Environment::GetInstance(); String filePath = environment->GetParsedArgument("WriteBuildInfo"); if(filePath.Empty() || filePath == "true") filePath = FilePath::CombineWithExtension(sourceDir, "Meta", ".data"); StringBuilder builder; builder.AppendFormat("MajorVersion %d\n", GetMajorVersion()); builder.AppendFormat("MinorVersion %d\n", GetMinorVersion()); builder.AppendFormat("PatchVersion %d\n", GetPatchVersion()); builder.AppendFormat("RevisionId %d\n", GetRevisionNumber()); builder.AppendFormat("Platform \"%s\"\n", GetPlatformString()); cstr experimentalBranchName = GetExperimentalBranchName(); if(experimentalBranchName != nullptr) builder.AppendFormat("ExperimentalBranchName \"%s\"\n", experimentalBranchName); builder.AppendFormat("ShortChangeSet \"%s\"\n", GetShortChangeSetString()); builder.AppendFormat("ChangeSet \"%s\"\n", GetChangeSetString()); builder.AppendFormat("ChangeSetDate \"%s\"\n", GetChangeSetDateString()); builder.AppendFormat("BuildId \"%s\"\n", GetBuildIdString()); builder.AppendFormat("LauncherMajorVersion %d\n", GetLauncherMajorVersion()); String result = builder.ToString(); WriteStringRangeToFile(filePath, result); ZPrint("Writing build info to '%s'\n", filePath.c_str()); ZPrint("File Contents: %s\n", result.c_str()); PL::gEngine->Terminate(); } void OpenTestWidgetsCommand() { OpenTestWidgets(PL::gEditor); } // Used to test the crash handler void CrashEngine() { PL::gEngine->CrashEngine(); } void SortAndPrintMetaTypeList(StringBuilder& builder, Array<String>& names, cstr category) { if (names.Empty()) return; Sort(names.All()); builder.Append(category); builder.Append(":\n"); forRange(String& name, names.All()) { builder.Append(" "); builder.Append(name); builder.Append("\n"); } builder.Append("\n"); } // Special class to delay dispatching the unit test command until scripts have been compiled class UnitTestDelayRunner : public Composite { public: typedef UnitTestDelayRunner LightningSelf; void OnScriptsCompiled(Event* e) { ActionSequence* seq = new ActionSequence(PL::gEditor, ActionExecuteMode::FrameUpdate); //wait a little bit so we the scripts will be finished compiling (and hooked up) seq->Add(new ActionDelay(0.1f)); seq->Add(new ActionEvent(PL::gEngine, "RunUnitTests", new Event())); //when the game plays the scripts will be compiled again so don't dispatch this event DisconnectAll(PL::gEngine, this); this->Destroy(); } UnitTestDelayRunner(Composite* parent) : Composite(parent) { OnScriptsCompiled(nullptr); } }; void RunUnitTests() { Lightning::Sha1Builder::RunUnitTests(); new UnitTestDelayRunner(PL::gEditor); } void RecordUnitTestFile() { UnitTestSystem* unitTestSystem = PL::gEngine->has(UnitTestSystem); unitTestSystem->RecordToPlasmaTestFile(); } void PlayUnitTestFile() { UnitTestSystem* unitTestSystem = PL::gEngine->has(UnitTestSystem); unitTestSystem->PlayFromPlasmaTestFile(); } void HostLightningDebugger() { LightningManager* manager = LightningManager::GetInstance(); manager->HostDebugger(); } void RunLightningDebugger() { HostLightningDebugger(); String debuggerPath = FilePath::Combine(PL::gContentSystem->ToolPath, "LightningDebugger.html"); Os::SystemOpenFile(debuggerPath.c_str()); } void BindAppCommands(Cog* config, CommandManager* commands) { commands->AddCommand("About", BindCommandFunction(ShowAbout)); commands->AddCommand("Exit", BindCommandFunction(ExitEditor)); commands->AddCommand("ToggleFullScreen", BindCommandFunction(FullScreen)); commands->AddCommand("Restart", BindCommandFunction(Restart)); commands->AddCommand("BuildVersion", BindCommandFunction(BuildVersion)); commands->AddCommand("WriteBuildInfo", BindCommandFunction(WriteBuildInfo)); commands->AddCommand("RunUnitTests", BindCommandFunction(RunUnitTests)); commands->AddCommand("RecordUnitTestFile", BindCommandFunction(RecordUnitTestFile)); commands->AddCommand("PlayUnitTestFile", BindCommandFunction(PlayUnitTestFile)); if(DeveloperConfig* devConfig = PL::gEngine->GetConfigCog()->has(DeveloperConfig)) { commands->AddCommand("OpenTestWidgets", BindCommandFunction(OpenTestWidgetsCommand)); commands->AddCommand("CrashEngine", BindCommandFunction(CrashEngine)); commands->AddCommand("HostLightningDebugger", BindCommandFunction(HostLightningDebugger)); commands->AddCommand("RunLightningDebugger", BindCommandFunction(RunLightningDebugger)); } commands->AddCommand("Help", BindCommandFunction(OpenHelp)); commands->AddCommand("PlasmaHub", BindCommandFunction(OpenPlasmaHub)); commands->AddCommand("Documentation", BindCommandFunction(OpenDocumentation)); } }
[ "dragonCASTjosh@gmail.com" ]
dragonCASTjosh@gmail.com
602554a88c73c1f548cabb64b767c372b4c88526
98ab3e12ce3db4896ffa976fd258dffdbadb138c
/oxygine-framework/oxygine/src/Polygon.h
6fff8918d0bb586161ebcbcf61c93836f309a8e0
[ "MIT" ]
permissive
vlad-d-markin/dethgame
ce0a0f7868e59f12824fe9120c895a49ff3d1e19
bcb4bf7f432c14faf77ae9a7411c3c9df629bbd1
refs/heads/master
2021-01-17T16:56:34.567317
2016-07-19T21:42:01
2016-07-19T21:42:01
62,659,600
6
2
null
2016-07-17T21:06:13
2016-07-05T18:22:24
C
UTF-8
C++
false
false
902
h
#pragma once #include "oxygine_include.h" #include "Sprite.h" namespace oxygine { class ResAnim; DECLARE_SMART(Polygon, spPolygon); class Polygon : public _Sprite { public: DECLARE_COPYCLONE_NEW(Polygon); Polygon(); ~Polygon(); /** if *own* is true Polygon will delete[] data array; */ void setVertices(const void* data, int size, int bformat, bool own); void serialize(serializedata* data); void deserialize(const deserializedata* data); std::string dump(const dumpOptions&) const; protected: void doRender(const RenderState& rs); const VertexDeclaration* _vdecl; bool _own; const unsigned char* _verticesData; int _verticesSize; }; } #ifdef OX_EDITOR #include "EditorPolygon.h" #else namespace oxygine { typedef Polygon _Polygon; } #endif
[ "vlad.d.markin@gmail.com" ]
vlad.d.markin@gmail.com
44590293364cce2f65278bb659654bd3a991cebe
32411cce4a91a3a4b693b963af77fcb83b3c0764
/src/gruppe3/src/laser.cpp
1f322b2fad74245b624353b9ad81a410e867643e
[]
no_license
IchBinZeyuan/Robotic_CPP
2d1279898ab7e348a3d2dca7bd08626f56c9c562
099592490b583c39cece3b7c7abd1a85e3b74063
refs/heads/master
2020-05-02T07:04:19.241923
2019-03-26T19:44:58
2019-03-26T19:44:58
177,808,938
0
1
null
null
null
null
UTF-8
C++
false
false
1,178
cpp
#include <ros/ros.h> #include <iostream> #include <sensor_msgs/LaserScan.h> using namespace std; double datalaser[360] = {0} ; //void AutoExp::processLaserScan(const sensor_msgs::LaserScan::ConstPtr& scan){ //ROS_INFO("laser messages:",scan->ranges[]); //} //int main(int argc,char** argv) //{ //ros::init(argc,argv,"ladar"); //ros::NodeHandle nh; //ros::Subscriber sub = nh.subscribe<sensor_msgs/LaserScan>("/scan",10,&AutoExp::processLaserScan,this); //ros::spin(); //return 0; //} void get_laser_callback(const sensor_msgs::LaserScan &laser){ //count << "ROS Ladar Data"<<endl; //count << "Front:"<<laser.ranges[719] << endl; //count << "----------------------"<< endl; //double datalaser[360] = {0} ; int i = 0 ; while ( i<360){ datalaser[i] = laser.ranges[i] ; i++; } //ROS_INFO_STREAM("Front:"<<datalaser[2]); } int main (int argc, char **argv) { ros::init(argc,argv,"laser"); ros::NodeHandle n ; ros::Subscriber laser_sub = n.subscribe("/lidarscan",1000,get_laser_callback); //ROS_INFO_STREAM("Front:"<<datalaser[2]); ros::Rate rate(10); int i = 0; while(ros::ok()){ ROS_INFO_STREAM("Front:"<<datalaser[200]); ros::spinOnce(); rate.sleep(); i++; } return 0; }
[ "zeyuan.zhang@tum.de" ]
zeyuan.zhang@tum.de
98f14a305ef75ed6f3303bf0106d8fde28800cf1
98066229ed99c9c1f92fdf8915ab6a11fb8cf60f
/source/response.cpp
fa27221379bd2ea4ba3f9586bfe21484cd9762a8
[]
no_license
NickRegistered/webServer-select
4313faa3516946d5c4a2633e2a139be47014bb50
249a117c3aa80a1ae8e148450f797a3d8b78dec3
refs/heads/master
2020-05-03T20:19:16.746382
2019-04-07T02:04:10
2019-04-07T02:04:10
178,800,364
3
1
null
null
null
null
UTF-8
C++
false
false
2,498
cpp
#include "response.h" using namespace std; const map<string, string> ExtnToType = { { ".gif","image/gif\r\n" },{ ".mp3","audio/mp3\r\n" } , { ".ogg","application/ogg\r\n" },{ ".mp4","audio/mp4\r\n" } , { ".webm","video/webm\r\n" },{ ".html","text/html\r\n" }, {".ico","application/x-ico\r\n"},{ "","text/html\r\n" } }; const char* page404 = "<html><body><h1 style=\"text-align:center\">404 NotFound</h1></body></html>"; Response::Response(char* req) { int i = 0; for (;req[i] != ' ';++i) { Method[i] = req[i]; }Method[i++] = '\0';//ๆทปๅŠ ็ป“ๆŸ็ฌฆๅนถ่ทณ่ฟ‡็ฉบๆ ผ int j = 0, k = 0; int flag = 0; for (;req[i] != ' ';++i, ++j) { URL[j] = req[i]; if (URL[j] == '/') URL[j] = '\\';//ๅฐ†่ฏทๆฑ‚ไธญ็š„'/'ๆขไฝœ'\\' Extn[k] = req[i]; if (req[i] == '.')flag = 1; k += flag; }URL[j] = '\0', Extn[k] = '\0'; //ๅฆ‚ๆžœ่ฏทๆฑ‚ๆ น็›ฎๅฝ• if (strcmp(URL, "\\") == 0) {//้ป˜่ฎคๅ‘้€html strcat(URL, "index.html"); }; } void Response::ResponseHeader(const char *filename,char* buff) { buff[0] = '\0'; FILE *fin = fopen(filename, "rb"); if (!fin) { Stat[0] = '\0'; strcat(Stat, "HTTP/1.1 404 Not Found\r\nContent-Type: text/html\r\nContent-Length: 73\r\n\r\n");//ๆ–‡ไปถๆ‰“ๅผ€ๅคฑ่ดฅ๏ผŒๅ†™ๅ…ฅ็Šถๆ€ไฟกๆฏ404 strcat(buff, Stat); strcat(buff,page404);//็›ดๆŽฅๅ†™ๅ…ฅ404้กต้ข return; } else { Stat[0] = '\0'; strcat(Stat,"HTTP/1.1 200 OK\r\n"); auto itor = ExtnToType.find(Extn); CntType[0] = '\0'; strcat(CntType, "Content-Type: "); strcat(CntType, (itor->second).c_str()); fseek(fin, 0, SEEK_END); int size = ftell(fin); fclose(fin); char num[7],tempc; int i; for (i = 0;size > 0;++i) { num[i] = size % 10 + '0'; size /= 10; }num[i--] = '\0';//ๆทปๅŠ ็ป“ๆŸ็ฌฆ๏ผŒๅฐ†iๆŒ‡ๅ‘ๆœ€ๅŽไธ€ไธชๆ•ฐๅญ— for (int j = 0;j < i;++j, --i) { tempc = num[j]; num[j] = num[i]; num[i] = tempc; } CntLen[0] = '\0'; strcat(CntLen, "Content-Length: "); strcat(CntLen, num); strcat(CntLen,"\r\n\r\n");//็ป“ๆŸไธ€่กŒ๏ผŒ็ป“ๆŸๆŠฅๆ–‡ strcat(buff, Stat); strcat(buff, CntType); strcat(buff, CntLen); return; } }
[ "36127069+NickRegistered@users.noreply.github.com" ]
36127069+NickRegistered@users.noreply.github.com
ceea9ac8fd76a3d13cc8cec5831a2eed6853f85f
815ba6cc98dedf268cf66ef0a5207cfc4d3f5eb9
/mca-2.0.3/mcapi/src/mcapi_trans/mcapi_trans_sm/Fragments/mcapi_trans_smt_initialize_abl.cpp
6a4cb2a09d3222e50379304478f796b61cfc5291
[]
no_license
ke4harper/MxAPI
65b0c1fca9e58dd4670d1752c7f2a1d8f9ba78a7
fc4e2e4037cfb41360f0d0974f3142ba948d9bd7
refs/heads/master
2023-04-03T07:09:04.452807
2023-03-14T21:23:35
2023-03-14T21:23:35
185,410,427
1
0
null
2022-09-29T23:45:15
2019-05-07T13:43:25
C
UTF-8
C++
false
false
4,818
cpp
/* Copyright (c) 2012, ABB, Inc All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of ABB, Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 <COPYRIGHT HOLDER> 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. */ // Node attributes { int i = 0; mcapi_node_attributes_t na = { { { 0 } } }; mcapi_uint_t attribute1 = 0; mcapi_uint_t attribute2 = 0; status = MCAPI_SUCCESS; assert(mcapi_trans_node_init_attributes(&na,&status)); assert(MCAPI_SUCCESS == status); // status not used for(i = 0; i < MAX_NUM_ATTRIBUTES; i++) { assert(MCAPI_FALSE == na.entries[i].valid); } attribute1 = MCAPI_NODE_ATTR_TYPE_REGULAR; mcapi_trans_node_set_attribute(&na,MCAPI_NODE_ATTR_TYPE,&attribute1,sizeof(mcapi_uint_t),&status); // Attribute has to fit in size of pointer (void*) assert(MCAPI_SUCCESS == status); assert(MCAPI_NODE_ATTR_TYPE_REGULAR == na.entries[MCAPI_NODE_ATTR_TYPE].attribute_d.type); assert(mcapi_trans_initialize(domain,node,&na,MCAPI_TRUE)); assert(mcapi_trans_whoami(&node,&n_index,&domain,&d_index)); assert(mcapi_db->domains[d_index].nodes[n_index].valid); // Attribute valid property not used assert(sizeof(mcapi_uint_t) == mcapi_db->domains[d_index].nodes[n_index].attributes.entries[MCAPI_NODE_ATTR_TYPE].bytes); assert(MCAPI_NODE_ATTR_TYPE_REGULAR == mcapi_db->domains[d_index].nodes[n_index].attributes.entries[MCAPI_NODE_ATTR_TYPE].attribute_d.type); mcapi_trans_node_get_attribute(domain,node,MCAPI_NODE_ATTR_TYPE,&attribute2,sizeof(mcapi_uint_t),&status); assert(MCAPI_SUCCESS == status); assert(attribute2 == attribute1); assert(mcapi_trans_finalize()); } // Runtime initialization { // One node assert(mcapi_trans_node_init_attributes(&node_attrs,&status)); assert(mcapi_trans_initialize(domain,node,&node_attrs,MCAPI_FALSE)); assert(!mcapi_db->domains[0].nodes[0].valid); assert(mcapi_trans_access_database_pre(global_rwl,MCAPI_TRUE)); mcapi_trans_start_have_lock(); assert(mcapi_trans_access_database_post(global_rwl,MCAPI_TRUE)); assert(mcapi_db->domains[0].nodes[0].valid); assert(domain == mcapi_db->domains[0].domain_id); assert(MCAPI_TRUE == mcapi_db->domains[0].valid); assert(1 == mcapi_db->domains[0].num_nodes); assert(node == mcapi_db->domains[0].nodes[0].node_num); assert(MCAPI_TRUE == mcapi_db->domains[0].nodes[0].valid); #if !(__unix__) assert(GetCurrentProcessId() == mcapi_db->domains[0].nodes[0].pid); assert((pthread_t)GetCurrentThreadId() == mcapi_db->domains[0].nodes[0].tid); #else assert(getpid() == mcapi_db->domains[0].nodes[0].pid); assert(pthread_self() == mcapi_db->domains[0].nodes[0].tid); #endif // (__unix__) assert(mcapi_trans_initialized()); assert(!mcapi_trans_initialize(domain,node,&node_attrs,MCAPI_TRUE)); // Error to initialize duplicate node on same thread assert(!mcapi_db->domains[0].nodes[0].rundown); assert(mcapi_trans_finalize()); assert(mcapi_trans_initialize(domain,node,&node_attrs,MCAPI_TRUE)); assert(!mcapi_db->domains[0].nodes[0].rundown); assert(mcapi_trans_access_database_pre(global_rwl,MCAPI_TRUE)); mcapi_trans_rundown_have_lock(); assert(mcapi_trans_access_database_post(global_rwl,MCAPI_TRUE)); assert(mcapi_db->domains[0].nodes[0].rundown); assert(mcapi_trans_finalize()); }
[ "keharper@wt.net" ]
keharper@wt.net
8af99273daa74669ab403ad115c8de1c9536af78
64bd2dbc0d2c8f794905e3c0c613d78f0648eefc
/Cpp/SDK/OnlineSubsystem_functions.cpp
9029d704aa120b6cfb0bb84cfc22c3472c36c7a9
[]
no_license
zanzo420/SoT-Insider-SDK
37232fa74866031dd655413837813635e93f3692
874cd4f4f8af0c58667c4f7c871d2a60609983d3
refs/heads/main
2023-06-18T15:48:54.547869
2021-07-19T06:02:00
2021-07-19T06:02:00
387,354,587
1
2
null
null
null
null
UTF-8
C++
false
false
1,816
cpp
๏ปฟ// Name: SoT Insider, Version: 1.103.4306.0 #include "../pch.h" /*!!DEFINE!!*/ /*!!HELPER_DEF!!*/ /*!!HELPER_INC!!*/ #ifdef _MSC_VER #pragma pack(push, 0x01) #endif namespace CG { //--------------------------------------------------------------------------- // Functions //--------------------------------------------------------------------------- // Function OnlineSubsystem.TurnBasedMatchInterface.OnMatchReceivedTurn // (Event, Public, BlueprintEvent) // Parameters: // struct FString Match (Parm, ZeroConstructor, HasGetValueTypeHash) // bool bDidBecomeActive (Parm, ZeroConstructor, IsPlainOldData, NoDestructor) void UTurnBasedMatchInterface::OnMatchReceivedTurn(const struct FString& Match, bool bDidBecomeActive) { static auto fn = UObject::FindObject<UFunction>("Function OnlineSubsystem.TurnBasedMatchInterface.OnMatchReceivedTurn"); UTurnBasedMatchInterface_OnMatchReceivedTurn_Params params; params.Match = Match; params.bDidBecomeActive = bDidBecomeActive; auto flags = fn->FunctionFlags; UObject::ProcessEvent(fn, &params); fn->FunctionFlags = flags; } // Function OnlineSubsystem.TurnBasedMatchInterface.OnMatchEnded // (Event, Public, BlueprintEvent) // Parameters: // struct FString Match (Parm, ZeroConstructor, HasGetValueTypeHash) void UTurnBasedMatchInterface::OnMatchEnded(const struct FString& Match) { static auto fn = UObject::FindObject<UFunction>("Function OnlineSubsystem.TurnBasedMatchInterface.OnMatchEnded"); UTurnBasedMatchInterface_OnMatchEnded_Params params; params.Match = Match; auto flags = fn->FunctionFlags; UObject::ProcessEvent(fn, &params); fn->FunctionFlags = flags; } } #ifdef _MSC_VER #pragma pack(pop) #endif
[ "zp2kshield@gmail.com" ]
zp2kshield@gmail.com
73d6f0566dd9864b3423a486eae3bba868582991
1dd825971ed4ec0193445dc9ed72d10618715106
/examples/extended/polarisation/Pol01/src/StepMaxMessenger.cc
6a1c8aca373acdc93d2b880e393e8510731ad2e4
[]
no_license
gfh16/Geant4
4d442e5946eefc855436f4df444c245af7d3aa81
d4cc6c37106ff519a77df16f8574b2fe4ad9d607
refs/heads/master
2021-06-25T22:32:21.104339
2020-11-02T13:12:01
2020-11-02T13:12:01
158,790,658
0
0
null
null
null
null
UTF-8
C++
false
false
2,991
cc
// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // /// \file polarisation/Pol01/src/StepMaxMessenger.cc /// \brief Implementation of the StepMaxMessenger class // // $Id$ // //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... #include "StepMaxMessenger.hh" #include "StepMax.hh" #include "G4UIcmdWithADoubleAndUnit.hh" //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... StepMaxMessenger::StepMaxMessenger(StepMax* stepMax) : G4UImessenger(), fStepMax(stepMax), fStepMaxCmd(0) { fStepMaxCmd = new G4UIcmdWithADoubleAndUnit("/testem/stepMax",this); fStepMaxCmd->SetGuidance("Set max allowed step length"); fStepMaxCmd->SetParameterName("mxStep",false); fStepMaxCmd->SetRange("mxStep>0."); fStepMaxCmd->SetUnitCategory("Length"); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... StepMaxMessenger::~StepMaxMessenger() { delete fStepMaxCmd; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void StepMaxMessenger::SetNewValue(G4UIcommand* command, G4String newValue) { if (command == fStepMaxCmd) { fStepMax->SetMaxStep(fStepMaxCmd->GetNewDoubleValue(newValue));} } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
[ "gfh16@mails.tsinghua.edu.cn" ]
gfh16@mails.tsinghua.edu.cn
aa3cd6fdd4626ba635625988403aabc85c8d84b5
5bbeacc09bcb942112cb506f3bfce3ef4269e9b0
/ElliotEngine/src/ElliotEngineView.h
f3651cfd6775c27848e53c8d9dceef8d6235345b
[]
no_license
schaed/finance
cf62f898cf31e8c0060a57a3bed06d1acea44ca9
64a2d91f01f6abf39b9d1399e47a1f16a529fe41
refs/heads/master
2021-01-13T03:14:15.898981
2017-05-25T14:34:15
2017-05-25T14:34:15
77,621,789
0
3
null
null
null
null
UTF-8
C++
false
false
4,051
h
// ElliotEngineView.h : interface of the CElliotEngineView class // ///////////////////////////////////////////////////////////////////////////// #if !defined(AFX_ELLIOTENGINEVIEW_H__6022A139_5151_45DC_95EB_202FEBC1912E__INCLUDED_) #define AFX_ELLIOTENGINEVIEW_H__6022A139_5151_45DC_95EB_202FEBC1912E__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "FinanceChart.h" #include "./ChartDirector/mfcdemo/mfcdemo/ChartViewer.h" class CElliotEngineView : public CFormView { protected: // create from serialization only CElliotEngineView(); DECLARE_DYNCREATE(CElliotEngineView) public: //{{AFX_DATA(CElliotEngineView) enum { IDD = IDC_STATIC2 }; CButton m_ShowMonowaves; CScrollBar m_ChartScrollBar; CScrollBar m_WaveScroll; CEdit m_MovAvg2; CEdit m_MovAvg1; CButton m_MinorVGrid; CButton m_MajorVGrid; CButton m_LogScale; CButton m_HGrid; CButton m_Volume; CComboBox m_Indicator4; CComboBox m_Indicator3; CComboBox m_Indicator2; CComboBox m_Indicator1; CComboBox m_ChartType; CComboBox m_ChartSize; CComboBox m_Band; CComboBox m_AvgType2; CComboBox m_AvgType1; CComboBox m_TimeRange; CChartViewer m_Chart; //}}AFX_DATA // Attributes public: CElliotEngineDoc* GetDocument(); // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CElliotEngineView) public: virtual BOOL PreCreateWindow(CREATESTRUCT& cs); protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support virtual void OnInitialUpdate(); // called first time after construct virtual BOOL OnPreparePrinting(CPrintInfo* pInfo); virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo); virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo); virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo); //}}AFX_VIRTUAL // Implementation public: virtual ~CElliotEngineView(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: //Start date of the data points (excluding extra leading points) double m_startDate; //End date of the data points. double m_endDate; //The resolution of the data points (in sec) int m_resolution; //The timeStamps of the data points. It can include data points that are before the //startDate (extra leading points) to facilitate moving averages computation. int m_noOfPoints; int m_leadingExtraPoints; int m_offsetIntoRawArrays; int m_noOfRawPoints; double *m_timeStamps; double *m_volData; //The volume values. double *m_highData; //The high values. double *m_lowData; //The low values. double *m_openData; //The open values. double *m_closeData; //The close values. int m_avgPeriod1; int m_avgPeriod2; virtual void ReloadRawData(); virtual void GetData(int requestedDuration, int requestedExtraPoints); virtual void UpdateChart(CChartViewer *viewer); // Generated message map functions protected: //{{AFX_MSG(CElliotEngineView) afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg void OnSelectChange(); afx_msg void OnTextChange(); afx_msg void OnSelchangeChartsize(); afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg void OnResolutionChange(); //}}AFX_MSG DECLARE_MESSAGE_MAP() int DrawWave(const ETime& startDate, double startPrice, const ETime& endDate, double endPrice, double* pts); int AddMonoWaves(XYChart* pMainChart); }; #ifndef _DEBUG // debug version in ElliotEngineView.cpp inline CElliotEngineDoc* CElliotEngineView::GetDocument() { return (CElliotEngineDoc*)m_pDocument; } #endif ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_ELLIOTENGINEVIEW_H__6022A139_5151_45DC_95EB_202FEBC1912E__INCLUDED_)
[ "schae@cern.ch" ]
schae@cern.ch
4af6534731eb3b414a2a55422c4c9012c768eb34
045ad86b79d87f501cfd8252ecd8cc3c1ac960dd
/DDS/Policy/QosPolicyBase.h
46c582f7f146b30c98205ca4fd62c7c5c7389f02
[ "MIT" ]
permissive
intact-software-systems/cpp-software-patterns
9513e4d988342d88c100e4d85a0e58a3dbd9909e
e463fc7eeba4946b365b5f0b2eecf3da0f4c895b
refs/heads/master
2020-04-08T08:22:25.073672
2018-11-26T14:19:49
2018-11-26T14:19:49
159,176,259
1
0
null
null
null
null
UTF-8
C++
false
false
3,151
h
/* * QosPolicy.h * * Created on: 10. july 2012 * Author: KVik */ #ifndef DDS_QosPolicy_QosPolicyBase_h_IsIncluded #define DDS_QosPolicy_QosPolicyBase_h_IsIncluded #include"DDS/CommonDefines.h" #include"DDS/Policy/PolicyKind.h" #include"DDS/Export.h" namespace DDS { namespace Policy { /** * @brief * * This class is the abstract root for all the QoS policies. * * It provides the basic mechanism for an application to specify quality of service parameters. It has an attribute name that * is used to identify uniquely each QoS policy. All concrete QosPolicy classes derive from this root and include a value * whose type depends on the concrete QoS policy. * * The type of a QosPolicy value may be atomic, such as an integer or float, or compound (a structure). Compound types are * used whenever multiple parameters must be set coherently to define a consistent value for a QosPolicy. * * Each Entity can be configured with a list of QosPolicy. However, any Entity cannot support any QosPolicy. For instance, * a DomainParticipant supports different QosPolicy than a Topic or a Publisher. * * QosPolicy can be set when the Entity is created, or modified with the set_qos method. Each QosPolicy in the list is * treated independently from the others. This approach has the advantage of being very extensible. However, there may be * cases where several policies are in conflict. Consistency checking is performed each time the policies are modified via the * set_qos operation. * * When a policy is changed after being set to a given value, it is not required that the new value be applied instantaneously; * the Service is allowed to apply it after a transition phase. In addition, some QosPolicy have immutable semantics * meaning that they can only be specified either at Entity creation time or else prior to calling the enable operation on the * Entity. * * Section 7.1.3, Supported QoS, on page 96 provides the list of all QosPolicy, their meaning, characteristics and possible * values, as well as the concrete Entity to which they apply. */ #define DEFINE_POLICY_TRAITS(NAME, ID, RXO, CHANGEABLE) \ virtual const std::string& GetPolicyName() const { \ static std::string the_name = #NAME; \ return the_name; \ } \ virtual uint32_t GetPolicyId() const { \ static uint32_t id = ID; \ return id; \ } \ virtual DDS::Policy::RequestedOfferedKind::Type GetRxO() const { \ static DDS::Policy::RequestedOfferedKind::Type rxo = RXO; \ return rxo; \ } \ virtual bool IsChangeable() const { \ static bool changeable = CHANGEABLE; \ return changeable; \ } class DLL_STATE QosPolicyBase : public NetworkLib::NetObjectBase { public: QosPolicyBase() { } virtual ~QosPolicyBase() { } virtual const std::string& GetPolicyName() const = 0; virtual uint32_t GetPolicyId() const = 0; virtual bool IsChangeable() const = 0; virtual DDS::Policy::RequestedOfferedKind::Type GetRxO() const = 0; }; }} #endif
[ "intact.software.systems@gmail.com" ]
intact.software.systems@gmail.com
716ead90c8053dff43b2b8e2d754ee1137dbe2b2
1ab9ced624ad3518554548b7bed92a13c5d05faa
/Solutions/Daily Temperatures.cpp
a4f8a7b922222122c9c2ef10e30eabe2329cdd5c
[]
no_license
shehab-ashraf/Problem_Solving
361674efde765b705402d1971cf0206e604d92c7
2cb4d241bcc885251fdaf2757f3f0738b08f521f
refs/heads/master
2023-07-02T19:25:04.780816
2021-07-30T22:30:01
2021-07-30T22:30:01
381,096,647
0
0
null
null
null
null
UTF-8
C++
false
false
474
cpp
// O(n) time | O(n) space class Solution { public: vector<int> dailyTemperatures(vector<int>& temperatures) { stack<int> st; vector<int> ans(temperatures.size(),0); for(int i = 0 ; i < temperatures.size() ; i++){ while(!st.empty() && temperatures[st.top()] < temperatures[i]){ ans[st.top()] = i-st.top(); st.pop(); } st.push(i); } return ans; } };
[ "ashrafshehab377@gmail.com" ]
ashrafshehab377@gmail.com
be2c5d334b998cd2228c105cdbbfea0578cd2d5b
5586d98bf5f5d3336d5ec427eaa3a2b7c6f6d9da
/Practice/lab1.cpp
bcb9a74627772df5a58aa890a2ee54ee57f99235
[]
no_license
maybeabhishek/PDC_Lab
b09a00f3b25586601084861c42bac545e87843c1
eefb0d15b5344dceb5c089e0eb8f7829155aa0a0
refs/heads/master
2022-03-29T16:09:50.853593
2019-12-24T18:48:12
2019-12-24T18:48:12
198,183,784
1
0
null
null
null
null
UTF-8
C++
false
false
992
cpp
#include<iostream> #include<omp.h> using namespace std; int main(){ int num = omp_get_max_threads(); cout<<"Num threads: "<<num<<endl; int n = 400; double a[n][n], b[n][n], c[n][n]; int i,j,k; double wtime = omp_get_wtime(); srand(time(0)); #pragma omp shared(a,b,c,n) private(i,j,k) { #pragma omp for for( i = 0; i<n;i++){ for( j=0; j<n; j++){ a[i][j] = rand()%100; } } #pragma omp for for( i = 0; i<n;i++){ for( j=0; j<n; j++){ b[i][j] = rand()%100; } } #pragma omp for schedule(static) for( i =0; i<n; i++){ for( j = 0; j<n; j++){ c[i][j] = 0.0; for(k=0; k<n; k++){ c[i][j] += a[i][k] + b[k][j]; } } } } wtime = omp_get_wtime() - wtime; cout<<endl<<"Time taken: "<<wtime<<endl; return 0; }
[ "abhishek.satapathy01@gmail.com" ]
abhishek.satapathy01@gmail.com
22588425b27fc86a53fd743533098c88593f3751
5d4753b7e463827c9540e982108de22f62435c3f
/cc/subtle/prf/streaming_prf_wrapper_test.cc
875d6747aa9d648fd878eb35d10f03ed8d0ccecf
[ "Apache-2.0" ]
permissive
thaidn/tink
8c9b65e3f3914eb54d70847c9f56853afd051dd3
2a75c1c3e4ef6aa1b6e29700bf5946b725276c95
refs/heads/master
2021-07-25T02:02:59.839232
2021-02-10T17:21:31
2021-02-10T17:22:01
337,815,957
2
0
Apache-2.0
2021-02-10T18:28:20
2021-02-10T18:28:20
null
UTF-8
C++
false
false
4,640
cc
// Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // /////////////////////////////////////////////////////////////////////////////// #include "tink/subtle/prf/streaming_prf_wrapper.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "absl/strings/str_cat.h" #include "tink/util/input_stream_util.h" #include "tink/util/istream_input_stream.h" #include "tink/util/test_matchers.h" #include "tink/util/test_util.h" #include "proto/tink.pb.h" namespace crypto { namespace tink { namespace { using ::crypto::tink::test::IsOk; using ::crypto::tink::test::StatusIs; using ::google::crypto::tink::KeysetInfo; using ::google::crypto::tink::KeyStatusType; using ::google::crypto::tink::OutputPrefixType; using ::testing::Eq; using ::testing::HasSubstr; class DummyStreamingPrf : public StreamingPrf { public: explicit DummyStreamingPrf(absl::string_view name) : name_(name) {} std::unique_ptr<InputStream> ComputePrf( absl::string_view input) const override { return absl::make_unique<crypto::tink::util::IstreamInputStream>( absl::make_unique<std::stringstream>( absl::StrCat(name_.length(), ":", name_, input))); } private: std::string name_; }; TEST(AeadSetWrapperTest, WrapNullptr) { StreamingPrfWrapper wrapper; EXPECT_THAT(wrapper.Wrap(nullptr).status(), StatusIs(util::error::INVALID_ARGUMENT, HasSubstr("non-NULL"))); } TEST(KeysetDeriverWrapperTest, WrapEmpty) { EXPECT_THAT( StreamingPrfWrapper() .Wrap(absl::make_unique<PrimitiveSet<StreamingPrf>>()) .status(), StatusIs(util::error::INVALID_ARGUMENT, HasSubstr("exactly one key"))); } TEST(KeysetDeriverWrapperTest, WrapSingle) { auto prf_set = absl::make_unique<PrimitiveSet<StreamingPrf>>(); KeysetInfo::KeyInfo key_info; key_info.set_key_id(1234); key_info.set_status(KeyStatusType::ENABLED); key_info.set_output_prefix_type(OutputPrefixType::RAW); auto entry_or = prf_set->AddPrimitive( absl::make_unique<DummyStreamingPrf>("single_key"), key_info); ASSERT_THAT(entry_or.status(), IsOk()); EXPECT_THAT(prf_set->set_primary(entry_or.ValueOrDie()), IsOk()); auto wrapped_prf = StreamingPrfWrapper().Wrap(std::move(prf_set)); ASSERT_THAT(wrapped_prf.status(), IsOk()); auto prf_output = ReadBytesFromStream( 23, wrapped_prf.ValueOrDie()->ComputePrf("input_text").get()); ASSERT_THAT(prf_output.status(), IsOk()); EXPECT_THAT(prf_output.ValueOrDie(), Eq("10:single_keyinput_text")); } TEST(KeysetDeriverWrapperTest, WrapNonRaw) { auto prf_set = absl::make_unique<PrimitiveSet<StreamingPrf>>(); KeysetInfo::KeyInfo key_info; key_info.set_key_id(1234); key_info.set_status(KeyStatusType::ENABLED); key_info.set_output_prefix_type(OutputPrefixType::TINK); auto entry_or = prf_set->AddPrimitive( absl::make_unique<DummyStreamingPrf>("single_key"), key_info); ASSERT_THAT(entry_or.status(), IsOk()); EXPECT_THAT(prf_set->set_primary(entry_or.ValueOrDie()), IsOk()); EXPECT_THAT(StreamingPrfWrapper().Wrap(std::move(prf_set)).status(), StatusIs(util::error::INVALID_ARGUMENT, HasSubstr("output_prefix_type"))); } TEST(KeysetDeriverWrapperTest, WrapMultiple) { auto prf_set = absl::make_unique<PrimitiveSet<StreamingPrf>>(); KeysetInfo::KeyInfo key_info; key_info.set_key_id(1234); key_info.set_status(KeyStatusType::ENABLED); key_info.set_output_prefix_type(OutputPrefixType::RAW); auto entry_or = prf_set->AddPrimitive( absl::make_unique<DummyStreamingPrf>("single_key"), key_info); ASSERT_THAT(entry_or.status(), IsOk()); EXPECT_THAT(prf_set->set_primary(entry_or.ValueOrDie()), IsOk()); key_info.set_key_id(2345); EXPECT_THAT( prf_set ->AddPrimitive(absl::make_unique<DummyStreamingPrf>("second_key"), key_info) .status(), IsOk()); EXPECT_THAT(StreamingPrfWrapper().Wrap(std::move(prf_set)).status(), StatusIs(util::error::INVALID_ARGUMENT, HasSubstr("given set has 2 keys"))); } } // namespace } // namespace tink } // namespace crypto
[ "copybara-worker@google.com" ]
copybara-worker@google.com
0dd68be4b85d753fe732558602078b139e87ed0e
6fe17c32ba5bb492e276e13128c516a3f85f01ff
/New folder/stones on the table.cpp
385fd81f1bbde63893ea12f81cdf4a3b3416c12c
[ "Apache-2.0" ]
permissive
YaminArafat/Codeforces
35c5c527c8edd51c7f591bfe6474060934241d86
3d72ba0b5c9408a8e2491b25b5b643e9f9be728b
refs/heads/master
2023-08-17T03:12:04.596632
2021-10-06T14:49:29
2021-10-06T14:49:29
351,042,898
0
0
null
null
null
null
UTF-8
C++
false
false
326
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n,i,x=0; scanf("%d",&n); char str[n+1]; for (i=0 ; i<n; i++) { cin>>str[i]; } str[i]='\0'; for(i=0;i<n-1;i++) { if(str[i]==str[i+1]) { x++; } } cout<<x<<endl; return 0; }
[ "yaminarafat032@gmail.com" ]
yaminarafat032@gmail.com
8e3f2e3ab5b71a5bbc66053b5302ce944161c804
3943f4014015ae49a2c6c3c7018afd1d2119a7ed
/final_output/output_myrecur_abs_1_cp/laguerre_formula_0.9_1.1/3-6.cpp
06fb0675062f122b5c4dc02db7a92807b07d57df
[]
no_license
Cathy272272272/practicum
9fa7bfcccc23d4e40af9b647d9d98f5ada37aecf
e13ab8aa5cf5c037245b677453e14b586b10736d
refs/heads/master
2020-05-23T10:10:15.111847
2019-06-08T00:23:57
2019-06-08T00:23:57
186,689,468
0
0
null
null
null
null
UTF-8
C++
false
false
2,852
cpp
#include <iostream> #include <stdio.h> #include <assert.h> #include <math.h> extern "C" { #include "quadmath.h" } #ifndef IFT #define IFT float #endif #ifndef OFT #define OFT __float128 #endif //#include <cmath> using namespace std; //static const int k = 3; template <class T> T n_factorial(T n){ if ( n == 0 ) return 1; return n*n_factorial(n-1); } template <class T> T my_pow(T x, unsigned n){ if ( n == 0 ) return T(1.0); return x * my_pow(x, n-1); } template <class T> T my_hermite(unsigned n, T x){ if (n == 0 ) return T(1); T res(0); T cnt = n - 2*(n/2); T n_start = n_factorial(cnt); T m_start = n_factorial(n/2); T n_multiply = n_factorial(n); T neg_one = my_pow(-1, n/2); T x_start = my_pow(2*x, cnt); for ( unsigned i = n/2; i > 0; i-- ){ res += neg_one * x_start / m_start / n_start; neg_one *= (-1); x_start *= 4*x*x; m_start /= i; n_start *= (cnt+1) *(cnt+2); cnt += 2; } res += neg_one * x_start / m_start / n_start; return n_multiply * res; } template <class T> T my_laguerre(unsigned n, T x){ if (n == 0 ) return 1.0; T n_multiple = 1; T k_multiple = 1; T x_multiple = 1.0; T neg = 1.0; T res = 1.0; for ( unsigned i = 1; i <= n; i++ ){ x_multiple *= x; k_multiple *= i; n_multiple *= (n-i+1); neg *= (-1); res += neg * n_multiple / k_multiple / k_multiple * x_multiple; } return res; } template <class T> T my_legendre(unsigned n, T x){ if (n == 0 ) return 1.0; T x_half = 1.0; T n_minus_multiple = n_factorial(T(n)); T n_plus_multiple = n_minus_multiple; T k_multiple = 1; T res = 1.0; for ( unsigned i = 1; i <= n; i++ ){ n_minus_multiple /= (n-i+1); n_plus_multiple *= (n+i); k_multiple *= i; x_half *= ((x - 1.0) / 2); res += n_plus_multiple / n_minus_multiple / k_multiple / k_multiple * x_half; } return res; } int main (int argc, char *argv[]) { assert(argc == 3); char *iname = argv[1]; char *oname = argv[2]; FILE *ifile = fopen(iname, "r"); FILE *ofile = fopen(oname, "w"); assert(ifile != NULL && ofile != NULL); fseek(ifile, 0, SEEK_END); unsigned long fsize = ftell(ifile); assert(fsize == (sizeof(IFT) * 1)); fseek(ifile, 0, SEEK_SET); IFT in_x; fread(&in_x, sizeof(IFT), 1, ifile); FT rel = 0; FT x = in_x; #ifdef ORIG rel = my_laguerre(6, x + 0.0); #else rel = ( ( ( x*pow(x,3) ) * ( ( ( x*x ) *0.001389 ) + ( ( x*-0.05 ) +0.625 ) ) ) +log( ( ( exp(1.0)*pow(exp(-3.333333),pow(x,3)) ) *pow(exp(x), ( ( x*7.5 ) -6.0 ) ) ) ) ) ; #endif OFT outv = rel; fwrite(&outv, sizeof(OFT), 1, ofile); fclose(ifile); fclose(ofile); return 0; }
[ "cathyxu@Cathys-MacBook-Pro.local" ]
cathyxu@Cathys-MacBook-Pro.local
b1773c2ec4e1fb80e2e3dbd5904ecfd5627d91b2
94847d787dfe5695eeaa5e0bfd65eb11b6d4e6ef
/include/rllib/util/Vector3.hpp
ed28eb98ad8604a8ab5197fbd8ebe399436e4c06
[ "MIT" ]
permissive
loriswit/rllib
70bc3161e998d71355536a977f1ce74fdb172ec0
a09a73f8ac353db76454007b2ec95bf438c0fc1a
refs/heads/main
2021-06-15T19:12:58.385115
2021-02-07T17:44:39
2021-02-07T17:44:39
144,877,014
1
0
null
null
null
null
UTF-8
C++
false
false
1,212
hpp
#ifndef RLLIB_VECTOR3_HPP #define RLLIB_VECTOR3_HPP #include <ostream> namespace rl { /** * Structure representing a three-dimensional vector. * * @tparam T The type of the vector components */ template<typename T> struct RL_API Vector3 { /** * The horizontal component of the vector. */ T x; /** * The vertical component of the vector. */ T y; /** * The depth component of the vector. */ T z; /** * Creates a 3D vector. * * @param X The horizontal component of the vector * @param Y The vertical component of the vector * @param Z The depth component of the vector */ constexpr Vector3(T X = 0, T Y = 0, T Z = 0); }; /** * Writes the 3D vector components into a stream. * * @tparam T The type of the vector components * @param stream The stream object * @param vector The 3D vector object * @return The current stream */ template<typename T> std::ostream & operator<<(std::ostream & stream, const Vector3<T> & vector); /** * Type representing a 3D vector with float components. */ using Vector3f = Vector3<float>; #include "Vector3.inl" } // namespace rl #endif //RLLIB_VECTOR3_HPP
[ "loris.wit@gmail.com" ]
loris.wit@gmail.com
43134827e35602e8ae1f49eeed13910cd9028cbe
f82aa8969f093aeccc55d0724da3605185a29ae4
/templates/examples/videoexample.cpp
4a398b6e511a918f8b4aa26c8d720269c8b19da6
[]
no_license
EricMiddleton1/CPRE575-HW3
d78d0579377972357c5ec6704a45f0c7604173b2
e9fcef27e132b62ec8e141dce080907e75d41b3a
refs/heads/master
2021-03-19T17:30:06.717523
2018-02-22T09:13:08
2018-02-22T09:13:08
122,440,611
0
0
null
null
null
null
UTF-8
C++
false
false
1,638
cpp
// Headers #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; int main(int argc, char* argv[]) { // Load input video // If your video is in a different source folder than your code, // make sure you specify the directory correctly! VideoCapture input_cap("../../input/part1a/input1a1.avi"); // Check validity of target file if(!input_cap.isOpened()) { std::cout << "Input video not found." << std::endl; return -1; } // Set up target output video /* usage: VideoWriter(filename, encoding, framerate, Size) * in our case, cv_cap_prop_* means "get property of capture" * we want our output to have the same properties as the input! */ VideoWriter output_cap("helloworld.avi", input_cap.get(CV_CAP_PROP_FOURCC), input_cap.get(CV_CAP_PROP_FPS), Size(input_cap.get(CV_CAP_PROP_FRAME_WIDTH), input_cap.get(CV_CAP_PROP_FRAME_HEIGHT))); // Again, check validity of target output file if(!output_cap.isOpened()) { std::cout << "Could not create output file." << std::endl; return -1; } // Loop to read from input one frame at a time, write text on frame, and // copy to output video Mat frame; while(input_cap.read(frame)) { putText(frame, "Hello World!", Point(0, 50), FONT_HERSHEY_PLAIN, 1.0, Scalar(255, 255, 255)); output_cap.write(frame); } // free the capture objects from memory input_cap.release(); output_cap.release(); return 1; }
[ "ericm@iastate.edu" ]
ericm@iastate.edu
11da73a7609b400d1f32fffc741d4bf3fea24596
107dd749c9886d781894e5238d9c2419f7952649
/src/qt/bitcoingui.h
483fa2b75e701a13a46e904982aad166dee03137
[ "MIT" ]
permissive
Coin4Trade/Coin4Trade
ae58e76e09ed5a0cb62def5b91efd848cd77a284
fb5c4b7580212cd7e3daacd93fabf1be4d20ff7c
refs/heads/master
2023-08-23T22:42:33.681882
2021-10-02T20:58:21
2021-10-02T20:58:21
281,785,399
1
0
null
null
null
null
UTF-8
C++
false
false
9,416
h
// Copyright (c) 2011-2014 The Bitcoin developers // Copyright (c) 2017-2018 The PIVX developers // Copyright (c) 2020 The C4T developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_QT_BITCOINGUI_H #define BITCOIN_QT_BITCOINGUI_H #if defined(HAVE_CONFIG_H) #include "config/C4T-config.h" #endif #include "amount.h" #include <QLabel> #include <QMainWindow> #include <QMap> #include <QMenu> #include <QPoint> #include <QPushButton> #include <QSystemTrayIcon> class ClientModel; class NetworkStyle; class Notificator; class OptionsModel; class BlockExplorer; class RPCConsole; class SendCoinsRecipient; class UnitDisplayStatusBarControl; class WalletFrame; class WalletModel; class MasternodeList; class CWallet; QT_BEGIN_NAMESPACE class QAction; class QProgressBar; class QProgressDialog; QT_END_NAMESPACE /** Bitcoin GUI main class. This class represents the main window of the Bitcoin UI. It communicates with both the client and wallet models to give the user an up-to-date view of the current core state. */ class BitcoinGUI : public QMainWindow { Q_OBJECT public: static const QString DEFAULT_WALLET; explicit BitcoinGUI(const NetworkStyle* networkStyle, QWidget* parent = 0); ~BitcoinGUI(); /** Set the client model. The client model represents the part of the core that communicates with the P2P network, and is wallet-agnostic. */ void setClientModel(ClientModel* clientModel); #ifdef ENABLE_WALLET /** Set the wallet model. The wallet model represents a bitcoin wallet, and offers access to the list of transactions, address book and sending functionality. */ bool addWallet(const QString& name, WalletModel* walletModel); bool setCurrentWallet(const QString& name); void removeAllWallets(); #endif // ENABLE_WALLET bool enableWallet; bool fMultiSend = false; protected: void changeEvent(QEvent* e); void closeEvent(QCloseEvent* event); void dragEnterEvent(QDragEnterEvent* event); void dropEvent(QDropEvent* event); bool eventFilter(QObject* object, QEvent* event); private: ClientModel* clientModel; WalletFrame* walletFrame; UnitDisplayStatusBarControl* unitDisplayControl; QLabel* labelStakingIcon; QPushButton* labelAutoMintIcon; QPushButton* labelEncryptionIcon; QLabel* labelTorIcon; QPushButton* labelConnectionsIcon; QLabel* labelBlocksIcon; QLabel* progressBarLabel; QProgressBar* progressBar; QProgressDialog* progressDialog; QMenuBar* appMenuBar; QAction* overviewAction; QAction* historyAction; QAction* masternodeAction; QAction* quitAction; QAction* sendCoinsAction; QAction* usedSendingAddressesAction; QAction* usedReceivingAddressesAction; QAction* signMessageAction; QAction* verifyMessageAction; QAction* bip38ToolAction; QAction* multisigCreateAction; QAction* multisigSpendAction; QAction* multisigSignAction; QAction* aboutAction; QAction* receiveCoinsAction; QAction* optionsAction; QAction* toggleHideAction; QAction* encryptWalletAction; QAction* backupWalletAction; QAction* changePassphraseAction; QAction* unlockWalletAction; QAction* lockWalletAction; QAction* aboutQtAction; QAction* openInfoAction; QAction* openRPCConsoleAction; QAction* openNetworkAction; QAction* openPeersAction; QAction* openRepairAction; QAction* openConfEditorAction; QAction* openMNConfEditorAction; QAction* showBackupsAction; QAction* openAction; QAction* openBlockExplorerAction; QAction* showHelpMessageAction; QAction* multiSendAction; QSystemTrayIcon* trayIcon; QMenu* trayIconMenu; Notificator* notificator; RPCConsole* rpcConsole; BlockExplorer* explorerWindow; /** Keep track of previous number of blocks, to detect progress */ int prevBlocks; int spinnerFrame; /** Create the main UI actions. */ void createActions(const NetworkStyle* networkStyle); /** Create the menu bar and sub-menus. */ void createMenuBar(); /** Create the toolbars */ void createToolBars(); /** Create system tray icon and notification */ void createTrayIcon(const NetworkStyle* networkStyle); /** Create system tray menu (or setup the dock menu) */ void createTrayIconMenu(); /** Enable or disable all wallet-related actions */ void setWalletActionsEnabled(bool enabled); /** Connect core signals to GUI client */ void subscribeToCoreSignals(); /** Disconnect core signals from GUI client */ void unsubscribeFromCoreSignals(); signals: /** Signal raised when a URI was entered or dragged to the GUI */ void receivedURI(const QString& uri); /** Restart handling */ void requestedRestart(QStringList args); public slots: /** Set number of connections shown in the UI */ void setNumConnections(int count); /** Set number of blocks shown in the UI */ void setNumBlocks(int count); /** Get restart command-line parameters and request restart */ void handleRestart(QStringList args); /** Notify the user of an event from the core network or transaction handling code. @param[in] title the message box / notification title @param[in] message the displayed text @param[in] style modality and style definitions (icon and used buttons - buttons only for message boxes) @see CClientUIInterface::MessageBoxFlags @param[in] ret pointer to a bool that will be modified to whether Ok was clicked (modal only) */ void message(const QString& title, const QString& message, unsigned int style, bool* ret = NULL); #ifdef ENABLE_WALLET void setStakingStatus(); /** Set the encryption status as shown in the UI. @param[in] status current encryption status @see WalletModel::EncryptionStatus */ void setEncryptionStatus(int status); bool handlePaymentRequest(const SendCoinsRecipient& recipient); /** Show incoming transaction notification for new transactions. */ void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address); #endif // ENABLE_WALLET private: /** Set the Tor-enabled icon as shown in the UI. */ void updateTorIcon(); private slots: #ifdef ENABLE_WALLET /** Switch to overview (home) page */ void gotoOverviewPage(); /** Switch to history (transactions) page */ void gotoHistoryPage(); /** Switch to Explorer Page */ void gotoBlockExplorerPage(); /** Switch to masternode page */ void gotoMasternodePage(); /** Switch to receive coins page */ void gotoReceiveCoinsPage(); /** Switch to send coins page */ void gotoSendCoinsPage(QString addr = ""); /** Show Sign/Verify Message dialog and switch to sign message tab */ void gotoSignMessageTab(QString addr = ""); /** Show Sign/Verify Message dialog and switch to verify message tab */ void gotoVerifyMessageTab(QString addr = ""); /** Show MultiSend Dialog */ void gotoMultiSendDialog(); /** Show MultiSig Dialog */ void gotoMultisigCreate(); void gotoMultisigSpend(); void gotoMultisigSign(); /** Show BIP 38 tool - default to Encryption tab */ void gotoBip38Tool(); /** Show open dialog */ void openClicked(); #endif // ENABLE_WALLET /** Show configuration dialog */ void optionsClicked(); /** Show about dialog */ void aboutClicked(); /** Show help message dialog */ void showHelpMessageClicked(); #ifndef Q_OS_MAC /** Handle tray icon clicked */ void trayIconActivated(QSystemTrayIcon::ActivationReason reason); #endif /** Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHidden is true */ void showNormalIfMinimized(bool fToggleHidden = false); /** Simply calls showNormalIfMinimized(true) for use in SLOT() macro */ void toggleHidden(); /** called by a timer to check if fRequestShutdown has been set **/ void detectShutdown(); /** Show progress dialog e.g. for verifychain */ void showProgress(const QString& title, int nProgress); }; class UnitDisplayStatusBarControl : public QLabel { Q_OBJECT public: explicit UnitDisplayStatusBarControl(); /** Lets the control know about the Options Model (and its signals) */ void setOptionsModel(OptionsModel* optionsModel); protected: /** So that it responds to left-button clicks */ void mousePressEvent(QMouseEvent* event); private: OptionsModel* optionsModel; QMenu* menu; /** Shows context menu with Display Unit options by the mouse coordinates */ void onDisplayUnitsClicked(const QPoint& point); /** Creates context menu, its actions, and wires up all the relevant signals for mouse events. */ void createContextMenu(); private slots: /** When Display Units are changed on OptionsModel it will refresh the display text of the control on the status bar */ void updateDisplayUnit(int newUnits); /** Tells underlying optionsModel to update its current display unit. */ void onMenuSelection(QAction* action); }; #endif // BITCOIN_QT_BITCOINGUI_H
[ "68502813+Coin4Trade@users.noreply.github.com" ]
68502813+Coin4Trade@users.noreply.github.com
8301e048f1a2c75efe7cd5747e94a4ffcec1c3dd
276f0b31f669b3e1e36b7e2f332c4df86aec800d
/Mateusz Machaj Connect Four Source Code/Connect Four/Game Classes/Game.h
2f9122d52e6f9cba3ae7d40c703ac402f1a95d1d
[]
no_license
mateuszmachaj/Code-Foo
c06b5c5f821ca29224fa778cf97e0ae2e44eb23d
9b4279581f580b4b625b4cc362caf48a9e858f37
refs/heads/master
2021-01-13T02:29:52.554462
2012-05-01T04:25:10
2012-05-01T04:25:10
null
0
0
null
null
null
null
UTF-8
C++
false
false
1,005
h
#pragma once #include "../Framework/Graphics.h" #include "../Framework/Input.h" #include "../Framework/Audio.h" // Sprite structure typedef struct { // sprite details float width; float height; // sprite position float posX; float posY; bool visible; }Sprite; class Game { public: Game(); int Update(); void Render(); void setUp(bool multiGame, bool newGame); bool InitGame(); void Shutdown(); private: int field[6][7]; int playerPieces[7][6]; int aiPieces[7][6]; int playerTurn; int selection; Sprite redPieces[21]; Sprite bluePieces[21]; LPDIRECT3DTEXTURE9 redPiece; LPDIRECT3DTEXTURE9 bluePiece; LPDIRECT3DTEXTURE9 board; LPDIRECT3DTEXTURE9 title; int redCount; int blueCount; bool pieceFall; bool humanOp; int playerScore[2]; int aiScore[2]; CSound *music; CSound *move; CSound *hit; int aiSeletion(); bool winCheck(int pieces[7][6], int input); void updateField(int field[6][7], int pieces[7][6], int playerTurn); bool drawCheck(); };
[ "mateuszmachaj@yahoo.com" ]
mateuszmachaj@yahoo.com
0a9fcc33c4a2939430b6d0a810d4ac09375e73b8
087dea2f7147663ba90a213f59b70ddd59f6aec4
/main/stltest/bind2nd2.cpp
4949eb68852cab1062e669d946aa6f4a64a893a6
[ "MIT" ]
permissive
stormbrew/stir
b5c3bcaf7c7e8c3a95dd45bf1642c83b6291a408
2d39364bfceb87106daa2338f9dfe6362a811347
refs/heads/master
2022-05-24T17:52:26.908960
2022-04-28T03:39:42
2022-04-28T03:39:42
1,130,258
0
0
null
null
null
null
UTF-8
C++
false
false
469
cpp
#ifndef SINGLE // An adapted ObjectSpace example for use with SGI STL #include <iostream> #include <algorithm> #include <functional> #ifdef MAIN #define bind2nd2_test main #endif #endif int bind2nd2_test(int, char**) { std::cout<<"Results of bind2nd2_test:"<<std::endl; int array [3] = { 1, 2, 3 }; std::replace_if(array, array + 3, std::bind2nd(std::greater<int>(), 2), 4); for(int i = 0; i < 3; i++) std::cout << array[i] << std::endl; return 0; }
[ "megan@stormbrew.ca" ]
megan@stormbrew.ca
132408885f75e8a40b0f4ea9c497342073d408b6
e94caa5e0894eb25ff09ad75aa104e484d9f0582
/data/s30l/mp2/cp_corrected/20/AB/cc-pVQZ/2_ghosts/cbas_mp2/restart.cc
6dd50a8da7a2af525c343189c32bacc56e590290
[]
no_license
bdnguye2/divergence_mbpt_noncovalent
d74e5d755497509026e4ac0213ed66f3ca296908
f29b8c75ba2f1c281a9b81979d2a66d2fd48e09c
refs/heads/master
2022-04-14T14:09:08.951134
2020-04-04T10:49:03
2020-04-04T10:49:03
240,377,466
0
0
null
null
null
null
UTF-8
C++
false
false
444
cc
$chkbas= 1570771.54340576 $nucrep= 505.009748775714 $chkaux= 13179617163.0805 $chkupro= 1.00000000000000 $chkipro= 2.00000000000000 $chklasrep= 1.00000000000000 $chkisy6= 4.00000000000000 $chkmos= 2036.89531322081 $chkCCVPQ_ISQR= 52880.6863318043 $chkbqia= 55.1374803240782 $chkr0_MP2= 0.00000000000000 $energy_MP2= -389.004999792089 $sccss= 1.00000000000000 $sccos= 1.00000000000000 $end
[ "bdnguye2@uci.edu" ]
bdnguye2@uci.edu
c227fd87bad21b3935bdbc6acdf59f7ab7350b41
1d68c8a01ed498a99d4797f8c845b89d4bfe92c0
/VK9-Library/CVertexDeclaration9.h
d7fdba2c283135fedb83e4800056123160f84e4c
[ "Zlib" ]
permissive
lorendias/VK9
4edd16f4defaa470e208f2e9bf7237463e86c6a1
c788b63ac307dcae5891cf19b0a11a40a0e96d82
refs/heads/master
2020-05-09T19:20:58.189090
2019-04-14T03:19:11
2019-04-14T03:19:11
null
0
0
null
null
null
null
UTF-8
C++
false
false
2,582
h
#pragma once /* Copyright(c) 2016-2019 Christopher Joseph Dean Schaefer This software is provided 'as-is', without any express or implied warranty.In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions : 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software.If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include <vulkan/vulkan.hpp> #include <vulkan/vk_sdk_platform.h> #include "d3d9.h" #include <vector> class CDevice9; vk::Format ConvertDeclType(D3DDECLTYPE input) noexcept; uint32_t GetTextureCount(DWORD fvf) noexcept; class CVertexDeclaration9 : public IDirect3DVertexDeclaration9 { public: CVertexDeclaration9(CDevice9* device,const D3DVERTEXELEMENT9* pVertexElements); CVertexDeclaration9(CDevice9* device, DWORD fvf); ~CVertexDeclaration9(); //Reference Counting ULONG mReferenceCount = 1; ULONG mPrivateReferenceCount = 0; ULONG PrivateAddRef(void); ULONG PrivateRelease(void); //Creation Parameters std::vector<D3DVERTEXELEMENT9> mVertexElements; DWORD mFVF = 0; //Misc uint32_t mPositionSize = 3; BOOL mIsTransformed = 0; BOOL mHasPosition=0; BOOL mHasBlendWeight = 0; BOOL mHasBlendIndices = 0; BOOL mHasNormal = 0; BOOL mHasPSize = 0; size_t mTextureCount = 0; BOOL mHasTangent = 0; BOOL mHasBinormal = 0; BOOL mHasTessfactor = 0; BOOL mHasPositionT = 0; BOOL mHasColor1=0; BOOL mHasColor2=0; BOOL mHasFog = 0; BOOL mHasDepth = 0; BOOL mHasSample = 0; std::vector<vk::VertexInputAttributeDescription> mVertexInputAttributeDescription; private: CDevice9* mDevice; public: //IUnknown virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid,void **ppv); virtual ULONG STDMETHODCALLTYPE AddRef(void); virtual ULONG STDMETHODCALLTYPE Release(void); //IDirect3DVertexDeclaration9 virtual HRESULT STDMETHODCALLTYPE GetDeclaration(D3DVERTEXELEMENT9* pDecl, UINT* pNumElements); virtual HRESULT STDMETHODCALLTYPE GetDevice(IDirect3DDevice9** ppDevice); };
[ "disks86@gmail.com" ]
disks86@gmail.com
1bf6158d4778df4d204abe2699364432bdb10209
e1adcd0173cf849867144a511c029b8f5529b711
/ros_ws/install/include/baxter_maintenance_msgs/UpdateSource.h
01db0d7739d138f6ee9fb041e903ba16298fbf1d
[]
no_license
adubredu/cartbot_arm_subsystem
20a6e0c7bacc28dc0486160c6e25fede49f013f2
3e451272ddaf720bc7bd24da2ad5201b27248f1c
refs/heads/master
2022-01-04T23:01:25.061143
2019-05-14T16:45:02
2019-05-14T16:45:02
null
0
0
null
null
null
null
UTF-8
C++
false
false
6,794
h
// Generated by gencpp from file baxter_maintenance_msgs/UpdateSource.msg // DO NOT EDIT! #ifndef BAXTER_MAINTENANCE_MSGS_MESSAGE_UPDATESOURCE_H #define BAXTER_MAINTENANCE_MSGS_MESSAGE_UPDATESOURCE_H #include <string> #include <vector> #include <map> #include <ros/types.h> #include <ros/serialization.h> #include <ros/builtin_message_traits.h> #include <ros/message_operations.h> namespace baxter_maintenance_msgs { template <class ContainerAllocator> struct UpdateSource_ { typedef UpdateSource_<ContainerAllocator> Type; UpdateSource_() : devname() , filename() , version() , uuid() { } UpdateSource_(const ContainerAllocator& _alloc) : devname(_alloc) , filename(_alloc) , version(_alloc) , uuid(_alloc) { (void)_alloc; } typedef std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > _devname_type; _devname_type devname; typedef std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > _filename_type; _filename_type filename; typedef std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > _version_type; _version_type version; typedef std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > _uuid_type; _uuid_type uuid; typedef boost::shared_ptr< ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator> > Ptr; typedef boost::shared_ptr< ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator> const> ConstPtr; }; // struct UpdateSource_ typedef ::baxter_maintenance_msgs::UpdateSource_<std::allocator<void> > UpdateSource; typedef boost::shared_ptr< ::baxter_maintenance_msgs::UpdateSource > UpdateSourcePtr; typedef boost::shared_ptr< ::baxter_maintenance_msgs::UpdateSource const> UpdateSourceConstPtr; // constants requiring out of line definition template<typename ContainerAllocator> std::ostream& operator<<(std::ostream& s, const ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator> & v) { ros::message_operations::Printer< ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator> >::stream(s, "", v); return s; } } // namespace baxter_maintenance_msgs namespace ros { namespace message_traits { // BOOLTRAITS {'IsFixedSize': False, 'IsMessage': True, 'HasHeader': False} // {'baxter_maintenance_msgs': ['/home/bill/bill_ros/ros_ws/src/baxter_common/baxter_maintenance_msgs/msg'], 'std_msgs': ['/opt/ros/kinetic/share/std_msgs/cmake/../msg']} // !!!!!!!!!!! ['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_parsed_fields', 'constants', 'fields', 'full_name', 'has_header', 'header_present', 'names', 'package', 'parsed_fields', 'short_name', 'text', 'types'] template <class ContainerAllocator> struct IsFixedSize< ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator> > : FalseType { }; template <class ContainerAllocator> struct IsFixedSize< ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator> const> : FalseType { }; template <class ContainerAllocator> struct IsMessage< ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator> > : TrueType { }; template <class ContainerAllocator> struct IsMessage< ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator> const> : TrueType { }; template <class ContainerAllocator> struct HasHeader< ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator> > : FalseType { }; template <class ContainerAllocator> struct HasHeader< ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator> const> : FalseType { }; template<class ContainerAllocator> struct MD5Sum< ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator> > { static const char* value() { return "88ad69e3ed4d619e167c9d83e6d9310f"; } static const char* value(const ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator>&) { return value(); } static const uint64_t static_value1 = 0x88ad69e3ed4d619eULL; static const uint64_t static_value2 = 0x167c9d83e6d9310fULL; }; template<class ContainerAllocator> struct DataType< ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator> > { static const char* value() { return "baxter_maintenance_msgs/UpdateSource"; } static const char* value(const ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator>&) { return value(); } }; template<class ContainerAllocator> struct Definition< ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator> > { static const char* value() { return "string devname\n\ string filename\n\ string version\n\ string uuid\n\ "; } static const char* value(const ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator>&) { return value(); } }; } // namespace message_traits } // namespace ros namespace ros { namespace serialization { template<class ContainerAllocator> struct Serializer< ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator> > { template<typename Stream, typename T> inline static void allInOne(Stream& stream, T m) { stream.next(m.devname); stream.next(m.filename); stream.next(m.version); stream.next(m.uuid); } ROS_DECLARE_ALLINONE_SERIALIZER }; // struct UpdateSource_ } // namespace serialization } // namespace ros namespace ros { namespace message_operations { template<class ContainerAllocator> struct Printer< ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator> > { template<typename Stream> static void stream(Stream& s, const std::string& indent, const ::baxter_maintenance_msgs::UpdateSource_<ContainerAllocator>& v) { s << indent << "devname: "; Printer<std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > >::stream(s, indent + " ", v.devname); s << indent << "filename: "; Printer<std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > >::stream(s, indent + " ", v.filename); s << indent << "version: "; Printer<std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > >::stream(s, indent + " ", v.version); s << indent << "uuid: "; Printer<std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > >::stream(s, indent + " ", v.uuid); } }; } // namespace message_operations } // namespace ros #endif // BAXTER_MAINTENANCE_MSGS_MESSAGE_UPDATESOURCE_H
[ "alphonsusbq436@gmail.com" ]
alphonsusbq436@gmail.com
bb366dd7995357dcb2fe21bff61c83d1e3037f46
3fcc27c255db2da950af5b9b08c7e4cceea2ef75
/src/rpcwallet.cpp
3a7cd1b2664f0b871c8937a1c20e732b288775de
[ "MIT" ]
permissive
legendcoin/legendcoin
dfda212512f9c31b335cb9f169241c9cdfa93f34
5eeb4ef47dacece3a314d4944217b36a1f2e71c1
refs/heads/master
2021-01-10T20:49:46.572694
2014-05-14T09:52:43
2014-05-14T09:52:43
null
0
0
null
null
null
null
UTF-8
C++
false
false
55,117
cpp
// Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <boost/assign/list_of.hpp> #include "wallet.h" #include "walletdb.h" #include "bitcoinrpc.h" #include "init.h" #include "base58.h" using namespace std; using namespace boost; using namespace boost::assign; using namespace json_spirit; int64 nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime; std::string HelpRequiringPassphrase() { return pwalletMain && pwalletMain->IsCrypted() ? "\nrequires wallet passphrase to be set with walletpassphrase first" : ""; } void EnsureWalletIsUnlocked() { if (pwalletMain->IsLocked()) throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); } void WalletTxToJSON(const CWalletTx& wtx, Object& entry) { int confirms = wtx.GetDepthInMainChain(); entry.push_back(Pair("confirmations", confirms)); if (wtx.IsCoinBase()) entry.push_back(Pair("generated", true)); if (confirms > 0) { entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex())); entry.push_back(Pair("blockindex", wtx.nIndex)); entry.push_back(Pair("blocktime", (boost::int64_t)(mapBlockIndex[wtx.hashBlock]->nTime))); } entry.push_back(Pair("txid", wtx.GetHash().GetHex())); entry.push_back(Pair("normtxid", wtx.GetNormalizedHash().GetHex())); entry.push_back(Pair("time", (boost::int64_t)wtx.GetTxTime())); entry.push_back(Pair("timereceived", (boost::int64_t)wtx.nTimeReceived)); BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue) entry.push_back(Pair(item.first, item.second)); } string AccountFromValue(const Value& value) { string strAccount = value.get_str(); if (strAccount == "*") throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Invalid account name"); return strAccount; } Value getinfo(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) throw runtime_error( "getinfo\n" "Returns an object containing various state info."); proxyType proxy; GetProxy(NET_IPV4, proxy); Object obj; obj.push_back(Pair("version", (int)CLIENT_VERSION)); obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION)); if (pwalletMain) { obj.push_back(Pair("walletversion", pwalletMain->GetVersion())); obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance()))); } obj.push_back(Pair("blocks", (int)nBestHeight)); obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset())); obj.push_back(Pair("connections", (int)vNodes.size())); obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string()))); obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("testnet", fTestNet)); if (pwalletMain) { obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime())); obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize())); } obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee))); obj.push_back(Pair("mininput", ValueFromAmount(nMinimumInputValue))); if (pwalletMain && pwalletMain->IsCrypted()) obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime)); obj.push_back(Pair("errors", GetWarnings("statusbar"))); return obj; } Value getnewaddress(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) throw runtime_error( "getnewaddress [account]\n" "Returns a new Legendcoin address for receiving payments. " "If [account] is specified (recommended), it is added to the address book " "so payments received with the address will be credited to [account]."); // Parse the account first so we don't generate a key if there's an error string strAccount; if (params.size() > 0) strAccount = AccountFromValue(params[0]); if (!pwalletMain->IsLocked()) pwalletMain->TopUpKeyPool(); // Generate a new key that is added to wallet CPubKey newKey; if (!pwalletMain->GetKeyFromPool(newKey, false)) throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first"); CKeyID keyID = newKey.GetID(); pwalletMain->SetAddressBookName(keyID, strAccount); return CBitcoinAddress(keyID).ToString(); } CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false) { CWalletDB walletdb(pwalletMain->strWalletFile); CAccount account; walletdb.ReadAccount(strAccount, account); bool bKeyUsed = false; // Check if the current key has been used if (account.vchPubKey.IsValid()) { CScript scriptPubKey; scriptPubKey.SetDestination(account.vchPubKey.GetID()); for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end() && account.vchPubKey.IsValid(); ++it) { const CWalletTx& wtx = (*it).second; BOOST_FOREACH(const CTxOut& txout, wtx.vout) if (txout.scriptPubKey == scriptPubKey) bKeyUsed = true; } } // Generate a new key if (!account.vchPubKey.IsValid() || bForceNew || bKeyUsed) { if (!pwalletMain->GetKeyFromPool(account.vchPubKey, false)) throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first"); pwalletMain->SetAddressBookName(account.vchPubKey.GetID(), strAccount); walletdb.WriteAccount(strAccount, account); } return CBitcoinAddress(account.vchPubKey.GetID()); } Value getaccountaddress(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( "getaccountaddress <account>\n" "Returns the current Legendcoin address for receiving payments to this account."); // Parse the account first so we don't generate a key if there's an error string strAccount = AccountFromValue(params[0]); Value ret; ret = GetAccountAddress(strAccount).ToString(); return ret; } Value setaccount(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( "setaccount <legendcoinaddress> <account>\n" "Sets the account associated with the given address."); CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Legendcoin address"); string strAccount; if (params.size() > 1) strAccount = AccountFromValue(params[1]); // Detect when changing the account of an address that is the 'unused current key' of another account: if (pwalletMain->mapAddressBook.count(address.Get())) { string strOldAccount = pwalletMain->mapAddressBook[address.Get()]; if (address == GetAccountAddress(strOldAccount)) GetAccountAddress(strOldAccount, true); } pwalletMain->SetAddressBookName(address.Get(), strAccount); return Value::null; } Value getaccount(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( "getaccount <legendcoinaddress>\n" "Returns the account associated with the given address."); CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Legendcoin address"); string strAccount; map<CTxDestination, string>::iterator mi = pwalletMain->mapAddressBook.find(address.Get()); if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.empty()) strAccount = (*mi).second; return strAccount; } Value getaddressesbyaccount(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( "getaddressesbyaccount <account>\n" "Returns the list of addresses for the given account."); string strAccount = AccountFromValue(params[0]); // Find all addresses that have the given account Array ret; BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, string)& item, pwalletMain->mapAddressBook) { const CBitcoinAddress& address = item.first; const string& strName = item.second; if (strName == strAccount) ret.push_back(address.ToString()); } return ret; } Value setmininput(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 1) throw runtime_error( "setmininput <amount>\n" "<amount> is a real and is rounded to the nearest 0.00000001"); // Amount int64 nAmount = 0; if (params[0].get_real() != 0.0) nAmount = AmountFromValue(params[0]); // rejects 0.0 amounts nMinimumInputValue = nAmount; return true; } Value sendtoaddress(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 4) throw runtime_error( "sendtoaddress <legendcoinaddress> <amount> [comment] [comment-to]\n" "<amount> is a real and is rounded to the nearest 0.00000001" + HelpRequiringPassphrase()); CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Legendcoin address"); // Amount int64 nAmount = AmountFromValue(params[1]); // Wallet comments CWalletTx wtx; if (params.size() > 2 && params[2].type() != null_type && !params[2].get_str().empty()) wtx.mapValue["comment"] = params[2].get_str(); if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty()) wtx.mapValue["to"] = params[3].get_str(); if (pwalletMain->IsLocked()) throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx); if (strError != "") throw JSONRPCError(RPC_WALLET_ERROR, strError); return wtx.GetHash().GetHex(); } Value listaddressgroupings(const Array& params, bool fHelp) { if (fHelp) throw runtime_error( "listaddressgroupings\n" "Lists groups of addresses which have had their common ownership\n" "made public by common use as inputs or as the resulting change\n" "in past transactions"); Array jsonGroupings; map<CTxDestination, int64> balances = pwalletMain->GetAddressBalances(); BOOST_FOREACH(set<CTxDestination> grouping, pwalletMain->GetAddressGroupings()) { Array jsonGrouping; BOOST_FOREACH(CTxDestination address, grouping) { Array addressInfo; addressInfo.push_back(CBitcoinAddress(address).ToString()); addressInfo.push_back(ValueFromAmount(balances[address])); { LOCK(pwalletMain->cs_wallet); if (pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get()) != pwalletMain->mapAddressBook.end()) addressInfo.push_back(pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get())->second); } jsonGrouping.push_back(addressInfo); } jsonGroupings.push_back(jsonGrouping); } return jsonGroupings; } Value signmessage(const Array& params, bool fHelp) { if (fHelp || params.size() != 2) throw runtime_error( "signmessage <legendcoinaddress> <message>\n" "Sign a message with the private key of an address"); EnsureWalletIsUnlocked(); string strAddress = params[0].get_str(); string strMessage = params[1].get_str(); CBitcoinAddress addr(strAddress); if (!addr.IsValid()) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address"); CKeyID keyID; if (!addr.GetKeyID(keyID)) throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); CKey key; if (!pwalletMain->GetKey(keyID, key)) throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available"); CHashWriter ss(SER_GETHASH, 0); ss << strMessageMagic; ss << strMessage; vector<unsigned char> vchSig; if (!key.SignCompact(ss.GetHash(), vchSig)) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed"); return EncodeBase64(&vchSig[0], vchSig.size()); } Value verifymessage(const Array& params, bool fHelp) { if (fHelp || params.size() != 3) throw runtime_error( "verifymessage <legendcoinaddress> <signature> <message>\n" "Verify a signed message"); string strAddress = params[0].get_str(); string strSign = params[1].get_str(); string strMessage = params[2].get_str(); CBitcoinAddress addr(strAddress); if (!addr.IsValid()) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address"); CKeyID keyID; if (!addr.GetKeyID(keyID)) throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); bool fInvalid = false; vector<unsigned char> vchSig = DecodeBase64(strSign.c_str(), &fInvalid); if (fInvalid) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding"); CHashWriter ss(SER_GETHASH, 0); ss << strMessageMagic; ss << strMessage; CPubKey pubkey; if (!pubkey.RecoverCompact(ss.GetHash(), vchSig)) return false; return (pubkey.GetID() == keyID); } Value getreceivedbyaddress(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( "getreceivedbyaddress <legendcoinaddress> [minconf=1]\n" "Returns the total amount received by <legendcoinaddress> in transactions with at least [minconf] confirmations."); // Bitcoin address CBitcoinAddress address = CBitcoinAddress(params[0].get_str()); CScript scriptPubKey; if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Legendcoin address"); scriptPubKey.SetDestination(address.Get()); if (!IsMine(*pwalletMain,scriptPubKey)) return (double)0.0; // Minimum confirmations int nMinDepth = 1; if (params.size() > 1) nMinDepth = params[1].get_int(); // Tally int64 nAmount = 0; for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; if (wtx.IsCoinBase() || !wtx.IsFinal()) continue; BOOST_FOREACH(const CTxOut& txout, wtx.vout) if (txout.scriptPubKey == scriptPubKey) if (wtx.GetDepthInMainChain() >= nMinDepth) nAmount += txout.nValue; } return ValueFromAmount(nAmount); } void GetAccountAddresses(string strAccount, set<CTxDestination>& setAddress) { BOOST_FOREACH(const PAIRTYPE(CTxDestination, string)& item, pwalletMain->mapAddressBook) { const CTxDestination& address = item.first; const string& strName = item.second; if (strName == strAccount) setAddress.insert(address); } } Value getreceivedbyaccount(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( "getreceivedbyaccount <account> [minconf=1]\n" "Returns the total amount received by addresses with <account> in transactions with at least [minconf] confirmations."); // Minimum confirmations int nMinDepth = 1; if (params.size() > 1) nMinDepth = params[1].get_int(); // Get the set of pub keys assigned to account string strAccount = AccountFromValue(params[0]); set<CTxDestination> setAddress; GetAccountAddresses(strAccount, setAddress); // Tally int64 nAmount = 0; for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; if (wtx.IsCoinBase() || !wtx.IsFinal()) continue; BOOST_FOREACH(const CTxOut& txout, wtx.vout) { CTxDestination address; if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*pwalletMain, address) && setAddress.count(address)) if (wtx.GetDepthInMainChain() >= nMinDepth) nAmount += txout.nValue; } } return (double)nAmount / (double)COIN; } int64 GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth) { int64 nBalance = 0; // Tally wallet transactions for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; if (!wtx.IsFinal()) continue; int64 nReceived, nSent, nFee; wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee); if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth) nBalance += nReceived; nBalance -= nSent + nFee; } // Tally internal accounting entries nBalance += walletdb.GetAccountCreditDebit(strAccount); return nBalance; } int64 GetAccountBalance(const string& strAccount, int nMinDepth) { CWalletDB walletdb(pwalletMain->strWalletFile); return GetAccountBalance(walletdb, strAccount, nMinDepth); } Value getbalance(const Array& params, bool fHelp) { if (fHelp || params.size() > 2) throw runtime_error( "getbalance [account] [minconf=1]\n" "If [account] is not specified, returns the server's total available balance.\n" "If [account] is specified, returns the balance in the account."); if (params.size() == 0) return ValueFromAmount(pwalletMain->GetBalance()); int nMinDepth = 1; if (params.size() > 1) nMinDepth = params[1].get_int(); if (params[0].get_str() == "*") { // Calculate total balance a different way from GetBalance() // (GetBalance() sums up all unspent TxOuts) // getbalance and getbalance '*' 0 should return the same number int64 nBalance = 0; for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; if (!wtx.IsConfirmed()) continue; int64 allFee; string strSentAccount; list<pair<CTxDestination, int64> > listReceived; list<pair<CTxDestination, int64> > listSent; wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount); if (wtx.GetDepthInMainChain() >= nMinDepth) { BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64)& r, listReceived) nBalance += r.second; } BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64)& r, listSent) nBalance -= r.second; nBalance -= allFee; } return ValueFromAmount(nBalance); } string strAccount = AccountFromValue(params[0]); int64 nBalance = GetAccountBalance(strAccount, nMinDepth); return ValueFromAmount(nBalance); } Value movecmd(const Array& params, bool fHelp) { if (fHelp || params.size() < 3 || params.size() > 5) throw runtime_error( "move <fromaccount> <toaccount> <amount> [minconf=1] [comment]\n" "Move from one account in your wallet to another."); string strFrom = AccountFromValue(params[0]); string strTo = AccountFromValue(params[1]); int64 nAmount = AmountFromValue(params[2]); if (params.size() > 3) // unused parameter, used to be nMinDepth, keep type-checking it though (void)params[3].get_int(); string strComment; if (params.size() > 4) strComment = params[4].get_str(); CWalletDB walletdb(pwalletMain->strWalletFile); if (!walletdb.TxnBegin()) throw JSONRPCError(RPC_DATABASE_ERROR, "database error"); int64 nNow = GetAdjustedTime(); // Debit CAccountingEntry debit; debit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb); debit.strAccount = strFrom; debit.nCreditDebit = -nAmount; debit.nTime = nNow; debit.strOtherAccount = strTo; debit.strComment = strComment; walletdb.WriteAccountingEntry(debit); // Credit CAccountingEntry credit; credit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb); credit.strAccount = strTo; credit.nCreditDebit = nAmount; credit.nTime = nNow; credit.strOtherAccount = strFrom; credit.strComment = strComment; walletdb.WriteAccountingEntry(credit); if (!walletdb.TxnCommit()) throw JSONRPCError(RPC_DATABASE_ERROR, "database error"); return true; } Value sendfrom(const Array& params, bool fHelp) { if (fHelp || params.size() < 3 || params.size() > 6) throw runtime_error( "sendfrom <fromaccount> <tolegendcoinaddress> <amount> [minconf=1] [comment] [comment-to]\n" "<amount> is a real and is rounded to the nearest 0.00000001" + HelpRequiringPassphrase()); string strAccount = AccountFromValue(params[0]); CBitcoinAddress address(params[1].get_str()); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Legendcoin address"); int64 nAmount = AmountFromValue(params[2]); int nMinDepth = 1; if (params.size() > 3) nMinDepth = params[3].get_int(); CWalletTx wtx; wtx.strFromAccount = strAccount; if (params.size() > 4 && params[4].type() != null_type && !params[4].get_str().empty()) wtx.mapValue["comment"] = params[4].get_str(); if (params.size() > 5 && params[5].type() != null_type && !params[5].get_str().empty()) wtx.mapValue["to"] = params[5].get_str(); EnsureWalletIsUnlocked(); // Check funds int64 nBalance = GetAccountBalance(strAccount, nMinDepth); if (nAmount > nBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); // Send string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx); if (strError != "") throw JSONRPCError(RPC_WALLET_ERROR, strError); return wtx.GetHash().GetHex(); } Value sendmany(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 4) throw runtime_error( "sendmany <fromaccount> {address:amount,...} [minconf=1] [comment]\n" "amounts are double-precision floating point numbers" + HelpRequiringPassphrase()); string strAccount = AccountFromValue(params[0]); Object sendTo = params[1].get_obj(); int nMinDepth = 1; if (params.size() > 2) nMinDepth = params[2].get_int(); CWalletTx wtx; wtx.strFromAccount = strAccount; if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty()) wtx.mapValue["comment"] = params[3].get_str(); set<CBitcoinAddress> setAddress; vector<pair<CScript, int64> > vecSend; int64 totalAmount = 0; BOOST_FOREACH(const Pair& s, sendTo) { CBitcoinAddress address(s.name_); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Legendcoin address: ")+s.name_); if (setAddress.count(address)) throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+s.name_); setAddress.insert(address); CScript scriptPubKey; scriptPubKey.SetDestination(address.Get()); int64 nAmount = AmountFromValue(s.value_); totalAmount += nAmount; vecSend.push_back(make_pair(scriptPubKey, nAmount)); } EnsureWalletIsUnlocked(); // Check funds int64 nBalance = GetAccountBalance(strAccount, nMinDepth); if (totalAmount > nBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); // Send CReserveKey keyChange(pwalletMain); int64 nFeeRequired = 0; string strFailReason; bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason); if (!fCreated) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason); if (!pwalletMain->CommitTransaction(wtx, keyChange)) throw JSONRPCError(RPC_WALLET_ERROR, "Transaction commit failed"); return wtx.GetHash().GetHex(); } // // Used by addmultisigaddress / createmultisig: // static CScript _createmultisig(const Array& params) { int nRequired = params[0].get_int(); const Array& keys = params[1].get_array(); // Gather public keys if (nRequired < 1) throw runtime_error("a multisignature address must require at least one key to redeem"); if ((int)keys.size() < nRequired) throw runtime_error( strprintf("not enough keys supplied " "(got %"PRIszu" keys, but need at least %d to redeem)", keys.size(), nRequired)); std::vector<CPubKey> pubkeys; pubkeys.resize(keys.size()); for (unsigned int i = 0; i < keys.size(); i++) { const std::string& ks = keys[i].get_str(); // Case 1: Legendcoin address and we have full public key: CBitcoinAddress address(ks); if (pwalletMain && address.IsValid()) { CKeyID keyID; if (!address.GetKeyID(keyID)) throw runtime_error( strprintf("%s does not refer to a key",ks.c_str())); CPubKey vchPubKey; if (!pwalletMain->GetPubKey(keyID, vchPubKey)) throw runtime_error( strprintf("no full public key for address %s",ks.c_str())); if (!vchPubKey.IsFullyValid()) throw runtime_error(" Invalid public key: "+ks); pubkeys[i] = vchPubKey; } // Case 2: hex public key else if (IsHex(ks)) { CPubKey vchPubKey(ParseHex(ks)); if (!vchPubKey.IsFullyValid()) throw runtime_error(" Invalid public key: "+ks); pubkeys[i] = vchPubKey; } else { throw runtime_error(" Invalid public key: "+ks); } } CScript result; result.SetMultisig(nRequired, pubkeys); return result; } Value addmultisigaddress(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 3) { string msg = "addmultisigaddress <nrequired> <'[\"key\",\"key\"]'> [account]\n" "Add a nrequired-to-sign multisignature address to the wallet\"\n" "each key is a Legendcoin address or hex-encoded public key\n" "If [account] is specified, assign address to [account]."; throw runtime_error(msg); } string strAccount; if (params.size() > 2) strAccount = AccountFromValue(params[2]); // Construct using pay-to-script-hash: CScript inner = _createmultisig(params); CScriptID innerID = inner.GetID(); pwalletMain->AddCScript(inner); pwalletMain->SetAddressBookName(innerID, strAccount); return CBitcoinAddress(innerID).ToString(); } Value createmultisig(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 2) { string msg = "createmultisig <nrequired> <'[\"key\",\"key\"]'>\n" "Creates a multi-signature address and returns a json object\n" "with keys:\n" "address : legendcoin address\n" "redeemScript : hex-encoded redemption script"; throw runtime_error(msg); } // Construct using pay-to-script-hash: CScript inner = _createmultisig(params); CScriptID innerID = inner.GetID(); CBitcoinAddress address(innerID); Object result; result.push_back(Pair("address", address.ToString())); result.push_back(Pair("redeemScript", HexStr(inner.begin(), inner.end()))); return result; } struct tallyitem { int64 nAmount; int nConf; vector<uint256> txids; tallyitem() { nAmount = 0; nConf = std::numeric_limits<int>::max(); } }; Value ListReceived(const Array& params, bool fByAccounts) { // Minimum confirmations int nMinDepth = 1; if (params.size() > 0) nMinDepth = params[0].get_int(); // Whether to include empty accounts bool fIncludeEmpty = false; if (params.size() > 1) fIncludeEmpty = params[1].get_bool(); // Tally map<CBitcoinAddress, tallyitem> mapTally; for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; if (wtx.IsCoinBase() || !wtx.IsFinal()) continue; int nDepth = wtx.GetDepthInMainChain(); if (nDepth < nMinDepth) continue; BOOST_FOREACH(const CTxOut& txout, wtx.vout) { CTxDestination address; if (!ExtractDestination(txout.scriptPubKey, address) || !IsMine(*pwalletMain, address)) continue; tallyitem& item = mapTally[address]; item.nAmount += txout.nValue; item.nConf = min(item.nConf, nDepth); item.txids.push_back(wtx.GetHash()); } } // Reply Array ret; map<string, tallyitem> mapAccountTally; BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, string)& item, pwalletMain->mapAddressBook) { const CBitcoinAddress& address = item.first; const string& strAccount = item.second; map<CBitcoinAddress, tallyitem>::iterator it = mapTally.find(address); if (it == mapTally.end() && !fIncludeEmpty) continue; int64 nAmount = 0; int nConf = std::numeric_limits<int>::max(); if (it != mapTally.end()) { nAmount = (*it).second.nAmount; nConf = (*it).second.nConf; } if (fByAccounts) { tallyitem& item = mapAccountTally[strAccount]; item.nAmount += nAmount; item.nConf = min(item.nConf, nConf); } else { Object obj; obj.push_back(Pair("address", address.ToString())); obj.push_back(Pair("account", strAccount)); obj.push_back(Pair("amount", ValueFromAmount(nAmount))); obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf))); Array transactions; if (it != mapTally.end()) { BOOST_FOREACH(const uint256& item, (*it).second.txids) { transactions.push_back(item.GetHex()); } } obj.push_back(Pair("txids", transactions)); ret.push_back(obj); } } if (fByAccounts) { for (map<string, tallyitem>::iterator it = mapAccountTally.begin(); it != mapAccountTally.end(); ++it) { int64 nAmount = (*it).second.nAmount; int nConf = (*it).second.nConf; Object obj; obj.push_back(Pair("account", (*it).first)); obj.push_back(Pair("amount", ValueFromAmount(nAmount))); obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf))); ret.push_back(obj); } } return ret; } Value listreceivedbyaddress(const Array& params, bool fHelp) { if (fHelp || params.size() > 2) throw runtime_error( "listreceivedbyaddress [minconf=1] [includeempty=false]\n" "[minconf] is the minimum number of confirmations before payments are included.\n" "[includeempty] whether to include addresses that haven't received any payments.\n" "Returns an array of objects containing:\n" " \"address\" : receiving address\n" " \"account\" : the account of the receiving address\n" " \"amount\" : total amount received by the address\n" " \"confirmations\" : number of confirmations of the most recent transaction included\n" " \"txids\" : list of transactions with outputs to the address\n"); return ListReceived(params, false); } Value listreceivedbyaccount(const Array& params, bool fHelp) { if (fHelp || params.size() > 2) throw runtime_error( "listreceivedbyaccount [minconf=1] [includeempty=false]\n" "[minconf] is the minimum number of confirmations before payments are included.\n" "[includeempty] whether to include accounts that haven't received any payments.\n" "Returns an array of objects containing:\n" " \"account\" : the account of the receiving addresses\n" " \"amount\" : total amount received by addresses with this account\n" " \"confirmations\" : number of confirmations of the most recent transaction included"); return ListReceived(params, true); } static void MaybePushAddress(Object & entry, const CTxDestination &dest) { CBitcoinAddress addr; if (addr.Set(dest)) entry.push_back(Pair("address", addr.ToString())); } void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret) { int64 nFee; string strSentAccount; list<pair<CTxDestination, int64> > listReceived; list<pair<CTxDestination, int64> > listSent; wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount); bool fAllAccounts = (strAccount == string("*")); // Sent if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount)) { BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& s, listSent) { Object entry; entry.push_back(Pair("account", strSentAccount)); MaybePushAddress(entry, s.first); entry.push_back(Pair("category", "send")); entry.push_back(Pair("amount", ValueFromAmount(-s.second))); entry.push_back(Pair("fee", ValueFromAmount(-nFee))); if (fLong) WalletTxToJSON(wtx, entry); ret.push_back(entry); } } // Received if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) { BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& r, listReceived) { string account; if (pwalletMain->mapAddressBook.count(r.first)) account = pwalletMain->mapAddressBook[r.first]; if (fAllAccounts || (account == strAccount)) { Object entry; entry.push_back(Pair("account", account)); MaybePushAddress(entry, r.first); if (wtx.IsCoinBase()) { if (wtx.GetDepthInMainChain() < 1) entry.push_back(Pair("category", "orphan")); else if (wtx.GetBlocksToMaturity() > 0) entry.push_back(Pair("category", "immature")); else entry.push_back(Pair("category", "generate")); } else { entry.push_back(Pair("category", "receive")); } entry.push_back(Pair("amount", ValueFromAmount(r.second))); if (fLong) WalletTxToJSON(wtx, entry); ret.push_back(entry); } } } } void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Array& ret) { bool fAllAccounts = (strAccount == string("*")); if (fAllAccounts || acentry.strAccount == strAccount) { Object entry; entry.push_back(Pair("account", acentry.strAccount)); entry.push_back(Pair("category", "move")); entry.push_back(Pair("time", (boost::int64_t)acentry.nTime)); entry.push_back(Pair("amount", ValueFromAmount(acentry.nCreditDebit))); entry.push_back(Pair("otheraccount", acentry.strOtherAccount)); entry.push_back(Pair("comment", acentry.strComment)); ret.push_back(entry); } } Value listtransactions(const Array& params, bool fHelp) { if (fHelp || params.size() > 3) throw runtime_error( "listtransactions [account] [count=10] [from=0]\n" "Returns up to [count] most recent transactions skipping the first [from] transactions for account [account]."); string strAccount = "*"; if (params.size() > 0) strAccount = params[0].get_str(); int nCount = 10; if (params.size() > 1) nCount = params[1].get_int(); int nFrom = 0; if (params.size() > 2) nFrom = params[2].get_int(); if (nCount < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count"); if (nFrom < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from"); Array ret; std::list<CAccountingEntry> acentries; CWallet::TxItems txOrdered = pwalletMain->OrderedTxItems(acentries, strAccount); // iterate backwards until we have nCount items to return: for (CWallet::TxItems::reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) { CWalletTx *const pwtx = (*it).second.first; if (pwtx != 0) ListTransactions(*pwtx, strAccount, 0, true, ret); CAccountingEntry *const pacentry = (*it).second.second; if (pacentry != 0) AcentryToJSON(*pacentry, strAccount, ret); if ((int)ret.size() >= (nCount+nFrom)) break; } // ret is newest to oldest if (nFrom > (int)ret.size()) nFrom = ret.size(); if ((nFrom + nCount) > (int)ret.size()) nCount = ret.size() - nFrom; Array::iterator first = ret.begin(); std::advance(first, nFrom); Array::iterator last = ret.begin(); std::advance(last, nFrom+nCount); if (last != ret.end()) ret.erase(last, ret.end()); if (first != ret.begin()) ret.erase(ret.begin(), first); std::reverse(ret.begin(), ret.end()); // Return oldest to newest return ret; } Value listaccounts(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) throw runtime_error( "listaccounts [minconf=1]\n" "Returns Object that has account names as keys, account balances as values."); int nMinDepth = 1; if (params.size() > 0) nMinDepth = params[0].get_int(); map<string, int64> mapAccountBalances; BOOST_FOREACH(const PAIRTYPE(CTxDestination, string)& entry, pwalletMain->mapAddressBook) { if (IsMine(*pwalletMain, entry.first)) // This address belongs to me mapAccountBalances[entry.second] = 0; } for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; int64 nFee; string strSentAccount; list<pair<CTxDestination, int64> > listReceived; list<pair<CTxDestination, int64> > listSent; wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount); mapAccountBalances[strSentAccount] -= nFee; BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& s, listSent) mapAccountBalances[strSentAccount] -= s.second; if (wtx.GetDepthInMainChain() >= nMinDepth) { BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& r, listReceived) if (pwalletMain->mapAddressBook.count(r.first)) mapAccountBalances[pwalletMain->mapAddressBook[r.first]] += r.second; else mapAccountBalances[""] += r.second; } } list<CAccountingEntry> acentries; CWalletDB(pwalletMain->strWalletFile).ListAccountCreditDebit("*", acentries); BOOST_FOREACH(const CAccountingEntry& entry, acentries) mapAccountBalances[entry.strAccount] += entry.nCreditDebit; Object ret; BOOST_FOREACH(const PAIRTYPE(string, int64)& accountBalance, mapAccountBalances) { ret.push_back(Pair(accountBalance.first, ValueFromAmount(accountBalance.second))); } return ret; } Value listsinceblock(const Array& params, bool fHelp) { if (fHelp) throw runtime_error( "listsinceblock [blockhash] [target-confirmations]\n" "Get all transactions in blocks since block [blockhash], or all transactions if omitted"); CBlockIndex *pindex = NULL; int target_confirms = 1; if (params.size() > 0) { uint256 blockId = 0; blockId.SetHex(params[0].get_str()); pindex = CBlockLocator(blockId).GetBlockIndex(); } if (params.size() > 1) { target_confirms = params[1].get_int(); if (target_confirms < 1) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter"); } int depth = pindex ? (1 + nBestHeight - pindex->nHeight) : -1; Array transactions; for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); it++) { CWalletTx tx = (*it).second; if (depth == -1 || tx.GetDepthInMainChain() < depth) ListTransactions(tx, "*", 0, true, transactions); } uint256 lastblock; if (target_confirms == 1) { lastblock = hashBestChain; } else { int target_height = pindexBest->nHeight + 1 - target_confirms; CBlockIndex *block; for (block = pindexBest; block && block->nHeight > target_height; block = block->pprev) { } lastblock = block ? block->GetBlockHash() : 0; } Object ret; ret.push_back(Pair("transactions", transactions)); ret.push_back(Pair("lastblock", lastblock.GetHex())); return ret; } Value gettransaction(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( "gettransaction <txid>\n" "Get detailed information about in-wallet transaction <txid>"); uint256 hash; hash.SetHex(params[0].get_str()); Object entry; if (!pwalletMain->mapWallet.count(hash)) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id"); const CWalletTx& wtx = pwalletMain->mapWallet[hash]; int64 nCredit = wtx.GetCredit(); int64 nDebit = wtx.GetDebit(); int64 nNet = nCredit - nDebit; int64 nFee = (wtx.IsFromMe() ? wtx.GetValueOut() - nDebit : 0); entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee))); if (wtx.IsFromMe()) entry.push_back(Pair("fee", ValueFromAmount(nFee))); WalletTxToJSON(wtx, entry); Array details; ListTransactions(wtx, "*", 0, false, details); entry.push_back(Pair("details", details)); return entry; } Value backupwallet(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( "backupwallet <destination>\n" "Safely copies wallet.dat to destination, which can be a directory or a path with filename."); string strDest = params[0].get_str(); if (!BackupWallet(*pwalletMain, strDest)) throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!"); return Value::null; } Value keypoolrefill(const Array& params, bool fHelp) { if (fHelp || params.size() > 0) throw runtime_error( "keypoolrefill\n" "Fills the keypool." + HelpRequiringPassphrase()); EnsureWalletIsUnlocked(); pwalletMain->TopUpKeyPool(); if (pwalletMain->GetKeyPoolSize() < GetArg("-keypool", 100)) throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool."); return Value::null; } void ThreadTopUpKeyPool(void* parg) { // Make this thread recognisable as the key-topping-up thread RenameThread("bitcoin-key-top"); pwalletMain->TopUpKeyPool(); } void ThreadCleanWalletPassphrase(void* parg) { // Make this thread recognisable as the wallet relocking thread RenameThread("bitcoin-lock-wa"); int64 nMyWakeTime = GetTimeMillis() + *((int64*)parg) * 1000; ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime); if (nWalletUnlockTime == 0) { nWalletUnlockTime = nMyWakeTime; do { if (nWalletUnlockTime==0) break; int64 nToSleep = nWalletUnlockTime - GetTimeMillis(); if (nToSleep <= 0) break; LEAVE_CRITICAL_SECTION(cs_nWalletUnlockTime); MilliSleep(nToSleep); ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime); } while(1); if (nWalletUnlockTime) { nWalletUnlockTime = 0; pwalletMain->Lock(); } } else { if (nWalletUnlockTime < nMyWakeTime) nWalletUnlockTime = nMyWakeTime; } LEAVE_CRITICAL_SECTION(cs_nWalletUnlockTime); delete (int64*)parg; } Value walletpassphrase(const Array& params, bool fHelp) { if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2)) throw runtime_error( "walletpassphrase <passphrase> <timeout>\n" "Stores the wallet decryption key in memory for <timeout> seconds."); if (fHelp) return true; if (!pwalletMain->IsCrypted()) throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrase was called."); if (!pwalletMain->IsLocked()) throw JSONRPCError(RPC_WALLET_ALREADY_UNLOCKED, "Error: Wallet is already unlocked."); // Note that the walletpassphrase is stored in params[0] which is not mlock()ed SecureString strWalletPass; strWalletPass.reserve(100); // TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string) // Alternately, find a way to make params[0] mlock()'d to begin with. strWalletPass = params[0].get_str().c_str(); if (strWalletPass.length() > 0) { if (!pwalletMain->Unlock(strWalletPass)) throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect."); } else throw runtime_error( "walletpassphrase <passphrase> <timeout>\n" "Stores the wallet decryption key in memory for <timeout> seconds."); NewThread(ThreadTopUpKeyPool, NULL); int64* pnSleepTime = new int64(params[1].get_int64()); NewThread(ThreadCleanWalletPassphrase, pnSleepTime); return Value::null; } Value walletpassphrasechange(const Array& params, bool fHelp) { if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2)) throw runtime_error( "walletpassphrasechange <oldpassphrase> <newpassphrase>\n" "Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>."); if (fHelp) return true; if (!pwalletMain->IsCrypted()) throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called."); // TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string) // Alternately, find a way to make params[0] mlock()'d to begin with. SecureString strOldWalletPass; strOldWalletPass.reserve(100); strOldWalletPass = params[0].get_str().c_str(); SecureString strNewWalletPass; strNewWalletPass.reserve(100); strNewWalletPass = params[1].get_str().c_str(); if (strOldWalletPass.length() < 1 || strNewWalletPass.length() < 1) throw runtime_error( "walletpassphrasechange <oldpassphrase> <newpassphrase>\n" "Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>."); if (!pwalletMain->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect."); return Value::null; } Value walletlock(const Array& params, bool fHelp) { if (pwalletMain->IsCrypted() && (fHelp || params.size() != 0)) throw runtime_error( "walletlock\n" "Removes the wallet encryption key from memory, locking the wallet.\n" "After calling this method, you will need to call walletpassphrase again\n" "before being able to call any methods which require the wallet to be unlocked."); if (fHelp) return true; if (!pwalletMain->IsCrypted()) throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called."); { LOCK(cs_nWalletUnlockTime); pwalletMain->Lock(); nWalletUnlockTime = 0; } return Value::null; } Value encryptwallet(const Array& params, bool fHelp) { if (!pwalletMain->IsCrypted() && (fHelp || params.size() != 1)) throw runtime_error( "encryptwallet <passphrase>\n" "Encrypts the wallet with <passphrase>."); if (fHelp) return true; if (pwalletMain->IsCrypted()) throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called."); // TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string) // Alternately, find a way to make params[0] mlock()'d to begin with. SecureString strWalletPass; strWalletPass.reserve(100); strWalletPass = params[0].get_str().c_str(); if (strWalletPass.length() < 1) throw runtime_error( "encryptwallet <passphrase>\n" "Encrypts the wallet with <passphrase>."); if (!pwalletMain->EncryptWallet(strWalletPass)) throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet."); // BDB seems to have a bad habit of writing old data into // slack space in .dat files; that is bad if the old data is // unencrypted private keys. So: StartShutdown(); return "wallet encrypted; Legendcoin server stopping, restart to run with encrypted wallet. The keypool has been flushed, you need to make a new backup."; } class DescribeAddressVisitor : public boost::static_visitor<Object> { public: Object operator()(const CNoDestination &dest) const { return Object(); } Object operator()(const CKeyID &keyID) const { Object obj; CPubKey vchPubKey; pwalletMain->GetPubKey(keyID, vchPubKey); obj.push_back(Pair("isscript", false)); obj.push_back(Pair("pubkey", HexStr(vchPubKey))); obj.push_back(Pair("iscompressed", vchPubKey.IsCompressed())); return obj; } Object operator()(const CScriptID &scriptID) const { Object obj; obj.push_back(Pair("isscript", true)); CScript subscript; pwalletMain->GetCScript(scriptID, subscript); std::vector<CTxDestination> addresses; txnouttype whichType; int nRequired; ExtractDestinations(subscript, whichType, addresses, nRequired); obj.push_back(Pair("script", GetTxnOutputType(whichType))); Array a; BOOST_FOREACH(const CTxDestination& addr, addresses) a.push_back(CBitcoinAddress(addr).ToString()); obj.push_back(Pair("addresses", a)); if (whichType == TX_MULTISIG) obj.push_back(Pair("sigsrequired", nRequired)); return obj; } }; Value validateaddress(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( "validateaddress <legendcoinaddress>\n" "Return information about <legendcoinaddress>."); CBitcoinAddress address(params[0].get_str()); bool isValid = address.IsValid(); Object ret; ret.push_back(Pair("isvalid", isValid)); if (isValid) { CTxDestination dest = address.Get(); string currentAddress = address.ToString(); ret.push_back(Pair("address", currentAddress)); bool fMine = pwalletMain ? IsMine(*pwalletMain, dest) : false; ret.push_back(Pair("ismine", fMine)); if (fMine) { Object detail = boost::apply_visitor(DescribeAddressVisitor(), dest); ret.insert(ret.end(), detail.begin(), detail.end()); } if (pwalletMain && pwalletMain->mapAddressBook.count(dest)) ret.push_back(Pair("account", pwalletMain->mapAddressBook[dest])); } return ret; } Value lockunspent(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( "lockunspent unlock? [array-of-Objects]\n" "Updates list of temporarily unspendable outputs."); if (params.size() == 1) RPCTypeCheck(params, list_of(bool_type)); else RPCTypeCheck(params, list_of(bool_type)(array_type)); bool fUnlock = params[0].get_bool(); if (params.size() == 1) { if (fUnlock) pwalletMain->UnlockAllCoins(); return true; } Array outputs = params[1].get_array(); BOOST_FOREACH(Value& output, outputs) { if (output.type() != obj_type) throw JSONRPCError(-8, "Invalid parameter, expected object"); const Object& o = output.get_obj(); RPCTypeCheck(o, map_list_of("txid", str_type)("vout", int_type)); string txid = find_value(o, "txid").get_str(); if (!IsHex(txid)) throw JSONRPCError(-8, "Invalid parameter, expected hex txid"); int nOutput = find_value(o, "vout").get_int(); if (nOutput < 0) throw JSONRPCError(-8, "Invalid parameter, vout must be positive"); COutPoint outpt(uint256(txid), nOutput); if (fUnlock) pwalletMain->UnlockCoin(outpt); else pwalletMain->LockCoin(outpt); } return true; } Value listlockunspent(const Array& params, bool fHelp) { if (fHelp || params.size() > 0) throw runtime_error( "listlockunspent\n" "Returns list of temporarily unspendable outputs."); vector<COutPoint> vOutpts; pwalletMain->ListLockedCoins(vOutpts); Array ret; BOOST_FOREACH(COutPoint &outpt, vOutpts) { Object o; o.push_back(Pair("txid", outpt.hash.GetHex())); o.push_back(Pair("vout", (int)outpt.n)); ret.push_back(o); } return ret; }
[ "sunchaoqun@126.com" ]
sunchaoqun@126.com
81c1afc23b0bf8396ccb7cfb078d27d5c4e40585
e17f365bf6d40cc0325ed0dc6ec1c5ecd9132b99
/arduino/libraries/EZKey/EZKey.cpp
440783316bb0a99c8709a7d18096ef0f37f97c34
[ "MIT" ]
permissive
wyolum/VPD
70740230807ba4c74eb1455507ff60149c91d618
52baa1d7046b004015e4c9d727df13d7cfa4bf23
refs/heads/master
2016-09-05T08:44:23.418769
2015-05-24T13:56:39
2015-05-24T13:56:39
35,377,369
1
0
null
null
null
null
UTF-8
C++
false
false
537
cpp
#include "EZKey.h" void keyCommand(SoftwareSerial BT, uint8_t modifiers, uint8_t keycode1, uint8_t keycode2, uint8_t keycode3, uint8_t keycode4, uint8_t keycode5, uint8_t keycode6) { BT.write(0xFD); // our command BT.write(modifiers); // modifier! BT.write((byte)0x00); // 0x00 BT.write(keycode1); // key code #1 BT.write(keycode2); // key code #2 BT.write(keycode3); // key code #3 BT.write(keycode4); // key code #4 BT.write(keycode5); // key code #5 BT.write(keycode6); // key code #6 }
[ "wyojustin@gmail.com" ]
wyojustin@gmail.com
44496751581b6f2b80791871729c24c53d5c64e3
de35ee3cb9e95affb2971ca96d3d67d2cb89d3fe
/src/Game.h
bb080cd3cbbacff8071bc34ddab19871e0a0dc47
[]
no_license
ratanraj/triangle
45d8d655579db8b603314593212ffbe9188b0cd3
a263ed7ee7389be2ff71a5e6ce2a2767a8d7c4b7
refs/heads/master
2020-12-20T18:49:26.338201
2020-01-25T17:29:43
2020-01-25T17:29:43
236,176,383
0
0
null
null
null
null
UTF-8
C++
false
false
543
h
// // Created by ratanraj on 25/01/20. // #ifndef TRIANGLE_GAME_H #define TRIANGLE_GAME_H #include <iostream> #include <SDL2/SDL.h> #include <SDL2/SDL_image.h> class Game { private: bool isRunning; SDL_Window *window; int cnt = 0; public: Game(); ~Game(); void init(const char *title, int xpos, int ypos, int width, int height, bool fullscreen); void handleEvents(); void update(); void render(); void clean(); bool running(); static SDL_Renderer *renderer; }; #endif //TRIANGLE_GAME_H
[ "ratanraj.r@gmail.com" ]
ratanraj.r@gmail.com
243365f568677d6f2311811a20efb11b75c580fd
5f2f9dcb47bb810cf55291825ab2be3028a201a5
/HNU/2015 ๆš‘ๆœŸๅŸน่ฎญ่ฎญ็ปƒ่ต›ไน‹ๅ…ซ 1004/main2.cpp
7302a98eb36fad4a79fc480a0320e926713e8c4a
[]
no_license
Linfanty/ACM-ICPC
19480155d6e461b728147cfd299e8bce8930f303
2d23ef8013df4eb55dc27aa8f7149420a1b5d3a7
refs/heads/master
2021-01-24T00:24:39.585748
2017-08-27T08:27:32
2017-08-27T08:27:32
122,764,304
1
0
null
2018-02-24T17:48:03
2018-02-24T17:48:03
null
UTF-8
C++
false
false
531
cpp
/* * this code is made by crazyacking * Verdict: Accepted * Submission Date: 2015-08-16-21.49 * Time: 0MS * Memory: 137KB */ #include <queue> #include <cstdio> #include <set> #include <string> #include <stack> #include <cmath> #include <climits> #include <map> #include <cstdlib> #include <iostream> #include <vector> #include <algorithm> #include <cstring> #define LL long long #define ULL unsigned long long using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); return 0; } /* */
[ "11301655@qq.com" ]
11301655@qq.com
cfefaf4cdf63b5692c396e21d7902d8a138910a3
ae68403fba102765271c28ad47a9cf17650f5623
/ch16/DebugDelete.h
dd9444d78872157010ea36db18365feec887fab6
[]
no_license
yangcnju/cpp_primer_5
a3b0a903f81b5b281053adc01b5a1a66704819c0
81152ad4277405082613f29de6fb89a6176e4fa4
refs/heads/master
2021-01-01T19:06:22.280063
2015-11-20T03:05:42
2015-11-20T03:05:42
40,577,238
0
0
null
null
null
null
UTF-8
C++
false
false
372
h
#ifndef _DebugDelete_h #define _DebugDelete_h #include <iostream> // function-obj class that calls delete on a given ptr class DebugDelete { public: DebugDelete(std::ostream &s = std::cerr) : os(s) {} template <typename T> void operator()(T *p) const { os << "deleting unique_ptr" << std::endl; delete p; } private: std::ostream &os; }; // class DebugDelete #endif
[ "yangcnju@gmail.com" ]
yangcnju@gmail.com
afeeb5ef42f822403b4fd9048a2be1c94dc1ed50
ab01f5ba3e2130f1160a5fa51f7a993c7aa8d14f
/Projects/IMeteorite/Meteorite.h
cc101e616ef13d1ed49f053932d04e68531e18e4
[]
no_license
HinsSyr/Shoot-Game
b6400ae8239d02a5e7bf1f838b29de3b0297aac2
7415791f069b6bbee5913c51256c18a31600a4bb
refs/heads/master
2023-03-02T00:35:11.171213
2021-02-08T01:15:07
2021-02-08T01:15:07
336,927,469
0
0
null
null
null
null
UTF-8
C++
false
false
2,545
h
#ifndef METEORITE_H #define METEORITE_H /////////////////////////////////////////////////////////////////////// // Meteorite.h Meteorite object // // // // ver 1.0 // // Author: Bo Qiu Master in Computer Engineering, // // Syracuse University // // (315) 278-2362, qb86880301@gmail.com // /////////////////////////////////////////////////////////////////////// /* * Package Operations: * ------------------- * - This package contains a Meteorite class that implements IMeteorite * interface. It also contains a Factory class that creates instances * of Meteorite. * * Required Files: * --------------- * IMeteorite.h * Simple2D.h * * Maintenance History * ------------------- * ver 1.0 : 05 Dec 2020 * - first release */ #include "IMeteorite.h" #include "../../Extern/Simple2D/Includes/Simple2D.h" #include <iostream> namespace Simple2D { class Meteorite : public IMeteorite { public: Meteorite(int &tp, int& minSp, int& maxSp, float &sps); ~Meteorite(); virtual void drawMeteorite() override; virtual float getPosx() override; virtual float getPosy() override; virtual void movement() override; virtual int getDesx() override; virtual int getDesy() override; virtual int getHeight() override; virtual int getWidth() override; virtual void increHitCount(int count) override; virtual int getHitCount() override; virtual int getMaxHit() override; virtual void increMaxHit(int count) override; virtual void setSpeed(int &minSp, int &maxSp) override; virtual int getMaxSpeed() override; virtual int getMinSpeed() override; virtual void setSpeedScale(float &scale) override; private: void getSize(); void randomPos(); //meteorites born in random places int getRandomNumber(int a, int b); //get random number from [A,B] Simple2D::Image* pImageMeteorite = nullptr; float posX, posY, speedScale; int speed, scale, rotate, desX, desY, speedX, speedY, minSpeed, maxSpeed, countHits, maxHits; int* pWidth, * pHeight; bool goUp; }; class MeteoriteFactory { public: static IMeteorite* createMeteorite(int &tp, int& minSp, int& maxSp, float &sps) { Meteorite* rtn = new Meteorite(tp,minSp,maxSp,sps); return rtn; } }; } #endif
[ "bqiu03@syr.edu" ]
bqiu03@syr.edu
9bd21eec6afbc87007020e6dc7253210fd7602cf
d4bfae1b7aba456a355487e98c50dfd415ccb9ba
/media/filters/decrypting_demuxer_stream.cc
bc35d5bd109c40db26380e75932b9629161fa39f
[ "BSD-3-Clause" ]
permissive
mindaptiv/chromium
d123e4e215ef4c82518a6d08a9c4211433ae3715
a93319b2237f37862989129eeecf87304ab4ff0c
refs/heads/master
2023-05-19T22:48:12.614549
2016-08-23T02:56:57
2016-08-23T02:56:57
66,865,429
1
1
null
2016-08-29T17:35:46
2016-08-29T17:35:45
null
UTF-8
C++
false
false
12,383
cc
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "media/filters/decrypting_demuxer_stream.h" #include "base/bind.h" #include "base/callback_helpers.h" #include "base/location.h" #include "base/logging.h" #include "base/single_thread_task_runner.h" #include "media/base/bind_to_current_loop.h" #include "media/base/decoder_buffer.h" #include "media/base/media_log.h" #include "media/base/media_util.h" namespace media { static bool IsStreamValidAndEncrypted(DemuxerStream* stream) { return ((stream->type() == DemuxerStream::AUDIO && stream->audio_decoder_config().IsValidConfig() && stream->audio_decoder_config().is_encrypted()) || (stream->type() == DemuxerStream::VIDEO && stream->video_decoder_config().IsValidConfig() && stream->video_decoder_config().is_encrypted())); } DecryptingDemuxerStream::DecryptingDemuxerStream( const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, const scoped_refptr<MediaLog>& media_log, const base::Closure& waiting_for_decryption_key_cb) : task_runner_(task_runner), media_log_(media_log), state_(kUninitialized), waiting_for_decryption_key_cb_(waiting_for_decryption_key_cb), demuxer_stream_(NULL), decryptor_(NULL), key_added_while_decrypt_pending_(false), weak_factory_(this) {} std::string DecryptingDemuxerStream::GetDisplayName() const { return "DecryptingDemuxerStream"; } void DecryptingDemuxerStream::Initialize(DemuxerStream* stream, CdmContext* cdm_context, const PipelineStatusCB& status_cb) { DVLOG(2) << __FUNCTION__; DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK_EQ(state_, kUninitialized) << state_; DCHECK(stream); DCHECK(cdm_context); DCHECK(!demuxer_stream_); weak_this_ = weak_factory_.GetWeakPtr(); demuxer_stream_ = stream; init_cb_ = BindToCurrentLoop(status_cb); InitializeDecoderConfig(); if (!cdm_context->GetDecryptor()) { MEDIA_LOG(DEBUG, media_log_) << GetDisplayName() << ": no decryptor"; state_ = kUninitialized; base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); return; } decryptor_ = cdm_context->GetDecryptor(); decryptor_->RegisterNewKeyCB( GetDecryptorStreamType(), BindToCurrentLoop( base::Bind(&DecryptingDemuxerStream::OnKeyAdded, weak_this_))); state_ = kIdle; base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); } void DecryptingDemuxerStream::Read(const ReadCB& read_cb) { DVLOG(3) << __FUNCTION__; DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK_EQ(state_, kIdle) << state_; DCHECK(!read_cb.is_null()); CHECK(read_cb_.is_null()) << "Overlapping reads are not supported."; read_cb_ = BindToCurrentLoop(read_cb); state_ = kPendingDemuxerRead; demuxer_stream_->Read( base::Bind(&DecryptingDemuxerStream::DecryptBuffer, weak_this_)); } void DecryptingDemuxerStream::Reset(const base::Closure& closure) { DVLOG(2) << __FUNCTION__ << " - state: " << state_; DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(state_ != kUninitialized) << state_; DCHECK(reset_cb_.is_null()); reset_cb_ = BindToCurrentLoop(closure); decryptor_->CancelDecrypt(GetDecryptorStreamType()); // Reset() cannot complete if the read callback is still pending. // Defer the resetting process in this case. The |reset_cb_| will be fired // after the read callback is fired - see DoDecryptBuffer() and // DoDeliverBuffer(). if (state_ == kPendingDemuxerRead || state_ == kPendingDecrypt) { DCHECK(!read_cb_.is_null()); return; } if (state_ == kWaitingForKey) { DCHECK(!read_cb_.is_null()); pending_buffer_to_decrypt_ = NULL; base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); } DCHECK(read_cb_.is_null()); DoReset(); } AudioDecoderConfig DecryptingDemuxerStream::audio_decoder_config() { DCHECK(state_ != kUninitialized) << state_; CHECK_EQ(demuxer_stream_->type(), AUDIO); return audio_config_; } VideoDecoderConfig DecryptingDemuxerStream::video_decoder_config() { DCHECK(state_ != kUninitialized) << state_; CHECK_EQ(demuxer_stream_->type(), VIDEO); return video_config_; } DemuxerStream::Type DecryptingDemuxerStream::type() const { DCHECK(state_ != kUninitialized) << state_; return demuxer_stream_->type(); } DemuxerStream::Liveness DecryptingDemuxerStream::liveness() const { DCHECK(state_ != kUninitialized) << state_; return demuxer_stream_->liveness(); } void DecryptingDemuxerStream::EnableBitstreamConverter() { demuxer_stream_->EnableBitstreamConverter(); } bool DecryptingDemuxerStream::SupportsConfigChanges() { return demuxer_stream_->SupportsConfigChanges(); } VideoRotation DecryptingDemuxerStream::video_rotation() { return demuxer_stream_->video_rotation(); } bool DecryptingDemuxerStream::enabled() const { return demuxer_stream_->enabled(); } void DecryptingDemuxerStream::set_enabled(bool enabled, base::TimeDelta timestamp) { demuxer_stream_->set_enabled(enabled, timestamp); } void DecryptingDemuxerStream::SetStreamRestartedCB( const StreamRestartedCB& cb) { demuxer_stream_->SetStreamRestartedCB(cb); } DecryptingDemuxerStream::~DecryptingDemuxerStream() { DVLOG(2) << __FUNCTION__ << " : state_ = " << state_; DCHECK(task_runner_->BelongsToCurrentThread()); if (state_ == kUninitialized) return; if (decryptor_) { decryptor_->CancelDecrypt(GetDecryptorStreamType()); decryptor_ = NULL; } if (!init_cb_.is_null()) base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); if (!read_cb_.is_null()) base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); if (!reset_cb_.is_null()) base::ResetAndReturn(&reset_cb_).Run(); pending_buffer_to_decrypt_ = NULL; } void DecryptingDemuxerStream::DecryptBuffer( DemuxerStream::Status status, const scoped_refptr<DecoderBuffer>& buffer) { DVLOG(3) << __FUNCTION__; DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK_EQ(state_, kPendingDemuxerRead) << state_; DCHECK(!read_cb_.is_null()); DCHECK_EQ(buffer.get() != NULL, status == kOk) << status; // Even when |!reset_cb_.is_null()|, we need to pass |kConfigChanged| back to // the caller so that the downstream decoder can be properly reinitialized. if (status == kConfigChanged) { DVLOG(2) << "DoDecryptBuffer() - kConfigChanged."; DCHECK_EQ(demuxer_stream_->type() == AUDIO, audio_config_.IsValidConfig()); DCHECK_EQ(demuxer_stream_->type() == VIDEO, video_config_.IsValidConfig()); // Update the decoder config, which the decoder will use when it is notified // of kConfigChanged. InitializeDecoderConfig(); state_ = kIdle; base::ResetAndReturn(&read_cb_).Run(kConfigChanged, NULL); if (!reset_cb_.is_null()) DoReset(); return; } if (!reset_cb_.is_null()) { base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); DoReset(); return; } if (status == kAborted) { DVLOG(2) << "DoDecryptBuffer() - kAborted."; state_ = kIdle; base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); return; } if (buffer->end_of_stream()) { DVLOG(2) << "DoDecryptBuffer() - EOS buffer."; state_ = kIdle; base::ResetAndReturn(&read_cb_).Run(status, buffer); return; } DCHECK(buffer->decrypt_config()); // An empty iv string signals that the frame is unencrypted. if (buffer->decrypt_config()->iv().empty()) { DVLOG(2) << "DoDecryptBuffer() - clear buffer."; scoped_refptr<DecoderBuffer> decrypted = DecoderBuffer::CopyFrom( buffer->data(), buffer->data_size()); decrypted->set_timestamp(buffer->timestamp()); decrypted->set_duration(buffer->duration()); if (buffer->is_key_frame()) decrypted->set_is_key_frame(true); state_ = kIdle; base::ResetAndReturn(&read_cb_).Run(kOk, decrypted); return; } pending_buffer_to_decrypt_ = buffer; state_ = kPendingDecrypt; DecryptPendingBuffer(); } void DecryptingDemuxerStream::DecryptPendingBuffer() { DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK_EQ(state_, kPendingDecrypt) << state_; decryptor_->Decrypt( GetDecryptorStreamType(), pending_buffer_to_decrypt_, BindToCurrentLoop( base::Bind(&DecryptingDemuxerStream::DeliverBuffer, weak_this_))); } void DecryptingDemuxerStream::DeliverBuffer( Decryptor::Status status, const scoped_refptr<DecoderBuffer>& decrypted_buffer) { DVLOG(3) << __FUNCTION__ << " - status: " << status; DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK_EQ(state_, kPendingDecrypt) << state_; DCHECK_NE(status, Decryptor::kNeedMoreData); DCHECK(!read_cb_.is_null()); DCHECK(pending_buffer_to_decrypt_.get()); bool need_to_try_again_if_nokey = key_added_while_decrypt_pending_; key_added_while_decrypt_pending_ = false; if (!reset_cb_.is_null()) { pending_buffer_to_decrypt_ = NULL; base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); DoReset(); return; } DCHECK_EQ(status == Decryptor::kSuccess, decrypted_buffer.get() != NULL); if (status == Decryptor::kError) { DVLOG(2) << "DoDeliverBuffer() - kError"; MEDIA_LOG(ERROR, media_log_) << GetDisplayName() << ": decrypt error"; pending_buffer_to_decrypt_ = NULL; state_ = kIdle; base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); return; } if (status == Decryptor::kNoKey) { DVLOG(2) << "DoDeliverBuffer() - kNoKey"; MEDIA_LOG(DEBUG, media_log_) << GetDisplayName() << ": no key"; if (need_to_try_again_if_nokey) { // The |state_| is still kPendingDecrypt. DecryptPendingBuffer(); return; } state_ = kWaitingForKey; waiting_for_decryption_key_cb_.Run(); return; } DCHECK_EQ(status, Decryptor::kSuccess); // Copy the key frame flag from the encrypted to decrypted buffer, assuming // that the decryptor initialized the flag to false. if (pending_buffer_to_decrypt_->is_key_frame()) decrypted_buffer->set_is_key_frame(true); pending_buffer_to_decrypt_ = NULL; state_ = kIdle; base::ResetAndReturn(&read_cb_).Run(kOk, decrypted_buffer); } void DecryptingDemuxerStream::OnKeyAdded() { DCHECK(task_runner_->BelongsToCurrentThread()); if (state_ == kPendingDecrypt) { key_added_while_decrypt_pending_ = true; return; } if (state_ == kWaitingForKey) { state_ = kPendingDecrypt; DecryptPendingBuffer(); } } void DecryptingDemuxerStream::DoReset() { DCHECK(state_ != kUninitialized); DCHECK(init_cb_.is_null()); DCHECK(read_cb_.is_null()); state_ = kIdle; base::ResetAndReturn(&reset_cb_).Run(); } Decryptor::StreamType DecryptingDemuxerStream::GetDecryptorStreamType() const { if (demuxer_stream_->type() == AUDIO) return Decryptor::kAudio; DCHECK_EQ(demuxer_stream_->type(), VIDEO); return Decryptor::kVideo; } void DecryptingDemuxerStream::InitializeDecoderConfig() { // The decoder selector or upstream demuxer make sure the stream is valid and // potentially encrypted. DCHECK(IsStreamValidAndEncrypted(demuxer_stream_)); switch (demuxer_stream_->type()) { case AUDIO: { AudioDecoderConfig input_audio_config = demuxer_stream_->audio_decoder_config(); audio_config_.Initialize( input_audio_config.codec(), input_audio_config.sample_format(), input_audio_config.channel_layout(), input_audio_config.samples_per_second(), input_audio_config.extra_data(), Unencrypted(), input_audio_config.seek_preroll(), input_audio_config.codec_delay()); break; } case VIDEO: { VideoDecoderConfig input_video_config = demuxer_stream_->video_decoder_config(); video_config_.Initialize( input_video_config.codec(), input_video_config.profile(), input_video_config.format(), input_video_config.color_space(), input_video_config.coded_size(), input_video_config.visible_rect(), input_video_config.natural_size(), input_video_config.extra_data(), Unencrypted()); break; } default: NOTREACHED(); return; } } } // namespace media
[ "serg.zhukovsky@gmail.com" ]
serg.zhukovsky@gmail.com
e2b1bd304976789735eb1ec74676e74907ab870f
309e9e43f6c105f686a5991d355f201423b6f20e
/old study/c++/c_++ yuanma/appliance/light.h
71df3d0b4fecd81b6e049e96c7c82120db70e83c
[]
no_license
jikal/mystudy
d1e106725154730de0567fe4d7a7efa857b09682
ff51292c3fcb93d354c279e2c5222bc17b874966
refs/heads/master
2020-05-30T09:36:55.439089
2015-06-30T02:58:22
2015-06-30T02:58:22
35,258,479
0
0
null
null
null
null
UTF-8
C++
false
false
257
h
#ifndef _LIGHT_H_ #define _LIGHT_H_ #include "appliance.h" #define WHITE 1 #define GREEN 2 class Light : public Appliance{ public: Light(int price, int color); ~Light(); void on(); void off(); string toString(); private: int m_color; }; #endif
[ "zhk@ubuntu.(none)" ]
zhk@ubuntu.(none)
af878b71446af13a25c84154d07c56691cfb77d4
d4876d852d32d64391f4eaf67b38a461a219cf73
/src/GameCuaTao/Castlevania/Models/Weapons/Whip.cpp
dbd1ef7f96eb2fa5d63547c912f9c3d5a207cbcc
[]
no_license
ngb0511/Castlevania
1894988743bfcd622e4eb01d13329cffaf31c91a
c2c8a33fcbe9c67cb22b0fe15fbe65b313f0b8aa
refs/heads/master
2022-03-21T03:16:26.013207
2019-10-15T12:55:57
2019-10-15T12:55:57
null
0
0
null
null
null
null
UTF-8
C++
false
false
1,261
cpp
#include "Direct2DGame/MathHelper.h" #include "Whip.h" #include "../Settings.h" #include "WhipFlashingRenderingSystem.h" #include "../../Utilities/AudioManager.h" using namespace Castlevania; const auto HITPOINTS = std::map<int, int> { { 1, 1 }, { 2, 2 }, { 3, 2 }, }; Whip::Whip() : GameObject{ ObjectId::Whip } { level = 1; } int Whip::GetLevel() { return level; } void Whip::SetLevel(int level) { this->level = MathHelper::Clamp(level, 1, WHIP_MAX_LEVEL); } int Whip::GetAttack() { return HITPOINTS.at(level); } void Whip::SetAttack(int attack) { } GameObject *Whip::GetOwner() { return owner; } void Whip::SetOwner(GameObject *owner) { this->owner = owner; } void Whip::SetFacing(Facing facing) { GameObject::SetFacing(facing); SendMessageToSystems(FACING_CHANGED); } void Whip::LoadContent(ContentManager &content) { GameObject::LoadContent(content); Withdraw(); } void Whip::Unleash() { // Collision detection will be turn on when whip is on the attack frame // body.Enabled(true); SendMessageToSystems(WHIP_UNLEASHED); AudioManager::Play(SE_USING_WEAPON); } void Whip::Withdraw() { body.Enabled(false); SendMessageToSystems(WEAPON_WITHDRAWN); } void Whip::Upgrade() { level = MathHelper::Min(++level, WHIP_MAX_LEVEL); }
[ "near.huscarl@gmail.com" ]
near.huscarl@gmail.com
f2b96fe3cce8de49105796a4e25830df341131d6
fec81bfe0453c5646e00c5d69874a71c579a103d
/blazetest/src/mathtest/operations/dmatsmatsub/UHbUCb.cpp
bbe5ce937dc99f5427d41e501de214028caf4914
[ "BSD-3-Clause" ]
permissive
parsa/blaze
801b0f619a53f8c07454b80d0a665ac0a3cf561d
6ce2d5d8951e9b367aad87cc55ac835b054b5964
refs/heads/master
2022-09-19T15:46:44.108364
2022-07-30T04:47:03
2022-07-30T04:47:03
105,918,096
52
7
null
null
null
null
UTF-8
C++
false
false
4,190
cpp
//================================================================================================= /*! // \file src/mathtest/operations/dmatsmatsub/UHbUCb.cpp // \brief Source file for the UHbUCb dense matrix/sparse matrix subtraction math test // // Copyright (C) 2012-2020 Klaus Iglberger - All Rights Reserved // // This file is part of the Blaze library. You can redistribute it and/or modify it under // the terms of the New (Revised) BSD License. Redistribution and use in source and binary // forms, with or without modification, are permitted provided that the following conditions // are met: // // 1. Redistributions of source code must retain the above copyright notice, this list of // conditions and the following disclaimer. // 2. 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. // 3. Neither the names of the Blaze development group nor the names of its contributors // may be used to endorse or promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 HOLDER 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. */ //================================================================================================= //************************************************************************************************* // Includes //************************************************************************************************* #include <cstdlib> #include <iostream> #include <blaze/math/CompressedMatrix.h> #include <blaze/math/HybridMatrix.h> #include <blaze/math/UpperMatrix.h> #include <blazetest/mathtest/Creator.h> #include <blazetest/mathtest/operations/dmatsmatsub/OperationTest.h> #include <blazetest/system/MathTest.h> #ifdef BLAZE_USE_HPX_THREADS # include <hpx/hpx_main.hpp> #endif //================================================================================================= // // MAIN FUNCTION // //================================================================================================= //************************************************************************************************* int main() { std::cout << " Running 'UHbUCb'..." << std::endl; using blazetest::mathtest::TypeB; try { // Matrix type definitions using UHb = blaze::UpperMatrix< blaze::HybridMatrix<TypeB,128UL,128UL> >; using UCb = blaze::UpperMatrix< blaze::CompressedMatrix<TypeB> >; // Creator type definitions using CUHb = blazetest::Creator<UHb>; using CUCb = blazetest::Creator<UCb>; // Running tests with small matrices for( size_t i=0UL; i<=6UL; ++i ) { for( size_t j=0UL; j<=UCb::maxNonZeros( i ); ++j ) { RUN_DMATSMATSUB_OPERATION_TEST( CUHb( i ), CUCb( i, j ) ); } } // Running tests with large matrices RUN_DMATSMATSUB_OPERATION_TEST( CUHb( 67UL ), CUCb( 67UL, 7UL ) ); RUN_DMATSMATSUB_OPERATION_TEST( CUHb( 128UL ), CUCb( 128UL, 16UL ) ); } catch( std::exception& ex ) { std::cerr << "\n\n ERROR DETECTED during dense matrix/sparse matrix subtraction:\n" << ex.what() << "\n"; return EXIT_FAILURE; } return EXIT_SUCCESS; } //*************************************************************************************************
[ "klaus.iglberger@gmail.com" ]
klaus.iglberger@gmail.com
889e592fd4c76f9c96705afbbb3ea6f8719a23bb
b2b10f8ba5b3a2b023fe3dbfb9fe9900c111a8e7
/common/columnlistview/haiku/ColumnListView.cpp
37ee3eee3dc67a0abc1549d96878b323dd92dd35
[ "BSD-3-Clause" ]
permissive
HaikuArchives/IMKit
0759451f29a15502838e9102c0c4566a436fd9c0
9c80ad110de77481717d855f503d3de6ce65e4d8
refs/heads/master
2021-01-19T03:14:00.562465
2009-11-27T16:17:29
2009-11-27T16:17:29
12,183,169
1
0
null
null
null
null
UTF-8
C++
false
false
117,906
cpp
/* Open Tracker License Terms and Conditions Copyright (c) 1991-2000, Be Incorporated. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice applies to all licensees and shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the name of Be Incorporated shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Be Incorporated. Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks of Be Incorporated in the United States and other countries. Other brand product names are registered trademarks or trademarks of their respective holders. All rights reserved. */ /******************************************************************************* / / File: ColumnListView.cpp / / Description: Experimental multi-column list view. / / Copyright 2000+, Be Incorporated, All Rights Reserved / By Jeff Bush / *******************************************************************************/ #include "ColumnListView.h" #include <typeinfo> #include <stdio.h> #include <stdlib.h> #include <Application.h> #include <Bitmap.h> #include <ControlLook.h> #include <Cursor.h> #include <Debug.h> #include <GraphicsDefs.h> #include <LayoutUtils.h> #include <MenuItem.h> #include <PopUpMenu.h> #include <Region.h> #include <ScrollBar.h> #include <String.h> #include <Window.h> #include "ColorTools.h" #include "ObjectList.h" #define DOUBLE_BUFFERED_COLUMN_RESIZE 1 #define SMART_REDRAW 1 #define DRAG_TITLE_OUTLINE 1 #define CONSTRAIN_CLIPPING_REGION 1 #define LOWER_SCROLLBAR 0 namespace BPrivate { static const unsigned char kResizeCursorData[] = { 16, 1, 8, 8, 0x03, 0xc0, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x1a, 0x58, 0x2a, 0x54, 0x4a, 0x52, 0x8a, 0x51, 0x8a, 0x51, 0x4a, 0x52, 0x2a, 0x54, 0x1a, 0x58, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x1b, 0xd8, 0x3b, 0xdc, 0x7b, 0xde, 0xfb, 0xdf, 0xfb, 0xdf, 0x7b, 0xde, 0x3b, 0xdc, 0x1b, 0xd8, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0 }; static const unsigned char kMaxResizeCursorData[] = { 16, 1, 8, 8, 0x03, 0xc0, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x1a, 0x40, 0x2a, 0x40, 0x4a, 0x40, 0x8a, 0x40, 0x8a, 0x40, 0x4a, 0x40, 0x2a, 0x40, 0x1a, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x1b, 0xc0, 0x3b, 0xc0, 0x7b, 0xc0, 0xfb, 0xc0, 0xfb, 0xc0, 0x7b, 0xc0, 0x3b, 0xc0, 0x1b, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0 }; static const unsigned char kMinResizeCursorData[] = { 16, 1, 8, 8, 0x03, 0xc0, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x58, 0x02, 0x54, 0x02, 0x52, 0x02, 0x51, 0x02, 0x51, 0x02, 0x52, 0x02, 0x54, 0x02, 0x58, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xd8, 0x03, 0xdc, 0x03, 0xde, 0x03, 0xdf, 0x03, 0xdf, 0x03, 0xde, 0x03, 0xdc, 0x03, 0xd8, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0 }; static const unsigned char kColumnMoveCursorData[] = { 16, 1, 8, 8, 0x01, 0x80, 0x02, 0x40, 0x04, 0x20, 0x08, 0x10, 0x1e, 0x78, 0x2a, 0x54, 0x4e, 0x72, 0x80, 0x01, 0x80, 0x01, 0x4e, 0x72, 0x2a, 0x54, 0x1e, 0x78, 0x08, 0x10, 0x04, 0x20, 0x02, 0x40, 0x01, 0x80, 0x01, 0x80, 0x03, 0xc0, 0x07, 0xe0, 0x0f, 0xf0, 0x1f, 0xf8, 0x3b, 0xdc, 0x7f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0x3b, 0xdc, 0x1f, 0xf8, 0x0f, 0xf0, 0x07, 0xe0, 0x03, 0xc0, 0x01, 0x80 }; static const unsigned char kDownSortArrow8x8[] = { 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff }; static const unsigned char kUpSortArrow8x8[] = { 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff }; static const unsigned char kDownSortArrow8x8Invert[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x1f, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0xff }; static const unsigned char kUpSortArrow8x8Invert[] = { 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x1f, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; static const float kTintedLineTint = 0.7 * B_NO_TINT + 0.3 * B_DARKEN_1_TINT; static const float kTitleHeight = 16.0; static const float kLatchWidth = 15.0; static const rgb_color kColor[B_COLOR_TOTAL] = { {236, 236, 236, 255}, // B_COLOR_BACKGROUND { 0, 0, 0, 255}, // B_COLOR_TEXT {148, 148, 148, 255}, // B_COLOR_ROW_DIVIDER {190, 190, 190, 255}, // B_COLOR_SELECTION { 0, 0, 0, 255}, // B_COLOR_SELECTION_TEXT {200, 200, 200, 255}, // B_COLOR_NON_FOCUS_SELECTION {180, 180, 180, 180}, // B_COLOR_EDIT_BACKGROUND { 0, 0, 0, 255}, // B_COLOR_EDIT_TEXT {215, 215, 215, 255}, // B_COLOR_HEADER_BACKGROUND { 0, 0, 0, 255}, // B_COLOR_HEADER_TEXT { 0, 0, 0, 255}, // B_COLOR_SEPARATOR_LINE { 0, 0, 0, 255}, // B_COLOR_SEPARATOR_BORDER }; static const int32 kMaxDepth = 1024; static const float kLeftMargin = kLatchWidth; static const float kRightMargin = kLatchWidth; static const float kOutlineLevelIndent = kLatchWidth; static const float kColumnResizeAreaWidth = 10.0; static const float kRowDragSensitivity = 5.0; static const float kDoubleClickMoveSensitivity = 4.0; static const float kSortIndicatorWidth = 9.0; static const float kDropHighlightLineHeight = 2.0; static const uint32 kToggleColumn = 'BTCL'; class BRowContainer : public BObjectList<BRow> { }; class TitleView : public BView { typedef BView _inherited; public: TitleView(BRect frame, OutlineView* outlineView, BList* visibleColumns, BList* sortColumns, BColumnListView* masterView, uint32 resizingMode); virtual ~TitleView(); void ColumnAdded(BColumn* column); void ColumnResized(BColumn* column, float oldWidth); void SetColumnVisible(BColumn* column, bool visible); virtual void Draw(BRect updateRect); virtual void ScrollTo(BPoint where); virtual void MessageReceived(BMessage* message); virtual void MouseDown(BPoint where); virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage); virtual void MouseUp(BPoint where); virtual void FrameResized(float width, float height); void MoveColumn(BColumn* column, int32 index); void SetColumnFlags(column_flags flags); void SetEditMode(bool state) { fEditMode = state; } private: void GetTitleRect(BColumn* column, BRect* _rect); int32 FindColumn(BPoint where, float* _leftEdge); void FixScrollBar(bool scrollToFit); void DragSelectedColumn(BPoint where); void ResizeSelectedColumn(BPoint where, bool preferred = false); void ComputeDragBoundries(BColumn* column, BPoint where); void DrawTitle(BView* view, BRect frame, BColumn* column, bool depressed); float _VirtualWidth() const; OutlineView* fOutlineView; BList* fColumns; BList* fSortColumns; // float fColumnsWidth; BRect fVisibleRect; #if DOUBLE_BUFFERED_COLUMN_RESIZE BBitmap* fDrawBuffer; BView* fDrawBufferView; #endif enum { INACTIVE, RESIZING_COLUMN, PRESSING_COLUMN, DRAG_COLUMN_INSIDE_TITLE, DRAG_COLUMN_OUTSIDE_TITLE } fCurrentState; BPopUpMenu* fColumnPop; BColumnListView* fMasterView; bool fEditMode; int32 fColumnFlags; // State information for resizing/dragging BColumn* fSelectedColumn; BRect fSelectedColumnRect; bool fResizingFirstColumn; BPoint fClickPoint; // offset within cell float fLeftDragBoundry; float fRightDragBoundry; BPoint fCurrentDragPosition; BBitmap* fUpSortArrow; BBitmap* fDownSortArrow; BCursor* fResizeCursor; BCursor* fMinResizeCursor; BCursor* fMaxResizeCursor; BCursor* fColumnMoveCursor; }; class OutlineView : public BView { typedef BView _inherited; public: OutlineView(BRect, BList* visibleColumns, BList* sortColumns, BColumnListView* listView); virtual ~OutlineView(); virtual void Draw(BRect); const BRect& VisibleRect() const; void RedrawColumn(BColumn* column, float leftEdge, bool isFirstColumn); void StartSorting(); float GetColumnPreferredWidth(BColumn* column); void AddRow(BRow*, int32 index, BRow* TheRow); BRow* CurrentSelection(BRow* lastSelected) const; void ToggleFocusRowSelection(bool selectRange); void ToggleFocusRowOpen(); void ChangeFocusRow(bool up, bool updateSelection, bool addToCurrentSelection); void MoveFocusToVisibleRect(); void ExpandOrCollapse(BRow* parent, bool expand); void RemoveRow(BRow*); BRowContainer* RowList(); void UpdateRow(BRow*); bool FindParent(BRow* row, BRow** _parent, bool* _isVisible); int32 IndexOf(BRow* row); void Deselect(BRow*); void AddToSelection(BRow*); void DeselectAll(); BRow* FocusRow() const; void SetFocusRow(BRow* row, bool select); BRow* FindRow(float ypos, int32* _indent, float* _top); bool FindRect(const BRow* row, BRect* _rect); void ScrollTo(const BRow* row); void Clear(); void SetSelectionMode(list_view_type type); list_view_type SelectionMode() const; void SetMouseTrackingEnabled(bool); void FixScrollBar(bool scrollToFit); void SetEditMode(bool state) { fEditMode = state; } virtual void FrameResized(float width, float height); virtual void ScrollTo(BPoint where); virtual void MouseDown(BPoint where); virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage); virtual void MouseUp(BPoint where); virtual void MessageReceived(BMessage* message); private: bool SortList(BRowContainer* list, bool isVisible); static int32 DeepSortThreadEntry(void* outlineView); void DeepSort(); void SelectRange(BRow* start, BRow* end); int32 CompareRows(BRow* row1, BRow* row2); void AddSorted(BRowContainer* list, BRow* row); void RecursiveDeleteRows(BRowContainer* list, bool owner); void InvalidateCachedPositions(); bool FindVisibleRect(BRow* row, BRect* _rect); BList* fColumns; BList* fSortColumns; float fItemsHeight; BRowContainer fRows; BRect fVisibleRect; #if DOUBLE_BUFFERED_COLUMN_RESIZE BBitmap* fDrawBuffer; BView* fDrawBufferView; #endif BRow* fFocusRow; BRect fFocusRowRect; BRow* fRollOverRow; BRow fSelectionListDummyHead; BRow* fLastSelectedItem; BRow* fFirstSelectedItem; thread_id fSortThread; int32 fNumSorted; bool fSortCancelled; enum CurrentState { INACTIVE, LATCH_CLICKED, ROW_CLICKED, DRAGGING_ROWS }; CurrentState fCurrentState; BColumnListView* fMasterView; list_view_type fSelectionMode; bool fTrackMouse; BField* fCurrentField; BRow* fCurrentRow; BColumn* fCurrentColumn; bool fMouseDown; BRect fFieldRect; int32 fCurrentCode; bool fEditMode; // State information for mouse/keyboard interaction BPoint fClickPoint; bool fDragging; int32 fClickCount; BRow* fTargetRow; float fTargetRowTop; BRect fLatchRect; float fDropHighlightY; friend class RecursiveOutlineIterator; }; class RecursiveOutlineIterator { public: RecursiveOutlineIterator( BRowContainer* container, bool openBranchesOnly = true); BRow* CurrentRow() const; int32 CurrentLevel() const; void GoToNext(); private: struct { BRowContainer* fRowSet; int32 fIndex; int32 fDepth; } fStack[kMaxDepth]; int32 fStackIndex; BRowContainer* fCurrentList; int32 fCurrentListIndex; int32 fCurrentListDepth; bool fOpenBranchesOnly; }; } // namespace BPrivate using namespace BPrivate; BField::BField() { } BField::~BField() { } // #pragma mark - void BColumn::MouseMoved(BColumnListView* /*parent*/, BRow* /*row*/, BField* /*field*/, BRect /*field_rect*/, BPoint/*point*/, uint32 /*buttons*/, int32 /*code*/) { } void BColumn::MouseDown(BColumnListView* /*parent*/, BRow* /*row*/, BField* /*field*/, BRect /*field_rect*/, BPoint /*point*/, uint32 /*buttons*/) { } void BColumn::MouseUp(BColumnListView* /*parent*/, BRow* /*row*/, BField* /*field*/) { } // #pragma mark - BRow::BRow(float height) : fChildList(NULL), fIsExpanded(false), fHeight(height), fNextSelected(NULL), fPrevSelected(NULL), fParent(NULL), fList(NULL) { } BRow::~BRow() { while (true) { BField* field = (BField*) fFields.RemoveItem(0L); if (field == 0) break; delete field; } } bool BRow::HasLatch() const { return fChildList != 0; } int32 BRow::CountFields() const { return fFields.CountItems(); } BField* BRow::GetField(int32 index) { return (BField*)fFields.ItemAt(index); } const BField* BRow::GetField(int32 index) const { return (const BField*)fFields.ItemAt(index); } void BRow::SetField(BField* field, int32 logicalFieldIndex) { if (fFields.ItemAt(logicalFieldIndex) != 0) delete (BField*)fFields.RemoveItem(logicalFieldIndex); if (NULL != fList) { ValidateField(field, logicalFieldIndex); BRect inv; fList->GetRowRect(this, &inv); fList->Invalidate(inv); } fFields.AddItem(field, logicalFieldIndex); } float BRow::Height() const { return fHeight; } bool BRow::IsExpanded() const { return fIsExpanded; } void BRow::ValidateFields() const { for (int32 i = 0; i < CountFields(); i++) ValidateField(GetField(i), i); } void BRow::ValidateField(const BField* field, int32 logicalFieldIndex) const { // The Fields may be moved by the user, but the logicalFieldIndexes // do not change, so we need to map them over when checking the // Field types. BColumn* col = NULL; int32 items = fList->CountColumns(); for (int32 i = 0 ; i < items; ++i) { col = fList->ColumnAt(i); if( col->LogicalFieldNum() == logicalFieldIndex ) break; } if (NULL == col) { BString dbmessage("\n\n\tThe parent BColumnListView does not have " "\n\ta BColumn at the logical field index "); dbmessage << logicalFieldIndex << ".\n\n"; printf(dbmessage.String()); } else { if (!col->AcceptsField(field)) { BString dbmessage("\n\n\tThe BColumn of type "); dbmessage << typeid(*col).name() << "\n\tat logical field index " << logicalFieldIndex << "\n\tdoes not support the " "field type " << typeid(*field).name() << ".\n\n"; debugger(dbmessage.String()); } } } // #pragma mark - BColumn::BColumn(float width, float minWidth, float maxWidth, alignment align) : fWidth(width), fMinWidth(minWidth), fMaxWidth(maxWidth), fVisible(true), fList(0), fShowHeading(true), fAlignment(align) { } BColumn::~BColumn() { } float BColumn::Width() const { return fWidth; } void BColumn::SetWidth(float width) { fWidth = width; } float BColumn::MinWidth() const { return fMinWidth; } float BColumn::MaxWidth() const { return fMaxWidth; } void BColumn::DrawTitle(BRect, BView*) { } void BColumn::DrawField(BField*, BRect, BView*) { } int BColumn::CompareFields(BField*, BField*) { return 0; } void BColumn::GetColumnName(BString* into) const { *into = "(Unnamed)"; } float BColumn::GetPreferredWidth(BField* field, BView* parent) const { return fWidth; } bool BColumn::IsVisible() const { return fVisible; } void BColumn::SetVisible(bool visible) { if (fList && (fVisible != visible)) fList->SetColumnVisible(this, visible); } bool BColumn::ShowHeading() const { return fShowHeading; } void BColumn::SetShowHeading(bool state) { fShowHeading = state; } alignment BColumn::Alignment() const { return fAlignment; } void BColumn::SetAlignment(alignment align) { fAlignment = align; } bool BColumn::WantsEvents() const { return fWantsEvents; } void BColumn::SetWantsEvents(bool state) { fWantsEvents = state; } int32 BColumn::LogicalFieldNum() const { return fFieldID; } bool BColumn::AcceptsField(const BField*) const { return true; } // #pragma mark - BColumnListView::BColumnListView(BRect rect, const char* name, uint32 resizingMode, uint32 flags, border_style border, bool showHorizontalScrollbar) : BView(rect, name, resizingMode, flags | B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE), fStatusView(NULL), fSelectionMessage(NULL), fSortingEnabled(true), fLatchWidth(kLatchWidth), fBorderStyle(border) { _Init(showHorizontalScrollbar); } BColumnListView::BColumnListView(const char* name, uint32 flags, border_style border, bool showHorizontalScrollbar) : BView(name, flags | B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE), fStatusView(NULL), fSelectionMessage(NULL), fSortingEnabled(true), fLatchWidth(kLatchWidth), fBorderStyle(border) { _Init(showHorizontalScrollbar); } BColumnListView::~BColumnListView() { while (BColumn* column = (BColumn*)fColumns.RemoveItem(0L)) delete column; } bool BColumnListView::InitiateDrag(BPoint, bool) { return false; } void BColumnListView::MessageDropped(BMessage*, BPoint) { } void BColumnListView::ExpandOrCollapse(BRow* row, bool Open) { fOutlineView->ExpandOrCollapse(row, Open); } status_t BColumnListView::Invoke(BMessage* message) { if (message == 0) message = Message(); return BInvoker::Invoke(message); } void BColumnListView::ItemInvoked() { Invoke(); } void BColumnListView::SetInvocationMessage(BMessage* message) { SetMessage(message); } BMessage* BColumnListView::InvocationMessage() const { return Message(); } uint32 BColumnListView::InvocationCommand() const { return Command(); } BRow* BColumnListView::FocusRow() const { return fOutlineView->FocusRow(); } void BColumnListView::SetFocusRow(int32 Index, bool Select) { SetFocusRow(RowAt(Index), Select); } void BColumnListView::SetFocusRow(BRow* row, bool Select) { fOutlineView->SetFocusRow(row, Select); } void BColumnListView::SetMouseTrackingEnabled(bool Enabled) { fOutlineView->SetMouseTrackingEnabled(Enabled); } list_view_type BColumnListView::SelectionMode() const { return fOutlineView->SelectionMode(); } void BColumnListView::Deselect(BRow* row) { fOutlineView->Deselect(row); } void BColumnListView::AddToSelection(BRow* row) { fOutlineView->AddToSelection(row); } void BColumnListView::DeselectAll() { fOutlineView->DeselectAll(); } BRow* BColumnListView::CurrentSelection(BRow* lastSelected) const { return fOutlineView->CurrentSelection(lastSelected); } void BColumnListView::SelectionChanged() { if (fSelectionMessage) Invoke(fSelectionMessage); } void BColumnListView::SetSelectionMessage(BMessage* message) { if (fSelectionMessage == message) return; delete fSelectionMessage; fSelectionMessage = message; } BMessage* BColumnListView::SelectionMessage() { return fSelectionMessage; } uint32 BColumnListView::SelectionCommand() const { if (fSelectionMessage) return fSelectionMessage->what; return 0; } void BColumnListView::SetSelectionMode(list_view_type mode) { fOutlineView->SetSelectionMode(mode); } void BColumnListView::SetSortingEnabled(bool enabled) { fSortingEnabled = enabled; fSortColumns.MakeEmpty(); fTitleView->Invalidate(); // Erase sort indicators } bool BColumnListView::SortingEnabled() const { return fSortingEnabled; } void BColumnListView::SetSortColumn(BColumn* column, bool add, bool ascending) { if (!SortingEnabled()) return; if (!add) fSortColumns.MakeEmpty(); if (!fSortColumns.HasItem(column)) fSortColumns.AddItem(column); column->fSortAscending = ascending; fTitleView->Invalidate(); fOutlineView->StartSorting(); } void BColumnListView::ClearSortColumns() { fSortColumns.MakeEmpty(); fTitleView->Invalidate(); // Erase sort indicators } void BColumnListView::AddStatusView(BView* view) { BRect bounds = Bounds(); float width = view->Bounds().Width(); if (width > bounds.Width() / 2) width = bounds.Width() / 2; fStatusView = view; Window()->BeginViewTransaction(); fHorizontalScrollBar->ResizeBy(-(width + 1), 0); fHorizontalScrollBar->MoveBy((width + 1), 0); AddChild(view); BRect viewRect(bounds); viewRect.right = width; viewRect.top = viewRect.bottom - B_H_SCROLL_BAR_HEIGHT; if (fBorderStyle == B_PLAIN_BORDER) viewRect.OffsetBy(1, -1); else if (fBorderStyle == B_FANCY_BORDER) viewRect.OffsetBy(2, -2); view->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); view->ResizeTo(viewRect.Width(), viewRect.Height()); view->MoveTo(viewRect.left, viewRect.top); Window()->EndViewTransaction(); } BView* BColumnListView::RemoveStatusView() { if (fStatusView) { float width = fStatusView->Bounds().Width(); Window()->BeginViewTransaction(); fStatusView->RemoveSelf(); fHorizontalScrollBar->MoveBy(-width, 0); fHorizontalScrollBar->ResizeBy(width, 0); Window()->EndViewTransaction(); } BView* view = fStatusView; fStatusView = 0; return view; } void BColumnListView::AddColumn(BColumn* column, int32 logicalFieldIndex) { ASSERT(column != NULL); column->fList = this; column->fFieldID = logicalFieldIndex; // sanity check. If there is already a field with this ID, remove it. for (int32 index = 0; index < fColumns.CountItems(); index++) { BColumn* existingColumn = (BColumn*) fColumns.ItemAt(index); if (existingColumn && existingColumn->fFieldID == logicalFieldIndex) { RemoveColumn(existingColumn); break; } } if (column->Width() < column->MinWidth()) column->SetWidth(column->MinWidth()); else if (column->Width() > column->MaxWidth()) column->SetWidth(column->MaxWidth()); fColumns.AddItem((void*) column); fTitleView->ColumnAdded(column); } void BColumnListView::MoveColumn(BColumn* column, int32 index) { ASSERT(column != NULL); fTitleView->MoveColumn(column, index); } void BColumnListView::RemoveColumn(BColumn* column) { if (fColumns.HasItem(column)) { SetColumnVisible(column, false); if (Window() != NULL) Window()->UpdateIfNeeded(); fColumns.RemoveItem(column); } } int32 BColumnListView::CountColumns() const { return fColumns.CountItems(); } BColumn* BColumnListView::ColumnAt(int32 field) const { return (BColumn*) fColumns.ItemAt(field); } void BColumnListView::SetColumnVisible(BColumn* column, bool visible) { fTitleView->SetColumnVisible(column, visible); } void BColumnListView::SetColumnVisible(int32 index, bool isVisible) { BColumn* column = ColumnAt(index); if (column) column->SetVisible(isVisible); } bool BColumnListView::IsColumnVisible(int32 index) const { BColumn* column = ColumnAt(index); if (column) return column->IsVisible(); return false; } void BColumnListView::SetColumnFlags(column_flags flags) { fTitleView->SetColumnFlags(flags); } void BColumnListView::ResizeColumnToPreferred(int32 index) { BColumn* column = ColumnAt(index); if (column == NULL) return; // get the preferred column width float width = fOutlineView->GetColumnPreferredWidth(column); // set it float oldWidth = column->Width(); column->SetWidth(width); fTitleView->ColumnResized(column, oldWidth); fOutlineView->Invalidate(); } void BColumnListView::ResizeAllColumnsToPreferred() { int32 count = CountColumns(); for (int32 i = 0; i < count; i++) ResizeColumnToPreferred(i); } const BRow* BColumnListView::RowAt(int32 Index, BRow* parentRow) const { if (parentRow == 0) return fOutlineView->RowList()->ItemAt(Index); return parentRow->fChildList ? parentRow->fChildList->ItemAt(Index) : NULL; } BRow* BColumnListView::RowAt(int32 Index, BRow* parentRow) { if (parentRow == 0) return fOutlineView->RowList()->ItemAt(Index); return parentRow->fChildList ? parentRow->fChildList->ItemAt(Index) : 0; } const BRow* BColumnListView::RowAt(BPoint point) const { float top; int32 indent; return fOutlineView->FindRow(point.y, &indent, &top); } BRow* BColumnListView::RowAt(BPoint point) { float top; int32 indent; return fOutlineView->FindRow(point.y, &indent, &top); } bool BColumnListView::GetRowRect(const BRow* row, BRect* outRect) const { return fOutlineView->FindRect(row, outRect); } bool BColumnListView::FindParent(BRow* row, BRow** _parent, bool* _isVisible) const { return fOutlineView->FindParent(row, _parent, _isVisible); } int32 BColumnListView::IndexOf(BRow* row) { return fOutlineView->IndexOf(row); } int32 BColumnListView::CountRows(BRow* parentRow) const { if (parentRow == 0) return fOutlineView->RowList()->CountItems(); if (parentRow->fChildList) return parentRow->fChildList->CountItems(); else return 0; } void BColumnListView::AddRow(BRow* row, BRow* parentRow) { AddRow(row, -1, parentRow); } void BColumnListView::AddRow(BRow* row, int32 index, BRow* parentRow) { row->fChildList = 0; row->fList = this; row->ValidateFields(); fOutlineView->AddRow(row, index, parentRow); } void BColumnListView::RemoveRow(BRow* row) { fOutlineView->RemoveRow(row); row->fList = NULL; } void BColumnListView::UpdateRow(BRow* row) { fOutlineView->UpdateRow(row); } void BColumnListView::ScrollTo(const BRow* row) { fOutlineView->ScrollTo(row); } void BColumnListView::ScrollTo(BPoint point) { fOutlineView->ScrollTo(point); } void BColumnListView::Clear() { fOutlineView->Clear(); } void BColumnListView::SetFont(const BFont* font, uint32 mask) { // This method is deprecated. fOutlineView->SetFont(font, mask); fTitleView->SetFont(font, mask); } void BColumnListView::SetFont(ColumnListViewFont font_num, const BFont* font, uint32 mask) { switch (font_num) { case B_FONT_ROW: fOutlineView->SetFont(font, mask); break; case B_FONT_HEADER: fTitleView->SetFont(font, mask); break; default: ASSERT(false); break; } } void BColumnListView::GetFont(ColumnListViewFont font_num, BFont* font) const { switch (font_num) { case B_FONT_ROW: fOutlineView->GetFont(font); break; case B_FONT_HEADER: fTitleView->GetFont(font); break; default: ASSERT(false); break; } } void BColumnListView::SetColor(ColumnListViewColor color_num, const rgb_color color) { if ((int)color_num < 0) { ASSERT(false); color_num = (ColumnListViewColor) 0; } if ((int)color_num >= (int)B_COLOR_TOTAL) { ASSERT(false); color_num = (ColumnListViewColor) (B_COLOR_TOTAL - 1); } fColorList[color_num] = color; } rgb_color BColumnListView::Color(ColumnListViewColor color_num) const { if ((int)color_num < 0) { ASSERT(false); color_num = (ColumnListViewColor) 0; } if ((int)color_num >= (int)B_COLOR_TOTAL) { ASSERT(false); color_num = (ColumnListViewColor) (B_COLOR_TOTAL - 1); } return fColorList[color_num]; } void BColumnListView::SetHighColor(rgb_color color) { BView::SetHighColor(color); // fOutlineView->Invalidate(); // Redraw things with the new color // Note that this will currently cause // an infinite loop, refreshing over and over. // A better solution is needed. } void BColumnListView::SetSelectionColor(rgb_color color) { fColorList[B_COLOR_SELECTION] = color; } void BColumnListView::SetBackgroundColor(rgb_color color) { fColorList[B_COLOR_BACKGROUND] = color; fOutlineView->Invalidate(); // Repaint with new color } void BColumnListView::SetEditColor(rgb_color color) { fColorList[B_COLOR_EDIT_BACKGROUND] = color; } const rgb_color BColumnListView::SelectionColor() const { return fColorList[B_COLOR_SELECTION]; } const rgb_color BColumnListView::BackgroundColor() const { return fColorList[B_COLOR_BACKGROUND]; } const rgb_color BColumnListView::EditColor() const { return fColorList[B_COLOR_EDIT_BACKGROUND]; } BPoint BColumnListView::SuggestTextPosition(const BRow* row, const BColumn* inColumn) const { BRect rect; GetRowRect(row, &rect); if (inColumn) { float leftEdge = MAX(kLeftMargin, LatchWidth()); for (int index = 0; index < fColumns.CountItems(); index++) { BColumn* column = (BColumn*) fColumns.ItemAt(index); if (!column->IsVisible()) continue; if (column == inColumn) { rect.left = leftEdge; rect.right = rect.left + column->Width(); break; } leftEdge += column->Width() + 1; } } font_height fh; fOutlineView->GetFontHeight(&fh); float baseline = floor(rect.top + fh.ascent + (rect.Height()+1-(fh.ascent+fh.descent))/2); return BPoint(rect.left + 8, baseline); } void BColumnListView::SetLatchWidth(float width) { fLatchWidth = width; Invalidate(); } float BColumnListView::LatchWidth() const { return fLatchWidth; } void BColumnListView::DrawLatch(BView* view, BRect rect, LatchType position, BRow*) { const int32 rectInset = 4; view->SetHighColor(0, 0, 0); // Make Square int32 sideLen = rect.IntegerWidth(); if (sideLen > rect.IntegerHeight()) sideLen = rect.IntegerHeight(); // Make Center int32 halfWidth = rect.IntegerWidth() / 2; int32 halfHeight = rect.IntegerHeight() / 2; int32 halfSide = sideLen / 2; float left = rect.left + halfWidth - halfSide; float top = rect.top + halfHeight - halfSide; BRect itemRect(left, top, left + sideLen, top + sideLen); // Why it is a pixel high? I don't know. itemRect.OffsetBy(0, -1); itemRect.InsetBy(rectInset, rectInset); // Make it an odd number of pixels wide, the latch looks better this way if ((itemRect.IntegerWidth() % 2) == 1) { itemRect.right += 1; itemRect.bottom += 1; } switch (position) { case B_OPEN_LATCH: view->StrokeRect(itemRect); view->StrokeLine( BPoint(itemRect.left + 2, (itemRect.top + itemRect.bottom) / 2), BPoint(itemRect.right - 2, (itemRect.top + itemRect.bottom) / 2)); break; case B_PRESSED_LATCH: view->StrokeRect(itemRect); view->StrokeLine( BPoint(itemRect.left + 2, (itemRect.top + itemRect.bottom) / 2), BPoint(itemRect.right - 2, (itemRect.top + itemRect.bottom) / 2)); view->StrokeLine( BPoint((itemRect.left + itemRect.right) / 2, itemRect.top + 2), BPoint((itemRect.left + itemRect.right) / 2, itemRect.bottom - 2)); view->InvertRect(itemRect); break; case B_CLOSED_LATCH: view->StrokeRect(itemRect); view->StrokeLine( BPoint(itemRect.left + 2, (itemRect.top + itemRect.bottom) / 2), BPoint(itemRect.right - 2, (itemRect.top + itemRect.bottom) / 2)); view->StrokeLine( BPoint((itemRect.left + itemRect.right) / 2, itemRect.top + 2), BPoint((itemRect.left + itemRect.right) / 2, itemRect.bottom - 2)); break; case B_NO_LATCH: // No drawing break; } } void BColumnListView::MakeFocus(bool isFocus) { if (fBorderStyle != B_NO_BORDER) { // Redraw focus marks around view Invalidate(); fHorizontalScrollBar->SetBorderHighlighted(isFocus); fVerticalScrollBar->SetBorderHighlighted(isFocus); } BView::MakeFocus(isFocus); } void BColumnListView::MessageReceived(BMessage* message) { // Propagate mouse wheel messages down to child, so that it can // scroll. Note we have done so, so we don't go into infinite // recursion if this comes back up here. if (message->what == B_MOUSE_WHEEL_CHANGED) { bool handled; if (message->FindBool("be:clvhandled", &handled) != B_OK) { message->AddBool("be:clvhandled", true); fOutlineView->MessageReceived(message); return; } } BView::MessageReceived(message); } void BColumnListView::KeyDown(const char* bytes, int32 numBytes) { char c = bytes[0]; switch (c) { case B_RIGHT_ARROW: case B_LEFT_ARROW: { float minVal, maxVal; fHorizontalScrollBar->GetRange(&minVal, &maxVal); float smallStep, largeStep; fHorizontalScrollBar->GetSteps(&smallStep, &largeStep); float oldVal = fHorizontalScrollBar->Value(); float newVal = oldVal; if (c == B_LEFT_ARROW) newVal -= smallStep; else if (c == B_RIGHT_ARROW) newVal += smallStep; if (newVal < minVal) newVal = minVal; else if (newVal > maxVal) newVal = maxVal; fHorizontalScrollBar->SetValue(newVal); break; } case B_DOWN_ARROW: fOutlineView->ChangeFocusRow(false, (modifiers() & B_CONTROL_KEY) == 0, (modifiers() & B_SHIFT_KEY) != 0); break; case B_UP_ARROW: fOutlineView->ChangeFocusRow(true, (modifiers() & B_CONTROL_KEY) == 0, (modifiers() & B_SHIFT_KEY) != 0); break; case B_PAGE_UP: case B_PAGE_DOWN: { float minValue, maxValue; fVerticalScrollBar->GetRange(&minValue, &maxValue); float smallStep, largeStep; fVerticalScrollBar->GetSteps(&smallStep, &largeStep); float currentValue = fVerticalScrollBar->Value(); float newValue = currentValue; if (c == B_PAGE_UP) newValue -= largeStep; else newValue += largeStep; if (newValue > maxValue) newValue = maxValue; else if (newValue < minValue) newValue = minValue; fVerticalScrollBar->SetValue(newValue); // Option + pgup or pgdn scrolls and changes the selection. if (modifiers() & B_OPTION_KEY) fOutlineView->MoveFocusToVisibleRect(); break; } case B_ENTER: Invoke(); break; case B_SPACE: fOutlineView->ToggleFocusRowSelection( (modifiers() & B_SHIFT_KEY) != 0); break; case '+': fOutlineView->ToggleFocusRowOpen(); break; default: BView::KeyDown(bytes, numBytes); } } void BColumnListView::AttachedToWindow() { if (!Messenger().IsValid()) SetTarget(Window()); if (SortingEnabled()) fOutlineView->StartSorting(); } void BColumnListView::WindowActivated(bool active) { fOutlineView->Invalidate(); // Focus and selection appearance changes with focus Invalidate(); // Redraw focus marks around view BView::WindowActivated(active); } void BColumnListView::Draw(BRect updateRect) { BRect rect = Bounds(); if (be_control_look != NULL) { uint32 flags = 0; if (IsFocus() && Window()->IsActive()) flags |= BControlLook::B_FOCUSED; rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); BRect verticalScrollBarFrame; if (!fVerticalScrollBar->IsHidden()) verticalScrollBarFrame = fVerticalScrollBar->Frame(); BRect horizontalScrollBarFrame; if (!fHorizontalScrollBar->IsHidden()) horizontalScrollBarFrame = fHorizontalScrollBar->Frame(); if (fBorderStyle == B_NO_BORDER) { // We still draw the left/top border, but not focused. // The scrollbars cannot be displayed without frame and // it looks bad to have no frame only along the left/top // side. rgb_color borderColor = tint_color(base, B_DARKEN_2_TINT); SetHighColor(borderColor); StrokeLine(BPoint(rect.left, rect.bottom), BPoint(rect.left, rect.top)); StrokeLine(BPoint(rect.left + 1, rect.top), BPoint(rect.right, rect.top)); } be_control_look->DrawScrollViewFrame(this, rect, updateRect, verticalScrollBarFrame, horizontalScrollBarFrame, base, fBorderStyle, flags); return; } BRect cornerRect(rect.right - B_V_SCROLL_BAR_WIDTH, rect.bottom - B_H_SCROLL_BAR_HEIGHT, rect.right, rect.bottom); if (fBorderStyle == B_PLAIN_BORDER) { BView::SetHighColor(0, 0, 0); StrokeRect(rect); cornerRect.OffsetBy(-1, -1); } else if (fBorderStyle == B_FANCY_BORDER) { bool isFocus = IsFocus() && Window()->IsActive(); if (isFocus) { // TODO: Need to find focus color programatically BView::SetHighColor(0, 0, 190); } else BView::SetHighColor(255, 255, 255); StrokeRect(rect); if (!isFocus) BView::SetHighColor(184, 184, 184); else BView::SetHighColor(152, 152, 152); rect.InsetBy(1,1); StrokeRect(rect); cornerRect.OffsetBy(-2, -2); } BView::SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); // fills lower right rect between scroll bars FillRect(cornerRect); } void BColumnListView::SaveState(BMessage* msg) { msg->MakeEmpty(); for (int32 i = 0; BColumn* col = (BColumn*)fColumns.ItemAt(i); i++) { msg->AddInt32("ID",col->fFieldID); msg->AddFloat("width", col->fWidth); msg->AddBool("visible", col->fVisible); } msg->AddBool("sortingenabled", fSortingEnabled); if (fSortingEnabled) { for (int32 i = 0; BColumn* col = (BColumn*)fSortColumns.ItemAt(i); i++) { msg->AddInt32("sortID", col->fFieldID); msg->AddBool("sortascending", col->fSortAscending); } } } void BColumnListView::LoadState(BMessage* msg) { int32 id; for (int i = 0; msg->FindInt32("ID", i, &id) == B_OK; i++) { for (int j = 0; BColumn* column = (BColumn*)fColumns.ItemAt(j); j++) { if (column->fFieldID == id) { // move this column to position 'i' and set its attributes MoveColumn(column, i); float width; if (msg->FindFloat("width", i, &width) == B_OK) column->SetWidth(width); bool visible; if (msg->FindBool("visible", i, &visible) == B_OK) column->SetVisible(visible); } } } bool b; if (msg->FindBool("sortingenabled", &b) == B_OK) { SetSortingEnabled(b); for (int k = 0; msg->FindInt32("sortID", k, &id) == B_OK; k++) { for (int j = 0; BColumn* column = (BColumn*)fColumns.ItemAt(j); j++) { if (column->fFieldID == id) { // add this column to the sort list bool value; if (msg->FindBool("sortascending", k, &value) == B_OK) SetSortColumn(column, true, value); } } } } } void BColumnListView::SetEditMode(bool state) { fOutlineView->SetEditMode(state); fTitleView->SetEditMode(state); } void BColumnListView::Refresh() { if (LockLooper()) { Invalidate(); fOutlineView->FixScrollBar (true); fOutlineView->Invalidate(); Window()->UpdateIfNeeded(); UnlockLooper(); } } BSize BColumnListView::MinSize() { BSize size; size.width = 100; size.height = kTitleHeight + 4 * B_H_SCROLL_BAR_HEIGHT; if (!fHorizontalScrollBar->IsHidden()) size.height += fHorizontalScrollBar->Frame().Height() + 1; // TODO: Take border size into account return BLayoutUtils::ComposeSize(ExplicitMinSize(), size); } BSize BColumnListView::PreferredSize() { BSize size = MinSize(); size.height += ceilf(be_plain_font->Size()) * 20; int32 count = CountColumns(); if (count > 0) { // return MinSize().width if there are no columns. size.width = 40.0f; for (int32 i = 0; i < count; i++) { BColumn* column = ColumnAt(i); if (column != NULL) size.width += fOutlineView->GetColumnPreferredWidth(column); } } return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), size); } BSize BColumnListView::MaxSize() { BSize size(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED); return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size); } void BColumnListView::InvalidateLayout(bool descendants) { BView::InvalidateLayout(descendants); } void BColumnListView::DoLayout() { if (!(Flags() & B_SUPPORTS_LAYOUT)) return; BRect titleRect; BRect outlineRect; BRect vScrollBarRect; BRect hScrollBarRect; _GetChildViewRects(Bounds(), !fHorizontalScrollBar->IsHidden(), titleRect, outlineRect, vScrollBarRect, hScrollBarRect); fTitleView->MoveTo(titleRect.LeftTop()); fTitleView->ResizeTo(titleRect.Width(), titleRect.Height()); fOutlineView->MoveTo(outlineRect.LeftTop()); fOutlineView->ResizeTo(outlineRect.Width(), outlineRect.Height()); fVerticalScrollBar->MoveTo(vScrollBarRect.LeftTop()); fVerticalScrollBar->ResizeTo(vScrollBarRect.Width(), vScrollBarRect.Height()); fHorizontalScrollBar->MoveTo(hScrollBarRect.LeftTop()); fHorizontalScrollBar->ResizeTo(hScrollBarRect.Width(), hScrollBarRect.Height()); fOutlineView->FixScrollBar(true); } void BColumnListView::_Init(bool showHorizontalScrollbar) { SetViewColor(B_TRANSPARENT_32_BIT); BRect bounds(Bounds()); if (bounds.Width() <= 0) bounds.right = 100; if (bounds.Height() <= 0) bounds.bottom = 100; for (int i = 0; i < (int)B_COLOR_TOTAL; i++) fColorList[i] = kColor[i]; BRect titleRect; BRect outlineRect; BRect vScrollBarRect; BRect hScrollBarRect; _GetChildViewRects(bounds, showHorizontalScrollbar, titleRect, outlineRect, vScrollBarRect, hScrollBarRect); fOutlineView = new OutlineView(outlineRect, &fColumns, &fSortColumns, this); AddChild(fOutlineView); fTitleView = new TitleView(titleRect, fOutlineView, &fColumns, &fSortColumns, this, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); AddChild(fTitleView); fVerticalScrollBar = new BScrollBar(vScrollBarRect, "vertical_scroll_bar", fOutlineView, 0.0, bounds.Height(), B_VERTICAL); AddChild(fVerticalScrollBar); fHorizontalScrollBar = new BScrollBar(hScrollBarRect, "horizontal_scroll_bar", fTitleView, 0.0, bounds.Width(), B_HORIZONTAL); AddChild(fHorizontalScrollBar); if (!showHorizontalScrollbar) fHorizontalScrollBar->Hide(); fOutlineView->FixScrollBar(true); } void BColumnListView::_GetChildViewRects(const BRect& bounds, bool showHorizontalScrollbar, BRect& titleRect, BRect& outlineRect, BRect& vScrollBarRect, BRect& hScrollBarRect) { titleRect = bounds; titleRect.bottom = titleRect.top + kTitleHeight; #if !LOWER_SCROLLBAR titleRect.right -= B_V_SCROLL_BAR_WIDTH; #endif outlineRect = bounds; outlineRect.top = titleRect.bottom + 1.0; outlineRect.right -= B_V_SCROLL_BAR_WIDTH; if (showHorizontalScrollbar) outlineRect.bottom -= B_H_SCROLL_BAR_HEIGHT; vScrollBarRect = bounds; #if LOWER_SCROLLBAR vScrollBarRect.top += kTitleHeight; #endif vScrollBarRect.left = vScrollBarRect.right - B_V_SCROLL_BAR_WIDTH; if (showHorizontalScrollbar) vScrollBarRect.bottom -= B_H_SCROLL_BAR_HEIGHT; hScrollBarRect = bounds; hScrollBarRect.top = hScrollBarRect.bottom - B_H_SCROLL_BAR_HEIGHT; hScrollBarRect.right -= B_V_SCROLL_BAR_WIDTH; // Adjust stuff so the border will fit. if (fBorderStyle == B_PLAIN_BORDER || fBorderStyle == B_NO_BORDER) { titleRect.InsetBy(1, 0); titleRect.OffsetBy(0, 1); outlineRect.InsetBy(1, 1); } else if (fBorderStyle == B_FANCY_BORDER) { titleRect.InsetBy(2, 0); titleRect.OffsetBy(0, 2); outlineRect.InsetBy(2, 2); vScrollBarRect.OffsetBy(-1, 0); #if LOWER_SCROLLBAR vScrollBarRect.top += 2; vScrollBarRect.bottom -= 1; #else vScrollBarRect.InsetBy(0, 1); #endif hScrollBarRect.OffsetBy(0, -1); hScrollBarRect.InsetBy(1, 0); } } // #pragma mark - TitleView::TitleView(BRect rect, OutlineView* horizontalSlave, BList* visibleColumns, BList* sortColumns, BColumnListView* listView, uint32 resizingMode) : BView(rect, "title_view", resizingMode, B_WILL_DRAW | B_FRAME_EVENTS), fOutlineView(horizontalSlave), fColumns(visibleColumns), fSortColumns(sortColumns), // fColumnsWidth(0), fVisibleRect(rect.OffsetToCopy(0, 0)), fCurrentState(INACTIVE), fColumnPop(NULL), fMasterView(listView), fEditMode(false), fColumnFlags(B_ALLOW_COLUMN_MOVE | B_ALLOW_COLUMN_RESIZE | B_ALLOW_COLUMN_POPUP | B_ALLOW_COLUMN_REMOVE) { SetViewColor(B_TRANSPARENT_COLOR); #if DOUBLE_BUFFERED_COLUMN_RESIZE // xxx this needs to be smart about the size of the backbuffer. BRect doubleBufferRect(0, 0, 600, 35); fDrawBuffer = new BBitmap(doubleBufferRect, B_RGB32, true); fDrawBufferView = new BView(doubleBufferRect, "double_buffer_view", B_FOLLOW_ALL_SIDES, 0); fDrawBuffer->Lock(); fDrawBuffer->AddChild(fDrawBufferView); fDrawBuffer->Unlock(); #endif fUpSortArrow = new BBitmap(BRect(0, 0, 7, 7), B_CMAP8); fDownSortArrow = new BBitmap(BRect(0, 0, 7, 7), B_CMAP8); fUpSortArrow->SetBits((const void*) kUpSortArrow8x8, 64, 0, B_CMAP8); fDownSortArrow->SetBits((const void*) kDownSortArrow8x8, 64, 0, B_CMAP8); fResizeCursor = new BCursor(kResizeCursorData); fMinResizeCursor = new BCursor(kMinResizeCursorData); fMaxResizeCursor = new BCursor(kMaxResizeCursorData); fColumnMoveCursor = new BCursor(kColumnMoveCursorData); FixScrollBar(true); } TitleView::~TitleView() { delete fColumnPop; fColumnPop = NULL; #if DOUBLE_BUFFERED_COLUMN_RESIZE delete fDrawBuffer; #endif delete fUpSortArrow; delete fDownSortArrow; delete fResizeCursor; delete fMaxResizeCursor; delete fMinResizeCursor; delete fColumnMoveCursor; } void TitleView::ColumnAdded(BColumn* column) { // fColumnsWidth += column->Width(); FixScrollBar(false); Invalidate(); } void TitleView::ColumnResized(BColumn* column, float oldWidth) { // fColumnsWidth += column->Width() - oldWidth; FixScrollBar(false); Invalidate(); } void TitleView::SetColumnVisible(BColumn* column, bool visible) { if (column->fVisible == visible) return; // If setting it visible, do this first so we can find its position // to invalidate. If hiding it, do it last. if (visible) column->fVisible = visible; BRect titleInvalid; GetTitleRect(column, &titleInvalid); // Now really set the visibility column->fVisible = visible; // if (visible) // fColumnsWidth += column->Width(); // else // fColumnsWidth -= column->Width(); BRect outlineInvalid(fOutlineView->VisibleRect()); outlineInvalid.left = titleInvalid.left; titleInvalid.right = outlineInvalid.right; Invalidate(titleInvalid); fOutlineView->Invalidate(outlineInvalid); } void TitleView::GetTitleRect(BColumn* findColumn, BRect* _rect) { float leftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); int32 numColumns = fColumns->CountItems(); for (int index = 0; index < numColumns; index++) { BColumn* column = (BColumn*) fColumns->ItemAt(index); if (!column->IsVisible()) continue; if (column == findColumn) { _rect->Set(leftEdge, 0, leftEdge + column->Width(), fVisibleRect.bottom); return; } leftEdge += column->Width() + 1; } TRESPASS(); } int32 TitleView::FindColumn(BPoint position, float* _leftEdge) { float leftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); int32 numColumns = fColumns->CountItems(); for (int index = 0; index < numColumns; index++) { BColumn* column = (BColumn*) fColumns->ItemAt(index); if (!column->IsVisible()) continue; if (leftEdge > position.x) break; if (position.x >= leftEdge && position.x <= leftEdge + column->Width()) { *_leftEdge = leftEdge; return index; } leftEdge += column->Width() + 1; } return 0; } void TitleView::FixScrollBar(bool scrollToFit) { BScrollBar* hScrollBar = ScrollBar(B_HORIZONTAL); if (hScrollBar == NULL) return; float virtualWidth = _VirtualWidth(); if (virtualWidth > fVisibleRect.Width()) { hScrollBar->SetProportion(fVisibleRect.Width() / virtualWidth); // Perform the little trick if the user is scrolled over too far. // See OutlineView::FixScrollBar for a more in depth explanation float maxScrollBarValue = virtualWidth - fVisibleRect.Width(); if (scrollToFit || hScrollBar->Value() <= maxScrollBarValue) { hScrollBar->SetRange(0.0, maxScrollBarValue); hScrollBar->SetSteps(50, fVisibleRect.Width()); } } else if (hScrollBar->Value() == 0.0) { // disable scroll bar. hScrollBar->SetRange(0.0, 0.0); } } void TitleView::DragSelectedColumn(BPoint position) { float invalidLeft = fSelectedColumnRect.left; float invalidRight = fSelectedColumnRect.right; float leftEdge; int32 columnIndex = FindColumn(position, &leftEdge); fSelectedColumnRect.OffsetTo(leftEdge, 0); MoveColumn(fSelectedColumn, columnIndex); fSelectedColumn->fVisible = true; ComputeDragBoundries(fSelectedColumn, position); // Redraw the new column position GetTitleRect(fSelectedColumn, &fSelectedColumnRect); invalidLeft = MIN(fSelectedColumnRect.left, invalidLeft); invalidRight = MAX(fSelectedColumnRect.right, invalidRight); Invalidate(BRect(invalidLeft, 0, invalidRight, fVisibleRect.bottom)); fOutlineView->Invalidate(BRect(invalidLeft, 0, invalidRight, fOutlineView->VisibleRect().bottom)); DrawTitle(this, fSelectedColumnRect, fSelectedColumn, true); } void TitleView::MoveColumn(BColumn* column, int32 index) { fColumns->RemoveItem((void*) column); if (-1 == index) { // Re-add the column at the end of the list. fColumns->AddItem((void*) column); } else { fColumns->AddItem((void*) column, index); } } void TitleView::SetColumnFlags(column_flags flags) { fColumnFlags = flags; } void TitleView::ResizeSelectedColumn(BPoint position, bool preferred) { float minWidth = fSelectedColumn->MinWidth(); float maxWidth = fSelectedColumn->MaxWidth(); float oldWidth = fSelectedColumn->Width(); float originalEdge = fSelectedColumnRect.left + oldWidth; if (preferred) { float width = fOutlineView->GetColumnPreferredWidth(fSelectedColumn); fSelectedColumn->SetWidth(width); } else if (position.x > fSelectedColumnRect.left + maxWidth) fSelectedColumn->SetWidth(maxWidth); else if (position.x < fSelectedColumnRect.left + minWidth) fSelectedColumn->SetWidth(minWidth); else fSelectedColumn->SetWidth(position.x - fSelectedColumnRect.left - 1); float dX = fSelectedColumnRect.left + fSelectedColumn->Width() - originalEdge; if (dX != 0) { float columnHeight = fVisibleRect.Height(); BRect originalRect(originalEdge, 0, 1000000.0, columnHeight); BRect movedRect(originalRect); movedRect.OffsetBy(dX, 0); // Update the size of the title column BRect sourceRect(0, 0, fSelectedColumn->Width(), columnHeight); BRect destRect(sourceRect); destRect.OffsetBy(fSelectedColumnRect.left, 0); #if DOUBLE_BUFFERED_COLUMN_RESIZE fDrawBuffer->Lock(); DrawTitle(fDrawBufferView, sourceRect, fSelectedColumn, false); fDrawBufferView->Sync(); fDrawBuffer->Unlock(); CopyBits(originalRect, movedRect); DrawBitmap(fDrawBuffer, sourceRect, destRect); #else CopyBits(originalRect, movedRect); DrawTitle(this, destRect, fSelectedColumn, false); #endif // Update the body view BRect slaveSize = fOutlineView->VisibleRect(); BRect slaveSource(originalRect); slaveSource.bottom = slaveSize.bottom; BRect slaveDest(movedRect); slaveDest.bottom = slaveSize.bottom; fOutlineView->CopyBits(slaveSource, slaveDest); fOutlineView->RedrawColumn(fSelectedColumn, fSelectedColumnRect.left, fResizingFirstColumn); // fColumnsWidth += dX; // Update the cursor if (fSelectedColumn->Width() == minWidth) SetViewCursor(fMinResizeCursor, true); else if (fSelectedColumn->Width() == maxWidth) SetViewCursor(fMaxResizeCursor, true); else SetViewCursor(fResizeCursor, true); ColumnResized(fSelectedColumn, oldWidth); } } void TitleView::ComputeDragBoundries(BColumn* findColumn, BPoint) { float previousColumnLeftEdge = -1000000.0; float nextColumnRightEdge = 1000000.0; bool foundColumn = false; float leftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); int32 numColumns = fColumns->CountItems(); for (int index = 0; index < numColumns; index++) { BColumn* column = (BColumn*) fColumns->ItemAt(index); if (!column->IsVisible()) continue; if (column == findColumn) { foundColumn = true; continue; } if (foundColumn) { nextColumnRightEdge = leftEdge + column->Width(); break; } else previousColumnLeftEdge = leftEdge; leftEdge += column->Width() + 1; } float rightEdge = leftEdge + findColumn->Width(); fLeftDragBoundry = MIN(previousColumnLeftEdge + findColumn->Width(), leftEdge); fRightDragBoundry = MAX(nextColumnRightEdge, rightEdge); } void TitleView::DrawTitle(BView* view, BRect rect, BColumn* column, bool depressed) { BRect drawRect; rgb_color borderColor = mix_color( fMasterView->Color(B_COLOR_HEADER_BACKGROUND), make_color(0, 0, 0), 128); rgb_color backgroundColor; rgb_color bevelHigh; rgb_color bevelLow; // Want exterior borders to overlap. if (be_control_look == NULL) { rect.right += 1; drawRect = rect; drawRect.InsetBy(2, 2); if (depressed) { backgroundColor = mix_color( fMasterView->Color(B_COLOR_HEADER_BACKGROUND), make_color(0, 0, 0), 64); bevelHigh = mix_color(backgroundColor, make_color(0, 0, 0), 64); bevelLow = mix_color(backgroundColor, make_color(255, 255, 255), 128); drawRect.left++; drawRect.top++; } else { backgroundColor = fMasterView->Color(B_COLOR_HEADER_BACKGROUND); bevelHigh = mix_color(backgroundColor, make_color(255, 255, 255), 192); bevelLow = mix_color(backgroundColor, make_color(0, 0, 0), 64); drawRect.bottom--; drawRect.right--; } } else { drawRect = rect; } font_height fh; GetFontHeight(&fh); float baseline = floor(drawRect.top + fh.ascent + (drawRect.Height() + 1 - (fh.ascent + fh.descent)) / 2); if (be_control_look != NULL) { BRect bgRect = rect; rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); view->SetHighColor(tint_color(base, B_DARKEN_2_TINT)); view->StrokeLine(bgRect.LeftBottom(), bgRect.RightBottom()); bgRect.bottom--; bgRect.right--; if (depressed) base = tint_color(base, B_DARKEN_1_TINT); be_control_look->DrawButtonBackground(view, bgRect, rect, base, 0, BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER); view->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_2_TINT)); view->StrokeLine(rect.RightTop(), rect.RightBottom()); } else { view->SetHighColor(borderColor); view->StrokeRect(rect); view->BeginLineArray(4); view->AddLine(BPoint(rect.left + 1, rect.top + 1), BPoint(rect.right - 1, rect.top + 1), bevelHigh); view->AddLine(BPoint(rect.left + 1, rect.top + 1), BPoint(rect.left + 1, rect.bottom - 1), bevelHigh); view->AddLine(BPoint(rect.right - 1, rect.top + 1), BPoint(rect.right - 1, rect.bottom - 1), bevelLow); view->AddLine(BPoint(rect.left + 2, rect.bottom-1), BPoint(rect.right - 1, rect.bottom - 1), bevelLow); view->EndLineArray(); view->SetHighColor(backgroundColor); view->SetLowColor(backgroundColor); view->FillRect(rect.InsetByCopy(2, 2)); } // If no column given, nothing else to draw. if (!column) return; view->SetHighColor(fMasterView->Color(B_COLOR_HEADER_TEXT)); BFont font; GetFont(&font); view->SetFont(&font); int sortIndex = fSortColumns->IndexOf(column); if (sortIndex >= 0) { // Draw sort notation. BPoint upperLeft(drawRect.right - kSortIndicatorWidth, baseline); if (fSortColumns->CountItems() > 1) { char str[256]; sprintf(str, "%d", sortIndex + 1); const float w = view->StringWidth(str); upperLeft.x -= w; view->SetDrawingMode(B_OP_COPY); view->MovePenTo(BPoint(upperLeft.x + kSortIndicatorWidth, baseline)); view->DrawString(str); } float bmh = fDownSortArrow->Bounds().Height()+1; view->SetDrawingMode(B_OP_OVER); if (column->fSortAscending) { BPoint leftTop(upperLeft.x, drawRect.top + (drawRect.IntegerHeight() - fDownSortArrow->Bounds().IntegerHeight()) / 2); view->DrawBitmapAsync(fDownSortArrow, leftTop); } else { BPoint leftTop(upperLeft.x, drawRect.top + (drawRect.IntegerHeight() - fUpSortArrow->Bounds().IntegerHeight()) / 2); view->DrawBitmapAsync(fUpSortArrow, leftTop); } upperLeft.y = baseline - bmh + floor((fh.ascent + fh.descent - bmh) / 2); if (upperLeft.y < drawRect.top) upperLeft.y = drawRect.top; // Adjust title stuff for sort indicator drawRect.right = upperLeft.x - 2; } if (drawRect.right > drawRect.left) { #if CONSTRAIN_CLIPPING_REGION BRegion clipRegion(drawRect); view->PushState(); view->ConstrainClippingRegion(&clipRegion); #endif view->MovePenTo(BPoint(drawRect.left + 8, baseline)); view->SetDrawingMode(B_OP_OVER); view->SetHighColor(fMasterView->Color(B_COLOR_HEADER_TEXT)); column->DrawTitle(drawRect, view); #if CONSTRAIN_CLIPPING_REGION view->PopState(); #endif } } float TitleView::_VirtualWidth() const { float width = 0.0f; int32 count = fColumns->CountItems(); for (int32 i = 0; i < count; i++) { BColumn* column = reinterpret_cast<BColumn*>(fColumns->ItemAt(i)); width += column->Width(); } return width + MAX(kLeftMargin, fMasterView->LatchWidth()) + kRightMargin * 2; } void TitleView::Draw(BRect invalidRect) { float columnLeftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); for (int32 columnIndex = 0; columnIndex < fColumns->CountItems(); columnIndex++) { BColumn* column = (BColumn*) fColumns->ItemAt(columnIndex); if (!column->IsVisible()) continue; if (columnLeftEdge > invalidRect.right) break; if (columnLeftEdge + column->Width() >= invalidRect.left) { BRect titleRect(columnLeftEdge, 0, columnLeftEdge + column->Width(), fVisibleRect.Height()); DrawTitle(this, titleRect, column, (fCurrentState == DRAG_COLUMN_INSIDE_TITLE && fSelectedColumn == column)); } columnLeftEdge += column->Width() + 1; } // Bevels for right title margin if (columnLeftEdge <= invalidRect.right) { BRect titleRect(columnLeftEdge, 0, Bounds().right + 2, fVisibleRect.Height()); DrawTitle(this, titleRect, NULL, false); } // Bevels for left title margin if (invalidRect.left < MAX(kLeftMargin, fMasterView->LatchWidth())) { BRect titleRect(0, 0, MAX(kLeftMargin, fMasterView->LatchWidth()) - 1, fVisibleRect.Height()); DrawTitle(this, titleRect, NULL, false); } #if DRAG_TITLE_OUTLINE // (Internal) Column Drag Indicator if (fCurrentState == DRAG_COLUMN_INSIDE_TITLE) { BRect dragRect(fSelectedColumnRect); dragRect.OffsetTo(fCurrentDragPosition.x - fClickPoint.x, 0); if (dragRect.Intersects(invalidRect)) { SetHighColor(0, 0, 255); StrokeRect(dragRect); } } #endif } void TitleView::ScrollTo(BPoint position) { fOutlineView->ScrollBy(position.x - fVisibleRect.left, 0); fVisibleRect.OffsetTo(position.x, position.y); // Perform the little trick if the user is scrolled over too far. // See OutlineView::ScrollTo for a more in depth explanation float maxScrollBarValue = _VirtualWidth() - fVisibleRect.Width(); BScrollBar* hScrollBar = ScrollBar(B_HORIZONTAL); float min, max; hScrollBar->GetRange(&min, &max); if (max != maxScrollBarValue && position.x > maxScrollBarValue) FixScrollBar(true); _inherited::ScrollTo(position); } void TitleView::MessageReceived(BMessage* message) { if (message->what == kToggleColumn) { int32 num; if (message->FindInt32("be:field_num", &num) == B_OK) { for (int index = 0; index < fColumns->CountItems(); index++) { BColumn* column = (BColumn*) fColumns->ItemAt(index); if (!column) continue; if (column->LogicalFieldNum() == num) column->SetVisible(!column->IsVisible()); } } return; } else { BView::MessageReceived(message); } } void TitleView::MouseDown(BPoint position) { if(fEditMode) return; int32 buttons = 1; Window()->CurrentMessage()->FindInt32("buttons", &buttons); if (buttons == B_SECONDARY_MOUSE_BUTTON && (fColumnFlags & B_ALLOW_COLUMN_POPUP)) { // Right mouse button -- bring up menu to show/hide columns. if (!fColumnPop) fColumnPop = new BPopUpMenu("Columns", false, false); fColumnPop->RemoveItems(0, fColumnPop->CountItems(), true); BMessenger me(this); for (int index = 0; index < fColumns->CountItems(); index++) { BColumn* column = (BColumn*) fColumns->ItemAt(index); if (!column) continue; BString name; column->GetColumnName(&name); BMessage* msg = new BMessage(kToggleColumn); msg->AddInt32("be:field_num", column->LogicalFieldNum()); BMenuItem* it = new BMenuItem(name.String(), msg); it->SetMarked(column->IsVisible()); it->SetTarget(me); fColumnPop->AddItem(it); } BPoint screenPosition = ConvertToScreen(position); BRect sticky(screenPosition, screenPosition); sticky.InsetBy(-5, -5); fColumnPop->Go(ConvertToScreen(position), true, false, sticky, true); return; } fResizingFirstColumn = true; float leftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); for (int index = 0; index < fColumns->CountItems(); index++) { BColumn* column = (BColumn*) fColumns->ItemAt(index); if (!column->IsVisible()) continue; if (leftEdge > position.x + kColumnResizeAreaWidth / 2) break; // Check for resizing a column float rightEdge = leftEdge + column->Width(); if (column->ShowHeading()) { if (position.x > rightEdge - kColumnResizeAreaWidth / 2 && position.x < rightEdge + kColumnResizeAreaWidth / 2 && column->MaxWidth() > column->MinWidth() && (fColumnFlags & B_ALLOW_COLUMN_RESIZE)) { int32 clicks = 0; Window()->CurrentMessage()->FindInt32("clicks", &clicks); if (clicks == 2) { ResizeSelectedColumn(position, true); fCurrentState = INACTIVE; break; } fCurrentState = RESIZING_COLUMN; fSelectedColumn = column; fSelectedColumnRect.Set(leftEdge, 0, rightEdge, fVisibleRect.Height()); fClickPoint = BPoint(position.x - rightEdge - 1, position.y - fSelectedColumnRect.top); SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY); break; } fResizingFirstColumn = false; // Check for clicking on a column. if (position.x > leftEdge && position.x < rightEdge) { fCurrentState = PRESSING_COLUMN; fSelectedColumn = column; fSelectedColumnRect.Set(leftEdge, 0, rightEdge, fVisibleRect.Height()); DrawTitle(this, fSelectedColumnRect, fSelectedColumn, true); fClickPoint = BPoint(position.x - fSelectedColumnRect.left, position.y - fSelectedColumnRect.top); SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY); break; } } leftEdge = rightEdge + 1; } } void TitleView::MouseMoved(BPoint position, uint32 transit, const BMessage* dragMessage) { if (fEditMode) return; // Handle column manipulation switch (fCurrentState) { case RESIZING_COLUMN: ResizeSelectedColumn(position - BPoint(fClickPoint.x, 0)); break; case PRESSING_COLUMN: { if (abs((int32)(position.x - (fClickPoint.x + fSelectedColumnRect.left))) > kColumnResizeAreaWidth || abs((int32)(position.y - (fClickPoint.y + fSelectedColumnRect.top))) > kColumnResizeAreaWidth) { // User has moved the mouse more than the tolerable amount, // initiate a drag. if (transit == B_INSIDE_VIEW || transit == B_ENTERED_VIEW) { if(fColumnFlags & B_ALLOW_COLUMN_MOVE) { fCurrentState = DRAG_COLUMN_INSIDE_TITLE; ComputeDragBoundries(fSelectedColumn, position); SetViewCursor(fColumnMoveCursor, true); #if DRAG_TITLE_OUTLINE BRect invalidRect(fSelectedColumnRect); invalidRect.OffsetTo(position.x - fClickPoint.x, 0); fCurrentDragPosition = position; Invalidate(invalidRect); #endif } } else { if(fColumnFlags & B_ALLOW_COLUMN_REMOVE) { // Dragged outside view fCurrentState = DRAG_COLUMN_OUTSIDE_TITLE; fSelectedColumn->SetVisible(false); BRect dragRect(fSelectedColumnRect); // There is a race condition where the mouse may have // moved by the time we get to handle this message. // If the user drags a column very quickly, this // results in the annoying bug where the cursor is // outside of the rectangle that is being dragged // around. Call GetMouse with the checkQueue flag set // to false so we can get the most recent position of // the mouse. This minimizes this problem (although // it is currently not possible to completely eliminate // it). uint32 buttons; GetMouse(&position, &buttons, false); dragRect.OffsetTo(position.x - fClickPoint.x, position.y - dragRect.Height() / 2); BeginRectTracking(dragRect, B_TRACK_WHOLE_RECT); } } } break; } case DRAG_COLUMN_INSIDE_TITLE: { if (transit == B_EXITED_VIEW && (fColumnFlags & B_ALLOW_COLUMN_REMOVE)) { // Dragged outside view fCurrentState = DRAG_COLUMN_OUTSIDE_TITLE; fSelectedColumn->SetVisible(false); BRect dragRect(fSelectedColumnRect); // See explanation above. uint32 buttons; GetMouse(&position, &buttons, false); dragRect.OffsetTo(position.x - fClickPoint.x, position.y - fClickPoint.y); BeginRectTracking(dragRect, B_TRACK_WHOLE_RECT); } else if (position.x < fLeftDragBoundry || position.x > fRightDragBoundry) { DragSelectedColumn(position - BPoint(fClickPoint.x, 0)); } #if DRAG_TITLE_OUTLINE // Set up the invalid rect to include the rect for the previous // position of the drag rect, as well as the new one. BRect invalidRect(fSelectedColumnRect); invalidRect.OffsetTo(fCurrentDragPosition.x - fClickPoint.x, 0); if (position.x < fCurrentDragPosition.x) invalidRect.left -= fCurrentDragPosition.x - position.x; else invalidRect.right += position.x - fCurrentDragPosition.x; fCurrentDragPosition = position; Invalidate(invalidRect); #endif break; } case DRAG_COLUMN_OUTSIDE_TITLE: if (transit == B_ENTERED_VIEW) { // Drag back into view EndRectTracking(); fCurrentState = DRAG_COLUMN_INSIDE_TITLE; fSelectedColumn->SetVisible(true); DragSelectedColumn(position - BPoint(fClickPoint.x, 0)); } break; case INACTIVE: // Check for cursor changes if we are over the resize area for // a column. BColumn* resizeColumn = 0; float leftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); for (int index = 0; index < fColumns->CountItems(); index++) { BColumn* column = (BColumn*) fColumns->ItemAt(index); if (!column->IsVisible()) continue; if (leftEdge > position.x + kColumnResizeAreaWidth / 2) break; float rightEdge = leftEdge + column->Width(); if (position.x > rightEdge - kColumnResizeAreaWidth / 2 && position.x < rightEdge + kColumnResizeAreaWidth / 2 && column->MaxWidth() > column->MinWidth()) { resizeColumn = column; break; } leftEdge = rightEdge + 1; } // Update the cursor if (resizeColumn) { if (resizeColumn->Width() == resizeColumn->MinWidth()) SetViewCursor(fMinResizeCursor, true); else if (resizeColumn->Width() == resizeColumn->MaxWidth()) SetViewCursor(fMaxResizeCursor, true); else SetViewCursor(fResizeCursor, true); } else SetViewCursor(B_CURSOR_SYSTEM_DEFAULT, true); break; } } void TitleView::MouseUp(BPoint position) { if (fEditMode) return; switch (fCurrentState) { case RESIZING_COLUMN: ResizeSelectedColumn(position - BPoint(fClickPoint.x, 0)); fCurrentState = INACTIVE; FixScrollBar(false); break; case PRESSING_COLUMN: { if (fMasterView->SortingEnabled()) { if (fSortColumns->HasItem(fSelectedColumn)) { if ((modifiers() & B_CONTROL_KEY) == 0 && fSortColumns->CountItems() > 1) { fSortColumns->MakeEmpty(); fSortColumns->AddItem(fSelectedColumn); } fSelectedColumn->fSortAscending = !fSelectedColumn->fSortAscending; } else { if ((modifiers() & B_CONTROL_KEY) == 0) fSortColumns->MakeEmpty(); fSortColumns->AddItem(fSelectedColumn); fSelectedColumn->fSortAscending = true; } fOutlineView->StartSorting(); } fCurrentState = INACTIVE; Invalidate(); break; } case DRAG_COLUMN_INSIDE_TITLE: fCurrentState = INACTIVE; #if DRAG_TITLE_OUTLINE Invalidate(); // xxx Can make this smaller #else Invalidate(fSelectedColumnRect); #endif SetViewCursor(B_CURSOR_SYSTEM_DEFAULT, true); break; case DRAG_COLUMN_OUTSIDE_TITLE: fCurrentState = INACTIVE; EndRectTracking(); SetViewCursor(B_CURSOR_SYSTEM_DEFAULT, true); break; default: ; } } void TitleView::FrameResized(float width, float height) { fVisibleRect.right = fVisibleRect.left + width; fVisibleRect.bottom = fVisibleRect.top + height; FixScrollBar(true); } // #pragma mark - OutlineView::OutlineView(BRect rect, BList* visibleColumns, BList* sortColumns, BColumnListView* listView) : BView(rect, "outline_view", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS), fColumns(visibleColumns), fSortColumns(sortColumns), fItemsHeight(0.0), fVisibleRect(rect.OffsetToCopy(0, 0)), fFocusRow(0), fRollOverRow(0), fLastSelectedItem(0), fFirstSelectedItem(0), fSortThread(B_BAD_THREAD_ID), fCurrentState(INACTIVE), fMasterView(listView), fSelectionMode(B_MULTIPLE_SELECTION_LIST), fTrackMouse(false), fCurrentField(0), fCurrentRow(0), fCurrentColumn(0), fMouseDown(false), fCurrentCode(B_OUTSIDE_VIEW), fEditMode(false), fDragging(false), fClickCount(0), fDropHighlightY(-1) { SetViewColor(B_TRANSPARENT_COLOR); #if DOUBLE_BUFFERED_COLUMN_RESIZE // TODO: This needs to be smart about the size of the buffer. // Also, the buffer can be shared with the title's buffer. BRect doubleBufferRect(0, 0, 600, 35); fDrawBuffer = new BBitmap(doubleBufferRect, B_RGB32, true); fDrawBufferView = new BView(doubleBufferRect, "double_buffer_view", B_FOLLOW_ALL_SIDES, 0); fDrawBuffer->Lock(); fDrawBuffer->AddChild(fDrawBufferView); fDrawBuffer->Unlock(); #endif FixScrollBar(true); fSelectionListDummyHead.fNextSelected = &fSelectionListDummyHead; fSelectionListDummyHead.fPrevSelected = &fSelectionListDummyHead; } OutlineView::~OutlineView() { #if DOUBLE_BUFFERED_COLUMN_RESIZE delete fDrawBuffer; #endif Clear(); } void OutlineView::Clear() { DeselectAll(); // Make sure selection list doesn't point to deleted rows! RecursiveDeleteRows(&fRows, false); Invalidate(); fItemsHeight = 0.0; FixScrollBar(true); } void OutlineView::SetSelectionMode(list_view_type mode) { DeselectAll(); fSelectionMode = mode; } list_view_type OutlineView::SelectionMode() const { return fSelectionMode; } void OutlineView::Deselect(BRow* row) { if (row == NULL) return; if (row->fNextSelected != 0) { row->fNextSelected->fPrevSelected = row->fPrevSelected; row->fPrevSelected->fNextSelected = row->fNextSelected; row->fNextSelected = 0; row->fPrevSelected = 0; Invalidate(); } } void OutlineView::AddToSelection(BRow* row) { if (row == NULL) return; if (row->fNextSelected == 0) { if (fSelectionMode == B_SINGLE_SELECTION_LIST) DeselectAll(); row->fNextSelected = fSelectionListDummyHead.fNextSelected; row->fPrevSelected = &fSelectionListDummyHead; row->fNextSelected->fPrevSelected = row; row->fPrevSelected->fNextSelected = row; BRect invalidRect; if (FindVisibleRect(row, &invalidRect)) Invalidate(invalidRect); } } void OutlineView::RecursiveDeleteRows(BRowContainer* list, bool isOwner) { if (list == NULL) return; while (true) { BRow* row = list->RemoveItemAt(0L); if (row == 0) break; if (row->fChildList) RecursiveDeleteRows(row->fChildList, true); delete row; } if (isOwner) delete list; } void OutlineView::RedrawColumn(BColumn* column, float leftEdge, bool isFirstColumn) { // TODO: Remove code duplication (private function which takes a view // pointer, pass "this" in non-double buffered mode)! // Watch out for sourceRect versus destRect though! if (!column) return; font_height fh; GetFontHeight(&fh); float line = 0.0; bool tintedLine = true; for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); line += iterator.CurrentRow()->Height() + 1, iterator.GoToNext()) { BRow* row = iterator.CurrentRow(); float rowHeight = row->Height(); if (line > fVisibleRect.bottom) break; tintedLine = !tintedLine; if (line + rowHeight >= fVisibleRect.top) { #if DOUBLE_BUFFERED_COLUMN_RESIZE BRect sourceRect(0, 0, column->Width(), rowHeight); #endif BRect destRect(leftEdge, line, leftEdge + column->Width(), line + rowHeight); rgb_color highColor; rgb_color lowColor; if (row->fNextSelected != 0) { if (fEditMode) { highColor = fMasterView->Color(B_COLOR_EDIT_BACKGROUND); lowColor = fMasterView->Color(B_COLOR_EDIT_BACKGROUND); } else { highColor = fMasterView->Color(B_COLOR_SELECTION); lowColor = fMasterView->Color(B_COLOR_SELECTION); } } else { highColor = fMasterView->Color(B_COLOR_BACKGROUND); lowColor = fMasterView->Color(B_COLOR_BACKGROUND); } if (tintedLine) lowColor = tint_color(lowColor, kTintedLineTint); #if DOUBLE_BUFFERED_COLUMN_RESIZE fDrawBuffer->Lock(); fDrawBufferView->SetHighColor(highColor); fDrawBufferView->SetLowColor(lowColor); BFont font; GetFont(&font); fDrawBufferView->SetFont(&font); fDrawBufferView->FillRect(sourceRect, B_SOLID_LOW); if (isFirstColumn) { // If this is the first column, double buffer drawing the latch // too. destRect.left += iterator.CurrentLevel() * kOutlineLevelIndent - fMasterView->LatchWidth(); sourceRect.left += iterator.CurrentLevel() * kOutlineLevelIndent - fMasterView->LatchWidth(); LatchType pos = B_NO_LATCH; if (row->HasLatch()) pos = row->fIsExpanded ? B_OPEN_LATCH : B_CLOSED_LATCH; BRect latchRect(sourceRect); latchRect.right = latchRect.left + fMasterView->LatchWidth(); fMasterView->DrawLatch(fDrawBufferView, latchRect, pos, row); } BField* field = row->GetField(column->fFieldID); if (field) { BRect fieldRect(sourceRect); if (isFirstColumn) fieldRect.left += fMasterView->LatchWidth(); #if CONSTRAIN_CLIPPING_REGION BRegion clipRegion(fieldRect); fDrawBufferView->PushState(); fDrawBufferView->ConstrainClippingRegion(&clipRegion); #endif fDrawBufferView->SetHighColor(fMasterView->Color( row->fNextSelected ? B_COLOR_SELECTION_TEXT : B_COLOR_TEXT)); float baseline = floor(fieldRect.top + fh.ascent + (fieldRect.Height() + 1 - (fh.ascent+fh.descent)) / 2); fDrawBufferView->MovePenTo(fieldRect.left + 8, baseline); column->DrawField(field, fieldRect, fDrawBufferView); #if CONSTRAIN_CLIPPING_REGION fDrawBufferView->PopState(); #endif } if (fFocusRow == row && !fEditMode && fMasterView->IsFocus() && Window()->IsActive()) { fDrawBufferView->SetHighColor(fMasterView->Color( B_COLOR_ROW_DIVIDER)); fDrawBufferView->StrokeRect(BRect(-1, sourceRect.top, 10000.0, sourceRect.bottom)); } fDrawBufferView->Sync(); fDrawBuffer->Unlock(); SetDrawingMode(B_OP_COPY); DrawBitmap(fDrawBuffer, sourceRect, destRect); #else SetHighColor(highColor); SetLowColor(lowColor); FillRect(destRect, B_SOLID_LOW); BField* field = row->GetField(column->fFieldID); if (field) { #if CONSTRAIN_CLIPPING_REGION BRegion clipRegion(destRect); PushState(); ConstrainClippingRegion(&clipRegion); #endif SetHighColor(fMasterView->Color(row->fNextSelected ? B_COLOR_SELECTION_TEXT : B_COLOR_TEXT)); float baseline = floor(destRect.top + fh.ascent + (destRect.Height() + 1 - (fh.ascent + fh.descent)) / 2); MovePenTo(destRect.left + 8, baseline); column->DrawField(field, destRect, this); #if CONSTRAIN_CLIPPING_REGION PopState(); #endif } if (fFocusRow == row && !fEditMode && fMasterView->IsFocus() && Window()->IsActive()) { SetHighColor(fMasterView->Color(B_COLOR_ROW_DIVIDER)); StrokeRect(BRect(0, destRect.top, 10000.0, destRect.bottom)); } #endif } } } void OutlineView::Draw(BRect invalidBounds) { #if SMART_REDRAW BRegion invalidRegion; GetClippingRegion(&invalidRegion); #endif font_height fh; GetFontHeight(&fh); float line = 0.0; bool tintedLine = true; int32 numColumns = fColumns->CountItems(); for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); iterator.GoToNext()) { BRow* row = iterator.CurrentRow(); if (line > invalidBounds.bottom) break; tintedLine = !tintedLine; float rowHeight = row->Height(); if (line > invalidBounds.top - rowHeight) { bool isFirstColumn = true; float fieldLeftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); // setup background color rgb_color lowColor; if (row->fNextSelected != 0) { if (Window()->IsActive()) { if (fEditMode) lowColor = fMasterView->Color(B_COLOR_EDIT_BACKGROUND); else lowColor = fMasterView->Color(B_COLOR_SELECTION); } else lowColor = fMasterView->Color(B_COLOR_NON_FOCUS_SELECTION); } else lowColor = fMasterView->Color(B_COLOR_BACKGROUND); if (tintedLine) lowColor = tint_color(lowColor, kTintedLineTint); for (int columnIndex = 0; columnIndex < numColumns; columnIndex++) { BColumn* column = (BColumn*) fColumns->ItemAt(columnIndex); if (!column->IsVisible()) continue; if (!isFirstColumn && fieldLeftEdge > invalidBounds.right) break; if (fieldLeftEdge + column->Width() >= invalidBounds.left) { BRect fullRect(fieldLeftEdge, line, fieldLeftEdge + column->Width(), line + rowHeight); bool clippedFirstColumn = false; // This happens when a column is indented past the // beginning of the next column. SetHighColor(lowColor); BRect destRect(fullRect); if (isFirstColumn) { fullRect.left -= fMasterView->LatchWidth(); destRect.left += iterator.CurrentLevel() * kOutlineLevelIndent; if (destRect.left >= destRect.right) { // clipped FillRect(BRect(0, line, fieldLeftEdge + column->Width(), line + rowHeight)); clippedFirstColumn = true; } FillRect(BRect(0, line, MAX(kLeftMargin, fMasterView->LatchWidth()), line + row->Height())); } #if SMART_REDRAW if (!clippedFirstColumn && invalidRegion.Intersects(fullRect)) { #else if (!clippedFirstColumn) { #endif FillRect(fullRect); // Using color set above // Draw the latch widget if it has one. if (isFirstColumn) { if (row == fTargetRow && fCurrentState == LATCH_CLICKED) { // Note that this only occurs if the user is // holding down a latch while items are added // in the background. BPoint pos; uint32 buttons; GetMouse(&pos, &buttons); if (fLatchRect.Contains(pos)) { fMasterView->DrawLatch(this, fLatchRect, B_PRESSED_LATCH, fTargetRow); } else { fMasterView->DrawLatch(this, fLatchRect, row->fIsExpanded ? B_OPEN_LATCH : B_CLOSED_LATCH, fTargetRow); } } else { LatchType pos = B_NO_LATCH; if (row->HasLatch()) pos = row->fIsExpanded ? B_OPEN_LATCH : B_CLOSED_LATCH; fMasterView->DrawLatch(this, BRect(destRect.left - fMasterView->LatchWidth(), destRect.top, destRect.left, destRect.bottom), pos, row); } } SetHighColor(fMasterView->HighColor()); // The master view just holds the high color for us. SetLowColor(lowColor); BField* field = row->GetField(column->fFieldID); if (field) { #if CONSTRAIN_CLIPPING_REGION BRegion clipRegion(destRect); PushState(); ConstrainClippingRegion(&clipRegion); #endif SetHighColor(fMasterView->Color( row->fNextSelected ? B_COLOR_SELECTION_TEXT : B_COLOR_TEXT)); float baseline = floor(destRect.top + fh.ascent + (destRect.Height() + 1 - (fh.ascent+fh.descent)) / 2); MovePenTo(destRect.left + 8, baseline); column->DrawField(field, destRect, this); #if CONSTRAIN_CLIPPING_REGION PopState(); #endif } } } isFirstColumn = false; fieldLeftEdge += column->Width() + 1; } if (fieldLeftEdge <= invalidBounds.right) { SetHighColor(lowColor); FillRect(BRect(fieldLeftEdge, line, invalidBounds.right, line + rowHeight)); } } // indicate the keyboard focus row if (fFocusRow == row && !fEditMode && fMasterView->IsFocus() && Window()->IsActive()) { SetHighColor(fMasterView->Color(B_COLOR_ROW_DIVIDER)); StrokeRect(BRect(0, line, 10000.0, line + rowHeight)); } line += rowHeight + 1; } if (line <= invalidBounds.bottom) { // fill background below last item SetHighColor(fMasterView->Color(B_COLOR_BACKGROUND)); FillRect(BRect(invalidBounds.left, line, invalidBounds.right, invalidBounds.bottom)); } // Draw the drop target line if (fDropHighlightY != -1) { InvertRect(BRect(0, fDropHighlightY - kDropHighlightLineHeight / 2, 1000000, fDropHighlightY + kDropHighlightLineHeight / 2)); } } BRow* OutlineView::FindRow(float ypos, int32* _rowIndent, float* _top) { if (_rowIndent && _top) { float line = 0.0; for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); iterator.GoToNext()) { BRow* row = iterator.CurrentRow(); if (line > ypos) break; float rowHeight = row->Height(); if (ypos <= line + rowHeight) { *_top = line; *_rowIndent = iterator.CurrentLevel(); return row; } line += rowHeight + 1; } } return NULL; } void OutlineView::SetMouseTrackingEnabled(bool enabled) { fTrackMouse = enabled; if (!enabled && fDropHighlightY != -1) { // Erase the old target line InvertRect(BRect(0, fDropHighlightY - kDropHighlightLineHeight / 2, 1000000, fDropHighlightY + kDropHighlightLineHeight / 2)); fDropHighlightY = -1; } } // // Note that this interaction is not totally safe. If items are added to // the list in the background, the widget rect will be incorrect, possibly // resulting in drawing glitches. The code that adds items needs to be a little smarter // about invalidating state. // void OutlineView::MouseDown(BPoint position) { if (!fEditMode) fMasterView->MakeFocus(true); // Check to see if the user is clicking on a widget to open a section // of the list. bool reset_click_count = false; int32 indent; float rowTop; BRow* row = FindRow(position.y, &indent, &rowTop); if (row != NULL) { // Update fCurrentField bool handle_field = false; BField* new_field = 0; BRow* new_row = 0; BColumn* new_column = 0; BRect new_rect; if (position.y >= 0) { if (position.x >= 0) { float x = 0; for (int32 c = 0; c < fMasterView->CountColumns(); c++) { new_column = fMasterView->ColumnAt(c); if (!new_column->IsVisible()) continue; if ((MAX(kLeftMargin, fMasterView->LatchWidth()) + x) + new_column->Width() >= position.x) { if (new_column->WantsEvents()) { new_field = row->GetField(c); new_row = row; FindRect(new_row,&new_rect); new_rect.left = MAX(kLeftMargin, fMasterView->LatchWidth()) + x; new_rect.right = new_rect.left + new_column->Width() - 1; handle_field = true; } break; } x += new_column->Width(); } } } // Handle mouse down if (handle_field) { fMouseDown = true; fFieldRect = new_rect; fCurrentColumn = new_column; fCurrentRow = new_row; fCurrentField = new_field; fCurrentCode = B_INSIDE_VIEW; fCurrentColumn->MouseDown(fMasterView, fCurrentRow, fCurrentField, fFieldRect, position, 1); } if (!fEditMode) { fTargetRow = row; fTargetRowTop = rowTop; FindVisibleRect(fFocusRow, &fFocusRowRect); float leftWidgetBoundry = indent * kOutlineLevelIndent + MAX(kLeftMargin, fMasterView->LatchWidth()) - fMasterView->LatchWidth(); fLatchRect.Set(leftWidgetBoundry, rowTop, leftWidgetBoundry + fMasterView->LatchWidth(), rowTop + row->Height()); if (fLatchRect.Contains(position) && row->HasLatch()) { fCurrentState = LATCH_CLICKED; if (fTargetRow->fNextSelected != 0) SetHighColor(fMasterView->Color(B_COLOR_SELECTION)); else SetHighColor(fMasterView->Color(B_COLOR_BACKGROUND)); FillRect(fLatchRect); if (fLatchRect.Contains(position)) { fMasterView->DrawLatch(this, fLatchRect, B_PRESSED_LATCH, row); } else { fMasterView->DrawLatch(this, fLatchRect, fTargetRow->fIsExpanded ? B_OPEN_LATCH : B_CLOSED_LATCH, row); } } else { Invalidate(fFocusRowRect); fFocusRow = fTargetRow; FindVisibleRect(fFocusRow, &fFocusRowRect); ASSERT(fTargetRow != 0); if ((modifiers() & B_CONTROL_KEY) == 0) DeselectAll(); if ((modifiers() & B_SHIFT_KEY) != 0 && fFirstSelectedItem != 0 && fSelectionMode == B_MULTIPLE_SELECTION_LIST) { SelectRange(fFirstSelectedItem, fTargetRow); } else { if (fTargetRow->fNextSelected != 0) { // Unselect row fTargetRow->fNextSelected->fPrevSelected = fTargetRow->fPrevSelected; fTargetRow->fPrevSelected->fNextSelected = fTargetRow->fNextSelected; fTargetRow->fPrevSelected = 0; fTargetRow->fNextSelected = 0; fFirstSelectedItem = NULL; } else { // Select row if (fSelectionMode == B_SINGLE_SELECTION_LIST) DeselectAll(); fTargetRow->fNextSelected = fSelectionListDummyHead.fNextSelected; fTargetRow->fPrevSelected = &fSelectionListDummyHead; fTargetRow->fNextSelected->fPrevSelected = fTargetRow; fTargetRow->fPrevSelected->fNextSelected = fTargetRow; fFirstSelectedItem = fTargetRow; } Invalidate(BRect(fVisibleRect.left, fTargetRowTop, fVisibleRect.right, fTargetRowTop + fTargetRow->Height())); } fCurrentState = ROW_CLICKED; if (fLastSelectedItem != fTargetRow) reset_click_count = true; fLastSelectedItem = fTargetRow; fMasterView->SelectionChanged(); } } SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY); } else if (fFocusRow != 0) { // User clicked in open space, unhighlight focus row. FindVisibleRect(fFocusRow, &fFocusRowRect); fFocusRow = 0; Invalidate(fFocusRowRect); } // We stash the click counts here because the 'clicks' field // is not in the CurrentMessage() when MouseUp is called... ;( if (reset_click_count) fClickCount = 1; else Window()->CurrentMessage()->FindInt32("clicks", &fClickCount); fClickPoint = position; } void OutlineView::MouseMoved(BPoint position, uint32 /*transit*/, const BMessage* /*dragMessage*/) { if (!fMouseDown) { // Update fCurrentField bool handle_field = false; BField* new_field = 0; BRow* new_row = 0; BColumn* new_column = 0; BRect new_rect(0,0,0,0); if (position.y >=0 ) { float top; int32 indent; BRow* row = FindRow(position.y, &indent, &top); if (row && position.x >=0 ) { float x=0; for (int32 c=0;c<fMasterView->CountColumns();c++) { new_column = fMasterView->ColumnAt(c); if (!new_column->IsVisible()) continue; if ((MAX(kLeftMargin, fMasterView->LatchWidth()) + x) + new_column->Width() > position.x) { if(new_column->WantsEvents()) { new_field = row->GetField(c); new_row = row; FindRect(new_row,&new_rect); new_rect.left = MAX(kLeftMargin, fMasterView->LatchWidth()) + x; new_rect.right = new_rect.left + new_column->Width() - 1; handle_field = true; } break; } x += new_column->Width(); } } } // Handle mouse moved if (handle_field) { if (new_field != fCurrentField) { if (fCurrentField) { fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, fCurrentField, fFieldRect, position, 0, fCurrentCode = B_EXITED_VIEW); } fCurrentColumn = new_column; fCurrentRow = new_row; fCurrentField = new_field; fFieldRect = new_rect; if (fCurrentField) { fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, fCurrentField, fFieldRect, position, 0, fCurrentCode = B_ENTERED_VIEW); } } else { if (fCurrentField) { fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, fCurrentField, fFieldRect, position, 0, fCurrentCode = B_INSIDE_VIEW); } } } else { if (fCurrentField) { fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, fCurrentField, fFieldRect, position, 0, fCurrentCode = B_EXITED_VIEW); fCurrentField = 0; fCurrentColumn = 0; fCurrentRow = 0; } } } else { if (fCurrentField) { if (fFieldRect.Contains(position)) { if (fCurrentCode == B_OUTSIDE_VIEW || fCurrentCode == B_EXITED_VIEW) { fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, fCurrentField, fFieldRect, position, 1, fCurrentCode = B_ENTERED_VIEW); } else { fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, fCurrentField, fFieldRect, position, 1, fCurrentCode = B_INSIDE_VIEW); } } else { if (fCurrentCode == B_INSIDE_VIEW || fCurrentCode == B_ENTERED_VIEW) { fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, fCurrentField, fFieldRect, position, 1, fCurrentCode = B_EXITED_VIEW); } else { fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, fCurrentField, fFieldRect, position, 1, fCurrentCode = B_OUTSIDE_VIEW); } } } } if (!fEditMode) { switch (fCurrentState) { case LATCH_CLICKED: if (fTargetRow->fNextSelected != 0) SetHighColor(fMasterView->Color(B_COLOR_SELECTION)); else SetHighColor(fMasterView->Color(B_COLOR_BACKGROUND)); FillRect(fLatchRect); if (fLatchRect.Contains(position)) { fMasterView->DrawLatch(this, fLatchRect, B_PRESSED_LATCH, fTargetRow); } else { fMasterView->DrawLatch(this, fLatchRect, fTargetRow->fIsExpanded ? B_OPEN_LATCH : B_CLOSED_LATCH, fTargetRow); } break; case ROW_CLICKED: if (abs((int)(position.x - fClickPoint.x)) > kRowDragSensitivity || abs((int)(position.y - fClickPoint.y)) > kRowDragSensitivity) { fCurrentState = DRAGGING_ROWS; fMasterView->InitiateDrag(fClickPoint, fTargetRow->fNextSelected != 0); } break; case DRAGGING_ROWS: #if 0 // falls through... #else if (fTrackMouse /*&& message*/) { if (fVisibleRect.Contains(position)) { float top; int32 indent; BRow* target = FindRow(position.y, &indent, &top); if (target) SetFocusRow(target, true); } } break; #endif default: { if (fTrackMouse /*&& message*/) { // Draw a highlight line... if (fVisibleRect.Contains(position)) { float top; int32 indent; BRow* target = FindRow(position.y, &indent, &top); if (target == fRollOverRow) break; if (fRollOverRow) { BRect rect; FindRect(fRollOverRow, &rect); Invalidate(rect); } fRollOverRow = target; #if 0 SetFocusRow(fRollOverRow,false); #else PushState(); SetDrawingMode(B_OP_BLEND); SetHighColor(255, 255, 255, 255); BRect rect; FindRect(fRollOverRow, &rect); rect.bottom -= 1.0; FillRect(rect); PopState(); #endif } else { if (fRollOverRow) { BRect rect; FindRect(fRollOverRow, &rect); Invalidate(rect); fRollOverRow = NULL; } } } } } } } void OutlineView::MouseUp(BPoint position) { if (fCurrentField) { fCurrentColumn->MouseUp(fMasterView, fCurrentRow, fCurrentField); fMouseDown = false; } if (fEditMode) return; switch (fCurrentState) { case LATCH_CLICKED: if (fLatchRect.Contains(position)) { fMasterView->ExpandOrCollapse(fTargetRow, !fTargetRow->fIsExpanded); } Invalidate(fLatchRect); fCurrentState = INACTIVE; break; case ROW_CLICKED: if (fClickCount > 1 && abs((int)fClickPoint.x - (int)position.x) < kDoubleClickMoveSensitivity && abs((int)fClickPoint.y - (int)position.y) < kDoubleClickMoveSensitivity) { fMasterView->ItemInvoked(); } fCurrentState = INACTIVE; break; case DRAGGING_ROWS: fCurrentState = INACTIVE; // Falls through default: if (fDropHighlightY != -1) { InvertRect(BRect(0, fDropHighlightY - kDropHighlightLineHeight / 2, 1000000, fDropHighlightY + kDropHighlightLineHeight / 2)); // Erase the old target line fDropHighlightY = -1; } } } void OutlineView::MessageReceived(BMessage* message) { if (message->WasDropped()) { fMasterView->MessageDropped(message, ConvertFromScreen(message->DropPoint())); } else { BView::MessageReceived(message); } } void OutlineView::ChangeFocusRow(bool up, bool updateSelection, bool addToCurrentSelection) { int32 indent; float top; float newRowPos = 0; float verticalScroll = 0; if (fFocusRow) { // A row currently has the focus, get information about it newRowPos = fFocusRowRect.top + (up ? -4 : fFocusRow->Height() + 4); if (newRowPos < fVisibleRect.top + 20) verticalScroll = newRowPos - 20; else if (newRowPos > fVisibleRect.bottom - 20) verticalScroll = newRowPos - fVisibleRect.Height() + 20; } else newRowPos = fVisibleRect.top + 2; // no row is currently focused, set this to the top of the window // so we will select the first visible item in the list. BRow* newRow = FindRow(newRowPos, &indent, &top); if (newRow) { if (fFocusRow) { fFocusRowRect.right = 10000; Invalidate(fFocusRowRect); } fFocusRow = newRow; fFocusRowRect.top = top; fFocusRowRect.left = 0; fFocusRowRect.right = 10000; fFocusRowRect.bottom = fFocusRowRect.top + fFocusRow->Height(); Invalidate(fFocusRowRect); if (updateSelection) { if (!addToCurrentSelection || fSelectionMode == B_SINGLE_SELECTION_LIST) { DeselectAll(); } if (fFocusRow->fNextSelected == 0) { fFocusRow->fNextSelected = fSelectionListDummyHead.fNextSelected; fFocusRow->fPrevSelected = &fSelectionListDummyHead; fFocusRow->fNextSelected->fPrevSelected = fFocusRow; fFocusRow->fPrevSelected->fNextSelected = fFocusRow; } fLastSelectedItem = fFocusRow; } } else Invalidate(fFocusRowRect); if (verticalScroll != 0) { BScrollBar* vScrollBar = ScrollBar(B_VERTICAL); float min, max; vScrollBar->GetRange(&min, &max); if (verticalScroll < min) verticalScroll = min; else if (verticalScroll > max) verticalScroll = max; vScrollBar->SetValue(verticalScroll); } if (newRow && updateSelection) fMasterView->SelectionChanged(); } void OutlineView::MoveFocusToVisibleRect() { fFocusRow = 0; ChangeFocusRow(true, true, false); } BRow* OutlineView::CurrentSelection(BRow* lastSelected) const { BRow* row; if (lastSelected == 0) row = fSelectionListDummyHead.fNextSelected; else row = lastSelected->fNextSelected; if (row == &fSelectionListDummyHead) row = 0; return row; } void OutlineView::ToggleFocusRowSelection(bool selectRange) { if (fFocusRow == 0) return; if (selectRange && fSelectionMode == B_MULTIPLE_SELECTION_LIST) SelectRange(fLastSelectedItem, fFocusRow); else { if (fFocusRow->fNextSelected != 0) { // Unselect row fFocusRow->fNextSelected->fPrevSelected = fFocusRow->fPrevSelected; fFocusRow->fPrevSelected->fNextSelected = fFocusRow->fNextSelected; fFocusRow->fPrevSelected = 0; fFocusRow->fNextSelected = 0; } else { // Select row if (fSelectionMode == B_SINGLE_SELECTION_LIST) DeselectAll(); fFocusRow->fNextSelected = fSelectionListDummyHead.fNextSelected; fFocusRow->fPrevSelected = &fSelectionListDummyHead; fFocusRow->fNextSelected->fPrevSelected = fFocusRow; fFocusRow->fPrevSelected->fNextSelected = fFocusRow; } } fLastSelectedItem = fFocusRow; fMasterView->SelectionChanged(); Invalidate(fFocusRowRect); } void OutlineView::ToggleFocusRowOpen() { if (fFocusRow) fMasterView->ExpandOrCollapse(fFocusRow, !fFocusRow->fIsExpanded); } void OutlineView::ExpandOrCollapse(BRow* parentRow, bool expand) { // TODO: Could use CopyBits here to speed things up. if (parentRow == NULL) return; if (parentRow->fIsExpanded == expand) return; parentRow->fIsExpanded = expand; BRect parentRect; if (FindRect(parentRow, &parentRect)) { // Determine my new height float subTreeHeight = 0.0; if (parentRow->fIsExpanded) for (RecursiveOutlineIterator iterator(parentRow->fChildList); iterator.CurrentRow(); iterator.GoToNext() ) { subTreeHeight += iterator.CurrentRow()->Height()+1; } else for (RecursiveOutlineIterator iterator(parentRow->fChildList); iterator.CurrentRow(); iterator.GoToNext() ) { subTreeHeight -= iterator.CurrentRow()->Height()+1; } fItemsHeight += subTreeHeight; // Adjust focus row if necessary. if (FindRect(fFocusRow, &fFocusRowRect) == false) { // focus row is in a subtree that has collapsed, // move it up to the parent. fFocusRow = parentRow; FindRect(fFocusRow, &fFocusRowRect); } Invalidate(BRect(0, parentRect.top, fVisibleRect.right, fVisibleRect.bottom)); FixScrollBar(false); } } void OutlineView::RemoveRow(BRow* row) { if (row == NULL) return; BRow* parentRow; bool parentIsVisible; float subTreeHeight = row->Height(); if (FindParent(row, &parentRow, &parentIsVisible)) { // adjust height if (parentIsVisible && (parentRow == 0 || parentRow->fIsExpanded)) { if (row->fIsExpanded) { for (RecursiveOutlineIterator iterator(row->fChildList); iterator.CurrentRow(); iterator.GoToNext()) subTreeHeight += iterator.CurrentRow()->Height(); } } } if (parentRow) { if (parentRow->fIsExpanded) fItemsHeight -= subTreeHeight + 1; } else { fItemsHeight -= subTreeHeight + 1; } FixScrollBar(false); if (parentRow) parentRow->fChildList->RemoveItem(row); else fRows.RemoveItem(row); if (parentRow != 0 && parentRow->fChildList->CountItems() == 0) { delete parentRow->fChildList; parentRow->fChildList = 0; if (parentIsVisible) Invalidate(); // xxx crude way of redrawing latch } if (parentIsVisible && (parentRow == 0 || parentRow->fIsExpanded)) Invalidate(); // xxx make me smarter. // Adjust focus row if necessary. if (fFocusRow && FindRect(fFocusRow, &fFocusRowRect) == false) { // focus row is in a subtree that is gone, move it up to the parent. fFocusRow = parentRow; if (fFocusRow) FindRect(fFocusRow, &fFocusRowRect); } // Remove this from the selection if necessary if (row->fNextSelected != 0) { row->fNextSelected->fPrevSelected = row->fPrevSelected; row->fPrevSelected->fNextSelected = row->fNextSelected; row->fPrevSelected = 0; row->fNextSelected = 0; fMasterView->SelectionChanged(); } fCurrentColumn = 0; fCurrentRow = 0; fCurrentField = 0; } BRowContainer* OutlineView::RowList() { return &fRows; } void OutlineView::UpdateRow(BRow* row) { if (row) { // Determine if this row has changed its sort order BRow* parentRow = NULL; bool parentIsVisible = false; FindParent(row, &parentRow, &parentIsVisible); BRowContainer* list = (parentRow == NULL) ? &fRows : parentRow->fChildList; if(list) { int32 rowIndex = list->IndexOf(row); ASSERT(rowIndex >= 0); ASSERT(list->ItemAt(rowIndex) == row); bool rowMoved = false; if (rowIndex > 0 && CompareRows(list->ItemAt(rowIndex - 1), row) > 0) rowMoved = true; if (rowIndex < list->CountItems() - 1 && CompareRows(list->ItemAt(rowIndex + 1), row) < 0) rowMoved = true; if (rowMoved) { // Sort location of this row has changed. // Remove and re-add in the right spot SortList(list, parentIsVisible && (parentRow == NULL || parentRow->fIsExpanded)); } else if (parentIsVisible && (parentRow == NULL || parentRow->fIsExpanded)) { BRect invalidRect; if (FindVisibleRect(row, &invalidRect)) Invalidate(invalidRect); } } } } void OutlineView::AddRow(BRow* row, int32 Index, BRow* parentRow) { if (!row) return; row->fParent = parentRow; if (fMasterView->SortingEnabled()) { // Ignore index here. if (parentRow) { if (parentRow->fChildList == NULL) parentRow->fChildList = new BRowContainer; AddSorted(parentRow->fChildList, row); } else AddSorted(&fRows, row); } else { // Note, a -1 index implies add to end if sorting is not enabled if (parentRow) { if (parentRow->fChildList == 0) parentRow->fChildList = new BRowContainer; if (Index < 0 || Index > parentRow->fChildList->CountItems()) parentRow->fChildList->AddItem(row); else parentRow->fChildList->AddItem(row, Index); } else { if (Index < 0 || Index >= fRows.CountItems()) fRows.AddItem(row); else fRows.AddItem(row, Index); } } if (parentRow == 0 || parentRow->fIsExpanded) fItemsHeight += row->Height() + 1; FixScrollBar(false); BRect newRowRect; bool newRowIsInOpenBranch = FindRect(row, &newRowRect); if (fFocusRow && fFocusRowRect.top > newRowRect.bottom) { // The focus row has moved. Invalidate(fFocusRowRect); FindRect(fFocusRow, &fFocusRowRect); Invalidate(fFocusRowRect); } if (newRowIsInOpenBranch) { if (fCurrentState == INACTIVE) { if (newRowRect.bottom < fVisibleRect.top) { // The new row is totally above the current viewport, move // everything down and redraw the first line. BRect source(fVisibleRect); BRect dest(fVisibleRect); source.bottom -= row->Height() + 1; dest.top += row->Height() + 1; CopyBits(source, dest); Invalidate(BRect(fVisibleRect.left, fVisibleRect.top, fVisibleRect.right, fVisibleRect.top + newRowRect.Height())); } else if (newRowRect.top < fVisibleRect.bottom) { // New item is somewhere in the current region. Scroll everything // beneath it down and invalidate just the new row rect. BRect source(fVisibleRect.left, newRowRect.top, fVisibleRect.right, fVisibleRect.bottom - newRowRect.Height()); BRect dest(source); dest.OffsetBy(0, newRowRect.Height() + 1); CopyBits(source, dest); Invalidate(newRowRect); } // otherwise, this is below the currently visible region } else { // Adding the item may have caused the item that the user is currently // selected to move. This would cause annoying drawing and interaction // bugs, as the position of that item is cached. If this happens, resize // the scroll bar, then scroll back so the selected item is in view. BRect targetRect; if (FindRect(fTargetRow, &targetRect)) { float delta = targetRect.top - fTargetRowTop; if (delta != 0) { // This causes a jump because ScrollBy will copy a chunk of the view. // Since the actual contents of the view have been offset, we don't // want this, we just want to change the virtual origin of the window. // Constrain the clipping region so everything is clipped out so no // copy occurs. // // xxx this currently doesn't work if the scroll bars aren't enabled. // everything will still move anyway. A minor annoyance. BRegion emptyRegion; ConstrainClippingRegion(&emptyRegion); PushState(); ScrollBy(0, delta); PopState(); ConstrainClippingRegion(NULL); fTargetRowTop += delta; fClickPoint.y += delta; fLatchRect.OffsetBy(0, delta); } } } } // If the parent was previously childless, it will need to have a latch // drawn. BRect parentRect; if (parentRow && parentRow->fChildList->CountItems() == 1 && FindVisibleRect(parentRow, &parentRect)) Invalidate(parentRect); } void OutlineView::FixScrollBar(bool scrollToFit) { BScrollBar* vScrollBar = ScrollBar(B_VERTICAL); if (vScrollBar) { if (fItemsHeight > fVisibleRect.Height()) { float maxScrollBarValue = fItemsHeight - fVisibleRect.Height(); vScrollBar->SetProportion(fVisibleRect.Height() / fItemsHeight); // If the user is scrolled down too far when makes the range smaller, the list // will jump suddenly, which is undesirable. In this case, don't fix the scroll // bar here. In ScrollTo, it checks to see if this has occured, and will // fix the scroll bars sneakily if the user has scrolled up far enough. if (scrollToFit || vScrollBar->Value() <= maxScrollBarValue) { vScrollBar->SetRange(0.0, maxScrollBarValue); vScrollBar->SetSteps(20.0, fVisibleRect.Height()); } } else if (vScrollBar->Value() == 0.0) vScrollBar->SetRange(0.0, 0.0); // disable scroll bar. } } void OutlineView::AddSorted(BRowContainer* list, BRow* row) { if (list && row) { // Find general vicinity with binary search. int32 lower = 0; int32 upper = list->CountItems()-1; while( lower < upper ) { int32 middle = lower + (upper-lower+1)/2; int32 cmp = CompareRows(row, list->ItemAt(middle)); if( cmp < 0 ) upper = middle-1; else if( cmp > 0 ) lower = middle+1; else lower = upper = middle; } // At this point, 'upper' and 'lower' at the last found item. // Arbitrarily use 'upper' and determine the final insertion // point -- either before or after this item. if( upper < 0 ) upper = 0; else if( upper < list->CountItems() ) { if( CompareRows(row, list->ItemAt(upper)) > 0 ) upper++; } if (upper >= list->CountItems()) list->AddItem(row); // Adding to end. else list->AddItem(row, upper); // Insert } } int32 OutlineView::CompareRows(BRow* row1, BRow* row2) { int32 itemCount (fSortColumns->CountItems()); if (row1 && row2) { for (int32 index = 0; index < itemCount; index++) { BColumn* column = (BColumn*) fSortColumns->ItemAt(index); int comp = 0; BField* field1 = (BField*) row1->GetField(column->fFieldID); BField* field2 = (BField*) row2->GetField(column->fFieldID); if (field1 && field2) comp = column->CompareFields(field1, field2); if (!column->fSortAscending) comp = -comp; if (comp != 0) return comp; } } return 0; } void OutlineView::FrameResized(float width, float height) { fVisibleRect.right = fVisibleRect.left + width; fVisibleRect.bottom = fVisibleRect.top + height; FixScrollBar(true); _inherited::FrameResized(width, height); } void OutlineView::ScrollTo(BPoint position) { fVisibleRect.OffsetTo(position.x, position.y); // In FixScrollBar, we might not have been able to change the size of // the scroll bar because the user was scrolled down too far. Take // this opportunity to sneak it in if we can. BScrollBar* vScrollBar = ScrollBar(B_VERTICAL); float maxScrollBarValue = fItemsHeight - fVisibleRect.Height(); float min, max; vScrollBar->GetRange(&min, &max); if (max != maxScrollBarValue && position.y > maxScrollBarValue) FixScrollBar(true); _inherited::ScrollTo(position); } const BRect& OutlineView::VisibleRect() const { return fVisibleRect; } bool OutlineView::FindVisibleRect(BRow* row, BRect* _rect) { if (row && _rect) { float line = 0.0; for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); iterator.GoToNext()) { if (line > fVisibleRect.bottom) break; if (iterator.CurrentRow() == row) { _rect->Set(fVisibleRect.left, line, fVisibleRect.right, line + row->Height()); return true; } line += iterator.CurrentRow()->Height() + 1; } } return false; } bool OutlineView::FindRect(const BRow* row, BRect* _rect) { float line = 0.0; for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); iterator.GoToNext()) { if (iterator.CurrentRow() == row) { _rect->Set(fVisibleRect.left, line, fVisibleRect.right, line + row->Height()); return true; } line += iterator.CurrentRow()->Height() + 1; } return false; } void OutlineView::ScrollTo(const BRow* row) { BRect rect; if (FindRect(row, &rect)) { BRect bounds = Bounds(); if (rect.top < bounds.top) ScrollTo(BPoint(bounds.left, rect.top)); else if (rect.bottom > bounds.bottom) ScrollBy(0, rect.bottom - bounds.bottom); } } void OutlineView::DeselectAll() { // Invalidate all selected rows float line = 0.0; for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); iterator.GoToNext()) { if (line > fVisibleRect.bottom) break; BRow* row = iterator.CurrentRow(); if (line + row->Height() > fVisibleRect.top) { if (row->fNextSelected != 0) Invalidate(BRect(fVisibleRect.left, line, fVisibleRect.right, line + row->Height())); } line += row->Height() + 1; } // Set items not selected while (fSelectionListDummyHead.fNextSelected != &fSelectionListDummyHead) { BRow* row = fSelectionListDummyHead.fNextSelected; row->fNextSelected->fPrevSelected = row->fPrevSelected; row->fPrevSelected->fNextSelected = row->fNextSelected; row->fNextSelected = 0; row->fPrevSelected = 0; } } BRow* OutlineView::FocusRow() const { return fFocusRow; } void OutlineView::SetFocusRow(BRow* row, bool Select) { if (row) { if (Select) AddToSelection(row); if (fFocusRow == row) return; Invalidate(fFocusRowRect); // invalidate previous fTargetRow = fFocusRow = row; FindVisibleRect(fFocusRow, &fFocusRowRect); Invalidate(fFocusRowRect); // invalidate current fFocusRowRect.right = 10000; fMasterView->SelectionChanged(); } } bool OutlineView::SortList(BRowContainer* list, bool isVisible) { if (list) { // Shellsort BRow** items = (BRow**) list->AsBList()->Items(); int32 numItems = list->CountItems(); int h; for (h = 1; h < numItems / 9; h = 3 * h + 1) ; for (;h > 0; h /= 3) { for (int step = h; step < numItems; step++) { BRow* temp = items[step]; int i; for (i = step - h; i >= 0; i -= h) { if (CompareRows(temp, items[i]) < 0) items[i + h] = items[i]; else break; } items[i + h] = temp; } } if (isVisible) { Invalidate(); InvalidateCachedPositions(); int lockCount = Window()->CountLocks(); for (int i = 0; i < lockCount; i++) Window()->Unlock(); while (lockCount--) if (!Window()->Lock()) return false; // Window is gone... } } return true; } int32 OutlineView::DeepSortThreadEntry(void* _outlineView) { ((OutlineView*) _outlineView)->DeepSort(); return 0; } void OutlineView::DeepSort() { struct stack_entry { bool isVisible; BRowContainer* list; int32 listIndex; } stack[kMaxDepth]; int32 stackTop = 0; stack[stackTop].list = &fRows; stack[stackTop].isVisible = true; stack[stackTop].listIndex = 0; fNumSorted = 0; if (Window()->Lock() == false) return; bool doneSorting = false; while (!doneSorting && !fSortCancelled) { stack_entry* currentEntry = &stack[stackTop]; // xxx Can make the invalidate area smaller by finding the rect for the // parent item and using that as the top of the invalid rect. bool haveLock = SortList(currentEntry->list, currentEntry->isVisible); if (!haveLock) return ; // window is gone. // Fix focus rect. InvalidateCachedPositions(); if (fCurrentState != INACTIVE) fCurrentState = INACTIVE; // sorry... // next list. bool foundNextList = false; while (!foundNextList && !fSortCancelled) { for (int32 index = currentEntry->listIndex; index < currentEntry->list->CountItems(); index++) { BRow* parentRow = currentEntry->list->ItemAt(index); BRowContainer* childList = parentRow->fChildList; if (childList != 0) { currentEntry->listIndex = index + 1; stackTop++; ASSERT(stackTop < kMaxDepth); stack[stackTop].listIndex = 0; stack[stackTop].list = childList; stack[stackTop].isVisible = (currentEntry->isVisible && parentRow->fIsExpanded); foundNextList = true; break; } } if (!foundNextList) { // back up if (--stackTop < 0) { doneSorting = true; break; } currentEntry = &stack[stackTop]; } } } Window()->Unlock(); } void OutlineView::StartSorting() { // If this view is not yet attached to a window, don't start a sort thread! if (Window() == NULL) return; if (fSortThread != B_BAD_THREAD_ID) { thread_info tinfo; if (get_thread_info(fSortThread, &tinfo) == B_OK) { // Unlock window so this won't deadlock (sort thread is probably // waiting to lock window). int lockCount = Window()->CountLocks(); for (int i = 0; i < lockCount; i++) Window()->Unlock(); fSortCancelled = true; int32 status; wait_for_thread(fSortThread, &status); while (lockCount--) if (!Window()->Lock()) return ; // Window is gone... } } fSortCancelled = false; fSortThread = spawn_thread(DeepSortThreadEntry, "sort_thread", B_NORMAL_PRIORITY, this); resume_thread(fSortThread); } void OutlineView::SelectRange(BRow* start, BRow* end) { if (!start || !end) return; if (start == end) // start is always selected when this is called return; RecursiveOutlineIterator iterator(&fRows, false); while (iterator.CurrentRow() != 0) { if (iterator.CurrentRow() == end) { // reverse selection, swap to fix special case BRow* temp = start; start = end; end = temp; break; } else if (iterator.CurrentRow() == start) break; iterator.GoToNext(); } while (true) { BRow* row = iterator.CurrentRow(); if (row) { if (row->fNextSelected == 0) { row->fNextSelected = fSelectionListDummyHead.fNextSelected; row->fPrevSelected = &fSelectionListDummyHead; row->fNextSelected->fPrevSelected = row; row->fPrevSelected->fNextSelected = row; } } else break; if (row == end) break; iterator.GoToNext(); } Invalidate(); // xxx make invalidation smaller } bool OutlineView::FindParent(BRow* row, BRow** outParent, bool* out_parentIsVisible) { bool result = false; if (row && outParent) { *outParent = row->fParent; // Walk up the parent chain to determine if this row is visible bool isVisible = true; for (BRow* currentRow = row->fParent; currentRow; currentRow = currentRow->fParent) { if (!currentRow->fIsExpanded) { isVisible = false; break; } } if (out_parentIsVisible) *out_parentIsVisible = isVisible; result = (NULL != *outParent); } return result; } int32 OutlineView::IndexOf(BRow* row) { if (row) { if (row->fParent == 0) return fRows.IndexOf(row); ASSERT(row->fParent->fChildList); return row->fParent->fChildList->IndexOf(row); } return B_ERROR; } void OutlineView::InvalidateCachedPositions() { if (fFocusRow) FindRect(fFocusRow, &fFocusRowRect); } float OutlineView::GetColumnPreferredWidth(BColumn* column) { float preferred = 0.0; for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); iterator.GoToNext()) { BRow* row = iterator.CurrentRow(); BField* field = row->GetField(column->fFieldID); if (field) { float width = column->GetPreferredWidth(field, this); if (preferred < width) preferred = width; } } // Constrain to preferred width. This makes the method do a little // more than asked, but it's for convenience. if (preferred < column->MinWidth()) preferred = column->MinWidth(); else if (preferred > column->MaxWidth()) preferred = column->MaxWidth(); return preferred; } // #pragma mark - RecursiveOutlineIterator::RecursiveOutlineIterator(BRowContainer* list, bool openBranchesOnly) : fStackIndex(0), fCurrentListIndex(0), fCurrentListDepth(0), fOpenBranchesOnly(openBranchesOnly) { if (list == 0 || list->CountItems() == 0) fCurrentList = 0; else fCurrentList = list; } BRow* RecursiveOutlineIterator::CurrentRow() const { if (fCurrentList == 0) return 0; return fCurrentList->ItemAt(fCurrentListIndex); } void RecursiveOutlineIterator::GoToNext() { if (fCurrentList == 0) return; if (fCurrentListIndex < 0 || fCurrentListIndex >= fCurrentList->CountItems()) { fCurrentList = 0; return; } BRow* currentRow = fCurrentList->ItemAt(fCurrentListIndex); if(currentRow) { if (currentRow->fChildList && (currentRow->fIsExpanded || !fOpenBranchesOnly) && currentRow->fChildList->CountItems() > 0) { // Visit child. // Put current list on the stack if it needs to be revisited. if (fCurrentListIndex < fCurrentList->CountItems() - 1) { fStack[fStackIndex].fRowSet = fCurrentList; fStack[fStackIndex].fIndex = fCurrentListIndex + 1; fStack[fStackIndex].fDepth = fCurrentListDepth; fStackIndex++; } fCurrentList = currentRow->fChildList; fCurrentListIndex = 0; fCurrentListDepth++; } else if (fCurrentListIndex < fCurrentList->CountItems() - 1) fCurrentListIndex++; // next item in current list else if (--fStackIndex >= 0) { fCurrentList = fStack[fStackIndex].fRowSet; fCurrentListIndex = fStack[fStackIndex].fIndex; fCurrentListDepth = fStack[fStackIndex].fDepth; } else fCurrentList = 0; } } int32 RecursiveOutlineIterator::CurrentLevel() const { return fCurrentListDepth; }
[ "plfiorini@8f1b5804-98cd-0310-9b8b-c217470a4c7c" ]
plfiorini@8f1b5804-98cd-0310-9b8b-c217470a4c7c
a1e7d1781673d8224587d0bc836808e2e55466c0
3e1ac5a6f5473c93fb9d4174ced2e721a7c1ff4c
/build/iOS/Preview/include/Fuse.Internal.CacheRef-2.h
ce5b60c3dcb5b0eac560458bc1ffe1f4669d3f79
[]
no_license
dream-plus/DreamPlus_popup
49d42d313e9cf1c9bd5ffa01a42d4b7c2cf0c929
76bb86b1f2e36a513effbc4bc055efae78331746
refs/heads/master
2020-04-28T20:47:24.361319
2019-05-13T12:04:14
2019-05-13T12:04:14
175,556,703
0
1
null
null
null
null
UTF-8
C++
false
false
1,839
h
// This file was generated based on /usr/local/share/uno/Packages/Fuse.Common/1.9.0/Internal/Cache.uno. // WARNING: Changes might be lost if you edit this file directly. #pragma once #include <Uno.IDisposable.h> #include <Uno.Object.h> namespace g{namespace Fuse{namespace Internal{struct Cache;}}} namespace g{namespace Fuse{namespace Internal{struct CacheRef;}}} namespace g{namespace Uno{namespace Collections{struct LinkedListNode;}}} namespace g{ namespace Fuse{ namespace Internal{ // internal sealed class CacheRef<TKey, TValue> :152 // { struct CacheRef_type : uType { ::g::Uno::IDisposable interface0; }; CacheRef_type* CacheRef_typeof(); void CacheRef__ctor__fn(CacheRef* __this, ::g::Fuse::Internal::Cache* parent, void* key, uObject* value); void CacheRef__Dispose_fn(CacheRef* __this); void CacheRef__New1_fn(uType* __type, ::g::Fuse::Internal::Cache* parent, void* key, uObject* value, CacheRef** __retval); void CacheRef__Release_fn(CacheRef* __this); void CacheRef__Retain_fn(CacheRef* __this); struct CacheRef : uObject { uStrong< ::g::Fuse::Internal::Cache*> _parent; uTField Key() { return __type->Field(this, 1); } uStrong<uObject*> Value; int32_t _refCount; uStrong<uObject*> _refCountMutex; uStrong< ::g::Uno::Collections::LinkedListNode*> _unusedListNode; template<class TKey> void ctor_(::g::Fuse::Internal::Cache* parent, TKey key, uObject* value) { CacheRef__ctor__fn(this, parent, uConstrain(__type->T(0), key), value); } void Dispose(); void Release(); void Retain(); template<class TKey> static CacheRef* New1(uType* __type, ::g::Fuse::Internal::Cache* parent, TKey key, uObject* value) { CacheRef* __retval; return CacheRef__New1_fn(__type, parent, uConstrain(__type->T(0), key), value, &__retval), __retval; } }; // } }}} // ::g::Fuse::Internal
[ "cowodbs156@gmail.com" ]
cowodbs156@gmail.com
18aa0c2584ee9c9addc69129d37c52442bdc8f68
c53bbbdb65378437e05ef1e0de0041684e1797cb
/CONTRIB/LLVM/src/lib/Support/ManagedStatic.cpp
9868207b14ff2733ba7c8ea75b81ec6a98b7abe4
[ "Spencer-94", "BSD-3-Clause", "Apache-2.0" ]
permissive
Maeiky/CpcdosOS2.1-1
b4d087b85f137f44fc34a521ebede3a5fc1d6c59
95910f2fe0cfeda592d6c47d8fa29f380b2b4d08
refs/heads/main
2023-03-26T08:39:40.606756
2021-03-16T05:57:00
2021-03-16T05:57:00
345,801,854
0
0
Apache-2.0
2021-03-08T21:36:06
2021-03-08T21:36:06
null
UTF-8
C++
false
false
2,683
cpp
//===-- ManagedStatic.cpp - Static Global wrapper -------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This file implements the ManagedStatic class and llvm_shutdown(). // //===----------------------------------------------------------------------===// #include "llvm/Support/ManagedStatic.h" #include "llvm/Config/config.h" #include "llvm/Support/Atomic.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Mutex.h" #include "llvm/Support/MutexGuard.h" #include <cassert> using namespace llvm; static const ManagedStaticBase *StaticList = nullptr; static sys::Mutex& getManagedStaticMutex() { // We need to use a function local static here, since this can get called // during a static constructor and we need to guarantee that it's initialized // correctly. static sys::Mutex ManagedStaticMutex; return ManagedStaticMutex; } void ManagedStaticBase::RegisterManagedStatic(void *(*Creator)(), void (*Deleter)(void*)) const { assert(Creator); if (llvm_is_multithreaded()) { MutexGuard Lock(getManagedStaticMutex()); if (!Ptr) { void* tmp = Creator(); TsanHappensBefore(this); sys::MemoryFence(); // This write is racy against the first read in the ManagedStatic // accessors. The race is benign because it does a second read after a // memory fence, at which point it isn't possible to get a partial value. TsanIgnoreWritesBegin(); Ptr = tmp; TsanIgnoreWritesEnd(); DeleterFn = Deleter; // Add to list of managed statics. Next = StaticList; StaticList = this; } } else { assert(!Ptr && !DeleterFn && !Next && "Partially initialized ManagedStatic!?"); Ptr = Creator(); DeleterFn = Deleter; // Add to list of managed statics. Next = StaticList; StaticList = this; } } void ManagedStaticBase::destroy() const { assert(DeleterFn && "ManagedStatic not initialized correctly!"); assert(StaticList == this && "Not destroyed in reverse order of construction?"); // Unlink from list. StaticList = Next; Next = nullptr; // Destroy memory. DeleterFn(Ptr); // Cleanup. Ptr = nullptr; DeleterFn = nullptr; } /// llvm_shutdown - Deallocate and destroy all ManagedStatic variables. void llvm::llvm_shutdown() { MutexGuard Lock(getManagedStaticMutex()); while (StaticList) StaticList->destroy(); }
[ "cpcdososx@gmail.com" ]
cpcdososx@gmail.com
e669675136ccb263e0d7f18eed8ab42d4ec7c9a2
84827d73992a00aa28a6baabf6ff660af55657db
/1.0/code/interface/AndroidQQDecryptSDK.hpp
f32962424645cf052e364569df523b8c951f30ea
[]
no_license
mogeku/mytest
6b167c503330740df7f0127878e3a045539db981
cd3e474aaada674991c4d40761e9be9db77abd2f
refs/heads/main
2023-01-09T23:26:07.936899
2020-11-10T10:24:04
2020-11-10T10:24:04
310,562,755
0
0
null
null
null
null
UTF-8
C++
false
false
1,447
hpp
// The following ifdef block is the standard way of creating macros which make exporting // from a DLL simpler. All files within this DLL are compiled with the ANDROIDQQDECRYPTSDK_EXPORTS // symbol defined on the command line. This symbol should not be defined on any project // that uses this DLL. This way any other project whose source files include this file see // ANDROIDQQDECRYPTSDK_API functions as being imported from a DLL, whereas this DLL sees symbols // defined with this macro as being exported. #ifndef _ANDROIDQQDECRYPTSDK_H #define _ANDROIDQQDECRYPTSDK_H #ifdef _WIN32 #ifdef ANDROIDQQDECRYPTSDK_EXPORTS #define ANDROIDQQDECRYPTSDK_API __declspec(dllexport) #else #define ANDROIDQQDECRYPTSDK_API __declspec(dllimport) #endif #else #ifdef ANDROIDQQDECRYPTSDK_EXPORTS #define ANDROIDQQDECRYPTSDK_API extern "C" __attribute__((visibility ("default"))) #else #define ANDROIDQQDECRYPTSDK_API extern "C" #endif #endif enum PhoneType { HUAWEI = 0, XIAOMI, }; enum QQDecryptErrorType { ERROR_NO, ERROR_INVALID_PARAM = 2000, ERROR_PATH_NOT_EXIST, ERROR_UNKNOW_PHONE_TYPE, ERROR_PATH_NOT_DIR, ERROR_DATABASE_COPY_FAILED, ERROR_GET_TABLE_FIELD_FAILED, ERROR_SEARCH_KEY_FAILED, }; ANDROIDQQDECRYPTSDK_API int InitAndroidQQDecryptSDK(); ANDROIDQQDECRYPTSDK_API int DecryptAndroidQQDB(PhoneType phone_type, const char* backup_folder, const char* decrypted_folder); ANDROIDQQDECRYPTSDK_API void StopAndroidQQDBDecrypt(); #endif
[ "local@email.com" ]
local@email.com
04c0a8bbc1eb6d8a834a02fee0d51bf070fba784
ef3fa8e089c53422db4a5bbff9721268976bae53
/cases/mixerVessel2D/150/uniform/time
08677b802582989a4172a79f1f321292383cac84
[]
no_license
will214/CFDcourse
6b22f00a86f5ac83378e059074eb907e288693f2
37bd665013d77095f85ea4e6bc464caa11f91db1
refs/heads/master
2021-05-09T18:51:12.192394
2016-11-20T10:02:50
2016-11-20T10:02:50
null
0
0
null
null
null
null
UTF-8
C++
false
false
968
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 4.0 | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; location "150/uniform"; object time; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // value 150; name "150"; index 150; deltaT 1; deltaT0 1; // ************************************************************************* //
[ "victormavi_1995@hotmail.com" ]
victormavi_1995@hotmail.com
52211ec7167cbe4534272b0dfe158ab6edae8c5d
89016fcda83d19cf880a3671e7923d69b8cb7c39
/spriterengine/global/settings.h
8ec7bd60521f147648da2e3de563344d2f2c7538
[ "Zlib" ]
permissive
lucidspriter/SpriterPlusPlus
9f83e68cd81295642dd3814ab800cd92967ee6c0
8fb550e1633036b42acd1cce0e05cfe60a3041c0
refs/heads/master
2023-08-10T10:29:03.386422
2021-02-17T22:13:10
2021-02-17T22:13:10
45,448,363
97
55
NOASSERTION
2023-07-23T13:17:31
2015-11-03T07:09:45
C++
UTF-8
C++
false
false
875
h
#ifndef SETTINGS_H #define SETTINGS_H #include <iostream> #include <string> namespace SpriterEngine { typedef void(*ErrorFunctionPointer)(const std::string &errorMessage); class Settings { public: static bool renderDebugBoxes; static bool renderDebugPoints; static bool renderDebugBones; static bool enableDebugBones; static void simpleError(const std::string &errorMessage); static void nullError(const std::string &errorMessage); static void error(const std::string &errorMessage); static void setErrorFunction(ErrorFunctionPointer errorFunction); static void suppressErrorOutput(bool suppress = true); static bool reverseYOnLoad; static bool reversePivotYOnLoad; static bool reverseAngleOnLoad; private: static ErrorFunctionPointer errFunction; static ErrorFunctionPointer previousErrorFunction; }; } #endif // SETTINGS_H
[ "lucid@brashmonkey.com" ]
lucid@brashmonkey.com
45cd2f2228f37422e3a3ad9ffe0f1bfaa4124892
4bad7578931dd47c38dc283aec7eb961be6e1f30
/tests/core_tests/v2_tests.h
76a3b24728e4221a8a750a92818b212e4c9b96fd
[ "BSD-3-Clause", "LicenseRef-scancode-unknown-license-reference" ]
permissive
cyberstormdotmu/electroneum-classic
d034453071a3c9fa37f494c212e3ffc6d0effc9b
494bd2b5f9d9d759c10568e0326dde1737cefad6
refs/heads/master
2020-04-01T06:25:43.262217
2018-10-17T04:16:13
2018-10-17T04:16:13
152,947,188
0
0
null
2018-10-14T06:47:32
2018-10-14T06:47:32
null
UTF-8
C++
false
false
5,069
h
// Copyrights(c) 2018, The Electroneum Classic Project // Copyrights(c) 2017-2018, The Electroneum Project // Copyrights(c) 2014-2017, The Monero Project // // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, are // permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, this list of // conditions and the following disclaimer. // // 2. 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. // // 3. Neither the name of the copyright holder nor the names of its contributors may be // used to endorse or promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 HOLDER 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. // // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #pragma once #include "chaingen.h" struct gen_v2_tx_validation_base : public test_chain_unit_base { gen_v2_tx_validation_base() : m_invalid_tx_index(0) , m_invalid_block_index(0) { REGISTER_CALLBACK_METHOD(gen_v2_tx_validation_base, mark_invalid_tx); REGISTER_CALLBACK_METHOD(gen_v2_tx_validation_base, mark_invalid_block); } bool check_tx_verification_context(const cryptonote::tx_verification_context& tvc, bool tx_added, size_t event_idx, const cryptonote::transaction& /*tx*/) { if (m_invalid_tx_index == event_idx) return tvc.m_verifivation_failed; else return !tvc.m_verifivation_failed && tx_added; } bool check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_idx, const cryptonote::block& /*block*/) { if (m_invalid_block_index == event_idx) return bvc.m_verifivation_failed; else return !bvc.m_verifivation_failed; } bool mark_invalid_block(cryptonote::core& /*c*/, size_t ev_index, const std::vector<test_event_entry>& /*events*/) { m_invalid_block_index = ev_index + 1; return true; } bool mark_invalid_tx(cryptonote::core& /*c*/, size_t ev_index, const std::vector<test_event_entry>& /*events*/) { m_invalid_tx_index = ev_index + 1; return true; } bool generate_with(std::vector<test_event_entry>& events, const int *out_idx, int mixin, uint64_t amount_paid, bool valid) const; private: size_t m_invalid_tx_index; size_t m_invalid_block_index; }; template<> struct get_test_options<gen_v2_tx_validation_base> { const std::pair<uint8_t, uint64_t> hard_forks[3] = {std::make_pair(1, 0), std::make_pair(2, 1), std::make_pair(0, 0)}; const cryptonote::test_options test_options = { hard_forks }; }; struct gen_v2_tx_mixable_0_mixin : public gen_v2_tx_validation_base { bool generate(std::vector<test_event_entry>& events) const; }; template<> struct get_test_options<gen_v2_tx_mixable_0_mixin>: public get_test_options<gen_v2_tx_validation_base> {}; struct gen_v2_tx_mixable_low_mixin : public gen_v2_tx_validation_base { bool generate(std::vector<test_event_entry>& events) const; }; template<> struct get_test_options<gen_v2_tx_mixable_low_mixin>: public get_test_options<gen_v2_tx_validation_base> {}; struct gen_v2_tx_unmixable_only : public gen_v2_tx_validation_base { bool generate(std::vector<test_event_entry>& events) const; }; template<> struct get_test_options<gen_v2_tx_unmixable_only>: public get_test_options<gen_v2_tx_validation_base> {}; struct gen_v2_tx_unmixable_one : public gen_v2_tx_validation_base { bool generate(std::vector<test_event_entry>& events) const; }; template<> struct get_test_options<gen_v2_tx_unmixable_one>: public get_test_options<gen_v2_tx_validation_base> {}; struct gen_v2_tx_unmixable_two : public gen_v2_tx_validation_base { bool generate(std::vector<test_event_entry>& events) const; }; template<> struct get_test_options<gen_v2_tx_unmixable_two>: public get_test_options<gen_v2_tx_validation_base> {}; struct gen_v2_tx_dust : public gen_v2_tx_validation_base { bool generate(std::vector<test_event_entry>& events) const; }; template<> struct get_test_options<gen_v2_tx_dust>: public get_test_options<gen_v2_tx_validation_base> {};
[ "vans_163@yahoo.com" ]
vans_163@yahoo.com
add8c74707964611e16d7c21d04f9d8f8a933f36
bdb9af8381619e483ef1a9e5cbe1c1fc408a0bf9
/tools/grpc/cpp/gobgp_api_client.cc
938b9f0e5a8255ca267f4794853d88313f1afd11
[ "Apache-2.0" ]
permissive
gitter-badger/gobgp
06bc9396cd9f684aedf96e04a67bca2bb93349e8
e41e86f9d1d1d23c90219efd7c93aec7f01510c6
refs/heads/master
2021-01-18T10:33:54.814163
2015-09-03T11:40:55
2015-09-04T05:51:49
41,905,487
0
0
null
2015-09-04T08:31:01
2015-09-04T08:31:01
null
UTF-8
C++
false
false
1,663
cc
#include <iostream> #include <memory> #include <sstream> #include <string> #include <grpc/grpc.h> #include <grpc++/channel.h> #include <grpc++/client_context.h> #include <grpc++/create_channel.h> #include <grpc++/security/credentials.h> #include "gobgp_api_client.grpc.pb.h" using grpc::Channel; using grpc::ClientContext; using grpc::Status; using api::Grpc; class GrpcClient { public: GrpcClient(std::shared_ptr<Channel> channel) : stub_(Grpc::NewStub(channel)) {} std::string GetAllNeighbor(std::string neighbor_ip) { api::Arguments request; request.set_rf(4); request.set_name(neighbor_ip); ClientContext context; api::Peer peer; grpc::Status status = stub_->GetNeighbor(&context, request, &peer); if (status.ok()) { api::PeerConf peer_conf = peer.conf(); api::PeerInfo peer_info = peer.info(); std::stringstream buffer; buffer << "Peer AS: " << peer_conf.remote_as() << "\n" << "Peer router id: " << peer_conf.id() << "\n" << "Peer flops: " << peer_info.flops() << "\n" << "BGP state: " << peer_info.bgp_state(); return buffer.str(); } else { return "Something wrong"; } } private: std::unique_ptr<Grpc::Stub> stub_; }; int main(int argc, char** argv) { GrpcClient gobgp_client(grpc::CreateChannel("localhost:8080", grpc::InsecureCredentials())); std::string reply = gobgp_client.GetAllNeighbor("213.133.111.200"); std::cout << "We received: " << reply << std::endl; return 0; }
[ "fujita.tomonori@lab.ntt.co.jp" ]
fujita.tomonori@lab.ntt.co.jp
c2f76efc3bc25c376acece49eb70ac0c1c618eb2
6e017be8782f3978f2bb235ef2d90dff16409e65
/Dev_class11Brofiler_handout/Motor2D/j1Scene.cpp
5e817ccabb642c29917cd38d847796cde3a4223c
[]
no_license
joseppi/Dev-Class
03fb4c2fde3cbd1628c9a24aca3cdf6646d51507
e12693f6a5e8f1786b33402e589e4498b3dfe124
refs/heads/master
2018-09-27T02:19:03.000505
2018-06-07T10:54:34
2018-06-07T10:54:34
112,933,525
0
0
null
null
null
null
UTF-8
C++
false
false
3,414
cpp
#include "p2Defs.h" #include "p2Log.h" #include "j1App.h" #include "j1Input.h" #include "j1Textures.h" #include "j1Audio.h" #include "j1Render.h" #include "j1Window.h" #include "j1Map.h" #include "j1PathFinding.h" #include "j1Scene.h" j1Scene::j1Scene() : j1Module() { name.create("scene"); } // Destructor j1Scene::~j1Scene() {} // Called before render is available bool j1Scene::Awake() { LOG("Loading Scene"); bool ret = true; return ret; } // Called before the first frame bool j1Scene::Start() { if(App->map->Load("iso_walk.tmx") == true) { int w, h; uchar* data = NULL; if(App->map->CreateWalkabilityMap(w, h, &data)) App->pathfinding->SetMap(w, h, data); RELEASE_ARRAY(data); } debug_tex = App->tex->Load("maps/path2.png"); return true; } // Called each loop iteration bool j1Scene::PreUpdate() { BROFILER_CATEGORY("PreUpdate Scene", Profiler::Color::Yellow); // debug pathfing ------------------ static iPoint origin; static bool origin_selected = false; int x, y; App->input->GetMousePosition(x, y); iPoint p = App->render->ScreenToWorld(x, y); p = App->map->WorldToMap(p.x, p.y); if(App->input->GetMouseButtonDown(SDL_BUTTON_LEFT) == KEY_DOWN) { if(origin_selected == true) { App->pathfinding->CreatePath(origin, p); origin_selected = false; } else { origin = p; origin_selected = true; } } return true; } // Called each loop iteration bool j1Scene::Update(float dt) { BROFILER_CATEGORY("Update Scene", Profiler::Color::Orange); if(App->input->GetKey(SDL_SCANCODE_L) == KEY_DOWN) App->LoadGame("save_game.xml"); if(App->input->GetKey(SDL_SCANCODE_S) == KEY_DOWN) App->SaveGame("save_game.xml"); if(App->input->GetKey(SDL_SCANCODE_UP) == KEY_REPEAT) App->render->camera.y += floor(200.0f * dt); if(App->input->GetKey(SDL_SCANCODE_DOWN) == KEY_REPEAT) App->render->camera.y -= floor(200.0f * dt); if(App->input->GetKey(SDL_SCANCODE_LEFT) == KEY_REPEAT) App->render->camera.x += floor(200.0f * dt); if(App->input->GetKey(SDL_SCANCODE_RIGHT) == KEY_REPEAT) App->render->camera.x -= floor(200.0f * dt); App->map->Draw(); int x, y; App->input->GetMousePosition(x, y); iPoint map_coordinates = App->map->WorldToMap(x - App->render->camera.x, y - App->render->camera.y); p2SString title("Map:%dx%d Tiles:%dx%d Tilesets:%d Tile:%d,%d", App->map->data.width, App->map->data.height, App->map->data.tile_width, App->map->data.tile_height, App->map->data.tilesets.count(), map_coordinates.x, map_coordinates.y); //App->win->SetTitle(title.GetString()); // Debug pathfinding ------------------------------ //int x, y; App->input->GetMousePosition(x, y); iPoint p = App->render->ScreenToWorld(x, y); p = App->map->WorldToMap(p.x, p.y); p = App->map->MapToWorld(p.x, p.y); App->render->Blit(debug_tex, p.x, p.y); const p2DynArray<iPoint>* path = App->pathfinding->GetLastPath(); for(uint i = 0; i < path->Count(); ++i) { iPoint pos = App->map->MapToWorld(path->At(i)->x, path->At(i)->y); App->render->Blit(debug_tex, pos.x, pos.y); } return true; } // Called each loop iteration bool j1Scene::PostUpdate() { BROFILER_CATEGORY("PostUpdate Scene", Profiler::Color::MistyRose); bool ret = true; if(App->input->GetKey(SDL_SCANCODE_ESCAPE) == KEY_DOWN) ret = false; return ret; } // Called before quitting bool j1Scene::CleanUp() { LOG("Freeing scene"); return true; }
[ "josep.pi.serra@gmail.com" ]
josep.pi.serra@gmail.com
e4897687d6455ae0e5b051345063725b9547303a
6a69d57c782e0b1b993e876ad4ca2927a5f2e863
/vendor/samsung/common/packages/apps/SBrowser/src/ui/views/controls/button/image_button.h
5d71ec42fc17647aaf9f23a6f205679f35e69d53
[ "BSD-3-Clause" ]
permissive
duki994/G900H-Platform-XXU1BOA7
c8411ef51f5f01defa96b3381f15ea741aa5bce2
4f9307e6ef21893c9a791c96a500dfad36e3b202
refs/heads/master
2020-05-16T20:57:07.585212
2015-05-11T11:03:16
2015-05-11T11:03:16
35,418,464
2
1
null
null
null
null
UTF-8
C++
false
false
5,566
h
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ #define UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ #include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" #include "ui/base/layout.h" #include "ui/gfx/image/image_skia.h" #include "ui/views/controls/button/custom_button.h" namespace views { class Painter; // An image button. // Note that this type of button is not focusable by default and will not be // part of the focus chain. Call SetFocusable(true) to make it part of the // focus chain. class VIEWS_EXPORT ImageButton : public CustomButton { public: static const char kViewClassName[]; enum HorizontalAlignment { ALIGN_LEFT = 0, ALIGN_CENTER, ALIGN_RIGHT }; enum VerticalAlignment { ALIGN_TOP = 0, ALIGN_MIDDLE, ALIGN_BOTTOM }; explicit ImageButton(ButtonListener* listener); virtual ~ImageButton(); // Returns the image for a given |state|. virtual const gfx::ImageSkia& GetImage(ButtonState state) const; // Set the image the button should use for the provided state. virtual void SetImage(ButtonState state, const gfx::ImageSkia* image); // Set the background details. void SetBackground(SkColor color, const gfx::ImageSkia* image, const gfx::ImageSkia* mask); // Sets how the image is laid out within the button's bounds. void SetImageAlignment(HorizontalAlignment h_align, VerticalAlignment v_align); void SetFocusPainter(scoped_ptr<Painter> focus_painter); // Sets preferred size, so it could be correctly positioned in layout even if // it is NULL. void SetPreferredSize(const gfx::Size& preferred_size) { preferred_size_ = preferred_size; } // Whether we should draw our images resources horizontally flipped. void SetDrawImageMirrored(bool mirrored) { draw_image_mirrored_ = mirrored; } // Overridden from View: virtual gfx::Size GetPreferredSize() OVERRIDE; virtual const char* GetClassName() const OVERRIDE; virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; protected: // Overridden from View: virtual void OnFocus() OVERRIDE; virtual void OnBlur() OVERRIDE; // Returns the image to paint. This is invoked from paint and returns a value // from images. virtual gfx::ImageSkia GetImageToPaint(); // Updates button background for |scale_factor|. void UpdateButtonBackground(ui::ScaleFactor scale_factor); Painter* focus_painter() { return focus_painter_.get(); } // The images used to render the different states of this button. gfx::ImageSkia images_[STATE_COUNT]; gfx::ImageSkia background_image_; private: FRIEND_TEST_ALL_PREFIXES(ImageButtonTest, Basics); FRIEND_TEST_ALL_PREFIXES(ImageButtonTest, ImagePositionWithBorder); FRIEND_TEST_ALL_PREFIXES(ImageButtonTest, LeftAlignedMirrored); FRIEND_TEST_ALL_PREFIXES(ImageButtonTest, RightAlignedMirrored); // Returns the correct position of the image for painting. gfx::Point ComputeImagePaintPosition(const gfx::ImageSkia& image); // Image alignment. HorizontalAlignment h_alignment_; VerticalAlignment v_alignment_; gfx::Size preferred_size_; // Whether we draw our resources horizontally flipped. This can happen in the // linux titlebar, where image resources were designed to be flipped so a // small curved corner in the close button designed to fit into the frame // resources. bool draw_image_mirrored_; scoped_ptr<Painter> focus_painter_; DISALLOW_COPY_AND_ASSIGN(ImageButton); }; //////////////////////////////////////////////////////////////////////////////// // // ToggleImageButton // // A toggle-able ImageButton. It swaps out its graphics when toggled. // //////////////////////////////////////////////////////////////////////////////// class VIEWS_EXPORT ToggleImageButton : public ImageButton { public: explicit ToggleImageButton(ButtonListener* listener); virtual ~ToggleImageButton(); // Change the toggled state. void SetToggled(bool toggled); // Like ImageButton::SetImage(), but to set the graphics used for the // "has been toggled" state. Must be called for each button state // before the button is toggled. void SetToggledImage(ButtonState state, const gfx::ImageSkia* image); // Set the tooltip text displayed when the button is toggled. void SetToggledTooltipText(const base::string16& tooltip); // Overridden from ImageButton: virtual const gfx::ImageSkia& GetImage(ButtonState state) const OVERRIDE; virtual void SetImage(ButtonState state, const gfx::ImageSkia* image) OVERRIDE; // Overridden from View: virtual bool GetTooltipText(const gfx::Point& p, base::string16* tooltip) const OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; private: // The parent class's images_ member is used for the current images, // and this array is used to hold the alternative images. // We swap between the two when toggling. gfx::ImageSkia alternate_images_[STATE_COUNT]; // True if the button is currently toggled. bool toggled_; // The parent class's tooltip_text_ is displayed when not toggled, and // this one is shown when toggled. base::string16 toggled_tooltip_text_; DISALLOW_COPY_AND_ASSIGN(ToggleImageButton); }; } // namespace views #endif // UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_
[ "duki994@gmail.com" ]
duki994@gmail.com
1b9c983f3a69410d0321641d8935ff4d1dc11745
9f35bea3c50668a4205c04373da95195e20e5427
/ash/assistant/assistant_web_ui_controller.cc
fe627906dc6b3ccfbc67192a73cdb36f74bc4a0b
[ "BSD-3-Clause" ]
permissive
foolcodemonkey/chromium
5958fb37df91f92235fa8cf2a6e4a834c88f44aa
c155654fdaeda578cebc218d47f036debd4d634f
refs/heads/master
2023-02-21T00:56:13.446660
2020-01-07T05:12:51
2020-01-07T05:12:51
232,250,603
1
0
BSD-3-Clause
2020-01-07T05:38:18
2020-01-07T05:38:18
null
UTF-8
C++
false
false
4,976
cc
// Copyright 2019 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ash/assistant/assistant_web_ui_controller.h" #include "ash/assistant/assistant_controller.h" #include "ash/assistant/ui/assistant_web_container_view.h" #include "ash/assistant/util/deep_link_util.h" #include "ash/multi_user/multi_user_window_manager_impl.h" #include "ash/session/session_controller_impl.h" #include "ash/shell.h" #include "chromeos/services/assistant/public/features.h" #include "ui/aura/client/aura_constants.h" #include "ui/events/event_observer.h" #include "ui/views/event_monitor.h" namespace ash { // ----------------------------------------------------------------------------- // AssistantWebContainerEventObserver: class AssistantWebContainerEventObserver : public ui::EventObserver { public: AssistantWebContainerEventObserver(AssistantWebUiController* owner, views::Widget* widget) : owner_(owner), widget_(widget), event_monitor_( views::EventMonitor::CreateWindowMonitor(this, widget->GetNativeWindow(), {ui::ET_KEY_PRESSED})) {} ~AssistantWebContainerEventObserver() override = default; // ui::EventObserver: void OnEvent(const ui::Event& event) override { DCHECK(event.type() == ui::ET_KEY_PRESSED); const ui::KeyEvent& key_event = static_cast<const ui::KeyEvent&>(event); switch (key_event.key_code()) { case ui::VKEY_BROWSER_BACK: owner_->OnBackButtonPressed(); break; case ui::VKEY_W: if (!key_event.IsControlDown()) break; event_monitor_.reset(); widget_->Close(); break; default: // No action necessary. break; } } private: AssistantWebUiController* owner_ = nullptr; views::Widget* widget_ = nullptr; std::unique_ptr<views::EventMonitor> event_monitor_; DISALLOW_COPY_AND_ASSIGN(AssistantWebContainerEventObserver); }; // ----------------------------------------------------------------------------- // AssistantWebUiController: AssistantWebUiController::AssistantWebUiController( AssistantController* assistant_controller) : assistant_controller_(assistant_controller) { DCHECK(chromeos::assistant::features::IsAssistantWebContainerEnabled()); assistant_controller_->AddObserver(this); } AssistantWebUiController::~AssistantWebUiController() { assistant_controller_->RemoveObserver(this); } void AssistantWebUiController::OnWidgetDestroying(views::Widget* widget) { ResetWebContainerView(); } void AssistantWebUiController::OnAssistantControllerDestroying() { if (!web_container_view_) return; // The view should not outlive the controller. web_container_view_->GetWidget()->CloseNow(); DCHECK_EQ(nullptr, web_container_view_); } void AssistantWebUiController::OnDeepLinkReceived( assistant::util::DeepLinkType type, const std::map<std::string, std::string>& params) { if (!assistant::util::IsWebDeepLinkType(type, params)) return; ShowUi(); // Open the url associated w/ the deep link. web_container_view_->OpenUrl( assistant::util::GetWebUrl(type, params).value()); } void AssistantWebUiController::ShowUi() { if (!web_container_view_) CreateWebContainerView(); web_container_view_->GetWidget()->Show(); } void AssistantWebUiController::OnBackButtonPressed() { DCHECK(web_container_view_); web_container_view_->OnBackButtonPressed(); } AssistantWebContainerView* AssistantWebUiController::GetViewForTest() { return web_container_view_; } void AssistantWebUiController::CreateWebContainerView() { DCHECK(!web_container_view_); web_container_view_ = new AssistantWebContainerView( assistant_controller_->view_delegate(), &view_delegate_); auto* widget = web_container_view_->GetWidget(); widget->AddObserver(this); event_observer_ = std::make_unique<AssistantWebContainerEventObserver>(this, widget); // Associate the window for Assistant Web UI with the active user in order to // not leak across user sessions. auto* window_manager = MultiUserWindowManagerImpl::Get(); if (!window_manager) return; const UserSession* active_user_session = Shell::Get()->session_controller()->GetUserSession(0); if (!active_user_session) return; auto* native_window = widget->GetNativeWindow(); native_window->SetProperty(aura::client::kCreatedByUserGesture, true); window_manager->SetWindowOwner(native_window, active_user_session->user_info.account_id); } void AssistantWebUiController::ResetWebContainerView() { DCHECK(web_container_view_); event_observer_.reset(); web_container_view_->GetWidget()->RemoveObserver(this); web_container_view_ = nullptr; } } // namespace ash
[ "commit-bot@chromium.org" ]
commit-bot@chromium.org
817a1e920ec10374737864a4c0d8602b44fbd624
180492f944459ac416476603f601407e9c4c6988
/NeoGUI/Connector.h
22cd1e1666b232c92f43f28a216f95e01cce6149
[]
no_license
bratao/NeoLoader
3a05068f104fa82c853a3ccf8bcc079c5a61a527
7885abdb71dc98ef1b45273faaad699eda82c57b
refs/heads/master
2021-01-15T08:48:06.483422
2015-04-02T18:04:54
2015-04-02T18:04:54
35,004,681
0
1
null
2015-05-03T23:33:38
2015-05-03T23:33:38
null
UTF-8
C++
false
false
1,321
h
#pragma once #if QT_VERSION < 0x050000 #include <QtGui> #else #include <QWidget> #include <QHBoxLayout> #include <QTreeWidget> #include <QFormLayout> #include <QLineEdit> #include <QCheckBox> #include <QPushButton> #include <QSplitter> #include <QHeaderView> #include <QApplication> #include <QMessageBox> #include <QInputDialog> #include <QCloseEvent> #include <QComboBox> #include <QStackedLayout> #include <QDialogButtonBox> #endif #include "Common/Dialog.h" class CConnector : public QDialogEx { Q_OBJECT public: CConnector(QWidget *pMainWindow = 0); ~CConnector(); private slots: void OnModeChanged(int Index); void OnConnect(); void OnClicked(QAbstractButton* pButton); protected: void timerEvent(QTimerEvent *e); void closeEvent(QCloseEvent *e); void Load(); void Apply(); int m_uTimerID; int m_Mode; private: QFormLayout* m_pMainLayout; QLabel* m_pLabel; QComboBox* m_pMode; QLineEdit* m_pPassword; QLineEdit* m_pPipeName; QLineEdit* m_pHostPort; QLineEdit* m_pHostName; QComboBox* m_pAutoConnect; /*QPushButton* m_pServiceBtn; QLineEdit* m_pServiceName;*/ //QPushButton* m_pStartBtn; QPushButton* m_pConnectBtn; QDialogButtonBox* m_pButtonBox; };
[ "xanatosdavid@gmail.com" ]
xanatosdavid@gmail.com
5f05584b9468a039ee59c83807d43557e34b3ef6
aab5af1da9e52c9f49d8d063868da0a0a929f085
/inputValidation.hpp
2c576fae9aaa325a3f63b64ed2fc76604494c480
[]
no_license
mcopland/home-invasion
47a1fb470f574aea3a4683e93598d7d2b7ef8907
3dcf1a8b27a367caab4a0483e3faf08d3f3715ce
refs/heads/master
2021-08-19T20:22:06.448986
2020-07-24T22:56:26
2020-07-24T22:56:26
207,384,800
0
0
null
null
null
null
UTF-8
C++
false
false
812
hpp
/******************************************************************************* ** Program: homeInvasion ** File: inputValidation.hpp ** ----------------------------------------------------------------------------- ** This is the inputValidation class specification (header) file. There are ** functions to validate yes or no questions, ints, floats, and strings for use ** throughout the program. *******************************************************************************/ #ifndef INPUTVALIDATION_HPP #define INPUTVALIDATION_HPP #include <ios> // <streamsize> #include <iostream> #include <limits> // numeric_limits #include <string> bool getYesNo(std::string); float getValidFloat(std::string prompt); int getValidInt(int min, int max); long getValidLong(long min, long max); #endif
[ "mcopland@users.noreply.github.com" ]
mcopland@users.noreply.github.com
d51bcc14984b55b544b69af2d5810dca24ea36b3
c13fe33b9ccf0e6857388405ef791071aa753c0f
/mythread.cpp
295791a01ac4914d0dc8b0d6985e7d231a317443
[]
no_license
Cirnoo/game-server
8b1c8b1fdff4b92c42812e2de2ff5d825abed675
b4970692fd980240e58543454f127c1713a8e2ae
refs/heads/master
2020-04-01T22:55:29.567920
2018-11-17T16:35:27
2018-11-17T16:35:27
153,732,972
0
0
null
null
null
null
UTF-8
C++
false
false
266
cpp
#include "mythread.h" #include <QTcpSocket> #include <QMetaType> MyThread::MyThread() { qRegisterMetaType<DATA_PACKAGE>("DATA_PACKAGE"); } void MyThread::Reply(QTcpSocket * socket, const DATA_PACKAGE &pack) { socket->write((char *)&pack,sizeof (pack)); }
[ "42065449+Cirno0@users.noreply.github.com" ]
42065449+Cirno0@users.noreply.github.com
c7bf8ef392302de54ca6cd1ea6bedeb80926ab4f
0e4f37b4dd9754203ea3cfe61d24c4db900ff1b1
/ch14 Augmenting Data Structures/IntervalTree_test.cpp
9728fc8e42671df24ef0a2ea77172bb11fceb1dc
[]
no_license
HongfeiXu/LearnCLRS
1c8eacb6ed7396c061e00444629224c8f5c07116
403a6da7ea89ac61642557b013df48de7ab04909
refs/heads/master
2021-01-10T23:01:48.120537
2018-04-11T14:21:58
2018-04-11T14:21:58
70,452,998
2
0
null
null
null
null
WINDOWS-1252
C++
false
false
4,168
cpp
/*************************************************************************** * @file IntervalTree_test.cpp * @author Alex.Xu * @mail icevmj@gmail.com * @date 7.6 2017 * @remark Test the functionality of IntervalTree template * @platform visual studio 2013, windows 10 ***************************************************************************/ #include <iostream> #include <string> #include <vector> #include <ctime> #include "myUtility.h" // RandomizeInPlace() #include "IntervalTree.h" using ch14_2::IntervalTree; // overload operator<<, so we can use OutputVec to print the infomation of *pNode std::ostream& ch14_2::operator<< (std::ostream &os, const IntervalTree<int, std::string>::IntervalNode * pNode) { os << "key: "<<pNode->key << " interval: (" << pNode->interval.first << "," << pNode->interval.second << ")" << " value: " << pNode->value << " max:" << pNode->max; return os; } void ch14_2::IntervalTree_test() { std::srand(unsigned(time(0))); IntervalTree<int, std::string> intervalTree; std::vector<IntervalTree<int, std::string>::IntervalNode *> ptr_vec(8); ptr_vec[0] = new IntervalTree<int, std::string>::IntervalNode(std::make_pair(0,3), "Cat"); ptr_vec[1] = new IntervalTree<int, std::string>::IntervalNode(std::make_pair(5,8), "Razor"); ptr_vec[2] = new IntervalTree<int, std::string>::IntervalNode(std::make_pair(6,10), "Grass"); ptr_vec[3] = new IntervalTree<int, std::string>::IntervalNode(std::make_pair(8,9), "Sun"); ptr_vec[4] = new IntervalTree<int, std::string>::IntervalNode(std::make_pair(15,23), "Apple"); ptr_vec[5] = new IntervalTree<int, std::string>::IntervalNode(std::make_pair(16,21), "Dog"); ptr_vec[6] = new IntervalTree<int, std::string>::IntervalNode(std::make_pair(17,19), "Knife"); ptr_vec[7] = new IntervalTree<int, std::string>::IntervalNode(std::make_pair(25,30), "Shark"); std::cout << "Initial nodes:" << std::endl; OutputVec(ptr_vec, std::cout, '\n'); //RandomizeInPlace(ptr_vec); //std::cout << "After Randomized:" << std::endl; //OutputVec(ptr_vec, std::cout, ' '); for (auto &item : ptr_vec) intervalTree.insert(item); std::cout << "inorderTreeWalk:" << std::endl; intervalTree.inorderTreeWalk(std::cout); std::cout << "Tree: "; intervalTree.printTree(std::cout); std::cout << std::endl; std::cout << "deleteNodeHasKey 8" << std::endl; // if there are many nodes have key 8, only delete the node inseted firstly. intervalTree.deleteNodeHasKey(8); std::cout << "inorderTreeWalk:" << std::endl; intervalTree.inorderTreeWalk(std::cout); std::cout << "Tree: "; intervalTree.printTree(std::cout); std::cout << std::endl; // test intervalSearch std::pair<int, int> interval_a(8, 9); IntervalTree<int, std::string>::IntervalNode * pInterval_a = intervalTree.intervalSearch(interval_a); std::cout << pInterval_a << std::endl; return; } /* Initial nodes: key: 0 interval: (0,3) value: Cat max:0 key: 5 interval: (5,8) value: Razor max:0 key: 6 interval: (6,10) value: Grass max:0 key: 8 interval: (8,9) value: Sun max:0 key: 15 interval: (15,23) value: Apple max:0 key: 16 interval: (16,21) value: Dog max:0 key: 17 interval: (17,19) value: Knife max:0 key: 25 interval: (25,30) value: Shark max:0 inorderTreeWalk: key: 0 interval: (0,3) value:Cat max:3 BLACK key: 5 interval: (5,8) value:Razor max:10 RED key: 6 interval: (6,10) value:Grass max:10 BLACK key: 8 interval: (8,9) value:Sun max:30 BLACK key: 15 interval: (15,23) value:Apple max:23 BLACK key: 16 interval: (16,21) value:Dog max:30 RED key: 17 interval: (17,19) value:Knife max:30 BLACK key: 25 interval: (25,30) value:Shark max:30 RED Tree: 8(5(0,6),16(15,17(,25))) deleteNodeHasKey 8 inorderTreeWalk: key: 0 interval: (0,3) value:Cat max:3 BLACK key: 5 interval: (5,8) value:Razor max:10 RED key: 6 interval: (6,10) value:Grass max:10 BLACK key: 15 interval: (15,23) value:Apple max:30 BLACK key: 16 interval: (16,21) value:Dog max:21 BLACK key: 17 interval: (17,19) value:Knife max:30 RED key: 25 interval: (25,30) value:Shark max:30 BLACK Tree: 15(5(0,6),17(16,25)) key: 5 interval: (5,8) value: Razor max:10 ร‡รซยฐยดรˆรŽร’รขยผรผยผรŒรรธ. . . */
[ "icevmj@gmail.com" ]
icevmj@gmail.com
3ba0853664f970541666c81e085fecaf601f430b
92e67b30497ffd29d3400e88aa553bbd12518fe9
/assignment2/part6/Re=110/12.5/p
d4fc3a93bef16e746100e42729eab6138aa9df9f
[]
no_license
henryrossiter/OpenFOAM
8b89de8feb4d4c7f9ad4894b2ef550508792ce5c
c54b80dbf0548b34760b4fdc0dc4fb2facfdf657
refs/heads/master
2022-11-18T10:05:15.963117
2020-06-28T15:24:54
2020-06-28T15:24:54
241,991,470
0
0
null
null
null
null
UTF-8
C++
false
false
20,094
/*--------------------------------*- C++ -*----------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Version: 7 \\/ M anipulation | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class volScalarField; location "12.5"; object p; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [0 2 -2 0 0 0 0]; internalField nonuniform List<scalar> 2000 ( 0.0336571 0.0371535 0.0392559 0.0423602 0.0471211 0.0536115 0.0613989 0.0698262 0.0782675 0.0864584 0.0358873 0.0388906 0.0405405 0.0428691 0.0465651 0.0518905 0.0586208 0.0662324 0.0741274 0.081996 0.0380545 0.0405732 0.0418639 0.0436037 0.0464481 0.0507575 0.0564719 0.0632125 0.0704536 0.0778572 0.0401796 0.0422155 0.0432207 0.0445336 0.0467381 0.0502168 0.0550157 0.0608839 0.0673933 0.0741893 0.0422827 0.0438356 0.0446188 0.0456453 0.0474101 0.0502633 0.0542974 0.0593534 0.0651029 0.0711649 0.0443778 0.0454534 0.0460772 0.0469428 0.0484514 0.0508874 0.054341 0.0587036 0.0637223 0.0689475 0.0464626 0.0470806 0.0476143 0.0484365 0.0498554 0.0520729 0.0551457 0.0589813 0.0633577 0.067674 0.0485079 0.0487079 0.049231 0.050124 0.0516045 0.0537867 0.0566782 0.0601864 0.0640715 0.0674729 0.0504478 0.0502984 0.0508954 0.0519696 0.0536494 0.0559603 0.0588568 0.0622529 0.0658713 0.0684593 0.0521848 0.0517796 0.0525322 0.0538881 0.055887 0.05847 0.0615358 0.0650125 0.0686674 0.071024 0.102475 0.119266 0.12978 0.136949 0.141881 0.145656 0.148066 0.14997 0.150817 0.151394 0.0981505 0.115546 0.126175 0.133442 0.138452 0.142323 0.14482 0.146802 0.147715 0.148326 0.093966 0.11191 0.12258 0.129979 0.135071 0.139035 0.141626 0.143683 0.14466 0.145306 0.0900863 0.108394 0.119018 0.126582 0.131754 0.135803 0.13849 0.140615 0.141654 0.142333 0.0867567 0.105062 0.11554 0.123282 0.128511 0.132641 0.135425 0.137605 0.138693 0.139396 0.0841683 0.101872 0.112158 0.120085 0.125342 0.129553 0.132431 0.13466 0.135784 0.136504 0.082529 0.0988789 0.108997 0.117029 0.122269 0.12656 0.129526 0.131783 0.132915 0.133628 0.0816756 0.0958257 0.106013 0.114059 0.119271 0.123641 0.126696 0.128985 0.130122 0.130819 0.0818428 0.0931341 0.103458 0.11125 0.116422 0.120855 0.12398 0.126247 0.127325 0.127957 0.081204 0.0900802 0.100817 0.108415 0.113607 0.118071 0.121305 0.123618 0.124704 0.125294 0.0880799 0.0882393 0.0963484 0.102529 0.107663 0.11206 0.115159 0.116966 0.117576 0.11784 0.0934872 0.0900745 0.0932539 0.0959844 0.0991109 0.102062 0.104675 0.107106 0.108873 0.11018 0.0893516 0.0879193 0.0886617 0.0897362 0.0919035 0.0942553 0.0960687 0.0976025 0.0992483 0.100456 0.0777365 0.0792725 0.0805242 0.0817366 0.0837039 0.0859021 0.0878906 0.0892818 0.0904838 0.0912534 0.0644466 0.067514 0.0701096 0.0729688 0.0757247 0.0776252 0.0788837 0.0799796 0.0809222 0.0816657 0.051789 0.0558134 0.0589013 0.0622624 0.0656382 0.0684135 0.0699977 0.0708977 0.0716024 0.0722231 0.0396444 0.0439021 0.0475513 0.0513756 0.0548612 0.0575058 0.059226 0.0601554 0.0606346 0.0609164 0.0273512 0.0313155 0.0349643 0.0388246 0.0424141 0.0450174 0.0467391 0.0477848 0.0483339 0.048494 0.0154132 0.018652 0.0217215 0.0247125 0.0276147 0.0298842 0.0312459 0.0319474 0.0323583 0.0325851 0.00183696 0.0050897 0.00738762 0.00893608 0.0103858 0.0117441 0.012634 0.0130189 0.0131798 0.0133455 0.0843276 0.0915544 0.0838786 0.0709122 0.0581221 0.0461572 0.0355604 0.0240848 0.0138562 -0.000395019 0.0865209 0.0909065 0.0810793 0.0674802 0.0550259 0.0435477 0.0335159 0.0224968 0.0132226 -0.00104594 0.0901766 0.0885424 0.0772084 0.0637726 0.0519408 0.0410628 0.0316126 0.0211321 0.0126236 -0.0015789 0.090247 0.0848998 0.0728734 0.0600008 0.0488491 0.0386104 0.0297166 0.0198377 0.0120058 -0.00204909 0.0882009 0.0806198 0.0682583 0.0561714 0.0457722 0.0362085 0.0278659 0.0186463 0.0114016 -0.00240599 0.0841519 0.0758339 0.0635566 0.0523467 0.0427271 0.0338553 0.0260607 0.0175355 0.0108281 -0.00262483 0.0787659 0.0706502 0.0589181 0.0485862 0.0397326 0.03156 0.024317 0.0164932 0.0103211 -0.00221157 0.0728036 0.0652584 0.0544297 0.0449512 0.0368222 0.0293432 0.0226546 0.0155074 0.00982747 -0.0011522 0.0668588 0.0599154 0.0501522 0.0414933 0.0340393 0.0272359 0.0211008 0.0145883 0.00927552 -0.000118582 0.061332 0.0548686 0.0461377 0.0382502 0.0314288 0.0252716 0.0196837 0.0137782 0.00874941 0.000691593 0.056451 0.0502951 0.0424272 0.0352451 0.0290252 0.0234767 0.0184222 0.0130742 0.00828965 0.0012666 0.0523093 0.0463121 0.0390745 0.0325092 0.0268598 0.0218789 0.0173281 0.0124706 0.00790292 0.00164257 0.0489329 0.0429914 0.0361533 0.0300844 0.024967 0.0205177 0.0164108 0.011967 0.00758317 0.00186954 0.0463046 0.0403532 0.0337063 0.0279871 0.0233924 0.0194021 0.0156761 0.0115667 0.00732469 0.00199788 0.0443635 0.0383594 0.0317315 0.0262242 0.0221813 0.0185156 0.0151189 0.0112668 0.00712387 0.00206839 0.0429797 0.0369106 0.0302166 0.0250443 0.0210922 0.0178536 0.0147135 0.0110602 0.00697557 0.00210837 0.042021 0.0359653 0.0292543 0.0241301 0.0203318 0.0173974 0.0144082 0.0109233 0.00687163 0.00213254 0.0416464 0.0357439 0.0287416 0.0235521 0.0198504 0.0171311 0.0144396 0.0108417 0.0067908 0.00214792 0.0419665 0.0362089 0.0287906 0.0233027 0.0195838 0.0170278 0.014318 0.0108346 0.00674086 0.00215711 0.0409157 0.0362595 0.0292371 0.0235409 0.0196249 0.0171156 0.0143659 0.0109072 0.00671734 0.00215772 0.0334824 0.0337366 0.0310385 0.0264585 0.0217318 0.0176373 0.0143573 0.0107542 0.00667122 0.00222248 0.0400106 0.0291663 0.0241423 0.0214017 0.0187371 0.0162378 0.0135477 0.0101349 0.00615463 0.00200819 0.0456421 0.0385194 0.0318254 0.0268918 0.0218773 0.0179488 0.0142155 0.0104233 0.00627801 0.0021052 0.0466911 0.0384841 0.0315056 0.0264787 0.0217831 0.0179994 0.0142499 0.0103611 0.00638668 0.00228505 0.0498632 0.0417067 0.0345754 0.0286883 0.023456 0.0192765 0.0148588 0.0107558 0.00674677 0.00263593 0.0514653 0.043245 0.0361149 0.0301938 0.0248517 0.0201232 0.0153182 0.0112013 0.00725154 0.0031231 0.0538637 0.0453388 0.0378019 0.0315653 0.0260287 0.0208241 0.0159045 0.0117291 0.00772473 0.00352554 0.0557301 0.0469051 0.0394652 0.0331208 0.0271073 0.0214962 0.0164813 0.0120519 0.00824154 0.00404371 0.0570426 0.0491176 0.0414282 0.0343568 0.0279692 0.0222616 0.0169618 0.0125309 0.00899702 0.00443462 0.0584549 0.0498685 0.0421047 0.0350093 0.0285291 0.0226686 0.0173088 0.0128851 0.00899911 0.00401291 0.0527937 0.0550946 0.0533767 0.0533573 0.0559014 0.0572778 0.0598625 0.0625936 0.0626517 0.0649764 0.055999 0.0589275 0.0564133 0.0564531 0.0587291 0.0599881 0.0629168 0.0658986 0.0666657 0.0688284 0.059239 0.0599587 0.0580381 0.0592917 0.0616217 0.063068 0.0665103 0.0697703 0.0722921 0.074394 0.0623579 0.061253 0.0594632 0.0617608 0.0642986 0.0661892 0.0700096 0.0735443 0.0773569 0.0797805 0.0652556 0.0632564 0.0614972 0.0642561 0.0669228 0.0693167 0.0733749 0.077097 0.0814609 0.0843096 0.0680299 0.0653714 0.0639904 0.0669888 0.069715 0.072551 0.076774 0.0806103 0.0850501 0.0881748 0.0707661 0.0673681 0.0665657 0.069883 0.0727543 0.0759685 0.0803299 0.084281 0.0886604 0.0918803 0.0735381 0.0693586 0.0690857 0.0728266 0.0760124 0.0795769 0.0840738 0.0881933 0.0925857 0.0958233 0.0764294 0.0714532 0.0715967 0.0758059 0.0794513 0.0833441 0.0879918 0.0923386 0.0968812 0.100161 0.0795185 0.073691 0.0741586 0.0788658 0.083064 0.0872301 0.0920678 0.096672 0.101482 0.104867 0.0828251 0.0760863 0.0767983 0.0820445 0.0868629 0.0911993 0.0963003 0.101157 0.106318 0.109855 0.0863758 0.0786703 0.0795473 0.0853442 0.0908436 0.0952287 0.100687 0.105782 0.111353 0.115054 0.0904584 0.0815157 0.0824797 0.0887202 0.0949679 0.0993228 0.105228 0.11059 0.11659 0.120449 0.0952317 0.0846884 0.0857022 0.0921001 0.0991796 0.103493 0.109913 0.115637 0.122028 0.126043 0.100543 0.088224 0.0892685 0.0954845 0.103414 0.107769 0.114823 0.120923 0.127687 0.131874 0.106274 0.0921574 0.0931652 0.0989422 0.107567 0.112276 0.119876 0.126356 0.133535 0.137941 0.112267 0.096493 0.097297 0.102595 0.111531 0.117124 0.125038 0.131936 0.139608 0.144288 0.118335 0.101181 0.101502 0.106466 0.115454 0.121931 0.130138 0.137548 0.145822 0.150878 0.124735 0.106451 0.105568 0.110648 0.119421 0.126715 0.135253 0.143316 0.152252 0.157763 0.130868 0.112148 0.109453 0.114447 0.122937 0.130936 0.139902 0.148785 0.158609 0.16485 0.140925 0.130528 0.123957 0.126918 0.133784 0.142825 0.152815 0.163665 0.175197 0.182872 0.155336 0.1502 0.146998 0.149657 0.156516 0.166633 0.178702 0.192526 0.206815 0.216659 0.174466 0.173684 0.173162 0.176989 0.184731 0.195927 0.210018 0.226866 0.24384 0.255173 0.192446 0.195918 0.200061 0.206559 0.216688 0.230253 0.247012 0.267024 0.286456 0.298364 0.208487 0.215156 0.223167 0.233731 0.2476 0.264836 0.284922 0.30787 0.329343 0.342234 0.22182 0.230828 0.242025 0.256186 0.273764 0.294843 0.318184 0.34313 0.365772 0.37863 0.231545 0.242482 0.255999 0.272707 0.292833 0.316559 0.342121 0.367744 0.390353 0.403359 0.239312 0.251304 0.266374 0.284939 0.306775 0.33198 0.358788 0.384441 0.40562 0.415317 0.241933 0.255038 0.271383 0.291353 0.314277 0.340543 0.368336 0.393607 0.412704 0.423049 0.246286 0.259849 0.27674 0.297201 0.321215 0.348334 0.376807 0.404597 0.425994 0.41907 0.148046 0.158852 0.174511 0.190106 0.204723 0.21704 0.226059 0.233373 0.235587 0.239507 0.151787 0.163008 0.177435 0.191468 0.204909 0.216247 0.224543 0.231321 0.233242 0.237043 0.155311 0.167851 0.181731 0.194544 0.206574 0.216545 0.223792 0.229675 0.231315 0.23481 0.157488 0.17053 0.184092 0.196311 0.207438 0.216445 0.222908 0.228056 0.229558 0.232564 0.159162 0.172074 0.185168 0.196943 0.207471 0.215844 0.221791 0.226417 0.227859 0.230357 0.160701 0.173481 0.186034 0.19729 0.207248 0.21509 0.220626 0.224835 0.226229 0.228294 0.161974 0.174799 0.186925 0.19767 0.207052 0.214384 0.219535 0.223365 0.224704 0.226422 0.162904 0.175854 0.187695 0.198019 0.20688 0.213743 0.218535 0.222016 0.223304 0.224737 0.163549 0.176634 0.188273 0.19826 0.206677 0.213135 0.21761 0.220779 0.222029 0.22321 0.163999 0.177213 0.188697 0.198399 0.206437 0.212552 0.216752 0.219646 0.220881 0.22181 0.164327 0.177648 0.189017 0.198469 0.206182 0.212002 0.215966 0.21862 0.219829 0.220545 0.164527 0.177927 0.189246 0.198486 0.205923 0.211495 0.215255 0.217703 0.218865 0.219405 0.164542 0.178012 0.189371 0.198446 0.205667 0.211033 0.214619 0.216886 0.217996 0.218381 0.164352 0.177911 0.189401 0.198355 0.205417 0.210615 0.214055 0.21616 0.217224 0.217468 0.163971 0.177667 0.189348 0.198221 0.205179 0.210244 0.21356 0.21552 0.216538 0.216667 0.163366 0.177314 0.189207 0.198054 0.204954 0.209916 0.213135 0.214961 0.215918 0.215977 0.162517 0.17691 0.188969 0.197864 0.20474 0.209632 0.212776 0.214478 0.215353 0.215419 0.161189 0.176419 0.18859 0.197648 0.204528 0.209388 0.212477 0.214062 0.214799 0.214992 0.159531 0.175968 0.188148 0.197418 0.204327 0.209185 0.212236 0.213722 0.214299 0.214747 0.156783 0.174914 0.18738 0.197009 0.204052 0.208971 0.212022 0.213412 0.213686 0.214643 0.152032 0.17298 0.186058 0.19638 0.203707 0.208741 0.211862 0.213364 0.213374 0.214846 0.163079 0.179191 0.189938 0.199192 0.205442 0.209755 0.212285 0.213574 0.21363 0.214689 0.172008 0.185262 0.194699 0.202531 0.207618 0.211058 0.212835 0.213762 0.213838 0.214403 0.177798 0.189382 0.198214 0.204838 0.20912 0.211811 0.213043 0.213832 0.214356 0.215084 0.181838 0.192326 0.200511 0.206046 0.209575 0.211582 0.212554 0.213666 0.215314 0.217939 0.184818 0.194453 0.201809 0.206193 0.20875 0.210191 0.211328 0.213678 0.218462 0.226327 0.186652 0.195778 0.202035 0.204762 0.205682 0.206539 0.208487 0.213878 0.225564 0.245641 0.188407 0.196945 0.202088 0.203194 0.202922 0.20362 0.206902 0.218649 0.244923 0.291643 0.188642 0.196267 0.198773 0.196879 0.195219 0.196675 0.206679 0.230845 0.283963 0.378324 0.191894 0.201963 0.206783 0.206146 0.206538 0.215619 0.236485 0.280382 0.370486 0.521657 0.140175 0.151835 0.160889 0.167931 0.17289 0.177025 0.179153 0.18137 0.181781 0.184088 0.136668 0.148702 0.157709 0.164798 0.169772 0.174062 0.176149 0.17844 0.178835 0.180753 0.134709 0.14713 0.156169 0.162892 0.167518 0.171505 0.173392 0.175553 0.175891 0.177416 0.131781 0.144659 0.153777 0.160619 0.165035 0.16877 0.170541 0.172559 0.17287 0.174062 0.128154 0.141398 0.150635 0.157597 0.162121 0.165741 0.167498 0.169436 0.169762 0.170711 0.124261 0.137905 0.147286 0.154236 0.158928 0.162534 0.164327 0.166229 0.166604 0.167389 0.120159 0.134333 0.143909 0.150843 0.155568 0.159264 0.161098 0.162984 0.163428 0.164106 0.115846 0.130652 0.140472 0.147439 0.152173 0.155849 0.157903 0.159721 0.160254 0.160865 0.111392 0.126872 0.136953 0.143982 0.148762 0.152424 0.154635 0.156466 0.157088 0.157666 0.1069 0.123052 0.133377 0.140474 0.145328 0.149026 0.151344 0.153196 0.153948 0.154509 0.0535983 0.0530518 0.0540261 0.0557394 0.0581488 0.0611195 0.0644988 0.0682317 0.0724173 0.0767082 0.0545626 0.0540029 0.0552367 0.0573419 0.0602036 0.0636118 0.0673456 0.0712488 0.0752227 0.0790386 0.0549652 0.0545358 0.0560351 0.0585126 0.0618068 0.06563 0.0696933 0.0737387 0.0774127 0.0803967 0.0547451 0.0545976 0.0563428 0.0591282 0.062778 0.0669117 0.0711954 0.0752921 0.0787258 0.0808042 0.0539047 0.0541955 0.0561612 0.0591559 0.0630631 0.0673211 0.0716267 0.075576 0.0787357 0.0801852 0.0525024 0.0533893 0.055567 0.0587336 0.0626583 0.0668815 0.0709883 0.0745692 0.0773254 0.0784462 0.050628 0.0522649 0.0546535 0.0579117 0.0617542 0.0657417 0.0694446 0.0724917 0.0746859 0.075605 0.0483754 0.0509018 0.0535063 0.0567959 0.0604551 0.0640552 0.0672065 0.069624 0.0711804 0.0718327 0.0458386 0.0493367 0.0521632 0.0554381 0.0588357 0.0619557 0.0644874 0.0662475 0.0671964 0.067464 0.0430698 0.0475835 0.0506222 0.0538543 0.056959 0.0595807 0.0615092 0.062658 0.0630845 0.0629152 0.0401066 0.0456208 0.0488628 0.0520656 0.054913 0.0570957 0.0585059 0.0591448 0.0591441 0.0585699 0.0370298 0.0435013 0.0469544 0.0501819 0.0528564 0.0547045 0.0557092 0.0559508 0.055603 0.0546944 0.0339356 0.0412611 0.0449811 0.0483406 0.050963 0.0525981 0.0533081 0.0532459 0.0526068 0.0514316 0.0309649 0.0389943 0.043107 0.0467373 0.0494276 0.0509535 0.0514519 0.0511431 0.0502379 0.0488418 0.0282979 0.0368583 0.0415479 0.0455824 0.048427 0.049908 0.0502413 0.04971 0.0485417 0.046943 0.0261336 0.0350677 0.0405321 0.045067 0.0481019 0.0495554 0.049731 0.0489741 0.0475339 0.0457189 0.0246707 0.0338764 0.0402702 0.0453447 0.048558 0.0499596 0.0499439 0.0489169 0.047153 0.0450466 0.0240981 0.0335438 0.0409333 0.046525 0.0498752 0.0511887 0.0509329 0.0495364 0.0472648 0.044623 0.0245893 0.0342928 0.0426401 0.048666 0.0521011 0.053324 0.0528484 0.0510375 0.048036 0.0444016 0.0262965 0.036283 0.0454471 0.0517629 0.055215 0.0563797 0.05583 0.0538417 0.0503756 0.0461895 0.029366 0.0396092 0.0493532 0.0557528 0.0591056 0.0601902 0.0596778 0.057939 0.0552141 0.0528206 0.0339901 0.044314 0.054316 0.0605391 0.0636184 0.0644892 0.0638739 0.0622191 0.0600402 0.0583526 0.0401675 0.0503296 0.0602543 0.0660067 0.0686213 0.0691307 0.0682743 0.0665291 0.0644104 0.0626345 0.0478621 0.057572 0.0670529 0.0720446 0.0739939 0.073982 0.0727414 0.0707412 0.0684276 0.0663697 0.056988 0.0659775 0.0745227 0.0785306 0.0796415 0.0789689 0.0772206 0.0748349 0.0721978 0.0698155 0.0674361 0.0752866 0.0825454 0.0853581 0.0854925 0.0840518 0.0817063 0.078857 0.0758421 0.0731258 0.0790119 0.0852371 0.0909834 0.092437 0.0914963 0.089217 0.086219 0.0828638 0.079447 0.0763956 0.0913589 0.09568 0.0996933 0.0996831 0.0976153 0.0944665 0.0907972 0.086927 0.0831076 0.0797223 0.104151 0.10639 0.108526 0.107012 0.103814 0.0998059 0.0954821 0.0911199 0.0869237 0.0832129 0.116985 0.117097 0.117323 0.114332 0.11005 0.105233 0.100306 0.0955058 0.0909851 0.0869676 0.129392 0.127516 0.125919 0.121544 0.116271 0.110732 0.105284 0.100124 0.0953492 0.0910476 0.141291 0.13745 0.134147 0.128529 0.122397 0.116258 0.110399 0.104979 0.100028 0.0954678 0.152317 0.146653 0.141846 0.135175 0.128351 0.121758 0.115622 0.110061 0.105029 0.100277 0.162133 0.154891 0.148844 0.141351 0.134027 0.127148 0.120879 0.115315 0.110341 0.105522 0.170444 0.161947 0.154976 0.14692 0.139307 0.132319 0.126074 0.120649 0.115876 0.111147 0.176996 0.167628 0.160087 0.151748 0.144068 0.137154 0.131087 0.125943 0.121522 0.116952 0.181582 0.171772 0.164041 0.155712 0.148189 0.141531 0.135792 0.131057 0.127085 0.122812 0.184054 0.174258 0.16673 0.158706 0.151566 0.14534 0.140071 0.135863 0.132459 0.12857 0.184329 0.175008 0.168078 0.160651 0.15411 0.148491 0.14382 0.140222 0.137488 0.134156 0.182392 0.173999 0.168048 0.161496 0.155753 0.150891 0.146918 0.143939 0.141953 0.139696 0.178295 0.171254 0.166641 0.161229 0.156482 0.152557 0.149484 0.147292 0.146128 0.146159 0.172119 0.166836 0.163888 0.159841 0.156226 0.153295 0.151097 0.149575 0.14886 0.149379 0.164085 0.160881 0.159867 0.157371 0.154994 0.153098 0.151787 0.15098 0.15072 0.151497 0.154469 0.153575 0.154706 0.153913 0.152873 0.152069 0.151686 0.151684 0.152041 0.153125 0.143588 0.145143 0.148568 0.149604 0.149989 0.150336 0.150917 0.151764 0.152843 0.154367 0.131791 0.135841 0.141648 0.144604 0.146485 0.148032 0.149606 0.151313 0.153145 0.15521 0.11944 0.125943 0.134144 0.139077 0.142503 0.145287 0.147871 0.150434 0.153009 0.155645 0.106898 0.115715 0.126252 0.133177 0.138175 0.142212 0.14581 0.149217 0.152511 0.155712 0.0945084 0.105402 0.118152 0.127043 0.133611 0.1389 0.143505 0.147735 0.151721 0.155478 0.0826032 0.0952033 0.109995 0.120787 0.128902 0.135425 0.141016 0.146045 0.150694 0.155 0.0716211 0.0853103 0.101923 0.114496 0.12411 0.131836 0.138386 0.144185 0.149466 0.154314 0.0614461 0.0757757 0.0940392 0.108251 0.119299 0.128178 0.135648 0.142181 0.148056 0.153425 0.052154 0.0670045 0.0863852 0.102111 0.114509 0.124473 0.132815 0.140042 0.146468 0.152324 0.0439064 0.0590152 0.0790965 0.0961353 0.109752 0.12072 0.129881 0.137763 0.144695 0.150995 0.0367859 0.0518076 0.0722793 0.0903451 0.105026 0.116913 0.126833 0.135331 0.142731 0.149412 0.0308175 0.0454626 0.0659545 0.0847521 0.100317 0.113035 0.12364 0.132716 0.140572 0.147514 0.025991 0.0400424 0.0601482 0.0793704 0.0956335 0.109052 0.120265 0.12986 0.138208 0.14523 0.0222685 0.0355695 0.0548983 0.0742157 0.090971 0.104954 0.116683 0.126697 0.135329 0.142862 0.019591 0.0320383 0.0502404 0.0693101 0.0863254 0.100724 0.11287 0.123252 0.132141 0.139935 0.0178846 0.0294208 0.0462041 0.0646862 0.081711 0.0963611 0.108809 0.119507 0.128663 0.136374 0.0170579 0.0276665 0.0428114 0.0603842 0.0771565 0.0918753 0.104465 0.115277 0.124574 0.131823 0.0169587 0.0266821 0.0400685 0.0564486 0.0727036 0.0873041 0.0999058 0.110678 0.119931 0.127447 0.017533 0.0263983 0.0379793 0.0529295 0.0684151 0.0827248 0.0952766 0.106066 0.115393 0.123336 0.0186819 0.026718 0.036529 0.0498757 0.0643644 0.0782182 0.090659 0.10151 0.110971 0.119178 0.020284 0.0275289 0.0356833 0.0473259 0.0606177 0.073839 0.0860566 0.0969145 0.106468 0.114831 0.0222204 0.0287191 0.0353857 0.0452996 0.0572296 0.0696327 0.0814768 0.0922365 0.101814 0.110292 0.0243813 0.0301838 0.0355604 0.0437955 0.0542499 0.0656592 0.0769689 0.0875151 0.097047 0.105597 0.0266704 0.0318287 0.0361193 0.0427933 0.0517235 0.0619933 0.0726109 0.0828215 0.0922285 0.100794 0.0290092 0.0335713 0.0369704 0.0422536 0.0496845 0.0587158 0.0684966 0.0782413 0.0874317 0.095948 0.0313461 0.0353534 0.038031 0.0421219 0.0481455 0.0558969 0.064722 0.07387 0.0827421 0.0911391 ) ; boundaryField { inlet { type zeroGradient; } outlet { type fixedValue; value uniform 0; } cylinder { type zeroGradient; } top { type symmetryPlane; } bottom { type symmetryPlane; } defaultFaces { type empty; } } // ************************************************************************* //
[ "henry.rossiter@utexas.edu" ]
henry.rossiter@utexas.edu
92a0f299fe1f364e129d42f4650b39e87b29f4c7
8f7c8beaa2fca1907fb4796538ea77b4ecddc300
/chrome/installer/zucchini/disassembler_win32.h
0241257c082d0c9e63373019cbaa047822399929
[ "BSD-3-Clause" ]
permissive
lgsvl/chromium-src
8f88f6ae2066d5f81fa363f1d80433ec826e3474
5a6b4051e48b069d3eacbfad56eda3ea55526aee
refs/heads/ozone-wayland-62.0.3202.94
2023-03-14T10:58:30.213573
2017-10-26T19:27:03
2017-11-17T09:42:56
108,161,483
8
4
null
2017-12-19T22:53:32
2017-10-24T17:34:08
null
UTF-8
C++
false
false
3,832
h
// Copyright 2017 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_INSTALLER_ZUCCHINI_DISASSEMBLER_WIN32_H_ #define CHROME_INSTALLER_ZUCCHINI_DISASSEMBLER_WIN32_H_ #include <stddef.h> #include <stdint.h> #include <memory> #include <string> #include <utility> #include <vector> #include "base/macros.h" #include "chrome/installer/zucchini/address_translator.h" #include "chrome/installer/zucchini/buffer_view.h" #include "chrome/installer/zucchini/disassembler.h" #include "chrome/installer/zucchini/image_utils.h" #include "chrome/installer/zucchini/type_win_pe.h" namespace zucchini { class Rel32FinderX86; class Rel32FinderX64; struct Win32X86Traits { static constexpr ExecutableType kExeType = kExeTypeWin32X86; enum : uint16_t { kMagic = 0x10B }; enum : uint16_t { kRelocType = 3 }; enum : offset_t { kVAWidth = 4 }; static const char kExeTypeString[]; using ImageOptionalHeader = pe::ImageOptionalHeader; using RelFinder = Rel32FinderX86; using Address = uint32_t; }; struct Win32X64Traits { static constexpr ExecutableType kExeType = kExeTypeWin32X64; enum : uint16_t { kMagic = 0x20B }; enum : uint16_t { kRelocType = 10 }; enum : offset_t { kVAWidth = 8 }; static const char kExeTypeString[]; using ImageOptionalHeader = pe::ImageOptionalHeader64; using RelFinder = Rel32FinderX64; using Address = uint64_t; }; template <class Traits> class DisassemblerWin32 : public Disassembler { public: enum ReferenceType : uint8_t { kRel32, kTypeCount }; // Applies quick checks to determine whether |image| *may* point to the start // of an executable. Returns true iff the check passes. static bool QuickDetect(ConstBufferView image); // Main instantiator and initializer. static std::unique_ptr<DisassemblerWin32> Make(ConstBufferView image); DisassemblerWin32(); ~DisassemblerWin32() override; // Disassembler: ExecutableType GetExeType() const override; std::string GetExeTypeString() const override; std::vector<ReferenceGroup> MakeReferenceGroups() const override; // Functions that return reader / writer for references. std::unique_ptr<ReferenceReader> MakeReadRel32(offset_t lower, offset_t upper); std::unique_ptr<ReferenceWriter> MakeWriteRel32(MutableBufferView image); private: // Disassembler: bool Parse(ConstBufferView image) override; // Parses the file header. Returns true iff successful. bool ParseHeader(); // Parsers to extract references. These are lazily called, and return whether // parsing was successful (failures are non-fatal). bool ParseAndStoreRel32(); // PE-specific translation utilities. rva_t AddressToRva(typename Traits::Address address) const; typename Traits::Address RvaToAddress(rva_t rva) const; // In-memory copy of sections. std::vector<pe::ImageSectionHeader> sections_; // Image base address to translate between RVA and VA. typename Traits::Address image_base_ = 0; // Translator between offsets and RVAs. AddressTranslator translator_; // Reference storage. std::vector<offset_t> rel32_locations_; // Initialization states of reference storage, used for lazy initialization. // TODO(huangs): Investigate whether lazy initialization is useful for memory // reduction. This is a carryover from Courgette. To be sure we should run // experiment after Zucchini is able to do ensemble patching. bool has_parsed_rel32_ = false; DISALLOW_COPY_AND_ASSIGN(DisassemblerWin32); }; using DisassemblerWin32X86 = DisassemblerWin32<Win32X86Traits>; using DisassemblerWin32X64 = DisassemblerWin32<Win32X64Traits>; } // namespace zucchini #endif // CHROME_INSTALLER_ZUCCHINI_DISASSEMBLER_WIN32_H_
[ "commit-bot@chromium.org" ]
commit-bot@chromium.org
84ae28000560b6103020accf566949083b972462
9aaa39f200ee6a14d7d432ef6a3ee9795163ebed
/Algorithm/C++/009. Palindrome Number.cpp
1061308f3faa138c3eb9b5a655dc81263f8c010c
[]
no_license
WuLC/LeetCode
47e1c351852d86c64595a083e7818ecde4131cb3
ee79d3437cf47b26a4bca0ec798dc54d7b623453
refs/heads/master
2023-07-07T18:29:29.110931
2023-07-02T04:31:00
2023-07-02T04:31:00
54,354,616
29
16
null
null
null
null
UTF-8
C++
false
false
928
cpp
/* * Created on Thu Apr 19 2018 14:41:13 * Author: WuLC * EMail: liangchaowu5@gmail.com */ // method 1, convert number to string class Solution { public: bool isPalindrome(int x) { string s = std::to_string(x); int left = 0, right = s.length()-1; while(left < right) { if (s[left] != s[right]) return false; left++; right--; } return true; } }; // method 2,no need to convert number to string // follow the method of reversing a number class Solution { public: bool isPalindrome(int x) { if (x<0 || (x>0 && x%10==0)) return false; int sum = 0; while(x>sum) { sum = sum*10+x%10; x/=10; } return x==sum || x==sum/10; } };
[ "liangchaowu5@gmail.com" ]
liangchaowu5@gmail.com
35a37ab15b20f5c99aa417b860e2e1a79f98b9c3
ec68c973b7cd3821dd70ed6787497a0f808e18e1
/Cpp/SDK/BP_RandomMapActor_classes.h
0ae829b86b9867a57c06c1a26ae73215a86770a4
[]
no_license
Hengle/zRemnant-SDK
05be5801567a8cf67e8b03c50010f590d4e2599d
be2d99fb54f44a09ca52abc5f898e665964a24cb
refs/heads/main
2023-07-16T04:44:43.113226
2021-08-27T14:26:40
2021-08-27T14:26:40
null
0
0
null
null
null
null
UTF-8
C++
false
false
783
h
๏ปฟ#pragma once // Name: Remnant, Version: 1.0 /*!!DEFINE!!*/ /*!!HELPER_DEF!!*/ /*!!HELPER_INC!!*/ #ifdef _MSC_VER #pragma pack(push, 0x01) #endif namespace CG { //--------------------------------------------------------------------------- // Classes //--------------------------------------------------------------------------- // BlueprintGeneratedClass BP_RandomMapActor.BP_RandomMapActor_C // 0x0000 class ABP_RandomMapActor_C : public AActor { public: static UClass* StaticClass() { static auto ptr = UObject::FindClass("BlueprintGeneratedClass BP_RandomMapActor.BP_RandomMapActor_C"); return ptr; } void Init(); void ReceiveBeginPlay(); void SetRandomSeed(); void ExecuteUbergraph_BP_RandomMapActor(); }; } #ifdef _MSC_VER #pragma pack(pop) #endif
[ "zp2kshield@gmail.com" ]
zp2kshield@gmail.com
eddd44313e6274eeb0acac7ff02b8121405143a2
b34cd2fb7a9e361fe1deb0170e3df323ec33259f
/Applications/ChiaMarketDataFeedClient/Include/ChiaMarketDataFeedClient/ChiaMdProtocolClient.hpp
79e338cd94ddcf9fa10332d3f5e997b550d703bf
[]
no_license
lineCode/nexus
c4479879dba1fbd11573c129f15b7b3c2156463e
aea7e2cbcf96a113f58eed947138b76e09b8fccb
refs/heads/master
2022-04-19T01:10:22.139995
2020-04-16T23:07:23
2020-04-16T23:07:23
null
0
0
null
null
null
null
UTF-8
C++
false
false
8,468
hpp
#ifndef NEXUS_CHIAMDPROTOCOLCLIENT_HPP #define NEXUS_CHIAMDPROTOCOLCLIENT_HPP #include <string> #include <Beam/IO/NotConnectedException.hpp> #include <Beam/IO/OpenState.hpp> #include <Beam/Pointers/Dereference.hpp> #include <Beam/Pointers/LocalPtr.hpp> #include <boost/noncopyable.hpp> #include <boost/throw_exception.hpp> #include "ChiaMarketDataFeedClient/ChiaMessage.hpp" namespace Nexus { namespace MarketDataService { /*! \class ChiaMdProtocolClient \brief Parses packets from the CHIA market data feed. \tparam ChannelType The type of Channel receiving data. */ template<typename ChannelType> class ChiaMdProtocolClient : private boost::noncopyable { public: //! The type of Channel receiving data. using Channel = Beam::GetTryDereferenceType<ChannelType>; //! Constructs a ChiaMdProtocolClient. /*! \param channel Initializes the Channel receiving data. \param username The username. \param password The password. */ template<typename ChannelForward> ChiaMdProtocolClient(ChannelForward&& channel, std::string username, std::string password); //! Constructs a ChiaMdProtocolClient. /*! \param channel Initializes the Channel receiving data. \param username The username. \param password The password. \param session The session ID. \param sequence The sequence of the next expected message. */ template<typename ChannelForward> ChiaMdProtocolClient(ChannelForward&& channel, std::string username, std::string password, std::string session, std::uint32_t sequence); ~ChiaMdProtocolClient(); //! Reads the next message. ChiaMessage Read(); //! Reads the next message. /*! \param sequenceNumber The message's sequence number. */ ChiaMessage Read(Beam::Out<std::uint32_t> sequenceNumber); //! Reads the next message. /*! \param sequenceNumber The message's sequence number. */ Beam::IO::SharedBuffer ReadBuffer( Beam::Out<std::uint32_t> sequenceNumber); void Open(); void Close(); private: Beam::GetOptionalLocalPtr<ChannelType> m_channel; std::string m_username; std::string m_password; std::string m_session; std::uint32_t m_sequence; std::uint32_t m_nextSequence; Beam::IO::SharedBuffer m_message; Beam::IO::SharedBuffer m_buffer; Beam::IO::OpenState m_openState; void Shutdown(); Beam::IO::SharedBuffer ReadBuffer(); void Append(const std::string& value, int size, Beam::Out<Beam::IO::SharedBuffer> buffer); void Append(int value, int size, Beam::Out<Beam::IO::SharedBuffer> buffer); void Append(std::uint32_t value, int size, Beam::Out<Beam::IO::SharedBuffer> buffer); }; template<typename ChannelType> template<typename ChannelForward> ChiaMdProtocolClient<ChannelType>::ChiaMdProtocolClient( ChannelForward&& channel, std::string username, std::string password) : ChiaMdProtocolClient{std::forward<ChannelForward>(channel), std::move(username), std::move(password), "", 0} {} template<typename ChannelType> template<typename ChannelForward> ChiaMdProtocolClient<ChannelType>::ChiaMdProtocolClient( ChannelForward&& channel, std::string username, std::string password, std::string session, std::uint32_t sequence) : m_channel{std::forward<ChannelForward>(channel)}, m_username{std::move(username)}, m_password{std::move(password)}, m_session{std::move(session)}, m_sequence{sequence} {} template<typename ChannelType> ChiaMdProtocolClient<ChannelType>::~ChiaMdProtocolClient() { Close(); } template<typename ChannelType> ChiaMessage ChiaMdProtocolClient<ChannelType>::Read() { std::uint32_t sequence; return Read(Beam::Store(sequence)); } template<typename ChannelType> ChiaMessage ChiaMdProtocolClient<ChannelType>::Read( Beam::Out<std::uint32_t> sequenceNumber) { while(true) { m_message = ReadBuffer(); if(!m_message.IsEmpty() && m_message.GetData()[0] == 'S') { auto message = ChiaMessage::Parse(m_message.GetData() + 1, m_message.GetSize() - 2); *sequenceNumber = m_nextSequence; ++m_nextSequence; return message; } } } template<typename ChannelType> Beam::IO::SharedBuffer ChiaMdProtocolClient<ChannelType>::ReadBuffer( Beam::Out<std::uint32_t> sequenceNumber) { while(true) { auto buffer = ReadBuffer(); if(!buffer.IsEmpty() && buffer.GetData()[0] == 'S') { buffer.ShrinkFront(1); buffer.Shrink(2); *sequenceNumber = m_nextSequence; ++m_nextSequence; return buffer; } } } template<typename ChannelType> void ChiaMdProtocolClient<ChannelType>::Open() { const auto USERNAME_LENGTH = 6; const auto PASSWORD_LENGTH = 10; const auto SESSION_LENGTH = 10; const auto SEQUENCE_OFFSET = 11; const auto SEQUENCE_LENGTH = 10; if(m_openState.SetOpening()) { return; } try { m_channel->GetConnection().Open(); Beam::IO::SharedBuffer loginBuffer; Append("L", 1, Beam::Store(loginBuffer)); Append(m_username, USERNAME_LENGTH, Beam::Store(loginBuffer)); Append(m_password, PASSWORD_LENGTH, Beam::Store(loginBuffer)); Append(m_session, SESSION_LENGTH, Beam::Store(loginBuffer)); Append(m_sequence, SEQUENCE_LENGTH, Beam::Store(loginBuffer)); loginBuffer.Append('\x0A'); m_channel->GetWriter().Write(loginBuffer); auto response = ReadBuffer(); if(response.GetSize() < SEQUENCE_OFFSET + SEQUENCE_LENGTH || response.GetData()[0] != 'A') { BOOST_THROW_EXCEPTION(Beam::IO::ConnectException{"Invalid response."}); } auto cursor = &(response.GetData()[SEQUENCE_OFFSET]); m_nextSequence = static_cast<std::uint32_t>(ChiaMessage::ParseNumeric( SEQUENCE_LENGTH, Beam::Store(cursor))); } catch(const std::exception&) { m_openState.SetOpenFailure(); Shutdown(); } m_openState.SetOpen(); } template<typename ChannelType> void ChiaMdProtocolClient<ChannelType>::Close() { if(m_openState.SetClosing()) { return; } Shutdown(); } template<typename ChannelType> void ChiaMdProtocolClient<ChannelType>::Shutdown() { m_channel->GetConnection().Close(); m_openState.SetClosed(); } template<typename ChannelType> Beam::IO::SharedBuffer ChiaMdProtocolClient<ChannelType>::ReadBuffer() { const auto READ_SIZE = 1024; while(true) { auto delimiter = std::find(m_buffer.GetData(), m_buffer.GetData() + m_buffer.GetSize(), '\x0A'); if(delimiter == m_buffer.GetData() + m_buffer.GetSize()) { m_channel->GetReader().Read(Beam::Store(m_buffer), READ_SIZE); } else if(delimiter == m_buffer.GetData() + m_buffer.GetSize()) { auto buffer = std::move(m_buffer); m_buffer.Reset(); return buffer; } else { auto size = delimiter - m_buffer.GetData(); Beam::IO::SharedBuffer buffer{m_buffer.GetData(), static_cast<std::size_t>(size)}; m_buffer.ShrinkFront(size + 1); return buffer; } } } template<typename ChannelType> void ChiaMdProtocolClient<ChannelType>::Append(const std::string& value, int size, Beam::Out<Beam::IO::SharedBuffer> buffer) { buffer->Append(value.c_str(), value.size()); for(int i = 0; i < size - static_cast<int>(value.size()); ++i) { buffer->Append(' '); } } template<typename ChannelType> void ChiaMdProtocolClient<ChannelType>::Append(int value, int size, Beam::Out<Beam::IO::SharedBuffer> buffer) { auto stringValue = std::to_string(value); for(int i = 0; i < size - static_cast<int>(stringValue.size()); ++i) { buffer->Append(' '); } buffer->Append(stringValue.c_str(), stringValue.size()); } template<typename ChannelType> void ChiaMdProtocolClient<ChannelType>::Append(std::uint32_t value, int size, Beam::Out<Beam::IO::SharedBuffer> buffer) { auto stringValue = std::to_string(value); for(int i = 0; i < size - static_cast<int>(stringValue.size()); ++i) { buffer->Append(' '); } buffer->Append(stringValue.c_str(), stringValue.size()); } } } #endif
[ "kamal@eidolonsystems.com" ]
kamal@eidolonsystems.com
ba075a5618803e90bb72c0c15f910c2bf2e61c85
ccfbf5a9ee9c00282c200945bbe36b387eb38b19
/UVA Solutions/uva 674.cpp
10a42902b8480662d2d5e0567e6f904a72b67b95
[]
no_license
sakiib/OnlineJudge-Solutions
e070d4b255d036cdefaf087e9f75b69db708406c
b024352aa99efe548b48ef74c492cb69c1fa89f9
refs/heads/master
2023-01-07T20:57:04.259395
2020-11-16T08:41:27
2020-11-16T08:41:27
288,191,980
0
0
null
null
null
null
UTF-8
C++
false
false
644
cpp
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int Coin[] = {1, 5, 10, 20, 25}; int dp[7][7493]; int makeCoin(int I, int H){ if(I >= 5){ if(!H)return 1; else return 0; } if(dp[I][H] != -1)return dp[I][H]; int Way1 = 0, Way2 = 0; if(H-Coin[I] >= 0)Way1 = makeCoin(I, H-Coin[I]); Way2 = makeCoin(I+1, H); cout << Way1 << " " << Way2 << " I = " << I << " H = " << H << endl; return dp[I][H] = Way1+Way2; } int main(){ int N; memset(dp, -1, sizeof(dp)); while(cin >> N){ cout << makeCoin(0, N) << endl; } return 0; }
[ "sakibalamin162@gmail.com" ]
sakibalamin162@gmail.com
bc8a31f28ed687ebbb33bd15d10d3f3373154da8
f40a9ea8fcc5cf34e132181aed9076978161dc45
/mba/cpp/include/readers/common.h
7eaa467bc5160e02751dcd431d6960fa25ca85ca
[]
no_license
azeroman/Livingstone-2
7cb7373e58457ab09f979a966eed2ae043285dee
c422a8264900860ff6255c676e254004766486ec
refs/heads/master
2022-04-12T20:35:36.050943
2020-04-08T14:58:50
2020-04-08T14:58:50
null
0
0
null
null
null
null
UTF-8
C++
false
false
1,727
h
/*** *** See the file "mba/disclaimers-and-notices-L2.txt" for *** information on usage and redistribution of this file, *** and for a DISCLAIMER OF ALL WARRANTIES. ***/ /* $Id: common.h,v 1.17 2004/02/18 23:50:16 lbrown Exp $ */ #ifndef COMMON_H #define COMMON_H #define L2_READER_MAGIC "L211" #include <livingstone/L2_assert.h> /** * Return array[i], checking that i < size. * The template ensures we can't use this as an l-value. * Gcc-3.0 requires both templates in order to work with either * passing in T const * const * or T**. */ template <class T> const T *bounds_check_access(unsigned i, unsigned size, const T *const * array, const char *name) { L2_assert(i<size, L2_bounds_error, (MBA_string(name)+" array", i, size)); return array[i]; } template <class T> const T *bounds_check_access(unsigned i, unsigned size, T *const * array, const char *name) { L2_assert(i<size, L2_bounds_error, (MBA_string(name)+" array", i, size)); return array[i]; } /** * Similarly, except array is only T**, and return is T* * We don't need to worry about the consts. */ template <class T> T *bounds_check_access_friend(unsigned i, unsigned size, T ** array, const char *name) { L2_assert(i<size, L2_bounds_error, (MBA_string(name)+" array", i, size)); return array[i]; } /*************************************************************************** Several of the methods only need to be virtual if we have the debug versions of the objects. ***************************************************************************/ #ifdef ENABLE_L2_DEBUG_SECTIONS # define l2_virtual virtual #else # define l2_virtual #endif #endif
[ "kbshah1998@outlook.com" ]
kbshah1998@outlook.com
899cf420ecb8531f47b155a42fef0df93aed0d9e
9a488a219a4f73086dc704c163d0c4b23aabfc1f
/tags/Release-0_9_15/src/FbTk/Button.cc
e2ba7b5e5a7c1a0b19c8caeebffe40df17382548
[ "LicenseRef-scancode-unknown-license-reference", "MIT" ]
permissive
BackupTheBerlios/fluxbox-svn
47b8844b562f56d02b211fd4323c2a761b473d5b
3ac62418ccf8ffaddbf3c181f28d2f652543f83f
refs/heads/master
2016-09-05T14:55:27.249504
2007-12-14T23:27:57
2007-12-14T23:27:57
40,667,038
0
0
null
null
null
null
UTF-8
C++
false
false
4,356
cc
// Button.cc for FbTk - fluxbox toolkit // Copyright (c) 2002 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org) // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // $Id$ #include "Button.hh" #include "Command.hh" #include "EventManager.hh" #include "App.hh" namespace FbTk { Button::Button(int screen_num, int x, int y, unsigned int width, unsigned int height): FbWindow(screen_num, x, y, width, height, ExposureMask | ButtonPressMask | ButtonReleaseMask), m_background_pm(0), m_pressed_pm(0), m_pressed_color(), m_gc(DefaultGC(FbTk::App::instance()->display(), screen_num)), m_pressed(false) { // add this to eventmanager FbTk::EventManager::instance()->add(*this, *this); } Button::Button(const FbWindow &parent, int x, int y, unsigned int width, unsigned int height): FbWindow(parent, x, y, width, height, ExposureMask | ButtonPressMask | ButtonReleaseMask), m_background_pm(0), m_pressed_pm(0), m_pressed_color(), m_gc(DefaultGC(FbTk::App::instance()->display(), screenNumber())), m_pressed(false) { // add this to eventmanager FbTk::EventManager::instance()->add(*this, *this); } Button::~Button() { } void Button::setOnClick(RefCount<Command> &cmd, int button) { // we only handle buttons 1 to 5 if (button > 5 || button == 0) return; //set on click command for the button m_onclick[button - 1] = cmd; } void Button::setPressedPixmap(Pixmap pm) { m_pressed_pm = pm; } void Button::setPressedColor(const FbTk::Color &color) { m_pressed_pm = None; m_pressed_color = color; } void Button::setBackgroundColor(const Color &color) { m_background_pm = 0; // we're using background color now m_background_color = color; FbTk::FbWindow::setBackgroundColor(color); } void Button::setBackgroundPixmap(Pixmap pm) { m_background_pm = pm; FbTk::FbWindow::setBackgroundPixmap(pm); } void Button::buttonPressEvent(XButtonEvent &event) { bool update = false; if (m_pressed_pm != 0) { update = true; FbTk::FbWindow::setBackgroundPixmap(m_pressed_pm); } else if (m_pressed_color.isAllocated()) { update = true; FbTk::FbWindow::setBackgroundColor(m_pressed_color); } m_pressed = true; if (update) { clear(); } } void Button::buttonReleaseEvent(XButtonEvent &event) { m_pressed = false; bool update = false; if (m_background_pm) { if (m_pressed_pm != 0) { update = true; setBackgroundPixmap(m_background_pm); } } else if (m_pressed_color.isAllocated()) { update = true; setBackgroundColor(m_background_color); } if (update) clear(); // clear background // finaly, execute command (this must be done last since this object might be deleted by the command) if (event.button > 0 && event.button <= 5 && event.x > 0 && event.x < static_cast<signed>(width()) && event.y > 0 && event.y < static_cast<signed>(height()) && m_onclick[event.button -1].get() != 0) m_onclick[event.button - 1]->execute(); } void Button::exposeEvent(XExposeEvent &event) { clearArea(event.x, event.y, event.width, event.height); } }; // end namespace FbTk
[ "simonb@54ec5f11-9ae8-0310-9a2b-99d706b22625" ]
simonb@54ec5f11-9ae8-0310-9a2b-99d706b22625
334410342f21d7015da0ee58b08c9923ab1171cf
c6b483cc2d7bc9eb6dc5c08ae92aa55ff9b3a994
/hazelcast/include/hazelcast/util/Comparator.h
4345b0bf2911757cd6803a1dc73321c91ea60e48
[ "Apache-2.0" ]
permissive
oguzdemir/hazelcast-cpp-client
ebffc7137a3a14b9fc5d96e1a1b0eac8aac1e60f
95c4687634a8ac4886d0a9b9b4c17622225261f0
refs/heads/master
2021-01-21T02:53:05.197319
2016-08-24T21:08:14
2016-08-24T21:08:14
63,674,978
0
0
null
2016-07-19T08:16:24
2016-07-19T08:16:23
null
UTF-8
C++
false
false
1,238
h
/* * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. * * 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. */ // // Created by ihsan demir on 14 Apr 2016. #ifndef HAZELCAST_UTIL_COMPARATOR_ #define HAZELCAST_UTIL_COMPARATOR_ #include "hazelcast/util/HazelcastDll.h" namespace hazelcast { namespace util { template <typename T> class Comparator { public: /** * @lhs First value to compare * @rhs Second value to compare * @return Returns < 0 if lhs is less, >0 if lhs is greater, else returns 0. */ virtual int compare(const T &lhs, const T &rhs) const = 0; }; } } #endif //HAZELCAST_UTIL_COMPARATOR_
[ "ihsan@hazelcast.com" ]
ihsan@hazelcast.com
f3e4040bd2aa091af393812201eddc440aa7eb44
5eb2628304a47e1aafd7496b9c1479b1dd6e07ca
/Health.h
f9a8683133628e903ddcfe4e6a94267a974d990a
[]
no_license
johnn134/TheTankHeardAroundTheWorld
577044a73621a01db7c68d51fddae95433ff8699
c88c10caa5e1065a65ab00164f9a18d814e3384d
refs/heads/master
2021-01-10T09:56:39.154855
2015-10-14T21:21:52
2015-10-14T21:21:52
43,763,952
1
0
null
2015-10-06T17:27:40
2015-10-06T16:43:26
C++
UTF-8
C++
false
false
281
h
//view object to show the player's health #ifndef __HEALTH_H__ #define __HEALTH_H__ #include "ViewObject.h" #include "Event.h" #define HEALTH_STRING "Health: " class Health : public df::ViewObject{ private: public: Health(); int eventHandler(const df::Event *p_e); }; #endif
[ "silverx@verizon.net" ]
silverx@verizon.net
53b424e3501b355260b3c587cf3dcabc6057ce74
63b39b6cb42b762fd9d1114cd6ade08644796e64
/checkers-server/eventService/RequestService.h
6d3fa85294b43174fbff0c5d6b9fe4c55e4c2a38
[]
no_license
Yamadads/checkers
f265e5543bc4908f4e775483171a0ff694d82a51
1c837b91dfb73f64084429c05b82a1423928feb3
refs/heads/master
2021-01-16T19:14:54.555761
2016-02-15T11:46:02
2016-02-15T11:46:02
null
0
0
null
null
null
null
UTF-8
C++
false
false
625
h
/* * requestService.h * * Created on: 09-11-2015 * Author: debian */ #ifndef EVENTSERVICE_REQUESTSERVICE_H_ #define EVENTSERVICE_REQUESTSERVICE_H_ #include "../jsonParser/json/json.h" #include "../game/Server.h" #include "../game/Client.h" class RequestService { protected: Json::Reader reader; Json::StyledWriter writer; public: RequestService(); virtual ~RequestService(); virtual bool action(Json::Value root, Server *server, Client *client) = 0; Json::Value shortJson(string key, string value); bool sendResponse(Json::Value root, Client *client); }; #endif /* EVENTSERVICE_REQUESTSERVICE_H_ */
[ "s_pawlak@yahoo.com" ]
s_pawlak@yahoo.com
fcf863f30fe195fb4594c06a28640a4c0b85e131
b3632665c205bd5dd4f4b90823a39eb22c3a2e7a
/mebel.h
c4e9e039393df3c753ab9b2468ace4c469c61ea9
[]
no_license
vadimibs/rabota3
f361387390b959ceb0fe2578baa10d249c86ab04
88226232982d0fcc89e6c0d8edc85acb704bb064
refs/heads/master
2022-07-16T16:43:12.081323
2020-05-19T14:11:38
2020-05-19T14:11:38
265,254,200
0
0
null
null
null
null
UTF-8
C++
false
false
383
h
#ifndef MEBEL_H_INCLUDED #define MEBEL_H_INCLUDED #include "izdelie.h" class mebel: public izdelie{ protected: string material; public: mebel(); mebel(string name_, int size_, string color_, string material_); void SetMaterial(string material_); string GetMaterial() const; virtual void print()const = 0; }; #endif // MEBEL_H_INCLUDED
[ "w1ntoff@mail.ru" ]
w1ntoff@mail.ru
5ed459d3dbacb0ad2f69e7f496bfc812180cdbf5
debe35fd227dcb9fc3535c6957ac017b914a7915
/src/Managers/GlobalManager.h
7684f3e6af8f9b34a1e075b9e785e03bc4fe49dd
[]
no_license
menegais1/EngineRenderer
d83b79388533c30f2dbd8ea892a1e4bf46253483
0aeddc6bbd343658e3c20351d0bcd2141761f53f
refs/heads/master
2022-12-03T02:58:06.701352
2020-08-13T22:59:16
2020-08-13T22:59:16
284,381,006
0
0
null
null
null
null
UTF-8
C++
false
false
1,689
h
///Manager responsible for forwarding the GLFW callbacks ///To every CanvasObject instantiated, every object has a uniqueId given ///in the beggining of its lifetime #ifndef GLOBAL_MANAGER_H #define GLOBAL_MANAGER_H #include <vector> #include <chrono> #include "../Base/CanvasObject.h" class GlobalManager { public: void keyboard(int key, int scancode, int action, int mods); void mouseButton(int button, int action, int modifier); void mouseMovement(double xpos, double ypos); void render(); int registerObject(CanvasObject *object); CanvasObject *unregisterObject(CanvasObject *object); static GlobalManager *getInstance(); CanvasObject *deleteObject(CanvasObject *object); void changeObjectOrder(CanvasObject *object); void reshape(int width, int height); int screenWidth; int screenHeight; fvec2 mousePosition; float deltaTime; float time = 0; float fpsUpdateCycle = 0.25; float lastFpsUpdate = 0; int fps; private: float lastReshapeTime = 0; std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long, std::ratio<1, 1000000000>>> lastTime = std::chrono::high_resolution_clock::now(); std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long, std::ratio<1, 1000000000>>> currentTime = std::chrono::high_resolution_clock::now(); int objectIdCounter; static GlobalManager *instance; //The order of the objects is descending, so what will be rendered first is last std::vector<CanvasObject *> objects; GlobalManager(); void addObjectToList(CanvasObject *object); CanvasObject *cleanUpObjects(); }; #endif
[ "menegais1@gmail.com" ]
menegais1@gmail.com
6705959800b3220449cdea8c9c827ce196b9550f
9b6eced5d80668bd4328a8f3d1f75c97f04f5e08
/bluetoothapitest/bluetoothsvs/T_BTSdpAPI/inc/T_DataSdpAttrValueList.h
70fe0d33cca84cb5f609d71f90222406faf32f06
[]
no_license
SymbianSource/oss.FCL.sf.os.bt
3ca94a01740ac84a6a35718ad3063884ea885738
ba9e7d24a7fa29d6dd93808867c28bffa2206bae
refs/heads/master
2021-01-18T23:42:06.315016
2010-10-14T10:30:12
2010-10-14T10:30:12
72,765,157
1
0
null
null
null
null
UTF-8
C++
false
false
2,474
h
/* * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" * which accompanies this distribution, and is available * at the URL "http://www.eclipse.org/legal/epl-v10.html". * * Initial Contributors: * Nokia Corporation - initial contribution. * * Contributors: * * Description: * */ #if (!defined __T_DATA_SDP_ATTR_VALUE_LIST_H__ ) #define __T_DATA_SDP_ATTR_VALUE_LIST_H__ // User Includes #include "T_DataSdpAttrValue.h" #include "T_DataSdpElementBuilder.h" #include "T_DataSdpAgent.h" /** * Test Active Notification class * */ class CT_DataSdpAttrValueList : public CT_DataSdpAttrValue { public: /** * Public destructor */ ~CT_DataSdpAttrValueList(); /** * Process a command read from the ini file * * @param aCommand The command to process * @param aSection The section in the ini containing data for the command * @param aAsyncErrorIndex Command index for async calls to return errors to * * @return ETrue if the command is processed * * @leave System wide error */ virtual TBool DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex); /** * Return a pointer to the object that the data wraps * * @return pointer to the object that the data wraps */ virtual TAny* GetObject() { return iAttrValueList; } /** * Set the object that the data wraps * * @param aObject object that the wrapper is testing * */ virtual void SetObjectL(TAny* aAny); /** * The object will no longer be owned by this * * @leave KErrNotSupported if the the function is not supported */ virtual void DisownObjectL(); inline virtual TCleanupOperation CleanupOperation(); protected: /** * Protected constructor. First phase construction */ CT_DataSdpAttrValueList(); /** * Second phase construction */ void ConstructL(); virtual CSdpAttrValueList* GetSdpAttrValueList() const; virtual CSdpAttrValue* GetSdpAttrValue() const; private: static void CleanupOperation(TAny* aAny); /** * Helper methods */ void DestroyData(); inline void DoCmdDestructor(); inline void DoCmdAppendValueL(const TDesC& aSection); inline void DoCmdBuildEncodedL(const TDesC& aSection); private: CSdpAttrValueList* iAttrValueList; CT_DataSdpElementBuilder* iElementBuilder; }; #endif /* __T_DATA_SDP_ATTR_VALUE_LIST_H__ */
[ "kirill.dremov@nokia.com" ]
kirill.dremov@nokia.com
ff41145cba05ec35d2ff7a85ca27949a407ef29e
09112640ccaf06b9cc28317a67f803f9131ed65d
/BolosLocos/BolosLocos/skeleton/main.cpp
409742725ccf15c1ddfc05b850ee22736ce388e1
[]
no_license
Posna/SimulacionFisicaPracticas
42552434f44d2bebeec991e4b001f826d74819e7
974899fc0c87a4663f663bf814170f3d03e872a3
refs/heads/master
2022-03-18T11:31:15.571758
2019-12-12T22:12:21
2019-12-12T22:12:21
209,085,757
0
0
null
null
null
null
UTF-8
C++
false
false
13,790
cpp
#include <ctype.h> #include <PxPhysicsAPI.h> #include <iostream> #include <vector> #include "core.hpp" #include "RenderUtils.hpp" #include "callbacks.hpp" #include "Particle.h" #include "ParticleSystem.h" #include "ParticleForceRegistry.h" #include "ParticleForceGenerator.h" #include "ParticleGravity.h" #include "ParticleExplosion.h" #include "ParticleWind.h" #include "ParticleAnchoredSpring.h" #include "ParticleSpring.h" #include "ParticleBuoyancy.h" #include "ParticleCable.h" #include "ParticleCollisionRegistry.h" #include "ParticleRod.h" #include "ParticleSystemRigid.h" #include "Bolos.h" #include "Barra.h" using namespace physx; PxDefaultAllocator gAllocator; PxDefaultErrorCallback gErrorCallback; PxFoundation* gFoundation = NULL; PxPhysics* gPhysics = NULL; PxMaterial* gMaterial = NULL; PxPvd* gPvd = NULL; PxDefaultCpuDispatcher* gDispatcher = NULL; PxScene* gScene = NULL; ContactReportCallback gContactReportCallback; //Scene 2 ParticleSystemRigid* fuenteI; ParticleSystemRigid* fuenteD; ParticleSystemRigid* fuenteC; //Scene 3 enum Fuerzas { Wind1, Wind2, Wind3 }; std::vector<ParticleForceGenerator*> fuerzas; //Scene 4 ParticleForceRegistry registry; ParticleRigid* muelle4; //Scene 5 ParticleCable* cable; ParticleCable* cable1; ParticleCable* cable2; ParticleContact* contacto1; ParticleContact* contacto2; ParticleContact* contacto3; ParticleRigid* baseCuerdas; ParticleRigid* rompeBolas; ParticleRigid* rompeBolas1; ParticleRigid* rompeBolas2; //Global Bolos* b; Barra* barra1; PxTransform* t; PxShape* pShape; std::vector<PxRigidStatic*> particleRigid; ParticleRigid* bola = nullptr; bool complete = true; float time = 0; int level_ = 0; void deleteScene5() { for each (PxRigidStatic * var in particleRigid) { var->release(); } particleRigid.clear(); delete b; delete barra1; delete contacto3; delete contacto2; delete contacto1; delete baseCuerdas; delete rompeBolas; delete rompeBolas1; delete rompeBolas2; } void Scene5Update(float t) { cable->addContact(contacto1, 0); contacto1->resolve(t); cable1->addContact(contacto2, 0); contacto2->resolve(t); cable2->addContact(contacto3, 0); contacto3->resolve(t); } void Scene5() { t = new PxTransform(Vector3(0.0, 0.0, 150.0)); pShape = CreateShape(PxBoxGeometry(25, 1, 200)); PxRigidStatic* particleRigidAux = gPhysics->createRigidStatic(*t); particleRigidAux->attachShape(*pShape); gScene->addActor(*particleRigidAux); particleRigid.push_back(particleRigidAux); t = new PxTransform(Vector3(0.0, 95.0f, 40.0)); pShape = CreateShape(PxBoxGeometry(25, 1, 25)); particleRigidAux = gPhysics->createRigidStatic(*t); particleRigidAux->attachShape(*pShape); gScene->addActor(*particleRigidAux); particleRigid.push_back(particleRigidAux); barra1 = new Barra(); b = new Bolos(Vector3(0.0, 5.0, 0.0), 5, gPhysics, gScene); baseCuerdas = new ParticleRigid(gPhysics, gScene, 10.0f, 1.0f, 10.0f, Vector3(0.0f, 100.0f, 40.0f), 86400.0f); rompeBolas = new ParticleRigid(gPhysics, gScene, 5.0f, Vector3(-5.0f, 10.0f, 35.0f), 86400.0f); rompeBolas1 = new ParticleRigid(gPhysics, gScene, 5.0f, Vector3(0.0f, 10.0f, 40.0f), 86400.0f); rompeBolas2 = new ParticleRigid(gPhysics, gScene, 5.0f, Vector3(5.0f, 10.0f, 35.0f), 86400.0f); contacto1 = new ParticleContact(rompeBolas, baseCuerdas); contacto2 = new ParticleContact(rompeBolas1, baseCuerdas); contacto3 = new ParticleContact(rompeBolas2, baseCuerdas); cable = new ParticleCable(rompeBolas, baseCuerdas, 80); cable1 = new ParticleCable(rompeBolas1, baseCuerdas, 80); cable2 = new ParticleCable(rompeBolas2, baseCuerdas, 80); //bola = new ParticleRigid(gPhysics, gScene, 5, Vector3(0.0, 0.0, 120.0)); } void deleteScene4() { for each (PxRigidStatic * var in particleRigid) { var->release(); } particleRigid.clear(); registry.clear(); delete fuerzas[0]; delete muelle4; fuerzas.clear(); delete barra1; delete b; } void Scene4Update(float t) { muelle4->update(t); registry.updateForces(t); } void Scene4() { t = new PxTransform(Vector3(0.0, -14.9, -25.0)); pShape = CreateShape(PxBoxGeometry(25, 15, 75)); PxRigidStatic* particleRigidAux = gPhysics->createRigidStatic(*t); particleRigidAux->attachShape(*pShape); gScene->addActor(*particleRigidAux); particleRigid.push_back(particleRigidAux); t = new PxTransform(Vector3(0.0, -14.9, 225.0)); pShape = CreateShape(PxBoxGeometry(25, 15, 75)); particleRigidAux = gPhysics->createRigidStatic(*t); particleRigidAux->attachShape(*pShape); gScene->addActor(*particleRigidAux); particleRigid.push_back(particleRigidAux); t = new PxTransform(Vector3(26.0, 0.0, 100.0)); pShape = CreateShape(PxBoxGeometry(1, 200, 75)); particleRigidAux = gPhysics->createRigidStatic(*t); particleRigidAux->attachShape(*pShape); gScene->addActor(*particleRigidAux); particleRigid.push_back(particleRigidAux); t = new PxTransform(Vector3(-26.0, 0.0, 100.0)); pShape = CreateShape(PxBoxGeometry(1, 200, 75)); particleRigidAux = gPhysics->createRigidStatic(*t); particleRigidAux->attachShape(*pShape); gScene->addActor(*particleRigidAux); particleRigid.push_back(particleRigidAux); PxQuat g = PxQuat(3.14 / 9.0, Vector3(1.0, 0.0, 0.0)); t = new PxTransform(Vector3(0.0, -5.0, 165.0), g); pShape = CreateShape(PxBoxGeometry(25, 1, 20)); particleRigidAux = gPhysics->createRigidStatic(*t); particleRigidAux->attachShape(*pShape); gScene->addActor(*particleRigidAux); particleRigid.push_back(particleRigidAux); barra1 = new Barra(); b = new Bolos(Vector3(0.0, 5.0, 0.0), 5, gPhysics, gScene); muelle4 = new ParticleRigid(gPhysics, gScene, 24.9f, 9.9f, 25.0f, Vector3(0.0, 0.0, 100.0), 86400.0f); fuerzas.push_back(new ParticleBuoyancy(-10.0f, 90990.1f, 20.0f)); registry.add(muelle4, fuerzas[0]); } void deleteScene3() { for each (PxRigidStatic * var in particleRigid) { var->release(); } particleRigid.clear(); delete b; delete barra1; for each (ParticleWind * var in fuerzas) { delete var; } fuerzas.clear(); registry.clear(); } void Scene3Update(float t) { registry.updateForces(t); } void Scene3() { fuerzas.push_back(new ParticleWind(Vector3(-25, 0, 80), 15)); fuerzas.push_back(new ParticleWind(Vector3(25, 0, 80), 15)); fuerzas.push_back(new ParticleWind(Vector3(0, -7, 140), 20)); //fuerzas[Explosion]->setInstantForce(true); t = new PxTransform(Vector3(0.0, 0.0, -25.0)); pShape = CreateShape(PxBoxGeometry(25, 1, 75)); PxRigidStatic* particleRigidAux = gPhysics->createRigidStatic(*t); particleRigidAux->attachShape(*pShape); gScene->addActor(*particleRigidAux); particleRigid.push_back(particleRigidAux); t = new PxTransform(Vector3(0.0, 0.0, 225.0)); pShape = CreateShape(PxBoxGeometry(25, 1, 75)); particleRigidAux = gPhysics->createRigidStatic(*t); particleRigidAux->attachShape(*pShape); gScene->addActor(*particleRigidAux); particleRigid.push_back(particleRigidAux); t = new PxTransform(Vector3(20.0, 0.0, 100.0)); pShape = CreateShape(PxBoxGeometry(5, 1, 70)); particleRigidAux = gPhysics->createRigidStatic(*t); particleRigidAux->attachShape(*pShape); gScene->addActor(*particleRigidAux); particleRigid.push_back(particleRigidAux); t = new PxTransform(Vector3(-20.0, 0.0, 100.0)); pShape = CreateShape(PxBoxGeometry(5, 1, 70)); particleRigidAux = gPhysics->createRigidStatic(*t); particleRigidAux->attachShape(*pShape); gScene->addActor(*particleRigidAux); particleRigid.push_back(particleRigidAux); barra1 = new Barra(); b = new Bolos(Vector3(0.0, 5.0, 0.0), 5, gPhysics, gScene); registry.add(bola, fuerzas[0]); registry.add(bola, fuerzas[1]); registry.add(bola, fuerzas[2]); } void deleteScene2() { for each (PxRigidStatic * var in particleRigid) { var->release(); } particleRigid.clear(); delete b; delete barra1; delete fuenteC; delete fuenteD; delete fuenteI; } void Scene2Update(float t) { fuenteI->update(t); fuenteD->update(t); fuenteC->update(t); } void Scene2() { t = new PxTransform(Vector3(0.0, 0.0, -25.0)); pShape = CreateShape(PxBoxGeometry(25, 1, 75)); PxRigidStatic* particleRigidAux = gPhysics->createRigidStatic(*t); particleRigidAux->attachShape(*pShape); gScene->addActor(*particleRigidAux); particleRigid.push_back(particleRigidAux); t = new PxTransform(Vector3(0.0, 0.0, 225.0)); pShape = CreateShape(PxBoxGeometry(25, 1, 75)); particleRigidAux = gPhysics->createRigidStatic(*t); particleRigidAux->attachShape(*pShape); gScene->addActor(*particleRigidAux); particleRigid.push_back(particleRigidAux); PxQuat g = PxQuat(3.14 / 9.0, Vector3(1.0, 0.0, 0.0)); t = new PxTransform(Vector3(0.0, -5.0, 160.0), g); pShape = CreateShape(PxBoxGeometry(25, 1, 20)); particleRigidAux = gPhysics->createRigidStatic(*t); particleRigidAux->attachShape(*pShape); gScene->addActor(*particleRigidAux); particleRigid.push_back(particleRigidAux); barra1 = new Barra(); fuenteI = new ParticleSystemRigid(gPhysics, gScene, Vector3(7.0, 30.0, 100.0), 1.0f); fuenteC = new ParticleSystemRigid(gPhysics, gScene, Vector3(0.0, 30.0, 100.0), 1.0f); fuenteD = new ParticleSystemRigid(gPhysics, gScene, Vector3(-7.0, 30.0, 100.0), 1.0f); b = new Bolos(Vector3(0.0, 5.0, 0.0), 5, gPhysics, gScene); } void deleteScene1() { for each (PxRigidStatic * var in particleRigid) { var->release(); } particleRigid.clear(); delete b; delete barra1; } void Scene1() { t = new PxTransform(Vector3(0.0, 0.0, 150.0)); pShape = CreateShape(PxBoxGeometry(25, 1, 200)); PxRigidStatic* particleRigidAux = gPhysics->createRigidStatic(*t); particleRigidAux->attachShape(*pShape); gScene->addActor(*particleRigidAux); particleRigid.push_back(particleRigidAux); barra1 = new Barra(); b = new Bolos(Vector3(0.0, 5.0, 0.0), 5, gPhysics, gScene); if (bola == nullptr) bola = new ParticleRigid(gPhysics, gScene, 5, Vector3(0.0, 0.0, 120.0)); } // Initialize physics engine void initPhysics(bool interactive) { PX_UNUSED(interactive); gFoundation = PxCreateFoundation(PX_FOUNDATION_VERSION, gAllocator, gErrorCallback); gPvd = PxCreatePvd(*gFoundation); PxPvdTransport* transport = PxDefaultPvdSocketTransportCreate(PVD_HOST, 5425, 10); gPvd->connect(*transport, PxPvdInstrumentationFlag::eALL); gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *gFoundation, PxTolerancesScale(), true, gPvd); gMaterial = gPhysics->createMaterial(0.5f, 0.5f, 0.6f); // For Solid Rigids +++++++++++++++++++++++++++++++++++++ PxSceneDesc sceneDesc(gPhysics->getTolerancesScale()); sceneDesc.gravity = PxVec3(0.0f, -98.0f, 0.0f); gDispatcher = PxDefaultCpuDispatcherCreate(2); sceneDesc.cpuDispatcher = gDispatcher; sceneDesc.filterShader = contactReportFilterShader; sceneDesc.simulationEventCallback = &gContactReportCallback; gScene = gPhysics->createScene(sceneDesc); // ------------------------------------------------------ } // Function to configure what happens in each step of physics // interactive: true if the game is rendering, false if it offline // t: time passed since last call in milliseconds void stepPhysics(bool interactive, double t) { PX_UNUSED(interactive); //Crear y borrar cada escena segun toque if (complete) { switch (level_) { case 0: Scene1(); break; case 1: deleteScene1(); Scene2(); break; case 2: deleteScene2(); Scene3(); break; case 3: deleteScene3(); Scene4(); break; case 4: deleteScene4(); Scene5(); break; default: break; } complete = false; } //Update de cada scene switch (level_) { case 1: Scene2Update(t); break; case 2: Scene3Update(t); break; case 3: Scene4Update(t); break; case 4: Scene5Update(t); break; default: break; } //Updates principales bola->update(t); barra1->update(t); b->update(t); //Siguiente nivel if (b->caidos() == b->numBolos()) { time += t; if (time > 3.0f) { complete = true; level_++; if (level_ == 5) { deleteScene5(); } level_ = level_ % 5; time = 0; } } gScene->simulate(t); gScene->fetchResults(true); } // Function to clean data // Add custom code to the begining of the function void cleanupPhysics(bool interactive) { PX_UNUSED(interactive); // Rigid Body ++++++++++++++++++++++++++++++++++++++++++ gScene->release(); gDispatcher->release(); delete bola; switch (level_) { case 0: deleteScene1(); break; case 1: deleteScene2(); break; case 2: deleteScene3(); break; case 3: deleteScene4(); break; case 4: deleteScene5(); break; default: break; } // ----------------------------------------------------- gPhysics->release(); PxPvdTransport* transport = gPvd->getTransport(); gPvd->release(); transport->release(); gFoundation->release(); } // Function called when a key is pressed void keyPress(unsigned char key, const PxTransform& camera) { PX_UNUSED(camera); switch (toupper(key)) { case 'Q': { level_++; if (level_ == 5) { deleteScene5(); } level_ = level_ % 5; complete = true; break; } case ' ': { if (level_ == 2) { registry.clear(); delete bola; bola = new ParticleRigid(gPhysics, gScene, 5, barra1->getPos()); registry.add(bola, fuerzas[0]); registry.add(bola, fuerzas[1]); registry.add(bola, fuerzas[2]); } else { delete bola; bola = new ParticleRigid(gPhysics, gScene, 5, barra1->getPos()); } bola->addForce(Vector3(0.0, 0.0, -1.0), 99999, PxForceMode::eIMPULSE); break; } default: break; } } void onCollision(physx::PxActor* actor1, physx::PxActor* actor2) { PX_UNUSED(actor1); PX_UNUSED(actor2); } int main(int, const char* const*) { #ifndef OFFLINE_EXECUTION extern void renderLoop(); renderLoop(); #else static const PxU32 frameCount = 100; initPhysics(false); for (PxU32 i = 0; i < frameCount; i++) stepPhysics(false); cleanupPhysics(false); #endif return 0; }
[ "jomart17@ucm.es" ]
jomart17@ucm.es
5e0e47e322ce264ce384ebef15005272e2c874d6
140d78334109e02590f04769ec154180b2eaf78d
/aws-cpp-sdk-sms/include/aws/sms/model/GetServersResult.h
403b60bdc237b3a097fd4729d71c858848acdd0f
[ "Apache-2.0", "MIT", "JSON" ]
permissive
coderTong/aws-sdk-cpp
da140feb7e5495366a8d2a6a02cf8b28ba820ff6
5cd0c0a03b667c5a0bd17394924abe73d4b3754a
refs/heads/master
2021-07-08T07:04:40.181622
2017-08-22T21:50:00
2017-08-22T21:50:00
101,145,374
0
1
Apache-2.0
2021-05-04T21:06:36
2017-08-23T06:24:37
C++
UTF-8
C++
false
false
4,243
h
๏ปฟ/* * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file 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. */ #pragma once #include <aws/sms/SMS_EXPORTS.h> #include <aws/core/utils/DateTime.h> #include <aws/sms/model/ServerCatalogStatus.h> #include <aws/core/utils/memory/stl/AWSVector.h> #include <aws/core/utils/memory/stl/AWSString.h> #include <aws/sms/model/Server.h> #include <utility> namespace Aws { template<typename RESULT_TYPE> class AmazonWebServiceResult; namespace Utils { namespace Json { class JsonValue; } // namespace Json } // namespace Utils namespace SMS { namespace Model { class AWS_SMS_API GetServersResult { public: GetServersResult(); GetServersResult(const AmazonWebServiceResult<Aws::Utils::Json::JsonValue>& result); GetServersResult& operator=(const AmazonWebServiceResult<Aws::Utils::Json::JsonValue>& result); inline const Aws::Utils::DateTime& GetLastModifiedOn() const{ return m_lastModifiedOn; } inline void SetLastModifiedOn(const Aws::Utils::DateTime& value) { m_lastModifiedOn = value; } inline void SetLastModifiedOn(Aws::Utils::DateTime&& value) { m_lastModifiedOn = std::move(value); } inline GetServersResult& WithLastModifiedOn(const Aws::Utils::DateTime& value) { SetLastModifiedOn(value); return *this;} inline GetServersResult& WithLastModifiedOn(Aws::Utils::DateTime&& value) { SetLastModifiedOn(std::move(value)); return *this;} inline const ServerCatalogStatus& GetServerCatalogStatus() const{ return m_serverCatalogStatus; } inline void SetServerCatalogStatus(const ServerCatalogStatus& value) { m_serverCatalogStatus = value; } inline void SetServerCatalogStatus(ServerCatalogStatus&& value) { m_serverCatalogStatus = std::move(value); } inline GetServersResult& WithServerCatalogStatus(const ServerCatalogStatus& value) { SetServerCatalogStatus(value); return *this;} inline GetServersResult& WithServerCatalogStatus(ServerCatalogStatus&& value) { SetServerCatalogStatus(std::move(value)); return *this;} inline const Aws::Vector<Server>& GetServerList() const{ return m_serverList; } inline void SetServerList(const Aws::Vector<Server>& value) { m_serverList = value; } inline void SetServerList(Aws::Vector<Server>&& value) { m_serverList = std::move(value); } inline GetServersResult& WithServerList(const Aws::Vector<Server>& value) { SetServerList(value); return *this;} inline GetServersResult& WithServerList(Aws::Vector<Server>&& value) { SetServerList(std::move(value)); return *this;} inline GetServersResult& AddServerList(const Server& value) { m_serverList.push_back(value); return *this; } inline GetServersResult& AddServerList(Server&& value) { m_serverList.push_back(std::move(value)); return *this; } inline const Aws::String& GetNextToken() const{ return m_nextToken; } inline void SetNextToken(const Aws::String& value) { m_nextToken = value; } inline void SetNextToken(Aws::String&& value) { m_nextToken = std::move(value); } inline void SetNextToken(const char* value) { m_nextToken.assign(value); } inline GetServersResult& WithNextToken(const Aws::String& value) { SetNextToken(value); return *this;} inline GetServersResult& WithNextToken(Aws::String&& value) { SetNextToken(std::move(value)); return *this;} inline GetServersResult& WithNextToken(const char* value) { SetNextToken(value); return *this;} private: Aws::Utils::DateTime m_lastModifiedOn; ServerCatalogStatus m_serverCatalogStatus; Aws::Vector<Server> m_serverList; Aws::String m_nextToken; }; } // namespace Model } // namespace SMS } // namespace Aws
[ "henso@amazon.com" ]
henso@amazon.com
960da726aaca071019a120a69226c33828edb107
6ea0e138431c129d5c520ea739cabf4a15fb3b10
/src/Game.cpp
66903cc27089fef956893a473e37d8fc62b41e54
[]
no_license
ceh-2000/pong
10b61dfb36cc8e862cd1aed63e701e7d5eaeef65
1d679c8d748b3be362c06dc8b1f87fcfe7ea09e1
refs/heads/main
2023-03-07T07:28:36.697065
2021-02-17T16:27:21
2021-02-17T16:27:21
338,654,622
0
0
null
null
null
null
UTF-8
C++
false
false
6,642
cpp
#include <SFML/Graphics.hpp> #include <iostream> #include "Game.h" Game::Game(Paddle& paddle1, Paddle& paddle2, Ball& ball, PaddleView& paddle1View, PaddleView& paddle2View, BallView& ballView): paddle1(paddle1), paddle2(paddle2), ball(ball), paddle1View(paddle1View), paddle2View(paddle2View), ballView(ballView) { // Set the initial scores this->score1 = 0; this->score2 = 0; // Set the font of our text if (!font.loadFromFile("../data/Newsreader_18pt-Regular.ttf")) { std::cout << "Could not load font." << std::endl; } if (!backgroundTexture.loadFromFile("../data/faces.png")) { std::cout << "Could not load image from file." << std::endl; } displayScore.setFont(font); this->gameHappening = false; this->level = 4; } Game::~Game(){} void Game::resetGame(sf::RenderWindow& app, int winner){ gameHappening = false; // Set the text on this screen displayScore.setCharacterSize(40); displayScore.setPosition(0, 0); sf::String myText = "Press Space Bar to start\n" "or exit to quit.\n\n" "Press up to set player 1 as AI.\n" "Press down to set player 1 as human.\n" "Press left to set player 2 as AI.\n" "Press right to set player 2 as human.\n\n" "Press a number between 1 and 9\n" "to set difficulty\n"; if(winner == 2){ myText = "Player 2 Wins!\n"+myText; } else if(winner == 1){ myText = "Player 1 Wins!\n"+myText; } else{ myText = "Stop coronavirus\nby moving the mask up and down.\n\n"+myText; } displayScore.setString(myText); app.clear(sf::Color::Blue); displayScore.setFillColor(sf::Color::White); app.draw(displayScore); app.display(); // Keyboard inputs for user to select players, difficulty, and game start if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){ paddle1View.setAI(true); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){ paddle1View.setAI(false); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){ paddle2View.setAI(true); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){ paddle2View.setAI(false); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num1)){ level = 1; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num2)){ level = 2; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num3)){ level = 3; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num4)){ level = 4; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num5)){ level = 5; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num6)){ level = 6; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num7)){ level = 7; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num8)){ level = 8; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num9)){ level = 9; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)){ this->score1 = 0; this->score2 = 0; gameHappening = true; resetRound(app, app.getSize().x, app.getSize().y); } } void Game::resetRound(sf::RenderWindow& app, float windowWidth, float windowHeight){ // Check for a game win if(score1 == 11){ // Set to default players paddle1View.setAI(true); paddle2View.setAI(false); this->level = 4; resetGame(app, 1); } else if(score2 == 11){ // Set to default players paddle1View.setAI(true); paddle2View.setAI(false); this->level = 4; resetGame(app, 2); } // Update the text that shows the score displayScore.setString("Player 1: "+std::to_string(score1)+" | Player 2: "+std::to_string(score2)); displayScore.setPosition(windowWidth / 2.0f - 130.0f, 0); displayScore.setCharacterSize(30); // Reposition the paddles and ball float paddleDistanceFromEdge = 100.0f; paddle1.setPosition(paddleDistanceFromEdge - paddle1.getWidth(), windowHeight / 2.0f - paddle1.getHeight() / 2.0f); paddle2.setPosition(windowWidth - paddleDistanceFromEdge, windowHeight / 2.0f - paddle2.getHeight() / 2.0f); ball.setPosition(windowWidth / 2.0f - ball.getRadius(), windowHeight / 2.0f - ball.getRadius()); // Scale the ball's velocity based on how far the player has come float ballVelocity = level * 100 + score1 * 20 + score2 * 20; ball.setRandomVelocity(ballVelocity); } void Game::updateGame(sf::RenderWindow& app, float deltaTime){ if(gameHappening == true){ float windowWidth = app.getSize().x; float windowHeight = app.getSize().y; // Check to see if we resize and move the paddle and text if(abs(windowWidth - 100.0f - paddle2.getPosition().x) > 0.01f ){ paddle2.setPosition(windowWidth - 100.0f, paddle2.getPosition().y); displayScore.setPosition(windowWidth / 2.0f - 130.0f, 0); } // Update the paddles paddle1View.move(paddle1, windowHeight, windowWidth, ball, deltaTime); paddle2View.move(paddle2, windowHeight, windowWidth, ball, deltaTime); ballView.move(ball, deltaTime); //Check if either player has won the round int win = ball.checkWin(windowWidth); if(win == 2){ score2 += 1; resetRound(app, windowWidth, windowHeight); } else if(win == 1){ score1 += 1; resetRound(app, windowWidth, windowHeight); } // Update the ball according to collisions ball.checkCollisionWall(windowHeight, true); ball.checkCollisionPaddle1(paddle1, true); ball.checkCollisionPaddle2(paddle2, true); // Resolve any lingering intersections using the new trajectory (velocity) of the ball while(ball.checkCollisionWall(windowHeight, false) | ball.checkCollisionPaddle1(paddle1, false) | ball.checkCollisionPaddle2(paddle2, false)) { ball.move(deltaTime); // another option is to move ball immediately outside and then continue game } // Clear screen and fill with white app.clear(sf::Color::White); sf::RectangleShape background(sf::Vector2f(windowWidth, windowHeight)); const sf::Texture *pBackgroundTexture = &backgroundTexture; background.setTexture(pBackgroundTexture); app.draw(background); displayScore.setFillColor(sf::Color::Black); app.draw(displayScore); paddle1View.draw(paddle1, app); paddle2View.draw(paddle2, app); ballView.draw(ball, app); // Display app.display(); } else{ if(score1 == 11){ resetGame(app, 1); } else if(score2 == 11){ resetGame(app, 2); } else{ resetGame(app, 0); } } }
[ "clare.heinbaugh@gmail.com" ]
clare.heinbaugh@gmail.com
0fd43608809485b1c41b329438d3d9d7189711d9
9c47aff8f135146e599fb19c19fea2c4898129ae
/Render/RenderList.h
c6ebdb4276a8cbd29bc3b6f77626cbe19fb640d1
[]
no_license
ELTraxo/DX9-Render
4b1b7d531612784d0289e3bfcf1e16995c90270e
97150d13bb0e20b73996f4933a01cc5b75c8fe92
refs/heads/master
2021-06-20T01:26:31.699033
2021-01-12T03:28:15
2021-01-12T03:28:15
157,016,157
0
1
null
null
null
null
UTF-8
C++
false
false
413
h
#pragma once #include "Primitive.h" #include "Sprite.h" #include "Text.h" using Renderables = std::vector<RenderablePtr>; class CRenderList { Renderables renderables; public: CRenderList(); ~CRenderList(); Renderables& GetList(); void Clear(); void AddRenderable( PrimitivePtr pPrim ); void AddRenderable( TexturePtr pTexture ); void AddRenderable( TextPtr pFont ); }; using RenderList = CRenderList;
[ "traxin@noreply.github.com" ]
traxin@noreply.github.com
db76149f373b6306d6d36ee5b77a464094be676b
9de5bc4636f13f78651238c2c7c047387e885a3b
/component/RestServer/export/WorkerThread.h
3c7f9429cb0376832359465d249b1d91a5aa3673
[]
no_license
nerfe/CPPRestSDK-server
1ba7bcaf25344644e38fa5480ff8cc54968aa734
8b76ea5ed2071be0456df702847fac37f4f6f08a
refs/heads/main
2023-07-13T01:06:18.610123
2021-07-30T14:56:00
2021-07-30T14:56:00
null
0
0
null
null
null
null
UTF-8
C++
false
false
496
h
#ifndef _WORKERTHREAD_H #define _WORKERTHREAD_H #include "thread.h" #include "workqueue.h" class WorkerThread { private: std::thread *tid; static WorkerThread* workerInstance; public: CWorkQueue* wmsgQueue; WorkerThread(); virtual ~WorkerThread(); virtual void Run(); virtual void start(); static WorkerThread* getThreadInstance() { if(workerInstance==NULL) workerInstance=new WorkerThread(); return workerInstance; } }; #endif
[ "chandanshoun@gmail.com" ]
chandanshoun@gmail.com
08efbd0db7b9245205c7795b57e3a8d080b5ae1d
e95ba818ef79f11c2b96e5c38ce9270d971ade56
/src/engine/octaedit.cpp
ffa64136706d7009b7ab875f3136ad14dfbb841a
[ "Zlib", "BSD-3-Clause", "LicenseRef-scancode-unknown-license-reference", "MIT" ]
permissive
Manmellon/zeromod-sauerbraten
92095da2f36daafb4742512a5e108e107ee799e7
ae025cc5ee998b03869ce06ef991322d3eead46b
refs/heads/master
2020-04-08T05:50:35.967620
2018-11-25T21:27:42
2018-11-25T21:27:42
null
0
0
null
null
null
null
UTF-8
C++
false
false
81,080
cpp
#include "engine.h" extern int outline; bool boxoutline = false; void boxs(int orient, vec o, const vec &s, float size) { int d = dimension(orient), dc = dimcoord(orient); float f = boxoutline ? (dc>0 ? 0.2f : -0.2f) : 0; o[D[d]] += dc * s[D[d]] + f; vec r(0, 0, 0), c(0, 0, 0); r[R[d]] = s[R[d]]; c[C[d]] = s[C[d]]; vec v1 = o, v2 = vec(o).add(r), v3 = vec(o).add(r).add(c), v4 = vec(o).add(c); r[R[d]] = 0.5f*size; c[C[d]] = 0.5f*size; gle::defvertex(); gle::begin(GL_TRIANGLE_STRIP); gle::attrib(vec(v1).sub(r).sub(c)); gle::attrib(vec(v1).add(r).add(c)); gle::attrib(vec(v2).add(r).sub(c)); gle::attrib(vec(v2).sub(r).add(c)); gle::attrib(vec(v3).add(r).add(c)); gle::attrib(vec(v3).sub(r).sub(c)); gle::attrib(vec(v4).sub(r).add(c)); gle::attrib(vec(v4).add(r).sub(c)); gle::attrib(vec(v1).sub(r).sub(c)); gle::attrib(vec(v1).add(r).add(c)); xtraverts += gle::end(); } void boxs(int orient, vec o, const vec &s) { int d = dimension(orient), dc = dimcoord(orient); float f = boxoutline ? (dc>0 ? 0.2f : -0.2f) : 0; o[D[d]] += dc * s[D[d]] + f; gle::defvertex(); gle::begin(GL_LINE_LOOP); gle::attrib(o); o[R[d]] += s[R[d]]; gle::attrib(o); o[C[d]] += s[C[d]]; gle::attrib(o); o[R[d]] -= s[R[d]]; gle::attrib(o); xtraverts += gle::end(); } void boxs3D(const vec &o, vec s, int g) { s.mul(g); loopi(6) boxs(i, o, s); } void boxsgrid(int orient, vec o, vec s, int g) { int d = dimension(orient), dc = dimcoord(orient); float ox = o[R[d]], oy = o[C[d]], xs = s[R[d]], ys = s[C[d]], f = boxoutline ? (dc>0 ? 0.2f : -0.2f) : 0; o[D[d]] += dc * s[D[d]]*g + f; gle::defvertex(); gle::begin(GL_LINES); loop(x, xs) { o[R[d]] += g; gle::attrib(o); o[C[d]] += ys*g; gle::attrib(o); o[C[d]] = oy; } loop(y, ys) { o[C[d]] += g; o[R[d]] = ox; gle::attrib(o); o[R[d]] += xs*g; gle::attrib(o); } xtraverts += gle::end(); } selinfo sel, lastsel, savedsel; int orient = 0; int gridsize = 8; ivec cor, lastcor; ivec cur, lastcur; extern int entediting; bool editmode = false; bool havesel = false; bool hmapsel = false; int horient = 0; extern int entmoving; VARF(dragging, 0, 0, 1, if(!dragging || cor[0]<0) return; lastcur = cur; lastcor = cor; sel.grid = gridsize; sel.orient = orient; ); int moving = 0; ICOMMAND(moving, "b", (int *n), { if(*n >= 0) { if(!*n || (moving<=1 && !pointinsel(sel, vec(cur).add(1)))) moving = 0; else if(!moving) moving = 1; } intret(moving); }); VARF(gridpower, 0, 3, 12, { if(dragging) return; gridsize = 1<<gridpower; if(gridsize>=worldsize) gridsize = worldsize/2; cancelsel(); }); VAR(passthroughsel, 0, 0, 1); VAR(editing, 1, 0, 0); VAR(selectcorners, 0, 0, 1); VARF(hmapedit, 0, 0, 1, horient = sel.orient); void forcenextundo() { lastsel.orient = -1; } extern void hmapcancel(); void cubecancel() { havesel = false; moving = dragging = hmapedit = passthroughsel = 0; forcenextundo(); hmapcancel(); } void cancelsel() { cubecancel(); entcancel(); } void toggleedit(bool force) { if(!force) { if(!isconnected()) return; if(player->state!=CS_ALIVE && player->state!=CS_DEAD && player->state!=CS_EDITING) return; // do not allow dead players to edit to avoid state confusion if(!game::allowedittoggle()) return; // not in most multiplayer modes } if(!(editmode = !editmode)) { player->state = player->editstate; player->o.z -= player->eyeheight; // entinmap wants feet pos entinmap(player); // find spawn closest to current floating pos } else { game::resetgamestate(); player->editstate = player->state; player->state = CS_EDITING; } cancelsel(); stoppaintblendmap(); keyrepeat(editmode); editing = entediting = editmode; extern int fullbright; if(fullbright) { initlights(); lightents(); } if(!force) game::edittoggled(editmode); } bool noedit(bool view, bool msg) { if(!editmode) { if(msg) conoutf(CON_ERROR, "operation only allowed in edit mode"); return true; } if(view || haveselent()) return false; float r = 1.0f; vec o(sel.o), s(sel.s); s.mul(float(sel.grid) / 2.0f); o.add(s); r = float(max(s.x, max(s.y, s.z))); bool viewable = (isvisiblesphere(r, o) != VFC_NOT_VISIBLE); if(!viewable && msg) conoutf(CON_ERROR, "selection not in view"); return !viewable; } void reorient() { sel.cx = 0; sel.cy = 0; sel.cxs = sel.s[R[dimension(orient)]]*2; sel.cys = sel.s[C[dimension(orient)]]*2; sel.orient = orient; } void selextend() { if(noedit(true)) return; loopi(3) { if(cur[i]<sel.o[i]) { sel.s[i] += (sel.o[i]-cur[i])/sel.grid; sel.o[i] = cur[i]; } else if(cur[i]>=sel.o[i]+sel.s[i]*sel.grid) { sel.s[i] = (cur[i]-sel.o[i])/sel.grid+1; } } } ICOMMAND(edittoggle, "", (), toggleedit(false)); COMMAND(entcancel, ""); COMMAND(cubecancel, ""); COMMAND(cancelsel, ""); COMMAND(reorient, ""); COMMAND(selextend, ""); ICOMMAND(selmoved, "", (), { if(noedit(true)) return; intret(sel.o != savedsel.o ? 1 : 0); }); ICOMMAND(selsave, "", (), { if(noedit(true)) return; savedsel = sel; }); ICOMMAND(selrestore, "", (), { if(noedit(true)) return; sel = savedsel; }); ICOMMAND(selswap, "", (), { if(noedit(true)) return; swap(sel, savedsel); }); ///////// selection support ///////////// cube &blockcube(int x, int y, int z, const block3 &b, int rgrid) // looks up a world cube, based on coordinates mapped by the block { int dim = dimension(b.orient), dc = dimcoord(b.orient); ivec s(dim, x*b.grid, y*b.grid, dc*(b.s[dim]-1)*b.grid); s.add(b.o); if(dc) s[dim] -= z*b.grid; else s[dim] += z*b.grid; return lookupcube(s, rgrid); } #define loopxy(b) loop(y,(b).s[C[dimension((b).orient)]]) loop(x,(b).s[R[dimension((b).orient)]]) #define loopxyz(b, r, f) { loop(z,(b).s[D[dimension((b).orient)]]) loopxy((b)) { cube &c = blockcube(x,y,z,b,r); f; } } #define loopselxyz(f) { if(local) makeundo(); loopxyz(sel, sel.grid, f); changed(sel); } #define selcube(x, y, z) blockcube(x, y, z, sel, sel.grid) ////////////// cursor /////////////// int selchildcount = 0, selchildmat = -1; ICOMMAND(havesel, "", (), intret(havesel ? selchildcount : 0)); void countselchild(cube *c, const ivec &cor, int size) { ivec ss = ivec(sel.s).mul(sel.grid); loopoctaboxsize(cor, size, sel.o, ss) { ivec o(i, cor, size); if(c[i].children) countselchild(c[i].children, o, size/2); else { selchildcount++; if(c[i].material != MAT_AIR && selchildmat != MAT_AIR) { if(selchildmat < 0) selchildmat = c[i].material; else if(selchildmat != c[i].material) selchildmat = MAT_AIR; } } } } void normalizelookupcube(const ivec &o) { if(lusize>gridsize) { lu.x += (o.x-lu.x)/gridsize*gridsize; lu.y += (o.y-lu.y)/gridsize*gridsize; lu.z += (o.z-lu.z)/gridsize*gridsize; } else if(gridsize>lusize) { lu.x &= ~(gridsize-1); lu.y &= ~(gridsize-1); lu.z &= ~(gridsize-1); } lusize = gridsize; } void updateselection() { sel.o.x = min(lastcur.x, cur.x); sel.o.y = min(lastcur.y, cur.y); sel.o.z = min(lastcur.z, cur.z); sel.s.x = abs(lastcur.x-cur.x)/sel.grid+1; sel.s.y = abs(lastcur.y-cur.y)/sel.grid+1; sel.s.z = abs(lastcur.z-cur.z)/sel.grid+1; } bool editmoveplane(const vec &o, const vec &ray, int d, float off, vec &handle, vec &dest, bool first) { plane pl(d, off); float dist = 0.0f; if(!pl.rayintersect(player->o, ray, dist)) return false; dest = vec(ray).mul(dist).add(player->o); if(first) handle = vec(dest).sub(o); dest.sub(handle); return true; } inline bool isheightmap(int orient, int d, bool empty, cube *c); extern void entdrag(const vec &ray); extern bool hoveringonent(int ent, int orient); extern void renderentselection(const vec &o, const vec &ray, bool entmoving); extern float rayent(const vec &o, const vec &ray, float radius, int mode, int size, int &orient, int &ent); VAR(gridlookup, 0, 0, 1); VAR(passthroughcube, 0, 1, 1); void rendereditcursor() { int d = dimension(sel.orient), od = dimension(orient), odc = dimcoord(orient); bool hidecursor = g3d_windowhit(true, false) || blendpaintmode, hovering = false; hmapsel = false; if(moving) { static vec dest, handle; if(editmoveplane(vec(sel.o), camdir, od, sel.o[D[od]]+odc*sel.grid*sel.s[D[od]], handle, dest, moving==1)) { if(moving==1) { dest.add(handle); handle = vec(ivec(handle).mask(~(sel.grid-1))); dest.sub(handle); moving = 2; } ivec o = ivec(dest).mask(~(sel.grid-1)); sel.o[R[od]] = o[R[od]]; sel.o[C[od]] = o[C[od]]; } } else if(entmoving) { entdrag(camdir); } else { ivec w; float sdist = 0, wdist = 0, t; int entorient = 0, ent = -1; wdist = rayent(player->o, camdir, 1e16f, (editmode && showmat ? RAY_EDITMAT : 0) // select cubes first | (!dragging && entediting ? RAY_ENTS : 0) | RAY_SKIPFIRST | (passthroughcube==1 ? RAY_PASS : 0), gridsize, entorient, ent); if((havesel || dragging) && !passthroughsel && !hmapedit) // now try selecting the selection if(rayboxintersect(vec(sel.o), vec(sel.s).mul(sel.grid), player->o, camdir, sdist, orient)) { // and choose the nearest of the two if(sdist < wdist) { wdist = sdist; ent = -1; } } if((hovering = hoveringonent(hidecursor ? -1 : ent, entorient))) { if(!havesel) { selchildcount = 0; selchildmat = -1; sel.s = ivec(0, 0, 0); } } else { vec w = vec(camdir).mul(wdist+0.05f).add(player->o); if(!insideworld(w)) { loopi(3) wdist = min(wdist, ((camdir[i] > 0 ? worldsize : 0) - player->o[i]) / camdir[i]); w = vec(camdir).mul(wdist-0.05f).add(player->o); if(!insideworld(w)) { wdist = 0; loopi(3) w[i] = clamp(player->o[i], 0.0f, float(worldsize)); } } cube *c = &lookupcube(ivec(w)); if(gridlookup && !dragging && !moving && !havesel && hmapedit!=1) gridsize = lusize; int mag = lusize / gridsize; normalizelookupcube(ivec(w)); if(sdist == 0 || sdist > wdist) rayboxintersect(vec(lu), vec(gridsize), player->o, camdir, t=0, orient); // just getting orient cur = lu; cor = ivec(vec(w).mul(2).div(gridsize)); od = dimension(orient); d = dimension(sel.orient); if(hmapedit==1 && dimcoord(horient) == (camdir[dimension(horient)]<0)) { hmapsel = isheightmap(horient, dimension(horient), false, c); if(hmapsel) od = dimension(orient = horient); } if(dragging) { updateselection(); sel.cx = min(cor[R[d]], lastcor[R[d]]); sel.cy = min(cor[C[d]], lastcor[C[d]]); sel.cxs = max(cor[R[d]], lastcor[R[d]]); sel.cys = max(cor[C[d]], lastcor[C[d]]); if(!selectcorners) { sel.cx &= ~1; sel.cy &= ~1; sel.cxs &= ~1; sel.cys &= ~1; sel.cxs -= sel.cx-2; sel.cys -= sel.cy-2; } else { sel.cxs -= sel.cx-1; sel.cys -= sel.cy-1; } sel.cx &= 1; sel.cy &= 1; havesel = true; } else if(!havesel) { sel.o = lu; sel.s.x = sel.s.y = sel.s.z = 1; sel.cx = sel.cy = 0; sel.cxs = sel.cys = 2; sel.grid = gridsize; sel.orient = orient; d = od; } sel.corner = (cor[R[d]]-(lu[R[d]]*2)/gridsize)+(cor[C[d]]-(lu[C[d]]*2)/gridsize)*2; selchildcount = 0; selchildmat = -1; countselchild(worldroot, ivec(0, 0, 0), worldsize/2); if(mag>=1 && selchildcount==1) { selchildmat = c->material; if(mag>1) selchildcount = -mag; } } } glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); // cursors notextureshader->set(); renderentselection(player->o, camdir, entmoving!=0); boxoutline = outline!=0; enablepolygonoffset(GL_POLYGON_OFFSET_LINE); if(!moving && !hovering && !hidecursor) { if(hmapedit==1) gle::colorub(0, hmapsel ? 255 : 40, 0); else gle::colorub(120,120,120); boxs(orient, vec(lu), vec(lusize)); } // selections if(havesel || moving) { d = dimension(sel.orient); gle::colorub(50,50,50); // grid boxsgrid(sel.orient, vec(sel.o), vec(sel.s), sel.grid); gle::colorub(200,0,0); // 0 reference boxs3D(vec(sel.o).sub(0.5f*min(gridsize*0.25f, 2.0f)), vec(min(gridsize*0.25f, 2.0f)), 1); gle::colorub(200,200,200);// 2D selection box vec co(sel.o.v), cs(sel.s.v); co[R[d]] += 0.5f*(sel.cx*gridsize); co[C[d]] += 0.5f*(sel.cy*gridsize); cs[R[d]] = 0.5f*(sel.cxs*gridsize); cs[C[d]] = 0.5f*(sel.cys*gridsize); cs[D[d]] *= gridsize; boxs(sel.orient, co, cs); if(hmapedit==1) // 3D selection box gle::colorub(0,120,0); else gle::colorub(0,0,120); boxs3D(vec(sel.o), vec(sel.s), sel.grid); } disablepolygonoffset(GL_POLYGON_OFFSET_LINE); boxoutline = false; glDisable(GL_BLEND); } void tryedit() { extern int hidehud; if(!editmode || hidehud || mainmenu) return; if(blendpaintmode) trypaintblendmap(); } //////////// ready changes to vertex arrays //////////// static bool haschanged = false; void readychanges(const ivec &bbmin, const ivec &bbmax, cube *c, const ivec &cor, int size) { loopoctabox(cor, size, bbmin, bbmax) { ivec o(i, cor, size); if(c[i].ext) { if(c[i].ext->va) // removes va s so that octarender will recreate { int hasmerges = c[i].ext->va->hasmerges; destroyva(c[i].ext->va); c[i].ext->va = NULL; if(hasmerges) invalidatemerges(c[i], o, size, true); } freeoctaentities(c[i]); c[i].ext->tjoints = -1; } if(c[i].children) { if(size<=1) { solidfaces(c[i]); discardchildren(c[i], true); brightencube(c[i]); } else readychanges(bbmin, bbmax, c[i].children, o, size/2); } else brightencube(c[i]); } } void commitchanges(bool force) { if(!force && !haschanged) return; haschanged = false; int oldlen = valist.length(); resetclipplanes(); entitiesinoctanodes(); inbetweenframes = false; octarender(); inbetweenframes = true; setupmaterials(oldlen); invalidatepostfx(); updatevabbs(); resetblobs(); } void changed(const block3 &sel, bool commit = true) { if(sel.s.iszero()) return; readychanges(ivec(sel.o).sub(1), ivec(sel.s).mul(sel.grid).add(sel.o).add(1), worldroot, ivec(0, 0, 0), worldsize/2); haschanged = true; if(commit) commitchanges(); } //////////// copy and undo ///////////// static inline void copycube(const cube &src, cube &dst) { dst = src; dst.visible = 0; dst.merged = 0; dst.ext = NULL; // src cube is responsible for va destruction if(src.children) { dst.children = newcubes(F_EMPTY); loopi(8) copycube(src.children[i], dst.children[i]); } } static inline void pastecube(const cube &src, cube &dst) { discardchildren(dst); copycube(src, dst); } void blockcopy(const block3 &s, int rgrid, block3 *b) { *b = s; cube *q = b->c(); loopxyz(s, rgrid, copycube(c, *q++)); } block3 *blockcopy(const block3 &s, int rgrid) { int bsize = sizeof(block3)+sizeof(cube)*s.size(); if(bsize <= 0 || bsize > (100<<20)) return NULL; block3 *b = (block3 *)new (false) uchar[bsize]; if(b) blockcopy(s, rgrid, b); return b; } void freeblock(block3 *b, bool alloced = true) { cube *q = b->c(); loopi(b->size()) discardchildren(*q++); if(alloced) delete[] b; } void selgridmap(selinfo &sel, uchar *g) // generates a map of the cube sizes at each grid point { loopxyz(sel, -sel.grid, (*g++ = bitscan(lusize), (void)c)); } void freeundo(undoblock *u) { if(!u->numents) freeblock(u->block(), false); delete[] (uchar *)u; } void pasteundoblock(block3 *b, uchar *g) { cube *s = b->c(); loopxyz(*b, 1<<min(int(*g++), worldscale-1), pastecube(*s++, c)); } void pasteundo(undoblock *u) { if(u->numents) pasteundoents(u); else pasteundoblock(u->block(), u->gridmap()); } static inline int undosize(undoblock *u) { if(u->numents) return u->numents*sizeof(undoent); else { block3 *b = u->block(); cube *q = b->c(); int size = b->size(), total = size; loopj(size) total += familysize(*q++)*sizeof(cube); return total; } } struct undolist { undoblock *first, *last; undolist() : first(NULL), last(NULL) {} bool empty() { return !first; } void add(undoblock *u) { u->next = NULL; u->prev = last; if(!first) first = last = u; else { last->next = u; last = u; } } undoblock *popfirst() { undoblock *u = first; first = first->next; if(first) first->prev = NULL; else last = NULL; return u; } undoblock *poplast() { undoblock *u = last; last = last->prev; if(last) last->next = NULL; else first = NULL; return u; } }; undolist undos, redos; VARP(undomegs, 0, 5, 100); // bounded by n megs int totalundos = 0; void pruneundos(int maxremain) // bound memory { while(totalundos > maxremain && !undos.empty()) { undoblock *u = undos.popfirst(); totalundos -= u->size; freeundo(u); } //conoutf(CON_DEBUG, "undo: %d of %d(%%%d)", totalundos, undomegs<<20, totalundos*100/(undomegs<<20)); while(!redos.empty()) { undoblock *u = redos.popfirst(); totalundos -= u->size; freeundo(u); } } void clearundos() { pruneundos(0); } COMMAND(clearundos, ""); undoblock *newundocube(selinfo &s) { int ssize = s.size(), selgridsize = ssize, blocksize = sizeof(block3)+ssize*sizeof(cube); if(blocksize <= 0 || blocksize > (undomegs<<20)) return NULL; undoblock *u = (undoblock *)new (false) uchar[sizeof(undoblock) + blocksize + selgridsize]; if(!u) return NULL; u->numents = 0; block3 *b = u->block(); blockcopy(s, -s.grid, b); uchar *g = u->gridmap(); selgridmap(s, g); return u; } void addundo(undoblock *u) { u->size = undosize(u); u->timestamp = totalmillis; undos.add(u); totalundos += u->size; pruneundos(undomegs<<20); } VARP(nompedit, 0, 1, 1); void makeundo(selinfo &s) { #ifdef OLDPROTO if(nompedit && multiplayer(false)) return; #endif undoblock *u = newundocube(s); if(u) addundo(u); } void makeundo() // stores state of selected cubes before editing { if(lastsel==sel || sel.s.iszero()) return; lastsel=sel; makeundo(sel); } static inline int countblock(cube *c, int n = 8) { int r = n; loopi(n) if(c[i].children) r += countblock(c[i].children); return r; } static int countblock(block3 *b) { return countblock(b->c(), b->size()); } void swapundo(undolist &a, undolist &b, int op) { #ifndef OLDPROTO if(noedit()) return; #else if(noedit() || (nompedit && multiplayer())) return; #endif if(a.empty()) { conoutf(CON_WARN, "nothing more to %s", op == EDIT_REDO ? "redo" : "undo"); return; } int ts = a.last->timestamp; if(multiplayer(false)) { int n = 0, ops = 0; for(undoblock *u = a.last; u && ts==u->timestamp; u = u->prev) { ++ops; n += u->numents ? u->numents : countblock(u->block()); if(ops > 10 || n > 500) { if(nompedit) { multiplayer(); return; } op = -1; break; } } } selinfo l = sel; while(!a.empty() && ts==a.last->timestamp) { if(op >= 0) game::edittrigger(sel, op); undoblock *u = a.poplast(), *r; if(u->numents) r = copyundoents(u); else { block3 *ub = u->block(); l.o = ub->o; l.s = ub->s; l.grid = ub->grid; l.orient = ub->orient; r = newundocube(l); } if(r) { r->size = u->size; r->timestamp = totalmillis; b.add(r); } pasteundo(u); if(!u->numents) changed(*u->block(), false); freeundo(u); } commitchanges(); if(!hmapsel) { sel = l; reorient(); } forcenextundo(); } void editundo() { swapundo(undos, redos, EDIT_UNDO); } void editredo() { swapundo(redos, undos, EDIT_REDO); } // guard against subdivision #define protectsel(f) { undoblock *_u = newundocube(sel); f; if(_u) { pasteundo(_u); freeundo(_u); } } vector<editinfo *> editinfos; editinfo *localedit = NULL; template<class B> static void packcube(cube &c, B &buf) { if(c.children) { buf.put(0xFF); loopi(8) packcube(c.children[i], buf); } else { cube data = c; lilswap(data.texture, 6); buf.put(c.material&0xFF); buf.put(c.material>>8); buf.put(data.edges, sizeof(data.edges)); buf.put((uchar *)data.texture, sizeof(data.texture)); } } template<class B> static bool packblock(block3 &b, B &buf) { if(b.size() <= 0 || b.size() > (1<<20)) return false; block3 hdr = b; lilswap(hdr.o.v, 3); lilswap(hdr.s.v, 3); lilswap(&hdr.grid, 1); lilswap(&hdr.orient, 1); buf.put((const uchar *)&hdr, sizeof(hdr)); cube *c = b.c(); loopi(b.size()) packcube(c[i], buf); return true; } struct vslothdr { ushort index; ushort slot; }; static void packvslots(cube &c, vector<uchar> &buf, vector<ushort> &used) { if(c.children) { loopi(8) packvslots(c.children[i], buf, used); } else loopi(6) { ushort index = c.texture[i]; if(vslots.inrange(index) && vslots[index]->changed && used.find(index) < 0) { used.add(index); VSlot &vs = *vslots[index]; vslothdr &hdr = *(vslothdr *)buf.pad(sizeof(vslothdr)); hdr.index = index; hdr.slot = vs.slot->index; lilswap(&hdr.index, 2); packvslot(buf, vs); } } } static void packvslots(block3 &b, vector<uchar> &buf) { vector<ushort> used; cube *c = b.c(); loopi(b.size()) packvslots(c[i], buf, used); memset(buf.pad(sizeof(vslothdr)), 0, sizeof(vslothdr)); } template<class B> static void unpackcube(cube &c, B &buf) { int mat = buf.get(); if(mat == 0xFF) { c.children = newcubes(F_EMPTY); loopi(8) unpackcube(c.children[i], buf); } else { c.material = mat | (buf.get()<<8); buf.get(c.edges, sizeof(c.edges)); buf.get((uchar *)c.texture, sizeof(c.texture)); lilswap(c.texture, 6); } } template<class B> static bool unpackblock(block3 *&b, B &buf) { if(b) { freeblock(b); b = NULL; } block3 hdr; if(buf.get((uchar *)&hdr, sizeof(hdr)) < int(sizeof(hdr))) return false; lilswap(hdr.o.v, 3); lilswap(hdr.s.v, 3); lilswap(&hdr.grid, 1); lilswap(&hdr.orient, 1); if(hdr.size() > (1<<20) || hdr.grid <= 0 || hdr.grid > (1<<12)) return false; b = (block3 *)new (false) uchar[sizeof(block3)+hdr.size()*sizeof(cube)]; if(!b) return false; *b = hdr; cube *c = b->c(); memset(c, 0, b->size()*sizeof(cube)); loopi(b->size()) unpackcube(c[i], buf); return true; } struct vslotmap { int index; VSlot *vslot; vslotmap() {} vslotmap(int index, VSlot *vslot) : index(index), vslot(vslot) {} }; static vector<vslotmap> unpackingvslots; static void unpackvslots(cube &c, ucharbuf &buf) { if(c.children) { loopi(8) unpackvslots(c.children[i], buf); } else loopi(6) { ushort tex = c.texture[i]; loopvj(unpackingvslots) if(unpackingvslots[j].index == tex) { c.texture[i] = unpackingvslots[j].vslot->index; break; } } } static void unpackvslots(block3 &b, ucharbuf &buf) { while(buf.remaining() >= int(sizeof(vslothdr))) { vslothdr &hdr = *(vslothdr *)buf.pad(sizeof(vslothdr)); lilswap(&hdr.index, 2); if(!hdr.index) break; VSlot &vs = *lookupslot(hdr.slot, false).variants; VSlot ds; if(!unpackvslot(buf, ds, false)) break; if(vs.index < 0 || vs.index == DEFAULT_SKY) continue; VSlot *edit = editvslot(vs, ds); unpackingvslots.add(vslotmap(hdr.index, edit ? edit : &vs)); } cube *c = b.c(); loopi(b.size()) unpackvslots(c[i], buf); unpackingvslots.setsize(0); } static bool compresseditinfo(const uchar *inbuf, int inlen, uchar *&outbuf, int &outlen) { uLongf len = compressBound(inlen); if(len > (1<<20)) return false; outbuf = new (false) uchar[len]; if(!outbuf || compress2((Bytef *)outbuf, &len, (const Bytef *)inbuf, inlen, Z_BEST_COMPRESSION) != Z_OK || len > (1<<16)) { delete[] outbuf; outbuf = NULL; return false; } outlen = len; return true; } static bool uncompresseditinfo(const uchar *inbuf, int inlen, uchar *&outbuf, int &outlen) { if(compressBound(outlen) > (1<<20)) return false; uLongf len = outlen; outbuf = new (false) uchar[len]; if(!outbuf || uncompress((Bytef *)outbuf, &len, (const Bytef *)inbuf, inlen) != Z_OK) { delete[] outbuf; outbuf = NULL; return false; } outlen = len; return true; } bool packeditinfo(editinfo *e, int &inlen, uchar *&outbuf, int &outlen) { vector<uchar> buf; if(!e || !e->copy || !packblock(*e->copy, buf)) return false; packvslots(*e->copy, buf); inlen = buf.length(); return compresseditinfo(buf.getbuf(), buf.length(), outbuf, outlen); } bool unpackeditinfo(editinfo *&e, const uchar *inbuf, int inlen, int outlen) { if(e && e->copy) { freeblock(e->copy); e->copy = NULL; } uchar *outbuf = NULL; if(!uncompresseditinfo(inbuf, inlen, outbuf, outlen)) return false; ucharbuf buf(outbuf, outlen); if(!e) e = editinfos.add(new editinfo); if(!unpackblock(e->copy, buf)) { delete[] outbuf; return false; } unpackvslots(*e->copy, buf); delete[] outbuf; return true; } void freeeditinfo(editinfo *&e) { if(!e) return; editinfos.removeobj(e); if(e->copy) freeblock(e->copy); delete e; e = NULL; } bool packundo(undoblock *u, int &inlen, uchar *&outbuf, int &outlen) { vector<uchar> buf; buf.reserve(512); *(ushort *)buf.pad(2) = lilswap(ushort(u->numents)); if(u->numents) { undoent *ue = u->ents(); loopi(u->numents) { *(ushort *)buf.pad(2) = lilswap(ushort(ue[i].i)); entity &e = *(entity *)buf.pad(sizeof(entity)); e = ue[i].e; lilswap(&e.o.x, 3); lilswap(&e.attr1, 5); } } else { block3 &b = *u->block(); if(!packblock(b, buf)) return false; buf.put(u->gridmap(), b.size()); packvslots(b, buf); } inlen = buf.length(); return compresseditinfo(buf.getbuf(), buf.length(), outbuf, outlen); } bool unpackundo(const uchar *inbuf, int inlen, int outlen) { uchar *outbuf = NULL; if(!uncompresseditinfo(inbuf, inlen, outbuf, outlen)) return false; ucharbuf buf(outbuf, outlen); if(buf.remaining() < 2) { delete[] outbuf; return false; } int numents = lilswap(*(const ushort *)buf.pad(2)); if(numents) { if(buf.remaining() < numents*int(2 + sizeof(entity))) { delete[] outbuf; return false; } loopi(numents) { int idx = lilswap(*(const ushort *)buf.pad(2)); entity &e = *(entity *)buf.pad(sizeof(entity)); lilswap(&e.o.x, 3); lilswap(&e.attr1, 5); pasteundoent(idx, e); } } else { block3 *b = NULL; if(!unpackblock(b, buf) || b->grid >= worldsize || buf.remaining() < b->size()) { freeblock(b); delete[] outbuf; return false; } uchar *g = buf.pad(b->size()); unpackvslots(*b, buf); pasteundoblock(b, g); changed(*b, false); freeblock(b); } delete[] outbuf; commitchanges(); return true; } bool packundo(int op, int &inlen, uchar *&outbuf, int &outlen) { switch(op) { case EDIT_UNDO: return !undos.empty() && packundo(undos.last, inlen, outbuf, outlen); case EDIT_REDO: return !redos.empty() && packundo(redos.last, inlen, outbuf, outlen); default: return false; } } struct prefabheader { char magic[4]; int version; }; struct prefab : editinfo { char *name; GLuint ebo, vbo; int numtris, numverts; prefab() : name(NULL), ebo(0), vbo(0), numtris(0), numverts(0) {} ~prefab() { DELETEA(name); if(copy) freeblock(copy); } void cleanup() { if(ebo) { glDeleteBuffers_(1, &ebo); ebo = 0; } if(vbo) { glDeleteBuffers_(1, &vbo); vbo = 0; } numtris = numverts = 0; } }; static hashnameset<prefab> prefabs; void cleanupprefabs() { enumerate(prefabs, prefab, p, p.cleanup()); } void delprefab(char *name) { prefab *p = prefabs.access(name); if(p) { p->cleanup(); prefabs.remove(name); conoutf("deleted prefab %s", name); } } COMMAND(delprefab, "s"); void saveprefab(char *name) { if(!name[0] || noedit(true) || (nompedit && multiplayer())) return; prefab *b = prefabs.access(name); if(!b) { b = &prefabs[name]; b->name = newstring(name); } if(b->copy) freeblock(b->copy); protectsel(b->copy = blockcopy(block3(sel), sel.grid)); changed(sel); defformatstring(filename, strpbrk(name, "/\\") ? "packages/%s.obr" : "packages/prefab/%s.obr", name); path(filename); stream *f = opengzfile(filename, "wb"); if(!f) { conoutf(CON_ERROR, "could not write prefab to %s", filename); return; } prefabheader hdr; memcpy(hdr.magic, "OEBR", 4); hdr.version = 0; lilswap(&hdr.version, 1); f->write(&hdr, sizeof(hdr)); streambuf<uchar> s(f); if(!packblock(*b->copy, s)) { delete f; conoutf(CON_ERROR, "could not pack prefab %s", filename); return; } delete f; conoutf("wrote prefab file %s", filename); } COMMAND(saveprefab, "s"); void pasteblock(block3 &b, selinfo &sel, bool local) { sel.s = b.s; int o = sel.orient; sel.orient = b.orient; cube *s = b.c(); loopselxyz(if(!isempty(*s) || s->children || s->material != MAT_AIR) pastecube(*s, c); s++); // 'transparent'. old opaque by 'delcube; paste' sel.orient = o; } prefab *loadprefab(const char *name, bool msg = true) { prefab *b = prefabs.access(name); if(b) return b; defformatstring(filename, strpbrk(name, "/\\") ? "packages/%s.obr" : "packages/prefab/%s.obr", name); path(filename); stream *f = opengzfile(filename, "rb"); if(!f) { if(msg) conoutf(CON_ERROR, "could not read prefab %s", filename); return NULL; } prefabheader hdr; if(f->read(&hdr, sizeof(hdr)) != sizeof(prefabheader) || memcmp(hdr.magic, "OEBR", 4)) { delete f; if(msg) conoutf(CON_ERROR, "prefab %s has malformatted header", filename); return NULL; } lilswap(&hdr.version, 1); if(hdr.version != 0) { delete f; if(msg) conoutf(CON_ERROR, "prefab %s uses unsupported version", filename); return NULL; } streambuf<uchar> s(f); block3 *copy = NULL; if(!unpackblock(copy, s)) { delete f; if(msg) conoutf(CON_ERROR, "could not unpack prefab %s", filename); return NULL; } delete f; b = &prefabs[name]; b->name = newstring(name); b->copy = copy; return b; } void pasteprefab(char *name) { if(!name[0] || noedit() || (nompedit && multiplayer())) return; prefab *b = loadprefab(name, true); if(b) pasteblock(*b->copy, sel, true); } COMMAND(pasteprefab, "s"); struct prefabmesh { struct vertex { vec pos; bvec4 norm; }; static const int SIZE = 1<<9; int table[SIZE]; vector<vertex> verts; vector<int> chain; vector<ushort> tris; prefabmesh() { memset(table, -1, sizeof(table)); } int addvert(const vertex &v) { uint h = hthash(v.pos)&(SIZE-1); for(int i = table[h]; i>=0; i = chain[i]) { const vertex &c = verts[i]; if(c.pos==v.pos && c.norm==v.norm) return i; } if(verts.length() >= USHRT_MAX) return -1; verts.add(v); chain.add(table[h]); return table[h] = verts.length()-1; } int addvert(const vec &pos, const bvec &norm) { vertex vtx; vtx.pos = pos; vtx.norm = norm; return addvert(vtx); } void setup(prefab &p) { if(tris.empty()) return; p.cleanup(); loopv(verts) verts[i].norm.flip(); if(!p.vbo) glGenBuffers_(1, &p.vbo); gle::bindvbo(p.vbo); glBufferData_(GL_ARRAY_BUFFER, verts.length()*sizeof(vertex), verts.getbuf(), GL_STATIC_DRAW); gle::clearvbo(); p.numverts = verts.length(); if(!p.ebo) glGenBuffers_(1, &p.ebo); gle::bindebo(p.ebo); glBufferData_(GL_ELEMENT_ARRAY_BUFFER, tris.length()*sizeof(ushort), tris.getbuf(), GL_STATIC_DRAW); gle::clearebo(); p.numtris = tris.length()/3; } }; static void genprefabmesh(prefabmesh &r, cube &c, const ivec &co, int size) { if(c.children) { neighbourstack[++neighbourdepth] = c.children; loopi(8) { ivec o(i, co, size/2); genprefabmesh(r, c.children[i], o, size/2); } --neighbourdepth; } else if(!isempty(c)) { int vis; loopi(6) if((vis = visibletris(c, i, co, size))) { ivec v[4]; genfaceverts(c, i, v); int convex = 0; if(!flataxisface(c, i)) convex = faceconvexity(v); int order = vis&4 || convex < 0 ? 1 : 0, numverts = 0; vec vo(co), pos[4], norm[4]; pos[numverts++] = vec(v[order]).mul(size/8.0f).add(vo); if(vis&1) pos[numverts++] = vec(v[order+1]).mul(size/8.0f).add(vo); pos[numverts++] = vec(v[order+2]).mul(size/8.0f).add(vo); if(vis&2) pos[numverts++] = vec(v[(order+3)&3]).mul(size/8.0f).add(vo); guessnormals(pos, numverts, norm); int index[4]; loopj(numverts) index[j] = r.addvert(pos[j], bvec(norm[j])); loopj(numverts-2) if(index[0]!=index[j+1] && index[j+1]!=index[j+2] && index[j+2]!=index[0]) { r.tris.add(index[0]); r.tris.add(index[j+1]); r.tris.add(index[j+2]); } } } } void genprefabmesh(prefab &p) { block3 b = *p.copy; b.o = ivec(0, 0, 0); cube *oldworldroot = worldroot; int oldworldscale = worldscale, oldworldsize = worldsize; worldroot = newcubes(); worldscale = 1; worldsize = 2; while(worldsize < max(max(b.s.x, b.s.y), b.s.z)*b.grid) { worldscale++; worldsize *= 2; } cube *s = p.copy->c(); loopxyz(b, b.grid, if(!isempty(*s) || s->children) pastecube(*s, c); s++); prefabmesh r; neighbourstack[++neighbourdepth] = worldroot; loopi(8) genprefabmesh(r, worldroot[i], ivec(i, ivec(0, 0, 0), worldsize/2), worldsize/2); --neighbourdepth; r.setup(p); freeocta(worldroot); worldroot = oldworldroot; worldscale = oldworldscale; worldsize = oldworldsize; useshaderbyname("prefab"); } extern int outlinecolour; static void renderprefab(prefab &p, const vec &o, float yaw, float pitch, float roll, float size, const vec &color) { if(!p.numtris) { genprefabmesh(p); if(!p.numtris) return; } block3 &b = *p.copy; matrix4 m; m.identity(); m.settranslation(o); if(yaw) m.rotate_around_z(yaw*RAD); if(pitch) m.rotate_around_x(pitch*RAD); if(roll) m.rotate_around_y(-roll*RAD); matrix3 w(m); if(size > 0 && size != 1) m.scale(size); m.translate(vec(b.s).mul(-b.grid*0.5f)); gle::bindvbo(p.vbo); gle::bindebo(p.ebo); gle::enablevertex(); gle::enablenormal(); prefabmesh::vertex *v = (prefabmesh::vertex *)0; gle::vertexpointer(sizeof(prefabmesh::vertex), v->pos.v); gle::normalpointer(sizeof(prefabmesh::vertex), v->norm.v, GL_BYTE); matrix4 pm; pm.mul(camprojmatrix, m); GLOBALPARAM(prefabmatrix, pm); GLOBALPARAM(prefabworld, w); SETSHADER(prefab); gle::color(color); glDrawRangeElements_(GL_TRIANGLES, 0, p.numverts-1, p.numtris*3, GL_UNSIGNED_SHORT, (ushort *)0); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); enablepolygonoffset(GL_POLYGON_OFFSET_LINE); pm.mul(camprojmatrix, m); GLOBALPARAM(prefabmatrix, pm); SETSHADER(prefab); gle::color(vec::hexcolor(outlinecolour)); glDrawRangeElements_(GL_TRIANGLES, 0, p.numverts-1, p.numtris*3, GL_UNSIGNED_SHORT, (ushort *)0); disablepolygonoffset(GL_POLYGON_OFFSET_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); gle::disablevertex(); gle::disablenormal(); gle::clearebo(); gle::clearvbo(); } void renderprefab(const char *name, const vec &o, float yaw, float pitch, float roll, float size, const vec &color) { prefab *p = loadprefab(name, false); if(p) renderprefab(*p, o, yaw, pitch, roll, size, color); } void previewprefab(const char *name, const vec &color) { prefab *p = loadprefab(name, false); if(p) { block3 &b = *p->copy; float yaw; vec o = calcmodelpreviewpos(vec(b.s).mul(b.grid*0.5f), yaw); renderprefab(*p, o, yaw, 0, 0, 1, color); } } void mpcopy(editinfo *&e, selinfo &sel, bool local) { if(local) game::edittrigger(sel, EDIT_COPY); if(e==NULL) e = editinfos.add(new editinfo); if(e->copy) freeblock(e->copy); e->copy = NULL; protectsel(e->copy = blockcopy(block3(sel), sel.grid)); changed(sel); } void mppaste(editinfo *&e, selinfo &sel, bool local) { if(e==NULL) return; if(local) game::edittrigger(sel, EDIT_PASTE); if(e->copy) pasteblock(*e->copy, sel, local); } void copy() { if(noedit(true)) return; mpcopy(localedit, sel, true); } void pastehilite() { if(!localedit) return; sel.s = localedit->copy->s; reorient(); havesel = true; } void paste() { if(noedit()) return; mppaste(localedit, sel, true); } COMMAND(copy, ""); COMMAND(pastehilite, ""); COMMAND(paste, ""); COMMANDN(undo, editundo, ""); COMMANDN(redo, editredo, ""); static vector<int *> editingvslots; struct vslotref { vslotref(int &index) { editingvslots.add(&index); } ~vslotref() { editingvslots.pop(); } }; #define editingvslot(...) vslotref vslotrefs[] = { __VA_ARGS__ }; (void)vslotrefs; void compacteditvslots() { loopv(editingvslots) if(*editingvslots[i]) compactvslot(*editingvslots[i]); loopv(unpackingvslots) compactvslot(*unpackingvslots[i].vslot); loopv(editinfos) { editinfo *e = editinfos[i]; compactvslots(e->copy->c(), e->copy->size()); } for(undoblock *u = undos.first; u; u = u->next) if(!u->numents) compactvslots(u->block()->c(), u->block()->size()); for(undoblock *u = redos.first; u; u = u->next) if(!u->numents) compactvslots(u->block()->c(), u->block()->size()); } ///////////// height maps //////////////// #define MAXBRUSH 64 #define MAXBRUSHC 63 #define MAXBRUSH2 32 int brush[MAXBRUSH][MAXBRUSH]; VAR(brushx, 0, MAXBRUSH2, MAXBRUSH); VAR(brushy, 0, MAXBRUSH2, MAXBRUSH); bool paintbrush = 0; int brushmaxx = 0, brushminx = MAXBRUSH; int brushmaxy = 0, brushminy = MAXBRUSH; void clearbrush() { memset(brush, 0, sizeof brush); brushmaxx = brushmaxy = 0; brushminx = brushminy = MAXBRUSH; paintbrush = false; } void brushvert(int *x, int *y, int *v) { *x += MAXBRUSH2 - brushx + 1; // +1 for automatic padding *y += MAXBRUSH2 - brushy + 1; if(*x<0 || *y<0 || *x>=MAXBRUSH || *y>=MAXBRUSH) return; brush[*x][*y] = clamp(*v, 0, 8); paintbrush = paintbrush || (brush[*x][*y] > 0); brushmaxx = min(MAXBRUSH-1, max(brushmaxx, *x+1)); brushmaxy = min(MAXBRUSH-1, max(brushmaxy, *y+1)); brushminx = max(0, min(brushminx, *x-1)); brushminy = max(0, min(brushminy, *y-1)); } vector<int> htextures; COMMAND(clearbrush, ""); COMMAND(brushvert, "iii"); void hmapcancel() { htextures.setsize(0); } COMMAND(hmapcancel, ""); ICOMMAND(hmapselect, "", (), int t = lookupcube(cur).texture[orient]; int i = htextures.find(t); if(i<0) htextures.add(t); else htextures.remove(i); ); inline bool isheightmap(int o, int d, bool empty, cube *c) { return havesel || (empty && isempty(*c)) || htextures.empty() || htextures.find(c->texture[o]) >= 0; } namespace hmap { # define PAINTED 1 # define NOTHMAP 2 # define MAPPED 16 uchar flags[MAXBRUSH][MAXBRUSH]; cube *cmap[MAXBRUSHC][MAXBRUSHC][4]; int mapz[MAXBRUSHC][MAXBRUSHC]; int map [MAXBRUSH][MAXBRUSH]; selinfo changes; bool selecting; int d, dc, dr, dcr, biasup, br, hws, fg; int gx, gy, gz, mx, my, mz, nx, ny, nz, bmx, bmy, bnx, bny; uint fs; selinfo hundo; cube *getcube(ivec t, int f) { t[d] += dcr*f*gridsize; if(t[d] > nz || t[d] < mz) return NULL; cube *c = &lookupcube(t, gridsize); if(c->children) forcemip(*c, false); discardchildren(*c, true); if(!isheightmap(sel.orient, d, true, c)) return NULL; if (t.x < changes.o.x) changes.o.x = t.x; else if(t.x > changes.s.x) changes.s.x = t.x; if (t.y < changes.o.y) changes.o.y = t.y; else if(t.y > changes.s.y) changes.s.y = t.y; if (t.z < changes.o.z) changes.o.z = t.z; else if(t.z > changes.s.z) changes.s.z = t.z; return c; } uint getface(cube *c, int d) { return 0x0f0f0f0f & ((dc ? c->faces[d] : 0x88888888 - c->faces[d]) >> fs); } void pushside(cube &c, int d, int x, int y, int z) { ivec a; getcubevector(c, d, x, y, z, a); a[R[d]] = 8 - a[R[d]]; setcubevector(c, d, x, y, z, a); } void addpoint(int x, int y, int z, int v) { if(!(flags[x][y] & MAPPED)) map[x][y] = v + (z*8); flags[x][y] |= MAPPED; } void select(int x, int y, int z) { if((NOTHMAP & flags[x][y]) || (PAINTED & flags[x][y])) return; ivec t(d, x+gx, y+gy, dc ? z : hws-z); t.shl(gridpower); // selections may damage; must makeundo before hundo.o = t; hundo.o[D[d]] -= dcr*gridsize*2; makeundo(hundo); cube **c = cmap[x][y]; loopk(4) c[k] = NULL; c[1] = getcube(t, 0); if(!c[1] || !isempty(*c[1])) { // try up c[2] = c[1]; c[1] = getcube(t, 1); if(!c[1] || isempty(*c[1])) { c[0] = c[1]; c[1] = c[2]; c[2] = NULL; } else { z++; t[d]+=fg; } } else // drop down { z--; t[d]-= fg; c[0] = c[1]; c[1] = getcube(t, 0); } if(!c[1] || isempty(*c[1])) { flags[x][y] |= NOTHMAP; return; } flags[x][y] |= PAINTED; mapz [x][y] = z; if(!c[0]) c[0] = getcube(t, 1); if(!c[2]) c[2] = getcube(t, -1); c[3] = getcube(t, -2); c[2] = !c[2] || isempty(*c[2]) ? NULL : c[2]; c[3] = !c[3] || isempty(*c[3]) ? NULL : c[3]; uint face = getface(c[1], d); if(face == 0x08080808 && (!c[0] || !isempty(*c[0]))) { flags[x][y] |= NOTHMAP; return; } if(c[1]->faces[R[d]] == F_SOLID) // was single face += 0x08080808; else // was pair face += c[2] ? getface(c[2], d) : 0x08080808; face += 0x08080808; // c[3] uchar *f = (uchar*)&face; addpoint(x, y, z, f[0]); addpoint(x+1, y, z, f[1]); addpoint(x, y+1, z, f[2]); addpoint(x+1, y+1, z, f[3]); if(selecting) // continue to adjacent cubes { if(x>bmx) select(x-1, y, z); if(x<bnx) select(x+1, y, z); if(y>bmy) select(x, y-1, z); if(y<bny) select(x, y+1, z); } } void ripple(int x, int y, int z, bool force) { if(force) select(x, y, z); if((NOTHMAP & flags[x][y]) || !(PAINTED & flags[x][y])) return; bool changed = false; int *o[4], best, par, q = 0; loopi(2) loopj(2) o[i+j*2] = &map[x+i][y+j]; #define pullhmap(I, LT, GT, M, N, A) do { \ best = I; \ loopi(4) if(*o[i] LT best) best = *o[q = i] - M; \ par = (best&(~7)) + N; \ /* dual layer for extra smoothness */ \ if(*o[q^3] GT par && !(*o[q^1] LT par || *o[q^2] LT par)) { \ if(*o[q^3] GT par A 8 || *o[q^1] != par || *o[q^2] != par) { \ *o[q^3] = (*o[q^3] GT par A 8 ? par A 8 : *o[q^3]); \ *o[q^1] = *o[q^2] = par; \ changed = true; \ } \ /* single layer */ \ } else { \ loopj(4) if(*o[j] GT par) { \ *o[j] = par; \ changed = true; \ } \ } \ } while(0) if(biasup) pullhmap(0, >, <, 1, 0, -); else pullhmap(worldsize*8, <, >, 0, 8, +); cube **c = cmap[x][y]; int e[2][2]; int notempty = 0; loopk(4) if(c[k]) { loopi(2) loopj(2) { e[i][j] = min(8, map[x+i][y+j] - (mapz[x][y]+3-k)*8); notempty |= e[i][j] > 0; } if(notempty) { c[k]->texture[sel.orient] = c[1]->texture[sel.orient]; solidfaces(*c[k]); loopi(2) loopj(2) { int f = e[i][j]; if(f<0 || (f==0 && e[1-i][j]==0 && e[i][1-j]==0)) { f=0; pushside(*c[k], d, i, j, 0); pushside(*c[k], d, i, j, 1); } edgeset(cubeedge(*c[k], d, i, j), dc, dc ? f : 8-f); } } else emptyfaces(*c[k]); } if(!changed) return; if(x>mx) ripple(x-1, y, mapz[x][y], true); if(x<nx) ripple(x+1, y, mapz[x][y], true); if(y>my) ripple(x, y-1, mapz[x][y], true); if(y<ny) ripple(x, y+1, mapz[x][y], true); #define DIAGONAL_RIPPLE(a,b,exp) if(exp) { \ if(flags[x a][ y] & PAINTED) \ ripple(x a, y b, mapz[x a][y], true); \ else if(flags[x][y b] & PAINTED) \ ripple(x a, y b, mapz[x][y b], true); \ } DIAGONAL_RIPPLE(-1, -1, (x>mx && y>my)); // do diagonals because adjacents DIAGONAL_RIPPLE(-1, +1, (x>mx && y<ny)); // won't unless changed DIAGONAL_RIPPLE(+1, +1, (x<nx && y<ny)); DIAGONAL_RIPPLE(+1, -1, (x<nx && y>my)); } #define loopbrush(i) for(int x=bmx; x<=bnx+i; x++) for(int y=bmy; y<=bny+i; y++) void paint() { loopbrush(1) map[x][y] -= dr * brush[x][y]; } void smooth() { int sum, div; loopbrush(-2) { sum = 0; div = 9; loopi(3) loopj(3) if(flags[x+i][y+j] & MAPPED) sum += map[x+i][y+j]; else div--; if(div) map[x+1][y+1] = sum / div; } } void rippleandset() { loopbrush(0) ripple(x, y, gz, false); } void run(int dir, int mode) { d = dimension(sel.orient); dc = dimcoord(sel.orient); dcr= dc ? 1 : -1; dr = dir>0 ? 1 : -1; br = dir>0 ? 0x08080808 : 0; // biasup = mode == dir<0; biasup = dir<0; bool paintme = paintbrush; int cx = (sel.corner&1 ? 0 : -1); int cy = (sel.corner&2 ? 0 : -1); hws= (worldsize>>gridpower); gx = (cur[R[d]] >> gridpower) + cx - MAXBRUSH2; gy = (cur[C[d]] >> gridpower) + cy - MAXBRUSH2; gz = (cur[D[d]] >> gridpower); fs = dc ? 4 : 0; fg = dc ? gridsize : -gridsize; mx = max(0, -gx); // ripple range my = max(0, -gy); nx = min(MAXBRUSH-1, hws-gx) - 1; ny = min(MAXBRUSH-1, hws-gy) - 1; if(havesel) { // selection range bmx = mx = max(mx, (sel.o[R[d]]>>gridpower)-gx); bmy = my = max(my, (sel.o[C[d]]>>gridpower)-gy); bnx = nx = min(nx, (sel.s[R[d]]+(sel.o[R[d]]>>gridpower))-gx-1); bny = ny = min(ny, (sel.s[C[d]]+(sel.o[C[d]]>>gridpower))-gy-1); } if(havesel && mode<0) // -ve means smooth selection paintme = false; else { // brush range bmx = max(mx, brushminx); bmy = max(my, brushminy); bnx = min(nx, brushmaxx-1); bny = min(ny, brushmaxy-1); } nz = worldsize-gridsize; mz = 0; hundo.s = ivec(d,1,1,5); hundo.orient = sel.orient; hundo.grid = gridsize; forcenextundo(); changes.grid = gridsize; changes.s = changes.o = cur; memset(map, 0, sizeof map); memset(flags, 0, sizeof flags); selecting = true; select(clamp(MAXBRUSH2-cx, bmx, bnx), clamp(MAXBRUSH2-cy, bmy, bny), dc ? gz : hws - gz); selecting = false; if(paintme) paint(); else smooth(); rippleandset(); // pull up points to cubify, and set changes.s.sub(changes.o).shr(gridpower).add(1); changed(changes); } } void edithmap(int dir, int mode) { if((nompedit && multiplayer()) || !hmapsel) return; hmap::run(dir, mode); } ///////////// main cube edit //////////////// int bounded(int n) { return n<0 ? 0 : (n>8 ? 8 : n); } void pushedge(uchar &edge, int dir, int dc) { int ne = bounded(edgeget(edge, dc)+dir); edgeset(edge, dc, ne); int oe = edgeget(edge, 1-dc); if((dir<0 && dc && oe>ne) || (dir>0 && dc==0 && oe<ne)) edgeset(edge, 1-dc, ne); } void linkedpush(cube &c, int d, int x, int y, int dc, int dir) { ivec v, p; getcubevector(c, d, x, y, dc, v); loopi(2) loopj(2) { getcubevector(c, d, i, j, dc, p); if(v==p) pushedge(cubeedge(c, d, i, j), dir, dc); } } static ushort getmaterial(cube &c) { if(c.children) { ushort mat = getmaterial(c.children[7]); loopi(7) if(mat != getmaterial(c.children[i])) return MAT_AIR; return mat; } return c.material; } VAR(invalidcubeguard, 0, 1, 1); void mpeditface(int dir, int mode, selinfo &sel, bool local) { if(mode==1 && (sel.cx || sel.cy || sel.cxs&1 || sel.cys&1)) mode = 0; int d = dimension(sel.orient); int dc = dimcoord(sel.orient); int seldir = dc ? -dir : dir; if(local) game::edittrigger(sel, EDIT_FACE, dir, mode); if(mode==1) { int h = sel.o[d]+dc*sel.grid; if(((dir>0) == dc && h<=0) || ((dir<0) == dc && h>=worldsize)) return; if(dir<0) sel.o[d] += sel.grid * seldir; } if(dc) sel.o[d] += sel.us(d)-sel.grid; sel.s[d] = 1; loopselxyz( if(c.children) solidfaces(c); ushort mat = getmaterial(c); discardchildren(c, true); c.material = mat; if(mode==1) // fill command { if(dir<0) { solidfaces(c); cube &o = blockcube(x, y, 1, sel, -sel.grid); loopi(6) c.texture[i] = o.children ? DEFAULT_GEOM : o.texture[i]; } else emptyfaces(c); } else { uint bak = c.faces[d]; uchar *p = (uchar *)&c.faces[d]; if(mode==2) linkedpush(c, d, sel.corner&1, sel.corner>>1, dc, seldir); // corner command else { loop(mx,2) loop(my,2) // pull/push edges command { if(x==0 && mx==0 && sel.cx) continue; if(y==0 && my==0 && sel.cy) continue; if(x==sel.s[R[d]]-1 && mx==1 && (sel.cx+sel.cxs)&1) continue; if(y==sel.s[C[d]]-1 && my==1 && (sel.cy+sel.cys)&1) continue; if(p[mx+my*2] != ((uchar *)&bak)[mx+my*2]) continue; linkedpush(c, d, mx, my, dc, seldir); } } optiface(p, c); if(invalidcubeguard==1 && !isvalidcube(c)) { uint newbak = c.faces[d]; uchar *m = (uchar *)&bak; uchar *n = (uchar *)&newbak; loopk(4) if(n[k] != m[k]) // tries to find partial edit that is valid { c.faces[d] = bak; c.edges[d*4+k] = n[k]; if(isvalidcube(c)) m[k] = n[k]; } c.faces[d] = bak; } } ); if (mode==1 && dir>0) sel.o[d] += sel.grid * seldir; } void editface(int *dir, int *mode) { if(noedit(moving!=0)) return; if(hmapedit!=1) mpeditface(*dir, *mode, sel, true); else edithmap(*dir, *mode); } VAR(selectionsurf, 0, 0, 1); void pushsel(int *dir) { if(noedit(moving!=0)) return; int d = dimension(orient); int s = dimcoord(orient) ? -*dir : *dir; sel.o[d] += s*sel.grid; if(selectionsurf==1) { player->o[d] += s*sel.grid; player->resetinterp(); } } void mpdelcube(selinfo &sel, bool local) { if(local) game::edittrigger(sel, EDIT_DELCUBE); loopselxyz(discardchildren(c, true); emptyfaces(c)); } void delcube() { if(noedit()) return; mpdelcube(sel, true); } COMMAND(pushsel, "i"); COMMAND(editface, "ii"); COMMAND(delcube, ""); /////////// texture editing ////////////////// int curtexindex = -1, lasttex = 0, lasttexmillis = -1; int texpaneltimer = 0; vector<ushort> texmru; void tofronttex() // maintain most recently used of the texture lists when applying texture { int c = curtexindex; if(texmru.inrange(c)) { texmru.insert(0, texmru.remove(c)); curtexindex = -1; } } selinfo repsel; int reptex = -1; static vector<vslotmap> remappedvslots; VAR(usevdelta, 1, 0, 0); static VSlot *remapvslot(int index, bool delta, const VSlot &ds) { loopv(remappedvslots) if(remappedvslots[i].index == index) return remappedvslots[i].vslot; VSlot &vs = lookupvslot(index, false); if(vs.index < 0 || vs.index == DEFAULT_SKY) return NULL; VSlot *edit = NULL; if(delta) { VSlot ms; mergevslot(ms, vs, ds); edit = ms.changed ? editvslot(vs, ms) : vs.slot->variants; } else edit = ds.changed ? editvslot(vs, ds) : vs.slot->variants; if(!edit) edit = &vs; remappedvslots.add(vslotmap(vs.index, edit)); return edit; } static void remapvslots(cube &c, bool delta, const VSlot &ds, int orient, bool &findrep, VSlot *&findedit) { if(c.children) { loopi(8) remapvslots(c.children[i], delta, ds, orient, findrep, findedit); return; } static VSlot ms; if(orient<0) loopi(6) { VSlot *edit = remapvslot(c.texture[i], delta, ds); if(edit) { c.texture[i] = edit->index; if(!findedit) findedit = edit; } } else { int i = visibleorient(c, orient); VSlot *edit = remapvslot(c.texture[i], delta, ds); if(edit) { if(findrep) { if(reptex < 0) reptex = c.texture[i]; else if(reptex != c.texture[i]) findrep = false; } c.texture[i] = edit->index; if(!findedit) findedit = edit; } } } void edittexcube(cube &c, int tex, int orient, bool &findrep) { if(orient<0) loopi(6) c.texture[i] = tex; else { int i = visibleorient(c, orient); if(findrep) { if(reptex < 0) reptex = c.texture[i]; else if(reptex != c.texture[i]) findrep = false; } c.texture[i] = tex; } if(c.children) loopi(8) edittexcube(c.children[i], tex, orient, findrep); } VAR(allfaces, 0, 0, 1); void mpeditvslot(int delta, VSlot &ds, int allfaces, selinfo &sel, bool local) { if(local) { game::edittrigger(sel, EDIT_VSLOT, delta, allfaces, 0, &ds); if(!(lastsel==sel)) tofronttex(); if(allfaces || !(repsel == sel)) reptex = -1; repsel = sel; } bool findrep = local && !allfaces && reptex < 0; VSlot *findedit = NULL; loopselxyz(remapvslots(c, delta != 0, ds, allfaces ? -1 : sel.orient, findrep, findedit)); remappedvslots.setsize(0); if(local && findedit) { lasttex = findedit->index; lasttexmillis = totalmillis; curtexindex = texmru.find(lasttex); if(curtexindex < 0) { curtexindex = texmru.length(); texmru.add(lasttex); } } } bool mpeditvslot(int delta, int allfaces, selinfo &sel, ucharbuf &buf) { VSlot ds; if(!unpackvslot(buf, ds, delta != 0)) return false; editingvslot(ds.layer); mpeditvslot(delta, ds, allfaces, sel, false); return true; } void vdelta(char *body) { #ifndef OLDPROTO if(noedit()) return; #else if(noedit() || (nompedit && multiplayer())) return; #endif usevdelta++; execute(body); usevdelta--; } COMMAND(vdelta, "s"); void vrotate(int *n) { #ifndef OLDPROTO if(noedit()) return; #else if(noedit() || (nompedit && multiplayer())) return; #endif VSlot ds; ds.changed = 1<<VSLOT_ROTATION; ds.rotation = usevdelta ? *n : clamp(*n, 0, 5); mpeditvslot(usevdelta, ds, allfaces, sel, true); } COMMAND(vrotate, "i"); void voffset(int *x, int *y) { #ifndef OLDPROTO if(noedit()) return; #else if(noedit() || (nompedit && multiplayer())) return; #endif VSlot ds; ds.changed = 1<<VSLOT_OFFSET; ds.offset = usevdelta ? ivec2(*x, *y) : ivec2(*x, *y).max(0); mpeditvslot(usevdelta, ds, allfaces, sel, true); } COMMAND(voffset, "ii"); void vscroll(float *s, float *t) { #ifndef OLDPROTO if(noedit()) return; #else if(noedit() || (nompedit && multiplayer())) return; #endif VSlot ds; ds.changed = 1<<VSLOT_SCROLL; ds.scroll = vec2(*s, *t).div(1000); mpeditvslot(usevdelta, ds, allfaces, sel, true); } COMMAND(vscroll, "ff"); void vscale(float *scale) { #ifndef OLDPROTO if(noedit()) return; #else if(noedit() || (nompedit && multiplayer())) return; #endif VSlot ds; ds.changed = 1<<VSLOT_SCALE; ds.scale = *scale <= 0 ? 1 : (usevdelta ? *scale : clamp(*scale, 1/8.0f, 8.0f)); mpeditvslot(usevdelta, ds, allfaces, sel, true); } COMMAND(vscale, "f"); void vlayer(int *n) { #ifndef OLDPROTO if(noedit()) return; #else if(noedit() || (nompedit && multiplayer())) return; #endif VSlot ds; ds.changed = 1<<VSLOT_LAYER; if(vslots.inrange(*n)) { ds.layer = *n; if(vslots[ds.layer]->changed && nompedit && multiplayer()) return; } editingvslot(ds.layer); mpeditvslot(usevdelta, ds, allfaces, sel, true); } COMMAND(vlayer, "i"); void valpha(float *front, float *back) { #ifndef OLDPROTO if(noedit()) return; #else if(noedit() || (nompedit && multiplayer())) return; #endif VSlot ds; ds.changed = 1<<VSLOT_ALPHA; ds.alphafront = clamp(*front, 0.0f, 1.0f); ds.alphaback = clamp(*back, 0.0f, 1.0f); mpeditvslot(usevdelta, ds, allfaces, sel, true); } COMMAND(valpha, "ff"); void vcolor(float *r, float *g, float *b) { #ifndef OLDPROTO if(noedit()) return; #else if(noedit() || (nompedit && multiplayer())) return; #endif VSlot ds; ds.changed = 1<<VSLOT_COLOR; ds.colorscale = vec(clamp(*r, 0.0f, 1.0f), clamp(*g, 0.0f, 1.0f), clamp(*b, 0.0f, 1.0f)); mpeditvslot(usevdelta, ds, allfaces, sel, true); } COMMAND(vcolor, "fff"); void vreset() { #ifndef OLDPROTO if(noedit()) return; #else if(noedit() || (nompedit && multiplayer())) return; #endif VSlot ds; mpeditvslot(usevdelta, ds, allfaces, sel, true); } COMMAND(vreset, ""); void vshaderparam(const char *name, float *x, float *y, float *z, float *w) { #ifndef OLDPROTO if(noedit()) return; #else if(noedit() || (nompedit && multiplayer())) return; #endif VSlot ds; ds.changed = 1<<VSLOT_SHPARAM; if(name[0]) { SlotShaderParam p = { getshaderparamname(name), -1, {*x, *y, *z, *w} }; ds.params.add(p); } mpeditvslot(usevdelta, ds, allfaces, sel, true); } COMMAND(vshaderparam, "sffff"); void mpedittex(int tex, int allfaces, selinfo &sel, bool local) { if(local) { game::edittrigger(sel, EDIT_TEX, tex, allfaces); if(allfaces || !(repsel == sel)) reptex = -1; repsel = sel; } bool findrep = local && !allfaces && reptex < 0; loopselxyz(edittexcube(c, tex, allfaces ? -1 : sel.orient, findrep)); } static int unpacktex(int &tex, ucharbuf &buf, bool insert = true) { if(tex < 0x10000) return true; VSlot ds; if(!unpackvslot(buf, ds, false)) return false; VSlot &vs = *lookupslot(tex & 0xFFFF, false).variants; if(vs.index < 0 || vs.index == DEFAULT_SKY) return false; VSlot *edit = insert ? editvslot(vs, ds) : findvslot(*vs.slot, vs, ds); if(!edit) return false; tex = edit->index; return true; } int shouldpacktex(int index) { if(vslots.inrange(index)) { VSlot &vs = *vslots[index]; if(vs.changed) return 0x10000 + vs.slot->index; } return 0; } bool mpedittex(int tex, int allfaces, selinfo &sel, ucharbuf &buf) { if(!unpacktex(tex, buf)) return false; mpedittex(tex, allfaces, sel, false); return true; } void filltexlist() { if(texmru.length()!=vslots.length()) { loopvrev(texmru) if(texmru[i]>=vslots.length()) { if(curtexindex > i) curtexindex--; else if(curtexindex == i) curtexindex = -1; texmru.remove(i); } loopv(vslots) if(texmru.find(i)<0) texmru.add(i); } } void compactmruvslots() { remappedvslots.setsize(0); loopvrev(texmru) { if(vslots.inrange(texmru[i])) { VSlot &vs = *vslots[texmru[i]]; if(vs.index >= 0) { texmru[i] = vs.index; continue; } } if(curtexindex > i) curtexindex--; else if(curtexindex == i) curtexindex = -1; texmru.remove(i); } if(vslots.inrange(lasttex)) { VSlot &vs = *vslots[lasttex]; lasttex = vs.index >= 0 ? vs.index : 0; } else lasttex = 0; reptex = vslots.inrange(reptex) ? vslots[reptex]->index : -1; } void edittex(int i, bool save = true) { lasttex = i; lasttexmillis = totalmillis; if(save) { loopvj(texmru) if(texmru[j]==lasttex) { curtexindex = j; break; } } mpedittex(i, allfaces, sel, true); } void edittex_(int *dir) { if(noedit()) return; filltexlist(); if(texmru.empty()) return; texpaneltimer = 5000; if(!(lastsel==sel)) tofronttex(); curtexindex = clamp(curtexindex<0 ? 0 : curtexindex+*dir, 0, texmru.length()-1); edittex(texmru[curtexindex], false); } void gettex() { if(noedit(true)) return; filltexlist(); int tex = -1; loopxyz(sel, sel.grid, tex = c.texture[sel.orient]); loopv(texmru) if(texmru[i]==tex) { curtexindex = i; tofronttex(); return; } } void getcurtex() { if(noedit(true)) return; filltexlist(); int index = curtexindex < 0 ? 0 : curtexindex; if(!texmru.inrange(index)) return; intret(texmru[index]); } void getseltex() { if(noedit(true)) return; cube &c = lookupcube(sel.o, -sel.grid); if(c.children || isempty(c)) return; intret(c.texture[sel.orient]); } void gettexname(int *tex, int *subslot) { if(noedit(true) || *tex<0) return; VSlot &vslot = lookupvslot(*tex, false); Slot &slot = *vslot.slot; if(!slot.sts.inrange(*subslot)) return; result(slot.sts[*subslot].name); } COMMANDN(edittex, edittex_, "i"); COMMAND(gettex, ""); COMMAND(getcurtex, ""); COMMAND(getseltex, ""); ICOMMAND(getreptex, "", (), { if(!noedit()) intret(vslots.inrange(reptex) ? reptex : -1); }); COMMAND(gettexname, "ii"); void replacetexcube(cube &c, int oldtex, int newtex) { loopi(6) if(c.texture[i] == oldtex) c.texture[i] = newtex; if(c.children) loopi(8) replacetexcube(c.children[i], oldtex, newtex); } void mpreplacetex(int oldtex, int newtex, bool insel, selinfo &sel, bool local) { if(local) game::edittrigger(sel, EDIT_REPLACE, oldtex, newtex, insel ? 1 : 0); if(insel) { loopselxyz(replacetexcube(c, oldtex, newtex)); } else { loopi(8) replacetexcube(worldroot[i], oldtex, newtex); } allchanged(); } bool mpreplacetex(int oldtex, int newtex, bool insel, selinfo &sel, ucharbuf &buf) { if(!unpacktex(oldtex, buf, false)) return false; editingvslot(oldtex); if(!unpacktex(newtex, buf)) return false; mpreplacetex(oldtex, newtex, insel, sel, false); return true; } void replace(bool insel) { if(noedit()) return; if(reptex < 0) { conoutf(CON_ERROR, "can only replace after a texture edit"); return; } mpreplacetex(reptex, lasttex, insel, sel, true); } ICOMMAND(replace, "", (), replace(false)); ICOMMAND(replacesel, "", (), replace(true)); ////////// flip and rotate /////////////// uint dflip(uint face) { return face==F_EMPTY ? face : 0x88888888 - (((face&0xF0F0F0F0)>>4) | ((face&0x0F0F0F0F)<<4)); } uint cflip(uint face) { return ((face&0xFF00FF00)>>8) | ((face&0x00FF00FF)<<8); } uint rflip(uint face) { return ((face&0xFFFF0000)>>16)| ((face&0x0000FFFF)<<16); } uint mflip(uint face) { return (face&0xFF0000FF) | ((face&0x00FF0000)>>8) | ((face&0x0000FF00)<<8); } void flipcube(cube &c, int d) { swap(c.texture[d*2], c.texture[d*2+1]); c.faces[D[d]] = dflip(c.faces[D[d]]); c.faces[C[d]] = cflip(c.faces[C[d]]); c.faces[R[d]] = rflip(c.faces[R[d]]); if(c.children) { loopi(8) if(i&octadim(d)) swap(c.children[i], c.children[i-octadim(d)]); loopi(8) flipcube(c.children[i], d); } } void rotatequad(cube &a, cube &b, cube &c, cube &d) { cube t = a; a = b; b = c; c = d; d = t; } void rotatecube(cube &c, int d) // rotates cube clockwise. see pics in cvs for help. { c.faces[D[d]] = cflip (mflip(c.faces[D[d]])); c.faces[C[d]] = dflip (mflip(c.faces[C[d]])); c.faces[R[d]] = rflip (mflip(c.faces[R[d]])); swap(c.faces[R[d]], c.faces[C[d]]); swap(c.texture[2*R[d]], c.texture[2*C[d]+1]); swap(c.texture[2*C[d]], c.texture[2*R[d]+1]); swap(c.texture[2*C[d]], c.texture[2*C[d]+1]); if(c.children) { int row = octadim(R[d]); int col = octadim(C[d]); for(int i=0; i<=octadim(d); i+=octadim(d)) rotatequad ( c.children[i+row], c.children[i], c.children[i+col], c.children[i+col+row] ); loopi(8) rotatecube(c.children[i], d); } } void mpflip(selinfo &sel, bool local) { if(local) { game::edittrigger(sel, EDIT_FLIP); makeundo(); } int zs = sel.s[dimension(sel.orient)]; loopxy(sel) { loop(z,zs) flipcube(selcube(x, y, z), dimension(sel.orient)); loop(z,zs/2) { cube &a = selcube(x, y, z); cube &b = selcube(x, y, zs-z-1); swap(a, b); } } changed(sel); } void flip() { if(noedit()) return; mpflip(sel, true); } void mprotate(int cw, selinfo &sel, bool local) { if(local) game::edittrigger(sel, EDIT_ROTATE, cw); int d = dimension(sel.orient); if(!dimcoord(sel.orient)) cw = -cw; int m = sel.s[C[d]] < sel.s[R[d]] ? C[d] : R[d]; int ss = sel.s[m] = max(sel.s[R[d]], sel.s[C[d]]); if(local) makeundo(); loop(z,sel.s[D[d]]) loopi(cw>0 ? 1 : 3) { loopxy(sel) rotatecube(selcube(x,y,z), d); loop(y,ss/2) loop(x,ss-1-y*2) rotatequad ( selcube(ss-1-y, x+y, z), selcube(x+y, y, z), selcube(y, ss-1-x-y, z), selcube(ss-1-x-y, ss-1-y, z) ); } changed(sel); } void rotate(int *cw) { if(noedit()) return; mprotate(*cw, sel, true); } COMMAND(flip, ""); COMMAND(rotate, "i"); enum { EDITMATF_EMPTY = 0x10000, EDITMATF_NOTEMPTY = 0x20000, EDITMATF_SOLID = 0x30000, EDITMATF_NOTSOLID = 0x40000 }; static const struct { const char *name; int filter; } editmatfilters[] = { { "empty", EDITMATF_EMPTY }, { "notempty", EDITMATF_NOTEMPTY }, { "solid", EDITMATF_SOLID }, { "notsolid", EDITMATF_NOTSOLID } }; void setmat(cube &c, ushort mat, ushort matmask, ushort filtermat, ushort filtermask, int filtergeom) { if(c.children) loopi(8) setmat(c.children[i], mat, matmask, filtermat, filtermask, filtergeom); else if((c.material&filtermask) == filtermat) { switch(filtergeom) { case EDITMATF_EMPTY: if(isempty(c)) break; return; case EDITMATF_NOTEMPTY: if(!isempty(c)) break; return; case EDITMATF_SOLID: if(isentirelysolid(c)) break; return; case EDITMATF_NOTSOLID: if(!isentirelysolid(c)) break; return; } if(mat!=MAT_AIR) { c.material &= matmask; c.material |= mat; } else c.material = MAT_AIR; } } void mpeditmat(int matid, int filter, selinfo &sel, bool local) { if(local) game::edittrigger(sel, EDIT_MAT, matid, filter); ushort filtermat = 0, filtermask = 0, matmask; int filtergeom = 0; if(filter >= 0) { filtermat = filter&0xFFFF; filtermask = filtermat&(MATF_VOLUME|MATF_INDEX) ? MATF_VOLUME|MATF_INDEX : (filtermat&MATF_CLIP ? MATF_CLIP : filtermat); filtergeom = filter&~0xFFFF; } if(matid < 0) { matid = 0; matmask = filtermask; if(isclipped(filtermat&MATF_VOLUME)) matmask &= ~MATF_CLIP; if(isdeadly(filtermat&MATF_VOLUME)) matmask &= ~MAT_DEATH; } else { matmask = matid&(MATF_VOLUME|MATF_INDEX) ? 0 : (matid&MATF_CLIP ? ~MATF_CLIP : ~matid); if(isclipped(matid&MATF_VOLUME)) matid |= MAT_CLIP; if(isdeadly(matid&MATF_VOLUME)) matid |= MAT_DEATH; } loopselxyz(setmat(c, matid, matmask, filtermat, filtermask, filtergeom)); } void editmat(char *name, char *filtername) { if(noedit()) return; int filter = -1; if(filtername[0]) { loopi(sizeof(editmatfilters)/sizeof(editmatfilters[0])) if(!strcmp(editmatfilters[i].name, filtername)) { filter = editmatfilters[i].filter; break; } if(filter < 0) filter = findmaterial(filtername); if(filter < 0) { conoutf(CON_ERROR, "unknown material \"%s\"", filtername); return; } } int id = -1; if(name[0] || filter < 0) { id = findmaterial(name); if(id<0) { conoutf(CON_ERROR, "unknown material \"%s\"", name); return; } } mpeditmat(id, filter, sel, true); } COMMAND(editmat, "ss"); extern int menudistance, menuautoclose; VARP(texguiwidth, 1, 12, 1000); VARP(texguiheight, 1, 8, 1000); VARP(texguitime, 0, 25, 1000); static int lastthumbnail = 0; VARP(texgui2d, 0, 1, 1); struct texturegui : g3d_callback { bool menuon; vec menupos; int menustart, menutab; texturegui() : menustart(-1) {} void gui(g3d_gui &g, bool firstpass) { int origtab = menutab, numtabs = max((slots.length() + texguiwidth*texguiheight - 1)/(texguiwidth*texguiheight), 1); g.start(menustart, 0.04f, &menutab); loopi(numtabs) { g.tab(!i ? "Textures" : NULL, 0xAAFFAA); if(i+1 != origtab) continue; //don't load textures on non-visible tabs! loop(h, texguiheight) { g.pushlist(); loop(w, texguiwidth) { extern VSlot dummyvslot; int ti = (i*texguiheight+h)*texguiwidth+w; if(ti<slots.length()) { Slot &slot = lookupslot(ti, false); VSlot &vslot = *slot.variants; if(slot.sts.empty()) continue; else if(!slot.loaded && !slot.thumbnail) { if(totalmillis-lastthumbnail<texguitime) { g.texture(dummyvslot, 1.0, false); //create an empty space continue; } loadthumbnail(slot); lastthumbnail = totalmillis; } if(g.texture(vslot, 1.0f, true)&G3D_UP && (slot.loaded || slot.thumbnail!=notexture)) { edittex(vslot.index); hudshader->set(); } } else { g.texture(dummyvslot, 1.0, false); //create an empty space } } g.poplist(); } } g.end(); } void showtextures(bool on) { if(on != menuon && (menuon = on)) { if(menustart <= lasttexmillis) menutab = 1+clamp(lookupvslot(lasttex, false).slot->index, 0, slots.length()-1)/(texguiwidth*texguiheight); menupos = menuinfrontofplayer(); menustart = starttime(); } } void show() { if(!menuon) return; filltexlist(); extern int usegui2d; if(!editmode || ((!texgui2d || !usegui2d) && camera1->o.dist(menupos) > menuautoclose)) menuon = false; else g3d_addgui(this, menupos, texgui2d ? GUI_2D : 0); } } gui; void g3d_texturemenu() { gui.show(); } void showtexgui(int *n) { if(!editmode) { conoutf(CON_ERROR, "operation only allowed in edit mode"); return; } gui.showtextures(*n==0 ? !gui.menuon : *n==1); } // 0/noargs = toggle, 1 = on, other = off - will autoclose if too far away or exit editmode COMMAND(showtexgui, "i"); void rendertexturepanel(int w, int h) { if((texpaneltimer -= curtime)>0 && editmode) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); pushhudmatrix(); hudmatrix.scale(h/1800.0f, h/1800.0f, 1); flushhudmatrix(false); SETSHADER(hudrgb); int y = 50, gap = 10; gle::defvertex(2); gle::deftexcoord0(); loopi(7) { int s = (i == 3 ? 285 : 220), ti = curtexindex+i-3; if(texmru.inrange(ti)) { VSlot &vslot = lookupvslot(texmru[ti]), *layer = NULL; Slot &slot = *vslot.slot; Texture *tex = slot.sts.empty() ? notexture : slot.sts[0].t, *glowtex = NULL, *layertex = NULL; if(slot.texmask&(1<<TEX_GLOW)) { loopvj(slot.sts) if(slot.sts[j].type==TEX_GLOW) { glowtex = slot.sts[j].t; break; } } if(vslot.layer) { layer = &lookupvslot(vslot.layer); layertex = layer->slot->sts.empty() ? notexture : layer->slot->sts[0].t; } float sx = min(1.0f, tex->xs/(float)tex->ys), sy = min(1.0f, tex->ys/(float)tex->xs); int x = w*1800/h-s-50, r = s; vec2 tc[4] = { vec2(0, 0), vec2(1, 0), vec2(1, 1), vec2(0, 1) }; float xoff = vslot.offset.x, yoff = vslot.offset.y; if(vslot.rotation) { if((vslot.rotation&5) == 1) { swap(xoff, yoff); loopk(4) swap(tc[k].x, tc[k].y); } if(vslot.rotation >= 2 && vslot.rotation <= 4) { xoff *= -1; loopk(4) tc[k].x *= -1; } if(vslot.rotation <= 2 || vslot.rotation == 5) { yoff *= -1; loopk(4) tc[k].y *= -1; } } loopk(4) { tc[k].x = tc[k].x/sx - xoff/tex->xs; tc[k].y = tc[k].y/sy - yoff/tex->ys; } glBindTexture(GL_TEXTURE_2D, tex->id); loopj(glowtex ? 3 : 2) { if(j < 2) gle::color(vec(vslot.colorscale).mul(j), texpaneltimer/1000.0f); else { glBindTexture(GL_TEXTURE_2D, glowtex->id); glBlendFunc(GL_SRC_ALPHA, GL_ONE); gle::color(vslot.glowcolor, texpaneltimer/1000.0f); } gle::begin(GL_TRIANGLE_STRIP); gle::attribf(x, y); gle::attrib(tc[0]); gle::attribf(x+r, y); gle::attrib(tc[1]); gle::attribf(x, y+r); gle::attrib(tc[3]); gle::attribf(x+r, y+r); gle::attrib(tc[2]); xtraverts += gle::end(); if(j==1 && layertex) { gle::color(layer->colorscale, texpaneltimer/1000.0f); glBindTexture(GL_TEXTURE_2D, layertex->id); gle::begin(GL_TRIANGLE_STRIP); gle::attribf(x+r/2, y+r/2); gle::attrib(tc[0]); gle::attribf(x+r, y+r/2); gle::attrib(tc[1]); gle::attribf(x+r/2, y+r); gle::attrib(tc[3]); gle::attribf(x+r, y+r); gle::attrib(tc[2]); xtraverts += gle::end(); } if(!j) { r -= 10; x += 5; y += 5; } else if(j == 2) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } } y += s+gap; } pophudmatrix(true, false); hudshader->set(); } }
[ "andrius4669@gmail.com" ]
andrius4669@gmail.com
014110b2478e330113d121bf7acb954a22429273
84d078cfe9a7676abc9f1f41d7835e9bc2f7722b
/piscine_cpp/d00/ex02/Account.class.cpp
12b93f21422186ed027f2e0e521ff3e4a802110c
[]
no_license
aradiuk/CPP
0b58a823317c05ca8941998481da61700752d52d
1414413ae524c185908b30c4a9ddd77cf791383b
refs/heads/master
2021-07-19T21:08:34.762887
2021-02-16T10:18:15
2021-02-16T10:18:15
99,698,590
0
0
null
null
null
null
UTF-8
C++
false
false
2,975
cpp
#include "Account.class.hpp" #include <iostream> // CHECK THE ORDER // OF DESTRUCTORS // LAST 8 ROWS OF // THE OUTPUT int Account::_nbAccounts = 0; int Account::_totalAmount = 0; int Account::_totalNbDeposits = 0; int Account::_totalNbWithdrawals = 0; int Account::getNbAccounts() { return _nbAccounts; } int Account::getTotalAmount() { return _totalAmount; } int Account::getNbDeposits() { return _totalNbDeposits; } int Account::getNbWithdrawals() { return _totalNbWithdrawals; } Account::Account(int initial_deposit) { this->_amount = initial_deposit; this->_totalAmount += _amount; this->_nbDeposits = 0; this->_nbWithdrawals = 0; this->_accountIndex = this->_nbAccounts; this->_nbAccounts++; _displayTimestamp(); std::cout << "index:" << _accountIndex << ";"; std::cout << "amount:" << _amount << ";created\n"; } Account::~Account() { Account::_displayTimestamp(); std::cout << "index:" << this->_accountIndex << ";"; std::cout << "amount:" << this->_amount << ";closed\n"; } void Account::_displayTimestamp() { char str[19]; time_t time = time_t(NULL); if (strftime(str, sizeof(str), "[%Y%d%m_%H%M%S] ", localtime(&time))) std::cout << str; } void Account::displayAccountsInfos() { _displayTimestamp(); std::cout << "accounts:" << getNbAccounts() << ";"; std::cout << "total:" << getTotalAmount() << ";"; std::cout << "deposits:" << getNbDeposits() << ";"; std::cout << "withdrawals:" << getNbWithdrawals() << "\n"; } void Account::displayStatus() const { _displayTimestamp(); std::cout << "index:" << this->_accountIndex << ";"; std::cout << "amount:" << this->_amount << ";"; std::cout << "deposits:" << this->_nbDeposits << ";"; std::cout << "withdrawals:" << this->_nbWithdrawals; std::cout << std::endl; } void Account::makeDeposit(int deposit) { int p_amount = this->_amount; this->_amount += deposit; this->_nbDeposits++; Account::_totalAmount += deposit; Account::_totalNbDeposits++; _displayTimestamp(); std::cout << "index:" << this->_accountIndex << ";"; std::cout << "p_amount:" << p_amount << ";"; std::cout << "deposit:" << deposit << ";"; std::cout << "amount:" << this->_amount << ";"; std::cout << "nb_deposits:" << this->_nbDeposits; std::cout << std::endl; } bool Account::makeWithdrawal(int withdrawal) { int p_amount = this->_amount; bool allow = withdrawal <= this->_amount; _displayTimestamp(); std::cout << "index:" << this->_accountIndex << ";"; std::cout << "p_amount:" << p_amount << ";"; std::cout << "withdrawal:"; if (allow) { this->_amount -= withdrawal; this->_nbWithdrawals++; Account::_totalAmount -= withdrawal; Account::_totalNbWithdrawals++; std::cout << withdrawal << ";"; std::cout << "amount:" << this->_amount << ";"; std::cout << "nb_withdrawals:" << this->_nbWithdrawals; std::cout << std::endl; return (true); } else { std::cout << "refused\n"; return (false); } } int Account::checkAmount() const { return (this->_amount); }
[ "hartright@bitbucket.org" ]
hartright@bitbucket.org
518622424b9903c5be5cd2f1ebd5c72f45f16105
7edeec5310bf96c435c287f59be66fb78be556b9
/OSDesign/main.cpp
d4ad4d7949c906f240b014c0a2f3331fc13ee4c1
[]
no_license
typeme/daily-study
e145824eb4dab77a7e862003a133d4a3ffdf9c1f
e149cde065c84285bacb6c7012bf5e7d54432efc
refs/heads/master
2020-08-03T20:23:33.019127
2020-07-13T15:54:48
2020-07-13T15:54:48
211,875,489
1
0
null
null
null
null
UTF-8
C++
false
false
79,681
cpp
#include <iostream> #include<termios.h> #include<unistd.h> #include<assert.h> #include<time.h> #include <stdio.h>//c่ฏญ่จ€็š„็š„unixๆ–‡ไปถ่พ“ๅ…ฅ่พ“ๅ‡บๅบ“ #include <fcntl.h>//ๆ นๆฎๆ–‡ไปถๆ่ฟฐ่ฏๆ“ไฝœๆ–‡ไปถ็š„็‰นๆ€ง #include <string> #include <cstring> using namespace std; //ๅธธ้‡ๅฎšไน‰ // NADDRไธบๆ–‡ไปถๅฏไฝฟ็”จ็š„ๆœ€ๅคงๆ•ฐ้‡่Š‚็‚น const unsigned int NADDR = 6; // BLOCK_SIZEไธบไธ€ไธชblock็š„ๅคงๅฐ const unsigned short BLOCK_SIZE = 512; //ๆ–‡ไปถๆœ€ๅคงๅฐบๅฏธ const unsigned int FILE_SIZE_MAX = (NADDR - 2) * BLOCK_SIZE + BLOCK_SIZE / sizeof(int) * BLOCK_SIZE; //block็š„ๆ•ฐ้‡ const unsigned short BLOCK_NUM = 512; //inode ็ดขๅผ•่Š‚็‚นๅคงๅฐ const unsigned short INODE_SIZE = 128; //inodeๆ•ฐ้‡ const unsigned short INODE_NUM = 256; //inode็š„่ตทๅง‹ไฝ็ฝฎ const unsigned int INODE_START = 3 * BLOCK_SIZE; //ๆ•ฐๆฎ่ตทๅง‹ไฝ็ฝฎ const unsigned int DATA_START = INODE_START + INODE_NUM * INODE_SIZE; //ๆ–‡ไปถ็ณป็ปŸๆ”ฏๆŒ็š„็”จๆˆทๆ•ฐ้‡ const unsigned int ACCOUNT_NUM = 10; //ๅญ็›ฎๅฝ•็š„ๆœ€ๅคงๆ•ฐ้‡ const unsigned int DIRECTORY_NUM = 16; //ๆ–‡ไปถๅ็š„ๆœ€ๅคง้•ฟๅบฆ const unsigned short FILE_NAME_LENGTH = 14; //็”จๆˆทๅ็š„ๆœ€ๅคง้•ฟๅบฆ const unsigned short USER_NAME_LENGTH = 14; //็”จๆˆทๅฏ†็ ็š„ๆœ€ๅคง้•ฟๅบฆ const unsigned short USER_PASSWORD_LENGTH = 14; //ๆ–‡ไปถๆœ€ๅคงๆƒ้™ const unsigned short MAX_PERMISSION = 511; //็”จๆˆทๆœ€ๅคงๆƒ้™ const unsigned short MAX_OWNER_PERMISSION = 448; //ๆƒ้™ const unsigned short ELSE_E = 1; const unsigned short ELSE_W = 1 << 1; const unsigned short ELSE_R = 1 << 2; const unsigned short GRP_E = 1 << 3; const unsigned short GRP_W = 1 << 4; const unsigned short GRP_R = 1 << 5; const unsigned short OWN_E = 1 << 6; const unsigned short OWN_W = 1 << 7; const unsigned short OWN_R = 1 << 8; //inode่ฎพ่ฎก ็ดขๅผ•่Š‚็‚น struct inode { unsigned int i_ino; //inodeๅท. unsigned int di_addr[NADDR]; // ๅญ˜ๅ‚จๆ–‡ไปถ็š„ๆ•ฐๆฎๅ—ๆ•ฐใ€‚ unsigned short di_number; // ๅ…ณ่”ๆ–‡ไปถๆ•ฐใ€‚ unsigned short di_mode; //ๆ–‡ไปถ็ฑปๅž‹. unsigned short icount; //่ฟžๆŽฅๆ•ฐ unsigned short permission; //ๆ–‡ไปถๆƒ้™ unsigned short di_uid; //ๆ–‡ไปถๆ‰€ๅฑž็”จๆˆทid. unsigned short di_grp; //ๆ–‡ไปถๆ‰€ๅฑž็ป„ unsigned short di_size; //ๆ–‡ไปถๅคงๅฐ. char time[100]; }; //่ถ…็บงๅ—่ฎพ็ฝฎ struct filsys { unsigned short s_num_inode; //inodeๆ€ปๆ•ฐ unsigned short s_num_finode; //็ฉบ้—ฒinodeๆ•ฐ. unsigned short s_size_inode; //inodeๅคงๅฐ. unsigned short s_num_block; //block็š„ๆ•ฐ้‡. unsigned short s_num_fblock; //็ฉบ้—ฒๅ—็š„ๆ•ฐ้‡. unsigned short s_size_block; //block็š„ๅคงๅฐ. unsigned int special_stack[50]; //ๆ ˆไธญๅ…ƒ็ด ไธบ็ฉบ้—ฒๅ—ๆŒ‡้’ˆ int special_free; //ไธ‹ไธ€็ป„ไธญ็ฉบ้—ฒๅ—ๆ•ฐ้‡ }; //็›ฎๅฝ•่ฎพ่ฎก struct directory { char fileName[20][FILE_NAME_LENGTH]; //็›ฎๅฝ•ๅ็งฐ unsigned int inodeID[DIRECTORY_NUM]; //inodeๅท }; //่ดฆๆˆท่ฎพ่ฎก struct userPsw { unsigned short userID[ACCOUNT_NUM]; //็”จๆˆทid char userName[ACCOUNT_NUM][USER_NAME_LENGTH]; //็”จๆˆทๅ char password[ACCOUNT_NUM][USER_PASSWORD_LENGTH]; //็”จๆˆทๅฏ†็  unsigned short groupID[ACCOUNT_NUM]; //็”จๆˆทๆ‰€ๅœจ็ป„id }; //ๅŠŸ่ƒฝๅ‡ฝๆ•ฐๅฃฐๆ˜Ž void CommParser(inode*&); // ้€‰ๅ–ๅŠŸ่ƒฝ void Help(); //ๅธฎๅŠฉไฟกๆฏ void Sys_start(); //ๅฏๅŠจๆ–‡ไปถ็ณป็ปŸ //ๅ…จๅฑ€ๅ˜้‡ FILE* fd = NULL; //ๆ–‡ไปถ็ณป็ปŸไฝ็ฝฎ //่ถ…็บงๅ— filsys superBlock; //1ไปฃ่กจๅทฒ็ปไฝฟ็”จ๏ผŒ0่กจ็คบ็ฉบ้—ฒ unsigned short inode_bitmap[INODE_NUM]; //็”จๆˆท userPsw users; //็”จๆˆทid unsigned short userID = ACCOUNT_NUM; //็”จๆˆทๅ char userName[USER_NAME_LENGTH + 6]; //ๅฝ“ๅ‰็›ฎๅฝ• directory currentDirectory; char ab_dir[100][14]; unsigned short dir_pointer; //ๅฏปๆ‰พ็ฉบ้—ฒๅ— void find_free_block(unsigned int &inode_number) { // ่ฎพ็ฝฎๆ–‡ไปถ็ณป็ปŸ็š„ไฝ็ฝฎไธบไปŽSEEK_SET ๅผ€ๅง‹ๅ็งปBLOCK_SIZEๅผ€ๅง‹ fseek(fd, BLOCK_SIZE, SEEK_SET); // ่ฏปๅ–ๆ–‡ไปถ็ณป็ปŸไธญ็š„ๅคงๅฐไธบfilsys็š„ๅ†…ๅฎนๅˆฐsuperBlock fread(&superBlock, sizeof(filsys), 1, fd); // ๅฆ‚ๆžœๅฝ“ๅ‰็ฉบ้—ฒๅ—ๆ•ฐ้‡ไธบ0 if (superBlock.special_free == 0) { // ๅฆ‚ๆžœ็ณป็ปŸไธญไธๅญ˜ๅœจ็ฉบ้—ฒๅ— if (superBlock.special_stack[0] == 0) { printf("No value block!\n"); return; } // ๅชๅ‰ฉไธ‹ๆœ€ไธŠๆ–นๅ…ƒ็ด ๏ผŒๅˆ™ๅฐ†ๆœ€ไธŠๆ–นๅ…ƒ็ด ๆ ˆ็š„ไฟกๆฏๅ’ŒNไฟๅญ˜ๅˆฐ่ถ…็บงๅ—ไธญ๏ผŒๆŽฅ็€ๅฐ†ๅŽŸๆœ€ไธŠๆ–นๅ…ƒ็ด ไฝœไธบๆ™ฎ้€šๅ…ƒ็ด ๅˆ†้…ๅ‡บๅŽปๅณๅฏ unsigned int stack[51]; for (int i = 0; i < 50; i++) { stack[i] = superBlock.special_stack[i]; } stack[50] = superBlock.special_free; fseek(fd, DATA_START + (superBlock.special_stack[0] - 50) * BLOCK_SIZE, SEEK_SET); // ๅฐ†stackๅ†…ๅฎนๅ†™ๅˆฐๆ–‡ไปถ็ณป็ปŸ fwrite(stack, sizeof(stack), 1, fd); fseek(fd, DATA_START + superBlock.special_stack[0] * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(stack), 1, fd); for (int i = 0; i < 50; i++) { superBlock.special_stack[i] = stack[i]; } superBlock.special_free = stack[50]; } // ๅ‡บๆ ˆๆœ€ๅŽไธ€ไธชๅ— ไฝœไธบๅˆ†้…็š„block inode_number = superBlock.special_stack[superBlock.special_free]; superBlock.special_free--; superBlock.s_num_fblock--; fseek(fd, BLOCK_SIZE, SEEK_SET); fwrite(&superBlock, sizeof(filsys), 1, fd); } //้‡็ฝฎblock void recycle_block(unsigned int &inode_number) { fseek(fd, BLOCK_SIZE, SEEK_SET); fread(&superBlock, sizeof(filsys), 1, fd); // ่‹ฅๆ ˆๆปกไบ†๏ผŒๅˆ™ๆŠŠ่ถ…็บงๅ—ไธญ็š„ๅ†…ๅฎนๅคๅˆถๅˆฐๆ–ฐๆฅ็š„ๅ—ไธญ๏ผŒๅŒ…ๆ‹ฌN๏ผŒๆ ˆไฟกๆฏ ๆŽฅ็€ๆ›ดๆ–ฐ่ถ…็บงๅ—ไฟกๆฏ๏ผŒ่ถ…็บงๅ—Nๅ˜ไธบ1๏ผŒ็ฌฌไธ€ไธชๅ…ƒ็ด ๆŒ‡ๅ‘ๅˆšๆ‰ๆ–ฐๆฅ็š„็ฃ็›˜ๅ— if (superBlock.special_free == 49) { unsigned int block_num; unsigned int stack[51]; if (superBlock.special_stack[0] == 0) block_num = 499; else block_num = superBlock.special_stack[0] - 50; for (int i = 0; i < 50; i++) { stack[i] = superBlock.special_stack[i]; } stack[50] = superBlock.special_free; fseek(fd, DATA_START + block_num*BLOCK_SIZE, SEEK_SET); fwrite(stack, sizeof(stack), 1, fd); block_num -= 50; fseek(fd, DATA_START + block_num*BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(stack), 1, fd); for (int i = 0; i < 50; i++) { superBlock.special_stack[i] = stack[i]; } superBlock.special_free = stack[50]; } superBlock.special_free++; superBlock.s_num_fblock++; superBlock.special_stack[superBlock.special_free] = inode_number; fseek(fd, BLOCK_SIZE, SEEK_SET); fwrite(&superBlock, sizeof(filsys), 1, fd); } //ๅˆๅง‹ๅŒ–ๆ–‡ไปถ็ณป็ปŸ bool Format() { //ๅœจๅฝ“ๅ‰็›ฎๅฝ•ๆ–ฐๅปบไธ€ไธชๆ–‡ไปถไฝœไธบๆ–‡ไปถๅท FILE* fd = fopen("root.tianye", "wb+"); if (fd == NULL) { printf("ๅˆๅง‹ๅŒ–ๆ–‡ไปถ็ณป็ปŸๅคฑ่ดฅ!\n"); return false; } //ๅˆๅง‹ๅŒ–่ถ…็บงๅ— filsys superBlock; superBlock.s_num_inode = INODE_NUM; superBlock.s_num_block = BLOCK_NUM + 3 + 64; //3ไปฃ่กจ๏ผŒ0็ฉบ้—ฒๅ—ใ€1่ถ…็บงๅ—ใ€2Inodeไฝ็คบๅ›พ่กจ,64ๅ—ๅญ˜inode ไฝ็คบๅ›พ๏ผŒ่ฎฐๅฝ•ๆ–‡ไปถๅญ˜ๅ‚จๅ™จ็š„ไฝฟ็”จๆƒ…ๅ†ต superBlock.s_size_inode = INODE_SIZE; superBlock.s_size_block = BLOCK_SIZE; superBlock.s_num_fblock = BLOCK_NUM - 2; superBlock.s_num_finode = INODE_NUM - 2; superBlock.special_stack[0] = 99; for (int i = 1; i < 50; i++) { superBlock.special_stack[i] = 49 - i; } superBlock.special_free = 47; //Write super block into file. fseek(fd, BLOCK_SIZE, SEEK_SET); fwrite(&superBlock, sizeof(filsys), 1, fd); fseek(fd, BLOCK_SIZE, SEEK_SET); fread(&superBlock, sizeof(filsys), 1, fd); //ๅˆๅง‹ๅŒ–ไฝ็คบๅ›พ unsigned short inode_bitmap[INODE_NUM]; memset(inode_bitmap, 0, INODE_NUM); inode_bitmap[0] = 1; inode_bitmap[1] = 1; //Write bitmaps into file. fseek(fd, 2 * BLOCK_SIZE, SEEK_SET); fwrite(inode_bitmap, sizeof(unsigned short) * INODE_NUM, 1, fd); //ๆˆ็ป„้“พๆŽฅ unsigned int stack[51]; for (int i = 0; i < BLOCK_NUM / 50; i++) { memset(stack, 0, sizeof(stack)); for (unsigned int j = 0; j < 50; j++) { stack[j] = (49 + i * 50) - j; } stack[0] = 49 + (i + 1) * 50; stack[50] = 49; fseek(fd, DATA_START + (49 + i * 50)*BLOCK_SIZE, SEEK_SET); fwrite(stack, sizeof(unsigned int) * 51, 1, fd); } memset(stack, 0, sizeof(stack)); for (int i = 0; i < 12; i++) { stack[i] = 511 - i; } stack[0] = 0; stack[50] = 11; fseek(fd, DATA_START + 511 * BLOCK_SIZE, SEEK_SET); fwrite(stack, sizeof(unsigned int) * 51, 1, fd); fseek(fd, DATA_START + 49 * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(unsigned int) * 51, 1, fd); fseek(fd, DATA_START + 99 * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(unsigned int) * 51, 1, fd); fseek(fd, DATA_START + 149 * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(unsigned int) * 51, 1, fd); fseek(fd, DATA_START + 199 * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(unsigned int) * 51, 1, fd); fseek(fd, DATA_START + 249 * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(unsigned int) * 51, 1, fd); fseek(fd, DATA_START + 299 * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(unsigned int) * 51, 1, fd); fseek(fd, DATA_START + 349 * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(unsigned int) * 51, 1, fd); fseek(fd, DATA_START + 399 * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(unsigned int) * 51, 1, fd); fseek(fd, DATA_START + 449 * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(unsigned int) * 51, 1, fd); fseek(fd, DATA_START + 499 * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(unsigned int) * 51, 1, fd); fseek(fd, DATA_START + 511 * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(unsigned int) * 51, 1, fd); //ๅˆ›ๅปบๆ น็›ฎๅฝ• inode iroot_tmp; iroot_tmp.i_ino = 0; iroot_tmp.di_number = 2; iroot_tmp.di_mode = 0; //0 =็›ฎๅฝ• iroot_tmp.di_size = 0; //็›ฎๅฝ•ๅคงๅฐไธบ0 memset(iroot_tmp.di_addr, -1, sizeof(unsigned int) * NADDR); iroot_tmp.di_addr[0] = 0; iroot_tmp.permission = MAX_OWNER_PERMISSION; iroot_tmp.di_grp = 1; iroot_tmp.di_uid = 0; //Root user id. iroot_tmp.icount = 0; time_t t = time(0); strftime(iroot_tmp.time, sizeof(iroot_tmp.time), "%Y/%m/%d %X", localtime(&t)); iroot_tmp.time[64] = 0; fseek(fd, INODE_START, SEEK_SET); fwrite(&iroot_tmp, sizeof(inode), 1, fd); //็›ดๆŽฅๅˆ›ๅปบๆ–‡ไปถ directory droot_tmp; memset(droot_tmp.fileName, 0, sizeof(char) * DIRECTORY_NUM * FILE_NAME_LENGTH); memset(droot_tmp.inodeID, -1, sizeof(unsigned int) * DIRECTORY_NUM); strcpy(droot_tmp.fileName[0], "."); droot_tmp.inodeID[0] = 0; strcpy(droot_tmp.fileName[1], ".."); droot_tmp.inodeID[1] = 0; //A sub directory for accounting files strcpy(droot_tmp.fileName[2], "system"); droot_tmp.inodeID[2] = 1; //ๅ†™ๅ…ฅ fseek(fd, DATA_START, SEEK_SET); fwrite(&droot_tmp, sizeof(directory), 1, fd); //ๅˆ›ๅปบ็”จๆˆทๆ–‡ไปถ //ๅ…ˆๅˆ›ๅปบ inode inode iaccouting_tmp; iaccouting_tmp.i_ino = 1; iaccouting_tmp.di_number = 1; iaccouting_tmp.di_mode = 1; //1 ไปฃ่กจๆ–‡ไปถ iaccouting_tmp.di_size = sizeof(userPsw); //ๆ–‡ไปถๅคงๅฐ memset(iaccouting_tmp.di_addr, -1, sizeof(unsigned int) * NADDR); iaccouting_tmp.di_addr[0] = 1; //ๆ น็›ฎๅฝ•ๅญ˜ๅœจ็ฌฌไธ€ๅ— iaccouting_tmp.di_uid = 0; //Root user id. iaccouting_tmp.di_grp = 1; iaccouting_tmp.permission = 320; iaccouting_tmp.icount = 0; t = time(0); strftime(iaccouting_tmp.time, sizeof(iaccouting_tmp.time), "%Y/%m/%d %X", localtime(&t)); iaccouting_tmp.time[64] = 0; fseek(fd, INODE_START + INODE_SIZE, SEEK_SET); fwrite(&iaccouting_tmp, sizeof(inode), 1, fd); //ๅˆ›ๅปบ่ดฆๆˆท. userPsw paccouting_tmp; memset(paccouting_tmp.userName, 0, sizeof(char) * USER_NAME_LENGTH * ACCOUNT_NUM); memset(paccouting_tmp.password, 0, sizeof(char) * USER_PASSWORD_LENGTH * ACCOUNT_NUM); strcpy(paccouting_tmp.userName[0], "root"); strcpy(paccouting_tmp.userName[1], "tianye"); strcpy(paccouting_tmp.password[0], "123"); strcpy(paccouting_tmp.password[1], "123"); //0 ไปฃ่กจ็ฎก็†ๅ‘˜๏ผŒๅ…ถไป–ๆ•ฐๅญ—ๅฐฑๆ˜ฏuserid for (unsigned short i = 0; i < ACCOUNT_NUM; i++) { paccouting_tmp.userID[i] = i; } paccouting_tmp.groupID[0] = 1; paccouting_tmp.groupID[1] = 2; //ๅ†™ๅ…ฅๆ–‡ไปถ fseek(fd, DATA_START + BLOCK_SIZE, SEEK_SET); fwrite(&paccouting_tmp, sizeof(userPsw), 1, fd); //ๅ…ณ้—ญๆ–‡ไปถ. fclose(fd); return true; }; //ๅˆๅง‹ๅŒ–ๆ–‡ไปถ็ณป็ปŸ็š„ๅ„้กนๅŠŸ่ƒฝ bool Mount() { //ๆ‰“ๅผ€ๆ–‡ไปถๅท fd = fopen("root.tianye", "rb+"); if (fd == NULL) { printf("ๆ–‡ไปถ็ณป็ปŸๆฒกๆœ‰ๆ‰พๅˆฐ!\n"); return false; } //่ฏปๅ–่ถ…็บงๅ—ไฟกๆฏ fseek(fd, BLOCK_SIZE, SEEK_SET); fread(&superBlock, sizeof(superBlock), 1, fd); //่ฏปๅ–่Š‚็‚นๆ˜ ๅฐ„่กจ fseek(fd, 2 * BLOCK_SIZE, SEEK_SET); fread(inode_bitmap, sizeof(unsigned short) * INODE_NUM, 1, fd); //่ฏปๅ–ๅฝ“ๅ‰็›ฎๅฝ• fseek(fd, DATA_START, SEEK_SET); fread(&currentDirectory, sizeof(directory), 1, fd); //่ฏปๅ–่ดฆๆˆท่ต„ๆ–™ fseek(fd, DATA_START + BLOCK_SIZE, SEEK_SET); fread(&users, sizeof(userPsw), 1, fd); return true; }; //็™ปๅฝ•ๆจกๅ— bool Login(const char* user, const char* password) { //ๆฃ€ๆต‹ๅ‚ๆ•ฐ if (user == NULL || password == NULL) { printf("็”จๆˆทๅๆˆ–ๅฏ†็ ไธๅˆๆณ•!\n\n"); return false; } if (strlen(user) > USER_NAME_LENGTH || strlen(password) > USER_PASSWORD_LENGTH) { printf("็”จๆˆทๅๆˆ–ๅฏ†็ ไธๅˆๆณ•!\n"); return false; } //ๆฃ€ๆต‹ๆ˜ฏๅฆ็™ปๅฝ• if (userID != ACCOUNT_NUM) { printf("็”จๆˆทๅทฒ็ป็™ปๅฝ•๏ผŒ่ฏทๅ…ˆ้€€ๅ‡บ.\n"); return false; } //ๅœจ่ดฆๆˆทๆ–‡ไปถไธญๆœ็›ธๅบ”็š„่ดฆๆˆทๅ for (int i = 0; i < ACCOUNT_NUM; i++) { if (strcmp(users.userName[i], user) == 0) { //้ชŒ่ฏ็›ธๅบ”็š„ๅฏ†็  if (strcmp(users.password[i], password) == 0) { //็™ปๅฝ•ๆˆๅŠŸๆ็คบ printf("็™ปๅฝ•ๆˆๅŠŸ๏ผ.\n"); userID = users.userID[i]; //ไธชๆ€งๅŒ–่ฎพ็ฝฎ memset(userName, 0, USER_NAME_LENGTH + 6); if (userID == 0) { strcat(userName, "mamnager "); strcat(userName, users.userName[i]); strcat(userName, "$"); } else { strcat(userName, users.userName[i]); strcat(userName, "#"); } return true; } else { //ๅฏ†็ ้”™่ฏฏ็š„ๆ็คบ printf("ๅฏ†็ ้”™่ฏฏ.\n"); return false; } } } //็”จๆˆทๅๆœชๆ‰พๅˆฐ printf("็™ปๅฝ•ๅคฑ่ดฅ๏ผŒๆฒกๆœ‰็›ธๅบ”็š„็”จๆˆท.\n"); return false; }; //็™ปๅ‡บๅŠŸ่ƒฝ void Logout() { userID = ACCOUNT_NUM; memset(&users, 0, sizeof(users)); memset(userName, 0, 6 + USER_NAME_LENGTH); Mount(); }; //ๆ นๆฎๆ–‡ไปถๅๅˆ›ๅปบๆ–‡ไปถ bool CreateFile(const char* filename) { //ๆ–‡ไปถๅๅˆๆณ•ๆ€งๆฃ€ๆต‹ if (filename == NULL || strlen(filename) > FILE_NAME_LENGTH) { printf("ไธๅˆๆณ•็š„ๆ–‡ไปถๅ.\n"); return false; } //ๆฃ€ๆต‹ๆ˜ฏๅฆ่ฟ˜ๆœ‰็ฉบ้—ฒ็š„block if (superBlock.s_num_fblock <= 0 || superBlock.s_num_finode <= 0) { printf("ๆฒกๆœ‰็ฉบ้—ดๅˆ›ๅปบๆ–ฐๆ–‡ไปถไบ†.\n"); return false; } //่‹ฅๆœ‰็ฉบ้—ฒblock๏ผŒๅˆ™ๆ‰พๆ–ฐ็š„inode int new_ino = 0; unsigned int new_block_addr = -1; for (; new_ino < INODE_NUM; new_ino++) { if (inode_bitmap[new_ino] == 0) { break; } } //ๆฃ€ๆต‹ๅฝ“ๅ‰็›ฎๅฝ•ๆ˜ฏๅฆๆœ‰ๅŒๅๆ–‡ไปถ for (int i = 0; i < DIRECTORY_NUM; i++) { if (strcmp(currentDirectory.fileName[i], filename) == 0) { inode* tmp_file_inode = new inode; int tmp_file_ino = currentDirectory.inodeID[i]; fseek(fd, INODE_START + tmp_file_ino * INODE_SIZE, SEEK_SET); fread(tmp_file_inode, sizeof(inode), 1, fd); if (tmp_file_inode->di_mode == 0) continue; else { printf("ๆ–‡ไปถๅ'%s' ๆœ‰้‡ๅค.\n", currentDirectory.fileName[i]); return false; } } } //ๆฃ€ๆต‹ๅฝ“ๅ‰็›ฎๅฝ•็š„ๆ–‡ไปถๆ•ฐ้‡ๆ˜ฏๅฆ่พพๅˆฐ้™ๅˆถ int itemCounter = 0; for (int i = 0; i < DIRECTORY_NUM; i++) { if (strlen(currentDirectory.fileName[i]) > 0) { itemCounter++; } } if (itemCounter >= DIRECTORY_NUM) { printf("ๆ–‡ไปถๅˆ›ๅปบ้”™่ฏฏ๏ผšๅฝ“ๅ‰ๆ–‡ไปถๅคนไธญๅญ˜ๅœจๅคชๅคšๆ–‡ไปถๆˆ–ๆ–‡ไปถๅคนใ€‚\n"); return false; } //ๅˆ›ๅปบๆ–ฐ็š„inode inode ifile_tmp; ifile_tmp.i_ino = new_ino; ifile_tmp.di_number = 1; ifile_tmp.di_mode = 1; //1 ่กจ็คบๆ–‡ไปถ ifile_tmp.di_size = 0; //ๆ–ฐๆ–‡ไปถๅคงๅฐไธบ0 memset(ifile_tmp.di_addr, -1, sizeof(unsigned int) * NADDR); ifile_tmp.di_uid = userID; //ๅฝ“ๅ‰็”จๆˆทid. ifile_tmp.di_grp = users.groupID[userID];//ๅฝ“ๅ‰็”จๆˆท็š„็ป„ ifile_tmp.permission = MAX_PERMISSION; ifile_tmp.icount = 0; time_t t = time(0); strftime(ifile_tmp.time, sizeof(ifile_tmp.time), "%Y/%m/%d %X", localtime(&t)); ifile_tmp.time[64]; fseek(fd, INODE_START + new_ino * INODE_SIZE, SEEK_SET); fwrite(&ifile_tmp, sizeof(inode), 1, fd); //ๆ›ดๆ–ฐๆ˜ ๅฐ„่กจ inode_bitmap[new_ino] = 1; fseek(fd, 2 * BLOCK_SIZE, SEEK_SET); fwrite(inode_bitmap, sizeof(unsigned short) * INODE_NUM, 1, fd); //ๆ›ดๆ–ฐ็›ฎๅฝ• //ๆŸฅๆ‰พๅฝ“ๅ‰็›ฎๅฝ•็š„inode int pos_directory_inode = 0; pos_directory_inode = currentDirectory.inodeID[0]; //"." inode tmp_directory_inode; fseek(fd, INODE_START + pos_directory_inode * INODE_SIZE, SEEK_SET); fread(&tmp_directory_inode, sizeof(inode), 1, fd); //ๅŠ ๅ…ฅๅฝ“ๅ‰็›ฎๅฝ• for (int i = 2; i < DIRECTORY_NUM; i++) { if (strlen(currentDirectory.fileName[i]) == 0) { strcat(currentDirectory.fileName[i], filename); currentDirectory.inodeID[i] = new_ino; break; } } //ๅ†™ๅ…ฅๆ–‡ไปถ fseek(fd, DATA_START + tmp_directory_inode.di_addr[0] * BLOCK_SIZE, SEEK_SET); fwrite(&currentDirectory, sizeof(directory), 1, fd); //ๆ›ดๆ–ฐ็›ธๅ…ณไฟกๆฏ directory tmp_directory = currentDirectory; int tmp_pos_directory_inode = pos_directory_inode; while (true) { tmp_directory_inode.di_number++; fseek(fd, INODE_START + tmp_pos_directory_inode * INODE_SIZE, SEEK_SET); fwrite(&tmp_directory_inode, sizeof(inode), 1, fd); //ๅฆ‚ๆžœๅˆฐไบ†ๆ น็›ฎๅฝ•ๅฐฑๅœๆญขๆ›ดๆ–ฐ if (tmp_directory.inodeID[1] == tmp_directory.inodeID[0]) { break; } tmp_pos_directory_inode = tmp_directory.inodeID[1]; //".." fseek(fd, INODE_START + tmp_pos_directory_inode * INODE_SIZE, SEEK_SET); fread(&tmp_directory_inode, sizeof(inode), 1, fd); fseek(fd, DATA_START + tmp_directory_inode.di_addr[0] * BLOCK_SIZE, SEEK_SET); fread(&tmp_directory, sizeof(directory), 1, fd); } //ๆ›ดๆ–ฐ่ถ…็บงๅ— superBlock.s_num_finode--; fseek(fd, BLOCK_SIZE, SEEK_SET); fwrite(&superBlock, sizeof(filsys), 1, fd); return true; }; //ๅˆ ้™คๆ–‡ไปถ bool DeleteFile(const char* filename) { //ๆ–‡ไปถๅๅˆๆณ•ๆ€งๆฃ€ๆต‹ if (filename == NULL || strlen(filename) > FILE_NAME_LENGTH) { printf("้”™่ฏฏ๏ผš้žๆณ•ๆ–‡ไปถๅ\n"); return false; } //1.ๆฃ€ๆต‹ๆ–‡ไปถๅๆ˜ฏๅฆๅญ˜ๅœจๅฝ“ๅ‰็›ฎๅฝ• int pos_in_directory = -1, tmp_file_ino; inode tmp_file_inode; do { pos_in_directory++; for (; pos_in_directory < DIRECTORY_NUM; pos_in_directory++) { if (strcmp(currentDirectory.fileName[pos_in_directory], filename) == 0) { break; } } if (pos_in_directory == DIRECTORY_NUM) { printf("้”™่ฏฏ:ๅฝ“ๅ‰็›ฎๅฝ•ๆœชๆ‰พๅˆฐๅˆ ้™คๆ–‡ไปถ\n"); return false; } //2.็œ‹inodeๆ˜ฏๅฆไธบๆ–‡ไปถ่ฟ˜ๆ˜ฏ็›ฎๅฝ• tmp_file_ino = currentDirectory.inodeID[pos_in_directory]; fseek(fd, INODE_START + tmp_file_ino * INODE_SIZE, SEEK_SET); fread(&tmp_file_inode, sizeof(inode), 1, fd); //ๆฃ€ๆต‹็›ฎๅฝ• } while (tmp_file_inode.di_mode == 0); //ๆƒ้™ๆฃ€ๆต‹ if (userID == tmp_file_inode.di_uid) { if (!(tmp_file_inode.permission & OWN_E)) { printf("ไธๅฅฝๆ„ๆ€๏ผŒไฝ ๆฒกๆœ‰ๆƒ้™ๅˆ ้™ค.\n"); return -1; } } else if (users.groupID[userID] == tmp_file_inode.di_grp) { if (!(tmp_file_inode.permission & GRP_E)) { printf("ไธๅฅฝๆ„ๆ€๏ผŒๆฒกๆœ‰ๆƒ้™ๅˆ ้™ค.\n"); return -1; } } else { if (!(tmp_file_inode.permission & ELSE_E)) { printf("ไธๅฅฝๆ„ๆ€๏ผŒๆฒกๆœ‰ๆƒ้™ๅˆ ้™ค.\n"); return -1; } } //3.ๅผ€ๅง‹ๅˆ ้™ค๏ผŒinode่ต‹ๅ€ผไธบ0 if (tmp_file_inode.icount > 0) { tmp_file_inode.icount--; fseek(fd, INODE_START + tmp_file_inode.i_ino * INODE_SIZE, SEEK_SET); fwrite(&tmp_file_inode, sizeof(inode), 1, fd); //ๆ›ดๆ–ฐ็›ฎๅฝ• int pos_directory_inode = currentDirectory.inodeID[0]; //"." inode tmp_directory_inode; fseek(fd, INODE_START + pos_directory_inode * INODE_SIZE, SEEK_SET); fread(&tmp_directory_inode, sizeof(inode), 1, fd); memset(currentDirectory.fileName[pos_in_directory], 0, FILE_NAME_LENGTH); currentDirectory.inodeID[pos_in_directory] = -1; fseek(fd, DATA_START + tmp_directory_inode.di_addr[0] * BLOCK_SIZE, SEEK_SET); fwrite(&currentDirectory, sizeof(directory), 1, fd); //ๆ›ดๆ–ฐ็›ธๅ…ณไฟกๆฏ directory tmp_directory = currentDirectory; int tmp_pos_directory_inode = pos_directory_inode; while (true) { tmp_directory_inode.di_number--; fseek(fd, INODE_START + tmp_pos_directory_inode * INODE_SIZE, SEEK_SET); fwrite(&tmp_directory_inode, sizeof(inode), 1, fd); if (tmp_directory.inodeID[1] == tmp_directory.inodeID[0]) { break; } tmp_pos_directory_inode = tmp_directory.inodeID[1]; //".." fseek(fd, INODE_START + tmp_pos_directory_inode * INODE_SIZE, SEEK_SET); fread(&tmp_directory_inode, sizeof(inode), 1, fd); fseek(fd, DATA_START + tmp_directory_inode.di_addr[0] * BLOCK_SIZE, SEEK_SET); fread(&tmp_directory, sizeof(directory), 1, fd); } return true; } int tmp_fill[sizeof(inode)]; memset(tmp_fill, 0, sizeof(inode)); fseek(fd, INODE_START + tmp_file_ino * INODE_SIZE, SEEK_SET); fwrite(&tmp_fill, sizeof(inode), 1, fd); //4.ๆ›ดๆ–ฐๆ˜ ๅฐ„ inode_bitmap[tmp_file_ino] = 0; fseek(fd, 2 * BLOCK_SIZE, SEEK_SET); fwrite(&inode_bitmap, sizeof(unsigned short) * INODE_NUM, 1, fd); for (int i = 0; i < NADDR - 2; i++) { if(tmp_file_inode.di_addr[i] != -1) recycle_block(tmp_file_inode.di_addr[i]); else break; } if (tmp_file_inode.di_addr[NADDR - 2] != -1) { unsigned int f1[128]; fseek(fd, DATA_START + tmp_file_inode.di_addr[NADDR - 2] * BLOCK_SIZE, SEEK_SET); fread(f1, sizeof(f1), 1, fd); for (int k = 0; k < 128; k++) { recycle_block(f1[k]); } recycle_block(tmp_file_inode.di_addr[NADDR - 2]); } // 5. ๆ›ดๆ–ฐ็›ฎๅฝ• int pos_directory_inode = currentDirectory.inodeID[0]; //"." inode tmp_directory_inode; fseek(fd, INODE_START + pos_directory_inode * INODE_SIZE, SEEK_SET); fread(&tmp_directory_inode, sizeof(inode), 1, fd); //ๆ›ดๆ–ฐ็›ฎๅฝ•้กน memset(currentDirectory.fileName[pos_in_directory], 0, FILE_NAME_LENGTH); currentDirectory.inodeID[pos_in_directory] = -1; fseek(fd, DATA_START + tmp_directory_inode.di_addr[0] * BLOCK_SIZE, SEEK_SET); fwrite(&currentDirectory, sizeof(directory), 1, fd); directory tmp_directory = currentDirectory; int tmp_pos_directory_inode = pos_directory_inode; while (true) { tmp_directory_inode.di_number--; fseek(fd, INODE_START + tmp_pos_directory_inode * INODE_SIZE, SEEK_SET); fwrite(&tmp_directory_inode, sizeof(inode), 1, fd); if (tmp_directory.inodeID[1] == tmp_directory.inodeID[0]) { break; } tmp_pos_directory_inode = tmp_directory.inodeID[1]; //".." fseek(fd, INODE_START + tmp_pos_directory_inode * INODE_SIZE, SEEK_SET); fread(&tmp_directory_inode, sizeof(inode), 1, fd); fseek(fd, DATA_START + tmp_directory_inode.di_addr[0] * BLOCK_SIZE, SEEK_SET); fread(&tmp_directory, sizeof(directory), 1, fd); } //6.ๆ›ดๆ–ฐ่ถ…็บงๅ— superBlock.s_num_finode++; fseek(fd, BLOCK_SIZE, SEEK_SET); fwrite(&superBlock, sizeof(filsys), 1, fd); return true; } //ๆ นๆฎๆ–‡ไปถๅๆ‰“ๅผ€ๆ–‡ไปถ inode* OpenFile(const char* filename) { //ๆ–‡ไปถๅๆฃ€ๆต‹ if (filename == NULL || strlen(filename) > FILE_NAME_LENGTH) { printf("ไธๅˆๆณ•ๆ–‡ไปถๅ.\n"); return NULL; } //1. ๆŸฅๆ‰พๆ˜ฏๅฆๅญ˜ๅœจ่ฏฅๆ–‡ไปถ. int pos_in_directory = -1; inode* tmp_file_inode = new inode; do { pos_in_directory++; for (; pos_in_directory < DIRECTORY_NUM; pos_in_directory++) { if (strcmp(currentDirectory.fileName[pos_in_directory], filename) == 0) { break; } } if (pos_in_directory == DIRECTORY_NUM) { printf("ๆฒกๆœ‰ๆ‰พๅˆฐ่ฏฅๆ–‡ไปถ.\n"); return NULL; } // 2. ๅˆคๆ–ญinodeๆ˜ฏๅฆๆ˜ฏ็›ฎๅฝ• int tmp_file_ino = currentDirectory.inodeID[pos_in_directory]; fseek(fd, INODE_START + tmp_file_ino * INODE_SIZE, SEEK_SET); fread(tmp_file_inode, sizeof(inode), 1, fd); } while (tmp_file_inode->di_mode == 0); return tmp_file_inode; }; //ๅœจๆ–‡ไปถๅฐพๆทปๅŠ ๆ•ฐๆฎ int Write(inode& ifile, const char* content) { if (content == NULL) { printf("ไธๅˆๆณ•็š„ๅ†…ๅฎน.\n"); return -1; } //ๆƒ้™ๆฃ€ๆต‹ if (userID == ifile.di_uid) { if (!(ifile.permission & OWN_W)) { printf("ๆƒ้™ไธๅคŸ.\n"); return -1; } } else if (users.groupID[userID] == ifile.di_grp) { if (!(ifile.permission & GRP_W)) { printf("ๆƒ้™ไธๅคŸ.\n"); return -1; } } else { if (!(ifile.permission & ELSE_W)) { printf("ๆƒ้™ไธๅคŸ.\n"); return -1; } } // 1.ๆฃ€ๆต‹ๆ–‡ไปถๆ˜ฏๅฆ่พพๅˆฐไบ†ๆœ€ๅคงๅคงๅฐ int len_content = strlen(content); unsigned int new_file_length = len_content + ifile.di_size; if (new_file_length >= FILE_SIZE_MAX) { printf("ๆ–‡ไปถไธ่ƒฝๅ†ๅคงไบ†.\n"); return -1; } //2. ๅ–ๅพ—ๆ‰€้œ€็š„inode๏ผŒๅนถๆŸฅ็œ‹ๆ˜ฏๅฆๆœ‰็ฉบ้—ฒ. unsigned int block_num; if (ifile.di_addr[0] == -1)block_num = -1; else { for (int i = 0; i < NADDR - 2; i++) { if (ifile.di_addr[i] != -1) block_num = ifile.di_addr[i]; else break; } int f1[128]; fseek(fd, DATA_START + ifile.di_addr[NADDR - 2] * BLOCK_SIZE, SEEK_SET); int num; if (ifile.di_size%BLOCK_SIZE == 0) num = ifile.di_size / BLOCK_SIZE; else num = ifile.di_size / BLOCK_SIZE + 1; if (num > 4 && num <=132) { fseek(fd, DATA_START + ifile.di_addr[NADDR - 2] * BLOCK_SIZE, SEEK_SET); fread(f1, sizeof(f1), 1, fd); block_num = f1[num - 4]; } } int free_space_firstBlock = BLOCK_SIZE - ifile.di_size % BLOCK_SIZE; unsigned int num_block_needed; if (len_content - free_space_firstBlock > 0) { num_block_needed = (len_content - free_space_firstBlock) / BLOCK_SIZE + 1; } else { num_block_needed = 0; } //ๆฃ€ๆŸฅๆ˜ฏๅฆๆœ‰็ฉบ้—ฒ if (num_block_needed > superBlock.s_num_fblock) { printf("ๅ†…ๅญ˜ไธๅคŸ.\n"); return -1; } //3. ๅ†™ๅ…ฅ็ฌฌไธ€ๅ—. if (ifile.di_addr[0] == -1) { find_free_block(block_num); ifile.di_addr[0] = block_num; fseek(fd, DATA_START + block_num * BLOCK_SIZE, SEEK_SET); } else fseek(fd, DATA_START + block_num * BLOCK_SIZE + ifile.di_size % BLOCK_SIZE, SEEK_SET); char data[BLOCK_SIZE]; if (num_block_needed == 0) { fwrite(content, len_content, 1, fd); fseek(fd, DATA_START + block_num * BLOCK_SIZE, SEEK_SET); fread(data, sizeof(data), 1, fd); ifile.di_size += len_content; } else { fwrite(content, free_space_firstBlock, 1, fd); fseek(fd, DATA_START + block_num * BLOCK_SIZE, SEEK_SET); fread(data, sizeof(data), 1, fd); ifile.di_size += free_space_firstBlock; } //4. ๅ†™ๅ…ฅๅ…ถไป–ๅ—๏ผŒๆ›ดๆ–ฐๆ–‡ไปถไฟกๆฏใ€‚ char write_buf[BLOCK_SIZE]; unsigned int new_block_addr = -1; unsigned int content_write_pos = free_space_firstBlock; //ๅพช็Žฏๅ†™ๅ…ฅ if ((len_content + ifile.di_size) / BLOCK_SIZE + ((len_content + ifile.di_size) % BLOCK_SIZE == 0 ? 0 : 1) <= NADDR - 2) { for (int i = 0; i < num_block_needed; i++) { find_free_block(new_block_addr); if (new_block_addr == -1)return -1; for (int j = 0; j < NADDR - 2; j++) { if (ifile.di_addr[j] == -1) { ifile.di_addr[j] = new_block_addr; break; } } memset(write_buf, 0, BLOCK_SIZE); unsigned int tmp_counter = 0; for (; tmp_counter < BLOCK_SIZE; tmp_counter++) { if (content[content_write_pos + tmp_counter] == '\0') break; write_buf[tmp_counter] = content[content_write_pos + tmp_counter]; } content_write_pos += tmp_counter; fseek(fd, DATA_START + new_block_addr * BLOCK_SIZE, SEEK_SET); fwrite(write_buf, tmp_counter, 1, fd); fseek(fd, DATA_START + new_block_addr * BLOCK_SIZE, SEEK_SET); fread(data, sizeof(data), 1, fd); ifile.di_size += tmp_counter; } } else if ((len_content+ifile.di_size)/BLOCK_SIZE+((len_content + ifile.di_size) % BLOCK_SIZE == 0 ? 0 : 1)> NADDR - 2) { for (int i = 0; i < NADDR - 2; i++) { if (ifile.di_addr[i] != -1)continue; memset(write_buf, 0, BLOCK_SIZE); new_block_addr = -1; find_free_block(new_block_addr); if (new_block_addr == -1)return -1; ifile.di_addr[i] = new_block_addr; unsigned int tmp_counter = 0; for (; tmp_counter < BLOCK_SIZE; tmp_counter++) { if (content[content_write_pos + tmp_counter] == '\0') { break; } write_buf[tmp_counter] = content[content_write_pos + tmp_counter]; } content_write_pos += tmp_counter; fseek(fd, DATA_START + new_block_addr * BLOCK_SIZE, SEEK_SET); fwrite(write_buf, tmp_counter, 1, fd); ifile.di_size += tmp_counter; } unsigned int f1[BLOCK_SIZE / sizeof(unsigned int)] = { 0 }; new_block_addr = -1; find_free_block(new_block_addr); if (new_block_addr == -1)return -1; ifile.di_addr[NADDR - 2] = new_block_addr; for (int i = 0;i < BLOCK_SIZE / sizeof(unsigned int);i++) { new_block_addr = -1; find_free_block(new_block_addr); if (new_block_addr == -1)return -1; else f1[i] = new_block_addr; } fseek(fd, DATA_START + ifile.di_addr[4] * BLOCK_SIZE, SEEK_SET); fwrite(f1, sizeof(f1), 1, fd); bool flag = 0; for (int j = 0; j < BLOCK_SIZE / sizeof(int); j++) { fseek(fd, DATA_START + f1[j] * BLOCK_SIZE, SEEK_SET); unsigned int tmp_counter = 0; for (; tmp_counter < BLOCK_SIZE; tmp_counter++) { if (content[content_write_pos + tmp_counter] == '\0') { //tmp_counter--; flag = 1; break; } write_buf[tmp_counter] = content[content_write_pos + tmp_counter]; } content_write_pos += tmp_counter; fwrite(write_buf, tmp_counter, 1, fd); ifile.di_size += tmp_counter; if (flag == 1) break; } } time_t t = time(0); strftime(ifile.time, sizeof(ifile.time), "%Y/%m/%d %X", localtime(&t)); ifile.time[64] = 0; fseek(fd, INODE_START + ifile.i_ino * INODE_SIZE, SEEK_SET); fwrite(&ifile, sizeof(inode), 1, fd); //5.ๆ›ดๆ–ฐ่ถ…็บงๅ— fseek(fd, BLOCK_SIZE, SEEK_SET); fwrite(&superBlock, sizeof(superBlock), 1, fd); return len_content; }; //่พ“ๅ‡บๆ–‡ไปถไฟกๆฏ void PrintFile(inode& ifile) { //ๆƒ้™ๆฃ€ๆต‹ if (userID == ifile.di_uid) { if (!(ifile.permission & OWN_R)) { printf("ๆฒกๆœ‰่ฏปๅ–ๆƒ้™.\n"); return; } } else if (users.groupID[userID] == ifile.di_grp) { if (!(ifile.permission & GRP_R)) { printf("ๆฒกๆœ‰่ฏปๅ–ๆƒ้™.\n"); return; } } else { if (!(ifile.permission & ELSE_R)) { printf("ๆฒกๆœ‰่ฏปๅ–ๆƒ้™.\n"); return; } } int block_num = ifile.di_size / BLOCK_SIZE + 1; int print_line_num = 0; //16 bytes ๆฏไธ€่กŒ. //ไปŽๅ—ไธญ่ฏปๅ–ๆ–‡ไปถ char stack[BLOCK_SIZE]; if (block_num <= NADDR - 2) { for (int i = 0; i < block_num; i++) { fseek(fd, DATA_START + ifile.di_addr[i] * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(stack), 1, fd); for (int j = 0; j < BLOCK_SIZE; j++) { if (stack[j] == '\0')break; if (j % 16 == 0) { printf("\n"); printf("%d\t", ++print_line_num); } printf("%c", stack[j]); } } } else if (block_num > NADDR - 2) { for (int i = 0; i < NADDR - 2; i++) { fseek(fd, DATA_START + ifile.di_addr[i] * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(stack), 1, fd); for (int j = 0; j < BLOCK_SIZE; j++) { if (stack[j] == '\0')break; if (j % 16 == 0) { printf("\n"); printf("%d\t", ++print_line_num); } printf("%c", stack[j]); } } unsigned int f1[BLOCK_SIZE / sizeof(unsigned int)] = { 0 }; fseek(fd, DATA_START + ifile.di_addr[NADDR - 2] * BLOCK_SIZE, SEEK_SET); fread(f1, sizeof(f1), 1, fd); for (int i = 0; i < block_num - (NADDR - 2); i++) { fseek(fd, DATA_START + f1[i] * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(stack), 1, fd); for (int j = 0; j < BLOCK_SIZE; j++) { if (stack[j] == '\0')break; if (j % 16 == 0) { printf("\n"); printf("%d\t", ++print_line_num); } printf("%c", stack[j]); } } } printf("\n\n\n"); }; //ๅˆ›ๅปบๆ–ฐ็›ฎๅฝ•๏ผŒๆ–ฐ็›ฎๅฝ•ๅŒ…ๅซ. .. bool MakeDir(const char* dirname) { //ๅ‚ๆ•ฐๆฃ€ๆต‹ if (dirname == NULL || strlen(dirname) > FILE_NAME_LENGTH) { printf("ไธๅˆๆณ•็š„็›ฎๅฝ•ๅ.\n"); return false; } // 1. ๆฃ€ๆŸฅinodeๆ˜ฏๅฆ็”จๅ…‰ไบ†ใ€‚ if (superBlock.s_num_fblock <= 0 || superBlock.s_num_finode <= 0) { printf("ๆฒกๆœ‰่ถณๅคŸ็ฉบ้—ดๅˆ›ๅปบ็›ฎๅฝ•ไบ†.\n"); return false; } int new_ino = 0; unsigned int new_block_addr = 0; for (; new_ino < INODE_NUM; new_ino++) { if (inode_bitmap[new_ino] == 0) { break; } } find_free_block(new_block_addr); if (new_block_addr == -1) return false; if (new_ino == INODE_NUM || new_block_addr == BLOCK_NUM) { printf("ๆ–‡ไปถๅˆ›ๅปบ้”™่ฏฏ๏ผšๅ‰ฉไฝ™็ฉบ้—ดไธ่ถณ\n"); return false; } //2. ๆฃ€ๆŸฅ็›ฎๅฝ•ๅๅœจๅฝ“ๅ‰็›ฎๅฝ•ๆ˜ฏๅฆๆœ‰้‡ๅ. for (int i = 0; i < DIRECTORY_NUM; i++) { if (strcmp(currentDirectory.fileName[i], dirname) == 0) { inode* tmp_file_inode = new inode; int tmp_file_ino = currentDirectory.inodeID[i]; fseek(fd, INODE_START + tmp_file_ino * INODE_SIZE, SEEK_SET); fread(tmp_file_inode, sizeof(inode), 1, fd); if (tmp_file_inode->di_mode == 1) continue; else { printf("ๆ–‡ไปถๅˆ›ๅปบ้”™่ฏฏ๏ผšๆ–‡ไปถๅ '%s' ๅทฒ็ป่ขซไฝฟ็”จไบ†ใ€‚\n", currentDirectory.fileName[i]); return false; } } } //3. ๆฃ€ๆŸฅๅฝ“ๅ‰็›ฎๅฝ•้กนๆ˜ฏๅฆๅคชๅคšไบ†. int itemCounter = 0; for (int i = 0; i < DIRECTORY_NUM; i++) { if (strlen(currentDirectory.fileName[i]) > 0) { itemCounter++; } } if (itemCounter >= DIRECTORY_NUM) { printf("ๆ–‡ไปถๅˆ›ๅปบ้”™่ฏฏ๏ผšๅฝ“ๅ‰ๆ–‡ไปถๅคนไธญๅญ˜ๅœจๅคชๅคšๆ–‡ไปถๆˆ–ๆ–‡ไปถๅคนใ€‚\n"); return false; } //4. ๅˆ›ๅปบๆ–ฐinode. inode idir_tmp; idir_tmp.i_ino = new_ino; idir_tmp.di_number = 1; idir_tmp.di_mode = 0; //0 ไปฃ่กจ็›ฎๅฝ• idir_tmp.di_size = sizeof(directory); memset(idir_tmp.di_addr, -1, sizeof(unsigned int) * NADDR); idir_tmp.di_addr[0] = new_block_addr; idir_tmp.di_uid = userID; idir_tmp.di_grp = users.groupID[userID]; time_t t = time(0); strftime(idir_tmp.time, sizeof(idir_tmp.time), "%Y/%m/%d %X", localtime(&t)); idir_tmp.time[64] = 0; idir_tmp.icount = 0; idir_tmp.permission = MAX_PERMISSION; fseek(fd, INODE_START + new_ino * INODE_SIZE, SEEK_SET); fwrite(&idir_tmp, sizeof(inode), 1, fd); //5. ๅˆ›ๅปบ็›ฎๅฝ•ๆ–‡ไปถ. directory tmp_dir; memset(tmp_dir.fileName, 0, sizeof(char) * DIRECTORY_NUM * FILE_NAME_LENGTH); memset(tmp_dir.inodeID, -1, sizeof(unsigned int) * DIRECTORY_NUM); strcpy(tmp_dir.fileName[0], "."); tmp_dir.inodeID[0] = new_ino; strcpy(tmp_dir.fileName[1], ".."); tmp_dir.inodeID[1] = currentDirectory.inodeID[0]; fseek(fd, DATA_START + new_block_addr * BLOCK_SIZE, SEEK_SET); fwrite(&tmp_dir, sizeof(directory), 1, fd); //6. ๆ›ดๆ–ฐๆ˜ ๅฐ„่กจ. inode_bitmap[new_ino] = 1; fseek(fd, 2 * BLOCK_SIZE, SEEK_SET); fwrite(inode_bitmap, sizeof(unsigned short) * INODE_NUM, 1, fd); //7. ๆ›ดๆ–ฐ็›ฎๅฝ•. int pos_directory_inode = 0; pos_directory_inode = currentDirectory.inodeID[0]; //"." inode tmp_directory_inode; fseek(fd, INODE_START + pos_directory_inode * INODE_SIZE, SEEK_SET); fread(&tmp_directory_inode, sizeof(inode), 1, fd); for (int i = 2; i < DIRECTORY_NUM; i++) { if (strlen(currentDirectory.fileName[i]) == 0) { strcat(currentDirectory.fileName[i], dirname); currentDirectory.inodeID[i] = new_ino; break; } } fseek(fd, DATA_START + tmp_directory_inode.di_addr[0] * BLOCK_SIZE, SEEK_SET); fwrite(&currentDirectory, sizeof(directory), 1, fd); directory tmp_directory = currentDirectory; int tmp_pos_directory_inode = pos_directory_inode; while (true) { tmp_directory_inode.di_number++; fseek(fd, INODE_START + tmp_pos_directory_inode * INODE_SIZE, SEEK_SET); fwrite(&tmp_directory_inode, sizeof(inode), 1, fd); if (tmp_directory.inodeID[1] == tmp_directory.inodeID[0]) { break; } tmp_pos_directory_inode = tmp_directory.inodeID[1]; //".." fseek(fd, INODE_START + tmp_pos_directory_inode * INODE_SIZE, SEEK_SET); fread(&tmp_directory_inode, sizeof(inode), 1, fd); fseek(fd, DATA_START + tmp_directory_inode.di_addr[0] * BLOCK_SIZE, SEEK_SET); fread(&tmp_directory, sizeof(directory), 1, fd); } // 8. ๆ›ดๆ–ฐ่ถ…็บงๅ—. superBlock.s_num_finode--; fseek(fd, BLOCK_SIZE, SEEK_SET); fwrite(&superBlock, sizeof(filsys), 1, fd); return true; }; //ๅˆ ้™คไธ€ไธช็›ฎๅฝ•ๅ’Œ็›ฎๅฝ•ไธ‹็š„ๆ‰€ๆœ‰ๆ–‡ไปถ bool RemoveDir(const char* dirname) { if (dirname == NULL || strlen(dirname) > FILE_NAME_LENGTH) { printf("็›ฎๅฝ•ไธๅˆๆณ•.\n"); return false; } //1. ๆฃ€ๆŸฅ็›ฎๅฝ•ๆ˜ฏๅฆๅญ˜ๅœจ int pos_in_directory = 0; int tmp_dir_ino; inode tmp_dir_inode; do { pos_in_directory++; for (; pos_in_directory < DIRECTORY_NUM; pos_in_directory++) { if (strcmp(currentDirectory.fileName[pos_in_directory], dirname) == 0) { break; } } if (pos_in_directory == DIRECTORY_NUM) { printf("ๆฒกๆœ‰ๆ‰พๅˆฐ่ฏฅ็›ฎๅฝ•.\n"); return false; } // 2. ๆŸฅ็œ‹inodeๆ˜ฏๅฆๆ˜ฏๆ–‡ไปถ. tmp_dir_ino = currentDirectory.inodeID[pos_in_directory]; fseek(fd, INODE_START + tmp_dir_ino * INODE_SIZE, SEEK_SET); fread(&tmp_dir_inode, sizeof(inode), 1, fd); //Directory check } while (tmp_dir_inode.di_mode == 1); //3. ๆƒ้™ๆฃ€ if (userID == tmp_dir_inode.di_uid) { if (!(tmp_dir_inode.permission & OWN_E)) { printf("ๆƒ้™ไธๅคŸ.\n"); return false; } } else if (users.groupID[userID] == tmp_dir_inode.di_grp) { if (!(tmp_dir_inode.permission & GRP_E)) { printf("ๆƒ้™ไธๅคŸ.\n"); return false; } } else { if (!(tmp_dir_inode.permission & ELSE_E)) { printf("ๆƒ้™ไธๅคŸ.\n"); return false; } } //4. ๅผ€ๅง‹ๅˆ ้™ค if (tmp_dir_inode.icount > 0) { tmp_dir_inode.icount--; fseek(fd, INODE_START + tmp_dir_inode.i_ino * INODE_SIZE, SEEK_SET); fwrite(&tmp_dir_inode, sizeof(inode), 1, fd); //ๆ›ดๆ–ฐ็›ฎๅฝ• int pos_directory_inode = currentDirectory.inodeID[0]; //"." inode tmp_directory_inode; fseek(fd, INODE_START + pos_directory_inode * INODE_SIZE, SEEK_SET); fread(&tmp_directory_inode, sizeof(inode), 1, fd); memset(currentDirectory.fileName[pos_in_directory], 0, FILE_NAME_LENGTH); currentDirectory.inodeID[pos_in_directory] = -1; fseek(fd, DATA_START + tmp_directory_inode.di_addr[0] * BLOCK_SIZE, SEEK_SET); fwrite(&currentDirectory, sizeof(directory), 1, fd); directory tmp_directory = currentDirectory; int tmp_pos_directory_inode = pos_directory_inode; while (true) { tmp_directory_inode.di_number--; fseek(fd, INODE_START + tmp_pos_directory_inode * INODE_SIZE, SEEK_SET); fwrite(&tmp_directory_inode, sizeof(inode), 1, fd); if (tmp_directory.inodeID[1] == tmp_directory.inodeID[0]) { break; } tmp_pos_directory_inode = tmp_directory.inodeID[1]; //".." fseek(fd, INODE_START + tmp_pos_directory_inode * INODE_SIZE, SEEK_SET); fread(&tmp_directory_inode, sizeof(inode), 1, fd); fseek(fd, DATA_START + tmp_directory_inode.di_addr[0] * BLOCK_SIZE, SEEK_SET); fread(&tmp_directory, sizeof(directory), 1, fd); } return true; } directory tmp_dir; fseek(fd, DATA_START + tmp_dir_inode.di_addr[0] * BLOCK_SIZE, SEEK_SET); fread(&tmp_dir, sizeof(directory), 1, fd); //ๆŸฅๆ‰พๆ‰€ๆœ‰็š„ๅญๆ–‡ไปถ็›ฎๅฝ•๏ผŒๅนถๅˆ ้™ค. inode tmp_sub_inode; char tmp_sub_filename[FILE_NAME_LENGTH]; memset(tmp_sub_filename, 0, FILE_NAME_LENGTH); for (int i = 2; i < DIRECTORY_NUM; i++) { if (strlen(tmp_dir.fileName[i]) > 0) { strcpy(tmp_sub_filename, tmp_dir.fileName[i]); fseek(fd, INODE_START + tmp_dir.inodeID[i] * INODE_SIZE, SEEK_SET); fread(&tmp_sub_inode, sizeof(inode), 1, fd); directory tmp_swp; tmp_swp = currentDirectory; currentDirectory = tmp_dir; tmp_dir = tmp_swp; if (tmp_sub_inode.di_mode == 1) { DeleteFile(tmp_sub_filename); } else if (tmp_sub_inode.di_mode == 0) { RemoveDir(tmp_sub_filename); } tmp_swp = currentDirectory; currentDirectory = tmp_dir; tmp_dir = tmp_swp; } } //5.ๅฐ†inode่ต‹ไธบ0. int tmp_fill[sizeof(inode)]; memset(tmp_fill, 0, sizeof(inode)); fseek(fd, INODE_START + tmp_dir_ino * INODE_SIZE, SEEK_SET); fwrite(&tmp_fill, sizeof(inode), 1, fd); //6. ๆ›ดๆ–ฐๆ˜ ๅฐ„ inode_bitmap[tmp_dir_ino] = 0; fseek(fd, 2 * BLOCK_SIZE, SEEK_SET); fwrite(&inode_bitmap, sizeof(unsigned short) * INODE_NUM, 1, fd); for (int i = 0; i < (tmp_dir_inode.di_size / BLOCK_SIZE + 1); i++) { recycle_block(tmp_dir_inode.di_addr[i]); } //7. ๆ›ดๆ–ฐ็›ฎๅฝ• int pos_directory_inode = currentDirectory.inodeID[0]; //"." inode tmp_directory_inode; fseek(fd, INODE_START + pos_directory_inode * INODE_SIZE, SEEK_SET); fread(&tmp_directory_inode, sizeof(inode), 1, fd); memset(currentDirectory.fileName[pos_in_directory], 0, FILE_NAME_LENGTH); currentDirectory.inodeID[pos_in_directory] = -1; fseek(fd, DATA_START + tmp_directory_inode.di_addr[0] * INODE_SIZE, SEEK_SET); fwrite(&currentDirectory, sizeof(directory), 1, fd); directory tmp_directory = currentDirectory; int tmp_pos_directory_inode = pos_directory_inode; while (true) { tmp_directory_inode.di_number--; fseek(fd, INODE_START + tmp_pos_directory_inode * INODE_SIZE, SEEK_SET); fwrite(&tmp_directory_inode, sizeof(inode), 1, fd); if (tmp_directory.inodeID[1] == tmp_directory.inodeID[0]) { break; } tmp_pos_directory_inode = tmp_directory.inodeID[1]; //".." fseek(fd, INODE_START + tmp_pos_directory_inode * INODE_SIZE, SEEK_SET); fread(&tmp_directory_inode, sizeof(inode), 1, fd); fseek(fd, DATA_START + tmp_directory_inode.di_addr[0] * BLOCK_SIZE, SEEK_SET); fread(&tmp_directory, sizeof(directory), 1, fd); } //8 ๆ›ดๆ–ฐ่ถ…็บงๅ— superBlock.s_num_finode++; fseek(fd, BLOCK_SIZE, SEEK_SET); fwrite(&superBlock, sizeof(filsys), 1, fd); return true; }; //ๆ‰“ๅผ€ไธ€ไธช็›ฎๅฝ• bool OpenDir(const char* dirname) { //ๅ‚ๆ•ฐๆฃ€ๆต‹ if (dirname == NULL || strlen(dirname) > FILE_NAME_LENGTH) { printf("ไธๅˆๆณ•ๅ็งฐ.\n"); return false; } //1. ๆฃ€ๆŸฅๆ˜ฏๅฆๅญ˜ๅœจ่ฏฅ็›ฎๅฝ•. int pos_in_directory = 0; inode tmp_dir_inode; int tmp_dir_ino; do { for (; pos_in_directory < DIRECTORY_NUM; pos_in_directory++) { if (strcmp(currentDirectory.fileName[pos_in_directory], dirname) == 0) { break; } } if (pos_in_directory == DIRECTORY_NUM) { printf("ๅˆ ้™ค้”™่ฏฏ๏ผšๆ–‡ไปถๅคนไธๅญ˜ๅœจใ€‚\n"); return false; } //2. ๆŸฅๆ‰พinode๏ผŒๆŸฅ็œ‹ๆ˜ฏๅฆไธบ็›ฎๅฝ•. tmp_dir_ino = currentDirectory.inodeID[pos_in_directory]; fseek(fd, INODE_START + tmp_dir_ino * INODE_SIZE, SEEK_SET); fread(&tmp_dir_inode, sizeof(inode), 1, fd); } while (tmp_dir_inode.di_mode == 1); if (userID == tmp_dir_inode.di_uid) { if (tmp_dir_inode.permission & OWN_E != OWN_E) { printf("ๆƒ้™ไธๅคŸ.\n"); return NULL; } } else if (users.groupID[userID] == tmp_dir_inode.di_grp) { if (tmp_dir_inode.permission & GRP_E != GRP_E) { printf("ๆƒ้™ไธๅคŸ.\n"); return NULL; } } else { if (tmp_dir_inode.permission & ELSE_E != ELSE_E) { printf("ๆƒ้™ไธๅคŸ.\n"); return NULL; } } //3. ๆ›ดๆ–ฐๅฝ“ๅ‰็›ฎๅฝ•. directory new_current_dir; fseek(fd, DATA_START + tmp_dir_inode.di_addr[0] * BLOCK_SIZE, SEEK_SET); fread(&new_current_dir, sizeof(directory), 1, fd); currentDirectory = new_current_dir; if (dirname[0] == '.' && dirname[1] == 0) { dir_pointer; } else if (dirname[0] == '.' && dirname[1] == '.' && dirname[2] == 0) { if (dir_pointer != 0) dir_pointer--; } else { for (int i = 0; i < 14; i++) { ab_dir[dir_pointer][i] = dirname[i]; } dir_pointer++; } return true; }; //ๆ˜พ็คบๅฝ“ๅ‰็›ฎๅฝ•ไธ‹็š„ๆ–‡ไปถไฟกๆฏ void List() { printf("\n name\tuser\tgroup\tinodeID\tIcount\tsize\tpermission\ttime\n"); for (int i = 0; i < DIRECTORY_NUM; i++) { if (strlen(currentDirectory.fileName[i]) > 0) { inode tmp_inode; fseek(fd, INODE_START + currentDirectory.inodeID[i] * INODE_SIZE, SEEK_SET); fread(&tmp_inode, sizeof(inode), 1, fd); const char* tmp_type = tmp_inode.di_mode == 0 ? "d" : "-"; const char* tmp_user = users.userName[tmp_inode.di_uid]; const int tmp_grpID = tmp_inode.di_grp; printf("%10s\t%s\t%d\t%d\t%d\t%u\t%s", currentDirectory.fileName[i], tmp_user, tmp_grpID, tmp_inode.i_ino, tmp_inode.icount, tmp_inode.di_size, tmp_type); for (int x = 8; x > 0; x--) { if (tmp_inode.permission & (1 << x)) { if ((x + 1) % 3 == 0) printf("r"); else if ((x + 1) % 3 == 2) printf("w"); else printf("x"); } else printf("-"); } if(tmp_inode.permission & 1) printf("x\t"); else printf("-\t"); printf("%s\n", tmp_inode.time); } } printf("\n\n"); } //ๆ˜พ็คบ็ปๅฏน็›ฎๅฝ•. void Ab_dir() { for (int i = 0; i < dir_pointer; i++) printf("%s/", ab_dir[i]); printf("\n"); } //ไฟฎๆ”นๆ–‡ไปถๆƒ้™ void Chmod(char* filename) { printf("0=ๆ–‡ไปถ๏ผŒ1=็›ฎๅฝ•๏ผŒ่ฏท่พ“ๅ…ฅ:"); int tt; scanf("%d", &tt); if (filename == NULL || strlen(filename) > FILE_NAME_LENGTH) { printf("ไธๅˆๆณ•.\n"); return; } //1. ๆฃ€ๆŸฅๆ˜ฏๅฆๅญ˜ๅœจ. int pos_in_directory = -1; inode* tmp_file_inode = new inode; do { pos_in_directory++; for (; pos_in_directory < DIRECTORY_NUM; pos_in_directory++) { if (strcmp(currentDirectory.fileName[pos_in_directory], filename) == 0) { break; } } if (pos_in_directory == DIRECTORY_NUM) { printf("ๆฒกๆœ‰ๆ‰พๅˆฐ.\n"); return; } //2. ๆฃ€ๆŸฅๆ˜ฏๅฆๅญ˜ๅœจ็›ฎๅฝ•. int tmp_file_ino = currentDirectory.inodeID[pos_in_directory]; fseek(fd, INODE_START + tmp_file_ino * INODE_SIZE, SEEK_SET); fread(tmp_file_inode, sizeof(inode), 1, fd); } while (tmp_file_inode->di_mode == tt); printf("่ฏท่พ“ๅ…ฅ 0&1 ไธฒ็ป™ไบˆๆƒ้™\n"); printf("ๆ ผๅผ: rwerwerwe\n"); char str[10]; scanf("%s", &str); if (userID == tmp_file_inode->di_uid) { if (!(tmp_file_inode->permission & OWN_E)) { printf("ๆƒ้™ไธๅคŸ.\n"); return; } } else if (users.groupID[userID] == tmp_file_inode->di_grp) { if (!(tmp_file_inode->permission & GRP_E)) { printf("ๆƒ้™ไธๅคŸ.\n"); return; } } else { if (!(tmp_file_inode->permission & ELSE_E)) { printf("ๆƒ้™ไธๅคŸ.\n"); return; } } int temp = 0; for (int i = 0; i < 8; i++) { if (str[i] == '1') temp += 1 << (8 - i); } if (str[8] == '1') temp += 1; tmp_file_inode->permission = temp; fseek(fd, INODE_START + tmp_file_inode->i_ino * INODE_SIZE, SEEK_SET); fwrite(tmp_file_inode, sizeof(inode), 1, fd); return; } //ๆ”นๅ˜ๆ–‡ไปถๆ‰€ๅฑž void Chown(char* filename) { printf("0=ๆ–‡ไปถ๏ผŒ1=็›ฎๅฝ•๏ผŒ่ฏท้€‰ๆ‹ฉ:"); int tt; scanf("%d", &tt); //ๅ‚ๆ•ฐๆฃ€ๆต‹ if (filename == NULL || strlen(filename) > FILE_NAME_LENGTH) { printf("ๅ‚ๆ•ฐไธๅˆๆณ•.\n"); return; } // 1. ๆฃ€ๆŸฅๆ–‡ไปถๆ˜ฏๅฆๅญ˜ๅœจ. int pos_in_directory = -1; inode* tmp_file_inode = new inode; do { pos_in_directory++; for (; pos_in_directory < DIRECTORY_NUM; pos_in_directory++) { if (strcmp(currentDirectory.fileName[pos_in_directory], filename) == 0) { break; } } if (pos_in_directory == DIRECTORY_NUM) { printf("Not found.\n"); return; } int tmp_file_ino = currentDirectory.inodeID[pos_in_directory]; fseek(fd, INODE_START + tmp_file_ino * INODE_SIZE, SEEK_SET); fread(tmp_file_inode, sizeof(inode), 1, fd); } while (tmp_file_inode->di_mode == tt); if (userID == tmp_file_inode->di_uid) { if (!(tmp_file_inode->permission & OWN_E)) { printf("ๆƒ้™ไธๅคŸ.\n"); return; } } else if (users.groupID[userID] == tmp_file_inode->di_grp) { if (!(tmp_file_inode->permission & GRP_E)) { printf("ๆƒ้™ไธๅคŸ.\n"); return; } } else { if (!(tmp_file_inode->permission & ELSE_E)) { printf("ๆƒ้™ไธๅคŸ.\n"); return; } } printf("่ฏท่พ“ๅ…ฅ็”จๆˆทๅ:"); char str[USER_NAME_LENGTH]; int i; scanf("%s", str); for (i = 0; i < ACCOUNT_NUM; i++) { if (strcmp(users.userName[i], str) == 0) break; } if (i == ACCOUNT_NUM) { printf("ไธๅˆๆณ•็”จๆˆท!\n"); return; } tmp_file_inode->di_uid = i; fseek(fd, INODE_START + tmp_file_inode->i_ino * INODE_SIZE, SEEK_SET); fwrite(tmp_file_inode, sizeof(inode), 1, fd); return; } //ๆ”นๅ˜ๆ–‡ไปถๆ‰€ๅฑž็ป„. void Chgrp(char* filename) { printf("0=ๆ–‡ไปถ๏ผŒ1=็›ฎๅฝ•๏ผŒ่ฏท้€‰ๆ‹ฉ:"); int tt; scanf("%d", &tt); if (filename == NULL || strlen(filename) > FILE_NAME_LENGTH) { printf("ไธๅˆๆณ•.\n"); return; } int pos_in_directory = -1; inode* tmp_file_inode = new inode; do { pos_in_directory++; for (; pos_in_directory < DIRECTORY_NUM; pos_in_directory++) { if (strcmp(currentDirectory.fileName[pos_in_directory], filename) == 0) { break; } } if (pos_in_directory == DIRECTORY_NUM) { printf("Not found.\n"); return; } int tmp_file_ino = currentDirectory.inodeID[pos_in_directory]; fseek(fd, INODE_START + tmp_file_ino * INODE_SIZE, SEEK_SET); fread(tmp_file_inode, sizeof(inode), 1, fd); } while (tmp_file_inode->di_mode == tt); if (userID == tmp_file_inode->di_uid) { if (!(tmp_file_inode->permission & OWN_E)) { printf("ๆƒ้™ไธๅคŸ.\n"); return; } } else if (users.groupID[userID] == tmp_file_inode->di_grp) { if (!(tmp_file_inode->permission & GRP_E)) { printf("ๆƒ้™ไธๅคŸ.\n"); return; } } else { if (!(tmp_file_inode->permission & ELSE_E)) { printf("ๆƒ้™ไธๅคŸ.\n"); return; } } printf("่ฏท่พ“ๅ…ฅ็ป„ๅท:"); int ttt, i; scanf("%d", &ttt); for (i = 0; i < ACCOUNT_NUM; i++) { if (users.groupID[i] == ttt) break; } if (i == ACCOUNT_NUM) { printf("็”จๆˆท้”™่ฏฏ!\n"); return; } tmp_file_inode->di_grp = ttt; fseek(fd, INODE_START + tmp_file_inode->i_ino * INODE_SIZE, SEEK_SET); fwrite(tmp_file_inode, sizeof(inode), 1, fd); return; } //ไฟฎๆ”นๅฏ†็  void Passwd() { printf("่ฏท่พ“ๅ…ฅๆ—งๅฏ†็ :"); char str[USER_PASSWORD_LENGTH]; scanf("%s", str); str[USER_PASSWORD_LENGTH] = 0; if (strcmp(users.password[userID], str) == 0) { printf("่ฏท่พ“ๅ…ฅๆ–ฐๅฏ†็ :"); scanf("%s", str); if (strcmp(users.password[userID], str) == 0) { printf("ไธคๆฌกๅฏ†็ ็›ธๅŒ!\n"); } else { strcpy(users.password[userID], str); fseek(fd, DATA_START + BLOCK_SIZE, SEEK_SET); fwrite(&users, sizeof(users), 1, fd); printf("ไฟฎๆ”นๆˆๅŠŸ\n"); } } else { printf("ๅฏ†็ ้”™่ฏฏ!!!\n"); } } //็”จๆˆท็ฎก็† void User_management() { if (userID != 0) { printf("ๅชๆœ‰็ฎก็†ๅ‘˜ๆ‰ๅฏไปฅ็ฎก็†็”จๆˆท!\n"); return; } printf("ๆฌข่ฟŽๆฅๅˆฐ็”จๆˆท็ฎก็†!\n"); char c; scanf("%c", &c); while (c != '0') { printf("\n1.ๆŸฅ็œ‹ 2.ๅˆ›ๅปบ 3.ๅˆ ้™ค 0.ไฟๅญ˜ & ้€€ๅ‡บ\n"); scanf("%c", &c); switch (c) { case '1': for (int i = 0; i < ACCOUNT_NUM; i++) { if (users.userName[i][0] != 0) printf("%d\t%s\t%d\n", users.userID[i], users.userName[i], users.groupID[i]); else break; } scanf("%c", &c); break; case '2': int i; for (i = 0; i < ACCOUNT_NUM; i++) { if (users.userName[i][0] == 0) break; } if (i == ACCOUNT_NUM) { printf("็”จๆˆทๅคชๅคšไบ†!\n"); break; } printf("่ฏท่พ“ๅ…ฅ็”จๆˆทๅ:"); char str[USER_NAME_LENGTH]; scanf("%s", str); for (i = 0; i < ACCOUNT_NUM; i++) { if (strcmp(users.userName[i], str) == 0) { printf("ๅทฒ็ปๆœ‰ๅŒๅ็š„็”จๆˆทๅไบ†!\n"); } if (users.userName[i][0] == 0) { strcpy(users.userName[i], str); printf("่ฏท่พ“ๅ…ฅๅฏ†็ :"); scanf("%s", str); strcpy(users.password[i], str); printf("่ฏท่พ“ๅ…ฅ group ID:"); int t; scanf("%d", &t); scanf("%c", &c); if (t > 0) { users.groupID[i] = t; printf("ๆˆๅŠŸ!\n"); } else { printf("ๅˆ›ๅปบๅคฑ่ดฅ!\n"); strcpy(users.userName[i], 0); strcpy(users.password[i], 0); } break; } } break; case '3': printf("่ฏท่พ“ๅ…ฅuserID:"); int tmp; scanf("%d", &tmp);scanf("%c", &c); for (int j = tmp; j < ACCOUNT_NUM - 1; j++) { strcpy(users.userName[j], users.userName[j + 1]); strcpy(users.password[j], users.password[j + 1]); users.groupID[j] = users.groupID[j+1]; } printf("ๆˆๅŠŸ!\n"); } } fseek(fd, DATA_START + BLOCK_SIZE, SEEK_SET); fwrite(&users, sizeof(users), 1, fd); } //ๅฏนๆ–‡ไปถๆˆ–็›ฎๅฝ•้‡ๅ‘ฝๅ void Rename(char* filename) { printf("0=ๆ–‡ไปถ๏ผŒ1=็›ฎๅฝ•๏ผŒ่ฏท้€‰ๆ‹ฉ:"); int tt; scanf("%d", &tt); if (filename == NULL || strlen(filename) > FILE_NAME_LENGTH) { printf("ๅ‚ๆ•ฐไธๅˆๆณ•.\n"); return; } int pos_in_directory = -1; inode* tmp_file_inode = new inode; do { pos_in_directory++; for (; pos_in_directory < DIRECTORY_NUM; pos_in_directory++) { if (strcmp(currentDirectory.fileName[pos_in_directory], filename) == 0) { break; } } if (pos_in_directory == DIRECTORY_NUM) { printf("ๆฒกๆœ‰ๆ‰พๅˆฐ.\n"); return; } int tmp_file_ino = currentDirectory.inodeID[pos_in_directory]; fseek(fd, INODE_START + tmp_file_ino * INODE_SIZE, SEEK_SET); fread(tmp_file_inode, sizeof(inode), 1, fd); } while (tmp_file_inode->di_mode == tt); printf("่ฏท่พ“ๅ…ฅๆ–ฐ็š„็”จๆˆทๅ:"); char str[14]; scanf("%s", str); str[14] = 0; for (int i = 0; i < DIRECTORY_NUM; i++) { if (currentDirectory.inodeID[i] == tmp_file_inode->i_ino) { strcpy(currentDirectory.fileName[i], str); break; } } fseek(fd, DATA_START + tmp_file_inode->di_addr[0] * BLOCK_SIZE, SEEK_SET); fwrite(&currentDirectory, sizeof(directory), 1, fd); return; } //ๆ–‡ไปถๅคๅˆถ bool Copy(char* filename, inode*& currentInode) { currentInode = OpenFile(filename); int block_num = currentInode->di_size / BLOCK_SIZE + 1; //่ฏปๅ–ๆ–‡ไปถ char stack[BLOCK_SIZE]; char str[100000]; int cnt = 0; if (block_num <= NADDR - 2) { for (int i = 0; i < block_num; i++) { if (currentInode->di_addr[i] == -1) break; fseek(fd, DATA_START + currentInode->di_addr[i] * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(stack), 1, fd); for (int j = 0; j < BLOCK_SIZE; j++) { if (stack[j] == '\0') { str[cnt] = 0; break; } str[cnt++] = stack[j]; } } } else if (block_num > NADDR - 2) { for (int i = 0; i < NADDR - 2; i++) { fseek(fd, DATA_START + currentInode->di_addr[i] * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(stack), 1, fd); for (int j = 0; j < BLOCK_SIZE; j++) { if (stack[j] == '\0') { str[cnt] = 0; break; } str[cnt++] = stack[j]; } } unsigned int f1[BLOCK_SIZE / sizeof(unsigned int)] = { 0 }; fseek(fd, DATA_START + currentInode->di_addr[NADDR - 2] * BLOCK_SIZE, SEEK_SET); fread(f1, sizeof(f1), 1, fd); for (int i = 0; i < block_num - (NADDR - 2); i++) { fseek(fd, DATA_START + f1[i] * BLOCK_SIZE, SEEK_SET); fread(stack, sizeof(stack), 1, fd); for (int j = 0; j < BLOCK_SIZE; j++) { if (stack[j] == '\0') { str[cnt] = 0; break; } str[cnt++] = stack[j]; } } } int pos_in_directory = -1; inode* tmp_file_inode = new inode; do { pos_in_directory++; for (; pos_in_directory < DIRECTORY_NUM; pos_in_directory++) { if (strcmp(currentDirectory.fileName[pos_in_directory], filename) == 0) { break; } } if (pos_in_directory == DIRECTORY_NUM) { printf("ๆฒกๆœ‰ๆ‰พๅˆฐ.\n"); return false; } int tmp_file_ino = currentDirectory.inodeID[pos_in_directory]; fseek(fd, INODE_START + tmp_file_ino * INODE_SIZE, SEEK_SET); fread(tmp_file_inode, sizeof(inode), 1, fd); } while (tmp_file_inode->di_mode == 0); //ๆƒ้™ๆฃ€ๆต‹ if (userID == tmp_file_inode->di_uid) { if (!(tmp_file_inode->permission & OWN_E)) { printf("ๆƒ้™ไธๅคŸ.\n"); return false; } } else if (users.groupID[userID] == tmp_file_inode->di_grp) { if (!(tmp_file_inode->permission & GRP_E)) { printf("ๆƒ้™ไธๅคŸ.\n"); return false; } } else { if (!(tmp_file_inode->permission & ELSE_E)) { printf("ๆƒ้™ไธๅคŸ.\n"); return false; } } //ๅ–็ปๅฏนๅœฐๅ€ char absolute[1024]; int path_pos = 0; printf("่ฏท่พ“ๅ…ฅ็ปๅฏนๅœฐๅ€:"); scanf("%s", absolute); char dirname[14]; int pos_dir = 0; bool root = false; inode dir_inode; directory cur_dir; int i; for (i = 0; i < 5; i++) { dirname[i] = absolute[i]; } dirname[i] = 0; if (strcmp("root/", dirname) != 0) { printf("่ทฏๅพ„้”™่ฏฏ!\n"); return false; } fseek(fd, INODE_START, SEEK_SET); fread(&dir_inode, sizeof(inode), 1, fd); for (int i = 5; absolute[i] != '\n'; i++) { if (absolute[i] == '/') { dirname[pos_dir++] = 0; pos_dir = 0; fseek(fd, DATA_START + dir_inode.di_addr[0] * BLOCK_SIZE, SEEK_SET); fread(&cur_dir, sizeof(directory), 1, fd); int i; for (i = 0; i < DIRECTORY_NUM; i++) { if (strcmp(cur_dir.fileName[i], dirname) == 0) { fseek(fd, INODE_START + cur_dir.inodeID[i] * INODE_SIZE, SEEK_SET); fread(&dir_inode, sizeof(inode), 1, fd); if (dir_inode.di_mode == 0)break; } } if (i == DIRECTORY_NUM) { printf("่ทฏๅพ„้”™่ฏฏ!\n"); return false; } } else dirname[pos_dir++] = absolute[i]; } //ๆ›ดๆ–ฐๅฝ“ๅ‰็›ฎๅฝ• fseek(fd, DATA_START + dir_inode.di_addr[0] * BLOCK_SIZE, SEEK_SET); fread(&cur_dir, sizeof(directory), 1, fd); for (i = 0; i < DIRECTORY_NUM; i++) { if (strlen(cur_dir.fileName[i]) == 0) { strcat(cur_dir.fileName[i], filename); int new_ino = 0; for (; new_ino < INODE_NUM; new_ino++) { if (inode_bitmap[new_ino] == 0) { break; } } inode ifile_tmp; ifile_tmp.i_ino = new_ino; ifile_tmp.icount = 0; ifile_tmp.di_uid = tmp_file_inode->di_uid; ifile_tmp.di_grp = tmp_file_inode->di_grp; ifile_tmp.di_mode = tmp_file_inode->di_mode; memset(ifile_tmp.di_addr, -1, sizeof(unsigned int) * NADDR); ifile_tmp.di_size = 0; ifile_tmp.permission = tmp_file_inode->permission; time_t t = time(0); strftime(ifile_tmp.time, sizeof(ifile_tmp.time), "%Y/%m/%d %X", localtime(&t)); cur_dir.inodeID[i] = new_ino; Write(ifile_tmp, str); //Update bitmaps inode_bitmap[new_ino] = 1; fseek(fd, 2 * BLOCK_SIZE, SEEK_SET); fwrite(inode_bitmap, sizeof(unsigned short) * INODE_NUM, 1, fd); superBlock.s_num_finode--; fseek(fd, BLOCK_SIZE, SEEK_SET); fwrite(&superBlock, sizeof(filsys), 1, fd); break; } } if (i == DIRECTORY_NUM) { printf("No value iterms!\n"); return false; } fseek(fd, DATA_START + dir_inode.di_addr[0] * BLOCK_SIZE, SEEK_SET); fwrite(&cur_dir, sizeof(directory), 1, fd); dir_inode.di_number++; fseek(fd, INODE_START + tmp_file_inode->i_ino*INODE_SIZE, SEEK_SET); fwrite(tmp_file_inode, sizeof(inode), 1, fd); return true; } //็ณป็ปŸๅฏๅŠจ void Sys_start() { //่ฝฝๅ…ฅๆ–‡ไปถ็ณป็ปŸ Mount(); printf("**************************************************************\n"); printf("* *\n"); printf("* ๅคš็”จๆˆทๆ–‡ไปถ็ฎก็†็ณป็ปŸ *\n"); printf("* *\n"); printf("**************************************************************\n"); } //่‡ชๅฎšไน‰ไธๅ›žๆ˜พๅญ—็ฌฆ int getch() { int c = 0; struct termios org_opts, new_opts; int res = 0; res = tcgetattr(STDIN_FILENO, &org_opts); assert(res == 0); memcpy(&new_opts, &org_opts, sizeof(new_opts)); new_opts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE | ICRNL); tcsetattr(STDIN_FILENO, TCSANOW, &new_opts); c = getchar(); res = tcsetattr(STDIN_FILENO, TCSANOW, &org_opts); assert(res == 0); if(c == '\n') c = '\r'; else if(c == 127) c = '\b'; return c; } void CommParser(inode*& currentInode) { char para1[11]; char para2[1024]; bool flag = false; while (true) { unsigned int f1[BLOCK_SIZE / sizeof(unsigned int)] = { 0 }; fseek(fd, DATA_START + 8 * BLOCK_SIZE, SEEK_SET); fread(f1, sizeof(f1), 1, fd); memset(para1, 0, 11); memset(para2, 0, 1024); printf("%s>", userName); scanf("%s", para1); para1[10] = 0; //้€‰ๆ‹ฉๅŠŸ่ƒฝ if (strcmp("ls", para1) == 0)//ๆ˜พ็คบๅฝ“ๅ‰ๆ–‡ไปถ { flag = false; List(); } else if (strcmp("cp", para1) == 0) {//ๆ–‡ไปถๅคๅˆถ flag = false; scanf("%s", para2); para2[1023] = 0; //ๅฎ‰ๅ…จไฟๆŠค Copy(para2, currentInode); } else if (strcmp("mv", para1) == 0) {//้‡ๅ‘ฝๅ flag = false; scanf("%s", para2); para2[1023] = 0; //ๅฎ‰ๅ…จไฟๆŠค Rename(para2); } else if (strcmp("pwd", para1) == 0) {//ๆ˜พ็คบๅฝ“ๅ‰็›ฎๅฝ• flag = false; Ab_dir(); } else if (strcmp("passwd", para1) == 0) { flag = false; Passwd(); } else if (strcmp("chmod", para1) == 0) {//็”จๆˆทๆƒ้™ flag = false; scanf("%s", para2); para2[1023] = 0; Chmod(para2); } else if (strcmp("chown", para1) == 0) {//ๆ›ดๆ”น็”จๆˆทๆƒ้™ flag = false; scanf("%s", para2); para2[1023] = 0; Chown(para2); } else if (strcmp("chgrp", para1) == 0) {//ๆ›ดๆ”นๆ‰€ๅฑž็ป„ flag = false; scanf("%s", para2); para2[1023] = 0; Chgrp(para2); } else if (strcmp("info", para1) == 0) { printf("็ณป็ปŸไฟกๆฏ:\nๆ€ปๅ…ฑ็š„block:%d\n ็ฉบ้—ฒblock:%d\nๆ€ปinode:%d\nๅ‰ฉไฝ™inode:%d\n\n", superBlock.s_num_block, superBlock.s_num_fblock, superBlock.s_num_inode, superBlock.s_num_finode); for (int i = 0; i < 50; i++) { if (i>superBlock.special_free)printf("-1\t"); else printf("%d\t", superBlock.special_stack[i]); if (i % 10 == 9)printf("\n"); } printf("\n\n"); } //ๅˆ›ๅปบๆ–‡ไปถ else if (strcmp("create", para1) == 0) { flag = false; scanf("%s", para2); para2[1023] = 0; CreateFile(para2); } //ๅˆ ้™คๆ–‡ไปถ else if (strcmp("rm", para1) == 0) { flag = false; scanf("%s", para2); para2[1023] = 0; DeleteFile(para2); } //ๆ‰“ๅผ€ๆ–‡ไปถ else if (strcmp("open", para1) == 0){ flag = true; scanf("%s", para2); para2[1023] = 0; currentInode = OpenFile(para2); } //ๅ†™ๆ–‡ไปถ else if (strcmp("write", para1) == 0 && flag){ scanf("%s", para2); para2[1023] = 0; Write(*currentInode, para2); } //่ฏปๆ–‡ไปถ else if (strcmp("read", para1) == 0 && flag) { PrintFile(*currentInode); } //ๆ‰“ๅผ€ไธ€ไธช็›ฎๅฝ• else if (strcmp("cd", para1) == 0){ flag = false; scanf("%s", para2); para2[1023] = 0; OpenDir(para2); } //ๅˆ›ๅปบ็›ฎๅฝ• else if (strcmp("mkdir", para1) == 0){ flag = false; scanf("%s", para2); para2[1023] = 0; //security protection MakeDir(para2); } //ๅˆ ้™ค็›ฎๅฝ• else if (strcmp("rmdir", para1) == 0){ flag = false; scanf("%s", para2); para2[1023] = 0; //security protection RemoveDir(para2); } //็™ปๅ‡บ็ณป็ปŸ else if (strcmp("logout", para1) == 0){ flag = false; Logout(); char tmp_userName[USER_NAME_LENGTH], tmp_userPassword[USER_PASSWORD_LENGTH * 5]; do { memset(tmp_userName, 0, USER_NAME_LENGTH); memset(tmp_userPassword, 0, USER_PASSWORD_LENGTH * 5); printf("็”จๆˆท็™ปๅฝ•\n\n"); printf("็”จๆˆทๅ:\t"); scanf("%s", tmp_userName); printf("ๅฏ†็ :\t"); char c; scanf("%c", &c); int i = 0; while (1) { char ch; ch = getch(); if (ch == '\b') { if (i != 0) { printf("\b \b"); i--; } else { tmp_userPassword[i] = '\0'; } } else if (ch == '\r') { tmp_userPassword[i] = '\0'; printf("\n\n"); break; } else { putchar('*'); tmp_userPassword[i++] = ch; } } } while (Login(tmp_userName, tmp_userPassword) != true); } //็™ปๅฝ• else if (strcmp("su", para1) == 0){ Logout(); flag = false; char para3[USER_PASSWORD_LENGTH * 5]; memset(para3, 0, USER_PASSWORD_LENGTH + 1); scanf("%s", para2); para2[1023] = 0; printf("ๅฏ†็ : "); char c; scanf("%c", &c); int i = 0; while (1) { char ch; ch = getch(); if (ch == '\b') { if (i != 0) { printf("\b \b"); i--; } } else if (ch == '\r') { para3[i] = '\0'; printf("\n\n"); break; } else { putchar('*'); para3[i++] = ch; } } para3[USER_PASSWORD_LENGTH] = 0; //ๅฎ‰ๅ…จไฟๆŠค Login(para2, para3); } else if (strcmp("manage", para1) == 0) { flag = false; User_management(); } //้€€ๅ‡บ็ณป็ปŸ else if (strcmp("quit", para1) == 0){ flag = false; break; } //help else{ flag = false; Help(); } } }; void Help(){ printf("็ณป็ปŸๅฝ“ๅ‰ๆ”ฏๆŒๆŒ‡ไปค:\n"); printf("\t01.quit...........................้€€ๅ‡บ็ณป็ปŸ\n"); printf("\t02.help...........................ๆ˜พ็คบๅธฎๅŠฉไฟกๆฏ\n"); printf("\t03.pwd............................ๆ˜พ็คบๅฝ“ๅ‰็›ฎๅฝ•\n"); printf("\t04.ls.............................ๅˆ—ๅ‡บๆ–‡ไปถๆˆ–็›ฎๅฝ•\n"); printf("\t05.cd + dirname...................cdๅˆฐๅ…ถไป–็›ฎๅฝ•\n"); printf("\t06.mkdir + dirname................ๅˆ›ๅปบๆ–ฐ็›ฎๅฝ•\n"); printf("\t07.rmdir + dirname................ๅˆ ้™ค็›ฎๅฝ•\n"); printf("\t08.create + filename..............ๆ–ฐๅปบๆ–‡ไปถ\n"); printf("\t09.open + filename................ๆ‰“ๅผ€ๆ–‡ไปถ\n"); printf("\t10.read + filename................่ฏปๅ–ๆ–‡ไปถ\n"); printf("\t11.write + content................ๅ†™ๅ…ฅๆ–‡ไปถ\n"); printf("\t12.rm + filename..................ๅˆ ้™คๆ–‡ไปถ\n"); printf("\t13.logout.........................้€€ๅ‡บๅฝ“ๅ‰็”จๆˆท\n"); printf("\t14.chmod + filename...............ๆ”นๅ˜ๆ–‡ไปถๆƒ้™\n"); printf("\t15.chown + filename...............ๆ”นๅ˜ๆ–‡ไปถๆ‰€ๆœ‰่€…\n"); printf("\t16.chgrp + filename...............ๆ”นๅ˜ๆ‰€ๅฑž็ป„\n"); printf("\t17.mv + filename..................้‡ๅ‘ฝๅ\n"); printf("\t18.passwd.........................ๆ”นๅฏ†็ \n"); printf("\t19.manage.........................็”จๆˆท็ฎก็†็•Œ้ข\n"); }; int main() { memset(ab_dir, 0, sizeof(ab_dir)); dir_pointer = 0; //ๅ…ˆๆŸฅๆ‰พๆ–‡ไปถๅท. FILE* fs_test = fopen("root.tianye", "r"); if (fs_test == NULL) { printf("ๆ–‡ไปถๅทๆฒกๆ‰พๅˆฐ... ่ฏท็จๅŽ๏ผŒๆญฃๅœจๆ–ฐๅปบๆ–‡ไปถๅท...\n\n"); Format(); } Sys_start(); ab_dir[dir_pointer][0] = 'r';ab_dir[dir_pointer][1] = 'o';ab_dir[dir_pointer][2] = 'o';ab_dir[dir_pointer][3] = 't';ab_dir[dir_pointer][4] = '\0'; dir_pointer++; //็™ปๅฝ• char tmp_userName[USER_NAME_LENGTH]; char tmp_userPassword[USER_PASSWORD_LENGTH * 5]; do { memset(tmp_userName, 0, USER_NAME_LENGTH); memset(tmp_userPassword, 0, USER_PASSWORD_LENGTH * 5); printf("็”จๆˆท็™ปๅฝ•\n\n"); printf("็”จๆˆทๅ:\t"); scanf("%s", tmp_userName); printf("ๅฏ†็ :\t"); char c; scanf("%c", &c); int i = 0; while (1) { char ch; ch = getch(); if (ch == '\b') { if (i != 0) { printf("\b \b"); i--; } else { tmp_userPassword[i] = '\0'; } } else if (ch == '\r') { tmp_userPassword[i] = '\0'; printf("\n\n"); break; } else { putchar('*'); tmp_userPassword[i++] = ch; } } } while (Login(tmp_userName, tmp_userPassword) != true); inode* currentInode = new inode; CommParser(currentInode); return 0; }
[ "typeme3@163.com" ]
typeme3@163.com
cbfcb606d5f189a8cf61b489d266329447a4fa9d
d522a93c6d573c1b2f8b559d8a88269bad4130d3
/shellcode/loader/loader.cpp
2d34ede6a93edbf5ad114acd8d763c30d8e3f0ce
[]
no_license
floomby/framework
d7699947027bb440f82e033655f03f51335c631e
d08e5f54381393acb08c85317caaf841c574c35d
refs/heads/master
2016-09-06T17:28:16.754564
2014-06-07T01:44:07
2014-06-07T01:44:07
null
0
0
null
null
null
null
UTF-8
C++
false
false
306
cpp
#include <cstdio> #include <cstdint> #include "reflect/reflect.h" int main(int argc, char *argv[]) { uint8_t *it = (uint8_t *)&ReflectiveLoad; printf("print \""); for(size_t i = 0; i < ReflectiveLoad_size; ++i){ printf("\\x%02x", it[i]); } puts("\""); return 0; }
[ "caboodlennm@gmail.com" ]
caboodlennm@gmail.com
f7683e4a33d2ce2c6339ed8a1e953cc5494809fb
a2853414268447c37d448570ee648e8d45ed706c
/core/Data.hpp
058d69dfa7f5a744a925958cbd3c1c593c66465c
[]
no_license
acherkaoui/HTOP
5f61057a6a478925d32ebea82e0e99f6fe0f6afa
3577c1ea7aebba85cdd7364229ca6c5a69318589
refs/heads/master
2021-04-09T14:11:22.022810
2018-03-16T23:03:12
2018-03-16T23:03:12
125,578,109
3
0
null
null
null
null
UTF-8
C++
false
false
622
hpp
/* ** EPITECH PROJECT, 2021 ** cpp_rush3 ** File description: ** Created by abderrahim.cherkaoui@epitech.eu, */ #ifndef CPP_RUSH3_DATA_HPP #define CPP_RUSH3_DATA_HPP #include "../modules/Clock.hpp" #include "../modules/Network.hpp" #include "../modules/OperatingSystem.hpp" #include "../modules/Processes.hpp" #include "../modules/RAM.hpp" #include "../modules/User.hpp" #include "../modules/CPU.hpp" class Data { public: Data() = default; virtual ~Data() = default; public: Cpu cpu; Clock clock; Network network; OperatingSystem os; Processes processes; RAM ram; User user; }; #endif //CPP_RUSH3_DATA_HPP
[ "abderrahim.cherkaoui@epitech.eu" ]
abderrahim.cherkaoui@epitech.eu
68c48eb9c3083acb80a04939595049812c31dcf1
969a3f74a957b7fa3685ac5ae5f94ac225af9522
/Rendering/OpenGL2/vtkOpenGLES30PolyDataMapper2D.h
49e1411fb205556b4e466bb573cabaac34e81028
[ "BSD-3-Clause" ]
permissive
gview/VTK
61adbce5b78e0fdf8069e2384c0fc1899a723df5
17c664f1c3bdb84997aa2c9bfdf51ba77171672e
refs/heads/master
2023-06-01T11:56:23.857210
2023-05-30T04:01:23
2023-05-30T04:01:23
null
0
0
null
null
null
null
UTF-8
C++
false
false
3,929
h
/*========================================================================= Program: Visualization Toolkit Module: vtkOpenGLES30PolyDataMapper2D.h Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ /** * @class vtkOpenGLES30PolyDataMapper2D * @brief 2D PolyData support for OpenGL ES 3.0 * * This mapper provides a GLES 3.0 compatible implementation of the 2D OpenGL * polydata mapper. Since GLES30 3.0 lacks geometry shaders and texture buffers, * `vtkOpenGLPolyDataMapper2D` will not function * correctly when VTK is configured with `VTK_OPENGL_USE_GLES=ON` since that mapper * works with GLES30 >= 3.2 or desktop GL 3.2 contexts. * * @note This class replaces the default OpenGL factory override for `vtkOpenGLPolyDataMapper2D` * when VTK targets GLES 3.0 contexts with `VTK_OPENGL_USE_GLES=ON`. * * @sa * vtkPolyDataMapper2D, vtkOpenGLPolyDataMapper2D */ #ifndef vtkOpenGLES30PolyDataMapper2D_h #define vtkOpenGLES30PolyDataMapper2D_h #include "vtkOpenGLPolyDataMapper2D.h" #include "vtkOpenGLVertexBufferObjectGroup.h" // for ivar #include "vtkRenderingOpenGL2Module.h" // for export macro VTK_ABI_NAMESPACE_BEGIN class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLES30PolyDataMapper2D : public vtkOpenGLPolyDataMapper2D { public: vtkTypeMacro(vtkOpenGLES30PolyDataMapper2D, vtkOpenGLPolyDataMapper2D); static vtkOpenGLES30PolyDataMapper2D* New(); void PrintSelf(ostream& os, vtkIndent indent) override; enum PrimitiveTypes { PrimitiveStart = 0, PrimitivePoints = 0, PrimitiveLines, PrimitiveTris, PrimitiveTriStrips, PrimitiveEnd }; /** * Actually draw the poly data. */ void RenderOverlay(vtkViewport* viewport, vtkActor2D* actor) override; /** * Release any graphics resources that are being consumed by this mapper. * The parameter window could be used to determine which graphic * resources to release. */ void ReleaseGraphicsResources(vtkWindow*) override; protected: vtkOpenGLES30PolyDataMapper2D(); ~vtkOpenGLES30PolyDataMapper2D() override; /** * Build the shader source code */ void BuildShaders(std::string& VertexCode, std::string& fragmentCode, std::string& geometryCode, vtkViewport* ren, vtkActor2D* act) override; /** * In GLES 3.0, point size is set from the vertex shader. */ void ReplaceShaderPointSize(std::string& VSSource, vtkViewport* ren, vtkActor2D* act); /** * GLES 3.0 does not support wide lines (width > 1). Shader computations combined with * instanced rendering is used to emulate wide lines. */ void ReplaceShaderWideLines(std::string& VSSource, vtkViewport* ren, vtkActor2D* act); /** * Determine what shader to use and compile/link it */ void UpdateShaders(vtkOpenGLHelper& cellBO, vtkViewport* viewport, vtkActor2D* act) override; /** * Set the shader parameters related to the mapper/input data, called by UpdateShader */ void SetMapperShaderParameters( vtkOpenGLHelper& cellBO, vtkViewport* viewport, vtkActor2D* act) override; /** * Update the scene when necessary. */ void UpdateVBO(vtkActor2D* act, vtkViewport* viewport); std::vector<unsigned int> PrimitiveIndexArrays[PrimitiveEnd]; vtkNew<vtkOpenGLVertexBufferObjectGroup> PrimitiveVBOGroup[PrimitiveEnd]; PrimitiveTypes CurrentDrawCallPrimtiveType = PrimitiveEnd; private: vtkOpenGLES30PolyDataMapper2D(const vtkOpenGLES30PolyDataMapper2D&) = delete; void operator=(const vtkOpenGLES30PolyDataMapper2D&) = delete; }; VTK_ABI_NAMESPACE_END #endif
[ "jaswant.panchumarti@kitware.com" ]
jaswant.panchumarti@kitware.com
5fb8da5217f1e4cf5ead0e1de197592896394db4
39cdb6ff35231538ef25c565181981ccf237cc30
/BOJ/14225.cpp
0d0ffcdbfae96ffefcc514c6f12855288e86c191
[]
no_license
dittoo8/algorithm_cpp
51b35321f6cf16c8c1c259af746a9f35d5ba8b76
d9cdda322d3658ffc07744e4080c71faeee6370c
refs/heads/master
2023-08-03T14:49:08.808253
2021-02-16T04:13:53
2021-02-16T04:13:53
null
0
0
null
null
null
null
UTF-8
C++
false
false
515
cpp
#include <cstdio> using namespace std; int n; int a[21]; bool ck[20*100000]; void backtrack(int idx, int sum){ if (idx == n){ ck[sum]= true; return; } backtrack(idx+1, sum+a[idx]); backtrack(idx+1, sum); } int main(){ scanf("%d", &n); for(int i=0;i<n;i++){ scanf("%d", &a[i]); } backtrack(0,0); int start =1; while(true){ if(!ck[start]){ printf("%d\n", start); return 0; } start++; } return 0; }
[ "sohyun1018@gmail.com" ]
sohyun1018@gmail.com
1c259c53f596bebd4c0d756c05cb2e09b3b342a9
08ed3720f797ab761f9d627601896ee7a3f7f14b
/LuaSQLite3/LuaSQLite3.cpp
2c203a1a291aab7320a7dfeda47658d6fb91135b
[]
no_license
fcccode/LuaUI2
2df357681a1f6df8c9c42a73a56ed96efc5212fd
daba4835c848261943fd9ce6d2df0bac0140bd95
refs/heads/master
2020-03-14T12:37:28.846054
2017-06-09T11:15:11
2017-06-09T11:15:11
null
0
0
null
null
null
null
UTF-8
C++
false
false
108
cpp
// LuaSQLite3.cpp : Defines the exported functions for the DLL application. // #include "stdafx.h"
[ "6659907@gmail.com" ]
6659907@gmail.com
73b82e3e8ae1271dc90b868329daec6dae21cde4
946e56abf2e2de724aab9d575a94accb2184c88c
/openmp/ring/ring.cpp
00e22bb05e8a8514f65e9d6a87fcba45b8b827b2
[ "MIT" ]
permissive
pavelkryukov/paraprog
e71137d196a26fe74c7748efec4ecba6208aea00
9a3307f75019543dfd24fc9b5c1a3c0ea1dcd3be
refs/heads/master
2021-01-20T14:52:37.855913
2017-05-08T23:29:43
2017-05-08T23:37:30
90,681,013
0
0
null
null
null
null
UTF-8
C++
false
false
4,442
cpp
/** * ring.cpp * * Send/Recv messages with pthreads in ring using pthreads * * @author pikryukov * @version 1.0 * * e-mail: kryukov@frtk.ru * * Copyright (C) Kryukov Pavel 2012 * for MIPT MPI course. */ #include <cstdlib> #include <iostream> #include <vector> #include <pthread.h> /** * Mutex class wrapper */ class Mutex { private: friend class Cond; pthread_mutex_t m; public: inline Mutex() { pthread_mutex_init(&m, NULL); } inline ~Mutex() { pthread_mutex_destroy(&m); } inline int Lock() { return pthread_mutex_lock(&m); } inline int Unlock() { return pthread_mutex_unlock(&m); } inline int TryLock() { return pthread_mutex_trylock(&m); } }; /** * Condition class wrapper */ class Cond { private: pthread_cond_t c; public: inline Cond() { pthread_cond_init(&c, NULL); } inline ~Cond() { pthread_cond_destroy(&c); } inline int Wait(Mutex& mutex) { return pthread_cond_wait(&c, &mutex.m); } inline int TimedWait(Mutex& mutex, const timespec* time) { return pthread_cond_timedwait(&c, &mutex.m, time); } inline int Signal() { return pthread_cond_signal(&c); } inline int Broadcast() { return pthread_cond_broadcast(&c); } }; /** * Simple port between two threads */ template<typename T> class Port { private: Mutex mutex; T data; bool isValid; Cond full; Cond free; public: Port() : isValid(false) { } void Write(const T& what) { mutex.Lock(); while (isValid) free.Wait(mutex); data = what; isValid = true; full.Broadcast(); mutex.Unlock(); } T Read() { mutex.Lock(); while(!isValid) full.Wait(mutex); T result = data; isValid = false; free.Broadcast(); mutex.Unlock(); return result; } }; /** * Thread unit */ class Unit { private: Port<unsigned>* readPort; Port<unsigned>* writePort; static Mutex printMutex; ///< Mutex for locking stdout int rank; unsigned maxAmount; public: Unit(int rank, int maxAmount) : readPort(NULL) , writePort(NULL) , rank(rank) , maxAmount(maxAmount) { } ~Unit() { delete readPort; } inline int GetRank() { return rank; } inline unsigned GetAmount() { return maxAmount; } static void Connect(Unit* to, Unit* from) { to->readPort = from->writePort = new Port<unsigned>; } /// Method for forwarding from previous to next void Forward() { unsigned i = readPort->Read() + 1; printMutex.Lock(); std::cout << "[" << rank << "] received data (" << i << " time)" << std::endl; printMutex.Unlock(); writePort->Write(i); } inline void Pulse() { writePort->Write(0); } inline void Catch() { readPort->Read(); } }; Mutex Unit::printMutex = Mutex(); void* unitRun(void* ptr) { Unit* unit = reinterpret_cast<Unit*>(ptr); int rank = unit->GetRank(); unsigned amount = unit->GetAmount(); // Creating pulse if (rank == 0) unit->Pulse(); // Pulse is going around the threads for (size_t i = 0; i < amount; ++i) unit->Forward(); // Catching pulse if (rank == 1) unit->Catch(); return static_cast<void*>(0); } void ring(unsigned size, int counter) { // Creating units (thread tasks) std::vector<Unit*> units(size); for (size_t i = 0; i < size; ++i) units[i] = new Unit(i, counter); // Units connection for (size_t i = 0; i < size - 1; ++i) Unit::Connect(units[i + 1], units[i]); // Looping Unit::Connect(units[0], units[size - 1]); // Creating threads std::vector<pthread_t> threads(size); for (size_t i = 0; i < size; ++i) pthread_create(&threads[i], 0, unitRun, reinterpret_cast<void*>(units[i])); for (size_t i = 0; i < size; ++i) { pthread_join(threads[i], NULL); delete units[i]; } } int main(int argc, char** argv) { if (argc != 3) { std::cerr << "Syntax error! First argument is number of threads," << " second is amount of operations" << std::endl; return 1; } unsigned size = strtoul(argv[1], NULL, 0); int counter = strtoul(argv[2], NULL, 0); ring(size, counter); return 0; }
[ "kryukov@frtk.ru" ]
kryukov@frtk.ru
f3203921cadf78d4fff5b1970ba513caa28088f2
86db324c6a039369ef9d904defd9a15c944c429c
/thrift/lib/cpp2/test/FlagsTest.cpp
be64a14bd8d7e9c9e60b117a95bb49dd478c68ab
[ "Apache-2.0" ]
permissive
curoky/fbthrift
1eb3cecfee5f72748a5787e792c63276f7734f76
199ca4b1807a705fc55e6fa099c39b7e90ef03e0
refs/heads/master
2023-04-29T21:19:41.027102
2023-04-25T16:23:11
2023-04-25T16:23:11
242,927,696
0
0
Apache-2.0
2020-02-25T06:31:35
2020-02-25T06:31:34
null
UTF-8
C++
false
false
9,038
cpp
/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <exception> #include <folly/CPortability.h> #include <folly/MapUtil.h> #include <folly/portability/GTest.h> #include <thrift/lib/cpp2/Flags.h> #include <thrift/lib/cpp2/PluggableFunction.h> #include <folly/experimental/observer/SimpleObservable.h> THRIFT_FLAG_DEFINE_bool(test_flag_bool, true); THRIFT_FLAG_DEFINE_int64(test_flag_int, 42); THRIFT_FLAG_DECLARE_bool(test_flag_bool_external); THRIFT_FLAG_DECLARE_int64(test_flag_int_external); class TestFlagsBackend : public apache::thrift::detail::FlagsBackend { public: folly::observer::Observer<folly::Optional<bool>> getFlagObserverBool( folly::StringPiece name) override { return getFlagObservableBool(name).getObserver(); } folly::observer::Observer<folly::Optional<int64_t>> getFlagObserverInt64( folly::StringPiece name) override { return getFlagObservableInt64(name).getObserver(); } folly::observer::SimpleObservable<folly::Optional<bool>>& getFlagObservableBool(folly::StringPiece name) { if (auto observablePtr = folly::get_ptr(boolObservables_, name.str())) { return **observablePtr; } return *( boolObservables_[name.str()] = std::make_unique< folly::observer::SimpleObservable<folly::Optional<bool>>>( folly::Optional<bool>{})); } folly::observer::SimpleObservable<folly::Optional<int64_t>>& getFlagObservableInt64(folly::StringPiece name) { if (auto observablePtr = folly::get_ptr(int64Observables_, name.str())) { return **observablePtr; } return *( int64Observables_[name.str()] = std::make_unique< folly::observer::SimpleObservable<folly::Optional<int64_t>>>( folly::Optional<int64_t>{})); } private: std::unordered_map< std::string, std::unique_ptr<folly::observer::SimpleObservable<folly::Optional<bool>>>> boolObservables_; std::unordered_map< std::string, std::unique_ptr< folly::observer::SimpleObservable<folly::Optional<int64_t>>>> int64Observables_; }; namespace { TestFlagsBackend* testBackendPtr; bool useDummyBackend{false}; } // namespace namespace apache::thrift::detail { THRIFT_PLUGGABLE_FUNC_SET( std::unique_ptr<apache::thrift::detail::FlagsBackend>, createFlagsBackend) { if (useDummyBackend) { return {}; } auto testBackend = std::make_unique<TestFlagsBackend>(); testBackendPtr = testBackend.get(); return testBackend; } } // namespace apache::thrift::detail TEST(Flags, Get) { EXPECT_EQ(true, THRIFT_FLAG(test_flag_bool)); EXPECT_EQ(42, THRIFT_FLAG(test_flag_int)); EXPECT_EQ(true, THRIFT_FLAG(test_flag_bool_external)); EXPECT_EQ(42, THRIFT_FLAG(test_flag_int_external)); testBackendPtr->getFlagObservableBool("test_flag_bool").setValue(false); testBackendPtr->getFlagObservableInt64("test_flag_int").setValue(41); testBackendPtr->getFlagObservableBool("test_flag_bool_external") .setValue(false); testBackendPtr->getFlagObservableInt64("test_flag_int_external").setValue(41); folly::observer_detail::ObserverManager::waitForAllUpdates(); EXPECT_EQ(false, THRIFT_FLAG(test_flag_bool)); EXPECT_EQ(41, THRIFT_FLAG(test_flag_int)); EXPECT_EQ(false, THRIFT_FLAG(test_flag_bool_external)); EXPECT_EQ(41, THRIFT_FLAG(test_flag_int_external)); } TEST(Flags, Observe) { auto test_flag_bool_observer = THRIFT_FLAG_OBSERVE(test_flag_bool); auto test_flag_int_observer = THRIFT_FLAG_OBSERVE(test_flag_int); auto test_flag_bool_external_observer = THRIFT_FLAG_OBSERVE(test_flag_bool_external); auto test_flag_int_extenal_observer = THRIFT_FLAG_OBSERVE(test_flag_int_external); EXPECT_EQ(true, **test_flag_bool_observer); EXPECT_EQ(42, **test_flag_int_observer); EXPECT_EQ(true, **test_flag_bool_external_observer); EXPECT_EQ(42, **test_flag_int_extenal_observer); testBackendPtr->getFlagObservableBool("test_flag_bool").setValue(false); testBackendPtr->getFlagObservableInt64("test_flag_int").setValue(41); testBackendPtr->getFlagObservableBool("test_flag_bool_external") .setValue(false); testBackendPtr->getFlagObservableInt64("test_flag_int_external").setValue(41); folly::observer_detail::ObserverManager::waitForAllUpdates(); EXPECT_EQ(false, **test_flag_bool_observer); EXPECT_EQ(41, **test_flag_int_observer); EXPECT_EQ(false, **test_flag_bool_external_observer); EXPECT_EQ(41, **test_flag_int_extenal_observer); } TEST(Flags, NoBackend) { useDummyBackend = true; EXPECT_EQ(true, THRIFT_FLAG(test_flag_bool)); EXPECT_EQ(42, THRIFT_FLAG(test_flag_int)); EXPECT_EQ(true, THRIFT_FLAG(test_flag_bool_external)); EXPECT_EQ(42, THRIFT_FLAG(test_flag_int_external)); } TEST(Flags, MockGet) { EXPECT_EQ(true, THRIFT_FLAG(test_flag_bool)); EXPECT_EQ(42, THRIFT_FLAG(test_flag_int)); EXPECT_EQ(true, THRIFT_FLAG(test_flag_bool_external)); EXPECT_EQ(42, THRIFT_FLAG(test_flag_int_external)); THRIFT_FLAG_SET_MOCK(test_flag_bool, false); THRIFT_FLAG_SET_MOCK(test_flag_int, 41); THRIFT_FLAG_SET_MOCK(test_flag_bool_external, false); THRIFT_FLAG_SET_MOCK(test_flag_int_external, 41); folly::observer_detail::ObserverManager::waitForAllUpdates(); EXPECT_EQ(false, THRIFT_FLAG(test_flag_bool)); EXPECT_EQ(41, THRIFT_FLAG(test_flag_int)); EXPECT_EQ(false, THRIFT_FLAG(test_flag_bool_external)); EXPECT_EQ(41, THRIFT_FLAG(test_flag_int_external)); THRIFT_FLAG_SET_MOCK(test_flag_bool, true); THRIFT_FLAG_SET_MOCK(test_flag_int, 9); THRIFT_FLAG_SET_MOCK(test_flag_bool_external, true); THRIFT_FLAG_SET_MOCK(test_flag_int_external, 61); folly::observer_detail::ObserverManager::waitForAllUpdates(); EXPECT_EQ(true, THRIFT_FLAG(test_flag_bool)); EXPECT_EQ(9, THRIFT_FLAG(test_flag_int)); EXPECT_EQ(true, THRIFT_FLAG(test_flag_bool_external)); EXPECT_EQ(61, THRIFT_FLAG(test_flag_int_external)); } TEST(Flags, MockObserve) { EXPECT_EQ(true, THRIFT_FLAG(test_flag_bool)); EXPECT_EQ(42, THRIFT_FLAG(test_flag_int)); EXPECT_EQ(true, THRIFT_FLAG(test_flag_bool_external)); EXPECT_EQ(42, THRIFT_FLAG(test_flag_int_external)); auto test_flag_bool_observer = THRIFT_FLAG_OBSERVE(test_flag_bool); auto test_flag_int_observer = THRIFT_FLAG_OBSERVE(test_flag_int); auto test_flag_bool_external_observer = THRIFT_FLAG_OBSERVE(test_flag_bool_external); auto test_flag_int_extenal_observer = THRIFT_FLAG_OBSERVE(test_flag_int_external); THRIFT_FLAG_SET_MOCK(test_flag_bool, false); THRIFT_FLAG_SET_MOCK(test_flag_int, 41); THRIFT_FLAG_SET_MOCK(test_flag_bool_external, false); THRIFT_FLAG_SET_MOCK(test_flag_int_external, 41); folly::observer_detail::ObserverManager::waitForAllUpdates(); EXPECT_EQ(false, **test_flag_bool_observer); EXPECT_EQ(41, **test_flag_int_observer); EXPECT_EQ(false, **test_flag_bool_external_observer); EXPECT_EQ(41, **test_flag_int_extenal_observer); THRIFT_FLAG_SET_MOCK(test_flag_bool, true); THRIFT_FLAG_SET_MOCK(test_flag_int, 9); THRIFT_FLAG_SET_MOCK(test_flag_bool_external, true); THRIFT_FLAG_SET_MOCK(test_flag_int_external, 61); folly::observer_detail::ObserverManager::waitForAllUpdates(); EXPECT_EQ(true, **test_flag_bool_observer); EXPECT_EQ(9, **test_flag_int_observer); EXPECT_EQ(true, **test_flag_bool_external_observer); EXPECT_EQ(61, **test_flag_int_extenal_observer); } TEST(Flags, MockValuePreferred) { EXPECT_EQ(true, THRIFT_FLAG(test_flag_bool)); EXPECT_EQ(42, THRIFT_FLAG(test_flag_int)); EXPECT_EQ(true, THRIFT_FLAG(test_flag_bool_external)); EXPECT_EQ(42, THRIFT_FLAG(test_flag_int_external)); THRIFT_FLAG_SET_MOCK(test_flag_bool, true); THRIFT_FLAG_SET_MOCK(test_flag_int, 73); THRIFT_FLAG_SET_MOCK(test_flag_bool_external, true); THRIFT_FLAG_SET_MOCK(test_flag_int_external, 49); folly::observer_detail::ObserverManager::waitForAllUpdates(); testBackendPtr->getFlagObservableBool("test_flag_bool").setValue(false); testBackendPtr->getFlagObservableInt64("test_flag_int").setValue(41); testBackendPtr->getFlagObservableBool("test_flag_bool_external") .setValue(false); testBackendPtr->getFlagObservableInt64("test_flag_int_external").setValue(41); folly::observer_detail::ObserverManager::waitForAllUpdates(); EXPECT_EQ(true, THRIFT_FLAG(test_flag_bool)); EXPECT_EQ(73, THRIFT_FLAG(test_flag_int)); EXPECT_EQ(true, THRIFT_FLAG(test_flag_bool_external)); EXPECT_EQ(49, THRIFT_FLAG(test_flag_int_external)); }
[ "facebook-github-bot@users.noreply.github.com" ]
facebook-github-bot@users.noreply.github.com
2d5b9967b371d88f4cbccb3f786a0091ced74dce
fffc0e7860910ed1c7689b5c1349a35bdd5426da
/pitzDaily/100/p
4dabb0df764655f05dc85debeb8a35eeb646d3b5
[]
no_license
asAmrita/adjointShapeOptimization
001fa7361c9a856dd0ebdf2b118af78c9fa4a5b4
2ffee0fc27832104ffc8535a784eba0e1e5d1e44
refs/heads/master
2020-07-31T12:33:51.409116
2019-09-28T15:06:34
2019-09-28T15:06:34
210,605,738
2
0
null
null
null
null
UTF-8
C++
false
false
96,607
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: v1806 | | \\ / A nd | Web: www.OpenFOAM.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class volScalarField; location "100"; object p; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [0 2 -2 0 0 0 0]; internalField nonuniform List<scalar> 6400 ( 0.257061053697 0.256940073014 0.256861364005 0.256884776888 0.256889989922 0.256692987247 0.256113417636 0.255115578056 0.253710575656 0.251896833988 0.249803967818 0.247630545101 0.245467411123 0.243366429592 0.241376766087 0.239536531115 0.237872144737 0.236398424365 0.235119947594 0.234032448011 0.233124455488 0.232379166471 0.231776748345 0.231296962 0.230921615206 0.230636097355 0.230429457269 0.230293092915 0.23021892151 0.230198291761 0.230222632617 0.230285848541 0.230387348261 0.23053384196 0.230738535727 0.231018241648 0.231390828106 0.231875446015 0.232495072914 0.23328121014 0.23427644722 0.235533478718 0.237113160832 0.239081086746 0.24150444578 0.244446767283 0.2479578116 0.252058610446 0.256726113274 0.261883274376 0.267394893982 0.273071275237 0.278679743541 0.283966947819 0.288701511157 0.292701275568 0.295819463118 0.297928632941 0.299069868638 0.299722922531 0.299980243728 0.299563024964 0.2986509053 0.297517761914 0.296349830452 0.295284619503 0.29443293106 0.293867448567 0.29363238758 0.293744345813 0.294166901981 0.294831123707 0.295652341552 0.296537389567 0.297391453719 0.298127601699 0.29867839861 0.298996525808 0.299124840961 0.299194327337 0.257053358421 0.256925167409 0.256876644297 0.256875983978 0.256798547014 0.256522612285 0.255870632268 0.254788428928 0.253330208156 0.251527979173 0.249481002958 0.24732740001 0.245164006204 0.243060312431 0.241071992248 0.239239158395 0.237588111946 0.236132693815 0.234876131969 0.233812768131 0.232929850937 0.232209527588 0.231631159985 0.231173875199 0.230818851826 0.230550761389 0.230357914107 0.230231196171 0.230162506812 0.23014375981 0.230167307207 0.23022780083 0.23032463001 0.230463349561 0.230654984538 0.230914008855 0.2312575842 0.231707288365 0.232288381449 0.233029510683 0.233969105258 0.235157624059 0.23665450438 0.23852565248 0.240840282082 0.243665155135 0.247054168469 0.251033820781 0.25558791721 0.260645149785 0.266073474754 0.271683676272 0.277245320447 0.282512956722 0.287255405151 0.291266769996 0.294363827305 0.29648163516 0.297882803301 0.298776988117 0.299048626468 0.298682604478 0.297878382825 0.296849459808 0.295768646045 0.29477436963 0.293977473915 0.29345621598 0.293255302148 0.293396710824 0.293852986637 0.294557350193 0.295424374018 0.296358888081 0.297262778984 0.298044376316 0.298632173849 0.298978503248 0.299148488271 0.299296922959 0.257189823091 0.256991870331 0.2568703169 0.256728385004 0.256434996801 0.255905731956 0.255053718353 0.253827427025 0.252270832053 0.250434936108 0.248402045905 0.246275910247 0.24414831398 0.242091703602 0.240161253111 0.238395547258 0.236818430319 0.235440933279 0.23426344391 0.233277726058 0.232468950526 0.231817805299 0.231302767973 0.23090239185 0.230597294113 0.230371419982 0.230212298499 0.230110365375 0.230057818847 0.230047792541 0.230074410962 0.230133920902 0.230226189549 0.230355470602 0.230530324166 0.230764020911 0.231076046898 0.231485832016 0.232012104382 0.232682475014 0.233535054966 0.234617427536 0.235987122722 0.237710762333 0.239861479934 0.242512762634 0.245727661324 0.249543646638 0.253955103895 0.258898033946 0.264241314954 0.269791377039 0.275316668303 0.280571579025 0.285309442955 0.289288160796 0.292332844568 0.294551580856 0.296215337919 0.297287916773 0.297639595999 0.297396923305 0.296724875177 0.295805086668 0.29480770457 0.293876554615 0.293125719065 0.292635091185 0.292453672471 0.292614119761 0.293095770481 0.293834304773 0.294746702206 0.29574087116 0.296722173455 0.297603421525 0.298321193305 0.298844697235 0.299210407077 0.299501399489 0.257463246589 0.257187420237 0.25689483187 0.256479934608 0.255886461713 0.255065984241 0.253967908254 0.252559665207 0.250877758065 0.248983397313 0.246950704044 0.244861964909 0.242795404587 0.240817992058 0.238980819007 0.237318179728 0.235849650019 0.234582323085 0.233513069346 0.232630712407 0.231918202891 0.231354804095 0.23091824164 0.230586725631 0.230340624364 0.23016350228 0.230042425023 0.229967592278 0.229931604846 0.22992877817 0.229955009062 0.230008167784 0.230088529107 0.2301993945 0.230348357992 0.230549438879 0.230818066194 0.231167122248 0.231614797372 0.232188054048 0.232921304612 0.233858391682 0.235054169567 0.236575328521 0.238499052469 0.240907771819 0.243878407671 0.247465264105 0.251678817305 0.256465395344 0.261696963996 0.267174210131 0.27266315945 0.27790624005 0.282622778945 0.286561940809 0.289659809106 0.29215539763 0.294066136439 0.29521481379 0.295666623683 0.295538698058 0.294980746054 0.294162773679 0.293250956889 0.292390377233 0.291697405796 0.291254319069 0.29111480072 0.291319875769 0.291852296913 0.292650290273 0.293634873119 0.29471917691 0.295814943199 0.296842734663 0.297745886763 0.298497927333 0.299096591829 0.299616308027 0.257743400002 0.257325084437 0.256781399708 0.256062293658 0.255152493189 0.254030306125 0.252683298831 0.251092110999 0.2492850435 0.247323326543 0.245281078076 0.243231747129 0.241241325078 0.239365432986 0.237646299154 0.236111522256 0.234775257013 0.233640050611 0.232698956786 0.231937689579 0.231336843509 0.230874107135 0.230526378913 0.230271612153 0.230090215802 0.229965897379 0.229885894703 0.229840732968 0.229823609553 0.229829877577 0.229856841394 0.229903567591 0.229971012807 0.230063414888 0.230189899643 0.230361429243 0.230584823049 0.230870292144 0.2312364282 0.231706447687 0.23231044416 0.233087677826 0.234089185989 0.235380117798 0.237040470728 0.239161988176 0.241837720482 0.245142894309 0.249108182796 0.253692969294 0.258775328652 0.264147041236 0.269565529231 0.274748892907 0.279392030354 0.283315464101 0.286630412157 0.289365631073 0.291353101129 0.292586037458 0.293133636389 0.293106665751 0.292649703506 0.291925626418 0.291096306991 0.290307030635 0.289676784486 0.289291182859 0.289208098279 0.289475334195 0.290077958408 0.290957960075 0.292041076959 0.293245149679 0.294486476028 0.295689091087 0.296793818109 0.297764694788 0.298551578639 0.299244238221 0.257691331119 0.257078346031 0.256288072305 0.25530510488 0.25413827708 0.252773697753 0.251209610453 0.249456654174 0.247552921399 0.245553354553 0.243523802171 0.24153054309 0.239631344315 0.237871847549 0.236284872903 0.234890609756 0.233697504473 0.232703593235 0.231898226495 0.231264055894 0.230779236138 0.230419732415 0.230161499385 0.229982266333 0.229862803841 0.229787510171 0.229744450391 0.229725032818 0.229723350848 0.229735678093 0.229760261577 0.229797664003 0.229850849721 0.229926861787 0.230032765693 0.230170725139 0.230346364594 0.230571434822 0.230860276025 0.231231489722 0.231709836531 0.232328776703 0.233133799094 0.234186293668 0.235567016488 0.237375922676 0.239723067106 0.24270693468 0.246383083867 0.250725652834 0.255623665069 0.26085216539 0.266147623048 0.271209389925 0.275771660698 0.279805775817 0.283297950591 0.286092668267 0.288127004972 0.289415849358 0.290025444159 0.290065532821 0.289677763101 0.289020706439 0.288253797631 0.287523151055 0.286950968744 0.286627278867 0.286613552866 0.286963130503 0.287660928797 0.288651564415 0.289863831368 0.291217428673 0.292629179594 0.29402131486 0.295325995841 0.296494817099 0.297429040996 0.298246137835 0.256955253709 0.256237641512 0.255322453187 0.254176770284 0.252833660368 0.2512974443 0.249579496039 0.247714106804 0.245752995247 0.243750409546 0.241763575792 0.239849322236 0.238057030988 0.236424526351 0.234977388904 0.233729596482 0.232684470545 0.231835757333 0.231169068605 0.230663757042 0.230295230338 0.230037498384 0.229865520324 0.229756993145 0.229693497202 0.229660749174 0.229648231704 0.229648976637 0.229658626659 0.229674656001 0.229696931375 0.229729027615 0.229775465582 0.229837851472 0.229918436387 0.230022610008 0.230157327534 0.230330960937 0.230554026287 0.230840317719 0.231208648148 0.231685484997 0.232308807783 0.233133493959 0.2342374654 0.235726033673 0.237725214809 0.240357157801 0.243708845508 0.24776908262 0.252441399167 0.257470305593 0.262565783219 0.267459325833 0.272006305399 0.276111285504 0.279607355204 0.282391807639 0.284422630111 0.285714738756 0.286335284844 0.28639388306 0.286030550081 0.285401879839 0.284666929348 0.283973945547 0.283449350179 0.283188663967 0.28325431923 0.283701949105 0.284514932406 0.285640074535 0.287007214394 0.288534574789 0.290135493569 0.29172637713 0.293227751739 0.294581442853 0.295646495536 0.296576388878 0.255529412462 0.254823632979 0.253918923439 0.252718681773 0.251285157144 0.249648720264 0.247846291107 0.245928588522 0.243954827976 0.241981734491 0.240062888818 0.238247275878 0.236575856029 0.235079249837 0.233777104404 0.23267842201 0.231782179441 0.231078115869 0.230548000256 0.230167589283 0.229909259141 0.229745064647 0.229649314986 0.229600237682 0.229581087644 0.229579805481 0.22958817067 0.22960189037 0.229619103114 0.229638935632 0.229661927773 0.229688639719 0.229721684065 0.22976577329 0.2298250613 0.229904097341 0.230008208642 0.230143582798 0.230317626705 0.230539798828 0.230823101778 0.231186569952 0.231659292052 0.232286680394 0.233139044199 0.234322034596 0.235975693988 0.238244163335 0.241252375885 0.244999522497 0.249395480977 0.25414986064 0.258975125827 0.263703688869 0.268187528041 0.272205231357 0.275615209422 0.278318993557 0.280275942314 0.281503172651 0.282069166929 0.28208369313 0.28168624326 0.281033141188 0.280285138401 0.279594856056 0.279095533526 0.278890705066 0.279040124945 0.279595871795 0.280540184695 0.281821741049 0.28336792576 0.28509124448 0.28689801205 0.288696416215 0.290394162624 0.291926606594 0.293116258775 0.294157233583 0.253625087175 0.253017588061 0.252196678367 0.251010035455 0.249557159415 0.247888842674 0.246065589042 0.244150892461 0.242208512085 0.240297147392 0.238468911226 0.236767577017 0.235227405599 0.233872838884 0.232718504302 0.231769261118 0.231020265903 0.230457305258 0.230058045664 0.229794384438 0.229635678848 0.229552342226 0.229519003642 0.229515901279 0.229529486959 0.229551308615 0.22957507823 0.22959600551 0.229612673695 0.229626951639 0.229641562456 0.229658955226 0.229681832611 0.22971359102 0.229758009795 0.229819321708 0.22990212271 0.230011257939 0.230151960365 0.230330400043 0.230554828477 0.230837544285 0.231198398813 0.231671516164 0.232314714509 0.233228187295 0.234565452902 0.236486796562 0.23915197371 0.242555580057 0.246595483618 0.250988566747 0.255519300777 0.260031345551 0.264315484356 0.268154142237 0.271391601635 0.273930106709 0.275731558124 0.27681520567 0.277250799887 0.27714844355 0.276647706485 0.275905424562 0.275085382749 0.274346646323 0.27383377266 0.273667466055 0.27390021248 0.274568726472 0.275655202445 0.277109962188 0.278854295471 0.280791069211 0.28281656915 0.28482909804 0.286723015724 0.288429703514 0.289737376669 0.290885576253 0.251562989234 0.25105985621 0.250312075376 0.249159598274 0.247731311156 0.246083167295 0.244289824539 0.242422948815 0.240549559588 0.238728977414 0.237011512202 0.235437041387 0.23403500548 0.232825217672 0.2318183241 0.231015617263 0.230408618356 0.229979193014 0.229700610558 0.22954052475 0.229465866841 0.22944713819 0.22946120643 0.22949174561 0.229525775661 0.229554473553 0.229575897029 0.229591524869 0.229603072033 0.229612492551 0.229621726269 0.229632751741 0.229648005155 0.229670573129 0.229704119332 0.229752748968 0.229820731501 0.229912240935 0.230031302114 0.230182083464 0.230369624834 0.230601182884 0.230888475755 0.231255205494 0.23174480989 0.232447634896 0.233527545938 0.235145979491 0.237467080022 0.240480934677 0.244055100996 0.24806134483 0.252250273265 0.256468320192 0.260465362703 0.264028334465 0.267000201768 0.269284264194 0.270844528365 0.271702011164 0.271927485458 0.271631049503 0.270952243054 0.27004831536 0.269086644006 0.268233731532 0.26765060274 0.267481325999 0.26777135798 0.268541276706 0.269776903054 0.271423076816 0.273385026615 0.275550545575 0.277803822055 0.280032978935 0.282119618875 0.283994054301 0.285411940607 0.286661261467 0.249572589035 0.249114471446 0.248393570121 0.247273802663 0.24589164792 0.244296150146 0.242568086237 0.24078193309 0.239005839617 0.237298218354 0.235706755818 0.234267809842 0.233007176431 0.231941285946 0.23107768599 0.230414637654 0.229940228823 0.229631968568 0.229458667975 0.229384947829 0.229376488723 0.229405470951 0.229450983692 0.229496263776 0.229532330418 0.229558079828 0.229575560742 0.229587148377 0.229594797101 0.229600187175 0.229604865564 0.229610538115 0.229619353959 0.229634150199 0.229658505973 0.229696553528 0.229752610894 0.229830757244 0.229934572692 0.23006718891 0.230231741734 0.230432510778 0.230675227342 0.230977321308 0.231371282336 0.231933609771 0.232819797448 0.234176169496 0.236111287532 0.238690920792 0.241812048027 0.245396931903 0.249222975414 0.253063771753 0.256685410508 0.259882225487 0.262500025002 0.264444668414 0.265682603361 0.266236456924 0.266177375707 0.26561377481 0.264683115273 0.263540459083 0.262355588678 0.261305279582 0.260590910888 0.26038488453 0.260698122912 0.261527923506 0.262890083492 0.264726374034 0.266914000678 0.269315374382 0.271797348442 0.274237063761 0.276505079312 0.278534902964 0.280051791186 0.281395716933 0.247684092619 0.247232379612 0.246515248624 0.245429032418 0.244104696786 0.2425814752 0.240941724512 0.239258430098 0.237598463341 0.236017875989 0.234561130959 0.233261192927 0.232140785896 0.23121364175 0.230484853628 0.229950036564 0.229593849023 0.229389820955 0.22930325768 0.229296446103 0.229336090823 0.229395957516 0.229455254114 0.229503034607 0.229537381277 0.22956003472 0.229574085822 0.229582284962 0.229586726818 0.229588981095 0.229590297094 0.229591956193 0.229595659829 0.229603908975 0.229620170541 0.22964873457 0.229694259708 0.229761086479 0.229852730646 0.22997178996 0.230120210566 0.23030119221 0.230516702545 0.230781067476 0.231121017401 0.231592723406 0.232303899117 0.233407988063 0.234993800464 0.237159856531 0.239887299522 0.243048108665 0.246438939632 0.249832845149 0.253004816828 0.255758384628 0.2579461765 0.259479200587 0.260327783292 0.260516760098 0.260117052799 0.259232799884 0.257996178594 0.256555362161 0.255075686667 0.253712346313 0.25271616103 0.252359964919 0.252641879343 0.2535182829 0.255013540133 0.257043228058 0.259454120066 0.262083344023 0.264777847521 0.26740394452 0.269824566229 0.27198282178 0.27357854844 0.275006737956 0.245853932349 0.245412181642 0.244709473525 0.243668594221 0.242413341454 0.240976452265 0.239440154909 0.237873508289 0.236340434289 0.234893570848 0.233573851387 0.232410974211 0.231424910532 0.230627141752 0.230020799838 0.229599274972 0.229344247395 0.229225845468 0.229206135378 0.229247164509 0.229317657446 0.229392214048 0.2294556147 0.229503398592 0.229536432597 0.229557434048 0.229569880607 0.229576560446 0.229579558825 0.229580350623 0.229579910786 0.229579158436 0.2295793549 0.229582599443 0.22959218871 0.229612555184 0.229648762435 0.229705487425 0.229786246715 0.229893316419 0.230027561401 0.230191712853 0.230386537112 0.230619935074 0.230914571584 0.231309754651 0.2318763695 0.232761168664 0.234080277786 0.2359132586 0.238244630791 0.240960596198 0.243875126896 0.246771918951 0.249438049538 0.251689731808 0.253390415983 0.254459680994 0.254874560744 0.25466396668 0.253899486774 0.252683656636 0.251152571997 0.249461373712 0.247790594165 0.246256568141 0.244964336534 0.244142973412 0.243957254168 0.2446772637 0.246251678484 0.24846701254 0.251087179477 0.253916192177 0.256780884946 0.259539171835 0.262052709969 0.264284093925 0.265916819878 0.267409808862 0.244076951473 0.243662919686 0.242996357646 0.242017129082 0.240842972913 0.239503708429 0.238080795688 0.236638376664 0.235236628342 0.233924222298 0.232738487432 0.231706038449 0.23084438565 0.230163159553 0.229664011241 0.22933862795 0.229166297797 0.22911373587 0.229140616188 0.229211836369 0.229300018347 0.229380753616 0.229444733906 0.229492281978 0.229525595954 0.229547278102 0.229560704102 0.229568447403 0.229572391578 0.2295738023 0.229573453649 0.22957209861 0.229570730392 0.229571090961 0.229576142669 0.229590176182 0.229618473053 0.229665865497 0.229735692304 0.229830006222 0.22994893279 0.230093274102 0.230265666349 0.23046693 0.230713715124 0.231039706213 0.231510204902 0.232236572991 0.233329881443 0.234858927395 0.236809510907 0.23907851162 0.2414969328 0.243865937727 0.245990060214 0.247702422161 0.248881430896 0.249459358441 0.249423608071 0.248809403307 0.247693872022 0.246195404478 0.244482372245 0.24273412176 0.241025990933 0.239389389692 0.238020937105 0.236996671662 0.236382721717 0.23650492038 0.237683856998 0.239741360235 0.242327144642 0.245158582563 0.248020882523 0.250756132099 0.253222313913 0.255406345363 0.256986958885 0.258502410259 0.242389595387 0.242014444491 0.241398719806 0.240493262612 0.239409622698 0.238175880024 0.236871845138 0.235556321144 0.234285447323 0.233103710938 0.232044907729 0.231132766153 0.230382592521 0.229802449062 0.229392852203 0.22914430868 0.229034291043 0.229027115034 0.229085231392 0.229178278179 0.229277282746 0.229360169675 0.229423727829 0.229471784269 0.229507080392 0.229531563185 0.229547870897 0.22955810691 0.229564040518 0.229566936099 0.229567689794 0.229567067226 0.22956586602 0.229565467093 0.229568360168 0.22957831651 0.229600266202 0.22963880614 0.229696912419 0.229776238245 0.229877551572 0.230000040181 0.230146212879 0.23031782232 0.230524679672 0.230794660842 0.231184602001 0.231782969268 0.232681634902 0.233934036973 0.235521831139 0.237350146966 0.239267292473 0.241095498858 0.242661139602 0.243818346733 0.244464626368 0.244549210493 0.244072784605 0.243079686646 0.241666592968 0.239988643934 0.238210700306 0.23641000698 0.234604409129 0.233025722385 0.23182031824 0.230904867854 0.230266802888 0.230020057141 0.230458175045 0.23176386731 0.233841359034 0.236310818116 0.238844827182 0.241262781579 0.243417846223 0.24532483165 0.246676085387 0.248126945094 0.240833356867 0.240499215494 0.23993906715 0.239112468379 0.238123894628 0.236999188816 0.235815252015 0.234625218812 0.233481045439 0.232422968406 0.231481371118 0.230677271687 0.230023944547 0.229528061082 0.229189319934 0.228997911529 0.228930982755 0.228952339137 0.229032671898 0.229145230585 0.22925256374 0.229335435445 0.229398018259 0.22944718004 0.229485429673 0.229513686906 0.229533267458 0.229546051121 0.229554007598 0.229558612615 0.229560925168 0.229561720522 0.229561657044 0.229561745817 0.229563895799 0.2295711978 0.229587630553 0.229617164425 0.229663001692 0.229727081103 0.229810518451 0.229913223828 0.230035197449 0.230177342399 0.230346920722 0.230567700292 0.230887516763 0.231374919522 0.232098572487 0.233093391776 0.234334075473 0.235732215702 0.237153226989 0.23844230407 0.239450732946 0.240057110179 0.240181831603 0.239794065203 0.23890897085 0.237589937555 0.235975200377 0.2342196036 0.232360940487 0.230500060174 0.228782804013 0.227382897371 0.226293354655 0.225428036404 0.224762185126 0.224333776982 0.22422127827 0.224775927052 0.225917648835 0.227679870887 0.229527333508 0.231252006963 0.232712707355 0.233969833146 0.234773582371 0.235985179664 0.23943471523 0.239138803947 0.238632993004 0.237884988614 0.236991427183 0.235975066089 0.234908705429 0.233839537399 0.232815235771 0.231871776435 0.231036269035 0.230327166898 0.229755832566 0.229327645646 0.22904185613 0.228889463682 0.228849316893 0.228888290493 0.228984701238 0.229112696637 0.229227056078 0.229310782535 0.229373734528 0.229424269348 0.22946470626 0.229495535969 0.229517399429 0.229532209053 0.229542088392 0.229548580084 0.229552740634 0.229555257113 0.229556614358 0.229557593202 0.229559585228 0.229564884754 0.229576645904 0.229598522086 0.229633720599 0.229684375916 0.229751358181 0.229834357116 0.229932515266 0.23004587533 0.230180306992 0.230356269193 0.230611847434 0.230996399669 0.231555375249 0.232304583375 0.233210841697 0.234191455351 0.235128893707 0.235892350648 0.236359971131 0.236437531826 0.236070967271 0.235249576259 0.234005574443 0.232440634936 0.230721363928 0.228846210545 0.226993080871 0.225186090214 0.223635418836 0.222377369312 0.221341222078 0.22046305648 0.219732198437 0.219139705286 0.218677324392 0.218483943792 0.218832347583 0.219502481563 0.220257200884 0.220861663752 0.221126559977 0.221167303588 0.220863973786 0.221469686098 0.2382034619 0.237941674401 0.237486860374 0.236814406383 0.236012693906 0.235100858858 0.234146788523 0.233191633499 0.232278757677 0.231439930741 0.230699155923 0.230072491309 0.229569537354 0.229194489661 0.228946390972 0.228817985292 0.228791024441 0.228838934676 0.228944364177 0.229083037347 0.229202109323 0.229289623646 0.229354218469 0.229405151668 0.229446151298 0.229478044814 0.229501585395 0.229518252174 0.229529943302 0.229538186581 0.229543988977 0.229547957586 0.229550506292 0.229552214375 0.229554124878 0.229558047 0.229566533303 0.229582579437 0.229608945528 0.229647501642 0.229698952719 0.22976284272 0.229837923867 0.229923583374 0.230024715688 0.230158509247 0.23035229761 0.230636518477 0.231034748314 0.231544995305 0.232127032611 0.232704251508 0.233176452915 0.233437362082 0.233393151506 0.23297873545 0.232165928338 0.230963079951 0.229432217909 0.227715704007 0.225868833735 0.224013802019 0.222182320523 0.22052514019 0.219138608012 0.217979960974 0.216963974788 0.216036575101 0.215194175895 0.21439758038 0.213605655233 0.212825094861 0.212320951862 0.211730600977 0.211085365704 0.210162502879 0.20861685202 0.206594043909 0.20417576783 0.20331878612 0.237138049461 0.236906558749 0.236499222613 0.23589820276 0.235183501899 0.234370491205 0.233521760848 0.232672539497 0.231861969628 0.231117749357 0.230461000595 0.229905619999 0.229459733071 0.229126589729 0.228905124258 0.228789613338 0.228763017423 0.228812024602 0.228916016706 0.229060821308 0.229185774328 0.22927499468 0.229338457163 0.229388030849 0.229428790447 0.229461700361 0.229487093412 0.229505607208 0.229518827831 0.229528382772 0.229535396221 0.229540475616 0.229543961884 0.229546274313 0.229548233101 0.229551226568 0.229557246118 0.22956858482 0.229587388327 0.229615110845 0.229652206847 0.229698024425 0.229751041054 0.229810193835 0.229879663191 0.229972759648 0.230104679719 0.230287367083 0.230524606728 0.230799140249 0.231065822126 0.231255408632 0.231285609383 0.231074926589 0.230558230514 0.22970012825 0.228495852943 0.226976805611 0.225254926632 0.223482017418 0.221542685334 0.21974118282 0.218025425566 0.21654161112 0.215279879106 0.214173575334 0.213144660137 0.212142012481 0.211146569701 0.21010161997 0.208942801927 0.207601408621 0.206099891043 0.204493408336 0.202085223972 0.199261589463 0.195164015127 0.189801167873 0.183357774241 0.178698977801 0.236230827363 0.236026409059 0.235663361764 0.235129348378 0.234496074733 0.233775282755 0.233024203289 0.232272451278 0.231555141408 0.230896110966 0.230313869733 0.229820421482 0.229422897268 0.229124121479 0.228923396613 0.228818464362 0.228783559547 0.228811649124 0.228914086511 0.22906391128 0.229185793546 0.229268174199 0.229326285933 0.229372604109 0.229411938575 0.229445186537 0.229472628894 0.229493623882 0.229508721385 0.229519410842 0.229527216646 0.229533037259 0.229537265654 0.229540193483 0.229542338652 0.229544628575 0.229548538916 0.229555827768 0.229568070464 0.229586191894 0.229610218259 0.22963918665 0.22967132088 0.229705254945 0.229744539767 0.229797385417 0.229865379173 0.22994286368 0.230016422952 0.230056801696 0.23001686552 0.229836589001 0.229452371177 0.22880770609 0.227866420316 0.226620783225 0.225086677781 0.223333163001 0.22150107066 0.219557451225 0.217793451398 0.216068208895 0.214515273342 0.213186320103 0.212015026418 0.210927526787 0.209855194298 0.208751084571 0.207574696582 0.206253226759 0.204700111143 0.202809101322 0.200460574165 0.197547697407 0.193468185581 0.188455205284 0.180984236694 0.170496374836 0.156542276016 0.141704044595 0.235470950236 0.235291003228 0.234969393822 0.234497905104 0.233940225082 0.233304771642 0.232643564409 0.231981034182 0.231348529639 0.230766266767 0.230250434583 0.229811215853 0.229455389567 0.229185931427 0.228999947274 0.228894918568 0.228853679644 0.228865264257 0.228970646414 0.229108587131 0.229216273926 0.229288296345 0.229338846542 0.229378057832 0.229410220425 0.229436976205 0.229460335751 0.229481608183 0.229499011847 0.229511204365 0.229519621635 0.229525869375 0.229530646223 0.229534166495 0.22953658689 0.229538361247 0.229540437072 0.229544130666 0.229550537183 0.229560072877 0.229572252434 0.22958568142 0.229598247279 0.229608339501 0.229618720598 0.229630719369 0.229631149367 0.229598234683 0.229504306138 0.229311782502 0.228974840243 0.228444749751 0.22767747985 0.22664189378 0.225330137781 0.223758047015 0.22196586802 0.220076647013 0.218220762751 0.216251327466 0.214553092281 0.21298264066 0.211612639888 0.210409270068 0.209297330284 0.208202537715 0.207063602003 0.205836669254 0.204461971415 0.202852425472 0.200900344274 0.198466298933 0.195349993161 0.191166594684 0.185851964413 0.178342146011 0.16684360412 0.148960995646 0.119619759426 0.0592651020798 0.234846432843 0.234688676095 0.234405763522 0.233992279444 0.23350432832 0.232947400256 0.232368577741 0.231787607139 0.231232363879 0.230719610538 0.230263753156 0.229872310858 0.229550876767 0.229303091315 0.22912804713 0.229024839452 0.228987174849 0.229002567843 0.229097092817 0.229207600014 0.229293390294 0.229352063823 0.229391846623 0.229419072547 0.229437803226 0.229450676272 0.229460774981 0.229473344763 0.229489741627 0.229503659567 0.22951290138 0.229519455016 0.229524628668 0.229528623906 0.22953132788 0.229532732664 0.229533282823 0.22953375754 0.229534824442 0.229536518916 0.229537893997 0.229537058612 0.229531424233 0.22951911959 0.229501596289 0.229471068145 0.229399089745 0.229249816795 0.228984520389 0.228561104859 0.227938360314 0.22708083432 0.225965064813 0.224585663402 0.222960237482 0.221125482156 0.219160507157 0.217205966422 0.21518469039 0.213498955617 0.211901768511 0.210485123372 0.20925986228 0.208145867528 0.207065098495 0.205943547566 0.204722905967 0.20336020047 0.201780953648 0.199887309165 0.197555188415 0.194619183724 0.190853626413 0.185776440118 0.179350278356 0.1696221135 0.155173353355 0.132499051966 0.0975125860401 0.0431214525603 0.234344626971 0.234207077286 0.233960125113 0.233600067819 0.233176023095 0.232691010418 0.232187537619 0.231681218501 0.231196827468 0.23074697687 0.230342874892 0.229991971706 0.229699849657 0.229471873727 0.229312192058 0.229221933315 0.229193741451 0.229207051405 0.229278331511 0.229356901657 0.229416740747 0.229455991017 0.229478634413 0.22948851499 0.229489500764 0.229485171581 0.229479052183 0.229475761094 0.229482790113 0.22949666306 0.229507293757 0.229514431714 0.229519959702 0.229524264343 0.229527067942 0.229528143485 0.229527443098 0.229525102323 0.229521289242 0.229515719486 0.229507110586 0.229493131383 0.229470612846 0.229437380007 0.229392540852 0.229316736456 0.229166701065 0.228895018893 0.228455246624 0.227804522266 0.226909237918 0.225748872352 0.22432165177 0.222647733157 0.220765580313 0.218736569163 0.216690504889 0.214745910096 0.212746510592 0.211158237545 0.209725799547 0.208480286807 0.207371436353 0.206317735123 0.205245527112 0.204083642146 0.202772705604 0.201267748524 0.199487195288 0.197325892072 0.194647789428 0.191269639341 0.186950571164 0.181222044739 0.173659531078 0.162770027042 0.147382311629 0.123932274444 0.0894406555156 0.042893593683 0.233953204629 0.233833888065 0.233619982292 0.233308644109 0.232942698646 0.232523175309 0.232088445594 0.2316505333 0.231229490417 0.230834272411 0.230474365481 0.230159263255 0.22989669244 0.229692935636 0.22955368358 0.229480179846 0.229454825125 0.229457932682 0.229499011028 0.229543106857 0.229574125685 0.229589632299 0.229590785168 0.229579868821 0.229560470457 0.229536701628 0.229512475463 0.229492335041 0.229483382051 0.229490899072 0.229502887257 0.229511375645 0.229517339525 0.229521782179 0.229524457862 0.229525045506 0.229523202198 0.229518465083 0.229510338243 0.229498090633 0.229480175811 0.229453973775 0.22941574548 0.229363001543 0.229290854497 0.229166063024 0.228931961268 0.228532328494 0.227916432558 0.227044160322 0.225891994933 0.224455624134 0.222755754898 0.220835704246 0.218752968599 0.216610838832 0.21453813988 0.212447984011 0.210804722323 0.209322704509 0.208026782707 0.206907238006 0.205875796008 0.20485232303 0.203767753522 0.202556022667 0.201155803343 0.199506615322 0.197531795001 0.195124199437 0.192138654519 0.188379519803 0.183585635354 0.177321384025 0.168891353389 0.157790962653 0.142348613383 0.119341607301 0.0855409913238 0.0427657639074 0.233659935158 0.233556982641 0.23337303179 0.233105547178 0.232791837001 0.232431417994 0.232058951359 0.231681698767 0.231315397964 0.23096728749 0.230648209955 0.230368461094 0.230136592309 0.229958893428 0.229840082543 0.229781593764 0.229751846416 0.22973772563 0.229746380011 0.229755786709 0.229756541773 0.229745850454 0.229722962457 0.229689360843 0.229648328582 0.229603933632 0.229560299684 0.229522030865 0.229495414037 0.229489624888 0.229500163646 0.229510651605 0.229517381707 0.229521808717 0.229524204335 0.229524076066 0.229520957837 0.229514078072 0.229502247542 0.229484023139 0.22945748349 0.22941983864 0.229366912635 0.229295938971 0.229195731414 0.229017487352 0.228693394807 0.228161302844 0.2273696089 0.226284092408 0.224893305542 0.223210308396 0.221278141174 0.219157888491 0.216929927465 0.214760079665 0.212736807626 0.210681719238 0.209174435842 0.207850009189 0.206702537069 0.205678392817 0.204693403064 0.203675011102 0.202559715719 0.201286995496 0.199795993984 0.198016042092 0.195861253262 0.193230304903 0.189977594556 0.185901375594 0.180730209018 0.174074538058 0.165213322853 0.154084837256 0.138612913464 0.116418958349 0.0835324584361 0.0432245028207 0.233453424037 0.233364880408 0.233207515418 0.232978808018 0.232711314734 0.23240351013 0.232085663338 0.23176043061 0.231441920108 0.231136925872 0.230856634768 0.230611812523 0.230410075989 0.230257391329 0.230156452744 0.230108874373 0.230070716539 0.2300358217 0.230011398391 0.22998647979 0.229956746613 0.229918836522 0.229870942698 0.229814163954 0.229751284752 0.229685999428 0.229622364527 0.229565182618 0.229520565854 0.229496888408 0.229499602978 0.229512226125 0.229520541402 0.229524977651 0.229527041016 0.229526097483 0.229521432473 0.229512332255 0.229497216007 0.229473754245 0.229439368988 0.229391037473 0.229324333566 0.22923619933 0.229106284653 0.228869650131 0.228450135576 0.22778252433 0.226817645518 0.225529814247 0.223921235855 0.22202337392 0.219899789995 0.217626248315 0.215319964787 0.21315816355 0.211020182089 0.209360735964 0.207953776709 0.206740961719 0.205697587585 0.20473171812 0.203763258877 0.20272661205 0.201563496318 0.200217794555 0.198631945229 0.196741428479 0.194435433923 0.191603653794 0.188115865648 0.183778757302 0.178319497221 0.171378883433 0.162365941156 0.150795354949 0.135311568508 0.114409541489 0.0829511528922 0.0444508704596 0.233322705498 0.233246831719 0.233112429185 0.232917215818 0.232689672843 0.232427519459 0.232156213063 0.231875954637 0.231599987227 0.23133506092 0.23109152905 0.230879658261 0.230706065485 0.230575617728 0.230490061917 0.230447615764 0.230398370279 0.230342075719 0.230285635075 0.230228046766 0.230168756267 0.230103932518 0.230031388297 0.229951901366 0.229867651278 0.229781832775 0.229698179715 0.229621644038 0.229558469305 0.229516502347 0.229505145804 0.229516972969 0.229527706792 0.229532304187 0.229533841986 0.229532096891 0.229525678725 0.229513988441 0.229495601768 0.229467464743 0.229426072205 0.229367872321 0.22928833962 0.229183831785 0.229021635693 0.228721523089 0.228201983408 0.227397532769 0.226264461764 0.224787729234 0.22298465099 0.22090529502 0.218628539242 0.216248058486 0.213944749709 0.211873540882 0.209734350619 0.208255738509 0.206997498841 0.205911202957 0.204943424739 0.204007666104 0.203032707491 0.201959662388 0.200735244514 0.199307116179 0.197620346589 0.195617487625 0.193198190203 0.190218737864 0.186526661884 0.181959746786 0.176259489669 0.169068658744 0.159863406491 0.147819401856 0.132758638745 0.113173748587 0.0832405122172 0.0458666375892 0.233258133803 0.233193087242 0.233077781511 0.232910651475 0.232716673031 0.232492695601 0.232261004085 0.232019919939 0.231782104049 0.231553792237 0.231344376255 0.231162444742 0.231014072695 0.230902430544 0.23082932295 0.230787256698 0.23072602183 0.230649322797 0.230563089422 0.230475407244 0.23038827096 0.230297769326 0.230201723857 0.230100592603 0.229995872683 0.229890205751 0.229786967976 0.229691001586 0.229608931336 0.229548891647 0.229520222036 0.229526097859 0.22953968755 0.22954489725 0.229545523896 0.229542956375 0.229534833254 0.22952017664 0.229498155801 0.229465539372 0.229417886705 0.229350685243 0.229259400238 0.22913892299 0.228941040367 0.228572536672 0.227949461188 0.227008758255 0.225714755822 0.224064671778 0.222092423555 0.219865601399 0.217473528745 0.215035429897 0.212754543644 0.210648598954 0.208868665414 0.207476890949 0.206313707965 0.205319686731 0.204397172164 0.203466572714 0.202465866644 0.201342206704 0.20004633256 0.198528351517 0.196734196607 0.194602399103 0.192060745562 0.188982892419 0.185189742562 0.180469878777 0.17457251253 0.167162859624 0.15777762445 0.145530469569 0.130893450412 0.112323960672 0.0837744689845 0.0469164491284 0.233251045896 0.233195006472 0.23309474874 0.232950252228 0.232783523379 0.232590616511 0.232392148285 0.232185058316 0.231981332029 0.231785702712 0.231607127825 0.231451738253 0.231325401333 0.23122948747 0.231166565006 0.231122583667 0.231049565572 0.23095345026 0.230840246492 0.230725351073 0.230612558523 0.230498197749 0.230380183248 0.230258677982 0.230134652636 0.230009981721 0.229887840489 0.22977275441 0.229671560547 0.229592900273 0.229546293171 0.229541479595 0.229556968868 0.229563480808 0.229562894136 0.229559374701 0.229549903396 0.229532242627 0.229506109336 0.229468822102 0.229415399197 0.229340000748 0.229238181944 0.229101604818 0.228864013688 0.228422677934 0.227693856007 0.226619471458 0.225173874708 0.223367813228 0.221252526471 0.218909221697 0.216441229753 0.214020743328 0.211802191361 0.209575973164 0.208132529571 0.206900976653 0.205849010351 0.204920219349 0.204019239146 0.203075982264 0.202036455702 0.200853268964 0.199480523906 0.197870024509 0.195967822621 0.193710548555 0.19102029477 0.187799000291 0.183905636657 0.179124905016 0.173188280946 0.165755046874 0.156360826846 0.144198018973 0.129969366376 0.112182407018 0.0848899622255 0.0480972093075 0.233294028158 0.233245576525 0.233155873402 0.233028537697 0.232882797419 0.232714569374 0.232543200939 0.232364976012 0.232191069095 0.232023988215 0.231872578375 0.23174048645 0.231633046451 0.231550751701 0.231496819005 0.231450722907 0.231366958805 0.231252344768 0.231115243814 0.230976124824 0.230840173575 0.230704042466 0.230565761282 0.230425276678 0.230283090309 0.230140383019 0.229999982988 0.229866320601 0.229746218041 0.229648682973 0.229583864147 0.229564379868 0.229579116467 0.229588126183 0.229586659162 0.229582056706 0.22957178119 0.229551572637 0.229521063175 0.229478689872 0.229419655145 0.229336666251 0.229225590853 0.229072051429 0.228790409745 0.228272530435 0.2274372271 0.226233706764 0.224647747281 0.222704890362 0.220472863792 0.218040078482 0.215533144228 0.213179682553 0.211033999531 0.208989406908 0.207651177647 0.206537743186 0.205577165225 0.204686314208 0.203785547482 0.202815553682 0.201728660132 0.200481645797 0.199031157604 0.197330177391 0.195324672156 0.192949811767 0.190124977019 0.186746765861 0.182678586502 0.177757108338 0.171736210116 0.164289634791 0.154963163369 0.143121013957 0.129257893476 0.111844095539 0.0853735144494 0.0487899893799 0.233381296046 0.23333924586 0.233255115441 0.2331394668 0.233008468146 0.232858853077 0.232708713524 0.232554079868 0.232405336193 0.232262712904 0.232134322454 0.232022644849 0.231931445306 0.23186113724 0.231815990018 0.231768982515 0.231676392286 0.231544853938 0.231387096058 0.231226876902 0.231070407582 0.230914748228 0.230757973418 0.230599911567 0.230440641568 0.230280966367 0.230123012928 0.229971254099 0.229832683797 0.229716646952 0.229634242425 0.229598437848 0.229608392564 0.229620355544 0.229618326866 0.229612180714 0.229601403872 0.229579434 0.229544709448 0.22949687944 0.229432119096 0.229341879358 0.229222743953 0.229050474197 0.228720440487 0.228123246675 0.22718234951 0.22585616286 0.22414281049 0.222083610968 0.219759672033 0.217266028062 0.214772579433 0.21248555975 0.210239825874 0.208666772455 0.207421785833 0.206376444512 0.205466633305 0.204590211323 0.203675356286 0.202670445007 0.201532732441 0.200222223257 0.198697564699 0.196912722163 0.194813752618 0.192335092871 0.189394786479 0.18588808235 0.181678624106 0.176588643384 0.170374865669 0.162725548068 0.153131553926 0.141526843244 0.127719978883 0.109550992051 0.0825226627551 0.0465216837609 0.233509372117 0.233471699218 0.233387998785 0.233278392703 0.233155768808 0.233018742634 0.232884037898 0.232747671734 0.232618789614 0.232496668562 0.232387149474 0.232292741199 0.232215896374 0.232156092818 0.232120088918 0.232073753587 0.231974991074 0.231829226571 0.231654380354 0.23147653401 0.231302521571 0.231129767769 0.230956442362 0.230782285024 0.230607103866 0.230431364855 0.230256796859 0.230087492024 0.229930756497 0.229796536302 0.229696529544 0.229644396106 0.229647360587 0.229662148522 0.229659684985 0.229651111503 0.22963960504 0.229616739435 0.229578463367 0.22952513021 0.229454436502 0.229357073103 0.229230840469 0.22903710006 0.228654638895 0.227976453646 0.226932544667 0.225492031797 0.223666192014 0.221511797546 0.219116097614 0.216588604685 0.214170821818 0.212000364449 0.209788186479 0.208439773847 0.207328068706 0.206365768524 0.20548897527 0.204612495005 0.203675274051 0.202632028563 0.201444106863 0.200074202821 0.198482687701 0.196624530191 0.194446212401 0.191882140049 0.188850064963 0.185245011567 0.180930935539 0.175729610592 0.169404769595 0.161615410539 0.151766489182 0.14016419071 0.126080457137 0.106522700019 0.0781109647727 0.0427634842587 0.23367620743 0.233640262422 0.233552344889 0.233442211064 0.233321155092 0.233190415377 0.233065190533 0.232941737109 0.232827257439 0.232721301262 0.232627046069 0.232546397881 0.232481755224 0.232431400497 0.232404364439 0.232360618204 0.232259272945 0.232102815505 0.231914884583 0.23172319197 0.23153501461 0.23134812994 0.231160612374 0.230972109968 0.230782406295 0.230591615148 0.230401231868 0.230215198495 0.230040671831 0.229888208254 0.229770314177 0.22970072393 0.229694968687 0.229713104077 0.229711384254 0.22969984886 0.229686991588 0.229663957576 0.229623204968 0.22956481832 0.229488096869 0.229383707254 0.229250987093 0.229032177509 0.228593811619 0.227834136861 0.226691400879 0.225146532883 0.22322509528 0.220997607871 0.218550628658 0.216019607731 0.21367612261 0.211508457236 0.209687748225 0.208428465056 0.207386960707 0.206483622755 0.205625204852 0.204739667722 0.203776140654 0.20269487384 0.201460680616 0.200038606438 0.19839066929 0.196473016954 0.194232999104 0.19160570583 0.18850955957 0.18484037412 0.180462694473 0.175199372084 0.168814974824 0.160920985727 0.151285752291 0.139475497002 0.124579634436 0.10394424021 0.0747894257077 0.0402611692462 0.233880400701 0.233843941498 0.23374774126 0.233630771937 0.233502881231 0.233371053619 0.233248976171 0.23313299061 0.233028008857 0.232933120286 0.232850526477 0.232780421555 0.232725147216 0.232682800269 0.232664139725 0.232623422975 0.232524435113 0.232363255702 0.232166690149 0.231964832537 0.231766101859 0.231568465553 0.231369711894 0.231169108979 0.230966535523 0.230761927233 0.230556551095 0.230354401134 0.230162730625 0.229992138455 0.229855891156 0.229767645934 0.229750034656 0.229771564701 0.229773074543 0.229759073966 0.229744108621 0.229721246414 0.229679224547 0.229616732845 0.229534177965 0.229423085571 0.229284041642 0.22903601358 0.228539026336 0.227698582123 0.226462634502 0.224824679139 0.222825309459 0.220544480693 0.218071380083 0.215597501082 0.213343132635 0.211072875485 0.209642729965 0.208528361625 0.207569368814 0.206708859097 0.205859490703 0.204961094795 0.203971227215 0.202855290719 0.201581371684 0.200116784715 0.198425287267 0.196464506328 0.194183176343 0.191517805574 0.188388409165 0.184692415357 0.180295492027 0.175021825361 0.168592044731 0.160512840995 0.151042357651 0.139373949043 0.123469580915 0.101802681339 0.0720296904533 0.0378218984338 0.234122391789 0.234083311559 0.233974282917 0.233844949804 0.233702699699 0.233561082365 0.233433745126 0.233319589499 0.233219324433 0.233130346234 0.233055025635 0.23299230123 0.232943580788 0.232906935816 0.232895127115 0.232856720896 0.232764921587 0.232606622007 0.232407541352 0.232199458938 0.231993973311 0.231789563956 0.231583008323 0.231373032471 0.231159551563 0.230942481793 0.2307231977 0.23050555577 0.230297086448 0.230108767433 0.229953964672 0.229846652542 0.229812878687 0.229836052851 0.229843971154 0.229829249931 0.229811525368 0.229788621784 0.229746354714 0.229681087171 0.229593274529 0.229476297257 0.229330580166 0.229049074167 0.22849164443 0.227572347705 0.226250078482 0.224531758114 0.22247237636 0.22015257856 0.217674298476 0.215307750849 0.213178073014 0.211011050773 0.209753264104 0.208745811408 0.207862096329 0.207030819803 0.206182636098 0.205269369235 0.204255276263 0.203110076478 0.201804842774 0.200309147364 0.198588685942 0.196602971951 0.194302736952 0.19162670774 0.188497343882 0.184814111195 0.180445668499 0.175219146834 0.168816987673 0.161089978823 0.1513756036 0.139308311062 0.122707855554 0.100359941178 0.0701322181749 0.0357128896021 0.234403937916 0.234360480935 0.23423360216 0.234085592948 0.233922754115 0.233763724735 0.233622895944 0.233501806313 0.23340028452 0.233312734982 0.233240047653 0.233180605362 0.23313513356 0.233101865748 0.23309387121 0.233056815641 0.232975740192 0.232828441985 0.232634411132 0.232425554026 0.23221779343 0.232010637449 0.23179978643 0.231583597737 0.231361555381 0.231133608309 0.230901441126 0.230669296328 0.23044456206 0.230238819825 0.230065665788 0.229939747479 0.22988599689 0.229906333879 0.22992321894 0.229910395355 0.229889631551 0.229866061778 0.229824270904 0.229757803316 0.229665690762 0.229544295576 0.22939095848 0.229072089906 0.228453405579 0.227458287791 0.226057564836 0.224272974604 0.222172070114 0.219828164492 0.217368035804 0.215096239521 0.212985786321 0.211215204887 0.210041623565 0.209086126299 0.208249236334 0.207435533286 0.206584617786 0.205657150729 0.204622932595 0.203455442808 0.202128572353 0.200614254724 0.198880443222 0.19688908089 0.194593685133 0.191936294668 0.188843000883 0.185216161797 0.180925752243 0.175757803063 0.169304288174 0.161900468123 0.152622116301 0.140090858644 0.123012299399 0.100243241155 0.0696456708601 0.034287071801 0.234728975219 0.2346794673 0.234529876955 0.234356252582 0.234165276188 0.233981735197 0.233820799471 0.233684371917 0.233573385106 0.233481085887 0.233407030811 0.23334671119 0.2332999107 0.233266541794 0.233258028662 0.233221629381 0.233152600355 0.233024571492 0.232845288747 0.232642627153 0.232437449763 0.232231324692 0.232019778003 0.231800551603 0.231572580022 0.231335646801 0.231091785653 0.230845898183 0.230605848306 0.230383253531 0.230192106315 0.230048102692 0.229972837798 0.229983479912 0.230009790081 0.230001774791 0.229978483364 0.229953726924 0.229912960755 0.229846964958 0.229751752715 0.229628041302 0.229465432492 0.229106084952 0.228426457212 0.227359702308 0.225889213585 0.224052659139 0.221926210091 0.219578052018 0.217186157438 0.215004203847 0.212790971214 0.211442014584 0.210407012008 0.20951905251 0.208715724993 0.207912119665 0.207057032818 0.206117708033 0.205068593263 0.203886567017 0.202548264938 0.201028153479 0.199296842195 0.197319361891 0.195052983499 0.192444523484 0.189425861897 0.185907323456 0.181767420488 0.176770427854 0.170751832451 0.163300476976 0.154273788856 0.141816129704 0.124797086781 0.101965313342 0.0712205962542 0.0340910555835 0.235101952497 0.23504536238 0.234869046976 0.234663224654 0.234436136443 0.234219419642 0.234030509464 0.233872570534 0.23374499851 0.233641030336 0.23355932535 0.233493557723 0.233441399173 0.233403277073 0.233389470474 0.233351475948 0.233295578125 0.233190905393 0.233037101594 0.232850092088 0.232653051468 0.232451579495 0.232242622538 0.232023503819 0.231792533428 0.231548864058 0.231294774198 0.231036149834 0.23078145841 0.23054277927 0.230334274955 0.230171783463 0.230074870134 0.230069186907 0.230102831085 0.23010246011 0.230078312456 0.230052449522 0.230013215609 0.229949234493 0.229852104551 0.229728560636 0.229554200917 0.229152207941 0.228413085672 0.227280202015 0.225750109671 0.223875862558 0.221733546454 0.219397659457 0.217129188785 0.215080476433 0.212909178204 0.21176938048 0.210845886314 0.210026609446 0.209249505883 0.208451371085 0.207591938142 0.20664393657 0.205585636342 0.204396974004 0.203057307248 0.20154385422 0.199830336135 0.197885615169 0.195671785468 0.193142014343 0.190236004689 0.18687439478 0.182932403766 0.178189164909 0.172786766113 0.165954616948 0.157256405109 0.145318714556 0.128886265712 0.106268525708 0.0752739222395 0.0348602853349 0.235528736255 0.23546424077 0.235258164091 0.235014502919 0.234743942411 0.234485093088 0.234258951284 0.234071436525 0.23392134272 0.233800322129 0.233705059341 0.233628828916 0.233566668303 0.23351893872 0.233492928461 0.233450676947 0.233408073921 0.233328413168 0.233208428356 0.233046844105 0.232864356396 0.232671857698 0.232468432998 0.232251991753 0.23202075183 0.23177331071 0.231510826627 0.231240689733 0.230972481804 0.230718579597 0.230493461427 0.230312255133 0.2301938596 0.230166873659 0.230203826242 0.230213294912 0.230190643941 0.230164219723 0.230126840633 0.230065946646 0.229967777431 0.229846916476 0.229657447737 0.229211485041 0.228415122384 0.227222671195 0.225645243241 0.22374914055 0.221598202583 0.219283979195 0.21713551488 0.215169945438 0.213332137868 0.212249952527 0.21137300339 0.210597565835 0.209838627228 0.209043742023 0.208181014518 0.207227919781 0.20616605784 0.204978191732 0.203646422595 0.202150969313 0.200469150874 0.198574472902 0.196435050912 0.194012511804 0.191257411482 0.188101515415 0.184421663966 0.180175510127 0.175297993704 0.169514692447 0.161800321138 0.151280953404 0.136596879639 0.115409855703 0.0840266282434 0.0359692957113 0.236014043027 0.235941743869 0.23570439701 0.235418782388 0.235098812048 0.234789814928 0.234517196382 0.234290805836 0.234110331586 0.233966457472 0.233853644071 0.233763411363 0.2336882135 0.233628148134 0.233582079697 0.233533144163 0.23349770749 0.233442741508 0.233360757981 0.233233352451 0.233072884627 0.232893549925 0.232698366083 0.232486550696 0.23225714702 0.232008708667 0.231740775972 0.231460426092 0.231179588225 0.230911639144 0.230671247578 0.230472227652 0.230333296401 0.230283333844 0.230318091436 0.230338048967 0.230318727036 0.230292055766 0.230256351759 0.230198878751 0.230100088954 0.229984073677 0.229775424522 0.229284817512 0.228433718578 0.227188243312 0.225576437975 0.223675146083 0.221529463269 0.219262037008 0.217193014256 0.21516344867 0.213778126474 0.212791483728 0.211963055442 0.21121796241 0.210471818596 0.209679573255 0.208815302935 0.20786061761 0.206800192377 0.205619495977 0.204303422519 0.202835435447 0.201196926783 0.199366845785 0.197320502434 0.195030344483 0.192459953473 0.189556569799 0.186273824093 0.182730323488 0.178634844222 0.174036784001 0.168008108681 0.16001167314 0.149071853946 0.133368094091 0.107673180692 0.053603046279 0.236562493293 0.236482821442 0.236214194444 0.235884442219 0.235511218738 0.235145970895 0.234818923994 0.234544622678 0.234325060587 0.23415117738 0.23401558153 0.233908251004 0.233819540388 0.233747433323 0.233676744935 0.233617135581 0.233580747593 0.233547527298 0.233504063187 0.233415524422 0.233282690252 0.233120060239 0.232935051289 0.232729343289 0.232503312505 0.232255680737 0.231985446377 0.231697081198 0.231404432376 0.231123021892 0.230867990681 0.230652789999 0.230494994169 0.230423409038 0.230451699654 0.230481412373 0.23046623809 0.23043907299 0.230404304531 0.230349797165 0.230250434833 0.230140807498 0.229908623115 0.229373323243 0.22847006431 0.227177264717 0.225541764775 0.223646583506 0.221524880821 0.219359144938 0.217379449043 0.215249201474 0.214215341223 0.213358774934 0.212595803431 0.211876773563 0.211139752426 0.210349568358 0.209485217149 0.208531747288 0.207476595848 0.206307816341 0.20501311589 0.203579393302 0.20199251342 0.200237621873 0.198298334688 0.196159603816 0.193794883149 0.191182009985 0.188423434658 0.185621703495 0.182686871535 0.179415824155 0.175403277225 0.17044591202 0.164217705992 0.156575495448 0.146751519826 0.138632704388 0.237175482574 0.237089941914 0.236791954314 0.236418257386 0.235990622978 0.23556579142 0.235178813101 0.234849276923 0.234582632089 0.234371450891 0.234207281627 0.234078987667 0.233975923409 0.233890263242 0.233796227308 0.233725186473 0.233684554136 0.233666756966 0.233655603029 0.233604645245 0.233501393676 0.23335720575 0.233182955559 0.2329839444 0.232762028336 0.232516036104 0.232245455225 0.23195201772 0.231648499091 0.231354140209 0.231084907069 0.230853980686 0.230678564916 0.230586940749 0.23060702825 0.230645812655 0.230635417744 0.230607417043 0.230572672848 0.230520143696 0.230420126037 0.230317550455 0.230057779575 0.229478554289 0.228526343036 0.227192019904 0.225540691326 0.223652525646 0.221563906061 0.219544551289 0.2176973736 0.215683472743 0.214757991295 0.213975492861 0.21326314184 0.212563793053 0.211832822593 0.211043911572 0.210180226728 0.209229640081 0.20818199288 0.20702775215 0.205757384976 0.204361286648 0.202830016322 0.201155565845 0.199330904641 0.19735421723 0.195209883634 0.192977257904 0.190837847337 0.188800049785 0.187041539086 0.185198604097 0.183194351326 0.181021224975 0.17863305666 0.176304713875 0.173753513186 0.174282181399 0.237852530072 0.237762882016 0.237439039967 0.237024063272 0.236543909145 0.236059586872 0.235610637862 0.235221615454 0.23490218659 0.234647882663 0.234450285216 0.234298061754 0.23418048445 0.234076785751 0.233965366332 0.233885101966 0.233838167327 0.233826158152 0.233836500771 0.233816041496 0.233739590979 0.233612688752 0.233448096542 0.23325500503 0.233036816701 0.232792487743 0.232521884998 0.232226232372 0.231913385681 0.231605760671 0.231322506292 0.231076054614 0.230883571478 0.230772669595 0.230783848708 0.230831355145 0.230826682197 0.230797917853 0.230762604909 0.230710851561 0.230610301092 0.230514307648 0.230223599489 0.229601982517 0.228605246662 0.227237501786 0.225579198608 0.223694423746 0.221634927514 0.219741137239 0.217968402509 0.216331350384 0.215404526907 0.214642092256 0.213955666727 0.21326822463 0.21254065283 0.211751989646 0.210888752251 0.209941212094 0.208901289355 0.2077616502 0.206515366237 0.20515621477 0.203679375299 0.202083948908 0.200371732016 0.19855325151 0.196647668853 0.194864112806 0.19336741577 0.192227132276 0.191491990278 0.190988977516 0.190745725252 0.190809872207 0.191187066968 0.192104492885 0.193113014114 0.196208805732 0.238588230656 0.23849709336 0.238152565345 0.237701413134 0.237173744099 0.236633760514 0.236124932541 0.235676343763 0.235302190258 0.235002037809 0.234768760655 0.234592949592 0.234460393068 0.234333060296 0.234208415663 0.234120733737 0.234066038653 0.234050579045 0.234068814064 0.234066788204 0.234009489381 0.233895313471 0.233737167613 0.233547636307 0.233331501651 0.233087783742 0.232816387351 0.232519497152 0.232200502803 0.231879355223 0.231581114383 0.231319307085 0.23110969575 0.230979845224 0.230981248481 0.231036922342 0.2310391573 0.231010315146 0.230974508431 0.230922424465 0.230821886087 0.230730553751 0.230406329648 0.229743992365 0.228707871376 0.227317760051 0.225666027229 0.223790840387 0.221768900471 0.219939394527 0.218095554074 0.216920594822 0.216059105382 0.215329311878 0.214660445467 0.213979625838 0.213252754435 0.212462544468 0.211598174911 0.21065195044 0.209617546068 0.208489563687 0.207263440272 0.205936105465 0.204507208449 0.202982722782 0.201368757678 0.19968907845 0.198059900213 0.19677634494 0.195871337082 0.195578987262 0.195744159238 0.196389843508 0.197561925153 0.199278247059 0.201493442543 0.204257468385 0.20692201722 0.210646813944 0.23937421491 0.239284064425 0.238924934424 0.238444653296 0.237877228828 0.237288955743 0.236726556634 0.236222973722 0.235796855589 0.235452444053 0.23518547182 0.234990946449 0.234837634144 0.234684098594 0.234547601513 0.234452399283 0.234388068657 0.234360587016 0.234371829706 0.234372680225 0.23432275778 0.234213510858 0.234056445422 0.233866540577 0.233649591885 0.233404496583 0.233130947219 0.232831537583 0.232508852438 0.232175804843 0.231861602284 0.231583889778 0.231357303811 0.231208544901 0.23119856466 0.23126108684 0.231271387566 0.231243714024 0.231208233868 0.23115494474 0.231055609507 0.230965362736 0.230605632999 0.229903457367 0.22883218134 0.227430960952 0.22580090474 0.223956498528 0.222017579195 0.220237257093 0.2182578185 0.217446899144 0.216700779602 0.21602113765 0.215367252119 0.214688412707 0.213958563539 0.213163648702 0.212294806614 0.211345890828 0.210311901061 0.209189030018 0.20797472758 0.206668835213 0.205275611865 0.203807656526 0.202272234566 0.200738125616 0.199364305559 0.19847290085 0.19824179795 0.198593861219 0.199515583077 0.201076919152 0.20330080008 0.20615354347 0.209517400936 0.21327697523 0.216695149283 0.220492581312 0.240196923572 0.240110523157 0.239743517067 0.239242492491 0.23864513949 0.238018806564 0.237412755076 0.236863002522 0.236392292581 0.236009630416 0.2357159232 0.235508483915 0.235326733529 0.235147907498 0.23499853509 0.23489296083 0.234815278068 0.234767569568 0.234757489908 0.234744668659 0.234688085978 0.234573693688 0.234410703281 0.234215258664 0.233993719252 0.233744577619 0.233466957891 0.233163328239 0.232837045126 0.232494339793 0.232164330375 0.231870263514 0.231626771689 0.231459299819 0.231435686124 0.231502767139 0.231521901177 0.231496889744 0.231463172868 0.231408121094 0.231311916545 0.231217613653 0.230820997614 0.230078762351 0.228974491086 0.227569322578 0.225967567747 0.224174187354 0.222377590529 0.220697131166 0.218742309859 0.218031139515 0.217353972418 0.216711674186 0.216066311348 0.215384338319 0.214646875916 0.213842599708 0.212963942576 0.212005723023 0.210963656996 0.209834996697 0.208618559923 0.207316627013 0.205937831656 0.204498967591 0.203016511425 0.201682214636 0.20063220674 0.199986040306 0.200201627278 0.201047879093 0.202559431353 0.204791514891 0.207733209799 0.211303897711 0.215328180591 0.219575278248 0.223333759092 0.227061416113 0.241040329817 0.240959728274 0.240591268945 0.240078342343 0.239462036267 0.238809709014 0.238172392357 0.237588332789 0.237083775591 0.236671945546 0.236361320461 0.236142040032 0.235931331909 0.235729146496 0.23556389842 0.23544243021 0.235346026812 0.235270790942 0.235227451739 0.235186126872 0.235109161794 0.234979076375 0.234802479545 0.234595687885 0.234365261879 0.234109052966 0.233825243983 0.233515819573 0.233184680892 0.232834301298 0.232488732348 0.232178156479 0.231918052913 0.231732583597 0.231692976983 0.231761491573 0.231789566145 0.231768512605 0.23173825328 0.231681181992 0.23159096117 0.231486346556 0.231052403535 0.230269604991 0.229133287988 0.227725656429 0.226142927151 0.22439699807 0.222751856955 0.221173875059 0.219482679485 0.218697634974 0.218021150208 0.217391195871 0.21674608668 0.216055999911 0.215305726463 0.214485993997 0.213590035719 0.212613069397 0.211550714381 0.210400470998 0.209161246595 0.207836503061 0.206436900327 0.20498031778 0.2035295599 0.202349958738 0.201496128108 0.201229240887 0.201645980496 0.202784750077 0.204683768346 0.207345024197 0.21071665405 0.214677420129 0.21901348205 0.223429829797 0.227330214771 0.230956840263 0.241884860623 0.241811707321 0.241447506126 0.24093124325 0.240307233924 0.239641753668 0.238986721299 0.23838170798 0.237855651938 0.237424967588 0.237106626684 0.236874760473 0.236640708585 0.236416859561 0.236231539149 0.236087273597 0.235966240241 0.235858165967 0.235773137037 0.235692210848 0.235583769413 0.23542893602 0.235231660938 0.235007833975 0.234764169164 0.234497830702 0.234205728107 0.23388895412 0.233551401507 0.233194672687 0.232835068913 0.232507842886 0.232231400256 0.232028950407 0.231971444212 0.232037609329 0.232073862273 0.232057381804 0.232032140011 0.231973029042 0.23189253477 0.231770926211 0.23130060243 0.23047785211 0.229311767438 0.227900980223 0.226318376765 0.224595707068 0.22304139621 0.221472958239 0.220190835871 0.219360377554 0.218676669505 0.218046786335 0.217395401264 0.216692069272 0.215922866427 0.215079899221 0.21415678369 0.213148624784 0.212049997248 0.21085766187 0.20956857335 0.208185247305 0.206716694343 0.205188276887 0.20369206608 0.202510741714 0.201839927752 0.2017442836 0.202303209571 0.203622580793 0.205737938453 0.208621585056 0.212190572755 0.216292060521 0.220685819157 0.22504696484 0.228911832272 0.232209082839 0.242710541178 0.242645152775 0.242289276053 0.24177730716 0.241156458395 0.240490610187 0.239831474173 0.239218983918 0.2386838511 0.238244769081 0.237926711455 0.237683953235 0.237432954813 0.23718821833 0.236978385956 0.236805307646 0.236653748282 0.236508905207 0.236377805522 0.236251166926 0.236104434371 0.235918783251 0.235695552435 0.235449891601 0.235189046385 0.234909752357 0.23460747824 0.234281963314 0.233936468163 0.233573081737 0.233201839632 0.232858827104 0.23256703153 0.232349010922 0.232272787097 0.23233242414 0.232375118733 0.232362836166 0.232343585781 0.232282479352 0.232216200686 0.232071012157 0.231566537878 0.230706190495 0.229516004078 0.228105301507 0.226512292492 0.224801775863 0.223262801184 0.221579456403 0.220747565823 0.219973542243 0.219304026658 0.218670070411 0.218005690738 0.217282267548 0.216486116703 0.215609848493 0.214646838114 0.213591574812 0.212436696424 0.211177440426 0.209806324619 0.208323698276 0.206744141835 0.205134832436 0.203567421472 0.202195920229 0.201562531979 0.201501299457 0.202105414492 0.203482189575 0.205658352345 0.208591500881 0.212177892504 0.216241825545 0.220526390333 0.224699762175 0.228333648547 0.230838659279 0.243496659042 0.243437889755 0.24309235359 0.24259125619 0.241983840504 0.241329937011 0.240679684906 0.240072342264 0.239539394413 0.239101266383 0.238787134153 0.238537084839 0.238277749532 0.238013740052 0.237776315385 0.237570316553 0.237383203557 0.237199243912 0.237021897593 0.236848307736 0.23666071351 0.236441531845 0.236189442727 0.235918611158 0.23563739285 0.23534276392 0.23502885191 0.23469368202 0.234339442829 0.233968463188 0.233586918813 0.233229536894 0.232923596542 0.232691545237 0.232596949623 0.232646985374 0.232694173078 0.232684988277 0.232671960278 0.232608656098 0.232561240095 0.232386174996 0.231850161016 0.230955331263 0.229749649623 0.22834946598 0.226758044704 0.225091577654 0.223552089286 0.221730339877 0.221209299647 0.220541537508 0.219899112539 0.219256162601 0.218570024981 0.217817098331 0.21698340103 0.216060839472 0.215041456125 0.213918360968 0.212681368552 0.211324014171 0.209832267601 0.208213913259 0.206510449855 0.204707130401 0.202881943045 0.201470401082 0.200655867232 0.200477710922 0.201014587064 0.202332869003 0.204443228098 0.207294232734 0.210771093059 0.214685424247 0.218775716484 0.22270937494 0.226026810414 0.228428241377 0.244225616882 0.244167781161 0.24383205149 0.243347924958 0.242763978253 0.242133918105 0.241504678852 0.240913772587 0.240392361143 0.239961804873 0.239650976755 0.239400011528 0.239142056387 0.238862484011 0.238596893573 0.23835597867 0.238131032616 0.237908021072 0.237687154284 0.237468667619 0.237240912853 0.236988474635 0.236707223007 0.236409682722 0.236105954235 0.235794183995 0.235467613857 0.235122408488 0.234759310127 0.23438059836 0.233989252617 0.233618511385 0.233299534448 0.233054534471 0.232942083231 0.232981259773 0.233031923182 0.233024711526 0.233017296866 0.232951044615 0.232926610826 0.232715446682 0.232149484311 0.231221999177 0.230009289026 0.228633458694 0.227073238436 0.225515069687 0.224021630227 0.222195048867 0.221703804731 0.221090799293 0.220461288809 0.219799556937 0.219081027576 0.218287098861 0.21740283467 0.216417976544 0.215321413964 0.214103035283 0.212747713372 0.211246371758 0.209578590241 0.207786998218 0.205852978383 0.203663431812 0.201614389774 0.200005285287 0.198990989097 0.198649420819 0.199041757997 0.200211196222 0.202159508688 0.204833831309 0.208119507598 0.211827016181 0.215701913389 0.219395175594 0.222560521339 0.225206558399 0.244885840206 0.244811179647 0.244483716066 0.244023840443 0.243474036485 0.24287968561 0.242282822279 0.241718352809 0.241216240317 0.24079805033 0.240490109556 0.240247860005 0.239996690959 0.239707130341 0.239415591535 0.239140312573 0.238877838507 0.238618008135 0.238357791572 0.238098251771 0.237833271596 0.237550132024 0.237241905802 0.236918212977 0.236591092384 0.23626100561 0.235921146394 0.235565951431 0.235194436552 0.234808448554 0.23440836519 0.234024840678 0.233693518002 0.233436158459 0.233306119364 0.233334239268 0.233388718224 0.23338288399 0.233379854744 0.233309108486 0.233310574489 0.233057031998 0.232460764052 0.231499688811 0.230284561765 0.22894083148 0.227435509717 0.22603104292 0.224607447536 0.222924962099 0.222265204245 0.221628589833 0.220984716715 0.220291881233 0.219529821045 0.218682342691 0.217732821192 0.216667499519 0.215469781095 0.214122554501 0.212600798387 0.210887768871 0.208956524725 0.206870871025 0.204458375082 0.20196274899 0.199690345281 0.197866774603 0.196639071364 0.196090230943 0.196273805012 0.197222649823 0.198936280315 0.20136783504 0.204412709639 0.207895560727 0.211594959118 0.215097009986 0.218080494882 0.220129760292 0.24543703696 0.245331202694 0.245022298186 0.244599186819 0.244096071514 0.243549484321 0.242995599695 0.242466423733 0.241990345815 0.241588958664 0.241287183204 0.241055751495 0.240811466932 0.240523207053 0.240212585941 0.239906219663 0.239608829695 0.239314921862 0.239019337058 0.238724249306 0.238426851738 0.238117223544 0.23778615845 0.237438993232 0.237089063616 0.23674016162 0.236386662746 0.236021763897 0.235642597197 0.235250076506 0.234843032726 0.234447824001 0.234104021905 0.233834330797 0.23368664306 0.233703470458 0.23376296531 0.233758835108 0.2337587994 0.233681634336 0.233710630006 0.233408536618 0.232779834853 0.231781835818 0.230563379338 0.229245728428 0.227791659031 0.226526229303 0.2251316033 0.223685102082 0.222836604772 0.22213809187 0.221458481259 0.220723146004 0.219906650657 0.218992424342 0.217961553226 0.21679609736 0.215472324592 0.213962231547 0.212226095691 0.210236800759 0.207932590965 0.205290162072 0.202414114764 0.199684519338 0.197200887569 0.195156975695 0.1937016678 0.192915837368 0.192847690113 0.193526274319 0.1949555676 0.19710174013 0.199875891108 0.203124196891 0.20664527688 0.209910650692 0.212207071924 0.213798519709 0.245803430905 0.245687766366 0.245428669715 0.245062237459 0.244620116693 0.244132612673 0.243630911981 0.243144432549 0.242699898017 0.242318582729 0.242024614755 0.241797917861 0.241566487299 0.241292118285 0.24097227809 0.240640712117 0.240312542485 0.239987608752 0.239661890292 0.23933736025 0.239012822378 0.238681466534 0.238332861527 0.237966830534 0.237596269709 0.237228866177 0.236861575532 0.236487289828 0.236101302183 0.23570293074 0.235290309335 0.234885351219 0.234528950463 0.23424627931 0.234080115917 0.234083794103 0.234149500839 0.234148793534 0.234151387195 0.234066342878 0.234123735976 0.23376768464 0.233103837235 0.232065127877 0.230838342478 0.229527768822 0.228093424904 0.226894431677 0.22544097119 0.224321821617 0.223364547068 0.222600737855 0.221872573569 0.221084558576 0.220202478746 0.219207120192 0.218076379371 0.216787590377 0.215309774908 0.213605417054 0.211632486443 0.209354011156 0.206541133854 0.203185227821 0.200005673071 0.196996495186 0.194275295934 0.192011348836 0.190327520907 0.18929366279 0.188952014099 0.189331694929 0.190448076129 0.192289329682 0.194795984118 0.197844648121 0.201102004908 0.203974438983 0.205800057698 0.207118694065 0.245983853143 0.245899100076 0.245711539058 0.245417584186 0.245047331238 0.244626680418 0.244183594699 0.24374513599 0.243336265487 0.242977694805 0.24269207884 0.242466875239 0.242255563404 0.241999551267 0.24168281621 0.241335022152 0.240981640341 0.240629931652 0.240279409468 0.239930443696 0.239583867166 0.239235498735 0.238874985021 0.23849632281 0.23810914761 0.237724700069 0.237343780674 0.236960358424 0.236568421225 0.23616544006 0.235748651003 0.23533593969 0.234967094827 0.234670150744 0.234483778216 0.234469227713 0.234540954813 0.234546840443 0.234553460174 0.234460549507 0.234547185461 0.234133115494 0.233432194908 0.232350707264 0.231109958708 0.22978396708 0.228332206345 0.227115913781 0.225517401916 0.22476211396 0.223810151639 0.223002052625 0.222220375369 0.221370282824 0.220410586864 0.219318067956 0.218065507046 0.216622885733 0.214952018612 0.213014897507 0.210791213094 0.208062257719 0.204561490438 0.200847939941 0.197293863084 0.193992535145 0.191051234781 0.188590524336 0.186699838223 0.185431581205 0.184818815421 0.184892013698 0.185682986935 0.187214517737 0.189488010473 0.192360539435 0.195326421798 0.197533867427 0.199146466331 0.200381108177 0.246060044404 0.246033939201 0.245904562742 0.245684633394 0.245388265602 0.245036399063 0.244654564544 0.244266941872 0.24389641287 0.243562811319 0.243286504256 0.243065328051 0.242868999912 0.2426322774 0.242333732619 0.241982237468 0.241611224062 0.241237987552 0.24086689087 0.240498167435 0.240134598925 0.239773630653 0.23940620677 0.239021771462 0.238623956635 0.238225512309 0.237831770239 0.237439395288 0.237042172464 0.236635854059 0.236216502519 0.23579841334 0.235418388187 0.235106337159 0.234898028778 0.234857355207 0.234932227584 0.234948455149 0.234961965432 0.234862356343 0.234979246018 0.234504623272 0.233766327063 0.232642910626 0.231385404064 0.230029794309 0.228545137464 0.227276423382 0.225524657129 0.225040034336 0.224165876371 0.223336887566 0.222499770191 0.221577818193 0.220527125742 0.219320001563 0.217921266518 0.216288786505 0.214376528552 0.21214925428 0.209514567924 0.206047226093 0.202129555161 0.198133866758 0.194307202996 0.190790537094 0.187686004893 0.185080193992 0.183031811178 0.181571143699 0.18071818425 0.180502560733 0.180970378954 0.182190112696 0.184229873442 0.186837048965 0.189307950868 0.191256716005 0.192800083367 0.193946819648 0.246096480876 0.24611938555 0.246028063934 0.245880644219 0.245655164738 0.245370034484 0.245048761837 0.244712428181 0.244381531518 0.244074548676 0.243809082066 0.243592828141 0.243402392412 0.243191323223 0.242917749291 0.24257679704 0.242198352988 0.241809732447 0.241422163523 0.241038625285 0.240661983639 0.240291944967 0.239921387405 0.239537412873 0.239136515848 0.238729102181 0.238324545459 0.237923596896 0.237521450643 0.237112833982 0.2366924281 0.236270944254 0.235881750485 0.235555312276 0.235325739255 0.235252904921 0.235324797206 0.235353999669 0.235376788903 0.235271555154 0.23541915653 0.234882511807 0.234108259868 0.23294657861 0.231674105653 0.230289188907 0.228786819853 0.227491921555 0.225683212189 0.225262007513 0.224456132615 0.223610453963 0.222712600838 0.221707192956 0.220550309269 0.219209409558 0.21763838623 0.215783869871 0.213603173614 0.211006161127 0.207606909947 0.203561132184 0.199399167249 0.195204795223 0.191194327637 0.187543401878 0.184352037581 0.181679028818 0.179550574695 0.177969673711 0.176939578548 0.176484001946 0.176664909558 0.177633173482 0.17941759456 0.181621766012 0.183627384895 0.185554160705 0.187107001869 0.188149353256 0.246129158858 0.24616823465 0.246111990556 0.246023568797 0.245860849861 0.245637538675 0.245373455639 0.245086904757 0.244795740347 0.244516652595 0.244264951959 0.244053274662 0.243867110187 0.24367540852 0.243428556958 0.243113033094 0.242740607378 0.242344524848 0.241945289495 0.241550867955 0.241164183053 0.240787947452 0.240417147311 0.240038249574 0.239641681378 0.239232502405 0.238821118278 0.238412830434 0.238006005144 0.237595679247 0.237175647227 0.236752961558 0.23635686012 0.236017811974 0.235769608759 0.235664925943 0.235724957695 0.235767177151 0.235799892268 0.235688726725 0.235866208837 0.235266599544 0.234459114925 0.233264435658 0.231982511051 0.230580620322 0.229092615178 0.227810283907 0.226033912293 0.225500793079 0.224709589566 0.223832326929 0.22286269042 0.221759764749 0.220479407213 0.218982381988 0.217209925707 0.215114930863 0.212680073801 0.209496979225 0.205317174894 0.20096988144 0.196553583852 0.192190914411 0.188083026368 0.184395375379 0.181217999599 0.178582656343 0.176479574492 0.174879190237 0.173759511322 0.173120921114 0.173071661524 0.173905207383 0.175373116625 0.177068243328 0.1789771683 0.180910026022 0.182387259707 0.183213853348 0.246170553208 0.246200000676 0.24618400534 0.246128809637 0.24601772616 0.245849045138 0.245636887035 0.245397185702 0.245144855651 0.244894382671 0.244659105338 0.244451297442 0.244268954159 0.244087659638 0.243869988372 0.24358426678 0.243233667263 0.242841181379 0.242436322659 0.242034448593 0.24164144444 0.241260970912 0.240891605921 0.24052065156 0.240134056329 0.239731392989 0.239319643415 0.238907092649 0.238496447675 0.23808478434 0.23766581081 0.237243843901 0.23684330504 0.236493551274 0.236227924067 0.236094149614 0.236134422223 0.236188276942 0.23623127813 0.236113702062 0.236319170886 0.235655791578 0.234818382318 0.233595883807 0.232311265186 0.230909906814 0.22946801236 0.228218656602 0.226492737844 0.225772194092 0.224943417007 0.224011072568 0.222954053381 0.221737416468 0.220314256404 0.218634541443 0.216630427417 0.214279890516 0.211425167311 0.207434847571 0.202952582073 0.198311961416 0.193671289461 0.189203248866 0.185091356218 0.181478751143 0.17843611979 0.175964929667 0.174016480149 0.172525142143 0.171423470183 0.170669394028 0.170500937027 0.17111053021 0.172392866198 0.173956289684 0.175803443612 0.177586766461 0.178843788463 0.179261346703 0.246210877814 0.246221555436 0.246235638626 0.24619762512 0.246132396592 0.246012408783 0.245847085406 0.245650666554 0.24543555304 0.245213907211 0.244997206968 0.244795847515 0.244616153193 0.244441432102 0.244243842996 0.24399250569 0.243675042568 0.243298930884 0.242896361017 0.242491308128 0.242094952712 0.241711816409 0.241344494676 0.240982394233 0.240609341076 0.24021995108 0.239816305807 0.239405257761 0.238993409455 0.238581375525 0.238164235157 0.237744300156 0.237341096563 0.2369820053 0.236699056513 0.23653562173 0.236547314117 0.236611578868 0.236667919844 0.236545301017 0.236776833924 0.236048569796 0.23518420608 0.233937398783 0.232655521982 0.231270407986 0.22989442326 0.228679849231 0.227005519945 0.226076278183 0.225166092366 0.224152352372 0.222989808136 0.221642008294 0.220055295471 0.218167973806 0.215917543699 0.213243436078 0.209561214249 0.205112555712 0.200429621953 0.195599299772 0.190825975917 0.186337596172 0.182321944071 0.178901840349 0.176121155157 0.173946197614 0.172290247513 0.171054101578 0.170108388289 0.169429918767 0.169488310665 0.169962161757 0.170805629182 0.172348066716 0.174020960577 0.175509887682 0.176477517722 0.17651785807 0.246243724344 0.246243901088 0.246267783431 0.246249055745 0.246215788794 0.246136288647 0.246012315221 0.24585499921 0.245674851237 0.245481772634 0.245285380288 0.245094378158 0.244916128538 0.244746854977 0.244564200878 0.244342358618 0.244057925865 0.243713307212 0.243325283576 0.24292312717 0.242525913937 0.242142350377 0.241776975853 0.241423665666 0.241066256255 0.24069384093 0.24030536348 0.239903852811 0.239495946863 0.239085901001 0.238671829796 0.238255339834 0.23785126874 0.237484016425 0.237184008038 0.236990338333 0.236962970724 0.23703339905 0.237107633694 0.236983443129 0.237239099178 0.236443523203 0.235554007096 0.234283768221 0.233006920054 0.231646569344 0.230338226022 0.22914616927 0.227527570058 0.226397637108 0.22537630066 0.224257668194 0.222971673011 0.221474549787 0.219701621542 0.217595867944 0.215125275177 0.211904086343 0.207435616071 0.202776695942 0.197892333463 0.192912123043 0.188084923047 0.183666936818 0.179850566164 0.176734921314 0.174328679344 0.172556957831 0.171300668663 0.170438794035 0.169814187071 0.169491277869 0.169462778827 0.169953445881 0.170782833191 0.172007050441 0.173290749321 0.174392460443 0.175028209131 0.174987906299 0.246273821731 0.246273743738 0.246290984371 0.246293039692 0.246274526173 0.246227824689 0.246139858037 0.246017378228 0.245869550389 0.245704308959 0.245529399709 0.245352019422 0.245178321812 0.245011678948 0.244838322855 0.244637228603 0.244387114629 0.244078640296 0.243719833403 0.243330463811 0.242936788968 0.242554680711 0.242190482333 0.241845422627 0.241504590486 0.241151433625 0.240782081841 0.240397213293 0.240000502778 0.239597127001 0.239188604809 0.238776982718 0.238373928416 0.238000272469 0.23768488846 0.237464056595 0.237393486714 0.237458151056 0.237552174081 0.237429749918 0.237706583809 0.23683914305 0.235924952239 0.234629461376 0.233356185406 0.232019627339 0.230762892119 0.2295716011 0.228017504154 0.226713016391 0.225566437703 0.224325490488 0.222900328268 0.221235846605 0.219256631029 0.216929375563 0.214108478495 0.21004086318 0.205359699451 0.200481824003 0.195397816565 0.190308552474 0.185499514705 0.181243695834 0.177725232392 0.175007297639 0.173050927108 0.171732746212 0.170909290619 0.170436730187 0.170102913303 0.169876884401 0.17010600384 0.170584856194 0.171287079077 0.172202307475 0.173142251471 0.173913095402 0.174256375279 0.174338625207 0.246302443949 0.246303712409 0.246309048305 0.246325027164 0.246316250082 0.246293612478 0.246236082186 0.246144458492 0.24602605971 0.245887448625 0.24573466629 0.245573463006 0.245408698752 0.245244023639 0.245077865078 0.244892802718 0.244668972316 0.244397372487 0.244076337646 0.243712529363 0.24332960983 0.242951333219 0.242590097942 0.242251168615 0.241924621779 0.241592416567 0.24124484712 0.240880578963 0.240501414706 0.240110870658 0.239712184473 0.239308303235 0.238908438373 0.238530754424 0.238202405208 0.237958060956 0.237848201558 0.237892041819 0.238003464737 0.237885757922 0.238179730101 0.23723371616 0.236294372826 0.234969700082 0.233695472191 0.232373713162 0.231141553468 0.229926590849 0.228445420616 0.227001503241 0.225728527797 0.224354275903 0.222776338763 0.220926802911 0.218736155915 0.216185719516 0.212704120929 0.20803253484 0.203210774054 0.198197694872 0.192969286065 0.187827189747 0.183110135952 0.179104111275 0.175969400102 0.173712687824 0.172233723984 0.171357602054 0.170914987134 0.170664527562 0.170431155033 0.170391944484 0.17068245965 0.171157917266 0.17177675039 0.172513061649 0.173239346544 0.173809379193 0.174010165505 0.174202845768 0.246328521994 0.246329609855 0.246331217156 0.246349080473 0.246351579169 0.246339943293 0.246306648906 0.246242058776 0.246150134814 0.246036542945 0.245906007786 0.245762902679 0.245611052647 0.245453312461 0.24529140473 0.245118579187 0.244917900504 0.24467572053 0.244391046208 0.244065343261 0.243705296962 0.243336288383 0.242979480039 0.242643970152 0.242329198446 0.242018292977 0.241694865598 0.241353996775 0.240996185219 0.240623828948 0.24023966016 0.239847055184 0.239453553741 0.239074725611 0.238736035792 0.238470360612 0.23832382909 0.238332874597 0.238458258066 0.238350803327 0.238659127212 0.237626201022 0.236660337903 0.235301024713 0.234019665771 0.232699754964 0.23146474314 0.230208920914 0.228802884359 0.227252768137 0.225859381775 0.224345096561 0.222601792811 0.220557612481 0.218170475746 0.215227344799 0.210911718872 0.206127645432 0.201132068338 0.195986355058 0.190638776806 0.185497450709 0.180947569301 0.177271338831 0.174586332332 0.172818685436 0.171794800332 0.171299920883 0.171104736651 0.170940899435 0.170763993351 0.170828656252 0.17118006198 0.171644109976 0.172206198155 0.172832059291 0.173425879343 0.173887877318 0.174060616173 0.174289967961 0.246352506355 0.246353888623 0.246356725735 0.246365538617 0.246376855558 0.246371950277 0.246356266062 0.246315088801 0.246246958383 0.246156442797 0.246047671569 0.245923860443 0.24578786201 0.245641768219 0.245486765987 0.24532244224 0.24513927109 0.244924004527 0.244670384664 0.244381799518 0.24405905055 0.243710510152 0.24336144809 0.243030299456 0.242724039326 0.242431556595 0.242133447413 0.241818903279 0.241485862913 0.241135606415 0.240770424188 0.240393118661 0.240009304721 0.239632426595 0.239286095221 0.239001082952 0.238819161765 0.238781526584 0.238913092242 0.238823375769 0.239146142785 0.238016649187 0.237021919185 0.235621517106 0.234326597804 0.232995236818 0.231737348065 0.230435826538 0.229100056035 0.227467156136 0.225961245913 0.224302656905 0.222383105806 0.220143643729 0.217524154277 0.213885138686 0.209097875079 0.204210833881 0.199105643864 0.193869235573 0.188424658749 0.183342237866 0.179037004781 0.175762935942 0.173569480159 0.172265710315 0.171629442603 0.171420882862 0.171347314502 0.171182236633 0.171062170266 0.171201845171 0.171593286449 0.172051503606 0.172573665453 0.173123958025 0.17362993861 0.174030691558 0.174225109455 0.174459803811 0.246374338698 0.246375751092 0.246378447595 0.246382453436 0.246395559178 0.246398189103 0.246389442439 0.246367699591 0.24632085559 0.2462513391 0.246163301636 0.246059233641 0.245941085561 0.245810276242 0.245667245999 0.245511600441 0.245341899225 0.245149192812 0.244924313846 0.244666961051 0.244382756514 0.244070274276 0.243739610322 0.243416015013 0.24311411198 0.242835547632 0.242562686034 0.242276950121 0.241971946748 0.241647405797 0.241304858852 0.24094653963 0.240576433349 0.240204842176 0.239853922545 0.23955279116 0.239340078509 0.23925369821 0.239370510291 0.23930201017 0.239641439416 0.238405120329 0.237378947186 0.235931025135 0.234617211649 0.233262666102 0.231970019989 0.230624462353 0.229352875459 0.227649895795 0.226037884632 0.224232354862 0.222141628362 0.219736792228 0.216686445868 0.212231939183 0.207385614493 0.202377788494 0.197170123195 0.191869000674 0.186342603778 0.181382001554 0.177400869409 0.174595521009 0.172904772233 0.171961110021 0.171644984072 0.171637339955 0.171526394152 0.171397369385 0.171332444505 0.171524627706 0.171928731754 0.172379036487 0.172870404456 0.173367954578 0.173816040051 0.174181434888 0.174412733867 0.174639193614 0.246394161605 0.24639553623 0.246398099837 0.246401931153 0.246408412929 0.246416599477 0.246411103169 0.246403657293 0.246375253934 0.24632478794 0.246256060655 0.246171470137 0.246072311874 0.245959391742 0.245832666473 0.245691121785 0.245533538428 0.245358920988 0.245160472648 0.244932342654 0.244679143865 0.244406130504 0.244109930093 0.243802268697 0.243507486567 0.243238101782 0.242985991747 0.242730232775 0.242456327233 0.242160879824 0.241844556706 0.241508747682 0.241156112635 0.240793738993 0.240441429152 0.240127922422 0.239889005874 0.239759369394 0.239835592367 0.239784429221 0.240142883153 0.238790411972 0.237731484741 0.236230817813 0.234894899649 0.23350866338 0.232178187062 0.230794426239 0.229580633883 0.227810147308 0.226092558552 0.224136629541 0.221889244755 0.219287735822 0.215544081398 0.210639795243 0.205703513672 0.200619171224 0.195336104884 0.189993245168 0.184399642621 0.179631557506 0.176054105344 0.173765826826 0.172538070211 0.171845908554 0.171866053949 0.1717947688 0.171707158198 0.171601413127 0.171574837006 0.171790103693 0.172193757677 0.172635187994 0.173101470605 0.173561699521 0.173973065531 0.174320323655 0.174590293279 0.17481189374 0.246412190008 0.246413506812 0.246415754613 0.246418783963 0.246421777639 0.246428648851 0.246430416899 0.246428037918 0.246413727902 0.246379871869 0.246328651127 0.246262648091 0.246182813433 0.246089424317 0.245982042254 0.245859306058 0.245719278649 0.245560697245 0.245383597928 0.24518443313 0.24496004645 0.24471771823 0.244461402833 0.244187315753 0.243908385594 0.243645457701 0.243408900708 0.243181992758 0.242941366028 0.242678186101 0.24239117723 0.242081279042 0.241750503041 0.241402172544 0.241052211148 0.240729594415 0.240468611696 0.24030019964 0.240317957722 0.240272299773 0.240649358995 0.23917143376 0.238079283069 0.236521656801 0.235161589247 0.233739994778 0.232385432739 0.230983825439 0.229813493795 0.227961665583 0.226131502926 0.224028161043 0.221645155178 0.218639221425 0.214088254982 0.209145490825 0.204100720254 0.198948854061 0.193612555476 0.188249750798 0.182603452807 0.178111978912 0.175012026923 0.173208370306 0.172318807938 0.172150506306 0.172051259811 0.171969766583 0.171886159118 0.171796105632 0.171789661327 0.172005512462 0.172400919339 0.172834275914 0.173280490093 0.173714596565 0.174104200783 0.174444980265 0.174749071 0.174986856954 0.246428722243 0.246429960471 0.246431867321 0.246434242043 0.246436551813 0.246438944205 0.246446303581 0.246443916469 0.246439028603 0.246418933138 0.24638334901 0.246334600901 0.246273706354 0.246200581723 0.246114381611 0.246013459927 0.245895514445 0.245758281529 0.245600861047 0.245424334289 0.245229525205 0.245015737001 0.244790542496 0.244556765797 0.244310915597 0.244065656255 0.243839502323 0.24363341869 0.243427122443 0.243199704118 0.242945121499 0.242663412226 0.242357310305 0.242028604641 0.241686516364 0.24135899596 0.241080911273 0.240882048673 0.24084323566 0.240781410851 0.241170504967 0.239550118664 0.23842110511 0.236801227587 0.235412624478 0.233954906077 0.232601694252 0.231202688162 0.230073118719 0.228118515926 0.226164226021 0.223934189268 0.221330683397 0.217498206947 0.212608211481 0.207649991684 0.202554258052 0.19736545187 0.191998526802 0.186638484641 0.180958229496 0.17685423141 0.174301140029 0.172896950861 0.172348774425 0.172417589083 0.172240183636 0.172137529786 0.172054866766 0.171977615251 0.171979935959 0.172182909694 0.172564628357 0.172991166882 0.173422286198 0.173839284165 0.174217841824 0.174558786408 0.174884756354 0.175158141025 0.246444000688 0.246445084128 0.246446623867 0.246448258021 0.246449587983 0.246450313332 0.246453586749 0.246456139329 0.246454467433 0.246444571949 0.246422380072 0.246389162528 0.246346205262 0.246293248759 0.246229014134 0.246151482333 0.246058067051 0.24594602696 0.24581325888 0.245659387466 0.245486496359 0.245301264151 0.245105753527 0.24490431142 0.244698912097 0.244488040472 0.244280524969 0.244093318747 0.243917408932 0.243727585153 0.243507363713 0.24325495162 0.242973500046 0.242666531747 0.242337774808 0.242010774511 0.241721357839 0.241499729303 0.241417287555 0.241327273496 0.241718940175 0.239928370037 0.238753157166 0.237063135222 0.235636978307 0.234141902162 0.232797766039 0.231372361223 0.230341440001 0.228290358306 0.226208466177 0.223877616601 0.220870854679 0.216089405119 0.211203559121 0.20620662126 0.201073806029 0.195871698596 0.190494507681 0.185154122996 0.179465455479 0.175881792183 0.173874118152 0.172739452626 0.172716974209 0.172541834832 0.172394683606 0.172288188085 0.172210616874 0.172146197454 0.172150438591 0.172332494142 0.172696677382 0.173118451525 0.173539905398 0.17394768633 0.174322893361 0.174666370381 0.174997762931 0.175324229874 0.246458147196 0.246458985925 0.246460182009 0.246460982771 0.246461242856 0.246460560761 0.24645994651 0.246463779682 0.246462590337 0.246459001362 0.246447755322 0.246428325227 0.246401888305 0.246368297261 0.246325895759 0.246272170236 0.246204144829 0.246118758404 0.246013403043 0.245886641353 0.245738951966 0.245573802015 0.245404178276 0.245234213047 0.245061336775 0.244891989857 0.244723714374 0.244559000743 0.244409474778 0.2442585994 0.24407568929 0.243852894144 0.243594432763 0.243307562214 0.242995047506 0.242673950156 0.242379337699 0.242141679752 0.24202345859 0.241905866078 0.242291951966 0.240302039087 0.23906748049 0.237295986807 0.235816688423 0.234280771751 0.232934709561 0.231472420078 0.230621228087 0.228506863855 0.226290129949 0.223673865193 0.219686406894 0.214733155588 0.20983075527 0.204802938334 0.19965458892 0.194461942174 0.189094633732 0.183784677569 0.178132429141 0.175182323097 0.173576829859 0.173002852205 0.172953142596 0.17271373036 0.172544267606 0.172429629528 0.172356625077 0.172305052793 0.172308355646 0.172466890668 0.172808118788 0.173225981937 0.173643983952 0.174050008422 0.174427991834 0.174778293467 0.175124279885 0.175504666581 0.246471175834 0.246471727939 0.24647264276 0.246472561998 0.246471757474 0.246469839553 0.246467770461 0.246466746121 0.246467446899 0.246464767436 0.246461628515 0.246454151744 0.246442691908 0.246427226364 0.246405817591 0.246375373695 0.246332383214 0.246273402752 0.246195544745 0.246097030363 0.245977805629 0.245840060603 0.245691051311 0.245536753745 0.245391001987 0.245256792544 0.24513081148 0.24501112008 0.244896975167 0.244782472553 0.244640602491 0.244449014473 0.244211101829 0.243939887382 0.243642297498 0.243331207882 0.243038299724 0.242792284895 0.242646730604 0.242506752977 0.24287928898 0.240663635424 0.239354108747 0.237484766069 0.235923454969 0.234325031365 0.232943667947 0.231496964158 0.23089888214 0.228790922314 0.226345697025 0.22299480782 0.218105463605 0.21329138003 0.208449338525 0.203432693479 0.198295291074 0.193133526859 0.187789471137 0.182517579145 0.176984008535 0.174729507126 0.173355687601 0.173382926903 0.173068645059 0.172842420865 0.172670672058 0.172559710088 0.1724986434 0.172465147553 0.172470298348 0.172606642791 0.172910903092 0.173315948755 0.17374217174 0.17415557244 0.174546096596 0.174923227589 0.175316499959 0.17573850358 0.246483120147 0.246483370869 0.246484037481 0.246483166444 0.246481314719 0.246478409053 0.246474971016 0.2464715001 0.246469191935 0.246467238644 0.246467082342 0.246469027554 0.246470946385 0.246472117068 0.246470388527 0.246462009005 0.246442760791 0.246408689098 0.246356590413 0.246284470427 0.246192027429 0.246080985367 0.245956022182 0.245823068744 0.24569141608 0.24557032427 0.24547240519 0.24539773452 0.245332307025 0.24526809702 0.245176056543 0.245022468194 0.244805774805 0.244545476055 0.244258860219 0.243959802668 0.243676007835 0.243431457519 0.243269709384 0.24311415072 0.243466446184 0.241005841716 0.239606097232 0.237620017291 0.235933211305 0.234218813517 0.232715493271 0.231237601923 0.230738084623 0.228831750121 0.225888830737 0.221503554628 0.216632183863 0.211870215577 0.207087547149 0.202106487492 0.196997344388 0.191881118958 0.186559679351 0.18133738007 0.176002795548 0.174292016853 0.173334942242 0.173447576744 0.173127509568 0.172909162955 0.172756359506 0.172668150909 0.172633677297 0.172630248291 0.172653263935 0.172772329521 0.173037176993 0.173416212148 0.173843687202 0.174278517674 0.174704290284 0.175141470231 0.175607898516 0.17605894318 0.246493985071 0.246493993087 0.246494338598 0.246492899251 0.246490191952 0.246486725672 0.246482572954 0.24647804235 0.246473065379 0.246470156537 0.246469047245 0.24647662106 0.246489594972 0.24650559194 0.246521868969 0.246533866193 0.246536423811 0.246524900631 0.246495697045 0.246446570125 0.246377007563 0.246288532775 0.246185073304 0.246072321102 0.245957766932 0.245849721783 0.245757286306 0.245689582387 0.245653804357 0.245642661393 0.245620053759 0.245529014554 0.245347812593 0.245099250235 0.244818534089 0.24453145558 0.244263919316 0.244032948017 0.24386919708 0.243704372208 0.244032439361 0.241322186853 0.239822802285 0.237707799611 0.235854565988 0.233968897584 0.232235628515 0.230503910447 0.22942927787 0.227564404849 0.224115468252 0.219609453693 0.215060809972 0.210453548776 0.205773048466 0.200843330089 0.195767702141 0.190696271066 0.185371107539 0.180205446706 0.175104779311 0.173770813546 0.173487662064 0.173261131719 0.173043350516 0.172875029458 0.172773657691 0.172736137834 0.172754635172 0.172806977097 0.172873623503 0.172984480402 0.173214372218 0.173571363322 0.173998593099 0.174458864076 0.174943136391 0.175468483455 0.176025033466 0.176494791481 0.246503722522 0.246503658768 0.246503457519 0.246501707481 0.246498638445 0.246495039797 0.246490839122 0.246485970063 0.246480165533 0.24647415689 0.246474189537 0.246482184173 0.246502751836 0.246531104661 0.246563229777 0.246593411585 0.246615344126 0.246623481588 0.246613723078 0.246583518034 0.246532172103 0.246461124685 0.246374071808 0.2462765061 0.246175283399 0.246077932723 0.245992204409 0.245925428543 0.245883486054 0.245872352512 0.245900261003 0.245906089976 0.245797328981 0.245574881687 0.245298159458 0.245023006271 0.244779083765 0.244574664152 0.244424441676 0.244251631162 0.244555425722 0.241612979873 0.240012701654 0.237771384586 0.235732853666 0.233656801665 0.23164585602 0.229523249964 0.227621111252 0.225320049865 0.221793688507 0.217809419893 0.21355092545 0.209107877691 0.204544273596 0.1996684707 0.194623715544 0.189581416909 0.184196456142 0.179029325783 0.173907098524 0.172729195365 0.173248459277 0.173039601195 0.172871545204 0.172737069478 0.172692825476 0.17272259535 0.172822667888 0.172962213484 0.173104974327 0.173256938515 0.173484170686 0.173829032129 0.174261484933 0.174757492308 0.17531080309 0.175932266047 0.176582750368 0.1770630063 0.246512131576 0.246512202986 0.246511423425 0.24650956583 0.24650673527 0.246503538909 0.246499791563 0.246494873329 0.246488546575 0.246481809272 0.246480154856 0.246489855514 0.246515826148 0.246553359661 0.246598531701 0.246643805973 0.24668196006 0.246706399747 0.246712393694 0.246696922885 0.246659048082 0.246600244014 0.246524274413 0.246436629802 0.24634386027 0.246252961667 0.24617088804 0.246104108029 0.24605813725 0.246037552221 0.246045980713 0.246090798485 0.246090244325 0.245931358998 0.245666712006 0.245404441517 0.245197188665 0.245043158975 0.24494077672 0.244777364615 0.245064840139 0.241911128686 0.240199229883 0.237847365582 0.235630759351 0.233373463886 0.231054609487 0.228478556791 0.226017889586 0.223242620702 0.21983330544 0.216063029316 0.212008915611 0.207766158946 0.203395657892 0.198615534737 0.193611079194 0.188577873814 0.183075579218 0.177834942534 0.172378352963 0.171651008443 0.172514507793 0.172530316564 0.172523604785 0.1725025857 0.172540489757 0.172672327818 0.172894862971 0.173147528703 0.173384446472 0.173617762354 0.173889380621 0.174234717537 0.174671991207 0.175202931975 0.17582637216 0.176540243239 0.177277423163 0.17776018729 0.246518795674 0.246519052321 0.246518170596 0.246516605636 0.24651459111 0.246512390015 0.246509338204 0.246504563532 0.246498233365 0.246491637772 0.246489239773 0.246501804904 0.246530349082 0.246575647418 0.24663210403 0.246688876684 0.246739390142 0.246775968327 0.246793657614 0.246788733775 0.246759865895 0.246708625722 0.246639073391 0.246556926576 0.246468615768 0.246380708827 0.246299543348 0.246231009197 0.246180247493 0.246151409897 0.246148114093 0.2461754597 0.246217991557 0.246143129132 0.245906384704 0.245659281219 0.245512060589 0.24546626461 0.245492606726 0.24539796735 0.245697699777 0.242292580088 0.240411247244 0.237975854645 0.235620117184 0.233211577471 0.230533558004 0.227374046327 0.224416972552 0.221363800092 0.217937788691 0.214252197099 0.210357107559 0.206406449575 0.202394745521 0.197786603568 0.192820522647 0.187760152659 0.182121762799 0.176902168941 0.171385682464 0.17151745324 0.171812379181 0.172053011393 0.172256957308 0.172407879026 0.172561837249 0.17279610475 0.173081555107 0.1733816805 0.173674562318 0.173972190573 0.174303257551 0.174700918535 0.175190121391 0.175782484863 0.176481613655 0.177279375145 0.178085445281 0.178552242026 0.24652330202 0.246523576528 0.246523210721 0.24652263773 0.246522066602 0.246521280788 0.246519211183 0.246515233211 0.24651001422 0.24650524214 0.246504756857 0.246516686793 0.246547762583 0.246598966414 0.246662049708 0.246728551776 0.246789364571 0.246834323754 0.246859844676 0.246861152028 0.24683683551 0.246788878577 0.246721936028 0.246642060539 0.246555544063 0.24646845804 0.246386566792 0.24631519428 0.246259100922 0.246222762057 0.246208809775 0.246212642283 0.246208882505 0.246157552158 0.246022579898 0.245812909678 0.245721890409 0.245814753139 0.246006558255 0.246065903789 0.246483312444 0.242775202813 0.240637183431 0.238163021376 0.235750332109 0.233299689644 0.230437865116 0.227025120067 0.223822995427 0.22068731245 0.217250127778 0.213540612647 0.209634112754 0.205781129427 0.201900718389 0.197345437947 0.192324843473 0.187170316287 0.18149172843 0.176482640183 0.170516905292 0.171484645001 0.171595129842 0.171868224652 0.172137559961 0.172379927998 0.172621699237 0.17289005256 0.173185943074 0.173501900256 0.173838694082 0.174214219534 0.174662859633 0.17521138703 0.175820740883 0.176473933428 0.177214676063 0.178084856846 0.178938298729 0.179365294358 0.246525505809 0.246525609146 0.246525874178 0.246526589143 0.246527629758 0.246528277061 0.246527423667 0.246524817337 0.246521486175 0.246519375336 0.246522017559 0.24653562947 0.246567748523 0.246620912049 0.24668920158 0.246761210511 0.246826062977 0.246878316772 0.246910975452 0.246916277226 0.24689291968 0.246844140505 0.246776265686 0.2466961021 0.246609680404 0.246522390461 0.246439306516 0.246365020507 0.246303180194 0.246255819889 0.246221741763 0.246195404138 0.246165341616 0.246116242821 0.246042456559 0.245970937717 0.245963814531 0.246058422583 0.24625124803 0.246412798531 0.246797502314 0.243187130476 0.240811154111 0.238339432086 0.235946646208 0.233611262201 0.231137994277 0.229092628623 0.226364859535 0.223412665149 0.220015863899 0.21620145138 0.211960517087 0.207361770537 0.202236471201 0.197278453617 0.192068877765 0.186746295486 0.181196492029 0.176749466662 0.169324276369 0.170726675211 0.171201775004 0.171659289503 0.172017237702 0.172329875622 0.172630131929 0.172939042424 0.173263554219 0.173606017776 0.173972081887 0.174377104079 0.174848741909 0.175419145017 0.176103553262 0.17689285572 0.177795168177 0.178817052213 0.17974095564 0.180151737395 0.246525894609 0.246526025108 0.246526749383 0.246528157019 0.246529825924 0.246530869508 0.246530348271 0.246528322372 0.2465263363 0.246526808621 0.246533245337 0.246550885076 0.246585395307 0.246639598564 0.246709553355 0.246785110859 0.246854051003 0.246906199036 0.246939377509 0.246949665501 0.246927975129 0.246877289006 0.246806774714 0.246724638149 0.246636884108 0.246548468533 0.246464042593 0.246387767178 0.246322543575 0.246269391362 0.246227502802 0.246193045467 0.246158468284 0.246116573949 0.246068073894 0.246030259119 0.246034479109 0.246097929565 0.246192066925 0.24622032891 0.246546258042 0.243432175956 0.240890380313 0.238420036965 0.236048200086 0.233802390837 0.231734905199 0.230594980877 0.228349737538 0.225540937582 0.222175470783 0.218293554845 0.213817402503 0.208640846192 0.202666909232 0.197313040273 0.19196871287 0.186498694365 0.180715454206 0.174566520462 0.165102723066 0.169537992983 0.170781115543 0.171464948596 0.171918671196 0.172286782693 0.172622365376 0.172952916182 0.17329292096 0.173651155506 0.174037306373 0.174466473202 0.174959672536 0.175540224417 0.176232160282 0.177076811047 0.178144576496 0.179408125323 0.180482155093 0.180885012921 ) ; boundaryField { frontAndBack { type empty; } upperWall { type zeroGradient; } lowerWall { type zeroGradient; } inlet { type zeroGradient; } outlet { type fixedValue; value uniform 0; } } // ************************************************************************* //
[ "as998@snu.edu.in" ]
as998@snu.edu.in
73a7eb67e6bf2490552a798ea3c128d1a3c86ed4
b8482403496a1b2ff50310e2074bebdbea942a68
/training/2018/winterTraining/3-U.cpp
11aff0c45c40df7d283188edf1392d1f8f99d8ce
[]
no_license
TangliziGit/icpc-code
02cc8d70cb5da893ec18c79052f16d7976be98ee
cb0986e12af34d1624e534671f97bd540d412de9
refs/heads/master
2021-08-07T09:41:01.999446
2020-07-05T02:08:22
2020-07-05T02:08:22
197,133,978
2
0
null
null
null
null
UTF-8
C++
false
false
1,059
cpp
#include <cstdio> #include <queue> using namespace std; int nx, ny, dir[4][2]={1, 0, 0, 1, -1, 0, 0, -1}; char map[25][25]; struct Point{ int x, y; Point(int x=0, int y=0): x(x),y(y) {} }points[400+5]; int bfs(int x, int y){ queue<int> que; int size=1; points[0].x=x; points[0].y=y; que.push(0); map[y][x]='#'; while (que.size()){ int idx=que.front(); que.pop(); for (int i=0; i<4; i++){ int xx=points[idx].x+dir[i][0], yy=points[idx].y+dir[i][1]; if (xx<0 || xx>=nx || yy<0 || yy>=ny) continue; if (map[yy][xx]=='#') continue; map[yy][xx]='#'; points[size].x=xx; points[size].y=yy; que.push(size++); } }return size; } int main(void){ while (scanf("%d%d", &nx, &ny)==2 && nx){ for (int y=0; y<ny; y++) scanf("%s", map[y]); int ans; for (int y=0; y<ny; y++) for (int x=0; x<nx; x++) if (map[y][x]=='@') ans=bfs(x, y); printf("%d\n", ans); } return 0; }
[ "tanglizimail@foxmail.com" ]
tanglizimail@foxmail.com
27afcc0d8d527c6eecf1a5143451b4f2070f9089
3a7b4600778f147a24d49fe5264f96e46db57e10
/32_3.cpp
d422030a249a597c6a5f63596f3948d656a1c2ee
[]
no_license
CanRui-Wu/PointToOffer
9f5fea82f7d8796a95ecbbf1fb6b01e998ca46c0
88204fb67a4dc29373dcb94980857d6210dcf176
refs/heads/master
2021-04-26T23:54:09.474574
2018-03-24T12:21:52
2018-03-24T12:21:52
123,877,220
0
0
null
null
null
null
UTF-8
C++
false
false
1,571
cpp
#include <iostream> #include <vector> #include <queue> using namespace std; struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } }; class Solution { public: vector<vector<int> > Print(TreeNode* pRoot) { vector<vector<int> > result; if(pRoot == NULL) return result; queue<pair<TreeNode*,int> > myqueue; myqueue.push(make_pair(pRoot,0)); vector<int> temp; int current = 0; while(!myqueue.empty()) { pair<TreeNode*,int> mypair = myqueue.front(); myqueue.pop(); if(mypair.second != current) { if(current & 1 == 1) { for(int i = 0;i < temp.size()/2;i++) { swap(temp[i],temp[temp.size()-1-i]); } } result.push_back(temp); temp.clear(); current++; } temp.push_back(mypair.first->val); if(mypair.first->left != NULL) myqueue.push(make_pair(mypair.first->left,mypair.second+1)); if(mypair.first->right != NULL) myqueue.push(make_pair(mypair.first->right,mypair.second+1)); } if(current & 1 == 1) { for(int i = 0;i < temp.size()/2;i++) { swap(temp[i],temp[temp.size()-1-i]); } } result.push_back(temp); return result; } }; int main() { Solution solution; // vector<int> sequence = {4,8,6,12,16,14,10}; // cout << solution.VerifySquenceOfBST(sequence) << endl; }
[ "434858383@qq.com" ]
434858383@qq.com
814f1289e8c958c485b7ec1308550c397b77c0aa
6924d84805ef11ae874c50bf5cea64152e296750
/refBoxComm/src/explorationInfoListenerNode.cpp
13fee157820279c16cf1be451be8275d1027f77b
[]
no_license
ValentinVERGEZ/RBQT_communication
95ad18cea7f2328411e3728fd58b68fc895bf4c1
b3eabac8d33c0cd591ad64e1c569d11ff1f687cb
refs/heads/master
2020-05-19T21:31:54.834701
2014-12-14T15:53:38
2014-12-14T15:53:38
null
0
0
null
null
null
null
UTF-8
C++
false
false
629
cpp
#include "ros/ros.h" #include "std_msgs/String.h" #include "geometry_msgs/Pose2D.h" #include "refBoxComm/ExplorationInfo.h" void eiCallback(const refBoxComm::ExplorationInfo &ei) { for(int idx=0; idx < ei.signals.size(); idx++) { ROS_INFO("signal %d : %s", idx, ei.signals[idx].type.c_str()); } } int main(int argc, char **argv) { ros::init(argc, argv, "explorationInfoListener"); ros::NodeHandle n; ros::Subscriber sub = n.subscribe("/refBoxComm/ExplorationInfo", 1000, eiCallback); ros::Rate loop_rate(50); ros::spin(); return 0; }
[ "vincent.coelen@polytech-lille.net" ]
vincent.coelen@polytech-lille.net
4e71e77596d3329e2592052b42712c56c9e13ea5
983515294c903355d6574e9c73db6a84d9bd65c8
/test/modules/sequencizer/sequence-controller-idle-suite.cpp
5c364bff0466c0ee72e909caeb5f33eaeb4b1d79
[ "MIT" ]
permissive
dhemery/DHE-Modules
80c10f54219633d356ed922aa014bf94e3dcbd00
1d1c286fc69babdb36dfe5fa4fe2856b0f707854
refs/heads/main
2022-12-23T20:46:49.810184
2022-02-05T20:50:38
2022-02-05T20:50:38
117,472,503
36
5
null
null
null
null
UTF-8
C++
false
false
8,590
cpp
#include "components/latch.h" #include "fixtures/sequence-controller-fixture.h" #include <functional> namespace test { namespace sequencizer { using dhe::unit::Suite; using dhe::unit::Tester; using TestFunc = std::function<void(Tester &)>; static inline void when_idle(Signals &signals, StepSelector & /*step_selector*/, StepController & /*step_controller*/, SequenceController &sequence_controller) { signals.running_ = false; signals.reset_ = false; sequence_controller.execute(0.F); } class SequenceControllerIdleSuite : Suite { public: SequenceControllerIdleSuite() : Suite{"dhe::sequencizer::SequenceController: idle"} {} void run(Tester &t) override { t.run("with run high: with reset low: does nothing", test(when_idle, [](Tester &t, Signals &signals, StepSelector &step_selector, StepController &step_controller, SequenceController &sequence_controller) { signals.running_ = true; signals.reset_ = false; auto constexpr original_output = -99342.2F; signals.output_ = original_output; sequence_controller.execute(0.1F); if (step_selector.called_) { t.error("step selector was called"); } if (step_controller.called_) { t.error("step controller was called"); } if (signals.output_ != original_output) { t.errorf("signals output was changed (to {})", signals.output_); } })); t.run("with run high: with gate low: does nothing", test(when_idle, [](Tester &t, Signals &signals, StepSelector &step_selector, StepController &step_controller, SequenceController &sequence_controller) { signals.running_ = true; signals.gate_ = false; auto constexpr original_output = -992.223F; signals.output_ = original_output; sequence_controller.execute(0.1F); if (step_selector.called_) { t.error("step selector was called"); } if (step_controller.called_) { t.error("step controller was called"); } if (signals.output_ != original_output) { t.errorf("signals output was changed (to {})", signals.output_); } })); t.run("with run high: " "if gate rises: executes first step with gate edge cleared", test(when_idle, [](Tester &t, Signals &signals, StepSelector &step_selector, StepController &step_controller, SequenceController &sequence_controller) { signals.running_ = true; signals.gate_ = true; auto constexpr first_enabled_step = 3; step_selector.first_ = first_enabled_step; step_controller.status_ = StepStatus::Generating; auto constexpr sample_time = 0.39947F; sequence_controller.execute(sample_time); if (step_controller.entered_step_ != first_enabled_step) { t.errorf("Entered step {}, want step {}", step_controller.entered_step_, first_enabled_step); } if (step_controller.executed_latch_ != dhe::latch::high) { t.errorf("Executed latch was {}, want {}", step_controller.executed_latch_, dhe::latch::high); } if (step_controller.executed_sample_time_ != sample_time) { t.errorf("Executed sample time was {}, want {}", step_controller.executed_sample_time_, sample_time); } })); t.run("with run high: " "if gate rises: does nothing if no first step", test(when_idle, [](Tester &t, Signals &signals, StepSelector &step_selector, StepController &step_controller, SequenceController &sequence_controller) { signals.running_ = true; signals.gate_ = true; step_selector.first_ = -1; auto constexpr original_output = -2340.223F; signals.output_ = original_output; sequence_controller.execute(0.F); if (step_controller.called_) { t.error("step controller was called"); } if (signals.output_ != original_output) { t.errorf("signals output was changed (to {})", signals.output_); } })); t.run("with run low: with reset low: does nothing", test(when_idle, [](Tester &t, Signals &signals, StepSelector &step_selector, StepController &step_controller, SequenceController &sequence_controller) { signals.running_ = false; signals.reset_ = false; auto constexpr original_output = 349.319F; signals.output_ = original_output; sequence_controller.execute(0.1F); if (step_selector.called_) { t.error("step selector was called"); } if (step_controller.called_) { t.error("step controller was called"); } if (signals.output_ != original_output) { t.errorf("signals output was changed (to {})", signals.output_); } })); t.run("with run low: " "if reset rises: " "does nothing", test(when_idle, [](Tester &t, Signals &signals, StepSelector &step_selector, StepController &step_controller, SequenceController &sequence_controller) { signals.running_ = false; signals.reset_ = true; auto constexpr original_output = 349.319F; signals.output_ = original_output; sequence_controller.execute(0.1F); if (step_selector.called_) { t.error("step selector was called"); } if (step_controller.called_) { t.error("step controller was called"); } if (signals.output_ != original_output) { t.errorf("signals output was changed (to {})", signals.output_); } })); t.run("with run low: with gate low: does nothing", test(when_idle, [](Tester &t, Signals &signals, StepSelector &step_selector, StepController &step_controller, SequenceController &sequence_controller) { signals.running_ = false; signals.gate_ = false; auto constexpr original_output = 349.319F; signals.output_ = original_output; sequence_controller.execute(0.1F); if (step_selector.called_) { t.error("step selector was called"); } if (step_controller.called_) { t.error("step controller was called"); } if (signals.output_ != original_output) { t.errorf("signals output was changed (to {})", signals.output_); } })); t.run("with run low: if gate rises: does nothing", test(when_idle, [](Tester &t, Signals &signals, StepSelector &step_selector, StepController &step_controller, SequenceController &sequence_controller) { signals.gate_ = true; auto constexpr original_output = 349.319F; signals.output_ = original_output; sequence_controller.execute(0.1F); if (step_selector.called_) { t.error("step selector was called"); } if (step_controller.called_) { t.error("step controller was called"); } if (signals.output_ != original_output) { t.errorf("signals output was changed (to {})", signals.output_); } })); } }; static auto _ = SequenceControllerIdleSuite{}; } // namespace sequencizer } // namespace test
[ "dale@dhemery.com" ]
dale@dhemery.com
5b336b02c651da3ae7f044af55b5dd6371291715
33aa51db560b5b1f0af1e442f2cf11bee538e9fc
/VipClient/UpdateIpDlg.h
1cc82121260d176145309d4989b7e37d937a656c
[]
no_license
hanggithub/vipshell
529f7652d5ec8480dd679f0e79cfc7ef589020c6
a34593d7a6865fa06d098137c04e4cbab0050065
refs/heads/master
2021-01-22T21:32:50.236517
2014-11-16T08:27:06
2014-11-16T08:27:06
26,708,064
4
3
null
null
null
null
GB18030
C++
false
false
618
h
#pragma once // CUpdateIpDlg ๅฏน่ฏๆก† class CUpdateIpDlg : public CDialog { DECLARE_DYNAMIC(CUpdateIpDlg) public: CUpdateIpDlg(CWnd* pParent = NULL); // ๆ ‡ๅ‡†ๆž„้€ ๅ‡ฝๆ•ฐ virtual ~CUpdateIpDlg(); // ๅฏน่ฏๆก†ๆ•ฐๆฎ enum { IDD = IDD_DIALOG_UPDATEIP }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV ๆ”ฏๆŒ DECLARE_MESSAGE_MAP() public: afx_msg void OnBnClickedOk(); CString m_strFtpServer; DWORD m_dwPortFtp; DWORD m_dwPortMy; CString m_strMyIp; CString m_strFile; CString m_strUser; CString m_strPass; virtual BOOL OnInitDialog(); };
[ "ignccvv@163.com" ]
ignccvv@163.com
576ef45d4369a754d9c22d53b8274301c48f4156
1cf3c0bda1eeec186c21363ee514957d4215c9cb
/backgrounds/Sorting/Comparison_functions.cpp
228f6240802fd456bd6e967f7e4909a62589c51e
[]
no_license
jaguarcode/algorithms
5aeb6d6a46e6658a9fbc04186313f46d4135ac86
222b65dcfb245292ad10663039a8406871cb2a43
refs/heads/master
2023-05-04T08:09:24.246394
2021-05-27T23:32:40
2021-05-27T23:32:40
307,350,248
0
0
null
null
null
null
UTF-8
C++
false
false
421
cpp
/** * author: jaguarcode * date: **/ #include <bits/stdc++.h> using namespace std; template<typename T> auto print(T& t) { for(auto value : t) cout << value << " "; cout << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); vector<int> v { 2,3,4,5,6,2,1,8,2,3,6,9 }; sort(v.begin(), v.end(), [](int a, int b) { return (a < b); // incr //return (a > b); // decr }); print(v); return 0; }
[ "behonz@gmail.com" ]
behonz@gmail.com
c37031c4d39298c4280ec1fa2d29a2c105dfd582
93db044eb00abbd18b75eeb0617dd1e054f2b199
/Engine/Source/ThirdParty/PhysX/PhysX-3.3/include/PxQueryReport.h
9aed019b55ecb2458ae8b1817b541217151a5809
[]
no_license
cadviz/AHRUnrealEngine
9c003bf9988d58ece42be4af030ec6ec092cd12e
e0c1a65098f4a86b4d0538535b5a85dd1544fd30
refs/heads/release
2021-01-01T15:59:31.497876
2015-04-13T22:03:55
2015-04-13T22:03:55
34,035,641
9
19
null
2015-04-16T05:12:05
2015-04-16T05:12:05
null
UTF-8
C++
false
false
16,776
h
// This code contains NVIDIA Confidential Information and is disclosed to you // under a form of NVIDIA software license agreement provided separately to you. // // Notice // NVIDIA Corporation and its licensors retain all intellectual property and // proprietary rights in and to this software and related documentation and // any modifications thereto. Any use, reproduction, disclosure, or // distribution of this software and related documentation without an express // license agreement from NVIDIA Corporation is strictly prohibited. // // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. // // Information and code furnished is believed to be accurate and reliable. // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such // information or for any infringement of patents or other rights of third parties that may // result from its use. No license is granted by implication or otherwise under any patent // or patent rights of NVIDIA Corporation. Details are subject to change without notice. // This code supersedes and replaces all information previously supplied. // NVIDIA Corporation products are not authorized for use as critical // components in life support devices or systems without express written approval of // NVIDIA Corporation. // // Copyright (c) 2008-2013 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. #ifndef PX_PHYSICS_NX_SCENEQUERYREPORT #define PX_PHYSICS_NX_SCENEQUERYREPORT /** \addtogroup scenequery @{ */ #include "PxPhysXConfig.h" #include "foundation/PxVec3.h" #include "foundation/PxFlags.h" #ifndef PX_DOXYGEN namespace physx { #endif class PxShape; class PxRigidActor; /** \brief Scene query and geometry query behavior flags. PxHitFlags are used for 3 different purposes: 1) To request hit fields to be filled in by scene queries (such as hit position, normal, distance or UVs). 2) Once query is completed, to indicate which fields are valid (note that a query may produce more valid fields than requested). 3) To specify additional options for the narrow phase and mid-phase intersection routines. All these flags apply to both scene queries and geometry queries (PxGeometryQuery). @see PxRaycastHit PxSweepHit PxOverlapHit PxScene.raycast PxScene.sweep PxScene.overlap PxGeometryQuery */ struct PxHitFlag { enum Enum { ePOSITION = (1<<0), //!< "position" member of #PxQueryHit is valid eIMPACT = ePOSITION,//!< \deprecated Deprecated alias PX_DEPRECATED eNORMAL = (1<<1), //!< "normal" member of #PxQueryHit is valid eDISTANCE = (1<<2), //!< "distance" member of #PxQueryHit is valid eUV = (1<<3), //!< "u" and "v" barycentric coordinates of #PxQueryHit are valid. Not applicable to sweep queries. eASSUME_NO_INITIAL_OVERLAP = (1<<4), //!< Performance hint flag for sweeps when it is known upfront there's no initial overlap. //!< NOTE: using this flag may cause undefined results if shapes are initially overlapping. eMESH_MULTIPLE = (1<<5), //!< Report all hits for meshes rather than just the first. //!< On SPU the number of reported hits per mesh is limited to 16 in no specific order. eMESH_ANY = (1<<6), //!< Report any first hit for meshes. If neither eMESH_MULTIPLE or eMESH_ANY is specified, //!< a single closest hit will be reported for meshes. eMESH_BOTH_SIDES = (1<<7), //!< Report hits with back faces of triangles. Also report hits for raycast //!< originating on mesh surface and facing away from the surface normal. ePRECISE_SWEEP = (1<<8), //!< Use more accurate but slower narrow phase sweep tests. //!< May provide better compatibility with PhysX 3.2 sweep behavior. Ignored on SPU. eMTD = (1<<9), //!< Report the minimum translation depth, normal and contact point. Ignored on SPU. eDIRECT_SWEEP = ePRECISE_SWEEP, //!< \deprecated Deprecated alias. PX_DEPRECATED eDEFAULT = ePOSITION|eNORMAL|eDISTANCE, /** \brief Only this subset of flags can be modified by pre-filter. Other modifications will be discarded. */ eMODIFIABLE_FLAGS = eMESH_MULTIPLE|eMESH_BOTH_SIDES|eASSUME_NO_INITIAL_OVERLAP|ePRECISE_SWEEP }; }; /** \brief collection of set bits defined in PxHitFlag. @see PxHitFlag */ PX_FLAGS_TYPEDEF(PxHitFlag, PxU16) /** \deprecated Deprecated definition for backwards compatibility with PhysX 3.2 */ #define PxSceneQueryFlag PxHitFlag // PX_DEPRECATED /** \deprecated Deprecated definition for backwards compatibility with PhysX 3.2 */ #define PxSceneQueryFlags PxHitFlags // PX_DEPRECATED /** \brief Combines a shape pointer and the actor the shape belongs to into one memory location. Used with PxVolumeCache iterator and serves as a base class for PxQueryHit. @see PxVolumeCache PxQueryHit */ struct PxActorShape { PX_INLINE PxActorShape() : actor(NULL), shape(NULL) {} PX_INLINE PxActorShape(PxRigidActor* a, PxShape* s) : actor(a), shape(s) {} PxRigidActor* actor; PxShape* shape; }; /** \brief Scene query hit information. */ struct PxQueryHit : PxActorShape { PX_INLINE PxQueryHit() : faceIndex(0xFFFFffff) {} /** Face index of touched triangle, for triangle meshes, convex meshes and height fields. \note This index will default to 0xFFFFffff value for overlap queries and sweeps with initial overlap. \note This index is remapped by mesh cooking. Use #PxTriangleMesh::getTrianglesRemap() to convert to original mesh index. \note For convex meshes use #PxConvexMesh::getPolygonData() to retrieve touched polygon data. */ PxU32 faceIndex; }; /** \deprecated Deprecated definition for backwards compatibility with PhysX 3.2 */ #define PxSceneQueryHit PxQueryHit /** \brief Scene query hit information for raycasts and sweeps returning hit position and normal information. ::PxHitFlag flags can be passed to scene query functions, as an optimization, to cause the SDK to only generate specific members of this structure. */ struct PxLocationHit : public PxQueryHit { PX_INLINE PxLocationHit() : flags(0), position(PxVec3(0)), normal(PxVec3(0)), distance(PX_MAX_REAL) {} /** \note For raycast hits: true for shapes overlapping with raycast origin. \note For sweep hits: true for shapes overlapping at zero sweep distance. @see PxRaycastHit PxSweepHit */ PX_INLINE bool hadInitialOverlap() const { return (distance <= 0.0f); } // the following fields are set in accordance with the #PxHitFlags PxHitFlags flags; //!< Hit flags specifying which members contain valid values. PxVec3 position; //!< World-space hit position (flag: #PxHitFlag::ePOSITION) //!< Formerly known as .impact, renamed for clarity. PxVec3 normal; //!< World-space hit normal (flag: #PxHitFlag::eNORMAL) /** \brief Distance to hit. \note If the eMTD flag is used, distance will be a negative value if shapes are overlapping indicating the penetration depth. \note Otherwise, this value will be >= 0 (flag: #PxHitFlag::eDISTANCE) */ PxF32 distance; }; /** \brief Stores results of raycast queries. ::PxHitFlag flags can be passed to raycast function, as an optimization, to cause the SDK to only compute specified members of this structure. Some members like barycentric coordinates are currently only computed for triangle meshes and convexes, but next versions might provide them in other cases. The client code should check #flags to make sure returned values are valid. @see PxScene.raycast PxBatchQuery.raycast PxVolumeCache.raycast */ struct PxRaycastHit : public PxLocationHit { PX_INLINE PxRaycastHit() : u(0.0f), v(0.0f) {} // the following fields are set in accordance with the #PxHitFlags PxReal u, v; //!< barycentric coordinates of hit point, for triangle mesh and height field (flag: #PxHitFlag::eUV) #if !defined(PX_X64) && !defined(PX_ARM64) PxU32 padTo16Bytes[3]; #endif }; /** \brief Stores results of overlap queries. @see PxScene.overlap and PxBatchQuery.overlap PxVolumeCache.overlap */ struct PxOverlapHit: public PxQueryHit { PxU32 padTo16Bytes; }; /** \brief Stores results of sweep queries. @see PxScene.sweep PxBatchQuery.sweep PxVolumeCache.sweep */ struct PxSweepHit : public PxLocationHit { PX_INLINE PxSweepHit() {} PxU32 padTo16Bytes; }; /** \brief Describes query behavior after returning a partial query result via a callback. If callback returns true, traversal will continue and callback can be issued again. If callback returns false, traversal will stop, callback will not be issued again. @see PxHitCallback */ typedef bool PxAgain; /** \brief This callback class facilitates reporting scene query hits (intersections) to the user. User overrides the virtual processTouches function to receive hits in (possibly multiple) fixed size blocks. \note PxHitBuffer derives from this class and is used to receive touching hits in a fixed size buffer. \note Since the compiler doesn't look in template dependent base classes when looking for non-dependent names \note with some compilers it will be necessary to use "this->hasBlock" notation to access a parent variable \note in a child callback class. \note Pre-made typedef shorthands, such as ::PxRaycastCallback can be used for raycast, overlap and sweep queries. @see PxHitBuffer PxRaycastHit PxSweepHit PxOverlapHit PxRaycastCallback PxOverlapCallback PxSweepCallback */ template<typename HitType> struct PxHitCallback { HitType block; //<! Holds the closest blocking hit result for the query. Invalid if hasBlock is false. bool hasBlock; //<! Set to true if there was a blocking hit during query. HitType* touches; //<! User specified buffer for touching hits. /** \brief Size of the user specified touching hits buffer. \note If set to 0 all hits will default to PxQueryHitType::eBLOCK, otherwise to PxQueryHitType::eTOUCH \note Hit type returned from pre-filter overrides this default */ PxU32 maxNbTouches; /** \brief Number of touching hits returned by the query. Used with PxHitBuffer. \note If true (PxAgain) is returned from the callback, nbTouches will be reset to 0. */ PxU32 nbTouches; /** \brief Initializes the class with user provided buffer. \param[in] aTouches Optional buffer for recording PxQueryHitType::eTOUCH type hits. \param[in] aMaxNbTouches Size of touch buffer. \note if aTouches is NULL and aMaxNbTouches is 0, only the closest blocking hit will be recorded by the query. \note If PxQueryFlag::eANY_HIT flag is used as a query parameter, hasBlock will be set to true and blockingHit will be used to receive the result. \note Both eTOUCH and eBLOCK hits will be registered as hasBlock=true and stored in PxHitCallback.block when eANY_HIT flag is used. @see PxHitCallback.hasBlock PxHitCallback.block */ PxHitCallback(HitType* aTouches, PxU32 aMaxNbTouches) : hasBlock(false), touches(aTouches), maxNbTouches(aMaxNbTouches), nbTouches(0) {} /** \brief virtual callback function used to communicate query results to the user. This callback will always be invoked with aTouches as a buffer if aTouches was specified as non-NULL. All reported touch hits are guaranteed to be closer than the closest blocking hit. \param[in] buffer Callback will report touch hits to the user in this buffer. This pointer will be the same as aTouches parameter. \param[in] nbHits Number of touch hits reported in buffer. This number will not exceed aMaxNbTouches constructor parameter. \note There is a significant performance penalty in case multiple touch callbacks are issued (up to 2x) \note to avoid the penalty use a bigger buffer so that all touching hits can be reported in a single buffer. \note If true (again) is returned from the callback, nbTouches will be reset to 0, \note If false is returned, nbTouched will remain unchanged. \note By the time processTouches is first called, the globally closest blocking hit is already determined, \note values of hasBlock and block are final and all touch hits are guaranteed to be closer than the blocking hit. \note touches and maxNbTouches can be modified inside of processTouches callback. \return true to continue receiving callbacks in case there are more hits or false to stop. @see PxAgain PxRaycastHit PxSweepHit PxOverlapHit */ virtual PxAgain processTouches(const HitType* buffer, PxU32 nbHits) = 0; virtual void finalizeQuery() {} //<! Query finalization callback, called after the last processTouches callback. virtual ~PxHitCallback() {} /** \brief Returns true if any blocking or touching hits were encountered during a query. */ PX_FORCE_INLINE bool hasAnyHits() { return (hasBlock || (nbTouches > 0)); } }; /** \brief Returns scene query hits (intersections) to the user in a preallocated buffer. Will clip touch hits to maximum buffer capacity. When clipped, an arbitrary subset of touching hits will be discarded. Overflow does not trigger warnings or errors. block and hasBlock will be valid in finalizeQuery callback and after query completion. Touching hits are guaranteed to have closer or same distance ( <= condition) as the globally nearest blocking hit at the time any processTouches() callback is issued. \note Pre-made typedef shorthands, such as ::PxRaycastBuffer can be used for raycast, overlap and sweep queries. @see PxHitCallback @see PxRaycastBuffer PxOverlapBuffer PxSweepBuffer PxRaycastBufferN PxOverlapBufferN PxSweepBufferN */ template<typename HitType> struct PxHitBuffer : public PxHitCallback<HitType> { /** \brief Initializes the buffer with user memory. The buffer is initialized with 0 touch hits by default => query will only report a single closest blocking hit. Use PxQueryFlag::eANY_HIT to tell the query to abort and return any first hit encoutered as blocking. \param[in] aTouches Optional buffer for recording PxQueryHitType::eTOUCH type hits. \param[in] aMaxNbTouches Size of touch buffer. @see PxHitCallback */ PxHitBuffer(HitType* aTouches = NULL, PxU32 aMaxNbTouches = 0) : PxHitCallback<HitType>(aTouches, aMaxNbTouches) {} /** \brief Computes the number of any hits in this result, blocking or touching. */ PX_INLINE PxU32 getNbAnyHits() const { return getNbTouches() + PxU32(this->hasBlock); } /** \brief Convenience iterator used to access any hits in this result, blocking or touching. */ PX_INLINE const HitType& getAnyHit(const PxU32 index) const { PX_ASSERT(index < getNbTouches() + PxU32(this->hasBlock)); return index < getNbTouches() ? getTouches()[index] : this->block; } PX_INLINE PxU32 getNbTouches() const { return this->nbTouches; } PX_INLINE const HitType* getTouches() const { return this->touches; } PX_INLINE const HitType& getTouch(const PxU32 index) const { PX_ASSERT(index < getNbTouches()); return getTouches()[index]; } PX_INLINE PxU32 getMaxNbTouches() const { return this->maxNbTouches; } virtual ~PxHitBuffer() {} protected: // stops after the first callback virtual PxAgain processTouches(const HitType* buffer, PxU32 nbHits) { PX_UNUSED(buffer); PX_UNUSED(nbHits); return false; } }; /** \brief Raycast query callback. */ typedef PxHitCallback<PxRaycastHit> PxRaycastCallback; /** \brief Overlap query callback. */ typedef PxHitCallback<PxOverlapHit> PxOverlapCallback; /** \brief Sweep query callback. */ typedef PxHitCallback<PxSweepHit> PxSweepCallback; /** \brief Raycast query buffer. */ typedef PxHitBuffer<PxRaycastHit> PxRaycastBuffer; /** \brief Overlap query buffer. */ typedef PxHitBuffer<PxOverlapHit> PxOverlapBuffer; /** \brief Sweep query buffer. */ typedef PxHitBuffer<PxSweepHit> PxSweepBuffer; /** \brief Returns touching raycast hits to the user in a fixed size array embedded in the buffer class. **/ template <int N> struct PxRaycastBufferN : PxHitBuffer<PxRaycastHit> { PxRaycastHit hits[N]; PxRaycastBufferN() : PxHitBuffer<PxRaycastHit>(hits, N) {} }; /** \brief Returns touching overlap hits to the user in a fixed size array embedded in the buffer class. **/ template <int N> struct PxOverlapBufferN : PxHitBuffer<PxOverlapHit> { PxOverlapHit hits[N]; PxOverlapBufferN() : PxHitBuffer<PxOverlapHit>(hits, N) {} }; /** \brief Returns touching sweep hits to the user in a fixed size array embedded in the buffer class. **/ template <int N> struct PxSweepBufferN : PxHitBuffer<PxSweepHit> { PxSweepHit hits[N]; PxSweepBufferN() : PxHitBuffer<PxSweepHit>(hits, N) {} }; #ifndef PX_DOXYGEN } // namespace physx #endif /** @} */ #endif
[ "unrealbot@users.noreply.github.com" ]
unrealbot@users.noreply.github.com
e85b42250df1e8b140ef72ed94e8c252c9cca7dc
ed4a91fd9b4fefca40cc5118b485c0ec7d4ba40c
/louluosrc/template_tcp/src/main/main.cpp
5899d2047fb7fefadf9a5c96726d9d393835a488
[]
no_license
hkduke/my_src
165035db12481d36bedb48cf2c1c1759ce2af42f
2282fff562fd14c972e7ce66a615a7125cb4a877
refs/heads/master
2020-06-13T08:14:34.674528
2017-04-09T12:47:57
2017-04-09T12:48:37
null
0
0
null
null
null
null
UTF-8
C++
false
false
2,575
cpp
//#include "module_test.h" #include "SDConfigurationSingleton.h" #include <log4cplus/configurator.h> using namespace log4cplus; #include "common/SDLogger.h" #include "dispatcher.h" //#include "service_stat.h" //#include "http_server.h" #include <sys/types.h> #include <sys/wait.h> //#include "log_codec_wrapper.h" #include "http_server.h" #include "mycommon.h" void init_config(void) { std::string config_file; config_file ="../conf/notify_adapter.conf"; SDConfiguration* config = new SDConfiguration(config_file.c_str()); if (!config->load()) { //LOG4CPLUS_ERROR(logger, "read config_file \"" << m_conf_file << "\" fail: " << strerror(errno)); printf("failed to load config file path=%s\n", config_file.c_str()); delete config; exit(0); } SDConfigurationSingleton::get_instance()->init(config); } void sign_t(int sign) { printf("error!! in thread %u\n", (unsigned int) pthread_self()); abort(); } int main(int argc, char* argv[]) { if (argc >= 2) { char *pparam = argv[1]; std::string str_param=pparam; if (!str_param.compare("daemon")) { printf("become guard\n"); printf("become daemon\n"); daemon(1, 1); do { pid_t pid; pid = fork(); if (pid == 0) {// child process break; } else { int status=0; waitpid(pid, &status, 0); printf("child process exit, restart child process\n"); } } while (true); } else { printf("becom app \n"); } } PropertyConfigurator::doConfigure("../conf/log4cplus.conf"); Logger logger=Logger::getInstance("MY"); LOG4CPLUS_INFO(logger,"======main======"); EnableCoreFile(); EnableFileLimit(); init_config(); //const SDConfiguration& config = SDConfigurationSingleton::get_instance()->get_config(); //std::string test = config.getString("hello","xxxx"); //module_test mytest; //mytest.general_test(); /*if (argc < 2) { printf("username is needed \n"); exit(0); } mytest.usernametouid(argv[1]); exit(0);*/ //log_codec_wrapper::log_codec_wrapper_init(); //general_log_client *plogclient = general_log_client::get_instance(); //plogclient->init(); signal(SIGPIPE, SIG_IGN); //debug signal(SIGSEGV, sign_t); signal(SIGIO, SIG_IGN); //signal(SIGINT, SIG_IGN); signal(SIGALRM, SIG_IGN); http_server diagnose_server; diagnose_server.init(); dispatcher service; service.init(); while(true) { sleep(1000000); } return 0; }
[ "18915413902@163.com" ]
18915413902@163.com
f7e3598ca2384268d722850c20e9a5a91ca71484
8c6e11ae739ba9da168c991a166855d3b84206ca
/arduino_rfid/arduino_rfid.ino
075f578ed3b3d812ee18a4e6d4353fd89c8c5579
[ "BSD-2-Clause" ]
permissive
mrozo/RFIDScreenLock
8c8d633564b6b30c8b210ab8f7e3a916f7ed6448
15bb335df594cea70094a97556c1149b4b3f1cf7
refs/heads/master
2021-04-26T04:54:03.361584
2017-10-22T21:25:29
2017-10-22T21:25:29
107,031,216
0
0
null
null
null
null
UTF-8
C++
false
false
4,022
ino
/* * Initial Author: ryand1011 (https://github.com/ryand1011) * * Reads data written by a program such as "rfid_write_personal_data.ino" * * See: https://github.com/miguelbalboa/rfid/tree/master/examples/rfid_write_personal_data * * Uses MIFARE RFID card using RFID-RC522 reader * Uses MFRC522 - Library * ----------------------------------------------------------------------------------------- * MFRC522 Arduino Arduino Arduino Arduino Arduino * Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro * Signal Pin Pin Pin Pin Pin Pin * ----------------------------------------------------------------------------------------- * RST/Reset RST 9 5 D9 RESET/ICSP-5 RST * SPI SS SDA(SS) 10 53 D10 10 10 * SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16 * SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14 * SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15 */ #include <SPI.h> #include <MFRC522.h> #define RST_PIN 9 // Configurable, see typical pin layout above #define SS_PIN 10 // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance //*****************************************************************************************// void setup() { Serial.begin(9600); // Initialize serial communications with the PC SPI.begin(); // Init SPI bus mfrc522.PCD_Init(); // Init MFRC522 card } void PrintHex(uint8_t *data, uint8_t length) // prints 8-bit data in hex with leading zeroes { char tmp[16]; for (int i=0; i<length; i++) { sprintf(tmp, "0x%.2X",data[i]); Serial.print(tmp); Serial.print(" "); } } uint8_t buf[10]= {}; MFRC522::Uid id; MFRC522::Uid id2; bool is_card_present = false; //*****************************************************************************************// void cpid(MFRC522::Uid *id){ memset(id, 0, sizeof(MFRC522::Uid)); memcpy(id->uidByte, mfrc522.uid.uidByte, mfrc522.uid.size); id->size = mfrc522.uid.size; id->sak = mfrc522.uid.sak; } bool cmpid(MFRC522::Uid *id1, MFRC522::Uid *id2){ return memcmp(id1, id2, sizeof(MFRC522::Uid)); } void deregister_card(){ is_card_present = false; memset(&id,0, sizeof(id)); } uint8_t control = 0x00; void loop() { MFRC522::MIFARE_Key key; for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF; MFRC522::StatusCode status; //------------------------------------------- // Look for new cards if ( !mfrc522.PICC_IsNewCardPresent()) { return; } if ( !mfrc522.PICC_ReadCardSerial()) { return; } //PrintHex(id.uidByte, id.size); //Serial.println("hello"); bool result = true; uint8_t buf_len=4; cpid(&id); Serial.print("NewCard "); qPrintHex(id.uidByte, id.size); Serial.println(""); while(true){ control=0; for(int i=0; i<3; i++){ if(!mfrc522.PICC_IsNewCardPresent()){ if(mfrc522.PICC_ReadCardSerial()){ //Serial.print('a'); control |= 0x16; } if(mfrc522.PICC_ReadCardSerial()){ //Serial.print('b'); control |= 0x16; } //Serial.print('c'); control += 0x1; } //Serial.print('d'); control += 0x4; } //Serial.println(control); if(control == 13 || control == 14){ //card is still there } else { break; } } Serial.println("CardRemoved"); delay(500); //change value if you want to read cards faster mfrc522.PICC_HaltA(); mfrc522.PCD_StopCrypto1(); } //*****************************************************************************************//a
[ "private@mrozo.pl" ]
private@mrozo.pl
71b2bc5e6b14568b6e6753cfe175cdf22d7acf08
9c025e695dfeab531a47c68b1373811bed94b1da
/BCไธ€ๅ‘จๅนดB.cpp
8b543e8e434e0b6dc9c3e716f5a553c5eb8c8b05
[]
no_license
shipoyewu/code
8ecfa66f5a82976327ec649e9fe142efe0293e28
54bcf1623d6eef87109c6c34148a6072f419dfa8
refs/heads/master
2021-01-23T21:34:34.113351
2015-09-17T11:58:31
2015-09-17T11:58:31
39,375,222
0
0
null
null
null
null
UTF-8
C++
false
false
1,803
cpp
#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <cmath> #include <cstring> #include <stack> #include <set> #include <map> #include <vector> using namespace std; #define INF 0x4fffffff #define LL long long #define MAX(a,b) ((a)>(b))?(a):(b) #define MIN(a,b) ((a)<(b))?(a):(b) char str[] = "anniversary"; int a[300][4] = {}; char st[105]; int main(){ int t; cin >> t; int len = strlen(str); int w = 0; for(int i = 0;i < len-2;i++){ for(int j = i+1;j < len-1;j++){ a[w][0] = i; a[w][1] = j; a[w][2] = len-1; w++; } } while(t--){ scanf("%s",st); len = strlen(st); int flag = 0; int s,e,g,f; for(int i = 0;i < w;i++){ s = 0; f = 0; g = 0; for(int j = 0;j < 3;j++){ e = a[i][j]; for(int k = g;k < len;k++){ int d = 0; int status = 0; while(str[s+d] == st[k+d] && s+d <= e && k+d < len){ if(s+d == e){ f ++; s = a[i][j]+1; g = k+d+1; status = 1; break; } d ++; } if(status){ break; } } } if(f == 3){ flag = 1; break; } } if(flag){ printf("YES\n"); } else{ printf("NO\n"); } } return 0; }
[ "871650575@qq.com" ]
871650575@qq.com
b8ce8dac5ae09e0d7b54a6b10d797ec31f79748c
cb2b64e9cdf6fbde8ea49e9fd04eeae6e7690acc
/pokemon-battle.cpp
b9d5af724498aedd5992f4c9499a34d5f773ecc2
[]
no_license
bdavis171/Pokemon-Battle
327d5b181d53b6e65683d786c541ee713254609e
bf277272688d5729232c399a99dddce36fc6e3e0
refs/heads/master
2022-08-19T17:45:46.783296
2020-05-21T23:29:25
2020-05-21T23:29:25
263,171,171
0
0
null
null
null
null
UTF-8
C++
false
false
8,511
cpp
#include <cstdlib> // imports rand() and srand() #include <ctime> // import time() #include <iostream> // NOTE: To get a decimal value when divided two int values, one of them must be casted to a double using namespace std; // create a class for Moves that has the following properties: name,type,pwr,and acc. class Moves { public: string name, type; int pwr, acc; void setValues(string, string, int, int); }; // method to set values for Moves class void Moves::setValues(string moveName, string moveType, int power, int accuracy) { name = moveName; type = moveType; pwr = power; acc = accuracy; }; // create a class for Pokemon that has the following properties: name, type, hp, atk, def, spAtk, spDef, and spd class Pokemon { public: string name, type; int hp, atk, def, spAtk, spDef, spd; Moves move1, move2, move3, move4; void setValues(string, string, int, int, int, int, int, int, Moves, Moves, Moves, Moves); void changeHp(int); }; // method to set values for Pokemon class void Pokemon::setValues(string pokeName, string pokeType, int health, int attack, int defense, int specialAttack, int specialDefense, int speed, Moves pokeMove1, Moves pokeMove2, Moves pokeMove3, Moves pokeMove4) { name = pokeName; type = pokeType; hp = health; atk = attack; def = defense; spAtk = specialAttack; spDef = specialDefense; spd = speed; move1 = pokeMove1; move2 = pokeMove2; move3 = pokeMove3; move4 = pokeMove4; }; // method to change the pokemon's hp void Pokemon::changeHp(int newHealth) { hp = newHealth; }; // create a function for Typhlosion to use Flamthrower (Move 1) int useFlamthrower(Pokemon typhlosion, Pokemon blastoise) { srand((unsigned)time(0)); // prevent rand() from returning the same number // modifier float modifier = 0.5; // critical hit modifier float criticalModifier = 2; // possible damage dealt int damage = ((((2 * 100 / 5) + 2) + 2) * typhlosion.move1.pwr * ((double)typhlosion.spAtk / blastoise.spDef) / 50 + 2) * modifier; // calculate accuracy int hitChance = rand() % 100 + 1; // calculate critical hit int criticalChance = (rand() % 100) + 1; cout << "Typholsion used Flamthrower!" << "\n"; if (hitChance > typhlosion.move1.acc) { cout << "The attack missed..." << "\n"; } else { if (criticalChance <= 6) { damage = damage * criticalModifier; cout << "Critical hit!" << "\n"; } cout << "It's not very effective!" << "\n"; return damage; } } // function for Wild Charge (Move 2) int useWildCharge(Pokemon typhlosion, Pokemon blastoise) { srand((unsigned)time(0)); // prevent rand() from returning the same number // modifier float modifier = 1.5; // critical hit modifier float criticalModifier = 2; // possible damage dealt int damage = ((((2 * 100 / 5) + 2) + 2) * typhlosion.move2.pwr * (((double)typhlosion.atk / blastoise.def)) / 50 + 2) * modifier; cout << typhlosion.atk << "\n"; // calculate accuracy int hitChance = rand() % 100 + 1; // calculate critical hit int criticalChance = (rand() % 100) + 1; cout << "Typholsion used Wild Charge!" << "\n"; if (hitChance > typhlosion.move2.acc) { cout << "The attack missed..." << "\n"; } else { if (criticalChance <= 6) { damage = damage * criticalModifier; cout << "Critical hit!" << "\n"; } cout << "It's super effective!" << "\n"; return damage; } } // create a function for Typhlosion to use Extrasensory (Move 3) int useExtrasensory(Pokemon typhlosion, Pokemon blastoise) { srand((unsigned)time(0)); // prevent rand() from returning the same number // modifier float modifier = 1; // critical hit modifier float criticalModifier = 2; // possible damage dealt int damage = ((((2 * 100 / 5) + 2) + 2) * typhlosion.move3.pwr * ((double)typhlosion.spAtk / blastoise.spDef) / 50 + 2) * modifier; // calculate accuracy int hitChance = rand() % 100 + 1; // calculate critical hit int criticalChance = (rand() % 100) + 1; cout << "Typholsion used Extrasensory!" << "\n"; if (hitChance > typhlosion.move3.acc) { cout << "The attack missed..." << "\n"; } else { if (criticalChance <= 6) { damage = damage * criticalModifier; cout << "Critical hit!" << "\n"; } return damage; } } // create a function for Typhlosion to use Brick Break (Move 4) int useBrickBreak(Pokemon typhlosion, Pokemon blastoise) { srand((unsigned)time(0)); // prevent rand() from returning the same number // modifier float modifier = 1; // critical hit modifier float criticalModifier = 2; // possible damage dealt int damage = ((((2 * 100 / 5) + 2) + 2) * typhlosion.move4.pwr * ((double)typhlosion.atk / blastoise.def) / 50 + 2) * modifier; // calculate accuracy int hitChance = rand() % 100 + 1; // calculate critical hit int criticalChance = (rand() % 100) + 1; cout << "Typholsion used Brick Break!" << "\n"; if (hitChance > typhlosion.move4.acc) { cout << "The attack missed..." << "\n"; } else { if (criticalChance <= 6) { damage = damage * criticalModifier; cout << "Critical hit!" << "\n"; } return damage; } } // declaration function int main() { // create a new instance of the Pokemon class called Typhlosion Pokemon typhlosion; // create a new instance of the Pokemon class called Blastoise Pokemon blastoise; // (Typhlosion) create new instances of the Moves class for the following moves and set their values to the appropriate ones: Flamethrower,Wild Charge,Extrasensory, and Brick Break Moves flamethrower, wildCharge, extrasensory, brickBreak; // (Typhlosion) Move 1 flamethrower.setValues("Flamethrower", "Fire", 90, 100); // (Typhlosion) Move 2 wildCharge.setValues("Wild Charge", "Electric", 90, 100); // (Typhlosion) Move 3 extrasensory.setValues("Extrasensory", "Psychic", 80, 100); // (Typhlosion) Move 4 brickBreak.setValues("Brick Break", "Fighting", 75, 100); // (Blastoise) create new instances of the Moves class for the following moves and set their values to the appropriate ones: Hydro Pump, Dragon Pulse, Flash Cannon, and Dark Pulse Moves hydroPump, dragonPulse, flashCannon, darkPulse; // (Blastoise) Move 1 hydroPump.setValues("Hydro Pump", "Water", 110, 80); // (Blastoise) Move 2 dragonPulse.setValues("Dragon Pulse", "Dragon", 85, 100); // (Blastoise) Move 3 flashCannon.setValues("Flash Cannon", "Steel", 80, 100); // (Blastoise) Move 4 darkPulse.setValues("Dark Pulse", "Dark", 80, 100); // set typhlosion's values to the appropriate ones typhlosion.setValues("Typhlosion", "Fire", 322, 204, 192, 254, 231, 236, flamethrower, wildCharge, extrasensory, brickBreak); // set blastoise's values to the appropriate ones blastoise.setValues("Blastoise", "Water", 299, 171, 236, 206, 246, 192, hydroPump, dragonPulse, flashCannon, darkPulse); // get the original hp for both pokemon each int typhlosionOriginHp = typhlosion.hp; int blastoiseOriginHp = blastoise.hp; // variable for user commands string command; while (typhlosion.hp >= 0 && blastoise.hp >= 0) { cout << "Enter a command for Typhlosion." << "\n"; getline(cin,command); if (command == "Flamethrower") { int damageDealt = blastoise.hp - useFlamthrower(typhlosion, blastoise); blastoise.changeHp(damageDealt); cout << blastoise.hp << "/" << blastoiseOriginHp << "\n"; } else if (command == "Wild Charge"){ int damageDealt = blastoise.hp - useWildCharge(typhlosion, blastoise); blastoise.changeHp(damageDealt); cout << blastoise.hp << "/" << blastoiseOriginHp << "\n"; } else { cout << "That is not a command!!!" << "\n"; continue; } } cout << "You win!" << "\n"; }
[ "bdavis171@gmail.com" ]
bdavis171@gmail.com
013e48952bf2b2fb19473eb8cec8cc84c5502e48
bf9318969029963bc8f790798aa62769334a3026
/16- Majority Element II/sol1.cpp
33b721619432d8c1b792d072cba5ced7f5693301
[]
no_license
wandering-sage/dsa-practice
b7e16daf51f9c5cffb846a75cc50fa10ea54ee92
c63d832731f254c47a905f243d266f703bfefa79
refs/heads/main
2023-07-16T04:07:04.170288
2021-08-25T05:38:22
2021-08-25T05:38:22
379,991,570
0
0
null
null
null
null
UTF-8
C++
false
false
811
cpp
#include <bits/stdc++.h> using namespace std; // Using Moore Voting Algorithm // time-->O(N) space-->O(1) vector<int> majorityElement(vector<int> &nums) { int me1 = -1, me2 = -2; int c1 = 0, c2 = 0; vector<int> ret; int i = 0; for (int i = 0; i < nums.size(); i++) { if (nums[i] == me1) c1++; else if (nums[i] == me2) c2++; else if (c1 == 0) { me1 = nums[i]; c1++; } else if (c2 == 0) { me2 = nums[i]; c2++; } else { c1--; c2--; } } c1 = 0; c2 = 0; for (int i = 0; i < nums.size(); i++) { if (nums[i] == me1) c1++; if (nums[i] == me2) c2++; } if (c1 > nums.size() / 3) ret.push_back(me1); if (c2 > nums.size() / 3) ret.push_back(me2); return ret; }
[ "shivam4503@gmail.com" ]
shivam4503@gmail.com
62f48f8c1e86d61f8c3caaf55e1eeb5f9c7f9d26
ac1c9fbc1f1019efb19d0a8f3a088e8889f1e83c
/out/release/gen/third_party/blink/renderer/bindings/modules/v8/v8_data_transfer_item_partial.cc
dc2be783a55ea6cbfac2593cfd4102495af82a30
[ "BSD-3-Clause" ]
permissive
xueqiya/chromium_src
5d20b4d3a2a0251c063a7fb9952195cda6d29e34
d4aa7a8f0e07cfaa448fcad8c12b29242a615103
refs/heads/main
2022-07-30T03:15:14.818330
2021-01-16T16:47:22
2021-01-16T16:47:22
330,115,551
1
0
null
null
null
null
UTF-8
C++
false
false
5,253
cc
// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // This file has been auto-generated from the Jinja2 template // third_party/blink/renderer/bindings/templates/partial_interface.cc.tmpl // by the script code_generator_v8.py. // DO NOT MODIFY! // clang-format off #include "third_party/blink/renderer/bindings/modules/v8/v8_data_transfer_item_partial.h" #include <algorithm> #include "base/memory/scoped_refptr.h" #include "third_party/blink/renderer/bindings/core/v8/v8_data_transfer_item.h" #include "third_party/blink/renderer/bindings/core/v8/v8_dom_configuration.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_entry.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/frame/web_feature.h" #include "third_party/blink/renderer/modules/filesystem/data_transfer_item_file_system.h" #include "third_party/blink/renderer/platform/bindings/exception_messages.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/runtime_call_stats.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/bindings/v8_object_constructor.h" #include "third_party/blink/renderer/platform/instrumentation/use_counter.h" #include "third_party/blink/renderer/platform/scheduler/public/cooperative_scheduling_manager.h" #include "third_party/blink/renderer/platform/wtf/get_ptr.h" namespace blink { namespace data_transfer_item_partial_v8_internal { static void WebkitGetAsEntryMethod(const v8::FunctionCallbackInfo<v8::Value>& info) { DataTransferItem* impl = V8DataTransferItem::ToImpl(info.Holder()); ScriptState* script_state = ScriptState::ForRelevantRealm(info); Entry* result = DataTransferItemFileSystem::webkitGetAsEntry(script_state, *impl); V8SetReturnValue(info, result); } } // namespace data_transfer_item_partial_v8_internal void V8DataTransferItemPartial::WebkitGetAsEntryMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { BLINK_BINDINGS_TRACE_EVENT("DataTransferItem.webkitGetAsEntry"); RUNTIME_CALL_TIMER_SCOPE_DISABLED_BY_DEFAULT(info.GetIsolate(), "Blink_DataTransferItem_webkitGetAsEntry"); ExecutionContext* execution_context_for_measurement = CurrentExecutionContext(info.GetIsolate()); UseCounter::Count(execution_context_for_measurement, WebFeature::kV8DataTransferItem_WebkitGetAsEntry_Method); data_transfer_item_partial_v8_internal::WebkitGetAsEntryMethod(info); } static constexpr V8DOMConfiguration::MethodConfiguration kV8DataTransferItemMethods[] = { {"webkitGetAsEntry", V8DataTransferItemPartial::WebkitGetAsEntryMethodCallback, 0, v8::None, V8DOMConfiguration::kOnPrototype, V8DOMConfiguration::kCheckHolder, V8DOMConfiguration::kDoNotCheckAccess, V8DOMConfiguration::kHasSideEffect, V8DOMConfiguration::kAllWorlds}, }; void V8DataTransferItemPartial::InstallV8DataTransferItemTemplate( v8::Isolate* isolate, const DOMWrapperWorld& world, v8::Local<v8::FunctionTemplate> interface_template) { // Initialize the interface object's template. V8DataTransferItem::InstallV8DataTransferItemTemplate(isolate, world, interface_template); v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interface_template); ALLOW_UNUSED_LOCAL(signature); v8::Local<v8::ObjectTemplate> instance_template = interface_template->InstanceTemplate(); ALLOW_UNUSED_LOCAL(instance_template); v8::Local<v8::ObjectTemplate> prototype_template = interface_template->PrototypeTemplate(); ALLOW_UNUSED_LOCAL(prototype_template); // Register IDL constants, attributes and operations. V8DOMConfiguration::InstallMethods( isolate, world, instance_template, prototype_template, interface_template, signature, kV8DataTransferItemMethods, base::size(kV8DataTransferItemMethods)); // Custom signature V8DataTransferItemPartial::InstallRuntimeEnabledFeaturesOnTemplate( isolate, world, interface_template); } void V8DataTransferItemPartial::InstallRuntimeEnabledFeaturesOnTemplate( v8::Isolate* isolate, const DOMWrapperWorld& world, v8::Local<v8::FunctionTemplate> interface_template) { V8DataTransferItem::InstallRuntimeEnabledFeaturesOnTemplate(isolate, world, interface_template); v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interface_template); ALLOW_UNUSED_LOCAL(signature); v8::Local<v8::ObjectTemplate> instance_template = interface_template->InstanceTemplate(); ALLOW_UNUSED_LOCAL(instance_template); v8::Local<v8::ObjectTemplate> prototype_template = interface_template->PrototypeTemplate(); ALLOW_UNUSED_LOCAL(prototype_template); // Register IDL constants, attributes and operations. // Custom signature } void V8DataTransferItemPartial::Initialize() { // Should be invoked from ModulesInitializer. V8DataTransferItem::UpdateWrapperTypeInfo( &V8DataTransferItemPartial::InstallV8DataTransferItemTemplate, nullptr, &V8DataTransferItemPartial::InstallRuntimeEnabledFeaturesOnTemplate, nullptr); } } // namespace blink
[ "xueqi@zjmedia.net" ]
xueqi@zjmedia.net
ee1fd5a7032a390d5aab81dc81182035df8ccf50
923d0c8d9e4578c9a77e6f5fab207ba706ad61c4
/simplect_cpp/width-height_image.cpp
6c7e7c955c0520e5a8497863eaa2ee72f0b2da60
[]
no_license
yuni-net/simplect
d19a73c39af660bf69fc25dd655efe8067f632bf
9bdb75eb08652ad37a43555827228d4b5eb72ba3
refs/heads/master
2021-01-21T10:09:19.623786
2015-06-28T08:45:10
2015-06-28T08:45:10
38,192,343
0
0
null
null
null
null
UTF-8
C++
false
false
391
cpp
#include "includes.h" #include "image.h" float sim::image::width() const { return base_width()*magni(); } float sim::image::height() const { return base_height()*magni(); } uint sim::image::base_width() const { if (pImageData == NULL) return 0; return pImageData->width(); } uint sim::image::base_height() const { if (pImageData == NULL) return 0; return pImageData->height(); }
[ "yuni.net.liberty@gmail.com" ]
yuni.net.liberty@gmail.com
2113963c0eb66e7db7bf43f697480962f577be4a
e18a51c1bd1425f22db15700a88e8c66f3552d93
/packages/lagrangian/intermediateNew/parcels/Templates/KinematicParcel/KinematicParcel.H
ee860ad478dc325305b57ba1d41997a831391526
[]
no_license
trinath2rao/fireFoam-2.2.x
6253191db406405683e15da2263d19f4b16181ba
5f28904ffd7e82a9a55cb3f67fafb32f8f889d58
refs/heads/master
2020-12-29T01:42:16.305833
2014-11-24T21:53:39
2014-11-24T21:53:39
34,248,660
1
0
null
2015-04-20T08:37:28
2015-04-20T08:37:27
null
UTF-8
C++
false
false
20,385
h
/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM 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 3 of the License, or (at your option) any later version. OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>. Class Foam::KinematicParcel Description Kinematic parcel class with rotational motion (as spherical particles only) and one/two-way coupling with the continuous phase. Sub-models include: - drag - turbulent dispersion - wall interactions SourceFiles KinematicParcelI.H KinematicParcel.C KinematicParcelIO.C \*---------------------------------------------------------------------------*/ #ifndef KinematicParcel_H #define KinematicParcel_H #include "particle.H" #include "IOstream.H" #include "autoPtr.H" #include "interpolation.H" // #include "ParticleForceList.H" // TODO // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { template<class ParcelType> class KinematicParcel; // Forward declaration of friend functions template<class ParcelType> Ostream& operator<< ( Ostream&, const KinematicParcel<ParcelType>& ); /*---------------------------------------------------------------------------*\ Class KinematicParcel Declaration \*---------------------------------------------------------------------------*/ template<class ParcelType> class KinematicParcel : public ParcelType { public: //- Class to hold kinematic particle constant properties class constantProperties { // Private data //- Constant properties dictionary const dictionary dict_; //- Parcel type id - used for post-processing to flag the type // of parcels issued by this cloud label parcelTypeId_; //- Minimum density [kg/m3] scalar rhoMin_; //- Particle density [kg/m3] (constant) scalar rho0_; //- Minimum particle mass [kg] scalar minParticleMass_; //- Young's modulus [N/m2] scalar youngsModulus_; //- Poisson's ratio scalar poissonsRatio_; public: // Constructors //- Null constructor constantProperties(); //- Copy constructor constantProperties(const constantProperties& cp); //- Constructor from dictionary constantProperties ( const dictionary& parentDict, const bool readFields = true ); //- Construct from components constantProperties ( const label parcelTypeId, const scalar rhoMin, const scalar rho0, const scalar minParticleMass, const scalar youngsModulus, const scalar poissonsRatio ); // Member functions //- Return const access to the constant properties dictionary inline const dictionary& dict() const; //- Return const access to the parcel type id inline label parcelTypeId() const; //- Return const access to the minimum density inline scalar rhoMin() const; //- Return const access to the particle density inline scalar rho0() const; //- Return const access to the minimum particle mass inline scalar minParticleMass() const; //- Return const access to Young's Modulus inline scalar youngsModulus() const; //- Return const access to Poisson's ratio inline scalar poissonsRatio() const; }; template<class CloudType> class TrackingData : public ParcelType::template TrackingData<CloudType> { public: enum trackPart { tpVelocityHalfStep, tpLinearTrack, tpRotationalTrack }; private: // Private data // Interpolators for continuous phase fields //- Density interpolator autoPtr<interpolation<scalar> > rhoInterp_; //- Velocity interpolator autoPtr<interpolation<vector> > UInterp_; //- Dynamic viscosity interpolator autoPtr<interpolation<scalar> > muInterp_; //- Local gravitational or other body-force acceleration const vector& g_; // label specifying which part of the integration // algorithm is taking place trackPart part_; public: // Constructors //- Construct from components inline TrackingData ( CloudType& cloud, trackPart part = tpLinearTrack ); // Member functions //- Return conat access to the interpolator for continuous // phase density field inline const interpolation<scalar>& rhoInterp() const; //- Return conat access to the interpolator for continuous // phase velocity field inline const interpolation<vector>& UInterp() const; //- Return conat access to the interpolator for continuous // phase dynamic viscosity field inline const interpolation<scalar>& muInterp() const; // Return const access to the gravitational acceleration vector inline const vector& g() const; //- Return the part of the tracking operation taking place inline trackPart part() const; //- Return access to the part of the tracking operation taking place inline trackPart& part(); }; protected: // Protected data // Parcel properties //- Active flag - tracking inactive when active = false bool active_; //- Parcel type id label typeId_; //- Number of particles in Parcel scalar nParticle_; //- Diameter [m] scalar d_; //- Target diameter [m] scalar dTarget_; //- Velocity of Parcel [m/s] vector U_; //- Force on particle due to collisions [N] vector f_; //- Angular momentum of Parcel in global reference frame // [kg m2/s] vector angularMomentum_; //- Torque on particle due to collisions in global // reference frame [Nm] vector torque_; //- Density [kg/m3] scalar rho_; //- Age [s] scalar age_; //- Time spent in turbulent eddy [s] scalar tTurb_; //- Turbulent velocity fluctuation [m/s] vector UTurb_; // Cell-based quantities //- Density [kg/m3] scalar rhoc_; //- Velocity [m/s] vector Uc_; //- Viscosity [Pa.s] scalar muc_; // Protected Member Functions //- Calculate new particle velocity template<class TrackData> const vector calcVelocity ( TrackData& td, const scalar dt, // timestep const label cellI, // owner cell const scalar Re, // Reynolds number const scalar mu, // local carrier viscosity const scalar mass, // mass const vector& Su, // explicit particle momentum source vector& dUTrans, // momentum transfer to carrier scalar& Spu // linearised drag coefficient ) const; public: // Static data members //- Runtime type information TypeName("KinematicParcel"); //- String representation of properties AddToPropertyList ( ParcelType, " active" + " typeId" + " nParticle" + " d" + " dTarget " + " (Ux Uy Uz)" + " (fx fy fz)" + " (angularMomentumx angularMomentumy angularMomentumz)" + " (torquex torquey torquez)" + " rho" + " age" + " tTurb" + " (UTurbx UTurby UTurbz)" ); // Constructors //- Construct from owner, position, and cloud owner // Other properties initialised as null inline KinematicParcel ( const polyMesh& mesh, const vector& position, const label cellI, const label tetFaceI, const label tetPtI ); //- Construct from components inline KinematicParcel ( const polyMesh& mesh, const vector& position, const label cellI, const label tetFaceI, const label tetPtI, const label typeId, const scalar nParticle0, const scalar d0, const scalar dTarget0, const vector& U0, const vector& f0, const vector& angularMomentum0, const vector& torque0, const constantProperties& constProps ); //- Construct from Istream KinematicParcel ( const polyMesh& mesh, Istream& is, bool readFields = true ); //- Construct as a copy KinematicParcel(const KinematicParcel& p); //- Construct as a copy KinematicParcel(const KinematicParcel& p, const polyMesh& mesh); //- Construct and return a (basic particle) clone virtual autoPtr<particle> clone() const { return autoPtr<particle>(new KinematicParcel(*this)); } //- Construct and return a (basic particle) clone virtual autoPtr<particle> clone(const polyMesh& mesh) const { return autoPtr<particle>(new KinematicParcel(*this, mesh)); } //- Factory class to read-construct particles used for // parallel transfer class iNew { const polyMesh& mesh_; public: iNew(const polyMesh& mesh) : mesh_(mesh) {} autoPtr<KinematicParcel<ParcelType> > operator()(Istream& is) const { return autoPtr<KinematicParcel<ParcelType> > ( new KinematicParcel<ParcelType>(mesh_, is, true) ); } }; // Member Functions // Access //- Return const access to active flag inline bool active() const; //- Return const access to type id inline label typeId() const; //- Return const access to number of particles inline scalar nParticle() const; //- Return const access to diameter inline scalar d() const; //- Return const access to target diameter inline scalar dTarget() const; //- Return const access to velocity inline const vector& U() const; //- Return const access to force inline const vector& f() const; //- Return const access to angular momentum inline const vector& angularMomentum() const; //- Return const access to torque inline const vector& torque() const; //- Return const access to density inline scalar rho() const; //- Return const access to the age inline scalar age() const; //- Return const access to time spent in turbulent eddy inline scalar tTurb() const; //- Return const access to turbulent velocity fluctuation inline const vector& UTurb() const; //- Return const access to carrier density [kg/m3] inline scalar rhoc() const; //- Return const access to carrier velocity [m/s] inline const vector& Uc() const; //- Return const access to carrier viscosity [Pa.s] inline scalar muc() const; // Edit //- Return const access to active flag inline bool& active(); //- Return access to type id inline label& typeId(); //- Return access to number of particles inline scalar& nParticle(); //- Return access to diameter inline scalar& d(); //- Return access to target diameter inline scalar& dTarget(); //- Return access to velocity inline vector& U(); //- Return access to force inline vector& f(); //- Return access to angular momentum inline vector& angularMomentum(); //- Return access to torque inline vector& torque(); //- Return access to density inline scalar& rho(); //- Return access to the age inline scalar& age(); //- Return access to time spent in turbulent eddy inline scalar& tTurb(); //- Return access to turbulent velocity fluctuation inline vector& UTurb(); // Helper functions //- Return the index of the face to be used in the interpolation // routine inline label faceInterpolation() const; //- Cell owner mass inline scalar massCell(const label cellI) const; //- Particle mass inline scalar mass() const; //- Particle moment of inertia around diameter axis inline scalar momentOfInertia() const; //- Particle angular velocity inline vector omega() const; //- Particle volume inline scalar volume() const; //- Particle volume for a given diameter inline static scalar volume(const scalar d); //- Particle projected area inline scalar areaP() const; //- Projected area for given diameter inline static scalar areaP(const scalar d); //- Particle surface area inline scalar areaS() const; //- Surface area for given diameter inline static scalar areaS(const scalar d); //- Reynolds number inline scalar Re ( const vector& U, // particle velocity const scalar d, // particle diameter const scalar rhoc, // carrier density const scalar muc // carrier dynamic viscosity ) const; //- Weber number inline scalar We ( const vector& U, // particle velocity const scalar d, // particle diameter const scalar rhoc, // carrier density const scalar sigma // particle surface tension ) const; //- Eotvos number inline scalar Eo ( const vector& a, // acceleration const scalar d, // particle diameter const scalar sigma // particle surface tension ) const; // Main calculation loop //- Set cell values template<class TrackData> void setCellValues ( TrackData& td, const scalar dt, const label cellI ); //- Correct cell values using latest transfer information template<class TrackData> void cellValueSourceCorrection ( TrackData& td, const scalar dt, const label cellI ); //- Update parcel properties over the time interval template<class TrackData> void calc ( TrackData& td, const scalar dt, const label cellI ); // Tracking //- Move the parcel template<class TrackData> bool move(TrackData& td, const scalar trackTime); // Patch interactions //- Overridable function to handle the particle hitting a face // without trackData void hitFace(int& td); //- Overridable function to handle the particle hitting a face template<class TrackData> void hitFace(TrackData& td); //- Overridable function to handle the particle hitting a patch // Executed before other patch-hitting functions template<class TrackData> bool hitPatch ( const polyPatch& p, TrackData& td, const label patchI, const scalar trackFraction, const tetIndices& tetIs ); //- Overridable function to handle the particle hitting a // processorPatch template<class TrackData> void hitProcessorPatch ( const processorPolyPatch&, TrackData& td ); //- Overridable function to handle the particle hitting a wallPatch template<class TrackData> void hitWallPatch ( const wallPolyPatch&, TrackData& td, const tetIndices& ); //- Overridable function to handle the particle hitting a polyPatch template<class TrackData> void hitPatch ( const polyPatch&, TrackData& td ); //- Transform the physical properties of the particle // according to the given transformation tensor virtual void transformProperties(const tensor& T); //- Transform the physical properties of the particle // according to the given separation vector virtual void transformProperties(const vector& separation); //- The nearest distance to a wall that the particle can be // in the n direction virtual scalar wallImpactDistance(const vector& n) const; // I-O //- Read template<class CloudType> static void readFields(CloudType& c); //- Write template<class CloudType> static void writeFields(const CloudType& c); // Ostream Operator friend Ostream& operator<< <ParcelType> ( Ostream&, const KinematicParcel<ParcelType>& ); }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #include "KinematicParcelI.H" #include "KinematicParcelTrackingDataI.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository #include "KinematicParcel.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif // ************************************************************************* //
[ "karl.meredith@fmglobal.com" ]
karl.meredith@fmglobal.com
efd68d2dded62d980338d0eb39b3682c8b5b1e99
1835bc57373845971613cda3f66b88813c139fc2
/examples/Cylindrical/tracker.cc
9c2ef9360fdf68c2eafe505390268eb1ec37ccc5
[]
no_license
jtalman/ual-sandbox_SL7.4Plus
4cf8037a0b289d9a29b9e8918ca15e40d4eca8a4
decdce8e9e42b51be4ced1174811bcb14427353a
refs/heads/master
2020-03-09T19:36:51.464651
2019-11-12T12:57:52
2019-11-12T12:57:52
128,962,122
0
0
null
null
null
null
UTF-8
C++
false
false
5,565
cc
#include <iostream> #include <fstream> #include <iomanip> #include <string> #include <algorithm> #include <stdio.h> #include <stdlib.h> #include "UAL/APDF/APDF_Builder.hh" #include "PAC/Beam/Position.hh" #include "SMF/PacSmf.h" #include "PAC/Beam/Bunch.hh" #include "Main/Teapot.h" #include "UAL/UI/Shell.hh" #include "PAC/Beam/Particle.hh" #include "PAC/Beam/Spin.hh" #include "UAL/SMF/AcceleratorNodeFinder.hh" #include "Optics/PacTMap.h" #include "Integrator/TeapotElemBend.h" #include "positionPrinter.hh" #include "xmgracePrint.hh" #include "ETEAPOT/Integrator/DipoleTracker.hh" using namespace UAL; int main(int argc,char * argv[]){ if(argc!=2){ std::cout << "usage: ./tracker ./data/pre-E_pEDm.sxf (> ! myOut)\n"; std::cout << "argv[0] is this executable: ./tracker\n"; std::cout << "argv[1] is the input sxf file - ./data/pre-E_pEDm.sxf\n"; exit(0); } std::string mysxf =argv[1]; std::string mysxfbase=mysxf.substr(7,mysxf.size()-11); std::cout << "mysxf " << mysxf.c_str() << "\n"; std::cout << "mysxfbase " << mysxfbase.c_str() << "\n"; #include "designBeamValues.hh" #include "extractParameters.h" UAL::Shell shell; // ************************************************************************ std::cout << "\nDefine the space of Taylor maps." << std::endl; // ************************************************************************ shell.setMapAttributes(UAL::Args() << UAL::Arg("order", 5)); // ************************************************************************ std::cout << "\nBuild lattice." << std::endl; // ************************************************************************ shell.readSXF(UAL::Args() << UAL::Arg("file", sxfFile.c_str())); // ************************************************************************ std::cout << "\nAdd split ." << std::endl; // ************************************************************************ shell.addSplit(UAL::Args() << UAL::Arg("lattice", "ring") << UAL::Arg("types", "Sbend") << UAL::Arg("ir", split)); shell.addSplit(UAL::Args() << UAL::Arg("lattice", "ring") << UAL::Arg("types", "Quadrupole") << UAL::Arg("ir", 0)); shell.addSplit(UAL::Args() << UAL::Arg("lattice", "ring") << UAL::Arg("types", "Sextupole") << UAL::Arg("ir", 0)); // ************************************************************************ std::cout << "Select lattice." << std::endl; // ************************************************************************ shell.use(UAL::Args() << UAL::Arg("lattice", "ring")); // ************************************************************************ std::cout << "\nWrite SXF file ." << std::endl; // ************************************************************************ shell.writeSXF(UAL::Args() << UAL::Arg("file", outputFile.c_str())); // ************************************************************************ std::cout << "\nDefine beam parameters." << std::endl; // ************************************************************************ #include "setBeamAttributes.hh" PAC::BeamAttributes& ba = shell.getBeamAttributes(); // ************************************************************************ std::cout << "\nLinear analysis." << std::endl; // ************************************************************************ // Make linear matrix std::cout << " matrix" << std::endl; shell.map(UAL::Args() << UAL::Arg("order", 1) << UAL::Arg("print", mapFile.c_str())); // Calculate twiss std::cout << " twiss (ring )" << std::endl; shell.twiss(UAL::Args() << UAL::Arg("print", twissFile.c_str())); std::cout << " calculate suml" << std::endl; shell.analysis(UAL::Args()); // ************************************************************************ std::cout << "\nAlgorithm Part. " << std::endl; // ************************************************************************ UAL::APDF_Builder apBuilder; apBuilder.setBeamAttributes(ba); UAL::AcceleratorPropagator* ap = apBuilder.parse(apdfFile); if(ap == 0) { std::cout << "Accelerator Propagator has not been created " << std::endl; return 1; } std::cout << "\n SXF_TRACKER tracker, "; std::cout << "size : " << ap->getRootNode().size() << " propagators " << endl; // ************************************************************************ std::cout << "\nBunch Part." << std::endl; // ************************************************************************ // ba.setG(1.7928474); // adds proton G factor PAC::Bunch bunch(4); // bunch with 4 particles bunch.setBeamAttributes(ba); PAC::Spin spin; spin.setSX(0.0); spin.setSY(0.0); spin.setSZ(1.0); //bunch[0].getPosition().set(1.e-4,0. ,0. ,0. ,0.,0.); bunch[0].getPosition().set(1.e-4,0. ,1.e-4,0. ,0.,0.); bunch[1].getPosition().set(0. ,0.5e-5,0. ,0. ,0.,0.); bunch[2].getPosition().set(0. ,0. ,1.e-4,0. ,0.,0.); bunch[3].getPosition().set(0. ,0. ,0. ,0.5e-6,0.,0.); // ************************************************************************ std::cout << "\nTracking. " << std::endl; // ************************************************************************ double t; // time variable int turns = 16; positionPrinter pP; pP.open(orbitFile.c_str()); xmgracePrint xP; xP.open("bunchSub0"); ba.setElapsedTime(0.0); for(int iturn = 1; iturn <= turns; iturn++){ ap -> propagate(bunch); for(int ip=0; ip < bunch.size(); ip++){ pP.write(iturn, ip, bunch); } xP.write(iturn, 0, bunch); } pP.close(); xP.close(); return 1; }
[ "JohnDTalman@gmail.com" ]
JohnDTalman@gmail.com
4bad78897ff2cc64284e87972bbf4e3990e2e7a1
f53c6b3045e89b6674808e1c41495a020af48484
/test/sy/angle/angle.ino
ba29651295de0c87b3fa57143129e7b7f4ffdb30
[]
no_license
Team-Achi/Electric-Toothbrush
73783a78c7d2b319718277e93fd5161b671e9fec
74a4ec49851a60d0e93f84cbbfe2d76d159114fa
refs/heads/master
2020-03-28T19:42:15.625659
2018-12-10T14:18:33
2018-12-10T14:18:33
149,001,579
0
0
null
null
null
null
UTF-8
C++
false
false
1,052
ino
#include<Wire.h> const int MPU=0x68;//MPU6050 I2C์ฃผ์†Œ int AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ; void get6050(); void setup() { Wire.begin(); Wire.beginTransmission(MPU); Wire.write(0x6B); Wire.write(0);//MPU6050 ์„ ๋™์ž‘ ๋Œ€๊ธฐ ๋ชจ๋“œ๋กœ ๋ณ€๊ฒฝ Wire.endTransmission(true); Serial.begin(9600); } void loop() { get6050();//์„ผ์„œ๊ฐ’ ๊ฐฑ์‹  //๋ฐ›์•„์˜จ ์„ผ์„œ๊ฐ’์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. Serial.print(AcX); Serial.print("\t"); Serial.print(AcY); Serial.print("\t"); Serial.print(AcZ); Serial.println(); delay(500); } void get6050(){ Wire.beginTransmission(MPU);//MPU6050 ํ˜ธ์ถœ Wire.write(0x3B);//AcX ๋ ˆ์ง€์Šคํ„ฐ ์œ„์น˜ ์š”์ฒญ Wire.endTransmission(false); Wire.requestFrom(MPU,14,true);//14byte์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์š”์ฒญ AcX=Wire.read()<<8|Wire.read();//๋‘๊ฐœ์˜ ๋‚˜๋‰˜์–ด์ง„ ๋ฐ”์ดํŠธ๋ฅผ ํ•˜๋‚˜๋กœ ์ด์–ด๋ถ™์ž…๋‹ˆ๋‹ค. AcY=Wire.read()<<8|Wire.read(); AcZ=Wire.read()<<8|Wire.read(); Tmp=Wire.read()<<8|Wire.read(); GyX=Wire.read()<<8|Wire.read(); GyY=Wire.read()<<8|Wire.read(); GyZ=Wire.read()<<8|Wire.read(); }
[ "gfsusan@naver.com" ]
gfsusan@naver.com
9c6897ad10c77e78913865041aeee2163b784c79
28a961d8524aa1fe84cfdd2b6e124f39eb1b5237
/net/Server.h
94e9064756774cab14e2f46269b76916da660f3b
[]
no_license
yanpd1228/Yedis
0765607ef26cb03d416ab76262109d2f6ab2a658
d137a68636637599ebe78e35a403fc145a22450c
refs/heads/master
2023-05-12T20:39:01.805463
2021-05-30T05:01:30
2021-05-30T05:01:30
363,556,674
2
0
null
null
null
null
UTF-8
C++
false
false
1,910
h
#ifndef _YPD_SERVER_H_ #define _YPD_SERVER_H_ #include <functional> #include "SocketAddr.h" #include "TcpConnection.h" #include <atomic> #include <memory> #include <map> class AcceptNew; class EventLoop; class EventLoopThreadPool; class Server { public: enum Option { kNoReusePort, kReusePort, }; Server(EventLoop* loop, const SocketAddr& listenAddr, const std::string& nameArg, Option option = kReusePort); ~Server(); public: void setConnectionCallback(const ConnectionCallback& cb){m_NewConnectionCallback = cb; } const std::string& hostport() const { return m_strHostPort; } const std::string& name() const { return m_strName; } EventLoop* getLoop() const { return m_ptrLoop; } typedef std::map<std::string, TcpConnectionPtr> ConnectionMap; void start(int nWorkThreadCount); void newConnection(int nSockfd, SocketAddr& peerAdder); void removeConnection(const TcpConnectionPtr& conn); void removeConnectionInLoop(const TcpConnectionPtr& conn); private: EventLoop* m_ptrLoop; // the acceptor loop std::string m_strHostPort; std::string m_strName; std::unique_ptr<AcceptNew> m_ptrAccepNewConn; std::unique_ptr<EventLoopThreadPool> m_ptrEventLoopThreadPool; ConnectionCallback m_NewConnectionCallback; MessageCallback m_MessageCallback; WriteCompleteCallback m_WriteCompleteCallback; ThreadInitCallback m_ThreadInitCallback; std::atomic<int> m_nStarted; int m_nNextConnId; ConnectionMap m_mapConnections; }; #endif //!_YPD_SERVER_H_
[ "1654309840@qq.com" ]
1654309840@qq.com
ddbe164296fe772daef73bdf76842991f7d7c89b
bd56aece437cd598f929ca4df96138e8c2a5713e
/2DPlatformer/Fighter.h
dbf58cd453f60d8b9bff5931303adc8bfd2f0789
[]
no_license
dbncourt/SpaceFighter
9bb5b1585459cef5f81d59e208c38b20815e9890
84c4fa2428dad8573e8eabf23180610c83d2229a
refs/heads/master
2021-01-01T06:05:05.102586
2015-10-01T01:41:27
2015-10-01T01:41:27
42,380,702
1
1
null
null
null
null
UTF-8
C++
false
false
960
h
//////////////////////////////////////////////////////////////////////////////// // Filename: Fighter.h //////////////////////////////////////////////////////////////////////////////// #ifndef _FIGHTER_H_ #define _FIGHTER_H_ ////////////// // INCLUDES // ////////////// #include <list> /////////////////////// // MY CLASS INCLUDES // /////////////////////// #include "GameObject.h" #include "BoxCollider.h" class Fighter : public GameObject { public: Fighter(); Fighter(const Fighter& other); ~Fighter(); virtual bool Initialize(ID3D11Device* device, HWND hwnd, Bitmap::DimensionType screen, bool drawCollider) override; virtual bool Render(ID3D11DeviceContext* deviceContext, D3DXMATRIX wordMatrix, D3DXMATRIX viewMatrix, D3DXMATRIX projectionMatrix) override; virtual void Frame(const InputHandler::ControlsType& controls) override; private: BoxCollider* m_boxCollider; const int SHIP_SPEED = 3; const float ANIMATION_DELAY = 20.0f; }; #endif
[ "dbncourt@gmail.com" ]
dbncourt@gmail.com